@miurajs/miura-render 0.1.0 → 0.2.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.
- package/README.md +6 -6
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/src/binding-manager/binding-manager.d.ts +30 -0
- package/dist/src/binding-manager/binding-manager.d.ts.map +1 -0
- package/dist/src/binding-manager/binding-manager.js +245 -0
- package/dist/src/binding-manager/binding-manager.js.map +1 -0
- package/dist/src/binding-manager/binding-type.d.ts +24 -0
- package/dist/src/binding-manager/binding-type.d.ts.map +1 -0
- package/dist/src/binding-manager/binding-type.js +25 -0
- package/dist/src/binding-manager/binding-type.js.map +1 -0
- package/dist/src/binding-manager/bindings/async-binding.d.ts +23 -0
- package/dist/src/binding-manager/bindings/async-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/async-binding.js +67 -0
- package/dist/src/binding-manager/bindings/async-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/attribute-binding.d.ts +41 -0
- package/dist/src/binding-manager/bindings/attribute-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/attribute-binding.js +79 -0
- package/dist/src/binding-manager/bindings/attribute-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/bind-binding.d.ts +30 -0
- package/dist/src/binding-manager/bindings/bind-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/bind-binding.js +81 -0
- package/dist/src/binding-manager/bindings/bind-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/binding.d.ts +6 -0
- package/dist/src/binding-manager/bindings/binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/binding.js +2 -0
- package/dist/src/binding-manager/bindings/binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/boolean-binding.d.ts +18 -0
- package/dist/src/binding-manager/bindings/boolean-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/boolean-binding.js +65 -0
- package/dist/src/binding-manager/bindings/boolean-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/class-binding.d.ts +10 -0
- package/dist/src/binding-manager/bindings/class-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/class-binding.js +68 -0
- package/dist/src/binding-manager/bindings/class-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/directive-binding.d.ts +15 -0
- package/dist/src/binding-manager/bindings/directive-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/directive-binding.js +70 -0
- package/dist/src/binding-manager/bindings/directive-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/event-binding.d.ts +14 -0
- package/dist/src/binding-manager/bindings/event-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/event-binding.js +73 -0
- package/dist/src/binding-manager/bindings/event-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/node-binding.d.ts +36 -0
- package/dist/src/binding-manager/bindings/node-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/node-binding.js +235 -0
- package/dist/src/binding-manager/bindings/node-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/object-class-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/object-class-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/object-class-binding.js +42 -0
- package/dist/src/binding-manager/bindings/object-class-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/object-style-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/object-style-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/object-style-binding.js +38 -0
- package/dist/src/binding-manager/bindings/object-style-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/property-binding.d.ts +12 -0
- package/dist/src/binding-manager/bindings/property-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/property-binding.js +44 -0
- package/dist/src/binding-manager/bindings/property-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/reference-binding.d.ts +14 -0
- package/dist/src/binding-manager/bindings/reference-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/reference-binding.js +44 -0
- package/dist/src/binding-manager/bindings/reference-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/spread-binding.d.ts +16 -0
- package/dist/src/binding-manager/bindings/spread-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/spread-binding.js +40 -0
- package/dist/src/binding-manager/bindings/spread-binding.js.map +1 -0
- package/dist/src/binding-manager/bindings/style-binding.d.ts +10 -0
- package/dist/src/binding-manager/bindings/style-binding.d.ts.map +1 -0
- package/dist/src/binding-manager/bindings/style-binding.js +44 -0
- package/dist/src/binding-manager/bindings/style-binding.js.map +1 -0
- package/dist/src/compiler/code-factory.d.ts +45 -0
- package/dist/src/compiler/code-factory.d.ts.map +1 -0
- package/dist/src/compiler/code-factory.js +211 -0
- package/dist/src/compiler/code-factory.js.map +1 -0
- package/dist/src/compiler/compiler.d.ts +77 -0
- package/dist/src/compiler/compiler.d.ts.map +1 -0
- package/dist/src/compiler/compiler.js +77 -0
- package/dist/src/compiler/compiler.js.map +1 -0
- package/dist/src/compiler/constants.d.ts +5 -0
- package/dist/src/compiler/constants.d.ts.map +1 -0
- package/dist/src/compiler/constants.js +9 -0
- package/dist/src/compiler/constants.js.map +1 -0
- package/dist/src/css-result.d.ts +27 -0
- package/dist/src/css-result.d.ts.map +1 -0
- package/dist/src/css-result.js +56 -0
- package/dist/src/css-result.js.map +1 -0
- package/dist/src/css.d.ts +26 -0
- package/dist/src/css.d.ts.map +1 -0
- package/dist/src/css.js +62 -0
- package/dist/src/css.js.map +1 -0
- package/dist/src/directives/animate.directive.d.ts +42 -0
- package/dist/src/directives/animate.directive.d.ts.map +1 -0
- package/dist/src/directives/animate.directive.js +349 -0
- package/dist/src/directives/animate.directive.js.map +1 -0
- package/dist/src/directives/await.d.ts +68 -0
- package/dist/src/directives/await.d.ts.map +1 -0
- package/dist/src/directives/await.js +70 -0
- package/dist/src/directives/await.js.map +1 -0
- package/dist/src/directives/choose.d.ts +28 -0
- package/dist/src/directives/choose.d.ts.map +1 -0
- package/dist/src/directives/choose.js +30 -0
- package/dist/src/directives/choose.js.map +1 -0
- package/dist/src/directives/decorator-example.d.ts +8 -0
- package/dist/src/directives/decorator-example.d.ts.map +1 -0
- package/dist/src/directives/decorator-example.js +32 -0
- package/dist/src/directives/decorator-example.js.map +1 -0
- package/dist/src/directives/decorators.d.ts +3 -0
- package/dist/src/directives/decorators.d.ts.map +1 -0
- package/dist/src/directives/decorators.js +17 -0
- package/dist/src/directives/decorators.js.map +1 -0
- package/dist/src/directives/directive-manager.d.ts +26 -0
- package/dist/src/directives/directive-manager.d.ts.map +1 -0
- package/dist/src/directives/directive-manager.js +114 -0
- package/dist/src/directives/directive-manager.js.map +1 -0
- package/dist/src/directives/directive.d.ts +38 -0
- package/dist/src/directives/directive.d.ts.map +1 -0
- package/dist/src/directives/directive.js +18 -0
- package/dist/src/directives/directive.js.map +1 -0
- package/dist/src/directives/focus.directive.d.ts +16 -0
- package/dist/src/directives/focus.directive.d.ts.map +1 -0
- package/dist/src/directives/focus.directive.js +29 -0
- package/dist/src/directives/focus.directive.js.map +1 -0
- package/dist/src/directives/gesture.directive.d.ts +58 -0
- package/dist/src/directives/gesture.directive.d.ts.map +1 -0
- package/dist/src/directives/gesture.directive.js +331 -0
- package/dist/src/directives/gesture.directive.js.map +1 -0
- package/dist/src/directives/index.d.ts +34 -0
- package/dist/src/directives/index.d.ts.map +1 -0
- package/dist/src/directives/index.js +35 -0
- package/dist/src/directives/index.js.map +1 -0
- package/dist/src/directives/intersection.directive.d.ts +18 -0
- package/dist/src/directives/intersection.directive.d.ts.map +1 -0
- package/dist/src/directives/intersection.directive.js +50 -0
- package/dist/src/directives/intersection.directive.js.map +1 -0
- package/dist/src/directives/keyed-diff.d.ts +30 -0
- package/dist/src/directives/keyed-diff.d.ts.map +1 -0
- package/dist/src/directives/keyed-diff.js +185 -0
- package/dist/src/directives/keyed-diff.js.map +1 -0
- package/dist/src/directives/lazy-setup.d.ts +3 -0
- package/dist/src/directives/lazy-setup.d.ts.map +1 -0
- package/dist/src/directives/lazy-setup.js +55 -0
- package/dist/src/directives/lazy-setup.js.map +1 -0
- package/dist/src/directives/lazy.directive.d.ts +19 -0
- package/dist/src/directives/lazy.directive.d.ts.map +1 -0
- package/dist/src/directives/lazy.directive.js +73 -0
- package/dist/src/directives/lazy.directive.js.map +1 -0
- package/dist/src/directives/media.directive.d.ts +31 -0
- package/dist/src/directives/media.directive.d.ts.map +1 -0
- package/dist/src/directives/media.directive.js +105 -0
- package/dist/src/directives/media.directive.js.map +1 -0
- package/dist/src/directives/mutation.directive.d.ts +11 -0
- package/dist/src/directives/mutation.directive.d.ts.map +1 -0
- package/dist/src/directives/mutation.directive.js +56 -0
- package/dist/src/directives/mutation.directive.js.map +1 -0
- package/dist/src/directives/repeat.d.ts +50 -0
- package/dist/src/directives/repeat.d.ts.map +1 -0
- package/dist/src/directives/repeat.js +47 -0
- package/dist/src/directives/repeat.js.map +1 -0
- package/dist/src/directives/resize.directive.d.ts +14 -0
- package/dist/src/directives/resize.directive.d.ts.map +1 -0
- package/dist/src/directives/resize.directive.js +81 -0
- package/dist/src/directives/resize.directive.js.map +1 -0
- package/dist/src/directives/setup.d.ts +9 -0
- package/dist/src/directives/setup.d.ts.map +1 -0
- package/dist/src/directives/setup.js +9 -0
- package/dist/src/directives/setup.js.map +1 -0
- package/dist/src/directives/structural/async.directive.d.ts +39 -0
- package/dist/src/directives/structural/async.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/async.directive.js +115 -0
- package/dist/src/directives/structural/async.directive.js.map +1 -0
- package/dist/src/directives/structural/for.directive.d.ts +37 -0
- package/dist/src/directives/structural/for.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/for.directive.js +209 -0
- package/dist/src/directives/structural/for.directive.js.map +1 -0
- package/dist/src/directives/structural/if.directive.d.ts +54 -0
- package/dist/src/directives/structural/if.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/if.directive.js +210 -0
- package/dist/src/directives/structural/if.directive.js.map +1 -0
- package/dist/src/directives/structural/structural.directive.d.ts +11 -0
- package/dist/src/directives/structural/structural.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/structural.directive.js +29 -0
- package/dist/src/directives/structural/structural.directive.js.map +1 -0
- package/dist/src/directives/structural/switch.directive.d.ts +12 -0
- package/dist/src/directives/structural/switch.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/switch.directive.js +69 -0
- package/dist/src/directives/structural/switch.directive.js.map +1 -0
- package/dist/src/directives/structural/virtual-scroll.directive.d.ts +50 -0
- package/dist/src/directives/structural/virtual-scroll.directive.d.ts.map +1 -0
- package/dist/src/directives/structural/virtual-scroll.directive.js +165 -0
- package/dist/src/directives/structural/virtual-scroll.directive.js.map +1 -0
- package/dist/src/directives/utils.d.ts +61 -0
- package/dist/src/directives/utils.d.ts.map +1 -0
- package/dist/src/directives/utils.js +121 -0
- package/dist/src/directives/utils.js.map +1 -0
- package/dist/src/directives/validate.directive.d.ts +41 -0
- package/dist/src/directives/validate.directive.d.ts.map +1 -0
- package/dist/src/directives/validate.directive.js +161 -0
- package/dist/src/directives/validate.directive.js.map +1 -0
- package/dist/src/directives/virtual-scroll.d.ts +91 -0
- package/dist/src/directives/virtual-scroll.d.ts.map +1 -0
- package/dist/src/directives/virtual-scroll.js +78 -0
- package/dist/src/directives/virtual-scroll.js.map +1 -0
- package/dist/src/directives/when.d.ts +24 -0
- package/dist/src/directives/when.d.ts.map +1 -0
- package/dist/src/directives/when.js +25 -0
- package/dist/src/directives/when.js.map +1 -0
- package/dist/src/html.d.ts +23 -0
- package/dist/src/html.d.ts.map +1 -0
- package/dist/src/html.js +37 -0
- package/dist/src/html.js.map +1 -0
- package/dist/src/modifiers/capture-modifier.d.ts +6 -0
- package/dist/src/modifiers/capture-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/capture-modifier.js +14 -0
- package/dist/src/modifiers/capture-modifier.js.map +1 -0
- package/dist/src/modifiers/event-modifiers.d.ts +38 -0
- package/dist/src/modifiers/event-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/event-modifiers.js +90 -0
- package/dist/src/modifiers/event-modifiers.js.map +1 -0
- package/dist/src/modifiers/key-modifiers.d.ts +8 -0
- package/dist/src/modifiers/key-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/key-modifiers.js +29 -0
- package/dist/src/modifiers/key-modifiers.js.map +1 -0
- package/dist/src/modifiers/mouse-modifiers.d.ts +8 -0
- package/dist/src/modifiers/mouse-modifiers.d.ts.map +1 -0
- package/dist/src/modifiers/mouse-modifiers.js +15 -0
- package/dist/src/modifiers/mouse-modifiers.js.map +1 -0
- package/dist/src/modifiers/once-modifier.d.ts +6 -0
- package/dist/src/modifiers/once-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/once-modifier.js +11 -0
- package/dist/src/modifiers/once-modifier.js.map +1 -0
- package/dist/src/modifiers/passive-modifier.d.ts +6 -0
- package/dist/src/modifiers/passive-modifier.d.ts.map +1 -0
- package/dist/src/modifiers/passive-modifier.js +14 -0
- package/dist/src/modifiers/passive-modifier.js.map +1 -0
- package/dist/src/processor/parser.d.ts +74 -0
- package/dist/src/processor/parser.d.ts.map +1 -0
- package/dist/src/processor/parser.js +345 -0
- package/dist/src/processor/parser.js.map +1 -0
- package/dist/src/processor/processor.d.ts +68 -0
- package/dist/src/processor/processor.d.ts.map +1 -0
- package/dist/src/processor/processor.js +138 -0
- package/dist/src/processor/processor.js.map +1 -0
- package/dist/src/processor/template-result.d.ts +74 -0
- package/dist/src/processor/template-result.d.ts.map +1 -0
- package/dist/src/processor/template-result.js +53 -0
- package/dist/src/processor/template-result.js.map +1 -0
- package/dist/src/processor/types.d.ts +16 -0
- package/dist/src/processor/types.d.ts.map +1 -0
- package/dist/src/processor/types.js +13 -0
- package/dist/src/processor/types.js.map +1 -0
- package/dist/src/utils/debug.d.ts +7 -0
- package/dist/src/utils/debug.d.ts.map +1 -0
- package/dist/src/utils/debug.js +7 -0
- package/dist/src/utils/debug.js.map +1 -0
- package/dist/src/utils/performance.d.ts +50 -0
- package/dist/src/utils/performance.d.ts.map +1 -0
- package/dist/src/utils/performance.js +51 -0
- package/dist/src/utils/performance.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +8 -10
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { BindingType } from './template-result';
|
|
2
|
+
import { debugLog } from '../utils/debug';
|
|
3
|
+
import { DirectiveManager } from '../directives/directive-manager';
|
|
4
|
+
/**
|
|
5
|
+
* Parser for HTML templates with binding markers.
|
|
6
|
+
* Uses a state machine to correctly handle expressions in any context:
|
|
7
|
+
* text content, single-expression attributes, and multi-expression attributes.
|
|
8
|
+
*/
|
|
9
|
+
export class TemplateParser {
|
|
10
|
+
static BINDING_MARKER = 'binding:';
|
|
11
|
+
static ATTRIBUTE_PREFIX_REGEX = /^([.@?#&:~]|\.\.\.)/;
|
|
12
|
+
/**
|
|
13
|
+
* Performance tracking
|
|
14
|
+
*/
|
|
15
|
+
metrics = {
|
|
16
|
+
parseTime: 0,
|
|
17
|
+
parseCount: 0,
|
|
18
|
+
cacheHits: 0,
|
|
19
|
+
cacheMisses: 0
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Get performance metrics
|
|
23
|
+
*/
|
|
24
|
+
getPerformanceMetrics() {
|
|
25
|
+
return { ...this.metrics };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reset performance metrics
|
|
29
|
+
*/
|
|
30
|
+
resetMetrics() {
|
|
31
|
+
this.metrics = {
|
|
32
|
+
parseTime: 0,
|
|
33
|
+
parseCount: 0,
|
|
34
|
+
cacheHits: 0,
|
|
35
|
+
cacheMisses: 0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses template strings and extracts bindings.
|
|
40
|
+
* Handles text/node bindings, single-expression attribute bindings,
|
|
41
|
+
* and multi-expression attribute bindings (e.g. style="color: ${a}; bg: ${b}").
|
|
42
|
+
*/
|
|
43
|
+
parse(strings) {
|
|
44
|
+
const startTime = performance.now();
|
|
45
|
+
this.metrics.parseCount++;
|
|
46
|
+
debugLog('parser', 'Starting template parse', {
|
|
47
|
+
stringsLength: strings.length,
|
|
48
|
+
strings: Array.from(strings)
|
|
49
|
+
});
|
|
50
|
+
const bindings = [];
|
|
51
|
+
let html = '';
|
|
52
|
+
// State machine
|
|
53
|
+
let state = 0 /* ParserState.TEXT */;
|
|
54
|
+
let lastAttrName = '';
|
|
55
|
+
let attrNameStart = -1;
|
|
56
|
+
let attrValueContentStart = -1;
|
|
57
|
+
let openQuotePos = -1;
|
|
58
|
+
// Multi-part attribute tracking
|
|
59
|
+
let attrCtx = null;
|
|
60
|
+
for (let i = 0; i < strings.length; i++) {
|
|
61
|
+
const str = strings[i];
|
|
62
|
+
const isLast = i === strings.length - 1;
|
|
63
|
+
// htmlStart: position in `str` from which we start emitting to `html`.
|
|
64
|
+
// For attribute continuation strings we skip the content (captured in attrCtx.strings).
|
|
65
|
+
let htmlStart = 0;
|
|
66
|
+
// If we're continuing inside an attribute value from the previous string,
|
|
67
|
+
// we must first look for the closing quote.
|
|
68
|
+
if (attrCtx && (state === 4 /* ParserState.ATTR_VALUE_DQ */ || state === 5 /* ParserState.ATTR_VALUE_SQ */)) {
|
|
69
|
+
const quote = state === 4 /* ParserState.ATTR_VALUE_DQ */ ? '"' : "'";
|
|
70
|
+
const closePos = str.indexOf(quote);
|
|
71
|
+
if (closePos === -1) {
|
|
72
|
+
// Still inside the attribute — entire string is attribute content
|
|
73
|
+
if (!isLast) {
|
|
74
|
+
// Expression inside the same attribute
|
|
75
|
+
attrCtx.strings.push(str);
|
|
76
|
+
attrCtx.partCount++;
|
|
77
|
+
bindings.push({
|
|
78
|
+
type: BindingType.Attribute,
|
|
79
|
+
name: attrCtx.name,
|
|
80
|
+
index: i,
|
|
81
|
+
partIndex: attrCtx.partCount - 1,
|
|
82
|
+
groupStart: attrCtx.startBindingIndex,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Don't emit anything to HTML for this string
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Attribute value closes in this string
|
|
90
|
+
const finalStaticPart = str.substring(0, closePos);
|
|
91
|
+
attrCtx.strings.push(finalStaticPart);
|
|
92
|
+
// Assign the completed strings array to the first binding in the group
|
|
93
|
+
const firstBinding = bindings.find(b => b.index === attrCtx.startBindingIndex);
|
|
94
|
+
if (firstBinding) {
|
|
95
|
+
firstBinding.strings = attrCtx.strings;
|
|
96
|
+
}
|
|
97
|
+
// Finalize the attribute type for the group
|
|
98
|
+
this.finalizeAttrGroup(bindings, attrCtx);
|
|
99
|
+
attrCtx = null;
|
|
100
|
+
state = 1 /* ParserState.TAG */;
|
|
101
|
+
htmlStart = closePos + 1; // resume HTML after closing quote
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Scan characters to track state transitions
|
|
105
|
+
let j = htmlStart;
|
|
106
|
+
while (j < str.length) {
|
|
107
|
+
const ch = str[j];
|
|
108
|
+
switch (state) {
|
|
109
|
+
case 0 /* ParserState.TEXT */:
|
|
110
|
+
if (ch === '<') {
|
|
111
|
+
if (str[j + 1] === '!' && str[j + 2] === '-' && str[j + 3] === '-') {
|
|
112
|
+
state = 6 /* ParserState.COMMENT */;
|
|
113
|
+
j += 3;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
state = 1 /* ParserState.TAG */;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case 1 /* ParserState.TAG */:
|
|
121
|
+
if (ch === '>') {
|
|
122
|
+
state = 0 /* ParserState.TEXT */;
|
|
123
|
+
}
|
|
124
|
+
else if (ch === '/' && str[j + 1] === '>') {
|
|
125
|
+
state = 0 /* ParserState.TEXT */;
|
|
126
|
+
j++;
|
|
127
|
+
}
|
|
128
|
+
else if (!/[\s/]/.test(ch) && ch !== '=' && ch !== '"' && ch !== "'") {
|
|
129
|
+
attrNameStart = j;
|
|
130
|
+
state = 2 /* ParserState.ATTR_NAME */;
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case 2 /* ParserState.ATTR_NAME */:
|
|
134
|
+
if (ch === '=') {
|
|
135
|
+
lastAttrName = str.substring(attrNameStart, j);
|
|
136
|
+
state = 3 /* ParserState.ATTR_EQ */;
|
|
137
|
+
}
|
|
138
|
+
else if (ch === '>' || /\s/.test(ch)) {
|
|
139
|
+
lastAttrName = str.substring(attrNameStart, j);
|
|
140
|
+
state = ch === '>' ? 0 /* ParserState.TEXT */ : 1 /* ParserState.TAG */;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case 3 /* ParserState.ATTR_EQ */:
|
|
144
|
+
if (ch === '"') {
|
|
145
|
+
state = 4 /* ParserState.ATTR_VALUE_DQ */;
|
|
146
|
+
openQuotePos = j;
|
|
147
|
+
attrValueContentStart = j + 1;
|
|
148
|
+
}
|
|
149
|
+
else if (ch === "'") {
|
|
150
|
+
state = 5 /* ParserState.ATTR_VALUE_SQ */;
|
|
151
|
+
openQuotePos = j;
|
|
152
|
+
attrValueContentStart = j + 1;
|
|
153
|
+
}
|
|
154
|
+
else if (!/\s/.test(ch)) {
|
|
155
|
+
// Unquoted value — scan to whitespace or >
|
|
156
|
+
const end = str.substring(j).search(/[\s>]/);
|
|
157
|
+
j += (end === -1 ? str.length - j : end) - 1;
|
|
158
|
+
state = 1 /* ParserState.TAG */;
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
case 4 /* ParserState.ATTR_VALUE_DQ */:
|
|
162
|
+
if (ch === '"') {
|
|
163
|
+
state = 1 /* ParserState.TAG */;
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case 5 /* ParserState.ATTR_VALUE_SQ */:
|
|
167
|
+
if (ch === "'") {
|
|
168
|
+
state = 1 /* ParserState.TAG */;
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case 6 /* ParserState.COMMENT */:
|
|
172
|
+
if (ch === '-' && str[j + 1] === '-' && str[j + 2] === '>') {
|
|
173
|
+
state = 0 /* ParserState.TEXT */;
|
|
174
|
+
j += 2;
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
j++;
|
|
179
|
+
}
|
|
180
|
+
// ── End of string part: if not last, there's an expression ${} here ──
|
|
181
|
+
if (!isLast) {
|
|
182
|
+
if (state === 4 /* ParserState.ATTR_VALUE_DQ */ || state === 5 /* ParserState.ATTR_VALUE_SQ */) {
|
|
183
|
+
// Expression is inside an attribute value
|
|
184
|
+
const staticPart = str.substring(attrValueContentStart, str.length);
|
|
185
|
+
if (!attrCtx) {
|
|
186
|
+
// First expression in this attribute — start a new group
|
|
187
|
+
const prefix = lastAttrName.match(TemplateParser.ATTRIBUTE_PREFIX_REGEX)?.[0] || '';
|
|
188
|
+
const cleanName = prefix ? lastAttrName.slice(1) : lastAttrName;
|
|
189
|
+
let modifiers = [];
|
|
190
|
+
if (prefix === '@') {
|
|
191
|
+
const parts = cleanName.split('|');
|
|
192
|
+
const modParts = parts[1] ? parts[1].split(',').map(mod => {
|
|
193
|
+
const [n, v] = mod.split(':');
|
|
194
|
+
return v ? `${n}:${v}` : n;
|
|
195
|
+
}) : [];
|
|
196
|
+
modifiers = modParts;
|
|
197
|
+
}
|
|
198
|
+
attrCtx = {
|
|
199
|
+
name: lastAttrName,
|
|
200
|
+
prefix,
|
|
201
|
+
cleanName: prefix === '@' ? cleanName.split('|')[0] : cleanName,
|
|
202
|
+
openQuotePos,
|
|
203
|
+
startBindingIndex: i,
|
|
204
|
+
strings: [staticPart],
|
|
205
|
+
partCount: 1,
|
|
206
|
+
modifiers,
|
|
207
|
+
};
|
|
208
|
+
// Emit HTML: everything from htmlStart up to and including the opening quote,
|
|
209
|
+
// then a binding marker as placeholder, then closing quote
|
|
210
|
+
html += str.substring(htmlStart, openQuotePos + 1);
|
|
211
|
+
html += `${TemplateParser.BINDING_MARKER}${i}"`;
|
|
212
|
+
bindings.push({
|
|
213
|
+
type: BindingType.Attribute, // provisional — finalized when attr closes
|
|
214
|
+
name: lastAttrName,
|
|
215
|
+
index: i,
|
|
216
|
+
partIndex: 0,
|
|
217
|
+
groupStart: i,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// Subsequent expression in same attribute
|
|
222
|
+
attrCtx.strings.push(staticPart);
|
|
223
|
+
attrCtx.partCount++;
|
|
224
|
+
bindings.push({
|
|
225
|
+
type: BindingType.Attribute,
|
|
226
|
+
name: attrCtx.name,
|
|
227
|
+
index: i,
|
|
228
|
+
partIndex: attrCtx.partCount - 1,
|
|
229
|
+
groupStart: attrCtx.startBindingIndex,
|
|
230
|
+
});
|
|
231
|
+
// Don't emit HTML for intermediate parts
|
|
232
|
+
}
|
|
233
|
+
// Next string's attribute content starts at position 0
|
|
234
|
+
attrValueContentStart = 0;
|
|
235
|
+
}
|
|
236
|
+
else if (state === 3 /* ParserState.ATTR_EQ */) {
|
|
237
|
+
// Expression IS the entire attribute value (unquoted): attr=${val}
|
|
238
|
+
const prefix = lastAttrName.match(TemplateParser.ATTRIBUTE_PREFIX_REGEX)?.[0] || '';
|
|
239
|
+
const cleanName = prefix ? lastAttrName.slice(1) : lastAttrName;
|
|
240
|
+
let modifiers = [];
|
|
241
|
+
let bindingName = cleanName;
|
|
242
|
+
if (prefix === '@') {
|
|
243
|
+
const parts = cleanName.split('|');
|
|
244
|
+
bindingName = parts[0];
|
|
245
|
+
modifiers = parts[1] ? parts[1].split(',').map(mod => {
|
|
246
|
+
const [n, v] = mod.split(':');
|
|
247
|
+
return v ? `${n}:${v}` : n;
|
|
248
|
+
}) : [];
|
|
249
|
+
}
|
|
250
|
+
const type = this.getSpecializedType(prefix, bindingName);
|
|
251
|
+
bindings.push({
|
|
252
|
+
type,
|
|
253
|
+
name: prefix === '@' ? bindingName : lastAttrName,
|
|
254
|
+
index: i,
|
|
255
|
+
modifiers: modifiers.length > 0 ? modifiers : undefined,
|
|
256
|
+
strings: ['', ''],
|
|
257
|
+
partIndex: 0,
|
|
258
|
+
groupStart: i,
|
|
259
|
+
});
|
|
260
|
+
// Emit HTML: up to the = sign, replace with marker
|
|
261
|
+
// Find where the attribute name starts by going backwards
|
|
262
|
+
const eqPos = str.lastIndexOf('=');
|
|
263
|
+
html += str.substring(htmlStart, eqPos + 1);
|
|
264
|
+
html += `"${TemplateParser.BINDING_MARKER}${i}"`;
|
|
265
|
+
state = 1 /* ParserState.TAG */;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// Expression in text content — NodeBinding
|
|
269
|
+
html += str.substring(htmlStart);
|
|
270
|
+
html += `<!--binding:${i}--><!--/binding:${i}-->`;
|
|
271
|
+
bindings.push({
|
|
272
|
+
type: BindingType.Node,
|
|
273
|
+
index: i,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
// Last string part — just emit remaining HTML
|
|
279
|
+
html += str.substring(htmlStart);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
this.metrics.parseTime = performance.now() - startTime;
|
|
283
|
+
debugLog('parser', 'Final parsed template', { html, bindings });
|
|
284
|
+
return { html, bindings };
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* After an attribute value closes, determine the final binding type(s) for the group.
|
|
288
|
+
* Single-expression attributes with special prefixes/names use specialized types.
|
|
289
|
+
* Multi-expression or plain attributes use BindingType.Attribute.
|
|
290
|
+
*/
|
|
291
|
+
finalizeAttrGroup(bindings, ctx) {
|
|
292
|
+
const isSingleExpr = ctx.partCount === 1 && ctx.strings[0] === '' && ctx.strings[1] === '';
|
|
293
|
+
const firstBinding = bindings.find(b => b.index === ctx.startBindingIndex);
|
|
294
|
+
if (!firstBinding)
|
|
295
|
+
return;
|
|
296
|
+
if (isSingleExpr) {
|
|
297
|
+
// Entire attribute value is a single expression — use specialized binding type
|
|
298
|
+
const type = this.getSpecializedType(ctx.prefix, ctx.cleanName);
|
|
299
|
+
firstBinding.type = type;
|
|
300
|
+
firstBinding.name = ctx.prefix === '@' ? ctx.cleanName : ctx.name;
|
|
301
|
+
firstBinding.modifiers = ctx.modifiers.length > 0 ? ctx.modifiers : undefined;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
// Multi-expression or has static content — stays as Attribute
|
|
305
|
+
firstBinding.name = ctx.name;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Determine the specialized binding type for a single-expression attribute.
|
|
310
|
+
*/
|
|
311
|
+
getSpecializedType(prefix, name) {
|
|
312
|
+
switch (prefix) {
|
|
313
|
+
case '@':
|
|
314
|
+
return BindingType.Event;
|
|
315
|
+
case '?':
|
|
316
|
+
return BindingType.Boolean;
|
|
317
|
+
case '.':
|
|
318
|
+
return BindingType.Property;
|
|
319
|
+
case '&':
|
|
320
|
+
return BindingType.Bind;
|
|
321
|
+
case ':':
|
|
322
|
+
if (name === 'class')
|
|
323
|
+
return BindingType.ObjectClass;
|
|
324
|
+
if (name === 'style')
|
|
325
|
+
return BindingType.ObjectStyle;
|
|
326
|
+
return BindingType.Property;
|
|
327
|
+
case '~':
|
|
328
|
+
return BindingType.Async;
|
|
329
|
+
case '...':
|
|
330
|
+
return BindingType.Spread;
|
|
331
|
+
case '#': {
|
|
332
|
+
const directiveName = name.replace(/^#/, '');
|
|
333
|
+
const hasDirective = DirectiveManager.has(directiveName);
|
|
334
|
+
return hasDirective ? BindingType.Directive : BindingType.Reference;
|
|
335
|
+
}
|
|
336
|
+
default:
|
|
337
|
+
if (name === 'class')
|
|
338
|
+
return BindingType.Class;
|
|
339
|
+
if (name === 'style')
|
|
340
|
+
return BindingType.Style;
|
|
341
|
+
return BindingType.Attribute;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@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I,KAAK,OAAO;oBAAE,OAAO,WAAW,CAAC,KAAK,CAAC;gBAC/C,IAAI,IAAI,KAAK,OAAO;oBAAE,OAAO,WAAW,CAAC,KAAK,CAAC;gBAC/C,OAAO,WAAW,CAAC,SAAS,CAAC;QACrC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TemplateResult } from './template-result';
|
|
2
|
+
import { Binding } from '../binding-manager/bindings/binding';
|
|
3
|
+
/**
|
|
4
|
+
* Performance metrics for template processing
|
|
5
|
+
*/
|
|
6
|
+
interface ProcessingMetrics {
|
|
7
|
+
parseTime: number;
|
|
8
|
+
createTime: number;
|
|
9
|
+
updateTime: number;
|
|
10
|
+
cacheHits: number;
|
|
11
|
+
cacheMisses: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The TemplateProcessor is responsible for:
|
|
15
|
+
* 1. Processing template results into DOM structures
|
|
16
|
+
* 2. Managing template instances and their lifecycles
|
|
17
|
+
* 3. Creating and managing parts that handle dynamic content
|
|
18
|
+
* 4. Caching parsed templates for better performance
|
|
19
|
+
*/
|
|
20
|
+
export declare class TemplateProcessor {
|
|
21
|
+
private templateCache;
|
|
22
|
+
private parser;
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Performance tracking
|
|
26
|
+
*/
|
|
27
|
+
private metrics;
|
|
28
|
+
/**
|
|
29
|
+
* Get performance metrics
|
|
30
|
+
*/
|
|
31
|
+
getPerformanceMetrics(): ProcessingMetrics;
|
|
32
|
+
/**
|
|
33
|
+
* Reset performance metrics
|
|
34
|
+
*/
|
|
35
|
+
resetMetrics(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Clear template cache to free memory
|
|
38
|
+
*/
|
|
39
|
+
clearCache(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get cache statistics
|
|
42
|
+
*/
|
|
43
|
+
getCacheStats(): {
|
|
44
|
+
size: number;
|
|
45
|
+
hits: number;
|
|
46
|
+
misses: number;
|
|
47
|
+
};
|
|
48
|
+
createInstance(result: TemplateResult, context?: unknown): Promise<TemplateInstance>;
|
|
49
|
+
private getOrCreateParsedTemplate;
|
|
50
|
+
private createDOMFragment;
|
|
51
|
+
}
|
|
52
|
+
declare class TemplateInstance {
|
|
53
|
+
private result;
|
|
54
|
+
private parts;
|
|
55
|
+
private fragment;
|
|
56
|
+
private updateMetrics;
|
|
57
|
+
constructor(result: TemplateResult, parts: Binding[], fragment: DocumentFragment);
|
|
58
|
+
getFragment(): DocumentFragment;
|
|
59
|
+
connect(context?: unknown): void;
|
|
60
|
+
update(values: unknown[], context?: unknown): Promise<void>;
|
|
61
|
+
disconnect(): void;
|
|
62
|
+
getUpdateMetrics(): {
|
|
63
|
+
updateTime: number;
|
|
64
|
+
updateCount: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../../../src/processor/processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAE9D;;GAEG;AACH,UAAU,iBAAiB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,aAAa,CAAuD;IAC5E,OAAO,CAAC,MAAM,CAAwB;;IAMtC;;OAEG;IACH,OAAO,CAAC,OAAO,CAMb;IAEF;;OAEG;IACH,qBAAqB,IAAI,iBAAiB;IAI1C;;OAEG;IACH,YAAY,IAAI,IAAI;IAUpB;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IASzD,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAuB1F,OAAO,CAAC,yBAAyB;IAejC,OAAO,CAAC,iBAAiB;CAK5B;AAED,cAAM,gBAAgB;IAId,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IALpB,OAAO,CAAC,aAAa,CAAqC;gBAG9C,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,OAAO,EAAE,EAChB,QAAQ,EAAE,gBAAgB;IAGtC,WAAW,IAAI,gBAAgB;IAI/B,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI;IAI1B,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,UAAU,IAAI,IAAI;IAclB,gBAAgB;;;;CAGnB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { TemplateParser } from './parser';
|
|
2
|
+
import { registerDefaultProcessor } from './types';
|
|
3
|
+
import { debugLog } from '../utils/debug';
|
|
4
|
+
import { BindingManager } from '../binding-manager/binding-manager';
|
|
5
|
+
/**
|
|
6
|
+
* The TemplateProcessor is responsible for:
|
|
7
|
+
* 1. Processing template results into DOM structures
|
|
8
|
+
* 2. Managing template instances and their lifecycles
|
|
9
|
+
* 3. Creating and managing parts that handle dynamic content
|
|
10
|
+
* 4. Caching parsed templates for better performance
|
|
11
|
+
*/
|
|
12
|
+
export class TemplateProcessor {
|
|
13
|
+
templateCache = new WeakMap();
|
|
14
|
+
parser = new TemplateParser();
|
|
15
|
+
constructor() {
|
|
16
|
+
registerDefaultProcessor(this);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Performance tracking
|
|
20
|
+
*/
|
|
21
|
+
metrics = {
|
|
22
|
+
parseTime: 0,
|
|
23
|
+
createTime: 0,
|
|
24
|
+
updateTime: 0,
|
|
25
|
+
cacheHits: 0,
|
|
26
|
+
cacheMisses: 0
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Get performance metrics
|
|
30
|
+
*/
|
|
31
|
+
getPerformanceMetrics() {
|
|
32
|
+
return { ...this.metrics };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reset performance metrics
|
|
36
|
+
*/
|
|
37
|
+
resetMetrics() {
|
|
38
|
+
this.metrics = {
|
|
39
|
+
parseTime: 0,
|
|
40
|
+
createTime: 0,
|
|
41
|
+
updateTime: 0,
|
|
42
|
+
cacheHits: 0,
|
|
43
|
+
cacheMisses: 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Clear template cache to free memory
|
|
48
|
+
*/
|
|
49
|
+
clearCache() {
|
|
50
|
+
this.templateCache = new WeakMap();
|
|
51
|
+
debugLog('processor', 'Template cache cleared');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get cache statistics
|
|
55
|
+
*/
|
|
56
|
+
getCacheStats() {
|
|
57
|
+
// Note: WeakMap size is not directly accessible, but we can track hits/misses
|
|
58
|
+
return {
|
|
59
|
+
size: 0, // WeakMap size is not available
|
|
60
|
+
hits: this.metrics.cacheHits,
|
|
61
|
+
misses: this.metrics.cacheMisses
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async createInstance(result, context) {
|
|
65
|
+
const startTime = performance.now();
|
|
66
|
+
debugLog('processor', 'Creating template instance', { result });
|
|
67
|
+
// Get or create parsed template
|
|
68
|
+
const parsed = this.getOrCreateParsedTemplate(result);
|
|
69
|
+
// For nested templates, we need a fresh sequence of indices
|
|
70
|
+
const fragment = this.createDOMFragment(parsed.html);
|
|
71
|
+
// Create and initialize parts using BindingManager
|
|
72
|
+
const parts = await BindingManager.createAndInitializeParts(fragment, parsed.bindings, // Don't offset the bindings for nested templates
|
|
73
|
+
result.values, context, this // Pass processor so NodeBinding can create nested instances
|
|
74
|
+
);
|
|
75
|
+
this.metrics.createTime = performance.now() - startTime;
|
|
76
|
+
return new TemplateInstance(result, parts, fragment);
|
|
77
|
+
}
|
|
78
|
+
getOrCreateParsedTemplate(result) {
|
|
79
|
+
const startTime = performance.now();
|
|
80
|
+
let template = this.templateCache.get(result.strings);
|
|
81
|
+
if (!template) {
|
|
82
|
+
this.metrics.cacheMisses++;
|
|
83
|
+
template = this.parser.parse(result.strings);
|
|
84
|
+
this.templateCache.set(result.strings, template);
|
|
85
|
+
debugLog('processor', 'Created new template', { template });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.metrics.cacheHits++;
|
|
89
|
+
}
|
|
90
|
+
this.metrics.parseTime = performance.now() - startTime;
|
|
91
|
+
return template;
|
|
92
|
+
}
|
|
93
|
+
createDOMFragment(html) {
|
|
94
|
+
const template = document.createElement('template');
|
|
95
|
+
template.innerHTML = html;
|
|
96
|
+
return document.importNode(template.content, true);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class TemplateInstance {
|
|
100
|
+
result;
|
|
101
|
+
parts;
|
|
102
|
+
fragment;
|
|
103
|
+
updateMetrics = { updateTime: 0, updateCount: 0 };
|
|
104
|
+
constructor(result, parts, fragment) {
|
|
105
|
+
this.result = result;
|
|
106
|
+
this.parts = parts;
|
|
107
|
+
this.fragment = fragment;
|
|
108
|
+
}
|
|
109
|
+
getFragment() {
|
|
110
|
+
return this.fragment;
|
|
111
|
+
}
|
|
112
|
+
connect(context) {
|
|
113
|
+
// No-op for now since Bindings handle their own connections
|
|
114
|
+
}
|
|
115
|
+
async update(values, context) {
|
|
116
|
+
const startTime = performance.now();
|
|
117
|
+
await BindingManager.initializeBindings(this.parts, values, context);
|
|
118
|
+
this.updateMetrics.updateTime = performance.now() - startTime;
|
|
119
|
+
this.updateMetrics.updateCount++;
|
|
120
|
+
}
|
|
121
|
+
disconnect() {
|
|
122
|
+
this.parts.forEach(part => {
|
|
123
|
+
// Clean up any signal subscription attached by BindingManager
|
|
124
|
+
const unsub = part.__signalUnsub;
|
|
125
|
+
if (typeof unsub === 'function')
|
|
126
|
+
unsub();
|
|
127
|
+
if ('disconnect' in part) {
|
|
128
|
+
part.disconnect();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
// Clear references to help GC
|
|
132
|
+
this.parts = [];
|
|
133
|
+
}
|
|
134
|
+
getUpdateMetrics() {
|
|
135
|
+
return { ...this.updateMetrics };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../../../src/processor/processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAkB,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAcpE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAClB,aAAa,GAAG,IAAI,OAAO,EAAwC,CAAC;IACpE,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IAEtC;QACI,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACK,OAAO,GAAsB;QACjC,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACjB,CAAC;IAEF;;OAEG;IACH,qBAAqB;QACjB,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED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kB;IACnC,CAAC;IAEJ,WAAW;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,OAAiB;QACrB,4DAA4D;IAChE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAiB,EAAE,OAAiB;QAC7C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,MAAM,cAAc,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACrE,IAAI,CAAC,aAAa,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QAC9D,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC;IAED,UAAU;QACN,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACtB,8DAA8D;YAC9D,MAAM,KAAK,GAAI,IAAY,CAAC,aAAa,CAAC;YAC1C,IAAI,OAAO,KAAK,KAAK,UAAU;gBAAE,KAAK,EAAE,CAAC;YAEzC,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;gBACtB,IAAY,CAAC,UAAU,EAAE,CAAC;YAC/B,CAAC;QACL,CAAC,CAAC,CAAC;QACH,8BAA8B;QAC9B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,gBAAgB;QACZ,OAAO,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC;CACJ"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type for template expressions that can be either values or functions
|
|
3
|
+
*/
|
|
4
|
+
export type TemplateExpression = Function | ((context: unknown) => unknown);
|
|
5
|
+
/**
|
|
6
|
+
* Represents the result of processing a template literal.
|
|
7
|
+
* Contains the strings and values that make up the template.
|
|
8
|
+
* @interface TemplateResult
|
|
9
|
+
*/
|
|
10
|
+
export declare class TemplateResult {
|
|
11
|
+
/** The array of static strings in the template */
|
|
12
|
+
readonly strings: TemplateStringsArray;
|
|
13
|
+
/** The array of dynamic values in the template */
|
|
14
|
+
readonly values: unknown[];
|
|
15
|
+
/**
|
|
16
|
+
* @param strings The array of static strings in the template
|
|
17
|
+
* @param values The array of dynamic values in the template
|
|
18
|
+
*/
|
|
19
|
+
constructor(
|
|
20
|
+
/** The array of static strings in the template */
|
|
21
|
+
strings: TemplateStringsArray,
|
|
22
|
+
/** The array of dynamic values in the template */
|
|
23
|
+
values: unknown[]);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Represents the type of binding in a template.
|
|
27
|
+
* @enum {number}
|
|
28
|
+
*/
|
|
29
|
+
export declare enum BindingType {
|
|
30
|
+
/** A binding that represents a DOM node (text content) */
|
|
31
|
+
Node = "node",
|
|
32
|
+
/** A binding that represents a property on an element */
|
|
33
|
+
Property = "property",
|
|
34
|
+
/** A binding that represents an event handler */
|
|
35
|
+
Event = "event",
|
|
36
|
+
Reference = "reference",
|
|
37
|
+
Boolean = "boolean",
|
|
38
|
+
/** A binding that represents a class attribute */
|
|
39
|
+
Class = "class",
|
|
40
|
+
Style = "Style",
|
|
41
|
+
Directive = "directive",
|
|
42
|
+
/** A binding that represents a generic attribute value (single or multi-expression) */
|
|
43
|
+
Attribute = "attribute",
|
|
44
|
+
/** Two-way binding: syncs a property with a DOM element value via events */
|
|
45
|
+
Bind = "bind",
|
|
46
|
+
/** Object class map: :class=${{ active: bool }} */
|
|
47
|
+
ObjectClass = "object-class",
|
|
48
|
+
/** Object style map: :style=${{ color: 'red' }} */
|
|
49
|
+
ObjectStyle = "object-style",
|
|
50
|
+
/** Spread binding: ...=${propsObj} — sets each key as a property */
|
|
51
|
+
Spread = "spread",
|
|
52
|
+
/** Async auto-unwrap: ~prop=${promise} — resolves and sets when promise settles */
|
|
53
|
+
Async = "async"
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents a binding in a template.
|
|
57
|
+
* A binding connects a value in the template to a specific location in the DOM.
|
|
58
|
+
* @interface TemplateBinding
|
|
59
|
+
*/
|
|
60
|
+
export interface TemplateBinding {
|
|
61
|
+
/** The type of binding (Node, Property, Event, etc.) */
|
|
62
|
+
type: BindingType;
|
|
63
|
+
/**
|
|
64
|
+
* The name of the binding target.
|
|
65
|
+
* - For Node bindings: empty string
|
|
66
|
+
* - For Property bindings: property name (e.g., "value", "checked")
|
|
67
|
+
* - For Event bindings: event name (e.g., "click", "input")
|
|
68
|
+
* - For Class bindings: "class"
|
|
69
|
+
*/
|
|
70
|
+
name?: string;
|
|
71
|
+
/** The index of the value in the template's values array */
|
|
72
|
+
index: number;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=template-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-result.d.ts","sourceRoot":"","sources":["../../../src/processor/template-result.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,cAAc;IAMnB,kDAAkD;aAClC,OAAO,EAAE,oBAAoB;IAC7C,kDAAkD;aAClC,MAAM,EAAE,OAAO,EAAE;IARrC;;;OAGG;;IAEC,kDAAkD;IAClC,OAAO,EAAE,oBAAoB;IAC7C,kDAAkD;IAClC,MAAM,EAAE,OAAO,EAAE;CAExC;AAED;;;GAGG;AACH,oBAAY,WAAW;IACnB,0DAA0D;IAC1D,IAAI,SAAS;IACb,yDAAyD;IACzD,QAAQ,aAAa;IACrB,iDAAiD;IACjD,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,kDAAkD;IAClD,KAAK,UAAU;IACf,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,uFAAuF;IACvF,SAAS,cAAc;IACvB,4EAA4E;IAC5E,IAAI,SAAS;IACb,mDAAmD;IACnD,WAAW,iBAAiB;IAC5B,mDAAmD;IACnD,WAAW,iBAAiB;IAC5B,oEAAoE;IACpE,MAAM,WAAW;IACjB,mFAAmF;IACnF,KAAK,UAAU;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B,wDAAwD;IACxD,IAAI,EAAE,WAAW,CAAC;IAClB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACjB"}
|