domflax 0.1.1 → 0.1.4

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 (46) hide show
  1. package/README.md +25 -8
  2. package/dist/{chunk-DNHOGPYV.js → chunk-3Z5ZWLXX.js} +407 -51
  3. package/dist/chunk-3Z5ZWLXX.js.map +1 -0
  4. package/dist/{chunk-DOQEBGWB.js → chunk-5FWENSD2.js} +63 -8
  5. package/dist/chunk-5FWENSD2.js.map +1 -0
  6. package/dist/chunk-EVENAJYI.js +336 -0
  7. package/dist/chunk-EVENAJYI.js.map +1 -0
  8. package/dist/{chunk-DWLB7FRR.js → chunk-H5KTGI3A.js} +153 -7
  9. package/dist/chunk-H5KTGI3A.js.map +1 -0
  10. package/dist/{chunk-6WVVF6AD.js → chunk-U5GOONKV.js} +5 -2
  11. package/dist/{chunk-6WVVF6AD.js.map → chunk-U5GOONKV.js.map} +1 -1
  12. package/dist/cli.cjs +1033 -178
  13. package/dist/cli.cjs.map +1 -1
  14. package/dist/cli.js +285 -243
  15. package/dist/cli.js.map +1 -1
  16. package/dist/index.cjs +614 -68
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +34 -18
  19. package/dist/index.d.ts +34 -18
  20. package/dist/index.js +4 -4
  21. package/dist/{pattern-F5xBtIE-.d.cts → pattern-CP9_HpVK.d.cts} +1 -1
  22. package/dist/{pattern-CV607P87.d.ts → pattern-CYgsv-jO.d.ts} +1 -1
  23. package/dist/pattern-kit.cjs.map +1 -1
  24. package/dist/pattern-kit.d.cts +2 -2
  25. package/dist/pattern-kit.d.ts +2 -2
  26. package/dist/pattern-kit.js +2 -2
  27. package/dist/{resolve-ops-DIwEelH-.d.ts → resolve-ops-Ci7LgYHC.d.cts} +9 -0
  28. package/dist/{resolve-ops-DIwEelH-.d.cts → resolve-ops-Ci7LgYHC.d.ts} +9 -0
  29. package/dist/verify.d.cts +1 -1
  30. package/dist/verify.d.ts +1 -1
  31. package/dist/verify.js +1 -1
  32. package/dist/webpack-loader.cjs +614 -68
  33. package/dist/webpack-loader.cjs.map +1 -1
  34. package/dist/webpack-loader.d.cts +2 -2
  35. package/dist/webpack-loader.d.ts +2 -2
  36. package/dist/webpack-loader.js +4 -4
  37. package/dist/worker.cjs +5955 -0
  38. package/dist/worker.cjs.map +1 -0
  39. package/dist/worker.d.cts +2 -0
  40. package/dist/worker.d.ts +2 -0
  41. package/dist/worker.js +72 -0
  42. package/dist/worker.js.map +1 -0
  43. package/package.json +4 -2
  44. package/dist/chunk-DNHOGPYV.js.map +0 -1
  45. package/dist/chunk-DOQEBGWB.js.map +0 -1
  46. package/dist/chunk-DWLB7FRR.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  init_esm_shims
3
- } from "./chunk-6WVVF6AD.js";
3
+ } from "./chunk-U5GOONKV.js";
4
4
 
5
5
  // ../core/src/builders.ts
6
6
  init_esm_shims();
@@ -72,6 +72,7 @@ function defaultMeta(safetyFloor = 0) {
72
72
  declaresCustomProperties: false,
73
73
  whitespaceSensitive: false,
74
74
  touched: false,
75
+ styleDirty: false,
75
76
  synthetic: false,
76
77
  safetyFloor
77
78
  };
@@ -286,6 +287,14 @@ function markTouched(state, id) {
286
287
  state.touched.add(id);
287
288
  }
288
289
  }
290
+ function markStyleDirty(state, id) {
291
+ const n = state.doc.nodes.get(id);
292
+ if (n) {
293
+ n.meta.touched = true;
294
+ n.meta.styleDirty = true;
295
+ state.touched.add(id);
296
+ }
297
+ }
289
298
  function removeSubtree(state, id) {
290
299
  const node = state.doc.nodes.get(id);
291
300
  if (!node) return;
@@ -578,7 +587,7 @@ function applyOne(state, op) {
578
587
  return [precond(op, op.target, "setClassList target is not an element")];
579
588
  }
580
589
  el.computed = cloneStyleMap(op.style);
581
- markTouched(state, op.target);
590
+ markStyleDirty(state, op.target);
582
591
  return [];
583
592
  }
584
593
  case "mergeStyle": {
@@ -601,7 +610,7 @@ function applyOne(state, op) {
601
610
  const src = doc.nodes.get(op.source);
602
611
  if (src) markTouched(state, op.source);
603
612
  }
604
- markTouched(state, op.target);
613
+ markStyleDirty(state, op.target);
605
614
  return [];
606
615
  }
607
616
  case "foldInheritedStyles":
@@ -652,7 +661,7 @@ function applyFold(state, op) {
652
661
  }
