domflax 0.1.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/LICENSE +214 -0
- package/dist/chunk-4HHISSMR.js +2227 -0
- package/dist/chunk-4HHISSMR.js.map +1 -0
- package/dist/chunk-6WVVF6AD.js +55 -0
- package/dist/chunk-6WVVF6AD.js.map +1 -0
- package/dist/chunk-77SLHRN6.js +2047 -0
- package/dist/chunk-77SLHRN6.js.map +1 -0
- package/dist/chunk-ZJ2S36GY.js +175 -0
- package/dist/chunk-ZJ2S36GY.js.map +1 -0
- package/dist/cli.cjs +5207 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1310 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4383 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +539 -0
- package/dist/index.d.ts +539 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/pattern-CX6iBzTD.d.ts +237 -0
- package/dist/pattern-P4FIKAUB.d.cts +237 -0
- package/dist/pattern-kit.cjs +630 -0
- package/dist/pattern-kit.cjs.map +1 -0
- package/dist/pattern-kit.d.cts +80 -0
- package/dist/pattern-kit.d.ts +80 -0
- package/dist/pattern-kit.js +55 -0
- package/dist/pattern-kit.js.map +1 -0
- package/dist/types-BQ7l6dVe.d.cts +749 -0
- package/dist/types-BQ7l6dVe.d.ts +749 -0
- package/dist/verify.cjs +2747 -0
- package/dist/verify.cjs.map +1 -0
- package/dist/verify.d.cts +245 -0
- package/dist/verify.d.ts +245 -0
- package/dist/verify.js +2700 -0
- package/dist/verify.js.map +1 -0
- package/dist/webpack-loader.cjs +4149 -0
- package/dist/webpack-loader.cjs.map +1 -0
- package/dist/webpack-loader.d.cts +21 -0
- package/dist/webpack-loader.d.ts +21 -0
- package/dist/webpack-loader.js +30 -0
- package/dist/webpack-loader.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/pattern-kit.ts
|
|
21
|
+
var pattern_kit_exports = {};
|
|
22
|
+
__export(pattern_kit_exports, {
|
|
23
|
+
and: () => and,
|
|
24
|
+
computed: () => computed,
|
|
25
|
+
createNormalizer: () => createNormalizer,
|
|
26
|
+
definePattern: () => definePattern,
|
|
27
|
+
emptyStyleMap: () => emptyStyleMap,
|
|
28
|
+
foldInheritedStyles: () => foldInheritedStyles,
|
|
29
|
+
hasDynamicChildren: () => hasDynamicChildren,
|
|
30
|
+
hasDynamicClasses: () => hasDynamicClasses,
|
|
31
|
+
hasEventHandlers: () => hasEventHandlers,
|
|
32
|
+
hasOwnVisualStyle: () => hasOwnVisualStyle,
|
|
33
|
+
hasRef: () => hasRef,
|
|
34
|
+
hasSingleElementChild: () => hasSingleElementChild,
|
|
35
|
+
isElement: () => isElement,
|
|
36
|
+
isStyleSuperset: () => isStyleSuperset,
|
|
37
|
+
mergeStyle: () => mergeStyle,
|
|
38
|
+
normalizer: () => normalizer,
|
|
39
|
+
not: () => not,
|
|
40
|
+
or: () => or,
|
|
41
|
+
pattern: () => pattern,
|
|
42
|
+
removeNode: () => removeNode,
|
|
43
|
+
replaceWith: () => replaceWith,
|
|
44
|
+
targetedByCombinator: () => targetedByCombinator
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(pattern_kit_exports);
|
|
47
|
+
|
|
48
|
+
// ../pattern-kit/src/define.ts
|
|
49
|
+
var PHASES = /* @__PURE__ */ new Set(["flatten", "compress", "extract"]);
|
|
50
|
+
var SAFETY_LEVELS = /* @__PURE__ */ new Set([0, 1, 2, 3]);
|
|
51
|
+
function fail(name, why) {
|
|
52
|
+
throw new Error(`definePattern(${name || "<anonymous>"}): ${why}`);
|
|
53
|
+
}
|
|
54
|
+
function definePattern(spec) {
|
|
55
|
+
if (spec == null || typeof spec !== "object") {
|
|
56
|
+
throw new Error("definePattern: spec must be an object");
|
|
57
|
+
}
|
|
58
|
+
const name = spec.name;
|
|
59
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
60
|
+
fail(String(name), "name must be a non-empty string");
|
|
61
|
+
}
|
|
62
|
+
if (typeof spec.category !== "string" || !spec.category.includes("/")) {
|
|
63
|
+
fail(name, `category must be a "<phase>/<slug>" string (got ${JSON.stringify(spec.category)})`);
|
|
64
|
+
}
|
|
65
|
+
const phase = spec.category.split("/", 1)[0];
|
|
66
|
+
if (!PHASES.has(phase)) {
|
|
67
|
+
fail(name, `category phase must be one of flatten|compress|extract (got "${phase}")`);
|
|
68
|
+
}
|
|
69
|
+
if (!SAFETY_LEVELS.has(spec.safety)) {
|
|
70
|
+
fail(name, `safety must be 0|1|2|3 (got ${JSON.stringify(spec.safety)})`);
|
|
71
|
+
}
|
|
72
|
+
if (typeof spec.evaluate !== "function") {
|
|
73
|
+
fail(name, "evaluate must be a function");
|
|
74
|
+
}
|
|
75
|
+
if (spec.priority !== void 0 && !Number.isFinite(spec.priority)) {
|
|
76
|
+
fail(name, "priority must be a finite number when provided");
|
|
77
|
+
}
|
|
78
|
+
return Object.freeze({ ...spec });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ../core/src/builders.ts
|
|
82
|
+
var BASE_CONDITION = { media: "", states: [], pseudoElement: "" };
|
|
83
|
+
function conditionKey(c) {
|
|
84
|
+
const states = [...c.states].sort().join(",");
|
|
85
|
+
return `${c.media}|${states}|${c.pseudoElement}`;
|
|
86
|
+
}
|
|
87
|
+
var BASE_CONDITION_KEY = conditionKey(BASE_CONDITION);
|
|
88
|
+
function emptyStyleMap() {
|
|
89
|
+
return { blocks: /* @__PURE__ */ new Map() };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ../pattern-kit/src/normalize.ts
|
|
93
|
+
var INHERITED_PROPERTIES = [
|
|
94
|
+
"azimuth",
|
|
95
|
+
"border-collapse",
|
|
96
|
+
"border-spacing",
|
|
97
|
+
"caption-side",
|
|
98
|
+
"color",
|
|
99
|
+
"cursor",
|
|
100
|
+
"direction",
|
|
101
|
+
"empty-cells",
|
|
102
|
+
"font-family",
|
|
103
|
+
"font-feature-settings",
|
|
104
|
+
"font-kerning",
|
|
105
|
+
"font-size",
|
|
106
|
+
"font-size-adjust",
|
|
107
|
+
"font-stretch",
|
|
108
|
+
"font-style",
|
|
109
|
+
"font-variant",
|
|
110
|
+
"font-variant-caps",
|
|
111
|
+
"font-variant-numeric",
|
|
112
|
+
"font-weight",
|
|
113
|
+
"hyphens",
|
|
114
|
+
"letter-spacing",
|
|
115
|
+
"line-height",
|
|
116
|
+
"list-style-image",
|
|
117
|
+
"list-style-position",
|
|
118
|
+
"list-style-type",
|
|
119
|
+
"orphans",
|
|
120
|
+
"overflow-wrap",
|
|
121
|
+
"quotes",
|
|
122
|
+
"tab-size",
|
|
123
|
+
"text-align",
|
|
124
|
+
"text-align-last",
|
|
125
|
+
"text-decoration-color",
|
|
126
|
+
"text-indent",
|
|
127
|
+
"text-justify",
|
|
128
|
+
"text-rendering",
|
|
129
|
+
"text-shadow",
|
|
130
|
+
"text-transform",
|
|
131
|
+
"text-underline-position",
|
|
132
|
+
"visibility",
|
|
133
|
+
"white-space",
|
|
134
|
+
"widows",
|
|
135
|
+
"word-break",
|
|
136
|
+
"word-spacing",
|
|
137
|
+
"writing-mode",
|
|
138
|
+
"-webkit-font-smoothing"
|
|
139
|
+
];
|
|
140
|
+
function createInheritedTable() {
|
|
141
|
+
const properties = new Set(INHERITED_PROPERTIES);
|
|
142
|
+
return {
|
|
143
|
+
version: "domflax-inherited@1",
|
|
144
|
+
properties,
|
|
145
|
+
isInherited(property) {
|
|
146
|
+
return String(property).startsWith("--") || properties.has(property);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
var ZERO_LENGTH_RE = /\b0(?:px|em|rem|ex|ch|vh|vw|vmin|vmax|vi|vb|pt|pc|cm|mm|in|q|lh|rlh|fr|deg|rad|turn|s|ms|%)\b/g;
|
|
151
|
+
var FUNC_ARGS_RE = /\b(rgba?|hsla?|hwb|lab|lch|oklab|oklch)\(([^()]*)\)/gi;
|
|
152
|
+
var RELATIVE_UNIT_RE = /(?:\d*\.?\d+)(?:em|ex|ch|lh)\b|%/i;
|
|
153
|
+
function canonValue(raw) {
|
|
154
|
+
let v = raw.trim().replace(/\s+/g, " ");
|
|
155
|
+
v = v.replace(/#([0-9a-fA-F]{3,8})\b/g, (_m, hex) => "#" + hex.toLowerCase());
|
|
156
|
+
v = v.replace(
|
|
157
|
+
/#([0-9a-f])([0-9a-f])([0-9a-f])(?![0-9a-f])/g,
|
|
158
|
+
(_m, r, g, b) => `#${r}${r}${g}${g}${b}${b}`
|
|
159
|
+
);
|
|
160
|
+
v = v.replace(/\btransparent\b/gi, "rgba(0, 0, 0, 0)");
|
|
161
|
+
v = v.replace(/#00000000\b/g, "rgba(0, 0, 0, 0)");
|
|
162
|
+
v = v.replace(ZERO_LENGTH_RE, "0");
|
|
163
|
+
v = v.replace(FUNC_ARGS_RE, (_m, fn, args) => {
|
|
164
|
+
const parts = args.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
165
|
+
return `${fn.toLowerCase()}(${parts.join(", ")})`;
|
|
166
|
+
});
|
|
167
|
+
return v;
|
|
168
|
+
}
|
|
169
|
+
function isRelativeValue(value) {
|
|
170
|
+
return RELATIVE_UNIT_RE.test(value);
|
|
171
|
+
}
|
|
172
|
+
var BOX_SIDES = {
|
|
173
|
+
padding: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
|
|
174
|
+
margin: ["margin-top", "margin-right", "margin-bottom", "margin-left"],
|
|
175
|
+
inset: ["top", "right", "bottom", "left"],
|
|
176
|
+
"border-width": [
|
|
177
|
+
"border-top-width",
|
|
178
|
+
"border-right-width",
|
|
179
|
+
"border-bottom-width",
|
|
180
|
+
"border-left-width"
|
|
181
|
+
],
|
|
182
|
+
"border-style": [
|
|
183
|
+
"border-top-style",
|
|
184
|
+
"border-right-style",
|
|
185
|
+
"border-bottom-style",
|
|
186
|
+
"border-left-style"
|
|
187
|
+
],
|
|
188
|
+
"border-color": [
|
|
189
|
+
"border-top-color",
|
|
190
|
+
"border-right-color",
|
|
191
|
+
"border-bottom-color",
|
|
192
|
+
"border-left-color"
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
function splitTopLevel(value) {
|
|
196
|
+
const out = [];
|
|
197
|
+
let depth = 0;
|
|
198
|
+
let cur = "";
|
|
199
|
+
for (const ch of value) {
|
|
200
|
+
if (ch === "(") depth += 1;
|
|
201
|
+
else if (ch === ")") depth = Math.max(0, depth - 1);
|
|
202
|
+
if (depth === 0 && /\s/.test(ch)) {
|
|
203
|
+
if (cur.length > 0) {
|
|
204
|
+
out.push(cur);
|
|
205
|
+
cur = "";
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
cur += ch;
|
|
210
|
+
}
|
|
211
|
+
if (cur.length > 0) out.push(cur);
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
function boxFourSides(values) {
|
|
215
|
+
const [a, b, c, d] = values;
|
|
216
|
+
switch (values.length) {
|
|
217
|
+
case 1:
|
|
218
|
+
return [a, a, a, a];
|
|
219
|
+
case 2:
|
|
220
|
+
return [a, b, a, b];
|
|
221
|
+
case 3:
|
|
222
|
+
return [a, b, c, b];
|
|
223
|
+
default:
|
|
224
|
+
return [a, b, c, d];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function expandShorthand(prop, value) {
|
|
228
|
+
const box = BOX_SIDES[prop];
|
|
229
|
+
if (box) {
|
|
230
|
+
const parts = splitTopLevel(value);
|
|
231
|
+
if (parts.length >= 1 && parts.length <= 4) {
|
|
232
|
+
const sides = boxFourSides(parts);
|
|
233
|
+
return box.map((p, i) => [p, sides[i]]);
|
|
234
|
+
}
|
|
235
|
+
return [[prop, value]];
|
|
236
|
+
}
|
|
237
|
+
if (prop === "gap" || prop === "grid-gap") {
|
|
238
|
+
const parts = splitTopLevel(value);
|
|
239
|
+
if (parts.length === 1) {
|
|
240
|
+
return [
|
|
241
|
+
["row-gap", parts[0]],
|
|
242
|
+
["column-gap", parts[0]]
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
if (parts.length === 2) {
|
|
246
|
+
return [
|
|
247
|
+
["row-gap", parts[0]],
|
|
248
|
+
["column-gap", parts[1]]
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
return [[prop, value]];
|
|
252
|
+
}
|
|
253
|
+
return [[prop, value]];
|
|
254
|
+
}
|
|
255
|
+
function makeDecl(table, prop, rawValue, important) {
|
|
256
|
+
const property = prop.trim().toLowerCase();
|
|
257
|
+
const value = canonValue(rawValue);
|
|
258
|
+
return {
|
|
259
|
+
property,
|
|
260
|
+
value,
|
|
261
|
+
important,
|
|
262
|
+
relativeToParent: isRelativeValue(value),
|
|
263
|
+
inherited: table.isInherited(property)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function createNormalizer() {
|
|
267
|
+
const inherited = createInheritedTable();
|
|
268
|
+
const normalizeDeclaration = (prop, value, important) => {
|
|
269
|
+
const p = prop.trim().toLowerCase();
|
|
270
|
+
const expanded = expandShorthand(p, value.trim());
|
|
271
|
+
return expanded.map(([lp, lv]) => makeDecl(inherited, lp, lv, important));
|
|
272
|
+
};
|
|
273
|
+
const normalizeValue = (prop, raw) => {
|
|
274
|
+
void prop;
|
|
275
|
+
return canonValue(raw);
|
|
276
|
+
};
|
|
277
|
+
const normalizeStyleMap = (sm) => {
|
|
278
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
279
|
+
for (const block of sm.blocks.values()) {
|
|
280
|
+
const decls = /* @__PURE__ */ new Map();
|
|
281
|
+
for (const decl of block.decls.values()) {
|
|
282
|
+
const next = {
|
|
283
|
+
...decl,
|
|
284
|
+
value: canonValue(String(decl.value)),
|
|
285
|
+
relativeToParent: isRelativeValue(String(decl.value)),
|
|
286
|
+
inherited: inherited.isInherited(decl.property)
|
|
287
|
+
};
|
|
288
|
+
decls.set(next.property, next);
|
|
289
|
+
}
|
|
290
|
+
const sorted = new Map(
|
|
291
|
+
[...decls.entries()].sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)
|
|
292
|
+
);
|
|
293
|
+
const key = conditionKey(block.condition);
|
|
294
|
+
blocks.set(key, { condition: block.condition, decls: sorted });
|
|
295
|
+
}
|
|
296
|
+
return { blocks };
|
|
297
|
+
};
|
|
298
|
+
const equals = (a, b) => {
|
|
299
|
+
const na = normalizeStyleMap(a);
|
|
300
|
+
const nb = normalizeStyleMap(b);
|
|
301
|
+
if (na.blocks.size !== nb.blocks.size) return false;
|
|
302
|
+
for (const [key, blockA] of na.blocks) {
|
|
303
|
+
const blockB = nb.blocks.get(key);
|
|
304
|
+
if (!blockB) return false;
|
|
305
|
+
if (blockA.decls.size !== blockB.decls.size) return false;
|
|
306
|
+
for (const [prop, declA] of blockA.decls) {
|
|
307
|
+
const declB = blockB.decls.get(prop);
|
|
308
|
+
if (!declB) return false;
|
|
309
|
+
if (declA.value !== declB.value || declA.important !== declB.important) return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return true;
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
version: "domflax-normalizer@1",
|
|
316
|
+
normalizeDeclaration,
|
|
317
|
+
normalizeValue,
|
|
318
|
+
normalizeStyleMap,
|
|
319
|
+
equals,
|
|
320
|
+
inherited
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
var normalizer = createNormalizer();
|
|
324
|
+
function isStyleSuperset(full, partial, norm = normalizer) {
|
|
325
|
+
const nf = norm.normalizeStyleMap(full);
|
|
326
|
+
const np = norm.normalizeStyleMap(partial);
|
|
327
|
+
for (const [key, want] of np.blocks) {
|
|
328
|
+
const have = nf.blocks.get(key) ?? nf.blocks.get(conditionKey(want.condition));
|
|
329
|
+
if (!have) return false;
|
|
330
|
+
for (const [prop, decl] of want.decls) {
|
|
331
|
+
const got = have.decls.get(prop);
|
|
332
|
+
if (!got || got.value !== decl.value) return false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ../pattern-kit/src/combinators.ts
|
|
339
|
+
function asElement(node) {
|
|
340
|
+
const n = node;
|
|
341
|
+
return n.kind === "element" ? n : null;
|
|
342
|
+
}
|
|
343
|
+
function elementChildrenOf(el, ctx) {
|
|
344
|
+
const out = [];
|
|
345
|
+
for (const childId of el.children) {
|
|
346
|
+
const child = ctx.doc.nodes.get(childId);
|
|
347
|
+
if (child && child.kind === "element") out.push(child);
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
|
351
|
+
function and(...matchers) {
|
|
352
|
+
return (node, ctx) => matchers.every((m) => m(node, ctx));
|
|
353
|
+
}
|
|
354
|
+
function or(...matchers) {
|
|
355
|
+
return (node, ctx) => matchers.some((m) => m(node, ctx));
|
|
356
|
+
}
|
|
357
|
+
function not(matcher) {
|
|
358
|
+
return (node, ctx) => !matcher(node, ctx);
|
|
359
|
+
}
|
|
360
|
+
function isElement(tag) {
|
|
361
|
+
const want = tag?.toLowerCase();
|
|
362
|
+
return (node) => {
|
|
363
|
+
const el = asElement(node);
|
|
364
|
+
if (!el) return false;
|
|
365
|
+
return want === void 0 || el.tag.toLowerCase() === want;
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
var hasSingleElementChild = (node, ctx) => {
|
|
369
|
+
const el = asElement(node);
|
|
370
|
+
if (!el) return false;
|
|
371
|
+
return elementChildrenOf(el, ctx).length === 1;
|
|
372
|
+
};
|
|
373
|
+
function computed(partial) {
|
|
374
|
+
return (node, ctx) => {
|
|
375
|
+
const el = asElement(node);
|
|
376
|
+
if (!el) return false;
|
|
377
|
+
const full = ctx.computedOf(el) ?? el.computed;
|
|
378
|
+
return isStyleSuperset(full, partial, normalizer);
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
var VISUAL_PROPERTIES = /* @__PURE__ */ new Set([
|
|
382
|
+
"background",
|
|
383
|
+
"background-color",
|
|
384
|
+
"background-image",
|
|
385
|
+
"border-top-width",
|
|
386
|
+
"border-right-width",
|
|
387
|
+
"border-bottom-width",
|
|
388
|
+
"border-left-width",
|
|
389
|
+
"border-top-style",
|
|
390
|
+
"border-right-style",
|
|
391
|
+
"border-bottom-style",
|
|
392
|
+
"border-left-style",
|
|
393
|
+
"border-top-color",
|
|
394
|
+
"border-right-color",
|
|
395
|
+
"border-bottom-color",
|
|
396
|
+
"border-left-color",
|
|
397
|
+
"border-radius",
|
|
398
|
+
"box-shadow",
|
|
399
|
+
"outline",
|
|
400
|
+
"outline-width",
|
|
401
|
+
"outline-style",
|
|
402
|
+
"outline-color",
|
|
403
|
+
"text-shadow",
|
|
404
|
+
"filter",
|
|
405
|
+
"backdrop-filter",
|
|
406
|
+
"mix-blend-mode",
|
|
407
|
+
"opacity"
|
|
408
|
+
]);
|
|
409
|
+
var EMPTY_VISUAL_VALUES = /* @__PURE__ */ new Set([
|
|
410
|
+
"none",
|
|
411
|
+
"0",
|
|
412
|
+
"normal",
|
|
413
|
+
"transparent",
|
|
414
|
+
"rgba(0, 0, 0, 0)",
|
|
415
|
+
"initial",
|
|
416
|
+
"unset",
|
|
417
|
+
"auto"
|
|
418
|
+
]);
|
|
419
|
+
var hasOwnVisualStyle = (node, ctx) => {
|
|
420
|
+
const el = asElement(node);
|
|
421
|
+
if (!el) return false;
|
|
422
|
+
if (el.meta.hasOwnVisualStyle) return true;
|
|
423
|
+
const computedMap = ctx.computedOf(el) ?? el.computed;
|
|
424
|
+
const norm = normalizer.normalizeStyleMap(computedMap);
|
|
425
|
+
for (const block of norm.blocks.values()) {
|
|
426
|
+
for (const decl of block.decls.values()) {
|
|
427
|
+
if (!VISUAL_PROPERTIES.has(String(decl.property))) continue;
|
|
428
|
+
if (!EMPTY_VISUAL_VALUES.has(String(decl.value))) return true;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return false;
|
|
432
|
+
};
|
|
433
|
+
var hasRef = (node) => asElement(node)?.meta.hasRef ?? false;
|
|
434
|
+
var hasEventHandlers = (node) => asElement(node)?.meta.hasEventHandlers ?? false;
|
|
435
|
+
var hasDynamicChildren = (node) => asElement(node)?.meta.hasDynamicChildren ?? false;
|
|
436
|
+
var hasDynamicClasses = (node) => asElement(node)?.classes.hasDynamic ?? false;
|
|
437
|
+
var targetedByCombinator = (node, ctx) => {
|
|
438
|
+
const el = asElement(node);
|
|
439
|
+
if (!el) return false;
|
|
440
|
+
if (el.meta.targetedByCombinator) return true;
|
|
441
|
+
return ctx.selectors.targetedByCombinator(el.id);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// ../pattern-kit/src/ops.ts
|
|
445
|
+
function idOf(ref) {
|
|
446
|
+
return typeof ref === "number" ? ref : ref.id;
|
|
447
|
+
}
|
|
448
|
+
function mergeStyle(target, source, style, onConflict = "abort") {
|
|
449
|
+
return {
|
|
450
|
+
op: "mergeStyle",
|
|
451
|
+
target: idOf(target),
|
|
452
|
+
source: source == null ? null : idOf(source),
|
|
453
|
+
style,
|
|
454
|
+
onConflict
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function foldInheritedStyles(from, into, opts) {
|
|
458
|
+
const list = Array.isArray(into) ? into : [into];
|
|
459
|
+
return {
|
|
460
|
+
op: "foldInheritedStyles",
|
|
461
|
+
from: idOf(from),
|
|
462
|
+
into: list.map(idOf),
|
|
463
|
+
properties: opts?.only ?? "all-inherited",
|
|
464
|
+
conditions: opts?.conditions ?? "base"
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function replaceWith(target, replacement) {
|
|
468
|
+
return { op: "replaceWith", target: idOf(target), replacement };
|
|
469
|
+
}
|
|
470
|
+
function removeNode(target) {
|
|
471
|
+
return { op: "removeNode", target: idOf(target) };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ../pattern-kit/src/pattern.ts
|
|
475
|
+
function camelToKebab(key) {
|
|
476
|
+
if (key.startsWith("--")) return key;
|
|
477
|
+
return key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
478
|
+
}
|
|
479
|
+
function plainToStyleMap(style) {
|
|
480
|
+
const decls = /* @__PURE__ */ new Map();
|
|
481
|
+
for (const [rawKey, rawValue] of Object.entries(style)) {
|
|
482
|
+
const prop = camelToKebab(rawKey);
|
|
483
|
+
for (const decl of normalizer.normalizeDeclaration(prop, String(rawValue), false)) {
|
|
484
|
+
decls.set(decl.property, decl);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const block = { condition: BASE_CONDITION, decls };
|
|
488
|
+
return { blocks: /* @__PURE__ */ new Map([[conditionKey(BASE_CONDITION), block]]) };
|
|
489
|
+
}
|
|
490
|
+
function asElement2(node) {
|
|
491
|
+
const n = node;
|
|
492
|
+
return n.kind === "element" ? n : null;
|
|
493
|
+
}
|
|
494
|
+
function metaFlag(flag) {
|
|
495
|
+
return (node) => Boolean(asElement2(node)?.meta[flag]);
|
|
496
|
+
}
|
|
497
|
+
var hasRawHtml = metaFlag("hasDangerousHtml");
|
|
498
|
+
var affectsSelectorMatching = (node, ctx) => {
|
|
499
|
+
const el = asElement2(node);
|
|
500
|
+
if (!el) return false;
|
|
501
|
+
return ctx.selectors.reparentImpact(el.id).size > 0;
|
|
502
|
+
};
|
|
503
|
+
var FLATTEN_GUARDS = and(
|
|
504
|
+
not(hasRef),
|
|
505
|
+
not(hasEventHandlers),
|
|
506
|
+
not(hasDynamicChildren),
|
|
507
|
+
not(hasRawHtml),
|
|
508
|
+
not(targetedByCombinator),
|
|
509
|
+
not(affectsSelectorMatching)
|
|
510
|
+
);
|
|
511
|
+
function isFlattenCategory(category) {
|
|
512
|
+
return category.split("/", 1)[0] === "flatten";
|
|
513
|
+
}
|
|
514
|
+
function compileDeclarativeMatch(m) {
|
|
515
|
+
const parts = [isElement(m.tag)];
|
|
516
|
+
if (m.style) parts.push(computed(plainToStyleMap(m.style)));
|
|
517
|
+
if (m.onlyChild === "element") parts.push(hasSingleElementChild);
|
|
518
|
+
if (m.paintsNothing) parts.push(not(hasOwnVisualStyle));
|
|
519
|
+
if (m.where) {
|
|
520
|
+
const extra = Array.isArray(m.where) ? m.where : [m.where];
|
|
521
|
+
for (const w of extra) parts.push(w);
|
|
522
|
+
}
|
|
523
|
+
return and(...parts);
|
|
524
|
+
}
|
|
525
|
+
function compileMatch(match, category) {
|
|
526
|
+
if (typeof match === "function") return match;
|
|
527
|
+
const declarative = compileDeclarativeMatch(match ?? {});
|
|
528
|
+
const guarded = isFlattenCategory(category) ? and(declarative, FLATTEN_GUARDS) : declarative;
|
|
529
|
+
return (node, ctx) => guarded(node, ctx);
|
|
530
|
+
}
|
|
531
|
+
function pruneShadowed(sm, drop) {
|
|
532
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
533
|
+
for (const [key, block] of sm.blocks) {
|
|
534
|
+
const decls = /* @__PURE__ */ new Map();
|
|
535
|
+
for (const [prop, decl] of block.decls) {
|
|
536
|
+
const filtered = (decl.shadowed ?? []).filter(
|
|
537
|
+
(o) => !(o.kind === "class" && drop.has(o.className))
|
|
538
|
+
);
|
|
539
|
+
const rest = { ...decl };
|
|
540
|
+
delete rest.shadowed;
|
|
541
|
+
const next = filtered.length > 0 ? { ...rest, shadowed: filtered } : rest;
|
|
542
|
+
decls.set(prop, next);
|
|
543
|
+
}
|
|
544
|
+
blocks.set(key, { condition: block.condition, decls });
|
|
545
|
+
}
|
|
546
|
+
return { blocks };
|
|
547
|
+
}
|
|
548
|
+
function compileFlattenInto(recipe) {
|
|
549
|
+
const childGains = recipe.childGains ? plainToStyleMap(recipe.childGains) : null;
|
|
550
|
+
const fold = recipe.foldInherited !== false;
|
|
551
|
+
return (ctx, rw) => {
|
|
552
|
+
const wrapper = ctx.node;
|
|
553
|
+
const child = ctx.onlyElementChild();
|
|
554
|
+
if (!child) return null;
|
|
555
|
+
const ops = [];
|
|
556
|
+
if (fold) ops.push(rw.foldInheritedStyles(wrapper, child, { conditions: "all" }));
|
|
557
|
+
if (childGains) ops.push(rw.mergeStyle(child, null, childGains, "source-wins"));
|
|
558
|
+
ops.push(rw.unwrap(wrapper));
|
|
559
|
+
return ops;
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function compileRewrite(rewrite) {
|
|
563
|
+
if (typeof rewrite === "function") return rewrite;
|
|
564
|
+
if ("flattenInto" in rewrite) return compileFlattenInto(rewrite);
|
|
565
|
+
if ("rewriteClasses" in rewrite) {
|
|
566
|
+
const preserveOpaque = rewrite.preserveOpaque ?? true;
|
|
567
|
+
return (ctx, rw) => {
|
|
568
|
+
const next = rewrite.rewriteClasses(ctx.computed(), ctx);
|
|
569
|
+
if (!next) return null;
|
|
570
|
+
return [rw.setClassList(ctx.node, next, preserveOpaque)];
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
if ("dropClasses" in rewrite) {
|
|
574
|
+
const preserveOpaque = rewrite.preserveOpaque ?? true;
|
|
575
|
+
return (ctx, rw) => {
|
|
576
|
+
const drop = new Set(rewrite.dropClasses(ctx.computed(), ctx));
|
|
577
|
+
if (drop.size === 0) return null;
|
|
578
|
+
return [rw.setClassList(ctx.node, pruneShadowed(ctx.computed(), drop), preserveOpaque)];
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
const style = plainToStyleMap(rewrite.mergeStyle);
|
|
582
|
+
const onConflict = rewrite.onConflict ?? "abort";
|
|
583
|
+
return (ctx, rw) => [rw.mergeStyle(ctx.node, null, style, onConflict)];
|
|
584
|
+
}
|
|
585
|
+
function pattern(config) {
|
|
586
|
+
const matchFn = compileMatch(config.match, config.category);
|
|
587
|
+
const rewriteFn = compileRewrite(config.rewrite);
|
|
588
|
+
const spec = {
|
|
589
|
+
name: config.name,
|
|
590
|
+
category: config.category,
|
|
591
|
+
safety: config.safety,
|
|
592
|
+
priority: config.priority,
|
|
593
|
+
precondition: config.precondition,
|
|
594
|
+
doc: config.doc,
|
|
595
|
+
examples: config.examples,
|
|
596
|
+
evaluate(ctx, rw) {
|
|
597
|
+
if (!matchFn(ctx.node, ctx)) return null;
|
|
598
|
+
const ops = rewriteFn(ctx, rw);
|
|
599
|
+
if (!ops || ops.length === 0) return null;
|
|
600
|
+
return { ops };
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
return definePattern(spec);
|
|
604
|
+
}
|
|
605
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
606
|
+
0 && (module.exports = {
|
|
607
|
+
and,
|
|
608
|
+
computed,
|
|
609
|
+
createNormalizer,
|
|
610
|
+
definePattern,
|
|
611
|
+
emptyStyleMap,
|
|
612
|
+
foldInheritedStyles,
|
|
613
|
+
hasDynamicChildren,
|
|
614
|
+
hasDynamicClasses,
|
|
615
|
+
hasEventHandlers,
|
|
616
|
+
hasOwnVisualStyle,
|
|
617
|
+
hasRef,
|
|
618
|
+
hasSingleElementChild,
|
|
619
|
+
isElement,
|
|
620
|
+
isStyleSuperset,
|
|
621
|
+
mergeStyle,
|
|
622
|
+
normalizer,
|
|
623
|
+
not,
|
|
624
|
+
or,
|
|
625
|
+
pattern,
|
|
626
|
+
removeNode,
|
|
627
|
+
replaceWith,
|
|
628
|
+
targetedByCombinator
|
|
629
|
+
});
|
|
630
|
+
//# sourceMappingURL=pattern-kit.cjs.map
|