@pairdraw/dom-css 0.0.0-stage → 0.16.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/LICENSE +21 -0
- package/README.md +219 -2
- package/dist/browser.d.ts +29 -0
- package/dist/browser.js +2 -0
- package/dist/chunks/behaviours/args.js +59 -0
- package/dist/chunks/behaviours/args.js.map +1 -0
- package/dist/chunks/behaviours/controls.js +109 -0
- package/dist/chunks/behaviours/controls.js.map +1 -0
- package/dist/chunks/behaviours/reset.js +40 -0
- package/dist/chunks/behaviours/reset.js.map +1 -0
- package/dist/chunks/behaviours/roles.js +51 -0
- package/dist/chunks/behaviours/roles.js.map +1 -0
- package/dist/chunks/behaviours/states/conditions.js +103 -0
- package/dist/chunks/behaviours/states/conditions.js.map +1 -0
- package/dist/chunks/behaviours/states/css.js +172 -0
- package/dist/chunks/behaviours/states/css.js.map +1 -0
- package/dist/chunks/behaviours/states/layers.js +1736 -0
- package/dist/chunks/behaviours/states/layers.js.map +1 -0
- package/dist/chunks/behaviours/states/model.js +144 -0
- package/dist/chunks/behaviours/states/model.js.map +1 -0
- package/dist/chunks/behaviours/states/tailwind.js +198 -0
- package/dist/chunks/behaviours/states/tailwind.js.map +1 -0
- package/dist/chunks/browser.js +1352 -0
- package/dist/chunks/browser.js.map +1 -0
- package/dist/chunks/export/bundle.js +337 -0
- package/dist/chunks/export/bundle.js.map +1 -0
- package/dist/chunks/export/components/drawn.js +60 -0
- package/dist/chunks/export/components/drawn.js.map +1 -0
- package/dist/chunks/export/components/fields.js +178 -0
- package/dist/chunks/export/components/fields.js.map +1 -0
- package/dist/chunks/export/components/groups.js +297 -0
- package/dist/chunks/export/components/groups.js.map +1 -0
- package/dist/chunks/export/components/icons.js +260 -0
- package/dist/chunks/export/components/icons.js.map +1 -0
- package/dist/chunks/export/components/layers.js +1599 -0
- package/dist/chunks/export/components/layers.js.map +1 -0
- package/dist/chunks/export/index.js +477 -0
- package/dist/chunks/export/index.js.map +1 -0
- package/dist/chunks/export/storybook/component.js +448 -0
- package/dist/chunks/export/storybook/component.js.map +1 -0
- package/dist/chunks/export/storybook/export.js +410 -0
- package/dist/chunks/export/storybook/export.js.map +1 -0
- package/dist/chunks/import/html.js +406 -0
- package/dist/chunks/import/html.js.map +1 -0
- package/dist/chunks/import/jsx/dev-runtime.js +37 -0
- package/dist/chunks/import/jsx/dev-runtime.js.map +1 -0
- package/dist/chunks/tokens/cssom-validator.js +10 -0
- package/dist/chunks/tokens/cssom-validator.js.map +1 -0
- package/dist/export.d.ts +594 -0
- package/dist/export.js +13 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +7 -0
- package/dist/jsx-dev-runtime.d.ts +8 -0
- package/dist/jsx-dev-runtime.js +3 -0
- package/dist/jsx-runtime.d.ts +20 -0
- package/dist/jsx-runtime.js +3 -0
- package/dist/rolldown-runtime.js +13 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/scene-graph.d.ts +2 -0
- package/dist/scene-graph.js +2 -0
- package/dist/scene-graph2.d.ts +10 -0
- package/dist/styling.d.ts +93 -0
- package/dist/tailwind.d.ts +39 -0
- package/dist/types.d.ts +89 -0
- package/package.json +88 -4
- package/src/behaviours/args.ts +85 -0
- package/src/behaviours/controls.ts +195 -0
- package/src/behaviours/index.ts +11 -0
- package/src/behaviours/reset.ts +37 -0
- package/src/behaviours/roles.ts +44 -0
- package/src/behaviours/states/conditions.ts +105 -0
- package/src/behaviours/states/css.ts +123 -0
- package/src/behaviours/states/index.ts +4 -0
- package/src/behaviours/states/layers.ts +205 -0
- package/src/behaviours/states/model.ts +175 -0
- package/src/behaviours/states/names.ts +39 -0
- package/src/behaviours/states/tailwind.ts +148 -0
- package/src/behaviours/states/types.ts +56 -0
- package/src/browser.ts +146 -0
- package/src/cssom.d.ts +38 -0
- package/src/export/bundle.ts +461 -0
- package/src/export/components/drawn.ts +73 -0
- package/src/export/components/fields.ts +178 -0
- package/src/export/components/groups.ts +78 -0
- package/src/export/components/icons.ts +230 -0
- package/src/export/components/layers.ts +121 -0
- package/src/export/components/model.ts +544 -0
- package/src/export/components/properties.ts +167 -0
- package/src/export/components/react/fields.ts +129 -0
- package/src/export/components/react/index.ts +412 -0
- package/src/export/components/react/props.ts +151 -0
- package/src/export/components/react/radix.ts +52 -0
- package/src/export/components/react/shared.ts +76 -0
- package/src/export/components/references.ts +212 -0
- package/src/export/components/repeats.ts +128 -0
- package/src/export/components/shaders.ts +125 -0
- package/src/export/components/styling.ts +31 -0
- package/src/export/components/tree.ts +72 -0
- package/src/export/components/vue.ts +517 -0
- package/src/export/css.ts +57 -0
- package/src/export/grid.ts +42 -0
- package/src/export/html.ts +163 -0
- package/src/export/index.ts +44 -0
- package/src/export/projection.ts +581 -0
- package/src/export/storybook/component.ts +334 -0
- package/src/export/storybook/export.ts +430 -0
- package/src/export/storybook/groups.ts +161 -0
- package/src/export/storybook/module.ts +319 -0
- package/src/export/storybook/names.ts +51 -0
- package/src/export/tailwind-jsx.ts +156 -0
- package/src/export/text.ts +415 -0
- package/src/import/css-text.ts +4 -0
- package/src/import/css-values.ts +31 -0
- package/src/import/flow.ts +248 -0
- package/src/import/html.ts +88 -0
- package/src/import/jsx/core.ts +130 -0
- package/src/import/jsx/dev-runtime.ts +8 -0
- package/src/import/jsx/runtime.ts +76 -0
- package/src/import/scene-graph.ts +582 -0
- package/src/import/style-attribute.ts +25 -0
- package/src/import/tailwind.ts +54 -0
- package/src/import/text.ts +518 -0
- package/src/index.ts +51 -0
- package/src/runtime/browser/runtime.ts +301 -0
- package/src/runtime/headless/runtime.ts +99 -0
- package/src/runtime/headless/styles.ts +330 -0
- package/src/runtime/index.ts +11 -0
- package/src/tokens/conditions.ts +66 -0
- package/src/tokens/cssom-validator.ts +8 -0
- package/src/tokens/custom-properties.ts +331 -0
- package/src/tokens/expression.ts +128 -0
- package/src/tokens/formula.ts +140 -0
- package/src/tokens/index.ts +43 -0
- package/src/tokens/names.ts +161 -0
- package/src/tokens/references.ts +201 -0
- package/src/tokens/stylesheet.ts +304 -0
- package/src/tokens/validate.ts +86 -0
- package/src/tokens/values.ts +44 -0
- package/src/types.ts +59 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { __exportAll } from "../../rolldown-runtime.js";
|
|
2
|
+
import { serializeHTML } from "../behaviours/states/tailwind.js";
|
|
3
|
+
import { INLINE_TAGS, createBrowserCSSRuntime, designDocumentToSceneGraph, mergeCSSText } from "../browser.js";
|
|
4
|
+
import { tryParseColor } from "@pairdraw/scene-graph/color";
|
|
5
|
+
import { parse, parseFragment } from "parse5";
|
|
6
|
+
import { parseCSSNumber, splitCSSValue } from "@pairdraw/scene-graph/css";
|
|
7
|
+
import { parse as parse$1 } from "@acemir/cssom";
|
|
8
|
+
import { compile } from "tailwindcss";
|
|
9
|
+
//#region src/import/style-attribute.ts
|
|
10
|
+
function firstStyleRule(cssText) {
|
|
11
|
+
const [rule] = parse$1(cssText).cssRules;
|
|
12
|
+
if (!rule || typeof rule !== "object" || !("style" in rule)) return null;
|
|
13
|
+
return rule;
|
|
14
|
+
}
|
|
15
|
+
function parseStyleAttribute(value) {
|
|
16
|
+
if (!value) return void 0;
|
|
17
|
+
const rule = firstStyleRule(`*{${value}}`);
|
|
18
|
+
if (!rule) return void 0;
|
|
19
|
+
const style = {};
|
|
20
|
+
for (const property of Array.from(rule.style)) {
|
|
21
|
+
const propertyValue = rule.style.getPropertyValue(property);
|
|
22
|
+
if (propertyValue) style[property] = propertyValue;
|
|
23
|
+
}
|
|
24
|
+
return Object.keys(style).length > 0 ? style : void 0;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/runtime/headless/styles.ts
|
|
28
|
+
const INHERITED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
29
|
+
"color",
|
|
30
|
+
"font-family",
|
|
31
|
+
"font-size",
|
|
32
|
+
"font-weight",
|
|
33
|
+
"line-height"
|
|
34
|
+
]);
|
|
35
|
+
function styleToRecord(style, customProperties = {}) {
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const property of Array.from({ length: style.length }, (_, index) => style[index])) {
|
|
38
|
+
const value = resolveCSSValue(style.getPropertyValue(property), customProperties);
|
|
39
|
+
if (property && value) result[property] = value;
|
|
40
|
+
}
|
|
41
|
+
return expandStyleShorthands(result);
|
|
42
|
+
}
|
|
43
|
+
function isStyleRule(rule) {
|
|
44
|
+
return typeof rule === "object" && rule !== null && "selectorText" in rule && "style" in rule && typeof rule.selectorText === "string";
|
|
45
|
+
}
|
|
46
|
+
function isGroupingRule(rule) {
|
|
47
|
+
return typeof rule === "object" && rule !== null && "cssRules" in rule && Array.isArray(rule.cssRules);
|
|
48
|
+
}
|
|
49
|
+
function collectStyleRules(rules) {
|
|
50
|
+
return rules.flatMap((rule) => {
|
|
51
|
+
if (isStyleRule(rule)) return [rule];
|
|
52
|
+
if (isGroupingRule(rule)) return collectStyleRules(rule.cssRules);
|
|
53
|
+
return [];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function parseRules(cssText) {
|
|
57
|
+
let order = 0;
|
|
58
|
+
const styleRules = collectStyleRules(parse$1(cssText).cssRules);
|
|
59
|
+
const customProperties = collectCustomProperties(styleRules);
|
|
60
|
+
return {
|
|
61
|
+
rules: styleRules.flatMap((rule) => {
|
|
62
|
+
const style = styleToRecord(rule.style, customProperties);
|
|
63
|
+
return rule.selectorText.split(",").map((selector) => selector.trim()).filter((selector) => selector.length > 0).map((selector) => ({
|
|
64
|
+
selector,
|
|
65
|
+
specificity: selectorSpecificity(selector),
|
|
66
|
+
order: order++,
|
|
67
|
+
style
|
|
68
|
+
}));
|
|
69
|
+
}),
|
|
70
|
+
customProperties
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function collectCustomProperties(rules) {
|
|
74
|
+
const customProperties = {};
|
|
75
|
+
for (const rule of rules) {
|
|
76
|
+
if (!rule.selectorText.split(",").some((selector) => selector.trim() === ":root")) continue;
|
|
77
|
+
Object.assign(customProperties, styleToRecord(rule.style));
|
|
78
|
+
}
|
|
79
|
+
return customProperties;
|
|
80
|
+
}
|
|
81
|
+
function resolveCSSValue(value, customProperties) {
|
|
82
|
+
return resolveSimpleCalc(value.replaceAll(/var\((--[\w-]+)(?:,[^)]+)?\)/g, (_, name) => {
|
|
83
|
+
return customProperties[name] ?? "";
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
function resolveSimpleCalc(value) {
|
|
87
|
+
const calc = value.match(/^calc\(([-\d.]+)(rem|px)?\s*\*\s*([-\d.]+)\)$/);
|
|
88
|
+
if (!calc?.[1] || !calc[3]) return value;
|
|
89
|
+
const base = Number.parseFloat(calc[1]);
|
|
90
|
+
const multiplier = Number.parseFloat(calc[3]);
|
|
91
|
+
const unit = calc.at(2) ?? "px";
|
|
92
|
+
if (!Number.isFinite(base) || !Number.isFinite(multiplier)) return value;
|
|
93
|
+
return `${unit === "rem" ? base * multiplier * 16 : base * multiplier}px`;
|
|
94
|
+
}
|
|
95
|
+
const BORDER_STYLES = /* @__PURE__ */ new Set([
|
|
96
|
+
"none",
|
|
97
|
+
"hidden",
|
|
98
|
+
"dotted",
|
|
99
|
+
"dashed",
|
|
100
|
+
"solid",
|
|
101
|
+
"double",
|
|
102
|
+
"groove",
|
|
103
|
+
"ridge",
|
|
104
|
+
"inset",
|
|
105
|
+
"outset"
|
|
106
|
+
]);
|
|
107
|
+
/**
|
|
108
|
+
* Shorthands as the longhands they set, in declaration order, so a later declaration wins over
|
|
109
|
+
* an earlier one whether it is a shorthand, a logical side, or a single side, as in CSS.
|
|
110
|
+
*/
|
|
111
|
+
function expandStyleShorthands(style) {
|
|
112
|
+
const result = {};
|
|
113
|
+
for (const [property, value] of Object.entries(style)) {
|
|
114
|
+
result[property] = value;
|
|
115
|
+
Object.assign(result, longhandsOf(property, value));
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function longhandsOf(property, value) {
|
|
120
|
+
if (property === "margin" || property === "padding") return boxSides(property, value);
|
|
121
|
+
const logical = /^(margin|padding)-(inline|block)$/u.exec(property);
|
|
122
|
+
if (logical) return logicalSides(property, value, logical[2] === "inline");
|
|
123
|
+
if (property === "border") return borderLonghands(value);
|
|
124
|
+
if (property === "background") {
|
|
125
|
+
const color = splitCSSValue(value).find(isColor);
|
|
126
|
+
return color ? { "background-color": color } : {};
|
|
127
|
+
}
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
function boxSides(property, value) {
|
|
131
|
+
const [top, right = top, bottom = top, left = right] = splitCSSValue(value);
|
|
132
|
+
if (!top || !right || !bottom || !left) return {};
|
|
133
|
+
return {
|
|
134
|
+
[`${property}-top`]: top,
|
|
135
|
+
[`${property}-right`]: right,
|
|
136
|
+
[`${property}-bottom`]: bottom,
|
|
137
|
+
[`${property}-left`]: left
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** `padding-inline` and `padding-block` as the sides they set in left-to-right, horizontal text. */
|
|
141
|
+
function logicalSides(property, value, inline) {
|
|
142
|
+
const box = property.slice(0, property.lastIndexOf("-"));
|
|
143
|
+
const [first, second = first] = splitCSSValue(value);
|
|
144
|
+
if (!first || !second) return {};
|
|
145
|
+
const [start, end] = inline ? ["left", "right"] : ["top", "bottom"];
|
|
146
|
+
return {
|
|
147
|
+
[`${box}-${start}`]: first,
|
|
148
|
+
[`${box}-${end}`]: second
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function borderLonghands(value) {
|
|
152
|
+
const parts = splitCSSValue(value);
|
|
153
|
+
const longhands = {};
|
|
154
|
+
const color = parts.find(isColor);
|
|
155
|
+
const width = parts.find((part) => parseCSSNumber(part) !== null);
|
|
156
|
+
const style = parts.find((part) => BORDER_STYLES.has(part.toLowerCase()));
|
|
157
|
+
if (color) longhands["border-color"] = color;
|
|
158
|
+
if (width) longhands["border-width"] = width;
|
|
159
|
+
if (style) longhands["border-style"] = style.toLowerCase();
|
|
160
|
+
return longhands;
|
|
161
|
+
}
|
|
162
|
+
/** Any CSS color, including `transparent`, which a shorthand may set on purpose. */
|
|
163
|
+
function isColor(value) {
|
|
164
|
+
return tryParseColor(value) !== null;
|
|
165
|
+
}
|
|
166
|
+
function classList(element) {
|
|
167
|
+
const className = "class" in element.attrs ? element.attrs.class : "";
|
|
168
|
+
return new Set(className.split(/\s+/).filter((name) => name.length > 0));
|
|
169
|
+
}
|
|
170
|
+
function elementId(element) {
|
|
171
|
+
return "id" in element.attrs ? element.attrs.id : void 0;
|
|
172
|
+
}
|
|
173
|
+
function selectorSpecificity(selector) {
|
|
174
|
+
const idCount = selector.match(/#[\w-]+/g)?.length ?? 0;
|
|
175
|
+
const classCount = selector.match(/\.[\w-]+/g)?.length ?? 0;
|
|
176
|
+
const tagCount = selector.split(/[\s>]+/).filter((part) => /^[a-z]/iu.test(part)).length;
|
|
177
|
+
return idCount * 100 + classCount * 10 + tagCount;
|
|
178
|
+
}
|
|
179
|
+
function matchesSimpleSelector(element, selector) {
|
|
180
|
+
if (selector.includes(":") || selector.includes("[")) return false;
|
|
181
|
+
const idMatch = selector.match(/#([\w-]+)/);
|
|
182
|
+
if (idMatch?.[1] && elementId(element) !== idMatch[1]) return false;
|
|
183
|
+
const classes = selector.match(/\.[\w-]+/g) ?? [];
|
|
184
|
+
const elementClasses = classList(element);
|
|
185
|
+
if (!classes.every((name) => elementClasses.has(name.slice(1)))) return false;
|
|
186
|
+
const tag = selector.replace(/#[\w-]+/g, "").replace(/\.[\w-]+/g, "");
|
|
187
|
+
return tag.length === 0 || tag === "*" || element.tagName.toLowerCase() === tag.toLowerCase();
|
|
188
|
+
}
|
|
189
|
+
function matchesSelector(element, selector, parent) {
|
|
190
|
+
const childParts = selector.split(">").map((part) => part.trim());
|
|
191
|
+
if (childParts.length > 1) return matchesChildSelector(element, childParts, parent);
|
|
192
|
+
const descendantParts = selector.split(/\s+/).filter((part) => part.length > 0);
|
|
193
|
+
if (descendantParts.length > 1) return matchesDescendantSelector(element, descendantParts, parent);
|
|
194
|
+
return matchesSimpleSelector(element, selector);
|
|
195
|
+
}
|
|
196
|
+
function matchesSelectorParts(element, parts, parent, directParentOnly) {
|
|
197
|
+
const current = parts.at(-1);
|
|
198
|
+
if (!current || !matchesSimpleSelector(element, current)) return false;
|
|
199
|
+
let ancestor = parent;
|
|
200
|
+
for (const selector of parts.slice(0, -1).reverse()) {
|
|
201
|
+
if (!directParentOnly) while (ancestor && !matchesSimpleSelector(ancestor.element, selector)) ancestor = ancestor.parent;
|
|
202
|
+
if (!ancestor || !matchesSimpleSelector(ancestor.element, selector)) return false;
|
|
203
|
+
ancestor = ancestor.parent;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
function matchesChildSelector(element, parts, parent) {
|
|
208
|
+
return matchesSelectorParts(element, parts, parent, true);
|
|
209
|
+
}
|
|
210
|
+
function matchesDescendantSelector(element, parts, parent) {
|
|
211
|
+
return matchesSelectorParts(element, parts, parent, false);
|
|
212
|
+
}
|
|
213
|
+
function applyComputedStyles(node, rules, parent, inheritedStyle) {
|
|
214
|
+
if (node.type === "text") return node;
|
|
215
|
+
const computedStyle = pickInheritedStyle(inheritedStyle);
|
|
216
|
+
const matchingRules = rules.filter((rule) => matchesSelector(node, rule.selector, parent)).sort((left, right) => left.specificity - right.specificity || left.order - right.order);
|
|
217
|
+
for (const rule of matchingRules) Object.assign(computedStyle, rule.style);
|
|
218
|
+
Object.assign(computedStyle, expandStyleShorthands(node.inlineStyle ?? {}));
|
|
219
|
+
const context = {
|
|
220
|
+
element: node,
|
|
221
|
+
parent
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
...node,
|
|
225
|
+
computedStyle: Object.keys(computedStyle).length > 0 ? computedStyle : void 0,
|
|
226
|
+
children: node.children.map((child) => applyComputedStyles(child, rules, context, computedStyle))
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function pickInheritedStyle(style) {
|
|
230
|
+
const inherited = {};
|
|
231
|
+
for (const property of INHERITED_PROPERTIES) {
|
|
232
|
+
const value = style[property];
|
|
233
|
+
if (value) inherited[property] = value;
|
|
234
|
+
}
|
|
235
|
+
return inherited;
|
|
236
|
+
}
|
|
237
|
+
function computeHeadlessStyles(document, cssText = "") {
|
|
238
|
+
const { rules } = parseRules([document.stylesheets?.map((sheet) => sheet.cssText).join("\n"), cssText].filter((text) => !!text).join("\n"));
|
|
239
|
+
return {
|
|
240
|
+
...document,
|
|
241
|
+
children: document.children.map((child) => applyComputedStyles(child, rules, null, {}))
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/runtime/headless/runtime.ts
|
|
246
|
+
function attrsToRecord(attrs) {
|
|
247
|
+
const result = {};
|
|
248
|
+
for (const attr of attrs) result[attr.name] = attr.value;
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
function isTextNode(node) {
|
|
252
|
+
return node.nodeName === "#text";
|
|
253
|
+
}
|
|
254
|
+
const NON_RENDERED_TAGS = /* @__PURE__ */ new Set([
|
|
255
|
+
"head",
|
|
256
|
+
"link",
|
|
257
|
+
"meta",
|
|
258
|
+
"script",
|
|
259
|
+
"style",
|
|
260
|
+
"template",
|
|
261
|
+
"title"
|
|
262
|
+
]);
|
|
263
|
+
function isInlineElement(node) {
|
|
264
|
+
return node !== void 0 && "tagName" in node && INLINE_TAGS.has(node.tagName.toLowerCase());
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Text, and the spaces in or beside inline elements, which CSS draws among their words; spaces
|
|
268
|
+
* between blocks lay nothing out, so they are left out.
|
|
269
|
+
*/
|
|
270
|
+
function keepsText(node, siblings, index, inInline) {
|
|
271
|
+
if (node.value.trim().length > 0) return true;
|
|
272
|
+
return node.value.length > 0 && (inInline || isInlineElement(siblings[index - 1]) || isInlineElement(siblings[index + 1]));
|
|
273
|
+
}
|
|
274
|
+
function childrenToDesignNodes(nodes, inInline) {
|
|
275
|
+
return nodes.map((node, index) => childToDesignNode(node, index, nodes, inInline)).filter((child) => child !== null);
|
|
276
|
+
}
|
|
277
|
+
function childToDesignNode(node, index, siblings, inInline) {
|
|
278
|
+
if (isTextNode(node)) return keepsText(node, siblings, index, inInline) ? {
|
|
279
|
+
type: "text",
|
|
280
|
+
text: node.value
|
|
281
|
+
} : null;
|
|
282
|
+
if (!("tagName" in node)) return null;
|
|
283
|
+
if (NON_RENDERED_TAGS.has(node.tagName.toLowerCase())) return null;
|
|
284
|
+
const attrs = attrsToRecord(node.attrs);
|
|
285
|
+
const element = {
|
|
286
|
+
type: "element",
|
|
287
|
+
tagName: node.tagName.toLowerCase(),
|
|
288
|
+
attrs,
|
|
289
|
+
children: childrenToDesignNodes(node.childNodes, isInlineElement(node))
|
|
290
|
+
};
|
|
291
|
+
const inlineStyle = parseStyleAttribute(attrs.style);
|
|
292
|
+
if (inlineStyle) element.inlineStyle = inlineStyle;
|
|
293
|
+
return element;
|
|
294
|
+
}
|
|
295
|
+
function parseHTML(html) {
|
|
296
|
+
return {
|
|
297
|
+
type: "document",
|
|
298
|
+
children: childrenToDesignNodes(parseFragment(html).childNodes, false)
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function createHeadlessCSSRuntime() {
|
|
302
|
+
return {
|
|
303
|
+
kind: "headless",
|
|
304
|
+
parseHTML,
|
|
305
|
+
serializeHTML(document) {
|
|
306
|
+
return serializeHTML(document);
|
|
307
|
+
},
|
|
308
|
+
async computeStyles(document, cssText = "") {
|
|
309
|
+
return computeHeadlessStyles(document, cssText);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/runtime/index.ts
|
|
315
|
+
var runtime_exports = /* @__PURE__ */ __exportAll({ createCSSRuntime: () => createCSSRuntime });
|
|
316
|
+
function createCSSRuntime() {
|
|
317
|
+
return typeof document !== "undefined" ? createBrowserCSSRuntime() : createHeadlessCSSRuntime();
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/import/tailwind.ts
|
|
321
|
+
var tailwind_exports = /* @__PURE__ */ __exportAll({ compileTailwindCSS: () => compileTailwindCSS });
|
|
322
|
+
const DEFAULT_TAILWIND_CSS = "@import \"tailwindcss\";";
|
|
323
|
+
async function compileTailwindCSS(classes, options = {}) {
|
|
324
|
+
return (await compile(tailwindCompilerCSS(options.css), {
|
|
325
|
+
base: options.base,
|
|
326
|
+
loadStylesheet: async (id, base) => {
|
|
327
|
+
return {
|
|
328
|
+
path: id,
|
|
329
|
+
base,
|
|
330
|
+
content: options.loadStylesheet ? await options.loadStylesheet(id, base) : await loadTailwindStylesheet(id)
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
})).build(normalizeClasses(classes));
|
|
334
|
+
}
|
|
335
|
+
function tailwindCompilerCSS(css) {
|
|
336
|
+
const trimmed = css?.trim();
|
|
337
|
+
if (!trimmed) return DEFAULT_TAILWIND_CSS;
|
|
338
|
+
if (containsTailwindImport(trimmed)) return trimmed;
|
|
339
|
+
return `${DEFAULT_TAILWIND_CSS}\n${trimmed}`;
|
|
340
|
+
}
|
|
341
|
+
function containsTailwindImport(css) {
|
|
342
|
+
const withoutComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
343
|
+
return /^\s*@import\s+(?:"tailwindcss(?:\/[^"]*)?"|'tailwindcss(?:\/[^']*)?')/m.test(withoutComments);
|
|
344
|
+
}
|
|
345
|
+
function normalizeClasses(classes) {
|
|
346
|
+
return (typeof classes === "string" ? [classes] : Array.from(classes)).flatMap((className) => className.split(/\s+/)).map((className) => className.trim()).filter((className) => className.length > 0);
|
|
347
|
+
}
|
|
348
|
+
async function loadTailwindStylesheet(id) {
|
|
349
|
+
const stylesheet = id === "tailwindcss" ? "tailwindcss/index.css" : id;
|
|
350
|
+
const url = new URL(import.meta.resolve(stylesheet));
|
|
351
|
+
const { readFile } = await import(
|
|
352
|
+
/* @vite-ignore */
|
|
353
|
+
"node:fs/promises"
|
|
354
|
+
);
|
|
355
|
+
return readFile(url, "utf8");
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/import/html.ts
|
|
359
|
+
function runtimeForOptions(runtime) {
|
|
360
|
+
return runtime ?? createCSSRuntime();
|
|
361
|
+
}
|
|
362
|
+
function getChildNodes(node) {
|
|
363
|
+
return "childNodes" in node ? node.childNodes : [];
|
|
364
|
+
}
|
|
365
|
+
function textContent(node) {
|
|
366
|
+
if (node.nodeName === "#text" && "value" in node) return node.value;
|
|
367
|
+
return getChildNodes(node).map(textContent).join("");
|
|
368
|
+
}
|
|
369
|
+
function collectStyleText(node, styles) {
|
|
370
|
+
if ("tagName" in node && node.tagName.toLowerCase() === "style") {
|
|
371
|
+
const css = textContent(node).trim();
|
|
372
|
+
if (css) styles.push(css);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
for (const child of getChildNodes(node)) collectStyleText(child, styles);
|
|
376
|
+
}
|
|
377
|
+
function extractEmbeddedCSSText(html) {
|
|
378
|
+
const styles = [];
|
|
379
|
+
collectStyleText(parse(html), styles);
|
|
380
|
+
return styles.length > 0 ? styles.join("\n") : void 0;
|
|
381
|
+
}
|
|
382
|
+
async function htmlToDesignDocument(html, options = {}) {
|
|
383
|
+
const runtime = runtimeForOptions(options.runtime);
|
|
384
|
+
const document = runtime.parseHTML(html);
|
|
385
|
+
const cssText = mergeCSSText(extractEmbeddedCSSText(html), options.cssText);
|
|
386
|
+
return runtime.computeStyles(document, cssText, options.compute);
|
|
387
|
+
}
|
|
388
|
+
async function htmlToSceneGraph(html, options = {}) {
|
|
389
|
+
const document = await htmlToDesignDocument(html, options);
|
|
390
|
+
return designDocumentToSceneGraph(document, options);
|
|
391
|
+
}
|
|
392
|
+
async function tailwindHTMLToDesignDocument(html, candidates, options = {}) {
|
|
393
|
+
const cssText = await compileTailwindCSS(candidates, options);
|
|
394
|
+
return htmlToDesignDocument(html, {
|
|
395
|
+
...options,
|
|
396
|
+
cssText
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
async function tailwindHTMLToSceneGraph(html, candidates, options = {}) {
|
|
400
|
+
const document = await tailwindHTMLToDesignDocument(html, candidates, options);
|
|
401
|
+
return designDocumentToSceneGraph(document, options);
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
404
|
+
export { compileTailwindCSS, createCSSRuntime, createHeadlessCSSRuntime, htmlToDesignDocument, htmlToSceneGraph, runtime_exports, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph, tailwind_exports };
|
|
405
|
+
|
|
406
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","names":["parse","parse"],"sources":["../../../src/import/style-attribute.ts","../../../src/runtime/headless/styles.ts","../../../src/runtime/headless/runtime.ts","../../../src/runtime/index.ts","../../../src/import/tailwind.ts","../../../src/import/html.ts"],"sourcesContent":["import { parse } from '@acemir/cssom'\nimport type { CSSStyleRuleLike } from '@acemir/cssom'\n\nimport type { DesignStyleDeclaration } from '../types'\n\nfunction firstStyleRule(cssText: string): CSSStyleRuleLike | null {\n const [rule] = parse(cssText).cssRules\n if (!rule || typeof rule !== 'object' || !('style' in rule)) return null\n return rule as CSSStyleRuleLike\n}\n\nexport function parseStyleAttribute(value: string | undefined): DesignStyleDeclaration | undefined {\n if (!value) return undefined\n\n const rule = firstStyleRule(`*{${value}}`)\n if (!rule) return undefined\n\n const style: DesignStyleDeclaration = {}\n for (const property of Array.from(rule.style)) {\n const propertyValue = rule.style.getPropertyValue(property)\n if (propertyValue) style[property] = propertyValue\n }\n\n return Object.keys(style).length > 0 ? style : undefined\n}\n","import type {\n DesignDocument,\n DesignElement,\n DesignNode,\n DesignStyleDeclaration\n} from '#dom-css/types'\nimport {\n parse,\n type CSSGroupingRuleLike,\n type CSSStyleDeclarationLike,\n type CSSStyleRuleLike\n} from '@acemir/cssom'\n\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport { parseCSSNumber, splitCSSValue } from '@pairdraw/scene-graph/css'\n\ninterface HeadlessCSSRule {\n selector: string\n specificity: number\n order: number\n style: DesignStyleDeclaration\n}\n\ninterface ParsedHeadlessCSS {\n rules: HeadlessCSSRule[]\n customProperties: DesignStyleDeclaration\n}\n\ninterface AncestorContext {\n element: DesignElement\n parent: AncestorContext | null\n}\n\nconst INHERITED_PROPERTIES = new Set([\n 'color',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'line-height'\n])\n\nfunction styleToRecord(\n style: CSSStyleDeclarationLike,\n customProperties: DesignStyleDeclaration = {}\n): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const property of Array.from({ length: style.length }, (_, index) => style[index])) {\n const value = resolveCSSValue(style.getPropertyValue(property), customProperties)\n if (property && value) result[property] = value\n }\n return expandStyleShorthands(result)\n}\n\nfunction isStyleRule(rule: unknown): rule is CSSStyleRuleLike {\n return (\n typeof rule === 'object' &&\n rule !== null &&\n 'selectorText' in rule &&\n 'style' in rule &&\n typeof rule.selectorText === 'string'\n )\n}\n\nfunction isGroupingRule(rule: unknown): rule is CSSGroupingRuleLike {\n return (\n typeof rule === 'object' && rule !== null && 'cssRules' in rule && Array.isArray(rule.cssRules)\n )\n}\n\nfunction collectStyleRules(rules: unknown[]): CSSStyleRuleLike[] {\n return rules.flatMap((rule) => {\n if (isStyleRule(rule)) return [rule]\n if (isGroupingRule(rule)) return collectStyleRules(rule.cssRules)\n return []\n })\n}\n\nfunction parseRules(cssText: string): ParsedHeadlessCSS {\n let order = 0\n const sheet = parse(cssText)\n const styleRules = collectStyleRules(sheet.cssRules)\n const customProperties = collectCustomProperties(styleRules)\n const rules = styleRules.flatMap((rule) => {\n const style = styleToRecord(rule.style, customProperties)\n return rule.selectorText\n .split(',')\n .map((selector) => selector.trim())\n .filter((selector) => selector.length > 0)\n .map((selector) => ({\n selector,\n specificity: selectorSpecificity(selector),\n order: order++,\n style\n }))\n })\n return { rules, customProperties }\n}\n\nfunction collectCustomProperties(rules: CSSStyleRuleLike[]): DesignStyleDeclaration {\n const customProperties: DesignStyleDeclaration = {}\n for (const rule of rules) {\n if (!rule.selectorText.split(',').some((selector) => selector.trim() === ':root')) continue\n Object.assign(customProperties, styleToRecord(rule.style))\n }\n return customProperties\n}\n\nfunction resolveCSSValue(value: string, customProperties: DesignStyleDeclaration): string {\n const withVariables = value.replaceAll(/var\\((--[\\w-]+)(?:,[^)]+)?\\)/g, (_, name: string) => {\n return customProperties[name] ?? ''\n })\n return resolveSimpleCalc(withVariables)\n}\n\nfunction resolveSimpleCalc(value: string): string {\n const calc = value.match(/^calc\\(([-\\d.]+)(rem|px)?\\s*\\*\\s*([-\\d.]+)\\)$/)\n if (!calc?.[1] || !calc[3]) return value\n\n const base = Number.parseFloat(calc[1])\n const multiplier = Number.parseFloat(calc[3])\n const unit = calc.at(2) ?? 'px'\n if (!Number.isFinite(base) || !Number.isFinite(multiplier)) return value\n return `${unit === 'rem' ? base * multiplier * 16 : base * multiplier}px`\n}\n\nconst BORDER_STYLES = new Set([\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset'\n])\n\n/**\n * Shorthands as the longhands they set, in declaration order, so a later declaration wins over\n * an earlier one whether it is a shorthand, a logical side, or a single side, as in CSS.\n */\nfunction expandStyleShorthands(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const [property, value] of Object.entries(style)) {\n result[property] = value\n Object.assign(result, longhandsOf(property, value))\n }\n return result\n}\n\nfunction longhandsOf(property: string, value: string): DesignStyleDeclaration {\n if (property === 'margin' || property === 'padding') return boxSides(property, value)\n const logical = /^(margin|padding)-(inline|block)$/u.exec(property)\n if (logical) return logicalSides(property, value, logical[2] === 'inline')\n if (property === 'border') return borderLonghands(value)\n if (property === 'background') {\n const color = splitCSSValue(value).find(isColor)\n return color ? { 'background-color': color } : {}\n }\n return {}\n}\n\nfunction boxSides(property: string, value: string): DesignStyleDeclaration {\n const [top, right = top, bottom = top, left = right] = splitCSSValue(value)\n if (!top || !right || !bottom || !left) return {}\n return {\n [`${property}-top`]: top,\n [`${property}-right`]: right,\n [`${property}-bottom`]: bottom,\n [`${property}-left`]: left\n }\n}\n\n/** `padding-inline` and `padding-block` as the sides they set in left-to-right, horizontal text. */\nfunction logicalSides(property: string, value: string, inline: boolean): DesignStyleDeclaration {\n const box = property.slice(0, property.lastIndexOf('-'))\n const [first, second = first] = splitCSSValue(value)\n if (!first || !second) return {}\n const [start, end] = inline ? ['left', 'right'] : ['top', 'bottom']\n return { [`${box}-${start}`]: first, [`${box}-${end}`]: second }\n}\n\nfunction borderLonghands(value: string): DesignStyleDeclaration {\n const parts = splitCSSValue(value)\n const longhands: DesignStyleDeclaration = {}\n const color = parts.find(isColor)\n const width = parts.find((part) => parseCSSNumber(part) !== null)\n const style = parts.find((part) => BORDER_STYLES.has(part.toLowerCase()))\n if (color) longhands['border-color'] = color\n if (width) longhands['border-width'] = width\n if (style) longhands['border-style'] = style.toLowerCase()\n return longhands\n}\n\n/** Any CSS color, including `transparent`, which a shorthand may set on purpose. */\nfunction isColor(value: string): boolean {\n return tryParseColor(value) !== null\n}\n\nfunction classList(element: DesignElement): Set<string> {\n const className = 'class' in element.attrs ? element.attrs.class : ''\n return new Set(className.split(/\\s+/).filter((name) => name.length > 0))\n}\n\nfunction elementId(element: DesignElement): string | undefined {\n return 'id' in element.attrs ? element.attrs.id : undefined\n}\n\nfunction selectorSpecificity(selector: string): number {\n const idCount = selector.match(/#[\\w-]+/g)?.length ?? 0\n const classCount = selector.match(/\\.[\\w-]+/g)?.length ?? 0\n // A tag counts once per compound; the universal selector, alone or as in `*.card`, counts zero.\n const tagCount = selector.split(/[\\s>]+/).filter((part) => /^[a-z]/iu.test(part)).length\n return idCount * 100 + classCount * 10 + tagCount\n}\n\nfunction matchesSimpleSelector(element: DesignElement, selector: string): boolean {\n if (selector.includes(':') || selector.includes('[')) return false\n\n const idMatch = selector.match(/#([\\w-]+)/)\n if (idMatch?.[1] && elementId(element) !== idMatch[1]) return false\n\n const classes = selector.match(/\\.[\\w-]+/g) ?? []\n const elementClasses = classList(element)\n if (!classes.every((name) => elementClasses.has(name.slice(1)))) return false\n\n const tag = selector.replace(/#[\\w-]+/g, '').replace(/\\.[\\w-]+/g, '')\n // The universal selector, as Tailwind's preflight uses for `box-sizing`, matches any element.\n return tag.length === 0 || tag === '*' || element.tagName.toLowerCase() === tag.toLowerCase()\n}\n\nfunction matchesSelector(\n element: DesignElement,\n selector: string,\n parent: AncestorContext | null\n): boolean {\n const childParts = selector.split('>').map((part) => part.trim())\n if (childParts.length > 1) return matchesChildSelector(element, childParts, parent)\n\n const descendantParts = selector.split(/\\s+/).filter((part) => part.length > 0)\n if (descendantParts.length > 1) return matchesDescendantSelector(element, descendantParts, parent)\n\n return matchesSimpleSelector(element, selector)\n}\n\nfunction matchesSelectorParts(\n element: DesignElement,\n parts: string[],\n parent: AncestorContext | null,\n directParentOnly: boolean\n): boolean {\n const current = parts.at(-1)\n if (!current || !matchesSimpleSelector(element, current)) return false\n\n let ancestor = parent\n for (const selector of parts.slice(0, -1).reverse()) {\n if (!directParentOnly) {\n while (ancestor && !matchesSimpleSelector(ancestor.element, selector)) {\n ancestor = ancestor.parent\n }\n }\n if (!ancestor || !matchesSimpleSelector(ancestor.element, selector)) return false\n ancestor = ancestor.parent\n }\n return true\n}\n\nfunction matchesChildSelector(\n element: DesignElement,\n parts: string[],\n parent: AncestorContext | null\n): boolean {\n return matchesSelectorParts(element, parts, parent, true)\n}\n\nfunction matchesDescendantSelector(\n element: DesignElement,\n parts: string[],\n parent: AncestorContext | null\n): boolean {\n return matchesSelectorParts(element, parts, parent, false)\n}\n\nfunction applyComputedStyles(\n node: DesignNode,\n rules: HeadlessCSSRule[],\n parent: AncestorContext | null,\n inheritedStyle: DesignStyleDeclaration\n): DesignNode {\n if (node.type === 'text') return node\n\n const computedStyle: DesignStyleDeclaration = pickInheritedStyle(inheritedStyle)\n const matchingRules = rules\n .filter((rule) => matchesSelector(node, rule.selector, parent))\n .sort((left, right) => left.specificity - right.specificity || left.order - right.order)\n\n for (const rule of matchingRules) Object.assign(computedStyle, rule.style)\n Object.assign(computedStyle, expandStyleShorthands(node.inlineStyle ?? {}))\n\n const context = { element: node, parent }\n return {\n ...node,\n computedStyle: Object.keys(computedStyle).length > 0 ? computedStyle : undefined,\n children: node.children.map((child) =>\n applyComputedStyles(child, rules, context, computedStyle)\n )\n }\n}\n\nfunction pickInheritedStyle(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const inherited: DesignStyleDeclaration = {}\n for (const property of INHERITED_PROPERTIES) {\n const value = style[property]\n if (value) inherited[property] = value\n }\n return inherited\n}\n\nexport function computeHeadlessStyles(document: DesignDocument, cssText = ''): DesignDocument {\n const stylesheetText = [document.stylesheets?.map((sheet) => sheet.cssText).join('\\n'), cssText]\n .filter((text): text is string => !!text)\n .join('\\n')\n const { rules } = parseRules(stylesheetText)\n\n return {\n ...document,\n children: document.children.map((child) => applyComputedStyles(child, rules, null, {}))\n }\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport { INLINE_TAGS } from '#dom-css/import/flow'\nimport { parseStyleAttribute } from '#dom-css/import/style-attribute'\nimport type { CSSRuntime, DesignDocument, DesignElement, DesignNode } from '#dom-css/types'\nimport { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport { computeHeadlessStyles } from './styles'\n\nfunction attrsToRecord(attrs: DefaultTreeAdapterTypes.Element['attrs']): Record<string, string> {\n const result: Record<string, string> = {}\n for (const attr of attrs) result[attr.name] = attr.value\n return result\n}\n\nfunction isTextNode(\n node: DefaultTreeAdapterTypes.ChildNode\n): node is DefaultTreeAdapterTypes.TextNode {\n return node.nodeName === '#text'\n}\n\nconst NON_RENDERED_TAGS = new Set(['head', 'link', 'meta', 'script', 'style', 'template', 'title'])\n\nfunction isInlineElement(node: DefaultTreeAdapterTypes.ChildNode | undefined): boolean {\n return node !== undefined && 'tagName' in node && INLINE_TAGS.has(node.tagName.toLowerCase())\n}\n\n/**\n * Text, and the spaces in or beside inline elements, which CSS draws among their words; spaces\n * between blocks lay nothing out, so they are left out.\n */\nfunction keepsText(\n node: DefaultTreeAdapterTypes.TextNode,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n index: number,\n inInline: boolean\n): boolean {\n if (node.value.trim().length > 0) return true\n return (\n node.value.length > 0 &&\n (inInline || isInlineElement(siblings[index - 1]) || isInlineElement(siblings[index + 1]))\n )\n}\n\nfunction childrenToDesignNodes(\n nodes: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode[] {\n return nodes\n .map((node, index) => childToDesignNode(node, index, nodes, inInline))\n .filter((child): child is DesignNode => child !== null)\n}\n\nfunction childToDesignNode(\n node: DefaultTreeAdapterTypes.ChildNode,\n index: number,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode | null {\n if (isTextNode(node)) {\n return keepsText(node, siblings, index, inInline) ? { type: 'text', text: node.value } : null\n }\n\n if (!('tagName' in node)) return null\n if (NON_RENDERED_TAGS.has(node.tagName.toLowerCase())) return null\n\n const attrs = attrsToRecord(node.attrs)\n const element: DesignElement = {\n type: 'element',\n tagName: node.tagName.toLowerCase(),\n attrs,\n children: childrenToDesignNodes(node.childNodes, isInlineElement(node))\n }\n\n const inlineStyle = parseStyleAttribute(attrs.style)\n if (inlineStyle) element.inlineStyle = inlineStyle\n\n return element\n}\n\nfunction parseHTML(html: string): DesignDocument {\n const fragment = parseFragment(html)\n return {\n type: 'document',\n children: childrenToDesignNodes(fragment.childNodes, false)\n }\n}\n\nexport function createHeadlessCSSRuntime(): CSSRuntime {\n return {\n kind: 'headless',\n parseHTML,\n serializeHTML(document: DesignDocument) {\n return serializeHTML(document)\n },\n async computeStyles(document: DesignDocument, cssText = '') {\n return computeHeadlessStyles(document, cssText)\n }\n }\n}\n","import type { CSSRuntime } from '../types'\nimport { createBrowserCSSRuntime } from './browser/runtime'\nimport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport { createBrowserCSSRuntime } from './browser/runtime'\nexport type { BrowserCSSRuntimeOptions } from './browser/runtime'\nexport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport function createCSSRuntime(): CSSRuntime {\n return typeof document !== 'undefined' ? createBrowserCSSRuntime() : createHeadlessCSSRuntime()\n}\n","import { compile } from 'tailwindcss'\n\nexport interface CompileTailwindCSSOptions {\n css?: string\n base?: string\n loadStylesheet?: (id: string, base: string) => Promise<string>\n}\n\nconst DEFAULT_TAILWIND_CSS = '@import \"tailwindcss\";'\n\nexport async function compileTailwindCSS(\n classes: string | Iterable<string>,\n options: CompileTailwindCSSOptions = {}\n): Promise<string> {\n const compiler = await compile(tailwindCompilerCSS(options.css), {\n base: options.base,\n loadStylesheet: async (id, base) => {\n const content = options.loadStylesheet\n ? await options.loadStylesheet(id, base)\n : await loadTailwindStylesheet(id)\n return { path: id, base, content }\n }\n })\n return compiler.build(normalizeClasses(classes))\n}\n\nfunction tailwindCompilerCSS(css: string | undefined): string {\n const trimmed = css?.trim()\n if (!trimmed) return DEFAULT_TAILWIND_CSS\n if (containsTailwindImport(trimmed)) return trimmed\n return `${DEFAULT_TAILWIND_CSS}\\n${trimmed}`\n}\n\nfunction containsTailwindImport(css: string): boolean {\n const withoutComments = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n return /^\\s*@import\\s+(?:\"tailwindcss(?:\\/[^\"]*)?\"|'tailwindcss(?:\\/[^']*)?')/m.test(\n withoutComments\n )\n}\n\nfunction normalizeClasses(classes: string | Iterable<string>): string[] {\n const classNames = typeof classes === 'string' ? [classes] : Array.from(classes)\n return classNames\n .flatMap((className) => className.split(/\\s+/))\n .map((className) => className.trim())\n .filter((className) => className.length > 0)\n}\n\nasync function loadTailwindStylesheet(id: string): Promise<string> {\n const stylesheet = id === 'tailwindcss' ? 'tailwindcss/index.css' : id\n const url = new URL(import.meta.resolve(stylesheet))\n const { readFile } = await import(/* @vite-ignore */ 'node:fs/promises')\n return readFile(url, 'utf8')\n}\n","import { parse, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { createCSSRuntime } from '../runtime'\nimport type { CSSComputeOptions, CSSRuntime, DesignDocument } from '../types'\nimport { mergeCSSText } from './css-text'\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from './scene-graph'\nimport { compileTailwindCSS, type CompileTailwindCSSOptions } from './tailwind'\n\nexport interface HTMLToDesignDocumentOptions {\n cssText?: string\n runtime?: CSSRuntime\n compute?: CSSComputeOptions\n}\n\nexport interface HTMLToSceneGraphOptions extends HTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface TailwindHTMLToDesignDocumentOptions\n extends Omit<HTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface TailwindHTMLToSceneGraphOptions\n extends TailwindHTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nfunction runtimeForOptions(runtime: CSSRuntime | undefined) {\n return runtime ?? createCSSRuntime()\n}\n\nfunction getChildNodes(node: DefaultTreeAdapterTypes.Node): DefaultTreeAdapterTypes.ChildNode[] {\n return 'childNodes' in node ? node.childNodes : []\n}\n\nfunction textContent(node: DefaultTreeAdapterTypes.Node): string {\n if (node.nodeName === '#text' && 'value' in node) return node.value\n return getChildNodes(node).map(textContent).join('')\n}\n\nfunction collectStyleText(node: DefaultTreeAdapterTypes.Node, styles: string[]): void {\n if ('tagName' in node && node.tagName.toLowerCase() === 'style') {\n const css = textContent(node).trim()\n if (css) styles.push(css)\n return\n }\n\n for (const child of getChildNodes(node)) collectStyleText(child, styles)\n}\n\nfunction extractEmbeddedCSSText(html: string): string | undefined {\n const styles: string[] = []\n collectStyleText(parse(html), styles)\n return styles.length > 0 ? styles.join('\\n') : undefined\n}\n\nexport async function htmlToDesignDocument(\n html: string,\n options: HTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const runtime = runtimeForOptions(options.runtime)\n const document = runtime.parseHTML(html)\n const cssText = mergeCSSText(extractEmbeddedCSSText(html), options.cssText)\n return runtime.computeStyles(document, cssText, options.compute)\n}\n\nexport async function htmlToSceneGraph(\n html: string,\n options: HTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await htmlToDesignDocument(html, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function tailwindHTMLToDesignDocument(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileTailwindCSS(candidates, options)\n return htmlToDesignDocument(html, { ...options, cssText })\n}\n\nexport async function tailwindHTMLToSceneGraph(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await tailwindHTMLToDesignDocument(html, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n"],"mappings":";;;;;;;;;AAKA,SAAS,eAAe,SAA0C;CAChE,MAAM,CAAC,QAAQA,QAAM,OAAO,CAAC,CAAC;CAC9B,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO;CACpE,OAAO;AACT;AAEA,SAAgB,oBAAoB,OAA+D;CACjG,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,OAAO,eAAe,KAAK,MAAM,EAAE;CACzC,IAAI,CAAC,MAAM,OAAO,KAAA;CAElB,MAAM,QAAgC,CAAC;CACvC,KAAK,MAAM,YAAY,MAAM,KAAK,KAAK,KAAK,GAAG;EAC7C,MAAM,gBAAgB,KAAK,MAAM,iBAAiB,QAAQ;EAC1D,IAAI,eAAe,MAAM,YAAY;CACvC;CAEA,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,QAAQ,KAAA;AACjD;;;ACSA,MAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,cACP,OACA,m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
|
1
|
+
import { designDocumentToSceneGraph, jsx, jsxToDesignDocumentCore } from "../../browser.js";
|
|
2
|
+
import { compileTailwindCSS } from "../html.js";
|
|
3
|
+
//#region src/import/jsx/runtime.ts
|
|
4
|
+
async function runtimeForOptions(runtime) {
|
|
5
|
+
if (runtime) return runtime;
|
|
6
|
+
const { createCSSRuntime } = await import("../html.js").then((n) => n.runtime_exports);
|
|
7
|
+
return createCSSRuntime();
|
|
8
|
+
}
|
|
9
|
+
async function jsxToDesignDocument(input, options = {}) {
|
|
10
|
+
const document = jsxToDesignDocumentCore(input);
|
|
11
|
+
if (!options.cssText && !options.runtime && !options.compute) return document;
|
|
12
|
+
return (await runtimeForOptions(options.runtime)).computeStyles(document, options.cssText, options.compute);
|
|
13
|
+
}
|
|
14
|
+
async function jsxToSceneGraph(input, options = {}) {
|
|
15
|
+
const document = await jsxToDesignDocument(input, options);
|
|
16
|
+
return designDocumentToSceneGraph(document, options);
|
|
17
|
+
}
|
|
18
|
+
async function tailwindJSXToDesignDocument(input, candidates, options = {}) {
|
|
19
|
+
const cssText = await compileTailwindCSS(candidates, options);
|
|
20
|
+
return jsxToDesignDocument(input, {
|
|
21
|
+
...options,
|
|
22
|
+
cssText
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function tailwindJSXToSceneGraph(input, candidates, options = {}) {
|
|
26
|
+
const document = await tailwindJSXToDesignDocument(input, candidates, options);
|
|
27
|
+
return designDocumentToSceneGraph(document, options);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/import/jsx/dev-runtime.ts
|
|
31
|
+
function jsxDEV(tag, props = {}) {
|
|
32
|
+
return jsx(tag, props);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { jsxDEV, jsxToDesignDocument, jsxToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=dev-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-runtime.js","names":[],"sources":["../../../../src/import/jsx/runtime.ts","../../../../src/import/jsx/dev-runtime.ts"],"sourcesContent":["import type { CSSComputeOptions, CSSRuntime, DesignDocument } from '#dom-css/types'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from '../scene-graph'\nimport { compileTailwindCSS, type CompileTailwindCSSOptions } from '../tailwind'\nimport { jsxToDesignDocumentCore, type JSXChild } from './core'\n\nexport { Fragment, jsx, jsxs } from './core'\nexport type {\n JSXChild,\n JSXElementProps,\n JSXStyleInput,\n JSXStyleObject,\n JSXStyleValue,\n JSXTag\n} from './core'\n\nexport interface JSXToDesignDocumentOptions {\n cssText?: string\n runtime?: CSSRuntime\n compute?: CSSComputeOptions\n}\n\nexport interface JSXToSceneGraphOptions extends JSXToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface TailwindJSXToDesignDocumentOptions\n extends Omit<JSXToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface TailwindJSXToSceneGraphOptions\n extends TailwindJSXToDesignDocumentOptions, ToSceneGraphOptions {}\n\nasync function runtimeForOptions(runtime: CSSRuntime | undefined) {\n if (runtime) return runtime\n const { createCSSRuntime } = await import('#dom-css/runtime')\n return createCSSRuntime()\n}\n\nexport async function jsxToDesignDocument(\n input: JSXChild,\n options: JSXToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const document = jsxToDesignDocumentCore(input)\n\n if (!options.cssText && !options.runtime && !options.compute) return document\n const runtime = await runtimeForOptions(options.runtime)\n return runtime.computeStyles(document, options.cssText, options.compute)\n}\n\nexport async function jsxToSceneGraph(\n input: JSXChild,\n options: JSXToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await jsxToDesignDocument(input, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function tailwindJSXToDesignDocument(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: TailwindJSXToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileTailwindCSS(candidates, options)\n return jsxToDesignDocument(input, { ...options, cssText })\n}\n\nexport async function tailwindJSXToSceneGraph(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: TailwindJSXToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await tailwindJSXToDesignDocument(input, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport type { JSX } from './core'\n","import { jsx, type JSXElementProps, type JSXTag } from './runtime'\n\nexport { Fragment } from './runtime'\nexport type * from './runtime'\n\nexport function jsxDEV(tag: JSXTag, props: JSXElementProps = {}) {\n return jsx(tag, props)\n}\n"],"mappings":";;;AAgCA,eAAe,kBAAkB,SAAiC;CAChE,IAAI,SAAS,OAAO;CACpB,MAAM,EAAE,qBAAqB,MAAM,OAAO,aAAmB,CAAA,MAAA,MAAA,EAAA,eAAA;CAC7D,OAAO,iBAAiB;AAC1B;AAEA,eAAsB,oBACpB,OACA,UAAsC,CAAC,GACd;CACzB,MAAM,WAAW,wBAAwB,KAAK;CAE9C,IAAI,CAAC,QAAQ,WAAW,CAAC,QAAQ,WAAW,CAAC,QAAQ,SAAS,OAAO;CAErE,QAAO,MADe,kBAAkB,QAAQ,OAAO,EAAA,CACxC,cAAc,UAAU,QAAQ,SAAS,QAAQ,OAAO;AACzE;AAEA,eAAsB,gBACpB,OACA,UAAkC,CAAC,GACd;CACrB,MAAM,WAAW,MAAM,oBAAoB,OAAO,OAAO;CACzD,OAAO,2BAA2B,UAAU,OAAO;AACrD;AAEA,eAAsB,4BACpB,OACA,YACA,UAA8C,CAAC,GACtB;CACzB,MAAM,UAAU,MAAM,mBAAmB,YAAY,OAAO;CAC5D,OAAO,oBAAoB,OAAO;EAAE,GAAG;EAAS;CAAQ,CAAC;AAC3D;AAEA,eAAsB,wBACpB,OACA,YACA,UAA0C,CAAC,GACtB;CACrB,MAAM,WAAW,MAAM,4BAA4B,OAAO,YAAY,OAAO;CAC7E,OAAO,2BAA2B,UAAU,OAAO;AACrD;;;ACpEA,SAAgB,OAAO,KAAa,QAAyB,CAAC,GAAG;CAC/D,OAAO,IAAI,KAAK,KAAK;AACvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { __exportAll } from "../../rolldown-runtime.js";
|
|
2
|
+
import { createTokenValidator } from "../behaviours/states/layers.js";
|
|
3
|
+
import * as cssom from "@acemir/cssom";
|
|
4
|
+
//#region src/tokens/cssom-validator.ts
|
|
5
|
+
var cssom_validator_exports = /* @__PURE__ */ __exportAll({ tokenValidator: () => tokenValidator });
|
|
6
|
+
const tokenValidator = createTokenValidator((cssText) => cssom.parse(cssText));
|
|
7
|
+
//#endregion
|
|
8
|
+
export { cssom_validator_exports };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=cssom-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssom-validator.js","names":[],"sources":["../../../src/tokens/cssom-validator.ts"],"sourcesContent":["// Headless only: `./stylesheet` loads this module lazily where the browser's parser is missing.\n// A namespace import, read at call time: browser builds resolve the package to a script that\n// exports nothing, and a named import would fail those builds even though this never runs there.\nimport * as cssom from '@acemir/cssom'\n\nimport { createTokenValidator } from './validate'\n\nexport const tokenValidator = createTokenValidator((cssText) => cssom.parse(cssText))\n"],"mappings":";;;;;AAOA,MAAa,iBAAiB,sBAAsB,YAAY,MAAM,MAAM,OAAO,CAAC"}
|