@fluentic/style 0.1.0-beta.5 → 0.1.0-beta.7

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.
Files changed (186) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +105 -31
  3. package/atomic/className.ts +19 -2
  4. package/atomic/utils/hash.ts +1 -65
  5. package/compiler/compiler/compiler.ts +85 -8
  6. package/compiler/cssProp.ts +0 -14
  7. package/compiler/transform/cssProp/plugin.ts +33 -1
  8. package/compiler/transform/evaluator/evaluator.ts +1 -0
  9. package/compiler/transform/extract/chain/chain.ts +120 -11
  10. package/compiler/utils/import_source.ts +17 -7
  11. package/dist/{combine-Ca6LfFxv.js → combine-D0AXSTn-.js} +2 -2
  12. package/dist/{combine-Ca6LfFxv.js.map → combine-D0AXSTn-.js.map} +1 -1
  13. package/dist/compiler/index.mjs +1 -1
  14. package/dist/{compiler-OgDBuqfs.mjs → compiler-CCvRlaq0.mjs} +141 -89
  15. package/dist/compiler-CCvRlaq0.mjs.map +1 -0
  16. package/dist/{config-Barf8f4B.js → config-B-w6rOe0.js} +2 -2
  17. package/dist/{config-Barf8f4B.js.map → config-B-w6rOe0.js.map} +1 -1
  18. package/dist/{config-CsB4MuFI.js → config-B1WtpYar.js} +2 -2
  19. package/dist/{config-CsB4MuFI.js.map → config-B1WtpYar.js.map} +1 -1
  20. package/dist/{config-t76UljYv.js → config-CCMwA9Gm.js} +2 -2
  21. package/dist/{config-t76UljYv.js.map → config-CCMwA9Gm.js.map} +1 -1
  22. package/dist/{createTransformElement-DDqld3RF.js → createTransformElement-PCilcudP.js} +2 -2
  23. package/dist/{createTransformElement-DDqld3RF.js.map → createTransformElement-PCilcudP.js.map} +1 -1
  24. package/dist/{css-a9O5so0b.js → css-DirG7Jwu.js} +41 -7
  25. package/dist/css-DirG7Jwu.js.map +1 -0
  26. package/dist/{css-YfHN_8Nk.js → css-nmclCl2P.js} +8 -8
  27. package/dist/{css-YfHN_8Nk.js.map → css-nmclCl2P.js.map} +1 -1
  28. package/dist/{css-CZwrac6F.js → css-shX7_73D.js} +12 -41
  29. package/dist/css-shX7_73D.js.map +1 -0
  30. package/dist/css.js +1 -1
  31. package/dist/{data-CzHJg147.js → data-DUvixly5.js} +14 -6
  32. package/dist/data-DUvixly5.js.map +1 -0
  33. package/dist/{debug-DkrxyknP.js → debug-DJRCBKhM.js} +2 -2
  34. package/dist/{debug-DkrxyknP.js.map → debug-DJRCBKhM.js.map} +1 -1
  35. package/dist/dev/rsc.js +5 -5
  36. package/dist/{dev-z4laBwlS.js → dev-Cwha8aAp.js} +4 -4
  37. package/dist/{dev-z4laBwlS.js.map → dev-Cwha8aAp.js.map} +1 -1
  38. package/dist/dev.js +1 -1
  39. package/dist/dialect/extracted/index.js +1 -1
  40. package/dist/dialect/index.js +1 -1
  41. package/dist/{elementMarker-CqhU_l_m.js → elementMarker-Cb46vtLU.js} +3 -3
  42. package/dist/{elementMarker-CqhU_l_m.js.map → elementMarker-Cb46vtLU.js.map} +1 -1
  43. package/dist/entry/dev/adapter/preact.js +2 -2
  44. package/dist/entry/dev/adapter/react.js +2 -2
  45. package/dist/entry/dev/adapter/solid.js +2 -2
  46. package/dist/entry/dev/css.js +2 -2
  47. package/dist/entry/dev/jsx-dev-runtime.js +2 -2
  48. package/dist/entry/dev/jsx-runtime.js +2 -2
  49. package/dist/entry/dev.js +8 -8
  50. package/dist/entry/prod/adapter/preact.js +1 -1
  51. package/dist/entry/prod/adapter/react.js +1 -1
  52. package/dist/entry/prod/adapter/solid.js +1 -1
  53. package/dist/entry/prod/css.js +2 -2
  54. package/dist/entry/prod.js +2 -3
  55. package/dist/entry/prod.js.map +1 -1
  56. package/dist/entry/rsc-dev/adapter/preact.js +5 -4
  57. package/dist/entry/rsc-dev/adapter/preact.js.map +1 -1
  58. package/dist/entry/rsc-dev/adapter/react.js +5 -4
  59. package/dist/entry/rsc-dev/adapter/react.js.map +1 -1
  60. package/dist/entry/rsc-dev/adapter/solid.js +5 -4
  61. package/dist/entry/rsc-dev/adapter/solid.js.map +1 -1
  62. package/dist/entry/rsc-dev/css.js +2 -2
  63. package/dist/entry/rsc-dev/dev.js +5 -6
  64. package/dist/entry/rsc-dev/dev.js.map +1 -1
  65. package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
  66. package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
  67. package/dist/entry/rsc-dev.js +5 -6
  68. package/dist/entry/rsc-dev.js.map +1 -1
  69. package/dist/entry/rsc-prod/css.js +2 -2
  70. package/dist/entry/rsc-prod.js +2 -2
  71. package/dist/{env-Db2cRt-h.js → env-0Gu2Jh47.js} +2 -39
  72. package/dist/env-0Gu2Jh47.js.map +1 -0
  73. package/dist/{utils-CLnpwhJd.js → getClassName-CHZKhmde.js} +5 -43
  74. package/dist/getClassName-CHZKhmde.js.map +1 -0
  75. package/dist/{getClassName-DaZF5nfJ.js → getClassName-CHd0iCXp.js} +3 -3
  76. package/dist/{getClassName-DaZF5nfJ.js.map → getClassName-CHd0iCXp.js.map} +1 -1
  77. package/dist/global-Dg37z0lV.js +14 -0
  78. package/dist/global-Dg37z0lV.js.map +1 -0
  79. package/dist/{hash-BOlQThNz.js → hash-Cr-LCWDt.js} +2 -40
  80. package/dist/hash-Cr-LCWDt.js.map +1 -0
  81. package/dist/index.js +6 -6
  82. package/dist/jsx/jsx-dev-runtime.js +1 -1
  83. package/dist/jsx/jsx-dev-runtime.server.js +1 -1
  84. package/dist/jsx/jsx-runtime.js +1 -1
  85. package/dist/jsx/jsx-runtime.server.js +1 -1
  86. package/dist/{jsx-C2pnWLcb.js → jsx-BMFC8_tA.js} +4 -4
  87. package/dist/{jsx-C2pnWLcb.js.map → jsx-BMFC8_tA.js.map} +1 -1
  88. package/dist/{jsx_runtime-XJSHujgI.js → jsx_runtime-Ch1pZ6-n.js} +2 -2
  89. package/dist/{jsx_runtime-XJSHujgI.js.map → jsx_runtime-Ch1pZ6-n.js.map} +1 -1
  90. package/dist/{loader-DHvgp0fK.mjs → loader-hNaefW-U.mjs} +13 -14
  91. package/dist/loader-hNaefW-U.mjs.map +1 -0
  92. package/dist/{misc-BuSLnvx0.mjs → misc-1OS0aeY1.mjs} +2 -2
  93. package/dist/{misc-BuSLnvx0.mjs.map → misc-1OS0aeY1.mjs.map} +1 -1
  94. package/dist/{namedTokens-D3tt-joz.js → namedTokens-mgRfd9hs.js} +3 -3
  95. package/dist/{namedTokens-D3tt-joz.js.map → namedTokens-mgRfd9hs.js.map} +1 -1
  96. package/dist/plugin/farm/index.mjs +3 -3
  97. package/dist/plugin/nextjs/index.mjs +120 -16
  98. package/dist/plugin/nextjs/index.mjs.map +1 -1
  99. package/dist/plugin/nextjs/loader.mjs +4 -4
  100. package/dist/plugin/parcel/index.cjs +1 -1
  101. package/dist/plugin/parcel/index.mjs +2 -2
  102. package/dist/plugin/parcel/optimizer.cjs +1 -1
  103. package/dist/plugin/parcel/optimizer.mjs +2 -2
  104. package/dist/plugin/parcel/resolver.cjs +1 -1
  105. package/dist/plugin/parcel/resolver.mjs +2 -2
  106. package/dist/plugin/parcel/runtime.cjs +1 -1
  107. package/dist/plugin/parcel/runtime.mjs +1 -1
  108. package/dist/plugin/parcel/transformer.cjs +1 -1
  109. package/dist/plugin/parcel/transformer.mjs +2 -2
  110. package/dist/plugin/rspack/index.mjs +2 -2
  111. package/dist/plugin/vite/index.mjs +3 -3
  112. package/dist/plugin/webpack/index.mjs +2 -2
  113. package/dist/plugin/webpack/loader.mjs +2 -2
  114. package/dist/presets/tailwind/index.js +25 -3
  115. package/dist/presets/tailwind/index.js.map +1 -1
  116. package/dist/{registry-r3BKWqpI.mjs → registry-OA0niXJL.mjs} +2 -2
  117. package/dist/{registry-r3BKWqpI.mjs.map → registry-OA0niXJL.mjs.map} +1 -1
  118. package/dist/{resolveClassNameRuntime-D5a37GNr.js → resolveClassNameRuntime-BKXT1bmR.js} +2 -2
  119. package/dist/{resolveClassNameRuntime-D5a37GNr.js.map → resolveClassNameRuntime-BKXT1bmR.js.map} +1 -1
  120. package/dist/{rules-B0_rKPfB.js → rules-DgcCENkw.js} +5 -5
  121. package/dist/{rules-B0_rKPfB.js.map → rules-DgcCENkw.js.map} +1 -1
  122. package/dist/server.js +10 -10
  123. package/dist/{shared-8_Msr7Q5.cjs → shared-Bc9RwNNj.cjs} +140 -88
  124. package/dist/shared-Bc9RwNNj.cjs.map +1 -0
  125. package/dist/{shared-BGO_05rW.mjs → shared-COiLPdZ1.mjs} +4 -4
  126. package/dist/{shared-BGO_05rW.mjs.map → shared-COiLPdZ1.mjs.map} +1 -1
  127. package/dist/sheet-B87QCFWF.js +7 -0
  128. package/dist/{sheet-BpLZIIuO.js.map → sheet-B87QCFWF.js.map} +1 -1
  129. package/dist/{sidecar-Bu2x35JE.mjs → sidecar-ViZUL9B8.mjs} +3 -3
  130. package/dist/{sidecar-Bu2x35JE.mjs.map → sidecar-ViZUL9B8.mjs.map} +1 -1
  131. package/dist/{types-BEUgXuu2.js → style-DFsOmxLg.js} +7 -8
  132. package/dist/{types-BEUgXuu2.js.map → style-DFsOmxLg.js.map} +1 -1
  133. package/dist/{styleStore-BDy5TH6N.js → styleStore-BlC8Ax9f.js} +3 -3
  134. package/dist/{styleStore-BDy5TH6N.js.map → styleStore-BlC8Ax9f.js.map} +1 -1
  135. package/dist/{styleStore-DX3z_UVK.js → styleStore-DHzH25A7.js} +2 -2
  136. package/dist/{styleStore-DX3z_UVK.js.map → styleStore-DHzH25A7.js.map} +1 -1
  137. package/dist/{token-BsW_S8fN.js → token-CAQWMtan.js} +2 -2
  138. package/dist/{token-BsW_S8fN.js.map → token-CAQWMtan.js.map} +1 -1
  139. package/dist/{trace-BdKEpgME.js → trace-D3yBmJad.js} +2 -2
  140. package/dist/{trace-BdKEpgME.js.map → trace-D3yBmJad.js.map} +1 -1
  141. package/dist/{trace-DcuMxR45.js → trace-DdXWjgAD.js} +3 -3
  142. package/dist/{trace-DcuMxR45.js.map → trace-DdXWjgAD.js.map} +1 -1
  143. package/dist/utils-B6HVRX10.js +42 -0
  144. package/dist/utils-B6HVRX10.js.map +1 -0
  145. package/dist/{utils-BPDxr-oc.mjs → utils-C7UalRKf.mjs} +41 -7
  146. package/dist/utils-C7UalRKf.mjs.map +1 -0
  147. package/dist/{utils-sBVZEq4u.js → utils-Cd4wqN56.js} +2 -39
  148. package/dist/utils-Cd4wqN56.js.map +1 -0
  149. package/dist/{utils-DZjLTV4D.mjs → utils-DjxH0zc7.mjs} +3 -3
  150. package/dist/{utils-DZjLTV4D.mjs.map → utils-DjxH0zc7.mjs.map} +1 -1
  151. package/dist/utils-DxCpyV2E.js +62 -0
  152. package/dist/utils-DxCpyV2E.js.map +1 -0
  153. package/dist/utils.js +2 -2
  154. package/dist/{webpack-DTKgR-HY.mjs → webpack-6et2ZVI6.mjs} +5 -5
  155. package/dist/{webpack-DTKgR-HY.mjs.map → webpack-6et2ZVI6.mjs.map} +1 -1
  156. package/entry/rsc_dev/adapter/preact.ts +9 -1
  157. package/entry/rsc_dev/adapter/react.ts +9 -1
  158. package/entry/rsc_dev/adapter/solid.ts +9 -1
  159. package/jsx/types/index.ts +0 -2
  160. package/package.json +30 -11
  161. package/plugin/bundler/webpack/shared/loader.ts +9 -7
  162. package/plugin/nextjs/plugin.ts +205 -15
  163. package/plugin/nextjs/types.ts +1 -2
  164. package/plugin/nextjs/utils.ts +50 -0
  165. package/presets/tailwind/classname/transform.ts +32 -1
  166. package/runtime/adapter/utils.ts +40 -14
  167. package/dist/compiler-OgDBuqfs.mjs.map +0 -1
  168. package/dist/css-CZwrac6F.js.map +0 -1
  169. package/dist/css-a9O5so0b.js.map +0 -1
  170. package/dist/css_extra-CXXZAylc.js +0 -8
  171. package/dist/css_extra-CXXZAylc.js.map +0 -1
  172. package/dist/data-CzHJg147.js.map +0 -1
  173. package/dist/env-Db2cRt-h.js.map +0 -1
  174. package/dist/getClassName-DKtQl5ZX.js +0 -32
  175. package/dist/getClassName-DKtQl5ZX.js.map +0 -1
  176. package/dist/global-zYTvWskP.js +0 -10
  177. package/dist/global-zYTvWskP.js.map +0 -1
  178. package/dist/hash-BOlQThNz.js.map +0 -1
  179. package/dist/loader-DHvgp0fK.mjs.map +0 -1
  180. package/dist/shared-8_Msr7Q5.cjs.map +0 -1
  181. package/dist/sheet-BpLZIIuO.js +0 -7
  182. package/dist/utils-BPDxr-oc.mjs.map +0 -1
  183. package/dist/utils-CLnpwhJd.js.map +0 -1
  184. package/dist/utils-okFWrQsg.js +0 -41
  185. package/dist/utils-okFWrQsg.js.map +0 -1
  186. package/dist/utils-sBVZEq4u.js.map +0 -1
