@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/dist/App.d.ts +66 -0
- package/dist/App.js +251 -0
- package/dist/Component.d.ts +44 -0
- package/dist/Component.js +108 -0
- package/dist/EventEmitter.d.ts +10 -0
- package/dist/EventEmitter.js +34 -0
- package/dist/Link.d.ts +11 -0
- package/dist/Link.js +57 -0
- package/dist/Links.d.ts +11 -0
- package/dist/Links.js +30 -0
- package/dist/Page.d.ts +52 -0
- package/dist/Page.js +133 -0
- package/dist/index.d.ts +8 -187
- package/dist/index.js +8 -599
- package/package.json +11 -10
- package/.turbo/turbo-build.log +0 -20
- package/CHANGELOG.md +0 -265
- package/dist/index.cjs +0 -643
- package/dist/index.d.cts +0 -187
- package/dist/index.d.mts +0 -178
- package/dist/index.mjs +0 -563
- package/src/App.ts +0 -308
- package/src/Component.ts +0 -144
- package/src/EventEmitter.ts +0 -44
- package/src/Link.ts +0 -51
- package/src/Links.ts +0 -46
- package/src/Page.ts +0 -228
- package/src/index.ts +0 -10
- package/tsconfig.json +0 -3
package/dist/Page.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Lenis from 'lenis';
|
|
2
|
+
import { makeObservable, observable } from 'mobx';
|
|
3
|
+
import Tempus from 'tempus';
|
|
4
|
+
import { Component } from './Component.js';
|
|
5
|
+
export class Page extends Component {
|
|
6
|
+
datasets = [];
|
|
7
|
+
scroll = 0;
|
|
8
|
+
scrollEnabled = true;
|
|
9
|
+
scrollOptions = {};
|
|
10
|
+
constructor({ application, classes, datasets, element, elements, scrollEnabled = true, scrollOptions = {}, }) {
|
|
11
|
+
super({
|
|
12
|
+
autoMount: false,
|
|
13
|
+
autoListeners: false,
|
|
14
|
+
classes,
|
|
15
|
+
element,
|
|
16
|
+
elements,
|
|
17
|
+
});
|
|
18
|
+
this.application = application;
|
|
19
|
+
this.datasets = datasets;
|
|
20
|
+
this.scrollEnabled = scrollEnabled;
|
|
21
|
+
this.scrollOptions = scrollOptions;
|
|
22
|
+
makeObservable(this, {
|
|
23
|
+
element: observable,
|
|
24
|
+
elements: observable,
|
|
25
|
+
components: observable,
|
|
26
|
+
scroll: observable,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
create() {
|
|
30
|
+
super.create();
|
|
31
|
+
this.createResizeObserver();
|
|
32
|
+
this.createComponents();
|
|
33
|
+
this.createScroll();
|
|
34
|
+
this.addEventListeners();
|
|
35
|
+
}
|
|
36
|
+
createResizeObserver() {
|
|
37
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
38
|
+
this.onResize();
|
|
39
|
+
});
|
|
40
|
+
this.resizeObserver.observe(this.elements.wrapper);
|
|
41
|
+
}
|
|
42
|
+
destroyResizeObserver() {
|
|
43
|
+
this.resizeObserver.disconnect();
|
|
44
|
+
}
|
|
45
|
+
//
|
|
46
|
+
// Components.
|
|
47
|
+
//
|
|
48
|
+
components = new Set();
|
|
49
|
+
createComponents() {
|
|
50
|
+
this.datasets.forEach(({ component: Component, selector }) => {
|
|
51
|
+
const elements = this.element.querySelectorAll(selector);
|
|
52
|
+
const components = Array.from(elements).map((element) => {
|
|
53
|
+
const component = new Component({
|
|
54
|
+
application: this.application,
|
|
55
|
+
element: element,
|
|
56
|
+
});
|
|
57
|
+
return component;
|
|
58
|
+
});
|
|
59
|
+
components.forEach((component) => {
|
|
60
|
+
this.application.addComponent(component);
|
|
61
|
+
this.components.add(component);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
destroyComponents() {
|
|
66
|
+
this.components.forEach((component) => {
|
|
67
|
+
this.application.removeComponent(component);
|
|
68
|
+
});
|
|
69
|
+
this.components.clear();
|
|
70
|
+
}
|
|
71
|
+
createScroll() {
|
|
72
|
+
if (!this.scrollEnabled) {
|
|
73
|
+
this.element.addEventListener('scroll', this.onScrollFallback);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.lenis = new Lenis({
|
|
77
|
+
content: this.elements.wrapper,
|
|
78
|
+
wrapper: this.element,
|
|
79
|
+
...this.scrollOptions,
|
|
80
|
+
});
|
|
81
|
+
this.lenis.on('scroll', this.onLenisScroll);
|
|
82
|
+
}
|
|
83
|
+
onLenisScroll(event) {
|
|
84
|
+
this.onScroll(event.scroll);
|
|
85
|
+
this.emitter.emit('scroll', event);
|
|
86
|
+
}
|
|
87
|
+
destroyScroll() {
|
|
88
|
+
if (!this.scrollEnabled) {
|
|
89
|
+
this.element.removeEventListener('scroll', this.onScrollFallback);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.lenis.off('scroll', this.onLenisScroll);
|
|
93
|
+
this.lenis?.destroy();
|
|
94
|
+
this.lenis = undefined;
|
|
95
|
+
}
|
|
96
|
+
//
|
|
97
|
+
// Events.
|
|
98
|
+
//
|
|
99
|
+
onResize() {
|
|
100
|
+
this.lenis?.resize();
|
|
101
|
+
}
|
|
102
|
+
onRAF({ time }) {
|
|
103
|
+
this.lenis?.raf(time);
|
|
104
|
+
}
|
|
105
|
+
onScroll(scroll) {
|
|
106
|
+
this.scroll = scroll;
|
|
107
|
+
}
|
|
108
|
+
onScrollFallback() {
|
|
109
|
+
this.scroll = this.element.scrollTop;
|
|
110
|
+
this.emitter.emit('scroll', { scroll: this.scroll });
|
|
111
|
+
}
|
|
112
|
+
//
|
|
113
|
+
// Events.
|
|
114
|
+
//
|
|
115
|
+
addEventListeners() {
|
|
116
|
+
super.addEventListeners();
|
|
117
|
+
this.unsubscribeRaf = Tempus.add(this.onRAF);
|
|
118
|
+
}
|
|
119
|
+
removeEventListeners() {
|
|
120
|
+
super.removeEventListeners();
|
|
121
|
+
this.unsubscribeRaf?.();
|
|
122
|
+
this.unsubscribeRaf = undefined;
|
|
123
|
+
}
|
|
124
|
+
//
|
|
125
|
+
// Destroy.
|
|
126
|
+
//
|
|
127
|
+
destroy() {
|
|
128
|
+
this.destroyResizeObserver();
|
|
129
|
+
this.destroyComponents();
|
|
130
|
+
this.destroyScroll();
|
|
131
|
+
super.destroy();
|
|
132
|
+
}
|
|
133
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,187 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor();
|
|
10
|
-
on(event: string, callback: (...args: any) => void): void | Unsubscribe;
|
|
11
|
-
off(event: string, callback: (...args: any) => void): void;
|
|
12
|
-
fire(event: string, ...args: any[]): void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface ComponentClasses {
|
|
17
|
-
[key: string]: string;
|
|
18
|
-
}
|
|
19
|
-
interface ComponentElements {
|
|
20
|
-
[key: string]: Array<any> | Element | Array<Element> | HTMLElement | Array<HTMLElement> | NodeList | Window | null;
|
|
21
|
-
}
|
|
22
|
-
type ComponentSelector = string | HTMLElement;
|
|
23
|
-
interface ComponentSelectors {
|
|
24
|
-
[key: string]: string | Element | Array<Element> | HTMLElement | Array<HTMLElement> | NodeList | Window;
|
|
25
|
-
}
|
|
26
|
-
interface ComponentParameters {
|
|
27
|
-
application?: ApplicationManager;
|
|
28
|
-
autoListeners?: boolean;
|
|
29
|
-
autoMount?: boolean;
|
|
30
|
-
classes?: ComponentClasses;
|
|
31
|
-
element?: ComponentSelector;
|
|
32
|
-
elements?: ComponentSelectors;
|
|
33
|
-
id?: string;
|
|
34
|
-
}
|
|
35
|
-
declare class Component extends EventEmitter {
|
|
36
|
-
application?: ApplicationManager;
|
|
37
|
-
autoListeners: boolean;
|
|
38
|
-
autoMount: boolean;
|
|
39
|
-
classes?: ComponentClasses;
|
|
40
|
-
selector?: ComponentSelector;
|
|
41
|
-
selectors?: ComponentSelectors;
|
|
42
|
-
id?: string;
|
|
43
|
-
element?: HTMLElement;
|
|
44
|
-
elements: ComponentElements;
|
|
45
|
-
constructor({ application, autoListeners, autoMount, classes, element, elements, id, }: ComponentParameters);
|
|
46
|
-
create(): void;
|
|
47
|
-
initElement(selector: ComponentSelector): void;
|
|
48
|
-
destroyElement(): void;
|
|
49
|
-
initElements(selectors?: ComponentSelectors): void;
|
|
50
|
-
destroyElements(): void;
|
|
51
|
-
addEventListeners(): void;
|
|
52
|
-
removeEventListeners(): void;
|
|
53
|
-
destroy(): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare class Link extends Component {
|
|
57
|
-
element: HTMLLinkElement;
|
|
58
|
-
constructor({ element }: {
|
|
59
|
-
element: HTMLAnchorElement;
|
|
60
|
-
});
|
|
61
|
-
onClick(event: MouseEvent): void;
|
|
62
|
-
addEventListeners(): void;
|
|
63
|
-
removeEventListeners(): void;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare class Links extends EventEmitter {
|
|
67
|
-
application: ApplicationManager;
|
|
68
|
-
links: Array<Link>;
|
|
69
|
-
constructor(application: ApplicationManager);
|
|
70
|
-
addEventListeners(): void;
|
|
71
|
-
onLinkClick(href: string): void;
|
|
72
|
-
refresh(): void;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface PageParameters {
|
|
76
|
-
application: ApplicationManager;
|
|
77
|
-
classes?: ComponentClasses;
|
|
78
|
-
datasets: Array<{
|
|
79
|
-
component: typeof Component;
|
|
80
|
-
selector: string;
|
|
81
|
-
}>;
|
|
82
|
-
element?: HTMLElement | string;
|
|
83
|
-
elements?: ComponentSelectors;
|
|
84
|
-
scrollEnabled?: boolean;
|
|
85
|
-
scrollOptions?: LenisOptions;
|
|
86
|
-
}
|
|
87
|
-
declare class Page extends Component {
|
|
88
|
-
element: HTMLElement;
|
|
89
|
-
elements: {
|
|
90
|
-
wrapper: HTMLElement;
|
|
91
|
-
};
|
|
92
|
-
application: ApplicationManager;
|
|
93
|
-
datasets: Array<{
|
|
94
|
-
component: typeof Component;
|
|
95
|
-
selector: string;
|
|
96
|
-
}>;
|
|
97
|
-
scroll: number;
|
|
98
|
-
scrollEnabled: boolean;
|
|
99
|
-
scrollOptions: LenisOptions;
|
|
100
|
-
unsubscribeRaf: (() => void) | undefined;
|
|
101
|
-
constructor({ application, classes, datasets, element, elements, scrollEnabled, scrollOptions, }: PageParameters);
|
|
102
|
-
create(): void;
|
|
103
|
-
resizeObserver: ResizeObserver;
|
|
104
|
-
createResizeObserver(): void;
|
|
105
|
-
destroyResizeObserver(): void;
|
|
106
|
-
components: Set<Component>;
|
|
107
|
-
createComponents(): void;
|
|
108
|
-
destroyComponents(): void;
|
|
109
|
-
lenis: Lenis;
|
|
110
|
-
createScroll(): void;
|
|
111
|
-
onGSAPTicker(time: number): void;
|
|
112
|
-
onLenisScroll(event: {
|
|
113
|
-
scroll: number;
|
|
114
|
-
}): void;
|
|
115
|
-
destroyScroll(): void;
|
|
116
|
-
onResize(): void;
|
|
117
|
-
onRAF(time: number): void;
|
|
118
|
-
onScroll(scroll: number): void;
|
|
119
|
-
onScrollFallback(): void;
|
|
120
|
-
addEventListeners(): void;
|
|
121
|
-
removeEventListeners(): void;
|
|
122
|
-
destroy(): void;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
interface ApplicationComponentData {
|
|
126
|
-
component: new (params?: ComponentParameters) => Component;
|
|
127
|
-
}
|
|
128
|
-
interface ApplicationComponentDatasetData extends ApplicationComponentData {
|
|
129
|
-
selector: string;
|
|
130
|
-
}
|
|
131
|
-
interface ApplicationRoute {
|
|
132
|
-
component: new (params?: PageParameters) => Page;
|
|
133
|
-
template: string;
|
|
134
|
-
}
|
|
135
|
-
declare class ApplicationManager extends Component {
|
|
136
|
-
element: HTMLElement;
|
|
137
|
-
template: string;
|
|
138
|
-
constructor();
|
|
139
|
-
onTitleUpdate(): void;
|
|
140
|
-
onTemplateUpdate(): void;
|
|
141
|
-
canvas?: Component;
|
|
142
|
-
components: Array<Component>;
|
|
143
|
-
transition?: Component & {
|
|
144
|
-
onTransition?: (args: any) => Promise<void>;
|
|
145
|
-
};
|
|
146
|
-
initComponents(components: Array<ApplicationComponentData>): void;
|
|
147
|
-
addComponent(component: Component): void;
|
|
148
|
-
removeComponent(component: Component): void;
|
|
149
|
-
onComponentChange(event: IArrayDidChange<Component>): void;
|
|
150
|
-
datasets: Array<ApplicationComponentDatasetData>;
|
|
151
|
-
initDatasets(datasets: Array<ApplicationComponentDatasetData>): void;
|
|
152
|
-
pages: Map<string, new (args: PageParameters) => Page>;
|
|
153
|
-
initRoutes(routes: Array<ApplicationRoute>): void;
|
|
154
|
-
initSprites(url?: string): Promise<void>;
|
|
155
|
-
IS_LINKS_ENABLED: boolean;
|
|
156
|
-
links: Links;
|
|
157
|
-
initPage(): void;
|
|
158
|
-
createLinks(): void;
|
|
159
|
-
currentPage?: Page;
|
|
160
|
-
createPage(template?: string): void;
|
|
161
|
-
destroyPage(): void;
|
|
162
|
-
route: string;
|
|
163
|
-
routeHistory: Array<string>;
|
|
164
|
-
routePushState: boolean;
|
|
165
|
-
onRouteChange({ oldValue, newValue }: IValueDidChange<string>): void;
|
|
166
|
-
onRouteChangeRequest({ href, pushState }: {
|
|
167
|
-
href: string;
|
|
168
|
-
pushState: boolean;
|
|
169
|
-
}): Promise<void>;
|
|
170
|
-
nextPage: {
|
|
171
|
-
element?: Element;
|
|
172
|
-
template?: string;
|
|
173
|
-
title?: string;
|
|
174
|
-
};
|
|
175
|
-
onRequest({ href, response, pushState }: {
|
|
176
|
-
href: string;
|
|
177
|
-
response: string;
|
|
178
|
-
pushState: boolean;
|
|
179
|
-
}): Promise<void>;
|
|
180
|
-
onPopState(event: PopStateEvent): void;
|
|
181
|
-
get scroll(): number;
|
|
182
|
-
addEventListeners(): void;
|
|
183
|
-
removeEventListeners(): void;
|
|
184
|
-
}
|
|
185
|
-
declare const Application: ApplicationManager;
|
|
186
|
-
|
|
187
|
-
export { Application, type ApplicationComponentData, type ApplicationComponentDatasetData, ApplicationManager, type ApplicationRoute, Component, type ComponentClasses, type ComponentElements, type ComponentParameters, type ComponentSelector, type ComponentSelectors, EventEmitter, Link, Links, Page, type PageParameters };
|
|
1
|
+
export * from './App.js';
|
|
2
|
+
export * from './Component.js';
|
|
3
|
+
export * from './EventEmitter.js';
|
|
4
|
+
export * from './Link.js';
|
|
5
|
+
export * from './Links.js';
|
|
6
|
+
export * from './Page.js';
|
|
7
|
+
import Tempus from 'tempus';
|
|
8
|
+
export { Tempus };
|