@thomas-siegfried/tapout 0.0.1 → 0.0.2

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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1205 -1205
  3. package/package.json +55 -55
  4. package/src/applyBindings.ts +372 -372
  5. package/src/arrayToDomMapping.ts +300 -300
  6. package/src/attributeInterpolationMarkup.ts +91 -91
  7. package/src/bindingContext.ts +207 -207
  8. package/src/bindingEvent.ts +198 -198
  9. package/src/bindingProvider.ts +260 -260
  10. package/src/bindings.ts +963 -963
  11. package/src/compareArrays.ts +122 -122
  12. package/src/componentBinding.ts +318 -318
  13. package/src/componentDecorator.ts +62 -62
  14. package/src/components.ts +367 -367
  15. package/src/computed.ts +439 -439
  16. package/src/configure.ts +52 -52
  17. package/src/controlFlowBindings.ts +206 -206
  18. package/src/core.ts +60 -60
  19. package/src/decorators.ts +407 -407
  20. package/src/dependencyDetection.ts +76 -76
  21. package/src/disposable.ts +36 -36
  22. package/src/domData.ts +42 -42
  23. package/src/domNodeDisposal.ts +94 -94
  24. package/src/effects.ts +29 -29
  25. package/src/event.ts +173 -173
  26. package/src/expressionRewriting.ts +219 -219
  27. package/src/extenders.ts +102 -102
  28. package/src/filters.ts +91 -91
  29. package/src/index.ts +150 -150
  30. package/src/interpolationMarkup.ts +130 -130
  31. package/src/memoization.ts +71 -71
  32. package/src/namespacedBindings.ts +132 -132
  33. package/src/observable.ts +48 -48
  34. package/src/observableArray.ts +397 -397
  35. package/src/options.ts +25 -25
  36. package/src/selectExtensions.ts +68 -68
  37. package/src/slotBinding.ts +84 -84
  38. package/src/subscribable.ts +266 -266
  39. package/src/tasks.ts +79 -79
  40. package/src/templateEngine.ts +108 -108
  41. package/src/templateRendering.ts +399 -399
  42. package/src/templateRewriting.ts +94 -94
  43. package/src/templateSources.ts +134 -134
  44. package/src/utils.ts +123 -123
  45. package/src/utilsDom.ts +87 -87
  46. package/src/virtualElements.ts +153 -153
  47. package/src/wireParams.ts +49 -49
