@@ -13,7 +13,7 @@ import {
13
13
import { injectBeforeRender , injectStore , NgtHTML , pick , provideHTMLDomElement } from 'angular-three' ;
14
14
import { easing } from 'maath' ;
15
15
import { mergeInputs } from 'ngxtension/inject-inputs' ;
16
- import { Group } from 'three' ;
16
+ import * as THREE from 'three' ;
17
17
18
18
export interface NgtsScrollControlsOptions {
19
19
/** Precision, default 0.00001 */
@@ -65,13 +65,6 @@ export class NgtsScrollControls {
65
65
66
66
private document = inject ( DOCUMENT ) ;
67
67
private store = injectStore ( ) ;
68
- private gl = this . store . select ( 'gl' ) ;
69
- private events = this . store . select ( 'events' ) ;
70
- private invalidate = this . store . select ( 'invalidate' ) ;
71
- private size = this . store . select ( 'size' ) ;
72
-
73
- private domElement = pick ( this . gl , 'domElement' ) ;
74
- private target = pick ( this . domElement , 'parentNode' ) ;
75
68
76
69
private _el = this . document . createElement ( 'div' ) ;
77
70
private _fill = this . document . createElement ( 'div' ) ;
@@ -82,6 +75,7 @@ export class NgtsScrollControls {
82
75
private enabled = pick ( this . options , 'enabled' ) ;
83
76
private infinite = pick ( this . options , 'infinite' ) ;
84
77
private maxSpeed = pick ( this . options , 'maxSpeed' ) ;
78
+
85
79
eps = pick ( this . options , 'eps' ) ;
86
80
horizontal = pick ( this . options , 'horizontal' ) ;
87
81
pages = pick ( this . options , 'pages' ) ;
@@ -93,7 +87,7 @@ export class NgtsScrollControls {
93
87
94
88
constructor ( ) {
95
89
effect ( ( onCleanup ) => {
96
- const target = this . target ( ) ;
90
+ const target = this . store . gl . domElement . parentNode ( ) ;
97
91
if ( ! target ) return ;
98
92
99
93
const parent = target as HTMLElement ;
@@ -106,8 +100,8 @@ export class NgtsScrollControls {
106
100
this . fixed ,
107
101
untracked ( this . style ) ,
108
102
untracked ( this . prepend ) ,
109
- untracked ( this . domElement ) ,
110
- untracked ( this . events ) ,
103
+ this . store . snapshot . gl . domElement ,
104
+ this . store . snapshot . events ,
111
105
] ;
112
106
113
107
el . style . position = 'absolute' ;
@@ -165,13 +159,13 @@ export class NgtsScrollControls {
165
159
} ) ;
166
160
167
161
effect ( ( onCleanup ) => {
168
- const [ el , events ] = [ this . el , this . events ( ) ] ;
162
+ const [ el , events ] = [ this . el , this . store . events ( ) ] ;
169
163
if ( ! events . connected || events . connected !== el ) return ;
170
164
171
165
const [ size , infinite , invalidate , horizontal , enabled ] = [
172
- this . size ( ) ,
166
+ this . store . size ( ) ,
173
167
this . infinite ( ) ,
174
- this . invalidate ( ) ,
168
+ this . store . invalidate ( ) ,
175
169
this . horizontal ( ) ,
176
170
this . enabled ( ) ,
177
171
] ;
@@ -237,7 +231,7 @@ export class NgtsScrollControls {
237
231
undefined ,
238
232
this . eps ( ) ,
239
233
) ;
240
- if ( this . delta > this . eps ( ) ) this . invalidate ( ) ( ) ;
234
+ if ( this . delta > this . eps ( ) ) this . store . invalidate ( ) ( ) ;
241
235
} ) ;
242
236
}
243
237
@@ -270,45 +264,46 @@ export class NgtsScrollControls {
270
264
}
271
265
}
272
266
273
- @Directive ( { selector : 'ngt-group[ngtsScrollCanvas ]' } )
274
- export class NgtsScrollCanvas {
275
- private host = inject < ElementRef < Group > > ( ElementRef ) ;
267
+ @Directive ( { selector : 'ngt-group[canvasScrollContent ]' } )
268
+ export class NgtsCanvasScrollContent {
269
+ private host = inject < ElementRef < THREE . Group > > ( ElementRef ) ;
276
270
private scrollControls = inject ( NgtsScrollControls ) ;
277
271
private store = injectStore ( ) ;
278
- private viewport = this . store . select ( 'viewport' ) ;
279
272
280
273
constructor ( ) {
281
274
injectBeforeRender ( ( ) => {
282
275
const group = this . host . nativeElement ;
283
276
284
277
group . position . x = this . scrollControls . horizontal ( )
285
- ? - this . viewport ( ) . width * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset
278
+ ? - this . store . snapshot . viewport . width * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset
286
279
: 0 ;
287
280
group . position . y = this . scrollControls . horizontal ( )
288
281
? 0
289
- : this . viewport ( ) . height * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset ;
282
+ : this . store . snapshot . viewport . height * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset ;
290
283
} ) ;
291
284
}
292
285
}
293
286
294
287
@Directive ( {
295
- selector : 'div[ngtsScrollHTML ]' ,
288
+ selector : 'div[htmlScrollContent ]' ,
296
289
host : { style : 'position: absolute; top: 0; left: 0; will-change: transform;' } ,
297
290
providers : [ provideHTMLDomElement ( [ NgtsScrollControls ] , ( scrollControls ) => scrollControls . fixed ) ] ,
298
291
} )
299
- export class NgtsScrollHtml extends NgtHTML {
292
+ export class NgtsHTMLScrollContent extends NgtHTML {
300
293
private scrollControls = inject ( NgtsScrollControls ) ;
301
- private size = this . store . select ( 'size' ) ;
294
+ private store = injectStore ( ) ;
295
+ private host = inject < ElementRef < HTMLDivElement > > ( ElementRef ) ;
302
296
303
297
constructor ( ) {
304
298
super ( ) ;
299
+
305
300
injectBeforeRender ( ( ) => {
306
301
if ( this . scrollControls . delta > this . scrollControls . eps ( ) ) {
307
302
this . host . nativeElement . style . transform = `translate3d(${
308
303
this . scrollControls . horizontal ( )
309
- ? - this . size ( ) . width * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset
304
+ ? - this . store . snapshot . size . width * ( this . scrollControls . pages ( ) - 1 ) * this . scrollControls . offset
310
305
: 0
311
- } px,${ this . scrollControls . horizontal ( ) ? 0 : this . size ( ) . height * ( this . scrollControls . pages ( ) - 1 ) * - this . scrollControls . offset } px,0)`;
306
+ } px,${ this . scrollControls . horizontal ( ) ? 0 : this . store . snapshot . size . height * ( this . scrollControls . pages ( ) - 1 ) * - this . scrollControls . offset } px,0)`;
312
307
}
313
308
} ) ;
314
309
}
0 commit comments