@pairdraw/dom-css 0.21.1 → 0.22.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/dist/chunks/behaviours/states/layers.js +78 -12
- package/dist/chunks/behaviours/states/layers.js.map +1 -1
- package/dist/chunks/browser.js +373 -37
- package/dist/chunks/browser.js.map +1 -1
- package/dist/chunks/import/html.js +66 -11
- package/dist/chunks/import/html.js.map +1 -1
- package/dist/chunks/import/jsx/source/ast.js +207 -0
- package/dist/chunks/import/jsx/source/ast.js.map +1 -0
- package/dist/chunks/import/jsx/source/candidates.js +74 -0
- package/dist/chunks/import/jsx/source/candidates.js.map +1 -0
- package/dist/chunks/import/jsx/source/evaluate.js +213 -0
- package/dist/chunks/import/jsx/source/evaluate.js.map +1 -0
- package/dist/chunks/import/jsx/source/index.js +448 -0
- package/dist/chunks/import/jsx/source/index.js.map +1 -0
- package/dist/export.d.ts +15 -2
- package/dist/export.js +2 -2
- package/dist/index.d.ts +66 -1
- package/dist/index.js +5 -2
- package/package.json +5 -3
- package/src/cssom/browser.ts +63 -0
- package/src/export/css.ts +28 -1
- package/src/export/index.ts +1 -0
- package/src/export/projection.ts +69 -10
- package/src/import/flow.ts +127 -6
- package/src/import/jsx/source/ast.ts +267 -0
- package/src/import/jsx/source/candidates.ts +72 -0
- package/src/import/jsx/source/evaluate.ts +300 -0
- package/src/import/jsx/source/index.ts +36 -0
- package/src/import/jsx/source/render.ts +543 -0
- package/src/import/jsx/source/report.ts +49 -0
- package/src/import/scene-graph.ts +19 -7
- package/src/index.ts +10 -0
- package/src/runtime/browser/runtime.ts +13 -5
- package/src/runtime/browser/sandbox.ts +176 -27
- package/src/runtime/css/scan.ts +45 -0
- package/src/runtime/css/url.ts +92 -0
- package/src/runtime/headless/styles.ts +71 -15
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { CodeSourceError, CodeTooLargeError, MAX_CODE_ELEMENTS, UNKNOWN, calleeName, declarationOf, drawsElements, emptyReport, expressionText, functionNode, isElementCall, isLiteralFunction, memberName, parseSource, pascalCase, propertyKey } from "./ast.js";
|
|
2
|
+
import { CLASS_HELPERS, bindParams, evaluate, mergeClasses, truthy } from "./evaluate.js";
|
|
3
|
+
//#region src/import/jsx/source/render.ts
|
|
4
|
+
/** Attributes a layer has a place for; the rest of an element's props are counted as dropped. */
|
|
5
|
+
const KEPT_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
6
|
+
"id",
|
|
7
|
+
"href",
|
|
8
|
+
"src",
|
|
9
|
+
"alt",
|
|
10
|
+
"srcset",
|
|
11
|
+
"title",
|
|
12
|
+
"type",
|
|
13
|
+
"value",
|
|
14
|
+
"placeholder",
|
|
15
|
+
"name",
|
|
16
|
+
"role",
|
|
17
|
+
"for",
|
|
18
|
+
"lang",
|
|
19
|
+
"rows",
|
|
20
|
+
"cols"
|
|
21
|
+
]);
|
|
22
|
+
const MAX_EXPANDED_ITEMS = 100;
|
|
23
|
+
const MAX_COMPONENT_DEPTH = 16;
|
|
24
|
+
/** The trees the paste stands for: its default export, its last exported component, or all of them. */
|
|
25
|
+
function renderRoots(program, env, state) {
|
|
26
|
+
const defaultExport = program.body.find((statement) => statement.type === "ExportDefaultDeclaration");
|
|
27
|
+
if (defaultExport) return renderExported(defaultExport.declaration, env, state);
|
|
28
|
+
const lastExport = program.body.filter((statement) => statement.type === "ExportNamedDeclaration" && statement.declaration !== null).at(-1);
|
|
29
|
+
if (lastExport) {
|
|
30
|
+
const declaration = lastExport.declaration;
|
|
31
|
+
if (declaration) {
|
|
32
|
+
const rendered = renderExported(declaration, env, state);
|
|
33
|
+
if (rendered.length > 0) return rendered;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const lastExpression = program.body.filter((statement) => statement.type === "ExpressionStatement" && isElementCall(statement.expression)).at(-1);
|
|
37
|
+
if (lastExpression) return renderExpression(lastExpression.expression, env, state);
|
|
38
|
+
const rendered = [];
|
|
39
|
+
for (const component of state.components.values()) {
|
|
40
|
+
if (rendered.length >= MAX_EXPANDED_ITEMS) break;
|
|
41
|
+
rendered.push(...nameAfterComponent(component.name, renderFunction(component, [], state)));
|
|
42
|
+
}
|
|
43
|
+
return rendered;
|
|
44
|
+
}
|
|
45
|
+
/** Every top-level function that builds an element, so a component the source defines expands. */
|
|
46
|
+
function collectComponents(program, env) {
|
|
47
|
+
const components = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const statement of program.body) {
|
|
49
|
+
const target = declarationOf(statement);
|
|
50
|
+
if (target?.type === "FunctionDeclaration") {
|
|
51
|
+
addFunction(components, target, env);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (target?.type !== "VariableDeclaration") continue;
|
|
55
|
+
for (const declarator of target.declarations) {
|
|
56
|
+
if (declarator.id.type !== "Identifier") continue;
|
|
57
|
+
const init = declarator.init;
|
|
58
|
+
if (!init) continue;
|
|
59
|
+
const fn = functionNode(init);
|
|
60
|
+
if (!fn) continue;
|
|
61
|
+
addNamedFunction(components, declarator.id.name, fn, env);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return components;
|
|
65
|
+
}
|
|
66
|
+
function addFunction(components, node, env) {
|
|
67
|
+
const id = node.id;
|
|
68
|
+
if (id) addNamedFunction(components, id.name, node, env);
|
|
69
|
+
}
|
|
70
|
+
function addNamedFunction(components, name, node, env) {
|
|
71
|
+
if (!drawsElements(node)) return;
|
|
72
|
+
components.set(name, {
|
|
73
|
+
kind: "function",
|
|
74
|
+
node,
|
|
75
|
+
env,
|
|
76
|
+
name
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Module-scope `const` values, read as literals; anything else stays unknown. */
|
|
80
|
+
function collectBindings(statement, env) {
|
|
81
|
+
if (statement.type !== "VariableDeclaration") return;
|
|
82
|
+
for (const declarator of statement.declarations) {
|
|
83
|
+
if (declarator.id.type !== "Identifier") continue;
|
|
84
|
+
const init = declarator.init;
|
|
85
|
+
if (!init) continue;
|
|
86
|
+
const name = declarator.id.name;
|
|
87
|
+
const callable = functionNode(init);
|
|
88
|
+
if (callable) {
|
|
89
|
+
env.set(name, {
|
|
90
|
+
kind: "function",
|
|
91
|
+
node: callable,
|
|
92
|
+
env,
|
|
93
|
+
name
|
|
94
|
+
});
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const value = evaluate(init, env);
|
|
98
|
+
if (value !== null) env.set(name, value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function renderExported(declaration, env, state) {
|
|
102
|
+
if (!drawsElements(declaration)) return [];
|
|
103
|
+
const component = functionNode(declaration);
|
|
104
|
+
if (component) {
|
|
105
|
+
const name = (component.type === "FunctionDeclaration" ? component.id : null)?.name ?? "";
|
|
106
|
+
return renderFunction((name ? state.components.get(name) : void 0) ?? {
|
|
107
|
+
kind: "function",
|
|
108
|
+
node: component,
|
|
109
|
+
env,
|
|
110
|
+
name
|
|
111
|
+
}, [], state);
|
|
112
|
+
}
|
|
113
|
+
const value = evaluate(declaration, env);
|
|
114
|
+
if (isLiteralFunction(value)) return renderFunction(value, [], state);
|
|
115
|
+
return renderExpression(declaration, env, state);
|
|
116
|
+
}
|
|
117
|
+
/** A component's rendered tree, with its parameters bound to the values a call passes. */
|
|
118
|
+
function renderFunction(component, args, state) {
|
|
119
|
+
if (state.depth >= MAX_COMPONENT_DEPTH) {
|
|
120
|
+
state.report.approximations += 1;
|
|
121
|
+
return [{
|
|
122
|
+
type: "text",
|
|
123
|
+
text: `{${component.name ?? "component"}}`
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
const env = new Map(component.env);
|
|
127
|
+
bindParams(component.node, args, env);
|
|
128
|
+
const depth = state.depth;
|
|
129
|
+
state.depth = depth + 1;
|
|
130
|
+
try {
|
|
131
|
+
return renderBody(component.node, env, state);
|
|
132
|
+
} finally {
|
|
133
|
+
state.depth = depth;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function renderBody(node, env, state) {
|
|
137
|
+
if (node.body.type !== "BlockStatement") return renderExpression(node.body, env, state);
|
|
138
|
+
return runStatements(node.body.body, env, state) ?? [];
|
|
139
|
+
}
|
|
140
|
+
/** The tree a block's statements end with, reading only what JavaScript would collect. */
|
|
141
|
+
function runStatements(statements, env, state) {
|
|
142
|
+
for (const statement of statements) {
|
|
143
|
+
if (statement.type === "VariableDeclaration") {
|
|
144
|
+
collectBindings(statement, env);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (statement.type === "ReturnStatement") {
|
|
148
|
+
const argument = statement.argument;
|
|
149
|
+
return argument ? renderExpression(argument, env, state) : [];
|
|
150
|
+
}
|
|
151
|
+
if (statement.type !== "IfStatement") continue;
|
|
152
|
+
const nested = renderBranch(statement, env, state);
|
|
153
|
+
if (nested) return nested;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
function renderBranch(statement, env, state) {
|
|
158
|
+
const test = evaluate(statement.test, env);
|
|
159
|
+
if (test === null) {
|
|
160
|
+
state.report.approximations += 1;
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const branch = truthy(test) ? statement.consequent : statement.alternate;
|
|
164
|
+
if (!branch) return null;
|
|
165
|
+
return branch.type === "BlockStatement" ? runStatements(branch.body, env, state) : runStatements([branch], env, state);
|
|
166
|
+
}
|
|
167
|
+
/** The nodes an expression draws: elements, an array of them, or text. */
|
|
168
|
+
function renderExpression(node, env, state) {
|
|
169
|
+
if (isElementCall(node)) return renderElement(node, env, state);
|
|
170
|
+
const drawn = renderComposite(node, env, state);
|
|
171
|
+
if (drawn) return drawn;
|
|
172
|
+
const value = evaluate(node, env);
|
|
173
|
+
return value === null ? placeholder(node, state) : literalNodes(value);
|
|
174
|
+
}
|
|
175
|
+
/** Expressions that stand for other expressions rather than for one value. */
|
|
176
|
+
function renderComposite(node, env, state) {
|
|
177
|
+
if (node.type === "ArrayExpression") return node.elements.flatMap((element) => element && element.type !== "SpreadElement" ? renderExpression(element, env, state) : []);
|
|
178
|
+
if (node.type === "ConditionalExpression") return renderChoice(node, env, state);
|
|
179
|
+
if (node.type === "LogicalExpression") return renderLogical(node, env, state);
|
|
180
|
+
if (node.type === "CallExpression") return renderMapped(node, env, state);
|
|
181
|
+
if (node.type !== "Identifier") return null;
|
|
182
|
+
const value = env.get(node.name);
|
|
183
|
+
if (value === void 0 || value === UNKNOWN) return placeholder(node, state);
|
|
184
|
+
return literalNodes(value);
|
|
185
|
+
}
|
|
186
|
+
function renderChoice(node, env, state) {
|
|
187
|
+
const test = evaluate(node.test, env);
|
|
188
|
+
if (test === null) state.report.approximations += 1;
|
|
189
|
+
return renderExpression(test === null || truthy(test) ? node.consequent : node.alternate, env, state);
|
|
190
|
+
}
|
|
191
|
+
function renderLogical(node, env, state) {
|
|
192
|
+
const left = evaluate(node.left, env);
|
|
193
|
+
if (node.operator === "&&") {
|
|
194
|
+
if (left === null) state.report.approximations += 1;
|
|
195
|
+
return truthy(left) ? renderExpression(node.right, env, state) : [];
|
|
196
|
+
}
|
|
197
|
+
return left !== null && truthy(left) ? renderExpression(node.left, env, state) : renderExpression(node.right, env, state);
|
|
198
|
+
}
|
|
199
|
+
/** `items.map((item) => <li>{item.label}</li>)` over a literal array, one element per item. */
|
|
200
|
+
function renderMapped(node, env, state) {
|
|
201
|
+
if (node.callee.type !== "MemberExpression") return null;
|
|
202
|
+
const member = node.callee;
|
|
203
|
+
if (!(!member.computed && member.property.type === "Identifier" && member.property.name === "map")) return null;
|
|
204
|
+
const items = evaluate(member.object, env);
|
|
205
|
+
if (!Array.isArray(items)) return null;
|
|
206
|
+
const callback = node.arguments.at(0);
|
|
207
|
+
if (!callback) return null;
|
|
208
|
+
const fn = functionNode(callback);
|
|
209
|
+
if (!fn) return null;
|
|
210
|
+
if (items.length > MAX_EXPANDED_ITEMS) state.report.approximations += 1;
|
|
211
|
+
const rendered = [];
|
|
212
|
+
for (const item of items.slice(0, MAX_EXPANDED_ITEMS)) {
|
|
213
|
+
const callbackEnv = new Map(env);
|
|
214
|
+
const first = fn.params.at(0);
|
|
215
|
+
if (first?.type === "Identifier") callbackEnv.set(first.name, item);
|
|
216
|
+
const nodes = fn.body.type === "BlockStatement" ? runStatements(fn.body.body, callbackEnv, state) ?? [] : renderExpression(fn.body, callbackEnv, state);
|
|
217
|
+
rendered.push(...nodes);
|
|
218
|
+
}
|
|
219
|
+
return rendered;
|
|
220
|
+
}
|
|
221
|
+
/** One `__h(tag, props, …children)` call as a layer. */
|
|
222
|
+
function renderElement(call, env, state) {
|
|
223
|
+
state.elements += 1;
|
|
224
|
+
if (state.elements > 2e3) throw new CodeTooLargeError(`The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`);
|
|
225
|
+
const tag = call.arguments.at(0);
|
|
226
|
+
const propsNode = call.arguments.at(1) ?? null;
|
|
227
|
+
const props = propsNode ? readProps(propsNode, env, state) : { attrs: {} };
|
|
228
|
+
const children = call.arguments.slice(2).flatMap((child) => child.type === "SpreadElement" ? [] : renderExpression(child, env, state));
|
|
229
|
+
if (!tag || tag.type === "SpreadElement") return children;
|
|
230
|
+
if (tag.type === "Identifier") {
|
|
231
|
+
const name = tag.name;
|
|
232
|
+
if (name === "__fragment") return children;
|
|
233
|
+
const component = state.components.get(name) ?? env.get(name);
|
|
234
|
+
if (isLiteralFunction(component)) {
|
|
235
|
+
const passed = propsNode ? evaluate(propsNode, env) : {};
|
|
236
|
+
return renderFunction(component, [passed !== null && typeof passed === "object" && !Array.isArray(passed) ? passed : null], state);
|
|
237
|
+
}
|
|
238
|
+
return [componentFrame(name, componentProps(props, state), children, state)];
|
|
239
|
+
}
|
|
240
|
+
const name = tag.type === "MemberExpression" ? memberName(tag) : void 0;
|
|
241
|
+
const value = name ? void 0 : evaluate(tag, env);
|
|
242
|
+
if (typeof value !== "string") return [componentFrame(name ?? expressionText(tag), componentProps(props, state), children, state)];
|
|
243
|
+
const element = elementNode(value, props, children);
|
|
244
|
+
if (value.toLowerCase() === "img") state.report.imagesAsPlaceholders += 1;
|
|
245
|
+
return [element];
|
|
246
|
+
}
|
|
247
|
+
function readProps(node, env, state) {
|
|
248
|
+
if (node.type !== "ObjectExpression") {
|
|
249
|
+
state.report.droppedProps += 1;
|
|
250
|
+
return { attrs: {} };
|
|
251
|
+
}
|
|
252
|
+
const props = { attrs: {} };
|
|
253
|
+
for (const property of node.properties) {
|
|
254
|
+
if (property.type === "SpreadElement") {
|
|
255
|
+
state.report.droppedProps += 1;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const name = propertyKey(property);
|
|
259
|
+
if (!name || name === "key" || name.startsWith("on")) continue;
|
|
260
|
+
readProperty(name, property.value, props, env, state);
|
|
261
|
+
}
|
|
262
|
+
return props;
|
|
263
|
+
}
|
|
264
|
+
function readProperty(name, value, props, env, state) {
|
|
265
|
+
if (name === "className" || name === "class") {
|
|
266
|
+
const classes = readClasses(value, env, state);
|
|
267
|
+
if (classes) props.class = classes;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (name === "style") {
|
|
271
|
+
const style = readStyle(value, env);
|
|
272
|
+
if (style) props.style = style;
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const kept = attributeValue(value, env);
|
|
276
|
+
if (kept !== null) {
|
|
277
|
+
if (isKeptAttribute(name)) props.attrs[name] = kept;
|
|
278
|
+
else state.report.droppedProps += 1;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (isKeptAttribute(name)) {
|
|
282
|
+
props.attrs[name] = `{${expressionText(value)}}`;
|
|
283
|
+
state.report.placeholders += 1;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
state.report.droppedProps += 1;
|
|
287
|
+
}
|
|
288
|
+
function isKeptAttribute(name) {
|
|
289
|
+
return name.startsWith("data-") || name.startsWith("aria-") || KEPT_ATTRIBUTES.has(name);
|
|
290
|
+
}
|
|
291
|
+
/** `cn("flex", cond && "gap-2")` read as one class list, leaving out arguments it cannot know. */
|
|
292
|
+
function readClasses(node, env, state) {
|
|
293
|
+
const value = evaluate(node, env);
|
|
294
|
+
const text = classesOf(value);
|
|
295
|
+
if (text !== void 0) return text;
|
|
296
|
+
if (node.type === "CallExpression" && CLASS_HELPERS.has(calleeName(node) ?? "")) return mergeClasses(node, env) || void 0;
|
|
297
|
+
if (node.type === "ConditionalExpression") return readClassChoice(node, env, state);
|
|
298
|
+
if (node.type === "LogicalExpression") return readClassLogical(node, env, state);
|
|
299
|
+
if (value === null) state.report.approximations += 1;
|
|
300
|
+
}
|
|
301
|
+
function classesOf(value) {
|
|
302
|
+
if (typeof value === "string") return value || void 0;
|
|
303
|
+
if (!Array.isArray(value)) return void 0;
|
|
304
|
+
const names = value.filter((entry) => typeof entry === "string");
|
|
305
|
+
return names.length > 0 ? names.join(" ") : void 0;
|
|
306
|
+
}
|
|
307
|
+
function readClassChoice(node, env, state) {
|
|
308
|
+
const test = evaluate(node.test, env);
|
|
309
|
+
if (test === null) state.report.approximations += 1;
|
|
310
|
+
return readClasses(test === null || truthy(test) ? node.consequent : node.alternate, env, state);
|
|
311
|
+
}
|
|
312
|
+
function readClassLogical(node, env, state) {
|
|
313
|
+
const left = evaluate(node.left, env);
|
|
314
|
+
if (node.operator === "&&") {
|
|
315
|
+
if (left === null) state.report.approximations += 1;
|
|
316
|
+
return truthy(left) ? readClasses(node.right, env, state) : void 0;
|
|
317
|
+
}
|
|
318
|
+
return readClasses(node.right, env, state);
|
|
319
|
+
}
|
|
320
|
+
function readStyle(node, env) {
|
|
321
|
+
const value = evaluate(node, env);
|
|
322
|
+
if (typeof value === "string") return styleFromText(value);
|
|
323
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || "kind" in value) return;
|
|
324
|
+
const declaration = {};
|
|
325
|
+
for (const [property, entry] of Object.entries(value)) {
|
|
326
|
+
if (typeof entry === "object") continue;
|
|
327
|
+
declaration[cssProperty(property)] = String(entry);
|
|
328
|
+
}
|
|
329
|
+
return Object.keys(declaration).length > 0 ? declaration : void 0;
|
|
330
|
+
}
|
|
331
|
+
function styleFromText(value) {
|
|
332
|
+
const declaration = {};
|
|
333
|
+
for (const part of value.split(";")) {
|
|
334
|
+
const colon = part.indexOf(":");
|
|
335
|
+
if (colon === -1) continue;
|
|
336
|
+
const property = cssProperty(part.slice(0, colon).trim());
|
|
337
|
+
const entry = part.slice(colon + 1).trim();
|
|
338
|
+
if (property && entry) declaration[property] = entry;
|
|
339
|
+
}
|
|
340
|
+
return Object.keys(declaration).length > 0 ? declaration : void 0;
|
|
341
|
+
}
|
|
342
|
+
function cssProperty(name) {
|
|
343
|
+
if (name.startsWith("--")) return name;
|
|
344
|
+
return name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
345
|
+
}
|
|
346
|
+
function attributeValue(node, env) {
|
|
347
|
+
const value = evaluate(node, env);
|
|
348
|
+
if (value === null || typeof value === "object") return null;
|
|
349
|
+
return String(value);
|
|
350
|
+
}
|
|
351
|
+
function elementNode(tag, props, children) {
|
|
352
|
+
const attrs = {
|
|
353
|
+
"data-name": pascalCase(tag),
|
|
354
|
+
...props.attrs
|
|
355
|
+
};
|
|
356
|
+
if (props.class) attrs.class = props.class;
|
|
357
|
+
return {
|
|
358
|
+
type: "element",
|
|
359
|
+
tagName: tag.toLowerCase(),
|
|
360
|
+
attrs,
|
|
361
|
+
inlineStyle: props.style,
|
|
362
|
+
children
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function componentFrame(name, props, children, state) {
|
|
366
|
+
state.report.componentsAsFrames += 1;
|
|
367
|
+
const attrs = {
|
|
368
|
+
"data-name": name,
|
|
369
|
+
...props.attrs
|
|
370
|
+
};
|
|
371
|
+
if (props.class) attrs.class = props.class;
|
|
372
|
+
return {
|
|
373
|
+
type: "element",
|
|
374
|
+
tagName: "div",
|
|
375
|
+
attrs,
|
|
376
|
+
inlineStyle: props.style,
|
|
377
|
+
children
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/** A component's props an element would hold have no place on a frame; only classes carry over. */
|
|
381
|
+
function componentProps(props, state) {
|
|
382
|
+
state.report.droppedProps += Object.keys(props.attrs).length;
|
|
383
|
+
return {
|
|
384
|
+
class: props.class,
|
|
385
|
+
style: props.style,
|
|
386
|
+
attrs: {}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/** A component's rendered roots take its name, so the layer tree says which component drew them. */
|
|
390
|
+
function nameAfterComponent(name, nodes) {
|
|
391
|
+
if (!name) return nodes;
|
|
392
|
+
const first = nodes.at(0);
|
|
393
|
+
if (first?.type !== "element") return nodes;
|
|
394
|
+
const rest = nodes.slice(1);
|
|
395
|
+
return [{
|
|
396
|
+
...first,
|
|
397
|
+
attrs: {
|
|
398
|
+
...first.attrs,
|
|
399
|
+
"data-name": name
|
|
400
|
+
}
|
|
401
|
+
}, ...rest];
|
|
402
|
+
}
|
|
403
|
+
function placeholder(node, state) {
|
|
404
|
+
state.report.placeholders += 1;
|
|
405
|
+
return [{
|
|
406
|
+
type: "text",
|
|
407
|
+
text: `{${expressionText(node)}}`
|
|
408
|
+
}];
|
|
409
|
+
}
|
|
410
|
+
function literalNodes(value) {
|
|
411
|
+
if (typeof value === "string") return value.trim() ? [{
|
|
412
|
+
type: "text",
|
|
413
|
+
text: value
|
|
414
|
+
}] : [];
|
|
415
|
+
if (typeof value === "number" || typeof value === "boolean") return [{
|
|
416
|
+
type: "text",
|
|
417
|
+
text: String(value)
|
|
418
|
+
}];
|
|
419
|
+
return [];
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/import/jsx/source/index.ts
|
|
423
|
+
/**
|
|
424
|
+
* The element tree a pasted JSX or TSX source describes, and what it could not keep. Parsing and
|
|
425
|
+
* reading only: nothing in the source runs, and a construct the reader cannot classify becomes a
|
|
426
|
+
* placeholder rather than an error.
|
|
427
|
+
*/
|
|
428
|
+
function jsxSourceToTree(source) {
|
|
429
|
+
const program = parseSource(source);
|
|
430
|
+
const report = emptyReport();
|
|
431
|
+
const moduleEnv = /* @__PURE__ */ new Map();
|
|
432
|
+
for (const statement of program.body) collectBindings(statement, moduleEnv);
|
|
433
|
+
const roots = renderRoots(program, moduleEnv, {
|
|
434
|
+
report,
|
|
435
|
+
components: collectComponents(program, moduleEnv),
|
|
436
|
+
depth: 0,
|
|
437
|
+
elements: 0
|
|
438
|
+
});
|
|
439
|
+
if (roots.length === 0) throw new CodeSourceError("No JSX element found: paste a React or JSX component, or HTML markup.");
|
|
440
|
+
return {
|
|
441
|
+
children: roots,
|
|
442
|
+
report
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
export { jsxSourceToTree };
|
|
447
|
+
|
|
448
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/import/jsx/source/render.ts","../../../../../src/import/jsx/source/index.ts"],"sourcesContent":["import type { DesignNode, DesignStyleDeclaration } from '#dom-css/types'\nimport type {\n ArrayExpression,\n CallExpression,\n ConditionalExpression,\n ExportNamedDeclaration,\n ExpressionStatement,\n FunctionDeclaration,\n IfStatement,\n Identifier,\n LogicalExpression,\n ModuleDeclaration,\n Node,\n ObjectExpression,\n Program,\n Statement,\n VariableDeclaration\n} from 'acorn'\n\nimport {\n calleeName,\n declarationOf,\n drawsElements,\n isLiteralFunction,\n expressionText,\n functionNode,\n isElementCall,\n memberName,\n pascalCase,\n propertyKey,\n UNKNOWN,\n type Env,\n type LiteralFunction,\n type LiteralValue\n} from './ast'\nimport { CLASS_HELPERS, bindParams, evaluate, mergeClasses, truthy } from './evaluate'\nimport { CodeTooLargeError, MAX_CODE_ELEMENTS, type CodeReport } from './report'\n\n/** Attributes a layer has a place for; the rest of an element's props are counted as dropped. */\nconst KEPT_ATTRIBUTES = new Set([\n 'id',\n 'href',\n 'src',\n 'alt',\n 'srcset',\n 'title',\n 'type',\n 'value',\n 'placeholder',\n 'name',\n 'role',\n 'for',\n 'lang',\n 'rows',\n 'cols'\n])\n\n/** A declaration's name. Acorn types it as required; a pasted `export default function () {}` has none. */\ninterface IdHolder extends Node {\n id?: Identifier | null\n}\n\nconst MAX_EXPANDED_ITEMS = 100\nconst MAX_COMPONENT_DEPTH = 16\n\nexport interface RenderState {\n report: CodeReport\n /** Top-level functions of the pasted module, by name. */\n components: Map<string, LiteralFunction>\n depth: number\n /** Elements drawn so far, bounded by `MAX_CODE_ELEMENTS`. */\n elements: number\n}\n\n/** The trees the paste stands for: its default export, its last exported component, or all of them. */\nexport function renderRoots(program: Program, env: Env, state: RenderState): DesignNode[] {\n const defaultExport = program.body.find(\n (statement) => statement.type === 'ExportDefaultDeclaration'\n )\n if (defaultExport) return renderExported(defaultExport.declaration, env, state)\n const exported = program.body.filter(\n (statement) => statement.type === 'ExportNamedDeclaration' && statement.declaration !== null\n )\n const lastExport = exported.at(-1)\n if (lastExport) {\n const declaration = (lastExport as ExportNamedDeclaration).declaration\n if (declaration) {\n const rendered = renderExported(declaration, env, state)\n if (rendered.length > 0) return rendered\n }\n }\n const expressions = program.body.filter(\n (statement) => statement.type === 'ExpressionStatement' && isElementCall(statement.expression)\n )\n const lastExpression = expressions.at(-1)\n if (lastExpression) {\n return renderExpression((lastExpression as ExpressionStatement).expression, env, state)\n }\n // A pasted component library defines several components and exports none as its default.\n const rendered: DesignNode[] = []\n for (const component of state.components.values()) {\n if (rendered.length >= MAX_EXPANDED_ITEMS) break\n rendered.push(...nameAfterComponent(component.name, renderFunction(component, [], state)))\n }\n return rendered\n}\n\n/** Every top-level function that builds an element, so a component the source defines expands. */\nexport function collectComponents(program: Program, env: Env): Map<string, LiteralFunction> {\n const components = new Map<string, LiteralFunction>()\n for (const statement of program.body) {\n const target = declarationOf(statement)\n if (target?.type === 'FunctionDeclaration') {\n addFunction(components, target as FunctionDeclaration, env)\n continue\n }\n if (target?.type !== 'VariableDeclaration') continue\n for (const declarator of (target as VariableDeclaration).declarations) {\n if (declarator.id.type !== 'Identifier') continue\n const init = declarator.init\n if (!init) continue\n const fn = functionNode(init)\n if (!fn) continue\n addNamedFunction(components, declarator.id.name, fn, env)\n }\n }\n return components\n}\n\nfunction addFunction(\n components: Map<string, LiteralFunction>,\n node: FunctionDeclaration,\n env: Env\n): void {\n const id = (node as IdHolder).id\n if (id) addNamedFunction(components, id.name, node, env)\n}\n\nfunction addNamedFunction(\n components: Map<string, LiteralFunction>,\n name: string,\n node: LiteralFunction['node'],\n env: Env\n): void {\n if (!drawsElements(node)) return\n components.set(name, { kind: 'function', node, env, name })\n}\n\n/** Module-scope `const` values, read as literals; anything else stays unknown. */\nexport function collectBindings(statement: Statement | ModuleDeclaration, env: Env): void {\n if (statement.type !== 'VariableDeclaration') return\n for (const declarator of statement.declarations) {\n if (declarator.id.type !== 'Identifier') continue\n const init = declarator.init\n if (!init) continue\n const name = declarator.id.name\n const callable = functionNode(init)\n if (callable) {\n env.set(name, { kind: 'function', node: callable, env, name })\n continue\n }\n const value = evaluate(init, env)\n if (value !== null) env.set(name, value)\n }\n}\n\nfunction renderExported(declaration: Node, env: Env, state: RenderState): DesignNode[] {\n if (!drawsElements(declaration)) return []\n const component = functionNode(declaration)\n if (component) {\n const id = component.type === 'FunctionDeclaration' ? (component as IdHolder).id : null\n const name = id?.name ?? ''\n const known = name ? state.components.get(name) : undefined\n return renderFunction(known ?? { kind: 'function', node: component, env, name }, [], state)\n }\n const value = evaluate(declaration, env)\n if (isLiteralFunction(value)) return renderFunction(value, [], state)\n return renderExpression(declaration, env, state)\n}\n\n/** A component's rendered tree, with its parameters bound to the values a call passes. */\nexport function renderFunction(\n component: LiteralFunction,\n args: (LiteralValue | null)[],\n state: RenderState\n): DesignNode[] {\n if (state.depth >= MAX_COMPONENT_DEPTH) {\n state.report.approximations += 1\n return [{ type: 'text', text: `{${component.name ?? 'component'}}` }]\n }\n const env: Env = new Map(component.env)\n bindParams(component.node, args, env)\n const depth = state.depth\n state.depth = depth + 1\n try {\n return renderBody(component.node, env, state)\n } finally {\n state.depth = depth\n }\n}\n\nfunction renderBody(node: LiteralFunction['node'], env: Env, state: RenderState): DesignNode[] {\n if (node.body.type !== 'BlockStatement') return renderExpression(node.body, env, state)\n return runStatements(node.body.body, env, state) ?? []\n}\n\n/** The tree a block's statements end with, reading only what JavaScript would collect. */\nfunction runStatements(statements: Statement[], env: Env, state: RenderState): DesignNode[] | null {\n for (const statement of statements) {\n if (statement.type === 'VariableDeclaration') {\n collectBindings(statement, env)\n continue\n }\n if (statement.type === 'ReturnStatement') {\n const argument = statement.argument\n return argument ? renderExpression(argument, env, state) : []\n }\n if (statement.type !== 'IfStatement') continue\n const nested = renderBranch(statement, env, state)\n if (nested) return nested\n }\n return null\n}\n\nfunction renderBranch(statement: IfStatement, env: Env, state: RenderState): DesignNode[] | null {\n const test = evaluate(statement.test, env)\n if (test === null) {\n state.report.approximations += 1\n return null\n }\n const branch = truthy(test) ? statement.consequent : statement.alternate\n if (!branch) return null\n return branch.type === 'BlockStatement'\n ? runStatements(branch.body, env, state)\n : runStatements([branch], env, state)\n}\n\n/** The nodes an expression draws: elements, an array of them, or text. */\nexport function renderExpression(node: Node, env: Env, state: RenderState): DesignNode[] {\n if (isElementCall(node)) return renderElement(node as CallExpression, env, state)\n const drawn = renderComposite(node, env, state)\n if (drawn) return drawn\n const value = evaluate(node, env)\n return value === null ? placeholder(node, state) : literalNodes(value)\n}\n\n/** Expressions that stand for other expressions rather than for one value. */\nfunction renderComposite(node: Node, env: Env, state: RenderState): DesignNode[] | null {\n if (node.type === 'ArrayExpression') {\n return (node as ArrayExpression).elements.flatMap((element) =>\n element && element.type !== 'SpreadElement' ? renderExpression(element, env, state) : []\n )\n }\n if (node.type === 'ConditionalExpression')\n return renderChoice(node as ConditionalExpression, env, state)\n if (node.type === 'LogicalExpression') return renderLogical(node as LogicalExpression, env, state)\n if (node.type === 'CallExpression') return renderMapped(node as CallExpression, env, state)\n if (node.type !== 'Identifier') return null\n const value = env.get((node as Identifier).name)\n if (value === undefined || value === UNKNOWN) return placeholder(node, state)\n return literalNodes(value)\n}\n\nfunction renderChoice(node: ConditionalExpression, env: Env, state: RenderState): DesignNode[] {\n const test = evaluate(node.test, env)\n if (test === null) state.report.approximations += 1\n const chosen = test === null || truthy(test) ? node.consequent : node.alternate\n return renderExpression(chosen, env, state)\n}\n\nfunction renderLogical(node: LogicalExpression, env: Env, state: RenderState): DesignNode[] {\n const left = evaluate(node.left, env)\n if (node.operator === '&&') {\n if (left === null) state.report.approximations += 1\n return truthy(left) ? renderExpression(node.right, env, state) : []\n }\n return left !== null && truthy(left)\n ? renderExpression(node.left, env, state)\n : renderExpression(node.right, env, state)\n}\n\n/** `items.map((item) => <li>{item.label}</li>)` over a literal array, one element per item. */\nfunction renderMapped(node: CallExpression, env: Env, state: RenderState): DesignNode[] | null {\n if (node.callee.type !== 'MemberExpression') return null\n const member = node.callee\n const isMap =\n !member.computed && member.property.type === 'Identifier' && member.property.name === 'map'\n if (!isMap) return null\n const items = evaluate(member.object, env)\n if (!Array.isArray(items)) return null\n const callback = node.arguments.at(0)\n if (!callback) return null\n const fn = functionNode(callback)\n if (!fn) return null\n\n if (items.length > MAX_EXPANDED_ITEMS) state.report.approximations += 1\n const rendered: DesignNode[] = []\n for (const item of items.slice(0, MAX_EXPANDED_ITEMS)) {\n const callbackEnv: Env = new Map(env)\n const first = fn.params.at(0)\n if (first?.type === 'Identifier') callbackEnv.set(first.name, item)\n const nodes =\n fn.body.type === 'BlockStatement'\n ? (runStatements(fn.body.body, callbackEnv, state) ?? [])\n : renderExpression(fn.body, callbackEnv, state)\n rendered.push(...nodes)\n }\n return rendered\n}\n\n/** One `__h(tag, props, …children)` call as a layer. */\nfunction renderElement(call: CallExpression, env: Env, state: RenderState): DesignNode[] {\n state.elements += 1\n if (state.elements > MAX_CODE_ELEMENTS) {\n throw new CodeTooLargeError(\n `The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`\n )\n }\n const tag = call.arguments.at(0)\n const propsNode = call.arguments.at(1) ?? null\n const props = propsNode ? readProps(propsNode, env, state) : { attrs: {} }\n const children = call.arguments\n .slice(2)\n .flatMap((child) => (child.type === 'SpreadElement' ? [] : renderExpression(child, env, state)))\n if (!tag || tag.type === 'SpreadElement') return children\n\n if (tag.type === 'Identifier') {\n const name = tag.name\n if (name === '__fragment') return children\n const component = state.components.get(name) ?? env.get(name)\n if (isLiteralFunction(component)) {\n const passed = propsNode ? evaluate(propsNode, env) : {}\n const first =\n passed !== null && typeof passed === 'object' && !Array.isArray(passed) ? passed : null\n return renderFunction(component, [first], state)\n }\n return [componentFrame(name, componentProps(props, state), children, state)]\n }\n const name = tag.type === 'MemberExpression' ? memberName(tag) : undefined\n const value = name ? undefined : evaluate(tag, env)\n if (typeof value !== 'string') {\n const frameName = name ?? expressionText(tag)\n return [componentFrame(frameName, componentProps(props, state), children, state)]\n }\n\n const element = elementNode(value, props, children)\n if (value.toLowerCase() === 'img') state.report.imagesAsPlaceholders += 1\n return [element]\n}\n\n/** Props an element keeps, with what it has no place for counted. */\ninterface ReadProps {\n class?: string\n style?: DesignStyleDeclaration\n attrs: Record<string, string>\n}\n\nfunction readProps(node: Node, env: Env, state: RenderState): ReadProps {\n if (node.type !== 'ObjectExpression') {\n state.report.droppedProps += 1\n return { attrs: {} }\n }\n const props: ReadProps = { attrs: {} }\n for (const property of (node as ObjectExpression).properties) {\n if (property.type === 'SpreadElement') {\n // `{...props}` names whatever a caller passes, which a paste does not have.\n state.report.droppedProps += 1\n continue\n }\n const name = propertyKey(property)\n if (!name || name === 'key' || name.startsWith('on')) continue\n readProperty(name, property.value, props, env, state)\n }\n return props\n}\n\nfunction readProperty(\n name: string,\n value: Node,\n props: ReadProps,\n env: Env,\n state: RenderState\n): void {\n if (name === 'className' || name === 'class') {\n const classes = readClasses(value, env, state)\n if (classes) props.class = classes\n return\n }\n if (name === 'style') {\n const style = readStyle(value, env)\n if (style) props.style = style\n return\n }\n const kept = attributeValue(value, env)\n if (kept !== null) {\n if (isKeptAttribute(name)) props.attrs[name] = kept\n else state.report.droppedProps += 1\n return\n }\n if (isKeptAttribute(name)) {\n // A value only the paste's own code could know, on an attribute a layer keeps.\n props.attrs[name] = `{${expressionText(value)}}`\n state.report.placeholders += 1\n return\n }\n state.report.droppedProps += 1\n}\n\nfunction isKeptAttribute(name: string): boolean {\n return name.startsWith('data-') || name.startsWith('aria-') || KEPT_ATTRIBUTES.has(name)\n}\n\n/** `cn(\"flex\", cond && \"gap-2\")` read as one class list, leaving out arguments it cannot know. */\nfunction readClasses(node: Node, env: Env, state: RenderState): string | undefined {\n const value = evaluate(node, env)\n const text = classesOf(value)\n if (text !== undefined) return text\n if (\n node.type === 'CallExpression' &&\n CLASS_HELPERS.has(calleeName(node as CallExpression) ?? '')\n ) {\n return mergeClasses(node as CallExpression, env) || undefined\n }\n if (node.type === 'ConditionalExpression')\n return readClassChoice(node as ConditionalExpression, env, state)\n if (node.type === 'LogicalExpression')\n return readClassLogical(node as LogicalExpression, env, state)\n if (value === null) state.report.approximations += 1\n return undefined\n}\n\nfunction classesOf(value: LiteralValue | null): string | undefined {\n if (typeof value === 'string') return value || undefined\n if (!Array.isArray(value)) return undefined\n const names = value.filter((entry): entry is string => typeof entry === 'string')\n return names.length > 0 ? names.join(' ') : undefined\n}\n\nfunction readClassChoice(\n node: ConditionalExpression,\n env: Env,\n state: RenderState\n): string | undefined {\n const test = evaluate(node.test, env)\n if (test === null) state.report.approximations += 1\n return readClasses(test === null || truthy(test) ? node.consequent : node.alternate, env, state)\n}\n\nfunction readClassLogical(\n node: LogicalExpression,\n env: Env,\n state: RenderState\n): string | undefined {\n const left = evaluate(node.left, env)\n if (node.operator === '&&') {\n if (left === null) state.report.approximations += 1\n return truthy(left) ? readClasses(node.right, env, state) : undefined\n }\n return readClasses(node.right, env, state)\n}\n\nfunction readStyle(node: Node, env: Env): DesignStyleDeclaration | undefined {\n const value = evaluate(node, env)\n if (typeof value === 'string') return styleFromText(value)\n if (value === null || typeof value !== 'object' || Array.isArray(value) || 'kind' in value) {\n return undefined\n }\n const declaration: DesignStyleDeclaration = {}\n for (const [property, entry] of Object.entries(value)) {\n if (typeof entry === 'object') continue\n declaration[cssProperty(property)] = String(entry)\n }\n return Object.keys(declaration).length > 0 ? declaration : undefined\n}\n\nfunction styleFromText(value: string): DesignStyleDeclaration | undefined {\n const declaration: DesignStyleDeclaration = {}\n for (const part of value.split(';')) {\n const colon = part.indexOf(':')\n if (colon === -1) continue\n const property = cssProperty(part.slice(0, colon).trim())\n const entry = part.slice(colon + 1).trim()\n if (property && entry) declaration[property] = entry\n }\n return Object.keys(declaration).length > 0 ? declaration : undefined\n}\n\nfunction cssProperty(name: string): string {\n if (name.startsWith('--')) return name\n return name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`)\n}\n\nfunction attributeValue(node: Node, env: Env): string | null {\n const value = evaluate(node, env)\n if (value === null || typeof value === 'object') return null\n return String(value)\n}\n\nfunction elementNode(tag: string, props: ReadProps, children: DesignNode[]): DesignNode {\n const attrs: Record<string, string> = { 'data-name': pascalCase(tag), ...props.attrs }\n if (props.class) attrs.class = props.class\n return { type: 'element', tagName: tag.toLowerCase(), attrs, inlineStyle: props.style, children }\n}\n\nfunction componentFrame(\n name: string,\n props: ReadProps,\n children: DesignNode[],\n state: RenderState\n): DesignNode {\n state.report.componentsAsFrames += 1\n const attrs: Record<string, string> = { 'data-name': name, ...props.attrs }\n if (props.class) attrs.class = props.class\n return { type: 'element', tagName: 'div', attrs, inlineStyle: props.style, children }\n}\n\n/** A component's props an element would hold have no place on a frame; only classes carry over. */\nfunction componentProps(props: ReadProps, state: RenderState): ReadProps {\n state.report.droppedProps += Object.keys(props.attrs).length\n return { class: props.class, style: props.style, attrs: {} }\n}\n\n/** A component's rendered roots take its name, so the layer tree says which component drew them. */\nfunction nameAfterComponent(name: string | undefined, nodes: DesignNode[]): DesignNode[] {\n if (!name) return nodes\n const first = nodes.at(0)\n if (first?.type !== 'element') return nodes\n const rest = nodes.slice(1)\n return [{ ...first, attrs: { ...first.attrs, 'data-name': name } }, ...rest]\n}\n\nfunction placeholder(node: Node, state: RenderState): DesignNode[] {\n state.report.placeholders += 1\n return [{ type: 'text', text: `{${expressionText(node)}}` }]\n}\n\nfunction literalNodes(value: LiteralValue): DesignNode[] {\n if (typeof value === 'string') return value.trim() ? [{ type: 'text', text: value }] : []\n if (typeof value === 'number' || typeof value === 'boolean') {\n return [{ type: 'text', text: String(value) }]\n }\n return []\n}\n","import type { DesignNode } from '#dom-css/types'\n\nimport type { Env } from './ast'\nimport { parseSource } from './ast'\nimport { collectBindings, collectComponents, renderRoots, type RenderState } from './render'\nimport { emptyReport, CodeSourceError, type CodeTree } from './report'\n\nexport { CodeSourceError, CodeTooLargeError, MAX_CODE_ELEMENTS } from './report'\nexport type { CodeReport, CodeTree } from './report'\nexport { tailwindCandidates, tailwindUtilities } from './candidates'\n\n/**\n * The element tree a pasted JSX or TSX source describes, and what it could not keep. Parsing and\n * reading only: nothing in the source runs, and a construct the reader cannot classify becomes a\n * placeholder rather than an error.\n */\nexport function jsxSourceToTree(source: string): CodeTree {\n const program = parseSource(source)\n const report = emptyReport()\n const moduleEnv: Env = new Map()\n for (const statement of program.body) collectBindings(statement, moduleEnv)\n const state: RenderState = {\n report,\n components: collectComponents(program, moduleEnv),\n depth: 0,\n elements: 0\n }\n\n const roots: DesignNode[] = renderRoots(program, moduleEnv, state)\n if (roots.length === 0) {\n throw new CodeSourceError(\n 'No JSX element found: paste a React or JSX component, or HTML markup.'\n )\n }\n return { children: roots, report }\n}\n"],"mappings":";;;;AAuCA,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAOD,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;;AAY5B,SAAgB,YAAY,SAAkB,KAAU,OAAkC;CACxF,MAAM,gBAAgB,QAAQ,KAAK,MAChC,cAAc,UAAU,SAAS,0BACpC;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CAQ1E,MAAM,QAAsB,YAAY,SAAS,WAAW;EAN1D;EACA,YAAY,kBAAkB,SAAS,SAAS;EAChD,OAAO;EACP,UAAU;CAGgD,CAAK;CACjE,IAAI,MAAM,WAAW,GACnB,MAAM,IAAI,gBACR,uEACF;CAEF,OAAO;EAAE,UAAU;EAAO;CAAO;AACnC"}
|
package/dist/export.d.ts
CHANGED
|
@@ -3,7 +3,20 @@ import { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundl
|
|
|
3
3
|
import { ThemeNamespace } from "twirlwind";
|
|
4
4
|
import { Behaviour } from "@pairdraw/scene-graph/behaviours";
|
|
5
5
|
import { es } from "@pairdraw/emit";
|
|
6
|
-
import { ComponentPropertyDefinition, SceneGraph, SceneNode, TokenUnit, Variable, VariableCollection, VariableCollectionMode } from "@pairdraw/scene-graph";
|
|
6
|
+
import { ColorProfile, ComponentPropertyDefinition, Fill, SceneGraph, SceneNode, TokenUnit, Variable, VariableCollection, VariableCollectionMode } from "@pairdraw/scene-graph";
|
|
7
|
+
//#region src/export/css.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* A diamond gradient as the Pairdraw spelling `get_css` reads and `set_fill` parses: CSS has no
|
|
10
|
+
* diamond form, and the stops are the same colours and positions every other gradient emits.
|
|
11
|
+
*/
|
|
12
|
+
declare function diamondFillToCSS(fill: Fill, profile?: ColorProfile): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* A gradient paint as the CSS gradient that draws it in a `width` × `height` box. The transform
|
|
15
|
+
* maps the box's unit square onto gradient space; its inverse gives the line's ends, the
|
|
16
|
+
* ellipse's centre and radii, or the sweep's start ray. Diamond gradients have no CSS spelling.
|
|
17
|
+
*/
|
|
18
|
+
declare function gradientFillToCSS(fill: Fill, width: number, height: number, profile?: ColorProfile): string | undefined;
|
|
19
|
+
//#endregion
|
|
7
20
|
//#region src/export/tailwind-jsx.d.ts
|
|
8
21
|
/** Engine services the projection takes, such as drawing vector layers as SVG. */
|
|
9
22
|
type ProjectionServices = Pick<SceneGraphToDesignOptions, 'vectorElement'>;
|
|
@@ -596,5 +609,5 @@ declare function stateTailwindClasses(styles: StateStyles, options?: StateTailwi
|
|
|
596
609
|
/** The state styles as Tailwind utilities on each element of the merged markup. */
|
|
597
610
|
declare function stateStylesToTailwind(styles: StateStyles, options?: StateTailwindOptions): DesignDocument;
|
|
598
611
|
//#endregion
|
|
599
|
-
export { BUTTON_RESET, type BehaviourArgs, type BooleanArg, type BooleanModel, COMPONENT_STYLINGS, type CSSExpressionProblem, type CSSValueToken, type CSSValueTokenKind, type ComponentStyling, type ControlModel, type ControlRole, type CustomPropertyDeclaration, type CustomPropertyScope, type CustomPropertySheet, type DesignDocument, type DesignElement, type DesignNode, type ExportHTMLBundle, type ExportHTMLBundleOptions, type ExportHTMLFile, type FeatureCondition, ICON_PACKAGES, INPUT_RESET, type IconFramework, type IconPackage, LAYER_COMPONENT_FRAMEWORKS, type LayerComponent, type LayerComponentFramework, type LayerMarkup, type SceneGraphToDesignOptions, type StateCondition, type StateElement, type StateNode, type StateRule, type StateStyles, type StateStylesheet, type StateTailwindOptions, type StatesModel, TOKEN_UNIT_PROPERTY, type TailwindJSXWithLayers, type TailwindStylesheetId, type TailwindStylesheetLoader, type TokenStylesheet, type TokenStylesheetFormat, type TokenStylesheetIssue, type TokenStylesheetOptions, type TokenValidator, type VectorElementRenderer, type WebFontFaceAsset, type WebFontFaceRequest, type WebFontFaceResolver, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, designNodeDraws, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, paintsSomething, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
612
|
+
export { BUTTON_RESET, type BehaviourArgs, type BooleanArg, type BooleanModel, COMPONENT_STYLINGS, type CSSExpressionProblem, type CSSValueToken, type CSSValueTokenKind, type ComponentStyling, type ControlModel, type ControlRole, type CustomPropertyDeclaration, type CustomPropertyScope, type CustomPropertySheet, type DesignDocument, type DesignElement, type DesignNode, type ExportHTMLBundle, type ExportHTMLBundleOptions, type ExportHTMLFile, type FeatureCondition, ICON_PACKAGES, INPUT_RESET, type IconFramework, type IconPackage, LAYER_COMPONENT_FRAMEWORKS, type LayerComponent, type LayerComponentFramework, type LayerMarkup, type SceneGraphToDesignOptions, type StateCondition, type StateElement, type StateNode, type StateRule, type StateStyles, type StateStylesheet, type StateTailwindOptions, type StatesModel, TOKEN_UNIT_PROPERTY, type TailwindJSXWithLayers, type TailwindStylesheetId, type TailwindStylesheetLoader, type TokenStylesheet, type TokenStylesheetFormat, type TokenStylesheetIssue, type TokenStylesheetOptions, type TokenValidator, type VectorElementRenderer, type WebFontFaceAsset, type WebFontFaceRequest, type WebFontFaceResolver, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, designNodeDraws, diamondFillToCSS, explicitCSSName, exportHTMLBundle, featureConditionCSS, gradientFillToCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, paintsSomething, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
600
613
|
//# sourceMappingURL=export.d.ts.map
|
package/dist/export.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TOKEN_UNIT_PROPERTY, buildTokenStylesheet, collectionVariables, createTokenValidator, cssNameCodeSyntax, cssNameVariableName, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designNodeDraws, explicitCSSName, loadTokenValidator, modeAttribute, paintsSomething, parseCSSName, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit } from "./chunks/behaviours/states/layers.js";
|
|
1
|
+
import { TOKEN_UNIT_PROPERTY, buildTokenStylesheet, collectionVariables, createTokenValidator, cssNameCodeSyntax, cssNameVariableName, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designNodeDraws, diamondFillToCSS, explicitCSSName, gradientFillToCSS, loadTokenValidator, modeAttribute, paintsSomething, parseCSSName, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit } from "./chunks/behaviours/states/layers.js";
|
|
2
2
|
import { serializeHTML, stateStylesToTailwind, stateTailwindClasses } from "./chunks/behaviours/states/tailwind.js";
|
|
3
3
|
import { exportHTMLBundle } from "./chunks/export/bundle.js";
|
|
4
4
|
import { behaviourArgs } from "./chunks/behaviours/args.js";
|
|
@@ -10,4 +10,4 @@ import { ICON_PACKAGES, iconPackagesFor, isIconPackage } from "./chunks/export/c
|
|
|
10
10
|
import { cssExpressionProblem, cssTokenProperty, cssValueTokens, designDocumentToTailwindJSX, featureConditionCSS, modeConditionKey, modeConditionName, parseFeatureCondition, readCustomProperties, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers } from "./chunks/export/index.js";
|
|
11
11
|
import { behaviourControls, booleanOf } from "./chunks/behaviours/controls.js";
|
|
12
12
|
import { controlRoles, groupOf } from "./chunks/behaviours/roles.js";
|
|
13
|
-
export { BUTTON_RESET, COMPONENT_STYLINGS, ICON_PACKAGES, INPUT_RESET, LAYER_COMPONENT_FRAMEWORKS, TOKEN_UNIT_PROPERTY, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, designNodeDraws, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, paintsSomething, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
13
|
+
export { BUTTON_RESET, COMPONENT_STYLINGS, ICON_PACKAGES, INPUT_RESET, LAYER_COMPONENT_FRAMEWORKS, TOKEN_UNIT_PROPERTY, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, designNodeDraws, diamondFillToCSS, explicitCSSName, exportHTMLBundle, featureConditionCSS, gradientFillToCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, paintsSomething, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
package/dist/index.d.ts
CHANGED
|
@@ -101,6 +101,71 @@ declare function htmlToSceneGraph(html: string, options?: HTMLToSceneGraphOption
|
|
|
101
101
|
declare function tailwindHTMLToDesignDocument(html: string, candidates: string | Iterable<string>, options?: TailwindHTMLToDesignDocumentOptions): Promise<DesignDocument$1>;
|
|
102
102
|
declare function tailwindHTMLToSceneGraph(html: string, candidates: string | Iterable<string>, options?: TailwindHTMLToSceneGraphOptions): Promise<SceneGraph>;
|
|
103
103
|
//#endregion
|
|
104
|
+
//#region src/runtime/css/url.d.ts
|
|
105
|
+
/** A stylesheet value with its comments removed and its escapes decoded, as CSS parses it. */
|
|
106
|
+
declare function decodedCSS(text: string): string;
|
|
107
|
+
/** Whether a declaration or rule loads a picture, in any spelling CSS allows. */
|
|
108
|
+
declare function mentionsURL(text: string): boolean;
|
|
109
|
+
/** Whether text can load anything: `url()`, `image-set()`, or a stylesheet import. */
|
|
110
|
+
declare function mentionsResource(text: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* A pasted stylesheet with its resource-loading declarations and imports removed, keeping the
|
|
113
|
+
* rules that only style. A block the flat scan cannot take apart is dropped whole.
|
|
114
|
+
*/
|
|
115
|
+
declare function withoutResourceRules(cssText: string): string;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/import/jsx/source/report.d.ts
|
|
118
|
+
/** Pasted source that a reader cannot turn into layers. */
|
|
119
|
+
declare class CodeSourceError extends Error {
|
|
120
|
+
constructor(message: string);
|
|
121
|
+
}
|
|
122
|
+
/** The most layers one paste may draw, so a pathological source cannot stall a document. */
|
|
123
|
+
declare const MAX_CODE_ELEMENTS = 2000;
|
|
124
|
+
/** Pasted source that draws more than a document should take, which a paste refuses by size. */
|
|
125
|
+
declare class CodeTooLargeError extends CodeSourceError {
|
|
126
|
+
constructor(message: string);
|
|
127
|
+
}
|
|
128
|
+
/** What a paste could not keep, so the caller can tell the user in one toast. */
|
|
129
|
+
interface CodeReport {
|
|
130
|
+
/** Expressions rendered as their own source text. */
|
|
131
|
+
placeholders: number;
|
|
132
|
+
/** Components with no definition in the paste, drawn as frames under their name. */
|
|
133
|
+
componentsAsFrames: number;
|
|
134
|
+
/** Attributes an element has no layer property for, and props no component could take. */
|
|
135
|
+
droppedProps: number;
|
|
136
|
+
/** Branches and values read from one possibility rather than known exactly. */
|
|
137
|
+
approximations: number;
|
|
138
|
+
/** Images whose source a paste cannot load, drawn at their box size. */
|
|
139
|
+
imagesAsPlaceholders: number;
|
|
140
|
+
}
|
|
141
|
+
interface CodeTree {
|
|
142
|
+
children: DesignNode$1[];
|
|
143
|
+
report: CodeReport;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/import/jsx/source/candidates.d.ts
|
|
147
|
+
/** The utilities a class list names, with one base utility per class and its variant count. */
|
|
148
|
+
declare function tailwindUtilities(classes: Iterable<string>): {
|
|
149
|
+
candidates: string[];
|
|
150
|
+
variantsStripped: number;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* The Tailwind utilities pasted markup names, with the base utility kept from every variant
|
|
154
|
+
* (`md:flex-row` asks for `flex-row` here), so a paste styles the same at any canvas width.
|
|
155
|
+
*/
|
|
156
|
+
declare function tailwindCandidates(nodes: readonly DesignNode$1[]): {
|
|
157
|
+
candidates: string[];
|
|
158
|
+
variantsStripped: number;
|
|
159
|
+
};
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/import/jsx/source/index.d.ts
|
|
162
|
+
/**
|
|
163
|
+
* The element tree a pasted JSX or TSX source describes, and what it could not keep. Parsing and
|
|
164
|
+
* reading only: nothing in the source runs, and a construct the reader cannot classify becomes a
|
|
165
|
+
* placeholder rather than an error.
|
|
166
|
+
*/
|
|
167
|
+
declare function jsxSourceToTree(source: string): CodeTree;
|
|
168
|
+
//#endregion
|
|
104
169
|
//#region src/index.d.ts
|
|
105
170
|
type CSSComputeOptions = CSSComputeOptions$1;
|
|
106
171
|
type CSSRuntime = CSSRuntime$1;
|
|
@@ -111,5 +176,5 @@ type DesignStyleDeclaration = DesignStyleDeclaration$1;
|
|
|
111
176
|
type DesignStyleSheet = DesignStyleSheet$1;
|
|
112
177
|
type DesignText = DesignText$1;
|
|
113
178
|
//#endregion
|
|
114
|
-
export { type BrowserCSSRuntimeOptions, CSSComputeOptions, CSSRuntime, type CompileTailwindCSSOptions, DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignStyleSheet, DesignText, type ExportStorybookOptions, type HTMLToDesignDocumentOptions, type HTMLToSceneGraphOptions, type JSXStyleObject, type JSXStyleValue, type JSXToDesignDocumentOptions, type JSXToSceneGraphOptions, STORYBOOK_FRAMEWORKS, STORY_MODES, type SerializeHTMLOptions, type StoryMode, type StoryPlan, type StoryTarget, type StorybookFile, type StorybookFramework, type TailwindHTMLToDesignDocumentOptions, type TailwindHTMLToSceneGraphOptions, type TailwindJSXToDesignDocumentOptions, type TailwindJSXToSceneGraphOptions, compileTailwindCSS, createBrowserCSSRuntime, createCSSRuntime, createHeadlessCSSRuntime, exportStorybook, htmlToDesignDocument, htmlToSceneGraph, jsxToDesignDocument, jsxToSceneGraph, serializeNode, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
179
|
+
export { type BrowserCSSRuntimeOptions, CSSComputeOptions, CSSRuntime, type CodeReport, CodeSourceError, CodeTooLargeError, type CodeTree, type CompileTailwindCSSOptions, DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignStyleSheet, DesignText, type ExportStorybookOptions, type HTMLToDesignDocumentOptions, type HTMLToSceneGraphOptions, type JSXStyleObject, type JSXStyleValue, type JSXToDesignDocumentOptions, type JSXToSceneGraphOptions, MAX_CODE_ELEMENTS, STORYBOOK_FRAMEWORKS, STORY_MODES, type SerializeHTMLOptions, type StoryMode, type StoryPlan, type StoryTarget, type StorybookFile, type StorybookFramework, type TailwindHTMLToDesignDocumentOptions, type TailwindHTMLToSceneGraphOptions, type TailwindJSXToDesignDocumentOptions, type TailwindJSXToSceneGraphOptions, compileTailwindCSS, createBrowserCSSRuntime, createCSSRuntime, createHeadlessCSSRuntime, decodedCSS, exportStorybook, htmlToDesignDocument, htmlToSceneGraph, jsxSourceToTree, jsxToDesignDocument, jsxToSceneGraph, mentionsResource, mentionsURL, serializeNode, tailwindCandidates, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph, tailwindUtilities, withoutResourceRules };
|
|
115
180
|
//# sourceMappingURL=index.d.ts.map
|