@oscarpalmer/abydon 0.12.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 (54) 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 -911
  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 +13 -14
  14. package/src/helpers/dom.ts +2 -1
  15. package/src/helpers/index.ts +0 -9
  16. package/src/index.ts +11 -2
  17. package/src/models.ts +6 -8
  18. package/src/node/attribute/index.ts +4 -3
  19. package/src/node/attribute/value.ts +8 -15
  20. package/src/node/event.ts +1 -1
  21. package/src/node/index.ts +4 -3
  22. package/src/node/value.ts +6 -7
  23. package/src/{html.ts → parse.ts} +5 -14
  24. package/types/fragment.d.cts +27 -0
  25. package/types/helpers/dom.d.cts +7 -0
  26. package/types/helpers/index.d.cts +29 -0
  27. package/types/helpers/index.d.ts +0 -3
  28. package/types/index.d.cts +278 -2
  29. package/types/index.d.ts +4 -2
  30. package/types/models.d.cts +107 -0
  31. package/types/models.d.ts +6 -7
  32. package/types/node/attribute/index.d.cts +109 -0
  33. package/types/node/attribute/index.d.ts +2 -1
  34. package/types/node/attribute/value.d.cts +109 -0
  35. package/types/node/attribute/value.d.ts +2 -1
  36. package/types/node/event.d.cts +7 -0
  37. package/types/node/event.d.ts +1 -1
  38. package/types/node/index.d.cts +108 -0
  39. package/types/node/value.d.cts +108 -0
  40. package/types/node/value.d.ts +2 -2
  41. package/types/parse.d.cts +108 -0
  42. package/types/parse.d.ts +2 -0
  43. package/dist/fragment.mjs +0 -75
  44. package/dist/helpers/dom.mjs +0 -44
  45. package/dist/helpers/index.mjs +0 -25
  46. package/dist/html.mjs +0 -36
  47. package/dist/index.mjs +0 -6
  48. package/dist/node/attribute/index.mjs +0 -40
  49. package/dist/node/attribute/value.mjs +0 -89
  50. package/dist/node/event.mjs +0 -38
  51. package/dist/node/index.mjs +0 -60
  52. package/dist/node/value.mjs +0 -123
  53. package/types/html.d.ts +0 -4
  54. /package/dist/{models.mjs → models.js} +0 -0
@@ -0,0 +1,109 @@
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
+ type HTMLOrSVGElement$1 = HTMLElement | SVGElement;
107
+ export declare function setAttribute(data: FragmentData, element: HTMLOrSVGElement$1, name: string, value: unknown): void;
108
+
109
+ export {};
@@ -1,2 +1,3 @@
1
- import type { FragmentData, HTMLOrSVGElement } from '../../models';
1
+ import type { HTMLOrSVGElement } from '@oscarpalmer/toretto/models';
2
+ import type { FragmentData } from '../../models';
2
3
  export declare function setAttribute(data: FragmentData, element: HTMLOrSVGElement, name: string, value: unknown): void;
@@ -0,0 +1,7 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ type HTMLOrSVGElement$1 = HTMLElement | SVGElement;
4
+ export declare function mapEvent(element: HTMLOrSVGElement$1, name: string, value: unknown): void;
5
+ export declare function removeEvents(element: HTMLOrSVGElement$1): void;
6
+
7
+ export {};
@@ -1,3 +1,3 @@
1
- import type { HTMLOrSVGElement } from '../models';
1
+ import type { HTMLOrSVGElement } from '@oscarpalmer/toretto/models';
2
2
  export declare function mapEvent(element: HTMLOrSVGElement, name: string, value: unknown): void;
3
3
  export declare function removeEvents(element: HTMLOrSVGElement): 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 mapNodes(data: FragmentData, nodes: ChildNode[]): void;
107
+
108
+ export {};
@@ -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 setReactiveValue(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,75 +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
- function removeFragment(data) {
7
- removeSentinels(data);
8
- const { length } = data.items;
9
- for (let index = 0;index < length; index += 1) {
10
- const { fragments, nodes } = data.items[index];
11
- const { length: length2 } = fragments ?? [];
12
- for (let index2 = 0;index2 < length2; index2 += 1) {
13
- fragments?.[index2]?.remove();
14
- }
15
- removeNodes(nodes);
16
- }
17
- data.items.splice(0, length);
18
- }
19
- function removeSentinels(data) {
20
- const sentinels = [...data.sentinel.effects, ...data.sentinel.values];
21
- const { length } = sentinels;
22
- for (let index = 0;index < length; index += 1) {
23
- sentinels[index].stop();
24
- }
25
- data.sentinel.effects.clear();
26
- data.sentinel.values.clear();
27
- }
28
-
29
- class Fragment {
30
- $fragment = true;
31
- data;
32
- get identifier() {
33
- return this.data.identifier;
34
- }
35
- constructor(strings, expressions) {
36
- this.data = {
37
- expressions,
38
- strings,
39
- items: [],
40
- sentinel: {
41
- effects: new Set,
42
- values: new Set
43
- },
44
- values: []
45
- };
46
- }
47
- appendTo(element) {
48
- element.append(...this.get());
49
- }
50
- get() {
51
- if (this.data.items.length === 0) {
52
- const parsed = parse(this.data);
53
- const templated = html2(parsed, {
54
- sanitiseBooleanAttributes: false
55
- });
56
- this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
57
- nodes: [node2]
58
- })));
59
- mapNodes(this.data, this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes));
60
- }
61
- return [
62
- ...this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes)
63
- ];
64
- }
65
- identify(identifier) {
66
- this.data.identifier = identifier;
67
- return this;
68
- }
69
- remove() {
70
- removeFragment(this.data);
71
- }
72
- }
73
- export {
74
- Fragment
75
- };
@@ -1,44 +0,0 @@
1
- // src/helpers/dom.ts
2
- import {getString} from "@oscarpalmer/atoms/string";
3
- import {isChildNode, isFragment, isHTMLOrSVGElement} from "./index";
4
- import {removeEvents} from "../node/event";
5
- function createNodes(value) {
6
- if (isFragment(value)) {
7
- return value.get();
8
- }
9
- if (isChildNode(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 (isHTMLOrSVGElement(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 isChildNode(value) {
12
- return value instanceof CharacterData || value instanceof Element;
13
- }
14
- function isFragment(value) {
15
- return typeof value === "object" && value != null && "$fragment" in value && value.$fragment === true;
16
- }
17
- function isHTMLOrSVGElement(value) {
18
- return value instanceof HTMLElement || value instanceof SVGElement;
19
- }
20
- export {
21
- isHTMLOrSVGElement,
22
- isFragment,
23
- isChildNode,
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,6 +0,0 @@
1
- // src/index.ts
2
- import"@oscarpalmer/sentinel";
3
- import {html} from "./html";
4
- export {
5
- html
6
- };
@@ -1,40 +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(data, element, name, actual);
19
- }
20
- }
21
- }
22
- function mapValue(data, element, name, value2) {
23
- switch (true) {
24
- case typeof value2 === "function":
25
- setComputedAttribute(data, element, name, value2);
26
- break;
27
- default:
28
- setAttribute(data, element, name, value2);
29
- break;
30
- }
31
- }
32
- function setComputedAttribute(data, element, name, callback) {
33
- const value2 = computed(callback);
34
- data.sentinel.values.add(value2);
35
- setAttribute(data, element, name, value2);
36
- }
37
- var commentExpression = /^<!--abydon\.(\d+)-->$/;
38
- export {
39
- mapAttributes
40
- };