@solidjs/web 2.0.0-rc.13 → 2.0.0-rc.14

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 (57) hide show
  1. package/dist/server.dev.js +200 -73
  2. package/dist/server.js +182 -59
  3. package/dist/server.observe.js +183 -60
  4. package/dist/web.dev.js +70 -35
  5. package/dist/web.js +43 -31
  6. package/dist/web.observe.js +43 -33
  7. package/frames/dist/assets.js +92 -0
  8. package/frames/dist/bind.dev.js +326 -0
  9. package/frames/dist/bind.js +295 -0
  10. package/frames/dist/client.dev.js +605 -1086
  11. package/frames/dist/client.js +572 -1066
  12. package/frames/dist/client.observe.js +571 -1066
  13. package/frames/dist/regions.js +130 -0
  14. package/frames/dist/server.dev.js +339 -177
  15. package/frames/dist/server.js +335 -173
  16. package/frames/dist/server.observe.js +335 -173
  17. package/frames/dist/trace.js +42 -0
  18. package/frames/dist/wire.js +133 -0
  19. package/package.json +28 -2
  20. package/performance-tracks/dist/performance-tracks.dev.js +2 -1
  21. package/performance-tracks/dist/performance-tracks.observe.js +2 -1
  22. package/performance-tracks/types/index.d.ts +8 -6
  23. package/serialization/dist/decode.js +37 -8
  24. package/serialization/dist/serialization.js +39 -10
  25. package/serialization/types/serializer-decode.d.ts +24 -2
  26. package/server-functions/dist/client.dev.js +99 -61
  27. package/server-functions/dist/client.js +99 -61
  28. package/server-functions/dist/client.observe.js +99 -61
  29. package/server-functions/dist/server.dev.js +87 -50
  30. package/server-functions/dist/server.js +87 -50
  31. package/server-functions/dist/server.observe.js +87 -50
  32. package/skills/server-components/SKILL.md +65 -43
  33. package/types/client.d.ts +20 -0
  34. package/types/constants.d.ts +2 -1
  35. package/types/diagnostics.d.ts +8 -0
  36. package/types/frames/assets-tier.d.ts +78 -0
  37. package/types/frames/bind-tier.d.ts +60 -0
  38. package/types/frames/client.d.ts +37 -3
  39. package/types/frames/frame-client.d.ts +249 -78
  40. package/types/frames/frame-container-plugin.d.ts +2 -2
  41. package/types/frames/frame-sink.d.ts +33 -0
  42. package/types/frames/frame-transport.d.ts +66 -18
  43. package/types/frames/regions-tier.d.ts +45 -0
  44. package/types/frames/serializer-decode.d.ts +24 -2
  45. package/types/frames/server.d.ts +32 -8
  46. package/types/frames/trace-tier.d.ts +2 -0
  47. package/types/frames/wire-tier.d.ts +116 -0
  48. package/types/index.d.ts +38 -0
  49. package/types/index.server.d.ts +9 -0
  50. package/types/jsx.d.ts +1 -1
  51. package/types/observe.d.ts +4 -2
  52. package/types/serializer-decode.d.ts +24 -2
  53. package/types/server-functions/client.d.ts +26 -0
  54. package/types/server-functions/registry.d.ts +4 -1
  55. package/types/server-functions/shared.d.ts +12 -8
  56. package/types/server-mock.d.ts +13 -1
  57. package/types/server.d.ts +34 -8
@@ -1,6 +1,6 @@
1
- import { createRenderEffect, createMemo, enableHydration, $PROXY, untrack, runWithOwner, createRoot, getOwner, ROOT_ERROR_HOOK, flatten, flush, OBSERVE, createComponent, omit, createOwner, createSignal, onCleanup, createEffect } from 'solid-js';
1
+ import { createRenderEffect, createMemo, OBSERVE, enableHydration, $PROXY, untrack, runWithOwner, createRoot, getOwner, ROOT_ERROR_HOOK, flatten, flush, createComponent, omit, createOwner, createSignal, createEffect, onCleanup } from 'solid-js';
2
2
  export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
- import { sharedConfig, sourceKeys, SOURCE_PROXY, hasStaticKeys, resolvedTable, viewOf, OmitView, sourceHas, SOURCE_OMIT, sourceGet, SOURCE_MEMO, SOURCE_PLAIN } from 'solid-js/internal';
3
+ import { sharedConfig, sourceKeys, SOURCE_PROXY, resolvedTable, viewOf, OmitView, hasStaticKeys, SOURCE_MEMO, sourceHas, SOURCE_OMIT, sourceGet, SOURCE_PLAIN } from 'solid-js/internal';
4
4
 
