@reidelsaltres/pureper 0.2.3 → 0.2.10
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/out/foundation/api/Observer.d.ts +3 -6
- package/out/foundation/api/Observer.d.ts.map +1 -1
- package/out/foundation/api/Observer.js +1 -4
- package/out/foundation/api/Observer.js.map +1 -1
- package/out/foundation/engine/TemplateEngine.d.ts +2 -2
- package/out/foundation/engine/TemplateEngine.d.ts.map +1 -1
- package/out/foundation/engine/TemplateEngine.js +5 -0
- package/out/foundation/engine/TemplateEngine.js.map +1 -1
- package/out/foundation/worker/serviceworker.js +1 -0
- package/package.json +1 -1
- package/src/foundation/api/Observer.ts +4 -7
- package/src/foundation/engine/TemplateEngine.ts +8 -5
- package/out/components/ContainItSelfTest.d.ts +0 -4
- package/out/components/ContainItSelfTest.d.ts.map +0 -1
- package/out/components/ContainItSelfTest.js +0 -18
- package/out/components/ContainItSelfTest.js.map +0 -1
- package/out/components/DynamicBlock.d.ts +0 -10
- package/out/components/DynamicBlock.d.ts.map +0 -1
- package/out/components/DynamicBlock.js +0 -32
- package/out/components/DynamicBlock.js.map +0 -1
- package/out/foundation/HMLELoader.d.ts +0 -9
- package/out/foundation/HMLELoader.d.ts.map +0 -1
- package/out/foundation/HMLELoader.js +0 -14
- package/out/foundation/HMLELoader.js.map +0 -1
- package/out/foundation/HMLEParser.d.ts +0 -87
- package/out/foundation/HMLEParser.d.ts.map +0 -1
- package/out/foundation/HMLEParser.js +0 -523
- package/out/foundation/HMLEParser.js.map +0 -1
- package/out/foundation/HMLEParserReborn.d.ts +0 -49
- package/out/foundation/HMLEParserReborn.d.ts.map +0 -1
- package/out/foundation/HMLEParserReborn.js +0 -932
- package/out/foundation/HMLEParserReborn.js.map +0 -1
- package/out/foundation/PHTMLParser.d.ts +0 -12
- package/out/foundation/PHTMLParser.d.ts.map +0 -1
- package/out/foundation/PHTMLParser.js +0 -222
- package/out/foundation/PHTMLParser.js.map +0 -1
- package/out/foundation/dynamic/Rule.d.ts +0 -16
- package/out/foundation/dynamic/Rule.d.ts.map +0 -1
- package/out/foundation/dynamic/Rule.js +0 -20
- package/out/foundation/dynamic/Rule.js.map +0 -1
- package/out/foundation/engine/BalancedParser.d.ts +0 -58
- package/out/foundation/engine/BalancedParser.d.ts.map +0 -1
- package/out/foundation/engine/BalancedParser.js +0 -301
- package/out/foundation/engine/BalancedParser.js.map +0 -1
- package/out/foundation/engine/EscapeHandler.d.ts +0 -27
- package/out/foundation/engine/EscapeHandler.d.ts.map +0 -1
- package/out/foundation/engine/EscapeHandler.js +0 -47
- package/out/foundation/engine/EscapeHandler.js.map +0 -1
- package/out/foundation/engine/Rule.d.ts +0 -85
- package/out/foundation/engine/Rule.d.ts.map +0 -1
- package/out/foundation/engine/Rule.js +0 -69
- package/out/foundation/engine/Rule.js.map +0 -1
- package/out/foundation/engine/TemplateEngine.old.d.ts +0 -96
- package/out/foundation/engine/TemplateEngine.old.d.ts.map +0 -1
- package/out/foundation/engine/TemplateEngine.old.js +0 -235
- package/out/foundation/engine/TemplateEngine.old.js.map +0 -1
- package/out/foundation/engine/TemplateInstance.d.ts +0 -241
- package/out/foundation/engine/TemplateInstance.d.ts.map +0 -1
- package/out/foundation/engine/TemplateInstance.js +0 -637
- package/out/foundation/engine/TemplateInstance.js.map +0 -1
- package/out/foundation/engine/TemplateInstance.old.d.ts +0 -219
- package/out/foundation/engine/TemplateInstance.old.d.ts.map +0 -1
- package/out/foundation/engine/TemplateInstance.old.js +0 -487
- package/out/foundation/engine/TemplateInstance.old.js.map +0 -1
- package/out/foundation/engine/exceptions/TemplateExceptions.d.ts +0 -21
- package/out/foundation/engine/exceptions/TemplateExceptions.d.ts.map +0 -1
- package/out/foundation/engine/exceptions/TemplateExceptions.js +0 -26
- package/out/foundation/engine/exceptions/TemplateExceptions.js.map +0 -1
- package/out/foundation/engine/index.d.ts +0 -18
- package/out/foundation/engine/index.d.ts.map +0 -1
- package/out/foundation/engine/index.js +0 -19
- package/out/foundation/engine/index.js.map +0 -1
- package/out/foundation/engine/rules/attribute/EventRule.d.ts +0 -22
- package/out/foundation/engine/rules/attribute/EventRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/attribute/EventRule.js +0 -129
- package/out/foundation/engine/rules/attribute/EventRule.js.map +0 -1
- package/out/foundation/engine/rules/attribute/InjectionRule.d.ts +0 -20
- package/out/foundation/engine/rules/attribute/InjectionRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/attribute/InjectionRule.js +0 -108
- package/out/foundation/engine/rules/attribute/InjectionRule.js.map +0 -1
- package/out/foundation/engine/rules/attribute/RefRule.d.ts +0 -23
- package/out/foundation/engine/rules/attribute/RefRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/attribute/RefRule.js +0 -104
- package/out/foundation/engine/rules/attribute/RefRule.js.map +0 -1
- package/out/foundation/engine/rules/syntax/ExpressionRule.d.ts +0 -19
- package/out/foundation/engine/rules/syntax/ExpressionRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/syntax/ExpressionRule.js +0 -82
- package/out/foundation/engine/rules/syntax/ExpressionRule.js.map +0 -1
- package/out/foundation/engine/rules/syntax/ForRule.d.ts +0 -19
- package/out/foundation/engine/rules/syntax/ForRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/syntax/ForRule.js +0 -226
- package/out/foundation/engine/rules/syntax/ForRule.js.map +0 -1
- package/out/foundation/engine/rules/syntax/IfRule.d.ts +0 -17
- package/out/foundation/engine/rules/syntax/IfRule.d.ts.map +0 -1
- package/out/foundation/engine/rules/syntax/IfRule.js +0 -220
- package/out/foundation/engine/rules/syntax/IfRule.js.map +0 -1
- package/out/foundation/hmle/Context.d.ts +0 -29
- package/out/foundation/hmle/Context.d.ts.map +0 -1
- package/out/foundation/hmle/Context.js +0 -91
- package/out/foundation/hmle/Context.js.map +0 -1
- package/out/foundation/hmle/Expression.d.ts +0 -1
- package/out/foundation/hmle/Expression.d.ts.map +0 -1
- package/out/foundation/hmle/Expression.js +0 -1
- package/out/foundation/hmle/Expression.js.map +0 -1
|
@@ -1,523 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HMLEParser - HTML Markup Language Extensions Parser
|
|
3
|
-
*
|
|
4
|
-
* Two-stage parsing:
|
|
5
|
-
* Stage 1: String processing - @for loops, @(expression) interpolations
|
|
6
|
-
* Stage 2: DOM processing - @[event](handler) bindings, attribute directives
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* const parser = new HMLEParser();
|
|
10
|
-
* parser.addVariable('items', [{name: 'Item 1'}, {name: 'Item 2'}]);
|
|
11
|
-
* const fragment = parser.parseToDOM(templateString, scopeObject);
|
|
12
|
-
*/
|
|
13
|
-
// Stage 1: String-based rules
|
|
14
|
-
class HMLEParserRule {
|
|
15
|
-
pattern;
|
|
16
|
-
replacer;
|
|
17
|
-
constructor(pattern, replacer) {
|
|
18
|
-
this.pattern = pattern;
|
|
19
|
-
this.replacer = replacer;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// Stage 2: DOM-based rules for attribute processing
|
|
23
|
-
class HMLEDOMRule {
|
|
24
|
-
attrPattern;
|
|
25
|
-
processor;
|
|
26
|
-
constructor(attrPattern, processor) {
|
|
27
|
-
this.attrPattern = attrPattern;
|
|
28
|
-
this.processor = processor;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export default class HMLEParser {
|
|
32
|
-
// Extract balanced braces { ... }
|
|
33
|
-
static extractBalancedBraces(content, start) {
|
|
34
|
-
if (content[start] !== '{')
|
|
35
|
-
return null;
|
|
36
|
-
let depth = 1;
|
|
37
|
-
let i = start + 1;
|
|
38
|
-
while (i < content.length && depth > 0) {
|
|
39
|
-
if (content[i] === '{')
|
|
40
|
-
depth++;
|
|
41
|
-
else if (content[i] === '}')
|
|
42
|
-
depth--;
|
|
43
|
-
i++;
|
|
44
|
-
}
|
|
45
|
-
if (depth !== 0)
|
|
46
|
-
return null;
|
|
47
|
-
return { block: content.slice(start + 1, i - 1), end: i };
|
|
48
|
-
}
|
|
49
|
-
// Extract balanced parentheses ( ... )
|
|
50
|
-
static extractBalancedParens(content, start) {
|
|
51
|
-
if (content[start] !== '(')
|
|
52
|
-
return null;
|
|
53
|
-
let depth = 1;
|
|
54
|
-
let i = start + 1;
|
|
55
|
-
while (i < content.length && depth > 0) {
|
|
56
|
-
if (content[i] === '(')
|
|
57
|
-
depth++;
|
|
58
|
-
else if (content[i] === ')')
|
|
59
|
-
depth--;
|
|
60
|
-
i++;
|
|
61
|
-
}
|
|
62
|
-
if (depth !== 0)
|
|
63
|
-
return null;
|
|
64
|
-
return { block: content.slice(start + 1, i - 1), end: i };
|
|
65
|
-
}
|
|
66
|
-
// Predefined rules processed in order
|
|
67
|
-
static rules = [
|
|
68
|
-
// Rule: @for (item in items) { ... }
|
|
69
|
-
// Accept either single variable or index,value pair and either a variable/expr or a numeric literal
|
|
70
|
-
// Examples:
|
|
71
|
-
// @for (item in items) { ... }
|
|
72
|
-
// @for (idx, item in items) { ... }
|
|
73
|
-
// @for (i in 10) { ... }
|
|
74
|
-
new HMLEParserRule(/@for\s*\(\s*([A-Za-z_$][A-Za-z0-9_$]*)(?:\s*,\s*([A-Za-z_$][A-Za-z0-9_$]*))?\s+in\s+([A-Za-z_$][A-Za-z0-9_$.]*|[0-9]+)\s*\)\s*\{/g, (parser, match, input, scope) => {
|
|
75
|
-
// match[1] = first identifier (either item OR index when pair syntax used)
|
|
76
|
-
// match[2] = optional second identifier (value when pair syntax used)
|
|
77
|
-
// match[3] = iterable expression (dotted path or numeric literal)
|
|
78
|
-
const maybeFirst = match[1];
|
|
79
|
-
const maybeSecond = match[2];
|
|
80
|
-
const iterableExpr = match[3];
|
|
81
|
-
const blockStart = match.index + match[0].length - 1; // position of '{'
|
|
82
|
-
const extracted = HMLEParser.extractBalancedBraces(input, blockStart);
|
|
83
|
-
if (!extracted)
|
|
84
|
-
return match[0];
|
|
85
|
-
const inner = extracted.block;
|
|
86
|
-
// Support numeric literal or expression that resolves to a number
|
|
87
|
-
let arr = [];
|
|
88
|
-
// If the iterable part is a plain number literal, use it directly
|
|
89
|
-
if (/^\d+$/.test(iterableExpr)) {
|
|
90
|
-
const n = parseInt(iterableExpr, 10);
|
|
91
|
-
arr = Array.from({ length: Math.max(0, n) }, (_, i) => i);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const resolved = parser.resolveExpression(iterableExpr, scope);
|
|
95
|
-
if (typeof resolved === 'number' && isFinite(resolved)) {
|
|
96
|
-
const n = Math.max(0, Math.floor(resolved));
|
|
97
|
-
arr = Array.from({ length: n }, (_, i) => i);
|
|
98
|
-
}
|
|
99
|
-
else if (Array.isArray(resolved)) {
|
|
100
|
-
arr = resolved;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
arr = [];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const parts = [];
|
|
107
|
-
for (let i = 0; i < arr.length; i++) {
|
|
108
|
-
const item = arr[i];
|
|
109
|
-
let fullScope;
|
|
110
|
-
// If two identifiers were provided, treat first as index and second as value
|
|
111
|
-
if (maybeSecond) {
|
|
112
|
-
fullScope = Object.assign({}, scope, { [maybeFirst]: i, [maybeSecond]: item });
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Single identifier: bind it to the item
|
|
116
|
-
fullScope = Object.assign({}, scope, { [maybeFirst]: item });
|
|
117
|
-
}
|
|
118
|
-
parts.push(parser.parse(inner, fullScope));
|
|
119
|
-
}
|
|
120
|
-
return { text: parts.join('\n'), end: extracted.end };
|
|
121
|
-
}),
|
|
122
|
-
// Rule: @(( code )) — double-paren for complex expressions
|
|
123
|
-
new HMLEParserRule(/@\(\(/g, (parser, match, input, scope) => {
|
|
124
|
-
const blockStart = match.index + match[0].length - 1; // points at inner '('
|
|
125
|
-
const extracted = HMLEParser.extractBalancedParens(input, blockStart);
|
|
126
|
-
if (!extracted)
|
|
127
|
-
return match[0];
|
|
128
|
-
const code = extracted.block;
|
|
129
|
-
const ctx = parser.buildContext(scope);
|
|
130
|
-
let result;
|
|
131
|
-
try {
|
|
132
|
-
const fn = new Function('with(this){ return (' + code + '); }');
|
|
133
|
-
result = fn.call(ctx);
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
try {
|
|
137
|
-
const fn2 = new Function('with(this){ ' + code + ' }');
|
|
138
|
-
result = fn2.call(ctx);
|
|
139
|
-
}
|
|
140
|
-
catch (e2) {
|
|
141
|
-
return { text: '', end: extracted.end };
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// Skip outer ')' if present
|
|
145
|
-
let finalEnd = extracted.end;
|
|
146
|
-
if (input[extracted.end] === ')')
|
|
147
|
-
finalEnd = extracted.end + 1;
|
|
148
|
-
return { text: parser.stringifyValue(result), end: finalEnd };
|
|
149
|
-
}),
|
|
150
|
-
// Rule: @( code ) — single-paren expression
|
|
151
|
-
new HMLEParserRule(/@\(/g, (parser, match, input, scope) => {
|
|
152
|
-
const blockStart = match.index + match[0].length - 1; // points at '('
|
|
153
|
-
const extracted = HMLEParser.extractBalancedParens(input, blockStart);
|
|
154
|
-
if (!extracted)
|
|
155
|
-
return match[0];
|
|
156
|
-
const code = extracted.block;
|
|
157
|
-
const ctx = parser.buildContext(scope);
|
|
158
|
-
let result;
|
|
159
|
-
try {
|
|
160
|
-
const fn = new Function('with(this){ return (' + code + '); }');
|
|
161
|
-
result = fn.call(ctx);
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
try {
|
|
165
|
-
const fn2 = new Function('with(this){ ' + code + ' }');
|
|
166
|
-
result = fn2.call(ctx);
|
|
167
|
-
}
|
|
168
|
-
catch (e2) {
|
|
169
|
-
return { text: '', end: extracted.end };
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return { text: parser.stringifyValue(result), end: extracted.end };
|
|
173
|
-
}),
|
|
174
|
-
];
|
|
175
|
-
// Stage 2: DOM rules for attribute processing
|
|
176
|
-
static domRules = [
|
|
177
|
-
// Rule: @[on{eventName}] = "{expression}" — event binding
|
|
178
|
-
// Example: @[onclick] = "handleClick()""
|
|
179
|
-
// Expression is parsed from the attribute name itself: @[on{click}]= "code here"
|
|
180
|
-
new HMLEDOMRule(/^@\[on([A-Za-z]+)\]/g, (parser, element, attrName, attrValue, match, scope) => {
|
|
181
|
-
const eventName = match[1].toLowerCase(); // click, input, etc.
|
|
182
|
-
const code = attrValue; // expression from (...)
|
|
183
|
-
const ctx = parser.buildContext(scope);
|
|
184
|
-
const handler = (event) => {
|
|
185
|
-
// Add $event to context
|
|
186
|
-
const eventCtx = Object.assign({}, ctx, { event: event, element: element });
|
|
187
|
-
try {
|
|
188
|
-
const fn = new Function('with(this){ ' + code + ' }');
|
|
189
|
-
fn.call(eventCtx);
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
console.error(`HMLEParser: Error in @[on${eventName}] handler:`, e);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
element.addEventListener(eventName, handler);
|
|
196
|
-
//element.removeAttribute(attrName);
|
|
197
|
-
}),
|
|
198
|
-
// Rule: @[bind:attribute](expression) — two-way binding
|
|
199
|
-
// Example: @[bind:value](inputValue)
|
|
200
|
-
/*new HMLEDOMRule(/^@\[bind:([A-Za-z-]+)\]$/,
|
|
201
|
-
(parser, element, attrName, attrValue, match, scope) => {
|
|
202
|
-
const boundAttr = match[1];
|
|
203
|
-
const ctx = parser.buildContext(scope);
|
|
204
|
-
|
|
205
|
-
// Set initial value
|
|
206
|
-
const initialValue = parser.evaluateInContext(attrValue, ctx);
|
|
207
|
-
if (boundAttr === 'value' && 'value' in element) {
|
|
208
|
-
(element as HTMLInputElement).value = initialValue ?? '';
|
|
209
|
-
} else {
|
|
210
|
-
element.setAttribute(boundAttr, parser.stringifyValue(initialValue));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// For input elements, listen for changes
|
|
214
|
-
if (boundAttr === 'value' && (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA' || element.tagName === 'SELECT')) {
|
|
215
|
-
element.addEventListener('input', (event) => {
|
|
216
|
-
const newValue = (event.target as HTMLInputElement).value;
|
|
217
|
-
// Try to update the bound variable in scope
|
|
218
|
-
if (scope && attrValue in scope) {
|
|
219
|
-
scope[attrValue] = newValue;
|
|
220
|
-
} else if (attrValue in parser.variables) {
|
|
221
|
-
parser.variables[attrValue] = newValue;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
element.removeAttribute(attrName);
|
|
227
|
-
}
|
|
228
|
-
),*/
|
|
229
|
-
// Rule: @[ref] = "refName" — element reference
|
|
230
|
-
// Example: @[ref] = "myButton"
|
|
231
|
-
new HMLEDOMRule(/^@\[ref\]/g, (parser, element, attrName, attrValue, match, scope) => {
|
|
232
|
-
// attrValue may be a literal name or an expression that returns a string
|
|
233
|
-
// Evaluate the value in context first, falling back to the raw attrValue
|
|
234
|
-
const ctx = parser.buildContext(scope);
|
|
235
|
-
let refName;
|
|
236
|
-
if (attrValue && attrValue.trim() !== '') {
|
|
237
|
-
const evaluated = parser.evaluateInContext(attrValue, ctx);
|
|
238
|
-
if (typeof evaluated === 'string')
|
|
239
|
-
refName = evaluated;
|
|
240
|
-
else if (evaluated != null)
|
|
241
|
-
refName = String(evaluated);
|
|
242
|
-
else
|
|
243
|
-
refName = attrValue; // fallback to literal attr value
|
|
244
|
-
}
|
|
245
|
-
if (refName) {
|
|
246
|
-
if (scope) {
|
|
247
|
-
scope[refName] = element;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
parser.variables[refName] = element;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
// keep attribute intact for debugging; parser consumer may remove it later
|
|
254
|
-
// element.removeAttribute(attrName);
|
|
255
|
-
}),
|
|
256
|
-
// Rule: @[class:className](condition) — conditional class
|
|
257
|
-
// Example: @[class:active](isActive)
|
|
258
|
-
/*new HMLEDOMRule(/^@\[class:([A-Za-z_-][A-Za-z0-9_-]*)\]$/,
|
|
259
|
-
(parser, element, attrName, attrValue, match, scope) => {
|
|
260
|
-
const className = match[1];
|
|
261
|
-
const ctx = parser.buildContext(scope);
|
|
262
|
-
const condition = parser.evaluateInContext(attrValue, ctx);
|
|
263
|
-
|
|
264
|
-
if (condition) {
|
|
265
|
-
element.classList.add(className);
|
|
266
|
-
} else {
|
|
267
|
-
element.classList.remove(className);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
element.removeAttribute(attrName);
|
|
271
|
-
}
|
|
272
|
-
),*/
|
|
273
|
-
// Rule: @[style:property](expression) — dynamic style
|
|
274
|
-
// Example: @[style:color](textColor)
|
|
275
|
-
/*new HMLEDOMRule(/^@\[style:([A-Za-z-]+)\]$/,
|
|
276
|
-
(parser, element, attrName, attrValue, match, scope) => {
|
|
277
|
-
const styleProp = match[1];
|
|
278
|
-
const ctx = parser.buildContext(scope);
|
|
279
|
-
const value = parser.evaluateInContext(attrValue, ctx);
|
|
280
|
-
|
|
281
|
-
if (value != null) {
|
|
282
|
-
(element as HTMLElement).style.setProperty(styleProp, String(value));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
element.removeAttribute(attrName);
|
|
286
|
-
}
|
|
287
|
-
),*/
|
|
288
|
-
// Rule: @[if](condition) — conditional rendering
|
|
289
|
-
// Example: @[if](showElement)
|
|
290
|
-
/*new HMLEDOMRule(/^@\[if\]$/,
|
|
291
|
-
(parser, element, attrName, attrValue, match, scope) => {
|
|
292
|
-
const ctx = parser.buildContext(scope);
|
|
293
|
-
const condition : boolean = parser.evaluateInContext(attrValue, ctx);
|
|
294
|
-
|
|
295
|
-
if (!condition) {
|
|
296
|
-
// Create a placeholder comment
|
|
297
|
-
const placeholder = document.createComment(`@[if](${attrValue})`);
|
|
298
|
-
element.parentNode?.replaceChild(placeholder, element);
|
|
299
|
-
} else {
|
|
300
|
-
element.removeAttribute(attrName);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
),*/
|
|
304
|
-
];
|
|
305
|
-
variables = {};
|
|
306
|
-
/**
|
|
307
|
-
* Add a variable to the parser's global scope
|
|
308
|
-
*/
|
|
309
|
-
addVariable(name, value) {
|
|
310
|
-
this.variables[name] = value;
|
|
311
|
-
return this;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Build execution context that includes prototype methods from scope
|
|
315
|
-
*/
|
|
316
|
-
buildContext(scope) {
|
|
317
|
-
const ctx = Object.assign({}, this.variables);
|
|
318
|
-
if (scope) {
|
|
319
|
-
// Copy own properties
|
|
320
|
-
Object.assign(ctx, scope);
|
|
321
|
-
// Copy prototype methods (for class instances)
|
|
322
|
-
let proto = Object.getPrototypeOf(scope);
|
|
323
|
-
while (proto && proto !== Object.prototype) {
|
|
324
|
-
// Avoid copying host (DOM/native) prototype methods which may throw
|
|
325
|
-
const ctorName = proto && proto.constructor ? String(proto.constructor?.name ?? '') : '';
|
|
326
|
-
if (/HTMLElement|Element|Node|EventTarget|Window|GlobalThis/i.test(ctorName)) {
|
|
327
|
-
// Skip host prototypes entirely
|
|
328
|
-
proto = Object.getPrototypeOf(proto);
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
332
|
-
if (key === 'constructor' || key in ctx)
|
|
333
|
-
continue;
|
|
334
|
-
// Use descriptor to avoid triggering getters/accessors
|
|
335
|
-
let desc;
|
|
336
|
-
try {
|
|
337
|
-
desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
338
|
-
}
|
|
339
|
-
catch (e) {
|
|
340
|
-
// Some host objects may throw on descriptor access — skip safely
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
if (!desc)
|
|
344
|
-
continue;
|
|
345
|
-
// Only bind plain function values — don't copy getters/setters
|
|
346
|
-
if (typeof desc.value === 'function') {
|
|
347
|
-
try {
|
|
348
|
-
ctx[key] = desc.value.bind(scope);
|
|
349
|
-
}
|
|
350
|
-
catch (e) {
|
|
351
|
-
// binding some native functions may throw; skip them
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
proto = Object.getPrototypeOf(proto);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return ctx;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Resolve a dotted expression against the parser variables and optional local scope.
|
|
363
|
-
*/
|
|
364
|
-
resolveExpression(expr, scope) {
|
|
365
|
-
const combined = this.buildContext(scope);
|
|
366
|
-
const parts = expr.split('.').map(p => p.trim()).filter(Boolean);
|
|
367
|
-
let cur = combined;
|
|
368
|
-
for (const part of parts) {
|
|
369
|
-
if (cur == null)
|
|
370
|
-
return undefined;
|
|
371
|
-
cur = cur[part];
|
|
372
|
-
}
|
|
373
|
-
return cur;
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Convert value to string for text content
|
|
377
|
-
*/
|
|
378
|
-
stringifyValue(val) {
|
|
379
|
-
if (val == null)
|
|
380
|
-
return '';
|
|
381
|
-
if (typeof val === 'string')
|
|
382
|
-
return val;
|
|
383
|
-
return String(val);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Evaluate a JavaScript expression in a given context
|
|
387
|
-
*/
|
|
388
|
-
evaluateInContext(code, ctx) {
|
|
389
|
-
try {
|
|
390
|
-
const fn = new Function('with(this){ return (' + code + '); }');
|
|
391
|
-
return fn.call(ctx);
|
|
392
|
-
}
|
|
393
|
-
catch (e) {
|
|
394
|
-
try {
|
|
395
|
-
const fn2 = new Function('with(this){ ' + code + ' }');
|
|
396
|
-
return fn2.call(ctx);
|
|
397
|
-
}
|
|
398
|
-
catch (e2) {
|
|
399
|
-
return undefined;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Parse HMLE template string and return processed HTML string
|
|
405
|
-
* @param content HMLE template string
|
|
406
|
-
* @param scope Optional scope object (can be a class instance)
|
|
407
|
-
* @returns Processed HTML string
|
|
408
|
-
*/
|
|
409
|
-
parse(content, scope) {
|
|
410
|
-
let working = content;
|
|
411
|
-
for (const rule of HMLEParser.rules) {
|
|
412
|
-
const pattern = rule.pattern;
|
|
413
|
-
let result = '';
|
|
414
|
-
let lastIndex = 0;
|
|
415
|
-
let match;
|
|
416
|
-
// Reset scanning position
|
|
417
|
-
pattern.lastIndex = 0;
|
|
418
|
-
while ((match = pattern.exec(working)) !== null) {
|
|
419
|
-
// Append text before this match
|
|
420
|
-
result += working.slice(lastIndex, match.index);
|
|
421
|
-
const out = rule.replacer(this, match, working, scope);
|
|
422
|
-
if (typeof out === 'string') {
|
|
423
|
-
result += out;
|
|
424
|
-
lastIndex = match.index + match[0].length;
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
result += out.text;
|
|
428
|
-
lastIndex = out.end;
|
|
429
|
-
}
|
|
430
|
-
// Continue scanning from the correct position
|
|
431
|
-
pattern.lastIndex = lastIndex;
|
|
432
|
-
}
|
|
433
|
-
// Append tail and update working
|
|
434
|
-
result += working.slice(lastIndex);
|
|
435
|
-
working = result;
|
|
436
|
-
}
|
|
437
|
-
return working;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Stage 2: Process DOM rules on a fragment
|
|
441
|
-
* Walks all elements and applies DOM rules based on attributes
|
|
442
|
-
*/
|
|
443
|
-
processDOMRules(fragment, scope) {
|
|
444
|
-
const elements = fragment instanceof DocumentFragment
|
|
445
|
-
? Array.from(fragment.querySelectorAll('*'))
|
|
446
|
-
: [fragment, ...Array.from(fragment.querySelectorAll('*'))];
|
|
447
|
-
for (const element of elements) {
|
|
448
|
-
// Get all attributes to process (copy to avoid mutation issues)
|
|
449
|
-
const attrs = Array.from(element.attributes);
|
|
450
|
-
for (const attr of attrs) {
|
|
451
|
-
// Check each DOM rule
|
|
452
|
-
for (const rule of HMLEParser.domRules) {
|
|
453
|
-
rule.attrPattern.lastIndex = 0;
|
|
454
|
-
const match = rule.attrPattern.exec(attr.name);
|
|
455
|
-
if (match) {
|
|
456
|
-
rule.processor(this, element, attr.name, attr.value, match, scope);
|
|
457
|
-
break; // Only one rule per attribute
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Parse HMLE template and create DOM elements (Stage 1 + Stage 2)
|
|
465
|
-
* @param content HMLE template string
|
|
466
|
-
* @param scope Optional scope object
|
|
467
|
-
* @returns DocumentFragment containing parsed HTML with bindings applied
|
|
468
|
-
*/
|
|
469
|
-
parseToDOM(content, scope) {
|
|
470
|
-
// Stage 1: String processing
|
|
471
|
-
const html = this.parse(content, scope);
|
|
472
|
-
const template = document.createElement('template');
|
|
473
|
-
template.innerHTML = html.trim();
|
|
474
|
-
const fragment = template.content;
|
|
475
|
-
// Stage 2: DOM processing
|
|
476
|
-
this.processDOMRules(fragment, scope);
|
|
477
|
-
return fragment;
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Parse HMLE template and return single element (first child)
|
|
481
|
-
* @param content HMLE template string
|
|
482
|
-
* @param scope Optional scope object
|
|
483
|
-
* @returns First element from parsed HTML, or null
|
|
484
|
-
*/
|
|
485
|
-
parseToElement(content, scope) {
|
|
486
|
-
const fragment = this.parseToDOM(content, scope);
|
|
487
|
-
return fragment.firstElementChild;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Parse and append to a parent element
|
|
491
|
-
* @param content HMLE template string
|
|
492
|
-
* @param parent Parent element to append to
|
|
493
|
-
* @param scope Optional scope object
|
|
494
|
-
* @returns The parent element
|
|
495
|
-
*/
|
|
496
|
-
parseAndAppend(content, parent, scope) {
|
|
497
|
-
const fragment = this.parseToDOM(content, scope);
|
|
498
|
-
parent.appendChild(fragment);
|
|
499
|
-
return parent;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Parse and replace element's innerHTML
|
|
503
|
-
* @param content HMLE template string
|
|
504
|
-
* @param element Element to update
|
|
505
|
-
* @param scope Optional scope object
|
|
506
|
-
* @returns The updated element
|
|
507
|
-
*/
|
|
508
|
-
parseAndReplace(content, element, scope) {
|
|
509
|
-
const fragment = this.parseToDOM(content, scope);
|
|
510
|
-
element.innerHTML = '';
|
|
511
|
-
element.appendChild(fragment);
|
|
512
|
-
return element;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Apply DOM rules to an existing element (Stage 2 only)
|
|
516
|
-
* Useful when you already have DOM and just want to process bindings
|
|
517
|
-
*/
|
|
518
|
-
applyBindings(element, scope) {
|
|
519
|
-
this.processDOMRules(element, scope);
|
|
520
|
-
return element;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
//# sourceMappingURL=HMLEParser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HMLEParser.js","sourceRoot":"","sources":["../../src/foundation/HMLEParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8BAA8B;AAC9B,MAAM,cAAc;IACT,OAAO,CAAS;IAChB,QAAQ,CAAqI;IAEpJ,YACI,OAAe,EACf,QAA4I;QAE5I,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAED,oDAAoD;AACpD,MAAM,WAAW;IACN,WAAW,CAAS;IACpB,SAAS,CAA2I;IAE3J,YACI,WAAmB,EACnB,SAAmJ;QAEnJ,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B,kCAAkC;IAC1B,MAAM,CAAC,qBAAqB,CAAC,OAAe,EAAE,KAAa;QAC/D,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;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AW,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED;;;OAGG;IACI,aAAa,CAAC,OAAgB,EAAE,KAA2B;QAC9D,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC;IACnB,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rule — represents a single parsing rule with its own check and execution logic.
|
|
3
|
-
* Rules can apply to any of the 3 parsing stages or to specific ones.
|
|
4
|
-
*/
|
|
5
|
-
export interface Rule {
|
|
6
|
-
name: string;
|
|
7
|
-
/** Stage 1: text parsing — returns transformed string or null if rule doesn't apply */
|
|
8
|
-
parseText?: (parser: HMLEParserReborn, content: string, scope?: Record<string, any>, dynamicVars?: Set<string>) => string | null;
|
|
9
|
-
/** Stage 3: hydration — processes template elements in DOM */
|
|
10
|
-
hydrate?: (parser: HMLEParserReborn, template: HTMLTemplateElement, scope?: Record<string, any>) => void;
|
|
11
|
-
/** Optional: element-level hydration (stage 2/DOM parse) */
|
|
12
|
-
elementHydrate?: (parser: HMLEParserReborn, el: Element, scope?: Record<string, any>) => void;
|
|
13
|
-
}
|
|
14
|
-
export default class HMLEParserReborn {
|
|
15
|
-
private rules;
|
|
16
|
-
variables: Record<string, any>;
|
|
17
|
-
constructor();
|
|
18
|
-
/**
|
|
19
|
-
* Add a custom rule to the parser
|
|
20
|
-
*/
|
|
21
|
-
addRule(rule: Rule): this;
|
|
22
|
-
/**
|
|
23
|
-
* Get registered rules
|
|
24
|
-
*/
|
|
25
|
-
getRules(): Rule[];
|
|
26
|
-
static isIdentifier(s: string): boolean;
|
|
27
|
-
private buildContext;
|
|
28
|
-
evaluate(expr: string, scope?: Record<string, any>): any;
|
|
29
|
-
stringify(v: any): string;
|
|
30
|
-
/**
|
|
31
|
-
* Stage 1: Parsing — parse HMLE as text, execute STATIC RULES.
|
|
32
|
-
* Observable values are left as <template ...> placeholders for Stage 3.
|
|
33
|
-
*/
|
|
34
|
-
parse(content: string, scope?: Record<string, any>): string;
|
|
35
|
-
/**
|
|
36
|
-
* Stage 2: DOM Parsing — parse HMLE text to DOM, create <template> for dynamic rules.
|
|
37
|
-
* Created templates are preserved for reuse when Observable updates.
|
|
38
|
-
*/
|
|
39
|
-
parseToDOM(content: string, scope?: Record<string, any>): DocumentFragment;
|
|
40
|
-
/**
|
|
41
|
-
* Stage 3: Hydration — remove templates and execute dynamic rules.
|
|
42
|
-
*/
|
|
43
|
-
hydrate(fragment: DocumentFragment | Element, scope?: Record<string, any>): void;
|
|
44
|
-
/**
|
|
45
|
-
* Process {{EXP:expr}} placeholders in element attributes
|
|
46
|
-
*/
|
|
47
|
-
private hydrateAttributeExpressions;
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=HMLEParserReborn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HMLEParserReborn.d.ts","sourceRoot":"","sources":["../../src/foundation/HMLEParserReborn.ts"],"names":[],"mappings":"AAsGA;;;GAGG;AACH,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC;IACjI,8DAA8D;IAC9D,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACzG,4DAA4D;IAC5D,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,C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