designmockdown 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/dist/app/assets/index-CmugGtLS.js +15 -0
- package/dist/app/assets/index-CwhgxL4e.css +1 -0
- package/dist/app/index.html +13 -0
- package/dist/lib/cli.d.ts +11 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +968 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/collab/client.d.ts +20 -0
- package/dist/lib/collab/client.d.ts.map +1 -0
- package/dist/lib/collab/client.js +126 -0
- package/dist/lib/collab/client.js.map +1 -0
- package/dist/lib/collab/index.d.ts +40 -0
- package/dist/lib/collab/index.d.ts.map +1 -0
- package/dist/lib/collab/index.js +154 -0
- package/dist/lib/collab/index.js.map +1 -0
- package/dist/lib/collab/room.d.ts +111 -0
- package/dist/lib/collab/room.d.ts.map +1 -0
- package/dist/lib/collab/room.js +120 -0
- package/dist/lib/collab/room.js.map +1 -0
- package/dist/lib/collab/ws.d.ts +33 -0
- package/dist/lib/collab/ws.d.ts.map +1 -0
- package/dist/lib/collab/ws.js +191 -0
- package/dist/lib/collab/ws.js.map +1 -0
- package/dist/lib/components/basic.d.ts +8 -0
- package/dist/lib/components/basic.d.ts.map +1 -0
- package/dist/lib/components/basic.js +181 -0
- package/dist/lib/components/basic.js.map +1 -0
- package/dist/lib/components/config.d.ts +26 -0
- package/dist/lib/components/config.d.ts.map +1 -0
- package/dist/lib/components/config.js +94 -0
- package/dist/lib/components/config.js.map +1 -0
- package/dist/lib/components/containers.d.ts +9 -0
- package/dist/lib/components/containers.d.ts.map +1 -0
- package/dist/lib/components/containers.js +102 -0
- package/dist/lib/components/containers.js.map +1 -0
- package/dist/lib/components/controls.d.ts +8 -0
- package/dist/lib/components/controls.d.ts.map +1 -0
- package/dist/lib/components/controls.js +376 -0
- package/dist/lib/components/controls.js.map +1 -0
- package/dist/lib/components/data.d.ts +8 -0
- package/dist/lib/components/data.d.ts.map +1 -0
- package/dist/lib/components/data.js +494 -0
- package/dist/lib/components/data.js.map +1 -0
- package/dist/lib/components/feedback.d.ts +8 -0
- package/dist/lib/components/feedback.d.ts.map +1 -0
- package/dist/lib/components/feedback.js +151 -0
- package/dist/lib/components/feedback.js.map +1 -0
- package/dist/lib/components/icons.d.ts +28 -0
- package/dist/lib/components/icons.d.ts.map +1 -0
- package/dist/lib/components/icons.js +85 -0
- package/dist/lib/components/icons.js.map +1 -0
- package/dist/lib/components/layout.d.ts +10 -0
- package/dist/lib/components/layout.d.ts.map +1 -0
- package/dist/lib/components/layout.js +82 -0
- package/dist/lib/components/layout.js.map +1 -0
- package/dist/lib/components/nav.d.ts +8 -0
- package/dist/lib/components/nav.d.ts.map +1 -0
- package/dist/lib/components/nav.js +216 -0
- package/dist/lib/components/nav.js.map +1 -0
- package/dist/lib/components/plugin.d.ts +27 -0
- package/dist/lib/components/plugin.d.ts.map +1 -0
- package/dist/lib/components/plugin.js +152 -0
- package/dist/lib/components/plugin.js.map +1 -0
- package/dist/lib/components/registry.d.ts +111 -0
- package/dist/lib/components/registry.d.ts.map +1 -0
- package/dist/lib/components/registry.js +375 -0
- package/dist/lib/components/registry.js.map +1 -0
- package/dist/lib/components/types.d.ts +111 -0
- package/dist/lib/components/types.d.ts.map +1 -0
- package/dist/lib/components/types.js +6 -0
- package/dist/lib/components/types.js.map +1 -0
- package/dist/lib/core/anim.d.ts +31 -0
- package/dist/lib/core/anim.d.ts.map +1 -0
- package/dist/lib/core/anim.js +95 -0
- package/dist/lib/core/anim.js.map +1 -0
- package/dist/lib/core/ast.d.ts +174 -0
- package/dist/lib/core/ast.d.ts.map +1 -0
- package/dist/lib/core/ast.js +42 -0
- package/dist/lib/core/ast.js.map +1 -0
- package/dist/lib/core/chart-source.d.ts +37 -0
- package/dist/lib/core/chart-source.d.ts.map +1 -0
- package/dist/lib/core/chart-source.js +125 -0
- package/dist/lib/core/chart-source.js.map +1 -0
- package/dist/lib/core/data.d.ts +32 -0
- package/dist/lib/core/data.d.ts.map +1 -0
- package/dist/lib/core/data.js +150 -0
- package/dist/lib/core/data.js.map +1 -0
- package/dist/lib/core/define.d.ts +16 -0
- package/dist/lib/core/define.d.ts.map +1 -0
- package/dist/lib/core/define.js +232 -0
- package/dist/lib/core/define.js.map +1 -0
- package/dist/lib/core/diagnostics.d.ts +64 -0
- package/dist/lib/core/diagnostics.d.ts.map +1 -0
- package/dist/lib/core/diagnostics.js +62 -0
- package/dist/lib/core/diagnostics.js.map +1 -0
- package/dist/lib/core/errors.d.ts +27 -0
- package/dist/lib/core/errors.d.ts.map +1 -0
- package/dist/lib/core/errors.js +70 -0
- package/dist/lib/core/errors.js.map +1 -0
- package/dist/lib/core/expand.d.ts +21 -0
- package/dist/lib/core/expand.d.ts.map +1 -0
- package/dist/lib/core/expand.js +226 -0
- package/dist/lib/core/expand.js.map +1 -0
- package/dist/lib/core/expr.d.ts +29 -0
- package/dist/lib/core/expr.d.ts.map +1 -0
- package/dist/lib/core/expr.js +313 -0
- package/dist/lib/core/expr.js.map +1 -0
- package/dist/lib/core/format.d.ts +30 -0
- package/dist/lib/core/format.d.ts.map +1 -0
- package/dist/lib/core/format.js +106 -0
- package/dist/lib/core/format.js.map +1 -0
- package/dist/lib/core/lexer.d.ts +54 -0
- package/dist/lib/core/lexer.d.ts.map +1 -0
- package/dist/lib/core/lexer.js +311 -0
- package/dist/lib/core/lexer.js.map +1 -0
- package/dist/lib/core/parser.d.ts +29 -0
- package/dist/lib/core/parser.d.ts.map +1 -0
- package/dist/lib/core/parser.js +674 -0
- package/dist/lib/core/parser.js.map +1 -0
- package/dist/lib/core/resolver.d.ts +37 -0
- package/dist/lib/core/resolver.d.ts.map +1 -0
- package/dist/lib/core/resolver.js +240 -0
- package/dist/lib/core/resolver.js.map +1 -0
- package/dist/lib/core/spec.d.ts +87 -0
- package/dist/lib/core/spec.d.ts.map +1 -0
- package/dist/lib/core/spec.js +207 -0
- package/dist/lib/core/spec.js.map +1 -0
- package/dist/lib/core/state.d.ts +19 -0
- package/dist/lib/core/state.d.ts.map +1 -0
- package/dist/lib/core/state.js +64 -0
- package/dist/lib/core/state.js.map +1 -0
- package/dist/lib/core/tokens.d.ts +36 -0
- package/dist/lib/core/tokens.d.ts.map +1 -0
- package/dist/lib/core/tokens.js +198 -0
- package/dist/lib/core/tokens.js.map +1 -0
- package/dist/lib/export/pages.d.ts +39 -0
- package/dist/lib/export/pages.d.ts.map +1 -0
- package/dist/lib/export/pages.js +95 -0
- package/dist/lib/export/pages.js.map +1 -0
- package/dist/lib/export/raster.d.ts +39 -0
- package/dist/lib/export/raster.d.ts.map +1 -0
- package/dist/lib/export/raster.js +152 -0
- package/dist/lib/export/raster.js.map +1 -0
- package/dist/lib/index.d.ts +33 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +30 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/layout/engine.d.ts +32 -0
- package/dist/lib/layout/engine.d.ts.map +1 -0
- package/dist/lib/layout/engine.js +1063 -0
- package/dist/lib/layout/engine.js.map +1 -0
- package/dist/lib/layout/measure.d.ts +30 -0
- package/dist/lib/layout/measure.d.ts.map +1 -0
- package/dist/lib/layout/measure.js +148 -0
- package/dist/lib/layout/measure.js.map +1 -0
- package/dist/lib/layout/types.d.ts +94 -0
- package/dist/lib/layout/types.d.ts.map +1 -0
- package/dist/lib/layout/types.js +16 -0
- package/dist/lib/layout/types.js.map +1 -0
- package/dist/lib/lsp/server.d.ts +76 -0
- package/dist/lib/lsp/server.d.ts.map +1 -0
- package/dist/lib/lsp/server.js +264 -0
- package/dist/lib/lsp/server.js.map +1 -0
- package/dist/lib/output/docs.d.ts +26 -0
- package/dist/lib/output/docs.d.ts.map +1 -0
- package/dist/lib/output/docs.js +231 -0
- package/dist/lib/output/docs.js.map +1 -0
- package/dist/lib/output/ir.d.ts +105 -0
- package/dist/lib/output/ir.d.ts.map +1 -0
- package/dist/lib/output/ir.js +89 -0
- package/dist/lib/output/ir.js.map +1 -0
- package/dist/lib/output/schema.d.ts +69 -0
- package/dist/lib/output/schema.d.ts.map +1 -0
- package/dist/lib/output/schema.js +84 -0
- package/dist/lib/output/schema.js.map +1 -0
- package/dist/lib/paths.d.ts +12 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +27 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/playground/examples.d.ts +16 -0
- package/dist/lib/playground/examples.d.ts.map +1 -0
- package/dist/lib/playground/examples.js +515 -0
- package/dist/lib/playground/examples.js.map +1 -0
- package/dist/lib/playground/index.d.ts +51 -0
- package/dist/lib/playground/index.d.ts.map +1 -0
- package/dist/lib/playground/index.js +598 -0
- package/dist/lib/playground/index.js.map +1 -0
- package/dist/lib/render/assets.d.ts +35 -0
- package/dist/lib/render/assets.d.ts.map +1 -0
- package/dist/lib/render/assets.js +114 -0
- package/dist/lib/render/assets.js.map +1 -0
- package/dist/lib/render/backends.d.ts +31 -0
- package/dist/lib/render/backends.d.ts.map +1 -0
- package/dist/lib/render/backends.js +57 -0
- package/dist/lib/render/backends.js.map +1 -0
- package/dist/lib/render/css.d.ts +24 -0
- package/dist/lib/render/css.d.ts.map +1 -0
- package/dist/lib/render/css.js +148 -0
- package/dist/lib/render/css.js.map +1 -0
- package/dist/lib/render/document-html.d.ts +28 -0
- package/dist/lib/render/document-html.d.ts.map +1 -0
- package/dist/lib/render/document-html.js +214 -0
- package/dist/lib/render/document-html.js.map +1 -0
- package/dist/lib/render/dom.d.ts +32 -0
- package/dist/lib/render/dom.d.ts.map +1 -0
- package/dist/lib/render/dom.js +531 -0
- package/dist/lib/render/dom.js.map +1 -0
- package/dist/lib/render/primitives.d.ts +81 -0
- package/dist/lib/render/primitives.d.ts.map +1 -0
- package/dist/lib/render/primitives.js +172 -0
- package/dist/lib/render/primitives.js.map +1 -0
- package/dist/lib/render/react.d.ts +23 -0
- package/dist/lib/render/react.d.ts.map +1 -0
- package/dist/lib/render/react.js +447 -0
- package/dist/lib/render/react.js.map +1 -0
- package/dist/lib/render/svg.d.ts +45 -0
- package/dist/lib/render/svg.d.ts.map +1 -0
- package/dist/lib/render/svg.js +179 -0
- package/dist/lib/render/svg.js.map +1 -0
- package/dist/lib/runtime/proto.d.ts +19 -0
- package/dist/lib/runtime/proto.d.ts.map +1 -0
- package/dist/lib/runtime/proto.js +81 -0
- package/dist/lib/runtime/proto.js.map +1 -0
- package/dist/lib/skill/install.d.ts +28 -0
- package/dist/lib/skill/install.d.ts.map +1 -0
- package/dist/lib/skill/install.js +89 -0
- package/dist/lib/skill/install.js.map +1 -0
- package/dist/lib/workbench/app.d.ts +24 -0
- package/dist/lib/workbench/app.d.ts.map +1 -0
- package/dist/lib/workbench/app.js +45 -0
- package/dist/lib/workbench/app.js.map +1 -0
- package/dist/lib/workbench/assets.d.ts +21 -0
- package/dist/lib/workbench/assets.d.ts.map +1 -0
- package/dist/lib/workbench/assets.js +44 -0
- package/dist/lib/workbench/assets.js.map +1 -0
- package/dist/lib/workbench/client.d.ts +18 -0
- package/dist/lib/workbench/client.d.ts.map +1 -0
- package/dist/lib/workbench/client.js +736 -0
- package/dist/lib/workbench/client.js.map +1 -0
- package/dist/lib/workbench/drag.d.ts +90 -0
- package/dist/lib/workbench/drag.d.ts.map +1 -0
- package/dist/lib/workbench/drag.js +109 -0
- package/dist/lib/workbench/drag.js.map +1 -0
- package/dist/lib/workbench/geometry.d.ts +28 -0
- package/dist/lib/workbench/geometry.d.ts.map +1 -0
- package/dist/lib/workbench/geometry.js +28 -0
- package/dist/lib/workbench/geometry.js.map +1 -0
- package/dist/lib/workbench/select.d.ts +56 -0
- package/dist/lib/workbench/select.d.ts.map +1 -0
- package/dist/lib/workbench/select.js +111 -0
- package/dist/lib/workbench/select.js.map +1 -0
- package/dist/lib/workbench/server.d.ts +223 -0
- package/dist/lib/workbench/server.d.ts.map +1 -0
- package/dist/lib/workbench/server.js +576 -0
- package/dist/lib/workbench/server.js.map +1 -0
- package/dist/lib/workbench/source.d.ts +124 -0
- package/dist/lib/workbench/source.d.ts.map +1 -0
- package/dist/lib/workbench/source.js +405 -0
- package/dist/lib/workbench/source.js.map +1 -0
- package/docs/README.md +49 -0
- package/docs/cheatsheet.md +243 -0
- package/docs/cli.md +95 -0
- package/docs/data.md +112 -0
- package/docs/export.md +106 -0
- package/docs/getting-started.md +105 -0
- package/docs/language.md +136 -0
- package/docs/layout.md +159 -0
- package/docs/plugins.md +82 -0
- package/docs/reference.md +1156 -0
- package/docs/roadmap.md +54 -0
- package/docs/syntax.md +312 -0
- package/docs/workbench.md +125 -0
- package/examples/app.dm +76 -0
- package/examples/assets/avatar.png +0 -0
- package/examples/assets/cover.png +0 -0
- package/examples/assets/logo.svg +4 -0
- package/examples/assets.dm +49 -0
- package/examples/dashboard.dm +64 -0
- package/examples/data.dm +107 -0
- package/examples/layout.dm +93 -0
- package/examples/login.dm +43 -0
- package/examples/login.html +61 -0
- package/examples/plugins/rating/README.md +67 -0
- package/examples/plugins/rating/example.dm +29 -0
- package/examples/plugins/rating/index.ts +122 -0
- package/examples/plugins/rating/package.json +22 -0
- package/examples/recipe/assets/broccoli.jpg +0 -0
- package/examples/recipe/assets/cheesecake.jpg +0 -0
- package/examples/recipe/assets/chicken-pot.jpg +0 -0
- package/examples/recipe/assets/noodles.jpg +0 -0
- package/examples/recipe/assets/shrimp.jpg +0 -0
- package/examples/recipe/assets/tomato-beef.jpg +0 -0
- package/examples/recipe/detail.dm +105 -0
- package/examples/recipe/discover.dm +116 -0
- package/examples/recipe/favorites.dm +115 -0
- package/examples/recipe/index.dm +124 -0
- package/examples/recipe/profile.dm +134 -0
- package/examples/recipe/steps.dm +89 -0
- package/examples/settings.dm +108 -0
- package/package.json +84 -4
- package/skills/designmockdown/REFERENCE.md +373 -0
- package/skills/designmockdown/SKILL.md +179 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@define` expansion: user-defined component templates.
|
|
3
|
+
*
|
|
4
|
+
* A definition is a subtree of ordinary nodes. A usage `@my-card {p=24}` clones that subtree and
|
|
5
|
+
* merges the usage's attributes into the clone's root, so the result is a plain AST that layout and
|
|
6
|
+
* both renderers handle without knowing `@define` exists.
|
|
7
|
+
*
|
|
8
|
+
* Expansion happens before L2 interpolation, so a template body may itself contain `{}` references
|
|
9
|
+
* and `@if` / `@for` - those are resolved afterwards against the data scope.
|
|
10
|
+
*/
|
|
11
|
+
import { isContainer } from "./ast.js";
|
|
12
|
+
import { DesignMockdownError } from "./errors.js";
|
|
13
|
+
/** Expand every `@<defined>` usage in the tree. Mutates and returns the page. */
|
|
14
|
+
export function expandDefs(page) {
|
|
15
|
+
const defs = page.defs ?? {};
|
|
16
|
+
if (Object.keys(defs).length === 0)
|
|
17
|
+
return;
|
|
18
|
+
const walk = (node) => {
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const child of node.children) {
|
|
21
|
+
if (child.type === 'component' && defs[child.name] && child.name !== 'define') {
|
|
22
|
+
out.push(...instantiate(defs[child.name], child));
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (isContainer(child))
|
|
26
|
+
walk(child);
|
|
27
|
+
out.push(child);
|
|
28
|
+
}
|
|
29
|
+
node.children = out;
|
|
30
|
+
for (const [key, list] of Object.entries(node.slots)) {
|
|
31
|
+
const slotOut = [];
|
|
32
|
+
for (const child of list) {
|
|
33
|
+
if (child.type === 'component' && defs[child.name]) {
|
|
34
|
+
slotOut.push(...instantiate(defs[child.name], child));
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (isContainer(child))
|
|
38
|
+
walk(child);
|
|
39
|
+
slotOut.push(child);
|
|
40
|
+
}
|
|
41
|
+
node.slots[key] = slotOut;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
walk(page);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Clone a template and merge the usage's attributes into the clone's root.
|
|
48
|
+
*
|
|
49
|
+
* The template's holder is a synthetic container, so the real root is its first child. When the
|
|
50
|
+
* body is a single component (the common case) that component is promoted and becomes the root,
|
|
51
|
+
* which keeps the output identical to hand-writing it. A multi-root body keeps a neutral wrapper.
|
|
52
|
+
*
|
|
53
|
+
* Inline content on the usage is pushed down to the template's first text-bearing descendant: the
|
|
54
|
+
* root is usually a container, and hanging text off a container is not what the author meant.
|
|
55
|
+
*/
|
|
56
|
+
function instantiate(template, usage) {
|
|
57
|
+
const body = template.children;
|
|
58
|
+
const root = body.length === 1 ? cloneNode(body[0]) : cloneNode(template);
|
|
59
|
+
// Computed from the template, before any substitution: afterwards the {{key}} markers are gone
|
|
60
|
+
const consumed = new Set(consumedKeys(template, usage.attrs));
|
|
61
|
+
if (body.length === 1) {
|
|
62
|
+
root.attrs = { ...root.attrs, ...usage.attrs };
|
|
63
|
+
root.pos = usage.pos;
|
|
64
|
+
// Remember where it came from: the expanded root wears the template's component name, so
|
|
65
|
+
// without this the workbench cannot tell an instance from a hand-written card
|
|
66
|
+
root.definedAs = usage.name;
|
|
67
|
+
if (usage.id && !usage.id.startsWith(`${usage.name}-`))
|
|
68
|
+
root.id = usage.id;
|
|
69
|
+
bindPlaceholders(root, usage.attrs);
|
|
70
|
+
// Keys the template referenced as {{key}} are template inputs, not attributes of the root:
|
|
71
|
+
// `label` on a `box` would trip the unknown-attribute warning
|
|
72
|
+
for (const key of consumed)
|
|
73
|
+
delete root.attrs[key];
|
|
74
|
+
if (usage.content)
|
|
75
|
+
applyContent(root, usage.content);
|
|
76
|
+
return [root];
|
|
77
|
+
}
|
|
78
|
+
// Multi-root body: the wrapper stands in for the template itself
|
|
79
|
+
const wrapper = cloneNode(template);
|
|
80
|
+
wrapper.name = 'box';
|
|
81
|
+
wrapper.attrs = { ...wrapper.attrs, ...usage.attrs };
|
|
82
|
+
wrapper.pos = usage.pos;
|
|
83
|
+
wrapper.definedAs = usage.name;
|
|
84
|
+
if (usage.id && !usage.id.startsWith(`${usage.name}-`))
|
|
85
|
+
wrapper.id = usage.id;
|
|
86
|
+
bindPlaceholders(wrapper, usage.attrs);
|
|
87
|
+
for (const key of consumed)
|
|
88
|
+
delete wrapper.attrs[key];
|
|
89
|
+
if (usage.content)
|
|
90
|
+
applyContent(wrapper, usage.content);
|
|
91
|
+
return [wrapper];
|
|
92
|
+
}
|
|
93
|
+
/** Put the usage's inline text on the first descendant that already carries text */
|
|
94
|
+
function applyContent(root, content) {
|
|
95
|
+
const target = findTextCarrier(root);
|
|
96
|
+
if (target)
|
|
97
|
+
target.content = content;
|
|
98
|
+
else
|
|
99
|
+
root.content = content;
|
|
100
|
+
}
|
|
101
|
+
function findTextCarrier(node) {
|
|
102
|
+
if (!isContainer(node))
|
|
103
|
+
return null;
|
|
104
|
+
for (const child of node.children) {
|
|
105
|
+
if (child.type === 'component' && child.content !== '')
|
|
106
|
+
return child;
|
|
107
|
+
const found = findTextCarrier(child);
|
|
108
|
+
if (found)
|
|
109
|
+
return found;
|
|
110
|
+
}
|
|
111
|
+
for (const list of Object.values(node.slots)) {
|
|
112
|
+
for (const child of list) {
|
|
113
|
+
if (child.type === 'component' && child.content !== '')
|
|
114
|
+
return child;
|
|
115
|
+
const found = findTextCarrier(child);
|
|
116
|
+
if (found)
|
|
117
|
+
return found;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Which of the caller's keys the template referenced as `{{key}}`.
|
|
124
|
+
*
|
|
125
|
+
* Those keys are template inputs, not attributes of the root component, so they must be dropped
|
|
126
|
+
* from the root - otherwise `label` would sit on a `box` and trip the unknown-attribute warning.
|
|
127
|
+
*/
|
|
128
|
+
function consumedKeys(template, usage) {
|
|
129
|
+
const used = new Set();
|
|
130
|
+
const scan = (node) => {
|
|
131
|
+
if (node.type === 'component') {
|
|
132
|
+
for (const m of node.content.matchAll(/\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}/g))
|
|
133
|
+
used.add(m[1]);
|
|
134
|
+
}
|
|
135
|
+
if (!isContainer(node))
|
|
136
|
+
return;
|
|
137
|
+
for (const child of node.children)
|
|
138
|
+
scan(child);
|
|
139
|
+
for (const list of Object.values(node.slots))
|
|
140
|
+
for (const child of list)
|
|
141
|
+
scan(child);
|
|
142
|
+
};
|
|
143
|
+
scan(template);
|
|
144
|
+
return Object.keys(usage).filter((k) => used.has(k));
|
|
145
|
+
}
|
|
146
|
+
/** Deep clone, with fresh ids so two instances of the same template never collide */
|
|
147
|
+
function cloneNode(node) {
|
|
148
|
+
const copy = { ...node };
|
|
149
|
+
if (isContainer(copy)) {
|
|
150
|
+
copy.children = copy.children.map((c) => cloneNode(c));
|
|
151
|
+
const slots = {};
|
|
152
|
+
for (const [k, list] of Object.entries(copy.slots))
|
|
153
|
+
slots[k] = list.map((c) => cloneNode(c));
|
|
154
|
+
copy.slots = slots;
|
|
155
|
+
}
|
|
156
|
+
if (copy.type === 'component') {
|
|
157
|
+
copy.attrs = { ...copy.attrs };
|
|
158
|
+
// states must be deep-copied: two instances of the same template must not share one map, or
|
|
159
|
+
// applying a state to one would silently change the other
|
|
160
|
+
if (copy.states) {
|
|
161
|
+
const states = {};
|
|
162
|
+
for (const [k, v] of Object.entries(copy.states))
|
|
163
|
+
states[k] = { ...v };
|
|
164
|
+
copy.states = states;
|
|
165
|
+
}
|
|
166
|
+
// rawTail must NOT survive the clone: L2 re-splits it against the data scope, which would
|
|
167
|
+
// resurrect the template's original `{label}` attribute and undo bindPlaceholders. The clone
|
|
168
|
+
// carries its attributes directly, so the re-split path is not needed.
|
|
169
|
+
delete copy.rawTail;
|
|
170
|
+
if (copy.rows)
|
|
171
|
+
copy.rows = copy.rows.map((r) => [...r]);
|
|
172
|
+
if (copy.tokens)
|
|
173
|
+
copy.tokens = { ...copy.tokens };
|
|
174
|
+
}
|
|
175
|
+
return copy;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Rewrite `{{name}}` placeholders inside a cloned template body.
|
|
179
|
+
*
|
|
180
|
+
* A template needs a way to say "the caller's text goes here" that is unambiguous. `{name}` is
|
|
181
|
+
* already taken (it is the attribute-block syntax, and `{primary}` must keep working as a flag),
|
|
182
|
+
* and `{expr}` is the L2 interpolation syntax. So a template uses `{{name}}` - a double brace -
|
|
183
|
+
* which the lexer passes through as literal text and only this module interprets.
|
|
184
|
+
*
|
|
185
|
+
* Keys the caller passed are substituted immediately, because the caller's attributes live on the
|
|
186
|
+
* usage node and L2 has no way to see them. Keys the caller did not pass stay as `{name}` so L2
|
|
187
|
+
* resolves them against the data scope (a `@for` variable, say).
|
|
188
|
+
*/
|
|
189
|
+
function bindPlaceholders(node, usage) {
|
|
190
|
+
if (node.type === 'component') {
|
|
191
|
+
const rewritten = node.content.replace(/\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}/g, (_whole, key) => key in usage ? String(usage[key]) : `{${key}}`);
|
|
192
|
+
if (rewritten !== node.content)
|
|
193
|
+
node.content = rewritten;
|
|
194
|
+
}
|
|
195
|
+
if (!isContainer(node))
|
|
196
|
+
return;
|
|
197
|
+
for (const child of node.children)
|
|
198
|
+
bindPlaceholders(child, usage);
|
|
199
|
+
for (const list of Object.values(node.slots))
|
|
200
|
+
for (const child of list)
|
|
201
|
+
bindPlaceholders(child, usage);
|
|
202
|
+
}
|
|
203
|
+
/** Guard against a template that expands into itself, which would loop forever */
|
|
204
|
+
export function checkDefCycles(page) {
|
|
205
|
+
const defs = page.defs ?? {};
|
|
206
|
+
const visiting = new Set();
|
|
207
|
+
const done = new Set();
|
|
208
|
+
const visit = (name, chain) => {
|
|
209
|
+
if (done.has(name))
|
|
210
|
+
return;
|
|
211
|
+
if (visiting.has(name)) {
|
|
212
|
+
throw new DesignMockdownError(`"@${name}" expands into itself`, { line: defs[name]?.pos.line ?? 1, col: 1 }, `cycle: ${[...chain, name].join(' -> ')}`);
|
|
213
|
+
}
|
|
214
|
+
visiting.add(name);
|
|
215
|
+
const body = defs[name];
|
|
216
|
+
if (body)
|
|
217
|
+
for (const child of body.children)
|
|
218
|
+
scan(child, [...chain, name]);
|
|
219
|
+
visiting.delete(name);
|
|
220
|
+
done.add(name);
|
|
221
|
+
};
|
|
222
|
+
const scan = (node, chain) => {
|
|
223
|
+
if (node.type === 'component' && defs[node.name])
|
|
224
|
+
visit(node.name, chain);
|
|
225
|
+
if (isContainer(node))
|
|
226
|
+
for (const c of node.children)
|
|
227
|
+
scan(c, chain);
|
|
228
|
+
};
|
|
229
|
+
for (const name of Object.keys(defs))
|
|
230
|
+
visit(name, []);
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/core/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,IAAc;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAA;IAC5B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAM;IAE1C,MAAM,IAAI,GAAG,CAAC,IAAmB,EAAQ,EAAE;QACzC,MAAM,GAAG,GAAc,EAAE,CAAA;QACzB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC9E,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;gBACjD,SAAQ;YACV,CAAC;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..."), which is fine for a terminal and
|
|
5
|
+
* useless for anything else: an editor cannot underline a string, and an LLM repairing its own
|
|
6
|
+
* output cannot act on prose. Every producer now emits a Diagnostic, and `formatDiagnostic`
|
|
7
|
+
* reproduces the old text byte for byte so the CLI and the workbench keep their output.
|
|
8
|
+
*/
|
|
9
|
+
import { DesignMockdownError, type Pos } from './errors.ts';
|
|
10
|
+
export type Severity = 'error' | 'warning' | 'info';
|
|
11
|
+
export interface Diagnostic {
|
|
12
|
+
severity: Severity;
|
|
13
|
+
/** Stable code, so a consumer can branch on the kind without matching the message */
|
|
14
|
+
code: string;
|
|
15
|
+
/** Human message without the "line N:" prefix; the position lives in `pos` */
|
|
16
|
+
message: string;
|
|
17
|
+
pos?: Pos;
|
|
18
|
+
hint?: string;
|
|
19
|
+
/** Page title, filled in by the resolver so a multi-page file says where to look */
|
|
20
|
+
page?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The code catalogue.
|
|
24
|
+
*
|
|
25
|
+
* Codes are grouped by layer (1xxx input, 2xxx expansion, 3xxx validation, 4xxx state) so a
|
|
26
|
+
* consumer can tell "fix your syntax" from "fix your values" without a lookup table.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CODES: {
|
|
29
|
+
/** Anything that has not been given a specific code yet */
|
|
30
|
+
readonly generic: "DM0001";
|
|
31
|
+
readonly parse: "DM1001";
|
|
32
|
+
readonly unknownComponent: "DM1002";
|
|
33
|
+
readonly duplicateId: "DM1003";
|
|
34
|
+
readonly canvas: "DM1004";
|
|
35
|
+
/** @if / @for could not be evaluated */
|
|
36
|
+
readonly expansion: "DM2001";
|
|
37
|
+
/** {expr} interpolation failed */
|
|
38
|
+
readonly interpolation: "DM2002";
|
|
39
|
+
/** enum-valued attribute got an unknown value */
|
|
40
|
+
readonly enumValue: "DM3001";
|
|
41
|
+
/** grid cell span is not a positive integer */
|
|
42
|
+
readonly cellSpan: "DM3002";
|
|
43
|
+
/** a requested @state does not exist */
|
|
44
|
+
readonly state: "DM4001";
|
|
45
|
+
};
|
|
46
|
+
/** The text form the CLI and the workbench print */
|
|
47
|
+
export declare function formatDiagnostic(d: Diagnostic): string;
|
|
48
|
+
/**
|
|
49
|
+
* Convert an error into a diagnostic.
|
|
50
|
+
*
|
|
51
|
+
* Kept here rather than as a method on the error so `errors.ts` stays free of the diagnostic
|
|
52
|
+
* vocabulary: a lexer error should not have to know what a diagnostic is.
|
|
53
|
+
*/
|
|
54
|
+
export declare function errorToDiagnostic(err: DesignMockdownError, page?: string): Diagnostic;
|
|
55
|
+
/**
|
|
56
|
+
* Recover a position from a legacy preformatted warning.
|
|
57
|
+
*
|
|
58
|
+
* The expansion and state layers still return strings (their callers and tests read them). Rather
|
|
59
|
+
* than rewrite those layers in the same change, the strings are upgraded here: `line 12: ...`
|
|
60
|
+
* becomes `pos: {line: 12}` and the message loses the prefix, so JSON output is structured even
|
|
61
|
+
* for the parts that have not been migrated yet.
|
|
62
|
+
*/
|
|
63
|
+
export declare function fromLegacyWarning(text: string, code: string): Diagnostic;
|
|
64
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../../src/core/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAA;AAE3D,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;AAEnD,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,QAAQ,CAAA;IAClB,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAA;IACZ,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK;IAChB,2DAA2D;;;;;;IAM3D,wCAAwC;;IAExC,kCAAkC;;IAElC,iDAAiD;;IAEjD,+CAA+C;;IAE/C,wCAAwC;;CAEhC,CAAA;AAEV,oDAAoD;AACpD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAGtD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,mBAAmB,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAErF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAIxE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* Warnings used to be preformatted strings ("line 12: ..."), which is fine for a terminal and
|
|
5
|
+
* useless for anything else: an editor cannot underline a string, and an LLM repairing its own
|
|
6
|
+
* output cannot act on prose. Every producer now emits a Diagnostic, and `formatDiagnostic`
|
|
7
|
+
* reproduces the old text byte for byte so the CLI and the workbench keep their output.
|
|
8
|
+
*/
|
|
9
|
+
import { DesignMockdownError } from "./errors.js";
|
|
10
|
+
/**
|
|
11
|
+
* The code catalogue.
|
|
12
|
+
*
|
|
13
|
+
* Codes are grouped by layer (1xxx input, 2xxx expansion, 3xxx validation, 4xxx state) so a
|
|
14
|
+
* consumer can tell "fix your syntax" from "fix your values" without a lookup table.
|
|
15
|
+
*/
|
|
16
|
+
export const CODES = {
|
|
17
|
+
/** Anything that has not been given a specific code yet */
|
|
18
|
+
generic: 'DM0001',
|
|
19
|
+
parse: 'DM1001',
|
|
20
|
+
unknownComponent: 'DM1002',
|
|
21
|
+
duplicateId: 'DM1003',
|
|
22
|
+
canvas: 'DM1004',
|
|
23
|
+
/** @if / @for could not be evaluated */
|
|
24
|
+
expansion: 'DM2001',
|
|
25
|
+
/** {expr} interpolation failed */
|
|
26
|
+
interpolation: 'DM2002',
|
|
27
|
+
/** enum-valued attribute got an unknown value */
|
|
28
|
+
enumValue: 'DM3001',
|
|
29
|
+
/** grid cell span is not a positive integer */
|
|
30
|
+
cellSpan: 'DM3002',
|
|
31
|
+
/** a requested @state does not exist */
|
|
32
|
+
state: 'DM4001',
|
|
33
|
+
};
|
|
34
|
+
/** The text form the CLI and the workbench print */
|
|
35
|
+
export function formatDiagnostic(d) {
|
|
36
|
+
const where = d.pos ? `line ${d.pos.line}: ` : '';
|
|
37
|
+
return `${where}${d.message}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert an error into a diagnostic.
|
|
41
|
+
*
|
|
42
|
+
* Kept here rather than as a method on the error so `errors.ts` stays free of the diagnostic
|
|
43
|
+
* vocabulary: a lexer error should not have to know what a diagnostic is.
|
|
44
|
+
*/
|
|
45
|
+
export function errorToDiagnostic(err, page) {
|
|
46
|
+
return { severity: 'error', code: err.code, message: err.message, pos: err.pos, hint: err.hint, page };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recover a position from a legacy preformatted warning.
|
|
50
|
+
*
|
|
51
|
+
* The expansion and state layers still return strings (their callers and tests read them). Rather
|
|
52
|
+
* than rewrite those layers in the same change, the strings are upgraded here: `line 12: ...`
|
|
53
|
+
* becomes `pos: {line: 12}` and the message loses the prefix, so JSON output is structured even
|
|
54
|
+
* for the parts that have not been migrated yet.
|
|
55
|
+
*/
|
|
56
|
+
export function fromLegacyWarning(text, code) {
|
|
57
|
+
const m = /^line (\d+):\s?([\s\S]*)$/.exec(text);
|
|
58
|
+
if (!m)
|
|
59
|
+
return { severity: 'warning', code, message: text };
|
|
60
|
+
return { severity: 'warning', code, message: m[2], pos: { line: Number(m[1]), col: 1 } };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceR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AAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAC3D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAA;AAC1F,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DesignMockdown error system.
|
|
3
|
+
* Every parse/validation error carries a source position; the CLI prints a source frame plus a fix hint.
|
|
4
|
+
*/
|
|
5
|
+
export interface Pos {
|
|
6
|
+
/** 1-based line number */
|
|
7
|
+
line: number;
|
|
8
|
+
/** 1-based column number */
|
|
9
|
+
col: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class DesignMockdownError extends Error {
|
|
12
|
+
readonly pos?: Pos;
|
|
13
|
+
readonly hint?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Stable diagnostic code (see diagnostics.ts). Defaults to the generic code so the ~60 throw
|
|
16
|
+
* sites do not all have to grow a fourth argument on the day the field is introduced.
|
|
17
|
+
*/
|
|
18
|
+
readonly code: string;
|
|
19
|
+
constructor(message: string, pos?: Pos, hint?: string, code?: string);
|
|
20
|
+
}
|
|
21
|
+
/** Edit distance, powers the "did you mean xxx" hint */
|
|
22
|
+
export declare function levenshtein(a: string, b: string): number;
|
|
23
|
+
/** Find the closest matches among a set of candidates */
|
|
24
|
+
export declare function suggest(word: string, candidates: readonly string[], max?: number): string[];
|
|
25
|
+
/** Format an error as multi-line text with a source frame */
|
|
26
|
+
export declare function formatError(err: DesignMockdownError, source: string, file?: string): string;
|
|
27
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,GAAG;IAClB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAA;IAClB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBAET,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,SAAW;CAOvE;AAED,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAmBxD;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,SAAI,GAAG,MAAM,EAAE,CAOtF;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,SAAa,GAAG,MAAM,CAa/F"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DesignMockdown error system.
|
|
3
|
+
* Every parse/validation error carries a source position; the CLI prints a source frame plus a fix hint.
|
|
4
|
+
*/
|
|
5
|
+
export class DesignMockdownError extends Error {
|
|
6
|
+
pos;
|
|
7
|
+
hint;
|
|
8
|
+
/**
|
|
9
|
+
* Stable diagnostic code (see diagnostics.ts). Defaults to the generic code so the ~60 throw
|
|
10
|
+
* sites do not all have to grow a fourth argument on the day the field is introduced.
|
|
11
|
+
*/
|
|
12
|
+
code;
|
|
13
|
+
constructor(message, pos, hint, code = 'DM0001') {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'DesignMockdownError';
|
|
16
|
+
this.pos = pos;
|
|
17
|
+
this.hint = hint;
|
|
18
|
+
this.code = code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Edit distance, powers the "did you mean xxx" hint */
|
|
22
|
+
export function levenshtein(a, b) {
|
|
23
|
+
const m = a.length;
|
|
24
|
+
const n = b.length;
|
|
25
|
+
if (m === 0)
|
|
26
|
+
return n;
|
|
27
|
+
if (n === 0)
|
|
28
|
+
return m;
|
|
29
|
+
let prev = new Array(n + 1);
|
|
30
|
+
let cur = new Array(n + 1);
|
|
31
|
+
for (let j = 0; j <= n; j++)
|
|
32
|
+
prev[j] = j;
|
|
33
|
+
for (let i = 1; i <= m; i++) {
|
|
34
|
+
cur[0] = i;
|
|
35
|
+
for (let j = 1; j <= n; j++) {
|
|
36
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
37
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost);
|
|
38
|
+
}
|
|
39
|
+
const tmp = prev;
|
|
40
|
+
prev = cur;
|
|
41
|
+
cur = tmp;
|
|
42
|
+
}
|
|
43
|
+
return prev[n];
|
|
44
|
+
}
|
|
45
|
+
/** Find the closest matches among a set of candidates */
|
|
46
|
+
export function suggest(word, candidates, max = 3) {
|
|
47
|
+
const scored = candidates
|
|
48
|
+
.map((c) => ({ c, d: levenshtein(word.toLowerCase(), c.toLowerCase()) }))
|
|
49
|
+
.filter((s) => s.d <= Math.max(2, Math.floor(s.c.length / 2)))
|
|
50
|
+
.sort((a, b) => a.d - b.d)
|
|
51
|
+
.slice(0, max);
|
|
52
|
+
return scored.map((s) => s.c);
|
|
53
|
+
}
|
|
54
|
+
/** Format an error as multi-line text with a source frame */
|
|
55
|
+
export function formatError(err, source, file = 'input.dm') {
|
|
56
|
+
const out = [];
|
|
57
|
+
out.push(err.pos ? `${file}:${err.pos.line}:${err.pos.col}` : file);
|
|
58
|
+
if (err.pos) {
|
|
59
|
+
const srcLine = source.split(/\r?\n/)[err.pos.line - 1] ?? '';
|
|
60
|
+
const no = String(err.pos.line);
|
|
61
|
+
const pad = ' '.repeat(no.length);
|
|
62
|
+
out.push(` ${no} | ${srcLine}`);
|
|
63
|
+
out.push(` ${pad} | ${' '.repeat(Math.max(0, err.pos.col - 1))}^`);
|
|
64
|
+
}
|
|
65
|
+
out.push(`error: ${err.message}`);
|
|
66
|
+
if (err.hint)
|
|
67
|
+
out.push(`hint: ${err.hint}`);
|
|
68
|
+
return out.join('\n');
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,GAAG,CAAM;IACT,IAAI,CAAS;IACtB;;;OAGG;IACM,IAAI,CAAQ;IAErB,YAAY,OAAe,EAAE,GAAS,EAAE,IAAa,EAAE,IAAI,GAAG,QAAQ;QACpE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;QACjC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,wDAAwD;AACxD,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS;IAC9C,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAA;IAClB,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAA;IAClB,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IACrB,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IACrB,IAAI,IAAI,GAAG,IAAI,KAAK,CAAS,CAAC,GAAG,CAAC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,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACrE,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IACjC,IAAI,GAAG,CAAC,IAAI;QAAE,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAC3C,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L2 expansion: data binding, `@if` / `@for` and `{}` interpolation.
|
|
3
|
+
*
|
|
4
|
+
* Runs between parse and resolve, and produces a plain AST with no control-flow nodes left.
|
|
5
|
+
* Layout and both renderers therefore never learn that L2 exists.
|
|
6
|
+
*
|
|
7
|
+
* Two rules shape the whole module:
|
|
8
|
+
* 1. A half-finished design draft must still render. A missing variable or a malformed
|
|
9
|
+
* expression keeps the original text and records a warning - it never throws.
|
|
10
|
+
* 2. Ids must stay unique and deterministic. `@for` clones its subtree once per item, so every
|
|
11
|
+
* clone gets `${varName}-${index}-${baseId}`; ids anchor animation targets, event binding,
|
|
12
|
+
* test selectors and collab presence, so a collision is a correctness bug, not cosmetics.
|
|
13
|
+
*/
|
|
14
|
+
import type { PageNode } from './ast.ts';
|
|
15
|
+
export interface ExpandResult {
|
|
16
|
+
page: PageNode;
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
/** Expand control flow and interpolate every `{}` reference against the page's data scope */
|
|
20
|
+
export declare function expand(page: PageNode): ExpandResult;
|
|
21
|
+
//# sourceMappingURL=expand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../../../src/core/expand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAA0C,QAAQ,EAAE,MAAM,UAAU,CAAA;AAMhF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,6FAA6F;AAC7F,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAwFnD"}
|