@oscarpalmer/abydon 0.11.0 → 0.13.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.
Files changed (57) hide show
  1. package/dist/abydon.full.js +1247 -0
  2. package/dist/fragment.js +60 -0
  3. package/dist/helpers/dom.js +28 -0
  4. package/dist/helpers/index.js +11 -0
  5. package/dist/index.js +6 -885
  6. package/dist/node/attribute/index.js +34 -0
  7. package/dist/node/attribute/value.js +58 -0
  8. package/dist/node/event.js +32 -0
  9. package/dist/node/index.js +52 -0
  10. package/dist/node/value.js +93 -0
  11. package/dist/parse.js +21 -0
  12. package/package.json +41 -28
  13. package/src/fragment.ts +36 -15
  14. package/src/helpers/dom.ts +10 -10
  15. package/src/helpers/index.ts +0 -9
  16. package/src/index.ts +11 -1
  17. package/src/models.ts +7 -4
  18. package/src/node/attribute/index.ts +26 -7
  19. package/src/node/attribute/value.ts +31 -20
  20. package/src/node/event.ts +9 -9
  21. package/src/node/index.ts +22 -9
  22. package/src/node/value.ts +38 -37
  23. package/src/{html.ts → parse.ts} +5 -14
  24. package/types/fragment.d.cts +27 -0
  25. package/types/fragment.d.ts +1 -2
  26. package/types/helpers/dom.d.cts +7 -0
  27. package/types/helpers/dom.d.ts +3 -4
  28. package/types/helpers/index.d.cts +29 -0
  29. package/types/helpers/index.d.ts +0 -3
  30. package/types/index.d.cts +279 -4
  31. package/types/index.d.ts +4 -1
  32. package/types/models.d.cts +107 -0
  33. package/types/models.d.ts +8 -3
  34. package/types/node/attribute/index.d.cts +109 -0
  35. package/types/node/attribute/index.d.ts +3 -2
  36. package/types/node/attribute/value.d.cts +109 -0
  37. package/types/node/attribute/value.d.ts +3 -2
  38. package/types/node/event.d.cts +7 -0
  39. package/types/node/event.d.ts +3 -3
  40. package/types/node/index.d.cts +108 -0
  41. package/types/node/index.d.ts +2 -2
  42. package/types/node/value.d.cts +108 -0
  43. package/types/node/value.d.ts +2 -2
  44. package/types/parse.d.cts +108 -0
  45. package/types/parse.d.ts +2 -0
  46. package/dist/fragment.mjs +0 -58
  47. package/dist/helpers/dom.mjs +0 -44
  48. package/dist/helpers/index.mjs +0 -25
  49. package/dist/html.mjs +0 -36
  50. package/dist/index.mjs +0 -5
  51. package/dist/node/attribute/index.mjs +0 -35
  52. package/dist/node/attribute/value.mjs +0 -89
  53. package/dist/node/event.mjs +0 -39
  54. package/dist/node/index.mjs +0 -55
  55. package/dist/node/value.mjs +0 -123
  56. package/types/html.d.ts +0 -4
  57. /package/dist/{models.mjs → models.js} +0 -0
