@atom.io/spa 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -6
- package/README.mdx +62 -1
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.js +7 -4
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-server.js +4 -3
- package/dist/astro-server.js.map +1 -1
- package/dist/astro-shared-BT45auwR.js.map +1 -1
- package/dist/{astro-shared-DkZaqX7L.d.ts → astro-shared-DyzbUi6c.d.ts} +4 -2
- package/dist/astro-shared-DyzbUi6c.d.ts.map +1 -0
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/{core-Dvqm7w2y.js → capabilities-BuZUQpiD.js} +64 -2
- package/dist/capabilities-BuZUQpiD.js.map +1 -0
- package/dist/{core-BhiA9fFi.d.ts → capabilities-yC9TsHDI.d.ts} +20 -2
- package/dist/capabilities-yC9TsHDI.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/development/astro-client.js +7 -4
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-server.js +4 -3
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/astro-shared-BT45auwR.js.map +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/{core-DB3sQz4h.js → capabilities-DhOJmeoJ.js} +64 -2
- package/dist/development/capabilities-DhOJmeoJ.js.map +1 -0
- package/dist/development/{dom-D9cY6l1R.js → dom-BKc6V_Kz.js} +8 -3
- package/dist/development/dom-BKc6V_Kz.js.map +1 -0
- package/dist/development/index.js +3 -38
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +121 -0
- package/dist/development/konva.js.map +1 -0
- package/dist/development/motion.js +217 -0
- package/dist/development/motion.js.map +1 -0
- package/dist/development/renderer.js +177 -0
- package/dist/development/renderer.js.map +1 -0
- package/dist/development/server.js +17 -7
- package/dist/development/server.js.map +1 -1
- package/dist/development/src-Dh-d6w4y.js +38 -0
- package/dist/development/src-Dh-d6w4y.js.map +1 -0
- package/dist/development/three.js +438 -0
- package/dist/development/three.js.map +1 -0
- package/dist/development/vite-CSHoxzXU.js +240 -0
- package/dist/development/vite-CSHoxzXU.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-BR9o9wZW.js → dom-B2rm8o2L.js} +8 -3
- package/dist/dom-B2rm8o2L.js.map +1 -0
- package/dist/index-BdwxmSKg.d.ts +24 -0
- package/dist/index-BdwxmSKg.d.ts.map +1 -0
- package/dist/index.d.ts +4 -24
- package/dist/index.js +3 -38
- package/dist/{jsx-runtime-BzGV18VO.d.ts → jsx-runtime-CZU7F8Qz.d.ts} +6 -4
- package/dist/jsx-runtime-CZU7F8Qz.d.ts.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +32 -0
- package/dist/konva.d.ts.map +1 -0
- package/dist/konva.js +121 -0
- package/dist/konva.js.map +1 -0
- package/dist/motion.d.ts +44 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +217 -0
- package/dist/motion.js.map +1 -0
- package/dist/renderer.d.ts +24 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +177 -0
- package/dist/renderer.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +17 -7
- package/dist/server.js.map +1 -1
- package/dist/size.json +16 -16
- package/dist/src-BZxX4xbU.js +38 -0
- package/dist/src-BZxX4xbU.js.map +1 -0
- package/dist/three.d.ts +110 -0
- package/dist/three.d.ts.map +1 -0
- package/dist/three.js +438 -0
- package/dist/three.js.map +1 -0
- package/dist/vite-CSHoxzXU.js +240 -0
- package/dist/vite-CSHoxzXU.js.map +1 -0
- package/dist/vite.js +1 -1
- package/package.json +176 -131
- package/src/astro-client.ts +1 -0
- package/src/astro-server.ts +1 -0
- package/src/astro-shared.ts +3 -0
- package/src/capabilities.ts +88 -0
- package/src/compiler.ts +251 -177
- package/src/core.ts +11 -0
- package/src/dom.ts +4 -1
- package/src/index.ts +5 -0
- package/src/jsx-runtime.ts +4 -0
- package/src/jsx-types.d.ts +3 -1
- package/src/konva.ts +159 -0
- package/src/motion.ts +406 -0
- package/src/renderer.ts +241 -0
- package/src/server.ts +21 -13
- package/src/three-events.ts +330 -0
- package/src/three.ts +350 -0
- package/dist/astro-shared-DkZaqX7L.d.ts.map +0 -1
- package/dist/core-BhiA9fFi.d.ts.map +0 -1
- package/dist/core-Dvqm7w2y.js.map +0 -1
- package/dist/development/core-DB3sQz4h.js.map +0 -1
- package/dist/development/dom-D9cY6l1R.js.map +0 -1
- package/dist/development/index.js.map +0 -1
- package/dist/development/vite-BadrFSIM.js +0 -126
- package/dist/development/vite-BadrFSIM.js.map +0 -1
- package/dist/dom-BR9o9wZW.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jsx-runtime-BzGV18VO.d.ts.map +0 -1
- package/dist/vite-BadrFSIM.js +0 -126
- package/dist/vite-BadrFSIM.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","names":[],"sources":["../src/renderer.ts"],"sourcesContent":["import type { CapabilityTarget } from \"./capabilities.ts\"\nimport { capabilityProps } from \"./capabilities.ts\"\nimport type { Child, Component, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\towner,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nexport interface SceneHost<N> {\n\ttarget?(node: N): CapabilityTarget\n\tcreate(type: string, props: Record<string, any>): N\n\tupdate(\n\t\tnode: N,\n\t\tprops: Record<string, any>,\n\t\tprevious: Record<string, any>,\n\t): void\n\tchildren(parent: N, children: N[]): void\n\tdestroy(node: N): void\n}\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Child\n\tnodes: () => N[]\n}\n\nexport interface SceneRenderer<N> {\n\tmount(setup: () => Child, parent: N): void\n\trender(\n\t\tsetup: () => Child,\n\t\tparent: N,\n\t\toptions?: RootOptions,\n\t): { flush(): void; dispose(): void }\n}\n\n/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */\nexport function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {\n\tfunction mount(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): () => N[] {\n\t\tlet entries: Entry<N>[] = []\n\t\tobserve(scope, source, (next) => {\n\t\t\tconst values = (\n\t\t\t\tArray.isArray(next) ? next.flat(Infinity) : [next]\n\t\t\t) as Child[]\n\t\t\tconst old = new Map(\n\t\t\t\tentries.map((entry, i) => [key(entry.value, i), entry]),\n\t\t\t)\n\t\t\tconst seen = new Set<string>()\n\t\t\tentries = values.map((value, i) => {\n\t\t\t\tconst id = key(value, i)\n\t\t\t\tif (seen.has(id)) throw new Error(`spa: duplicate scene key`)\n\t\t\t\tseen.add(id)\n\t\t\t\tlet entry = old.get(id)\n\t\t\t\told.delete(id)\n\t\t\t\tif (entry && !same(entry.value, value)) {\n\t\t\t\t\tdispose(entry.scope)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\n\t\t\t\t\tinvalidate(entry.scope)\n\t\t\t\t\treturn entry\n\t\t\t\t}\n\t\t\t\tconst childScope = createScope(scope)\n\t\t\t\tconst created: Entry<N> = { scope: childScope, value, nodes: null! }\n\t\t\t\tcreated.nodes = build(() => created.value, childScope, changed)\n\t\t\t\treturn created\n\t\t\t})\n\t\t\tfor (const entry of old.values()) dispose(entry.scope)\n\t\t\tchanged()\n\t\t})\n\t\treturn () => entries.flatMap((entry) => entry.nodes())\n\t}\n\tfunction key(value: Child, i: number): string {\n\t\tconst explicit = (value as VNode | null)?.props?.[`key`]\n\t\treturn explicit == null ? `index:${i}` : `key:${explicit}`\n\t}\n\tfunction same(a: Child, b: Child): boolean {\n\t\treturn (\n\t\t\ttypeof a === typeof b &&\n\t\t\t(a as VNode | null)?.type === (b as VNode | null)?.type\n\t\t)\n\t}\n\tfunction build(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): () => N[] {\n\t\tconst value = untrack(source)\n\t\tif (typeof value === `function`)\n\t\t\treturn mount(() => (source() as () => Child)(), scope, changed)\n\t\tif (value == null || typeof value === `boolean`) return () => []\n\t\tif (typeof value !== `object`)\n\t\t\tthrow new Error(`spa: scene children must be nodes`)\n\t\tif (!(`type` in value) || !(`props` in value))\n\t\t\tthrow new Error(`spa: invalid scene child`)\n\t\tconst vnode = value\n\t\tconst props = merge(() => (source() as VNode).props)\n\t\tif (!vnode.type || vnode.type === Fragment)\n\t\t\treturn mount(() => props[`children`], scope, changed)\n\t\tif (typeof vnode.type === `function`) {\n\t\t\tconst output = within(scope, () =>\n\t\t\t\tuntrack(() => (vnode.type as Component)(props)),\n\t\t\t)\n\t\t\treturn mount(() => output, scope, changed)\n\t\t}\n\t\tconst node = host.create(\n\t\t\tvnode.type,\n\t\t\tuntrack(() => props),\n\t\t)\n\t\tscope._cleanups.add(() => {\n\t\t\thost.destroy(node)\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\tscope,\n\t\t\thost.target?.(node) ?? { kind: `scene`, node },\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tobserve(\n\t\t\tscope,\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\thost.update(node, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tlet children: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children())\n\t\t}\n\t\tchildren = mount(() => props[`children`], scope, sync)\n\t\tsync()\n\t\tconst ref = untrack(() => props[`ref`])\n\t\tif (ref)\n\t\t\tscope._root._mounts!.unshift(() => {\n\t\t\t\tif (!scope._dead) {\n\t\t\t\t\tscope._cleanups.add(() => ref(null))\n\t\t\t\t\tref(node)\n\t\t\t\t}\n\t\t\t})\n\t\treturn () => [node]\n\t}\n\tfunction attach(setup: () => Child, parent: N, scope: Scope) {\n\t\tlet nodes: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes())\n\t\t}\n\t\tnodes = mount(() => untrack(setup), scope, sync)\n\t\tsync()\n\t\tscope._cleanups.add(() => {\n\t\t\thost.children(parent, [])\n\t\t})\n\t}\n\treturn {\n\t\t/** Attach beneath the current component; disposal follows its lifetime. */\n\t\tmount(setup: () => Child, parent: N): void {\n\t\t\tif (!owner) throw new Error(`spa: scene mount requires an owner`)\n\t\t\tconst scope = createScope(owner)\n\t\t\ttry {\n\t\t\t\tattach(setup, parent, scope)\n\t\t\t} catch (error) {\n\t\t\t\tfail(scope, error)\n\t\t\t}\n\t\t},\n\t\trender(setup: () => Child, parent: N, options: RootOptions = {}) {\n\t\t\tconst root = createRoot(options)\n\t\t\ttry {\n\t\t\t\twithin(root, () => {\n\t\t\t\t\tattach(setup, parent, root)\n\t\t\t\t})\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tfail(root, error)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tflush: root.flush,\n\t\t\t\tdispose: () => {\n\t\t\t\t\tdispose(root)\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\n/** Define a typed scene component without introducing another JSX runtime. */\nexport function sceneComponent<P>(type: string): (props: P) => VNode {\n\treturn (props) => ({ type, props: props as Record<string, any> })\n}\n\n/** Bind imperative scene work to the current owner and its reactive dependencies. */\nexport function bindScene<T>(read: () => T, apply: (value: T) => void): void {\n\tobserve(owner!, read, apply)\n}\n\n/** Scene drawing follows an installed capability clock, or the browser clock. */\nexport function onSceneFrame(callback: (time: number) => void): void {\n\tconst scope = owner!\n\tconst clocks = [...scope._root._capabilities.values()].filter(\n\t\t(capability) => capability.scheduleFrame,\n\t)\n\tif (clocks.length > 1)\n\t\tthrow new Error(`spa: multiple frame clock capabilities`)\n\tconst draw = (time: number) => {\n\t\tif (scope._dead) return\n\t\ttry {\n\t\t\tcallback(time)\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tfail(scope._root, error)\n\t\t\t} catch (failure) {\n\t\t\t\tscope._root.error(failure)\n\t\t\t}\n\t\t}\n\t}\n\tlet stop: () => void\n\tif (clocks[0]) stop = clocks[0].scheduleFrame!(draw)\n\telse {\n\t\tlet frame = 0\n\t\tconst tick = (time: number) => {\n\t\t\tif (scope._dead) return\n\t\t\tdraw(time)\n\t\t\tif (!scope._dead) frame = requestAnimationFrame(tick)\n\t\t}\n\t\tframe = requestAnimationFrame(tick)\n\t\tstop = () => {\n\t\t\tcancelAnimationFrame(frame)\n\t\t}\n\t}\n\tscope._cleanups.add(stop)\n}\n"],"mappings":";;;;AA2CA,SAAgB,oBAAuB,MAAsC;CAC5E,SAAS,MACR,QACA,OACA,SACY;EACZ,IAAI,UAAsB,CAAC;EAC3B,QAAQ,OAAO,SAAS,SAAS;GAChC,MAAM,SACL,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI;GAElD,MAAM,MAAM,IAAI,IACf,QAAQ,KAAK,OAAO,MAAM,CAAC,IAAI,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CACvD;GACA,MAAM,uBAAO,IAAI,IAAY;GAC7B,UAAU,OAAO,KAAK,OAAO,MAAM;IAClC,MAAM,KAAK,IAAI,OAAO,CAAC;IACvB,IAAI,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,0BAA0B;IAC5D,KAAK,IAAI,EAAE;IACX,IAAI,QAAQ,IAAI,IAAI,EAAE;IACtB,IAAI,OAAO,EAAE;IACb,IAAI,SAAS,CAAC,KAAK,MAAM,OAAO,KAAK,GAAG;K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
|
1
|
+
import { a as Child, s as RootOptions } from "./capabilities-yC9TsHDI.js";
|
|
2
2
|
export declare function renderToString(setup: () => Child, options?: RootOptions): string;
|
|
3
3
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"mappings":";wBAkJgB,eACf,aAAa,OACb,UAAS"}
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as within, a as createScope, h as untrack, i as createRoot, o as dispose, p as plain, r as validateCapabilities, t as capabilityNamespace } from "./capabilities-BuZUQpiD.js";
|
|
2
2
|
import { Fragment } from "./jsx-runtime.js";
|
|
3
3
|
// src/server.ts
|
|
4
4
|
const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
|
@@ -9,7 +9,7 @@ const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
|
|
|
9
9
|
"'": `'`
|
|
10
10
|
})[char]);
|
|
11
11
|
const voidTags = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
|
12
|
-
const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls default defer disabled formnovalidate
|
|
12
|
+
const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(` `));
|
|
13
13
|
function stringify(value, owner, namespace = `html`, selectValue) {
|
|
14
14
|
if (typeof value === `function`) {
|
|
15
15
|
const values = [untrack(value)].flat(Infinity);
|
|
@@ -35,23 +35,33 @@ function stringify(value, owner, namespace = `html`, selectValue) {
|
|
|
35
35
|
if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
|
|
36
36
|
if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
|
|
37
37
|
const ns = type === `svg` ? `svg` : namespace;
|
|
38
|
+
validateCapabilities(owner, props);
|
|
38
39
|
let attrs = ``;
|
|
39
40
|
let textValue;
|
|
40
41
|
for (let key of Object.keys(props)) {
|
|
41
|
-
if (key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
|
|
42
|
+
if (capabilityNamespace(key) !== void 0 || key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
|
|
42
43
|
if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
|
|
43
44
|
let attribute = props[key];
|
|
45
|
+
if (ns === `html`) {
|
|
46
|
+
if (key === `defaultValue` && (type === `input` || type === `textarea`)) {
|
|
47
|
+
if (props[`value`] != null) continue;
|
|
48
|
+
key = `value`;
|
|
49
|
+
} else if (key === `defaultChecked` && type === `input`) {
|
|
50
|
+
if (props[`checked`] != null) continue;
|
|
51
|
+
key = `checked`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
if (key === `className`) key = `class`;
|
|
45
55
|
if (key === `htmlFor`) key = `for`;
|
|
46
56
|
if (!/^[^\s"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`);
|
|
47
57
|
if (key === `value` && (type === `select` || type === `textarea`)) {
|
|
48
|
-
textValue = attribute;
|
|
58
|
+
textValue = attribute ?? textValue;
|
|
49
59
|
continue;
|
|
50
60
|
}
|
|
51
61
|
if (key === `style` && attribute != null && typeof attribute !== `string`) throw new TypeError(`spa: CSS string required`);
|
|
52
|
-
const boolean = ns === `html` && booleans.has(key.toLowerCase());
|
|
53
|
-
if (attribute == null || boolean && !attribute
|
|
54
|
-
attrs += boolean
|
|
62
|
+
const boolean = ns === `html` && (booleans.has(key.toLowerCase()) || /^(capture|download|hidden)$/.test(key) && typeof attribute === `boolean`);
|
|
63
|
+
if (attribute == null || boolean && !attribute) continue;
|
|
64
|
+
attrs += boolean ? ` ${key}=""` : ` ${key}="${escape(attribute)}"`;
|
|
55
65
|
}
|
|
56
66
|
if (type === `option` && selectValue !== void 0 && String(props[`value`]) === String(selectValue)) attrs += ` selected=""`;
|
|
57
67
|
if (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`;
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&`, \"<\": `<`, \">\": `>`, '\"': `"`, \"'\": `'` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls default defer disabled formnovalidate
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&`, \"<\": `<`, \">\": `>`, '\"': `"`, \"'\": `'` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Child,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = ([untrack(value)] as unknown[]).flat(Infinity) as Child[]\n\t\tconst keys = new Set<unknown>()\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map((child, index) => {\n\t\t\t\t\tconst explicit = (child as VNode | null)?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (keys.has(key)) throw new Error(`spa: duplicate key`)\n\t\t\t\t\tkeys.add(key)\n\t\t\t\t\treturn `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`\n\t\t\t\t})\n\t\t\t\t.join(``) +\n\t\t\t`<!--}-->`\n\t\t)\n\t}\n\tif (Array.isArray(value))\n\t\treturn value\n\t\t\t.map((child) => stringify(child, owner, namespace, selectValue))\n\t\t\t.join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (typeof value !== `object`) return `<!--t-->${escape(value)}`\n\tif (!(`type` in value) || !(`props` in value))\n\t\tthrow new TypeError(`spa: invalid child`)\n\tconst { type, props } = value\n\tif (!type || type === Fragment)\n\t\treturn stringify(() => props[`children`], owner, namespace, selectValue)\n\tif (typeof type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\treturn within(childOwner, () =>\n\t\t\tstringify(\n\t\t\t\tuntrack(() => type(props)),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tvalidateCapabilities(owner, props)\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tcapabilityNamespace(key) !== undefined ||\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute ?? textValue\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToString(\n\tsetup: () => Child,\n\toptions: RootOptions = {},\n): string {\n\tconst root = createRoot(options, true)\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":";;;AAYA,MAAM,UAAU,UACf,OAAO,KAAK,CAAC,CAAC,QACb,aACC,UACC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;CAAU,KAAK;AAAQ,EAAA,CACtE,KAEH;AACD,MAAM,WACL;AACD,MAAM,WAAW,IAAI,IACpB,qVAAqV,MACpV,GACD,CACD;AACA,SAAS,UACR,OACA,OACA,YAAY,QACZ,aACS;CACT,IAAI,OAAO,UAAU,YAAY;EA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G;EAClE,IAAI,OAAO,MACV,SAAS,aAAc,aAAa,MAAM,cAAe,MAAM,WAChE;EACA,IAAI,SAAS,cAAc,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK;EAC9D,IAAI,mBAAmB,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,GAC1E,MAAM,IAAI,MAAM,sBAAsB;EACvC,OAAO,IAAI,OAAO,MAAM,GAAG,mBAAmB,KAAK,IAAI,IAAI,OAAO,OAAO,IAAI,EAAE,IAAI,KAAK;CACzF;CACA,MAAM,WAAW,gBACV,MAAM,aACZ,OACA,SAAS,kBAAkB,SAAS,IACpC,SAAS,WAAW,YAAY,WACjC;CACA,OAAO,IAAI,OAAO,MAAM,GAAG,SAAS,IAAI,KAAK;AAC9C;AAEA,SAAgB,eACf,OACA,UAAuB,CAAC,GACf;CACT,MAAM,OAAO,WAAW,SAAS,IAAI;CACrC,IAAI,UAAU,KAAK,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,uBAAuB;CACzE,IAAI;EACH,OAAO,SAAS,KAAK,QAAQ,KAAK,OAAO,YAAY,UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
|
package/dist/size.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
3
|
"name": "spa client",
|
|
4
|
-
"raw":
|
|
5
|
-
"minified":
|
|
6
|
-
"gzip":
|
|
7
|
-
"brotli":
|
|
4
|
+
"raw": 18295,
|
|
5
|
+
"minified": 8786,
|
|
6
|
+
"gzip": 3710,
|
|
7
|
+
"brotli": 3376
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"name": "spa + atom.io",
|
|
11
|
-
"raw":
|
|
12
|
-
"minified":
|
|
13
|
-
"gzip":
|
|
14
|
-
"brotli":
|
|
11
|
+
"raw": 106921,
|
|
12
|
+
"minified": 52010,
|
|
13
|
+
"gzip": 15571,
|
|
14
|
+
"brotli": 14074
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"name": "spa Astro client",
|
|
18
|
-
"raw":
|
|
19
|
-
"minified":
|
|
20
|
-
"gzip":
|
|
21
|
-
"brotli":
|
|
18
|
+
"raw": 23105,
|
|
19
|
+
"minified": 10877,
|
|
20
|
+
"gzip": 4452,
|
|
21
|
+
"brotli": 4029
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"name": "Preact",
|
|
25
|
-
"raw":
|
|
26
|
-
"minified":
|
|
27
|
-
"gzip":
|
|
28
|
-
"brotli":
|
|
25
|
+
"raw": 17966,
|
|
26
|
+
"minified": 12004,
|
|
27
|
+
"gzip": 4956,
|
|
28
|
+
"brotli": 4540
|
|
29
29
|
}
|
|
30
30
|
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { S as useValue, f as owner, m as resolveStateToken } from "./capabilities-BuZUQpiD.js";
|
|
2
|
+
import { withdraw } from "atom.io/internal";
|
|
3
|
+
// src/use-loadable.ts
|
|
4
|
+
function useLoadable(...params) {
|
|
5
|
+
const store = owner._root._store;
|
|
6
|
+
const [token] = params;
|
|
7
|
+
const family = token.type.endsWith(`_family`);
|
|
8
|
+
const selected = resolveStateToken(token, params[1]);
|
|
9
|
+
const read = useValue(selected);
|
|
10
|
+
const fallbackIndex = family ? 2 : 1;
|
|
11
|
+
const fallback = params[fallbackIndex];
|
|
12
|
+
const hasFallback = params.length > fallbackIndex;
|
|
13
|
+
let available = hasFallback;
|
|
14
|
+
let previous = fallback;
|
|
15
|
+
let error;
|
|
16
|
+
return () => {
|
|
17
|
+
const value = read();
|
|
18
|
+
const loading = value instanceof Promise;
|
|
19
|
+
if (!loading) {
|
|
20
|
+
previous = value;
|
|
21
|
+
available = true;
|
|
22
|
+
const state = withdraw(store, selected);
|
|
23
|
+
error = hasFallback && `catch` in state && state.catch.some((ErrorType) => value instanceof ErrorType) ? value : void 0;
|
|
24
|
+
}
|
|
25
|
+
if (!available) return `LOADING`;
|
|
26
|
+
return error ? {
|
|
27
|
+
loading,
|
|
28
|
+
value: fallback,
|
|
29
|
+
error
|
|
30
|
+
} : {
|
|
31
|
+
loading,
|
|
32
|
+
value: previous
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export { useLoadable as t };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=src-BZxX4xbU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-BZxX4xbU.js","names":[],"sources":["../src/use-loadable.ts"],"sourcesContent":["import type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport { withdraw } from \"atom.io/internal\"\n\nimport { type Accessor, owner, resolveStateToken, useValue } from \"./core.ts\"\n\nexport type LoadableValue<T> = { loading: boolean; value: T }\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable(\n\t...params:\n\t\t| [ReadableToken<any, any, any>]\n\t\t| [ReadableToken<any, any, any>, unknown]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n): Accessor<`LOADING` | (LoadableValue<unknown> & { error?: unknown })> {\n\tconst store = owner!._root._store\n\tconst [token] = params\n\tconst family = token.type.endsWith(`_family`)\n\tconst selected = resolveStateToken(token, params[1] as Canonical)\n\tconst read = useValue(selected)\n\tconst fallbackIndex = family ? 2 : 1\n\tconst fallback = params[fallbackIndex]\n\tconst hasFallback = params.length > fallbackIndex\n\tlet available = hasFallback\n\tlet previous = fallback\n\tlet error: unknown\n\treturn () => {\n\t\tconst value = read()\n\t\tconst loading = value instanceof Promise\n\t\tif (!loading) {\n\t\t\tprevious = value\n\t\t\tavailable = true\n\t\t\tconst state = withdraw(store, selected)\n\t\t\terror =\n\t\t\t\thasFallback &&\n\t\t\t\t`catch` in state &&\n\t\t\t\tstate.catch.some((ErrorType) => value instanceof ErrorType)\n\t\t\t\t\t? value\n\t\t\t\t\t: undefined\n\t\t}\n\t\tif (!available) return `LOADING`\n\t\treturn error\n\t\t\t? { loading, value: fallback, error }\n\t\t\t: { loading, value: previous }\n\t}\n}\n"],"mappings":";;;AA6BA,SAAgB,YACf,GAAG,QAKoE;CACvE,MAAM,QAAQ,MAAO,MAAM;CAC3B,MAAM,CAAC,SAAS;CAChB,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS;CAC5C,MAAM,WAAW,kBAAkB,OAAO,OAAO,EAAe;CAChE,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,gBAAgB,SAAS,IAAI;CACnC,MAAM,WAAW,OAAO;CACxB,MAAM,cAAc,OAAO,SAAS;CACpC,IAAI,YAAY;CAChB,IAAI,WAAW;CACf,IAAI;CACJ,aAAa;EACZ,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,iBAAiB;EACjC,IAAI,CAAC,SAAS;GACb,WAAW;GACX,YAAY;GACZ,MAAM,QAAQ,SAAS,OAAO,QAAQ;GACtC,QACC,eACA,WAAW,SACX,MAAM,MAAM,MAAM,cAAc,iBAAiB,SAAS,IACvD,QACA,KAAA;EACL;EACA,IAAI,CAAC,WAAW,OAAO;EACvB,OAAO,QACJ;GAAE;GAAS,OAAO;GAAU;EAAM,IAClC;GAAE;GAAS,OAAO;EAAS;CAC/B;AACD"}
|
package/dist/three.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { a as Child, l as VNode } from "./capabilities-yC9TsHDI.js";
|
|
2
|
+
import { SceneRenderer } from "./renderer.js";
|
|
3
|
+
import "./index-BdwxmSKg.js";
|
|
4
|
+
import { t as CapabilityAttributes } from "./jsx-runtime-CZU7F8Qz.js";
|
|
5
|
+
import * as THREE from "three";
|
|
6
|
+
interface ThreePointerEvent<N extends THREE.Object3D = THREE.Object3D> {
|
|
7
|
+
type: string;
|
|
8
|
+
nativeEvent: PointerEvent;
|
|
9
|
+
target: THREE.Object3D;
|
|
10
|
+
currentTarget: N;
|
|
11
|
+
intersection: THREE.Intersection;
|
|
12
|
+
ray: THREE.Ray;
|
|
13
|
+
pointerId: number;
|
|
14
|
+
button: number;
|
|
15
|
+
buttons: number;
|
|
16
|
+
clientX: number;
|
|
17
|
+
clientY: number;
|
|
18
|
+
stopPropagation(): void;
|
|
19
|
+
preventDefault(): void;
|
|
20
|
+
setPointerCapture(): void;
|
|
21
|
+
releasePointerCapture(): void;
|
|
22
|
+
hasPointerCapture(): boolean;
|
|
23
|
+
}
|
|
24
|
+
type ThreeEventHandler<N extends THREE.Object3D = THREE.Object3D> = (event: ThreePointerEvent<N>) => void;
|
|
25
|
+
interface ThreeEventAttributes<N extends THREE.Object3D = THREE.Object3D> {
|
|
26
|
+
onPointerDown?: ThreeEventHandler<N>;
|
|
27
|
+
onPointerUp?: ThreeEventHandler<N>;
|
|
28
|
+
onPointerMove?: ThreeEventHandler<N>;
|
|
29
|
+
onPointerEnter?: ThreeEventHandler<N>;
|
|
30
|
+
onPointerLeave?: ThreeEventHandler<N>;
|
|
31
|
+
onPointerOver?: ThreeEventHandler<N>;
|
|
32
|
+
onPointerOut?: ThreeEventHandler<N>;
|
|
33
|
+
onPointerCancel?: ThreeEventHandler<N>;
|
|
34
|
+
onClick?: ThreeEventHandler<N>;
|
|
35
|
+
}
|
|
36
|
+
interface ThreeEventManager {
|
|
37
|
+
update(): void;
|
|
38
|
+
/** Release hover, press, and capture state for a removed subtree. */
|
|
39
|
+
remove(node: THREE.Object3D): void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
42
|
+
/** Attach raycast pointer routing to a canvas; usable with borrowed scene roots. */
|
|
43
|
+
export declare function createThreeEvents(canvas: HTMLCanvasElement, scene: THREE.Object3D, camera: () => THREE.Camera, onError?: (error: unknown) => void): ThreeEventManager;
|
|
44
|
+
type Resource = THREE.Object3D | THREE.BufferGeometry | THREE.Material;
|
|
45
|
+
type Vector3 = readonly [number, number, number];
|
|
46
|
+
export interface ObjectProps<N extends THREE.Object3D = THREE.Object3D> extends CapabilityAttributes<`three`>, ThreeEventAttributes<N> {
|
|
47
|
+
children?: Child;
|
|
48
|
+
position?: Vector3;
|
|
49
|
+
rotation?: Vector3;
|
|
50
|
+
scale?: Vector3 | number;
|
|
51
|
+
visible?: boolean;
|
|
52
|
+
name?: string;
|
|
53
|
+
ref?: (object: N | null) => void;
|
|
54
|
+
}
|
|
55
|
+
declare const renderer: SceneRenderer<Resource>;
|
|
56
|
+
export interface CanvasProps {
|
|
57
|
+
children?: Child;
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
camera?: THREE.Camera;
|
|
61
|
+
onFrame?: (state: {
|
|
62
|
+
scene: THREE.Scene;
|
|
63
|
+
camera: THREE.Camera;
|
|
64
|
+
renderer: THREE.WebGLRenderer;
|
|
65
|
+
delta: number;
|
|
66
|
+
time: number;
|
|
67
|
+
}) => void;
|
|
68
|
+
}
|
|
69
|
+
/** Browser-only scene boundary. The camera prop is borrowed and never disposed. */
|
|
70
|
+
export declare function Canvas(props: CanvasProps): VNode;
|
|
71
|
+
export declare const Group: (props: ObjectProps<THREE.Object3D<THREE.Object3DEventMap>>) => VNode;
|
|
72
|
+
export declare const Mesh: (props: ObjectProps<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material<THREE.MaterialEventMap>[] | THREE.Material<THREE.MaterialEventMap>, THREE.Object3DEventMap>>) => VNode;
|
|
73
|
+
export declare const PerspectiveCamera: (props: ObjectProps<THREE.PerspectiveCamera> & {
|
|
74
|
+
args?: ConstructorParameters<typeof THREE.PerspectiveCamera>;
|
|
75
|
+
fov?: number;
|
|
76
|
+
aspect?: number;
|
|
77
|
+
near?: number;
|
|
78
|
+
far?: number;
|
|
79
|
+
}) => VNode;
|
|
80
|
+
export declare const AmbientLight: (props: ObjectProps<THREE.Light> & {
|
|
81
|
+
color?: THREE.ColorRepresentation;
|
|
82
|
+
intensity?: number;
|
|
83
|
+
}) => VNode;
|
|
84
|
+
export declare const DirectionalLight: (props: ObjectProps<THREE.Light> & {
|
|
85
|
+
color?: THREE.ColorRepresentation;
|
|
86
|
+
intensity?: number;
|
|
87
|
+
}) => VNode;
|
|
88
|
+
export declare const BoxGeometry: (props: {
|
|
89
|
+
args?: ConstructorParameters<typeof THREE.BoxGeometry>;
|
|
90
|
+
ref?: (node: THREE.BoxGeometry | null) => void;
|
|
91
|
+
}) => VNode;
|
|
92
|
+
export declare const SphereGeometry: (props: {
|
|
93
|
+
args?: ConstructorParameters<typeof THREE.SphereGeometry>;
|
|
94
|
+
ref?: (node: THREE.SphereGeometry | null) => void;
|
|
95
|
+
}) => VNode;
|
|
96
|
+
export declare const PlaneGeometry: (props: {
|
|
97
|
+
args?: ConstructorParameters<typeof THREE.PlaneGeometry>;
|
|
98
|
+
ref?: (node: THREE.PlaneGeometry | null) => void;
|
|
99
|
+
}) => VNode;
|
|
100
|
+
export declare const MeshStandardMaterial: (props: THREE.MeshStandardMaterialParameters & CapabilityAttributes<"three"> & {
|
|
101
|
+
ref?: (node: THREE.MeshStandardMaterial | null) => void;
|
|
102
|
+
}) => VNode;
|
|
103
|
+
export declare const MeshBasicMaterial: (props: THREE.MeshBasicMaterialParameters & CapabilityAttributes<"three"> & {
|
|
104
|
+
ref?: (node: THREE.MeshBasicMaterial | null) => void;
|
|
105
|
+
}) => VNode;
|
|
106
|
+
export declare const MeshNormalMaterial: (props: THREE.MeshNormalMaterialParameters & CapabilityAttributes<"three"> & {
|
|
107
|
+
ref?: (node: THREE.MeshNormalMaterial | null) => void;
|
|
108
|
+
}) => VNode;
|
|
109
|
+
export { type ThreeEventAttributes, type ThreeEventHandler, type ThreeEventManager, type ThreePointerEvent, renderer as threeRenderer };
|
|
110
|
+
//# sourceMappingURL=three.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three.d.ts","names":["_$__renderer_ts0.SceneRenderer"],"sources":["../src/three-events.ts","../src/three.ts"],"mappings":";;;;;UAEiB,kBAAkB,UAAU,MAAM,WAAW,MAAM;EACnE;EACA,aAAa;EACb,QAAQ,MAAM;EACd,eAAe;EACf,cAAc,MAAM;EACpB,KAAK,MAAM;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAEW,kBAAkB,UAAU,MAAM,WAAW,MAAM,aAC9D,OAAO,kBAAkB;UAET,qBAChB,UAAU,MAAM,WAAW,MAAM;EAEjC,gBAAgB,kBAAkB;EAClC,cAAc,kBAAkB;EAChC,gBAAgB,kBAAkB;EAClC,iBAAiB,kBAAkB;EACnC,iBAAiB,kBAAkB;EACnC,gBAAgB,kBAAkB;EAClC,eAAe,kBAAkB;EACjC,kBAAkB,kBAAkB;EACpC,UAAU,kBAAkB;;UAmCZ;EAChB;;EAEA,OAAO,MAAM,MAAM;EACnB;;;wBAIe,kBACf,QAAQ,mBACR,OAAO,MAAM,UACb,cAAc,MAAM,QACpB,WAAU,0BAGR;KC5DE,WAAW,MAAM,WAAW,MAAM,iBAAiB,MAAM;KACzD;iBACY,YAAY,UAAU,MAAM,WAAW,MAAM,kBACrD,+BAA+B,q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