@vettvangur/framework 0.0.13 → 0.0.15
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/browser-events.d.ts +3 -0
- package/dist/browser-events.js +4 -3
- package/dist/dom.d.ts +3 -0
- package/dist/dom.js +3 -0
- package/dist/enable-zoom.d.ts +1 -0
- package/dist/enable-zoom.js +22 -0
- package/dist/events.d.ts +10 -12
- package/dist/events.js +4 -9
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/preload-timeout.d.ts +3 -0
- package/dist/preload-timeout.js +3 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.js +5 -0
- package/dist/vertical-resize.d.ts +2 -0
- package/dist/vertical-resize.js +12 -0
- package/dist/vettvangur.js +24 -9
- package/package.json +1 -1
package/dist/browser-events.d.ts
CHANGED
package/dist/browser-events.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module framework
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* Run a callback when the DOM is fully parsed (no need to wait for images/CSS).
|
|
3
6
|
*
|
|
@@ -11,9 +14,7 @@
|
|
|
11
14
|
* initApp()
|
|
12
15
|
* })
|
|
13
16
|
*/
|
|
14
|
-
export const onDOMContentLoaded = (fn) => document.readyState === 'loading'
|
|
15
|
-
? document.addEventListener('DOMContentLoaded', fn, { once: true })
|
|
16
|
-
: fn();
|
|
17
|
+
export const onDOMContentLoaded = (fn) => document.readyState === 'loading' ? document.addEventListener('DOMContentLoaded', fn, { once: true }) : fn();
|
|
17
18
|
/**
|
|
18
19
|
* Subscribe to browser history changes triggered by `history.pushState`,
|
|
19
20
|
* `history.replaceState`, or user navigation (back/forward).
|
package/dist/dom.d.ts
CHANGED
package/dist/dom.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function enableZoom(): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function enableZoom() {
|
|
2
|
+
const getProperty = (property) => getComputedStyle(document.documentElement).getPropertyValue(property).trim();
|
|
3
|
+
const setProperty = (property, value) => {
|
|
4
|
+
document.documentElement.style.setProperty(property, value);
|
|
5
|
+
};
|
|
6
|
+
const ddw = '--breakpoint-desktop-design-width';
|
|
7
|
+
const tdw = '--breakpoint-tablet-design-width';
|
|
8
|
+
const mdw = '--breakpoint-mobile-design-width';
|
|
9
|
+
const initialScale = window.devicePixelRatio;
|
|
10
|
+
const desktopDesignWidth = getProperty(ddw);
|
|
11
|
+
const tabletDesignWidth = getProperty(tdw);
|
|
12
|
+
const mobileDesignWidth = getProperty(mdw);
|
|
13
|
+
const observer = new ResizeObserver(() => {
|
|
14
|
+
const currentScale = window.devicePixelRatio;
|
|
15
|
+
setProperty(ddw, (Number(desktopDesignWidth) * (initialScale / currentScale)).toString());
|
|
16
|
+
setProperty(tdw, (Number(tabletDesignWidth) * (initialScale / currentScale)).toString());
|
|
17
|
+
setProperty(mdw, (Number(mobileDesignWidth) * (initialScale / currentScale)).toString());
|
|
18
|
+
});
|
|
19
|
+
if (document.body) {
|
|
20
|
+
observer.observe(document.body);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/events.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module framework
|
|
3
|
+
*/
|
|
1
4
|
import type { Handler } from './types';
|
|
2
5
|
/**
|
|
3
6
|
* Create a tiny event bus backed by `EventTarget`.
|
|
@@ -22,26 +25,21 @@ import type { Handler } from './types';
|
|
|
22
25
|
* bus.emit('READY')
|
|
23
26
|
* ```
|
|
24
27
|
*
|
|
25
|
-
* @returns {
|
|
26
|
-
* on(type: string, handler: Handler): () => void;
|
|
27
|
-
* once(type: string, handler: Handler): void;
|
|
28
|
-
* emit(type: string, payload?: any): void;
|
|
29
|
-
* }}
|
|
30
|
-
* An object with `on`, `once`, and `emit` methods.
|
|
28
|
+
* @returns {object} An object with `on`, `once`, and `emit` methods.
|
|
31
29
|
*/
|
|
32
30
|
export declare function createEventBus(): {
|
|
33
31
|
/**
|
|
34
32
|
* Subscribe to an event type.
|
|
35
33
|
* @param {string} type - Event name.
|
|
36
|
-
* @param {
|
|
37
|
-
* @returns {()
|
|
34
|
+
* @param {function(*=): void} handler - Called with `payload` passed to {@link emit}.
|
|
35
|
+
* @returns {function(): void} Unsubscribe function to remove this handler.
|
|
38
36
|
*/
|
|
39
37
|
on(type: string, handler: Handler): () => void;
|
|
40
38
|
/**
|
|
41
39
|
* Subscribe to a single occurrence of an event type.
|
|
42
40
|
* Automatically unsubscribes after the first call.
|
|
43
41
|
* @param {string} type - Event name.
|
|
44
|
-
* @param {
|
|
42
|
+
* @param {function(*=): void} handler - Called once with the emitted `payload`.
|
|
45
43
|
*/
|
|
46
44
|
once(type: string, handler: Handler): void;
|
|
47
45
|
/**
|
|
@@ -67,15 +65,15 @@ export declare const events: {
|
|
|
67
65
|
/**
|
|
68
66
|
* Subscribe to an event type.
|
|
69
67
|
* @param {string} type - Event name.
|
|
70
|
-
* @param {
|
|
71
|
-
* @returns {()
|
|
68
|
+
* @param {function(*=): void} handler - Called with `payload` passed to {@link emit}.
|
|
69
|
+
* @returns {function(): void} Unsubscribe function to remove this handler.
|
|
72
70
|
*/
|
|
73
71
|
on(type: string, handler: Handler): () => void;
|
|
74
72
|
/**
|
|
75
73
|
* Subscribe to a single occurrence of an event type.
|
|
76
74
|
* Automatically unsubscribes after the first call.
|
|
77
75
|
* @param {string} type - Event name.
|
|
78
|
-
* @param {
|
|
76
|
+
* @param {function(*=): void} handler - Called once with the emitted `payload`.
|
|
79
77
|
*/
|
|
80
78
|
once(type: string, handler: Handler): void;
|
|
81
79
|
/**
|
package/dist/events.js
CHANGED
|
@@ -21,12 +21,7 @@
|
|
|
21
21
|
* bus.emit('READY')
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
|
-
* @returns {
|
|
25
|
-
* on(type: string, handler: Handler): () => void;
|
|
26
|
-
* once(type: string, handler: Handler): void;
|
|
27
|
-
* emit(type: string, payload?: any): void;
|
|
28
|
-
* }}
|
|
29
|
-
* An object with `on`, `once`, and `emit` methods.
|
|
24
|
+
* @returns {object} An object with `on`, `once`, and `emit` methods.
|
|
30
25
|
*/
|
|
31
26
|
export function createEventBus() {
|
|
32
27
|
const target = new EventTarget();
|
|
@@ -34,8 +29,8 @@ export function createEventBus() {
|
|
|
34
29
|
/**
|
|
35
30
|
* Subscribe to an event type.
|
|
36
31
|
* @param {string} type - Event name.
|
|
37
|
-
* @param {
|
|
38
|
-
* @returns {()
|
|
32
|
+
* @param {function(*=): void} handler - Called with `payload` passed to {@link emit}.
|
|
33
|
+
* @returns {function(): void} Unsubscribe function to remove this handler.
|
|
39
34
|
*/
|
|
40
35
|
on(type, handler) {
|
|
41
36
|
const wrapped = (e) => handler(e.detail);
|
|
@@ -46,7 +41,7 @@ export function createEventBus() {
|
|
|
46
41
|
* Subscribe to a single occurrence of an event type.
|
|
47
42
|
* Automatically unsubscribes after the first call.
|
|
48
43
|
* @param {string} type - Event name.
|
|
49
|
-
* @param {
|
|
44
|
+
* @param {function(*=): void} handler - Called once with the emitted `payload`.
|
|
50
45
|
*/
|
|
51
46
|
once(type, handler) {
|
|
52
47
|
const wrapped = (e) => handler(e.detail);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Lightweight runtime for mounting “features” on DOM nodes.
|
|
4
|
+
* @module framework
|
|
5
|
+
*/
|
|
1
6
|
export type { FeatureProps, FeatureInstance, Feature, Loader } from './types';
|
|
2
7
|
export { vettvangur } from './vettvangur';
|
|
3
8
|
export { onDOMContentLoaded } from './browser-events';
|
|
4
9
|
export { preloadTimeout } from './preload-timeout';
|
|
10
|
+
export { enableZoom } from './enable-zoom';
|
|
11
|
+
export { verticalResizeCheck, isVerticalResize } from './vertical-resize';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Lightweight runtime for mounting “features” on DOM nodes.
|
|
4
|
+
* @module framework
|
|
5
|
+
*/
|
|
1
6
|
export { vettvangur } from './vettvangur';
|
|
2
7
|
export { onDOMContentLoaded } from './browser-events';
|
|
3
8
|
export { preloadTimeout } from './preload-timeout';
|
|
9
|
+
export { enableZoom } from './enable-zoom';
|
|
10
|
+
export { verticalResizeCheck, isVerticalResize } from './vertical-resize';
|
package/dist/preload-timeout.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Public types for the feature-loader runtime.
|
|
4
|
+
* @module framework
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Key/value props passed into a feature factory.
|
|
8
|
+
*/
|
|
1
9
|
export type FeatureProps = Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Runtime instance returned by a feature factory.
|
|
12
|
+
*/
|
|
2
13
|
export interface FeatureInstance {
|
|
3
14
|
mount(): void;
|
|
4
15
|
unmount(): void;
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Feature factory function.
|
|
19
|
+
*/
|
|
6
20
|
export type Feature = (root: HTMLElement, props?: FeatureProps) => FeatureInstance;
|
|
21
|
+
/**
|
|
22
|
+
* Dynamic import function used to load a feature module.
|
|
23
|
+
*/
|
|
7
24
|
export type Loader = () => Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Event bus handler.
|
|
27
|
+
*/
|
|
8
28
|
export type Handler = (payload?: any) => void;
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export let isVerticalResize = false;
|
|
2
|
+
export function verticalResizeCheck() {
|
|
3
|
+
let lastWindowHeight = window.innerHeight;
|
|
4
|
+
let lastWindowWidth = window.innerWidth;
|
|
5
|
+
window.addEventListener('resize', () => {
|
|
6
|
+
const currentHeight = window.innerHeight;
|
|
7
|
+
const currentWidth = window.innerWidth;
|
|
8
|
+
isVerticalResize = currentHeight !== lastWindowHeight && currentWidth === lastWindowWidth;
|
|
9
|
+
lastWindowHeight = currentHeight;
|
|
10
|
+
lastWindowWidth = currentWidth;
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/vettvangur.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module framework
|
|
3
|
+
*/
|
|
1
4
|
import { $$, inViewport } from './dom';
|
|
2
5
|
/** @internal Symbolic key stored on mounted HTMLElements to cache their FeatureInstance. */
|
|
3
6
|
const INST = '__feature_instance__';
|
|
@@ -19,11 +22,16 @@ const loaderCache = new WeakMap();
|
|
|
19
22
|
*/
|
|
20
23
|
async function mount(el, load) {
|
|
21
24
|
// Already mounted? bail.
|
|
22
|
-
if (el[INST])
|
|
25
|
+
if (el[INST]) {
|
|
23
26
|
return;
|
|
27
|
+
}
|
|
24
28
|
try {
|
|
25
29
|
// Reuse an in-flight or completed import for this loader.
|
|
26
|
-
|
|
30
|
+
let promise = loaderCache.get(load);
|
|
31
|
+
if (!promise) {
|
|
32
|
+
promise = load();
|
|
33
|
+
loaderCache.set(load, promise);
|
|
34
|
+
}
|
|
27
35
|
const mod = await promise;
|
|
28
36
|
const exp = mod.default ?? mod;
|
|
29
37
|
let instance;
|
|
@@ -112,12 +120,14 @@ export function vettvangur(root = document, moduleMap) {
|
|
|
112
120
|
/** Lazily mount elements as they approach the viewport. */
|
|
113
121
|
const io = new IntersectionObserver((entries) => {
|
|
114
122
|
entries.forEach((e) => {
|
|
115
|
-
if (!e.isIntersecting)
|
|
123
|
+
if (!e.isIntersecting) {
|
|
116
124
|
return;
|
|
125
|
+
}
|
|
117
126
|
const el = e.target;
|
|
118
127
|
const loader = resolveLoader(el, moduleMap);
|
|
119
|
-
if (!loader)
|
|
128
|
+
if (!loader) {
|
|
120
129
|
return io.unobserve(el);
|
|
130
|
+
}
|
|
121
131
|
mount(el, loader).finally(() => io.unobserve(el));
|
|
122
132
|
});
|
|
123
133
|
}, { root: null, threshold: 0, rootMargin: '200px 0px' });
|
|
@@ -130,8 +140,9 @@ export function vettvangur(root = document, moduleMap) {
|
|
|
130
140
|
.map((s) => s.trim())
|
|
131
141
|
.filter(Boolean);
|
|
132
142
|
sels.forEach((sel) => $$(root, sel).forEach((el) => {
|
|
133
|
-
if (seen.has(el))
|
|
143
|
+
if (seen.has(el)) {
|
|
134
144
|
return;
|
|
145
|
+
}
|
|
135
146
|
seen.add(el);
|
|
136
147
|
if (inViewport(el)) {
|
|
137
148
|
// Eager mount if already visible
|
|
@@ -152,8 +163,9 @@ export function vettvangur(root = document, moduleMap) {
|
|
|
152
163
|
for (const m of muts) {
|
|
153
164
|
// Added nodes → try to mount
|
|
154
165
|
m.addedNodes.forEach((n) => {
|
|
155
|
-
if (!(n instanceof HTMLElement))
|
|
166
|
+
if (!(n instanceof HTMLElement)) {
|
|
156
167
|
return;
|
|
168
|
+
}
|
|
157
169
|
// If the added node itself matches a selector
|
|
158
170
|
const loader = resolveLoader(n, moduleMap);
|
|
159
171
|
if (loader) {
|
|
@@ -166,18 +178,21 @@ export function vettvangur(root = document, moduleMap) {
|
|
|
166
178
|
.map((s) => s.trim())
|
|
167
179
|
.filter(Boolean);
|
|
168
180
|
sels.forEach((sel) => n.querySelectorAll(sel).forEach((el) => {
|
|
169
|
-
if (el[INST])
|
|
181
|
+
if (el[INST]) {
|
|
170
182
|
return;
|
|
183
|
+
}
|
|
171
184
|
inViewport(el) ? mount(el, moduleMap[key]) : io.observe(el);
|
|
172
185
|
}));
|
|
173
186
|
}
|
|
174
187
|
});
|
|
175
188
|
// Removed nodes → unmount if needed
|
|
176
189
|
m.removedNodes.forEach((n) => {
|
|
177
|
-
if (!(n instanceof HTMLElement))
|
|
190
|
+
if (!(n instanceof HTMLElement)) {
|
|
178
191
|
return;
|
|
179
|
-
|
|
192
|
+
}
|
|
193
|
+
if (n[INST]) {
|
|
180
194
|
unmount(n);
|
|
195
|
+
}
|
|
181
196
|
n.querySelectorAll('*').forEach((el) => el[INST] && unmount(el));
|
|
182
197
|
});
|
|
183
198
|
}
|