Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-shoes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heroui/theme": patch
---

remove flat dependencies (#6148)
1 change: 0 additions & 1 deletion packages/core/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"color": "^4.2.3",
"color2k": "^2.0.3",
"deepmerge": "4.3.1",
"flat": "^5.0.2",
"tailwind-variants": "3.2.2",
"tailwind-merge": "3.4.0",
"@heroui/shared-utils": "workspace:*"
Expand Down
53 changes: 51 additions & 2 deletions packages/core/theme/src/utils/object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import flatten from "flat";

export function swapColorValues<T extends Object>(colors: T) {
const swappedColors = {};
const keys = Object.keys(colors);
Expand Down Expand Up @@ -40,6 +38,57 @@ export function removeDefaultKeys<T extends Object>(obj: T) {
return newObj;
}

function isBuffer(obj) {
return (
obj &&
obj.constructor &&
typeof obj.constructor.isBuffer === "function" &&
obj.constructor.isBuffer(obj)
);
}

function keyIdentity(key) {
return key;
}

export function flatten(target, opts) {
opts = opts || {};

const delimiter = opts.delimiter || ".";
const maxDepth = opts.maxDepth;
const transformKey = opts.transformKey || keyIdentity;
const output = {};

function step(object, prev, currentDepth) {
currentDepth = currentDepth || 1;
Object.keys(object).forEach(function (key) {
const value = object[key];
const isarray = opts.safe && Array.isArray(value);
const type = Object.prototype.toString.call(value);
const isbuffer = isBuffer(value);
const isobject = type === "[object Object]" || type === "[object Array]";

const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);

if (
!isarray &&
!isbuffer &&
isobject &&
Object.keys(value).length &&
(!opts.maxDepth || currentDepth < maxDepth)
) {
return step(value, newKey, currentDepth + 1);
}

output[newKey] = value;
});
}

step(target, null, null);

return output;
}

/**
*
* Flatten theme object and remove default keys
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading