Skip to content

Commit d3c141f

Browse files
committed
move all types to types
1 parent 07f7c83 commit d3c141f

22 files changed

+416
-416
lines changed

libs/core/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
export * from './lib/canvas';
22
export * from './lib/directives/args';
3-
export { NgtCamera, NgtComputeFunction, NgtDomEvent, NgtEventHandlers, NgtThreeEvent } from './lib/events';
43
export * from './lib/html';
54
export * from './lib/instance';
65
export * from './lib/loader';
7-
export { addAfterEffect, addEffect, addTail } from './lib/loop';
8-
export { NgtPortal, NgtPortalContent } from './lib/portal';
6+
export * from './lib/loop';
7+
export * from './lib/portal';
98
export * from './lib/renderer';
10-
export { injectCanvasRootInitializer } from './lib/roots';
9+
export * from './lib/roots';
1110
export * from './lib/routed-scene';
1211
export * from './lib/store';
1312
export * from './lib/utils/apply-props';
14-
export { createAttachFunction } from './lib/utils/attach';
13+
export * from './lib/utils/attach';
1514
export * from './lib/utils/before-render';
1615
export * from './lib/utils/is';
1716
export * from './lib/utils/make';

libs/core/src/lib/canvas.ts

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -23,93 +23,14 @@ import {
2323
import { outputFromObservable } from '@angular/core/rxjs-interop';
2424
import { injectAutoEffect } from 'ngxtension/auto-effect';
2525
import { NgxResize, provideResizeOptions, ResizeOptions, ResizeResult } from 'ngxtension/resize';
26-
import {
27-
Camera,
28-
OrthographicCamera,
29-
PerspectiveCamera,
30-
Raycaster,
31-
Scene,
32-
Vector3,
33-
WebGLRenderer,
34-
WebGLRendererParameters,
35-
WebGLShadowMap,
36-
} from 'three';
26+
import { Raycaster, Scene, Vector3 } from 'three';
3727
import { createPointerEvents } from './dom/events';
38-
import { NgtCamera, NgtDomEvent, NgtEventManager } from './events';
3928
import { provideNgtRenderer } from './renderer';
40-
import { injectCanvasRootInitializer, NgtCanvasConfigurator, NgtCanvasElement } from './roots';
29+
import { injectCanvasRootInitializer, NgtCanvasConfigurator } from './roots';
4130
import { NgtRoutedScene } from './routed-scene';
42-
import { injectStore, NgtDpr, NgtPerformance, NgtRendererLike, NgtSize, NgtState, provideStore } from './store';
43-
import { NgtObject3DNode } from './three-types';
44-
import { NgtProperties } from './types';
31+
import { injectStore, provideStore } from './store';
32+
import { NgtCanvasOptions, NgtDomEvent, NgtDpr, NgtGLOptions, NgtPerformance, NgtSize, NgtState } from './types';
4533
import { is } from './utils/is';
46-
import { NgtSignalStore } from './utils/signal-store';
47-
48-
export type NgtGLOptions =
49-
| NgtRendererLike
50-
| ((canvas: NgtCanvasElement) => NgtRendererLike)
51-
| Partial<NgtProperties<WebGLRenderer> | WebGLRendererParameters>
52-
| undefined;
53-
54-
export interface NgtCanvasOptions {
55-
/** A threejs renderer instance or props that go into the default renderer */
56-
gl?: NgtGLOptions;
57-
/** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
58-
size?: NgtSize;
59-
/**
60-
* Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
61-
* but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
62-
* @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
63-
*/
64-
shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<WebGLShadowMap>;
65-
/**
66-
* Disables three r139 color management.
67-
* @see https://threejs.org/docs/#manual/en/introduction/Color-management
68-
*/
69-
legacy?: boolean;
70-
/** Switch off automatic sRGB color space and gamma correction */
71-
linear?: boolean;
72-
/** Use `THREE.NoToneMapping` instead of `THREE.ACESFilmicToneMapping` */
73-
flat?: boolean;
74-
/** Creates an orthographic camera */
75-
orthographic?: boolean;
76-
/**
77-
* R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
78-
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
79-
*/
80-
frameloop?: 'always' | 'demand' | 'never';
81-
/**
82-
* R3F performance options for adaptive performance.
83-
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
84-
*/
85-
performance?: Partial<Omit<NgtPerformance, 'regress'>>;
86-
/** Target pixel ratio. Can clamp between a range: `[min, max]` */
87-
dpr?: NgtDpr;
88-
/** Props that go into the default raycaster */
89-
raycaster?: Partial<Raycaster>;
90-
/** A `Scene` instance or props that go into the default scene */
91-
scene?: Scene | Partial<Scene>;
92-
/** A `Camera` instance or props that go into the default camera */
93-
camera?: (
94-
| NgtCamera
95-
| Partial<
96-
NgtObject3DNode<Camera, typeof Camera> &
97-
NgtObject3DNode<PerspectiveCamera, typeof PerspectiveCamera> &
98-
NgtObject3DNode<OrthographicCamera, typeof OrthographicCamera>
99-
>
100-
) & {
101-
/** Flags the camera as manual, putting projection into your own hands */
102-
manual?: boolean;
103-
};
104-
/** An R3F event manager to manage elements' pointer events */
105-
events?: (store: NgtSignalStore<NgtState>) => NgtEventManager<HTMLElement>;
106-
/** The target where events are being subscribed to, default: the div that wraps canvas */
107-
eventSource?: HTMLElement | ElementRef<HTMLElement>;
108-
/** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
109-
eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
110-
/** Default coordinate for the camera to look at */
111-
lookAt?: Vector3 | Parameters<Vector3['set']>;
112-
}
11334

11435
@Component({
11536
selector: 'ngt-canvas',
@@ -292,3 +213,5 @@ export class NgtCanvas {
292213
});
293214
}
294215
}
216+
217+
export const injectRoot = injectCanvasRootInitializer;

