Skip to content

Commit 87ff923

Browse files
committed
fixing lots of types
1 parent 743e4d6 commit 87ff923

21 files changed

+164
-326
lines changed

Diff for: libs/core/src/lib/directives/args.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import { injectAutoEffect } from 'ngxtension/auto-effect';
1414
import { SPECIAL_INTERNAL_ADD_COMMENT } from '../renderer/constants';
1515

1616
@Directive({ selector: 'ng-template[args]', standalone: true })
17-
export class NgtArgs<TArgs extends any[] = any[]> {
18-
args = input.required<TArgs | null>();
17+
export class NgtArgs {
18+
args = input.required<any[] | null>();
1919

2020
private vcr = inject(ViewContainerRef);
2121
private zone = inject(NgZone);
2222
private template = inject(TemplateRef);
2323
private autoEffect = injectAutoEffect();
2424

2525
protected injected = false;
26-
protected injectedArgs: TArgs | null = null;
26+
protected injectedArgs: any[] | null = null;
2727
private view?: EmbeddedViewRef<unknown>;
2828

2929
constructor() {

Diff for: libs/postprocessing/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@
3838
"dependencies": {
3939
"tslib": "^2.3.0"
4040
},
41-
"sideEffects": false
41+
"sideEffects": false,
42+
"web-types": [
43+
"../../node_modules/angular-three/web-types.json",
44+
"node_modules/angular-three/web-types.json"
45+
]
4246
}

Diff for: libs/soba/controls/src/lib/camera-controls.ts

-9
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ export interface NgtsCameraControlsOptions {
3232
regress: boolean;
3333
}
3434

35-
declare global {
36-
interface HTMLElementTagNameMap {
37-
/**
38-
* @extends camera-controls|CameraControls
39-
*/
40-
'ngts-camera-controls': CameraControls & NgtsCameraControlsOptions;
41-
}
42-
}
43-
4435
const defaultOptions: Partial<CameraControls> & NgtsCameraControlsOptions = {
4536
makeDefault: false,
4637
events: false,

Diff for: libs/soba/controls/src/lib/orbit-controls.ts

-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ export interface NgtsOrbitControlsOptions {
1414
keyEvents: boolean | HTMLElement;
1515
}
1616

17-
declare global {
18-
interface HTMLElementTagNameMap {
19-
/**
20-
* @extends three-stdlib|OrbitControls
21-
*/
22-
'ngts-orbit-controls': OrbitControls & NgtsOrbitControlsOptions;
23-
}
24-
}
25-
2617
const defaultOptions: Partial<OrbitControls> & NgtsOrbitControlsOptions = {
2718
enableDamping: true,
2819
regress: false,

Diff for: libs/soba/local-web-types.json

-38
This file was deleted.

Diff for: libs/soba/materials/src/lib/mesh-transmission-material.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
untracked,
1111
viewChild,
1212
} from '@angular/core';
13-
import { MeshDiscardMaterial, MeshTransmissionMaterial } from '@pmndrs/vanilla';
1413
import {
1514
getLocalState,
1615
injectBeforeRender,
@@ -21,6 +20,7 @@ import {
2120
pick,
2221
} from 'angular-three';
2322
import { injectFBO } from 'angular-three-soba/misc';
23+
import { MeshDiscardMaterial, MeshTransmissionMaterial } from 'angular-three-soba/vanilla-exports';
2424
import { mergeInputs } from 'ngxtension/inject-inputs';
2525
import { BackSide, Color, FrontSide, Mesh, NoToneMapping, Texture, ToneMapping } from 'three';
2626

Diff for: libs/soba/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
},
5353
"sideEffects": false,
5454
"web-types": [
55-
"../../dist/libs/core/web-types.json",
56-
"./local-web-types.json",
55+
"../../node_modules/angular-three/web-types.json",
56+
"../../node_modules/angular-three-soba/web-types.json",
5757
"./web-types.json"
5858
]
5959
}

Diff for: libs/soba/shaders/src/lib/grid-material.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { shaderMaterial } from '@pmndrs/vanilla';
2-
import { NgtShaderMaterial } from 'angular-three';
2+
import { NgtMaterial } from 'angular-three';
33
import { getVersion } from 'angular-three-soba/misc';
44
import { Color, ColorRepresentation, Side, Vector3 } from 'three';
55

@@ -110,11 +110,14 @@ export const GridMaterial = shaderMaterial(
110110
`,
111111
);
112112

113+
export type NgtGridMaterial = NgtMaterial<InstanceType<typeof GridMaterial>, [GridMaterialOptions]>;
114+
113115
declare global {
114116
interface HTMLElementTagNameMap {
115117
/**
116118
* @extends ngt-shader-material
119+
* @options GridMaterialOptions
117120
*/
118-
'ngt-grid-material': GridMaterialOptions & NgtShaderMaterial;
121+
'ngt-grid-material': NgtGridMaterial;
119122
}
120123
}

Diff for: libs/soba/shaders/src/lib/mesh-refraction-material.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { shaderMaterial } from '@pmndrs/vanilla';
2-
import { NgtShaderMaterial } from 'angular-three';
32
import { getVersion } from 'angular-three-soba/misc';
43
import * as THREE from 'three';
54
import { MeshBVHUniformStruct, shaderIntersectFunction, shaderStructs } from 'three-mesh-bvh';
@@ -168,12 +167,3 @@ export const MeshRefractionMaterial = shaderMaterial(
168167
#include <${getVersion() >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
169168
}`,
170169
);
171-
172-
declare global {
173-
interface HTMLElementTagNameMap {
174-
/**
175-
* @extends ngt-shader-material
176-
*/
177-
'ngt-mesh-refraction-material': NgtShaderMaterial;
178-
}
179-
}

Diff for: libs/soba/shaders/src/lib/mesh-wobble-material.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgtMeshStandardMaterial } from 'angular-three';
1+
import { NgtMaterial, NgtMeshStandardMaterial } from 'angular-three';
22
import {
33
IUniform,
44
MeshStandardMaterial,
@@ -59,11 +59,14 @@ export class MeshWobbleMaterial extends MeshStandardMaterial {
5959
}
6060
}
6161

62+
export type NgtMeshWobbleMaterial = NgtMaterial<MeshWobbleMaterial, [MeshWobbleMaterialOptions]>;
63+
6264
declare global {
6365
interface HTMLElementTagNameMap {
6466
/**
6567
* @extends ngt-mesh-standard-material
68+
* @options MeshWobbleMaterialOptions
6669
*/
67-
'ngt-mesh-wobble-material': MeshWobbleMaterialOptions & NgtMeshStandardMaterial;
70+
'ngt-mesh-wobble-material': NgtMeshWobbleMaterial;
6871
}
6972
}

Diff for: libs/soba/src/abstractions/text.stories.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class TextCustomMaterialContainer {
5757
maxWidth: 200,
5858
lineHeight: 1,
5959
letterSpacing: 0.02,
60-
textAlign: 'left',
60+
textAlign: 'left' as const,
6161
font: 'https://fonts.gstatic.com/s/raleway/v14/1Ptrg8zYS_SKggPNwK4vaqI.woff',
62-
anchorX: 'center',
63-
anchorY: 'middle',
62+
anchorX: 'center' as const,
63+
anchorY: 'middle' as const,
6464
};
6565

6666
textRef = viewChild.required(NgtsText);

Diff for: libs/soba/src/staging/accumulative-shadows.stories.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { color, makeDecorators, makeStoryObject } from '../setup-canvas';
1717
selector: 'accumulative-shadows-suzi',
1818
standalone: true,
1919
template: `
20-
<ngt-primitive *args="[scene()]" [rotation]="[-0.63, 0, 0]" [scale]="2" [position]="[0, -1.175, 0]" />
20+
<ngt-primitive *args="[scene()]" [parameters]="{ rotation: [-0.63, 0, 0], scale: 2, position: [0, -1.175, 0] }" />
2121
`,
2222
imports: [NgtArgs],
2323
schemas: [CUSTOM_ELEMENTS_SCHEMA],

Diff for: libs/soba/src/staging/bb-anchor.stories.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, Component, input } from '@angular/core';
22
import { Meta } from '@storybook/angular';
33
import { NgtArgs } from 'angular-three';
4+
import { NgtsHelper } from 'angular-three-soba/abstractions';
45
import { NgtsOrbitControls } from 'angular-three-soba/controls';
56
import { NgtsBBAnchor, NgtsBBAnchorOptions } from 'angular-three-soba/staging';
7+
import { BoxHelper } from 'three';
68
import { makeDecorators, makeStoryObject } from '../setup-canvas';
79

