dom-primitive-bindings 1.3.1 → 1.7.3

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.
Files changed (69) hide show
  1. package/LICENSE +22 -22
  2. package/README.md +67 -77
  3. package/package.json +26 -35
  4. package/src/index.js +3 -3
  5. package/src/{v3 → v5}/dispatch/executeBinding.js +21 -21
  6. package/src/{v3 → v5}/dispatch/getClientData.js +8 -8
  7. package/src/{v3 → v5}/dispatch/getStartInput.js +10 -10
  8. package/src/{v3 → v5}/dispatch/index.js +15 -15
  9. package/src/{v3 → v5}/guards/bindings/index.js +11 -11
  10. package/src/{v3 → v5}/guards/bindings/validateArray.js +10 -10
  11. package/src/{v3 → v5}/guards/container/index.js +13 -13
  12. package/src/{v3 → v5}/guards/container/resolveElement.js +14 -14
  13. package/src/{v3 → v5}/guards/index.js +15 -15
  14. package/src/{v3 → v5}/index.js +21 -22
  15. package/src/{v3 → v5}/listeners/attachListener.js +10 -10
  16. package/src/{v3 → v5}/listeners/index.js +12 -12
  17. package/src/{v3 → v5}/prepare/groupBindings.js +14 -14
  18. package/src/v5/prepare/index.js +23 -0
  19. package/src/{v3 → v5}/register/index.js +18 -18
  20. package/src/v5/register/meta.js +6 -0
  21. package/src/v6/dispatch/executeBinding.js +21 -0
  22. package/src/v6/dispatch/getClientData.js +8 -0
  23. package/src/v6/dispatch/getStartInput.js +10 -0
  24. package/src/v6/dispatch/index.js +15 -0
  25. package/src/v6/guards/actions/index.js +21 -0
  26. package/src/v6/guards/bindings/index.js +5 -0
  27. package/src/v6/guards/bindings/validateArray.js +23 -0
  28. package/src/v6/guards/bindings/validateBinding.js +22 -0
  29. package/src/v6/guards/container/index.js +13 -0
  30. package/src/v6/guards/container/resolveElement.js +14 -0
  31. package/src/v6/guards/index.js +19 -0
  32. package/src/v6/index.js +21 -0
  33. package/src/v6/listeners/attachListener.js +10 -0
  34. package/src/v6/listeners/index.js +12 -0
  35. package/src/v6/prepare/groupBindings.js +14 -0
  36. package/src/v6/prepare/index.js +23 -0
  37. package/src/v6/register/index.js +18 -0
  38. package/src/{v3 → v6}/register/meta.js +1 -1
  39. package/src/v7/dispatch/executeBinding.js +21 -0
  40. package/src/v7/dispatch/getClientData.js +8 -0
  41. package/src/v7/dispatch/getStartInput.js +10 -0
  42. package/src/v7/dispatch/index.js +15 -0
  43. package/src/v7/guards/actions/index.js +21 -0
  44. package/src/v7/guards/bindings/index.js +5 -0
  45. package/src/v7/guards/bindings/validateArray.js +23 -0
  46. package/src/v7/guards/bindings/validateBinding.js +22 -0
  47. package/src/v7/guards/container/index.js +13 -0
  48. package/src/v7/guards/container/resolveElement.js +14 -0
  49. package/src/v7/guards/index.js +19 -0
  50. package/src/v7/index.js +43 -0
  51. package/src/v7/listeners/attachListener.js +10 -0
  52. package/src/v7/listeners/index.js +12 -0
  53. package/src/v7/prepare/groupBindings.js +14 -0
  54. package/src/v7/prepare/index.js +23 -0
  55. package/src/v7/register/index.js +18 -0
  56. package/src/v7/register/meta.js +6 -0
  57. package/src/v7/sample/index.js +22 -0
  58. package/docs/architecture.md +0 -111
  59. package/docs/binding-spec.md +0 -86
  60. package/docs/dist/min.js +0 -64
  61. package/docs/dist/v1/min.js +0 -63
  62. package/docs/dist/v2/min.js +0 -64
  63. package/docs/dist/v3/min.js +0 -64
  64. package/docs/index.html +0 -208
  65. package/docs/stories/01-the-listener-trap.html +0 -189
  66. package/docs/stories/02-the-delegation-epiphany.html +0 -185
  67. package/docs/stories/03-the-staged-pipeline.html +0 -162
  68. package/docs/stories/04-declarative-json-bindings.html +0 -159
  69. package/src/v3/prepare/index.js +0 -8