5
5
  const DOMWithState = {
6
6
  INPUT: {
@@ -325,7 +325,7 @@ function serializeCookie(name, value, options = {}) {
325
325
  return cookie;
326
326
  }
327
327
  const FLASH_COOKIE = "flash";
328
- const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
328
+ const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
329
329
  function hasFlashCookie(cookieHeader) {
330
330
  return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
331
331
  }
@@ -509,8 +509,9 @@ function dispatchAsInteraction(e, fn) {
509
509
  return OBSERVE.attribution.withInteraction({
510
510
  type: e.type,
511
511
  target: describeEventTarget(e.target),
512
- at: interactionStart(e)
513
- }, fn);
512
+ at: interactionStart(e),
513
+ event: e
514
+ }, fn) ;
514
515
  }
515
516
  function getDelegatedRoot(node) {
516
517
  while (node) {
@@ -724,26 +725,15 @@ function spread(node, props, skipChildren, skip, name) {
724
725
  assign(node, newProps, true, prevProps, true);
725
726
  };
726
727
  if (Array.isArray(props)) {
728
+ effect(() => collectSources({}, props, undefined, skip), apply);
727
729
  if (!skipChildren && !(skip !== undefined && skip("children"))) insert(node, () => {
728
730
  for (let i = props.length - 1; i >= 0; i--) {
729
731
  const s = resolveSource(props[i]);
730
732
  if (s != null && entryHas(s, "children")) return entryGet(s, "children");
731
733
  }
732
734
  });
733
- effect(() => collectSources({}, props, undefined, skip), apply);
734
735
  return prevProps;
735
736
  }
736
- if (!skipChildren && !(skip !== undefined && skip("children"))) {
737
- if (typeof props !== "function" && props != null && hasStaticKeys(props)) {
738
- const desc = Object.getOwnPropertyDescriptor(props, "children");
739
- if (desc !== undefined) {
740
- if (desc.get === undefined) insert(node, desc.value);else insert(node, () => props.children);
741
- }
742
- } else insert(node, () => {
743
- const source = resolveSource(props);
744
- return source != null && entryHas(source, "children") ? entryGet(source, "children") : undefined;
745
- });
746
- }
747
737
  effect(() => {
748
738
  const source = resolveSource(props);
749
739
  const newProps = {};
@@ -755,6 +745,17 @@ function spread(node, props, skipChildren, skip, name) {
755
745
  }
756
746
  return newProps;
757
747
  }, apply);
748
+ if (!skipChildren && !(skip !== undefined && skip("children"))) {
749
+ if (typeof props !== "function" && props != null && hasStaticKeys(props)) {
750
+ const desc = Object.getOwnPropertyDescriptor(props, "children");
751
+ if (desc !== undefined) {
752
+ if (desc.get === undefined) insert(node, desc.value);else insert(node, () => props.children);
753
+ }
754
+ } else insert(node, () => {
755
+ const source = resolveSource(props);
756
+ return source != null && entryHas(source, "children") ? entryGet(source, "children") : undefined;
757
+ });
758
+ }
758
759
  return prevProps;
759
760
  }
760
761
  function collectTable(out, table, skip) {
@@ -939,13 +940,14 @@ function insert(parent, accessor, marker, initial, options) {
939
940
  if (hydrationRt !== null) current = hydrationRt.reclaimRegion(current, parent, marker);
940
941
  const value = normalize(accessor(), current, multi, true);
941
942
  if (typeof value !== "function") return value;
943
+ const innerOptions = prev !== undefined && !(options && options.schedule) ? {
944
+ ...options,
945
+ schedule: true
946
+ } : options;
942
947
  effect(() => (hydrationRt !== null && (current = hydrationRt.reclaimRegion(current, parent, marker)), normalize(value, current, multi)), inner => {
943
948
  current = insertExpression(parent, inner, current, marker);
944
949
  host && tagHost(current, host);
945
- }, prev !== undefined && !(options && options.schedule) ? {
946
- ...options,
947
- schedule: true
948
- } : options);
950
+ }, innerOptions);
949
951
  return INNER_OWNED;
950
952
  }, value => {
951
953
  if (value === INNER_OWNED) return;
@@ -1254,7 +1256,7 @@ function flushHeadRegistry() {
1254
1256
  function createHeadElement(tag, props) {
1255
1257
  const el = document.createElement(tag);
1256
1258
  for (const name in props) {
1257
- if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1259
+ if (name === "children" || name === "ref" || /^on[A-Z]/.test(name)) continue;
1258
1260
  if (!HEAD_ATTR_NAME.test(name)) {
1259
1261
  continue;
1260
1262
  }
@@ -1277,7 +1279,7 @@ function renderHeadElement(t, identity, existing) {
1277
1279
  function headElementMatches(el, t) {
1278
1280
  if (el.tagName.toLowerCase() !== t.tag) return false;
1279
1281
  for (const name in t.props) {
1280
- if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1282
+ if (name === "children" || name === "ref" || /^on[A-Z]/.test(name)) continue;
1281
1283
  if (!HEAD_ATTR_NAME.test(name)) continue;
1282
1284
  const v = t.props[name];
1283
1285
  if (v == null || v === false) {
@@ -1622,8 +1624,9 @@ function assignProp(node, prop, value, prev, skipRef, nodeName) {
1622
1624
  if (!skipRef && value) ref(() => value, node);
1623
1625
  return value;
1624
1626
  }
1627
+ let c;
1625
1628
  const hasNamespace = prop.indexOf(":") > -1;
1626
- if (!hasNamespace && prop.slice(0, 2) === "on") {
1629
+ if (!hasNamespace && prop.startsWith("on") && (c = prop.charCodeAt(2)) > 64 && c < 91) {
1627
1630
  const name = prop.slice(2).toLowerCase();
1628
1631
  const delegate = DelegatedEvents.has(name);
1629
1632
  if (!delegate && prev) {
@@ -1726,6 +1729,7 @@ function insertExpression(parent, value, current, marker) {
1726
1729
  return value;
1727
1730
  }
1728
1731
  if (value === current) return value;
1732
+ if (hydrationRt !== null && sharedConfig.hydrating && current == null && value && [].concat(value).every(n => n?.parentNode === parent) && value.length !== 0) return value;
1729
1733
  const t = typeof value,
1730
1734
  multi = marker !== undefined;
1731
1735
  if (t === "string" || t === "number") {
@@ -1854,16 +1858,14 @@ function cleanChildren(parent, current, marker, replacement) {
1854
1858
  if (replacement && marker) replacement[$$SLOT] = marker;
1855
1859
  }
1856
1860
  function gatherHydratable(element, root) {
1857
- const templates = element.querySelectorAll(`*[_hk]`);
1861
+ const templates = element.querySelectorAll(root ? `[_hk^="${root.replace(/["\\]/g, "\\$&")}"]` : `*[_hk]`);
1858
1862
  const frames = root ? null : element.querySelectorAll("[data-fid]");
1859
1863
  const frameCount = frames ? frames.length : 0;
1860
1864
  const registry = sharedConfig.registry;
1861
1865
  for (let i = 0; i < templates.length; i++) {
1862
1866
  const node = templates[i];
1863
1867
  const key = node.getAttribute("_hk");
1864
- if (root) {
1865
- if (!key.startsWith(root)) continue;
1866
- } else if (frameCount !== 0) {
1868
+ if (frameCount !== 0) {
1867
1869
  let inFrame = false;
1868
1870
  for (let j = 0; j < frameCount; j++) {
1869
1871
  if (frames[j].contains(node)) {
@@ -1882,6 +1884,7 @@ function getHydrationKey() {
1882
1884
  const RequestContext = Symbol();
1883
1885
 
1884
1886
  function configureServerErrors(_config) {}
1887
+ function reportRequestFailure(_error, _event) {}
1885
1888
  function throwInBrowser(func) {
1886
1889
  const err = new Error(`${func.name} is not supported in the browser, returning undefined`);
1887
1890
  console.error(err);
@@ -1916,6 +1919,7 @@ function ssrElementAttribute(key, value) {}
1916
1919
  function ssrClassName(value) {}
1917
1920
  function ssrStyle(value) {}
1918
1921
  function ssrStyleProperty(name, value) {}
1922
+ function ssrStyleProperties(...entries) {}
1919
1923
  function ssrAttribute(key, value) {}
1920
1924
  function ssrGroup(fn, n) {}
1921
1925
  function ssrHydrationKey() {}
@@ -2107,7 +2111,13 @@ function bindingOf(value) {
2107
2111
  return value !== null && (typeof value === "function" || typeof value === "object") && value[COMPONENT_BINDING] || undefined;
2108
2112
  }
2109
2113
  function dynamic(source, options) {
2110
- if (options?.static) return staticDynamic(untrack(source));
2114
+ return dynamicCore(source, options, staticElement);
2115
+ }
2116
+ function dynamicComponent(source, options) {
2117
+ return dynamicCore(source, options);
2118
+ }
2119
+ function dynamicCore(source, options, tagArm) {
2120
+ if (options?.static) return staticDynamic(untrack(source), tagArm);
2111
2121
  const sites = new Set();
2112
2122
  let deliveredAddress;
2113
2123
  const resolveBinding = (next, prev) => {
@@ -2182,12 +2192,12 @@ function dynamic(source, options) {
2182
2192
  return untrack(() => component(props));
2183
2193
  }
2184
2194
  case "string":
2185
- return staticElement(component, props);
2195
+ return tagArm ? tagArm(component, props) : undefined;
2186
2196
  }
2187
2197
  });
2188
2198
  };
2189
2199
  }
2190
- function staticDynamic(component) {
2200
+ function staticDynamic(component, tagArm) {
2191
2201
  if (typeof component === "function") {
2192
2202
  const binding = bindingOf(component);
2193
2203
  if (binding) {
@@ -2196,7 +2206,7 @@ function staticDynamic(component) {
2196
2206
  }
2197
2207
  return props => untrack(() => component(props));
2198
2208
  }
2199
- if (typeof component === "string") return props => staticElement(component, props);
2209
+ if (typeof component === "string" && tagArm) return props => tagArm(component, props);
2200
2210
  return () => undefined;
2201
2211
  }
2202
2212
  function staticElement(tag, props) {
@@ -2245,4 +2255,4 @@ _moduleUrl) {
2245
2255
  function httpStatus(_code, _text) {}
2246
2256
  function httpHeader(_name, _value, _options) {}
2247
2257
 
2248
- export { ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, NULL_BODY_STATUSES, Namespaces, Portal, RESPONSE_HEADER_VALUE_LIMIT, REVALIDATE_ALL, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SAFE_ERROR, SVGElements, VoidElements, acquireAsset, addEvent, applyRef, assign, claimElement, claimElementTree, className, clearFlashCookie, clientOnly, commitEventResponse, composeMiddleware, configureServerErrors, createRequestEvent, createResponseStub, createSSRResponse, delegateEvents, dynamic, dynamicProperty, effect, escape, generateHydrationScript, getDelegatedRoot, getExpectedRedirectStatus, getFirstChild, getHydrationKey, getHydrationWriter, getNextElement, getNextMarker, getNextMatch, getNextSibling, getRequestEvent, getServerFunctionMetadata, getServerFunctionRPC, getTraceContext, hasFlashCookie, httpHeader, httpStatus, hydrate, insert, installHydrationRuntime, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, readShallow, redirect, ref, registerDelegatedContainer, registerDelegatedRoot, registerElementClaim, reload, render, renderToStream, renderToString, resolveSSRNode, respond, runHydrationEvents, scope, serializeCookie, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, style, takeHydrationValue, template, unregisterDelegatedContainer, unregisterDelegatedRoot, useHead, waitAsset, warmAsset };
2258
+ export { ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, NULL_BODY_STATUSES, Namespaces, Portal, RESPONSE_HEADER_VALUE_LIMIT, REVALIDATE_ALL, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SAFE_ERROR, SVGElements, VoidElements, acquireAsset, addEvent, applyRef, assign, claimElement, claimElementTree, className, clearFlashCookie, clientOnly, commitEventResponse, composeMiddleware, configureServerErrors, createRequestEvent, createResponseStub, createSSRResponse, delegateEvents, dispatchAsInteraction, dynamic, dynamicComponent, dynamicProperty, effect, escape, generateHydrationScript, getDelegatedRoot, getExpectedRedirectStatus, getFirstChild, getHydrationKey, getHydrationWriter, getNextElement, getNextMarker, getNextMatch, getNextSibling, getRequestEvent, getServerFunctionMetadata, getServerFunctionRPC, getTraceContext, hasFlashCookie, httpHeader, httpStatus, hydrate, insert, installHydrationRuntime, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, readShallow, redirect, ref, registerDelegatedContainer, registerDelegatedRoot, registerElementClaim, reload, render, renderToStream, renderToString, reportRequestFailure, resolveSSRNode, respond, runHydrationEvents, scope, serializeCookie, setAttribute, setAttributeNS, setProperty, setStyleProperty, spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperties, ssrStyleProperty, style, takeHydrationValue, template, unregisterDelegatedContainer, unregisterDelegatedRoot, useHead, waitAsset, warmAsset };
@@ -0,0 +1,92 @@
1
+ const PRELOAD_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
2
+ function qualifierValue(name, value) {
3
+ if (value == null) return null;
4
+ if (name === "imagesrcset" || name === "imagesizes") return value === "" ? null : value;
5
+ if (name === "as") return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
6
+ if (name !== "crossorigin") return value;
7
+ return value.length === 15 && value.toLowerCase() === "use-credentials" ? "use-credentials" : "anonymous";
8
+ }
9
+ function findHeadElement(selector, attr, value, qualifiers) {
10
+ candidate: for (const node of document.head.querySelectorAll(selector)) {
11
+ if (node.getAttribute(attr) !== value) continue;
12
+ if (!qualifiers) return node;
13
+ for (let i = 0; i < PRELOAD_QUALIFIERS.length; i++) {
14
+ const name = PRELOAD_QUALIFIERS[i];
15
+ if (qualifierValue(name, node.getAttribute(name)) !== qualifierValue(name, qualifiers[name] ?? null)) continue candidate;
16
+ }
17
+ return node;
18
+ }
19
+ return null;
20
+ }
21
+ function ensurePreload(entry) {
22
+ const attrs = entry.attrs;
23
+ const href = entry.href;
24
+ if (findHeadElement('link[rel="preload"]', "href", href || null, attrs)) return;
25
+ const link = document.createElement("link");
26
+ link.rel = "preload";
27
+ for (const name in attrs) link.setAttribute(name, attrs[name]);
28
+ if (href) link.setAttribute("href", href);
29
+ document.head.appendChild(link);
30
+ }
31
+ function ensureStylesheet(entry, onSettle) {
32
+ const href = typeof entry === "string" ? entry : entry.href;
33
+ let link = findHeadElement('link[rel="stylesheet"]', "href", href);
34
+ if (!link) {
35
+ link = document.createElement("link");
36
+ link.rel = "stylesheet";
37
+ if (typeof entry !== "string" && entry.attrs) {
38
+ for (const name in entry.attrs) link.setAttribute(name, entry.attrs[name]);
39
+ }
40
+ link.href = href;
41
+ const waiters = new Set();
42
+ link._$frWaiters = waiters;
43
+ const settle = () => {
44
+ link._$frWaiters = null;
45
+ for (const fn of waiters) fn();
46
+ };
47
+ link.addEventListener("load", settle);
48
+ link.addEventListener("error", settle);
49
+ document.head.appendChild(link);
50
+ }
51
+ const waiters = link._$frWaiters;
52
+ if (waiters == null) return true;
53
+ waiters.add(onSettle);
54
+ return false;
55
+ }
56
+ function ensureModulePreload(href) {
57
+ if (findHeadElement('link[rel="modulepreload"]', "href", href)) return;
58
+ const link = document.createElement("link");
59
+ link.rel = "modulepreload";
60
+ link.href = href;
61
+ document.head.appendChild(link);
62
+ }
63
+ function applyInlineStyles(inlineStyles) {
64
+ for (const entry of inlineStyles) {
65
+ if (findHeadElement("style[data-asset]", "data-asset", entry.id)) continue;
66
+ const el = document.createElement("style");
67
+ el.setAttribute("data-asset", entry.id);
68
+ if (entry.attrs) {
69
+ for (const name in entry.attrs) el.setAttribute(name, entry.attrs[name]);
70
+ }
71
+ el.textContent = entry.content || "";
72
+ document.head.appendChild(el);
73
+ }
74
+ }
75
+ const flushers = new WeakMap();
76
+ function gate(entries, frame) {
77
+ let flush = flushers.get(frame);
78
+ if (!flush) flushers.set(frame, flush = () => frame.apply({
79
+ version: frame.version,
80
+ r: {}
81
+ }));
82
+ let ready = true;
83
+ for (const entry of entries) ready = ensureStylesheet(entry, flush) && ready;
84
+ return ready;
85
+ }
86
+ function apply(record) {
87
+ if (record.modules) for (const href of record.modules) ensureModulePreload(href);
88
+ if (record.preloads) for (const entry of record.preloads) ensurePreload(entry);
89
+ if (record.inlineStyles) applyInlineStyles(record.inlineStyles);
90
+ }
91
+
92
+ export { apply, gate };
@@ -0,0 +1,326 @@
1
+ import { DEV, OBSERVE, createSignal, untrack, createRenderEffect, onCleanup } from 'solid-js';
2
+ import { assign, runHydrationEvents } from '@solidjs/web';
3
+ import { sharedConfig } from 'solid-js/internal';
4
+ import { isAsyncValue as isAsyncValue$1 } from '@solidjs/web/frames';
5
+
6
+ const SLOT_MARKER = "_s:";
7
+ const SLOT_TEXT = SLOT_MARKER + "t=";
8
+ function isAsyncValue(v) {
9
+ return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
10
+ }
11
+ function shapeOf(v) {
12
+ return v === null ? "null" : typeof Node === "function" && v instanceof Node ? "a DOM node" : Array.isArray(v) ? "an array" : isAsyncValue(v) ? "an async value" : typeof v;
13
+ }
14
+ function slotShapeFinding(data, message) {
15
+ DEV.report(OBSERVE.diagnostics.emit({
16
+ code: "BINDING_SLOT_POSITION",
17
+ kind: "render",
18
+ severity: "warn",
19
+ message,
20
+ data
21
+ }, null));
22
+ }
23
+
24
+ function slotEntry(entry, pos) {
25
+ const colon = entry.indexOf(":");
26
+ if (colon < 1) return null;
27
+ const eq = entry.indexOf("=", colon);
28
+ return [entry.slice(0, colon), {
29
+ pos,
30
+ key: decodeURIComponent(eq === -1 ? entry.slice(colon + 1) : entry.slice(colon + 1, eq)),
31
+ name: eq === -1 ? undefined : decodeURIComponent(entry.slice(eq + 1))
32
+ }];
33
+ }
34
+ function consumersOf(elements, occurrence) {
35
+ let consumers = elements.get(occurrence);
36
+ if (consumers === undefined) elements.set(occurrence, consumers = []);
37
+ return Array.isArray(consumers) ? consumers : null;
38
+ }
39
+ function text(start, elements) {
40
+ const parsed = slotEntry(start.data.slice(SLOT_TEXT.length), "text");
41
+ const consumers = parsed && consumersOf(elements, parsed[0]);
42
+ if (!consumers) return;
43
+ const element = start.parentNode;
44
+ let consumer;
45
+ for (let i = consumers.length; i-- && !consumer;) if (consumers[i].element === element) consumer = consumers[i];
46
+ consumer || consumers.push(consumer = {
47
+ element,
48
+ positions: []
49
+ });
50
+ parsed[1].start = start;
51
+ consumer.positions.push(parsed[1]);
52
+ }
53
+ function slotPositions(el) {
54
+ const attrs = el.attributes;
55
+ let out = null;
56
+ for (let i = 0; i < attrs.length; i++) {
57
+ const attr = attrs[i];
58
+ if (!attr.name.startsWith(SLOT_MARKER)) continue;
59
+ const pos = attr.name.slice(SLOT_MARKER.length);
60
+ for (const entry of attr.value.split(",")) {
61
+ const parsed = slotEntry(entry, pos);
62
+ if (!parsed) continue;
63
+ out || (out = Object.create(null));
64
+ (out[parsed[0]] || (out[parsed[0]] = [])).push(parsed[1]);
65
+ }
66
+ }
67
+ return out;
68
+ }
69
+ function positions(el, elements) {
70
+ const byOccurrence = slotPositions(el);
71
+ if (byOccurrence !== null) {
72
+ for (const occurrence in byOccurrence) {
73
+ const consumers = consumersOf(elements, occurrence);
74
+ if (consumers) consumers.push({
75
+ element: el,
76
+ positions: byOccurrence[occurrence]
77
+ });
78
+ }
79
+ }
80
+ }
81
+ function consumersEqual(a, b) {
82
+ if (a.length !== b.length) return false;
83
+ for (let i = 0; i < a.length; i++) {
84
+ const x = a[i];
85
+ const y = b[i];
86
+ if (x.element !== y.element || x.positions.length !== y.positions.length) return false;
87
+ for (let j = 0; j < x.positions.length; j++) {
88
+ const p = x.positions[j];
89
+ const q = y.positions[j];
90
+ if (p.pos !== q.pos || p.key !== q.key || p.name !== q.name || p.start !== q.start) return false;
91
+ }
92
+ }
93
+ return true;
94
+ }
95
+ const byFrame = new WeakMap();
96
+ function occurrencesOf(frame) {
97
+ let slots = byFrame.get(frame);
98
+ if (!slots) byFrame.set(frame, slots = new Map());
99
+ return slots;
100
+ }
101
+ function sync(frame, occurrence, consumers) {
102
+ const slots = occurrencesOf(frame);
103
+ const entry = slots.get(occurrence);
104
+ if (!entry) slots.set(occurrence, {
105
+ consumers,
106
+ rebind: undefined
107
+ });else if (!entry.consumers) entry.consumers = consumers;else if (!consumersEqual(entry.consumers, consumers)) {
108
+ entry.consumers = consumers;
109
+ entry.rebind && entry.rebind(consumers);
110
+ }
111
+ }
112
+ function rebinder(frame, occurrence, fn) {
113
+ const slots = occurrencesOf(frame);
114
+ const entry = slots.get(occurrence);
115
+ if (entry) entry.rebind = fn;else slots.set(occurrence, {
116
+ consumers: undefined,
117
+ rebind: fn
118
+ });
119
+ }
120
+ function unmount(frame, occurrence) {
121
+ byFrame.get(frame)?.delete(occurrence);
122
+ }
123
+ function owned(el) {
124
+ const attrs = el.attributes;
125
+ let out = null;
126
+ for (let i = 0; i < attrs.length; i++) {
127
+ const name = attrs[i].name;
128
+ if (!name.startsWith(SLOT_MARKER)) continue;
129
+ const pos = name.slice(SLOT_MARKER.length);
130
+ if (pos === "ref" || pos.startsWith("on:")) continue;
131
+ out || (out = {
132
+ attrs: new Set(),
133
+ class: null,
134
+ style: null
135
+ });
136
+ if (pos !== "class" && pos !== "style") {
137
+ out.attrs.add(pos);
138
+ continue;
139
+ }
140
+ for (const entry of attrs[i].value.split(",")) {
141
+ const eq = entry.indexOf("=");
142
+ if (eq === -1) {
143
+ out.attrs.add(pos);
144
+ continue;
145
+ }
146
+ (out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
147
+ }
148
+ }
149
+ return out;
150
+ }
151
+ function morphOwnedClass(oldEl, value, names) {
152
+ const list = oldEl.classList;
153
+ const set = new Set(value ? value.split(/\s+/) : []);
154
+ set.delete("");
155
+ for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
156
+ const next = [...set].join(" ");
157
+ if (next === (oldEl.getAttribute("class") || "")) return false;
158
+ next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
159
+ return true;
160
+ }
161
+ function morphOwnedStyle(oldEl, value, names) {
162
+ const style = oldEl.style;
163
+ const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
164
+ const before = oldEl.getAttribute("style");
165
+ value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
166
+ for (const [name, v, priority] of saved) {
167
+ v ? style.setProperty(name, v, priority) : style.removeProperty(name);
168
+ }
169
+ return oldEl.getAttribute("style") !== before;
170
+ }
171
+ function apply(oldEl, name, value, owned) {
172
+ if (owned.attrs.has(name)) return false;
173
+ if ((name === "class" || name === "style") && owned[name] !== null) {
174
+ return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
175
+ }
176
+ return undefined;
177
+ }
178
+ const handlerOwners = new WeakMap();
179
+ function bind(fill, args, ctx, label) {
180
+ const [consumers, setConsumers] = createSignal(ctx.positions);
181
+ ctx.onRebind(setConsumers);
182
+ const raw = untrack(() => fill(args), label);
183
+ const node = typeof Node === "function" && raw instanceof Node;
184
+ const pending = isAsyncValue$1(raw);
185
+ if ((raw == null || typeof raw !== "object" || Array.isArray(raw) || node || pending)) {
186
+ const shape = shapeOf(raw);
187
+ slotShapeFinding({
188
+ reason: "fill-shape",
189
+ occurrence: ctx.key,
190
+ shape
191
+ }, `[BINDING_SLOT_POSITION] The fill for \`${ctx.key}\` returned ${shape}; server markup reads ` + `its properties at bound positions, so it must return an object (\`{ done, onToggle, … }\`). ` + `Nothing binds.`);
192
+ }
193
+ const out = raw == null || typeof raw !== "object" || node || pending ? {} : raw;
194
+ const token = {};
195
+ const state = new WeakMap();
196
+ let bound = new Set();
197
+ createRenderEffect(() => consumers().map(valuesFor), writes => {
198
+ const next = new Set();
199
+ for (const {
200
+ element,
201
+ positions,
202
+ values,
203
+ texts
204
+ } of writes) {
205
+ next.add(element);
206
+ write(element, positions, values);
207
+ for (const [start, v, key] of texts) writeText(start, v, key);
208
+ }
209
+ for (const element of bound) if (!next.has(element)) release(element);
210
+ bound = next;
211
+ });
212
+ onCleanup(() => {
213
+ for (const element of bound) release(element);
214
+ });
215
+ function valuesFor({
216
+ element,
217
+ positions
218
+ }) {
219
+ const props = {};
220
+ const texts = [];
221
+ let classNames = null;
222
+ let styleProps = null;
223
+ for (const {
224
+ pos,
225
+ key,
226
+ name,
227
+ start
228
+ } of positions) {
229
+ if (pos === "ref" || pos.startsWith("on:")) continue;
230
+ if (pos === "text") texts.push([start, out[key], key]);else if (pos === "class" || pos === "style") {
231
+ if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
232
+ } else props[pos] = out[key];
233
+ }
234
+ if (classNames !== null && !("class" in props)) props.class = classNames;
235
+ if (styleProps !== null && !("style" in props)) props.style = styleProps;
236
+ return {
237
+ element,
238
+ positions,
239
+ values: props,
240
+ texts
241
+ };
242
+ }
243
+ function write(element, positions, props) {
244
+ let st = state.get(element);
245
+ if (!st) state.set(element, st = {
246
+ prev: {},
247
+ handlers: {},
248
+ ref: undefined,
249
+ refId: ""
250
+ });
251
+ const handlers = {};
252
+ const refKeys = [];
253
+ for (const {
254
+ pos,
255
+ key
256
+ } of positions) {
257
+ if (pos === "ref") refKeys.push(key);else if (pos.startsWith("on:")) handlers["on" + pos[3].toUpperCase() + pos.slice(4)] = key;
258
+ }
259
+ let owners = handlerOwners.get(element);
260
+ if (!owners) handlerOwners.set(element, owners = {});
261
+ let events = false;
262
+ for (const prop in handlers) {
263
+ events = true;
264
+ const key = handlers[prop];
265
+ let h = st.handlers[prop];
266
+ if (h === undefined || h.key !== key) st.handlers[prop] = h = {
267
+ key,
268
+ value: untrack(() => out[key])
269
+ };
270
+ props[prop] = h.value;
271
+ owners[prop] = token;
272
+ }
273
+ const clearing = {};
274
+ for (const prop in st.handlers) {
275
+ if (prop in handlers) continue;
276
+ delete st.handlers[prop];
277
+ if (owners[prop] === token) {
278
+ delete owners[prop];
279
+ clearing[prop] = true;
280
+ }
281
+ }
282
+ if (refKeys.length) {
283
+ const id = refKeys.join(",");
284
+ if (st.refId !== id) {
285
+ const refs = refKeys.map(k => untrack(() => out[k]));
286
+ st.refId = id;
287
+ st.ref = el => {
288
+ for (const r of refs) typeof r === "function" && r(el);
289
+ };
290
+ }
291
+ props.ref = st.ref;
292
+ }
293
+ for (const k in st.prev) {
294
+ if (k in props || k === "ref" || k in clearing) continue;
295
+ delete st.prev[k];
296
+ }
297
+ assign(element, props, true, st.prev);
298
+ if (events && sharedConfig.completed && !sharedConfig.completed.has(element)) {
299
+ sharedConfig.completed.add(element);
300
+ runHydrationEvents();
301
+ }
302
+ }
303
+ function release(element) {
304
+ if (!state.has(element)) return;
305
+ write(element, [], {});
306
+ state.delete(element);
307
+ }
308
+ function writeText(start, v, key) {
309
+ let s = "";
310
+ if (typeof v === "string" || typeof v === "number") s = "" + v;else if (v != null && typeof v !== "boolean") {
311
+ const shape = shapeOf(v);
312
+ slotShapeFinding({
313
+ reason: "text-shape",
314
+ occurrence: ctx.key,
315
+ key,
316
+ shape
317
+ }, `[BINDING_SLOT_POSITION] \`${key}\` of \`${ctx.key}\` is placed as text, but the fill ` + `returned ${shape} for it. A text position renders a string or number; markup belongs ` + `in a template slot. The text is cleared.`);
318
+ }
319
+ const n = start.nextSibling;
320
+ if (n && n.nodeType === 3) {
321
+ if (n.data !== s) n.data = s;
322
+ } else if (s) start.after(s);
323
+ }
324
+ }
325
+
326
+ export { apply, bind, owned, positions, rebinder, sync, text, unmount };