@@ -350,11 +350,14 @@ function createCssPropPlugin(args) {
350
350
  }
351
351
  },
352
352
  JSXOpeningElement(path, state) {
353
+ const keyHoistedAttributes = hoistKeyAttributes(path.node.attributes);
354
+ if (keyHoistedAttributes) path.node.attributes = keyHoistedAttributes;
353
355
  if (!getCssPropOptions(state.options) || !state.mergeId) return;
354
356
  if (!isIntrinsicElement(path.node.name)) return;
355
357
  if (!hasCssAttribute(path.node.attributes)) return;
356
- const parts = path.node.attributes.map((attr) => buildPart(t, attr));
357
- path.node.attributes = [t.jsxSpreadAttribute(t.callExpression(state.mergeId, [t.arrayExpression(parts)]))];
358
+ const keyAttributes = path.node.attributes.filter(isKeyAttribute);
359
+ const parts = path.node.attributes.filter((attr) => !isKeyAttribute(attr)).map((attr) => buildPart(t, attr));
360
+ path.node.attributes = [...keyAttributes, t.jsxSpreadAttribute(t.callExpression(state.mergeId, [t.arrayExpression(parts)]))];
358
361
  state.changed = true;
359
362
  }
360
363
  }
@@ -372,6 +375,17 @@ function hasCssAttribute(attrs) {
372
375
  return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "css";
373
376
  });
