@bquery/bquery 1.2.0 → 1.4.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/README.md +127 -27
- package/dist/batch-x7b2eZST.js +13 -0
- package/dist/batch-x7b2eZST.js.map +1 -0
- package/dist/component/component.d.ts +69 -0
- package/dist/component/component.d.ts.map +1 -0
- package/dist/component/html.d.ts +35 -0
- package/dist/component/html.d.ts.map +1 -0
- package/dist/component/index.d.ts +3 -126
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/props.d.ts +18 -0
- package/dist/component/props.d.ts.map +1 -0
- package/dist/component/types.d.ts +77 -0
- package/dist/component/types.d.ts.map +1 -0
- package/dist/component.es.mjs +90 -59
- package/dist/component.es.mjs.map +1 -1
- package/dist/core/collection.d.ts +55 -3
- package/dist/core/collection.d.ts.map +1 -1
- package/dist/core/dom.d.ts +6 -0
- package/dist/core/dom.d.ts.map +1 -0
- package/dist/core/element.d.ts +31 -4
- package/dist/core/element.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/utils/array.d.ts +74 -0
- package/dist/core/utils/array.d.ts.map +1 -0
- package/dist/core/utils/function.d.ts +87 -0
- package/dist/core/utils/function.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/misc.d.ts +63 -0
- package/dist/core/utils/misc.d.ts.map +1 -0
- package/dist/core/utils/number.d.ts +65 -0
- package/dist/core/utils/number.d.ts.map +1 -0
- package/dist/core/utils/object.d.ts +133 -0
- package/dist/core/utils/object.d.ts.map +1 -0
- package/dist/core/utils/string.d.ts +80 -0
- package/dist/core/utils/string.d.ts.map +1 -0
- package/dist/core/utils/type-guards.d.ts +79 -0
- package/dist/core/utils/type-guards.d.ts.map +1 -0
- package/dist/core-BhpuvPhy.js +170 -0
- package/dist/core-BhpuvPhy.js.map +1 -0
- package/dist/core.es.mjs +495 -489
- package/dist/core.es.mjs.map +1 -1
- package/dist/full.d.ts +2 -2
- package/dist/full.d.ts.map +1 -1
- package/dist/full.es.mjs +87 -64
- package/dist/full.es.mjs.map +1 -1
- package/dist/full.iife.js +2 -2
- package/dist/full.iife.js.map +1 -1
- package/dist/full.umd.js +2 -2
- package/dist/full.umd.js.map +1 -1
- package/dist/index.es.mjs +138 -68
- package/dist/index.es.mjs.map +1 -1
- package/dist/motion/animate.d.ts +25 -0
- package/dist/motion/animate.d.ts.map +1 -0
- package/dist/motion/easing.d.ts +30 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/flip.d.ts +55 -0
- package/dist/motion/flip.d.ts.map +1 -0
- package/dist/motion/index.d.ts +11 -138
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/keyframes.d.ts +21 -0
- package/dist/motion/keyframes.d.ts.map +1 -0
- package/dist/motion/reduced-motion.d.ts +12 -0
- package/dist/motion/reduced-motion.d.ts.map +1 -0
- package/dist/motion/scroll.d.ts +15 -0
- package/dist/motion/scroll.d.ts.map +1 -0
- package/dist/motion/spring.d.ts +42 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/stagger.d.ts +22 -0
- package/dist/motion/stagger.d.ts.map +1 -0
- package/dist/motion/timeline.d.ts +21 -0
- package/dist/motion/timeline.d.ts.map +1 -0
- package/dist/motion/transition.d.ts +22 -0
- package/dist/motion/transition.d.ts.map +1 -0
- package/dist/motion/types.d.ts +182 -0
- package/dist/motion/types.d.ts.map +1 -0
- package/dist/motion.es.mjs +320 -61
- package/dist/motion.es.mjs.map +1 -1
- package/dist/persisted-DHoi3uEs.js +278 -0
- package/dist/persisted-DHoi3uEs.js.map +1 -0
- package/dist/platform/storage.d.ts.map +1 -1
- package/dist/platform.es.mjs +12 -7
- package/dist/platform.es.mjs.map +1 -1
- package/dist/reactive/batch.d.ts +13 -0
- package/dist/reactive/batch.d.ts.map +1 -0
- package/dist/reactive/computed.d.ts +50 -0
- package/dist/reactive/computed.d.ts.map +1 -0
- package/dist/reactive/core.d.ts +72 -0
- package/dist/reactive/core.d.ts.map +1 -0
- package/dist/reactive/effect.d.ts +15 -0
- package/dist/reactive/effect.d.ts.map +1 -0
- package/dist/reactive/index.d.ts +2 -2
- package/dist/reactive/index.d.ts.map +1 -1
- package/dist/reactive/internals.d.ts +42 -0
- package/dist/reactive/internals.d.ts.map +1 -0
- package/dist/reactive/linked.d.ts +36 -0
- package/dist/reactive/linked.d.ts.map +1 -0
- package/dist/reactive/persisted.d.ts +14 -0
- package/dist/reactive/persisted.d.ts.map +1 -0
- package/dist/reactive/readonly.d.ts +26 -0
- package/dist/reactive/readonly.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +13 -312
- package/dist/reactive/signal.d.ts.map +1 -1
- package/dist/reactive/type-guards.d.ts +20 -0
- package/dist/reactive/type-guards.d.ts.map +1 -0
- package/dist/reactive/untrack.d.ts +29 -0
- package/dist/reactive/untrack.d.ts.map +1 -0
- package/dist/reactive/watch.d.ts +42 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive.es.mjs +30 -163
- package/dist/reactive.es.mjs.map +1 -1
- package/dist/router/index.d.ts +6 -252
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/links.d.ts +44 -0
- package/dist/router/links.d.ts.map +1 -0
- package/dist/router/match.d.ts +20 -0
- package/dist/router/match.d.ts.map +1 -0
- package/dist/router/navigation.d.ts +45 -0
- package/dist/router/navigation.d.ts.map +1 -0
- package/dist/router/query.d.ts +16 -0
- package/dist/router/query.d.ts.map +1 -0
- package/dist/router/router.d.ts +34 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/state.d.ts +27 -0
- package/dist/router/state.d.ts.map +1 -0
- package/dist/router/types.d.ts +88 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/utils.d.ts +65 -0
- package/dist/router/utils.d.ts.map +1 -0
- package/dist/router.es.mjs +168 -132
- package/dist/router.es.mjs.map +1 -1
- package/dist/sanitize-Cxvxa-DX.js +283 -0
- package/dist/sanitize-Cxvxa-DX.js.map +1 -0
- package/dist/security/constants.d.ts +42 -0
- package/dist/security/constants.d.ts.map +1 -0
- package/dist/security/csp.d.ts +24 -0
- package/dist/security/csp.d.ts.map +1 -0
- package/dist/security/index.d.ts +4 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/sanitize-core.d.ts +13 -0
- package/dist/security/sanitize-core.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +5 -57
- package/dist/security/sanitize.d.ts.map +1 -1
- package/dist/security/trusted-types.d.ts +25 -0
- package/dist/security/trusted-types.d.ts.map +1 -0
- package/dist/security/types.d.ts +36 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security.es.mjs +50 -277
- package/dist/security.es.mjs.map +1 -1
- package/dist/store/create-store.d.ts +15 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/define-store.d.ts +28 -0
- package/dist/store/define-store.d.ts.map +1 -0
- package/dist/store/devtools.d.ts +22 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/index.d.ts +10 -286
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/mapping.d.ts +28 -0
- package/dist/store/mapping.d.ts.map +1 -0
- package/dist/store/persisted.d.ts +13 -0
- package/dist/store/persisted.d.ts.map +1 -0
- package/dist/store/plugins.d.ts +13 -0
- package/dist/store/plugins.d.ts.map +1 -0
- package/dist/store/registry.d.ts +28 -0
- package/dist/store/registry.d.ts.map +1 -0
- package/dist/store/types.d.ts +71 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/utils.d.ts +28 -0
- package/dist/store/utils.d.ts.map +1 -0
- package/dist/store/watch.d.ts +23 -0
- package/dist/store/watch.d.ts.map +1 -0
- package/dist/store.es.mjs +22 -224
- package/dist/store.es.mjs.map +1 -1
- package/dist/type-guards-BdKlYYlS.js +32 -0
- package/dist/type-guards-BdKlYYlS.js.map +1 -0
- package/dist/untrack-DNnnqdlR.js +6 -0
- package/dist/untrack-DNnnqdlR.js.map +1 -0
- package/dist/view/directives/bind.d.ts +7 -0
- package/dist/view/directives/bind.d.ts.map +1 -0
- package/dist/view/directives/class.d.ts +8 -0
- package/dist/view/directives/class.d.ts.map +1 -0
- package/dist/view/directives/for.d.ts +23 -0
- package/dist/view/directives/for.d.ts.map +1 -0
- package/dist/view/directives/html.d.ts +7 -0
- package/dist/view/directives/html.d.ts.map +1 -0
- package/dist/view/directives/if.d.ts +7 -0
- package/dist/view/directives/if.d.ts.map +1 -0
- package/dist/view/directives/index.d.ts +12 -0
- package/dist/view/directives/index.d.ts.map +1 -0
- package/dist/view/directives/model.d.ts +7 -0
- package/dist/view/directives/model.d.ts.map +1 -0
- package/dist/view/directives/on.d.ts +7 -0
- package/dist/view/directives/on.d.ts.map +1 -0
- package/dist/view/directives/ref.d.ts +7 -0
- package/dist/view/directives/ref.d.ts.map +1 -0
- package/dist/view/directives/show.d.ts +7 -0
- package/dist/view/directives/show.d.ts.map +1 -0
- package/dist/view/directives/style.d.ts +7 -0
- package/dist/view/directives/style.d.ts.map +1 -0
- package/dist/view/directives/text.d.ts +7 -0
- package/dist/view/directives/text.d.ts.map +1 -0
- package/dist/view/evaluate.d.ts +43 -0
- package/dist/view/evaluate.d.ts.map +1 -0
- package/dist/view/index.d.ts +3 -93
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/mount.d.ts +69 -0
- package/dist/view/mount.d.ts.map +1 -0
- package/dist/view/process.d.ts +26 -0
- package/dist/view/process.d.ts.map +1 -0
- package/dist/view/types.d.ts +36 -0
- package/dist/view/types.d.ts.map +1 -0
- package/dist/view.es.mjs +358 -251
- package/dist/view.es.mjs.map +1 -1
- package/dist/watch-DXXv3iAI.js +58 -0
- package/dist/watch-DXXv3iAI.js.map +1 -0
- package/package.json +14 -14
- package/src/component/component.ts +289 -0
- package/src/component/html.ts +53 -0
- package/src/component/index.ts +40 -414
- package/src/component/props.ts +116 -0
- package/src/component/types.ts +85 -0
- package/src/core/collection.ts +181 -7
- package/src/core/dom.ts +38 -0
- package/src/core/element.ts +59 -25
- package/src/core/index.ts +48 -4
- package/src/core/utils/array.ts +102 -0
- package/src/core/utils/function.ts +151 -0
- package/src/core/utils/index.ts +83 -0
- package/src/core/utils/misc.ts +82 -0
- package/src/core/utils/number.ts +78 -0
- package/src/core/utils/object.ts +206 -0
- package/src/core/utils/string.ts +112 -0
- package/src/core/utils/type-guards.ts +112 -0
- package/src/full.ts +187 -150
- package/src/index.ts +36 -36
- package/src/motion/animate.ts +113 -0
- package/src/motion/easing.ts +40 -0
- package/src/motion/flip.ts +176 -0
- package/src/motion/index.ts +41 -358
- package/src/motion/keyframes.ts +46 -0
- package/src/motion/reduced-motion.ts +17 -0
- package/src/motion/scroll.ts +57 -0
- package/src/motion/spring.ts +150 -0
- package/src/motion/stagger.ts +43 -0
- package/src/motion/timeline.ts +246 -0
- package/src/motion/transition.ts +51 -0
- package/src/motion/types.ts +198 -0
- package/src/platform/storage.ts +215 -208
- package/src/reactive/batch.ts +22 -0
- package/src/reactive/computed.ts +92 -0
- package/src/reactive/core.ts +114 -0
- package/src/reactive/effect.ts +54 -0
- package/src/reactive/index.ts +23 -22
- package/src/reactive/internals.ts +122 -0
- package/src/reactive/linked.ts +56 -0
- package/src/reactive/persisted.ts +74 -0
- package/src/reactive/readonly.ts +35 -0
- package/src/reactive/signal.ts +20 -520
- package/src/reactive/type-guards.ts +22 -0
- package/src/reactive/untrack.ts +31 -0
- package/src/reactive/watch.ts +73 -0
- package/src/router/index.ts +41 -718
- package/src/router/links.ts +130 -0
- package/src/router/match.ts +106 -0
- package/src/router/navigation.ts +71 -0
- package/src/router/query.ts +35 -0
- package/src/router/router.ts +211 -0
- package/src/router/state.ts +46 -0
- package/src/router/types.ts +93 -0
- package/src/router/utils.ts +116 -0
- package/src/security/constants.ts +209 -0
- package/src/security/csp.ts +77 -0
- package/src/security/index.ts +4 -12
- package/src/security/sanitize-core.ts +364 -0
- package/src/security/sanitize.ts +66 -625
- package/src/security/trusted-types.ts +69 -0
- package/src/security/types.ts +40 -0
- package/src/store/create-store.ts +329 -0
- package/src/store/define-store.ts +48 -0
- package/src/store/devtools.ts +45 -0
- package/src/store/index.ts +22 -848
- package/src/store/mapping.ts +73 -0
- package/src/store/persisted.ts +61 -0
- package/src/store/plugins.ts +32 -0
- package/src/store/registry.ts +51 -0
- package/src/store/types.ts +94 -0
- package/src/store/utils.ts +141 -0
- package/src/store/watch.ts +52 -0
- package/src/view/directives/bind.ts +23 -0
- package/src/view/directives/class.ts +70 -0
- package/src/view/directives/for.ts +275 -0
- package/src/view/directives/html.ts +19 -0
- package/src/view/directives/if.ts +30 -0
- package/src/view/directives/index.ts +11 -0
- package/src/view/directives/model.ts +56 -0
- package/src/view/directives/on.ts +41 -0
- package/src/view/directives/ref.ts +41 -0
- package/src/view/directives/show.ts +26 -0
- package/src/view/directives/style.ts +47 -0
- package/src/view/directives/text.ts +15 -0
- package/src/view/evaluate.ts +290 -0
- package/src/view/index.ts +112 -1041
- package/src/view/mount.ts +200 -0
- package/src/view/process.ts +92 -0
- package/src/view/types.ts +44 -0
- package/dist/core/utils.d.ts +0 -313
- package/dist/core/utils.d.ts.map +0 -1
- package/src/core/utils.ts +0 -444
package/dist/component.es.mjs
CHANGED
|
@@ -1,43 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
return Number
|
|
1
|
+
import { s as h } from "./sanitize-Cxvxa-DX.js";
|
|
2
|
+
const p = (e, r) => {
|
|
3
|
+
const { type: s } = r;
|
|
4
|
+
if (s === String) return e;
|
|
5
|
+
if (s === Number)
|
|
6
|
+
return Number(e);
|
|
7
|
+
if (s === Boolean) {
|
|
8
|
+
const c = e.trim().toLowerCase();
|
|
9
|
+
return c === "" || c === "true" || c === "1" ? !0 : c === "false" || c === "0" ? !1 : !!e;
|
|
7
10
|
}
|
|
8
|
-
if (
|
|
9
|
-
const s = e.trim().toLowerCase();
|
|
10
|
-
return s === "" || s === "true" || s === "1" ? !0 : s === "false" || s === "0" ? !1 : !!e;
|
|
11
|
-
}
|
|
12
|
-
if (o === Object || o === Array)
|
|
11
|
+
if (s === Object || s === Array)
|
|
13
12
|
try {
|
|
14
13
|
return JSON.parse(e);
|
|
15
14
|
} catch {
|
|
16
15
|
return e;
|
|
17
16
|
}
|
|
18
|
-
if (typeof
|
|
19
|
-
const
|
|
17
|
+
if (typeof s == "function") {
|
|
18
|
+
const c = s, t = s;
|
|
19
|
+
if (r.construct === !0)
|
|
20
|
+
return Reflect.construct(t, [e]);
|
|
21
|
+
if (r.construct === !1)
|
|
22
|
+
return c(e);
|
|
23
|
+
const o = s.prototype !== void 0 && s.prototype !== null, u = (o ? Object.getOwnPropertyNames(s.prototype) : []).length > 1, n = o && s.prototype.constructor !== s, l = /^class\s/.test(Function.prototype.toString.call(s));
|
|
24
|
+
if (u || n || l)
|
|
25
|
+
try {
|
|
26
|
+
return Reflect.construct(t, [e]);
|
|
27
|
+
} catch {
|
|
28
|
+
return c(e);
|
|
29
|
+
}
|
|
20
30
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const a = c(e);
|
|
32
|
+
if (a === void 0 && o)
|
|
33
|
+
try {
|
|
34
|
+
return Reflect.construct(t, [e]);
|
|
35
|
+
} catch {
|
|
36
|
+
return a;
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
} catch (a) {
|
|
40
|
+
if (a instanceof TypeError && /cannot be invoked without 'new'|is not a function/i.test(a.message))
|
|
41
|
+
return Reflect.construct(t, [e]);
|
|
42
|
+
throw a;
|
|
24
43
|
}
|
|
25
44
|
}
|
|
26
45
|
return e;
|
|
27
|
-
}, p = (e, ...r) => e.reduce((o, s, t) => `${o}${s}${r[t] ?? ""}`, ""), i = (e, ...r) => {
|
|
28
|
-
const o = {
|
|
29
|
-
"&": "&",
|
|
30
|
-
"<": "<",
|
|
31
|
-
">": ">",
|
|
32
|
-
'"': """,
|
|
33
|
-
"'": "'",
|
|
34
|
-
"`": "`"
|
|
35
|
-
}, s = (t) => String(t ?? "").replace(/[&<>"'`]/g, (n) => o[n]);
|
|
36
|
-
return e.reduce((t, c, n) => `${t}${c}${s(r[n])}`, "");
|
|
37
46
|
}, d = (e, r) => {
|
|
38
|
-
class
|
|
47
|
+
class s extends HTMLElement {
|
|
39
48
|
constructor() {
|
|
40
|
-
super(), this.state = { ...r.state ?? {} }, this.props = {}, this.attachShadow({ mode: "open" }), this.syncProps();
|
|
49
|
+
super(), this.state = { ...r.state ?? {} }, this.props = {}, this.missingRequiredProps = /* @__PURE__ */ new Set(), this.hasMounted = !1, this.attachShadow({ mode: "open" }), this.syncProps();
|
|
41
50
|
}
|
|
42
51
|
/**
|
|
43
52
|
* Returns the list of attributes to observe for changes.
|
|
@@ -50,11 +59,21 @@ const u = (e, r) => {
|
|
|
50
59
|
*/
|
|
51
60
|
connectedCallback() {
|
|
52
61
|
try {
|
|
53
|
-
|
|
62
|
+
if (this.missingRequiredProps.size > 0)
|
|
63
|
+
return;
|
|
64
|
+
this.mount();
|
|
54
65
|
} catch (t) {
|
|
55
66
|
this.handleError(t);
|
|
56
67
|
}
|
|
57
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Performs the initial mount of the component.
|
|
71
|
+
* Called when the element is connected and all required props are present.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
mount() {
|
|
75
|
+
this.hasMounted || (r.beforeMount?.call(this), r.connected?.call(this), this.render(), this.hasMounted = !0);
|
|
76
|
+
}
|
|
58
77
|
/**
|
|
59
78
|
* Called when the element is removed from the DOM.
|
|
60
79
|
*/
|
|
@@ -68,11 +87,11 @@ const u = (e, r) => {
|
|
|
68
87
|
/**
|
|
69
88
|
* Called when an observed attribute changes.
|
|
70
89
|
*/
|
|
71
|
-
attributeChangedCallback() {
|
|
90
|
+
attributeChangedCallback(t, o, i) {
|
|
72
91
|
try {
|
|
73
|
-
this.syncProps(), this.render(!0);
|
|
74
|
-
} catch (
|
|
75
|
-
this.handleError(
|
|
92
|
+
this.syncProps(), this.hasMounted ? this.render(!0) : this.isConnected && this.missingRequiredProps.size === 0 && this.mount();
|
|
93
|
+
} catch (u) {
|
|
94
|
+
this.handleError(u);
|
|
76
95
|
}
|
|
77
96
|
}
|
|
78
97
|
/**
|
|
@@ -88,8 +107,8 @@ const u = (e, r) => {
|
|
|
88
107
|
* @param key - The state property key
|
|
89
108
|
* @param value - The new value
|
|
90
109
|
*/
|
|
91
|
-
setState(t,
|
|
92
|
-
this.state[t] =
|
|
110
|
+
setState(t, o) {
|
|
111
|
+
this.state[t] = o, this.render(!0);
|
|
93
112
|
}
|
|
94
113
|
/**
|
|
95
114
|
* Gets a state property value.
|
|
@@ -106,20 +125,14 @@ const u = (e, r) => {
|
|
|
106
125
|
*/
|
|
107
126
|
syncProps() {
|
|
108
127
|
const t = r.props ?? {};
|
|
109
|
-
for (const [
|
|
110
|
-
const
|
|
111
|
-
let
|
|
112
|
-
if (
|
|
113
|
-
if (n.required && n.default === void 0)
|
|
114
|
-
throw new Error(`bQuery component: missing required prop "${c}"`);
|
|
115
|
-
a = n.default ?? void 0;
|
|
116
|
-
} else
|
|
117
|
-
a = u(l, n);
|
|
118
|
-
if (n.validator && a !== void 0 && !n.validator(a))
|
|
128
|
+
for (const [o, i] of Object.entries(t)) {
|
|
129
|
+
const u = this.getAttribute(o);
|
|
130
|
+
let n;
|
|
131
|
+
if (u == null ? i.required && i.default === void 0 ? (this.missingRequiredProps.add(o), n = void 0) : n = i.default ?? void 0 : (this.missingRequiredProps.has(o) && this.missingRequiredProps.delete(o), n = p(u, i)), i.validator && n !== void 0 && !i.validator(n))
|
|
119
132
|
throw new Error(
|
|
120
|
-
`bQuery component: validation failed for prop "${
|
|
133
|
+
`bQuery component: validation failed for prop "${o}" with value ${JSON.stringify(n)}`
|
|
121
134
|
);
|
|
122
|
-
this.props[
|
|
135
|
+
this.props[o] = n;
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
138
|
/**
|
|
@@ -130,26 +143,44 @@ const u = (e, r) => {
|
|
|
130
143
|
try {
|
|
131
144
|
if (t && r.beforeUpdate && r.beforeUpdate.call(this, this.props) === !1)
|
|
132
145
|
return;
|
|
133
|
-
const
|
|
134
|
-
this.dispatchEvent(new CustomEvent(
|
|
146
|
+
const o = (n, l) => {
|
|
147
|
+
this.dispatchEvent(new CustomEvent(n, { detail: l, bubbles: !0, composed: !0 }));
|
|
135
148
|
};
|
|
136
149
|
if (!this.shadowRoot) return;
|
|
137
|
-
const
|
|
150
|
+
const i = r.render({
|
|
138
151
|
props: this.props,
|
|
139
152
|
state: this.state,
|
|
140
|
-
emit:
|
|
141
|
-
}),
|
|
142
|
-
this.shadowRoot.innerHTML =
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
emit: o
|
|
154
|
+
}), u = h(i);
|
|
155
|
+
if (this.shadowRoot.innerHTML = u, r.styles) {
|
|
156
|
+
const n = document.createElement("style");
|
|
157
|
+
n.textContent = r.styles, this.shadowRoot.prepend(n);
|
|
158
|
+
}
|
|
159
|
+
t && r.updated?.call(this);
|
|
160
|
+
} catch (o) {
|
|
161
|
+
this.handleError(o);
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
}
|
|
148
|
-
|
|
165
|
+
return s;
|
|
166
|
+
}, b = (e, r) => {
|
|
167
|
+
const s = d(e, r);
|
|
168
|
+
customElements.get(e) || customElements.define(e, s);
|
|
169
|
+
}, E = (e, ...r) => e.reduce((s, c, t) => `${s}${c}${r[t] ?? ""}`, ""), g = (e, ...r) => {
|
|
170
|
+
const s = {
|
|
171
|
+
"&": "&",
|
|
172
|
+
"<": "<",
|
|
173
|
+
">": ">",
|
|
174
|
+
'"': """,
|
|
175
|
+
"'": "'",
|
|
176
|
+
"`": "`"
|
|
177
|
+
}, c = (t) => String(t ?? "").replace(/[&<>"'`]/g, (i) => s[i]);
|
|
178
|
+
return e.reduce((t, o, i) => `${t}${o}${c(r[i])}`, "");
|
|
149
179
|
};
|
|
150
180
|
export {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
181
|
+
b as component,
|
|
182
|
+
d as defineComponent,
|
|
183
|
+
E as html,
|
|
184
|
+
g as safeHtml
|
|
154
185
|
};
|
|
155
186
|
//# sourceMappingURL=component.es.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.es.mjs","sources":["../src/component/index.ts"],"sourcesContent":["/**\r\n * Minimal Web Component helper for building custom elements.\r\n *\r\n * This module provides a declarative API for defining Web Components\r\n * without complex build steps. Features include:\r\n * - Type-safe props with automatic attribute coercion\r\n * - Reactive state management\r\n * - Shadow DOM encapsulation with scoped styles\r\n * - Lifecycle hooks (connected, disconnected)\r\n * - Event emission helpers\r\n *\r\n * @module bquery/component\r\n *\r\n * @example\r\n * ```ts\r\n * import { component, html } from 'bquery/component';\r\n *\r\n * component('user-card', {\r\n * props: {\r\n * username: { type: String, required: true },\r\n * avatar: { type: String, default: '/default-avatar.png' },\r\n * },\r\n * styles: `\r\n * .card { padding: 1rem; border: 1px solid #ccc; }\r\n * `,\r\n * render({ props }) {\r\n * return html`\r\n * <div class=\"card\">\r\n * <img src=\"${props.avatar}\" alt=\"${props.username}\" />\r\n * <h3>${props.username}</h3>\r\n * </div>\r\n * `;\r\n * },\r\n * });\r\n * ```\r\n */\r\n\r\n/**\r\n * Defines a single prop's type and configuration.\r\n *\r\n * @template T - The TypeScript type of the prop value\r\n *\r\n * @example\r\n * ```ts\r\n * const myProp: PropDefinition<number> = {\r\n * type: Number,\r\n * required: false,\r\n * default: 0,\r\n * };\r\n * ```\r\n */\r\nexport type PropDefinition<T = unknown> = {\r\n /** Constructor or converter function for the prop type */\r\n type:\r\n | StringConstructor\r\n | NumberConstructor\r\n | BooleanConstructor\r\n | ObjectConstructor\r\n | ArrayConstructor\r\n | { new (value: unknown): T }\r\n | ((value: unknown) => T);\r\n /** Whether the prop must be provided */\r\n required?: boolean;\r\n /** Default value when prop is not provided */\r\n default?: T;\r\n /** Optional validator function to validate prop values */\r\n validator?: (value: T) => boolean;\r\n};\r\n\r\n/**\r\n * Complete component definition including props, state, styles, and lifecycle.\r\n *\r\n * @template TProps - Type of the component's props\r\n */\r\nexport type ComponentDefinition<TProps extends Record<string, unknown> = Record<string, unknown>> =\r\n {\r\n /** Prop definitions with types and defaults */\r\n props?: Record<keyof TProps, PropDefinition>;\r\n /** Initial internal state */\r\n state?: Record<string, unknown>;\r\n /** CSS styles scoped to the component's shadow DOM */\r\n styles?: string;\r\n /** Lifecycle hook called before the component mounts (before first render) */\r\n beforeMount?: () => void;\r\n /** Lifecycle hook called when component is added to DOM */\r\n connected?: () => void;\r\n /** Lifecycle hook called when component is removed from DOM */\r\n disconnected?: () => void;\r\n /** Lifecycle hook called before an update render; return false to prevent */\r\n beforeUpdate?: (props: TProps) => boolean | void;\r\n /** Lifecycle hook called after reactive updates trigger a render */\r\n updated?: () => void;\r\n /** Error handler for errors during rendering or lifecycle */\r\n onError?: (error: Error) => void;\r\n /** Render function returning HTML string */\r\n render: (context: {\r\n props: TProps;\r\n state: Record<string, unknown>;\r\n emit: (event: string, detail?: unknown) => void;\r\n }) => string;\r\n };\r\n\r\n/**\r\n * Coerces a string attribute value into a typed prop value.\r\n * Supports String, Number, Boolean, Object, Array, and custom converters.\r\n *\r\n * @internal\r\n * @template T - The target type\r\n * @param rawValue - The raw string value from the attribute\r\n * @param config - The prop definition with type information\r\n * @returns The coerced value of type T\r\n */\r\nconst coercePropValue = <T>(rawValue: string, config: PropDefinition<T>): T => {\r\n const { type } = config;\r\n\r\n if (type === String) return rawValue as T;\r\n\r\n if (type === Number) {\r\n const parsed = Number(rawValue);\r\n return (Number.isNaN(parsed) ? rawValue : parsed) as T;\r\n }\r\n\r\n if (type === Boolean) {\r\n const normalized = rawValue.trim().toLowerCase();\r\n if (normalized === '' || normalized === 'true' || normalized === '1') {\r\n return true as T;\r\n }\r\n if (normalized === 'false' || normalized === '0') {\r\n return false as T;\r\n }\r\n return Boolean(rawValue) as T;\r\n }\r\n\r\n if (type === Object || type === Array) {\r\n try {\r\n return JSON.parse(rawValue) as T;\r\n } catch {\r\n return rawValue as T;\r\n }\r\n }\r\n\r\n if (typeof type === 'function') {\r\n const callable = type as (value: unknown) => T;\r\n const constructable = type as new (value: unknown) => T;\r\n try {\r\n return callable(rawValue);\r\n } catch {\r\n return new constructable(rawValue);\r\n }\r\n }\r\n\r\n return rawValue as T;\r\n};\r\n\r\n/**\r\n * Tagged template literal for creating HTML strings.\r\n *\r\n * This function handles interpolation of values into HTML templates,\r\n * converting null/undefined to empty strings.\r\n *\r\n * @param strings - Template literal string parts\r\n * @param values - Interpolated values\r\n * @returns Combined HTML string\r\n *\r\n * @example\r\n * ```ts\r\n * const name = 'World';\r\n * const greeting = html`<h1>Hello, ${name}!</h1>`;\r\n * // Result: '<h1>Hello, World!</h1>'\r\n * ```\r\n */\r\nexport const html = (strings: TemplateStringsArray, ...values: unknown[]): string => {\r\n return strings.reduce((acc, part, index) => `${acc}${part}${values[index] ?? ''}`, '');\r\n};\r\n\r\n/**\r\n * Escapes HTML entities in interpolated values for XSS prevention.\r\n * Use this when you need to safely embed user content in templates.\r\n *\r\n * @param strings - Template literal string parts\r\n * @param values - Interpolated values to escape\r\n * @returns Combined HTML string with escaped values\r\n *\r\n * @example\r\n * ```ts\r\n * const userInput = '<script>alert(\"xss\")</script>';\r\n * const safe = safeHtml`<div>${userInput}</div>`;\r\n * // Result: '<div><script>alert(\"xss\")</script></div>'\r\n * ```\r\n */\r\nexport const safeHtml = (strings: TemplateStringsArray, ...values: unknown[]): string => {\r\n const escapeMap: Record<string, string> = {\r\n '&': '&',\r\n '<': '<',\r\n '>': '>',\r\n '\"': '"',\r\n \"'\": ''',\r\n '`': '`',\r\n };\r\n\r\n const escape = (value: unknown): string => {\r\n const str = String(value ?? '');\r\n return str.replace(/[&<>\"'`]/g, (char) => escapeMap[char]);\r\n };\r\n\r\n return strings.reduce((acc, part, index) => `${acc}${part}${escape(values[index])}`, '');\r\n};\r\n\r\n/**\r\n * Defines and registers a custom Web Component.\r\n *\r\n * This function creates a new custom element with the given tag name\r\n * and configuration. The component uses Shadow DOM for encapsulation\r\n * and automatically re-renders when observed attributes change.\r\n *\r\n * @template TProps - Type of the component's props\r\n * @param tagName - The custom element tag name (must contain a hyphen)\r\n * @param definition - The component configuration\r\n *\r\n * @example\r\n * ```ts\r\n * component('counter-button', {\r\n * props: {\r\n * start: { type: Number, default: 0 },\r\n * },\r\n * state: { count: 0 },\r\n * styles: `\r\n * button { padding: 0.5rem 1rem; }\r\n * `,\r\n * connected() {\r\n * console.log('Counter mounted');\r\n * },\r\n * render({ props, state, emit }) {\r\n * return html`\r\n * <button onclick=\"this.getRootNode().host.increment()\">\r\n * Count: ${state.count}\r\n * </button>\r\n * `;\r\n * },\r\n * });\r\n * ```\r\n */\r\nexport const component = <TProps extends Record<string, unknown>>(\r\n tagName: string,\r\n definition: ComponentDefinition<TProps>\r\n): void => {\r\n /**\r\n * Internal Web Component class created for each component definition.\r\n * @internal\r\n */\r\n class BQueryComponent extends HTMLElement {\r\n /** Internal state object for the component */\r\n private readonly state = { ...(definition.state ?? {}) };\r\n /** Typed props object populated from attributes */\r\n private props = {} as TProps;\r\n\r\n constructor() {\r\n super();\r\n this.attachShadow({ mode: 'open' });\r\n this.syncProps();\r\n }\r\n\r\n /**\r\n * Returns the list of attributes to observe for changes.\r\n */\r\n static get observedAttributes(): string[] {\r\n return Object.keys(definition.props ?? {});\r\n }\r\n\r\n /**\r\n * Called when the element is added to the DOM.\r\n */\r\n connectedCallback(): void {\r\n try {\r\n definition.beforeMount?.call(this);\r\n definition.connected?.call(this);\r\n this.render();\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Called when the element is removed from the DOM.\r\n */\r\n disconnectedCallback(): void {\r\n try {\r\n definition.disconnected?.call(this);\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Called when an observed attribute changes.\r\n */\r\n attributeChangedCallback(): void {\r\n try {\r\n this.syncProps();\r\n this.render(true);\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n\r\n /**\r\n * Handles errors during component lifecycle.\r\n * @internal\r\n */\r\n private handleError(error: Error): void {\r\n if (definition.onError) {\r\n definition.onError.call(this, error);\r\n } else {\r\n console.error(`bQuery component error in <${tagName}>:`, error);\r\n }\r\n }\r\n\r\n /**\r\n * Updates a state property and triggers a re-render.\r\n *\r\n * @param key - The state property key\r\n * @param value - The new value\r\n */\r\n setState(key: string, value: unknown): void {\r\n this.state[key] = value;\r\n this.render(true);\r\n }\r\n\r\n /**\r\n * Gets a state property value.\r\n *\r\n * @param key - The state property key\r\n * @returns The current value\r\n */\r\n getState<T = unknown>(key: string): T {\r\n return this.state[key] as T;\r\n }\r\n\r\n /**\r\n * Synchronizes props from attributes.\r\n * @internal\r\n */\r\n private syncProps(): void {\r\n const props = definition.props ?? {};\r\n for (const [key, config] of Object.entries(props) as [string, PropDefinition][]) {\r\n const attrValue = this.getAttribute(key);\r\n let value: unknown;\r\n\r\n if (attrValue == null) {\r\n if (config.required && config.default === undefined) {\r\n throw new Error(`bQuery component: missing required prop \"${key}\"`);\r\n }\r\n value = config.default ?? undefined;\r\n } else {\r\n value = coercePropValue(attrValue, config);\r\n }\r\n\r\n // Validate the prop value if a validator is provided\r\n if (config.validator && value !== undefined) {\r\n const isValid = config.validator(value);\r\n if (!isValid) {\r\n throw new Error(\r\n `bQuery component: validation failed for prop \"${key}\" with value ${JSON.stringify(value)}`\r\n );\r\n }\r\n }\r\n\r\n (this.props as Record<string, unknown>)[key] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Renders the component to its shadow root.\r\n * @internal\r\n */\r\n private render(triggerUpdated = false): void {\r\n try {\r\n // Check beforeUpdate hook if this is an update\r\n if (triggerUpdated && definition.beforeUpdate) {\r\n const shouldUpdate = definition.beforeUpdate.call(this, this.props);\r\n if (shouldUpdate === false) return;\r\n }\r\n\r\n /**\r\n * Emits a custom event from the component.\r\n */\r\n const emit = (event: string, detail?: unknown): void => {\r\n this.dispatchEvent(new CustomEvent(event, { detail, bubbles: true, composed: true }));\r\n };\r\n\r\n if (!this.shadowRoot) return;\r\n\r\n const markup = definition.render({\r\n props: this.props,\r\n state: this.state,\r\n emit,\r\n });\r\n\r\n const styles = definition.styles ? `<style>${definition.styles}</style>` : '';\r\n this.shadowRoot.innerHTML = `${styles}${markup}`;\r\n\r\n if (triggerUpdated) {\r\n definition.updated?.call(this);\r\n }\r\n } catch (error) {\r\n this.handleError(error as Error);\r\n }\r\n }\r\n }\r\n\r\n if (!customElements.get(tagName)) {\r\n customElements.define(tagName, BQueryComponent);\r\n }\r\n};\r\n"],"names":["coercePropValue","rawValue","config","type","parsed","normalized","callable","constructable","html","strings","values","acc","part","index","safeHtml","escapeMap","escape","value","char","component","tagName","definition","BQueryComponent","error","key","props","attrValue","triggerUpdated","emit","event","detail","markup","styles"],"mappings":"AAgHA,MAAMA,IAAkB,CAAIC,GAAkBC,MAAiC;AAC7E,QAAM,EAAE,MAAAC,MAASD;AAEjB,MAAIC,MAAS,OAAQ,QAAOF;AAE5B,MAAIE,MAAS,QAAQ;AACnB,UAAMC,IAAS,OAAOH,CAAQ;AAC9B,WAAQ,OAAO,MAAMG,CAAM,IAAIH,IAAWG;AAAA,EAC5C;AAEA,MAAID,MAAS,SAAS;AACpB,UAAME,IAAaJ,EAAS,KAAA,EAAO,YAAA;AACnC,WAAII,MAAe,MAAMA,MAAe,UAAUA,MAAe,MACxD,KAELA,MAAe,WAAWA,MAAe,MACpC,KAEF,EAAQJ;AAAA,EACjB;AAEA,MAAIE,MAAS,UAAUA,MAAS;AAC9B,QAAI;AACF,aAAO,KAAK,MAAMF,CAAQ;AAAA,IAC5B,QAAQ;AACN,aAAOA;AAAA,IACT;AAGF,MAAI,OAAOE,KAAS,YAAY;AAC9B,UAAM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EAAO,UAAUe,CAAK;AAEpC,gBAAM,IAAI;AAAA,YACR,iDAAiDO,CAAG,gBAAgB,KAAK,UAAUP,CAAK,CAAC;AAAA,UAAA;AAK9F,aAAK,MAAkCO,CAAG,IAAIP;AAAA,MACjD;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMQ,OAAOU,IAAiB,IAAa;AAC3C,UAAI;AAEF,YAAIA,KAAkBN,EAAW,gBACVA,EAAW,aAAa,KAAK,MAAM,KAAK,KAAK,MAC7C;AAAO;AAM9B,cAAMO,IAAO,CAACC,GAAeC,MAA2B;AACtD,eAAK,cAAc,IAAI,YAAYD,GAAO,EAAE,QAAAC,GAAQ,SAAS,IAAM,UAAU,GAAA,CAAM,CAAC;AAAA,QACtF;AAEA,YAAI,CAAC,KAAK,WAAY;AAEtB,cAAMC,IAASV,EAAW,OAAO;AAAA,UAC/B,OAAO,KAAK;AAAA,UACZ,OAAO,KAAK;AAAA,UACZ,MAAAO;AAAA,QAAA,CACD,GAEKI,IAASX,EAAW,SAAS,UAAUA,EAAW,MAAM,aAAa;AAC3E,aAAK,WAAW,YAAY,GAAGW,CAAM,GAAGD,CAAM,IAE1CJ,KACFN,EAAW,SAAS,KAAK,IAAI;AAAA,MAEjC,SAASE,GAAO;AACd,aAAK,YAAYA,CAAc;AAAA,MACjC;AAAA,IACF;AAAA,EAAA;AAGF,EAAK,eAAe,IAAIH,CAAO,KAC7B,eAAe,OAAOA,GAASE,CAAe;AAElD;"}
|
|
1
|
+
{"version":3,"file":"component.es.mjs","sources":["../src/component/props.ts","../src/component/component.ts","../src/component/html.ts"],"sourcesContent":["/**\n * Prop coercion utilities.\n *\n * @module bquery/component\n */\n\nimport type { PropDefinition } from './types';\n\n/**\n * Coerces a string attribute value into a typed prop value.\n * Supports String, Number, Boolean, Object, Array, and custom converters.\n *\n * @internal\n * @template T - The target type\n * @param rawValue - The raw string value from the attribute\n * @param config - The prop definition with type information\n * @returns The coerced value of type T\n */\nexport const coercePropValue = <T>(rawValue: string, config: PropDefinition<T>): T => {\n const { type } = config;\n\n if (type === String) return rawValue as T;\n\n if (type === Number) {\n return Number(rawValue) as T;\n }\n\n if (type === Boolean) {\n const normalized = rawValue.trim().toLowerCase();\n if (normalized === '' || normalized === 'true' || normalized === '1') {\n return true as T;\n }\n if (normalized === 'false' || normalized === '0') {\n return false as T;\n }\n return Boolean(rawValue) as T;\n }\n\n if (type === Object || type === Array) {\n try {\n return JSON.parse(rawValue) as T;\n } catch {\n return rawValue as T;\n }\n }\n\n if (typeof type === 'function') {\n const callable = type as (value: unknown) => T;\n const constructable = type as new (value: unknown) => T;\n\n // Explicit construct mode takes precedence\n if (config.construct === true) {\n return Reflect.construct(constructable, [rawValue]) as T;\n }\n if (config.construct === false) {\n return callable(rawValue);\n }\n\n // Auto-detect: Check if type is constructable\n // A function is considered constructable if:\n // 1. It has a prototype with properties beyond just constructor, OR\n // 2. Its prototype.constructor is not itself (inherited), OR\n // 3. It's a class (toString starts with \"class\")\n const hasPrototype = type.prototype !== undefined && type.prototype !== null;\n const prototypeProps = hasPrototype ? Object.getOwnPropertyNames(type.prototype) : [];\n const hasPrototypeMethods = prototypeProps.length > 1;\n const hasInheritedConstructor = hasPrototype && type.prototype.constructor !== type;\n const isClassSyntax = /^class\\s/.test(Function.prototype.toString.call(type));\n\n const isConstructable = hasPrototypeMethods || hasInheritedConstructor || isClassSyntax;\n\n // For constructable types (e.g. Date, custom classes), prefer `new` to avoid\n // silent wrong-type returns (Date() returns string, new Date() returns Date)\n if (isConstructable) {\n try {\n return Reflect.construct(constructable, [rawValue]) as T;\n } catch {\n // Fall back to calling as function if construction fails\n return callable(rawValue);\n }\n }\n\n // For non-constructable types (arrow functions, plain functions), call directly\n // but fall back to constructor if result is undefined (common for function constructors)\n try {\n const result = callable(rawValue);\n\n // If calling without `new` returned undefined and the function has a prototype,\n // it's likely a function constructor that should be called with `new`\n if (result === undefined && hasPrototype) {\n try {\n return Reflect.construct(constructable, [rawValue]) as T;\n } catch {\n // Construction also failed, return the undefined\n return result as T;\n }\n }\n\n return result as T;\n } catch (error) {\n // Fall back to constructor if error indicates 'new' is required\n const isNewRequired =\n error instanceof TypeError &&\n /cannot be invoked without 'new'|is not a function/i.test(error.message);\n\n if (isNewRequired) {\n return Reflect.construct(constructable, [rawValue]) as T;\n }\n\n // Rethrow original error for non-constructable converters\n throw error;\n }\n }\n\n return rawValue as T;\n};\n","/**\n * Web Component factory and registry.\n *\n * @module bquery/component\n */\n\nimport { sanitizeHtml } from '../security/sanitize';\nimport { coercePropValue } from './props';\nimport type { ComponentDefinition, PropDefinition } from './types';\n\n/**\n * Creates a custom element class for a component definition.\n *\n * This is useful when you want to extend or register the class manually\n * (e.g. with different tag names in tests or custom registries).\n *\n * @template TProps - Type of the component's props\n * @param tagName - The custom element tag name (used for diagnostics)\n * @param definition - The component configuration\n */\nexport const defineComponent = <TProps extends Record<string, unknown>>(\n tagName: string,\n definition: ComponentDefinition<TProps>\n): typeof HTMLElement => {\n class BQueryComponent extends HTMLElement {\n /** Internal state object for the component */\n private readonly state = { ...(definition.state ?? {}) };\n /** Typed props object populated from attributes */\n private props = {} as TProps;\n /** Tracks missing required props for validation during connectedCallback */\n private missingRequiredProps = new Set<string>();\n /** Tracks whether the component has completed its initial mount */\n private hasMounted = false;\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n this.syncProps();\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n */\n static get observedAttributes(): string[] {\n return Object.keys(definition.props ?? {});\n }\n\n /**\n * Called when the element is added to the DOM.\n */\n connectedCallback(): void {\n try {\n // Defer initial render until all required props are present\n // This allows attributes to be set after element creation\n if (this.missingRequiredProps.size > 0) {\n // Component will mount once all required props are satisfied\n // via attributeChangedCallback\n return;\n }\n this.mount();\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Performs the initial mount of the component.\n * Called when the element is connected and all required props are present.\n * @internal\n */\n private mount(): void {\n if (this.hasMounted) return;\n definition.beforeMount?.call(this);\n definition.connected?.call(this);\n this.render();\n this.hasMounted = true;\n }\n\n /**\n * Called when the element is removed from the DOM.\n */\n disconnectedCallback(): void {\n try {\n definition.disconnected?.call(this);\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Called when an observed attribute changes.\n */\n attributeChangedCallback(\n _name: string,\n _oldValue: string | null,\n _newValue: string | null\n ): void {\n try {\n this.syncProps();\n\n if (this.hasMounted) {\n // Component already mounted - trigger update render\n this.render(true);\n } else if (this.isConnected && this.missingRequiredProps.size === 0) {\n // All required props are now satisfied and element is connected\n // Trigger the deferred initial mount\n this.mount();\n }\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n\n /**\n * Handles errors during component lifecycle.\n * @internal\n */\n private handleError(error: Error): void {\n if (definition.onError) {\n definition.onError.call(this, error);\n } else {\n console.error(`bQuery component error in <${tagName}>:`, error);\n }\n }\n\n /**\n * Updates a state property and triggers a re-render.\n *\n * @param key - The state property key\n * @param value - The new value\n */\n setState(key: string, value: unknown): void {\n this.state[key] = value;\n this.render(true);\n }\n\n /**\n * Gets a state property value.\n *\n * @param key - The state property key\n * @returns The current value\n */\n getState<T = unknown>(key: string): T {\n return this.state[key] as T;\n }\n\n /**\n * Synchronizes props from attributes.\n * @internal\n */\n private syncProps(): void {\n const props = definition.props ?? {};\n for (const [key, config] of Object.entries(props) as [string, PropDefinition][]) {\n const attrValue = this.getAttribute(key);\n let value: unknown;\n\n if (attrValue == null) {\n if (config.required && config.default === undefined) {\n // Mark as missing instead of throwing - validate during connectedCallback\n this.missingRequiredProps.add(key);\n value = undefined;\n } else {\n value = config.default ?? undefined;\n }\n } else {\n // Attribute is present, remove from missing set if it was there\n if (this.missingRequiredProps.has(key)) {\n this.missingRequiredProps.delete(key);\n }\n value = coercePropValue(attrValue, config);\n }\n\n if (config.validator && value !== undefined) {\n const isValid = config.validator(value);\n if (!isValid) {\n throw new Error(\n `bQuery component: validation failed for prop \"${key}\" with value ${JSON.stringify(value)}`\n );\n }\n }\n\n (this.props as Record<string, unknown>)[key] = value;\n }\n }\n\n /**\n * Renders the component to its shadow root.\n * @internal\n */\n private render(triggerUpdated = false): void {\n try {\n if (triggerUpdated && definition.beforeUpdate) {\n const shouldUpdate = definition.beforeUpdate.call(this, this.props);\n if (shouldUpdate === false) return;\n }\n\n const emit = (event: string, detail?: unknown): void => {\n this.dispatchEvent(new CustomEvent(event, { detail, bubbles: true, composed: true }));\n };\n\n if (!this.shadowRoot) return;\n\n const markup = definition.render({\n props: this.props,\n state: this.state,\n emit,\n });\n\n const sanitizedMarkup = sanitizeHtml(markup);\n this.shadowRoot.innerHTML = sanitizedMarkup;\n\n if (definition.styles) {\n const styleElement = document.createElement('style');\n styleElement.textContent = definition.styles;\n this.shadowRoot.prepend(styleElement);\n }\n\n if (triggerUpdated) {\n definition.updated?.call(this);\n }\n } catch (error) {\n this.handleError(error as Error);\n }\n }\n }\n\n return BQueryComponent;\n};\n\n/**\n * Defines and registers a custom Web Component.\n *\n * This function creates a new custom element with the given tag name\n * and configuration. The component uses Shadow DOM for encapsulation\n * and automatically re-renders when observed attributes change.\n *\n * @template TProps - Type of the component's props\n * @param tagName - The custom element tag name (must contain a hyphen)\n * @param definition - The component configuration\n *\n * @example\n * ```ts\n * component('counter-button', {\n * props: {\n * start: { type: Number, default: 0 },\n * },\n * state: { count: 0 },\n * styles: `\n * button { padding: 0.5rem 1rem; }\n * `,\n * connected() {\n * // Use event delegation on shadow root so handler survives re-renders\n * const handleClick = (event: Event) => {\n * const target = event.target as HTMLElement | null;\n * if (target?.matches('button')) {\n * this.setState('count', (this.getState('count') as number) + 1);\n * }\n * };\n * this.shadowRoot?.addEventListener('click', handleClick);\n * // Store handler for cleanup\n * (this as any)._handleClick = handleClick;\n * },\n * disconnected() {\n * // Clean up event listener to prevent memory leaks\n * const handleClick = (this as any)._handleClick;\n * if (handleClick) {\n * this.shadowRoot?.removeEventListener('click', handleClick);\n * }\n * },\n * render({ props, state }) {\n * return html`\n * <button>\n * Count: ${state.count}\n * </button>\n * `;\n * },\n * });\n * ```\n */\nexport const component = <TProps extends Record<string, unknown>>(\n tagName: string,\n definition: ComponentDefinition<TProps>\n): void => {\n const elementClass = defineComponent(tagName, definition);\n\n if (!customElements.get(tagName)) {\n customElements.define(tagName, elementClass);\n }\n};\n","/**\n * Tagged template literal for creating HTML strings.\n *\n * This function handles interpolation of values into HTML templates,\n * converting null/undefined to empty strings.\n *\n * @param strings - Template literal string parts\n * @param values - Interpolated values\n * @returns Combined HTML string\n *\n * @example\n * ```ts\n * const name = 'World';\n * const greeting = html`<h1>Hello, ${name}!</h1>`;\n * // Result: '<h1>Hello, World!</h1>'\n * ```\n */\nexport const html = (strings: TemplateStringsArray, ...values: unknown[]): string => {\n return strings.reduce((acc, part, index) => `${acc}${part}${values[index] ?? ''}`, '');\n};\n\n/**\n * Escapes HTML entities in interpolated values for XSS prevention.\n * Use this when you need to safely embed user content in templates.\n *\n * @param strings - Template literal string parts\n * @param values - Interpolated values to escape\n * @returns Combined HTML string with escaped values\n *\n * @example\n * ```ts\n * const userInput = '<script>alert(\"xss\")</script>';\n * const safe = safeHtml`<div>${userInput}</div>`;\n * // Result: '<div><script>alert(\"xss\")</script></div>'\n * ```\n */\nexport const safeHtml = (strings: TemplateStringsArray, ...values: unknown[]): string => {\n const escapeMap: Record<string, string> = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n };\n\n const escape = (value: unknown): string => {\n const str = String(value ?? '');\n return str.replace(/[&<>\"'`]/g, (char) => escapeMap[char]);\n };\n\n return strings.reduce((acc, part, index) => `${acc}${part}${escape(values[index])}`, '');\n};\n"],"names":["coercePropValue","rawValue","config","type","normalized","callable","constructable","hasPrototype","hasPrototypeMethods","hasInheritedConstructor","isClassSyntax","result","error","defineComponent","tagName","definition","BQueryComponent","_name","_oldValue","_newValue","key","value","props","attrValue","triggerUpdated","emit","event","detail","markup","sanitizedMarkup","sanitizeHtml","styleElement","component","elementClass","html","strings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AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EAAA,GAGDC,IAAS,CAACrB,MACF,OAAOA,KAAS,EAAE,EACnB,QAAQ,aAAa,CAACsB,MAASF,EAAUE,CAAI,CAAC;AAG3D,SAAOR,EAAQ,OAAO,CAACE,GAAKC,GAAMC,MAAU,GAAGF,CAAG,GAAGC,CAAI,GAAGI,EAAON,EAAOG,CAAK,CAAC,CAAC,IAAI,EAAE;AACzF;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type InsertableContent } from './dom';
|
|
1
2
|
import { BQueryElement } from './element';
|
|
2
3
|
/**
|
|
3
4
|
* Wrapper for multiple DOM elements.
|
|
@@ -114,6 +115,8 @@ export declare class BQueryCollection {
|
|
|
114
115
|
* @returns The instance for method chaining
|
|
115
116
|
*/
|
|
116
117
|
removeAttr(name: string): this;
|
|
118
|
+
/** Toggle an attribute on all elements. */
|
|
119
|
+
toggleAttr(name: string, force?: boolean): this;
|
|
117
120
|
/**
|
|
118
121
|
* Sets text content on all elements or gets from first.
|
|
119
122
|
*
|
|
@@ -136,14 +139,48 @@ export declare class BQueryCollection {
|
|
|
136
139
|
* @warning Bypasses XSS protection
|
|
137
140
|
*/
|
|
138
141
|
htmlUnsafe(value: string): this;
|
|
142
|
+
/** Append content to all elements. */
|
|
143
|
+
append(content: InsertableContent): this;
|
|
144
|
+
/** Prepend content to all elements. */
|
|
145
|
+
prepend(content: InsertableContent): this;
|
|
146
|
+
/** Insert content before all elements. */
|
|
147
|
+
before(content: InsertableContent): this;
|
|
148
|
+
/** Insert content after all elements. */
|
|
149
|
+
after(content: InsertableContent): this;
|
|
139
150
|
/**
|
|
140
|
-
*
|
|
151
|
+
* Gets or sets CSS styles on all elements.
|
|
152
|
+
* When getting, returns the computed style value from the first element.
|
|
141
153
|
*
|
|
142
154
|
* @param property - Property name or object of properties
|
|
143
155
|
* @param value - Value when setting single property
|
|
144
|
-
* @returns The instance
|
|
156
|
+
* @returns The computed style value when getting, instance when setting
|
|
157
|
+
*/
|
|
158
|
+
css(property: string): string;
|
|
159
|
+
css(property: string, value: string): this;
|
|
160
|
+
css(property: Record<string, string>): this;
|
|
161
|
+
/** Wrap each element with a wrapper element or tag. */
|
|
162
|
+
wrap(wrapper: string | Element): this;
|
|
163
|
+
/**
|
|
164
|
+
* Remove the parent element of each element, keeping the elements in place.
|
|
165
|
+
*
|
|
166
|
+
* **Important**: This method unwraps ALL children of each parent element,
|
|
167
|
+
* not just the elements in the collection. If you call `unwrap()` on a
|
|
168
|
+
* collection containing only some children of a parent, all siblings will
|
|
169
|
+
* also be unwrapped. This behavior is consistent with jQuery's `.unwrap()`.
|
|
170
|
+
*
|
|
171
|
+
* @returns The collection for chaining
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* // HTML: <div><section><span>A</span><span>B</span></section></div>
|
|
176
|
+
* const spans = $$('span');
|
|
177
|
+
* spans.unwrap(); // Removes <section>, both spans move to <div>
|
|
178
|
+
* // Result: <div><span>A</span><span>B</span></div>
|
|
179
|
+
* ```
|
|
145
180
|
*/
|
|
146
|
-
|
|
181
|
+
unwrap(): this;
|
|
182
|
+
/** Replace each element with provided content. */
|
|
183
|
+
replaceWith(content: string | Element): BQueryCollection;
|
|
147
184
|
/**
|
|
148
185
|
* Shows all elements.
|
|
149
186
|
*
|
|
@@ -228,6 +265,19 @@ export declare class BQueryCollection {
|
|
|
228
265
|
* ```
|
|
229
266
|
*/
|
|
230
267
|
undelegate(event: string, selector: string, handler: (event: Event, target: Element) => void): this;
|
|
268
|
+
/**
|
|
269
|
+
* Finds all descendant elements matching the selector across all elements
|
|
270
|
+
* in the collection. Returns a new BQueryCollection with the results.
|
|
271
|
+
*
|
|
272
|
+
* @param selector - CSS selector to match
|
|
273
|
+
* @returns A new BQueryCollection with all matching descendants
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* $$('.container').find('.item').addClass('highlight');
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
find(selector: string): BQueryCollection;
|
|
231
281
|
/**
|
|
232
282
|
* Removes all elements from the DOM.
|
|
233
283
|
*
|
|
@@ -240,5 +290,7 @@ export declare class BQueryCollection {
|
|
|
240
290
|
* @returns The instance for method chaining
|
|
241
291
|
*/
|
|
242
292
|
empty(): this;
|
|
293
|
+
/** @internal */
|
|
294
|
+
private insertAll;
|
|
243
295
|
}
|
|
244
296
|
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/core/collection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../src/core/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAM1C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAgB;aAgBC,QAAQ,EAAE,OAAO,EAAE;IAf/C;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAG9B;IAEJ;;;OAGG;gBACyB,QAAQ,EAAE,OAAO,EAAE;IAE/C;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,OAAO,CAAC,KAAK;IAIb;;;;;OAKG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAK5C;;;;OAIG;IACH,OAAO,IAAI,aAAa,GAAG,SAAS;IAIpC;;;;OAIG;IACH,MAAM,IAAI,aAAa,GAAG,SAAS;IAInC;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOrE;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,QAA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AAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAC/C,IAAI;IA4BP;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAC/C,IAAI;IA4BP;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAexC;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAKd;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAOb,gBAAgB;IAChB,OAAO,CAAC,SAAS;CAiBlB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type InsertableContent = string | Element | Element[];
|
|
2
|
+
export declare const sanitizeContent: (html: string) => string;
|
|
3
|
+
export declare const setHtml: (element: Element, html: string) => void;
|
|
4
|
+
export declare const createElementFromHtml: (html: string) => Element;
|
|
5
|
+
export declare const insertContent: (target: Element, content: InsertableContent, position: InsertPosition) => void;
|
|
6
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/core/dom.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC;AAE7D,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAA4B,CAAC;AAE5E,eAAO,MAAM,OAAO,GAAI,SAAS,OAAO,EAAE,MAAM,MAAM,KAAG,IAExD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,OAIpD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,QAAQ,OAAO,EACf,SAAS,iBAAiB,EAC1B,UAAU,cAAc,KACvB,IAgBF,CAAC"}
|
package/dist/core/element.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare class BQueryElement {
|
|
|
29
29
|
toggleClass(className: string, force?: boolean): this;
|
|
30
30
|
/** Get or set an attribute. */
|
|
31
31
|
attr(name: string, value?: string): string | this;
|
|
32
|
+
/** Remove an attribute. */
|
|
33
|
+
removeAttr(name: string): this;
|
|
34
|
+
/** Toggle an attribute on/off. */
|
|
35
|
+
toggleAttr(name: string, force?: boolean): this;
|
|
32
36
|
/** Get or set a property. */
|
|
33
37
|
prop<T extends keyof Element>(name: T, value?: Element[T]): Element[T] | this;
|
|
34
38
|
/** Read or write data attributes in camelCase. */
|
|
@@ -64,18 +68,23 @@ export declare class BQueryElement {
|
|
|
64
68
|
*
|
|
65
69
|
* @param property - A CSS property name or an object of property-value pairs
|
|
66
70
|
* @param value - The value when setting a single property
|
|
67
|
-
* @returns The instance for method chaining
|
|
71
|
+
* @returns The computed style value when getting a single property, or the instance for method chaining when setting
|
|
68
72
|
*
|
|
69
73
|
* @example
|
|
70
74
|
* ```ts
|
|
71
|
-
* //
|
|
75
|
+
* // Get a computed style value
|
|
76
|
+
* const color = $('#box').css('color');
|
|
77
|
+
*
|
|
78
|
+
* // Set a single property
|
|
72
79
|
* $('#box').css('color', 'red');
|
|
73
80
|
*
|
|
74
|
-
* //
|
|
81
|
+
* // Set multiple properties
|
|
75
82
|
* $('#box').css({ color: 'red', 'font-size': '16px' });
|
|
76
83
|
* ```
|
|
77
84
|
*/
|
|
78
|
-
css(property: string
|
|
85
|
+
css(property: string): string;
|
|
86
|
+
css(property: string, value: string): this;
|
|
87
|
+
css(property: Record<string, string>): this;
|
|
79
88
|
/**
|
|
80
89
|
* Appends HTML or elements to the end of the element.
|
|
81
90
|
*
|
|
@@ -121,6 +130,10 @@ export declare class BQueryElement {
|
|
|
121
130
|
* Removes the parent element, keeping this element in its place.
|
|
122
131
|
* Essentially the opposite of wrap().
|
|
123
132
|
*
|
|
133
|
+
* **Important**: This method only moves the current element out of its parent
|
|
134
|
+
* before removing the parent. Any sibling elements will be removed along with
|
|
135
|
+
* the parent. For unwrapping multiple siblings, use a collection: `$$(siblings).unwrap()`.
|
|
136
|
+
*
|
|
124
137
|
* @returns The instance for method chaining
|
|
125
138
|
*
|
|
126
139
|
* @example
|
|
@@ -305,6 +318,20 @@ export declare class BQueryElement {
|
|
|
305
318
|
* @returns True if the element matches the selector
|
|
306
319
|
*/
|
|
307
320
|
matches(selector: string): boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Alias for `matches()`. Checks if the element matches a CSS selector.
|
|
323
|
+
*
|
|
324
|
+
* @param selector - CSS selector to match against
|
|
325
|
+
* @returns True if the element matches the selector
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* if ($('#el').is('.active')) {
|
|
330
|
+
* console.log('Element is active');
|
|
331
|
+
* }
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
is(selector: string): boolean;
|
|
308
335
|
/**
|
|
309
336
|
* Checks if the element has a specific class.
|
|
310
337
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/core/element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/core/element.ts"],"names":[],"mappings":"AA2BA,qBAAa,aAAa;IAYZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAXpC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA2D;IAE7F;;;OAGG;gBAC0B,OAAO,EAAE,OAAO;IAE7C;;;OAGG;IACH,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,+BAA+B;IAC/B,QAAQ,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI;IAKvC,kCAAkC;IAClC,WAAW,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAA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AAG,MAAM,GAAG,IAAI;IASrC;;;;;;;;;;;;OAYG;IACH,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IA4B9C;;;;;;;;;;OAUG;IACH,eAAe,IAAI,MAAM;IAkBzB;;;;OAIG;IACH,IAAI,IAAI,OAAO;IAIf;;;;OAIG;IACH,MAAM,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAUtE;;;OAGG;IACH,OAAO,CAAC,aAAa;CAGtB"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { BQueryCollection } from './collection';
|
|
|
2
2
|
export { BQueryElement } from './element';
|
|
3
3
|
export { $, $$ } from './selector';
|
|
4
4
|
export { utils } from './utils';
|
|
5
|
+
export { chunk, compact, ensureArray, flatten, unique, debounce, noop, once, throttle, isEmpty, parseJson, sleep, uid, clamp, inRange, randomInt, toNumber, clone, hasOwn, isPlainObject, merge, omit, pick, capitalize, escapeRegExp, slugify, toCamelCase, toKebabCase, truncate, isArray, isBoolean, isCollection, isDate, isElement, isFunction, isNumber, isObject, isPromise, isString, } from './utils';
|
|
6
|
+
export type { DebouncedFn, ThrottledFn } from './utils';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EACL,KAAK,EACL,OAAO,EACP,WAAW,EACX,OAAO,EACP,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EACL,GAAG,EACH,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAK,EACL,MAAM,EACN,aAAa,EACb,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array-focused utility helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module bquery/core/utils/array
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Ensures the input is always returned as an array.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The item type
|
|
10
|
+
* @param value - A single value, array, or nullish value
|
|
11
|
+
* @returns An array (empty if nullish)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* ensureArray('a'); // ['a']
|
|
16
|
+
* ensureArray(['a', 'b']); // ['a', 'b']
|
|
17
|
+
* ensureArray(null); // []
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function ensureArray<T>(value: T | T[] | null | undefined): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Removes duplicate entries from an array.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The item type
|
|
25
|
+
* @param items - The array to deduplicate
|
|
26
|
+
* @returns A new array with unique items
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* unique([1, 2, 2, 3]); // [1, 2, 3]
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function unique<T>(items: T[]): T[];
|
|
34
|
+
/**
|
|
35
|
+
* Splits an array into chunks of a given size.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The item type
|
|
38
|
+
* @param items - The array to chunk
|
|
39
|
+
* @param size - The maximum size of each chunk
|
|
40
|
+
* @returns An array of chunks
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function chunk<T>(items: T[], size: number): T[][];
|
|
48
|
+
/**
|
|
49
|
+
* Removes falsy values from an array.
|
|
50
|
+
*
|
|
51
|
+
* @template T - The item type
|
|
52
|
+
* @param items - The array to compact
|
|
53
|
+
* @returns A new array without falsy values
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* compact([0, 1, '', 'ok', null]); // [1, 'ok']
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function compact<T>(items: Array<T | null | undefined | false | 0 | ''>): T[];
|
|
61
|
+
/**
|
|
62
|
+
* Flattens a single level of nested arrays.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The item type
|
|
65
|
+
* @param items - The array to flatten
|
|
66
|
+
* @returns A new flattened array
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* flatten([1, [2, 3], 4]); // [1, 2, 3, 4]
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function flatten<T>(items: Array<T | T[]>): T[];
|
|
74
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/core/utils/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,EAAE,CAGrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAOxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAEnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAUrD"}
|