domflax 0.1.0 → 0.1.1
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/README.md +159 -0
- package/dist/{chunk-4HHISSMR.js → chunk-DNHOGPYV.js} +2675 -1503
- package/dist/chunk-DNHOGPYV.js.map +1 -0
- package/dist/{chunk-ZJ2S36GY.js → chunk-DOQEBGWB.js} +33 -20
- package/dist/chunk-DOQEBGWB.js.map +1 -0
- package/dist/{chunk-77SLHRN6.js → chunk-DWLB7FRR.js} +341 -176
- package/dist/chunk-DWLB7FRR.js.map +1 -0
- package/dist/cli.cjs +2169 -760
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +183 -91
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3021 -1699
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +477 -54
- package/dist/index.d.ts +477 -54
- package/dist/index.js +49 -3
- package/dist/pattern-CV607P87.d.ts +547 -0
- package/dist/pattern-F5xBtIE-.d.cts +547 -0
- package/dist/pattern-kit.cjs +60 -39
- package/dist/pattern-kit.cjs.map +1 -1
- package/dist/pattern-kit.d.cts +3 -18
- package/dist/pattern-kit.d.ts +3 -18
- package/dist/pattern-kit.js +3 -1
- package/dist/pattern-kit.js.map +1 -1
- package/dist/{types-BQ7l6dVe.d.ts → resolve-ops-DIwEelH-.d.cts} +26 -251
- package/dist/{types-BQ7l6dVe.d.cts → resolve-ops-DIwEelH-.d.ts} +26 -251
- package/dist/verify.d.cts +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/webpack-loader.cjs +2975 -1699
- package/dist/webpack-loader.cjs.map +1 -1
- package/dist/webpack-loader.d.cts +2 -2
- package/dist/webpack-loader.d.ts +2 -2
- package/dist/webpack-loader.js +3 -3
- package/package.json +3 -6
- package/dist/chunk-4HHISSMR.js.map +0 -1
- package/dist/chunk-77SLHRN6.js.map +0 -1
- package/dist/chunk-ZJ2S36GY.js.map +0 -1
- package/dist/pattern-CX6iBzTD.d.ts +0 -237
- package/dist/pattern-P4FIKAUB.d.cts +0 -237
|
@@ -227,7 +227,7 @@ function walk(doc, visitor) {
|
|
|
227
227
|
visit(doc.root, 0);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
// ../core/src/ops.ts
|
|
230
|
+
// ../core/src/ops/runtime.ts
|
|
231
231
|
init_esm_shims();
|
|
232
232
|
function cloneStyleMap(sm) {
|
|
233
233
|
const blocks = /* @__PURE__ */ new Map();
|
|
@@ -295,6 +295,32 @@ function removeSubtree(state, id) {
|
|
|
295
295
|
state.doc.nodes.delete(id);
|
|
296
296
|
state.removed.add(id);
|
|
297
297
|
}
|
|
298
|
+
function precond(op, nodeId, message) {
|
|
299
|
+
return diag("DF_OP_PRECONDITION_FAILED", message, {
|
|
300
|
+
nodeId,
|
|
301
|
+
pattern: op.origin.pattern,
|
|
302
|
+
severity: "error"
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
function primaryTarget(op) {
|
|
306
|
+
switch (op.op) {
|
|
307
|
+
case "removeNode":
|
|
308
|
+
case "unwrap":
|
|
309
|
+
case "replaceWith":
|
|
310
|
+
case "wrap":
|
|
311
|
+
case "moveNode":
|
|
312
|
+
case "setClassList":
|
|
313
|
+
case "mergeStyle":
|
|
314
|
+
return op.target;
|
|
315
|
+
case "insertBefore":
|
|
316
|
+
case "insertAfter":
|
|
317
|
+
return op.anchor;
|
|
318
|
+
case "mergeSiblings":
|
|
319
|
+
return op.first;
|
|
320
|
+
case "foldInheritedStyles":
|
|
321
|
+
return op.from;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
298
324
|
function specToAttrs(map) {
|
|
299
325
|
if (!map || map.size === 0) return { entries: /* @__PURE__ */ new Map(), spreads: [], order: [] };
|
|
300
326
|
const entries = /* @__PURE__ */ new Map();
|
|
@@ -403,6 +429,9 @@ function mergeStyleMaps(target, source, policy) {
|
|
|
403
429
|
}
|
|
404
430
|
return { map: { blocks }, conflict };
|
|
405
431
|
}
|
|
432
|
+
|
|
433
|
+
// ../core/src/ops/apply.ts
|
|
434
|
+
init_esm_shims();
|
|
406
435
|
function safetyOk(state, op, targetId) {
|
|
407
436
|
const opSafety = op.origin.safety;
|
|
408
437
|
if (opSafety > state.ceiling) {
|
|
@@ -629,32 +658,6 @@ function applyFold(state, op) {
|
|
|
629
658
|
for (const d of issues) state.diagnostics.push(d);
|
|
630
659
|
return [];
|
|
631
660
|
}
|
|
632
|
-
function precond(op, nodeId, message) {
|
|
633
|
-
return diag("DF_OP_PRECONDITION_FAILED", message, {
|
|
634
|
-
nodeId,
|
|
635
|
-
pattern: op.origin.pattern,
|
|
636
|
-
severity: "error"
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
function primaryTarget(op) {
|
|
640
|
-
switch (op.op) {
|
|
641
|
-
case "removeNode":
|
|
642
|
-
case "unwrap":
|
|
643
|
-
case "replaceWith":
|
|
644
|
-
case "wrap":
|
|
645
|
-
case "moveNode":
|
|
646
|
-
case "setClassList":
|
|
647
|
-
case "mergeStyle":
|
|
648
|
-
return op.target;
|
|
649
|
-
case "insertBefore":
|
|
650
|
-
case "insertAfter":
|
|
651
|
-
return op.anchor;
|
|
652
|
-
case "mergeSiblings":
|
|
653
|
-
return op.first;
|
|
654
|
-
case "foldInheritedStyles":
|
|
655
|
-
return op.from;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
661
|
function applyOps(doc, ops, ctx) {
|
|
659
662
|
const cloned = cloneDocument(doc);
|
|
660
663
|
const state = {
|
|
@@ -732,15 +735,11 @@ function finalize(state) {
|
|
|
732
735
|
};
|
|
733
736
|
}
|
|
734
737
|
|
|
735
|
-
// ../core/src/
|
|
738
|
+
// ../core/src/ops.ts
|
|
739
|
+
init_esm_shims();
|
|
740
|
+
|
|
741
|
+
// ../core/src/pass-context.ts
|
|
736
742
|
init_esm_shims();
|
|
737
|
-
var DEFAULT_FIXPOINT = {
|
|
738
|
-
maxIterations: 16,
|
|
739
|
-
phases: { flatten: 16, compress: 8, extract: 4 },
|
|
740
|
-
onBudgetExhausted: "warn",
|
|
741
|
-
detectOscillation: true
|
|
742
|
-
};
|
|
743
|
-
var PHASE_ORDER = ["flatten", "compress", "extract"];
|
|
744
743
|
function createNullResolver() {
|
|
745
744
|
const empty = {
|
|
746
745
|
styles: emptyStyleMap(),
|
|
@@ -985,6 +984,134 @@ function buildMatchContext(doc, elementId, resolver, selectors, safety, phase, i
|
|
|
985
984
|
}
|
|
986
985
|
};
|
|
987
986
|
}
|
|
987
|
+
|
|
988
|
+
// ../core/src/flatten-safety.ts
|
|
989
|
+
init_esm_shims();
|
|
990
|
+
var DISPLAY = "display";
|
|
991
|
+
var POSITION = "position";
|
|
992
|
+
var TRANSFORM = "transform";
|
|
993
|
+
var CONTEXT_SAFE_DISPLAYS = /* @__PURE__ */ new Set(["block", "contents", ""]);
|
|
994
|
+
var STATIC_POSITIONS = /* @__PURE__ */ new Set(["static", ""]);
|
|
995
|
+
var SELF_ALIGN_PROPS = [
|
|
996
|
+
"place-self",
|
|
997
|
+
"align-self",
|
|
998
|
+
"justify-self"
|
|
999
|
+
];
|
|
1000
|
+
var NEUTRAL_ALIGN = /* @__PURE__ */ new Set(["auto", "normal", "auto auto", ""]);
|
|
1001
|
+
var FLEX_GRID_DISPLAYS = /* @__PURE__ */ new Set(["flex", "inline-flex", "grid", "inline-grid"]);
|
|
1002
|
+
function establishesChildContext(sm) {
|
|
1003
|
+
for (const block of sm.blocks.values()) {
|
|
1004
|
+
const display = block.decls.get(DISPLAY);
|
|
1005
|
+
if (display && !CONTEXT_SAFE_DISPLAYS.has(String(display.value))) return true;
|
|
1006
|
+
const position = block.decls.get(POSITION);
|
|
1007
|
+
if (position && !STATIC_POSITIONS.has(String(position.value))) return true;
|
|
1008
|
+
const transform = block.decls.get(TRANSFORM);
|
|
1009
|
+
if (transform && String(transform.value) !== "none") return true;
|
|
1010
|
+
}
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
function isInherited2(decl, norm) {
|
|
1014
|
+
if (decl.inherited) return true;
|
|
1015
|
+
try {
|
|
1016
|
+
return norm.inherited.isInherited(decl.property);
|
|
1017
|
+
} catch {
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
function childReproduces(childComputed, conditionK, prop, value) {
|
|
1022
|
+
if (!childComputed) return false;
|
|
1023
|
+
const block = childComputed.blocks.get(conditionK);
|
|
1024
|
+
if (!block) return false;
|
|
1025
|
+
const d = block.decls.get(prop);
|
|
1026
|
+
return d != null && String(d.value) === value;
|
|
1027
|
+
}
|
|
1028
|
+
function dropsOwnStyle(wrapperComputed, childComputed, norm) {
|
|
1029
|
+
for (const block of wrapperComputed.blocks.values()) {
|
|
1030
|
+
const ck = conditionKey(block.condition);
|
|
1031
|
+
for (const [prop, decl] of block.decls) {
|
|
1032
|
+
if (prop === DISPLAY || prop === POSITION || prop === TRANSFORM) continue;
|
|
1033
|
+
if (isInherited2(decl, norm)) continue;
|
|
1034
|
+
if (!childReproduces(childComputed, ck, prop, String(decl.value))) return true;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
function displayOf(el, norm) {
|
|
1040
|
+
if (!el) return "";
|
|
1041
|
+
for (const block of norm.normalizeStyleMap(el.computed).blocks.values()) {
|
|
1042
|
+
if (block.condition.media === "" && block.condition.states.length === 0 && block.condition.pseudoElement === "") {
|
|
1043
|
+
const d = block.decls.get(DISPLAY);
|
|
1044
|
+
if (d) return String(d.value);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return "";
|
|
1048
|
+
}
|
|
1049
|
+
function newParentIsFlexOrGrid(before, wrapper, norm) {
|
|
1050
|
+
if (wrapper.parent == null) return false;
|
|
1051
|
+
const p = before.nodes.get(wrapper.parent);
|
|
1052
|
+
if (!p || p.kind !== "element") return false;
|
|
1053
|
+
return FLEX_GRID_DISPLAYS.has(displayOf(p, norm));
|
|
1054
|
+
}
|
|
1055
|
+
function addsParentContextStyle(childBefore, childAfter, norm) {
|
|
1056
|
+
if (!childAfter) return false;
|
|
1057
|
+
const before = childBefore ? norm.normalizeStyleMap(childBefore) : null;
|
|
1058
|
+
const after = norm.normalizeStyleMap(childAfter);
|
|
1059
|
+
for (const block of after.blocks.values()) {
|
|
1060
|
+
const ck = conditionKey(block.condition);
|
|
1061
|
+
for (const prop of SELF_ALIGN_PROPS) {
|
|
1062
|
+
const d = block.decls.get(prop);
|
|
1063
|
+
if (!d || NEUTRAL_ALIGN.has(String(d.value))) continue;
|
|
1064
|
+
const prev = before?.blocks.get(ck)?.decls.get(prop);
|
|
1065
|
+
if (!prev || String(prev.value) !== String(d.value)) return true;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return false;
|
|
1069
|
+
}
|
|
1070
|
+
function unwrapTargetOf(ops) {
|
|
1071
|
+
for (const op of ops) if (op.op === "unwrap") return op.target;
|
|
1072
|
+
return null;
|
|
1073
|
+
}
|
|
1074
|
+
function survivingChildOf(ops, wrapper, before) {
|
|
1075
|
+
for (const op of ops) if (op.op === "mergeStyle") return op.target;
|
|
1076
|
+
for (const op of ops) if (op.op === "foldInheritedStyles" && op.into.length > 0) return op.into[0];
|
|
1077
|
+
for (const c of wrapper.children) {
|
|
1078
|
+
const n = before.nodes.get(c);
|
|
1079
|
+
if (n && n.kind === "element") return c;
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
function classifyFlattenOps(before, after, ops, norm) {
|
|
1084
|
+
const wrapperId = unwrapTargetOf(ops);
|
|
1085
|
+
if (wrapperId == null) return { kind: "provably-safe", wrapperId: null, childId: null };
|
|
1086
|
+
const wrapper = before.nodes.get(wrapperId);
|
|
1087
|
+
if (!wrapper || wrapper.kind !== "element") {
|
|
1088
|
+
return { kind: "provably-safe", wrapperId: null, childId: null };
|
|
1089
|
+
}
|
|
1090
|
+
const childId = survivingChildOf(ops, wrapper, before);
|
|
1091
|
+
const wrapperComputed = norm.normalizeStyleMap(wrapper.computed);
|
|
1092
|
+
const childAfter = childId != null ? getElement(after, childId)?.computed ?? null : null;
|
|
1093
|
+
const childBefore = childId != null ? getElement(before, childId)?.computed ?? null : null;
|
|
1094
|
+
if (establishesChildContext(wrapperComputed)) {
|
|
1095
|
+
return { kind: "needs-verification", wrapperId, childId };
|
|
1096
|
+
}
|
|
1097
|
+
if (dropsOwnStyle(wrapperComputed, childAfter ? norm.normalizeStyleMap(childAfter) : null, norm)) {
|
|
1098
|
+
return { kind: "needs-verification", wrapperId, childId };
|
|
1099
|
+
}
|
|
1100
|
+
if (addsParentContextStyle(childBefore, childAfter, norm) && !newParentIsFlexOrGrid(before, wrapper, norm)) {
|
|
1101
|
+
return { kind: "needs-verification", wrapperId, childId };
|
|
1102
|
+
}
|
|
1103
|
+
return { kind: "provably-safe", wrapperId, childId };
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// ../core/src/pass-manager.ts
|
|
1107
|
+
init_esm_shims();
|
|
1108
|
+
var DEFAULT_FIXPOINT = {
|
|
1109
|
+
maxIterations: 16,
|
|
1110
|
+
phases: { flatten: 16, compress: 8, extract: 4 },
|
|
1111
|
+
onBudgetExhausted: "warn",
|
|
1112
|
+
detectOscillation: true
|
|
1113
|
+
};
|
|
1114
|
+
var PHASE_ORDER = ["flatten", "compress", "extract"];
|
|
988
1115
|
function stampOrigin(draft, pattern2) {
|
|
989
1116
|
return {
|
|
990
1117
|
...draft,
|
|
@@ -1040,69 +1167,76 @@ function flattenWouldDropStyle(before, after, ops, resolver, normalizer2) {
|
|
|
1040
1167
|
}
|
|
1041
1168
|
return false;
|
|
1042
1169
|
}
|
|
1170
|
+
function flattenVerdict(before, after, ops, ctx) {
|
|
1171
|
+
if (flattenWouldDropStyle(before, after, ops, ctx.resolver, ctx.normalizer)) return "revert";
|
|
1172
|
+
const gate = ctx.gate ?? "all";
|
|
1173
|
+
if (gate === "all") return "commit";
|
|
1174
|
+
const cls = classifyFlattenOps(before, after, ops, ctx.normalizer);
|
|
1175
|
+
return cls.kind === "provably-safe" ? "commit" : "revert";
|
|
1176
|
+
}
|
|
1177
|
+
function evaluateElement(doc, elId, patterns, ctx, factory, phase, iteration, diagnostics) {
|
|
1178
|
+
for (const pattern2 of patterns) {
|
|
1179
|
+
if (pattern2.safety > ctx.safetyCeiling) continue;
|
|
1180
|
+
let drafts = [];
|
|
1181
|
+
try {
|
|
1182
|
+
const mctx = buildMatchContext(doc, elId, ctx.resolver, ctx.selectors, ctx.safetyCeiling, phase, iteration);
|
|
1183
|
+
const result = pattern2.evaluate(mctx, factory);
|
|
1184
|
+
if (!result) continue;
|
|
1185
|
+
drafts = result.ops;
|
|
1186
|
+
if (result.diagnostics) for (const d of result.diagnostics) diagnostics.push(d);
|
|
1187
|
+
} catch (err) {
|
|
1188
|
+
diagnostics.push({
|
|
1189
|
+
code: "DF_PATTERN_THREW",
|
|
1190
|
+
severity: "error",
|
|
1191
|
+
message: `pattern '${pattern2.name}' threw: ${String(err?.message ?? err)}`,
|
|
1192
|
+
nodeId: elId,
|
|
1193
|
+
pattern: pattern2.name,
|
|
1194
|
+
phase,
|
|
1195
|
+
iteration,
|
|
1196
|
+
cause: err
|
|
1197
|
+
});
|
|
1198
|
+
continue;
|
|
1199
|
+
}
|
|
1200
|
+
if (drafts.length === 0) continue;
|
|
1201
|
+
return { ops: drafts.map((d) => stampOrigin(d, pattern2)), pattern: pattern2 };
|
|
1202
|
+
}
|
|
1203
|
+
return null;
|
|
1204
|
+
}
|
|
1205
|
+
function revertDiagnostic(pattern2, elId, phase, iteration, resolverId) {
|
|
1206
|
+
return {
|
|
1207
|
+
code: "DF_VERIFY_REVERTED",
|
|
1208
|
+
severity: "warn",
|
|
1209
|
+
message: `flatten '${pattern2.name}' reverted on node ${elId}: it would change rendering (drops a style, establishes layout context, or assumes a parent context) and was not proven safe by resolver '${resolverId}'`,
|
|
1210
|
+
nodeId: elId,
|
|
1211
|
+
pattern: pattern2.name,
|
|
1212
|
+
phase,
|
|
1213
|
+
iteration
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1043
1216
|
function runSweep(state, patterns, ctx, factory, phase, iteration, touched, diagnostics, flattenBarred) {
|
|
1044
1217
|
let appliedOps = 0;
|
|
1045
|
-
const resolver = ctx.resolver;
|
|
1046
|
-
const selectors = ctx.selectors;
|
|
1047
1218
|
for (const elId of elementIds(state.doc)) {
|
|
1048
1219
|
const el = getElement(state.doc, elId);
|
|
1049
1220
|
if (!el) continue;
|
|
1050
1221
|
if (phase === "flatten" && flattenBarred.has(elId)) continue;
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
iteration
|
|
1063
|
-
);
|
|
1064
|
-
const result = pattern2.evaluate(mctx, factory);
|
|
1065
|
-
if (!result) continue;
|
|
1066
|
-
drafts = result.ops;
|
|
1067
|
-
if (result.diagnostics) for (const d of result.diagnostics) diagnostics.push(d);
|
|
1068
|
-
} catch (err) {
|
|
1069
|
-
diagnostics.push({
|
|
1070
|
-
code: "DF_PATTERN_THREW",
|
|
1071
|
-
severity: "error",
|
|
1072
|
-
message: `pattern '${pattern2.name}' threw: ${String(err?.message ?? err)}`,
|
|
1073
|
-
nodeId: elId,
|
|
1074
|
-
pattern: pattern2.name,
|
|
1075
|
-
phase,
|
|
1076
|
-
iteration,
|
|
1077
|
-
cause: err
|
|
1078
|
-
});
|
|
1222
|
+
const evaluated = evaluateElement(state.doc, elId, patterns, ctx, factory, phase, iteration, diagnostics);
|
|
1223
|
+
if (!evaluated) continue;
|
|
1224
|
+
const { ops, pattern: pattern2 } = evaluated;
|
|
1225
|
+
const outcome = applyOps(state.doc, ops, ctx);
|
|
1226
|
+
for (const d of outcome.result.diagnostics) diagnostics.push(d);
|
|
1227
|
+
if (outcome.result.appliedGroups === 0) continue;
|
|
1228
|
+
if (phase === "flatten") {
|
|
1229
|
+
const verdict = flattenVerdict(state.doc, outcome.doc, ops, ctx);
|
|
1230
|
+
if (verdict !== "commit") {
|
|
1231
|
+
diagnostics.push(revertDiagnostic(pattern2, elId, phase, iteration, ctx.resolver.id));
|
|
1232
|
+
flattenBarred.add(elId);
|
|
1079
1233
|
continue;
|
|
1080
1234
|
}
|
|
1081
|
-
if (drafts.length === 0) continue;
|
|
1082
|
-
const ops = drafts.map((d) => stampOrigin(d, pattern2));
|
|
1083
|
-
const outcome = applyOps(state.doc, ops, ctx);
|
|
1084
|
-
for (const d of outcome.result.diagnostics) diagnostics.push(d);
|
|
1085
|
-
if (outcome.result.appliedGroups > 0) {
|
|
1086
|
-
if (phase === "flatten" && flattenWouldDropStyle(state.doc, outcome.doc, ops, resolver, ctx.normalizer)) {
|
|
1087
|
-
diagnostics.push({
|
|
1088
|
-
code: "DF_VERIFY_REVERTED",
|
|
1089
|
-
severity: "warn",
|
|
1090
|
-
message: `flatten '${pattern2.name}' reverted on node ${elId}: residual style is not reproducible by resolver '${resolver.id}', so flattening would drop it`,
|
|
1091
|
-
nodeId: elId,
|
|
1092
|
-
pattern: pattern2.name,
|
|
1093
|
-
phase,
|
|
1094
|
-
iteration
|
|
1095
|
-
});
|
|
1096
|
-
flattenBarred.add(elId);
|
|
1097
|
-
break;
|
|
1098
|
-
}
|
|
1099
|
-
state.doc = outcome.doc;
|
|
1100
|
-
appliedOps += outcome.result.appliedGroups;
|
|
1101
|
-
for (const id of outcome.result.touched) touched.add(id);
|
|
1102
|
-
for (const id of outcome.result.created) touched.add(id);
|
|
1103
|
-
break;
|
|
1104
|
-
}
|
|
1105
1235
|
}
|
|
1236
|
+
state.doc = outcome.doc;
|
|
1237
|
+
appliedOps += outcome.result.appliedGroups;
|
|
1238
|
+
for (const id of outcome.result.touched) touched.add(id);
|
|
1239
|
+
for (const id of outcome.result.created) touched.add(id);
|
|
1106
1240
|
}
|
|
1107
1241
|
return appliedOps;
|
|
1108
1242
|
}
|
|
@@ -1117,6 +1251,26 @@ function docFingerprint(doc) {
|
|
|
1117
1251
|
visit(doc.root);
|
|
1118
1252
|
return parts.join("|");
|
|
1119
1253
|
}
|
|
1254
|
+
function finalizePhase(phase, s, budget, onBudgetExhausted) {
|
|
1255
|
+
if (!s.converged && s.haltReason !== "oscillation") {
|
|
1256
|
+
s.haltReason = "budget";
|
|
1257
|
+
s.diagnostics.push({
|
|
1258
|
+
code: "DF_FIXPOINT_BUDGET",
|
|
1259
|
+
severity: onBudgetExhausted === "error" ? "error" : "warn",
|
|
1260
|
+
message: `phase '${phase}' exhausted ${budget}-iteration budget`,
|
|
1261
|
+
phase,
|
|
1262
|
+
iteration: s.iterations
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
return {
|
|
1266
|
+
phase,
|
|
1267
|
+
iterations: s.iterations,
|
|
1268
|
+
converged: s.converged,
|
|
1269
|
+
haltReason: s.haltReason,
|
|
1270
|
+
touched: s.touched,
|
|
1271
|
+
diagnostics: s.diagnostics
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1120
1274
|
function runPasses(doc, passes, ctx, config) {
|
|
1121
1275
|
const cfg = { ...DEFAULT_FIXPOINT, ...config };
|
|
1122
1276
|
const factory = createRewriteFactory();
|
|
@@ -1125,76 +1279,54 @@ function runPasses(doc, passes, ctx, config) {
|
|
|
1125
1279
|
const flattenBarred = /* @__PURE__ */ new Set();
|
|
1126
1280
|
for (const phase of PHASE_ORDER) {
|
|
1127
1281
|
const patterns = patternsForPhase(passes, phase);
|
|
1128
|
-
const phaseTouched = /* @__PURE__ */ new Set();
|
|
1129
|
-
const diagnostics = [];
|
|
1130
1282
|
const budget = cfg.phases[phase] ?? cfg.maxIterations;
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1283
|
+
const s = {
|
|
1284
|
+
iterations: 0,
|
|
1285
|
+
converged: false,
|
|
1286
|
+
haltReason: "converged",
|
|
1287
|
+
touched: /* @__PURE__ */ new Set(),
|
|
1288
|
+
diagnostics: [],
|
|
1289
|
+
seen: /* @__PURE__ */ new Set()
|
|
1290
|
+
};
|
|
1135
1291
|
if (patterns.length === 0) {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
iterations: 0,
|
|
1139
|
-
converged: true,
|
|
1140
|
-
haltReason: "converged",
|
|
1141
|
-
touched: phaseTouched,
|
|
1142
|
-
diagnostics
|
|
1143
|
-
});
|
|
1292
|
+
s.converged = true;
|
|
1293
|
+
results.push(finalizePhase(phase, s, budget, cfg.onBudgetExhausted));
|
|
1144
1294
|
continue;
|
|
1145
1295
|
}
|
|
1146
|
-
while (iterations < budget) {
|
|
1147
|
-
iterations += 1;
|
|
1296
|
+
while (s.iterations < budget) {
|
|
1297
|
+
s.iterations += 1;
|
|
1148
1298
|
const applied = runSweep(
|
|
1149
1299
|
state,
|
|
1150
1300
|
patterns,
|
|
1151
1301
|
ctx,
|
|
1152
1302
|
factory,
|
|
1153
1303
|
phase,
|
|
1154
|
-
iterations,
|
|
1155
|
-
|
|
1156
|
-
diagnostics,
|
|
1304
|
+
s.iterations,
|
|
1305
|
+
s.touched,
|
|
1306
|
+
s.diagnostics,
|
|
1157
1307
|
flattenBarred
|
|
1158
1308
|
);
|
|
1159
1309
|
if (applied === 0) {
|
|
1160
|
-
converged = true;
|
|
1161
|
-
haltReason = "converged";
|
|
1310
|
+
s.converged = true;
|
|
1162
1311
|
break;
|
|
1163
1312
|
}
|
|
1164
1313
|
if (cfg.detectOscillation) {
|
|
1165
1314
|
const fp = docFingerprint(state.doc);
|
|
1166
|
-
if (seen.has(fp)) {
|
|
1167
|
-
haltReason = "oscillation";
|
|
1168
|
-
diagnostics.push({
|
|
1315
|
+
if (s.seen.has(fp)) {
|
|
1316
|
+
s.haltReason = "oscillation";
|
|
1317
|
+
s.diagnostics.push({
|
|
1169
1318
|
code: "DF_FIXPOINT_OSCILLATION",
|
|
1170
1319
|
severity: "warn",
|
|
1171
1320
|
message: `phase '${phase}' oscillated; halting`,
|
|
1172
1321
|
phase,
|
|
1173
|
-
iteration: iterations
|
|
1322
|
+
iteration: s.iterations
|
|
1174
1323
|
});
|
|
1175
1324
|
break;
|
|
1176
1325
|
}
|
|
1177
|
-
seen.add(fp);
|
|
1326
|
+
s.seen.add(fp);
|
|
1178
1327
|
}
|
|
1179
1328
|
}
|
|
1180
|
-
|
|
1181
|
-
haltReason = "budget";
|
|
1182
|
-
diagnostics.push({
|
|
1183
|
-
code: "DF_FIXPOINT_BUDGET",
|
|
1184
|
-
severity: cfg.onBudgetExhausted === "error" ? "error" : "warn",
|
|
1185
|
-
message: `phase '${phase}' exhausted ${budget}-iteration budget`,
|
|
1186
|
-
phase,
|
|
1187
|
-
iteration: iterations
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
results.push({
|
|
1191
|
-
phase,
|
|
1192
|
-
iterations,
|
|
1193
|
-
converged,
|
|
1194
|
-
haltReason,
|
|
1195
|
-
touched: phaseTouched,
|
|
1196
|
-
diagnostics
|
|
1197
|
-
});
|
|
1329
|
+
results.push(finalizePhase(phase, s, budget, cfg.onBudgetExhausted));
|
|
1198
1330
|
}
|
|
1199
1331
|
return { doc: state.doc, results };
|
|
1200
1332
|
}
|
|
@@ -1431,40 +1563,6 @@ function syncClassesFromComputed(doc, resolver, norm) {
|
|
|
1431
1563
|
// ../core/src/index.ts
|
|
1432
1564
|
init_esm_shims();
|
|
1433
1565
|
|
|
1434
|
-
// ../pattern-kit/src/define.ts
|
|
1435
|
-
init_esm_shims();
|
|
1436
|
-
var PHASES = /* @__PURE__ */ new Set(["flatten", "compress", "extract"]);
|
|
1437
|
-
var SAFETY_LEVELS = /* @__PURE__ */ new Set([0, 1, 2, 3]);
|
|
1438
|
-
function fail(name, why) {
|
|
1439
|
-
throw new Error(`definePattern(${name || "<anonymous>"}): ${why}`);
|
|
1440
|
-
}
|
|
1441
|
-
function definePattern(spec) {
|
|
1442
|
-
if (spec == null || typeof spec !== "object") {
|
|
1443
|
-
throw new Error("definePattern: spec must be an object");
|
|
1444
|
-
}
|
|
1445
|
-
const name = spec.name;
|
|
1446
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
1447
|
-
fail(String(name), "name must be a non-empty string");
|
|
1448
|
-
}
|
|
1449
|
-
if (typeof spec.category !== "string" || !spec.category.includes("/")) {
|
|
1450
|
-
fail(name, `category must be a "<phase>/<slug>" string (got ${JSON.stringify(spec.category)})`);
|
|
1451
|
-
}
|
|
1452
|
-
const phase = spec.category.split("/", 1)[0];
|
|
1453
|
-
if (!PHASES.has(phase)) {
|
|
1454
|
-
fail(name, `category phase must be one of flatten|compress|extract (got "${phase}")`);
|
|
1455
|
-
}
|
|
1456
|
-
if (!SAFETY_LEVELS.has(spec.safety)) {
|
|
1457
|
-
fail(name, `safety must be 0|1|2|3 (got ${JSON.stringify(spec.safety)})`);
|
|
1458
|
-
}
|
|
1459
|
-
if (typeof spec.evaluate !== "function") {
|
|
1460
|
-
fail(name, "evaluate must be a function");
|
|
1461
|
-
}
|
|
1462
|
-
if (spec.priority !== void 0 && !Number.isFinite(spec.priority)) {
|
|
1463
|
-
fail(name, "priority must be a finite number when provided");
|
|
1464
|
-
}
|
|
1465
|
-
return Object.freeze({ ...spec });
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
1566
|
// ../pattern-kit/src/normalize.ts
|
|
1469
1567
|
init_esm_shims();
|
|
1470
1568
|
var INHERITED_PROPERTIES = [
|
|
@@ -1812,6 +1910,11 @@ var hasRef = (node) => asElement(node)?.meta.hasRef ?? false;
|
|
|
1812
1910
|
var hasEventHandlers = (node) => asElement(node)?.meta.hasEventHandlers ?? false;
|
|
1813
1911
|
var hasDynamicChildren = (node) => asElement(node)?.meta.hasDynamicChildren ?? false;
|
|
1814
1912
|
var hasDynamicClasses = (node) => asElement(node)?.classes.hasDynamic ?? false;
|
|
1913
|
+
var opaque = (node, ctx) => {
|
|
1914
|
+
const el = asElement(node);
|
|
1915
|
+
if (!el) return false;
|
|
1916
|
+
return ctx.isOpaque(el);
|
|
1917
|
+
};
|
|
1815
1918
|
var targetedByCombinator = (node, ctx) => {
|
|
1816
1919
|
const el = asElement(node);
|
|
1817
1920
|
if (!el) return false;
|
|
@@ -1852,6 +1955,42 @@ function removeNode(target) {
|
|
|
1852
1955
|
|
|
1853
1956
|
// ../pattern-kit/src/pattern.ts
|
|
1854
1957
|
init_esm_shims();
|
|
1958
|
+
|
|
1959
|
+
// ../pattern-kit/src/define.ts
|
|
1960
|
+
init_esm_shims();
|
|
1961
|
+
var PHASES = /* @__PURE__ */ new Set(["flatten", "compress", "extract"]);
|
|
1962
|
+
var SAFETY_LEVELS = /* @__PURE__ */ new Set([0, 1, 2, 3]);
|
|
1963
|
+
function fail(name, why) {
|
|
1964
|
+
throw new Error(`definePattern(${name || "<anonymous>"}): ${why}`);
|
|
1965
|
+
}
|
|
1966
|
+
function validatePattern(spec) {
|
|
1967
|
+
if (spec == null || typeof spec !== "object") {
|
|
1968
|
+
throw new Error("definePattern: spec must be an object");
|
|
1969
|
+
}
|
|
1970
|
+
const name = spec.name;
|
|
1971
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
1972
|
+
fail(String(name), "name must be a non-empty string");
|
|
1973
|
+
}
|
|
1974
|
+
if (typeof spec.category !== "string" || !spec.category.includes("/")) {
|
|
1975
|
+
fail(name, `category must be a "<phase>/<slug>" string (got ${JSON.stringify(spec.category)})`);
|
|
1976
|
+
}
|
|
1977
|
+
const phase = spec.category.split("/", 1)[0];
|
|
1978
|
+
if (!PHASES.has(phase)) {
|
|
1979
|
+
fail(name, `category phase must be one of flatten|compress|extract (got "${phase}")`);
|
|
1980
|
+
}
|
|
1981
|
+
if (!SAFETY_LEVELS.has(spec.safety)) {
|
|
1982
|
+
fail(name, `safety must be 0|1|2|3 (got ${JSON.stringify(spec.safety)})`);
|
|
1983
|
+
}
|
|
1984
|
+
if (typeof spec.evaluate !== "function") {
|
|
1985
|
+
fail(name, "evaluate must be a function");
|
|
1986
|
+
}
|
|
1987
|
+
if (spec.priority !== void 0 && !Number.isFinite(spec.priority)) {
|
|
1988
|
+
fail(name, "priority must be a finite number when provided");
|
|
1989
|
+
}
|
|
1990
|
+
return Object.freeze({ ...spec });
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
// ../pattern-kit/src/pattern.ts
|
|
1855
1994
|
function camelToKebab(key) {
|
|
1856
1995
|
if (key.startsWith("--")) return key;
|
|
1857
1996
|
return key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
@@ -1888,8 +2027,20 @@ var FLATTEN_GUARDS = and(
|
|
|
1888
2027
|
not(targetedByCombinator),
|
|
1889
2028
|
not(affectsSelectorMatching)
|
|
1890
2029
|
);
|
|
1891
|
-
|
|
1892
|
-
|
|
2030
|
+
var COMPRESS_GUARDS = and(
|
|
2031
|
+
not(hasDynamicClasses),
|
|
2032
|
+
not(opaque),
|
|
2033
|
+
not(targetedByCombinator)
|
|
2034
|
+
);
|
|
2035
|
+
function autoGuardsFor(category) {
|
|
2036
|
+
switch (category.split("/", 1)[0]) {
|
|
2037
|
+
case "flatten":
|
|
2038
|
+
return FLATTEN_GUARDS;
|
|
2039
|
+
case "compress":
|
|
2040
|
+
return COMPRESS_GUARDS;
|
|
2041
|
+
default:
|
|
2042
|
+
return null;
|
|
2043
|
+
}
|
|
1893
2044
|
}
|
|
1894
2045
|
function compileDeclarativeMatch(m) {
|
|
1895
2046
|
const parts = [isElement(m.tag)];
|
|
@@ -1905,7 +2056,8 @@ function compileDeclarativeMatch(m) {
|
|
|
1905
2056
|
function compileMatch(match, category) {
|
|
1906
2057
|
if (typeof match === "function") return match;
|
|
1907
2058
|
const declarative = compileDeclarativeMatch(match ?? {});
|
|
1908
|
-
const
|
|
2059
|
+
const guards = autoGuardsFor(category);
|
|
2060
|
+
const guarded = guards ? and(declarative, guards) : declarative;
|
|
1909
2061
|
return (node, ctx) => guarded(node, ctx);
|
|
1910
2062
|
}
|
|
1911
2063
|
function pruneShadowed(sm, drop) {
|
|
@@ -1962,7 +2114,7 @@ function compileRewrite(rewrite) {
|
|
|
1962
2114
|
const onConflict = rewrite.onConflict ?? "abort";
|
|
1963
2115
|
return (ctx, rw) => [rw.mergeStyle(ctx.node, null, style, onConflict)];
|
|
1964
2116
|
}
|
|
1965
|
-
function
|
|
2117
|
+
function definePattern(config) {
|
|
1966
2118
|
const matchFn = compileMatch(config.match, config.category);
|
|
1967
2119
|
const rewriteFn = compileRewrite(config.rewrite);
|
|
1968
2120
|
const spec = {
|
|
@@ -1972,7 +2124,7 @@ function pattern(config) {
|
|
|
1972
2124
|
priority: config.priority,
|
|
1973
2125
|
precondition: config.precondition,
|
|
1974
2126
|
doc: config.doc,
|
|
1975
|
-
|
|
2127
|
+
test: config.test,
|
|
1976
2128
|
evaluate(ctx, rw) {
|
|
1977
2129
|
if (!matchFn(ctx.node, ctx)) return null;
|
|
1978
2130
|
const ops = rewriteFn(ctx, rw);
|
|
@@ -1980,8 +2132,9 @@ function pattern(config) {
|
|
|
1980
2132
|
return { ops };
|
|
1981
2133
|
}
|
|
1982
2134
|
};
|
|
1983
|
-
return
|
|
2135
|
+
return validatePattern(spec);
|
|
1984
2136
|
}
|
|
2137
|
+
var pattern = definePattern;
|
|
1985
2138
|
|
|
1986
2139
|
// ../pattern-kit/src/index.ts
|
|
1987
2140
|
init_esm_shims();
|
|
@@ -2012,17 +2165,27 @@ export {
|
|
|
2012
2165
|
cloneDocument,
|
|
2013
2166
|
applyOps,
|
|
2014
2167
|
applyGroups,
|
|
2015
|
-
DEFAULT_FIXPOINT,
|
|
2016
2168
|
createNullResolver,
|
|
2017
2169
|
createNullSelectorIndex,
|
|
2018
2170
|
buildSelectorIndex,
|
|
2019
2171
|
createRewriteFactory,
|
|
2172
|
+
buildMatchContext,
|
|
2173
|
+
classifyFlattenOps,
|
|
2174
|
+
DEFAULT_FIXPOINT,
|
|
2175
|
+
PHASE_ORDER,
|
|
2176
|
+
stampOrigin,
|
|
2177
|
+
patternsForPhase,
|
|
2178
|
+
flattenWouldDropStyle,
|
|
2179
|
+
flattenVerdict,
|
|
2180
|
+
evaluateElement,
|
|
2181
|
+
revertDiagnostic,
|
|
2182
|
+
docFingerprint,
|
|
2183
|
+
finalizePhase,
|
|
2020
2184
|
runPasses,
|
|
2021
2185
|
createPassManager,
|
|
2022
2186
|
createSyntheticSink,
|
|
2023
2187
|
createPipeline,
|
|
2024
2188
|
syncClassesFromComputed,
|
|
2025
|
-
definePattern,
|
|
2026
2189
|
createNormalizer,
|
|
2027
2190
|
normalizer,
|
|
2028
2191
|
isStyleSuperset,
|
|
@@ -2037,11 +2200,13 @@ export {
|
|
|
2037
2200
|
hasEventHandlers,
|
|
2038
2201
|
hasDynamicChildren,
|
|
2039
2202
|
hasDynamicClasses,
|
|
2203
|
+
opaque,
|
|
2040
2204
|
targetedByCombinator,
|
|
2041
2205
|
mergeStyle,
|
|
2042
2206
|
foldInheritedStyles,
|
|
2043
2207
|
replaceWith,
|
|
2044
2208
|
removeNode,
|
|
2209
|
+
definePattern,
|
|
2045
2210
|
pattern
|
|
2046
2211
|
};
|
|
2047
|
-
//# sourceMappingURL=chunk-
|
|
2212
|
+
//# sourceMappingURL=chunk-DWLB7FRR.js.map
|