374
377
  }
378
+ function hoistKeyAttributes(attrs) {
379
+ const keyAttributes = attrs.filter(isKeyAttribute);
380
+ if (!keyAttributes.length) return null;
381
+ const firstKeyIndex = attrs.findIndex(isKeyAttribute);
382
+ const firstSpreadIndex = attrs.findIndex((attr) => attr.type === "JSXSpreadAttribute");
383
+ if (firstSpreadIndex < 0 || firstKeyIndex < firstSpreadIndex) return null;
384
+ return [...keyAttributes, ...attrs.filter((attr) => !isKeyAttribute(attr))];
385
+ }
386
+ function isKeyAttribute(attr) {
387
+ return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "key";
388
+ }
375
389
  function buildPart(t, attr) {
376
390
  if (attr.type === "JSXSpreadAttribute") return attr.argument;
377
391
  return t.objectExpression([t.objectProperty(getObjectKey(t, attr.name), getAttributeValue(t, attr))]);
@@ -1252,46 +1266,9 @@ function formatScopeClassName$1(format, info) {
1252
1266
  }
1253
1267
  //#endregion
1254
1268
  //#region atomic/utils/hash.ts
1255
- const POOLED_HASH_STATE = globalData("atomic.hashPool", () => ({
1256
- byValue: /* @__PURE__ */ new Map(),
1257
- byHash: /* @__PURE__ */ new Map(),
1258
- usedByLength: []
1259
- }));
1260
1269
  function getIdentifierSafeHash(value, startLength = 7) {
1261
- return getPooledHash(value, startLength);
1262
- }
1263
- function getPooledHash(value, startLength) {
1264
1270
  const normalizedStartLength = normalizeHashLength(startLength);
1265
- const valueKey = normalizedStartLength + "\0" + value;
1266
- const existing = POOLED_HASH_STATE.byValue.get(valueKey);
1267
- if (existing) return existing;
1268
- let length = normalizedStartLength;
1269
- while (true) {
1270
- if (getPooledHashUsedCount(length) >= getIdentifierSafeHashPoolSize(length)) {
1271
- length++;
1272
- continue;
1273
- }
1274
- for (let index = 0; index < getIdentifierSafeHashPoolSize(length); index++) {
1275
- const hash = getPooledHashCandidate(value, length, index);
1276
- const owner = POOLED_HASH_STATE.byHash.get(hash);
1277
- if (owner !== void 0 && owner !== valueKey) continue;
1278
- POOLED_HASH_STATE.byValue.set(valueKey, hash);
1279
- POOLED_HASH_STATE.byHash.set(hash, valueKey);
1280
- POOLED_HASH_STATE.usedByLength[length] = getPooledHashUsedCount(length) + 1;
1281
- return hash;
1282
- }
1283
- length++;
1284
- }
1285
- }
1286
- function getPooledHashCandidate(value, length, index) {
1287
- return getIdentifierSafeHashValue(hashString(index === 0 ? value : value + "::" + index)).slice(0, length);
1288
- }
1289
- function getPooledHashUsedCount(length) {
1290
- return POOLED_HASH_STATE.usedByLength[length] ?? 0;
1291
- }
1292
- function getIdentifierSafeHashPoolSize(length) {
1293
- if (length <= 0) return 0;
1294
- return 26 * 36 ** (length - 1);
1271
+ return getIdentifierSafeHashValue(hashString(value)).slice(0, normalizedStartLength);
1295
1272
  }
1296
1273
  function getIdentifierSafeHashValue(hash) {
1297
1274
  const first = hash.charCodeAt(0);
@@ -1341,8 +1318,16 @@ function getAtomicClassName(property, priority, important, value, selector, pare
1341
1318
  });
1342
1319
  }
