@zero-dependency/dom 0.11.0 → 0.12.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.
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ function el(tag, attributes, ...children) {
6
+ const el2 = document.createElement(tag);
7
+ if (typeof attributes === "string") {
8
+ el2.append(text(attributes));
9
+ } else if (Array.isArray(attributes)) {
10
+ el2.append(...attributes);
11
+ } else {
12
+ Object.assign(el2, attributes);
13
+ Object.assign(el2.style, attributes?.style);
14
+ }
15
+ if (children.length) {
16
+ el2.append(...children);
17
+ }
18
+ return el2;
19
+ }
20
+ function text(str) {
21
+ return document.createTextNode(str);
22
+ }
23
+ function nbsp() {
24
+ return text("\xA0");
25
+ }
26
+ async function domReady() {
27
+ return new Promise((resolve) => {
28
+ if (document.readyState == "loading") {
29
+ document.addEventListener("DOMContentLoaded", () => resolve(), {
30
+ once: true
31
+ });
32
+ } else {
33
+ resolve();
34
+ }
35
+ });
36
+ }
37
+
38
+ function observeElement(el, callback, options) {
39
+ const observe = new MutationObserver((mutations, observer) => {
40
+ for (const mutation of mutations) {
41
+ callback(mutation, observer);
42
+ }
43
+ });
44
+ observe.observe(el, {
45
+ childList: true,
46
+ subtree: true,
47
+ ...options
48
+ });
49
+ return observe;
50
+ }
51
+
52
+ function waitElement(selector, target = document.documentElement) {
53
+ return new Promise((resolve) => {
54
+ function resolveElement() {
55
+ const el = target.querySelector(selector);
56
+ if (el) {
57
+ resolve(el);
58
+ }
59
+ }
60
+ observeElement(target, (_, observer) => {
61
+ resolveElement();
62
+ observer.disconnect();
63
+ });
64
+ });
65
+ }
66
+
67
+ class n {
68
+ #t = {};
69
+ on(t, e) {
70
+ const s = this.#t[t];
71
+ return s ? s.push(e) : this.#t[t] = [e], this;
72
+ }
73
+ addListener(t, e) {
74
+ return this.on(t, e);
75
+ }
76
+ once(t, e) {
77
+ const s = (...i) => {
78
+ this.off(t, s), e(...i);
79
+ };
80
+ return this.on(t, s), this;
81
+ }
82
+ emit(t, ...e) {
83
+ const s = this.#t[t] || [];
84
+ for (let i = 0; i < s.length; i++)
85
+ s[i](...e);
86
+ return Boolean(s.length);
87
+ }
88
+ off(t, e) {
89
+ return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;
90
+ }
91
+ removeListener(t, e) {
92
+ return this.off(t, e);
93
+ }
94
+ removeAllListeners(t) {
95
+ return t ? delete this.#t[t] : this.#t = {}, this;
96
+ }
97
+ eventNames() {
98
+ return Reflect.ownKeys(this.#t);
99
+ }
100
+ listeners(t) {
101
+ return this.#t[t];
102
+ }
103
+ listenerCount(t) {
104
+ return this.#t[t]?.length ?? 0;
105
+ }
106
+ }
107
+
108
+ class LocationObserver extends n {
109
+ constructor() {
110
+ super();
111
+ const { history, location } = window;
112
+ const { pushState, replaceState } = history;
113
+ history.pushState = (...args) => {
114
+ pushState.apply(history, args);
115
+ this.emit("pushState", location, args[0]);
116
+ };
117
+ history.replaceState = (...args) => {
118
+ replaceState.apply(history, args);
119
+ this.emit("replaceState", location, args[0]);
120
+ };
121
+ window.addEventListener("popstate", ({ state }) => {
122
+ this.emit("popState", location, state);
123
+ });
124
+ }
125
+ }
126
+
127
+ exports.LocationObserver = LocationObserver;
128
+ exports.domReady = domReady;
129
+ exports.el = el;
130
+ exports.nbsp = nbsp;
131
+ exports.observeElement = observeElement;
132
+ exports.text = text;
133
+ exports.waitElement = waitElement;
134
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/html.ts","../src/observeElement.ts","../src/waitElement.ts","../node_modules/.pnpm/@zero-dependency+emitter@1.1.1/node_modules/@zero-dependency/emitter/dist/index.es.js","../src/locationObserver.ts"],"sourcesContent":["// prettier-ignore\ntype Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: Partial<CSSStyleDeclaration>\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype Children = (string | Node | HTMLElement)[]\n\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n attributes?: Children | Attributes<T>,\n ...children: Children\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (typeof attributes === 'string') {\n el.append(text(attributes))\n } else if (Array.isArray(attributes)) {\n el.append(...attributes)\n } else {\n Object.assign(el, attributes)\n Object.assign(el.style, attributes?.style)\n }\n\n if (children.length) {\n el.append(...children)\n }\n\n return el\n}\n\nexport function text(str: string): Text {\n return document.createTextNode(str)\n}\n\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n\nexport async function domReady(): Promise<void> {\n return new Promise((resolve) => {\n if (document.readyState == 'loading') {\n document.addEventListener('DOMContentLoaded', () => resolve(), {\n once: true\n })\n } else {\n resolve()\n }\n })\n}\n","export function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n) {\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\n}\n","import { observeElement } from './observeElement.js'\n\nexport function waitElement<T extends Element = Element>(\n selector: string,\n target = document.documentElement\n): Promise<T> {\n return new Promise((resolve) => {\n function resolveElement() {\n const el = target.querySelector<T>(selector)\n if (el) {\n resolve(el)\n }\n }\n\n observeElement(target, (_, observer) => {\n resolveElement()\n observer.disconnect()\n })\n })\n}\n","class n {\n #t = {};\n on(t, e) {\n const s = this.#t[t];\n return s ? s.push(e) : this.#t[t] = [e], this;\n }\n addListener(t, e) {\n return this.on(t, e);\n }\n once(t, e) {\n const s = (...i) => {\n this.off(t, s), e(...i);\n };\n return this.on(t, s), this;\n }\n emit(t, ...e) {\n const s = this.#t[t] || [];\n for (let i = 0; i < s.length; i++)\n s[i](...e);\n return Boolean(s.length);\n }\n off(t, e) {\n return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;\n }\n removeListener(t, e) {\n return this.off(t, e);\n }\n removeAllListeners(t) {\n return t ? delete this.#t[t] : this.#t = {}, this;\n }\n eventNames() {\n return Reflect.ownKeys(this.#t);\n }\n listeners(t) {\n return this.#t[t];\n }\n listenerCount(t) {\n return this.#t[t]?.length ?? 0;\n }\n}\nexport {\n n as Emitter\n};\n//# sourceMappingURL=index.es.js.map\n","import { Emitter } from '@zero-dependency/emitter'\n\ntype LocationCallback = (location: Location, state: any) => void\n\ntype Events = {\n pushState: LocationCallback\n replaceState: LocationCallback\n popState: LocationCallback\n}\n\nexport class LocationObserver extends Emitter<Events> {\n constructor() {\n super()\n\n const { history, location } = window\n const { pushState, replaceState } = history\n\n history.pushState = (...args) => {\n pushState.apply(history, args)\n this.emit('pushState', location, args[0])\n }\n\n history.replaceState = (...args) => {\n replaceState.apply(history, args)\n this.emit('replaceState', location, args[0])\n }\n\n window.addEventListener('popstate', ({ state }) => {\n this.emit('popState', location, state)\n })\n }\n}\n"],"names":["el","Emitter"],"mappings":";;;;AAOgB,SAAA,EAAA,CACd,GACA,EAAA,UAAA,EAAA,GACG,QACuB,EAAA;AAC1B,EAAMA,MAAAA,GAAAA,GAAK,QAAS,CAAA,aAAA,CAAc,GAAG,CAAA,CAAA;AAErC,EAAI,IAAA,OAAO,eAAe,QAAU,EAAA;AAClC,IAAAA,GAAG,CAAA,MAAA,CAAO,IAAK,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,GACjB,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,UAAU,CAAG,EAAA;AACpC,IAAAA,GAAAA,CAAG,MAAO,CAAA,GAAG,UAAU,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAO,MAAA,CAAA,MAAA,CAAOA,KAAI,UAAU,CAAA,CAAA;AAC5B,IAAA,MAAA,CAAO,MAAOA,CAAAA,GAAAA,CAAG,KAAO,EAAA,UA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AAI,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AACnC,GAAG;AACH;;AC7BO,MAAM,yBAAyBC,CAAgB,CAAA;AAAA,EACpD,WAAc,GAAA;AACZ,IAAM,KAAA,EAAA,CAAA;AAEN,IAAM,MAAA,EAAE,OAAS,EAAA,QAAA,EAAa,GAAA,MAAA,CAAA;AAC9B,IAAM,MAAA,EAAE,SAAW,EAAA,YAAA,EAAiB,GAAA,OAAA,CAAA;AAEpC,IAAQ,OAAA,CAAA,SAAA,GAAY,IAAI,IAAS,KAAA;AAC/B,MAAU,SAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;AAC7B,MAAA,IAAA,CAAK,IAAK,CAAA,WAAA,EAAa,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;AAAA,KAC1C,CAAA;AAEA,IAAQ,OAAA,CAAA,YAAA,GAAe,IAAI,IAAS,KAAA;AAClC,MAAa,YAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;AAChC,MAAA,IAAA,CAAK,IAAK,CAAA,cAAA,EAAgB,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;AAAA,KAC7C,CAAA;AAEA,IAAA,MAAA,CAAO,gBAAiB,CAAA,UAAA,EAAY,CAAC,EAAE,OAAY,KAAA;AACjD,MAAK,IAAA,CAAA,IAAA,CAAK,UAAY,EAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AAAA,KACtC,CAAA,CAAA;AAAA,GACH;AACF;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { el, text, nbsp, domReady } from './html.js';
2
- export { fetcher, Fetcher, FetcherError } from './fetcher.js';
3
2
  export { waitElement } from './waitElement.js';
4
- export { locationObserver } from './locationObserver.js';
3
+ export { LocationObserver } from './locationObserver.js';
5
4
  export { observeElement } from './observeElement.js';
package/dist/index.es.js CHANGED
@@ -1,165 +1,124 @@
1
- function y(r, e, ...t) {
2
- const n = document.createElement(r);
3
- return typeof e == "string" ? n.append(i(e)) : Array.isArray(e) ? n.append(...e) : (Object.assign(n, e), Object.assign(n.style, e?.style)), t.length && n.append(...t), n;
1
+ function el(tag, attributes, ...children) {
2
+ const el2 = document.createElement(tag);
3
+ if (typeof attributes === "string") {
4
+ el2.append(text(attributes));
5
+ } else if (Array.isArray(attributes)) {
6
+ el2.append(...attributes);
7
+ } else {
8
+ Object.assign(el2, attributes);
9
+ Object.assign(el2.style, attributes?.style);
10
+ }
11
+ if (children.length) {
12
+ el2.append(...children);
13
+ }
14
+ return el2;
4
15
  }
5
- function i(r) {
6
- return document.createTextNode(r);
16
+ function text(str) {
17
+ return document.createTextNode(str);
7
18
  }
8
- function E() {
9
- return i("\xA0");
19
+ function nbsp() {
20
+ return text("\xA0");
10
21
  }
11
- async function v() {
12
- return new Promise((r) => {
13
- document.readyState == "loading" ? document.addEventListener("DOMContentLoaded", () => r(), {
14
- once: !0
15
- }) : r();
22
+ async function domReady() {
23
+ return new Promise((resolve) => {
24
+ if (document.readyState == "loading") {
25
+ document.addEventListener("DOMContentLoaded", () => resolve(), {
26
+ once: true
27
+ });
28
+ } else {
29
+ resolve();
30
+ }
16
31
  });
17
32
  }
18
- const u = [
19
- "GET",
20
- "POST",
21
- "PUT",
22
- "PATCH",
23
- "DELETE"
24
- ];
25
- class c {
26
- constructor(e, t) {
27
- this.baseURL = e, this.baseInit = t;
28
- for (const n of u)
29
- this[n.toLowerCase()] = (s, o) => this.request(s, { ...o, method: n });
30
- }
31
- get;
32
- post;
33
- put;
34
- patch;
35
- delete;
36
- extends(e, t) {
37
- const { url: n, init: s } = this.fetcherParameters(e, t);
38
- return new c(n, s);
39
- }
40
- async request(e, t) {
41
- const { url: n, init: s } = this.fetcherParameters(e, t);
42
- return await h(n, s);
43
- }
44
- fetcherParameters(e, t) {
45
- const n = d(this.baseURL, e), s = f(this.baseInit?.headers, t?.headers), o = { ...this.baseInit, ...t, headers: s };
46
- return { url: n, init: o };
47
- }
48
- }
49
- async function h(...r) {
50
- const e = await fetch(...r), t = await e.json();
51
- if (e.ok)
52
- return t;
53
- throw new l({
54
- response: e,
55
- data: t
33
+
34
+ function observeElement(el, callback, options) {
35
+ const observe = new MutationObserver((mutations, observer) => {
36
+ for (const mutation of mutations) {
37
+ callback(mutation, observer);
38
+ }
56
39
  });
57
- }
58
- class l extends Error {
59
- response;
60
- data;
61
- constructor({ response: e, data: t }) {
62
- super(e.statusText), this.name = "FetcherError", this.response = e, this.data = t;
63
- }
64
- }
65
- function d(r, e) {
66
- return e ? r.replace(/\/+$/, "") + "/" + e.replace(/^\/+/, "") : r;
67
- }
68
- function f(...r) {
69
- const e = {};
70
- for (const t of r) {
71
- const n = new Headers(t);
72
- for (const [s, o] of n.entries())
73
- o == null ? delete e[s] : e[s] = o;
74
- }
75
- return new Headers(e);
76
- }
77
- function p(r, e, t) {
78
- const n = new MutationObserver((s, o) => {
79
- for (const a of s)
80
- e(a, o);
40
+ observe.observe(el, {
41
+ childList: true,
42
+ subtree: true,
43
+ ...options
81
44
  });
82
- return n.observe(r, {
83
- childList: !0,
84
- subtree: !0,
85
- ...t
86
- }), n;
45
+ return observe;
87
46
  }
88
- function L(r, e = document.documentElement) {
89
- return new Promise((t) => {
90
- function n() {
91
- const s = e.querySelector(r);
92
- s && t(s);
47
+
48
+ function waitElement(selector, target = document.documentElement) {
49
+ return new Promise((resolve) => {
50
+ function resolveElement() {
51
+ const el = target.querySelector(selector);
52
+ if (el) {
53
+ resolve(el);
54
+ }
93
55
  }
94
- p(e, (s, o) => {
95
- n(), o.disconnect();
56
+ observeElement(target, (_, observer) => {
57
+ resolveElement();
58
+ observer.disconnect();
96
59
  });
97
60
  });
98
61
  }
99
- class m {
100
- #e = {};
101
- on(e, t) {
102
- const n = this.#e[e];
103
- return n ? n.push(t) : this.#e[e] = [t], this;
104
- }
105
- addListener(e, t) {
106
- return this.on(e, t);
107
- }
108
- once(e, t) {
109
- const n = (...s) => {
110
- this.off(e, n), t(...s);
62
+
63
+ class n {
64
+ #t = {};
65
+ on(t, e) {
66
+ const s = this.#t[t];
67
+ return s ? s.push(e) : this.#t[t] = [e], this;
68
+ }
69
+ addListener(t, e) {
70
+ return this.on(t, e);
71
+ }
72
+ once(t, e) {
73
+ const s = (...i) => {
74
+ this.off(t, s), e(...i);
111
75
  };
112
- return this.on(e, n), this;
76
+ return this.on(t, s), this;
113
77
  }
114
- emit(e, ...t) {
115
- const n = this.#e[e] || [];
116
- for (let s = 0; s < n.length; s++)
117
- n[s](...t);
118
- return Boolean(n.length);
78
+ emit(t, ...e) {
79
+ const s = this.#t[t] || [];
80
+ for (let i = 0; i < s.length; i++)
81
+ s[i](...e);
82
+ return Boolean(s.length);
119
83
  }
120
- off(e, t) {
121
- return this.#e[e] && (this.#e[e] = this.#e[e].filter((n) => n !== t)), this;
84
+ off(t, e) {
85
+ return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;
122
86
  }
123
- removeListener(e, t) {
124
- return this.off(e, t);
87
+ removeListener(t, e) {
88
+ return this.off(t, e);
125
89
  }
126
- removeAllListeners(e) {
127
- return e ? delete this.#e[e] : this.#e = {}, this;
90
+ removeAllListeners(t) {
91
+ return t ? delete this.#t[t] : this.#t = {}, this;
128
92
  }
129
93
  eventNames() {
130
- return Reflect.ownKeys(this.#e);
94
+ return Reflect.ownKeys(this.#t);
131
95
  }
132
- listeners(e) {
133
- return this.#e[e];
96
+ listeners(t) {
97
+ return this.#t[t];
134
98
  }
135
- listenerCount(e) {
136
- return this.#e[e]?.length ?? 0;
99
+ listenerCount(t) {
100
+ return this.#t[t]?.length ?? 0;
137
101
  }
138
102
  }
139
- class w extends m {
103
+
104
+ class LocationObserver extends n {
140
105
  constructor() {
141
106
  super();
142
- const { history: e, location: t } = window, { pushState: n, replaceState: s } = e;
143
- e.pushState = (...o) => {
144
- n.apply(e, o), this.emit("pushState", t, o[0]);
145
- }, e.replaceState = (...o) => {
146
- s.apply(e, o), this.emit("replaceState", t, o[0]);
147
- }, window.addEventListener("popstate", ({ state: o }) => {
148
- this.emit("popState", t, o);
107
+ const { history, location } = window;
108
+ const { pushState, replaceState } = history;
109
+ history.pushState = (...args) => {
110
+ pushState.apply(history, args);
111
+ this.emit("pushState", location, args[0]);
112
+ };
113
+ history.replaceState = (...args) => {
114
+ replaceState.apply(history, args);
115
+ this.emit("replaceState", location, args[0]);
116
+ };
117
+ window.addEventListener("popstate", ({ state }) => {
118
+ this.emit("popState", location, state);
149
119
  });
150
120
  }
151
121
  }
152
- const b = new w();
153
- export {
154
- c as Fetcher,
155
- l as FetcherError,
156
- v as domReady,
157
- y as el,
158
- h as fetcher,
159
- b as locationObserver,
160
- E as nbsp,
161
- p as observeElement,
162
- i as text,
163
- L as waitElement
164
- };
122
+
123
+ export { LocationObserver, domReady, el, nbsp, observeElement, text, waitElement };
165
124
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/html.ts","../src/fetcher.ts","../src/observeElement.ts","../src/waitElement.ts","../node_modules/.pnpm/@zero-dependency+emitter@1.1.1/node_modules/@zero-dependency/emitter/dist/index.es.js","../src/locationObserver.ts"],"sourcesContent":["// prettier-ignore\ntype Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: Partial<CSSStyleDeclaration>\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype Children = (string | Node | HTMLElement)[]\n\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n attributes?: Children | Attributes<T>,\n ...children: Children\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (typeof attributes === 'string') {\n el.append(text(attributes))\n } else if (Array.isArray(attributes)) {\n el.append(...attributes)\n } else {\n Object.assign(el, attributes)\n Object.assign(el.style, attributes?.style)\n }\n\n if (children.length) {\n el.append(...children)\n }\n\n return el\n}\n\nexport function text(str: string): Text {\n return document.createTextNode(str)\n}\n\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n\nexport async function domReady(): Promise<void> {\n return new Promise((resolve) => {\n if (document.readyState == 'loading') {\n document.addEventListener('DOMContentLoaded', () => resolve(), {\n once: true\n })\n } else {\n resolve()\n }\n })\n}\n","interface FetcherInit\n extends Pick<\n RequestInit,\n 'headers' | 'credentials' | 'mode' | 'cache' | 'redirect' | 'referrerPolicy'\n > {}\n\ninterface FetcherRequest extends Omit<RequestInit, 'method'> {}\n\nconst methods = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE'\n] as const\n\ntype RequestMethods = typeof methods[number]\ntype FetcherMethod = <T>(path: string, init?: FetcherRequest) => Promise<T>\n\nexport class Fetcher {\n get: FetcherMethod\n post: FetcherMethod\n put: FetcherMethod\n patch: FetcherMethod\n delete: FetcherMethod\n\n constructor(\n private readonly baseURL: string,\n private readonly baseInit?: FetcherInit\n ) {\n for (const method of methods) {\n // @ts-ignore\n this[method.toLowerCase()] = (path: string, init?: FetcherRequest) => {\n return this.request(path, { ...init, method })\n }\n }\n }\n\n extends(path: string, baseInit?: FetcherInit): Fetcher {\n const { url, init } = this.fetcherParameters(path, baseInit)\n return new Fetcher(url, init)\n }\n\n async request<T>(\n path: string,\n initRequest: FetcherRequest & { method: RequestMethods }\n ): Promise<T> {\n const { url, init } = this.fetcherParameters(path, initRequest)\n return await fetcher<T>(url, init)\n }\n\n private fetcherParameters(path: string, baseInit?: FetcherInit) {\n const url = combineURLs(this.baseURL, path)\n const headers = combineHeaders(this.baseInit?.headers, baseInit?.headers)\n const init = { ...this.baseInit, ...baseInit, headers }\n return { url, init }\n }\n}\n\nexport async function fetcher<T = unknown>(\n ...args: Parameters<typeof fetch>\n): Promise<T> {\n const response = await fetch(...args)\n const data = (await response.json()) as T\n\n if (response.ok) {\n return data\n }\n\n throw new FetcherError({\n response,\n data\n })\n}\n\nexport class FetcherError<T> extends Error {\n response: Response\n data: T\n\n constructor({ response, data }: { response: Response; data: T }) {\n super(response.statusText)\n\n this.name = 'FetcherError'\n this.response = response\n this.data = data\n }\n}\n\n// https://github.com/axios/axios/blob/v1.x/lib/helpers/combineURLs.js\nfunction combineURLs(baseURL: string, path: string): string {\n return path\n ? baseURL.replace(/\\/+$/, '') + '/' + path.replace(/^\\/+/, '')\n : baseURL\n}\n\nfunction combineHeaders(...sources: HeadersInit[]): Headers {\n const result: Record<string, string> = {}\n\n for (const source of sources) {\n const headers = new Headers(source)\n\n for (const [key, value] of headers.entries()) {\n if (value === undefined || value === null) {\n delete result[key]\n } else {\n result[key] = value\n }\n }\n }\n\n return new Headers(result)\n}\n","export function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n) {\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\n}\n","import { observeElement } from './observeElement.js'\n\nexport function waitElement<T extends Element = Element>(\n selector: string,\n target = document.documentElement\n): Promise<T> {\n return new Promise((resolve) => {\n function resolveElement() {\n const el = target.querySelector<T>(selector)\n if (el) {\n resolve(el)\n }\n }\n\n observeElement(target, (_, observer) => {\n resolveElement()\n observer.disconnect()\n })\n })\n}\n","class n {\n #t = {};\n on(t, e) {\n const s = this.#t[t];\n return s ? s.push(e) : this.#t[t] = [e], this;\n }\n addListener(t, e) {\n return this.on(t, e);\n }\n once(t, e) {\n const s = (...i) => {\n this.off(t, s), e(...i);\n };\n return this.on(t, s), this;\n }\n emit(t, ...e) {\n const s = this.#t[t] || [];\n for (let i = 0; i < s.length; i++)\n s[i](...e);\n return Boolean(s.length);\n }\n off(t, e) {\n return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;\n }\n removeListener(t, e) {\n return this.off(t, e);\n }\n removeAllListeners(t) {\n return t ? delete this.#t[t] : this.#t = {}, this;\n }\n eventNames() {\n return Reflect.ownKeys(this.#t);\n }\n listeners(t) {\n return this.#t[t];\n }\n listenerCount(t) {\n return this.#t[t]?.length ?? 0;\n }\n}\nexport {\n n as Emitter\n};\n//# sourceMappingURL=index.es.js.map\n","import { Emitter } from '@zero-dependency/emitter'\n\ntype LocationCallback = (location: Location, state: any) => void\n\ntype Events = {\n pushState: LocationCallback\n replaceState: LocationCallback\n popState: LocationCallback\n}\n\nclass LocationObserver extends Emitter<Events> {\n constructor() {\n super()\n\n const { history, location } = window\n const { pushState, replaceState } = history\n\n history.pushState = (...args) => {\n pushState.apply(history, args)\n this.emit('pushState', location, args[0])\n }\n\n history.replaceState = (...args) => {\n replaceState.apply(history, args)\n this.emit('replaceState', location, args[0])\n }\n\n window.addEventListener('popstate', ({ state }) => {\n this.emit('popState', location, state)\n })\n }\n}\n\nexport const locationObserver = new LocationObserver()\n"],"names":["el","tag","attributes","children","text","str","nbsp","domReady","resolve","methods","Fetcher","baseURL","baseInit","method","path","init","url","initRequest","fetcher","combineURLs","headers","combineHeaders","args","response","data","FetcherError","sources","result","source","key","value","observeElement","callback","options","observe","mutations","observer","mutation","waitElement","selector","target","resolveElement","_","n","#t","t","e","s","i","LocationObserver","Emitter","history","location","pushState","replaceState","state","locationObserver"],"mappings":"AAOgB,SAAAA,EACdC,GACAC,MACGC,GACuB;AACpBH,QAAAA,IAAK,SAAS,cAAcC,CAAG;AAEjC,SAAA,OAAOC,KAAe,WACxBF,EAAG,OAAOI,EAAKF,CAAU,CAAC,IACjB,MAAM,QAAQA,CAAU,IACjCF,EAAG,OAAO,GAAGE,CAAU,KAEhB,OAAA,OAAOF,GAAIE,CAAU,GAC5B,OAAO,OAAOF,EAAG,OAAOE,GAAY,KAAK,IAGvCC,EAAS,UACXH,EAAG,OAAO,GAAGG,CAAQ,GAGhBH;AACT;AAEO,SAASI,EAAKC,GAAmB;AAC/B,SAAA,SAAS,eAAeA,CAAG;AACpC;AAEO,SAASC,IAAa;AAC3B,SAAOF,EAAK,MAAQ;AACtB;AAEA,eA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AAAA,EAChB;AAAA,EACD,cAAcA,GAAG;AACf,WAAO,KAAKD,GAAGC,IAAI,UAAU;AAAA,EAC9B;AACH;AC7BA,MAAMI,UAAyBC,EAAgB;AAAA,EAC7C,cAAc;AACN;AAEA,UAAA,EAAE,SAAAC,GAAS,UAAAC,EAAa,IAAA,QACxB,EAAE,WAAAC,GAAW,cAAAC,EAAiB,IAAAH;AAE5B,IAAAA,EAAA,YAAY,IAAI7B,MAAS;AACrB,MAAA+B,EAAA,MAAMF,GAAS7B,CAAI,GAC7B,KAAK,KAAK,aAAa8B,GAAU9B,EAAK,EAAE;AAAA,IAAA,GAGlC6B,EAAA,eAAe,IAAI7B,MAAS;AACrB,MAAAgC,EAAA,MAAMH,GAAS7B,CAAI,GAChC,KAAK,KAAK,gBAAgB8B,GAAU9B,EAAK,EAAE;AAAA,IAAA,GAG7C,OAAO,iBAAiB,YAAY,CAAC,EAAE,OAAAiC,QAAY;AAC5C,WAAA,KAAK,YAAYH,GAAUG,CAAK;AAAA,IAAA,CACtC;AAAA,EACH;AACF;AAEa,MAAAC,IAAmB,IAAIP,EAAiB;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/html.ts","../src/observeElement.ts","../src/waitElement.ts","../node_modules/.pnpm/@zero-dependency+emitter@1.1.1/node_modules/@zero-dependency/emitter/dist/index.es.js","../src/locationObserver.ts"],"sourcesContent":["// prettier-ignore\ntype Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: Partial<CSSStyleDeclaration>\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype Children = (string | Node | HTMLElement)[]\n\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n attributes?: Children | Attributes<T>,\n ...children: Children\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (typeof attributes === 'string') {\n el.append(text(attributes))\n } else if (Array.isArray(attributes)) {\n el.append(...attributes)\n } else {\n Object.assign(el, attributes)\n Object.assign(el.style, attributes?.style)\n }\n\n if (children.length) {\n el.append(...children)\n }\n\n return el\n}\n\nexport function text(str: string): Text {\n return document.createTextNode(str)\n}\n\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n\nexport async function domReady(): Promise<void> {\n return new Promise((resolve) => {\n if (document.readyState == 'loading') {\n document.addEventListener('DOMContentLoaded', () => resolve(), {\n once: true\n })\n } else {\n resolve()\n }\n })\n}\n","export function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n) {\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\n}\n","import { observeElement } from './observeElement.js'\n\nexport function waitElement<T extends Element = Element>(\n selector: string,\n target = document.documentElement\n): Promise<T> {\n return new Promise((resolve) => {\n function resolveElement() {\n const el = target.querySelector<T>(selector)\n if (el) {\n resolve(el)\n }\n }\n\n observeElement(target, (_, observer) => {\n resolveElement()\n observer.disconnect()\n })\n })\n}\n","class n {\n #t = {};\n on(t, e) {\n const s = this.#t[t];\n return s ? s.push(e) : this.#t[t] = [e], this;\n }\n addListener(t, e) {\n return this.on(t, e);\n }\n once(t, e) {\n const s = (...i) => {\n this.off(t, s), e(...i);\n };\n return this.on(t, s), this;\n }\n emit(t, ...e) {\n const s = this.#t[t] || [];\n for (let i = 0; i < s.length; i++)\n s[i](...e);\n return Boolean(s.length);\n }\n off(t, e) {\n return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;\n }\n removeListener(t, e) {\n return this.off(t, e);\n }\n removeAllListeners(t) {\n return t ? delete this.#t[t] : this.#t = {}, this;\n }\n eventNames() {\n return Reflect.ownKeys(this.#t);\n }\n listeners(t) {\n return this.#t[t];\n }\n listenerCount(t) {\n return this.#t[t]?.length ?? 0;\n }\n}\nexport {\n n as Emitter\n};\n//# sourceMappingURL=index.es.js.map\n","import { Emitter } from '@zero-dependency/emitter'\n\ntype LocationCallback = (location: Location, state: any) => void\n\ntype Events = {\n pushState: LocationCallback\n replaceState: LocationCallback\n popState: LocationCallback\n}\n\nexport class LocationObserver extends Emitter<Events> {\n constructor() {\n super()\n\n const { history, location } = window\n const { pushState, replaceState } = history\n\n history.pushState = (...args) => {\n pushState.apply(history, args)\n this.emit('pushState', location, args[0])\n }\n\n history.replaceState = (...args) => {\n replaceState.apply(history, args)\n this.emit('replaceState', location, args[0])\n }\n\n window.addEventListener('popstate', ({ state }) => {\n this.emit('popState', location, state)\n })\n }\n}\n"],"names":["el","Emitter"],"mappings":"AAOgB,SAAA,EAAA,CACd,GACA,EAAA,UAAA,EAAA,GACG,QACuB,EAAA;AAC1B,EAAMA,MAAAA,GAAAA,GAAK,QAAS,CAAA,aAAA,CAAc,GAAG,CAAA,CAAA;AAErC,EAAI,IAAA,OAAO,eAAe,QAAU,EAAA;AAClC,IAAAA,GAAG,CAAA,MAAA,CAAO,IAAK,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,GACjB,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,UAAU,CAAG,EAAA;AACpC,IAAAA,GAAAA,CAAG,MAAO,CAAA,GAAG,UAAU,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAO,MAAA,CAAA,MAAA,CAAOA,KAAI,UAAU,CAAA,CAAA;AAC5B,IAAA,MAAA,CAAO,MAAOA,CAAAA,GAAAA,CAAG,KAAO,EAAA,UAAA,EAAY,KAAK,CAAA,CAAA;AAAA,GAC3C;AAEA,EAAA,IAAI,SAAS,MAAQ,EAAA;AACnB,IAAAA,GAAAA,CAAG,MAAO,CAAA,GAAG,QAAQ,CAAA,CAAA;AAAA,GACvB;AAEA,EAAOA,OAAAA,GAAAA,CAAAA;AACT,CAAA;AAEO,SAAS,KAAK,GAAmB,EAAA;AACtC,EAAO,OAAA,QAAA,CAAS,eAAe,GAAG,CAAA,CAAA;AACpC,CAAA;AAEO,SAAS,IAAa,GAAA;AAC3B,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AAQ,OAAA,CAAA,SAAA,GAAY,IAAI,IAAS,KAAA;AAC/B,MAAU,SAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;AAC7B,MAAA,IAAA,CAAK,IAAK,CAAA,WAAA,EAAa,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;AAAA,KAC1C,CAAA;AAEA,IAAQ,OAAA,CAAA,YAAA,GAAe,IAAI,IAAS,KAAA;AAClC,MAAa,YAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;AAChC,MAAA,IAAA,CAAK,IAAK,CAAA,cAAA,EAAgB,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;AAAA,KAC7C,CAAA;AAEA,IAAA,MAAA,CAAO,gBAAiB,CAAA,UAAA,EAAY,CAAC,EAAE,OAAY,KAAA;AACjD,MAAK,IAAA,CAAA,IAAA,CAAK,UAAY,EAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AAAA,KACtC,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,140 @@
1
- (function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i["@zero-dependency/dom"]={}))})(this,function(i){"use strict";function c(r,e,...t){const n=document.createElement(r);return typeof e=="string"?n.append(a(e)):Array.isArray(e)?n.append(...e):(Object.assign(n,e),Object.assign(n.style,e?.style)),t.length&&n.append(...t),n}function a(r){return document.createTextNode(r)}function f(){return a("\xA0")}async function m(){return new Promise(r=>{document.readyState=="loading"?document.addEventListener("DOMContentLoaded",()=>r(),{once:!0}):r()})}const p=["GET","POST","PUT","PATCH","DELETE"];class u{constructor(e,t){this.baseURL=e,this.baseInit=t;for(const n of p)this[n.toLowerCase()]=(s,o)=>this.request(s,{...o,method:n})}get;post;put;patch;delete;extends(e,t){const{url:n,init:s}=this.fetcherParameters(e,t);return new u(n,s)}async request(e,t){const{url:n,init:s}=this.fetcherParameters(e,t);return await h(n,s)}fetcherParameters(e,t){const n=y(this.baseURL,e),s=w(this.baseInit?.headers,t?.headers),o={...this.baseInit,...t,headers:s};return{url:n,init:o}}}async function h(...r){const e=await fetch(...r),t=await e.json();if(e.ok)return t;throw new l({response:e,data:t})}class l extends Error{response;data;constructor({response:e,data:t}){super(e.statusText),this.name="FetcherError",this.response=e,this.data=t}}function y(r,e){return e?r.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):r}function w(...r){const e={};for(const t of r){const n=new Headers(t);for(const[s,o]of n.entries())o==null?delete e[s]:e[s]=o}return new Headers(e)}function d(r,e,t){const n=new MutationObserver((s,o)=>{for(const S of s)e(S,o)});return n.observe(r,{childList:!0,subtree:!0,...t}),n}function v(r,e=document.documentElement){return new Promise(t=>{function n(){const s=e.querySelector(r);s&&t(s)}d(e,(s,o)=>{n(),o.disconnect()})})}class E{#e={};on(e,t){const n=this.#e[e];return n?n.push(t):this.#e[e]=[t],this}addListener(e,t){return this.on(e,t)}once(e,t){const n=(...s)=>{this.off(e,n),t(...s)};return this.on(e,n),this}emit(e,...t){const n=this.#e[e]||[];for(let s=0;s<n.length;s++)n[s](...t);return Boolean(n.length)}off(e,t){return this.#e[e]&&(this.#e[e]=this.#e[e].filter(n=>n!==t)),this}removeListener(e,t){return this.off(e,t)}removeAllListeners(e){return e?delete this.#e[e]:this.#e={},this}eventNames(){return Reflect.ownKeys(this.#e)}listeners(e){return this.#e[e]}listenerCount(e){return this.#e[e]?.length??0}}class b extends E{constructor(){super();const{history:e,location:t}=window,{pushState:n,replaceState:s}=e;e.pushState=(...o)=>{n.apply(e,o),this.emit("pushState",t,o[0])},e.replaceState=(...o)=>{s.apply(e,o),this.emit("replaceState",t,o[0])},window.addEventListener("popstate",({state:o})=>{this.emit("popState",t,o)})}}const L=new b;i.Fetcher=u,i.FetcherError=l,i.domReady=m,i.el=c,i.fetcher=h,i.locationObserver=L,i.nbsp=f,i.observeElement=d,i.text=a,i.waitElement=v,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@zero-dependency/dom"] = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ function el(tag, attributes, ...children) {
8
+ const el2 = document.createElement(tag);
9
+ if (typeof attributes === "string") {
10
+ el2.append(text(attributes));
11
+ } else if (Array.isArray(attributes)) {
12
+ el2.append(...attributes);
13
+ } else {
14
+ Object.assign(el2, attributes);
15
+ Object.assign(el2.style, attributes?.style);
16
+ }
17
+ if (children.length) {
18
+ el2.append(...children);
19
+ }
20
+ return el2;
21
+ }
22
+ function text(str) {
23
+ return document.createTextNode(str);
24
+ }
25
+ function nbsp() {
26
+ return text("\xA0");
27
+ }
28
+ async function domReady() {
29
+ return new Promise((resolve) => {
30
+ if (document.readyState == "loading") {
31
+ document.addEventListener("DOMContentLoaded", () => resolve(), {
32
+ once: true
33
+ });
34
+ } else {
35
+ resolve();
36
+ }
37
+ });
38
+ }
39
+
40
+ function observeElement(el, callback, options) {
41
+ const observe = new MutationObserver((mutations, observer) => {
42
+ for (const mutation of mutations) {
43
+ callback(mutation, observer);
44
+ }
45
+ });
46
+ observe.observe(el, {
47
+ childList: true,
48
+ subtree: true,
49
+ ...options
50
+ });
51
+ return observe;
52
+ }
53
+
54
+ function waitElement(selector, target = document.documentElement) {
55
+ return new Promise((resolve) => {
56
+ function resolveElement() {
57
+ const el = target.querySelector(selector);
58
+ if (el) {
59
+ resolve(el);
60
+ }
61
+ }
62
+ observeElement(target, (_, observer) => {
63
+ resolveElement();
64
+ observer.disconnect();
65
+ });
66
+ });
67
+ }
68
+
69
+ class n {
70
+ #t = {};
71
+ on(t, e) {
72
+ const s = this.#t[t];
73
+ return s ? s.push(e) : this.#t[t] = [e], this;
74
+ }
75
+ addListener(t, e) {
76
+ return this.on(t, e);
77
+ }
78
+ once(t, e) {
79
+ const s = (...i) => {
80
+ this.off(t, s), e(...i);
81
+ };
82
+ return this.on(t, s), this;
83
+ }
84
+ emit(t, ...e) {
85
+ const s = this.#t[t] || [];
86
+ for (let i = 0; i < s.length; i++)
87
+ s[i](...e);
88
+ return Boolean(s.length);
89
+ }
90
+ off(t, e) {
91
+ return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;
92
+ }
93
+ removeListener(t, e) {
94
+ return this.off(t, e);
95
+ }
96
+ removeAllListeners(t) {
97
+ return t ? delete this.#t[t] : this.#t = {}, this;
98
+ }
99
+ eventNames() {
100
+ return Reflect.ownKeys(this.#t);
101
+ }
102
+ listeners(t) {
103
+ return this.#t[t];
104
+ }
105
+ listenerCount(t) {
106
+ return this.#t[t]?.length ?? 0;
107
+ }
108
+ }
109
+
110
+ class LocationObserver extends n {
111
+ constructor() {
112
+ super();
113
+ const { history, location } = window;
114
+ const { pushState, replaceState } = history;
115
+ history.pushState = (...args) => {
116
+ pushState.apply(history, args);
117
+ this.emit("pushState", location, args[0]);
118
+ };
119
+ history.replaceState = (...args) => {
120
+ replaceState.apply(history, args);
121
+ this.emit("replaceState", location, args[0]);
122
+ };
123
+ window.addEventListener("popstate", ({ state }) => {
124
+ this.emit("popState", location, state);
125
+ });
126
+ }
127
+ }
128
+
129
+ exports.LocationObserver = LocationObserver;
130
+ exports.domReady = domReady;
131
+ exports.el = el;
132
+ exports.nbsp = nbsp;
133
+ exports.observeElement = observeElement;
134
+ exports.text = text;
135
+ exports.waitElement = waitElement;
136
+
137
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
138
+
139
+ }));
2
140
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/html.ts","../src/fetcher.ts","../src/observeElement.ts","../src/waitElement.ts","../node_modules/.pnpm/@zero-dependency+emitter@1.1.1/node_modules/@zero-dependency/emitter/dist/index.es.js","../src/locationObserver.ts"],"sourcesContent":["// prettier-ignore\ntype Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: Partial<CSSStyleDeclaration>\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype Children = (string | Node | HTMLElement)[]\n\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n attributes?: Children | Attributes<T>,\n ...children: Children\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (typeof attributes === 'string') {\n el.append(text(attributes))\n } else if (Array.isArray(attributes)) {\n el.append(...attributes)\n } else {\n Object.assign(el, attributes)\n Object.assign(el.style, attributes?.style)\n }\n\n if (children.length) {\n el.append(...children)\n }\n\n return el\n}\n\nexport function text(str: string): Text {\n return document.createTextNode(str)\n}\n\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n\nexport async function domReady(): Promise<void> {\n return new Promise((resolve) => {\n if (document.readyState == 'loading') {\n document.addEventListener('DOMContentLoaded', () => resolve(), {\n once: true\n })\n } else {\n resolve()\n }\n })\n}\n","interface FetcherInit\n extends Pick<\n RequestInit,\n 'headers' | 'credentials' | 'mode' | 'cache' | 'redirect' | 'referrerPolicy'\n > {}\n\ninterface FetcherRequest extends Omit<RequestInit, 'method'> {}\n\nconst methods = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE'\n] as const\n\ntype RequestMethods = typeof methods[number]\ntype FetcherMethod = <T>(path: string, init?: FetcherRequest) => Promise<T>\n\nexport class Fetcher {\n get: FetcherMethod\n post: FetcherMethod\n put: FetcherMethod\n patch: FetcherMethod\n delete: FetcherMethod\n\n constructor(\n private readonly baseURL: string,\n private readonly baseInit?: FetcherInit\n ) {\n for (const method of methods) {\n // @ts-ignore\n this[method.toLowerCase()] = (path: string, init?: FetcherRequest) => {\n return this.request(path, { ...init, method })\n }\n }\n }\n\n extends(path: string, baseInit?: FetcherInit): Fetcher {\n const { url, init } = this.fetcherParameters(path, baseInit)\n return new Fetcher(url, init)\n }\n\n async request<T>(\n path: string,\n initRequest: FetcherRequest & { method: RequestMethods }\n ): Promise<T> {\n const { url, init } = this.fetcherParameters(path, initRequest)\n return await fetcher<T>(url, init)\n }\n\n private fetcherParameters(path: string, baseInit?: FetcherInit) {\n const url = combineURLs(this.baseURL, path)\n const headers = combineHeaders(this.baseInit?.headers, baseInit?.headers)\n const init = { ...this.baseInit, ...baseInit, headers }\n return { url, init }\n }\n}\n\nexport async function fetcher<T = unknown>(\n ...args: Parameters<typeof fetch>\n): Promise<T> {\n const response = await fetch(...args)\n const data = (await response.json()) as T\n\n if (response.ok) {\n return data\n }\n\n throw new FetcherError({\n response,\n data\n })\n}\n\nexport class FetcherError<T> extends Error {\n response: Response\n data: T\n\n constructor({ response, data }: { response: Response; data: T }) {\n super(response.statusText)\n\n this.name = 'FetcherError'\n this.response = response\n this.data = data\n }\n}\n\n// https://github.com/axios/axios/blob/v1.x/lib/helpers/combineURLs.js\nfunction combineURLs(baseURL: string, path: string): string {\n return path\n ? baseURL.replace(/\\/+$/, '') + '/' + path.replace(/^\\/+/, '')\n : baseURL\n}\n\nfunction combineHeaders(...sources: HeadersInit[]): Headers {\n const result: Record<string, string> = {}\n\n for (const source of sources) {\n const headers = new Headers(source)\n\n for (const [key, value] of headers.entries()) {\n if (value === undefined || value === null) {\n delete result[key]\n } else {\n result[key] = value\n }\n }\n }\n\n return new Headers(result)\n}\n","export function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n) {\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\n}\n","import { observeElement } from './observeElement.js'\n\nexport function waitElement<T extends Element = Element>(\n selector: string,\n target = document.documentElement\n): Promise<T> {\n return new Promise((resolve) => {\n function resolveElement() {\n const el = target.querySelector<T>(selector)\n if (el) {\n resolve(el)\n }\n }\n\n observeElement(target, (_, observer) => {\n resolveElement()\n observer.disconnect()\n })\n })\n}\n","class n {\n #t = {};\n on(t, e) {\n const s = this.#t[t];\n return s ? s.push(e) : this.#t[t] = [e], this;\n }\n addListener(t, e) {\n return this.on(t, e);\n }\n once(t, e) {\n const s = (...i) => {\n this.off(t, s), e(...i);\n };\n return this.on(t, s), this;\n }\n emit(t, ...e) {\n const s = this.#t[t] || [];\n for (let i = 0; i < s.length; i++)\n s[i](...e);\n return Boolean(s.length);\n }\n off(t, e) {\n return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;\n }\n removeListener(t, e) {\n return this.off(t, e);\n }\n removeAllListeners(t) {\n return t ? delete this.#t[t] : this.#t = {}, this;\n }\n eventNames() {\n return Reflect.ownKeys(this.#t);\n }\n listeners(t) {\n return this.#t[t];\n }\n listenerCount(t) {\n return this.#t[t]?.length ?? 0;\n }\n}\nexport {\n n as Emitter\n};\n//# sourceMappingURL=index.es.js.map\n","import { Emitter } from '@zero-dependency/emitter'\n\ntype LocationCallback = (location: Location, state: any) => void\n\ntype Events = {\n pushState: LocationCallback\n replaceState: LocationCallback\n popState: LocationCallback\n}\n\nclass LocationObserver extends Emitter<Events> {\n constructor() {\n super()\n\n const { history, location } = window\n const { pushState, replaceState } = history\n\n history.pushState = (...args) => {\n pushState.apply(history, args)\n this.emit('pushState', location, args[0])\n }\n\n history.replaceState = (...args) => {\n replaceState.apply(history, args)\n this.emit('replaceState', location, args[0])\n }\n\n window.addEventListener('popstate', ({ state }) => {\n this.emit('popState', location, state)\n })\n }\n}\n\nexport const locationObserver = new LocationObserver()\n"],"names":["el","tag","attributes","children","text","str","nbsp","domReady","resolve","methods","Fetcher","baseURL","baseInit","method","path","init","url","initRequest","fetcher","combineURLs","headers","combineHeaders","args","response","data","FetcherError","sources","result","source","key","value","observeElement","callback","options","observe","mutations","observer","mutation","waitElement","selector","target","resolveElement","_","n","#t","t","e","s","i","LocationObserver","Emitter","history","location","pushState","replaceState","state","locationObserver"],"mappings":"+OAOgB,SAAAA,EACdC,EACAC,KACGC,EACuB,CACpBH,MAAAA,EAAK,SAAS,cAAcC,CAAG,EAEjC,OAAA,OAAOC,GAAe,SACxBF,EAAG,OAAOI,EAAKF,CAAU,CAAC,EACjB,MAAM,QAAQA,CAAU,EACjCF,EAAG,OAAO,GAAGE,CAAU,GAEhB,OAAA,OAAOF,EAAIE,CAAU,EAC5B,OAAO,OAAOF,EAAG,MAAOE,GAAY,KAAK,GAGvCC,EAAS,QACXH,EAAG,OAAO,GAAGG,CAAQ,EAGhBH,CACT,CAEO,SAASI,EAAKC,EAAmB,CAC/B,OAAA,SAAS,eAAeA,CAAG,CACpC,CAEO,SAASC,GAAa,CAC3B,OAAOF,EAAK,MAAQ,CACtB,CAEA,eAAsBG,GAA0B,CACvC,OAAA,IAAI,QAASC,GAAY,CAC1B,SAAS,YAAc,UACzB,SAAS,iBAAiB,mBAAoB,IAAMA,EAAA,EAAW,CAC7D,KAAM,EAAA,CACP,EAEOA,GACV,CACD,CACH,CCxCA,MAAMC,EAAU,CACd,MACA,OACA,MACA,QACA,QACF,EAKO,MAAMC,CAAQ,CAOnB,YACmBC,EACAC,EACjB,CAFiB,KAAA,QAAAD,EACA,KAAA,SAAAC,EAEjB,UAAWC,KAAUJ,EAEnB,KAAKI,EAAO,YAAA,GAAiB,CAACC,EAAcC,IACnC,KAAK,QAAQD,EAAM,CAAE,GAAGC,EAAM,OAAAF,EAAQ,CAGnD,CAhBA,IACA,KACA,IACA,MACA,OAcA,QAAQC,EAAcF,EAAiC,CACrD,KAAM,CAAE,IAAAI,EAAK,KAAAD,GAAS,KAAK,kBAAkBD,EAAMF,CAAQ,EACpD,OAAA,IAAIF,EAAQM,EAAKD,CAAI,CAC9B,CAEA,MAAM,QACJD,EACAG,EACY,CACZ,KAAM,CAAE,IAAAD,EAAK,KAAAD,GAAS,KA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I,OAAO,KAAKD,GAAGC,GAAK,KAAKD,GAAK,CAAE,EAAE,IAC9C,CACD,YAAa,CACX,OAAO,QAAQ,QAAQ,KAAKA,EAAE,CAC/B,CACD,UAAUC,EAAG,CACX,OAAO,KAAKD,GAAGC,EAChB,CACD,cAAcA,EAAG,CACf,OAAO,KAAKD,GAAGC,IAAI,QAAU,CAC9B,CACH,CC7BA,MAAMI,UAAyBC,CAAgB,CAC7C,aAAc,CACN,QAEA,KAAA,CAAE,QAAAC,EAAS,SAAAC,CAAa,EAAA,OACxB,CAAE,UAAAC,EAAW,aAAAC,CAAiB,EAAAH,EAE5BA,EAAA,UAAY,IAAI7B,IAAS,CACrB+B,EAAA,MAAMF,EAAS7B,CAAI,EAC7B,KAAK,KAAK,YAAa8B,EAAU9B,EAAK,EAAE,CAAA,EAGlC6B,EAAA,aAAe,IAAI7B,IAAS,CACrBgC,EAAA,MAAMH,EAAS7B,CAAI,EAChC,KAAK,KAAK,eAAgB8B,EAAU9B,EAAK,EAAE,CAAA,EAG7C,OAAO,iBAAiB,WAAY,CAAC,CAAE,MAAAiC,KAAY,CAC5C,KAAA,KAAK,WAAYH,EAAUG,CAAK,CAAA,CACtC,CACH,CACF,CAEa,MAAAC,EAAmB,IAAIP"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/html.ts","../src/observeElement.ts","../src/waitElement.ts","../node_modules/.pnpm/@zero-dependency+emitter@1.1.1/node_modules/@zero-dependency/emitter/dist/index.es.js","../src/locationObserver.ts"],"sourcesContent":["// prettier-ignore\ntype Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{\n style: Partial<CSSStyleDeclaration>\n} & Omit<HTMLElementTagNameMap[T], 'style'>>\n\ntype Children = (string | Node | HTMLElement)[]\n\nexport function el<T extends keyof HTMLElementTagNameMap>(\n tag: T,\n attributes?: Children | Attributes<T>,\n ...children: Children\n): HTMLElementTagNameMap[T] {\n const el = document.createElement(tag)\n\n if (typeof attributes === 'string') {\n el.append(text(attributes))\n } else if (Array.isArray(attributes)) {\n el.append(...attributes)\n } else {\n Object.assign(el, attributes)\n Object.assign(el.style, attributes?.style)\n }\n\n if (children.length) {\n el.append(...children)\n }\n\n return el\n}\n\nexport function text(str: string): Text {\n return document.createTextNode(str)\n}\n\nexport function nbsp(): Text {\n return text('\\u00a0')\n}\n\nexport async function domReady(): Promise<void> {\n return new Promise((resolve) => {\n if (document.readyState == 'loading') {\n document.addEventListener('DOMContentLoaded', () => resolve(), {\n once: true\n })\n } else {\n resolve()\n }\n })\n}\n","export function observeElement<T extends Element = Element>(\n el: T,\n callback: (mutation: MutationRecord, observer: MutationObserver) => void,\n options?: MutationObserverInit\n) {\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\n}\n","import { observeElement } from './observeElement.js'\n\nexport function waitElement<T extends Element = Element>(\n selector: string,\n target = document.documentElement\n): Promise<T> {\n return new Promise((resolve) => {\n function resolveElement() {\n const el = target.querySelector<T>(selector)\n if (el) {\n resolve(el)\n }\n }\n\n observeElement(target, (_, observer) => {\n resolveElement()\n observer.disconnect()\n })\n })\n}\n","class n {\n #t = {};\n on(t, e) {\n const s = this.#t[t];\n return s ? s.push(e) : this.#t[t] = [e], this;\n }\n addListener(t, e) {\n return this.on(t, e);\n }\n once(t, e) {\n const s = (...i) => {\n this.off(t, s), e(...i);\n };\n return this.on(t, s), this;\n }\n emit(t, ...e) {\n const s = this.#t[t] || [];\n for (let i = 0; i < s.length; i++)\n s[i](...e);\n return Boolean(s.length);\n }\n off(t, e) {\n return this.#t[t] && (this.#t[t] = this.#t[t].filter((s) => s !== e)), this;\n }\n removeListener(t, e) {\n return this.off(t, e);\n }\n removeAllListeners(t) {\n return t ? delete this.#t[t] : this.#t = {}, this;\n }\n eventNames() {\n return Reflect.ownKeys(this.#t);\n }\n listeners(t) {\n return this.#t[t];\n }\n listenerCount(t) {\n return this.#t[t]?.length ?? 0;\n }\n}\nexport {\n n as Emitter\n};\n//# sourceMappingURL=index.es.js.map\n","import { Emitter } from '@zero-dependency/emitter'\n\ntype LocationCallback = (location: Location, state: any) => void\n\ntype Events = {\n pushState: LocationCallback\n replaceState: LocationCallback\n popState: LocationCallback\n}\n\nexport class LocationObserver extends Emitter<Events> {\n constructor() {\n super()\n\n const { history, location } = window\n const { pushState, replaceState } = history\n\n history.pushState = (...args) => {\n pushState.apply(history, args)\n this.emit('pushState', location, args[0])\n }\n\n history.replaceState = (...args) => {\n replaceState.apply(history, args)\n this.emit('replaceState', location, args[0])\n }\n\n window.addEventListener('popstate', ({ state }) => {\n this.emit('popState', location, state)\n })\n }\n}\n"],"names":["el","Emitter"],"mappings":";;;;;;EAOgB,SAAA,EAAA,CACd,GACA,EAAA,UAAA,EAAA,GACG,QACuB,EAAA;EAC1B,EAAMA,MAAAA,GAAAA,GAAK,QAAS,CAAA,aAAA,CAAc,GAAG,CAAA,CAAA;EAErC,EAAI,IAAA,OAAO,eAAe,QAAU,EAAA;EAClC,IAAAA,GAAG,CAAA,MAAA,CAAO,IAAK,CAAA,UAAU,CAAC,CAAA,CAAA;EAAA,GACjB,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,UAAU,CAAG,EAAA;EACpC,IAAAA,GAAAA,CAAG,MAAO,CAAA,GAAG,UAAU,CAAA,CAAA;EAAA,GAClB,MAAA;EACL,IAAO,MAAA,CAAA,MAAA,CAAOA,KAAI,UAAU,CAAA,CAAA;EAC5B,IAAA,MAAA,CAAO,MAAOA,CAAAA,GAAAA,CAAG,KAAO,EAAA,UAAA,EAAY,KAAK,CAAA,CAAA;EAAA,GAC3C;EAEA,EAAA,IAAI,SAAS,MAAQ,EAAA;EACnB,IAAAA,GAAAA,CAAG,MAAO,CAAA,GAAG,QAAQ,CAAA,CAAA;EAAA,GACvB;EAEA,EAAOA,OAAAA,GAAAA,CAAAA;EACT,CAAA;EAEO,SAAS,KAAK,GAAmB,EAAA;EACtC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AA,MAAA,CAAA;EAC9B,IAAM,MAAA,EAAE,SAAW,EAAA,YAAA,EAAiB,GAAA,OAAA,CAAA;EAEpC,IAAQ,OAAA,CAAA,SAAA,GAAY,IAAI,IAAS,KAAA;EAC/B,MAAU,SAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;EAC7B,MAAA,IAAA,CAAK,IAAK,CAAA,WAAA,EAAa,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;EAAA,KAC1C,CAAA;EAEA,IAAQ,OAAA,CAAA,YAAA,GAAe,IAAI,IAAS,KAAA;EAClC,MAAa,YAAA,CAAA,KAAA,CAAM,SAAS,IAAI,CAAA,CAAA;EAChC,MAAA,IAAA,CAAK,IAAK,CAAA,cAAA,EAAgB,QAAU,EAAA,IAAA,CAAK,CAAE,CAAA,CAAA,CAAA;EAAA,KAC7C,CAAA;EAEA,IAAA,MAAA,CAAO,gBAAiB,CAAA,UAAA,EAAY,CAAC,EAAE,OAAY,KAAA;EACjD,MAAK,IAAA,CAAA,IAAA,CAAK,UAAY,EAAA,QAAA,EAAU,KAAK,CAAA,CAAA;EAAA,KACtC,CAAA,CAAA;EAAA,GACH;EACF;;;;;;;;;;;;;;;;"}
@@ -5,8 +5,7 @@ declare type Events = {
5
5
  replaceState: LocationCallback;
6
6
  popState: LocationCallback;
7
7
  };
8
- declare class LocationObserver extends Emitter<Events> {
8
+ export declare class LocationObserver extends Emitter<Events> {
9
9
  constructor();
10
10
  }
11
- export declare const locationObserver: LocationObserver;
12
11
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero-dependency/dom",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.umd.js",
@@ -22,16 +22,16 @@
22
22
  "url": "https://crashmax.ru"
23
23
  },
24
24
  "devDependencies": {
25
- "@crashmax/prettier-config": "^2.0.4",
25
+ "@crashmax/prettier-config": "^2.1.0",
26
26
  "@crashmax/tsconfig": "^1.0.2",
27
- "@types/node": "^18.8.3",
28
- "@vitest/coverage-c8": "^0.24.0",
29
- "@vitest/ui": "^0.23.4",
30
- "jsdom": "^20.0.1",
31
- "typescript": "^4.8.4",
32
- "vite": "^3.1.6",
33
- "vite-plugin-dts": "^1.6.5",
34
- "vitest": "^0.23.4"
27
+ "@types/node": "^18.11.9",
28
+ "@vitest/coverage-c8": "^0.25.2",
29
+ "@vitest/ui": "^0.25.2",
30
+ "jsdom": "^20.0.3",
31
+ "typescript": "^4.9.3",
32
+ "vite": "^3.2.4",
33
+ "vite-plugin-dts": "^1.7.1",
34
+ "vitest": "^0.25.2"
35
35
  },
36
36
  "dependencies": {
37
37
  "@zero-dependency/emitter": "1.1.1"
package/dist/fetcher.d.ts DELETED
@@ -1,32 +0,0 @@
1
- interface FetcherInit extends Pick<RequestInit, 'headers' | 'credentials' | 'mode' | 'cache' | 'redirect' | 'referrerPolicy'> {
2
- }
3
- interface FetcherRequest extends Omit<RequestInit, 'method'> {
4
- }
5
- declare const methods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
6
- declare type RequestMethods = typeof methods[number];
7
- declare type FetcherMethod = <T>(path: string, init?: FetcherRequest) => Promise<T>;
8
- export declare class Fetcher {
9
- private readonly baseURL;
10
- private readonly baseInit?;
11
- get: FetcherMethod;
12
- post: FetcherMethod;
13
- put: FetcherMethod;
14
- patch: FetcherMethod;
15
- delete: FetcherMethod;
16
- constructor(baseURL: string, baseInit?: FetcherInit);
17
- extends(path: string, baseInit?: FetcherInit): Fetcher;
18
- request<T>(path: string, initRequest: FetcherRequest & {
19
- method: RequestMethods;
20
- }): Promise<T>;
21
- private fetcherParameters;
22
- }
23
- export declare function fetcher<T = unknown>(...args: Parameters<typeof fetch>): Promise<T>;
24
- export declare class FetcherError<T> extends Error {
25
- response: Response;
26
- data: T;
27
- constructor({ response, data }: {
28
- response: Response;
29
- data: T;
30
- });
31
- }
32
- export {};