@@ -0,0 +1,108 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * A generic key type
5
+ */
6
+ export type Key = number | string;
7
+ export type GenericCallback = (...args: any[]) => any;
8
+ declare class Effect {
9
+ private readonly $mora;
10
+ private readonly state;
11
+ constructor(callback: GenericCallback);
12
+ }
13
+ declare class Computed<Value> extends Reactive<Value> {
14
+ private readonly effect;
15
+ constructor(callback: () => Value, options?: ReactiveOptions<Value>);
16
+ /**
17
+ * @inheritdoc
18
+ */
19
+ get(): Value;
20
+ }
21
+ declare abstract class Reactive<Value, Equal = Value> {
22
+ protected readonly state: ReactiveState<Value, Equal>;
23
+ constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
24
+ /**
25
+ * Get the value
26
+ */
27
+ abstract get(): Value;
28
+ /**
29
+ * Get the value _(without reactivity)_
30
+ */
31
+ peek(): Value;
32
+ /**
33
+ * Subscribe to changes
34
+ */
35
+ subscribe(callback: (value: Value) => void): Unsubscribe;
36
+ /**
37
+ * JSON representation of the value
38
+ */
39
+ toJSON(): Value;
40
+ /**
41
+ * String representation of the value
42
+ */
43
+ toString(): string;
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ unsubscribe(callback: (value: Value) => void): void;
48
+ }
49
+ export type ReactiveOptions<Value> = {
50
+ /**
51
+ * Method to compare values for equality
52
+ */
53
+ equal?: (first: Value, second: Value) => boolean;
54
+ };
55
+ export type ReactiveState<Value, Equal> = {
56
+ computeds: Set<Computed<unknown>>;
57
+ effects: Set<Effect>;
58
+ equal: (first: Equal, second: Equal) => boolean;
59
+ subscriptions: Map<GenericCallback, Subscription>;
60
+ value: Value;
61
+ };
62
+ declare class Subscription {
63
+ state: ReactiveState<unknown, never>;
64
+ callback: GenericCallback;
65
+ constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
66
+ }
67
+ /**
68
+ * Unsubscribe from changes
69
+ */
70
+ export type Unsubscribe = () => void;
71
+ declare class Fragment {
72
+ private readonly $fragment;
73
+ private readonly data;
74
+ get identifier(): Key | undefined;
75
+ constructor(strings: TemplateStringsArray, expressions: unknown[]);
76
+ /**
77
+ * Appends the fragment to the given element
78
+ */
79
+ appendTo(element: Element): void;
80
+ /**
81
+ * Gets a list of the fragment's nodes
82
+ */
83
+ get(): ChildNode[];
84
+ identify(identifier: Key): Fragment;
85
+ /**
86
+ * Removes the fragment from the DOM
87
+ */
88
+ remove(): void;
89
+ }
90
+ export type FragmentData = {
91
+ expressions: unknown[];
92
+ identifier?: Key;
93
+ items: FragmentItem[];
94
+ mora: MoraData;
95
+ strings: TemplateStringsArray;
96
+ values: unknown[];
97
+ };
98
+ export type FragmentItem = {
99
+ fragments?: Fragment[];
100
+ nodes: ChildNode[];
101
+ };
102
+ export type MoraData = {
103
+ subscribers: Set<() => void>;
104
+ values: Set<Reactive<unknown>>;
105
+ };
106
+ export declare function mapNodes(data: FragmentData, nodes: ChildNode[]): void;
107
+
108
+ export {};
@@ -1,2 +1,2 @@
1
- import type { FragmentData, ProperNode } from '../models';
2
- export declare function mapNodes(data: FragmentData, nodes: ProperNode[]): void;
1
+ import type { FragmentData } from '../models';
2
+ export declare function mapNodes(data: FragmentData, nodes: ChildNode[]): void;
@@ -0,0 +1,108 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * A generic key type
5
+ */
6
+ export type Key = number | string;
7
+ export type GenericCallback = (...args: any[]) => any;
8
+ declare class Effect {
9
+ private readonly $mora;
10
+ private readonly state;
11
+ constructor(callback: GenericCallback);
12
+ }
13
+ declare class Computed<Value> extends Reactive<Value> {
14
+ private readonly effect;
15
+ constructor(callback: () => Value, options?: ReactiveOptions<Value>);
16
+ /**
17
+ * @inheritdoc
18
+ */
19
+ get(): Value;
20
+ }
21
+ declare abstract class Reactive<Value, Equal = Value> {
22
+ protected readonly state: ReactiveState<Value, Equal>;
23
+ constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
24
+ /**
25
+ * Get the value
26
+ */
27
+ abstract get(): Value;
28
+ /**
29
+ * Get the value _(without reactivity)_
30
+ */
31
+ peek(): Value;
32
+ /**
33
+ * Subscribe to changes
34
+ */
35
+ subscribe(callback: (value: Value) => void): Unsubscribe;
36
+ /**
37
+ * JSON representation of the value
38
+ */
39
+ toJSON(): Value;
40
+ /**
41
+ * String representation of the value
42
+ */
43
+ toString(): string;
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ unsubscribe(callback: (value: Value) => void): void;
48
+ }
49
+ export type ReactiveOptions<Value> = {
50
+ /**
51
+ * Method to compare values for equality
52
+ */
53
+ equal?: (first: Value, second: Value) => boolean;
54
+ };
55
+ export type ReactiveState<Value, Equal> = {
56
+ computeds: Set<Computed<unknown>>;
57
+ effects: Set<Effect>;
58
+ equal: (first: Equal, second: Equal) => boolean;
59
+ subscriptions: Map<GenericCallback, Subscription>;
60
+ value: Value;
61
+ };
62
+ declare class Subscription {
63
+ state: ReactiveState<unknown, never>;
64
+ callback: GenericCallback;
65
+ constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
66
+ }
67
+ /**
68
+ * Unsubscribe from changes
69
+ */
70
+ export type Unsubscribe = () => void;
71
+ declare class Fragment {
72
+ private readonly $fragment;
73
+ private readonly data;
74
+ get identifier(): Key | undefined;
75
+ constructor(strings: TemplateStringsArray, expressions: unknown[]);
76
+ /**
77
+ * Appends the fragment to the given element
78
+ */
79
+ appendTo(element: Element): void;
80
+ /**
81
+ * Gets a list of the fragment's nodes
82
+ */
83
+ get(): ChildNode[];
84
+ identify(identifier: Key): Fragment;
85
+ /**
86
+ * Removes the fragment from the DOM
87
+ */
88
+ remove(): void;
89
+ }
90
+ export type FragmentData = {
91
+ expressions: unknown[];
92
+ identifier?: Key;
93
+ items: FragmentItem[];
94
+ mora: MoraData;
95
+ strings: TemplateStringsArray;
96
+ values: unknown[];
97
+ };
98
+ export type FragmentItem = {
99
+ fragments?: Fragment[];
100
+ nodes: ChildNode[];
101
+ };
102
+ export type MoraData = {
103
+ subscribers: Set<() => void>;
104
+ values: Set<Reactive<unknown>>;
105
+ };
106
+ export declare function setReactiveValue(data: FragmentData, comment: Comment, reactive: Reactive<unknown>): void;
107
+
108
+ export {};
@@ -1,3 +1,3 @@
1
- import { type Reactive } from '@oscarpalmer/sentinel';
1
+ import type { Reactive } from '@oscarpalmer/mora';
2
2
  import type { FragmentData } from '../models';