1343
1320
  function getRuntimeClassNameHashLength(debugClassName) {
1344
- if (debugClassName && DEV_CONFIG.isDev) return DEV_CONFIG.hashLength ?? CSS_CONFIG.hashLength ?? 3;
1345
- return CSS_CONFIG.hashLength ?? 7;
1321
+ return getClassNameHashLength({
1322
+ debugClassName,
1323
+ isDev: DEV_CONFIG.isDev,
1324
+ devHashLength: DEV_CONFIG.hashLength,
1325
+ cssHashLength: CSS_CONFIG.hashLength
1326
+ });
1327
+ }
1328
+ function getClassNameHashLength(options) {
1329
+ if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 3;
1330
+ return options.cssHashLength ?? 7;
1346
1331
  }
1347
1332
  function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
1348
1333
  let hash = property;
@@ -3598,9 +3583,11 @@ function createImportSourceMatcher(importSources) {
3598
3583
  meta: DefaultStyleFnMeta
3599
3584
  });
3600
3585
  importSources?.forEach((entry) => {
3586
+ const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
3587
+ if (!meta) return;
3601
3588
  addImportSourceEntry(state, {
3602
3589
  ...entry,
3603
- meta: getStyleFnMeta(entry.styleFn)
3590
+ meta
3604
3591
  });
3605
3592
  });
