Skip to content

Commit 4bdfcde

Browse files
committed
docs: setup new docs (2)
1 parent 8c1fa84 commit 4bdfcde

File tree

15 files changed

+1078
-53
lines changed

15 files changed

+1078
-53
lines changed

apps/astro-docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "docs",
2+
"name": "astro-docs",
33
"type": "module",
44
"version": "0.0.1",
55
"scripts": {

apps/docs/astro.config.mjs

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,94 @@
1-
// @ts-check
2-
import { defineConfig } from 'astro/config';
1+
import analogjsangular from '@analogjs/astro-angular';
32
import starlight from '@astrojs/starlight';
43
import tailwind from '@astrojs/tailwind';
4+
import { defineConfig } from 'astro/config';
5+
import { readFileSync } from 'node:fs';
6+
import starlightBlog from 'starlight-blog';
7+
8+
function includeContentPlugin() {
9+
const map = new Map();
10+
11+
return [
12+
{
13+
name: 'pre-include-content',
14+
enforce: 'pre',
15+
transform(_, id) {
16+
if (!id.includes('?includeContent') || id.includes('astro-entry')) return;
17+
18+
const [filePath] = id.split('?');
19+
const fileContent = readFileSync(filePath, 'utf-8');
20+
21+
if (map.has(filePath)) return;
22+
map.set(filePath, fileContent.replace(/\t/g, ' '));
23+
},
24+
},
25+
{
26+
name: 'post-include-content',
27+
enforce: 'post',
28+
transform(code, id) {
29+
if (!id.includes('?includeContent') || id.includes('astro-entry')) return;
30+
const [filePath] = id.split('?');
31+
const fileContent = map.get(filePath);
32+
33+
return {
34+
code: `
35+
${code}
36+
export const content = ${JSON.stringify(fileContent)};
37+
`,
38+
};
39+
},
40+
},
41+
];
42+
}
543

644
// https://astro.build/config
745
export default defineConfig({
46+
vite: {
47+
ssr: {
48+
noExternal: [
49+
'angular-three',
50+
'angular-three/**',
51+
'angular-three-soba/**',
52+
'angular-three-cannon',
53+
'angular-three-cannon/**',
54+
'angular-three-rapier',
55+
'angular-three-postprocessing',
56+
'angular-three-postprocessing/**',
57+
'@angular/common',
58+
'@angular/core',
59+
'@angular/core/rxjs-interop',
60+
'ngxtension/**',
61+
'@pmndrs/vanilla',
62+
'@pmndrs/cannon-worker-api',
63+
'three-custom-shader-material',
64+
],
65+
},
66+
esbuild: {
67+
jsxDev: true,
68+
},
69+
plugins: [includeContentPlugin()],
70+
},
871
integrations: [
72+
analogjsangular(),
973
starlight({
10-
title: 'Docs with Tailwind',
11-
social: {
12-
github: 'https://github.com/withastro/starlight',
13-
},
74+
title: 'Angular Three',
75+
plugins: [
76+
starlightBlog({
77+
authors: {
78+
chau: {
79+
name: 'Chau Tran',
80+
url: 'https://nartc.me',
81+
picture: 'https://avatars.githubusercontent.com/u/25516557?v=4',
82+
},
83+
},
84+
}),
85+
],
86+
favicon: './src/assets/angular-three-dark.svg',
87+
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4 },
88+
logo: { light: './src/assets/angular-three.svg', dark: './src/assets/angular-three-dark.svg' },
89+
social: { github: 'https://github.com/angular-threejs/angular-three' },
90+
credits: true,
91+
customCss: ['./src/tailwind.css'],
1492
sidebar: [
1593
{
1694
label: 'Guides',
@@ -24,7 +102,6 @@ export default defineConfig({
24102
autogenerate: { directory: 'reference' },
25103
},
26104
],
27-
customCss: ['./src/tailwind.css'],
28105
}),
29106
tailwind({ applyBaseStyles: false }),
30107
],

apps/docs/ec.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { pluginLineNumbers } from '@expressive-code/plugin-line-numbers';
2+
3+
export default {
4+
themes: ['dark-plus', 'light-plus'],
5+
plugins: [pluginLineNumbers()],
6+
};

apps/docs/package.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
2-
"name": "docs",
3-
"type": "module",
4-
"version": "0.0.1",
5-
"scripts": {
6-
"dev": "astro dev",
7-
"start": "astro dev",
8-
"build": "astro build",
9-
"preview": "astro preview",
10-
"astro": "astro"
11-
},
12-
"dependencies": {
13-
"@astrojs/starlight": "^0.31.1",
14-
"@astrojs/starlight-tailwind": "^3.0.0",
15-
"@astrojs/tailwind": "^5.1.4",
16-
"astro": "^5.1.5",
17-
"sharp": "^0.32.5",
18-
"tailwindcss": "^3.4.4"
19-
}
20-
}
2+
"name": "docs",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"scripts": {
6+
"dev": "astro dev",
7+
"start": "astro dev",
8+
"build": "astro build",
9+
"preview": "astro preview",
10+
"astro": "astro"
11+
},
12+
"dependencies": {
13+
"@astrojs/starlight": "^0.31.1",
14+
"@astrojs/starlight-tailwind": "^3.0.0",
15+
"@astrojs/tailwind": "^5.1.5",
16+
"astro": "^5.1.8",
17+
"starlight-blog": "^0.16.1",
18+
"sharp": "^0.33.5",
19+
"tailwindcss": "^3.4.17"
20+
},
21+
"devDependencies": {
22+
"@expressive-code/plugin-line-numbers": "^0.40.1"
23+
}
24+
}

apps/docs/src/assets/angular-three-dark.svg

Lines changed: 34 additions & 0 deletions
Loading

apps/docs/src/assets/angular-three.svg

Lines changed: 34 additions & 0 deletions
Loading

apps/docs/src/content.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { defineCollection } from 'astro:content';
2+
23
import { docsLoader } from '@astrojs/starlight/loaders';
34
import { docsSchema } from '@astrojs/starlight/schema';
5+
import { blogSchema } from 'starlight-blog/schema';
46

57
export const collections = {
6-
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
8+
// @ts-expect-error - not sure why this is an error
9+
docs: defineCollection({ loader: docsLoader(), schema: docsSchema({ extend: (context) => blogSchema(context) }) }),
710
};

apps/docs/src/env.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="../.astro/types.d.ts" />
2+
/// <reference types="astro/client" />
3+
4+
declare module '*?includeContent' {
5+
import type { Type } from '@angular/core';
6+
const component: Type<any>;
7+
export const content: string;
8+
export default component;
9+
}

apps/docs/tailwind.config.mjs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import colors from 'tailwindcss/colors';
21
import starlightPlugin from '@astrojs/starlight-tailwind';
32

3+
// Generated color palettes - oxide
4+
const accent = { 200: '#feb3a6', 600: '#a60a00', 900: '#640300', 950: '#460b05' };
5+
const gray = {
6+
100: '#f9f5f5',
7+
200: '#f3ecea',
8+
300: '#c8c0be',
9+
400: '#978784',
10+
500: '#635451',
11+
700: '#423432',
12+
800: '#302321',
13+
900: '#1d1715',
14+
};
15+
416
/** @type {import('tailwindcss').Config} */
517
export default {
618
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
719
theme: {
820
extend: {
9-
colors: {
10-
// Your preferred accent color. Indigo is closest to Starlight’s defaults.
11-
accent: colors.indigo,
12-
// Your preferred gray scale. Zinc is closest to Starlight’s defaults.
13-
gray: colors.zinc,
14-
},
21+
colors: { accent, gray },
1522
},
1623
},
1724
plugins: [starlightPlugin()],

apps/docs/tsconfig.app.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compileOnSave": false,
4+
"compilerOptions": {
5+
"baseUrl": "./",
6+
"outDir": "./dist/out-tsc",
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"noImplicitOverride": true,
10+
"noPropertyAccessFromIndexSignature": true,
11+
"noImplicitReturns": true,
12+
"noFallthroughCasesInSwitch": true,
13+
"sourceMap": true,
14+
"declaration": false,
15+
"downlevelIteration": true,
16+
"experimentalDecorators": true,
17+
"moduleResolution": "node",
18+
"importHelpers": true,
19+
"noEmit": false,
20+
"target": "es2020",
21+
"module": "es2020",
22+
"lib": ["es2020", "dom"],
23+
"skipLibCheck": true
24+
},
25+
"angularCompilerOptions": {
26+
"enableI18nLegacyMessageIdFormat": false,
27+
"strictInjectionParameters": true,
28+
"strictInputAccessModifiers": true,
29+
"strictTemplates": true,
30+
"allowJs": false
31+
},
32+
"files": [],
33+
"include": ["src/**/*.ts"]
34+
}

apps/kitchen-sink-new/src/app/misc/basic/scene.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ export class NestedBox {
107107
<ngt-mesh-toon-material [color]="color()" (attached)="onAttach($event)" />
108108
</ngt-mesh>
109109
110+
<ngt-primitive *args="[mesh]" [parameters]="{ position: [2, 0, 0] }" />
111+
110112
<!-- <app-nested-box [position]="[-3, 0, 0]" />-->
111113
112114
<!-- &lt;!&ndash; three element under condition &ndash;&gt;-->
@@ -172,16 +174,16 @@ export class NestedBox {
172174
</ngt-group>
173175
174176
<!-- portal -->
175-
<ngt-portal [container]="virtualScene">
176-
<ngt-group *portalContent>
177-
<!-- component inside portal -->
178-
<app-box context="in portal" />
179-
180-
@if (show()) {
181-
<app-box context="in portal in condition" />
182-
}
183-
</ngt-group>
184-
</ngt-portal>
177+
<!-- <ngt-portal [container]="virtualScene">-->
178+
<!-- <ngt-group *portalContent>-->
179+
<!-- &lt;!&ndash; component inside portal &ndash;&gt;-->
180+
<!-- <app-box context="in portal" />-->
181+
182+
<!-- @if (show()) {-->
183+
<!-- <app-box context="in portal in condition" />-->
184+
<!-- }-->
185+
<!-- </ngt-group>-->
186+
<!-- </ngt-portal>-->
185187
`,
186188
imports: [NgtArgs, Box, ConditionBox, NgtPortalDeclarations, NestedBox],
187189
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -201,6 +203,8 @@ export class Scene {
201203

202204
private groupRef = viewChild.required<ElementRef<THREE.Group>>('group');
203205

206+
protected mesh = new THREE.Mesh(new THREE.IcosahedronGeometry(), new THREE.MeshNormalMaterial());
207+
204208
constructor() {
205209
setInterval(() => {
206210
this.show.update((v) => !v);

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,34 @@ export class NgtRenderer2 implements Renderer2 {
202202
return createRendererNode('portal', platformElement, this.document);
203203
}
204204

205+
if (name === 'ngt-value') {
206+
return createRendererNode('three', prepare(platformElement, 'ngt-value'), this.document);
207+
}
208+
205209
const [injectedArgs, injectedParent] = [
206210
this.getNgtDirective(NgtArgs, this.argsInjectors)?.value || [],
207211
this.getNgtDirective(NgtParent, this.parentInjectors)?.value,
208212
];
209213

214+
if (name === 'ngt-primitive') {
215+
if (!injectedArgs[0]) throw new Error(`[NGT] ngt-primitive without args is invalid`);
216+
const object = injectedArgs[0];
217+
let instanceState = getInstanceState(object);
218+
if (!instanceState || instanceState.type === 'ngt-primitive') {
219+
// if an object isn't already "prepared", we'll prepare it
220+
prepare(object, 'ngt-primitive', instanceState);
221+
instanceState = getInstanceState(object);
222+
}
223+
224+
const primitiveRendererNode = createRendererNode('three', object, this.document);
225+
if (injectedParent) {
226+
primitiveRendererNode.__ngt_renderer__[NgtRendererClassId.parent] =
227+
injectedParent as unknown as NgtRendererNode<'three'>;
228+
}
229+
230+
return primitiveRendererNode;
231+
}
232+
210233
const threeName = kebabToPascal(name.startsWith('ngt-') ? name.slice(4) : name);
211234
const threeTarget = this.catalogue[threeName];
212235
//
@@ -725,7 +748,11 @@ export class NgtRenderer2 implements Renderer2 {
725748
// [rawValue]
726749
if (instanceState?.type === 'ngt-value' && name === 'rawValue') {
727750
rS[NgtRendererClassId.rawValue] = value;
728-
if (parent) this.appendChild(parent, el);
751+
if (parent) {
752+
// untrack this attach because this is during setProperty which is a reactive context
753+
// attaching potentially updates signals which is not allowed
754+
untracked(() => attachThreeNodes(parent, el as unknown as NgtInstanceNode));
755+
}
729756
return;
730757
}
731758

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,24 @@ export function attachThreeNodes(parent: NgtInstanceNode, child: NgtInstanceNode
109109
parent['material'] = [];
110110
}
111111

112-
// attach
113-
// save prev value
114-
cIS.previousAttach = attachProp.reduce((value, key) => value[key], parent);
115-
116112
if (cIS.type === 'ngt-value') {
117113
if (cIS.hierarchyStore.snapshot.parent !== parent) {
118114
cIS.setParent(parent);
119115
}
120116
// at this point we don't have rawValue yet, so we bail and wait until the Renderer recalls attach
121117
if ((child as unknown as NgtRendererNode).__ngt_renderer__[NgtRendererClassId.rawValue] === undefined) return;
118+
119+
// save prev value
120+
cIS.previousAttach = attachProp.reduce((value, key) => value[key], parent);
122121
attach(
123122
parent,
124123
(child as unknown as NgtRendererNode).__ngt_renderer__[NgtRendererClassId.rawValue],
125124
attachProp,
126125
true,
127126
);
128127
} else {
128+
// save prev value
129+
cIS.previousAttach = attachProp.reduce((value, key) => value[key], parent);
129130
attach(parent, child, attachProp);
130131
}
131132
}

0 commit comments

Comments
 (0)