@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30

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 (73) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +1211 -205
  3. package/dist/dev.js +1175 -199
  4. package/dist/server.cjs +1342 -234
  5. package/dist/server.js +1304 -231
  6. package/dist/web.cjs +1195 -196
  7. package/dist/web.js +1159 -190
  8. package/frames/dist/client.cjs +1746 -0
  9. package/frames/dist/client.dev.cjs +1759 -0
  10. package/frames/dist/client.dev.js +1747 -0
  11. package/frames/dist/client.js +1734 -0
  12. package/frames/dist/server.cjs +2426 -0
  13. package/frames/dist/server.js +2414 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +287 -38
  16. package/serialization/dist/serialization.cjs +169 -0
  17. package/serialization/dist/serialization.js +159 -0
  18. package/serialization/package.json +20 -0
  19. package/serialization/types/index.d.ts +157 -0
  20. package/serialization/types-cjs/index.d.cts +157 -0
  21. package/serialization/types-cjs/package.json +3 -0
  22. package/server-functions/dist/client.cjs +613 -0
  23. package/server-functions/dist/client.js +585 -0
  24. package/server-functions/dist/server.cjs +904 -0
  25. package/server-functions/dist/server.js +875 -0
  26. package/server-functions/package.json +30 -0
  27. package/storage/package.json +8 -3
  28. package/storage/types/index.d.ts +26 -0
  29. package/storage/types-cjs/index.d.cts +28 -0
  30. package/storage/types-cjs/package.json +3 -0
  31. package/types/client.d.ts +125 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +20 -0
  34. package/types/frames/frame-client.d.ts +270 -0
  35. package/types/frames/frame-sink.d.ts +168 -0
  36. package/types/frames/frame-transport.d.ts +196 -0
  37. package/types/frames/serializer.d.ts +157 -0
  38. package/types/frames/server.d.ts +30 -0
  39. package/types/index.d.ts +211 -26
  40. package/types/jsx-properties.d.ts +93 -0
  41. package/types/jsx.d.ts +4150 -1
  42. package/types/response.d.ts +129 -0
  43. package/types/serializer.d.ts +157 -0
  44. package/types/server-functions/client.d.ts +200 -0
  45. package/types/server-functions/flash.d.ts +38 -0
  46. package/types/server-functions/server.d.ts +490 -0
  47. package/types/server-functions/shared.d.ts +445 -0
  48. package/types/server-mock.d.ts +93 -0
  49. package/types/server.d.ts +221 -28
  50. package/types-cjs/client.d.cts +192 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +20 -0
  53. package/types-cjs/frames/frame-client.d.cts +270 -0
  54. package/types-cjs/frames/frame-sink.d.cts +168 -0
  55. package/types-cjs/frames/frame-transport.d.cts +196 -0
  56. package/types-cjs/frames/serializer.d.cts +157 -0
  57. package/types-cjs/frames/server.d.cts +30 -0
  58. package/types-cjs/index.d.cts +231 -0
  59. package/types-cjs/jsx-properties.d.cts +93 -0
  60. package/types-cjs/jsx.d.cts +4150 -0
  61. package/types-cjs/package.json +3 -0
  62. package/types-cjs/response.d.cts +129 -0
  63. package/types-cjs/serializer.d.cts +157 -0
  64. package/types-cjs/server-functions/client.d.cts +200 -0
  65. package/types-cjs/server-functions/flash.d.cts +38 -0
  66. package/types-cjs/server-functions/server.d.cts +490 -0
  67. package/types-cjs/server-functions/shared.d.cts +445 -0
  68. package/types-cjs/server-mock.d.cts +165 -0
  69. package/types-cjs/server.d.cts +349 -0
  70. package/storage/types/src/client.d.ts +0 -1
  71. package/storage/types/src/index.d.ts +0 -46
  72. package/storage/types/src/server-mock.d.ts +0 -72
  73. package/storage/types/storage/src/index.d.ts +0 -2
package/dist/dev.js CHANGED
@@ -1,39 +1,80 @@
1
- import { createRenderEffect, createMemo as createMemo$1, sharedConfig, untrack, runWithOwner, flatten, createRoot, omit, $DEVCOMP, enableHydration, enforceLoadingBoundary } from 'solid-js';
2
- export { Errored, For, Hydration, Loading, Match, NoHydration, Show, Switch, createComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
- import { createMemo } from '@solidjs/signals';
1
+ import { createRenderEffect, createMemo, sharedConfig, untrack, runWithOwner, flatten, createRoot, merge, createComponent, omit, createOwner, createSignal, onSettled, $DEVCOMP, enableHydration, enforceLoadingBoundary, flush, getOwner, createEffect } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, untrack } from 'solid-js';
4
3
 
5
- const Properties = /*#__PURE__*/new Set([
6
- "value", "checked", "selected", "muted"]);
4
+ const DOMWithState = {
5
+ INPUT: {
6
+ value: 1,
7
+ defaultValue: 2,
8
+ checked: 1,
9
+ defaultChecked: 2
10
+ },
11
+ SELECT: {
12
+ value: 1
13
+ },
14
+ OPTION: {
15
+ value: 1,
16
+ selected: 1,
17
+ defaultSelected: 2
18
+ },
19
+ TEXTAREA: {
20
+ value: 1,
21
+ defaultValue: 2
22
+ },
23
+ VIDEO: {
24
+ muted: 1,
25
+ defaultMuted: 2
26
+ },
27
+ AUDIO: {
28
+ muted: 1,
29
+ defaultMuted: 2
30
+ }
31
+ };
7
32
  const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
33
+ const $$SLOT = /*#__PURE__*/Symbol("slot");
34
+ const $$HOST = /*#__PURE__*/Symbol("host");
8
35
  const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]);
9
36
  const SVGElements = /*#__PURE__*/new Set([
10
37
  "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect",
11
38
  "set", "stop",
12
39
  "svg", "switch", "symbol", "text", "textPath",
13
40
  "tref", "tspan", "use", "view", "vkern"]);
14
- const SVGNamespace = {
41
+ const MathMLElements = /*#__PURE__*/new Set(["annotation", "annotation-xml", "maction", "math", "menclose", "merror", "mfenced", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"]);
42
+ const Namespaces = {
43
+ svg: "http://www.w3.org/2000/svg",
44
+ mathml: "http://www.w3.org/1998/Math/MathML",
15
45
  xlink: "http://www.w3.org/1999/xlink",
16
46
  xml: "http://www.w3.org/XML/1998/namespace"
17
47
  };
18
- const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "main", "nav", "section", "body", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "param", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "menu", "summary", "details", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "portal", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp", "input", "h1", "h2", "h3", "h4", "h5", "h6",
19
- "webview",
20
- "isindex", "listing", "multicol", "nextid", "noindex", "search"]);
48
+ const VoidElements = /*#__PURE__*/new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
49
+ const RawTextElements = /*#__PURE__*/new Set(["style", "script", "noscript", "template", "textarea", "title"]);
50
+ const DOMElements = /*#__PURE__*/new Set(/*#__PURE__*/"a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,math,menu,menuitem,meta,meter,multicol,nav,nextid,nobr,noembed,noframes,noindex,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,portal,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,search,section,select,shadow,slot,small,source,spacer,span,strike,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,webview,xmp".split(","));
21
51
 
22
- const effect = (fn, effectFn, initial) => createRenderEffect(fn, effectFn, initial, {
23
- transparent: true
24
- });
25
- const memo = (fn, transparent) => transparent ? fn.$r ? fn : createMemo(() => fn(), undefined, {
26
- transparent: true
27
- }) : createMemo$1(() => fn());
52
+ const transparentOptions = {
53
+ transparent: true,
54
+ sync: true
55
+ };
56
+ const syncOptions = {
57
+ sync: true
58
+ };
59
+ const effect = (fn, effectFn, options) => createRenderEffect(fn, effectFn, options ? {
60
+ sync: true,
61
+ ...options,
62
+ transparent: !options.scope
63
+ } : transparentOptions);
64
+ const memo = fn => createMemo(() => fn(), syncOptions);
28
65
 
29
- function reconcileArrays(parentNode, a, b) {
66
+ function reconcileArrays(parentNode, a, b, marker) {
30
67
  let bLength = b.length,
31
68
  aEnd = a.length,
32
69
  bEnd = bLength,
33
70
  aStart = 0,
34
71
  bStart = 0,
35
- after = a[aEnd - 1].nextSibling,
36
- map = null;
72
+ tail = a[aEnd - 1],
73
+ tailTag = tail[$$SLOT],
74
+ after = tail.parentNode === parentNode && (!tailTag || tailTag === marker) ? tail.nextSibling : marker || null,
75
+ map = null,
76
+ anchor,
77
+ anchorTag;
37
78
  while (aStart < aEnd || bStart < bEnd) {
38
79
  if (a[aStart] === b[bStart]) {
39
80
  aStart++;
@@ -45,18 +86,43 @@ function reconcileArrays(parentNode, a, b) {
45
86
  bEnd--;
46
87
  }
47
88
  if (aEnd === aStart) {
48
- const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after;
49
- while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node);
89
+ let node;
90
+ if (bEnd < bLength) {
91
+ if (bStart) {
92
+ const prev = b[bStart - 1];
93
+ const prevTag = prev[$$SLOT];
94
+ node = prev.parentNode === parentNode && (!prevTag || prevTag === marker) ? prev.nextSibling : after;
95
+ } else node = b[bEnd - bStart];
96
+ } else node = after;
97
+ while (bStart < bEnd) {
98
+ const n = b[bStart++];
99
+ parentNode.insertBefore(n, node);
100
+ if (marker) n[$$SLOT] = marker;
101
+ }
50
102
  } else if (bEnd === bStart) {
51
103
  while (aStart < aEnd) {
52
- if (!map || !map.has(a[aStart])) a[aStart].remove();
53
- aStart++;
104
+ const n = a[aStart++];
105
+ if (!map || !map.has(n)) {
106
+ const tag = n[$$SLOT];
107
+ if (n.parentNode === parentNode && (!tag || tag === marker)) n.remove();
108
+ }
109
+ }
110
+ } else if ((anchor = a[aStart]) === b[bEnd - 1] && b[bStart] === a[aEnd - 1] && anchor.parentNode === parentNode && (!(anchorTag = anchor[$$SLOT]) || anchorTag === marker)) {
111
+ if (marker) {
112
+ do {
113
+ const n = a[--aEnd];
114
+ parentNode.insertBefore(n, anchor);
115
+ n[$$SLOT] = marker;
116
+ bStart++;
117
+ if (aStart >= aEnd - 1 || bStart >= bEnd) break;
118
+ } while (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]);
119
+ } else {
120
+ do {
121
+ parentNode.insertBefore(a[--aEnd], anchor);
122
+ bStart++;
123
+ if (aStart >= aEnd - 1 || bStart >= bEnd) break;
124
+ } while (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]);
54
125
  }
55
- } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
56
- const node = a[--aEnd].nextSibling;
57
- parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
58
- parentNode.insertBefore(b[--bEnd], node);
59
- a[aEnd] = b[bEnd];
60
126
  } else {
61
127
  if (!map) {
62
128
  map = new Map();
@@ -74,80 +140,277 @@ function reconcileArrays(parentNode, a, b) {
74
140
  sequence++;
75
141
  }
76
142
  if (sequence > index - bStart) {
77
- const node = a[aStart];
78
- while (bStart < index) parentNode.insertBefore(b[bStart++], node);
79
- } else parentNode.replaceChild(b[bStart++], a[aStart++]);
143
+ const head = a[aStart];
144
+ const headTag = head[$$SLOT];
145
+ const node = head.parentNode === parentNode && (!headTag || headTag === marker) ? head : after;
146
+ while (bStart < index) {
147
+ const n = b[bStart++];
148
+ parentNode.insertBefore(n, node);
149
+ if (marker) n[$$SLOT] = marker;
150
+ }
151
+ } else {
152
+ const oldNode = a[aStart++];
153
+ const newNode = b[bStart++];
154
+ const oldTag = oldNode[$$SLOT];
155
+ if (oldNode.parentNode === parentNode && (!oldTag || oldTag === marker)) {
156
+ parentNode.replaceChild(newNode, oldNode);
157
+ } else {
158
+ parentNode.insertBefore(newNode, after);
159
+ }
160
+ if (marker) newNode[$$SLOT] = marker;
161
+ }
80
162
  } else aStart++;
81
- } else a[aStart++].remove();
163
+ } else {
164
+ const n = a[aStart++];
165
+ const nTag = n[$$SLOT];
166
+ if (n.parentNode === parentNode && (!nTag || nTag === marker)) n.remove();
167
+ }
82
168
  }
