@atom.io/spa 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +201 -6
  2. package/README.mdx +62 -1
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-client.d.ts +1 -1
  5. package/dist/astro-client.js +6 -3
  6. package/dist/astro-client.js.map +1 -1
  7. package/dist/astro-server.js +2 -1
  8. package/dist/astro-server.js.map +1 -1
  9. package/dist/astro-shared-BT45auwR.js.map +1 -1
  10. package/dist/{astro-shared-DkZaqX7L.d.ts → astro-shared-DyzbUi6c.d.ts} +4 -2
  11. package/dist/astro-shared-DyzbUi6c.d.ts.map +1 -0
  12. package/dist/astro.d.ts +1 -1
  13. package/dist/astro.js +1 -1
  14. package/dist/{core-Dvqm7w2y.js → capabilities-BuZUQpiD.js} +64 -2
  15. package/dist/capabilities-BuZUQpiD.js.map +1 -0
  16. package/dist/{core-BhiA9fFi.d.ts → capabilities-yC9TsHDI.d.ts} +20 -2
  17. package/dist/capabilities-yC9TsHDI.d.ts.map +1 -0
  18. package/dist/client.min.js +1 -1
  19. package/dist/development/astro-client.js +6 -3
  20. package/dist/development/astro-client.js.map +1 -1
  21. package/dist/development/astro-server.js +2 -1
  22. package/dist/development/astro-server.js.map +1 -1
  23. package/dist/development/astro-shared-BT45auwR.js.map +1 -1
  24. package/dist/development/astro.js +1 -1
  25. package/dist/development/{core-DB3sQz4h.js → capabilities-DhOJmeoJ.js} +64 -2
  26. package/dist/development/capabilities-DhOJmeoJ.js.map +1 -0
  27. package/dist/development/{dom-D9cY6l1R.js → dom-BKc6V_Kz.js} +8 -3
  28. package/dist/development/dom-BKc6V_Kz.js.map +1 -0
  29. package/dist/development/index.js +3 -38
  30. package/dist/development/jsx-runtime.js.map +1 -1
  31. package/dist/development/konva.js +121 -0
  32. package/dist/development/konva.js.map +1 -0
  33. package/dist/development/motion.js +217 -0
  34. package/dist/development/motion.js.map +1 -0
  35. package/dist/development/renderer.js +177 -0
  36. package/dist/development/renderer.js.map +1 -0
  37. package/dist/development/server.js +3 -2
  38. package/dist/development/server.js.map +1 -1
  39. package/dist/development/src-Dh-d6w4y.js +38 -0
  40. package/dist/development/src-Dh-d6w4y.js.map +1 -0
  41. package/dist/development/three.js +438 -0
  42. package/dist/development/three.js.map +1 -0
  43. package/dist/development/vite-CSHoxzXU.js +240 -0
  44. package/dist/development/vite-CSHoxzXU.js.map +1 -0
  45. package/dist/development/vite.js +1 -1
  46. package/dist/{dom-BR9o9wZW.js → dom-B2rm8o2L.js} +8 -3
  47. package/dist/dom-B2rm8o2L.js.map +1 -0
  48. package/dist/index-BdwxmSKg.d.ts +24 -0
  49. package/dist/index-BdwxmSKg.d.ts.map +1 -0
  50. package/dist/index.d.ts +4 -24
  51. package/dist/index.js +3 -38
  52. package/dist/{jsx-runtime-BzGV18VO.d.ts → jsx-runtime-CZU7F8Qz.d.ts} +6 -4
  53. package/dist/jsx-runtime-CZU7F8Qz.d.ts.map +1 -0
  54. package/dist/jsx-runtime.d.ts +2 -2
  55. package/dist/jsx-runtime.js.map +1 -1
  56. package/dist/konva.d.ts +32 -0
  57. package/dist/konva.d.ts.map +1 -0
  58. package/dist/konva.js +121 -0
  59. package/dist/konva.js.map +1 -0
  60. package/dist/motion.d.ts +44 -0
  61. package/dist/motion.d.ts.map +1 -0
  62. package/dist/motion.js +217 -0
  63. package/dist/motion.js.map +1 -0
  64. package/dist/renderer.d.ts +24 -0
  65. package/dist/renderer.d.ts.map +1 -0
  66. package/dist/renderer.js +177 -0
  67. package/dist/renderer.js.map +1 -0
  68. package/dist/server.d.ts +1 -1
  69. package/dist/server.d.ts.map +1 -1
  70. package/dist/server.js +3 -2
  71. package/dist/server.js.map +1 -1
  72. package/dist/size.json +16 -16
  73. package/dist/src-BZxX4xbU.js +38 -0
  74. package/dist/src-BZxX4xbU.js.map +1 -0
  75. package/dist/three.d.ts +110 -0
  76. package/dist/three.d.ts.map +1 -0
  77. package/dist/three.js +438 -0
  78. package/dist/three.js.map +1 -0
  79. package/dist/vite-CSHoxzXU.js +240 -0
  80. package/dist/vite-CSHoxzXU.js.map +1 -0
  81. package/dist/vite.js +1 -1
  82. package/package.json +56 -11
  83. package/src/astro-client.ts +1 -0
  84. package/src/astro-server.ts +1 -0
  85. package/src/astro-shared.ts +3 -0
  86. package/src/capabilities.ts +88 -0
  87. package/src/compiler.ts +251 -178
  88. package/src/core.ts +11 -0
  89. package/src/dom.ts +4 -1
  90. package/src/index.ts +5 -0
  91. package/src/jsx-runtime.ts +4 -0
  92. package/src/jsx-types.d.ts +3 -1
  93. package/src/konva.ts +159 -0
  94. package/src/motion.ts +406 -0
  95. package/src/renderer.ts +241 -0
  96. package/src/server.ts +3 -0
  97. package/src/three-events.ts +330 -0
  98. package/src/three.ts +350 -0
  99. package/dist/astro-shared-DkZaqX7L.d.ts.map +0 -1
  100. package/dist/core-BhiA9fFi.d.ts.map +0 -1
  101. package/dist/core-Dvqm7w2y.js.map +0 -1
  102. package/dist/development/core-DB3sQz4h.js.map +0 -1
  103. package/dist/development/dom-D9cY6l1R.js.map +0 -1
  104. package/dist/development/index.js.map +0 -1
  105. package/dist/development/vite-CQchIQ_-.js +0 -126
  106. package/dist/development/vite-CQchIQ_-.js.map +0 -1
  107. package/dist/dom-BR9o9wZW.js.map +0 -1
  108. package/dist/index.d.ts.map +0 -1
  109. package/dist/index.js.map +0 -1
  110. package/dist/jsx-runtime-BzGV18VO.d.ts.map +0 -1
  111. package/dist/vite-CQchIQ_-.js +0 -126
  112. package/dist/vite-CQchIQ_-.js.map +0 -1
