@octanejs/three 0.1.24 → 0.1.26
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 +13 -0
- package/package.json +6 -6
- package/src/core/catalogue.ts +17 -5
- package/src/core/constructors.ts +36 -0
- package/src/core/driver.ts +712 -22
- package/src/core/events.ts +152 -52
- package/src/core/hooks.ts +5 -1
- package/src/core/props.ts +2 -6
- package/src/core/store.ts +24 -19
- package/src/renderer.ts +1 -0
- package/src/scheduling.ts +11 -5
- package/src/web/Canvas.tsrx +2 -0
- package/src/web/dom-region.ts +6 -1
package/README.md
CHANGED
|
@@ -137,6 +137,19 @@ root.render(Scene, { color: 'hotpink' });
|
|
|
137
137
|
root.store.getState().advance(1 / 60);
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
+
Compiled Three scene modules import and register only the built-in constructors
|
|
141
|
+
used by their authored intrinsic tags, so direct roots do not retain the entire
|
|
142
|
+
Three namespace. Both extension forms remain selective: `extend({ CustomMesh })`
|
|
143
|
+
registers the named constructor, while `extend(CustomMesh)` returns a stable
|
|
144
|
+
callable component without registering unrelated built-ins. An explicit
|
|
145
|
+
extension always takes precedence over a compiler-registered constructor.
|
|
146
|
+
|
|
147
|
+
`Canvas` registers the complete Three namespace when it first renders, retaining
|
|
148
|
+
the familiar R3F-compatible catalogue for dynamic or otherwise uncompiled scene
|
|
149
|
+
content. Code that constructs low-level universal host plans by hand instead
|
|
150
|
+
of compiling a `.three.tsrx` scene must register each constructor itself before
|
|
151
|
+
rendering, for example `extend({ Mesh })` for a manually authored `mesh` plan.
|
|
152
|
+
|
|
140
153
|
Direct-root scheduling uses Octane's public `act` and `flushSync` semantics.
|
|
141
154
|
Call `root.unmount()` directly, or use
|
|
142
155
|
`unmountComponentAtNode(canvas, optionalCallback)` to remove the root registered
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/three",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@types/three": ">=0.156.0",
|
|
53
53
|
"three": ">=0.156.0",
|
|
54
|
-
"octane": "0.1.
|
|
54
|
+
"octane": "0.1.33"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"@types/three": {
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"typescript": "^5.9.3",
|
|
73
73
|
"vite": "^8.1.5",
|
|
74
74
|
"vitest": "^4.1.10",
|
|
75
|
-
"@octanejs/rsbuild-plugin": "0.1.
|
|
76
|
-
"@octanejs/rspack-plugin": "0.1.
|
|
77
|
-
"@octanejs/vite-plugin": "0.1.
|
|
78
|
-
"octane": "0.1.
|
|
75
|
+
"@octanejs/rsbuild-plugin": "0.1.28",
|
|
76
|
+
"@octanejs/rspack-plugin": "0.1.28",
|
|
77
|
+
"@octanejs/vite-plugin": "0.1.33",
|
|
78
|
+
"octane": "0.1.33"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"test": "pnpm upstream:check && vitest run --root ../.. --project three",
|
package/src/core/catalogue.ts
CHANGED
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
import * as THREE from 'three';
|
|
8
8
|
import {
|
|
9
9
|
defineUniversalComponent,
|
|
10
|
+
markUniversalHostComponent,
|
|
10
11
|
type UniversalComponent,
|
|
11
12
|
universalPlan,
|
|
12
13
|
universalProps,
|
|
13
14
|
universalValue,
|
|
14
15
|
} from 'octane/universal';
|
|
15
16
|
import type { EventHandlers } from './events.js';
|
|
17
|
+
import { registerTrustedThreeConstructor } from './constructors.js';
|
|
16
18
|
|
|
17
19
|
export const THREE_RENDERER_ID = 'three';
|
|
18
20
|
|
|
@@ -181,11 +183,23 @@ function toPascalCase(type: string): string {
|
|
|
181
183
|
return type.length === 0 ? type : `${type[0].toUpperCase()}${type.slice(1)}`;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
/** Register
|
|
186
|
+
/** Register one compiler-selected built-in without replacing an authored extension. */
|
|
187
|
+
export function registerThreeIntrinsic(name: string, Constructor: ConstructorRepresentation): void {
|
|
188
|
+
registerTrustedThreeConstructor(Constructor);
|
|
189
|
+
if (!Object.hasOwn(catalogue, name)) catalogue[name] = Constructor;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Register the complete Three namespace only for Canvas's compatibility surface. */
|
|
185
193
|
export function registerThreeNamespace(): void {
|
|
186
194
|
if (namespaceRegistered) return;
|
|
187
195
|
namespaceRegistered = true;
|
|
188
|
-
Object.
|
|
196
|
+
for (const name of Object.keys(THREE)) {
|
|
197
|
+
const Constructor = (THREE as unknown as Catalogue)[name];
|
|
198
|
+
registerTrustedThreeConstructor(Constructor);
|
|
199
|
+
if (!Object.hasOwn(catalogue, name)) {
|
|
200
|
+
catalogue[name] = Constructor;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
189
203
|
}
|
|
190
204
|
|
|
191
205
|
/** Resolve conflicting `threeLine`-style host names without shadowing explicit extensions. */
|
|
@@ -241,9 +255,6 @@ export function extend<T extends Catalogue>(objects: T): void;
|
|
|
241
255
|
export function extend<T extends Catalogue | ConstructorRepresentation>(
|
|
242
256
|
objects: T,
|
|
243
257
|
): UniversalComponent<any> | void {
|
|
244
|
-
// Seed built-ins before user entries so an explicit extension can override a
|
|
245
|
-
// catalogue name deterministically, independent of driver creation order.
|
|
246
|
-
registerThreeNamespace();
|
|
247
258
|
if (typeof objects !== 'function') {
|
|
248
259
|
Object.assign(catalogue, objects);
|
|
249
260
|
return;
|
|
@@ -261,6 +272,7 @@ export function extend<T extends Catalogue | ConstructorRepresentation>(
|
|
|
261
272
|
(props) => universalValue(plan, [universalProps([['spread', props]])]),
|
|
262
273
|
{ module: '@octanejs/three' },
|
|
263
274
|
);
|
|
275
|
+
markUniversalHostComponent(component, THREE_RENDERER_ID, plan);
|
|
264
276
|
constructorComponents.set(objects, component);
|
|
265
277
|
return component as UniversalComponent<any>;
|
|
266
278
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Color,
|
|
3
|
+
Euler,
|
|
4
|
+
Layers,
|
|
5
|
+
Matrix3,
|
|
6
|
+
Matrix4,
|
|
7
|
+
Quaternion,
|
|
8
|
+
Vector2,
|
|
9
|
+
Vector3,
|
|
10
|
+
Vector4,
|
|
11
|
+
} from 'three';
|
|
12
|
+
|
|
13
|
+
// These value classes occur on ordinary Three objects even when they are not
|
|
14
|
+
// authored as scene intrinsics. Keep their identities explicit so bundlers can
|
|
15
|
+
// discard the rest of the Three namespace and custom subclasses stay untrusted.
|
|
16
|
+
const TRUSTED_THREE_CONSTRUCTORS = new WeakSet<Function>([
|
|
17
|
+
Color,
|
|
18
|
+
Euler,
|
|
19
|
+
Layers,
|
|
20
|
+
Matrix3,
|
|
21
|
+
Matrix4,
|
|
22
|
+
Quaternion,
|
|
23
|
+
Vector2,
|
|
24
|
+
Vector3,
|
|
25
|
+
Vector4,
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/** Accept constructors obtained from compiler-owned or full Three namespace registration. */
|
|
29
|
+
export function registerTrustedThreeConstructor(value: unknown): void {
|
|
30
|
+
if (typeof value === 'function') TRUSTED_THREE_CONSTRUCTORS.add(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Only an exact Three constructor, never a derived custom class, is trusted. */
|
|
34
|
+
export function isTrustedThreeConstructor(value: unknown): boolean {
|
|
35
|
+
return typeof value === 'function' && TRUSTED_THREE_CONSTRUCTORS.has(value);
|
|
36
|
+
}
|