@@ -0,0 +1,43 @@
1
+ import registerGlobal from "./register/index.js";
2
+ import runGuards from "./guards/index.js";
3
+ import prepareBindings from "./prepare/index.js";
4
+ import attachListeners from "./listeners/index.js";
5
+ import sample, {
6
+ sampleContainer,
7
+ sampleBindings,
8
+ sampleActions
9
+ } from "./sample/index.js";
10
+
11
+ const check = (containerOrId, bindings = [], actions = {}) =>
12
+ runGuards(containerOrId, bindings, actions);
13
+
14
+ const bindEvents = (containerOrId, bindings = [], actions = {}) => {
15
+ const guarded = check(containerOrId, bindings, actions);
16
+ if (!guarded) return null;
17
+
18
+ const { container, bindings: validBindings } = guarded;
19
+ const eventGroups = prepareBindings(validBindings, guarded.actions);
20
+
21
+ attachListeners(container, eventGroups);
22
+
23
+ return container;
24
+ };
25
+
26
+ export {
27
+ bindEvents,
28
+ check,
29
+ sample,
30
+ sampleContainer,
31
+ sampleBindings,
32
+ sampleActions
33
+ };
34
+ export default bindEvents;
35
+
36
+ registerGlobal({
37
+ bindEvents,
38
+ check,
39
+ sample,
40
+ sampleContainer,
41
+ sampleBindings,
42
+ sampleActions
43
+ });
@@ -0,0 +1,10 @@
1
+ import dispatchEvent from "../dispatch/index.js";
2
+
3
+ const attachListener = (container, eventType, bindings) => {
4
+ container.addEventListener(eventType, (event) => {
5
+ dispatchEvent({ bindings, event, container });
6
+ });
7
+ };
8
+
9
+ export default attachListener;
10
+
@@ -0,0 +1,12 @@
1
+ import attachListener from "./attachListener.js";
2
+
3
+ const attachListeners = (container, eventGroups) => {
4
+ for (const [eventType, bindings] of eventGroups.entries()) {
5
+ attachListener(container, eventType, bindings);
6
+ }
7
+
8
+ return container;
9
+ };
10
+
11
+ export default attachListeners;
12
+
@@ -0,0 +1,14 @@
1
+ const groupBindings = (bindings) => {
2
+ const groups = new Map();
3
+
4
+ for (const binding of bindings) {
5
+ const list = groups.get(binding.event) ?? [];
6
+ list.push(binding);
7
+ groups.set(binding.event, list);
8
+ }
9
+
10
+ return groups;
11
+ };
12
+
13
+ export default groupBindings;
14
+
@@ -0,0 +1,23 @@
1
+ import groupBindings from "./groupBindings.js";
2
+
3
+ const prepareBindings = (bindings, actions = {}) => {
4
+ const hasActions = actions && typeof actions === "object" && Object.keys(actions).length > 0;
5
+
6
+ const configuredBindings = hasActions
7
+ ? bindings.map((binding) => {
8
+ if (binding.action && typeof actions[binding.action] === "function" && typeof binding.onExtract !== "function") {
9
+ return {
10
+ ...binding,
11
+ onExtract: (result, event, matchElement) => {
12
+ actions[binding.action](event, matchElement, result);
13
+ }
14
+ };
15
+ }
16
+ return binding;
17
+ })
18
+ : bindings;
19
+
20
+ return groupBindings(configuredBindings);
21
+ };
22
+
23
+ export default prepareBindings;
@@ -0,0 +1,18 @@
1
+ import meta from "./meta.js";
2
+
3
+ const registerGlobal = (api, metadata = meta) => {
4
+ if (!api || typeof globalThis === "undefined") return;
5
+
6
+ globalThis.ks ??= {};
7
+
8
+ globalThis.ks.domPrimitiveBindings = {
9
+ meta: metadata,
10
+ ...api
11
+ };
12
+
13
+ globalThis.ks.bindEvents ??= api.bindEvents;
14
+
15
+ return globalThis.ks.domPrimitiveBindings;
16
+ };
17
+
18
+ export default registerGlobal;
@@ -0,0 +1,6 @@
1
+ export const meta = {
2
+ name: "dom-primitive-bindings",
3
+ version: "5.0.0"
4
+ };
5
+
6
+ export default meta;
@@ -0,0 +1,22 @@
1
+ const sampleContainer = () => "app";
2
+
3
+ const sampleBindings = () => [
4
+ {
5
+ event: "click",
6
+ selector: "#loadBtn",
7
+ action: "loadData"
8
+ }
9
+ ];
10
+
11
+ const sampleActions = () => ({
12
+ loadData: () => {}
13
+ });
14
+
15
+ const sample = () => ({
16
+ containerOrId: sampleContainer(),
17
+ bindings: sampleBindings(),
18
+ actions: sampleActions()
19
+ });
20
+
21
+ export { sample, sampleContainer, sampleBindings, sampleActions };
22
+ export default sample;
@@ -1,111 +0,0 @@
1
- # Architecture & Design Story — DOM Primitive Bindings
2
-
3
- This document details the architectural philosophy, data flow, and design trade-offs behind **DOM Primitive Bindings**.
4
-
5
- ---
6
-
7
- ## 1. The Core Architectural Philosophy
8
-
9
- ### Separation of Concerns: The Wiring Layer vs. The Extraction Layer
10
-
11
- Modern frontend architectures fail when they blur the boundary between **how events are wired** and **how data is extracted or mutated**:
12
-
13
- ```text
14
- ┌─────────────────────────────────┐
15
- │ Browser DOM │ <-- Stateful View (Table, Form, Cards)
16
- └────────────────┬────────────────┘
17
- │ user interaction (click, input, keydown)
18
- ▼
19
- ┌─────────────────────────────────┐
20
- │ dom-primitive-bindings │ <-- Responsibility: The Wiring Layer
21
- │ (guards → prepare → dispatch) │ • Single listener on container
22
- └────────────────┬────────────────┘ • Matches closest(selector)
23
- │ passes { event, targetElement }
24
- ▼
25
- ┌─────────────────────────────────┐
26
- │ dom-primitive-engine │ <-- Responsibility: The Extraction Layer
27
- │ (declarative instructions) │ • Traverses DOM (tr, td)
28
- └────────────────┬────────────────┘ • Produces clean JSON object
29
- │ outputs clean Plain Data
30
- ▼
31
- ┌─────────────────────────────────┐
32
- │ Business Logic / API Call │ <-- Consumes Plain Data
33
- └─────────────────────────────────┘
34
- ```
35
-
36
- By strictly separating event wiring into `dom-primitive-bindings`:
37
- 1. **Zero DOM manipulation**: Bindings never alter, insert, or delete DOM elements.
38
- 2. **Zero schema extraction**: Bindings never parse table cells or form schemas into business models.
39
- 3. **Pure delegation**: Exactly **one listener per event type** is attached to the parent container. Bubbling handles target matching.
40
-
41
- ---
42
-
43
- ## 2. Why Delegated Bindings over Element Listeners?
44
-
45
- | Approach | Memory Usage | Dynamic Element Support | Duplicate Fire Risk |
46
- | :--- | :--- | :--- | :--- |
47
- | **Direct Listeners** (`element.addEventListener`) | High ($O(N)$ listeners) | Fails on newly added DOM elements | High (re-attaching duplicates listeners) |
48
- | **DOM Primitive Bindings** (Container Delegation) | Minimal ($O(1)$ listener per event type) | Works instantly on dynamic elements | Zero (single stable container listener) |
49
-
50
- ---
51
-
52
- ## 3. The 4-Stage Internal Pipeline (`src/v3/`)
53
-
54
- The engine operates on a strictly staged, functional pipeline where every folder contains an `index.js` and exports a single function as `default`:
55
-
56
- ```text
57
- src/v3/
58
- ├── guards/ # Validates container & bindings array
59
- │ ├── container/ # Resolves 1st input (container ID or DOM element)
60
- │ ├── bindings/ # Filters and validates 2nd input (bindings array)
61
- │ └── index.js
62
- ├── prepare/ # Groups bindings by event type into Map
63
- │ ├── groupBindings.js
64
- │ └── index.js
65
- ├── listeners/ # Attaches single container listener per event type
66
- │ ├── attachListener.js
67
- │ └── index.js
68
- ├── dispatch/ # Handles event bubbling, target matching & execution
69
- │ ├── getStartInput.js
70
- │ ├── getClientData.js
71
- │ ├── executeBinding.js
72
- │ └── index.js
73
- ├── register/ # Exposes module onto window.ks.domPrimitiveBindings
74
- │ ├── meta.js
75
- │ └── index.js
76
- └── index.js # Orchestrator
77
- ```
78
-
79
- ### Stage Details
80
-
81
- 1. **`guards/`**: Validates inputs before any DOM mutation occurs.
82
- - `container/`: Resolves string IDs via `document.getElementById` or verifies existing element.
83
- - `bindings/`: Filters invalid items and ensures at least one valid binding exists.
84
- 2. **`prepare/`**: Groups bindings into a `Map<eventType, bindings[]>`.
85
- - If 10 separate selectors listen for `click`, they are aggregated under the single `"click"` event group.
86
- 3. **`listeners/`**: Attaches exactly one native event listener to the container per event type.
87
- 4. **`dispatch/`**:
88
- - Intercepts the bubbling event.
89
- - Resolves matching element via `event.target.closest(binding.selector)`.
90
- - Resolves starting input (`event` for keyboard events, `matchElement` for clicks).
91
- - Invokes runner and forwards data to `onExtract`.
92
-
93
- ---
94
-
95
- ## 4. Responsibility Boundaries
96
-
97
- | Actor | What It Does | What It NEVER Does |
98
- | :--- | :--- | :--- |
99
- | **Container Element** | Acts as the stable anchor for bubbling events | Does not know about inner button schemas |
100
- | **`bindings.json`** | Declares `event` and `selector` | Does not execute imperative logic |
101
- | **`dom-primitive-bindings`** | Resolves target, manages delegation pipeline | Does not extract table rows or mutate markup |
102
- | **`dom-primitive-engine`** | Extracts clean JSON data from the matched target | Does not manage event listeners |
103
-
104
- ---
105
-
106
- ## 5. Version Evolution (`v3` as Single Source of Truth)
107
-
108
- - **v1**: Staged architecture established with zero code comments and single-function default exports.
109
- - **v2**: Removed accidental DOM manipulation and cell extraction from samples, solidifying the pure delegation boundary.
110
- - **v3**: Declarative JSON transformation. Replaced imperative `.js` event arrays with pure, serializable `bindings.json` configurations.
111
-
@@ -1,86 +0,0 @@
1
- # Binding Specification — DOM Primitive Bindings
2
-
3
- This document defines the normative schema and runtime behavior for declarative `bindings.json` files.
4
-
5
- ---
6
-
7
- ## 1. Schema Overview
8
-
9
- A bindings file is an array of binding specification objects:
10
-
11
- ```json
12
- [
13
- {
14
- "event": "click",
15
- "selector": ".ks-btn-show",
16
- "root": "element",
17
- "clientData": {
18
- "context": "tableRow"
19
- }
20
- }
21
- ]
22
- ```
23
-
24
- ---
25
-
26
- ## 2. Property Definitions
27
-
28
- ### `event` (Required)
29
- - **Type**: `string`
30
- - **Description**: The standard browser DOM event name to listen for on the container (e.g. `"click"`, `"keydown"`, `"input"`, `"change"`, `"submit"`).
31
- - **Behavior**: The engine groups all bindings with the same `event` name under a single native event listener on the container element.
32
-
33
- ### `selector` (Required)
34
- - **Type**: `string`
35
- - **Description**: Standard CSS selector used by `event.target.closest(selector)` to identify whether the bubbling event originated from or within a target element.
36
- - **Examples**:
37
- - `".ks-btn-show"`
38
- - `"input[type='search'], input"`
39
- - `".btn-action"`
40
- - `".product-card"`
41
-
42
- ### `root` (Optional)
43
- - **Type**: `string` (`"element"` | `"event"`)
44
- - **Default**: `"element"` (automatically defaults to `"event"` for key events such as `keydown`, `keyup`, `keypress`).
45
- - **Description**: Determines what is passed as the first argument to the runner function:
46
- - `"element"`: passes the matched DOM element (`matchElement`).
47
- - `"event"`: passes the native browser `Event` object.
48
-
49
- ### `clientData` (Optional)
50
- - **Type**: `object`
51
- - **Description**: Arbitrary user-defined context passed along into the dispatch pipeline. The engine merges this into the client context object alongside `event` and `targetElement`.
52
-
53
- ### `instructions` (Optional)
54
- - **Type**: `array`
55
- - **Description**: Declarative extraction instructions intended for handoff to `dom-primitive-engine`.
56
-
57
- ---
58
-
59
- ## 3. Runtime Dispatch Lifecycle
60
-
61
- When an event fires inside the container:
62
-
63
- ```text
64
- Browser Event Fires
65
- │
66
- ▼
67
- Container Listener Intercepts (listeners/attachListener.js)
68
- │
69
- ▼
70
- Find Matching Element: event.target.closest(binding.selector)
71
- │
72
- ├── No match / not inside container ──> Discard (continue)
73
- │
74
- ▼
75
- Resolve Start Input (dispatch/getStartInput.js)
76
- │
77
- ├── Key event or root === "event" ──> Pass event
78
- └── Otherwise ──> Pass matchElement
79
- │
80
- ▼
81
- Execute Runner (dispatch/executeBinding.js)
82
- │
83
- ▼
84
- Forward to onExtract(result, event, matchElement)
85
- ```
86
-
package/docs/dist/min.js DELETED
@@ -1,64 +0,0 @@
1
- const u = {
2
- name: "dom-primitive-bindings",
3
- version: "3.0.0"
4
- }, c = (t, n = u) => {
5
- var e;
6
- if (!(!t || typeof globalThis > "u"))
7
- return globalThis.ks ?? (globalThis.ks = {}), globalThis.ks.domPrimitiveBindings = {
8
- meta: n,
9
- bindEvents: t
10
- }, (e = globalThis.ks).bindEvents ?? (e.bindEvents = t), globalThis.ks.domPrimitiveBindings;
11
- }, l = (t) => typeof t == "string" ? document.getElementById(t) || document.querySelector(t) : t && typeof t == "object" && "addEventListener" in t ? t : null, a = (t) => {
12
- if (!t) return null;
13
- const n = l(t);
14
- return n || null;
15
- }, f = (t) => Array.isArray(t) ? t.filter((n) => n && typeof n == "object" && typeof n.event == "string" && typeof n.selector == "string") : [], g = (t) => {
16
- const n = f(t);
17
- return n.length === 0 ? null : n;
18
- }, p = (t, n) => {
19
- const e = a(t);
20
- if (!e) return null;
21
- const r = g(n);
22
- return r ? { container: e, bindings: r } : null;
23
- }, d = (t) => {
24
- const n = /* @__PURE__ */ new Map();
25
- for (const e of t) {
26
- const r = n.get(e.event) ?? [];
27
- r.push(e), n.set(e.event, r);
28
- }
29
- return n;
30
- }, y = (t) => d(t), m = (t, n, e) => {
31
- var r;
32
- return t.root === "event" || (r = n == null ? void 0 : n.type) != null && r.startsWith("key") ? n : e;
33
- }, h = (t, n, e) => ({
34
- ...t.clientData,
35
- event: n,
36
- targetElement: e
37
- }), v = ({ binding: t, event: n, matchElement: e }) => {
38
- const r = m(t, n, e), i = h(t, n, e), o = t.runner, s = typeof o == "function" ? o(r, t.instructions, i) : r;
39
- return s != null && typeof t.onExtract == "function" && t.onExtract(s, n, e), s;
40
- }, B = ({ bindings: t, event: n, container: e }) => {
41
- var r, i;
42
- for (const o of t) {
43
- const s = (i = (r = n.target) == null ? void 0 : r.closest) == null ? void 0 : i.call(r, o.selector);
44
- !s || !e.contains(s) || v({ binding: o, event: n, matchElement: s });
45
- }
46
- }, k = (t, n, e) => {
47
- t.addEventListener(n, (r) => {
48
- B({ bindings: e, event: r, container: t });
49
- });
50
- }, E = (t, n) => {
51
- for (const [e, r] of n.entries())
52
- k(t, e, r);
53
- return t;
54
- }, T = (t, n = []) => {
55
- const e = p(t, n);
56
- if (!e) return null;
57
- const { container: r, bindings: i } = e, o = y(i);
58
- return E(r, o), r;
59
- };
60
- c(T);
61
- export {
62
- T as bindEvents,
63
- T as default
64
- };
@@ -1,63 +0,0 @@
1
- const u = {
2
- name: "dom-primitive-bindings",
3
- version: "1.0.0"
4
- }, c = (t, n = u) => {
5
- if (!(!t || typeof globalThis > "u"))
6
- return globalThis.ks ?? (globalThis.ks = {}), globalThis.ks.domPrimitiveBindings = {
7
- meta: n,
8
- bindEvents: t
9
- }, globalThis.ks.domPrimitiveBindings;
10
- }, l = (t) => typeof t == "string" ? document.getElementById(t) || document.querySelector(t) : t && typeof t == "object" && "addEventListener" in t ? t : null, a = (t) => {
11
- if (!t) return null;
12
- const n = l(t);
13
- return n || null;
14
- }, f = (t) => Array.isArray(t) ? t.filter((n) => n && typeof n == "object" && typeof n.event == "string" && typeof n.selector == "string") : [], g = (t) => {
15
- const n = f(t);
16
- return n.length === 0 ? null : n;
17
- }, p = (t, n) => {
18
- const e = a(t);
19
- if (!e) return null;
20
- const r = g(n);
21
- return r ? { container: e, bindings: r } : null;
22
- }, d = (t) => {
23
- const n = /* @__PURE__ */ new Map();
24
- for (const e of t) {
25
- const r = n.get(e.event) ?? [];
26
- r.push(e), n.set(e.event, r);
27
- }
28
- return n;
29
- }, y = (t) => d(t), m = (t, n, e) => {
30
- var r;
31
- return t.root === "event" || (r = n == null ? void 0 : n.type) != null && r.startsWith("key") ? n : e;
32
- }, h = (t, n, e) => ({
33
- ...t.clientData,
34
- event: n,
35
- targetElement: e
36
- }), v = ({ binding: t, event: n, matchElement: e }) => {
37
- const r = m(t, n, e), i = h(t, n, e), o = t.runner, s = typeof o == "function" ? o(r, t.instructions, i) : r;
38
- return s != null && typeof t.onExtract == "function" && t.onExtract(s, n, e), s;
39
- }, B = ({ bindings: t, event: n, container: e }) => {
40
- var r, i;
41
- for (const o of t) {
42
- const s = (i = (r = n.target) == null ? void 0 : r.closest) == null ? void 0 : i.call(r, o.selector);
43
- !s || !e.contains(s) || v({ binding: o, event: n, matchElement: s });
44
- }
45
- }, E = (t, n, e) => {
46
- t.addEventListener(n, (r) => {
47
- B({ bindings: e, event: r, container: t });
48
- });
49
- }, k = (t, n) => {
50
- for (const [e, r] of n.entries())
51
- E(t, e, r);
52
- return t;
53
- }, T = (t, n = []) => {
54
- const e = p(t, n);
55
- if (!e) return null;
56
- const { container: r, bindings: i } = e, o = y(i);
57
- return k(r, o), r;
58
- };
59
- c(T);
60
- export {
61
- T as bindEvents,
62
- T as default
63
- };
@@ -1,64 +0,0 @@
1
- const u = {
2
- name: "dom-primitive-bindings",
3
- version: "2.0.0"
4
- }, c = (t, n = u) => {
5
- var e;
6
- if (!(!t || typeof globalThis > "u"))
7
- return globalThis.ks ?? (globalThis.ks = {}), globalThis.ks.domPrimitiveBindings = {
8
- meta: n,
9
- bindEvents: t
10
- }, (e = globalThis.ks).bindEvents ?? (e.bindEvents = t), globalThis.ks.domPrimitiveBindings;
11
- }, l = (t) => typeof t == "string" ? document.getElementById(t) || document.querySelector(t) : t && typeof t == "object" && "addEventListener" in t ? t : null, a = (t) => {
12
- if (!t) return null;
13
- const n = l(t);
14
- return n || null;
15
- }, f = (t) => Array.isArray(t) ? t.filter((n) => n && typeof n == "object" && typeof n.event == "string" && typeof n.selector == "string") : [], g = (t) => {
16
- const n = f(t);
17
- return n.length === 0 ? null : n;
18
- }, p = (t, n) => {
19
- const e = a(t);
20
- if (!e) return null;
21
- const r = g(n);
22
- return r ? { container: e, bindings: r } : null;
23
- }, d = (t) => {
24
- const n = /* @__PURE__ */ new Map();
25
- for (const e of t) {
26
- const r = n.get(e.event) ?? [];
27
- r.push(e), n.set(e.event, r);
28
- }
29
- return n;
30
- }, y = (t) => d(t), m = (t, n, e) => {
31
- var r;
32
- return t.root === "event" || (r = n == null ? void 0 : n.type) != null && r.startsWith("key") ? n : e;
33
- }, h = (t, n, e) => ({
34
- ...t.clientData,
35
- event: n,
36
- targetElement: e
37
- }), v = ({ binding: t, event: n, matchElement: e }) => {
38
- const r = m(t, n, e), i = h(t, n, e), o = t.runner, s = typeof o == "function" ? o(r, t.instructions, i) : r;
39
- return s != null && typeof t.onExtract == "function" && t.onExtract(s, n, e), s;
40
- }, B = ({ bindings: t, event: n, container: e }) => {
41
- var r, i;
42
- for (const o of t) {
43
- const s = (i = (r = n.target) == null ? void 0 : r.closest) == null ? void 0 : i.call(r, o.selector);
44
- !s || !e.contains(s) || v({ binding: o, event: n, matchElement: s });
45
- }
46
- }, k = (t, n, e) => {
47
- t.addEventListener(n, (r) => {
48
- B({ bindings: e, event: r, container: t });
49
- });
50
- }, E = (t, n) => {
51
- for (const [e, r] of n.entries())
52
- k(t, e, r);
53
- return t;
54
- }, T = (t, n = []) => {
55
- const e = p(t, n);
56
- if (!e) return null;
57
- const { container: r, bindings: i } = e, o = y(i);
58
- return E(r, o), r;
59
- };
60
- c(T);
61
- export {
62
- T as bindEvents,
63
- T as default
64
- };
@@ -1,64 +0,0 @@
1
- const u = {
2
- name: "dom-primitive-bindings",
3
- version: "3.0.0"
4
- }, c = (t, n = u) => {
5
- var e;
6
- if (!(!t || typeof globalThis > "u"))
7
- return globalThis.ks ?? (globalThis.ks = {}), globalThis.ks.domPrimitiveBindings = {
8
- meta: n,
9
- bindEvents: t
10
- }, (e = globalThis.ks).bindEvents ?? (e.bindEvents = t), globalThis.ks.domPrimitiveBindings;
11
- }, l = (t) => typeof t == "string" ? document.getElementById(t) || document.querySelector(t) : t && typeof t == "object" && "addEventListener" in t ? t : null, a = (t) => {
12
- if (!t) return null;
13
- const n = l(t);
14
- return n || null;
15
- }, f = (t) => Array.isArray(t) ? t.filter((n) => n && typeof n == "object" && typeof n.event == "string" && typeof n.selector == "string") : [], g = (t) => {
16
- const n = f(t);
17
- return n.length === 0 ? null : n;
18
- }, p = (t, n) => {
19
- const e = a(t);
20
- if (!e) return null;
21
- const r = g(n);
22
- return r ? { container: e, bindings: r } : null;
23
- }, d = (t) => {
24
- const n = /* @__PURE__ */ new Map();
25
- for (const e of t) {
26
- const r = n.get(e.event) ?? [];
27
- r.push(e), n.set(e.event, r);
28
- }
29
- return n;
30
- }, y = (t) => d(t), m = (t, n, e) => {
31
- var r;
32
- return t.root === "event" || (r = n == null ? void 0 : n.type) != null && r.startsWith("key") ? n : e;
33
- }, h = (t, n, e) => ({
34
- ...t.clientData,
35
- event: n,
36
- targetElement: e
37
- }), v = ({ binding: t, event: n, matchElement: e }) => {
38
- const r = m(t, n, e), i = h(t, n, e), o = t.runner, s = typeof o == "function" ? o(r, t.instructions, i) : r;
39
- return s != null && typeof t.onExtract == "function" && t.onExtract(s, n, e), s;
40
- }, B = ({ bindings: t, event: n, container: e }) => {
41
- var r, i;
42
- for (const o of t) {
43
- const s = (i = (r = n.target) == null ? void 0 : r.closest) == null ? void 0 : i.call(r, o.selector);
44
- !s || !e.contains(s) || v({ binding: o, event: n, matchElement: s });
45
- }
46
- }, k = (t, n, e) => {
47
- t.addEventListener(n, (r) => {
48
- B({ bindings: e, event: r, container: t });
49
- });
50
- }, E = (t, n) => {
51
- for (const [e, r] of n.entries())
52
- k(t, e, r);
53
- return t;
54
- }, T = (t, n = []) => {
55
- const e = p(t, n);
56
- if (!e) return null;
57
- const { container: r, bindings: i } = e, o = y(i);
58
- return E(r, o), r;
59
- };
60
- c(T);
61
- export {
62
- T as bindEvents,
63
- T as default
64
- };