libs/core/src/lib/dom/events.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { createEvents, NgtDomEvent, NgtEventManager, NgtEvents } from '../events';
2-
import { NgtState } from '../store';
3-
import { NgtAnyRecord } from '../types';
1+
import { createEvents } from '../events';
2+
import { NgtAnyRecord, NgtDomEvent, NgtEventManager, NgtEvents, NgtState } from '../types';
43
import { NgtSignalStore } from '../utils/signal-store';
54

65
const DOM_EVENTS = {

libs/core/src/lib/events.ts

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,18 @@
11
import { Subject } from 'rxjs';
2-
import { Intersection, Object3D, OrthographicCamera, PerspectiveCamera, Ray, Vector2, Vector3 } from 'three';
2+
import { Intersection, Object3D, Vector3 } from 'three';
33
import { getLocalState } from './instance';
4-
import { NgtState } from './store';
5-
import { NgtAnyRecord, NgtProperties } from './types';
4+
import {
5+
NgtAnyRecord,
6+
NgtDomEvent,
7+
NgtEventHandlers,
8+
NgtIntersection,
9+
NgtPointerCaptureTarget,
10+
NgtState,
11+
NgtThreeEvent,
12+
} from './types';
613
import { makeId } from './utils/make';
714
import { NgtSignalStore } from './utils/signal-store';
815

9-
export interface NgtIntersection extends Intersection {
10-
/** The event source (the object which registered the handler) */
11-
eventObject: Object3D;
12-
}
13-
14-
export interface NgtIntersectionEvent<TSourceEvent> extends NgtIntersection {
15-
/** The event source (the object which registered the handler) */
16-
eventObject: Object3D;
17-
/** An array of intersections */
18-
intersections: NgtIntersection[];
19-
/** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
20-
unprojectedPoint: Vector3;
21-
/** Normalized event coordinates */
22-
pointer: Vector2;
23-
/** Delta between first click and this event */
24-
delta: number;
25-
/** The ray that pierced it */
26-
ray: Ray;
27-
/** The camera that was used by the raycaster */
28-
camera: NgtCamera;
29-
/** stopPropagation will stop underlying handlers from firing */
30-
stopPropagation: () => void;
31-
/** The original host event */
32-
nativeEvent: TSourceEvent;
33-
/** If the event was stopped by calling stopPropagation */
34-
stopped: boolean;
35-
}
36-
37-
export type NgtCamera = OrthographicCamera | PerspectiveCamera;
38-
export type NgtThreeEvent<TEvent> = NgtIntersectionEvent<TEvent> & NgtProperties<TEvent>;
39-
export type NgtDomEvent = PointerEvent | MouseEvent | WheelEvent;
40-
41-
export type NgtEventHandlers = {
42-
click?: (event: NgtThreeEvent<MouseEvent>) => void;
43-
contextmenu?: (event: NgtThreeEvent<MouseEvent>) => void;
44-
dblclick?: (event: NgtThreeEvent<MouseEvent>) => void;
45-
pointerup?: (event: NgtThreeEvent<PointerEvent>) => void;
46-
pointerdown?: (event: NgtThreeEvent<PointerEvent>) => void;
47-
pointerover?: (event: NgtThreeEvent<PointerEvent>) => void;
48-
pointerout?: (event: NgtThreeEvent<PointerEvent>) => void;
49-
pointerenter?: (event: NgtThreeEvent<PointerEvent>) => void;
50-
pointerleave?: (event: NgtThreeEvent<PointerEvent>) => void;
51-
pointermove?: (event: NgtThreeEvent<PointerEvent>) => void;
52-
pointermissed?: (event: MouseEvent) => void;
53-
pointercancel?: (event: NgtThreeEvent<PointerEvent>) => void;
54-
wheel?: (event: NgtThreeEvent<WheelEvent>) => void;
55-
};
56-
57-
export type NgtEvents = {
58-
[TEvent in keyof NgtEventHandlers]-?: EventListener;
59-
};
60-
61-
export type NgtFilterFunction = (items: Intersection[], store: NgtSignalStore<NgtState>) => Intersection[];
62-
export type NgtComputeFunction = (
63-
event: NgtDomEvent,
64-
root: NgtSignalStore<NgtState>,
65-
previous: NgtSignalStore<NgtState> | null,
66-
) => void;
67-
68-
export type NgtEventManager<TTarget> = {
69-
/** Determines if the event layer is active */
70-
enabled: boolean;
71-
/** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
72-
priority: number;
73-
/** The compute function needs to set up the raycaster and an xy- pointer */
74-
compute?: NgtComputeFunction;
75-
/** The filter can re-order or re-structure the intersections */
76-
filter?: NgtFilterFunction;
77-
/** The target node the event layer is tied to */
78-
connected?: TTarget;
79-
/** All the pointer event handlers through which the host forwards native events */
80-
handlers?: NgtEvents;
81-
/** Allows re-connecting to another target */
82-
connect?: (target: TTarget) => void;
83-
/** Removes all existing events handlers from the target */
84-
disconnect?: () => void;
85-
/** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
86-
* explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
87-
*/
88-
update?: () => void;
89-
};
90-
91-
export interface NgtPointerCaptureTarget {
92-
intersection: NgtIntersection;
93-
target: Element;
94-
}
95-
9616
/**
9717
* Release pointer captures.
9818
* This is called by releasePointerCapture in the API, and when an object is removed.

libs/core/src/lib/instance.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,7 @@
1-
import { Signal } from '@angular/core';
2-
import { NgtEventHandlers } from './events';
3-
import { NgtState } from './store';
4-
import { NgtAnyRecord } from './types';
5-
import { NgtSignalStore, signalStore } from './utils/signal-store';
1+
import { NgtAnyRecord, NgtInstanceNode, NgtLocalInstanceState, NgtLocalState } from './types';
2+
import { signalStore } from './utils/signal-store';
63
import { checkUpdate } from './utils/update';
74

8-
export type NgtAttachFunction<TChild = any, TParent = any> = (
9-
parent: TParent,
10-
child: TChild,
11-
store: NgtSignalStore<NgtState>,
12-
) => void | (() => void);
13-
14-
export interface NgtAfterAttach<
15-
TChild extends NgtInstanceNode = NgtInstanceNode,
16-
TParent extends NgtInstanceNode = NgtInstanceNode,
17-
> {
18-
parent: TParent;
19-
node: TChild;
20-
}
21-
22-
export interface NgtLocalInstanceState {
23-
objects: NgtInstanceNode[];
24-
nonObjects: NgtInstanceNode[];
25-
parent: NgtInstanceNode | null;
26-
}
27-
28-
export interface NgtLocalState {
29-
/** the store of the canvas that the instance is being rendered to */
30-
store: NgtSignalStore<NgtState>;
31-
// objects related to this instance
32-
instanceStore: NgtSignalStore<NgtLocalInstanceState>;
33-
// shortcut to signals
34-
parent: Signal<NgtLocalInstanceState['parent']>;
35-
objects: Signal<NgtLocalInstanceState['objects']>;
36-
nonObjects: Signal<NgtLocalInstanceState['nonObjects']>;
37-
// shortcut to add/remove object to list
38-
add: (instance: NgtInstanceNode, type: 'objects' | 'nonObjects') => void;
39-
remove: (instance: NgtInstanceNode, type: 'objects' | 'nonObjects') => void;
40-
setParent: (parent: NgtInstanceNode | null) => void;
41-
// if this THREE instance is a ngt-primitive
42-
primitive?: boolean;
43-
// if this THREE object has any events bound to it
44-
eventCount: number;
45-
// list of handlers to handle the events
46-
handlers: Partial<NgtEventHandlers>;
47-
// attach information so that we can detach as well as reset
48-
attach?: string[] | NgtAttachFunction;
49-
// previously attach information so we can reset as well as clean up
50-
previousAttach?: unknown | (() => void);
51-
// is raw value
52-
isRaw?: boolean;
53-
// priority for before render
54-
priority?: number;
55-
onUpdate?: (node: NgtInstanceNode) => void;
56-
onAttach?: (afterAttach: NgtAfterAttach) => void;
57-
}
58-
59-
export type NgtInstanceNode<TNode = any> = { __ngt__: NgtLocalState } & NgtAnyRecord & TNode;
60-
615
export function getLocalState<TInstance extends object>(obj: TInstance | undefined): NgtLocalState | undefined {
626
if (!obj) return undefined;
637
return (obj as NgtAnyRecord)['__ngt__'];

libs/core/src/lib/loop.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createInjectionToken } from 'ngxtension/create-injection-token';
2-
import { roots } from './roots';
3-
import { NgtState } from './store';
2+
import { NgtCanvasElement, NgtGlobalRenderCallback, NgtState } from './types';
43
import { NgtSignalStore } from './utils/signal-store';
54

