@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
@@ -1,266 +1,266 @@
1
- import { begin, end } from './dependencyDetection.js';
2
- import { getExtenderHandler } from './extenders.js';
3
- import type { ExtenderOptions } from './extenders.js';
4
- import { addDisposeCallback } from './domNodeDisposal.js';
5
-
6
- export type SubscriptionCallback<T> = (value: T) => void;
7
-
8
- const primitiveTypes: Record<string, boolean> = {
9
- undefined: true,
10
- boolean: true,
11
- number: true,
12
- string: true,
13
- };
14
-
15
- export function valuesArePrimitiveAndEqual<T>(a: T, b: T): boolean {
16
- const oldValueIsPrimitive = a === null || typeof a in primitiveTypes;
17
- return oldValueIsPrimitive ? a === b : false;
18
- }
19
-
20
- const DEFAULT_EVENT = 'change';
21
-
22
- export class Subscription<T> {
23
- private _target: Subscribable<T> | null;
24
- private _callback: SubscriptionCallback<T> | null;
25
- private _disposeCallback: (() => void) | null;
26
- private _isDisposed = false;
27
-
28
- constructor(
29
- target: Subscribable<T>,
30
- callback: SubscriptionCallback<T>,
31
- disposeCallback: () => void,
32
- ) {
33
- this._target = target;
34
- this._callback = callback;
35
- this._disposeCallback = disposeCallback;
36
- }
37
-
38
- dispose(): void {
39
- if (!this._isDisposed) {
40
- this._isDisposed = true;
41
- this._disposeCallback!();
42
- this._target = null;
43
- this._callback = null;
44
- this._disposeCallback = null;
45
- }
46
- }
47
-
48
- get closed(): boolean {
49
- return this._isDisposed;
50
- }
51
-
52
- disposeWhenNodeIsRemoved(node: Node): void {
53
- addDisposeCallback(node, () => this.dispose());
54
- }
55
-
56
- /** @internal */
57
- _notify(value: T): void {
58
- if (!this._isDisposed) {
59
- this._callback!(value);
60
- }
61
- }
62
- }
63
-
64
- export class Subscribable<T = unknown> {
65
- private _subscriptions: Record<string, Subscription<T>[]> = { [DEFAULT_EVENT]: [] };
66
- private _versionNumber = 1;
67
-
68
- /** @internal Lazy unique ID for dependency tracking */
69
- _id: number | undefined;
70
-
71
- equalityComparer?: (a: T, b: T) => boolean;
72
-
73
- protected beforeSubscriptionAdd?(event: string): void;
74
- protected afterSubscriptionRemove?(event: string): void;
75
-
76
- subscribe(callback: SubscriptionCallback<T>, event?: string): Subscription<T> {
77
- const eventName = event ?? DEFAULT_EVENT;
78
-
79
- const subscription = new Subscription<T>(this, callback, () => {
80
- const subs = this._subscriptions[eventName];
81
- if (subs) {
82
- const index = subs.indexOf(subscription);
83
- if (index !== -1) {
84
- subs.splice(index, 1);
85
- }
86
- }
87
- this.afterSubscriptionRemove?.(eventName);
88
- });
89
-
90
- this.beforeSubscriptionAdd?.(eventName);
91
-
92
- if (!this._subscriptions[eventName]) {
93
- this._subscriptions[eventName] = [];
94
- }
95
- this._subscriptions[eventName].push(subscription);
96
-
97
- return subscription;
98
- }
99
-
100
- notifySubscribers(value: T, event?: string): void {
101
- const eventName = event ?? DEFAULT_EVENT;
102
-
103
- if (eventName === DEFAULT_EVENT) {
104
- this.updateVersion();
105
- }
106
-
107
- if (this.hasSubscriptionsForEvent(eventName)) {
108
- const subs = this._subscriptions[eventName].slice(0);
109
- try {
110
- begin();
111
- for (let i = 0; i < subs.length; i++) {
112
- subs[i]._notify(value);
113
- }
114
- } finally {
115
- end();
116
- }
117
- }
118
- }
119
-
120
- getVersion(): number {
121
- return this._versionNumber;
122
- }
123
-
124
- hasChanged(versionToCheck: number): boolean {
125
- return this._versionNumber !== versionToCheck;
126
- }
127
-
128
- updateVersion(): void {
129
- ++this._versionNumber;
130
- }
131
-
132
- hasSubscriptionsForEvent(event: string): boolean {
133
- const subs = this._subscriptions[event];
134
- return subs != null && subs.length > 0;
135
- }
136
-
137
- getSubscriptionsCount(event?: string): number {
138
- if (event) {
139
- const subs = this._subscriptions[event];
140
- return subs ? subs.length : 0;
141
- }
142
- let total = 0;
143
- for (const key of Object.keys(this._subscriptions)) {
144
- if (key !== 'dirty') {
145
- total += this._subscriptions[key].length;
146
- }
147
- }
148
- return total;
149
- }
150
-
151
- isDifferent(oldValue: T, newValue: T): boolean {
152
- if (this.equalityComparer) {
153
- return !this.equalityComparer(oldValue, newValue);
154
- }
155
- return true;
156
- }
157
-
158
- extend(requestedExtenders: ExtenderOptions): this {
159
- for (const [key, value] of Object.entries(requestedExtenders)) {
160
- const handler = getExtenderHandler(key);
161
- if (typeof handler === 'function') {
162
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
- handler(this as Subscribable<any>, value);
164
- } else {
165
- throw new Error(`Unknown extender: '${key}'`);
166
- }
167
- }
168
- return this;
169
- }
170
-
171
- /** @internal */
172
- _deferUpdates = false;
173
- /** @internal */
174
- _origNotifySubscribers?: (value: T, event?: string) => void;
175
- /** @internal */
176
- _limitChange?: (value: T, isDirty?: boolean) => void;
177
- /** @internal */
178
- _limitBeforeChange?: (value: T) => void;
179
- /** @internal */
180
- _recordUpdate?: () => void;
181
- /** @internal */
182
- _notificationIsPending?: boolean;
183
- /** @internal */
184
- _changeSubscriptions?: Subscription<T>[];
185
- /** @internal */
186
- _evalIfChanged?(): T;
187
-
188
- limit(limitFunction: (callback: () => void) => () => void): void {
189
- const self = this;
190
- let ignoreBeforeChange = false;
191
- let previousValue: T;
192
- let pendingValue: T;
193
- let didUpdate = false;
194
-
195
- if (!self._origNotifySubscribers) {
196
- self._origNotifySubscribers = self.notifySubscribers.bind(self);
197
- self.notifySubscribers = function limitNotifySubscribers(value: T, event?: string): void {
198
- if (!event || event === DEFAULT_EVENT) {
199
- self._limitChange!(value);
200
- } else if (event === 'beforeChange') {
201
- self._limitBeforeChange!(value);
202
- } else {
203
- self._origNotifySubscribers!(value, event);
204
- }
205
- };
206
- }
207
-
208
- const finish = limitFunction(function () {
209
- self._notificationIsPending = false;
210
-
211
- if (pendingValue === (self as unknown) && self._evalIfChanged) {
212
- pendingValue = self._evalIfChanged();
213
- }
214
- const shouldNotify = didUpdate && self.isDifferent(previousValue, pendingValue);
215
-
216
- didUpdate = ignoreBeforeChange = false;
217
-
218
- if (shouldNotify) {
219
- previousValue = pendingValue;
220
- self._origNotifySubscribers!(pendingValue);
221
- }
222
- });
223
-
224
- self._limitChange = function (value: T, isDirty?: boolean) {
225
- if (!isDirty || !self._notificationIsPending) {
226
- didUpdate = !isDirty;
227
- }
228
- self._changeSubscriptions = self._subscriptions[DEFAULT_EVENT].slice(0);
229
- self._notificationIsPending = ignoreBeforeChange = true;
230
- pendingValue = value;
231
- finish();
232
- };
233
-
234
- self._limitBeforeChange = function (value: T) {
235
- if (!ignoreBeforeChange) {
236
- previousValue = value;
237
- self._origNotifySubscribers!(value, 'beforeChange');
238
- }
239
- };
240
-
241
- self._recordUpdate = function () {
242
- didUpdate = true;
243
- };
244
- }
245
- }
246
-
247
- export function isSubscribable(value: unknown): value is Subscribable {
248
- return (
249
- value != null &&
250
- typeof (value as Subscribable).subscribe === 'function' &&
251
- typeof (value as Subscribable).notifySubscribers === 'function'
252
- );
253
- }
254
-
255
- export interface ReadableSubscribable<T = unknown> extends Subscribable<T> {
256
- get(): T;
257
- peek(): T;
258
- }
259
-
260
- export function isReadableSubscribable(value: unknown): value is ReadableSubscribable {
261
- return (
262
- isSubscribable(value) &&
263
- typeof (value as ReadableSubscribable).get === 'function' &&
264
- typeof (value as ReadableSubscribable).peek === 'function'
265
- );
266
- }
1
+ import { begin, end } from './dependencyDetection.js';
2
+ import { getExtenderHandler } from './extenders.js';
3
+ import type { ExtenderOptions } from './extenders.js';
4
+ import { addDisposeCallback } from './domNodeDisposal.js';
5
+
6
+ export type SubscriptionCallback<T> = (value: T) => void;
7
+
8
+ const primitiveTypes: Record<string, boolean> = {
9
+ undefined: true,
10
+ boolean: true,
11
+ number: true,
12
+ string: true,
13
+ };
14
+
15
+ export function valuesArePrimitiveAndEqual<T>(a: T, b: T): boolean {
16
+ const oldValueIsPrimitive = a === null || typeof a in primitiveTypes;
17
+ return oldValueIsPrimitive ? a === b : false;
18
+ }
19
+
20
+ const DEFAULT_EVENT = 'change';
21
+
22
+ export class Subscription<T> {
23
+ private _target: Subscribable<T> | null;
24
+ private _callback: SubscriptionCallback<T> | null;
25
+ private _disposeCallback: (() => void) | null;
26
+ private _isDisposed = false;
27
+
28
+ constructor(
29
+ target: Subscribable<T>,
30
+ callback: SubscriptionCallback<T>,
31
+ disposeCallback: () => void,
32
+ ) {
33
+ this._target = target;
34
+ this._callback = callback;
35
+ this._disposeCallback = disposeCallback;
36
+ }
37
+
38
+ dispose(): void {
39
+ if (!this._isDisposed) {
40
+ this._isDisposed = true;
41
+ this._disposeCallback!();
42
+ this._target = null;
43
+ this._callback = null;
44
+ this._disposeCallback = null;
45
+ }
46
+ }
47
+
48
+ get closed(): boolean {
49
+ return this._isDisposed;
50
+ }
51
+
52
+ disposeWhenNodeIsRemoved(node: Node): void {
53
+ addDisposeCallback(node, () => this.dispose());
54
+ }
55
+
56
+ /** @internal */
57
+ _notify(value: T): void {
58
+ if (!this._isDisposed) {
59
+ this._callback!(value);
60
+ }
61
+ }
62
+ }
63
+
64
+ export class Subscribable<T = unknown> {
65
+ private _subscriptions: Record<string, Subscription<T>[]> = { [DEFAULT_EVENT]: [] };
66
+ private _versionNumber = 1;
67
+
68
+ /** @internal Lazy unique ID for dependency tracking */
69
+ _id: number | undefined;
70
+
71
+ equalityComparer?: (a: T, b: T) => boolean;
72
+
73
+ protected beforeSubscriptionAdd?(event: string): void;
74
+ protected afterSubscriptionRemove?(event: string): void;
75
+
76
+ subscribe(callback: SubscriptionCallback<T>, event?: string): Subscription<T> {
77
+ const eventName = event ?? DEFAULT_EVENT;
78
+
79
+ const subscription = new Subscription<T>(this, callback, () => {
80
+ const subs = this._subscriptions[eventName];
81
+ if (subs) {
82
+ const index = subs.indexOf(subscription);
83
+ if (index !== -1) {
84
+ subs.splice(index, 1);
85
+ }
86
+ }
87
+ this.afterSubscriptionRemove?.(eventName);
88
+ });
89
+
90
+ this.beforeSubscriptionAdd?.(eventName);
91
+
92
+ if (!this._subscriptions[eventName]) {
93
+ this._subscriptions[eventName] = [];
94
+ }
95
+ this._subscriptions[eventName].push(subscription);
96
+
97
+ return subscription;
98
+ }
99
+
100
+ notifySubscribers(value: T, event?: string): void {
101
+ const eventName = event ?? DEFAULT_EVENT;
102
+
103
+ if (eventName === DEFAULT_EVENT) {
104
+ this.updateVersion();
105
+ }
106
+
107
+ if (this.hasSubscriptionsForEvent(eventName)) {
108
+ const subs = this._subscriptions[eventName].slice(0);
109
+ try {
110
+ begin();
111
+ for (let i = 0; i < subs.length; i++) {
112
+ subs[i]._notify(value);
113
+ }
114
+ } finally {
115
+ end();
116
+ }
117
+ }
118
+ }
119
+
120
+ getVersion(): number {
121
+ return this._versionNumber;
122
+ }
123
+
124
+ hasChanged(versionToCheck: number): boolean {
125
+ return this._versionNumber !== versionToCheck;
126
+ }
127
+
128
+ updateVersion(): void {
129
+ ++this._versionNumber;
130
+ }
131
+
132
+ hasSubscriptionsForEvent(event: string): boolean {
133
+ const subs = this._subscriptions[event];
134
+ return subs != null && subs.length > 0;
135
+ }
136
+
137
+ getSubscriptionsCount(event?: string): number {
138
+ if (event) {
139
+ const subs = this._subscriptions[event];
140
+ return subs ? subs.length : 0;
141
+ }
142
+ let total = 0;
143
+ for (const key of Object.keys(this._subscriptions)) {
144
+ if (key !== 'dirty') {
145
+ total += this._subscriptions[key].length;
146
+ }
147
+ }
148
+ return total;
149
+ }
150
+
151
+ isDifferent(oldValue: T, newValue: T): boolean {
152
+ if (this.equalityComparer) {
153
+ return !this.equalityComparer(oldValue, newValue);
154
+ }
155
+ return true;
156
+ }
157
+
158
+ extend(requestedExtenders: ExtenderOptions): this {
159
+ for (const [key, value] of Object.entries(requestedExtenders)) {
160
+ const handler = getExtenderHandler(key);
161
+ if (typeof handler === 'function') {
162
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
+ handler(this as Subscribable<any>, value);
164
+ } else {
165
+ throw new Error(`Unknown extender: '${key}'`);
166
+ }
167
+ }
168
+ return this;
169
+ }
170
+
171
+ /** @internal */
172
+ _deferUpdates = false;
173
+ /** @internal */
174
+ _origNotifySubscribers?: (value: T, event?: string) => void;
175
+ /** @internal */
176
+ _limitChange?: (value: T, isDirty?: boolean) => void;
177
+ /** @internal */
178
+ _limitBeforeChange?: (value: T) => void;
179
+ /** @internal */
180
+ _recordUpdate?: () => void;
181
+ /** @internal */
182
+ _notificationIsPending?: boolean;
183
+ /** @internal */
184
+ _changeSubscriptions?: Subscription<T>[];
185
+ /** @internal */
186
+ _evalIfChanged?(): T;
187
+
188
+ limit(limitFunction: (callback: () => void) => () => void): void {
189
+ const self = this;
190
+ let ignoreBeforeChange = false;
191
+ let previousValue: T;
192
+ let pendingValue: T;
193
+ let didUpdate = false;
194
+
195
+ if (!self._origNotifySubscribers) {
196
+ self._origNotifySubscribers = self.notifySubscribers.bind(self);
197
+ self.notifySubscribers = function limitNotifySubscribers(value: T, event?: string): void {
198
+ if (!event || event === DEFAULT_EVENT) {
199
+ self._limitChange!(value);
200
+ } else if (event === 'beforeChange') {
201
+ self._limitBeforeChange!(value);
202
+ } else {
203
+ self._origNotifySubscribers!(value, event);
204
+ }
205
+ };
206
+ }
207
+
208
+ const finish = limitFunction(function () {
209
+ self._notificationIsPending = false;
210
+
211
+ if (pendingValue === (self as unknown) && self._evalIfChanged) {
212
+ pendingValue = self._evalIfChanged();
213
+ }
214
+ const shouldNotify = didUpdate && self.isDifferent(previousValue, pendingValue);
215
+
216
+ didUpdate = ignoreBeforeChange = false;
217
+
218
+ if (shouldNotify) {
219
+ previousValue = pendingValue;
220
+ self._origNotifySubscribers!(pendingValue);
221
+ }
222
+ });
223
+
224
+ self._limitChange = function (value: T, isDirty?: boolean) {
225
+ if (!isDirty || !self._notificationIsPending) {
226
+ didUpdate = !isDirty;
227
+ }
228
+ self._changeSubscriptions = self._subscriptions[DEFAULT_EVENT].slice(0);
229
+ self._notificationIsPending = ignoreBeforeChange = true;
230
+ pendingValue = value;
231
+ finish();
232
+ };
233
+
234
+ self._limitBeforeChange = function (value: T) {
235
+ if (!ignoreBeforeChange) {
236
+ previousValue = value;
237
+ self._origNotifySubscribers!(value, 'beforeChange');
238
+ }
239
+ };
240
+
241
+ self._recordUpdate = function () {
242
+ didUpdate = true;
243
+ };
244
+ }
245
+ }
246
+
247
+ export function isSubscribable(value: unknown): value is Subscribable {
248
+ return (
249
+ value != null &&
250
+ typeof (value as Subscribable).subscribe === 'function' &&
251
+ typeof (value as Subscribable).notifySubscribers === 'function'
252
+ );
253
+ }
254
+
255
+ export interface ReadableSubscribable<T = unknown> extends Subscribable<T> {
256
+ get(): T;
257
+ peek(): T;
258
+ }
259
+
260
+ export function isReadableSubscribable(value: unknown): value is ReadableSubscribable {
261
+ return (
262
+ isSubscribable(value) &&
263
+ typeof (value as ReadableSubscribable).get === 'function' &&
264
+ typeof (value as ReadableSubscribable).peek === 'function'
265
+ );
266
+ }