810
@Component({
@@ -31,17 +33,18 @@ class MeshObject {}
3133
<ngts-bb-anchor [options]="options()">
3234
<ng-content />
3335
</ngts-bb-anchor>
34-
</ngt-mesh>
3536
36-
@if (drawBoundingBox()) {
37-
<ngt-box-helper *args="[mesh, 'cyan']" />
38-
}
37+
@if (drawBoundingBox()) {
38+
<ngts-helper [type]="BoxHelper" [options]="['cyan']" />
39+
}
40+
</ngt-mesh>
3941
`,
40-
imports: [NgtsBBAnchor, NgtsOrbitControls, NgtArgs],
42+
imports: [NgtsBBAnchor, NgtsOrbitControls, NgtArgs, NgtsHelper],
4143
schemas: [CUSTOM_ELEMENTS_SCHEMA],
4244
changeDetection: ChangeDetectionStrategy.OnPush,
4345
})
4446
class BBAnchorWrapper {
47+
protected readonly BoxHelper = BoxHelper;
4548
options = input.required<NgtsBBAnchorOptions>();
4649
drawBoundingBox = input(false);
4750
}

Diff for: libs/soba/staging/src/lib/accumulative-shadows.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
untracked,
1212
viewChild,
1313
} from '@angular/core';
14-
import { ProgressiveLightMap, SoftShadowMaterial } from '@pmndrs/vanilla';
1514
import { NgtGroup, extend, getLocalState, injectBeforeRender, injectStore, omit, pick } from 'angular-three';
15+
import { ProgressiveLightMap, SoftShadowMaterial } from 'angular-three-soba/vanilla-exports';
1616
import { injectAutoEffect } from 'ngxtension/auto-effect';
1717
import { mergeInputs } from 'ngxtension/inject-inputs';
1818
import { Group, Mesh, PlaneGeometry } from 'three';

Diff for: libs/soba/vanilla-exports/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# angular-three-soba/vanilla-exports
2+
3+
Secondary entry point of `angular-three-soba`. It can be used by importing from `angular-three-soba/vanilla-exports`.

Diff for: libs/soba/vanilla-exports/ng-package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"lib": {
3+
"entryFile": "src/index.ts"
4+
}
5+
}

Diff for: libs/soba/vanilla-exports/src/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
MeshDiscardMaterial,
3+
MeshTransmissionMaterial,
4+
ProgressiveLightMap,
5+
SoftShadowMaterial,
6+
} from '@pmndrs/vanilla';
7+
import { NgtMaterial } from 'angular-three';
8+
9+
export type NgtSoftShadowMaterial = NgtMaterial<InstanceType<typeof SoftShadowMaterial>, typeof SoftShadowMaterial>;
10+
11+
declare global {
12+
interface HTMLElementTagNameMap {
13+
/**
14+
* @extends ngt-mesh-standard-material
15+
* @rawOptions color|blend|opacity|alphaTest|map
16+
*/
17+
'ngt-soft-shadow-material': NgtSoftShadowMaterial;
18+
}
19+
}
20+
21+
export { MeshDiscardMaterial, MeshTransmissionMaterial, ProgressiveLightMap, SoftShadowMaterial };

Diff for: tools/scripts/generate-json.mjs

+9-23
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ const logger = createLog();
55

66
const { metadataJson, webTypesJson, write } = createBareJsons();
77

8-
const { typeChecker, sourceFile, typeToTypeNode, typeToString, processIntersectionTypeNode, processTypeMembers } =
9-
createProgram(['libs/core/src/lib/three-types.ts']);
10-
11-
/** @type {Map<string, { typeDeclaration: ts.TypeAliasDeclaration, type: ts.Type, typeNode: ts.TypeNode, typeString: string}>} */
12-
const typeDeclarationMap = new Map();
8+
const { sourceFile, typesMap, processIntersectionTypeNode, processTypeMembers } = createProgram([
9+
'libs/core/src/lib/three-types.ts',
10+
]);
1311

1412
const THREE_MEMBERS_TO_SKIP = ['ngt-primitive'];
1513
const THREE_ELEMENTS_NAME = 'ThreeElements';
@@ -19,7 +17,7 @@ const THREE_OBJECT_EVENTS_MAP_NAME = 'NgtObject3DEventsMap';
1917
* @param {{name: string, attributes: any[]}} metadata
2018
*/
2119
function processObject3DEvents(metadata) {
22-
const object3DEventsMapType = typeDeclarationMap.get(THREE_OBJECT_EVENTS_MAP_NAME).type;
20+
const object3DEventsMapType = typesMap[THREE_OBJECT_EVENTS_MAP_NAME].type;
2321
for (const member of object3DEventsMapType.properties) {
2422
metadata.attributes.push({
2523
name: `(${member.name})`,
@@ -43,9 +41,8 @@ ts.forEachChild(sourceFile, (node) => {
4341
/** @type {ts.TypeReferenceNode} */
4442
const threeMemberType = threeMember.type;
4543
const threeMemberTypeName = threeMemberType.typeName.text;
46-
const cachedType = typeDeclarationMap.get(threeMemberTypeName);
47-
// delete parent from typeDeclaration
48-
delete cachedType.typeDeclaration.parent;
44+
const cachedType = typesMap[threeMemberTypeName];
45+
4946
if (!THREE_MEMBERS_TO_SKIP.includes(threeMemberName)) {
5047
const threeMemberTypeNode = cachedType.typeNode;
5148
if (threeMemberTypeNode) {
@@ -58,6 +55,9 @@ ts.forEachChild(sourceFile, (node) => {
5855
processTypeMembers(metadataAtMember, threeMemberTypeNode.members);
5956
}
6057
} else {
58+
if (cachedType.typeString.includes(THREE_OBJECT_EVENTS_MAP_NAME)) {
59+
processObject3DEvents(metadataAtMember);
60+
}
6161
processTypeMembers(metadataAtMember, cachedType.type.properties);
6262
}
6363
}
@@ -69,20 +69,6 @@ ts.forEachChild(sourceFile, (node) => {
6969
webTypesJson.contributions.html.elements.push(metadataAtMember);
7070
}
7171
}
72-
73-
if (ts.isTypeAliasDeclaration(node)) {
74-
const typeName = node.name.escapedText;
75-
const type = typeChecker.getTypeAtLocation(node);
76-
const typeNode = typeToTypeNode(type, node);
77-
const typeString = typeToString(type, node);
78-
79-
// remove checker from type
80-
delete type.checker;
81-
82-
typeDeclarationMap.set(typeName, { type, typeDeclaration: node, typeNode, typeString });
83-
84-
// TODO: we probably should recursively expand the type here as well
85-
}
8672
});
8773

8874
write(metadataJson, webTypesJson);

0 commit comments

Comments
 (0)