@plumeria/turbopack-loader 18.3.17 → 18.4.0

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export interface LoaderOptions {
1
+ import type { PropertyPolicyOptions } from '@plumeria/utils';
2
+ export interface LoaderOptions extends PropertyPolicyOptions {
2
3
  include?: string[];
3
4
  exclude?: string[];
4
5
  styleProp?: string;
package/dist/index.js CHANGED
@@ -63,6 +63,8 @@ async function generateProductionCss(virtualFilePath, options) {
63
63
  exclude: options.exclude ?? DEFAULT_EXCLUDE,
64
64
  cwd: process.cwd(),
65
65
  styleProp: options.styleProp ?? utils_1.DEFAULT_STYLE_PROP,
66
+ withoutLogicalProperties: options.withoutLogicalProperties,
67
+ withoutPhysicalProperties: options.withoutPhysicalProperties,
66
68
  });
67
69
  const optimized = await (0, utils_1.optimizer)(css);
68
70
  const tempPath = `${virtualFilePath}.${process.pid}.tmp`;
@@ -205,17 +207,45 @@ const foldDynamicVars = (vars) => {
205
207
  return `"${cssVar}": ${value}`;
206
208
  });
207
209
  };
208
- const findVarProp = (style, cssVar) => {
210
+ const isUnitlessProp = (prop) => zss_engine_1.exceptionCamelCase.includes(prop) || prop.startsWith('--');
211
+ const collectVarProps = (style, cssVar, props) => {
212
+ const reference = `var(${cssVar})`;
213
+ for (const [prop, value] of Object.entries(style)) {
214
+ if (typeof value === 'string' && value.includes(reference))
215
+ props.push(prop);
216
+ else if (value !== null && typeof value === 'object')
217
+ collectVarProps(value, cssVar, props);
218
+ }
219
+ };
220
+ const retargetVar = (style, cssVar, next, unitless) => {
221
+ const reference = `var(${cssVar})`;
209
222
  for (const [prop, value] of Object.entries(style)) {
210
- if (typeof value === 'string' && value.includes(cssVar))
211
- return prop;
212
- if (value !== null && typeof value === 'object') {
213
- const nested = findVarProp(value, cssVar);
214
- if (nested)
215
- return nested;
223
+ if (typeof value === 'string' && value.includes(reference)) {
224
+ if (isUnitlessProp(prop) === unitless)
225
+ style[prop] = value
226
+ .split(reference)
227
+ .join(`var(${next})`);
228
+ }
229
+ else if (value !== null && typeof value === 'object') {
230
+ retargetVar(value, cssVar, next, unitless);
216
231
  }
217
232
  }
218
- return undefined;
233
+ };
234
+ const splitVarByUnit = (style, cssVar) => {
235
+ const props = [];
236
+ collectVarProps(style, cssVar, props);
237
+ if (props.length === 0)
238
+ return [];
239
+ const lead = props[0];
240
+ const split = props.find((prop) => isUnitlessProp(prop) !== isUnitlessProp(lead));
241
+ if (!split)
242
+ return [{ cssVar, prop: lead }];
243
+ const splitVar = `${cssVar}-${(0, zss_engine_1.camelToKebabCase)(split).replace(/^-+/, '')}`;
244
+ retargetVar(style, cssVar, splitVar, isUnitlessProp(split));
245
+ return [
246
+ { cssVar, prop: lead },
247
+ { cssVar: splitVar, prop: split },
248
+ ];
219
249
  };
220
250
  const applyVarFallback = (style, cssVar, literal) => {
221
251
  const reference = `var(${cssVar})`;
@@ -236,6 +266,7 @@ async function loader(source) {
236
266
  (typeof this.query === 'object' ? this.query : undefined) ??
237
267
  {};
238
268
  const styleProp = loaderOptions.styleProp ?? utils_1.DEFAULT_STYLE_PROP;
269
+ const propertyPolicy = (0, utils_1.resolvePropertyPolicy)(loaderOptions);
239
270
  const resourcePath = this.resourcePath;
240
271
  const isProduction = process.env.NODE_ENV === 'production';
241
272
  const VIRTUAL_FILE_PATH = path.resolve(__dirname, '..', 'zero-virtual.css');
@@ -251,6 +282,7 @@ async function loader(source) {
251
282
  tsx: true,
252
283
  target: 'es2022',
253
284
  });
285
+ (0, utils_1.assertPropertyPolicy)(ast, propertyPolicy, resourcePath);
254
286
  const leadingLen = (0, utils_1.getLeadingCommentLength)(source);
255
287
  const sourceBuffer = Buffer.from(source, 'utf-8');
256
288
  const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
@@ -1036,47 +1068,48 @@ async function loader(source) {
1036
1068
  const style = (0, utils_1.objectExpressionToObject)(func.body, tempStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
1037
1069
  if (!style)
1038
1070
  return null;
1039
- withDefault.forEach(([param, expr]) => {
1071
+ const varGroups = new Map();
1072
+ varParams.forEach((param) => {
1040
1073
  const cssVar = cssVars[param];
1041
- const targetProp = cssVar ? findVarProp(style, cssVar) : undefined;
1042
- if (!targetProp)
1043
- return;
1074
+ if (cssVar)
1075
+ varGroups.set(param, splitVarByUnit(style, cssVar));
1076
+ });
1077
+ withDefault.forEach(([param, expr]) => {
1044
1078
  const literal = expr.type === 'StringLiteral' || expr.type === 'NumericLiteral'
1045
1079
  ? expr.value
1046
1080
  : undefined;
1047
1081
  if (literal === undefined)
1048
1082
  return;
1049
- applyVarFallback(style, cssVar, literal);
1083
+ (varGroups.get(param) ?? []).forEach(({ cssVar }) => applyVarFallback(style, cssVar, literal));
1050
1084
  });
1051
1085
  const vars = [];
1052
1086
  runtime.forEach(({ param, source }) => {
1053
- const cssVar = cssVars[param];
1054
- const targetProp = cssVar ? findVarProp(style, cssVar) : undefined;
1055
- if (!targetProp)
1087
+ const groups = varGroups.get(param);
1088
+ if (!groups?.length)
1056
1089
  return;
1057
1090
  const argStart = source.span.start - baseByteOffset;
1058
1091
  const argEnd = source.span.end - baseByteOffset;
1059
1092
  const argSource = sourceBuffer
1060
1093
  .subarray(argStart, argEnd)
1061
1094
  .toString('utf-8');
1062
- let valueExpr;
1063
- const kebabProp = (0, zss_engine_1.camelToKebabCase)(targetProp);
1064
- const isUnitless = zss_engine_1.exceptionCamelCase.includes(targetProp) ||
1065
- targetProp.startsWith('--');
1066
1095
  const maybeNumber = Number(argSource);
1067
- if (!isNaN(maybeNumber) && argSource.trim() === String(maybeNumber)) {
1068
- valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(maybeNumber, kebabProp));
1069
- }
1070
- else if ((argSource.startsWith('"') && argSource.endsWith('"')) ||
1071
- (argSource.startsWith("'") && argSource.endsWith("'"))) {
1072
- valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(argSource.slice(1, -1), kebabProp));
1073
- }
1074
- else {
1075
- valueExpr = isUnitless
1076
- ? argSource
1077
- : `(typeof (${argSource}) === 'number' ? (${argSource}) + 'px' : (${argSource}))`;
1078
- }
1079
- vars.push({ cssVar, valueExpr });
1096
+ groups.forEach(({ cssVar, prop }) => {
1097
+ let valueExpr;
1098
+ const kebabProp = (0, zss_engine_1.camelToKebabCase)(prop);
1099
+ if (!isNaN(maybeNumber) && argSource.trim() === String(maybeNumber)) {
1100
+ valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(maybeNumber, kebabProp));
1101
+ }
1102
+ else if ((argSource.startsWith('"') && argSource.endsWith('"')) ||
1103
+ (argSource.startsWith("'") && argSource.endsWith("'"))) {
1104
+ valueExpr = JSON.stringify((0, zss_engine_1.applyCssValue)(argSource.slice(1, -1), kebabProp));
1105
+ }
1106
+ else {
1107
+ valueExpr = isUnitlessProp(prop)
1108
+ ? argSource
1109
+ : `(typeof (${argSource}) === 'number' ? (${argSource}) + 'px' : (${argSource}))`;
1110
+ }
1111
+ vars.push({ cssVar, valueExpr });
1112
+ });
1080
1113
  });
1081
1114
  return { style, vars };
1082
1115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.3.17",
3
+ "version": "18.4.0",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -29,12 +29,12 @@
29
29
  "zero-virtual.css"
30
30
  ],
31
31
  "dependencies": {
32
- "@plumeria/compiler": "^18.3.17",
33
- "@plumeria/utils": "^18.3.17"
32
+ "@plumeria/compiler": "^18.4.0",
33
+ "@plumeria/utils": "^18.4.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@swc/core": "1.15.47",
37
- "zss-engine": "2.7.0"
37
+ "zss-engine": "2.8.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public",