@atom.io/spa 0.0.8 → 0.0.10

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 (185) hide show
  1. package/README.md +194 -30
  2. package/README.mdx +78 -20
  3. package/dist/BrandMarkScene-CBYk-RJ2.js +140 -0
  4. package/dist/BrandMarkScene-CBYk-RJ2.js.map +1 -0
  5. package/dist/astro-application.d.ts +1 -1
  6. package/dist/astro-client.d.ts +1 -1
  7. package/dist/astro-client.d.ts.map +1 -1
  8. package/dist/astro-client.js +5 -4
  9. package/dist/astro-client.js.map +1 -1
  10. package/dist/astro-resumability-client.d.ts +1 -1
  11. package/dist/astro-server.js +4 -4
  12. package/dist/astro-server.js.map +1 -1
  13. package/dist/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
  14. package/dist/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
  15. package/dist/{astro-shared-DZp1x8RQ.d.ts → astro-shared-KxK9OUSj.d.ts} +2 -2
  16. package/dist/{astro-shared-DZp1x8RQ.d.ts.map → astro-shared-KxK9OUSj.d.ts.map} +1 -1
  17. package/dist/astro.d.ts +1 -1
  18. package/dist/astro.js +1 -1
  19. package/dist/brand-css.d.ts +2 -0
  20. package/dist/brand-model.d.ts +32 -0
  21. package/dist/brand-model.d.ts.map +1 -0
  22. package/dist/brand-model.js +120 -0
  23. package/dist/brand-model.js.map +1 -0
  24. package/dist/brand.css +37 -0
  25. package/dist/brand.d.ts +13 -0
  26. package/dist/brand.d.ts.map +1 -0
  27. package/dist/brand.js +94 -0
  28. package/dist/brand.js.map +1 -0
  29. package/dist/{capabilities-DNcnGRv_.d.ts → capabilities-ChgSs6bp.d.ts} +34 -6
  30. package/dist/capabilities-ChgSs6bp.d.ts.map +1 -0
  31. package/dist/client.min.js +1 -1
  32. package/dist/core-DD2giR6E.js +451 -0
  33. package/dist/core-DD2giR6E.js.map +1 -0
  34. package/dist/development/BrandMarkScene-BDdC7K5M.js +140 -0
  35. package/dist/development/BrandMarkScene-BDdC7K5M.js.map +1 -0
  36. package/dist/development/astro-client.js +5 -4
  37. package/dist/development/astro-client.js.map +1 -1
  38. package/dist/development/astro-server.js +4 -4
  39. package/dist/development/astro-server.js.map +1 -1
  40. package/dist/development/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
  41. package/dist/development/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
  42. package/dist/development/astro.js +1 -1
  43. package/dist/development/brand-model.js +120 -0
  44. package/dist/development/brand-model.js.map +1 -0
  45. package/dist/development/brand.css +37 -0
  46. package/dist/development/brand.js +94 -0
  47. package/dist/development/brand.js.map +1 -0
  48. package/dist/development/core-DrUd8x25.js +465 -0
  49. package/dist/development/core-DrUd8x25.js.map +1 -0
  50. package/dist/development/{dom-DQ0M3rLL.js → dom-CEVtlaav.js} +152 -36
  51. package/dist/development/dom-CEVtlaav.js.map +1 -0
  52. package/dist/development/floating.js +2 -6
  53. package/dist/development/floating.js.map +1 -1
  54. package/dist/development/hot.js +164 -0
  55. package/dist/development/hot.js.map +1 -0
  56. package/dist/development/identity-B8wTFkyW.js +121 -0
  57. package/dist/development/identity-B8wTFkyW.js.map +1 -0
  58. package/dist/development/index.js +5 -5
  59. package/dist/development/jsx-runtime-BGDPK50B.js +49 -0
  60. package/dist/development/jsx-runtime-BGDPK50B.js.map +1 -0
  61. package/dist/development/jsx-runtime.js +1 -25
  62. package/dist/development/konva.js +12 -5
  63. package/dist/development/konva.js.map +1 -1
  64. package/dist/development/motion.js +41 -39
  65. package/dist/development/motion.js.map +1 -1
  66. package/dist/development/renderer.js +41 -40
  67. package/dist/development/renderer.js.map +1 -1
  68. package/dist/development/{server-renderer-DCLoMdOX.js → server-renderer-zAqEL1g1.js} +8 -18
  69. package/dist/development/server-renderer-zAqEL1g1.js.map +1 -0
  70. package/dist/development/server.js +1 -1
  71. package/dist/{src-Bme1kz2b.js → development/src-CB7ruwRs.js} +3 -3
  72. package/dist/development/src-CB7ruwRs.js.map +1 -0
  73. package/dist/development/three-CsZ6Od1C.js +527 -0
  74. package/dist/development/three-CsZ6Od1C.js.map +1 -0
  75. package/dist/development/three.js +1 -508
  76. package/dist/development/vite-WUiz1ju6.js +545 -0
  77. package/dist/development/vite-WUiz1ju6.js.map +1 -0
  78. package/dist/development/vite.js +1 -1
  79. package/dist/{dom-D8g3roX9.js → dom-DUpa3Sj2.js} +141 -33
  80. package/dist/dom-DUpa3Sj2.js.map +1 -0
  81. package/dist/floating.d.ts +1 -1
  82. package/dist/floating.d.ts.map +1 -1
  83. package/dist/floating.js +2 -6
  84. package/dist/floating.js.map +1 -1
  85. package/dist/hot.d.ts +15 -0
  86. package/dist/hot.d.ts.map +1 -0
  87. package/dist/hot.js +19 -0
  88. package/dist/hot.js.map +1 -0
  89. package/dist/identity-ByJswZtF.js +121 -0
  90. package/dist/identity-ByJswZtF.js.map +1 -0
  91. package/dist/{index-BFnXIfOj.d.ts → index-DdA39aMv.d.ts} +4 -4
  92. package/dist/{index-BFnXIfOj.d.ts.map → index-DdA39aMv.d.ts.map} +1 -1
  93. package/dist/index.d.ts +4 -4
  94. package/dist/index.js +5 -5
  95. package/dist/jsx-runtime-BGDPK50B.js +49 -0
  96. package/dist/jsx-runtime-BGDPK50B.js.map +1 -0
  97. package/dist/{jsx-runtime-DQnpyT_g.d.ts → jsx-runtime-CCvcEosg.d.ts} +14 -9
  98. package/dist/jsx-runtime-CCvcEosg.d.ts.map +1 -0
  99. package/dist/jsx-runtime.d.ts +1 -1
  100. package/dist/jsx-runtime.js +1 -25
  101. package/dist/konva.d.ts +46 -9
  102. package/dist/konva.d.ts.map +1 -1
  103. package/dist/konva.js +12 -5
  104. package/dist/konva.js.map +1 -1
  105. package/dist/motion.d.ts +3 -1
  106. package/dist/motion.d.ts.map +1 -1
  107. package/dist/motion.js +41 -39
  108. package/dist/motion.js.map +1 -1
  109. package/dist/renderer.d.ts +1 -1
  110. package/dist/renderer.d.ts.map +1 -1
  111. package/dist/renderer.js +39 -40
  112. package/dist/renderer.js.map +1 -1
  113. package/dist/{server-renderer-D0rsFL_-.js → server-renderer-D7CdyOMo.js} +8 -18
  114. package/dist/server-renderer-D7CdyOMo.js.map +1 -0
  115. package/dist/server.d.ts +1 -1
  116. package/dist/server.js +1 -1
  117. package/dist/size.json +12 -12
  118. package/dist/{development/src-DoQgCX-O.js → src-B2W_TA_X.js} +3 -3
  119. package/dist/src-B2W_TA_X.js.map +1 -0
  120. package/dist/three-DcYxRXPW.js +527 -0
  121. package/dist/three-DcYxRXPW.js.map +1 -0
  122. package/dist/three.d.ts +24 -3
  123. package/dist/three.d.ts.map +1 -1
  124. package/dist/three.js +1 -508
  125. package/dist/vite-WUiz1ju6.js +545 -0
  126. package/dist/vite-WUiz1ju6.js.map +1 -0
  127. package/dist/vite.d.ts.map +1 -1
  128. package/dist/vite.js +1 -1
  129. package/package.json +45 -18
  130. package/src/BrandMark.module.css +25 -0
  131. package/src/BrandMark.tsx +106 -0
  132. package/src/BrandMarkScene.module.css +10 -0
  133. package/src/BrandMarkScene.tsx +116 -0
  134. package/src/astro-client.ts +3 -2
  135. package/src/astro-server.ts +2 -2
  136. package/src/brand-css.d.ts +2 -0
  137. package/src/brand-model.ts +177 -0
  138. package/src/brand.ts +3 -0
  139. package/src/capabilities.ts +48 -21
  140. package/src/compiler-hmr.ts +297 -0
  141. package/src/compiler.ts +127 -25
  142. package/src/core.ts +282 -33
  143. package/src/dom-forms.ts +127 -0
  144. package/src/dom.ts +124 -53
  145. package/src/floating.ts +2 -6
  146. package/src/hot.ts +191 -0
  147. package/src/identity.ts +39 -0
  148. package/src/index.ts +2 -0
  149. package/src/jsx-runtime.ts +6 -26
  150. package/src/jsx-types.d.ts +8 -3
  151. package/src/konva.ts +66 -10
  152. package/src/lasertag.d.ts +1 -0
  153. package/src/motion-layout.ts +55 -26
  154. package/src/motion.ts +3 -0
  155. package/src/presence.ts +11 -23
  156. package/src/props.ts +55 -0
  157. package/src/renderer.ts +91 -71
  158. package/src/server-renderer.ts +18 -13
  159. package/src/three.ts +92 -46
  160. package/src/use-loadable.ts +2 -2
  161. package/src/vite.ts +44 -4
  162. package/dist/capabilities-DNcnGRv_.d.ts.map +0 -1
  163. package/dist/capabilities-nOIitQ-_.js +0 -65
  164. package/dist/capabilities-nOIitQ-_.js.map +0 -1
  165. package/dist/core-B4rJ0xdc.js +0 -268
  166. package/dist/core-B4rJ0xdc.js.map +0 -1
  167. package/dist/development/capabilities-nOIitQ-_.js +0 -65
  168. package/dist/development/capabilities-nOIitQ-_.js.map +0 -1
  169. package/dist/development/core-BHA7I1nf.js +0 -271
  170. package/dist/development/core-BHA7I1nf.js.map +0 -1
  171. package/dist/development/dom-DQ0M3rLL.js.map +0 -1
  172. package/dist/development/jsx-runtime.js.map +0 -1
  173. package/dist/development/server-renderer-DCLoMdOX.js.map +0 -1
  174. package/dist/development/src-DoQgCX-O.js.map +0 -1
  175. package/dist/development/three.js.map +0 -1
  176. package/dist/development/vite-Bmyb6P5w.js +0 -265
  177. package/dist/development/vite-Bmyb6P5w.js.map +0 -1
  178. package/dist/dom-D8g3roX9.js.map +0 -1
  179. package/dist/jsx-runtime-DQnpyT_g.d.ts.map +0 -1
  180. package/dist/jsx-runtime.js.map +0 -1
  181. package/dist/server-renderer-D0rsFL_-.js.map +0 -1
  182. package/dist/src-Bme1kz2b.js.map +0 -1
  183. package/dist/three.js.map +0 -1
  184. package/dist/vite-Bmyb6P5w.js +0 -265
  185. package/dist/vite-Bmyb6P5w.js.map +0 -1
