@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/src/core/events.ts
CHANGED
|
@@ -143,6 +143,15 @@ const POINTER_MOVE_LISTENERS = [
|
|
|
143
143
|
'onPointerLeave',
|
|
144
144
|
] as const;
|
|
145
145
|
|
|
146
|
+
const POINTER_HOVER_LISTENERS = [
|
|
147
|
+
'onPointerOver',
|
|
148
|
+
'onPointerEnter',
|
|
149
|
+
'onPointerOut',
|
|
150
|
+
'onPointerLeave',
|
|
151
|
+
] as const;
|
|
152
|
+
|
|
153
|
+
const STANDARD_MESH_RAYCAST = THREE.Mesh.prototype.raycast;
|
|
154
|
+
|
|
146
155
|
const NATIVE_EVENT_NAMES: Readonly<Record<keyof Events, true>> = Object.freeze({
|
|
147
156
|
onClick: true,
|
|
148
157
|
onContextMenu: true,
|
|
@@ -220,9 +229,7 @@ export function createEvents(store: RootStore): {
|
|
|
220
229
|
}
|
|
221
230
|
|
|
222
231
|
function filterPointerEvents(objects: THREE.Object3D[]): THREE.Object3D[] {
|
|
223
|
-
return objects.filter((object) =>
|
|
224
|
-
POINTER_MOVE_LISTENERS.some((name) => getThreeEventListener(object, name) !== undefined),
|
|
225
|
-
);
|
|
232
|
+
return objects.filter((object) => hasThreeEventListeners(object, POINTER_MOVE_LISTENERS));
|
|
226
233
|
}
|
|
227
234
|
|
|
228
235
|
function intersect(
|
|
@@ -235,53 +242,89 @@ export function createEvents(store: RootStore): {
|
|
|
235
242
|
const eventObjects = filter
|
|
236
243
|
? filter(rootState.internal.interaction)
|
|
237
244
|
: rootState.internal.interaction;
|
|
245
|
+
let sharedEventStore: RootStore | undefined;
|
|
246
|
+
let singleEventStore = true;
|
|
247
|
+
let previousEventStore: RootStore | undefined;
|
|
238
248
|
|
|
239
249
|
// Each event layer computes its ray lazily, once, for this native event.
|
|
240
250
|
for (const object of eventObjects) {
|
|
241
251
|
const objectStore = getThreeEventStore(object);
|
|
242
|
-
if (objectStore
|
|
252
|
+
if (objectStore === undefined) {
|
|
253
|
+
singleEventStore = false;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (sharedEventStore === undefined) sharedEventStore = objectStore;
|
|
257
|
+
else if (sharedEventStore !== objectStore) singleEventStore = false;
|
|
258
|
+
if (objectStore !== previousEventStore) {
|
|
259
|
+
objectStore.getState().raycaster.camera = undefined!;
|
|
260
|
+
previousEventStore = objectStore;
|
|
261
|
+
}
|
|
243
262
|
}
|
|
244
263
|
|
|
245
264
|
if (!rootState.previousRoot) {
|
|
246
265
|
rootState.events.compute?.(event, rootState);
|
|
247
266
|
}
|
|
248
267
|
|
|
249
|
-
|
|
268
|
+
const rawHits: THREE.Intersection<THREE.Object3D>[] = [];
|
|
269
|
+
for (const object of eventObjects) {
|
|
250
270
|
const objectStore = getThreeEventStore(object);
|
|
251
|
-
if (objectStore === undefined)
|
|
271
|
+
if (objectStore === undefined) continue;
|
|
272
|
+
if (objectStore !== sharedEventStore) singleEventStore = false;
|
|
252
273
|
const state = objectStore.getState();
|
|
253
|
-
if (!state.events.enabled || state.raycaster.camera === null)
|
|
274
|
+
if (!state.events.enabled || state.raycaster.camera === null) continue;
|
|
254
275
|
|
|
255
276
|
if (state.raycaster.camera === undefined) {
|
|
256
277
|
state.events.compute?.(event, state, state.previousRoot?.getState());
|
|
257
278
|
if (state.raycaster.camera === undefined) state.raycaster.camera = null!;
|
|
258
279
|
}
|
|
259
280
|
|
|
260
|
-
if (!state.raycaster.camera)
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
281
|
+
if (!state.raycaster.camera) continue;
|
|
282
|
+
const sharesHitArray =
|
|
283
|
+
Object.getPrototypeOf(object) === THREE.Mesh.prototype &&
|
|
284
|
+
!Object.prototype.hasOwnProperty.call(object, 'raycast') &&
|
|
285
|
+
THREE.Mesh.prototype.raycast === STANDARD_MESH_RAYCAST &&
|
|
286
|
+
object.children.length === 0;
|
|
287
|
+
const objectHits = sharesHitArray ? rawHits : [];
|
|
288
|
+
const firstHit = objectHits.length;
|
|
289
|
+
raycastLiveObject(state.raycaster, object, objectHits);
|
|
290
|
+
let retainedHits = firstHit;
|
|
291
|
+
for (let index = firstHit; index < objectHits.length; index++) {
|
|
292
|
+
const hit = objectHits[index];
|
|
293
|
+
if (!isThreeEventHitLive(hit.object)) continue;
|
|
294
|
+
if (singleEventStore && getThreeEventStore(hit.object) !== sharedEventStore) {
|
|
295
|
+
singleEventStore = false;
|
|
296
|
+
}
|
|
297
|
+
if (sharesHitArray) rawHits[retainedHits++] = hit;
|
|
298
|
+
else rawHits.push(hit);
|
|
299
|
+
}
|
|
300
|
+
if (sharesHitArray) rawHits.length = retainedHits;
|
|
264
301
|
}
|
|
265
302
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
303
|
+
rawHits.sort(
|
|
304
|
+
singleEventStore
|
|
305
|
+
? (left, right) => left.distance - right.distance
|
|
306
|
+
: (left, right) => {
|
|
307
|
+
const leftStore = findEventStore(left.object);
|
|
308
|
+
const rightStore = findEventStore(right.object);
|
|
309
|
+
if (leftStore === undefined || rightStore === undefined) {
|
|
310
|
+
return left.distance - right.distance;
|
|
311
|
+
}
|
|
312
|
+
return (
|
|
313
|
+
rightStore.getState().events.priority - leftStore.getState().events.priority ||
|
|
314
|
+
left.distance - right.distance
|
|
315
|
+
);
|
|
316
|
+
},
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
let hitCount = 0;
|
|
320
|
+
for (const hit of rawHits) {
|
|
321
|
+
const id = makeIntersectionId(hit as Intersection);
|
|
322
|
+
if (duplicates.has(id)) continue;
|
|
323
|
+
duplicates.add(id);
|
|
324
|
+
rawHits[hitCount++] = hit;
|
|
325
|
+
}
|
|
326
|
+
rawHits.length = hitCount;
|
|
327
|
+
let hits = rawHits;
|
|
285
328
|
|
|
286
329
|
if (rootState.events.filter !== undefined) {
|
|
287
330
|
hits = rootState.events.filter(hits, rootState);
|
|
@@ -347,10 +390,13 @@ export function createEvents(store: RootStore): {
|
|
|
347
390
|
intersections: Intersection[],
|
|
348
391
|
event: DomEvent,
|
|
349
392
|
delta: number,
|
|
350
|
-
callback: (event: ThreeEvent<DomEvent
|
|
393
|
+
callback: (event: ThreeEvent<DomEvent>, retainPointerCapture: () => void) => void,
|
|
351
394
|
): Intersection[] {
|
|
352
395
|
if (intersections.length === 0) return intersections;
|
|
353
396
|
const localState = { stopped: false };
|
|
397
|
+
let nativeProperties: Record<string, unknown> | undefined;
|
|
398
|
+
let ownNativeProperties: string[] | undefined;
|
|
399
|
+
let reusableNativeProperties = false;
|
|
354
400
|
|
|
355
401
|
for (const hit of intersections) {
|
|
356
402
|
const eventStore = findEventStore(hit.object);
|
|
@@ -359,18 +405,27 @@ export function createEvents(store: RootStore): {
|
|
|
359
405
|
const { raycaster, pointer, camera, internal } = state;
|
|
360
406
|
const unprojectedPoint = new THREE.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
361
407
|
|
|
362
|
-
|
|
408
|
+
let captureIdentity: ReturnType<typeof createPointerCaptureIdentity> | undefined;
|
|
409
|
+
const ensurePointerCaptureIdentity = () => {
|
|
410
|
+
if (captureIdentity !== undefined) return captureIdentity;
|
|
411
|
+
captureIdentity = createPointerCaptureIdentity(hit);
|
|
412
|
+
registerPointerCaptureFacade(target, captureIdentity);
|
|
413
|
+
registerPointerCaptureFacade(currentTarget, captureIdentity);
|
|
414
|
+
return captureIdentity;
|
|
415
|
+
};
|
|
363
416
|
const hasPointerCapture = (pointerId: number): boolean =>
|
|
364
|
-
internal.capturedMap.get(pointerId)?.has(captureIdentity.eventObject) ??
|
|
417
|
+
internal.capturedMap.get(pointerId)?.has(captureIdentity?.eventObject ?? hit.eventObject) ??
|
|
418
|
+
false;
|
|
365
419
|
|
|
366
420
|
const setPointerCapture = (pointerId: number): void => {
|
|
421
|
+
const identity = ensurePointerCaptureIdentity();
|
|
367
422
|
const target = event.target as Element;
|
|
368
|
-
const capture = { intersection:
|
|
423
|
+
const capture = { intersection: identity.intersection, target };
|
|
369
424
|
setInternalPointerCapture(
|
|
370
425
|
internal.capturedMap,
|
|
371
|
-
|
|
426
|
+
identity.eventObject,
|
|
372
427
|
capture,
|
|
373
|
-
|
|
428
|
+
identity,
|
|
374
429
|
pointerId,
|
|
375
430
|
);
|
|
376
431
|
target.setPointerCapture(pointerId);
|
|
@@ -381,25 +436,73 @@ export function createEvents(store: RootStore): {
|
|
|
381
436
|
if (captures !== undefined) {
|
|
382
437
|
releaseInternalPointerCapture(
|
|
383
438
|
internal.capturedMap,
|
|
384
|
-
captureIdentity.eventObject,
|
|
439
|
+
captureIdentity?.eventObject ?? hit.eventObject,
|
|
385
440
|
captures,
|
|
386
441
|
pointerId,
|
|
387
442
|
);
|
|
388
443
|
}
|
|
389
444
|
};
|
|
390
445
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
446
|
+
if (nativeProperties === undefined) {
|
|
447
|
+
nativeProperties = {};
|
|
448
|
+
const prototype = Object.getPrototypeOf(event);
|
|
449
|
+
reusableNativeProperties =
|
|
450
|
+
(typeof PointerEvent !== 'undefined' && prototype === PointerEvent.prototype) ||
|
|
451
|
+
(typeof MouseEvent !== 'undefined' && prototype === MouseEvent.prototype) ||
|
|
452
|
+
(typeof WheelEvent !== 'undefined' && prototype === WheelEvent.prototype);
|
|
453
|
+
// Inherited native-event getters are stable during this dispatch. Snapshot
|
|
454
|
+
// ordinary event prototypes once; custom subclasses can expose changing
|
|
455
|
+
// inherited getters and retain the complete per-hit extraction.
|
|
456
|
+
for (const property in event) {
|
|
457
|
+
const value = event[property as keyof DomEvent];
|
|
458
|
+
if (typeof value !== 'function') nativeProperties[property] = value;
|
|
459
|
+
}
|
|
460
|
+
// The native event exposes dozens of inherited fields. Building this
|
|
461
|
+
// snapshot dynamically puts it in dictionary mode; clone it once so
|
|
462
|
+
// the per-hit spreads retain a compact, reusable property shape.
|
|
463
|
+
nativeProperties = { ...nativeProperties };
|
|
464
|
+
ownNativeProperties = Object.keys(event);
|
|
465
|
+
} else if (!reusableNativeProperties) {
|
|
466
|
+
nativeProperties = {};
|
|
467
|
+
for (const property in event) {
|
|
468
|
+
const value = event[property as keyof DomEvent];
|
|
469
|
+
if (typeof value !== 'function') nativeProperties[property] = value;
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
for (const property of ownNativeProperties!) {
|
|
473
|
+
if (Object.prototype.propertyIsEnumerable.call(event, property)) continue;
|
|
474
|
+
delete nativeProperties[property];
|
|
475
|
+
|
|
476
|
+
if (Object.prototype.hasOwnProperty.call(event, property)) continue;
|
|
477
|
+
let prototype = Object.getPrototypeOf(event);
|
|
478
|
+
while (prototype !== null) {
|
|
479
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
|
480
|
+
if (descriptor !== undefined) {
|
|
481
|
+
if (descriptor.enumerable) {
|
|
482
|
+
const value = event[property as keyof DomEvent];
|
|
483
|
+
if (typeof value !== 'function') nativeProperties[property] = value;
|
|
484
|
+
}
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
ownNativeProperties = Object.keys(event);
|
|
492
|
+
for (const property of ownNativeProperties) {
|
|
493
|
+
const value = event[property as keyof DomEvent];
|
|
494
|
+
if (typeof value === 'function') delete nativeProperties[property];
|
|
495
|
+
else nativeProperties[property] = value;
|
|
496
|
+
}
|
|
497
|
+
if ('defaultPrevented' in nativeProperties) {
|
|
498
|
+
nativeProperties.defaultPrevented = event.defaultPrevented;
|
|
499
|
+
}
|
|
500
|
+
if ('cancelBubble' in nativeProperties) nativeProperties.cancelBubble = event.cancelBubble;
|
|
501
|
+
if ('returnValue' in nativeProperties) nativeProperties.returnValue = event.returnValue;
|
|
397
502
|
}
|
|
398
503
|
|
|
399
504
|
const target = { hasPointerCapture, setPointerCapture, releasePointerCapture };
|
|
400
505
|
const currentTarget = { hasPointerCapture, setPointerCapture, releasePointerCapture };
|
|
401
|
-
registerPointerCaptureFacade(target, captureIdentity);
|
|
402
|
-
registerPointerCaptureFacade(currentTarget, captureIdentity);
|
|
403
506
|
|
|
404
507
|
const raycastEvent = {
|
|
405
508
|
...hit,
|
|
@@ -430,7 +533,7 @@ export function createEvents(store: RootStore): {
|
|
|
430
533
|
nativeEvent: event,
|
|
431
534
|
} as unknown as ThreeEvent<DomEvent>;
|
|
432
535
|
|
|
433
|
-
callback(raycastEvent);
|
|
536
|
+
callback(raycastEvent, ensurePointerCaptureIdentity);
|
|
434
537
|
if (localState.stopped) break;
|
|
435
538
|
}
|
|
436
539
|
return intersections;
|
|
@@ -458,20 +561,17 @@ export function createEvents(store: RootStore): {
|
|
|
458
561
|
|
|
459
562
|
if (isPointerMove) cancelPointer(hits);
|
|
460
563
|
|
|
461
|
-
function onIntersect(data: ThreeEvent<DomEvent
|
|
564
|
+
function onIntersect(data: ThreeEvent<DomEvent>, retainPointerCapture: () => void): void {
|
|
462
565
|
const { eventObject } = data;
|
|
463
566
|
const eventStore = findEventStore(eventObject) ?? store;
|
|
464
567
|
|
|
465
568
|
if (isPointerMove) {
|
|
466
|
-
const hasHoverHandler =
|
|
467
|
-
getThreeEventListener(eventObject, 'onPointerOver') !== undefined ||
|
|
468
|
-
getThreeEventListener(eventObject, 'onPointerEnter') !== undefined ||
|
|
469
|
-
getThreeEventListener(eventObject, 'onPointerOut') !== undefined ||
|
|
470
|
-
getThreeEventListener(eventObject, 'onPointerLeave') !== undefined;
|
|
569
|
+
const hasHoverHandler = hasThreeEventListeners(eventObject, POINTER_HOVER_LISTENERS);
|
|
471
570
|
if (hasHoverHandler) {
|
|
472
571
|
const id = makeIntersectionId(data);
|
|
473
572
|
const hovered = internal.hovered.get(id);
|
|
474
573
|
if (hovered === undefined) {
|
|
574
|
+
retainPointerCapture();
|
|
475
575
|
internal.hovered.set(id, data);
|
|
476
576
|
invokeListener(eventStore, getThreeEventListener(eventObject, 'onPointerOver'), data);
|
|
477
577
|
invokeListener(eventStore, getThreeEventListener(eventObject, 'onPointerEnter'), data);
|
package/src/core/hooks.ts
CHANGED
|
@@ -131,7 +131,11 @@ export function useFrame(callback: RenderCallback, ...args: unknown[]): null {
|
|
|
131
131
|
const [userArgs, slot] = splitSlot(args);
|
|
132
132
|
const renderPriority = typeof userArgs[0] === 'number' ? userArgs[0] : 0;
|
|
133
133
|
const store = useStore();
|
|
134
|
-
const callbackRef =
|
|
134
|
+
const callbackRef = useMemo(
|
|
135
|
+
() => ({ current: callback }),
|
|
136
|
+
[],
|
|
137
|
+
subSlot(slot, 'useFrame:callback'),
|
|
138
|
+
);
|
|
135
139
|
|
|
136
140
|
useLayoutEffect(
|
|
137
141
|
() => {
|
package/src/core/props.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* properties only; renderer-reserved callbacks never become object fields.
|
|
13
13
|
*/
|
|
14
14
|
import * as THREE from 'three';
|
|
15
|
+
import { isTrustedThreeConstructor } from './constructors.js';
|
|
15
16
|
|
|
16
17
|
export type ThreePropBag = Readonly<Record<string, unknown>>;
|
|
17
18
|
|
|
@@ -53,11 +54,6 @@ export const THREE_RESERVED_PROPS = Object.freeze([
|
|
|
53
54
|
const EVENT_PROP = /^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/;
|
|
54
55
|
const COLOR_MAPS = new Set(['map', 'emissiveMap', 'sheenColorMap', 'specularColorMap', 'envMap']);
|
|
55
56
|
const MEMOIZED_PROTOTYPES = new Map<Function, any>();
|
|
56
|
-
const THREE_CONSTRUCTORS = new Set<Function>(
|
|
57
|
-
Object.values(THREE as unknown as Record<string, unknown>).filter(
|
|
58
|
-
(value) => typeof value === 'function',
|
|
59
|
-
) as Function[],
|
|
60
|
-
);
|
|
61
57
|
const UNKNOWN_SHAPE = Symbol('unknown Three property shape');
|
|
62
58
|
|
|
63
59
|
function isObject(value: unknown): value is Record<string, any> {
|
|
@@ -373,7 +369,7 @@ function resolveShadowProperty(state: ShadowState, key: string): ResolvedShadowP
|
|
|
373
369
|
|
|
374
370
|
function isKnownThreeValue(value: unknown): boolean {
|
|
375
371
|
const Constructor = (value as { constructor?: unknown } | null)?.constructor;
|
|
376
|
-
return
|
|
372
|
+
return isTrustedThreeConstructor(Constructor);
|
|
377
373
|
}
|
|
378
374
|
|
|
379
375
|
function isCanonicalThreeMethod(value: unknown, key: string, method: unknown): boolean {
|
package/src/core/store.ts
CHANGED
|
@@ -6,13 +6,8 @@
|
|
|
6
6
|
* components. Zustand remains the framework-neutral storage primitive.
|
|
7
7
|
*/
|
|
8
8
|
import * as THREE from 'three';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
useContext,
|
|
12
|
-
useRef,
|
|
13
|
-
useSyncExternalStore,
|
|
14
|
-
withSlot,
|
|
15
|
-
} from 'octane/universal';
|
|
9
|
+
import { useContext, useRef, useSyncExternalStore, withSlot } from 'octane/universal';
|
|
10
|
+
import { createContext } from 'octane/universal/native';
|
|
16
11
|
import { createStore as createVanillaStore, type StoreApi } from 'zustand/vanilla';
|
|
17
12
|
import type {
|
|
18
13
|
DomEvent,
|
|
@@ -181,7 +176,7 @@ const ROOT_OBJECT_STORES = new WeakMap<object, RootStore>();
|
|
|
181
176
|
interface PointerCaptureIdentity {
|
|
182
177
|
eventObject: THREE.Object3D;
|
|
183
178
|
intersection: Intersection;
|
|
184
|
-
pointerIds: Set<number
|
|
179
|
+
pointerIds: Set<number> | null;
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
const POINTER_CAPTURE_IDENTITIES = new WeakMap<object, PointerCaptureIdentity>();
|
|
@@ -196,7 +191,7 @@ const POINTER_CAPTURE_TARGET_IDENTITIES = new WeakMap<
|
|
|
196
191
|
|
|
197
192
|
/** Create the mutable identity cell used by an event's pointer-capture facade. */
|
|
198
193
|
export function createPointerCaptureIdentity(intersection: Intersection): PointerCaptureIdentity {
|
|
199
|
-
return { eventObject: intersection.eventObject, intersection, pointerIds:
|
|
194
|
+
return { eventObject: intersection.eventObject, intersection, pointerIds: null };
|
|
200
195
|
}
|
|
201
196
|
|
|
202
197
|
/** Associate a public capture facade with its renderer-owned identity cell. */
|
|
@@ -230,7 +225,7 @@ function pointerCaptureIdentityObjects(identity: PointerCaptureIdentity): Set<TH
|
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
function indexPointerCaptureIdentity(identity: PointerCaptureIdentity): void {
|
|
233
|
-
if (identity.pointerIds.size === 0) return;
|
|
228
|
+
if (identity.pointerIds === null || identity.pointerIds.size === 0) return;
|
|
234
229
|
for (const object of pointerCaptureIdentityObjects(identity)) {
|
|
235
230
|
const identities = ACTIVE_POINTER_CAPTURE_IDENTITIES.get(object);
|
|
236
231
|
if (identities === undefined) {
|
|
@@ -256,14 +251,21 @@ function activatePointerCaptureIdentity(
|
|
|
256
251
|
pointerId: number,
|
|
257
252
|
): void {
|
|
258
253
|
POINTER_CAPTURE_TARGET_IDENTITIES.set(capture, identity);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
254
|
+
const pointerIds = (identity.pointerIds ??= new Set());
|
|
255
|
+
if (pointerIds.has(pointerId)) return;
|
|
256
|
+
pointerIds.add(pointerId);
|
|
257
|
+
if (pointerIds.size === 1) indexPointerCaptureIdentity(identity);
|
|
262
258
|
}
|
|
263
259
|
|
|
264
260
|
function deactivatePointerCaptureIdentity(capture: PointerCaptureTarget, pointerId: number): void {
|
|
265
261
|
const identity = POINTER_CAPTURE_TARGET_IDENTITIES.get(capture);
|
|
266
|
-
if (
|
|
262
|
+
if (
|
|
263
|
+
identity === undefined ||
|
|
264
|
+
identity.pointerIds === null ||
|
|
265
|
+
!identity.pointerIds.delete(pointerId)
|
|
266
|
+
) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
267
269
|
if (identity.pointerIds.size === 0) unindexPointerCaptureIdentity(identity);
|
|
268
270
|
}
|
|
269
271
|
|
|
@@ -276,7 +278,7 @@ function transferPointerCaptureIdentity(
|
|
|
276
278
|
const eventObject = identity.eventObject === previous ? next : identity.eventObject;
|
|
277
279
|
if (intersection === identity.intersection && eventObject === identity.eventObject) return;
|
|
278
280
|
|
|
279
|
-
const active = identity.pointerIds.size > 0;
|
|
281
|
+
const active = identity.pointerIds !== null && identity.pointerIds.size > 0;
|
|
280
282
|
if (active) unindexPointerCaptureIdentity(identity);
|
|
281
283
|
identity.eventObject = eventObject;
|
|
282
284
|
identity.intersection = intersection;
|
|
@@ -548,6 +550,7 @@ export function createPortalStore(initialState: RootState): RootStore {
|
|
|
548
550
|
|
|
549
551
|
/** Walk a portal chain to the one root that owns scheduling and native events. */
|
|
550
552
|
export function getInitialRootStore(store: RootStore): RootStore {
|
|
553
|
+
if (store.getState().previousRoot === undefined) return store;
|
|
551
554
|
const seen = new Set<RootStore>();
|
|
552
555
|
let current = store;
|
|
553
556
|
while (current.getState().previousRoot !== undefined) {
|
|
@@ -705,10 +708,12 @@ export function createRootStore(invalidate: Invalidate, advance: Advance): RootS
|
|
|
705
708
|
subscribe(ref, priority, subscriptionStore) {
|
|
706
709
|
const internal = get().internal;
|
|
707
710
|
if (priority > 0) internal.priority++;
|
|
708
|
-
internal.subscribers
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
711
|
+
const previous = internal.subscribers;
|
|
712
|
+
const subscribers = [...previous, { ref, priority, store: subscriptionStore }];
|
|
713
|
+
if (previous.length !== 0 && !(previous[previous.length - 1].priority <= priority)) {
|
|
714
|
+
subscribers.sort((left, right) => left.priority - right.priority);
|
|
715
|
+
}
|
|
716
|
+
internal.subscribers = subscribers;
|
|
712
717
|
return () => {
|
|
713
718
|
const current = get().internal;
|
|
714
719
|
if (priority > 0) current.priority--;
|
package/src/renderer.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export * from 'octane/universal';
|
|
9
9
|
export * from './core/index.js';
|
|
10
|
+
export { registerThreeIntrinsic } from './core/catalogue.js';
|
|
10
11
|
// Resolve the deliberate name overlap with the capability-gated universal
|
|
11
12
|
// primitive in favor of Three's R3F-shaped state-enclave adapter.
|
|
12
13
|
export { createPortal } from './core/portal.js';
|
package/src/scheduling.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as Octane from 'octane';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
flushUniversalAct,
|
|
4
|
+
flushUniversalSync,
|
|
5
|
+
getUniversalHostFlusher,
|
|
6
|
+
type UniversalSyncFlusher,
|
|
7
|
+
} from 'octane/universal';
|
|
3
8
|
|
|
4
9
|
export type Act = typeof import('octane').act;
|
|
5
10
|
type FlushSync = typeof import('octane').flushSync;
|
|
@@ -66,17 +71,18 @@ function runClientAct<T>(callback: () => T | Promise<T>, clientAct: Act): Promis
|
|
|
66
71
|
|
|
67
72
|
/** Flushes both the DOM scheduler and mounted universal Three roots. */
|
|
68
73
|
export const flushSync: FlushSync = (callback) => {
|
|
69
|
-
|
|
70
|
-
return flushUniversalSync(callback, clientFlushSync);
|
|
74
|
+
return flushUniversalSync(callback, getUniversalHostFlusher());
|
|
71
75
|
};
|
|
72
76
|
|
|
73
77
|
/** R3F-compatible test helper backed by Octane's client scheduler when available. */
|
|
74
78
|
export const act: Act = (callback) => {
|
|
79
|
+
// The server entry has flushSync but deliberately does not export act. Keep
|
|
80
|
+
// this optional namespace lookup inside the cold test-only export so bundles
|
|
81
|
+
// using only flushSync can still remove the rest of Octane's public surface.
|
|
75
82
|
const clientAct = Reflect.get(Octane, 'act') as Act | undefined;
|
|
76
|
-
const clientFlushSync = Reflect.get(Octane, 'flushSync') as FlushSync | undefined;
|
|
77
83
|
if (typeof clientAct === 'function') return runClientAct(callback, clientAct);
|
|
78
84
|
try {
|
|
79
|
-
return Promise.resolve(runActCallback(callback,
|
|
85
|
+
return Promise.resolve(runActCallback(callback, getUniversalHostFlusher()));
|
|
80
86
|
} catch (error) {
|
|
81
87
|
return Promise.reject(error);
|
|
82
88
|
}
|
package/src/web/Canvas.tsrx
CHANGED
|
@@ -2,6 +2,7 @@ import { useInsertionEffect, useLayoutEffect, useRef, useState } from 'octane';
|
|
|
2
2
|
import type { OctaneNode } from 'octane';
|
|
3
3
|
import { createUniversalHostBoundary } from 'octane/universal';
|
|
4
4
|
import type { RendererRegion } from 'octane/universal';
|
|
5
|
+
import { registerThreeNamespace } from '../core/catalogue.js';
|
|
5
6
|
import type { ComputeFunction, DomEvent } from '../core/events.js';
|
|
6
7
|
import { createRoot, createThreeBoundaryMount } from '../core/root.js';
|
|
7
8
|
import type { RenderProps, ThreeBoundaryMount, ThreeRoot } from '../core/root.js';
|
|
@@ -208,6 +209,7 @@ export function Canvas({
|
|
|
208
209
|
let cancelled = false;
|
|
209
210
|
let root = rootRef.current;
|
|
210
211
|
if (root === null) {
|
|
212
|
+
registerThreeNamespace();
|
|
211
213
|
root = createRoot(canvas);
|
|
212
214
|
rootRef.current = root;
|
|
213
215
|
}
|
package/src/web/dom-region.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as Octane from 'octane';
|
|
2
2
|
import type { ComponentBody, Root } from 'octane';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isRendererRegion,
|
|
5
|
+
registerUniversalHostBridge,
|
|
6
|
+
type RendererRegion,
|
|
7
|
+
} from 'octane/universal';
|
|
4
8
|
|
|
5
9
|
export type DOMRegionTarget = HTMLElement | { current: HTMLElement | null };
|
|
6
10
|
|
|
@@ -28,6 +32,7 @@ export interface DOMRegionBinding {
|
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
export function createDOMRegionBinding(): DOMRegionBinding {
|
|
35
|
+
registerUniversalHostBridge();
|
|
31
36
|
const createRoot = Reflect.get(Octane, 'createRoot') as
|
|
32
37
|
typeof import('octane').createRoot | undefined;
|
|
33
38
|
if (typeof createRoot !== 'function' || typeof document === 'undefined') {
|