@floless/app 0.131.1 → 0.132.1
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/dist/floless-server.cjs +2374 -1901
- package/dist/schemas/steel.model.v2.schema.json +3 -1
- package/dist/skills/floless-app-onboarding/SKILL.md +12 -2
- package/dist/skills/floless-app-queue/SKILL.md +2 -2
- package/dist/web/app.css +359 -0
- package/dist/web/app.js +22 -0
- package/dist/web/aware.js +121 -13
- package/dist/web/commands-filter.js +157 -0
- package/dist/web/commands-shell.js +1316 -0
- package/dist/web/commands-steel.js +1829 -0
- package/dist/web/commands-vector.js +154 -0
- package/dist/web/commands-vector3d.js +96 -0
- package/dist/web/commands.js +316 -0
- package/dist/web/grid-core.js +124 -23
- package/dist/web/index.html +269 -164
- package/dist/web/instructor-reporter.js +201 -0
- package/dist/web/instructor.js +1178 -0
- package/dist/web/reference-geometry-worker.js +194 -0
- package/dist/web/steel-3d-core.js +486 -107
- package/dist/web/steel-3d-view.js +847 -204
- package/dist/web/steel-canvas-guidance.js +7 -4
- package/dist/web/steel-editor.html +1620 -1799
- package/dist/web/steel-filter-core.js +13 -5
- package/dist/web/steel-filter.html +36 -22
- package/dist/web/steel-model-adapter.js +17 -22
- package/dist/web/steel-model-commands.js +23 -10
- package/dist/web/steel-model-v2-client-validation.js +20 -3
- package/dist/web/steel-model-v2-commands.js +91 -3
- package/dist/web/steel-model-v2-projection.js +4 -5
- package/dist/web/steel-plan-transform.js +4 -8
- package/dist/web/steel-split-view.js +33 -0
- package/dist/web/vector-3d.html +19 -7
- package/dist/web/vector-editor.html +21 -8
- package/dist/web/workspaces.js +12 -25
- package/package.json +10 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/* ──────────────────────────────────────────────────────────────────────────
|
|
2
|
+
Trace (vector editor) capability registrations (vector-editor.html).
|
|
3
|
+
|
|
4
|
+
Same shape and the same two-documents rule as commands-steel.js: this file
|
|
5
|
+
loads in vector-editor.html AND in index.html, because the shell is the sole
|
|
6
|
+
guidance producer and must be able to resolve an id arriving over the
|
|
7
|
+
reporter seam.
|
|
8
|
+
|
|
9
|
+
── Why NOTHING here is 'active-command' ─────────────────────────────────
|
|
10
|
+
This surface arms nothing — verified by reading every handler in the page,
|
|
11
|
+
not inferred. Export, Fit, the zoom slider, the kind/layer/confidence
|
|
12
|
+
checkboxes and the weak-list Accept/Delete buttons all act immediately;
|
|
13
|
+
clicking the canvas locates a trace rather than starting a sequence. There is
|
|
14
|
+
no mode to be in, so there are no steps to narrate, and inventing some would
|
|
15
|
+
put a step counter on a command that has no sequence.
|
|
16
|
+
|
|
17
|
+
── persistence, on this surface ─────────────────────────────────────────
|
|
18
|
+
Edits here are 'working': unlike the Drawing Filter, this page AUTO-SAVES
|
|
19
|
+
(scheduleSave → persistServer, 500 ms after the last edit), so accepting or
|
|
20
|
+
deleting a trace reaches the contract on its own. View-only controls stay
|
|
21
|
+
'local'.
|
|
22
|
+
────────────────────────────────────────────────────────────────────────── */
|
|
23
|
+
(function () {
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
if (!window.Commands) return;
|
|
27
|
+
var def = window.Commands.define;
|
|
28
|
+
window.Commands.surfaceScope('vector-editor');
|
|
29
|
+
|
|
30
|
+
/* ── the header ─────────────────────────────────────────────────────────── */
|
|
31
|
+
|
|
32
|
+
def('vector.export-svg', {
|
|
33
|
+
label: 'Export SVG',
|
|
34
|
+
actsOn: 'Downloads the traced drawing as an SVG file',
|
|
35
|
+
group: 'In the Trace header',
|
|
36
|
+
persistence: 'none',
|
|
37
|
+
interaction: 'instant',
|
|
38
|
+
risk: [],
|
|
39
|
+
guidance: 'on-demand',
|
|
40
|
+
why: 'Exports what is currently shown, so hidden layers and hidden kinds are left out of the file.',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/* ── the side panel: what is shown, and reviewing weak traces ───────────── */
|
|
44
|
+
|
|
45
|
+
def('vector.show-kind', {
|
|
46
|
+
label: 'Show lines, curves or text',
|
|
47
|
+
actsOn: 'Hides or shows a whole kind of element',
|
|
48
|
+
group: 'In the Trace panel',
|
|
49
|
+
persistence: 'local',
|
|
50
|
+
interaction: 'instant',
|
|
51
|
+
risk: [],
|
|
52
|
+
guidance: 'on-demand',
|
|
53
|
+
why: 'A view filter, not an edit — hiding text does not remove it from the drawing, but it does leave it out of an Export SVG.',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
def('vector.layer-toggle', {
|
|
57
|
+
label: 'Show a layer',
|
|
58
|
+
actsOn: 'Hides or shows one layer from the source drawing',
|
|
59
|
+
group: 'In the Trace panel',
|
|
60
|
+
persistence: 'local',
|
|
61
|
+
interaction: 'instant',
|
|
62
|
+
risk: [],
|
|
63
|
+
guidance: 'on-demand',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
def('vector.isolate-weak', {
|
|
67
|
+
label: 'Isolate weak traces',
|
|
68
|
+
actsOn: 'Shows only the traces the tracer was unsure about',
|
|
69
|
+
group: 'In the Trace panel',
|
|
70
|
+
persistence: 'local',
|
|
71
|
+
interaction: 'instant',
|
|
72
|
+
risk: [],
|
|
73
|
+
guidance: 'on-demand',
|
|
74
|
+
why: 'Only appears when there are weak traces to review. A drawing traced from a true vector PDF usually has none.',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
def('vector.locate-trace', {
|
|
78
|
+
label: 'Locate a trace',
|
|
79
|
+
actsOn: 'Flashes the trace on the drawing',
|
|
80
|
+
group: 'In the Trace panel',
|
|
81
|
+
persistence: 'none',
|
|
82
|
+
interaction: 'instant',
|
|
83
|
+
risk: [],
|
|
84
|
+
guidance: 'on-demand',
|
|
85
|
+
why: 'Works both ways: a row in the list flashes the trace on the canvas, and clicking a weak trace on the canvas flashes its row.',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
def('vector.accept-trace', {
|
|
89
|
+
label: 'Accept a trace',
|
|
90
|
+
actsOn: 'Marks one weak trace as correct',
|
|
91
|
+
group: 'In the Trace panel',
|
|
92
|
+
persistence: 'working',
|
|
93
|
+
interaction: 'instant',
|
|
94
|
+
risk: [],
|
|
95
|
+
guidance: 'on-demand',
|
|
96
|
+
why: 'Clears the low-confidence flag so the trace stops being listed for review. It does not change the geometry.',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
def('vector.delete-trace', {
|
|
100
|
+
label: 'Delete a trace',
|
|
101
|
+
actsOn: 'Removes one trace from the drawing',
|
|
102
|
+
group: 'In the Trace panel',
|
|
103
|
+
persistence: 'working',
|
|
104
|
+
interaction: 'instant',
|
|
105
|
+
risk: ['destructive'],
|
|
106
|
+
guidance: 'on-demand',
|
|
107
|
+
why: 'Also removes the trace from any group it belonged to. Undo is offered for six seconds and restores both.',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/* ── the canvas ─────────────────────────────────────────────────────────── */
|
|
111
|
+
|
|
112
|
+
def('vector.undo-delete', {
|
|
113
|
+
label: 'Undo a delete',
|
|
114
|
+
actsOn: 'Puts the last deleted trace back',
|
|
115
|
+
group: 'On the Trace canvas',
|
|
116
|
+
persistence: 'working',
|
|
117
|
+
interaction: 'instant',
|
|
118
|
+
risk: [],
|
|
119
|
+
guidance: 'on-demand',
|
|
120
|
+
why: 'Offered in the toast for six seconds after a delete, and restores the trace to its original position in the drawing and its groups. Only the most recent delete can be undone.',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
def('vector.fit', {
|
|
124
|
+
label: 'Fit',
|
|
125
|
+
actsOn: 'Frames the whole page',
|
|
126
|
+
group: 'On the Trace canvas',
|
|
127
|
+
persistence: 'local',
|
|
128
|
+
interaction: 'instant',
|
|
129
|
+
risk: [],
|
|
130
|
+
guidance: 'on-demand',
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
def('vector.zoom', {
|
|
134
|
+
label: 'Zoom',
|
|
135
|
+
actsOn: 'Sets the zoom level',
|
|
136
|
+
group: 'On the Trace canvas',
|
|
137
|
+
persistence: 'local',
|
|
138
|
+
interaction: 'instant',
|
|
139
|
+
risk: [],
|
|
140
|
+
guidance: 'on-demand',
|
|
141
|
+
why: 'Shown as a percentage of the fitted view, so 100% is the whole page rather than the drawing’s real scale.',
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
def('vector.pan-zoom', {
|
|
145
|
+
label: 'Pan and zoom the drawing',
|
|
146
|
+
actsOn: 'Moves the view only',
|
|
147
|
+
group: 'On the Trace canvas',
|
|
148
|
+
persistence: 'local',
|
|
149
|
+
interaction: 'gesture',
|
|
150
|
+
risk: [],
|
|
151
|
+
guidance: 'on-demand',
|
|
152
|
+
why: 'Drag to pan, wheel to zoom.',
|
|
153
|
+
});
|
|
154
|
+
})();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* ──────────────────────────────────────────────────────────────────────────
|
|
2
|
+
Trace — 3D capability registrations (vector-3d.html).
|
|
3
|
+
|
|
4
|
+
Same shape and the same two-documents rule as commands-steel.js: this file
|
|
5
|
+
loads in vector-3d.html AND in index.html, because the shell is the sole
|
|
6
|
+
guidance producer and must be able to resolve an id arriving over the
|
|
7
|
+
reporter seam.
|
|
8
|
+
|
|
9
|
+
── Why NOTHING here is 'active-command', and why that is structural ─────
|
|
10
|
+
This page is a READ-ONLY viewer. It drives the shared renderer
|
|
11
|
+
(steel-3d-view.js) through a host api whose every editing, dimension and snap
|
|
12
|
+
hook is an inert stub — `geoMode: () => null`, `onAddDim3d: () => {}`,
|
|
13
|
+
`getMembers: () => []`. So `Steel3DView.instructorCommand()` has nothing to
|
|
14
|
+
report here even though the same module DOES arm commands inside the steel
|
|
15
|
+
editor. Nothing on this surface can be armed, so nothing here declares steps.
|
|
16
|
+
|
|
17
|
+
Everything is 'local': a viewer never writes. The one thing that reaches the
|
|
18
|
+
project is the reconstruction request the page makes on load, which is not a
|
|
19
|
+
control the user invokes.
|
|
20
|
+
────────────────────────────────────────────────────────────────────────── */
|
|
21
|
+
(function () {
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
if (!window.Commands) return;
|
|
25
|
+
var def = window.Commands.define;
|
|
26
|
+
window.Commands.surfaceScope('vector-3d');
|
|
27
|
+
|
|
28
|
+
/* ── the header ─────────────────────────────────────────────────────────── */
|
|
29
|
+
|
|
30
|
+
def('vector3d.unplaced', {
|
|
31
|
+
label: 'Not shown in 3D',
|
|
32
|
+
actsOn: 'Lists the entities that could not be placed',
|
|
33
|
+
group: 'In the Trace — 3D header',
|
|
34
|
+
persistence: 'local',
|
|
35
|
+
interaction: 'instant',
|
|
36
|
+
risk: [],
|
|
37
|
+
guidance: 'on-demand',
|
|
38
|
+
why: 'Each entry names why that entity has no 3D position — usually a missing height, a level datum or a matching elevation. Fix the reason in the drawing, then reopen this view. Opens by itself when anything was skipped, so a partial reconstruction never looks complete.',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/* ── the 3D view ────────────────────────────────────────────────────────── */
|
|
42
|
+
|
|
43
|
+
def('vector3d.projection', {
|
|
44
|
+
label: 'Perspective or orthographic',
|
|
45
|
+
actsOn: 'Changes the camera only',
|
|
46
|
+
group: 'On the Trace — 3D view',
|
|
47
|
+
persistence: 'local',
|
|
48
|
+
interaction: 'instant',
|
|
49
|
+
risk: [],
|
|
50
|
+
guidance: 'on-demand',
|
|
51
|
+
why: 'Perspective looks natural; orthographic keeps true scale, so parallel lines stay parallel and you can compare lengths across the depth of the model.',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
def('vector3d.display-mode', {
|
|
55
|
+
label: 'Solid, wireframe or X-ray',
|
|
56
|
+
actsOn: 'Changes how the bodies are drawn',
|
|
57
|
+
group: 'On the Trace — 3D view',
|
|
58
|
+
persistence: 'local',
|
|
59
|
+
interaction: 'instant',
|
|
60
|
+
risk: [],
|
|
61
|
+
guidance: 'on-demand',
|
|
62
|
+
why: 'X-ray is the one to reach for when you need to see something buried inside or behind the reconstruction.',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
def('vector3d.fit', {
|
|
66
|
+
label: 'Fit',
|
|
67
|
+
actsOn: 'Frames the whole reconstruction',
|
|
68
|
+
group: 'On the Trace — 3D view',
|
|
69
|
+
persistence: 'local',
|
|
70
|
+
interaction: 'instant',
|
|
71
|
+
risk: [],
|
|
72
|
+
guidance: 'on-demand',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
def('vector3d.group-toggle', {
|
|
76
|
+
label: 'Show a group',
|
|
77
|
+
actsOn: 'Hides or shows one colour group of bodies',
|
|
78
|
+
group: 'On the Trace — 3D view',
|
|
79
|
+
persistence: 'local',
|
|
80
|
+
interaction: 'instant',
|
|
81
|
+
risk: [],
|
|
82
|
+
guidance: 'on-demand',
|
|
83
|
+
why: 'The groups come from the traced drawing, and the count beside each one tells you how many bodies it holds.',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
def('vector3d.orbit', {
|
|
87
|
+
label: 'Orbit, pan and zoom',
|
|
88
|
+
actsOn: 'Moves the camera only',
|
|
89
|
+
group: 'On the Trace — 3D view',
|
|
90
|
+
persistence: 'local',
|
|
91
|
+
interaction: 'gesture',
|
|
92
|
+
risk: [],
|
|
93
|
+
guidance: 'on-demand',
|
|
94
|
+
why: 'Right-drag to orbit, middle-drag to pan, wheel to zoom, double-click to zoom into a point.',
|
|
95
|
+
});
|
|
96
|
+
})();
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/* ──────────────────────────────────────────────────────────────────────────
|
|
2
|
+
The command registry — schema, vocabularies and mechanics.
|
|
3
|
+
|
|
4
|
+
PHASE 1. This module is the single authority on WHAT a capability is. It is
|
|
5
|
+
deliberately NOT a live registry shared across documents: phase 0 proved that
|
|
6
|
+
importing one module into separate iframe realms creates separate instances
|
|
7
|
+
with separate state, so each document owns its own registrations and the shell
|
|
8
|
+
is the sole guidance producer (see the phase 0 findings, §3).
|
|
9
|
+
|
|
10
|
+
What lives here: the closed vocabularies, validation, storage, resolution and
|
|
11
|
+
the inventory used by the coverage guard.
|
|
12
|
+
What does NOT live here: any narration text. That is the producer's job, in
|
|
13
|
+
instructor.js, and keeping it out is what stops a second narrator appearing.
|
|
14
|
+
|
|
15
|
+
── Classification ────────────────────────────────────────────────────────
|
|
16
|
+
Four required fields, each a closed vocabulary. They are DECLARED, never
|
|
17
|
+
inferred: no script can decide "costs money" by looking at a button, so the
|
|
18
|
+
judgment happens once, in a reviewable diff, and CI rejects anything outside
|
|
19
|
+
the vocabulary.
|
|
20
|
+
|
|
21
|
+
persistence where a change lands
|
|
22
|
+
interaction how the user drives it
|
|
23
|
+
risk a SET of flags (an action can be destructive AND costly)
|
|
24
|
+
guidance whether it needs live step narration, or explains on demand
|
|
25
|
+
|
|
26
|
+
A fifth, `surface`, says which screen the command lives on. It is declared
|
|
27
|
+
once per FILE (surfaceScope) rather than per command, because a registration
|
|
28
|
+
file is wholly one surface — see the note beside SURFACE below.
|
|
29
|
+
|
|
30
|
+
`guidance` exists because `interaction` alone got tiers wrong: treating every
|
|
31
|
+
gesture as a narrated command would demand step text for canvas pan and orbit,
|
|
32
|
+
which need none, while drag-to-place genuinely does.
|
|
33
|
+
────────────────────────────────────────────────────────────────────────── */
|
|
34
|
+
(function () {
|
|
35
|
+
'use strict';
|
|
36
|
+
|
|
37
|
+
var PERSISTENCE = ['none', 'local', 'working', 'approved', 'external'];
|
|
38
|
+
var INTERACTION = ['mode', 'armed-gesture', 'gesture', 'instant', 'dialog'];
|
|
39
|
+
var RISK = ['costs-time', 'costs-money', 'destructive'];
|
|
40
|
+
var GUIDANCE = ['active-command', 'on-demand'];
|
|
41
|
+
/* Which guidance value obliges a command to declare its steps. Named so the
|
|
42
|
+
CI guard can read the rule instead of restating it — one source of truth. */
|
|
43
|
+
var GUIDANCE_REQUIRING_STEPS = 'active-command';
|
|
44
|
+
|
|
45
|
+
/* Which surface a command LIVES ON. A fifth closed vocabulary, and the only
|
|
46
|
+
one that is declared per FILE rather than per command — every registration
|
|
47
|
+
file is wholly one surface, so repeating it on all 77 definitions would add
|
|
48
|
+
nothing but 77 chances to mistype it.
|
|
49
|
+
|
|
50
|
+
Note it describes where the command lives, NOT where the file was parsed:
|
|
51
|
+
commands-steel.js loads in the shell too (see its header), and stays
|
|
52
|
+
'steel-editor' in both, because that is where its buttons are.
|
|
53
|
+
|
|
54
|
+
Why it exists: the `?` sheet holds every surface's commands, but only one
|
|
55
|
+
surface is on screen at a time (the contract-editor overlay is
|
|
56
|
+
position:fixed inset:0, so an open child hides the shell completely). The
|
|
57
|
+
sheet has to put the live one first, and stamping the surface on each
|
|
58
|
+
command is what lets it — with NO surface→groups table in the shell to
|
|
59
|
+
drift out of step with the registrations. That table was the alternative,
|
|
60
|
+
and a second statement of which command sits where is exactly the drift
|
|
61
|
+
this design exists to prevent. */
|
|
62
|
+
var SURFACE = ['shell', 'steel-editor', 'steel-filter', 'vector-editor', 'vector-3d'];
|
|
63
|
+
|
|
64
|
+
var registry = Object.create(null);
|
|
65
|
+
var problems = [];
|
|
66
|
+
|
|
67
|
+
/* Set by surfaceScope() at the top of each registration file, read by define().
|
|
68
|
+
Deliberately NOT reset after each file: script order is the only thing that
|
|
69
|
+
scopes it, so a file that forgets to declare gets the PREVIOUS file's
|
|
70
|
+
surface — which is why define() refuses a definition with no scope set and
|
|
71
|
+
verify-command-registry requires the call per file. Silent inheritance is
|
|
72
|
+
the failure mode worth spending a guard on. */
|
|
73
|
+
var currentSurface = null;
|
|
74
|
+
|
|
75
|
+
function fail(id, message) {
|
|
76
|
+
var text = 'commands: ' + id + ' — ' + message;
|
|
77
|
+
problems.push(text);
|
|
78
|
+
// Loud in the browser, never fatal: a bad definition must not take the app
|
|
79
|
+
// down. CI is what makes it un-shippable (verify-command-registry).
|
|
80
|
+
if (typeof console !== 'undefined' && console.error) console.error(text);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function validate(id, meta) {
|
|
84
|
+
var ok = true;
|
|
85
|
+
if (!id || typeof id !== 'string') { fail(String(id), 'id must be a non-empty string'); return false; }
|
|
86
|
+
if (id.indexOf('#') !== -1) { fail(id, 'id must not contain "#" — that separates the instance key'); ok = false; }
|
|
87
|
+
/* The id is concatenated straight into an attribute SELECTOR by
|
|
88
|
+
instructor.js activate(), so its character set is a safety property, not a
|
|
89
|
+
style rule: a quote would close the selector's string early and a
|
|
90
|
+
backslash would start an escape. Refusing anything outside dotted-kebab
|
|
91
|
+
here — where an invalid definition is never registered at all — is what
|
|
92
|
+
lets that concatenation stay plain and readable. All 279 ids already match.
|
|
93
|
+
(The INSTANCE half is not covered by this: it comes from data, never
|
|
94
|
+
enters a selector, and is guarded where it is written into markup
|
|
95
|
+
instead — see verify-instructor-carrier-escaping.) */
|
|
96
|
+
/* A hyphen is legal in EVERY segment, including the first. The first cut of
|
|
97
|
+
this allowed it only after the leading dot, which would have refused
|
|
98
|
+
`steel-filter.reset` or `vector-3d.zoom` — and two of the five surfaces are
|
|
99
|
+
literally named `steel-filter` and `vector-3d`, so that is an id someone
|
|
100
|
+
writes by accident of good naming, not by carelessness. */
|
|
101
|
+
if (!/^[a-z0-9][a-z0-9-]*(\.[a-z0-9-]+)+$/.test(id)) {
|
|
102
|
+
fail(id, 'id must be lowercase, hyphens and dots only, with at least one dot (steel-filter.reset) — it is interpolated into a CSS attribute selector');
|
|
103
|
+
ok = false;
|
|
104
|
+
}
|
|
105
|
+
if (!meta || typeof meta !== 'object') { fail(id, 'missing metadata'); return false; }
|
|
106
|
+
if (!meta.label) { fail(id, 'missing label'); ok = false; }
|
|
107
|
+
|
|
108
|
+
if (PERSISTENCE.indexOf(meta.persistence) === -1) {
|
|
109
|
+
fail(id, 'persistence must be one of ' + PERSISTENCE.join(' | ') + ' (got ' + meta.persistence + ')');
|
|
110
|
+
ok = false;
|
|
111
|
+
}
|
|
112
|
+
if (INTERACTION.indexOf(meta.interaction) === -1) {
|
|
113
|
+
fail(id, 'interaction must be one of ' + INTERACTION.join(' | ') + ' (got ' + meta.interaction + ')');
|
|
114
|
+
ok = false;
|
|
115
|
+
}
|
|
116
|
+
if (GUIDANCE.indexOf(meta.guidance) === -1) {
|
|
117
|
+
fail(id, 'guidance must be one of ' + GUIDANCE.join(' | ') + ' (got ' + meta.guidance + ')');
|
|
118
|
+
ok = false;
|
|
119
|
+
}
|
|
120
|
+
var risk = meta.risk || [];
|
|
121
|
+
if (!Array.isArray(risk)) {
|
|
122
|
+
fail(id, 'risk must be an array of flags (use [] for none)');
|
|
123
|
+
ok = false;
|
|
124
|
+
} else {
|
|
125
|
+
for (var i = 0; i < risk.length; i++) {
|
|
126
|
+
if (RISK.indexOf(risk[i]) === -1) { fail(id, 'unknown risk flag "' + risk[i] + '"'); ok = false; }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// A command that narrates steps must say what its steps are.
|
|
131
|
+
if (meta.guidance === GUIDANCE_REQUIRING_STEPS && (!Array.isArray(meta.steps) || !meta.steps.length)) {
|
|
132
|
+
fail(id, 'guidance "active-command" requires a non-empty steps array');
|
|
133
|
+
ok = false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* No scope declared means this file never called surfaceScope(). Refused
|
|
137
|
+
rather than defaulted: a default would put the command on whichever
|
|
138
|
+
surface happened to be listed first, and the sheet would then confidently
|
|
139
|
+
order it under a screen it is not on. */
|
|
140
|
+
if (!currentSurface) {
|
|
141
|
+
fail(id, 'no surface in scope — call Commands.surfaceScope(...) at the top of this file');
|
|
142
|
+
ok = false;
|
|
143
|
+
}
|
|
144
|
+
return ok;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The tier is DERIVED from the classification — never declared separately. */
|
|
148
|
+
function tierOf(meta) {
|
|
149
|
+
if (meta.guidance === GUIDANCE_REQUIRING_STEPS) return 'T1';
|
|
150
|
+
if (meta.persistence === 'approved' || meta.persistence === 'external') return 'T2';
|
|
151
|
+
if (meta.risk && meta.risk.length) return 'T2';
|
|
152
|
+
return 'T3';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function define(id, meta) {
|
|
156
|
+
if (!validate(id, meta)) return null;
|
|
157
|
+
// Idempotent, last-write-wins: a re-render must not duplicate, and a
|
|
158
|
+
// reloaded module must not leave a stale definition behind.
|
|
159
|
+
registry[id] = {
|
|
160
|
+
id: id,
|
|
161
|
+
label: meta.label,
|
|
162
|
+
actsOn: meta.actsOn || null,
|
|
163
|
+
group: meta.group || null,
|
|
164
|
+
key: meta.key || null,
|
|
165
|
+
persistence: meta.persistence,
|
|
166
|
+
interaction: meta.interaction,
|
|
167
|
+
risk: meta.risk || [],
|
|
168
|
+
guidance: meta.guidance,
|
|
169
|
+
steps: meta.steps || null,
|
|
170
|
+
why: meta.why || null,
|
|
171
|
+
surface: currentSurface,
|
|
172
|
+
tier: tierOf(meta),
|
|
173
|
+
};
|
|
174
|
+
return registry[id];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Declare which surface the definitions BELOW belong to. One call per
|
|
179
|
+
* registration file, before its first define().
|
|
180
|
+
*/
|
|
181
|
+
function surfaceScope(name) {
|
|
182
|
+
if (SURFACE.indexOf(name) === -1) {
|
|
183
|
+
fail('surfaceScope', 'unknown surface "' + name + '" — must be one of ' + SURFACE.join(' | '));
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
currentSurface = name;
|
|
187
|
+
return name;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
/** `template#instance` → its parts. An id with no hash is its own template. */
|
|
192
|
+
function split(raw) {
|
|
193
|
+
if (!raw) return null;
|
|
194
|
+
var hash = raw.indexOf('#');
|
|
195
|
+
return hash === -1
|
|
196
|
+
? { template: raw, instance: null }
|
|
197
|
+
: { template: raw.slice(0, hash), instance: raw.slice(hash + 1) };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function resolve(el) {
|
|
201
|
+
if (!el || !el.closest) return null;
|
|
202
|
+
var carrier = el.closest('[data-command-id]');
|
|
203
|
+
if (!carrier) return null;
|
|
204
|
+
var parts = split(carrier.getAttribute('data-command-id'));
|
|
205
|
+
if (!parts) return null;
|
|
206
|
+
return { id: parts.template, instance: parts.instance, meta: registry[parts.template] || null, el: carrier };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Live instances mapped to their templates — what the coverage guard consumes.
|
|
211
|
+
* Instances are COUNTED but never required to be registered; only their
|
|
212
|
+
* template must be. That is what keeps a checked-in id inventory stable when
|
|
213
|
+
* project data changes.
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* The accessible name a screen reader would announce for this control.
|
|
217
|
+
*
|
|
218
|
+
* The FLOOR, not a nicety: icon-only and generated controls have no useful
|
|
219
|
+
* textContent, and an inventory entry with no accessible name is a failure
|
|
220
|
+
* rather than a blank — there would be nothing to search for in the `?` sheet
|
|
221
|
+
* and nothing to announce. Deliberately does NOT fall back to the registry
|
|
222
|
+
* label: the point is to check what the DOM actually exposes, and borrowing
|
|
223
|
+
* the label would make every control pass by construction.
|
|
224
|
+
*/
|
|
225
|
+
function accessibleNameOf(el) {
|
|
226
|
+
var aria = el.getAttribute('aria-label');
|
|
227
|
+
if (aria && aria.trim()) return aria.trim();
|
|
228
|
+
var by = el.getAttribute('aria-labelledby');
|
|
229
|
+
if (by) {
|
|
230
|
+
var owner = document.getElementById(by.split(/\s+/)[0]);
|
|
231
|
+
if (owner && (owner.textContent || '').trim()) return owner.textContent.trim();
|
|
232
|
+
}
|
|
233
|
+
/* A form control's associated <label>, which is how the BROWSER names it —
|
|
234
|
+
either `<label for=id>` or a <label> wrapping the control. Omitting this
|
|
235
|
+
was not a small gap: the inventory reported a dozen correctly-labelled
|
|
236
|
+
inputs as anonymous, and the fix that satisfied it was to bolt an
|
|
237
|
+
aria-label onto each, which OVERRIDES the visible label and breaks
|
|
238
|
+
WCAG 2.5.3 (a speech-input user saying the visible word no longer hits
|
|
239
|
+
the control). Reading what the browser reads means the markup needs no
|
|
240
|
+
such decoration. (Code review.) */
|
|
241
|
+
var tag = (el.tagName || '').toLowerCase();
|
|
242
|
+
if (tag === 'input' || tag === 'select' || tag === 'textarea') {
|
|
243
|
+
var byFor = el.id && document.querySelector
|
|
244
|
+
? document.querySelector('label[for="' + (window.CSS && CSS.escape ? CSS.escape(el.id) : el.id) + '"]')
|
|
245
|
+
: null;
|
|
246
|
+
if (byFor && (byFor.textContent || '').trim()) return byFor.textContent.replace(/\s+/g, ' ').trim();
|
|
247
|
+
/* A wrapping <label> labels its FIRST labelable descendant, and only that
|
|
248
|
+
one. Without the check, a label around a whole row would hand its text to
|
|
249
|
+
every control in the row — so two different controls would announce the
|
|
250
|
+
same name, which is worse than announcing none. (Codex review.) */
|
|
251
|
+
var wrap = el.closest && el.closest('label');
|
|
252
|
+
if (wrap && wrap.querySelector('input, select, textarea, button, meter, output, progress') === el
|
|
253
|
+
&& (wrap.textContent || '').trim()) {
|
|
254
|
+
return wrap.textContent.replace(/\s+/g, ' ').trim();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
var text = (el.textContent || '').replace(/\s+/g, ' ').trim();
|
|
259
|
+
if (text) return text;
|
|
260
|
+
var alt = el.querySelector && el.querySelector('img[alt]');
|
|
261
|
+
if (alt && alt.getAttribute('alt').trim()) return alt.getAttribute('alt').trim();
|
|
262
|
+
/* NO `title` fallback, deliberately. The browser would use it, but this repo
|
|
263
|
+
bans title= outright (npm run verify:no-title — it renders the light OS
|
|
264
|
+
tooltip against the dark theme). Accepting it here would make a control
|
|
265
|
+
that violates that ban read as correctly named, so the one place that
|
|
266
|
+
could have reported the violation would instead conceal it. */
|
|
267
|
+
return '';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function inventory(root) {
|
|
271
|
+
var scope = root || document;
|
|
272
|
+
var out = {
|
|
273
|
+
instances: 0, templates: 0, byTemplate: {}, unregistered: [],
|
|
274
|
+
byTier: { T1: 0, T2: 0, T3: 0 },
|
|
275
|
+
/* Live instances whose control announces nothing. Reported per instance,
|
|
276
|
+
not per template, because the same template can be fine on one row and
|
|
277
|
+
empty on another — which is exactly the case a template-level count
|
|
278
|
+
would hide. */
|
|
279
|
+
unnamed: [],
|
|
280
|
+
};
|
|
281
|
+
scope.querySelectorAll('[data-command-id]').forEach(function (el) {
|
|
282
|
+
var raw = el.getAttribute('data-command-id');
|
|
283
|
+
var parts = split(raw);
|
|
284
|
+
if (!parts) return;
|
|
285
|
+
out.instances++;
|
|
286
|
+
out.byTemplate[parts.template] = (out.byTemplate[parts.template] || 0) + 1;
|
|
287
|
+
var meta = registry[parts.template];
|
|
288
|
+
if (!meta) {
|
|
289
|
+
if (out.unregistered.indexOf(parts.template) === -1) out.unregistered.push(parts.template);
|
|
290
|
+
} else {
|
|
291
|
+
out.byTier[meta.tier]++;
|
|
292
|
+
}
|
|
293
|
+
// Hidden controls are not announced and cannot be reached, so an empty
|
|
294
|
+
// name on one is not a defect the user can meet.
|
|
295
|
+
var visible = !!(el.offsetParent || (el.getClientRects && el.getClientRects().length));
|
|
296
|
+
if (visible && !accessibleNameOf(el)) out.unnamed.push(raw);
|
|
297
|
+
});
|
|
298
|
+
out.templates = Object.keys(registry).length;
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
window.Commands = {
|
|
303
|
+
VOCAB: { persistence: PERSISTENCE, interaction: INTERACTION, risk: RISK, guidance: GUIDANCE, surface: SURFACE },
|
|
304
|
+
define: define,
|
|
305
|
+
surfaceScope: surfaceScope,
|
|
306
|
+
get: function (id) { return registry[id] || null; },
|
|
307
|
+
ids: function () { return Object.keys(registry).sort(); },
|
|
308
|
+
all: function () { return Object.keys(registry).map(function (k) { return registry[k]; }); },
|
|
309
|
+
resolve: resolve,
|
|
310
|
+
split: split,
|
|
311
|
+
inventory: inventory,
|
|
312
|
+
tierOf: tierOf,
|
|
313
|
+
/** Definition errors seen this session — asserted as empty by the E2E. */
|
|
314
|
+
problems: function () { return problems.slice(); },
|
|
315
|
+
};
|
|
316
|
+
})();
|