3
- export declare function setReactiveNode(data: FragmentData, comment: Comment, reactive: Reactive): void;
3
+ export declare function setReactiveValue(data: FragmentData, comment: Comment, reactive: Reactive<unknown>): void;
@@ -0,0 +1,108 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * A generic key type
5
+ */
6
+ export type Key = number | string;
7
+ export type GenericCallback = (...args: any[]) => any;
8
+ declare class Effect {
9
+ private readonly $mora;
10
+ private readonly state;
11
+ constructor(callback: GenericCallback);
12
+ }
13
+ declare class Computed<Value> extends Reactive<Value> {
14
+ private readonly effect;
15
+ constructor(callback: () => Value, options?: ReactiveOptions<Value>);
16
+ /**
17
+ * @inheritdoc
18
+ */
19
+ get(): Value;
20
+ }
21
+ declare abstract class Reactive<Value, Equal = Value> {
22
+ protected readonly state: ReactiveState<Value, Equal>;
23
+ constructor(name: string, value: Value, options?: ReactiveOptions<Equal>);
24
+ /**
25
+ * Get the value
26
+ */
27
+ abstract get(): Value;
28
+ /**
29
+ * Get the value _(without reactivity)_
30
+ */
31
+ peek(): Value;
32
+ /**
33
+ * Subscribe to changes
34
+ */
35
+ subscribe(callback: (value: Value) => void): Unsubscribe;
36
+ /**
37
+ * JSON representation of the value
38
+ */
39
+ toJSON(): Value;
40
+ /**
41
+ * String representation of the value
42
+ */
43
+ toString(): string;
44
+ /**
45
+ * Unsubscribe from changes
46
+ */
47
+ unsubscribe(callback: (value: Value) => void): void;
48
+ }
49
+ export type ReactiveOptions<Value> = {
50
+ /**
51
+ * Method to compare values for equality
52
+ */
53
+ equal?: (first: Value, second: Value) => boolean;
54
+ };
55
+ export type ReactiveState<Value, Equal> = {
56
+ computeds: Set<Computed<unknown>>;
57
+ effects: Set<Effect>;
58
+ equal: (first: Equal, second: Equal) => boolean;
59
+ subscriptions: Map<GenericCallback, Subscription>;
60
+ value: Value;
61
+ };
62
+ declare class Subscription {
63
+ state: ReactiveState<unknown, never>;
64
+ callback: GenericCallback;
65
+ constructor(state: ReactiveState<unknown, never>, callback: GenericCallback);
66
+ }
67
+ /**
68
+ * Unsubscribe from changes
69
+ */
70
+ export type Unsubscribe = () => void;
71
+ declare class Fragment {
72
+ private readonly $fragment;
73
+ private readonly data;
74
+ get identifier(): Key | undefined;
75
+ constructor(strings: TemplateStringsArray, expressions: unknown[]);
76
+ /**
77
+ * Appends the fragment to the given element
78
+ */
79
+ appendTo(element: Element): void;
80
+ /**
81
+ * Gets a list of the fragment's nodes
82
+ */
83
+ get(): ChildNode[];
84
+ identify(identifier: Key): Fragment;
85
+ /**
86
+ * Removes the fragment from the DOM
87
+ */
88
+ remove(): void;
89
+ }
90
+ export type FragmentData = {
91
+ expressions: unknown[];
92
+ identifier?: Key;
93
+ items: FragmentItem[];
94
+ mora: MoraData;
95
+ strings: TemplateStringsArray;
96
+ values: unknown[];
97
+ };
98
+ export type FragmentItem = {
99
+ fragments?: Fragment[];
100
+ nodes: ChildNode[];
101
+ };
102
+ export type MoraData = {
103
+ subscribers: Set<() => void>;
104
+ values: Set<Reactive<unknown>>;
105
+ };
106
+ export declare function parse(data: FragmentData): string;
107
+
108
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { FragmentData } from './models';
2
+ export declare function parse(data: FragmentData): string;
package/dist/fragment.mjs DELETED
@@ -1,58 +0,0 @@
1
- // src/fragment.ts
2
- import {html as html2} from "@oscarpalmer/toretto/html";
3
- import {parse} from "./html";
4
- import {mapNodes} from "./node";
5
- import {removeNodes} from "./helpers/dom";
6
-
7
- class Fragment {
8
- $fragment = true;
9
- data;
10
- get identifier() {
11
- return this.data.identifier;
12
- }
13
- constructor(strings, expressions) {
14
- this.data = {
15
- expressions,
16
- strings,
17
- items: [],
18
- values: []
19
- };
20
- }
21
- appendTo(element) {
22
- element.append(...this.get());
23
- }
24
- get() {
25
- if (this.data.items.length === 0) {
26
- const parsed = parse(this.data);
27
- const templated = html2(parsed, {
28
- sanitiseBooleanAttributes: false
29
- });
30
- this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
31
- nodes: [node2]
32
- })));
33
- mapNodes(this.data, this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes));
34
- }
35
- return [
36
- ...this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes)
37
- ];
38
- }
39
- identify(identifier) {
40
- this.data.identifier = identifier;
41
- return this;
42
- }
43
- remove() {
44
- const { length } = this.data.items;
45
- for (let index = 0;index < length; index += 1) {
46
- const { fragments, nodes } = this.data.items[index];
47
- const { length: length2 } = fragments ?? [];
48
- for (let index2 = 0;index2 < length2; index2 += 1) {
49
- fragments?.[index2]?.remove();
50
- }
51
- removeNodes(nodes);
52
- }
53
- this.data.items.splice(0, length);
54
- }
55
- }
56
- export {
57
- Fragment
58
- };
@@ -1,44 +0,0 @@
1
- // src/helpers/dom.ts
2
- import {getString} from "@oscarpalmer/atoms/string";
3
- import {isFragment, isProperElement, isProperNode} from "./index";
4
- import {removeEvents} from "../node/event";
5
- function createNodes(value) {
6
- if (isFragment(value)) {
7
- return value.get();
8
- }
9
- if (isProperNode(value)) {
10
- return [value];
11
- }
12
- return [new Text(getString(value))];
13
- }
14
- function removeNodes(nodes) {
15
- sanitiseNodes(nodes);
16
- const { length } = nodes;
17
- for (let index = 0;index < length; index += 1) {
18
- nodes[index].remove();
19
- }
20
- }
21
- function replaceNodes(from, to) {
22
- from[0]?.replaceWith(...to);
23
- const { length } = from;
24
- for (let index = 1;index < length; index += 1) {
25
- from[index].remove();
26
- }
27
- }
28
- function sanitiseNodes(nodes) {
29
- const { length } = nodes;
30
- for (let index = 0;index < length; index += 1) {
31
- const node = nodes[index];
32
- if (isProperElement(node)) {
33
- removeEvents(node);
34
- }
35
- if (node.hasChildNodes()) {
36
- sanitiseNodes([...node.childNodes]);
37
- }
38
- }
39
- }
40
- export {
41
- replaceNodes,
42
- removeNodes,
43
- createNodes
44
- };
@@ -1,25 +0,0 @@
1
- // src/helpers/index.ts
2
- function compareArrays(first, second) {
3
- const firstIsLarger = first.length > second.length;
4
- const from = firstIsLarger ? first : second;
5
- const to = firstIsLarger ? second : first;
6
- if (!from.filter((key) => to.includes(key)).every((key, index) => to[index] === key)) {
7
- return "dissimilar";
8
- }
9
- return firstIsLarger ? "removed" : "added";
10
- }
11
- function isFragment(value) {
12
- return typeof value === "object" && value != null && "$fragment" in value && value.$fragment === true;
13
- }
14
- function isProperElement(value) {
15
- return value instanceof HTMLElement || value instanceof SVGElement;
16
- }
17
- function isProperNode(value) {
18
- return value instanceof CharacterData || value instanceof Element;
19
- }
20
- export {
21
- isProperNode,
22
- isProperElement,
23
- isFragment,
24
- compareArrays
25
- };
package/dist/html.mjs DELETED
@@ -1,36 +0,0 @@
1
- // src/html.ts
2
- import {isNullableOrWhitespace} from "@oscarpalmer/atoms/is";
3
- import {Fragment} from "./fragment";
4
- function handleExpression(data, prefix, expression) {
5
- if (isNullableOrWhitespace(expression)) {
6
- return prefix;
7
- }
8
- if (Array.isArray(expression)) {
9
- const { length } = expression;
10
- let expressions = "";
11
- for (let index = 0;index < length; index += 1) {
12
- expressions += handleExpression(data, "", expression[index]);
13
- }
14
- return `${prefix}${expressions}`;
15
- }
16
- if (typeof expression === "function" || typeof expression === "object") {
17
- const index = data.values.push(expression) - 1;
18
- return `${prefix}<!--abydon.${index}-->`;
19
- }
20
- return `${prefix}${expression}`;
21
- }
22
- function html(strings, ...values) {
23
- return new Fragment(strings, values);
24
- }
25
- function parse(data) {
26
- const { length } = data.strings;
27
- let template = "";
28
- for (let index = 0;index < length; index += 1) {
29
- template += handleExpression(data, data.strings[index], data.expressions[index]);
30
- }
31
- return template;
32
- }
33
- export {
34
- parse,
35
- html
36
- };
package/dist/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- // src/index.ts
2
- import {html} from "./html";
3
- export {
4
- html
5
- };
@@ -1,35 +0,0 @@
1
- // src/node/attribute/index.ts
2
- import {computed, isReactive} from "@oscarpalmer/sentinel";
3
- import {mapEvent} from "../event";
4
- import {setAttribute} from "./value";
5
- function getValue(data, original) {
6
- const matches = commentExpression.exec(original ?? "");
7
- return matches == null ? original : data.values[+matches[1]];
8
- }
9
- function mapAttributes(data, element) {
10
- const attributes = [...element.attributes];
11
- const { length } = attributes;
12
- for (let index = 0;index < length; index += 1) {
13
- const { name, value: value2 } = attributes[index];
14
- const actual = getValue(data, value2);
15
- if (name.startsWith("@")) {
16
- mapEvent(element, name, actual);
17
- } else if (name.includes(".") || typeof value2 === "function" || isReactive(actual)) {
18
- mapValue(element, name, actual);
19
- }
20
- }
21
- }
22
- function mapValue(element, name, value2) {
23
- switch (true) {
24
- case typeof value2 === "function":
25
- setAttribute(element, name, computed(value2));
26
- break;
27
- default:
28
- setAttribute(element, name, value2);
29
- break;
30
- }
31
- }
32
- var commentExpression = /^<!--abydon\.(\d+)-->$/;
33
- export {
34
- mapAttributes
35
- };
@@ -1,89 +0,0 @@
1
- // src/node/attribute/value.ts
2
- import {getString} from "@oscarpalmer/atoms/string";
3
- import {effect, isReactive} from "@oscarpalmer/sentinel";
4
- import {
5
- isBooleanAttribute,
6
- setAttribute as setAttr
7
- } from "@oscarpalmer/toretto/attribute";
8
- function setAttribute(element, name, value) {
9
- element.removeAttribute(name);
10
- switch (true) {
11
- case classExpression.test(name):
12
- setClasses(element, name, value);
13
- return;
14
- case stylePrefixExpression.test(name):
15
- setStyle(element, name, value);
16
- return;
17
- default:
18
- setValue(element, name, value);
19
- break;
20
- }
21
- }
22
- function setClasses(element, name, value) {
23
- function update(value2) {
24
- if (value2 === true) {
25
- element.classList.add(...classes);
26
- } else {
27
- element.classList.remove(...classes);
28
- }
29
- }
30
- const classes = name.slice(6).split(".");
31
- if (isReactive(value)) {
32
- effect(() => {
33
- update(value.get());
34
- });
35
- } else {
36
- update(value);
37
- }
38
- }
39
- function setStyle(element, name, value) {
40
- function update(value2) {
41
- if (value2 == null || value2 === false || value2 === true && unit == null) {
42
- element.style.removeProperty(property);
43
- } else {
44
- element.style.setProperty(property, value2 === true ? unit : getString(value2));
45
- }
46
- }
47
- const [, property, unit] = styleFullExpression.exec(name) ?? [];
48
- if (property != null) {
49
- if (isReactive(value)) {
50
- effect(() => {
51
- update(value.get());
52
- });
53
- } else {
54
- update(value);
55
- }
56
- }
57
- }
58
- function setValue(element, name, value) {
59
- const callback = isBooleanAttribute(name) && name in element ? name === "selected" ? updateSelected : updateProperty : setAttr;
60
- if (isReactive(value)) {
61
- effect(() => {
62
- callback(element, name, value.get());
63
- });
64
- } else {
65
- callback(element, name, value);
66
- }
67
- }
68
- function triggerSelectChange(select) {
69
- if (select != null) {
70
- select.dispatchEvent(new Event("change", { bubbles: true }));
71
- }
72
- }
73
- function updateProperty(element, name, value) {
74
- element[name] = value === true;
75
- }
76
- function updateSelected(element, name, value) {
77
- const select = element.closest("select");
78
- const options = [...select?.options ?? []];
79
- if (select != null && options.includes(element)) {
80
- triggerSelectChange(select);
81
- }
82
- updateProperty(element, name, value);
83
- }
84
- var classExpression = /^class\./;
85
- var styleFullExpression = /^style\.([\w-]+)(?:\.([\w-]+))?$/;
86
- var stylePrefixExpression = /^style\./;
87
- export {
88
- setAttribute
89
- };
@@ -1,39 +0,0 @@
1
- // src/node/event.ts
2
- function getController(element) {
3
- let controller = controllers.get(element);
4
- if (controller == null) {
5
- controller = new AbortController;
6
- controllers.set(element, controller);
7
- }
8
- return controller;
9
- }
10
- function getOptions(options) {
11
- const parts = options.split(":");
12
- return {
13
- capture: parts.includes("c") || parts.includes("capture"),
14
- once: parts.includes("o") || parts.includes("once"),
15
- passive: !parts.includes("a") && !parts.includes("active")
16
- };
17
- }
18
- function mapEvent(element, name, value) {
19
- element.removeAttribute(name);
20
- const [, type, options] = eventNamePattern.exec(name) ?? [];
21
- if (typeof value === "function" && type != null) {
22
- element.addEventListener(type, value, {
23
- ...getOptions(options ?? ""),
24
- signal: getController(element).signal
25
- });
26
- }
27
- }
28
- function removeEvents(element) {
29
- if (controllers.has(element)) {
30
- controllers.get(element)?.abort();
31
- controllers.delete(element);
32
- }
33
- }
34
- var controllers = new WeakMap;
35
- var eventNamePattern = /^@([\w-]+)(?::([a-z:]+))?$/i;
36
- export {
37
- removeEvents,
38
- mapEvent
39
- };