Skip to content

Commit 44e9e08

Browse files
committed
update nx
1 parent 108fbd5 commit 44e9e08

File tree

8 files changed

+278
-272
lines changed

8 files changed

+278
-272
lines changed

apps/testbed/src/app/cube/cube.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
(pointerout)="hover.set(false)"
77
(click)="active.set(!active())"
88
>
9-
<ngt-box-geometry />
9+
<ngt-box-geometry *args="[1.5, 1.5, 1.5]" />
1010
<ngt-mesh-standard-material [withTimeline]="gsapTimeline['color']" />
1111
</ngt-mesh>

apps/testbed/src/app/cube/cube.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, Component, Input, computed } from '@angular/core';
2-
import { cdAwareSignal, type NgtBeforeRenderEvent } from 'angular-three';
1+
import {
2+
CUSTOM_ELEMENTS_SCHEMA,
3+
ChangeDetectionStrategy,
4+
Component,
5+
Input,
6+
afterNextRender,
7+
computed,
8+
} from '@angular/core';
9+
import { NgtArgs, cdAwareSignal, type NgtBeforeRenderEvent } from 'angular-three';
310
import { WithTimeline, injectGsap } from './gsap';
411

512
@Component({
613
selector: 'app-cube',
714
standalone: true,
8-
templateUrl: './cube.html',
915
template: `
1016
<ngt-mesh
11-
[withTimeline]="gsapTimeline.scale"
17+
[withTimeline]="gsapTimeline.mesh"
1218
[position]="position"
1319
(beforeRender)="onBeforeRender($event)"
1420
(pointerover)="hover.set(true)"
1521
(pointerout)="hover.set(false)"
1622
(click)="active.set(!active())"
1723
>
18-
<ngt-box-geometry />
19-
<ngt-mesh-standard-material [withTimeline]="gsapTimeline.color" />
24+
<ngt-box-geometry *args="[1.5, 1.5, 1.5]" />
25+
<ngt-mesh-standard-material [withTimeline]="gsapTimeline.material" />
2026
</ngt-mesh>
2127
`,
2228
schemas: [CUSTOM_ELEMENTS_SCHEMA],
23-
imports: [WithTimeline],
29+
imports: [WithTimeline, NgtArgs],
2430
changeDetection: ChangeDetectionStrategy.OnPush,
2531
})
2632
export class Cube {
@@ -33,10 +39,16 @@ export class Cube {
3339
protected scale = computed(() => (this.active() ? 1.5 : 1));
3440

3541
protected gsapTimeline = injectGsap({
36-
scale: { value: this.scale, ease: 'bounce.out' },
37-
color: { value: this.color },
42+
mesh: { value: () => ({ scale: this.scale() }), ease: 'bounce.out' },
43+
material: { value: () => ({ color: this.color() }) },
3844
});
3945

46+
constructor() {
47+
afterNextRender(() => {
48+
console.log(this.gsapTimeline);
49+
});
50+
}
51+
4052
onBeforeRender(event: NgtBeforeRenderEvent<THREE.Mesh>) {
4153
event.object.rotation.x += 0.01;
4254
}

apps/testbed/src/app/cube/gsap.ts

+48-43
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
11
import {
2+
afterNextRender,
3+
AfterRenderPhase,
24
DestroyRef,
35
Directive,
6+
effect,
47
ElementRef,
8+
inject,
59
Injector,
610
Input,
7-
afterNextRender,
8-
effect,
9-
inject,
1011
signal,
1112
untracked,
1213
type WritableSignal,
1314
} from '@angular/core';
15+
import { applyProps } from 'angular-three';
1416
import { gsap } from 'gsap';
15-
import { applyProps } from 'libs/core/src/lib/utils/apply-props';
1617

1718
export function injectGsap(config: Record<string, { value: () => any } & gsap.TweenVars>) {
1819
const destroyRef = inject(DestroyRef);
19-
const targets: Record<string, WritableSignal<any>> = {};
20-
const timelines: Record<string, gsap.core.Timeline> = {};
21-
let context: gsap.Context;
2220

2321
const entries = Object.entries(config);
2422

25-
afterNextRender(() => {
26-
context = gsap.context(() => {
27-
entries.forEach(([key]) => {
28-
timelines[key] = gsap.timeline();
29-
targets[key] = signal<any | null>(null);
30-
});
23+
const targets: Record<string, WritableSignal<any>> = entries.reduce(
24+
(acc, [key]) => {
25+
acc[key] = signal(null!);
26+
return acc;
27+
},
28+
{} as Record<string, WritableSignal<any>>,
29+
);
30+
const timelines: Record<string, gsap.core.Timeline> = {};
31+
32+
const context = gsap.context(() => {
33+
entries.forEach(([key]) => {
34+
timelines[key] = gsap.timeline();
3135
});
3236
});
3337

34-
destroyRef.onDestroy(() => context?.revert());
38+
destroyRef.onDestroy(() => context.revert());
3539

3640
return entries.reduce((acc, [key, { value, ...rest }]) => {
37-
const preConfig = {
38-
[key]: untracked(value),
39-
};
40-
41-
acc[key] = {
42-
start: (target: any, injector: Injector) => {
43-
untracked(() => {
44-
targets[key].set(target);
45-
rest.onUpdate = () => {
46-
if (timelines[key].isActive()) {
47-
applyProps(target, preConfig);
48-
}
49-
};
50-
});
51-
queueMicrotask(() => {
52-
effect(
53-
(onCleanup) => {
54-
if (!target) return;
55-
56-
timelines[key].to(preConfig, { ...rest, [key]: value() });
41+
const targetValue = untracked(value);
42+
acc[key] = (target: any, injector: Injector) => {
43+
queueMicrotask(() => {
44+
effect(
45+
(onCleanup) => {
46+
const _target = targets[key]();
47+
if (!_target) return;
48+
timelines[key].to(targetValue, Object.assign(rest, value()));
49+
onCleanup(() => timelines[key].clear());
50+
},
51+
{ injector },
52+
);
53+
});
5754

58-
onCleanup(() => timelines[key].clear());
59-
},
60-
{ injector },
61-
);
62-
});
63-
},
55+
untracked(() => {
56+
applyProps(target, targetValue);
57+
targets[key].set(target);
58+
const originalOnUpdate = rest.onUpdate;
59+
rest.onUpdate = () => {
60+
originalOnUpdate?.();
61+
if (timelines[key].isActive()) {
62+
applyProps(target, targetValue);
63+
}
64+
};
65+
});
6466
};
6567

6668
return acc;
@@ -72,8 +74,11 @@ export class WithTimeline {
7274
@Input({ required: true }) withTimeline!: any;
7375

7476
constructor(elementRef: ElementRef<any>, injector: Injector) {
75-
afterNextRender(() => {
76-
this.withTimeline.start(elementRef.nativeElement, injector);
77-
});
77+
afterNextRender(
78+
() => {
79+
this.withTimeline(elementRef.nativeElement, injector);
80+
},
81+
{ phase: AfterRenderPhase.Read },
82+
);
7883
}
7984
}

apps/testbed/src/app/scene/scene.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<ngt-point-light [intensity]="5" [position]="-1.5" />
44

55
<app-cube [position]="[0, 0, 0]" />
6-
<app-cube [position]="[2, 0, 0]" />
6+
<!-- <app-cube [position]="[2, 0, 0]" /> -->
77

88
<ngt-orbit-controls *args="controlsArgs()" />

libs/core/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export * from './lib/ref';
88
export * from './lib/renderer';
99
export * from './lib/routed-scene';
1010
export * from './lib/store';
11-
export * from './lib/three-types';
12-
export * from './lib/types';
1311
export * from './lib/utils/apply-props';
1412
export { createAttachFunction } from './lib/utils/attach';
1513
export * from './lib/utils/before-render';

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
},
1515
"private": true,
1616
"devDependencies": {
17-
"@analogjs/platform": "^0.2.21",
18-
"@analogjs/vite-plugin-angular": "^0.2.21",
17+
"@analogjs/platform": "^0.2.22",
18+
"@analogjs/vite-plugin-angular": "^0.2.22",
1919
"@angular-devkit/build-angular": "17.0.3",
2020
"@angular-devkit/core": "17.0.3",
2121
"@angular-devkit/schematics": "17.0.3",
2222
"@angular-eslint/eslint-plugin": "17.1.0",
2323
"@angular-eslint/eslint-plugin-template": "17.1.0",
2424
"@angular-eslint/template-parser": "17.1.0",
25-
"@angular/cli": "~17.0.3",
25+
"@angular/cli": "~17.0.0",
2626
"@angular/compiler-cli": "17.0.4",
2727
"@angular/language-service": "17.0.4",
2828
"@nx/angular": "17.1.3",
@@ -52,7 +52,7 @@
5252
"@swc/cli": "~0.1.63",
5353
"@swc/core": "1.3.99",
5454
"@types/jest": "^29.5.10",
55-
"@types/node": "20.9.4",
55+
"@types/node": "20.10.0",
5656
"@types/three": "^0.158.3",
5757
"@typescript-eslint/eslint-plugin": "6.12.0",
5858
"@typescript-eslint/parser": "6.12.0",
@@ -92,8 +92,8 @@
9292
"@nx/eslint": "17.1.3"
9393
},
9494
"dependencies": {
95-
"@analogjs/content": "^0.2.21",
96-
"@analogjs/router": "^0.2.21",
95+
"@analogjs/content": "^0.2.22",
96+
"@analogjs/router": "^0.2.22",
9797
"@angular/animations": "17.0.4",
9898
"@angular/common": "17.0.4",
9999
"@angular/compiler": "17.0.4",

0 commit comments

Comments
 (0)