6-
export type NgtGlobalRenderCallback = (timeStamp: number) => void;
5+
export const roots = new Map<NgtCanvasElement, NgtSignalStore<NgtState>>();
6+
77
type SubItem = { callback: NgtGlobalRenderCallback };
88

99
function createSubs(callback: NgtGlobalRenderCallback, subs: Set<SubItem>): () => void {

libs/core/src/lib/portal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {
1919
} from '@angular/core';
2020
import { injectAutoEffect } from 'ngxtension/auto-effect';
2121
import { Camera, Object3D, Raycaster, Scene, Vector2, Vector3 } from 'three';
22-
import { NgtComputeFunction } from './events';
2322
import { getLocalState, prepare } from './instance';
2423
import { SPECIAL_INTERNAL_ADD_COMMENT } from './renderer/constants';
25-
import { injectStore, NgtSize, NgtState, provideStore } from './store';
24+
import { injectStore, provideStore } from './store';
25+
import { NgtComputeFunction, NgtSize, NgtState } from './types';
2626
import { injectBeforeRender } from './utils/before-render';
2727
import { is } from './utils/is';
2828
import { signalStore } from './utils/signal-store';

libs/core/src/lib/renderer/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
makeEnvironmentProviders,
1010
} from '@angular/core';
1111
import { NgtArgs } from '../directives/args';
12-
import { NgtInstanceNode, NgtLocalState, getLocalState, prepare } from '../instance';
13-
import { NGT_STORE, NgtState, injectStore, provideStore } from '../store';
14-
import { NgtAnyRecord } from '../types';
12+
import { getLocalState, prepare } from '../instance';
13+
import { NGT_STORE, injectStore, provideStore } from '../store';
14+
import { NgtAnyRecord, NgtInstanceNode, NgtLocalState, NgtState } from '../types';
1515
import { applyProps } from '../utils/apply-props';
1616
import { is } from '../utils/is';
1717
import { NgtSignalStore, signalStore } from '../utils/signal-store';

