@lisergia/core 24.0.0 → 25.0.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.
package/src/Page.ts DELETED
@@ -1,228 +0,0 @@
1
- import Lenis, { LenisOptions } from 'lenis'
2
- import { makeObservable, observable } from 'mobx'
3
- import GSAP from 'gsap'
4
- import ScrollTrigger from 'gsap/src/ScrollTrigger'
5
- import Tempus from 'tempus'
6
-
7
- import { ApplicationManager } from './App'
8
- import { Component, ComponentClasses, ComponentSelectors } from './Component'
9
-
10
- export interface PageParameters {
11
- application: ApplicationManager
12
- classes?: ComponentClasses
13
- datasets: Array<{ component: typeof Component; selector: string }>
14
- element?: HTMLElement | string
15
- elements?: ComponentSelectors
16
- scrollEnabled?: boolean
17
- scrollOptions?: LenisOptions
18
- }
19
-
20
- export class Page extends Component {
21
- declare element: HTMLElement
22
- declare elements: {
23
- wrapper: HTMLElement
24
- }
25
-
26
- declare application: ApplicationManager
27
-
28
- datasets: Array<{
29
- component: typeof Component
30
- selector: string
31
- }> = []
32
-
33
- scroll: number = 0
34
- scrollEnabled: boolean = true
35
- scrollOptions: LenisOptions = {}
36
-
37
- declare unsubscribeRaf: (() => void) | undefined
38
-
39
- constructor({
40
- application,
41
- classes,
42
- datasets,
43
- element,
44
- elements,
45
- scrollEnabled = true,
46
- scrollOptions = {},
47
- }: PageParameters) {
48
- super({
49
- autoMount: false,
50
- autoListeners: false,
51
- classes,
52
- element,
53
- elements,
54
- })
55
-
56
- this.application = application
57
- this.datasets = datasets
58
-
59
- this.scrollEnabled = scrollEnabled
60
- this.scrollOptions = scrollOptions
61
-
62
- makeObservable(this, {
63
- element: observable,
64
- elements: observable,
65
- components: observable,
66
- scroll: observable,
67
- })
68
- }
69
-
70
- create() {
71
- super.create()
72
-
73
- this.createResizeObserver()
74
- this.createComponents()
75
- this.createScroll()
76
-
77
- this.addEventListeners()
78
- }
79
-
80
- //
81
- // Observer.
82
- //
83
- declare resizeObserver: ResizeObserver
84
-
85
- createResizeObserver() {
86
- this.resizeObserver = new ResizeObserver(() => {
87
- this.onResize()
88
- })
89
-
90
- this.resizeObserver.observe(this.elements.wrapper)
91
- }
92
-
93
- destroyResizeObserver() {
94
- this.resizeObserver.disconnect()
95
- }
96
-
97
- //
98
- // Components.
99
- //
100
- components: Set<Component> = new Set()
101
-
102
- createComponents() {
103
- this.datasets.map(({ component: Component, selector }) => {
104
- const elements = this.element.querySelectorAll(selector)
105
-
106
- const components = Array.from(elements).map((element) => {
107
- const component = new Component({
108
- application: this.application,
109
- element: element as HTMLElement,
110
- })
111
-
112
- return component
113
- })
114
-
115
- components.forEach((component) => {
116
- this.application.addComponent(component)
117
-
118
- this.components.add(component)
119
- })
120
- })
121
- }
122
-
123
- destroyComponents() {
124
- this.components.forEach((component) => {
125
- this.application.removeComponent(component)
126
- })
127
-
128
- this.components.clear()
129
- }
130
-
131
- //
132
- // Scroll.
133
- //
134
- declare lenis: Lenis
135
-
136
- createScroll() {
137
- if (!this.scrollEnabled) {
138
- this.element.addEventListener('scroll', this.onScrollFallback)
139
-
140
- return
141
- }
142
-
143
- this.lenis = new Lenis({
144
- content: this.elements.wrapper as HTMLElement,
145
- wrapper: this.element,
146
- ...this.scrollOptions,
147
- })
148
-
149
- GSAP.ticker.add(this.onGSAPTicker)
150
- GSAP.ticker.lagSmoothing(0)
151
-
152
- this.lenis.on('scroll', this.onLenisScroll)
153
- }
154
-
155
- onGSAPTicker(time: number) {
156
- this.lenis.raf(time * 1000)
157
- }
158
-
159
- onLenisScroll(event: { scroll: number }) {
160
- ScrollTrigger.update()
161
-
162
- this.onScroll(event.scroll)
163
-
164
- this.emitter.emit('scroll', event)
165
- }
166
-
167
- destroyScroll() {
168
- if (!this.scrollEnabled) {
169
- this.element.removeEventListener('scroll', this.onScrollFallback)
170
-
171
- return
172
- }
173
-
174
- GSAP.ticker.remove(this.onGSAPTicker)
175
-
176
- this.lenis.off('scroll', this.onLenisScroll)
177
- this.lenis?.destroy()
178
- this.lenis = undefined!
179
- }
180
-
181
- //
182
- // Events.
183
- //
184
- onResize() {
185
- this.lenis?.resize()
186
- }
187
-
188
- onRAF(time: number) {
189
- this.lenis?.raf(time)
190
- }
191
-
192
- onScroll(scroll: number) {
193
- this.scroll = scroll
194
- }
195
-
196
- onScrollFallback() {
197
- this.scroll = this.element.scrollTop
198
-
199
- this.emitter.emit('scroll', { scroll: this.scroll })
200
- }
201
-
202
- //
203
- // Events.
204
- //
205
- addEventListeners() {
206
- super.addEventListeners()
207
-
208
- this.unsubscribeRaf = Tempus.add(this.onRAF)
209
- }
210
-
211
- removeEventListeners() {
212
- super.removeEventListeners()
213
-
214
- this.unsubscribeRaf?.()
215
- this.unsubscribeRaf = undefined
216
- }
217
-
218
- //
219
- // Destroy.
220
- //
221
- destroy() {
222
- this.destroyResizeObserver()
223
- this.destroyComponents()
224
- this.destroyScroll()
225
-
226
- super.destroy()
227
- }
228
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- export * from './App'
2
- export * from './Link'
3
- export * from './Links'
4
- export * from './Component'
5
- export * from './EventEmitter'
6
- export * from './Page'
7
-
8
- import Tempus from 'tempus'
9
-
10
- export { Tempus }
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "@lisergia/config-tsconfig/base.json"
3
- }