@@ -0,0 +1,217 @@
1
+ import { animate, cancelFrame, frame, hover, motionValue, press, readStyleValue, styleEffect } from "motion";
2
+ // src/motion.ts
3
+ const transform = /^(x|y|z|translate.*|scale.*|rotate.*|skew.*|transformPerspective)$/;
4
+ const allowed = /* @__PURE__ */ new Set([
5
+ `initial`,
6
+ `animate`,
7
+ `transition`,
8
+ `whileHover`,
9
+ `whileTap`
10
+ ]);
11
+ function equal(a, b) {
12
+ return Object.is(a, b) || Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((value, index) => Object.is(value, b[index]));
13
+ }
14
+ function attach(target, options) {
15
+ if (target.kind !== `dom` && (!target.read || !target.write)) throw new Error(`spa/motion: renderer ${target.kind} does not support motion`);
16
+ const element = target.kind === `dom` ? target.node : void 0;
17
+ const properties = /* @__PURE__ */ new Map();
18
+ const originalStyles = /* @__PURE__ */ new Map();
19
+ let styles;
20
+ let props = {};
21
+ let hovered = false;
22
+ let tapped = false;
23
+ let started = false;
24
+ let dead = false;
25
+ let gestures = [];
26
+ const preference = options.reducedMotion !== `never` && typeof matchMedia === `function` ? matchMedia(`(prefers-reduced-motion: reduce)`) : void 0;
27
+ const reduced = () => options.reducedMotion === `always` || options.reducedMotion !== `never` && preference?.matches;
28
+ const read = (key, fallback) => {
29
+ const value = element ? readStyleValue(element, key) : target.read(key);
30
+ return value === void 0 || value === `` ? typeof fallback === `number` ? key.startsWith(`scale`) || key === `opacity` ? 1 : 0 : fallback : value;
31
+ };
32
+ const bindStyles = () => {
33
+ styles?.();
34
+ if (element) styles = styleEffect([element], Object.fromEntries([...properties].map(([key, property]) => [key, property.values[0]])));
35
+ };
36
+ const ensure = (key, goal, initial) => {
37
+ const existing = properties.get(key);
38
+ if (existing) {
39
+ if (existing.values.length !== (Array.isArray(goal) ? goal.length : 1)) throw new Error(`spa/motion: cannot change the shape of ${key}`);
40
+ return existing;
41
+ }
42
+ const base = read(key, goal);
43
+ const rest = !Array.isArray(goal) && Array.isArray(base) ? base[0] : base;
44
+ let start = initial === false ? goal : initial[key] ?? rest;
45
+ if (!Array.isArray(goal) && Array.isArray(start)) start = start[0];
46
+ if (Array.isArray(goal) && (!Array.isArray(start) || start.length !== goal.length)) throw new Error(`spa/motion: ${key} requires matching numeric tuples`);
47
+ const values = (Array.isArray(start) ? start : [start]).map((value) => motionValue(value));
48
+ const unsubscribers = [];
49
+ if (element) {
50
+ if (Array.isArray(goal)) throw new Error(`spa/motion: DOM targets must be scalar styles or transforms`);
51
+ const cssKey = transform.test(key) ? `transform` : key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
52
+ if (!originalStyles.has(cssKey)) originalStyles.set(cssKey, {
53
+ value: element.style.getPropertyValue(cssKey),
54
+ priority: element.style.getPropertyPriority(cssKey)
55
+ });
56
+ } else {
57
+ const write = () => {
58
+ target.write(key, Array.isArray(goal) ? values.map((value) => value.get()) : values[0].get());
59
+ };
60
+ for (const value of values) unsubscribers.push(value.on(`change`, write));
61
+ write();
62
+ }
63
+ const property = {
64
+ values,
65
+ base,
66
+ rest,
67
+ target: start,
68
+ release() {
69
+ for (const release of unsubscribers) release();
70
+ for (const value of values) value.destroy();
71
+ }
72
+ };
73
+ properties.set(key, property);
74
+ return property;
75
+ };
76
+ const refresh = () => {
77
+ if (dead) return;
78
+ const initial = props[`initial`] ?? {};
79
+ const animateTo = props[`animate`] ?? {};
80
+ const hoverTo = props[`whileHover`] ?? {};
81
+ const tapTo = props[`whileTap`] ?? {};
82
+ const goals = {
83
+ ...animateTo,
84
+ ...hovered ? hoverTo : {},
85
+ ...tapped ? tapTo : {}
86
+ };
87
+ const keys = /* @__PURE__ */ new Set([
88
+ ...Object.keys(initial || {}),
89
+ ...Object.keys(animateTo),
90
+ ...Object.keys(hoverTo),
91
+ ...Object.keys(tapTo)
92
+ ]);
93
+ let added = false;
94
+ for (const key of keys) {
95
+ const sample = goals[key] ?? (initial === false ? void 0 : initial[key]) ?? hoverTo[key] ?? tapTo[key];
96
+ if (sample === void 0) continue;
97
+ const had = properties.has(key);
98
+ ensure(key, sample, started ? {} : initial);
99
+ if (!had) added = true;
100
+ }
101
+ if (added) bindStyles();
102
+ const transition = props[`transition`] ?? { type: `spring` };
103
+ for (const [key, property] of properties) {
104
+ const goal = goals[key] ?? (initial === false ? void 0 : initial[key]) ?? property.rest;
105
+ if (equal(property.target, goal)) continue;
106
+ property.target = Array.isArray(goal) ? [...goal] : goal;
107
+ const next = Array.isArray(goal) ? goal : [goal];
108
+ if (next.length !== property.values.length) throw new Error(`spa/motion: cannot change the shape of ${key}`);
109
+ property.values.forEach((value, index) => {
110
+ if (reduced() || !started && initial === false) value.jump(next[index]);
111
+ else animate(value, next[index], transition);
112
+ });
113
+ }
114
+ started = true;
115
+ };
116
+ const clearGestures = () => {
117
+ for (const release of gestures) release();
118
+ gestures = [];
119
+ };
120
+ const installGestures = () => {
121
+ clearGestures();
122
+ if (element) {
123
+ if (props[`whileHover`]) gestures.push(hover([element], () => {
124
+ hovered = true;
125
+ refresh();
126
+ return () => {
127
+ hovered = false;
128
+ refresh();
129
+ };
130
+ }));
131
+ if (props[`whileTap`]) gestures.push(press([element], () => {
132
+ tapped = true;
133
+ refresh();
134
+ return () => {
135
+ tapped = false;
136
+ refresh();
137
+ };
138
+ }));
139
+ } else if (props[`whileHover`] || props[`whileTap`]) {
140
+ if (!target.listen) throw new Error(`spa/motion: ${target.kind} gestures require a renderer event adapter`);
141
+ const listen = (event, run) => gestures.push(target.listen(event, run));
142
+ listen(`pointerenter`, () => {
143
+ hovered = true;
144
+ refresh();
145
+ });
146
+ listen(`pointerleave`, () => {
147
+ hovered = false;
148
+ tapped = false;
149
+ refresh();
150
+ });
151
+ listen(`pointerdown`, () => {
152
+ tapped = true;
153
+ refresh();
154
+ });
155
+ listen(`pointerup`, () => {
156
+ tapped = false;
157
+ refresh();
158
+ });
159
+ listen(`pointercancel`, () => {
160
+ tapped = false;
161
+ refresh();
162
+ });
163
+ }
164
+ };
165
+ const preferenceChanged = () => {
166
+ if (reduced()) for (const property of properties.values()) {
167
+ const goal = Array.isArray(property.target) ? property.target : [property.target];
168
+ property.values.forEach((value, i) => {
169
+ value.jump(goal[i]);
170
+ });
171
+ }
172
+ };
173
+ preference?.addEventListener(`change`, preferenceChanged);
174
+ return {
175
+ update(next) {
176
+ if (dead) return;
177
+ for (const key of Object.keys(next)) if (!allowed.has(key)) throw new Error(`spa/motion: unknown property motion:${key}`);
178
+ const gestureChange = !started || Boolean(next[`whileHover`]) !== Boolean(props[`whileHover`]) || Boolean(next[`whileTap`]) !== Boolean(props[`whileTap`]);
179
+ props = next;
180
+ if (gestureChange) installGestures();
181
+ refresh();
182
+ },
183
+ dispose() {
184
+ if (dead) return;
185
+ dead = true;
186
+ clearGestures();
187
+ preference?.removeEventListener(`change`, preferenceChanged);
188
+ styles?.();
189
+ for (const [key, property] of properties) {
190
+ property.release();
191
+ if (!element) target.write(key, property.base);
192
+ }
193
+ for (const [key, value] of originalStyles) if (value.value) element.style.setProperty(key, value.value, value.priority);
194
+ else element.style.removeProperty(key);
195
+ properties.clear();
196
+ }
197
+ };
198
+ }
199
+ /** Explicit, root-scoped motion:* integration. Importing it never registers globally. */
200
+ function motionCapability(options = {}) {
201
+ return {
202
+ namespace: `motion`,
203
+ attach: (target) => attach(target, options),
204
+ scheduleFrame(callback) {
205
+ const run = ({ timestamp }) => {
206
+ callback(timestamp);
207
+ };
208
+ frame.render(run, true);
209
+ return () => {
210
+ cancelFrame(run);
211
+ };
212
+ }
213
+ };
214
+ }
215
+ export { motionCapability };
216
+
217
+ //# sourceMappingURL=motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.js","names":[],"sources":["../../src/motion.ts"],"sourcesContent":["import type { MotionValue, ValueAnimationTransition } from \"motion\"\nimport {\n\tanimate,\n\tcancelFrame,\n\tframe,\n\thover,\n\tmotionValue,\n\tpress,\n\treadStyleValue,\n\tstyleEffect,\n} from \"motion\"\n\nimport type {\n\tCapability,\n\tCapabilityBinding,\n\tCapabilityTarget,\n} from \"./capabilities.ts\"\n\nexport type MotionScalar = number | string\nexport type MotionDOMTarget = Partial<\n\tRecord<\n\t\t| keyof CSSStyleDeclaration\n\t\t| `x`\n\t\t| `y`\n\t\t| `z`\n\t\t| `scale`\n\t\t| `scaleX`\n\t\t| `scaleY`\n\t\t| `rotate`\n\t\t| `rotateX`\n\t\t| `rotateY`\n\t\t| `rotateZ`\n\t\t| `skewX`\n\t\t| `skewY`\n\t\t| `--${string}`,\n\t\tMotionScalar\n\t>\n>\nexport interface MotionThreeTarget {\n\tposition?: readonly [number, number, number]\n\trotation?: readonly [number, number, number]\n\tscale?: number | readonly [number, number, number]\n\topacity?: number\n\tintensity?: number\n\tcolor?: string\n}\nexport type MotionTarget<Kind extends string> = Kind extends `dom`\n\t? MotionDOMTarget\n\t: Kind extends `three`\n\t\t? MotionThreeTarget\n\t\t: Record<string, MotionScalar>\n/** Supported transition options; keep public declarations independent of optional peer types. */\nexport interface MotionTransition {\n\ttype?: `spring` | `tween`\n\tstiffness?: number\n\tdamping?: number\n\tmass?: number\n\tvelocity?: number\n\trestSpeed?: number\n\trestDelta?: number\n\tbounce?: number\n\tvisualDuration?: number\n\tduration?: number\n\tdelay?: number\n\tease?:\n\t\t| `linear`\n\t\t| `easeIn`\n\t\t| `easeOut`\n\t\t| `easeInOut`\n\t\t| `circIn`\n\t\t| `circOut`\n\t\t| `circInOut`\n\t\t| `backIn`\n\t\t| `backOut`\n\t\t| `backInOut`\n\t\t| readonly [number, number, number, number]\n}\nexport interface MotionAttributes<Kind extends string = `dom`> {\n\t[`motion:initial`]?: MotionTarget<Kind> | false\n\t[`motion:animate`]?: MotionTarget<Kind>\n\t[`motion:transition`]?: MotionTransition\n\t[`motion:whileHover`]?: MotionTarget<Kind>\n\t[`motion:whileTap`]?: MotionTarget<Kind>\n}\n\n// eslint-disable-next-line quotes -- TypeScript module augmentation requires a string literal.\ndeclare module \"@atom.io/spa/jsx-runtime\" {\n\t// oxlint-disable-next-line typescript/no-empty-interface -- Declaration merging adds optional motion attributes.\n\tinterface CapabilityAttributes<\n\t\tKind extends string,\n\t> extends MotionAttributes<Kind> {}\n}\n\nexport interface MotionCapabilityOptions {\n\t/** Respect the user's reduced-motion preference by default. */\n\treducedMotion?: `user` | `always` | `never`\n}\ntype TargetValues = Record<string, MotionScalar | readonly number[]>\ninterface AnimatedProperty {\n\tvalues: MotionValue<MotionScalar>[]\n\tbase: MotionScalar | readonly number[]\n\trest: MotionScalar | readonly number[]\n\ttarget: MotionScalar | readonly number[]\n\trelease(): void\n}\nconst transform =\n\t/^(x|y|z|translate.*|scale.*|rotate.*|skew.*|transformPerspective)$/\nconst allowed = new Set([\n\t`initial`,\n\t`animate`,\n\t`transition`,\n\t`whileHover`,\n\t`whileTap`,\n])\nfunction equal(a: unknown, b: unknown): boolean {\n\treturn (\n\t\tObject.is(a, b) ||\n\t\t(Array.isArray(a) &&\n\t\t\tArray.isArray(b) &&\n\t\t\ta.length === b.length &&\n\t\t\ta.every((value, index) => Object.is(value, b[index])))\n\t)\n}\n\nfunction attach(\n\ttarget: CapabilityTarget,\n\toptions: MotionCapabilityOptions,\n): CapabilityBinding {\n\tif (target.kind !== `dom` && (!target.read || !target.write))\n\t\tthrow new Error(\n\t\t\t`spa/motion: renderer ${target.kind} does not support motion`,\n\t\t)\n\tconst element =\n\t\ttarget.kind === `dom` ? (target.node as HTMLElement | SVGElement) : undefined\n\tconst properties = new Map<string, AnimatedProperty>()\n\tconst originalStyles = new Map<string, { value: string; priority: string }>()\n\tlet styles: (() => void) | undefined\n\tlet props: Record<string, unknown> = {}\n\tlet hovered = false\n\tlet tapped = false\n\tlet started = false\n\tlet dead = false\n\tlet gestures: (() => void)[] = []\n\tconst preference =\n\t\toptions.reducedMotion !== `never` && typeof matchMedia === `function`\n\t\t\t? matchMedia(`(prefers-reduced-motion: reduce)`)\n\t\t\t: undefined\n\tconst reduced = () =>\n\t\toptions.reducedMotion === `always` ||\n\t\t(options.reducedMotion !== `never` && preference?.matches)\n\tconst read = (key: string, fallback: unknown): any => {\n\t\tconst value = element ? readStyleValue(element, key) : target.read!(key)\n\t\treturn value === undefined || value === ``\n\t\t\t? typeof fallback === `number`\n\t\t\t\t? key.startsWith(`scale`) || key === `opacity`\n\t\t\t\t\t? 1\n\t\t\t\t\t: 0\n\t\t\t\t: fallback\n\t\t\t: value\n\t}\n\tconst bindStyles = () => {\n\t\tstyles?.()\n\t\tif (element)\n\t\t\tstyles = styleEffect(\n\t\t\t\t[element],\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\t[...properties].map(([key, property]) => [key, property.values[0]]),\n\t\t\t\t) as any,\n\t\t\t)\n\t}\n\tconst ensure = (\n\t\tkey: string,\n\t\tgoal: MotionScalar | readonly number[],\n\t\tinitial: TargetValues | false,\n\t): AnimatedProperty => {\n\t\tconst existing = properties.get(key)\n\t\tif (existing) {\n\t\t\tif (existing.values.length !== (Array.isArray(goal) ? goal.length : 1))\n\t\t\t\tthrow new Error(`spa/motion: cannot change the shape of ${key}`)\n\t\t\treturn existing\n\t\t}\n\t\tconst base = read(key, goal) as MotionScalar | readonly number[]\n\t\tconst rest = !Array.isArray(goal) && Array.isArray(base) ? base[0]! : base\n\t\tlet start = initial === false ? goal : (initial[key] ?? rest)\n\t\tif (!Array.isArray(goal) && Array.isArray(start)) start = start[0]!\n\t\tif (\n\t\t\tArray.isArray(goal) &&\n\t\t\t(!Array.isArray(start) || start.length !== goal.length)\n\t\t)\n\t\t\tthrow new Error(`spa/motion: ${key} requires matching numeric tuples`)\n\t\tconst values = (Array.isArray(start) ? start : [start]).map((value) =>\n\t\t\tmotionValue(value),\n\t\t) as MotionValue<MotionScalar>[]\n\t\tconst unsubscribers: (() => void)[] = []\n\t\tif (element) {\n\t\t\tif (Array.isArray(goal))\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`spa/motion: DOM targets must be scalar styles or transforms`,\n\t\t\t\t)\n\t\t\tconst cssKey = transform.test(key)\n\t\t\t\t? `transform`\n\t\t\t\t: key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)\n\t\t\tif (!originalStyles.has(cssKey))\n\t\t\t\toriginalStyles.set(cssKey, {\n\t\t\t\t\tvalue: element.style.getPropertyValue(cssKey),\n\t\t\t\t\tpriority: element.style.getPropertyPriority(cssKey),\n\t\t\t\t})\n\t\t} else {\n\t\t\tconst write = () => {\n\t\t\t\ttarget.write!(\n\t\t\t\t\tkey,\n\t\t\t\t\tArray.isArray(goal)\n\t\t\t\t\t\t? values.map((value) => value.get())\n\t\t\t\t\t\t: values[0].get(),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const value of values) unsubscribers.push(value.on(`change`, write))\n\t\t\twrite()\n\t\t}\n\t\tconst property: AnimatedProperty = {\n\t\t\tvalues,\n\t\t\tbase,\n\t\t\trest,\n\t\t\ttarget: start,\n\t\t\trelease() {\n\t\t\t\tfor (const release of unsubscribers) release()\n\t\t\t\tfor (const value of values) value.destroy()\n\t\t\t},\n\t\t}\n\t\tproperties.set(key, property)\n\t\treturn property\n\t}\n\tconst refresh = () => {\n\t\tif (dead) return\n\t\tconst initial = (props[`initial`] ?? {}) as TargetValues | false\n\t\tconst animateTo = (props[`animate`] ?? {}) as TargetValues\n\t\tconst hoverTo = (props[`whileHover`] ?? {}) as TargetValues\n\t\tconst tapTo = (props[`whileTap`] ?? {}) as TargetValues\n\t\tconst goals = {\n\t\t\t...animateTo,\n\t\t\t...(hovered ? hoverTo : {}),\n\t\t\t...(tapped ? tapTo : {}),\n\t\t}\n\t\tconst keys = new Set([\n\t\t\t...Object.keys(initial || {}),\n\t\t\t...Object.keys(animateTo),\n\t\t\t...Object.keys(hoverTo),\n\t\t\t...Object.keys(tapTo),\n\t\t])\n\t\tlet added = false\n\t\tfor (const key of keys) {\n\t\t\tconst sample =\n\t\t\t\tgoals[key] ??\n\t\t\t\t(initial === false ? undefined : initial[key]) ??\n\t\t\t\thoverTo[key] ??\n\t\t\t\ttapTo[key]\n\t\t\tif (sample === undefined) continue\n\t\t\tconst had = properties.has(key)\n\t\t\tensure(key, sample, started ? {} : initial)\n\t\t\tif (!had) added = true\n\t\t}\n\t\tif (added) bindStyles()\n\t\tconst transition = (props[`transition`] ?? {\n\t\t\ttype: `spring`,\n\t\t}) as ValueAnimationTransition\n\t\tfor (const [key, property] of properties) {\n\t\t\tconst goal =\n\t\t\t\tgoals[key] ??\n\t\t\t\t(initial === false ? undefined : initial[key]) ??\n\t\t\t\tproperty.rest\n\t\t\tif (equal(property.target, goal)) continue\n\t\t\tproperty.target = Array.isArray(goal) ? [...goal] : goal\n\t\t\tconst next = Array.isArray(goal) ? goal : [goal]\n\t\t\tif (next.length !== property.values.length)\n\t\t\t\tthrow new Error(`spa/motion: cannot change the shape of ${key}`)\n\t\t\tproperty.values.forEach((value, index) => {\n\t\t\t\tif (reduced() || (!started && initial === false)) value.jump(next[index])\n\t\t\t\telse animate(value, next[index], transition)\n\t\t\t})\n\t\t}\n\t\tstarted = true\n\t}\n\tconst clearGestures = () => {\n\t\tfor (const release of gestures) release()\n\t\tgestures = []\n\t}\n\tconst installGestures = () => {\n\t\tclearGestures()\n\t\tif (element) {\n\t\t\tif (props[`whileHover`])\n\t\t\t\tgestures.push(\n\t\t\t\t\thover([element], () => {\n\t\t\t\t\t\thovered = true\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\thovered = false\n\t\t\t\t\t\t\trefresh()\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\tif (props[`whileTap`])\n\t\t\t\tgestures.push(\n\t\t\t\t\tpress([element], () => {\n\t\t\t\t\t\ttapped = true\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\ttapped = false\n\t\t\t\t\t\t\trefresh()\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t} else if (props[`whileHover`] || props[`whileTap`]) {\n\t\t\tif (!target.listen)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`spa/motion: ${target.kind} gestures require a renderer event adapter`,\n\t\t\t\t)\n\t\t\tconst listen = (event: string, run: () => void) =>\n\t\t\t\tgestures.push(target.listen!(event, run))\n\t\t\tlisten(`pointerenter`, () => {\n\t\t\t\thovered = true\n\t\t\t\trefresh()\n\t\t\t})\n\t\t\tlisten(`pointerleave`, () => {\n\t\t\t\thovered = false\n\t\t\t\ttapped = false\n\t\t\t\trefresh()\n\t\t\t})\n\t\t\tlisten(`pointerdown`, () => {\n\t\t\t\ttapped = true\n\t\t\t\trefresh()\n\t\t\t})\n\t\t\tlisten(`pointerup`, () => {\n\t\t\t\ttapped = false\n\t\t\t\trefresh()\n\t\t\t})\n\t\t\tlisten(`pointercancel`, () => {\n\t\t\t\ttapped = false\n\t\t\t\trefresh()\n\t\t\t})\n\t\t}\n\t}\n\tconst preferenceChanged = () => {\n\t\tif (reduced()) {\n\t\t\tfor (const property of properties.values()) {\n\t\t\t\tconst goal = Array.isArray(property.target)\n\t\t\t\t\t? property.target\n\t\t\t\t\t: [property.target]\n\t\t\t\tproperty.values.forEach((value, i) => {\n\t\t\t\t\tvalue.jump(goal[i])\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\tpreference?.addEventListener(`change`, preferenceChanged)\n\treturn {\n\t\tupdate(next) {\n\t\t\tif (dead) return\n\t\t\tfor (const key of Object.keys(next))\n\t\t\t\tif (!allowed.has(key))\n\t\t\t\t\tthrow new Error(`spa/motion: unknown property motion:${key}`)\n\t\t\tconst gestureChange =\n\t\t\t\t!started ||\n\t\t\t\tBoolean(next[`whileHover`]) !== Boolean(props[`whileHover`]) ||\n\t\t\t\tBoolean(next[`whileTap`]) !== Boolean(props[`whileTap`])\n\t\t\tprops = next\n\t\t\tif (gestureChange) installGestures()\n\t\t\trefresh()\n\t\t},\n\t\tdispose() {\n\t\t\tif (dead) return\n\t\t\tdead = true\n\t\t\tclearGestures()\n\t\t\tpreference?.removeEventListener(`change`, preferenceChanged)\n\t\t\tstyles?.()\n\t\t\tfor (const [key, property] of properties) {\n\t\t\t\tproperty.release()\n\t\t\t\tif (!element) target.write!(key, property.base)\n\t\t\t}\n\t\t\tfor (const [key, value] of originalStyles) {\n\t\t\t\tif (value.value)\n\t\t\t\t\telement!.style.setProperty(key, value.value, value.priority)\n\t\t\t\telse element!.style.removeProperty(key)\n\t\t\t}\n\t\t\tproperties.clear()\n\t\t},\n\t}\n}\n\n/** Explicit, root-scoped motion:* integration. Importing it never registers globally. */\nexport function motionCapability(\n\toptions: MotionCapabilityOptions = {},\n): Capability {\n\treturn {\n\t\tnamespace: `motion`,\n\t\tattach: (target) => attach(target, options),\n\t\tscheduleFrame(callback) {\n\t\t\tconst run = ({ timestamp }: { timestamp: number }) => {\n\t\t\t\tcallback(timestamp)\n\t\t\t}\n\t\t\tframe.render(run, true)\n\t\t\treturn () => {\n\t\t\t\tcancelFrame(run)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;AAyGA,MAAM,YACL;AACD,MAAM,0BAAU,IAAI,IAAI;CACvB;CACA;CACA;CACA;CACA;AACD,CAAC;AACD,SAAS,MAAM,GAAY,GAAqB;CAC/C,OACC,OAAO,GAAG,GAAG,CAAC,KACb,MAAM,QAAQ,CAAC,KACf,MAAM,QAAQ,CAAC,KACf,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,OAAO,UAAU,OAAO,GAAG,OAAO,EAAE,MAAM,CAAC;AAEvD;AAEA,SAAS,OACR,QACA,SACoB;CACpB,IAAI,OAAO,SAAS,UAAU,CAAC,OAAO,QAAQ,CAAC,OAAO,QACrD,MAAM,IAAI,MACT,wBAAwB,OAAO,KAAK,yBACrC;CACD,MAAM,UACL,OAAO,SAAS,QAAS,OAAO,OAAoC,KAAA;CACrE,MAAM,6BAAa,IAAI,IAA8B;CACrD,MAAM,iCAAiB,IAAI,IAAiD;CAC5E,IAAI;CACJ,IAAI,QAAiC,CAAC;CACtC,IAAI,UAAU;CACd,IAAI,SAAS;CACb,IAAI,UAAU;CACd,IAAI,OAAO;CACX,IAAI,WAA2B,CAAC;CAChC,MAAM,aACL,QAAQ,kBAAkB,WAAW,OAAO,eAAe,aACxD,WAAW,kCAAkC,IAC7C,KAAA;CACJ,MAAM,gBACL,QAAQ,kBAAkB,YACzB,QAAQ,kBAAkB,WAAW,YAAY;CACnD,MAAM,QAAQ,KAA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,CAAC,SAAS,OAAO,MAAO,KAAK,SAAS,IAAI;GAC/C;GACA,KAAK,MAAM,CAAC,KAAK,UAAU,gBAC1B,IAAI,MAAM,OACT,QAAS,MAAM,YAAY,KAAK,MAAM,OAAO,MAAM,QAAQ;QACvD,QAAS,MAAM,eAAe,GAAG;GAEvC,WAAW,MAAM;EAClB;CACD;AACD;;AAGA,SAAgB,iBACf,UAAmC,CAAC,GACvB;CACb,OAAO;EACN,WAAW;EACX,SAAS,WAAW,OAAO,QAAQ,OAAO;EAC1C,cAAc,UAAU;GACvB,MAAM,OAAO,EAAE,gBAAuC;IACrD,SAAS,SAAS;GACnB;GACA,MAAM,OAAO,KAAK,IAAI;GACtB,aAAa;IACZ,YAAY,GAAG;GAChB;EACD;CACD;AACD"}
@@ -0,0 +1,177 @@
1
+ import { C as within, a as createScope, c as invalidate, f as owner, h as untrack, i as createRoot, l as observe, n as capabilityProps, o as dispose, s as fail } from "./capabilities-DhOJmeoJ.js";
2
+ import { Fragment, merge } from "./jsx-runtime.js";
3
+ // src/renderer.ts
4
+ /** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */
5
+ function createSceneRenderer(host) {
6
+ function mount(source, scope, changed) {
7
+ let entries = [];
8
+ observe(scope, source, (next) => {
9
+ const values = Array.isArray(next) ? next.flat(Infinity) : [next];
10
+ const old = new Map(entries.map((entry, i) => [key(entry.value, i), entry]));
11
+ const seen = /* @__PURE__ */ new Set();
12
+ entries = values.map((value, i) => {
13
+ const id = key(value, i);
14
+ if (seen.has(id)) throw new Error(`spa: duplicate scene key`);
15
+ seen.add(id);
16
+ let entry = old.get(id);
17
+ old.delete(id);
18
+ if (entry && !same(entry.value, value)) {
19
+ dispose(entry.scope);
20
+ entry = void 0;
21
+ }
22
+ if (entry) {
23
+ entry.value = value;
24
+ invalidate(entry.scope);
25
+ return entry;
26
+ }
27
+ const childScope = createScope(scope);
28
+ const created = {
29
+ scope: childScope,
30
+ value,
31
+ nodes: null
32
+ };
33
+ created.nodes = build(() => created.value, childScope, changed);
34
+ return created;
35
+ });
36
+ for (const entry of old.values()) dispose(entry.scope);
37
+ changed();
38
+ });
39
+ return () => entries.flatMap((entry) => entry.nodes());
40
+ }
41
+ function key(value, i) {
42
+ const explicit = value?.props?.[`key`];
43
+ return explicit == null ? `index:${i}` : `key:${explicit}`;
44
+ }
45
+ function same(a, b) {
46
+ return typeof a === typeof b && a?.type === b?.type;
47
+ }
48
+ function build(source, scope, changed) {
49
+ const value = untrack(source);
50
+ if (typeof value === `function`) return mount(() => source()(), scope, changed);
51
+ if (value == null || typeof value === `boolean`) return () => [];
52
+ if (typeof value !== `object`) throw new Error(`spa: scene children must be nodes`);
53
+ if (!(`type` in value) || !(`props` in value)) throw new Error(`spa: invalid scene child`);
54
+ const vnode = value;
55
+ const props = merge(() => source().props);
56
+ if (!vnode.type || vnode.type === Fragment) return mount(() => props[`children`], scope, changed);
57
+ if (typeof vnode.type === `function`) {
58
+ const output = within(scope, () => untrack(() => vnode.type(props)));
59
+ return mount(() => output, scope, changed);
60
+ }
61
+ const node = host.create(vnode.type, untrack(() => props));
62
+ scope._cleanups.add(() => {
63
+ host.destroy(node);
64
+ });
65
+ const nativeProps = capabilityProps(scope, host.target?.(node) ?? {
66
+ kind: `scene`,
67
+ node
68
+ });
69
+ let previous = {};
70
+ observe(scope, () => ({ ...props }), (all) => {
71
+ const next = nativeProps(all);
72
+ host.update(node, next, previous);
73
+ previous = next;
74
+ });
75
+ let children = () => [];
76
+ const sync = () => {
77
+ host.children(node, children());
78
+ };
79
+ children = mount(() => props[`children`], scope, sync);
80
+ sync();
81
+ const ref = untrack(() => props[`ref`]);
82
+ if (ref) scope._root._mounts.unshift(() => {
83
+ if (!scope._dead) {
84
+ scope._cleanups.add(() => ref(null));
85
+ ref(node);
86
+ }
87
+ });
88
+ return () => [node];
89
+ }
90
+ function attach(setup, parent, scope) {
91
+ let nodes = () => [];
92
+ const sync = () => {
93
+ host.children(parent, nodes());
94
+ };
95
+ nodes = mount(() => untrack(setup), scope, sync);
96
+ sync();
97
+ scope._cleanups.add(() => {
98
+ host.children(parent, []);
99
+ });
100
+ }
101
+ return {
102
+ /** Attach beneath the current component; disposal follows its lifetime. */
103
+ mount(setup, parent) {
104
+ if (!owner) throw new Error(`spa: scene mount requires an owner`);
105
+ const scope = createScope(owner);
106
+ try {
107
+ attach(setup, parent, scope);
108
+ } catch (error) {
109
+ fail(scope, error);
110
+ }
111
+ },
112
+ render(setup, parent, options = {}) {
113
+ const root = createRoot(options);
114
+ try {
115
+ within(root, () => {
116
+ attach(setup, parent, root);
117
+ });
118
+ root.flush();
119
+ } catch (error) {
120
+ fail(root, error);
121
+ }
122
+ return {
123
+ flush: root.flush,
124
+ dispose: () => {
125
+ dispose(root);
126
+ }
127
+ };
128
+ }
129
+ };
130
+ }
131
+ /** Define a typed scene component without introducing another JSX runtime. */
132
+ function sceneComponent(type) {
133
+ return (props) => ({
134
+ type,
135
+ props
136
+ });
137
+ }
138
+ /** Bind imperative scene work to the current owner and its reactive dependencies. */
139
+ function bindScene(read, apply) {
140
+ observe(owner, read, apply);
141
+ }
142
+ /** Scene drawing follows an installed capability clock, or the browser clock. */
143
+ function onSceneFrame(callback) {
144
+ const scope = owner;
145
+ const clocks = [...scope._root._capabilities.values()].filter((capability) => capability.scheduleFrame);
146
+ if (clocks.length > 1) throw new Error(`spa: multiple frame clock capabilities`);
147
+ const draw = (time) => {
148
+ if (scope._dead) return;
149
+ try {
150
+ callback(time);
151
+ } catch (error) {
152
+ try {
153
+ fail(scope._root, error);
154
+ } catch (failure) {
155
+ scope._root.error(failure);
156
+ }
157
+ }
158
+ };
159
+ let stop;
160
+ if (clocks[0]) stop = clocks[0].scheduleFrame(draw);
161
+ else {
162
+ let frame = 0;
163
+ const tick = (time) => {
164
+ if (scope._dead) return;
165
+ draw(time);
166
+ if (!scope._dead) frame = requestAnimationFrame(tick);
167
+ };
168
+ frame = requestAnimationFrame(tick);
169
+ stop = () => {
170
+ cancelAnimationFrame(frame);
171
+ };
172
+ }
173
+ scope._cleanups.add(stop);
174
+ }
175
+ export { bindScene, createSceneRenderer, onSceneFrame, sceneComponent };
176
+
177
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +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\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[]): void\n\tdestroy(node: N): void\n}\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Child\n\tnodes: () => 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): () => N[] {\n\t\tlet entries: Entry<N>[] = []\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 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\tdispose(entry.scope)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\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 entry of old.values()) dispose(entry.scope)\n\t\t\tchanged()\n\t\t})\n\t\treturn () => entries.flatMap((entry) => entry.nodes())\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): () => 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)\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: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children())\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: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes())\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(callback: (time: number) => void): 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) 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"],"m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M,IAAI,MAAM,wCAAwC;CACzD,MAAM,QAAQ,SAAiB;EAC9B,IAAI,MAAM,OAAO;EACjB,IAAI;GACH,SAAS,IAAI;EACd,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,4 +1,4 @@
1
- import { b as within, f as untrack, n as createScope, r as dispose, t as createRoot, u as plain } from "./core-DB3sQz4h.js";
1
+ import { C as within, a as createScope, h as untrack, i as createRoot, o as dispose, p as plain, r as validateCapabilities, t as capabilityNamespace } from "./capabilities-DhOJmeoJ.js";
2
2
  import { Fragment } from "./jsx-runtime.js";
