@plumeria/utils 18.5.2 → 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);
@@ -359,7 +354,7 @@ function collectLocalConsts(ast) {
359
354
  result = resolveValue(init.value);
360
355
  }
361
356
  else if (exports.t.isObjectExpression(init)) {
362
- result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, {}, resolveValue);
357
+ result = objectExpressionToObject(init, localConsts, {}, {}, {}, {}, {}, {}, {}, resolveValue);
363
358
  }
364
359
  else if (exports.t.isBinaryExpression(init) ||
365
360
  exports.t.isTemplateLiteral(init) ||
@@ -865,16 +860,6 @@ function resolveCreateTableMemberExpression(node, createHashTable) {
865
860
  return createHashTable[node.value];
866
861
  }
867
862
  }
868
- function resolveVariantsTableMemberExpression(node, variantsHashTable) {
869
- if (exports.t.isIdentifier(node)) {
870
- return variantsHashTable[node.value];
871
- }
872
- if (exports.t.isMemberExpression(node)) {
873
- if (exports.t.isIdentifier(node.object)) {
874
- return variantsHashTable[node.object.value];
875
- }
876
- }
877
- }
878
863
  function resolveStaticTableMemberExpression(node, staticTable) {
879
864
  const keys = [];
880
865
  let current = node;
@@ -1015,8 +1000,6 @@ const globalAgregatedTables = {
1015
1000
  createObjectTable: {},
1016
1001
  createFunctionTable: {},
1017
1002
  createAtomicMapTable: {},
1018
- variantsHashTable: {},
1019
- variantsObjectTable: {},
1020
1003
  createThemeHashTable: {},
1021
1004
  createStaticHashTable: {},
1022
1005
  createStaticObjectTable: {},
@@ -1102,9 +1085,6 @@ function stripFileContributions(filePath, cached) {
1102
1085
  delete localTables.createHashTable[`${filePath}-${key}`];
1103
1086
  delete localTables.createFunctionTable[`${filePath}-${key}`];
1104
1087
  }
1105
- for (const key of Object.keys(cached.variantsHashTable)) {
1106
- delete localTables.variantsHashTable[`${filePath}-${key}`];
1107
- }
1108
1088
  for (const key of Object.keys(cached.createStaticObjectTable)) {
1109
1089
  releaseObjectOwner('createStaticObjectTable', key, filePath, localTables.createStaticObjectTable);
1110
1090
  }
@@ -1126,9 +1106,6 @@ function stripFileContributions(filePath, cached) {
1126
1106
  for (const key of Object.keys(cached.createAtomicMapTable)) {
1127
1107
  releaseObjectOwner('createAtomicMapTable', key, filePath, localTables.createAtomicMapTable);
1128
1108
  }
1129
- for (const key of Object.keys(cached.variantsObjectTable)) {
1130
- releaseObjectOwner('variantsObjectTable', key, filePath, localTables.variantsObjectTable);
1131
- }
1132
1109
  if (cached.componentPropsTable) {
1133
1110
  const table = localTables.componentPropsTable;
1134
1111
  for (const compKey of Object.keys(cached.componentPropsTable)) {
@@ -1289,8 +1266,6 @@ function scanAll(scanCwd = process.cwd()) {
1289
1266
  createHashTable: {},
1290
1267
  createObjectTable: {},
1291
1268
  createAtomicMapTable: {},
1292
- variantsHashTable: {},
1293
- variantsObjectTable: {},
1294
1269
  createStaticHashTable: {},
1295
1270
  createStaticObjectTable: {},
1296
1271
  hasCssUsage: false,
@@ -1350,8 +1325,6 @@ function scanAll(scanCwd = process.cwd()) {
1350
1325
  const localCreateHashTable = {};
1351
1326
  const localCreateObjectTable = {};
1352
1327
  const localCreateAtomicMapTable = {};
1353
- const localVariantsHashTable = {};
1354
- const localVariantsObjectTable = {};
1355
1328
  const localCreateThemeHashTable = {};
1356
1329
  const localCreateStaticHashTable = {};
1357
1330
  const localCreateStaticObjectTable = {};
@@ -1570,7 +1543,7 @@ function scanAll(scanCwd = process.cwd()) {
1570
1543
  const objExpression = isCreateTheme
1571
1544
  ? init.arguments[1].expression
1572
1545
  : init.arguments[0].expression;
1573
- 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);
1574
1547
  const uniqueKey = `${filePath}-${name}`;
1575
1548
  if (method === 'createStatic') {
1576
1549
  localStaticTable[name] = obj;
@@ -1636,7 +1609,7 @@ function scanAll(scanCwd = process.cwd()) {
1636
1609
  inlineOuterScope(objExpression, (property) => objectExpressionToObject({
1637
1610
  ...objExpression,
1638
1611
  properties: [property],
1639
- }, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localVariantsHashTable, resolveVariable));
1612
+ }, scopedStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, resolveVariable));
1640
1613
  const hashMap = {};
1641
1614
  Object.entries(obj).forEach(([key, style]) => {
1642
1615
  const records = (0, create_1.getStyleRecords)(style);
@@ -1648,14 +1621,6 @@ function scanAll(scanCwd = process.cwd()) {
1648
1621
  localTables.createAtomicMapTable[hash] = hashMap;
1649
1622
  registerObjectOwner('createAtomicMapTable', hash, filePath);
1650
1623
  }
1651
- else if (method === 'variants') {
1652
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
1653
- localVariantsHashTable[name] = hash;
1654
- localTables.variantsHashTable[uniqueKey] = hash;
1655
- localTables.variantsObjectTable[hash] = obj;
1656
- localVariantsObjectTable[hash] = obj;
1657
- registerObjectOwner('variantsObjectTable', hash, filePath);
1658
- }
1659
1624
  }
1660
1625
  }
1661
1626
  }
@@ -1679,8 +1644,6 @@ function scanAll(scanCwd = process.cwd()) {
1679
1644
  localCreateHashTable,
1680
1645
  localCreateObjectTable,
1681
1646
  localCreateAtomicMapTable,
1682
- localVariantsHashTable,
1683
- localVariantsObjectTable,
1684
1647
  localCreateThemeHashTable,
1685
1648
  localCreateStaticHashTable,
1686
1649
  localCreateStaticObjectTable,
@@ -1695,7 +1658,7 @@ function scanAll(scanCwd = process.cwd()) {
1695
1658
  for (const entry of jsxPhaseQueue) {
1696
1659
  try {
1697
1660
  delete fileErrors[entry.filePath];
1698
- 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;
1699
1662
  const localCreateFunctionTable = {};
1700
1663
  for (const localName of Object.keys(localImports)) {
1701
1664
  const { actualPath, importedName } = localImports[localName];
@@ -1721,7 +1684,6 @@ function scanAll(scanCwd = process.cwd()) {
1721
1684
  createHashTable: localCreateHashTable,
1722
1685
  createStaticHashTable: localCreateStaticHashTable,
1723
1686
  createStaticObjectTable: localTables.createStaticObjectTable,
1724
- variantsHashTable: localVariantsHashTable,
1725
1687
  };
1726
1688
  const dynamicStaticTable = {
1727
1689
  ...collectLocalConsts(ast),
@@ -2075,8 +2037,6 @@ function scanAll(scanCwd = process.cwd()) {
2075
2037
  createHashTable: localCreateHashTable,
2076
2038
  createObjectTable: localCreateObjectTable,
2077
2039
  createAtomicMapTable: localCreateAtomicMapTable,
2078
- variantsHashTable: localVariantsHashTable,
2079
- variantsObjectTable: localVariantsObjectTable,
2080
2040
  createStaticHashTable: localCreateStaticHashTable,
2081
2041
  createStaticObjectTable: localCreateStaticObjectTable,
2082
2042
  componentPropsTable: localComponentPropsTable,
@@ -2264,8 +2224,6 @@ function extractAndCacheExports(filePath, ast, mtimeMs) {
2264
2224
  createHashTable: {},
2265
2225
  createObjectTable: {},
2266
2226
  createAtomicMapTable: {},
2267
- variantsHashTable: {},
2268
- variantsObjectTable: {},
2269
2227
  createStaticHashTable: {},
2270
2228
  createStaticObjectTable: {},
2271
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.2",
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
- }