@zero-dependency/dom 1.8.4 → 1.8.5
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/html.d.ts +7 -5
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/dist/location-observer.d.ts +21 -0
- package/package.json +12 -12
package/dist/html.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type CSS from 'csstype';
|
|
2
2
|
type Properties<T extends keyof HTMLElementTagNameMap> = Partial<{
|
|
3
3
|
style: CSS.Properties;
|
|
4
4
|
} & Omit<HTMLElementTagNameMap[T], 'style'>>;
|
|
5
|
-
type
|
|
5
|
+
type ChildElement = string | Node | HTMLElement;
|
|
6
|
+
type Childrens = ChildElement[];
|
|
6
7
|
/**
|
|
7
8
|
* Creates a new HTML element of the specified type and with the given attributes and children nodes.
|
|
8
9
|
*
|
|
9
10
|
* @param {T} tag
|
|
10
11
|
* The type of HTML element to create.
|
|
11
12
|
*
|
|
12
|
-
* @param {Properties<T> |
|
|
13
|
+
* @param {Properties<T> | Childrens | ChildElement} [props]
|
|
13
14
|
* The properties or children nodes to add to the element.
|
|
14
15
|
*
|
|
15
|
-
* @param {
|
|
16
|
+
* @param {Childrens | ChildElement} [children]
|
|
16
17
|
* The children nodes to add to the element.
|
|
17
18
|
*
|
|
18
19
|
* @return {HTMLElementTagNameMap[T]}
|
|
@@ -25,8 +26,9 @@ type Children = (string | Node | HTMLElement)[];
|
|
|
25
26
|
* el('div', el('span', 'Hello world'))
|
|
26
27
|
* el('div', el('span', 'Hello'), el('span', 'world'))
|
|
27
28
|
* el('div', el('span', 'Hello world'), 'world')
|
|
29
|
+
* el('div', { id: 'foo' }, [el('span', 'Hello'), el('span', 'world')])
|
|
28
30
|
*/
|
|
29
|
-
export declare function el<T extends keyof HTMLElementTagNameMap>(tag: T, props?: Properties<T> |
|
|
31
|
+
export declare function el<T extends keyof HTMLElementTagNameMap>(tag: T, props?: Properties<T> | Childrens | ChildElement, children?: Childrens | ChildElement): HTMLElementTagNameMap[T];
|
|
30
32
|
/**
|
|
31
33
|
* Creates a new Text node with the provided text.
|
|
32
34
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(o,t,n){const e=document.createElement(o);return t instanceof Node?e.append(t):typeof t=="string"?e.append(r(t)):Array.isArray(t)?e.append(...t):t&&(Object.assign(e,t),Object.assign(e.style,t?.style)),n!==void 0&&(Array.isArray(n)?e.append(...n):n instanceof Node?e.append(n):typeof n=="string"&&e.append(r(n))),e}function r(o){return document.createTextNode(o)}function v(){return r(" ")}function d(o,t,n){const e=new MutationObserver((s,a)=>{for(const u of s)t(u,a)});return e.observe(o,{childList:!0,subtree:!0,...n}),()=>e.disconnect()}function m({selector:o,target:t=document.body,rejectTimeoutMs:n,signal:e}){return new Promise((s,a)=>{const u=d(t,(f,l)=>{const b=t.querySelector(o);b&&(l.disconnect(),s(b))}),i={timeout:null,abort:null},c=f=>{i.timeout&&clearTimeout(i.timeout),i.abort&&e.removeEventListener("abort",i.abort),u(),a(f)};n>0&&(i.timeout=setTimeout(()=>c(`${m.name} rejected (${n}ms)`),n)),e&&!e.aborted&&(i.abort=()=>c(e.reason),e.addEventListener("abort",i.abort))})}exports.el=y;exports.nbsp=v;exports.observeElement=d;exports.text=r;exports.waitElement=m;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/html.ts","../src/observe-element.ts","../src/wait-element.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/html.ts","../src/observe-element.ts","../src/wait-element.ts"],"sourcesContent":["import type CSS from 'csstype'\n\n// prettier-ignore\ntype Properties<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: CSS.Properties\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype ChildElement = string | Node | HTMLElement\ntype Childrens = ChildElement[]\n\n/**\n * Creates a new HTML element of the specified type and with the given attributes and children nodes.\n *\n * @param {T} tag\n * The type of HTML element to create.\n *\n * @param {Properties<T> | Childrens | ChildElement} [props]\n * The properties or children nodes to add to the element.\n *\n * @param {Childrens | ChildElement} [children]\n * The children nodes to add to the element.\n *\n * @return {HTMLElementTagNameMap[T]}\n * The newly created HTML element of the specified type.\n *\n * @example\n * el('div', { id: 'foo' }, 'Hello world')\n * el('div', 'Hello world')\n * el('div', [el('span', 'Hello'), el('span', 'world')])\n * el('div', el('span', 'Hello world'))\n * el('div', el('span', 'Hello'), el('span', 'world'))\n * el('div', el('span', 'Hello world'), 'world')\n * el('div', { id: 'foo' }, [el('span', 'Hello'), el('span', 'world')])\n */\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n props?: Properties<T> | Childrens | ChildElement,\n children?: Childrens | ChildElement\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (props instanceof Node) {\n el.append(props)\n } else if (typeof props === 'string') {\n el.append(text(props))\n } else if (Array.isArray(props)) {\n el.append(...props)\n } else if (props) {\n Object.assign(el, props)\n Object.assign(el.style, props?.style)\n }\n\n if (children !== undefined) {\n if (Array.isArray(children)) {\n el.append(...children)\n } else if (children instanceof Node) {\n el.append(children)\n } else if (typeof children === 'string') {\n el.append(text(children))\n }\n }\n\n return el\n}\n\n/**\n * Creates a new Text node with the provided text.\n *\n * @param {string} text\n * The text to create the Text node with.\n *\n * @return {Text}\n * A new Text node with the provided text.\n */\nexport function text(text: string): Text {\n return document.createTextNode(text)\n}\n\n/**\n * Returns a Text object containing a non-breaking space character.\n *\n * @return {Text}\n * A Text object containing a non-breaking space character.\n */\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n","type Disconnect = () => void\n\n/**\n * Observes changes to an element and invokes a callback function for each mutation.\n *\n * @param {T extends Element} el\n * The element to observe.\n *\n * @param {(mutation: MutationRecord, observer: MutationObserver) => void} callback\n * The function to call when a mutation occurs.\n *\n * @param {MutationObserverInit} [options]\n * Optional configuration options for the MutationObserver.\n *\n * @returns {Disconnect}\n * A function that disconnects the observer.\n *\n * @example\n * const disconnect = observeElement(document.body, (mutation, observer) => {\n * console.log(mutation)\n * })\n */\nexport function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n): Disconnect {\n const observe = new MutationObserver((mutations, observer) => {\n for (const mutation of mutations) {\n callback(mutation, observer)\n }\n })\n\n observe.observe(el, {\n childList: true,\n subtree: true,\n ...options\n })\n\n return () => observe.disconnect()\n}\n","import { observeElement } from './observe-element.js'\n\nexport interface WaitElementParams {\n selector: string\n target?: Element\n rejectTimeoutMs?: number\n signal?: AbortSignal\n}\n\n/**\n * Waits for the specified element to be present in the DOM and returns it.\n *\n * @param {WaitElementParams} params\n * The parameters for waiting and locating the element.\n *\n * @param {string} params.selector\n * The CSS selector to locate the element.\n *\n * @param {Element} [params.target=document.body]\n * The target element to search for the element in.\n *\n * @param {number} [params.rejectTimeoutMs]\n * The timeout in milliseconds after which the promise is rejected.\n *\n * @param {AbortSignal} [params.signal]\n * An optional AbortSignal instance to abort the waiting.\n *\n * @return {Promise<T>}\n * A promise that resolves with the found element.\n *\n * @throws {Error}\n * If the promise is rejected due to the element not being found within the specified time.\n *\n * @example\n * const fooElement = await waitElement({ selector: '.foo' })\n */\nexport function waitElement<T extends Element = Element>({\n selector,\n target = document.body,\n rejectTimeoutMs,\n signal\n}: WaitElementParams): Promise<T> {\n return new Promise((resolve, reject) => {\n const disconnect = observeElement(target, (_, observer) => {\n const el = target.querySelector<T>(selector)\n if (el) {\n observer.disconnect()\n resolve(el)\n }\n })\n\n const listeners: {\n timeout: ReturnType<typeof setTimeout> | null\n abort: (() => void) | null\n } = {\n timeout: null,\n abort: null\n }\n\n const dispose = (message: string) => {\n if (listeners.timeout) {\n clearTimeout(listeners.timeout)\n }\n\n if (listeners.abort) {\n signal.removeEventListener('abort', listeners.abort)\n }\n\n disconnect()\n reject(message)\n }\n\n if (rejectTimeoutMs > 0) {\n listeners.timeout = setTimeout(\n () => dispose(`${waitElement.name} rejected (${rejectTimeoutMs}ms)`),\n rejectTimeoutMs\n )\n }\n\n if (signal && !signal.aborted) {\n listeners.abort = () => dispose(signal.reason)\n signal.addEventListener('abort', listeners.abort)\n }\n })\n}\n"],"names":["el","tag","props","children","text","nbsp","observeElement","callback","options","observe","mutations","observer","mutation","waitElement","selector","target","rejectTimeoutMs","signal","resolve","reject","disconnect","_","listeners","dispose","message"],"mappings":"gFAkCgB,SAAAA,EACdC,EACAC,EACAC,EAC0B,CACpBH,MAAAA,EAAK,SAAS,cAAcC,CAAG,EAErC,OAAIC,aAAiB,KACnBF,EAAG,OAAOE,CAAK,EACN,OAAOA,GAAU,SAC1BF,EAAG,OAAOI,EAAKF,CAAK,CAAC,EACZ,MAAM,QAAQA,CAAK,EAC5BF,EAAG,OAAO,GAAGE,CAAK,EACTA,IACF,OAAA,OAAOF,EAAIE,CAAK,EACvB,OAAO,OAAOF,EAAG,MAAOE,GAAO,KAAK,GAGlCC,IAAa,SACX,MAAM,QAAQA,CAAQ,EACxBH,EAAG,OAAO,GAAGG,CAAQ,EACZA,aAAoB,KAC7BH,EAAG,OAAOG,CAAQ,EACT,OAAOA,GAAa,UAC7BH,EAAG,OAAOI,EAAKD,CAAQ,CAAC,GAIrBH,CACT,CAWO,SAASI,EAAKA,EAAoB,CAChC,OAAA,SAAS,eAAeA,CAAI,CACrC,CAQO,SAASC,GAAa,CAC3B,OAAOD,EAAK,GAAQ,CACtB,CChEgB,SAAAE,EACdN,EACAO,EACAC,EACY,CACZ,MAAMC,EAAU,IAAI,iBAAiB,CAACC,EAAWC,IAAa,CAC5D,UAAWC,KAAYF,EACrBH,EAASK,EAAUD,CAAQ,CAC7B,CACD,EAED,OAAAF,EAAQ,QAAQT,EAAI,CAClB,UAAW,GACX,QAAS,GACT,GAAGQ,CAAA,CACJ,EAEM,IAAMC,EAAQ,YACvB,CCJO,SAASI,EAAyC,CACvD,SAAAC,EACA,OAAAC,EAAS,SAAS,KAClB,gBAAAC,EACA,OAAAC,CACF,EAAkC,CAChC,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACtC,MAAMC,EAAad,EAAeS,EAAQ,CAACM,EAAGV,IAAa,CACnD,MAAAX,EAAKe,EAAO,cAAiBD,CAAQ,EACvCd,IACFW,EAAS,WAAW,EACpBO,EAAQlB,CAAE,EACZ,CACD,EAEKsB,EAGF,CACF,QAAS,KACT,MAAO,IAAA,EAGHC,EAAWC,GAAoB,CAC/BF,EAAU,SACZ,aAAaA,EAAU,OAAO,EAG5BA,EAAU,OACLL,EAAA,oBAAoB,QAASK,EAAU,KAAK,EAG1CF,IACXD,EAAOK,CAAO,CAAA,EAGZR,EAAkB,IACpBM,EAAU,QAAU,WAClB,IAAMC,EAAQ,GAAGV,EAAY,IAAI,cAAcG,CAAe,KAAK,EACnEA,CAAA,GAIAC,GAAU,CAACA,EAAO,UACpBK,EAAU,MAAQ,IAAMC,EAAQN,EAAO,MAAM,EACtCA,EAAA,iBAAiB,QAASK,EAAU,KAAK,EAClD,CACD,CACH"}
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
function
|
|
2
|
-
const e = document.createElement(
|
|
3
|
-
return t instanceof Node ? e.append(t) : typeof t == "string" ? e.append(
|
|
1
|
+
function y(o, t, n) {
|
|
2
|
+
const e = document.createElement(o);
|
|
3
|
+
return t instanceof Node ? e.append(t) : typeof t == "string" ? e.append(u(t)) : Array.isArray(t) ? e.append(...t) : t && (Object.assign(e, t), Object.assign(e.style, t?.style)), n !== void 0 && (Array.isArray(n) ? e.append(...n) : n instanceof Node ? e.append(n) : typeof n == "string" && e.append(u(n))), e;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return document.createTextNode(
|
|
5
|
+
function u(o) {
|
|
6
|
+
return document.createTextNode(o);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return
|
|
8
|
+
function v() {
|
|
9
|
+
return u(" ");
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
const e = new MutationObserver((
|
|
13
|
-
for (const
|
|
14
|
-
t(
|
|
11
|
+
function m(o, t, n) {
|
|
12
|
+
const e = new MutationObserver((r, s) => {
|
|
13
|
+
for (const a of r)
|
|
14
|
+
t(a, s);
|
|
15
15
|
});
|
|
16
|
-
return e.observe(
|
|
16
|
+
return e.observe(o, {
|
|
17
17
|
childList: !0,
|
|
18
18
|
subtree: !0,
|
|
19
|
-
...
|
|
19
|
+
...n
|
|
20
20
|
}), () => e.disconnect();
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
selector:
|
|
22
|
+
function l({
|
|
23
|
+
selector: o,
|
|
24
24
|
target: t = document.body,
|
|
25
|
-
rejectTimeoutMs:
|
|
25
|
+
rejectTimeoutMs: n,
|
|
26
26
|
signal: e
|
|
27
27
|
}) {
|
|
28
|
-
return new Promise((
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
}),
|
|
28
|
+
return new Promise((r, s) => {
|
|
29
|
+
const a = m(t, (c, d) => {
|
|
30
|
+
const b = t.querySelector(o);
|
|
31
|
+
b && (d.disconnect(), r(b));
|
|
32
|
+
}), i = {
|
|
33
33
|
timeout: null,
|
|
34
34
|
abort: null
|
|
35
|
-
},
|
|
36
|
-
|
|
35
|
+
}, f = (c) => {
|
|
36
|
+
i.timeout && clearTimeout(i.timeout), i.abort && e.removeEventListener("abort", i.abort), a(), s(c);
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
() =>
|
|
40
|
-
|
|
41
|
-
)), e && !e.aborted && (
|
|
38
|
+
n > 0 && (i.timeout = setTimeout(
|
|
39
|
+
() => f(`${l.name} rejected (${n}ms)`),
|
|
40
|
+
n
|
|
41
|
+
)), e && !e.aborted && (i.abort = () => f(e.reason), e.addEventListener("abort", i.abort));
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
export {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
y as el,
|
|
46
|
+
v as nbsp,
|
|
47
|
+
m as observeElement,
|
|
48
|
+
u as text,
|
|
49
|
+
l as waitElement
|
|
50
50
|
};
|
|
51
51
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/html.ts","../src/observe-element.ts","../src/wait-element.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/html.ts","../src/observe-element.ts","../src/wait-element.ts"],"sourcesContent":["import type CSS from 'csstype'\n\n// prettier-ignore\ntype Properties<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: CSS.Properties\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype ChildElement = string | Node | HTMLElement\ntype Childrens = ChildElement[]\n\n/**\n * Creates a new HTML element of the specified type and with the given attributes and children nodes.\n *\n * @param {T} tag\n * The type of HTML element to create.\n *\n * @param {Properties<T> | Childrens | ChildElement} [props]\n * The properties or children nodes to add to the element.\n *\n * @param {Childrens | ChildElement} [children]\n * The children nodes to add to the element.\n *\n * @return {HTMLElementTagNameMap[T]}\n * The newly created HTML element of the specified type.\n *\n * @example\n * el('div', { id: 'foo' }, 'Hello world')\n * el('div', 'Hello world')\n * el('div', [el('span', 'Hello'), el('span', 'world')])\n * el('div', el('span', 'Hello world'))\n * el('div', el('span', 'Hello'), el('span', 'world'))\n * el('div', el('span', 'Hello world'), 'world')\n * el('div', { id: 'foo' }, [el('span', 'Hello'), el('span', 'world')])\n */\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n props?: Properties<T> | Childrens | ChildElement,\n children?: Childrens | ChildElement\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (props instanceof Node) {\n el.append(props)\n } else if (typeof props === 'string') {\n el.append(text(props))\n } else if (Array.isArray(props)) {\n el.append(...props)\n } else if (props) {\n Object.assign(el, props)\n Object.assign(el.style, props?.style)\n }\n\n if (children !== undefined) {\n if (Array.isArray(children)) {\n el.append(...children)\n } else if (children instanceof Node) {\n el.append(children)\n } else if (typeof children === 'string') {\n el.append(text(children))\n }\n }\n\n return el\n}\n\n/**\n * Creates a new Text node with the provided text.\n *\n * @param {string} text\n * The text to create the Text node with.\n *\n * @return {Text}\n * A new Text node with the provided text.\n */\nexport function text(text: string): Text {\n return document.createTextNode(text)\n}\n\n/**\n * Returns a Text object containing a non-breaking space character.\n *\n * @return {Text}\n * A Text object containing a non-breaking space character.\n */\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n","type Disconnect = () => void\n\n/**\n * Observes changes to an element and invokes a callback function for each mutation.\n *\n * @param {T extends Element} el\n * The element to observe.\n *\n * @param {(mutation: MutationRecord, observer: MutationObserver) => void} callback\n * The function to call when a mutation occurs.\n *\n * @param {MutationObserverInit} [options]\n * Optional configuration options for the MutationObserver.\n *\n * @returns {Disconnect}\n * A function that disconnects the observer.\n *\n * @example\n * const disconnect = observeElement(document.body, (mutation, observer) => {\n * console.log(mutation)\n * })\n */\nexport function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n): Disconnect {\n const observe = new MutationObserver((mutations, observer) => {\n for (const mutation of mutations) {\n callback(mutation, observer)\n }\n })\n\n observe.observe(el, {\n childList: true,\n subtree: true,\n ...options\n })\n\n return () => observe.disconnect()\n}\n","import { observeElement } from './observe-element.js'\n\nexport interface WaitElementParams {\n selector: string\n target?: Element\n rejectTimeoutMs?: number\n signal?: AbortSignal\n}\n\n/**\n * Waits for the specified element to be present in the DOM and returns it.\n *\n * @param {WaitElementParams} params\n * The parameters for waiting and locating the element.\n *\n * @param {string} params.selector\n * The CSS selector to locate the element.\n *\n * @param {Element} [params.target=document.body]\n * The target element to search for the element in.\n *\n * @param {number} [params.rejectTimeoutMs]\n * The timeout in milliseconds after which the promise is rejected.\n *\n * @param {AbortSignal} [params.signal]\n * An optional AbortSignal instance to abort the waiting.\n *\n * @return {Promise<T>}\n * A promise that resolves with the found element.\n *\n * @throws {Error}\n * If the promise is rejected due to the element not being found within the specified time.\n *\n * @example\n * const fooElement = await waitElement({ selector: '.foo' })\n */\nexport function waitElement<T extends Element = Element>({\n selector,\n target = document.body,\n rejectTimeoutMs,\n signal\n}: WaitElementParams): Promise<T> {\n return new Promise((resolve, reject) => {\n const disconnect = observeElement(target, (_, observer) => {\n const el = target.querySelector<T>(selector)\n if (el) {\n observer.disconnect()\n resolve(el)\n }\n })\n\n const listeners: {\n timeout: ReturnType<typeof setTimeout> | null\n abort: (() => void) | null\n } = {\n timeout: null,\n abort: null\n }\n\n const dispose = (message: string) => {\n if (listeners.timeout) {\n clearTimeout(listeners.timeout)\n }\n\n if (listeners.abort) {\n signal.removeEventListener('abort', listeners.abort)\n }\n\n disconnect()\n reject(message)\n }\n\n if (rejectTimeoutMs > 0) {\n listeners.timeout = setTimeout(\n () => dispose(`${waitElement.name} rejected (${rejectTimeoutMs}ms)`),\n rejectTimeoutMs\n )\n }\n\n if (signal && !signal.aborted) {\n listeners.abort = () => dispose(signal.reason)\n signal.addEventListener('abort', listeners.abort)\n }\n })\n}\n"],"names":["el","tag","props","children","text","nbsp","observeElement","callback","options","observe","mutations","observer","mutation","waitElement","selector","target","rejectTimeoutMs","signal","resolve","reject","disconnect","_","listeners","dispose","message"],"mappings":"AAkCgB,SAAAA,EACdC,GACAC,GACAC,GAC0B;AACpBH,QAAAA,IAAK,SAAS,cAAcC,CAAG;AAErC,SAAIC,aAAiB,OACnBF,EAAG,OAAOE,CAAK,IACN,OAAOA,KAAU,WAC1BF,EAAG,OAAOI,EAAKF,CAAK,CAAC,IACZ,MAAM,QAAQA,CAAK,IAC5BF,EAAG,OAAO,GAAGE,CAAK,IACTA,MACF,OAAA,OAAOF,GAAIE,CAAK,GACvB,OAAO,OAAOF,EAAG,OAAOE,GAAO,KAAK,IAGlCC,MAAa,WACX,MAAM,QAAQA,CAAQ,IACxBH,EAAG,OAAO,GAAGG,CAAQ,IACZA,aAAoB,OAC7BH,EAAG,OAAOG,CAAQ,IACT,OAAOA,KAAa,YAC7BH,EAAG,OAAOI,EAAKD,CAAQ,CAAC,IAIrBH;AACT;AAWO,SAASI,EAAKA,GAAoB;AAChC,SAAA,SAAS,eAAeA,CAAI;AACrC;AAQO,SAASC,IAAa;AAC3B,SAAOD,EAAK,GAAQ;AACtB;AChEgB,SAAAE,EACdN,GACAO,GACAC,GACY;AACZ,QAAMC,IAAU,IAAI,iBAAiB,CAACC,GAAWC,MAAa;AAC5D,eAAWC,KAAYF;AACrB,MAAAH,EAASK,GAAUD,CAAQ;AAAA,EAC7B,CACD;AAED,SAAAF,EAAQ,QAAQT,GAAI;AAAA,IAClB,WAAW;AAAA,IACX,SAAS;AAAA,IACT,GAAGQ;AAAA,EAAA,CACJ,GAEM,MAAMC,EAAQ;AACvB;ACJO,SAASI,EAAyC;AAAA,EACvD,UAAAC;AAAA,EACA,QAAAC,IAAS,SAAS;AAAA,EAClB,iBAAAC;AAAA,EACA,QAAAC;AACF,GAAkC;AAChC,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,UAAMC,IAAad,EAAeS,GAAQ,CAACM,GAAGV,MAAa;AACnD,YAAAX,IAAKe,EAAO,cAAiBD,CAAQ;AAC3C,MAAId,MACFW,EAAS,WAAW,GACpBO,EAAQlB,CAAE;AAAA,IACZ,CACD,GAEKsB,IAGF;AAAA,MACF,SAAS;AAAA,MACT,OAAO;AAAA,IAAA,GAGHC,IAAU,CAACC,MAAoB;AACnC,MAAIF,EAAU,WACZ,aAAaA,EAAU,OAAO,GAG5BA,EAAU,SACLL,EAAA,oBAAoB,SAASK,EAAU,KAAK,GAG1CF,KACXD,EAAOK,CAAO;AAAA,IAAA;AAGhB,IAAIR,IAAkB,MACpBM,EAAU,UAAU;AAAA,MAClB,MAAMC,EAAQ,GAAGV,EAAY,IAAI,cAAcG,CAAe,KAAK;AAAA,MACnEA;AAAA,IAAA,IAIAC,KAAU,CAACA,EAAO,YACpBK,EAAU,QAAQ,MAAMC,EAAQN,EAAO,MAAM,GACtCA,EAAA,iBAAiB,SAASK,EAAU,KAAK;AAAA,EAClD,CACD;AACH;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type LocationCallback<T = any> = (location: Location, args: T) => void;
|
|
2
|
+
type Events<T> = {
|
|
3
|
+
onPush: LocationCallback<T>;
|
|
4
|
+
onReplace: LocationCallback<T>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Observes changes to the browser's location and history, and invokes
|
|
8
|
+
* the specified callbacks when the user navigates to a new page or updates the
|
|
9
|
+
* current page's state.
|
|
10
|
+
*
|
|
11
|
+
* @param {Events<T>} events
|
|
12
|
+
* An object that contains optional callback functions for push and replace actions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* locationObserver<{ id: string }>({
|
|
16
|
+
* onPush: (location, args) => {},
|
|
17
|
+
* onReplace: (location, args) => {}
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
export declare function locationObserver<T>(events: Events<T>): void;
|
|
21
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zero-dependency/dom",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "DOM utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -37,19 +37,19 @@
|
|
|
37
37
|
"url": "https://crashmax.ru"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@crashmax/prettier-config": "
|
|
41
|
-
"@crashmax/tsconfig": "2.0
|
|
42
|
-
"@types/node": "
|
|
43
|
-
"@vitest/coverage-
|
|
44
|
-
"@vitest/ui": "
|
|
45
|
-
"jsdom": "
|
|
46
|
-
"typescript": "5.
|
|
47
|
-
"vite": "
|
|
48
|
-
"vite-plugin-dts": "
|
|
49
|
-
"vitest": "
|
|
40
|
+
"@crashmax/prettier-config": "5.0.1",
|
|
41
|
+
"@crashmax/tsconfig": "2.1.0",
|
|
42
|
+
"@types/node": "20.11.10",
|
|
43
|
+
"@vitest/coverage-v8": "1.2.2",
|
|
44
|
+
"@vitest/ui": "1.2.2",
|
|
45
|
+
"jsdom": "24.0.0",
|
|
46
|
+
"typescript": "5.3.3",
|
|
47
|
+
"vite": "5.0.12",
|
|
48
|
+
"vite-plugin-dts": "3.7.2",
|
|
49
|
+
"vitest": "1.2.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"csstype": "3.1.
|
|
52
|
+
"csstype": "3.1.3"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"dev": "vite build --watch",
|