@nac3/runtime 2.5.2 → 2.8.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/CHANGELOG.md +928 -0
- package/NOTICE +15 -0
- package/README.md +110 -3
- package/SPEC.md +1590 -25
- package/contract-head.json +4 -4
- package/dist/cli-harness.mjs +468 -0
- package/dist/cli-levels.json +56 -15
- package/dist/cli-lint.mjs +718 -24
- package/dist/cli-url.mjs +234 -80
- package/dist/cli.js +317 -12
- package/dist/dom-harness.mjs +578 -0
- package/dist/nac-chat-client.browser.js +47 -6
- package/dist/nac-chat-client.cjs +47 -6
- package/dist/nac-chat-client.mjs +47 -6
- package/dist/nac-v2-extensions.browser.js +359 -18
- package/dist/nac-v2-extensions.cjs +359 -18
- package/dist/nac-v2-extensions.d.ts +1 -1
- package/dist/nac-v2-extensions.mjs +359 -18
- package/dist/nac.browser.js +2482 -88
- package/dist/nac.cjs +2482 -88
- package/dist/nac.d.ts +131 -2
- package/dist/nac.mjs +2482 -88
- package/package.json +30 -3
package/dist/nac.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7
7
|
=====================================================================
|
|
8
8
|
|
|
9
9
|
AUTHORITATIVE VERSION CONSTANT: see the global.NAC export at the
|
|
10
|
-
bottom of this file. `version: '2.
|
|
10
|
+
bottom of this file. `version: '2.8.0', spec_version: '2.8'`
|
|
11
11
|
is the normative declaration. The dated changelog sections below are
|
|
12
12
|
historical notes; if they ever drift from the export, the export
|
|
13
13
|
wins.
|
|
@@ -314,6 +314,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
314
314
|
|
|
315
315
|
if (global.NAC && global.NAC.__nac_v1_installed) return;
|
|
316
316
|
|
|
317
|
+
/* The tier this runtime declares when a host does not override it.
|
|
318
|
+
ONE declaration: the versioning gate and the NAC export both read
|
|
319
|
+
it. See the long note at the `conformance_tier` export for why a
|
|
320
|
+
tier is not a level, and RFC V24-04 sec 6 for the vocabulary. */
|
|
321
|
+
const DEFAULT_CONFORMANCE_TIER = 'NAC-3-versioned';
|
|
322
|
+
|
|
317
323
|
/* ---------- Errors ---------------------------------------------- */
|
|
318
324
|
|
|
319
325
|
function NacError(code, message, extra) {
|
|
@@ -324,6 +330,29 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
324
330
|
return e;
|
|
325
331
|
}
|
|
326
332
|
|
|
333
|
+
/* 2.7.0 (SPEC sec 19.3) -- fail closed where there is no document.
|
|
334
|
+
|
|
335
|
+
The DOM primitives of sections 1-14 address NODES: they resolve a
|
|
336
|
+
name by querying the document. Called where no document exists --
|
|
337
|
+
Node, a worker, an SSR build, a screenless assistant -- they used
|
|
338
|
+
to throw a raw "ReferenceError: document is not defined" from
|
|
339
|
+
whatever line happened to touch it first, which tells the caller
|
|
340
|
+
nothing about the contract and is not a code anybody can branch
|
|
341
|
+
on. validate_global was worse: it returned {ok: true} for a tree
|
|
342
|
+
that does not exist, which is a false green.
|
|
343
|
+
|
|
344
|
+
So they refuse by name. The headless profile (sec 19) is the other
|
|
345
|
+
half of the same rule: a surface with no document is reached
|
|
346
|
+
through the extension contract (sec 15), never through these. */
|
|
347
|
+
function _nac_requireDocument(where) {
|
|
348
|
+
if (typeof document !== 'undefined' && document) return;
|
|
349
|
+
throw NacError('no_document',
|
|
350
|
+
'NAC.' + where + ': no document in this context, so there is no node to resolve. ' +
|
|
351
|
+
'Reach a declared surface through the extension contract -- NAC.call / NAC.read / ' +
|
|
352
|
+
'NAC.subscribe (SPEC sec 15) -- and see the headless profile (SPEC sec 19).',
|
|
353
|
+
{ primitive: where });
|
|
354
|
+
}
|
|
355
|
+
|
|
327
356
|
/* ================================================================
|
|
328
357
|
v2.5 / RFC V24-01: Plugin slug uniqueness gate (spec sec 7.4)
|
|
329
358
|
================================================================
|
|
@@ -719,13 +748,58 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
719
748
|
over the canonical bytes, truncated to the leading 128 bits
|
|
720
749
|
(16 bytes), encoded as 32 lowercase hex chars. */
|
|
721
750
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
751
|
+
/* ONE definition of "visible" (TF-A12).
|
|
752
|
+
|
|
753
|
+
Until 2.7.0 there were two, both published, and they disagreed:
|
|
754
|
+
|
|
755
|
+
_hashIsEffectivelyVisible fed the `visible` key of the
|
|
756
|
+
concurrency hash. Looked at
|
|
757
|
+
aria-hidden and offsetParent. Did
|
|
758
|
+
NOT look at opacity.
|
|
759
|
+
_isVisible fed the `visible` key the AGENT
|
|
760
|
+
reads from a state snapshot. Looked
|
|
761
|
+
at opacity. Did NOT look at
|
|
762
|
+
aria-hidden.
|
|
763
|
+
|
|
764
|
+
So an element with `opacity: 0` was visible to one and invisible
|
|
765
|
+
to the other, and one with `aria-hidden="true"` was the reverse.
|
|
766
|
+
Two answers to one word, in one runtime, both shipped -- and the
|
|
767
|
+
word is load-bearing twice over: an agent decides whether to act
|
|
768
|
+
on an element by it, and the optimistic-concurrency gate decides
|
|
769
|
+
whether the page moved under the agent by it.
|
|
770
|
+
|
|
771
|
+
There was a third difference, and it was a crash rather than a
|
|
772
|
+
disagreement: _isVisible reached el.ownerDocument.defaultView
|
|
773
|
+
.getComputedStyle with NO GUARD, while this one checked for
|
|
774
|
+
window.getComputedStyle first. In an environment without a
|
|
775
|
+
defaultView -- a detached document, a server-side render, a test
|
|
776
|
+
harness -- one threw and the other did not.
|
|
777
|
+
|
|
778
|
+
THE DECISION, and the reasoning rather than just the outcome. The
|
|
779
|
+
union is the right answer, and specifically the agent's question
|
|
780
|
+
is the one that governs: "can this be perceived and acted on?"
|
|
781
|
+
Every one of the five conditions below answers no to it.
|
|
782
|
+
aria-hidden belongs in it because NAC3 sits next to the
|
|
783
|
+
accessibility tree and an element explicitly removed from that
|
|
784
|
+
tree is not something an agent may act on. opacity: 0 belongs in
|
|
785
|
+
it because a user cannot see it.
|
|
786
|
+
|
|
787
|
+
The hash gets the same predicate, which makes it slightly
|
|
788
|
+
stricter: a control fading to opacity 0 now changes the hash.
|
|
789
|
+
That is more correct for a concurrency check, not less -- it IS a
|
|
790
|
+
change in the observable state, which is exactly what the hash
|
|
791
|
+
exists to notice.
|
|
792
|
+
|
|
793
|
+
Cheap first, expensive last: the attribute and the layout box are
|
|
794
|
+
free, getComputedStyle is not. */
|
|
795
|
+
function _isPerceivable(el) {
|
|
725
796
|
if (!el || el.nodeType !== 1) return false;
|
|
797
|
+
/* 1. explicitly removed from the accessibility tree */
|
|
726
798
|
if (el.getAttribute && el.getAttribute('aria-hidden') === 'true') return false;
|
|
799
|
+
/* 2. not laid out. position:fixed legitimately has no
|
|
800
|
+
offsetParent, so a zero-sized rect is what decides, not the
|
|
801
|
+
null parent on its own. */
|
|
727
802
|
if (typeof el.offsetParent === 'object' && el.offsetParent === null) {
|
|
728
|
-
/* position:fixed escapes offsetParent=null. Use rect fallback. */
|
|
729
803
|
if (typeof el.getBoundingClientRect === 'function') {
|
|
730
804
|
const r = el.getBoundingClientRect();
|
|
731
805
|
if (r.width === 0 && r.height === 0) return false;
|
|
@@ -733,13 +807,35 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
733
807
|
return false;
|
|
734
808
|
}
|
|
735
809
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
810
|
+
/* 3. a zero-sized box, however it got that way */
|
|
811
|
+
if (typeof el.getBoundingClientRect === 'function') {
|
|
812
|
+
const r = el.getBoundingClientRect();
|
|
813
|
+
if (r.width === 0 && r.height === 0) return false;
|
|
814
|
+
}
|
|
815
|
+
/* 4..5. display / visibility / opacity, if anyone can tell us.
|
|
816
|
+
GUARDED on both paths: the document's own view first, the
|
|
817
|
+
global second, and neither is assumed to exist. Returning true
|
|
818
|
+
when nothing can be computed is deliberate -- an element we
|
|
819
|
+
cannot measure is reported as present rather than silently
|
|
820
|
+
vanishing from a snapshot. */
|
|
821
|
+
const view = (el.ownerDocument && el.ownerDocument.defaultView)
|
|
822
|
+
|| (typeof window !== 'undefined' ? window : null);
|
|
823
|
+
if (view && typeof view.getComputedStyle === 'function') {
|
|
824
|
+
const cs = view.getComputedStyle(el);
|
|
825
|
+
if (cs && (cs.display === 'none' || cs.visibility === 'hidden' || cs.opacity === '0')) {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
739
828
|
}
|
|
740
829
|
return true;
|
|
741
830
|
}
|
|
742
831
|
|
|
832
|
+
/* Kept as a name because the hash code reads better with it, and
|
|
833
|
+
because a reader looking for the old function should land on the
|
|
834
|
+
explanation above rather than on nothing. */
|
|
835
|
+
function _hashIsEffectivelyVisible(el) {
|
|
836
|
+
return _isPerceivable(el);
|
|
837
|
+
}
|
|
838
|
+
|
|
743
839
|
function _hashReadValue(el) {
|
|
744
840
|
if (!el || el.nodeType !== 1) return null;
|
|
745
841
|
const tag = (el.tagName || '').toLowerCase();
|
|
@@ -1019,7 +1115,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1019
1115
|
and a runtime that declares NAC-3 must NOT silently honor any
|
|
1020
1116
|
expected_*. */
|
|
1021
1117
|
const tier = (typeof window !== 'undefined' && window.NAC &&
|
|
1022
|
-
window.NAC.conformance_tier) ||
|
|
1118
|
+
window.NAC.conformance_tier) || DEFAULT_CONFORMANCE_TIER;
|
|
1023
1119
|
if (tier === 'NAC-3' && hasAny) {
|
|
1024
1120
|
throw NacError('feature_not_supported',
|
|
1025
1121
|
'Runtime tier is NAC-3 (non-versioned); expected_* parameters are not honored.',
|
|
@@ -1226,6 +1322,26 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1226
1322
|
of identical warnings per session. Key by (event_type, field).
|
|
1227
1323
|
Reset by calling NAC.__resetLegacyWarnDedup() (test-only). */
|
|
1228
1324
|
const _legacyWarnSeen = Object.create(null);
|
|
1325
|
+
/* 2.7.0 (TF-A03) -- THE REMOVAL PROMISE IS WITHDRAWN, and this
|
|
1326
|
+
message is where it was being made. It said "Will be removed in
|
|
1327
|
+
v2.0" to every adopter's console; v2.0 shipped, so did 2.1
|
|
1328
|
+
through 2.6, and the fields are all still here. A promise that
|
|
1329
|
+
outlives three majors is not a deprecation, it is noise that
|
|
1330
|
+
teaches authors to ignore the warning.
|
|
1331
|
+
|
|
1332
|
+
It is withdrawn rather than kept and honoured because the fields
|
|
1333
|
+
are LOAD-BEARING, which no document noticed: the event matcher
|
|
1334
|
+
that decides whether an event belongs to an element READS
|
|
1335
|
+
from_nac_id / target_nac_id / over_nac_id / nac_id / id /
|
|
1336
|
+
step_id as resolution keys (see _eventMatchesElement below).
|
|
1337
|
+
Removing them would not retire six lines, it would silently
|
|
1338
|
+
break wait_for() and assert_event_fired() on any host that
|
|
1339
|
+
emits only the alias -- which is exactly the shape of host the
|
|
1340
|
+
aliases exist for.
|
|
1341
|
+
|
|
1342
|
+
So: the alias stays, the canonical is still the one to write,
|
|
1343
|
+
and the warning says that without naming a version it cannot
|
|
1344
|
+
keep. Decision D-12, owner delegation of 2026-11-24. */
|
|
1229
1345
|
function _legacyWarn(eventType, field, canonical) {
|
|
1230
1346
|
const key = eventType + '::' + field;
|
|
1231
1347
|
if (_legacyWarnSeen[key]) return;
|
|
@@ -1233,7 +1349,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1233
1349
|
if (typeof console !== 'undefined' && console.warn) {
|
|
1234
1350
|
console.warn('[NAC] legacy_event_field: ' + eventType +
|
|
1235
1351
|
' detail.' + field + ' is a legacy alias. Use detail.' +
|
|
1236
|
-
canonical + ' instead.
|
|
1352
|
+
canonical + ' instead. The alias is frozen, not scheduled ' +
|
|
1353
|
+
'for removal: the event matcher resolves it (SPEC 7.4, ' +
|
|
1354
|
+
'decision D-12).');
|
|
1237
1355
|
}
|
|
1238
1356
|
}
|
|
1239
1357
|
|
|
@@ -1514,6 +1632,60 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1514
1632
|
return null;
|
|
1515
1633
|
}
|
|
1516
1634
|
|
|
1635
|
+
/* 2.7.0 -- `undrivable_until`, the declaration of a gated surface.
|
|
1636
|
+
|
|
1637
|
+
THE DEFECT IT ANSWERS, measured on this project's own landing page
|
|
1638
|
+
on 2026-11-25 with the probe that 2.7.0 added:
|
|
1639
|
+
`validate_global({probe: true})` reported seven
|
|
1640
|
+
nac_id_declared_not_reachable findings -- chat.lang, chat.tts,
|
|
1641
|
+
chat.mic, chat.voice.always_on, chat.log, chat.input, chat.send.
|
|
1642
|
+
All seven are real, all seven are declared, and all seven live
|
|
1643
|
+
inside a panel that stays behind `aria-hidden="true"` until
|
|
1644
|
+
somebody opens it.
|
|
1645
|
+
|
|
1646
|
+
Before this field the protocol had no way to say that, so the two
|
|
1647
|
+
parties both lost. An AGENT read a manifest advertising seven
|
|
1648
|
+
addressable ids, called click() on one of them and got
|
|
1649
|
+
NacError('hidden') with nothing to do about it -- the surface
|
|
1650
|
+
exists, is declared, and the one thing it needed to know (open the
|
|
1651
|
+
panel first) was the one thing nobody wrote down. And an AUTHOR
|
|
1652
|
+
with a legitimately gated panel had no honest way to reach
|
|
1653
|
+
conformance level 3, which asks for zero findings: the only moves
|
|
1654
|
+
available were to stop declaring the surface (worse for the agent)
|
|
1655
|
+
or to stop painting it until opened (a rewrite of the widget).
|
|
1656
|
+
|
|
1657
|
+
So an element may now declare the id that opens it:
|
|
1658
|
+
|
|
1659
|
+
{ id: 'chat.mic', role: 'action',
|
|
1660
|
+
undrivable_until: 'nac_landing.chat.toggle' }
|
|
1661
|
+
|
|
1662
|
+
and three things follow. The probe stops calling it a defect and
|
|
1663
|
+
reports it in its own `gated` bucket, which is NOT a finding.
|
|
1664
|
+
click() still refuses it while it is hidden -- the element really
|
|
1665
|
+
is unreachable, and failing closed is the whole point -- but the
|
|
1666
|
+
rejection now NAMES the gate, so the agent's next move is in the
|
|
1667
|
+
error it just got. And the declaration is checked: a gate that is
|
|
1668
|
+
not declared, not mounted, or itself unreachable is an ERROR, a
|
|
1669
|
+
harder finding than the warn it replaces. A promised way in that
|
|
1670
|
+
does not open is worse than no promise, because an agent will
|
|
1671
|
+
wait for it.
|
|
1672
|
+
|
|
1673
|
+
Fail-closed by construction: no field means no change, for every
|
|
1674
|
+
page already published. */
|
|
1675
|
+
function _resolveGate(nac_id) {
|
|
1676
|
+
for (const slug in _manifests) {
|
|
1677
|
+
const m = _manifests[slug];
|
|
1678
|
+
if (!m) continue;
|
|
1679
|
+
const all = (m.elements || []).concat(m.tabs || []);
|
|
1680
|
+
for (let i = 0; i < all.length; i++) {
|
|
1681
|
+
const e = all[i];
|
|
1682
|
+
if (!e || e.id !== nac_id) continue;
|
|
1683
|
+
return e.undrivable_until ? String(e.undrivable_until) : null;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return null;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1517
1689
|
function _hasCapability(cap) {
|
|
1518
1690
|
if (!cap) return true;
|
|
1519
1691
|
if (Array.isArray(cap)) {
|
|
@@ -1567,9 +1739,109 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1567
1739
|
'draggable', 'drop-target',
|
|
1568
1740
|
/* Tolerated for legacy buttons that just need to be clickable
|
|
1569
1741
|
without contract. Falls back to action behaviour at runtime. */
|
|
1570
|
-
'button'
|
|
1742
|
+
'button',
|
|
1743
|
+
|
|
1744
|
+
/* ---- v2.8.0: the surface vocabulary (SPEC.md 1.2) ------------
|
|
1745
|
+
THE DEFECT THIS CLOSES. Measured on this tree on 2026-11-25:
|
|
1746
|
+
the normative table declared 20 roles, the tree USED 67, and
|
|
1747
|
+
52 of those were declared nowhere -- not here, not in the
|
|
1748
|
+
spec table, not in the click completion map. Every one of
|
|
1749
|
+
them had been written into a page by somebody who needed the
|
|
1750
|
+
word, and the protocol's answer was to treat it as `action`
|
|
1751
|
+
and wait five seconds for an event that role never emits.
|
|
1752
|
+
|
|
1753
|
+
This Set is the runtime's half of the contract and section 1
|
|
1754
|
+
of SPEC.md is the document's half. They are hand-written in
|
|
1755
|
+
two places on purpose -- the runtime must refuse an unknown
|
|
1756
|
+
role with no network and no spec file at hand -- and from
|
|
1757
|
+
2.8.0 scripts/check-role-registries.mjs refuses the build
|
|
1758
|
+
when the two halves disagree. Before that gate existed the
|
|
1759
|
+
two lists had already drifted once (the spec table carried
|
|
1760
|
+
draggable / drop-target for four minor versions while the
|
|
1761
|
+
lint's copy did not), so this is not a hypothetical. */
|
|
1762
|
+
|
|
1763
|
+
/* Maps. The interior is drawn, not marked up. */
|
|
1764
|
+
'map', 'map-layer', 'map-marker',
|
|
1765
|
+
/* Charts: chart-series is the operable part, chart-point the
|
|
1766
|
+
readable one. */
|
|
1767
|
+
'chart', 'chart-series', 'chart-point',
|
|
1768
|
+
'calendar', 'calendar-event',
|
|
1769
|
+
/* tree-children exists as a role because a collapsed subtree is
|
|
1770
|
+
IN the DOM and not operable, and that is the distinction an
|
|
1771
|
+
agent has to be able to make. */
|
|
1772
|
+
'tree', 'tree-node', 'tree-children',
|
|
1773
|
+
'timeline', 'timeline-item',
|
|
1774
|
+
'carousel', 'carousel-slide',
|
|
1775
|
+
/* Live regions. One-to-one with ARIA on purpose. `feedback` is
|
|
1776
|
+
narrower than `status` and is what NAC.read_feedback() reads. */
|
|
1777
|
+
'status', 'log', 'toast', 'toast-region', 'banner', 'feedback',
|
|
1778
|
+
/* Overlays. `modal` is the general case of `confirm-dialog`. */
|
|
1779
|
+
'modal', 'drawer', 'bottom-sheet',
|
|
1780
|
+
/* Controls whose value is not their text: these are what tell an
|
|
1781
|
+
agent to resolve through options() instead of typing. */
|
|
1782
|
+
'combobox', 'listbox', 'slider', 'richtext',
|
|
1783
|
+
/* The containers of controls that were already declared. */
|
|
1784
|
+
'tablist', 'tabpanel', 'stepper', 'accordion-section',
|
|
1785
|
+
'breadcrumb', 'pagination-control',
|
|
1786
|
+
/* Identity, and the state of the interface itself. `skeleton`
|
|
1787
|
+
means NOT LOADED YET and `empty-state` means NOTHING HERE,
|
|
1788
|
+
AND THAT IS NOT AN ERROR -- the difference between waiting,
|
|
1789
|
+
moving on, and reporting a problem. */
|
|
1790
|
+
'avatar', 'presence-indicator', 'skeleton', 'empty-state',
|
|
1791
|
+
/* Structure. Every one of these is consumed by something: three
|
|
1792
|
+
are queried by this runtime, `list` hosts reorder(), and
|
|
1793
|
+
`canvas` is the door section 15.12 assigned to that surface. */
|
|
1794
|
+
'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas'
|
|
1571
1795
|
]);
|
|
1572
1796
|
|
|
1797
|
+
/* ---- Declared aliases (SPEC.md 1.5) ---------------------------
|
|
1798
|
+
Seven spellings this tree had grown for roles that already had a
|
|
1799
|
+
name. They are RESOLVED, not rejected: a spelling that ever
|
|
1800
|
+
worked keeps working (section 12 promise 2), and the migration
|
|
1801
|
+
of a tree is a decision its owner makes one page at a time, not
|
|
1802
|
+
something an upgrade imposes.
|
|
1803
|
+
|
|
1804
|
+
Resolution happens in _canonicalRole() below, before anything
|
|
1805
|
+
else in the runtime looks at a role -- so an alias reaches the
|
|
1806
|
+
known-role check, the click completion map and the manifest
|
|
1807
|
+
validator already spelled canonically. The static lint reports
|
|
1808
|
+
them as `dom_role_legacy_spelling` at severity warn, which is
|
|
1809
|
+
how a tree gets migrated deliberately.
|
|
1810
|
+
|
|
1811
|
+
NOT in this table, measured and kept as roles of their own:
|
|
1812
|
+
`feedback` (NAC.read_feedback() filters on it), `label`, `row`,
|
|
1813
|
+
`toast`, `toast-region` and `banner` (this runtime queries each
|
|
1814
|
+
of them by selector). A role the implementation reads is part
|
|
1815
|
+
of the contract whether the document said so or not. */
|
|
1816
|
+
const _ROLE_ALIASES = {
|
|
1817
|
+
'treenode': 'tree-node',
|
|
1818
|
+
'timeline-entry': 'timeline-item',
|
|
1819
|
+
'input': 'field',
|
|
1820
|
+
'textbox': 'field',
|
|
1821
|
+
'panel': 'region',
|
|
1822
|
+
'fab': 'action',
|
|
1823
|
+
'dropzone': 'drop-target'
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
/* Roles registered at runtime by a host (NAC.register_role, v2.8).
|
|
1827
|
+
Kept apart from _KNOWN_ROLES_V22 so introspection can always
|
|
1828
|
+
say which half of the vocabulary a role came from: the protocol
|
|
1829
|
+
or this page. */
|
|
1830
|
+
const _REGISTERED_ROLES = new Map();
|
|
1831
|
+
|
|
1832
|
+
function _canonicalRole(role) {
|
|
1833
|
+
if (!role) return role;
|
|
1834
|
+
const r = String(role);
|
|
1835
|
+
return Object.prototype.hasOwnProperty.call(_ROLE_ALIASES, r)
|
|
1836
|
+
? _ROLE_ALIASES[r]
|
|
1837
|
+
: r;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function _roleIsKnown(role) {
|
|
1841
|
+
const r = _canonicalRole(role);
|
|
1842
|
+
return _KNOWN_ROLES_V22.has(r) || _REGISTERED_ROLES.has(r);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1573
1845
|
function _v22Emit(severity, code, nac_id, message, detail) {
|
|
1574
1846
|
const fn = severity === 'error'
|
|
1575
1847
|
? (typeof console !== 'undefined' && console.error ? console.error.bind(console) : null)
|
|
@@ -1593,7 +1865,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1593
1865
|
if (!id) return; /* spec-level error caught elsewhere */
|
|
1594
1866
|
|
|
1595
1867
|
/* Check 1: role enumeration. */
|
|
1596
|
-
if (role && !
|
|
1868
|
+
if (role && !_roleIsKnown(role)) {
|
|
1597
1869
|
findings.push({
|
|
1598
1870
|
code: 'manifest_role_unknown',
|
|
1599
1871
|
nac_id: id,
|
|
@@ -1602,6 +1874,26 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
1602
1874
|
detail: { plugin: slug, source: source, role: role }
|
|
1603
1875
|
});
|
|
1604
1876
|
}
|
|
1877
|
+
/* v2.8.0: a declared alias (SPEC.md 1.5) is legal, and is
|
|
1878
|
+
REPORTED WITHOUT JOINING `findings` -- emitted straight at
|
|
1879
|
+
warn severity instead.
|
|
1880
|
+
|
|
1881
|
+
That distinction is the whole point, and the first draft of
|
|
1882
|
+
this block got it wrong: every entry of `findings` is emitted
|
|
1883
|
+
as an error AND makes register() throw under
|
|
1884
|
+
STRICT_VALIDATION, which has been the default since 2.3. So
|
|
1885
|
+
pushing this one would have meant that a page using a spelling
|
|
1886
|
+
v2.8 declares legal stops registering at all on upgrade --
|
|
1887
|
+
breaking exactly the adopter the alias table exists to
|
|
1888
|
+
protect, in the same release that promised not to. The suite
|
|
1889
|
+
that caught it is runtime/test/role-vocabulary.mjs. */
|
|
1890
|
+
if (role && role !== _canonicalRole(role)) {
|
|
1891
|
+
_v22Emit('warn', 'manifest_role_legacy_spelling', id,
|
|
1892
|
+
'plugin "' + slug + '" id="' + id + '" uses the legacy role spelling "' +
|
|
1893
|
+
role + '"; the canonical role is "' + _canonicalRole(role) +
|
|
1894
|
+
'" (SPEC.md 1.5). The alias resolves, so nothing is broken today.',
|
|
1895
|
+
{ plugin: slug, source: source, role: role, canonical: _canonicalRole(role) });
|
|
1896
|
+
}
|
|
1605
1897
|
|
|
1606
1898
|
/* Check 2: tab-id naming convention -- id like "tab.X" MUST
|
|
1607
1899
|
have role 'tab'. Catches the role drift class that broke
|
|
@@ -2113,10 +2405,60 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2113
2405
|
_emitAck('nac_editor.delete_selection');
|
|
2114
2406
|
}
|
|
2115
2407
|
async function aiCorrectSyntax() {
|
|
2116
|
-
status.textContent = 'asking AI...';
|
|
2117
2408
|
const original = textarea.value;
|
|
2409
|
+
|
|
2410
|
+
/* OFF UNTIL THE HOST SAYS WHERE (TF-A11).
|
|
2411
|
+
|
|
2412
|
+
What this did before 2.7.0: it POSTed the ENTIRE contents of
|
|
2413
|
+
the edited textarea to
|
|
2414
|
+
|
|
2415
|
+
(window.NacChat && window.NacChat._endpoint)
|
|
2416
|
+
|| '/crm/api/v1/yujin/nac-demo'
|
|
2417
|
+
|
|
2418
|
+
-- a default nobody on the host side had declared. The matter
|
|
2419
|
+
is narrower than it first looks and worth stating precisely:
|
|
2420
|
+
the path is RELATIVE, so the request went to the host's own
|
|
2421
|
+
origin, not to a third party. This was never a leak to
|
|
2422
|
+
yujin.app from an adopter's page.
|
|
2423
|
+
|
|
2424
|
+
It was still wrong, for two reasons that survive that
|
|
2425
|
+
correction:
|
|
2426
|
+
|
|
2427
|
+
1. a library does not get to send the user's text anywhere,
|
|
2428
|
+
not even to the host's own server, without the host
|
|
2429
|
+
asking. The host may have no handler on that path, may
|
|
2430
|
+
log request bodies, may be under a data-handling
|
|
2431
|
+
agreement that says what leaves the browser. That is the
|
|
2432
|
+
host's call to make and it was made for them.
|
|
2433
|
+
2. the only way to change it lived in ANOTHER FILE. An
|
|
2434
|
+
adopter who loads js/nac.js alone -- the documented way
|
|
2435
|
+
to get the runtime -- had no handle to redirect it and no
|
|
2436
|
+
way to switch it off.
|
|
2437
|
+
|
|
2438
|
+
So the endpoint is now declared, and on THIS file's export so
|
|
2439
|
+
loading the runtime alone is enough:
|
|
2440
|
+
|
|
2441
|
+
NAC.editor_ai_endpoint = '/my/own/handler';
|
|
2442
|
+
|
|
2443
|
+
With nothing declared and no chat client loaded, nothing is
|
|
2444
|
+
sent and the control says so. The action stays declared in the
|
|
2445
|
+
manifest and the button stays bound: an agent that invokes it
|
|
2446
|
+
gets an honest "not configured" instead of the control
|
|
2447
|
+
vanishing from the contract between one page and the next.
|
|
2448
|
+
NacChat's endpoint is still honoured when the host loaded the
|
|
2449
|
+
chat client, because that IS the host declaring one. */
|
|
2450
|
+
const endpoint = (global.NAC && global.NAC.editor_ai_endpoint)
|
|
2451
|
+
|| (window.NacChat && window.NacChat._endpoint)
|
|
2452
|
+
|| null;
|
|
2453
|
+
if (!endpoint) {
|
|
2454
|
+
status.textContent = 'AI correction is not configured: set NAC.editor_ai_endpoint'
|
|
2455
|
+
+ ' to the handler that should receive the text. Nothing was sent.';
|
|
2456
|
+
_emitAck('nac_editor.ai_correct_syntax');
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
status.textContent = 'asking AI...';
|
|
2118
2461
|
try {
|
|
2119
|
-
const endpoint = (window.NacChat && window.NacChat._endpoint) || '/crm/api/v1/yujin/nac-demo';
|
|
2120
2462
|
const resp = await fetch(endpoint, {
|
|
2121
2463
|
method: 'POST',
|
|
2122
2464
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -2206,18 +2548,37 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2206
2548
|
let manifest;
|
|
2207
2549
|
if (typeof arg1 === 'string' && arg2 && typeof arg2 === 'object') {
|
|
2208
2550
|
manifest = arg2;
|
|
2209
|
-
if (!manifest.plugin_slug) manifest.plugin_slug = arg1;
|
|
2210
2551
|
} else {
|
|
2211
2552
|
manifest = arg1;
|
|
2212
2553
|
}
|
|
2213
2554
|
if (!manifest || typeof manifest !== 'object') {
|
|
2214
2555
|
throw NacError('invalid', 'manifest object required');
|
|
2215
2556
|
}
|
|
2557
|
+
/* 2.7.0 (sec 7.2): the signed body is the manifest AS THE HOST
|
|
2558
|
+
BUILT IT. Snapshot it here, before the three defaults below
|
|
2559
|
+
change the bytes -- a host that signs {plugin_slug, elements}
|
|
2560
|
+
and calls register('invoice', m) would otherwise sign one
|
|
2561
|
+
object and have the runtime verify another, and the failure
|
|
2562
|
+
would look like a bad secret. */
|
|
2563
|
+
const _signedBody = (manifest.provenance && manifest.provenance.signature)
|
|
2564
|
+
? _manifestCanonicalString(manifest)
|
|
2565
|
+
: null;
|
|
2566
|
+
if (typeof arg1 === 'string' && arg2 === manifest && !manifest.plugin_slug) {
|
|
2567
|
+
manifest.plugin_slug = arg1;
|
|
2568
|
+
}
|
|
2216
2569
|
const slug = String(manifest.plugin_slug || '').trim();
|
|
2217
2570
|
if (!slug) throw NacError('invalid', 'manifest.plugin_slug required');
|
|
2218
2571
|
if (!manifest.version) manifest.version = '1.0.0';
|
|
2219
2572
|
if (!manifest.nac_version) manifest.nac_version = '1.0';
|
|
2220
2573
|
|
|
2574
|
+
/* 2.7.0 (sec 7.2, TF-A17): manifest authenticity. Throws when a
|
|
2575
|
+
provenance.signature is present and no registered tenant secret
|
|
2576
|
+
matches it; records what it could tell either way, so a
|
|
2577
|
+
validator can ask NAC.manifest_provenance(slug) instead of
|
|
2578
|
+
assuming. No secret registered = no check and no change for
|
|
2579
|
+
every adopter who never set one. */
|
|
2580
|
+
_recordManifestProvenance(slug, manifest, _signedBody);
|
|
2581
|
+
|
|
2221
2582
|
/* v2.5 / RFC V24-01 -- synchronous slug uniqueness gate.
|
|
2222
2583
|
Throws NacError('duplicate_plugin_no_instance_id', ...) when
|
|
2223
2584
|
the DOM already contains multiple roots for this slug and any
|
|
@@ -2420,6 +2781,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2420
2781
|
function unregister(slug) {
|
|
2421
2782
|
delete _manifests[slug];
|
|
2422
2783
|
delete _instances[slug];
|
|
2784
|
+
/* 2.7.0 (sec 7.2): the authenticity record is about the manifest
|
|
2785
|
+
that WAS registered. Leaving it behind would let a validator
|
|
2786
|
+
read "verified" for a plugin that is no longer mounted. */
|
|
2787
|
+
if (typeof _manifestProvenance !== 'undefined') {
|
|
2788
|
+
delete _manifestProvenance[slug];
|
|
2789
|
+
}
|
|
2423
2790
|
}
|
|
2424
2791
|
|
|
2425
2792
|
function manifest(slug) {
|
|
@@ -2451,17 +2818,24 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2451
2818
|
in one atomic step. Single source of truth for OCC. */
|
|
2452
2819
|
function syncPlugin(arg1, arg2) {
|
|
2453
2820
|
let m;
|
|
2821
|
+
let twoArg = false;
|
|
2454
2822
|
if (typeof arg1 === 'string' && arg2 && typeof arg2 === 'object') {
|
|
2455
2823
|
/* (slug, manifest) form -- match register's calling convention. */
|
|
2456
2824
|
m = Object.assign({}, arg2);
|
|
2457
|
-
|
|
2825
|
+
twoArg = true;
|
|
2826
|
+
/* 2.7.0 (sec 7.2): plugin_slug used to be injected HERE, which
|
|
2827
|
+
changed the bytes of a signed manifest before register() could
|
|
2828
|
+
hash them -- a host that signed {elements} and called
|
|
2829
|
+
syncPlugin('invoice', m) got a signature_mismatch that looked
|
|
2830
|
+
like a wrong secret. register() injects it now, after taking
|
|
2831
|
+
its snapshot, and both call forms go through that one place. */
|
|
2458
2832
|
} else if (arg1 && typeof arg1 === 'object') {
|
|
2459
2833
|
m = arg1;
|
|
2460
2834
|
} else {
|
|
2461
2835
|
throw NacError('invalid',
|
|
2462
2836
|
'syncPlugin: requires (manifest) or (slug, manifest)');
|
|
2463
2837
|
}
|
|
2464
|
-
const slug = m.plugin_slug;
|
|
2838
|
+
const slug = m.plugin_slug || (twoArg ? arg1 : null);
|
|
2465
2839
|
if (!slug || typeof slug !== 'string') {
|
|
2466
2840
|
throw NacError('invalid',
|
|
2467
2841
|
'syncPlugin: manifest.plugin_slug required (non-empty string)');
|
|
@@ -2477,7 +2851,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2477
2851
|
/* Delegate to register() so validation + storage code-path stays
|
|
2478
2852
|
exactly one place. If register throws (strict validation), the
|
|
2479
2853
|
prior entry is GONE -- caller's responsibility to handle. */
|
|
2480
|
-
register(m);
|
|
2854
|
+
if (twoArg) register(arg1, m); else register(m);
|
|
2481
2855
|
/* Bump V24-04 OCC version on REPLACE only. First-add is a normal
|
|
2482
2856
|
register: the boot tree_version already reflects the new plugin
|
|
2483
2857
|
and subscribers do not need to refresh anything that did not
|
|
@@ -2528,7 +2902,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2528
2902
|
|
|
2529
2903
|
Provenance on document:
|
|
2530
2904
|
nac:authority:requested / :granted / :denied / :revoked / :expired
|
|
2531
|
-
nac:action:confirmed
|
|
2905
|
+
nac:action:confirmed
|
|
2906
|
+
|
|
2907
|
+
(2.8.0: this comment used to name `nac:action:rejected` as well.
|
|
2908
|
+
No call site produces it -- the comment was the only place that
|
|
2909
|
+
name existed, which is the same defect as an event the spec names
|
|
2910
|
+
and the runtime never emits, one layer in. Found by
|
|
2911
|
+
scripts/check-event-vocabulary.mjs, which now refuses both
|
|
2912
|
+
directions.) */
|
|
2532
2913
|
|
|
2533
2914
|
const _V25_SCOPE_RANK = { low: 1, medium: 2, high: 3 };
|
|
2534
2915
|
const _v25_authority_grants = new Map();
|
|
@@ -2788,10 +3169,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2788
3169
|
}
|
|
2789
3170
|
|
|
2790
3171
|
function _allElements() {
|
|
3172
|
+
_nac_requireDocument('find');
|
|
2791
3173
|
return _deepQueryAll('[data-nac-id]', document, 0);
|
|
2792
3174
|
}
|
|
2793
3175
|
|
|
2794
3176
|
function _activePlugin() {
|
|
3177
|
+
_nac_requireDocument('find');
|
|
2795
3178
|
/* Most recently mounted plugin with state=ready wins. Falls back
|
|
2796
3179
|
to topmost plugin root in the DOM order. */
|
|
2797
3180
|
const plugins = Array.prototype.slice.call(
|
|
@@ -2902,17 +3285,18 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2902
3285
|
return null;
|
|
2903
3286
|
}
|
|
2904
3287
|
|
|
3288
|
+
/* The agent-facing `visible`. One predicate with the hash since
|
|
3289
|
+
2.7.0 -- see the long note on _isPerceivable for why the two used
|
|
3290
|
+
to disagree and which way the disagreement was settled. This also
|
|
3291
|
+
stops throwing in an environment with no defaultView. */
|
|
2905
3292
|
function _isVisible(el) {
|
|
2906
|
-
|
|
2907
|
-
const r = el.getBoundingClientRect();
|
|
2908
|
-
if (r.width === 0 && r.height === 0) return false;
|
|
2909
|
-
const cs = el.ownerDocument.defaultView.getComputedStyle(el);
|
|
2910
|
-
return cs.display !== 'none' && cs.visibility !== 'hidden' && cs.opacity !== '0';
|
|
3293
|
+
return _isPerceivable(el);
|
|
2911
3294
|
}
|
|
2912
3295
|
|
|
2913
3296
|
/* ---------- Public read API ------------------------------------- */
|
|
2914
3297
|
|
|
2915
3298
|
function describe() {
|
|
3299
|
+
_nac_requireDocument('describe');
|
|
2916
3300
|
const plugins = Array.prototype.slice.call(
|
|
2917
3301
|
document.querySelectorAll('[data-nac-plugin]')
|
|
2918
3302
|
).map(function (root) {
|
|
@@ -2981,6 +3365,152 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2981
3365
|
});
|
|
2982
3366
|
}
|
|
2983
3367
|
|
|
3368
|
+
/* ---- NAC.register_role(name, spec) (v2.8.0, SPEC.md 1.4) ------
|
|
3369
|
+
THE PROBLEM THIS SOLVES. The nineteen pieces of work that built
|
|
3370
|
+
the v2.8 vocabulary all shared one assumption: that adding a
|
|
3371
|
+
role means editing the protocol. Six layers, two of them
|
|
3372
|
+
published, one of them in nine languages. That is why the 52
|
|
3373
|
+
undeclared roles of 2026-11-25 existed at all -- somebody
|
|
3374
|
+
needed a word, the only door open was writing it into the HTML
|
|
3375
|
+
and hoping nobody looked, and for four years nobody did,
|
|
3376
|
+
because no rule compared the markup against the vocabulary.
|
|
3377
|
+
|
|
3378
|
+
So the vocabulary gets a door. A host declares a role at
|
|
3379
|
+
runtime, with the completion events it answers with, and from
|
|
3380
|
+
that moment:
|
|
3381
|
+
- the manifest validator accepts it instead of reporting
|
|
3382
|
+
manifest_role_unknown,
|
|
3383
|
+
- click() waits for ITS events instead of falling back to the
|
|
3384
|
+
action family and timing out at five seconds,
|
|
3385
|
+
- describe() / roles() report where it came from.
|
|
3386
|
+
|
|
3387
|
+
THE HARD PART, and how it is answered. A registered role exists
|
|
3388
|
+
only while the page is loaded, and the static lint runs with no
|
|
3389
|
+
page -- reading files. A role registered in JavaScript is
|
|
3390
|
+
invisible to it, so the lint would report a page as wrong for
|
|
3391
|
+
using a role that page itself declares. The answer is NOT to
|
|
3392
|
+
make the lint execute the page (a validator that runs the code
|
|
3393
|
+
it is validating has stopped being a validator). It is a second
|
|
3394
|
+
declaration the lint CAN read: a `nac3.roles.json` next to the
|
|
3395
|
+
markup, with the same shape as this argument. Two declarations
|
|
3396
|
+
of one fact is exactly the producer/consumer asymmetry this
|
|
3397
|
+
release spent its time removing, so it is not left to good
|
|
3398
|
+
intentions: `npx nac3 lint` reports role_registration_undeclared
|
|
3399
|
+
when a page calls register_role for a role its
|
|
3400
|
+
nac3.roles.json does not carry, and role_registration_orphan in
|
|
3401
|
+
the other direction.
|
|
3402
|
+
|
|
3403
|
+
WHAT IT REFUSES, and why each refusal is not negotiable:
|
|
3404
|
+
- a canonical role (SPEC.md 1.1 / 1.2). A page cannot
|
|
3405
|
+
redefine `action`: an agent that trusted the protocol's
|
|
3406
|
+
meaning of a canonical role would be reading a different
|
|
3407
|
+
contract on every page. This is the whole value of a closed
|
|
3408
|
+
vocabulary and a registry does not get to open it.
|
|
3409
|
+
- a declared alias (SPEC.md 1.5). Same reason, one level down.
|
|
3410
|
+
- a name that is not /^[a-z][a-z0-9-]*$/. Ids are opaque and
|
|
3411
|
+
roles are not: a role is compared, printed and published.
|
|
3412
|
+
- an event name that is not `nac:*`. A completion event that
|
|
3413
|
+
does not belong to this protocol cannot be waited for by
|
|
3414
|
+
anything that speaks it.
|
|
3415
|
+
Re-registering the SAME role with the SAME spec is idempotent
|
|
3416
|
+
and returns ok -- a page that registers on every render must not
|
|
3417
|
+
fail on the second one. Re-registering with a DIFFERENT spec
|
|
3418
|
+
throws: that is the one case where silence would leave two
|
|
3419
|
+
meanings for one word, which is where this release started. */
|
|
3420
|
+
function register_role(name, spec) {
|
|
3421
|
+
const raw = String(name == null ? '' : name);
|
|
3422
|
+
if (!/^[a-z][a-z0-9-]*$/.test(raw)) {
|
|
3423
|
+
throw NacError('invalid_role',
|
|
3424
|
+
'register_role: "' + raw + '" is not a legal role name. A role is lowercase'
|
|
3425
|
+
+ ' letters, digits and hyphens, starting with a letter (SPEC.md 1.4).');
|
|
3426
|
+
}
|
|
3427
|
+
if (_KNOWN_ROLES_V22.has(raw)) {
|
|
3428
|
+
throw NacError('role_is_canonical',
|
|
3429
|
+
'register_role: "' + raw + '" is a canonical role of SPEC.md section 1 and cannot be'
|
|
3430
|
+
+ ' redefined. An agent relies on a canonical role meaning the same thing on every'
|
|
3431
|
+
+ ' page; a page that could change it would be publishing a different protocol.');
|
|
3432
|
+
}
|
|
3433
|
+
if (Object.prototype.hasOwnProperty.call(_ROLE_ALIASES, raw)) {
|
|
3434
|
+
throw NacError('role_is_alias',
|
|
3435
|
+
'register_role: "' + raw + '" is a declared alias of "' + _ROLE_ALIASES[raw] +
|
|
3436
|
+
'" (SPEC.md 1.5) and cannot be redefined.');
|
|
3437
|
+
}
|
|
3438
|
+
spec = spec || {};
|
|
3439
|
+
const events = Array.isArray(spec.events) ? spec.events.slice(0, 2) : [];
|
|
3440
|
+
for (const ev of events) {
|
|
3441
|
+
if (typeof ev !== 'string' || ev.indexOf('nac:') !== 0) {
|
|
3442
|
+
throw NacError('invalid_role',
|
|
3443
|
+
'register_role("' + raw + '"): completion event "' + String(ev) + '" is not a NAC3'
|
|
3444
|
+
+ ' event name. A completion event must be nac:<family>:<name> so anything that'
|
|
3445
|
+
+ ' speaks this protocol can wait for it (SPEC.md 6.4).');
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
const entry = {
|
|
3449
|
+
role: raw,
|
|
3450
|
+
events: events,
|
|
3451
|
+
clickable: events.length > 0,
|
|
3452
|
+
describes: (typeof spec.describes === 'string') ? spec.describes : null,
|
|
3453
|
+
plugin: (typeof spec.plugin === 'string') ? spec.plugin : null,
|
|
3454
|
+
source: 'registered'
|
|
3455
|
+
};
|
|
3456
|
+
const prior = _REGISTERED_ROLES.get(raw);
|
|
3457
|
+
if (prior) {
|
|
3458
|
+
/* Idempotent on an identical re-registration: a page that
|
|
3459
|
+
registers its roles on every render must not fail on the
|
|
3460
|
+
second render. Different spec, same name -> throw, because
|
|
3461
|
+
that is two meanings for one word. */
|
|
3462
|
+
if (JSON.stringify(prior) === JSON.stringify(entry)) {
|
|
3463
|
+
return { ok: true, role: raw, already: true };
|
|
3464
|
+
}
|
|
3465
|
+
throw NacError('role_conflict',
|
|
3466
|
+
'register_role("' + raw + '"): already registered with a different definition.'
|
|
3467
|
+
+ ' Prior events=[' + prior.events.join(', ') + '], new events=[' +
|
|
3468
|
+
events.join(', ') + ']. Two definitions of one role is the drift this'
|
|
3469
|
+
+ ' registry exists to prevent.');
|
|
3470
|
+
}
|
|
3471
|
+
_REGISTERED_ROLES.set(raw, entry);
|
|
3472
|
+
try {
|
|
3473
|
+
document.dispatchEvent(new CustomEvent('nac:role_registered', {
|
|
3474
|
+
detail: { role: raw, events: events, clickable: entry.clickable,
|
|
3475
|
+
describes: entry.describes, plugin: entry.plugin },
|
|
3476
|
+
bubbles: true
|
|
3477
|
+
}));
|
|
3478
|
+
} catch (_) { /* headless (section 19): no document to dispatch on */ }
|
|
3479
|
+
return { ok: true, role: raw, already: false };
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
/* NAC.roles() -- the vocabulary, with the provenance of every
|
|
3483
|
+
word. Built so a consumer never has to ask which half of the
|
|
3484
|
+
contract a role came from: `canonical` is the protocol,
|
|
3485
|
+
`registered` is this page, `aliases` is what resolves to what.
|
|
3486
|
+
Published as data for the same reason section 1 is: a list a
|
|
3487
|
+
consumer has to reconstruct from prose is a list that rots. */
|
|
3488
|
+
function roles() {
|
|
3489
|
+
const registered = [];
|
|
3490
|
+
_REGISTERED_ROLES.forEach(function (v) { registered.push(v); });
|
|
3491
|
+
const click_events = {};
|
|
3492
|
+
for (const r in _CLICK_EVENT_FAMILY) {
|
|
3493
|
+
if (Object.prototype.hasOwnProperty.call(_CLICK_EVENT_FAMILY, r)) {
|
|
3494
|
+
click_events[r] = _CLICK_EVENT_FAMILY[r].slice();
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
return {
|
|
3498
|
+
spec_version: '2.8',
|
|
3499
|
+
canonical: Array.from(_KNOWN_ROLES_V22),
|
|
3500
|
+
aliases: Object.assign({}, _ROLE_ALIASES),
|
|
3501
|
+
registered: registered,
|
|
3502
|
+
click_events: click_events,
|
|
3503
|
+
no_click_event: Array.from(_CLICK_NO_EVENT_ROLES)
|
|
3504
|
+
};
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
/* NAC.canonical_role(role) -- what a spelling means. One line, and
|
|
3508
|
+
it exists because every consumer that compares a role to a
|
|
3509
|
+
constant needs the same answer this runtime gives itself. */
|
|
3510
|
+
function canonical_role(role) {
|
|
3511
|
+
return _canonicalRole(role);
|
|
3512
|
+
}
|
|
3513
|
+
|
|
2984
3514
|
function snapshot_state() {
|
|
2985
3515
|
const errs = _allElements()
|
|
2986
3516
|
.filter(function (el) {
|
|
@@ -3144,7 +3674,11 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3144
3674
|
const _CLICK_EVENT_FAMILY = {
|
|
3145
3675
|
'action': ['nac:action:succeeded', 'nac:action:failed'],
|
|
3146
3676
|
'option': ['nac:field:changed'],
|
|
3147
|
-
|
|
3677
|
+
/* v2.8.0: the failure half. nac:tab:activation_failed has been
|
|
3678
|
+
emitted since v2.2 and was not in this map, so click() on a
|
|
3679
|
+
tab whose activation was REFUSED waited out its full timeout
|
|
3680
|
+
instead of rejecting the moment the refusal arrived. */
|
|
3681
|
+
'tab': ['nac:tab:activated', 'nac:tab:activation_failed'],
|
|
3148
3682
|
'breadcrumb-item': ['nac:breadcrumb:navigated'],
|
|
3149
3683
|
'accordion-toggle': ['nac:accordion:expanded', 'nac:accordion:collapsed'],
|
|
3150
3684
|
'step': ['nac:step:advanced'],
|
|
@@ -3165,8 +3699,104 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3165
3699
|
column_nac_id and filter_nac_id as nac_id matches. */
|
|
3166
3700
|
'sort-control': ['nac:table:sort_changed'],
|
|
3167
3701
|
'filter-control': ['nac:table:filter_changed'],
|
|
3702
|
+
/* v2.7.0: `button` made EXPLICIT. SPEC.md section 1 says the
|
|
3703
|
+
runtime treats this role as `action`, and it did -- but only by
|
|
3704
|
+
falling through the `||` below, which is indistinguishable from
|
|
3705
|
+
a role nobody thought about. The fallback was right for this one
|
|
3706
|
+
role and wrong for the other eight, and nothing told them
|
|
3707
|
+
apart. Declaring it costs one line and removes the ambiguity
|
|
3708
|
+
that let the other eight hide. */
|
|
3709
|
+
'button': ['nac:action:succeeded', 'nac:action:failed'],
|
|
3710
|
+
|
|
3711
|
+
/* ---- v2.8.0: the twelve clickable surface roles -------------
|
|
3712
|
+
Each line removes one five-second timeout that blamed the
|
|
3713
|
+
page. The runtime ALREADY emitted every event named here --
|
|
3714
|
+
nac:map:marker_selected has existed since 2.5 -- so the
|
|
3715
|
+
defect was never that the signal was missing: it was that
|
|
3716
|
+
click() did not know the signal belonged to that role, took
|
|
3717
|
+
the `|| _CLICK_EVENT_FAMILY['action']` fallback below, waited
|
|
3718
|
+
for nac:action:succeeded, heard nothing and reported that the
|
|
3719
|
+
WIDGET had not acknowledged. The project paid this twice
|
|
3720
|
+
before (v1.6.4 for `field`, v1.6.6 for `sort-control`, both
|
|
3721
|
+
comments above) and both times fixed one role instead of the
|
|
3722
|
+
class. These twelve are the class.
|
|
3723
|
+
|
|
3724
|
+
Where two events existed for the same thing, the canonical
|
|
3725
|
+
one is here and the other stays emitted (SPEC.md 6.4). */
|
|
3726
|
+
'map-marker': ['nac:map:marker_selected'],
|
|
3727
|
+
'map-layer': ['nac:map:layer_toggled'],
|
|
3728
|
+
'chart-series': ['nac:chart:series_toggled'],
|
|
3729
|
+
'calendar-event': ['nac:calendar:event_selected'],
|
|
3730
|
+
'tree-node': ['nac:tree:selected'],
|
|
3731
|
+
'carousel-slide': ['nac:carousel:slide_changed'],
|
|
3732
|
+
'toast': ['nac:toast:dismissed'],
|
|
3733
|
+
'banner': ['nac:banner:dismissed'],
|
|
3734
|
+
'combobox': ['nac:field:changed'],
|
|
3735
|
+
'listbox': ['nac:field:changed'],
|
|
3736
|
+
'slider': ['nac:slider:value_changed'],
|
|
3737
|
+
'richtext': ['nac:richtext:format_applied'],
|
|
3168
3738
|
};
|
|
3169
3739
|
|
|
3740
|
+
/* The canonical roles that have NO completion event of their own,
|
|
3741
|
+
declared rather than left to the fallback.
|
|
3742
|
+
|
|
3743
|
+
THE DEFECT THIS CLOSES (TF-A14). _CLICK_EVENT_FAMILY knew 11 of
|
|
3744
|
+
the 20 canonical roles of SPEC.md section 1, and click() on
|
|
3745
|
+
anything else took `|| _CLICK_EVENT_FAMILY['action']` -- so it
|
|
3746
|
+
waited for nac:action:succeeded, heard nothing, timed out after
|
|
3747
|
+
five seconds and reported that the WIDGET had not acked. An agent
|
|
3748
|
+
doing exactly what the protocol tells it to do about one of these
|
|
3749
|
+
roles paid five seconds and got a message blaming the page.
|
|
3750
|
+
|
|
3751
|
+
And it is not hypothetical. The comments above record the same
|
|
3752
|
+
shape twice already: v1.6.4 for `field`, v1.6.6 for
|
|
3753
|
+
`sort-control`. Both were found by someone watching a click hang.
|
|
3754
|
+
|
|
3755
|
+
These nine are STRUCTURAL -- a plugin, a section, a region, a
|
|
3756
|
+
navigation landmark, a data-table host, a confirm dialog -- or
|
|
3757
|
+
are driven by their own verb rather than by click: a draggable and
|
|
3758
|
+
a drop target are what drag_drop() moves. None of them has a
|
|
3759
|
+
completion event in the protocol, so there is nothing for click()
|
|
3760
|
+
to wait for.
|
|
3761
|
+
|
|
3762
|
+
WHAT DOES NOT CHANGE, on purpose: click() still clicks them and
|
|
3763
|
+
still listens for the action family, because a host is free to
|
|
3764
|
+
make a region clickable and emit nac:action:succeeded, and that
|
|
3765
|
+
works today. Refusing outright would break those hosts for the
|
|
3766
|
+
sake of a tidier error. What changes is that the TIMEOUT now says
|
|
3767
|
+
what actually happened instead of blaming the widget -- see the
|
|
3768
|
+
rejection in click(). */
|
|
3769
|
+
const _CLICK_NO_EVENT_ROLES = new Set([
|
|
3770
|
+
'plugin', 'section', 'region', 'navigation', 'data-table',
|
|
3771
|
+
'confirm-dialog', 'draggable', 'drop-target',
|
|
3772
|
+
|
|
3773
|
+
/* ---- v2.8.0 ------------------------------------------------
|
|
3774
|
+
Thirty-three more, and declaring them is the whole point: a
|
|
3775
|
+
role in this Set gets a timeout message that says "this role
|
|
3776
|
+
has no completion event in the protocol", and a role in
|
|
3777
|
+
NEITHER map gets "no completion event is declared for this
|
|
3778
|
+
role" -- which is the protocol admitting a gap instead of
|
|
3779
|
+
blaming the widget. Until 2.8.0 these thirty-three were in
|
|
3780
|
+
neither map and were indistinguishable from a typo.
|
|
3781
|
+
|
|
3782
|
+
Why each is here rather than in the family map above: four
|
|
3783
|
+
are structural hosts (map, chart, calendar, tree, timeline,
|
|
3784
|
+
carousel, list), six are containers whose CONTROL carries the
|
|
3785
|
+
event (tablist, tabpanel, stepper, accordion-section,
|
|
3786
|
+
breadcrumb, pagination-control, toast-region), and the rest
|
|
3787
|
+
are read-only. Putting a read-only role in the family map
|
|
3788
|
+
would make click() promise a completion nobody emits, which
|
|
3789
|
+
is worse than the omission it would be fixing. */
|
|
3790
|
+
'map', 'chart', 'chart-point', 'calendar',
|
|
3791
|
+
'tree', 'tree-children', 'timeline', 'timeline-item',
|
|
3792
|
+
'carousel', 'status', 'log', 'toast-region', 'feedback',
|
|
3793
|
+
'modal', 'drawer', 'bottom-sheet',
|
|
3794
|
+
'tablist', 'tabpanel', 'stepper', 'accordion-section',
|
|
3795
|
+
'breadcrumb', 'pagination-control',
|
|
3796
|
+
'avatar', 'presence-indicator', 'skeleton', 'empty-state',
|
|
3797
|
+
'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas',
|
|
3798
|
+
]);
|
|
3799
|
+
|
|
3170
3800
|
/* v1.6.4: field types whose click() act on a value (toggle).
|
|
3171
3801
|
For these, the runtime synthesises nac:field:changed after
|
|
3172
3802
|
el.click() so an automation runner sees a deterministic
|
|
@@ -3236,15 +3866,52 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3236
3866
|
var rect = el.getBoundingClientRect();
|
|
3237
3867
|
hiddenByLayout = (rect.width === 0 && rect.height === 0);
|
|
3238
3868
|
}
|
|
3239
|
-
|
|
3869
|
+
/* 2.7.0: the ANCESTOR reasons too, through the same function the
|
|
3870
|
+
probe uses.
|
|
3871
|
+
|
|
3872
|
+
Found on 2026-11-25 by the suite written for undrivable_until.
|
|
3873
|
+
The two checks above read the element ITSELF, while
|
|
3874
|
+
validate_global's probe reads `closest('[aria-hidden="true"]')`,
|
|
3875
|
+
`closest('[inert]')` and the computed style -- so the two
|
|
3876
|
+
disagreed about a button inside a hidden PANEL, which is the
|
|
3877
|
+
commonest shape there is. And section 10.1 publishes the
|
|
3878
|
+
agreement as a fact: the unreachable bucket is "exactly what
|
|
3879
|
+
NAC.click() refuses with NacError('hidden')". It was not. The
|
|
3880
|
+
probe called the seven chat ids of this project's own landing
|
|
3881
|
+
page unreachable and click() would have fired into the closed
|
|
3882
|
+
panel, where the host handler never runs and the agent waits out
|
|
3883
|
+
the five-second completion timeout for a click nobody could
|
|
3884
|
+
see -- the silent damage, arriving as a timeout instead of a
|
|
3885
|
+
reason. _probeUnreachable IS the definition now, for the verb
|
|
3886
|
+
and for the validator, so a disagreement between them is not
|
|
3887
|
+
expressible. Decided rather than registered because the
|
|
3888
|
+
normative text already promised this behaviour and the code was
|
|
3889
|
+
the half that was wrong (working agreement rule 10; the owner
|
|
3890
|
+
delegated the call for this session on 2026-11-25). */
|
|
3891
|
+
var hiddenByAncestor = _probeUnreachable(el);
|
|
3892
|
+
if (hiddenByAria || hiddenByLayout || hiddenByAncestor) {
|
|
3893
|
+
/* 2.7.0: if the manifest declared what opens this element, the
|
|
3894
|
+
rejection carries it. The refusal itself does not change --
|
|
3895
|
+
the element is hidden and clicking it would be a lie -- but an
|
|
3896
|
+
agent that gets "open nac_landing.chat.toggle first" has its
|
|
3897
|
+
next move, and one that gets "is not visible" has nothing.
|
|
3898
|
+
That gap was measured on this project's own landing page:
|
|
3899
|
+
seven declared ids behind a closed panel. */
|
|
3900
|
+
var gateId = _resolveGate(nac_id);
|
|
3901
|
+
var msg = 'Element ' + nac_id + ' is not visible'
|
|
3902
|
+
+ (gateId ? ': it is declared undrivable until "' + gateId
|
|
3903
|
+
+ '" is operated -- do that first, then retry' : '');
|
|
3240
3904
|
_emitCommandRejected({
|
|
3241
3905
|
command_method: 'click',
|
|
3242
3906
|
command_target: nac_id,
|
|
3243
3907
|
reason: 'hidden',
|
|
3244
|
-
message:
|
|
3908
|
+
message: msg,
|
|
3909
|
+
gate: gateId || undefined,
|
|
3245
3910
|
source: (opts && opts.source) || undefined,
|
|
3246
3911
|
});
|
|
3247
|
-
|
|
3912
|
+
var hiddenErr = NacError('hidden', msg);
|
|
3913
|
+
if (gateId) hiddenErr.gate = gateId;
|
|
3914
|
+
throw hiddenErr;
|
|
3248
3915
|
}
|
|
3249
3916
|
/* v1.9.0 ARIA preflight (sec 7.3.3): inert ancestor + aria-busy
|
|
3250
3917
|
block click before the host handler runs. Disabled is already
|
|
@@ -3273,8 +3940,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3273
3940
|
await _resolveVersionExpectations(opts, el);
|
|
3274
3941
|
}
|
|
3275
3942
|
}
|
|
3276
|
-
|
|
3277
|
-
|
|
3943
|
+
/* v2.8.0: resolve a declared alias (SPEC.md 1.5) BEFORE picking
|
|
3944
|
+
the family, so a page that still writes `treenode` gets the
|
|
3945
|
+
tree-node completion event instead of the action fallback. */
|
|
3946
|
+
const role = _canonicalRole(el.getAttribute('data-nac-role') || 'action');
|
|
3947
|
+
const family = _CLICK_EVENT_FAMILY[role]
|
|
3948
|
+
|| (_REGISTERED_ROLES.has(role) && _REGISTERED_ROLES.get(role).events)
|
|
3949
|
+
|| _CLICK_EVENT_FAMILY['action'];
|
|
3278
3950
|
/* The first event in each family is the "success" signal; if a
|
|
3279
3951
|
second entry exists it is the "failure" signal. Some families
|
|
3280
3952
|
(option, tab, breadcrumb, step, pagination) have no failure
|
|
@@ -3285,8 +3957,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3285
3957
|
const successEvents = [family[0]];
|
|
3286
3958
|
const failureEvents = family.length > 1 ? [family[1]] : [];
|
|
3287
3959
|
if (role !== 'action') {
|
|
3288
|
-
|
|
3289
|
-
|
|
3960
|
+
/* Deduplicated since 2.7.0. A role with no family of its own
|
|
3961
|
+
falls back to the action family above and then had it pushed
|
|
3962
|
+
again, so the timeout message read "did not emit any of
|
|
3963
|
+
[nac:action:succeeded, nac:action:succeeded,
|
|
3964
|
+
nac:action:failed, nac:action:failed]" -- which makes a reader
|
|
3965
|
+
hunt for two contracts where there is one. Harmless to the
|
|
3966
|
+
listeners, confusing in the one place anybody reads. */
|
|
3967
|
+
if (successEvents.indexOf('nac:action:succeeded') < 0) {
|
|
3968
|
+
successEvents.push('nac:action:succeeded');
|
|
3969
|
+
}
|
|
3970
|
+
if (failureEvents.indexOf('nac:action:failed') < 0) {
|
|
3971
|
+
failureEvents.push('nac:action:failed');
|
|
3972
|
+
}
|
|
3290
3973
|
}
|
|
3291
3974
|
/* v1.6.5: cache plugin slug + option value/text BEFORE el.click()
|
|
3292
3975
|
fires. The host's click handler may DETACH el from the DOM
|
|
@@ -3332,10 +4015,28 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3332
4015
|
if (settled) return;
|
|
3333
4016
|
settled = true;
|
|
3334
4017
|
cleanup();
|
|
4018
|
+
/* Say WHY nothing arrived (TF-A14). The old message named the
|
|
4019
|
+
events and the elapsed time, which reads as "the widget did
|
|
4020
|
+
not ack" -- and for a role with no completion event in the
|
|
4021
|
+
protocol that is the wrong diagnosis in the one case where
|
|
4022
|
+
the runtime already knows the answer. Five seconds and a
|
|
4023
|
+
misattributed failure, per control. */
|
|
4024
|
+
const knownFamily = Object.prototype.hasOwnProperty.call(_CLICK_EVENT_FAMILY, role);
|
|
4025
|
+
let why = '';
|
|
4026
|
+
if (_CLICK_NO_EVENT_ROLES.has(role)) {
|
|
4027
|
+
why = ' -- role "' + role + '" has no completion event in NAC3: it is structural, or'
|
|
4028
|
+
+ ' it is driven by its own verb (a draggable and a drop-target are what drag_drop()'
|
|
4029
|
+
+ ' moves). If this control is meant to be clickable, have its handler emit'
|
|
4030
|
+
+ ' nac:action:succeeded (NAC.bindAction does it for you).';
|
|
4031
|
+
} else if (!knownFamily) {
|
|
4032
|
+
why = ' -- role "' + role + '" is not one of the canonical roles of SPEC.md section 1,'
|
|
4033
|
+
+ ' so this runtime waited for the action family by default. Declare a canonical'
|
|
4034
|
+
+ ' role, or emit nac:action:succeeded from the handler.';
|
|
4035
|
+
}
|
|
3335
4036
|
reject(NacError('timeout',
|
|
3336
4037
|
'click(' + nac_id + ', role=' + role + ') did not emit any of [' +
|
|
3337
4038
|
successEvents.concat(failureEvents).join(', ') + '] within ' +
|
|
3338
|
-
timeout_ms + 'ms'));
|
|
4039
|
+
timeout_ms + 'ms' + why));
|
|
3339
4040
|
}, timeout_ms);
|
|
3340
4041
|
successEvents.forEach(function (n) { document.addEventListener(n, onSucceeded); });
|
|
3341
4042
|
failureEvents.forEach(function (n) { document.addEventListener(n, onFailed); });
|
|
@@ -3404,7 +4105,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
3404
4105
|
d.stepper_id === nac_id || d.carousel_id === nac_id ||
|
|
3405
4106
|
d.timeline_id === nac_id || d.option_id === nac_id ||
|
|
3406
4107
|
d.table_id === nac_id ||
|
|
3407
|
-
/* v1.6.x legacy aliases
|
|
4108
|
+
/* v1.6.x legacy aliases. NOT deprecated-with-a-date any
|
|
4109
|
+
more (D-12, 2026-11-24): these six are RESOLUTION KEYS
|
|
4110
|
+
-- this is the code that reads them -- so the v2.0
|
|
4111
|
+
removal the comment used to announce would have broken
|
|
4112
|
+
event resolution for any host emitting only an alias.
|
|
4113
|
+
Frozen: they resolve for good, the canonical field is
|
|
4114
|
+
still the one to emit. */
|
|
3408
4115
|
d.nac_id === nac_id || d.from_nac_id === nac_id ||
|
|
3409
4116
|
d.target_nac_id === nac_id || d.id === nac_id ||
|
|
3410
4117
|
d.column_nac_id === nac_id || d.filter_nac_id === nac_id ||
|
|
@@ -4714,13 +5421,63 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4714
5421
|
emission.)
|
|
4715
5422
|
|
|
4716
5423
|
A NAC-3 codebase that wants drift to be a CI blocker should run
|
|
4717
|
-
this in addition to the per-plugin validate(slug) loop.
|
|
4718
|
-
|
|
5424
|
+
this in addition to the per-plugin validate(slug) loop.
|
|
5425
|
+
|
|
5426
|
+
THE opts ARGUMENT (2.7.0, audit N-35 / TF-A16). SPEC.md section
|
|
5427
|
+
5.2 has published the signature as
|
|
5428
|
+
validate_global(opts?: {probe?: boolean}) since 2.5, and section
|
|
5429
|
+
8 keys two conformance levels on it: level 2 wants
|
|
5430
|
+
validate_global({probe: false}) with zero error findings, level 3
|
|
5431
|
+
wants validate_global({probe: true}) with zero findings of ANY
|
|
5432
|
+
severity. This function TOOK NO ARGUMENTS. Passing {probe:true}
|
|
5433
|
+
was accepted and ignored, so the level 3 check was the level 2
|
|
5434
|
+
check with a stricter threshold and the word "probe" meant
|
|
5435
|
+
nothing -- measured while building the reference validator, and
|
|
5436
|
+
written into scripts/contract-api.meta.json as the reason no tool
|
|
5437
|
+
could decide that requirement.
|
|
5438
|
+
|
|
5439
|
+
What probing IS, now that it is defined: the static half of this
|
|
5440
|
+
validator compares two LISTS -- the manifests and the ids present
|
|
5441
|
+
in the DOM. It never asks whether a declared element can actually
|
|
5442
|
+
be reached, so the two failures an agent hits most do not appear
|
|
5443
|
+
in the report:
|
|
5444
|
+
|
|
5445
|
+
ambiguous the same nac_id is on 2+ DOM nodes under ONE
|
|
5446
|
+
manifest. find() takes the first, so click()
|
|
5447
|
+
silently operates on whichever node the document
|
|
5448
|
+
happens to list first. The duplicates bucket does
|
|
5449
|
+
NOT cover this: it compares manifests to each
|
|
5450
|
+
other, not the DOM to itself.
|
|
5451
|
+
unreachable the element is mounted but an agent cannot touch
|
|
5452
|
+
it -- an aria-hidden or inert ancestor, or a box
|
|
5453
|
+
that is not displayed. click() would reject it
|
|
5454
|
+
with NacError('hidden'), so the manifest declares
|
|
5455
|
+
a surface the protocol cannot operate.
|
|
5456
|
+
|
|
5457
|
+
Both buckets exist in the report ALWAYS, and are empty unless
|
|
5458
|
+
probe is true: a consumer reading the shape does not have to
|
|
5459
|
+
branch on the argument, and a caller who never passes opts gets
|
|
5460
|
+
exactly the report 2.5 gave them. Probing reads the DOM and
|
|
5461
|
+
reads computed style; it clicks nothing and mutates nothing. */
|
|
5462
|
+
function validate_global(opts) {
|
|
5463
|
+
_nac_requireDocument('validate_global');
|
|
5464
|
+
const probe = !!(opts && opts.probe);
|
|
4719
5465
|
const out = {
|
|
4720
5466
|
ok: true,
|
|
5467
|
+
probed: probe,
|
|
4721
5468
|
duplicates: [],
|
|
4722
5469
|
orphans: [],
|
|
4723
5470
|
unmounted: [],
|
|
5471
|
+
ambiguous: [],
|
|
5472
|
+
unreachable: [],
|
|
5473
|
+
/* 2.7.0: declared-and-gated surfaces. This bucket is NOT a
|
|
5474
|
+
findings bucket -- an element that declares what opens it is
|
|
5475
|
+
keeping the contract, not breaking it -- and like the two
|
|
5476
|
+
probe buckets above it is always present and empty unless the
|
|
5477
|
+
caller asked to probe. It is reported because an agent reading
|
|
5478
|
+
the validation output is exactly who needs to know that four
|
|
5479
|
+
of these ids need a panel opened first. */
|
|
5480
|
+
gated: [],
|
|
4724
5481
|
convention_violations: [],
|
|
4725
5482
|
/* v2.5 / RFC V24-01: plugin slug uniqueness findings live in
|
|
4726
5483
|
their own bucket so CI integrations can gate on them
|
|
@@ -4780,12 +5537,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4780
5537
|
- if not in idIndex, it is an orphan.
|
|
4781
5538
|
- track DOM-side seen ids to compute unmounted = manifest \ DOM. */
|
|
4782
5539
|
const inDom = Object.create(null);
|
|
5540
|
+
const domNodes = Object.create(null);
|
|
4783
5541
|
if (typeof document !== 'undefined') {
|
|
4784
5542
|
const all = document.querySelectorAll('[data-nac-id]');
|
|
4785
5543
|
Array.prototype.forEach.call(all, function (el) {
|
|
4786
5544
|
const id = el.getAttribute('data-nac-id');
|
|
4787
5545
|
if (!id) return;
|
|
4788
5546
|
inDom[id] = true;
|
|
5547
|
+
if (!domNodes[id]) domNodes[id] = [];
|
|
5548
|
+
domNodes[id].push(el);
|
|
4789
5549
|
if (!idIndex[id]) {
|
|
4790
5550
|
/* Orphan in DOM but not in any manifest. Note: tabs
|
|
4791
5551
|
frequently are declared in DOM-only because the host
|
|
@@ -4816,6 +5576,80 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4816
5576
|
}
|
|
4817
5577
|
}
|
|
4818
5578
|
|
|
5579
|
+
/* 2.7.0: the probe pass (opts.probe). Only declared ids are
|
|
5580
|
+
probed: an id nothing declares is already reported as an
|
|
5581
|
+
orphan, and a brownfield page full of them is the normal case
|
|
5582
|
+
this validator was built to tolerate. */
|
|
5583
|
+
if (probe && typeof document !== 'undefined') {
|
|
5584
|
+
for (const id in idIndex) {
|
|
5585
|
+
const nodes = domNodes[id] || [];
|
|
5586
|
+
if (nodes.length >= 2) {
|
|
5587
|
+
out.ambiguous.push({
|
|
5588
|
+
code: 'nac_id_ambiguous_in_dom',
|
|
5589
|
+
severity: 'error',
|
|
5590
|
+
nac_id: id, count: nodes.length,
|
|
5591
|
+
plugin: idIndex[id][0],
|
|
5592
|
+
hint: 'find() resolves the first match, so which element an '
|
|
5593
|
+
+ 'agent operates depends on document order',
|
|
5594
|
+
});
|
|
5595
|
+
}
|
|
5596
|
+
if (nodes.length === 1) {
|
|
5597
|
+
const why = _probeUnreachable(nodes[0]);
|
|
5598
|
+
if (why) {
|
|
5599
|
+
/* 2.7.0: a surface that DECLARES what opens it is not a
|
|
5600
|
+
defect -- it is a gated surface, and the agent now has
|
|
5601
|
+
its next move. The declaration is only honoured when the
|
|
5602
|
+
gate itself holds up; see _resolveGate. */
|
|
5603
|
+
const gate = _resolveGate(id);
|
|
5604
|
+
const gateNodes = gate ? (domNodes[gate] || []) : [];
|
|
5605
|
+
/* The four ways a declared gate fails to be a way in. They
|
|
5606
|
+
are separate values because they are separate fixes: one
|
|
5607
|
+
is a manifest that forgot the gate, one is a view that
|
|
5608
|
+
has not mounted it, one is an id on two nodes -- where
|
|
5609
|
+
find() picks by document order, so "operate the gate"
|
|
5610
|
+
does not name one thing -- and one is a gate behind its
|
|
5611
|
+
own closed container. */
|
|
5612
|
+
const gateBad = !gate ? null
|
|
5613
|
+
: (!idIndex[gate] ? 'gate_not_declared'
|
|
5614
|
+
: (gateNodes.length === 0 ? 'gate_not_mounted'
|
|
5615
|
+
: (gateNodes.length >= 2 ? 'gate_ambiguous'
|
|
5616
|
+
: (_probeUnreachable(gateNodes[0]) ? 'gate_not_reachable'
|
|
5617
|
+
: null))));
|
|
5618
|
+
if (gate && !gateBad) {
|
|
5619
|
+
out.gated.push({
|
|
5620
|
+
code: 'nac_id_undrivable_until_gate',
|
|
5621
|
+
severity: 'info',
|
|
5622
|
+
nac_id: id, reason: why, gate: gate,
|
|
5623
|
+
plugin: idIndex[id][0],
|
|
5624
|
+
hint: 'declared as undrivable until "' + gate + '" is operated; '
|
|
5625
|
+
+ 'click() refuses it until then and says so',
|
|
5626
|
+
});
|
|
5627
|
+
} else if (gate) {
|
|
5628
|
+
out.unreachable.push({
|
|
5629
|
+
code: 'nac_id_undrivable_gate_unusable',
|
|
5630
|
+
severity: 'error',
|
|
5631
|
+
nac_id: id, reason: why, gate: gate, gate_problem: gateBad,
|
|
5632
|
+
plugin: idIndex[id][0],
|
|
5633
|
+
hint: 'undrivable_until names "' + gate + '", and that gate is '
|
|
5634
|
+
+ gateBad.replace(/_/g, ' ') + ' -- a promised way in that '
|
|
5635
|
+
+ 'does not open is worse than none, an agent waits for it',
|
|
5636
|
+
});
|
|
5637
|
+
} else {
|
|
5638
|
+
out.unreachable.push({
|
|
5639
|
+
code: 'nac_id_declared_not_reachable',
|
|
5640
|
+
severity: 'warn',
|
|
5641
|
+
nac_id: id, reason: why,
|
|
5642
|
+
plugin: idIndex[id][0],
|
|
5643
|
+
hint: 'click() would reject this id with NacError(hidden). If the '
|
|
5644
|
+
+ 'surface is gated on purpose, declare undrivable_until with '
|
|
5645
|
+
+ 'the id that opens it',
|
|
5646
|
+
});
|
|
5647
|
+
}
|
|
5648
|
+
}
|
|
5649
|
+
}
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5652
|
+
|
|
4819
5653
|
/* v1.6.1: tolerated_violations support. Hosts retiring historic
|
|
4820
5654
|
findings incrementally can register a tolerated set via
|
|
4821
5655
|
NAC.set_validation_tolerance({tolerated:[...]}); each finding
|
|
@@ -4833,7 +5667,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4833
5667
|
const k = String(t.kind || '') + '::' + String(t.nac_id || '');
|
|
4834
5668
|
tolSet[k] = t.until || true;
|
|
4835
5669
|
});
|
|
4836
|
-
['duplicates', 'orphans', 'unmounted', '
|
|
5670
|
+
['duplicates', 'orphans', 'unmounted', 'ambiguous', 'unreachable',
|
|
5671
|
+
'convention_violations'].forEach(function (kind) {
|
|
4837
5672
|
const kept = [];
|
|
4838
5673
|
out[kind].forEach(function (item) {
|
|
4839
5674
|
const k = kind + '::' + item.nac_id;
|
|
@@ -4850,15 +5685,49 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4850
5685
|
});
|
|
4851
5686
|
}
|
|
4852
5687
|
|
|
4853
|
-
|
|
5688
|
+
/* 2.7.0: ambiguous joins duplicates in the hard-error gate. Both
|
|
5689
|
+
mean the same thing to an agent -- an id that does not resolve
|
|
5690
|
+
to one element -- and the bucket is empty unless the caller
|
|
5691
|
+
asked to probe, so a 2.5 caller sees the same booleans. */
|
|
5692
|
+
out.ok = !out.duplicates.length && !out.ambiguous.length;
|
|
4854
5693
|
/* v1.6.1: explicit has_errors flag for CI integration. Drift
|
|
4855
5694
|
findings (duplicates) are hard-errors per spec sec 7.3.2;
|
|
4856
5695
|
orphans + unmounted + convention_violations stay informative
|
|
4857
5696
|
unless the host explicitly opts in via tolerance config. */
|
|
4858
|
-
out.has_errors = out.duplicates.length > 0;
|
|
5697
|
+
out.has_errors = out.duplicates.length > 0 || out.ambiguous.length > 0;
|
|
4859
5698
|
return out;
|
|
4860
5699
|
}
|
|
4861
5700
|
|
|
5701
|
+
/* Why an element a manifest declares cannot be operated, or null.
|
|
5702
|
+
The three reasons are the ones click() itself refuses on, so the
|
|
5703
|
+
probe and the verb agree: a probe that reported something click()
|
|
5704
|
+
accepts, or missed something it rejects, would be worse than no
|
|
5705
|
+
probe. Everything is in a try: a host whose getComputedStyle
|
|
5706
|
+
throws gets a report without this bucket, not an exception out of
|
|
5707
|
+
a validator. */
|
|
5708
|
+
function _probeUnreachable(el) {
|
|
5709
|
+
if (!el) return null;
|
|
5710
|
+
try {
|
|
5711
|
+
if (el.closest && el.closest('[aria-hidden="true"]')) return 'aria_hidden';
|
|
5712
|
+
} catch (_) {}
|
|
5713
|
+
try {
|
|
5714
|
+
if (el.closest && el.closest('[inert]')) return 'inert_ancestor';
|
|
5715
|
+
} catch (_) {}
|
|
5716
|
+
try {
|
|
5717
|
+
const view = (el.ownerDocument && el.ownerDocument.defaultView)
|
|
5718
|
+
|| (typeof window !== 'undefined' ? window : null);
|
|
5719
|
+
if (view && typeof view.getComputedStyle === 'function') {
|
|
5720
|
+
const st = view.getComputedStyle(el);
|
|
5721
|
+
if (st) {
|
|
5722
|
+
if (st.display === 'none') return 'not_displayed';
|
|
5723
|
+
if (st.visibility === 'hidden') return 'not_displayed';
|
|
5724
|
+
if (String(st.opacity) === '0') return 'not_displayed';
|
|
5725
|
+
}
|
|
5726
|
+
}
|
|
5727
|
+
} catch (_) {}
|
|
5728
|
+
return null;
|
|
5729
|
+
}
|
|
5730
|
+
|
|
4862
5731
|
/* v1.6.1: tolerance config storage + setter. The shape:
|
|
4863
5732
|
{
|
|
4864
5733
|
tolerated: [
|
|
@@ -4889,14 +5758,51 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
4889
5758
|
are wrapped automatically when no resolver is set. */
|
|
4890
5759
|
const _optionResolvers = Object.create(null);
|
|
4891
5760
|
|
|
5761
|
+
/* The resolver key, which has to be INJECTIVE (TF-A05).
|
|
5762
|
+
|
|
5763
|
+
It used to be:
|
|
5764
|
+
|
|
5765
|
+
String(plugin || '') + '::' + String(field_id || '')
|
|
5766
|
+
|
|
5767
|
+
and that collided in two independent ways:
|
|
5768
|
+
|
|
5769
|
+
1. `String(x || '')` maps undefined, null, '', 0 and false all
|
|
5770
|
+
onto the empty string, so a resolver registered with no
|
|
5771
|
+
plugin and one registered with plugin '' were the same entry
|
|
5772
|
+
-- the second silently replaced the first.
|
|
5773
|
+
2. '::' as a separator with nothing escaping it: ('a::b', 'c')
|
|
5774
|
+
and ('a', 'b::c') both produce 'a::b::c'. SPEC.md does not
|
|
5775
|
+
restrict the characters of a field_id, so a '::' inside one
|
|
5776
|
+
is legal, and two different fields could share a resolver.
|
|
5777
|
+
|
|
5778
|
+
The length prefix makes the split unambiguous: knowing how long
|
|
5779
|
+
the plugin part is, there is exactly one way to read the key back.
|
|
5780
|
+
The separator stays for readability in a debugger, but nothing
|
|
5781
|
+
depends on it being unique any more. */
|
|
4892
5782
|
function _resolverKey(plugin, field_id) {
|
|
4893
|
-
|
|
5783
|
+
const p = plugin == null ? '' : String(plugin);
|
|
5784
|
+
const f = field_id == null ? '' : String(field_id);
|
|
5785
|
+
return p.length + ':' + p + '::' + f;
|
|
4894
5786
|
}
|
|
4895
5787
|
|
|
4896
5788
|
function set_options_resolver(plugin, field_id, fn) {
|
|
4897
5789
|
if (typeof fn !== 'function') {
|
|
4898
5790
|
throw NacError('invalid', 'resolver fn required');
|
|
4899
5791
|
}
|
|
5792
|
+
/* And refuse the empty case outright rather than keying on ''.
|
|
5793
|
+
A resolver with no plugin or no field is a programming error,
|
|
5794
|
+
and before this it was an error that looked like success until
|
|
5795
|
+
something else overwrote the entry. The sibling guard above
|
|
5796
|
+
already throws for a missing fn; this is the same shape. */
|
|
5797
|
+
if (plugin == null || String(plugin) === '') {
|
|
5798
|
+
throw NacError('invalid',
|
|
5799
|
+
'set_options_resolver: plugin is required -- a resolver with no plugin'
|
|
5800
|
+
+ ' used to be stored under the empty key, where the next one replaced it');
|
|
5801
|
+
}
|
|
5802
|
+
if (field_id == null || String(field_id) === '') {
|
|
5803
|
+
throw NacError('invalid',
|
|
5804
|
+
'set_options_resolver: field_id is required -- see the note on plugin');
|
|
5805
|
+
}
|
|
4900
5806
|
_optionResolvers[_resolverKey(plugin, field_id)] = fn;
|
|
4901
5807
|
}
|
|
4902
5808
|
|
|
@@ -5679,6 +6585,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5679
6585
|
function step_to(stepper_id, n) {
|
|
5680
6586
|
const steps = _stepperSteps(stepper_id);
|
|
5681
6587
|
if (!steps.length) throw NacError('stepper_not_found', stepper_id);
|
|
6588
|
+
/* n slots for n steps, 0..n-1: this SELECTS one of the steps that
|
|
6589
|
+
exist. Same limit as reorder(), which also moves within n.
|
|
6590
|
+
drag_drop() bounds to n instead, because inserting into a list
|
|
6591
|
+
of n has n + 1 slots (TF-A07). */
|
|
5682
6592
|
n = Math.max(0, Math.min(steps.length - 1, Number(n)));
|
|
5683
6593
|
const prior = step_state(stepper_id).current;
|
|
5684
6594
|
steps.forEach(function (s, i) {
|
|
@@ -6223,6 +7133,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6223
7133
|
var siblings = Array.prototype.slice.call(list.querySelectorAll(
|
|
6224
7134
|
'[data-nac-role="draggable"]'));
|
|
6225
7135
|
var from_index = siblings.indexOf(item);
|
|
7136
|
+
/* Bounded to siblings.length - 1, NOT siblings.length, and the
|
|
7137
|
+
difference from drag_drop() is deliberate (TF-A07): this MOVES
|
|
7138
|
+
an item that is already one of the n, so there are n landing
|
|
7139
|
+
slots, 0..n-1. drag_drop() INSERTS an item the list does not
|
|
7140
|
+
hold yet, so it has n + 1. step_to() selects one of n existing
|
|
7141
|
+
steps: n slots, like here.
|
|
7142
|
+
Three bounds, two limits, one reason -- written at all three
|
|
7143
|
+
sites because it was written at none, and a reader comparing
|
|
7144
|
+
them could not tell a deliberate asymmetry from a slip. */
|
|
6226
7145
|
var bounded = Math.max(0, Math.min(to_index, siblings.length - 1));
|
|
6227
7146
|
if (from_index === -1) {
|
|
6228
7147
|
return Promise.reject(new NacError('invalid',
|
|
@@ -6236,13 +7155,36 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6236
7155
|
list.insertBefore(item, ref);
|
|
6237
7156
|
}
|
|
6238
7157
|
}
|
|
7158
|
+
/* Say whether the index was ACOTADO (TF-A06).
|
|
7159
|
+
|
|
7160
|
+
The old pair was: emit to_index = bounded, resolve { ok: true }.
|
|
7161
|
+
So a consumer asking for index 99 in a list of three got
|
|
7162
|
+
ok: true and no index at all from the promise, and the event
|
|
7163
|
+
reported 2 with nothing marking it as clamped. "I moved it where
|
|
7164
|
+
you asked" and "I moved it as far as it would go" were
|
|
7165
|
+
indistinguishable -- for an agent deciding whether its plan
|
|
7166
|
+
worked, those are different answers.
|
|
7167
|
+
|
|
7168
|
+
requested_index and bounded are ADDITIVE: to_index still means
|
|
7169
|
+
what it meant, so nothing reading it breaks. */
|
|
7170
|
+
var wasBounded = bounded !== to_index;
|
|
6239
7171
|
_emit('nac:list:reordered', {
|
|
6240
|
-
list_id:
|
|
6241
|
-
item_id:
|
|
6242
|
-
from_index:
|
|
6243
|
-
to_index:
|
|
7172
|
+
list_id: list_id,
|
|
7173
|
+
item_id: item_id,
|
|
7174
|
+
from_index: from_index,
|
|
7175
|
+
to_index: bounded,
|
|
7176
|
+
requested_index: to_index,
|
|
7177
|
+
bounded: wasBounded,
|
|
7178
|
+
});
|
|
7179
|
+
return Promise.resolve({
|
|
7180
|
+
ok: true,
|
|
7181
|
+
list_id: list_id,
|
|
7182
|
+
item_id: item_id,
|
|
7183
|
+
from_index: from_index,
|
|
7184
|
+
to_index: bounded,
|
|
7185
|
+
requested_index: to_index,
|
|
7186
|
+
bounded: wasBounded,
|
|
6244
7187
|
});
|
|
6245
|
-
return Promise.resolve({ ok: true });
|
|
6246
7188
|
}
|
|
6247
7189
|
|
|
6248
7190
|
/* ---------- v1.6.2: drag_drop (implements spec sec 13.4) -------- */
|
|
@@ -6342,6 +7284,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6342
7284
|
|
|
6343
7285
|
source.setAttribute('data-nac-state', 'dragging');
|
|
6344
7286
|
/* v1.7.0: emit canonical source_id + legacy from_nac_id alias.
|
|
7287
|
+
The alias is frozen, not pending removal (D-12): the matcher
|
|
7288
|
+
resolves events by it.
|
|
6345
7289
|
Plugin scope from the source's data-nac-plugin ancestor so
|
|
6346
7290
|
sec 6.2.1 universal base (plugin + plugin_instance_id) is
|
|
6347
7291
|
satisfied. v1.7 round 3 conformance FAILed without these. */
|
|
@@ -6354,11 +7298,34 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6354
7298
|
};
|
|
6355
7299
|
_emit('nac:drag:started', Object.assign({}, dragPluginCtx, {
|
|
6356
7300
|
source_id: source_nac_id,
|
|
6357
|
-
from_nac_id: source_nac_id, /* legacy,
|
|
7301
|
+
from_nac_id: source_nac_id, /* legacy alias, frozen (D-12) */
|
|
6358
7302
|
}));
|
|
6359
7303
|
|
|
6360
|
-
/*
|
|
6361
|
-
|
|
7304
|
+
/* The settle delay, now the HOST's choice (TF-A02).
|
|
7305
|
+
|
|
7306
|
+
Why it exists: a focus pulse on the source is only visible to a
|
|
7307
|
+
human reviewer if the DOM move waits for it. The 80 ms was this
|
|
7308
|
+
repository's demo UX, hard-coded into the library -- so every
|
|
7309
|
+
adopter paid it, including the ones with no reviewer watching
|
|
7310
|
+
and the ones driving a thousand moves in a test.
|
|
7311
|
+
|
|
7312
|
+
The DEFAULT STAYS 80. Dropping it to zero would change the
|
|
7313
|
+
timing of every existing adopter's drop for the sake of
|
|
7314
|
+
tidiness, and a host that liked the pulse would lose it without
|
|
7315
|
+
asking. What changes is that it can now be set:
|
|
7316
|
+
|
|
7317
|
+
NAC.drag_drop(a, b, { settle_ms: 0 }) per call
|
|
7318
|
+
NAC.drag_settle_ms = 0 per host
|
|
7319
|
+
|
|
7320
|
+
opts wins over the global, and the global defaults to the
|
|
7321
|
+
historical 80. Zero is honoured -- `|| 80` would have silently
|
|
7322
|
+
turned the useful value back into the default, which is the
|
|
7323
|
+
usual way an option like this ends up not working. */
|
|
7324
|
+
var settleMs = (opts && typeof opts.settle_ms === 'number')
|
|
7325
|
+
? Math.max(0, opts.settle_ms)
|
|
7326
|
+
: ((global.NAC && typeof global.NAC.drag_settle_ms === 'number')
|
|
7327
|
+
? Math.max(0, global.NAC.drag_settle_ms)
|
|
7328
|
+
: 80);
|
|
6362
7329
|
return new Promise(function (resolve, reject) {
|
|
6363
7330
|
setTimeout(function () {
|
|
6364
7331
|
try {
|
|
@@ -6366,17 +7333,66 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6366
7333
|
_emit('nac:drag:over', Object.assign({}, dragPluginCtx, {
|
|
6367
7334
|
source_id: source_nac_id, /* v1.7.0 canonical */
|
|
6368
7335
|
target_id: target_nac_id, /* v1.7.0 canonical */
|
|
6369
|
-
from_nac_id: source_nac_id, /* legacy,
|
|
6370
|
-
over_nac_id: target_nac_id, /* legacy,
|
|
7336
|
+
from_nac_id: source_nac_id, /* legacy, frozen D-12 */
|
|
7337
|
+
over_nac_id: target_nac_id, /* legacy, frozen D-12 */
|
|
6371
7338
|
}));
|
|
6372
|
-
/* Remove
|
|
6373
|
-
|
|
6374
|
-
|
|
7339
|
+
/* Remove a "drop here" placeholder, IF THE HOST DECLARED ONE.
|
|
7340
|
+
|
|
7341
|
+
TF-A01. Until 2.7.0 this line was:
|
|
7342
|
+
|
|
7343
|
+
var empty = target.querySelector('.ne-drag-empty');
|
|
7344
|
+
if (empty) empty.parentNode.removeChild(empty);
|
|
7345
|
+
|
|
7346
|
+
-- the runtime deleting a node out of the host's document
|
|
7347
|
+
because of a CSS class name that belongs to THIS
|
|
7348
|
+
repository's demo (css/example.css, js/example.js). The
|
|
7349
|
+
class is real here; what was never real is the agreement.
|
|
7350
|
+
Nothing obliges an adopter to avoid `ne-drag-empty`, and
|
|
7351
|
+
an adopter who happens to use it for anything else lost
|
|
7352
|
+
the element on the first drop, silently, with no way to
|
|
7353
|
+
switch it off.
|
|
7354
|
+
|
|
7355
|
+
A library may not reach into a document it did not write
|
|
7356
|
+
on a convention it invented. So the default is now to
|
|
7357
|
+
remove NOTHING, and a host that wants placeholder removal
|
|
7358
|
+
asks for it, in the idiom the rest of the protocol uses --
|
|
7359
|
+
an attribute on the element that owns the contract:
|
|
7360
|
+
|
|
7361
|
+
<ul data-nac-role="drop-target"
|
|
7362
|
+
data-nac-drop-placeholder=".ne-drag-empty">
|
|
7363
|
+
|
|
7364
|
+
NAC.drop_placeholder_selector is the tree-wide default for
|
|
7365
|
+
a host that wants it everywhere; it is null, and the
|
|
7366
|
+
per-target attribute wins over it. The selector is only
|
|
7367
|
+
ever queried INSIDE the target, so a host cannot be made
|
|
7368
|
+
to delete something elsewhere in its page by accident. */
|
|
7369
|
+
var placeholderSel = target.getAttribute('data-nac-drop-placeholder')
|
|
7370
|
+
|| (global.NAC && global.NAC.drop_placeholder_selector) || null;
|
|
7371
|
+
if (placeholderSel) {
|
|
7372
|
+
var stale = target.querySelectorAll(placeholderSel);
|
|
7373
|
+
for (var pi = 0; pi < stale.length; pi++) {
|
|
7374
|
+
if (stale[pi].parentNode) stale[pi].parentNode.removeChild(stale[pi]);
|
|
7375
|
+
}
|
|
7376
|
+
}
|
|
6375
7377
|
/* Optional to_index for ordered drop-targets; otherwise
|
|
6376
7378
|
append at end. */
|
|
6377
7379
|
if (typeof opts.to_index === 'number') {
|
|
6378
7380
|
var siblings = Array.prototype.slice.call(
|
|
6379
7381
|
target.querySelectorAll('[data-nac-role="draggable"]'));
|
|
7382
|
+
/* Bounded to siblings.length, NOT siblings.length - 1, and
|
|
7383
|
+
the difference from reorder() is deliberate (TF-A07).
|
|
7384
|
+
|
|
7385
|
+
This is an INSERT into a list the item is not in yet, so
|
|
7386
|
+
a list of n items has n + 1 landing slots: before each
|
|
7387
|
+
of the n, plus after the last. reorder() MOVES an item
|
|
7388
|
+
that is already among the n, so it has n slots, and
|
|
7389
|
+
bounds to n - 1. step_to() selects one of n existing
|
|
7390
|
+
steps: also n - 1.
|
|
7391
|
+
|
|
7392
|
+
Three bounds, two limits, one reason -- written down
|
|
7393
|
+
here because it was not, and a reader comparing the
|
|
7394
|
+
three had no way to tell a deliberate asymmetry from a
|
|
7395
|
+
copy-paste slip. */
|
|
6380
7396
|
var bounded = Math.max(0, Math.min(opts.to_index, siblings.length));
|
|
6381
7397
|
var ref = siblings[bounded] || null;
|
|
6382
7398
|
if (ref) target.insertBefore(source, ref);
|
|
@@ -6389,8 +7405,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6389
7405
|
_emit('nac:drag:dropped', Object.assign({}, dragPluginCtx, {
|
|
6390
7406
|
source_id: source_nac_id, /* v1.7.0 canonical */
|
|
6391
7407
|
target_id: target_nac_id, /* v1.7.0 canonical */
|
|
6392
|
-
from_nac_id: source_nac_id, /* legacy,
|
|
6393
|
-
target_nac_id: target_nac_id, /* legacy,
|
|
7408
|
+
from_nac_id: source_nac_id, /* legacy, frozen D-12 */
|
|
7409
|
+
target_nac_id: target_nac_id, /* legacy, frozen D-12 */
|
|
6394
7410
|
value: opts.value !== undefined ? opts.value : null,
|
|
6395
7411
|
}));
|
|
6396
7412
|
resolve({ ok: true, source: source_nac_id, target: target_nac_id });
|
|
@@ -6399,7 +7415,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6399
7415
|
target.setAttribute('data-nac-state', 'idle');
|
|
6400
7416
|
_emit('nac:drag:cancelled', Object.assign({}, dragPluginCtx, {
|
|
6401
7417
|
source_id: source_nac_id, /* v1.7.0 canonical */
|
|
6402
|
-
from_nac_id: source_nac_id, /* legacy,
|
|
7418
|
+
from_nac_id: source_nac_id, /* legacy, frozen D-12 */
|
|
6403
7419
|
reason: 'aborted',
|
|
6404
7420
|
error: err && err.message ? err.message : String(err),
|
|
6405
7421
|
}));
|
|
@@ -6417,7 +7433,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6417
7433
|
reject(err instanceof Error ? err :
|
|
6418
7434
|
new NacError('invalid', String(err)));
|
|
6419
7435
|
}
|
|
6420
|
-
},
|
|
7436
|
+
}, settleMs);
|
|
6421
7437
|
});
|
|
6422
7438
|
}
|
|
6423
7439
|
|
|
@@ -6871,6 +7887,413 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6871
7887
|
return hex;
|
|
6872
7888
|
}
|
|
6873
7889
|
|
|
7890
|
+
/* ---------- 2.7.0: manifest authenticity (sec 7.2) ------------
|
|
7891
|
+
|
|
7892
|
+
WHAT THIS CLOSES. Section 7.2 has published, since 1.9, a worked
|
|
7893
|
+
example of an HMAC-signed manifest: set the tenant secret, pass a
|
|
7894
|
+
provenance block to register(), and "the runtime computes the
|
|
7895
|
+
expected HMAC over a stable serialisation of the manifest
|
|
7896
|
+
(excluding the signature itself) and rejects manifests whose
|
|
7897
|
+
signature does not match". None of that existed. sign_provenance /
|
|
7898
|
+
verify_provenance (above) sign an EVENT's detail.source and have
|
|
7899
|
+
never looked at a manifest, and register() stored whatever object
|
|
7900
|
+
it was handed. So conformance level 3 -- whose first requirement
|
|
7901
|
+
is "carries HMAC-signed manifests" -- could not be asserted by any
|
|
7902
|
+
tool, which is the measured finding audit N-36 / PND-045 records
|
|
7903
|
+
and what scripts/contract-api.meta.json says in the note on that
|
|
7904
|
+
requirement: "the runtime exposes no manifest verification at all
|
|
7905
|
+
... which is why no tool can assert level 3 today".
|
|
7906
|
+
|
|
7907
|
+
WHY A HAND-WRITTEN SHA-256 AND NOT SubtleCrypto. Because
|
|
7908
|
+
register() is SYNCHRONOUS and throws -- that is its whole
|
|
7909
|
+
contract, and STRICT_VALIDATION made it a hard gate in 2.3.
|
|
7910
|
+
crypto.subtle.sign returns a Promise, so a register() built on it
|
|
7911
|
+
could only verify AFTER returning: the manifest would already be
|
|
7912
|
+
live, the host would already have gone on to click things, and the
|
|
7913
|
+
rejection would arrive as a console message in a later tick. That
|
|
7914
|
+
is silent damage with extra steps. A synchronous digest is ~70
|
|
7915
|
+
lines, has fixed test vectors anybody can check (FIPS 180-4 for
|
|
7916
|
+
the digest, RFC 4231 for the HMAC -- both are in
|
|
7917
|
+
runtime/test/manifest-hmac.mjs), needs no DOM, no network and no
|
|
7918
|
+
Node built-in, and lets the signature be refused at the only
|
|
7919
|
+
moment where refusing costs nothing.
|
|
7920
|
+
|
|
7921
|
+
WHAT IT DOES NOT DO, said plainly: it does not make a manifest
|
|
7922
|
+
trustworthy. The secret lives in the page, so an agent with
|
|
7923
|
+
user-level access reads it (sec 7.3 says exactly this). What it
|
|
7924
|
+
buys is the multi-tenant case 7.2 names -- tenant A cannot hand
|
|
7925
|
+
tenant B's host a manifest it did not sign -- and an answer to
|
|
7926
|
+
"can anything here say it verified this?" that is not "no". */
|
|
7927
|
+
|
|
7928
|
+
const _SHA256_K = [
|
|
7929
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
7930
|
+
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
7931
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
7932
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
7933
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
7934
|
+
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
7935
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
7936
|
+
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
7937
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
7938
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
7939
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
7940
|
+
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
7941
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
7942
|
+
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
7943
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
7944
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
7945
|
+
];
|
|
7946
|
+
|
|
7947
|
+
function _rotr32(x, n) { return ((x >>> n) | (x << (32 - n))) >>> 0; }
|
|
7948
|
+
|
|
7949
|
+
/* UTF-8 bytes without TextEncoder, so the digest works in any host
|
|
7950
|
+
that can run the rest of this file (old WebViews included). */
|
|
7951
|
+
function _utf8Bytes(str) {
|
|
7952
|
+
str = String(str);
|
|
7953
|
+
if (typeof TextEncoder !== 'undefined') {
|
|
7954
|
+
return new TextEncoder().encode(str);
|
|
7955
|
+
}
|
|
7956
|
+
const out = [];
|
|
7957
|
+
for (let i = 0; i < str.length; i++) {
|
|
7958
|
+
let c = str.charCodeAt(i);
|
|
7959
|
+
if (c < 0x80) { out.push(c); continue; }
|
|
7960
|
+
if (c < 0x800) {
|
|
7961
|
+
out.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
|
|
7962
|
+
continue;
|
|
7963
|
+
}
|
|
7964
|
+
if (c >= 0xd800 && c <= 0xdbff && i + 1 < str.length) {
|
|
7965
|
+
const lo = str.charCodeAt(i + 1);
|
|
7966
|
+
if (lo >= 0xdc00 && lo <= 0xdfff) {
|
|
7967
|
+
c = 0x10000 + ((c - 0xd800) << 10) + (lo - 0xdc00);
|
|
7968
|
+
i++;
|
|
7969
|
+
out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 0x3f),
|
|
7970
|
+
0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
|
|
7971
|
+
continue;
|
|
7972
|
+
}
|
|
7973
|
+
}
|
|
7974
|
+
out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f),
|
|
7975
|
+
0x80 | (c & 0x3f));
|
|
7976
|
+
}
|
|
7977
|
+
return new Uint8Array(out);
|
|
7978
|
+
}
|
|
7979
|
+
|
|
7980
|
+
/* SHA-256 over bytes -> Uint8Array(32). FIPS 180-4. */
|
|
7981
|
+
function _sha256Bytes(bytes) {
|
|
7982
|
+
const H = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
7983
|
+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
|
|
7984
|
+
const len = bytes.length;
|
|
7985
|
+
const padded = new Uint8Array((Math.floor((len + 8) / 64) + 1) * 64);
|
|
7986
|
+
padded.set(bytes);
|
|
7987
|
+
padded[len] = 0x80;
|
|
7988
|
+
const n = padded.length;
|
|
7989
|
+
const hiBits = Math.floor(len / 536870912); /* (len * 8) >> 32 */
|
|
7990
|
+
const loBits = (len * 8) >>> 0;
|
|
7991
|
+
padded[n - 8] = (hiBits >>> 24) & 0xff;
|
|
7992
|
+
padded[n - 7] = (hiBits >>> 16) & 0xff;
|
|
7993
|
+
padded[n - 6] = (hiBits >>> 8) & 0xff;
|
|
7994
|
+
padded[n - 5] = hiBits & 0xff;
|
|
7995
|
+
padded[n - 4] = (loBits >>> 24) & 0xff;
|
|
7996
|
+
padded[n - 3] = (loBits >>> 16) & 0xff;
|
|
7997
|
+
padded[n - 2] = (loBits >>> 8) & 0xff;
|
|
7998
|
+
padded[n - 1] = loBits & 0xff;
|
|
7999
|
+
const w = new Array(64);
|
|
8000
|
+
for (let off = 0; off < n; off += 64) {
|
|
8001
|
+
for (let i = 0; i < 16; i++) {
|
|
8002
|
+
const j = off + i * 4;
|
|
8003
|
+
w[i] = ((padded[j] << 24) | (padded[j + 1] << 16)
|
|
8004
|
+
| (padded[j + 2] << 8) | padded[j + 3]) >>> 0;
|
|
8005
|
+
}
|
|
8006
|
+
for (let i = 16; i < 64; i++) {
|
|
8007
|
+
const x = w[i - 15], y = w[i - 2];
|
|
8008
|
+
const s0 = (_rotr32(x, 7) ^ _rotr32(x, 18) ^ (x >>> 3)) >>> 0;
|
|
8009
|
+
const s1 = (_rotr32(y, 17) ^ _rotr32(y, 19) ^ (y >>> 10)) >>> 0;
|
|
8010
|
+
w[i] = (((w[i - 16] + s0) >>> 0) + ((w[i - 7] + s1) >>> 0)) >>> 0;
|
|
8011
|
+
}
|
|
8012
|
+
let a = H[0], b = H[1], c = H[2], d = H[3];
|
|
8013
|
+
let e = H[4], f = H[5], g = H[6], h = H[7];
|
|
8014
|
+
for (let i = 0; i < 64; i++) {
|
|
8015
|
+
const S1 = (_rotr32(e, 6) ^ _rotr32(e, 11) ^ _rotr32(e, 25)) >>> 0;
|
|
8016
|
+
const ch = ((e & f) ^ (~e & g)) >>> 0;
|
|
8017
|
+
const t1 = (((h + S1) >>> 0) + ((ch + _SHA256_K[i]) >>> 0)
|
|
8018
|
+
+ w[i]) >>> 0;
|
|
8019
|
+
const S0 = (_rotr32(a, 2) ^ _rotr32(a, 13) ^ _rotr32(a, 22)) >>> 0;
|
|
8020
|
+
const maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0;
|
|
8021
|
+
const t2 = (S0 + maj) >>> 0;
|
|
8022
|
+
h = g; g = f; f = e; e = (d + t1) >>> 0;
|
|
8023
|
+
d = c; c = b; b = a; a = (t1 + t2) >>> 0;
|
|
8024
|
+
}
|
|
8025
|
+
H[0] = (H[0] + a) >>> 0; H[1] = (H[1] + b) >>> 0;
|
|
8026
|
+
H[2] = (H[2] + c) >>> 0; H[3] = (H[3] + d) >>> 0;
|
|
8027
|
+
H[4] = (H[4] + e) >>> 0; H[5] = (H[5] + f) >>> 0;
|
|
8028
|
+
H[6] = (H[6] + g) >>> 0; H[7] = (H[7] + h) >>> 0;
|
|
8029
|
+
}
|
|
8030
|
+
const out = new Uint8Array(32);
|
|
8031
|
+
for (let i = 0; i < 8; i++) {
|
|
8032
|
+
out[i * 4] = (H[i] >>> 24) & 0xff;
|
|
8033
|
+
out[i * 4 + 1] = (H[i] >>> 16) & 0xff;
|
|
8034
|
+
out[i * 4 + 2] = (H[i] >>> 8) & 0xff;
|
|
8035
|
+
out[i * 4 + 3] = H[i] & 0xff;
|
|
8036
|
+
}
|
|
8037
|
+
return out;
|
|
8038
|
+
}
|
|
8039
|
+
|
|
8040
|
+
function _bytesToHex(arr) {
|
|
8041
|
+
let hex = '';
|
|
8042
|
+
for (let i = 0; i < arr.length; i++) {
|
|
8043
|
+
const b = arr[i].toString(16);
|
|
8044
|
+
hex += b.length === 1 ? '0' + b : b;
|
|
8045
|
+
}
|
|
8046
|
+
return hex;
|
|
8047
|
+
}
|
|
8048
|
+
|
|
8049
|
+
/* HMAC-SHA256, synchronous. RFC 2104 / tested against RFC 4231. */
|
|
8050
|
+
function _hmacSha256Hex(secret, message) {
|
|
8051
|
+
const BLOCK = 64;
|
|
8052
|
+
let key = _utf8Bytes(secret);
|
|
8053
|
+
if (key.length > BLOCK) key = _sha256Bytes(key);
|
|
8054
|
+
const k0 = new Uint8Array(BLOCK);
|
|
8055
|
+
k0.set(key);
|
|
8056
|
+
const msg = _utf8Bytes(message);
|
|
8057
|
+
const inner = new Uint8Array(BLOCK + msg.length);
|
|
8058
|
+
const outer = new Uint8Array(BLOCK + 32);
|
|
8059
|
+
for (let i = 0; i < BLOCK; i++) {
|
|
8060
|
+
inner[i] = k0[i] ^ 0x36;
|
|
8061
|
+
outer[i] = k0[i] ^ 0x5c;
|
|
8062
|
+
}
|
|
8063
|
+
inner.set(msg, BLOCK);
|
|
8064
|
+
outer.set(_sha256Bytes(inner), BLOCK);
|
|
8065
|
+
return _bytesToHex(_sha256Bytes(outer));
|
|
8066
|
+
}
|
|
8067
|
+
|
|
8068
|
+
/* Stable serialisation: keys sorted at every depth, undefined
|
|
8069
|
+
dropped, so two hosts that build the same manifest in a different
|
|
8070
|
+
key order sign the same bytes. */
|
|
8071
|
+
function _stableStringify(v) {
|
|
8072
|
+
if (v === undefined) return 'null';
|
|
8073
|
+
if (v === null || typeof v !== 'object') return JSON.stringify(v);
|
|
8074
|
+
if (Array.isArray(v)) {
|
|
8075
|
+
const items = [];
|
|
8076
|
+
for (let i = 0; i < v.length; i++) items.push(_stableStringify(v[i]));
|
|
8077
|
+
return '[' + items.join(',') + ']';
|
|
8078
|
+
}
|
|
8079
|
+
const keys = Object.keys(v).filter(function (k) {
|
|
8080
|
+
return v[k] !== undefined && typeof v[k] !== 'function';
|
|
8081
|
+
}).sort();
|
|
8082
|
+
const parts = keys.map(function (k) {
|
|
8083
|
+
return JSON.stringify(k) + ':' + _stableStringify(v[k]);
|
|
8084
|
+
});
|
|
8085
|
+
return '{' + parts.join(',') + '}';
|
|
8086
|
+
}
|
|
8087
|
+
|
|
8088
|
+
/* The signed body: the whole manifest, with provenance.signature
|
|
8089
|
+
removed and everything else of the provenance block KEPT -- the
|
|
8090
|
+
signature covers signed_at and signed_by, so a replay cannot
|
|
8091
|
+
relabel who signed it or when. */
|
|
8092
|
+
function _manifestCanonicalString(m) {
|
|
8093
|
+
const clone = {};
|
|
8094
|
+
Object.keys(m).forEach(function (k) {
|
|
8095
|
+
if (k === 'provenance') return;
|
|
8096
|
+
clone[k] = m[k];
|
|
8097
|
+
});
|
|
8098
|
+
if (m.provenance && typeof m.provenance === 'object') {
|
|
8099
|
+
const p = {};
|
|
8100
|
+
Object.keys(m.provenance).forEach(function (k) {
|
|
8101
|
+
if (k === 'signature') return;
|
|
8102
|
+
p[k] = m.provenance[k];
|
|
8103
|
+
});
|
|
8104
|
+
clone.provenance = p;
|
|
8105
|
+
}
|
|
8106
|
+
return _stableStringify(clone);
|
|
8107
|
+
}
|
|
8108
|
+
|
|
8109
|
+
/* Tenant secrets for MANIFEST verification. Separate store from the
|
|
8110
|
+
extensions module's event-provenance secrets, and deliberately so:
|
|
8111
|
+
register() lives in this file and cannot reach into that closure.
|
|
8112
|
+
NAC.set_provenance_secret (extensions) FORWARDS here, so the
|
|
8113
|
+
example published in section 7.2 works exactly as written. */
|
|
8114
|
+
let _manifestSecrets = [];
|
|
8115
|
+
|
|
8116
|
+
function set_manifest_secret(s) {
|
|
8117
|
+
if (typeof s === 'string') _manifestSecrets = [s];
|
|
8118
|
+
else if (Array.isArray(s)) _manifestSecrets = s.slice();
|
|
8119
|
+
else if (s == null) _manifestSecrets = [];
|
|
8120
|
+
else {
|
|
8121
|
+
throw NacError('invalid',
|
|
8122
|
+
'NAC.set_manifest_secret expects a string, an array of strings, or null');
|
|
8123
|
+
}
|
|
8124
|
+
return _manifestSecrets.length;
|
|
8125
|
+
}
|
|
8126
|
+
|
|
8127
|
+
/* NAC.sign_manifest(manifest, secret?) -> hex signature.
|
|
8128
|
+
Sign the object you are about to hand to register(): the digest
|
|
8129
|
+
covers it as you built it, BEFORE register() fills in its
|
|
8130
|
+
defaults (version, nac_version, plugin_slug from the two-argument
|
|
8131
|
+
form), which is why register() takes its snapshot first. */
|
|
8132
|
+
function sign_manifest(manifest, secret) {
|
|
8133
|
+
if (!manifest || typeof manifest !== 'object') {
|
|
8134
|
+
throw NacError('invalid', 'NAC.sign_manifest: manifest object required');
|
|
8135
|
+
}
|
|
8136
|
+
const key = (secret != null) ? secret : _manifestSecrets[0];
|
|
8137
|
+
if (typeof key !== 'string' || !key) {
|
|
8138
|
+
throw NacError('invalid',
|
|
8139
|
+
'NAC.sign_manifest: no secret. Pass one, or call NAC.set_manifest_secret first');
|
|
8140
|
+
}
|
|
8141
|
+
return _hmacSha256Hex(key, _manifestCanonicalString(manifest));
|
|
8142
|
+
}
|
|
8143
|
+
|
|
8144
|
+
/* NAC.verify_manifest(manifest, secret?) -> boolean.
|
|
8145
|
+
Constant-time compare against every registered secret, so a
|
|
8146
|
+
tenant rotating a secret can hold both for the window. */
|
|
8147
|
+
function verify_manifest(manifest, secret) {
|
|
8148
|
+
if (!manifest || typeof manifest !== 'object') return false;
|
|
8149
|
+
const prov = manifest.provenance;
|
|
8150
|
+
if (!prov || typeof prov !== 'object' || !prov.signature) return false;
|
|
8151
|
+
const keys = (secret != null) ? [secret] : _manifestSecrets;
|
|
8152
|
+
if (!keys.length) return false;
|
|
8153
|
+
const body = _manifestCanonicalString(manifest);
|
|
8154
|
+
const provided = String(prov.signature);
|
|
8155
|
+
let any = false;
|
|
8156
|
+
for (let i = 0; i < keys.length; i++) {
|
|
8157
|
+
if (typeof keys[i] !== 'string' || !keys[i]) continue;
|
|
8158
|
+
const expected = _hmacSha256Hex(keys[i], body);
|
|
8159
|
+
if (provided.length !== expected.length) continue;
|
|
8160
|
+
let diff = 0;
|
|
8161
|
+
for (let j = 0; j < provided.length; j++) {
|
|
8162
|
+
diff |= provided.charCodeAt(j) ^ expected.charCodeAt(j);
|
|
8163
|
+
}
|
|
8164
|
+
if (diff === 0) any = true;
|
|
8165
|
+
}
|
|
8166
|
+
return any;
|
|
8167
|
+
}
|
|
8168
|
+
|
|
8169
|
+
/* What register() recorded about each manifest's provenance, so a
|
|
8170
|
+
validator on the page can ask instead of guessing. Shape:
|
|
8171
|
+
{ signed, verified, reason, signed_by, signed_at }
|
|
8172
|
+
verified is true / false / null, and null is not a synonym for
|
|
8173
|
+
false: it means NOBODY COULD TELL (no secret registered). A tool
|
|
8174
|
+
that reports level 3 off this MUST treat null as unverified. */
|
|
8175
|
+
const _manifestProvenance = Object.create(null);
|
|
8176
|
+
|
|
8177
|
+
function manifest_provenance(slug) {
|
|
8178
|
+
if (slug === undefined) {
|
|
8179
|
+
const out = {};
|
|
8180
|
+
Object.keys(_manifestProvenance).forEach(function (k) {
|
|
8181
|
+
out[k] = Object.assign({}, _manifestProvenance[k]);
|
|
8182
|
+
});
|
|
8183
|
+
return out;
|
|
8184
|
+
}
|
|
8185
|
+
const rec = _manifestProvenance[String(slug)];
|
|
8186
|
+
return rec ? Object.assign({}, rec) : null;
|
|
8187
|
+
}
|
|
8188
|
+
|
|
8189
|
+
/* Called from register() with the canonical string captured BEFORE
|
|
8190
|
+
any default was applied. Throws when a signature is present and a
|
|
8191
|
+
secret says it is wrong; stays silent when there is no signature
|
|
8192
|
+
(section 7.2: a manifest MAY carry a provenance block) or no
|
|
8193
|
+
secret (nothing to check against, and an adopter who never set
|
|
8194
|
+
one must keep working exactly as before). */
|
|
8195
|
+
function _recordManifestProvenance(slug, manifest, canonical) {
|
|
8196
|
+
const prov = manifest && manifest.provenance;
|
|
8197
|
+
if (!prov || typeof prov !== 'object' || !prov.signature) {
|
|
8198
|
+
_manifestProvenance[slug] = {
|
|
8199
|
+
signed: false, verified: null, reason: 'no_provenance_block',
|
|
8200
|
+
signed_by: (prov && prov.signed_by) || null,
|
|
8201
|
+
signed_at: (prov && prov.signed_at) || null,
|
|
8202
|
+
};
|
|
8203
|
+
return;
|
|
8204
|
+
}
|
|
8205
|
+
if (!_manifestSecrets.length) {
|
|
8206
|
+
_manifestProvenance[slug] = {
|
|
8207
|
+
signed: true, verified: null, reason: 'no_secret_registered',
|
|
8208
|
+
signed_by: prov.signed_by || null,
|
|
8209
|
+
signed_at: prov.signed_at || null,
|
|
8210
|
+
};
|
|
8211
|
+
return;
|
|
8212
|
+
}
|
|
8213
|
+
const provided = String(prov.signature);
|
|
8214
|
+
let ok = false;
|
|
8215
|
+
for (let i = 0; i < _manifestSecrets.length; i++) {
|
|
8216
|
+
const key = _manifestSecrets[i];
|
|
8217
|
+
if (typeof key !== 'string' || !key) continue;
|
|
8218
|
+
const expected = _hmacSha256Hex(key, canonical);
|
|
8219
|
+
if (provided.length !== expected.length) continue;
|
|
8220
|
+
let diff = 0;
|
|
8221
|
+
for (let j = 0; j < provided.length; j++) {
|
|
8222
|
+
diff |= provided.charCodeAt(j) ^ expected.charCodeAt(j);
|
|
8223
|
+
}
|
|
8224
|
+
if (diff === 0) ok = true;
|
|
8225
|
+
}
|
|
8226
|
+
if (!ok) {
|
|
8227
|
+
delete _manifestProvenance[slug];
|
|
8228
|
+
throw NacError('invalid',
|
|
8229
|
+
'manifest "' + slug + '" carries a provenance.signature that does not '
|
|
8230
|
+
+ 'match the HMAC of its body under any registered tenant secret '
|
|
8231
|
+
+ '(SPEC.md sec 7.2). Either the manifest was altered after signing, '
|
|
8232
|
+
+ 'or it was signed for another tenant.');
|
|
8233
|
+
}
|
|
8234
|
+
_manifestProvenance[slug] = {
|
|
8235
|
+
signed: true, verified: true, reason: 'verified',
|
|
8236
|
+
signed_by: prov.signed_by || null,
|
|
8237
|
+
signed_at: prov.signed_at || null,
|
|
8238
|
+
};
|
|
8239
|
+
}
|
|
8240
|
+
|
|
8241
|
+
/* ---------- 2.7.0: NAC.set_source (sec 15.7) ------------------
|
|
8242
|
+
|
|
8243
|
+
Section 15.7 has published, since 2.5, that source on
|
|
8244
|
+
nac:plugin:invoked / :read / :event "defaults to 'agent'; hosts
|
|
8245
|
+
that wrap the runtime in a user-facing UI MAY override via the
|
|
8246
|
+
existing NAC.set_source(...) mechanism (sec 7)". The mechanism
|
|
8247
|
+
was not existing: there were zero occurrences of set_source in
|
|
8248
|
+
js/, so every dispatch from a host where a HUMAN pressed the
|
|
8249
|
+
button was sealed source:'agent', trusted:false, and an auditor
|
|
8250
|
+
reading the log could not tell the two apart (D-09).
|
|
8251
|
+
|
|
8252
|
+
It is an ATTESTATION BY THE HOST, not a measurement, and the
|
|
8253
|
+
threat model (7.3) already says an agent with user-level access
|
|
8254
|
+
can do anything the user can -- including calling this. What it
|
|
8255
|
+
buys is the honest case: a host with a confirmation UI in front
|
|
8256
|
+
of the dispatch can say so, and every change of the claim emits
|
|
8257
|
+
nac:source_changed so the override is itself in the log. */
|
|
8258
|
+
|
|
8259
|
+
let _dispatchSource = { source: 'agent', trusted: false };
|
|
8260
|
+
|
|
8261
|
+
function set_source(src) {
|
|
8262
|
+
let next;
|
|
8263
|
+
if (src == null) {
|
|
8264
|
+
next = { source: 'agent', trusted: false };
|
|
8265
|
+
} else if (typeof src === 'string') {
|
|
8266
|
+
if (!src.trim()) {
|
|
8267
|
+
throw NacError('invalid', 'NAC.set_source: source string must not be empty');
|
|
8268
|
+
}
|
|
8269
|
+
next = { source: src, trusted: false };
|
|
8270
|
+
} else if (typeof src === 'object') {
|
|
8271
|
+
const label = src.source !== undefined ? src.source : src.type;
|
|
8272
|
+
if (typeof label !== 'string' || !label.trim()) {
|
|
8273
|
+
throw NacError('invalid',
|
|
8274
|
+
'NAC.set_source: {source} must be a non-empty string');
|
|
8275
|
+
}
|
|
8276
|
+
next = { source: label, trusted: !!src.trusted };
|
|
8277
|
+
} else {
|
|
8278
|
+
throw NacError('invalid',
|
|
8279
|
+
'NAC.set_source expects a string, {source, trusted}, or null to reset');
|
|
8280
|
+
}
|
|
8281
|
+
const prev = _dispatchSource;
|
|
8282
|
+
_dispatchSource = next;
|
|
8283
|
+
try {
|
|
8284
|
+
document.dispatchEvent(new CustomEvent('nac:source_changed', {
|
|
8285
|
+
detail: {
|
|
8286
|
+
source: next.source, trusted: next.trusted,
|
|
8287
|
+
previous_source: prev.source, previous_trusted: prev.trusted,
|
|
8288
|
+
},
|
|
8289
|
+
bubbles: true, composed: true,
|
|
8290
|
+
}));
|
|
8291
|
+
} catch (_) { /* no document: the setter still took effect */ }
|
|
8292
|
+
return Object.assign({}, next);
|
|
8293
|
+
}
|
|
8294
|
+
|
|
8295
|
+
function get_source() { return Object.assign({}, _dispatchSource); }
|
|
8296
|
+
|
|
6874
8297
|
/* ---------- v1.9.0: recommended_remediation (sec 6.2.30) ----- */
|
|
6875
8298
|
|
|
6876
8299
|
const _REMEDIATION_BY_REASON = {
|
|
@@ -6931,8 +8354,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6931
8354
|
|
|
6932
8355
|
const _v25_plugins = Object.create(null);
|
|
6933
8356
|
|
|
6934
|
-
/* The
|
|
6935
|
-
manifest is a hard reject at register time.
|
|
8357
|
+
/* The 9 backend names from SPEC.md sec 15.4. Any other name in a
|
|
8358
|
+
manifest is a hard reject at register time. `emitter-listen` is
|
|
8359
|
+
the v2.6 addition (RFC V26-01 hook E-3): the only real event
|
|
8360
|
+
source before it was postMessage, so a plugin wrapping a library
|
|
8361
|
+
that emits its own events (map.on('moveend'),
|
|
8362
|
+
video.addEventListener('timeupdate'), pdf.js 'pagechanging')
|
|
8363
|
+
had to fall back to polling or to a hand-written mirror node. */
|
|
6936
8364
|
const _V25_VALID_BACKENDS = {
|
|
6937
8365
|
'postmessage': true,
|
|
6938
8366
|
'postmessage-listen': true,
|
|
@@ -6942,7 +8370,133 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
6942
8370
|
'same-origin-window': true,
|
|
6943
8371
|
'synthetic-mutation': true,
|
|
6944
8372
|
'synthetic-poll': true,
|
|
8373
|
+
'emitter-listen': true,
|
|
8374
|
+
};
|
|
8375
|
+
|
|
8376
|
+
/* 2.7.0 (SPEC sec 19.1) -- which of those nine backends reach their
|
|
8377
|
+
surface WITHOUT a document. This is the whole predicate of the
|
|
8378
|
+
headless profile, and it is a property of the implementation, not
|
|
8379
|
+
an opinion: sdk-call walks a registered API handle or the global
|
|
8380
|
+
object, and emitter-listen subscribes to a library's own emitter.
|
|
8381
|
+
Neither ever calls document.querySelector. The other six do, which
|
|
8382
|
+
is why they are absent from this table.
|
|
8383
|
+
|
|
8384
|
+
'inherits' means the binding is DOM-free exactly when every state
|
|
8385
|
+
path it observes is: synthetic-poll only calls read() on the state
|
|
8386
|
+
paths it declares. */
|
|
8387
|
+
const _V25_DOM_FREE_BACKENDS = {
|
|
8388
|
+
'sdk-call': true,
|
|
8389
|
+
'emitter-listen': true,
|
|
8390
|
+
'synthetic-poll': 'inherits',
|
|
8391
|
+
};
|
|
8392
|
+
|
|
8393
|
+
/* Why each DOM-requiring backend needs one -- named, so the refusal a
|
|
8394
|
+
declared-headless manifest gets says what to change (sec 19.1). */
|
|
8395
|
+
const _V25_DOM_REASON = {
|
|
8396
|
+
'postmessage': 'posts to the contentWindow of an iframe matched by a CSS selector',
|
|
8397
|
+
'postmessage-listen': 'filters window.message by the iframe a CSS selector matches',
|
|
8398
|
+
'script-bridge': 'posts to the contentWindow of an iframe matched by a CSS selector',
|
|
8399
|
+
'dom-mirror': 'reads a DOM element matched by a CSS selector',
|
|
8400
|
+
'same-origin-window': 'reads into the contentWindow of an iframe matched by a CSS selector',
|
|
8401
|
+
'synthetic-mutation': 'observes DOM mutations with a MutationObserver',
|
|
8402
|
+
};
|
|
8403
|
+
|
|
8404
|
+
/* The closed list of NacError codes the plugin contract raises
|
|
8405
|
+
(SPEC.md sec 15.9), plus the namespace a plugin uses for a code
|
|
8406
|
+
of its own (v2.6, RFC V26-01 hook E-6). Before this, `call` lifted
|
|
8407
|
+
ANY string a backend put on err._code, so a plugin-specific code
|
|
8408
|
+
worked by accident of implementation rather than by contract --
|
|
8409
|
+
and a future runtime honouring the closed list could have killed
|
|
8410
|
+
it without breaking anything written down. */
|
|
8411
|
+
const _V25_ERROR_CODES = {
|
|
8412
|
+
'plugin_not_registered': true,
|
|
8413
|
+
'verb_not_declared': true,
|
|
8414
|
+
'state_not_declared': true,
|
|
8415
|
+
'event_not_declared': true,
|
|
8416
|
+
'backend_unknown': true,
|
|
8417
|
+
'backend_target_missing': true,
|
|
8418
|
+
'cross_origin_blocked': true,
|
|
8419
|
+
'state_unreadable': true,
|
|
8420
|
+
'timeout': true,
|
|
8421
|
+
'invalid': true,
|
|
8422
|
+
/* 2.7.0 (sec 19.3 / 19.4). no_document: a DOM primitive was called
|
|
8423
|
+
where there is no document, so there is nothing to resolve --
|
|
8424
|
+
raised instead of the raw ReferenceError the reference runtime
|
|
8425
|
+
used to let through. provenance_unobservable: a plugin that
|
|
8426
|
+
declares headless: true was called with no document AND no event
|
|
8427
|
+
sink, so its nac:plugin:* row would be dropped; refused before
|
|
8428
|
+
the effect, because a surface nobody can audit is the silent
|
|
8429
|
+
damage this protocol exists to remove. */
|
|
8430
|
+
'no_document': true,
|
|
8431
|
+
'provenance_unobservable': true,
|
|
6945
8432
|
};
|
|
8433
|
+
const _V25_PLUGIN_CODE_PREFIX = 'plugin.';
|
|
8434
|
+
|
|
8435
|
+
/* Is `code` a code this contract lets a backend raise? Either one of
|
|
8436
|
+
the ten above, or a plugin-owned code under the reserved prefix.
|
|
8437
|
+
Anything else is `invalid` -- fail closed, and name what was
|
|
8438
|
+
refused on err.offending_code so the author can see it. */
|
|
8439
|
+
function _v25_isDeclaredCode(code) {
|
|
8440
|
+
if (typeof code !== 'string' || !code) return false;
|
|
8441
|
+
if (_V25_ERROR_CODES[code]) return true;
|
|
8442
|
+
return code.indexOf(_V25_PLUGIN_CODE_PREFIX) === 0 &&
|
|
8443
|
+
code.length > _V25_PLUGIN_CODE_PREFIX.length;
|
|
8444
|
+
}
|
|
8445
|
+
|
|
8446
|
+
/* ---------- 15.10 API handle registry (v2.6, hook E-4) ----------
|
|
8447
|
+
|
|
8448
|
+
sdk-call used to resolve its `path` against the global object and
|
|
8449
|
+
nothing else, so an API object that never lands on `window` -- a
|
|
8450
|
+
React ref, a viewer handle held in a closure, a Leaflet map
|
|
8451
|
+
instance -- was unreachable. SPEC 15.1 names exactly that case
|
|
8452
|
+
("invoke excalidrawAPI.setElements(...) on a React ref") as a
|
|
8453
|
+
motivation, and the backend could not do it.
|
|
8454
|
+
|
|
8455
|
+
The host registers the object once under a name; manifests stay
|
|
8456
|
+
pure JSON and reference it by `handle`. */
|
|
8457
|
+
|
|
8458
|
+
const _v25_api_handles = Object.create(null);
|
|
8459
|
+
|
|
8460
|
+
function registerApiHandle(name, obj) {
|
|
8461
|
+
if (typeof name !== 'string' || !name) {
|
|
8462
|
+
const e = new Error('registerApiHandle: name must be a non-empty string');
|
|
8463
|
+
e.code = 'invalid'; throw e;
|
|
8464
|
+
}
|
|
8465
|
+
if (obj == null) {
|
|
8466
|
+
const e = new Error('registerApiHandle: handle "' + name + '" cannot be null or undefined');
|
|
8467
|
+
e.code = 'invalid'; throw e;
|
|
8468
|
+
}
|
|
8469
|
+
_v25_api_handles[name] = obj;
|
|
8470
|
+
}
|
|
8471
|
+
|
|
8472
|
+
function unregisterApiHandle(name) {
|
|
8473
|
+
if (typeof name !== 'string' || !name) return false;
|
|
8474
|
+
if (!Object.prototype.hasOwnProperty.call(_v25_api_handles, name)) return false;
|
|
8475
|
+
delete _v25_api_handles[name];
|
|
8476
|
+
return true;
|
|
8477
|
+
}
|
|
8478
|
+
|
|
8479
|
+
function apiHandles() {
|
|
8480
|
+
return Object.keys(_v25_api_handles).sort();
|
|
8481
|
+
}
|
|
8482
|
+
|
|
8483
|
+
/* Resolve the root a binding's `path` is walked against: a registered
|
|
8484
|
+
handle when the binding declares one, the global object otherwise.
|
|
8485
|
+
An undeclared handle is backend_target_missing, not a silent fall
|
|
8486
|
+
back to `window` -- the whole point is that the two are different
|
|
8487
|
+
places and a manifest naming the wrong one must say so. */
|
|
8488
|
+
function _v25_bindingRoot(binding) {
|
|
8489
|
+
if (binding.handle == null) return { root: global, label: 'window' };
|
|
8490
|
+
if (typeof binding.handle !== 'string' || !binding.handle) {
|
|
8491
|
+
const e = new Error('`handle` must be a non-empty string');
|
|
8492
|
+
e._code = 'invalid'; throw e;
|
|
8493
|
+
}
|
|
8494
|
+
if (!Object.prototype.hasOwnProperty.call(_v25_api_handles, binding.handle)) {
|
|
8495
|
+
const e = new Error('API handle "' + binding.handle + '" is not registered (NAC.registerApiHandle)');
|
|
8496
|
+
e._code = 'backend_target_missing'; throw e;
|
|
8497
|
+
}
|
|
8498
|
+
return { root: _v25_api_handles[binding.handle], label: 'handle:' + binding.handle };
|
|
8499
|
+
}
|
|
6946
8500
|
|
|
6947
8501
|
/* Counter for the request_id baked into every provenance event. */
|
|
6948
8502
|
let _v25_req_counter = 0;
|
|
@@ -7028,29 +8582,52 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7028
8582
|
if (!path || typeof path !== 'string') {
|
|
7029
8583
|
return Promise.reject(new Error('sdk-call requires `path` string'));
|
|
7030
8584
|
}
|
|
7031
|
-
|
|
8585
|
+
let base;
|
|
8586
|
+
try { base = _v25_bindingRoot(binding); }
|
|
8587
|
+
catch (e) { return Promise.reject(e); }
|
|
8588
|
+
const resolved = _v25_resolvePath(base.root, path);
|
|
7032
8589
|
if (mode === 'read') {
|
|
7033
8590
|
if (resolved.parent == null) {
|
|
7034
|
-
return Promise.reject(new Error('sdk-call read: path not resolvable: ' + path));
|
|
8591
|
+
return Promise.reject(new Error('sdk-call read: path not resolvable: ' + base.label + '.' + path));
|
|
7035
8592
|
}
|
|
7036
8593
|
if (resolved.value === undefined) {
|
|
7037
|
-
return Promise.reject(new Error('sdk-call read: path resolves to undefined: ' + path));
|
|
8594
|
+
return Promise.reject(new Error('sdk-call read: path resolves to undefined: ' + base.label + '.' + path));
|
|
7038
8595
|
}
|
|
7039
8596
|
return Promise.resolve(resolved.value);
|
|
7040
8597
|
}
|
|
7041
8598
|
if (mode === 'assign') {
|
|
7042
8599
|
if (resolved.parent == null) {
|
|
7043
|
-
return Promise.reject(new Error('sdk-call assign: path parent not resolvable: ' + path));
|
|
8600
|
+
return Promise.reject(new Error('sdk-call assign: path parent not resolvable: ' + base.label + '.' + path));
|
|
7044
8601
|
}
|
|
7045
8602
|
resolved.parent[resolved.key] = args;
|
|
7046
8603
|
return Promise.resolve({ ok: true });
|
|
7047
8604
|
}
|
|
7048
8605
|
if (mode === 'invoke') {
|
|
7049
8606
|
if (resolved.parent == null || typeof resolved.value !== 'function') {
|
|
7050
|
-
return Promise.reject(new Error('sdk-call invoke: path is not a function: ' + path));
|
|
8607
|
+
return Promise.reject(new Error('sdk-call invoke: path is not a function: ' + base.label + '.' + path));
|
|
8608
|
+
}
|
|
8609
|
+
/* v2.6 (hook E-4): `args_order` spells out the POSITIONAL
|
|
8610
|
+
argument list, so a library signature like
|
|
8611
|
+
map.setView(center, zoom) is expressible. Without it the
|
|
8612
|
+
backend passes the args object as a single argument, which is
|
|
8613
|
+
what every published manifest does and keeps doing. */
|
|
8614
|
+
let list = null;
|
|
8615
|
+
if (binding.args_order != null) {
|
|
8616
|
+
if (!Array.isArray(binding.args_order)) {
|
|
8617
|
+
const e = new Error('sdk-call: `args_order` must be an array of arg names');
|
|
8618
|
+
e._code = 'invalid'; return Promise.reject(e);
|
|
8619
|
+
}
|
|
8620
|
+
const bag = (args && typeof args === 'object') ? args : {};
|
|
8621
|
+
list = [];
|
|
8622
|
+
for (let i = 0; i < binding.args_order.length; i++) {
|
|
8623
|
+
const k = binding.args_order[i];
|
|
8624
|
+
list.push(Object.prototype.hasOwnProperty.call(bag, k) ? bag[k] : undefined);
|
|
8625
|
+
}
|
|
7051
8626
|
}
|
|
7052
8627
|
try {
|
|
7053
|
-
const ret =
|
|
8628
|
+
const ret = list
|
|
8629
|
+
? resolved.value.apply(resolved.parent, list)
|
|
8630
|
+
: resolved.value.call(resolved.parent, args);
|
|
7054
8631
|
return Promise.resolve(ret);
|
|
7055
8632
|
} catch (e) {
|
|
7056
8633
|
return Promise.reject(e);
|
|
@@ -7060,6 +8637,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7060
8637
|
}
|
|
7061
8638
|
|
|
7062
8639
|
function _v25_backend_dom_mirror(binding /*, args*/) {
|
|
8640
|
+
const miss = _v25_noDocument('dom-mirror');
|
|
8641
|
+
if (miss) return Promise.reject(miss);
|
|
7063
8642
|
const sel = binding.selector;
|
|
7064
8643
|
if (!sel) return Promise.reject(new Error('dom-mirror requires `selector` string'));
|
|
7065
8644
|
const el = document.querySelector(sel);
|
|
@@ -7084,6 +8663,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7084
8663
|
/* postmessage (verb): post a structured message to the iframe.contentWindow
|
|
7085
8664
|
of the target. `values` literal + `values_from_args` forward keys. */
|
|
7086
8665
|
function _v25_backend_postmessage(binding, args) {
|
|
8666
|
+
const miss = _v25_noDocument('postmessage');
|
|
8667
|
+
if (miss) return Promise.reject(miss);
|
|
7087
8668
|
const sel = binding.target;
|
|
7088
8669
|
if (!sel) return Promise.reject(new Error('postmessage requires `target` selector'));
|
|
7089
8670
|
const iframe = document.querySelector(sel);
|
|
@@ -7120,6 +8701,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7120
8701
|
flag the test sets explicitly; in real browsers the property access
|
|
7121
8702
|
throws a DOMException SecurityError which we map the same way. */
|
|
7122
8703
|
function _v25_backend_same_origin_window(binding /*, args*/) {
|
|
8704
|
+
const miss = _v25_noDocument('same-origin-window');
|
|
8705
|
+
if (miss) return Promise.reject(miss);
|
|
7123
8706
|
const sel = binding.target;
|
|
7124
8707
|
if (!sel) return Promise.reject(new Error('same-origin-window requires `target`'));
|
|
7125
8708
|
const iframe = document.querySelector(sel);
|
|
@@ -7164,6 +8747,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7164
8747
|
CallPythonScript pattern; generalises to any app that exposes a
|
|
7165
8748
|
RPC channel over postMessage. */
|
|
7166
8749
|
function _v25_backend_script_bridge(binding, args) {
|
|
8750
|
+
const miss = _v25_noDocument('script-bridge');
|
|
8751
|
+
if (miss) return Promise.reject(miss);
|
|
7167
8752
|
const sel = binding.target;
|
|
7168
8753
|
if (!sel) return Promise.reject(new Error('script-bridge requires `target`'));
|
|
7169
8754
|
const iframe = document.querySelector(sel);
|
|
@@ -7281,6 +8866,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7281
8866
|
fall back to synthetic-poll for those cases (declared, not
|
|
7282
8867
|
implicit). */
|
|
7283
8868
|
function _v25_subscribe_synthetic_mutation(plugin, event_path, binding, cb) {
|
|
8869
|
+
const miss = _v25_noDocument('synthetic-mutation');
|
|
8870
|
+
if (miss) throw miss;
|
|
7284
8871
|
if (typeof MutationObserver === 'undefined') {
|
|
7285
8872
|
throw new Error('synthetic-mutation requires MutationObserver in scope');
|
|
7286
8873
|
}
|
|
@@ -7293,6 +8880,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7293
8880
|
whole subscription if any observed path's primary binding is
|
|
7294
8881
|
not dom-mirror -- spec contract, no silent degradation. */
|
|
7295
8882
|
const elements = [];
|
|
8883
|
+
const unresolved = [];
|
|
7296
8884
|
const manifest = _v25_plugins[plugin];
|
|
7297
8885
|
for (let i = 0; i < paths.length; i++) {
|
|
7298
8886
|
const stateChain = manifest.state[paths[i]];
|
|
@@ -7308,9 +8896,47 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7308
8896
|
}
|
|
7309
8897
|
const el = document.querySelector(first.selector);
|
|
7310
8898
|
if (el) elements.push(el);
|
|
8899
|
+
else unresolved.push(paths[i] + ' (' + first.selector + ')');
|
|
8900
|
+
}
|
|
8901
|
+
/* v2.6 (hook E-5). Until 2.5.2 an unresolved selector was dropped
|
|
8902
|
+
here with `if (el) elements.push(el)`, so a subscription whose
|
|
8903
|
+
mirror nodes were all absent observed NOTHING: subscribe()
|
|
8904
|
+
returned a valid handle and the callback never fired. Success
|
|
8905
|
+
and silence -- the silent damage this protocol exists to remove,
|
|
8906
|
+
inside the protocol.
|
|
8907
|
+
|
|
8908
|
+
Two ways out, and the manifest chooses:
|
|
8909
|
+
- no `root`: fail closed. An absent mirror node is
|
|
8910
|
+
backend_target_missing at subscribe time, named selector by
|
|
8911
|
+
selector.
|
|
8912
|
+
- `root` declared: observe that container with subtree:true
|
|
8913
|
+
and re-read on every mutation. A node that comes and goes
|
|
8914
|
+
(the row of a virtualised grid) is then observed by the
|
|
8915
|
+
container that outlives it, so the subscription survives
|
|
8916
|
+
the remount. The root itself must resolve -- otherwise we
|
|
8917
|
+
would be back to observing nothing. */
|
|
8918
|
+
let rootEl = null;
|
|
8919
|
+
if (binding.root != null) {
|
|
8920
|
+
if (typeof binding.root !== 'string' || !binding.root) {
|
|
8921
|
+
const e = new Error('synthetic-mutation: `root` must be a non-empty CSS selector');
|
|
8922
|
+
e._code = 'invalid'; throw e;
|
|
8923
|
+
}
|
|
8924
|
+
rootEl = document.querySelector(binding.root);
|
|
8925
|
+
if (!rootEl) {
|
|
8926
|
+
const e = new Error('synthetic-mutation: `root` selector matched no element: ' + binding.root +
|
|
8927
|
+
' -- an observer with no root would never fire');
|
|
8928
|
+
e._code = 'backend_target_missing'; throw e;
|
|
8929
|
+
}
|
|
8930
|
+
}
|
|
8931
|
+
if (!rootEl && unresolved.length) {
|
|
8932
|
+
const e = new Error('synthetic-mutation: no element for observed state ' + unresolved.join(', ') +
|
|
8933
|
+
' -- a subscription with nothing to observe would never fire; declare `root` to observe a' +
|
|
8934
|
+
' container that outlives the node and re-resolve on mutation');
|
|
8935
|
+
e._code = 'backend_target_missing'; throw e;
|
|
7311
8936
|
}
|
|
7312
8937
|
let cached = null;
|
|
7313
8938
|
let pending = null;
|
|
8939
|
+
let primed = false; /* has this subscription ever held a readable snapshot? */
|
|
7314
8940
|
function snapshot() {
|
|
7315
8941
|
const out = {};
|
|
7316
8942
|
let allOk = true;
|
|
@@ -7334,29 +8960,48 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7334
8960
|
}
|
|
7335
8961
|
return false;
|
|
7336
8962
|
}
|
|
8963
|
+
function emit(snap) {
|
|
8964
|
+
try { cb(snap); }
|
|
8965
|
+
finally {
|
|
8966
|
+
_v25_emitProvenance('event', plugin, event_path, 'synthetic-mutation',
|
|
8967
|
+
_v25_nextRequestId('pe'), true, null, 0);
|
|
8968
|
+
}
|
|
8969
|
+
}
|
|
7337
8970
|
function tick() {
|
|
7338
8971
|
pending = null;
|
|
7339
8972
|
snapshot().then(function (snap) {
|
|
7340
8973
|
if (snap == null) return;
|
|
7341
|
-
if (cached == null) {
|
|
8974
|
+
if (cached == null) {
|
|
8975
|
+
cached = snap;
|
|
8976
|
+
/* v2.6 (hook E-5): the subscription started with NOTHING
|
|
8977
|
+
readable -- the observed node was not painted when
|
|
8978
|
+
subscribe() was called, which under `root` is a legal and
|
|
8979
|
+
expected state. The move from unreadable to readable IS
|
|
8980
|
+
the change the caller is waiting for; adopting it as a
|
|
8981
|
+
silent baseline is how a row that remounts goes unnoticed.
|
|
8982
|
+
When the first snapshot DID resolve, this branch never
|
|
8983
|
+
runs and the baseline behaviour of 2.5 is untouched. */
|
|
8984
|
+
if (!primed) { primed = true; emit(snap); }
|
|
8985
|
+
return;
|
|
8986
|
+
}
|
|
7342
8987
|
if (diffsFromCached(snap)) {
|
|
7343
8988
|
cached = snap;
|
|
7344
|
-
|
|
7345
|
-
finally {
|
|
7346
|
-
_v25_emitProvenance('event', plugin, event_path, 'synthetic-mutation',
|
|
7347
|
-
_v25_nextRequestId('pe'), true, null, 0);
|
|
7348
|
-
}
|
|
8989
|
+
emit(snap);
|
|
7349
8990
|
}
|
|
7350
8991
|
});
|
|
7351
8992
|
}
|
|
7352
|
-
/* Prime cache from first snapshot.
|
|
7353
|
-
|
|
8993
|
+
/* Prime cache from first snapshot. A tick that got there first
|
|
8994
|
+
keeps its snapshot: the fresher read wins. */
|
|
8995
|
+
snapshot().then(function (first) {
|
|
8996
|
+
if (first != null && cached == null) { cached = first; primed = true; }
|
|
8997
|
+
});
|
|
7354
8998
|
const observer = new MutationObserver(function () {
|
|
7355
8999
|
if (pending != null) return; /* already throttled */
|
|
7356
9000
|
pending = setTimeout(tick, throttle);
|
|
7357
9001
|
});
|
|
7358
|
-
|
|
7359
|
-
|
|
9002
|
+
const watched = rootEl ? [rootEl] : elements;
|
|
9003
|
+
for (let i = 0; i < watched.length; i++) {
|
|
9004
|
+
observer.observe(watched[i], {
|
|
7360
9005
|
attributes: true, childList: true, characterData: true, subtree: true,
|
|
7361
9006
|
});
|
|
7362
9007
|
}
|
|
@@ -7366,10 +9011,123 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7366
9011
|
};
|
|
7367
9012
|
}
|
|
7368
9013
|
|
|
9014
|
+
/* emitter-listen (event, v2.6 -- hook E-3): subscribe to a real
|
|
9015
|
+
event source that is NOT postMessage. The emitter is the global
|
|
9016
|
+
object, a dotted path into it, or a registered API handle; the
|
|
9017
|
+
subscribe / unsubscribe method pair is detected from the three
|
|
9018
|
+
shapes libraries actually ship (on/off, addEventListener/
|
|
9019
|
+
removeEventListener, addListener/removeListener) or declared
|
|
9020
|
+
outright.
|
|
9021
|
+
|
|
9022
|
+
Fail closed in both directions: no subscribe method is
|
|
9023
|
+
backend_target_missing, and NO REMOVAL METHOD is too -- a
|
|
9024
|
+
subscription that cannot be torn down is a leak dressed as a
|
|
9025
|
+
success, and unsubscribe() is part of the published contract.
|
|
9026
|
+
|
|
9027
|
+
Payload: `extract` plucks a field out of the event object the
|
|
9028
|
+
library hands us. `observe` instead re-reads declared state paths
|
|
9029
|
+
and fires the callback with that snapshot -- the useful shape for
|
|
9030
|
+
a continuous surface, where the event only says "it moved" and
|
|
9031
|
+
the state says where it moved to. */
|
|
9032
|
+
const _V25_LISTEN_PAIRS = {
|
|
9033
|
+
'on': 'off',
|
|
9034
|
+
'addEventListener': 'removeEventListener',
|
|
9035
|
+
'addListener': 'removeListener',
|
|
9036
|
+
};
|
|
9037
|
+
|
|
9038
|
+
function _v25_subscribe_emitter_listen(plugin, event_path, binding, cb) {
|
|
9039
|
+
const eventName = binding.event;
|
|
9040
|
+
if (!eventName || typeof eventName !== 'string') {
|
|
9041
|
+
const e = new Error('emitter-listen requires `event` (the library event name)');
|
|
9042
|
+
e._code = 'invalid'; throw e;
|
|
9043
|
+
}
|
|
9044
|
+
const base = _v25_bindingRoot(binding); /* throws with _code */
|
|
9045
|
+
let target = base.root;
|
|
9046
|
+
if (binding.path != null) {
|
|
9047
|
+
if (typeof binding.path !== 'string' || !binding.path) {
|
|
9048
|
+
const e = new Error('emitter-listen: `path` must be a non-empty dotted path');
|
|
9049
|
+
e._code = 'invalid'; throw e;
|
|
9050
|
+
}
|
|
9051
|
+
target = _v25_resolvePath(base.root, binding.path).value;
|
|
9052
|
+
}
|
|
9053
|
+
if (target == null) {
|
|
9054
|
+
const e = new Error('emitter-listen: emitter not resolvable at ' + base.label +
|
|
9055
|
+
(binding.path ? '.' + binding.path : ''));
|
|
9056
|
+
e._code = 'backend_target_missing'; throw e;
|
|
9057
|
+
}
|
|
9058
|
+
let onName = binding.method;
|
|
9059
|
+
if (onName != null) {
|
|
9060
|
+
if (typeof onName !== 'string' || typeof target[onName] !== 'function') {
|
|
9061
|
+
const e = new Error('emitter-listen: declared `method` "' + onName + '" is not a function on the emitter');
|
|
9062
|
+
e._code = 'backend_target_missing'; throw e;
|
|
9063
|
+
}
|
|
9064
|
+
} else {
|
|
9065
|
+
onName = null;
|
|
9066
|
+
for (const cand in _V25_LISTEN_PAIRS) {
|
|
9067
|
+
if (typeof target[cand] === 'function') { onName = cand; break; }
|
|
9068
|
+
}
|
|
9069
|
+
if (!onName) {
|
|
9070
|
+
const e = new Error('emitter-listen: emitter exposes none of on / addEventListener / addListener');
|
|
9071
|
+
e._code = 'backend_target_missing'; throw e;
|
|
9072
|
+
}
|
|
9073
|
+
}
|
|
9074
|
+
const offName = binding.off_method || _V25_LISTEN_PAIRS[onName] || null;
|
|
9075
|
+
if (!offName || typeof target[offName] !== 'function') {
|
|
9076
|
+
const e = new Error('emitter-listen: emitter has no removal method (' +
|
|
9077
|
+
(offName || 'none derivable from "' + onName + '"') +
|
|
9078
|
+
') -- a subscription that cannot be torn down is refused');
|
|
9079
|
+
e._code = 'backend_target_missing'; throw e;
|
|
9080
|
+
}
|
|
9081
|
+
const observed = Array.isArray(binding.observe) ? binding.observe.slice() : null;
|
|
9082
|
+
if (observed) {
|
|
9083
|
+
for (let i = 0; i < observed.length; i++) {
|
|
9084
|
+
if (!_v25_plugins[plugin].state[observed[i]]) {
|
|
9085
|
+
const e = new Error('emitter-listen: observed state "' + observed[i] + '" not declared');
|
|
9086
|
+
e._code = 'invalid'; throw e;
|
|
9087
|
+
}
|
|
9088
|
+
}
|
|
9089
|
+
}
|
|
9090
|
+
function fire(value, ok, errMsg) {
|
|
9091
|
+
try { if (ok) cb(value); }
|
|
9092
|
+
finally {
|
|
9093
|
+
_v25_emitProvenance('event', plugin, event_path, 'emitter-listen',
|
|
9094
|
+
_v25_nextRequestId('pe'), !!ok, errMsg || null, 0);
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9097
|
+
function handler(payload) {
|
|
9098
|
+
if (observed) {
|
|
9099
|
+
const out = {};
|
|
9100
|
+
let allOk = true;
|
|
9101
|
+
Promise.all(observed.map(function (p) {
|
|
9102
|
+
return read(plugin, p).then(function (v) { out[p] = v; },
|
|
9103
|
+
function () { allOk = false; });
|
|
9104
|
+
})).then(function () {
|
|
9105
|
+
if (allOk) fire(out, true, null);
|
|
9106
|
+
else fire(null, false, 'observed state unreadable at event time');
|
|
9107
|
+
});
|
|
9108
|
+
return;
|
|
9109
|
+
}
|
|
9110
|
+
let value;
|
|
9111
|
+
try {
|
|
9112
|
+
value = binding.extract ? _v25_extract(payload, binding.extract, false) : payload;
|
|
9113
|
+
} catch (e) {
|
|
9114
|
+
fire(null, false, e.message);
|
|
9115
|
+
return;
|
|
9116
|
+
}
|
|
9117
|
+
fire(value, true, null);
|
|
9118
|
+
}
|
|
9119
|
+
target[onName](eventName, handler);
|
|
9120
|
+
return function teardown() {
|
|
9121
|
+
try { target[offName](eventName, handler); } catch (_) { /* idempotent */ }
|
|
9122
|
+
};
|
|
9123
|
+
}
|
|
9124
|
+
|
|
7369
9125
|
/* postmessage-listen (event): subscribe to incoming `message` events
|
|
7370
9126
|
on the host window, filter by source iframe + MessageId, run the
|
|
7371
9127
|
extractor, fire the user callback. Returns a teardown closure. */
|
|
7372
9128
|
function _v25_subscribe_postmessage_listen(plugin, event_path, binding, cb) {
|
|
9129
|
+
const miss = _v25_noDocument('postmessage-listen');
|
|
9130
|
+
if (miss) throw miss;
|
|
7373
9131
|
const sel = binding.source;
|
|
7374
9132
|
const wantMsgId = binding.message;
|
|
7375
9133
|
if (!wantMsgId) throw new Error('postmessage-listen requires `message`');
|
|
@@ -7417,10 +9175,90 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7417
9175
|
'postmessage-listen': _v25_subscribe_postmessage_listen,
|
|
7418
9176
|
'synthetic-poll': _v25_subscribe_synthetic_poll,
|
|
7419
9177
|
'synthetic-mutation': _v25_subscribe_synthetic_mutation,
|
|
9178
|
+
'emitter-listen': _v25_subscribe_emitter_listen,
|
|
7420
9179
|
};
|
|
7421
9180
|
|
|
7422
9181
|
/* ---------- 15.2 / 15.3 public surface ---------- */
|
|
7423
9182
|
|
|
9183
|
+
/* ---------- 15.11 self-description (v2.6, hook E-2) ----------
|
|
9184
|
+
|
|
9185
|
+
A manifest used to declare only WHERE a verb routes, never what it
|
|
9186
|
+
is called or what it takes. The DOM half of the protocol has had
|
|
9187
|
+
that since v1 (a label, a hint, `fields[]` with a type); the
|
|
9188
|
+
plugin half had nothing, so on a continuous surface -- where the
|
|
9189
|
+
actionable thing IS the argument: a coordinate and a zoom, an
|
|
9190
|
+
instant, a page, a pose -- nothing declared the shape, the unit or
|
|
9191
|
+
the range of what travels in `args`, and a voice runner could not
|
|
9192
|
+
even name the verb out loud.
|
|
9193
|
+
|
|
9194
|
+
All of it is OPTIONAL: every manifest published against 2.5 stays
|
|
9195
|
+
valid. What is NOT optional is being well-formed when declared --
|
|
9196
|
+
a label that is not a string, or a param of a type the vocabulary
|
|
9197
|
+
does not have, is `invalid` at register time rather than a
|
|
9198
|
+
surprise at the moment an agent reads it. */
|
|
9199
|
+
|
|
9200
|
+
const _V25_PARAM_TYPES = {
|
|
9201
|
+
'string': true, 'number': true, 'boolean': true, 'object': true, 'array': true,
|
|
9202
|
+
};
|
|
9203
|
+
|
|
9204
|
+
function _v25_validateText(value, where, field) {
|
|
9205
|
+
if (value == null) return;
|
|
9206
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
9207
|
+
const e = new Error(where + ': `' + field + '` must be a non-empty string when declared');
|
|
9208
|
+
e.code = 'invalid'; throw e;
|
|
9209
|
+
}
|
|
9210
|
+
}
|
|
9211
|
+
|
|
9212
|
+
function _v25_validateParams(params, where) {
|
|
9213
|
+
if (params == null) return;
|
|
9214
|
+
if (!Array.isArray(params)) {
|
|
9215
|
+
const e = new Error(where + ': `params` must be an array of parameter declarations');
|
|
9216
|
+
e.code = 'invalid'; throw e;
|
|
9217
|
+
}
|
|
9218
|
+
const seen = Object.create(null);
|
|
9219
|
+
for (let i = 0; i < params.length; i++) {
|
|
9220
|
+
const p = params[i];
|
|
9221
|
+
const at = where + ' params[' + i + ']';
|
|
9222
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) {
|
|
9223
|
+
const e = new Error(at + ': must be an object');
|
|
9224
|
+
e.code = 'invalid'; throw e;
|
|
9225
|
+
}
|
|
9226
|
+
if (typeof p.name !== 'string' || !p.name.trim()) {
|
|
9227
|
+
const e = new Error(at + ': `name` is required and must be a non-empty string');
|
|
9228
|
+
e.code = 'invalid'; throw e;
|
|
9229
|
+
}
|
|
9230
|
+
if (seen[p.name]) {
|
|
9231
|
+
const e = new Error(at + ': duplicate parameter name "' + p.name + '"');
|
|
9232
|
+
e.code = 'invalid'; throw e;
|
|
9233
|
+
}
|
|
9234
|
+
seen[p.name] = true;
|
|
9235
|
+
if (typeof p.type !== 'string' || !_V25_PARAM_TYPES[p.type]) {
|
|
9236
|
+
const e = new Error(at + ': `type` must be one of string, number, boolean, object, array (got ' +
|
|
9237
|
+
JSON.stringify(p.type) + ')');
|
|
9238
|
+
e.code = 'invalid'; throw e;
|
|
9239
|
+
}
|
|
9240
|
+
if (p.required != null && typeof p.required !== 'boolean') {
|
|
9241
|
+
const e = new Error(at + ': `required` must be a boolean when declared');
|
|
9242
|
+
e.code = 'invalid'; throw e;
|
|
9243
|
+
}
|
|
9244
|
+
_v25_validateText(p.label, at, 'label');
|
|
9245
|
+
_v25_validateText(p.hint, at, 'hint');
|
|
9246
|
+
_v25_validateText(p.unit, at, 'unit');
|
|
9247
|
+
if (p.min != null && typeof p.min !== 'number') {
|
|
9248
|
+
const e = new Error(at + ': `min` must be a number when declared');
|
|
9249
|
+
e.code = 'invalid'; throw e;
|
|
9250
|
+
}
|
|
9251
|
+
if (p.max != null && typeof p.max !== 'number') {
|
|
9252
|
+
const e = new Error(at + ': `max` must be a number when declared');
|
|
9253
|
+
e.code = 'invalid'; throw e;
|
|
9254
|
+
}
|
|
9255
|
+
if (p.enum != null && (!Array.isArray(p.enum) || p.enum.length === 0)) {
|
|
9256
|
+
const e = new Error(at + ': `enum` must be a non-empty array when declared');
|
|
9257
|
+
e.code = 'invalid'; throw e;
|
|
9258
|
+
}
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9261
|
+
|
|
7424
9262
|
function _v25_validateManifest(slug, manifest) {
|
|
7425
9263
|
if (typeof slug !== 'string' || !slug) {
|
|
7426
9264
|
const e = new Error('registerPlugin: slug must be non-empty string');
|
|
@@ -7433,6 +9271,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7433
9271
|
const verbs = manifest.verbs || {};
|
|
7434
9272
|
const states = manifest.state || {};
|
|
7435
9273
|
const events = manifest.events || {};
|
|
9274
|
+
_v25_validateText(manifest.label, 'manifest "' + slug + '"', 'label');
|
|
9275
|
+
_v25_validateText(manifest.hint, 'manifest "' + slug + '"', 'hint');
|
|
9276
|
+
/* 2.7.0 (sec 19.1) -- headless is a boolean or it is absent. A
|
|
9277
|
+
string "true" is a typo that would silently leave the plugin
|
|
9278
|
+
outside the profile, so it is refused rather than coerced. */
|
|
9279
|
+
if (manifest.headless !== undefined && typeof manifest.headless !== 'boolean') {
|
|
9280
|
+
const e = new Error('manifest "' + slug + '": headless must be a boolean when declared');
|
|
9281
|
+
e.code = 'invalid'; throw e;
|
|
9282
|
+
}
|
|
7436
9283
|
/* Verbs: single binding each, backend in vocabulary. */
|
|
7437
9284
|
for (const vp in verbs) {
|
|
7438
9285
|
const b = verbs[vp];
|
|
@@ -7444,6 +9291,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7444
9291
|
const e = new Error('verb "' + vp + '" declares unknown backend: ' + b.backend);
|
|
7445
9292
|
e.code = 'backend_unknown'; throw e;
|
|
7446
9293
|
}
|
|
9294
|
+
_v25_validateText(b.label, 'verb "' + vp + '"', 'label');
|
|
9295
|
+
_v25_validateText(b.hint, 'verb "' + vp + '"', 'hint');
|
|
9296
|
+
_v25_validateParams(b.params, 'verb "' + vp + '"');
|
|
7447
9297
|
}
|
|
7448
9298
|
/* State: array of bindings each. */
|
|
7449
9299
|
for (const sp in states) {
|
|
@@ -7462,6 +9312,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7462
9312
|
const e = new Error('state "' + sp + '" binding[' + i + '] unknown backend: ' + b.backend);
|
|
7463
9313
|
e.code = 'backend_unknown'; throw e;
|
|
7464
9314
|
}
|
|
9315
|
+
_v25_validateText(b.label, 'state "' + sp + '" binding[' + i + ']', 'label');
|
|
9316
|
+
_v25_validateText(b.hint, 'state "' + sp + '" binding[' + i + ']', 'hint');
|
|
9317
|
+
_v25_validateText(b.unit, 'state "' + sp + '" binding[' + i + ']', 'unit');
|
|
7465
9318
|
}
|
|
7466
9319
|
}
|
|
7467
9320
|
/* Events: single binding each. */
|
|
@@ -7475,6 +9328,38 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7475
9328
|
const e = new Error('event "' + ep + '" unknown backend: ' + b.backend);
|
|
7476
9329
|
e.code = 'backend_unknown'; throw e;
|
|
7477
9330
|
}
|
|
9331
|
+
_v25_validateText(b.label, 'event "' + ep + '"', 'label');
|
|
9332
|
+
_v25_validateText(b.hint, 'event "' + ep + '"', 'hint');
|
|
9333
|
+
/* emitter-listen carries the one field the runtime cannot guess
|
|
9334
|
+
(v2.6): which event of the library to listen for. Caught here
|
|
9335
|
+
instead of at subscribe time so a manifest that can never work
|
|
9336
|
+
is refused when it is registered. */
|
|
9337
|
+
if (b.backend === 'emitter-listen' && (typeof b.event !== 'string' || !b.event)) {
|
|
9338
|
+
const e = new Error('event "' + ep + '": emitter-listen requires `event` (the library event name)');
|
|
9339
|
+
e.code = 'invalid'; throw e;
|
|
9340
|
+
}
|
|
9341
|
+
}
|
|
9342
|
+
/* 2.7.0 (sec 19.1) -- a manifest that DECLARES the headless
|
|
9343
|
+
profile has to be in it. Checked here, at register time, so the
|
|
9344
|
+
adopter learns on the bench instead of discovering it on a
|
|
9345
|
+
device with no screen: every binding must reach its surface
|
|
9346
|
+
without a document, and the refusal names the ones that do not. */
|
|
9347
|
+
if (manifest.headless === true) {
|
|
9348
|
+
const need = _v25_domRequired({
|
|
9349
|
+
verbs: verbs, state: states, events: events,
|
|
9350
|
+
});
|
|
9351
|
+
if (need.length) {
|
|
9352
|
+
const first = need[0];
|
|
9353
|
+
const e = new Error('manifest "' + slug + '" declares headless: true but ' +
|
|
9354
|
+
need.length + ' binding' + (need.length === 1 ? '' : 's') + ' need' +
|
|
9355
|
+
(need.length === 1 ? 's' : '') + ' a document. First: ' + first.kind + ' "' +
|
|
9356
|
+
first.path + '" -- ' + first.why + '. Declare a DOM-free backend (sdk-call, ' +
|
|
9357
|
+
'emitter-listen, or synthetic-poll over DOM-free state) or drop the ' +
|
|
9358
|
+
'declaration (SPEC sec 19.1).');
|
|
9359
|
+
e.code = 'invalid';
|
|
9360
|
+
e.dom_required = need;
|
|
9361
|
+
throw e;
|
|
9362
|
+
}
|
|
7478
9363
|
}
|
|
7479
9364
|
}
|
|
7480
9365
|
|
|
@@ -7483,12 +9368,315 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7483
9368
|
/* Re-register replaces -- idempotent for live-reload scenarios. */
|
|
7484
9369
|
_v25_plugins[slug] = {
|
|
7485
9370
|
slug: slug,
|
|
9371
|
+
label: manifest.label != null ? manifest.label : null,
|
|
9372
|
+
hint: manifest.hint != null ? manifest.hint : null,
|
|
9373
|
+
/* 2.7.0 (sec 19.1) -- the headless profile is DECLARED, never
|
|
9374
|
+
inferred. Absent means false, which is every manifest ever
|
|
9375
|
+
written before today. */
|
|
9376
|
+
headless: manifest.headless === true,
|
|
7486
9377
|
verbs: manifest.verbs || {},
|
|
7487
9378
|
state: manifest.state || {},
|
|
7488
9379
|
events: manifest.events || {},
|
|
7489
9380
|
};
|
|
7490
9381
|
}
|
|
7491
9382
|
|
|
9383
|
+
/* ---------- 15.10 discovery (v2.6, hook E-1) ----------
|
|
9384
|
+
|
|
9385
|
+
Until 2.5.2 the registry was readable by exactly three functions
|
|
9386
|
+
-- call, read and subscribe -- and all three require the caller to
|
|
9387
|
+
already know the slug and the path. An agent that did not register
|
|
9388
|
+
the plugin itself had no way to learn it exists: it read the DOM
|
|
9389
|
+
manifest (section 5), found the chrome, and the canvas surface was
|
|
9390
|
+
INVISIBLE. For a plugin that declares no DOM at all there was
|
|
9391
|
+
nothing to find whatsoever.
|
|
9392
|
+
|
|
9393
|
+
plugins() and describePlugin() are the read-only answer. They are
|
|
9394
|
+
SYNCHRONOUS on purpose -- unlike call / read / subscribe, which
|
|
9395
|
+
reach a surface and therefore have to be async, these only read a
|
|
9396
|
+
local object. And they hand back a COPY: a caller cannot reach the
|
|
9397
|
+
live registry through the descriptor and rewrite another plugin's
|
|
9398
|
+
routing. */
|
|
9399
|
+
|
|
9400
|
+
function _v25_copy(value) {
|
|
9401
|
+
if (value == null || typeof value !== 'object') return value;
|
|
9402
|
+
try { return JSON.parse(JSON.stringify(value)); }
|
|
9403
|
+
catch (_) { return undefined; } /* not representable as data */
|
|
9404
|
+
}
|
|
9405
|
+
|
|
9406
|
+
function _v25_describeEntry(entry) {
|
|
9407
|
+
const out = {
|
|
9408
|
+
slug: entry.slug,
|
|
9409
|
+
label: entry.label != null ? entry.label : null,
|
|
9410
|
+
hint: entry.hint != null ? entry.hint : null,
|
|
9411
|
+
/* 2.7.0 (sec 19.1): an agent that discovers a plugin learns
|
|
9412
|
+
from the descriptor whether it needs a page -- the same
|
|
9413
|
+
question NAC.profile answers in full. */
|
|
9414
|
+
headless: !!entry.headless,
|
|
9415
|
+
verbs: [],
|
|
9416
|
+
state: [],
|
|
9417
|
+
events: [],
|
|
9418
|
+
};
|
|
9419
|
+
const verbPaths = Object.keys(entry.verbs).sort();
|
|
9420
|
+
for (let i = 0; i < verbPaths.length; i++) {
|
|
9421
|
+
const vp = verbPaths[i];
|
|
9422
|
+
const b = entry.verbs[vp] || {};
|
|
9423
|
+
const row = {
|
|
9424
|
+
verb_path: vp,
|
|
9425
|
+
backend: b.backend || null,
|
|
9426
|
+
label: b.label != null ? b.label : null,
|
|
9427
|
+
hint: b.hint != null ? b.hint : null,
|
|
9428
|
+
params: Array.isArray(b.params) ? _v25_copy(b.params) : null,
|
|
9429
|
+
};
|
|
9430
|
+
if (b.handle != null) row.handle = b.handle;
|
|
9431
|
+
out.verbs.push(row);
|
|
9432
|
+
}
|
|
9433
|
+
const statePaths = Object.keys(entry.state).sort();
|
|
9434
|
+
for (let i = 0; i < statePaths.length; i++) {
|
|
9435
|
+
const sp = statePaths[i];
|
|
9436
|
+
const chain = entry.state[sp] || [];
|
|
9437
|
+
/* The label of a state PATH is the first one its chain declares:
|
|
9438
|
+
the chain is an ordered preference of sources for one value,
|
|
9439
|
+
so the value is named once, by whichever source names it. */
|
|
9440
|
+
let label = null; let hint = null; let unit = null;
|
|
9441
|
+
const backends = [];
|
|
9442
|
+
for (let j = 0; j < chain.length; j++) {
|
|
9443
|
+
const b = chain[j] || {};
|
|
9444
|
+
if (label == null && b.label != null) label = b.label;
|
|
9445
|
+
if (hint == null && b.hint != null) hint = b.hint;
|
|
9446
|
+
if (unit == null && b.unit != null) unit = b.unit;
|
|
9447
|
+
backends.push(b.backend || null);
|
|
9448
|
+
}
|
|
9449
|
+
out.state.push({
|
|
9450
|
+
state_path: sp,
|
|
9451
|
+
backends: backends,
|
|
9452
|
+
label: label,
|
|
9453
|
+
hint: hint,
|
|
9454
|
+
unit: unit,
|
|
9455
|
+
});
|
|
9456
|
+
}
|
|
9457
|
+
const eventPaths = Object.keys(entry.events).sort();
|
|
9458
|
+
for (let i = 0; i < eventPaths.length; i++) {
|
|
9459
|
+
const ep = eventPaths[i];
|
|
9460
|
+
const b = entry.events[ep] || {};
|
|
9461
|
+
const row = {
|
|
9462
|
+
event_path: ep,
|
|
9463
|
+
backend: b.backend || null,
|
|
9464
|
+
label: b.label != null ? b.label : null,
|
|
9465
|
+
hint: b.hint != null ? b.hint : null,
|
|
9466
|
+
observe: Array.isArray(b.observe) ? b.observe.slice() : null,
|
|
9467
|
+
};
|
|
9468
|
+
if (b.event != null) row.event = b.event;
|
|
9469
|
+
out.events.push(row);
|
|
9470
|
+
}
|
|
9471
|
+
return out;
|
|
9472
|
+
}
|
|
9473
|
+
|
|
9474
|
+
function plugins() {
|
|
9475
|
+
const slugs = Object.keys(_v25_plugins).sort();
|
|
9476
|
+
const out = [];
|
|
9477
|
+
for (let i = 0; i < slugs.length; i++) {
|
|
9478
|
+
out.push(_v25_describeEntry(_v25_plugins[slugs[i]]));
|
|
9479
|
+
}
|
|
9480
|
+
return out;
|
|
9481
|
+
}
|
|
9482
|
+
|
|
9483
|
+
function describePlugin(slug) {
|
|
9484
|
+
if (typeof slug !== 'string' || !slug) {
|
|
9485
|
+
throw _v25_buildNacError('invalid', 'NAC.describePlugin: slug must be a non-empty string');
|
|
9486
|
+
}
|
|
9487
|
+
if (!_v25_plugins[slug]) {
|
|
9488
|
+
throw _v25_buildNacError('plugin_not_registered',
|
|
9489
|
+
'NAC.describePlugin: plugin "' + slug + '" not registered');
|
|
9490
|
+
}
|
|
9491
|
+
return _v25_describeEntry(_v25_plugins[slug]);
|
|
9492
|
+
}
|
|
9493
|
+
|
|
9494
|
+
/* ================================================================
|
|
9495
|
+
19. Headless profile -- the manifest as the surface (v2.7)
|
|
9496
|
+
================================================================
|
|
9497
|
+
|
|
9498
|
+
Owner decision D-26 (2026-11-25). Sections 1-14 address nodes and
|
|
9499
|
+
section 15 addresses a surface a node cannot reach. Neither says
|
|
9500
|
+
what happens when there is no document AT ALL -- a screenless
|
|
9501
|
+
assistant, an IVR, a voice device, a worker. The answer is that the
|
|
9502
|
+
extension contract already IS a capability interface: a plugin
|
|
9503
|
+
whose every binding is DOM-free is operable with no document, and
|
|
9504
|
+
plugins() + describePlugin() are the resolution surface, because
|
|
9505
|
+
they read the manifest and never the page.
|
|
9506
|
+
|
|
9507
|
+
What was missing was not routing. It was three things:
|
|
9508
|
+
|
|
9509
|
+
1. Nothing DECLARED it, so neither an agent nor the adopter could
|
|
9510
|
+
tell a manifest that needs a page from one that does not.
|
|
9511
|
+
profile() answers it from the manifest, mechanically.
|
|
9512
|
+
2. Provenance was silently LOST. Until 2.7.0 the emit helper
|
|
9513
|
+
below did document.dispatchEvent inside a try/catch, so with
|
|
9514
|
+
no document every nac:plugin:* row vanished and the call
|
|
9515
|
+
still reported success -- the exact silent damage section 7
|
|
9516
|
+
exists to prevent. setEventSink gives the same events the
|
|
9517
|
+
same shapes over a bus that is not the DOM.
|
|
9518
|
+
3. A DOM primitive crashed with a ReferenceError instead of
|
|
9519
|
+
refusing by name. _nac_requireDocument (sec 19.3) fixed that.
|
|
9520
|
+
|
|
9521
|
+
Nothing here is a new primitive and nothing here is implicit: a
|
|
9522
|
+
manifest written against 2.5 or 2.6 keeps working untouched, and
|
|
9523
|
+
the only way into the profile is to declare headless: true. */
|
|
9524
|
+
|
|
9525
|
+
/* The non-DOM provenance bus. Additive: when a document exists the
|
|
9526
|
+
events still go to it, so installing a sink in a browser gives an
|
|
9527
|
+
audit log without changing a single consumer. */
|
|
9528
|
+
let _v25_event_sink = null;
|
|
9529
|
+
const _v25_prov_stats = { to_document: 0, to_sink: 0, dropped: 0, sink_errors: 0 };
|
|
9530
|
+
|
|
9531
|
+
function setEventSink(fn) {
|
|
9532
|
+
if (fn !== null && fn !== undefined && typeof fn !== 'function') {
|
|
9533
|
+
throw _v25_buildNacError('invalid',
|
|
9534
|
+
'NAC.setEventSink: expects a function or null');
|
|
9535
|
+
}
|
|
9536
|
+
_v25_event_sink = (typeof fn === 'function') ? fn : null;
|
|
9537
|
+
return _v25_event_sink;
|
|
9538
|
+
}
|
|
9539
|
+
|
|
9540
|
+
function eventSink() { return _v25_event_sink; }
|
|
9541
|
+
|
|
9542
|
+
/* Is a provenance row observable by anybody at all right now? Two
|
|
9543
|
+
buses, and the answer is the OR of them. */
|
|
9544
|
+
function _v25_provObservable() {
|
|
9545
|
+
const hasDoc = (typeof document !== 'undefined' && !!document && !!document.dispatchEvent);
|
|
9546
|
+
return hasDoc || !!_v25_event_sink;
|
|
9547
|
+
}
|
|
9548
|
+
|
|
9549
|
+
function provenanceStatus() {
|
|
9550
|
+
return {
|
|
9551
|
+
document: (typeof document !== 'undefined' && !!document && !!document.dispatchEvent),
|
|
9552
|
+
sink: !!_v25_event_sink,
|
|
9553
|
+
observable: _v25_provObservable(),
|
|
9554
|
+
to_document: _v25_prov_stats.to_document,
|
|
9555
|
+
to_sink: _v25_prov_stats.to_sink,
|
|
9556
|
+
/* A row nobody received. Counted instead of swallowed: outside
|
|
9557
|
+
the headless profile the runtime does not refuse the call, so
|
|
9558
|
+
the loss has to be READABLE or it is still silent. */
|
|
9559
|
+
dropped: _v25_prov_stats.dropped,
|
|
9560
|
+
/* A sink that threw. The row is gone and the call is not undone;
|
|
9561
|
+
what the runtime owes the caller is the count, not a retry. */
|
|
9562
|
+
sink_errors: _v25_prov_stats.sink_errors,
|
|
9563
|
+
};
|
|
9564
|
+
}
|
|
9565
|
+
|
|
9566
|
+
function _v25_noDocument(backend) {
|
|
9567
|
+
if (typeof document !== 'undefined' && document) return null;
|
|
9568
|
+
return _v25_buildNacError('no_document',
|
|
9569
|
+
'backend "' + backend + '" needs a document: it ' +
|
|
9570
|
+
(_V25_DOM_REASON[backend] || 'reads the DOM') +
|
|
9571
|
+
'. With no document there is nothing to reach -- declare a DOM-free ' +
|
|
9572
|
+
'backend (sdk-call, emitter-listen) or run this plugin where a document exists ' +
|
|
9573
|
+
'(SPEC sec 19.1).',
|
|
9574
|
+
{ backend: backend });
|
|
9575
|
+
}
|
|
9576
|
+
|
|
9577
|
+
/* Classify ONE binding. Returns null when it is DOM-free, or the row
|
|
9578
|
+
that goes into profile().dom_required when it is not. */
|
|
9579
|
+
function _v25_bindingDomNeed(kind, path, binding, entry, seen) {
|
|
9580
|
+
const backend = (binding && binding.backend) || null;
|
|
9581
|
+
const free = backend ? _V25_DOM_FREE_BACKENDS[backend] : undefined;
|
|
9582
|
+
if (free === true) return null;
|
|
9583
|
+
if (free === 'inherits') {
|
|
9584
|
+
/* synthetic-poll is DOM-free exactly when every state path it
|
|
9585
|
+
observes is. Recursion is depth-guarded: a manifest may name
|
|
9586
|
+
the same state from two events. */
|
|
9587
|
+
const observe = Array.isArray(binding.observe) ? binding.observe : [];
|
|
9588
|
+
for (let i = 0; i < observe.length; i++) {
|
|
9589
|
+
const sp = observe[i];
|
|
9590
|
+
const key = 'state:' + sp;
|
|
9591
|
+
if (seen[key]) continue;
|
|
9592
|
+
seen[key] = true;
|
|
9593
|
+
const chain = (entry.state && entry.state[sp]) || null;
|
|
9594
|
+
if (!chain || !chain.length) {
|
|
9595
|
+
return { kind: kind, path: path, backend: backend, observes: sp,
|
|
9596
|
+
why: 'observes the state path "' + sp + '", which this manifest does not declare' };
|
|
9597
|
+
}
|
|
9598
|
+
for (let j = 0; j < chain.length; j++) {
|
|
9599
|
+
const need = _v25_bindingDomNeed('state', sp, chain[j], entry, seen);
|
|
9600
|
+
if (need) {
|
|
9601
|
+
return { kind: kind, path: path, backend: backend, observes: sp,
|
|
9602
|
+
why: 'observes the state path "' + sp + '", which needs a document: ' + need.why };
|
|
9603
|
+
}
|
|
9604
|
+
}
|
|
9605
|
+
}
|
|
9606
|
+
return null;
|
|
9607
|
+
}
|
|
9608
|
+
return {
|
|
9609
|
+
kind: kind, path: path, backend: backend,
|
|
9610
|
+
why: backend
|
|
9611
|
+
? 'the ' + backend + ' backend ' + (_V25_DOM_REASON[backend] || 'reads the DOM')
|
|
9612
|
+
: 'the binding declares no backend',
|
|
9613
|
+
};
|
|
9614
|
+
}
|
|
9615
|
+
|
|
9616
|
+
/* Every binding of a plugin that would need a document. The state
|
|
9617
|
+
chain is checked WHOLE and not just its first link: a chain whose
|
|
9618
|
+
fallback is a dom-mirror works in a browser and degrades to
|
|
9619
|
+
nothing without one, which is a declaration error in a profile
|
|
9620
|
+
whose entire claim is that no page is needed. */
|
|
9621
|
+
function _v25_domRequired(entry) {
|
|
9622
|
+
const out = [];
|
|
9623
|
+
const seen = {};
|
|
9624
|
+
const verbPaths = Object.keys(entry.verbs || {}).sort();
|
|
9625
|
+
for (let i = 0; i < verbPaths.length; i++) {
|
|
9626
|
+
const need = _v25_bindingDomNeed('verb', verbPaths[i], entry.verbs[verbPaths[i]], entry, seen);
|
|
9627
|
+
if (need) out.push(need);
|
|
9628
|
+
}
|
|
9629
|
+
const statePaths = Object.keys(entry.state || {}).sort();
|
|
9630
|
+
for (let i = 0; i < statePaths.length; i++) {
|
|
9631
|
+
const chain = entry.state[statePaths[i]] || [];
|
|
9632
|
+
for (let j = 0; j < chain.length; j++) {
|
|
9633
|
+
const need = _v25_bindingDomNeed('state', statePaths[i], chain[j], entry, seen);
|
|
9634
|
+
if (need) { need.binding_index = j; out.push(need); }
|
|
9635
|
+
}
|
|
9636
|
+
}
|
|
9637
|
+
const eventPaths = Object.keys(entry.events || {}).sort();
|
|
9638
|
+
for (let i = 0; i < eventPaths.length; i++) {
|
|
9639
|
+
const need = _v25_bindingDomNeed('event', eventPaths[i], entry.events[eventPaths[i]], entry, seen);
|
|
9640
|
+
if (need) out.push(need);
|
|
9641
|
+
}
|
|
9642
|
+
return out;
|
|
9643
|
+
}
|
|
9644
|
+
|
|
9645
|
+
/* The public predicate. Answers for ANY registered plugin, declared
|
|
9646
|
+
or not: an agent can discover that a manifest written without the
|
|
9647
|
+
profile in mind happens to be operable with no page. */
|
|
9648
|
+
function profile(slug) {
|
|
9649
|
+
if (typeof slug !== 'string' || !slug) {
|
|
9650
|
+
throw _v25_buildNacError('invalid', 'NAC.profile: slug must be a non-empty string');
|
|
9651
|
+
}
|
|
9652
|
+
const entry = _v25_plugins[slug];
|
|
9653
|
+
if (!entry) {
|
|
9654
|
+
throw _v25_buildNacError('plugin_not_registered',
|
|
9655
|
+
'NAC.profile: plugin "' + slug + '" not registered');
|
|
9656
|
+
}
|
|
9657
|
+
const dom_required = _v25_domRequired(entry);
|
|
9658
|
+
return {
|
|
9659
|
+
slug: slug,
|
|
9660
|
+
declared_headless: !!entry.headless,
|
|
9661
|
+
headless: dom_required.length === 0,
|
|
9662
|
+
dom_required: _v25_copy(dom_required) || [],
|
|
9663
|
+
};
|
|
9664
|
+
}
|
|
9665
|
+
|
|
9666
|
+
/* The gate the profile buys: inside it, an unobservable call is
|
|
9667
|
+
refused BEFORE the effect. Outside it nothing changes -- which is
|
|
9668
|
+
why the profile is opt-in and not inferred. */
|
|
9669
|
+
function _v25_provGate(op, plugin, entry) {
|
|
9670
|
+
if (!entry || !entry.headless) return null;
|
|
9671
|
+
if (_v25_provObservable()) return null;
|
|
9672
|
+
return _v25_buildNacError('provenance_unobservable',
|
|
9673
|
+
'NAC.' + op + ': plugin "' + plugin + '" declares headless: true and there is ' +
|
|
9674
|
+
'neither a document nor an event sink, so its nac:plugin:* row would be dropped. ' +
|
|
9675
|
+
'Install one with NAC.setEventSink(fn) before driving a headless surface ' +
|
|
9676
|
+
'(SPEC sec 19.4).',
|
|
9677
|
+
{ plugin: plugin });
|
|
9678
|
+
}
|
|
9679
|
+
|
|
7492
9680
|
/* Provenance emit helper -- the kind is one of 'invoked', 'read',
|
|
7493
9681
|
'event'. Detail shape per SPEC.md sec 15.7. */
|
|
7494
9682
|
function _v25_emitProvenance(kind, plugin, path, backend, request_id, ok, error, duration_ms, extra) {
|
|
@@ -7496,8 +9684,11 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7496
9684
|
plugin: plugin,
|
|
7497
9685
|
backend: backend || null,
|
|
7498
9686
|
request_id: request_id,
|
|
7499
|
-
|
|
7500
|
-
|
|
9687
|
+
/* 2.7.0 (TF-A19): sec 15.7 publishes 'agent' as the DEFAULT and
|
|
9688
|
+
an override through NAC.set_source. _dispatchSource holds
|
|
9689
|
+
exactly that default until a host says otherwise. */
|
|
9690
|
+
source: _dispatchSource.source,
|
|
9691
|
+
trusted: _dispatchSource.trusted,
|
|
7501
9692
|
duration_ms: duration_ms,
|
|
7502
9693
|
ok: !!ok,
|
|
7503
9694
|
error: error || null,
|
|
@@ -7508,9 +9699,29 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7508
9699
|
if (extra) {
|
|
7509
9700
|
for (const k in extra) detail[k] = extra[k];
|
|
7510
9701
|
}
|
|
9702
|
+
/* 2.7.0 (sec 19.4): TWO buses, and a row that reached neither is
|
|
9703
|
+
COUNTED. Before this the dispatch was a lone try/catch, so with
|
|
9704
|
+
no document the row disappeared and nothing anywhere said so. */
|
|
9705
|
+
const type = 'nac:plugin:' + kind;
|
|
9706
|
+
let delivered = false;
|
|
7511
9707
|
try {
|
|
7512
|
-
document.dispatchEvent(new CustomEvent(
|
|
7513
|
-
|
|
9708
|
+
document.dispatchEvent(new CustomEvent(type, { detail: detail, bubbles: true }));
|
|
9709
|
+
delivered = true;
|
|
9710
|
+
_v25_prov_stats.to_document++;
|
|
9711
|
+
} catch (_) { /* no document, or a document without dispatchEvent */ }
|
|
9712
|
+
if (_v25_event_sink) {
|
|
9713
|
+
try {
|
|
9714
|
+
_v25_event_sink({ type: type, detail: detail });
|
|
9715
|
+
delivered = true;
|
|
9716
|
+
_v25_prov_stats.to_sink++;
|
|
9717
|
+
} catch (_) {
|
|
9718
|
+
/* A sink that throws is a host defect. The effect already
|
|
9719
|
+
happened, so the runtime does not undo it and does not
|
|
9720
|
+
retry -- it counts the loss where a caller can read it. */
|
|
9721
|
+
_v25_prov_stats.sink_errors++;
|
|
9722
|
+
}
|
|
9723
|
+
}
|
|
9724
|
+
if (!delivered) _v25_prov_stats.dropped++;
|
|
7514
9725
|
}
|
|
7515
9726
|
|
|
7516
9727
|
function _v25_buildNacError(code, message, extra) {
|
|
@@ -7532,6 +9743,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7532
9743
|
_v25_emitProvenance('invoked', plugin, verb_path, null, request_id, false, err.message, Date.now() - t0);
|
|
7533
9744
|
return Promise.reject(err);
|
|
7534
9745
|
}
|
|
9746
|
+
const gated = _v25_provGate('call', plugin, _v25_plugins[plugin]);
|
|
9747
|
+
if (gated) return Promise.reject(gated);
|
|
7535
9748
|
const binding = _v25_plugins[plugin].verbs[verb_path];
|
|
7536
9749
|
if (!binding) {
|
|
7537
9750
|
const err = _v25_buildNacError('verb_not_declared',
|
|
@@ -7557,7 +9770,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7557
9770
|
const msg = (err && err.message) || String(err);
|
|
7558
9771
|
_v25_emitProvenance('invoked', plugin, verb_path, binding.backend, request_id, false, msg, Date.now() - t0);
|
|
7559
9772
|
if (err && err._code) {
|
|
7560
|
-
|
|
9773
|
+
/* v2.6 (hook E-6): the code has to be one the contract
|
|
9774
|
+
declares -- one of the ten of 15.9, or a plugin-owned code
|
|
9775
|
+
under the `plugin.` prefix. Anything else is `invalid` and
|
|
9776
|
+
names what it refused, instead of inventing a code the
|
|
9777
|
+
published list does not have. */
|
|
9778
|
+
if (_v25_isDeclaredCode(err._code)) {
|
|
9779
|
+
throw _v25_buildNacError(err._code, msg);
|
|
9780
|
+
}
|
|
9781
|
+
throw _v25_buildNacError('invalid',
|
|
9782
|
+
'NAC.call: backend raised the undeclared error code "' + err._code +
|
|
9783
|
+
'" (SPEC 15.9: one of the ten contract codes, or a plugin code under the "' +
|
|
9784
|
+
_V25_PLUGIN_CODE_PREFIX + '" prefix): ' + msg,
|
|
9785
|
+
{ offending_code: err._code });
|
|
7561
9786
|
}
|
|
7562
9787
|
throw err;
|
|
7563
9788
|
});
|
|
@@ -7572,6 +9797,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7572
9797
|
_v25_emitProvenance('read', plugin, state_path, null, request_id, false, err.message, Date.now() - t0);
|
|
7573
9798
|
return Promise.reject(err);
|
|
7574
9799
|
}
|
|
9800
|
+
const gated = _v25_provGate('read', plugin, _v25_plugins[plugin]);
|
|
9801
|
+
if (gated) return Promise.reject(gated);
|
|
7575
9802
|
const chain = _v25_plugins[plugin].state[state_path];
|
|
7576
9803
|
if (!chain) {
|
|
7577
9804
|
const err = _v25_buildNacError('state_not_declared',
|
|
@@ -7641,6 +9868,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7641
9868
|
throw _v25_buildNacError('plugin_not_registered',
|
|
7642
9869
|
'NAC.subscribe: plugin "' + plugin + '" not registered');
|
|
7643
9870
|
}
|
|
9871
|
+
const gated = _v25_provGate('subscribe', plugin, _v25_plugins[plugin]);
|
|
9872
|
+
if (gated) throw gated;
|
|
7644
9873
|
const binding = _v25_plugins[plugin].events[event_path];
|
|
7645
9874
|
if (!binding) {
|
|
7646
9875
|
throw _v25_buildNacError('event_not_declared',
|
|
@@ -7654,7 +9883,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7654
9883
|
let teardown;
|
|
7655
9884
|
try { teardown = subscriber(plugin, event_path, binding, cb); }
|
|
7656
9885
|
catch (e) {
|
|
7657
|
-
if (e && e._code)
|
|
9886
|
+
if (e && e._code) {
|
|
9887
|
+
if (_v25_isDeclaredCode(e._code)) throw _v25_buildNacError(e._code, e.message);
|
|
9888
|
+
throw _v25_buildNacError('invalid',
|
|
9889
|
+
'NAC.subscribe: backend raised the undeclared error code "' + e._code +
|
|
9890
|
+
'" (SPEC 15.9): ' + e.message, { offending_code: e._code });
|
|
9891
|
+
}
|
|
7658
9892
|
throw e;
|
|
7659
9893
|
}
|
|
7660
9894
|
_v25_sub_counter += 1;
|
|
@@ -7721,6 +9955,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7721
9955
|
}
|
|
7722
9956
|
|
|
7723
9957
|
function narrate(plugin, nac_id) {
|
|
9958
|
+
_nac_requireDocument('narrate');
|
|
7724
9959
|
if (typeof nac_id !== 'string' || !nac_id) return null;
|
|
7725
9960
|
/* Scope by plugin if provided -- look only inside [data-nac-plugin=plugin]
|
|
7726
9961
|
subtree. If plugin is omitted, fall back to global search. */
|
|
@@ -7733,7 +9968,27 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7733
9968
|
/* Use attribute selector with CSS-safe escape via JSON.stringify
|
|
7734
9969
|
to avoid injection when nac_id contains weird chars. */
|
|
7735
9970
|
const safeId = '"' + String(nac_id).replace(/["\\]/g, '\\$&') + '"';
|
|
7736
|
-
|
|
9971
|
+
/* The ROOT ITSELF counts (fixed 2.7.0, found by the first test
|
|
9972
|
+
this verb ever had).
|
|
9973
|
+
|
|
9974
|
+
querySelector searches DESCENDANTS, so when `plugin` was given
|
|
9975
|
+
and the asked-for id belonged to the plugin root -- the usual
|
|
9976
|
+
case, since a root normally carries both data-nac-plugin and
|
|
9977
|
+
data-nac-id -- narrate returned null. A plugin could not narrate
|
|
9978
|
+
itself.
|
|
9979
|
+
|
|
9980
|
+
It showed up through context(), whose breadcrumb walks up to and
|
|
9981
|
+
including the root and labels each entry with narrate(): the
|
|
9982
|
+
FIRST entry of every breadcrumb came back with label: null. An
|
|
9983
|
+
assistive consumer reading that breadcrumb aloud started with
|
|
9984
|
+
nothing. */
|
|
9985
|
+
let el = null;
|
|
9986
|
+
if (root !== document && root.getAttribute
|
|
9987
|
+
&& root.getAttribute('data-nac-id') === String(nac_id)) {
|
|
9988
|
+
el = root;
|
|
9989
|
+
} else {
|
|
9990
|
+
el = root.querySelector('[data-nac-id=' + safeId + ']');
|
|
9991
|
+
}
|
|
7737
9992
|
if (!el) return null;
|
|
7738
9993
|
/* 1. aria-label */
|
|
7739
9994
|
const aria = el.getAttribute('aria-label');
|
|
@@ -7772,6 +10027,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7772
10027
|
}
|
|
7773
10028
|
|
|
7774
10029
|
function context(plugin) {
|
|
10030
|
+
_nac_requireDocument('context');
|
|
7775
10031
|
const out = { breadcrumb: [] };
|
|
7776
10032
|
const root = _v25b_pluginRoot(plugin);
|
|
7777
10033
|
if (!root) return out;
|
|
@@ -7830,6 +10086,28 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7830
10086
|
Both delegate to NAC.read() so they inherit V25-01's full
|
|
7831
10087
|
fallback-chain semantics for free. */
|
|
7832
10088
|
|
|
10089
|
+
/* A value rendered for a human, that cannot throw. JSON.stringify
|
|
10090
|
+
fails on a cycle and on a DOM node it returns '{}', neither of
|
|
10091
|
+
which helps a reader; a DOM node is named by what it is. */
|
|
10092
|
+
function _v25_renderValue(v) {
|
|
10093
|
+
if (v === undefined) return 'undefined';
|
|
10094
|
+
if (v === null) return 'null';
|
|
10095
|
+
if (typeof v === 'string') return JSON.stringify(v);
|
|
10096
|
+
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
|
|
10097
|
+
if (v && v.nodeType === 1 && typeof v.getAttribute === 'function') {
|
|
10098
|
+
const id = v.getAttribute('data-nac-id');
|
|
10099
|
+
return '<' + String(v.tagName || 'element').toLowerCase()
|
|
10100
|
+
+ (id ? ' data-nac-id="' + id + '"' : '') + '>'
|
|
10101
|
+
+ ' -- a DOM element: the binding has no `extract`, so it resolved the node itself';
|
|
10102
|
+
}
|
|
10103
|
+
try {
|
|
10104
|
+
const out = JSON.stringify(v);
|
|
10105
|
+
return out === undefined ? String(v) : out;
|
|
10106
|
+
} catch (e) {
|
|
10107
|
+
return '[unserialisable ' + (typeof v) + ': ' + (e && e.message ? e.message : 'cycle') + ']';
|
|
10108
|
+
}
|
|
10109
|
+
}
|
|
10110
|
+
|
|
7833
10111
|
function expect(plugin, statePath, value, opts) {
|
|
7834
10112
|
opts = opts || {};
|
|
7835
10113
|
const timeout = (typeof opts.timeout_ms === 'number') ? opts.timeout_ms : 5000;
|
|
@@ -7846,9 +10124,23 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7846
10124
|
catch (_) { matches = false; }
|
|
7847
10125
|
if (matches) { resolve(cur); return; }
|
|
7848
10126
|
if (Date.now() >= deadline) {
|
|
10127
|
+
/* The last value is rendered DEFENSIVELY (fixed 2.7.0,
|
|
10128
|
+
found by the first test this verb ever had).
|
|
10129
|
+
|
|
10130
|
+
It used to be a bare JSON.stringify(cur), and `cur` is
|
|
10131
|
+
whatever the host's state binding returned -- a
|
|
10132
|
+
dom-mirror binding with no extractor returns the ELEMENT
|
|
10133
|
+
itself, and app state can hold a reference cycle. On
|
|
10134
|
+
either of those, expect() threw a TypeError out of its
|
|
10135
|
+
own timeout path instead of rejecting with the timeout
|
|
10136
|
+
it promises, so the caller got "Converting circular
|
|
10137
|
+
structure to JSON" from inside a verb that was supposed
|
|
10138
|
+
to tell them their state never matched.
|
|
10139
|
+
An error path that can itself throw is worse than a
|
|
10140
|
+
vague message. */
|
|
7849
10141
|
reject(_v25_buildNacError('timeout',
|
|
7850
10142
|
'NAC.expect: state "' + statePath + '" did not match within ' +
|
|
7851
|
-
timeout + 'ms (last value: ' +
|
|
10143
|
+
timeout + 'ms (last value: ' + _v25_renderValue(cur) + ')'));
|
|
7852
10144
|
return;
|
|
7853
10145
|
}
|
|
7854
10146
|
setTimeout(tick, pollMs);
|
|
@@ -7891,6 +10183,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7891
10183
|
}
|
|
7892
10184
|
|
|
7893
10185
|
function tree(plugin, rootId) {
|
|
10186
|
+
_nac_requireDocument('tree');
|
|
7894
10187
|
const pluginRoot = _v25b_pluginRoot(plugin);
|
|
7895
10188
|
if (!pluginRoot) return [];
|
|
7896
10189
|
let start = pluginRoot;
|
|
@@ -7922,8 +10215,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7922
10215
|
|
|
7923
10216
|
global.NAC = {
|
|
7924
10217
|
__nac_v1_installed: true,
|
|
7925
|
-
version: '2.
|
|
7926
|
-
spec_version: '2.
|
|
10218
|
+
version: '2.8.0',
|
|
10219
|
+
spec_version: '2.8',
|
|
7927
10220
|
/* v2.2.0 (V22-01) -- strict validation toggle. When true,
|
|
7928
10221
|
NAC.register throws on findings (manifest_role_unknown,
|
|
7929
10222
|
tab_id_manifest_role_drift, manifest_dom_role_mismatch).
|
|
@@ -7937,7 +10230,18 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7937
10230
|
on the first slug uniqueness violation; the boot-time pass
|
|
7938
10231
|
paints a red banner + dispatches nac:fatal. Set false BEFORE
|
|
7939
10232
|
any register() call to opt out for a single migration window.
|
|
7940
|
-
|
|
10233
|
+
|
|
10234
|
+
2.7.0 (TF-A13) -- "The flag is removed in v2.6 (enforcement
|
|
10235
|
+
becomes unconditional)" is what this comment said while running
|
|
10236
|
+
INSIDE 2.6 with the flag present and consulted in four places.
|
|
10237
|
+
The removal is WITHDRAWN (D-13, owner delegation of
|
|
10238
|
+
2026-11-24), for two measured reasons: a host that set it false
|
|
10239
|
+
to get through a migration would start throwing on upgrade with
|
|
10240
|
+
no code change of its own -- the plainest form of breaking an
|
|
10241
|
+
adopter -- and the escape hatch is load-bearing in this
|
|
10242
|
+
repository too (runtime/test/stage11-plugin-id-dedup.mjs drives
|
|
10243
|
+
the opt-out path). The hatch is PERMANENT. What stays true is
|
|
10244
|
+
the default: enforcement is on unless a host says otherwise. */
|
|
7941
10245
|
HARD_DEDUP: true,
|
|
7942
10246
|
/* registry */
|
|
7943
10247
|
register: register,
|
|
@@ -7966,10 +10270,64 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
7966
10270
|
verb (click/fill/select/invoke/tab/tab_by_label) honours the
|
|
7967
10271
|
gate, so STRICT_VERSIONING default flips to true: callers
|
|
7968
10272
|
MUST pass at least one expected_* or set STRICT_VERSIONING
|
|
7969
|
-
=false explicitly.
|
|
10273
|
+
=false explicitly.
|
|
10274
|
+
|
|
10275
|
+
2.7.0 (TF-A13) -- "Removed in v2.6 (becomes unconditional)" was
|
|
10276
|
+
written here and is withdrawn (D-13, owner delegation of
|
|
10277
|
+
2026-11-24), same reasoning as HARD_DEDUP above and one more
|
|
10278
|
+
that is specific to this one: made unconditional, every caller
|
|
10279
|
+
of every mutating verb MUST carry an expected_* snapshot, so an
|
|
10280
|
+
adopter driving click() without optimistic concurrency stops
|
|
10281
|
+
working on upgrade. The flag is PERMANENT and the default stays
|
|
10282
|
+
true. runtime/test/stage12-snapshot-versioning.mjs drives both
|
|
10283
|
+
sides of it. */
|
|
7970
10284
|
STRICT_VERSIONING: true,
|
|
7971
10285
|
eager_hashing: false,
|
|
7972
|
-
|
|
10286
|
+
/* v2.4 (RFC V24-04 sec 5.11) -- the runtime's self-described tier.
|
|
10287
|
+
|
|
10288
|
+
A TIER IS NOT A LEVEL, and that distinction is the whole point
|
|
10289
|
+
of this comment. There are two taxonomies in this project and
|
|
10290
|
+
their names look alike:
|
|
10291
|
+
|
|
10292
|
+
- a conformance TIER is what the RUNTIME supports, and the
|
|
10293
|
+
vocabulary is RFC V24-04 sec 6: 'NAC-3' (no versioning),
|
|
10294
|
+
'NAC-3-versioned' (honours expected_*), 'NAC-3-strict'. An
|
|
10295
|
+
agent reads it at boot to decide what it may send.
|
|
10296
|
+
- a conformance LEVEL is what a PAGE achieves, and the
|
|
10297
|
+
vocabulary is SPEC.md sec 8. `nac validate <url> --drive`
|
|
10298
|
+
reports one.
|
|
10299
|
+
|
|
10300
|
+
The published catalogue has said so in machine-readable form
|
|
10301
|
+
since 2.5.0 (audit N-29: until then api/ published this field as
|
|
10302
|
+
`type: "string"` and not its values, so a machine could see the
|
|
10303
|
+
field with no way to learn that 'NAC-3-versioned' is not a level
|
|
10304
|
+
name). The runtime export itself said nothing, which left the
|
|
10305
|
+
clarification only where a human was least likely to be
|
|
10306
|
+
reading. Now it is next to the value.
|
|
10307
|
+
|
|
10308
|
+
DEFAULT_CONFORMANCE_TIER is read, not retyped: the tier reject
|
|
10309
|
+
in the versioning gate used to carry its own copy of this
|
|
10310
|
+
string literal, which is audit N-17's shape in miniature. */
|
|
10311
|
+
conformance_tier: DEFAULT_CONFORMANCE_TIER,
|
|
10312
|
+
/* v2.7.0 (TF-A01). The selector drag_drop() removes from INSIDE a
|
|
10313
|
+
drop target before dropping. null = remove nothing, which is
|
|
10314
|
+
the default because a library may not delete a node out of a
|
|
10315
|
+
document it did not write. A target can override it with
|
|
10316
|
+
data-nac-drop-placeholder, which wins over this. */
|
|
10317
|
+
drop_placeholder_selector: null,
|
|
10318
|
+
/* v2.7.0 (TF-A02). The settle delay of drag_drop(), in ms. 80 is
|
|
10319
|
+
what this repository's demo UX needed and what every adopter
|
|
10320
|
+
paid; it stays the default so no existing drop changes timing,
|
|
10321
|
+
and opts.settle_ms overrides it per call. */
|
|
10322
|
+
drag_settle_ms: 80,
|
|
10323
|
+
/* v2.7.0 (TF-A11). Where the editor's "fix my grammar" control
|
|
10324
|
+
POSTs the text being edited. null = the feature is off and
|
|
10325
|
+
nothing is sent; the control reports that instead of guessing a
|
|
10326
|
+
path. It lives on THIS export on purpose: the only way to
|
|
10327
|
+
change it used to be a field of nac-chat-client.js, so an
|
|
10328
|
+
adopter loading the runtime alone could neither redirect it nor
|
|
10329
|
+
switch it off. */
|
|
10330
|
+
editor_ai_endpoint: null,
|
|
7973
10331
|
markHydrationComplete: markHydrationComplete,
|
|
7974
10332
|
versionHistory: versionHistory,
|
|
7975
10333
|
/* v2.3 preview (V23-02): introspection helper that returns the
|
|
@@ -8008,6 +10366,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
8008
10366
|
list: list,
|
|
8009
10367
|
find: find,
|
|
8010
10368
|
read_feedback: read_feedback,
|
|
10369
|
+
/* v2.8.0 -- the role vocabulary, and the door into it. */
|
|
10370
|
+
roles: roles,
|
|
10371
|
+
canonical_role: canonical_role,
|
|
10372
|
+
register_role: register_role,
|
|
8011
10373
|
snapshot_state: snapshot_state,
|
|
8012
10374
|
/* write */
|
|
8013
10375
|
click: click,
|
|
@@ -8149,6 +10511,17 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
8149
10511
|
/* v1.9.0 -- provenance authenticity (sec 6.2.1) */
|
|
8150
10512
|
sign_provenance: sign_provenance,
|
|
8151
10513
|
verify_provenance: verify_provenance,
|
|
10514
|
+
/* 2.7.0 -- manifest authenticity (sec 7.2). set_manifest_secret
|
|
10515
|
+
is the core entry point; NAC.set_provenance_secret in the
|
|
10516
|
+
extensions module forwards here so the example published in
|
|
10517
|
+
7.2 works as written. */
|
|
10518
|
+
set_manifest_secret: set_manifest_secret,
|
|
10519
|
+
sign_manifest: sign_manifest,
|
|
10520
|
+
verify_manifest: verify_manifest,
|
|
10521
|
+
manifest_provenance: manifest_provenance,
|
|
10522
|
+
/* 2.7.0 -- dispatch provenance override (sec 15.7) */
|
|
10523
|
+
set_source: set_source,
|
|
10524
|
+
get_source: get_source,
|
|
8152
10525
|
/* v1.9.0 -- recommended remediation (sec 6.2.30) */
|
|
8153
10526
|
recommended_remediation: recommended_remediation,
|
|
8154
10527
|
/* v1.2 -- error codes */
|
|
@@ -8173,6 +10546,27 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
8173
10546
|
read: read,
|
|
8174
10547
|
subscribe: subscribe,
|
|
8175
10548
|
unsubscribe: unsubscribe,
|
|
10549
|
+
/* v2.6 -- the six hooks of RFC V26-01 (SPEC.md sec 15.10 / 15.11).
|
|
10550
|
+
plugins() + describePlugin() make the registry discoverable, so
|
|
10551
|
+
a plugin living in another repository under another licence can
|
|
10552
|
+
be FOUND by an agent that did not register it; registerApiHandle
|
|
10553
|
+
lets a manifest route to an API object that never lands on
|
|
10554
|
+
window (a React ref, a library instance held in a closure). */
|
|
10555
|
+
plugins: plugins,
|
|
10556
|
+
describePlugin: describePlugin,
|
|
10557
|
+
/* v2.7 -- the headless profile (SPEC.md sec 19 / decision D-26).
|
|
10558
|
+
profile() says whether a registered plugin needs a document at
|
|
10559
|
+
all; setEventSink() carries the nac:plugin:* family over a bus
|
|
10560
|
+
that is not the DOM, so a screenless host keeps its provenance;
|
|
10561
|
+
provenanceStatus() makes the delivery -- and any loss --
|
|
10562
|
+
readable instead of swallowed. */
|
|
10563
|
+
profile: profile,
|
|
10564
|
+
setEventSink: setEventSink,
|
|
10565
|
+
eventSink: eventSink,
|
|
10566
|
+
provenanceStatus: provenanceStatus,
|
|
10567
|
+
registerApiHandle: registerApiHandle,
|
|
10568
|
+
unregisterApiHandle: unregisterApiHandle,
|
|
10569
|
+
apiHandles: apiHandles,
|
|
8176
10570
|
/* v2.5 Block C -- assistive labels (SPEC.md sec 17 / RFC V25-03).
|
|
8177
10571
|
Canonical human-readable label resolution for screen readers,
|
|
8178
10572
|
TTS, voice flows, audit logs. Priority order: aria-label >
|