@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.21

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 (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +790 -223
  3. package/dist/dev.js +764 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +779 -196
  7. package/dist/web.js +753 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +448 -0
  16. package/server-functions/dist/client.js +435 -0
  17. package/server-functions/dist/server.cjs +632 -0
  18. package/server-functions/dist/server.js +615 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +137 -0
  32. package/types/server-functions/server.d.ts +307 -0
  33. package/types/server-functions/shared.d.ts +342 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +137 -0
  45. package/types-cjs/server-functions/server.d.cts +307 -0
  46. package/types-cjs/server-functions/shared.d.cts +342 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
package/dist/server.js CHANGED
@@ -1,11 +1,36 @@
1
- import { createRenderEffect, createMemo as createMemo$1, sharedConfig, createRoot, ssrHandleError, omit, getOwner, getNextChildId, createOwner, runWithOwner } from 'solid-js';
2
- export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Show, Switch, createComponent, getOwner, ssrRunInScope, untrack } from 'solid-js';
3
- import { Serializer, Feature, getCrossReferenceHeader } from 'seroval';
1
+ import { createRenderEffect, createMemo, sharedConfig, createRoot, ssrHandleError, getOwner, runWithOwner, createComponent, omit, getNextChildId, NotReadyError } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, ssrScope as scope, untrack } from 'solid-js';
3
+ import { Serializer, getCrossReferenceHeader, Feature } from 'seroval';
4
4
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
5
- import { createMemo } from '@solidjs/signals';
6
5
 
7
- const Properties = /*#__PURE__*/new Set([
8
- "value", "checked", "selected", "muted"]);
6
+ const DOMWithState = {
7
+ INPUT: {
8
+ value: 1,
9
+ defaultValue: 2,
10
+ checked: 1,
11
+ defaultChecked: 2
12
+ },
13
+ SELECT: {
14
+ value: 1
15
+ },
16
+ OPTION: {
17
+ value: 1,
18
+ selected: 1,
19
+ defaultSelected: 2
20
+ },
21
+ TEXTAREA: {
22
+ value: 1,
23
+ defaultValue: 2
24
+ },
25
+ VIDEO: {
26
+ muted: 1,
27
+ defaultMuted: 2
28
+ },
29
+ AUDIO: {
30
+ muted: 1,
31
+ defaultMuted: 2
32
+ }
33
+ };
9
34
  const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
10
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"]);
11
36
  const SVGElements = /*#__PURE__*/new Set([
@@ -13,52 +38,76 @@ const SVGElements = /*#__PURE__*/new Set([
13
38
  "set", "stop",
14
39
  "svg", "switch", "symbol", "text", "textPath",
15
40
  "tref", "tspan", "use", "view", "vkern"]);
16
- 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",
17
45
  xlink: "http://www.w3.org/1999/xlink",
18
46
  xml: "http://www.w3.org/XML/1998/namespace"
19
47
  };
20
- 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",
21
- "webview",
22
- "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(","));
23
51
 
24
- const effect = (fn, effectFn, initial) => createRenderEffect(fn, effectFn, initial, {
25
- transparent: true
26
- });
27
- const memo = (fn, transparent) => transparent ? fn.$r ? fn : createMemo(() => fn(), undefined, {
28
- transparent: true
29
- }) : 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);
30
65
 
