@plumeria/utils 18.5.1 → 18.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import type { Expression, ObjectExpression } from '@swc/core';
2
- import type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable, VariantsHashTable } from './types';
2
+ import type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable } from './types';
3
3
  export type NamedParam = {
4
4
  key: string;
5
5
  local: string;
@@ -27,7 +27,6 @@ export type DynamicStyleTables = {
27
27
  createHashTable: CreateHashTable;
28
28
  createStaticHashTable: CreateStaticHashTable;
29
29
  createStaticObjectTable: CreateStaticObjectTable;
30
- variantsHashTable: VariantsHashTable;
31
30
  };
32
31
  export type DynamicStyleResult = {
33
32
  style: CSSObject;
@@ -147,7 +147,7 @@ const resolveDynamicStyle = (func, runtimeParams, staticTable, tables, providedP
147
147
  if (func.unsupportedParams)
148
148
  throw new Error('[plumeria] Dynamic styles require named parameters or object destructuring; array and rest parameters are not supported.');
149
149
  const tempStaticTable = { ...staticTable };
150
- const resolveBody = () => (0, parser_1.objectExpressionToObject)(func.body, tempStaticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable, tables.variantsHashTable);
150
+ const resolveBody = () => (0, parser_1.objectExpressionToObject)(func.body, tempStaticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable);
151
151
  const withDefault = Object.entries(func.defaults ?? {}).filter(([param]) => providedParams
152
152
  ? !providedParams.has(param)
153
153
  : tempStaticTable[param] === undefined);
@@ -187,7 +187,7 @@ const resolveDynamicStyle = (func, runtimeParams, staticTable, tables, providedP
187
187
  value: expr,
188
188
  },
189
189
  ],
190
- }, staticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable, tables.variantsHashTable);
190
+ }, staticTable, tables.keyframesHashTable, tables.viewTransitionHashTable, tables.createThemeHashTable, tables.createThemeObjectTable, tables.createHashTable, tables.createStaticHashTable, tables.createStaticObjectTable);
191
191
  const literal = resolved.value;
192
192
  if (typeof literal !== 'string' && typeof literal !== 'number')
193
193
  return;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateFunctionTable, VariantsHashTable, CreateThemeHashTable, CreateStaticHashTable, } from './types';
1
+ export type { CSSObject, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateFunctionTable, CreateThemeHashTable, CreateStaticHashTable, } from './types';
2
2
  export { objectExpressionToObject, collectLocalConsts, traverse, t, getRootIdentifier, unwrapExpression, extractOndemandStyles, deepMerge, scanAll, resolveFileError, getFileDependencies, resolveExport, resolveComponentKey, resolveThemeSelector, } from './parser';
3
3
  export type { StyleRecord } from './create';
4
4
  export { getStyleRecords } from './create';
@@ -11,7 +11,6 @@ export { getStateWeights } from './escalation';
11
11
  export { themeHashOf } from './createTheme';
12
12
  export { resolveImportPath } from './resolver';
13
13
  export { optimizer } from './optimizer';
14
- export { processVariants } from './variants';
15
14
  export { getLeadingCommentLength } from './ast';
16
15
  export type { ReferenceIdentifiers } from './references';
17
16
  export { collectReferenceIdentifiers } from './references';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.processVariants = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.unwrapExpression = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
3
+ exports.assertPropertyPolicy = exports.resolvePropertyPolicy = exports.DEFAULT_STYLE_PROP = exports.timedAsync = exports.timed = exports.tally = exports.measure = exports.mark = exports.profiling = exports.collectReferenceIdentifiers = exports.getLeadingCommentLength = exports.optimizer = exports.resolveImportPath = exports.themeHashOf = exports.getStateWeights = exports.getPseudoElement = exports.getSpecificity = exports.resolveDynamicStyle = exports.applyVarFallback = exports.splitVarByUnit = exports.isUnitlessProp = exports.styleFunctionsOf = exports.getStyleRecords = exports.resolveThemeSelector = exports.resolveComponentKey = exports.resolveExport = exports.getFileDependencies = exports.resolveFileError = exports.scanAll = exports.deepMerge = exports.extractOndemandStyles = exports.unwrapExpression = exports.getRootIdentifier = exports.t = exports.traverse = exports.collectLocalConsts = exports.objectExpressionToObject = void 0;
4
4
  var parser_1 = require("./parser");
5
5
  Object.defineProperty(exports, "objectExpressionToObject", { enumerable: true, get: function () { return parser_1.objectExpressionToObject; } });
6
6
  Object.defineProperty(exports, "collectLocalConsts", { enumerable: true, get: function () { return parser_1.collectLocalConsts; } });
@@ -35,8 +35,6 @@ var resolver_1 = require("./resolver");
35
35
  Object.defineProperty(exports, "resolveImportPath", { enumerable: true, get: function () { return resolver_1.resolveImportPath; } });
36
36
  var optimizer_1 = require("./optimizer");
37
37
  Object.defineProperty(exports, "optimizer", { enumerable: true, get: function () { return optimizer_1.optimizer; } });
38
- var variants_1 = require("./variants");
39
- Object.defineProperty(exports, "processVariants", { enumerable: true, get: function () { return variants_1.processVariants; } });
40
38
  var ast_1 = require("./ast");
41
39
  Object.defineProperty(exports, "getLeadingCommentLength", { enumerable: true, get: function () { return ast_1.getLeadingCommentLength; } });
42
40
  var references_1 = require("./references");
package/dist/parser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, VariantsHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable } from './types';
1
+ import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable } from './types';
2
2
  import type { Module, Expression, CallExpression, Identifier, KeyValueProperty, StringLiteral, NumericLiteral, BooleanLiteral, ObjectExpression, MemberExpression, TemplateLiteral, BinaryExpression, UnaryExpression, ParenthesisExpression, VariableDeclaration, VariableDeclarator, ExportDeclaration, ConditionalExpression, JSXExpression, ArrowFunctionExpression, FunctionExpression } from '@swc/core';
3
3
  export declare function unwrapExpression(node: any): any;
4
4
  export declare const getRootIdentifier: (node: Expression) => string | null;
@@ -35,7 +35,7 @@ export declare function traverse(node: Module | JSXExpression, visitor: {
35
35
  stop: () => void;
36
36
  }) => void;
37
37
  }): void;
38
- export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, createThemeHashTable: CreateThemeHashTable, createThemeObjectTable: CreateThemeObjectTable, createHashTable: CreateHashTable, createStaticHashTable: CreateStaticHashTable, createStaticObjectTable: CreateStaticObjectTable, variantsHashTable: VariantsHashTable, resolveVariable?: (name: string) => any): CSSObject;
38
+ export declare function objectExpressionToObject(node: ObjectExpression, staticTable: StaticTable, keyframesHashTable: KeyframesHashTable, viewTransitionHashTable: ViewTransitionHashTable, createThemeHashTable: CreateThemeHashTable, createThemeObjectTable: CreateThemeObjectTable, createHashTable: CreateHashTable, createStaticHashTable: CreateStaticHashTable, createStaticObjectTable: CreateStaticObjectTable, resolveVariable?: (name: string) => any): CSSObject;
39
39
  export declare function collectLocalConsts(ast: Module): Record<string, any>;
40
40
  export declare function resolveThemeSelector(node: Expression, staticTable: StaticTable, createStaticHashTable: CreateStaticHashTable, createStaticObjectTable: CreateStaticObjectTable): string;
41
41
  export declare function resolveFileError(actualPath: string, importedName: string): {
package/dist/parser.js CHANGED
@@ -208,7 +208,7 @@ function traverse(node, visitor) {
208
208
  }
209
209
  walk(node);
210
210
  }