83
169
  }
84
170
  }
85
171
 
86
- const $$EVENTS = "_$DX_DELEGATE";
172
+ const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
173
+ const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
174
+ const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "icon", "stylesheet"]);
175
+ const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
176
+ function evalHeadValue(v) {
177
+ return typeof v === "function" ? v() : v;
178
+ }
179
+ function evalHeadProps(props, presets) {
180
+ const out = {};
181
+ for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
182
+ return out;
183
+ }
184
+ function classifyHeadTag(desc) {
185
+ const tag = desc.tag;
186
+ if (tag === "link") {
187
+ const rel = evalHeadValue(desc.props && desc.props.rel);
188
+ return {
189
+ resource: RESOURCE_LINK_RELS.has(rel),
190
+ rel
191
+ };
192
+ }
193
+ if (tag === "style") return {
194
+ resource: !!(desc.props && "href" in desc.props)
195
+ };
196
+ if (tag === "script") return {
197
+ resource: !!(desc.props && "src" in desc.props)
198
+ };
199
+ return {
200
+ resource: false
201
+ };
202
+ }
203
+ function resourceIdentity(tag, props) {
204
+ let id = "res:" + tag + ":" + (props.rel || "") + ":" + (props.href || props.src || "");
205
+ for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
206
+ const q = RESOURCE_QUALIFIERS[i];
207
+ if (props[q] != null) id += ":" + q + "=" + props[q];
208
+ }
209
+ return id;
210
+ }
211
+ function replaceableIdentity(tag, props, key, unique) {
212
+ if (tag === "title") return "title";
213
+ if (tag === "base") return "base";
214
+ if (tag === "meta" && props.charset != null) return "charset";
215
+ if (key != null) return tag + ":key:" + key;
216
+ if (tag === "meta") {
217
+ if (props.name != null) return "meta:name:" + props.name;
218
+ if (props.property != null) return "meta:property:" + props.property;
219
+ if (props["http-equiv"] != null) return "meta:http-equiv:" + props["http-equiv"];
220
+ return unique;
221
+ }
222
+ if (tag === "link") return "link:" + (props.rel || "") + ":" + (props.href || "");
223
+ return unique;
224
+ }
225
+ function resolveHead(groups) {
226
+ const winners = new Map();
227
+ const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
228
+ for (let i = 0; i < sorted.length; i++) {
229
+ const group = sorted[i];
230
+ const byIdentity = new Map();
231
+ for (let j = 0; j < group.tags.length; j++) {
232
+ const t = group.tags[j];
233
+ let list = byIdentity.get(t.identity);
234
+ if (!list) byIdentity.set(t.identity, list = []);
235
+ list.push(t);
236
+ }
237
+ for (const [identity, tags] of byIdentity) {
238
+ if (identity === "title") {
239
+ if (tags.length > 1) console.warn("Multiple <title> tags in one head group; the last one wins.");
240
+ winners.set(identity, {
241
+ seq: group.seq,
242
+ tags: [tags[tags.length - 1]]
243
+ });
244
+ } else {
245
+ winners.set(identity, {
246
+ seq: group.seq,
247
+ tags
248
+ });
249
+ }
250
+ }
251
+ }
252
+ return winners;
253
+ }
254
+
255
+ const $$EVENT_OWNER = "_$DX_EVENT_OWNER";
256
+ const INNER_OWNED = {};
257
+ const delegatedEvents = new Set();
258
+ const delegatedContainers = new Map();
87
259
  function render$1(code, element, init, options = {}) {
88
260
  if (!element) {
89
261
  throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document.");
90
262
  }
91
263
  let disposer;
92
- createRoot(dispose => {
93
- disposer = dispose;
94
- element === document ? flatten(code) : insert(element, code(), element.firstChild ? null : undefined, init);
95
- }, {
96
- id: options.renderId
97
- });
264
+ registerDelegatedRoot(element);
265
+ try {
266
+ createRoot(dispose => {
267
+ disposer = dispose;
268
+ if (element === document) {
269
+ const tree = code();
270
+ effect(() => flatten(tree), () => {});
271
+ } else {
272
+ const tree = code();
273
+ insert(element, () => tree, element.firstChild ? null : undefined, init, options.insertOptions);
274
+ }
275
+ }, {
276
+ id: options.renderId
277
+ });
278
+ } catch (err) {
279
+ if (disposer) disposer();
280
+ unregisterDelegatedRoot(element);
281
+ throw err;
282
+ }
98
283
  return () => {
99
284
  disposer();
285
+ unregisterDelegatedRoot(element);
100
286
  element.textContent = "";
101
287
  };
102
288
  }
