aptechka 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/.prettierignore +16 -0
  2. package/.prettierrc +9 -0
  3. package/.vscode/extensions.json +4 -0
  4. package/.vscode/launch.json +11 -0
  5. package/.vscode/settings.json +18 -0
  6. package/README.md +0 -0
  7. package/index.html +32 -0
  8. package/package.json +272 -0
  9. package/public/vite.svg +1 -0
  10. package/src/packages/animation/Animated.ts +189 -0
  11. package/src/packages/animation/Damped.ts +39 -0
  12. package/src/packages/animation/Tweened.ts +51 -0
  13. package/src/packages/animation/index.ts +10 -0
  14. package/src/packages/attribute/index.ts +59 -0
  15. package/src/packages/canvas-2d/index.ts +137 -0
  16. package/src/packages/controls/Controls.ts +15 -0
  17. package/src/packages/controls/KeyboardControls.ts +63 -0
  18. package/src/packages/controls/LinearControls.ts +27 -0
  19. package/src/packages/controls/User.ts +20 -0
  20. package/src/packages/controls/WheelControls.ts +92 -0
  21. package/src/packages/controls/index.ts +5 -0
  22. package/src/packages/css-unit-parser/index.ts +32 -0
  23. package/src/packages/custom-element/index.ts +19 -0
  24. package/src/packages/device/Device.ts +113 -0
  25. package/src/packages/device/Viewport.ts +67 -0
  26. package/src/packages/device/index.ts +2 -0
  27. package/src/packages/element-constructor/ElementConstructor.ts +577 -0
  28. package/src/packages/element-constructor/htmlTags.ts +679 -0
  29. package/src/packages/element-constructor/index.ts +4 -0
  30. package/src/packages/element-constructor/specialObjects.ts +8 -0
  31. package/src/packages/element-constructor/svgTags.ts +588 -0
  32. package/src/packages/en3/attachments/En3SourceManager.ts +116 -0
  33. package/src/packages/en3/core/en3.ts +306 -0
  34. package/src/packages/en3/index.ts +52 -0
  35. package/src/packages/en3/instances/en3LazyLoader.ts +22 -0
  36. package/src/packages/en3/libs/MeshoptDecoder.js +138 -0
  37. package/src/packages/en3/loaders/en3GLTFLoader.ts +54 -0
  38. package/src/packages/en3/loaders/en3TextureLoader.ts +3 -0
  39. package/src/packages/en3/objects/En3Clip.ts +53 -0
  40. package/src/packages/en3/objects/En3ClipHelpers.ts +12 -0
  41. package/src/packages/en3/objects/En3GLTF.ts +35 -0
  42. package/src/packages/en3/objects/En3Image.ts +18 -0
  43. package/src/packages/en3/objects/En3ImageLike.ts +101 -0
  44. package/src/packages/en3/objects/En3SourceConsumer.ts +5 -0
  45. package/src/packages/en3/objects/En3Video.ts +88 -0
  46. package/src/packages/en3/test/En3HTML.ts +55 -0
  47. package/src/packages/en3/test/En3ModifiedMaterial.ts +221 -0
  48. package/src/packages/en3/test/En3Raycaster.ts +187 -0
  49. package/src/packages/en3/utils/coverTexture.ts +29 -0
  50. package/src/packages/en3/utils/dispose.ts +27 -0
  51. package/src/packages/en3/utils/traverseMaterials.ts +10 -0
  52. package/src/packages/en3/utils/traverseMeshes.ts +9 -0
  53. package/src/packages/image/index.ts +19 -0
  54. package/src/packages/intersector/index.ts +83 -0
  55. package/src/packages/ladder/index.ts +112 -0
  56. package/src/packages/layout-box/index.ts +417 -0
  57. package/src/packages/loading/index.ts +131 -0
  58. package/src/packages/measurer/CumulativeOffsetLeft.ts +8 -0
  59. package/src/packages/measurer/CumulativeOffsetTop.ts +8 -0
  60. package/src/packages/measurer/Meaurer.ts +38 -0
  61. package/src/packages/measurer/index.ts +3 -0
  62. package/src/packages/media/index.ts +38 -0
  63. package/src/packages/morph/Link.ts +32 -0
  64. package/src/packages/morph/Morph.ts +246 -0
  65. package/src/packages/morph/index.ts +10 -0
  66. package/src/packages/notifier/index.ts +41 -0
  67. package/src/packages/order/index.ts +14 -0
  68. package/src/packages/resizer/index.ts +55 -0
  69. package/src/packages/router/Link.ts +33 -0
  70. package/src/packages/router/Route.ts +152 -0
  71. package/src/packages/router/RouteElement.ts +34 -0
  72. package/src/packages/router/Router.ts +190 -0
  73. package/src/packages/router/index.ts +13 -0
  74. package/src/packages/scroll/ScrollElement.ts +618 -0
  75. package/src/packages/scroll/ScrollUserElement.ts +21 -0
  76. package/src/packages/scroll/ScrollbarElement.ts +170 -0
  77. package/src/packages/scroll/index.ts +2 -0
  78. package/src/packages/scroll-entries/index.ts +74 -0
  79. package/src/packages/source/SourceClass.ts +77 -0
  80. package/src/packages/source/SourceElement.ts +177 -0
  81. package/src/packages/source/SourceManager.ts +61 -0
  82. package/src/packages/source/SourceSet.ts +52 -0
  83. package/src/packages/source/index.ts +8 -0
  84. package/src/packages/store/Composed.ts +33 -0
  85. package/src/packages/store/Derived.ts +24 -0
  86. package/src/packages/store/DerivedArray.ts +36 -0
  87. package/src/packages/store/Resource.ts +38 -0
  88. package/src/packages/store/Store.ts +144 -0
  89. package/src/packages/store/StoreRegistry.ts +105 -0
  90. package/src/packages/store/index.ts +23 -0
  91. package/src/packages/ticker/index.ts +173 -0
  92. package/src/packages/utils/array.ts +3 -0
  93. package/src/packages/utils/attributes.ts +19 -0
  94. package/src/packages/utils/browser.ts +2 -0
  95. package/src/packages/utils/canvas.ts +46 -0
  96. package/src/packages/utils/collisions.ts +12 -0
  97. package/src/packages/utils/coordinates.ts +40 -0
  98. package/src/packages/utils/decoding.ts +11 -0
  99. package/src/packages/utils/dev.ts +5 -0
  100. package/src/packages/utils/dom.ts +48 -0
  101. package/src/packages/utils/easings.ts +69 -0
  102. package/src/packages/utils/file.ts +17 -0
  103. package/src/packages/utils/function.ts +29 -0
  104. package/src/packages/utils/index.ts +61 -0
  105. package/src/packages/utils/layout.ts +22 -0
  106. package/src/packages/utils/math.ts +74 -0
  107. package/src/packages/utils/number.ts +26 -0
  108. package/src/packages/utils/object.ts +108 -0
  109. package/src/packages/utils/string.ts +49 -0
  110. package/src/packages/utils/ts-shape.ts +25 -0
  111. package/src/packages/utils/ts-utility.ts +47 -0
  112. package/src/packages/video/index.ts +39 -0
  113. package/src/playground/index.ts +0 -0
  114. package/tsconfig.json +31 -0
  115. package/vite.config.ts +65 -0