libs/core/src/lib/renderer/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { untracked } from '@angular/core';
22
import { removeInteractivity } from '../events';
3-
import { getLocalState, invalidateInstance, NgtInstanceNode } from '../instance';
3+
import { getLocalState, invalidateInstance } from '../instance';
4+
import { NgtInstanceNode } from '../types';
45
import { attach, detach } from '../utils/attach';
56
import { is } from '../utils/is';
67
import { SPECIAL_EVENTS } from './constants';

libs/core/src/lib/roots.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@ import {
1212
VSMShadowMap,
1313
Vector3,
1414
} from 'three';
15-
import { NgtCanvasOptions } from './canvas';
1615
import { prepare } from './instance';
17-
import { injectLoop } from './loop';
18-
import { NgtSize, NgtState, injectStore } from './store';
19-
import { NgtAnyRecord, NgtEquConfig } from './types';
16+
import { injectLoop, roots } from './loop';
17+
import { injectStore } from './store';
18+
import { NgtAnyRecord, NgtCanvasElement, NgtCanvasOptions, NgtEquConfig, NgtSize, NgtState } from './types';
2019
import { applyProps } from './utils/apply-props';
2120
import { is } from './utils/is';
2221
import { makeCameraInstance, makeDpr, makeRendererInstance } from './utils/make';
2322
import { NgtSignalStore } from './utils/signal-store';
2423
import { checkNeedsUpdate } from './utils/update';
2524

26-
export type NgtCanvasElement = HTMLCanvasElement | OffscreenCanvas;
27-
2825
const shallowLoose = { objects: 'shallow', strict: false } as NgtEquConfig;
2926

30-
export const roots = new Map<NgtCanvasElement, NgtSignalStore<NgtState>>();
31-
3227
export function injectCanvasRootInitializer(injector?: Injector) {
3328
return assertInjector(injectCanvasRootInitializer, injector, () => {
3429
const injectedStore = injectStore();

0 commit comments

Comments
 (0)