@studiometa/js-toolkit 2.9.0 → 2.10.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/decorators/index.cjs +2 -0
- package/decorators/index.cjs.map +2 -2
- package/decorators/index.d.ts +2 -0
- package/decorators/index.js +2 -0
- package/decorators/index.js.map +2 -2
- package/decorators/withMountOnMediaQuery.cjs +70 -0
- package/decorators/withMountOnMediaQuery.cjs.map +7 -0
- package/decorators/withMountOnMediaQuery.d.ts +18 -0
- package/decorators/withMountOnMediaQuery.js +48 -0
- package/decorators/withMountOnMediaQuery.js.map +7 -0
- package/decorators/withMountWhenPrefersMotion.cjs +30 -0
- package/decorators/withMountWhenPrefersMotion.cjs.map +7 -0
- package/decorators/withMountWhenPrefersMotion.d.ts +3 -0
- package/decorators/withMountWhenPrefersMotion.js +8 -0
- package/decorators/withMountWhenPrefersMotion.js.map +7 -0
- package/decorators/withScrolledInView/withScrolledInView.cjs +9 -8
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.js +9 -8
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.cjs +21 -20
- package/helpers/createApp.cjs.map +2 -2
- package/helpers/createApp.js +21 -20
- package/helpers/createApp.js.map +2 -2
- package/helpers/getInstanceFromElement.cjs +1 -1
- package/helpers/getInstanceFromElement.cjs.map +2 -2
- package/helpers/getInstanceFromElement.js +1 -1
- package/helpers/getInstanceFromElement.js.map +2 -2
- package/helpers/importOnInteraction.cjs +1 -7
- package/helpers/importOnInteraction.cjs.map +3 -3
- package/helpers/importOnInteraction.js +2 -8
- package/helpers/importOnInteraction.js.map +2 -2
- package/helpers/importOnMediaQuery.cjs +44 -0
- package/helpers/importOnMediaQuery.cjs.map +7 -0
- package/helpers/importOnMediaQuery.d.ts +14 -0
- package/helpers/importOnMediaQuery.js +22 -0
- package/helpers/importOnMediaQuery.js.map +7 -0
- package/helpers/importWhenIdle.cjs +2 -7
- package/helpers/importWhenIdle.cjs.map +3 -3
- package/helpers/importWhenIdle.js +2 -7
- package/helpers/importWhenIdle.js.map +2 -2
- package/helpers/importWhenPrefersMotion.cjs +36 -0
- package/helpers/importWhenPrefersMotion.cjs.map +7 -0
- package/helpers/importWhenPrefersMotion.d.ts +11 -0
- package/helpers/importWhenPrefersMotion.js +8 -0
- package/helpers/importWhenPrefersMotion.js.map +7 -0
- package/helpers/importWhenVisible.cjs +1 -10
- package/helpers/importWhenVisible.cjs.map +3 -3
- package/helpers/importWhenVisible.js +2 -11
- package/helpers/importWhenVisible.js.map +2 -2
- package/helpers/index.cjs +4 -0
- package/helpers/index.cjs.map +2 -2
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +4 -0
- package/helpers/index.js.map +2 -2
- package/package.json +4 -4
- package/services/drag.cjs +10 -3
- package/services/drag.cjs.map +2 -2
- package/services/drag.js +10 -3
- package/services/drag.js.map +2 -2
- package/utils/getComponentResolver.cjs +38 -0
- package/utils/getComponentResolver.cjs.map +7 -0
- package/utils/getComponentResolver.d.ts +7 -0
- package/utils/getComponentResolver.js +16 -0
- package/utils/getComponentResolver.js.map +7 -0
- package/utils/index.cjs +2 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -0
- package/utils/index.js.map +2 -2
- package/utils/math/ease.cjs +1 -1
- package/utils/math/ease.cjs.map +2 -2
- package/utils/math/ease.js +1 -1
- package/utils/math/ease.js.map +2 -2
package/helpers/createApp.js
CHANGED
|
@@ -8,26 +8,27 @@ function createApp(App, rootElement = document.body) {
|
|
|
8
8
|
features.set(feature, value);
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
11
|
+
function init() {
|
|
12
|
+
app = new App(options.root).$mount();
|
|
13
|
+
return app;
|
|
14
|
+
}
|
|
15
|
+
let p;
|
|
16
|
+
if (features.get("asyncChildren")) {
|
|
17
|
+
p = Promise.resolve(init());
|
|
18
|
+
} else {
|
|
19
|
+
p = new Promise((resolve) => {
|
|
20
|
+
if (document.readyState === "complete") {
|
|
21
|
+
resolve(init());
|
|
22
|
+
} else {
|
|
23
|
+
document.addEventListener("readystatechange", () => {
|
|
24
|
+
if (document.readyState === "complete") {
|
|
25
|
+
resolve(init());
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return () => p;
|
|
31
32
|
}
|
|
32
33
|
export {
|
|
33
34
|
createApp as default
|
package/helpers/createApp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n */\nexport default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features as Features).forEach(([feature, value]) => {\n features.set(feature as keyof Features, value);\n });\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(init());\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,WAAO,QAAQ,QAAQ,QAAoB,EAAE,QAAQ,CAAC,CAAC,SAAS,KAAK,MAAM;AACzE,eAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,7 +23,7 @@ __export(getInstanceFromElement_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(getInstanceFromElement_exports);
|
|
25
25
|
function getInstanceFromElement(element, Constructor) {
|
|
26
|
-
if (!element.__base__ || !element.__base__.has(Constructor)) {
|
|
26
|
+
if (!element || !element.__base__ || !element.__base__.has(Constructor)) {
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
return element.__base__.get(Constructor);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getInstanceFromElement.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,SAAS,IAAI,WAAW;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getInstanceFromElement.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
-
"mappings": "AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n */\nexport default function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
+
"mappings": "AAKe,SAAR,uBACL,SACA,aACwB;AACxB,MAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,WAAW,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,SAAS,IAAI,WAAW;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,13 +26,7 @@ var import_utils = require("./utils.cjs");
|
|
|
26
26
|
var import_utils2 = require("../utils/index.cjs");
|
|
27
27
|
function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
|
|
28
28
|
const normalizedEvents = (0, import_utils2.isString)(events) ? [events] : events;
|
|
29
|
-
|
|
30
|
-
const resolver = (resolve) => {
|
|
31
|
-
fn().then((module2) => {
|
|
32
|
-
ResolvedClass = "default" in module2 ? module2.default : module2;
|
|
33
|
-
resolve(ResolvedClass);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
29
|
+
const resolver = (0, import_utils2.getComponentResolver)(fn);
|
|
36
30
|
return new Promise((resolve) => {
|
|
37
31
|
const elements = (0, import_utils.getTargetElements)(nameOrSelectorOrElement, parent?.$el);
|
|
38
32
|
const eventListenerOptions = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importOnInteraction.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @returns {Promise<InstanceType<T>>}\n */\nexport default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkC;AAClC,IAAAA,
|
|
6
|
-
"names": ["import_utils"
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString, getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @returns {Promise<InstanceType<T>>}\n */\nexport default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n const eventListenerOptions = {\n capture: true,\n passive: true,\n once: true,\n };\n const handler = () => {\n resolver(resolve);\n };\n\n elements.forEach((element) => {\n normalizedEvents.forEach((event) => {\n element.addEventListener(event, handler, eventListenerOptions);\n });\n });\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkC;AAClC,IAAAA,gBAA+C;AAgBhC,SAAR,oBACL,IACA,yBACA,QACA,QACY;AACZ,QAAM,uBAAmB,wBAAS,MAAM,IAAI,CAAC,MAAM,IAAI;AAEvD,QAAM,eAAW,oCAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,eAAW,gCAAkB,yBAAyB,QAAQ,GAAG;AACvE,UAAM,uBAAuB;AAAA,MAC3B,SAAS;AAAA,MACT,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AACA,UAAM,UAAU,MAAM;AACpB,eAAS,OAAO;AAAA,IAClB;AAEA,aAAS,QAAQ,CAAC,YAAY;AAC5B,uBAAiB,QAAQ,CAAC,UAAU;AAClC,gBAAQ,iBAAiB,OAAO,SAAS,oBAAoB;AAAA,MAC/D,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { getTargetElements } from "./utils.js";
|
|
2
|
-
import { isString } from "../utils/index.js";
|
|
2
|
+
import { isString, getComponentResolver } from "../utils/index.js";
|
|
3
3
|
function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
|
|
4
4
|
const normalizedEvents = isString(events) ? [events] : events;
|
|
5
|
-
|
|
6
|
-
const resolver = (resolve) => {
|
|
7
|
-
fn().then((module) => {
|
|
8
|
-
ResolvedClass = "default" in module ? module.default : module;
|
|
9
|
-
resolve(ResolvedClass);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
5
|
+
const resolver = getComponentResolver(fn);
|
|
12
6
|
return new Promise((resolve) => {
|
|
13
7
|
const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);
|
|
14
8
|
const eventListenerOptions = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importOnInteraction.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @returns {Promise<InstanceType<T>>}\n */\nexport default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString, getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @returns {Promise<InstanceType<T>>}\n */\nexport default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n const eventListenerOptions = {\n capture: true,\n passive: true,\n once: true,\n };\n const handler = () => {\n resolver(resolve);\n };\n\n elements.forEach((element) => {\n normalizedEvents.forEach((event) => {\n element.addEventListener(event, handler, eventListenerOptions);\n });\n });\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,UAAU,4BAA4B;AAgBhC,SAAR,oBACL,IACA,yBACA,QACA,QACY;AACZ,QAAM,mBAAmB,SAAS,MAAM,IAAI,CAAC,MAAM,IAAI;AAEvD,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,UAAM,uBAAuB;AAAA,MAC3B,SAAS;AAAA,MACT,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AACA,UAAM,UAAU,MAAM;AACpB,eAAS,OAAO;AAAA,IAClB;AAEA,aAAS,QAAQ,CAAC,YAAY;AAC5B,uBAAiB,QAAQ,CAAC,UAAU;AAClC,gBAAQ,iBAAiB,OAAO,SAAS,oBAAoB;AAAA,MAC/D,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/helpers/importOnMediaQuery.ts
|
|
20
|
+
var importOnMediaQuery_exports = {};
|
|
21
|
+
__export(importOnMediaQuery_exports, {
|
|
22
|
+
default: () => importOnMediaQuery
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(importOnMediaQuery_exports);
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
function importOnMediaQuery(fn, media) {
|
|
27
|
+
const resolver = (0, import_utils.getComponentResolver)(fn);
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
const mediaQueryList = window.matchMedia(media);
|
|
30
|
+
if (mediaQueryList.matches) {
|
|
31
|
+
resolver(resolve);
|
|
32
|
+
}
|
|
33
|
+
const changeHandler = (event) => {
|
|
34
|
+
if (event.matches) {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
resolver(resolve, () => mediaQueryList.removeEventListener("change", changeHandler));
|
|
37
|
+
}, 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
mediaQueryList.addEventListener("change", changeHandler);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
44
|
+
//# sourceMappingURL=importOnMediaQuery.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/importOnMediaQuery.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils';\n\n/**\n * Import a component when given media query is true.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string} media\n * The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)\n * @returns {Promise<T>}\n */\nexport default function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n media: string,\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const mediaQueryList = window.matchMedia(media);\n\n if (mediaQueryList.matches) {\n resolver(resolve);\n }\n\n const changeHandler = (event: MediaQueryListEvent) => {\n if (event.matches) {\n setTimeout(() => {\n // Remove listener and mount the component\n resolver(resolve, () => mediaQueryList.removeEventListener('change', changeHandler));\n }, 0);\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqC;AAYtB,SAAR,mBACL,IACA,OACY;AACZ,QAAM,eAAW,mCAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,iBAAiB,OAAO,WAAW,KAAK;AAE9C,QAAI,eAAe,SAAS;AAC1B,eAAS,OAAO;AAAA,IAClB;AAEA,UAAM,gBAAgB,CAAC,UAA+B;AACpD,UAAI,MAAM,SAAS;AACjB,mBAAW,MAAM;AAEf,mBAAS,SAAS,MAAM,eAAe,oBAAoB,UAAU,aAAa,CAAC;AAAA,QACrF,GAAG,CAAC;AAAA,MACN;AAAA,IACF;AAGA,mBAAe,iBAAiB,UAAU,aAAa;AAAA,EACzD,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseConstructor } from '../Base/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Import a component when given media query is true.
|
|
4
|
+
*
|
|
5
|
+
* @template {BaseConstructor} T
|
|
6
|
+
* @param {() => Promise<T|{default:T}>} fn
|
|
7
|
+
* The import function.
|
|
8
|
+
* @param {string} media
|
|
9
|
+
* The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)
|
|
10
|
+
* @returns {Promise<T>}
|
|
11
|
+
*/
|
|
12
|
+
export default function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
13
|
+
default: T;
|
|
14
|
+
}>, media: string): Promise<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getComponentResolver } from "../utils";
|
|
2
|
+
function importOnMediaQuery(fn, media) {
|
|
3
|
+
const resolver = getComponentResolver(fn);
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
const mediaQueryList = window.matchMedia(media);
|
|
6
|
+
if (mediaQueryList.matches) {
|
|
7
|
+
resolver(resolve);
|
|
8
|
+
}
|
|
9
|
+
const changeHandler = (event) => {
|
|
10
|
+
if (event.matches) {
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
resolver(resolve, () => mediaQueryList.removeEventListener("change", changeHandler));
|
|
13
|
+
}, 0);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
mediaQueryList.addEventListener("change", changeHandler);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
importOnMediaQuery as default
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=importOnMediaQuery.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/importOnMediaQuery.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils';\n\n/**\n * Import a component when given media query is true.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string} media\n * The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)\n * @returns {Promise<T>}\n */\nexport default function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n media: string,\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const mediaQueryList = window.matchMedia(media);\n\n if (mediaQueryList.matches) {\n resolver(resolve);\n }\n\n const changeHandler = (event: MediaQueryListEvent) => {\n if (event.matches) {\n setTimeout(() => {\n // Remove listener and mount the component\n resolver(resolve, () => mediaQueryList.removeEventListener('change', changeHandler));\n }, 0);\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AAYtB,SAAR,mBACL,IACA,OACY;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,iBAAiB,OAAO,WAAW,KAAK;AAE9C,QAAI,eAAe,SAAS;AAC1B,eAAS,OAAO;AAAA,IAClB;AAEA,UAAM,gBAAgB,CAAC,UAA+B;AACpD,UAAI,MAAM,SAAS;AACjB,mBAAW,MAAM;AAEf,mBAAS,SAAS,MAAM,eAAe,oBAAoB,UAAU,aAAa,CAAC;AAAA,QACrF,GAAG,CAAC;AAAA,MACN;AAAA,IACF;AAGA,mBAAe,iBAAiB,UAAU,aAAa;AAAA,EACzD,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -22,14 +22,9 @@ __export(importWhenIdle_exports, {
|
|
|
22
22
|
default: () => importWhenIdle
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(importWhenIdle_exports);
|
|
25
|
+
var import_utils = require("../utils/index.cjs");
|
|
25
26
|
function importWhenIdle(fn, { timeout = 1 } = {}) {
|
|
26
|
-
|
|
27
|
-
const resolver = (resolve) => {
|
|
28
|
-
fn().then((module2) => {
|
|
29
|
-
ResolvedClass = "default" in module2 ? module2.default : module2;
|
|
30
|
-
resolve(ResolvedClass);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
27
|
+
const resolver = (0, import_utils.getComponentResolver)(fn);
|
|
33
28
|
return new Promise((resolve) => {
|
|
34
29
|
if (!("requestIdleCallback" in window)) {
|
|
35
30
|
setTimeout(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenIdle.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @returns {Promise<T>}\n */\nexport default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @returns {Promise<T>}\n */\nexport default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n if (!('requestIdleCallback' in window)) {\n setTimeout(() => {\n resolver(resolve);\n }, timeout);\n } else {\n window.requestIdleCallback(\n () => {\n setTimeout(() => {\n resolver(resolve);\n }, 0);\n },\n { timeout },\n );\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqC;AAgBtB,SAAR,eACL,IACA,EAAE,UAAU,EAAE,IAA2B,CAAC,GAC9B;AACZ,QAAM,eAAW,mCAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,EAAE,yBAAyB,SAAS;AACtC,iBAAW,MAAM;AACf,iBAAS,OAAO;AAAA,MAClB,GAAG,OAAO;AAAA,IACZ,OAAO;AACL,aAAO;AAAA,QACL,MAAM;AACJ,qBAAW,MAAM;AACf,qBAAS,OAAO;AAAA,UAClB,GAAG,CAAC;AAAA,QACN;AAAA,QACA,EAAE,QAAQ;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { getComponentResolver } from "../utils/index.js";
|
|
1
2
|
function importWhenIdle(fn, { timeout = 1 } = {}) {
|
|
2
|
-
|
|
3
|
-
const resolver = (resolve) => {
|
|
4
|
-
fn().then((module) => {
|
|
5
|
-
ResolvedClass = "default" in module ? module.default : module;
|
|
6
|
-
resolve(ResolvedClass);
|
|
7
|
-
});
|
|
8
|
-
};
|
|
3
|
+
const resolver = getComponentResolver(fn);
|
|
9
4
|
return new Promise((resolve) => {
|
|
10
5
|
if (!("requestIdleCallback" in window)) {
|
|
11
6
|
setTimeout(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenIdle.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @returns {Promise<T>}\n */\nexport default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @returns {Promise<T>}\n */\nexport default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n if (!('requestIdleCallback' in window)) {\n setTimeout(() => {\n resolver(resolve);\n }, timeout);\n } else {\n window.requestIdleCallback(\n () => {\n setTimeout(() => {\n resolver(resolve);\n }, 0);\n },\n { timeout },\n );\n }\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AAgBtB,SAAR,eACL,IACA,EAAE,UAAU,EAAE,IAA2B,CAAC,GAC9B;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,EAAE,yBAAyB,SAAS;AACtC,iBAAW,MAAM;AACf,iBAAS,OAAO;AAAA,MAClB,GAAG,OAAO;AAAA,IACZ,OAAO;AACL,aAAO;AAAA,QACL,MAAM;AACJ,qBAAW,MAAM;AACf,qBAAS,OAAO;AAAA,UAClB,GAAG,CAAC;AAAA,QACN;AAAA,QACA,EAAE,QAAQ;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// packages/js-toolkit/helpers/importWhenPrefersMotion.ts
|
|
26
|
+
var importWhenPrefersMotion_exports = {};
|
|
27
|
+
__export(importWhenPrefersMotion_exports, {
|
|
28
|
+
default: () => importWhenPrefersMotion
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(importWhenPrefersMotion_exports);
|
|
31
|
+
var import_importOnMediaQuery = __toESM(require("./importOnMediaQuery.cjs"), 1);
|
|
32
|
+
function importWhenPrefersMotion(fn) {
|
|
33
|
+
return (0, import_importOnMediaQuery.default)(fn, "not (prefers-reduced-motion)");
|
|
34
|
+
}
|
|
35
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
36
|
+
//# sourceMappingURL=importWhenPrefersMotion.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/importWhenPrefersMotion.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport importOnMediaQuery from './importOnMediaQuery.js';\n\n/**\n * Import a component if user does not reduce motion.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * @returns {Promise<T>}\n */\nexport default function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n): Promise<T> {\n return importOnMediaQuery(fn, 'not (prefers-reduced-motion)');\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAA+B;AAShB,SAAR,wBACL,IACY;AACZ,aAAO,0BAAAA,SAAmB,IAAI,8BAA8B;AAC9D;",
|
|
6
|
+
"names": ["importOnMediaQuery"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BaseConstructor } from '../Base/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Import a component if user does not reduce motion.
|
|
4
|
+
*
|
|
5
|
+
* @template {BaseConstructor} T
|
|
6
|
+
* @param {() => Promise<T|{default:T}>} fn
|
|
7
|
+
* @returns {Promise<T>}
|
|
8
|
+
*/
|
|
9
|
+
export default function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
10
|
+
default: T;
|
|
11
|
+
}>): Promise<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import importOnMediaQuery from "./importOnMediaQuery.js";
|
|
2
|
+
function importWhenPrefersMotion(fn) {
|
|
3
|
+
return importOnMediaQuery(fn, "not (prefers-reduced-motion)");
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
importWhenPrefersMotion as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=importWhenPrefersMotion.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/importWhenPrefersMotion.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport importOnMediaQuery from './importOnMediaQuery.js';\n\n/**\n * Import a component if user does not reduce motion.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * @returns {Promise<T>}\n */\nexport default function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n): Promise<T> {\n return importOnMediaQuery(fn, 'not (prefers-reduced-motion)');\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,wBAAwB;AAShB,SAAR,wBACL,IACY;AACZ,SAAO,mBAAmB,IAAI,8BAA8B;AAC9D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -25,16 +25,7 @@ module.exports = __toCommonJS(importWhenVisible_exports);
|
|
|
25
25
|
var import_utils = require("./utils.cjs");
|
|
26
26
|
var import_utils2 = require("../utils/index.cjs");
|
|
27
27
|
function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions = {}) {
|
|
28
|
-
|
|
29
|
-
const resolver = (resolve, cb) => {
|
|
30
|
-
fn().then((module2) => {
|
|
31
|
-
ResolvedClass = "default" in module2 ? module2.default : module2;
|
|
32
|
-
resolve(ResolvedClass);
|
|
33
|
-
if ((0, import_utils2.isFunction)(cb)) {
|
|
34
|
-
cb();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
};
|
|
28
|
+
const resolver = (0, import_utils2.getComponentResolver)(fn);
|
|
38
29
|
return new Promise((resolve) => {
|
|
39
30
|
const observer = new IntersectionObserver((entries) => {
|
|
40
31
|
const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenVisible.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkC;AAClC,IAAAA,
|
|
6
|
-
"names": ["import_utils"
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when it is visible.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {Base} [parent]\n * The parent component.\n * @param {IntersectionObserverInit} [observerOptions]\n * Options for the `IntersectionObserver` instance.\n * @returns {Promise<T>}\n */\nexport default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n parent?: Base,\n observerOptions: IntersectionObserverInit = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const observer = new IntersectionObserver((entries) => {\n const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);\n if (someEntriesAreVisible) {\n setTimeout(() => {\n resolver(resolve, () => observer.disconnect());\n }, 0);\n }\n }, observerOptions);\n\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n elements.forEach((element) => observer.observe(element));\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkC;AAClC,IAAAA,gBAAqC;AAgBtB,SAAR,kBACL,IACA,yBACA,QACA,kBAA4C,CAAC,GACjC;AACZ,QAAM,eAAW,oCAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,IAAI,qBAAqB,CAAC,YAAY;AACrD,YAAM,wBAAwB,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc;AAC1E,UAAI,uBAAuB;AACzB,mBAAW,MAAM;AACf,mBAAS,SAAS,MAAM,SAAS,WAAW,CAAC;AAAA,QAC/C,GAAG,CAAC;AAAA,MACN;AAAA,IACF,GAAG,eAAe;AAElB,UAAM,eAAW,gCAAkB,yBAAyB,QAAQ,GAAG;AACvE,aAAS,QAAQ,CAAC,YAAY,SAAS,QAAQ,OAAO,CAAC;AAAA,EACzD,CAAC;AACH;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { getTargetElements } from "./utils.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getComponentResolver } from "../utils/index.js";
|
|
3
3
|
function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions = {}) {
|
|
4
|
-
|
|
5
|
-
const resolver = (resolve, cb) => {
|
|
6
|
-
fn().then((module) => {
|
|
7
|
-
ResolvedClass = "default" in module ? module.default : module;
|
|
8
|
-
resolve(ResolvedClass);
|
|
9
|
-
if (isFunction(cb)) {
|
|
10
|
-
cb();
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
};
|
|
4
|
+
const resolver = getComponentResolver(fn);
|
|
14
5
|
return new Promise((resolve) => {
|
|
15
6
|
const observer = new IntersectionObserver((entries) => {
|
|
16
7
|
const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenVisible.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport {
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when it is visible.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {Base} [parent]\n * The parent component.\n * @param {IntersectionObserverInit} [observerOptions]\n * Options for the `IntersectionObserver` instance.\n * @returns {Promise<T>}\n */\nexport default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n parent?: Base,\n observerOptions: IntersectionObserverInit = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const observer = new IntersectionObserver((entries) => {\n const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);\n if (someEntriesAreVisible) {\n setTimeout(() => {\n resolver(resolve, () => observer.disconnect());\n }, 0);\n }\n }, observerOptions);\n\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n elements.forEach((element) => observer.observe(element));\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAgBtB,SAAR,kBACL,IACA,yBACA,QACA,kBAA4C,CAAC,GACjC;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,IAAI,qBAAqB,CAAC,YAAY;AACrD,YAAM,wBAAwB,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc;AAC1E,UAAI,uBAAuB;AACzB,mBAAW,MAAM;AACf,mBAAS,SAAS,MAAM,SAAS,WAAW,CAAC;AAAA,QAC/C,GAAG,CAAC;AAAA,MACN;AAAA,IACF,GAAG,eAAe;AAElB,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,aAAS,QAAQ,CAAC,YAAY,SAAS,QAAQ,OAAO,CAAC;AAAA,EACzD,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/index.cjs
CHANGED
|
@@ -30,7 +30,9 @@ __export(helpers_exports, {
|
|
|
30
30
|
getClosestParent: () => import_getClosestParent.default,
|
|
31
31
|
getInstanceFromElement: () => import_getInstanceFromElement.default,
|
|
32
32
|
importOnInteraction: () => import_importOnInteraction.default,
|
|
33
|
+
importOnMediaQuery: () => import_importOnMediaQuery.default,
|
|
33
34
|
importWhenIdle: () => import_importWhenIdle.default,
|
|
35
|
+
importWhenPrefersMotion: () => import_importWhenPrefersMotion.default,
|
|
34
36
|
importWhenVisible: () => import_importWhenVisible.default
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(helpers_exports);
|
|
@@ -41,5 +43,7 @@ var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cj
|
|
|
41
43
|
var import_importOnInteraction = __toESM(require("./importOnInteraction.cjs"), 1);
|
|
42
44
|
var import_importWhenIdle = __toESM(require("./importWhenIdle.cjs"), 1);
|
|
43
45
|
var import_importWhenVisible = __toESM(require("./importWhenVisible.cjs"), 1);
|
|
46
|
+
var import_importOnMediaQuery = __toESM(require("./importOnMediaQuery.cjs"), 1);
|
|
47
|
+
var import_importWhenPrefersMotion = __toESM(require("./importWhenPrefersMotion"), 1);
|
|
44
48
|
if (module.exports.default) module.exports = module.exports.default;
|
|
45
49
|
//# sourceMappingURL=index.cjs.map
|
package/helpers/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './getDirectChildren.js';\nexport { default as createApp } from './createApp.js';\nexport { default as getClosestParent } from './getClosestParent.js';\nexport { default as getInstanceFromElement } from './getInstanceFromElement.js';\nexport { default as importOnInteraction } from './importOnInteraction.js';\nexport { default as importWhenIdle } from './importWhenIdle.js';\nexport { default as importWhenVisible } from './importWhenVisible.js';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAc,oCAAd;AACA,uBAAqC;AACrC,8BAA4C;AAC5C,oCAAkD;AAClD,iCAA+C;AAC/C,4BAA0C;AAC1C,+BAA6C;",
|
|
4
|
+
"sourcesContent": ["export * from './getDirectChildren.js';\nexport { default as createApp } from './createApp.js';\nexport { default as getClosestParent } from './getClosestParent.js';\nexport { default as getInstanceFromElement } from './getInstanceFromElement.js';\nexport { default as importOnInteraction } from './importOnInteraction.js';\nexport { default as importWhenIdle } from './importWhenIdle.js';\nexport { default as importWhenVisible } from './importWhenVisible.js';\nexport { default as importOnMediaQuery } from './importOnMediaQuery.js';\nexport { default as importWhenPrefersMotion } from './importWhenPrefersMotion';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAc,oCAAd;AACA,uBAAqC;AACrC,8BAA4C;AAC5C,oCAAkD;AAClD,iCAA+C;AAC/C,4BAA0C;AAC1C,+BAA6C;AAC7C,gCAA8C;AAC9C,qCAAmD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export { default as getInstanceFromElement } from './getInstanceFromElement.js';
|
|
|
5
5
|
export { default as importOnInteraction } from './importOnInteraction.js';
|
|
6
6
|
export { default as importWhenIdle } from './importWhenIdle.js';
|
|
7
7
|
export { default as importWhenVisible } from './importWhenVisible.js';
|
|
8
|
+
export { default as importOnMediaQuery } from './importOnMediaQuery.js';
|
|
9
|
+
export { default as importWhenPrefersMotion } from './importWhenPrefersMotion';
|
package/helpers/index.js
CHANGED
|
@@ -5,12 +5,16 @@ import { default as default4 } from "./getInstanceFromElement.js";
|
|
|
5
5
|
import { default as default5 } from "./importOnInteraction.js";
|
|
6
6
|
import { default as default6 } from "./importWhenIdle.js";
|
|
7
7
|
import { default as default7 } from "./importWhenVisible.js";
|
|
8
|
+
import { default as default8 } from "./importOnMediaQuery.js";
|
|
9
|
+
import { default as default9 } from "./importWhenPrefersMotion";
|
|
8
10
|
export {
|
|
9
11
|
default2 as createApp,
|
|
10
12
|
default3 as getClosestParent,
|
|
11
13
|
default4 as getInstanceFromElement,
|
|
12
14
|
default5 as importOnInteraction,
|
|
15
|
+
default8 as importOnMediaQuery,
|
|
13
16
|
default6 as importWhenIdle,
|
|
17
|
+
default9 as importWhenPrefersMotion,
|
|
14
18
|
default7 as importWhenVisible
|
|
15
19
|
};
|
|
16
20
|
//# sourceMappingURL=index.js.map
|
package/helpers/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './getDirectChildren.js';\nexport { default as createApp } from './createApp.js';\nexport { default as getClosestParent } from './getClosestParent.js';\nexport { default as getInstanceFromElement } from './getInstanceFromElement.js';\nexport { default as importOnInteraction } from './importOnInteraction.js';\nexport { default as importWhenIdle } from './importWhenIdle.js';\nexport { default as importWhenVisible } from './importWhenVisible.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAyC;AAClD,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAAoC;",
|
|
4
|
+
"sourcesContent": ["export * from './getDirectChildren.js';\nexport { default as createApp } from './createApp.js';\nexport { default as getClosestParent } from './getClosestParent.js';\nexport { default as getInstanceFromElement } from './getInstanceFromElement.js';\nexport { default as importOnInteraction } from './importOnInteraction.js';\nexport { default as importWhenIdle } from './importWhenIdle.js';\nexport { default as importWhenVisible } from './importWhenVisible.js';\nexport { default as importOnMediaQuery } from './importOnMediaQuery.js';\nexport { default as importWhenPrefersMotion } from './importWhenPrefersMotion';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAyC;AAClD,SAAoB,WAAXA,gBAAsC;AAC/C,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAAoC;AAC7C,SAAoB,WAAXA,gBAAqC;AAC9C,SAAoB,WAAXA,gBAA0C;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|