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,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project config: `designmockdown.config.*`.
|
|
3
|
+
*
|
|
4
|
+
* The lookup walks up from the working directory and stops at the repository root (a `.git`), for
|
|
5
|
+
* the same reason tsconfig and Vite do it: a config two levels up is the project's, while one in a
|
|
6
|
+
* home directory belonging to an unrelated checkout would silently change what `check` accepts.
|
|
7
|
+
*
|
|
8
|
+
* Only `components` is read. Any other key is reported and ignored rather than silently accepted,
|
|
9
|
+
* so a typo (`component:` singular) does not look like a plugin that failed to load.
|
|
10
|
+
*/
|
|
11
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
12
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
13
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
14
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return path;
|
|
18
|
+
};
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
20
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
21
|
+
import { pathToFileURL } from 'node:url';
|
|
22
|
+
import { DesignMockdownError } from "../core/errors.js";
|
|
23
|
+
/** In the order Node itself would prefer them: the first match wins */
|
|
24
|
+
const NAMES = [
|
|
25
|
+
'designmockdown.config.ts',
|
|
26
|
+
'designmockdown.config.mts',
|
|
27
|
+
'designmockdown.config.js',
|
|
28
|
+
'designmockdown.config.mjs',
|
|
29
|
+
'designmockdown.config.json',
|
|
30
|
+
];
|
|
31
|
+
const KNOWN_KEYS = new Set(['components']);
|
|
32
|
+
/**
|
|
33
|
+
* Walk up from `start` until a config file or the repository root is found.
|
|
34
|
+
*
|
|
35
|
+
* The config in the starting directory is checked before the `.git` in the same directory: a repo
|
|
36
|
+
* root is exactly where a config belongs.
|
|
37
|
+
*/
|
|
38
|
+
export function findConfigFile(start) {
|
|
39
|
+
let dir = resolve(start);
|
|
40
|
+
for (;;) {
|
|
41
|
+
for (const name of NAMES) {
|
|
42
|
+
const candidate = join(dir, name);
|
|
43
|
+
if (existsSync(candidate))
|
|
44
|
+
return candidate;
|
|
45
|
+
}
|
|
46
|
+
if (existsSync(join(dir, '.git')))
|
|
47
|
+
return null;
|
|
48
|
+
const parent = dirname(dir);
|
|
49
|
+
if (parent === dir)
|
|
50
|
+
return null;
|
|
51
|
+
dir = parent;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Read the config, if there is one. `warn` receives keys that are recognised but not understood. */
|
|
55
|
+
export async function loadConfig(start, warn = () => { }) {
|
|
56
|
+
const file = findConfigFile(start);
|
|
57
|
+
if (!file)
|
|
58
|
+
return null;
|
|
59
|
+
let data;
|
|
60
|
+
if (file.endsWith('.json')) {
|
|
61
|
+
try {
|
|
62
|
+
data = JSON.parse(readFileSync(file, 'utf8'));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
66
|
+
throw new DesignMockdownError(`cannot read ${basename(file)}`, undefined, detail);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
try {
|
|
71
|
+
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
|
|
72
|
+
data = mod.default ?? mod;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
76
|
+
throw new DesignMockdownError(`cannot load ${basename(file)}`, undefined, detail);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
80
|
+
throw new DesignMockdownError(`${basename(file)} must export an object`, undefined, 'export default { components: ["./plugins/rating/index.ts"] }');
|
|
81
|
+
}
|
|
82
|
+
for (const key of Object.keys(data)) {
|
|
83
|
+
if (!KNOWN_KEYS.has(key))
|
|
84
|
+
warn(`${basename(file)}: ignoring unknown key "${key}"`);
|
|
85
|
+
}
|
|
86
|
+
const raw = data.components;
|
|
87
|
+
if (raw === undefined)
|
|
88
|
+
return { file, components: [] };
|
|
89
|
+
if (!Array.isArray(raw) || raw.some((v) => typeof v !== 'string')) {
|
|
90
|
+
throw new DesignMockdownError(`${basename(file)}: "components" must be an array of strings`, undefined, 'components: ["./plugins/rating/index.ts", "designmockdown-plugin-extra"]');
|
|
91
|
+
}
|
|
92
|
+
return { file, components: raw };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/components/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,uEAAuE;AACvE,MAAM,KAAK,GAAG;IACZ,0BAA0B;IAC1B,2BAA2B;IAC3B,0BAA0B;IAC1B,2BAA2B;IAC3B,4BAA4B;CAC7B,CAAA;AAED,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAA;AAS1C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACxB,SAAS,CAAC;QACR,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;YACjC,IAAI,UAAU,CAAC,SAAS,CAAC;gBAA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2
|
+
* Container components: tabs, accordion.
|
|
3
|
+
*
|
|
4
|
+
* Both are "items= driven": the item list is a single `|`-separated attribute so a whole
|
|
5
|
+
* tab bar fits on one line, which is the point of a line-oriented language.
|
|
6
|
+
*/
|
|
7
|
+
import type { ComponentDef } from './types.ts';
|
|
8
|
+
export declare const CONTAINER_COMPONENTS: ComponentDef[];
|
|
9
|
+
//# sourceMappingURL=containers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containers.d.ts","sourceRoot":"","sources":["../../../src/components/containers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA2G9C,eAAO,MAAM,oBAAoB,EAAE,YAAY,EAAsB,CAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container components: tabs, accordion.
|
|
3
|
+
*
|
|
4
|
+
* Both are "items= driven": the item list is a single `|`-separated attribute so a whole
|
|
5
|
+
* tab bar fits on one line, which is the point of a line-oriented language.
|
|
6
|
+
*/
|
|
7
|
+
import { contentOrigin, drawChrome, line, rect, textEl } from "../render/primitives.js";
|
|
8
|
+
import { measureText } from "../layout/measure.js";
|
|
9
|
+
import { iconSvg } from "./icons.js";
|
|
10
|
+
function splitList(v, fallback) {
|
|
11
|
+
if (v === undefined || v === true)
|
|
12
|
+
return fallback;
|
|
13
|
+
return String(v).split('|').map((s) => s.trim()).filter(Boolean);
|
|
14
|
+
}
|
|
15
|
+
const TAB_GAP = 24;
|
|
16
|
+
/**
|
|
17
|
+
* @tabs: a tab bar with an underline on the active item.
|
|
18
|
+
* Labels keep their natural width and the leftover space is folded into the gaps, so the
|
|
19
|
+
* intrinsic width and the rendered width always agree.
|
|
20
|
+
*/
|
|
21
|
+
const tabs = {
|
|
22
|
+
name: 'tabs',
|
|
23
|
+
defaults: { h: 40, items: 'Tab one|Tab two|Tab three', active: 0 },
|
|
24
|
+
intrinsic: (attrs, style) => {
|
|
25
|
+
const items = splitList(attrs.items, ['Tab']);
|
|
26
|
+
const w = items.reduce((a, s) => a + measureText(s, style.fontSize), 0) + TAB_GAP * Math.max(0, items.length - 1);
|
|
27
|
+
return { width: w, height: Number(attrs.h ?? 40) };
|
|
28
|
+
},
|
|
29
|
+
render: (b, ctx) => {
|
|
30
|
+
const t = ctx.theme.tokens;
|
|
31
|
+
const items = splitList(b.style.extra.items, ['Tab']);
|
|
32
|
+
const active = Number(b.style.extra.active ?? 0);
|
|
33
|
+
const out = [];
|
|
34
|
+
const textWs = items.map((s, i) => measureText(s, b.style.fontSize, i === active ? 600 : 400));
|
|
35
|
+
const contentW = textWs.reduce((a, x) => a + x, 0);
|
|
36
|
+
const free = Math.max(0, b.width - contentW);
|
|
37
|
+
const gap = items.length > 1 ? TAB_GAP + free / (items.length - 1) : 0;
|
|
38
|
+
let x = b.x;
|
|
39
|
+
items.forEach((label, i) => {
|
|
40
|
+
const on = i === active;
|
|
41
|
+
out.push(textEl(x, b.y + b.height / 2 + b.style.fontSize * 0.36, label, {
|
|
42
|
+
size: b.style.fontSize,
|
|
43
|
+
weight: on ? 600 : 400,
|
|
44
|
+
color: on ? t.text : t.text2,
|
|
45
|
+
}));
|
|
46
|
+
if (on) {
|
|
47
|
+
out.push(rect(x, b.y + b.height - 2, textWs[i], 2, { rx: 1, fill: t.brand }));
|
|
48
|
+
}
|
|
49
|
+
x += textWs[i] + gap;
|
|
50
|
+
});
|
|
51
|
+
out.push(line(b.x, b.y + b.height - 1, b.x + b.width, b.y + b.height - 1, { stroke: t.border, sw: 1 }));
|
|
52
|
+
return out.join('');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const ACCORDION_COLLAPSED_H = 44;
|
|
56
|
+
const ACCORDION_EXPANDED_H = 76;
|
|
57
|
+
/**
|
|
58
|
+
* @accordion: a list of collapsible sections. The open item is taller and shows a body
|
|
59
|
+
* placeholder; the row heights are shared with the intrinsic size so the box never has to
|
|
60
|
+
* guess how tall it is.
|
|
61
|
+
*/
|
|
62
|
+
const accordion = {
|
|
63
|
+
name: 'accordion',
|
|
64
|
+
defaults: { items: 'Section one|Section two|Section three', open: 0, p: 12, bg: 'bg', rounded: 'md', border: 'border' },
|
|
65
|
+
intrinsic: (attrs) => {
|
|
66
|
+
const n = splitList(attrs.items, ['Section']).length;
|
|
67
|
+
const open = Number(attrs.open ?? 0);
|
|
68
|
+
const h = n * ACCORDION_COLLAPSED_H + (open >= 0 && open < n ? ACCORDION_EXPANDED_H - ACCORDION_COLLAPSED_H : 0);
|
|
69
|
+
return { width: 320, height: h };
|
|
70
|
+
},
|
|
71
|
+
render: (b, ctx) => {
|
|
72
|
+
const t = ctx.theme.tokens;
|
|
73
|
+
const items = splitList(b.style.extra.items, ['Section']);
|
|
74
|
+
const open = Number(b.style.extra.open ?? 0);
|
|
75
|
+
const out = [drawChrome(b)];
|
|
76
|
+
const c = contentOrigin(b);
|
|
77
|
+
const rowHs = items.map((_, i) => (i === open ? ACCORDION_EXPANDED_H : ACCORDION_COLLAPSED_H));
|
|
78
|
+
let y = c.y;
|
|
79
|
+
items.forEach((label, i) => {
|
|
80
|
+
const rowH = rowHs[i];
|
|
81
|
+
const on = i === open;
|
|
82
|
+
if (i > 0)
|
|
83
|
+
out.push(line(c.x, y, c.x + c.w, y, { stroke: t.border, sw: 1 }));
|
|
84
|
+
out.push(textEl(c.x + 4, y + 20, label, {
|
|
85
|
+
size: b.style.fontSize,
|
|
86
|
+
weight: on ? 600 : 400,
|
|
87
|
+
color: on ? t.text : t.text2,
|
|
88
|
+
}));
|
|
89
|
+
const isz = 14;
|
|
90
|
+
out.push(`<g transform="translate(${c.x + c.w - isz - 4},${y + 14})">${iconSvg(on ? 'chevron-up' : 'chevron-down', isz, t.text3) ?? ''}</g>`);
|
|
91
|
+
if (on) {
|
|
92
|
+
// Body placeholder: two rules standing in for the expanded content
|
|
93
|
+
out.push(rect(c.x + 4, y + 34, c.w - 8, 6, { rx: 3, fill: t['surface-2'] }));
|
|
94
|
+
out.push(rect(c.x + 4, y + 48, (c.w - 8) * 0.6, 6, { rx: 3, fill: t['surface-2'] }));
|
|
95
|
+
}
|
|
96
|
+
y += rowH;
|
|
97
|
+
});
|
|
98
|
+
return out.join('');
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
export const CONTAINER_COMPONENTS = [tabs, accordion];
|
|
102
|
+
//# sourceMappingURL=containers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containers.js","sourceRoot":"","sources":["../../../src/components/containers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,SAAS,SAAS,CAAC,CAAU,EAAE,QAAkB;IAC/C,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAA;IAClD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAClE,CAAC;AAED,MAAM,OAAO,GAAG,EAAE,CAAA;AAElB;;;;GAIG;AACH,MAAM,IAAI,GAAiB;IACzB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,CAAC,EAAE;IAClE,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC1B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,C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
* Control components: button, input, select, switch and friends.
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentDef } from './types.ts';
|
|
5
|
+
import { drawSingle, ellipse, esc, line } from '../render/primitives.ts';
|
|
6
|
+
export declare const CONTROL_COMPONENTS: ComponentDef[];
|
|
7
|
+
export { esc, line, ellipse, drawSingle };
|
|
8
|
+
//# sourceMappingURL=controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../../../src/components/controls.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EAAgD,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAgB,MAAM,yBAAyB,CAAA;AAsZpI,eAAO,MAAM,kBAAkB,EAAE,YAAY,EAc5C,CAAA;AAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control components: button, input, select, switch and friends.
|
|
3
|
+
*/
|
|
4
|
+
import { contentOrigin, circle, drawChrome, drawLines, drawSingle, ellipse, esc, line, rect, textEl } from "../render/primitives.js";
|
|
5
|
+
import { measureText } from "../layout/measure.js";
|
|
6
|
+
import { hasIcon, iconSvg } from "./icons.js";
|
|
7
|
+
function buttonPalette(variant, theme) {
|
|
8
|
+
const t = theme.tokens;
|
|
9
|
+
switch (variant) {
|
|
10
|
+
case 'secondary':
|
|
11
|
+
return { bg: t['brand-soft'], fg: t.brand, border: undefined };
|
|
12
|
+
case 'ghost':
|
|
13
|
+
return { bg: undefined, fg: t.text, border: t.border };
|
|
14
|
+
case 'danger':
|
|
15
|
+
return { bg: t.danger, fg: t.white, border: undefined };
|
|
16
|
+
case 'link':
|
|
17
|
+
return { bg: undefined, fg: t.brand, border: undefined };
|
|
18
|
+
default:
|
|
19
|
+
return { bg: t.brand, fg: t.white, border: undefined };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const BUTTON_SIZES = {
|
|
23
|
+
sm: { h: 32, font: 12, px: 12 },
|
|
24
|
+
md: { h: 40, font: 14, px: 16 },
|
|
25
|
+
lg: { h: 48, font: 16, px: 20 },
|
|
26
|
+
};
|
|
27
|
+
const button = {
|
|
28
|
+
name: 'button',
|
|
29
|
+
defaults: { h: 40, p: '0 16', rounded: 'md', size: 'md', variant: 'primary' },
|
|
30
|
+
intrinsic: (attrs, style, _theme, content) => {
|
|
31
|
+
const size = String(attrs.size ?? 'md');
|
|
32
|
+
const cfg = BUTTON_SIZES[size] ?? BUTTON_SIZES.md;
|
|
33
|
+
const h = Number(attrs.h ?? cfg.h);
|
|
34
|
+
const font = style.fontSize;
|
|
35
|
+
const iconName = attrs.icon ? String(attrs.icon) : undefined;
|
|
36
|
+
const iconW = iconName ? font + 6 : 0;
|
|
37
|
+
const textW = content ? measureText(content, font, 500) : 0;
|
|
38
|
+
const w = textW + iconW + cfg.px * 2;
|
|
39
|
+
return { width: Math.max(w, h), height: h };
|
|
40
|
+
},
|
|
41
|
+
render: (b, ctx) => {
|
|
42
|
+
const s = b.style;
|
|
43
|
+
const variant = String(s.extra.variant ?? 'primary');
|
|
44
|
+
const pal = buttonPalette(variant, ctx.theme);
|
|
45
|
+
const disabled = s.extra.disabled === true;
|
|
46
|
+
const loading = s.extra.loading === true;
|
|
47
|
+
const circle_ = s.extra.circle === true;
|
|
48
|
+
const out = [];
|
|
49
|
+
const radius = circle_ ? Math.min(b.width, b.height) / 2 : (s.radius ?? 8);
|
|
50
|
+
const opacity = disabled ? 0.45 : s.opacity;
|
|
51
|
+
out.push(rect(b.x, b.y, b.width, b.height, {
|
|
52
|
+
rx: radius,
|
|
53
|
+
fill: pal.bg ?? 'none',
|
|
54
|
+
stroke: pal.border,
|
|
55
|
+
sw: pal.border ? 1 : undefined,
|
|
56
|
+
opacity,
|
|
57
|
+
}));
|
|
58
|
+
const font = s.fontSize;
|
|
59
|
+
const iconName = s.extra.icon ? String(s.extra.icon) : undefined;
|
|
60
|
+
const iconW = iconName ? font + 6 : 0;
|
|
61
|
+
const textW = b.text ? measureText(b.text, font, 500) : 0;
|
|
62
|
+
let cx = (b.width - textW - iconW) / 2;
|
|
63
|
+
if (loading) {
|
|
64
|
+
const cy = b.y + b.height / 2;
|
|
65
|
+
const rad = font * 0.42;
|
|
66
|
+
out.push(`<circle cx="${b.x + cx + rad}" cy="${cy}" r="${rad}" fill="none" stroke="${pal.fg}" stroke-width="2" stroke-linecap="round" stroke-dasharray="${rad * 1.8} ${rad * 1.2}"><animateTransform attributeName="transform" type="rotate" from="0 ${b.x + cx + rad} ${cy}" to="360 ${b.x + cx + rad} ${cy}" dur="0.9s" repeatCount="indefinite"/></circle>`);
|
|
67
|
+
cx += rad * 2 + 6;
|
|
68
|
+
}
|
|
69
|
+
else if (iconName && hasIcon(iconName)) {
|
|
70
|
+
out.push(`<g transform="translate(${b.x + cx},${b.y + (b.height - font) / 2})">${iconSvg(iconName, font, pal.fg) ?? ""}</g>`);
|
|
71
|
+
cx += iconW;
|
|
72
|
+
}
|
|
73
|
+
if (b.text) {
|
|
74
|
+
out.push(textEl(b.x + cx, b.y + b.height / 2 + font * 0.36, b.text, {
|
|
75
|
+
size: font,
|
|
76
|
+
weight: 500,
|
|
77
|
+
color: pal.fg,
|
|
78
|
+
anchor: 'start',
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
return out.join('');
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const iconButton = {
|
|
85
|
+
name: 'icon-button',
|
|
86
|
+
defaults: { w: 40, h: 40, rounded: 'md', variant: 'ghost', icon: 'three-dots' },
|
|
87
|
+
intrinsic: (attrs) => ({ width: Number(attrs.w ?? 40), height: Number(attrs.h ?? 40) }),
|
|
88
|
+
render: (b, ctx) => {
|
|
89
|
+
const variant = String(b.style.extra.variant ?? 'ghost');
|
|
90
|
+
const pal = buttonPalette(variant, ctx.theme);
|
|
91
|
+
const name = String(b.style.extra.icon ?? 'more');
|
|
92
|
+
const size = Math.min(b.width, b.height) * 0.5;
|
|
93
|
+
const out = [
|
|
94
|
+
rect(b.x, b.y, b.width, b.height, {
|
|
95
|
+
rx: b.style.radius ?? 8,
|
|
96
|
+
fill: pal.bg ?? 'none',
|
|
97
|
+
stroke: pal.border,
|
|
98
|
+
sw: pal.border ? 1 : undefined,
|
|
99
|
+
}),
|
|
100
|
+
];
|
|
101
|
+
if (hasIcon(name)) {
|
|
102
|
+
out.push(`<g transform="translate(${b.x + (b.width - size) / 2},${b.y + (b.height - size) / 2})">${iconSvg(name, size, pal.fg) ?? ""}</g>`);
|
|
103
|
+
}
|
|
104
|
+
return out.join('');
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const fab = {
|
|
108
|
+
name: 'fab',
|
|
109
|
+
defaults: { w: 56, h: 56, rounded: 'full', variant: 'primary', icon: 'plus' },
|
|
110
|
+
intrinsic: (attrs) => ({ width: Number(attrs.w ?? 56), height: Number(attrs.h ?? 56) }),
|
|
111
|
+
render: (b, ctx) => {
|
|
112
|
+
const pal = buttonPalette(String(b.style.extra.variant ?? 'primary'), ctx.theme);
|
|
113
|
+
const name = String(b.style.extra.icon ?? 'plus');
|
|
114
|
+
const size = Math.min(b.width, b.height) * 0.42;
|
|
115
|
+
const out = [
|
|
116
|
+
rect(b.x, b.y, b.width, b.height, { rx: Math.min(b.width, b.height) / 2, fill: pal.bg, extra: 'filter="url(#fab-shadow)"' }),
|
|
117
|
+
];
|
|
118
|
+
if (hasIcon(name)) {
|
|
119
|
+
out.push(`<g transform="translate(${b.x + (b.width - size) / 2},${b.y + (b.height - size) / 2})">${iconSvg(name, size, pal.fg) ?? ""}</g>`);
|
|
120
|
+
}
|
|
121
|
+
return out.join('');
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const input = {
|
|
125
|
+
name: 'input',
|
|
126
|
+
// overflow:hidden so append slots wider than the box are cut off at the edge instead of painting
|
|
127
|
+
// outside the input's rounded chrome
|
|
128
|
+
defaults: { h: 44, p: '0 12', rounded: 'md', bg: 'surface', border: 'border', size: 'md', overflow: 'hidden' },
|
|
129
|
+
intrinsic: (attrs) => ({ width: 240, height: Number(attrs.h ?? 44) }),
|
|
130
|
+
handlesChildren: true,
|
|
131
|
+
render: (b, ctx) => {
|
|
132
|
+
const s = b.style;
|
|
133
|
+
const t = ctx.theme.tokens;
|
|
134
|
+
const out = [drawChrome(b)];
|
|
135
|
+
const c = contentOrigin(b);
|
|
136
|
+
const iconName = s.extra.icon ? String(s.extra.icon) : undefined;
|
|
137
|
+
const iconSize = s.fontSize + 4;
|
|
138
|
+
let textX = c.x;
|
|
139
|
+
if (iconName && hasIcon(iconName)) {
|
|
140
|
+
out.push(`<g transform="translate(${c.x},${c.y + (c.h - iconSize) / 2})">${iconSvg(iconName, iconSize, t.text3) ?? ""}</g>`);
|
|
141
|
+
textX += iconSize + 8;
|
|
142
|
+
}
|
|
143
|
+
const append = b.slots.append ?? [];
|
|
144
|
+
const appendW = append.reduce((a, x) => a + x.width, 0) + (append.length > 1 ? 8 * (append.length - 1) : 0);
|
|
145
|
+
const value = b.text ?? '';
|
|
146
|
+
const placeholder = s.extra.ph ? String(s.extra.ph) : '';
|
|
147
|
+
if (value) {
|
|
148
|
+
out.push(textEl(textX, c.y + c.h / 2 + s.fontSize * 0.36, value, { size: s.fontSize, color: t.text }));
|
|
149
|
+
}
|
|
150
|
+
else if (placeholder) {
|
|
151
|
+
out.push(textEl(textX, c.y + c.h / 2 + s.fontSize * 0.36, placeholder, { size: s.fontSize, color: t.placeholder ?? t.text3 }));
|
|
152
|
+
}
|
|
153
|
+
// Slot content (such as a "Get code" button) hugs the right edge, vertically centered.
|
|
154
|
+
// When the slots are wider than the content box the start goes negative; that is fine because
|
|
155
|
+
// the input clips its overflow, so the leftmost slots are cut off at the edge rather than
|
|
156
|
+
// painting outside the chrome. Clamping to c.x instead would push the first slot on top of the
|
|
157
|
+
// placeholder text.
|
|
158
|
+
let ax = c.x + c.w - appendW;
|
|
159
|
+
for (const slot of append) {
|
|
160
|
+
slot.x = ax;
|
|
161
|
+
slot.y = c.y + (c.h - slot.height) / 2;
|
|
162
|
+
ax += slot.width + 8;
|
|
163
|
+
}
|
|
164
|
+
return out.join('');
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
const textarea = {
|
|
168
|
+
name: 'textarea',
|
|
169
|
+
defaults: { h: 96, p: 12, rounded: 'md', bg: 'surface', border: 'border', size: 'md' },
|
|
170
|
+
intrinsic: (attrs) => ({ width: 280, height: Number(attrs.h ?? 96) }),
|
|
171
|
+
render: (b, ctx) => {
|
|
172
|
+
const out = [drawChrome(b)];
|
|
173
|
+
const c = contentOrigin(b);
|
|
174
|
+
const value = b.text ?? '';
|
|
175
|
+
const placeholder = b.style.extra.ph ? String(b.style.extra.ph) : '';
|
|
176
|
+
if (value) {
|
|
177
|
+
out.push(drawLines({ ...b, x: c.x, y: c.y, width: c.w, height: c.h }, {}));
|
|
178
|
+
}
|
|
179
|
+
else if (placeholder) {
|
|
180
|
+
out.push(textEl(c.x, c.y + b.style.fontSize * 0.9, placeholder, { size: b.style.fontSize, color: ctx.theme.tokens.placeholder ?? ctx.theme.tokens.text3 }));
|
|
181
|
+
}
|
|
182
|
+
return out.join('');
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const select = {
|
|
186
|
+
name: 'select',
|
|
187
|
+
defaults: { h: 44, p: '0 12', rounded: 'md', bg: 'surface', border: 'border', size: 'md' },
|
|
188
|
+
intrinsic: (attrs) => ({ width: 200, height: Number(attrs.h ?? 44) }),
|
|
189
|
+
render: (b, ctx) => {
|
|
190
|
+
const t = ctx.theme.tokens;
|
|
191
|
+
const out = [drawChrome(b)];
|
|
192
|
+
const c = contentOrigin(b);
|
|
193
|
+
const value = b.text || String(b.style.extra.ph ?? 'Select');
|
|
194
|
+
out.push(textEl(c.x, c.y + c.h / 2 + b.style.fontSize * 0.36, value, { size: b.style.fontSize, color: b.text ? t.text : t.text3 }));
|
|
195
|
+
const isz = 16;
|
|
196
|
+
out.push(`<g transform="translate(${c.x + c.w - isz},${c.y + (c.h - isz) / 2})">${iconSvg('chevron-down', isz, t.text3) ?? ""}</g>`);
|
|
197
|
+
return out.join('');
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
const checkbox = {
|
|
201
|
+
name: 'checkbox',
|
|
202
|
+
defaults: { box: 18, gap: 8 },
|
|
203
|
+
intrinsic: (attrs, style, _theme, content) => {
|
|
204
|
+
const box = Number(attrs.box ?? 18);
|
|
205
|
+
const w = content ? box + 8 + measureText(content, style.fontSize) : box;
|
|
206
|
+
return { width: w, height: Math.max(box, style.lineHeight) };
|
|
207
|
+
},
|
|
208
|
+
render: (b, ctx) => {
|
|
209
|
+
const t = ctx.theme.tokens;
|
|
210
|
+
const size = Number(b.style.extra.box ?? 18);
|
|
211
|
+
const checked = b.style.extra.checked === true;
|
|
212
|
+
const y = (b.height - size) / 2;
|
|
213
|
+
const out = [
|
|
214
|
+
rect(b.x, y, size, size, {
|
|
215
|
+
rx: 4,
|
|
216
|
+
fill: checked ? t.brand : 'none',
|
|
217
|
+
stroke: checked ? t.brand : t['border-2'],
|
|
218
|
+
sw: checked ? 0 : 1.5,
|
|
219
|
+
}),
|
|
220
|
+
];
|
|
221
|
+
if (checked) {
|
|
222
|
+
out.push(`<g transform="translate(${b.x + size * 0.22},${y + size * 0.26})">${iconSvg('check', size * 0.56, t.white) ?? ''}</g>`);
|
|
223
|
+
}
|
|
224
|
+
if (b.text) {
|
|
225
|
+
out.push(textEl(b.x + size + 8, b.height / 2 + b.style.fontSize * 0.36, b.text, { size: b.style.fontSize, color: t.text }));
|
|
226
|
+
}
|
|
227
|
+
void ctx;
|
|
228
|
+
return out.join('');
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
const radio = {
|
|
232
|
+
name: 'radio',
|
|
233
|
+
defaults: { box: 18, gap: 8 },
|
|
234
|
+
intrinsic: (attrs, style, _theme, content) => {
|
|
235
|
+
const box = Number(attrs.box ?? 18);
|
|
236
|
+
const w = content ? box + 8 + measureText(content, style.fontSize) : box;
|
|
237
|
+
return { width: w, height: Math.max(box, style.lineHeight) };
|
|
238
|
+
},
|
|
239
|
+
render: (b, ctx) => {
|
|
240
|
+
const t = ctx.theme.tokens;
|
|
241
|
+
const size = Number(b.style.extra.box ?? 18);
|
|
242
|
+
const checked = b.style.extra.checked === true;
|
|
243
|
+
const cy = b.height / 2;
|
|
244
|
+
const out = [
|
|
245
|
+
circle(b.x + size / 2, cy, size / 2, { fill: checked ? t.brand : 'none', stroke: checked ? t.brand : t['border-2'], sw: checked ? 0 : 1.5 }),
|
|
246
|
+
];
|
|
247
|
+
if (checked)
|
|
248
|
+
out.push(circle(b.x + size / 2, cy, size / 4, { fill: t.white }));
|
|
249
|
+
if (b.text) {
|
|
250
|
+
out.push(textEl(b.x + size + 8, cy + b.style.fontSize * 0.36, b.text, { size: b.style.fontSize, color: t.text }));
|
|
251
|
+
}
|
|
252
|
+
void ctx;
|
|
253
|
+
return out.join('');
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
const switchDef = {
|
|
257
|
+
name: 'switch',
|
|
258
|
+
defaults: { w: 48, h: 28 },
|
|
259
|
+
intrinsic: (attrs) => ({ width: Number(attrs.w ?? 48), height: Number(attrs.h ?? 28) }),
|
|
260
|
+
render: (b, ctx) => {
|
|
261
|
+
const t = ctx.theme.tokens;
|
|
262
|
+
const on = b.style.extra.on === true || b.style.extra.checked === true;
|
|
263
|
+
const rad = b.height / 2;
|
|
264
|
+
const knob = b.height - 8;
|
|
265
|
+
const out = [
|
|
266
|
+
rect(b.x, b.y, b.width, b.height, { rx: rad, fill: on ? t.brand : t['border-2'] }),
|
|
267
|
+
circle(b.x + (on ? b.width - rad : rad), b.y + rad, knob / 2, { fill: t.white }),
|
|
268
|
+
];
|
|
269
|
+
void ctx;
|
|
270
|
+
return out.join('');
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
const slider = {
|
|
274
|
+
name: 'slider',
|
|
275
|
+
defaults: { w: 200, h: 24 },
|
|
276
|
+
intrinsic: (attrs) => ({ width: Number(attrs.w ?? 200), height: Number(attrs.h ?? 24) }),
|
|
277
|
+
render: (b, ctx) => {
|
|
278
|
+
const t = ctx.theme.tokens;
|
|
279
|
+
const value = Number(b.style.extra.value ?? 50);
|
|
280
|
+
const pct = Math.max(0, Math.min(100, value)) / 100;
|
|
281
|
+
const cy = b.y + b.height / 2;
|
|
282
|
+
const out = [
|
|
283
|
+
rect(b.x, cy - 2, b.width, 4, { rx: 2, fill: t['surface-2'] }),
|
|
284
|
+
rect(b.x, cy - 2, b.width * pct, 4, { rx: 2, fill: t.brand }),
|
|
285
|
+
circle(b.x + b.width * pct, cy, 8, { fill: t.white, stroke: t.brand, sw: 2 }),
|
|
286
|
+
];
|
|
287
|
+
void ctx;
|
|
288
|
+
return out.join('');
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
const stepper = {
|
|
292
|
+
name: 'stepper',
|
|
293
|
+
defaults: { h: 32, value: 1 },
|
|
294
|
+
intrinsic: (attrs) => ({ width: 120, height: Number(attrs.h ?? 32) }),
|
|
295
|
+
render: (b, ctx) => {
|
|
296
|
+
const t = ctx.theme.tokens;
|
|
297
|
+
const value = String(b.style.extra.value ?? 1);
|
|
298
|
+
const out = [
|
|
299
|
+
rect(b.x, b.y, b.width, b.height, { rx: 6, fill: t.surface, stroke: t.border, sw: 1 }),
|
|
300
|
+
textEl(b.x + b.width / 2, b.y + b.height / 2 + b.style.fontSize * 0.36, value, { size: b.style.fontSize, color: t.text, anchor: 'middle' }),
|
|
301
|
+
];
|
|
302
|
+
const isz = 14;
|
|
303
|
+
out.push(`<g transform="translate(${b.x + 9},${b.y + (b.height - isz) / 2})">${iconSvg('dash', isz, t.text2) ?? ''}</g>`, `<g transform="translate(${b.x + b.width - 9 - isz},${b.y + (b.height - isz) / 2})">${iconSvg('plus-lg', isz, t.text2) ?? ''}</g>`);
|
|
304
|
+
void ctx;
|
|
305
|
+
return out.join('');
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
const search = {
|
|
309
|
+
name: 'search',
|
|
310
|
+
defaults: { h: 36, p: '0 12', rounded: 'full', bg: 'surface', size: 'sm', ph: 'Search' },
|
|
311
|
+
intrinsic: (attrs) => ({ width: 260, height: Number(attrs.h ?? 36) }),
|
|
312
|
+
render: (b, ctx) => {
|
|
313
|
+
const t = ctx.theme.tokens;
|
|
314
|
+
const out = [drawChrome(b)];
|
|
315
|
+
const c = contentOrigin(b);
|
|
316
|
+
const isz = b.style.fontSize + 2;
|
|
317
|
+
out.push(`<g transform="translate(${c.x},${c.y + (c.h - isz) / 2})">${iconSvg('search', isz, t.text3) ?? ''}</g>`);
|
|
318
|
+
const ph = b.style.extra.ph ? String(b.style.extra.ph) : '';
|
|
319
|
+
// A search field sits on a tinted pill, so the `placeholder` token (one shade lighter than text3)
|
|
320
|
+
// drops under 2:1 contrast there and the hint disappears. Treat the hint as a label instead.
|
|
321
|
+
if (!b.text && ph) {
|
|
322
|
+
out.push(textEl(c.x + isz + 8, c.y + c.h / 2 + b.style.fontSize * 0.36, ph, { size: b.style.fontSize, color: t.text3 }));
|
|
323
|
+
}
|
|
324
|
+
else if (b.text) {
|
|
325
|
+
out.push(textEl(c.x + isz + 8, c.y + c.h / 2 + b.style.fontSize * 0.36, b.text, { size: b.style.fontSize, color: t.text }));
|
|
326
|
+
}
|
|
327
|
+
return out.join('');
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
const segmented = {
|
|
331
|
+
name: 'segmented',
|
|
332
|
+
defaults: { h: 32, rounded: 'md', bg: 'surface-2', p: 2, options: 'A|B' },
|
|
333
|
+
intrinsic: (attrs) => ({ width: 200, height: Number(attrs.h ?? 32) }),
|
|
334
|
+
render: (b, ctx) => {
|
|
335
|
+
const t = ctx.theme.tokens;
|
|
336
|
+
const options = String(b.style.extra.options ?? 'A|B').split('|');
|
|
337
|
+
const active = Number(b.style.extra.active ?? 0);
|
|
338
|
+
const out = [drawChrome(b)];
|
|
339
|
+
const c = contentOrigin(b);
|
|
340
|
+
const n = options.length;
|
|
341
|
+
const segW = c.w / n;
|
|
342
|
+
const pad = 2;
|
|
343
|
+
out.push(rect(c.x + active * segW + pad, c.y + pad, segW - pad * 2, c.h - pad * 2, {
|
|
344
|
+
rx: (b.style.radius ?? 6) - 1,
|
|
345
|
+
fill: t.bg,
|
|
346
|
+
extra: 'filter="url(#seg-shadow)"',
|
|
347
|
+
}));
|
|
348
|
+
options.forEach((opt, i) => {
|
|
349
|
+
out.push(textEl(c.x + segW * (i + 0.5), c.y + c.h / 2 + b.style.fontSize * 0.36, opt, {
|
|
350
|
+
size: b.style.fontSize,
|
|
351
|
+
weight: i === active ? 600 : 400,
|
|
352
|
+
color: i === active ? t.text : t.text2,
|
|
353
|
+
anchor: 'middle',
|
|
354
|
+
}));
|
|
355
|
+
});
|
|
356
|
+
void ctx;
|
|
357
|
+
return out.join('');
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
export const CONTROL_COMPONENTS = [
|
|
361
|
+
button,
|
|
362
|
+
iconButton,
|
|
363
|
+
fab,
|
|
364
|
+
input,
|
|
365
|
+
textarea,
|
|
366
|
+
select,
|
|
367
|
+
checkbox,
|
|
368
|
+
radio,
|
|
369
|
+
switchDef,
|
|
370
|
+
slider,
|
|
371
|
+
stepper,
|
|
372
|
+
search,
|
|
373
|
+
segmented,
|
|
374
|
+
];
|
|
375
|
+
export { esc, line, ellipse, drawSingle };
|
|
376
|
+
//# sourceMappingURL=controls.js.map
|