@velarscript/web 0.29.2 → 0.30.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.
Files changed (72) hide show
  1. package/README.md +10 -2
  2. package/dist/analysis/look-values.d.ts +76 -1
  3. package/dist/analysis/look-values.d.ts.map +1 -1
  4. package/dist/analysis/look-values.js +193 -0
  5. package/dist/analysis/look-values.js.map +1 -1
  6. package/dist/analysis/reactive-names.d.ts +50 -0
  7. package/dist/analysis/reactive-names.d.ts.map +1 -0
  8. package/dist/analysis/reactive-names.js +199 -0
  9. package/dist/analysis/reactive-names.js.map +1 -0
  10. package/dist/analysis/watch-cycles.d.ts +28 -0
  11. package/dist/analysis/watch-cycles.d.ts.map +1 -1
  12. package/dist/analysis/watch-cycles.js +47 -0
  13. package/dist/analysis/watch-cycles.js.map +1 -1
  14. package/dist/analyzer.d.ts +5 -1
  15. package/dist/analyzer.d.ts.map +1 -1
  16. package/dist/analyzer.js +50 -60
  17. package/dist/analyzer.js.map +1 -1
  18. package/dist/compiler.d.ts +1 -1
  19. package/dist/compiler.js +2 -2
  20. package/dist/compiler.js.map +1 -1
  21. package/dist/css-string.d.ts +4 -10
  22. package/dist/css-string.d.ts.map +1 -1
  23. package/dist/css-string.js +4 -27
  24. package/dist/css-string.js.map +1 -1
  25. package/dist/emitter.d.ts.map +1 -1
  26. package/dist/emitter.js +11 -2090
  27. package/dist/emitter.js.map +1 -1
  28. package/dist/lexer.js +63 -43
  29. package/dist/lexer.js.map +1 -1
  30. package/dist/look-static.d.ts +15 -1
  31. package/dist/look-static.d.ts.map +1 -1
  32. package/dist/look-static.js +30 -11
  33. package/dist/look-static.js.map +1 -1
  34. package/dist/look.d.ts +4 -4
  35. package/dist/look.d.ts.map +1 -1
  36. package/dist/look.js +4 -4
  37. package/dist/look.js.map +1 -1
  38. package/dist/parser.js +1 -2
  39. package/dist/parser.js.map +1 -1
  40. package/dist/runtime-sources.generated.d.ts +89 -0
  41. package/dist/runtime-sources.generated.d.ts.map +1 -0
  42. package/dist/runtime-sources.generated.js +96 -0
  43. package/dist/runtime-sources.generated.js.map +1 -0
  44. package/dist/runtime.d.ts +18 -0
  45. package/dist/runtime.d.ts.map +1 -1
  46. package/dist/runtime.js +31 -3742
  47. package/dist/runtime.js.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/browser-host-runtime.d.ts +0 -23
  50. package/dist/browser-host-runtime.d.ts.map +0 -1
  51. package/dist/browser-host-runtime.js +0 -29
  52. package/dist/browser-host-runtime.js.map +0 -1
  53. package/dist/reactive-bridge-runtime.d.ts +0 -6
  54. package/dist/reactive-bridge-runtime.d.ts.map +0 -1
  55. package/dist/reactive-bridge-runtime.js +0 -114
  56. package/dist/reactive-bridge-runtime.js.map +0 -1
  57. package/dist/realtime-client-runtime.d.ts +0 -3
  58. package/dist/realtime-client-runtime.d.ts.map +0 -1
  59. package/dist/realtime-client-runtime.js +0 -382
  60. package/dist/realtime-client-runtime.js.map +0 -1
  61. package/dist/runtime-foundation.d.ts +0 -7
  62. package/dist/runtime-foundation.d.ts.map +0 -1
  63. package/dist/runtime-foundation.js +0 -1676
  64. package/dist/runtime-foundation.js.map +0 -1
  65. package/dist/websocket-runtime.d.ts +0 -2
  66. package/dist/websocket-runtime.d.ts.map +0 -1
  67. package/dist/websocket-runtime.js +0 -37
  68. package/dist/websocket-runtime.js.map +0 -1
  69. package/dist/worker-runtime.d.ts +0 -2
  70. package/dist/worker-runtime.d.ts.map +0 -1
  71. package/dist/worker-runtime.js +0 -83
  72. package/dist/worker-runtime.js.map +0 -1
