@altopelago/sansa 0.14.2 → 0.15.0-rc.2

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +118 -1
  2. package/README.md +96 -1
  3. package/conformance/README.md +8 -0
  4. package/conformance/aeonic-anchor-claims.json +133 -0
  5. package/conformance/aeonic-arithmetic-claims.json +60 -0
  6. package/conformance/aeonic-clock-claims.json +123 -0
  7. package/conformance/aeonic-comparison-claims.json +37 -0
  8. package/conformance/aeonic-datetime-claims.json +110 -0
  9. package/conformance/aeonic-rational-arithmetic-claims.json +72 -0
  10. package/conformance/aeonic-temporal-claims.json +105 -0
  11. package/conformance/cts-claims.json +17 -3
  12. package/conformance/results/aeonic-anchor-capacity.json +452 -0
  13. package/conformance/results/aeonic-anchor-snapshot-0.1.json +39 -0
  14. package/conformance/results/aeonic-arithmetic-snapshot-0.1.json +28 -0
  15. package/conformance/results/aeonic-clock-all-snapshot-0.1.json +49 -0
  16. package/conformance/results/aeonic-clock-arithmetic-snapshot-0.1.json +48 -0
  17. package/conformance/results/aeonic-clock-capacity.json +326 -0
  18. package/conformance/results/aeonic-clock-relations-snapshot-0.1.json +48 -0
  19. package/conformance/results/aeonic-comparison-snapshot-0.1.json +19 -0
  20. package/conformance/results/aeonic-datetime-all-snapshot-0.1.json +47 -0
  21. package/conformance/results/aeonic-datetime-arithmetic-snapshot-0.1.json +46 -0
  22. package/conformance/results/aeonic-datetime-capacity.json +302 -0
  23. package/conformance/results/aeonic-datetime-relations-snapshot-0.1.json +46 -0
  24. package/conformance/results/aeonic-rational-arithmetic-capacity.json +100 -0
  25. package/conformance/results/aeonic-rational-arithmetic-snapshot-0.2.json +30 -0
  26. package/conformance/results/aeonic-temporal-all-property-addressing-2026-11-16.json +39 -0
  27. package/conformance/results/aeonic-temporal-all-snapshot-0.1.json +39 -0
  28. package/conformance/results/aeonic-temporal-calendar-property-addressing-2026-11-16.json +38 -0
  29. package/conformance/results/aeonic-temporal-calendar-snapshot-0.1.json +38 -0
  30. package/conformance/results/aeonic-temporal-capacity-property-addressing-2026-11-16.json +136 -0
  31. package/conformance/results/aeonic-temporal-capacity.json +136 -0
  32. package/conformance/results/aeonic-temporal-relations-property-addressing-2026-11-16.json +38 -0
  33. package/conformance/results/aeonic-temporal-relations-snapshot-0.1.json +38 -0
  34. package/docs/aeonic-arithmetic.md +126 -0
  35. package/docs/aeonic-comparison.md +123 -0
  36. package/docs/aeonic-rational-arithmetic.md +167 -0
  37. package/docs/aeonic-temporal-civil-anchor.md +89 -0
  38. package/docs/aeonic-temporal-civil-clock.md +100 -0
  39. package/docs/aeonic-temporal-civil-date.md +124 -0
  40. package/docs/aeonic-temporal-civil-datetime.md +122 -0
  41. package/docs/api-contract.md +130 -3
  42. package/docs/capabilities.json +106 -2
  43. package/docs/child-identity-activation.md +93 -0
  44. package/docs/child-identity-candidate.md +60 -0
  45. package/docs/child-identity-tooling.md +31 -0
  46. package/docs/child-identity-workflows.md +102 -0
  47. package/docs/empty-keys-candidate.md +29 -0
  48. package/docs/migration-0.15.0.md +75 -0
  49. package/docs/property-addressing-implementation.md +118 -0
  50. package/docs/property-resolve-implementation.md +105 -0
  51. package/docs/property-selector-support.md +65 -0
  52. package/docs/property-selectors-api.d.ts +43 -0
  53. package/docs/property-selectors-api.pyi +27 -0
  54. package/docs/property-selectors-api.rs +48 -0
  55. package/docs/property-selectors-contract.md +168 -0
  56. package/docs/query-tool.md +32 -1
  57. package/docs/selector-cursor.md +45 -0
  58. package/docs/unicode-hardening.md +41 -0
  59. package/fixtures/address-v1.json +4 -3
  60. package/fixtures/child-identity-workflows/README.md +9 -0
  61. package/fixtures/child-identity-workflows/moved.aeon +10 -0
  62. package/fixtures/child-identity-workflows/original.aeon +10 -0
  63. package/fixtures/child-identity-workflows/reordered.aeon +10 -0
  64. package/fixtures/child-identity-workflows/replacement.aeon +10 -0
  65. package/fixtures/child-identity-workflows/workflows.json +89 -0
  66. package/fixtures/property-namespace-candidate-v1.json +336 -0
  67. package/fixtures/property-parser-candidate-v1.json +705 -0
  68. package/fixtures/property-query-candidate-v1.json +398 -0
  69. package/fixtures/property-resolve-candidate-v1.json +2702 -0
  70. package/fixtures/unicode-hardening-v1.json +401 -0
  71. package/package.json +30 -3
  72. package/scripts/calibrate-aeonic-anchor-capacity.py +294 -0
  73. package/scripts/calibrate-aeonic-clock-capacity.py +62 -0
  74. package/scripts/calibrate-aeonic-datetime-capacity.py +76 -0
  75. package/scripts/calibrate-aeonic-rational-capacity.py +85 -0
  76. package/scripts/calibrate-aeonic-temporal-capacity.py +95 -0
  77. package/scripts/cts-address.mjs +6 -2
  78. package/scripts/cts-aeonic-anchor.mjs +21 -0
  79. package/scripts/cts-aeonic-arithmetic-adapter.mjs +25 -0
  80. package/scripts/cts-aeonic-arithmetic.mjs +24 -0
  81. package/scripts/cts-aeonic-clock.mjs +24 -0
  82. package/scripts/cts-aeonic-comparison-adapter.mjs +30 -0
  83. package/scripts/cts-aeonic-comparison.mjs +25 -0
  84. package/scripts/cts-aeonic-datetime.mjs +24 -0
  85. package/scripts/cts-aeonic-rational-arithmetic-adapter.mjs +25 -0
  86. package/scripts/cts-aeonic-rational-arithmetic.mjs +24 -0
  87. package/scripts/cts-aeonic-temporal-civil-anchor-adapter.mjs +26 -0
  88. package/scripts/cts-aeonic-temporal-civil-clock-adapter.mjs +28 -0
  89. package/scripts/cts-aeonic-temporal-civil-date-adapter.mjs +28 -0
  90. package/scripts/cts-aeonic-temporal-civil-datetime-adapter.mjs +28 -0
  91. package/scripts/cts-aeonic-temporal.mjs +24 -0
  92. package/scripts/cts-instruction.mjs +4 -2
  93. package/scripts/cts-mutate.mjs +3 -2
  94. package/scripts/cts-resolve.mjs +17 -2
  95. package/scripts/playground.mjs +110 -0
  96. package/src/aeonic-arithmetic-binding.js +61 -0
  97. package/src/aeonic-arithmetic.d.ts +84 -0
  98. package/src/aeonic-arithmetic.js +276 -0
  99. package/src/aeonic-comparison.d.ts +86 -0
  100. package/src/aeonic-comparison.js +274 -0
  101. package/src/aeonic-convenience.d.ts +30 -0
  102. package/src/aeonic-convenience.js +45 -0
  103. package/src/aeonic-exact-number.js +34 -0
  104. package/src/aeonic-json.js +45 -0
  105. package/src/aeonic-rational-arithmetic.d.ts +86 -0
  106. package/src/aeonic-rational-arithmetic.js +417 -0
  107. package/src/aeonic-rational-json.js +51 -0
  108. package/src/aeonic-temporal-civil-anchor.d.ts +54 -0
  109. package/src/aeonic-temporal-civil-anchor.js +316 -0
  110. package/src/aeonic-temporal-civil-clock.d.ts +124 -0
  111. package/src/aeonic-temporal-civil-clock.js +388 -0
  112. package/src/aeonic-temporal-civil-date.d.ts +123 -0
  113. package/src/aeonic-temporal-civil-date.js +310 -0
  114. package/src/aeonic-temporal-civil-datetime.d.ts +138 -0
  115. package/src/aeonic-temporal-civil-datetime.js +501 -0
  116. package/src/index.d.ts +84 -1
  117. package/src/index.js +828 -183
  118. package/src/property-address.js +196 -0
  119. package/src/property-resolve.js +132 -0
  120. package/src/query-metadata.d.ts +16 -0
  121. package/src/query-metadata.js +25 -0
  122. package/src/selector-cursor.d.ts +19 -0
  123. package/src/selector-cursor.js +79 -0
  124. package/stress-tests/address/invalid.sansa-cases +0 -2
  125. package/stress-tests/address/valid.sansa-cases +3 -0
  126. package/tools/mutate-web/examples.mjs +1 -1
  127. package/tools/mutate-web/runtime.mjs +0 -2
  128. package/tools/playground/README.md +165 -0
  129. package/tools/playground/accessibility.js +91 -0
  130. package/tools/playground/aeon-highlight.js +77 -0
  131. package/tools/playground/aeon-source-composer.js +1077 -0
  132. package/tools/playground/anchor-examples.mjs +16 -0
  133. package/tools/playground/arithmetic-evaluator.mjs +28 -0
  134. package/tools/playground/arithmetic-model.mjs +187 -0
  135. package/tools/playground/arithmetic-worker.mjs +14 -0
  136. package/tools/playground/arithmetic.css +1 -0
  137. package/tools/playground/arithmetic.html +29 -0
  138. package/tools/playground/arithmetic.mjs +110 -0
  139. package/tools/playground/clock-examples.mjs +16 -0
  140. package/tools/playground/datetime-examples.mjs +22 -0
  141. package/tools/playground/examples.mjs +46 -0
  142. package/tools/playground/index.html +174 -0
  143. package/tools/playground/local.css +25 -0
  144. package/tools/playground/namespace.mjs +39 -0
  145. package/tools/playground/sansa-playground.js +1565 -0
  146. package/tools/playground/site.css +3914 -0
  147. package/tools/playground/temporal-examples.mjs +20 -0
  148. package/tools/playground/walkthrough.js +90 -0
  149. package/tools/playground/website-origin.json +16 -0
  150. package/tools/query-web/IDENTITY_SELECTORS.md +44 -0
  151. package/tools/query-web/app.js +4 -0
  152. package/tools/query-web/index.html +4 -0
  153. package/tools/query-web/runtime.mjs +70 -19
  154. package/tools/workflows/property-playground-assertions.mjs +33 -0
  155. package/tools/workflows/verify-child-identities.mjs +137 -0
  156. package/tools/workflows/verify-property-playground.mjs +48 -0
