@thomas-siegfried/tapout 0.0.1 → 0.0.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 (52) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1207 -1205
  3. package/decorator-config.md +220 -0
  4. package/dist/wireParams.d.ts.map +1 -1
  5. package/dist/wireParams.js +27 -4
  6. package/dist/wireParams.js.map +1 -1
  7. package/llms.txt +360 -0
  8. package/package.json +57 -55
  9. package/src/applyBindings.ts +372 -372
  10. package/src/arrayToDomMapping.ts +300 -300
  11. package/src/attributeInterpolationMarkup.ts +91 -91
  12. package/src/bindingContext.ts +207 -207
  13. package/src/bindingEvent.ts +198 -198
  14. package/src/bindingProvider.ts +260 -260
  15. package/src/bindings.ts +963 -963
  16. package/src/compareArrays.ts +122 -122
  17. package/src/componentBinding.ts +318 -318
  18. package/src/componentDecorator.ts +62 -62
  19. package/src/components.ts +367 -367
  20. package/src/computed.ts +439 -439
  21. package/src/configure.ts +52 -52
  22. package/src/controlFlowBindings.ts +206 -206
  23. package/src/core.ts +60 -60
  24. package/src/decorators.ts +407 -407
  25. package/src/dependencyDetection.ts +76 -76
  26. package/src/disposable.ts +36 -36
  27. package/src/domData.ts +42 -42
  28. package/src/domNodeDisposal.ts +94 -94
  29. package/src/effects.ts +29 -29
  30. package/src/event.ts +173 -173
  31. package/src/expressionRewriting.ts +219 -219
  32. package/src/extenders.ts +102 -102
  33. package/src/filters.ts +91 -91
  34. package/src/index.ts +150 -150
  35. package/src/interpolationMarkup.ts +130 -130
  36. package/src/memoization.ts +71 -71
  37. package/src/namespacedBindings.ts +132 -132
  38. package/src/observable.ts +48 -48
  39. package/src/observableArray.ts +397 -397
  40. package/src/options.ts +25 -25
  41. package/src/selectExtensions.ts +68 -68
  42. package/src/slotBinding.ts +84 -84
  43. package/src/subscribable.ts +266 -266
  44. package/src/tasks.ts +79 -79
  45. package/src/templateEngine.ts +108 -108
  46. package/src/templateRendering.ts +399 -399
  47. package/src/templateRewriting.ts +94 -94
  48. package/src/templateSources.ts +134 -134
  49. package/src/utils.ts +123 -123
  50. package/src/utilsDom.ts +87 -87
  51. package/src/virtualElements.ts +153 -153
  52. package/src/wireParams.ts +69 -49
