@atom.io/spa 0.0.3 → 0.0.5
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/README.md +202 -138
- package/README.mdx +62 -26
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +3 -2
- package/dist/astro-client.d.ts.map +1 -1
- package/dist/astro-client.js +11 -10
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +10 -0
- package/dist/astro-resumability-client.d.ts.map +1 -0
- package/dist/astro-resumability-client.js +29 -0
- package/dist/astro-resumability-client.js.map +1 -0
- package/dist/astro-resumability-server.d.ts +3 -0
- package/dist/astro-resumability-server.d.ts.map +1 -0
- package/dist/astro-resumability-server.js +7 -0
- package/dist/astro-resumability-server.js.map +1 -0
- package/dist/astro-server.d.ts +3 -2
- package/dist/astro-server.d.ts.map +1 -1
- package/dist/astro-server.js +28 -9
- package/dist/astro-server.js.map +1 -1
- package/dist/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
- package/dist/astro-shared-83hxw7-M.js.map +1 -0
- package/dist/{astro-shared-BkWvVZWZ.d.ts → astro-shared-DHIpjNIG.d.ts} +2 -2
- package/dist/{astro-shared-BkWvVZWZ.d.ts.map → astro-shared-DHIpjNIG.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +5 -7
- package/dist/astro.js.map +1 -1
- package/dist/{capabilities-CFP-HIuY.d.ts → capabilities-BCtBG-ni.d.ts} +19 -14
- package/dist/capabilities-BCtBG-ni.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/{core-DCmqLZQP.js → core-DjFJ0aIJ.js} +31 -23
- package/dist/core-DjFJ0aIJ.js.map +1 -0
- package/dist/development/astro-client.js +11 -10
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-resumability-client.js +29 -0
- package/dist/development/astro-resumability-client.js.map +1 -0
- package/dist/development/astro-resumability-server.js +7 -0
- package/dist/development/astro-resumability-server.js.map +1 -0
- package/dist/development/astro-server.js +28 -9
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
- package/dist/development/astro-shared-83hxw7-M.js.map +1 -0
- package/dist/development/astro.js +5 -7
- package/dist/development/astro.js.map +1 -1
- package/dist/development/{core-p9vciX9C.js → core-DxPiKryn.js} +31 -23
- package/dist/development/core-DxPiKryn.js.map +1 -0
- package/dist/development/{dom-Ci1XvbVJ.js → dom-BytVV6Rp.js} +44 -12
- package/dist/development/dom-BytVV6Rp.js.map +1 -0
- package/dist/development/index.js +4 -4
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +1 -1
- package/dist/development/konva.js.map +1 -1
- package/dist/development/motion.js +1 -1
- package/dist/development/renderer.js +1 -1
- package/dist/development/renderer.js.map +1 -1
- package/dist/development/server-renderer-CUQXh9oF.js +90 -0
- package/dist/development/server-renderer-CUQXh9oF.js.map +1 -0
- package/dist/development/server.js +2 -83
- package/dist/development/server.js.map +1 -1
- package/dist/{src-DCQa6qxs.js → development/src-WSHJxR9b.js} +4 -4
- package/dist/development/src-WSHJxR9b.js.map +1 -0
- package/dist/development/three.js +1 -1
- package/dist/development/three.js.map +1 -1
- package/dist/{dom-dHQM0O7Q.js → dom-B5OxgHkr.js} +44 -12
- package/dist/dom-B5OxgHkr.js.map +1 -0
- package/dist/{index-CJJXcKaw.d.ts → index-DufwkB6W.d.ts} +5 -5
- package/dist/{index-CJJXcKaw.d.ts.map → index-DufwkB6W.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/{jsx-runtime-CREZYKDC.d.ts → jsx-runtime-DMDVr7A5.d.ts} +7 -7
- package/dist/{jsx-runtime-CREZYKDC.d.ts.map → jsx-runtime-DMDVr7A5.d.ts.map} +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +16 -16
- package/dist/konva.js +1 -1
- package/dist/konva.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +1 -1
- package/dist/renderer.d.ts +4 -4
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +1 -1
- package/dist/renderer.js.map +1 -1
- package/dist/server-renderer-DcU55e6s.js +90 -0
- package/dist/server-renderer-DcU55e6s.js.map +1 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -83
- package/dist/server.js.map +1 -1
- package/dist/size.json +16 -16
- package/dist/{development/src-DG0xjuS5.js → src-DWIqXCiz.js} +4 -4
- package/dist/src-DWIqXCiz.js.map +1 -0
- package/dist/three.d.ts +17 -17
- package/dist/three.js +1 -1
- package/dist/three.js.map +1 -1
- package/package.json +27 -11
- package/src/astro-client.ts +20 -7
- package/src/astro-resumability-client.ts +40 -0
- package/src/astro-resumability-server.ts +7 -0
- package/src/astro-server.ts +58 -19
- package/src/astro-shared.ts +5 -2
- package/src/astro.ts +11 -3
- package/src/core.ts +54 -49
- package/src/dom.ts +73 -39
- package/src/index.ts +4 -4
- package/src/jsx-runtime.ts +7 -6
- package/src/jsx-types.d.ts +2 -2
- package/src/konva.ts +3 -3
- package/src/renderer.ts +24 -18
- package/src/server-renderer.ts +162 -0
- package/src/server.ts +4 -153
- package/src/three.ts +4 -4
- package/src/use-loadable.ts +3 -3
- package/dist/astro-shared-BT45auwR.js.map +0 -1
- package/dist/capabilities-CFP-HIuY.d.ts.map +0 -1
- package/dist/core-DCmqLZQP.js.map +0 -1
- package/dist/development/astro-shared-BT45auwR.js.map +0 -1
- package/dist/development/core-p9vciX9C.js.map +0 -1
- package/dist/development/dom-Ci1XvbVJ.js.map +0 -1
- package/dist/development/src-DG0xjuS5.js.map +0 -1
- package/dist/dom-dHQM0O7Q.js.map +0 -1
- package/dist/src-DCQa6qxs.js.map +0 -1
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as jsxDEV, c as AriaAttributes, d as EventHandler, f as HTMLAttributes, h as TargetedEvent, i as jsx, l as DOMAttributes, m as SVGAttributes, n as Fragment, o as jsxs, p as Ref, r as JSX, s as merge, t as CapabilityAttributes, u as EventAttributes } from "./jsx-runtime-
|
|
1
|
+
import { a as jsxDEV, c as AriaAttributes, d as EventHandler, f as HTMLAttributes, h as TargetedEvent, i as jsx, l as DOMAttributes, m as SVGAttributes, n as Fragment, o as jsxs, p as Ref, r as JSX, s as merge, t as CapabilityAttributes, u as EventAttributes } from "./jsx-runtime-DMDVr7A5.js";
|
|
2
2
|
export { type AriaAttributes, CapabilityAttributes, type DOMAttributes, type EventAttributes, type EventHandler, Fragment, type HTMLAttributes, JSX, type Ref, type SVGAttributes, type TargetedEvent, jsx, jsxDEV, jsxs, merge };
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-runtime.js","names":[],"sources":["../src/jsx-runtime.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","names":[],"sources":["../src/jsx-runtime.ts"],"sourcesContent":["import type { Children, Component, SpaElement } 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\n/** Optional integrations augment attributes without changing element identity. */\n// oxlint-disable-next-line typescript/no-empty-interface -- Optional integrations augment this declaration.\nexport interface CapabilityAttributes<Kind extends string = string> {}\n\nexport const Fragment = (props: { children?: Children }): Children =>\n\tprops.children\nexport function jsx(\n\ttype: SpaElement[`type`],\n\tprops: SpaElement[`props`] | null,\n\tkey?: unknown,\n): SpaElement {\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 = SpaElement\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":";AAkBA,MAAa,YAAY,UACxB,MAAM;AACP,SAAgB,IACf,MACA,OACA,KACa;CACb,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"}
|
package/dist/konva.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Children, c as SpaElement } from "./capabilities-BCtBG-ni.js";
|
|
2
2
|
import { SceneRenderer } from "./renderer.js";
|
|
3
|
-
import "./index-
|
|
4
|
-
import { t as CapabilityAttributes } from "./jsx-runtime-
|
|
3
|
+
import "./index-DufwkB6W.js";
|
|
4
|
+
import { t as CapabilityAttributes } from "./jsx-runtime-DMDVr7A5.js";
|
|
5
5
|
import Konva from "konva";
|
|
6
6
|
type Props<C, N> = C & CapabilityAttributes<`konva`> & {
|
|
7
|
-
children?:
|
|
7
|
+
children?: Children;
|
|
8
8
|
ref?: (node: N | null) => void;
|
|
9
9
|
onClick?: (event: Konva.KonvaEventObject<MouseEvent>) => void;
|
|
10
10
|
onPointerDown?: (event: Konva.KonvaEventObject<PointerEvent>) => void;
|
|
@@ -16,17 +16,17 @@ declare const renderer: SceneRenderer<import("konva/lib/Node").Node<import("konv
|
|
|
16
16
|
export declare function Stage(props: Props<Omit<Konva.StageConfig, `container`>, Konva.Stage> & {
|
|
17
17
|
width?: number;
|
|
18
18
|
height?: number;
|
|
19
|
-
}):
|
|
20
|
-
export declare const Layer: (props: Props<import("konva/lib/Layer").LayerConfig, import("konva/lib/Layer").Layer>) =>
|
|
21
|
-
export declare const Group: (props: Props<import("konva/lib/Container").ContainerConfig, import("konva/lib/Group").Group>) =>
|
|
22
|
-
export declare const Rect: (props: Props<import("konva/lib/shapes/Rect").RectConfig, import("konva/lib/shapes/Rect").Rect>) =>
|
|
23
|
-
export declare const Circle: (props: Props<import("konva/lib/shapes/Circle").CircleConfig, import("konva/lib/shapes/Circle").Circle>) =>
|
|
24
|
-
export declare const Ellipse: (props: Props<import("konva/lib/shapes/Ellipse").EllipseConfig, import("konva/lib/shapes/Ellipse").Ellipse>) =>
|
|
25
|
-
export declare const Line: (props: Props<import("konva/lib/shapes/Line").LineConfig, import("konva/lib/shapes/Line").Line<import("konva/lib/shapes/Line").LineConfig>>) =>
|
|
26
|
-
export declare const Text: (props: Props<import("konva/lib/shapes/Text").TextConfig, import("konva/lib/shapes/Text").Text>) =>
|
|
27
|
-
export declare const Image: (props: Props<import("konva/lib/shapes/Image").ImageConfig, import("konva/lib/shapes/Image").Image>) =>
|
|
28
|
-
export declare const Path: (props: Props<import("konva/lib/shapes/Path").PathConfig, import("konva/lib/shapes/Path").Path>) =>
|
|
29
|
-
export declare const Star: (props: Props<import("konva/lib/shapes/Star").StarConfig, import("konva/lib/shapes/Star").Star>) =>
|
|
30
|
-
export declare const Transformer: (props: Props<import("konva/lib/shapes/Transformer").TransformerConfig, import("konva/lib/shapes/Transformer").Transformer>) =>
|
|
19
|
+
}): SpaElement;
|
|
20
|
+
export declare const Layer: (props: Props<import("konva/lib/Layer").LayerConfig, import("konva/lib/Layer").Layer>) => SpaElement;
|
|
21
|
+
export declare const Group: (props: Props<import("konva/lib/Container").ContainerConfig, import("konva/lib/Group").Group>) => SpaElement;
|
|
22
|
+
export declare const Rect: (props: Props<import("konva/lib/shapes/Rect").RectConfig, import("konva/lib/shapes/Rect").Rect>) => SpaElement;
|
|
23
|
+
export declare const Circle: (props: Props<import("konva/lib/shapes/Circle").CircleConfig, import("konva/lib/shapes/Circle").Circle>) => SpaElement;
|
|
24
|
+
export declare const Ellipse: (props: Props<import("konva/lib/shapes/Ellipse").EllipseConfig, import("konva/lib/shapes/Ellipse").Ellipse>) => SpaElement;
|
|
25
|
+
export declare const Line: (props: Props<import("konva/lib/shapes/Line").LineConfig, import("konva/lib/shapes/Line").Line<import("konva/lib/shapes/Line").LineConfig>>) => SpaElement;
|
|
26
|
+
export declare const Text: (props: Props<import("konva/lib/shapes/Text").TextConfig, import("konva/lib/shapes/Text").Text>) => SpaElement;
|
|
27
|
+
export declare const Image: (props: Props<import("konva/lib/shapes/Image").ImageConfig, import("konva/lib/shapes/Image").Image>) => SpaElement;
|
|
28
|
+
export declare const Path: (props: Props<import("konva/lib/shapes/Path").PathConfig, import("konva/lib/shapes/Path").Path>) => SpaElement;
|
|
29
|
+
export declare const Star: (props: Props<import("konva/lib/shapes/Star").StarConfig, import("konva/lib/shapes/Star").Star>) => SpaElement;
|
|
30
|
+
export declare const Transformer: (props: Props<import("konva/lib/shapes/Transformer").TransformerConfig, import("konva/lib/shapes/Transformer").Transformer>) => SpaElement;
|
|
31
31
|
export { renderer as konvaRenderer };
|
|
32
32
|
//# sourceMappingURL=konva.d.ts.map
|
package/dist/konva.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as capabilityProps } from "./capabilities-BkQ2i0vV.js";
|
|
2
|
-
import { c as onCleanup, l as onMount, u as owner } from "./core-
|
|
2
|
+
import { c as onCleanup, l as onMount, u as owner } from "./core-DjFJ0aIJ.js";
|
|
3
3
|
import { jsx } from "./jsx-runtime.js";
|
|
4
4
|
import { bindScene, createSceneRenderer, sceneComponent } from "./renderer.js";
|
|
5
5
|
import Konva from "konva";
|
package/dist/konva.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"konva.js","names":[],"sources":["../src/konva.ts"],"sourcesContent":["import Konva from \"konva\"\n\nimport { capabilityProps } from \"./capabilities.ts\"\nimport { owner } from \"./core.ts\"\nimport type {
|
|
1
|
+
{"version":3,"file":"konva.js","names":[],"sources":["../src/konva.ts"],"sourcesContent":["import Konva from \"konva\"\n\nimport { capabilityProps } from \"./capabilities.ts\"\nimport { owner } from \"./core.ts\"\nimport type { Children, SpaElement } from \"./index.ts\"\nimport { onCleanup, onMount } from \"./index.ts\"\nimport type { CapabilityAttributes } from \"./jsx-runtime.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\nimport { bindScene, createSceneRenderer, sceneComponent } from \"./renderer.ts\"\n\ntype Props<C, N> = C &\n\tCapabilityAttributes<`konva`> & {\n\t\tchildren?: Children\n\t\tref?: (node: N | null) => void\n\t\tonClick?: (event: Konva.KonvaEventObject<MouseEvent>) => void\n\t\tonPointerDown?: (event: Konva.KonvaEventObject<PointerEvent>) => void\n\t\tonDragMove?: (event: Konva.KonvaEventObject<DragEvent>) => void\n\t\tonDragEnd?: (event: Konva.KonvaEventObject<DragEvent>) => void\n\t}\nconst constructors = {\n\tLayer: Konva.Layer,\n\tGroup: Konva.Group,\n\tRect: Konva.Rect,\n\tCircle: Konva.Circle,\n\tEllipse: Konva.Ellipse,\n\tLine: Konva.Line,\n\tText: Konva.Text,\n\tImage: Konva.Image,\n\tPath: Konva.Path,\n\tStar: Konva.Star,\n\tTransformer: Konva.Transformer,\n}\nfunction suspendNode(node: Konva.Node): () => void {\n\tconst listening = node.listening()\n\tconst draggable = node.draggable()\n\tnode.listening(false)\n\t// The public setter clears both pending and active native drag records.\n\tnode.draggable(false)\n\treturn () => {\n\t\tnode.listening(listening)\n\t\tnode.draggable(draggable)\n\t}\n}\nfunction updateNode(\n\tnode: Konva.Node,\n\tprops: Record<string, any>,\n\tprevious: Record<string, any>,\n): void {\n\tfor (const key of new Set([...Object.keys(previous), ...Object.keys(props)])) {\n\t\tif (/^(key|children|ref)$/.test(key) || Object.is(props[key], previous[key]))\n\t\t\tcontinue\n\t\tif (key.startsWith(`on`)) {\n\t\t\tconst event = key.slice(2).toLowerCase()\n\t\t\tif (previous[key]) node.off(event, previous[key])\n\t\t\tif (props[key]) node.on(event, props[key])\n\t\t} else node.setAttr(key, props[key])\n\t}\n}\nconst renderer = createSceneRenderer<Konva.Node>({\n\ttarget(node) {\n\t\treturn {\n\t\t\tkind: `konva`,\n\t\t\tnode,\n\t\t\tsuspend() {\n\t\t\t\treturn suspendNode(node)\n\t\t\t},\n\t\t\tread: (key) => node.getAttr(key),\n\t\t\twrite: (key, value) => {\n\t\t\t\tnode.setAttr(key, value)\n\t\t\t},\n\t\t\tlisten(event, listener) {\n\t\t\t\tnode.on(event, listener)\n\t\t\t\treturn () => {\n\t\t\t\t\tnode.off(event, listener)\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n\tcreate(type) {\n\t\tconst Constructor = constructors[type as keyof typeof constructors]\n\t\tif (!Constructor) throw new Error(`spa/konva: unknown node ${type}`)\n\t\treturn new Constructor({} as any)\n\t},\n\tupdate: updateNode,\n\tchildren(parent, children) {\n\t\tif (children.length && !(parent instanceof Konva.Container))\n\t\t\tthrow new Error(`spa/konva: shapes cannot contain children`)\n\t\tif (parent instanceof Konva.Container) {\n\t\t\tfor (const child of [...parent.getChildren()])\n\t\t\t\tif (!children.includes(child)) child.remove()\n\t\t\tchildren.forEach((child, index) => {\n\t\t\t\tif (child.getParent() !== parent) parent.add(child as any)\n\t\t\t\tchild.zIndex(index)\n\t\t\t})\n\t\t}\n\t},\n\tdestroy(node) {\n\t\tnode.off()\n\t\tnode.destroy()\n\t},\n})\n\n/** A DOM boundary owning a Konva stage and its scene subtree. */\nexport function Stage(\n\tprops: Props<Omit<Konva.StageConfig, `container`>, Konva.Stage> & {\n\t\twidth?: number\n\t\theight?: number\n\t},\n): SpaElement {\n\tlet container: HTMLDivElement | null = null\n\tonMount(() => {\n\t\t// Konva clears its container; preserve SPA's markers in the outer element.\n\t\tconst surface = container!.ownerDocument.createElement(`div`)\n\t\tcontainer!.append(surface)\n\t\tonCleanup(() => {\n\t\t\tsurface.remove()\n\t\t})\n\t\tconst stage = new Konva.Stage({\n\t\t\tcontainer: surface,\n\t\t\twidth: props.width ?? 300,\n\t\t\theight: props.height ?? 150,\n\t\t})\n\t\tonCleanup(() => {\n\t\t\tstage.off()\n\t\t\tstage.destroy()\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\towner!,\n\t\t\t{\n\t\t\t\tkind: `konva`,\n\t\t\t\tnode: stage,\n\t\t\t\tsuspend() {\n\t\t\t\t\treturn suspendNode(stage)\n\t\t\t\t},\n\t\t\t\tlisten(event, listener) {\n\t\t\t\t\tstage.on(event, listener)\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tstage.off(event, listener)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tread: (key) => stage.getAttr(key),\n\t\t\t\twrite: (key, value) => {\n\t\t\t\t\tstage.setAttr(key, value)\n\t\t\t\t},\n\t\t\t},\n\t\t\t() => ({ ...props }),\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tbindScene(\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\tupdateNode(stage, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tprops.ref?.(stage)\n\t\tonCleanup(() => props.ref?.(null))\n\t\trenderer.mount(() => props.children, stage)\n\t})\n\treturn jsx(`div`, {\n\t\tref: (element: HTMLDivElement | null) => {\n\t\t\tcontainer = element\n\t\t},\n\t})\n}\nexport const Layer =\n\tsceneComponent<Props<Konva.LayerConfig, Konva.Layer>>(`Layer`)\nexport const Group =\n\tsceneComponent<Props<Konva.ContainerConfig, Konva.Group>>(`Group`)\nexport const Rect = sceneComponent<Props<Konva.RectConfig, Konva.Rect>>(`Rect`)\nexport const Circle =\n\tsceneComponent<Props<Konva.CircleConfig, Konva.Circle>>(`Circle`)\nexport const Ellipse =\n\tsceneComponent<Props<Konva.EllipseConfig, Konva.Ellipse>>(`Ellipse`)\nexport const Line = sceneComponent<Props<Konva.LineConfig, Konva.Line>>(`Line`)\nexport const Text = sceneComponent<Props<Konva.TextConfig, Konva.Text>>(`Text`)\nexport const Image =\n\tsceneComponent<Props<Konva.ImageConfig, Konva.Image>>(`Image`)\nexport const Path = sceneComponent<Props<Konva.PathConfig, Konva.Path>>(`Path`)\nexport const Star = sceneComponent<Props<Konva.StarConfig, Konva.Star>>(`Star`)\nexport const Transformer =\n\tsceneComponent<Props<Konva.TransformerConfig, Konva.Transformer>>(\n\t\t`Transformer`,\n\t)\nexport {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;IACtB,MAAM,QAAQ,KAAK,KAAK;GACzB;EACD,UACO,EAAE,GAAG,MAAM,EACnB;EACA,IAAI,WAAgC,CAAC;EACrC,iBACQ,EAAE,GAAG,MAAM,KACjB,QAAQ;GACR,MAAM,OAAO,YAAY,GAAG;GAC5B,WAAW,OAAO,MAAM,QAAQ;GAChC,WAAW;EACZ,CACD;EACA,MAAM,MAAM,KAAK;EACjB,gBAAgB,MAAM,MAAM,IAAI,CAAC;EACjC,SAAS,YAAY,MAAM,UAAU,KAAK;CAC3C,CAAC;CACD,OAAO,IAAI,OAAO,EACjB,MAAM,YAAmC;EACxC,YAAY;CACb,EACD,CAAC;AACF;AACA,MAAa,QACZ,eAAsD,OAAO;AAC9D,MAAa,QACZ,eAA0D,OAAO;AAClE,MAAa,OAAO,eAAoD,MAAM;AAC9E,MAAa,SACZ,eAAwD,QAAQ;AACjE,MAAa,UACZ,eAA0D,SAAS;AACpE,MAAa,OAAO,eAAoD,MAAM;AAC9E,MAAa,OAAO,eAAoD,MAAM;AAC9E,MAAa,QACZ,eAAsD,OAAO;AAC9D,MAAa,OAAO,eAAoD,MAAM;AAC9E,MAAa,OAAO,eAAoD,MAAM;AAC9E,MAAa,cACZ,eACC,aACD"}
|
package/dist/motion.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Capability } from "./capabilities-
|
|
1
|
+
import { t as Capability } from "./capabilities-BCtBG-ni.js";
|
|
2
2
|
export type MotionScalar = number | string;
|
|
3
3
|
export type MotionDOMTarget = Partial<Record<keyof CSSStyleDeclaration | `x` | `y` | `z` | `scale` | `scaleX` | `scaleY` | `rotate` | `rotateX` | `rotateY` | `rotateZ` | `skewX` | `skewY` | `--${string}`, MotionScalar>>;
|
|
4
4
|
export interface MotionThreeTarget {
|
package/dist/motion.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as invalidate, i as fail, o as isPresent, p as untrack, r as dispose } from "./core-
|
|
1
|
+
import { a as invalidate, i as fail, o as isPresent, p as untrack, r as dispose } from "./core-DjFJ0aIJ.js";
|
|
2
2
|
import { animate, cancelFrame, frame, hover, keyframes, motionValue, press, readStyleValue, styleEffect } from "motion";
|
|
3
3
|
// src/motion-tween.ts
|
|
4
4
|
const trajectories = /* @__PURE__ */ new WeakMap();
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as Children, c as SpaElement, r as CapabilityTarget, s as RootOptions } from "./capabilities-BCtBG-ni.js";
|
|
2
2
|
export interface SceneHost<N> {
|
|
3
3
|
target?(node: N): CapabilityTarget;
|
|
4
4
|
create(type: string, props: Record<string, any>): N;
|
|
@@ -7,8 +7,8 @@ export interface SceneHost<N> {
|
|
|
7
7
|
destroy(node: N): void;
|
|
8
8
|
}
|
|
9
9
|
export interface SceneRenderer<N> {
|
|
10
|
-
mount(setup: () =>
|
|
11
|
-
render(setup: () =>
|
|
10
|
+
mount(setup: () => Children, parent: N): void;
|
|
11
|
+
render(setup: () => Children, parent: N, options?: RootOptions): {
|
|
12
12
|
flush(): void;
|
|
13
13
|
dispose(): void;
|
|
14
14
|
};
|
|
@@ -16,7 +16,7 @@ export interface SceneRenderer<N> {
|
|
|
16
16
|
/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */
|
|
17
17
|
export declare function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N>;
|
|
18
18
|
/** Define a typed scene component without introducing another JSX runtime. */
|
|
19
|
-
export declare function sceneComponent<P>(type: string): (props: P) =>
|
|
19
|
+
export declare function sceneComponent<P>(type: string): (props: P) => SpaElement;
|
|
20
20
|
/** Bind imperative scene work to the current owner and its reactive dependencies. */
|
|
21
21
|
export declare function bindScene<T>(read: () => T, apply: (value: T) => void): void;
|
|
22
22
|
/** Scene drawing follows an installed capability clock, or the browser clock. */
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","names":[],"sources":["../src/renderer.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","names":[],"sources":["../src/renderer.ts"],"mappings":";iBAuBiB,UAAU;EAC1B,QAAQ,MAAM,IAAI;EAClB,OAAO,cAAc,OAAO,sBAAsB;EAClD,OACC,MAAM,GACN,OAAO,qBACP,UAAU;EAEX,SAAS,QAAQ,GAAG,UAAU,KAAK,gBAAgB;EACnD,QAAQ,MAAM;;iBAUE,cAAc;EAC9B,MAAM,aAAa,UAAU,QAAQ;EACrC,OACC,aAAa,UACb,QAAQ,GACR,UAAU;IACN;IAAe;;;;wBAIL,oBAAoB,GAAG,MAAM,UAAU,KAAK,cAAc;;wBAwL1D,eAAe,GAAG,gBAAgB,OAAO,MAAM;;wBAK/C,UAAU,GAAG,YAAY,GAAG,QAAQ,OAAO;;wBAK3C,aACf,WAAW,uBACX"}
|
package/dist/renderer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as capabilityProps } from "./capabilities-BkQ2i0vV.js";
|
|
2
|
-
import { a as invalidate, i as fail, n as createScope, o as isPresent, p as untrack, r as dispose, s as observe, t as createRoot, u as owner, x as within } from "./core-
|
|
2
|
+
import { a as invalidate, i as fail, n as createScope, o as isPresent, p as untrack, r as dispose, s as observe, t as createRoot, u as owner, x as within } from "./core-DjFJ0aIJ.js";
|
|
3
3
|
import { Fragment, merge } from "./jsx-runtime.js";
|
|
4
4
|
// src/renderer.ts
|
|
5
5
|
/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */
|
package/dist/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","names":[],"sources":["../src/renderer.ts"],"sourcesContent":["import type { CapabilityTarget } from \"./capabilities.ts\"\nimport { capabilityProps } from \"./capabilities.ts\"\nimport type { Child, Component, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tisPresent,\n\tobserve,\n\towner,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nexport interface SceneHost<N> {\n\ttarget?(node: N): CapabilityTarget\n\tcreate(type: string, props: Record<string, any>): N\n\tupdate(\n\t\tnode: N,\n\t\tprops: Record<string, any>,\n\t\tprevious: Record<string, any>,\n\t): void\n\tchildren(parent: N, children: N[], activeChildren: N[]): void\n\tdestroy(node: N): void\n}\ntype SceneNodes<N> = (activeOnly?: boolean) => N[]\n\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Child\n\tnodes: SceneNodes<N>\n}\n\nexport interface SceneRenderer<N> {\n\tmount(setup: () => Child, parent: N): void\n\trender(\n\t\tsetup: () => Child,\n\t\tparent: N,\n\t\toptions?: RootOptions,\n\t): { flush(): void; dispose(): void }\n}\n\n/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */\nexport function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {\n\tfunction mount(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tlet entries: Entry<N>[] = []\n\t\tconst presence = scope._root._presence?.collection<Entry<N>, Child>(\n\t\t\t(entry) => entry.scope,\n\t\t\t(entry, value) => same(entry.value, value),\n\t\t)\n\t\tconst retire = (\n\t\t\tentry: Entry<N>,\n\t\t\tid: string,\n\t\t\teligible: boolean,\n\t\t\tindex: number,\n\t\t) => {\n\t\t\tif (presence)\n\t\t\t\tpresence.remove(entry, id, eligible, index, () => {\n\t\t\t\t\tif (!scope._dead) changed()\n\t\t\t\t})\n\t\t\telse dispose(entry.scope)\n\t\t}\n\t\tobserve(scope, source, (next) => {\n\t\t\tconst values = (\n\t\t\t\tArray.isArray(next) ? next.flat(Infinity) : [next]\n\t\t\t) as Child[]\n\t\t\tconst previous = entries\n\t\t\tconst old = new Map(\n\t\t\t\tentries.map((entry, i) => [key(entry.value, i), entry]),\n\t\t\t)\n\t\t\tconst seen = new Set<string>()\n\t\t\tentries = values.map((value, i) => {\n\t\t\t\tconst id = key(value, i)\n\t\t\t\tif (seen.has(id)) throw new Error(`spa: duplicate scene key`)\n\t\t\t\tseen.add(id)\n\t\t\t\tlet entry = old.get(id)\n\t\t\t\told.delete(id)\n\t\t\t\tif (entry && !same(entry.value, value)) {\n\t\t\t\t\tretire(\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tvalue == null || typeof value === `boolean`,\n\t\t\t\t\t\tprevious.indexOf(entry),\n\t\t\t\t\t)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tentry ??= presence?.take(id, value)\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\n\t\t\t\t\tscope._root._presence?.resume(entry.scope)\n\t\t\t\t\tinvalidate(entry.scope)\n\t\t\t\t\treturn entry\n\t\t\t\t}\n\t\t\t\tconst childScope = createScope(scope)\n\t\t\t\tconst created: Entry<N> = { scope: childScope, value, nodes: null! }\n\t\t\t\tcreated.nodes = build(() => created.value, childScope, changed)\n\t\t\t\treturn created\n\t\t\t})\n\t\t\tfor (const [id, entry] of old)\n\t\t\t\tretire(entry, id, true, previous.indexOf(entry))\n\t\t\tchanged()\n\t\t})\n\t\treturn (activeOnly = false) => {\n\t\t\tconst rendered = activeOnly\n\t\t\t\t? entries\n\t\t\t\t: (presence?.merge(entries) ?? entries)\n\t\t\treturn rendered.flatMap((entry) => entry.nodes(activeOnly))\n\t\t}\n\t}\n\tfunction key(value: Child, i: number): string {\n\t\tconst explicit = (value as VNode | null)?.props?.[`key`]\n\t\treturn explicit == null ? `index:${i}` : `key:${explicit}`\n\t}\n\tfunction same(a: Child, b: Child): boolean {\n\t\treturn (\n\t\t\ttypeof a === typeof b &&\n\t\t\t(a as VNode | null)?.type === (b as VNode | null)?.type\n\t\t)\n\t}\n\tfunction build(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tconst value = untrack(source)\n\t\tif (typeof value === `function`)\n\t\t\treturn mount(() => (source() as () => Child)(), scope, changed)\n\t\tif (value == null || typeof value === `boolean`) return () => []\n\t\tif (typeof value !== `object`)\n\t\t\tthrow new Error(`spa: scene children must be nodes`)\n\t\tif (!(`type` in value) || !(`props` in value))\n\t\t\tthrow new Error(`spa: invalid scene child`)\n\t\tconst vnode = value\n\t\tconst props = merge(() => (source() as VNode).props)\n\t\tif (!vnode.type || vnode.type === Fragment)\n\t\t\treturn mount(() => props[`children`], scope, changed)\n\t\tif (typeof vnode.type === `function`) {\n\t\t\tconst output = within(scope, () =>\n\t\t\t\tuntrack(() => (vnode.type as Component)(props)),\n\t\t\t)\n\t\t\treturn mount(() => output, scope, changed)\n\t\t}\n\t\tconst node = host.create(\n\t\t\tvnode.type,\n\t\t\tuntrack(() => props),\n\t\t)\n\t\tscope._cleanups.add(() => {\n\t\t\thost.destroy(node)\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\tscope,\n\t\t\thost.target?.(node) ?? { kind: `scene`, node },\n\t\t\t() => ({ ...props }),\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tobserve(\n\t\t\tscope,\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\thost.update(node, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tlet children: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children(), children(true))\n\t\t}\n\t\tchildren = mount(() => props[`children`], scope, sync)\n\t\tsync()\n\t\tconst ref = untrack(() => props[`ref`])\n\t\tif (ref)\n\t\t\tscope._root._mounts!.unshift(() => {\n\t\t\t\tif (!scope._dead) {\n\t\t\t\t\tscope._cleanups.add(() => ref(null))\n\t\t\t\t\tref(node)\n\t\t\t\t}\n\t\t\t})\n\t\treturn () => [node]\n\t}\n\tfunction attach(setup: () => Child, parent: N, scope: Scope) {\n\t\tlet nodes: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes(), nodes(true))\n\t\t}\n\t\tnodes = mount(() => untrack(setup), scope, sync)\n\t\tsync()\n\t\tscope._cleanups.add(() => {\n\t\t\thost.children(parent, [], [])\n\t\t})\n\t}\n\treturn {\n\t\t/** Attach beneath the current component; disposal follows its lifetime. */\n\t\tmount(setup: () => Child, parent: N): void {\n\t\t\tif (!owner) throw new Error(`spa: scene mount requires an owner`)\n\t\t\tconst scope = createScope(owner)\n\t\t\ttry {\n\t\t\t\tattach(setup, parent, scope)\n\t\t\t} catch (error) {\n\t\t\t\tfail(scope, error)\n\t\t\t}\n\t\t},\n\t\trender(setup: () => Child, parent: N, options: RootOptions = {}) {\n\t\t\tconst root = createRoot(options)\n\t\t\ttry {\n\t\t\t\twithin(root, () => {\n\t\t\t\t\tattach(setup, parent, root)\n\t\t\t\t})\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tfail(root, error)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tflush: root.flush,\n\t\t\t\tdispose: () => {\n\t\t\t\t\tdispose(root)\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\n/** Define a typed scene component without introducing another JSX runtime. */\nexport function sceneComponent<P>(type: string): (props: P) => VNode {\n\treturn (props) => ({ type, props: props as Record<string, any> })\n}\n\n/** Bind imperative scene work to the current owner and its reactive dependencies. */\nexport function bindScene<T>(read: () => T, apply: (value: T) => void): void {\n\tobserve(owner!, read, apply)\n}\n\n/** Scene drawing follows an installed capability clock, or the browser clock. */\nexport function onSceneFrame(\n\tcallback: (time: number) => void,\n\tinfrastructure = false,\n): void {\n\tconst scope = owner!\n\tconst clocks = [...scope._root._capabilities.values()].filter(\n\t\t(capability) => capability.scheduleFrame,\n\t)\n\tif (clocks.length > 1)\n\t\tthrow new Error(`spa: multiple frame clock capabilities`)\n\tconst draw = (time: number) => {\n\t\tif (scope._dead || (!infrastructure && !isPresent(scope))) return\n\t\ttry {\n\t\t\tcallback(time)\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tfail(scope._root, error)\n\t\t\t} catch (failure) {\n\t\t\t\tscope._root.error(failure)\n\t\t\t}\n\t\t}\n\t}\n\tlet stop: () => void\n\tif (clocks[0]) stop = clocks[0].scheduleFrame!(draw)\n\telse {\n\t\tlet frame = 0\n\t\tconst tick = (time: number) => {\n\t\t\tif (scope._dead) return\n\t\t\tdraw(time)\n\t\t\tif (!scope._dead) frame = requestAnimationFrame(tick)\n\t\t}\n\t\tframe = requestAnimationFrame(tick)\n\t\tstop = () => {\n\t\t\tcancelAnimationFrame(frame)\n\t\t}\n\t}\n\tscope._cleanups.add(stop)\n}\n"],"mappings":";;;;;AA8CA,SAAgB,oBAAuB,MAAsC;CAC5E,SAAS,MACR,QACA,OACA,SACgB;EAChB,IAAI,UAAsB,CAAC;EAC3B,MAAM,WAAW,MAAM,MAAM,WAAW,YACtC,UAAU,MAAM,QAChB,OAAO,UAAU,KAAK,MAAM,OAAO,KAAK,CAC1C;EACA,MAAM,UACL,OACA,IACA,UACA,UACI;GACJ,IAAI,UACH,SAAS,OAAO,OAAO,IAAI,UAAU,aAAa;IACjD,IAAI,CAAC,MAAM,OAAO,QAAQ;GAC3B,CAAC;QACG,QAAQ,MAAM,KAAK;EACzB;EACA,QAAQ,OAAO,SAAS,SAAS;GAChC,MAAM,SACL,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI;GAElD,MAAM,WAAW;GACjB,MAAM,MAAM,IAAI,IACf,QAAQ,KAAK,OAAO,MAAM,CAAC,IAAI,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CACvD;GACA,MAAM,uBAAO,IAAI,IAAY;GAC7B,UAAU,OAAO,KAAK,OAAO,MAAM;IAClC,MAAM,KAAK,IAAI,OAAO,CAAC;IACvB,IAAI,KAAK,IAAI,EAAE,GAAG,MAAM,I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d,SAAS,OAAO;GACf,IAAI;IACH,KAAK,MAAM,OAAO,KAAK;GACxB,SAAS,SAAS;IACjB,MAAM,MAAM,MAAM,OAAO;GAC1B;EACD;CACD;CACA,IAAI;CACJ,IAAI,OAAO,IAAI,OAAO,OAAO,EAAE,CAAC,cAAe,IAAI;MAC9C;EACJ,IAAI,QAAQ;EACZ,MAAM,QAAQ,SAAiB;GAC9B,IAAI,MAAM,OAAO;GACjB,KAAK,IAAI;GACT,IAAI,CAAC,MAAM,OAAO,QAAQ,sBAAsB,IAAI;EACrD;EACA,QAAQ,sBAAsB,IAAI;EAClC,aAAa;GACZ,qBAAqB,KAAK;EAC3B;CACD;CACA,MAAM,UAAU,IAAI,IAAI;AACzB"}
|
|
1
|
+
{"version":3,"file":"renderer.js","names":[],"sources":["../src/renderer.ts"],"sourcesContent":["import type { CapabilityTarget } from \"./capabilities.ts\"\nimport { capabilityProps } from \"./capabilities.ts\"\nimport type {\n\tChildren,\n\tComponent,\n\tRootOptions,\n\tScope,\n\tSpaElement,\n} from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tisPresent,\n\tobserve,\n\towner,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nexport interface SceneHost<N> {\n\ttarget?(node: N): CapabilityTarget\n\tcreate(type: string, props: Record<string, any>): N\n\tupdate(\n\t\tnode: N,\n\t\tprops: Record<string, any>,\n\t\tprevious: Record<string, any>,\n\t): void\n\tchildren(parent: N, children: N[], activeChildren: N[]): void\n\tdestroy(node: N): void\n}\ntype SceneNodes<N> = (activeOnly?: boolean) => N[]\n\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Children\n\tnodes: SceneNodes<N>\n}\n\nexport interface SceneRenderer<N> {\n\tmount(setup: () => Children, parent: N): void\n\trender(\n\t\tsetup: () => Children,\n\t\tparent: N,\n\t\toptions?: RootOptions,\n\t): { flush(): void; dispose(): void }\n}\n\n/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */\nexport function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {\n\tfunction mount(\n\t\tsource: () => Children,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tlet entries: Entry<N>[] = []\n\t\tconst presence = scope._root._presence?.collection<Entry<N>, Children>(\n\t\t\t(entry) => entry.scope,\n\t\t\t(entry, value) => same(entry.value, value),\n\t\t)\n\t\tconst retire = (\n\t\t\tentry: Entry<N>,\n\t\t\tid: string,\n\t\t\teligible: boolean,\n\t\t\tindex: number,\n\t\t) => {\n\t\t\tif (presence)\n\t\t\t\tpresence.remove(entry, id, eligible, index, () => {\n\t\t\t\t\tif (!scope._dead) changed()\n\t\t\t\t})\n\t\t\telse dispose(entry.scope)\n\t\t}\n\t\tobserve(scope, source, (next) => {\n\t\t\tconst values = (\n\t\t\t\tArray.isArray(next) ? next.flat(Infinity) : [next]\n\t\t\t) as Children[]\n\t\t\tconst previous = entries\n\t\t\tconst old = new Map(\n\t\t\t\tentries.map((entry, i) => [key(entry.value, i), entry]),\n\t\t\t)\n\t\t\tconst seen = new Set<string>()\n\t\t\tentries = values.map((value, i) => {\n\t\t\t\tconst id = key(value, i)\n\t\t\t\tif (seen.has(id)) throw new Error(`spa: duplicate scene key`)\n\t\t\t\tseen.add(id)\n\t\t\t\tlet entry = old.get(id)\n\t\t\t\told.delete(id)\n\t\t\t\tif (entry && !same(entry.value, value)) {\n\t\t\t\t\tretire(\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tvalue == null || typeof value === `boolean`,\n\t\t\t\t\t\tprevious.indexOf(entry),\n\t\t\t\t\t)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tentry ??= presence?.take(id, value)\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\n\t\t\t\t\tscope._root._presence?.resume(entry.scope)\n\t\t\t\t\tinvalidate(entry.scope)\n\t\t\t\t\treturn entry\n\t\t\t\t}\n\t\t\t\tconst childScope = createScope(scope)\n\t\t\t\tconst created: Entry<N> = { scope: childScope, value, nodes: null! }\n\t\t\t\tcreated.nodes = build(() => created.value, childScope, changed)\n\t\t\t\treturn created\n\t\t\t})\n\t\t\tfor (const [id, entry] of old)\n\t\t\t\tretire(entry, id, true, previous.indexOf(entry))\n\t\t\tchanged()\n\t\t})\n\t\treturn (activeOnly = false) => {\n\t\t\tconst rendered = activeOnly\n\t\t\t\t? entries\n\t\t\t\t: (presence?.merge(entries) ?? entries)\n\t\t\treturn rendered.flatMap((entry) => entry.nodes(activeOnly))\n\t\t}\n\t}\n\tfunction key(value: Children, i: number): string {\n\t\tconst explicit = (value as SpaElement | null)?.props?.[`key`]\n\t\treturn explicit == null ? `index:${i}` : `key:${explicit}`\n\t}\n\tfunction same(a: Children, b: Children): boolean {\n\t\treturn (\n\t\t\ttypeof a === typeof b &&\n\t\t\t(a as SpaElement | null)?.type === (b as SpaElement | null)?.type\n\t\t)\n\t}\n\tfunction build(\n\t\tsource: () => Children,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tconst value = untrack(source)\n\t\tif (typeof value === `function`)\n\t\t\treturn mount(() => (source() as () => Children)(), scope, changed)\n\t\tif (value == null || typeof value === `boolean`) return () => []\n\t\tif (typeof value !== `object`)\n\t\t\tthrow new Error(`spa: scene children must be nodes`)\n\t\tif (!(`type` in value) || !(`props` in value))\n\t\t\tthrow new Error(`spa: invalid scene child`)\n\t\tconst vnode = value\n\t\tconst props = merge(() => (source() as SpaElement).props)\n\t\tif (!vnode.type || vnode.type === Fragment)\n\t\t\treturn mount(() => props[`children`], scope, changed)\n\t\tif (typeof vnode.type === `function`) {\n\t\t\tconst output = within(scope, () =>\n\t\t\t\tuntrack(() => (vnode.type as Component)(props)),\n\t\t\t)\n\t\t\treturn mount(() => output, scope, changed)\n\t\t}\n\t\tconst node = host.create(\n\t\t\tvnode.type,\n\t\t\tuntrack(() => props),\n\t\t)\n\t\tscope._cleanups.add(() => {\n\t\t\thost.destroy(node)\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\tscope,\n\t\t\thost.target?.(node) ?? { kind: `scene`, node },\n\t\t\t() => ({ ...props }),\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tobserve(\n\t\t\tscope,\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\thost.update(node, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tlet children: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children(), children(true))\n\t\t}\n\t\tchildren = mount(() => props[`children`], scope, sync)\n\t\tsync()\n\t\tconst ref = untrack(() => props[`ref`])\n\t\tif (ref)\n\t\t\tscope._root._mounts!.unshift(() => {\n\t\t\t\tif (!scope._dead) {\n\t\t\t\t\tscope._cleanups.add(() => ref(null))\n\t\t\t\t\tref(node)\n\t\t\t\t}\n\t\t\t})\n\t\treturn () => [node]\n\t}\n\tfunction attach(setup: () => Children, parent: N, scope: Scope) {\n\t\tlet nodes: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes(), nodes(true))\n\t\t}\n\t\tnodes = mount(() => untrack(setup), scope, sync)\n\t\tsync()\n\t\tscope._cleanups.add(() => {\n\t\t\thost.children(parent, [], [])\n\t\t})\n\t}\n\treturn {\n\t\t/** Attach beneath the current component; disposal follows its lifetime. */\n\t\tmount(setup: () => Children, parent: N): void {\n\t\t\tif (!owner) throw new Error(`spa: scene mount requires an owner`)\n\t\t\tconst scope = createScope(owner)\n\t\t\ttry {\n\t\t\t\tattach(setup, parent, scope)\n\t\t\t} catch (error) {\n\t\t\t\tfail(scope, error)\n\t\t\t}\n\t\t},\n\t\trender(setup: () => Children, parent: N, options: RootOptions = {}) {\n\t\t\tconst root = createRoot(options)\n\t\t\ttry {\n\t\t\t\twithin(root, () => {\n\t\t\t\t\tattach(setup, parent, root)\n\t\t\t\t})\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tfail(root, error)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tflush: root.flush,\n\t\t\t\tdispose: () => {\n\t\t\t\t\tdispose(root)\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\n/** Define a typed scene component without introducing another JSX runtime. */\nexport function sceneComponent<P>(type: string): (props: P) => SpaElement {\n\treturn (props) => ({ type, props: props as Record<string, any> })\n}\n\n/** Bind imperative scene work to the current owner and its reactive dependencies. */\nexport function bindScene<T>(read: () => T, apply: (value: T) => void): void {\n\tobserve(owner!, read, apply)\n}\n\n/** Scene drawing follows an installed capability clock, or the browser clock. */\nexport function onSceneFrame(\n\tcallback: (time: number) => void,\n\tinfrastructure = false,\n): void {\n\tconst scope = owner!\n\tconst clocks = [...scope._root._capabilities.values()].filter(\n\t\t(capability) => capability.scheduleFrame,\n\t)\n\tif (clocks.length > 1)\n\t\tthrow new Error(`spa: multiple frame clock capabilities`)\n\tconst draw = (time: number) => {\n\t\tif (scope._dead || (!infrastructure && !isPresent(scope))) return\n\t\ttry {\n\t\t\tcallback(time)\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tfail(scope._root, error)\n\t\t\t} catch (failure) {\n\t\t\t\tscope._root.error(failure)\n\t\t\t}\n\t\t}\n\t}\n\tlet stop: () => void\n\tif (clocks[0]) stop = clocks[0].scheduleFrame!(draw)\n\telse {\n\t\tlet frame = 0\n\t\tconst tick = (time: number) => {\n\t\t\tif (scope._dead) return\n\t\t\tdraw(time)\n\t\t\tif (!scope._dead) frame = requestAnimationFrame(tick)\n\t\t}\n\t\tframe = requestAnimationFrame(tick)\n\t\tstop = () => {\n\t\t\tcancelAnimationFrame(frame)\n\t\t}\n\t}\n\tscope._cleanups.add(stop)\n}\n"],"mappings":";;;;;AAoDA,SAAgB,oBAAuB,MAAsC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} from "./capabilities-BkQ2i0vV.js";
|
|
2
|
+
import { d as plain, n as createScope, p as untrack, r as dispose, t as createRoot, x as within } from "./core-DjFJ0aIJ.js";
|
|
3
|
+
import { Fragment } from "./jsx-runtime.js";
|
|
4
|
+
// src/server-renderer.ts
|
|
5
|
+
const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
|
6
|
+
"&": `&`,
|
|
7
|
+
"<": `<`,
|
|
8
|
+
">": `>`,
|
|
9
|
+
"\"": `"`,
|
|
10
|
+
"'": `'`
|
|
11
|
+
})[char]);
|
|
12
|
+
const voidTags = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
|
13
|
+
const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(` `));
|
|
14
|
+
function stringify(value, owner, namespace = `html`, selectValue) {
|
|
15
|
+
if (typeof value === `function`) {
|
|
16
|
+
const values = [untrack(value)].flat(Infinity);
|
|
17
|
+
const keys = /* @__PURE__ */ new Set();
|
|
18
|
+
return `<!--{-->` + values.map((child, index) => {
|
|
19
|
+
const explicit = child?.props?.[`key`];
|
|
20
|
+
const key = explicit == null ? index : String(explicit);
|
|
21
|
+
if (keys.has(key)) throw new Error(`spa: duplicate key`);
|
|
22
|
+
keys.add(key);
|
|
23
|
+
return `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`;
|
|
24
|
+
}).join(``) + `<!--}-->`;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) return value.map((child) => stringify(child, owner, namespace, selectValue)).join(``);
|
|
27
|
+
if (value == null || typeof value === `boolean`) return ``;
|
|
28
|
+
if (typeof value !== `object`) return `<!--t-->${escape(value)}`;
|
|
29
|
+
if (!(`type` in value) || !(`props` in value)) throw new TypeError(`spa: invalid child`);
|
|
30
|
+
const { type, props } = value;
|
|
31
|
+
if (!type || type === Fragment) return stringify(() => props[`children`], owner, namespace, selectValue);
|
|
32
|
+
if (typeof type === `function`) {
|
|
33
|
+
const childOwner = createScope(owner);
|
|
34
|
+
return within(childOwner, () => stringify(untrack(() => type(props)), childOwner, namespace, selectValue));
|
|
35
|
+
}
|
|
36
|
+
if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
|
|
37
|
+
if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
|
|
38
|
+
const ns = type === `svg` ? `svg` : namespace;
|
|
39
|
+
validateCapabilities(owner, props);
|
|
40
|
+
let attrs = ``;
|
|
41
|
+
let textValue;
|
|
42
|
+
for (let key of Object.keys(props)) {
|
|
43
|
+
if (capabilityNamespace(key) !== void 0 || key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
|
|
44
|
+
if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
|
|
45
|
+
let attribute = props[key];
|
|
46
|
+
if (ns === `html`) {
|
|
47
|
+
if (key === `defaultValue` && (type === `input` || type === `textarea`)) {
|
|
48
|
+
if (props[`value`] != null) continue;
|
|
49
|
+
key = `value`;
|
|
50
|
+
} else if (key === `defaultChecked` && type === `input`) {
|
|
51
|
+
if (props[`checked`] != null) continue;
|
|
52
|
+
key = `checked`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (key === `className`) key = `class`;
|
|
56
|
+
if (key === `htmlFor`) key = `for`;
|
|
57
|
+
if (!/^[^\s"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`);
|
|
58
|
+
if (key === `value` && (type === `select` || type === `textarea`)) {
|
|
59
|
+
textValue = attribute ?? textValue;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (key === `style` && attribute != null && typeof attribute !== `string`) throw new TypeError(`spa: CSS string required`);
|
|
63
|
+
const boolean = ns === `html` && (booleans.has(key.toLowerCase()) || /^(capture|download|hidden)$/.test(key) && typeof attribute === `boolean`);
|
|
64
|
+
if (attribute == null || boolean && !attribute) continue;
|
|
65
|
+
attrs += boolean ? ` ${key}=""` : ` ${key}="${escape(attribute)}"`;
|
|
66
|
+
}
|
|
67
|
+
if (type === `option` && selectValue !== void 0 && String(props[`value`]) === String(selectValue)) attrs += ` selected=""`;
|
|
68
|
+
if (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`;
|
|
69
|
+
if (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {
|
|
70
|
+
let text = plain(type === `textarea` ? textValue ?? props[`children`] : props[`children`]);
|
|
71
|
+
if (type === `textarea` && text.startsWith(`\n`)) text = `\n${text}`;
|
|
72
|
+
if (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text)) throw new Error(`spa: unsafe raw text`);
|
|
73
|
+
return `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`;
|
|
74
|
+
}
|
|
75
|
+
const children = stringify(() => props[`children`], owner, type === `foreignObject` ? `html` : ns, type === `select` ? textValue : selectValue);
|
|
76
|
+
return `<${type}${attrs}>${children}</${type}>`;
|
|
77
|
+
}
|
|
78
|
+
function renderToStringWithReads(setup, options = {}, onRead) {
|
|
79
|
+
const root = createRoot(options, true);
|
|
80
|
+
root._onRead = onRead;
|
|
81
|
+
if (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`);
|
|
82
|
+
try {
|
|
83
|
+
return `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`;
|
|
84
|
+
} finally {
|
|
85
|
+
dispose(root);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export { renderToStringWithReads as t };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=server-renderer-DcU55e6s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-renderer-DcU55e6s.js","names":[],"sources":["../src/server-renderer.ts"],"sourcesContent":["import type { ReadableToken } from \"atom.io\"\n\nimport { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport type { Children, RootOptions, Scope, SpaElement } 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 credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Children,\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 Children[]\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 SpaElement | 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\tvalidateCapabilities(owner, props)\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tcapabilityNamespace(key) !== undefined ||\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 (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\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 ?? textValue\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 =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${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 renderToStringWithReads(\n\tsetup: () => Children,\n\toptions: RootOptions = {},\n\tonRead?: (value: unknown, token: ReadableToken<unknown>) => void,\n): string {\n\tconst root = createRoot(options, true)\n\troot._onRead = onRead\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":";;;;AAcA,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,qVAAqV,MACpV,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,OAA6B,QAAQ;GACvD,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,OAAO,MACL,KAAK,UAAU,UAAU,OAAO,OAAO,WAAW,WAAW,CAAC,CAAC,CAC/D,KAAK,EAAE;CACV,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CACxD,IAAI,OAAO,UAAU,UAAU,OAAO,WAAW,OAAO,KAAK;CAC7D,IAAI,EAAE,UAAU,UAAU,EAAE,WAAW,QACtC,MA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,QAAQ,KAAK,OAAO,YAAY,UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export declare function renderToString(setup: () =>
|
|
1
|
+
import { a as Children, s as RootOptions } from "./capabilities-BCtBG-ni.js";
|
|
2
|
+
export declare function renderToString(setup: () => Children, options?: RootOptions): string;
|
|
3
3
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"mappings":";wBAGgB,eACf,aAAa,UACb,UAAS"}
|
package/dist/server.js
CHANGED
|
@@ -1,88 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as plain, n as createScope, p as untrack, r as dispose, t as createRoot, x as within } from "./core-DCmqLZQP.js";
|
|
3
|
-
import { Fragment } from "./jsx-runtime.js";
|
|
1
|
+
import { t as renderToStringWithReads } from "./server-renderer-DcU55e6s.js";
|
|
4
2
|
// src/server.ts
|
|
5
|
-
const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
|
6
|
-
"&": `&`,
|
|
7
|
-
"<": `<`,
|
|
8
|
-
">": `>`,
|
|
9
|
-
"\"": `"`,
|
|
10
|
-
"'": `'`
|
|
11
|
-
})[char]);
|
|
12
|
-
const voidTags = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
|
13
|
-
const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(` `));
|
|
14
|
-
function stringify(value, owner, namespace = `html`, selectValue) {
|
|
15
|
-
if (typeof value === `function`) {
|
|
16
|
-
const values = [untrack(value)].flat(Infinity);
|
|
17
|
-
const keys = /* @__PURE__ */ new Set();
|
|
18
|
-
return `<!--{-->` + values.map((child, index) => {
|
|
19
|
-
const explicit = child?.props?.[`key`];
|
|
20
|
-
const key = explicit == null ? index : String(explicit);
|
|
21
|
-
if (keys.has(key)) throw new Error(`spa: duplicate key`);
|
|
22
|
-
keys.add(key);
|
|
23
|
-
return `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`;
|
|
24
|
-
}).join(``) + `<!--}-->`;
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(value)) return value.map((child) => stringify(child, owner, namespace, selectValue)).join(``);
|
|
27
|
-
if (value == null || typeof value === `boolean`) return ``;
|
|
28
|
-
if (typeof value !== `object`) return `<!--t-->${escape(value)}`;
|
|
29
|
-
if (!(`type` in value) || !(`props` in value)) throw new TypeError(`spa: invalid child`);
|
|
30
|
-
const { type, props } = value;
|
|
31
|
-
if (!type || type === Fragment) return stringify(() => props[`children`], owner, namespace, selectValue);
|
|
32
|
-
if (typeof type === `function`) {
|
|
33
|
-
const childOwner = createScope(owner);
|
|
34
|
-
return within(childOwner, () => stringify(untrack(() => type(props)), childOwner, namespace, selectValue));
|
|
35
|
-
}
|
|
36
|
-
if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
|
|
37
|
-
if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
|
|
38
|
-
const ns = type === `svg` ? `svg` : namespace;
|
|
39
|
-
validateCapabilities(owner, props);
|
|
40
|
-
let attrs = ``;
|
|
41
|
-
let textValue;
|
|
42
|
-
for (let key of Object.keys(props)) {
|
|
43
|
-
if (capabilityNamespace(key) !== void 0 || key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
|
|
44
|
-
if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
|
|
45
|
-
let attribute = props[key];
|
|
46
|
-
if (ns === `html`) {
|
|
47
|
-
if (key === `defaultValue` && (type === `input` || type === `textarea`)) {
|
|
48
|
-
if (props[`value`] != null) continue;
|
|
49
|
-
key = `value`;
|
|
50
|
-
} else if (key === `defaultChecked` && type === `input`) {
|
|
51
|
-
if (props[`checked`] != null) continue;
|
|
52
|
-
key = `checked`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (key === `className`) key = `class`;
|
|
56
|
-
if (key === `htmlFor`) key = `for`;
|
|
57
|
-
if (!/^[^\s"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`);
|
|
58
|
-
if (key === `value` && (type === `select` || type === `textarea`)) {
|
|
59
|
-
textValue = attribute ?? textValue;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (key === `style` && attribute != null && typeof attribute !== `string`) throw new TypeError(`spa: CSS string required`);
|
|
63
|
-
const boolean = ns === `html` && (booleans.has(key.toLowerCase()) || /^(capture|download|hidden)$/.test(key) && typeof attribute === `boolean`);
|
|
64
|
-
if (attribute == null || boolean && !attribute) continue;
|
|
65
|
-
attrs += boolean ? ` ${key}=""` : ` ${key}="${escape(attribute)}"`;
|
|
66
|
-
}
|
|
67
|
-
if (type === `option` && selectValue !== void 0 && String(props[`value`]) === String(selectValue)) attrs += ` selected=""`;
|
|
68
|
-
if (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`;
|
|
69
|
-
if (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {
|
|
70
|
-
let text = plain(type === `textarea` ? textValue ?? props[`children`] : props[`children`]);
|
|
71
|
-
if (type === `textarea` && text.startsWith(`\n`)) text = `\n${text}`;
|
|
72
|
-
if (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text)) throw new Error(`spa: unsafe raw text`);
|
|
73
|
-
return `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`;
|
|
74
|
-
}
|
|
75
|
-
const children = stringify(() => props[`children`], owner, type === `foreignObject` ? `html` : ns, type === `select` ? textValue : selectValue);
|
|
76
|
-
return `<${type}${attrs}>${children}</${type}>`;
|
|
77
|
-
}
|
|
78
3
|
function renderToString(setup, options = {}) {
|
|
79
|
-
|
|
80
|
-
if (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`);
|
|
81
|
-
try {
|
|
82
|
-
return `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`;
|
|
83
|
-
} finally {
|
|
84
|
-
dispose(root);
|
|
85
|
-
}
|
|
4
|
+
return renderToStringWithReads(setup, options);
|
|
86
5
|
}
|
|
87
6
|
export { renderToString };
|
|
88
7
|
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import type { Children, RootOptions } from \"./core.ts\"\nimport { renderToStringWithReads } from \"./server-renderer.ts\"\n\nexport function renderToString(\n\tsetup: () => Children,\n\toptions: RootOptions = {},\n): string {\n\treturn renderToStringWithReads(setup, options)\n}\n"],"mappings":";;AAGA,SAAgB,eACf,OACA,UAAuB,CAAC,GACf;CACT,OAAO,wBAAwB,OAAO,OAAO;AAC9C"}
|
package/dist/size.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
3
|
"name": "spa client",
|
|
4
|
-
"raw":
|
|
5
|
-
"minified":
|
|
6
|
-
"gzip":
|
|
7
|
-
"brotli":
|
|
4
|
+
"raw": 20714,
|
|
5
|
+
"minified": 9960,
|
|
6
|
+
"gzip": 4218,
|
|
7
|
+
"brotli": 3840
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"name": "spa + atom.io",
|
|
11
|
-
"raw":
|
|
12
|
-
"minified":
|
|
13
|
-
"gzip":
|
|
14
|
-
"brotli":
|
|
11
|
+
"raw": 109879,
|
|
12
|
+
"minified": 53633,
|
|
13
|
+
"gzip": 16164,
|
|
14
|
+
"brotli": 14636
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"name": "spa Astro client",
|
|
18
|
-
"raw":
|
|
19
|
-
"minified":
|
|
20
|
-
"gzip":
|
|
21
|
-
"brotli":
|
|
18
|
+
"raw": 25690,
|
|
19
|
+
"minified": 12190,
|
|
20
|
+
"gzip": 5027,
|
|
21
|
+
"brotli": 4544
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"name": "Preact",
|
|
25
|
-
"raw":
|
|
26
|
-
"minified":
|
|
27
|
-
"gzip":
|
|
28
|
-
"brotli":
|
|
25
|
+
"raw": 17795,
|
|
26
|
+
"minified": 11884,
|
|
27
|
+
"gzip": 4927,
|
|
28
|
+
"brotli": 4506
|
|
29
29
|
}
|
|
30
30
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as resolveStateToken, m as useGetter, u as owner } from "./core-DjFJ0aIJ.js";
|
|
2
2
|
import { withdraw } from "atom.io/internal";
|
|
3
3
|
// src/use-loadable.ts
|
|
4
4
|
function useLoadable(...params) {
|
|
@@ -6,7 +6,7 @@ function useLoadable(...params) {
|
|
|
6
6
|
const [token] = params;
|
|
7
7
|
const family = token.type.endsWith(`_family`);
|
|
8
8
|
const selected = resolveStateToken(token, params[1]);
|
|
9
|
-
const
|
|
9
|
+
const getValue = useGetter(selected);
|
|
10
10
|
const fallbackIndex = family ? 2 : 1;
|
|
11
11
|
const fallback = params[fallbackIndex];
|
|
12
12
|
const hasFallback = params.length > fallbackIndex;
|
|
@@ -14,7 +14,7 @@ function useLoadable(...params) {
|
|
|
14
14
|
let previous = fallback;
|
|
15
15
|
let error;
|
|
16
16
|
return () => {
|
|
17
|
-
const value =
|
|
17
|
+
const value = getValue();
|
|
18
18
|
const loading = value instanceof Promise;
|
|
19
19
|
if (!loading) {
|
|
20
20
|
previous = value;
|
|
@@ -35,4 +35,4 @@ function useLoadable(...params) {
|
|
|
35
35
|
}
|
|
36
36
|
export { useLoadable as t };
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=src-
|
|
38
|
+
//# sourceMappingURL=src-DWIqXCiz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-DWIqXCiz.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, useGetter } 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 getValue = useGetter(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 = getValue()\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,WAAW,UAAU,QAAQ;CACnC,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,SAAS;EACvB,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"}
|