653
662
  if (folded) {
654
663
  into.computed = { blocks: nextBlocks };
655
- markTouched(state, intoId);
664
+ markStyleDirty(state, intoId);
656
665
  }
657
666
  }
658
667
  for (const d of issues) state.diagnostics.push(d);
@@ -990,8 +999,123 @@ init_esm_shims();
990
999
  var DISPLAY = "display";
991
1000
  var POSITION = "position";
992
1001
  var TRANSFORM = "transform";
1002
+ var ALIGN_ITEMS = "align-items";
1003
+ var JUSTIFY_CONTENT = "justify-content";
1004
+ var JUSTIFY_ITEMS = "justify-items";
1005
+ var PLACE_ITEMS = "place-items";
1006
+ var PLACE_SELF = "place-self";
993
1007
  var CONTEXT_SAFE_DISPLAYS = /* @__PURE__ */ new Set(["block", "contents", ""]);
994
1008
  var STATIC_POSITIONS = /* @__PURE__ */ new Set(["static", ""]);
1009
+ var CENTERING_DISPLAYS = /* @__PURE__ */ new Set(["flex", "grid"]);
1010
+ var GRID_PARENT_DISPLAYS = /* @__PURE__ */ new Set(["grid"]);
1011
+ var STRETCHY_ITEM_ALIGN = /* @__PURE__ */ new Set(["normal", "stretch"]);
1012
+ var PARENT_ITEMS_ALIGN_PROPS = [ALIGN_ITEMS, JUSTIFY_ITEMS, PLACE_ITEMS];
1013
+ function isBaseCondition(block) {
1014
+ const c = block.condition;
1015
+ return c.media === "" && c.states.length === 0 && c.pseudoElement === "";
1016
+ }
1017
+ function baseValue(sm, prop) {
1018
+ for (const block of sm.blocks.values()) {
1019
+ if (!isBaseCondition(block)) continue;
1020
+ const d = block.decls.get(prop);
1021
+ return d ? String(d.value) : null;
1022
+ }
1023
+ return null;
1024
+ }
1025
+ function parentIsFillingGrid(before, wrapper, norm) {
1026
+ if (wrapper.parent == null) return false;
1027
+ const p = before.nodes.get(wrapper.parent);
1028
+ if (!p || p.kind !== "element") return false;
1029
+ const pc = norm.normalizeStyleMap(p.computed);
1030
+ let baseIsGrid = false;
1031
+ for (const block of pc.blocks.values()) {
1032
+ const disp = block.decls.get(DISPLAY);
1033
+ if (disp) {
1034
+ if (!GRID_PARENT_DISPLAYS.has(String(disp.value))) return false;
1035
+ if (isBaseCondition(block)) baseIsGrid = true;
1036
+ }
1037
+ for (const prop of PARENT_ITEMS_ALIGN_PROPS) {
1038
+ const d = block.decls.get(prop);
1039
+ if (d && !STRETCHY_ITEM_ALIGN.has(String(d.value))) return false;
1040
+ }
1041
+ }
1042
+ return baseIsGrid;
1043
+ }
1044
+ function wrapperHasOnlyCenteringStyle(wrapperComputed, childComputed, norm) {
1045
+ for (const block of wrapperComputed.blocks.values()) {
1046
+ const base = isBaseCondition(block);
1047
+ const ck = conditionKey(block.condition);
1048
+ for (const [prop, decl] of block.decls) {
1049
+ const val = String(decl.value);
1050
+ if (prop === DISPLAY) {
1051
+ if (base && CENTERING_DISPLAYS.has(val)) continue;
1052
+ return false;
1053
+ }
1054
+ if (prop === ALIGN_ITEMS) {
1055
+ if (base && val === "center") continue;
1056
+ return false;
1057
+ }
1058
+ if (prop === JUSTIFY_CONTENT) {
1059
+ if (base && val === "center") continue;
1060
+ return false;
1061
+ }
1062
+ if (prop === POSITION) {
1063
+ if (STATIC_POSITIONS.has(val)) continue;
1064
+ return false;
1065
+ }
1066
+ if (prop === TRANSFORM) {
1067
+ if (val === "none") continue;
1068
+ return false;
1069
+ }
1070
+ if (isInherited2(decl, norm)) continue;
1071
+ if (childReproduces(childComputed, ck, prop, val)) continue;
1072
+ return false;
1073
+ }
1074
+ }
1075
+ return true;
1076
+ }
1077
+ function wrapperCentersSingleElement(before, wrapper) {
1078
+ let elements = 0;
1079
+ for (const cid of wrapper.children) {
1080
+ const n = before.nodes.get(cid);
1081
+ if (!n) continue;
1082
+ if (n.kind === "element") {
1083
+ elements += 1;
1084
+ continue;
1085
+ }
1086
+ if (n.kind === "comment") continue;
1087
+ if (n.kind === "text" && n.value.trim() === "") continue;
1088
+ return false;
1089
+ }
1090
+ return elements === 1;
1091
+ }
1092
+ function childHasSelfAlign(childBefore, norm) {
1093
+ if (!childBefore) return false;
1094
+ const sm = norm.normalizeStyleMap(childBefore);
1095
+ for (const block of sm.blocks.values()) {
1096
+ for (const prop of SELF_ALIGN_PROPS) {
1097
+ const d = block.decls.get(prop);
1098
+ if (d && !NEUTRAL_ALIGN.has(String(d.value))) return true;
1099
+ }
1100
+ }
1101
+ return false;
1102
+ }
1103
+ function childGainsPlaceSelfCenter(childAfter) {
1104
+ if (baseValue(childAfter, PLACE_SELF) === "center") return true;
1105
+ return baseValue(childAfter, "align-self") === "center" && baseValue(childAfter, "justify-self") === "center";
1106
+ }
1107
+ function isContextCompensatedCentering(before, wrapper, wrapperComputed, childBefore, childAfter, norm) {
1108
+ if (!childAfter) return false;
1109
+ if (!CENTERING_DISPLAYS.has(baseValue(wrapperComputed, DISPLAY) ?? "")) return false;
1110
+ if (baseValue(wrapperComputed, ALIGN_ITEMS) !== "center") return false;
1111
+ if (baseValue(wrapperComputed, JUSTIFY_CONTENT) !== "center") return false;
1112
+ const childAfterNorm = norm.normalizeStyleMap(childAfter);
1113
+ if (!childGainsPlaceSelfCenter(childAfterNorm)) return false;
1114
+ if (!wrapperHasOnlyCenteringStyle(wrapperComputed, childAfterNorm, norm)) return false;
1115
+ if (!wrapperCentersSingleElement(before, wrapper)) return false;
1116
+ if (childHasSelfAlign(childBefore, norm)) return false;
1117
+ return parentIsFillingGrid(before, wrapper, norm);
1118
+ }
995
1119
  var SELF_ALIGN_PROPS = [
996
1120
  "place-self",
997
1121
  "align-self",
@@ -1091,6 +1215,9 @@ function classifyFlattenOps(before, after, ops, norm) {
1091
1215
  const wrapperComputed = norm.normalizeStyleMap(wrapper.computed);
1092
1216
  const childAfter = childId != null ? getElement(after, childId)?.computed ?? null : null;
1093
1217
  const childBefore = childId != null ? getElement(before, childId)?.computed ?? null : null;
1218
+ if (isContextCompensatedCentering(before, wrapper, wrapperComputed, childBefore, childAfter, norm)) {
1219
+ return { kind: "provably-safe", wrapperId, childId };
1220
+ }
1094
1221
  if (establishesChildContext(wrapperComputed)) {
1095
1222
  return { kind: "needs-verification", wrapperId, childId };
1096
1223
  }
@@ -1529,15 +1656,34 @@ function sameTokens(a, b) {
1529
1656
  for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return false;
1530
1657
  return true;
1531
1658
  }
1659
+ function residualStyle(computed2, covered, norm) {
1660
+ const cov = norm.normalizeStyleMap(covered);
1661
+ const blocks = /* @__PURE__ */ new Map();
1662
+ for (const [key, block] of norm.normalizeStyleMap(computed2).blocks) {
1663
+ const covBlock = cov.blocks.get(key);
1664
+ const decls = /* @__PURE__ */ new Map();
1665
+ for (const [prop, decl] of block.decls) {
1666
+ const covDecl = covBlock?.decls.get(prop);
1667
+ if (covDecl && covDecl.value === decl.value && covDecl.important === decl.important) continue;
1668
+ decls.set(prop, decl);
1669
+ }
1670
+ if (decls.size > 0) blocks.set(key, { condition: block.condition, decls });
1671
+ }
1672
+ return { blocks };
1673
+ }
1532
1674
  function syncClassesFromComputed(doc, resolver, norm) {
1533
1675
  const sink = createSyntheticSink();
1534
1676
  for (const id of elementIds(doc)) {
1535
1677
  const el = getElement(doc, id);
1536
- if (!el || !el.meta.touched) continue;
1678
+ if (!el) continue;
1679
+ if (!el.meta.styleDirty) continue;
1537
1680
  if (el.classes.opaque || el.classes.hasDynamic) continue;
1538
1681
  const tokens = staticTokensOf(el.classes);
1682
+ const retained = tokens.filter((t) => !resolver.selectorUsage(t).droppable);
1683
+ const covered = retained.length > 0 ? resolver.resolve({ classes: retained }).styles : null;
1684
+ const target = covered ? residualStyle(el.computed, covered, norm) : el.computed;
1539
1685
  const ctx = { normalizer: norm, sink };
1540
- const emitted = resolver.emit(el.computed, ctx).classes;
1686
+ const emitted = resolver.emit(target, ctx).classes;
1541
1687
  if (emitted.length === 0) continue;
1542
1688
  const emittedSet = new Set(emitted);
1543
1689
  const next = [];
@@ -2209,4 +2355,4 @@ export {
2209
2355
  definePattern,
2210
2356
  pattern
2211
2357
  };
2212
- //# sourceMappingURL=chunk-DWLB7FRR.js.map
2358
+ //# sourceMappingURL=chunk-H5KTGI3A.js.map