@zero-dependency/dom 0.1.0 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Vitalij Ryndin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # `@zero-dependency/dom`
@@ -0,0 +1 @@
1
+ export declare function debounce<T extends (...args: any[]) => void>(fn: T, delay?: number): (this: ThisParameterType<T>, ...args: Parameters<T>) => void;
@@ -0,0 +1 @@
1
+ export declare function domReady(): Promise<void>;
package/dist/html.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ declare type Attributes<T extends keyof HTMLElementTagNameMap> = Partial<{
2
+ style: Partial<CSSStyleDeclaration>;
3
+ } & Omit<HTMLElementTagNameMap[T], 'style'>>;
4
+ declare type Children = (string | Node | HTMLElement)[];
5
+ export declare function el<T extends keyof HTMLElementTagNameMap>(tag: T, attributes?: Attributes<T>, ...children: Children): HTMLElementTagNameMap[T];
6
+ export declare function text(str: string): Text;
7
+ export declare function nbsp(): Text;
8
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export { observeElement } from './observeElement.js';
2
2
  export { waitObserveElement } from './waitObserveElement.js';
3
+ export { domReady } from './domReady.js';
4
+ export { debounce } from './debounce.js';
5
+ export { el, text, nbsp } from './html.js';
package/dist/index.es.js CHANGED
@@ -1,29 +1,60 @@
1
- function i(t, o, r = document.body) {
2
- const e = new MutationObserver((n) => {
3
- for (const s of n)
4
- for (const u of s.addedNodes) {
5
- const c = u;
6
- c.matches && c.matches(t) && o(c);
1
+ function s(e, o, n = document.body) {
2
+ const t = new MutationObserver((r) => {
3
+ for (const u of r)
4
+ for (const d of u.addedNodes) {
5
+ const c = d;
6
+ c.matches && c.matches(e) && o(c);
7
7
  }
8
8
  });
9
- return e.observe(r, {
9
+ return t.observe(n, {
10
10
  attributes: !0,
11
11
  childList: !0,
12
12
  subtree: !0
13
- }), e;
13
+ }), t;
14
14
  }
15
- function d(t, o = !0, r = document.body) {
16
- return new Promise((e) => {
17
- const n = i(
18
- t,
19
- (s) => {
20
- o && n.disconnect(), e(s);
15
+ function a(e, o = !0, n = document.body) {
16
+ return new Promise((t) => {
17
+ const r = s(
18
+ e,
19
+ (u) => {
20
+ o && r.disconnect(), t(u);
21
21
  },
22
- r
22
+ n
23
23
  );
24
24
  });
25
25
  }
26
+ async function m() {
27
+ if (document.readyState == "loading")
28
+ return new Promise((e) => {
29
+ document.addEventListener("DOMContentLoaded", () => e(), {
30
+ once: !0
31
+ });
32
+ });
33
+ }
34
+ function f(e, o = 500) {
35
+ let n;
36
+ return (...t) => {
37
+ n && clearTimeout(n), n = setTimeout(() => {
38
+ e(...t);
39
+ }, o);
40
+ };
41
+ }
42
+ function b(e, o, ...n) {
43
+ const t = document.createElement(e);
44
+ return Object.assign(t, o), t.append(...n), t;
45
+ }
46
+ function i(e) {
47
+ return document.createTextNode(e);
48
+ }
49
+ function l() {
50
+ return i("\xA0");
51
+ }
26
52
  export {
27
- i as observeElement,
28
- d as waitObserveElement
53
+ f as debounce,
54
+ m as domReady,
55
+ b as el,
56
+ l as nbsp,
57
+ s as observeElement,
58
+ i as text,
59
+ a as waitObserveElement
29
60
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["@zero-dependency/dom"]={}))})(this,function(e){"use strict";function t(o,s,r=document.body){const n=new MutationObserver(i=>{for(const d of i)for(const c of d.addedNodes){const u=c;u.matches&&u.matches(o)&&s(u)}});return n.observe(r,{attributes:!0,childList:!0,subtree:!0}),n}function f(o,s=!0,r=document.body){return new Promise(n=>{const i=t(o,d=>{s&&i.disconnect(),n(d)},r)})}e.observeElement=t,e.waitObserveElement=f,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(e,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(e=typeof globalThis<"u"?globalThis:e||self,d(e["@zero-dependency/dom"]={}))})(this,function(e){"use strict";function d(t,u,o=document.body){const n=new MutationObserver(i=>{for(const r of i)for(const v of r.addedNodes){const c=v;c.matches&&c.matches(t)&&u(c)}});return n.observe(o,{attributes:!0,childList:!0,subtree:!0}),n}function f(t,u=!0,o=document.body){return new Promise(n=>{const i=d(t,r=>{u&&i.disconnect(),n(r)},o)})}async function m(){if(document.readyState=="loading")return new Promise(t=>{document.addEventListener("DOMContentLoaded",()=>t(),{once:!0})})}function a(t,u=500){let o;return(...n)=>{o&&clearTimeout(o),o=setTimeout(()=>{t(...n)},u)}}function b(t,u,...o){const n=document.createElement(t);return Object.assign(n,u),n.append(...o),n}function s(t){return document.createTextNode(t)}function l(){return s("\xA0")}e.debounce=a,e.domReady=m,e.el=b,e.nbsp=l,e.observeElement=d,e.text=s,e.waitObserveElement=f,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@zero-dependency/dom",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
- "module": "./dist/index.es.js",
7
6
  "main": "./dist/index.umd.js",
7
+ "module": "./dist/index.es.js",
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "scripts": {
9
12
  "dev": "vite build --watch",
10
13
  "build": "vite build"
@@ -1,15 +0,0 @@
1
- @zero-dependency/dom:build: cache hit, replaying output b970533020e4e96e
2
- @zero-dependency/dom:build: 
3
- @zero-dependency/dom:build: > @zero-dependency/dom@0.0.0 build /home/crashmax/github/zero-dependency/packages/dom
4
- @zero-dependency/dom:build: > vite build
5
- @zero-dependency/dom:build: 
6
- @zero-dependency/dom:build: vite v3.1.4 building for production...
7
- @zero-dependency/dom:build: transforming...
8
- @zero-dependency/dom:build: ✓ 3 modules transformed.
9
- @zero-dependency/dom:build: rendering chunks...
10
- @zero-dependency/dom:build: dist/index.es.js 0.54 KiB / gzip: 0.29 KiB
11
- @zero-dependency/dom:build: dist/index.umd.js 0.68 KiB / gzip: 0.42 KiB
12
- @zero-dependency/dom:build: 
13
- @zero-dependency/dom:build: [vite:dts] Start generate declaration files...
14
- @zero-dependency/dom:build: [vite:dts] Declaration files built in 988ms.
15
- @zero-dependency/dom:build: 
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { observeElement } from './observeElement.js'
2
- export { waitObserveElement } from './waitObserveElement.js'
@@ -1,24 +0,0 @@
1
- export function observeElement(
2
- selector: string,
3
- callback: (el: Element) => void,
4
- target = document.body
5
- ) {
6
- const observer = new MutationObserver((mutations) => {
7
- for (const mutation of mutations) {
8
- for (const node of mutation.addedNodes) {
9
- const el = node as Element
10
- if (el.matches && el.matches(selector)) {
11
- callback(el)
12
- }
13
- }
14
- }
15
- })
16
-
17
- observer.observe(target, {
18
- attributes: true,
19
- childList: true,
20
- subtree: true
21
- })
22
-
23
- return observer
24
- }
@@ -1,21 +0,0 @@
1
- import { observeElement } from './observeElement.js'
2
-
3
- export function waitObserveElement(
4
- selector: string,
5
- disconnect = true,
6
- target = document.body
7
- ): Promise<Element> {
8
- return new Promise((resolve) => {
9
- const observer = observeElement(
10
- selector,
11
- (el) => {
12
- if (disconnect) {
13
- observer.disconnect()
14
- }
15
-
16
- resolve(el)
17
- },
18
- target
19
- )
20
- })
21
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@crashmax/tsconfig",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "include": [
7
- "src/**/*"
8
- ]
9
- }
package/vite.config.ts DELETED
@@ -1,17 +0,0 @@
1
- import { resolve } from 'path'
2
- import { defineConfig } from 'vite'
3
- import dts from 'vite-plugin-dts'
4
- import { name } from './package.json'
5
-
6
- export default defineConfig({
7
- plugins: [dts()],
8
- build: {
9
- target: 'esnext',
10
- lib: {
11
- entry: resolve(__dirname, 'src/index.ts'),
12
- fileName: (format) => `index.${format}.js`,
13
- formats: ['es', 'umd'],
14
- name
15
- }
16
- }
17
- })