package/src/tasks.ts CHANGED
@@ -1,79 +1,79 @@
1
- import { options } from './options.js';
2
-
3
- type TaskCallback = () => void;
4
-
5
- let taskQueue: (TaskCallback | null)[] = [];
6
- let taskQueueLength = 0;
7
- let nextHandle = 1;
8
- let nextIndexToProcess = 0;
9
-
10
- export let scheduler: (callback: TaskCallback) => void =
11
- typeof queueMicrotask === 'function'
12
- ? (cb) => queueMicrotask(cb)
13
- : (cb) => setTimeout(cb, 0);
14
-
15
- function deferError(error: unknown): void {
16
- if (options.onError) {
17
- options.onError(error);
18
- } else {
19
- setTimeout(() => { throw error; }, 0);
20
- }
21
- }
22
-
23
- function processTasks(): void {
24
- if (taskQueueLength) {
25
- let mark = taskQueueLength;
26
- let countMarks = 0;
27
-
28
- for (let task: TaskCallback | null; nextIndexToProcess < taskQueueLength; ) {
29
- task = taskQueue[nextIndexToProcess++];
30
- if (task) {
31
- if (nextIndexToProcess > mark) {
32
- if (++countMarks >= 5000) {
33
- nextIndexToProcess = taskQueueLength;
34
- deferError(new Error("'Too much recursion' after processing " + countMarks + " task groups."));
35
- break;
36
- }
37
- mark = taskQueueLength;
38
- }
39
- try {
40
- task();
41
- } catch (ex) {
42
- deferError(ex);
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- function scheduledProcess(): void {
50
- processTasks();
51
- nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
52
- }
53
-
54
- function scheduleTaskProcessing(): void {
55
- scheduler(scheduledProcess);
56
- }
57
-
58
- export function schedule(func: TaskCallback): number {
59
- if (!taskQueueLength) {
60
- scheduleTaskProcessing();
61
- }
62
- taskQueue[taskQueueLength++] = func;
63
- return nextHandle++;
64
- }
65
-
66
- export function cancel(handle: number): void {
67
- const index = handle - (nextHandle - taskQueueLength);
68
- if (index >= nextIndexToProcess && index < taskQueueLength) {
69
- taskQueue[index] = null;
70
- }
71
- }
72
-
73
- export function resetForTesting(): number {
74
- const length = taskQueueLength - nextIndexToProcess;
75
- nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
76
- return length;
77
- }
78
-
79
- export const runEarly: () => void = processTasks;
1
+ import { options } from './options.js';
2
+
3
+ type TaskCallback = () => void;
4
+
5
+ let taskQueue: (TaskCallback | null)[] = [];
6
+ let taskQueueLength = 0;
7
+ let nextHandle = 1;
8
+ let nextIndexToProcess = 0;
9
+
10
+ export let scheduler: (callback: TaskCallback) => void =
11
+ typeof queueMicrotask === 'function'
12
+ ? (cb) => queueMicrotask(cb)
13
+ : (cb) => setTimeout(cb, 0);
14
+
15
+ function deferError(error: unknown): void {
16
+ if (options.onError) {
17
+ options.onError(error);
18
+ } else {
19
+ setTimeout(() => { throw error; }, 0);
20
+ }
21
+ }
22
+
23
+ function processTasks(): void {
24
+ if (taskQueueLength) {
25
+ let mark = taskQueueLength;
26
+ let countMarks = 0;
27
+
28
+ for (let task: TaskCallback | null; nextIndexToProcess < taskQueueLength; ) {
29
+ task = taskQueue[nextIndexToProcess++];
30
+ if (task) {
31
+ if (nextIndexToProcess > mark) {
32
+ if (++countMarks >= 5000) {
33
+ nextIndexToProcess = taskQueueLength;
34
+ deferError(new Error("'Too much recursion' after processing " + countMarks + " task groups."));
35
+ break;
36
+ }
37
+ mark = taskQueueLength;
38
+ }
39
+ try {
40
+ task();
41
+ } catch (ex) {
42
+ deferError(ex);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ function scheduledProcess(): void {
50
+ processTasks();
51
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
52
+ }
53
+
54
+ function scheduleTaskProcessing(): void {
55
+ scheduler(scheduledProcess);
56
+ }
57
+
58
+ export function schedule(func: TaskCallback): number {
59
+ if (!taskQueueLength) {
60
+ scheduleTaskProcessing();
61
+ }
62
+ taskQueue[taskQueueLength++] = func;
63
+ return nextHandle++;
64
+ }
65
+
66
+ export function cancel(handle: number): void {
67
+ const index = handle - (nextHandle - taskQueueLength);
68
+ if (index >= nextIndexToProcess && index < taskQueueLength) {
69
+ taskQueue[index] = null;
70
+ }
71
+ }
72
+
73
+ export function resetForTesting(): number {
74
+ const length = taskQueueLength - nextIndexToProcess;
75
+ nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
76
+ return length;
77
+ }
78
+
79
+ export const runEarly: () => void = processTasks;
@@ -1,108 +1,108 @@
1
- import { DomElementSource, AnonymousSource } from './templateSources.js';
2
- import { parseHtmlFragment } from './utilsDom.js';
3
- import type { BindingContext } from './bindingContext.js';
4
-
5
- export interface TemplateRenderOptions {
6
- templateEngine?: TemplateEngine;
7
- foreach?: unknown;
8
- as?: string;
9
- noChildContext?: boolean;
10
- includeDestroyed?: boolean;
11
- afterRender?: (nodes: Node[], data: unknown) => void;
12
- afterAdd?: (node: Node, index: number, item: unknown) => void;
13
- beforeRemove?: (node: Node, index: number, item: unknown) => void;
14
- beforeMove?: (node: Node, index: number, item: unknown) => void;
15
- afterMove?: (node: Node, index: number, item: unknown) => void;
16
- if?: unknown;
17
- ifnot?: unknown;
18
- data?: unknown;
19
- exportDependencies?: boolean;
20
- dontLimitMoves?: boolean;
21
- }
22
-
23
- export type TemplateSource = DomElementSource | AnonymousSource;
24
-
25
- export abstract class TemplateEngine {
26
- allowTemplateRewriting = false;
27
-
28
- abstract renderTemplateSource(
29
- templateSource: TemplateSource,
30
- bindingContext: BindingContext,
31
- options: TemplateRenderOptions,
32
- templateDocument?: Document,
33
- ): Node[];
34
-
35
- createJavaScriptEvaluatorBlock(_script: string): string {
36
- throw new Error('Override createJavaScriptEvaluatorBlock');
37
- }
38
-
39
- makeTemplateSource(template: string | Node, templateDocument?: Document): TemplateSource {
40
- if (typeof template === 'string') {
41
- const doc = templateDocument || document;
42
- const elem = doc.getElementById(template);
43
- if (!elem) throw new Error('Cannot find template with ID ' + template);
44
- return new DomElementSource(elem);
45
- } else if (template.nodeType === 1 || template.nodeType === 8) {
46
- return new AnonymousSource(template as Element | Comment);
47
- } else {
48
- throw new Error('Unknown template type: ' + template);
49
- }
50
- }
51
-
52
- renderTemplate(
53
- template: string | Node,
54
- bindingContext: BindingContext,
55
- options: TemplateRenderOptions,
56
- templateDocument?: Document,
57
- ): Node[] {
58
- const source = this.makeTemplateSource(template, templateDocument);
59
- return this.renderTemplateSource(source, bindingContext, options, templateDocument);
60
- }
61
-
62
- isTemplateRewritten(template: string | Node, templateDocument?: Document): boolean {
63
- if (this.allowTemplateRewriting === false) return true;
64
- return !!this.makeTemplateSource(template, templateDocument).data('isRewritten');
65
- }
66
-
67
- rewriteTemplate(
68
- template: string | Node,
69
- rewriterCallback: (text: string) => string,
70
- templateDocument?: Document,
71
- ): void {
72
- const templateSource = this.makeTemplateSource(template, templateDocument);
73
- const rewritten = rewriterCallback(templateSource.text());
74
- templateSource.text(rewritten);
75
- templateSource.data('isRewritten', true);
76
- }
77
- }
78
-
79
- export class NativeTemplateEngine extends TemplateEngine {
80
- override allowTemplateRewriting = false;
81
-
82
- renderTemplateSource(
83
- templateSource: TemplateSource,
84
- _bindingContext: BindingContext,
85
- _options: TemplateRenderOptions,
86
- templateDocument?: Document,
87
- ): Node[] {
88
- const templateNodes = templateSource.nodes();
89
- if (templateNodes) {
90
- return Array.from(templateNodes.cloneNode(true).childNodes);
91
- } else {
92
- const templateText = templateSource.text();
93
- return parseHtmlFragment(templateText, templateDocument);
94
- }
95
- }
96
- }
97
-
98
- export const nativeTemplateEngine = new NativeTemplateEngine();
99
-
100
- let _templateEngine: TemplateEngine = nativeTemplateEngine;
101
-
102
- export function setTemplateEngine(engine: TemplateEngine): void {
103
- _templateEngine = engine;
104
- }
105
-
106
- export function getTemplateEngine(): TemplateEngine {
107
- return _templateEngine;
108
- }
1
+ import { DomElementSource, AnonymousSource } from './templateSources.js';
2
+ import { parseHtmlFragment } from './utilsDom.js';
3
+ import type { BindingContext } from './bindingContext.js';
4
+
5
+ export interface TemplateRenderOptions {
6
+ templateEngine?: TemplateEngine;
7
+ foreach?: unknown;
8
+ as?: string;
9
+ noChildContext?: boolean;
10
+ includeDestroyed?: boolean;
11
+ afterRender?: (nodes: Node[], data: unknown) => void;
12
+ afterAdd?: (node: Node, index: number, item: unknown) => void;
13
+ beforeRemove?: (node: Node, index: number, item: unknown) => void;
14
+ beforeMove?: (node: Node, index: number, item: unknown) => void;
15
+ afterMove?: (node: Node, index: number, item: unknown) => void;
16
+ if?: unknown;
17
+ ifnot?: unknown;
18
+ data?: unknown;
19
+ exportDependencies?: boolean;
20
+ dontLimitMoves?: boolean;
21
+ }
22
+
23
+ export type TemplateSource = DomElementSource | AnonymousSource;
24
+
25
+ export abstract class TemplateEngine {
26
+ allowTemplateRewriting = false;
27
+
28
+ abstract renderTemplateSource(
29
+ templateSource: TemplateSource,
30
+ bindingContext: BindingContext,
31
+ options: TemplateRenderOptions,
32
+ templateDocument?: Document,
33
+ ): Node[];
34
+
35
+ createJavaScriptEvaluatorBlock(_script: string): string {
36
+ throw new Error('Override createJavaScriptEvaluatorBlock');
37
+ }
38
+
39
+ makeTemplateSource(template: string | Node, templateDocument?: Document): TemplateSource {
40
+ if (typeof template === 'string') {
41
+ const doc = templateDocument || document;
42
+ const elem = doc.getElementById(template);
43
+ if (!elem) throw new Error('Cannot find template with ID ' + template);
44
+ return new DomElementSource(elem);
45
+ } else if (template.nodeType === 1 || template.nodeType === 8) {
46
+ return new AnonymousSource(template as Element | Comment);
47
+ } else {
48
+ throw new Error('Unknown template type: ' + template);
49
+ }
50
+ }
51
+
52
+ renderTemplate(
53
+ template: string | Node,
54
+ bindingContext: BindingContext,
55
+ options: TemplateRenderOptions,
56
+ templateDocument?: Document,
57
+ ): Node[] {
58
+ const source = this.makeTemplateSource(template, templateDocument);
59
+ return this.renderTemplateSource(source, bindingContext, options, templateDocument);
60
+ }
61
+
62
+ isTemplateRewritten(template: string | Node, templateDocument?: Document): boolean {
63
+ if (this.allowTemplateRewriting === false) return true;
64
+ return !!this.makeTemplateSource(template, templateDocument).data('isRewritten');
65
+ }
66
+
67
+ rewriteTemplate(
68
+ template: string | Node,
69
+ rewriterCallback: (text: string) => string,
70
+ templateDocument?: Document,
71
+ ): void {
72
+ const templateSource = this.makeTemplateSource(template, templateDocument);
73
+ const rewritten = rewriterCallback(templateSource.text());
74
+ templateSource.text(rewritten);
75
+ templateSource.data('isRewritten', true);
76
+ }
77
+ }
78
+
79
+ export class NativeTemplateEngine extends TemplateEngine {
80
+ override allowTemplateRewriting = false;
81
+
82
+ renderTemplateSource(
83
+ templateSource: TemplateSource,
84
+ _bindingContext: BindingContext,
85
+ _options: TemplateRenderOptions,
86
+ templateDocument?: Document,
87
+ ): Node[] {
88
+ const templateNodes = templateSource.nodes();
89
+ if (templateNodes) {
90
+ return Array.from(templateNodes.cloneNode(true).childNodes);
91
+ } else {
92
+ const templateText = templateSource.text();
93
+ return parseHtmlFragment(templateText, templateDocument);
94
+ }
95
+ }
96
+ }
97
+
98
+ export const nativeTemplateEngine = new NativeTemplateEngine();
99
+
100
+ let _templateEngine: TemplateEngine = nativeTemplateEngine;
101
+
102
+ export function setTemplateEngine(engine: TemplateEngine): void {
103
+ _templateEngine = engine;
104
+ }
105
+
106
+ export function getTemplateEngine(): TemplateEngine {
107
+ return _templateEngine;
108
+ }