31
- const ES2017FLAG = Feature.AggregateError
32
- | Feature.BigIntTypedArray;
33
- const GLOBAL_IDENTIFIER = '_$HY.r';
34
- function createSerializer({
66
+ const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
67
+ const HYDRATION_GLOBAL = "_$HY.r";
68
+ const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
69
+ CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
70
+ FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
71
+ function resolveSerializerPlugins(customPlugins) {
72
+ return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
73
+ }
74
+ function createSerializer(options) {
75
+ return new Serializer({
76
+ ...options,
77
+ plugins: resolveSerializerPlugins(options.plugins),
78
+ disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
79
+ });
80
+ }
81
+ function createHydrationSerializer({
35
82
  onData,
36
83
  onDone,
37
84
  scopeId,
38
85
  onError,
39
- plugins: customPlugins
86
+ plugins
40
87
  }) {
41
- const defaultPlugins = [AbortSignalPlugin,
42
- CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
43
- FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin];
44
- const allPlugins = customPlugins ? [...customPlugins, ...defaultPlugins] : defaultPlugins;
45
- return new Serializer({
88
+ return createSerializer({
46
89
  scopeId,
47
- plugins: allPlugins,
48
- globalIdentifier: GLOBAL_IDENTIFIER,
49
- disabledFeatures: ES2017FLAG,
90
+ plugins,
91
+ globalIdentifier: HYDRATION_GLOBAL,
50
92
  onData,
51
93
  onDone,
52
94
  onError
53
95
  });
54
96
  }
55
97
  function getLocalHeaderScript(id) {
56
- return getCrossReferenceHeader(id) + ';';
98
+ return getCrossReferenceHeader(id) + ";";
57
99
  }
100
+ Feature.RegExp;
58
101
 
102
+ function joinAssetPath(base, file) {
103
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
104
+ if (typeof base !== "string" || !base) base = "/";
105
+ if (base[base.length - 1] !== "/") base += "/";
106
+ return base + (file[0] === "/" ? file.slice(1) : file);
107
+ }
59
108
  function resolveAssets(moduleUrl, manifest) {
60
109
  if (!manifest) return null;
61
- const base = manifest._base || "/";
110
+ const base = manifest._base;
62
111
  const entry = manifest[moduleUrl];
63
112
  if (!entry) return null;
64
113
  const css = [];
@@ -69,8 +118,8 @@ function resolveAssets(moduleUrl, manifest) {
69
118
  visited.add(key);
70
119
  const e = manifest[key];
71
120
  if (!e) return;
72
- js.push(base + e.file);
73
- if (e.css) for (let i = 0; i < e.css.length; i++) css.push(base + e.css[i]);
121
+ js.push(joinAssetPath(base, e.file));
122
+ if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
74
123
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
75
124
  };
76
125
  walk(moduleUrl);
@@ -80,7 +129,7 @@ function resolveAssets(moduleUrl, manifest) {
80
129
  };
81
130
  }
82
131
  function registerEntryAssets(manifest) {
83
- if (!manifest) return;
132
+ if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
84
133
  const ctx = sharedConfig.context;
85
134
  if (!ctx?.registerAsset) return;
86
135
  for (const key in manifest) {
@@ -97,25 +146,48 @@ function createAssetTracking() {
97
146
  const boundaryModules = new Map();
98
147
  const boundaryStyles = new Map();
99
148
  const emittedAssets = new Set();
149
+ const inlineStyles = new Map();
100
150
  let currentBoundaryId = null;
101
151
  return {
102
152
  boundaryModules,
103
153
  boundaryStyles,
104
154
  emittedAssets,
155
+ inlineStyles,
156
+ registerInlineStyle(desc) {
157
+ let entry = inlineStyles.get(desc.id);
158
+ if (!entry) {
159
+ entry = {
160
+ id: desc.id,
161
+ content: desc.content || "",
162
+ attrs: desc.attrs,
163
+ emitted: false
164
+ };
165
+ inlineStyles.set(desc.id, entry);
166
+ }
167
+ if (currentBoundaryId) {
168
+ let styles = boundaryStyles.get(currentBoundaryId);
169
+ if (!styles) {
170
+ styles = new Set();
171
+ boundaryStyles.set(currentBoundaryId, styles);
172
+ }
173
+ styles.add(entry);
174
+ }
175
+ return entry;
176
+ },
105
177
  get currentBoundaryId() {
106
178
  return currentBoundaryId;
107
179
  },
108
180
  set currentBoundaryId(v) {
109
181
  currentBoundaryId = v;
110
182
  },
111
- registerModule(moduleUrl, entryUrl) {
112
- if (!currentBoundaryId) return;
113
- let map = boundaryModules.get(currentBoundaryId);
183
+ registerModule(key, entryUrl) {
184
+ const id = currentBoundaryId || "";
185
+ let map = boundaryModules.get(id);
114
186
  if (!map) {
115
187
  map = {};
116
- boundaryModules.set(currentBoundaryId, map);
188
+ boundaryModules.set(id, map);
117
189
  }
118
- map[moduleUrl] = entryUrl;
190
+ map[key] = entryUrl;
119
191
  },
120
192
  getBoundaryModules(id) {
121
193
  return boundaryModules.get(id) || null;
@@ -138,10 +210,21 @@ function applyAssetTracking(context, tracking, manifest) {
138
210
  });
139
211
  context.registerModule = tracking.registerModule;
140
212
  context.getBoundaryModules = tracking.getBoundaryModules;
141
- if (manifest) context.resolveAssets = moduleUrl => resolveAssets(moduleUrl, manifest);
213
+ if (typeof manifest === "function") {
214
+ context.resolveAssets = manifest;
215
+ } else if (manifest && typeof manifest.resolve === "function") {
216
+ context.resolveAssets = key => manifest.resolve(key);
217
+ if (typeof manifest.resolveSync === "function") {
218
+ context.resolveAssetsSync = key => manifest.resolveSync(key);
219
+ }
220
+ } else if (manifest) {
221
+ const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
222
+ context.resolveAssets = resolve;
223
+ context.resolveAssetsSync = resolve;
224
+ }
142
225
  }
143
226
  const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
144
- const REPLACE_SCRIPT = `function $df(e,n,o,t){if(n=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content)}n.remove(),_$HY.fe(e)}function $dfs(e,c){(_$HY.sc=_$HY.sc||{})[e]=c}function $dfc(e){if(--_$HY.sc[e]<=0)delete _$HY.sc[e],$df(e)}`;
227
+ const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content),n.remove(),_$HY.fe(e),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
145
228
  function renderToString(code, options = {}) {
146
229
  const {
147
230
  renderId = "",
@@ -150,7 +233,7 @@ function renderToString(code, options = {}) {
150
233
  manifest
151
234
  } = options;
152
235
  let scripts = "";
153
- const serializer = createSerializer({
236
+ const serializer = createHydrationSerializer({
154
237
  scopeId: renderId,
155
238
  plugins: options.plugins,
156
239
  onData(script) {
@@ -176,16 +259,20 @@ function renderToString(code, options = {}) {
176
259
  }
177
260
  serializer.write(id, p);
178
261
  },
179
- registerAsset(type, url) {
262
+ registerAsset(type, value) {
263
+ if (type === "inline-style") {
264
+ tracking.registerInlineStyle(value);
265
+ return;
266
+ }
180
267
  if (tracking.currentBoundaryId && type === "style") {
181
268
  let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
182
269
  if (!styles) {
183
270
  styles = new Set();
184
271
  tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
185
272
  }
186
- styles.add(url);
273
+ styles.add(value);
187
274
  }
188
- tracking.emittedAssets.add(url);
275
+ tracking.emittedAssets.add(value);
189
276
  }
190
277
  };
191
278
  applyAssetTracking(sharedConfig.context, tracking, manifest);
@@ -196,10 +283,12 @@ function renderToString(code, options = {}) {
196
283
  }, {
197
284
  id: renderId
198
285
  });
286
+ serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context);
199
287
  sharedConfig.context.noHydrate = true;
200
288
  serializer.close();
201
289
  html = injectAssets(sharedConfig.context.assets, html);
202
290
  html = injectPreloadLinks(tracking.emittedAssets, html);
291
+ html = injectInlineStyles(tracking.inlineStyles, html, nonce);
203
292
  if (scripts.length) html = injectScripts(html, scripts, options.nonce);
204
293
  return html;
205
294
  }
@@ -214,10 +303,12 @@ function renderToStream(code, options = {}) {
214
303
  } = options;
215
304
  let dispose;
216
305
  const blockingPromises = new Set();
306
+ let headerEmitted = false;
217
307
  const pushTask = task => {
218
308
  if (noScripts) return;
219
- if (!tasks && !firstFlushed) {
220
- tasks = getLocalHeaderScript(renderId);
309
+ if (!headerEmitted) {
310
+ headerEmitted = true;
311
+ tasks += getLocalHeaderScript(renderId);
221
312
  }
222
313
  tasks += task + ";";
223
314
  if (!timer && firstFlushed) {
@@ -236,15 +327,22 @@ function renderToStream(code, options = {}) {
236
327
  completed = true;
237
328
  if (firstFlushed) dispose();
238
329
  };
239
- const serializer = createSerializer({
330
+ const serializer = createHydrationSerializer({
240
331
  scopeId: options.renderId,
241
332
  plugins: options.plugins,
242
333
  onData: pushTask,
243
334
  onDone,
244
335
  onError: options.onError
245
336
  });
337
+ let rootAssetsSerialized = false;
338
+ const serializeRootAssets = () => {
339
+ if (rootAssetsSerialized) return;
340
+ rootAssetsSerialized = true;
341
+ serializeFragmentAssets("", tracking.boundaryModules, context);
342
+ };
246
343
  const flushEnd = () => {
247
344
  if (!registry.size) {
345
+ serializeRootAssets();
248
346
  queue(() => queue(() => serializer.flush()));
249
347
  }
250
348
  };
@@ -266,7 +364,29 @@ function renderToStream(code, options = {}) {
266
364
  let shellCompleted = false;
267
365
  let scriptFlushed = false;
268
366
  let headStyles;
367
+ const revealGroups = new Map();
269
368
  let timer = null;
369
+ const emitTask = task => {
370
+ pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
371
+ scriptFlushed = true;
372
+ };
373
+ function resolveRevealKeys(groupOrKeys, release, consume) {
374
+ if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
375
+ let group = revealGroups.get(groupOrKeys);
376
+ if (!group) {
377
+ if (!release) return;
378
+ group = {
379
+ order: [],
380
+ keys: new Set(),
381
+ released: true
382
+ };
383
+ revealGroups.set(groupOrKeys, group);
384
+ } else if (release) group.released = true;
385
+ if (!group.order.length) return;
386
+ const keys = group.order.slice();
387
+ if (consume) revealGroups.delete(groupOrKeys);
388
+ return keys;
389
+ }
270
390
  let rootHoles = null;
271
391
  let nextHoleId = 0;
272
392
  let buffer = {
@@ -279,19 +399,27 @@ function renderToStream(code, options = {}) {
279
399
  async: true,
280
400
  assets: [],
281
401
  nonce,
282
- registerAsset(type, url) {
402
+ registerAsset(type, value) {
403
+ if (type === "inline-style") {
404
+ const entry = tracking.registerInlineStyle(value);
405
+ if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
406
+ entry.emitted = true;
407
+ buffer.write(renderInlineStyle(entry, nonce));
408
+ }
409
+ return;
410
+ }
283
411
  if (tracking.currentBoundaryId && type === "style") {
284
412
  let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
285
413
  if (!styles) {
286
414
  styles = new Set();
287
415
  tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
288
416
  }
289
- styles.add(url);
417
+ styles.add(value);
290
418
  }
291
- if (!tracking.emittedAssets.has(url)) {
292
- tracking.emittedAssets.add(url);
419
+ if (!tracking.emittedAssets.has(value)) {
420
+ tracking.emittedAssets.add(value);
293
421
  if (firstFlushed && type === "module") {
294
- buffer.write(`<link rel="modulepreload" href="${url}">`);
422
+ buffer.write(`<link rel="modulepreload" href="${value}">`);
295
423
  }
296
424
  }
297
425
  },
@@ -316,7 +444,26 @@ function renderToStream(code, options = {}) {
316
444
  escape: escape,
317
445
  resolve: resolveSSRNode,
318
446
  ssr: ssr,
319
- registerFragment(key) {
447
+ registerFragment(key, options) {
448
+ const revealGroup = options && options.revealGroup;
449
+ if (revealGroup) {
450
+ let group = revealGroups.get(revealGroup);
451
+ if (!group) {
452
+ group = {
453
+ order: [],
454
+ keys: new Set(),
455
+ released: false
456
+ };
457
+ revealGroups.set(revealGroup, group);
458
+ }
459
+ if (!group.keys.has(key)) {
460
+ group.keys.add(key);
461
+ group.order.push(key);
462
+ }
463
+ if (group.released) {
464
+ throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
465
+ }
466
+ }
320
467
  if (!registry.has(key)) {
321
468
  let resolve, reject;
322
469
  const p = new Promise((r, rej) => (resolve = r, reject = rej));
@@ -326,7 +473,7 @@ function renderToStream(code, options = {}) {
326
473
  queue(flushEnd);
327
474
  }))
328
475
  });
329
- serializer.write(key, p);
476
+ serializer.write(key + "_fr", p);
330
477
  }
331
478
  return (value, error) => {
332
479
  if (registry.has(key)) {
@@ -355,18 +502,22 @@ function renderToStream(code, options = {}) {
355
502
  } else {
356
503
  serializeFragmentAssets(key, tracking.boundaryModules, context);
357
504
  const styles = collectStreamStyles(key, tracking, headStyles);
358
- if (styles.length) {
359
- pushTask(`$dfs("${key}",${styles.length})${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
360
- scriptFlushed = true;
505
+ const deferActivation = !!revealGroup;
506
+ for (let i = 0; i < styles.inline.length; i++) {
507
+ buffer.write(renderInlineStyle(styles.inline[i], nonce));
508
+ }
509
+ if (styles.links.length) {
510
+ emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
361
511
  writeTasks();
362
- for (const url of styles) {
512
+ for (const url of styles.links) {
363
513
  buffer.write(`<link rel="stylesheet" href="${url}" onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
364
514
  }
365
515
  buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
366
516
  } else {
367
517
  buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
368
- pushTask(`$df("${key}")${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
369
- scriptFlushed = true;
518
+ if (!deferActivation) {
519
+ emitTask(`$df("${key}")`);
520
+ }
370
521
  }
371
522
  item.resolve(error);
372
523
  }
@@ -374,6 +525,16 @@ function renderToStream(code, options = {}) {
374
525
  }
375
526
  return firstFlushed;
376
527
  };
528
+ },
529
+ revealFragments(groupOrKeys) {
530
+ const keys = resolveRevealKeys(groupOrKeys, true, true);
531
+ if (!keys) return;
532
+ emitTask(`$dfj(${JSON.stringify(keys)})`);
533
+ },
534
+ revealFallbacks(groupOrKeys) {
535
+ const keys = resolveRevealKeys(groupOrKeys, false, false);
536
+ if (!keys) return;
537
+ emitTask(`$dflj(${JSON.stringify(keys)})`);
377
538
  }
378
539
  };
379
540
  applyAssetTracking(context, tracking, manifest);
@@ -397,19 +558,41 @@ function renderToStream(code, options = {}) {
397
558
  }, {
398
559
  id: renderId
399
560
  });
400
- function doShell() {
401
- if (shellCompleted) return;
402
- if (rootHoles) {
403
- for (const {
404
- id,
405
- fn
406
- } of rootHoles) {
407
- const marker = `<!--rh${id}-->`;
408
- const res = resolveSSRNode(fn);
409
- html = html.replace(marker, !res.h.length ? res.t[0] : "");
561
+ function resolveRootHoles() {
562
+ if (!rootHoles) return true;
563
+ const pending = [];
564
+ for (const {
565
+ id,
566
+ fn
567
+ } of rootHoles) {
568
+ const marker = `<!--rh${id}-->`;
569
+ const res = resolveSSRNode(fn);
570
+ if (!res.h.length) {
571
+ html = html.replace(marker, res.t[0]);
572
+ } else {
573
+ let out = res.t[0];
574
+ for (let j = 0; j < res.h.length; j++) {
575
+ const newId = nextHoleId++;
576
+ pending.push({
577
+ id: newId,
578
+ fn: res.h[j]
579
+ });
580
+ out += `<!--rh${newId}-->` + res.t[j + 1];
581
+ }
582
+ html = html.replace(marker, out);
583
+ for (const p of res.p) blockingPromises.add(p);
410
584
  }
411
- rootHoles = null;
412
585
  }
586
+ if (pending.length) {
587
+ rootHoles = pending;
588
+ return false;
589
+ }
590
+ rootHoles = null;
591
+ return true;
592
+ }
593
+ function doShell() {
594
+ if (shellCompleted) return;
595
+ if (!resolveRootHoles()) return;
413
596
  sharedConfig.context = context;
414
597
  html = injectAssets(context.assets, html);
415
598
  headStyles = new Set();
@@ -417,6 +600,8 @@ function renderToStream(code, options = {}) {
417
600
  if (url.endsWith(".css")) headStyles.add(url);
418
601
  }
419
602
  html = injectPreloadLinks(tracking.emittedAssets, html);
603
+ html = injectInlineStyles(tracking.inlineStyles, html, nonce);
604
+ serializeRootAssets();
420
605
  if (tasks.length) html = injectScripts(html, tasks, nonce);
421
606
  buffer.write(html);
422
607
  tasks = "";
@@ -440,51 +625,67 @@ function renderToStream(code, options = {}) {
440
625
  complete();
441
626
  };
442
627
  } else onCompleteAll = complete;
443
- queue(flushEnd);
628
+ function flush() {
629
+ allSettled(blockingPromises).then(() => {
630
+ setTimeout(() => {
631
+ if (!resolveRootHoles()) return flush();
632
+ queue(flushEnd);
633
+ });
634
+ });
635
+ }
636
+ flush();
444
637
  },
445
638
  pipe(w) {
446
- allSettled(blockingPromises).then(() => {
447
- setTimeout(() => {
448
- doShell();
449
- buffer = writable = w;
450
- buffer.write(tmp);
451
- firstFlushed = true;
452
- if (completed) {
453
- dispose();
454
- writable.end();
455
- } else flushEnd();
639
+ function flush() {
640
+ allSettled(blockingPromises).then(() => {
641
+ setTimeout(() => {
642
+ doShell();
643
+ if (!shellCompleted) return flush();
644
+ buffer = writable = w;
645
+ buffer.write(tmp);
646
+ firstFlushed = true;
647
+ if (completed) {
648
+ dispose();
649
+ writable.end();
650
+ } else flushEnd();
651
+ });
456
652
  });
457
- });
653
+ }
654
+ flush();
458
655
  },
459
656
  pipeTo(w) {
460
- return allSettled(blockingPromises).then(() => {
461
- let resolve;
462
- const p = new Promise(r => resolve = r);
463
- setTimeout(() => {
464
- doShell();
465
- const encoder = new TextEncoder();
466
- const writer = w.getWriter();
467
- writable = {
468
- end() {
469
- writer.releaseLock();
470
- w.close().catch(() => {});
471
- resolve();
472
- }
473
- };
474
- buffer = {
475
- write(payload) {
476
- writer.write(encoder.encode(payload)).catch(() => {});
477
- }
478
- };
479
- buffer.write(tmp);
480
- firstFlushed = true;
481
- if (completed) {
482
- dispose();
483
- writable.end();
484
- } else flushEnd();
657
+ let resolve;
658
+ const p = new Promise(r => resolve = r);
659
+ function flush() {
660
+ allSettled(blockingPromises).then(() => {
661
+ setTimeout(() => {
662
+ doShell();
663
+ if (!shellCompleted) return flush();
664
+ const encoder = new TextEncoder();
665
+ const writer = w.getWriter();
666
+ writable = {
667
+ end() {
668
+ writer.releaseLock();
669
+ w.close().catch(() => {});
670
+ resolve();
671
+ }
672
+ };
673
+ buffer = {
674
+ write(payload) {
675
+ writer.write(encoder.encode(payload)).catch(() => {});
676
+ }
677
+ };
678
+ buffer.write(tmp);
679
+ firstFlushed = true;
680
+ if (completed) {
681
+ dispose();
682
+ writable.end();
683
+ } else flushEnd();
684
+ });
485
685
  });
486
- return p;
487
- });
686
+ }
687
+ flush();
688
+ return p;
488
689
  }
489
690
  };
490
691
  }
@@ -497,11 +698,176 @@ function HydrationScript(props) {
497
698
  ...props
498
699
  }));
499
700
  }
500
- function ssr(t, ...nodes) {
501
- if (nodes.length) return resolveSSR(t, nodes);
701
+ function ssrGroup(fn, n) {
702
+ fn.$g = n;
703
+ return fn;
704
+ }
705
+ function buildAsyncWrap(err, node) {
706
+ const p = ssrHandleError(err);
707
+ if (!p) return null;
708
+ const owner = getOwner();
502
709
  return {
710
+ fn: owner ? () => runWithOwner(owner, node) : node,
711
+ p
712
+ };
713
+ }
714
+ function ssrFirstGroupHit(hole) {
715
+ try {
716
+ return hole();
717
+ } catch (err) {
718
+ return buildAsyncWrap(err, hole);
719
+ }
720
+ }
721
+ function tryResolveFunctionHole(hole) {
722
+ let value;
723
+ try {
724
+ value = hole();
725
+ } catch (err) {
726
+ return buildAsyncWrap(err, hole) || "";
727
+ }
728
+ const t = typeof value;
729
+ if (t === "string") return value;
730
+ if (t === "number") return "" + value;
731
+ if (value == null || t === "boolean") return "";
732
+ return tryResolveString(value);
733
+ }
734
+ function mergeTemplateInto(result, node) {
735
+ result.t[result.t.length - 1] += node.t[0];
736
+ if (node.t.length > 1) {
737
+ result.t.push(...node.t.slice(1));
738
+ result.h.push(...node.h);
739
+ result.p.push(...node.p);
740
+ }
741
+ }
742
+ function appendResolvedNode(result, node) {
743
+ if (node.fn !== undefined) {
744
+ result.h.push(node.fn);
745
+ result.p.push(node.p);
746
+ result.t.push("");
747
+ } else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
748
+ }
749
+ let _lastGroupFn = null;
750
+ let _lastGroupArr = null;
751
+ let _lastGroupErr = null;
752
+ function ssrGroupSlot(fn, idx) {
753
+ return () => {
754
+ if (idx > 0 && _lastGroupFn === fn) {
755
+ if (_lastGroupArr !== null) return _lastGroupArr[idx];
756
+ throw _lastGroupErr;
757
+ }
758
+ _lastGroupFn = fn;
759
+ _lastGroupArr = null;
760
+ _lastGroupErr = null;
761
+ try {
762
+ _lastGroupArr = fn();
763
+ return _lastGroupArr[idx];
764
+ } catch (err) {
765
+ _lastGroupErr = err;
766
+ throw err;
767
+ }
768
+ };
769
+ }
770
+ function ssr(t) {
771
+ const len = arguments.length;
772
+ if (len === 1) return {
503
773
  t
504
774
  };
775
+ let s = t[0];
776
+ let result = null;
777
+ let lastGroup = null;
778
+ let lastGroupVal = null;
779
+ let lastGroupIdx = 0;
780
+ for (let i = 1; i < len; i++) {
781
+ const hole = arguments[i];
782
+ const ht = typeof hole;
783
+ if (ht === "string") {
784
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
785
+ } else if (ht === "number") {
786
+ if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
787
+ } else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
788
+ let value;
789
+ let hasValue = false;
790
+ if (lastGroup !== hole) {
791
+ const r = ssrFirstGroupHit(hole);
792
+ if (r !== null) {
793
+ lastGroup = hole;
794
+ lastGroupVal = r;
795
+ lastGroupIdx = 0;
796
+ if (!Array.isArray(r) && result === null) {
797
+ result = {
798
+ t: [s],
799
+ h: [],
800
+ p: []
801
+ };
802
+ s = "";
803
+ }
804
+ }
805
+ }
806
+ if (lastGroup === hole) {
807
+ if (Array.isArray(lastGroupVal)) {
808
+ value = lastGroupVal[lastGroupIdx++];
809
+ hasValue = true;
810
+ } else {
811
+ result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
812
+ result.p.push(lastGroupVal.p);
813
+ result.t.push("");
814
+ }
815
+ }
816
+ if (hasValue) {
817
+ const vt = typeof value;
818
+ if (vt === "string" || vt === "number") {
819
+ if (result === null) s += value;else result.t[result.t.length - 1] += value;
820
+ } else if (value == null || vt === "boolean") ; else if (result !== null) {
821
+ resolveSSRNode(value, result);
822
+ } else {
823
+ const rs = tryResolveString(value);
824
+ if (typeof rs === "string") {
825
+ s += rs;
826
+ } else {
827
+ result = {
828
+ t: [s],
829
+ h: [],
830
+ p: []
831
+ };
832
+ s = "";
833
+ if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
834
+ }
835
+ }
836
+ }
837
+ } else if (result !== null) {
838
+ resolveSSRNode(hole, result);
839
+ } else if (ht === "function") {
840
+ const r = tryResolveFunctionHole(hole);
841
+ if (typeof r === "string") s += r;else {
842
+ result = {
843
+ t: [s],
844
+ h: [],
845
+ p: []
846
+ };
847
+ s = "";
848
+ appendResolvedNode(result, r);
849
+ }
850
+ } else {
851
+ const r = tryResolveString(hole);
852
+ if (typeof r === "string") {
853
+ s += r;
854
+ } else {
855
+ result = {
856
+ t: [s],
857
+ h: [],
858
+ p: []
859
+ };
860
+ s = "";
861
+ appendResolvedNode(result, r);
862
+ }
863
+ }
864
+ const next = t[i];
865
+ if (result === null) s += next;else result.t[result.t.length - 1] += next;
866
+ }
867
+ if (result === null) return {
868
+ t: s
869
+ };
870
+ return result;
505
871
  }
506
872
  function ssrClassName(value) {
507
873
  if (!value) return "";
@@ -514,7 +880,7 @@ function ssrClassName(value) {
514
880
  classValue = !!value[key];
515
881
  if (!key || key === "undefined" || !classValue) continue;
516
882
  i && (result += " ");
517
- result += escape(key);
883
+ result += escape(key, true);
518
884
  }
519
885
  return result;
520
886
  }
@@ -524,8 +890,8 @@ function ssrStyle(value) {
524
890
  let result = "";
525
891
  const k = Object.keys(value);
526
892
  for (let i = 0; i < k.length; i++) {
527
- const s = k[i];
528
- const v = value[s];
893
+ const s = escape(k[i], true);
894
+ const v = value[k[i]];
529
895
  if (v != undefined) {
530
896
  if (i) result += ";";
531
897
  const r = escape(v, true);
@@ -540,10 +906,11 @@ function ssrStyleProperty(name, value) {
540
906
  return value != null ? name + value : "";
541
907
  }
542
908
  function ssrElement(tag, props, children, needsId) {
909
+ const hk = needsId ? ssrHydrationKey() : "";
543
910
  if (props == null) props = {};else if (typeof props === "function") props = props();
544
911
  const skipChildren = VOID_ELEMENTS.test(tag);
545
912
  const keys = Object.keys(props);
546
- let result = `<${tag}${needsId ? ssrHydrationKey() : ""} `;
913
+ let result = `<${tag}${hk} `;
547
914
  for (let i = 0; i < keys.length; i++) {
548
915
  const prop = keys[i];
549
916
  if (ChildProperties.has(prop)) {
@@ -582,18 +949,33 @@ function escape(s, attr) {
582
949
  const t = typeof s;
583
950
  if (t !== "string") {
584
951
  if (!attr && Array.isArray(s)) {
952
+ const joined = tryJoinPlainSSRArray(s);
953
+ if (joined !== undefined) return joined;
585
954
  s = s.slice();
586
955
  for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
587
956
  return s;
588
957
  }
589
- if (attr && t === "boolean") return s;
958
+ if (attr) {
959
+ if (s == null || t === "boolean" || t === "number") return s;
960
+ return escape(String(s), attr);
961
+ }
590
962
  return s;
591
963
  }
964
+ const delimCode = attr ? 34 : 60;
965
+ const len = s.length;
966
+ for (let i = 0; i < len; i++) {
967
+ const c = s.charCodeAt(i);
968
+ if (c === 38 || c === delimCode) return escapeSlow(s, attr, i);
969
+ }
970
+ return s;
971
+ }
972
+ function escapeSlow(s, attr, start) {
592
973
  const delim = attr ? '"' : "<";
974
+ const delimCode = attr ? 34 : 60;
593
975
  const escDelim = attr ? "&quot;" : "&lt;";
594
- let iDelim = s.indexOf(delim);
595
- let iAmp = s.indexOf("&");
596
- if (iDelim < 0 && iAmp < 0) return s;
976
+ const c0 = s.charCodeAt(start);
977
+ let iDelim = c0 === delimCode ? start : s.indexOf(delim, start);
978
+ let iAmp = c0 === 38 ? start : s.indexOf("&", start);
597
979
  let left = 0,
598
980
  out = "";
599
981
  while (iDelim >= 0 && iAmp >= 0) {
@@ -624,28 +1006,17 @@ function escape(s, attr) {
624
1006
  }
625
1007
  return left < s.length ? out + s.substring(left) : out;
626
1008
  }
627
- function mergeProps(...sources) {
628
- const target = {};
629
- for (let i = 0; i < sources.length; i++) {
630
- let source = sources[i];
631
- if (typeof source === "function") source = source();
632
- if (source) {
633
- const descriptors = Object.getOwnPropertyDescriptors(source);
634
- for (const key in descriptors) {
635
- if (key in target) continue;
636
- Object.defineProperty(target, key, {
637
- enumerable: true,
638
- get() {
639
- for (let i = sources.length - 1; i >= 0; i--) {
640
- const v = (sources[i] || {})[key];
641
- if (v !== undefined) return v;
642
- }
643
- }
644
- });
645
- }
1009
+ function tryJoinPlainSSRArray(nodes) {
1010
+ if (nodes.length === 0) return undefined;
1011
+ let out = "";
1012
+ for (let i = 0, len = nodes.length; i < len; i++) {
1013
+ const node = nodes[i];
1014
+ if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
1015
+ return undefined;
646
1016
  }
1017
+ out += node.t;
647
1018
  }
648
- return target;
1019
+ return out;
649
1020
  }
650
1021
  function getHydrationKey() {
651
1022
  const hydrate = sharedConfig.context;
@@ -663,11 +1034,14 @@ function getAssets() {
663
1034
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
664
1035
  return out;
665
1036
  }
1037
+ function Assets(props) {
1038
+ useAssets(() => props.children);
1039
+ }
666
1040
  function generateHydrationScript({
667
1041
  eventNames = ["click", "input"],
668
1042
  nonce
669
1043
  } = {}) {
670
- return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('", "')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`;
1044
+ return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`;
671
1045
  }
672
1046
  function queue(fn) {
673
1047
  return Promise.resolve().then(fn);
@@ -720,14 +1094,48 @@ function propagateBoundaryStyles(childKey, parentKey, tracking) {
720
1094
  }
721
1095
  function collectStreamStyles(key, tracking, headStyles) {
722
1096
  const styles = tracking.getBoundaryStyles(key);
723
- if (!styles) return [];
724
- const result = [];
725
- for (const url of styles) {
726
- if (!headStyles || !headStyles.has(url)) {
727
- result.push(url);
1097
+ const links = [];
1098
+ const inline = [];
1099
+ if (!styles) return {
1100
+ links,
1101
+ inline
1102
+ };
1103
+ for (const entry of styles) {
1104
+ if (typeof entry === "string") {
1105
+ if (!headStyles || !headStyles.has(entry)) links.push(entry);
1106
+ } else if (!entry.emitted) {
1107
+ entry.emitted = true;
1108
+ inline.push(entry);
728
1109
  }
729
1110
  }
730
- return result;
1111
+ return {
1112
+ links,
1113
+ inline
1114
+ };
1115
+ }
1116
+ function escapeStyleContent(content) {
1117
+ return content.replace(/<\/(style)/gi, "<\\/$1");
1118
+ }
1119
+ function renderInlineStyle(entry, nonce) {
1120
+ let attrs = "";
1121
+ if (entry.attrs) {
1122
+ for (const name in entry.attrs) {
1123
+ attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
1124
+ }
1125
+ }
1126
+ return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
1127
+ }
1128
+ function injectInlineStyles(inlineStyles, html, nonce) {
1129
+ if (!inlineStyles.size) return html;
1130
+ const index = html.indexOf("</head>");
1131
+ if (index === -1) return html;
1132
+ let out = "";
1133
+ for (const entry of inlineStyles.values()) {
1134
+ if (entry.emitted) continue;
1135
+ entry.emitted = true;
1136
+ out += renderInlineStyle(entry, nonce);
1137
+ }
1138
+ return out ? html.slice(0, index) + out + html.slice(index) : html;
731
1139
  }
732
1140
  function injectScripts(html, scripts, nonce) {
733
1141
  const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
@@ -765,19 +1173,49 @@ function flattenClassList(list, result) {
765
1173
  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;
766
1174
  }
767
1175
  }
768
- function resolveSSR(template, holes, result = {
769
- t: [""],
770
- h: [],
771
- p: []
772
- }) {
773
- for (let i = 0; i < holes.length; i++) {
774
- const hole = holes[i];
775
- result.t[result.t.length - 1] += template[i];
776
- if (hole == null || hole === true || hole === false) continue;
777
- resolveSSRNode(hole, result);
1176
+ function tryResolveString(node) {
1177
+ const t = typeof node;
1178
+ if (t === "string") return node;
1179
+ if (t === "number") return "" + node;
1180
+ if (node == null || t === "boolean") return "";
1181
+ if (t === "object") {
1182
+ if (Array.isArray(node)) {
1183
+ const joined = tryJoinPlainSSRArray(node);
1184
+ if (joined !== undefined) return joined;
1185
+ let s = "";
1186
+ let prevNonObj = false;
1187
+ for (let i = 0, len = node.length; i < len; i++) {
1188
+ const item = node[i];
1189
+ const itemNonObj = item !== null && typeof item !== "object";
1190
+ if (prevNonObj && itemNonObj) s += "<!--!$-->";
1191
+ prevNonObj = itemNonObj;
1192
+ const r = tryResolveString(item);
1193
+ if (typeof r !== "string") return {
1194
+ bail: node
1195
+ };
1196
+ s += r;
1197
+ }
1198
+ return s;
1199
+ }
1200
+ if (node.h && node.h.length > 0) return {
1201
+ merge: node
1202
+ };
1203
+ if (node.t === undefined) {
1204
+ console.warn(`Unrecognized value. Skipped inserting`, node);
1205
+ return "";
1206
+ }
1207
+ return Array.isArray(node.t) ? node.t[0] : node.t;
778
1208
  }
779
- result.t[result.t.length - 1] += template[template.length - 1];
780
- return result;
1209
+ if (t === "function") {
1210
+ let v;
1211
+ try {
1212
+ v = node();
1213
+ } catch (err) {
1214
+ return buildAsyncWrap(err, node) || "";
1215
+ }
1216
+ return tryResolveString(v);
1217
+ }
1218
+ return "";
781
1219
  }
782
1220
  function resolveSSRNode(node, result = {
783
1221
  t: [""],
@@ -788,10 +1226,13 @@ function resolveSSRNode(node, result = {
788
1226
  if (t === "string" || t === "number") {
789
1227
  result.t[result.t.length - 1] += node;
790
1228
  } else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
791
- let prev = {};
1229
+ let prevNonObj = false;
792
1230
  for (let i = 0, len = node.length; i < len; i++) {
793
- if (!top && typeof prev !== "object" && typeof node[i] !== "object") result.t[result.t.length - 1] += `<!--!$-->`;
794
- resolveSSRNode(prev = node[i], result);
1231
+ const item = node[i];
1232
+ const itemNonObj = item !== null && typeof item !== "object";
1233
+ if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
1234
+ prevNonObj = itemNonObj;
1235
+ resolveSSRNode(item, result);
795
1236
  }
796
1237
  } else if (t === "object") {
797
1238
  if (node.h) {
@@ -801,15 +1242,17 @@ function resolveSSRNode(node, result = {
801
1242
  result.h.push(...node.h);
802
1243
  result.p.push(...node.p);
803
1244
  }
804
- } else result.t[result.t.length - 1] += node.t;
1245
+ } else if (node.t !== undefined) {
1246
+ result.t[result.t.length - 1] += node.t;
1247
+ } else console.warn(`Unrecognized value. Skipped inserting`, node);
805
1248
  } else if (t === "function") {
806
1249
  try {
807
1250
  resolveSSRNode(node(), result);
808
1251
  } catch (err) {
809
- const p = ssrHandleError(err);
810
- if (p) {
811
- result.h.push(node);
812
- result.p.push(p);
1252
+ const wrap = buildAsyncWrap(err, node);
1253
+ if (wrap) {
1254
+ result.h.push(wrap.fn);
1255
+ result.p.push(wrap.p);
813
1256
  result.t.push("");
814
1257
  }
815
1258
  }
@@ -821,7 +1264,7 @@ function resolveSSRSync(node) {
821
1264
  if (!res.h.length) return res.t[0];
822
1265
  throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
823
1266
  }
824
- const RequestContext = Symbol();
1267
+ const RequestContext = Symbol.for("solid.RequestContext");
825
1268
  function getRequestEvent() {
826
1269
  return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
827
1270
  }
@@ -832,28 +1275,116 @@ function notSup() {
832
1275
  throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
833
1276
  }
834
1277
 
1278
+ const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
1279
+ class ResponseEnvelope {
1280
+ constructor(response, value) {
1281
+ this.response = response;
1282
+ this.value = value;
1283
+ }
1284
+ }
1285
+ ResponseEnvelope.prototype[ENVELOPE] = true;
1286
+ function isResponseEnvelope(value) {
1287
+ return !!(value && typeof value === "object" && value[ENVELOPE]);
1288
+ }
1289
+ function initWithRevalidate(init) {
1290
+ const {
1291
+ revalidate,
1292
+ ...responseInit
1293
+ } = init;
1294
+ const headers = new Headers(responseInit.headers);
1295
+ revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
1296
+ return {
1297
+ responseInit,
1298
+ headers
1299
+ };
1300
+ }
1301
+ function redirect(url, init = 302) {
1302
+ const {
1303
+ responseInit,
1304
+ headers
1305
+ } = initWithRevalidate(typeof init === "number" ? {
1306
+ status: init
1307
+ } : init);
1308
+ if (responseInit.status === undefined) {
1309
+ responseInit.status = 302;
1310
+ }
1311
+ headers.set("Location", url);
1312
+ return new Response(null, {
1313
+ ...responseInit,
1314
+ headers
1315
+ });
1316
+ }
1317
+ function reload(init = {}) {
1318
+ const {
1319
+ responseInit,
1320
+ headers
1321
+ } = initWithRevalidate(init);
1322
+ return new Response(null, {
1323
+ ...responseInit,
1324
+ headers
1325
+ });
1326
+ }
1327
+ function respond(value, init = {}) {
1328
+ const {
1329
+ responseInit,
1330
+ headers
1331
+ } = initWithRevalidate(init);
1332
+ headers.set("Content-Type", "application/json");
1333
+ return new ResponseEnvelope(new Response(JSON.stringify(value), {
1334
+ ...responseInit,
1335
+ headers
1336
+ }), value);
1337
+ }
1338
+
835
1339
  const isServer = true;
836
1340
  const isDev = false;
837
- function createDynamic(component, props) {
1341
+ function dynamic(source) {
838
1342
  const o = getOwner();
839
1343
  if (o?.id != null) getNextChildId(o);
840
- const memoOwner = createOwner();
841
- return runWithOwner(memoOwner, () => {
842
- const comp = component(),
843
- t = typeof comp;
844
- if (comp) {
845
- if (t === "function") return comp(props);else if (t === "string") {
846
- return ssrElement(comp, props, undefined, true);
847
- }
1344
+ return props => {
1345
+ const comp = source();
1346
+ let p;
1347
+ let settled = false;
1348
+ let value;
1349
+ let error;
1350
+ if (comp && typeof comp.then === "function") {
1351
+ p = comp;
1352
+ p.then(v => {
1353
+ value = v;
1354
+ settled = true;
1355
+ }, err => {
1356
+ error = err;
1357
+ settled = true;
1358
+ });
1359
+ const ctx = sharedConfig.context;
1360
+ if (ctx?.async) ctx.block(p.then(() => {}, () => {}));
848
1361
  }
849
- });
1362
+ return createMemo(() => {
1363
+ let c = comp;
1364
+ if (p) {
1365
+ if (!settled) throw new NotReadyError(p);
1366
+ if (error) throw error;
1367
+ c = value;
1368
+ }
1369
+ if (c) {
1370
+ if (typeof c === "function") return c(props);
1371
+ if (typeof c === "string") {
1372
+ return ssrElement(c, props, undefined, true);
1373
+ }
1374
+ }
1375
+ }, {
1376
+ sync: true
1377
+ });
1378
+ };
850
1379
  }
851
1380
  function Dynamic(props) {
852
- const others = omit(props, "component");
853
- return createDynamic(() => props.component, others);
1381
+ const Comp = dynamic(() => props.component);
1382
+ return createComponent(Comp, omit(props, "component"));
854
1383
  }
855
1384
  function Portal(props) {
856
- throw new Error("Portal is not supported on the server");
1385
+ const o = getOwner();
1386
+ if (o?.id != null) getNextChildId(o);
1387
+ return undefined;
857
1388
  }
858
1389
 
859
- export { ChildProperties, DOMElements, DelegatedEvents, Dynamic, HydrationScript, Portal, Properties, RequestContext, SVGElements, SVGNamespace, notSup as addEventListener, applyRef, notSup as assign, notSup as className, createDynamic, notSup as delegateEvents, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, mergeProps, notSup as render, renderToStream, renderToString, renderToStringAsync, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, useAssets };
1390
+ export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, ResponseEnvelope, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, notSup as className, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isResponseEnvelope, isServer, memo, redirect, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, reload, notSup as render, renderToStream, renderToString, renderToStringAsync, respond, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets };