@@ -12,9 +12,9 @@ import {
12
12
untracked ,
13
13
viewChild ,
14
14
} from '@angular/core' ;
15
- import { injectBeforeRender , NgtHTML , pick , resolveRef } from 'angular-three' ;
15
+ import { injectBeforeRender , injectStore , is , NgtHTML , pick , resolveRef } from 'angular-three' ;
16
16
import { mergeInputs } from 'ngxtension/inject-inputs' ;
17
- import { Object3D , OrthographicCamera , Vector3 } from 'three' ;
17
+ import * as THREE from 'three' ;
18
18
import { NgtsHTML } from './html' ;
19
19
import {
20
20
CalculatePosition ,
@@ -70,7 +70,7 @@ const defaultHtmlContentOptions: NgtsHTMLContentOptions = {
70
70
} ;
71
71
72
72
@Component ( {
73
- selector : '[ngtsHTMLContent ]' ,
73
+ selector : '[htmlContent ]' ,
74
74
template : `
75
75
@if (html.transform()) {
76
76
<div
@@ -90,10 +90,10 @@ const defaultHtmlContentOptions: NgtsHTMLContentOptions = {
90
90
#container
91
91
style="position:absolute"
92
92
[style.transform]="center() ? 'translate3d(-50%,-50%,0)' : 'none'"
93
- [style.top]="fullscreen() ? -size() .height / 2 + 'px' : 'unset'"
94
- [style.left]="fullscreen() ? -size() .width / 2 + 'px' : 'unset'"
95
- [style.width]="fullscreen() ? size() .width : 'unset'"
96
- [style.height]="fullscreen() ? size() .height : 'unset'"
93
+ [style.top]="fullscreen() ? -size.height() / 2 + 'px' : 'unset'"
94
+ [style.left]="fullscreen() ? -size.width() / 2 + 'px' : 'unset'"
95
+ [style.width]="fullscreen() ? size.width() : 'unset'"
96
+ [style.height]="fullscreen() ? size.height() : 'unset'"
97
97
[class]="containerClass()"
98
98
[style]="containerStyle()"
99
99
>
@@ -112,21 +112,18 @@ const defaultHtmlContentOptions: NgtsHTMLContentOptions = {
112
112
export class NgtsHTMLContent extends NgtHTML {
113
113
options = input ( defaultHtmlContentOptions , {
114
114
transform : mergeInputs ( defaultHtmlContentOptions ) ,
115
- alias : 'ngtsHTMLContent ' ,
115
+ alias : 'htmlContent ' ,
116
116
} ) ;
117
117
occluded = output < boolean > ( ) ;
118
118
119
- html = inject ( NgtsHTML ) ;
120
-
121
119
transformOuterRef = viewChild < ElementRef < HTMLDivElement > > ( 'transformOuter' ) ;
122
120
transformInnerRef = viewChild < ElementRef < HTMLDivElement > > ( 'transformInner' ) ;
123
121
containerRef = viewChild < ElementRef < HTMLDivElement > > ( 'container' ) ;
124
122
125
- private gl = this . store . select ( 'gl' ) ;
126
- private events = this . store . select ( 'events' ) ;
127
- private camera = this . store . select ( 'camera' ) ;
128
- private scene = this . store . select ( 'scene' ) ;
129
- protected size = this . store . select ( 'size' ) ;
123
+ protected html = inject ( NgtsHTML ) ;
124
+ private host = inject < ElementRef < HTMLElement > > ( ElementRef ) ;
125
+ private store = injectStore ( ) ;
126
+ protected size = this . store . size ;
130
127
131
128
private parent = pick ( this . options , 'parent' ) ;
132
129
private zIndexRange = pick ( this . options , 'zIndexRange' ) ;
@@ -141,7 +138,7 @@ export class NgtsHTMLContent extends NgtHTML {
141
138
private target = computed ( ( ) => {
142
139
const parent = resolveRef ( this . parent ( ) ) ;
143
140
if ( parent ) return parent ;
144
- return ( this . events ( ) . connected || this . gl ( ) . domElement . parentNode ) as HTMLElement ;
141
+ return ( this . store . events . connected ?. ( ) || this . store . gl . domElement . parentNode ( ) ) as HTMLElement ;
145
142
} ) ;
146
143
147
144
constructor ( ) {
@@ -154,7 +151,7 @@ export class NgtsHTMLContent extends NgtHTML {
154
151
effect ( ( ) => {
155
152
const [ occlude , canvasEl , zIndexRange ] = [
156
153
this . html . occlude ( ) ,
157
- untracked ( this . gl ) . domElement ,
154
+ this . store . snapshot . gl . domElement ,
158
155
untracked ( this . zIndexRange ) ,
159
156
] ;
160
157
@@ -175,11 +172,11 @@ export class NgtsHTMLContent extends NgtHTML {
175
172
this . target ( ) ,
176
173
this . host . nativeElement ,
177
174
untracked ( this . prepend ) ,
178
- untracked ( this . scene ) ,
175
+ this . store . snapshot . scene ,
179
176
untracked ( this . calculatePosition ) ,
180
177
untracked ( this . html . groupRef ) . nativeElement ,
181
- untracked ( this . size ) ,
182
- untracked ( this . camera ) ,
178
+ this . store . snapshot . size ,
179
+ this . store . snapshot . camera ,
183
180
] ;
184
181
185
182
scene . updateMatrixWorld ( ) ;
@@ -254,11 +251,11 @@ export class NgtsHTMLContent extends NgtHTML {
254
251
Math . abs ( oldPosition [ 1 ] - vec [ 1 ] ) > eps
255
252
) {
256
253
const isBehindCamera = isObjectBehindCamera ( group , camera ) ;
257
- let raytraceTarget : null | undefined | boolean | Object3D [ ] = false ;
254
+ let raytraceTarget : null | undefined | boolean | THREE . Object3D [ ] = false ;
258
255
259
256
if ( isRaycastOcclusion ) {
260
257
if ( Array . isArray ( occlude ) ) {
261
- raytraceTarget = occlude . map ( ( item ) => resolveRef ( item ) ) as Object3D [ ] ;
258
+ raytraceTarget = occlude . map ( ( item ) => resolveRef ( item ) ) as THREE . Object3D [ ] ;
262
259
} else if ( occlude !== 'blending' ) {
263
260
raytraceTarget = [ scene ] ;
264
261
}
@@ -289,7 +286,7 @@ export class NgtsHTMLContent extends NgtHTML {
289
286
if ( transform ) {
290
287
const [ widthHalf , heightHalf ] = [ size . width / 2 , size . height / 2 ] ;
291
288
const fov = camera . projectionMatrix . elements [ 5 ] * heightHalf ;
292
- const { isOrthographicCamera, top, left, bottom, right } = camera as OrthographicCamera ;
289
+ const { isOrthographicCamera, top, left, bottom, right } = camera as THREE . OrthographicCamera ;
293
290
const cameraMatrix = getCameraCSSMatrix ( camera . matrixWorldInverse ) ;
294
291
const cameraTransform = isOrthographicCamera
295
292
? `scale(${ fov } )translate(${ epsilon ( - ( right + left ) / 2 ) } px,${ epsilon ( ( top + bottom ) / 2 ) } px)`
@@ -332,13 +329,13 @@ export class NgtsHTMLContent extends NgtHTML {
332
329
const el = transformOuterEl . children [ 0 ] ;
333
330
334
331
if ( el ?. clientWidth && el ?. clientHeight ) {
335
- const { isOrthographicCamera } = camera as OrthographicCamera ;
332
+ const { isOrthographicCamera } = camera as THREE . OrthographicCamera ;
336
333
337
334
if ( isOrthographicCamera || occlusionGeometry ) {
338
335
if ( scale ) {
339
336
if ( ! Array . isArray ( scale ) ) {
340
337
occlusionMesh . scale . setScalar ( 1 / ( scale as number ) ) ;
341
- } else if ( scale instanceof Vector3 ) {
338
+ } else if ( is . three < THREE . Vector3 > ( scale , 'isVector3' ) ) {
342
339
occlusionMesh . scale . copy ( scale . clone ( ) . divideScalar ( 1 ) ) ;
343
340
} else {
344
341
occlusionMesh . scale . set ( 1 / scale [ 0 ] , 1 / scale [ 1 ] , 1 / scale [ 2 ] ) ;
0 commit comments