@atom.io/spa 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +401 -2
- package/README.mdx +150 -0
- package/dist/astro-application.d.ts +15 -0
- package/dist/astro-application.d.ts.map +1 -0
- package/dist/astro-application.js +62 -0
- package/dist/astro-application.js.map +1 -0
- package/dist/astro-client.d.ts +9 -0
- package/dist/astro-client.d.ts.map +1 -0
- package/dist/astro-client.js +98 -0
- package/dist/astro-client.js.map +1 -0
- package/dist/astro-context-OdlexHR4.js +79 -0
- package/dist/astro-context-OdlexHR4.js.map +1 -0
- package/dist/astro-middleware.d.ts +4 -0
- package/dist/astro-middleware.d.ts.map +1 -0
- package/dist/astro-middleware.js +49 -0
- package/dist/astro-middleware.js.map +1 -0
- package/dist/astro-request-DRKvDjsO.js +70 -0
- package/dist/astro-request-DRKvDjsO.js.map +1 -0
- package/dist/astro-server.d.ts +4 -0
- package/dist/astro-server.d.ts.map +1 -0
- package/dist/astro-server.js +30 -0
- package/dist/astro-server.js.map +1 -0
- package/dist/astro-shared-BT45auwR.js +29 -0
- package/dist/astro-shared-BT45auwR.js.map +1 -0
- package/dist/astro-shared-DkZaqX7L.d.ts +31 -0
- package/dist/astro-shared-DkZaqX7L.d.ts.map +1 -0
- package/dist/astro.d.ts +6 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +26 -0
- package/dist/astro.js.map +1 -0
- package/dist/client.min.d.ts +1 -0
- package/dist/client.min.js +1 -0
- package/dist/core-BhiA9fFi.d.ts +44 -0
- package/dist/core-BhiA9fFi.d.ts.map +1 -0
- package/dist/core-Dvqm7w2y.js +231 -0
- package/dist/core-Dvqm7w2y.js.map +1 -0
- package/dist/development/astro-application.js +62 -0
- package/dist/development/astro-application.js.map +1 -0
- package/dist/development/astro-client.js +98 -0
- package/dist/development/astro-client.js.map +1 -0
- package/dist/development/astro-context-OdlexHR4.js +79 -0
- package/dist/development/astro-context-OdlexHR4.js.map +1 -0
- package/dist/development/astro-middleware.js +49 -0
- package/dist/development/astro-middleware.js.map +1 -0
- package/dist/development/astro-request-DRKvDjsO.js +70 -0
- package/dist/development/astro-request-DRKvDjsO.js.map +1 -0
- package/dist/development/astro-server.js +30 -0
- package/dist/development/astro-server.js.map +1 -0
- package/dist/development/astro-shared-BT45auwR.js +29 -0
- package/dist/development/astro-shared-BT45auwR.js.map +1 -0
- package/dist/development/astro.js +26 -0
- package/dist/development/astro.js.map +1 -0
- package/dist/development/core-DB3sQz4h.js +234 -0
- package/dist/development/core-DB3sQz4h.js.map +1 -0
- package/dist/development/dom-D9cY6l1R.js +194 -0
- package/dist/development/dom-D9cY6l1R.js.map +1 -0
- package/dist/development/index.js +40 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/jsx-runtime.js +25 -0
- package/dist/development/jsx-runtime.js.map +1 -0
- package/dist/development/server.js +78 -0
- package/dist/development/server.js.map +1 -0
- package/dist/development/vite-BadrFSIM.js +126 -0
- package/dist/development/vite-BadrFSIM.js.map +1 -0
- package/dist/development/vite.js +1 -0
- package/dist/dom-BR9o9wZW.js +188 -0
- package/dist/dom-BR9o9wZW.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-runtime-BzGV18VO.d.ts +965 -0
- package/dist/jsx-runtime-BzGV18VO.d.ts.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.js +25 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +78 -0
- package/dist/server.js.map +1 -0
- package/dist/size.json +30 -0
- package/dist/vite-BadrFSIM.js +126 -0
- package/dist/vite-BadrFSIM.js.map +1 -0
- package/dist/vite.d.ts +6 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +1 -0
- package/package.json +131 -5
- package/src/astro-application.ts +71 -0
- package/src/astro-client.ts +136 -0
- package/src/astro-context.ts +102 -0
- package/src/astro-middleware.ts +48 -0
- package/src/astro-request.ts +79 -0
- package/src/astro-server.ts +43 -0
- package/src/astro-shared.ts +78 -0
- package/src/astro.ts +47 -0
- package/src/compiler.ts +189 -0
- package/src/core.ts +385 -0
- package/src/dom.ts +385 -0
- package/src/env.d.ts +1 -0
- package/src/index.ts +24 -0
- package/src/jsx-runtime.ts +63 -0
- package/src/jsx-types.d.ts +909 -0
- package/src/server.ts +150 -0
- package/src/use-loadable.ts +67 -0
- package/src/vite.ts +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-D9cY6l1R.js","names":[],"sources":["../../src/dom.ts"],"sourcesContent":["import type { Accessor, Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nconst HTML = `http://www.w3.org/1999/xhtml`\nconst SVG = `http://www.w3.org/2000/svg`\ntype Cursor = { node: Node | null }\ntype RecordNode = { _value: Child; _scope: Scope; _start: Node; _end: Node }\n\nfunction take(\n\tnode: Node,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\tif (\n\t\tcursor &&\n\t\t!(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)\n\t) {\n\t\tconst found = cursor.node\n\t\tif (\n\t\t\t!found ||\n\t\t\tfound.nodeType !== node.nodeType ||\n\t\t\tfound.nodeName !== node.nodeName ||\n\t\t\t(found as Element).namespaceURI !== (node as Element).namespaceURI ||\n\t\t\t(node.nodeType !== 1 && found.nodeValue !== node.nodeValue)\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\tnode = found\n\t\tcursor.node = found.nextSibling\n\t} else parent.insertBefore(node, cursor ? cursor.node : before)\n\towner._cleanups.add(() => {\n\t\t;(node as ChildNode).remove()\n\t})\n\treturn node\n}\nfunction comment(\n\tvalue: string,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\treturn take(\n\t\tparent.ownerDocument!.createComment(value),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t)\n}\nfunction property(\n\telement: Element,\n\tkey: string,\n\tvalue: any,\n\tprevious: any,\n): void {\n\tif (/^(key|children|ref)$/.test(key)) return\n\tif (key === `innerHTML` && element.localName === `astro-slot`) return\n\tif (\n\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\tkey,\n\t\t)\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: owned content` : undefined)\n\tif (key.startsWith(`on`)) {\n\t\tconst capture = /(?<!Pointer)Capture$/.test(key)\n\t\tconst event = key\n\t\t\t.slice(2, capture ? -7 : undefined)\n\t\t\t.toLowerCase()\n\t\t\t.replace(`doubleclick`, `dblclick`)\n\t\tif (previous) element.removeEventListener(event, previous, capture)\n\t\tif (value != null) {\n\t\t\tif (import.meta.env.DEV && typeof value !== `function`)\n\t\t\t\tthrow new Error(`spa: event handler`)\n\t\t\telement.addEventListener(event, value, capture)\n\t\t}\n\t\treturn\n\t}\n\tif (key === `className`) key = `class`\n\tif (key === `htmlFor`) key = `for`\n\tif (\n\t\timport.meta.env.DEV &&\n\t\tkey === `style` &&\n\t\tvalue != null &&\n\t\ttypeof value !== `string`\n\t)\n\t\tthrow new Error(`spa: CSS string required`)\n\tif (\n\t\telement.namespaceURI === HTML &&\n\t\tkey in element &&\n\t\t!/^(style|form|list)$/.test(key)\n\t) {\n\t\tconst target = element as any\n\t\ttarget[key] = value ?? (typeof target[key] === `boolean` ? false : ``)\n\t} else if (value == null || (value === false && !/^(aria-|data-)/.test(key)))\n\t\telement.removeAttribute(key)\n\telse\n\t\telement.setAttribute(\n\t\t\tkey,\n\t\t\tvalue === true && !/^(aria-|data-)/.test(key) ? `` : String(value),\n\t\t)\n}\n\nfunction mount(\n\tvalue: Child,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tnamespace: string,\n\tcursor?: Cursor,\n\tsource = () => value,\n): void {\n\tif (typeof value === `function`) {\n\t\tcomment(`{`, parent, before, owner, cursor)\n\t\tlet end: Node | null = null\n\t\tlet records = new Map<unknown, RecordNode>()\n\t\tlet initial = cursor\n\t\tobserve(\n\t\t\towner,\n\t\t\t() => (source() as () => Child)(),\n\t\t\t(next) => {\n\t\t\t\tconst values = ([next] as unknown[]).flat(Infinity) as Child[]\n\t\t\t\tconst kept = new Map<unknown, RecordNode>()\n\t\t\t\tconst focus = parent.ownerDocument!.activeElement as HTMLElement | null\n\t\t\t\tfor (let index = 0; index < values.length; index++) {\n\t\t\t\t\tconst child = values[index]\n\t\t\t\t\tconst vnode = child as VNode | null\n\t\t\t\t\tconst explicit = vnode?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (import.meta.env.DEV && kept.has(key))\n\t\t\t\t\t\tthrow new Error(`spa: duplicate key`)\n\t\t\t\t\tlet record = records.get(key)\n\t\t\t\t\tif (\n\t\t\t\t\t\trecord &&\n\t\t\t\t\t\t(typeof record._value !== typeof child ||\n\t\t\t\t\t\t\t(record._value as VNode | null)?.type !== vnode?.type)\n\t\t\t\t\t) {\n\t\t\t\t\t\tdispose(record._scope)\n\t\t\t\t\t\trecord = undefined\n\t\t\t\t\t}\n\t\t\t\t\tif (!record) {\n\t\t\t\t\t\tconst childOwner = createScope(owner)\n\t\t\t\t\t\trecord = {\n\t\t\t\t\t\t\t_value: child,\n\t\t\t\t\t\t\t_scope: childOwner,\n\t\t\t\t\t\t\t_start: comment(`[`, parent, end ?? before, childOwner, initial),\n\t\t\t\t\t\t\t_end: null!,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst held = record\n\t\t\t\t\t\tmount(\n\t\t\t\t\t\t\tchild,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t\t() => held._value,\n\t\t\t\t\t\t)\n\t\t\t\t\t\trecord._end = comment(\n\t\t\t\t\t\t\t`]`,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trecord._value = child\n\t\t\t\t\t\tinvalidate(record._scope)\n\t\t\t\t\t}\n\t\t\t\t\tkept.set(key, record)\n\t\t\t\t}\n\t\t\t\tfor (const [key, record] of records)\n\t\t\t\t\tif (!kept.has(key)) dispose(record._scope)\n\t\t\t\tif (!initial) {\n\t\t\t\t\tlet at = end ?? before\n\t\t\t\t\tfor (const record of [...kept.values()].reverse()) {\n\t\t\t\t\t\tif (record._end.nextSibling !== at) {\n\t\t\t\t\t\t\tconst range = parent.ownerDocument!.createRange()\n\t\t\t\t\t\t\trange.setStartBefore(record._start)\n\t\t\t\t\t\t\trange.setEndAfter(record._end)\n\t\t\t\t\t\t\tparent.insertBefore(range.extractContents(), at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tat = record._start\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocus?.isConnected &&\n\t\t\t\t\t\tfocus !== parent.ownerDocument!.activeElement\n\t\t\t\t\t)\n\t\t\t\t\t\tfocus.focus({ preventScroll: true })\n\t\t\t\t}\n\t\t\t\tinitial = undefined\n\t\t\t\trecords = kept\n\t\t\t},\n\t\t)\n\t\tend = comment(`}`, parent, before, owner, cursor)\n\t\treturn\n\t}\n\tif (Array.isArray(value)) {\n\t\tfor (const child of value)\n\t\t\tmount(child, parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (value == null || typeof value === `boolean`) return\n\tif (typeof value !== `object`) {\n\t\tcomment(`t`, parent, before, owner, cursor)\n\t\tconst text = take(\n\t\t\tparent.ownerDocument!.createTextNode(String(value)),\n\t\t\tparent,\n\t\t\tbefore,\n\t\t\towner,\n\t\t\tcursor,\n\t\t)\n\t\tobserve(owner, source as Accessor<string | number | bigint>, (next) => {\n\t\t\tconst data = String(next)\n\t\t\tif (text.nodeValue !== data) text.nodeValue = data\n\t\t})\n\t\treturn\n\t}\n\tif (import.meta.env.DEV && (!(`type` in value) || !(`props` in value)))\n\t\tthrow new Error(`spa: invalid child`)\n\tconst vnode = value as VNode\n\tconst props = merge(() => (source() as VNode).props)\n\tif (!vnode.type || vnode.type === Fragment) {\n\t\tmount(() => props[`children`], parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (typeof vnode.type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\tconst output = within(childOwner, () =>\n\t\t\tuntrack(() => (vnode.type as Function)(props)),\n\t\t)\n\t\tmount(output, parent, before, childOwner, namespace, cursor)\n\t\treturn\n\t}\n\tconst ns = vnode.type === `svg` ? SVG : namespace\n\tconst element = take(\n\t\tparent.ownerDocument!.createElementNS(ns, vnode.type),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t) as Element\n\tif (vnode.type === `astro-slot`) {\n\t\tif (!cursor) element.innerHTML = props[`innerHTML`] ?? ``\n\t} else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) {\n\t\tobserve(\n\t\t\towner,\n\t\t\t() =>\n\t\t\t\tplain(\n\t\t\t\t\tvnode.type === `textarea`\n\t\t\t\t\t\t? (props[`value`] ?? props[`children`])\n\t\t\t\t\t\t: props[`children`],\n\t\t\t\t),\n\t\t\t(text) => {\n\t\t\t\tif (element.textContent !== text) element.textContent = text\n\t\t\t},\n\t\t)\n\t} else {\n\t\tconst children = cursor ? { node: element.firstChild } : undefined\n\t\tif (\n\t\t\t!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(\n\t\t\t\tvnode.type,\n\t\t\t) ||\n\t\t\tns !== HTML\n\t\t)\n\t\t\tmount(\n\t\t\t\t() => props[`children`],\n\t\t\t\telement,\n\t\t\t\tnull,\n\t\t\t\towner,\n\t\t\t\tvnode.type === `foreignObject` ? HTML : ns,\n\t\t\t\tchildren,\n\t\t\t)\n\t\tif (children?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t}\n\tlet previous: Record<string, any> = {}\n\towner._cleanups.add(() => {\n\t\tfor (const key in previous)\n\t\t\tif (key.startsWith(`on`)) property(element, key, null, previous[key])\n\t})\n\tobserve(\n\t\towner,\n\t\t() => ({ ...props }),\n\t\t(next) => {\n\t\t\tfor (const key in { ...previous, ...next })\n\t\t\t\tif (\n\t\t\t\t\t!Object.is(previous[key], next[key]) ||\n\t\t\t\t\ttypeof next[key] === `object`\n\t\t\t\t) {\n\t\t\t\t\tproperty(element, key, next[key], previous[key])\n\t\t\t\t\tprevious[key] = next[key]\n\t\t\t\t}\n\t\t\tprevious = next\n\t\t},\n\t)\n\tconst ref = untrack(() => props[`ref`])\n\tif (ref) {\n\t\towner._root._mounts!.unshift(() => {\n\t\t\tif (!owner._dead) {\n\t\t\t\towner._cleanups.add(() => ref(null))\n\t\t\t\tref(element)\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport interface SpaRoot {\n\tdispose(): void\n\tflush(): void\n}\nfunction start(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions,\n\thydrating: boolean,\n): SpaRoot {\n\tconst cursor = hydrating ? { node: host.firstChild } : undefined\n\tconst prefix = cursor?.node?.nodeValue?.slice(2)\n\tif (\n\t\thydrating &&\n\t\t(prefix === undefined ||\n\t\t\t(options.idPrefix !== undefined && prefix !== options.idPrefix))\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: hydration mismatch` : undefined)\n\tconst root = createRoot(options)\n\tif (prefix !== undefined) root._prefix = prefix\n\ttry {\n\t\tcomment(`w:${root._prefix}`, host, null, root, cursor)\n\t\twithin(root, () => {\n\t\t\tmount(\n\t\t\t\tuntrack(setup),\n\t\t\t\thost,\n\t\t\t\tnull,\n\t\t\t\troot,\n\t\t\t\thost.namespaceURI === SVG ? SVG : HTML,\n\t\t\t\tcursor,\n\t\t\t)\n\t\t})\n\t\tcomment(`/w`, host, null, root, cursor)\n\t\tif (cursor?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\troot.flush()\n\t} catch (error) {\n\t\tfail(root, error)\n\t}\n\treturn {\n\t\tdispose: () => {\n\t\t\tdispose(root)\n\t\t},\n\t\tflush: root.flush,\n\t}\n}\nexport function render(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, false)\n}\nexport function hydrate(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, true)\n}\n"],"mappings":";;;AAcA,MAAM,OAAO;AACb,MAAM,MAAM;AAIZ,SAAS,KACR,MACA,QACA,QACA,OACA,QACO;CACP,IACC,UACA,EAAE,KAAK,aAAa,KAAK,CAAC,KAAK,aAAa,OAAO,MAAM,aAAa,IACrE;EACD,MAAM,QAAQ,OAAO;EACrB,IACC,CAAC,SACD,MAAM,aAAa,KAAK,YACxB,MAAM,aAAa,KAAK,YACvB,MAAkB,iBAAkB,KAAiB,gBACrD,KAAK,aAAa,KAAK,MAAM,cAAc,KAAK,WAEjD,MAAM,IAAI,MACa,yBACvB;EACD,OAAO;EACP,OAAO,OAAO,MAAM;CACrB,OAAO,OAAO,aAAa,MAAM,SAAS,OAAO,OAAO,MAAM;C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Token, g as useStore, h as useSetter, l as owner, m as useRef, p as useId, s as onCleanup, v as useTransaction, y as useValue } from "./core-DB3sQz4h.js";
|
|
2
|
+
import { Fragment } from "./jsx-runtime.js";
|
|
3
|
+
import { n as render, t as hydrate } from "./dom-D9cY6l1R.js";
|
|
4
|
+
import { withdraw } from "atom.io/internal";
|
|
5
|
+
// src/use-loadable.ts
|
|
6
|
+
function useLoadable(...params) {
|
|
7
|
+
const store = owner._root._store;
|
|
8
|
+
const [token] = params;
|
|
9
|
+
const family = token.type.endsWith(`_family`);
|
|
10
|
+
const selected = resolveStateToken(token, params[1]);
|
|
11
|
+
const read = useValue(selected);
|
|
12
|
+
const fallbackIndex = family ? 2 : 1;
|
|
13
|
+
const fallback = params[fallbackIndex];
|
|
14
|
+
const hasFallback = params.length > fallbackIndex;
|
|
15
|
+
let available = hasFallback;
|
|
16
|
+
let previous = fallback;
|
|
17
|
+
let error;
|
|
18
|
+
return () => {
|
|
19
|
+
const value = read();
|
|
20
|
+
const loading = value instanceof Promise;
|
|
21
|
+
if (!loading) {
|
|
22
|
+
previous = value;
|
|
23
|
+
available = true;
|
|
24
|
+
const state = withdraw(store, selected);
|
|
25
|
+
error = hasFallback && `catch` in state && state.catch.some((ErrorType) => value instanceof ErrorType) ? value : void 0;
|
|
26
|
+
}
|
|
27
|
+
if (!available) return `LOADING`;
|
|
28
|
+
return error ? {
|
|
29
|
+
loading,
|
|
30
|
+
value: fallback,
|
|
31
|
+
error
|
|
32
|
+
} : {
|
|
33
|
+
loading,
|
|
34
|
+
value: previous
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { Fragment, hydrate, onCleanup, onMount, render, useId, useLoadable, useRef, useSetter, useStore, useTimeline, useTransaction, useValue };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-loadable.ts"],"sourcesContent":["import type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport { withdraw } from \"atom.io/internal\"\n\nimport { type Accessor, owner, resolveStateToken, useValue } from \"./core.ts\"\n\nexport type LoadableValue<T> = { loading: boolean; value: T }\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable(\n\t...params:\n\t\t| [ReadableToken<any, any, any>]\n\t\t| [ReadableToken<any, any, any>, unknown]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n): Accessor<`LOADING` | (LoadableValue<unknown> & { error?: unknown })> {\n\tconst store = owner!._root._store\n\tconst [token] = params\n\tconst family = token.type.endsWith(`_family`)\n\tconst selected = resolveStateToken(token, params[1] as Canonical)\n\tconst read = useValue(selected)\n\tconst fallbackIndex = family ? 2 : 1\n\tconst fallback = params[fallbackIndex]\n\tconst hasFallback = params.length > fallbackIndex\n\tlet available = hasFallback\n\tlet previous = fallback\n\tlet error: unknown\n\treturn () => {\n\t\tconst value = read()\n\t\tconst loading = value instanceof Promise\n\t\tif (!loading) {\n\t\t\tprevious = value\n\t\t\tavailable = true\n\t\t\tconst state = withdraw(store, selected)\n\t\t\terror =\n\t\t\t\thasFallback &&\n\t\t\t\t`catch` in state &&\n\t\t\t\tstate.catch.some((ErrorType) => value instanceof ErrorType)\n\t\t\t\t\t? value\n\t\t\t\t\t: undefined\n\t\t}\n\t\tif (!available) return `LOADING`\n\t\treturn error\n\t\t\t? { loading, value: fallback, error }\n\t\t\t: { loading, value: previous }\n\t}\n}\n"],"mappings":";;;;;AA6BA,SAAgB,YACf,GAAG,QAKoE;CACvE,MAAM,QAAQ,MAAO,MAAM;CAC3B,MAAM,CAAC,SAAS;CAChB,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS;CAC5C,MAAM,WAAW,kBAAkB,OAAO,OAAO,EAAe;CAChE,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,gBAAgB,SAAS,IAAI;CACnC,MAAM,WAAW,OAAO;CACxB,MAAM,cAAc,OAAO,SAAS;CACpC,IAAI,YAAY;CAChB,IAAI,WAAW;CACf,IAAI;CACJ,aAAa;EACZ,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,iBAAiB;EACjC,IAAI,CAAC,SAAS;GACb,WAAW;GACX,YAAY;GACZ,MAAM,QAAQ,SAAS,OAAO,QAAQ;GACtC,QACC,eACA,WAAW,SACX,MAAM,MAAM,MAAM,cAAc,iBAAiB,SAAS,IACvD,QACA,KAAA;EACL;EACA,IAAI,CAAC,WAAW,OAAO;EACvB,OAAO,QACJ;GAAE;GAAS,OAAO;GAAU;EAAM,IAClC;GAAE;GAAS,OAAO;EAAS;CAC/B;AACD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/jsx-runtime.ts
|
|
2
|
+
const Fragment = (props) => props.children;
|
|
3
|
+
function jsx(type, props, key) {
|
|
4
|
+
return {
|
|
5
|
+
type,
|
|
6
|
+
props: key === void 0 ? props ?? {} : merge(props ?? {}, { key })
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
const jsxs = jsx;
|
|
10
|
+
const jsxDEV = jsx;
|
|
11
|
+
/** Preserve lazy props and spread precedence, including keys added by later updates. */
|
|
12
|
+
function merge(...sources) {
|
|
13
|
+
const values = () => sources.map((source) => (typeof source === `function` ? source() : source) ?? {});
|
|
14
|
+
return new Proxy({}, {
|
|
15
|
+
get: (_, key) => values().reverse().find((source) => Object.hasOwn(source, key))?.[key],
|
|
16
|
+
ownKeys: () => [...new Set(values().flatMap(Object.keys))],
|
|
17
|
+
getOwnPropertyDescriptor: () => ({
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { Fragment, jsx, jsxDEV, jsxs, merge };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","names":[],"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import type { Child, Component, VNode } from \"./core.ts\"\nimport type { HTMLAttributes, NativeElements } from \"./jsx-types.d.ts\"\n\nexport type {\n\tAriaAttributes,\n\tDOMAttributes,\n\tEventAttributes,\n\tEventHandler,\n\tHTMLAttributes,\n\tRef,\n\tSVGAttributes,\n\tTargetedEvent,\n} from \"./jsx-types.d.ts\"\n\nexport const Fragment = (props: { children?: Child }): Child => props.children\nexport function jsx(\n\ttype: VNode[`type`],\n\tprops: VNode[`props`] | null,\n\tkey?: unknown,\n): VNode {\n\treturn {\n\t\ttype,\n\t\tprops: key === undefined ? (props ?? {}) : merge(props ?? {}, { key }),\n\t}\n}\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\n/** Preserve lazy props and spread precedence, including keys added by later updates. */\nexport function merge(\n\t...sources: (Record<string, any> | (() => Record<string, any>))[]\n): Record<string, any> {\n\tconst values = () =>\n\t\tsources.map(\n\t\t\t(source) => (typeof source === `function` ? source() : source) ?? {},\n\t\t)\n\treturn new Proxy(\n\t\t{},\n\t\t{\n\t\t\tget: (_, key) =>\n\t\t\t\tvalues()\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((source) => Object.hasOwn(source, key))?.[key],\n\t\t\townKeys: () => [...new Set(values().flatMap(Object.keys))],\n\t\t\tgetOwnPropertyDescriptor: () => ({ enumerable: true, configurable: true }),\n\t\t},\n\t)\n}\n\nexport namespace JSX {\n\texport type Element = VNode\n\texport type ElementType = keyof IntrinsicElements | Component\n\texport interface ElementChildrenAttribute {\n\t\tchildren: {}\n\t}\n\texport interface IntrinsicAttributes {\n\t\tkey?: string | number\n\t}\n\t/** Augment this interface to declare attributes for registered custom elements. */\n\texport interface IntrinsicElements extends NativeElements {\n\t\t[tag: `${string}-${string}`]: HTMLAttributes<HTMLElement>\n\t}\n}\n"],"mappings":";AAcA,MAAa,YAAY,UAAuC,MAAM;AACtE,SAAgB,IACf,MACA,OACA,KACQ;CACR,OAAO;EACN;EACA,OAAO,QAAQ,KAAA,IAAa,SAAS,CAAC,IAAK,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC;CACtE;AACD;AACA,MAAa,OAAO;AACpB,MAAa,SAAS;;AAGtB,SAAgB,MACf,GAAG,SACmB;CACtB,MAAM,eACL,QAAQ,KACN,YAAY,OAAO,WAAW,aAAa,OAAO,IAAI,WAAW,CAAC,CACpE;CACD,OAAO,IAAI,MACV,CAAC,GACD;EACC,MAAM,GAAG,QACR,OAAO,CAAC,CACN,QAAQ,CAAC,CACT,MAAM,WAAW,OAAO,OAAO,QAAQ,GAAG,CAAC,CAAC,GAAG;EAClD,eAAe,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC,CAAC,QAAQ,OAAO,IAAI,CAAC,CAAC;EACzD,iCAAiC;GAAE,YAAY;GAAM,cAAc;EAAK;CACzE,CACD;AACD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { b as within, f as untrack, n as createScope, r as dispose, t as createRoot, u as plain } from "./core-DB3sQz4h.js";
|
|
2
|
+
import { Fragment } from "./jsx-runtime.js";
|
|
3
|
+
// src/server.ts
|
|
4
|
+
const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
|
5
|
+
"&": `&`,
|
|
6
|
+
"<": `<`,
|
|
7
|
+
">": `>`,
|
|
8
|
+
"\"": `"`,
|
|
9
|
+
"'": `'`
|
|
10
|
+
})[char]);
|
|
11
|
+
const voidTags = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
|
12
|
+
const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected`.split(` `));
|
|
13
|
+
function stringify(value, owner, namespace = `html`, selectValue) {
|
|
14
|
+
if (typeof value === `function`) {
|
|
15
|
+
const values = [untrack(value)].flat(Infinity);
|
|
16
|
+
const keys = /* @__PURE__ */ new Set();
|
|
17
|
+
return `<!--{-->` + values.map((child, index) => {
|
|
18
|
+
const explicit = child?.props?.[`key`];
|
|
19
|
+
const key = explicit == null ? index : String(explicit);
|
|
20
|
+
if (keys.has(key)) throw new Error(`spa: duplicate key`);
|
|
21
|
+
keys.add(key);
|
|
22
|
+
return `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`;
|
|
23
|
+
}).join(``) + `<!--}-->`;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value)) return value.map((child) => stringify(child, owner, namespace, selectValue)).join(``);
|
|
26
|
+
if (value == null || typeof value === `boolean`) return ``;
|
|
27
|
+
if (typeof value !== `object`) return `<!--t-->${escape(value)}`;
|
|
28
|
+
if (!(`type` in value) || !(`props` in value)) throw new TypeError(`spa: invalid child`);
|
|
29
|
+
const { type, props } = value;
|
|
30
|
+
if (!type || type === Fragment) return stringify(() => props[`children`], owner, namespace, selectValue);
|
|
31
|
+
if (typeof type === `function`) {
|
|
32
|
+
const childOwner = createScope(owner);
|
|
33
|
+
return within(childOwner, () => stringify(untrack(() => type(props)), childOwner, namespace, selectValue));
|
|
34
|
+
}
|
|
35
|
+
if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
|
|
36
|
+
if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
|
|
37
|
+
const ns = type === `svg` ? `svg` : namespace;
|
|
38
|
+
let attrs = ``;
|
|
39
|
+
let textValue;
|
|
40
|
+
for (let key of Object.keys(props)) {
|
|
41
|
+
if (key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
|
|
42
|
+
if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
|
|
43
|
+
let attribute = props[key];
|
|
44
|
+
if (key === `className`) key = `class`;
|
|
45
|
+
if (key === `htmlFor`) key = `for`;
|
|
46
|
+
if (!/^[^\s"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`);
|
|
47
|
+
if (key === `value` && (type === `select` || type === `textarea`)) {
|
|
48
|
+
textValue = attribute;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (key === `style` && attribute != null && typeof attribute !== `string`) throw new TypeError(`spa: CSS string required`);
|
|
52
|
+
const boolean = ns === `html` && booleans.has(key.toLowerCase());
|
|
53
|
+
if (attribute == null || boolean && !attribute || attribute === false && !/^(aria-|data-)/.test(key)) continue;
|
|
54
|
+
attrs += boolean || attribute === true && !/^(aria-|data-)/.test(key) ? ` ${key}=""` : ` ${key}="${escape(attribute)}"`;
|
|
55
|
+
}
|
|
56
|
+
if (type === `option` && selectValue !== void 0 && String(props[`value`]) === String(selectValue)) attrs += ` selected=""`;
|
|
57
|
+
if (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`;
|
|
58
|
+
if (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {
|
|
59
|
+
let text = plain(type === `textarea` ? textValue ?? props[`children`] : props[`children`]);
|
|
60
|
+
if (type === `textarea` && text.startsWith(`\n`)) text = `\n${text}`;
|
|
61
|
+
if (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text)) throw new Error(`spa: unsafe raw text`);
|
|
62
|
+
return `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`;
|
|
63
|
+
}
|
|
64
|
+
const children = stringify(() => props[`children`], owner, type === `foreignObject` ? `html` : ns, type === `select` ? textValue : selectValue);
|
|
65
|
+
return `<${type}${attrs}>${children}</${type}>`;
|
|
66
|
+
}
|
|
67
|
+
function renderToString(setup, options = {}) {
|
|
68
|
+
const root = createRoot(options, true);
|
|
69
|
+
if (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`);
|
|
70
|
+
try {
|
|
71
|
+
return `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`;
|
|
72
|
+
} finally {
|
|
73
|
+
dispose(root);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export { renderToString };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../../src/server.ts"],"sourcesContent":["import type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&`, \"<\": `<`, \">\": `>`, '\"': `"`, \"'\": `'` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Child,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = ([untrack(value)] as unknown[]).flat(Infinity) as Child[]\n\t\tconst keys = new Set<unknown>()\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map((child, index) => {\n\t\t\t\t\tconst explicit = (child as VNode | null)?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (keys.has(key)) throw new Error(`spa: duplicate key`)\n\t\t\t\t\tkeys.add(key)\n\t\t\t\t\treturn `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`\n\t\t\t\t})\n\t\t\t\t.join(``) +\n\t\t\t`<!--}-->`\n\t\t)\n\t}\n\tif (Array.isArray(value))\n\t\treturn value\n\t\t\t.map((child) => stringify(child, owner, namespace, selectValue))\n\t\t\t.join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (typeof value !== `object`) return `<!--t-->${escape(value)}`\n\tif (!(`type` in value) || !(`props` in value))\n\t\tthrow new TypeError(`spa: invalid child`)\n\tconst { type, props } = value\n\tif (!type || type === Fragment)\n\t\treturn stringify(() => props[`children`], owner, namespace, selectValue)\n\tif (typeof type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\treturn within(childOwner, () =>\n\t\t\tstringify(\n\t\t\t\tuntrack(() => type(props)),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean = ns === `html` && booleans.has(key.toLowerCase())\n\t\tif (\n\t\t\tattribute == null ||\n\t\t\t(boolean && !attribute) ||\n\t\t\t(attribute === false && !/^(aria-|data-)/.test(key))\n\t\t)\n\t\t\tcontinue\n\t\tattrs +=\n\t\t\tboolean || (attribute === true && !/^(aria-|data-)/.test(key))\n\t\t\t\t? ` ${key}=\"\"`\n\t\t\t\t: ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToString(\n\tsetup: () => Child,\n\toptions: RootOptions = {},\n): string {\n\tconst root = createRoot(options, true)\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":";;;AAWA,MAAM,UAAU,UACf,OAAO,KAAK,CAAC,CAAC,QACb,aACC,UACC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;CAAU,KAAK;AAAQ,EAAA,CACtE,KAEH;AACD,MAAM,WACL;AACD,MAAM,WAAW,IAAI,IACpB,4NAA4N,MAC3N,GACD,CACD;AACA,SAAS,UACR,OACA,OACA,YAAY,QACZ,aACS;CACT,IAAI,OAAO,UAAU,YAAY;EAChC,MAAM,SAAU,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAe,KAAK,QAAQ;EAC5D,MAAM,uBAAO,IAAI,IAAa;EAC9B,OACC,aACA,OACE,KAAK,OAAO,UAAU;GACtB,MAAM,WAAY,OAAwB,QAAQ;GAClD,MAAM,MAAM,YAAY,OAAO,QAAQ,OAAO,QAAQ;GACtD,IAAI,KAAK,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,oBAAoB;GACvD,KAAK,IAAI,GAAG;GACZ,OAAO,WAAW,OAAO,aAAa,UAAU,OAAO,YAAY,KAAK,GAAG,WAAW,WAAW,CAAC,EAAE;EACrG,CAAC,CAAC,CACD,KAAK,EAAE,IACT;CAEF;CACA,IAAI,MAAM,QAAQ,KAAK,GACtB,O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UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { transformSync, types } from "@babel/core";
|
|
2
|
+
// src/compiler.ts
|
|
3
|
+
function compile(code, filename) {
|
|
4
|
+
const plugin = () => {
|
|
5
|
+
let create;
|
|
6
|
+
let merge;
|
|
7
|
+
const generated = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
const components = /* @__PURE__ */ new Set();
|
|
9
|
+
function name(node) {
|
|
10
|
+
if (types.isJSXMemberExpression(node)) return types.memberExpression(types.isJSXIdentifier(node.object) ? node.object.name === `this` ? types.thisExpression() : types.identifier(node.object.name) : name(node.object), types.identifier(node.property.name));
|
|
11
|
+
if (types.isJSXNamespacedName(node)) return types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
|
|
12
|
+
return /^[a-z]/.test(node.name) || node.name.includes(`-`) ? types.stringLiteral(node.name) : types.identifier(node.name);
|
|
13
|
+
}
|
|
14
|
+
function literal(node) {
|
|
15
|
+
return types.isLiteral(node) && (!types.isTemplateLiteral(node) || node.expressions.length === 0);
|
|
16
|
+
}
|
|
17
|
+
function child(node) {
|
|
18
|
+
return generated.has(node) || literal(node) || types.isFunction(node) ? node : types.arrowFunctionExpression([], node);
|
|
19
|
+
}
|
|
20
|
+
return { visitor: {
|
|
21
|
+
ExportDefaultDeclaration(path) {
|
|
22
|
+
if (types.isArrowFunctionExpression(path.node.declaration) || types.isFunctionExpression(path.node.declaration)) {
|
|
23
|
+
const id = path.scope.generateUidIdentifier(`Component`);
|
|
24
|
+
path.replaceWithMultiple([types.variableDeclaration(`const`, [types.variableDeclarator(id, path.node.declaration)]), types.exportDefaultDeclaration(id)]);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
Program: {
|
|
28
|
+
enter(path) {
|
|
29
|
+
create = path.scope.generateUidIdentifier(`spa`);
|
|
30
|
+
merge = path.scope.generateUidIdentifier(`props`);
|
|
31
|
+
},
|
|
32
|
+
exit(path) {
|
|
33
|
+
path.unshiftContainer(`body`, types.importDeclaration([types.importSpecifier(create, types.identifier(`jsx`)), types.importSpecifier(merge, types.identifier(`merge`))], types.stringLiteral(`@atom.io/spa/jsx-runtime`)));
|
|
34
|
+
for (const component of components) path.pushContainer(`body`, types.expressionStatement(types.assignmentExpression(`=`, types.memberExpression(types.identifier(component), types.identifier(`spa`)), types.booleanLiteral(true))));
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"JSXElement|JSXFragment": { exit(path) {
|
|
38
|
+
const node = path.node;
|
|
39
|
+
const chunks = [];
|
|
40
|
+
let properties = [];
|
|
41
|
+
const flush = () => {
|
|
42
|
+
if (properties.length) {
|
|
43
|
+
chunks.push(types.objectExpression(properties));
|
|
44
|
+
properties = [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (types.isJSXElement(node)) for (const attribute of node.openingElement.attributes) {
|
|
48
|
+
if (types.isJSXSpreadAttribute(attribute)) {
|
|
49
|
+
flush();
|
|
50
|
+
chunks.push(types.arrowFunctionExpression([], attribute.argument));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const key = types.isJSXNamespacedName(attribute.name) ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name;
|
|
54
|
+
const expression = attribute.value == null ? types.booleanLiteral(true) : types.isJSXExpressionContainer(attribute.value) ? attribute.value.expression : attribute.value;
|
|
55
|
+
properties.push(key === `key` || literal(expression) || types.isFunction(expression) ? types.objectProperty(types.stringLiteral(key), expression) : types.objectMethod(`get`, types.stringLiteral(key), [], types.blockStatement([types.returnStatement(expression)])));
|
|
56
|
+
}
|
|
57
|
+
const children = types.react.buildChildren(node).map((value) => child(value));
|
|
58
|
+
if (children.length) properties.push(types.objectProperty(types.identifier(`children`), children.length === 1 ? children[0] : types.arrayExpression(children)));
|
|
59
|
+
flush();
|
|
60
|
+
const props = chunks.length > 1 ? types.callExpression(merge, chunks) : chunks[0] ?? types.objectExpression([]);
|
|
61
|
+
const result = types.callExpression(create, [types.isJSXElement(node) ? name(node.openingElement.name) : types.nullLiteral(), props]);
|
|
62
|
+
generated.add(result);
|
|
63
|
+
let fn = path.findParent((parent) => parent.isFunction());
|
|
64
|
+
while (fn?.findParent((parent) => parent.isFunction())) fn = fn.findParent((parent) => parent.isFunction());
|
|
65
|
+
if (fn) {
|
|
66
|
+
if (fn.node.id) components.add(fn.node.id.name);
|
|
67
|
+
else if (fn.parentPath.isVariableDeclarator() && types.isIdentifier(fn.parentPath.node.id)) components.add(fn.parentPath.node.id.name);
|
|
68
|
+
else if (fn.parentPath.isExportDefaultDeclaration() && types.isFunctionDeclaration(fn.node)) {
|
|
69
|
+
fn.node.id = path.scope.generateUidIdentifier(`Component`);
|
|
70
|
+
components.add(fn.node.id.name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
path.replaceWith(result);
|
|
74
|
+
} }
|
|
75
|
+
} };
|
|
76
|
+
};
|
|
77
|
+
const result = transformSync(code, {
|
|
78
|
+
filename,
|
|
79
|
+
babelrc: false,
|
|
80
|
+
configFile: false,
|
|
81
|
+
sourceMaps: true,
|
|
82
|
+
parserOpts: { plugins: [`jsx`, `typescript`] },
|
|
83
|
+
plugins: [plugin]
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
code: result.code,
|
|
87
|
+
map: result.map
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// src/vite.ts
|
|
91
|
+
function spa(options = {}) {
|
|
92
|
+
const include = options.include ?? /\.[jt]sx$/;
|
|
93
|
+
const matches = (id) => {
|
|
94
|
+
include.lastIndex = 0;
|
|
95
|
+
return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0]);
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
name: `spa`,
|
|
99
|
+
enforce: `pre`,
|
|
100
|
+
config() {
|
|
101
|
+
return {
|
|
102
|
+
resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
|
|
103
|
+
optimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] }
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
configEnvironment: {
|
|
107
|
+
order: `post`,
|
|
108
|
+
handler(_name, config) {
|
|
109
|
+
if (config.optimizeDeps?.include) config.optimizeDeps.include = config.optimizeDeps.include.filter((id) => !/^(@atom\.io\/spa|atom\.io)(\/|$)/.test(id));
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
transform(code, id) {
|
|
113
|
+
if (!matches(id)) return;
|
|
114
|
+
return compile(code, id);
|
|
115
|
+
},
|
|
116
|
+
handleHotUpdate({ server, file }) {
|
|
117
|
+
if (matches(file)) {
|
|
118
|
+
server.ws.send({ type: `full-reload` });
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export { spa as t };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=vite-BadrFSIM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-BadrFSIM.js","names":["t"],"sources":["../../src/compiler.ts","../../src/vite.ts"],"sourcesContent":["import type { PluginObj } from \"@babel/core\"\nimport { transformSync, types as t } from \"@babel/core\"\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: any } {\n\tconst plugin = (): PluginObj => {\n\t\tlet create: t.Identifier\n\t\tlet merge: t.Identifier\n\t\tconst generated = new WeakSet<object>()\n\t\tconst components = new Set<string>()\n\t\tfunction name(\n\t\t\tnode: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n\t\t): t.Expression {\n\t\t\tif (t.isJSXMemberExpression(node))\n\t\t\t\treturn t.memberExpression(\n\t\t\t\t\tt.isJSXIdentifier(node.object)\n\t\t\t\t\t\t? node.object.name === `this`\n\t\t\t\t\t\t\t? t.thisExpression()\n\t\t\t\t\t\t\t: t.identifier(node.object.name)\n\t\t\t\t\t\t: name(node.object),\n\t\t\t\t\tt.identifier(node.property.name),\n\t\t\t\t)\n\t\t\tif (t.isJSXNamespacedName(node))\n\t\t\t\treturn t.stringLiteral(`${node.namespace.name}:${node.name.name}`)\n\t\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t\t? t.stringLiteral(node.name)\n\t\t\t\t: t.identifier(node.name)\n\t\t}\n\t\tfunction literal(node: t.Node): boolean {\n\t\t\treturn (\n\t\t\t\tt.isLiteral(node) &&\n\t\t\t\t(!t.isTemplateLiteral(node) || node.expressions.length === 0)\n\t\t\t)\n\t\t}\n\t\tfunction child(node: t.Expression): t.Expression {\n\t\t\treturn generated.has(node) || literal(node) || t.isFunction(node)\n\t\t\t\t? node\n\t\t\t\t: t.arrowFunctionExpression([], node)\n\t\t}\n\t\treturn {\n\t\t\tvisitor: {\n\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tt.isArrowFunctionExpression(path.node.declaration) ||\n\t\t\t\t\t\tt.isFunctionExpression(path.node.declaration)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\tpath.replaceWithMultiple([\n\t\t\t\t\t\t\tt.variableDeclaration(`const`, [\n\t\t\t\t\t\t\t\tt.variableDeclarator(id, path.node.declaration),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\tt.exportDefaultDeclaration(id),\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tProgram: {\n\t\t\t\t\tenter(path) {\n\t\t\t\t\t\tcreate = path.scope.generateUidIdentifier(`spa`)\n\t\t\t\t\t\tmerge = path.scope.generateUidIdentifier(`props`)\n\t\t\t\t\t},\n\t\t\t\t\texit(path) {\n\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\tt.importDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tt.importSpecifier(create, t.identifier(`jsx`)),\n\t\t\t\t\t\t\t\t\tt.importSpecifier(merge, t.identifier(`merge`)),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tt.stringLiteral(`@atom.io/spa/jsx-runtime`),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tfor (const component of components)\n\t\t\t\t\t\t\tpath.pushContainer(\n\t\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\t\tt.expressionStatement(\n\t\t\t\t\t\t\t\t\tt.assignmentExpression(\n\t\t\t\t\t\t\t\t\t\t`=`,\n\t\t\t\t\t\t\t\t\t\tt.memberExpression(\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(component),\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(`spa`),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\tt.booleanLiteral(true),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t\"JSXElement|JSXFragment\": {\n\t\t\t\t\texit(path: any) {\n\t\t\t\t\t\tconst node = path.node as t.JSXElement | t.JSXFragment\n\t\t\t\t\t\tconst chunks: t.Expression[] = []\n\t\t\t\t\t\tlet properties: (t.ObjectProperty | t.ObjectMethod)[] = []\n\t\t\t\t\t\tconst flush = () => {\n\t\t\t\t\t\t\tif (properties.length) {\n\t\t\t\t\t\t\t\tchunks.push(t.objectExpression(properties))\n\t\t\t\t\t\t\t\tproperties = []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (t.isJSXElement(node))\n\t\t\t\t\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\t\t\t\t\tif (t.isJSXSpreadAttribute(attribute)) {\n\t\t\t\t\t\t\t\t\tflush()\n\t\t\t\t\t\t\t\t\tchunks.push(t.arrowFunctionExpression([], attribute.argument))\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst key = t.isJSXNamespacedName(attribute.name)\n\t\t\t\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t\t\t\t: attribute.name.name\n\t\t\t\t\t\t\t\tconst value =\n\t\t\t\t\t\t\t\t\tattribute.value == null\n\t\t\t\t\t\t\t\t\t\t? t.booleanLiteral(true)\n\t\t\t\t\t\t\t\t\t\t: t.isJSXExpressionContainer(attribute.value)\n\t\t\t\t\t\t\t\t\t\t\t? attribute.value.expression\n\t\t\t\t\t\t\t\t\t\t\t: attribute.value\n\t\t\t\t\t\t\t\t// The parser rejects empty attribute expressions.\n\t\t\t\t\t\t\t\tconst expression = value as t.Expression\n\t\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\t\tkey === `key` ||\n\t\t\t\t\t\t\t\t\t\tliteral(expression) ||\n\t\t\t\t\t\t\t\t\t\tt.isFunction(expression)\n\t\t\t\t\t\t\t\t\t\t? t.objectProperty(t.stringLiteral(key), expression)\n\t\t\t\t\t\t\t\t\t\t: t.objectMethod(\n\t\t\t\t\t\t\t\t\t\t\t\t`get`,\n\t\t\t\t\t\t\t\t\t\t\t\tt.stringLiteral(key),\n\t\t\t\t\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\t\t\t\t\tt.blockStatement([t.returnStatement(expression)]),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tconst children = t.react\n\t\t\t\t\t\t\t.buildChildren(node)\n\t\t\t\t\t\t\t.map((value) => child(value as t.Expression))\n\t\t\t\t\t\tif (children.length)\n\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\tt.objectProperty(\n\t\t\t\t\t\t\t\t\tt.identifier(`children`),\n\t\t\t\t\t\t\t\t\tchildren.length === 1\n\t\t\t\t\t\t\t\t\t\t? children[0]\n\t\t\t\t\t\t\t\t\t\t: t.arrayExpression(children),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tflush()\n\t\t\t\t\t\tconst props =\n\t\t\t\t\t\t\tchunks.length > 1\n\t\t\t\t\t\t\t\t? t.callExpression(merge, chunks)\n\t\t\t\t\t\t\t\t: (chunks[0] ?? t.objectExpression([]))\n\t\t\t\t\t\tconst result = t.callExpression(create, [\n\t\t\t\t\t\t\tt.isJSXElement(node)\n\t\t\t\t\t\t\t\t? name(node.openingElement.name)\n\t\t\t\t\t\t\t\t: t.nullLiteral(),\n\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t])\n\t\t\t\t\t\tgenerated.add(result)\n\t\t\t\t\t\tlet fn = path.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\twhile (fn?.findParent((parent: any) => parent.isFunction()))\n\t\t\t\t\t\t\tfn = fn.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\tif (fn) {\n\t\t\t\t\t\t\tif (fn.node.id) components.add(fn.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isVariableDeclarator() &&\n\t\t\t\t\t\t\t\tt.isIdentifier(fn.parentPath.node.id)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tcomponents.add(fn.parentPath.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isExportDefaultDeclaration() &&\n\t\t\t\t\t\t\t\tt.isFunctionDeclaration(fn.node)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tfn.node.id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpath.replaceWith(result)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\tconst result = transformSync(code, {\n\t\tfilename,\n\t\tbabelrc: false,\n\t\tconfigFile: false,\n\t\tsourceMaps: true,\n\t\tparserOpts: { plugins: [`jsx`, `typescript`] },\n\t\tplugins: [plugin],\n\t})!\n\treturn { code: result.code!, map: result.map }\n}\n","import type { Plugin } from \"vite\"\n\nimport { compile } from \"./compiler.ts\"\n\nexport interface SpaPluginOptions {\n\tinclude?: RegExp\n}\nexport default function spa(options: SpaPluginOptions = {}): Plugin {\n\tconst include = options.include ?? /\\.[jt]sx$/\n\tconst matches = (id: string): boolean => {\n\t\tinclude.lastIndex = 0\n\t\treturn !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])\n\t}\n\treturn {\n\t\tname: `spa`,\n\t\tenforce: `pre`,\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\tresolve: { dedupe: [`@atom.io/spa`, `atom.io`] },\n\t\t\t\toptimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] },\n\t\t\t}\n\t\t},\n\t\tconfigEnvironment: {\n\t\t\torder: `post`,\n\t\t\thandler(_name, config) {\n\t\t\t\t// Astro and its adapters force renderer entries into the optimizer.\n\t\t\t\t// Vite processes explicit includes even when their package is excluded.\n\t\t\t\t// Keep the renderer, hooks, and store in one unbundled module graph.\n\t\t\t\tif (config.optimizeDeps?.include) {\n\t\t\t\t\tconfig.optimizeDeps.include = config.optimizeDeps.include.filter(\n\t\t\t\t\t\t(id) => !/^(@atom\\.io\\/spa|atom\\.io)(\\/|$)/.test(id),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\ttransform(code, id) {\n\t\t\tif (!matches(id)) return\n\t\t\treturn compile(code, id)\n\t\t},\n\t\t// A reload disposes the whole document. No state-preserving HMR is promised.\n\t\thandleHotUpdate({ server, file }) {\n\t\t\tif (matches(file)) {\n\t\t\t\tserver.ws.send({ type: `full-reload` })\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;AAGA,SAAgB,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AAM;GACxB,EACD;EACD,EACD;CACD;CACA,MAAM,SAAS,cAAc,MAAM;EAClC;EACA,SAAS;EACT,YAAY;EACZ,YAAY;EACZ,YAAY,EAAE,SAAS,CAAC,OAAO,YAAY,EAAE;EAC7C,SAAS,CAAC,MAAM;CACjB,CAAC;CACD,OAAO;EAAE,MAAM,OAAO;EAAO,KAAK,OAAO;CAAI;AAC9C;;ACrLA,SAAwB,IAAI,UAA4B,CAAC,GAAW;CACnE,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,WAAW,OAAwB;EACxC,QAAQ,YAAY;EACpB,OAAO,CAAC,GAAG,SAAS,gBAAgB,KAAK,QAAQ,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE;CACvE;CACA,OAAO;EACN,MAAM;EACN,SAAS;EACT,SAAS;GACR,OAAO;IACN,SAAS,EAAE,QAAQ,CAAC,gBAAgB,SAAS,EAAE;IAC/C,cAAc,EAAE,SAAS,CAAC,gBAAgB,SAAS,EAAE;GACtD;EACD;EACA,mBAAmB;GAClB,OAAO;GACP,QAAQ,OAAO,QAAQ;IAItB,IAAI,OAAO,cAAc,SACxB,OAAO,aAAa,UAAU,OAAO,aAAa,QAAQ,QACxD,OAAO,CAAC,mCAAmC,KAAK,EAAE,CACpD;GAEF;EACD;EACA,UAAU,MAAM,IAAI;GACnB,IAAI,CAAC,QAAQ,EAAE,GAAG;GAClB,OAAO,QAAQ,MAAM,EAAE;EACxB;EAEA,gBAAgB,EAAE,QAAQ,QAAQ;GACjC,IAAI,QAAQ,IAAI,GAAG;IAClB,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IACtC,OAAO,CAAC;GACT;EACD;CACD;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as default } from "./vite-BadrFSIM.js";
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { a as invalidate, b as within, f as untrack, i as fail, n as createScope, o as observe, r as dispose, t as createRoot, u as plain } from "./core-Dvqm7w2y.js";
|
|
2
|
+
import { Fragment, merge } from "./jsx-runtime.js";
|
|
3
|
+
// src/dom.ts
|
|
4
|
+
const HTML = `http://www.w3.org/1999/xhtml`;
|
|
5
|
+
const SVG = `http://www.w3.org/2000/svg`;
|
|
6
|
+
function take(node, parent, before, owner, cursor) {
|
|
7
|
+
if (cursor && !(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)) {
|
|
8
|
+
const found = cursor.node;
|
|
9
|
+
if (!found || found.nodeType !== node.nodeType || found.nodeName !== node.nodeName || found.namespaceURI !== node.namespaceURI || node.nodeType !== 1 && found.nodeValue !== node.nodeValue) throw new Error(void 0);
|
|
10
|
+
node = found;
|
|
11
|
+
cursor.node = found.nextSibling;
|
|
12
|
+
} else parent.insertBefore(node, cursor ? cursor.node : before);
|
|
13
|
+
owner._cleanups.add(() => {
|
|
14
|
+
node.remove();
|
|
15
|
+
});
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
function comment(value, parent, before, owner, cursor) {
|
|
19
|
+
return take(parent.ownerDocument.createComment(value), parent, before, owner, cursor);
|
|
20
|
+
}
|
|
21
|
+
function property(element, key, value, previous) {
|
|
22
|
+
if (/^(key|children|ref)$/.test(key)) return;
|
|
23
|
+
if (key === `innerHTML` && element.localName === `astro-slot`) return;
|
|
24
|
+
if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(void 0);
|
|
25
|
+
if (key.startsWith(`on`)) {
|
|
26
|
+
const capture = /(?<!Pointer)Capture$/.test(key);
|
|
27
|
+
const event = key.slice(2, capture ? -7 : void 0).toLowerCase().replace(`doubleclick`, `dblclick`);
|
|
28
|
+
if (previous) element.removeEventListener(event, previous, capture);
|
|
29
|
+
if (value != null) element.addEventListener(event, value, capture);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (key === `className`) key = `class`;
|
|
33
|
+
if (key === `htmlFor`) key = `for`;
|
|
34
|
+
if (element.namespaceURI === HTML && key in element && !/^(style|form|list)$/.test(key)) {
|
|
35
|
+
const target = element;
|
|
36
|
+
target[key] = value ?? (typeof target[key] === `boolean` ? false : ``);
|
|
37
|
+
} else if (value == null || value === false && !/^(aria-|data-)/.test(key)) element.removeAttribute(key);
|
|
38
|
+
else element.setAttribute(key, value === true && !/^(aria-|data-)/.test(key) ? `` : String(value));
|
|
39
|
+
}
|
|
40
|
+
function mount(value, parent, before, owner, namespace, cursor, source = () => value) {
|
|
41
|
+
if (typeof value === `function`) {
|
|
42
|
+
comment(`{`, parent, before, owner, cursor);
|
|
43
|
+
let end = null;
|
|
44
|
+
let records = /* @__PURE__ */ new Map();
|
|
45
|
+
let initial = cursor;
|
|
46
|
+
observe(owner, () => source()(), (next) => {
|
|
47
|
+
const values = [next].flat(Infinity);
|
|
48
|
+
const kept = /* @__PURE__ */ new Map();
|
|
49
|
+
const focus = parent.ownerDocument.activeElement;
|
|
50
|
+
for (let index = 0; index < values.length; index++) {
|
|
51
|
+
const child = values[index];
|
|
52
|
+
const vnode = child;
|
|
53
|
+
const explicit = vnode?.props?.[`key`];
|
|
54
|
+
const key = explicit == null ? index : String(explicit);
|
|
55
|
+
let record = records.get(key);
|
|
56
|
+
if (record && (typeof record._value !== typeof child || record._value?.type !== vnode?.type)) {
|
|
57
|
+
dispose(record._scope);
|
|
58
|
+
record = void 0;
|
|
59
|
+
}
|
|
60
|
+
if (!record) {
|
|
61
|
+
const childOwner = createScope(owner);
|
|
62
|
+
record = {
|
|
63
|
+
_value: child,
|
|
64
|
+
_scope: childOwner,
|
|
65
|
+
_start: comment(`[`, parent, end ?? before, childOwner, initial),
|
|
66
|
+
_end: null
|
|
67
|
+
};
|
|
68
|
+
const held = record;
|
|
69
|
+
mount(child, parent, end ?? before, childOwner, namespace, initial, () => held._value);
|
|
70
|
+
record._end = comment(`]`, parent, end ?? before, childOwner, initial);
|
|
71
|
+
} else {
|
|
72
|
+
record._value = child;
|
|
73
|
+
invalidate(record._scope);
|
|
74
|
+
}
|
|
75
|
+
kept.set(key, record);
|
|
76
|
+
}
|
|
77
|
+
for (const [key, record] of records) if (!kept.has(key)) dispose(record._scope);
|
|
78
|
+
if (!initial) {
|
|
79
|
+
let at = end ?? before;
|
|
80
|
+
for (const record of [...kept.values()].reverse()) {
|
|
81
|
+
if (record._end.nextSibling !== at) {
|
|
82
|
+
const range = parent.ownerDocument.createRange();
|
|
83
|
+
range.setStartBefore(record._start);
|
|
84
|
+
range.setEndAfter(record._end);
|
|
85
|
+
parent.insertBefore(range.extractContents(), at);
|
|
86
|
+
}
|
|
87
|
+
at = record._start;
|
|
88
|
+
}
|
|
89
|
+
if (focus?.isConnected && focus !== parent.ownerDocument.activeElement) focus.focus({ preventScroll: true });
|
|
90
|
+
}
|
|
91
|
+
initial = void 0;
|
|
92
|
+
records = kept;
|
|
93
|
+
});
|
|
94
|
+
end = comment(`}`, parent, before, owner, cursor);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(value)) {
|
|
98
|
+
for (const child of value) mount(child, parent, before, owner, namespace, cursor);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (value == null || typeof value === `boolean`) return;
|
|
102
|
+
if (typeof value !== `object`) {
|
|
103
|
+
comment(`t`, parent, before, owner, cursor);
|
|
104
|
+
const text = take(parent.ownerDocument.createTextNode(String(value)), parent, before, owner, cursor);
|
|
105
|
+
observe(owner, source, (next) => {
|
|
106
|
+
const data = String(next);
|
|
107
|
+
if (text.nodeValue !== data) text.nodeValue = data;
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const vnode = value;
|
|
112
|
+
const props = merge(() => source().props);
|
|
113
|
+
if (!vnode.type || vnode.type === Fragment) {
|
|
114
|
+
mount(() => props[`children`], parent, before, owner, namespace, cursor);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (typeof vnode.type === `function`) {
|
|
118
|
+
const childOwner = createScope(owner);
|
|
119
|
+
mount(within(childOwner, () => untrack(() => vnode.type(props))), parent, before, childOwner, namespace, cursor);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const ns = vnode.type === `svg` ? SVG : namespace;
|
|
123
|
+
const element = take(parent.ownerDocument.createElementNS(ns, vnode.type), parent, before, owner, cursor);
|
|
124
|
+
if (vnode.type === `astro-slot`) {
|
|
125
|
+
if (!cursor) element.innerHTML = props[`innerHTML`] ?? ``;
|
|
126
|
+
} else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) observe(owner, () => plain(vnode.type === `textarea` ? props[`value`] ?? props[`children`] : props[`children`]), (text) => {
|
|
127
|
+
if (element.textContent !== text) element.textContent = text;
|
|
128
|
+
});
|
|
129
|
+
else {
|
|
130
|
+
const children = cursor ? { node: element.firstChild } : void 0;
|
|
131
|
+
if (!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(vnode.type) || ns !== HTML) mount(() => props[`children`], element, null, owner, vnode.type === `foreignObject` ? HTML : ns, children);
|
|
132
|
+
if (children?.node) throw new Error(void 0);
|
|
133
|
+
}
|
|
134
|
+
let previous = {};
|
|
135
|
+
owner._cleanups.add(() => {
|
|
136
|
+
for (const key in previous) if (key.startsWith(`on`)) property(element, key, null, previous[key]);
|
|
137
|
+
});
|
|
138
|
+
observe(owner, () => ({ ...props }), (next) => {
|
|
139
|
+
for (const key in {
|
|
140
|
+
...previous,
|
|
141
|
+
...next
|
|
142
|
+
}) if (!Object.is(previous[key], next[key]) || typeof next[key] === `object`) {
|
|
143
|
+
property(element, key, next[key], previous[key]);
|
|
144
|
+
previous[key] = next[key];
|
|
145
|
+
}
|
|
146
|
+
previous = next;
|
|
147
|
+
});
|
|
148
|
+
const ref = untrack(() => props[`ref`]);
|
|
149
|
+
if (ref) owner._root._mounts.unshift(() => {
|
|
150
|
+
if (!owner._dead) {
|
|
151
|
+
owner._cleanups.add(() => ref(null));
|
|
152
|
+
ref(element);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function start(setup, host, options, hydrating) {
|
|
157
|
+
const cursor = hydrating ? { node: host.firstChild } : void 0;
|
|
158
|
+
const prefix = cursor?.node?.nodeValue?.slice(2);
|
|
159
|
+
if (hydrating && (prefix === void 0 || options.idPrefix !== void 0 && prefix !== options.idPrefix)) throw new Error(void 0);
|
|
160
|
+
const root = createRoot(options);
|
|
161
|
+
if (prefix !== void 0) root._prefix = prefix;
|
|
162
|
+
try {
|
|
163
|
+
comment(`w:${root._prefix}`, host, null, root, cursor);
|
|
164
|
+
within(root, () => {
|
|
165
|
+
mount(untrack(setup), host, null, root, host.namespaceURI === SVG ? SVG : HTML, cursor);
|
|
166
|
+
});
|
|
167
|
+
comment(`/w`, host, null, root, cursor);
|
|
168
|
+
if (cursor?.node) throw new Error(void 0);
|
|
169
|
+
root.flush();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
fail(root, error);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
dispose: () => {
|
|
175
|
+
dispose(root);
|
|
176
|
+
},
|
|
177
|
+
flush: root.flush
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function render(setup, host, options = {}) {
|
|
181
|
+
return start(setup, host, options, false);
|
|
182
|
+
}
|
|
183
|
+
function hydrate(setup, host, options = {}) {
|
|
184
|
+
return start(setup, host, options, true);
|
|
185
|
+
}
|
|
186
|
+
export { render as n, hydrate as t };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=dom-BR9o9wZW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-BR9o9wZW.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { Accessor, Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nconst HTML = `http://www.w3.org/1999/xhtml`\nconst SVG = `http://www.w3.org/2000/svg`\ntype Cursor = { node: Node | null }\ntype RecordNode = { _value: Child; _scope: Scope; _start: Node; _end: Node }\n\nfunction take(\n\tnode: Node,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\tif (\n\t\tcursor &&\n\t\t!(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)\n\t) {\n\t\tconst found = cursor.node\n\t\tif (\n\t\t\t!found ||\n\t\t\tfound.nodeType !== node.nodeType ||\n\t\t\tfound.nodeName !== node.nodeName ||\n\t\t\t(found as Element).namespaceURI !== (node as Element).namespaceURI ||\n\t\t\t(node.nodeType !== 1 && found.nodeValue !== node.nodeValue)\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\tnode = found\n\t\tcursor.node = found.nextSibling\n\t} else parent.insertBefore(node, cursor ? cursor.node : before)\n\towner._cleanups.add(() => {\n\t\t;(node as ChildNode).remove()\n\t})\n\treturn node\n}\nfunction comment(\n\tvalue: string,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\treturn take(\n\t\tparent.ownerDocument!.createComment(value),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t)\n}\nfunction property(\n\telement: Element,\n\tkey: string,\n\tvalue: any,\n\tprevious: any,\n): void {\n\tif (/^(key|children|ref)$/.test(key)) return\n\tif (key === `innerHTML` && element.localName === `astro-slot`) return\n\tif (\n\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\tkey,\n\t\t)\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: owned content` : undefined)\n\tif (key.startsWith(`on`)) {\n\t\tconst capture = /(?<!Pointer)Capture$/.test(key)\n\t\tconst event = key\n\t\t\t.slice(2, capture ? -7 : undefined)\n\t\t\t.toLowerCase()\n\t\t\t.replace(`doubleclick`, `dblclick`)\n\t\tif (previous) element.removeEventListener(event, previous, capture)\n\t\tif (value != null) {\n\t\t\tif (import.meta.env.DEV && typeof value !== `function`)\n\t\t\t\tthrow new Error(`spa: event handler`)\n\t\t\telement.addEventListener(event, value, capture)\n\t\t}\n\t\treturn\n\t}\n\tif (key === `className`) key = `class`\n\tif (key === `htmlFor`) key = `for`\n\tif (\n\t\timport.meta.env.DEV &&\n\t\tkey === `style` &&\n\t\tvalue != null &&\n\t\ttypeof value !== `string`\n\t)\n\t\tthrow new Error(`spa: CSS string required`)\n\tif (\n\t\telement.namespaceURI === HTML &&\n\t\tkey in element &&\n\t\t!/^(style|form|list)$/.test(key)\n\t) {\n\t\tconst target = element as any\n\t\ttarget[key] = value ?? (typeof target[key] === `boolean` ? false : ``)\n\t} else if (value == null || (value === false && !/^(aria-|data-)/.test(key)))\n\t\telement.removeAttribute(key)\n\telse\n\t\telement.setAttribute(\n\t\t\tkey,\n\t\t\tvalue === true && !/^(aria-|data-)/.test(key) ? `` : String(value),\n\t\t)\n}\n\nfunction mount(\n\tvalue: Child,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tnamespace: string,\n\tcursor?: Cursor,\n\tsource = () => value,\n): void {\n\tif (typeof value === `function`) {\n\t\tcomment(`{`, parent, before, owner, cursor)\n\t\tlet end: Node | null = null\n\t\tlet records = new Map<unknown, RecordNode>()\n\t\tlet initial = cursor\n\t\tobserve(\n\t\t\towner,\n\t\t\t() => (source() as () => Child)(),\n\t\t\t(next) => {\n\t\t\t\tconst values = ([next] as unknown[]).flat(Infinity) as Child[]\n\t\t\t\tconst kept = new Map<unknown, RecordNode>()\n\t\t\t\tconst focus = parent.ownerDocument!.activeElement as HTMLElement | null\n\t\t\t\tfor (let index = 0; index < values.length; index++) {\n\t\t\t\t\tconst child = values[index]\n\t\t\t\t\tconst vnode = child as VNode | null\n\t\t\t\t\tconst explicit = vnode?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (import.meta.env.DEV && kept.has(key))\n\t\t\t\t\t\tthrow new Error(`spa: duplicate key`)\n\t\t\t\t\tlet record = records.get(key)\n\t\t\t\t\tif (\n\t\t\t\t\t\trecord &&\n\t\t\t\t\t\t(typeof record._value !== typeof child ||\n\t\t\t\t\t\t\t(record._value as VNode | null)?.type !== vnode?.type)\n\t\t\t\t\t) {\n\t\t\t\t\t\tdispose(record._scope)\n\t\t\t\t\t\trecord = undefined\n\t\t\t\t\t}\n\t\t\t\t\tif (!record) {\n\t\t\t\t\t\tconst childOwner = createScope(owner)\n\t\t\t\t\t\trecord = {\n\t\t\t\t\t\t\t_value: child,\n\t\t\t\t\t\t\t_scope: childOwner,\n\t\t\t\t\t\t\t_start: comment(`[`, parent, end ?? before, childOwner, initial),\n\t\t\t\t\t\t\t_end: null!,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst held = record\n\t\t\t\t\t\tmount(\n\t\t\t\t\t\t\tchild,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t\t() => held._value,\n\t\t\t\t\t\t)\n\t\t\t\t\t\trecord._end = comment(\n\t\t\t\t\t\t\t`]`,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trecord._value = child\n\t\t\t\t\t\tinvalidate(record._scope)\n\t\t\t\t\t}\n\t\t\t\t\tkept.set(key, record)\n\t\t\t\t}\n\t\t\t\tfor (const [key, record] of records)\n\t\t\t\t\tif (!kept.has(key)) dispose(record._scope)\n\t\t\t\tif (!initial) {\n\t\t\t\t\tlet at = end ?? before\n\t\t\t\t\tfor (const record of [...kept.values()].reverse()) {\n\t\t\t\t\t\tif (record._end.nextSibling !== at) {\n\t\t\t\t\t\t\tconst range = parent.ownerDocument!.createRange()\n\t\t\t\t\t\t\trange.setStartBefore(record._start)\n\t\t\t\t\t\t\trange.setEndAfter(record._end)\n\t\t\t\t\t\t\tparent.insertBefore(range.extractContents(), at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tat = record._start\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocus?.isConnected &&\n\t\t\t\t\t\tfocus !== parent.ownerDocument!.activeElement\n\t\t\t\t\t)\n\t\t\t\t\t\tfocus.focus({ preventScroll: true })\n\t\t\t\t}\n\t\t\t\tinitial = undefined\n\t\t\t\trecords = kept\n\t\t\t},\n\t\t)\n\t\tend = comment(`}`, parent, before, owner, cursor)\n\t\treturn\n\t}\n\tif (Array.isArray(value)) {\n\t\tfor (const child of value)\n\t\t\tmount(child, parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (value == null || typeof value === `boolean`) return\n\tif (typeof value !== `object`) {\n\t\tcomment(`t`, parent, before, owner, cursor)\n\t\tconst text = take(\n\t\t\tparent.ownerDocument!.createTextNode(String(value)),\n\t\t\tparent,\n\t\t\tbefore,\n\t\t\towner,\n\t\t\tcursor,\n\t\t)\n\t\tobserve(owner, source as Accessor<string | number | bigint>, (next) => {\n\t\t\tconst data = String(next)\n\t\t\tif (text.nodeValue !== data) text.nodeValue = data\n\t\t})\n\t\treturn\n\t}\n\tif (import.meta.env.DEV && (!(`type` in value) || !(`props` in value)))\n\t\tthrow new Error(`spa: invalid child`)\n\tconst vnode = value as VNode\n\tconst props = merge(() => (source() as VNode).props)\n\tif (!vnode.type || vnode.type === Fragment) {\n\t\tmount(() => props[`children`], parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (typeof vnode.type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\tconst output = within(childOwner, () =>\n\t\t\tuntrack(() => (vnode.type as Function)(props)),\n\t\t)\n\t\tmount(output, parent, before, childOwner, namespace, cursor)\n\t\treturn\n\t}\n\tconst ns = vnode.type === `svg` ? SVG : namespace\n\tconst element = take(\n\t\tparent.ownerDocument!.createElementNS(ns, vnode.type),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t) as Element\n\tif (vnode.type === `astro-slot`) {\n\t\tif (!cursor) element.innerHTML = props[`innerHTML`] ?? ``\n\t} else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) {\n\t\tobserve(\n\t\t\towner,\n\t\t\t() =>\n\t\t\t\tplain(\n\t\t\t\t\tvnode.type === `textarea`\n\t\t\t\t\t\t? (props[`value`] ?? props[`children`])\n\t\t\t\t\t\t: props[`children`],\n\t\t\t\t),\n\t\t\t(text) => {\n\t\t\t\tif (element.textContent !== text) element.textContent = text\n\t\t\t},\n\t\t)\n\t} else {\n\t\tconst children = cursor ? { node: element.firstChild } : undefined\n\t\tif (\n\t\t\t!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(\n\t\t\t\tvnode.type,\n\t\t\t) ||\n\t\t\tns !== HTML\n\t\t)\n\t\t\tmount(\n\t\t\t\t() => props[`children`],\n\t\t\t\telement,\n\t\t\t\tnull,\n\t\t\t\towner,\n\t\t\t\tvnode.type === `foreignObject` ? HTML : ns,\n\t\t\t\tchildren,\n\t\t\t)\n\t\tif (children?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t}\n\tlet previous: Record<string, any> = {}\n\towner._cleanups.add(() => {\n\t\tfor (const key in previous)\n\t\t\tif (key.startsWith(`on`)) property(element, key, null, previous[key])\n\t})\n\tobserve(\n\t\towner,\n\t\t() => ({ ...props }),\n\t\t(next) => {\n\t\t\tfor (const key in { ...previous, ...next })\n\t\t\t\tif (\n\t\t\t\t\t!Object.is(previous[key], next[key]) ||\n\t\t\t\t\ttypeof next[key] === `object`\n\t\t\t\t) {\n\t\t\t\t\tproperty(element, key, next[key], previous[key])\n\t\t\t\t\tprevious[key] = next[key]\n\t\t\t\t}\n\t\t\tprevious = next\n\t\t},\n\t)\n\tconst ref = untrack(() => props[`ref`])\n\tif (ref) {\n\t\towner._root._mounts!.unshift(() => {\n\t\t\tif (!owner._dead) {\n\t\t\t\towner._cleanups.add(() => ref(null))\n\t\t\t\tref(element)\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport interface SpaRoot {\n\tdispose(): void\n\tflush(): void\n}\nfunction start(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions,\n\thydrating: boolean,\n): SpaRoot {\n\tconst cursor = hydrating ? { node: host.firstChild } : undefined\n\tconst prefix = cursor?.node?.nodeValue?.slice(2)\n\tif (\n\t\thydrating &&\n\t\t(prefix === undefined ||\n\t\t\t(options.idPrefix !== undefined && prefix !== options.idPrefix))\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: hydration mismatch` : undefined)\n\tconst root = createRoot(options)\n\tif (prefix !== undefined) root._prefix = prefix\n\ttry {\n\t\tcomment(`w:${root._prefix}`, host, null, root, cursor)\n\t\twithin(root, () => {\n\t\t\tmount(\n\t\t\t\tuntrack(setup),\n\t\t\t\thost,\n\t\t\t\tnull,\n\t\t\t\troot,\n\t\t\t\thost.namespaceURI === SVG ? SVG : HTML,\n\t\t\t\tcursor,\n\t\t\t)\n\t\t})\n\t\tcomment(`/w`, host, null, root, cursor)\n\t\tif (cursor?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\troot.flush()\n\t} catch (error) {\n\t\tfail(root, error)\n\t}\n\treturn {\n\t\tdispose: () => {\n\t\t\tdispose(root)\n\t\t},\n\t\tflush: root.flush,\n\t}\n}\nexport function render(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, false)\n}\nexport function hydrate(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, true)\n}\n"],"mappings":";;;AAcA,MAAM,OAAO;AACb,MAAM,MAAM;AAIZ,SAAS,KACR,MACA,QACA,QACA,OACA,QACO;CACP,IACC,UACA,EAAE,KAAK,aAAa,KAAK,CAAC,KAAK,aAAa,OAAO,MAAM,aAAa,IACrE;EACD,MAAM,QAAQ,OAAO;EACrB,IACC,CAAC,SACD,MAAM,aAAa,KAAK,YACxB,MAAM,aAAa,KAAK,YACvB,MAAkB,iBAAkB,KAAiB,gBACrD,KAAK,aAAa,KAAK,MAAM,cAAc,KAAK,WAEjD,MAAM,IAAI,MACyC,KAAA,CACnD;EACD,OAAO;EACP,OAAO,OAAO,MAAM;CACrB,OAAO,OAAO,aAAa,MAAM,SAAS,OAAO,OAAO,MAAM;CAC9D,MAAM,UAAU,UAAU;EACxB,KAAoB,OAAO;CAC7B,CAAC;CACD,OAAO;AACR;AACA,SAAS,QACR,OACA,QACA,QACA,OACA,QACO;CACP,OAAO,KACN,OAAO,cAAe,cAAc,KAAK,GACzC,QACA,QACA,OACA,MACD;AACD;AACA,SAAS,SACR,SACA,KACA,OACA,UACO;CACP,IAAI,uBAAuB,KAAK,GAAG,GAAG;CACtC,IAAI,QAAQ,eAAe,QAAQ,cAAc,cAAc;CAC/D,IACC,wEAAwE,KACvE,GACD,GAEA,MAAM,IAAI,MAAmD,KAAA,CAAS;CACvE,IAAI,IAAI,WAAW,IAAI,GAAG;EACzB,MAAM,UAAU,uBAAuB,KAAK,GAAG;EAC/C,MAAM,QAAQ,IACZ,MAAM,GAAG,UAAU,KAAK,KAAA,CAAS,CAAC,CAClC,YAAY,CAAC,CACb,QAAQ,eAAe,UAAU;EACnC,IAAI,UAAU,QAAQ,oBAAoB,OAAO,UAAU,OAAO;EAClE,IAAI,SAAS,MAGZ,QAAQ,iBAAiB,OAAO,OAAO,OAAO;EAE/C;CACD;CACA,IA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b;EACA,OAAO,KAAK;CACb;AACD;AACA,SAAgB,OACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,KAAK;AACzC;AACA,SAAgB,QACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,IAAI;AACxC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { a as TimelineValue, c as onMount, d as useSetter, f as useStore, h as useValue, i as RootOptions, l as useId, m as useTransaction, n as Child, o as VNode, p as useTimeline, r as Component, s as onCleanup, t as Accessor, u as useRef } from "./core-BhiA9fFi.js";
|
|
2
|
+
import { t as Fragment } from "./jsx-runtime-BzGV18VO.js";
|
|
3
|
+
import { Loadable, ReadableFamilyToken, ReadableToken, ViewOf } from "atom.io";
|
|
4
|
+
import { Canonical } from "atom.io/foundations/canonical";
|
|
5
|
+
interface SpaRoot {
|
|
6
|
+
dispose(): void;
|
|
7
|
+
flush(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function render(setup: () => Child, host: Element, options?: RootOptions): SpaRoot;
|
|
10
|
+
export declare function hydrate(setup: () => Child, host: Element, options?: RootOptions): SpaRoot;
|
|
11
|
+
type LoadableValue<T> = {
|
|
12
|
+
loading: boolean;
|
|
13
|
+
value: T;
|
|
14
|
+
};
|
|
15
|
+
export declare function useLoadable<T, E>(token: ReadableToken<Loadable<T>, any, E>): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>;
|
|
16
|
+
export declare function useLoadable<T, K extends Canonical, E>(token: ReadableFamilyToken<Loadable<T>, K, E>, key: NoInfer<K>): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>;
|
|
17
|
+
export declare function useLoadable<T, E>(token: ReadableToken<Loadable<T>, any, E>, fallback: NoInfer<T>): Accessor<LoadableValue<ViewOf<T>> & {
|
|
18
|
+
error?: E;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function useLoadable<T, K extends Canonical, E>(token: ReadableFamilyToken<Loadable<T>, K, E>, key: NoInfer<K>, fallback: NoInfer<T>): Accessor<LoadableValue<ViewOf<T>> & {
|
|
21
|
+
error?: E;
|
|
22
|
+
}>;
|
|
23
|
+
export { type Accessor, type Child, type Component, Fragment, type LoadableValue, type RootOptions, type SpaRoot, type TimelineValue, type VNode, onCleanup, onMount, useId, useRef, useSetter, useStore, useTimeline, useTransaction, useValue };
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|