@@ -0,0 +1,165 @@
1
+ # Source playground
2
+
3
+ This is the AEON website's SANSA playground UI adapted to run inside this repo.
4
+ It keeps the source highlighter, Resolve/Query panels, example dialog and both
5
+ composers. [website-origin.json](website-origin.json) records the original revision
6
+ and asset digests. The original extraction left the website unchanged; its later
7
+ identity-aware browser integration is maintained and verified separately.
8
+
9
+ ## Run
10
+
11
+ ```sh
12
+ npm run playground -- --aeon-root /absolute/path/to/aeon
13
+ ```
14
+
15
+ Open **http://127.0.0.1:4174/tools/playground/**. Use `--port 4180` to choose another
16
+ port. A sibling AEON checkout is detected automatically; alternatively set
17
+ `SANSA_PLAYGROUND_AEON_ROOT`. The selected checkout must already have its TypeScript
18
+ packages built, including runtime, profiles, tonic and SDK. Use the normal AEON
19
+ workspace build (`pnpm --dir /path/to/aeon/implementations/typescript build`) when
20
+ needed. Its SANSA dependency must be compatible with this source checkout.
21
+
22
+ For child identities, use the matching AEON candidate whose SDK namespace exposes
23
+ the explicit identity accessor. An older SDK may correctly report unsupported
24
+ identity selection; the playground does not infer capability from binding fields.
25
+
26
+ There is no SANSA bundle, CDN, PHP dependency or release step. The browser imports
27
+ **`/src/index.js` directly**, including the shared selector cursor. AEON modules are
28
+ served from that checkout's `dist` directories, with an import map pointing every
29
+ SANSA import at this repo. Reload after editing SANSA source; rebuild the AEON
30
+ packages after editing their TypeScript. Responses are not cached. The server
31
+ binds to localhost and serves only playground assets, SANSA source and AEON build
32
+ modules. Documents are evaluated in the browser.
33
+
34
+ ## Try
35
+
36
+ - **Child identities:** chain `$.inventory.items.\item1\.\name1\` and inspect the
37
+ actual structural result path.
38
+ - **Reordered list:** the identity still selects the same authored ID at index 1.
39
+ - **Scope children / Scope root is excluded:** `$` and `?` use the selected scope
40
+ root; child selection cannot match that root's own identity. Scope root must be
41
+ one existing absolute structural path.
42
+ - **Inspection limit:** a match is not returned early when the remaining sibling
43
+ scan would exceed the limit. Missing/ambiguous/limit failures come from Resolve.
44
+ - **SANSA Composer:** offers both structural child steps and declared child IDs.
45
+ **AEON Composer:** preserves ordinary binding/list/attribute identities while
46
+ editing its supported source forms; use the source editor for other AEON forms.
47
+ - **Query:** exercises the Query engine over the SDK namespace. The
48
+ identity-in-Query example selects through an identity chain and shows structural
49
+ provenance. Its inspection limit is shared across the entire Query call.
50
+
51
+ Edits re-evaluate after a short debounce. Use **Run** or **Cmd/Ctrl+Enter** for an
52
+ immediate evaluation. Results show canonical structural paths and available IDs;
53
+ diagnostics show actual codes and identity/limit context. Invalid AEON source
54
+ does not produce partial resolved results.
55
+
56
+ The UI uses the real `resolveAddress` and `createAeonNamespace` APIs, replacing the
57
+ website's custom path matcher. This is a developer source adapter. The matching
58
+ website candidate now has separate SDK-backed Resolve/Query and AEOS composer
59
+ verification; deployment remains held. Trusted identity activation, mutation and
60
+ SO stay guarded. Query identity support
61
+ is explicitly integrated in the source evaluator. Child identities
62
+ remain non-exact, recursive extensions are unchanged, and AEON clone/pointer
63
+ references remain structural paths. Pushing this source branch creates no npm,
64
+ crates.io or GitHub release.
65
+
66
+ The source editor distinguishes structural identity annotations and embedded
67
+ SANSA address literals. Coloring is a lexical aid; actual parsers and consuming
68
+ APIs still determine validity and admission. See [tooling scope](../../docs/child-identity-tooling.md).
69
+
70
+ For complete original/reordered/moved/replacement examples, paste the linked
71
+ [source snapshots](../../fixtures/child-identity-workflows/README.md) into the
72
+ source editor and follow the [workflow guide](../../docs/child-identity-workflows.md).
73
+
74
+ ## Value operations
75
+
76
+ Choose **Value operations** to open `arithmetic.html`. This linked page calls SANSA's
77
+ finite snapshot 0.1 and rational snapshot 0.2 text APIs, with eleven numerical examples,
78
+ verbatim logical JSON and a separate combined-output-policy editor. Exact thirds
79
+ can feed multiplication, explicit quantization or materialization; continuations
80
+ copy the real returned value/history bundle. Editing or changing capability
81
+ clears reusable values. Errors never supply partial values.
82
+
83
+ Each run uses a fresh browser module worker, terminated on completion, cancellation,
84
+ input changes or four-second timeout. Input plus output policy is limited to
85
+ 256 KiB, policy to 16 KiB/depth 8, and result to 1 MiB. Engine defaults still apply
86
+ independently; these controls do not promise a general browser-memory sandbox.
87
+ No trusted resource settings or arbitrary code are accepted by the page. Arithmetic
88
+ imports this checkout's source and needs no document projection, external service
89
+ or Python execution. The shared launcher still loads the built AEON dependency
90
+ for its Resolve/Query page. [API and conformance details](../../docs/aeonic-rational-arithmetic.md).
91
+
92
+ The **Civil dates · snapshot 0.1** capability adds twelve civil-date examples.
93
+ It calls `evaluateAeonicTemporalText` directly, with explicit profile/calendar
94
+ policy in request JSON. Shift, step and materialize continuations copy the entire
95
+ returned date bundle, including precise ranges, origin and clamping history.
96
+ Symbolic outcomes and diagnostics cannot feed date continuations. Numerical
97
+ combined output policies are not offered in this lane. The live description
98
+ follows current request JSON; historical starting-point prose is labeled
99
+ separately. These controls share the same worker/time/input/output bounds above.
100
+ A containing month/year label never widens coverage. See the [civil-date API and
101
+ frozen claim](../../docs/aeonic-temporal-civil-date.md).
102
+
103
+ The **Civil date-times · snapshot 0.1** lane adds exact points/intervals,
104
+ excluded endpoints, reduced dates/clocks, calendar and civil-coordinate clock
105
+ shifts, complete-form stepping and exact materialization. Both origins and both
106
+ histories are displayed separately. Continuations copy the complete bundle;
107
+ step/materialize selectors are explicit, editable policies. No output-family
108
+ convenience mode is offered for temporal lanes. A containing display never widens
109
+ coverage, and clock shifts make no elapsed-time or timezone claim. Eleven
110
+ examples call the SANSA source API in a browser worker. Descriptions follow edited
111
+ requests; diagnostics retain no reusable value. See the
112
+ [date-time API and frozen evidence](../../docs/aeonic-temporal-civil-datetime.md).
113
+
114
+ ## Property selectors (development)
115
+
116
+ Use the coordinated AEON #207 build (or a later build retaining that integration).
117
+ The property examples use the same `createAeonNamespace` metadata facet and
118
+ `resolveAddress` / `evaluateQuery` engines as the SDK;
119
+ this UI has no property parser, tag-field inference or alternate resolver.
120
+ `&key("...")` compares the literal incoming member/attribute key. Empty keys,
121
+ `*` in a key, and Unicode remain literal. Positions are not keys. A selected
122
+ scope root hides its incoming key but retains its intrinsic/direct-head tags;
123
+ `&tag("...")` matches node containers only. `&headTag("...")` matches heads only; neither treats an ordinary field named `tag` as metadata.
124
+
125
+ **Property inspections** is independent of identity inspections: default 10,000,
126
+ maximum 1,000,000, with zero permitted. The value goes to Resolve, or Query's
127
+ shared Resolve allowance, unchanged;
128
+ logical work includes candidates and yielded direct heads, including misses and
129
+ repeated occurrences. Construction, ancestry and other navigation have separate
130
+ costs. Budget failures show the real property/budget/limit/observed fields and
131
+ return no partial results. Parser limit diagnostics retain limitKind too.
132
+
133
+ **Property Query: current row** selects the row's tagged container using `.`.
134
+ **Property Query: scope root** uses `?` to establish the row as a scope root,
135
+ whose incoming key is hidden: the Query retains one candidate with an empty
136
+ Binding Set. Direct read-only property Query is admitted. Portable AEOS validation
137
+ has separate explicit owning APIs; this UI does not turn its other policy or
138
+ mutation paths into that profile. Structural references and stored-address
139
+ activation remain closed. The [support matrix](../../docs/property-selector-support.md)
140
+ distinguishes this SDK-backed UI from the incapable legacy Query Workbench. The SANSA Composer accepts manually entered property suffixes through
141
+ the real parser; automatic property suggestions are not supplied yet.
142
+
143
+ Run the explicit cross-repository integration check after building AEON:
144
+
145
+ ```sh
146
+ node tools/workflows/verify-property-playground.mjs /absolute/path/to/built/aeon
147
+ # Or verify explicitly installed candidate packages:
148
+ node tools/workflows/verify-property-playground.mjs /absolute/path/to/consumer --installed
149
+ ```
150
+
151
+ It checks all 15 property examples as text and parsed AST, scope roots, original
152
+ candidate and selected binding handles, direct heads, inspection diagnostics,
153
+ Query selection and empty Binding Sets. No
154
+ installation, index, mutation or release is performed. Official releases,
155
+ deployment, stable profile promotion and final performance qualification remain
156
+ held; the 1.15x latency / 1.20x memory budgets are unchanged.
157
+
158
+ Results label their actual representation kind. Use the recursive container/head
159
+ examples to compare `&tag` and `&headTag`; add `.*` explicitly to visit head children.
160
+
161
+ Date anchoring uses frozen snapshot 0.1. Select **Date anchoring** in Value
162
+ operations, edit either authored or derived input in the request JSON, and run.
163
+ Clock/date results offer explicit anchoring actions; anchored results offer
164
+ **Shift as date-time**. Continuations preserve complete bundles and prepare an
165
+ explicit receiving profile for review without automatically executing.
@@ -0,0 +1,91 @@
1
+ // Modal focus management reused from aeon-website/html/assets/js/site.js.
2
+ const modalFocusState = new WeakMap();
3
+ const modalFocusableSelector = [
4
+ 'a[href]',
5
+ 'button:not([disabled])',
6
+ 'input:not([disabled]):not([type="hidden"])',
7
+ 'select:not([disabled])',
8
+ 'textarea:not([disabled])',
9
+ '[tabindex]:not([tabindex="-1"])'
10
+ ].join(",");
11
+
12
+ function modalDialog(modal) {
13
+ return modal?.matches?.('[role="dialog"]') ? modal : modal?.querySelector?.('[role="dialog"]');
14
+ }
15
+
16
+ function modalFocusableElements(modal) {
17
+ const dialog = modalDialog(modal);
18
+ if (!dialog) {
19
+ return [];
20
+ }
21
+ return Array.from(dialog.querySelectorAll(modalFocusableSelector))
22
+ .filter((element) => !element.hidden && element.getAttribute("aria-hidden") !== "true" && element.offsetParent !== null);
23
+ }
24
+
25
+ function openAccessibleModal(modal, trigger = document.activeElement, preferredFocus = null) {
26
+ if (!modal) {
27
+ return;
28
+ }
29
+ modalFocusState.set(modal, trigger instanceof HTMLElement ? trigger : null);
30
+ modal.hidden = false;
31
+ if (trigger instanceof HTMLElement && trigger.hasAttribute("aria-expanded")) {
32
+ trigger.setAttribute("aria-expanded", "true");
33
+ }
34
+ document.body.classList.add("has-open-modal");
35
+ window.requestAnimationFrame(() => {
36
+ const dialog = modalDialog(modal);
37
+ const target = preferredFocus instanceof HTMLElement
38
+ ? preferredFocus
39
+ : modalFocusableElements(modal)[0] ?? dialog;
40
+ target?.focus();
41
+ });
42
+ }
43
+
44
+ function closeAccessibleModal(modal) {
45
+ if (!modal) {
46
+ return;
47
+ }
48
+ modal.hidden = true;
49
+ const trigger = modalFocusState.get(modal);
50
+ if (trigger instanceof HTMLElement) {
51
+ if (trigger.hasAttribute("aria-expanded")) {
52
+ trigger.setAttribute("aria-expanded", "false");
53
+ }
54
+ trigger.focus();
55
+ }
56
+ modalFocusState.delete(modal);
57
+ if (!document.querySelector('.site-search:not([hidden]), .playground-modal:not([hidden])')) {
58
+ document.body.classList.remove("has-open-modal");
59
+ }
60
+ }
61
+
62
+ window.AeonAccessibility = {
63
+ openModal: openAccessibleModal,
64
+ closeModal: closeAccessibleModal
65
+ };
66
+
67
+ document.addEventListener("keydown", (event) => {
68
+ if (event.key !== "Tab") {
69
+ return;
70
+ }
71
+ const openModals = Array.from(document.querySelectorAll('.site-search:not([hidden]), .playground-modal:not([hidden])'));
72
+ const modal = openModals[openModals.length - 1];
73
+ if (!modal) {
74
+ return;
75
+ }
76
+ const focusable = modalFocusableElements(modal);
77
+ if (focusable.length === 0) {
78
+ event.preventDefault();
79
+ modalDialog(modal)?.focus();
80
+ return;
81
+ }
82
+ const first = focusable[0];
83
+ const last = focusable[focusable.length - 1];
84
+ if (event.shiftKey && document.activeElement === first) {
85
+ event.preventDefault();
86
+ last.focus();
87
+ } else if (!event.shiftKey && document.activeElement === last) {
88
+ event.preventDefault();
89
+ first.focus();
90
+ }
91
+ });
@@ -0,0 +1,77 @@
1
+ import {highlightAeon as renderAeon, highlightJson} from '@altopelago/aeon-highlight';
2
+
3
+ // Preserve the editor adapter's positional diagnostic API.
4
+ function highlightAeon(source, line = null, column = 1) {
5
+ return renderAeon(source, {diagnosticLine: line, diagnosticColumn: column});
6
+ }
7
+
8
+ function attachHighlightEditor(textarea, backdrop) {
9
+ const editor = textarea.closest(".highlight-editor");
10
+ let gutter = editor?.querySelector(".highlight-line-numbers") ?? null;
11
+ if (editor && !gutter) {
12
+ gutter = document.createElement("div");
13
+ gutter.className = "highlight-line-numbers";
14
+ gutter.setAttribute("aria-hidden", "true");
15
+ editor.insertBefore(gutter, editor.firstChild);
16
+ }
17
+
18
+ const sync = () => {
19
+ const code = backdrop.querySelector("code");
20
+ const diagnosticLine = Number.parseInt(textarea.dataset.aeonDiagnosticLine ?? "", 10);
21
+ const diagnosticColumn = Number.parseInt(textarea.dataset.aeonDiagnosticColumn ?? "", 10);
22
+ code.innerHTML = highlightAeon(
23
+ textarea.value,
24
+ Number.isInteger(diagnosticLine) && diagnosticLine > 0 ? diagnosticLine : null,
25
+ Number.isInteger(diagnosticColumn) && diagnosticColumn > 0 ? diagnosticColumn : 1
26
+ ) + "\n";
27
+ if (gutter) {
28
+ const lineCount = Math.max(1, textarea.value.split("\n").length);
29
+ gutter.innerHTML = Array.from({ length: lineCount }, (_, index) => {
30
+ const line = index + 1;
31
+ const className = line === diagnosticLine ? ' class="has-diagnostic"' : "";
32
+ return `<span${className}>${line}</span>`;
33
+ }).join("");
34
+ }
35
+ };
36
+
37
+ textarea.addEventListener("input", sync);
38
+ textarea.addEventListener("aeon:diagnostic-change", sync);
39
+ textarea.addEventListener("scroll", () => {
40
+ backdrop.scrollTop = textarea.scrollTop;
41
+ backdrop.scrollLeft = textarea.scrollLeft;
42
+ if (gutter) {
43
+ gutter.scrollTop = textarea.scrollTop;
44
+ }
45
+ });
46
+
47
+ sync();
48
+ }
49
+
50
+ function setEditorDiagnosticLine(textarea, line, column = null) {
51
+ if (Number.isInteger(line) && line > 0) {
52
+ textarea.dataset.aeonDiagnosticLine = String(line);
53
+ if (Number.isInteger(column) && column > 0) {
54
+ textarea.dataset.aeonDiagnosticColumn = String(column);
55
+ } else {
56
+ delete textarea.dataset.aeonDiagnosticColumn;
57
+ }
58
+ } else {
59
+ delete textarea.dataset.aeonDiagnosticLine;
60
+ delete textarea.dataset.aeonDiagnosticColumn;
61
+ }
62
+ textarea.dispatchEvent(new Event("aeon:diagnostic-change"));
63
+ }
64
+
65
+ function renderStaticBlocks() {
66
+ document.querySelectorAll("[data-aeon-static]").forEach((block) => {
67
+ block.innerHTML = highlightAeon(block.textContent || "") + "\n";
68
+ });
69
+ }
70
+
71
+ window.AeonWebHighlight = {
72
+ highlightAeon,
73
+ highlightJson,
74
+ attachHighlightEditor,
75
+ setEditorDiagnosticLine,
76
+ renderStaticBlocks
77
+ };