angular-three 1.0.0-beta.0 → 1.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 +55 -4
- package/esm2020/index.mjs +12 -2
- package/esm2020/lib/canvas.mjs +24 -29
- package/esm2020/lib/di/before-render.mjs +15 -0
- package/esm2020/lib/di/destroy.mjs +24 -0
- package/esm2020/lib/di/ref.mjs +71 -0
- package/esm2020/lib/loader.mjs +2 -2
- package/esm2020/lib/pipes/push.mjs +54 -0
- package/esm2020/lib/stores/store.mjs +2 -2
- package/fesm2015/angular-three.mjs +275 -128
- package/fesm2015/angular-three.mjs.map +1 -1
- package/fesm2020/angular-three.mjs +280 -134
- package/fesm2020/angular-three.mjs.map +1 -1
- package/index.d.ts +11 -1
- package/lib/canvas.d.ts +3 -7
- package/lib/di/before-render.d.ts +2 -0
- package/lib/di/destroy.d.ts +9 -0
- package/lib/di/ref.d.ts +12 -0
- package/lib/loader.d.ts +1 -1
- package/lib/pipes/push.d.ts +15 -0
- package/package.json +3 -4
|
@@ -1,13 +1,109 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { ElementRef, Injectable, inject, InjectionToken, ViewContainerRef, TemplateRef, Directive, Input, EventEmitter, getDebugNode, ChangeDetectorRef, RendererFactory2,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ElementRef, Injectable, inject, InjectionToken, ViewContainerRef, TemplateRef, Directive, Input, EventEmitter, getDebugNode, ChangeDetectorRef, RendererFactory2, EnvironmentInjector, createEnvironmentInjector, Component, HostBinding, Output, ViewChild, Pipe } from '@angular/core';
|
|
3
|
+
import { provideNgxResizeOptions, NgxResize } from 'ngx-resize';
|
|
4
|
+
import { isObservable, of, map, from, tap, retry, catchError, share, ReplaySubject, switchMap, forkJoin, take, BehaviorSubject, startWith, filter, distinctUntilChanged, takeUntil, merge } from 'rxjs';
|
|
5
|
+
import * as THREE from 'three';
|
|
5
6
|
import { __rest } from 'tslib';
|
|
6
7
|
import { DOCUMENT, NgForOf } from '@angular/common';
|
|
7
8
|
import { RxState, selectSlice } from '@rx-angular/state';
|
|
8
|
-
import * as THREE from 'three';
|
|
9
9
|
import { ɵDomRendererFactory2 } from '@angular/platform-browser';
|
|
10
10
|
|
|
11
|
+
const idCache = {};
|
|
12
|
+
function makeId(event) {
|
|
13
|
+
if (event) {
|
|
14
|
+
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
15
|
+
}
|
|
16
|
+
const newId = THREE.MathUtils.generateUUID();
|
|
17
|
+
// ensure not already used
|
|
18
|
+
if (!idCache[newId]) {
|
|
19
|
+
idCache[newId] = true;
|
|
20
|
+
return newId;
|
|
21
|
+
}
|
|
22
|
+
return makeId();
|
|
23
|
+
}
|
|
24
|
+
function makeDpr(dpr, window) {
|
|
25
|
+
const target = (window === null || window === void 0 ? void 0 : window.devicePixelRatio) || 1;
|
|
26
|
+
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
27
|
+
}
|
|
28
|
+
function makeDefaultCamera(isOrthographic, size) {
|
|
29
|
+
if (isOrthographic)
|
|
30
|
+
return new THREE.OrthographicCamera(0, 0, 0, 0, 0.1, 1000);
|
|
31
|
+
return new THREE.PerspectiveCamera(75, size.width / size.height, 0.1, 1000);
|
|
32
|
+
}
|
|
33
|
+
function makeDefaultRenderer(glOptions, canvasElement) {
|
|
34
|
+
const customRenderer = (typeof glOptions === 'function' ? glOptions(canvasElement) : glOptions);
|
|
35
|
+
if ((customRenderer === null || customRenderer === void 0 ? void 0 : customRenderer.render) != null)
|
|
36
|
+
return customRenderer;
|
|
37
|
+
return new THREE.WebGLRenderer(Object.assign({ powerPreference: 'high-performance', canvas: canvasElement, antialias: true, alpha: true }, (glOptions || {})));
|
|
38
|
+
}
|
|
39
|
+
function makeObjectGraph(object) {
|
|
40
|
+
const data = { nodes: {}, materials: {} };
|
|
41
|
+
if (object) {
|
|
42
|
+
object.traverse((child) => {
|
|
43
|
+
if (child.name)
|
|
44
|
+
data.nodes[child.name] = child;
|
|
45
|
+
if ('material' in child && !data.materials[child.material.name]) {
|
|
46
|
+
data.materials[child.material.name] = child
|
|
47
|
+
.material;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cached = new Map();
|
|
55
|
+
function injectLoader(loaderConstructorFactory, input, extensions, onProgress) {
|
|
56
|
+
const urls$ = isObservable(input) ? input : of(input);
|
|
57
|
+
return urls$.pipe(map((inputs) => {
|
|
58
|
+
const loaderConstructor = loaderConstructorFactory(inputs);
|
|
59
|
+
const loader = new loaderConstructor();
|
|
60
|
+
if (extensions) {
|
|
61
|
+
extensions(loader);
|
|
62
|
+
}
|
|
63
|
+
const urls = Array.isArray(inputs) ? inputs : typeof inputs === 'string' ? [inputs] : Object.values(inputs);
|
|
64
|
+
return [
|
|
65
|
+
urls.map((url) => {
|
|
66
|
+
if (!cached.has(url)) {
|
|
67
|
+
cached.set(url, from(loader.loadAsync(url, onProgress)).pipe(tap((data) => {
|
|
68
|
+
if (data.scene) {
|
|
69
|
+
Object.assign(data, makeObjectGraph(data.scene));
|
|
70
|
+
}
|
|
71
|
+
}), retry(2), catchError((err) => {
|
|
72
|
+
console.error(`[NGT] Error loading ${url}: ${err.message}`);
|
|
73
|
+
return of([]);
|
|
74
|
+
}), share({
|
|
75
|
+
connector: () => new ReplaySubject(1),
|
|
76
|
+
resetOnComplete: true,
|
|
77
|
+
resetOnError: true,
|
|
78
|
+
resetOnRefCountZero: true,
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
81
|
+
return cached.get(url);
|
|
82
|
+
}),
|
|
83
|
+
inputs,
|
|
84
|
+
];
|
|
85
|
+
}), switchMap(([observables$, inputs]) => {
|
|
86
|
+
return forkJoin(observables$).pipe(map((results) => {
|
|
87
|
+
if (Array.isArray(inputs))
|
|
88
|
+
return results;
|
|
89
|
+
if (typeof inputs === 'string')
|
|
90
|
+
return results[0];
|
|
91
|
+
const keys = Object.keys(inputs);
|
|
92
|
+
return keys.reduce((result, key) => {
|
|
93
|
+
result[key] = results[keys.indexOf(key)];
|
|
94
|
+
return result;
|
|
95
|
+
}, {});
|
|
96
|
+
}));
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
injectLoader.destroy = () => {
|
|
100
|
+
cached.clear();
|
|
101
|
+
};
|
|
102
|
+
injectLoader.preLoad = (loaderConstructorFactory, inputs, extensions) => {
|
|
103
|
+
injectLoader(loaderConstructorFactory, inputs, extensions).pipe(take(1)).subscribe();
|
|
104
|
+
};
|
|
105
|
+
const injectNgtLoader = injectLoader;
|
|
106
|
+
|
|
11
107
|
function createSubs(callback, subs) {
|
|
12
108
|
const sub = { callback };
|
|
13
109
|
subs.add(sub);
|
|
@@ -358,49 +454,6 @@ function applyProps(instance, props) {
|
|
|
358
454
|
return instance;
|
|
359
455
|
}
|
|
360
456
|
|
|
361
|
-
const idCache = {};
|
|
362
|
-
function makeId(event) {
|
|
363
|
-
if (event) {
|
|
364
|
-
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
365
|
-
}
|
|
366
|
-
const newId = THREE.MathUtils.generateUUID();
|
|
367
|
-
// ensure not already used
|
|
368
|
-
if (!idCache[newId]) {
|
|
369
|
-
idCache[newId] = true;
|
|
370
|
-
return newId;
|
|
371
|
-
}
|
|
372
|
-
return makeId();
|
|
373
|
-
}
|
|
374
|
-
function makeDpr(dpr, window) {
|
|
375
|
-
const target = (window === null || window === void 0 ? void 0 : window.devicePixelRatio) || 1;
|
|
376
|
-
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
377
|
-
}
|
|
378
|
-
function makeDefaultCamera(isOrthographic, size) {
|
|
379
|
-
if (isOrthographic)
|
|
380
|
-
return new THREE.OrthographicCamera(0, 0, 0, 0, 0.1, 1000);
|
|
381
|
-
return new THREE.PerspectiveCamera(75, size.width / size.height, 0.1, 1000);
|
|
382
|
-
}
|
|
383
|
-
function makeDefaultRenderer(glOptions, canvasElement) {
|
|
384
|
-
const customRenderer = (typeof glOptions === 'function' ? glOptions(canvasElement) : glOptions);
|
|
385
|
-
if ((customRenderer === null || customRenderer === void 0 ? void 0 : customRenderer.render) != null)
|
|
386
|
-
return customRenderer;
|
|
387
|
-
return new THREE.WebGLRenderer(Object.assign({ powerPreference: 'high-performance', canvas: canvasElement, antialias: true, alpha: true }, (glOptions || {})));
|
|
388
|
-
}
|
|
389
|
-
function makeObjectGraph(object) {
|
|
390
|
-
const data = { nodes: {}, materials: {} };
|
|
391
|
-
if (object) {
|
|
392
|
-
object.traverse((child) => {
|
|
393
|
-
if (child.name)
|
|
394
|
-
data.nodes[child.name] = child;
|
|
395
|
-
if ('material' in child && !data.materials[child.material.name]) {
|
|
396
|
-
data.materials[child.material.name] = child
|
|
397
|
-
.material;
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
return data;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
457
|
const startWithUndefined = () => startWith(undefined);
|
|
405
458
|
/**
|
|
406
459
|
* An extended `tap` operator that accepts an `effectFn` which:
|
|
@@ -768,7 +821,7 @@ class NgtStore extends NgtRxStore {
|
|
|
768
821
|
// Safely set color management if available.
|
|
769
822
|
// Avoid accessing THREE.ColorManagement to play nice with older versions
|
|
770
823
|
if (THREE.ColorManagement)
|
|
771
|
-
THREE.ColorManagement.legacyMode =
|
|
824
|
+
THREE.ColorManagement.legacyMode = legacy !== null && legacy !== void 0 ? legacy : true;
|
|
772
825
|
const outputEncoding = linear ? THREE.LinearEncoding : THREE.sRGBEncoding;
|
|
773
826
|
const toneMapping = flat ? THREE.NoToneMapping : THREE.ACESFilmicToneMapping;
|
|
774
827
|
if (gl.outputEncoding !== outputEncoding)
|
|
@@ -2160,72 +2213,6 @@ function createPointerEvents(store) {
|
|
|
2160
2213
|
};
|
|
2161
2214
|
}
|
|
2162
2215
|
|
|
2163
|
-
const cached = new Map();
|
|
2164
|
-
function injectLoader(loaderConstructorFactory, input, extensions, onProgress) {
|
|
2165
|
-
const urls$ = isObservable(input) ? input : of(input);
|
|
2166
|
-
return urls$.pipe(map((inputs) => {
|
|
2167
|
-
const loaderConstructor = loaderConstructorFactory(inputs);
|
|
2168
|
-
const loader = new loaderConstructor();
|
|
2169
|
-
if (extensions) {
|
|
2170
|
-
extensions(loader);
|
|
2171
|
-
}
|
|
2172
|
-
const urls = Array.isArray(inputs) ? inputs : typeof inputs === 'string' ? [inputs] : Object.values(inputs);
|
|
2173
|
-
return [
|
|
2174
|
-
urls.map((url) => {
|
|
2175
|
-
if (!cached.has(url)) {
|
|
2176
|
-
cached.set(url, from(loader.loadAsync(url, onProgress)).pipe(tap((data) => {
|
|
2177
|
-
if (data.scene) {
|
|
2178
|
-
Object.assign(data, makeObjectGraph(data.scene));
|
|
2179
|
-
}
|
|
2180
|
-
}), retry(2), catchError((err) => {
|
|
2181
|
-
console.error(`[NGT] Error loading ${url}: ${err.message}`);
|
|
2182
|
-
return of([]);
|
|
2183
|
-
}), share({
|
|
2184
|
-
connector: () => new ReplaySubject(1),
|
|
2185
|
-
resetOnComplete: true,
|
|
2186
|
-
resetOnError: true,
|
|
2187
|
-
resetOnRefCountZero: true,
|
|
2188
|
-
})));
|
|
2189
|
-
}
|
|
2190
|
-
return cached.get(url);
|
|
2191
|
-
}),
|
|
2192
|
-
inputs,
|
|
2193
|
-
];
|
|
2194
|
-
}), switchMap(([observables$, inputs]) => {
|
|
2195
|
-
return forkJoin(observables$).pipe(map((results) => {
|
|
2196
|
-
if (Array.isArray(inputs))
|
|
2197
|
-
return results;
|
|
2198
|
-
if (typeof inputs === 'string')
|
|
2199
|
-
return results[0];
|
|
2200
|
-
const keys = Object.keys(inputs);
|
|
2201
|
-
return keys.reduce((result, key) => {
|
|
2202
|
-
result[key] = results[keys.indexOf(key)];
|
|
2203
|
-
return result;
|
|
2204
|
-
}, {});
|
|
2205
|
-
}));
|
|
2206
|
-
}));
|
|
2207
|
-
}
|
|
2208
|
-
injectLoader.destroy = () => {
|
|
2209
|
-
cached.clear();
|
|
2210
|
-
};
|
|
2211
|
-
injectLoader.preLoad = (loaderConstructorFactory, inputs, extensions) => {
|
|
2212
|
-
injectLoader(loaderConstructorFactory, inputs, extensions).pipe(take(1)).subscribe();
|
|
2213
|
-
};
|
|
2214
|
-
const injectNgtLoader = injectLoader;
|
|
2215
|
-
|
|
2216
|
-
class NgtCanvasContainer {
|
|
2217
|
-
constructor() {
|
|
2218
|
-
this.canvasResize = injectNgxResize();
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
NgtCanvasContainer.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtCanvasContainer, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2222
|
-
NgtCanvasContainer.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: NgtCanvasContainer, isStandalone: true, selector: "ngt-canvas-container", outputs: { canvasResize: "canvasResize" }, providers: [provideNgxResizeOptions({ emitInZone: false })], ngImport: i0, template: '<ng-content />', isInline: true, styles: [":host{display:block;width:100%;height:100%}\n"] });
|
|
2223
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtCanvasContainer, decorators: [{
|
|
2224
|
-
type: Component,
|
|
2225
|
-
args: [{ selector: 'ngt-canvas-container', standalone: true, template: '<ng-content />', providers: [provideNgxResizeOptions({ emitInZone: false })], styles: [":host{display:block;width:100%;height:100%}\n"] }]
|
|
2226
|
-
}], propDecorators: { canvasResize: [{
|
|
2227
|
-
type: Output
|
|
2228
|
-
}] } });
|
|
2229
2216
|
class NgtCanvas extends NgtRxStore {
|
|
2230
2217
|
constructor() {
|
|
2231
2218
|
super(...arguments);
|
|
@@ -2364,9 +2351,12 @@ class NgtCanvas extends NgtRxStore {
|
|
|
2364
2351
|
compoundPrefixes: this.compoundPrefixes,
|
|
2365
2352
|
}),
|
|
2366
2353
|
], this.envInjector);
|
|
2367
|
-
this.glRef = this.glAnchor.createComponent(this.
|
|
2368
|
-
|
|
2354
|
+
this.glRef = this.glAnchor.createComponent(this.sceneGraph, {
|
|
2355
|
+
environmentInjector: this.glEnvInjector,
|
|
2356
|
+
});
|
|
2369
2357
|
this.glRef.changeDetectorRef.detach();
|
|
2358
|
+
// here, we override the detectChanges to also call detectChanges on the ComponentRef
|
|
2359
|
+
this.overrideDetectChanges();
|
|
2370
2360
|
this.cdr.detectChanges();
|
|
2371
2361
|
});
|
|
2372
2362
|
}
|
|
@@ -2380,29 +2370,35 @@ class NgtCanvas extends NgtRxStore {
|
|
|
2380
2370
|
injectNgtLoader.destroy();
|
|
2381
2371
|
super.ngOnDestroy();
|
|
2382
2372
|
}
|
|
2373
|
+
overrideDetectChanges() {
|
|
2374
|
+
const originalDetectChanges = this.cdr.detectChanges.bind(this.cdr);
|
|
2375
|
+
this.cdr.detectChanges = () => {
|
|
2376
|
+
var _a;
|
|
2377
|
+
originalDetectChanges();
|
|
2378
|
+
(_a = this.glRef) === null || _a === void 0 ? void 0 : _a.changeDetectorRef.detectChanges();
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2383
2381
|
}
|
|
2384
2382
|
NgtCanvas.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtCanvas, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
2385
|
-
NgtCanvas.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: NgtCanvas, isStandalone: true, selector: "ngt-canvas", inputs: {
|
|
2386
|
-
<
|
|
2383
|
+
NgtCanvas.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: NgtCanvas, isStandalone: true, selector: "ngt-canvas", inputs: { sceneGraph: "sceneGraph", compoundPrefixes: "compoundPrefixes", linear: "linear", legacy: "legacy", flat: "flat", orthographic: "orthographic", frameloop: "frameloop", dpr: "dpr", raycaster: "raycaster", shadows: "shadows", camera: "camera", gl: "gl", eventSource: "eventSource", eventPrefix: "eventPrefix", lookAt: "lookAt", performance: "performance" }, outputs: { created: "created", pointerMissed: "pointerMissed" }, host: { properties: { "class.ngt-canvas": "this.hostClass", "style.pointerEvents": "this.pointerEvents" } }, providers: [NgtStore, provideNgxResizeOptions({ emitInZone: false })], viewQueries: [{ propertyName: "glCanvas", first: true, predicate: ["glCanvas"], descendants: true, static: true }, { propertyName: "glAnchor", first: true, predicate: ["glCanvas"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, ngImport: i0, template: `
|
|
2384
|
+
<div (ngxResize)="onResize($event)" style="height: 100%; width: 100%;">
|
|
2387
2385
|
<canvas #glCanvas style="display: block;"></canvas>
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
`, isInline: true, styles: [":host{display:block;position:relative;width:100%;height:100%;overflow:hidden}\n"], dependencies: [{ kind: "component", type: NgtCanvasContainer, selector: "ngt-canvas-container", outputs: ["canvasResize"] }] });
|
|
2386
|
+
</div>
|
|
2387
|
+
`, isInline: true, styles: [":host{display:block;position:relative;width:100%;height:100%;overflow:hidden}\n"], dependencies: [{ kind: "directive", type: NgxResize, selector: "[ngxResize]", inputs: ["ngxResizeOptions"], outputs: ["ngxResize"] }] });
|
|
2391
2388
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtCanvas, decorators: [{
|
|
2392
2389
|
type: Component,
|
|
2393
2390
|
args: [{ selector: 'ngt-canvas', standalone: true, template: `
|
|
2394
|
-
<
|
|
2391
|
+
<div (ngxResize)="onResize($event)" style="height: 100%; width: 100%;">
|
|
2395
2392
|
<canvas #glCanvas style="display: block;"></canvas>
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
`, imports: [NgtCanvasContainer], providers: [NgtStore], styles: [":host{display:block;position:relative;width:100%;height:100%;overflow:hidden}\n"] }]
|
|
2393
|
+
</div>
|
|
2394
|
+
`, imports: [NgxResize], providers: [NgtStore, provideNgxResizeOptions({ emitInZone: false })], styles: [":host{display:block;position:relative;width:100%;height:100%;overflow:hidden}\n"] }]
|
|
2399
2395
|
}], propDecorators: { hostClass: [{
|
|
2400
2396
|
type: HostBinding,
|
|
2401
2397
|
args: ['class.ngt-canvas']
|
|
2402
2398
|
}], pointerEvents: [{
|
|
2403
2399
|
type: HostBinding,
|
|
2404
2400
|
args: ['style.pointerEvents']
|
|
2405
|
-
}],
|
|
2401
|
+
}], sceneGraph: [{
|
|
2406
2402
|
type: Input
|
|
2407
2403
|
}], compoundPrefixes: [{
|
|
2408
2404
|
type: Input
|
|
@@ -2443,9 +2439,109 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
2443
2439
|
args: ['glCanvas', { static: true }]
|
|
2444
2440
|
}], glAnchor: [{
|
|
2445
2441
|
type: ViewChild,
|
|
2446
|
-
args: ['
|
|
2442
|
+
args: ['glCanvas', { static: true, read: ViewContainerRef }]
|
|
2447
2443
|
}] } });
|
|
2448
2444
|
|
|
2445
|
+
/**
|
|
2446
|
+
* A utility injection fn that can be used in other injection fn to provide the destroy capability.
|
|
2447
|
+
*/
|
|
2448
|
+
function injectNgtDestroy(cb) {
|
|
2449
|
+
try {
|
|
2450
|
+
const cdr = inject(ChangeDetectorRef);
|
|
2451
|
+
const destroy$ = new ReplaySubject();
|
|
2452
|
+
queueMicrotask(() => {
|
|
2453
|
+
cdr.onDestroy(() => {
|
|
2454
|
+
destroy$.next();
|
|
2455
|
+
destroy$.complete();
|
|
2456
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
2457
|
+
});
|
|
2458
|
+
});
|
|
2459
|
+
return { destroy$, cdr };
|
|
2460
|
+
}
|
|
2461
|
+
catch (e) {
|
|
2462
|
+
console.warn(`[NGT] injectNgtDestroy is being called outside of Constructor Context`);
|
|
2463
|
+
return {};
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
function injectBeforeRender(cb, priority = 0) {
|
|
2468
|
+
try {
|
|
2469
|
+
const store = inject(NgtStore);
|
|
2470
|
+
const sub = store.get('internal').subscribe((state) => cb(state), priority, store);
|
|
2471
|
+
injectNgtDestroy(() => void sub());
|
|
2472
|
+
return sub;
|
|
2473
|
+
}
|
|
2474
|
+
catch (e) {
|
|
2475
|
+
throw new Error(`[NGT] "injectBeforeRender" is invoked outside of Constructor Context`);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
function injectNgtRef(initialValue = null) {
|
|
2480
|
+
let ref = new ElementRef(initialValue);
|
|
2481
|
+
if (is.ref(initialValue)) {
|
|
2482
|
+
ref = initialValue;
|
|
2483
|
+
}
|
|
2484
|
+
let lastValue = ref.nativeElement;
|
|
2485
|
+
const cdRefs = [];
|
|
2486
|
+
const ref$ = new BehaviorSubject(lastValue);
|
|
2487
|
+
const { destroy$, cdr } = injectNgtDestroy(() => {
|
|
2488
|
+
ref$.complete();
|
|
2489
|
+
});
|
|
2490
|
+
cdRefs.push(cdr);
|
|
2491
|
+
const obs$ = ref$.asObservable().pipe(distinctUntilChanged(), takeUntil(destroy$));
|
|
2492
|
+
const subscribe = (callback) => {
|
|
2493
|
+
return obs$.subscribe((current) => {
|
|
2494
|
+
callback(current, lastValue);
|
|
2495
|
+
lastValue = current;
|
|
2496
|
+
});
|
|
2497
|
+
};
|
|
2498
|
+
const $ = obs$.pipe(filter((value, index) => index > 0 || value != null), takeUntil(destroy$));
|
|
2499
|
+
const children$ = (type = 'objects') => $.pipe(switchMap((instance) => {
|
|
2500
|
+
const localState = getLocalState(instance);
|
|
2501
|
+
if (localState.objects && localState.nonObjects) {
|
|
2502
|
+
return merge(localState.objects, localState.nonObjects).pipe(map(() => {
|
|
2503
|
+
try {
|
|
2504
|
+
return type === 'both'
|
|
2505
|
+
? [...localState.objects.value, ...localState.nonObjects.value]
|
|
2506
|
+
: localState[type].value;
|
|
2507
|
+
}
|
|
2508
|
+
catch (e) {
|
|
2509
|
+
console.error(`[NGT] Exception in accessing children of ${instance}`);
|
|
2510
|
+
return [];
|
|
2511
|
+
}
|
|
2512
|
+
}));
|
|
2513
|
+
}
|
|
2514
|
+
return of([]);
|
|
2515
|
+
}), filter((children, index) => index > 0 || children.length > 0), takeUntil(destroy$));
|
|
2516
|
+
Object.defineProperty(ref, 'nativeElement', {
|
|
2517
|
+
set: (newVal) => {
|
|
2518
|
+
if (ref.nativeElement !== newVal) {
|
|
2519
|
+
ref$.next(newVal);
|
|
2520
|
+
lastValue = ref.nativeElement;
|
|
2521
|
+
ref.nativeElement = newVal;
|
|
2522
|
+
// clone the cdRefs so we can mutate cdRefs in the loop
|
|
2523
|
+
const cds = [...cdRefs];
|
|
2524
|
+
for (let i = 0; i < cds.length; i++) {
|
|
2525
|
+
const cd = cds[i];
|
|
2526
|
+
// if a ChangeDetectorRef is destroyed, we stop tracking it and go to the next one
|
|
2527
|
+
if (cd.destroyed) {
|
|
2528
|
+
cdRefs.splice(i, 1);
|
|
2529
|
+
continue;
|
|
2530
|
+
}
|
|
2531
|
+
// during creation phase, 'context' on ViewRef will be null
|
|
2532
|
+
// we check the "context" to avoid running detectChanges during this phase.
|
|
2533
|
+
// becuase there's nothing to check
|
|
2534
|
+
if (cd['context']) {
|
|
2535
|
+
cd.detectChanges();
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
},
|
|
2540
|
+
get: () => ref$.value,
|
|
2541
|
+
});
|
|
2542
|
+
return Object.assign(ref, { subscribe, $, children$, useCDR: (cdr) => void cdRefs.push(cdr) });
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2449
2545
|
class NgtRepeat extends NgForOf {
|
|
2450
2546
|
set ngForRepeat(count) {
|
|
2451
2547
|
this.ngForOf = Number.isInteger(count) ? Array.from({ length: count }, (_, i) => i) : [];
|
|
@@ -2460,9 +2556,60 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
2460
2556
|
type: Input
|
|
2461
2557
|
}] } });
|
|
2462
2558
|
|
|
2559
|
+
function isPromise(value) {
|
|
2560
|
+
return ((value instanceof Promise || Object.prototype.toString.call(value) === '[object Promise]') &&
|
|
2561
|
+
typeof value['then'] === 'function');
|
|
2562
|
+
}
|
|
2563
|
+
class NgtPush {
|
|
2564
|
+
constructor() {
|
|
2565
|
+
this.cdr = inject(ChangeDetectorRef);
|
|
2566
|
+
this.parentCdr = inject(ChangeDetectorRef, { skipSelf: true, optional: true });
|
|
2567
|
+
}
|
|
2568
|
+
transform(value, defaultValue = null) {
|
|
2569
|
+
if (this.obj === value) {
|
|
2570
|
+
return this.latestValue;
|
|
2571
|
+
}
|
|
2572
|
+
this.obj = value;
|
|
2573
|
+
this.latestValue = defaultValue;
|
|
2574
|
+
if (this.sub) {
|
|
2575
|
+
this.sub.unsubscribe();
|
|
2576
|
+
}
|
|
2577
|
+
if (isObservable(this.obj)) {
|
|
2578
|
+
this.sub = this.obj.subscribe(this.updateValue.bind(this));
|
|
2579
|
+
}
|
|
2580
|
+
else if (isPromise(this.obj)) {
|
|
2581
|
+
this.obj.then(this.updateValue.bind(this));
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
throw new Error(`[NGT] Invalid value passed to ngtPush pipe`);
|
|
2585
|
+
}
|
|
2586
|
+
return this.latestValue;
|
|
2587
|
+
}
|
|
2588
|
+
updateValue(val) {
|
|
2589
|
+
this.latestValue = val;
|
|
2590
|
+
this.cdr.detectChanges();
|
|
2591
|
+
if (this.parentCdr) {
|
|
2592
|
+
this.parentCdr.detectChanges();
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
ngOnDestroy() {
|
|
2596
|
+
if (this.sub) {
|
|
2597
|
+
this.sub.unsubscribe();
|
|
2598
|
+
}
|
|
2599
|
+
this.latestValue = undefined;
|
|
2600
|
+
this.obj = undefined;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
NgtPush.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtPush, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
2604
|
+
NgtPush.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.1.1", ngImport: i0, type: NgtPush, isStandalone: true, name: "ngtPush", pure: false });
|
|
2605
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: NgtPush, decorators: [{
|
|
2606
|
+
type: Pipe,
|
|
2607
|
+
args: [{ name: 'ngtPush', pure: false, standalone: true }]
|
|
2608
|
+
}] });
|
|
2609
|
+
|
|
2463
2610
|
/**
|
|
2464
2611
|
* Generated bundle index. Do not edit.
|
|
2465
2612
|
*/
|
|
2466
2613
|
|
|
2467
|
-
export { NGT_CATALOGUE, NgtArgs, NgtCanvas,
|
|
2614
|
+
export { NGT_CATALOGUE, NgtArgs, NgtCanvas, NgtPush, NgtRepeat, NgtRxStore, NgtStore, checkNeedsUpdate, checkUpdate, extend, getLocalState, injectBeforeRender, injectNgtDestroy, injectNgtLoader, injectNgtRef, invalidateInstance, is, prepare, rootStateMap, startWithUndefined, updateCamera };
|
|
2468
2615
|
//# sourceMappingURL=angular-three.mjs.map
|