@@ -0,0 +1,618 @@
1
+ import { Damped } from '$packages/animation'
2
+ import { Attribute } from '$packages/attribute'
3
+ import { WheelControls, KeyboardControls, ControlsValue } from '$packages/controls'
4
+ import { define, CustomElement } from '$packages/custom-element'
5
+ import { TICK_ORDER, RESIZE_ORDER } from '$packages/order'
6
+ import { resizer } from '$packages/resizer'
7
+ import { scrollEnties } from '$packages/scroll-entries'
8
+ import { Store } from '$packages/store'
9
+ import {
10
+ getCumulativeOffsetTop,
11
+ getCumulativeOffsetLeft,
12
+ Axes2D,
13
+ isBrowser,
14
+ clamp,
15
+ } from '$packages/utils'
16
+
17
+ export type ScrollBehaviour = 'smooth' | 'instant'
18
+
19
+ class Section {
20
+ #element: HTMLElement
21
+ #scrollElement: ScrollElement
22
+
23
+ #size = 0
24
+ #position = 0
25
+
26
+ constructor(element: HTMLElement, scrollElement: ScrollElement) {
27
+ this.#element = element
28
+ this.#scrollElement = scrollElement
29
+
30
+ scrollEnties.register(this.#element)
31
+ }
32
+
33
+ public get size() {
34
+ return this.#size
35
+ }
36
+
37
+ public get position() {
38
+ return this.#position
39
+ }
40
+
41
+ public destroy() {
42
+ scrollEnties.unregister(this.#element)
43
+ this.#element.style.transform = ''
44
+ }
45
+
46
+ public resize() {
47
+ this.#size = this.#scrollElement.vertical
48
+ ? this.#element.offsetHeight
49
+ : this.#element.offsetWidth
50
+
51
+ this.#position = this.#scrollElement.vertical
52
+ ? getCumulativeOffsetTop(this.#element)
53
+ : getCumulativeOffsetLeft(this.#element)
54
+
55
+ this.#position -= this.#scrollElement.position
56
+ }
57
+
58
+ public transform() {
59
+ let offset = 0
60
+
61
+ if (
62
+ this.#scrollElement.infiniteAttribute.current &&
63
+ this.#scrollElement.overscroll &&
64
+ this.#position + this.#size < this.#scrollElement.currentScrollValue
65
+ ) {
66
+ offset = this.#scrollElement.distance * -1
67
+ }
68
+
69
+ scrollEnties.update(this.#element, this.#scrollElement.axisAttibute.current, offset)
70
+
71
+ const value = clamp(
72
+ this.#scrollElement.currentScrollValue + offset,
73
+ this.#position - this.#scrollElement.viewportSize,
74
+ this.#position + this.#size
75
+ )
76
+
77
+ if (this.#scrollElement.vertical) {
78
+ this.#element.style.transform = `translate3d(0px, ${value * -1}px, 0px)`
79
+ } else {
80
+ this.#element.style.transform = `translate3d(${value * -1}px, 0px, 0px)`
81
+ }
82
+ }
83
+ }
84
+
85
+ @define('e-scroll')
86
+ export class ScrollElement extends CustomElement {
87
+ #damped: Damped = null!
88
+
89
+ #axisAttribute = new Attribute<Axes2D>(this, 'axis', 'y')
90
+ #pagesAttribute = new Attribute<number>(this, 'pages', 0, {
91
+ validate: (v) => Math.max(0, v - 1),
92
+ })
93
+ #sectionalAttribute = new Attribute<boolean>(this, 'sectional', false)
94
+ #infiniteAttribute = new Attribute<boolean>(this, 'infinite', false)
95
+ #splitAttribute = new Attribute<boolean>(this, 'split', false)
96
+ #dampingAttribute = new Attribute<number>(this, 'damping', 0.03)
97
+ #disabledAttribute = new Attribute<boolean>(this, 'disabled', false)
98
+ #hibernatedAttribute = new Attribute<boolean>(this, 'hibernated', false)
99
+
100
+ #contentElement: HTMLElement = null!
101
+ #sections: Array<Section> = []
102
+
103
+ #position = 0
104
+ #viewportSize = 0
105
+ #scrollSize = 0
106
+
107
+ #wheelControls: WheelControls = null!
108
+ #keyboardControls: KeyboardControls = null!
109
+
110
+ #counter = new Store(0)
111
+
112
+ #overscroll = 0
113
+ #distance = 0
114
+
115
+ constructor() {
116
+ super()
117
+
118
+ if (isBrowser) {
119
+ this.#damped = new Damped({ damping: 0.01, min: 0, order: TICK_ORDER.SCROLL })
120
+
121
+ const shadowRoot = this.attachShadow({ mode: 'open' })
122
+
123
+ const styleElement = document.createElement('style')
124
+ styleElement.textContent = `
125
+ :host {
126
+ position: relative;
127
+
128
+ width: 100%;
129
+ height: 100%;
130
+
131
+ display: block;
132
+ outline: none;
133
+ }
134
+
135
+ :host([hibernated="true"]) {
136
+ display: contents;
137
+ }
138
+
139
+ .static {
140
+ position: absolute;
141
+ top: 0;
142
+ left: 0;
143
+
144
+ z-index: 1;
145
+
146
+ width: 100%;
147
+ height: 100%;
148
+
149
+ }
150
+
151
+ .content {
152
+ display: flex;
153
+ }
154
+
155
+ :host([hibernated="true"]) .content {
156
+ display: contents;
157
+ }
158
+
159
+ ::slotted(*) {
160
+ flex-shrink: 0;
161
+ }
162
+ `
163
+ shadowRoot.appendChild(styleElement)
164
+
165
+ this.tabIndex = 0
166
+
167
+ const staticElement = document.createElement('div')
168
+ staticElement.classList.add('static')
169
+ shadowRoot.appendChild(staticElement)
170
+
171
+ const staticSlotElement = document.createElement('slot')
172
+ staticSlotElement.setAttribute('name', 'static')
173
+ staticElement.appendChild(staticSlotElement)
174
+
175
+ this.#contentElement = document.createElement('div')
176
+ this.#contentElement.classList.add('content')
177
+ shadowRoot.appendChild(this.#contentElement)
178
+
179
+ const defaultSlotElement = document.createElement('slot')
180
+ this.#contentElement.appendChild(defaultSlotElement)
181
+
182
+ this.#wheelControls = new WheelControls({ element: this })
183
+ this.#wheelControls.changeEvent.subscribe(this.#controlsListener)
184
+
185
+ this.#keyboardControls = new KeyboardControls({ element: this })
186
+ this.#keyboardControls.changeEvent.subscribe(this.#controlsListener)
187
+
188
+ this.#axisAttribute.subscribe(({ current }) => {
189
+ this.#contentElement.style.flexDirection = current === 'x' ? 'row' : 'column'
190
+ this.#wheelControls.axis = current
191
+
192
+ if (this.isConnected) {
193
+ this.#resizeListener()
194
+ }
195
+ })
196
+
197
+ this.#pagesAttribute.subscribe(() => {
198
+ if (this.isConnected) {
199
+ this.#resizeListener()
200
+ }
201
+ })
202
+
203
+ this.#sectionalAttribute.subscribe((e) => {
204
+ this.#counter.current = 0
205
+ this.#wheelControls.debounce = e.current
206
+ this.#damped.reset()
207
+
208
+ if (this.isConnected) {
209
+ if (e.current && !e.previous) {
210
+ this.#split()
211
+ } else if (!e.current && e.previous) {
212
+ this.#unsplit()
213
+ }
214
+ }
215
+ })
216
+
217
+ this.#infiniteAttribute.subscribe((e) => {
218
+ if (!e.current) {
219
+ this.#overscroll = 0
220
+ this.#damped.max = this.#scrollSize
221
+ this.#damped.min = 0
222
+ } else {
223
+ if (this.isConnected) {
224
+ if (!this.#sections.length) {
225
+ this.#splitAttribute.current = true
226
+ }
227
+ }
228
+
229
+ if (this.#sections.length) {
230
+ this.#damped.max = Infinity
231
+ this.#damped.min = -Infinity
232
+ }
233
+ }
234
+ })
235
+
236
+ this.#splitAttribute.subscribe(({ current }) => {
237
+ if (this.isConnected) {
238
+ if (current) {
239
+ this.#split()
240
+ } else {
241
+ this.#unsplit()
242
+ }
243
+ }
244
+ })
245
+
246
+ this.#dampingAttribute.subscribe((e) => {
247
+ this.#damped.damping = e.current
248
+ })
249
+
250
+ this.#disabledAttribute.subscribe((e) => {
251
+ if (e.current && !e.previous) {
252
+ this.#disable()
253
+ } else if (!e.current && e.previous) {
254
+ this.#enable()
255
+ }
256
+ })
257
+
258
+ this.#hibernatedAttribute.subscribe((e) => {
259
+ if (e.current && !e.previous) {
260
+ this.#hibernate()
261
+ } else if (!e.current && e.previous) {
262
+ this.#awake()
263
+ }
264
+ })
265
+ }
266
+ }
267
+
268
+ public get currentScrollValue() {
269
+ return this.#getScrollValue('current')
270
+ }
271
+
272
+ public get targetScrollValue() {
273
+ return this.#getScrollValue('target')
274
+ }
275
+
276
+ public get damped() {
277
+ return this.#damped
278
+ }
279
+
280
+ public get dampedAttibute() {
281
+ return this.#damped
282
+ }
283
+
284
+ public get axisAttibute() {
285
+ return this.#axisAttribute
286
+ }
287
+
288
+ public get pagesAttibute() {
289
+ return this.#pagesAttribute
290
+ }
291
+
292
+ public get sectionalAttibute() {
293
+ return this.#sectionalAttribute
294
+ }
295
+
296
+ public get infiniteAttribute() {
297
+ return this.#infiniteAttribute
298
+ }
299
+
300
+ public get splitAttibute() {
301
+ return this.#splitAttribute
302
+ }
303
+
304
+ public get dampingAttibute() {
305
+ return this.#dampingAttribute
306
+ }
307
+
308
+ public get disabledAttibute() {
309
+ return this.#disabledAttribute
310
+ }
311
+
312
+ public get hibernatedAttibute() {
313
+ return this.#hibernatedAttribute
314
+ }
315
+
316
+ public get position() {
317
+ return this.#position
318
+ }
319
+
320
+ public get viewportSize() {
321
+ return this.#viewportSize
322
+ }
323
+
324
+ public get scrollSize() {
325
+ return this.#scrollSize
326
+ }
327
+
328
+ public get counter() {
329
+ return this.#counter
330
+ }
331
+
332
+ public get distance() {
333
+ return this.#distance
334
+ }
335
+
336
+ public get overscroll() {
337
+ return this.#overscroll
338
+ }
339
+
340
+ public get vertical() {
341
+ return this.#axisAttribute.current === 'y'
342
+ }
343
+
344
+ public get currentProgress() {
345
+ return this.currentScrollValue / this.#distance
346
+ }
347
+
348
+ public get targetProgress() {
349
+ return this.targetScrollValue / this.#distance
350
+ }
351
+
352
+ // TODO: Поправить значение когда скролл не секционный ??
353
+ public scrollToSection(sectionIndex: number, behaviour: ScrollBehaviour = 'smooth') {
354
+ if (!this.#sections.length) {
355
+ return
356
+ }
357
+
358
+ const previousCounter = this.#counter.current
359
+
360
+ this.#setCounter(sectionIndex)
361
+
362
+ const previousSection = this.#sections[previousCounter]
363
+ const currentSection = this.#sections[this.#counter.current]
364
+
365
+ if (previousSection && currentSection) {
366
+ let shiftValue = 0
367
+
368
+ const limit = this.#sections.length - 1
369
+
370
+ if (this.#counter.current === 0 && previousCounter === limit) {
371
+ shiftValue = this.#scrollSize + this.#viewportSize - previousSection.position
372
+ } else if (this.#counter.current === limit && previousCounter === 0) {
373
+ shiftValue = currentSection.position - (this.#scrollSize + this.#viewportSize)
374
+ } else {
375
+ shiftValue = currentSection.position - previousSection.position
376
+ }
377
+
378
+ this.#damped.shift(shiftValue, behaviour === 'instant')
379
+ }
380
+ }
381
+
382
+ public shiftSections(direction: number, behaviour: ScrollBehaviour = 'smooth') {
383
+ if (!this.#sections.length) {
384
+ return
385
+ }
386
+
387
+ this.scrollToSection(this.#counter.current + direction, behaviour)
388
+ }
389
+
390
+ protected connectedCallback() {
391
+ this.#awake()
392
+
393
+ this.#axisAttribute.observe()
394
+ this.#pagesAttribute.observe()
395
+ this.#sectionalAttribute.observe()
396
+ this.#infiniteAttribute.observe()
397
+ this.#splitAttribute.observe()
398
+ this.#dampingAttribute.observe()
399
+ this.#disabledAttribute.observe()
400
+ this.#hibernatedAttribute.observe()
401
+ }
402
+
403
+ protected disconnectedCallback() {
404
+ this.#hibernate()
405
+
406
+ this.#axisAttribute.unobserve()
407
+ this.#pagesAttribute.unobserve()
408
+ this.#sectionalAttribute.unobserve()
409
+ this.#infiniteAttribute.unobserve()
410
+ this.#splitAttribute.unobserve()
411
+ this.#dampingAttribute.unobserve()
412
+ this.#disabledAttribute.unobserve()
413
+ this.#hibernatedAttribute.unobserve()
414
+ }
415
+
416
+ #split() {
417
+ this.#unsplit()
418
+
419
+ const slot = this.#contentElement!.querySelector('slot') as HTMLSlotElement
420
+
421
+ slot.assignedElements().forEach((element) => {
422
+ if (element instanceof HTMLElement) {
423
+ this.#sections.push(new Section(element, this))
424
+ }
425
+ })
426
+
427
+ this.#contentElement.style.transform = ''
428
+
429
+ this.#resizeListener()
430
+ }
431
+
432
+ #unsplit() {
433
+ this.#sections.forEach((section) => {
434
+ section.destroy()
435
+ })
436
+
437
+ this.#sections = []
438
+ }
439
+
440
+ #disable() {
441
+ this.#damped.unsubscribe(this.#animatedChangeListener)
442
+ this.#damped.unlistenAnimationFrame()
443
+
444
+ this.#wheelControls.disconnect()
445
+ this.#keyboardControls.disconnect()
446
+ }
447
+
448
+ #enable() {
449
+ this.#damped.subscribe(this.#animatedChangeListener)
450
+
451
+ this.#wheelControls.connect()
452
+ this.#keyboardControls.connect()
453
+ }
454
+
455
+ #hibernate() {
456
+ resizer.unsubscribe(this.#resizeListener)
457
+
458
+ this.#damped.reset()
459
+
460
+ this.#disable()
461
+
462
+ this.#contentElement.style.transform = ''
463
+
464
+ if (this.#splitAttribute.current) {
465
+ this.#unsplit()
466
+ }
467
+
468
+ scrollEnties.unregister(this)
469
+ }
470
+
471
+ #awake() {
472
+ if (this.#splitAttribute.current) {
473
+ this.#split()
474
+ }
475
+
476
+ scrollEnties.register(this)
477
+
478
+ resizer.subscribe(this.#resizeListener, RESIZE_ORDER.SCROLL)
479
+
480
+ this.#enable()
481
+ }
482
+
483
+ #resizeListener = () => {
484
+ const prevProgress = this.currentScrollValue / this.#scrollSize
485
+
486
+ this.#position = this.vertical ? getCumulativeOffsetTop(this) : getCumulativeOffsetLeft(this)
487
+ this.#viewportSize = this.vertical ? this.offsetHeight : this.offsetWidth
488
+
489
+ if (this.#pagesAttribute.current) {
490
+ this.#scrollSize = this.#viewportSize * this.#pagesAttribute.current
491
+ const contentSize = this.#scrollSize + this.#viewportSize
492
+
493
+ if (this.vertical) {
494
+ this.#contentElement.style.width = contentSize + 'px'
495
+ this.#contentElement.style.height = '100%'
496
+ } else {
497
+ this.#contentElement.style.height = contentSize + 'px'
498
+ this.#contentElement.style.width = '100%'
499
+ }
500
+ } else {
501
+ if (this.vertical) {
502
+ this.#contentElement.style.width = '100%'
503
+ this.#contentElement.style.height = 'max-content'
504
+ this.#scrollSize = this.#contentElement.offsetHeight - this.#viewportSize
505
+ } else {
506
+ this.#contentElement.style.width = 'max-content'
507
+ this.#contentElement.style.height = '100%'
508
+ this.#scrollSize = this.#contentElement.offsetWidth - this.#viewportSize
509
+ }
510
+ }
511
+
512
+ if (!this.#infiniteAttribute) {
513
+ this.#damped.max = this.#scrollSize
514
+ }
515
+
516
+ this.#sections.forEach((section) => {
517
+ section.resize()
518
+ section.transform()
519
+ })
520
+
521
+ if (this.#infiniteAttribute.current && this.#sections.length) {
522
+ const lastSection = this.#sections[this.#sections.length - 1]
523
+ const lastSectionMax = lastSection.position + lastSection.size - this.#viewportSize
524
+ const lastSectionMargin = this.#scrollSize - lastSectionMax
525
+ this.#distance = lastSection.position + lastSection.size + lastSectionMargin
526
+ } else {
527
+ this.#distance = this.#scrollSize
528
+ }
529
+
530
+ if (this.#sectionalAttribute.current && this.#sections.length) {
531
+ const section = this.#sections[this.#counter.current]
532
+ this.#damped.set(section.position, true)
533
+ } else {
534
+ this.#damped.set(prevProgress * this.#scrollSize, true)
535
+ }
536
+ }
537
+
538
+ #animatedChangeListener = () => {
539
+ if (this.#sections.length) {
540
+ let counter = 0
541
+
542
+ for (let index = 0; index < this.#sections.length; index++) {
543
+ const section = this.#sections[index]
544
+
545
+ section.transform()
546
+
547
+ if (this.targetScrollValue >= section.position) {
548
+ counter = index
549
+ }
550
+ }
551
+
552
+ this.#counter.current = counter
553
+ } else {
554
+ if (this.vertical) {
555
+ this.#contentElement.style.transform = `translate3d(0px, ${
556
+ this.currentScrollValue * -1
557
+ }px, 0px)`
558
+ } else {
559
+ this.#contentElement.style.transform = `translate3d(${
560
+ this.currentScrollValue * -1
561
+ }px, 0px, 0px)`
562
+ }
563
+ }
564
+
565
+ scrollEnties.update(this, this.#axisAttribute.current, this.currentScrollValue)
566
+ }
567
+
568
+ #setCounter(value: number) {
569
+ if (this.#infiniteAttribute.current) {
570
+ this.#counter.current = value % this.#sections.length
571
+ this.#counter.current =
572
+ this.#counter.current < 0
573
+ ? this.#sections.length + this.#counter.current
574
+ : this.#counter.current
575
+ } else {
576
+ this.#counter.current = clamp(value, 0, this.#sections.length - 1)
577
+ }
578
+ }
579
+
580
+ #controlsListener = (value: ControlsValue) => {
581
+ if (typeof value === 'number') {
582
+ if (this.#sectionalAttribute.current) {
583
+ const direction = Math.sign(value)
584
+
585
+ if (this.#sections.length) {
586
+ this.shiftSections(direction)
587
+ } else {
588
+ this.#damped.shift(direction * this.#viewportSize)
589
+ }
590
+ } else {
591
+ this.#damped.shift(value)
592
+ }
593
+ } else if (value === 'min') {
594
+ this.#damped.set(this.#damped.min)
595
+ } else if (value === 'max') {
596
+ this.#damped.set(this.#damped.delta)
597
+ }
598
+ }
599
+
600
+ #getScrollValue(type: 'target' | 'current' = 'current') {
601
+ if (this.#infiniteAttribute.current && this.#sections.length) {
602
+ const mod = this.#damped[type] % (this.#scrollSize + this.#viewportSize)
603
+ const value = mod < 0 ? this.#scrollSize + mod + this.#viewportSize : mod
604
+
605
+ this.#overscroll = Math.max(0, value - this.#scrollSize)
606
+
607
+ return value
608
+ } else {
609
+ return this.#damped[type]
610
+ }
611
+ }
612
+ }
613
+
614
+ declare global {
615
+ interface HTMLElementTagNameMap {
616
+ 'e-scroll': ScrollElement
617
+ }
618
+ }
@@ -0,0 +1,21 @@
1
+ import { CustomElement } from '$packages/custom-element'
2
+ import { findParentElement } from '$packages/utils'
3
+ import { ScrollElement } from './ScrollElement'
4
+
5
+ export class ScrollUserElement extends CustomElement {
6
+ #scrollElement: ScrollElement = null!
7
+
8
+ public get scrollElement() {
9
+ return this.#scrollElement
10
+ }
11
+
12
+ protected connectedCallback() {
13
+ const scrollElement = findParentElement(this, ScrollElement)
14
+
15
+ if (scrollElement instanceof ScrollElement) {
16
+ this.#scrollElement = scrollElement
17
+ } else {
18
+ console.error(this, 'e-scroll not found')
19
+ }
20
+ }
21
+ }