@@ -1,1676 +0,0 @@
1
- import { VELAR_ERROR_NORMALIZATION_RUNTIME, VELAR_RUNTIME_REGISTRY_KEY, VELAR_RUNTIME_SCHEMA_VERSION, } from "@velarscript/compiler/extension";
2
- export const WEB_DOM_HOST_RUNTIME = String.raw `
3
- const __velarDomNativeObject = globalThis.Object;
4
- const __velarDomNativeArray = globalThis.Array;
5
- const __velarDomNativeSet = globalThis.Set;
6
- const __velarDomNativeNumber = globalThis.Number;
7
- const __velarDomNativeString = globalThis.String;
8
- const __velarDomNativeSymbol = globalThis.Symbol;
9
- const __velarDomReflectApply = Object.getOwnPropertyDescriptor(Reflect, "apply")?.value;
10
- const __velarDomGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(Object, "getOwnPropertyDescriptor")?.value;
11
- const __velarDomGetOwnPropertyNames = Object.getOwnPropertyDescriptor(Object, "getOwnPropertyNames")?.value;
12
- const __velarDomGetOwnPropertySymbols = Object.getOwnPropertyDescriptor(Object, "getOwnPropertySymbols")?.value;
13
- const __velarDomGetPrototypeOf = Object.getOwnPropertyDescriptor(Object, "getPrototypeOf")?.value;
14
- const __velarDomDefineProperty = Object.getOwnPropertyDescriptor(Object, "defineProperty")?.value;
15
- const __velarDomArrayIsArray = Object.getOwnPropertyDescriptor(Array, "isArray")?.value;
16
- const __velarDomNumberIsFinite = Object.getOwnPropertyDescriptor(Number, "isFinite")?.value;
17
- const __velarDomNumberIsInteger = Object.getOwnPropertyDescriptor(Number, "isInteger")?.value;
18
- const __velarDomSymbolHasInstance = typeof __velarDomNativeSymbol === "function" ? __velarDomNativeSymbol.hasInstance : null;
19
- const __velarDomFunctionHasInstance = __velarDomSymbolHasInstance == null
20
- ? null
21
- : Object.getOwnPropertyDescriptor(Function.prototype, __velarDomSymbolHasInstance)?.value;
22
- const __velarDomSetPrototype = typeof __velarDomNativeSet === "function"
23
- ? Object.getOwnPropertyDescriptor(__velarDomNativeSet, "prototype")?.value
24
- : null;
25
- const __velarDomSetHas = __velarDomSetPrototype && Object.getOwnPropertyDescriptor(__velarDomSetPrototype, "has")?.value;
26
- const __velarDomSetAdd = __velarDomSetPrototype && Object.getOwnPropertyDescriptor(__velarDomSetPrototype, "add")?.value;
27
- const __velarDomSetDelete = __velarDomSetPrototype && Object.getOwnPropertyDescriptor(__velarDomSetPrototype, "delete")?.value;
28
- const __velarDomDocument = globalThis.document ?? null;
29
- const __velarDomNativeNode = typeof globalThis.Node === "function" ? globalThis.Node : null;
30
- const __velarDomNativeElement = typeof globalThis.Element === "function" ? globalThis.Element : null;
31
- const __velarDomNativeDocument = typeof globalThis.Document === "function" ? globalThis.Document : null;
32
- const __velarDomNativeFragment = typeof globalThis.DocumentFragment === "function" ? globalThis.DocumentFragment : null;
33
- const __velarDomNativeCharacterData = typeof globalThis.CharacterData === "function" ? globalThis.CharacterData : null;
34
- const __velarDomNativeDocumentType = typeof globalThis.DocumentType === "function" ? globalThis.DocumentType : null;
35
- const __velarDomNativeNodeList = typeof globalThis.NodeList === "function" ? globalThis.NodeList : null;
36
- const __velarDomNativeEventTarget = typeof globalThis.EventTarget === "function" ? globalThis.EventTarget : null;
37
- const __velarDomNativeHtmlElement = typeof globalThis.HTMLElement === "function" ? globalThis.HTMLElement : null;
38
- const __velarDomNativeSvgElement = typeof globalThis.SVGElement === "function" ? globalThis.SVGElement : null;
39
- const __velarDomNativeStyleDeclaration = typeof globalThis.CSSStyleDeclaration === "function" ? globalThis.CSSStyleDeclaration : null;
40
- const __velarDomNativeTokenList = typeof globalThis.DOMTokenList === "function" ? globalThis.DOMTokenList : null;
41
- const __velarDomNativeInputElement = typeof globalThis.HTMLInputElement === "function" ? globalThis.HTMLInputElement : null;
42
- const __velarDomNativeTextAreaElement = typeof globalThis.HTMLTextAreaElement === "function" ? globalThis.HTMLTextAreaElement : null;
43
- const __velarDomNativeSelectElement = typeof globalThis.HTMLSelectElement === "function" ? globalThis.HTMLSelectElement : null;
44
- function __velarDomApply(operation, receiver, arguments_, label) {
45
- if (typeof operation !== "function" || typeof __velarDomReflectApply !== "function") {
46
- throw new TypeError("The browser " + label + " API is unavailable");
47
- }
48
- return __velarDomReflectApply(operation, receiver, arguments_);
49
- }
50
- function __velarDomOwnDescriptor(value, name) {
51
- if ((typeof value !== "object" && typeof value !== "function") || value === null
52
- || typeof __velarDomGetOwnPropertyDescriptor !== "function" || typeof __velarDomReflectApply !== "function") return null;
53
- return __velarDomReflectApply(__velarDomGetOwnPropertyDescriptor, __velarDomNativeObject, [value, name]) ?? null;
54
- }
55
- function __velarDomMember(value, name, kind = "value") {
56
- if ((typeof value !== "object" && typeof value !== "function") || value === null) return null;
57
- let current = value;
58
- for (let depth = 0; current && depth < 32; depth += 1) {
59
- const descriptor = __velarDomOwnDescriptor(current, name);
60
- if (descriptor) {
61
- const member = kind === "get" ? descriptor.get : kind === "set" ? descriptor.set : "value" in descriptor ? descriptor.value : null;
62
- return typeof member === "function" ? member : null;
63
- }
64
- if (typeof __velarDomGetPrototypeOf !== "function" || typeof __velarDomReflectApply !== "function") return null;
65
- current = __velarDomReflectApply(__velarDomGetPrototypeOf, __velarDomNativeObject, [current]);
66
- }
67
- return null;
68
- }
69
- function __velarDomPrototype(constructor) {
70
- return typeof constructor === "function" ? __velarDomOwnDescriptor(constructor, "prototype")?.value ?? null : null;
71
- }
72
- function __velarDomPrototypeMember(constructor, name, kind = "value") {
73
- return __velarDomMember(__velarDomPrototype(constructor), name, kind);
74
- }
75
- function __velarDomInstance(value, constructor) {
76
- if (typeof constructor !== "function" || typeof __velarDomFunctionHasInstance !== "function") return false;
77
- try { return __velarDomApply(__velarDomFunctionHasInstance, constructor, [value], "Node identity"); }
78
- catch { return false; }
79
- }
80
- const __velarDomDocumentCreateElement = __velarDomMember(__velarDomDocument, "createElement");
81
- const __velarDomDocumentCreateElementNS = __velarDomMember(__velarDomDocument, "createElementNS");
82
- const __velarDomDocumentCreateTextNode = __velarDomMember(__velarDomDocument, "createTextNode");
83
- const __velarDomDocumentCreateComment = __velarDomMember(__velarDomDocument, "createComment");
84
- const __velarDomDocumentCreateFragment = __velarDomMember(__velarDomDocument, "createDocumentFragment");
85
- const __velarDomDocumentQuerySelector = __velarDomMember(__velarDomDocument, "querySelector");
86
- const __velarDomNodeNodeType = __velarDomPrototypeMember(__velarDomNativeNode, "nodeType", "get");
87
- const __velarDomNodeChildNodes = __velarDomPrototypeMember(__velarDomNativeNode, "childNodes", "get");
88
- const __velarDomNodeInsertBefore = __velarDomPrototypeMember(__velarDomNativeNode, "insertBefore");
89
- const __velarDomNodeReplaceChildren = __velarDomPrototypeMember(__velarDomNativeNode, "replaceChildren");
90
- const __velarDomNodeAppend = __velarDomPrototypeMember(__velarDomNativeNode, "append");
91
- const __velarDomNodeTextContentSet = __velarDomPrototypeMember(__velarDomNativeNode, "textContent", "set");
92
- const __velarDomCharacterDataDataSet = __velarDomPrototypeMember(__velarDomNativeCharacterData, "data", "set");
93
- const __velarDomElementAppend = __velarDomPrototypeMember(__velarDomNativeElement, "append");
94
- const __velarDomElementReplaceChildren = __velarDomPrototypeMember(__velarDomNativeElement, "replaceChildren");
95
- const __velarDomDocumentAppend = __velarDomPrototypeMember(__velarDomNativeDocument, "append");
96
- const __velarDomDocumentReplaceChildren = __velarDomPrototypeMember(__velarDomNativeDocument, "replaceChildren");
97
- const __velarDomFragmentAppend = __velarDomPrototypeMember(__velarDomNativeFragment, "append");
98
- const __velarDomFragmentReplaceChildren = __velarDomPrototypeMember(__velarDomNativeFragment, "replaceChildren");
99
- const __velarDomNodeRemove = __velarDomPrototypeMember(__velarDomNativeNode, "remove");
100
- const __velarDomElementRemove = __velarDomPrototypeMember(__velarDomNativeElement, "remove");
101
- const __velarDomCharacterDataRemove = __velarDomPrototypeMember(__velarDomNativeCharacterData, "remove");
102
- const __velarDomDocumentTypeRemove = __velarDomPrototypeMember(__velarDomNativeDocumentType, "remove");
103
- const __velarDomNodeBefore = __velarDomPrototypeMember(__velarDomNativeNode, "before");
104
- const __velarDomElementBefore = __velarDomPrototypeMember(__velarDomNativeElement, "before");
105
- const __velarDomCharacterDataBefore = __velarDomPrototypeMember(__velarDomNativeCharacterData, "before");
106
- const __velarDomDocumentTypeBefore = __velarDomPrototypeMember(__velarDomNativeDocumentType, "before");
107
- const __velarDomNodeSetAttribute = __velarDomPrototypeMember(__velarDomNativeNode, "setAttribute");
108
- const __velarDomElementSetAttribute = __velarDomPrototypeMember(__velarDomNativeElement, "setAttribute");
109
- const __velarDomElementSetAttributeNS = __velarDomPrototypeMember(__velarDomNativeElement, "setAttributeNS");
110
- const __velarDomNodeRemoveAttribute = __velarDomPrototypeMember(__velarDomNativeNode, "removeAttribute");
111
- const __velarDomElementRemoveAttribute = __velarDomPrototypeMember(__velarDomNativeElement, "removeAttribute");
112
- const __velarDomElementRemoveAttributeNS = __velarDomPrototypeMember(__velarDomNativeElement, "removeAttributeNS");
113
- const __velarDomNodeListLength = __velarDomPrototypeMember(__velarDomNativeNodeList, "length", "get");
114
- const __velarDomNodeListItem = __velarDomPrototypeMember(__velarDomNativeNodeList, "item");
115
- const __velarDomNodeNextSibling = __velarDomPrototypeMember(__velarDomNativeNode, "nextSibling", "get");
116
- const __velarDomNodeAddListener = __velarDomPrototypeMember(__velarDomNativeNode, "addEventListener");
117
- const __velarDomNodeRemoveListener = __velarDomPrototypeMember(__velarDomNativeNode, "removeEventListener");
118
- const __velarDomNodeInnerHtml = __velarDomPrototypeMember(__velarDomNativeNode, "innerHTML", "set");
119
- const __velarDomNodeQuerySelectorAll = __velarDomPrototypeMember(__velarDomNativeNode, "querySelectorAll");
120
- const __velarDomNodeClassList = __velarDomPrototypeMember(__velarDomNativeNode, "classList", "get");
121
- const __velarDomNodeStyle = __velarDomPrototypeMember(__velarDomNativeNode, "style", "get");
122
- const __velarDomNodeFieldValue = __velarDomPrototypeMember(__velarDomNativeNode, "value", "get");
123
- const __velarDomNodeSetFieldValue = __velarDomPrototypeMember(__velarDomNativeNode, "value", "set");
124
- const __velarDomNodeFieldNumber = __velarDomPrototypeMember(__velarDomNativeNode, "valueAsNumber", "get");
125
- const __velarDomNodeFieldChecked = __velarDomPrototypeMember(__velarDomNativeNode, "checked", "get");
126
- const __velarDomNodeSetFieldChecked = __velarDomPrototypeMember(__velarDomNativeNode, "checked", "set");
127
- const __velarDomEventTargetAdd = __velarDomPrototypeMember(__velarDomNativeEventTarget, "addEventListener");
128
- const __velarDomEventTargetRemove = __velarDomPrototypeMember(__velarDomNativeEventTarget, "removeEventListener");
129
- const __velarDomElementInnerHtml = __velarDomPrototypeMember(__velarDomNativeElement, "innerHTML", "set");
130
- const __velarDomElementQuerySelectorAll = __velarDomPrototypeMember(__velarDomNativeElement, "querySelectorAll");
131
- const __velarDomElementClassList = __velarDomPrototypeMember(__velarDomNativeElement, "classList", "get");
132
- const __velarDomHtmlElementStyle = __velarDomPrototypeMember(__velarDomNativeHtmlElement, "style", "get");
133
- const __velarDomSvgElementStyle = __velarDomPrototypeMember(__velarDomNativeSvgElement, "style", "get");
134
- const __velarDomStyleSetProperty = __velarDomPrototypeMember(__velarDomNativeStyleDeclaration, "setProperty");
135
- const __velarDomStyleRemoveProperty = __velarDomPrototypeMember(__velarDomNativeStyleDeclaration, "removeProperty");
136
- const __velarDomStylePropertyValue = __velarDomPrototypeMember(__velarDomNativeStyleDeclaration, "getPropertyValue");
137
- const __velarDomStylePropertyPriority = __velarDomPrototypeMember(__velarDomNativeStyleDeclaration, "getPropertyPriority");
138
- const __velarDomTokenListAdd = __velarDomPrototypeMember(__velarDomNativeTokenList, "add");
139
- const __velarDomTokenListRemove = __velarDomPrototypeMember(__velarDomNativeTokenList, "remove");
140
- const __velarDomTokenListLength = __velarDomPrototypeMember(__velarDomNativeTokenList, "length", "get");
141
- const __velarDomTokenListItem = __velarDomPrototypeMember(__velarDomNativeTokenList, "item");
142
- const __velarDomInputValueGet = __velarDomPrototypeMember(__velarDomNativeInputElement, "value", "get");
143
- const __velarDomInputValueSet = __velarDomPrototypeMember(__velarDomNativeInputElement, "value", "set");
144
- const __velarDomInputNumberGet = __velarDomPrototypeMember(__velarDomNativeInputElement, "valueAsNumber", "get");
145
- const __velarDomInputCheckedGet = __velarDomPrototypeMember(__velarDomNativeInputElement, "checked", "get");
146
- const __velarDomInputCheckedSet = __velarDomPrototypeMember(__velarDomNativeInputElement, "checked", "set");
147
- const __velarDomTextAreaValueGet = __velarDomPrototypeMember(__velarDomNativeTextAreaElement, "value", "get");
148
- const __velarDomTextAreaValueSet = __velarDomPrototypeMember(__velarDomNativeTextAreaElement, "value", "set");
149
- const __velarDomSelectValueGet = __velarDomPrototypeMember(__velarDomNativeSelectElement, "value", "get");
150
- const __velarDomSelectValueSet = __velarDomPrototypeMember(__velarDomNativeSelectElement, "value", "set");
151
- function __velarDomOwnData(value, name) {
152
- const descriptor = __velarDomOwnDescriptor(value, name);
153
- return descriptor?.enumerable && "value" in descriptor ? descriptor.value : undefined;
154
- }
155
- function __velarDomOwnMethod(value, name) {
156
- const method = __velarDomOwnData(value, name);
157
- return typeof method === "function" ? method : null;
158
- }
159
- function __velarDomNodeOperation(value, name, candidates, arguments_) {
160
- for (let index = 0; index < candidates.length; index += 1) {
161
- const candidate = candidates[index];
162
- if (__velarDomInstance(value, candidate[0]) && typeof candidate[1] === "function") {
163
- return __velarDomApply(candidate[1], value, arguments_, "DOM " + name);
164
- }
165
- }
166
- const own = __velarDomOwnMethod(value, name);
167
- if (own) return __velarDomApply(own, value, arguments_, "DOM " + name);
168
- throw new TypeError("The value does not expose native DOM " + name);
169
- }
170
- function __velarDomCreateElement(tag) { return __velarDomApply(__velarDomDocumentCreateElement, __velarDomDocument, [tag], "document.createElement"); }
171
- function __velarDomCreateElementNS(namespace, tag) { return __velarDomApply(__velarDomDocumentCreateElementNS, __velarDomDocument, [namespace, tag], "document.createElementNS"); }
172
- function __velarDomCreateTextNode(value) { return __velarDomApply(__velarDomDocumentCreateTextNode, __velarDomDocument, [value], "document.createTextNode"); }
173
- function __velarDomCreateComment(value) { return __velarDomApply(__velarDomDocumentCreateComment, __velarDomDocument, [value], "document.createComment"); }
174
- function __velarDomCreateFragment() { return __velarDomApply(__velarDomDocumentCreateFragment, __velarDomDocument, [], "document.createDocumentFragment"); }
175
- function __velarDomQuerySelector(value) { return __velarDomApply(__velarDomDocumentQuerySelector, __velarDomDocument, [value], "document.querySelector"); }
176
- function __velarDomAppend(value, ...children) {
177
- return __velarDomNodeOperation(value, "append", [
178
- [__velarDomNativeNode, __velarDomNodeAppend], [__velarDomNativeElement, __velarDomElementAppend],
179
- [__velarDomNativeDocument, __velarDomDocumentAppend], [__velarDomNativeFragment, __velarDomFragmentAppend],
180
- ], children);
181
- }
182
- function __velarDomInsertBefore(value, child, before = null) {
183
- return __velarDomNodeOperation(value, "insertBefore", [[__velarDomNativeNode, __velarDomNodeInsertBefore]], [child, before]);
184
- }
185
- function __velarDomReplaceChildren(value, ...children) {
186
- return __velarDomNodeOperation(value, "replaceChildren", [
187
- [__velarDomNativeNode, __velarDomNodeReplaceChildren], [__velarDomNativeElement, __velarDomElementReplaceChildren],
188
- [__velarDomNativeDocument, __velarDomDocumentReplaceChildren], [__velarDomNativeFragment, __velarDomFragmentReplaceChildren],
189
- ], children);
190
- }
191
- function __velarDomRemove(value) {
192
- return __velarDomNodeOperation(value, "remove", [
193
- [__velarDomNativeNode, __velarDomNodeRemove], [__velarDomNativeElement, __velarDomElementRemove],
194
- [__velarDomNativeCharacterData, __velarDomCharacterDataRemove], [__velarDomNativeDocumentType, __velarDomDocumentTypeRemove],
195
- ], []);
196
- }
197
- function __velarDomBefore(value, child) {
198
- return __velarDomNodeOperation(value, "before", [
199
- [__velarDomNativeNode, __velarDomNodeBefore], [__velarDomNativeElement, __velarDomElementBefore],
200
- [__velarDomNativeCharacterData, __velarDomCharacterDataBefore], [__velarDomNativeDocumentType, __velarDomDocumentTypeBefore],
201
- ], [child]);
202
- }
203
- function __velarDomSetAttribute(value, name, next) {
204
- return __velarDomNodeOperation(value, "setAttribute", [
205
- [__velarDomNativeNode, __velarDomNodeSetAttribute], [__velarDomNativeElement, __velarDomElementSetAttribute],
206
- ], [name, next]);
207
- }
208
- function __velarDomSetAttributeNS(value, namespace, name, next) {
209
- return __velarDomNodeOperation(value, "setAttributeNS", [[__velarDomNativeElement, __velarDomElementSetAttributeNS]], [namespace, name, next]);
210
- }
211
- function __velarDomRemoveAttribute(value, name) {
212
- return __velarDomNodeOperation(value, "removeAttribute", [
213
- [__velarDomNativeNode, __velarDomNodeRemoveAttribute], [__velarDomNativeElement, __velarDomElementRemoveAttribute],
214
- ], [name]);
215
- }
216
- function __velarDomRemoveAttributeNS(value, namespace, name) {
217
- return __velarDomNodeOperation(value, "removeAttributeNS", [[__velarDomNativeElement, __velarDomElementRemoveAttributeNS]], [namespace, name]);
218
- }
219
- // Accessor twin of __velarDomNodeOperation: the framework reads and writes a
220
- // handful of host properties (style, classList, innerHTML, field value) whose
221
- // prototypes are as replaceable as the methods above, so they go through the
222
- // same captured-then-own-data-descriptor path instead of ambient '.' access.
223
- function __velarDomNodeAccessor(value, name, candidates, arguments_, write) {
224
- for (let index = 0; index < candidates.length; index += 1) {
225
- const candidate = candidates[index];
226
- if (__velarDomInstance(value, candidate[0]) && typeof candidate[1] === "function") {
227
- return __velarDomApply(candidate[1], value, arguments_, "DOM " + name);
228
- }
229
- }
230
- const descriptor = __velarDomOwnDescriptor(value, name);
231
- if (!write) {
232
- if (descriptor && "value" in descriptor) return descriptor.value;
233
- throw new TypeError("The value does not expose native DOM " + name);
234
- }
235
- if (typeof __velarDomDefineProperty !== "function" || typeof __velarDomReflectApply !== "function"
236
- || (descriptor && (!("value" in descriptor) || descriptor.writable !== true))) {
237
- throw new TypeError("The value does not expose native DOM " + name);
238
- }
239
- return __velarDomReflectApply(__velarDomDefineProperty, __velarDomNativeObject, [value, name, descriptor
240
- ? { ...descriptor, value: arguments_[0] }
241
- : { value: arguments_[0], writable: true, enumerable: true, configurable: true }]);
242
- }
243
- function __velarDomNextSibling(value) {
244
- if (__velarDomInstance(value, __velarDomNativeNode) && typeof __velarDomNodeNextSibling === "function") {
245
- return __velarDomApply(__velarDomNodeNextSibling, value, [], "Node.nextSibling");
246
- }
247
- return null;
248
- }
249
- function __velarDomAddListener(value, name, listener, options) {
250
- return __velarDomNodeOperation(value, "addEventListener", [
251
- [__velarDomNativeNode, __velarDomNodeAddListener], [__velarDomNativeEventTarget, __velarDomEventTargetAdd],
252
- ], [name, listener, options]);
253
- }
254
- function __velarDomRemoveListener(value, name, listener, options) {
255
- return __velarDomNodeOperation(value, "removeEventListener", [
256
- [__velarDomNativeNode, __velarDomNodeRemoveListener], [__velarDomNativeEventTarget, __velarDomEventTargetRemove],
257
- ], [name, listener, options]);
258
- }
259
- // The in-place text update. A scalar interpolation owns one text node for its
260
- // whole life and rewrites its character data rather than replacing the node, so
261
- // 'data' joins the captured accessor ABI beside 'innerHTML' and 'value': a
262
- // planted CharacterData.prototype setter must not be able to observe or divert
263
- // what the framework writes into its own node.
264
- function __velarDomSetData(value, next) {
265
- return __velarDomNodeAccessor(value, "data", [[__velarDomNativeCharacterData, __velarDomCharacterDataDataSet]], [next], true);
266
- }
267
- function __velarDomSetHtml(value, next) {
268
- return __velarDomNodeAccessor(value, "innerHTML", [
269
- [__velarDomNativeNode, __velarDomNodeInnerHtml], [__velarDomNativeElement, __velarDomElementInnerHtml],
270
- ], [next], true);
271
- }
272
- function __velarDomQuerySelectorAll(value, selector) {
273
- return __velarDomNodeOperation(value, "querySelectorAll", [
274
- [__velarDomNativeNode, __velarDomNodeQuerySelectorAll], [__velarDomNativeElement, __velarDomElementQuerySelectorAll],
275
- ], [selector]);
276
- }
277
- function __velarDomStyle(value) {
278
- return __velarDomNodeAccessor(value, "style", [
279
- [__velarDomNativeNode, __velarDomNodeStyle], [__velarDomNativeHtmlElement, __velarDomHtmlElementStyle],
280
- [__velarDomNativeSvgElement, __velarDomSvgElementStyle],
281
- ], [], false);
282
- }
283
- function __velarDomStyleValue(value, property) {
284
- return __velarDomNodeOperation(__velarDomStyle(value), "getPropertyValue", [[__velarDomNativeStyleDeclaration, __velarDomStylePropertyValue]], [property]);
285
- }
286
- function __velarDomStylePriority(value, property) {
287
- return __velarDomNodeOperation(__velarDomStyle(value), "getPropertyPriority", [[__velarDomNativeStyleDeclaration, __velarDomStylePropertyPriority]], [property]);
288
- }
289
- function __velarDomStyleWrite(value, property, next, priority = "") {
290
- return __velarDomNodeOperation(__velarDomStyle(value), "setProperty", [[__velarDomNativeStyleDeclaration, __velarDomStyleSetProperty]], [property, next, priority]);
291
- }
292
- function __velarDomStyleClear(value, property) {
293
- return __velarDomNodeOperation(__velarDomStyle(value), "removeProperty", [[__velarDomNativeStyleDeclaration, __velarDomStyleRemoveProperty]], [property]);
294
- }
295
- function __velarDomClassList(value) {
296
- return __velarDomNodeAccessor(value, "classList", [
297
- [__velarDomNativeNode, __velarDomNodeClassList], [__velarDomNativeElement, __velarDomElementClassList],
298
- ], [], false);
299
- }
300
- function __velarDomClassInsert(value, name) {
301
- return __velarDomNodeOperation(__velarDomClassList(value), "add", [[__velarDomNativeTokenList, __velarDomTokenListAdd]], [name]);
302
- }
303
- function __velarDomClassRemove(value, name) {
304
- return __velarDomNodeOperation(__velarDomClassList(value), "remove", [[__velarDomNativeTokenList, __velarDomTokenListRemove]], [name]);
305
- }
306
- function __velarDomClassNames(value) {
307
- const list = __velarDomClassList(value);
308
- const length = __velarDomInstance(list, __velarDomNativeTokenList) && typeof __velarDomTokenListLength === "function"
309
- ? __velarDomApply(__velarDomTokenListLength, list, [], "DOMTokenList.length")
310
- : __velarDomOwnData(list, "length");
311
- // A data-only seam that exposes no bounded token list simply owns no base
312
- // classes; only a real token list can contribute names the framework must
313
- // preserve while it manages the rest.
314
- if (!__velarDomIsInteger(length) || length < 0 || length > 1000000) return new __velarDomNativeArray(0);
315
- const output = new __velarDomNativeArray(length);
316
- for (let index = 0; index < length; index += 1) {
317
- output[index] = __velarDomNodeOperation(list, "item", [[__velarDomNativeTokenList, __velarDomTokenListItem]], [index]);
318
- }
319
- return output;
320
- }
321
- function __velarDomFieldValue(value) {
322
- return __velarDomNodeAccessor(value, "value", [
323
- [__velarDomNativeNode, __velarDomNodeFieldValue], [__velarDomNativeInputElement, __velarDomInputValueGet],
324
- [__velarDomNativeTextAreaElement, __velarDomTextAreaValueGet], [__velarDomNativeSelectElement, __velarDomSelectValueGet],
325
- ], [], false);
326
- }
327
- function __velarDomSetFieldValue(value, next) {
328
- return __velarDomNodeAccessor(value, "value", [
329
- [__velarDomNativeNode, __velarDomNodeSetFieldValue], [__velarDomNativeInputElement, __velarDomInputValueSet],
330
- [__velarDomNativeTextAreaElement, __velarDomTextAreaValueSet], [__velarDomNativeSelectElement, __velarDomSelectValueSet],
331
- ], [next], true);
332
- }
333
- function __velarDomFieldNumber(value) {
334
- return __velarDomNodeAccessor(value, "valueAsNumber", [
335
- [__velarDomNativeNode, __velarDomNodeFieldNumber], [__velarDomNativeInputElement, __velarDomInputNumberGet],
336
- ], [], false);
337
- }
338
- function __velarDomFieldChecked(value) {
339
- return __velarDomNodeAccessor(value, "checked", [
340
- [__velarDomNativeNode, __velarDomNodeFieldChecked], [__velarDomNativeInputElement, __velarDomInputCheckedGet],
341
- ], [], false);
342
- }
343
- function __velarDomSetFieldChecked(value, next) {
344
- return __velarDomNodeAccessor(value, "checked", [
345
- [__velarDomNativeNode, __velarDomNodeSetFieldChecked], [__velarDomNativeInputElement, __velarDomInputCheckedSet],
346
- ], [next], true);
347
- }
348
- function __velarDomNodeType(value) {
349
- if (__velarDomInstance(value, __velarDomNativeNode) && typeof __velarDomNodeNodeType === "function") {
350
- return __velarDomApply(__velarDomNodeNodeType, value, [], "Node.nodeType");
351
- }
352
- const nodeType = __velarDomOwnData(value, "nodeType");
353
- return typeof nodeType === "number" ? nodeType : null;
354
- }
355
- function __velarDomSetText(value, next) {
356
- if (__velarDomInstance(value, __velarDomNativeNode) && typeof __velarDomNodeTextContentSet === "function") {
357
- return __velarDomApply(__velarDomNodeTextContentSet, value, [next], "Node.textContent");
358
- }
359
- const descriptor = __velarDomOwnDescriptor(value, "textContent");
360
- if (!descriptor?.enumerable || !("value" in descriptor) || descriptor.writable !== true
361
- || typeof __velarDomDefineProperty !== "function" || typeof __velarDomReflectApply !== "function") {
362
- throw new TypeError("The value does not expose native DOM textContent");
363
- }
364
- return __velarDomReflectApply(__velarDomDefineProperty, __velarDomNativeObject, [value, "textContent", { ...descriptor, value: next }]);
365
- }
366
- function __velarDomIsNode(value) {
367
- return __velarDomInstance(value, __velarDomNativeNode) || __velarDomNodeType(value) !== null;
368
- }
369
- function __velarDomCollectionSnapshot(value, name) {
370
- let length = null;
371
- let read = null;
372
- if (__velarDomInstance(value, __velarDomNativeNodeList) && typeof __velarDomNodeListLength === "function" && typeof __velarDomNodeListItem === "function") {
373
- length = __velarDomApply(__velarDomNodeListLength, value, [], name + ".length");
374
- read = (index) => __velarDomApply(__velarDomNodeListItem, value, [index], name + ".item");
375
- } else if (__velarDomIsArray(value)) {
376
- length = __velarDomOwnDescriptor(value, "length")?.value;
377
- read = (index) => __velarDomOwnDescriptor(value, index)?.value;
378
- }
379
- if (!__velarDomIsInteger(length) || length < 0 || length > 1000000 || read === null) throw new TypeError(name + " is not a bounded native collection");
380
- const output = new __velarDomNativeArray(length);
381
- for (let index = 0; index < length; index += 1) output[index] = read(index);
382
- return output;
383
- }
384
- function __velarDomChildNodes(value) {
385
- let children;
386
- if (__velarDomInstance(value, __velarDomNativeNode) && typeof __velarDomNodeChildNodes === "function") {
387
- children = __velarDomApply(__velarDomNodeChildNodes, value, [], "Node.childNodes");
388
- } else children = __velarDomOwnData(value, "childNodes");
389
- return __velarDomCollectionSnapshot(children, "Node.childNodes");
390
- }
391
- function __velarDomIsArray(value) {
392
- return typeof __velarDomArrayIsArray === "function" && typeof __velarDomReflectApply === "function"
393
- && __velarDomReflectApply(__velarDomArrayIsArray, __velarDomNativeArray, [value]);
394
- }
395
- function __velarDomIsFinite(value) {
396
- return typeof __velarDomNumberIsFinite === "function" && typeof __velarDomReflectApply === "function"
397
- && __velarDomReflectApply(__velarDomNumberIsFinite, __velarDomNativeNumber, [value]);
398
- }
399
- function __velarDomIsInteger(value) {
400
- return typeof __velarDomNumberIsInteger === "function" && typeof __velarDomReflectApply === "function"
401
- && __velarDomReflectApply(__velarDomNumberIsInteger, __velarDomNativeNumber, [value]);
402
- }
403
- function __velarDomString(value) { return __velarDomApply(__velarDomNativeString, undefined, [value], "String"); }
404
- function __velarDomListSnapshot(value, name) {
405
- if (!__velarDomIsArray(value)) throw new TypeError(name + " requires a List");
406
- const lengthDescriptor = __velarDomOwnDescriptor(value, "length");
407
- if (!lengthDescriptor || lengthDescriptor.writable !== true || lengthDescriptor.enumerable
408
- || lengthDescriptor.configurable || !("value" in lengthDescriptor)) {
409
- throw new TypeError(name + " requires an ordinary mutable List length");
410
- }
411
- const length = lengthDescriptor.value;
412
- if (!__velarDomIsInteger(length) || length < 0 || length > 1000000) throw new RangeError(name + " cannot exceed 1000000 items");
413
- const names = __velarDomApply(__velarDomGetOwnPropertyNames, __velarDomNativeObject, [value]);
414
- const symbols = __velarDomApply(__velarDomGetOwnPropertySymbols, __velarDomNativeObject, [value]);
415
- if (symbols.length > 0 || names.length !== length + 1) throw new TypeError(name + " requires a dense List without extra fields");
416
- const output = new __velarDomNativeArray(length);
417
- for (let index = 0; index < length; index += 1) {
418
- const descriptor = __velarDomOwnDescriptor(value, index);
419
- if (!descriptor?.enumerable || !descriptor.configurable || !descriptor.writable || !("value" in descriptor)) {
420
- throw new TypeError(name + " requires ordinary mutable List elements");
421
- }
422
- output[index] = descriptor.value;
423
- }
424
- return output;
425
- }
426
- function __velarDomCreateSet() {
427
- if (typeof __velarDomNativeSet !== "function") throw new TypeError("The browser Set API is unavailable");
428
- return new __velarDomNativeSet();
429
- }
430
- function __velarDomSetContains(value, item) { return __velarDomApply(__velarDomSetHas, value, [item], "Set.has"); }
431
- function __velarDomSetInsert(value, item) { return __velarDomApply(__velarDomSetAdd, value, [item], "Set.add"); }
432
- function __velarDomSetRemove(value, item) { return __velarDomApply(__velarDomSetDelete, value, [item], "Set.delete"); }
433
- `.trimStart();
434
- export const WEB_REACTIVITY_HOST_RUNTIME = String.raw `
435
- const __velarGraphNativeObject = globalThis.Object;
436
- const __velarGraphNativeArray = globalThis.Array;
437
- const __velarGraphNativeSet = globalThis.Set;
438
- const __velarGraphNativeMap = globalThis.Map;
439
- const __velarGraphNativeWeakSet = globalThis.WeakSet;
440
- const __velarGraphNativeWeakMap = globalThis.WeakMap;
441
- const __velarGraphNativeProxy = globalThis.Proxy;
442
- const __velarGraphReflectApply = Object.getOwnPropertyDescriptor(Reflect, "apply")?.value;
443
- const __velarGraphArrayIsArray = Object.getOwnPropertyDescriptor(Array, "isArray")?.value;
444
- const __velarGraphArrayPrototype = Object.getOwnPropertyDescriptor(__velarGraphNativeArray, "prototype")?.value;
445
- const __velarGraphArraySort = __velarGraphArrayPrototype && Object.getOwnPropertyDescriptor(__velarGraphArrayPrototype, "sort")?.value;
446
- const __velarGraphObjectIs = Object.getOwnPropertyDescriptor(Object, "is")?.value;
447
- const __velarGraphObjectFreeze = Object.getOwnPropertyDescriptor(Object, "freeze")?.value;
448
- const __velarGraphObjectDefineProperty = Object.getOwnPropertyDescriptor(Object, "defineProperty")?.value;
449
- const __velarGraphObjectIsExtensible = Object.getOwnPropertyDescriptor(Object, "isExtensible")?.value;
450
- const __velarGraphObjectGetPrototypeOf = Object.getOwnPropertyDescriptor(Object, "getPrototypeOf")?.value;
451
- const __velarGraphObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(Object, "getOwnPropertyDescriptor")?.value;
452
- const __velarGraphObjectGetOwnPropertyNames = Object.getOwnPropertyDescriptor(Object, "getOwnPropertyNames")?.value;
453
- const __velarGraphObjectCreate = Object.getOwnPropertyDescriptor(Object, "create")?.value;
454
- const __velarGraphSetPrototype = Object.getOwnPropertyDescriptor(__velarGraphNativeSet, "prototype")?.value;
455
- const __velarGraphSetHas = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "has")?.value;
456
- const __velarGraphSetAdd = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "add")?.value;
457
- const __velarGraphSetDelete = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "delete")?.value;
458
- const __velarGraphSetClear = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "clear")?.value;
459
- const __velarGraphSetValues = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "values")?.value;
460
- const __velarGraphSetSize = __velarGraphSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphSetPrototype, "size")?.get;
461
- const __velarGraphMapPrototype = Object.getOwnPropertyDescriptor(__velarGraphNativeMap, "prototype")?.value;
462
- const __velarGraphMapHas = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "has")?.value;
463
- const __velarGraphMapGet = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "get")?.value;
464
- const __velarGraphMapSet = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "set")?.value;
465
- const __velarGraphMapDelete = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "delete")?.value;
466
- const __velarGraphMapClear = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "clear")?.value;
467
- const __velarGraphMapValues = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "values")?.value;
468
- const __velarGraphMapKeys = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "keys")?.value;
469
- const __velarGraphMapSize = __velarGraphMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphMapPrototype, "size")?.get;
470
- const __velarGraphWeakSetPrototype = Object.getOwnPropertyDescriptor(__velarGraphNativeWeakSet, "prototype")?.value;
471
- const __velarGraphWeakSetHas = __velarGraphWeakSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakSetPrototype, "has")?.value;
472
- const __velarGraphWeakSetAdd = __velarGraphWeakSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakSetPrototype, "add")?.value;
473
- const __velarGraphWeakSetDelete = __velarGraphWeakSetPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakSetPrototype, "delete")?.value;
474
- const __velarGraphWeakMapPrototype = Object.getOwnPropertyDescriptor(__velarGraphNativeWeakMap, "prototype")?.value;
475
- const __velarGraphWeakMapHas = __velarGraphWeakMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakMapPrototype, "has")?.value;
476
- const __velarGraphWeakMapGet = __velarGraphWeakMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakMapPrototype, "get")?.value;
477
- const __velarGraphWeakMapSet = __velarGraphWeakMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakMapPrototype, "set")?.value;
478
- const __velarGraphWeakMapDelete = __velarGraphWeakMapPrototype && Object.getOwnPropertyDescriptor(__velarGraphWeakMapPrototype, "delete")?.value;
479
- const __velarGraphReflectGet = Object.getOwnPropertyDescriptor(Reflect, "get")?.value;
480
- const __velarGraphReflectSet = Object.getOwnPropertyDescriptor(Reflect, "set")?.value;
481
- const __velarGraphReflectHas = Object.getOwnPropertyDescriptor(Reflect, "has")?.value;
482
- const __velarGraphReflectDeleteProperty = Object.getOwnPropertyDescriptor(Reflect, "deleteProperty")?.value;
483
- function __velarGraphApply(operation, receiver, arguments_, label) {
484
- if (typeof operation !== "function" || typeof __velarGraphReflectApply !== "function") {
485
- throw new TypeError("The JavaScript " + label + " API is unavailable");
486
- }
487
- return __velarGraphReflectApply(operation, receiver, arguments_);
488
- }
489
- function __velarGraphCreateSet(values) {
490
- const output = new __velarGraphNativeSet();
491
- if (values !== undefined) for (const value of values) __velarGraphSetInsert(output, value);
492
- return output;
493
- }
494
- function __velarGraphCreateMap(values) {
495
- const output = new __velarGraphNativeMap();
496
- if (values !== undefined) for (const entry of values) __velarGraphMapWrite(output, entry[0], entry[1]);
497
- return output;
498
- }
499
- function __velarGraphCreateWeakSet() { return new __velarGraphNativeWeakSet(); }
500
- function __velarGraphCreateWeakMap() { return new __velarGraphNativeWeakMap(); }
501
- function __velarGraphSetContains(value, item) { return __velarGraphApply(__velarGraphSetHas, value, [item], "Set.has"); }
502
- function __velarGraphSetInsert(value, item) { return __velarGraphApply(__velarGraphSetAdd, value, [item], "Set.add"); }
503
- function __velarGraphSetRemove(value, item) { return __velarGraphApply(__velarGraphSetDelete, value, [item], "Set.delete"); }
504
- function __velarGraphSetEmpty(value) { return __velarGraphApply(__velarGraphSetClear, value, [], "Set.clear"); }
505
- function __velarGraphSetItems(value) { return __velarGraphApply(__velarGraphSetValues, value, [], "Set.values"); }
506
- function __velarGraphSetCount(value) { return __velarGraphApply(__velarGraphSetSize, value, [], "Set.size"); }
507
- function __velarGraphMapContains(value, key) { return __velarGraphApply(__velarGraphMapHas, value, [key], "Map.has"); }
508
- function __velarGraphMapRead(value, key) { return __velarGraphApply(__velarGraphMapGet, value, [key], "Map.get"); }
509
- function __velarGraphMapWrite(value, key, item) { return __velarGraphApply(__velarGraphMapSet, value, [key, item], "Map.set"); }
510
- function __velarGraphMapRemove(value, key) { return __velarGraphApply(__velarGraphMapDelete, value, [key], "Map.delete"); }
511
- function __velarGraphMapItems(value) { return __velarGraphApply(__velarGraphMapValues, value, [], "Map.values"); }
512
- function __velarGraphMapEmpty(value) { return __velarGraphApply(__velarGraphMapClear, value, [], "Map.clear"); }
513
- function __velarGraphMapKeyItems(value) { return __velarGraphApply(__velarGraphMapKeys, value, [], "Map.keys"); }
514
- function __velarGraphMapCount(value) { return __velarGraphApply(__velarGraphMapSize, value, [], "Map.size"); }
515
- function __velarGraphWeakSetContains(value, item) { return __velarGraphApply(__velarGraphWeakSetHas, value, [item], "WeakSet.has"); }
516
- function __velarGraphWeakSetInsert(value, item) { return __velarGraphApply(__velarGraphWeakSetAdd, value, [item], "WeakSet.add"); }
517
- function __velarGraphWeakSetRemove(value, item) { return __velarGraphApply(__velarGraphWeakSetDelete, value, [item], "WeakSet.delete"); }
518
- function __velarGraphWeakMapContains(value, key) { return __velarGraphApply(__velarGraphWeakMapHas, value, [key], "WeakMap.has"); }
519
- function __velarGraphWeakMapRead(value, key) { return __velarGraphApply(__velarGraphWeakMapGet, value, [key], "WeakMap.get"); }
520
- function __velarGraphWeakMapWrite(value, key, item) { return __velarGraphApply(__velarGraphWeakMapSet, value, [key, item], "WeakMap.set"); }
521
- function __velarGraphWeakMapRemove(value, key) { return __velarGraphApply(__velarGraphWeakMapDelete, value, [key], "WeakMap.delete"); }
522
- function __velarGraphIsList(value) { return __velarGraphApply(__velarGraphArrayIsArray, __velarGraphNativeArray, [value], "Array.isArray"); }
523
- // D114 F2: a plain record, as against a List, a Map, a Set or a class instance -- what a proxy is built over, what a report option must be, and which word a nested write is described with.
524
- function __velarGraphIsRecord(value) { const prototype = __velarGraphPrototype(value); return prototype === null || prototype === __velarGraphNativeObject.prototype; }
525
- function __velarGraphOrder(value, compare) { return __velarGraphApply(__velarGraphArraySort, value, [compare], "Array.sort"); }
526
- function __velarGraphSame(left, right) { return __velarGraphApply(__velarGraphObjectIs, __velarGraphNativeObject, [left, right], "Object.is"); }
527
- function __velarGraphFreeze(value) { return __velarGraphApply(__velarGraphObjectFreeze, __velarGraphNativeObject, [value], "Object.freeze"); }
528
- function __velarGraphDefine(value, key, descriptor) { return __velarGraphApply(__velarGraphObjectDefineProperty, __velarGraphNativeObject, [value, key, descriptor], "Object.defineProperty"); }
529
- function __velarGraphIsExtensible(value) { return __velarGraphApply(__velarGraphObjectIsExtensible, __velarGraphNativeObject, [value], "Object.isExtensible"); }
530
- function __velarGraphPrototype(value) { return __velarGraphApply(__velarGraphObjectGetPrototypeOf, __velarGraphNativeObject, [value], "Object.getPrototypeOf"); }
531
- function __velarGraphOwnDescriptor(value, key) { return __velarGraphApply(__velarGraphObjectGetOwnPropertyDescriptor, __velarGraphNativeObject, [value, key], "Object.getOwnPropertyDescriptor"); }
532
- function __velarGraphOwnNames(value) { return __velarGraphApply(__velarGraphObjectGetOwnPropertyNames, __velarGraphNativeObject, [value], "Object.getOwnPropertyNames"); }
533
- function __velarGraphCreateRecord() { return __velarGraphApply(__velarGraphObjectCreate, __velarGraphNativeObject, [null], "Object.create"); }
534
- function __velarGraphGet(value, key, receiver) { return __velarGraphApply(__velarGraphReflectGet, null, [value, key, receiver], "Reflect.get"); }
535
- function __velarGraphSet(value, key, item, receiver) { return __velarGraphApply(__velarGraphReflectSet, null, [value, key, item, receiver], "Reflect.set"); }
536
- function __velarGraphHas(value, key) { return __velarGraphApply(__velarGraphReflectHas, null, [value, key], "Reflect.has"); }
537
- function __velarGraphDelete(value, key) { return __velarGraphApply(__velarGraphReflectDeleteProperty, null, [value, key], "Reflect.deleteProperty"); }
538
- `.trimStart();
539
- export const WEB_ERROR_HOST_RUNTIME_BODY = String.raw `
540
- const __velarWebErrorNativeObject = globalThis.Object;
541
- const __velarWebErrorNativeNumber = globalThis.Number;
542
- const __velarWebErrorNativePromise = globalThis.Promise;
543
- const __velarWebErrorOwnSymbolsOperation = Object.getOwnPropertyDescriptor(Object, "getOwnPropertySymbols")?.value;
544
- const __velarWebErrorFreezeOperation = Object.getOwnPropertyDescriptor(Object, "freeze")?.value;
545
- const __velarWebErrorFiniteOperation = Object.getOwnPropertyDescriptor(Number, "isFinite")?.value;
546
- const __velarWebErrorPromisePrototype = Object.getOwnPropertyDescriptor(__velarWebErrorNativePromise, "prototype")?.value;
547
- const __velarWebErrorThenOperation = __velarWebErrorPromisePrototype
548
- ? Object.getOwnPropertyDescriptor(__velarWebErrorPromisePrototype, "then")?.value
549
- : null;
550
- function __velarWebErrorOwnSymbols(value) {
551
- return __velarErrorApply(__velarWebErrorOwnSymbolsOperation, __velarWebErrorNativeObject, [value], "Object.getOwnPropertySymbols");
552
- }
553
- function __velarWebErrorFreeze(value) {
554
- return __velarErrorApply(__velarWebErrorFreezeOperation, __velarWebErrorNativeObject, [value], "Object.freeze");
555
- }
556
- function __velarWebErrorFinite(value) {
557
- return __velarErrorApply(__velarWebErrorFiniteOperation, __velarWebErrorNativeNumber, [value], "Number.isFinite");
558
- }
559
- function __velarObservePromise(value, onRejected) {
560
- if ((typeof value !== "object" && typeof value !== "function") || value === null) return null;
561
- try { return __velarErrorApply(__velarWebErrorThenOperation, value, [undefined, onRejected], "Promise.then"); }
562
- catch { return null; }
563
- }
564
- `.trimStart();
565
- export const WEB_ERROR_HOST_RUNTIME = `${VELAR_ERROR_NORMALIZATION_RUNTIME}\n${WEB_ERROR_HOST_RUNTIME_BODY}`;
566
- function webRuntimeFoundation(errorHostRuntime) {
567
- return String.raw `
568
- ${WEB_REACTIVITY_HOST_RUNTIME}
569
- ${WEB_DOM_HOST_RUNTIME}
570
- ${errorHostRuntime}
571
- const __velarRuntimeKey = Symbol.for(${JSON.stringify(VELAR_RUNTIME_REGISTRY_KEY)});
572
- const __velarFoundationReflectApply = Object.getOwnPropertyDescriptor(Reflect, "apply")?.value;
573
- const __velarFoundationQueueMicrotask = globalThis.queueMicrotask;
574
- const __velarFoundationSetTimeout = globalThis.setTimeout;
575
- const __velarFoundationDate = globalThis.Date;
576
- const __velarFoundationDateNow = typeof __velarFoundationDate === "function"
577
- ? Object.getOwnPropertyDescriptor(__velarFoundationDate, "now")?.value
578
- : null;
579
- const __velarFoundationConsole = globalThis.console ?? null;
580
- const __velarFoundationConsoleError = __velarFoundationConsole !== null
581
- ? Object.getOwnPropertyDescriptor(__velarFoundationConsole, "error")?.value ?? null
582
- : null;
583
- function __velarFoundationTrace(error) {
584
- if (typeof __velarFoundationConsoleError !== "function" || typeof __velarFoundationReflectApply !== "function") return;
585
- let trace = "An unhandled VelarScript failure was reported";
586
- try { const stack = error.stack; if (typeof stack === "string" && stack !== "") trace = stack; } catch {}
587
- if (trace === "An unhandled VelarScript failure was reported") {
588
- try { const message = error.message; if (typeof message === "string" && message !== "") trace = message; } catch {}
589
- }
590
- try { __velarFoundationReflectApply(__velarFoundationConsoleError, __velarFoundationConsole, ["Unhandled VelarScript error report: " + trace]); } catch {}
591
- }
592
- function __velarEnqueue(callback) {
593
- if (typeof __velarFoundationQueueMicrotask !== "function" || typeof __velarFoundationReflectApply !== "function") {
594
- throw new TypeError("The browser queueMicrotask API is unavailable");
595
- }
596
- return __velarFoundationReflectApply(__velarFoundationQueueMicrotask, globalThis, [callback]);
597
- }
598
- function __velarNow() {
599
- if (typeof __velarFoundationDateNow !== "function" || typeof __velarFoundationReflectApply !== "function") {
600
- throw new TypeError("The browser Date.now API is unavailable");
601
- }
602
- return __velarFoundationReflectApply(__velarFoundationDateNow, __velarFoundationDate, []);
603
- }
604
- const __velarRuntimeFields = Object.freeze([
605
- "version", "domQueue", "watchQueue", "flushPending", "activeObserver", "errorHandlers",
606
- "actionFailures", "unhandledFailures", "lookSources", "classSources", "dependencies", "rawToProxy", "proxyToRaw",
607
- "versions", "parents", "toRaw", "reactive", "track", "trackDeep", "trigger", "versionOf",
608
- "collectionRead", "collectionTrigger", "collectionUnlink", "trackSubscribers", "runTracked", "cleanupObserver", "computed",
609
- "schedule", "report", "applyLook", "installLook",
610
- ]);
611
-
612
- function __velarRuntimeCollection(value, kind) {
613
- try {
614
- if (kind === "Set") __velarGraphSetContains(value, value);
615
- else if (kind === "WeakSet") __velarGraphWeakSetContains(value, value);
616
- else __velarGraphWeakMapContains(value, value);
617
- return true;
618
- } catch { return false; }
619
- }
620
-
621
- function __velarReportOptions(value) {
622
- if (value === undefined) value = {};
623
- if (!value || typeof value !== "object" || __velarGraphIsList(value) || !__velarGraphIsRecord(value)
624
- || __velarWebErrorOwnSymbols(value).length > 0) {
625
- throw new TypeError("VelarScript error report options must be a record");
626
- }
627
- const allowed = __velarGraphCreateSet(["phase", "detail", "component", "unhandled"]);
628
- const output = { phase: "runtime", detail: "", component: "", unhandled: false };
629
- for (const name of __velarGraphOwnNames(value)) {
630
- if (!__velarGraphSetContains(allowed, name)) throw new TypeError("Unknown VelarScript error report option '" + name + "'");
631
- const descriptor = __velarGraphOwnDescriptor(value, name);
632
- if (!descriptor || !("value" in descriptor)) throw new TypeError("VelarScript error report options cannot use accessors");
633
- const next = descriptor.value;
634
- if (name === "unhandled") {
635
- if (typeof next !== "boolean") throw new TypeError("VelarScript error report unhandled must be bool");
636
- output.unhandled = next;
637
- } else {
638
- if (typeof next !== "string") throw new TypeError("VelarScript error report " + name + " must be a string");
639
- const maximum = name === "phase" ? 256 : name === "component" ? 1024 : 65536;
640
- if (next.length > maximum) throw new RangeError("VelarScript error report " + name + " is too long");
641
- output[name] = next;
642
- }
643
- }
644
- return output;
645
- }
646
-
647
- // D90 R21: the number stamped on each observer when it is created, and the
648
- // order the flush runs the watch tier in -- execution order is the order the
649
- // author wrote the watches, and "wrote" spans more than one file: watches of
650
- // one module register as that module initializes, instances of one component
651
- // register as they mount, and modules register in the order the import graph
652
- // initializes them. Every one of those is registration order, so one counter
653
- // answers all three.
654
- //
655
- // It has to be application-wide, not per module. Each emitted module carries
656
- // its own copy of this runtime, so a module-scope counter would restart at zero
657
- // in the second module and the two modules' watches would compare equal. The
658
- // counter therefore lives on one global slot every copy reads, the same way the
659
- // runtime registry itself does.
660
- const __velarObserverSequenceKey = Symbol.for("velar.web.observer.sequence.v1");
661
- const __velarObserverSequenceCell = (() => {
662
- const descriptor = __velarGraphOwnDescriptor(globalThis, __velarObserverSequenceKey);
663
- if (descriptor) {
664
- if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable
665
- || !__velarGraphIsList(descriptor.value)) {
666
- throw new TypeError("VelarScript Web observer sequence ownership is invalid");
667
- }
668
- return descriptor.value;
669
- }
670
- const cell = [0];
671
- __velarGraphDefine(globalThis, __velarObserverSequenceKey, {
672
- value: cell,
673
- enumerable: false,
674
- configurable: false,
675
- writable: false,
676
- });
677
- return cell;
678
- })();
679
-
680
- function __velarNextObserverSequence() {
681
- __velarObserverSequenceCell[0] += 1;
682
- return __velarObserverSequenceCell[0];
683
- }
684
-
685
- // D114 W/A1, as narrowed by W2: the identity a flush stamps its run counts
686
- // with, and the budget those runs spend. They belong to one host *task* -- but
687
- // the window follows work an observer started, and nothing else.
688
- //
689
- // A cycle that crosses a microtask boundary -- 'watch x: detach step()', where
690
- // 'step' awaits an already-resolved Promise and then writes 'x' -- is a fresh
691
- // flush every round, so a budget that reset per flush never saw it: two
692
- // observer runs, well inside 100,000, forever. Flushes chained through
693
- // microtasks therefore share one token, one budget and one leaders list, and
694
- // the macrotask sentinel below closes the window. Work that resumes after a
695
- // timer, an event or network I/O is a new task and opens a fresh window, which
696
- // is what keeps an animation that writes state every frame from being stopped.
697
- //
698
- // W2: a flush continues the open window only once an observer run inside it has
699
- // started asynchronous work -- a 'detach' statement, or an 'action' call, made
700
- // while an observer was running. Those are the two ways a synchronous observer
701
- // body reaches a later microtask, so they are the only ways the ring above can
702
- // be closed; a chain of flushes with none of them in it has no cycle to find. A
703
- // bulk import loop that writes a progress counter and awaits promise-only work
704
- // per row runs millions of observers in one uninterrupted task and is not a
705
- // runaway, so each of its flushes gets the fresh budget it had before W. The
706
- // sentinel still closes every window at the task boundary, so the animation
707
- // case is protected either way.
708
- //
709
- // The overrun's carried token is the same rule seen from one flush earlier: an
710
- // overrun schedules its continuation as a microtask, so that continuation is
711
- // this same task and continues these same counts by construction. It carries
712
- // them whether or not an observer started anything, because the continuation is
713
- // the overrun's own unfinished work rather than a new write.
714
- const __velarFlushBudgetPerTask = 100000;
715
- let __velarFlushToken = null;
716
- let __velarFlushBudget = 0;
717
- // One-shot, consumed by the next settle: the flush an overrun scheduled
718
- // continues the window it was scheduled from, whatever that window recorded.
719
- let __velarFlushCarried = false;
720
- // One sentinel is enough for a window: the first one to fire closes it, and
721
- // arming a second on every flush would leave a timer per flush behind.
722
- let __velarTaskSentinelArmed = false;
723
-
724
- // The two facts W2 needs live on one global slot, for the same reason the
725
- // observer sequence above does: every emitted module carries its own copy of
726
- // this runtime, and the two ends of the question are in different copies. The
727
- // settle that asks it belongs to whichever copy created the registry -- in an
728
- // application that imports velar/app, that is velar/app's -- while the places
729
- // that answer it, a 'detach' statement's detached-task helper and an action's
730
- // run, are emitted into the application module. Two module-scope variables
731
- // would never meet.
732
- //
733
- // Slot 0 is how deep the settle currently is inside 'observer.run()'. It is a
734
- // depth rather than a flag because an observer created by a running one runs
735
- // nested. '__velarRuntime.activeObserver' cannot stand in for it: a watch body
736
- // runs untracked, precisely so its own reads do not become dependencies of the
737
- // watched expression, so the active observer is null exactly where the 'detach'
738
- // that closes a cycle is written.
739
- //
740
- // Slot 1 is the fact recorded on the open window: an observer run in it started
741
- // asynchronous work.
742
- const __velarAsyncWorkKey = Symbol.for("velar.web.observer.asyncwork.v1");
743
- const __velarAsyncWorkCell = (() => {
744
- const descriptor = __velarGraphOwnDescriptor(globalThis, __velarAsyncWorkKey);
745
- if (descriptor) {
746
- if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable
747
- || !__velarGraphIsList(descriptor.value)) {
748
- throw new TypeError("VelarScript Web observer async-work ownership is invalid");
749
- }
750
- return descriptor.value;
751
- }
752
- const cell = [0, false];
753
- __velarGraphDefine(globalThis, __velarAsyncWorkKey, {
754
- value: cell,
755
- enumerable: false,
756
- configurable: false,
757
- writable: false,
758
- });
759
- return cell;
760
- })();
761
-
762
- // What the two compiler-owned lowering points call: the detached-task helper a
763
- // 'detach' statement lowers to, where a detached Promise enters the runtime,
764
- // and an action's run, where an action call does. Outside an observer run there
765
- // is nothing to record -- an action a handler or '@main' starts is the host
766
- // task's own work, not a ring an observer closed -- so the same unconditional
767
- // call is correct at both sites.
768
- function __velarNoteAsyncWork() {
769
- if (__velarAsyncWorkCell[0] > 0) __velarAsyncWorkCell[1] = true;
770
- return null;
771
- }
772
-
773
- function __velarCloseTaskWindow() {
774
- __velarTaskSentinelArmed = false;
775
- __velarFlushToken = null;
776
- __velarAsyncWorkCell[1] = false;
777
- return null;
778
- }
779
-
780
- // The macrotask boundary the run-count window ends at. 'setTimeout' is the one
781
- // scheduling operation every host this runtime supports publishes -- page,
782
- // worker, and the Node process a 'velar test' run drives the emitted runtime
783
- // in -- and it is captured at module initialization like every other ambient
784
- // operation here. A host that publishes none is not left without a gate: the
785
- // window then closes as soon as the flush chain comes to rest, which is the
786
- // per-flush budget this runtime had before, so the synchronous cycles stay
787
- // covered and only the asynchronous one goes back to being invisible.
788
- function __velarArmTaskSentinel() {
789
- if (__velarTaskSentinelArmed) return true;
790
- if (typeof __velarFoundationSetTimeout !== "function" || typeof __velarFoundationReflectApply !== "function") return false;
791
- __velarTaskSentinelArmed = true;
792
- try { __velarFoundationReflectApply(__velarFoundationSetTimeout, globalThis, [__velarCloseTaskWindow, 0]); }
793
- catch { __velarTaskSentinelArmed = false; return false; }
794
- return true;
795
- }
796
-
797
- // The three observers that have run most in the task window running now, kept
798
- // as the run counts are stamped rather than reconstructed afterwards: the queue at
799
- // the moment the budget runs out holds only whichever half of a cycle has not
800
- // just run, so it cannot name the ring on its own. An observer that has run
801
- // once is not a candidate, which is every observer of an ordinary flush.
802
- const __velarFlushLeaders = [];
803
-
804
- function __velarFlushLead(observer) {
805
- let kept = 0;
806
- for (let index = 0; index < __velarFlushLeaders.length; index += 1) {
807
- if (__velarFlushLeaders[index] === observer) continue;
808
- __velarFlushLeaders[kept] = __velarFlushLeaders[index];
809
- kept += 1;
810
- }
811
- __velarFlushLeaders.length = kept;
812
- let position = kept;
813
- while (position > 0 && __velarFlushLeaders[position - 1].flushRuns < observer.flushRuns) {
814
- __velarFlushLeaders[position] = __velarFlushLeaders[position - 1];
815
- position -= 1;
816
- }
817
- __velarFlushLeaders[position] = observer;
818
- if (__velarFlushLeaders.length > 3) __velarFlushLeaders.length = 3;
819
- }
820
-
821
- // D90 R21: compile time no longer refuses two watches that write one state, so
822
- // this budget is the only gate left against a mutual-write cycle -- and a
823
- // report that names nobody hands the author a number with no line to go to.
824
- // The observers that ran most in this flush chain are the cycle; flushRuns
825
- // already counts exactly that, so the highest few are named. A watch's label is
826
- // its subject as the author spelled it, which in a write cycle is also the
827
- // state each watch is reacting to, and the scope it was registered in supplies
828
- // the component the report has always had a field for.
829
- //
830
- // Nothing here asks who wrote what. That question is gone from the language,
831
- // and answering it would need the write frames R21 deleted.
832
- function __velarFlushRunaway(stalled, token) {
833
- const ranked = [];
834
- const seen = __velarGraphCreateSet();
835
- const consider = (observer) => {
836
- if (observer.flushToken !== token || __velarGraphSetContains(seen, observer)) return;
837
- __velarGraphSetInsert(seen, observer);
838
- ranked[ranked.length] = observer;
839
- };
840
- // A cycle alternates, so the queue at the instant the budget ran out holds
841
- // only the half of the ring that has not just run. The leaders carry the
842
- // other half.
843
- for (let index = 0; index < __velarFlushLeaders.length; index += 1) consider(__velarFlushLeaders[index]);
844
- for (let index = 0; index < stalled.length; index += 1) consider(stalled[index]);
845
- __velarGraphOrder(ranked, (left, right) => right.flushRuns - left.flushRuns);
846
- const limit = ranked.length < 3 ? ranked.length : 3;
847
- let detail = "";
848
- let component = "";
849
- for (let index = 0; index < limit; index += 1) {
850
- const observer = ranked[index];
851
- const named = observer.mode === "watch" && typeof observer.label === "string" && observer.label !== ""
852
- ? "the watch on '" + observer.label + "'"
853
- : "a " + observer.mode + " observer";
854
- detail += (detail === "" ? "Ran most in this task: " : ", ") + named
855
- + " (" + observer.flushRuns + (observer.flushRuns === 1 ? " run)" : " runs)");
856
- if (component === "" && typeof observer.component === "string") component = observer.component;
857
- }
858
- return { detail, component };
859
- }
860
-
861
- function __velarScheduleFlush() {
862
- if (__velarRuntime.flushPending) return;
863
- __velarRuntime.flushPending = true;
864
- __velarEnqueue(__velarFlush);
865
- }
866
-
867
- // Only the observers that actually re-entered the queue during the overrun
868
- // belong to the runaway cycle. An observer queued once by an unrelated write
869
- // in the same turn is innocent, and stopping it is irreversible, so it is
870
- // put back for the next microtask instead.
871
- //
872
- // Every overrun must still remove something, or the requeue turns the
873
- // microtask chain into the freeze the budget exists to end: a cycle spread
874
- // across more observers than the budget can run four times over re-enters
875
- // none of them four times, so a fixed threshold of four stops nobody and the
876
- // next flush repeats it forever. Two rules make the progress unconditional.
877
- // The threshold falls to the highest run count actually present, so any
878
- // queued observer this flush chain has already run is stopped; and the token
879
- // is carried into the flush the overrun schedules, so run counts accumulate
880
- // across the chain and the observers the chain has not reached yet are a
881
- // pool that only shrinks.
882
- function __velarFlushOverflow(token) {
883
- const stalled = [];
884
- for (const observer of __velarGraphSetItems(__velarRuntime.domQueue)) stalled[stalled.length] = observer;
885
- for (const observer of __velarGraphSetItems(__velarRuntime.watchQueue)) stalled[stalled.length] = observer;
886
- __velarGraphSetEmpty(__velarRuntime.domQueue);
887
- __velarGraphSetEmpty(__velarRuntime.watchQueue);
888
- let threshold = 0;
889
- for (let index = 0; index < stalled.length; index += 1) {
890
- const observer = stalled[index];
891
- if (observer.flushToken === token && observer.flushRuns > threshold) threshold = observer.flushRuns;
892
- }
893
- if (threshold > 4) threshold = 4;
894
- let requeued = false;
895
- for (let index = 0; index < stalled.length; index += 1) {
896
- const observer = stalled[index];
897
- if (threshold > 0 && observer.flushToken === token && observer.flushRuns >= threshold) {
898
- if (typeof observer.stop === "function") observer.stop();
899
- else observer.stopped = true;
900
- continue;
901
- }
902
- if (observer.stopped) continue;
903
- __velarGraphSetInsert(observer.mode === "watch" ? __velarRuntime.watchQueue : __velarRuntime.domQueue, observer);
904
- requeued = true;
905
- }
906
- const runaway = __velarFlushRunaway(stalled, token);
907
- // The window keeps its token and its run counts -- the requeued flush is one
908
- // more flush of the same task, and the pool of observers it has not reached
909
- // yet only shrinks -- but the budget is granted again. Without that, the
910
- // exhausted count would trip the very next flush of the same task, and the
911
- // observers stopped for it would be whatever was queued at that moment: the
912
- // innocent ones this overrun just put back, or an unrelated later write.
913
- __velarFlushBudget = __velarFlushBudgetPerTask;
914
- __velarFlushCarried = requeued;
915
- __velarRuntime.report(new RangeError("Reactive updates cannot run more than " + __velarFlushBudgetPerTask + " observers in one task"),
916
- { phase: "update", detail: runaway.detail, component: runaway.component, unhandled: true });
917
- if (requeued) __velarScheduleFlush();
918
- }
919
-
920
- // The one entry point: the microtask __velarScheduleFlush enqueues, and the
921
- // synchronous drain the emitted tick() performs. It used to open and close D90
922
- // R1-a-scope's flush-scoped writer registry around the settle; R21 deleted the
923
- // registry with the referee that read it, so the name is all that remains and
924
- // it remains because __velarEnqueue and tick() both hold it.
925
- //
926
- // D114 W/A1: it is also where the task window is closed or handed on. Both
927
- // entries pass through here, including tick()'s drain, so the sentinel is armed
928
- // once per window however the flush was reached, and a host without a timer
929
- // falls back to closing the window here, one flush at a time.
930
- function __velarFlush() {
931
- try { __velarFlushSettle(); }
932
- // Without a timer the window closes as soon as the chain comes to rest,
933
- // which is the per-flush budget this runtime had before -- except that a
934
- // flush already scheduled keeps it open, so an overrun's carried counts and
935
- // the queues a settle could not finish reach the flush that continues them.
936
- finally { if (!__velarArmTaskSentinel() && !__velarRuntime.flushPending) __velarCloseTaskWindow(); }
937
- }
938
-
939
- // Glitch-free order: every derived value and every watch settles to a fixed
940
- // point before a single DOM node is written, so no watch and no rendered
941
- // position can read a half-updated world and no corrective watch can push an
942
- // invalid value through the DOM first. That is D90 R1 and it is unchanged.
943
- //
944
- // D90 R21 changed the other axis. Within the settle the watches run in
945
- // registration order -- source order in a module, mount order across instances
946
- // of one component, module-initialization order across modules -- and a watch
947
- // that writes state is not promoted ahead of one that only observes. Whoever is
948
- // written first runs first, two watches writing one state both take effect in
949
- // that order, and a later write that clobbers an earlier one is the author's.
950
- //
951
- // Queue insertion order is not registration order and cannot stand in for it:
952
- // two watches on two different states, both dirtied by one action, enter the
953
- // queue in the order the action wrote the states. So each pass takes the queue
954
- // as it stands and runs it by sequence number. Watches queued by this pass are
955
- // picked up by the next one, in their own order.
956
- //
957
- // D114 W/A1, narrowed by W2: a flush that starts while the task window is still
958
- // open continues it -- the same token, so flushRuns keeps accumulating on every
959
- // observer, the same leaders, and the same remaining budget -- but only when an
960
- // observer run in that window started asynchronous work, or when the overrun
961
- // itself scheduled this flush. Every other flush opens a new window, which is
962
- // the per-flush budget this runtime had before W.
963
- function __velarFlushSettle() {
964
- __velarRuntime.flushPending = false;
965
- const carried = __velarFlushCarried;
966
- __velarFlushCarried = false;
967
- if (__velarFlushToken === null || !(carried || __velarAsyncWorkCell[1])) {
968
- __velarFlushToken = {};
969
- __velarFlushBudget = __velarFlushBudgetPerTask;
970
- __velarFlushLeaders.length = 0;
971
- __velarAsyncWorkCell[1] = false;
972
- }
973
- const token = __velarFlushToken;
974
- const step = (observer) => {
975
- __velarGraphSetRemove(observer.mode === "watch" ? __velarRuntime.watchQueue : __velarRuntime.domQueue, observer);
976
- if (observer.flushToken === token) observer.flushRuns += 1;
977
- else { observer.flushToken = token; observer.flushRuns = 1; }
978
- if (observer.flushRuns > 1) __velarFlushLead(observer);
979
- // The span the two lowering points ask about. It is the run itself rather
980
- // than the whole settle: work started by the flush's own bookkeeping is
981
- // not an observer's, and a nested observer created by a running one is.
982
- __velarAsyncWorkCell[0] += 1;
983
- try { observer.run(); }
984
- finally { __velarAsyncWorkCell[0] -= 1; }
985
- };
986
- while (__velarGraphSetCount(__velarRuntime.domQueue) || __velarGraphSetCount(__velarRuntime.watchQueue)) {
987
- while (true) {
988
- let ran = false;
989
- for (const observer of __velarGraphSetItems(__velarRuntime.domQueue)) {
990
- if (observer.mode !== "computed") continue;
991
- if ((__velarFlushBudget -= 1) < 0) { __velarFlushOverflow(token); return; }
992
- step(observer);
993
- ran = true;
994
- }
995
- if (ran) continue;
996
- const pending = [];
997
- for (const observer of __velarGraphSetItems(__velarRuntime.watchQueue)) pending[pending.length] = observer;
998
- __velarGraphOrder(pending, (left, right) => left.sequence - right.sequence);
999
- for (let index = 0; index < pending.length; index += 1) {
1000
- const observer = pending[index];
1001
- // A watch this pass already re-ran or stopped is no longer queued; the
1002
- // snapshot is a plan, and the queue is what says whether it still owes
1003
- // a run.
1004
- if (observer.stopped || !__velarGraphSetContains(__velarRuntime.watchQueue, observer)) continue;
1005
- if ((__velarFlushBudget -= 1) < 0) { __velarFlushOverflow(token); return; }
1006
- step(observer);
1007
- ran = true;
1008
- }
1009
- if (!ran) break;
1010
- }
1011
- for (const observer of __velarGraphSetItems(__velarRuntime.domQueue)) {
1012
- if (observer.mode === "computed") break;
1013
- if ((__velarFlushBudget -= 1) < 0) { __velarFlushOverflow(token); return; }
1014
- step(observer);
1015
- }
1016
- }
1017
- if (__velarGraphSetCount(__velarRuntime.domQueue) || __velarGraphSetCount(__velarRuntime.watchQueue)) __velarScheduleFlush();
1018
- }
1019
-
1020
- function __velarCreateRuntime() {
1021
- const runtime = Object.create(null);
1022
- const domQueue = Object.freeze(__velarGraphCreateSet());
1023
- const watchQueue = Object.freeze(__velarGraphCreateSet());
1024
- const errorHandlers = Object.freeze(__velarGraphCreateSet());
1025
- const unhandledFailures = Object.freeze(__velarGraphCreateSet());
1026
- const actionFailures = Object.freeze(__velarGraphCreateWeakSet());
1027
- const lookSources = Object.freeze(__velarGraphCreateWeakMap());
1028
- const classSources = Object.freeze(__velarGraphCreateWeakMap());
1029
- const dependencies = Object.freeze(__velarGraphCreateWeakMap());
1030
- const rawToProxy = Object.freeze(__velarGraphCreateWeakMap());
1031
- const proxyToRaw = Object.freeze(__velarGraphCreateWeakMap());
1032
- const versions = Object.freeze(__velarGraphCreateWeakMap());
1033
- const parents = Object.freeze(__velarGraphCreateWeakMap());
1034
- const subscriptionStops = __velarGraphCreateWeakMap();
1035
- const collectionBrands = __velarGraphCreateWeakMap();
1036
- const iterateKey = Symbol.for("velar.reactive.iterate.v1");
1037
- const structureKey = Symbol.for("velar.reactive.structure.v1");
1038
- const deepKey = Symbol.for("velar.reactive.deep.v1");
1039
- let lookImplementation = null;
1040
- const toRaw = (value) => {
1041
- if ((typeof value !== "object" && typeof value !== "function") || value === null) return value;
1042
- return __velarGraphWeakMapRead(proxyToRaw, value) ?? value;
1043
- };
1044
- const trackSubscribers = (subscribers) => {
1045
- const observer = runtime.activeObserver;
1046
- if (!observer || observer.stopped) return;
1047
- __velarGraphSetInsert(subscribers, observer);
1048
- __velarGraphSetInsert(observer.dependencies, subscribers);
1049
- };
1050
- const runTracked = (observer, read) => {
1051
- const previousDependencies = observer.dependencies;
1052
- // Every run needs a second dependency set to diff against, and an observer
1053
- // that re-runs thousands of times per second would otherwise allocate one
1054
- // per run. The emptied previous set is kept as the next run's buffer.
1055
- const spare = observer.spareDependencies;
1056
- observer.spareDependencies = null;
1057
- observer.dependencies = spare ?? __velarGraphCreateSet();
1058
- const previousObserver = runtime.activeObserver;
1059
- runtime.activeObserver = observer;
1060
- try { return read(); }
1061
- finally {
1062
- runtime.activeObserver = previousObserver;
1063
- for (const subscribers of __velarGraphSetItems(previousDependencies)) {
1064
- if (__velarGraphSetContains(observer.dependencies, subscribers)) continue;
1065
- // A stop fires exactly when an actual removal empties the set. Firing
1066
- // on an already-empty set would let two detaching computeds whose
1067
- // cleanups have not yet emptied their dependency sets re-trigger each
1068
- // other without bound.
1069
- if (__velarGraphSetRemove(subscribers, observer) && __velarGraphSetCount(subscribers) === 0) {
1070
- const stop = __velarGraphWeakMapRead(subscriptionStops, subscribers);
1071
- if (stop) stop();
1072
- }
1073
- }
1074
- __velarGraphSetEmpty(previousDependencies);
1075
- observer.spareDependencies = previousDependencies;
1076
- }
1077
- };
1078
- const cleanupObserver = (observer) => {
1079
- for (const subscribers of __velarGraphSetItems(observer.dependencies)) {
1080
- if (__velarGraphSetRemove(subscribers, observer) && __velarGraphSetCount(subscribers) === 0) {
1081
- const stop = __velarGraphWeakMapRead(subscriptionStops, subscribers);
1082
- if (stop) stop();
1083
- }
1084
- }
1085
- __velarGraphSetEmpty(observer.dependencies);
1086
- };
1087
- const track = (target, key) => {
1088
- target = toRaw(target);
1089
- if ((typeof target !== "object" && typeof target !== "function") || target === null) return;
1090
- let byKey = __velarGraphWeakMapRead(dependencies, target);
1091
- if (!byKey) { byKey = __velarGraphCreateMap(); __velarGraphWeakMapWrite(dependencies, target, byKey); }
1092
- let subscribers = __velarGraphMapRead(byKey, key);
1093
- if (!subscribers) {
1094
- subscribers = __velarGraphCreateSet();
1095
- __velarGraphMapWrite(byKey, key, subscribers);
1096
- const ownedSubscribers = subscribers;
1097
- __velarGraphWeakMapWrite(subscriptionStops, subscribers, () => {
1098
- if (__velarGraphMapRead(byKey, key) !== ownedSubscribers) return;
1099
- __velarGraphMapRemove(byKey, key);
1100
- if (__velarGraphMapCount(byKey) === 0) __velarGraphWeakMapRemove(dependencies, target);
1101
- });
1102
- }
1103
- trackSubscribers(subscribers);
1104
- };
1105
- // P2b-9: the path a write travelled, in the words the author would recognise.
1106
- // Only the shape is named -- never a value -- because this reaches a report.
1107
- // The kind travels beside the phrase rather than being read back out of it:
1108
- // the reader of this is the runaway report, and it decides which remedy to
1109
- // give from the kind, not by looking inside a sentence.
1110
- const describeSubject = (target, key) => {
1111
- const container = __velarGraphIsList(target) ? "List" : __velarGraphIsRecord(target) ? "record" : "collection";
1112
- if (key === iterateKey || key === structureKey) return { kind: "collection", text: "the size or contents of a " + container };
1113
- if (key === deepKey) return { kind: "value", text: "a nested value of a " + container };
1114
- if (typeof key === "number") return { kind: "value", text: "element " + key + " of a " + container };
1115
- if (typeof key === "string") return { kind: "value", text: "field '" + key + "'" };
1116
- return { kind: "value", text: "a tracked value" };
1117
- };
1118
- const notify = (target, key) => {
1119
- const byKey = __velarGraphWeakMapRead(dependencies, target);
1120
- const subscribers = byKey ? __velarGraphMapRead(byKey, key) : null;
1121
- if (subscribers) for (const observer of __velarGraphSetItems(subscribers)) {
1122
- // A write that lands while its own reader is still running is the
1123
- // self-invalidating shape, and it is the only one whose path is worth
1124
- // describing -- so the description is built there and nowhere else, which
1125
- // keeps every ordinary write to one property read on this path. The
1126
- // observer's own budget owns the report; this only tells it what to name.
1127
- if (observer.running) {
1128
- const subject = describeSubject(target, key);
1129
- observer.selfInvalidationSubject = subject.text;
1130
- observer.selfInvalidationKind = subject.kind;
1131
- }
1132
- observer.notify();
1133
- }
1134
- };
1135
- const bump = (target) => {
1136
- __velarGraphWeakMapWrite(versions, target, (__velarGraphWeakMapRead(versions, target) ?? 0) + 1);
1137
- };
1138
- const trigger = (target, key, iterate = false, structure = false, indexFrom = null, allKeys = false) => {
1139
- target = toRaw(target);
1140
- if ((typeof target !== "object" && typeof target !== "function") || target === null) return;
1141
- bump(target);
1142
- notify(target, key);
1143
- if (allKeys || indexFrom !== null) {
1144
- const byKey = __velarGraphWeakMapRead(dependencies, target);
1145
- if (byKey) for (const candidate of __velarGraphMapKeyItems(byKey)) {
1146
- if (candidate === key) continue;
1147
- if (allKeys || (typeof candidate === "number" && candidate >= indexFrom)) notify(target, candidate);
1148
- }
1149
- }
1150
- if (iterate) notify(target, iterateKey);
1151
- if (structure) notify(target, structureKey);
1152
- notify(target, deepKey);
1153
- const owners = __velarGraphWeakMapRead(parents, target);
1154
- // A mutation of an unowned value -- the overwhelmingly common case -- must
1155
- // not pay for the cycle bookkeeping that only an ancestor walk needs.
1156
- if (!owners) return;
1157
- const visited = __velarGraphCreateSet();
1158
- __velarGraphSetInsert(visited, target);
1159
- const bubble = (current) => {
1160
- if (__velarGraphSetContains(visited, current)) return;
1161
- __velarGraphSetInsert(visited, current);
1162
- bump(current);
1163
- notify(current, deepKey);
1164
- const next = __velarGraphWeakMapRead(parents, current);
1165
- if (next) for (const owner of __velarGraphSetItems(next)) bubble(owner);
1166
- };
1167
- for (const owner of __velarGraphSetItems(owners)) bubble(owner);
1168
- };
1169
- const link = (child, parent) => {
1170
- if (child === null || (typeof child !== "object" && typeof child !== "function")) return;
1171
- linkOwner(toRaw(child), parent, true);
1172
- };
1173
- // 'structural' separates a slot being filled from a slot merely being read.
1174
- // A read proves the child is in the parent right now; only a write adds an
1175
- // occurrence, and only a write can create the duplicate the running count
1176
- // cannot see for itself.
1177
- const linkOwner = (child, parent, structural = false) => {
1178
- parent = toRaw(parent);
1179
- if (parent === null || (typeof parent !== "object" && typeof parent !== "function") || child === parent) return;
1180
- let owners = __velarGraphWeakMapRead(parents, child);
1181
- if (!owners) { owners = __velarGraphCreateSet(); __velarGraphWeakMapWrite(parents, child, owners); }
1182
- const known = __velarGraphSetContains(owners, parent);
1183
- __velarGraphSetInsert(owners, parent);
1184
- const counts = __velarGraphWeakMapRead(containment, parent);
1185
- if (!counts) return;
1186
- if (structural && known) { __velarGraphWeakMapRemove(containment, parent); return; }
1187
- if ((__velarGraphMapRead(counts, child) ?? 0) < 1) __velarGraphMapWrite(counts, child, 1);
1188
- };
1189
- // Removing the last owner of a value detaches everything only that value
1190
- // owned. Without the cascade, replacing a state root leaves every surviving
1191
- // descendant pointing at the dead root: the root stays strongly reachable
1192
- // and each later deep mutation walks one more generation.
1193
- const release = (root) => {
1194
- const pending = [root];
1195
- let index = 0;
1196
- while (index < pending.length) {
1197
- const current = pending[index];
1198
- index += 1;
1199
- forEachOwnedValue(current, (value) => {
1200
- const owners = __velarGraphWeakMapRead(parents, value);
1201
- if (!owners || !__velarGraphSetContains(owners, current)) return;
1202
- __velarGraphSetRemove(owners, current);
1203
- if (__velarGraphSetCount(owners) > 0) return;
1204
- __velarGraphWeakMapRemove(parents, value);
1205
- pending[pending.length] = value;
1206
- });
1207
- }
1208
- };
1209
- const unlink = (child, parent) => {
1210
- child = toRaw(child);
1211
- parent = toRaw(parent);
1212
- const owners = child !== null && (typeof child === "object" || typeof child === "function")
1213
- ? __velarGraphWeakMapRead(parents, child)
1214
- : null;
1215
- if (!owners) return;
1216
- __velarGraphSetRemove(owners, parent);
1217
- if (__velarGraphSetCount(owners) > 0) return;
1218
- __velarGraphWeakMapRemove(parents, child);
1219
- release(child);
1220
- };
1221
- // Map and Set membership is decided once per value and remembered: the only
1222
- // cross-realm test JavaScript offers is invoking a prototype accessor and
1223
- // catching, and a record write must not pay two thrown exceptions per field.
1224
- const collectionBrand = (value) => {
1225
- const known = __velarGraphWeakMapRead(collectionBrands, value);
1226
- if (known !== undefined) return known;
1227
- let brand = 0;
1228
- try { __velarGraphMapCount(value); brand = 1; }
1229
- catch {
1230
- try { __velarGraphSetCount(value); brand = 2; }
1231
- catch { brand = 0; }
1232
- }
1233
- __velarGraphWeakMapWrite(collectionBrands, value, brand);
1234
- return brand;
1235
- };
1236
- const forEachOwnedValue = (parent, visit) => {
1237
- if (parent === null || (typeof parent !== "object" && typeof parent !== "function")) return;
1238
- if (__velarGraphIsList(parent)) {
1239
- for (let index = 0; index < parent.length; index += 1) {
1240
- const value = toRaw(__velarGraphOwnDescriptor(parent, index)?.value);
1241
- if (value !== null && (typeof value === "object" || typeof value === "function")) visit(value);
1242
- }
1243
- return;
1244
- }
1245
- const brand = collectionBrand(parent);
1246
- if (brand === 1) {
1247
- for (const value of __velarGraphMapItems(parent)) {
1248
- const owned = toRaw(value);
1249
- if (owned !== null && (typeof owned === "object" || typeof owned === "function")) visit(owned);
1250
- }
1251
- // A Map key is linked to its Map exactly like a value, so releasing the
1252
- // Map has to release object keys too.
1253
- for (const value of __velarGraphMapKeyItems(parent)) {
1254
- const owned = toRaw(value);
1255
- if (owned !== null && (typeof owned === "object" || typeof owned === "function")) visit(owned);
1256
- }
1257
- return;
1258
- }
1259
- if (brand === 2) {
1260
- for (const value of __velarGraphSetItems(parent)) {
1261
- const owned = toRaw(value);
1262
- if (owned !== null && (typeof owned === "object" || typeof owned === "function")) visit(owned);
1263
- }
1264
- return;
1265
- }
1266
- if (typeof parent !== "object") return;
1267
- for (const name of __velarGraphOwnNames(parent)) {
1268
- const descriptor = __velarGraphOwnDescriptor(parent, name);
1269
- if (!descriptor || !("value" in descriptor)) continue;
1270
- const value = toRaw(descriptor.value);
1271
- if (value !== null && (typeof value === "object" || typeof value === "function")) visit(value);
1272
- }
1273
- };
1274
- // Containment used to be re-derived by scanning the whole container on every
1275
- // element write, which made one assignment into a rendered List cost O(list
1276
- // length). The occurrence index answers the same question -- does the parent
1277
- // still reference this child anywhere? -- in constant time: it is built once
1278
- // from the container's real contents and then maintained by the same link and
1279
- // release calls that change them.
1280
- const containment = __velarGraphCreateWeakMap();
1281
- const countOccurrence = (counts, value) => {
1282
- value = toRaw(value);
1283
- if (value === null || (typeof value !== "object" && typeof value !== "function")) return;
1284
- __velarGraphMapWrite(counts, value, (__velarGraphMapRead(counts, value) ?? 0) + 1);
1285
- };
1286
- // Mirrors exactly what the old scan looked at, Map keys included as owned
1287
- // values are, so the index cannot answer a question the scan answered
1288
- // differently.
1289
- const buildContainment = (parent) => {
1290
- const counts = __velarGraphCreateMap();
1291
- if (__velarGraphIsList(parent)) {
1292
- for (let index = 0; index < parent.length; index += 1) countOccurrence(counts, __velarGraphOwnDescriptor(parent, index)?.value);
1293
- return counts;
1294
- }
1295
- const brand = collectionBrand(parent);
1296
- if (brand === 1) {
1297
- for (const value of __velarGraphMapItems(parent)) countOccurrence(counts, value);
1298
- return counts;
1299
- }
1300
- if (brand === 2) {
1301
- for (const value of __velarGraphSetItems(parent)) countOccurrence(counts, value);
1302
- return counts;
1303
- }
1304
- if (!parent || typeof parent !== "object") return counts;
1305
- for (const name of __velarGraphOwnNames(parent)) {
1306
- const descriptor = __velarGraphOwnDescriptor(parent, name);
1307
- if (descriptor && "value" in descriptor) countOccurrence(counts, descriptor.value);
1308
- }
1309
- return counts;
1310
- };
1311
- // The one guard every detach path shares: a primitive was never linked, and
1312
- // an object with no owners has nothing to release, so neither may reach the
1313
- // containment bookkeeping.
1314
- const releaseChild = (parent, child) => {
1315
- if (child === null || (typeof child !== "object" && typeof child !== "function")
1316
- || !__velarGraphWeakMapContains(parents, child)) return;
1317
- parent = toRaw(parent);
1318
- if (parent === null || (typeof parent !== "object" && typeof parent !== "function")) return;
1319
- child = toRaw(child);
1320
- // A freshly built index already reflects the slot that was just cleared;
1321
- // a maintained one still counts it, so only that one takes the decrement.
1322
- let counts = __velarGraphWeakMapRead(containment, parent);
1323
- let remaining;
1324
- if (counts) remaining = (__velarGraphMapRead(counts, child) ?? 0) - 1;
1325
- else {
1326
- counts = buildContainment(parent);
1327
- __velarGraphWeakMapWrite(containment, parent, counts);
1328
- remaining = __velarGraphMapRead(counts, child) ?? 0;
1329
- }
1330
- if (remaining > 0) { __velarGraphMapWrite(counts, child, remaining); return; }
1331
- __velarGraphMapRemove(counts, child);
1332
- unlink(child, parent);
1333
- };
1334
- // The registry operation stays exactly two parameters wide; 'structural'
1335
- // belongs to the internal call, which knows whether a slot is being filled or
1336
- // merely read, and every caller outside this file fills one.
1337
- const reactive = (value, parent = null) => reactiveValue(value, parent, true);
1338
- const reactiveValue = (value, parent, structural) => {
1339
- if (value === null || (typeof value !== "object" && typeof value !== "function")) return value;
1340
- value = toRaw(value);
1341
- if (parent !== null) linkOwner(value, parent, structural);
1342
- if (typeof value !== "object" || __velarGraphIsList(value) || !__velarGraphIsExtensible(value)) return value;
1343
- if (!__velarGraphIsRecord(value)) return value;
1344
- let proxy = __velarGraphWeakMapRead(rawToProxy, value);
1345
- if (proxy) return proxy;
1346
- proxy = new __velarGraphNativeProxy(value, {
1347
- get(target, key) {
1348
- track(target, key);
1349
- return reactiveValue(__velarGraphGet(target, key, target), target, false);
1350
- },
1351
- set(target, key, next) {
1352
- next = toRaw(next);
1353
- const present = __velarGraphHas(target, key);
1354
- const previous = toRaw(__velarGraphGet(target, key, target));
1355
- // Creating an absent key is a structural change even when the value
1356
- // written equals the absent key's 'undefined' reading.
1357
- const changed = !present || !__velarGraphSame(previous, next);
1358
- const written = __velarGraphSet(target, key, next, target);
1359
- if (!written || !changed) return written;
1360
- link(next, target);
1361
- releaseChild(target, previous);
1362
- trigger(target, key, true, !present);
1363
- return true;
1364
- },
1365
- has(target, key) { track(target, key); return __velarGraphHas(target, key); },
1366
- deleteProperty(target, key) {
1367
- if (!__velarGraphHas(target, key)) return true;
1368
- const previous = toRaw(__velarGraphGet(target, key, target));
1369
- const deleted = __velarGraphDelete(target, key);
1370
- if (deleted) {
1371
- releaseChild(target, previous);
1372
- trigger(target, key, true, true);
1373
- }
1374
- return deleted;
1375
- },
1376
- });
1377
- __velarGraphWeakMapWrite(rawToProxy, value, proxy);
1378
- __velarGraphWeakMapWrite(proxyToRaw, proxy, value);
1379
- return proxy;
1380
- };
1381
- const trackDeep = (value) => { value = toRaw(value); track(value, deepKey); return value; };
1382
- const versionOf = (value) => {
1383
- value = toRaw(value);
1384
- return value && (typeof value === "object" || typeof value === "function")
1385
- ? __velarGraphWeakMapRead(versions, value) ?? 0
1386
- : 0;
1387
- };
1388
- const collectionRead = (value, key, child) => {
1389
- value = toRaw(value);
1390
- track(value, key);
1391
- // Only containers already connected to a state graph own children read
1392
- // through them. Fresh derived Lists (filter/map/etc.) stay ephemeral and
1393
- // cannot become strongly retained parents of every item merely by being
1394
- // iterated during rendering.
1395
- return reactiveValue(child, __velarGraphWeakMapContains(parents, value) ? value : null, false);
1396
- };
1397
- const collectionTrigger = (value, key, iterate = true, structure = false, indexFrom = null, allKeys = false) => trigger(toRaw(value), key, iterate, structure, indexFrom, allKeys);
1398
- const collectionUnlink = (value, child) => {
1399
- releaseChild(toRaw(value), toRaw(child));
1400
- };
1401
- const computed = (read) => {
1402
- if (typeof read !== "function") throw new TypeError("computed requires a function");
1403
- let dirty = true;
1404
- let evaluating = false;
1405
- let recursed = false;
1406
- let initialized = false;
1407
- let value;
1408
- let failed = false;
1409
- let failure;
1410
- const subscribers = __velarGraphCreateSet();
1411
- const notifyDependents = (skip = null) => {
1412
- for (const dependent of __velarGraphSetItems(subscribers)) if (dependent !== skip) dependent.notify();
1413
- };
1414
- const invalidateComputedDependents = () => {
1415
- for (const dependent of __velarGraphSetItems(subscribers)) {
1416
- if (dependent.mode === "computed") dependent.notify();
1417
- }
1418
- };
1419
- const observer = {
1420
- mode: "computed",
1421
- stopped: false,
1422
- running: false,
1423
- selfInvalidations: 0,
1424
- // P2b-9: filled in by the graph's notify when a write lands while this
1425
- // value is still being derived, so the runaway report names the path.
1426
- selfInvalidationSubject: "",
1427
- selfInvalidationKind: "",
1428
- dependencies: __velarGraphCreateSet(),
1429
- notify() {
1430
- // Stopping is shared discipline with DOM and watch observers: a flush
1431
- // overflow marks queued computed observers stopped, and a stopped
1432
- // observer must go inert instead of re-entering the storm on the next
1433
- // write.
1434
- if (observer.stopped) return;
1435
- // The 100 self-invalidation cap covers computed observers too. A
1436
- // computed whose own turn (evaluation plus dependent notification)
1437
- // keeps invalidating it is stopped with the same owned report a
1438
- // render or watch observer gets, instead of running to the whole
1439
- // flush budget.
1440
- if (observer.running) {
1441
- observer.selfInvalidations += 1;
1442
- if (observer.selfInvalidations > 100) {
1443
- observer.stopped = true;
1444
- cleanupObserver(observer);
1445
- reportUntracked(new RangeError("A computed value cannot invalidate itself more than 100 times"
1446
- + (observer.selfInvalidationSubject ? ": it writes " + observer.selfInvalidationSubject + " while reading it" : "")));
1447
- return;
1448
- }
1449
- } else {
1450
- observer.selfInvalidations = 0;
1451
- }
1452
- if (dirty) return;
1453
- dirty = true;
1454
- if (__velarGraphSetCount(subscribers) === 0) {
1455
- cleanupObserver(observer);
1456
- return;
1457
- }
1458
- schedule(observer);
1459
- // A downstream computed must become dirty immediately so a same-turn
1460
- // read cannot observe its cached result while an upstream dependency
1461
- // is already stale. DOM and watch observers still wait for evaluation
1462
- // to prove that the public result actually changed.
1463
- invalidateComputedDependents();
1464
- },
1465
- run() {
1466
- if (observer.stopped || !dirty || __velarGraphSetCount(subscribers) === 0) return;
1467
- observer.running = true;
1468
- try {
1469
- if (evaluate(false)) notifyDependents();
1470
- } finally { observer.running = false; }
1471
- },
1472
- };
1473
- const detach = () => {
1474
- cleanupObserver(observer);
1475
- dirty = true;
1476
- };
1477
- __velarGraphWeakMapWrite(subscriptionStops, subscribers, detach);
1478
- const evaluate = (throwFailure) => {
1479
- if (evaluating) {
1480
- recursed = true;
1481
- throw new RangeError("A computed value cannot read itself recursively");
1482
- }
1483
- const previous = value;
1484
- const previouslyFailed = failed;
1485
- const previousFailure = failure;
1486
- const hadValue = initialized;
1487
- evaluating = true;
1488
- recursed = false;
1489
- failed = false;
1490
- failure = undefined;
1491
- try { value = runTracked(observer, read); }
1492
- catch (error) { failed = true; failure = error; }
1493
- finally {
1494
- evaluating = false;
1495
- initialized = true;
1496
- dirty = false;
1497
- }
1498
- // A computed that failed because its own recursion guard tripped sits on
1499
- // a dependency cycle. The failure is cached and served, but the cyclic
1500
- // edges must not persist: two failed computeds that keep notifying each
1501
- // other would otherwise ping-pong the next flush into the whole-flush
1502
- // budget. Detaching unwinds the cycle (a peer whose last subscriber
1503
- // leaves detaches with it) and a later read simply re-attempts.
1504
- if (failed && recursed) detach();
1505
- else if (__velarGraphSetCount(subscribers) === 0) detach();
1506
- recursed = false;
1507
- const changed = !hadValue || previouslyFailed !== failed || (failed ? previousFailure !== failure : !__velarGraphSame(previous, value));
1508
- if (throwFailure && failed) throw failure;
1509
- return changed;
1510
- };
1511
- const access = () => {
1512
- const consumer = runtime.activeObserver;
1513
- if (consumer !== observer) trackSubscribers(subscribers);
1514
- if (dirty && !observer.stopped) {
1515
- // A cyclic read re-enters access while the outer evaluation is still
1516
- // running, so the running span is restored, never cleared.
1517
- const wasRunning = observer.running;
1518
- observer.running = true;
1519
- try {
1520
- const changed = evaluate(false);
1521
- if (changed && initialized) notifyDependents(consumer);
1522
- } finally { observer.running = wasRunning; }
1523
- }
1524
- if (failed) throw failure;
1525
- return value;
1526
- };
1527
- return __velarGraphFreeze(access);
1528
- };
1529
- // The loud channel for a failure nothing owns. In a browser the microtask
1530
- // throw reaches the host error event and the page survives it; in a
1531
- // non-browser host (a headless 'velar test' process, a worker) the same
1532
- // throw terminates the process, which is the program termination the
1533
- // runtime boundary forbids. There the failure is traced to the console and
1534
- // parked so the next tick() fails its awaiting caller instead.
1535
- const escalate = (error) => {
1536
- if (__velarDomDocument !== null) {
1537
- __velarEnqueue(() => { throw error; });
1538
- return;
1539
- }
1540
- if (__velarGraphSetCount(unhandledFailures) < 100) __velarGraphSetInsert(unhandledFailures, error);
1541
- __velarFoundationTrace(error);
1542
- };
1543
- const report = (value, options) => {
1544
- const error = __velarNormalizeError(value);
1545
- const checked = __velarReportOptions(options);
1546
- const timestamp = __velarNow();
1547
- if (!__velarWebErrorFinite(timestamp)) throw new TypeError("The browser returned an invalid error timestamp");
1548
- const errorReport = __velarWebErrorFreeze({
1549
- error,
1550
- phase: checked.phase,
1551
- detail: checked.detail,
1552
- component: checked.component,
1553
- timestamp,
1554
- });
1555
- let handled = false;
1556
- for (const handler of __velarGraphSetItems(errorHandlers)) {
1557
- handled = true;
1558
- try {
1559
- const result = handler(errorReport);
1560
- __velarObservePromise(result, (failure) => escalate(__velarNormalizeError(failure)));
1561
- } catch (failure) { escalate(__velarNormalizeError(failure)); }
1562
- }
1563
- if (checked.unhandled && !handled) escalate(error);
1564
- return errorReport;
1565
- };
1566
- // A report raised from inside a tracked evaluation (the computed cap) must
1567
- // not let handler reads become dependencies of the failing observer.
1568
- const reportUntracked = (error) => {
1569
- const previousObserver = runtime.activeObserver;
1570
- runtime.activeObserver = null;
1571
- try { report(error, { phase: "update", detail: "", component: "", unhandled: true }); }
1572
- finally { runtime.activeObserver = previousObserver; }
1573
- };
1574
- // The queue insert stays on the registry -- computed observers are created by
1575
- // whichever module stamped it first (velar/app under ESM import order, or the
1576
- // application prelude) and must schedule correctly whichever that was -- but
1577
- // the drain it calls is the module-scope one below, and there is now exactly
1578
- // one of those. A queue that outgrows its bound is the flush budget's failure
1579
- // to own, not an exception thrown out of the assignment that happened to
1580
- // cross the line: throwing here left the writing cell's subscriber walk half
1581
- // finished, with the remaining observers subscribed and never notified again.
1582
- const schedule = (observer) => {
1583
- __velarGraphSetInsert(observer.mode === "watch" ? watchQueue : domQueue, observer);
1584
- __velarScheduleFlush();
1585
- };
1586
- const applyLook = (...arguments_) => {
1587
- if (!lookImplementation) throw new TypeError("Link Look requires the VelarScript Web runtime");
1588
- return lookImplementation(...arguments_);
1589
- };
1590
- const installLook = (implementation) => {
1591
- if (typeof implementation !== "function") throw new TypeError("VelarScript Look integration requires a function");
1592
- lookImplementation ??= implementation;
1593
- return null;
1594
- };
1595
- const fields = {
1596
- version: ${JSON.stringify(VELAR_RUNTIME_SCHEMA_VERSION)}, domQueue, watchQueue, flushPending: false, activeObserver: null, errorHandlers,
1597
- actionFailures, unhandledFailures, lookSources, classSources, dependencies, rawToProxy, proxyToRaw, versions, parents,
1598
- toRaw, reactive, track, trackDeep, trigger, versionOf, collectionRead, collectionTrigger, collectionUnlink,
1599
- trackSubscribers, runTracked, cleanupObserver, computed,
1600
- schedule, report, applyLook, installLook,
1601
- };
1602
- for (const name of __velarRuntimeFields) Object.defineProperty(runtime, name, {
1603
- value: fields[name],
1604
- enumerable: false,
1605
- configurable: false,
1606
- writable: name === "flushPending" || name === "activeObserver",
1607
- });
1608
- return Object.preventExtensions(runtime);
1609
- }
1610
-
1611
- function __velarRequireRuntime(value) {
1612
- if (!value || typeof value !== "object") throw new TypeError("VelarScript Web runtime ownership is invalid");
1613
- // The schema comparison comes first, ahead of ownership and the field roster:
1614
- // a schema bump normally changes the roster too, so leaving it last reported
1615
- // "fields are invalid" and never named the one fact that identifies the
1616
- // cause. The version is read through its descriptor rather than the property
1617
- // so an unvalidated object cannot answer it with a getter.
1618
- const __velarVersionDescriptor = Object.getOwnPropertyDescriptor(value, "version");
1619
- const __velarVersion = __velarVersionDescriptor && "value" in __velarVersionDescriptor ? __velarVersionDescriptor.value : undefined;
1620
- if (__velarVersion !== ${JSON.stringify(VELAR_RUNTIME_SCHEMA_VERSION)}) {
1621
- throw new TypeError("VelarScript Web runtime schema " + (typeof __velarVersion === "string" ? __velarVersion : "(unknown)") + " does not match this module's schema ${VELAR_RUNTIME_SCHEMA_VERSION}; one build mixed two generations of @velarscript/* — run 'npm ls @velarscript/compiler' and pin one version");
1622
- }
1623
- if (Object.getPrototypeOf(value) !== null || Object.isExtensible(value)
1624
- || Object.getOwnPropertySymbols(value).length > 0) throw new TypeError("VelarScript Web runtime ownership is invalid");
1625
- const names = Object.getOwnPropertyNames(value);
1626
- if (names.length !== __velarRuntimeFields.length || __velarRuntimeFields.some((name) => !names.includes(name))) {
1627
- throw new TypeError("VelarScript Web runtime fields are invalid");
1628
- }
1629
- for (const name of __velarRuntimeFields) {
1630
- const descriptor = Object.getOwnPropertyDescriptor(value, name);
1631
- const mutable = name === "flushPending" || name === "activeObserver";
1632
- if (!descriptor || !("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable !== mutable) {
1633
- throw new TypeError("VelarScript Web runtime field '" + name + "' is invalid");
1634
- }
1635
- }
1636
- if (!__velarRuntimeCollection(value.domQueue, "Set") || !__velarRuntimeCollection(value.watchQueue, "Set")
1637
- || typeof value.flushPending !== "boolean" || (value.activeObserver !== null && typeof value.activeObserver !== "object")
1638
- || !__velarRuntimeCollection(value.errorHandlers, "Set") || !__velarRuntimeCollection(value.actionFailures, "WeakSet")
1639
- || !__velarRuntimeCollection(value.unhandledFailures, "Set")
1640
- || !__velarRuntimeCollection(value.lookSources, "WeakMap") || !__velarRuntimeCollection(value.classSources, "WeakMap")
1641
- || !__velarRuntimeCollection(value.dependencies, "WeakMap") || !__velarRuntimeCollection(value.rawToProxy, "WeakMap")
1642
- || !__velarRuntimeCollection(value.proxyToRaw, "WeakMap") || !__velarRuntimeCollection(value.versions, "WeakMap")
1643
- || !__velarRuntimeCollection(value.parents, "WeakMap")
1644
- || typeof value.toRaw !== "function" || typeof value.reactive !== "function" || typeof value.track !== "function"
1645
- || typeof value.trackDeep !== "function" || typeof value.trigger !== "function" || typeof value.versionOf !== "function"
1646
- || typeof value.collectionRead !== "function" || typeof value.collectionTrigger !== "function" || typeof value.collectionUnlink !== "function"
1647
- || typeof value.trackSubscribers !== "function" || typeof value.runTracked !== "function"
1648
- || typeof value.cleanupObserver !== "function" || typeof value.computed !== "function" || typeof value.schedule !== "function"
1649
- || typeof value.report !== "function" || typeof value.applyLook !== "function" || typeof value.installLook !== "function") {
1650
- throw new TypeError("VelarScript Web runtime values are invalid");
1651
- }
1652
- return value;
1653
- }
1654
-
1655
- const __velarRuntime = (() => {
1656
- const descriptor = Object.getOwnPropertyDescriptor(globalThis, __velarRuntimeKey);
1657
- if (descriptor) {
1658
- if (!("value" in descriptor) || descriptor.enumerable || descriptor.configurable || descriptor.writable) {
1659
- throw new TypeError("VelarScript Web runtime registry ownership is invalid");
1660
- }
1661
- return __velarRequireRuntime(descriptor.value);
1662
- }
1663
- const runtime = __velarCreateRuntime();
1664
- Object.defineProperty(globalThis, __velarRuntimeKey, {
1665
- value: runtime,
1666
- enumerable: false,
1667
- configurable: false,
1668
- writable: false,
1669
- });
1670
- return runtime;
1671
- })();
1672
- `.trimStart();
1673
- }
1674
- export const WEB_RUNTIME_FOUNDATION = webRuntimeFoundation(WEB_ERROR_HOST_RUNTIME);
1675
- export const WEB_RUNTIME_FOUNDATION_SHARED_ERROR = webRuntimeFoundation(WEB_ERROR_HOST_RUNTIME_BODY);
1676
- //# sourceMappingURL=runtime-foundation.js.map