@lisergia/core 0.0.0 → 2.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/.turbo/turbo-build.log +20 -0
- package/CHANGELOG.md +20 -0
- package/dist/index.cjs +596 -0
- package/dist/index.d.cts +178 -0
- package/dist/index.d.mts +178 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.js +596 -0
- package/dist/index.mjs +552 -0
- package/package.json +10 -8
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @lisergia/core@1.0.0 build
|
|
4
|
+
> tsup src/index.ts --format cjs,esm --dts
|
|
5
|
+
|
|
6
|
+
[1G[0K[34mCLI[39m Building entry: src/index.ts
|
|
7
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
+
[34mCLI[39m tsup v8.5.0
|
|
9
|
+
[34mCLI[39m Target: esnext
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m15.04 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 39ms
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.93 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 39ms
|
|
16
|
+
DTS Build start
|
|
17
|
+
DTS ⚡️ Build success in 1055ms
|
|
18
|
+
DTS dist/index.d.ts 5.74 KB
|
|
19
|
+
DTS dist/index.d.mts 5.74 KB
|
|
20
|
+
[1G[0K⠙[1G[0K
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @lisergia/core
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Update build and serving of npm packages.
|
|
8
|
+
- Updating build and serving of npm packages.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @lisergia/config-tsconfig@2.0.0
|
|
15
|
+
|
|
16
|
+
## 1.0.0
|
|
17
|
+
|
|
18
|
+
### Major Changes
|
|
19
|
+
|
|
20
|
+
- 9c70654: Initial release of Lisergia packages.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Application: () => Application,
|
|
34
|
+
ApplicationManager: () => ApplicationManager,
|
|
35
|
+
Component: () => Component,
|
|
36
|
+
EventEmitter: () => EventEmitter,
|
|
37
|
+
Link: () => Link,
|
|
38
|
+
Links: () => Links,
|
|
39
|
+
Page: () => Page,
|
|
40
|
+
Tempus: () => import_tempus2.default
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/App.ts
|
|
45
|
+
var import_mobx2 = require("mobx");
|
|
46
|
+
|
|
47
|
+
// src/EventEmitter.ts
|
|
48
|
+
var import_auto_bind = __toESM(require("auto-bind"), 1);
|
|
49
|
+
var import_nanoevents = require("nanoevents");
|
|
50
|
+
var EventEmitter = class {
|
|
51
|
+
emitter;
|
|
52
|
+
entries = /* @__PURE__ */ new Map();
|
|
53
|
+
constructor() {
|
|
54
|
+
(0, import_auto_bind.default)(this);
|
|
55
|
+
this.emitter = (0, import_nanoevents.createNanoEvents)();
|
|
56
|
+
}
|
|
57
|
+
on(event, callback) {
|
|
58
|
+
if (!callback) {
|
|
59
|
+
return console.trace("No callback provided");
|
|
60
|
+
}
|
|
61
|
+
const emitter = this.emitter.on(event, callback);
|
|
62
|
+
this.entries.set(callback, emitter);
|
|
63
|
+
return emitter;
|
|
64
|
+
}
|
|
65
|
+
off(event, callback) {
|
|
66
|
+
const unsubscribe = this.entries.get(callback);
|
|
67
|
+
if (unsubscribe) {
|
|
68
|
+
unsubscribe();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
fire(event, ...args) {
|
|
72
|
+
this.emitter.emit(event, ...args);
|
|
73
|
+
}
|
|
74
|
+
destroy() {
|
|
75
|
+
this.entries.forEach((unsubscribe) => unsubscribe());
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/Component.ts
|
|
80
|
+
var Component = class extends EventEmitter {
|
|
81
|
+
application;
|
|
82
|
+
autoListeners;
|
|
83
|
+
autoMount;
|
|
84
|
+
classes;
|
|
85
|
+
selector;
|
|
86
|
+
selectors;
|
|
87
|
+
id;
|
|
88
|
+
element;
|
|
89
|
+
elements = {};
|
|
90
|
+
constructor({
|
|
91
|
+
application,
|
|
92
|
+
autoListeners = true,
|
|
93
|
+
autoMount = true,
|
|
94
|
+
classes,
|
|
95
|
+
element,
|
|
96
|
+
elements,
|
|
97
|
+
id
|
|
98
|
+
}) {
|
|
99
|
+
super();
|
|
100
|
+
this.application = application;
|
|
101
|
+
this.autoListeners = autoListeners;
|
|
102
|
+
this.autoMount = autoMount;
|
|
103
|
+
this.classes = classes;
|
|
104
|
+
this.selector = element;
|
|
105
|
+
this.selectors = elements;
|
|
106
|
+
this.id = id;
|
|
107
|
+
if (this.autoMount) {
|
|
108
|
+
this.create();
|
|
109
|
+
}
|
|
110
|
+
if (this.autoListeners) {
|
|
111
|
+
this.addEventListeners();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
create() {
|
|
115
|
+
if (this.selector) {
|
|
116
|
+
this.initElement(this.selector);
|
|
117
|
+
}
|
|
118
|
+
if (this.selectors) {
|
|
119
|
+
this.initElements(this.selectors);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
initElement(selector) {
|
|
123
|
+
if (selector instanceof HTMLElement) {
|
|
124
|
+
this.element = selector;
|
|
125
|
+
} else {
|
|
126
|
+
this.element = document.querySelector(selector);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
initElements(selectors) {
|
|
130
|
+
for (const key in selectors) {
|
|
131
|
+
const selector = selectors[key];
|
|
132
|
+
if (selector === window) {
|
|
133
|
+
this.elements[key] = window;
|
|
134
|
+
} else if (selector instanceof HTMLElement) {
|
|
135
|
+
this.elements[key] = selector;
|
|
136
|
+
} else if (selector instanceof NodeList) {
|
|
137
|
+
this.elements[key] = selector;
|
|
138
|
+
} else if (Array.isArray(selector)) {
|
|
139
|
+
this.elements[key] = selector;
|
|
140
|
+
} else {
|
|
141
|
+
const elements = this.element.querySelectorAll(selector);
|
|
142
|
+
if (elements.length === 0) {
|
|
143
|
+
const elements2 = document.querySelectorAll(selector);
|
|
144
|
+
if (elements2.length === 0) {
|
|
145
|
+
this.elements[key] = null;
|
|
146
|
+
} else if (elements2.length === 1) {
|
|
147
|
+
this.elements[key] = elements2[0];
|
|
148
|
+
} else {
|
|
149
|
+
this.elements[key] = elements2;
|
|
150
|
+
}
|
|
151
|
+
} else if (elements.length === 1) {
|
|
152
|
+
this.elements[key] = elements[0];
|
|
153
|
+
} else {
|
|
154
|
+
this.elements[key] = elements;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
addEventListeners() {
|
|
160
|
+
}
|
|
161
|
+
removeEventListeners() {
|
|
162
|
+
}
|
|
163
|
+
destroy() {
|
|
164
|
+
super.destroy();
|
|
165
|
+
this.removeEventListeners();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/Links.ts
|
|
170
|
+
var import_mobx = require("mobx");
|
|
171
|
+
|
|
172
|
+
// src/Link.ts
|
|
173
|
+
var Link = class extends Component {
|
|
174
|
+
constructor({ element }) {
|
|
175
|
+
super({ element });
|
|
176
|
+
}
|
|
177
|
+
onClick(event) {
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
this.fire("click", this.element.href);
|
|
180
|
+
}
|
|
181
|
+
addEventListeners() {
|
|
182
|
+
const isLocal = this.element.href.includes(window.location.origin);
|
|
183
|
+
const isLocalPrevented = this.element.dataset.linkOverride === "";
|
|
184
|
+
const isNotEmail = !this.element.href.startsWith("mailto");
|
|
185
|
+
const isNotPhone = !this.element.href.startsWith("tel");
|
|
186
|
+
const isDownload = this.element.hasAttribute("download");
|
|
187
|
+
const isAnchor = this.element.href.includes("#");
|
|
188
|
+
if (isAnchor) {
|
|
189
|
+
const hash = this.element.href.split("#")[1];
|
|
190
|
+
const element = document.querySelector(`#${hash}`);
|
|
191
|
+
if (element) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (isLocalPrevented || isDownload) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (isLocal) {
|
|
199
|
+
this.element.onclick = this.onClick;
|
|
200
|
+
} else if (isNotEmail && isNotPhone) {
|
|
201
|
+
this.element.rel = "noopener";
|
|
202
|
+
this.element.setAttribute("target", "_blank");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
removeEventListeners() {
|
|
206
|
+
this.element.onclick = null;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// src/Links.ts
|
|
211
|
+
var Links = class extends EventEmitter {
|
|
212
|
+
constructor(application) {
|
|
213
|
+
super();
|
|
214
|
+
this.application = application;
|
|
215
|
+
(0, import_mobx.reaction)(
|
|
216
|
+
() => application.currentPage,
|
|
217
|
+
() => this.refresh(),
|
|
218
|
+
{ fireImmediately: true }
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
addEventListeners() {
|
|
222
|
+
this.links?.forEach((link) => link.destroy());
|
|
223
|
+
const links = document.querySelectorAll("a");
|
|
224
|
+
this.links = Array.from(links).map((element) => {
|
|
225
|
+
const link = new Link({
|
|
226
|
+
element
|
|
227
|
+
});
|
|
228
|
+
link.on("click", this.onLinkClick);
|
|
229
|
+
return link;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
onLinkClick(href) {
|
|
233
|
+
this.application.route = href;
|
|
234
|
+
}
|
|
235
|
+
refresh() {
|
|
236
|
+
this.addEventListeners();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/App.ts
|
|
241
|
+
var ApplicationManager = class extends Component {
|
|
242
|
+
template = document.documentElement.dataset.template ?? "404";
|
|
243
|
+
constructor() {
|
|
244
|
+
super({
|
|
245
|
+
autoListeners: false,
|
|
246
|
+
element: ".app"
|
|
247
|
+
});
|
|
248
|
+
(0, import_mobx2.makeObservable)(this, {
|
|
249
|
+
// Application DOM Element.
|
|
250
|
+
element: import_mobx2.observable,
|
|
251
|
+
// Components.
|
|
252
|
+
canvas: import_mobx2.observable,
|
|
253
|
+
components: import_mobx2.observable,
|
|
254
|
+
transition: import_mobx2.observable,
|
|
255
|
+
// Page Information.
|
|
256
|
+
currentPage: import_mobx2.observable,
|
|
257
|
+
nextPage: import_mobx2.observable,
|
|
258
|
+
// Route Information.
|
|
259
|
+
route: import_mobx2.observable,
|
|
260
|
+
// Template Information.
|
|
261
|
+
template: import_mobx2.observable,
|
|
262
|
+
// Page Scroll.
|
|
263
|
+
scroll: import_mobx2.computed
|
|
264
|
+
});
|
|
265
|
+
(0, import_mobx2.observe)(this.components, this.onComponentChange);
|
|
266
|
+
(0, import_mobx2.observe)(this, "route", this.onRouteChange);
|
|
267
|
+
(0, import_mobx2.autorun)(this.onTitleUpdate);
|
|
268
|
+
(0, import_mobx2.autorun)(this.onTemplateUpdate);
|
|
269
|
+
this.addEventListeners();
|
|
270
|
+
}
|
|
271
|
+
onTitleUpdate() {
|
|
272
|
+
const title = this.nextPage?.title;
|
|
273
|
+
if (title) {
|
|
274
|
+
document.title = title;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
onTemplateUpdate() {
|
|
278
|
+
const template = this.nextPage?.template;
|
|
279
|
+
if (template) {
|
|
280
|
+
document.documentElement.dataset.template = template;
|
|
281
|
+
this.template = template;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//
|
|
285
|
+
// Components.
|
|
286
|
+
//
|
|
287
|
+
canvas;
|
|
288
|
+
components = [];
|
|
289
|
+
transition;
|
|
290
|
+
initComponents(components) {
|
|
291
|
+
const classes = components.map(
|
|
292
|
+
({ component: Component2 }) => new Component2({
|
|
293
|
+
application: this
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
this.canvas = classes.find((component) => component.id === "canvas");
|
|
297
|
+
this.transition = classes.find((component) => component.id === "transition");
|
|
298
|
+
classes.forEach((component) => {
|
|
299
|
+
this.addComponent(component);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
addComponent(component) {
|
|
303
|
+
this.components.push(component);
|
|
304
|
+
}
|
|
305
|
+
removeComponent(component) {
|
|
306
|
+
component.destroy();
|
|
307
|
+
const index = this.components.indexOf(component);
|
|
308
|
+
if (index !== -1) {
|
|
309
|
+
this.components.splice(index, 1);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
onComponentChange(event) {
|
|
313
|
+
if (event.type === "splice") {
|
|
314
|
+
const { added, removed } = event;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
//
|
|
318
|
+
// Datasets.
|
|
319
|
+
//
|
|
320
|
+
datasets = [];
|
|
321
|
+
initDatasets(datasets) {
|
|
322
|
+
this.datasets = datasets;
|
|
323
|
+
}
|
|
324
|
+
//
|
|
325
|
+
// Routes.
|
|
326
|
+
//
|
|
327
|
+
pages = /* @__PURE__ */ new Map();
|
|
328
|
+
initRoutes(routes) {
|
|
329
|
+
routes.forEach(({ component, template }) => {
|
|
330
|
+
this.pages.set(template, component);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
//
|
|
334
|
+
// Sprites.
|
|
335
|
+
//
|
|
336
|
+
async initSprites(url = "/bundle.svg") {
|
|
337
|
+
const request = await window.fetch(url);
|
|
338
|
+
const response = await request.text();
|
|
339
|
+
const sprite = document.createElement("div");
|
|
340
|
+
sprite.innerHTML = response;
|
|
341
|
+
sprite.style.left = "-999999px";
|
|
342
|
+
sprite.style.opacity = "0";
|
|
343
|
+
sprite.style.position = "absolute";
|
|
344
|
+
sprite.style.top = "0";
|
|
345
|
+
document.body.appendChild(sprite);
|
|
346
|
+
}
|
|
347
|
+
initPage() {
|
|
348
|
+
this.createPage();
|
|
349
|
+
this.createLinks();
|
|
350
|
+
}
|
|
351
|
+
//
|
|
352
|
+
// Links.
|
|
353
|
+
//
|
|
354
|
+
createLinks() {
|
|
355
|
+
this.links = new Links(this);
|
|
356
|
+
}
|
|
357
|
+
//
|
|
358
|
+
// Page.
|
|
359
|
+
//
|
|
360
|
+
currentPage = void 0;
|
|
361
|
+
createPage(template = this.template) {
|
|
362
|
+
const PageClass = this.pages.get(template);
|
|
363
|
+
const page = new PageClass({
|
|
364
|
+
application: this,
|
|
365
|
+
datasets: this.datasets
|
|
366
|
+
});
|
|
367
|
+
this.currentPage = page;
|
|
368
|
+
this.currentPage.create();
|
|
369
|
+
}
|
|
370
|
+
destroyPage() {
|
|
371
|
+
if (this.currentPage) {
|
|
372
|
+
this.currentPage.destroy();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//
|
|
376
|
+
// Navigate.
|
|
377
|
+
//
|
|
378
|
+
route = window.location.pathname;
|
|
379
|
+
onRouteChange({ oldValue, newValue }) {
|
|
380
|
+
this.onRouteChangeRequest({
|
|
381
|
+
href: newValue,
|
|
382
|
+
pushState: true
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
async onRouteChangeRequest({ href, pushState = true }) {
|
|
386
|
+
const request = await window.fetch(href);
|
|
387
|
+
const response = await request.text();
|
|
388
|
+
this.onRequest({
|
|
389
|
+
href,
|
|
390
|
+
response,
|
|
391
|
+
pushState
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
//
|
|
395
|
+
// Request.
|
|
396
|
+
//
|
|
397
|
+
nextPage = {};
|
|
398
|
+
async onRequest({ href, response, pushState }) {
|
|
399
|
+
const domParser = new DOMParser();
|
|
400
|
+
const dom = domParser.parseFromString(response, "text/html");
|
|
401
|
+
const html = dom.querySelector("html");
|
|
402
|
+
const app = dom.querySelector(".app");
|
|
403
|
+
this.nextPage = {
|
|
404
|
+
element: app,
|
|
405
|
+
template: html.dataset.template ?? this.template,
|
|
406
|
+
title: dom.title ?? document.title
|
|
407
|
+
};
|
|
408
|
+
if (this.transition) {
|
|
409
|
+
await this.transition.onTransition?.(this);
|
|
410
|
+
} else {
|
|
411
|
+
this.currentPage.element.remove();
|
|
412
|
+
this.currentPage.destroy();
|
|
413
|
+
this.element.appendChild(this.nextPage.element.firstElementChild);
|
|
414
|
+
this.createPage(this.nextPage.template);
|
|
415
|
+
}
|
|
416
|
+
if (pushState) {
|
|
417
|
+
window.history.pushState({}, this.nextPage.title, href);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//
|
|
421
|
+
// Pop State.
|
|
422
|
+
//
|
|
423
|
+
onPopState() {
|
|
424
|
+
this.onRouteChangeRequest({
|
|
425
|
+
href: document.location.pathname,
|
|
426
|
+
pushState: false
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
//
|
|
430
|
+
// Scroll.
|
|
431
|
+
//
|
|
432
|
+
get scroll() {
|
|
433
|
+
return this.currentPage?.scroll ?? 0;
|
|
434
|
+
}
|
|
435
|
+
//
|
|
436
|
+
// Listeners.
|
|
437
|
+
//
|
|
438
|
+
addEventListeners() {
|
|
439
|
+
window.addEventListener("popstate", this.onPopState);
|
|
440
|
+
}
|
|
441
|
+
removeEventListeners() {
|
|
442
|
+
window.removeEventListener("popstate", this.onPopState);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
var Application = new ApplicationManager();
|
|
446
|
+
|
|
447
|
+
// src/Page.ts
|
|
448
|
+
var import_lenis = __toESM(require("lenis"), 1);
|
|
449
|
+
var import_mobx3 = require("mobx");
|
|
450
|
+
var import_tempus = __toESM(require("tempus"), 1);
|
|
451
|
+
var Page = class extends Component {
|
|
452
|
+
datasets = [];
|
|
453
|
+
scroll = 0;
|
|
454
|
+
scrollEnabled = true;
|
|
455
|
+
scrollOptions = {};
|
|
456
|
+
constructor({
|
|
457
|
+
application,
|
|
458
|
+
classes,
|
|
459
|
+
datasets,
|
|
460
|
+
element,
|
|
461
|
+
elements,
|
|
462
|
+
scrollEnabled = true,
|
|
463
|
+
scrollOptions = {}
|
|
464
|
+
}) {
|
|
465
|
+
super({
|
|
466
|
+
autoMount: false,
|
|
467
|
+
autoListeners: false,
|
|
468
|
+
classes,
|
|
469
|
+
element,
|
|
470
|
+
elements
|
|
471
|
+
});
|
|
472
|
+
this.application = application;
|
|
473
|
+
this.datasets = datasets;
|
|
474
|
+
this.scrollEnabled = scrollEnabled;
|
|
475
|
+
this.scrollOptions = scrollOptions;
|
|
476
|
+
(0, import_mobx3.makeObservable)(this, {
|
|
477
|
+
components: import_mobx3.observable,
|
|
478
|
+
scroll: import_mobx3.observable
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
create() {
|
|
482
|
+
super.create();
|
|
483
|
+
this.createResizeObserver();
|
|
484
|
+
this.createComponents();
|
|
485
|
+
this.createScroll();
|
|
486
|
+
this.addEventListeners();
|
|
487
|
+
}
|
|
488
|
+
createResizeObserver() {
|
|
489
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
490
|
+
this.onResize();
|
|
491
|
+
});
|
|
492
|
+
this.resizeObserver.observe(this.elements.wrapper);
|
|
493
|
+
}
|
|
494
|
+
destroyResizeObserver() {
|
|
495
|
+
this.resizeObserver.disconnect();
|
|
496
|
+
}
|
|
497
|
+
//
|
|
498
|
+
// Components.
|
|
499
|
+
//
|
|
500
|
+
components = /* @__PURE__ */ new Set();
|
|
501
|
+
createComponents() {
|
|
502
|
+
this.datasets.map(({ component: Component2, selector }) => {
|
|
503
|
+
const elements = this.element.querySelectorAll(selector);
|
|
504
|
+
const components = Array.from(elements).map((element) => {
|
|
505
|
+
const component = new Component2({
|
|
506
|
+
application: this.application,
|
|
507
|
+
element
|
|
508
|
+
});
|
|
509
|
+
return component;
|
|
510
|
+
});
|
|
511
|
+
components.forEach((component) => {
|
|
512
|
+
this.application.addComponent(component);
|
|
513
|
+
this.components.add(component);
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
destroyComponents() {
|
|
518
|
+
this.components.forEach((component) => {
|
|
519
|
+
this.application.removeComponent(component);
|
|
520
|
+
});
|
|
521
|
+
this.components.clear();
|
|
522
|
+
}
|
|
523
|
+
createScroll() {
|
|
524
|
+
if (!this.scrollEnabled) {
|
|
525
|
+
this.element.addEventListener("scroll", this.onScrollFallback);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
this.lenis = new import_lenis.default({
|
|
529
|
+
content: this.elements.wrapper,
|
|
530
|
+
wrapper: this.element,
|
|
531
|
+
...this.scrollOptions
|
|
532
|
+
});
|
|
533
|
+
this.lenis.on("scroll", (event) => {
|
|
534
|
+
this.onScroll(event.scroll);
|
|
535
|
+
this.emitter.emit("scroll", event);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
destroyScroll() {
|
|
539
|
+
if (!this.scrollEnabled) {
|
|
540
|
+
this.element.removeEventListener("scroll", this.onScrollFallback);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
this.lenis?.destroy();
|
|
544
|
+
}
|
|
545
|
+
//
|
|
546
|
+
// Events.
|
|
547
|
+
//
|
|
548
|
+
onResize() {
|
|
549
|
+
this.lenis?.resize();
|
|
550
|
+
}
|
|
551
|
+
onRAF(time) {
|
|
552
|
+
this.lenis?.raf(time);
|
|
553
|
+
}
|
|
554
|
+
onScroll(scroll) {
|
|
555
|
+
this.scroll = scroll;
|
|
556
|
+
}
|
|
557
|
+
onScrollFallback() {
|
|
558
|
+
this.scroll = this.element.scrollTop;
|
|
559
|
+
this.emitter.emit("scroll", { scroll: this.scroll });
|
|
560
|
+
}
|
|
561
|
+
//
|
|
562
|
+
// Events.
|
|
563
|
+
//
|
|
564
|
+
addEventListeners() {
|
|
565
|
+
super.addEventListeners();
|
|
566
|
+
this.unsubscribeRaf = import_tempus.default.add(this.onRAF);
|
|
567
|
+
}
|
|
568
|
+
removeEventListeners() {
|
|
569
|
+
super.removeEventListeners();
|
|
570
|
+
this.unsubscribeRaf?.();
|
|
571
|
+
this.unsubscribeRaf = void 0;
|
|
572
|
+
}
|
|
573
|
+
//
|
|
574
|
+
// Destroy.
|
|
575
|
+
//
|
|
576
|
+
destroy() {
|
|
577
|
+
super.destroy();
|
|
578
|
+
this.destroyResizeObserver();
|
|
579
|
+
this.destroyComponents();
|
|
580
|
+
this.destroyScroll();
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// src/index.ts
|
|
585
|
+
var import_tempus2 = __toESM(require("tempus"), 1);
|
|
586
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
587
|
+
0 && (module.exports = {
|
|
588
|
+
Application,
|
|
589
|
+
ApplicationManager,
|
|
590
|
+
Component,
|
|
591
|
+
EventEmitter,
|
|
592
|
+
Link,
|
|
593
|
+
Links,
|
|
594
|
+
Page,
|
|
595
|
+
Tempus
|
|
596
|
+
});
|