@@ -0,0 +1,451 @@
1
+ import { IMPLICIT, actUponStore, clearTimelineInStore, disposeFromStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore, withdraw } from "atom.io/internal";
2
+ // src/core.ts
3
+ let owner;
4
+ let tracking;
5
+ let serial = 0;
6
+ let setupOrder = 0;
7
+ function scopedErrorHandler(scope, error) {
8
+ const failure = scope._root._failure;
9
+ return failure && Object.is(failure.error, error) ? failure.report : scope._options?.onError;
10
+ }
11
+ function throwScopedError(scope, error, report = scopedErrorHandler(scope, error)) {
12
+ if (report) scope._root._failure = {
13
+ error,
14
+ report
15
+ };
16
+ throw error;
17
+ }
18
+ function within(scope, run) {
19
+ const previous = owner;
20
+ owner = scope;
21
+ try {
22
+ return run();
23
+ } catch (error) {
24
+ throwScopedError(scope, error);
25
+ } finally {
26
+ owner = previous;
27
+ }
28
+ }
29
+ function untrack(run) {
30
+ const previous = tracking;
31
+ tracking = void 0;
32
+ try {
33
+ return run();
34
+ } finally {
35
+ tracking = previous;
36
+ }
37
+ }
38
+ function createScope(parent) {
39
+ const child = {
40
+ _root: parent?._root,
41
+ _parent: parent,
42
+ _options: parent?._options,
43
+ _setupOrder: setupOrder++,
44
+ _cleanups: /* @__PURE__ */ new Set(),
45
+ _updates: [],
46
+ _dead: false
47
+ };
48
+ parent?._cleanups.add(child);
49
+ return child;
50
+ }
51
+ function fail(scope, error) {
52
+ const report = scopedErrorHandler(scope, error);
53
+ try {
54
+ dispose(scope);
55
+ } catch (cleanup) {
56
+ throwScopedError(scope, new AggregateError([error, cleanup]), report);
57
+ }
58
+ throw error;
59
+ }
60
+ function dispose(scope) {
61
+ if (scope._dead) return;
62
+ scope._dead = true;
63
+ const errors = [];
64
+ let report;
65
+ const record = (error) => {
66
+ errors.push(error);
67
+ report ??= scopedErrorHandler(scope, error);
68
+ };
69
+ try {
70
+ scope._root._presence?.forget(scope);
71
+ } catch (error) {
72
+ record(error);
73
+ }
74
+ for (const cleanup of [...scope._cleanups].reverse()) try {
75
+ typeof cleanup === `function` ? cleanup() : dispose(cleanup);
76
+ } catch (error) {
77
+ record(error);
78
+ }
79
+ scope._parent?._cleanups.delete(scope);
80
+ scope._cleanups.clear();
81
+ scope._targets?.clear();
82
+ scope._updates.length = 0;
83
+ if (errors.length) throwScopedError(scope, new AggregateError(errors), report);
84
+ }
85
+ function invalidate(scope) {
86
+ for (const run of scope._updates) enqueue(scope, run);
87
+ for (const child of scope._cleanups) if (typeof child !== `function`) invalidate(child);
88
+ }
89
+ function enqueue(scope, run) {
90
+ if (!isPresent(scope)) return;
91
+ const root = scope._root;
92
+ if (!root._queue.size && !root._flushing) queueMicrotask(() => {
93
+ try {
94
+ root.flush();
95
+ } catch (error) {
96
+ const report = scopedErrorHandler(root, error) ?? root.error;
97
+ root._failure = void 0;
98
+ report(error);
99
+ }
100
+ });
101
+ root._queue.add(run);
102
+ }
103
+ function runCommits(root, pending) {
104
+ const top = {
105
+ order: root._setupOrder,
106
+ children: [],
107
+ jobs: []
108
+ };
109
+ const groups = /* @__PURE__ */ new Map([[root, top]]);
110
+ const groupFor = (scope) => {
111
+ let group = groups.get(scope);
112
+ if (!group) {
113
+ group = {
114
+ order: scope._setupOrder,
115
+ children: [],
116
+ jobs: []
117
+ };
118
+ groups.set(scope, group);
119
+ groupFor(scope._parent).children.push(group);
120
+ }
121
+ return group;
122
+ };
123
+ for (const job of [...pending].sort((a, b) => a.order - b.order)) groupFor(job.scope).jobs.push(job);
124
+ const visit = (group) => {
125
+ for (const child of group.children.sort((a, b) => a.order - b.order)) visit(child);
126
+ for (const job of group.jobs) if (pending.delete(job) && isPresent(job.scope)) job.run();
127
+ };
128
+ visit(top);
129
+ }
130
+ function capabilityMap(list) {
131
+ const capabilities = /* @__PURE__ */ new Map();
132
+ for (const capability of list ?? []) {
133
+ if (capabilities.has(capability.namespace)) throw new Error(`spa: duplicate capability ${capability.namespace}`);
134
+ capabilities.set(capability.namespace, capability);
135
+ }
136
+ return capabilities;
137
+ }
138
+ function registerPresence(root, capability, shared = false) {
139
+ const create = capability.presence;
140
+ if (!create) return;
141
+ if (root._presence) {
142
+ if (!shared || root._presenceFactory !== create) throw new Error(`spa: multiple presence coordinators`);
143
+ } else {
144
+ root._presence = create(root);
145
+ root._presenceFactory = create;
146
+ }
147
+ }
148
+ function scopeCapabilities(scope) {
149
+ return scope._options?._capabilities ?? scope._root._capabilities;
150
+ }
151
+ function reportScopeError(scope, error) {
152
+ const report = scopedErrorHandler(scope, error) ?? scope._root.error;
153
+ try {
154
+ fail(scope._root, error);
155
+ } catch (failure) {
156
+ scope._root._failure = void 0;
157
+ report(failure);
158
+ }
159
+ }
160
+ /** Override root options for these children while sharing their parent's ownership. */
161
+ function RootBoundary(props) {
162
+ const scope = owner;
163
+ const { store, idPrefix, onError, capabilities } = props;
164
+ const options = { ...scope._options };
165
+ if (store !== void 0) options.store = store;
166
+ if (idPrefix !== void 0) options.idPrefix = idPrefix;
167
+ if (onError !== void 0) options.onError = onError;
168
+ if (capabilities !== void 0) {
169
+ options._capabilities = capabilityMap(capabilities);
170
+ const root = scope._root;
171
+ const active = root._boundaryCapabilities ??= /* @__PURE__ */ new Map();
172
+ for (const capability of options._capabilities.values()) {
173
+ registerPresence(root, capability, true);
174
+ active.set(capability, (active.get(capability) ?? 0) + 1);
175
+ scope._cleanups.add(() => {
176
+ const remaining = active.get(capability) - 1;
177
+ if (remaining) active.set(capability, remaining);
178
+ else active.delete(capability);
179
+ });
180
+ root._prepareCapability?.(capability);
181
+ }
182
+ }
183
+ scope._options = options;
184
+ return () => props.children;
185
+ }
186
+ function createRoot(options = {}, server = false) {
187
+ const capabilities = capabilityMap(options.capabilities);
188
+ const root = {
189
+ _capabilities: capabilities,
190
+ _store: options.store ?? IMPLICIT.STORE,
191
+ _prefix: options.idPrefix ?? `w${serial++}`,
192
+ _id: 0,
193
+ ...createScope(),
194
+ _queue: /* @__PURE__ */ new Set(),
195
+ _mounts: server ? void 0 : []
196
+ };
197
+ root._root = root;
198
+ root.error = options.onError ?? ((error) => {
199
+ throw error;
200
+ });
201
+ for (const capability of capabilities.values()) registerPresence(root, capability);
202
+ const hasWrites = () => root._queue.size || root._mounts.length;
203
+ const hasWork = () => hasWrites() || root._commits?.size;
204
+ let flushPendingWrites;
205
+ root.flush = () => {
206
+ const nested = root._flushing;
207
+ if (!(nested ? hasWrites() : hasWork()) && !root._forms?.size) return;
208
+ root._flushing = true;
209
+ try {
210
+ if (nested) {
211
+ flushPendingWrites?.();
212
+ return;
213
+ }
214
+ root._failure = void 0;
215
+ let lastCommit;
216
+ const runWriteBatch = () => {
217
+ const commits = /* @__PURE__ */ new Map();
218
+ const prepare = (capability) => {
219
+ if (!commits.has(capability)) commits.set(capability, capability.beforeUpdate?.(root));
220
+ };
221
+ const previous = root._prepareCapability;
222
+ root._prepareCapability = prepare;
223
+ let formsReady = true;
224
+ try {
225
+ for (const capability of capabilities.values()) prepare(capability);
226
+ for (const capability of root._boundaryCapabilities?.keys() ?? []) prepare(capability);
227
+ while (hasWrites()) {
228
+ for (const run of [...root._queue]) if (root._queue.delete(run)) run();
229
+ for (const run of root._mounts.splice(0)) run();
230
+ }
231
+ for (const restore of root._forms ?? []) if (!untrack(restore)) formsReady = false;
232
+ } finally {
233
+ root._prepareCapability = previous;
234
+ for (const commit of commits.values()) commit?.();
235
+ }
236
+ return formsReady;
237
+ };
238
+ do {
239
+ flushPendingWrites = runWriteBatch;
240
+ const formsReady = runWriteBatch();
241
+ flushPendingWrites = void 0;
242
+ if (!hasWrites()) {
243
+ if (!formsReady || !root._commits?.size) break;
244
+ lastCommit = runCommits(root, root._commits) ?? lastCommit;
245
+ }
246
+ } while (hasWork());
247
+ root._failure = void 0;
248
+ } catch (error) {
249
+ flushPendingWrites = void 0;
250
+ fail(root, error);
251
+ } finally {
252
+ if (!nested) root._flushing = false;
253
+ }
254
+ };
255
+ return root;
256
+ }
257
+ /** Return the atom.io store selected by the current owner. */
258
+ function useStore() {
259
+ return owner._options?.store ?? owner._root._store;
260
+ }
261
+ /** Return atom.io disposal bound to the current root's store. */
262
+ function useDisposal() {
263
+ return disposeFromStore.bind(null, useStore());
264
+ }
265
+ function onCleanup(cleanup) {
266
+ owner._cleanups.add(cleanup);
267
+ }
268
+ function onMount(run) {
269
+ const scope = owner;
270
+ scope._root._mounts?.push(() => {
271
+ if (!scope._dead) within(scope, () => {
272
+ untrack(run);
273
+ });
274
+ });
275
+ }
276
+ /** Observe state during setup and apply changes after the root's writes. */
277
+ function onCommit(read, apply) {
278
+ const scope = owner;
279
+ const root = scope._root;
280
+ if (!root._mounts) return;
281
+ const pending = root._commits ??= /* @__PURE__ */ new Set();
282
+ let ran = false;
283
+ let next;
284
+ let previous;
285
+ let cleanup;
286
+ const clear = () => {
287
+ const release = cleanup;
288
+ cleanup = void 0;
289
+ if (release) untrack(release);
290
+ };
291
+ const job = {
292
+ scope,
293
+ order: setupOrder++,
294
+ loopError: void 0,
295
+ run() {
296
+ within(scope, () => {
297
+ untrack(() => {
298
+ clear();
299
+ if (!isPresent(scope)) return;
300
+ const old = previous;
301
+ previous = next;
302
+ ran = true;
303
+ cleanup = apply(next, old);
304
+ if (scope._dead) clear();
305
+ });
306
+ });
307
+ }
308
+ };
309
+ scope._cleanups.add(() => {
310
+ pending.delete(job);
311
+ clear();
312
+ });
313
+ observe(scope, read, (value) => {
314
+ next = value;
315
+ if (!ran || !Object.is(value, previous)) pending.add(job);
316
+ else pending.delete(job);
317
+ });
318
+ }
319
+ function useId() {
320
+ const root = owner._root;
321
+ return `${owner._options?.idPrefix ?? root._prefix}-${root._id++}`;
322
+ }
323
+ function observe(scope, read, apply) {
324
+ const subscriptions = /* @__PURE__ */ new Map();
325
+ const run = () => {
326
+ if (!isPresent(scope)) return;
327
+ const used = /* @__PURE__ */ new Set();
328
+ const previous = tracking;
329
+ tracking = (subscribe) => {
330
+ used.add(subscribe);
331
+ if (!subscriptions.has(subscribe)) subscriptions.set(subscribe, subscribe(() => {
332
+ enqueue(scope, run);
333
+ }));
334
+ };
335
+ let value;
336
+ try {
337
+ value = within(scope, read);
338
+ } finally {
339
+ tracking = previous;
340
+ for (const [subscribe, unsubscribe] of subscriptions) if (!used.has(subscribe)) {
341
+ unsubscribe();
342
+ subscriptions.delete(subscribe);
343
+ }
344
+ }
345
+ within(scope, () => {
346
+ untrack(() => {
347
+ apply(value);
348
+ });
349
+ });
350
+ };
351
+ scope._updates.push(run);
352
+ scope._cleanups.add(() => {
353
+ scope._root._queue.delete(run);
354
+ for (const unsubscribe of subscriptions.values()) unsubscribe();
355
+ });
356
+ run();
357
+ }
358
+ /** Resolve a fixed family key in the current owner's store. */
359
+ function resolveStateToken(token, key) {
360
+ const store = useStore();
361
+ return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
362
+ }
363
+ function useGetter(token, key) {
364
+ token = resolveStateToken(token, key);
365
+ const root = owner._root;
366
+ const store = useStore();
367
+ const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
368
+ return () => {
369
+ const value = getFromStore(store, token);
370
+ root._onRead?.(value, token, store);
371
+ tracking?.(subscribe);
372
+ return value;
373
+ };
374
+ }
375
+ function useSetter(token, key) {
376
+ token = resolveStateToken(token, key);
377
+ const store = useStore();
378
+ return (value) => {
379
+ setIntoStore(store, token, value);
380
+ };
381
+ }
382
+ function useTransaction(token) {
383
+ return actUponStore(useStore(), token, `spa:${serial++}`);
384
+ }
385
+ const refs = /* @__PURE__ */ new WeakMap();
386
+ function useRef(token, key) {
387
+ token = resolveStateToken(token, key);
388
+ const store = useStore();
389
+ const owners = refs.get(store) ?? /* @__PURE__ */ new Map();
390
+ refs.set(store, owners);
391
+ const identity = {};
392
+ let held = null;
393
+ return (element) => {
394
+ if (element) {
395
+ held = element;
396
+ owners.set(token.key, identity);
397
+ setIntoStore(store, token, element);
398
+ } else if (owners.get(token.key) === identity) {
399
+ owners.delete(token.key);
400
+ if (getFromStore(store, token) === held) setIntoStore(store, token, null);
401
+ held = null;
402
+ }
403
+ };
404
+ }
405
+ function useTimeline(token, key) {
406
+ const store = useStore();
407
+ const selected = token.type === `timeline_family` ? findTimelineInStore(store, token, key) : token;
408
+ const subscribe = (notify) => subscribeToTimeline(store, selected, `spa:${serial++}`, notify);
409
+ const read = () => {
410
+ const timeline = withdraw(store, selected);
411
+ tracking?.(subscribe);
412
+ return timeline;
413
+ };
414
+ return {
415
+ getCursor: () => read().at,
416
+ getLength: () => read().history.length,
417
+ undo: () => {
418
+ timeTravel(store, `undo`, selected);
419
+ },
420
+ redo: () => {
421
+ timeTravel(store, `redo`, selected);
422
+ },
423
+ clear: () => {
424
+ clearTimelineInStore(store, selected);
425
+ },
426
+ getTransaction: () => {
427
+ const timeline = read();
428
+ const controls = {};
429
+ for (const direction of [`undo`, `redo`]) {
430
+ const group = getTimelineTransactionAtHead(timeline, direction);
431
+ if (group) controls[direction] = () => {
432
+ timeTravelTransactionGroupInStore(store, direction, group);
433
+ };
434
+ }
435
+ return controls;
436
+ }
437
+ };
438
+ }
439
+ function plain(value) {
440
+ if (typeof value === `function`) return plain(value());
441
+ if (Array.isArray(value)) return value.map(plain).join(``);
442
+ if (value == null || typeof value === `boolean`) return ``;
443
+ return String(value);
444
+ }
445
+ function isPresent(scope) {
446
+ for (let at = scope; at; at = at._parent) if (at._dead || at._exiting) return false;
447
+ return true;
448
+ }
449
+ export { useSetter as C, within as D, useTransaction as E, useRef as S, useTimeline as T, scopeCapabilities as _, enqueue as a, useGetter as b, isPresent as c, onCommit as d, onMount as f, resolveStateToken as g, reportScopeError as h, dispose as i, observe as l, plain as m, createRoot as n, fail as o, owner as p, createScope as r, invalidate as s, RootBoundary as t, onCleanup as u, untrack as v, useStore as w, useId as x, useDisposal as y };
450
+
451
+ //# sourceMappingURL=core-DD2giR6E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-DD2giR6E.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n\tdisposeState,\n\tReadableFamilyToken,\n\tReadableToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSetter,\n\tTimelineFamilyToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tViewOf,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tclearTimelineInStore,\n\tdisposeFromStore,\n\tfindInStore,\n\tfindTimelineInStore,\n\tgetFromStore,\n\tgetTimelineTransactionAtHead,\n\tIMPLICIT,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n\twithdraw,\n} from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type {\n\tExitParticipant,\n\tPresenceCoordinator,\n\tPresenceTarget,\n} from \"./presence.ts\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Children union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Children. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Children\n/** A JSX descriptor for an intrinsic tag, component, or fragment. */\nexport interface SpaElement {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\n/** Renderable content, including nested groups and reactive accessors. */\nexport type Children =\n\t| SpaElement\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Children[]\n\t| Accessor<Children>\nexport interface RootOptions {\n\tcapabilities?: readonly Capability[]\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\ninterface BoundaryOptions extends Omit<RootOptions, `capabilities`> {\n\t_capabilities?: Map<string, Capability>\n}\nexport interface Scope {\n\t_exiting?: boolean\n\t_exits?: Set<ExitParticipant>\n\t_targets?: Set<PresenceTarget>\n\t_root: Root\n\t_parent?: Scope | undefined\n\t_options?: BoundaryOptions | undefined\n\t_setupOrder: number\n\t_cleanups: Set<Cleanup | Scope>\n\t_updates: Cleanup[]\n\t_dead: boolean\n}\nexport interface Root extends Scope {\n\t_onRead?:\n\t\t| ((value: unknown, token: ReadableToken<unknown>, store: RootStore) => void)\n\t\t| undefined\n\t_presence?: PresenceCoordinator\n\t_presenceFactory?: Capability[`presence`]\n\t_capabilities: Map<string, Capability>\n\t_boundaryCapabilities?: Map<Capability, number>\n\t_prepareCapability?: ((capability: Capability) => void) | undefined\n\t_failure?: { error: unknown; report: Root[`error`] } | undefined\n\t_store: RootStore\n\t_prefix: string\n\t_id: number\n\t_queue: Set<Cleanup>\n\t_enqueueCount?: number\n\t_mounts: Cleanup[] | undefined\n\t_commits?: Set<CommitJob>\n\t_flushing?: boolean\n\t_forms?: Set<() => boolean>\n\t_host?: Element\n\tflush: Cleanup\n\terror: (error: unknown) => void\n}\n\ninterface CommitJob {\n\tscope: Scope\n\torder: number\n\trun: Cleanup\n\tloopError: Error | undefined\n}\ninterface CommitGroup {\n\torder: number\n\tchildren: CommitGroup[]\n\tjobs: CommitJob[]\n}\n\nexport let owner: Scope | undefined\ntype Subscribe = (notify: Cleanup) => Cleanup\nlet tracking: ((subscribe: Subscribe) => void) | undefined\nlet serial = 0\nlet setupOrder = 0\n\nfunction scopedErrorHandler(\n\tscope: Scope,\n\terror: unknown,\n): Root[`error`] | undefined {\n\tconst failure = scope._root._failure\n\treturn failure && Object.is(failure.error, error)\n\t\t? failure.report\n\t\t: scope._options?.onError\n}\nfunction throwScopedError(\n\tscope: Scope,\n\terror: unknown,\n\treport = scopedErrorHandler(scope, error),\n): never {\n\tif (report) scope._root._failure = { error, report }\n\tthrow error\n}\nexport function within<T>(scope: Scope, run: () => T): T {\n\tconst previous = owner\n\towner = scope\n\ttry {\n\t\treturn run()\n\t} catch (error) {\n\t\tthrowScopedError(scope, error)\n\t} finally {\n\t\towner = previous\n\t}\n}\nexport function untrack<T>(run: () => T): T {\n\tconst previous = tracking\n\ttracking = undefined\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\ttracking = previous\n\t}\n}\nexport function createScope(parent?: Scope): Scope {\n\tconst child: Scope = {\n\t\t_root: parent?._root as Root,\n\t\t_parent: parent,\n\t\t_options: parent?._options,\n\t\t_setupOrder: setupOrder++,\n\t\t_cleanups: new Set(),\n\t\t_updates: [],\n\t\t_dead: false,\n\t}\n\tparent?._cleanups.add(child)\n\treturn child\n}\nexport function fail(scope: Scope, error: unknown): never {\n\tconst report = scopedErrorHandler(scope, error)\n\ttry {\n\t\tdispose(scope)\n\t} catch (cleanup) {\n\t\tthrowScopedError(scope, new AggregateError([error, cleanup]), report)\n\t}\n\tthrow error\n}\nexport function dispose(scope: Scope): void {\n\tif (scope._dead) return\n\tscope._dead = true\n\tconst errors: unknown[] = []\n\tlet report: Root[`error`] | undefined\n\tconst record = (error: unknown) => {\n\t\terrors.push(error)\n\t\t// Keep the first boundary handler as nested disposal wraps its errors.\n\t\treport ??= scopedErrorHandler(scope, error)\n\t}\n\ttry {\n\t\tscope._root._presence?.forget(scope)\n\t} catch (error) {\n\t\trecord(error)\n\t}\n\tfor (const cleanup of [...scope._cleanups].reverse()) {\n\t\ttry {\n\t\t\ttypeof cleanup === `function` ? cleanup() : dispose(cleanup)\n\t\t} catch (error) {\n\t\t\trecord(error)\n\t\t}\n\t}\n\tscope._parent?._cleanups.delete(scope)\n\tscope._cleanups.clear()\n\tscope._targets?.clear()\n\tscope._updates.length = 0\n\tif (errors.length) throwScopedError(scope, new AggregateError(errors), report)\n}\nexport function invalidate(scope: Scope): void {\n\tfor (const run of scope._updates) enqueue(scope, run)\n\tfor (const child of scope._cleanups)\n\t\tif (typeof child !== `function`) invalidate(child)\n}\nexport function enqueue(scope: Scope, run: Cleanup): void {\n\tif (!isPresent(scope)) return\n\tconst root = scope._root\n\tif (!root._queue.size && !root._flushing)\n\t\tqueueMicrotask(() => {\n\t\t\ttry {\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tconst report = scopedErrorHandler(root, error) ?? root.error\n\t\t\t\troot._failure = undefined\n\t\t\t\treport(error)\n\t\t\t}\n\t\t})\n\t// A write can invalidate an observer that is already pending.\n\tif (import.meta.env.DEV) root._enqueueCount = (root._enqueueCount ?? 0) + 1\n\troot._queue.add(run)\n}\n\nfunction runCommits(root: Root, pending: Set<CommitJob>): CommitJob | undefined {\n\tconst top: CommitGroup = { order: root._setupOrder, children: [], jobs: [] }\n\tconst groups = new Map<Scope, CommitGroup>([[root, top]])\n\t// Keep only branches with pending work. Visit siblings in setup order.\n\tconst groupFor = (scope: Scope): CommitGroup => {\n\t\tlet group = groups.get(scope)\n\t\tif (!group) {\n\t\t\tgroup = { order: scope._setupOrder, children: [], jobs: [] }\n\t\t\tgroups.set(scope, group)\n\t\t\tgroupFor(scope._parent!).children.push(group)\n\t\t}\n\t\treturn group\n\t}\n\tfor (const job of [...pending].sort((a, b) => a.order - b.order))\n\t\tgroupFor(job.scope).jobs.push(job)\n\tlet last: CommitJob | undefined\n\tconst visit = (group: CommitGroup) => {\n\t\tfor (const child of group.children.sort((a, b) => a.order - b.order))\n\t\t\tvisit(child)\n\t\tfor (const job of group.jobs) {\n\t\t\tif (pending.delete(job) && isPresent(job.scope)) {\n\t\t\t\tconst enqueueCount = import.meta.env.DEV ? root._enqueueCount : undefined\n\t\t\t\tjob.run()\n\t\t\t\tif (import.meta.env.DEV && root._enqueueCount !== enqueueCount)\n\t\t\t\t\tlast = job\n\t\t\t}\n\t\t}\n\t}\n\tvisit(top)\n\treturn last\n}\n\nfunction capabilityMap(list: readonly Capability[] | undefined) {\n\tconst capabilities = new Map<string, Capability>()\n\tfor (const capability of list ?? []) {\n\t\tif (capabilities.has(capability.namespace))\n\t\t\tthrow new Error(`spa: duplicate capability ${capability.namespace}`)\n\t\tcapabilities.set(capability.namespace, capability)\n\t}\n\treturn capabilities\n}\nfunction registerPresence(\n\troot: Root,\n\tcapability: Capability,\n\tshared = false,\n): void {\n\tconst create = capability.presence\n\tif (!create) return\n\tif (root._presence) {\n\t\tif (!shared || root._presenceFactory !== create)\n\t\t\tthrow new Error(`spa: multiple presence coordinators`)\n\t} else {\n\t\troot._presence = create(root)\n\t\troot._presenceFactory = create\n\t}\n}\nexport function scopeCapabilities(scope: Scope): Map<string, Capability> {\n\treturn scope._options?._capabilities ?? scope._root._capabilities\n}\nexport function reportScopeError(scope: Scope, error: unknown): void {\n\tconst report = scopedErrorHandler(scope, error) ?? scope._root.error\n\ttry {\n\t\tfail(scope._root, error)\n\t} catch (failure) {\n\t\tscope._root._failure = undefined\n\t\treport(failure)\n\t}\n}\n\n/** Override root options for these children while sharing their parent's ownership. */\nexport function RootBoundary(\n\tprops: RootOptions & { children?: Children },\n): Children {\n\tconst scope = owner!\n\tconst { store, idPrefix, onError, capabilities } = props\n\tconst options = { ...scope._options }\n\tif (store !== undefined) options.store = store\n\tif (idPrefix !== undefined) options.idPrefix = idPrefix\n\tif (onError !== undefined) options.onError = onError\n\tif (capabilities !== undefined) {\n\t\toptions._capabilities = capabilityMap(capabilities)\n\t\tconst root = scope._root\n\t\tconst active = (root._boundaryCapabilities ??= new Map())\n\t\tfor (const capability of options._capabilities.values()) {\n\t\t\tregisterPresence(root, capability, true)\n\t\t\tactive.set(capability, (active.get(capability) ?? 0) + 1)\n\t\t\tscope._cleanups.add(() => {\n\t\t\t\tconst remaining = active.get(capability)! - 1\n\t\t\t\tif (remaining) active.set(capability, remaining)\n\t\t\t\telse active.delete(capability)\n\t\t\t})\n\t\t\troot._prepareCapability?.(capability)\n\t\t}\n\t}\n\tscope._options = options\n\treturn () => props.children\n}\n\nexport function createRoot(options: RootOptions = {}, server = false): Root {\n\tconst capabilities = capabilityMap(options.capabilities)\n\tconst root = {\n\t\t_capabilities: capabilities,\n\t\t_store: options.store ?? IMPLICIT.STORE,\n\t\t_prefix: options.idPrefix ?? `w${serial++}`,\n\t\t_id: 0,\n\t\t...createScope(),\n\t\t_queue: new Set(),\n\t\t_mounts: server ? undefined : [],\n\t} as unknown as Root\n\troot._root = root\n\troot.error =\n\t\toptions.onError ??\n\t\t((error) => {\n\t\t\tthrow error\n\t\t})\n\tfor (const capability of capabilities.values())\n\t\tregisterPresence(root, capability)\n\tconst hasWrites = () => root._queue.size || root._mounts!.length\n\tconst hasWork = () => hasWrites() || root._commits?.size\n\tlet flushPendingWrites: Cleanup | undefined\n\troot.flush = () => {\n\t\tconst nested = root._flushing\n\t\tif (!(nested ? hasWrites() : hasWork()) && !root._forms?.size) return\n\t\troot._flushing = true\n\t\ttry {\n\t\t\tif (nested) {\n\t\t\t\t// The outer flush owns commit dispatch. Mount callbacks can drain writes.\n\t\t\t\tflushPendingWrites?.()\n\t\t\t\treturn\n\t\t\t}\n\t\t\troot._failure = undefined\n\t\t\tlet passes = 0\n\t\t\tlet lastCommit: CommitJob | undefined\n\t\t\tconst checkLoop = () => {\n\t\t\t\tif (import.meta.env.DEV && ++passes > 100)\n\t\t\t\t\tthrow lastCommit?.loopError ?? new Error(`spa: update loop`)\n\t\t\t}\n\t\t\tconst runWriteBatch = () => {\n\t\t\t\tconst commits = new Map<Capability, Cleanup | undefined>()\n\t\t\t\tconst prepare = (capability: Capability) => {\n\t\t\t\t\tif (!commits.has(capability))\n\t\t\t\t\t\tcommits.set(capability, capability.beforeUpdate?.(root))\n\t\t\t\t}\n\t\t\t\tconst previous = root._prepareCapability\n\t\t\t\troot._prepareCapability = prepare\n\t\t\t\tlet formsReady = true\n\t\t\t\ttry {\n\t\t\t\t\tfor (const capability of capabilities.values()) prepare(capability)\n\t\t\t\t\tfor (const capability of root._boundaryCapabilities?.keys() ?? [])\n\t\t\t\t\t\tprepare(capability)\n\t\t\t\t\twhile (hasWrites()) {\n\t\t\t\t\t\tcheckLoop()\n\t\t\t\t\t\tfor (const run of [...root._queue])\n\t\t\t\t\t\t\tif (root._queue.delete(run)) run()\n\t\t\t\t\t\tfor (const run of root._mounts!.splice(0)) run()\n\t\t\t\t\t}\n\t\t\t\t\tfor (const restore of root._forms ?? [])\n\t\t\t\t\t\tif (!untrack(restore)) formsReady = false\n\t\t\t\t} finally {\n\t\t\t\t\troot._prepareCapability = previous\n\t\t\t\t\tfor (const commit of commits.values()) commit?.()\n\t\t\t\t}\n\t\t\t\treturn formsReady\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tflushPendingWrites = runWriteBatch\n\t\t\t\tconst formsReady = runWriteBatch()\n\t\t\t\tflushPendingWrites = undefined\n\t\t\t\tif (!hasWrites()) {\n\t\t\t\t\t// Form event completion schedules a flush to restore the controls.\n\t\t\t\t\tif (!formsReady || !root._commits?.size) break\n\t\t\t\t\tcheckLoop()\n\t\t\t\t\tlastCommit = runCommits(root, root._commits) ?? lastCommit\n\t\t\t\t}\n\t\t\t} while (hasWork())\n\t\t\troot._failure = undefined\n\t\t} catch (error) {\n\t\t\tflushPendingWrites = undefined\n\t\t\tfail(root, error)\n\t\t} finally {\n\t\t\tif (!nested) root._flushing = false\n\t\t}\n\t}\n\treturn root\n}\n/** Return the atom.io store selected by the current owner. */\nexport function useStore(): RootStore {\n\treturn owner!._options?.store ?? owner!._root._store\n}\n/** Return atom.io disposal bound to the current root's store. */\nexport function useDisposal(): typeof disposeState {\n\treturn disposeFromStore.bind(null, useStore()) as typeof disposeState\n}\nexport function onCleanup(cleanup: Cleanup): void {\n\towner!._cleanups.add(cleanup)\n}\nexport function onMount(run: Cleanup): void {\n\tconst scope = owner!\n\tscope._root._mounts?.push(() => {\n\t\tif (!scope._dead)\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(run)\n\t\t\t})\n\t})\n}\n/** Observe state during setup and apply changes after the root's writes. */\nexport function onCommit<T>(\n\tread: Accessor<T>,\n\tapply: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n\tconst scope = owner!\n\tconst root = scope._root\n\tif (!root._mounts) return\n\tconst pending = (root._commits ??= new Set())\n\tlet ran = false\n\tlet next: T\n\tlet previous: T | undefined\n\tlet cleanup: Cleanup | void\n\tconst clear = () => {\n\t\tconst release = cleanup\n\t\tcleanup = undefined\n\t\tif (release) untrack(release)\n\t}\n\tconst job: CommitJob = {\n\t\tscope,\n\t\torder: setupOrder++,\n\t\t// The registration stack identifies the component in a feedback loop.\n\t\tloopError: import.meta.env.DEV\n\t\t\t? new Error(`spa: onCommit update loop`)\n\t\t\t: undefined,\n\t\trun() {\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(() => {\n\t\t\t\t\tclear()\n\t\t\t\t\tif (!isPresent(scope)) return\n\t\t\t\t\tconst old = previous\n\t\t\t\t\tprevious = next\n\t\t\t\t\tran = true\n\t\t\t\t\tcleanup = apply(next, old)\n\t\t\t\t\tif (scope._dead) clear()\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t}\n\tscope._cleanups.add(() => {\n\t\tpending.delete(job)\n\t\tclear()\n\t})\n\tobserve(scope, read, (value) => {\n\t\tnext = value\n\t\tif (!ran || !Object.is(value, previous)) pending.add(job)\n\t\telse pending.delete(job)\n\t})\n}\nexport function useId(): string {\n\tconst root = owner!._root\n\treturn `${owner!._options?.idPrefix ?? root._prefix}-${root._id++}`\n}\n\nexport function observe<T>(\n\tscope: Scope,\n\tread: Accessor<T>,\n\tapply: (value: T) => void,\n): void {\n\tconst subscriptions = new Map<Subscribe, Cleanup>()\n\tconst run = () => {\n\t\tif (!isPresent(scope)) return\n\t\tconst used = new Set<Subscribe>()\n\t\tconst previous = tracking\n\t\ttracking = (subscribe) => {\n\t\t\tused.add(subscribe)\n\t\t\tif (!subscriptions.has(subscribe))\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tsubscribe,\n\t\t\t\t\tsubscribe(() => {\n\t\t\t\t\t\tenqueue(scope, run)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t}\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = within(scope, read)\n\t\t} finally {\n\t\t\ttracking = previous\n\t\t\tfor (const [subscribe, unsubscribe] of subscriptions)\n\t\t\t\tif (!used.has(subscribe)) {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tsubscriptions.delete(subscribe)\n\t\t\t\t}\n\t\t}\n\t\twithin(scope, () => {\n\t\t\tuntrack(() => {\n\t\t\t\tapply(value)\n\t\t\t})\n\t\t})\n\t}\n\tscope._updates.push(run)\n\tscope._cleanups.add(() => {\n\t\tscope._root._queue.delete(run)\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t})\n\trun()\n}\n\n/** Resolve a fixed family key in the current owner's store. */\nexport function resolveStateToken(token: any, key?: Canonical): any {\n\tconst store = useStore()\n\treturn token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token\n}\n\n/** Capture a token for this instance. Change the component key to change its token. */\nexport function useGetter<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst root = owner!._root\n\tconst store = useStore()\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToState(store, token, `spa:${serial++}`, notify)\n\treturn () => {\n\t\tconst value = getFromStore(store, token)\n\t\troot._onRead?.(value, token, store)\n\t\ttracking?.(subscribe)\n\t\treturn value\n\t}\n}\nexport function useSetter<T>(\n\ttoken: WritableToken<T, any, any>,\n): (value: T | Setter<T>) => void\nexport function useSetter<T, K extends Canonical>(\n\tfamily: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): (value: T | Setter<T>) => void\nexport function useSetter(token: any, key?: Canonical): (value: any) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\treturn (value) => {\n\t\tsetIntoStore(store, token, value)\n\t}\n}\nexport function useTransaction<F extends (...args: any[]) => any>(\n\ttoken: TransactionToken<F>,\n): (...args: Parameters<F>) => ReturnType<F> {\n\treturn actUponStore(useStore(), token, `spa:${serial++}`)\n}\n\nconst refs = new WeakMap<RootStore, Map<string, object>>()\nexport function useRef<E extends Element>(\n\ttoken: RegularAtomToken<E | null>,\n): (element: E | null) => void\nexport function useRef<E extends Element, K extends Canonical>(\n\tfamily: RegularAtomFamilyToken<E | null, K>,\n\tkey: NoInfer<K>,\n): (element: E | null) => void\nexport function useRef<E extends Element>(\n\ttoken: any,\n\tkey?: Canonical,\n): (element: E | null) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\tconst owners = refs.get(store) ?? new Map<string, object>()\n\trefs.set(store, owners)\n\tconst identity = {}\n\tlet held: E | null = null\n\treturn (element) => {\n\t\tif (element) {\n\t\t\theld = element\n\t\t\towners.set(token.key, identity)\n\t\t\tsetIntoStore(store, token, element)\n\t\t} else if (owners.get(token.key) === identity) {\n\t\t\towners.delete(token.key)\n\t\t\tif (getFromStore(store, token) === held) setIntoStore(store, token, null)\n\t\t\theld = null\n\t\t}\n\t}\n}\nexport interface TimelineControls {\n\tgetCursor(): number\n\tgetLength(): number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tgetTransaction(): { undo?: Cleanup; redo?: Cleanup }\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): TimelineControls\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): TimelineControls\nexport function useTimeline(token: any, key?: Canonical): TimelineControls {\n\tconst store = useStore()\n\tconst selected: TimelineToken<any> =\n\t\ttoken.type === `timeline_family`\n\t\t\t? findTimelineInStore(store, token, key!)\n\t\t\t: token\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, selected, `spa:${serial++}`, notify)\n\tconst read = () => {\n\t\tconst timeline = withdraw(store, selected)\n\t\ttracking?.(subscribe)\n\t\treturn timeline\n\t}\n\treturn {\n\t\tgetCursor: () => read().at,\n\t\tgetLength: () => read().history.length,\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, selected)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, selected)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, selected)\n\t\t},\n\t\tgetTransaction: () => {\n\t\t\tconst timeline = read()\n\t\t\tconst controls: ReturnType<TimelineControls[`getTransaction`]> = {}\n\t\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\t\tconst group = getTimelineTransactionAtHead(timeline, direction)\n\t\t\t\tif (group)\n\t\t\t\t\tcontrols[direction] = () => {\n\t\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t\t\t\t}\n\t\t\t}\n\t\t\treturn controls\n\t\t},\n\t}\n}\n\nexport function plain(value: Children): string {\n\tif (typeof value === `function`) return plain(value())\n\tif (Array.isArray(value)) return value.map(plain).join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (import.meta.env.DEV && typeof value === `object`)\n\t\tthrow new Error(`spa: text required`)\n\t// oxlint-disable-next-line typescript/no-base-to-string -- Valid text children are primitives here; development rejects malformed object children.\n\treturn String(value)\n}\n\nexport function isPresent(scope: Scope): boolean {\n\tfor (let at: Scope | undefined = scope; at; at = at._parent)\n\t\tif (at._dead || at._exiting) return false\n\treturn true\n}\n"],"mappings":";;AA0HA,IAAW;AAEX,IAAI;AACJ,IAAI,SAAS;AACb,IAAI,aAAa;AAEjB,SAAS,mBACR,OACA,OAC4B;CAC5B,MAAM,UAAU,MAAM,MAAM;CAC5B,OAAO,WAAW,OAAO,GAAG,QAAQ,OAAO,KAAK,IAC7C,QAAQ,SACR,MAAM,UAAU;AACpB;AACA,SAAS,iBACR,OACA,OACA,SAAS,mBAAmB,OAAO,KAAK,GAChC;CACR,IAAI,QAAQ,MAAM,MAAM,WAAW;EAAE;EAAO;CAAO;CACnD,MAAM;AACP;AACA,SAAgB,OAAU,OAAc,KAAiB;CACxD,MAAM,WAAW;CACjB,QAAQ;CACR,IAAI;EACH,OAAO,IAAI;CACZ,SAAS,OAAO;EACf,iBAAiB,OAAO,KAAK;CAC9B,UAAU;EACT,QAAQ;CACT;AACD;AACA,SAAgB,QAAW,KAAiB;CAC3C,MAAM,WAAW;CACjB,WAAW,KAAA;CACX,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,WAAW;CACZ;AACD;AACA,SAAgB,YAAY,QAA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AACD;AAEA,SAAgB,MAAM,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAAC;CACrD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE;CACzD,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CAIxD,OAAO,OAAO,KAAK;AACpB;AAEA,SAAgB,UAAU,OAAuB;CAChD,KAAK,IAAI,KAAwB,OAAO,IAAI,KAAK,GAAG,SACnD,IAAI,GAAG,SAAS,GAAG,UAAU,OAAO;CACrC,OAAO;AACR"}
@@ -0,0 +1,140 @@
1
+ import { DZ2_ORBITAL_LIGHTS, DZ2_ORBITAL_Y_ROTATION_RADIANS_PER_SECOND, createDz2OrbitalCamera, createDz2OrbitalModel, disposeDz2OrbitalModel } from "./brand-model.js";
2
+ import { f as onMount, u as onCleanup } from "./core-DrUd8x25.js";
3
+ import { h as PointLight, i as Canvas, l as Mesh, o as Group, t as AmbientLight } from "./three-CsZ6Od1C.js";
4
+ import { jsx } from "@atom.io/spa/jsx-runtime";
5
+ // src/BrandMarkScene.module.css
6
+ var BrandMarkScene_module_default = { "class": "atom-io-spa-BrandMarkScene-module-class" };
7
+ // src/BrandMarkScene.tsx
8
+ const canvas = { Canvas };
9
+ function BrandMarkScene(props) {
10
+ const view = props.view;
11
+ const camera = createDz2OrbitalCamera();
12
+ const model = createDz2OrbitalModel();
13
+ const mark = () => props.variant === `mark`;
14
+ const narrow = () => view.innerWidth < 680;
15
+ let orbital = null;
16
+ let dirty = true;
17
+ const preference = view.matchMedia(`(prefers-reduced-motion: reduce)`);
18
+ const invalidate = () => {
19
+ dirty = true;
20
+ };
21
+ onMount(() => {
22
+ preference.addEventListener(`change`, invalidate);
23
+ view.document.addEventListener(`visibilitychange`, invalidate);
24
+ onCleanup(() => {
25
+ preference.removeEventListener(`change`, invalidate);
26
+ view.document.removeEventListener(`visibilitychange`, invalidate);
27
+ });
28
+ });
29
+ onCleanup(() => {
30
+ disposeDz2OrbitalModel(model);
31
+ });
32
+ return jsx("brand-mark-scene", {
33
+ get "class"() {
34
+ return BrandMarkScene_module_default[`class`];
35
+ },
36
+ children: jsx(canvas.Canvas, {
37
+ get "camera"() {
38
+ return camera;
39
+ },
40
+ get "width"() {
41
+ return props.width;
42
+ },
43
+ get "height"() {
44
+ return props.height;
45
+ },
46
+ get "dpr"() {
47
+ return Math.min(view.devicePixelRatio || 1, mark() ? 2 : 1.35, mark() ? 1e400 : Math.sqrt(16e6 / (props.width * props.height)));
48
+ },
49
+ get "rendererOptions"() {
50
+ return {
51
+ alpha: true,
52
+ antialias: true,
53
+ powerPreference: mark() ? `low-power` : `high-performance`
54
+ };
55
+ },
56
+ get "onError"() {
57
+ return props.onError;
58
+ },
59
+ "onCreated": (({ scene, renderer }) => {
60
+ renderer.render(scene, camera);
61
+ props.onReady();
62
+ }),
63
+ "onResize": (({ width, height }) => {
64
+ camera.aspect = width / height;
65
+ camera.updateProjectionMatrix();
66
+ invalidate();
67
+ }),
68
+ "renderWhen": (() => !view.document.hidden && (dirty || !preference.matches)),
69
+ "onFrame": (({ delta }) => {
70
+ if (view.document.hidden) return;
71
+ if (!preference.matches) orbital.rotation.y += Math.min(delta, .1) * DZ2_ORBITAL_Y_ROTATION_RADIANS_PER_SECOND;
72
+ dirty = false;
73
+ }),
74
+ children: [
75
+ jsx(AmbientLight, {
76
+ get "color"() {
77
+ return DZ2_ORBITAL_LIGHTS.ambient.color;
78
+ },
79
+ get "intensity"() {
80
+ return DZ2_ORBITAL_LIGHTS.ambient.intensity;
81
+ }
82
+ }),
83
+ jsx(PointLight, {
84
+ get "color"() {
85
+ return DZ2_ORBITAL_LIGHTS.core.color;
86
+ },
87
+ get "intensity"() {
88
+ return DZ2_ORBITAL_LIGHTS.core.intensity;
89
+ },
90
+ get "distance"() {
91
+ return DZ2_ORBITAL_LIGHTS.core.distance;
92
+ },
93
+ get "position"() {
94
+ return DZ2_ORBITAL_LIGHTS.core.position;
95
+ }
96
+ }),
97
+ jsx(Group, {
98
+ get "scale"() {
99
+ return mark() ? 1.25 : narrow() ? .52 : .72;
100
+ },
101
+ get "position"() {
102
+ return [
103
+ 0,
104
+ !mark() && narrow() ? -.08 : 0,
105
+ 0
106
+ ];
107
+ },
108
+ "ref": ((node) => {
109
+ orbital = node;
110
+ if (node) node.rotation.copy(model.orbital.rotation);
111
+ }),
112
+ get children() {
113
+ return model.meshes.map((mesh, index) => jsx(Mesh, {
114
+ get "key"() {
115
+ return index;
116
+ },
117
+ get "args"() {
118
+ return [mesh.geometry, mesh.material];
119
+ },
120
+ get "position"() {
121
+ return mesh.position.toArray();
122
+ },
123
+ get "rotation"() {
124
+ return [
125
+ mesh.rotation.x,
126
+ mesh.rotation.y,
127
+ mesh.rotation.z
128
+ ];
129
+ }
130
+ }));
131
+ }
132
+ })
133
+ ]
134
+ })
135
+ });
136
+ }
137
+ BrandMarkScene.spa = true;
138
+ export { BrandMarkScene };
139
+
140
+ //# sourceMappingURL=BrandMarkScene-BDdC7K5M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrandMarkScene-BDdC7K5M.js","names":["_spa","css"],"sources":["../../src/BrandMarkScene.tsx"],"sourcesContent":["/** @jsxImportSource @atom.io/spa */\nimport type * as THREE from \"three\"\n\nimport {\n\tcreateDz2OrbitalCamera,\n\tcreateDz2OrbitalModel,\n\tdisposeDz2OrbitalModel,\n\tDZ2_ORBITAL_LIGHTS,\n\tDZ2_ORBITAL_Y_ROTATION_RADIANS_PER_SECOND,\n} from \"./brand-model.ts\"\nimport css from \"./BrandMarkScene.module.css\"\nimport type { SpaElement } from \"./core.ts\"\nimport { onCleanup, onMount } from \"./core.ts\"\nimport { AmbientLight, Canvas, Group, Mesh, PointLight } from \"./three.ts\"\n\nconst canvas = { Canvas }\nexport function BrandMarkScene(props: {\n\tvariant: `mark` | `splash`\n\twidth: number\n\theight: number\n\tview: Window\n\tonReady(): void\n\tonError(error: unknown): void\n}): SpaElement {\n\tconst view = props.view\n\tconst camera = createDz2OrbitalCamera()\n\tconst model = createDz2OrbitalModel()\n\tconst mark = () => props.variant === `mark`\n\tconst narrow = () => view.innerWidth < 680\n\tlet orbital: THREE.Object3D | null = null\n\tlet dirty = true\n\tconst preference = view.matchMedia(`(prefers-reduced-motion: reduce)`)\n\tconst invalidate = () => {\n\t\tdirty = true\n\t}\n\tonMount(() => {\n\t\tpreference.addEventListener(`change`, invalidate)\n\t\tview.document.addEventListener(`visibilitychange`, invalidate)\n\t\tonCleanup(() => {\n\t\t\tpreference.removeEventListener(`change`, invalidate)\n\t\t\tview.document.removeEventListener(`visibilitychange`, invalidate)\n\t\t})\n\t})\n\tonCleanup(() => {\n\t\tdisposeDz2OrbitalModel(model)\n\t})\n\treturn (\n\t\t<brand-mark-scene class={css[`class`]}>\n\t\t\t<canvas.Canvas\n\t\t\t\tcamera={camera}\n\t\t\t\twidth={props.width}\n\t\t\t\theight={props.height}\n\t\t\t\tdpr={Math.min(\n\t\t\t\t\tview.devicePixelRatio || 1,\n\t\t\t\t\tmark() ? 2 : 1.35,\n\t\t\t\t\tmark()\n\t\t\t\t\t\t? Infinity\n\t\t\t\t\t\t: Math.sqrt(16_000_000 / (props.width * props.height)),\n\t\t\t\t)}\n\t\t\t\trendererOptions={{\n\t\t\t\t\talpha: true,\n\t\t\t\t\tantialias: true,\n\t\t\t\t\tpowerPreference: mark() ? `low-power` : `high-performance`,\n\t\t\t\t}}\n\t\t\t\tonError={props.onError}\n\t\t\t\tonCreated={({ scene, renderer }) => {\n\t\t\t\t\trenderer.render(scene, camera)\n\t\t\t\t\tprops.onReady()\n\t\t\t\t}}\n\t\t\t\tonResize={({ width, height }) => {\n\t\t\t\t\tcamera.aspect = width / height\n\t\t\t\t\tcamera.updateProjectionMatrix()\n\t\t\t\t\tinvalidate()\n\t\t\t\t}}\n\t\t\t\trenderWhen={() =>\n\t\t\t\t\t!view.document.hidden && (dirty || !preference.matches)\n\t\t\t\t}\n\t\t\t\tonFrame={({ delta }) => {\n\t\t\t\t\tif (view.document.hidden) return\n\t\t\t\t\tif (!preference.matches)\n\t\t\t\t\t\torbital!.rotation.y +=\n\t\t\t\t\t\t\tMath.min(delta, 0.1) * DZ2_ORBITAL_Y_ROTATION_RADIANS_PER_SECOND\n\t\t\t\t\tdirty = false\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t<AmbientLight\n\t\t\t\t\tcolor={DZ2_ORBITAL_LIGHTS.ambient.color}\n\t\t\t\t\tintensity={DZ2_ORBITAL_LIGHTS.ambient.intensity}\n\t\t\t\t/>\n\t\t\t\t<PointLight\n\t\t\t\t\tcolor={DZ2_ORBITAL_LIGHTS.core.color}\n\t\t\t\t\tintensity={DZ2_ORBITAL_LIGHTS.core.intensity}\n\t\t\t\t\tdistance={DZ2_ORBITAL_LIGHTS.core.distance}\n\t\t\t\t\tposition={DZ2_ORBITAL_LIGHTS.core.position}\n\t\t\t\t/>\n\t\t\t\t<Group\n\t\t\t\t\tscale={mark() ? 1.25 : narrow() ? 0.52 : 0.72}\n\t\t\t\t\tposition={[0, !mark() && narrow() ? -0.08 : 0, 0]}\n\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\torbital = node\n\t\t\t\t\t\tif (node) node.rotation.copy(model.orbital.rotation)\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{model.meshes.map((mesh, index) => (\n\t\t\t\t\t\t<Mesh\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\targs={[mesh.geometry, mesh.material]}\n\t\t\t\t\t\t\tposition={mesh.position.toArray()}\n\t\t\t\t\t\t\trotation={[mesh.rotation.x, mesh.rotation.y, mesh.rotation.z]}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t</Group>\n\t\t\t</canvas.Canvas>\n\t\t</brand-mark-scene>\n\t)\n}\n"],"mappings":";;;;;;;AAeA,MAAM,SAAS,EAAE,OAAO;AACxB,SAAgB,eAAe,OAOhB;CACd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