angular-three 2.0.0-beta.0 → 2.0.0-beta.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 +4 -147
- package/esm2022/angular-three.mjs +1 -1
- package/esm2022/index.mjs +10 -7
- package/esm2022/lib/before-render.mjs +13 -0
- package/esm2022/lib/canvas.mjs +129 -161
- package/esm2022/lib/directives/args.mjs +13 -11
- package/esm2022/lib/directives/common.mjs +29 -27
- package/esm2022/lib/directives/key.mjs +29 -0
- package/esm2022/lib/directives/parent.mjs +13 -11
- package/esm2022/lib/directives/repeat.mjs +5 -6
- package/esm2022/lib/dom/events.mjs +6 -1
- package/esm2022/lib/events.mjs +75 -58
- package/esm2022/lib/instance.mjs +65 -0
- package/esm2022/lib/loader.mjs +41 -44
- package/esm2022/lib/loop.mjs +6 -3
- package/esm2022/lib/portal.mjs +91 -102
- package/esm2022/lib/ref.mjs +48 -0
- package/esm2022/lib/renderer/catalogue.mjs +7 -0
- package/esm2022/lib/renderer/constants.mjs +21 -0
- package/esm2022/lib/renderer/index.mjs +417 -0
- package/esm2022/lib/renderer/store.mjs +66 -29
- package/esm2022/lib/renderer/utils.mjs +31 -44
- package/esm2022/lib/roots.mjs +249 -0
- package/esm2022/lib/routed-scene.mjs +6 -7
- package/esm2022/lib/store.mjs +207 -0
- package/esm2022/lib/three-types.mjs +1 -1
- package/esm2022/lib/types.mjs +1 -1
- package/esm2022/lib/utils/apply-props.mjs +29 -13
- package/esm2022/lib/utils/assert-injection-context.mjs +14 -0
- package/esm2022/lib/utils/attach.mjs +2 -2
- package/esm2022/lib/utils/create-injection-token.mjs +47 -0
- package/esm2022/lib/utils/is.mjs +1 -1
- package/esm2022/lib/utils/make.mjs +1 -1
- package/esm2022/lib/utils/safe-detect-changes.mjs +15 -13
- package/esm2022/lib/utils/signal-store.mjs +91 -0
- package/esm2022/lib/utils/update.mjs +1 -1
- package/fesm2022/angular-three.mjs +1902 -1669
- package/fesm2022/angular-three.mjs.map +1 -1
- package/index.d.ts +10 -6
- package/lib/{di/before-render.d.ts → before-render.d.ts} +3 -3
- package/lib/canvas.d.ts +81 -11
- package/lib/directives/args.d.ts +2 -2
- package/lib/directives/common.d.ts +5 -1
- package/lib/directives/key.d.ts +10 -0
- package/lib/directives/parent.d.ts +5 -5
- package/lib/dom/events.d.ts +3 -2
- package/lib/events.d.ts +78 -2
- package/lib/instance.d.ts +36 -0
- package/lib/loader.d.ts +14 -3
- package/lib/loop.d.ts +64 -6
- package/lib/portal.d.ts +20 -12
- package/lib/ref.d.ts +8 -0
- package/lib/renderer/catalogue.d.ts +9 -0
- package/lib/renderer/constants.d.ts +20 -0
- package/lib/renderer/index.d.ts +5 -0
- package/lib/renderer/store.d.ts +19 -15
- package/lib/renderer/utils.d.ts +28 -18
- package/lib/roots.d.ts +11 -0
- package/lib/routed-scene.d.ts +1 -1
- package/lib/store.d.ts +143 -0
- package/lib/three-types.d.ts +5 -5
- package/lib/types.d.ts +1 -307
- package/lib/utils/apply-props.d.ts +4 -2
- package/lib/utils/assert-injection-context.d.ts +2 -0
- package/lib/utils/attach.d.ts +4 -2
- package/lib/utils/create-injection-token.d.ts +27 -0
- package/lib/utils/is.d.ts +4 -3
- package/lib/utils/make.d.ts +12 -1
- package/lib/utils/safe-detect-changes.d.ts +2 -2
- package/lib/utils/signal-store.d.ts +17 -0
- package/lib/utils/update.d.ts +1 -1
- package/metadata.json +1 -1
- package/package.json +4 -4
- package/plugin/generators.json +47 -17
- package/plugin/package.json +1 -4
- package/plugin/src/generators/init/compat.js +2 -2
- package/plugin/src/generators/init/compat.js.map +1 -1
- package/plugin/src/generators/init/generator.d.ts +2 -0
- package/plugin/src/generators/init/{init.js → generator.js} +4 -12
- package/plugin/src/generators/init/generator.js.map +1 -0
- package/plugin/src/generators/init/schema.json +4 -4
- package/plugin/src/generators/init-cannon/compat.d.ts +2 -0
- package/plugin/src/generators/init-cannon/compat.js +6 -0
- package/plugin/src/generators/init-cannon/compat.js.map +1 -0
- package/plugin/src/generators/init-cannon/generator.d.ts +2 -0
- package/plugin/src/generators/init-cannon/generator.js +22 -0
- package/plugin/src/generators/init-cannon/generator.js.map +1 -0
- package/plugin/src/generators/init-cannon/schema.json +6 -0
- package/plugin/src/generators/init-postprocessing/compat.d.ts +2 -0
- package/plugin/src/generators/init-postprocessing/compat.js +6 -0
- package/plugin/src/generators/init-postprocessing/compat.js.map +1 -0
- package/plugin/src/generators/init-postprocessing/generator.d.ts +2 -0
- package/plugin/src/generators/init-postprocessing/generator.js +20 -0
- package/plugin/src/generators/init-postprocessing/generator.js.map +1 -0
- package/plugin/src/generators/init-postprocessing/schema.json +6 -0
- package/plugin/src/generators/init-soba/compat.d.ts +2 -0
- package/plugin/src/generators/init-soba/compat.js +6 -0
- package/plugin/src/generators/init-soba/compat.js.map +1 -0
- package/plugin/src/generators/init-soba/generator.d.ts +2 -0
- package/plugin/src/generators/init-soba/generator.js +24 -0
- package/plugin/src/generators/init-soba/generator.js.map +1 -0
- package/plugin/src/generators/init-soba/schema.json +6 -0
- package/plugin/src/generators/versions.d.ts +12 -0
- package/plugin/src/generators/versions.js +16 -0
- package/plugin/src/generators/versions.js.map +1 -0
- package/plugin/src/index.d.ts +3 -1
- package/plugin/src/index.js +7 -3
- package/plugin/src/index.js.map +1 -1
- package/web-types.json +1 -1
- package/esm2022/lib/di/before-render.mjs +0 -12
- package/esm2022/lib/di/catalogue.mjs +0 -7
- package/esm2022/lib/di/ref.mjs +0 -44
- package/esm2022/lib/renderer/di.mjs +0 -3
- package/esm2022/lib/renderer/enums.mjs +0 -2
- package/esm2022/lib/renderer/provider.mjs +0 -18
- package/esm2022/lib/renderer/renderer.mjs +0 -362
- package/esm2022/lib/stores/signal.store.mjs +0 -60
- package/esm2022/lib/stores/store.mjs +0 -425
- package/esm2022/lib/utils/instance.mjs +0 -60
- package/lib/di/catalogue.d.ts +0 -3
- package/lib/di/ref.d.ts +0 -6
- package/lib/renderer/di.d.ts +0 -2
- package/lib/renderer/enums.d.ts +0 -26
- package/lib/renderer/provider.d.ts +0 -8
- package/lib/renderer/renderer.d.ts +0 -49
- package/lib/stores/signal.store.d.ts +0 -19
- package/lib/stores/store.d.ts +0 -13
- package/lib/utils/instance.d.ts +0 -4
- package/plugin/src/generators/init/init.d.ts +0 -5
- package/plugin/src/generators/init/init.js.map +0 -1
|
@@ -1,12 +1,102 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import { provideNgxResizeOptions, NgxResize } from 'ngx-resize';
|
|
4
|
-
import * as THREE from 'three';
|
|
2
|
+
import { untracked, computed, signal, ElementRef, inject, Injector, assertInInjectionContext, runInInjectionContext, DestroyRef, effect, InjectionToken, ChangeDetectorRef, Optional, SkipSelf, ViewContainerRef, NgZone, TemplateRef, Directive, Input, EventEmitter, getDebugNode, RendererFactory2, Injectable, makeEnvironmentProviders, provideZoneChangeDetection, EnvironmentInjector, createEnvironmentInjector, Component, ChangeDetectionStrategy, Output, ViewChild, ContentChild } from '@angular/core';
|
|
5
3
|
import { DOCUMENT, NgForOf, NgIf } from '@angular/common';
|
|
4
|
+
import { Subject, filter } from 'rxjs';
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { provideNgxResizeOptions, NgxResize } from 'ngx-resize';
|
|
6
7
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
8
|
import * as i1 from '@angular/router';
|
|
8
9
|
import { ActivationEnd, RouterOutlet } from '@angular/router';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
const STORE_COMPUTED_KEY = '__ngt_signal_store_computed__';
|
|
12
|
+
const setter = (_source) => (state) => {
|
|
13
|
+
const updater = (previous) => {
|
|
14
|
+
const partial = typeof state === 'function' ? state(previous) : state;
|
|
15
|
+
Object.keys(partial).forEach((key) => {
|
|
16
|
+
const typedKey = key;
|
|
17
|
+
if (partial[typedKey] === undefined && previous[typedKey] != null) {
|
|
18
|
+
partial[typedKey] = previous[typedKey];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return partial;
|
|
22
|
+
};
|
|
23
|
+
untracked(() => {
|
|
24
|
+
_source.update((previous) => ({ ...previous, ...updater(previous) }));
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const patcher = (_source) => (state) => {
|
|
28
|
+
const updater = (previous) => {
|
|
29
|
+
Object.keys(state).forEach((key) => {
|
|
30
|
+
const typedKey = key;
|
|
31
|
+
if (state[typedKey] === undefined && previous[typedKey] != null) {
|
|
32
|
+
state[typedKey] = previous[typedKey];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return state;
|
|
36
|
+
};
|
|
37
|
+
untracked(() => {
|
|
38
|
+
_source.update((previous) => ({ ...updater(previous), ...previous }));
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const getter = (_source) => (...keys) => {
|
|
42
|
+
const root = untracked(_source);
|
|
43
|
+
if (keys.length === 0)
|
|
44
|
+
return root;
|
|
45
|
+
return keys.reduce((value, key) => value[key], root);
|
|
46
|
+
};
|
|
47
|
+
const selector = (_state, computedCache) => (...keysAndOptions) => {
|
|
48
|
+
if (keysAndOptions.length === 0)
|
|
49
|
+
return _state;
|
|
50
|
+
if (keysAndOptions.length === 1 && typeof keysAndOptions[0] === 'object') {
|
|
51
|
+
const cachedKey = STORE_COMPUTED_KEY.concat(JSON.stringify(keysAndOptions[0]));
|
|
52
|
+
if (!computedCache.has(cachedKey)) {
|
|
53
|
+
computedCache.set(cachedKey, computed(_state, keysAndOptions));
|
|
54
|
+
}
|
|
55
|
+
return computedCache.get(cachedKey);
|
|
56
|
+
}
|
|
57
|
+
const [keys, options] = parseStoreOptions(keysAndOptions);
|
|
58
|
+
const joinedKeys = keys.join('-');
|
|
59
|
+
const cachedKeys = joinedKeys.concat(options ? JSON.stringify(options) : '');
|
|
60
|
+
if (!computedCache.has(cachedKeys)) {
|
|
61
|
+
computedCache.set(cachedKeys, computed(() => keys.reduce((value, key) => value[key], _state()), options));
|
|
62
|
+
}
|
|
63
|
+
return computedCache.get(cachedKeys);
|
|
64
|
+
};
|
|
65
|
+
function signalStore(initialState = {}, options) {
|
|
66
|
+
let source;
|
|
67
|
+
let set;
|
|
68
|
+
let get;
|
|
69
|
+
let patch;
|
|
70
|
+
if (typeof initialState === 'function') {
|
|
71
|
+
source = signal({}, options);
|
|
72
|
+
get = getter(source);
|
|
73
|
+
set = setter(source);
|
|
74
|
+
patch = patcher(source);
|
|
75
|
+
source.set(initialState({ set, get, patch }));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
source = signal(initialState, options);
|
|
79
|
+
get = getter(source);
|
|
80
|
+
set = setter(source);
|
|
81
|
+
patch = patcher(source);
|
|
82
|
+
}
|
|
83
|
+
const state = source.asReadonly();
|
|
84
|
+
const computedCache = new Map();
|
|
85
|
+
const store = { select: selector(state, computedCache), get, set, patch, state };
|
|
86
|
+
// NOTE: internal _snapshot to debug current state
|
|
87
|
+
Object.defineProperty(store, '_snapshot', {
|
|
88
|
+
get: state,
|
|
89
|
+
configurable: false,
|
|
90
|
+
enumerable: false,
|
|
91
|
+
});
|
|
92
|
+
return store;
|
|
93
|
+
}
|
|
94
|
+
function parseStoreOptions(keysAndOptions) {
|
|
95
|
+
if (typeof keysAndOptions.at(-1) === 'object') {
|
|
96
|
+
return [keysAndOptions.slice(0, -1), keysAndOptions.at(-1)];
|
|
97
|
+
}
|
|
98
|
+
return [keysAndOptions];
|
|
99
|
+
}
|
|
10
100
|
|
|
11
101
|
const is = {
|
|
12
102
|
obj: (a) => a === Object(a) && !Array.isArray(a) && typeof a !== 'function',
|
|
@@ -113,23 +203,27 @@ function prepare(object, localState) {
|
|
|
113
203
|
handlers: {},
|
|
114
204
|
objects,
|
|
115
205
|
nonObjects,
|
|
206
|
+
nativeProps: signalStore(),
|
|
116
207
|
add: (object, type) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
208
|
+
untracked(() => {
|
|
209
|
+
const current = instance.__ngt__[type]();
|
|
210
|
+
const foundIndex = current.indexOf((obj) => obj === object);
|
|
211
|
+
if (foundIndex > -1) {
|
|
212
|
+
// if we add an object with the same reference, then we switch it out
|
|
213
|
+
current.splice(foundIndex, 1, object);
|
|
214
|
+
instance.__ngt__[type].set(current);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
instance.__ngt__[type].update((prev) => [...prev, object]);
|
|
218
|
+
}
|
|
219
|
+
notifyAncestors(instance.__ngt__.parent());
|
|
220
|
+
});
|
|
129
221
|
},
|
|
130
222
|
remove: (object, type) => {
|
|
131
|
-
|
|
132
|
-
|
|
223
|
+
untracked(() => {
|
|
224
|
+
instance.__ngt__[type].update((prev) => prev.filter((o) => o !== object));
|
|
225
|
+
notifyAncestors(instance.__ngt__.parent());
|
|
226
|
+
});
|
|
133
227
|
},
|
|
134
228
|
...rest,
|
|
135
229
|
};
|
|
@@ -144,7 +238,142 @@ function notifyAncestors(instance) {
|
|
|
144
238
|
localState.objects.update((prev) => prev);
|
|
145
239
|
if (localState.nonObjects)
|
|
146
240
|
localState.nonObjects.update((prev) => prev);
|
|
147
|
-
notifyAncestors(
|
|
241
|
+
notifyAncestors(localState.parent());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// This function prepares a set of changes to be applied to the instance
|
|
245
|
+
function diffProps(instance, props) {
|
|
246
|
+
const propsEntries = Object.entries(props);
|
|
247
|
+
const changes = [];
|
|
248
|
+
for (const [propKey, propValue] of propsEntries) {
|
|
249
|
+
let key = propKey;
|
|
250
|
+
if (is.colorSpaceExist(instance)) {
|
|
251
|
+
if (propKey === 'encoding') {
|
|
252
|
+
key = 'colorSpace';
|
|
253
|
+
}
|
|
254
|
+
else if (propKey === 'outputEncoding') {
|
|
255
|
+
key = 'outputColorSpace';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (is.equ(propValue, instance[key]))
|
|
259
|
+
continue;
|
|
260
|
+
changes.push([propKey, propValue]);
|
|
261
|
+
}
|
|
262
|
+
return changes;
|
|
263
|
+
}
|
|
264
|
+
// This function applies a set of changes to the instance
|
|
265
|
+
function applyProps(instance, props) {
|
|
266
|
+
// if props is empty
|
|
267
|
+
if (!Object.keys(props).length)
|
|
268
|
+
return instance;
|
|
269
|
+
// Filter equals, events and reserved props
|
|
270
|
+
// filter equals, events , and reserved props
|
|
271
|
+
const localState = getLocalState(instance);
|
|
272
|
+
const rootState = localState.store?.get();
|
|
273
|
+
const changes = diffProps(instance, props);
|
|
274
|
+
for (let i = 0; i < changes.length; i++) {
|
|
275
|
+
let [key, value] = changes[i];
|
|
276
|
+
// Alias (output)encoding => (output)colorSpace (since r152)
|
|
277
|
+
// https://github.com/pmndrs/react-three-fiber/pull/2829
|
|
278
|
+
if (is.colorSpaceExist(instance)) {
|
|
279
|
+
const sRGBEncoding = 3001;
|
|
280
|
+
const SRGBColorSpace = 'srgb';
|
|
281
|
+
const LinearSRGBColorSpace = 'srgb-linear';
|
|
282
|
+
if (key === 'encoding') {
|
|
283
|
+
key = 'colorSpace';
|
|
284
|
+
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
285
|
+
}
|
|
286
|
+
else if (key === 'outputEncoding') {
|
|
287
|
+
key = 'outputColorSpace';
|
|
288
|
+
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const currentInstance = instance;
|
|
292
|
+
const targetProp = currentInstance[key];
|
|
293
|
+
// special treatmen for objects with support for set/copy, and layers
|
|
294
|
+
if (targetProp && targetProp['set'] && (targetProp['copy'] || targetProp instanceof THREE.Layers)) {
|
|
295
|
+
const isColor = targetProp instanceof THREE.Color;
|
|
296
|
+
// if value is an array
|
|
297
|
+
if (Array.isArray(value)) {
|
|
298
|
+
if (targetProp['fromArray'])
|
|
299
|
+
targetProp['fromArray'](value);
|
|
300
|
+
else
|
|
301
|
+
targetProp['set'](...value);
|
|
302
|
+
}
|
|
303
|
+
// test again target.copy
|
|
304
|
+
else if (targetProp['copy'] &&
|
|
305
|
+
value &&
|
|
306
|
+
value.constructor &&
|
|
307
|
+
targetProp.constructor.name === value.constructor.name) {
|
|
308
|
+
targetProp['copy'](value);
|
|
309
|
+
if (!THREE.ColorManagement && !rootState.linear && isColor)
|
|
310
|
+
targetProp['convertSRGBToLinear']();
|
|
311
|
+
}
|
|
312
|
+
// if nothing else fits, just set the single value, ignore undefined
|
|
313
|
+
else if (value !== undefined) {
|
|
314
|
+
const isColor = targetProp instanceof THREE.Color;
|
|
315
|
+
// allow setting array scalars
|
|
316
|
+
if (!isColor && targetProp['setScalar'])
|
|
317
|
+
targetProp['setScalar'](value);
|
|
318
|
+
// layers have no copy function, copy the mask
|
|
319
|
+
else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers)
|
|
320
|
+
targetProp.mask = value.mask;
|
|
321
|
+
// otherwise just set ...
|
|
322
|
+
else
|
|
323
|
+
targetProp['set'](value);
|
|
324
|
+
// auto-convert srgb
|
|
325
|
+
if (!THREE.ColorManagement && !rootState?.linear && isColor)
|
|
326
|
+
targetProp.convertSRGBToLinear();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// else just overwrite the value
|
|
330
|
+
else {
|
|
331
|
+
currentInstance[key] = value;
|
|
332
|
+
// auto-convert srgb textures
|
|
333
|
+
if (currentInstance[key] instanceof THREE.Texture &&
|
|
334
|
+
currentInstance[key].format === THREE.RGBAFormat &&
|
|
335
|
+
currentInstance[key].type === THREE.UnsignedByteType) {
|
|
336
|
+
const texture = currentInstance[key];
|
|
337
|
+
if (rootState?.gl) {
|
|
338
|
+
if (is.colorSpaceExist(texture) && is.colorSpaceExist(rootState.gl))
|
|
339
|
+
texture.colorSpace = rootState.gl.outputColorSpace;
|
|
340
|
+
else
|
|
341
|
+
texture.encoding = rootState.gl.outputEncoding;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
checkUpdate(currentInstance[key]);
|
|
346
|
+
checkUpdate(targetProp);
|
|
347
|
+
invalidateInstance(instance);
|
|
348
|
+
}
|
|
349
|
+
const instanceHandlers = localState.eventCount;
|
|
350
|
+
const parent = localState.parent ? untracked(localState.parent) : null;
|
|
351
|
+
if (parent && rootState.internal && instance['raycast'] && instanceHandlers !== localState.eventCount) {
|
|
352
|
+
// Pre-emptively remove the instance from the interaction manager
|
|
353
|
+
const index = rootState.internal.interaction.indexOf(instance);
|
|
354
|
+
if (index > -1)
|
|
355
|
+
rootState.internal.interaction.splice(index, 1);
|
|
356
|
+
// Add the instance to the interaction manager only when it has handlers
|
|
357
|
+
if (localState.eventCount)
|
|
358
|
+
rootState.internal.interaction.push(instance);
|
|
359
|
+
}
|
|
360
|
+
if (parent && localState.afterUpdate && localState.afterUpdate.observed && changes.length) {
|
|
361
|
+
localState.afterUpdate.emit(instance);
|
|
362
|
+
}
|
|
363
|
+
return instance;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function assertInjectionContext(fn, injector) {
|
|
367
|
+
try {
|
|
368
|
+
if (!injector) {
|
|
369
|
+
return inject(Injector);
|
|
370
|
+
}
|
|
371
|
+
return injector;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
!injector && assertInInjectionContext(fn);
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
148
377
|
}
|
|
149
378
|
|
|
150
379
|
const idCache = {};
|
|
@@ -196,1211 +425,1267 @@ function makeObjectGraph(object) {
|
|
|
196
425
|
return data;
|
|
197
426
|
}
|
|
198
427
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
428
|
+
const shallowLoose = { objects: 'shallow', strict: false };
|
|
429
|
+
const roots = new Map();
|
|
430
|
+
function injectCanvasRootInitializer(injector) {
|
|
431
|
+
injector = assertInjectionContext(injectCanvasRootInitializer, injector);
|
|
432
|
+
return runInInjectionContext(injector, () => {
|
|
433
|
+
const injectedStore = injectNgtStore();
|
|
434
|
+
const loop = injectNgtLoop();
|
|
435
|
+
const destroyRef = inject(DestroyRef);
|
|
436
|
+
return (canvas) => {
|
|
437
|
+
const exist = roots.has(canvas);
|
|
438
|
+
let store = roots.get(canvas);
|
|
439
|
+
if (store) {
|
|
440
|
+
console.warn('[NGT] Same canvas root is being created twice');
|
|
441
|
+
}
|
|
442
|
+
store ||= injectedStore;
|
|
443
|
+
if (!store) {
|
|
444
|
+
throw new Error('[NGT] No store initialized');
|
|
445
|
+
}
|
|
446
|
+
if (!exist) {
|
|
447
|
+
roots.set(canvas, store);
|
|
448
|
+
}
|
|
449
|
+
let isConfigured = false;
|
|
450
|
+
let invalidateRef;
|
|
451
|
+
destroyRef.onDestroy(() => invalidateRef?.destroy());
|
|
452
|
+
return {
|
|
453
|
+
isConfigured,
|
|
454
|
+
destroy: (timeout = 500) => {
|
|
455
|
+
const root = roots.get(canvas);
|
|
456
|
+
if (root) {
|
|
457
|
+
root.set((state) => ({ internal: { ...state.internal, active: false } }));
|
|
458
|
+
setTimeout(() => {
|
|
459
|
+
try {
|
|
460
|
+
const state = root.get();
|
|
461
|
+
state.events.disconnect?.();
|
|
462
|
+
state.gl?.renderLists?.dispose?.();
|
|
463
|
+
state.gl?.forceContextLoss?.();
|
|
464
|
+
if (state.gl?.xr)
|
|
465
|
+
state.xr.disconnect();
|
|
466
|
+
dispose(state);
|
|
467
|
+
roots.delete(canvas);
|
|
468
|
+
}
|
|
469
|
+
catch (e) {
|
|
470
|
+
console.error('[NGT] Unexpected error while destroying Canvas Root', e);
|
|
471
|
+
}
|
|
472
|
+
}, timeout);
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
configure: (inputs) => {
|
|
476
|
+
const { gl: glOptions, size: sizeOptions, camera: cameraOptions, raycaster: raycasterOptions, scene: sceneOptions, events, orthographic, lookAt, shadows, linear, legacy, flat, dpr, frameloop, performance, } = inputs;
|
|
477
|
+
const state = store.get();
|
|
478
|
+
const stateToUpdate = {};
|
|
479
|
+
// setup renderer
|
|
480
|
+
let gl = state.gl;
|
|
481
|
+
if (!state.gl)
|
|
482
|
+
stateToUpdate.gl = gl = makeDefaultRenderer(glOptions, canvas);
|
|
483
|
+
// setup raycaster
|
|
484
|
+
let raycaster = state.raycaster;
|
|
485
|
+
if (!raycaster)
|
|
486
|
+
stateToUpdate.raycaster = raycaster = new THREE.Raycaster();
|
|
487
|
+
// set raycaster options
|
|
488
|
+
const { params, ...options } = raycasterOptions || {};
|
|
489
|
+
if (!is.equ(options, raycaster, shallowLoose))
|
|
490
|
+
applyProps(raycaster, { ...options });
|
|
491
|
+
if (!is.equ(params, raycaster.params, shallowLoose)) {
|
|
492
|
+
applyProps(raycaster, { params: { ...raycaster.params, ...(params || {}) } });
|
|
493
|
+
}
|
|
494
|
+
// create default camera
|
|
495
|
+
if (!state.camera) {
|
|
496
|
+
const isCamera = is.camera(cameraOptions);
|
|
497
|
+
let camera = isCamera ? cameraOptions : makeDefaultCamera(orthographic || false, state.size);
|
|
498
|
+
if (!isCamera) {
|
|
499
|
+
if (cameraOptions)
|
|
500
|
+
applyProps(camera, cameraOptions);
|
|
501
|
+
// set position.z
|
|
502
|
+
if (!cameraOptions?.position)
|
|
503
|
+
camera.position.z = 5;
|
|
504
|
+
// always look at center or passed-in lookAt by default
|
|
505
|
+
if (!cameraOptions?.rotation && !cameraOptions?.quaternion) {
|
|
506
|
+
if (Array.isArray(lookAt))
|
|
507
|
+
camera.lookAt(lookAt[0], lookAt[1], lookAt[2]);
|
|
508
|
+
else if (lookAt instanceof THREE.Vector3)
|
|
509
|
+
camera.lookAt(lookAt);
|
|
510
|
+
else
|
|
511
|
+
camera.lookAt(0, 0, 0);
|
|
512
|
+
}
|
|
513
|
+
// update projection matrix after applyprops
|
|
514
|
+
camera.updateProjectionMatrix?.();
|
|
515
|
+
}
|
|
516
|
+
if (!is.instance(camera))
|
|
517
|
+
camera = prepare(camera, { store });
|
|
518
|
+
stateToUpdate.camera = camera;
|
|
519
|
+
}
|
|
520
|
+
// Set up scene (one time only!)
|
|
521
|
+
if (!state.scene) {
|
|
522
|
+
let scene;
|
|
523
|
+
if (sceneOptions instanceof THREE.Scene) {
|
|
524
|
+
scene = prepare(sceneOptions, { store });
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
scene = prepare(new THREE.Scene(), { store });
|
|
528
|
+
if (sceneOptions)
|
|
529
|
+
applyProps(scene, sceneOptions);
|
|
530
|
+
}
|
|
531
|
+
stateToUpdate.scene = scene;
|
|
532
|
+
}
|
|
533
|
+
// Set up XR (one time only!)
|
|
534
|
+
if (!state.xr) {
|
|
535
|
+
// Handle frame behavior in WebXR
|
|
536
|
+
const handleXRFrame = (timestamp, frame) => {
|
|
537
|
+
const state = store.get();
|
|
538
|
+
if (state.frameloop === 'never')
|
|
539
|
+
return;
|
|
540
|
+
loop.advance(timestamp, true, store, frame);
|
|
541
|
+
};
|
|
542
|
+
// Toggle render switching on session
|
|
543
|
+
const handleSessionChange = () => {
|
|
544
|
+
const state = store.get();
|
|
545
|
+
state.gl.xr.enabled = state.gl.xr.isPresenting;
|
|
546
|
+
state.gl.xr.setAnimationLoop(state.gl.xr.isPresenting ? handleXRFrame : null);
|
|
547
|
+
if (!state.gl.xr.isPresenting)
|
|
548
|
+
loop.invalidate(store);
|
|
549
|
+
};
|
|
550
|
+
// WebXR session manager
|
|
551
|
+
const xr = {
|
|
552
|
+
connect: () => {
|
|
553
|
+
gl.xr.addEventListener('sessionstart', handleSessionChange);
|
|
554
|
+
gl.xr.addEventListener('sessionend', handleSessionChange);
|
|
555
|
+
},
|
|
556
|
+
disconnect: () => {
|
|
557
|
+
gl.xr.removeEventListener('sessionstart', handleSessionChange);
|
|
558
|
+
gl.xr.removeEventListener('sessionend', handleSessionChange);
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
// Subscribe to WebXR session events
|
|
562
|
+
if (gl.xr && typeof gl.xr.addEventListener === 'function')
|
|
563
|
+
xr.connect();
|
|
564
|
+
stateToUpdate.xr = xr;
|
|
565
|
+
}
|
|
566
|
+
// Set shadowmap
|
|
567
|
+
if (gl.shadowMap) {
|
|
568
|
+
const oldEnabled = gl.shadowMap.enabled;
|
|
569
|
+
const oldType = gl.shadowMap.type;
|
|
570
|
+
gl.shadowMap.enabled = !!shadows;
|
|
571
|
+
if (typeof shadows === 'boolean') {
|
|
572
|
+
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
573
|
+
}
|
|
574
|
+
else if (typeof shadows === 'string') {
|
|
575
|
+
const types = {
|
|
576
|
+
basic: THREE.BasicShadowMap,
|
|
577
|
+
percentage: THREE.PCFShadowMap,
|
|
578
|
+
soft: THREE.PCFSoftShadowMap,
|
|
579
|
+
variance: THREE.VSMShadowMap,
|
|
580
|
+
};
|
|
581
|
+
gl.shadowMap.type = types[shadows] ?? THREE.PCFSoftShadowMap;
|
|
582
|
+
}
|
|
583
|
+
else if (is.obj(shadows)) {
|
|
584
|
+
Object.assign(gl.shadowMap, shadows);
|
|
585
|
+
}
|
|
586
|
+
if (oldEnabled !== gl.shadowMap.enabled || oldType !== gl.shadowMap.type)
|
|
587
|
+
checkNeedsUpdate(gl.shadowMap);
|
|
588
|
+
}
|
|
589
|
+
// Safely set color management if available.
|
|
590
|
+
// Avoid accessing THREE.ColorManagement to play nice with older versions
|
|
591
|
+
if (THREE.ColorManagement) {
|
|
592
|
+
const ColorManagement = THREE.ColorManagement;
|
|
593
|
+
if ('enabled' in ColorManagement)
|
|
594
|
+
ColorManagement['enabled'] = !legacy ?? false;
|
|
595
|
+
else if ('legacyMode' in ColorManagement)
|
|
596
|
+
ColorManagement['legacyMode'] = legacy ?? true;
|
|
597
|
+
}
|
|
598
|
+
// set color space and tonemapping preferences
|
|
599
|
+
const LinearEncoding = 3000;
|
|
600
|
+
const sRGBEncoding = 3001;
|
|
601
|
+
applyProps(gl, {
|
|
602
|
+
outputEncoding: linear ? LinearEncoding : sRGBEncoding,
|
|
603
|
+
toneMapping: flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping,
|
|
604
|
+
});
|
|
605
|
+
// Update color management state
|
|
606
|
+
if (state.legacy !== legacy)
|
|
607
|
+
stateToUpdate.legacy = legacy;
|
|
608
|
+
if (state.linear !== linear)
|
|
609
|
+
stateToUpdate.linear = linear;
|
|
610
|
+
if (state.flat !== flat)
|
|
611
|
+
stateToUpdate.flat = flat;
|
|
612
|
+
// Set gl props
|
|
613
|
+
gl.setClearAlpha(0);
|
|
614
|
+
gl.setPixelRatio(makeDpr(state.viewport.dpr));
|
|
615
|
+
gl.setSize(state.size.width, state.size.height);
|
|
616
|
+
if (is.obj(glOptions) &&
|
|
617
|
+
!(typeof glOptions === 'function') &&
|
|
618
|
+
!is.renderer(glOptions) &&
|
|
619
|
+
!is.equ(glOptions, gl, shallowLoose)) {
|
|
620
|
+
applyProps(gl, glOptions);
|
|
621
|
+
}
|
|
622
|
+
// Store events internally
|
|
623
|
+
if (events && !state.events.handlers)
|
|
624
|
+
stateToUpdate.events = events(store);
|
|
625
|
+
// Check performance
|
|
626
|
+
if (performance && !is.equ(performance, state.performance, shallowLoose)) {
|
|
627
|
+
stateToUpdate.performance = { ...state.performance, ...performance };
|
|
628
|
+
}
|
|
629
|
+
store.set(stateToUpdate);
|
|
630
|
+
// Check size, allow it to take on container bounds initially
|
|
631
|
+
const size = computeInitialSize(canvas, sizeOptions);
|
|
632
|
+
if (!is.equ(size, state.size, shallowLoose)) {
|
|
633
|
+
state.setSize(size.width, size.height, size.top, size.left);
|
|
634
|
+
}
|
|
635
|
+
// Check pixelratio
|
|
636
|
+
if (dpr && state.viewport.dpr !== makeDpr(dpr))
|
|
637
|
+
state.setDpr(dpr);
|
|
638
|
+
// Check frameloop
|
|
639
|
+
if (state.frameloop !== frameloop)
|
|
640
|
+
state.setFrameloop(frameloop);
|
|
641
|
+
isConfigured = true;
|
|
642
|
+
invalidateRef?.destroy();
|
|
643
|
+
invalidateRef = effect(() => void store.state().invalidate(), { manualCleanup: true, injector });
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
};
|
|
223
647
|
});
|
|
224
|
-
if (store.get('previousStore')) {
|
|
225
|
-
removeInteractivity(store.get('previousStore'), object);
|
|
226
|
-
}
|
|
227
648
|
}
|
|
228
|
-
function
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const dy = event.offsetY - internal.initialClick[1];
|
|
234
|
-
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
649
|
+
function computeInitialSize(canvas, defaultSize) {
|
|
650
|
+
if (defaultSize)
|
|
651
|
+
return defaultSize;
|
|
652
|
+
if (canvas instanceof HTMLCanvasElement && canvas.parentElement) {
|
|
653
|
+
return canvas.parentElement.getBoundingClientRect();
|
|
235
654
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
655
|
+
return { width: 0, height: 0, top: 0, left: 0 };
|
|
656
|
+
}
|
|
657
|
+
// Disposes an object and all its properties
|
|
658
|
+
function dispose(obj) {
|
|
659
|
+
if (obj.dispose && obj.type !== 'Scene')
|
|
660
|
+
obj.dispose();
|
|
661
|
+
for (const p in obj) {
|
|
662
|
+
p.dispose?.();
|
|
663
|
+
delete obj[p];
|
|
242
664
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
instanceState.raycaster.camera = undefined;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (!state.previousStore) {
|
|
257
|
-
// make sure root-level pointer and ray are setup
|
|
258
|
-
state.events.compute?.(event, store);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function createInjectFn(token) {
|
|
668
|
+
return (injectOptions) => inject(token, injectOptions);
|
|
669
|
+
}
|
|
670
|
+
function createProvideFn(token, factory, deps, extraProviders) {
|
|
671
|
+
return (value) => {
|
|
672
|
+
let provider;
|
|
673
|
+
if (value) {
|
|
674
|
+
provider = { provide: token, useValue: value };
|
|
259
675
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const objStore = objLocalState.store;
|
|
263
|
-
const objState = objStore?.get();
|
|
264
|
-
// skip event handling when noEvents is set, or when raycaster camera is null
|
|
265
|
-
if (!objState || !objState.events.enabled || objState.raycaster.camera === null)
|
|
266
|
-
return [];
|
|
267
|
-
// when the camera is undefined, we have to call the events layers to update function
|
|
268
|
-
if (objState.raycaster.camera === undefined) {
|
|
269
|
-
objState.events.compute?.(event, objStore, objState.previousStore);
|
|
270
|
-
// if the camera is still undefined, we have to skip this layer entirely
|
|
271
|
-
if (objState.raycaster.camera === undefined)
|
|
272
|
-
objState.raycaster.camera = null;
|
|
273
|
-
}
|
|
274
|
-
// intersect object by object
|
|
275
|
-
return objState.raycaster.camera ? objState.raycaster.intersectObject(obj, true) : [];
|
|
676
|
+
else {
|
|
677
|
+
provider = { provide: token, useFactory: factory, deps: (deps ?? []) };
|
|
276
678
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return false;
|
|
294
|
-
duplicates.add(id);
|
|
295
|
-
return true;
|
|
296
|
-
});
|
|
297
|
-
// allow custom userland intersect sort order, this likely only makes sense on the root
|
|
298
|
-
if (state.events.filter)
|
|
299
|
-
hits = state.events.filter(hits, store);
|
|
300
|
-
// bubble up the events, find the event source
|
|
301
|
-
for (const hit of hits) {
|
|
302
|
-
let eventObject = hit.object;
|
|
303
|
-
// bubble event up
|
|
304
|
-
while (eventObject) {
|
|
305
|
-
if (getLocalState(eventObject).eventCount) {
|
|
306
|
-
intersections.push({ ...hit, eventObject });
|
|
679
|
+
return extraProviders ? [extraProviders, provider] : provider;
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function createInjectionToken(factory, options) {
|
|
683
|
+
const opts = options ?? { isRoot: true };
|
|
684
|
+
opts.isRoot ??= true;
|
|
685
|
+
if (opts.isRoot) {
|
|
686
|
+
if (opts.token) {
|
|
687
|
+
throw new Error(`\
|
|
688
|
+
createInjectionToken is creating a root InjectionToken but an external token is passed in.
|
|
689
|
+
`);
|
|
690
|
+
}
|
|
691
|
+
const token = new InjectionToken(`Token for ${factory.name}`, {
|
|
692
|
+
factory: () => {
|
|
693
|
+
if (opts.deps && Array.isArray(opts.deps)) {
|
|
694
|
+
return factory(...opts.deps.map((dep) => inject(dep)));
|
|
307
695
|
}
|
|
308
|
-
|
|
696
|
+
return factory();
|
|
697
|
+
},
|
|
698
|
+
});
|
|
699
|
+
return [
|
|
700
|
+
createInjectFn(token),
|
|
701
|
+
createProvideFn(token, factory, opts.deps),
|
|
702
|
+
token,
|
|
703
|
+
];
|
|
704
|
+
}
|
|
705
|
+
const token = opts.token || new InjectionToken(`Token for ${factory.name}`);
|
|
706
|
+
return [
|
|
707
|
+
createInjectFn(token),
|
|
708
|
+
createProvideFn(token, factory, opts.deps, opts.extraProviders),
|
|
709
|
+
token,
|
|
710
|
+
];
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function createSubs(callback, subs) {
|
|
714
|
+
const sub = { callback };
|
|
715
|
+
subs.add(sub);
|
|
716
|
+
return () => void subs.delete(sub);
|
|
717
|
+
}
|
|
718
|
+
const globalEffects = new Set();
|
|
719
|
+
const globalAfterEffects = new Set();
|
|
720
|
+
const globalTailEffects = new Set();
|
|
721
|
+
/**
|
|
722
|
+
* Adds a global render callback which is called each frame.
|
|
723
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
724
|
+
*/
|
|
725
|
+
const addEffect = (callback) => createSubs(callback, globalEffects);
|
|
726
|
+
/**
|
|
727
|
+
* Adds a global after-render callback which is called each frame.
|
|
728
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
729
|
+
*/
|
|
730
|
+
const addAfterEffect = (callback) => createSubs(callback, globalAfterEffects);
|
|
731
|
+
/**
|
|
732
|
+
* Adds a global callback which is called when rendering stops.
|
|
733
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
734
|
+
*/
|
|
735
|
+
const addTail = (callback) => createSubs(callback, globalTailEffects);
|
|
736
|
+
function run(effects, timestamp) {
|
|
737
|
+
if (!effects.size)
|
|
738
|
+
return;
|
|
739
|
+
for (const { callback } of effects.values()) {
|
|
740
|
+
callback(timestamp);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function flushGlobalEffects(type, timestamp) {
|
|
744
|
+
switch (type) {
|
|
745
|
+
case 'before':
|
|
746
|
+
return run(globalEffects, timestamp);
|
|
747
|
+
case 'after':
|
|
748
|
+
return run(globalAfterEffects, timestamp);
|
|
749
|
+
case 'tail':
|
|
750
|
+
return run(globalTailEffects, timestamp);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function render(timestamp, store, frame) {
|
|
754
|
+
const state = store.get();
|
|
755
|
+
// Run local effects
|
|
756
|
+
let delta = state.clock.getDelta();
|
|
757
|
+
// In frameloop='never' mode, clock times are updated using the provided timestamp
|
|
758
|
+
if (state.frameloop === 'never' && typeof timestamp === 'number') {
|
|
759
|
+
delta = timestamp - state.clock.elapsedTime;
|
|
760
|
+
state.clock.oldTime = state.clock.elapsedTime;
|
|
761
|
+
state.clock.elapsedTime = timestamp;
|
|
762
|
+
}
|
|
763
|
+
// Call subscribers (useFrame)
|
|
764
|
+
const subscribers = state.internal.subscribers;
|
|
765
|
+
for (let i = 0; i < subscribers.length; i++) {
|
|
766
|
+
const subscription = subscribers[i];
|
|
767
|
+
subscription.callback({ ...subscription.store.get(), delta, frame });
|
|
768
|
+
}
|
|
769
|
+
// Render content
|
|
770
|
+
if (!state.internal.priority && state.gl.render)
|
|
771
|
+
state.gl.render(state.scene, state.camera);
|
|
772
|
+
// Decrease frame count
|
|
773
|
+
state.internal.frames = Math.max(0, state.internal.frames - 1);
|
|
774
|
+
return state.frameloop === 'always' ? 1 : state.internal.frames;
|
|
775
|
+
}
|
|
776
|
+
function createLoop(roots) {
|
|
777
|
+
let running = false;
|
|
778
|
+
let repeat;
|
|
779
|
+
let frame;
|
|
780
|
+
function loop(timestamp) {
|
|
781
|
+
frame = requestAnimationFrame(loop);
|
|
782
|
+
running = true;
|
|
783
|
+
repeat = 0;
|
|
784
|
+
// Run effects
|
|
785
|
+
flushGlobalEffects('before', timestamp);
|
|
786
|
+
// Render all roots
|
|
787
|
+
for (const root of roots.values()) {
|
|
788
|
+
const state = root.get();
|
|
789
|
+
// If the frameloop is invalidated, do not run another frame
|
|
790
|
+
if (state.internal.active &&
|
|
791
|
+
(state.frameloop === 'always' || state.internal.frames > 0) &&
|
|
792
|
+
!state.gl.xr?.isPresenting) {
|
|
793
|
+
repeat += render(timestamp, root);
|
|
309
794
|
}
|
|
310
795
|
}
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
796
|
+
// Run after-effects
|
|
797
|
+
flushGlobalEffects('after', timestamp);
|
|
798
|
+
// Stop the loop if nothing invalidates it
|
|
799
|
+
if (repeat === 0) {
|
|
800
|
+
// Tail call effects, they are called when rendering stops
|
|
801
|
+
flushGlobalEffects('tail', timestamp);
|
|
802
|
+
// Flag end of operation
|
|
803
|
+
running = false;
|
|
804
|
+
return cancelAnimationFrame(frame);
|
|
318
805
|
}
|
|
319
|
-
return intersections;
|
|
320
806
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const captureData = { intersection: hit, target: event.target };
|
|
334
|
-
if (internal.capturedMap.has(id)) {
|
|
335
|
-
// if the pointerId was previously captured, we add the hit to the event capturedMap
|
|
336
|
-
internal.capturedMap.get(id).set(hit.eventObject, captureData);
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
// if the pointerId was not previously captured, we create a Map containing the hitObject, and the hit. hitObject is used for faster access
|
|
340
|
-
internal.capturedMap.set(id, new Map([[hit.eventObject, captureData]]));
|
|
341
|
-
}
|
|
342
|
-
// call the original event now
|
|
343
|
-
event.target.setPointerCapture(id);
|
|
344
|
-
};
|
|
345
|
-
const releasePointerCapture = (id) => {
|
|
346
|
-
const captures = internal.capturedMap.get(id);
|
|
347
|
-
if (captures) {
|
|
348
|
-
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
// add native event props
|
|
352
|
-
const extractEventProps = {};
|
|
353
|
-
// This iterates over the event's properties including the inherited ones. Native PointerEvents have most of their props as getters which are inherited, but polyfilled PointerEvents have them all as their own properties (i.e. not inherited). We can't use Object.keys() or Object.entries() as they only return "own" properties; nor Object.getPrototypeOf(event) as that *doesn't* return "own" properties, only inherited ones.
|
|
354
|
-
for (const prop in event) {
|
|
355
|
-
const property = event[prop];
|
|
356
|
-
// only copy over atomics, leave functions alone as these should be called as event.nativeEvent.fn()
|
|
357
|
-
if (typeof property !== 'function') {
|
|
358
|
-
extractEventProps[prop] = property;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
const raycastEvent = {
|
|
362
|
-
...hit,
|
|
363
|
-
...extractEventProps,
|
|
364
|
-
pointer,
|
|
365
|
-
intersections,
|
|
366
|
-
stopped: localState.stopped,
|
|
367
|
-
delta,
|
|
368
|
-
unprojectedPoint,
|
|
369
|
-
ray: raycaster.ray,
|
|
370
|
-
camera: camera,
|
|
371
|
-
// Hijack stopPropagation, which just sets a flag
|
|
372
|
-
stopPropagation() {
|
|
373
|
-
// https://github.com/pmndrs/react-three-fiber/issues/596
|
|
374
|
-
// Events are not allowed to stop propagation if the pointer has been captured
|
|
375
|
-
const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId);
|
|
376
|
-
// We only authorize stopPropagation...
|
|
377
|
-
if (
|
|
378
|
-
// ...if this pointer hasn't been captured
|
|
379
|
-
!capturesForPointer ||
|
|
380
|
-
// ... or if the hit object is capturing the pointer
|
|
381
|
-
capturesForPointer.has(hit.eventObject)) {
|
|
382
|
-
raycastEvent.stopped = localState.stopped = true;
|
|
383
|
-
// Propagation is stopped, remove all other hover records
|
|
384
|
-
// An event handler is only allowed to flush other handlers if it is hovered itself
|
|
385
|
-
if (internal.hovered.size &&
|
|
386
|
-
Array.from(internal.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
387
|
-
// Objects cannot flush out higher up objects that have already caught the event
|
|
388
|
-
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
389
|
-
cancelPointer([...higher, hit]);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
},
|
|
393
|
-
// there should be a distinction between target and currentTarget
|
|
394
|
-
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
395
|
-
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
396
|
-
nativeEvent: event,
|
|
397
|
-
};
|
|
398
|
-
// call subscribers
|
|
399
|
-
callback(raycastEvent);
|
|
400
|
-
// event bubbling may be interupted by stopPropagation
|
|
401
|
-
if (localState.stopped === true)
|
|
402
|
-
break;
|
|
403
|
-
}
|
|
807
|
+
function invalidate(store, frames = 1) {
|
|
808
|
+
const state = store?.get();
|
|
809
|
+
if (!state)
|
|
810
|
+
return roots.forEach((root) => invalidate(root, frames));
|
|
811
|
+
if (state.gl.xr?.isPresenting || !state.internal.active || state.frameloop === 'never')
|
|
812
|
+
return;
|
|
813
|
+
// Increase frames, do not go higher than 60
|
|
814
|
+
state.internal.frames = Math.min(60, state.internal.frames + frames);
|
|
815
|
+
// If the render-loop isn't active, start it
|
|
816
|
+
if (!running) {
|
|
817
|
+
running = true;
|
|
818
|
+
requestAnimationFrame(loop);
|
|
404
819
|
}
|
|
405
|
-
return intersections;
|
|
406
820
|
}
|
|
407
|
-
function
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
821
|
+
function advance(timestamp, runGlobalEffects = true, store, frame) {
|
|
822
|
+
if (runGlobalEffects)
|
|
823
|
+
flushGlobalEffects('before', timestamp);
|
|
824
|
+
const state = store?.get();
|
|
825
|
+
if (!state)
|
|
826
|
+
for (const root of roots.values())
|
|
827
|
+
render(timestamp, root);
|
|
828
|
+
else
|
|
829
|
+
render(timestamp, store, frame);
|
|
830
|
+
if (runGlobalEffects)
|
|
831
|
+
flushGlobalEffects('after', timestamp);
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
loop,
|
|
835
|
+
/**
|
|
836
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
837
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
838
|
+
*/
|
|
839
|
+
invalidate,
|
|
840
|
+
/**
|
|
841
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
842
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
843
|
+
*/
|
|
844
|
+
advance,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
const [injectNgtLoop, , NGT_LOOP] = createInjectionToken(() => createLoop(roots));
|
|
848
|
+
|
|
849
|
+
function safeDetectChanges(...cdrs) {
|
|
850
|
+
cdrs.forEach((cdr) => {
|
|
851
|
+
if (!cdr)
|
|
852
|
+
return;
|
|
853
|
+
try {
|
|
854
|
+
// dynamic created component with ViewContainerRef#createComponent does not have Context
|
|
855
|
+
// but it has _attachedToViewContainer
|
|
856
|
+
if (cdr['_attachedToViewContainer'] || !!cdr['context']) {
|
|
857
|
+
cdr.detectChanges();
|
|
426
858
|
}
|
|
427
859
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
for (let i = 0; i < objects.length; i++) {
|
|
431
|
-
const instance = getLocalState(objects[i]);
|
|
432
|
-
instance?.handlers.pointermissed?.(event);
|
|
860
|
+
catch (e) {
|
|
861
|
+
cdr.markForCheck();
|
|
433
862
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const { internal } = store.get();
|
|
444
|
-
if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
|
|
445
|
-
// If the object event interface had onLostPointerCapture, we'd call it here on every
|
|
446
|
-
// object that's getting removed.
|
|
447
|
-
internal.capturedMap.delete(event.pointerId);
|
|
448
|
-
cancelPointer([]);
|
|
449
|
-
}
|
|
450
|
-
};
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
function storeFactory(loop, document, injector, parent) {
|
|
867
|
+
return runInInjectionContext(injector, () => {
|
|
868
|
+
const window = document.defaultView;
|
|
869
|
+
if (!window) {
|
|
870
|
+
// TODO: revisit this when we need to support multiple platforms
|
|
871
|
+
throw new Error(`[NGT] Window is not available.`);
|
|
451
872
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
// Take care of unhover
|
|
479
|
-
if (isPointerMove)
|
|
480
|
-
cancelPointer(hits);
|
|
481
|
-
function onIntersect(data) {
|
|
482
|
-
const eventObject = data.eventObject;
|
|
483
|
-
const instance = getLocalState(eventObject);
|
|
484
|
-
const handlers = instance?.handlers;
|
|
485
|
-
// Check presence of handlers
|
|
486
|
-
if (!instance?.eventCount)
|
|
487
|
-
return;
|
|
488
|
-
if (isPointerMove) {
|
|
489
|
-
// Move event ...
|
|
490
|
-
if (handlers?.pointerover ||
|
|
491
|
-
handlers?.pointerenter ||
|
|
492
|
-
handlers?.pointerout ||
|
|
493
|
-
handlers?.pointerleave) {
|
|
494
|
-
// When enter or out is present take care of hover-state
|
|
495
|
-
const id = makeId(data);
|
|
496
|
-
const hoveredItem = internal.hovered.get(id);
|
|
497
|
-
if (!hoveredItem) {
|
|
498
|
-
// If the object wasn't previously hovered, book it and call its handler
|
|
499
|
-
internal.hovered.set(id, data);
|
|
500
|
-
handlers.pointerover?.(data);
|
|
501
|
-
handlers.pointerenter?.(data);
|
|
502
|
-
}
|
|
503
|
-
else if (hoveredItem.stopped) {
|
|
504
|
-
// If the object was previously hovered and stopped, we shouldn't allow other items to proceed
|
|
505
|
-
data.stopPropagation();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
// Call mouse move
|
|
509
|
-
handlers?.pointermove?.(data);
|
|
873
|
+
const cdr = inject(ChangeDetectorRef);
|
|
874
|
+
// NOTE: using Subject because we do not care about late-subscribers
|
|
875
|
+
const pointerMissed$ = new Subject();
|
|
876
|
+
const store = signalStore(({ get, set }) => {
|
|
877
|
+
const { invalidate, advance } = loop;
|
|
878
|
+
const position = new THREE.Vector3();
|
|
879
|
+
const defaultTarget = new THREE.Vector3();
|
|
880
|
+
const tempTarget = new THREE.Vector3();
|
|
881
|
+
function getCurrentViewport(camera = get('camera'), target = defaultTarget, size = get('size')) {
|
|
882
|
+
const { width, height, top, left } = size;
|
|
883
|
+
const aspect = width / height;
|
|
884
|
+
if (target instanceof THREE.Vector3)
|
|
885
|
+
tempTarget.copy(target);
|
|
886
|
+
else
|
|
887
|
+
tempTarget.set(...target);
|
|
888
|
+
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
889
|
+
if (is.orthographicCamera(camera)) {
|
|
890
|
+
return {
|
|
891
|
+
width: width / camera.zoom,
|
|
892
|
+
height: height / camera.zoom,
|
|
893
|
+
top,
|
|
894
|
+
left,
|
|
895
|
+
factor: 1,
|
|
896
|
+
distance,
|
|
897
|
+
aspect,
|
|
898
|
+
};
|
|
510
899
|
}
|
|
511
900
|
else {
|
|
512
|
-
//
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
// which must use the initial target
|
|
517
|
-
if (!isClickEvent || internal.initialHits.includes(eventObject)) {
|
|
518
|
-
// Missed events have to come first
|
|
519
|
-
pointerMissed(event, internal.interaction.filter((object) => !internal.initialHits.includes(object)));
|
|
520
|
-
// Now call the handler
|
|
521
|
-
handler(data);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
// Trigger onPointerMissed on all elements that have pointer over/out handlers, but not click and weren't hit
|
|
526
|
-
if (isClickEvent && internal.initialHits.includes(eventObject)) {
|
|
527
|
-
pointerMissed(event, internal.interaction.filter((object) => !internal.initialHits.includes(object)));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
901
|
+
const fov = (camera.fov * Math.PI) / 180; // convert vertical fov to radians
|
|
902
|
+
const h = 2 * Math.tan(fov / 2) * distance; // visible height
|
|
903
|
+
const w = h * (width / height);
|
|
904
|
+
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
530
905
|
}
|
|
531
906
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
907
|
+
let performanceTimeout = undefined;
|
|
908
|
+
const setPerformanceCurrent = (current) => set((state) => ({ performance: { ...state.performance, current } }));
|
|
909
|
+
const pointer = new THREE.Vector2();
|
|
910
|
+
return {
|
|
911
|
+
pointerMissed$: pointerMissed$.asObservable(),
|
|
912
|
+
events: { priority: 1, enabled: true, connected: false },
|
|
913
|
+
invalidate: (frames = 1) => invalidate(store, frames),
|
|
914
|
+
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, store),
|
|
915
|
+
legacy: false,
|
|
916
|
+
linear: false,
|
|
917
|
+
flat: false,
|
|
918
|
+
controls: null,
|
|
919
|
+
clock: new THREE.Clock(),
|
|
920
|
+
pointer,
|
|
921
|
+
frameloop: 'always',
|
|
922
|
+
performance: {
|
|
923
|
+
current: 1,
|
|
924
|
+
min: 0.5,
|
|
925
|
+
max: 1,
|
|
926
|
+
debounce: 200,
|
|
927
|
+
regress: () => {
|
|
928
|
+
const state = get();
|
|
929
|
+
// Clear timeout
|
|
930
|
+
if (performanceTimeout)
|
|
931
|
+
clearTimeout(performanceTimeout);
|
|
932
|
+
// Set lower bound performance
|
|
933
|
+
if (state.performance.current !== state.performance.min)
|
|
934
|
+
setPerformanceCurrent(state.performance.min);
|
|
935
|
+
// Go back to upper bound performance after a while unless something regresses meanwhile
|
|
936
|
+
performanceTimeout = setTimeout(() => {
|
|
937
|
+
setPerformanceCurrent(get('performance', 'max'));
|
|
938
|
+
safeDetectChanges(cdr);
|
|
939
|
+
}, state.performance.debounce);
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
size: { width: 0, height: 0, top: 0, left: 0, updateStyle: false },
|
|
943
|
+
viewport: {
|
|
944
|
+
initialDpr: 0,
|
|
945
|
+
dpr: 0,
|
|
946
|
+
width: 0,
|
|
947
|
+
height: 0,
|
|
948
|
+
top: 0,
|
|
949
|
+
left: 0,
|
|
950
|
+
aspect: 0,
|
|
951
|
+
distance: 0,
|
|
952
|
+
factor: 0,
|
|
953
|
+
getCurrentViewport,
|
|
954
|
+
},
|
|
955
|
+
setEvents: (events) => set((state) => ({ ...state, events: { ...state.events, ...events } })),
|
|
956
|
+
setSize: (width, height, top, left) => {
|
|
957
|
+
const camera = get('camera');
|
|
958
|
+
const size = { width, height, top: top || 0, left: left || 0 };
|
|
959
|
+
set((state) => ({
|
|
960
|
+
size,
|
|
961
|
+
viewport: { ...state.viewport, ...getCurrentViewport(camera, defaultTarget, size) },
|
|
962
|
+
}));
|
|
963
|
+
},
|
|
964
|
+
setDpr: (dpr) => set((state) => {
|
|
965
|
+
const resolved = makeDpr(dpr, window);
|
|
966
|
+
return {
|
|
967
|
+
viewport: {
|
|
968
|
+
...state.viewport,
|
|
969
|
+
dpr: resolved,
|
|
970
|
+
initialDpr: state.viewport.initialDpr || resolved,
|
|
971
|
+
},
|
|
972
|
+
};
|
|
973
|
+
}),
|
|
974
|
+
setFrameloop: (frameloop = 'always') => {
|
|
975
|
+
const clock = get('clock');
|
|
976
|
+
// if frameloop === "never" clock.elapsedTime is updated using advance(timestamp)
|
|
977
|
+
clock.stop();
|
|
978
|
+
clock.elapsedTime = 0;
|
|
979
|
+
if (frameloop !== 'never') {
|
|
980
|
+
clock.start();
|
|
981
|
+
clock.elapsedTime = 0;
|
|
597
982
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
983
|
+
set(() => ({ frameloop }));
|
|
984
|
+
},
|
|
985
|
+
previousRoot: parent,
|
|
986
|
+
internal: {
|
|
987
|
+
active: false,
|
|
988
|
+
priority: 0,
|
|
989
|
+
frames: 0,
|
|
990
|
+
lastEvent: new ElementRef(null),
|
|
991
|
+
interaction: [],
|
|
992
|
+
hovered: new Map(),
|
|
993
|
+
subscribers: [],
|
|
994
|
+
initialClick: [0, 0],
|
|
995
|
+
initialHits: [],
|
|
996
|
+
capturedMap: new Map(),
|
|
997
|
+
subscribe: (callback, priority = 0, _store = store) => {
|
|
998
|
+
const internal = get('internal');
|
|
999
|
+
// If this subscription was given a priority, it takes rendering into its own hands
|
|
1000
|
+
// For that reason we switch off automatic rendering and increase the manual flag
|
|
1001
|
+
// As long as this flag is positive there can be no internal rendering at all
|
|
1002
|
+
// because there could be multiple render subscriptions
|
|
1003
|
+
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1004
|
+
internal.subscribers.push({ callback, priority, store });
|
|
1005
|
+
// Register subscriber and sort layers from lowest to highest, meaning,
|
|
1006
|
+
// highest priority renders last (on top of the other frames)
|
|
1007
|
+
internal.subscribers = internal.subscribers.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
1008
|
+
return () => {
|
|
1009
|
+
const internal = get('internal');
|
|
1010
|
+
if (internal?.subscribers) {
|
|
1011
|
+
// Decrease manual flag if this subscription had a priority
|
|
1012
|
+
internal.priority = internal.priority - (priority > 0 ? 1 : 0);
|
|
1013
|
+
// Remove subscriber from list
|
|
1014
|
+
internal.subscribers = internal.subscribers.filter((s) => s.callback !== callback);
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
},
|
|
1018
|
+
},
|
|
1019
|
+
};
|
|
1020
|
+
});
|
|
1021
|
+
// NOTE: assign pointerMissed$ so we can use it in events
|
|
1022
|
+
Object.defineProperty(store, 'pointerMissed$', { get: () => pointerMissed$ });
|
|
1023
|
+
const state = store.get();
|
|
1024
|
+
let oldSize = state.size;
|
|
1025
|
+
let oldDpr = state.viewport.dpr;
|
|
1026
|
+
let oldCamera = state.camera;
|
|
1027
|
+
const _camera = store.select('camera');
|
|
1028
|
+
const _size = store.select('size');
|
|
1029
|
+
const _viewport = store.select('viewport');
|
|
1030
|
+
effect(() => {
|
|
1031
|
+
const [camera, size, viewport, gl] = [_camera(), _size(), _viewport(), store.get('gl')];
|
|
1032
|
+
// Resize camera and renderer on changes to size and pixelratio
|
|
1033
|
+
if (size !== oldSize || viewport.dpr !== oldDpr) {
|
|
1034
|
+
oldSize = size;
|
|
1035
|
+
oldDpr = viewport.dpr;
|
|
1036
|
+
// Update camera & renderer
|
|
1037
|
+
updateCamera(camera, size);
|
|
1038
|
+
gl.setPixelRatio(viewport.dpr);
|
|
1039
|
+
const updateStyle = typeof HTMLCanvasElement !== 'undefined' && gl.domElement instanceof HTMLCanvasElement;
|
|
1040
|
+
gl.setSize(size.width, size.height, updateStyle);
|
|
639
1041
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
1042
|
+
// Update viewport once the camera changes
|
|
1043
|
+
if (camera !== oldCamera) {
|
|
1044
|
+
oldCamera = camera;
|
|
1045
|
+
updateCamera(camera, size);
|
|
1046
|
+
// Update viewport
|
|
1047
|
+
store.set((state) => ({
|
|
1048
|
+
viewport: { ...state.viewport, ...state.viewport.getCurrentViewport(camera) },
|
|
1049
|
+
}));
|
|
647
1050
|
}
|
|
648
|
-
})
|
|
649
|
-
|
|
1051
|
+
});
|
|
1052
|
+
return store;
|
|
1053
|
+
});
|
|
650
1054
|
}
|
|
651
|
-
|
|
652
|
-
|
|
1055
|
+
const NGT_STORE = new InjectionToken('NgtStore token');
|
|
1056
|
+
const [injectNgtStore, provideNgtStore] = createInjectionToken(storeFactory, {
|
|
1057
|
+
isRoot: false,
|
|
1058
|
+
deps: [NGT_LOOP, DOCUMENT, Injector, [new Optional(), new SkipSelf(), NGT_STORE]],
|
|
1059
|
+
token: NGT_STORE,
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
function injectBeforeRender(cb, { priority = 0, injector } = {}) {
|
|
1063
|
+
injector = assertInjectionContext(injectBeforeRender, injector);
|
|
653
1064
|
return runInInjectionContext(injector, () => {
|
|
654
|
-
const
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const originalUrls = untracked(inputs);
|
|
659
|
-
Promise.all(effector())
|
|
660
|
-
.then((results) => {
|
|
661
|
-
if (Array.isArray(originalUrls))
|
|
662
|
-
return results;
|
|
663
|
-
if (typeof originalUrls === 'string')
|
|
664
|
-
return results[0];
|
|
665
|
-
const keys = Object.keys(originalUrls);
|
|
666
|
-
return keys.reduce((result, key) => {
|
|
667
|
-
result[key] = results[keys.indexOf(key)];
|
|
668
|
-
return result;
|
|
669
|
-
}, {});
|
|
670
|
-
})
|
|
671
|
-
.then((value) => {
|
|
672
|
-
response.set(value);
|
|
673
|
-
safeDetectChanges(cdr);
|
|
674
|
-
});
|
|
675
|
-
}, { injector: injector, allowSignalWrites: true });
|
|
676
|
-
return response.asReadonly();
|
|
1065
|
+
const store = injectNgtStore();
|
|
1066
|
+
const sub = store.get('internal').subscribe(cb, priority, store);
|
|
1067
|
+
inject(DestroyRef).onDestroy(() => void sub());
|
|
1068
|
+
return sub;
|
|
677
1069
|
});
|
|
678
1070
|
}
|
|
679
|
-
injectNgtLoader['preload'] = (loaderConstructorFactory, inputs, extensions) => {
|
|
680
|
-
Promise.all(load(loaderConstructorFactory, inputs, { extensions })());
|
|
681
|
-
};
|
|
682
|
-
injectNgtLoader['destroy'] = () => {
|
|
683
|
-
cached.clear();
|
|
684
|
-
};
|
|
685
1071
|
|
|
686
|
-
function createSubs(callback, subs) {
|
|
687
|
-
const sub = { callback };
|
|
688
|
-
subs.add(sub);
|
|
689
|
-
return () => void subs.delete(sub);
|
|
690
|
-
}
|
|
691
|
-
const globalEffects = new Set();
|
|
692
|
-
const globalAfterEffects = new Set();
|
|
693
|
-
const globalTailEffects = new Set();
|
|
694
|
-
/**
|
|
695
|
-
* Adds a global render callback which is called each frame.
|
|
696
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
697
|
-
*/
|
|
698
|
-
const addEffect = (callback) => createSubs(callback, globalEffects);
|
|
699
1072
|
/**
|
|
700
|
-
*
|
|
701
|
-
*
|
|
1073
|
+
* Release pointer captures.
|
|
1074
|
+
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
702
1075
|
*/
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
for (const { callback } of effects.values()) {
|
|
713
|
-
callback(timestamp);
|
|
1076
|
+
function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
|
|
1077
|
+
const captureData = captures.get(obj);
|
|
1078
|
+
if (captureData) {
|
|
1079
|
+
captures.delete(obj);
|
|
1080
|
+
// If this was the last capturing object for this pointer
|
|
1081
|
+
if (captures.size === 0) {
|
|
1082
|
+
capturedMap.delete(pointerId);
|
|
1083
|
+
captureData.target.releasePointerCapture(pointerId);
|
|
1084
|
+
}
|
|
714
1085
|
}
|
|
715
1086
|
}
|
|
716
|
-
function
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
1087
|
+
function removeInteractivity(store, object) {
|
|
1088
|
+
const { internal } = store.get();
|
|
1089
|
+
// Removes every trace of an object from the data store
|
|
1090
|
+
internal.interaction = internal.interaction.filter((o) => o !== object);
|
|
1091
|
+
internal.initialHits = internal.initialHits.filter((o) => o !== object);
|
|
1092
|
+
internal.hovered.forEach((value, key) => {
|
|
1093
|
+
if (value.eventObject === object || value.object === object) {
|
|
1094
|
+
// Clear out intersects, they are outdated by now
|
|
1095
|
+
internal.hovered.delete(key);
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
internal.capturedMap.forEach((captures, pointerId) => {
|
|
1099
|
+
releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
|
|
1100
|
+
});
|
|
725
1101
|
}
|
|
726
|
-
function
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
state.clock.oldTime = state.clock.elapsedTime;
|
|
734
|
-
state.clock.elapsedTime = timestamp;
|
|
1102
|
+
function createEvents(store) {
|
|
1103
|
+
/** Calculates delta */
|
|
1104
|
+
function calculateDistance(event) {
|
|
1105
|
+
const internal = store.get('internal');
|
|
1106
|
+
const dx = event.offsetX - internal.initialClick[0];
|
|
1107
|
+
const dy = event.offsetY - internal.initialClick[1];
|
|
1108
|
+
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
735
1109
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
1110
|
+
/** Returns true if an instance has a valid pointer-event registered, this excludes scroll, clicks etc */
|
|
1111
|
+
function filterPointerEvents(objects) {
|
|
1112
|
+
return objects.filter((obj) => ['move', 'over', 'enter', 'out', 'leave'].some((name) => {
|
|
1113
|
+
const eventName = `pointer${name}`;
|
|
1114
|
+
return getLocalState(obj).handlers?.[eventName];
|
|
1115
|
+
}));
|
|
741
1116
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
function loop(timestamp) {
|
|
754
|
-
frame = requestAnimationFrame(loop);
|
|
755
|
-
running = true;
|
|
756
|
-
repeat = 0;
|
|
757
|
-
// Run effects
|
|
758
|
-
flushGlobalEffects('before', timestamp);
|
|
759
|
-
// Render all roots
|
|
760
|
-
for (const root of roots.values()) {
|
|
761
|
-
const state = root.get();
|
|
762
|
-
// If the frameloop is invalidated, do not run another frame
|
|
763
|
-
if (state.internal.active &&
|
|
764
|
-
(state.frameloop === 'always' || state.internal.frames > 0) &&
|
|
765
|
-
!state.gl.xr?.isPresenting) {
|
|
766
|
-
repeat += render(timestamp, root);
|
|
1117
|
+
function intersect(event, filter) {
|
|
1118
|
+
const state = store.get();
|
|
1119
|
+
const duplicates = new Set();
|
|
1120
|
+
const intersections = [];
|
|
1121
|
+
// Allow callers to eliminate event objects
|
|
1122
|
+
const eventsObjects = filter ? filter(state.internal.interaction) : state.internal.interaction;
|
|
1123
|
+
// Reset all raycaster cameras to undefined
|
|
1124
|
+
for (let i = 0; i < eventsObjects.length; i++) {
|
|
1125
|
+
const state = getLocalState(eventsObjects[i]).store.get();
|
|
1126
|
+
if (state) {
|
|
1127
|
+
state.raycaster.camera = undefined;
|
|
767
1128
|
}
|
|
768
1129
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
if (repeat === 0) {
|
|
773
|
-
// Tail call effects, they are called when rendering stops
|
|
774
|
-
flushGlobalEffects('tail', timestamp);
|
|
775
|
-
// Flag end of operation
|
|
776
|
-
running = false;
|
|
777
|
-
return cancelAnimationFrame(frame);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
function invalidate(store, frames = 1) {
|
|
781
|
-
const state = store?.get();
|
|
782
|
-
if (!state)
|
|
783
|
-
return roots.forEach((root) => invalidate(root, frames));
|
|
784
|
-
if (state.gl.xr?.isPresenting || !state.internal.active || state.frameloop === 'never')
|
|
785
|
-
return;
|
|
786
|
-
// Increase frames, do not go higher than 60
|
|
787
|
-
state.internal.frames = Math.min(60, state.internal.frames + frames);
|
|
788
|
-
// If the render-loop isn't active, start it
|
|
789
|
-
if (!running) {
|
|
790
|
-
running = true;
|
|
791
|
-
requestAnimationFrame(loop);
|
|
1130
|
+
if (!state.previousRoot) {
|
|
1131
|
+
// Make sure root-level pointer and ray are set up
|
|
1132
|
+
state.events.compute?.(event, store, null);
|
|
792
1133
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
return {
|
|
807
|
-
loop,
|
|
808
|
-
/**
|
|
809
|
-
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
810
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
811
|
-
*/
|
|
812
|
-
invalidate,
|
|
813
|
-
/**
|
|
814
|
-
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
815
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
816
|
-
*/
|
|
817
|
-
advance,
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
function diffProps(instance, props) {
|
|
822
|
-
const propsEntries = Object.entries(props);
|
|
823
|
-
const changes = [];
|
|
824
|
-
for (const [propKey, propValue] of propsEntries) {
|
|
825
|
-
if (is.equ(propValue, instance[propKey]))
|
|
826
|
-
continue;
|
|
827
|
-
changes.push([propKey, propValue]);
|
|
828
|
-
}
|
|
829
|
-
return changes;
|
|
830
|
-
}
|
|
831
|
-
function applyProps(instance, props) {
|
|
832
|
-
// if props is empty
|
|
833
|
-
if (!Object.keys(props).length)
|
|
834
|
-
return instance;
|
|
835
|
-
// filter equals, events , and reserved props
|
|
836
|
-
const localState = getLocalState(instance);
|
|
837
|
-
const rootState = localState.store?.get();
|
|
838
|
-
const changes = diffProps(instance, props);
|
|
839
|
-
for (let i = 0; i < changes.length; i++) {
|
|
840
|
-
let key = changes[i][0];
|
|
841
|
-
const currentInstance = instance;
|
|
842
|
-
const targetProp = currentInstance[key];
|
|
843
|
-
let value = changes[i][1];
|
|
844
|
-
if (is.colorSpaceExist(currentInstance)) {
|
|
845
|
-
const sRGBEncoding = 3001;
|
|
846
|
-
const SRGBColorSpace = 'srgb';
|
|
847
|
-
const LinearSRGBColorSpace = 'srgb-linear';
|
|
848
|
-
if (key === 'encoding') {
|
|
849
|
-
key = 'colorSpace';
|
|
850
|
-
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
851
|
-
}
|
|
852
|
-
else if (key === 'outputEncoding') {
|
|
853
|
-
key = 'outputColorSpace';
|
|
854
|
-
value = value === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
1134
|
+
function handleRaycast(obj) {
|
|
1135
|
+
const objLocalState = getLocalState(obj);
|
|
1136
|
+
const objStore = objLocalState.store;
|
|
1137
|
+
const objState = objStore?.get();
|
|
1138
|
+
// Skip event handling when noEvents is set, or when the raycasters camera is null
|
|
1139
|
+
if (!objState || !objState.events.enabled || objState.raycaster.camera === null)
|
|
1140
|
+
return [];
|
|
1141
|
+
// When the camera is undefined we have to call the event layers update function
|
|
1142
|
+
if (objState.raycaster.camera === undefined) {
|
|
1143
|
+
objState.events.compute?.(event, objStore, objState.previousRoot);
|
|
1144
|
+
// If the camera is still undefined we have to skip this layer entirely
|
|
1145
|
+
if (objState.raycaster.camera === undefined)
|
|
1146
|
+
objState.raycaster.camera = null;
|
|
855
1147
|
}
|
|
1148
|
+
// Intersect object by object
|
|
1149
|
+
return objState.raycaster.camera ? objState.raycaster.intersectObject(obj, true) : [];
|
|
856
1150
|
}
|
|
857
|
-
//
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1151
|
+
// Collect events
|
|
1152
|
+
let hits = eventsObjects
|
|
1153
|
+
// Intersect objects
|
|
1154
|
+
.flatMap(handleRaycast)
|
|
1155
|
+
// Sort by event priority and distance
|
|
1156
|
+
.sort((a, b) => {
|
|
1157
|
+
const aState = getLocalState(a.object).store.get();
|
|
1158
|
+
const bState = getLocalState(b.object).store.get();
|
|
1159
|
+
if (!aState || !bState)
|
|
1160
|
+
return a.distance - b.distance;
|
|
1161
|
+
return bState.events.priority - aState.events.priority || a.distance - b.distance;
|
|
1162
|
+
})
|
|
1163
|
+
// Filter out duplicates
|
|
1164
|
+
.filter((item) => {
|
|
1165
|
+
const id = makeId(item);
|
|
1166
|
+
if (duplicates.has(id))
|
|
1167
|
+
return false;
|
|
1168
|
+
duplicates.add(id);
|
|
1169
|
+
return true;
|
|
1170
|
+
});
|
|
1171
|
+
// https://github.com/mrdoob/three.js/issues/16031
|
|
1172
|
+
// Allow custom userland intersect sort order, this likely only makes sense on the root filter
|
|
1173
|
+
if (state.events.filter)
|
|
1174
|
+
hits = state.events.filter(hits, store);
|
|
1175
|
+
// Bubble up the events, find the event source (eventObject)
|
|
1176
|
+
for (const hit of hits) {
|
|
1177
|
+
let eventObject = hit.object;
|
|
1178
|
+
// bubble event up
|
|
1179
|
+
while (eventObject) {
|
|
1180
|
+
if (getLocalState(eventObject).eventCount) {
|
|
1181
|
+
intersections.push({ ...hit, eventObject });
|
|
1182
|
+
}
|
|
1183
|
+
eventObject = eventObject.parent;
|
|
866
1184
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (!THREE.ColorManagement && !rootState.linear && isColor)
|
|
874
|
-
targetProp['convertSRGBToLinear']();
|
|
1185
|
+
}
|
|
1186
|
+
// If the interaction is captured, make all capturing targets part of the intersect.
|
|
1187
|
+
if ('pointerId' in event && state.internal.capturedMap.has(event.pointerId)) {
|
|
1188
|
+
for (let captureData of state.internal.capturedMap.get(event.pointerId).values()) {
|
|
1189
|
+
if (!duplicates.has(makeId(captureData.intersection)))
|
|
1190
|
+
intersections.push(captureData.intersection);
|
|
875
1191
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1192
|
+
}
|
|
1193
|
+
return intersections;
|
|
1194
|
+
}
|
|
1195
|
+
/** Handles intersections by forwarding them to handlers */
|
|
1196
|
+
function handleIntersects(intersections, event, delta, callback) {
|
|
1197
|
+
const rootState = store.get();
|
|
1198
|
+
// If anything has been found, forward it to the event listeners
|
|
1199
|
+
if (intersections.length) {
|
|
1200
|
+
const localState = { stopped: false };
|
|
1201
|
+
for (const hit of intersections) {
|
|
1202
|
+
const state = getLocalState(hit.object).store?.get() || rootState;
|
|
1203
|
+
const { raycaster, pointer, camera, internal } = state;
|
|
1204
|
+
const unprojectedPoint = new THREE.Vector3(pointer.x, pointer.y, 0).unproject(camera);
|
|
1205
|
+
const hasPointerCapture = (id) => internal.capturedMap.get(id)?.has(hit.eventObject) ?? false;
|
|
1206
|
+
const setPointerCapture = (id) => {
|
|
1207
|
+
const captureData = { intersection: hit, target: event.target };
|
|
1208
|
+
if (internal.capturedMap.has(id)) {
|
|
1209
|
+
// if the pointerId was previously captured, we add the hit to the
|
|
1210
|
+
// event capturedMap.
|
|
1211
|
+
internal.capturedMap.get(id).set(hit.eventObject, captureData);
|
|
1212
|
+
}
|
|
1213
|
+
else {
|
|
1214
|
+
// if the pointerId was not previously captured, we create a map
|
|
1215
|
+
// containing the hitObject, and the hit. hitObject is used for
|
|
1216
|
+
// faster access.
|
|
1217
|
+
internal.capturedMap.set(id, new Map([[hit.eventObject, captureData]]));
|
|
1218
|
+
}
|
|
1219
|
+
// Call the original event now
|
|
1220
|
+
event.target.setPointerCapture(id);
|
|
1221
|
+
};
|
|
1222
|
+
const releasePointerCapture = (id) => {
|
|
1223
|
+
const captures = internal.capturedMap.get(id);
|
|
1224
|
+
if (captures) {
|
|
1225
|
+
releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
// Add native event props
|
|
1229
|
+
const extractEventProps = {};
|
|
1230
|
+
// This iterates over the event's properties including the inherited ones. Native PointerEvents have most of their props as getters which are inherited, but polyfilled PointerEvents have them all as their own properties (i.e. not inherited). We can't use Object.keys() or Object.entries() as they only return "own" properties; nor Object.getPrototypeOf(event) as that *doesn't* return "own" properties, only inherited ones.
|
|
1231
|
+
for (let prop in event) {
|
|
1232
|
+
let property = event[prop];
|
|
1233
|
+
// Only copy over atomics, leave functions alone as these should be
|
|
1234
|
+
// called as event.nativeEvent.fn()
|
|
1235
|
+
if (typeof property !== 'function')
|
|
1236
|
+
extractEventProps[prop] = property;
|
|
1237
|
+
}
|
|
1238
|
+
const raycastEvent = {
|
|
1239
|
+
...hit,
|
|
1240
|
+
...extractEventProps,
|
|
1241
|
+
pointer,
|
|
1242
|
+
intersections,
|
|
1243
|
+
stopped: localState.stopped,
|
|
1244
|
+
delta,
|
|
1245
|
+
unprojectedPoint,
|
|
1246
|
+
ray: raycaster.ray,
|
|
1247
|
+
camera,
|
|
1248
|
+
// Hijack stopPropagation, which just sets a flag
|
|
1249
|
+
stopPropagation() {
|
|
1250
|
+
// https://github.com/pmndrs/react-three-fiber/issues/596
|
|
1251
|
+
// Events are not allowed to stop propagation if the pointer has been captured
|
|
1252
|
+
const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId);
|
|
1253
|
+
// We only authorize stopPropagation...
|
|
1254
|
+
if (
|
|
1255
|
+
// ...if this pointer hasn't been captured
|
|
1256
|
+
!capturesForPointer ||
|
|
1257
|
+
// ... or if the hit object is capturing the pointer
|
|
1258
|
+
capturesForPointer.has(hit.eventObject)) {
|
|
1259
|
+
raycastEvent.stopped = localState.stopped = true;
|
|
1260
|
+
// Propagation is stopped, remove all other hover records
|
|
1261
|
+
// An event handler is only allowed to flush other handlers if it is hovered itself
|
|
1262
|
+
if (internal.hovered.size &&
|
|
1263
|
+
Array.from(internal.hovered.values()).find((i) => i.eventObject === hit.eventObject)) {
|
|
1264
|
+
// Objects cannot flush out higher up objects that have already caught the event
|
|
1265
|
+
const higher = intersections.slice(0, intersections.indexOf(hit));
|
|
1266
|
+
cancelPointer([...higher, hit]);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
// there should be a distinction between target and currentTarget
|
|
1271
|
+
target: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1272
|
+
currentTarget: { hasPointerCapture, setPointerCapture, releasePointerCapture },
|
|
1273
|
+
nativeEvent: event,
|
|
1274
|
+
};
|
|
1275
|
+
// Call subscribers
|
|
1276
|
+
callback(raycastEvent);
|
|
1277
|
+
// Event bubbling may be interrupted by stopPropagation
|
|
1278
|
+
if (localState.stopped === true)
|
|
1279
|
+
break;
|
|
891
1280
|
}
|
|
892
1281
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1282
|
+
return intersections;
|
|
1283
|
+
}
|
|
1284
|
+
function cancelPointer(intersections) {
|
|
1285
|
+
const internal = store.get('internal');
|
|
1286
|
+
for (const hoveredObj of internal.hovered.values()) {
|
|
1287
|
+
// When no objects were hit or the the hovered object wasn't found underneath the cursor
|
|
1288
|
+
// we call onPointerOut and delete the object from the hovered-elements map
|
|
1289
|
+
if (!intersections.length ||
|
|
1290
|
+
!intersections.find((hit) => hit.object === hoveredObj.object &&
|
|
1291
|
+
hit.index === hoveredObj.index &&
|
|
1292
|
+
hit.instanceId === hoveredObj.instanceId)) {
|
|
1293
|
+
const eventObject = hoveredObj.eventObject;
|
|
1294
|
+
const instance = getLocalState(eventObject);
|
|
1295
|
+
const handlers = instance?.handlers;
|
|
1296
|
+
internal.hovered.delete(makeId(hoveredObj));
|
|
1297
|
+
if (instance?.eventCount) {
|
|
1298
|
+
// Clear out intersects, they are outdated by now
|
|
1299
|
+
const data = { ...hoveredObj, intersections };
|
|
1300
|
+
handlers?.pointerout?.(data);
|
|
1301
|
+
handlers?.pointerleave?.(data);
|
|
1302
|
+
}
|
|
905
1303
|
}
|
|
906
1304
|
}
|
|
907
|
-
checkUpdate(targetProp);
|
|
908
|
-
invalidateInstance(instance);
|
|
909
1305
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
if (index > -1)
|
|
916
|
-
rootState.internal.interaction.splice(index, 1);
|
|
917
|
-
// Add the instance to the interaction manager only when it has handlers
|
|
918
|
-
if (localState.eventCount)
|
|
919
|
-
rootState.internal.interaction.push(instance);
|
|
1306
|
+
function pointerMissed(event, objects) {
|
|
1307
|
+
for (let i = 0; i < objects.length; i++) {
|
|
1308
|
+
const instance = getLocalState(objects[i]);
|
|
1309
|
+
instance?.handlers.pointermissed?.(event);
|
|
1310
|
+
}
|
|
920
1311
|
}
|
|
921
|
-
|
|
922
|
-
|
|
1312
|
+
function handlePointer(name) {
|
|
1313
|
+
// Deal with cancelation
|
|
1314
|
+
switch (name) {
|
|
1315
|
+
case 'pointerleave':
|
|
1316
|
+
case 'pointercancel':
|
|
1317
|
+
return () => cancelPointer([]);
|
|
1318
|
+
case 'lostpointercapture':
|
|
1319
|
+
return (event) => {
|
|
1320
|
+
const { internal } = store.get();
|
|
1321
|
+
if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
|
|
1322
|
+
// If the object event interface had onLostPointerCapture, we'd call it here on every
|
|
1323
|
+
// object that's getting removed.
|
|
1324
|
+
internal.capturedMap.delete(event.pointerId);
|
|
1325
|
+
cancelPointer([]);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
// Any other pointer goes here ...
|
|
1330
|
+
return function handleEvent(event) {
|
|
1331
|
+
const pointerMissed$ = store['pointerMissed$'];
|
|
1332
|
+
const internal = store.get('internal');
|
|
1333
|
+
// prepareRay(event)
|
|
1334
|
+
internal.lastEvent.nativeElement = event;
|
|
1335
|
+
// Get fresh intersects
|
|
1336
|
+
const isPointerMove = name === 'pointermove';
|
|
1337
|
+
const isClickEvent = name === 'click' || name === 'contextmenu' || name === 'dblclick';
|
|
1338
|
+
const filter = isPointerMove ? filterPointerEvents : undefined;
|
|
1339
|
+
const hits = intersect(event, filter);
|
|
1340
|
+
const delta = isClickEvent ? calculateDistance(event) : 0;
|
|
1341
|
+
// Save initial coordinates on pointer-down
|
|
1342
|
+
if (name === 'pointerdown') {
|
|
1343
|
+
internal.initialClick = [event.offsetX, event.offsetY];
|
|
1344
|
+
internal.initialHits = hits.map((hit) => hit.eventObject);
|
|
1345
|
+
}
|
|
1346
|
+
// If a click yields no results, pass it back to the user as a miss
|
|
1347
|
+
// Missed events have to come first in order to establish user-land side-effect clean up
|
|
1348
|
+
if (isClickEvent && !hits.length) {
|
|
1349
|
+
if (delta <= 2) {
|
|
1350
|
+
pointerMissed(event, internal.interaction);
|
|
1351
|
+
pointerMissed$.next(event);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
// Take care of unhover
|
|
1355
|
+
if (isPointerMove)
|
|
1356
|
+
cancelPointer(hits);
|
|
1357
|
+
function onIntersect(data) {
|
|
1358
|
+
const eventObject = data.eventObject;
|
|
1359
|
+
const instance = getLocalState(eventObject);
|
|
1360
|
+
const handlers = instance?.handlers;
|
|
1361
|
+
// Check presence of handlers
|
|
1362
|
+
if (!instance?.eventCount)
|
|
1363
|
+
return;
|
|
1364
|
+
/*
|
|
1365
|
+
MAYBE TODO, DELETE IF NOT:
|
|
1366
|
+
Check if the object is captured, captured events should not have intersects running in parallel
|
|
1367
|
+
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
1368
|
+
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
1369
|
+
|
|
1370
|
+
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
1371
|
+
if (pointerId !== undefined) {
|
|
1372
|
+
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
1373
|
+
if (capturedMeshSet) {
|
|
1374
|
+
const captured = capturedMeshSet.get(eventObject)
|
|
1375
|
+
if (captured && captured.localState.stopped) return
|
|
1376
|
+
}
|
|
1377
|
+
}*/
|
|
1378
|
+
if (isPointerMove) {
|
|
1379
|
+
// Move event ...
|
|
1380
|
+
if (handlers?.pointerover ||
|
|
1381
|
+
handlers?.pointerenter ||
|
|
1382
|
+
handlers?.pointerout ||
|
|
1383
|
+
handlers?.pointerleave) {
|
|
1384
|
+
// When enter or out is present take care of hover-state
|
|
1385
|
+
const id = makeId(data);
|
|
1386
|
+
const hoveredItem = internal.hovered.get(id);
|
|
1387
|
+
if (!hoveredItem) {
|
|
1388
|
+
// If the object wasn't previously hovered, book it and call its handler
|
|
1389
|
+
internal.hovered.set(id, data);
|
|
1390
|
+
handlers.pointerover?.(data);
|
|
1391
|
+
handlers.pointerenter?.(data);
|
|
1392
|
+
}
|
|
1393
|
+
else if (hoveredItem.stopped) {
|
|
1394
|
+
// If the object was previously hovered and stopped, we shouldn't allow other items to proceed
|
|
1395
|
+
data.stopPropagation();
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
// Call mouse move
|
|
1399
|
+
handlers?.pointermove?.(data);
|
|
1400
|
+
}
|
|
1401
|
+
else {
|
|
1402
|
+
// All other events ...
|
|
1403
|
+
const handler = handlers?.[name];
|
|
1404
|
+
if (handler) {
|
|
1405
|
+
// Forward all events back to their respective handlers with the exception of click events,
|
|
1406
|
+
// which must use the initial target
|
|
1407
|
+
if (!isClickEvent || internal.initialHits.includes(eventObject)) {
|
|
1408
|
+
// Missed events have to come first
|
|
1409
|
+
pointerMissed(event, internal.interaction.filter((object) => !internal.initialHits.includes(object)));
|
|
1410
|
+
// Now call the handler
|
|
1411
|
+
handler(data);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
else {
|
|
1415
|
+
// Trigger onPointerMissed on all elements that have pointer over/out handlers, but not click and weren't hit
|
|
1416
|
+
if (isClickEvent && internal.initialHits.includes(eventObject)) {
|
|
1417
|
+
pointerMissed(event, internal.interaction.filter((object) => !internal.initialHits.includes(object)));
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
handleIntersects(hits, event, delta, onIntersect);
|
|
1423
|
+
};
|
|
923
1424
|
}
|
|
924
|
-
return
|
|
1425
|
+
return { handlePointer };
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
const DOM_EVENTS = {
|
|
1429
|
+
click: false,
|
|
1430
|
+
contextmenu: false,
|
|
1431
|
+
dblclick: false,
|
|
1432
|
+
wheel: false,
|
|
1433
|
+
pointerdown: true,
|
|
1434
|
+
pointerup: true,
|
|
1435
|
+
pointerleave: true,
|
|
1436
|
+
pointermove: true,
|
|
1437
|
+
pointercancel: true,
|
|
1438
|
+
lostpointercapture: true,
|
|
1439
|
+
};
|
|
1440
|
+
const supportedEvents = [
|
|
1441
|
+
'click',
|
|
1442
|
+
'contextmenu',
|
|
1443
|
+
'dblclick',
|
|
1444
|
+
'pointerup',
|
|
1445
|
+
'pointerdown',
|
|
1446
|
+
'pointerover',
|
|
1447
|
+
'pointerout',
|
|
1448
|
+
'pointerenter',
|
|
1449
|
+
'pointerleave',
|
|
1450
|
+
'pointermove',
|
|
1451
|
+
'pointermissed',
|
|
1452
|
+
'pointercancel',
|
|
1453
|
+
'wheel',
|
|
1454
|
+
];
|
|
1455
|
+
function createPointerEvents(store) {
|
|
1456
|
+
const { handlePointer } = createEvents(store);
|
|
1457
|
+
return {
|
|
1458
|
+
priority: 1,
|
|
1459
|
+
enabled: true,
|
|
1460
|
+
compute: (event, root) => {
|
|
1461
|
+
const state = root.get();
|
|
1462
|
+
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
1463
|
+
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
1464
|
+
state.pointer.set((event.offsetX / state.size.width) * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
1465
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
1466
|
+
},
|
|
1467
|
+
connected: undefined,
|
|
1468
|
+
handlers: Object.keys(DOM_EVENTS).reduce((handlers, supportedEventName) => {
|
|
1469
|
+
handlers[supportedEventName] = handlePointer(supportedEventName);
|
|
1470
|
+
return handlers;
|
|
1471
|
+
}, {}),
|
|
1472
|
+
update: () => {
|
|
1473
|
+
const { events, internal } = store.get();
|
|
1474
|
+
if (internal.lastEvent?.nativeElement && events.handlers)
|
|
1475
|
+
events.handlers.pointermove(internal.lastEvent.nativeElement);
|
|
1476
|
+
},
|
|
1477
|
+
connect: (target) => {
|
|
1478
|
+
const state = store.get();
|
|
1479
|
+
state.events.disconnect?.();
|
|
1480
|
+
state.setEvents({ connected: target });
|
|
1481
|
+
Object.entries(state.events.handlers ?? {}).forEach(([eventName, eventHandler]) => {
|
|
1482
|
+
const passive = DOM_EVENTS[eventName];
|
|
1483
|
+
target.addEventListener(eventName, eventHandler, { passive });
|
|
1484
|
+
});
|
|
1485
|
+
},
|
|
1486
|
+
disconnect: () => {
|
|
1487
|
+
const { events, setEvents } = store.get();
|
|
1488
|
+
if (events.connected) {
|
|
1489
|
+
Object.entries(events.handlers ?? {}).forEach(([eventName, eventHandler]) => {
|
|
1490
|
+
if (events.connected instanceof HTMLElement) {
|
|
1491
|
+
events.connected.removeEventListener(eventName, eventHandler);
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
setEvents({ connected: undefined });
|
|
1495
|
+
}
|
|
1496
|
+
},
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const cached = new Map();
|
|
1501
|
+
function normalizeInputs(input) {
|
|
1502
|
+
if (Array.isArray(input))
|
|
1503
|
+
return input;
|
|
1504
|
+
if (typeof input === 'string')
|
|
1505
|
+
return [input];
|
|
1506
|
+
return Object.values(input);
|
|
925
1507
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
if (!this.#computedCache.has(joinedKeys)) {
|
|
947
|
-
this.#computedCache.set(joinedKeys, computed(() => {
|
|
948
|
-
const state = this.#state();
|
|
949
|
-
return keys.reduce((value, key) => value[key], state);
|
|
950
|
-
}, options));
|
|
951
|
-
}
|
|
952
|
-
return this.#computedCache.get(joinedKeys);
|
|
953
|
-
}
|
|
954
|
-
get(...keys) {
|
|
955
|
-
const state = untracked(this.#state);
|
|
956
|
-
if (keys.length === 0)
|
|
957
|
-
return state;
|
|
958
|
-
return keys.reduce((value, key) => value[key], state);
|
|
959
|
-
}
|
|
960
|
-
set(state) {
|
|
961
|
-
this.#state.update((previous) => ({
|
|
962
|
-
...previous,
|
|
963
|
-
...(typeof state === 'function' ? state(previous) : state),
|
|
964
|
-
}));
|
|
965
|
-
}
|
|
966
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtSignalStore, deps: [{ token: 'INITIAL_STATE', optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
967
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtSignalStore }); }
|
|
1508
|
+
function load(loaderConstructorFactory, inputs, { extensions, onProgress, } = {}) {
|
|
1509
|
+
return () => {
|
|
1510
|
+
const urls = normalizeInputs(inputs());
|
|
1511
|
+
const loader = new (loaderConstructorFactory(urls))();
|
|
1512
|
+
if (extensions)
|
|
1513
|
+
extensions(loader);
|
|
1514
|
+
// TODO: reevaluate this
|
|
1515
|
+
return urls.map((url) => {
|
|
1516
|
+
if (!cached.has(url)) {
|
|
1517
|
+
cached.set(url, new Promise((resolve, reject) => {
|
|
1518
|
+
loader.load(url, (data) => {
|
|
1519
|
+
if ('scene' in data)
|
|
1520
|
+
Object.assign(data, makeObjectGraph(data['scene']));
|
|
1521
|
+
resolve(data);
|
|
1522
|
+
}, onProgress, (error) => reject(new Error(`[NGT] Could not load ${url}: ${error}`)));
|
|
1523
|
+
}));
|
|
1524
|
+
}
|
|
1525
|
+
return cached.get(url);
|
|
1526
|
+
});
|
|
1527
|
+
};
|
|
968
1528
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1529
|
+
function injectNgtLoader(loaderConstructorFactory, inputs, { extensions, onProgress, injector, } = {}) {
|
|
1530
|
+
injector = assertInjectionContext(injectNgtLoader, injector);
|
|
1531
|
+
const response = signal(null);
|
|
1532
|
+
return runInInjectionContext(injector, () => {
|
|
1533
|
+
const cdr = inject(ChangeDetectorRef);
|
|
1534
|
+
const effector = load(loaderConstructorFactory, inputs, { extensions, onProgress });
|
|
1535
|
+
effect(() => {
|
|
1536
|
+
const originalUrls = inputs();
|
|
1537
|
+
Promise.all(effector()).then((results) => {
|
|
1538
|
+
response.update(() => {
|
|
1539
|
+
if (Array.isArray(originalUrls))
|
|
1540
|
+
return results;
|
|
1541
|
+
if (typeof originalUrls === 'string')
|
|
1542
|
+
return results[0];
|
|
1543
|
+
const keys = Object.keys(originalUrls);
|
|
1544
|
+
return keys.reduce((result, key) => {
|
|
1545
|
+
result[key] = results[keys.indexOf(key)];
|
|
1546
|
+
return result;
|
|
1547
|
+
}, {});
|
|
1548
|
+
});
|
|
1549
|
+
safeDetectChanges(cdr);
|
|
1550
|
+
});
|
|
1551
|
+
});
|
|
1552
|
+
return response.asReadonly();
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
injectNgtLoader['preload'] = (loaderConstructorFactory, inputs, extensions) => {
|
|
1556
|
+
Promise.all(load(loaderConstructorFactory, inputs, { extensions })());
|
|
1557
|
+
};
|
|
1558
|
+
injectNgtLoader['destroy'] = () => {
|
|
1559
|
+
cached.clear();
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
const catalogue = {};
|
|
1563
|
+
function extend(objects) {
|
|
1564
|
+
Object.assign(catalogue, objects);
|
|
982
1565
|
}
|
|
1566
|
+
const [injectNgtCatalogue] = createInjectionToken(() => catalogue);
|
|
983
1567
|
|
|
984
|
-
const
|
|
985
|
-
const
|
|
986
|
-
const
|
|
987
|
-
|
|
1568
|
+
const ROUTED_SCENE = '__ngt_renderer_is_routed_scene__';
|
|
1569
|
+
const HTML = '__ngt_renderer_is_html';
|
|
1570
|
+
const SPECIAL_INTERNAL_ADD_COMMENT = '__ngt_renderer_add_comment__';
|
|
1571
|
+
const SPECIAL_DOM_TAG = {
|
|
1572
|
+
NGT_PORTAL: 'ngt-portal',
|
|
1573
|
+
NGT_PRIMITIVE: 'ngt-primitive',
|
|
1574
|
+
NGT_VALUE: 'ngt-value',
|
|
1575
|
+
};
|
|
1576
|
+
const SPECIAL_PROPERTIES = {
|
|
1577
|
+
COMPOUND: 'ngtCompound',
|
|
1578
|
+
RENDER_PRIORITY: 'priority',
|
|
1579
|
+
ATTACH: 'attach',
|
|
1580
|
+
VALUE: 'rawValue',
|
|
1581
|
+
REF: 'ref',
|
|
1582
|
+
};
|
|
1583
|
+
const SPECIAL_EVENTS = {
|
|
1584
|
+
BEFORE_RENDER: 'beforeRender',
|
|
1585
|
+
AFTER_UPDATE: 'afterUpdate',
|
|
1586
|
+
AFTER_ATTACH: 'afterAttach',
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
class NgtCommonDirective {
|
|
1590
|
+
static { this.processComment = true; }
|
|
988
1591
|
constructor() {
|
|
989
|
-
|
|
990
|
-
this
|
|
991
|
-
this
|
|
992
|
-
this
|
|
993
|
-
this.
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (!this.isInit) {
|
|
1000
|
-
const position = new THREE.Vector3();
|
|
1001
|
-
const defaultTarget = new THREE.Vector3();
|
|
1002
|
-
const tempTarget = new THREE.Vector3();
|
|
1003
|
-
const getCurrentViewport = (camera = this.get('camera'), target = defaultTarget, size = this.get('size')) => {
|
|
1004
|
-
const { width, height, top, left } = size;
|
|
1005
|
-
const aspect = width / height;
|
|
1006
|
-
if (target instanceof THREE.Vector3)
|
|
1007
|
-
tempTarget.copy(target);
|
|
1008
|
-
else
|
|
1009
|
-
tempTarget.set(...target);
|
|
1010
|
-
const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
|
|
1011
|
-
if (is.orthographicCamera(camera)) {
|
|
1012
|
-
return {
|
|
1013
|
-
width: width / camera.zoom,
|
|
1014
|
-
height: height / camera.zoom,
|
|
1015
|
-
top,
|
|
1016
|
-
left,
|
|
1017
|
-
factor: 1,
|
|
1018
|
-
distance,
|
|
1019
|
-
aspect,
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
const fov = (camera.fov * Math.PI) / 180; // convert vertical fov to radians
|
|
1023
|
-
const h = 2 * Math.tan(fov / 2) * distance; // visible height
|
|
1024
|
-
const w = h * aspect;
|
|
1025
|
-
return { width: w, height: h, top, left, factor: width / w, distance, aspect };
|
|
1026
|
-
};
|
|
1027
|
-
let performanceTimeout;
|
|
1028
|
-
const setPerformanceCurrent = (current) => {
|
|
1029
|
-
this.set((state) => ({ performance: { ...state.performance, current } }));
|
|
1030
|
-
};
|
|
1031
|
-
this.set({
|
|
1032
|
-
get: this.get.bind(this),
|
|
1033
|
-
set: this.set.bind(this),
|
|
1034
|
-
ready: false,
|
|
1035
|
-
events: { priority: 1, enabled: true, connected: false },
|
|
1036
|
-
invalidate: (frames = 1) => invalidate(this, frames),
|
|
1037
|
-
advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, this),
|
|
1038
|
-
legacy: false,
|
|
1039
|
-
linear: false,
|
|
1040
|
-
flat: false,
|
|
1041
|
-
controls: null,
|
|
1042
|
-
clock: new THREE.Clock(),
|
|
1043
|
-
pointer: new THREE.Vector2(),
|
|
1044
|
-
frameloop: 'always',
|
|
1045
|
-
performance: {
|
|
1046
|
-
current: 1,
|
|
1047
|
-
min: 0.5,
|
|
1048
|
-
max: 1,
|
|
1049
|
-
debounce: 200,
|
|
1050
|
-
regress: () => {
|
|
1051
|
-
const state = this.get();
|
|
1052
|
-
// clear timeout
|
|
1053
|
-
if (performanceTimeout)
|
|
1054
|
-
clearTimeout(performanceTimeout);
|
|
1055
|
-
// set lower bound
|
|
1056
|
-
if (state.performance.current !== state.performance.min)
|
|
1057
|
-
setPerformanceCurrent(state.performance.min);
|
|
1058
|
-
// go back to upper bound
|
|
1059
|
-
performanceTimeout = setTimeout(() => setPerformanceCurrent(this.get('performance', 'max') || 1), state.performance.debounce);
|
|
1060
|
-
},
|
|
1061
|
-
},
|
|
1062
|
-
size: { width: 0, height: 0, top: 0, left: 0 },
|
|
1063
|
-
viewport: {
|
|
1064
|
-
initialDpr: 0,
|
|
1065
|
-
dpr: 0,
|
|
1066
|
-
width: 0,
|
|
1067
|
-
height: 0,
|
|
1068
|
-
top: 0,
|
|
1069
|
-
left: 0,
|
|
1070
|
-
aspect: 0,
|
|
1071
|
-
distance: 0,
|
|
1072
|
-
factor: 0,
|
|
1073
|
-
getCurrentViewport,
|
|
1074
|
-
},
|
|
1075
|
-
previousStore: this.#parentStore,
|
|
1076
|
-
internal: {
|
|
1077
|
-
active: false,
|
|
1078
|
-
priority: 0,
|
|
1079
|
-
frames: 0,
|
|
1080
|
-
lastEvent: new ElementRef(null),
|
|
1081
|
-
interaction: [],
|
|
1082
|
-
hovered: new Map(),
|
|
1083
|
-
subscribers: [],
|
|
1084
|
-
initialClick: [0, 0],
|
|
1085
|
-
initialHits: [],
|
|
1086
|
-
capturedMap: new Map(),
|
|
1087
|
-
subscribe: (callback, priority = 0, store = this) => {
|
|
1088
|
-
const internal = this.get('internal');
|
|
1089
|
-
// If this subscription was given a priority, it takes rendering into its own hands
|
|
1090
|
-
// For that reason we switch off automatic rendering and increase the manual flag
|
|
1091
|
-
// As long as this flag is positive there can be no internal rendering at all
|
|
1092
|
-
// because there could be multiple render subscriptions
|
|
1093
|
-
internal.priority = internal.priority + (priority > 0 ? 1 : 0);
|
|
1094
|
-
internal.subscribers.push({ priority, store, callback });
|
|
1095
|
-
// Register subscriber and sort layers from lowest to highest, meaning,
|
|
1096
|
-
// highest priority renders last (on top of the other frames)
|
|
1097
|
-
internal.subscribers.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
1098
|
-
return () => {
|
|
1099
|
-
const internal = this.get('internal');
|
|
1100
|
-
if (internal?.subscribers) {
|
|
1101
|
-
// Decrease manual flag if this subscription had a priority
|
|
1102
|
-
internal.priority = internal.priority - (priority > 0 ? 1 : 0);
|
|
1103
|
-
// Remove subscriber from list
|
|
1104
|
-
internal.subscribers = internal.subscribers.filter((s) => s.callback !== callback);
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
},
|
|
1108
|
-
},
|
|
1109
|
-
setEvents: (events) => {
|
|
1110
|
-
this.set((state) => ({ events: { ...state.events, ...events } }));
|
|
1111
|
-
},
|
|
1112
|
-
setSize: (width, height, top, left) => {
|
|
1113
|
-
const camera = this.get('camera');
|
|
1114
|
-
const size = { width, height, top: top || 0, left: left || 0 };
|
|
1115
|
-
this.set((state) => ({
|
|
1116
|
-
size,
|
|
1117
|
-
viewport: { ...state.viewport, ...getCurrentViewport(camera, defaultTarget, size) },
|
|
1118
|
-
}));
|
|
1119
|
-
},
|
|
1120
|
-
setDpr: (dpr) => {
|
|
1121
|
-
const resolved = makeDpr(dpr, this.#window);
|
|
1122
|
-
this.set((state) => ({
|
|
1123
|
-
viewport: {
|
|
1124
|
-
...state.viewport,
|
|
1125
|
-
dpr: resolved,
|
|
1126
|
-
initialDpr: state.viewport.initialDpr || resolved,
|
|
1127
|
-
},
|
|
1128
|
-
}));
|
|
1129
|
-
},
|
|
1130
|
-
setFrameloop: (frameloop = 'always') => {
|
|
1131
|
-
const clock = this.get('clock');
|
|
1132
|
-
clock.stop();
|
|
1133
|
-
clock.elapsedTime = 0;
|
|
1134
|
-
if (frameloop !== 'never') {
|
|
1135
|
-
clock.start();
|
|
1136
|
-
clock.elapsedTime = 0;
|
|
1137
|
-
}
|
|
1138
|
-
this.set({ frameloop });
|
|
1139
|
-
},
|
|
1140
|
-
});
|
|
1141
|
-
this.isInit = true;
|
|
1142
|
-
this.#resize();
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
configure(inputs, canvasElement) {
|
|
1146
|
-
const { gl: glOptions, size: sizeOptions, camera: cameraOptions, raycaster: raycasterOptions, scene: sceneOptions, events, orthographic, lookAt, shadows, linear, legacy, flat, dpr, frameloop, performance, } = inputs;
|
|
1147
|
-
const state = this.get();
|
|
1148
|
-
const stateToUpdate = {};
|
|
1149
|
-
// setup renderer
|
|
1150
|
-
let gl = state.gl;
|
|
1151
|
-
if (!state.gl)
|
|
1152
|
-
stateToUpdate.gl = gl = makeDefaultRenderer(glOptions, canvasElement);
|
|
1153
|
-
// setup raycaster
|
|
1154
|
-
let raycaster = state.raycaster;
|
|
1155
|
-
if (!raycaster)
|
|
1156
|
-
stateToUpdate.raycaster = raycaster = new THREE.Raycaster();
|
|
1157
|
-
// set raycaster options
|
|
1158
|
-
const { params, ...options } = raycasterOptions || {};
|
|
1159
|
-
if (!is.equ(options, raycaster, shallowLoose))
|
|
1160
|
-
applyProps(raycaster, { ...options });
|
|
1161
|
-
if (!is.equ(params, raycaster.params, shallowLoose)) {
|
|
1162
|
-
applyProps(raycaster, { params: { ...raycaster.params, ...(params || {}) } });
|
|
1163
|
-
}
|
|
1164
|
-
// create default camera
|
|
1165
|
-
if (!state.camera) {
|
|
1166
|
-
const isCamera = is.camera(cameraOptions);
|
|
1167
|
-
let camera = isCamera ? cameraOptions : makeDefaultCamera(orthographic || false, state.size);
|
|
1168
|
-
if (!isCamera) {
|
|
1169
|
-
if (cameraOptions)
|
|
1170
|
-
applyProps(camera, cameraOptions);
|
|
1171
|
-
// set position.z
|
|
1172
|
-
if (!cameraOptions?.position)
|
|
1173
|
-
camera.position.z = 5;
|
|
1174
|
-
// always look at center or passed-in lookAt by default
|
|
1175
|
-
if (!cameraOptions?.rotation && !cameraOptions?.quaternion) {
|
|
1176
|
-
if (Array.isArray(lookAt))
|
|
1177
|
-
camera.lookAt(lookAt[0], lookAt[1], lookAt[2]);
|
|
1178
|
-
else if (lookAt instanceof THREE.Vector3)
|
|
1179
|
-
camera.lookAt(lookAt);
|
|
1180
|
-
else
|
|
1181
|
-
camera.lookAt(0, 0, 0);
|
|
1182
|
-
}
|
|
1183
|
-
// update projection matrix after applyprops
|
|
1184
|
-
camera.updateProjectionMatrix?.();
|
|
1592
|
+
this.vcr = inject(ViewContainerRef);
|
|
1593
|
+
this.zone = inject(NgZone);
|
|
1594
|
+
this.template = inject(TemplateRef);
|
|
1595
|
+
this.injected = false;
|
|
1596
|
+
this.shouldCreateView = true;
|
|
1597
|
+
if (NgtCommonDirective.processComment) {
|
|
1598
|
+
const commentNode = this.vcr.element.nativeElement;
|
|
1599
|
+
if (commentNode[SPECIAL_INTERNAL_ADD_COMMENT]) {
|
|
1600
|
+
commentNode[SPECIAL_INTERNAL_ADD_COMMENT]();
|
|
1601
|
+
delete commentNode[SPECIAL_INTERNAL_ADD_COMMENT];
|
|
1185
1602
|
}
|
|
1186
|
-
if (!is.instance(camera))
|
|
1187
|
-
camera = prepare(camera, { store: this });
|
|
1188
|
-
stateToUpdate.camera = camera;
|
|
1189
1603
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
let scene;
|
|
1193
|
-
if (sceneOptions instanceof THREE.Scene) {
|
|
1194
|
-
scene = prepare(sceneOptions, { store: this });
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
scene = prepare(new THREE.Scene(), { store: this });
|
|
1198
|
-
if (sceneOptions)
|
|
1199
|
-
applyProps(scene, sceneOptions);
|
|
1200
|
-
}
|
|
1201
|
-
stateToUpdate.scene = scene;
|
|
1202
|
-
}
|
|
1203
|
-
// Set up XR (one time only!)
|
|
1204
|
-
if (!state.xr) {
|
|
1205
|
-
// Handle frame behavior in WebXR
|
|
1206
|
-
const handleXRFrame = (timestamp, frame) => {
|
|
1207
|
-
const state = this.get();
|
|
1208
|
-
if (state.frameloop === 'never')
|
|
1209
|
-
return;
|
|
1210
|
-
advance(timestamp, true, this, frame);
|
|
1211
|
-
};
|
|
1212
|
-
// Toggle render switching on session
|
|
1213
|
-
const handleSessionChange = () => {
|
|
1214
|
-
const state = this.get();
|
|
1215
|
-
state.gl.xr.enabled = state.gl.xr.isPresenting;
|
|
1216
|
-
state.gl.xr.setAnimationLoop(state.gl.xr.isPresenting ? handleXRFrame : null);
|
|
1217
|
-
if (!state.gl.xr.isPresenting)
|
|
1218
|
-
state.invalidate();
|
|
1219
|
-
};
|
|
1220
|
-
// WebXR session manager
|
|
1221
|
-
const xr = {
|
|
1222
|
-
connect: () => {
|
|
1223
|
-
gl.xr.addEventListener('sessionstart', handleSessionChange);
|
|
1224
|
-
gl.xr.addEventListener('sessionend', handleSessionChange);
|
|
1225
|
-
},
|
|
1226
|
-
disconnect: () => {
|
|
1227
|
-
gl.xr.removeEventListener('sessionstart', handleSessionChange);
|
|
1228
|
-
gl.xr.removeEventListener('sessionend', handleSessionChange);
|
|
1229
|
-
},
|
|
1230
|
-
};
|
|
1231
|
-
// Subscribe to WebXR session events
|
|
1232
|
-
if (gl.xr)
|
|
1233
|
-
xr.connect();
|
|
1234
|
-
stateToUpdate.xr = xr;
|
|
1235
|
-
}
|
|
1236
|
-
// Set shadowmap
|
|
1237
|
-
if (gl.shadowMap) {
|
|
1238
|
-
const oldEnabled = gl.shadowMap.enabled;
|
|
1239
|
-
const oldType = gl.shadowMap.type;
|
|
1240
|
-
gl.shadowMap.enabled = !!shadows;
|
|
1241
|
-
if (typeof shadows === 'boolean') {
|
|
1242
|
-
gl.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
1243
|
-
}
|
|
1244
|
-
else if (typeof shadows === 'string') {
|
|
1245
|
-
const types = {
|
|
1246
|
-
basic: THREE.BasicShadowMap,
|
|
1247
|
-
percentage: THREE.PCFShadowMap,
|
|
1248
|
-
soft: THREE.PCFSoftShadowMap,
|
|
1249
|
-
variance: THREE.VSMShadowMap,
|
|
1250
|
-
};
|
|
1251
|
-
gl.shadowMap.type = types[shadows] ?? THREE.PCFSoftShadowMap;
|
|
1252
|
-
}
|
|
1253
|
-
else if (is.obj(shadows)) {
|
|
1254
|
-
Object.assign(gl.shadowMap, shadows);
|
|
1255
|
-
}
|
|
1256
|
-
if (oldEnabled !== gl.shadowMap.enabled || oldType !== gl.shadowMap.type)
|
|
1257
|
-
checkNeedsUpdate(gl.shadowMap);
|
|
1258
|
-
}
|
|
1259
|
-
// Safely set color management if available.
|
|
1260
|
-
// Avoid accessing THREE.ColorManagement to play nice with older versions
|
|
1261
|
-
if (THREE.ColorManagement) {
|
|
1262
|
-
const ColorManagement = THREE.ColorManagement;
|
|
1263
|
-
if ('enabled' in ColorManagement)
|
|
1264
|
-
ColorManagement['enabled'] = !legacy ?? false;
|
|
1265
|
-
else if ('legacyMode' in ColorManagement)
|
|
1266
|
-
ColorManagement['legacyMode'] = legacy ?? true;
|
|
1267
|
-
}
|
|
1268
|
-
// set color space and tonemapping preferences
|
|
1269
|
-
const LinearEncoding = 3000;
|
|
1270
|
-
const sRGBEncoding = 3001;
|
|
1271
|
-
applyProps(gl, {
|
|
1272
|
-
outputEncoding: linear ? LinearEncoding : sRGBEncoding,
|
|
1273
|
-
toneMapping: flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping,
|
|
1604
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1605
|
+
this.view?.destroy();
|
|
1274
1606
|
});
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
stateToUpdate.flat = flat;
|
|
1282
|
-
// Set gl props
|
|
1283
|
-
gl.setClearAlpha(0);
|
|
1284
|
-
gl.setPixelRatio(makeDpr(state.viewport.dpr));
|
|
1285
|
-
gl.setSize(state.size.width, state.size.height);
|
|
1286
|
-
if (is.obj(glOptions) &&
|
|
1287
|
-
!(typeof glOptions === 'function') &&
|
|
1288
|
-
!is.renderer(glOptions) &&
|
|
1289
|
-
!is.equ(glOptions, gl, shallowLoose)) {
|
|
1290
|
-
applyProps(gl, glOptions);
|
|
1291
|
-
}
|
|
1292
|
-
// Store events internally
|
|
1293
|
-
if (events && !state.events.handlers)
|
|
1294
|
-
stateToUpdate.events = events(this);
|
|
1295
|
-
// Check performance
|
|
1296
|
-
if (performance && !is.equ(performance, state.performance, shallowLoose)) {
|
|
1297
|
-
stateToUpdate.performance = { ...state.performance, ...performance };
|
|
1298
|
-
}
|
|
1299
|
-
this.set(stateToUpdate);
|
|
1300
|
-
// Check pixelratio
|
|
1301
|
-
if (dpr && state.viewport.dpr !== makeDpr(dpr))
|
|
1302
|
-
state.setDpr(dpr);
|
|
1303
|
-
// Check size, allow it to take on container bounds initially
|
|
1304
|
-
const size = computeInitialSize(canvasElement, sizeOptions);
|
|
1305
|
-
if (!is.equ(size, state.size, shallowLoose))
|
|
1306
|
-
state.setSize(size.width, size.height, size.top, size.left);
|
|
1307
|
-
// Check frameloop
|
|
1308
|
-
if (state.frameloop !== frameloop)
|
|
1309
|
-
state.setFrameloop(frameloop);
|
|
1310
|
-
if (!this.get('ready'))
|
|
1311
|
-
this.set({ ready: true });
|
|
1312
|
-
this.#invalidate();
|
|
1313
|
-
}
|
|
1314
|
-
destroy(canvas) {
|
|
1315
|
-
this.set((state) => ({ internal: { ...state.internal, active: false } }));
|
|
1316
|
-
setTimeout(() => {
|
|
1317
|
-
const { gl, xr, events } = this.get();
|
|
1318
|
-
if (gl) {
|
|
1319
|
-
if (events.disconnect) {
|
|
1320
|
-
events.disconnect();
|
|
1321
|
-
}
|
|
1322
|
-
gl.renderLists.dispose();
|
|
1323
|
-
gl.forceContextLoss();
|
|
1324
|
-
if (gl.xr && gl.xr.enabled) {
|
|
1325
|
-
gl.xr.setAnimationLoop(null);
|
|
1326
|
-
xr.disconnect();
|
|
1607
|
+
}
|
|
1608
|
+
createView() {
|
|
1609
|
+
this.zone.runOutsideAngular(() => {
|
|
1610
|
+
if (this.shouldCreateView) {
|
|
1611
|
+
if (this.view && !this.view.destroyed) {
|
|
1612
|
+
this.view.destroy();
|
|
1327
1613
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1614
|
+
this.view = this.vcr.createEmbeddedView(this.template);
|
|
1615
|
+
safeDetectChanges(this.view);
|
|
1330
1616
|
}
|
|
1331
|
-
}, 500);
|
|
1332
|
-
}
|
|
1333
|
-
#resize() {
|
|
1334
|
-
const state = this.get();
|
|
1335
|
-
let oldSize = state.size;
|
|
1336
|
-
let oldDpr = state.viewport.dpr;
|
|
1337
|
-
let oldCamera = state.camera;
|
|
1338
|
-
const triggers = computed(() => {
|
|
1339
|
-
return {
|
|
1340
|
-
camera: this.select('camera')(),
|
|
1341
|
-
size: this.select('size')(),
|
|
1342
|
-
viewport: this.select('viewport')(),
|
|
1343
|
-
gl: this.get('gl'),
|
|
1344
|
-
};
|
|
1345
1617
|
});
|
|
1346
|
-
effect(() => {
|
|
1347
|
-
const { camera, size, viewport, gl } = triggers();
|
|
1348
|
-
// resize camera and renderer on changes to size and dpr
|
|
1349
|
-
if (size !== oldSize || viewport.dpr !== oldDpr) {
|
|
1350
|
-
oldSize = size;
|
|
1351
|
-
oldDpr = viewport.dpr;
|
|
1352
|
-
// update camera
|
|
1353
|
-
updateCamera(camera, size);
|
|
1354
|
-
gl.setPixelRatio(viewport.dpr);
|
|
1355
|
-
gl.setSize(size.width, size.height);
|
|
1356
|
-
}
|
|
1357
|
-
// update viewport when camera changes
|
|
1358
|
-
if (camera !== oldCamera) {
|
|
1359
|
-
oldCamera = camera;
|
|
1360
|
-
updateCamera(camera, size);
|
|
1361
|
-
this.set((state) => ({
|
|
1362
|
-
viewport: { ...state.viewport, ...state.viewport.getCurrentViewport(camera) },
|
|
1363
|
-
}));
|
|
1364
|
-
}
|
|
1365
|
-
}, { injector: this.#injector, allowSignalWrites: true });
|
|
1366
|
-
}
|
|
1367
|
-
#invalidate() {
|
|
1368
|
-
const state = this.select();
|
|
1369
|
-
effect(() => {
|
|
1370
|
-
state().invalidate();
|
|
1371
|
-
}, { injector: this.#injector });
|
|
1372
1618
|
}
|
|
1373
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
1374
|
-
static { this.ɵ
|
|
1619
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtCommonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1620
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtCommonDirective, ngImport: i0 }); }
|
|
1375
1621
|
}
|
|
1376
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
1377
|
-
type:
|
|
1378
|
-
}] });
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1622
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtCommonDirective, decorators: [{
|
|
1623
|
+
type: Directive
|
|
1624
|
+
}], ctorParameters: function () { return []; } });
|
|
1625
|
+
|
|
1626
|
+
class NgtArgs extends NgtCommonDirective {
|
|
1627
|
+
constructor() {
|
|
1628
|
+
super(...arguments);
|
|
1629
|
+
this.injectedArgs = [];
|
|
1384
1630
|
}
|
|
1385
|
-
|
|
1631
|
+
set args(args) {
|
|
1632
|
+
if (args == null || !Array.isArray(args) || (args.length === 1 && args[0] === null))
|
|
1633
|
+
return;
|
|
1634
|
+
this.injected = false;
|
|
1635
|
+
this.injectedArgs = args;
|
|
1636
|
+
this.createView();
|
|
1637
|
+
}
|
|
1638
|
+
get args() {
|
|
1639
|
+
if (this.validate()) {
|
|
1640
|
+
this.injected = true;
|
|
1641
|
+
return this.injectedArgs;
|
|
1642
|
+
}
|
|
1643
|
+
return null;
|
|
1644
|
+
}
|
|
1645
|
+
validate() {
|
|
1646
|
+
return !this.injected && !!this.injectedArgs.length;
|
|
1647
|
+
}
|
|
1648
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtArgs, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1649
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtArgs, isStandalone: true, selector: "ng-template[args]", inputs: { args: "args" }, usesInheritance: true, ngImport: i0 }); }
|
|
1386
1650
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1651
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtArgs, decorators: [{
|
|
1652
|
+
type: Directive,
|
|
1653
|
+
args: [{ selector: 'ng-template[args]', standalone: true }]
|
|
1654
|
+
}], propDecorators: { args: [{
|
|
1655
|
+
type: Input
|
|
1656
|
+
}] } });
|
|
1657
|
+
|
|
1658
|
+
class NgtParent extends NgtCommonDirective {
|
|
1659
|
+
constructor() {
|
|
1660
|
+
super(...arguments);
|
|
1661
|
+
this.injectedParent = null;
|
|
1662
|
+
}
|
|
1663
|
+
set parent(parent) {
|
|
1664
|
+
if (!parent)
|
|
1665
|
+
return;
|
|
1666
|
+
this.injected = false;
|
|
1667
|
+
this.injectedParent = parent;
|
|
1668
|
+
this.createView();
|
|
1669
|
+
}
|
|
1670
|
+
get parent() {
|
|
1671
|
+
if (this.validate()) {
|
|
1672
|
+
this.injected = true;
|
|
1673
|
+
return this.injectedParent;
|
|
1674
|
+
}
|
|
1675
|
+
return null;
|
|
1394
1676
|
}
|
|
1677
|
+
validate() {
|
|
1678
|
+
return !this.injected && !!this.injectedParent;
|
|
1679
|
+
}
|
|
1680
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtParent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1681
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtParent, isStandalone: true, selector: "ng-template[parent]", inputs: { parent: "parent" }, usesInheritance: true, ngImport: i0 }); }
|
|
1395
1682
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
}
|
|
1403
|
-
const NGT_CATALOGUE = new InjectionToken('THREE Constructors Catalogue', { factory: () => catalogue });
|
|
1683
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtParent, decorators: [{
|
|
1684
|
+
type: Directive,
|
|
1685
|
+
args: [{ selector: 'ng-template[parent]', standalone: true }]
|
|
1686
|
+
}], propDecorators: { parent: [{
|
|
1687
|
+
type: Input
|
|
1688
|
+
}] } });
|
|
1404
1689
|
|
|
1405
1690
|
function attach(object, value, paths = []) {
|
|
1406
1691
|
const [base, ...remaining] = paths;
|
|
@@ -1432,25 +1717,6 @@ function createAttachFunction(cb) {
|
|
|
1432
1717
|
return (parent, child, store) => cb({ parent, child, store });
|
|
1433
1718
|
}
|
|
1434
1719
|
|
|
1435
|
-
const ROUTED_SCENE = '__ngt_renderer_is_routed_scene__';
|
|
1436
|
-
const SPECIAL_INTERNAL_ADD_COMMENT = '__ngt_renderer_add_comment__';
|
|
1437
|
-
const SPECIAL_DOM_TAG = {
|
|
1438
|
-
NGT_PORTAL: 'ngt-portal',
|
|
1439
|
-
NGT_PRIMITIVE: 'ngt-primitive',
|
|
1440
|
-
NGT_VALUE: 'ngt-value',
|
|
1441
|
-
};
|
|
1442
|
-
const SPECIAL_PROPERTIES = {
|
|
1443
|
-
COMPOUND: 'ngtCompound',
|
|
1444
|
-
RENDER_PRIORITY: 'priority',
|
|
1445
|
-
ATTACH: 'attach',
|
|
1446
|
-
VALUE: 'rawValue',
|
|
1447
|
-
REF: 'ref',
|
|
1448
|
-
};
|
|
1449
|
-
const SPECIAL_EVENTS = {
|
|
1450
|
-
BEFORE_RENDER: 'beforeRender',
|
|
1451
|
-
AFTER_UPDATE: 'afterUpdate',
|
|
1452
|
-
AFTER_ATTACH: 'afterAttach',
|
|
1453
|
-
};
|
|
1454
1720
|
function attachThreeChild(parent, child) {
|
|
1455
1721
|
const pLS = getLocalState(parent);
|
|
1456
1722
|
const cLS = getLocalState(child);
|
|
@@ -1461,7 +1727,7 @@ function attachThreeChild(parent, child) {
|
|
|
1461
1727
|
let added = false;
|
|
1462
1728
|
// assign store on child if not already exist
|
|
1463
1729
|
// or child store is the parent of parent store
|
|
1464
|
-
if (!cLS.store || cLS.store === pLS.store.get('
|
|
1730
|
+
if (!cLS.store || cLS.store === pLS.store.get('previousRoot')) {
|
|
1465
1731
|
cLS.store = pLS.store;
|
|
1466
1732
|
}
|
|
1467
1733
|
if (cLS.attach) {
|
|
@@ -1487,7 +1753,11 @@ function attachThreeChild(parent, child) {
|
|
|
1487
1753
|
}
|
|
1488
1754
|
// attach
|
|
1489
1755
|
if (cLS.isRaw) {
|
|
1490
|
-
cLS.parent.
|
|
1756
|
+
if (cLS.parent && cLS.parent() !== parent) {
|
|
1757
|
+
untracked(() => {
|
|
1758
|
+
cLS.parent.set(parent);
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1491
1761
|
// at this point we don't have rawValue yet, so we bail and wait until the Renderer recalls attach
|
|
1492
1762
|
if (child.__ngt_renderer__[11 /* NgtRendererClassId.rawValue */] === undefined)
|
|
1493
1763
|
return;
|
|
@@ -1505,7 +1775,11 @@ function attachThreeChild(parent, child) {
|
|
|
1505
1775
|
added = true;
|
|
1506
1776
|
}
|
|
1507
1777
|
pLS.add(child, added ? 'objects' : 'nonObjects');
|
|
1508
|
-
cLS.parent.
|
|
1778
|
+
if (cLS.parent && cLS.parent() !== parent) {
|
|
1779
|
+
untracked(() => {
|
|
1780
|
+
cLS.parent.set(parent);
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1509
1783
|
if (cLS.afterAttach)
|
|
1510
1784
|
cLS.afterAttach.emit({ parent, node: child });
|
|
1511
1785
|
invalidateInstance(child);
|
|
@@ -1515,11 +1789,13 @@ function removeThreeChild(parent, child, dispose) {
|
|
|
1515
1789
|
const pLS = getLocalState(parent);
|
|
1516
1790
|
const cLS = getLocalState(child);
|
|
1517
1791
|
// clear parent ref
|
|
1518
|
-
|
|
1792
|
+
untracked(() => {
|
|
1793
|
+
cLS.parent?.set(null);
|
|
1794
|
+
});
|
|
1519
1795
|
// remove child from parent
|
|
1520
|
-
if (untracked(pLS.objects))
|
|
1796
|
+
if (pLS.objects && untracked(pLS.objects))
|
|
1521
1797
|
pLS.remove(child, 'objects');
|
|
1522
|
-
if (untracked(pLS.nonObjects))
|
|
1798
|
+
if (pLS.nonObjects && untracked(pLS.nonObjects))
|
|
1523
1799
|
pLS.remove(child, 'nonObjects');
|
|
1524
1800
|
if (cLS.attach) {
|
|
1525
1801
|
detach(parent, child, cLS.attach);
|
|
@@ -1543,7 +1819,15 @@ function removeThreeRecursive(array, parent, dispose) {
|
|
|
1543
1819
|
if (array)
|
|
1544
1820
|
[...array].forEach((child) => removeThreeChild(parent, child, dispose));
|
|
1545
1821
|
}
|
|
1546
|
-
function
|
|
1822
|
+
function kebabToPascal(str) {
|
|
1823
|
+
// split the string at each hyphen
|
|
1824
|
+
const parts = str.split('-');
|
|
1825
|
+
// map over the parts, capitalizing the first letter of each part
|
|
1826
|
+
const pascalParts = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1));
|
|
1827
|
+
// join the parts together to create the final PascalCase string
|
|
1828
|
+
return pascalParts.join('');
|
|
1829
|
+
}
|
|
1830
|
+
function processThreeEvent(instance, priority, eventName, callback, zone, rootCdr, targetCdr) {
|
|
1547
1831
|
const lS = getLocalState(instance);
|
|
1548
1832
|
if (eventName === SPECIAL_EVENTS.BEFORE_RENDER) {
|
|
1549
1833
|
return lS.store
|
|
@@ -1567,11 +1851,10 @@ function processThreeEvent(instance, priority, eventName, callback, zone, cdr) {
|
|
|
1567
1851
|
previousHandler(event);
|
|
1568
1852
|
zone.run(() => {
|
|
1569
1853
|
callback(event);
|
|
1570
|
-
safeDetectChanges(
|
|
1571
|
-
// cdr.detectChanges();
|
|
1854
|
+
safeDetectChanges(targetCdr, rootCdr);
|
|
1572
1855
|
});
|
|
1573
1856
|
};
|
|
1574
|
-
Object.assign(lS.handlers, { [eventName]:
|
|
1857
|
+
Object.assign(lS.handlers, { [eventName]: updatedCallback });
|
|
1575
1858
|
// increment the count everytime
|
|
1576
1859
|
lS.eventCount += 1;
|
|
1577
1860
|
// but only add the instance (target) to the interaction array (so that it is handled by the EventManager with Raycast)
|
|
@@ -1582,6 +1865,7 @@ function processThreeEvent(instance, priority, eventName, callback, zone, cdr) {
|
|
|
1582
1865
|
return () => {
|
|
1583
1866
|
const localState = getLocalState(instance);
|
|
1584
1867
|
if (localState && localState.eventCount) {
|
|
1868
|
+
localState.eventCount -= 1;
|
|
1585
1869
|
const index = localState.store
|
|
1586
1870
|
.get('internal', 'interaction')
|
|
1587
1871
|
.findIndex((obj) => obj.uuid === instance.uuid);
|
|
@@ -1590,117 +1874,12 @@ function processThreeEvent(instance, priority, eventName, callback, zone, cdr) {
|
|
|
1590
1874
|
}
|
|
1591
1875
|
};
|
|
1592
1876
|
}
|
|
1593
|
-
function eventToHandler(callback) {
|
|
1594
|
-
return (event) => {
|
|
1595
|
-
callback(event);
|
|
1596
|
-
};
|
|
1597
|
-
}
|
|
1598
|
-
function kebabToPascal(str) {
|
|
1599
|
-
// split the string at each hyphen
|
|
1600
|
-
const parts = str.split('-');
|
|
1601
|
-
// map over the parts, capitalizing the first letter of each part
|
|
1602
|
-
const pascalParts = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1));
|
|
1603
|
-
// join the parts together to create the final PascalCase string
|
|
1604
|
-
return pascalParts.join('');
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
class NgtCommonDirective {
|
|
1608
|
-
#vcr;
|
|
1609
|
-
#zone;
|
|
1610
|
-
#template;
|
|
1611
|
-
#view;
|
|
1612
|
-
constructor() {
|
|
1613
|
-
this.#vcr = inject(ViewContainerRef);
|
|
1614
|
-
this.#zone = inject(NgZone);
|
|
1615
|
-
this.#template = inject(TemplateRef);
|
|
1616
|
-
this.injected = false;
|
|
1617
|
-
this.shouldCreateView = true;
|
|
1618
|
-
const commentNode = this.#vcr.element.nativeElement;
|
|
1619
|
-
if (commentNode[SPECIAL_INTERNAL_ADD_COMMENT]) {
|
|
1620
|
-
commentNode[SPECIAL_INTERNAL_ADD_COMMENT]();
|
|
1621
|
-
delete commentNode[SPECIAL_INTERNAL_ADD_COMMENT];
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
createView() {
|
|
1625
|
-
if (this.shouldCreateView) {
|
|
1626
|
-
if (this.#view && !this.#view.destroyed) {
|
|
1627
|
-
this.#view.destroy();
|
|
1628
|
-
}
|
|
1629
|
-
this.#zone.runOutsideAngular(() => {
|
|
1630
|
-
this.#view = this.#vcr.createEmbeddedView(this.#template);
|
|
1631
|
-
this.#view.detectChanges();
|
|
1632
|
-
});
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtCommonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1636
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: NgtCommonDirective, ngImport: i0 }); }
|
|
1637
|
-
}
|
|
1638
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtCommonDirective, decorators: [{
|
|
1639
|
-
type: Directive
|
|
1640
|
-
}], ctorParameters: function () { return []; } });
|
|
1641
|
-
|
|
1642
|
-
class NgtArgs extends NgtCommonDirective {
|
|
1643
|
-
#injectedArgs = [];
|
|
1644
|
-
set args(args) {
|
|
1645
|
-
if (args == null || !Array.isArray(args) || (args.length === 1 && args[0] === null))
|
|
1646
|
-
return;
|
|
1647
|
-
this.injected = false;
|
|
1648
|
-
this.#injectedArgs = args;
|
|
1649
|
-
this.createView();
|
|
1650
|
-
}
|
|
1651
|
-
get args() {
|
|
1652
|
-
if (this.validate()) {
|
|
1653
|
-
this.injected = true;
|
|
1654
|
-
return this.#injectedArgs;
|
|
1655
|
-
}
|
|
1656
|
-
return null;
|
|
1657
|
-
}
|
|
1658
|
-
validate() {
|
|
1659
|
-
return !this.injected && !!this.#injectedArgs.length;
|
|
1660
|
-
}
|
|
1661
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtArgs, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1662
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: NgtArgs, isStandalone: true, selector: "[args]", inputs: { args: "args" }, usesInheritance: true, ngImport: i0 }); }
|
|
1663
|
-
}
|
|
1664
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtArgs, decorators: [{
|
|
1665
|
-
type: Directive,
|
|
1666
|
-
args: [{ selector: '[args]', standalone: true }]
|
|
1667
|
-
}], propDecorators: { args: [{
|
|
1668
|
-
type: Input
|
|
1669
|
-
}] } });
|
|
1670
|
-
|
|
1671
|
-
class NgtParent extends NgtCommonDirective {
|
|
1672
|
-
#injectedParent = null;
|
|
1673
|
-
set parent(parent) {
|
|
1674
|
-
if (!parent)
|
|
1675
|
-
return;
|
|
1676
|
-
this.injected = false;
|
|
1677
|
-
this.#injectedParent = parent;
|
|
1678
|
-
this.createView();
|
|
1679
|
-
}
|
|
1680
|
-
get parent() {
|
|
1681
|
-
if (this.validate()) {
|
|
1682
|
-
this.injected = true;
|
|
1683
|
-
return this.#injectedParent;
|
|
1684
|
-
}
|
|
1685
|
-
return null;
|
|
1686
|
-
}
|
|
1687
|
-
validate() {
|
|
1688
|
-
return !this.injected && !!this.#injectedParent;
|
|
1689
|
-
}
|
|
1690
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtParent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1691
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: NgtParent, isStandalone: true, selector: "[parent]", inputs: { parent: "parent" }, usesInheritance: true, ngImport: i0 }); }
|
|
1692
|
-
}
|
|
1693
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtParent, decorators: [{
|
|
1694
|
-
type: Directive,
|
|
1695
|
-
args: [{ selector: '[parent]', standalone: true }]
|
|
1696
|
-
}], propDecorators: { parent: [{
|
|
1697
|
-
type: Input
|
|
1698
|
-
}] } });
|
|
1699
1877
|
|
|
1878
|
+
const NGT_COMPOUND_PREFIXES = new InjectionToken('NgtCompoundPrefixes');
|
|
1700
1879
|
class NgtRendererStore {
|
|
1701
|
-
#comments = [];
|
|
1702
1880
|
constructor(root) {
|
|
1703
1881
|
this.root = root;
|
|
1882
|
+
this.comments = [];
|
|
1704
1883
|
}
|
|
1705
1884
|
createNode(type, node) {
|
|
1706
1885
|
const state = [
|
|
@@ -1721,16 +1900,16 @@ class NgtRendererStore {
|
|
|
1721
1900
|
undefined,
|
|
1722
1901
|
];
|
|
1723
1902
|
const rendererNode = Object.assign(node, { __ngt_renderer__: state });
|
|
1724
|
-
// assign ownerDocument to node so we can use HostListener in Component
|
|
1903
|
+
// NOTE: assign ownerDocument to node so we can use HostListener in Component
|
|
1725
1904
|
if (!rendererNode['ownerDocument'])
|
|
1726
1905
|
rendererNode['ownerDocument'] = this.root.document;
|
|
1727
|
-
// assign injectorFactory on non-three type since
|
|
1906
|
+
// NOTE: assign injectorFactory on non-three type since
|
|
1728
1907
|
// rendererNode is an instance of DOM Node
|
|
1729
1908
|
if (state[0 /* NgtRendererClassId.type */] !== 'three') {
|
|
1730
1909
|
state[14 /* NgtRendererClassId.injectorFactory */] = () => getDebugNode(rendererNode).injector;
|
|
1731
1910
|
}
|
|
1732
1911
|
if (state[0 /* NgtRendererClassId.type */] === 'comment') {
|
|
1733
|
-
// we attach an arrow function to the Comment node
|
|
1912
|
+
// NOTE: we attach an arrow function to the Comment node
|
|
1734
1913
|
// In our directives, we can call this function to then start tracking the RendererNode
|
|
1735
1914
|
// this is done to limit the amount of Nodes we need to process for getCreationState
|
|
1736
1915
|
rendererNode[SPECIAL_INTERNAL_ADD_COMMENT] = (node) => {
|
|
@@ -1738,7 +1917,7 @@ class NgtRendererStore {
|
|
|
1738
1917
|
this.portals.push(node);
|
|
1739
1918
|
}
|
|
1740
1919
|
else {
|
|
1741
|
-
this
|
|
1920
|
+
this.comments.push(rendererNode);
|
|
1742
1921
|
}
|
|
1743
1922
|
};
|
|
1744
1923
|
return rendererNode;
|
|
@@ -1762,12 +1941,21 @@ class NgtRendererStore {
|
|
|
1762
1941
|
}
|
|
1763
1942
|
}
|
|
1764
1943
|
removeChild(node, child) {
|
|
1765
|
-
const index = node.__ngt_renderer__[3 /* NgtRendererClassId.children */].findIndex((c) => child === c);
|
|
1944
|
+
const index = node.__ngt_renderer__?.[3 /* NgtRendererClassId.children */].findIndex((c) => child === c);
|
|
1766
1945
|
if (index >= 0) {
|
|
1767
1946
|
node.__ngt_renderer__[3 /* NgtRendererClassId.children */].splice(index, 1);
|
|
1768
1947
|
}
|
|
1769
1948
|
}
|
|
1770
1949
|
setCompound(compound, instance) {
|
|
1950
|
+
const instanceRS = instance.__ngt_renderer__;
|
|
1951
|
+
if (instanceRS && instanceRS[1 /* NgtRendererClassId.parent */]) {
|
|
1952
|
+
const parentRS = instanceRS[1 /* NgtRendererClassId.parent */].__ngt_renderer__;
|
|
1953
|
+
// NOTE: if instance is already compounded by its parent. skip
|
|
1954
|
+
if (parentRS[0 /* NgtRendererClassId.type */] === 'compound' &&
|
|
1955
|
+
parentRS[7 /* NgtRendererClassId.compounded */] === instance) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1771
1959
|
const rS = compound.__ngt_renderer__;
|
|
1772
1960
|
rS[7 /* NgtRendererClassId.compounded */] = instance;
|
|
1773
1961
|
const attributes = Object.keys(rS[9 /* NgtRendererClassId.attributes */]);
|
|
@@ -1799,7 +1987,7 @@ class NgtRendererStore {
|
|
|
1799
1987
|
const injector = injectorFactory?.();
|
|
1800
1988
|
if (!injector)
|
|
1801
1989
|
return;
|
|
1802
|
-
const portalStore = injector.get(
|
|
1990
|
+
const portalStore = injector.get(NGT_STORE, null);
|
|
1803
1991
|
if (!portalStore)
|
|
1804
1992
|
return;
|
|
1805
1993
|
const portalContainer = portalStore.get('scene');
|
|
@@ -1812,8 +2000,8 @@ class NgtRendererStore {
|
|
|
1812
2000
|
if (rS[4 /* NgtRendererClassId.destroyed */])
|
|
1813
2001
|
return;
|
|
1814
2002
|
if (name === SPECIAL_PROPERTIES.RENDER_PRIORITY) {
|
|
1815
|
-
// priority needs to be set as an attribute string so that they can be set as early as possible
|
|
1816
|
-
// we convert that string to a number. if it's invalid, 0
|
|
2003
|
+
// NOTE: priority needs to be set as an attribute string so that they can be set as early as possible
|
|
2004
|
+
// we convert that string to a number. if it's invalid, default 0
|
|
1817
2005
|
let priority = Number(value);
|
|
1818
2006
|
if (isNaN(priority)) {
|
|
1819
2007
|
priority = 0;
|
|
@@ -1822,19 +2010,19 @@ class NgtRendererStore {
|
|
|
1822
2010
|
getLocalState(node).priority = priority;
|
|
1823
2011
|
}
|
|
1824
2012
|
if (name === SPECIAL_PROPERTIES.COMPOUND) {
|
|
1825
|
-
// we set the compound property on instance node now so we know that this instance is being compounded
|
|
2013
|
+
// NOTE: we set the compound property on instance node now so we know that this instance is being compounded
|
|
1826
2014
|
rS[5 /* NgtRendererClassId.compound */] = [value === '' || value === 'first', {}];
|
|
1827
2015
|
return;
|
|
1828
2016
|
}
|
|
1829
2017
|
if (name === SPECIAL_PROPERTIES.ATTACH) {
|
|
1830
|
-
// handle attach as tring
|
|
2018
|
+
// NOTE: handle attach as tring
|
|
1831
2019
|
const paths = value.split('.');
|
|
1832
2020
|
if (paths.length)
|
|
1833
2021
|
getLocalState(node).attach = paths;
|
|
1834
2022
|
return;
|
|
1835
2023
|
}
|
|
1836
2024
|
if (name === SPECIAL_PROPERTIES.VALUE) {
|
|
1837
|
-
// coercion
|
|
2025
|
+
// NOTE: coercion
|
|
1838
2026
|
let maybeCoerced = value;
|
|
1839
2027
|
if (maybeCoerced === '' || maybeCoerced === 'true' || maybeCoerced === 'false') {
|
|
1840
2028
|
maybeCoerced = maybeCoerced === 'true' || maybeCoerced === '';
|
|
@@ -1846,6 +2034,7 @@ class NgtRendererStore {
|
|
|
1846
2034
|
return;
|
|
1847
2035
|
}
|
|
1848
2036
|
applyProps(node, { [name]: value });
|
|
2037
|
+
this.updateNativeProps(node, name, value);
|
|
1849
2038
|
}
|
|
1850
2039
|
applyProperty(node, name, value) {
|
|
1851
2040
|
const rS = node.__ngt_renderer__;
|
|
@@ -1879,6 +2068,7 @@ class NgtRendererStore {
|
|
|
1879
2068
|
value = compound[1 /* NgtCompoundClassId.props */][name];
|
|
1880
2069
|
}
|
|
1881
2070
|
applyProps(node, { [name]: value });
|
|
2071
|
+
this.updateNativeProps(node, name, value);
|
|
1882
2072
|
}
|
|
1883
2073
|
isCompound(name) {
|
|
1884
2074
|
return this.root.compoundPrefixes.some((prefix) => name.startsWith(prefix));
|
|
@@ -1939,7 +2129,7 @@ class NgtRendererStore {
|
|
|
1939
2129
|
}
|
|
1940
2130
|
destroy(node, parent) {
|
|
1941
2131
|
const rS = node.__ngt_renderer__;
|
|
1942
|
-
if (rS[4 /* NgtRendererClassId.destroyed */])
|
|
2132
|
+
if (!rS || rS[4 /* NgtRendererClassId.destroyed */])
|
|
1943
2133
|
return;
|
|
1944
2134
|
if (rS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
1945
2135
|
rS[5 /* NgtRendererClassId.compound */] = undefined;
|
|
@@ -1957,6 +2147,7 @@ class NgtRendererStore {
|
|
|
1957
2147
|
localState.afterAttach.complete();
|
|
1958
2148
|
delete localState['objects'];
|
|
1959
2149
|
delete localState['nonObjects'];
|
|
2150
|
+
delete localState['nativeProps'];
|
|
1960
2151
|
delete localState['add'];
|
|
1961
2152
|
delete localState['remove'];
|
|
1962
2153
|
delete localState['afterUpdate'];
|
|
@@ -1970,9 +2161,9 @@ class NgtRendererStore {
|
|
|
1970
2161
|
if (rS[0 /* NgtRendererClassId.type */] === 'comment') {
|
|
1971
2162
|
rS[14 /* NgtRendererClassId.injectorFactory */] = null;
|
|
1972
2163
|
delete node[SPECIAL_INTERNAL_ADD_COMMENT];
|
|
1973
|
-
const index = this
|
|
2164
|
+
const index = this.comments.findIndex((comment) => comment === node);
|
|
1974
2165
|
if (index > -1) {
|
|
1975
|
-
this
|
|
2166
|
+
this.comments.splice(index, 1);
|
|
1976
2167
|
}
|
|
1977
2168
|
}
|
|
1978
2169
|
if (rS[0 /* NgtRendererClassId.type */] === 'portal') {
|
|
@@ -1992,14 +2183,21 @@ class NgtRendererStore {
|
|
|
1992
2183
|
}
|
|
1993
2184
|
if (rS[12 /* NgtRendererClassId.ref */]) {
|
|
1994
2185
|
// nullify ref
|
|
1995
|
-
|
|
1996
|
-
|
|
2186
|
+
// but we do it later so that it doesn't hinder render
|
|
2187
|
+
// TODO: will this cause memory leak?
|
|
2188
|
+
requestAnimationFrame(() => {
|
|
2189
|
+
rS[12 /* NgtRendererClassId.ref */].nativeElement = null;
|
|
2190
|
+
rS[12 /* NgtRendererClassId.ref */] = undefined;
|
|
2191
|
+
});
|
|
1997
2192
|
}
|
|
1998
2193
|
// nullify parent
|
|
1999
2194
|
rS[1 /* NgtRendererClassId.parent */] = null;
|
|
2000
2195
|
for (const renderChild of rS[3 /* NgtRendererClassId.children */] || []) {
|
|
2001
|
-
if (renderChild.__ngt_renderer__[0 /* NgtRendererClassId.type */] === 'three' && parent) {
|
|
2002
|
-
|
|
2196
|
+
if (renderChild.__ngt_renderer__?.[0 /* NgtRendererClassId.type */] === 'three' && parent) {
|
|
2197
|
+
const closestInstance = this.getClosestParentWithInstance(parent);
|
|
2198
|
+
if (closestInstance) {
|
|
2199
|
+
removeThreeChild(closestInstance, renderChild, true);
|
|
2200
|
+
}
|
|
2003
2201
|
}
|
|
2004
2202
|
this.destroy(renderChild, parent);
|
|
2005
2203
|
}
|
|
@@ -2009,12 +2207,20 @@ class NgtRendererStore {
|
|
|
2009
2207
|
this.removeChild(parent, node);
|
|
2010
2208
|
}
|
|
2011
2209
|
}
|
|
2210
|
+
updateNativeProps(node, key, value) {
|
|
2211
|
+
const localState = getLocalState(node);
|
|
2212
|
+
if (!localState || !localState.nativeProps)
|
|
2213
|
+
return;
|
|
2214
|
+
localState.nativeProps.set({ [key]: value });
|
|
2215
|
+
}
|
|
2012
2216
|
firstNonInjectedDirective(dir) {
|
|
2013
2217
|
let directive;
|
|
2014
|
-
|
|
2218
|
+
const destroyed = [];
|
|
2219
|
+
let i = this.comments.length - 1;
|
|
2015
2220
|
while (i >= 0) {
|
|
2016
|
-
const comment = this
|
|
2221
|
+
const comment = this.comments[i];
|
|
2017
2222
|
if (comment.__ngt_renderer__[4 /* NgtRendererClassId.destroyed */]) {
|
|
2223
|
+
destroyed.push(i);
|
|
2018
2224
|
i--;
|
|
2019
2225
|
continue;
|
|
2020
2226
|
}
|
|
@@ -2030,16 +2236,21 @@ class NgtRendererStore {
|
|
|
2030
2236
|
}
|
|
2031
2237
|
i--;
|
|
2032
2238
|
}
|
|
2239
|
+
destroyed.forEach((index) => {
|
|
2240
|
+
this.comments.splice(index, 1);
|
|
2241
|
+
});
|
|
2033
2242
|
return directive;
|
|
2034
2243
|
}
|
|
2035
2244
|
tryGetPortalStore() {
|
|
2036
2245
|
let store;
|
|
2246
|
+
const destroyed = [];
|
|
2037
2247
|
// we only care about the portal states because NgtStore only differs per Portal
|
|
2038
2248
|
let i = this.portals.length - 1;
|
|
2039
2249
|
while (i >= 0) {
|
|
2040
2250
|
// loop through the portal state backwards to find the closest NgtStore
|
|
2041
2251
|
const portal = this.portals[i];
|
|
2042
2252
|
if (portal.__ngt_renderer__[4 /* NgtRendererClassId.destroyed */]) {
|
|
2253
|
+
destroyed.push(i);
|
|
2043
2254
|
i--;
|
|
2044
2255
|
continue;
|
|
2045
2256
|
}
|
|
@@ -2048,55 +2259,62 @@ class NgtRendererStore {
|
|
|
2048
2259
|
i--;
|
|
2049
2260
|
continue;
|
|
2050
2261
|
}
|
|
2051
|
-
const instance = injector.get(
|
|
2052
|
-
// only the instance with
|
|
2053
|
-
if (instance && instance.get('
|
|
2262
|
+
const instance = injector.get(NGT_STORE, null);
|
|
2263
|
+
// only the instance with previousRoot should pass
|
|
2264
|
+
if (instance && instance.get('previousRoot')) {
|
|
2054
2265
|
store = instance;
|
|
2055
2266
|
break;
|
|
2056
2267
|
}
|
|
2057
2268
|
i--;
|
|
2058
2269
|
}
|
|
2270
|
+
destroyed.forEach((index) => {
|
|
2271
|
+
this.portals.splice(index, 1);
|
|
2272
|
+
});
|
|
2059
2273
|
return store || this.root.store;
|
|
2060
2274
|
}
|
|
2061
2275
|
}
|
|
2062
2276
|
|
|
2063
2277
|
class NgtRendererFactory {
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2278
|
+
constructor() {
|
|
2279
|
+
this.delegateRendererFactory = inject(RendererFactory2, { skipSelf: true });
|
|
2280
|
+
this.zone = inject(NgZone);
|
|
2281
|
+
this.catalogue = injectNgtCatalogue();
|
|
2282
|
+
this.cdr = inject(ChangeDetectorRef);
|
|
2283
|
+
this.rendererMap = new Map();
|
|
2284
|
+
this.routedSet = new Set();
|
|
2285
|
+
// all Renderer instances share the same Store
|
|
2286
|
+
this.rendererStore = new NgtRendererStore({
|
|
2287
|
+
portals: [],
|
|
2288
|
+
store: injectNgtStore(),
|
|
2289
|
+
compoundPrefixes: inject(NGT_COMPOUND_PREFIXES),
|
|
2290
|
+
document: inject(DOCUMENT),
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2077
2293
|
createRenderer(hostElement, type) {
|
|
2078
|
-
const
|
|
2294
|
+
const delegate = this.delegateRendererFactory.createRenderer(hostElement, type);
|
|
2079
2295
|
if (!type)
|
|
2080
|
-
return
|
|
2081
|
-
//
|
|
2082
|
-
|
|
2083
|
-
|
|
2296
|
+
return delegate;
|
|
2297
|
+
// TODO: handle html in canvas
|
|
2298
|
+
if (type['type'][HTML]) {
|
|
2299
|
+
this.rendererMap.set(type.id, delegate);
|
|
2300
|
+
return delegate;
|
|
2301
|
+
}
|
|
2084
2302
|
if (type['type'][ROUTED_SCENE]) {
|
|
2085
|
-
this
|
|
2303
|
+
this.routedSet.add(type.id);
|
|
2086
2304
|
}
|
|
2087
|
-
let renderer = this
|
|
2305
|
+
let renderer = this.rendererMap.get(type.id);
|
|
2088
2306
|
if (!renderer) {
|
|
2089
|
-
renderer = new NgtRenderer(
|
|
2307
|
+
renderer = new NgtRenderer(delegate, this.rendererStore, this.catalogue, this.zone, this.cdr,
|
|
2090
2308
|
// setting root scene if there's no routed scene OR this component is the routed Scene
|
|
2091
|
-
!hostElement && (this
|
|
2092
|
-
this
|
|
2309
|
+
!hostElement && (this.routedSet.size === 0 || this.routedSet.has(type.id)));
|
|
2310
|
+
this.rendererMap.set(type.id, renderer);
|
|
2093
2311
|
}
|
|
2094
2312
|
return renderer;
|
|
2095
2313
|
}
|
|
2096
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2097
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.
|
|
2314
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRendererFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2315
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRendererFactory }); }
|
|
2098
2316
|
}
|
|
2099
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
2317
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRendererFactory, decorators: [{
|
|
2100
2318
|
type: Injectable
|
|
2101
2319
|
}] });
|
|
2102
2320
|
/**
|
|
@@ -2141,7 +2359,10 @@ class NgtRenderer {
|
|
|
2141
2359
|
}
|
|
2142
2360
|
// handle raw value
|
|
2143
2361
|
if (name === SPECIAL_DOM_TAG.NGT_VALUE) {
|
|
2144
|
-
return this.store.createNode('three', Object.assign({ __ngt_renderer__: { rawValue: undefined } },
|
|
2362
|
+
return this.store.createNode('three', Object.assign({ __ngt_renderer__: { rawValue: undefined } },
|
|
2363
|
+
// NOTE: we assign this manually to a raw value node
|
|
2364
|
+
// because we say it is a 'three' node but we're not using prepare()
|
|
2365
|
+
{ __ngt__: { isRaw: true, parent: signal(null) } }));
|
|
2145
2366
|
}
|
|
2146
2367
|
const { injectedArgs, injectedParent, store } = this.store.getCreationState();
|
|
2147
2368
|
let parent = injectedParent;
|
|
@@ -2157,8 +2378,8 @@ class NgtRenderer {
|
|
|
2157
2378
|
const object = injectedArgs[0];
|
|
2158
2379
|
let localState = getLocalState(object);
|
|
2159
2380
|
if (!Object.keys(localState).length) {
|
|
2160
|
-
|
|
2161
|
-
localState = getLocalState(object);
|
|
2381
|
+
// NOTE: if an object isn't already "prepared", we prepare it
|
|
2382
|
+
localState = getLocalState(prepare(object, { store, args: injectedArgs, primitive: true }));
|
|
2162
2383
|
}
|
|
2163
2384
|
if (!localState.store)
|
|
2164
2385
|
localState.store = store;
|
|
@@ -2194,16 +2415,27 @@ class NgtRenderer {
|
|
|
2194
2415
|
return this.store.createNode('comment', this.delegate.createComment(value));
|
|
2195
2416
|
}
|
|
2196
2417
|
appendChild(parent, newChild) {
|
|
2197
|
-
// TODO: just ignore text node for now
|
|
2198
|
-
if (newChild instanceof Text)
|
|
2199
|
-
return;
|
|
2200
|
-
const cRS = newChild.__ngt_renderer__;
|
|
2201
2418
|
const pRS = parent.__ngt_renderer__;
|
|
2202
|
-
|
|
2419
|
+
const cRS = newChild.__ngt_renderer__;
|
|
2420
|
+
if (pRS[0 /* NgtRendererClassId.type */] === 'dom' &&
|
|
2421
|
+
(newChild instanceof Text || cRS[0 /* NgtRendererClassId.type */] === 'dom')) {
|
|
2422
|
+
this.store.setParent(newChild, parent);
|
|
2423
|
+
this.store.addChild(parent, newChild);
|
|
2424
|
+
this.delegate.appendChild(parent, newChild);
|
|
2425
|
+
if (this.shouldFindGrandparentInstance(pRS, cRS, newChild)) {
|
|
2426
|
+
// we'll try to get the grandparent instance here so that we can run appendChild with both instances
|
|
2427
|
+
const closestGrandparentInstance = this.store.getClosestParentWithInstance(parent);
|
|
2428
|
+
if (closestGrandparentInstance)
|
|
2429
|
+
this.appendChild(closestGrandparentInstance, newChild);
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
if (cRS?.[0 /* NgtRendererClassId.type */] === 'comment') {
|
|
2203
2435
|
this.store.setParent(newChild, parent);
|
|
2204
2436
|
return;
|
|
2205
2437
|
}
|
|
2206
|
-
if (cRS[2 /* NgtRendererClassId.injectedParent */]) {
|
|
2438
|
+
if (cRS?.[2 /* NgtRendererClassId.injectedParent */]) {
|
|
2207
2439
|
if (is.ref(cRS[2 /* NgtRendererClassId.injectedParent */])) {
|
|
2208
2440
|
const injector = cRS[14 /* NgtRendererClassId.injectorFactory */]().get(Injector, null);
|
|
2209
2441
|
if (!injector) {
|
|
@@ -2229,7 +2461,7 @@ class NgtRenderer {
|
|
|
2229
2461
|
this.store.setParent(newChild, parent);
|
|
2230
2462
|
this.store.addChild(parent, newChild);
|
|
2231
2463
|
// if new child is a portal
|
|
2232
|
-
if (cRS[0 /* NgtRendererClassId.type */] === 'portal') {
|
|
2464
|
+
if (cRS?.[0 /* NgtRendererClassId.type */] === 'portal') {
|
|
2233
2465
|
this.store.processPortalContainer(newChild);
|
|
2234
2466
|
if (cRS[13 /* NgtRendererClassId.portalContainer */]) {
|
|
2235
2467
|
this.appendChild(parent, cRS[13 /* NgtRendererClassId.portalContainer */]);
|
|
@@ -2245,7 +2477,7 @@ class NgtRenderer {
|
|
|
2245
2477
|
return;
|
|
2246
2478
|
}
|
|
2247
2479
|
// if both are three instances, straightforward case
|
|
2248
|
-
if (pRS[0 /* NgtRendererClassId.type */] === 'three' && cRS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2480
|
+
if (pRS[0 /* NgtRendererClassId.type */] === 'three' && cRS?.[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2249
2481
|
// if child already attached to a parent, skip
|
|
2250
2482
|
if (getLocalState(newChild).parent && untracked(getLocalState(newChild).parent))
|
|
2251
2483
|
return;
|
|
@@ -2262,7 +2494,7 @@ class NgtRenderer {
|
|
|
2262
2494
|
}
|
|
2263
2495
|
// if only the parent is the THREE instance
|
|
2264
2496
|
if (pRS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2265
|
-
for (const renderChild of cRS[3 /* NgtRendererClassId.children */]) {
|
|
2497
|
+
for (const renderChild of cRS?.[3 /* NgtRendererClassId.children */]) {
|
|
2266
2498
|
this.appendChild(parent, renderChild);
|
|
2267
2499
|
}
|
|
2268
2500
|
}
|
|
@@ -2285,27 +2517,15 @@ class NgtRenderer {
|
|
|
2285
2517
|
this.store.setCompound(parent, newChild);
|
|
2286
2518
|
}
|
|
2287
2519
|
}
|
|
2288
|
-
|
|
2289
|
-
// if child is three but haven't been attached to a parent yet
|
|
2290
|
-
(cRS[0 /* NgtRendererClassId.type */] === 'three' && !untracked(getLocalState(newChild).parent)) ||
|
|
2291
|
-
// or both parent and child are DOM elements
|
|
2292
|
-
// or they are compound AND haven't had a THREE instance yet
|
|
2293
|
-
((pRS[0 /* NgtRendererClassId.type */] === 'dom' ||
|
|
2294
|
-
(pRS[0 /* NgtRendererClassId.type */] === 'compound' && !pRS[7 /* NgtRendererClassId.compounded */])) &&
|
|
2295
|
-
(cRS[0 /* NgtRendererClassId.type */] === 'dom' ||
|
|
2296
|
-
(cRS[0 /* NgtRendererClassId.type */] === 'compound' && !cRS[7 /* NgtRendererClassId.compounded */])));
|
|
2297
|
-
if (shouldFindGrandparentInstance) {
|
|
2520
|
+
if (this.shouldFindGrandparentInstance(pRS, cRS, newChild)) {
|
|
2298
2521
|
// we'll try to get the grandparent instance here so that we can run appendChild with both instances
|
|
2299
2522
|
const closestGrandparentInstance = this.store.getClosestParentWithInstance(parent);
|
|
2300
2523
|
if (closestGrandparentInstance)
|
|
2301
2524
|
this.appendChild(closestGrandparentInstance, newChild);
|
|
2525
|
+
return;
|
|
2302
2526
|
}
|
|
2303
2527
|
}
|
|
2304
|
-
insertBefore(parent, newChild
|
|
2305
|
-
// TODO: we might need these?
|
|
2306
|
-
// refChild: NgtRendererNode
|
|
2307
|
-
// isMove?: boolean | undefined
|
|
2308
|
-
) {
|
|
2528
|
+
insertBefore(parent, newChild) {
|
|
2309
2529
|
if (parent == null || !parent.__ngt_renderer__ || parent === newChild)
|
|
2310
2530
|
return;
|
|
2311
2531
|
this.appendChild(parent, newChild);
|
|
@@ -2313,6 +2533,18 @@ class NgtRenderer {
|
|
|
2313
2533
|
removeChild(parent, oldChild, isHostElement) {
|
|
2314
2534
|
const pRS = parent.__ngt_renderer__;
|
|
2315
2535
|
const cRS = oldChild.__ngt_renderer__;
|
|
2536
|
+
if ((!cRS || !pRS) &&
|
|
2537
|
+
parent instanceof Element &&
|
|
2538
|
+
(oldChild instanceof Element || oldChild instanceof Text || oldChild instanceof Comment)) {
|
|
2539
|
+
this.delegate.removeChild(parent, oldChild);
|
|
2540
|
+
this.store.destroy(oldChild, parent);
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
if (cRS[0 /* NgtRendererClassId.type */] === 'dom' && (!pRS || pRS[0 /* NgtRendererClassId.type */] === 'dom')) {
|
|
2544
|
+
this.delegate.removeChild(parent, oldChild);
|
|
2545
|
+
this.store.destroy(oldChild, parent);
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2316
2548
|
if (pRS[0 /* NgtRendererClassId.type */] === 'three' && cRS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2317
2549
|
removeThreeChild(parent, oldChild, true);
|
|
2318
2550
|
this.store.destroy(oldChild, parent);
|
|
@@ -2349,8 +2581,11 @@ class NgtRenderer {
|
|
|
2349
2581
|
this.setAttribute(rS[7 /* NgtRendererClassId.compounded */], name, value, namespace);
|
|
2350
2582
|
return;
|
|
2351
2583
|
}
|
|
2352
|
-
if (rS[0 /* NgtRendererClassId.type */] === 'three')
|
|
2584
|
+
if (rS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2353
2585
|
this.store.applyAttribute(el, name, value);
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
return this.delegate.setAttribute(el, name, value);
|
|
2354
2589
|
}
|
|
2355
2590
|
setProperty(el, name, value) {
|
|
2356
2591
|
const rS = el.__ngt_renderer__;
|
|
@@ -2362,15 +2597,16 @@ class NgtRenderer {
|
|
|
2362
2597
|
return;
|
|
2363
2598
|
}
|
|
2364
2599
|
if (rS[7 /* NgtRendererClassId.compounded */].__ngt_renderer__[5 /* NgtRendererClassId.compound */]) {
|
|
2365
|
-
Object.assign(rS[7 /* NgtRendererClassId.compounded */].__ngt_renderer__[5 /* NgtRendererClassId.compound */], {
|
|
2366
|
-
props: Object.assign(rS[7 /* NgtRendererClassId.compounded */].__ngt_renderer__[5 /* NgtRendererClassId.compound */], { [name]: value }),
|
|
2367
|
-
});
|
|
2600
|
+
Object.assign(rS[7 /* NgtRendererClassId.compounded */].__ngt_renderer__[5 /* NgtRendererClassId.compound */][1 /* NgtCompoundClassId.props */], { [name]: value });
|
|
2368
2601
|
}
|
|
2369
2602
|
this.setProperty(rS[7 /* NgtRendererClassId.compounded */], name, value);
|
|
2370
2603
|
return;
|
|
2371
2604
|
}
|
|
2372
|
-
if (rS[0 /* NgtRendererClassId.type */] === 'three')
|
|
2605
|
+
if (rS[0 /* NgtRendererClassId.type */] === 'three') {
|
|
2373
2606
|
this.store.applyProperty(el, name, value);
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
return this.delegate.setProperty(el, name, value);
|
|
2374
2610
|
}
|
|
2375
2611
|
listen(target, eventName, callback) {
|
|
2376
2612
|
const rS = target.__ngt_renderer__;
|
|
@@ -2383,7 +2619,9 @@ class NgtRenderer {
|
|
|
2383
2619
|
(rS[0 /* NgtRendererClassId.type */] === 'compound' && rS[7 /* NgtRendererClassId.compounded */])) {
|
|
2384
2620
|
const instance = rS[7 /* NgtRendererClassId.compounded */] || target;
|
|
2385
2621
|
const priority = getLocalState(target).priority;
|
|
2386
|
-
|
|
2622
|
+
const targetCdr = rS[14 /* NgtRendererClassId.injectorFactory */]?.().get(ChangeDetectorRef, null) ||
|
|
2623
|
+
rS[1 /* NgtRendererClassId.parent */]?.__ngt_renderer__?.[14 /* NgtRendererClassId.injectorFactory */]?.().get(ChangeDetectorRef, null);
|
|
2624
|
+
return processThreeEvent(instance, priority || 0, eventName, callback, this.zone, this.cdr, targetCdr);
|
|
2387
2625
|
}
|
|
2388
2626
|
if (rS[0 /* NgtRendererClassId.type */] === 'compound' && !rS[7 /* NgtRendererClassId.compounded */]) {
|
|
2389
2627
|
this.store.queueOperation(target, [
|
|
@@ -2406,171 +2644,165 @@ class NgtRenderer {
|
|
|
2406
2644
|
}
|
|
2407
2645
|
return () => { };
|
|
2408
2646
|
}
|
|
2647
|
+
shouldFindGrandparentInstance(pRS, cRS, child) {
|
|
2648
|
+
const pType = pRS[0 /* NgtRendererClassId.type */];
|
|
2649
|
+
const cType = cRS[0 /* NgtRendererClassId.type */];
|
|
2650
|
+
const isParentCompounded = pRS[7 /* NgtRendererClassId.compounded */];
|
|
2651
|
+
const isChildCompounded = cRS[7 /* NgtRendererClassId.compounded */];
|
|
2652
|
+
// if child is three but haven't been attached to a parent yet
|
|
2653
|
+
const isDanglingThreeChild = cType === 'three' && !untracked(getLocalState(child).parent);
|
|
2654
|
+
// or both parent and child are DOM elements
|
|
2655
|
+
// or they are compound AND haven't had a THREE instance yet
|
|
2656
|
+
const isParentStillDOM = pType === 'dom' || (pType === 'compound' && !isParentCompounded);
|
|
2657
|
+
const isChildStillDOM = cType === 'dom' || (cType === 'compound' && !isChildCompounded);
|
|
2658
|
+
// and the child is a compounded compound
|
|
2659
|
+
const isCompoundChildCompounded = cType === 'compound' && !!isChildCompounded;
|
|
2660
|
+
return (isDanglingThreeChild ||
|
|
2661
|
+
(isParentStillDOM && isChildStillDOM) ||
|
|
2662
|
+
(isParentStillDOM && isCompoundChildCompounded));
|
|
2663
|
+
}
|
|
2409
2664
|
get data() {
|
|
2410
2665
|
return this.delegate.data;
|
|
2411
2666
|
}
|
|
2412
2667
|
}
|
|
2413
|
-
|
|
2414
|
-
function provideNgtRenderer({ store, changeDetectorRef, compoundPrefixes = [] }) {
|
|
2668
|
+
function provideNgtRenderer(store, compoundPrefixes, cdr) {
|
|
2415
2669
|
if (!compoundPrefixes.includes('ngts'))
|
|
2416
2670
|
compoundPrefixes.push('ngts');
|
|
2417
2671
|
if (!compoundPrefixes.includes('ngtp'))
|
|
2418
2672
|
compoundPrefixes.push('ngtp');
|
|
2419
2673
|
return makeEnvironmentProviders([
|
|
2420
2674
|
{ provide: RendererFactory2, useClass: NgtRendererFactory },
|
|
2421
|
-
{ provide: NgtStore, useValue: store },
|
|
2422
|
-
{ provide: ChangeDetectorRef, useValue: changeDetectorRef },
|
|
2423
2675
|
{ provide: NGT_COMPOUND_PREFIXES, useValue: compoundPrefixes },
|
|
2676
|
+
{ provide: ChangeDetectorRef, useValue: cdr },
|
|
2677
|
+
provideNgtStore(store),
|
|
2424
2678
|
provideZoneChangeDetection({ runCoalescing: true, eventCoalescing: true }),
|
|
2425
2679
|
]);
|
|
2426
2680
|
}
|
|
2427
2681
|
|
|
2428
|
-
class NgtCanvas
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2682
|
+
class NgtCanvas {
|
|
2683
|
+
constructor() {
|
|
2684
|
+
this.store = injectNgtStore();
|
|
2685
|
+
this.initRoot = injectCanvasRootInitializer();
|
|
2686
|
+
this.host = inject(ElementRef);
|
|
2687
|
+
this.viewContainerRef = inject(ViewContainerRef);
|
|
2688
|
+
this.injector = inject(Injector);
|
|
2689
|
+
this.environmentInjector = inject(EnvironmentInjector);
|
|
2690
|
+
this.zone = inject(NgZone);
|
|
2691
|
+
this.destroyRef = inject(DestroyRef);
|
|
2692
|
+
this.cdr = inject(ChangeDetectorRef);
|
|
2693
|
+
this.inputs = signalStore({
|
|
2694
|
+
shadows: false,
|
|
2695
|
+
linear: false,
|
|
2696
|
+
flat: false,
|
|
2697
|
+
legacy: false,
|
|
2698
|
+
orthographic: false,
|
|
2699
|
+
frameloop: 'always',
|
|
2700
|
+
dpr: [1, 2],
|
|
2701
|
+
events: createPointerEvents,
|
|
2702
|
+
});
|
|
2703
|
+
this.sceneGraphInputs = {};
|
|
2704
|
+
this.compoundPrefixes = [];
|
|
2705
|
+
this.created = new EventEmitter();
|
|
2706
|
+
this.inputsEventSource = this.inputs.select('eventSource');
|
|
2707
|
+
this.hbPointerEvents = computed(() => (!!this.inputsEventSource() ? 'none' : 'auto'));
|
|
2708
|
+
}
|
|
2436
2709
|
set linear(linear) {
|
|
2437
|
-
this.set({ linear });
|
|
2710
|
+
this.inputs.set({ linear });
|
|
2438
2711
|
}
|
|
2439
2712
|
set legacy(legacy) {
|
|
2440
|
-
this.set({ legacy });
|
|
2713
|
+
this.inputs.set({ legacy });
|
|
2441
2714
|
}
|
|
2442
2715
|
set flat(flat) {
|
|
2443
|
-
this.set({ flat });
|
|
2716
|
+
this.inputs.set({ flat });
|
|
2444
2717
|
}
|
|
2445
2718
|
set orthographic(orthographic) {
|
|
2446
|
-
this.set({ orthographic });
|
|
2719
|
+
this.inputs.set({ orthographic });
|
|
2447
2720
|
}
|
|
2448
2721
|
set frameloop(frameloop) {
|
|
2449
|
-
this.set({ frameloop });
|
|
2722
|
+
this.inputs.set({ frameloop });
|
|
2450
2723
|
}
|
|
2451
2724
|
set dpr(dpr) {
|
|
2452
|
-
this.set({ dpr });
|
|
2725
|
+
this.inputs.set({ dpr });
|
|
2453
2726
|
}
|
|
2454
2727
|
set raycaster(raycaster) {
|
|
2455
|
-
this.set({ raycaster });
|
|
2728
|
+
this.inputs.set({ raycaster });
|
|
2456
2729
|
}
|
|
2457
2730
|
set shadows(shadows) {
|
|
2458
|
-
this.set({ shadows });
|
|
2731
|
+
this.inputs.set({ shadows });
|
|
2459
2732
|
}
|
|
2460
2733
|
set camera(camera) {
|
|
2461
|
-
this.set({ camera });
|
|
2734
|
+
this.inputs.set({ camera });
|
|
2462
2735
|
}
|
|
2463
2736
|
set scene(scene) {
|
|
2464
|
-
this.set({ scene });
|
|
2737
|
+
this.inputs.set({ scene });
|
|
2465
2738
|
}
|
|
2466
2739
|
set gl(gl) {
|
|
2467
|
-
this.set({ gl });
|
|
2740
|
+
this.inputs.set({ gl });
|
|
2468
2741
|
}
|
|
2469
2742
|
set eventSource(eventSource) {
|
|
2470
|
-
this.set({ eventSource });
|
|
2743
|
+
this.inputs.set({ eventSource });
|
|
2471
2744
|
}
|
|
2472
2745
|
set eventPrefix(eventPrefix) {
|
|
2473
|
-
this.set({ eventPrefix });
|
|
2746
|
+
this.inputs.set({ eventPrefix });
|
|
2474
2747
|
}
|
|
2475
2748
|
set lookAt(lookAt) {
|
|
2476
|
-
this.set({ lookAt });
|
|
2749
|
+
this.inputs.set({ lookAt });
|
|
2477
2750
|
}
|
|
2478
2751
|
set performance(performance) {
|
|
2479
|
-
this.set({ performance });
|
|
2480
|
-
}
|
|
2481
|
-
#glRef;
|
|
2482
|
-
#glEnvInjector;
|
|
2483
|
-
constructor() {
|
|
2484
|
-
super({
|
|
2485
|
-
shadows: false,
|
|
2486
|
-
linear: false,
|
|
2487
|
-
flat: false,
|
|
2488
|
-
legacy: false,
|
|
2489
|
-
orthographic: false,
|
|
2490
|
-
frameloop: 'always',
|
|
2491
|
-
dpr: [1, 2],
|
|
2492
|
-
events: createPointerEvents,
|
|
2493
|
-
});
|
|
2494
|
-
this.#envInjector = inject(EnvironmentInjector);
|
|
2495
|
-
this.#injector = inject(Injector);
|
|
2496
|
-
this.#host = inject(ElementRef);
|
|
2497
|
-
this.#zone = inject(NgZone);
|
|
2498
|
-
this.#cdr = inject(ChangeDetectorRef);
|
|
2499
|
-
this.#store = inject(NgtStore);
|
|
2500
|
-
this.#isReady = this.#store.select('ready');
|
|
2501
|
-
this.sceneGraphInputs = {};
|
|
2502
|
-
this.compoundPrefixes = [];
|
|
2503
|
-
this.created = new EventEmitter();
|
|
2504
|
-
this.pointerMissed = new EventEmitter();
|
|
2505
|
-
inject(DestroyRef).onDestroy(() => {
|
|
2506
|
-
if (this.#glRef)
|
|
2507
|
-
this.#glRef.destroy();
|
|
2508
|
-
if (this.#glEnvInjector)
|
|
2509
|
-
this.#glEnvInjector.destroy();
|
|
2510
|
-
injectNgtLoader.destroy();
|
|
2511
|
-
this.#store.destroy(this.glCanvas.nativeElement);
|
|
2512
|
-
});
|
|
2513
|
-
}
|
|
2514
|
-
get hbPointerEvents() {
|
|
2515
|
-
return this.select('eventSource')() !== this.#host.nativeElement ? 'none' : 'auto';
|
|
2752
|
+
this.inputs.set({ performance });
|
|
2516
2753
|
}
|
|
2517
2754
|
ngOnChanges(changes) {
|
|
2518
|
-
if (changes['sceneGraphInputs'] && !changes['sceneGraphInputs'].firstChange && this
|
|
2519
|
-
this
|
|
2755
|
+
if (changes['sceneGraphInputs'] && !changes['sceneGraphInputs'].firstChange && this.glRef) {
|
|
2756
|
+
this.setSceneGraphInputs();
|
|
2520
2757
|
}
|
|
2521
2758
|
}
|
|
2522
2759
|
ngOnInit() {
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
this
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
this
|
|
2541
|
-
|
|
2542
|
-
this
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
this.#resizeRef.destroy();
|
|
2552
|
-
}
|
|
2553
|
-
if (width > 0 && height > 0) {
|
|
2554
|
-
if (!this.#store.isInit)
|
|
2555
|
-
this.#store.init();
|
|
2556
|
-
const inputs = this.select();
|
|
2557
|
-
this.#resizeRef = this.#zone.run(() => effect(() => {
|
|
2558
|
-
const canvasInputs = inputs();
|
|
2559
|
-
this.#zone.runOutsideAngular(() => {
|
|
2560
|
-
this.#store.configure({ ...canvasInputs, size: { width, height, top, left } }, this.glCanvas.nativeElement);
|
|
2760
|
+
// NOTE: we resolve glCanvas at this point, setup the configurator
|
|
2761
|
+
this.configurator = this.initRoot(this.glCanvas.nativeElement);
|
|
2762
|
+
this.destroyRef.onDestroy(() => {
|
|
2763
|
+
this.glEnvironmentInjector?.destroy();
|
|
2764
|
+
this.glRef?.destroy();
|
|
2765
|
+
this.resizeEffectRef?.destroy();
|
|
2766
|
+
injectNgtLoader.destroy();
|
|
2767
|
+
this.configurator?.destroy();
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
// NOTE: runs outside of Zone due to emitInZone: false
|
|
2771
|
+
onResize(result) {
|
|
2772
|
+
if (result.width > 0 && result.height > 0) {
|
|
2773
|
+
this.resizeEffectRef?.destroy();
|
|
2774
|
+
const inputs = this.inputs.select();
|
|
2775
|
+
// NOTE: go back into zone so that effect runs
|
|
2776
|
+
// TODO: Double-check when effect is made not depended on zone
|
|
2777
|
+
this.resizeEffectRef = this.zone.run(() => effect(() => {
|
|
2778
|
+
this.zone.runOutsideAngular(() => {
|
|
2779
|
+
if (!this.configurator)
|
|
2780
|
+
this.configurator = this.initRoot(this.glCanvas.nativeElement);
|
|
2781
|
+
this.configurator.configure({ ...inputs(), size: result });
|
|
2782
|
+
if (this.glRef) {
|
|
2783
|
+
this.cdr.detectChanges();
|
|
2784
|
+
}
|
|
2785
|
+
else {
|
|
2786
|
+
this.render();
|
|
2787
|
+
}
|
|
2561
2788
|
});
|
|
2562
|
-
}, {
|
|
2789
|
+
}, { manualCleanup: true, injector: this.injector }));
|
|
2563
2790
|
}
|
|
2564
2791
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
const
|
|
2792
|
+
render() {
|
|
2793
|
+
this.glEnvironmentInjector?.destroy();
|
|
2794
|
+
this.glRef?.destroy();
|
|
2795
|
+
// Flag the canvas active, rendering will now begin
|
|
2796
|
+
this.store.set((state) => ({ internal: { ...state.internal, active: true } }));
|
|
2797
|
+
const inputs = this.inputs.get();
|
|
2798
|
+
const state = this.store.get();
|
|
2571
2799
|
// connect to event source
|
|
2572
|
-
state.events.connect?.(
|
|
2573
|
-
|
|
2800
|
+
state.events.connect?.(inputs.eventSource
|
|
2801
|
+
? is.ref(inputs.eventSource)
|
|
2802
|
+
? inputs.eventSource.nativeElement
|
|
2803
|
+
: inputs.eventSource
|
|
2804
|
+
: this.host.nativeElement);
|
|
2805
|
+
// setup compute for eventPrefix
|
|
2574
2806
|
if (inputs.eventPrefix) {
|
|
2575
2807
|
state.setEvents({
|
|
2576
2808
|
compute: (event, store) => {
|
|
@@ -2584,70 +2816,65 @@ class NgtCanvas extends NgtSignalStore {
|
|
|
2584
2816
|
}
|
|
2585
2817
|
// emit created event if observed
|
|
2586
2818
|
if (this.created.observed) {
|
|
2587
|
-
// but go back into zone to
|
|
2588
|
-
this
|
|
2589
|
-
this.created.emit(this
|
|
2819
|
+
// but go back into zone to do so
|
|
2820
|
+
this.zone.run(() => {
|
|
2821
|
+
this.created.emit(this.store.get());
|
|
2590
2822
|
});
|
|
2591
2823
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
changeDetectorRef: this.#cdr,
|
|
2600
|
-
compoundPrefixes: this.compoundPrefixes,
|
|
2601
|
-
}),
|
|
2602
|
-
], this.#envInjector);
|
|
2603
|
-
this.#glRef = this.glAnchor.createComponent(this.sceneGraph, {
|
|
2604
|
-
environmentInjector: this.#glEnvInjector,
|
|
2605
|
-
});
|
|
2606
|
-
this.#setSceneGraphInputs();
|
|
2607
|
-
this.#overrideChangeDetectorRef();
|
|
2608
|
-
safeDetectChanges(this.#cdr);
|
|
2824
|
+
if (!this.store.get('events', 'connected')) {
|
|
2825
|
+
this.store.get('events').connect?.(this.glCanvas.nativeElement);
|
|
2826
|
+
}
|
|
2827
|
+
this.glEnvironmentInjector = createEnvironmentInjector([provideNgtRenderer(this.store, this.compoundPrefixes, this.cdr)], this.environmentInjector);
|
|
2828
|
+
this.glRef = this.viewContainerRef.createComponent(this.sceneGraph, {
|
|
2829
|
+
environmentInjector: this.glEnvironmentInjector,
|
|
2830
|
+
injector: this.injector,
|
|
2609
2831
|
});
|
|
2832
|
+
this.overrideChangeDetectorRef();
|
|
2833
|
+
this.setSceneGraphInputs();
|
|
2610
2834
|
}
|
|
2611
|
-
|
|
2612
|
-
const originalDetectChanges = this
|
|
2613
|
-
this
|
|
2835
|
+
overrideChangeDetectorRef() {
|
|
2836
|
+
const originalDetectChanges = this.cdr.detectChanges.bind(this.cdr);
|
|
2837
|
+
this.cdr.detectChanges = () => {
|
|
2614
2838
|
originalDetectChanges();
|
|
2615
|
-
safeDetectChanges(this
|
|
2839
|
+
safeDetectChanges(this.glRef?.changeDetectorRef);
|
|
2616
2840
|
};
|
|
2617
2841
|
}
|
|
2618
|
-
|
|
2619
|
-
this
|
|
2620
|
-
if (this
|
|
2842
|
+
setSceneGraphInputs() {
|
|
2843
|
+
this.zone.run(() => {
|
|
2844
|
+
if (this.glRef) {
|
|
2621
2845
|
for (const [key, value] of Object.entries(this.sceneGraphInputs)) {
|
|
2622
|
-
this
|
|
2846
|
+
this.glRef.setInput(key, value);
|
|
2623
2847
|
}
|
|
2624
|
-
|
|
2848
|
+
this.glRef.changeDetectorRef.detectChanges();
|
|
2625
2849
|
}
|
|
2626
2850
|
});
|
|
2627
2851
|
}
|
|
2628
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2629
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2852
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtCanvas, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2853
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: NgtCanvas, isStandalone: true, selector: "ngt-canvas", inputs: { sceneGraph: "sceneGraph", sceneGraphInputs: "sceneGraphInputs", compoundPrefixes: "compoundPrefixes", linear: "linear", legacy: "legacy", flat: "flat", orthographic: "orthographic", frameloop: "frameloop", dpr: "dpr", raycaster: "raycaster", shadows: "shadows", camera: "camera", scene: "scene", gl: "gl", eventSource: "eventSource", eventPrefix: "eventPrefix", lookAt: "lookAt", performance: "performance" }, outputs: { created: "created" }, host: { properties: { "style.pointerEvents": "hbPointerEvents()" }, styleAttribute: "display: block;position: relative;width: 100%;height: 100%;overflow: hidden;" }, providers: [provideNgxResizeOptions({ emitInZone: false, emitInitialResult: true }), provideNgtStore()], viewQueries: [{ propertyName: "glCanvas", first: true, predicate: ["glCanvas"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: `
|
|
2854
|
+
<div (ngxResize)="onResize($event)" style="height: 100%; width: 100%;">
|
|
2855
|
+
<canvas #glCanvas style="display: block;"> </canvas>
|
|
2856
|
+
</div>
|
|
2857
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgxResize, selector: "[ngxResize]", inputs: ["ngxResizeOptions"], outputs: ["ngxResize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
2634
2858
|
}
|
|
2635
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
2859
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtCanvas, decorators: [{
|
|
2636
2860
|
type: Component,
|
|
2637
2861
|
args: [{
|
|
2638
2862
|
selector: 'ngt-canvas',
|
|
2639
2863
|
standalone: true,
|
|
2640
2864
|
template: `
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2865
|
+
<div (ngxResize)="onResize($event)" style="height: 100%; width: 100%;">
|
|
2866
|
+
<canvas #glCanvas style="display: block;"> </canvas>
|
|
2867
|
+
</div>
|
|
2868
|
+
`,
|
|
2645
2869
|
imports: [NgxResize],
|
|
2646
|
-
providers: [
|
|
2647
|
-
host: {
|
|
2870
|
+
providers: [provideNgxResizeOptions({ emitInZone: false, emitInitialResult: true }), provideNgtStore()],
|
|
2871
|
+
host: {
|
|
2872
|
+
style: 'display: block;position: relative;width: 100%;height: 100%;overflow: hidden;',
|
|
2873
|
+
'[style.pointerEvents]': 'hbPointerEvents()',
|
|
2874
|
+
},
|
|
2648
2875
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2649
2876
|
}]
|
|
2650
|
-
}],
|
|
2877
|
+
}], propDecorators: { sceneGraph: [{
|
|
2651
2878
|
type: Input,
|
|
2652
2879
|
args: [{ required: true }]
|
|
2653
2880
|
}], sceneGraphInputs: [{
|
|
@@ -2686,34 +2913,58 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImpor
|
|
|
2686
2913
|
type: Input
|
|
2687
2914
|
}], created: [{
|
|
2688
2915
|
type: Output
|
|
2689
|
-
}], pointerMissed: [{
|
|
2690
|
-
type: Output
|
|
2691
2916
|
}], glCanvas: [{
|
|
2692
2917
|
type: ViewChild,
|
|
2693
2918
|
args: ['glCanvas', { static: true }]
|
|
2694
|
-
}], glAnchor: [{
|
|
2695
|
-
type: ViewChild,
|
|
2696
|
-
args: ['glCanvas', { static: true, read: ViewContainerRef }]
|
|
2697
2919
|
}] } });
|
|
2698
2920
|
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2921
|
+
class NgtKey extends NgtCommonDirective {
|
|
2922
|
+
constructor() {
|
|
2923
|
+
super(...arguments);
|
|
2924
|
+
this.lastKey = '';
|
|
2925
|
+
}
|
|
2926
|
+
static { this.processComment = false; }
|
|
2927
|
+
validate() {
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2930
|
+
set key(key) {
|
|
2931
|
+
const normalizedKey = JSON.stringify(key);
|
|
2932
|
+
if (this.lastKey !== normalizedKey) {
|
|
2933
|
+
this.lastKey = normalizedKey;
|
|
2934
|
+
this.createView();
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtKey, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2938
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtKey, isStandalone: true, selector: "ng-template[key]", inputs: { key: "key" }, usesInheritance: true, ngImport: i0 }); }
|
|
2939
|
+
}
|
|
2940
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtKey, decorators: [{
|
|
2941
|
+
type: Directive,
|
|
2942
|
+
args: [{ selector: 'ng-template[key]', standalone: true }]
|
|
2943
|
+
}], propDecorators: { key: [{
|
|
2944
|
+
type: Input
|
|
2945
|
+
}] } });
|
|
2946
|
+
|
|
2947
|
+
class NgtRepeat extends NgForOf {
|
|
2948
|
+
set ngForRepeat(count) {
|
|
2949
|
+
this.ngForOf = Number.isInteger(count) ? Array.from({ length: count }, (_, i) => i) : [];
|
|
2950
|
+
}
|
|
2951
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRepeat, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2952
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtRepeat, isStandalone: true, selector: "[ngFor][ngForRepeat]", inputs: { ngForRepeat: "ngForRepeat" }, usesInheritance: true, ngImport: i0 }); }
|
|
2707
2953
|
}
|
|
2954
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRepeat, decorators: [{
|
|
2955
|
+
type: Directive,
|
|
2956
|
+
args: [{ selector: '[ngFor][ngForRepeat]', standalone: true }]
|
|
2957
|
+
}], propDecorators: { ngForRepeat: [{
|
|
2958
|
+
type: Input
|
|
2959
|
+
}] } });
|
|
2708
2960
|
|
|
2709
|
-
function injectNgtRef(initial = null, injector
|
|
2710
|
-
|
|
2961
|
+
function injectNgtRef(initial = null, injector) {
|
|
2962
|
+
injector = assertInjectionContext(injectNgtRef);
|
|
2963
|
+
const ref = is.ref(initial) ? initial : new ElementRef(initial);
|
|
2964
|
+
const signalRef = signal(ref.nativeElement);
|
|
2965
|
+
const readonlySignal = signalRef.asReadonly();
|
|
2966
|
+
const cached = new Map();
|
|
2711
2967
|
return runInInjectionContext(injector, () => {
|
|
2712
|
-
const cdr = inject(ChangeDetectorRef);
|
|
2713
|
-
const ref = is.ref(initial) ? initial : new ElementRef(initial);
|
|
2714
|
-
const signalRef = signal(ref.nativeElement);
|
|
2715
|
-
const readonlySignal = signalRef.asReadonly();
|
|
2716
|
-
const cached = new Map();
|
|
2717
2968
|
inject(DestroyRef).onDestroy(() => void cached.clear());
|
|
2718
2969
|
const children = (type = 'objects') => {
|
|
2719
2970
|
if (!cached.has(type)) {
|
|
@@ -2733,33 +2984,24 @@ function injectNgtRef(initial = null, injector = inject(Injector, { optional: tr
|
|
|
2733
2984
|
}
|
|
2734
2985
|
return cached.get(type);
|
|
2735
2986
|
};
|
|
2736
|
-
Object.
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2987
|
+
Object.defineProperties(ref, {
|
|
2988
|
+
nativeElement: {
|
|
2989
|
+
set: (newElement) => {
|
|
2990
|
+
untracked(() => {
|
|
2991
|
+
if (newElement !== signalRef()) {
|
|
2992
|
+
signalRef.set(newElement);
|
|
2993
|
+
}
|
|
2994
|
+
});
|
|
2995
|
+
},
|
|
2996
|
+
get: readonlySignal,
|
|
2742
2997
|
},
|
|
2743
|
-
get: () => readonlySignal
|
|
2998
|
+
untracked: { get: () => untracked(readonlySignal) },
|
|
2999
|
+
children: { get: () => children },
|
|
2744
3000
|
});
|
|
2745
|
-
return
|
|
3001
|
+
return ref;
|
|
2746
3002
|
});
|
|
2747
3003
|
}
|
|
2748
3004
|
|
|
2749
|
-
class NgtRepeat extends NgForOf {
|
|
2750
|
-
set ngForRepeat(count) {
|
|
2751
|
-
this.ngForOf = Number.isInteger(count) ? Array.from({ length: count }, (_, i) => i) : [];
|
|
2752
|
-
}
|
|
2753
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtRepeat, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
2754
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: NgtRepeat, isStandalone: true, selector: "[ngFor][ngForRepeat]", inputs: { ngForRepeat: "ngForRepeat" }, usesInheritance: true, ngImport: i0 }); }
|
|
2755
|
-
}
|
|
2756
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NgtRepeat, decorators: [{
|
|
2757
|
-
type: Directive,
|
|
2758
|
-
args: [{ selector: '[ngFor][ngForRepeat]', standalone: true }]
|
|
2759
|
-
}], propDecorators: { ngForRepeat: [{
|
|
2760
|
-
type: Input
|
|
2761
|
-
}] } });
|
|
2762
|
-
|
|
2763
3005
|
const privateKeys = [
|
|
2764
3006
|
'get',
|
|
2765
3007
|
'set',
|
|
@@ -2774,21 +3016,17 @@ const privateKeys = [
|
|
|
2774
3016
|
'viewport',
|
|
2775
3017
|
];
|
|
2776
3018
|
class NgtPortalBeforeRender {
|
|
2777
|
-
#portalStore;
|
|
2778
|
-
#subscription;
|
|
2779
3019
|
constructor() {
|
|
2780
|
-
this
|
|
3020
|
+
this.portalStore = injectNgtStore();
|
|
3021
|
+
this.injector = inject(Injector);
|
|
2781
3022
|
this.renderPriority = 1;
|
|
2782
3023
|
this.beforeRender = new EventEmitter();
|
|
2783
|
-
inject(DestroyRef).onDestroy(() => {
|
|
2784
|
-
this.#subscription?.();
|
|
2785
|
-
});
|
|
2786
3024
|
}
|
|
2787
3025
|
ngOnInit() {
|
|
2788
3026
|
let oldClear;
|
|
2789
|
-
|
|
2790
|
-
this.beforeRender.emit({ ...this
|
|
2791
|
-
const { gl, scene, camera } = this
|
|
3027
|
+
injectBeforeRender(({ delta, frame }) => {
|
|
3028
|
+
this.beforeRender.emit({ ...this.portalStore.get(), delta, frame });
|
|
3029
|
+
const { gl, scene, camera } = this.portalStore.get();
|
|
2792
3030
|
oldClear = gl.autoClear;
|
|
2793
3031
|
if (this.renderPriority === 1) {
|
|
2794
3032
|
// clear scene and render with default
|
|
@@ -2801,15 +3039,15 @@ class NgtPortalBeforeRender {
|
|
|
2801
3039
|
gl.render(scene, camera);
|
|
2802
3040
|
// restore
|
|
2803
3041
|
gl.autoClear = oldClear;
|
|
2804
|
-
}, this.renderPriority, this
|
|
3042
|
+
}, { priority: this.renderPriority, injector: this.injector });
|
|
2805
3043
|
}
|
|
2806
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2807
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.
|
|
3044
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortalBeforeRender, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
3045
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtPortalBeforeRender, isStandalone: true, selector: "[ngtPortalBeforeRender]", inputs: { renderPriority: "renderPriority", parentScene: "parentScene", parentCamera: "parentCamera" }, outputs: { beforeRender: "beforeRender" }, ngImport: i0 }); }
|
|
2808
3046
|
}
|
|
2809
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
3047
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortalBeforeRender, decorators: [{
|
|
2810
3048
|
type: Directive,
|
|
2811
3049
|
args: [{ selector: '[ngtPortalBeforeRender]', standalone: true }]
|
|
2812
|
-
}],
|
|
3050
|
+
}], propDecorators: { renderPriority: [{
|
|
2813
3051
|
type: Input
|
|
2814
3052
|
}], parentScene: [{
|
|
2815
3053
|
type: Input,
|
|
@@ -2828,96 +3066,90 @@ class NgtPortalContent {
|
|
|
2828
3066
|
delete commentNode[SPECIAL_INTERNAL_ADD_COMMENT];
|
|
2829
3067
|
}
|
|
2830
3068
|
}
|
|
2831
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2832
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.
|
|
3069
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortalContent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ViewContainerRef, skipSelf: true }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
3070
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.7", type: NgtPortalContent, isStandalone: true, selector: "ng-template[ngtPortalContent]", ngImport: i0 }); }
|
|
2833
3071
|
}
|
|
2834
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
3072
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortalContent, decorators: [{
|
|
2835
3073
|
type: Directive,
|
|
2836
3074
|
args: [{ selector: 'ng-template[ngtPortalContent]', standalone: true }]
|
|
2837
3075
|
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.ViewContainerRef, decorators: [{
|
|
2838
3076
|
type: SkipSelf
|
|
2839
3077
|
}] }]; } });
|
|
2840
|
-
class NgtPortal
|
|
3078
|
+
class NgtPortal {
|
|
2841
3079
|
set container(container) {
|
|
2842
|
-
this.set({ container });
|
|
2843
|
-
}
|
|
2844
|
-
set
|
|
2845
|
-
this.set({ state });
|
|
2846
|
-
}
|
|
2847
|
-
#parentStore;
|
|
2848
|
-
#portalStore;
|
|
2849
|
-
#injector;
|
|
2850
|
-
#zone;
|
|
2851
|
-
#raycaster;
|
|
2852
|
-
#pointer;
|
|
2853
|
-
#portalContentView;
|
|
3080
|
+
this.inputs.set({ container });
|
|
3081
|
+
}
|
|
3082
|
+
set portalState(state) {
|
|
3083
|
+
this.inputs.set({ state });
|
|
3084
|
+
}
|
|
2854
3085
|
constructor() {
|
|
2855
|
-
|
|
3086
|
+
this.inputs = signalStore({ container: injectNgtRef(prepare(new THREE.Scene())) });
|
|
2856
3087
|
this.autoRender = true;
|
|
2857
3088
|
this.autoRenderPriority = 1;
|
|
2858
3089
|
this.beforeRender = new EventEmitter();
|
|
2859
|
-
this
|
|
2860
|
-
this.parentScene = this
|
|
2861
|
-
this.parentCamera = this
|
|
2862
|
-
this
|
|
2863
|
-
this
|
|
2864
|
-
this
|
|
2865
|
-
this
|
|
2866
|
-
this
|
|
3090
|
+
this.parentStore = injectNgtStore({ skipSelf: true });
|
|
3091
|
+
this.parentScene = this.parentStore.get('scene');
|
|
3092
|
+
this.parentCamera = this.parentStore.get('camera');
|
|
3093
|
+
this.portalStore = injectNgtStore({ self: true });
|
|
3094
|
+
this.injector = inject(Injector);
|
|
3095
|
+
this.zone = inject(NgZone);
|
|
3096
|
+
this.raycaster = new THREE.Raycaster();
|
|
3097
|
+
this.pointer = new THREE.Vector2();
|
|
2867
3098
|
this.portalContentRendered = false;
|
|
2868
3099
|
inject(DestroyRef).onDestroy(() => {
|
|
2869
|
-
if (this
|
|
2870
|
-
this
|
|
3100
|
+
if (this.portalContentView && !this.portalContentView.destroyed) {
|
|
3101
|
+
this.portalContentView.destroy();
|
|
2871
3102
|
}
|
|
2872
3103
|
});
|
|
2873
3104
|
}
|
|
2874
3105
|
ngOnInit() {
|
|
2875
|
-
const previousState = this
|
|
2876
|
-
const inputsState = this.get();
|
|
3106
|
+
const previousState = this.parentStore.get();
|
|
3107
|
+
const inputsState = this.inputs.get();
|
|
2877
3108
|
if (!inputsState.state && this.autoRender) {
|
|
2878
3109
|
inputsState.state = { events: { priority: this.autoRenderPriority + 1 } };
|
|
2879
3110
|
}
|
|
2880
3111
|
const { events, size, ...restInputsState } = inputsState.state || {};
|
|
2881
3112
|
const containerState = inputsState.container;
|
|
2882
|
-
|
|
3113
|
+
let container = is.ref(containerState) ? containerState.nativeElement : containerState;
|
|
3114
|
+
if (!is.instance(container)) {
|
|
3115
|
+
container = prepare(container);
|
|
3116
|
+
}
|
|
2883
3117
|
const localState = getLocalState(container);
|
|
2884
3118
|
if (!localState.store) {
|
|
2885
|
-
localState.store = this
|
|
3119
|
+
localState.store = this.portalStore;
|
|
2886
3120
|
}
|
|
2887
|
-
this
|
|
3121
|
+
this.portalStore.set({
|
|
2888
3122
|
...previousState,
|
|
2889
3123
|
scene: container,
|
|
2890
|
-
raycaster: this
|
|
2891
|
-
pointer: this
|
|
2892
|
-
|
|
3124
|
+
raycaster: this.raycaster,
|
|
3125
|
+
pointer: this.pointer,
|
|
3126
|
+
previousRoot: this.parentStore,
|
|
2893
3127
|
events: { ...previousState.events, ...(events || {}) },
|
|
2894
3128
|
size: { ...previousState.size, ...(size || {}) },
|
|
2895
3129
|
...restInputsState,
|
|
2896
|
-
|
|
2897
|
-
set: this.#portalStore.set.bind(this.#portalStore),
|
|
2898
|
-
setEvents: (events) => this.#portalStore.set((state) => ({ ...state, events: { ...state.events, ...events } })),
|
|
3130
|
+
setEvents: (events) => this.portalStore.set((state) => ({ ...state, events: { ...state.events, ...events } })),
|
|
2899
3131
|
});
|
|
2900
|
-
const parentState = this
|
|
3132
|
+
const parentState = this.parentStore.select();
|
|
2901
3133
|
effect(() => {
|
|
2902
3134
|
const previous = parentState();
|
|
2903
|
-
this
|
|
2904
|
-
this
|
|
3135
|
+
this.zone.runOutsideAngular(() => {
|
|
3136
|
+
this.portalStore.set((state) => this.inject(previous, state));
|
|
2905
3137
|
});
|
|
2906
|
-
}, { injector: this
|
|
3138
|
+
}, { injector: this.injector });
|
|
2907
3139
|
requestAnimationFrame(() => {
|
|
2908
|
-
this
|
|
3140
|
+
this.portalStore.set((injectState) => this.inject(this.parentStore.get(), injectState));
|
|
2909
3141
|
});
|
|
2910
|
-
this
|
|
2911
|
-
safeDetectChanges(this
|
|
3142
|
+
this.portalContentView = this.portalContentAnchor.createEmbeddedView(this.portalContentTemplate);
|
|
3143
|
+
safeDetectChanges(this.portalContentView);
|
|
2912
3144
|
this.portalContentRendered = true;
|
|
2913
3145
|
}
|
|
2914
3146
|
onBeforeRender(portal) {
|
|
2915
3147
|
this.beforeRender.emit({
|
|
2916
|
-
root: { ...this
|
|
3148
|
+
root: { ...this.parentStore.get(), delta: portal.delta, frame: portal.frame },
|
|
2917
3149
|
portal,
|
|
2918
3150
|
});
|
|
2919
3151
|
}
|
|
2920
|
-
|
|
3152
|
+
inject(rootState, injectState) {
|
|
2921
3153
|
const intersect = { ...rootState };
|
|
2922
3154
|
Object.keys(intersect).forEach((key) => {
|
|
2923
3155
|
if (privateKeys.includes(key) ||
|
|
@@ -2925,7 +3157,7 @@ class NgtPortal extends NgtSignalStore {
|
|
|
2925
3157
|
delete intersect[key];
|
|
2926
3158
|
}
|
|
2927
3159
|
});
|
|
2928
|
-
const inputs = this.get();
|
|
3160
|
+
const inputs = this.inputs.get();
|
|
2929
3161
|
const { size, events, ...restInputsState } = inputs.state || {};
|
|
2930
3162
|
let viewport = undefined;
|
|
2931
3163
|
if (injectState && size) {
|
|
@@ -2937,53 +3169,54 @@ class NgtPortal extends NgtSignalStore {
|
|
|
2937
3169
|
return {
|
|
2938
3170
|
...intersect,
|
|
2939
3171
|
scene: is.ref(inputs.container) ? inputs.container.nativeElement : inputs.container,
|
|
2940
|
-
raycaster: this
|
|
2941
|
-
pointer: this
|
|
2942
|
-
|
|
3172
|
+
raycaster: this.raycaster,
|
|
3173
|
+
pointer: this.pointer,
|
|
3174
|
+
previousRoot: this.parentStore,
|
|
2943
3175
|
events: { ...rootState.events, ...(injectState?.events || {}), ...events },
|
|
2944
3176
|
size: { ...rootState.size, ...size },
|
|
2945
3177
|
viewport: { ...rootState.viewport, ...(viewport || {}) },
|
|
2946
3178
|
...restInputsState,
|
|
2947
3179
|
};
|
|
2948
3180
|
}
|
|
2949
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
2950
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
3181
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortal, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3182
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: NgtPortal, isStandalone: true, selector: "ngt-portal", inputs: { container: "container", portalState: ["state", "portalState"], autoRender: "autoRender", autoRenderPriority: "autoRenderPriority" }, outputs: { beforeRender: "beforeRender" }, providers: [{ provide: NGT_STORE, useFactory: () => signalStore({}) }], queries: [{ propertyName: "portalContentTemplate", first: true, predicate: NgtPortalContent, descendants: true, read: TemplateRef, static: true }], viewQueries: [{ propertyName: "portalContentAnchor", first: true, predicate: ["portalContentAnchor"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: `
|
|
3183
|
+
<ng-container #portalContentAnchor>
|
|
3184
|
+
<ng-container
|
|
3185
|
+
*ngIf="autoRender && portalContentRendered"
|
|
3186
|
+
ngtPortalBeforeRender
|
|
3187
|
+
[renderPriority]="autoRenderPriority"
|
|
3188
|
+
[parentScene]="parentScene"
|
|
3189
|
+
[parentCamera]="parentCamera"
|
|
3190
|
+
(beforeRender)="onBeforeRender($event)"
|
|
3191
|
+
/>
|
|
3192
|
+
</ng-container>
|
|
3193
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgtPortalBeforeRender, selector: "[ngtPortalBeforeRender]", inputs: ["renderPriority", "parentScene", "parentCamera"], outputs: ["beforeRender"] }] }); }
|
|
2962
3194
|
}
|
|
2963
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
3195
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtPortal, decorators: [{
|
|
2964
3196
|
type: Component,
|
|
2965
3197
|
args: [{
|
|
2966
3198
|
selector: 'ngt-portal',
|
|
2967
3199
|
standalone: true,
|
|
2968
3200
|
template: `
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
3201
|
+
<ng-container #portalContentAnchor>
|
|
3202
|
+
<ng-container
|
|
3203
|
+
*ngIf="autoRender && portalContentRendered"
|
|
3204
|
+
ngtPortalBeforeRender
|
|
3205
|
+
[renderPriority]="autoRenderPriority"
|
|
3206
|
+
[parentScene]="parentScene"
|
|
3207
|
+
[parentCamera]="parentCamera"
|
|
3208
|
+
(beforeRender)="onBeforeRender($event)"
|
|
3209
|
+
/>
|
|
3210
|
+
</ng-container>
|
|
3211
|
+
`,
|
|
2980
3212
|
imports: [NgIf, NgtPortalBeforeRender],
|
|
2981
|
-
providers: [
|
|
3213
|
+
providers: [{ provide: NGT_STORE, useFactory: () => signalStore({}) }],
|
|
2982
3214
|
}]
|
|
2983
3215
|
}], ctorParameters: function () { return []; }, propDecorators: { container: [{
|
|
2984
3216
|
type: Input
|
|
2985
|
-
}],
|
|
2986
|
-
type: Input
|
|
3217
|
+
}], portalState: [{
|
|
3218
|
+
type: Input,
|
|
3219
|
+
args: ['state']
|
|
2987
3220
|
}], autoRender: [{
|
|
2988
3221
|
type: Input
|
|
2989
3222
|
}], autoRenderPriority: [{
|
|
@@ -3007,10 +3240,10 @@ class NgtRoutedScene {
|
|
|
3007
3240
|
.pipe(filter((event) => event instanceof ActivationEnd), takeUntilDestroyed())
|
|
3008
3241
|
.subscribe(() => safeDetectChanges(cdr));
|
|
3009
3242
|
}
|
|
3010
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.
|
|
3011
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.
|
|
3243
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRoutedScene, deps: [{ token: i1.Router }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3244
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.7", type: NgtRoutedScene, isStandalone: true, selector: "ngt-routed-scene", ngImport: i0, template: `<router-outlet />`, isInline: true, dependencies: [{ kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }] }); }
|
|
3012
3245
|
}
|
|
3013
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.
|
|
3246
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.7", ngImport: i0, type: NgtRoutedScene, decorators: [{
|
|
3014
3247
|
type: Component,
|
|
3015
3248
|
args: [{
|
|
3016
3249
|
standalone: true,
|
|
@@ -3024,5 +3257,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImpor
|
|
|
3024
3257
|
* Generated bundle index. Do not edit.
|
|
3025
3258
|
*/
|
|
3026
3259
|
|
|
3027
|
-
export {
|
|
3260
|
+
export { HTML, NGT_STORE, NgtArgs, NgtCanvas, NgtKey, NgtParent, NgtPortal, NgtPortalContent, NgtRepeat, NgtRoutedScene, addAfterEffect, addEffect, addTail, applyProps, assertInjectionContext, checkNeedsUpdate, checkUpdate, createAttachFunction, createInjectionToken, diffProps, extend, getLocalState, injectBeforeRender, injectNgtLoader, injectNgtRef, injectNgtStore, invalidateInstance, is, makeDefaultCamera, makeDefaultRenderer, makeDpr, makeId, makeObjectGraph, prepare, provideNgtRenderer, provideNgtStore, safeDetectChanges, signalStore, updateCamera };
|
|
3028
3261
|
//# sourceMappingURL=angular-three.mjs.map
|