package/src/event.ts CHANGED
@@ -1,173 +1,173 @@
1
- import { addDisposeCallback } from './domNodeDisposal.js';
2
-
3
- export type EventCallback<T> = (value: T) => void;
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export type Constructor<T> = abstract new (...args: any[]) => T;
7
-
8
- interface SubscriptionEntry<T> {
9
- callback: EventCallback<T>;
10
- disposed: boolean;
11
- }
12
-
13
- export class EventSubscription {
14
- private _disposeCallback: (() => void) | null;
15
- private _isDisposed = false;
16
-
17
- constructor(disposeCallback: () => void) {
18
- this._disposeCallback = disposeCallback;
19
- }
20
-
21
- dispose(): void {
22
- if (!this._isDisposed) {
23
- this._isDisposed = true;
24
- this._disposeCallback!();
25
- this._disposeCallback = null;
26
- }
27
- }
28
-
29
- get closed(): boolean {
30
- return this._isDisposed;
31
- }
32
-
33
- disposeWhenNodeIsRemoved(node: Node): void {
34
- addDisposeCallback(node, () => this.dispose());
35
- }
36
- }
37
-
38
- export class EventSubscribable<T = unknown> {
39
- #entries: SubscriptionEntry<T>[] = [];
40
- #isDisposed = false;
41
-
42
- subscribe(callback: EventCallback<T>): EventSubscription {
43
- if (this.#isDisposed) {
44
- throw new Error('EventSubscribable is disposed');
45
- }
46
- const entry: SubscriptionEntry<T> = { callback, disposed: false };
47
- this.#entries.push(entry);
48
- return new EventSubscription(() => {
49
- entry.disposed = true;
50
- const idx = this.#entries.indexOf(entry);
51
- if (idx !== -1) {
52
- this.#entries.splice(idx, 1);
53
- }
54
- });
55
- }
56
-
57
- on<U extends T>(type: Constructor<U>): EventSubscribable<U> {
58
- return new FilteredEventSubscribable<T, U>(this, type);
59
- }
60
-
61
- get subscriberCount(): number {
62
- return this.#entries.length;
63
- }
64
-
65
- /** @internal */
66
- _emit(value: T): void {
67
- if (this.#isDisposed) return;
68
- const snapshot = this.#entries.slice();
69
- for (let i = 0; i < snapshot.length; i++) {
70
- if (!snapshot[i].disposed) {
71
- snapshot[i].callback(value);
72
- }
73
- }
74
- }
75
-
76
- /** @internal */
77
- _dispose(): void {
78
- this.#isDisposed = true;
79
- this.#entries.length = 0;
80
- }
81
- }
82
-
83
- class FilteredEventSubscribable<T, U extends T> extends EventSubscribable<U> {
84
- private _parent: EventSubscribable<T>;
85
- private _type: Constructor<U>;
86
-
87
- constructor(parent: EventSubscribable<T>, type: Constructor<U>) {
88
- super();
89
- this._parent = parent;
90
- this._type = type;
91
- }
92
-
93
- override subscribe(callback: EventCallback<U>): EventSubscription {
94
- return this._parent.subscribe((value: T) => {
95
- if (value instanceof this._type) {
96
- callback(value as U);
97
- }
98
- });
99
- }
100
-
101
- override on<V extends U>(type: Constructor<V>): EventSubscribable<V> {
102
- return new FilteredEventSubscribable<T, V>(this._parent, type);
103
- }
104
- }
105
-
106
- export class Event<T = unknown> {
107
- private _subscribable: EventSubscribable<T>;
108
- private _isDisposed = false;
109
-
110
- constructor() {
111
- this._subscribable = new EventSubscribable<T>();
112
- }
113
-
114
- get subscribable(): EventSubscribable<T> {
115
- return this._subscribable;
116
- }
117
-
118
- emit(value: T): void {
119
- if (this._isDisposed) {
120
- throw new Error('Event is disposed');
121
- }
122
- this._subscribable._emit(value);
123
- }
124
-
125
- dispose(): void {
126
- if (!this._isDisposed) {
127
- this._isDisposed = true;
128
- this._subscribable._dispose();
129
- }
130
- }
131
-
132
- get isDisposed(): boolean {
133
- return this._isDisposed;
134
- }
135
- }
136
-
137
- export class AggregateEvent<T = unknown> extends Event<T> {
138
- private _pipedSubscriptions: EventSubscription[] = [];
139
-
140
- pipe(...sources: EventSubscribable<T>[]): EventSubscription[] {
141
- const newSubs: EventSubscription[] = [];
142
- for (const source of sources) {
143
- const sub = source.subscribe((value: T) => {
144
- this.emit(value);
145
- });
146
- this._pipedSubscriptions.push(sub);
147
- newSubs.push(sub);
148
- }
149
- return newSubs;
150
- }
151
-
152
- override dispose(): void {
153
- for (const sub of this._pipedSubscriptions) {
154
- if (!sub.closed) {
155
- sub.dispose();
156
- }
157
- }
158
- this._pipedSubscriptions.length = 0;
159
- super.dispose();
160
- }
161
- }
162
-
163
- export function isEvent(value: unknown): value is Event {
164
- return value instanceof Event;
165
- }
166
-
167
- export function isEventSubscribable(value: unknown): value is EventSubscribable {
168
- return value instanceof EventSubscribable;
169
- }
170
-
171
- export function isAggregateEvent(value: unknown): value is AggregateEvent {
172
- return value instanceof AggregateEvent;
173
- }
1
+ import { addDisposeCallback } from './domNodeDisposal.js';
2
+
3
+ export type EventCallback<T> = (value: T) => void;
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ export type Constructor<T> = abstract new (...args: any[]) => T;
7
+
8
+ interface SubscriptionEntry<T> {
9
+ callback: EventCallback<T>;
10
+ disposed: boolean;
11
+ }
12
+
13
+ export class EventSubscription {
14
+ private _disposeCallback: (() => void) | null;
15
+ private _isDisposed = false;
16
+
17
+ constructor(disposeCallback: () => void) {
18
+ this._disposeCallback = disposeCallback;
19
+ }
20
+
21
+ dispose(): void {
22
+ if (!this._isDisposed) {
23
+ this._isDisposed = true;
24
+ this._disposeCallback!();
25
+ this._disposeCallback = null;
26
+ }
27
+ }
28
+
29
+ get closed(): boolean {
30
+ return this._isDisposed;
31
+ }
32
+
33
+ disposeWhenNodeIsRemoved(node: Node): void {
34
+ addDisposeCallback(node, () => this.dispose());
35
+ }
36
+ }
37
+
38
+ export class EventSubscribable<T = unknown> {
39
+ #entries: SubscriptionEntry<T>[] = [];
40
+ #isDisposed = false;
41
+
42
+ subscribe(callback: EventCallback<T>): EventSubscription {
43
+ if (this.#isDisposed) {
44
+ throw new Error('EventSubscribable is disposed');
45
+ }
46
+ const entry: SubscriptionEntry<T> = { callback, disposed: false };
47
+ this.#entries.push(entry);
48
+ return new EventSubscription(() => {
49
+ entry.disposed = true;
50
+ const idx = this.#entries.indexOf(entry);
51
+ if (idx !== -1) {
52
+ this.#entries.splice(idx, 1);
53
+ }
54
+ });
55
+ }
56
+
57
+ on<U extends T>(type: Constructor<U>): EventSubscribable<U> {
58
+ return new FilteredEventSubscribable<T, U>(this, type);
59
+ }
60
+
61
+ get subscriberCount(): number {
62
+ return this.#entries.length;
63
+ }
64
+
65
+ /** @internal */
66
+ _emit(value: T): void {
67
+ if (this.#isDisposed) return;
68
+ const snapshot = this.#entries.slice();
69
+ for (let i = 0; i < snapshot.length; i++) {
70
+ if (!snapshot[i].disposed) {
71
+ snapshot[i].callback(value);
72
+ }
73
+ }
74
+ }
75
+
76
+ /** @internal */
77
+ _dispose(): void {
78
+ this.#isDisposed = true;
79
+ this.#entries.length = 0;
80
+ }
81
+ }
82
+
83
+ class FilteredEventSubscribable<T, U extends T> extends EventSubscribable<U> {
84
+ private _parent: EventSubscribable<T>;
85
+ private _type: Constructor<U>;
86
+
87
+ constructor(parent: EventSubscribable<T>, type: Constructor<U>) {
88
+ super();
89
+ this._parent = parent;
90
+ this._type = type;
91
+ }
92
+
93
+ override subscribe(callback: EventCallback<U>): EventSubscription {
94
+ return this._parent.subscribe((value: T) => {
95
+ if (value instanceof this._type) {
96
+ callback(value as U);
97
+ }
98
+ });
99
+ }
100
+
101
+ override on<V extends U>(type: Constructor<V>): EventSubscribable<V> {
102
+ return new FilteredEventSubscribable<T, V>(this._parent, type);
103
+ }
104
+ }
105
+
106
+ export class Event<T = unknown> {
107
+ private _subscribable: EventSubscribable<T>;
108
+ private _isDisposed = false;
109
+
110
+ constructor() {
111
+ this._subscribable = new EventSubscribable<T>();
112
+ }
113
+
114
+ get subscribable(): EventSubscribable<T> {
115
+ return this._subscribable;
116
+ }
117
+
118
+ emit(value: T): void {
119
+ if (this._isDisposed) {
120
+ throw new Error('Event is disposed');
121
+ }
122
+ this._subscribable._emit(value);
123
+ }
124
+
125
+ dispose(): void {
126
+ if (!this._isDisposed) {
127
+ this._isDisposed = true;
128
+ this._subscribable._dispose();
129
+ }
130
+ }
131
+
132
+ get isDisposed(): boolean {
133
+ return this._isDisposed;
134
+ }
135
+ }
136
+
137
+ export class AggregateEvent<T = unknown> extends Event<T> {
138
+ private _pipedSubscriptions: EventSubscription[] = [];
139
+
140
+ pipe(...sources: EventSubscribable<T>[]): EventSubscription[] {
141
+ const newSubs: EventSubscription[] = [];
142
+ for (const source of sources) {
143
+ const sub = source.subscribe((value: T) => {
144
+ this.emit(value);
145
+ });
146
+ this._pipedSubscriptions.push(sub);
147
+ newSubs.push(sub);
148
+ }
149
+ return newSubs;
150
+ }
151
+
152
+ override dispose(): void {
153
+ for (const sub of this._pipedSubscriptions) {
154
+ if (!sub.closed) {
155
+ sub.dispose();
156
+ }
157
+ }
158
+ this._pipedSubscriptions.length = 0;
159
+ super.dispose();
160
+ }
161
+ }
162
+
163
+ export function isEvent(value: unknown): value is Event {
164
+ return value instanceof Event;
165
+ }
166
+
167
+ export function isEventSubscribable(value: unknown): value is EventSubscribable {
168
+ return value instanceof EventSubscribable;
169
+ }
170
+
171
+ export function isAggregateEvent(value: unknown): value is AggregateEvent {
172
+ return value instanceof AggregateEvent;
173
+ }