3
3
  // src/server.ts
4
4
  const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
@@ -35,10 +35,11 @@ function stringify(value, owner, namespace = `html`, selectValue) {
35
35
  if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
36
36
  if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
37
37
  const ns = type === `svg` ? `svg` : namespace;
38
+ validateCapabilities(owner, props);
38
39
  let attrs = ``;
39
40
  let textValue;
40
41
  for (let key of Object.keys(props)) {
41
- if (key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
42
+ if (capabilityNamespace(key) !== void 0 || key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
42
43
  if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
43
44
  let attribute = props[key];
44
45
  if (ns === `html`) {
@@ -1 +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({ \"&\": `&amp;`, \"<\": `&lt;`, \">\": `&gt;`, '\"': `&quot;`, \"'\": `&#39;` })[\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: 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 (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 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,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,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,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,MAAM,IAAI,UAAU,oBAAoB;CAC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
1
+ {"version":3,"file":"server.js","names":[],"sources":["../../src/server.ts"],"sourcesContent":["import { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport 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({ \"&\": `&amp;`, \"<\": `&lt;`, \">\": `&gt;`, '\"': `&quot;`, \"'\": `&#39;` })[\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: 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\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 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":";;;AAYA,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,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,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,MAAM,IAAI,UAAU,oBAAoB;CACzC,MAAM,EAAE,MAAM,UAAU;CACxB,IAAI,CAAC,QAAQ,SAAS,UACrB,OAAO,gBA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38 @@
1
+ import { S as useValue, f as owner, m as resolveStateToken } from "./capabilities-DhOJmeoJ.js";
2
+ import { withdraw } from "atom.io/internal";
3
+ // src/use-loadable.ts
4
+ function useLoadable(...params) {
5
+ const store = owner._root._store;
6
+ const [token] = params;
7
+ const family = token.type.endsWith(`_family`);
8
+ const selected = resolveStateToken(token, params[1]);
9
+ const read = useValue(selected);
10
+ const fallbackIndex = family ? 2 : 1;
11
+ const fallback = params[fallbackIndex];
12
+ const hasFallback = params.length > fallbackIndex;
13
+ let available = hasFallback;
14
+ let previous = fallback;
15
+ let error;
16
+ return () => {
17
+ const value = read();
18
+ const loading = value instanceof Promise;
19
+ if (!loading) {
20
+ previous = value;
21
+ available = true;
22
+ const state = withdraw(store, selected);
23
+ error = hasFallback && `catch` in state && state.catch.some((ErrorType) => value instanceof ErrorType) ? value : void 0;
24
+ }
25
+ if (!available) return `LOADING`;
26
+ return error ? {
27
+ loading,
28
+ value: fallback,
29
+ error
30
+ } : {
31
+ loading,
32
+ value: previous
33
+ };
34
+ };
35
+ }
36
+ export { useLoadable as t };
37
+
38
+ //# sourceMappingURL=src-Dh-d6w4y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-Dh-d6w4y.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"}