@metamorph-labs/polymorph-screen 0.0.0-stage → 1.0.18
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/CHANGELOG.md +99 -0
- package/LICENSE +21 -0
- package/README.md +148 -2
- package/dist/card.js +1 -0
- package/dist/check.js +1 -0
- package/dist/chunks/card-CVzvz0j_.js +229 -0
- package/dist/chunks/card-CVzvz0j_.js.map +1 -0
- package/dist/chunks/check-BB8y9DW3.js +749 -0
- package/dist/chunks/check-BB8y9DW3.js.map +1 -0
- package/dist/chunks/members-CPUURBV9.js +362 -0
- package/dist/chunks/members-CPUURBV9.js.map +1 -0
- package/dist/chunks/receivers-1COQpnEw.js +332 -0
- package/dist/chunks/receivers-1COQpnEw.js.map +1 -0
- package/dist/chunks/urls-DMQZeRPI.js +127 -0
- package/dist/chunks/urls-DMQZeRPI.js.map +1 -0
- package/dist/chunks/vocabulary-C8KzYJUx.js +64 -0
- package/dist/chunks/vocabulary-C8KzYJUx.js.map +1 -0
- package/dist/chunks/walk-h75fseiY.js +754 -0
- package/dist/chunks/walk-h75fseiY.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/partial.js +290 -0
- package/dist/partial.js.map +1 -0
- package/dist/types/_internal/registry/card-parts.d.ts +37 -0
- package/dist/types/_internal/registry/frameworks.d.ts +272 -0
- package/dist/types/_internal/registry/platforms.d.ts +90 -0
- package/dist/types/_internal/registry/screen-table.d.ts +254 -0
- package/dist/types/_internal/registry/shape.d.ts +128 -0
- package/dist/types/_internal/spec/action-type.d.ts +32 -0
- package/dist/types/_internal/spec/schema.d.ts +68 -0
- package/dist/types/_internal/spec/validate.d.ts +194 -0
- package/dist/types/actions.d.ts +113 -0
- package/dist/types/card.d.ts +26 -0
- package/dist/types/check.d.ts +38 -0
- package/dist/types/depth.d.ts +29 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/json.d.ts +48 -0
- package/dist/types/members.d.ts +106 -0
- package/dist/types/partial.d.ts +64 -0
- package/dist/types/receivers.d.ts +87 -0
- package/dist/types/urls.d.ts +55 -0
- package/dist/types/vocabulary.d.ts +10 -0
- package/dist/types/vocabulary.gen.d.ts +2 -0
- package/dist/types/walk.d.ts +274 -0
- package/dist/vocabulary.js +3 -0
- package/dist/walk.js +1 -0
- package/package.json +58 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @polymorph/screen
|
|
2
|
+
|
|
3
|
+
## 1.0.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ddbd1d4: **Three usage rules for Button, and a destructive Button never takes focus first.**
|
|
8
|
+
|
|
9
|
+
- `@polymorph/rules` gains three red rules, in `stageTwoRules` and so in `allRules`, which
|
|
10
|
+
`polymorph add` applies. An app that upgrades may see new reports from them:
|
|
11
|
+
- `polymorph/one-main-button`: a second main Button (`solid`/`accent`, the defaults) in one
|
|
12
|
+
Dialog, Drawer, Popover, Card or `Dashboard.Panel`.
|
|
13
|
+
- `polymorph/danger-last`: within one group of Buttons placed together, a danger Button
|
|
14
|
+
before another Button.
|
|
15
|
+
- `polymorph/trailing-icon`: a `trailingIcon` that is not a direction or a disclosure. The fix
|
|
16
|
+
moves the role to `icon` when the Button has none.
|
|
17
|
+
|
|
18
|
+
The groups report them as warnings, so a build that passed still passes. Spread the new
|
|
19
|
+
`usageRulesAsErrors` after the groups to make them errors. The rules read TSX, Vue, Svelte,
|
|
20
|
+
Solid and Angular. `@polymorph/rules/usage` holds what they count.
|
|
21
|
+
|
|
22
|
+
- A warning stays a warning past ESLint. `verify`'s `Diagnostic` gains an optional `severity`
|
|
23
|
+
(`error` or `warning`), which `verify` always writes from the linter's result, with
|
|
24
|
+
`isWarning`, `errorsOf` and `warningsOf` beside it. `polymorph check` marks a warning, counts it
|
|
25
|
+
apart and exits 1 on errors only. The MCP server's `validate`, `fix` and `fix_file` return
|
|
26
|
+
warnings in `warnings`, apart from `violations`, and `ok` reads the violations alone.
|
|
27
|
+
`emitCheckedScreen` returns `warnings` beside `violations`, and `emit_screen`, `pnpm emit` and
|
|
28
|
+
the screen scripts write a screen whose code has only warnings. Every existing rule is an
|
|
29
|
+
error, so nothing else changes.
|
|
30
|
+
- `danger-last` reads the Buttons one element holds side by side, up to a `Separator`, as one
|
|
31
|
+
group. A destructive action in a group of its own, apart from the group that holds the main
|
|
32
|
+
Button, may come first.
|
|
33
|
+
- `design/icons.json` marks the roles a trailing icon may take `trailing`: `collapse`, `down`,
|
|
34
|
+
`expand`, `forward`, `next` and `open-external`. The registry publishes it as `icons.trailing`.
|
|
35
|
+
- The validation of a screen spec (`@polymorph/spec/validate`, and `checkScreen` in
|
|
36
|
+
`@polymorph/screen`) reports the same three as faults.
|
|
37
|
+
- `@polymorph/engine`: `modalFocusTarget` never puts focus on a destructive Button when a
|
|
38
|
+
Dialog or a Drawer opens, in any framework. A footer whose rightmost action is destructive
|
|
39
|
+
starts on its leftmost safe action. A footer whose every action is destructive starts in the
|
|
40
|
+
body, else on close. A Dialog with a `tone="danger"` primary used to start on it.
|
|
41
|
+
- `@polymorph/recipes`: a disabled control fades its glyph with its label where it did not:
|
|
42
|
+
Accordion's chevron at rest, a checked and disabled entry's check in Menu, ContextMenu,
|
|
43
|
+
Menubar, SplitButton, Select, Combobox and MultiSelect, a disabled submenu row's chevron, and
|
|
44
|
+
the text of ImageEditor's and FileUpload's drop zones. A danger row's icon in Menu,
|
|
45
|
+
ContextMenu, Menubar and SplitButton takes the row's danger colour, as its spec says.
|
|
46
|
+
|
|
47
|
+
## 1.0.17
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- 14d4d55: The run-time card (`runtimeCard`) says two things a measured run showed a model needs. A member
|
|
52
|
+
that takes the four ARIA props lists them as `aria-*`, and the card says each is written under its
|
|
53
|
+
own name and that no member has a prop named `aria`: a model that read `aria` in a member's line
|
|
54
|
+
wrote a prop of that name, holding an object. The output contract says a control's name is used
|
|
55
|
+
once in a screen, because two forms on one screen each named a field `email` and `values` holds
|
|
56
|
+
one value for a name.
|
|
57
|
+
- 628200f: `@polymorph/screen` is a new package: what a host needs to draw a screen a model writes, at run
|
|
58
|
+
time, with no build. The screen is a `polymorph-screen/1` document, the format `pnpm emit` reads.
|
|
59
|
+
The package has no framework, no DOM and no dependencies:
|
|
60
|
+
|
|
61
|
+
- `VOCABULARY` (`@polymorph/screen/vocabulary`): the members, their props, parts and lawful cells,
|
|
62
|
+
generated from the release's registry.
|
|
63
|
+
- `checkScreen(document, { framework, members })` (`@polymorph/screen/check`): the spec
|
|
64
|
+
validator's faults, in a page or in Node, with no registry, and the faults the walk adds for
|
|
65
|
+
the document: a member the host does not allow, an address that is not relative or `http:`,
|
|
66
|
+
`https:`, `mailto:` or `tel:` (as text, or a flat list of text), a control's name two controls
|
|
67
|
+
share or every object has, an input type or a key over its length limit, a callback input bound where no
|
|
68
|
+
callback receives it, an element in a structured object's field that takes no node, and a
|
|
69
|
+
document nested too deep to read. `ThirdParty` is allowed only where the host names it in
|
|
70
|
+
`members`.
|
|
71
|
+
- `parsePartial(text)` (`@polymorph/screen/partial`): the document a model's streamed answer holds
|
|
72
|
+
so far, prose and a fenced `json` block included.
|
|
73
|
+
- `createScreen(options)` (`@polymorph/screen/walk`): what a renderer draws from a document, the
|
|
74
|
+
host's data and the vocabulary, with actions, controls that follow the reader, named values and
|
|
75
|
+
faults. A callback input is handed by the prop or field it is bound to: where that prop's type
|
|
76
|
+
returns nothing, it is an action the host is told of (`{ name, args, values, changed }`); where
|
|
77
|
+
it returns a value, nothing is passed if it may be left out and a stub answers by that type if it
|
|
78
|
+
is required, and the host is never told; anywhere else, the binding is a fault and nothing is
|
|
79
|
+
passed. An element whose required data prop was never written, or was refused, is not drawn,
|
|
80
|
+
with a fault that names the prop; a slot whose element is a fault leaves its page drawn, while a member that reads one element it
|
|
81
|
+
requires (a FormField's child, a SettingsRow's `control`) is not drawn without it. A
|
|
82
|
+
function in the host's data is never handed to a member as itself. `values` holds what each named control holds, on screen or not, its default or its empty value included, and `changed` names the ones the person chose. An element in a structured
|
|
83
|
+
object is drawn only where the field's data type takes a node, and none at any depth below a
|
|
84
|
+
field that takes data only. Each node's `key` holds a named
|
|
85
|
+
control's name, so a renderer draws a renamed control afresh.
|
|
86
|
+
- A document nests at most `MAX_DEPTH` (128) objects and lists, a declared input type is at most
|
|
87
|
+
`MAX_TYPE_LENGTH` (500) characters, a key a document writes is at most `MAX_KEY_LENGTH` (100)
|
|
88
|
+
characters, and a value reduced to JSON holds at most `MAX_JSON_VALUES` (100,000) values.
|
|
89
|
+
`hostile.test.ts` feeds the core documents and host data written to break it (deep nesting, long
|
|
90
|
+
strings, thousands of children, an unclosed fence, cyclic and shared data, input types and keys
|
|
91
|
+
over their limits): none makes it throw, and for each kind it times, the larger of two sizes
|
|
92
|
+
costs less than twenty times the smaller (eight times the size, for most kinds).
|
|
93
|
+
- `runtimeCard({ framework, members })` (`@polymorph/screen/card`): the text a host puts in the
|
|
94
|
+
model's system prompt: the members it allows, each with its props' types, the data types those
|
|
95
|
+
props take with their fields, and the output contract.
|
|
96
|
+
|
|
97
|
+
- e7f8f9c: The run-time core holds a pager's `previousHref` and `nextHref` and an image's `srcSet` to the
|
|
98
|
+
rule for an address, as it holds `href`, `src` and `avatar`. Each address in a `srcSet` is checked.
|
|
99
|
+
`addressListFault` is exported beside `addressFault`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Metamorph, Inc.
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,149 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @polymorph/screen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Screens a model writes and a host draws at run time.
|
|
4
|
+
|
|
5
|
+
An agent inside a running product (a chat, a copilot panel, a tool result) writes a small
|
|
6
|
+
document, and the host draws it at once, as interactive UI in the host's own theme. The document is
|
|
7
|
+
a `polymorph-screen/1` screen spec: the same format `pnpm emit` turns into source for any framework
|
|
8
|
+
or platform, drawn here without a build. It names members of the vocabulary, their props and the
|
|
9
|
+
inputs they bind to. It has no field for a style and no expression language, so nothing in it runs.
|
|
10
|
+
|
|
11
|
+
This package is what every run-time renderer shares. It has no framework, no DOM and no
|
|
12
|
+
dependencies, and runs in a page, a worker and a server alike.
|
|
13
|
+
|
|
14
|
+
| Import | What it is |
|
|
15
|
+
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
16
|
+
| `@polymorph/screen/vocabulary` | `VOCABULARY`: the members, their props, parts and lawful cells, generated from the registry of the release you install. |
|
|
17
|
+
| `@polymorph/screen/check` | `checkScreen(document, { framework?, members? })`: the spec validator's faults, plus a member the host does not allow and an address a screen may not hold. |
|
|
18
|
+
| `@polymorph/screen/partial` | `parsePartial(text)`: the document a model's answer holds so far, for drawing while it streams. |
|
|
19
|
+
| `@polymorph/screen/walk` | `createScreen(options)`: the document, the host's data and the vocabulary, resolved into what a renderer draws, with actions, controlled values and faults. |
|
|
20
|
+
| `@polymorph/screen/card` | `runtimeCard({ framework?, members? })`: the text a host puts in the model's system prompt. |
|
|
21
|
+
|
|
22
|
+
The root re-exports all of it. Import a subpath to load only what it needs: `parsePartial` loads
|
|
23
|
+
no vocabulary, and the walk loads neither the vocabulary table nor the card.
|
|
24
|
+
|
|
25
|
+
## Drawing a screen
|
|
26
|
+
|
|
27
|
+
A host draws with a renderer, and every renderer draws from `createScreen`, so a document
|
|
28
|
+
behaves the same in each of them:
|
|
29
|
+
|
|
30
|
+
- a data input is filled from the host's `data` by name, and is empty when the host has no value.
|
|
31
|
+
An input whose type is longer than `MAX_TYPE_LENGTH` (500 characters) is a fault, and is data
|
|
32
|
+
with no value;
|
|
33
|
+
- an input whose type is a function is a callback, and what a member is handed for it is decided
|
|
34
|
+
by the prop or the field it is bound to, as a member calls a prop by the prop's type. Where that
|
|
35
|
+
prop's type is a function that returns nothing, it is an action: the host is told
|
|
36
|
+
`{ name, args, values, changed }` when the member calls it, and the member waits on a promise
|
|
37
|
+
the host returns. Where it is a function that returns a value, it is a question the member asks
|
|
38
|
+
while it draws (a row's key, a page's label), which no document can answer at run time: where
|
|
39
|
+
the prop or field may be left out, nothing is passed and the member answers as it does by
|
|
40
|
+
default; where it is required, a stub answers by that type. The host is never told of a
|
|
41
|
+
question. Anywhere else (a text, a child, data, a field of an object type the vocabulary does not
|
|
42
|
+
name), the binding is a fault and nothing is passed;
|
|
43
|
+
- a function in the host's `data` is never handed to a member as itself: a binding whose value is
|
|
44
|
+
a function is a fault, wherever it is bound. Functions inside an object or a list the host binds
|
|
45
|
+
whole (a column's `cell`) are the host's, and are passed as the host gave them;
|
|
46
|
+
- a control keeps what the reader chose, and its value is in `values` under its `name` (see
|
|
47
|
+
below);
|
|
48
|
+
- a component is drawn only if the vocabulary has it and the host allows it (`members`), a prop
|
|
49
|
+
only if the member takes it, a callback only if it is a function, and an object only as the
|
|
50
|
+
format writes one (`{ "$object": … }`);
|
|
51
|
+
- an element is drawn only once every prop a reader needs has a value: a required prop that takes
|
|
52
|
+
data (a label, an `alt`, options), as a member drawn without one is drawn empty or unnamed. One
|
|
53
|
+
whose required data prop was never written, or was refused (a callback bound where none receives
|
|
54
|
+
it, a function in the host's data, an object or an element that is not drawn), is drawn as
|
|
55
|
+
nothing, with a fault that names the prop. Not counted: a required callback, which a stub
|
|
56
|
+
answers; `children`; an address that was refused, as a link or an image without its address
|
|
57
|
+
still reads, and is inert; a required prop bound to data the host has not given yet, drawn
|
|
58
|
+
without it with a fault, so a screen keeps its shape while its data arrives; and a required slot
|
|
59
|
+
(a prop that takes any node, such as a page's `actions`), which leaves the element drawn with
|
|
60
|
+
the slot empty when its element is a fault or is never written. So a fault in one element never
|
|
61
|
+
removes the elements around it, the page above it included. The exception is a member that
|
|
62
|
+
reads one element it requires, as its child (a FormField's control) or in a prop that takes
|
|
63
|
+
exactly one element (a SettingsRow's `control`): it is drawn once that element is; while a
|
|
64
|
+
document streams it waits for it, and once whole, one without an element it can draw is a fault
|
|
65
|
+
(the element above it is drawn). A prop that takes exactly one element and is optional (a
|
|
66
|
+
Dialog's `trigger`, a page's `titleEdit`) is handed a drawn element or nothing: where its element
|
|
67
|
+
is a fault, or it holds no element, it is left out;
|
|
68
|
+
- an element in a structured object is drawn only where the field's data type takes a node (an
|
|
69
|
+
empty state's `action`). A field the type does not declare, or declares as text, numbers or
|
|
70
|
+
booleans, holds no element at any depth: every element below it, through lists and structured
|
|
71
|
+
objects, is left out with one fault at the field, and its other data is kept, so no control
|
|
72
|
+
there holds a value in `values`. In an object whose type the vocabulary does not name (a row of
|
|
73
|
+
the host's own type, a type written out in full), an element is drawn;
|
|
74
|
+
- a key a document writes (a prop's name, a structured object's field) is at most
|
|
75
|
+
`MAX_KEY_LENGTH` (100) characters, as every node below a key carries it in its path; a longer
|
|
76
|
+
one is a fault at its parent, and what it holds is not read;
|
|
77
|
+
- an address (a prop or a field named `avatar`, `href`, `nextHref`, `previousHref`, `src` or
|
|
78
|
+
`srcSet`, whose text is a list of addresses) is passed only as text that is
|
|
79
|
+
relative or `http:`, `https:`, `mailto:` or `tel:`, or a flat list of such text, from the
|
|
80
|
+
document or from the host's data a binding puts there. Data nested inside an object the host
|
|
81
|
+
binds whole is the host's responsibility: the walk passes it as the host gave it;
|
|
82
|
+
- a document nests at most `MAX_DEPTH` (128) objects and lists: `parsePartial` stops reading
|
|
83
|
+
deeper text with an `error`, `checkScreen` reports a fault, and the walk draws nothing deeper.
|
|
84
|
+
An action's `args` and a control's value are reduced to at most `MAX_JSON_VALUES` (100,000)
|
|
85
|
+
values, which bounds host data that shares one object at many levels. No text and no value
|
|
86
|
+
makes `parsePartial`, `checkScreen`, `createScreen` or `update` throw, and each takes time in
|
|
87
|
+
proportion to what it reads;
|
|
88
|
+
- a member that hosts another library's code (`ThirdParty`) is drawn only where the host names it;
|
|
89
|
+
- a node that cannot be drawn is drawn as nothing and reported with its path. Each fault is told
|
|
90
|
+
to `onFault` once in a drawing, by its path and message. A drawing begins when the screen is
|
|
91
|
+
made, when a stream begins, and when the host gives a whole document, not streaming, that
|
|
92
|
+
differs from the one drawn; a stream's chunks and new `data` are the same drawing;
|
|
93
|
+
- while a document streams, an element is drawn once every prop it requires is written and the
|
|
94
|
+
text (`parsePartial`'s `cut`) has moved past its plain props, so a member is never drawn without
|
|
95
|
+
a prop it requires nor with a half-written value, and a page is drawn while the elements in its
|
|
96
|
+
props and its children are still being written; a prop written later arrives when it is whole.
|
|
97
|
+
|
|
98
|
+
### The values of named controls
|
|
99
|
+
|
|
100
|
+
`values`, and the `values` of each action, hold each control that has a `name`, as JSON, by that
|
|
101
|
+
name. A control's value is what the reader sees in it:
|
|
102
|
+
|
|
103
|
+
1. what the reader chose, until the document or the host gives the control another value, or the
|
|
104
|
+
control at that place becomes another component or takes another name;
|
|
105
|
+
2. else the value the document or the host gives it (`value`, or a checkbox's `checked`);
|
|
106
|
+
3. else its default (`defaultValue`, `defaultChecked`);
|
|
107
|
+
4. else the empty value of its type: `null` where the type admits it (a Select with nothing
|
|
108
|
+
chosen, an empty NumberInput or DatePicker), `[]` for a list (MultiSelect, CheckboxGroup),
|
|
109
|
+
`false` for a checkbox or a switch, and `""` for text.
|
|
110
|
+
|
|
111
|
+
A control whose type has none of these is left out until it has a value; every control the
|
|
112
|
+
vocabulary has today has one. A value that is not JSON is reduced to JSON: a date or a time to its
|
|
113
|
+
ISO text. What the reader chose in a control the document gives no value is passed back to the
|
|
114
|
+
member as its default, so a member drawn again, such as a field in a dialog that opens again,
|
|
115
|
+
shows what `values` holds. A renderer keys each node by `key`, which holds a named control's
|
|
116
|
+
name, so a control drawn under another name is drawn afresh.
|
|
117
|
+
|
|
118
|
+
Two controls with one name are a fault, and `values` holds the last of them in document order:
|
|
119
|
+
an element comes before the elements its props hold, those in the order its props are written,
|
|
120
|
+
and then its children. That is the order of the text for a document that writes `props` before
|
|
121
|
+
`children`, as the card asks. A control named `__proto__`, `constructor` or `prototype` is a
|
|
122
|
+
fault, and is left out of `values`, as a host that copies `values` into an object with
|
|
123
|
+
`Object.assign` would set that object's prototype.
|
|
124
|
+
|
|
125
|
+
### What an action is, and is not
|
|
126
|
+
|
|
127
|
+
`values` is what the controls hold, not the person's word. The document wrote each control's
|
|
128
|
+
default and empty value, and chose the action's `name` and what its `args` carry. `changed` names
|
|
129
|
+
the controls whose value the person chose; every other value in `values` is the document's or the
|
|
130
|
+
host's. A host that acts on an action with consequences (a payment, a deletion, a message sent)
|
|
131
|
+
confirms it with the person outside the screen, in its own words, and does not take an action's
|
|
132
|
+
name as what the person meant.
|
|
133
|
+
|
|
134
|
+
## Asking a model for a screen
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { runtimeCard } from '@polymorph/screen/card'
|
|
138
|
+
import { checkScreen } from '@polymorph/screen/check'
|
|
139
|
+
import { parsePartial } from '@polymorph/screen/partial'
|
|
140
|
+
|
|
141
|
+
const members = ['Stack', 'Card', 'Text', 'Button', 'Input', 'FormField']
|
|
142
|
+
const system = runtimeCard({ members })
|
|
143
|
+
// … stream the model's answer into `text` …
|
|
144
|
+
const { document, complete } = parsePartial(text)
|
|
145
|
+
if (complete) console.log(checkScreen(document, { members }).faults)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The card lists only the members the host allows, each with its props and their types, and ends
|
|
149
|
+
with the output contract, so the model needs no tool call.
|
package/dist/card.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as outputContract, n as runtimeCard } from "./chunks/card-CVzvz0j_.js";
|
package/dist/check.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as checkScreen } from "./chunks/check-BB8y9DW3.js";
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { _ as e, g as t, i as n } from "./members-CPUURBV9.js";
|
|
2
|
+
import { c as r, n as i, t as a } from "./urls-DMQZeRPI.js";
|
|
3
|
+
import { t as o } from "./vocabulary-C8KzYJUx.js";
|
|
4
|
+
//#region ../registry/src/card-parts.ts
|
|
5
|
+
var s = /* @__PURE__ */ new Set([
|
|
6
|
+
"children",
|
|
7
|
+
"aria-label",
|
|
8
|
+
"aria-labelledby",
|
|
9
|
+
"aria-describedby",
|
|
10
|
+
"aria-required"
|
|
11
|
+
]), c = [
|
|
12
|
+
"icon",
|
|
13
|
+
"layout",
|
|
14
|
+
"controls",
|
|
15
|
+
"overlays",
|
|
16
|
+
"structure",
|
|
17
|
+
"charts",
|
|
18
|
+
"ai",
|
|
19
|
+
"archetypes"
|
|
20
|
+
], l = {
|
|
21
|
+
icon: "Iconography",
|
|
22
|
+
layout: "Layout primitives",
|
|
23
|
+
controls: "Controls",
|
|
24
|
+
overlays: "Overlays",
|
|
25
|
+
structure: "Structure",
|
|
26
|
+
ai: "AI — the conversation",
|
|
27
|
+
archetypes: "Page archetypes"
|
|
28
|
+
};
|
|
29
|
+
function u(e, t = 84) {
|
|
30
|
+
let n = e.match(/(?:`[^`]*`|[^\s`])+/g) ?? [], r = [], i = "";
|
|
31
|
+
for (let e of n) i !== "" && i.length + 1 + e.length > t ? (r.push(i), i = e) : i = i === "" ? e : `${i} ${e}`;
|
|
32
|
+
return i !== "" && r.push(i), r;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../registry/src/runtime-card.ts
|
|
36
|
+
var d = [...s].filter((e) => e.startsWith("aria-")), f = /^(?:React\.)?(?:ReactNode|ReactElement|ReactPortal)\b|^JSX\.Element\b/, p = /^(?:React\.)?[A-Z]\w*EventHandler(?:<.*>)?$/s, m = /^(?:React\.)?(?:Ref|RefObject|MutableRefObject|RefCallback)</, h = /(?:^|[^\w])(?:\w*Event|HTML\w*Element|Element)(?:<|$)/;
|
|
37
|
+
function g(e) {
|
|
38
|
+
let t = e.trim();
|
|
39
|
+
for (; t.startsWith("(") && _(t, 0) === t.length - 1;) t = t.slice(1, -1).trim();
|
|
40
|
+
return t;
|
|
41
|
+
}
|
|
42
|
+
function _(e, t) {
|
|
43
|
+
let n = 0;
|
|
44
|
+
for (let r = t; r < e.length; r += 1) {
|
|
45
|
+
let t = e[r];
|
|
46
|
+
if ("(<{[".includes(t)) n += 1;
|
|
47
|
+
else if ((")}]".includes(t) || t === ">" && e[r - 1] !== "=") && (--n, n === 0)) return r;
|
|
48
|
+
}
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
function v(e) {
|
|
52
|
+
let t = [], n = 0, r = 0;
|
|
53
|
+
for (let i = 0; i < e.length; i += 1) {
|
|
54
|
+
let a = e[i];
|
|
55
|
+
"(<{[".includes(a) ? n += 1 : ")}]".includes(a) || a === ">" && e[i - 1] !== "=" ? --n : a === "," && n === 0 && (t.push(e.slice(r, i).trim()), r = i + 1);
|
|
56
|
+
}
|
|
57
|
+
let i = e.slice(r).trim();
|
|
58
|
+
return i !== "" && t.push(i), t;
|
|
59
|
+
}
|
|
60
|
+
function y(e, t) {
|
|
61
|
+
let n = g(e);
|
|
62
|
+
if (!n.startsWith("(")) return null;
|
|
63
|
+
let r = _(n, 0);
|
|
64
|
+
if (r === -1) return null;
|
|
65
|
+
let i = n.slice(r + 1).trim();
|
|
66
|
+
return i.startsWith("=>") ? `(${v(n.slice(1, r)).filter((e) => {
|
|
67
|
+
let t = e.indexOf(":");
|
|
68
|
+
return t === -1 || !h.test(e.slice(t + 1).trim());
|
|
69
|
+
}).join(", ")}) => ${b(i.slice(2), t)}` : null;
|
|
70
|
+
}
|
|
71
|
+
function b(t, n) {
|
|
72
|
+
let r = t.replace(/\s+/g, " ").trim().replace(/\?: ([^;{}]+?) \| undefined;/g, "?: $1;"), i = y(r, n);
|
|
73
|
+
if (i !== null) return i;
|
|
74
|
+
let a = e(r);
|
|
75
|
+
if (a.length === 0) return "undefined";
|
|
76
|
+
let o = a.filter((e) => /^"[^"]*"$/.test(e)).map((e) => e.slice(1, -1));
|
|
77
|
+
if (n.size > 0 && o.length === a.length && o.length === n.size && o.every((e) => n.has(e))) return "IconRole";
|
|
78
|
+
let s = a.map((e) => {
|
|
79
|
+
let t = g(e);
|
|
80
|
+
return f.test(t) ? "node" : p.test(t) ? "() => void" : y(t, n) ?? t.replace(/^readonly /, "");
|
|
81
|
+
}), c = s.includes("false") && s.includes("true"), l = s.includes("node"), u = s.filter((e) => (!c || e !== "false" && e !== "true") && (!l || e !== "string" && e !== "number"));
|
|
82
|
+
c && u.unshift("boolean");
|
|
83
|
+
let d = [...new Set(u)];
|
|
84
|
+
return d.map((e) => d.length > 1 && e.includes("=>") ? `(${e})` : e).join("|");
|
|
85
|
+
}
|
|
86
|
+
var x = /=> (?:void|undefined|Promise<(?:void|undefined)>)(?:\|(?:void|undefined|Promise<(?:void|undefined)>))*\)?$/;
|
|
87
|
+
function S(t, n, r = !1) {
|
|
88
|
+
let i = t.filter((t) => !t.name.includes(".") && !e(t.type).every((e) => m.test(e))), a = new Set(i.map((e) => e.name)), o = d.every((e) => a.has(e)), s = i.filter((e) => !(o && d.includes(e.name))).map((e) => {
|
|
89
|
+
let t = b(e.type, n), i = r && w(e.type) && !x.test(t);
|
|
90
|
+
return `${e.name}${e.optional ? "" : "*"}: ${i ? "fn" : t}`;
|
|
91
|
+
});
|
|
92
|
+
return o ? [...s, "aria-*"] : s;
|
|
93
|
+
}
|
|
94
|
+
function C(e, n, r) {
|
|
95
|
+
let i = S(e.props, r);
|
|
96
|
+
e.grid !== null && i.push(`cells: ${Object.entries(e.grid).map(([e, t]) => `${e}(${t.join("|")})`).join(" ")}`);
|
|
97
|
+
let a = e.purpose === "" ? "" : ` — ${e.purpose}`, o = [`- **${e.name}**${a}${i.map((e) => ` · ${e}`).join("")}`];
|
|
98
|
+
for (let i of t(e, "web", n)) {
|
|
99
|
+
let t = e.parts.find((e) => e.name === i.name);
|
|
100
|
+
if (t === void 0) continue;
|
|
101
|
+
let n = S(t.props, r);
|
|
102
|
+
o.push(` - **${e.name}.${i.name}**${n.length === 0 ? "" : ` · ${n.join(" · ")}`}`);
|
|
103
|
+
}
|
|
104
|
+
return o;
|
|
105
|
+
}
|
|
106
|
+
function w(t) {
|
|
107
|
+
let n = t.replace(/\s+/g, " ").trim();
|
|
108
|
+
if (y(n, /* @__PURE__ */ new Set()) !== null) return !0;
|
|
109
|
+
let r = e(n);
|
|
110
|
+
return r.length > 0 && r.every((e) => y(e, /* @__PURE__ */ new Set()) !== null || p.test(g(e)));
|
|
111
|
+
}
|
|
112
|
+
function T(e, n, r, i, a) {
|
|
113
|
+
let o = new Map((e.dataTypes ?? []).map((e) => [e.name, e]));
|
|
114
|
+
if (o.size === 0) return [];
|
|
115
|
+
let s = /* @__PURE__ */ new Set(), c = [], l = (e) => {
|
|
116
|
+
if (!w(e)) for (let t of e.match(/\b[A-Z][A-Za-z0-9]*\b/g) ?? []) o.has(t) && !s.has(t) && (s.add(t), c.push(t));
|
|
117
|
+
};
|
|
118
|
+
for (let e of n) {
|
|
119
|
+
for (let t of e.props) t.name.includes(".") || l(t.type);
|
|
120
|
+
for (let n of t(e, "web", i)) {
|
|
121
|
+
let t = e.parts.find((e) => e.name === n.name);
|
|
122
|
+
for (let e of t?.props ?? []) l(e.type);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (let e of r) for (let t of e.props) l(t.type);
|
|
126
|
+
for (let e = c.shift(); e !== void 0; e = c.shift()) {
|
|
127
|
+
let t = o.get(e);
|
|
128
|
+
for (let e of t?.union ?? []) l(e);
|
|
129
|
+
for (let e of t?.fields ?? []) l(e.type);
|
|
130
|
+
}
|
|
131
|
+
if (s.size === 0) return [];
|
|
132
|
+
let d = new Set(n.map((e) => e.name)), f = [...o.values()].filter((e) => s.has(e.name)).map((e) => {
|
|
133
|
+
let t = `**${e.name}${e.params.length === 0 ? "" : `<${e.params.join(", ")}>`}**`;
|
|
134
|
+
if (e.union !== void 0) return `- ${t} = ${e.union.join(" | ")}`;
|
|
135
|
+
let n = e.name.endsWith("Props") ? e.name.slice(0, -5) : "";
|
|
136
|
+
return d.has(n) ? `- ${t} · the props of \`${n}\`` : `- ${t}${S(e.fields, a, !0).map((e) => ` · ${e}`).join("")}`;
|
|
137
|
+
});
|
|
138
|
+
return [
|
|
139
|
+
"### Data types",
|
|
140
|
+
"",
|
|
141
|
+
...u("A prop typed with one of these takes an object: write it as `{ \"$object\": { … } }` with the fields listed, `*` marking a required one, or bind the prop to an input that holds it. A `node` field takes an element. A function field cannot be written as a value: one shown by its signature returns nothing and takes a binding to an action input of that type; one shown as `fn` returns a value, and a document cannot give it.", 96),
|
|
142
|
+
"",
|
|
143
|
+
...f,
|
|
144
|
+
""
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
function E(e, t) {
|
|
148
|
+
let { framework: n, members: r } = t, i = new Set(e.icons.roles.map((e) => e.name)), a = e.components.filter((e) => r.has(e.name)), o = [
|
|
149
|
+
"## Members",
|
|
150
|
+
"",
|
|
151
|
+
...u(`One line per member: what it is for, then its props as \`name: type\`, \`*\` marking a required one, then its lawful variant × tone \`cells\`; a part (\`Member.Part\`) is a line under its member. \`node\` is an element, a text, or a list of them. A function type is a callback: bind it to an input of that type. \`aria-*\` stands for four props, each written under its own name (${d.map((e) => `\`${e}\``).join(", ")}); no member has a prop named \`aria\`. A member takes no prop it does not list, and takes children only where it lists \`children\`.`, 96),
|
|
152
|
+
""
|
|
153
|
+
], s = [.../* @__PURE__ */ new Set([...c, ...a.map((e) => e.tier)])];
|
|
154
|
+
for (let e of s) {
|
|
155
|
+
let t = a.filter((t) => t.tier === e);
|
|
156
|
+
if (t.length !== 0) {
|
|
157
|
+
o.push(`### ${l[e] ?? e}`, "");
|
|
158
|
+
for (let e of t) o.push(...C(e, n, i));
|
|
159
|
+
o.push("");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
let f = e.exceptions.primitives.filter((e) => r.has(e.name));
|
|
163
|
+
if (f.length > 0) {
|
|
164
|
+
o.push("### Declared exceptions", "");
|
|
165
|
+
for (let e of f) {
|
|
166
|
+
let t = S(e.props, i);
|
|
167
|
+
o.push(`- **${e.name}** (rung ${e.rung}) — ${e.purpose}` + t.map((e) => ` · ${e}`).join(""));
|
|
168
|
+
}
|
|
169
|
+
o.push("");
|
|
170
|
+
}
|
|
171
|
+
return o.push(...T(e, a, f, n, i)), o.some((e) => e.includes("IconRole")) && o.push("### Icon roles", "", ...u(`An \`IconRole\` is a meaning, never a glyph name, and one of: ${e.icons.roles.map((e) => e.name).join(", ")}.`, 96), ""), o.join("\n");
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/card.ts
|
|
175
|
+
var D = (e) => e.length <= 1 ? e.join("") : `${e.slice(0, -1).join(", ")} and ${e.at(-1)}`, O = (e) => `\`${e}\``, k = [
|
|
176
|
+
"# Writing a screen",
|
|
177
|
+
"",
|
|
178
|
+
"You write one screen as a document that names members of a closed vocabulary, their props and",
|
|
179
|
+
"what they hold. The host draws it at once, in its own theme: every colour, space, size and motion",
|
|
180
|
+
"is the theme’s, so a document has no field for a style, a class or an expression. Choose members",
|
|
181
|
+
"and variants; bind content to the inputs the host hands the screen.",
|
|
182
|
+
""
|
|
183
|
+
].join("\n");
|
|
184
|
+
function A(e = {}) {
|
|
185
|
+
let t = e.vocabulary ?? o, s = n(t, e), c = t.exceptions.primitives.filter((e) => s.has(e.name)), l = t.components.filter((e) => s.has(e.name)).filter((e) => e.props.some((e) => e.name === "patch")).map((e) => O(e.name)), u = [...c.map((e) => `${O(e.name)} is rung ${e.rung}`), ...l.length === 0 ? [] : [`a ${O("patch")} prop (on ${D(l)}) is rung 3`]], d = D([...a].map(O)), f = i.map(O), p = [
|
|
186
|
+
"## What you write",
|
|
187
|
+
"",
|
|
188
|
+
`Answer with one document in the ${O(r)} format, as JSON in one fenced \`json\``,
|
|
189
|
+
"block. The host draws it while it arrives, so write its keys in this order: `spec`, `name`,",
|
|
190
|
+
"`purpose`, `inputs`, and `root` last.",
|
|
191
|
+
"",
|
|
192
|
+
`- ${O("spec")} is ${O(JSON.stringify(r))}. ${O("name")} is a PascalCase name for the screen that no member has.`,
|
|
193
|
+
` ${O("purpose")} is one sentence.`,
|
|
194
|
+
"- `inputs` lists what the host hands the screen, each `{ \"name\": …, \"type\": … }`. A data input is",
|
|
195
|
+
" named for a key of the host’s data, and its `type` is a TypeScript type (`string`, `Order[]`);",
|
|
196
|
+
" an input the host has no value for is empty. An input whose type is a function that returns",
|
|
197
|
+
" nothing (`(id: string) => void`) is an action: when a member calls it, the host is told its",
|
|
198
|
+
" name, its arguments and the value of every named control. Bind each callback prop the person",
|
|
199
|
+
" acts through to an action input of the callback’s type. A function that returns a value",
|
|
200
|
+
" (`(row: Row) => string`) is answered with an empty answer and the host is never told.",
|
|
201
|
+
"- `root` is an element: `{ \"component\": …, \"props\": { … }, \"children\": [ … ] }`, `props` and",
|
|
202
|
+
" `children` left out when empty. `component` is a member or a part (`Member.Part`) listed",
|
|
203
|
+
" above. Every prop goes inside `props`, and a member takes no prop and no child it does not list.",
|
|
204
|
+
" Write an element’s plain props before its props that hold elements, and `props` before",
|
|
205
|
+
" `children`: the screen is drawn as it is written, and an element is drawn once its plain",
|
|
206
|
+
" props are whole.",
|
|
207
|
+
"- A value is a string, a number, a boolean, `null`, an element, a list of values, a binding",
|
|
208
|
+
" `{ \"$\": \"input\" }` or `{ \"$\": \"input.field\" }`, or a structured object `{ \"$object\": { … } }`",
|
|
209
|
+
" (an option, a column). A binding names a declared input and is never an expression.",
|
|
210
|
+
"- There is no condition and no loop: every element is drawn whenever the screen is. Content that",
|
|
211
|
+
" is sometimes absent is a prop bound to an input that is empty while there is nothing to show.",
|
|
212
|
+
"- A control with a `name` reports its current value under that name with every action, so name",
|
|
213
|
+
" each field a person fills in. A name is used once in a screen: two forms on one screen name",
|
|
214
|
+
" their fields apart (`signInEmail`, `signUpEmail`), because one name holds one value.",
|
|
215
|
+
`- An address (${d}) is relative, a fragment, or ${f.slice(0, -1).join(", ")} or ${f.at(-1) ?? ""}.`
|
|
216
|
+
];
|
|
217
|
+
return u.length > 0 && p.push(`- A declared exception: ${D(u)}. An element that is one carries`, " `\"exception\": { \"rung\": …, \"because\": \"…\" }`, the reason in four words or more; no other", " element has `exception`."), `${p.join("\n")}\n`;
|
|
218
|
+
}
|
|
219
|
+
function j(e = {}) {
|
|
220
|
+
let t = e.vocabulary ?? o;
|
|
221
|
+
return `${k}\n${E(t, {
|
|
222
|
+
framework: e.framework ?? "react",
|
|
223
|
+
members: n(t, e)
|
|
224
|
+
})}\n${A(e)}`;
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
export { j as n, A as t };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=card-CVzvz0j_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-CVzvz0j_.js","names":["unionParts","shippedParts","allowedMembers","SPEC_ID","ADDRESS_SCHEMES","ADDRESS_KEYS","VOCABULARY","CONVENTION_PROPS","TIER_ORDER","TIER_TITLE","wrapped","words","paragraph","lines","line","word","width","ARIA","name","NODE_TYPE","EVENT_HANDLER_ALIAS","REF_TYPE","DOM_PARAMETER","unwrap","inner","text","closing","depth","at","open","char","commaParts","parts","start","last","functionType","part","end","rest","colon","parameter","cardType","roles","flat","printed","whole","literals","literal","written","bare","boolean","node","kept","distinct","NOTHING","propList","own","props","prop","names","allAria","type","question","questions","isFunctionPrint","memberLines","segments","member","variant","tones","purpose","s","framework","recorded","candidate","dataTypeLines","catalogue","vocabulary","reached","queue","read","listed","primitive","primitives","next","field","members","owner","renderRuntimeCard","options","role","out","tiers","tier","inTier","items","code","OPENING","outputContract","allowed","scopes","patched","rungs","addresses","schemes","runtimeCard"],"sources":["../../../registry/src/card-parts.ts","../../../registry/src/runtime-card.ts","../../src/card.ts"],"sourcesContent":["/**\n * What the system card (`card.ts`) and the run-time card (`runtime-card.ts`)\n * share: the conventions stated once, the tiers' reading order and titles,\n * how a paragraph is wrapped, and how a member React draws through a function\n * is found.\n *\n * It imports nothing, so the run-time card reaches none of the registry\n * builder through it.\n */\n\n/** Conventions the whole vocabulary shares, stated once and omitted from each row. */\nexport const CONVENTION_PROPS: ReadonlySet<string> = new Set([\n 'children',\n 'aria-label',\n 'aria-labelledby',\n 'aria-describedby',\n 'aria-required',\n])\n\n// Content, then data, then pages. This is the reading order `galleries.ts` uses.\nexport const TIER_ORDER: readonly string[] = [\n 'icon',\n 'layout',\n 'controls',\n 'overlays',\n 'structure',\n 'charts',\n 'ai',\n 'archetypes',\n]\n\nexport const TIER_TITLE: Readonly<Record<string, string>> = {\n icon: 'Iconography',\n layout: 'Layout primitives',\n controls: 'Controls',\n overlays: 'Overlays',\n structure: 'Structure',\n ai: 'AI — the conversation',\n archetypes: 'Page archetypes',\n}\n\n/**\n * A paragraph broken into lines of at most `width` characters, at spaces outside\n * a code span, so `polymorph init --framework` stays on one line.\n */\nexport function wrapped(paragraph: string, width = 84): string[] {\n const words = paragraph.match(/(?:`[^`]*`|[^\\s`])+/g) ?? []\n const lines: string[] = []\n let line = ''\n for (const word of words) {\n if (line !== '' && line.length + 1 + word.length > width) {\n lines.push(line)\n line = word\n } else line = line === '' ? word : `${line} ${word}`\n }\n if (line !== '') lines.push(line)\n return lines\n}\n\n/** An export as `optionsCarrier` reads it: its kind and the props it takes. */\ninterface CarrierExport {\n readonly kind: string\n readonly props: readonly { readonly name: string }[]\n}\n\n/**\n * The function export whose options are the member's own props (`toast()` for\n * Toast), or `undefined`. React has no component of the member's name then:\n * a call site calls the function, and the member's props are its options.\n */\nexport function optionsCarrier<Export extends CarrierExport>(component: {\n readonly props: readonly { readonly name: string }[]\n readonly exports: readonly Export[]\n}): Export | undefined {\n const own = component.props.filter((prop) => !prop.name.includes('.'))\n const names = new Set(own.map((prop) => prop.name))\n return component.exports.find(\n (other) =>\n other.kind === 'function' &&\n other.props.length === own.length &&\n other.props.every((prop) => names.has(prop.name)),\n )\n}\n","import { CONVENTION_PROPS, TIER_ORDER, TIER_TITLE, wrapped } from './card-parts'\nimport { shippedParts, unionParts, type Framework, type PartsOwner } from './frameworks'\nimport { DEFAULT_PLATFORM } from './platforms'\n\n/**\n * The run-time card: the members a model may compose in a screen a host draws\n * at run time, each with what the model needs to write it lawfully without a\n * tool call.\n *\n * It is the system card's vocabulary section (`card.ts`) with the prop types\n * written out, because a model with no tool to look a prop up must know what\n * a prop takes: an enum's literals, whether it is text or a node, and the\n * signature of a callback it binds to an action. Everything a screen document\n * cannot use is left out: tokens, the red rules, the ladder beyond the rungs a\n * document declares, install facts, platforms and frameworks other than the\n * one drawing.\n *\n * It reads a vocabulary, not the registry: the registry is one, and the\n * run-time table (`screen-table.ts`) another, so `@polymorph/screen` renders\n * the card from the table a host installed. `packages/screen/src/card.test.ts`\n * holds the two renderings equal. The output contract that follows the card\n * in a model's prompt is the screen package's (`packages/screen/src/card.ts`).\n *\n * This module reads no file, so the browser can import it\n * (`@polymorph/registry/runtime-card`).\n */\n\ninterface CardProp {\n readonly name: string\n readonly type: string\n readonly optional: boolean\n}\n\n/** What the card reads of a member. */\nexport interface RuntimeCardMember extends PartsOwner<{\n readonly name: string\n readonly props: readonly CardProp[]\n}> {\n readonly name: string\n readonly tier: string\n readonly purpose: string\n readonly props: readonly CardProp[]\n readonly grid: Readonly<Record<string, readonly string[]>> | null\n}\n\n/** What the card reads of an exception primitive. */\nexport interface RuntimeCardPrimitive {\n readonly name: string\n readonly rung: number\n readonly purpose: string\n readonly props: readonly CardProp[]\n}\n\n/** What the card reads of a named data type a prop takes: its fields, or the types it is a union of. */\nexport interface RuntimeCardDataType {\n readonly name: string\n readonly params: readonly string[]\n readonly union?: readonly string[]\n readonly fields: readonly CardProp[]\n}\n\n/** What the card reads of a vocabulary: the registry and the run-time table both have it. */\nexport interface RuntimeCardVocabulary {\n readonly components: readonly RuntimeCardMember[]\n readonly exceptions: { readonly primitives: readonly RuntimeCardPrimitive[] }\n readonly icons: { readonly roles: readonly { readonly name: string }[] }\n /** The named data types the props take. A vocabulary without them gets a card without them. */\n readonly dataTypes?: readonly RuntimeCardDataType[]\n}\n\nexport interface RuntimeCardOptions {\n /** The web framework that draws the screen: a member's parts are the ones it carries. */\n readonly framework: Framework\n /** The members and exception primitives the host allows, by name. Every other is left out. */\n readonly members: ReadonlySet<string>\n}\n\n/**\n * The ARIA hooks a member takes, written once as `aria-*` on a member that takes all four.\n * The mark is not a word a document could hold as a key: a model that read `aria` in a\n * member's line wrote a prop of that name, holding an object.\n */\nconst ARIA = [...CONVENTION_PROPS].filter((name) => name.startsWith('aria-'))\n\n/** A type the vocabulary draws as a node: an element, a text, or a list of them. */\nconst NODE_TYPE = /^(?:React\\.)?(?:ReactNode|ReactElement|ReactPortal)\\b|^JSX\\.Element\\b/\n\n/** A React handler alias (`ReactEventHandler<T>`): a function of one DOM event, which an action does not receive. */\nconst EVENT_HANDLER_ALIAS = /^(?:React\\.)?[A-Z]\\w*EventHandler(?:<.*>)?$/s\n\n/** A ref, which an element holds in code and a document cannot write. */\nconst REF_TYPE = /^(?:React\\.)?(?:Ref|RefObject|MutableRefObject|RefCallback)</\n\n/** A parameter a callback receives that a document's action cannot use: a DOM event or element. */\nconst DOM_PARAMETER = /(?:^|[^\\w])(?:\\w*Event|HTML\\w*Element|Element)(?:<|$)/\n\n/** The text without the parentheses around all of it. */\nfunction unwrap(text: string): string {\n let inner = text.trim()\n while (inner.startsWith('(') && closing(inner, 0) === inner.length - 1) {\n inner = inner.slice(1, -1).trim()\n }\n return inner\n}\n\n/** The index of the bracket that closes the one at `open`, or -1. */\nfunction closing(text: string, open: number): number {\n let depth = 0\n for (let at = open; at < text.length; at += 1) {\n const char = text[at] as string\n if ('(<{['.includes(char)) depth += 1\n else if (')}]'.includes(char) || (char === '>' && text[at - 1] !== '=')) {\n depth -= 1\n if (depth === 0) return at\n }\n }\n return -1\n}\n\n/** The text split at each top-level comma. */\nfunction commaParts(text: string): string[] {\n const parts: string[] = []\n let depth = 0\n let start = 0\n for (let at = 0; at < text.length; at += 1) {\n const char = text[at] as string\n if ('(<{['.includes(char)) depth += 1\n else if (')}]'.includes(char) || (char === '>' && text[at - 1] !== '=')) depth -= 1\n else if (char === ',' && depth === 0) {\n parts.push(text.slice(start, at).trim())\n start = at + 1\n }\n }\n const last = text.slice(start).trim()\n if (last !== '') parts.push(last)\n return parts\n}\n\n/** A function type as the card writes it, or `null` when the text is not one. */\nfunction functionType(part: string, roles: ReadonlySet<string>): string | null {\n const text = unwrap(part)\n if (!text.startsWith('(')) return null\n const end = closing(text, 0)\n if (end === -1) return null\n const rest = text.slice(end + 1).trim()\n if (!rest.startsWith('=>')) return null\n const parameters = commaParts(text.slice(1, end)).filter((parameter) => {\n const colon = parameter.indexOf(':')\n return colon === -1 || !DOM_PARAMETER.test(parameter.slice(colon + 1).trim())\n })\n return `(${parameters.join(', ')}) => ${cardType(rest.slice(2), roles)}`\n}\n\n/**\n * A printed prop type as the card writes it: `undefined` left out, because\n * `*` marks a required prop and `?` an optional field; an icon role union as\n * `IconRole`, which the card lists once; `false | true` as `boolean`; a React\n * node type as `node`; a callback without the DOM event it is handed, which\n * an action does not receive; and the parts of a union joined by `|`, a\n * function among them in parentheses.\n */\nexport function cardType(printed: string, roles: ReadonlySet<string>): string {\n // An optional field of an object type says `?` already: `skipToContent?: string`.\n const flat = printed\n .replace(/\\s+/g, ' ')\n .trim()\n .replace(/\\?: ([^;{}]+?) \\| undefined;/g, '?: $1;')\n // A function's result runs to the end of the text: `() => void | Promise<void>` is one\n // function, as the validator reads it (`isActionType`), not a union with a promise.\n const whole = functionType(flat, roles)\n if (whole !== null) return whole\n const parts = unionParts(flat)\n if (parts.length === 0) return 'undefined'\n const literals = parts.filter((part) => /^\"[^\"]*\"$/.test(part)).map((part) => part.slice(1, -1))\n if (\n roles.size > 0 &&\n literals.length === parts.length &&\n literals.length === roles.size &&\n literals.every((literal) => roles.has(literal))\n ) {\n return 'IconRole'\n }\n const written = parts.map((part) => {\n const bare = unwrap(part)\n if (NODE_TYPE.test(bare)) return 'node'\n if (EVENT_HANDLER_ALIAS.test(bare)) return '() => void'\n return functionType(bare, roles) ?? bare.replace(/^readonly /, '')\n })\n const boolean = written.includes('false') && written.includes('true')\n const node = written.includes('node')\n const kept = written.filter(\n (part) =>\n !(boolean && (part === 'false' || part === 'true')) &&\n // A node is already a text or a number.\n !(node && (part === 'string' || part === 'number')),\n )\n if (boolean) kept.unshift('boolean')\n const distinct = [...new Set(kept)]\n // A function in a union is parenthesised, so its result does not read as part of the union.\n return distinct\n .map((part) => (distinct.length > 1 && part.includes('=>') ? `(${part})` : part))\n .join('|')\n}\n\n/** A function's printed result that is nothing: what an action returns. */\nconst NOTHING =\n /=> (?:void|undefined|Promise<(?:void|undefined)>)(?:\\|(?:void|undefined|Promise<(?:void|undefined)>))*\\)?$/\n\n/**\n * `name: type`, `*` marking a required one; the four ARIA hooks as `aria-*`\n * where all four are taken. A ref is left out, as a document cannot hold one.\n * With `questions`, a function that returns a value is written `fn`: a\n * data type's field of that kind cannot be given by a document at all, so its\n * signature says nothing a document can use.\n */\nfunction propList(\n props: readonly CardProp[],\n roles: ReadonlySet<string>,\n questions = false,\n): string[] {\n const own = props.filter(\n (prop) =>\n !prop.name.includes('.') && !unionParts(prop.type).every((part) => REF_TYPE.test(part)),\n )\n const names = new Set(own.map((prop) => prop.name))\n const allAria = ARIA.every((name) => names.has(name))\n const written = own\n .filter((prop) => !(allAria && ARIA.includes(prop.name)))\n .map((prop) => {\n const type = cardType(prop.type, roles)\n const question = questions && isFunctionPrint(prop.type) && !NOTHING.test(type)\n return `${prop.name}${prop.optional ? '' : '*'}: ${question ? 'fn' : type}`\n })\n return allAria ? [...written, 'aria-*'] : written\n}\n\n/** One member, then a line under it for each part the framework carries. */\nfunction memberLines(\n member: RuntimeCardMember,\n framework: Framework,\n roles: ReadonlySet<string>,\n): string[] {\n const segments = propList(member.props, roles)\n if (member.grid !== null) {\n segments.push(\n `cells: ${Object.entries(member.grid)\n .map(([variant, tones]) => `${variant}(${tones.join('|')})`)\n .join(' ')}`,\n )\n }\n const purpose = member.purpose === '' ? '' : ` — ${member.purpose}`\n const lines = [`- **${member.name}**${purpose}${segments.map((s) => ` · ${s}`).join('')}`]\n for (const part of shippedParts(member, DEFAULT_PLATFORM, framework)) {\n // A part whose props the registry does not record cannot be checked, so a document cannot compose it.\n const recorded = member.parts.find((candidate) => candidate.name === part.name)\n if (recorded === undefined) continue\n const props = propList(recorded.props, roles)\n lines.push(\n ` - **${member.name}.${part.name}**${props.length === 0 ? '' : ` · ${props.join(' · ')}`}`,\n )\n }\n return lines\n}\n\n/** Whether a printed type is a function, alone or in a union with `undefined`: a callback, not data. */\nfunction isFunctionPrint(printed: string): boolean {\n const flat = printed.replace(/\\s+/g, ' ').trim()\n if (functionType(flat, new Set()) !== null) return true\n const parts = unionParts(flat)\n return (\n parts.length > 0 &&\n parts.every(\n (part) => functionType(part, new Set()) !== null || EVENT_HANDLER_ALIAS.test(unwrap(part)),\n )\n )\n}\n\n/**\n * The data types section: each named data type the listed members' props\n * take, the types those types' fields take, and so on, each printed once,\n * sorted by name. A callback's parameters are not data a document writes,\n * so a type only a callback names is left out. A type that is the props of\n * a listed member (`StatProps`) points at the member's line.\n */\nfunction dataTypeLines(\n vocabulary: RuntimeCardVocabulary,\n listed: readonly RuntimeCardMember[],\n primitives: readonly RuntimeCardPrimitive[],\n framework: Framework,\n roles: ReadonlySet<string>,\n): string[] {\n const catalogue = new Map((vocabulary.dataTypes ?? []).map((type) => [type.name, type]))\n if (catalogue.size === 0) return []\n const reached = new Set<string>()\n const queue: string[] = []\n const read = (printed: string) => {\n if (isFunctionPrint(printed)) return\n for (const name of printed.match(/\\b[A-Z][A-Za-z0-9]*\\b/g) ?? []) {\n if (catalogue.has(name) && !reached.has(name)) {\n reached.add(name)\n queue.push(name)\n }\n }\n }\n for (const member of listed) {\n for (const prop of member.props) if (!prop.name.includes('.')) read(prop.type)\n for (const part of shippedParts(member, DEFAULT_PLATFORM, framework)) {\n const recorded = member.parts.find((candidate) => candidate.name === part.name)\n for (const prop of recorded?.props ?? []) read(prop.type)\n }\n }\n for (const primitive of primitives) for (const prop of primitive.props) read(prop.type)\n for (let next = queue.shift(); next !== undefined; next = queue.shift()) {\n const type = catalogue.get(next)\n for (const member of type?.union ?? []) read(member)\n for (const field of type?.fields ?? []) read(field.type)\n }\n if (reached.size === 0) return []\n\n const members = new Set(listed.map((member) => member.name))\n const lines = [...catalogue.values()]\n .filter((type) => reached.has(type.name))\n .map((type) => {\n const name = `**${type.name}${type.params.length === 0 ? '' : `<${type.params.join(', ')}>`}**`\n if (type.union !== undefined) return `- ${name} = ${type.union.join(' | ')}`\n const owner = type.name.endsWith('Props') ? type.name.slice(0, -'Props'.length) : ''\n if (members.has(owner)) return `- ${name} · the props of \\`${owner}\\``\n return `- ${name}${propList(type.fields, roles, true)\n .map((field) => ` · ${field}`)\n .join('')}`\n })\n return [\n '### Data types',\n '',\n ...wrapped(\n 'A prop typed with one of these takes an object: write it as `{ \"$object\": { … } }` with ' +\n 'the fields listed, `*` marking a required one, or bind the prop to an input that holds ' +\n 'it. A `node` field takes an element. A function field cannot be written as a value: one ' +\n 'shown by its signature returns nothing and takes a binding to an action input of that ' +\n 'type; one shown as `fn` returns a value, and a document cannot give it.',\n 96,\n ),\n '',\n ...lines,\n '',\n ]\n}\n\n/**\n * The card's members section, for the members a host allows: a legend, the\n * members tier by tier in the system card's reading order, the exception\n * primitives, the data types their props take, and the icon roles when a\n * member listed takes one.\n */\nexport function renderRuntimeCard(\n vocabulary: RuntimeCardVocabulary,\n options: RuntimeCardOptions,\n): string {\n const { framework, members } = options\n const roles = new Set(vocabulary.icons.roles.map((role) => role.name))\n const listed = vocabulary.components.filter((member) => members.has(member.name))\n const out: string[] = [\n '## Members',\n '',\n ...wrapped(\n 'One line per member: what it is for, then its props as `name: type`, `*` marking a ' +\n 'required one, then its lawful variant × tone `cells`; a part (`Member.Part`) is a line ' +\n 'under its member. `node` is an element, a text, or a list of them. A function type is ' +\n 'a callback: bind it to an input of that type. `aria-*` stands for four props, each ' +\n `written under its own name (${ARIA.map((name) => `\\`${name}\\``).join(', ')}); no member ` +\n 'has a prop named `aria`. A member takes no prop it does not list, and takes children ' +\n 'only where it lists `children`.',\n 96,\n ),\n '',\n ]\n\n const tiers = [...new Set([...TIER_ORDER, ...listed.map((member) => member.tier)])]\n for (const tier of tiers) {\n const inTier = listed.filter((member) => member.tier === tier)\n if (inTier.length === 0) continue\n out.push(`### ${TIER_TITLE[tier] ?? tier}`, '')\n for (const member of inTier) out.push(...memberLines(member, framework, roles))\n out.push('')\n }\n\n const primitives = vocabulary.exceptions.primitives.filter((primitive) =>\n members.has(primitive.name),\n )\n if (primitives.length > 0) {\n out.push('### Declared exceptions', '')\n for (const primitive of primitives) {\n const props = propList(primitive.props, roles)\n out.push(\n `- **${primitive.name}** (rung ${primitive.rung}) — ${primitive.purpose}` +\n props.map((prop) => ` · ${prop}`).join(''),\n )\n }\n out.push('')\n }\n\n out.push(...dataTypeLines(vocabulary, listed, primitives, framework, roles))\n\n if (out.some((line) => line.includes('IconRole'))) {\n out.push(\n '### Icon roles',\n '',\n ...wrapped(\n 'An `IconRole` is a meaning, never a glyph name, and one of: ' +\n `${vocabulary.icons.roles.map((role) => role.name).join(', ')}.`,\n 96,\n ),\n '',\n )\n }\n return out.join('\\n')\n}\n","import { DEFAULT_FRAMEWORK } from '@polymorph/registry/frameworks'\nimport { renderRuntimeCard } from '@polymorph/registry/runtime-card'\nimport { SPEC_ID } from '@polymorph/spec/schema'\n\nimport { allowedMembers, type MemberOptions, type ScreenVocabulary } from './members'\nimport { ADDRESS_KEYS, ADDRESS_SCHEMES } from './urls'\nimport { VOCABULARY } from './vocabulary'\n\n/**\n * The run-time card: what a host puts in a model's system prompt so the\n * model writes a screen the host can draw, in one call, with no tool.\n *\n * It has three parts. The opening says what the model is doing. The members\n * section is the registry's (`renderRuntimeCard` in\n * `packages/registry/src/runtime-card.ts`), rendered from the vocabulary\n * table the host installed, for the members the host allows. The output\n * contract says what the answer is: one `polymorph-screen/1` document, and\n * what the host does with each part of it at run time. A host builds its\n * prompt from the version it runs, so the card never names a member the host\n * cannot draw.\n */\n\nexport interface CardOptions extends MemberOptions {\n /** The vocabulary to describe. The generated table when absent. */\n vocabulary?: ScreenVocabulary\n}\n\n/** `a`, `a and b`, `a, b and c`. */\nconst listed = (items: readonly string[]): string =>\n items.length <= 1 ? items.join('') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`\n\nconst code = (text: string) => `\\`${text}\\``\n\n/** The opening: what the model is asked to do, and what it cannot do. */\nconst OPENING = [\n '# Writing a screen',\n '',\n 'You write one screen as a document that names members of a closed vocabulary, their props and',\n 'what they hold. The host draws it at once, in its own theme: every colour, space, size and motion',\n 'is the theme’s, so a document has no field for a style, a class or an expression. Choose members',\n 'and variants; bind content to the inputs the host hands the screen.',\n '',\n].join('\\n')\n\n/** The output contract, for the members a host allows. */\nexport function outputContract(options: CardOptions = {}): string {\n const vocabulary = options.vocabulary ?? VOCABULARY\n const allowed = allowedMembers(vocabulary, options)\n const scopes = vocabulary.exceptions.primitives.filter((primitive) => allowed.has(primitive.name))\n const patched = vocabulary.components\n .filter((member) => allowed.has(member.name))\n .filter((member) => member.props.some((prop) => prop.name === 'patch'))\n .map((member) => code(member.name))\n const rungs = [\n ...scopes.map((primitive) => `${code(primitive.name)} is rung ${primitive.rung}`),\n ...(patched.length === 0 ? [] : [`a ${code('patch')} prop (on ${listed(patched)}) is rung 3`]),\n ]\n const addresses = listed([...ADDRESS_KEYS].map(code))\n const schemes = ADDRESS_SCHEMES.map(code)\n\n const lines = [\n '## What you write',\n '',\n `Answer with one document in the ${code(SPEC_ID)} format, as JSON in one fenced \\`json\\``,\n 'block. The host draws it while it arrives, so write its keys in this order: `spec`, `name`,',\n '`purpose`, `inputs`, and `root` last.',\n '',\n `- ${code('spec')} is ${code(JSON.stringify(SPEC_ID))}. ${code('name')} is a PascalCase name for the screen that no member has.`,\n ` ${code('purpose')} is one sentence.`,\n '- `inputs` lists what the host hands the screen, each `{ \"name\": …, \"type\": … }`. A data input is',\n ' named for a key of the host’s data, and its `type` is a TypeScript type (`string`, `Order[]`);',\n ' an input the host has no value for is empty. An input whose type is a function that returns',\n ' nothing (`(id: string) => void`) is an action: when a member calls it, the host is told its',\n ' name, its arguments and the value of every named control. Bind each callback prop the person',\n ' acts through to an action input of the callback’s type. A function that returns a value',\n ' (`(row: Row) => string`) is answered with an empty answer and the host is never told.',\n '- `root` is an element: `{ \"component\": …, \"props\": { … }, \"children\": [ … ] }`, `props` and',\n ' `children` left out when empty. `component` is a member or a part (`Member.Part`) listed',\n ' above. Every prop goes inside `props`, and a member takes no prop and no child it does not list.',\n ' Write an element’s plain props before its props that hold elements, and `props` before',\n ' `children`: the screen is drawn as it is written, and an element is drawn once its plain',\n ' props are whole.',\n '- A value is a string, a number, a boolean, `null`, an element, a list of values, a binding',\n ' `{ \"$\": \"input\" }` or `{ \"$\": \"input.field\" }`, or a structured object `{ \"$object\": { … } }`',\n ' (an option, a column). A binding names a declared input and is never an expression.',\n '- There is no condition and no loop: every element is drawn whenever the screen is. Content that',\n ' is sometimes absent is a prop bound to an input that is empty while there is nothing to show.',\n '- A control with a `name` reports its current value under that name with every action, so name',\n ' each field a person fills in. A name is used once in a screen: two forms on one screen name',\n ' their fields apart (`signInEmail`, `signUpEmail`), because one name holds one value.',\n `- An address (${addresses}) is relative, a fragment, or ${schemes.slice(0, -1).join(', ')} or ${schemes.at(-1) ?? ''}.`,\n ]\n if (rungs.length > 0) {\n lines.push(\n `- A declared exception: ${listed(rungs)}. An element that is one carries`,\n ' `\"exception\": { \"rung\": …, \"because\": \"…\" }`, the reason in four words or more; no other',\n ' element has `exception`.',\n )\n }\n return `${lines.join('\\n')}\\n`\n}\n\n/**\n * The run-time card for the members a host allows: the opening, the members\n * section and the output contract. Its default is every member the\n * framework draws but those that host another library's code.\n */\nexport function runtimeCard(options: CardOptions = {}): string {\n const vocabulary = options.vocabulary ?? VOCABULARY\n const members = renderRuntimeCard(vocabulary, {\n framework: options.framework ?? DEFAULT_FRAMEWORK,\n members: allowedMembers(vocabulary, options),\n })\n return `${OPENING}\\n${members}\\n${outputContract(options)}`\n}\n"],"mappings":";;;;AAWA,IAAaO,oBAAwC,IAAI,IAAI;CAC3D;CACA;CACA;CACA;CACA;AACF,CAAC,GAGYC,IAAgC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEaC,IAA+C;CAC1D,MAAM;CACN,QAAQ;CACR,UAAU;CACV,UAAU;CACV,WAAW;CACX,IAAI;CACJ,YAAY;AACd;AAMA,SAAgBC,EAAQ,GAAmB,IAAQ,IAAc;CAC/D,IAAMC,IAAQC,EAAU,MAAM,sBAAsB,KAAK,CAAC,GACpDC,IAAkB,CAAC,GACrBC,IAAO;CAC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