what-core 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
package/dist/dom.js ADDED
@@ -0,0 +1,796 @@
1
+ // src/dom.js
2
+ import { report, setNextBinding, _thrownMessage } from "./diagnostics.js";
3
+ import { _symbolChild, effect, untrack, createRoot, getOwner, onCleanup, _currentComponent, _serverComponentOwner, _enterFrame, _exitFrame, _isDisposed, _tracking, runWithOwner, _runOwned } from "./reactive.js";
4
+ import { _renderComponent, _region, _signalKeyed, _listFragment, _valuesToNodes, _toFunctionComponent, _adoptDetached, _isDomNode, _afterWalk, _installOptionsChanged, applyRef, setClassList, setStyle, _writeClass } from "./render.js";
5
+ import { REFUSED_ATTRS, URL_ATTRS, ATTRIBUTE_VALUE_TYPES, isAriaAttr, isEnumeratedAttr, isUnsafeUrl, selectedOptions } from "./markup-rules.js";
6
+ import { isVNode, SVG_TAG } from "./vnode-renderer.js";
7
+ var SVG_NS = "http://www.w3.org/2000/svg";
8
+ function _isEventProp(key) {
9
+ if (key.length <= 2) return false;
10
+ const a = key.charCodeAt(0);
11
+ const b = key.charCodeAt(1);
12
+ return (a === 111 || a === 79) && (b === 110 || b === 78);
13
+ }
14
+ function _isUnsafeAttr(key, value) {
15
+ const lower = key.toLowerCase();
16
+ return REFUSED_ATTRS.has(lower) || URL_ATTRS.has(lower) && isUnsafeUrl(value);
17
+ }
18
+ function _liveRegionNodes(tracked) {
19
+ let out = null;
20
+ for (const node of tracked) {
21
+ const end = (
22
+ /** @type {any} */
23
+ node._rangeEnd
24
+ );
25
+ if (!end || end.parentNode !== node.parentNode) continue;
26
+ if (!out) out = tracked.slice();
27
+ const buf = (
28
+ /** @type {any[]} */
29
+ out
30
+ );
31
+ for (let n = node.nextSibling; n; n = n.nextSibling) {
32
+ buf.push(n);
33
+ if (n === end) break;
34
+ }
35
+ }
36
+ return out || tracked;
37
+ }
38
+ function mount(node, container) {
39
+ container = _mountTarget(container, "mount");
40
+ return createRoot((dispose) => {
41
+ const unmount = _trackRoot(container, dispose);
42
+ container.textContent = "";
43
+ const nodes = _valuesToNodes(node, container, [], false);
44
+ _adoptDetached(nodes);
45
+ for (let i = 0; i < nodes.length; i++) container.appendChild(nodes[i]);
46
+ return unmount;
47
+ });
48
+ }
49
+ function _mountTarget(container, fn) {
50
+ const el = typeof container === "string" ? document.querySelector(container) : container;
51
+ if (el == null || typeof el.nodeType !== "number") {
52
+ throw Object.assign(new Error((process.env.NODE_ENV !== "production") ? _thrownMessage("ERR_MOUNT_TARGET_MISSING", `${fn}() got no container element: ${typeof container === "string" ? `no element matches "${container}"` : `it was ${String(container)}`}`) : `[what] ${fn}() got no container element`), { code: "ERR_MOUNT_TARGET_MISSING" });
53
+ }
54
+ return el;
55
+ }
56
+ var mountedRoots = /* @__PURE__ */ new WeakMap();
57
+ function _trackRoot(container, dispose) {
58
+ const previous = mountedRoots.get(container);
59
+ const unmount = () => {
60
+ if (mountedRoots.get(container) === unmount) {
61
+ mountedRoots.delete(container);
62
+ dispose();
63
+ container.textContent = "";
64
+ } else {
65
+ dispose();
66
+ }
67
+ };
68
+ mountedRoots.set(container, unmount);
69
+ if (previous !== void 0) previous();
70
+ return unmount;
71
+ }
72
+ function createDOM(vnode, parent, isSvg) {
73
+ if (vnode == null || typeof vnode === "boolean" || typeof vnode === "symbol") {
74
+ if ((process.env.NODE_ENV !== "production") && typeof vnode === "symbol") _symbolChild(vnode, "client");
75
+ return document.createComment("");
76
+ }
77
+ if (typeof vnode === "string" || typeof vnode === "number") {
78
+ return document.createTextNode(String(vnode));
79
+ }
80
+ if (_isDomNode(vnode)) {
81
+ return vnode;
82
+ }
83
+ if (typeof vnode === "function") {
84
+ if (vnode._lazyChildren) return createDOM(vnode(), parent, isSvg);
85
+ return vnode._mapArray ? _listFragment(vnode) : _region(vnode, isSvg);
86
+ }
87
+ if (Array.isArray(vnode)) {
88
+ const frag = document.createDocumentFragment();
89
+ for (const child of vnode) {
90
+ const node = createDOM(child, parent, isSvg);
91
+ if (node) frag.appendChild(node);
92
+ }
93
+ return frag;
94
+ }
95
+ if (!isVNode(vnode)) return document.createTextNode(String(vnode));
96
+ if (typeof vnode.key === "function") return _region(_signalKeyed(vnode), isSvg);
97
+ if (typeof vnode.tag === "function") {
98
+ return createComponent(vnode, parent, isSvg);
99
+ }
100
+ if (vnode.tag === "__errorBoundary" || vnode.tag === "__portal") return vnode.props.mount(vnode, parent);
101
+ if (vnode.tag === "__suspense") return vnode.props.boundary.mount(vnode, parent);
102
+ return createElementFromVNode(vnode, parent, isSvg);
103
+ }
104
+ function getCurrentComponent() {
105
+ return _currentComponent();
106
+ }
107
+ function _beginComponentSSR(Component, parent) {
108
+ const frame = _serverComponentOwner(Component, parent);
109
+ frame._parentCtx = parent !== void 0 ? parent : parentFrame(frame);
110
+ _enterFrame(frame);
111
+ return frame;
112
+ }
113
+ function parentFrame(frame) {
114
+ for (let o = frame.owner; o != null; o = o.owner) {
115
+ if (o.Component !== void 0) return o;
116
+ }
117
+ return null;
118
+ }
119
+ function _endComponentSSR(frame) {
120
+ _exitFrame(frame);
121
+ }
122
+ function _runInComponentSSR(frame, fn) {
123
+ return runWithOwner(frame, fn);
124
+ }
125
+ var placing = false;
126
+ var outsideRead = null;
127
+ function _setOutsideRead(fn) {
128
+ outsideRead = fn;
129
+ }
130
+ var flat = false;
131
+ function _place(props, key, inPlace, fallback) {
132
+ const fallsBack = arguments.length > 3;
133
+ if (_isLiveProp(props, key)) {
134
+ const read = fallsBack ? () => {
135
+ const v = props[key];
136
+ return v === void 0 ? fallback : v;
137
+ } : () => props[key];
138
+ read._forward = true;
139
+ return read;
140
+ }
141
+ placing = true;
142
+ const outer = flat;
143
+ flat = inPlace === 1;
144
+ try {
145
+ const v = props[key];
146
+ return fallsBack && v === void 0 ? fallback : v;
147
+ } finally {
148
+ placing = false;
149
+ flat = outer;
150
+ }
151
+ }
152
+ var PROPS = /* @__PURE__ */ Symbol.for("what-core.props.v1");
153
+ var MARK = { value: true };
154
+ var HIDE = { enumerable: false };
155
+ function _markProps(props) {
156
+ return Object.defineProperty(props, PROPS, MARK);
157
+ }
158
+ function _ownProps(props) {
159
+ if (Object.getPrototypeOf(props) === null) return Object.defineProperty(Object.setPrototypeOf(props, Object.prototype), PROPS, MARK);
160
+ if (Object.prototype.propertyIsEnumerable.call(props, PROPS)) Object.defineProperty(props, PROPS, HIDE);
161
+ return props;
162
+ }
163
+ function _isOwnProps(x) {
164
+ return x[PROPS] > 0 || Object.getPrototypeOf(x) === null;
165
+ }
166
+ function _isLiveProp(props, key) {
167
+ if (props == null || typeof props !== "object" || !_isOwnProps(props)) return false;
168
+ const d = Object.getOwnPropertyDescriptor(props, key);
169
+ return d === void 0 ? props[PROPS] === 2 : d.get !== void 0 && /** @type {any} */
170
+ d.get._lazy !== true;
171
+ }
172
+ function _copyProps(props, omit) {
173
+ if (props == null) return {};
174
+ const own = _isOwnProps(props);
175
+ if (!own && !omit) return { ...props };
176
+ const out = {};
177
+ let live = false;
178
+ for (const key in props) {
179
+ if (Object.hasOwn(props, key) && !(omit && omit.includes(key)) && _copyProp(out, props, key, own)) live = true;
180
+ }
181
+ return live ? _markProps(out) : out;
182
+ }
183
+ function _copyProp(out, src, key, own) {
184
+ const get = own ? (
185
+ /** @type {PropertyDescriptor} */
186
+ Object.getOwnPropertyDescriptor(src, key).get
187
+ ) : void 0;
188
+ if (get) {
189
+ Object.defineProperty(out, key, { get, enumerable: true, configurable: true });
190
+ return true;
191
+ }
192
+ _setOwnProp(out, key, src[key]);
193
+ return false;
194
+ }
195
+ function _setOwnProp(props, key, value) {
196
+ if (key in props) Object.defineProperty(props, key, { value, writable: true, enumerable: true, configurable: true });
197
+ else props[key] = value;
198
+ }
199
+ function _placeFlat(build) {
200
+ const outer = flat;
201
+ flat = true;
202
+ try {
203
+ return build();
204
+ } finally {
205
+ flat = outer;
206
+ }
207
+ }
208
+ function _takeFlat() {
209
+ const was = flat;
210
+ flat = false;
211
+ return was;
212
+ }
213
+ function _installLazyChildren(Component, target, lazyChildren, slots) {
214
+ const cache = [null];
215
+ const define = (key, factory) => {
216
+ if (cache.length === 1 && !_isOwnProps(target)) _markProps(target);
217
+ const at = cache.push(factory, void 0, 0, null) - 4;
218
+ const get = function() {
219
+ const place = placing;
220
+ placing = false;
221
+ return readLazy(cache, at, place);
222
+ };
223
+ get._lazy = true;
224
+ Object.defineProperty(target, key, { get, enumerable: true, configurable: true });
225
+ };
226
+ if (lazyChildren) {
227
+ if (Component._deferChildren) target.children = lazyChildren;
228
+ else define("children", lazyChildren);
229
+ }
230
+ if (slots) for (const key in slots) define(key, slots[key]);
231
+ return cache.length === 1 ? null : (owner) => {
232
+ if ((process.env.NODE_ENV !== "production") && owner === null) for (let at = 1; at < cache.length; at += 4) cache.splice(at + 1, 3, void 0, 0, null);
233
+ cache[0] = owner;
234
+ };
235
+ }
236
+ var PLACED = {};
237
+ var FORWARDS = 3;
238
+ function readLazy(cache, at, place) {
239
+ const home = cache[0];
240
+ let value = cache[at + 1];
241
+ const state = cache[at + 2];
242
+ if (state === FORWARDS) return place ? value : value();
243
+ if (place) {
244
+ if (state !== 1) value = buildLazy(cache[at], home !== null && getOwner() === null ? home : null);
245
+ cache[at + 1] = holdsNodes(value) ? PLACED : value;
246
+ cache[at + 2] = value?._forward ? FORWARDS : 2;
247
+ return value;
248
+ }
249
+ if (state === 0) {
250
+ const build = () => buildLazy(cache[at], home);
251
+ value = cache[at + 1] = outsideRead === null ? build() : outsideRead(build);
252
+ cache[at + 2] = 1;
253
+ if (value?._forward) return cache[at + 2] = FORWARDS, value();
254
+ }
255
+ if (value !== PLACED && (home === null || !holdsNodes(value))) return value;
256
+ if (cache[at + 3] === null) {
257
+ const build = () => readLazy(cache, at, true);
258
+ build._lazyChildren = true;
259
+ cache[at + 3] = [build];
260
+ }
261
+ return cache[at + 3];
262
+ }
263
+ function buildLazy(factory, owner) {
264
+ return owner !== null ? _runOwned(owner, factory) : untrack(factory);
265
+ }
266
+ function holdsNodes(value) {
267
+ return _isDomNode(value) || Array.isArray(value) && value.some(holdsNodes);
268
+ }
269
+ var NAV_SIGNAL = /* @__PURE__ */ Symbol.for("what.navigation.signal.v1");
270
+ function _handleNavigationSignal(error) {
271
+ if (error == null) return false;
272
+ const handler = error[NAV_SIGNAL];
273
+ if (typeof handler !== "function") return false;
274
+ handler(error);
275
+ return true;
276
+ }
277
+ var vnodeLazyProps = () => null;
278
+ function _installVNodeLazyProps() {
279
+ vnodeLazyProps = _installLazyChildren;
280
+ }
281
+ function createComponent(vnode, parent, isSvg) {
282
+ const { props, children } = vnode;
283
+ const Component = _toFunctionComponent(vnode.tag);
284
+ const mergedProps = _copyProps(props);
285
+ if (children.length > 0) _setOwnProp(mergedProps, "children", children.length === 1 ? children[0] : children);
286
+ const lazyChildren = props && props._$lazyChildren;
287
+ const slots = props && props._$slots;
288
+ const endChildrenPass = lazyChildren || slots ? vnodeLazyProps(Component, mergedProps, lazyChildren, slots) : null;
289
+ if ((process.env.NODE_ENV !== "production") && vnode._loc) return _renderComponent(Component, mergedProps, endChildrenPass, isSvg, vnode._loc);
290
+ return _renderComponent(Component, mergedProps, endChildrenPass, isSvg);
291
+ }
292
+ function createPortalDOM(vnode, _parent) {
293
+ const { container } = vnode.props;
294
+ const children = vnode.children;
295
+ if (!container) {
296
+ console.warn("[what] Portal: target container not found");
297
+ return document.createComment("portal:empty");
298
+ }
299
+ const portalNodes = [];
300
+ for (const child of children) {
301
+ const node = createDOM(child, container);
302
+ if (!node) continue;
303
+ if (node.nodeType === 11) {
304
+ for (let n = node.firstChild; n !== null; n = n.nextSibling) portalNodes.push(n);
305
+ } else {
306
+ portalNodes.push(node);
307
+ }
308
+ container.appendChild(node);
309
+ }
310
+ onCleanup(() => {
311
+ for (const node of portalNodes) {
312
+ if (node.parentNode) node.parentNode.removeChild(node);
313
+ }
314
+ });
315
+ return document.createComment("portal");
316
+ }
317
+ function createElementFromVNode(vnode, parent, isSvg) {
318
+ const { tag, props, children } = vnode;
319
+ const svgContext = isSvg || SVG_TAG.test(tag);
320
+ const el = svgContext ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
321
+ for (const key in props) {
322
+ if (key === "key" || key === "children") continue;
323
+ if (key === "ref") applyRef(props.ref, el);
324
+ else setProp(el, key, props[key], svgContext);
325
+ }
326
+ if (tag === "noscript") return el;
327
+ const isSvgChildren = svgContext && tag !== "foreignObject";
328
+ for (let i = 0; i < children.length; i++) {
329
+ const node = createDOM(children[i], el, isSvgChildren);
330
+ if (node) el.appendChild(node);
331
+ }
332
+ return el;
333
+ }
334
+ function _setFieldProp(el, key, value) {
335
+ const tag = el.tagName;
336
+ if (tag === "OPTION" || tag === "SELECT") {
337
+ if (selects !== null) return selects(el, tag, key, value);
338
+ if ((process.env.NODE_ENV !== "production")) console.error(`[what] internal: a <${el.localName}>'s ${key} was written before what-core installed its select code.`);
339
+ return false;
340
+ }
341
+ if (tag === "INPUT" && key === "checked") {
342
+ const on = value == null ? void 0 : !!value;
343
+ if (el._$checked !== on) el.checked = (el._$checked = on) === true;
344
+ } else if (tag === "INPUT" && key === "defaultChecked") {
345
+ el.defaultChecked = !!value;
346
+ if (value && el.type === "radio" && el._$checked === void 0 && el.form) {
347
+ for (const other of _formMember(el.form, "elements")) if (other._$checked && other.name === el.name) other.checked = true;
348
+ }
349
+ } else if (key !== "value" && key !== "defaultValue" || (tag === "INPUT" ? ATTRIBUTE_VALUE_TYPES.has(el.type) : tag !== "TEXTAREA")) {
350
+ return false;
351
+ } else if (key === "defaultValue") {
352
+ el.defaultValue = value == null ? "" : String(value);
353
+ } else {
354
+ const str = value == null ? void 0 : String(value);
355
+ if (el._$value !== str) {
356
+ el._$value = str;
357
+ if (el.type === "file" ? !str : str === void 0 || el.type !== "number" || el.validity.badInput || (el.value || NaN) != +str) writeValue(el, str ?? "");
358
+ }
359
+ }
360
+ return true;
361
+ }
362
+ function writeValue(el, value) {
363
+ const was = el._$seen;
364
+ const seen = was === el.value;
365
+ el.value = value;
366
+ el._$seen = seen ? el.value : was;
367
+ }
368
+ var selects = null;
369
+ function _installSelects() {
370
+ selects = selectProp;
371
+ }
372
+ function _selectsFor(el) {
373
+ if (selects === null && (el.tagName === "SELECT" || el.tagName === "OPTION")) selects = selectProp;
374
+ }
375
+ function selectProp(el, tag, key, value) {
376
+ if (tag === "OPTION") {
377
+ if (key === "value") {
378
+ if (value == null) el.removeAttribute("value");
379
+ else el.value = value;
380
+ _optionsChanged(el);
381
+ } else if (key === "selected" || key === "defaultSelected") {
382
+ el.defaultSelected = !!value;
383
+ _keepSelection(el);
384
+ } else return false;
385
+ } else if (key === "defaultValue") setSelectDefault(el, value);
386
+ else if (key === "value") _setSelectValue(el, value);
387
+ else return false;
388
+ return true;
389
+ }
390
+ function _controlFields(el) {
391
+ if (!_tracking()) return;
392
+ el._$kept = true;
393
+ const win = el.ownerDocument.defaultView || globalThis.window;
394
+ if (!win || win._$controlled) return;
395
+ win._$controlled = true;
396
+ for (const type of ["input", "change", "compositionend", "reset"]) {
397
+ win.addEventListener(type, controlledChanged, true);
398
+ win.addEventListener(type, controlledChanged);
399
+ }
400
+ }
401
+ function controlledChanged(e) {
402
+ const el = e.composedPath()[0];
403
+ if (e.type !== "reset" && (e.isComposing || !el?._$kept || e.type !== "change" && (el.options || el.type === "checkbox" || el.type === "radio"))) return;
404
+ if (e.eventPhase === 1) setTimeout(showControlled, 0, el);
405
+ else queueMicrotask(() => showControlled(el));
406
+ }
407
+ function _onChange(e, handler) {
408
+ const el = e.target;
409
+ const change = e.type === "change";
410
+ const text = "selectionStart" in el && !el.files && !ATTRIBUTE_VALUE_TYPES.has(el.type);
411
+ e._$change ??= text ? el.value !== el._$seen : change;
412
+ if (e._$change) handler(e);
413
+ if (text) {
414
+ el._$seen = change && e.isTrusted ? void 0 : el.value;
415
+ hearScriptWrites(el);
416
+ }
417
+ }
418
+ function hearScriptWrites(el) {
419
+ const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value");
420
+ const set = desc?.set;
421
+ if (set === void 0 || Object.hasOwn(el, "value")) return;
422
+ Object.defineProperty(el, "value", {
423
+ configurable: true,
424
+ get: (
425
+ /** @type {PropertyDescriptor} */
426
+ desc.get
427
+ ),
428
+ set(next) {
429
+ set.call(this, next);
430
+ this._$seen = void 0;
431
+ }
432
+ });
433
+ }
434
+ function showControlled(el) {
435
+ if (el.localName === "form") {
436
+ for (const field of _formMember(el, "elements")) if (field._$kept) showControlled(field);
437
+ return;
438
+ }
439
+ const value = el._$value;
440
+ if (value !== void 0) {
441
+ if (el._$select) el._$select(el, value);
442
+ else if (!el.files && el.value !== value && (el.type !== "number" || !el.validity.badInput && (el.value || NaN) != +value)) writeValue(el, value);
443
+ }
444
+ if (el._$checked === void 0) return;
445
+ const group = el.type !== "radio" || !el.name ? [el] : el.form ? _formMember(el.form, "elements") : el.getRootNode().querySelectorAll("input[type=radio]");
446
+ for (const field of group) {
447
+ if (field._$kept && field._$checked !== void 0 && field.type === el.type && field.name === el.name) field.checked = field._$checked;
448
+ }
449
+ }
450
+ function _setSelectValue(el, value) {
451
+ if (value == null && el._$value === void 0) return;
452
+ _selectionKeeper = _keepSelection;
453
+ el._$value = value ?? void 0;
454
+ el._$select = _setSelectValue;
455
+ _installOptionsChanged(_optionsChanged);
456
+ const write = el._$selectWrite = (el._$selectWrite || 0) + 1;
457
+ if (!markOptions(el, value, "selected")) {
458
+ const retry = () => el._$selectWrite === write && markOptions(el, value, "selected");
459
+ if (!_afterWalk(retry)) queueMicrotask(retry);
460
+ }
461
+ }
462
+ function markOptions(el, value, prop) {
463
+ const options = [...el.options];
464
+ const values = options.map((option) => option.value);
465
+ el._$marked = [options, values];
466
+ const chosen = selectedOptions(values, value);
467
+ for (let i = 0; i < options.length; i++) if (options[i][prop] !== chosen[i]) options[i][prop] = chosen[i];
468
+ if (prop === "selected" && !el.multiple && !chosen.includes(true)) el.selectedIndex = -1;
469
+ return values.length > 0 && [value].flat().every((v) => values.includes(String(v)));
470
+ }
471
+ function _keepSelection(el) {
472
+ const select = el.closest("select");
473
+ if (select !== null) refollow(select, true);
474
+ }
475
+ function _optionsChanged(parent, text) {
476
+ const tag = parent.localName;
477
+ if (text === 1 && tag === "option" && parent.hasAttribute("value")) return;
478
+ const select = tag === "select" ? parent : tag === "optgroup" || tag === "option" ? parent.closest("select") : null;
479
+ if (select !== null) refollow(select, false);
480
+ }
481
+ function refollow(select, always) {
482
+ if (select._$refollow !== void 0) {
483
+ select._$refollow ||= always;
484
+ return;
485
+ }
486
+ select._$refollow = always;
487
+ const run = () => {
488
+ const now = select._$refollow;
489
+ select._$refollow = void 0;
490
+ if (now || optionValuesChanged(select)) follow(select);
491
+ };
492
+ if (!_afterWalk(run)) run();
493
+ }
494
+ function optionValuesChanged(select) {
495
+ const marked = select._$marked;
496
+ if (marked === void 0) return true;
497
+ const [options, values] = marked;
498
+ const now = select.options;
499
+ if (now.length !== options.length) return true;
500
+ for (let i = 0; i < options.length; i++) {
501
+ if (now[i] !== options[i] || now[i].value !== values[i]) return true;
502
+ }
503
+ return false;
504
+ }
505
+ function follow(select) {
506
+ if (select._$value !== void 0) markOptions(select, select._$value, "selected");
507
+ else if (select._$default !== void 0 && !select._$chosen && !select._$following) {
508
+ select._$following = true;
509
+ const mark = () => {
510
+ select._$following = false;
511
+ if (select._$value === void 0 && !select._$chosen) markOptions(select, select._$default, "defaultSelected");
512
+ };
513
+ if (!_afterWalk(mark)) mark();
514
+ }
515
+ }
516
+ var _selectionKeeper = null;
517
+ function setSelectDefault(el, value) {
518
+ if (value == null) return;
519
+ if (el._$default === void 0) el.addEventListener("change", () => {
520
+ el._$chosen = true;
521
+ });
522
+ el._$default = value;
523
+ _selectionKeeper = _keepSelection;
524
+ _installOptionsChanged(_optionsChanged);
525
+ const apply = () => {
526
+ if (el._$default !== value) return;
527
+ markOptions(el, value, "defaultSelected");
528
+ _keepSelection(el);
529
+ };
530
+ apply();
531
+ if (!_afterWalk(apply)) queueMicrotask(apply);
532
+ }
533
+ function _changedFields(el, out, seen) {
534
+ if (el.type !== "radio") {
535
+ const changed = changedField(el);
536
+ if (changed !== null) out.push(changed);
537
+ return;
538
+ }
539
+ const group = el.form !== null ? _formMember(el.form, "elements") : el.ownerDocument.getElementsByName(el.name);
540
+ const radios = [];
541
+ for (const radio of group) {
542
+ if (radio.localName !== "input" || radio.type !== "radio" || radio.name !== el.name || radio.form !== el.form || seen.has(radio)) continue;
543
+ seen.add(radio);
544
+ radios.push(radio);
545
+ }
546
+ if (radios.length === 0 || radios.every((radio) => radio.checked === radio.hasAttribute("checked"))) return;
547
+ const copies = untouched(radios);
548
+ radios.forEach((radio, i) => {
549
+ if (radio.checked !== copies[i].checked) out.push([radio, radio.checked]);
550
+ });
551
+ }
552
+ function untouched(els) {
553
+ const doc = els[0].ownerDocument;
554
+ const form = doc.createElement("form");
555
+ const copies = els.map((el) => copyOf(el, doc));
556
+ _formMember(form, "append")(...copies);
557
+ _formMember(form, "reset")();
558
+ return copies;
559
+ }
560
+ function copyOf(el, doc) {
561
+ const copy = doc.createElement(el.localName);
562
+ for (const name of el.getAttributeNames()) if (name !== "is") copy.setAttribute(name, el.getAttribute(name));
563
+ if (el.localName === "textarea") copy.textContent = el.defaultValue;
564
+ else if (el.localName === "select") {
565
+ let group = null;
566
+ let groupCopy = null;
567
+ for (const option of el.options) {
568
+ const parent = option.parentElement;
569
+ let into = copy;
570
+ if (parent !== el && parent !== null && parent.localName === "optgroup") {
571
+ if (parent !== group) {
572
+ group = parent;
573
+ groupCopy = copy.appendChild(copyOf(parent, doc));
574
+ }
575
+ into = groupCopy;
576
+ }
577
+ into.appendChild(copyOf(option, doc)).textContent = option.text;
578
+ }
579
+ }
580
+ return copy;
581
+ }
582
+ function changedField(el) {
583
+ if (el.type === "file" || el.type === "image") return null;
584
+ if (el.tagName === "SELECT") {
585
+ const [copy] = untouched([el]);
586
+ const options = [...el.options];
587
+ const live = options.map((option) => option.selected);
588
+ const reset = copy.options;
589
+ if (!live.some((selected, i) => selected !== reset[i].selected)) return null;
590
+ el._$chosen = true;
591
+ return [el, options, live];
592
+ }
593
+ if (el.type === "checkbox") {
594
+ if (el.checked === el.hasAttribute("checked")) return null;
595
+ return el.checked !== untouched([el])[0].checked ? [el, el.checked] : null;
596
+ }
597
+ if (el.value === (el.tagName === "TEXTAREA" ? el.defaultValue : el.getAttribute("value") ?? "")) return null;
598
+ return el.value !== untouched([el])[0].value ? [el, el.value] : null;
599
+ }
600
+ function _restoreFields(fields) {
601
+ for (const [el, shown, live] of fields) {
602
+ if (live !== void 0) {
603
+ shown.forEach((option, i) => {
604
+ if (!live[i]) option.selected = false;
605
+ });
606
+ shown.forEach((option, i) => {
607
+ if (live[i]) option.selected = true;
608
+ });
609
+ if (!el.multiple && !live.includes(true)) el.selectedIndex = -1;
610
+ } else if (shown === false) el.checked = false;
611
+ else if (shown !== true && el.value !== shown) el.value = shown;
612
+ }
613
+ for (const [el, shown] of fields) if (shown === true) el.checked = true;
614
+ }
615
+ function _writableProp(el, key) {
616
+ for (let o = el; o !== null; o = Object.getPrototypeOf(o)) {
617
+ const d = Object.getOwnPropertyDescriptor(o, key);
618
+ if (d !== void 0) return d.writable === true || d.set !== void 0;
619
+ }
620
+ return false;
621
+ }
622
+ function setProp(el, key, value, isSvg) {
623
+ if (key === "__proto__") return;
624
+ if (key === "classList") {
625
+ setClassList(el, value);
626
+ return;
627
+ }
628
+ if (typeof value === "function" && !_isEventProp(key) && key !== "ref") {
629
+ if ((process.env.NODE_ENV !== "production")) setNextBinding(el, `${el.localName}.${key}`);
630
+ effect(() => {
631
+ setProp(el, key, value(), isSvg);
632
+ });
633
+ return;
634
+ }
635
+ if (_isEventProp(key)) {
636
+ if (typeof value !== "function" && value != null) return;
637
+ let eventName = key.slice(2);
638
+ let useCapture = false;
639
+ if (eventName.endsWith("Capture") && !eventName.endsWith("PointerCapture")) {
640
+ eventName = eventName.slice(0, -7);
641
+ useCapture = true;
642
+ }
643
+ let event = eventName.toLowerCase();
644
+ if (event === "doubleclick") event = "dblclick";
645
+ const storageKey = useCapture ? event + "_capture" : event;
646
+ const types = event === "change" ? ["input", event] : [event];
647
+ const old = el._events?.[storageKey];
648
+ if (old && old._original === value) return;
649
+ if (old) for (const type of types) el.removeEventListener(type, old, useCapture);
650
+ if (value == null) return;
651
+ if (!el._events) el._events = {};
652
+ const owner = getOwner();
653
+ const opts = value._eventOpts || useCapture || void 0;
654
+ const wrappedHandler = (e) => {
655
+ if (owner !== null && _isDisposed(owner)) {
656
+ for (const type of types) el.removeEventListener(type, wrappedHandler, opts);
657
+ if (el._events[storageKey] === wrappedHandler) delete el._events[storageKey];
658
+ return;
659
+ }
660
+ if (!e.nativeEvent) e.nativeEvent = e;
661
+ return untrack(() => event === "change" ? _onChange(e, wrappedHandler._handler) : wrappedHandler._handler(e));
662
+ };
663
+ wrappedHandler._handler = value;
664
+ wrappedHandler._original = value;
665
+ el._events[storageKey] = wrappedHandler;
666
+ for (const type of types) el.addEventListener(type, wrappedHandler, opts);
667
+ return;
668
+ }
669
+ if (_isUnsafeAttr(key, value)) {
670
+ el.removeAttribute(key);
671
+ if (typeof console !== "undefined") {
672
+ console.warn(`[what] Blocked unsafe URL in "${key}" attribute:`, value);
673
+ }
674
+ return;
675
+ }
676
+ if (key === "className" || key === "class") {
677
+ _writeClass(el, value, isSvg);
678
+ return;
679
+ }
680
+ if (key === "style") {
681
+ setStyle(el, value);
682
+ return;
683
+ }
684
+ if (key === "dangerouslySetInnerHTML" || key === "innerHTML") {
685
+ if (key === "innerHTML" && !(value && typeof value === "object" && "__html" in value)) {
686
+ if ((process.env.NODE_ENV !== "production") && value != null) report("ERR_UNSAFE_INNERHTML", { subject: { kind: "element", name: el.localName } });
687
+ return;
688
+ }
689
+ const html = value?.__html ?? "";
690
+ if ((process.env.NODE_ENV !== "production") && typeof html === "string" && /(<script|onerror\s*=|onload\s*=|javascript:)/i.test(html)) {
691
+ console.warn("[what] dangerouslySetInnerHTML contains potential XSS vectors. Ensure content is sanitized.");
692
+ }
693
+ el.innerHTML = html;
694
+ return;
695
+ }
696
+ selects = selectProp;
697
+ if (_setFieldProp(el, key, value)) return;
698
+ if (value == null) {
699
+ if (_writableProp(el, key)) {
700
+ try {
701
+ el[key] = "";
702
+ } catch {
703
+ }
704
+ }
705
+ el.removeAttribute(key);
706
+ return;
707
+ }
708
+ if (isEnumeratedAttr(key)) {
709
+ el.setAttribute(key, typeof value === "boolean" ? String(value) : value);
710
+ return;
711
+ }
712
+ if (typeof value === "boolean") {
713
+ if (value) el.setAttribute(key, "");
714
+ else el.removeAttribute(key);
715
+ return;
716
+ }
717
+ if (isSvg) {
718
+ if (value === false || value == null) {
719
+ el.removeAttribute(key);
720
+ } else {
721
+ el.setAttribute(key, value === true ? "" : String(value));
722
+ }
723
+ return;
724
+ }
725
+ if (_writableProp(el, key)) {
726
+ el[key] = value;
727
+ } else {
728
+ el.setAttribute(key, value);
729
+ }
730
+ }
731
+ function _formMember(form, name) {
732
+ const value = Reflect.get(Object.getPrototypeOf(form), name, form);
733
+ return typeof value === "function" ? value.bind(form) : value;
734
+ }
735
+ function _resetForm(form, onError) {
736
+ const fields = [..._formMember(form, "elements")];
737
+ const held = fields.map((el) => [el._$value, el._$checked]);
738
+ const attempt = (write) => {
739
+ try {
740
+ write();
741
+ } catch (error) {
742
+ onError(error);
743
+ }
744
+ };
745
+ attempt(_formMember(form, "reset"));
746
+ fields.forEach((el, i) => {
747
+ const [value, checked] = held[i];
748
+ if (value !== void 0) attempt(() => el._$select ? el._$select(el, value) : el.value = value);
749
+ if (checked !== void 0) attempt(() => {
750
+ el.checked = checked;
751
+ });
752
+ });
753
+ }
754
+ export {
755
+ PROPS,
756
+ _beginComponentSSR,
757
+ _changedFields,
758
+ _controlFields,
759
+ _copyProp,
760
+ _copyProps,
761
+ _endComponentSSR,
762
+ _formMember,
763
+ _handleNavigationSignal,
764
+ _installLazyChildren,
765
+ _installSelects,
766
+ _installVNodeLazyProps,
767
+ isAriaAttr as _isAriaAttr,
768
+ _isEventProp,
769
+ _isLiveProp,
770
+ _isOwnProps,
771
+ _isUnsafeAttr,
772
+ _liveRegionNodes,
773
+ _markProps,
774
+ _mountTarget,
775
+ _onChange,
776
+ _ownProps,
777
+ _place,
778
+ _placeFlat,
779
+ _resetForm,
780
+ _restoreFields,
781
+ _runInComponentSSR,
782
+ _selectionKeeper,
783
+ _selectsFor,
784
+ _setFieldProp,
785
+ _setOutsideRead,
786
+ _setOwnProp,
787
+ setProp as _setVNodeProp,
788
+ showControlled as _showControlled,
789
+ _takeFlat,
790
+ _trackRoot,
791
+ _writableProp,
792
+ createDOM,
793
+ createPortalDOM,
794
+ getCurrentComponent,
795
+ mount
796
+ };