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,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component registry: the single entry point for every component, built-in or registered.
|
|
3
|
+
*
|
|
4
|
+
* Built-ins are declared in the sibling files and grouped here; plugins arrive at runtime through
|
|
5
|
+
* `registerComponent`. Both share one lookup table, so a registered component is visible to
|
|
6
|
+
* validation, layout, rendering, the palette and the schema at the same moment.
|
|
7
|
+
*
|
|
8
|
+
* Registration happens at start-up, before anything parses (see components/plugin.ts and
|
|
9
|
+
* components/config.ts). That ordering is what keeps "same input, same output" true: the table is
|
|
10
|
+
* fixed for the whole life of the process, exactly like the built-in one used to be.
|
|
11
|
+
*/
|
|
12
|
+
import { DesignMockdownError } from "../core/errors.js";
|
|
13
|
+
import { BASIC_COMPONENTS } from "./basic.js";
|
|
14
|
+
import { CONTROL_COMPONENTS } from "./controls.js";
|
|
15
|
+
import { NAV_COMPONENTS } from "./nav.js";
|
|
16
|
+
import { DATA_COMPONENTS } from "./data.js";
|
|
17
|
+
import { FEEDBACK_COMPONENTS } from "./feedback.js";
|
|
18
|
+
import { LAYOUT_COMPONENTS } from "./layout.js";
|
|
19
|
+
import { CONTAINER_COMPONENTS } from "./containers.js";
|
|
20
|
+
/**
|
|
21
|
+
* Palette sections, in the order the panel shows them.
|
|
22
|
+
*
|
|
23
|
+
* The grouping lives here rather than on each definition: the source files already encode it, and
|
|
24
|
+
* a second copy per component would drift the moment one of them is moved.
|
|
25
|
+
*/
|
|
26
|
+
const GROUPS = [
|
|
27
|
+
{ category: 'layout', label: '布局', list: BASIC_COMPONENTS.filter((d) => ['box', 'row', 'col', 'grid', 'divider', 'spacer'].includes(d.name)) },
|
|
28
|
+
{ category: 'content', label: '内容', list: BASIC_COMPONENTS.filter((d) => !['box', 'row', 'col', 'grid', 'divider', 'spacer'].includes(d.name)) },
|
|
29
|
+
{ category: 'layout', label: '容器', list: [...LAYOUT_COMPONENTS, ...CONTAINER_COMPONENTS] },
|
|
30
|
+
{ category: 'form', label: '控件', list: CONTROL_COMPONENTS },
|
|
31
|
+
{ category: 'nav', label: '导航', list: NAV_COMPONENTS },
|
|
32
|
+
{ category: 'data', label: '数据', list: DATA_COMPONENTS },
|
|
33
|
+
{ category: 'feedback', label: '反馈', list: FEEDBACK_COMPONENTS },
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Inline content each component renders with in the palette thumbnail.
|
|
37
|
+
*
|
|
38
|
+
* A thumbnail of a bare `@button` is an empty rounded rectangle, which tells the user nothing; a
|
|
39
|
+
* label does. Components that draw no text are simply absent from the map.
|
|
40
|
+
*/
|
|
41
|
+
const SAMPLES = {
|
|
42
|
+
text: '标题文字',
|
|
43
|
+
code: 'const a = 1',
|
|
44
|
+
quote: '引用的一段话',
|
|
45
|
+
icon: 'star',
|
|
46
|
+
button: '按钮',
|
|
47
|
+
fab: '+',
|
|
48
|
+
input: '请输入内容',
|
|
49
|
+
textarea: '多行文本',
|
|
50
|
+
select: '请选择',
|
|
51
|
+
checkbox: '同意条款',
|
|
52
|
+
radio: '选项一',
|
|
53
|
+
switch: '开关',
|
|
54
|
+
stepper: '数量',
|
|
55
|
+
search: '搜索',
|
|
56
|
+
segmented: '选项',
|
|
57
|
+
navbar: '页面标题',
|
|
58
|
+
breadcrumb: '首页 / 列表',
|
|
59
|
+
pagination: '‹ 1 2 3 ›',
|
|
60
|
+
menu: '菜单项',
|
|
61
|
+
drawer: '抽屉',
|
|
62
|
+
steps: '第一步',
|
|
63
|
+
tabs: '标签页',
|
|
64
|
+
accordion: '折叠面板',
|
|
65
|
+
card: '卡片标题',
|
|
66
|
+
stat: '1,286',
|
|
67
|
+
avatar: 'A',
|
|
68
|
+
badge: '12',
|
|
69
|
+
tag: '标签',
|
|
70
|
+
timeline: '事件',
|
|
71
|
+
calendar: '日历',
|
|
72
|
+
toast: '操作成功',
|
|
73
|
+
modal: '对话框标题',
|
|
74
|
+
alert: '提示信息',
|
|
75
|
+
loading: '加载中',
|
|
76
|
+
empty: '暂无数据',
|
|
77
|
+
tabbar: '首页',
|
|
78
|
+
sidebar: '导航',
|
|
79
|
+
form: '表单',
|
|
80
|
+
};
|
|
81
|
+
const ALL = GROUPS.flatMap((g) => g.list);
|
|
82
|
+
/** Which section a component belongs to; duplicate names cannot happen, the registry keys by name */
|
|
83
|
+
const GROUP_OF = new Map();
|
|
84
|
+
for (const g of GROUPS)
|
|
85
|
+
for (const d of g.list)
|
|
86
|
+
GROUP_OF.set(d.name, { category: g.category, label: g.label });
|
|
87
|
+
const BY_NAME = new Map(ALL.map((d) => [d.name, d]));
|
|
88
|
+
/** The built-in table as it was before any registration, so a removed override can be restored */
|
|
89
|
+
const ORIGINAL = new Map(BY_NAME);
|
|
90
|
+
const PLUGINS = new Map();
|
|
91
|
+
/** name -> what it extends, kept for cycle detection and for error messages that name the chain */
|
|
92
|
+
const PARENT = new Map();
|
|
93
|
+
let version = 0;
|
|
94
|
+
export function getComponent(name) {
|
|
95
|
+
return BY_NAME.get(name);
|
|
96
|
+
}
|
|
97
|
+
export function hasComponent(name) {
|
|
98
|
+
return BY_NAME.has(name);
|
|
99
|
+
}
|
|
100
|
+
export function componentNames() {
|
|
101
|
+
// Map iteration keeps insertion order: built-ins first, then registration order
|
|
102
|
+
return [...BY_NAME.keys()];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Bumped on every registration and removal.
|
|
106
|
+
*
|
|
107
|
+
* Downstream caches key on it. The palette renders each component thumbnail once and would
|
|
108
|
+
* otherwise keep showing the old artwork for a name a plugin has just replaced.
|
|
109
|
+
*/
|
|
110
|
+
export function registryVersion() {
|
|
111
|
+
return version;
|
|
112
|
+
}
|
|
113
|
+
/** Palette section for registered components, shown only when at least one exists */
|
|
114
|
+
export const PLUGIN_GROUP = '扩展组件';
|
|
115
|
+
/** Plugin contract version; raised only by a breaking change to ComponentPlugin */
|
|
116
|
+
export const PLUGIN_API = 1;
|
|
117
|
+
const NAME_RE = /^[A-Za-z][A-Za-z0-9-]*$/;
|
|
118
|
+
/** Smallest edit distance, used for spelling suggestions on a bad `extends` target */
|
|
119
|
+
function closest(input, candidates) {
|
|
120
|
+
let best;
|
|
121
|
+
let bestScore = Infinity;
|
|
122
|
+
for (const c of candidates) {
|
|
123
|
+
const d = editDistance(input, c);
|
|
124
|
+
if (d < bestScore) {
|
|
125
|
+
bestScore = d;
|
|
126
|
+
best = c;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return bestScore <= Math.max(2, Math.floor(input.length / 3)) ? best : undefined;
|
|
130
|
+
}
|
|
131
|
+
function editDistance(a, b) {
|
|
132
|
+
const row = new Array(b.length + 1);
|
|
133
|
+
for (let j = 0; j <= b.length; j++)
|
|
134
|
+
row[j] = j;
|
|
135
|
+
for (let i = 1; i <= a.length; i++) {
|
|
136
|
+
let diag = row[0];
|
|
137
|
+
row[0] = i;
|
|
138
|
+
for (let j = 1; j <= b.length; j++) {
|
|
139
|
+
const above = row[j];
|
|
140
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
141
|
+
diag = above;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return row[b.length];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Register one component.
|
|
148
|
+
*
|
|
149
|
+
* Every check runs here rather than at render time: a plugin that is wrong should fail the moment
|
|
150
|
+
* it is loaded, with the plugin's own name in the message, not three renders later with a
|
|
151
|
+
* "cannot read properties of undefined" from somewhere inside the layout engine.
|
|
152
|
+
*/
|
|
153
|
+
export function registerComponent(def, opts = {}) {
|
|
154
|
+
const api = def.api ?? PLUGIN_API;
|
|
155
|
+
if (api > PLUGIN_API) {
|
|
156
|
+
throw new DesignMockdownError(`plugin "@${def.name}" needs plugin API ${api}, this build supports ${PLUGIN_API}`, undefined, 'upgrade designmockdown, or use an older version of the plugin');
|
|
157
|
+
}
|
|
158
|
+
if (!NAME_RE.test(def.name)) {
|
|
159
|
+
throw new DesignMockdownError(`invalid component name "${def.name}"`, undefined, 'component names use letters, digits and dashes, and start with a letter');
|
|
160
|
+
}
|
|
161
|
+
if (BY_NAME.has(def.name) && !opts.override) {
|
|
162
|
+
throw new DesignMockdownError(`component "@${def.name}" already exists`, undefined, 'pass { override: true } to replace it');
|
|
163
|
+
}
|
|
164
|
+
let base;
|
|
165
|
+
if (def.extends) {
|
|
166
|
+
base = BY_NAME.get(def.extends);
|
|
167
|
+
if (!base) {
|
|
168
|
+
const names = componentNames();
|
|
169
|
+
const guess = closest(def.extends, names);
|
|
170
|
+
throw new DesignMockdownError(`"@${def.name}" extends "@${def.extends}", which is not a component`, undefined, guess ? `did you mean "@${guess}"?` : `available: ${names.slice(0, 12).join(', ')}…`);
|
|
171
|
+
}
|
|
172
|
+
// Bases are flattened at registration, so the chain below is usually one hop. Re-registering a
|
|
173
|
+
// name with override is the one way it can close into a loop, and that is what this walk catches.
|
|
174
|
+
const chain = [def.name];
|
|
175
|
+
let cursor = def.extends;
|
|
176
|
+
while (cursor) {
|
|
177
|
+
chain.push(cursor);
|
|
178
|
+
if (cursor === def.name) {
|
|
179
|
+
throw new DesignMockdownError(`"@${chain[0]}" extends itself: ${chain.map((n) => `@${n}`).join(' extends ')}`, undefined, 'remove one of the extends in the chain');
|
|
180
|
+
}
|
|
181
|
+
cursor = PARENT.get(cursor);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const render = def.render ?? base?.render;
|
|
185
|
+
if (!render) {
|
|
186
|
+
throw new DesignMockdownError(`"@${def.name}" has no render function`, undefined, 'a plugin must provide render(), or extend a component that has one');
|
|
187
|
+
}
|
|
188
|
+
const merged = { ...(base ?? {}), name: def.name, render };
|
|
189
|
+
// Defaults merge shallowly: a derived component keeps its base's attributes and only adds to them
|
|
190
|
+
if (def.defaults || base?.defaults)
|
|
191
|
+
merged.defaults = { ...(base?.defaults ?? {}), ...(def.defaults ?? {}) };
|
|
192
|
+
if (def.intrinsic)
|
|
193
|
+
merged.intrinsic = def.intrinsic;
|
|
194
|
+
if (def.textAsChild !== undefined)
|
|
195
|
+
merged.textAsChild = def.textAsChild;
|
|
196
|
+
if (def.dom)
|
|
197
|
+
merged.dom = def.dom;
|
|
198
|
+
if (def.react)
|
|
199
|
+
merged.react = def.react;
|
|
200
|
+
if (def.doc !== undefined)
|
|
201
|
+
merged.doc = def.doc;
|
|
202
|
+
BY_NAME.set(def.name, merged);
|
|
203
|
+
if (def.extends)
|
|
204
|
+
PARENT.set(def.name, def.extends);
|
|
205
|
+
else
|
|
206
|
+
PARENT.delete(def.name);
|
|
207
|
+
PLUGINS.set(def.name, {
|
|
208
|
+
group: def.group,
|
|
209
|
+
category: def.category,
|
|
210
|
+
sample: def.sample,
|
|
211
|
+
preview: def.preview,
|
|
212
|
+
container: def.container,
|
|
213
|
+
doc: def.doc,
|
|
214
|
+
});
|
|
215
|
+
version++;
|
|
216
|
+
}
|
|
217
|
+
export function registerComponents(defs, opts = {}) {
|
|
218
|
+
for (const def of defs)
|
|
219
|
+
registerComponent(def, opts);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Remove a registered component. Returns false for built-ins: a built-in has no plugin to undo,
|
|
223
|
+
* and silently deleting one would leave documents that render today failing tomorrow.
|
|
224
|
+
*/
|
|
225
|
+
export function unregisterComponent(name) {
|
|
226
|
+
if (!PLUGINS.has(name))
|
|
227
|
+
return false;
|
|
228
|
+
PLUGINS.delete(name);
|
|
229
|
+
PARENT.delete(name);
|
|
230
|
+
const original = ORIGINAL.get(name);
|
|
231
|
+
if (original)
|
|
232
|
+
BY_NAME.set(name, original);
|
|
233
|
+
else
|
|
234
|
+
BY_NAME.delete(name);
|
|
235
|
+
version++;
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
/** Back to built-ins only. Tests use it; a long-running host can use it to unload a plugin set */
|
|
239
|
+
export function resetComponents() {
|
|
240
|
+
for (const name of [...PLUGINS.keys()])
|
|
241
|
+
unregisterComponent(name);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Register for the duration of one call, then restore the previous table.
|
|
245
|
+
*
|
|
246
|
+
* The registry is a singleton, so "load these plugins for this document only" cannot be expressed
|
|
247
|
+
* by loading and unloading by hand: an exception in between would leave the process with
|
|
248
|
+
* components it did not start with. The snapshot lives in a finally for that reason.
|
|
249
|
+
*/
|
|
250
|
+
export function withComponents(defs, fn) {
|
|
251
|
+
const snapshot = {
|
|
252
|
+
byName: new Map(BY_NAME),
|
|
253
|
+
plugins: new Map(PLUGINS),
|
|
254
|
+
parent: new Map(PARENT),
|
|
255
|
+
version,
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
registerComponents(defs);
|
|
259
|
+
return fn();
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
BY_NAME.clear();
|
|
263
|
+
for (const [k, v] of snapshot.byName)
|
|
264
|
+
BY_NAME.set(k, v);
|
|
265
|
+
PLUGINS.clear();
|
|
266
|
+
for (const [k, v] of snapshot.plugins)
|
|
267
|
+
PLUGINS.set(k, v);
|
|
268
|
+
PARENT.clear();
|
|
269
|
+
for (const [k, v] of snapshot.parent)
|
|
270
|
+
PARENT.set(k, v);
|
|
271
|
+
version = snapshot.version;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Call a plugin-supplied function, keeping the plugin's name on the error.
|
|
276
|
+
*
|
|
277
|
+
* Without this a broken hook surfaces as "Cannot read properties of undefined" from deep inside the
|
|
278
|
+
* renderer, and the author has no idea which plugin to look at.
|
|
279
|
+
*/
|
|
280
|
+
export function callPlugin(name, what, fn) {
|
|
281
|
+
try {
|
|
282
|
+
return fn();
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
if (e instanceof DesignMockdownError)
|
|
286
|
+
throw e;
|
|
287
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
288
|
+
throw new DesignMockdownError(`plugin "@${name}" failed in ${what}(): ${detail}`, undefined, 'fix the plugin, or drop it from --components');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/** Components whose point is to contain something, used by the canvas drop rule */
|
|
292
|
+
const CONTAINERS = new Set([
|
|
293
|
+
'box',
|
|
294
|
+
'row',
|
|
295
|
+
'col',
|
|
296
|
+
'grid',
|
|
297
|
+
'scroll',
|
|
298
|
+
'stack',
|
|
299
|
+
'sidebar',
|
|
300
|
+
'form',
|
|
301
|
+
'card',
|
|
302
|
+
'tabs',
|
|
303
|
+
'accordion',
|
|
304
|
+
'modal',
|
|
305
|
+
'drawer',
|
|
306
|
+
]);
|
|
307
|
+
/** Used by `designmockdown schema`, the palette, and error hints */
|
|
308
|
+
export function componentSummaries() {
|
|
309
|
+
return [...BY_NAME.entries()].map(([name, d]) => ({
|
|
310
|
+
name,
|
|
311
|
+
attrs: Object.keys(d.defaults ?? {}),
|
|
312
|
+
category: GROUP_OF.get(name)?.category ?? PLUGINS.get(name)?.category ?? 'content',
|
|
313
|
+
// A plugin joins its own section unless it asked for one, so a pack of related components
|
|
314
|
+
// groups together instead of scattering through the built-in sections
|
|
315
|
+
group: GROUP_OF.get(name)?.label ?? PLUGINS.get(name)?.group ?? PLUGIN_GROUP,
|
|
316
|
+
sample: SAMPLES[name] ?? PLUGINS.get(name)?.sample ?? '',
|
|
317
|
+
container: CONTAINERS.has(name) || PLUGINS.get(name)?.container === true,
|
|
318
|
+
preview: PREVIEWS[name] ?? PLUGINS.get(name)?.preview,
|
|
319
|
+
origin: PLUGINS.has(name) ? 'plugin' : 'builtin',
|
|
320
|
+
backends: componentBackends(name, d),
|
|
321
|
+
doc: PLUGINS.get(name)?.doc ?? d.doc,
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Which backends draw this component's own artwork.
|
|
326
|
+
*
|
|
327
|
+
* Built-ins have a branch in dom.ts and react.ts by definition; a plugin only has what it brought.
|
|
328
|
+
*/
|
|
329
|
+
function componentBackends(name, def) {
|
|
330
|
+
const out = ['svg'];
|
|
331
|
+
if (!PLUGINS.has(name) || def.dom)
|
|
332
|
+
out.push('dom');
|
|
333
|
+
if (!PLUGINS.has(name) || def.react)
|
|
334
|
+
out.push('react');
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Thumbnail bodies for the components whose default render is empty.
|
|
339
|
+
*
|
|
340
|
+
* Everything here is written with the same vocabulary a document uses - no special-casing in the
|
|
341
|
+
* renderer - so what the palette shows is what an inserted component looks like once it has content.
|
|
342
|
+
*/
|
|
343
|
+
const PREVIEWS = {
|
|
344
|
+
box: ['@box {p=10, bg=surface, rounded=8}', ' @text 内容'],
|
|
345
|
+
row: ['@row {gap=8}', ' @button 一', ' @button 二'],
|
|
346
|
+
col: ['@col {gap=8}', ' @button 一', ' @button 二'],
|
|
347
|
+
grid: ['@grid {cols=2, gap=8}', ' @card 甲', ' @card 乙', ' @card 丙', ' @card 丁'],
|
|
348
|
+
stack: ['@stack {h=92}', ' @card 底层 {p=10}', ' @card 上层 {x=16, y=14, p=10}'],
|
|
349
|
+
card: ['@card 卡片标题 {p=10}', ' @text 副标题 {size=sm}'],
|
|
350
|
+
form: ['@form {gap=8, p=10}', ' @input 手机号', ' @button 提交 {primary}'],
|
|
351
|
+
divider: ['@divider 分 隔'],
|
|
352
|
+
// A spacer is a gap: two blocks with air between them is the only honest way to draw one
|
|
353
|
+
spacer: ['@box {p=8, bg=surface, rounded=8}', ' @text 上', ' @spacer {h=14}', ' @text 下'],
|
|
354
|
+
table: ['@table {w=252}', ' | 名称 | 数量 |', ' | 咖啡 | 2 |', ' | 面包 | 1 |'],
|
|
355
|
+
drawer: ['@drawer 标题', ' @text 抽屉内容'],
|
|
356
|
+
modal: ['@modal 确认', ' @text 弹窗内容'],
|
|
357
|
+
sidebar: ['@sidebar {h=96}', ' @text 侧栏'],
|
|
358
|
+
scroll: ['@scroll {h=96}', ' @text 滚动内容'],
|
|
359
|
+
};
|
|
360
|
+
/** Palette section titles, in display order */
|
|
361
|
+
export function componentGroups() {
|
|
362
|
+
const groups = GROUPS.map((g) => ({ category: g.category, label: g.label }));
|
|
363
|
+
// Plugin sections come from the plugins themselves, in registration order. Deriving them here
|
|
364
|
+
// instead of naming a single section is what keeps a component visible: the palette drops a
|
|
365
|
+
// component whose group has no entry, so each distinct plugin label needs its own entry.
|
|
366
|
+
for (const meta of PLUGINS.values()) {
|
|
367
|
+
const label = meta.group ?? PLUGIN_GROUP;
|
|
368
|
+
if (!groups.some((g) => g.label === label))
|
|
369
|
+
groups.push({ category: meta.category ?? 'content', label });
|
|
370
|
+
}
|
|
371
|
+
return groups;
|
|
372
|
+
}
|
|
373
|
+
/** The built-in components only; registered ones are reachable through componentNames() */
|
|
374
|
+
export { ALL as ALL_COMPONENTS };
|
|
375
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/components/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAKtD;;;;;GAKG;AACH,MAAM,MAAM,GAA2E;IACrF,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,QAAQ,CA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,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC;YAAE,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1G,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,2FAA2F;AAC3F,OAAO,EAAE,GAAG,IAAI,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component definition contract.
|
|
3
|
+
* Every component = defaults + intrinsic size + render function.
|
|
4
|
+
*/
|
|
5
|
+
import type { Attrs } from '../core/ast.ts';
|
|
6
|
+
import type { LayoutBox, Style } from '../layout/types.ts';
|
|
7
|
+
import type { Theme } from '../core/tokens.ts';
|
|
8
|
+
/** Palette grouping: what the component is for, not which file it lives in */
|
|
9
|
+
export type ComponentCategory = 'layout' | 'content' | 'form' | 'nav' | 'data' | 'feedback';
|
|
10
|
+
export interface RenderContext {
|
|
11
|
+
/** Directory of the .dm file, used to resolve image paths */
|
|
12
|
+
baseDir: string;
|
|
13
|
+
theme: Theme;
|
|
14
|
+
/** Collects <defs> content (filters, gradients, clip paths) */
|
|
15
|
+
defs: string[];
|
|
16
|
+
/** Generates an id unique within the document */
|
|
17
|
+
uid: (prefix: string) => string;
|
|
18
|
+
/** Prototype mode: onclick and other interactions take effect */
|
|
19
|
+
interactive: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Edit mode: the renderer tags every box with data-mk-node so the workbench can map a canvas
|
|
22
|
+
* click back to its AST node. Off for every static export.
|
|
23
|
+
*/
|
|
24
|
+
editMode: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface IntrinsicSize {
|
|
27
|
+
width?: number;
|
|
28
|
+
height?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ComponentDef {
|
|
31
|
+
name: string;
|
|
32
|
+
/** Default attributes; user-written attributes override them */
|
|
33
|
+
defaults?: Attrs;
|
|
34
|
+
/** Intrinsic size when w/h are not given explicitly */
|
|
35
|
+
intrinsic?: (attrs: Attrs, style: Style, theme: Theme, content: string) => IntrinsicSize;
|
|
36
|
+
/** Renders itself only (children are handled by the renderer) */
|
|
37
|
+
render: (box: LayoutBox, ctx: RenderContext) => string;
|
|
38
|
+
/** true means the component places its own children/slots; the renderer stops drawing them */
|
|
39
|
+
handlesChildren?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* true means the component's inline content (`@card 标题`) is painted as a measured text child.
|
|
42
|
+
*
|
|
43
|
+
* Opt in only for pure containers: components that read box.text themselves (button, input, navbar,
|
|
44
|
+
* stat, avatar, badge, tag, alert, loading, quote, code, ...) must leave this off, or their label
|
|
45
|
+
* would be drawn twice. Leaving it off used to mean the text was dropped silently - the synthesized
|
|
46
|
+
* child box was never measured, so it rendered nothing and took no space.
|
|
47
|
+
*/
|
|
48
|
+
textAsChild?: boolean;
|
|
49
|
+
/** Palette grouping; set in registry.ts, not on the individual definitions */
|
|
50
|
+
category?: ComponentCategory;
|
|
51
|
+
/**
|
|
52
|
+
* Inline content the palette thumbnail renders with. Without it a text-bearing component
|
|
53
|
+
* (`@button` with no label, `@input` with no placeholder) draws as an empty box, which tells
|
|
54
|
+
* the user nothing about what the component does.
|
|
55
|
+
*/
|
|
56
|
+
sample?: string;
|
|
57
|
+
/** One-line description shown by `schema`; only plugins set it */
|
|
58
|
+
doc?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Semantic-backend hooks (DOM / React). Only plugins provide them.
|
|
61
|
+
*
|
|
62
|
+
* Built-ins keep their per-component branches in dom.ts / react.ts: turning those two switches
|
|
63
|
+
* into hooks would be a rewrite of both backends, and the plugin feature does not need it.
|
|
64
|
+
* Returning null (or omitting the hook) falls back to the generic box either way.
|
|
65
|
+
*/
|
|
66
|
+
dom?: (box: LayoutBox, ctx: SemanticContext) => string | null;
|
|
67
|
+
react?: (box: LayoutBox, ctx: SemanticContext) => string | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What a semantic-backend hook is given.
|
|
71
|
+
*
|
|
72
|
+
* There are no absolute coordinates here: the DOM and React backends use flexbox, so `box.x` /
|
|
73
|
+
* `box.y` are laid out by the browser. A hook expresses structure and style, never a position.
|
|
74
|
+
*/
|
|
75
|
+
export interface SemanticContext {
|
|
76
|
+
theme: Theme;
|
|
77
|
+
baseDir: string;
|
|
78
|
+
/** `style="…"` in HTML, `style={{…}}` in JSX: one Style, in the backend's own spelling */
|
|
79
|
+
style(style: Style): string;
|
|
80
|
+
/** The component's inline content, wrapped lines already joined */
|
|
81
|
+
text(box: LayoutBox): string;
|
|
82
|
+
/** Escape text for this backend (HTML entities / JSX braces) */
|
|
83
|
+
escape(text: string): string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What a plugin hands to `registerComponent`.
|
|
87
|
+
*
|
|
88
|
+
* Deliberately the same shape as ComponentDef: the registry merges the two, so a plugin that
|
|
89
|
+
* omits a field inherits it from its `extends` base (or gets nothing, when it has no base).
|
|
90
|
+
*/
|
|
91
|
+
export interface ComponentPlugin {
|
|
92
|
+
name: string;
|
|
93
|
+
/** Contract version; defaults to 1. A plugin newer than this build is refused, not half-run */
|
|
94
|
+
api?: number;
|
|
95
|
+
/** Copy another component's fields first, then apply this object's */
|
|
96
|
+
extends?: string;
|
|
97
|
+
defaults?: Attrs;
|
|
98
|
+
intrinsic?: ComponentDef['intrinsic'];
|
|
99
|
+
render?: ComponentDef['render'];
|
|
100
|
+
textAsChild?: boolean;
|
|
101
|
+
doc?: string;
|
|
102
|
+
/** Palette metadata; without it the component lands in the plugin section */
|
|
103
|
+
group?: string;
|
|
104
|
+
category?: ComponentCategory;
|
|
105
|
+
sample?: string;
|
|
106
|
+
preview?: string[];
|
|
107
|
+
container?: boolean;
|
|
108
|
+
dom?: ComponentDef['dom'];
|
|
109
|
+
react?: ComponentDef['react'];
|
|
110
|
+
}
|
|
111
|
+
//# sour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M,CAAA;IACd,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,GAAG,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAA;IACzB,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entrance animations.
|
|
3
|
+
*
|
|
4
|
+
* `@anim fade-in` declares that a component should animate in. The animation is expressed as CSS
|
|
5
|
+
* `@keyframes` plus an `animation` shorthand, which means it works in the DOM and React backends
|
|
6
|
+
* and in the preview shell for free.
|
|
7
|
+
*
|
|
8
|
+
* The SVG backend deliberately ignores animations: a static design draft is a still image, and
|
|
9
|
+
* SMIL would make the output non-deterministic across renderers. If a motion spec is needed it
|
|
10
|
+
* belongs in the annotation layer, not in the pixels.
|
|
11
|
+
*/
|
|
12
|
+
import type { AnyNode, Attrs } from './ast.ts';
|
|
13
|
+
/** A named animation: the keyframe body plus its defaults */
|
|
14
|
+
interface AnimDef {
|
|
15
|
+
/** CSS keyframe body, e.g. `from { opacity: 0 }` */
|
|
16
|
+
frames: string;
|
|
17
|
+
duration: string;
|
|
18
|
+
easing: string;
|
|
19
|
+
}
|
|
20
|
+
/** The built-in animation set. Names are kebab-case to match component and state names. */
|
|
21
|
+
export declare const ANIMATIONS: Record<string, AnimDef>;
|
|
22
|
+
/** Every animation name, for schema output and error messages */
|
|
23
|
+
export declare function animationNames(): string[];
|
|
24
|
+
/** The `animation` shorthand for one declared animation, or undefined if the name is unknown */
|
|
25
|
+
export declare function animationDecl(name: string, overrides: Attrs): string | undefined;
|
|
26
|
+
/** The `@keyframes` rules for every animation used on the page, ready to drop into a <style> */
|
|
27
|
+
export declare function keyframesCss(used: Iterable<string>): string;
|
|
28
|
+
/** Collect every animation name declared anywhere in the tree, in declaration order */
|
|
29
|
+
export declare function collectAnims(root: AnyNode): string[];
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=anim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anim.d.ts","sourceRoot":"","sources":["../../../src/core/anim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAG9C,6DAA6D;AAC7D,UAAU,OAAO;IACf,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,2FAA2F;AAC3F,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAoC9C,CAAA;AAED,iEAAiE;AACjE,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAEzC;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAQhF;AAED,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAM3D;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAYpD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entrance animations.
|
|
3
|
+
*
|
|
4
|
+
* `@anim fade-in` declares that a component should animate in. The animation is expressed as CSS
|
|
5
|
+
* `@keyframes` plus an `animation` shorthand, which means it works in the DOM and React backends
|
|
6
|
+
* and in the preview shell for free.
|
|
7
|
+
*
|
|
8
|
+
* The SVG backend deliberately ignores animations: a static design draft is a still image, and
|
|
9
|
+
* SMIL would make the output non-deterministic across renderers. If a motion spec is needed it
|
|
10
|
+
* belongs in the annotation layer, not in the pixels.
|
|
11
|
+
*/
|
|
12
|
+
import { isContainer } from "./ast.js";
|
|
13
|
+
/** The built-in animation set. Names are kebab-case to match component and state names. */
|
|
14
|
+
export const ANIMATIONS = {
|
|
15
|
+
'fade-in': {
|
|
16
|
+
frames: 'from { opacity: 0 }',
|
|
17
|
+
duration: '300ms',
|
|
18
|
+
easing: 'ease-out',
|
|
19
|
+
},
|
|
20
|
+
'slide-up': {
|
|
21
|
+
frames: 'from { opacity: 0; transform: translateY(12px) }',
|
|
22
|
+
duration: '320ms',
|
|
23
|
+
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
24
|
+
},
|
|
25
|
+
'slide-down': {
|
|
26
|
+
frames: 'from { opacity: 0; transform: translateY(-12px) }',
|
|
27
|
+
duration: '320ms',
|
|
28
|
+
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
29
|
+
},
|
|
30
|
+
'slide-left': {
|
|
31
|
+
frames: 'from { opacity: 0; transform: translateX(16px) }',
|
|
32
|
+
duration: '320ms',
|
|
33
|
+
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
34
|
+
},
|
|
35
|
+
'slide-right': {
|
|
36
|
+
frames: 'from { opacity: 0; transform: translateX(-16px) }',
|
|
37
|
+
duration: '320ms',
|
|
38
|
+
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
39
|
+
},
|
|
40
|
+
'scale-in': {
|
|
41
|
+
frames: 'from { opacity: 0; transform: scale(0.94) }',
|
|
42
|
+
duration: '260ms',
|
|
43
|
+
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
44
|
+
},
|
|
45
|
+
'pop-in': {
|
|
46
|
+
frames: 'from { opacity: 0; transform: scale(0.8) }',
|
|
47
|
+
duration: '380ms',
|
|
48
|
+
easing: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
/** Every animation name, for schema output and error messages */
|
|
52
|
+
export function animationNames() {
|
|
53
|
+
return Object.keys(ANIMATIONS);
|
|
54
|
+
}
|
|
55
|
+
/** The `animation` shorthand for one declared animation, or undefined if the name is unknown */
|
|
56
|
+
export function animationDecl(name, overrides) {
|
|
57
|
+
const def = ANIMATIONS[name];
|
|
58
|
+
if (!def)
|
|
59
|
+
return undefined;
|
|
60
|
+
const duration = String(overrides.duration ?? def.duration);
|
|
61
|
+
const easing = String(overrides.easing ?? def.easing);
|
|
62
|
+
const delay = overrides.delay !== undefined ? String(overrides.delay) : '0ms';
|
|
63
|
+
const fill = overrides.fill !== undefined ? String(overrides.fill) : 'both';
|
|
64
|
+
return `${name} ${duration} ${easing} ${delay} ${fill}`;
|
|
65
|
+
}
|
|
66
|
+
/** The `@keyframes` rules for every animation used on the page, ready to drop into a <style> */
|
|
67
|
+
export function keyframesCss(used) {
|
|
68
|
+
const names = [...new Set(used)].filter((n) => ANIMATIONS[n]);
|
|
69
|
+
if (names.length === 0)
|
|
70
|
+
return '';
|
|
71
|
+
return names
|
|
72
|
+
.map((n) => `@keyframes ${n} {\n ${ANIMATIONS[n].frames}\n}`)
|
|
73
|
+
.join('\n');
|
|
74
|
+
}
|
|
75
|
+
/** Collect every animation name declared anywhere in the tree, in declaration order */
|
|
76
|
+
export function collectAnims(root) {
|
|
77
|
+
const names = [];
|
|
78
|
+
const walk = (node) => {
|
|
79
|
+
if (node.type === 'component' && node.anims) {
|
|
80
|
+
for (const name of Object.keys(node.anims))
|
|
81
|
+
if (!names.includes(name))
|
|
82
|
+
names.push(name);
|
|
83
|
+
}
|
|
84
|
+
if (!isContainer(node))
|
|
85
|
+
return;
|
|
86
|
+
for (const child of node.children)
|
|
87
|
+
walk(child);
|
|
88
|
+
for (const list of Object.values(node.slots))
|
|
89
|
+
for (const child of list)
|
|
90
|
+
walk(child);
|
|
91
|
+
};
|
|
92
|
+
walk(root);
|
|
93
|
+
return names;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=anim.js.map
|