@atom.io/spa 0.0.9 → 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.
- package/README.md +30 -10
- package/README.mdx +16 -5
- package/dist/BrandMarkScene-CBYk-RJ2.js +140 -0
- package/dist/BrandMarkScene-CBYk-RJ2.js.map +1 -0
- package/dist/astro-client.js +1 -1
- package/dist/astro-server.js +1 -1
- package/dist/brand-css.d.ts +2 -0
- package/dist/brand-model.d.ts +32 -0
- package/dist/brand-model.d.ts.map +1 -0
- package/dist/brand-model.js +120 -0
- package/dist/brand-model.js.map +1 -0
- package/dist/brand.css +37 -0
- package/dist/brand.d.ts +13 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +94 -0
- package/dist/brand.js.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/development/BrandMarkScene-BDdC7K5M.js +140 -0
- package/dist/development/BrandMarkScene-BDdC7K5M.js.map +1 -0
- package/dist/development/astro-client.js +1 -1
- package/dist/development/astro-server.js +1 -1
- package/dist/development/brand-model.js +120 -0
- package/dist/development/brand-model.js.map +1 -0
- package/dist/development/brand.css +37 -0
- package/dist/development/brand.js +94 -0
- package/dist/development/brand.js.map +1 -0
- package/dist/development/{dom-BRFv7FP_.js → dom-CEVtlaav.js} +4 -3
- package/dist/development/dom-CEVtlaav.js.map +1 -0
- package/dist/development/floating.js.map +1 -1
- package/dist/development/hot.js +2 -2
- package/dist/development/hot.js.map +1 -1
- package/dist/development/{identity-DwB8MTM1.js → identity-B8wTFkyW.js} +2 -2
- package/dist/development/{identity-DwB8MTM1.js.map → identity-B8wTFkyW.js.map} +1 -1
- package/dist/development/index.js +1 -1
- package/dist/development/konva.js +1 -1
- package/dist/development/motion.js +38 -19
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +1 -1
- package/dist/development/{server-renderer-u1-c5PGd.js → server-renderer-zAqEL1g1.js} +2 -2
- package/dist/development/{server-renderer-u1-c5PGd.js.map → server-renderer-zAqEL1g1.js.map} +1 -1
- package/dist/development/server.js +1 -1
- package/dist/development/three-CsZ6Od1C.js +527 -0
- package/dist/development/three-CsZ6Od1C.js.map +1 -0
- package/dist/development/three.js +1 -509
- package/dist/{dom--HZvmgqd.js → dom-DUpa3Sj2.js} +4 -3
- package/dist/dom-DUpa3Sj2.js.map +1 -0
- package/dist/floating.js.map +1 -1
- package/dist/hot.d.ts.map +1 -1
- package/dist/hot.js.map +1 -1
- package/dist/{identity-oFU5p-Qj.js → identity-ByJswZtF.js} +2 -2
- package/dist/{identity-oFU5p-Qj.js.map → identity-ByJswZtF.js.map} +1 -1
- package/dist/index-DdA39aMv.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/konva.js +1 -1
- package/dist/motion.d.ts +2 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +38 -19
- package/dist/motion.js.map +1 -1
- package/dist/renderer.js +1 -1
- package/dist/{server-renderer-BYFDmqnM.js → server-renderer-D7CdyOMo.js} +2 -2
- package/dist/{server-renderer-BYFDmqnM.js.map → server-renderer-D7CdyOMo.js.map} +1 -1
- package/dist/server.js +1 -1
- package/dist/size.json +12 -12
- package/dist/three-DcYxRXPW.js +527 -0
- package/dist/three-DcYxRXPW.js.map +1 -0
- package/dist/three.d.ts +21 -0
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +1 -509
- package/package.json +39 -19
- package/src/BrandMark.module.css +25 -0
- package/src/BrandMark.tsx +106 -0
- package/src/BrandMarkScene.module.css +10 -0
- package/src/BrandMarkScene.tsx +116 -0
- package/src/brand-css.d.ts +2 -0
- package/src/brand-model.ts +177 -0
- package/src/brand.ts +3 -0
- package/src/dom.ts +8 -1
- package/src/hot.ts +3 -2
- package/src/lasertag.d.ts +1 -0
- package/src/motion-layout.ts +55 -26
- package/src/motion.ts +3 -0
- package/src/three.ts +69 -22
- package/dist/development/dom-BRFv7FP_.js.map +0 -1
- package/dist/development/three.js.map +0 -1
- package/dist/dom--HZvmgqd.js.map +0 -1
- package/dist/three.js.map +0 -1
package/dist/renderer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as capabilityProps, t as identifyChildren } from "./identity-
|
|
1
|
+
import { i as capabilityProps, t as identifyChildren } from "./identity-ByJswZtF.js";
|
|
2
2
|
import { D as within, _ as scopeCapabilities, c as isPresent, h as reportScopeError, i as dispose, l as observe, n as createRoot, o as fail, p as owner, r as createScope, s as invalidate, v as untrack } from "./core-DD2giR6E.js";
|
|
3
3
|
import { a as instanceProps, t as Fragment } from "./jsx-runtime-BGDPK50B.js";
|
|
4
4
|
// src/renderer.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as validateCapabilities, n as trackKeys, r as capabilityNamespace, t as identifyChildren } from "./identity-
|
|
1
|
+
import { a as validateCapabilities, n as trackKeys, r as capabilityNamespace, t as identifyChildren } from "./identity-ByJswZtF.js";
|
|
2
2
|
import { D as within, i as dispose, m as plain, n as createRoot, r as createScope, v as untrack } from "./core-DD2giR6E.js";
|
|
3
3
|
import { a as instanceProps, t as Fragment } from "./jsx-runtime-BGDPK50B.js";
|
|
4
4
|
// src/server-renderer.ts
|
|
@@ -77,4 +77,4 @@ function renderToStringWithReads(setup, options = {}, onRead) {
|
|
|
77
77
|
}
|
|
78
78
|
export { renderToStringWithReads as t };
|
|
79
79
|
|
|
80
|
-
//# sourceMappingURL=server-renderer-
|
|
80
|
+
//# sourceMappingURL=server-renderer-D7CdyOMo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-renderer-
|
|
1
|
+
{"version":3,"file":"server-renderer-D7CdyOMo.js","names":[],"sources":["../src/server-renderer.ts"],"sourcesContent":["import type { ReadableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\n\nimport { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport type { Children, RootOptions, Scope } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { identifyChildren, trackKeys } from \"./identity.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\nimport { instanceProps } from \"./props.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&`, \"<\": `<`, \">\": `>`, '\"': `"`, \"'\": `'` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Children,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n\tinitialKey?: Canonical,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = within(owner, () => untrack(() => identifyChildren(value())))\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map(\n\t\t\t\t\t({ value: child, key }) =>\n\t\t\t\t\t\t`<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue, key))}<!--]-->`,\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\ttrackKeys(untrack(() => type(instanceProps(() => props, initialKey)))),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tvalidateCapabilities(owner, props)\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tcapabilityNamespace(key) !== undefined ||\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute ?? textValue\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToStringWithReads(\n\tsetup: () => Children,\n\toptions: RootOptions = {},\n\tonRead?: (\n\t\tvalue: unknown,\n\t\ttoken: ReadableToken<unknown>,\n\t\tstore: RootStore,\n\t) => void,\n): string {\n\tconst root = createRoot(options, true)\n\troot._onRead = onRead\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(trackKeys(untrack(setup)), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":"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"}
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as renderToStringWithReads } from "./server-renderer-
|
|
1
|
+
import { t as renderToStringWithReads } from "./server-renderer-D7CdyOMo.js";
|
|
2
2
|
// src/server.ts
|
|
3
3
|
function renderToString(setup, options = {}) {
|
|
4
4
|
return renderToStringWithReads(setup, options);
|
package/dist/size.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
3
|
"name": "spa client",
|
|
4
|
-
"raw":
|
|
5
|
-
"minified":
|
|
6
|
-
"gzip":
|
|
7
|
-
"brotli":
|
|
4
|
+
"raw": 33184,
|
|
5
|
+
"minified": 15537,
|
|
6
|
+
"gzip": 6212,
|
|
7
|
+
"brotli": 5657
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"name": "spa + atom.io",
|
|
11
|
-
"raw":
|
|
12
|
-
"minified":
|
|
13
|
-
"gzip":
|
|
14
|
-
"brotli":
|
|
11
|
+
"raw": 122689,
|
|
12
|
+
"minified": 59349,
|
|
13
|
+
"gzip": 18190,
|
|
14
|
+
"brotli": 16469
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"name": "spa Astro client",
|
|
18
|
-
"raw":
|
|
19
|
-
"minified":
|
|
20
|
-
"gzip":
|
|
21
|
-
"brotli":
|
|
18
|
+
"raw": 36261,
|
|
19
|
+
"minified": 16958,
|
|
20
|
+
"gzip": 6708,
|
|
21
|
+
"brotli": 6086
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"name": "Preact",
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { D as within, c as isPresent, f as onMount, h as reportScopeError, p as owner, u as onCleanup } from "./core-DD2giR6E.js";
|
|
2
|
+
import { n as jsx } from "./jsx-runtime-BGDPK50B.js";
|
|
3
|
+
import { bindScene, createSceneRenderer, onSceneFrame, sceneComponent } from "./renderer.js";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
// src/three-events.ts
|
|
6
|
+
const suspended = /* @__PURE__ */ new WeakSet();
|
|
7
|
+
function suspendThree(node) {
|
|
8
|
+
suspended.add(node);
|
|
9
|
+
for (const manager of managers) manager.remove(node);
|
|
10
|
+
return () => {
|
|
11
|
+
suspended.delete(node);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const listeners = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
const managers = /* @__PURE__ */ new Set();
|
|
16
|
+
function listenThree(node, type, handler) {
|
|
17
|
+
const events = listeners.get(node) ?? /* @__PURE__ */ new Map();
|
|
18
|
+
listeners.set(node, events);
|
|
19
|
+
const handlers = events.get(type) ?? /* @__PURE__ */ new Set();
|
|
20
|
+
events.set(type, handlers);
|
|
21
|
+
handlers.add(handler);
|
|
22
|
+
return () => {
|
|
23
|
+
handlers.delete(handler);
|
|
24
|
+
if (!handlers.size) events.delete(type);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function forgetThree(node) {
|
|
28
|
+
const errors = [];
|
|
29
|
+
for (const manager of managers) try {
|
|
30
|
+
manager.remove(node);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
errors.push(error);
|
|
33
|
+
}
|
|
34
|
+
listeners.delete(node);
|
|
35
|
+
if (errors.length) throw new AggregateError(errors);
|
|
36
|
+
}
|
|
37
|
+
/** Attach raycast pointer routing to a canvas; usable with borrowed scene roots. */
|
|
38
|
+
function createThreeEvents(canvas, scene, camera, onError = (error) => {
|
|
39
|
+
throw error;
|
|
40
|
+
}) {
|
|
41
|
+
const raycaster = new THREE.Raycaster();
|
|
42
|
+
const pointer = new THREE.Vector2();
|
|
43
|
+
const hovering = /* @__PURE__ */ new Map();
|
|
44
|
+
const pressed = /* @__PURE__ */ new Map();
|
|
45
|
+
const captures = /* @__PURE__ */ new Map();
|
|
46
|
+
const last = /* @__PURE__ */ new Map();
|
|
47
|
+
let dead = false;
|
|
48
|
+
const path = (node) => {
|
|
49
|
+
const nodes = [];
|
|
50
|
+
for (let at = node; at; at = at.parent) {
|
|
51
|
+
nodes.push(at);
|
|
52
|
+
if (at === scene) return nodes;
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
};
|
|
56
|
+
const contains = (node, child) => {
|
|
57
|
+
for (let at = child; at; at = at.parent) if (at === node) return true;
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
const eligible = (intersection) => {
|
|
61
|
+
const nodes = path(intersection.object);
|
|
62
|
+
if (!nodes.length || nodes.some((node) => !node.visible || suspended.has(node))) return false;
|
|
63
|
+
const material = intersection.object.material;
|
|
64
|
+
return !material || (Array.isArray(material) ? material[intersection.face?.materialIndex ?? 0]?.visible !== false : material.visible);
|
|
65
|
+
};
|
|
66
|
+
const pick = (event) => {
|
|
67
|
+
const bounds = canvas.getBoundingClientRect();
|
|
68
|
+
if (!bounds.width || !bounds.height) return void 0;
|
|
69
|
+
const active = camera();
|
|
70
|
+
scene.updateWorldMatrix(true, true);
|
|
71
|
+
active.updateWorldMatrix(true, false);
|
|
72
|
+
pointer.set((event.clientX - bounds.left) / bounds.width * 2 - 1, 1 - (event.clientY - bounds.top) / bounds.height * 2);
|
|
73
|
+
raycaster.layers.mask = active.layers.mask;
|
|
74
|
+
raycaster.setFromCamera(pointer, active);
|
|
75
|
+
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) return void 0;
|
|
76
|
+
const intersection = raycaster.intersectObject(scene, true).find(eligible);
|
|
77
|
+
return intersection ? {
|
|
78
|
+
node: intersection.object,
|
|
79
|
+
intersection
|
|
80
|
+
} : void 0;
|
|
81
|
+
};
|
|
82
|
+
const nativeCapture = (id) => {
|
|
83
|
+
if (canvas.hasPointerCapture?.(id)) canvas.releasePointerCapture(id);
|
|
84
|
+
};
|
|
85
|
+
const dispatch = (type, hit, nativeEvent, nodes = path(hit.node)) => {
|
|
86
|
+
let stopped = false;
|
|
87
|
+
for (const node of nodes) {
|
|
88
|
+
if (dead) break;
|
|
89
|
+
const event = {
|
|
90
|
+
type,
|
|
91
|
+
nativeEvent,
|
|
92
|
+
target: hit.node,
|
|
93
|
+
currentTarget: node,
|
|
94
|
+
intersection: hit.intersection,
|
|
95
|
+
ray: raycaster.ray.clone(),
|
|
96
|
+
pointerId: nativeEvent.pointerId,
|
|
97
|
+
button: nativeEvent.button,
|
|
98
|
+
buttons: nativeEvent.buttons,
|
|
99
|
+
clientX: nativeEvent.clientX,
|
|
100
|
+
clientY: nativeEvent.clientY,
|
|
101
|
+
stopPropagation() {
|
|
102
|
+
stopped = true;
|
|
103
|
+
},
|
|
104
|
+
preventDefault() {
|
|
105
|
+
nativeEvent.preventDefault();
|
|
106
|
+
},
|
|
107
|
+
setPointerCapture() {
|
|
108
|
+
canvas.setPointerCapture(nativeEvent.pointerId);
|
|
109
|
+
captures.set(nativeEvent.pointerId, {
|
|
110
|
+
node,
|
|
111
|
+
intersection: hit.intersection
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
releasePointerCapture() {
|
|
115
|
+
if (captures.get(nativeEvent.pointerId)?.node === node) {
|
|
116
|
+
captures.delete(nativeEvent.pointerId);
|
|
117
|
+
nativeCapture(nativeEvent.pointerId);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
hasPointerCapture() {
|
|
121
|
+
return captures.get(nativeEvent.pointerId)?.node === node;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
for (const handler of [...listeners.get(node)?.get(type) ?? []]) if (!dead && listeners.get(node)?.get(type)?.has(handler)) handler(event);
|
|
125
|
+
if (stopped) break;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const hover = (event, next) => {
|
|
129
|
+
const previous = hovering.get(event.pointerId);
|
|
130
|
+
if (previous?.node === next?.node) {
|
|
131
|
+
if (next) hovering.set(event.pointerId, next);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const oldPath = previous ? path(previous.node) : [];
|
|
135
|
+
const newPath = next ? path(next.node) : [];
|
|
136
|
+
if (next) hovering.set(event.pointerId, next);
|
|
137
|
+
else hovering.delete(event.pointerId);
|
|
138
|
+
if (previous) {
|
|
139
|
+
dispatch(`pointerout`, previous, event);
|
|
140
|
+
for (const node of oldPath) if (!newPath.includes(node)) dispatch(`pointerleave`, previous, event, [node]);
|
|
141
|
+
}
|
|
142
|
+
if (next && path(next.node).length) {
|
|
143
|
+
dispatch(`pointerover`, next, event);
|
|
144
|
+
for (const node of newPath.reverse()) if (!oldPath.includes(node)) dispatch(`pointerenter`, next, event, [node]);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const cancel = (event) => {
|
|
148
|
+
const hit = captures.get(event.pointerId) ?? pressed.get(event.pointerId);
|
|
149
|
+
captures.delete(event.pointerId);
|
|
150
|
+
pressed.delete(event.pointerId);
|
|
151
|
+
try {
|
|
152
|
+
if (hit) dispatch(`pointercancel`, hit, event);
|
|
153
|
+
} finally {
|
|
154
|
+
nativeCapture(event.pointerId);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const handle = (event) => {
|
|
158
|
+
try {
|
|
159
|
+
if (event.type === `lostpointercapture`) {
|
|
160
|
+
cancel(event);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (event.type === `pointercancel`) {
|
|
164
|
+
cancel(event);
|
|
165
|
+
hover(event);
|
|
166
|
+
last.delete(event.pointerId);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (event.type === `pointerleave`) {
|
|
170
|
+
last.set(event.pointerId, event);
|
|
171
|
+
hover(event);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
last.set(event.pointerId, event);
|
|
175
|
+
const hit = pick(event);
|
|
176
|
+
hover(event, hit);
|
|
177
|
+
if (dead) return;
|
|
178
|
+
const capture = captures.get(event.pointerId);
|
|
179
|
+
if (capture && hit && contains(capture.node, hit.node)) capture.intersection = hit.intersection;
|
|
180
|
+
const delivery = capture ?? hit;
|
|
181
|
+
if (event.type === `pointerdown`) {
|
|
182
|
+
if (hit) {
|
|
183
|
+
pressed.set(event.pointerId, hit);
|
|
184
|
+
canvas.setPointerCapture?.(event.pointerId);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (event.type === `pointerup`) {
|
|
188
|
+
const down = pressed.get(event.pointerId);
|
|
189
|
+
pressed.delete(event.pointerId);
|
|
190
|
+
try {
|
|
191
|
+
if (down && !capture && down.node !== hit?.node) dispatch(`pointercancel`, down, event);
|
|
192
|
+
if (delivery) dispatch(`pointerup`, delivery, event);
|
|
193
|
+
if (down && down.node === hit?.node && event.button === 0) dispatch(`click`, hit, event);
|
|
194
|
+
} finally {
|
|
195
|
+
captures.delete(event.pointerId);
|
|
196
|
+
nativeCapture(event.pointerId);
|
|
197
|
+
if (event.pointerType === `touch`) {
|
|
198
|
+
hover(event);
|
|
199
|
+
last.delete(event.pointerId);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else if (delivery) dispatch(event.type, delivery, event);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
onError(error);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const events = [
|
|
208
|
+
`pointerdown`,
|
|
209
|
+
`pointerup`,
|
|
210
|
+
`pointermove`,
|
|
211
|
+
`pointerleave`,
|
|
212
|
+
`pointercancel`,
|
|
213
|
+
`lostpointercapture`
|
|
214
|
+
];
|
|
215
|
+
for (const type of events) canvas.addEventListener(type, handle);
|
|
216
|
+
const manager = {
|
|
217
|
+
/** Re-pick stationary pointers after camera, geometry, or transforms change. */
|
|
218
|
+
update() {
|
|
219
|
+
if (dead) return;
|
|
220
|
+
try {
|
|
221
|
+
for (const event of last.values()) if (event.type !== `pointerleave`) hover(event, pick(event));
|
|
222
|
+
} catch (error) {
|
|
223
|
+
onError(error);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
remove(node) {
|
|
227
|
+
const errors = [];
|
|
228
|
+
for (const [id, hit] of hovering) if (contains(node, hit.node)) try {
|
|
229
|
+
hover(last.get(id));
|
|
230
|
+
} catch (error) {
|
|
231
|
+
errors.push(error);
|
|
232
|
+
}
|
|
233
|
+
for (const [id, hit] of [...pressed, ...captures]) if (contains(node, hit.node)) try {
|
|
234
|
+
cancel(last.get(id));
|
|
235
|
+
} catch (error) {
|
|
236
|
+
errors.push(error);
|
|
237
|
+
}
|
|
238
|
+
if (errors.length) throw new AggregateError(errors);
|
|
239
|
+
},
|
|
240
|
+
dispose() {
|
|
241
|
+
if (dead) return;
|
|
242
|
+
dead = true;
|
|
243
|
+
for (const type of events) canvas.removeEventListener(type, handle);
|
|
244
|
+
for (const id of /* @__PURE__ */ new Set([...pressed.keys(), ...captures.keys()])) nativeCapture(id);
|
|
245
|
+
hovering.clear();
|
|
246
|
+
pressed.clear();
|
|
247
|
+
captures.clear();
|
|
248
|
+
last.clear();
|
|
249
|
+
managers.delete(manager);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
managers.add(manager);
|
|
253
|
+
return manager;
|
|
254
|
+
}
|
|
255
|
+
// src/three.ts
|
|
256
|
+
const constructors = {
|
|
257
|
+
Group: THREE.Group,
|
|
258
|
+
Mesh: THREE.Mesh,
|
|
259
|
+
LineSegments: THREE.LineSegments,
|
|
260
|
+
BufferGeometry: THREE.BufferGeometry,
|
|
261
|
+
LineBasicMaterial: THREE.LineBasicMaterial,
|
|
262
|
+
PerspectiveCamera: THREE.PerspectiveCamera,
|
|
263
|
+
AmbientLight: THREE.AmbientLight,
|
|
264
|
+
PointLight: THREE.PointLight,
|
|
265
|
+
DirectionalLight: THREE.DirectionalLight,
|
|
266
|
+
BoxGeometry: THREE.BoxGeometry,
|
|
267
|
+
SphereGeometry: THREE.SphereGeometry,
|
|
268
|
+
PlaneGeometry: THREE.PlaneGeometry,
|
|
269
|
+
MeshStandardMaterial: THREE.MeshStandardMaterial,
|
|
270
|
+
MeshBasicMaterial: THREE.MeshBasicMaterial,
|
|
271
|
+
MeshNormalMaterial: THREE.MeshNormalMaterial
|
|
272
|
+
};
|
|
273
|
+
const drawableDefaults = /* @__PURE__ */ new WeakMap();
|
|
274
|
+
const borrowedDrawableDefaults = /* @__PURE__ */ new WeakMap();
|
|
275
|
+
const constructorArgs = /* @__PURE__ */ new WeakMap();
|
|
276
|
+
const eventHandlers = /* @__PURE__ */ new WeakMap();
|
|
277
|
+
const defaults = /* @__PURE__ */ new WeakMap();
|
|
278
|
+
function writeProperty(node, key, value) {
|
|
279
|
+
const target = node;
|
|
280
|
+
if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`);
|
|
281
|
+
const current = target[key];
|
|
282
|
+
if (current?.isColor) current.set(value);
|
|
283
|
+
else if (Array.isArray(value) && typeof current?.set === `function`) current.set(...value);
|
|
284
|
+
else if (key === `scale` && typeof value === `number`) current.setScalar(value);
|
|
285
|
+
else if (current?.copy && value?.constructor === current.constructor) current.copy(value);
|
|
286
|
+
else target[key] = value;
|
|
287
|
+
if (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix();
|
|
288
|
+
}
|
|
289
|
+
const renderer = createSceneRenderer({
|
|
290
|
+
target(node) {
|
|
291
|
+
return {
|
|
292
|
+
kind: `three`,
|
|
293
|
+
node,
|
|
294
|
+
...node instanceof THREE.Object3D ? {
|
|
295
|
+
suspend: () => suspendThree(node),
|
|
296
|
+
listen: (type, listener) => listenThree(node, type, listener)
|
|
297
|
+
} : {},
|
|
298
|
+
read(key) {
|
|
299
|
+
const value = node[key];
|
|
300
|
+
return value?.isColor ? value.getStyle() : value?.isVector3 || value?.isEuler ? [
|
|
301
|
+
value.x,
|
|
302
|
+
value.y,
|
|
303
|
+
value.z
|
|
304
|
+
] : value;
|
|
305
|
+
},
|
|
306
|
+
write(key, value) {
|
|
307
|
+
writeProperty(node, key, value);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
create(type, props) {
|
|
312
|
+
const Constructor = constructors[type];
|
|
313
|
+
if (!Constructor) throw new Error(`spa/three: unknown node ${type}`);
|
|
314
|
+
const node = new Constructor(...props[`args`] ?? []);
|
|
315
|
+
if (node instanceof THREE.Mesh || node instanceof THREE.LineSegments) drawableDefaults.set(node, {
|
|
316
|
+
geometry: node.geometry,
|
|
317
|
+
material: node.material,
|
|
318
|
+
ownsGeometry: props[`args`]?.[0] === void 0,
|
|
319
|
+
ownsMaterial: props[`args`]?.[1] === void 0
|
|
320
|
+
});
|
|
321
|
+
constructorArgs.set(node, [...props[`args`] ?? []]);
|
|
322
|
+
defaults.set(node, /* @__PURE__ */ new Map());
|
|
323
|
+
eventHandlers.set(node, /* @__PURE__ */ new Map());
|
|
324
|
+
return node;
|
|
325
|
+
},
|
|
326
|
+
update(node, props, previous) {
|
|
327
|
+
if (!equalArgs(constructorArgs.get(node), props[`args`])) throw new Error(`spa/three: change the component key to replace constructor args`);
|
|
328
|
+
const target = node;
|
|
329
|
+
const saved = defaults.get(node);
|
|
330
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(props)])) {
|
|
331
|
+
if (/^(key|children|ref|args)$/.test(key) || Object.is(props[key], previous[key])) continue;
|
|
332
|
+
if (key.startsWith(`on`)) {
|
|
333
|
+
if (!(node instanceof THREE.Object3D) || !/^on(Pointer(Down|Up|Move|Enter|Leave|Over|Out|Cancel)|Click)$/.test(key)) throw new Error(`spa/three: unknown event ${key}`);
|
|
334
|
+
const handlers = eventHandlers.get(node);
|
|
335
|
+
handlers.get(key)?.();
|
|
336
|
+
handlers.delete(key);
|
|
337
|
+
const handler = props[key];
|
|
338
|
+
if (handler) {
|
|
339
|
+
const scope = owner;
|
|
340
|
+
handlers.set(key, listenThree(node, key.slice(2).toLowerCase(), (event) => {
|
|
341
|
+
within(scope, () => {
|
|
342
|
+
handler(event);
|
|
343
|
+
});
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`);
|
|
349
|
+
const current = target[key];
|
|
350
|
+
if (!saved.has(key)) saved.set(key, current?.clone ? current.clone() : current);
|
|
351
|
+
writeProperty(node, key, props[key] === void 0 ? saved.get(key) : props[key]);
|
|
352
|
+
}
|
|
353
|
+
if (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix();
|
|
354
|
+
},
|
|
355
|
+
children(parent, children, activeChildren) {
|
|
356
|
+
if (!(parent instanceof THREE.Object3D)) {
|
|
357
|
+
if (children.length) throw new Error(`spa/three: resources cannot contain children`);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const objects = children.filter((child) => child instanceof THREE.Object3D);
|
|
361
|
+
if (parent.children.length !== objects.length || objects.some((child, index) => child !== parent.children[index])) {
|
|
362
|
+
const wanted = new Set(objects);
|
|
363
|
+
for (const child of [...parent.children]) if (!wanted.has(child)) parent.remove(child);
|
|
364
|
+
for (const child of objects) if (child.parent !== parent) parent.add(child);
|
|
365
|
+
parent.children.splice(0, parent.children.length, ...objects);
|
|
366
|
+
}
|
|
367
|
+
const resources = children.filter((child) => !(child instanceof THREE.Object3D));
|
|
368
|
+
if (resources.length && !(parent instanceof THREE.Mesh || parent instanceof THREE.LineSegments)) throw new Error(`spa/three: geometry and material require a Mesh or LineSegments parent`);
|
|
369
|
+
if (parent instanceof THREE.Mesh || parent instanceof THREE.LineSegments) {
|
|
370
|
+
const geometries = resources.filter((child) => child instanceof THREE.BufferGeometry);
|
|
371
|
+
const materials = resources.filter((child) => child instanceof THREE.Material);
|
|
372
|
+
const activeGeometries = activeChildren.filter((child) => child instanceof THREE.BufferGeometry);
|
|
373
|
+
const activeMaterials = activeChildren.filter((child) => child instanceof THREE.Material);
|
|
374
|
+
if (activeGeometries.length > 1 || activeMaterials.length > 1) throw new Error(`spa/three: each ${parent instanceof THREE.Mesh ? `Mesh` : `LineSegments`} accepts one geometry and one material`);
|
|
375
|
+
const owned = drawableDefaults.get(parent);
|
|
376
|
+
let baseline = owned ?? borrowedDrawableDefaults.get(parent);
|
|
377
|
+
if (!baseline) {
|
|
378
|
+
baseline = {
|
|
379
|
+
geometry: parent.geometry,
|
|
380
|
+
material: parent.material
|
|
381
|
+
};
|
|
382
|
+
borrowedDrawableDefaults.set(parent, baseline);
|
|
383
|
+
}
|
|
384
|
+
parent.geometry = activeGeometries[0] ?? geometries.find((geometry) => geometry === parent.geometry) ?? geometries.at(-1) ?? baseline.geometry;
|
|
385
|
+
parent.material = activeMaterials[0] ?? materials.find((material) => material === parent.material) ?? materials.at(-1) ?? baseline.material;
|
|
386
|
+
if (!owned && children.length === 0) borrowedDrawableDefaults.delete(parent);
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
destroy(node) {
|
|
390
|
+
eventHandlers.get(node).clear();
|
|
391
|
+
if (node instanceof THREE.Object3D) try {
|
|
392
|
+
forgetThree(node);
|
|
393
|
+
} finally {
|
|
394
|
+
node.removeFromParent();
|
|
395
|
+
if (node instanceof THREE.Mesh || node instanceof THREE.LineSegments) {
|
|
396
|
+
const owned = drawableDefaults.get(node);
|
|
397
|
+
if (owned.ownsGeometry) owned.geometry.dispose();
|
|
398
|
+
if (owned.ownsMaterial) owned.material.dispose();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else node.dispose();
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
function equalArgs(a, b = []) {
|
|
405
|
+
return a.length === b.length && a.every((value, index) => Object.is(value, b[index]) || Array.isArray(value) && Array.isArray(b[index]) && equalArgs(value, b[index]));
|
|
406
|
+
}
|
|
407
|
+
/** Browser-only scene boundary. The camera prop is borrowed and never disposed. */
|
|
408
|
+
function Canvas(props) {
|
|
409
|
+
let canvas = null;
|
|
410
|
+
onMount(() => {
|
|
411
|
+
const parameters = {
|
|
412
|
+
antialias: true,
|
|
413
|
+
...props.rendererOptions,
|
|
414
|
+
canvas
|
|
415
|
+
};
|
|
416
|
+
let webgl;
|
|
417
|
+
try {
|
|
418
|
+
webgl = props.createRenderer ? props.createRenderer(parameters) : new THREE.WebGLRenderer(parameters);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (!props.onError) throw error;
|
|
421
|
+
props.onError(error);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
onCleanup(() => {
|
|
425
|
+
webgl.dispose();
|
|
426
|
+
});
|
|
427
|
+
if (webgl.domElement !== canvas) throw new Error(`spa/three: renderer must use the supplied Canvas element`);
|
|
428
|
+
const scene = new THREE.Scene();
|
|
429
|
+
const camera = new THREE.PerspectiveCamera(50, 1, .1, 1e3);
|
|
430
|
+
camera.position.z = 5;
|
|
431
|
+
const view = canvas.ownerDocument.defaultView;
|
|
432
|
+
const size = () => ({
|
|
433
|
+
width: props.width ?? 800,
|
|
434
|
+
height: props.height ?? 600,
|
|
435
|
+
dpr: props.dpr ?? 1,
|
|
436
|
+
active: props.camera ?? camera
|
|
437
|
+
});
|
|
438
|
+
const resize = ({ width, height, dpr, active }) => {
|
|
439
|
+
const range = typeof dpr === `number` ? [dpr, dpr] : dpr;
|
|
440
|
+
if (![
|
|
441
|
+
width,
|
|
442
|
+
height,
|
|
443
|
+
...range
|
|
444
|
+
].every((value) => Number.isFinite(value) && value > 0) || range[0] > range[1]) throw new Error(`spa/three: dimensions and DPR must be positive with an ordered DPR range`);
|
|
445
|
+
const ratio = Math.max(range[0], Math.min(range[1], view.devicePixelRatio || 1));
|
|
446
|
+
webgl.setPixelRatio(ratio);
|
|
447
|
+
webgl.setSize(width, height);
|
|
448
|
+
camera.aspect = width / height;
|
|
449
|
+
camera.updateProjectionMatrix();
|
|
450
|
+
props.onResize?.({
|
|
451
|
+
scene,
|
|
452
|
+
camera: active,
|
|
453
|
+
renderer: webgl,
|
|
454
|
+
width,
|
|
455
|
+
height,
|
|
456
|
+
dpr: ratio
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
bindScene(size, resize);
|
|
460
|
+
const scope = owner;
|
|
461
|
+
const resized = () => {
|
|
462
|
+
try {
|
|
463
|
+
resize(size());
|
|
464
|
+
} catch (error) {
|
|
465
|
+
reportScopeError(scope, error);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
view.addEventListener(`resize`, resized);
|
|
469
|
+
onCleanup(() => {
|
|
470
|
+
view.removeEventListener(`resize`, resized);
|
|
471
|
+
});
|
|
472
|
+
renderer.mount(() => props.children, scene);
|
|
473
|
+
const events = createThreeEvents(canvas, scene, () => props.camera ?? camera, (error) => {
|
|
474
|
+
reportScopeError(scope, error);
|
|
475
|
+
});
|
|
476
|
+
onCleanup(() => {
|
|
477
|
+
events.dispose();
|
|
478
|
+
});
|
|
479
|
+
onMount(() => {
|
|
480
|
+
const cleanup = props.onCreated?.({
|
|
481
|
+
scene,
|
|
482
|
+
camera: props.camera ?? camera,
|
|
483
|
+
renderer: webgl
|
|
484
|
+
});
|
|
485
|
+
if (cleanup) onCleanup(cleanup);
|
|
486
|
+
let last;
|
|
487
|
+
onSceneFrame((time) => {
|
|
488
|
+
const active = props.camera ?? camera;
|
|
489
|
+
const delta = last === void 0 ? 0 : (time - last) / 1e3;
|
|
490
|
+
last = time;
|
|
491
|
+
const present = isPresent(scope);
|
|
492
|
+
const draw = !present || (props.renderWhen?.() ?? true);
|
|
493
|
+
if (present) props.onFrame?.({
|
|
494
|
+
scene,
|
|
495
|
+
camera: active,
|
|
496
|
+
renderer: webgl,
|
|
497
|
+
delta,
|
|
498
|
+
time: time / 1e3
|
|
499
|
+
});
|
|
500
|
+
events.update();
|
|
501
|
+
if (draw) webgl.render(scene, active);
|
|
502
|
+
}, true);
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
return jsx(`canvas`, { ref: (element) => {
|
|
506
|
+
canvas = element;
|
|
507
|
+
} });
|
|
508
|
+
}
|
|
509
|
+
const Group = sceneComponent(`Group`);
|
|
510
|
+
const Mesh = sceneComponent(`Mesh`);
|
|
511
|
+
const PerspectiveCamera = sceneComponent(`PerspectiveCamera`);
|
|
512
|
+
const AmbientLight = sceneComponent(`AmbientLight`);
|
|
513
|
+
const DirectionalLight = sceneComponent(`DirectionalLight`);
|
|
514
|
+
const PointLight = sceneComponent(`PointLight`);
|
|
515
|
+
const BoxGeometry = sceneComponent(`BoxGeometry`);
|
|
516
|
+
const SphereGeometry = sceneComponent(`SphereGeometry`);
|
|
517
|
+
const PlaneGeometry = sceneComponent(`PlaneGeometry`);
|
|
518
|
+
const MeshStandardMaterial = sceneComponent(`MeshStandardMaterial`);
|
|
519
|
+
const MeshBasicMaterial = sceneComponent(`MeshBasicMaterial`);
|
|
520
|
+
const MeshNormalMaterial = sceneComponent(`MeshNormalMaterial`);
|
|
521
|
+
/** Batched line geometry, with the same attachment and ownership rules as Mesh. */
|
|
522
|
+
const LineSegments = sceneComponent(`LineSegments`);
|
|
523
|
+
const BufferGeometry = sceneComponent(`BufferGeometry`);
|
|
524
|
+
const LineBasicMaterial = sceneComponent(`LineBasicMaterial`);
|
|
525
|
+
export { renderer as _, DirectionalLight as a, LineSegments as c, MeshNormalMaterial as d, MeshStandardMaterial as f, SphereGeometry as g, PointLight as h, Canvas as i, Mesh as l, PlaneGeometry as m, BoxGeometry as n, Group as o, PerspectiveCamera as p, BufferGeometry as r, LineBasicMaterial as s, AmbientLight as t, MeshBasicMaterial as u, createThreeEvents as v };
|
|
526
|
+
|
|
527
|
+
//# sourceMappingURL=three-DcYxRXPW.js.map
|