tosijs-floorplan 0.3.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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # tosijs-floorplan
2
+
3
+ Render an **agent-surface map** — plain records describing a UI's wired
4
+ elements — as a floorplan SVG: one shape per element at its true geometry,
5
+ wearing an explicit **affordance grammar** so "can I act here?" never needs
6
+ guessing. Like a floorplan of a building, it documents a *real, live*
7
+ structure — where the doors are, which ones open.
8
+
9
+ It is a **pure function over plain data**. No DOM, no framework, no
10
+ dependencies. The map travels as JSON, so the renderer runs in the page, in
11
+ a headless embodiment, in a test harness, or on the far side of a wire from
12
+ an app nobody is viewing.
13
+
14
+ > **Formerly `tosijs-schematic`** (deprecated on npm at 0.2.0; renamed
15
+ > before its first external consumer shipped). The old name near-collided
16
+ > with [tosijs-schema](https://github.com/tonioloewald/tosijs-schema), the
17
+ > JSON-schema validation library, and confused readers in practice — an
18
+ > honest hazard of real cross-fertilization: schemas become *contracts*,
19
+ > contracts ride the *map*, and the map is what this package draws. The
20
+ > **exported API keeps its names** (`schematic()`, `SchematicRecord`, …):
21
+ > the drawing is still a schematic in the common-noun sense, and the record
22
+ > format is a multi-producer contract mid-adoption.
23
+
24
+ ## Install
25
+
26
+ ```
27
+ npm add tosijs-floorplan
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ With [tosijs](https://tosijs.net), the map draws itself — `describe()`
33
+ output is already the record format:
34
+
35
+ ```js
36
+ import { enableAgentInterface } from 'tosijs'
37
+ import { schematicSVG } from 'tosijs-floorplan'
38
+
39
+ const agent = enableAgentInterface()
40
+ const svg = schematicSVG(agent.describe({ styles: true }))
41
+ ```
42
+
43
+ Without tosijs, emit records yourself — anything that produces them gets
44
+ the renderer and the grammar:
45
+
46
+ ```js
47
+ import { schematicSVG } from 'tosijs-floorplan'
48
+
49
+ const svg = schematicSVG({
50
+ wiring: [
51
+ {
52
+ tag: 'input',
53
+ label: 'quantity',
54
+ value: '3 ⟷ app.qty',
55
+ bounds: { x: 10, y: 10, width: 160, height: 24 },
56
+ },
57
+ {
58
+ tag: 'button',
59
+ text: 'submit',
60
+ on: { click: 'app.submit' },
61
+ bounds: { x: 180, y: 10, width: 80, height: 24 },
62
+ },
63
+ ],
64
+ })
65
+ ```
66
+
67
+ ## The record format (the contract)
68
+
69
+ One flat record per wired element. Producers may add fields beyond these —
70
+ **bound props ride under their own keys** as `"value ⟷ path"` strings.
71
+
72
+ | field | type | meaning |
73
+ | --- | --- | --- |
74
+ | `tag` | `string` | lowercase tag name (required) |
75
+ | `ref` | `string` | a durable, actionable handle from the producer (survives re-renders — an agent can *act* on it, where an index only *looks up*) |
76
+ | `flags` | `{kind, label, severity?}[]` | computed verdicts about the element (contrast ratios, target sizes, …) |
77
+ | `image` | `string` | data-URL snapshot of inline media, drawn in place — pixels a pure renderer can't obtain |
78
+ | `bounds` | `{x, y, width, height}` | page-coordinate geometry — layout is part of the semantics; zero-size or absent = not drawn |
79
+ | `label` | `string` | the accessible **name** (aria-label, resolved labelledby, `<label>` association, title, alt) |
80
+ | `placeholder` | `string` | the hint — deliberately distinct from `label`: an empty input must never read as content |
81
+ | `text` | `string` | textContent, static (`"foo"`) or bound (`"foo ⟵ path"`) |
82
+ | `href` | `string` | a link's destination — distinct from `text` ("the link *says* X" is not "the link *goes to* Y"). Captions fall back to it only when nothing else names the element; it always rides the **legend** |
83
+ | `value` | `string` | a filled control's value, distinct from `label`/`placeholder` — static (`"3"`) or bound (`"3 ⟷ app.qty"`); the fact that distinguishes an empty form from a filled one |
84
+ | `type` | `string` | input kind when not plain text (`checkbox`, `radio`, `range`, `email`, …) |
85
+ | `checked` | `boolean` | live toggle state |
86
+ | `focused` | `boolean` | holds keyboard focus right now |
87
+ | `invalid` | `boolean` | live ValidityState (or aria-invalid) says invalid |
88
+ | `required` | `boolean` | the field is required |
89
+ | `disabled` | `boolean` | disabled right now |
90
+ | `contentEditable` | `boolean` | an editable region — treated as an input field |
91
+ | `on` | `Record<string, string \| string[]>` | handlers by event type — a path when nameable, `ƒ` (or `ƒ name`) when not |
92
+ | `list` | `{path, idPath?}` | this element renders a collection (drawn as *ground*, not figure) |
93
+ | `structural` | `boolean` | structure, not affordance (headings, landmarks, containers) |
94
+ | `viewportFixed` | `boolean` | rides the viewport (fixed/sticky) — bounds are screen coordinates |
95
+ | `style` | `{background, borderColor, color}` | computed colors, worn when present |
96
+ | `id`, `part`, `role`, `description` | `string` | identity and explanation, passed through to consumers |
97
+
98
+ **Provenance tokens** (exported as `BOUND_TO_DOM` / `BOUND_TWO_WAY`): a bound
99
+ value reads `"<shown> <arrow> <path>"` — `⟵` means state flows to the DOM
100
+ (display), `⟷` means two-way (a user-writable affordance). A plain string
101
+ with no arrow is a live-but-unbound value.
102
+
103
+ **The picture is not the whole payload.** The renderer is *allowed to omit*:
104
+ captions and badges below legibility thresholds move to the legend, keyed by
105
+ the stamped index/ref, and facts that never draw well (`href` above all)
106
+ live there always. A consumer of the raster is expected to hold
107
+ `schematic().legend` alongside it — the image says *where* and *which*; the
108
+ legend says *what*.
109
+
110
+ ## The grammar
111
+
112
+ Every rule is **geometry or ASCII** — hard-won: a single exotic glyph can
113
+ tofu an entire caption run under a rasterizer, and text glyphs are mush at
114
+ checkbox sizes.
115
+
116
+ | you see | it means |
117
+ | --- | --- |
118
+ | **bold outline** | wired to act (has handlers) |
119
+ | `↔` badge, bottom-right | editable here (two-way binding, or contenteditable) |
120
+ | caption ending `*` | required |
121
+ | **red corner flag**, top-left | invalid *right now* — live ValidityState, the same truth `:invalid` styles |
122
+ | `✕` filling a box / dot in a circle | checkbox / radio state, live |
123
+ | *italic caption* | placeholder hint — **not** content |
124
+ | faded | disabled right now (beats bold: a disabled button is not an affordance) |
125
+ | double outline | keyboard focus — where the user is |
126
+ | faint dotted | structure — including list *containers* (their items are the affordances) |
127
+ | number, top-right, on a white backdrop | the record's index (`index: true`) — the raster form of `data-record`: read it off the image, look up `wiring[n]` |
128
+ | a `ref` (e.g. `@42`), top-right | the producer's **durable, actionable handle** — takes the index slot when present, survives re-renders, rides the group as `data-ref` |
129
+ | colored bars, left edge | computed **verdicts** (`flags`): WCAG contrast failures and friends — error red, warn amber, info gray, first flag's label shown |
130
+ | pixels inside a box | embedded media (`image`: a data URL) — the producer's snapshot of inline `<svg>`/`<canvas>`, drawn in place |
131
+ | a bare box wearing only a stamped number | too small to label legibly — its caption, badges and flags live in the **legend**, matched by that number |
132
+ | single amber bar, left edge | an interactive element below `targetSize` (default 24×24, WCAG 2.5.8; set 44/48 for the touch-target bar) — a usability defect in its own right; the measurement is in the legend |
133
+ | footer strip: "N elements with details in legend" | the image's confession that it isn't the whole map — fetch `schematic().legend` (a machine-readable `<desc>` says the same) |
134
+
135
+ The target-size audit honours WCAG 2.5.8's **inline exception** as far as
136
+ pure geometry can: a link *with text* is presumed sized by its text and is
137
+ exempt (flagging prose links would fire on every paragraph — a check that
138
+ cries wolf gets ignored, taking the real findings with it). An icon link —
139
+ an `<a>` wrapping an `<svg>`, no text — stays flagged. A producer with DOM
140
+ access can compute the exception *properly* (computed display + parent text
141
+ nodes) and ship the finding via `flags`; a producer flag whose `kind`
142
+ mentions `target` **supersedes** the built-in audit, so the two never
143
+ double-mark.
144
+
145
+ Captions tell the truth in priority order: a held **value** wins (as
146
+ `label: value` when both are known), an empty control falls back to its
147
+ *hint*, then label, then text. Containers holding other drawn boxes get no
148
+ text-derived caption — their children speak. Captions **wrap** when the box
149
+ affords more than one line — a paragraph that wraps on the real page has
150
+ the same vertical room here — and only truncate (with `…`) when the
151
+ geometry genuinely runs out.
152
+
153
+ ## API
154
+
155
+ | export | what |
156
+ | --- | --- |
157
+ | `schematic(description, options?)` | the renderer's primary form — returns `{ svg, legend }`: the drawing plus the metadata it could not legibly carry (cramped/truncated/undersized records), keyed by index/ref. **Pair every raster with its legend.** |
158
+ | `schematicSVG(description, options?)` | `schematic().svg` — the string-only form; each `<g>` carries `data-record="<i>"` linking back to `description.wiring[i]` (the image as index) |
159
+ | `rasterizeSVG(svg, {scale})` | SVG → PNG Blob for vision encoders (browser canvas; under bun/node use `@resvg/resvg-js` — rasterize at 2× so labels OCR cleanly) |
160
+ | `boundsOf(element)` | an element's page-coordinate bounds — the natural `within` argument |
161
+ | `BOUND_TO_DOM`, `BOUND_TWO_WAY` | the provenance tokens |
162
+
163
+ **Options**: `pad`, `minLabelHeight`, `maxCaption`, `fontSize`; `within`
164
+ (a page-coordinate rect — spatial scoping: the viewBox *is* the region);
165
+ `index: true` (stamp record indexes); `targetSize` (the undersized-audit
166
+ floor: 24 default, 44/48 for touch, 0 off); `legendNote: false` (suppress
167
+ the footer strip); `decorate` (below).
168
+
169
+ ## Plugins (EXPERIMENTAL)
170
+
171
+ `decorate` is the extension seam: called once per drawn record, just before
172
+ its `<g>` closes, with the record, its resolved geometry, and an `emit`
173
+ function. The corner slots already spoken for: **top-left** invalid flag,
174
+ **top-right** index, **bottom-right** `↔` badge, **outline** focus/emphasis.
175
+ Claim empty real estate:
176
+
177
+ ```js
178
+ schematicSVG(map, {
179
+ decorate({ record, x, y, width, emit }) {
180
+ if (record.style && contrastRatio(record.style) < 4.5) {
181
+ emit(`<text x="${x + width / 2}" y="${y - 2}" font-size="6"
182
+ text-anchor="middle">contrast!</text>`)
183
+ }
184
+ },
185
+ })
186
+ ```
187
+
188
+ The first real plugins will shape the successor API — if you build one,
189
+ open an issue.
190
+
191
+ ## Provenance
192
+
193
+ Extracted from the [tosijs](https://tosijs.net) *one user interface* work:
194
+ one source of truth for state, UI, and AI, where the agent's map derives
195
+ from what the framework already knows. The grammar here was debugged
196
+ against real rasterizers and real assistive-tech semantics — see the tosijs
197
+ docs for the living demos (a todo list whose map redraws itself, and a
198
+ kitchen-sink truth page).
199
+
200
+ ## License
201
+
202
+ Apache-2.0
@@ -0,0 +1,207 @@
1
+ /**
2
+ * tosijs-floorplan — render an agent-surface map as a floorplan SVG.
3
+ *
4
+ * (Formerly tosijs-schematic — renamed to stop near-colliding with
5
+ * tosijs-schema. Exported API names are unchanged.)
6
+ *
7
+ * A PURE FUNCTION over plain data: one record per wired element, drawn at
8
+ * its true geometry, wearing the affordance grammar. No DOM, no framework,
9
+ * no dependencies — the map travels as JSON, so this runs in the page, in
10
+ * a headless embodiment, or on the far side of a wire from an app nobody
11
+ * is viewing.
12
+ *
13
+ * The RECORD FORMAT is the contract (see README): tosijs's describe()
14
+ * produces it, but anything that emits records gets the renderer — and
15
+ * every consumer inherits the grammar's hard-won rules (geometry over
16
+ * glyphs, hints are not content, ground is not figure).
17
+ */
18
+ /** provenance tokens for bound values: "shown ⟵ path" (display-only) and
19
+ * "shown ⟷ path" (two-way — user-writable). Part of the record format. */
20
+ export declare const BOUND_TO_DOM = "\u27F5";
21
+ export declare const BOUND_TWO_WAY = "\u27F7";
22
+ /**
23
+ * One wired element, flat. Producers may include fields beyond these —
24
+ * bound props ride as "value ⟷ path" strings under their own keys.
25
+ */
26
+ export interface SchematicRecord {
27
+ tag: string;
28
+ id?: string;
29
+ part?: string;
30
+ role?: string;
31
+ label?: string;
32
+ placeholder?: string;
33
+ type?: string;
34
+ checked?: boolean;
35
+ focused?: boolean;
36
+ invalid?: boolean;
37
+ required?: boolean;
38
+ disabled?: boolean;
39
+ contentEditable?: boolean;
40
+ description?: string;
41
+ text?: string;
42
+ on?: Record<string, string | string[]>;
43
+ list?: {
44
+ path: string;
45
+ idPath?: string;
46
+ };
47
+ bounds?: {
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ };
53
+ viewportFixed?: boolean;
54
+ structural?: boolean;
55
+ style?: {
56
+ background: string;
57
+ borderColor: string;
58
+ color: string;
59
+ };
60
+ /** a DURABLE, actionable handle from the producer (haltija's `@42`) —
61
+ * survives re-renders where a wiring index doesn't; rendered in the
62
+ * index slot in preference to the index, and emitted as data-ref */
63
+ ref?: string;
64
+ /** computed verdicts about this element (WCAG contrast failures, etc.) —
65
+ * drawn as severity-colored bars on the LEFT edge (the unclaimed slot),
66
+ * with the first flag's label */
67
+ flags?: Array<{
68
+ kind: string;
69
+ label: string;
70
+ severity?: 'info' | 'warn' | 'error';
71
+ }>;
72
+ /** pixels a pure renderer can't obtain: a data-URL snapshot of inline
73
+ * media (serialized <svg>, <canvas>.toDataURL()) drawn IN PLACE — on an
74
+ * illustration-led page the picture IS the content */
75
+ image?: string;
76
+ /** a link's destination — the most actionable fact about a link, and
77
+ * deliberately distinct from `text` ("the link says X" is not "the link
78
+ * goes to Y"). Captions fall back to it only when nothing else names the
79
+ * element; it ALWAYS rides the legend — URLs are the facts most often
80
+ * too long to draw */
81
+ href?: string;
82
+ /** a filled control's value, distinct from label/placeholder — static
83
+ * ("3") or bound ("3 ⟷ app.qty"). tosijs emits it as a bound prop; the
84
+ * declared field gives plain-DOM producers the same home */
85
+ value?: string;
86
+ [boundProp: string]: unknown;
87
+ }
88
+ /** the map: only `wiring` is read. The named optional fields are the
89
+ * known producer extras (tosijs's describe() shape) — deliberately NOT an
90
+ * index signature, which would stop interface-typed producers (TS gives
91
+ * implicit index signatures to literals, never to interfaces) from
92
+ * assigning without casts. */
93
+ export interface SchematicDescription {
94
+ wiring: SchematicRecord[];
95
+ roots?: unknown;
96
+ actions?: unknown;
97
+ exposure?: unknown;
98
+ contract?: unknown;
99
+ }
100
+ export interface SchematicBounds {
101
+ x: number;
102
+ y: number;
103
+ width: number;
104
+ height: number;
105
+ }
106
+ export interface SchematicOptions {
107
+ /** padding around the drawn region, px (default 8) */
108
+ pad?: number;
109
+ /** boxes shorter than this get no caption (default 14) */
110
+ minLabelHeight?: number;
111
+ /** caption length limit (default 36) */
112
+ maxCaption?: number;
113
+ /** caption font size, px (default 11) */
114
+ fontSize?: number;
115
+ /**
116
+ * Scope the map SPATIALLY: only records whose bounds intersect this
117
+ * page-coordinate rect are drawn, and the viewBox IS the rect — the
118
+ * schematic becomes "this region of the page". Use `boundsOf(element)`
119
+ * to scope to an element's region; omit for the whole map.
120
+ */
121
+ within?: SchematicBounds;
122
+ /**
123
+ * Stamp each box with its wiring index (top-right corner) — the raster
124
+ * form of `data-record`: a vision consumer reads the number off the image
125
+ * and looks the record up in `description.wiring[n]` — image as legend.
126
+ */
127
+ index?: boolean;
128
+ /**
129
+ * Interactive elements (handlers or editable, toggles exempt as
130
+ * user-agent-sized) smaller than this on either axis are flagged
131
+ * undersized — amber bar + legend fact. Default 24 (WCAG 2.5.8 AA);
132
+ * raise to 44/48 for the AAA / platform touch-target bar. 0 disables.
133
+ */
134
+ targetSize?: number;
135
+ /** draw the footer strip advertising the legend when it's non-empty
136
+ * (default true) — the raster must confess what it couldn't carry */
137
+ legendNote?: boolean;
138
+ /**
139
+ * EXPERIMENTAL plugin seam: called once per drawn record, just before
140
+ * its <g> closes — emit extra SVG into the record's group. The corner
141
+ * slots already spoken for: top-left = invalid flag, top-right = index,
142
+ * bottom-right = ↔ badge, outline = focus ring / emphasis. Claim empty
143
+ * real estate; the first real plugins will shape the successor API.
144
+ */
145
+ decorate?: (ctx: {
146
+ record: SchematicRecord;
147
+ index: number;
148
+ x: number;
149
+ y: number;
150
+ width: number;
151
+ height: number;
152
+ structural: boolean;
153
+ emit: (svg: string) => void;
154
+ }) => void;
155
+ }
156
+ /** what the drawing could not legibly carry, keyed back by index/ref —
157
+ * the image's companion JSON. Pair every raster with this. */
158
+ export interface SchematicLegendEntry {
159
+ index: number;
160
+ ref?: string;
161
+ tag: string;
162
+ /** the caption that would have been drawn (or its untruncated form) */
163
+ caption?: string;
164
+ editable?: boolean;
165
+ required?: boolean;
166
+ invalid?: boolean;
167
+ disabled?: boolean;
168
+ flags?: Array<{
169
+ kind: string;
170
+ label: string;
171
+ severity?: 'info' | 'warn' | 'error';
172
+ }>;
173
+ /** the link's destination — carried whenever the record has one */
174
+ href?: string;
175
+ /** the control's held value (provenance stripped), when the drawing
176
+ * elided or truncated it */
177
+ value?: string;
178
+ /** interactive element below the target-size floor, e.g.
179
+ * "18×13 — below 24×24 (WCAG 2.5.8)" */
180
+ undersized?: string;
181
+ }
182
+ export interface SchematicResult {
183
+ svg: string;
184
+ legend: SchematicLegendEntry[];
185
+ }
186
+ /**
187
+ * An element's page-coordinate bounds (the same space describe() records) —
188
+ * the natural `within` argument for a region-scoped schematic.
189
+ */
190
+ export declare const boundsOf: (element: Element) => SchematicBounds;
191
+ export declare const schematic: (description: SchematicDescription, options?: SchematicOptions) => SchematicResult;
192
+ /** the string-only form — schematic().svg, kept for drop-in compatibility */
193
+ export declare const schematicSVG: (description: SchematicDescription, options?: SchematicOptions) => string;
194
+ /**
195
+ * Rasterize an SVG string to a PNG Blob — the vision-encoder form of the map
196
+ * (rasterize at 2× so labels land large enough to OCR near-losslessly).
197
+ *
198
+ * Browser-only by design: it uses Image + canvas, which keeps tosijs at zero
199
+ * dependencies. Under bun/node, use `@resvg/resvg-js` directly instead:
200
+ *
201
+ * const { Resvg } = await import('@resvg/resvg-js')
202
+ * const png = new Resvg(svg, { fitTo: { mode: 'zoom', value: 2 } })
203
+ * .render().asPng()
204
+ */
205
+ export declare const rasterizeSVG: (svg: string, options?: {
206
+ scale?: number;
207
+ }) => Promise<Blob>;