211
- function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, variantsHashTable, resolveVariable) {
211
+ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable) {
212
212
  const obj = Object.create(null);
213
213
  node.properties.forEach((prop) => {
214
214
  if (prop.type === 'SpreadElement') {
@@ -279,11 +279,6 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
279
279
  obj[key] = resolvedStatic;
280
280
  return;
281
281
  }
282
- const resolvedVariants = resolveVariantsTableMemberExpression(val, variantsHashTable);
283
- if (resolvedVariants !== undefined) {
284
- obj[key] = 'vr-' + resolvedVariants;
285
- return;
286
- }
287
282
  }
288
283
  if (exports.t.isStringLiteral(val) ||
289
284
  exports.t.isNumericLiteral(val) ||
@@ -294,7 +289,7 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
294
289
  obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
295
290
  }
296
291
  else if (exports.t.isObjectExpression(val)) {
297
- obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, variantsHashTable, resolveVariable);
292
+ obj[key] = objectExpressionToObject(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createHashTable, createStaticHashTable, createStaticObjectTable, resolveVariable);
298
293
  }
299
294
  else if (exports.t.isBinaryExpression(val) || exports.t.isTemplateLiteral(val)) {
300
295
  obj[key] = evaluateExpression(val, staticTable, keyframesHashTable, viewTransitionHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
@@ -355,8 +350,11 @@ function collectLocalConsts(ast) {
355
350
  exports.t.isBooleanLiteral(init)) {
356
351
  result = init.value;
357
352
  }
353
+ else if (exports.t.isIdentifier(init)) {
354
+ result = resolveValue(init.value);
355
+ }
358
356
  else if (exports.t.isObjectExpression(init)) {
359
- result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, {}, resolveValue);
357
+ result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, resolveValue);
360
358
  }
361
359
  else if (exports.t.isBinaryExpression(init) ||
362
360
  exports.t.isTemplateLiteral(init) ||
@@ -862,16 +860,6 @@ function resolveCreateTableMemberExpression(node, createHashTable) {
862
860
  return createHashTable[node.value];
863
861
  }
864
862
  }
865
- function resolveVariantsTableMemberExpression(node, variantsHashTable) {
866
- if (exports.t.isIdentifier(node)) {
867
- return variantsHashTable[node.value];
868
- }
869
- if (exports.t.isMemberExpression(node)) {
870
- if (exports.t.isIdentifier(node.object)) {
871
- return variantsHashTable[node.object.value];
872
- }
873
- }
874
- }
875
863
  function resolveStaticTableMemberExpression(node, staticTable) {
876
864
  const keys = [];
877
865
  let current = node;
@@ -1012,8 +1000,6 @@ const globalAgregatedTables = {
1012
1000
  createObjectTable: {},
1013
1001
  createFunctionTable: {},
1014
1002
  createAtomicMapTable: {},
1015
- variantsHashTable: {},
1016
- variantsObjectTable: {},
1017
1003
  createThemeHashTable: {},
1018
1004
  createStaticHashTable: {},
1019
1005
  createStaticObjectTable: {},
@@ -1099,9 +1085,6 @@ function stripFileContributions(filePath, cached) {
1099
1085
  delete localTables.createHashTable[`${filePath}-${key}`];
1100
1086
  delete localTables.createFunctionTable[`${filePath}-${key}`];
1101
1087
  }
1102
- for (const key of Object.keys(cached.variantsHashTable)) {
1103
- delete localTables.variantsHashTable[`${filePath}-${key}`];
1104
- }
1105
1088
  for (const key of Object.keys(cached.createStaticObjectTable)) {
1106
1089
  releaseObjectOwner('createStaticObjectTable', key, filePath, localTables.createStaticObjectTable);
1107
1090
  }
@@ -1123,9 +1106,6 @@ function stripFileContributions(filePath, cached) {
1123
1106
  for (const key of Object.keys(cached.createAtomicMapTable)) {
1124
1107
  releaseObjectOwner('createAtomicMapTable', key, filePath, localTables.createAtomicMapTable);
1125
1108
  }
1126
- for (const key of Object.keys(cached.variantsObjectTable)) {
1127
- releaseObjectOwner('variantsObjectTable', key, filePath, localTables.variantsObjectTable);
1128
- }
1129
1109
  if (cached.componentPropsTable) {
1130
1110
  const table = localTables.componentPropsTable;
1131
1111
  for (const compKey of Object.keys(cached.componentPropsTable)) {
@@ -1286,8 +1266,6 @@ function scanAll(scanCwd = process.cwd()) {
1286
1266
  createHashTable: {},
1287
1267
  createObjectTable: {},
1288
1268
  createAtomicMapTable: {},
1289
- variantsHashTable: {},
1290
- variantsObjectTable: {},
1291
1269
  createStaticHashTable: {},
1292
1270
  createStaticObjectTable: {},
1293
1271
  hasCssUsage: false,
@@ -1347,8 +1325,6 @@ function scanAll(scanCwd = process.cwd()) {
1347
1325
  const localCreateHashTable = {};
1348
1326
  const localCreateObjectTable = {};
1349
1327
  const localCreateAtomicMapTable = {};
1350
- const localVariantsHashTable = {};
1351
- const localVariantsObjectTable = {};
1352
1328
  const localCreateThemeHashTable = {};
1353
1329
  const localCreateStaticHashTable = {};
1354
1330
  const localCreateStaticObjectTable = {};
@@ -1567,7 +1543,7 @@ function scanAll(scanCwd = process.cwd()) {
1567
1543
  const objExpression = isCreateTheme
1568
1544
  ? init.arguments[1].expression
1569
1545
  : init.arguments[0].expression;
1570
- const obj = objectExpressionToObject(objExpression, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localVariantsHashTable, resolveVariable);
1546
+ const obj = objectExpressionToObject(objExpression, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable);
1571
1547
  const uniqueKey = `${filePath}-${name}`;
1572
1548
  if (method === 'createStatic') {
1573
1549
  localStaticTable[name] = obj;
@@ -1633,7 +1609,7 @@ function scanAll(scanCwd = process.cwd()) {
1633
1609
  inlineOuterScope(objExpression, (property) => objectExpressionToObject({
1634
1610
  ...objExpression,
1635
1611
  properties: [property],
1636
- }, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localVariantsHashTable, resolveVariable));
1612
+ }, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable));
1637
1613
  const hashMap = {};
1638
1614
  Object.entries(obj).forEach(([key, style]) => {
1639
1615
  const records = (0, create_1.getStyleRecords)(style);
@@ -1645,14 +1621,6 @@ function scanAll(scanCwd = process.cwd()) {
1645
1621
  localTables.createAtomicMapTable[hash] = hashMap;
1646
1622
  registerObjectOwner('createAtomicMapTable', hash, filePath);
1647
1623
  }
1648
- else if (method === 'variants') {
1649
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
1650
- localVariantsHashTable[name] = hash;
1651
- localTables.variantsHashTable[uniqueKey] = hash;
1652
- localTables.variantsObjectTable[hash] = obj;
1653
- localVariantsObjectTable[hash] = obj;
1654
- registerObjectOwner('variantsObjectTable', hash, filePath);
1655
- }
1656
1624
  }
1657
1625
  }
1658
1626
  }
@@ -1676,8 +1644,6 @@ function scanAll(scanCwd = process.cwd()) {
1676
1644
  localCreateHashTable,
1677
1645
  localCreateObjectTable,
1678
1646
  localCreateAtomicMapTable,
1679
- localVariantsHashTable,
1680
- localVariantsObjectTable,
1681
1647
  localCreateThemeHashTable,
1682
1648
  localCreateStaticHashTable,
1683
1649
  localCreateStaticObjectTable,
@@ -1692,7 +1658,7 @@ function scanAll(scanCwd = process.cwd()) {
1692
1658
  for (const entry of jsxPhaseQueue) {
1693
1659
  try {
1694
1660
  delete fileErrors[entry.filePath];
1695
- const { filePath, ast, mtimeMs, localDependencies, localStaticTable, localKeyframesHashTable, localKeyframesObjectTable, localViewTransitionHashTable, localViewTransitionObjectTable, localCreateThemeObjectTable, localCreateThemeSelectorTable, localCreateHashTable, localCreateObjectTable, localCreateAtomicMapTable, localVariantsHashTable, localVariantsObjectTable, localCreateThemeHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localImports, } = entry;
1661
+ const { filePath, ast, mtimeMs, localDependencies, localStaticTable, localKeyframesHashTable, localKeyframesObjectTable, localViewTransitionHashTable, localViewTransitionObjectTable, localCreateThemeObjectTable, localCreateThemeSelectorTable, localCreateHashTable, localCreateObjectTable, localCreateAtomicMapTable, localCreateThemeHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localImports, } = entry;
1696
1662
  const localCreateFunctionTable = {};
1697
1663
  for (const localName of Object.keys(localImports)) {
1698
1664
  const { actualPath, importedName } = localImports[localName];
@@ -1718,7 +1684,6 @@ function scanAll(scanCwd = process.cwd()) {
1718
1684
  createHashTable: localCreateHashTable,
1719
1685
  createStaticHashTable: localCreateStaticHashTable,
1720
1686
  createStaticObjectTable: localTables.createStaticObjectTable,
1721
- variantsHashTable: localVariantsHashTable,
1722
1687
  };
1723
1688
  const dynamicStaticTable = {
1724
1689
  ...collectLocalConsts(ast),
@@ -2072,8 +2037,6 @@ function scanAll(scanCwd = process.cwd()) {
2072
2037
  createHashTable: localCreateHashTable,
2073
2038
  createObjectTable: localCreateObjectTable,
2074
2039
  createAtomicMapTable: localCreateAtomicMapTable,
2075
- variantsHashTable: localVariantsHashTable,
2076
- variantsObjectTable: localVariantsObjectTable,
2077
2040
  createStaticHashTable: localCreateStaticHashTable,
2078
2041
  createStaticObjectTable: localCreateStaticObjectTable,
2079
2042
  componentPropsTable: localComponentPropsTable,
@@ -2261,8 +2224,6 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2261
2224
  createHashTable: {},
2262
2225
  createObjectTable: {},
2263
2226
  createAtomicMapTable: {},
2264
- variantsHashTable: {},
2265
- variantsObjectTable: {},
2266
2227
  createStaticHashTable: {},
2267
2228
  createStaticObjectTable: {},
2268
2229
  hasCssUsage: false,
package/dist/types.d.ts CHANGED
@@ -14,8 +14,6 @@ export type CreateThemeObjectTable = Record<string, CSSObject>;
14
14
  export type CreateHashTable = Record<string, string>;
15
15
  export type CreateObjectTable = Record<string, CSSObject>;
16
16
  export type CreateFunctionTable = Record<string, ObjectExpression>;
17
- export type VariantsHashTable = Record<string, string>;
18
- export type VariantsObjectTable = Record<string, CSSObject>;
19
17
  export type CreateAtomicMapTable = Record<string, Record<string, Record<string, string>>>;
20
18
  export type CreateStaticHashTable = Record<string, string>;
21
19
  export type CreateStaticObjectTable = Record<string, CSSObject>;
@@ -49,8 +47,6 @@ export interface Tables {
49
47
  createAtomicMapTable: CreateAtomicMapTable;
50
48
  createStaticHashTable: CreateStaticHashTable;
51
49
  createStaticObjectTable: CreateStaticObjectTable;
52
- variantsHashTable: VariantsHashTable;
53
- variantsObjectTable: VariantsObjectTable;
54
50
  componentPropsTable?: Record<string, Record<string, TableEntry[]>>;
55
51
  }
56
52
  export type CreateTheme = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "18.5.1",
3
+ "version": "18.5.3",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -1,13 +0,0 @@
1
- import type { CSSObject } from './types';
2
- type CompoundEntry = {
3
- keys: string[];
4
- map: Record<string, string>;
5
- };
6
- type IndependentHashMap = Record<string, Record<string, string>>;
7
- type VariantsHashMap = IndependentHashMap & {
8
- _compound?: CompoundEntry[];
9
- };
10
- export declare function processVariants(variants: Record<string, Record<string, CSSObject>>): {
11
- hashMap: VariantsHashMap;
12
- };
13
- export {};
package/dist/variants.js DELETED
@@ -1,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processVariants = processVariants;
4
- const parser_1 = require("./parser");
5
- const create_1 = require("./create");
6
- function processVariants(variants) {
7
- const variantKeys = Object.keys(variants);
8
- const variantProperties = {};
9
- variantKeys.forEach((key) => {
10
- variantProperties[key] = new Set();
11
- Object.values(variants[key]).forEach((style) => {
12
- Object.keys(style).forEach((prop) => variantProperties[key].add(prop));
13
- });
14
- });
15
- const conflicts = {};
16
- variantKeys.forEach((key) => (conflicts[key] = new Set()));
17
- for (let i = 0; i < variantKeys.length; i++) {
18
- for (let j = i + 1; j < variantKeys.length; j++) {
19
- const keyA = variantKeys[i];
20
- const keyB = variantKeys[j];
21
- let hasConflict = false;
22
- for (const prop of variantProperties[keyA]) {
23
- if (variantProperties[keyB].has(prop)) {
24
- hasConflict = true;
25
- break;
26
- }
27
- }
28
- if (hasConflict) {
29
- conflicts[keyA].add(keyB);
30
- conflicts[keyB].add(keyA);
31
- }
32
- }
33
- }
34
- const visited = new Set();
35
- const independentKeys = [];
36
- const compoundGroups = [];
37
- variantKeys.forEach((key) => {
38
- if (visited.has(key))
39
- return;
40
- const queue = [key];
41
- const component = new Set();
42
- while (queue.length > 0) {
43
- const curr = queue.shift();
44
- if (component.has(curr))
45
- continue;
46
- component.add(curr);
47
- visited.add(curr);
48
- conflicts[curr].forEach((neighbor) => {
49
- if (!visited.has(neighbor)) {
50
- queue.push(neighbor);
51
- }
52
- });
53
- }
54
- if (component.size === 1) {
55
- independentKeys.push(key);
56
- }
57
- else {
58
- compoundGroups.push(Array.from(component));
59
- }
60
- });
61
- const hashMap = {};
62
- independentKeys.forEach((key) => {
63
- const optionMap = {};
64
- Object.entries(variants[key]).forEach(([optKey, style]) => {
65
- const records = (0, create_1.getStyleRecords)(style);
66
- optionMap[optKey] = records.map((r) => r.hash).join(' ');
67
- });
68
- hashMap[key] = optionMap;
69
- });
70
- if (compoundGroups.length > 0) {
71
- hashMap._compound = compoundGroups.map((groupKeys) => {
72
- const compoundMap = {};
73
- const generateCombinations = (depth, currentCombo) => {
74
- if (depth === groupKeys.length) {
75
- let mergedStyle = {};
76
- const comboKeyParts = [];
77
- groupKeys.forEach((k) => {
78
- const opt = currentCombo[k];
79
- comboKeyParts.push(opt || 'default');
80
- if (opt && variants[k][opt]) {
81
- mergedStyle = (0, parser_1.deepMerge)(mergedStyle, variants[k][opt]);
82
- }
83
- });
84
- const records = (0, create_1.getStyleRecords)(mergedStyle);
85
- const className = records.map((r) => r.hash).join(' ');
86
- if (className) {
87
- compoundMap[comboKeyParts.join(':')] = className;
88
- }
89
- return;
90
- }
91
- const key = groupKeys[depth];
92
- const options = Object.keys(variants[key]);
93
- const effectiveOptions = new Set(options);
94
- effectiveOptions.add('default');
95
- effectiveOptions.forEach((opt) => {
96
- generateCombinations(depth + 1, { ...currentCombo, [key]: opt });
97
- });
98
- };
99
- generateCombinations(0, {});
100
- return {
101
- keys: groupKeys,
102
- map: compoundMap,
103
- };
104
- });
105
- }
106
- return {
107
- hashMap,
108
- };
109
- }