103
- function template(html, isImportNode, isSVG, isMathML) {
289
+ function create(html, bypassGuard, flag) {
290
+ if (isHydrating() && !bypassGuard) throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");
291
+ const t = document.createElement("template");
292
+ t.innerHTML = html;
293
+ return flag === 2 ? t.content.firstChild.firstChild : t.content.firstChild;
294
+ }
295
+ function template(html, flag) {
104
296
  let node;
105
- const create = bypassGuard => {
106
- if (isHydrating() && !bypassGuard) throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration.");
107
- const t = isMathML ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template") : document.createElement("template");
108
- t.innerHTML = html;
109
- return isSVG ? t.content.firstChild.firstChild : isMathML ? t.firstChild : t.content.firstChild;
110
- };
111
- const fn = isImportNode ? bypassGuard => untrack(() => document.importNode(node || (node = create(bypassGuard)), true)) : bypassGuard => (node || (node = create(bypassGuard))).cloneNode(true);
112
- fn._html = html;
297
+ const fn = flag === 1 ? bypassGuard => document.importNode(node || (node = create(html, bypassGuard, flag)), true) : bypassGuard => (node || (node = create(html, bypassGuard, flag))).cloneNode(true);
298
+ fn._html = flag === 2 ? html.replace(/^<[^>]+>/, "") : html;
113
299
  return fn;
114
300
  }
115
- function delegateEvents(eventNames, document = window.document) {
116
- const e = document[$$EVENTS] || (document[$$EVENTS] = new Set());
301
+ function delegateEvents(eventNames) {
117
302
  for (let i = 0, l = eventNames.length; i < l; i++) {
118
303
  const name = eventNames[i];
119
- if (!e.has(name)) {
120
- e.add(name);
121
- document.addEventListener(name, eventHandler);
304
+ if (!delegatedEvents.has(name)) {
305
+ delegatedEvents.add(name);
306
+ delegatedContainers.forEach((state, container) => attachDelegatedEvent(name, container, state));
122
307
  }
123
308
  }
124
309
  }
125
- function clearDelegatedEvents(document = window.document) {
126
- if (document[$$EVENTS]) {
127
- for (let name of document[$$EVENTS].keys()) document.removeEventListener(name, eventHandler);
128
- delete document[$$EVENTS];
310
+ function registerDelegatedRoot(root) {
311
+ const state = registerDelegatedContainer(root, root);
312
+ if (state) state.roots = (state.roots || 0) + 1;
313
+ }
314
+ function unregisterDelegatedRoot(root) {
315
+ const state = delegatedContainers.get(root);
316
+ if (state) state.roots > 1 ? state.roots-- : delete state.roots;
317
+ unregisterDelegatedContainer(root, root);
318
+ }
319
+ function registerDelegatedContainer(container, owner = container) {
320
+ if (!container || !owner) return;
321
+ let state = delegatedContainers.get(container);
322
+ if (!state) delegatedContainers.set(container, state = {
323
+ owners: new Map(),
324
+ handlers: new Map()
325
+ });
326
+ state.owners.set(owner, (state.owners.get(owner) || 0) + 1);
327
+ delegatedEvents.forEach(name => attachDelegatedEvent(name, container, state));
328
+ return state;
329
+ }
330
+ function unregisterDelegatedContainer(container, owner = container) {
331
+ const state = delegatedContainers.get(container);
332
+ if (!state) return;
333
+ const count = state.owners.get(owner);
334
+ if (count > 1) state.owners.set(owner, count - 1);else state.owners.delete(owner);
335
+ if (state.owners.size) return;
336
+ state.handlers.forEach((handler, name) => container.removeEventListener(name, handler));
337
+ delegatedContainers.delete(container);
338
+ }
339
+ function attachDelegatedEvent(name, container, state) {
340
+ if (state.handlers.has(name)) return;
341
+ const handler = e => eventHandler(e, container, state);
342
+ state.handlers.set(name, handler);
343
+ container.addEventListener(name, handler);
344
+ }
345
+ function getDelegatedRoot(node) {
346
+ while (node) {
347
+ if (delegatedContainers.get(node)?.roots) return node;
348
+ node = node._$host || node.parentNode || node.host;
349
+ }
350
+ }
351
+ function findOwner(target, state) {
352
+ let node = target;
353
+ let distance = 0;
354
+ while (node) {
355
+ if (state.owners.has(node)) return {
356
+ owner: node,
357
+ distance
358
+ };
359
+ distance++;
360
+ node = node._$host || node.parentNode || node.host;
129
361
  }
130
362
  }
131
363
  function setProperty(node, name, value) {
132
364
  if (isHydrating(node)) return;
133
365
  node[name] = value;
134
366
  }
367
+ let claimHandlers = null;
368
+ const CLAIM_SEAM = Symbol.for("dom-expressions.element-claims");
369
+ function registerElementClaim(handler) {
370
+ (claimHandlers || (claimHandlers = globalThis[CLAIM_SEAM] = [])).push(handler);
371
+ return () => {
372
+ const index = claimHandlers.indexOf(handler);
373
+ index > -1 && claimHandlers.splice(index, 1);
374
+ };
375
+ }
376
+ const CLAIMED_ELEMENTS = "a[href], form[action]";
377
+ function claimElementTree(root) {
378
+ const handlers = globalThis[CLAIM_SEAM];
379
+ if (handlers === undefined || handlers.length === 0) return root;
380
+ const isElement = root.nodeType === 1;
381
+ if (!isElement && root.nodeType !== 11) return root;
382
+ if (isElement && root.matches(CLAIMED_ELEMENTS)) {
383
+ for (let i = 0; i < handlers.length; i++) handlers[i](root);
384
+ }
385
+ const found = root.querySelectorAll(CLAIMED_ELEMENTS);
386
+ for (let i = 0; i < found.length; i++) {
387
+ for (let j = 0; j < handlers.length; j++) handlers[j](found[i]);
388
+ }
389
+ return root;
390
+ }
391
+ function claimElement(node) {
392
+ if (claimHandlers !== null) {
393
+ for (let i = 0; i < claimHandlers.length; i++) claimHandlers[i](node);
394
+ }
395
+ return node;
396
+ }
135
397
  function setAttribute(node, name, value) {
136
398
  if (isHydrating(node)) return;
137
399
  if (value == null || value === false) node.removeAttribute(name);else node.setAttribute(name, value === true ? "" : value);
400
+ if (claimHandlers !== null && (name === "href" || name === "action")) claimElement(node);
138
401
  }
139
402
  function setAttributeNS(node, namespace, name, value) {
140
403
  if (isHydrating(node)) return;
141
- if (value == null) node.removeAttributeNS(namespace, name);else node.setAttributeNS(namespace, name, value);
404
+ if (value == null || value === false) node.removeAttributeNS(namespace, name.indexOf(":") > -1 ? name.split(":").pop() : name);else node.setAttributeNS(namespace, name, value === true ? "" : value);
142
405
  }
143
- function className(node, value, isSVG, prev) {
406
+ function className(node, value, prev) {
144
407
  if (isHydrating(node)) return;
145
408
  if (value == null || value === false) {
146
409
  prev && node.removeAttribute("class");
147
410
  return;
148
411
  }
149
412
  if (typeof value === "string") {
150
- value !== prev && (isSVG ? node.setAttribute("class", value) : node.className = value);
413
+ value !== prev && node.setAttribute("class", value);
151
414
  return;
152
415
  }
153
416
  if (typeof prev === "string") {
@@ -161,16 +424,16 @@ function className(node, value, isSVG, prev) {
161
424
  for (i = 0, len = prevKeys.length; i < len; i++) {
162
425
  const key = prevKeys[i];
163
426
  if (!key || key === "undefined" || value[key]) continue;
164
- toggleClassKey(node, key, false);
427
+ node.classList.remove(key);
165
428
  }
166
429
  for (i = 0, len = classKeys.length; i < len; i++) {
167
430
  const key = classKeys[i],
168
431
  classValue = !!value[key];
169
432
  if (!key || key === "undefined" || prev[key] === classValue || !classValue) continue;
170
- toggleClassKey(node, key, true);
433
+ node.classList.add(key);
171
434
  }
172
435
  }
173
- function addEventListener(node, name, handler, delegate) {
436
+ function addEvent(node, name, handler, delegate) {
174
437
  if (delegate) {
175
438
  if (Array.isArray(handler)) {
176
439
  node[`$$${name}`] = handler[0];
@@ -183,33 +446,48 @@ function addEventListener(node, name, handler, delegate) {
183
446
  }
184
447
  function style(node, value, prev) {
185
448
  if (!value) {
186
- if (prev) setAttribute(node, "style");
449
+ if (prev || node._$styles) {
450
+ setAttribute(node, "style");
451
+ node._$styles = undefined;
452
+ }
187
453
  return;
188
454
  }
189
455
  const nodeStyle = node.style;
190
- if (typeof value === "string") return nodeStyle.cssText = value;
191
- typeof prev === "string" && (nodeStyle.cssText = prev = undefined);
192
- prev || (prev = {});
193
- value || (value = {});
456
+ if (typeof value === "string") {
457
+ node._$styles = undefined;
458
+ return nodeStyle.cssText = value;
459
+ }
460
+ if (typeof prev === "string") {
461
+ nodeStyle.cssText = "";
462
+ prev = undefined;
463
+ }
464
+ let applied = node._$styles;
465
+ if (!applied) {
466
+ applied = node._$styles = prev ? {
467
+ ...prev
468
+ } : {};
469
+ }
194
470
  let v, s;
471
+ for (s in applied) {
472
+ if (value[s] == null) {
473
+ nodeStyle.removeProperty(s);
474
+ delete applied[s];
475
+ }
476
+ }
195
477
  for (s in value) {
196
478
  v = value[s];
197
- if (v !== prev[s]) nodeStyle.setProperty(s, v);
198
- delete prev[s];
479
+ if (v != null && v !== applied[s]) {
480
+ nodeStyle.setProperty(s, v);
481
+ applied[s] = v;
482
+ }
199
483
  }
200
- for (s in prev) value[s] == null && nodeStyle.removeProperty(s);
201
484
  }
202
485
  function setStyleProperty(node, name, value) {
203
486
  value != null ? node.style.setProperty(name, value) : node.style.removeProperty(name);
204
487
  }
205
- function spread(node, props = {}, isSVG, skipChildren) {
488
+ function spread(node, props = {}, skipChildren) {
206
489
  const prevProps = {};
207
- if (!skipChildren) {
208
- effect(() => normalize(props.children, prevProps.children), value => {
209
- insertExpression(node, value, prevProps.children);
210
- prevProps.children = value;
211
- });
212
- }
490
+ if (!skipChildren) insert(node, () => props.children);
213
491
  effect(() => {
214
492
  const r = props.ref;
215
493
  (typeof r === "function" || Array.isArray(r)) && ref(() => r, node);
@@ -221,7 +499,7 @@ function spread(node, props = {}, isSVG, skipChildren) {
221
499
  newProps[prop] = props[prop];
222
500
  }
223
501
  return newProps;
224
- }, props => assign(node, props, isSVG, true, prevProps, true));
502
+ }, props => assign(node, props, true, prevProps, true));
225
503
  return prevProps;
226
504
  }
227
505
  function dynamicProperty(props, key) {
@@ -241,49 +519,474 @@ function ref(fn, element) {
241
519
  const resolved = untrack(fn);
242
520
  runWithOwner(null, () => applyRef(resolved, element));
243
521
  }
244
- function insert(parent, accessor, marker, initial) {
245
- const multi = marker !== undefined;
246
- if (multi && !initial) initial = [];
247
- if (isHydrating(parent)) {
248
- if (!multi && initial === undefined && parent) initial = [...parent.childNodes];
249
- if (Array.isArray(initial)) {
250
- let j = 0;
251
- for (let i = 0; i < initial.length; i++) {
252
- if (initial[i].nodeType === 8 && initial[i].nodeValue === "!$") initial[i].remove();else initial[j++] = initial[i];
522
+ function scope(fn) {
523
+ fn.$s = true;
524
+ return fn;
525
+ }
526
+ const SCOPE_OPTIONS = {
527
+ scope: true
528
+ };
529
+ let hydrationRt = null;
530
+ function installHydrationRuntime() {
531
+ hydrationRt = {
532
+ claimInitial(parent, multi, initial) {
533
+ if (isHydrating(parent)) {
534
+ if (!multi && initial === undefined && parent) initial = [...parent.childNodes];
535
+ if (Array.isArray(initial)) stripTextSeparators(initial);
253
536
  }
254
- initial.length = j;
537
+ return initial;
538
+ },
539
+ reclaimRegion(current, parent, marker) {
540
+ if (!sharedConfig.hydrating || !current || !parent.isConnected) return current;
541
+ const first = Array.isArray(current) ? current[0] : current;
542
+ if (!first || !first.nodeType || first.isConnected) return current;
543
+ let nodes;
544
+ if (marker) {
545
+ nodes = [];
546
+ let node = marker.previousSibling,
547
+ depth = 0;
548
+ while (node) {
549
+ if (node.nodeType === 8) {
550
+ const v = node.nodeValue;
551
+ if (v === "/") depth++;else if (v === "$") {
552
+ if (depth === 0) break;
553
+ depth--;
554
+ }
555
+ }
556
+ nodes.unshift(node);
557
+ node = node.previousSibling;
558
+ }
559
+ } else nodes = [...parent.childNodes];
560
+ return stripTextSeparators(nodes);
561
+ },
562
+ dedupEvent(e) {
563
+ return !!(sharedConfig.registry && sharedConfig.events && sharedConfig.events.find(([el, ev]) => ev === e));
255
564
  }
565
+ };
566
+ }
567
+ function stripTextSeparators(nodes) {
568
+ let j = 0;
569
+ for (let i = 0; i < nodes.length; i++) {
570
+ const node = nodes[i],
571
+ t = node.nodeType;
572
+ if (t === 8) {
573
+ const v = node.nodeValue;
574
+ if (v === "!$") {
575
+ node.remove();
576
+ continue;
577
+ }
578
+ if (v.startsWith("pl-")) continue;
579
+ } else if (t === 1 && node.localName === "template" && node.id.startsWith("pl-")) continue;
580
+ nodes[j++] = node;
256
581
  }
582
+ nodes.length = j;
583
+ return nodes;
584
+ }
585
+ function insert(parent, accessor, marker, initial, options) {
586
+ const multi = marker !== undefined;
587
+ const host = options && options.host;
588
+ if (multi && !initial) initial = [];
589
+ if (hydrationRt !== null) initial = hydrationRt.claimInitial(parent, multi, initial);
257
590
  if (typeof accessor !== "function") {
258
591
  accessor = normalize(accessor, initial, multi, true);
259
- if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
592
+ if (typeof accessor !== "function") {
593
+ insertExpression(parent, accessor, initial, marker);
594
+ host && tagHost(accessor, host);
595
+ return;
596
+ }
260
597
  }
261
- accessor = memo(accessor, true);
262
- if (multi && initial.length === 0 && !isHydrating(parent)) {
598
+ if (multi && initial.length === 0) {
263
599
  const placeholder = document.createTextNode("");
264
600
  parent.insertBefore(placeholder, marker);
265
601
  initial = [placeholder];
266
602
  }
267
- effect(prev => normalize(accessor, prev, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
603
+ let current = initial;
604
+ effect(prev => {
605
+ if (hydrationRt !== null) current = hydrationRt.reclaimRegion(current, parent, marker);
606
+ const value = normalize(accessor(), current, multi, true);
607
+ if (typeof value !== "function") return value;
608
+ effect(() => (hydrationRt !== null && (current = hydrationRt.reclaimRegion(current, parent, marker)), normalize(value, current, multi)), inner => {
609
+ insertExpression(parent, inner, current, marker);
610
+ current = inner;
611
+ host && tagHost(current, host);
612
+ }, prev !== undefined && !(options && options.schedule) ? {
613
+ ...options,
614
+ schedule: true
615
+ } : options);
616
+ return INNER_OWNED;
617
+ }, value => {
618
+ if (value === INNER_OWNED) return;
619
+ insertExpression(parent, value, current, marker);
620
+ current = value;
621
+ host && tagHost(current, host);
622
+ },
623
+ accessor.$s ? options ? {
624
+ ...options,
625
+ scope: true
626
+ } : SCOPE_OPTIONS : options);
268
627
  }
269
- function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef = false) {
628
+ function assign(node, props, skipChildren, prevProps = {}, skipRef = false) {
629
+ const nodeName = node.nodeName;
270
630
  props || (props = {});
271
631
  for (const prop in prevProps) {
272
632
  if (!(prop in props)) {
273
633
  if (prop === "children") continue;
274
- prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef);
634
+ prevProps[prop] = assignProp(node, prop, null, prevProps[prop], skipRef, nodeName);
275
635
  }
276
636
  }
277
637
  for (const prop in props) {
278
638
  if (prop === "children") {
279
- if (!skipChildren) insertExpression(node, props.children);
639
+ if (!skipChildren) insertExpression(node, normalize(props.children, undefined, false));
640
+ continue;
641
+ }
642
+ prevProps[prop] = assignProp(node, prop, props[prop], prevProps[prop], skipRef, nodeName);
643
+ }
644
+ }
645
+ const ASSET_REMOVAL_GRACE = 100;
646
+ const assetRegistry = new Map();
647
+ function assetEntryKey(descriptor) {
648
+ if (descriptor.policy === "exclusive") return "x|" + descriptor.key;
649
+ return descriptor.type === "inline-style" ? "i|" + descriptor.id : descriptor.type + "|" + descriptor.href;
650
+ }
651
+ function findAssetElement(selector, attr, value) {
652
+ const nodes = document.querySelectorAll(selector);
653
+ for (let i = 0; i < nodes.length; i++) {
654
+ if (nodes[i].getAttribute(attr) === value) return nodes[i];
655
+ }
656
+ return null;
657
+ }
658
+ function mountAssetElement(descriptor) {
659
+ let el;
660
+ if (descriptor.type === "inline-style") {
661
+ el = findAssetElement("style[data-asset]", "data-asset", descriptor.id);
662
+ if (!el) {
663
+ el = document.createElement("style");
664
+ el.setAttribute("data-asset", descriptor.id);
665
+ el.textContent = descriptor.content || "";
666
+ }
667
+ } else {
668
+ const rel = descriptor.type === "module" ? "modulepreload" : "stylesheet";
669
+ el = findAssetElement(`link[rel="${rel}"]`, "href", descriptor.href);
670
+ if (!el) {
671
+ el = document.createElement("link");
672
+ el.rel = rel;
673
+ el.href = descriptor.href;
674
+ }
675
+ }
676
+ if (descriptor.attrs) {
677
+ for (const name in descriptor.attrs) el.setAttribute(name, descriptor.attrs[name]);
678
+ }
679
+ if (!el.isConnected) document.head.appendChild(el);
680
+ return el;
681
+ }
682
+ function acquireAsset(descriptor) {
683
+ const key = assetEntryKey(descriptor);
684
+ let entry = assetRegistry.get(key);
685
+ if (descriptor.policy === "exclusive") {
686
+ if (!entry) {
687
+ entry = {
688
+ original: descriptor.get(),
689
+ set: descriptor.set,
690
+ writers: []
691
+ };
692
+ assetRegistry.set(key, entry);
693
+ }
694
+ const writer = {
695
+ value: descriptor.value
696
+ };
697
+ entry.writers.push(writer);
698
+ entry.set(writer.value);
699
+ let released = false;
700
+ return () => {
701
+ if (released) return;
702
+ released = true;
703
+ const index = entry.writers.indexOf(writer);
704
+ const wasTop = index === entry.writers.length - 1;
705
+ entry.writers.splice(index, 1);
706
+ if (!wasTop) return;
707
+ if (entry.writers.length) {
708
+ entry.set(entry.writers[entry.writers.length - 1].value);
709
+ } else {
710
+ entry.set(entry.original);
711
+ assetRegistry.delete(key);
712
+ }
713
+ };
714
+ }
715
+ if (!entry) {
716
+ entry = {
717
+ count: 0,
718
+ element: null,
719
+ timer: null
720
+ };
721
+ assetRegistry.set(key, entry);
722
+ }
723
+ if (entry.timer) {
724
+ clearTimeout(entry.timer);
725
+ entry.timer = null;
726
+ }
727
+ entry.count++;
728
+ if (!entry.element || !entry.element.isConnected) entry.element = mountAssetElement(descriptor);
729
+ let released = false;
730
+ return () => {
731
+ if (released) return;
732
+ released = true;
733
+ if (--entry.count > 0) return;
734
+ entry.timer = setTimeout(() => {
735
+ assetRegistry.delete(key);
736
+ entry.element && entry.element.remove();
737
+ }, ASSET_REMOVAL_GRACE);
738
+ };
739
+ }
740
+ let headRegistrations = null;
741
+ let headSeq = 0;
742
+ let headUid = 0;
743
+ let headOwned = null;
744
+ let headApplied = null;
745
+ let headFallbackTitle = null;
746
+ let headScheduled = false;
747
+ const headMountedResources = new Set();
748
+ function initHeadRegistry() {
749
+ if (headRegistrations) return;
750
+ headRegistrations = [];
751
+ headOwned = new Map();
752
+ headApplied = new Map();
753
+ const t = document.querySelector("title");
754
+ headFallbackTitle = t && !t.hasAttribute("data-dh") ? t.textContent : null;
755
+ if (globalThis._$HY) globalThis._$HY.h = applyServerHeadOps;
756
+ }
757
+ function applyServerHeadOps(ops) {
758
+ for (let i = 0; i < ops.length; i++) {
759
+ const op = ops[i];
760
+ const identity = op[0] === "t" ? "title" : op[1];
761
+ if (headOwned.has(identity)) continue;
762
+ if (op[0] === "t") setHeadTitle(op[1]);else if (op[0] === "r") {
763
+ const els = headMarkedElements(identity);
764
+ for (let j = 0; j < els.length; j++) els[j].remove();
765
+ } else {
766
+ const el = document.createElement(op[2]);
767
+ for (const name in op[3]) el.setAttribute(name, op[3][name]);
768
+ if (op[4] != null) el.textContent = op[4];
769
+ el.setAttribute("data-dh", identity);
770
+ document.head.appendChild(el);
771
+ }
772
+ }
773
+ }
774
+ function headMarkedElements(identity) {
775
+ const nodes = document.head.querySelectorAll("[data-dh]");
776
+ const out = [];
777
+ for (let i = 0; i < nodes.length; i++) {
778
+ if (nodes[i].getAttribute("data-dh") === identity) out.push(nodes[i]);
779
+ }
780
+ return out;
781
+ }
782
+ function setHeadTitle(text) {
783
+ let el = document.querySelector("title");
784
+ if (!el) {
785
+ el = document.createElement("title");
786
+ document.head.appendChild(el);
787
+ }
788
+ el.textContent = text;
789
+ el.setAttribute("data-dh", "title");
790
+ return el;
791
+ }
792
+ function scheduleHeadApply() {
793
+ if (headScheduled) return;
794
+ headScheduled = true;
795
+ queueMicrotask(flushHeadRegistry);
796
+ }
797
+ function flushHeadRegistry() {
798
+ if (sharedConfig.hydrating) {
799
+ setTimeout(flushHeadRegistry, 0);
800
+ return;
801
+ }
802
+ headScheduled = false;
803
+ const winners = resolveHead(headRegistrations);
804
+ for (const [identity, els] of headOwned) {
805
+ if (winners.has(identity)) continue;
806
+ headOwned.delete(identity);
807
+ headApplied.delete(identity);
808
+ if (identity === "title") {
809
+ if (headFallbackTitle != null) setHeadTitle(headFallbackTitle).removeAttribute("data-dh");
810
+ } else {
811
+ for (let i = 0; i < els.length; i++) els[i].remove();
812
+ }
813
+ }
814
+ for (const [identity, winner] of winners) {
815
+ let sig = "";
816
+ for (let i = 0; i < winner.tags.length; i++) sig += winner.tags[i].tag + JSON.stringify(winner.tags[i].props) + "|";
817
+ if (headApplied.get(identity) === sig) continue;
818
+ headApplied.set(identity, sig);
819
+ if (identity === "base" || identity === "charset") {
820
+ console.warn(`useHead: <${winner.tags[0].tag}> (${identity}) is shell-only and ignored on the client`);
821
+ continue;
822
+ }
823
+ if (identity === "title") {
824
+ const children = winner.tags[0].props.children;
825
+ setHeadTitle(children == null ? "" : String(children));
826
+ headOwned.set(identity, []);
827
+ continue;
828
+ }
829
+ const existing = headMarkedElements(identity);
830
+ const els = [];
831
+ for (let i = 0; i < winner.tags.length; i++) {
832
+ els.push(renderHeadElement(winner.tags[i], identity, existing));
833
+ }
834
+ for (let i = 0; i < existing.length; i++) {
835
+ if (els.indexOf(existing[i]) === -1) existing[i].remove();
836
+ }
837
+ headOwned.set(identity, els);
838
+ }
839
+ }
840
+ function renderHeadElement(t, identity, existing) {
841
+ for (let i = 0; i < existing.length; i++) {
842
+ if (headElementMatches(existing[i], t)) return existing.splice(i, 1)[0];
843
+ }
844
+ const el = document.createElement(t.tag);
845
+ for (const name in t.props) {
846
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
847
+ if (!HEAD_ATTR_NAME.test(name)) {
848
+ console.warn(`useHead: ignoring invalid attribute name "${name}"`);
280
849
  continue;
281
850
  }
282
- const value = props[prop];
283
- prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef);
851
+ const v = t.props[name];
852
+ if (v == null || v === false) continue;
853
+ el.setAttribute(name, v === true ? "" : String(v));
284
854
  }
855
+ if (t.props.children != null) el.textContent = String(t.props.children);
856
+ el.setAttribute("data-dh", identity);
857
+ document.head.appendChild(el);
858
+ return el;
859
+ }
860
+ function headElementMatches(el, t) {
861
+ if (el.tagName.toLowerCase() !== t.tag) return false;
862
+ for (const name in t.props) {
863
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
864
+ if (!HEAD_ATTR_NAME.test(name)) continue;
865
+ const v = t.props[name];
866
+ if (v == null || v === false) {
867
+ if (el.hasAttribute(name)) return false;
868
+ } else if (el.getAttribute(name) !== (v === true ? "" : String(v))) return false;
869
+ }
870
+ const children = t.props.children;
871
+ return (children == null ? "" : String(children)) === el.textContent;
872
+ }
873
+ function acquireHeadResource(tag, props) {
874
+ if (tag === "link" && (props.rel === "stylesheet" || props.rel === "modulepreload")) {
875
+ const descriptor = {
876
+ type: props.rel === "stylesheet" ? "style" : "module",
877
+ href: props.href
878
+ };
879
+ let attrs = null;
880
+ for (const name in props) {
881
+ if (name === "rel" || name === "href") continue;
882
+ if (!HEAD_ATTR_NAME.test(name)) continue;
883
+ const v = props[name];
884
+ if (v == null || v === false) continue;
885
+ (attrs || (attrs = {}))[name] = v === true ? "" : String(v);
886
+ }
887
+ if (attrs) descriptor.attrs = attrs;
888
+ return acquireAsset(descriptor);
889
+ }
890
+ const identity = resourceIdentity(tag, props);
891
+ if (headMountedResources.has(identity)) return noopFn;
892
+ headMountedResources.add(identity);
893
+ const url = props.href || props.src;
894
+ let el = null;
895
+ if (url != null) {
896
+ if (tag === "link") el = findAssetElement(`link[rel="${props.rel}"]`, "href", url);else if (tag === "script") el = findAssetElement("script[src]", "src", url);else el = findAssetElement("style[href]", "href", url);
897
+ }
898
+ if (!el) {
899
+ el = document.createElement(tag);
900
+ for (const name in props) {
901
+ if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
902
+ if (!HEAD_ATTR_NAME.test(name)) continue;
903
+ const v = props[name];
904
+ if (v == null || v === false) continue;
905
+ el.setAttribute(name, v === true ? "" : String(v));
906
+ }
907
+ if (props.children != null) el.textContent = String(props.children);
908
+ document.head.appendChild(el);
909
+ }
910
+ return noopFn;
911
+ }
912
+ function noopFn() {}
913
+ function useHead(tags) {
914
+ const list = Array.isArray(tags) ? tags : [tags];
915
+ initHeadRegistry();
916
+ const reg = {
917
+ seq: -1,
918
+ tags: null
919
+ };
920
+ const uid = ++headUid;
921
+ effect(() => {
922
+ const replaceable = [];
923
+ const resources = [];
924
+ for (let i = 0; i < list.length; i++) {
925
+ const desc = list[i];
926
+ if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
927
+ console.warn(`useHead: ignoring non-head tag`, desc);
928
+ continue;
929
+ }
930
+ const cls = classifyHeadTag(desc);
931
+ const props = evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
932
+ rel: cls.rel
933
+ } : undefined);
934
+ if (cls.resource) {
935
+ resources.push({
936
+ tag: desc.tag,
937
+ props
938
+ });
939
+ } else {
940
+ const key = evalHeadValue(desc.key);
941
+ replaceable.push({
942
+ tag: desc.tag,
943
+ props,
944
+ identity: replaceableIdentity(desc.tag, props, key, "u:c" + uid + ":" + i)
945
+ });
946
+ }
947
+ }
948
+ return {
949
+ replaceable,
950
+ resources
951
+ };
952
+ }, evaluated => {
953
+ const releases = [];
954
+ for (let i = 0; i < evaluated.resources.length; i++) {
955
+ releases.push(acquireHeadResource(evaluated.resources[i].tag, evaluated.resources[i].props));
956
+ }
957
+ reg.tags = evaluated.replaceable;
958
+ if (reg.seq < 0) reg.seq = ++headSeq;
959
+ if (headRegistrations.indexOf(reg) === -1) headRegistrations.push(reg);
960
+ scheduleHeadApply();
961
+ return () => {
962
+ const idx = headRegistrations.indexOf(reg);
963
+ if (idx > -1) headRegistrations.splice(idx, 1);
964
+ for (let i = 0; i < releases.length; i++) releases[i]();
965
+ scheduleHeadApply();
966
+ };
967
+ });
968
+ }
969
+ function loadModuleAssets(mapping) {
970
+ const hy = globalThis._$HY;
971
+ if (!hy) return;
972
+ const pending = [];
973
+ for (const key in mapping) {
974
+ if (hy.modules[key]) continue;
975
+ const entryUrl = mapping[key];
976
+ if (!hy.loading[key]) {
977
+ hy.loading[key] = import(entryUrl).then(mod => {
978
+ hy.modules[key] = mod;
979
+ }, err => {
980
+ delete hy.loading[key];
981
+ throw err;
982
+ });
983
+ }
984
+ pending.push(hy.loading[key]);
985
+ }
986
+ return pending.length ? Promise.all(pending).then(() => {}) : undefined;
285
987
  }
286
988
  function hydrate$1(code, element, options = {}) {
989
+ installHydrationRuntime();
287
990
  if (globalThis._$HY.done) return render$1(code, element, [...element.childNodes], options);
288
991
  options.renderId ||= "";
289
992
  if (!globalThis._$HY.modules) globalThis._$HY.modules = {};
@@ -293,6 +996,7 @@ function hydrate$1(code, element, options = {}) {
293
996
  sharedConfig.load = id => globalThis._$HY.r[id];
294
997
  sharedConfig.has = id => id in globalThis._$HY.r;
295
998
  sharedConfig.gather = root => gatherHydratable(element, root);
999
+ sharedConfig.loadModuleAssets = loadModuleAssets;
296
1000
  sharedConfig.cleanupFragment = id => {
297
1001
  const tpl = document.getElementById("pl-" + id);
298
1002
  if (tpl) {
@@ -310,15 +1014,45 @@ function hydrate$1(code, element, options = {}) {
310
1014
  }
311
1015
  };
312
1016
  sharedConfig.registry = new Map();
1017
+ if (!sharedConfig.boundaryScopes) sharedConfig.boundaryScopes = new Map();
1018
+ sharedConfig.captureBoundaryScope = id => {
1019
+ if (sharedConfig.registry) sharedConfig.boundaryScopes.set(id, {
1020
+ registry: sharedConfig.registry,
1021
+ gather: sharedConfig.gather
1022
+ });
1023
+ };
313
1024
  sharedConfig.hydrating = true;
314
1025
  {
315
1026
  sharedConfig.verifyHydration = () => {
316
1027
  if (sharedConfig.registry && sharedConfig.registry.size) {
317
- const orphaned = [...sharedConfig.registry.values()];
1028
+ const orphaned = [...sharedConfig.registry.values()].filter(node => node.isConnected);
1029
+ sharedConfig.registry.clear();
1030
+ if (!orphaned.length) return;
318
1031
  console.warn(`Hydration completed with ${orphaned.length} unclaimed server-rendered node(s):\n` + orphaned.map(node => ` ${node.outerHTML.slice(0, 100)}`).join("\n"));
319
1032
  }
320
1033
  };
321
1034
  }
1035
+ const rootMapping = globalThis._$HY.r && globalThis._$HY.r["_assets"];
1036
+ if (rootMapping && typeof rootMapping === "object") {
1037
+ const p = loadModuleAssets(rootMapping);
1038
+ if (p) {
1039
+ gatherHydratable(element, options.renderId);
1040
+ let disposer;
1041
+ p.then(() => {
1042
+ try {
1043
+ disposer = render$1(code, element, [...element.childNodes], options);
1044
+ } finally {
1045
+ sharedConfig.hydrating = false;
1046
+ }
1047
+ }, err => {
1048
+ console.error("Hydration module preload failed, falling back to client render:", err);
1049
+ sharedConfig.hydrating = false;
1050
+ sharedConfig.registry = undefined;
1051
+ disposer = render$1(code, element, [...element.childNodes], options);
1052
+ });
1053
+ return () => disposer && disposer();
1054
+ }
1055
+ }
322
1056
  try {
323
1057
  gatherHydratable(element, options.renderId);
324
1058
  return render$1(code, element, [...element.childNodes], options);
@@ -380,20 +1114,21 @@ function getFirstChild(node, expectedTag) {
380
1114
  function getNextSibling(node, expectedTag) {
381
1115
  const sibling = node.nextSibling;
382
1116
  if (isHydrating() && expectedTag && sibling?.localName !== expectedTag) {
383
- const parent = node.parentElement;
1117
+ const parent = node.parentNode;
384
1118
  const isMissing = !sibling || sibling.nodeType !== 1;
385
1119
  console.warn("Hydration structure mismatch: expected <" + expectedTag + "> after", node, "in", parent, "\n " + describeSiblings(parent, sibling, expectedTag, isMissing));
386
1120
  }
387
1121
  return sibling;
388
1122
  }
389
1123
  function describeSiblings(parent, mismatchChild, expectedTag, isMissing) {
1124
+ if (!parent) return `<${expectedTag} \u2190 parent unavailable>`;
390
1125
  const children = [];
391
1126
  let child = parent.firstChild;
392
1127
  while (child) {
393
1128
  if (child.nodeType === 1) children.push(child);
394
1129
  child = child.nextSibling;
395
1130
  }
396
- const pTag = parent.localName;
1131
+ const pTag = parent.localName || "#fragment";
397
1132
  if (isMissing) {
398
1133
  const tags = children.map(c => `<${c.localName}>`).join("");
399
1134
  return `<${pTag}>${tags}<${expectedTag} \u2190 missing></${pTag}>`;
@@ -425,7 +1160,32 @@ function runHydrationEvents() {
425
1160
  const [el, e] = events[0];
426
1161
  if (!completed.has(el)) return;
427
1162
  events.shift();
428
- eventHandler(e);
1163
+ let matchContainer, matchState, matchDistance, matches;
1164
+ for (const [container, state] of delegatedContainers) {
1165
+ if (!state.handlers.has(e.type)) continue;
1166
+ const entry = findOwner(e.target, state);
1167
+ if (!entry) continue;
1168
+ if (matchContainer) {
1169
+ if (!matches) matches = [{
1170
+ container: matchContainer,
1171
+ state: matchState,
1172
+ distance: matchDistance
1173
+ }];
1174
+ matches.push({
1175
+ container,
1176
+ state,
1177
+ distance: entry.distance
1178
+ });
1179
+ } else {
1180
+ matchContainer = container;
1181
+ matchState = state;
1182
+ matchDistance = entry.distance;
1183
+ }
1184
+ }
1185
+ if (matches) {
1186
+ matches.sort((a, b) => a.distance - b.distance);
1187
+ for (let i = 0; i < matches.length; i++) eventHandler(e, matches[i].container, matches[i].state);
1188
+ } else if (matchContainer) eventHandler(e, matchContainer, matchState);
429
1189
  }
430
1190
  if (sharedConfig.done) {
431
1191
  sharedConfig.events = _$HY.events = null;
@@ -436,16 +1196,31 @@ function runHydrationEvents() {
436
1196
  }
437
1197
  }
438
1198
  function isHydrating(node) {
439
- return sharedConfig.hydrating && (!node || node.isConnected);
440
- }
441
- function toggleClassKey(node, key, value) {
442
- const classNames = key.trim().split(/\s+/);
443
- for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
1199
+ if (!sharedConfig.hydrating) return false;
1200
+ if (!node || node.isConnected) return true;
1201
+ const roots = sharedConfig.claimRoots;
1202
+ if (roots) {
1203
+ for (let i = 0; i < roots.length; i++) {
1204
+ if (roots[i].contains(node)) return true;
1205
+ }
1206
+ }
1207
+ return false;
444
1208
  }
445
1209
  function classListToObject(classList) {
446
1210
  if (Array.isArray(classList)) {
447
1211
  const result = {};
448
1212
  flattenClassList(classList, result);
1213
+ classList = result;
1214
+ }
1215
+ if (classList && typeof classList === "object") {
1216
+ const result = {},
1217
+ keys = Object.keys(classList);
1218
+ for (let i = 0, len = keys.length; i < len; i++) {
1219
+ const key = keys[i];
1220
+ if (!classList[key]) continue;
1221
+ const classNames = key.trim().split(/\s+/);
1222
+ for (let j = 0, nameLen = classNames.length; j < nameLen; j++) classNames[j] && (result[classNames[j]] = true);
1223
+ }
449
1224
  return result;
450
1225
  }
451
1226
  return classList;
@@ -456,18 +1231,16 @@ function flattenClassList(list, result) {
456
1231
  if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);else if (item || item === 0) result[item] = true;
457
1232
  }
458
1233
  }
459
- function assignProp(node, prop, value, prev, isSVG, skipRef) {
460
- let forceProp;
1234
+ function assignProp(node, prop, value, prev, skipRef, nodeName) {
461
1235
  if (prop === "style") return style(node, value, prev), value;
462
- if (prop === "class") return className(node, value, isSVG, prev), value;
463
- if (value === prev) return prev;
1236
+ if (prop === "class") return className(node, value, prev), value;
1237
+ if (value === prev && DOMWithState[nodeName]?.[prop] !== 1) return prev;
464
1238
  if (prop === "ref") {
465
1239
  if (!skipRef && value) ref(() => value, node);
466
- } else if (prop.slice(0, 3) === "on:") {
467
- const e = prop.slice(3);
468
- prev && node.removeEventListener(e, prev, typeof prev !== "function" && prev);
469
- value && node.addEventListener(e, value, typeof value !== "function" && value);
470
- } else if (prop.slice(0, 2) === "on") {
1240
+ return value;
1241
+ }
1242
+ const hasNamespace = prop.indexOf(":") > -1;
1243
+ if (!hasNamespace && prop.slice(0, 2) === "on") {
471
1244
  const name = prop.slice(2).toLowerCase();
472
1245
  const delegate = DelegatedEvents.has(name);
473
1246
  if (!delegate && prev) {
@@ -475,26 +1248,34 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) {
475
1248
  node.removeEventListener(name, h);
476
1249
  }
477
1250
  if (delegate || value) {
478
- addEventListener(node, name, value, delegate);
1251
+ addEvent(node, name, value, delegate);
479
1252
  delegate && delegateEvents([name]);
480
1253
  }
481
- } else if ((forceProp = prop.slice(0, 5) === "prop:") || ChildProperties.has(prop) || !isSVG && Properties.has(prop)) {
482
- if (forceProp) prop = prop.slice(5);else if (isHydrating(node)) return value;
483
- if (prop === "value" && node.nodeName === "SELECT") queueMicrotask(() => node.value = value) || (node.value = value);else node[prop] = value;
1254
+ } else if (hasNamespace && prop.slice(0, 5) === "prop:" || ChildProperties.has(prop) || DOMWithState[nodeName]?.[prop]) {
1255
+ if (hasNamespace) prop = prop.slice(5);else if (isHydrating(node)) return value;
1256
+ if (prop === "value" && nodeName === "SELECT") queueMicrotask(() => node.value = value) || (node.value = value);else if ((prop === "value" || prop === "defaultValue") && (nodeName === "INPUT" || nodeName === "TEXTAREA"))
1257
+ node[prop] = value ?? "";else node[prop] = value;
484
1258
  } else {
485
- const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
1259
+ const ns = hasNamespace && Namespaces[prop.split(":")[0]];
486
1260
  if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, prop, value);
487
1261
  }
488
1262
  return value;
489
1263
  }
490
- function eventHandler(e) {
491
- if (sharedConfig.registry && sharedConfig.events) {
492
- if (sharedConfig.events.find(([el, ev]) => ev === e)) return;
1264
+ function eventHandler(e, container, state) {
1265
+ if (hydrationRt !== null && hydrationRt.dedupEvent(e)) return;
1266
+ const prev = e[$$EVENT_OWNER];
1267
+ let resumeNode;
1268
+ if (prev) {
1269
+ if (prev === true || prev === container || !container.contains(prev)) return;
1270
+ resumeNode = prev;
493
1271
  }
494
- let node = e.target;
1272
+ const owner = state && (state.owners.size === 1 && state.owners.has(container) ? container : findOwner(e.target, state)?.owner);
1273
+ if (state && !owner) return;
1274
+ e[$$EVENT_OWNER] = owner || true;
1275
+ let node = resumeNode || e.target;
495
1276
  const key = `$$${e.type}`;
496
1277
  const oriTarget = e.target;
497
- const oriCurrentTarget = e.currentTarget;
1278
+ const boundary = owner || container || e.currentTarget;
498
1279
  const retarget = value => Object.defineProperty(e, "target", {
499
1280
  configurable: true,
500
1281
  value
@@ -510,35 +1291,43 @@ function eventHandler(e) {
510
1291
  return true;
511
1292
  };
512
1293
  const walkUpTree = () => {
513
- while (handleNode() && (node = node._$host || node.parentNode || node.host));
1294
+ while (handleNode()) {
1295
+ if (node === boundary || node.parentNode === boundary) break;
1296
+ node = node._$host || node.parentNode || node.host;
1297
+ }
514
1298
  };
515
1299
  Object.defineProperty(e, "currentTarget", {
516
1300
  configurable: true,
517
1301
  get() {
518
- return node || document;
1302
+ return node || boundary || document;
519
1303
  }
520
1304
  });
521
- if (e.composedPath) {
1305
+ if (resumeNode) {
1306
+ if (resumeNode === e.target) node = resumeNode._$host || resumeNode.parentNode || resumeNode.host;
1307
+ if (node && node !== boundary) walkUpTree();
1308
+ } else if (e.composedPath) {
522
1309
  const path = e.composedPath();
523
- retarget(path[0]);
524
- for (let i = 0; i < path.length - 2; i++) {
525
- node = path[i];
526
- if (!handleNode()) break;
527
- if (node._$host) {
528
- node = node._$host;
529
- walkUpTree();
530
- break;
531
- }
532
- if (node.parentNode === oriCurrentTarget) {
533
- break;
1310
+ if (path.length) {
1311
+ retarget(path[0]);
1312
+ for (let i = 0; i < path.length; i++) {
1313
+ node = path[i];
1314
+ if (!handleNode()) break;
1315
+ if (node._$host) {
1316
+ node = node._$host;
1317
+ walkUpTree();
1318
+ break;
1319
+ }
1320
+ if (node === boundary || node.parentNode === boundary) {
1321
+ break;
1322
+ }
534
1323
  }
535
- }
1324
+ } else walkUpTree();
536
1325
  }
537
1326
  else walkUpTree();
538
1327
  retarget(oriTarget);
539
1328
  }
540
1329
  function insertExpression(parent, value, current, marker) {
541
- if (isHydrating(parent)) return;
1330
+ if (hydrationRt !== null && isHydrating(parent)) return;
542
1331
  if (value === current) return;
543
1332
  const t = typeof value,
544
1333
  multi = marker !== undefined;
@@ -546,15 +1335,25 @@ function insertExpression(parent, value, current, marker) {
546
1335
  const tc = typeof current;
547
1336
  if (tc === "string" || tc === "number") {
548
1337
  parent.firstChild.data = value;
549
- } else parent.textContent = value;
1338
+ } else {
1339
+ if (ownsAllChildren(parent, current)) parent.textContent = value;else {
1340
+ removeOwnedChildren(parent, current);
1341
+ parent.insertBefore(document.createTextNode(value), parent.firstChild);
1342
+ }
1343
+ }
550
1344
  } else if (value === undefined) {
551
1345
  cleanChildren(parent, current, marker);
552
1346
  } else if (value.nodeType) {
553
1347
  if (Array.isArray(current)) {
554
1348
  cleanChildren(parent, current, multi ? marker : null, value);
555
- } else if (current === undefined || !parent.firstChild) {
1349
+ } else if (current && current.nodeType) {
1350
+ current.parentNode === parent ? parent.replaceChild(value, current) : parent.appendChild(value);
1351
+ } else if (current && parent.firstChild) {
1352
+ parent.replaceChild(value, parent.firstChild);
1353
+ } else {
556
1354
  parent.appendChild(value);
557
- } else parent.replaceChild(value, parent.firstChild);
1355
+ }
1356
+ if (marker) value[$$SLOT] = marker;
558
1357
  } else if (Array.isArray(value)) {
559
1358
  const currentArray = current && Array.isArray(current);
560
1359
  if (value.length === 0) {
@@ -562,9 +1361,9 @@ function insertExpression(parent, value, current, marker) {
562
1361
  } else if (currentArray) {
563
1362
  if (current.length === 0) {
564
1363
  appendNodes(parent, value, marker);
565
- } else reconcileArrays(parent, current, value);
1364
+ } else reconcileArrays(parent, current, value, marker);
566
1365
  } else {
567
- current && cleanChildren(parent);
1366
+ current && cleanChildren(parent, current);
568
1367
  appendNodes(parent, value);
569
1368
  }
570
1369
  } else console.warn(`Unrecognized value. Skipped inserting`, value);
@@ -586,21 +1385,64 @@ function normalize(value, current, multi, doNotUnwrap) {
586
1385
  }
587
1386
  return value;
588
1387
  }
1388
+ function tagHost(value, host) {
1389
+ if (Array.isArray(value)) {
1390
+ for (let i = 0, len = value.length; i < len; i++) tagHost(value[i], host);
1391
+ } else if (value && value.nodeType && value[$$HOST] !== host) {
1392
+ value[$$HOST] = host;
1393
+ Object.defineProperty(value, "_$host", {
1394
+ get: host,
1395
+ configurable: true
1396
+ });
1397
+ }
1398
+ }
589
1399
  function appendNodes(parent, array, marker = null) {
590
- for (let i = 0, len = array.length; i < len; i++) parent.insertBefore(array[i], marker);
1400
+ for (let i = 0, len = array.length; i < len; i++) {
1401
+ const n = array[i];
1402
+ parent.insertBefore(n, marker);
1403
+ if (marker) n[$$SLOT] = marker;
1404
+ }
1405
+ }
1406
+ function ownsAllChildren(parent, current) {
1407
+ if (current == null) return true;
1408
+ if (Array.isArray(current)) {
1409
+ return current.length ? parent.firstChild === current[0] && parent.lastChild === current[current.length - 1] : parent.firstChild === null;
1410
+ }
1411
+ if (current === "") return parent.firstChild === null;
1412
+ if (current.nodeType) return parent.firstChild === current && parent.lastChild === current;
1413
+ const first = parent.firstChild;
1414
+ return first !== null && first.nodeType === 3 && parent.lastChild === first;
1415
+ }
1416
+ function removeOwnedChildren(parent, current) {
1417
+ if (Array.isArray(current)) {
1418
+ for (let i = 0; i < current.length; i++) {
1419
+ const el = current[i];
1420
+ if (el.parentNode === parent) el.remove();
1421
+ }
1422
+ } else if (current.nodeType) {
1423
+ if (current.parentNode === parent) current.remove();
1424
+ } else {
1425
+ const first = parent.firstChild;
1426
+ if (first && first.nodeType === 3) first.remove();
1427
+ }
591
1428
  }
592
1429
  function cleanChildren(parent, current, marker, replacement) {
593
- if (marker === undefined) return parent.textContent = "";
1430
+ if (marker === undefined) {
1431
+ if (ownsAllChildren(parent, current)) return parent.textContent = "";
1432
+ return removeOwnedChildren(parent, current);
1433
+ }
594
1434
  if (current.length) {
595
1435
  let inserted = false;
596
1436
  for (let i = current.length - 1; i >= 0; i--) {
597
1437
  const el = current[i];
598
1438
  if (replacement !== el) {
599
- const isParent = el.parentNode === parent;
600
- if (replacement && !inserted && !i) isParent ? parent.replaceChild(replacement, el) : parent.insertBefore(replacement, marker);else isParent && el.remove();
1439
+ const tag = el[$$SLOT];
1440
+ const owns = el.parentNode === parent && (!tag || tag === marker);
1441
+ if (replacement && !inserted && !i) owns ? parent.replaceChild(replacement, el) : parent.insertBefore(replacement, marker);else if (owns) el.remove();
601
1442
  } else inserted = true;
602
1443
  }
603
1444
  } else if (replacement) parent.insertBefore(replacement, marker);
1445
+ if (replacement && marker) replacement[$$SLOT] = marker;
604
1446
  }
605
1447
  function gatherHydratable(element, root) {
606
1448
  const templates = element.querySelectorAll(`*[_hk]`);
@@ -638,82 +1480,216 @@ function ssrHydrationKey() {}
638
1480
  function resolveSSRNode(node) {}
639
1481
  function escape(html) {}
640
1482
 
641
- function render(...args) {
642
- enforceLoadingBoundary(true);
643
- const result = render$1(...args);
644
- enforceLoadingBoundary(false);
645
- return result;
1483
+ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
1484
+ class ResponseEnvelope {
1485
+ constructor(response, value) {
1486
+ this.response = response;
1487
+ this.value = value;
1488
+ }
1489
+ }
1490
+ ResponseEnvelope.prototype[ENVELOPE] = true;
1491
+ function isResponseEnvelope(value) {
1492
+ return !!(value && typeof value === "object" && value[ENVELOPE]);
1493
+ }
1494
+ const HREF = Symbol.for("solid.Href");
1495
+ function isHref(value) {
1496
+ return !!(value && (typeof value === "object" || typeof value === "function") && value[HREF]);
1497
+ }
1498
+ const REVALIDATE_HEADER = "X-Revalidate";
1499
+ function initWithRevalidate(init) {
1500
+ const {
1501
+ revalidate,
1502
+ ...responseInit
1503
+ } = init;
1504
+ const headers = new Headers(responseInit.headers);
1505
+ revalidate !== undefined && headers.set(REVALIDATE_HEADER, revalidate.toString());
1506
+ return {
1507
+ responseInit,
1508
+ headers
1509
+ };
646
1510
  }
1511
+ function redirect(url, init = 302) {
1512
+ if (typeof url !== "string" && !isHref(url)) {
1513
+ throw new TypeError("redirect() expects a string URL or an Href-branded value (Symbol.for('solid.Href')).");
1514
+ }
1515
+ const {
1516
+ responseInit,
1517
+ headers
1518
+ } = initWithRevalidate(typeof init === "number" ? {
1519
+ status: init
1520
+ } : init);
1521
+ if (responseInit.status === undefined) {
1522
+ responseInit.status = 302;
1523
+ }
1524
+ headers.set("Location", String(url));
1525
+ return new Response(null, {
1526
+ ...responseInit,
1527
+ headers
1528
+ });
1529
+ }
1530
+ function reload(init = {}) {
1531
+ const {
1532
+ responseInit,
1533
+ headers
1534
+ } = initWithRevalidate(init);
1535
+ return new Response(null, {
1536
+ ...responseInit,
1537
+ headers
1538
+ });
1539
+ }
1540
+ function respond(value, init = {}) {
1541
+ const {
1542
+ responseInit,
1543
+ headers
1544
+ } = initWithRevalidate(init);
1545
+ headers.set("Content-Type", "application/json");
1546
+ return new ResponseEnvelope(new Response(JSON.stringify(value), {
1547
+ ...responseInit,
1548
+ headers
1549
+ }), value);
1550
+ }
1551
+
1552
+ const mergeProps = merge;
647
1553
  const isServer = false;
648
1554
  const isDev = true;
649
- const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
650
- function createElement(tagName, isSVG = false, is = undefined) {
651
- return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName, {
652
- is
653
- });
1555
+ function render(code, element, init, options = {}) {
1556
+ enforceLoadingBoundary(true);
1557
+ try {
1558
+ const dispose = render$1(code, element, init, {
1559
+ ...options,
1560
+ insertOptions: {
1561
+ schedule: true
1562
+ }
1563
+ });
1564
+ flush();
1565
+ return dispose;
1566
+ } finally {
1567
+ enforceLoadingBoundary(false);
1568
+ }
654
1569
  }
655
1570
  const hydrate = (...args) => {
656
1571
  enableHydration();
657
1572
  return hydrate$1(...args);
658
1573
  };
659
1574
  function Portal(props) {
1575
+ return runWithOwner(createOwner(), () => portalImpl(props));
1576
+ }
1577
+ function portalImpl(props) {
660
1578
  const treeMarker = document.createTextNode(""),
661
1579
  startMarker = document.createTextNode(""),
662
1580
  endMarker = document.createTextNode(""),
663
- mount = () => createElementProxy(props.mount || document.body, treeMarker);
664
- let content = createMemo$1(() => [startMarker, props.children]);
665
- createRenderEffect(() => [mount(), content()], ([m, c]) => {
1581
+ mount = () => props.mount || document.body,
1582
+ content = createMemo(() => [startMarker, props.children], {
1583
+ ssrSource: "client"
1584
+ });
1585
+ createRenderEffect(
1586
+ () => [mount(), content(), getOwner()], ([, c, owner]) => {
1587
+ const m = untrack(mount);
666
1588
  m.appendChild(endMarker);
667
- insert(m, c, endMarker);
1589
+ const dispose = runWithOwner(owner, () => createRoot(d => {
1590
+ insert(m, c, endMarker, undefined, {
1591
+ host: () => treeMarker.parentNode
1592
+ });
1593
+ return d;
1594
+ }));
668
1595
  return () => {
1596
+ dispose();
669
1597
  let c = startMarker;
670
- while (c && c !== endMarker) {
1598
+ while (c) {
671
1599
  const n = c.nextSibling;
672
1600
  m.removeChild(c);
1601
+ if (c === endMarker) break;
673
1602
  c = n;
674
1603
  }
675
1604
  };
1605
+ },
1606
+ {
1607
+ schedule: true,
1608
+ ssrSource: "client"
1609
+ });
1610
+ createEffect(mount, () => {
1611
+ const m = untrack(mount);
1612
+ const ownerRoot = getDelegatedRoot(treeMarker);
1613
+ if (!ownerRoot || ownerRoot.contains(m)) return;
1614
+ registerDelegatedContainer(m, ownerRoot);
1615
+ return () => unregisterDelegatedContainer(m, ownerRoot);
1616
+ }, {
1617
+ ssrSource: "client"
1618
+ });
1619
+ if (sharedConfig.hydrating) return createMemo(() => treeMarker, {
1620
+ ssrSource: "client"
676
1621
  });
677
1622
  return treeMarker;
678
1623
  }
679
- function createElementProxy(el, marker) {
680
- return new Proxy(el, {
681
- get(target, prop) {
682
- if (prop === "appendChild" || prop === "insertBefore") {
683
- return (...args) => {
684
- Object.defineProperty(args[0], "_$host", {
685
- get: () => marker.parentNode,
686
- configurable: true
1624
+ const COMPONENT_HANDOFF = Symbol.for("dom-expressions.component-handoff");
1625
+ function resolveHandoff(next, prev) {
1626
+ const handoff = typeof next === "function" && next !== null && next[COMPONENT_HANDOFF];
1627
+ return handoff && handoff.take(prev) ? prev : next;
1628
+ }
1629
+ function dynamic(source) {
1630
+ let latest = 0;
1631
+ const cached = createMemo(prev => {
1632
+ const next = source();
1633
+ if (!next || typeof next.then !== "function") return resolveHandoff(next, prev);
1634
+ const token = ++latest;
1635
+ return {
1636
+ then: (onFulfilled, onRejected) => next.then(resolved => onFulfilled(token === latest ? resolveHandoff(resolved, prev) : resolved), onRejected)
1637
+ };
1638
+ }, {
1639
+ lazy: true
1640
+ });
1641
+ return props => {
1642
+ return createMemo(() => {
1643
+ const component = cached();
1644
+ switch (typeof component) {
1645
+ case "function":
1646
+ Object.assign(component, {
1647
+ [$DEVCOMP]: true
687
1648
  });
688
- target[prop](...args);
689
- };
1649
+ return untrack(() => component(props));
1650
+ case "string":
1651
+ const el = sharedConfig.hydrating ? getNextElement() : createElement(component, untrack(() => props.is));
1652
+ spread(el, props);
1653
+ return el;
690
1654
  }
691
- const value = Reflect.get(target, prop);
692
- return typeof value === "function" ? value.bind(target) : value;
693
- }
694
- });
1655
+ });
1656
+ };
695
1657
  }
696
- function createDynamic(component, props) {
697
- const cached = createMemo$1(component);
698
- return createMemo$1(() => {
699
- const component = cached();
700
- switch (typeof component) {
701
- case "function":
702
- Object.assign(component, {
703
- [$DEVCOMP]: true
704
- });
705
- return untrack(() => component(props));
706
- case "string":
707
- const isSvg = SVGElements.has(component);
708
- const el = sharedConfig.hydrating ? getNextElement() : createElement(component, isSvg, untrack(() => props.is));
709
- spread(el, props, isSvg);
710
- return el;
711
- }
1658
+ function Dynamic(props) {
1659
+ const Comp = dynamic(() => props.component);
1660
+ return createComponent(Comp, omit(props, "component"));
1661
+ }
1662
+ function createElement(tagName, is = undefined) {
1663
+ return SVGElements.has(tagName) ? document.createElementNS(Namespaces.svg, tagName) : MathMLElements.has(tagName) ? document.createElementNS(Namespaces.mathml, tagName) : document.createElement(tagName, {
1664
+ is
712
1665
  });
713
1666
  }
714
- function Dynamic(props) {
715
- const others = omit(props, "component");
716
- return createDynamic(() => props.component, others);
1667
+ function loadClientOnly(fn, setComp) {
1668
+ fn().then(m => setComp(() => m.default));
1669
+ }
1670
+ function clientOnly(fn, options = {},
1671
+ _moduleUrl) {
1672
+ const [comp, setComp] = createSignal();
1673
+ let started = !options.lazy;
1674
+ started && loadClientOnly(fn, setComp);
1675
+ return props => {
1676
+ let Comp;
1677
+ let m;
1678
+ const rest = omit(props, "fallback");
1679
+ if (!started) {
1680
+ started = true;
1681
+ loadClientOnly(fn, setComp);
1682
+ }
1683
+ if ((Comp = untrack(comp)) && !sharedConfig.hydrating) return Comp(rest);
1684
+ const [mounted, setMounted] = createSignal(!sharedConfig.hydrating);
1685
+ const gate = createMemo(() => (Comp = comp(), m = mounted(), untrack(() => Comp && m ? Comp(rest) : props.fallback)));
1686
+ onSettled(() => {
1687
+ setMounted(true);
1688
+ });
1689
+ return gate;
1690
+ };
717
1691
  }
1692
+ function httpStatus(_code, _text) {}
1693
+ function httpHeader(_name, _value, _options) {}
718
1694
 
719
- export { voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, voidFn as HydrationScript, Portal, Properties, RequestContext, SVGElements, SVGNamespace, addEventListener, applyRef, assign, className, clearDelegatedEvents, createDynamic, delegateEvents, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, hydrate, insert, isDev, isServer, memo, ref, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, voidFn as useAssets };
1695
+ export { voidFn as Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, voidFn as HydrationScript, MathMLElements, Namespaces, Portal, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SVGElements, VoidElements, acquireAsset, addEvent, applyRef, assign, claimElement, claimElementTree, className, clientOnly, delegateEvents, dynamic, dynamicProperty, effect, escape, voidFn as generateHydrationScript, voidFn as getAssets, getDelegatedRoot, getFirstChild, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getNextSibling, voidFn as getRequestEvent, httpHeader, httpStatus, hydrate, insert, installHydrationRuntime, isDev, isHref, isResponseEnvelope, isServer, memo, mergeProps, redirect, ref, registerDelegatedContainer, registerDelegatedRoot, registerElementClaim, reload, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, respond, runHydrationEvents, scope, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrStyle, style, template, unregisterDelegatedContainer, unregisterDelegatedRoot, voidFn as useAssets, useHead };