@nac3/runtime 2.9.0 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nac.mjs 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.9.0', spec_version: '2.9'`
10
+ bottom of this file. `version: '2.9.1', spec_version: '2.9'`
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.
@@ -344,14 +344,54 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
344
344
  So they refuse by name. The headless profile (sec 19) is the other
345
345
  half of the same rule: a surface with no document is reached
346
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',
347
+ /* ONE producer of the refusal. Two consumers: the primitives that
348
+ call the guard inline since 2.7.0, and the install-time pass at the
349
+ bottom of this file that applies it to the rest of the family
350
+ (2.9.1). A second copy of this message would be a second answer to
351
+ "what does the contract say when there is no document". */
352
+ function _nac_noDocumentError(where) {
353
+ return NacError('no_document',
350
354
  'NAC.' + where + ': no document in this context, so there is no node to resolve. ' +
351
355
  'Reach a declared surface through the extension contract -- NAC.call / NAC.read / ' +
352
356
  'NAC.subscribe (SPEC sec 15) -- and see the headless profile (SPEC sec 19).',
353
357
  { primitive: where });
354
358
  }
359
+ function _nac_requireDocument(where) {
360
+ if (typeof document !== 'undefined' && document) return;
361
+ throw _nac_noDocumentError(where);
362
+ }
363
+
364
+ /* 2.9.1 -- escape a value that is about to be interpolated into a
365
+ QUOTED attribute selector: [data-nac-id="<value>"].
366
+
367
+ WHY. Every id the runtime resolves arrives from outside -- the
368
+ adopter's markup or the agent's call -- and went straight into the
369
+ selector string. A nac_id carrying a double quote closed the string
370
+ and the browser answered with a raw DOMException ("is not a valid
371
+ selector") where the contract promises not_found; a comma could
372
+ continue the selector LIST and resolve a different element. Neither
373
+ is XSS -- a selector does not execute -- but both are an unsanitised
374
+ value reaching a sink, and one of them is a crash where a code was
375
+ promised.
376
+
377
+ Inside a quoted CSS string only two characters can break out, the
378
+ backslash and the quote itself, so those two are escaped and
379
+ nothing else is touched: a dot stays a dot, which matters because
380
+ every NAC id has them. A raw newline is invalid inside a CSS string,
381
+ so it travels as a numeric escape (the trailing space ends it).
382
+
383
+ Deliberately NOT CSS.escape(): that one escapes a value for use as
384
+ an IDENTIFIER, so it backslashes every dot in every id. The only
385
+ escaper this tree had (cssEscape in js/tester-report.js) does the
386
+ same, which is why the runtime could not borrow it. */
387
+ function _nac_attrValue(value) {
388
+ return String(value)
389
+ .replace(/[\\"]/g, function (c) { return '\\' + c; })
390
+ .replace(/[\n\r\f]/g, function (c) {
391
+ return '\\' + c.charCodeAt(0).toString(16) + ' ';
392
+ });
393
+ }
394
+
355
395
 
356
396
  /* ================================================================
357
397
  v2.5 / RFC V24-01: Plugin slug uniqueness gate (spec sec 7.4)
@@ -1938,7 +1978,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
1938
1978
  data-nac-role MUST match. Skip when DOM is not yet ready
1939
1979
  (a deferred check runs on DOMContentLoaded). */
1940
1980
  if (typeof document !== 'undefined' && document.body) {
1941
- const domEl = document.querySelector('[data-nac-id="' + id + '"]');
1981
+ const domEl = document.querySelector('[data-nac-id="' + _nac_attrValue(id) + '"]');
1942
1982
  if (domEl) {
1943
1983
  const domRole = domEl.getAttribute('data-nac-role');
1944
1984
  if (domRole && role && domRole !== role) {
@@ -2299,7 +2339,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2299
2339
 
2300
2340
  function edit_field(field_nac_id) {
2301
2341
  if (!field_nac_id) throw NacError('invalid', 'edit_field requires a nac_id');
2302
- const sourceEl = document.querySelector('[data-nac-id="' + field_nac_id + '"]');
2342
+ const sourceEl = document.querySelector('[data-nac-id="' + _nac_attrValue(field_nac_id) + '"]');
2303
2343
  if (!sourceEl) throw NacError('not_found', 'edit_field: ' + field_nac_id + ' not in DOM');
2304
2344
  if (sourceEl.tagName !== 'INPUT' && sourceEl.tagName !== 'TEXTAREA' && !sourceEl.isContentEditable) {
2305
2345
  throw NacError('invalid', 'edit_field: ' + field_nac_id + ' is not an editable widget');
@@ -2323,7 +2363,18 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2323
2363
 
2324
2364
  const head = document.createElement('div');
2325
2365
  head.className = 'nac-editor-head';
2326
- head.innerHTML = '<span class="title">Editing ' + field_nac_id + '</span>';
2366
+ /* 2.9.1 -- the title carries the nac_id, and a nac_id is adopter
2367
+ data: ids built from user-supplied text ("row." + title) are the
2368
+ pattern the spec asks for. Through innerHTML that made the EDITOR
2369
+ the one primitive that executed its own argument -- a stored XSS
2370
+ reachable by the contract's happy path. The two other dialog
2371
+ builders in this file never did: toast() writes textContent and
2372
+ confirm_dialog() escapes. Same node, same class, text instead of
2373
+ markup. */
2374
+ const headTitle = document.createElement('span');
2375
+ headTitle.className = 'title';
2376
+ headTitle.textContent = 'Editing ' + field_nac_id;
2377
+ head.appendChild(headTitle);
2327
2378
  modal.appendChild(head);
2328
2379
 
2329
2380
  const toolbar = document.createElement('div');
@@ -2728,7 +2779,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
2728
2779
  /* Wait for the plugin root to mount, then apply.
2729
2780
  Some plugins register before their DOM is mounted. */
2730
2781
  function apply() {
2731
- const root = document.querySelector('[data-nac-plugin="' + slug + '"]');
2782
+ const root = document.querySelector('[data-nac-plugin="' + _nac_attrValue(slug) + '"]');
2732
2783
  if (!root) {
2733
2784
  /* Try once after DOMContentLoaded if root is not yet in DOM. */
2734
2785
  if (document.readyState === 'loading') {
@@ -3242,8 +3293,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
3242
3293
  action: el.getAttribute('data-nac-action') || null,
3243
3294
  error: el.getAttribute('data-nac-error') || null,
3244
3295
  label: el.getAttribute('aria-label')
3245
- || (el.id && document.querySelector('label[for="' + el.id + '"]')
3246
- ? document.querySelector('label[for="' + el.id + '"]').textContent.trim()
3296
+ || (el.id && document.querySelector('label[for="' + _nac_attrValue(el.id) + '"]')
3297
+ ? document.querySelector('label[for="' + _nac_attrValue(el.id) + '"]').textContent.trim()
3247
3298
  : null)
3248
3299
  /* Fallback for KPI/feedback/static elements: look for an
3249
3300
  inner labeled child by convention. Resolves the case
@@ -4152,13 +4203,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4152
4203
  /* Field-change events fire on the parent field when an option
4153
4204
  is clicked; resolve those too. */
4154
4205
  if (e.type === 'nac:field:changed' && d && d.nac_id) {
4155
- var parentField = el.closest('[data-nac-id="' + d.nac_id + '"]');
4206
+ var parentField = el.closest('[data-nac-id="' + _nac_attrValue(d.nac_id) + '"]');
4156
4207
  if (parentField) return true;
4157
4208
  /* Or: the element is a descendant of an element whose nac_id
4158
4209
  matches the field that fired. */
4159
4210
  var fieldHost = document.querySelector(
4160
- '[data-nac-role="field"][data-nac-id="' + d.nac_id + '"], ' +
4161
- '[data-nac-role="combobox"][data-nac-id="' + d.nac_id + '"]');
4211
+ '[data-nac-role="field"][data-nac-id="' + _nac_attrValue(d.nac_id) + '"], ' +
4212
+ '[data-nac-role="combobox"][data-nac-id="' + _nac_attrValue(d.nac_id) + '"]');
4162
4213
  if (fieldHost && fieldHost.contains(el)) return true;
4163
4214
  /* v1.6.4-v1.6.5: combobox option click. The host's option
4164
4215
  click handler emits nac:field:changed on the parent field
@@ -4182,7 +4233,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4182
4233
  ? optPluginNode.getAttribute('data-nac-plugin') : null;
4183
4234
  }
4184
4235
  var fieldElForPlugin = document.querySelector(
4185
- '[data-nac-id="' + d.nac_id + '"]');
4236
+ '[data-nac-id="' + _nac_attrValue(d.nac_id) + '"]');
4186
4237
  var fieldPluginNode = fieldElForPlugin
4187
4238
  ? fieldElForPlugin.closest('[data-nac-plugin]') : null;
4188
4239
  var fieldPluginSlug = fieldPluginNode
@@ -4357,8 +4408,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4357
4408
  }
4358
4409
  /* Non-native select widget: try clicking the option element. */
4359
4410
  const root = el.closest('[data-nac-plugin]') || document;
4360
- const opt = root.querySelector('[data-nac-id="' + nac_id + '.' + option + '"]')
4361
- || root.querySelector('[data-nac-id="' + option + '"]');
4411
+ const opt = root.querySelector('[data-nac-id="' + _nac_attrValue(nac_id) + '.' + _nac_attrValue(option) + '"]')
4412
+ || root.querySelector('[data-nac-id="' + _nac_attrValue(option) + '"]');
4362
4413
  if (opt) { _focusElement(opt); opt.click(); return { ok: true }; }
4363
4414
  throw NacError('not_found', 'option ' + option + ' not present in ' + nac_id);
4364
4415
  }
@@ -4387,7 +4438,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4387
4438
  if (tab_key === undefined && typeof plugin === 'string' && plugin.indexOf('.') >= 0) {
4388
4439
  const bareId = plugin;
4389
4440
  let tabEl = document.querySelector(
4390
- '[data-nac-role="tab"][data-nac-id="' + bareId + '"]'
4441
+ '[data-nac-role="tab"][data-nac-id="' + _nac_attrValue(bareId) + '"]'
4391
4442
  );
4392
4443
  /* H1.v7 (2026-05-21): strict resolution. If the bare id is not
4393
4444
  in DOM, try the qualified-instance fallback ONLY when the
@@ -4464,10 +4515,10 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4464
4515
  try { await wait_for('nac:tab:changed', 1500); } catch (e) { /* tolerated */ }
4465
4516
  return { ok: true };
4466
4517
  }
4467
- const root = document.querySelector('[data-nac-plugin="' + plugin + '"]');
4518
+ const root = document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin) + '"]');
4468
4519
  if (!root) throw NacError('not_found', 'plugin ' + plugin + ' not mounted');
4469
4520
  const tabEl = root.querySelector(
4470
- '[data-nac-role="tab"][data-nac-id="' + tab_key + '"]'
4521
+ '[data-nac-role="tab"][data-nac-id="' + _nac_attrValue(tab_key) + '"]'
4471
4522
  );
4472
4523
  if (!tabEl) throw NacError('not_found', 'tab ' + tab_key + ' missing');
4473
4524
  /* v2.5 V24-04 OCC gate (two-arg path). */
@@ -4537,14 +4588,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4537
4588
  Fall through to the DOM scan so we pick whichever qualified
4538
4589
  instance is actually mounted. */
4539
4590
  if (matched && matched.nac_id) {
4540
- const probe = document.querySelector('[data-nac-id="' + matched.nac_id + '"]');
4591
+ const probe = document.querySelector('[data-nac-id="' + _nac_attrValue(matched.nac_id) + '"]');
4541
4592
  if (!probe) matched = null;
4542
4593
  }
4543
4594
 
4544
4595
  if (!matched) {
4545
4596
  /* Fallback: scan DOM within plugin scope for [data-nac-action]. */
4546
4597
  const root = targetPlugin
4547
- ? document.querySelector('[data-nac-plugin="' + targetPlugin + '"]')
4598
+ ? document.querySelector('[data-nac-plugin="' + _nac_attrValue(targetPlugin) + '"]')
4548
4599
  : document;
4549
4600
  if (root) {
4550
4601
  if (qualifier) {
@@ -4559,7 +4610,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4559
4610
  SUFFIX after the "__" separator counts. Zero matches
4560
4611
  throws no_matching_instance; multiple matches throw
4561
4612
  ambiguous_qualifier. No silent resolution. */
4562
- const cands = root.querySelectorAll('[data-nac-action="' + verb + '"]');
4613
+ const cands = root.querySelectorAll('[data-nac-action="' + _nac_attrValue(verb) + '"]');
4563
4614
  const exact = [];
4564
4615
  for (let i = 0; i < cands.length; i++) {
4565
4616
  const id = cands[i].getAttribute('data-nac-id') || '';
@@ -4612,14 +4663,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4612
4663
  }
4613
4664
  matched = { nac_id: exact[0].getAttribute('data-nac-id'), verb: verb };
4614
4665
  } else if (qualifierOrdinal !== null) {
4615
- const cands = root.querySelectorAll('[data-nac-action="' + verb + '"]');
4666
+ const cands = root.querySelectorAll('[data-nac-action="' + _nac_attrValue(verb) + '"]');
4616
4667
  const el = cands[qualifierOrdinal];
4617
4668
  if (el && el.getAttribute('data-nac-id')) {
4618
4669
  matched = { nac_id: el.getAttribute('data-nac-id'), verb: verb };
4619
4670
  }
4620
4671
  } else {
4621
4672
  /* Default: first match in DOM order. */
4622
- const el = root.querySelector('[data-nac-action="' + verb + '"]');
4673
+ const el = root.querySelector('[data-nac-action="' + _nac_attrValue(verb) + '"]');
4623
4674
  if (el && el.getAttribute('data-nac-id')) {
4624
4675
  matched = { nac_id: el.getAttribute('data-nac-id'), verb: verb };
4625
4676
  }
@@ -4940,7 +4991,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
4940
4991
  that humans wouldn't say aloud). Same two-tier strict logic. */
4941
4992
  if (!matched) {
4942
4993
  const root = document.querySelector(
4943
- '[data-nac-plugin="' + targetPlugin + '"]');
4994
+ '[data-nac-plugin="' + _nac_attrValue(targetPlugin) + '"]');
4944
4995
  if (root) {
4945
4996
  const tabs = Array.prototype.slice.call(
4946
4997
  root.querySelectorAll('[data-nac-role="tab"]'));
@@ -5029,7 +5080,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5029
5080
  /* Best-effort: serialize the active plugin DOM to data URL.
5030
5081
  For real screenshots, the runner uses Playwright's screenshot
5031
5082
  primitive; this is a fallback for in-page operators. */
5032
- const root = document.querySelector('[data-nac-plugin="' + _activePlugin() + '"]')
5083
+ const root = document.querySelector('[data-nac-plugin="' + _nac_attrValue(_activePlugin()) + '"]')
5033
5084
  || document.body;
5034
5085
  const xml = new XMLSerializer().serializeToString(root);
5035
5086
  return 'data:image/svg+xml;base64,' +
@@ -5057,7 +5108,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5057
5108
  function validate(plugin_slug) {
5058
5109
  const m = _manifests[plugin_slug];
5059
5110
  if (!m) return { ok: false, code: 'no_manifest' };
5060
- const root = document.querySelector('[data-nac-plugin="' + plugin_slug + '"]');
5111
+ const root = document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin_slug) + '"]');
5061
5112
  if (!root) return { ok: false, code: 'plugin_not_mounted' };
5062
5113
  const found = {};
5063
5114
  const elemByNacId = {};
@@ -5248,8 +5299,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5248
5299
  m.rows.cells.forEach(function (col) {
5249
5300
  if (!col || !col.nac_id) return;
5250
5301
  const cell = sampleRow.querySelector(
5251
- '[data-nac-id$="' + col.nac_id + '"], '
5252
- + '[data-nac-cell="' + col.nac_id + '"]');
5302
+ '[data-nac-id$="' + _nac_attrValue(col.nac_id) + '"], '
5303
+ + '[data-nac-cell="' + _nac_attrValue(col.nac_id) + '"]');
5253
5304
  if (!cell) {
5254
5305
  pushErr('error', 'row_cell_missing', col.nac_id,
5255
5306
  'manifest declares row cell "' + col.nac_id
@@ -5266,7 +5317,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5266
5317
  b.items.forEach(function (item) {
5267
5318
  if (!item || !item.nac_id) return;
5268
5319
  const el = root.querySelector(
5269
- '[data-nac-role="breadcrumb-item"][data-nac-id="' + item.nac_id + '"]');
5320
+ '[data-nac-role="breadcrumb-item"][data-nac-id="' + _nac_attrValue(item.nac_id) + '"]');
5270
5321
  if (!el) {
5271
5322
  pushErr('error', 'breadcrumb_item_missing', item.nac_id,
5272
5323
  'breadcrumb item "' + item.nac_id
@@ -5335,7 +5386,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5335
5386
  {
5336
5387
  const sameSlug = Array.prototype.slice.call(
5337
5388
  document.querySelectorAll(
5338
- '[data-nac-plugin="' + plugin_slug + '"]'));
5389
+ '[data-nac-plugin="' + _nac_attrValue(plugin_slug) + '"]'));
5339
5390
  if (sameSlug.length > 1) {
5340
5391
  const ids = sameSlug.map(function (r) {
5341
5392
  return r.getAttribute('data-nac-plugin-id') || '';
@@ -5929,8 +5980,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
5929
5980
  /* ---------- v1.2: window chrome (min/max/restore) --------------- */
5930
5981
 
5931
5982
  function _findPluginRoot(plugin) {
5932
- return document.querySelector('[data-nac-plugin="' + plugin + '"]')
5933
- || document.querySelector('[data-nac-id="' + plugin + '"]');
5983
+ return document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin) + '"]')
5984
+ || document.querySelector('[data-nac-id="' + _nac_attrValue(plugin) + '"]');
5934
5985
  }
5935
5986
 
5936
5987
  function _setPluginState(plugin, newState) {
@@ -6108,7 +6159,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6108
6159
 
6109
6160
  function _genericReset(plugin_slug) {
6110
6161
  const root = plugin_slug
6111
- ? document.querySelector('[data-nac-plugin="' + plugin_slug + '"]')
6162
+ ? document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin_slug) + '"]')
6112
6163
  : document;
6113
6164
  if (!root) return false;
6114
6165
  /* Clear every NAC-instrumented field. Honours
@@ -6188,7 +6239,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6188
6239
 
6189
6240
  function _findSection(sectionId) {
6190
6241
  return document.querySelector(
6191
- '[data-nac-role="section"][data-nac-id="' + sectionId + '"]');
6242
+ '[data-nac-role="section"][data-nac-id="' + _nac_attrValue(sectionId) + '"]');
6192
6243
  }
6193
6244
 
6194
6245
  function list_sections() {
@@ -6299,7 +6350,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6299
6350
  }
6300
6351
  if (detail.plugin && detail.plugin_instance_id === undefined) {
6301
6352
  const root = document.querySelector(
6302
- '[data-nac-plugin="' + detail.plugin + '"]');
6353
+ '[data-nac-plugin="' + _nac_attrValue(detail.plugin) + '"]');
6303
6354
  detail.plugin_instance_id = root
6304
6355
  ? (root.getAttribute('data-nac-plugin-id') || null)
6305
6356
  : null;
@@ -6326,9 +6377,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6326
6377
  payload filtering. */
6327
6378
  if (detail.plugin) {
6328
6379
  const root = document.querySelector(
6329
- '[data-nac-plugin="' + detail.plugin + '"]'
6380
+ '[data-nac-plugin="' + _nac_attrValue(detail.plugin) + '"]'
6330
6381
  + (detail.plugin_instance_id
6331
- ? '[data-nac-plugin-id="' + detail.plugin_instance_id + '"]'
6382
+ ? '[data-nac-plugin-id="' + _nac_attrValue(detail.plugin_instance_id) + '"]'
6332
6383
  : ''));
6333
6384
  if (root && root.getAttribute('data-nac-plugin-bus') === 'enabled') {
6334
6385
  root.dispatchEvent(new CustomEvent(name, {
@@ -6391,9 +6442,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6391
6442
  exposure API. Falls back to document.querySelector when
6392
6443
  the deep helper is unavailable (defensive). */
6393
6444
  if (typeof _deepQuery === 'function') {
6394
- return _deepQuery('[data-nac-id="' + id + '"]', document);
6445
+ return _deepQuery('[data-nac-id="' + _nac_attrValue(id) + '"]', document);
6395
6446
  }
6396
- return document.querySelector('[data-nac-id="' + id + '"]');
6447
+ return document.querySelector('[data-nac-id="' + _nac_attrValue(id) + '"]');
6397
6448
  }
6398
6449
 
6399
6450
  /* ---------- v1.3: toast / banner / confirm --------------------- */
@@ -6514,8 +6565,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6514
6565
  _emit(answer ? 'nac:confirm:confirmed' : 'nac:confirm:cancelled', { id: id });
6515
6566
  resolve(!!answer);
6516
6567
  }
6517
- card.querySelector('[data-nac-id="' + id + '.confirm"]').addEventListener('click', function () { done(true); });
6518
- card.querySelector('[data-nac-id="' + id + '.cancel"]').addEventListener('click', function () { done(false); });
6568
+ card.querySelector('[data-nac-id="' + _nac_attrValue(id) + '.confirm"]').addEventListener('click', function () { done(true); });
6569
+ card.querySelector('[data-nac-id="' + _nac_attrValue(id) + '.cancel"]').addEventListener('click', function () { done(false); });
6519
6570
  });
6520
6571
  }
6521
6572
  function list_pending_confirms() {
@@ -6588,7 +6639,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6588
6639
 
6589
6640
  function _stepperRoot(stepper_id) {
6590
6641
  return document.querySelector(
6591
- '[data-nac-role="stepper"][data-nac-id="' + stepper_id + '"]');
6642
+ '[data-nac-role="stepper"][data-nac-id="' + _nac_attrValue(stepper_id) + '"]');
6592
6643
  }
6593
6644
  function _stepperSteps(stepper_id) {
6594
6645
  const root = _stepperRoot(stepper_id);
@@ -6644,7 +6695,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6644
6695
 
6645
6696
  function _treeNode(node_id) {
6646
6697
  return document.querySelector(
6647
- '[data-nac-role="treenode"][data-nac-id="' + node_id + '"]');
6698
+ '[data-nac-role="treenode"][data-nac-id="' + _nac_attrValue(node_id) + '"]');
6648
6699
  }
6649
6700
  function tree_expand(node_id) {
6650
6701
  const n = _treeNode(node_id);
@@ -6703,7 +6754,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6703
6754
 
6704
6755
  function _tagFieldRoot(field_id) {
6705
6756
  const el = document.querySelector(
6706
- '[data-nac-role="field"][data-nac-field-type="tag-input"][data-nac-id="' + field_id + '"]');
6757
+ '[data-nac-role="field"][data-nac-field-type="tag-input"][data-nac-id="' + _nac_attrValue(field_id) + '"]');
6707
6758
  return el;
6708
6759
  }
6709
6760
  function add_tag(field_id, value) {
@@ -6733,8 +6784,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6733
6784
 
6734
6785
  function _drawer(id) {
6735
6786
  return document.querySelector(
6736
- '[data-nac-role="drawer"][data-nac-id="' + id + '"], ' +
6737
- '[data-nac-role="bottom-sheet"][data-nac-id="' + id + '"]');
6787
+ '[data-nac-role="drawer"][data-nac-id="' + _nac_attrValue(id) + '"], ' +
6788
+ '[data-nac-role="bottom-sheet"][data-nac-id="' + _nac_attrValue(id) + '"]');
6738
6789
  }
6739
6790
  function open_drawer(id, position) {
6740
6791
  const d = _drawer(id);
@@ -6761,14 +6812,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6761
6812
 
6762
6813
  function calendar_view(cal_id, view) {
6763
6814
  const c = document.querySelector(
6764
- '[data-nac-role="calendar"][data-nac-id="' + cal_id + '"]');
6815
+ '[data-nac-role="calendar"][data-nac-id="' + _nac_attrValue(cal_id) + '"]');
6765
6816
  if (!c) throw NacError('calendar_not_found', cal_id);
6766
6817
  c.setAttribute('data-nac-view', view);
6767
6818
  _emit('nac:calendar:view_changed', { calendar_id: cal_id, view: view });
6768
6819
  }
6769
6820
  function calendar_go_to(cal_id, date) {
6770
6821
  const c = document.querySelector(
6771
- '[data-nac-role="calendar"][data-nac-id="' + cal_id + '"]');
6822
+ '[data-nac-role="calendar"][data-nac-id="' + _nac_attrValue(cal_id) + '"]');
6772
6823
  if (!c) throw NacError('calendar_not_found', cal_id);
6773
6824
  c.setAttribute('data-nac-date', date);
6774
6825
  _emit('nac:calendar:date_selected', { calendar_id: cal_id, date: date });
@@ -6785,7 +6836,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6785
6836
  }
6786
6837
  function calendar_list_events(cal_id /*, from, to */) {
6787
6838
  const c = document.querySelector(
6788
- '[data-nac-role="calendar"][data-nac-id="' + cal_id + '"]');
6839
+ '[data-nac-role="calendar"][data-nac-id="' + _nac_attrValue(cal_id) + '"]');
6789
6840
  if (!c) return [];
6790
6841
  const out = [];
6791
6842
  c.querySelectorAll('[data-nac-role="calendar-event"]').forEach(function (e) {
@@ -6804,7 +6855,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6804
6855
 
6805
6856
  function chart_data(chart_id) {
6806
6857
  const c = document.querySelector(
6807
- '[data-nac-role="chart"][data-nac-id="' + chart_id + '"]');
6858
+ '[data-nac-role="chart"][data-nac-id="' + _nac_attrValue(chart_id) + '"]');
6808
6859
  if (!c) throw NacError('chart_not_found', chart_id);
6809
6860
  const series = [];
6810
6861
  c.querySelectorAll('[data-nac-role="chart-series"]').forEach(function (s) {
@@ -6828,7 +6879,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6828
6879
  }
6829
6880
  function chart_toggle_series(chart_id, series_id, on) {
6830
6881
  const s = document.querySelector(
6831
- '[data-nac-role="chart-series"][data-nac-id="' + series_id + '"]');
6882
+ '[data-nac-role="chart-series"][data-nac-id="' + _nac_attrValue(series_id) + '"]');
6832
6883
  if (!s) throw NacError('chart_series_not_found', series_id);
6833
6884
  const target = (typeof on === 'boolean') ? on : (s.getAttribute('data-nac-state') === 'hidden');
6834
6885
  s.setAttribute('data-nac-state', target ? 'visible' : 'hidden');
@@ -6842,7 +6893,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6842
6893
 
6843
6894
  function map_focus(map_id, lat, lng, zoom) {
6844
6895
  const m = document.querySelector(
6845
- '[data-nac-role="map"][data-nac-id="' + map_id + '"]');
6896
+ '[data-nac-role="map"][data-nac-id="' + _nac_attrValue(map_id) + '"]');
6846
6897
  if (!m) throw NacError('map_not_found', map_id);
6847
6898
  m.setAttribute('data-nac-lat', String(lat));
6848
6899
  m.setAttribute('data-nac-lng', String(lng));
@@ -6854,7 +6905,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6854
6905
  }
6855
6906
  function map_select_marker(marker_id) {
6856
6907
  const mk = document.querySelector(
6857
- '[data-nac-role="map-marker"][data-nac-id="' + marker_id + '"]');
6908
+ '[data-nac-role="map-marker"][data-nac-id="' + _nac_attrValue(marker_id) + '"]');
6858
6909
  if (!mk) throw NacError('map_marker_not_found', marker_id);
6859
6910
  mk.setAttribute('data-nac-state', 'selected');
6860
6911
  const map_id = (mk.closest('[data-nac-role="map"]') || {}).getAttribute
@@ -6870,7 +6921,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6870
6921
  }
6871
6922
  function map_toggle_layer(map_id, layer_id, on) {
6872
6923
  const ly = document.querySelector(
6873
- '[data-nac-role="map-layer"][data-nac-id="' + layer_id + '"]');
6924
+ '[data-nac-role="map-layer"][data-nac-id="' + _nac_attrValue(layer_id) + '"]');
6874
6925
  if (!ly) throw NacError('map_layer_not_found', layer_id);
6875
6926
  const target = (typeof on === 'boolean') ? on : (ly.getAttribute('data-nac-state') === 'hidden');
6876
6927
  ly.setAttribute('data-nac-state', target ? 'visible' : 'hidden');
@@ -6878,7 +6929,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6878
6929
  }
6879
6930
  function list_markers(map_id) {
6880
6931
  const m = document.querySelector(
6881
- '[data-nac-role="map"][data-nac-id="' + map_id + '"]');
6932
+ '[data-nac-role="map"][data-nac-id="' + _nac_attrValue(map_id) + '"]');
6882
6933
  if (!m) return [];
6883
6934
  const out = [];
6884
6935
  m.querySelectorAll('[data-nac-role="map-marker"]').forEach(function (mk) {
@@ -6912,7 +6963,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6912
6963
 
6913
6964
  function _breadcrumbContainer(crumb_id) {
6914
6965
  return document.querySelector(
6915
- '[data-nac-role="breadcrumb"][data-nac-id="' + crumb_id + '"]');
6966
+ '[data-nac-role="breadcrumb"][data-nac-id="' + _nac_attrValue(crumb_id) + '"]');
6916
6967
  }
6917
6968
  function _breadcrumbItems(rootEl) {
6918
6969
  if (!rootEl) return [];
@@ -6947,7 +6998,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6947
6998
  + item_id + '"]');
6948
6999
  if (!el) {
6949
7000
  // fallback: any anchor whose label matches
6950
- el = document.querySelector('a[data-nac-id="' + item_id + '"]');
7001
+ el = document.querySelector('a[data-nac-id="' + _nac_attrValue(item_id) + '"]');
6951
7002
  }
6952
7003
  if (!el) {
6953
7004
  return Promise.reject(new NacError('not_found',
@@ -6973,7 +7024,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6973
7024
 
6974
7025
  function _carousel(carousel_id) {
6975
7026
  return document.querySelector(
6976
- '[data-nac-role="carousel"][data-nac-id="' + carousel_id + '"]');
7027
+ '[data-nac-role="carousel"][data-nac-id="' + _nac_attrValue(carousel_id) + '"]');
6977
7028
  }
6978
7029
  function _carouselSlides(rootEl) {
6979
7030
  if (!rootEl) return [];
@@ -7074,7 +7125,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7074
7125
 
7075
7126
  function _timeline(timeline_id) {
7076
7127
  return document.querySelector(
7077
- '[data-nac-role="timeline"][data-nac-id="' + timeline_id + '"]');
7128
+ '[data-nac-role="timeline"][data-nac-id="' + _nac_attrValue(timeline_id) + '"]');
7078
7129
  }
7079
7130
  function _timelineItems(rootEl) {
7080
7131
  if (!rootEl) return [];
@@ -7152,7 +7203,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7152
7203
  'list not found: ' + list_id));
7153
7204
  }
7154
7205
  var item = list.querySelector(
7155
- '[data-nac-role="draggable"][data-nac-id="' + item_id + '"]')
7206
+ '[data-nac-role="draggable"][data-nac-id="' + _nac_attrValue(item_id) + '"]')
7156
7207
  || _byId(item_id);
7157
7208
  if (!item) {
7158
7209
  return Promise.reject(new NacError('not_found',
@@ -8688,6 +8739,53 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8688
8739
  }
8689
8740
  }
8690
8741
 
8742
+ /* 2.9.1 (PND-168) -- WHO IS ALLOWED TO READ AN OUTGOING MESSAGE.
8743
+
8744
+ Both postMessage backends sent `binding.target_origin || '*'`, so a
8745
+ manifest that did not declare an origin broadcast the action's
8746
+ arguments to whatever origin happened to occupy that iframe. The
8747
+ INCOMING half was already right (both listeners filter on
8748
+ ev.source === iframe.contentWindow), which is what made the
8749
+ outgoing default stand out rather than look like the house style.
8750
+
8751
+ The default is now the origin of the iframe the adopter pointed at,
8752
+ read from its src. '*' survives exactly where it is the only thing
8753
+ that can work -- srcdoc, about:blank, a blob or no src at all,
8754
+ which all resolve to an opaque origin -- and it survives where the
8755
+ adopter asks for it by declaring target_origin: '*'.
8756
+
8757
+ The derivation is announced once per message id. An adopter whose
8758
+ iframe has navigated cross-origin since it was mounted would
8759
+ otherwise see the message silently dropped by the browser, and a
8760
+ silent drop is the one outcome this project does not accept: the
8761
+ line names the origin it chose and how to pin it. */
8762
+ const _v25_origin_notices = Object.create(null);
8763
+ function _v25_targetOrigin(binding, iframe, backend) {
8764
+ if (binding && binding.target_origin) return binding.target_origin;
8765
+ let origin = null;
8766
+ try {
8767
+ const raw = iframe && typeof iframe.getAttribute === 'function'
8768
+ ? iframe.getAttribute('src') : null;
8769
+ if (raw && typeof URL === 'function') {
8770
+ const base = typeof location !== 'undefined' ? location.href : undefined;
8771
+ const resolved = new URL(String(raw), base).origin;
8772
+ if (resolved && resolved !== 'null') origin = resolved;
8773
+ }
8774
+ } catch (e) { origin = null; }
8775
+ if (!origin) return '*';
8776
+ const key = backend + ':' + (binding && binding.message) + ':' + origin;
8777
+ if (!_v25_origin_notices[key]) {
8778
+ _v25_origin_notices[key] = true;
8779
+ if (typeof console !== 'undefined' && console.warn) {
8780
+ console.warn('[nac] ' + backend + ': no target_origin declared for message "'
8781
+ + (binding && binding.message) + '", so it is posted to ' + origin
8782
+ + ', the origin of the target iframe. Declare target_origin in the manifest '
8783
+ + "to pin it (target_origin: '*' restores the pre-2.9.1 broadcast).");
8784
+ }
8785
+ }
8786
+ return origin;
8787
+ }
8788
+
8691
8789
  /* postmessage (verb): post a structured message to the iframe.contentWindow
8692
8790
  of the target. `values` literal + `values_from_args` forward keys. */
8693
8791
  function _v25_backend_postmessage(binding, args) {
@@ -8716,7 +8814,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8716
8814
  }
8717
8815
  }
8718
8816
  try {
8719
- iframe.contentWindow.postMessage(msg, binding.target_origin || '*');
8817
+ iframe.contentWindow.postMessage(msg, _v25_targetOrigin(binding, iframe, 'postmessage'));
8720
8818
  return Promise.resolve({ ok: true });
8721
8819
  } catch (e) {
8722
8820
  return Promise.reject(e);
@@ -8822,7 +8920,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8822
8920
  MessageId: binding.message,
8823
8921
  SendTime: Date.now(),
8824
8922
  Values: wantValues,
8825
- }, binding.target_origin || '*');
8923
+ }, _v25_targetOrigin(binding, iframe, 'script-bridge'));
8826
8924
  });
8827
8925
  }
8828
8926
 
@@ -9989,7 +10087,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
9989
10087
  subtree. If plugin is omitted, fall back to global search. */
9990
10088
  let root = document;
9991
10089
  if (plugin) {
9992
- const pluginRoot = document.querySelector('[data-nac-plugin="' + plugin + '"]');
10090
+ const pluginRoot = document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin) + '"]');
9993
10091
  if (!pluginRoot) return null;
9994
10092
  root = pluginRoot;
9995
10093
  }
@@ -10051,7 +10149,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
10051
10149
 
10052
10150
  function _v25b_pluginRoot(plugin) {
10053
10151
  if (!plugin) return null;
10054
- return document.querySelector('[data-nac-plugin="' + plugin + '"]');
10152
+ return document.querySelector('[data-nac-plugin="' + _nac_attrValue(plugin) + '"]');
10055
10153
  }
10056
10154
 
10057
10155
  function context(plugin) {
@@ -10243,7 +10341,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
10243
10341
 
10244
10342
  global.NAC = {
10245
10343
  __nac_v1_installed: true,
10246
- version: '2.9.0',
10344
+ version: '2.9.1',
10247
10345
  spec_version: '2.9',
10248
10346
  /* v2.2.0 (V22-01) -- strict validation toggle. When true,
10249
10347
  NAC.register throws on findings (manifest_role_unknown,
@@ -10616,6 +10714,115 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
10616
10714
  diff: diff,
10617
10715
  };
10618
10716
 
10717
+ /* ================================================================
10718
+ 2.9.1 -- SPEC 19.3 for the whole family (PND-162, PND-163)
10719
+ ================================================================
10720
+
10721
+ 19.3 names eight primitives and then says "and any other that
10722
+ resolves a name by querying the document". Since 2.7.0 the eight
10723
+ called _nac_requireDocument inline and the OTHERS did not: measured
10724
+ on 2026-11-28 by calling all 151 exports in a sandbox with no
10725
+ document, 69 of them still died with a raw
10726
+ "ReferenceError: document is not defined" -- the same defect D-26
10727
+ closed one layer up, and the suite that guarded it only ever tested
10728
+ the eight, so it asserted more than it measured.
10729
+
10730
+ Worst of them was wait_for: it scheduled a setTimeout BEFORE
10731
+ touching the document, so the ReferenceError came out of the timer
10732
+ -- outside every try/catch the caller could write -- and killed the
10733
+ Node process. A promise .catch() could not reach it.
10734
+
10735
+ WHY HERE, at install, and not inline in 69 bodies. Fail closed
10736
+ before the primitive does any work (which is what kills the timer
10737
+ path), one place to read, and the list is a DECLARATION a gate can
10738
+ enforce. Inline guards would be 69 edits to a published runtime for
10739
+ the same effect, and the next primitive would forget the line.
10740
+
10741
+ WHY TWO LISTS. The channel the refusal arrives through is part of
10742
+ the published surface: an adopter who wrote
10743
+ NAC.confirm(...).catch(h) must keep getting a rejection, not a
10744
+ synchronous throw. So each name carries the channel its failure
10745
+ ALREADY used, measured rather than guessed -- the async ones return
10746
+ a promise (three of them are not declared async: they return
10747
+ new Promise, and the executor's throw rejected). The suite checks
10748
+ this against an independent oracle: it calls the same primitive
10749
+ WITH a document and asks whether the return value is a thenable.
10750
+
10751
+ NOT in these lists, on purpose: the eight that guard inline (their
10752
+ call sites read better where they are), and everything that works
10753
+ with no document at all -- the extension contract (call / read /
10754
+ subscribe), the manifest surface, profile(), the provenance sink.
10755
+ Those are the headless profile, and guarding them would break
10756
+ section 19 instead of serving it. */
10757
+ const _NAC_DOM_PRIMITIVES_SYNC = [
10758
+ 'add_tag', 'calendar_go_to', 'calendar_list_events',
10759
+ 'calendar_select_event', 'calendar_view', 'carousel_state',
10760
+ 'chart_data', 'chart_filter', 'chart_toggle_series',
10761
+ 'close_drawer', 'dismiss_banner', 'dismiss_toast', 'edit_field',
10762
+ 'emit_dual', 'invalidate_options', 'is_blocked', 'list_banners',
10763
+ 'list_breadcrumbs', 'list_carousels', 'list_markers',
10764
+ 'list_pending_confirms', 'list_sections', 'list_tags',
10765
+ 'list_timelines', 'list_toasts', 'map_focus', 'map_select_marker',
10766
+ 'map_toggle_layer', 'open_drawer', 'peek_drawer', 'remove_tag',
10767
+ 'richtext_format', 'richtext_insert_link',
10768
+ 'richtext_insert_mention', 'set_a11y_hint_localizer', 'step_back',
10769
+ 'step_next', 'step_state', 'step_to', 'timeline_state', 'toast',
10770
+ 'tree_collapse', 'tree_expand', 'tree_path', 'tree_select',
10771
+ ];
10772
+ const _NAC_DOM_PRIMITIVES_ASYNC = [
10773
+ 'assert_event_count', 'assert_event_fired', 'carousel_advance',
10774
+ 'carousel_autoplay', 'carousel_to', 'click_by_verb', 'confirm',
10775
+ 'drag_drop', 'fullscreen', 'go_to_section', 'maximize', 'minimize',
10776
+ 'navigate_breadcrumb', 'perf_probe', 'reorder', 'reset', 'restore',
10777
+ 'screenshot', 'tab', 'tab_by_label', 'timeline_load_newer',
10778
+ 'timeline_load_older', 'validate_event_conformance', 'wait_for',
10779
+ ];
10780
+ function _nac_guardDomPrimitive(api, name, isAsync) {
10781
+ const fn = api[name];
10782
+ /* No silent no-op: a name in the table that is not exported means
10783
+ the table and the surface drifted, and the gate says so. */
10784
+ if (typeof fn !== 'function') return false;
10785
+ function guarded() {
10786
+ if (typeof document === 'undefined' || !document) {
10787
+ const err = _nac_noDocumentError(name);
10788
+ if (isAsync) return Promise.reject(err);
10789
+ throw err;
10790
+ }
10791
+ return fn.apply(this, arguments);
10792
+ }
10793
+ /* The published shape of a function is its name and its arity;
10794
+ both are read by adopters and by this tree's own gates. */
10795
+ try { Object.defineProperty(guarded, 'name', { value: name, configurable: true }); } catch (e) { /* older engines */ }
10796
+ try { Object.defineProperty(guarded, 'length', { value: fn.length, configurable: true }); } catch (e) { /* idem */ }
10797
+ guarded.__nac_requires_document = true;
10798
+ api[name] = guarded;
10799
+ return true;
10800
+ }
10801
+ (function _nac_installDocumentGuards(api) {
10802
+ const missing = [];
10803
+ for (let i = 0; i < _NAC_DOM_PRIMITIVES_SYNC.length; i++) {
10804
+ if (!_nac_guardDomPrimitive(api, _NAC_DOM_PRIMITIVES_SYNC[i], false)) {
10805
+ missing.push(_NAC_DOM_PRIMITIVES_SYNC[i]);
10806
+ }
10807
+ }
10808
+ for (let i = 0; i < _NAC_DOM_PRIMITIVES_ASYNC.length; i++) {
10809
+ if (!_nac_guardDomPrimitive(api, _NAC_DOM_PRIMITIVES_ASYNC[i], true)) {
10810
+ missing.push(_NAC_DOM_PRIMITIVES_ASYNC[i]);
10811
+ }
10812
+ }
10813
+ /* Readable from outside so a gate can enforce the declaration
10814
+ instead of re-deriving it, and so an adopter can ask whether a
10815
+ primitive needs a document before calling it. */
10816
+ api.documentPrimitives = function () {
10817
+ return {
10818
+ sync: _NAC_DOM_PRIMITIVES_SYNC.slice(),
10819
+ async: _NAC_DOM_PRIMITIVES_ASYNC.slice(),
10820
+ missing: missing.slice(),
10821
+ };
10822
+ };
10823
+ })(global.NAC);
10824
+
10825
+
10619
10826
  /* v2.2.1: guard browser-only init so this module is importable in
10620
10827
  Node / SSR / test contexts without crashing. */
10621
10828
  if (typeof document !== 'undefined') {