3606
3593
  return (source) => {
@@ -5859,7 +5846,7 @@ function compileChain(chain, fileId, nodeLoc, scope, opts, runtimeMode, meta, st
5859
5846
  if (!meta) return null;
5860
5847
  if (meta.mode === "ClassName") {
5861
5848
  if (chain.kind !== "style") return null;
5862
- return compileClassNameChain(chain, meta.selectors, fileId, scope, css, meta.transform, styleNames, opts);
5849
+ return compileClassNameChain(chain, meta.selectors, fileId, nodeLoc, scope, css, meta.transform, styleNames, opts);
5863
5850
  }
5864
5851
  const selectors = meta.selectors;
5865
5852
  const transform = meta.transform;
@@ -5950,14 +5937,19 @@ function compileSelectorStyleArg(styleArgNode, fileId, scope, cssConfig, transfo
5950
5937
  function getCssConfig(opts, runtimeMode) {
5951
5938
  const css = opts.css;
5952
5939
  const isDevRuntimeMode = runtimeMode === "dev" || runtimeMode === "rsc-dev";
5940
+ const debugClassName = css?.debugClassName ?? isDevRuntimeMode;
5953
5941
  return {
5954
5942
  classNameFormat: css?.classNameFormat ?? DEFAULT_CONFIG.classNameFormat ?? null,
5955
5943
  sheetClassNameFormat: css?.sheetClassNameFormat ?? DEFAULT_CONFIG.sheetClassNameFormat ?? null,
5956
5944
  transformClassNameFormat: css?.transformClassNameFormat ?? DEFAULT_CONFIG.transformClassNameFormat ?? null,
5957
- hashLength: css?.hashLength ?? DEFAULT_CONFIG.hashLength ?? 7,
5945
+ hashLength: getClassNameHashLength({
5946
+ debugClassName,
5947
+ isDev: isDevRuntimeMode,
5948
+ cssHashLength: css?.hashLength ?? DEFAULT_CONFIG.hashLength
5949
+ }),
5958
5950
  tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
5959
5951
  localClassName: isDevRuntimeMode,
5960
- debugClassName: css?.debugClassName ?? isDevRuntimeMode,
5952
+ debugClassName,
5961
5953
  scopeTargetPrefix: css?.scopeTargetPrefix ?? ""
5962
5954
  };
5963
5955
  }
@@ -5975,10 +5967,10 @@ function compileStyleChain(chain, selectors, fileId, scope, cssConfig, transform
5975
5967
  rules
5976
5968
  };
5977
5969
  }
5978
- function compileClassNameChain(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options) {
5970
+ function compileClassNameChain(chain, selectors, fileId, nodeLoc, scope, cssConfig, transform, styleNames, options) {
5979
5971
  const items = [];
5980
5972
  const rules = [];
5981
- if (!compileClassNameArgsInto(chain.baseArgs, 0, null, null, fileId, scope, cssConfig, transform, 1, null, items, rules)) return null;
5973
+ if (!compileClassNameArgsInto(chain.baseArgs, 0, null, null, fileId, scope, createClassNameFallbackLocation(nodeLoc, scope, fileId), cssConfig, transform, 1, null, items, rules)) return null;
5982
5974
  let i = 0;
5983
5975
  while (i < chain.methods.length) {
5984
5976
  const method = chain.methods[i];
@@ -6000,7 +5992,7 @@ function compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig
6000
5992
  const localChain = getLocalStyleChainArg(method.args[0], scope, styleNames);
6001
5993
  const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
6002
5994
  if (localChain?.kind === "style" && localMeta?.mode === "ClassName") {
6003
- const result = compileClassNameChain(localChain, localMeta.selectors, fileId, scope, cssConfig, localMeta.transform, styleNames, options);
5995
+ const result = compileClassNameChain(localChain, localMeta.selectors, fileId, method.nameNode.loc?.start, scope, cssConfig, localMeta.transform, styleNames, options);
6004
5996
  if (!result) return false;
6005
5997
  items.push(...result.items);
6006
5998
  rules.push(...result.rules);
@@ -6025,7 +6017,7 @@ function compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig
6025
6017
  }
6026
6018
  const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
6027
6019
  const classNameOffset = hasArg ? argOffset + 1 : argOffset;
6028
- return compileClassNameArgsInto(method.args, classNameOffset, null, [atRuleSelector], fileId, scope, cssConfig, transform, 1, null, items, rules);
6020
+ return compileClassNameArgsInto(method.args, classNameOffset, null, [atRuleSelector], fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
6029
6021
  }
6030
6022
  if (selectorStr.includes("$$") || selectorStr.includes("$")) {
6031
6023
  const splitToken = selectorStr.includes("$$") ? "$$" : "$";
@@ -6035,14 +6027,15 @@ function compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig
6035
6027
  if (!selectorArg.ok) return false;
6036
6028
  const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
6037
6029
  const itemSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
6038
- return compileClassNameArgsInto(method.args, 1, itemSelector, null, fileId, scope, cssConfig, transform, 1, null, items, rules);
6030
+ return compileClassNameArgsInto(method.args, 1, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
6039
6031
  }
6040
6032
  const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
6041
- return compileClassNameArgsInto(method.args, 0, itemSelector, null, fileId, scope, cssConfig, transform, 1, null, items, rules);
6033
+ return compileClassNameArgsInto(method.args, 0, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
6042
6034
  }
6043
- function compileClassNameArgsInto(args, startIndex, selector, atRules, fileId, scope, cssConfig, transform, type, slotId, items, rules) {
6035
+ function compileClassNameArgsInto(args, startIndex, selector, atRules, fileId, scope, fallbackLocation, cssConfig, transform, type, slotId, items, rules) {
6044
6036
  if (startIndex >= args.length) return true;
6045
6037
  const styleObj = {};
6038
+ const locations = {};
6046
6039
  let i = startIndex;
6047
6040
  while (i < args.length) {
6048
6041
  const arg = evaluateNode(args[i], scope);
@@ -6050,28 +6043,59 @@ function compileClassNameArgsInto(args, startIndex, selector, atRules, fileId, s
6050
6043
  throwIfRequiredStaticStyleValue(arg);
6051
6044
  return false;
6052
6045
  }
6053
- if (!appendClassNameArgStyle(arg.value, transform, styleObj)) return false;
6046
+ if (!appendClassNameArgStyle(args[i], arg.value, transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
6054
6047
  i++;
6055
6048
  }
6049
+ if (Object.keys(locations).length) Object.defineProperty(styleObj, COMPILED_STYLE_OBJECT_LOCATIONS, {
6050
+ configurable: true,
6051
+ enumerable: false,
6052
+ value: locations
6053
+ });
6056
6054
  return addStyleItems(styleObj, selector, null, atRules, fileId, type, slotId, items, rules, cssConfig);
6057
6055
  }
6058
- function appendClassNameArgStyle(value, transform, styleObj) {
6056
+ function appendClassNameArgStyle(node, value, transform, styleObj, locations, fallbackLocation, scope, fileId) {
6059
6057
  if (!value) return true;
6060
6058
  if (typeof value === "string") {
6061
- Object.assign(styleObj, decorateClassNameStyle(transform.transform(value), value));
6059
+ const transformed = decorateClassNameStyle(transform.transform(value), value);
6060
+ Object.assign(styleObj, transformed);
6061
+ assignClassNameStyleLocations(transformed, locations, getClassNameArgLocation(node, fallbackLocation, scope, fileId));
6062
6062
  return true;
6063
6063
  }
6064
6064
  if (Array.isArray(value)) {
6065
- for (const item of value) if (!appendClassNameArgStyle(item, transform, styleObj)) return false;
6065
+ const nodes = node.type === "ArrayExpression" ? node.elements : [];
6066
+ for (let i = 0; i < value.length; i++) if (!appendClassNameArgStyle(nodes[i] ?? node, value[i], transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
6066
6067
  return true;
6067
6068
  }
6068
6069
  if (isWeightedClassName(value)) {
6069
6070
  const transformed = decorateClassNameStyle(transform.transform(value.className), value.className);
6070
6071
  Object.assign(styleObj, applyClassNameWeight(transformed, value.weight));
6072
+ assignClassNameStyleLocations(transformed, locations, getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId));
6071
6073
  return true;
6072
6074
  }
6073
6075
  return false;
6074
6076
  }
6077
+ function assignClassNameStyleLocations(styleObj, locations, location) {
6078
+ if (!location) return;
6079
+ for (const property of Object.keys(styleObj)) locations[property] = location;
6080
+ }
6081
+ function getClassNameArgLocation(node, fallbackLocation, scope, fileId) {
6082
+ if (node.type === "StringLiteral") return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
6083
+ if (node.type === "TemplateLiteral" && node.expressions.length === 0) return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
6084
+ return fallbackLocation;
6085
+ }
6086
+ function getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId) {
6087
+ if (node.type === "CallExpression" && node.arguments[0] && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "weight") return getClassNameArgLocation(node.arguments[0], fallbackLocation, scope, fileId);
6088
+ return fallbackLocation;
6089
+ }
6090
+ function createClassNameFallbackLocation(loc, scope, fileId) {
6091
+ if (!loc) return null;
6092
+ return {
6093
+ filePath: scope.styleFilePath ?? fileId,
6094
+ line: loc.line,
6095
+ column: loc.column + 1,
6096
+ variable: false
6097
+ };
6098
+ }
6075
6099
  function decorateClassNameStyle(style, className) {
6076
6100
  const result = {};
6077
6101
  for (const [property, value] of Object.entries(style)) {
@@ -6923,7 +6947,7 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
6923
6947
  column: propertyLoc.column
6924
6948
  } : null);
6925
6949
  const shouldUseVariable = !!(token || runtimeValue);
6926
- const variableName = shouldUseVariable && propertyLoc ? getLocalVarName(propertyLoc.filePath ?? fileId, propertyLoc.line, propertyLoc.column, cssConfig.tokenNameFormat) : null;
6950
+ const variableName = shouldUseVariable && propertyLoc && propertyLoc.variable !== false ? getLocalVarName(propertyLoc.filePath ?? fileId, propertyLoc.line, propertyLoc.column, cssConfig.tokenNameFormat) : null;
6927
6951
  const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
6928
6952
  const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules);
6929
6953
  const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
@@ -8266,10 +8290,10 @@ function createCompiler(args, options) {
8266
8290
  const tracer = createTracer(internal);
8267
8291
  const collector = createCssCollector();
8268
8292
  const compileDebug = (args) => {
8269
- return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
8293
+ return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8270
8294
  };
8271
8295
  const compileDebugRSC = (args) => {
8272
- const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
8296
+ const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8273
8297
  if (!debugResult) return null;
8274
8298
  const rscCollector = createCssCollector();
8275
8299
  transformExtract(internal, args, {
@@ -8298,7 +8322,7 @@ function createCompiler(args, options) {
8298
8322
  return rewriteTransformResult({
8299
8323
  ...result,
8300
8324
  rules: collector.getItems().slice(startIndex)
8301
- }, internal.runtimeMode);
8325
+ }, internal.runtimeMode, args.code);
8302
8326
  };
8303
8327
  const getExtractedCss = () => {
8304
8328
  return extractCss(collector.getItems(), {
@@ -8328,46 +8352,74 @@ function createCompilerInternal(args, options) {
8328
8352
  options
8329
8353
  };
8330
8354
  }
8331
- function rewriteTransformResult(result, runtimeMode) {
8355
+ function rewriteTransformResult(result, runtimeMode, sourceCode) {
8332
8356
  if (!result || !runtimeMode) return result;
8333
8357
  return {
8334
8358
  ...result,
8335
- code: rewriteCompilerRuntimeImports(result.code, runtimeMode)
8359
+ code: rewriteCompilerRuntimeImports(result.code, runtimeMode, sourceCode)
8336
8360
  };
8337
8361
  }
8338
- function rewriteCompilerRuntimeImports(code, runtimeMode) {
8339
- return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode));
8362
+ function rewriteCompilerRuntimeImports(code, runtimeMode, sourceCode) {
8363
+ const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
8364
+ return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode));
8365
+ }
8366
+ function getImportRuntimeMode(runtimeMode, sourceCode) {
8367
+ if (runtimeMode === "rsc-dev" && hasUseClientDirective(sourceCode)) return "dev";
8368
+ return runtimeMode;
8340
8369
  }
8341
- function getCompilerRuntimeImportSource(source, runtimeMode) {
8342
- if (source === "@fluentic/style") return getStyleRuntimeImportPath(runtimeMode);
8343
- const adapterImportPath = getStyleRuntimeAdapterImportPath(source, runtimeMode);
8370
+ function getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode) {
8371
+ if (source === "@fluentic/style") return getStyleRuntimeImportPath(importRuntimeMode);
8372
+ const adapterImportPath = getStyleRuntimeAdapterImportPath(source, importRuntimeMode);
8344
8373
  if (adapterImportPath) return adapterImportPath;
8345
- if (source === "@fluentic/style/css") return getStyleRuntimeCssImportPath(runtimeMode);
8374
+ if (source === "@fluentic/style/css") return getStyleRuntimeCssImportPath(importRuntimeMode);
8346
8375
  if (source === "@fluentic/style/entry/prod/runtime") return getStyleExtractRuntimeImportPath(runtimeMode);
8347
8376
  if (runtimeMode === "rsc-dev" && source === "@fluentic/style/dev/rsc") return getStyleRuntimeDevRscImportPath(runtimeMode);
8348
8377
  return null;
8349
8378
  }
8350
- const CssPropPresets = {
8351
- Solid: {
8352
- classProp: "class",
8353
- styleProp: "style",
8354
- styleMode: "solid",
8355
- adapter: "@fluentic/style/adapter/solid"
8356
- },
8357
- Preact: {
8358
- classProp: "class",
8359
- styleProp: "style",
8360
- styleMode: "react",
8361
- adapter: "@fluentic/style/adapter/preact"
8362
- },
8363
- React: {
8364
- classProp: "className",
8365
- styleProp: "style",
8366
- styleMode: "react",
8367
- adapter: "@fluentic/style/adapter/react"
8379
+ function hasUseClientDirective(code) {
8380
+ let index = 0;
8381
+ while (index < code.length) {
8382
+ index = skipWhitespaceAndComments(code, index);
8383
+ const quote = code[index];
8384
+ if (quote !== "\"" && quote !== "'") return false;
8385
+ const end = code.indexOf(quote, index + 1);
8386
+ if (end < 0) return false;
8387
+ const directive = code.slice(index + 1, end);
8388
+ index = skipWhitespaceAndComments(code, end + 1);
8389
+ if (code[index] === ";") index += 1;
8390
+ else if (code[index] && code[index] !== "\n" && code[index] !== "\r") return false;
8391
+ if (directive === "use client") return true;
8392
+ }
8393
+ return false;
8394
+ }
8395
+ function skipWhitespaceAndComments(code, index) {
8396
+ let next = index;
8397
+ while (next < code.length) {
8398
+ const char = code[next];
8399
+ if (char === " " || char === " " || char === "\n" || char === "\r") {
8400
+ next += 1;
8401
+ continue;
8402
+ }
8403
+ if (char === "/" && code[next + 1] === "/") {
8404
+ const lineEnd = code.indexOf("\n", next + 2);
8405
+ next = lineEnd < 0 ? code.length : lineEnd + 1;
8406
+ continue;
8407
+ }
8408
+ if (char === "/" && code[next + 1] === "*") {
8409
+ const commentEnd = code.indexOf("*/", next + 2);
8410
+ next = commentEnd < 0 ? code.length : commentEnd + 2;
8411
+ continue;
8412
+ }
8413
+ break;
8368
8414
  }
8415
+ return next;
8416
+ }
8417
+ const CssPropPresets = {
8418
+ Solid: { adapter: "@fluentic/style/adapter/solid" },
8419
+ Preact: { adapter: "@fluentic/style/adapter/preact" },
8420
+ React: { adapter: "@fluentic/style/adapter/react" }
8369
8421
  };
8370
8422
  //#endregion
8371
- export { getDefaultSourcemapUrl as a, isPromiseLike as c, extractCss as d, compareLayerPriority as f, createCompilerCache as h, CompilerRuntimeMode as i, babelPlugin as l, globalData as m, createCompiler as n, normalizeSourcemapSourcePath as o, SIDECAR_URL_GLOBAL_SYMBOL as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelTransform as u };
8423
+ export { getDefaultSourcemapUrl as a, getStyleFnMeta as c, babelTransform as d, extractCss as f, createCompilerCache as g, globalData as h, CompilerRuntimeMode as i, isPromiseLike as l, SIDECAR_URL_GLOBAL_SYMBOL as m, createCompiler as n, normalizeSourcemapSourcePath as o, compareLayerPriority as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelPlugin as u };
8372
8424
 
8373
- //# sourceMappingURL=compiler-OgDBuqfs.mjs.map
8425
+ //# sourceMappingURL=compiler-CCvRlaq0.mjs.map