@wirelith/core 0.0.0 → 0.1.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/NOTICE +48 -0
- package/README.md +49 -1
- package/dist/ai-spec.d.ts +5 -0
- package/dist/ai-spec.js +7 -0
- package/dist/ai-spec.js.map +1 -0
- package/dist/api.d.ts +54 -0
- package/dist/api.js +236 -0
- package/dist/api.js.map +1 -0
- package/dist/components.d.ts +43 -0
- package/dist/components.js +159 -0
- package/dist/components.js.map +1 -0
- package/dist/data/ai-spec.d.ts +2 -0
- package/dist/data/ai-spec.js +5 -0
- package/dist/data/ai-spec.js.map +1 -0
- package/dist/data/fonts.d.ts +2 -0
- package/dist/data/fonts.js +5 -0
- package/dist/data/fonts.js.map +1 -0
- package/dist/data/icons.d.ts +4 -0
- package/dist/data/icons.js +7 -0
- package/dist/data/icons.js.map +1 -0
- package/dist/format.d.ts +7 -0
- package/dist/format.js +189 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +156 -0
- package/dist/layout.js +1118 -0
- package/dist/layout.js.map +1 -0
- package/dist/measure.d.ts +27 -0
- package/dist/measure.js +105 -0
- package/dist/measure.js.map +1 -0
- package/dist/overview.d.ts +37 -0
- package/dist/overview.js +523 -0
- package/dist/overview.js.map +1 -0
- package/dist/parse.d.ts +57 -0
- package/dist/parse.js +609 -0
- package/dist/parse.js.map +1 -0
- package/dist/render.d.ts +12 -0
- package/dist/render.js +980 -0
- package/dist/render.js.map +1 -0
- package/dist/svg.d.ts +18 -0
- package/dist/svg.js +97 -0
- package/dist/svg.js.map +1 -0
- package/dist/theme.d.ts +42 -0
- package/dist/theme.js +220 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +35 -0
- package/dist/validate.js +450 -0
- package/dist/validate.js.map +1 -0
- package/package.json +38 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Bullwhip Technologies LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Wirelith
|
|
2
|
+
Copyright 2026 Bullwhip Technologies LLC
|
|
3
|
+
|
|
4
|
+
Wirelith is licensed under the MIT License. See LICENSE.
|
|
5
|
+
|
|
6
|
+
This covers the code, the specification, the documentation, the examples, the
|
|
7
|
+
conformance suite and the data tables in this repository, except where a file
|
|
8
|
+
or a section below says otherwise.
|
|
9
|
+
|
|
10
|
+
Third-party material
|
|
11
|
+
--------------------
|
|
12
|
+
|
|
13
|
+
CODE_OF_CONDUCT.md is adapted from the Contributor Covenant, version 2.1,
|
|
14
|
+
licensed under the Creative Commons Attribution 4.0 International License
|
|
15
|
+
(CC BY 4.0). See CODE_OF_CONDUCT.md for its attribution.
|
|
16
|
+
|
|
17
|
+
Fonts
|
|
18
|
+
-----
|
|
19
|
+
|
|
20
|
+
The PNG renderers bundle these fonts, unmodified, so that output does not
|
|
21
|
+
depend on the fonts installed on a machine. Each is licensed under the SIL Open
|
|
22
|
+
Font License, version 1.1 (OFL-1.1). The license texts are in third-party/fonts.
|
|
23
|
+
|
|
24
|
+
Inter 4.1
|
|
25
|
+
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
|
26
|
+
License: third-party/fonts/inter/LICENSE.txt
|
|
27
|
+
|
|
28
|
+
Source Serif 4, version 4.005
|
|
29
|
+
Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font
|
|
30
|
+
Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the
|
|
31
|
+
United States and/or other countries.
|
|
32
|
+
License: third-party/fonts/source-serif-4/LICENSE.md
|
|
33
|
+
|
|
34
|
+
JetBrains Mono 2.304
|
|
35
|
+
Copyright 2020 The JetBrains Mono Project Authors
|
|
36
|
+
(https://github.com/JetBrains/JetBrainsMono)
|
|
37
|
+
License: third-party/fonts/jetbrains-mono/OFL.txt
|
|
38
|
+
|
|
39
|
+
The font-metrics tables in spec/data/fonts are measurements taken from these
|
|
40
|
+
font files.
|
|
41
|
+
|
|
42
|
+
Icons
|
|
43
|
+
-----
|
|
44
|
+
|
|
45
|
+
The icon shapes in spec/data/icons.json are a subset of Lucide 1.62.0, under the
|
|
46
|
+
ISC License; the icons Lucide derives from the Feather project are also under
|
|
47
|
+
the MIT License. The full license text is in third-party/lucide/LICENSE.
|
|
48
|
+
Copyright (c) 2026 Lucide Icons and Contributors
|
package/README.md
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
# @wirelith/core
|
|
2
|
+
|
|
3
|
+
The parser, validator, layout engine and SVG renderer for Wirelith, a plain-text language for low-fidelity wireframes.
|
|
4
|
+
|
|
5
|
+
**Status: 0.x, unstable, not yet published.** It implements the [Wirelith specification](https://github.com/wirelith/wirelith/blob/main/spec/spec.md), version 0.1.
|
|
6
|
+
|
|
7
|
+
Try Wirelith in your browser at [play.wirelith.dev](https://play.wirelith.dev).
|
|
8
|
+
|
|
9
|
+
- No dependencies. No network requests. No DOM. No file access.
|
|
10
|
+
- Every function is pure and synchronous: the same input gives the same bytes.
|
|
11
|
+
- Every string from a source is escaped. The output contains only the SVG elements and attributes the specification allows.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { render, validate } from '@wirelith/core';
|
|
17
|
+
|
|
18
|
+
const source = `screen "Sign in" phone #signin
|
|
19
|
+
h1 "Welcome back"
|
|
20
|
+
input "Email" placeholder="you@example.com"
|
|
21
|
+
button "Sign in" primary -> #home
|
|
22
|
+
|
|
23
|
+
screen "Home" phone #home
|
|
24
|
+
h1 "Hello, Sam"
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const { svg, diagnostics } = render(source);
|
|
28
|
+
// svg is a complete SVG document, or null when the source has errors.
|
|
29
|
+
// diagnostics: [{ code, severity, line, column, message, hint? }]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
| Function | Returns |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `parse(source)` | `{ tree, diagnostics }`: the syntax tree and syntax errors |
|
|
37
|
+
| `validate(source, options?)` | Every diagnostic, sorted by line, column and code |
|
|
38
|
+
| `layout(source, options?)` | Frames and element boxes, with diagnostics |
|
|
39
|
+
| `render(source, options?)` | `{ svg, diagnostics }`; `svg` is null when there are errors |
|
|
40
|
+
| `outline(source, options?)` | `{ outline, diagnostics }`: screens, overlays and links |
|
|
41
|
+
| `extractSource(svg)` | The source embedded in an SVG, or null. Treat it as untrusted. |
|
|
42
|
+
|
|
43
|
+
Options (all optional): `themes`, `defaultTheme`, `screen`, `flows`, `notes`, `idPrefix`, `embedSource`. See section 8 of the specification.
|
|
44
|
+
|
|
45
|
+
A host should insert the SVG as a document or parsed DOM, not by concatenating it into HTML, and should set its own limits on time. See section 16 of the specification.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT. See [LICENSE](../../LICENSE) and [NOTICE](../../NOTICE).
|
package/dist/ai-spec.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The one-page description of Wirelith for AI agents, as text. A separate entry point
|
|
4
|
+
* (`@wirelith/core/ai-spec`), so that renderers that don't need it don't carry it.
|
|
5
|
+
*/
|
|
6
|
+
export { AI_SPEC } from './data/ai-spec.js';
|
|
7
|
+
//# sourceMappingURL=ai-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-spec.js","sourceRoot":"","sources":["../src/ai-spec.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SPEC_VERSION } from './parse.js';
|
|
2
|
+
import type { Diagnostic, Document, Options, Outline } from './types.js';
|
|
3
|
+
/** The fixed source of the theme specimen (spec section 9.6). */
|
|
4
|
+
export declare const SPECIMEN_SOURCE = "screen \"Specimen\"\n h1 \"Heading one\"\n h2 \"Heading two\"\n h3 \"Heading three\"\n text \"Body text. The quick brown fox jumps over the lazy dog.\"\n label \"Label text\"\n row\n button \"Primary\" primary\n button \"Secondary\"\n button \"Danger\" danger\n input \"Input\" placeholder=\"Placeholder\"\n row\n checkbox \"Checkbox\" checked\n toggle \"Toggle\" on\n row\n badge \"Default\"\n badge \"Primary\" primary\n badge \"Success\" success\n badge \"Danger\" danger\n card \"Card\"\n text \"Card content\"\n";
|
|
5
|
+
/** Parses a source into its syntax tree (spec section 13), with the syntax diagnostics. */
|
|
6
|
+
export declare function parse(source: string): {
|
|
7
|
+
tree: Document;
|
|
8
|
+
diagnostics: Diagnostic[];
|
|
9
|
+
};
|
|
10
|
+
/** Every diagnostic for a source (spec section 15), sorted. */
|
|
11
|
+
export declare function validate(source: string, options?: Options): Diagnostic[];
|
|
12
|
+
/** The result of `render`: the SVG, or null when the source has errors. */
|
|
13
|
+
export interface RenderResult {
|
|
14
|
+
svg: string | null;
|
|
15
|
+
diagnostics: Diagnostic[];
|
|
16
|
+
}
|
|
17
|
+
/** Renders a source to an SVG document (spec section 12). */
|
|
18
|
+
export declare function render(source: string, options?: Options): RenderResult;
|
|
19
|
+
/** A laid-out element, for tools. */
|
|
20
|
+
export interface LaidOutElement {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
export interface LayoutResult {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
frames: {
|
|
32
|
+
id: string;
|
|
33
|
+
title: string;
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
elements: LaidOutElement[];
|
|
39
|
+
}[];
|
|
40
|
+
diagnostics: Diagnostic[];
|
|
41
|
+
}
|
|
42
|
+
/** Lays out a source (spec section 10). Element positions are relative to their frame. */
|
|
43
|
+
export declare function layout(source: string, options?: Options): LayoutResult;
|
|
44
|
+
/** The outline of a source (spec section 13.2), or null when it has errors. */
|
|
45
|
+
export declare function outline(source: string, options?: Options): {
|
|
46
|
+
outline: Outline | null;
|
|
47
|
+
diagnostics: Diagnostic[];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Reads the source embedded in an SVG (spec section 12.3), or returns null when there is none.
|
|
51
|
+
* The SVG is untrusted: this only searches the text, and the result is untrusted too.
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractSource(svg: string): string | null;
|
|
54
|
+
export { SPEC_VERSION };
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// The public functions. All are pure and synchronous: no I/O, no DOM, no network.
|
|
3
|
+
import { OVERLAYS } from './components.js';
|
|
4
|
+
import { Layout } from './layout.js';
|
|
5
|
+
import { buildOverview, countLinks, frameElements } from './overview.js';
|
|
6
|
+
import { diagnostic, normalizeSource, parse as parseSource, SPEC_VERSION } from './parse.js';
|
|
7
|
+
import { paint } from './render.js';
|
|
8
|
+
import { resolveTheme } from './theme.js';
|
|
9
|
+
import { CAPS, check, hasErrors, sortDiagnostics, textOf, walk } from './validate.js';
|
|
10
|
+
const PREFIX = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
11
|
+
/** The fixed source of the theme specimen (spec section 9.6). */
|
|
12
|
+
export const SPECIMEN_SOURCE = `screen "Specimen"
|
|
13
|
+
h1 "Heading one"
|
|
14
|
+
h2 "Heading two"
|
|
15
|
+
h3 "Heading three"
|
|
16
|
+
text "Body text. The quick brown fox jumps over the lazy dog."
|
|
17
|
+
label "Label text"
|
|
18
|
+
row
|
|
19
|
+
button "Primary" primary
|
|
20
|
+
button "Secondary"
|
|
21
|
+
button "Danger" danger
|
|
22
|
+
input "Input" placeholder="Placeholder"
|
|
23
|
+
row
|
|
24
|
+
checkbox "Checkbox" checked
|
|
25
|
+
toggle "Toggle" on
|
|
26
|
+
row
|
|
27
|
+
badge "Default"
|
|
28
|
+
badge "Primary" primary
|
|
29
|
+
badge "Success" success
|
|
30
|
+
badge "Danger" danger
|
|
31
|
+
card "Card"
|
|
32
|
+
text "Card content"
|
|
33
|
+
`;
|
|
34
|
+
function checkOptions(options) {
|
|
35
|
+
if (options.idPrefix !== undefined && !PREFIX.test(options.idPrefix)) {
|
|
36
|
+
throw new TypeError(`idPrefix "${options.idPrefix}" must match [A-Za-z][A-Za-z0-9_-]*`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Parse, check, resolve the theme, and (when there are no errors and `lay` is set) lay out. */
|
|
40
|
+
function analyse(source, options, lay) {
|
|
41
|
+
checkOptions(options);
|
|
42
|
+
const p = parseSource(source);
|
|
43
|
+
if (p.tooLarge || p.diagnostics.some((d) => d.code === 'E103')) {
|
|
44
|
+
return { tree: p.tree, diagnostics: sortDiagnostics(p.diagnostics) };
|
|
45
|
+
}
|
|
46
|
+
const semantic = check(p.tree);
|
|
47
|
+
if (semantic.length === 1 && semantic[0]?.code === 'E701') {
|
|
48
|
+
return { tree: p.tree, diagnostics: semantic };
|
|
49
|
+
}
|
|
50
|
+
const themeDiagnostics = [];
|
|
51
|
+
const theme = resolveTheme(p.tree, options, p.tokenLines, themeDiagnostics);
|
|
52
|
+
let diagnostics = sortDiagnostics([...p.diagnostics, ...semantic, ...themeDiagnostics]);
|
|
53
|
+
const result = { tree: p.tree, diagnostics, theme };
|
|
54
|
+
if (!lay || hasErrors(diagnostics))
|
|
55
|
+
return result;
|
|
56
|
+
const drawn = p.tree.screens.length > 0 ? p.tree : specimen(theme);
|
|
57
|
+
const overview = buildOverview(drawn, theme, options);
|
|
58
|
+
const extra = [...overview.layout.warnings];
|
|
59
|
+
if (overview.width > CAPS.canvas || overview.height > CAPS.canvas) {
|
|
60
|
+
return {
|
|
61
|
+
tree: p.tree,
|
|
62
|
+
diagnostics: [
|
|
63
|
+
diagnostic('E701', { line: 1, column: 1 }, `The output would be ${overview.width} by ${overview.height} px; the limit is ${CAPS.canvas.toLocaleString('en-US')} px on either side`),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Layout warnings for the specimen belong to the specimen, not the source.
|
|
68
|
+
if (drawn === p.tree)
|
|
69
|
+
diagnostics = sortDiagnostics([...diagnostics, ...extra]);
|
|
70
|
+
return { ...result, diagnostics, overview, drawn };
|
|
71
|
+
}
|
|
72
|
+
function specimen(theme) {
|
|
73
|
+
const doc = parseSource(SPECIMEN_SOURCE).tree;
|
|
74
|
+
const screen = doc.screens[0];
|
|
75
|
+
screen.label = `Theme: ${theme.name}`;
|
|
76
|
+
const swatches = { type: 'swatches', loc: { line: 1, column: 1 } };
|
|
77
|
+
screen.children = [swatches, ...(screen.children ?? [])];
|
|
78
|
+
return doc;
|
|
79
|
+
}
|
|
80
|
+
/** Parses a source into its syntax tree (spec section 13), with the syntax diagnostics. */
|
|
81
|
+
export function parse(source) {
|
|
82
|
+
const p = parseSource(source);
|
|
83
|
+
return { tree: p.tree, diagnostics: sortDiagnostics(p.diagnostics) };
|
|
84
|
+
}
|
|
85
|
+
/** Every diagnostic for a source (spec section 15), sorted. */
|
|
86
|
+
export function validate(source, options = {}) {
|
|
87
|
+
return analyse(source, options, true).diagnostics;
|
|
88
|
+
}
|
|
89
|
+
/** Renders a source to an SVG document (spec section 12). */
|
|
90
|
+
export function render(source, options = {}) {
|
|
91
|
+
const a = analyse(source, options, true);
|
|
92
|
+
if (!a.overview || !a.theme || !a.drawn || hasErrors(a.diagnostics))
|
|
93
|
+
return { svg: null, diagnostics: a.diagnostics };
|
|
94
|
+
const ov = a.overview;
|
|
95
|
+
const shown = [...new Set(ov.frames.map((f) => f.screen))];
|
|
96
|
+
const isSpecimen = a.drawn !== a.tree;
|
|
97
|
+
const title = isSpecimen
|
|
98
|
+
? `Theme: ${a.theme.name}`
|
|
99
|
+
: shown.length === 1
|
|
100
|
+
? (shown[0]?.label ?? '')
|
|
101
|
+
: `${a.drawn.screens.length} screens`;
|
|
102
|
+
const links = isSpecimen ? 0 : countLinks(a.tree);
|
|
103
|
+
const desc = `Screens: ${shown.map((s) => s.label ?? '').join(', ')}. ${links} ${links === 1 ? 'link' : 'links'}.`;
|
|
104
|
+
const input = {
|
|
105
|
+
overview: ov,
|
|
106
|
+
theme: a.theme,
|
|
107
|
+
idPrefix: options.idPrefix ?? 'wl',
|
|
108
|
+
title,
|
|
109
|
+
desc,
|
|
110
|
+
};
|
|
111
|
+
if (options.embedSource !== false)
|
|
112
|
+
input.source = normalizeSource(source).replace(/\r\n?/g, '\n');
|
|
113
|
+
return { svg: paint(input), diagnostics: a.diagnostics };
|
|
114
|
+
}
|
|
115
|
+
/** Lays out a source (spec section 10). Element positions are relative to their frame. */
|
|
116
|
+
export function layout(source, options = {}) {
|
|
117
|
+
const a = analyse(source, options, true);
|
|
118
|
+
if (!a.overview)
|
|
119
|
+
return { width: 0, height: 0, frames: [], diagnostics: a.diagnostics };
|
|
120
|
+
const L = a.overview.layout;
|
|
121
|
+
const key = (n) => n.id ?? `n${L.index.get(n) ?? 0}`;
|
|
122
|
+
return {
|
|
123
|
+
width: a.overview.width,
|
|
124
|
+
height: a.overview.height,
|
|
125
|
+
frames: a.overview.frames.map((f) => ({
|
|
126
|
+
id: f.key,
|
|
127
|
+
title: f.title,
|
|
128
|
+
x: f.x,
|
|
129
|
+
y: f.y,
|
|
130
|
+
width: f.w,
|
|
131
|
+
height: f.h,
|
|
132
|
+
elements: frameElements(f).map((l) => ({
|
|
133
|
+
id: key(l.node),
|
|
134
|
+
type: l.node.type,
|
|
135
|
+
x: l.box.x,
|
|
136
|
+
y: l.box.y,
|
|
137
|
+
width: l.box.w,
|
|
138
|
+
height: l.box.h,
|
|
139
|
+
})),
|
|
140
|
+
})),
|
|
141
|
+
diagnostics: a.diagnostics,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** The outline of a source (spec section 13.2), or null when it has errors. */
|
|
145
|
+
export function outline(source, options = {}) {
|
|
146
|
+
const a = analyse(source, options, false);
|
|
147
|
+
if (hasErrors(a.diagnostics) || !a.theme)
|
|
148
|
+
return { outline: null, diagnostics: a.diagnostics };
|
|
149
|
+
const doc = a.tree;
|
|
150
|
+
const L = new Layout(doc, a.theme);
|
|
151
|
+
const key = (n) => n.id ?? `n${L.index.get(n) ?? 0}`;
|
|
152
|
+
const screens = doc.screens.map((s) => {
|
|
153
|
+
const d = L.device(s);
|
|
154
|
+
const out = {
|
|
155
|
+
id: key(s),
|
|
156
|
+
title: s.label ?? '',
|
|
157
|
+
device: { name: d.name, width: d.w, height: d.h },
|
|
158
|
+
overlays: [],
|
|
159
|
+
};
|
|
160
|
+
const of = s.attrs?.of;
|
|
161
|
+
if (typeof of === 'object' && of !== null && !Array.isArray(of)) {
|
|
162
|
+
out.of = of.ref;
|
|
163
|
+
const state = textOf(s.attrs?.state);
|
|
164
|
+
if (state !== undefined)
|
|
165
|
+
out.state = state;
|
|
166
|
+
}
|
|
167
|
+
out.overlays = (s.children ?? [])
|
|
168
|
+
.filter((c) => OVERLAYS.has(c.type))
|
|
169
|
+
.map((o) => {
|
|
170
|
+
const entry = {
|
|
171
|
+
id: key(o),
|
|
172
|
+
type: o.type,
|
|
173
|
+
open: o.flags?.includes('open') ?? false,
|
|
174
|
+
};
|
|
175
|
+
if (o.label !== undefined) {
|
|
176
|
+
return { id: entry.id, type: entry.type, title: o.label, open: entry.open };
|
|
177
|
+
}
|
|
178
|
+
return entry;
|
|
179
|
+
});
|
|
180
|
+
return out;
|
|
181
|
+
});
|
|
182
|
+
const links = [];
|
|
183
|
+
for (const w of walk(doc)) {
|
|
184
|
+
const n = w.node;
|
|
185
|
+
if (!n.link)
|
|
186
|
+
continue;
|
|
187
|
+
const element = {
|
|
188
|
+
index: w.index,
|
|
189
|
+
type: n.type,
|
|
190
|
+
line: n.loc.line,
|
|
191
|
+
};
|
|
192
|
+
const el = n.id !== undefined ? { id: n.id, ...element } : element;
|
|
193
|
+
const link = {
|
|
194
|
+
kind: 'element',
|
|
195
|
+
from: { screen: key(w.screen), element: el },
|
|
196
|
+
to: n.link.to,
|
|
197
|
+
};
|
|
198
|
+
if (n.link.label !== undefined)
|
|
199
|
+
link.label = n.link.label;
|
|
200
|
+
links.push(link);
|
|
201
|
+
}
|
|
202
|
+
for (const f of doc.flows ?? []) {
|
|
203
|
+
const link = { kind: 'flow', from: { screen: f.from }, to: f.to };
|
|
204
|
+
if (f.label !== undefined)
|
|
205
|
+
link.label = f.label;
|
|
206
|
+
links.push(link);
|
|
207
|
+
}
|
|
208
|
+
return { outline: { screens, links }, diagnostics: a.diagnostics };
|
|
209
|
+
}
|
|
210
|
+
const ENTITY = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
211
|
+
/**
|
|
212
|
+
* Reads the source embedded in an SVG (spec section 12.3), or returns null when there is none.
|
|
213
|
+
* The SVG is untrusted: this only searches the text, and the result is untrusted too.
|
|
214
|
+
*/
|
|
215
|
+
export function extractSource(svg) {
|
|
216
|
+
if (typeof svg !== 'string')
|
|
217
|
+
return null;
|
|
218
|
+
const m = /<wl:source(?:\s[^<>]*)?(?:\/>|>([\s\S]*?)<\/wl:source\s*>)/.exec(svg);
|
|
219
|
+
if (!m)
|
|
220
|
+
return null;
|
|
221
|
+
const raw = m[1] ?? '';
|
|
222
|
+
return raw.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (whole, ent) => {
|
|
223
|
+
if (ent.startsWith('#x'))
|
|
224
|
+
return safeChar(Number.parseInt(ent.slice(2), 16)) ?? whole;
|
|
225
|
+
if (ent.startsWith('#'))
|
|
226
|
+
return safeChar(Number.parseInt(ent.slice(1), 10)) ?? whole;
|
|
227
|
+
return Object.hasOwn(ENTITY, ent) ? ENTITY[ent] : whole;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function safeChar(cp) {
|
|
231
|
+
if (!Number.isInteger(cp) || cp < 0 || cp > 0x10ffff || (cp >= 0xd800 && cp <= 0xdfff))
|
|
232
|
+
return undefined;
|
|
233
|
+
return String.fromCodePoint(cp);
|
|
234
|
+
}
|
|
235
|
+
export { SPEC_VERSION };
|
|
236
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map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
|
3
|
+
flags: readonly string[];
|
|
4
|
+
/** Attributes it defines, besides the common ones. */
|
|
5
|
+
attrs: readonly string[];
|
|
6
|
+
/** Whether its first string means something. */
|
|
7
|
+
label: boolean;
|
|
8
|
+
/** Whether its first list means something. */
|
|
9
|
+
items: boolean;
|
|
10
|
+
/** Whether it takes children. */
|
|
11
|
+
children: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const COMPONENTS: Record<string, ComponentSpec>;
|
|
14
|
+
/**
|
|
15
|
+
* Reads a key only if the object has it as its own property. Keys from a source, such as
|
|
16
|
+
* "constructor" or "toString", must never find something JavaScript objects carry by default.
|
|
17
|
+
*/
|
|
18
|
+
export declare function own<T>(record: Record<string, T>, key: string): T | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Stores a value under a key as a plain own property, even when the key is "__proto__", which an
|
|
21
|
+
* ordinary assignment would treat as the object's prototype instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setOwn<T>(record: Record<string, T>, key: string, value: T): void;
|
|
24
|
+
/** Flags and attributes every element accepts (spec section 5.10). */
|
|
25
|
+
export declare const COMMON_FLAGS: string[];
|
|
26
|
+
export declare const COMMON_ATTRS: string[];
|
|
27
|
+
/** Component names a source may write. `table-row` is written as `row`. */
|
|
28
|
+
export declare const WRITTEN_NAMES: string[];
|
|
29
|
+
export declare const OVERLAYS: Set<string>;
|
|
30
|
+
export declare const SIZES: string[];
|
|
31
|
+
export declare const ALIGNS: string[];
|
|
32
|
+
export declare const JUSTIFIES: string[];
|
|
33
|
+
export declare const INPUT_TYPES: string[];
|
|
34
|
+
export declare const DEVICES: Record<string, [number, number]>;
|
|
35
|
+
/** Common names people write for a component, for "did you mean" hints (spec section 5). */
|
|
36
|
+
export declare const SYNONYMS: Record<string, string>;
|
|
37
|
+
/** The edit distance between two strings, for "did you mean" hints. */
|
|
38
|
+
export declare function distance(a: string, b: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* The closest candidate within a small distance, or undefined. Ties go to the earliest
|
|
41
|
+
* candidate in the order given.
|
|
42
|
+
*/
|
|
43
|
+
export declare function closest(word: string, candidates: Iterable<string>): string | undefined;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
const C = (flags, attrs, label, items, children) => ({ flags, attrs, label, items, children });
|
|
3
|
+
const BOX = ['gap', 'pad', 'align', 'justify'];
|
|
4
|
+
export const COMPONENTS = {
|
|
5
|
+
screen: C(['phone', 'tablet', 'desktop'], ['size', 'of', 'state'], true, false, true),
|
|
6
|
+
row: C(['wrap'], BOX, false, false, true),
|
|
7
|
+
column: C([], BOX, false, false, true),
|
|
8
|
+
grid: C([], ['cols', 'gap', 'pad'], false, false, true),
|
|
9
|
+
spacer: C([], ['size'], false, false, false),
|
|
10
|
+
divider: C([], [], false, false, false),
|
|
11
|
+
header: C([], BOX, false, false, true),
|
|
12
|
+
footer: C([], BOX, false, false, true),
|
|
13
|
+
sidebar: C(['right'], [], false, false, true),
|
|
14
|
+
nav: C(['vertical'], ['active'], false, true, true),
|
|
15
|
+
tabs: C([], ['active'], false, true, true),
|
|
16
|
+
breadcrumbs: C([], [], false, true, false),
|
|
17
|
+
h1: C([], ['align'], true, false, false),
|
|
18
|
+
h2: C([], ['align'], true, false, false),
|
|
19
|
+
h3: C([], ['align'], true, false, false),
|
|
20
|
+
text: C(['muted'], ['align', 'lines'], true, false, false),
|
|
21
|
+
label: C(['muted'], [], true, false, false),
|
|
22
|
+
button: C(['primary', 'secondary', 'danger', 'disabled', 'sm', 'lg'], ['icon'], true, false, false),
|
|
23
|
+
link: C(['disabled'], [], true, false, false),
|
|
24
|
+
input: C(['required', 'disabled'], ['placeholder', 'value', 'type', 'error'], true, false, false),
|
|
25
|
+
textarea: C([], ['placeholder', 'value', 'rows'], true, false, false),
|
|
26
|
+
select: C(['disabled'], ['value', 'placeholder'], true, true, false),
|
|
27
|
+
checkbox: C(['checked', 'on', 'disabled'], [], true, false, false),
|
|
28
|
+
radio: C(['disabled'], ['value'], true, true, false),
|
|
29
|
+
toggle: C(['on', 'checked', 'disabled'], [], true, false, false),
|
|
30
|
+
table: C([], ['rows'], true, true, true),
|
|
31
|
+
'table-row': C(['selected'], [], false, true, false),
|
|
32
|
+
list: C(['ordered'], [], false, true, true),
|
|
33
|
+
item: C(['active'], ['icon', 'badge'], true, false, false),
|
|
34
|
+
card: C([], ['pad', 'gap'], true, false, true),
|
|
35
|
+
image: C([], ['ratio'], true, false, false),
|
|
36
|
+
icon: C(['sm', 'lg'], [], true, false, false),
|
|
37
|
+
badge: C(['primary', 'danger', 'success'], [], true, false, false),
|
|
38
|
+
avatar: C(['sm', 'lg'], [], true, false, false),
|
|
39
|
+
modal: C(['open'], [], true, false, true),
|
|
40
|
+
drawer: C(['open', 'right', 'left', 'bottom'], [], true, false, true),
|
|
41
|
+
empty: C([], [], true, false, true),
|
|
42
|
+
loading: C([], [], true, false, false),
|
|
43
|
+
error: C([], [], true, false, true),
|
|
44
|
+
note: C([], ['for'], true, false, false),
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Reads a key only if the object has it as its own property. Keys from a source, such as
|
|
48
|
+
* "constructor" or "toString", must never find something JavaScript objects carry by default.
|
|
49
|
+
*/
|
|
50
|
+
export function own(record, key) {
|
|
51
|
+
return Object.hasOwn(record, key) ? record[key] : undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Stores a value under a key as a plain own property, even when the key is "__proto__", which an
|
|
55
|
+
* ordinary assignment would treat as the object's prototype instead.
|
|
56
|
+
*/
|
|
57
|
+
export function setOwn(record, key, value) {
|
|
58
|
+
Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true });
|
|
59
|
+
}
|
|
60
|
+
/** Flags and attributes every element accepts (spec section 5.10). */
|
|
61
|
+
export const COMMON_FLAGS = ['grow'];
|
|
62
|
+
export const COMMON_ATTRS = ['width', 'height', 'span'];
|
|
63
|
+
/** Component names a source may write. `table-row` is written as `row`. */
|
|
64
|
+
export const WRITTEN_NAMES = Object.keys(COMPONENTS).filter((n) => n !== 'table-row');
|
|
65
|
+
export const OVERLAYS = new Set(['modal', 'drawer']);
|
|
66
|
+
export const SIZES = ['none', 'xs', 'sm', 'md', 'lg', 'xl'];
|
|
67
|
+
export const ALIGNS = ['start', 'center', 'end', 'stretch'];
|
|
68
|
+
export const JUSTIFIES = ['start', 'center', 'end', 'between'];
|
|
69
|
+
export const INPUT_TYPES = ['text', 'password', 'email', 'number', 'search', 'date'];
|
|
70
|
+
export const DEVICES = {
|
|
71
|
+
phone: [390, 844],
|
|
72
|
+
tablet: [820, 1180],
|
|
73
|
+
desktop: [1280, 800],
|
|
74
|
+
};
|
|
75
|
+
/** Common names people write for a component, for "did you mean" hints (spec section 5). */
|
|
76
|
+
export const SYNONYMS = {
|
|
77
|
+
textfield: 'input',
|
|
78
|
+
textbox: 'input',
|
|
79
|
+
field: 'input',
|
|
80
|
+
dropdown: 'select',
|
|
81
|
+
combobox: 'select',
|
|
82
|
+
picker: 'select',
|
|
83
|
+
navbar: 'nav',
|
|
84
|
+
navigation: 'nav',
|
|
85
|
+
menu: 'nav',
|
|
86
|
+
menubar: 'nav',
|
|
87
|
+
container: 'column',
|
|
88
|
+
div: 'column',
|
|
89
|
+
stack: 'column',
|
|
90
|
+
vstack: 'column',
|
|
91
|
+
hstack: 'row',
|
|
92
|
+
paragraph: 'text',
|
|
93
|
+
p: 'text',
|
|
94
|
+
span: 'text',
|
|
95
|
+
heading: 'h1',
|
|
96
|
+
title: 'h1',
|
|
97
|
+
img: 'image',
|
|
98
|
+
picture: 'image',
|
|
99
|
+
photo: 'image',
|
|
100
|
+
switch: 'toggle',
|
|
101
|
+
dialog: 'modal',
|
|
102
|
+
popup: 'modal',
|
|
103
|
+
sheet: 'drawer',
|
|
104
|
+
panel: 'drawer',
|
|
105
|
+
chip: 'badge',
|
|
106
|
+
tag: 'badge',
|
|
107
|
+
pill: 'badge',
|
|
108
|
+
separator: 'divider',
|
|
109
|
+
hr: 'divider',
|
|
110
|
+
section: 'card',
|
|
111
|
+
box: 'card',
|
|
112
|
+
spinner: 'loading',
|
|
113
|
+
alert: 'error',
|
|
114
|
+
placeholder: 'empty',
|
|
115
|
+
tab: 'tabs',
|
|
116
|
+
crumbs: 'breadcrumbs',
|
|
117
|
+
options: 'radio',
|
|
118
|
+
textinput: 'input',
|
|
119
|
+
password: 'input',
|
|
120
|
+
menuitem: 'item',
|
|
121
|
+
li: 'item',
|
|
122
|
+
ul: 'list',
|
|
123
|
+
ol: 'list',
|
|
124
|
+
tr: 'row',
|
|
125
|
+
td: 'text',
|
|
126
|
+
};
|
|
127
|
+
/** The edit distance between two strings, for "did you mean" hints. */
|
|
128
|
+
export function distance(a, b) {
|
|
129
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
130
|
+
for (let i = 1; i <= a.length; i++) {
|
|
131
|
+
let diag = prev[0] ?? 0;
|
|
132
|
+
prev[0] = i;
|
|
133
|
+
for (let j = 1; j <= b.length; j++) {
|
|
134
|
+
const up = prev[j] ?? 0;
|
|
135
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
136
|
+
prev[j] = Math.min(up + 1, (prev[j - 1] ?? 0) + 1, diag + cost);
|
|
137
|
+
diag = up;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return prev[b.length] ?? 0;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The closest candidate within a small distance, or undefined. Ties go to the earliest
|
|
144
|
+
* candidate in the order given.
|
|
145
|
+
*/
|
|
146
|
+
export function closest(word, candidates) {
|
|
147
|
+
const lower = word.toLowerCase();
|
|
148
|
+
let best;
|
|
149
|
+
let bestD = Math.max(2, Math.floor(word.length / 3)) + 1;
|
|
150
|
+
for (const c of candidates) {
|
|
151
|
+
const d = distance(lower, c);
|
|
152
|
+
if (d < bestD) {
|
|
153
|
+
best = c;
|
|
154
|
+
bestD = d;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return best;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=components.js.map
|