@arikajs/view 0.0.4 → 0.0.6
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 +92 -194
- package/dist/Compiler/AST.d.ts +34 -0
- package/dist/Compiler/AST.d.ts.map +1 -0
- package/dist/Compiler/AST.js +12 -0
- package/dist/Compiler/AST.js.map +1 -0
- package/dist/Compiler/CodeGenerator.d.ts +11 -0
- package/dist/Compiler/CodeGenerator.d.ts.map +1 -0
- package/dist/Compiler/CodeGenerator.js +53 -0
- package/dist/Compiler/CodeGenerator.js.map +1 -0
- package/dist/Compiler/DirectiveRegistry.d.ts +10 -0
- package/dist/Compiler/DirectiveRegistry.d.ts.map +1 -0
- package/dist/Compiler/DirectiveRegistry.js +206 -0
- package/dist/Compiler/DirectiveRegistry.js.map +1 -0
- package/dist/Compiler/Lexer.d.ts +28 -0
- package/dist/Compiler/Lexer.d.ts.map +1 -0
- package/dist/Compiler/Lexer.js +209 -0
- package/dist/Compiler/Lexer.js.map +1 -0
- package/dist/Compiler/Parser.d.ts +15 -0
- package/dist/Compiler/Parser.d.ts.map +1 -0
- package/dist/Compiler/Parser.js +188 -0
- package/dist/Compiler/Parser.js.map +1 -0
- package/dist/Compiler.d.ts +4 -3
- package/dist/Compiler.d.ts.map +1 -1
- package/dist/Compiler.js +13 -60
- package/dist/Compiler.js.map +1 -1
- package/dist/Engine.d.ts +47 -4
- package/dist/Engine.d.ts.map +1 -1
- package/dist/Engine.js +203 -39
- package/dist/Engine.js.map +1 -1
- package/dist/Template.js +1 -1
- package/dist/Template.js.map +1 -1
- package/dist/View.d.ts +19 -3
- package/dist/View.d.ts.map +1 -1
- package/dist/View.js +30 -2
- package/dist/View.js.map +1 -1
- package/dist/src/Compiler/AST.d.ts +34 -0
- package/dist/src/Compiler/AST.d.ts.map +1 -0
- package/dist/src/Compiler/AST.js +12 -0
- package/dist/src/Compiler/AST.js.map +1 -0
- package/dist/src/Compiler/CodeGenerator.d.ts +11 -0
- package/dist/src/Compiler/CodeGenerator.d.ts.map +1 -0
- package/dist/src/Compiler/CodeGenerator.js +53 -0
- package/dist/src/Compiler/CodeGenerator.js.map +1 -0
- package/dist/src/Compiler/DirectiveRegistry.d.ts +10 -0
- package/dist/src/Compiler/DirectiveRegistry.d.ts.map +1 -0
- package/dist/src/Compiler/DirectiveRegistry.js +206 -0
- package/dist/src/Compiler/DirectiveRegistry.js.map +1 -0
- package/dist/src/Compiler/Lexer.d.ts +28 -0
- package/dist/src/Compiler/Lexer.d.ts.map +1 -0
- package/dist/src/Compiler/Lexer.js +209 -0
- package/dist/src/Compiler/Lexer.js.map +1 -0
- package/dist/src/Compiler/Parser.d.ts +15 -0
- package/dist/src/Compiler/Parser.d.ts.map +1 -0
- package/dist/src/Compiler/Parser.js +188 -0
- package/dist/src/Compiler/Parser.js.map +1 -0
- package/dist/src/Compiler.d.ts +14 -0
- package/dist/src/Compiler.d.ts.map +1 -0
- package/dist/src/Compiler.js +31 -0
- package/dist/src/Compiler.js.map +1 -0
- package/dist/src/Engine.d.ts +76 -0
- package/dist/src/Engine.d.ts.map +1 -0
- package/dist/src/Engine.js +308 -0
- package/dist/src/Engine.js.map +1 -0
- package/dist/src/Template.d.ts +14 -0
- package/dist/src/Template.d.ts.map +1 -0
- package/dist/src/Template.js +63 -0
- package/dist/src/Template.js.map +1 -0
- package/dist/src/View.d.ts +30 -0
- package/dist/src/View.d.ts.map +1 -0
- package/dist/src/View.js +51 -0
- package/dist/src/View.js.map +1 -0
- package/dist/tests/View.test.d.ts +2 -0
- package/dist/tests/View.test.d.ts.map +1 -0
- package/dist/tests/View.test.js +190 -0
- package/dist/tests/View.test.js.map +1 -0
- package/package.json +45 -43
- package/dist/Directives/For.d.ts +0 -5
- package/dist/Directives/For.d.ts.map +0 -1
- package/dist/Directives/For.js +0 -18
- package/dist/Directives/For.js.map +0 -1
- package/dist/Directives/If.d.ts +0 -6
- package/dist/Directives/If.d.ts.map +0 -1
- package/dist/Directives/If.js +0 -26
- package/dist/Directives/If.js.map +0 -1
- package/dist/Directives/Include.d.ts +0 -5
- package/dist/Directives/Include.d.ts.map +0 -1
- package/dist/Directives/Include.js +0 -15
- package/dist/Directives/Include.js.map +0 -1
- package/dist/Directives/Section.d.ts +0 -5
- package/dist/Directives/Section.d.ts.map +0 -1
- package/dist/Directives/Section.js +0 -28
- package/dist/Directives/Section.js.map +0 -1
package/dist/Engine.js
CHANGED
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.Engine = void 0;
|
|
37
37
|
const fs = __importStar(require("node:fs"));
|
|
38
38
|
const path = __importStar(require("node:path"));
|
|
39
|
+
const crypto = __importStar(require("node:crypto"));
|
|
39
40
|
const Compiler_1 = require("./Compiler");
|
|
40
41
|
const Template_1 = require("./Template");
|
|
41
42
|
class Engine {
|
|
@@ -45,14 +46,54 @@ class Engine {
|
|
|
45
46
|
this.sectionStack = [];
|
|
46
47
|
this.parentTemplate = null;
|
|
47
48
|
this.compiledFunctions = new Map();
|
|
49
|
+
this.sharedData = {};
|
|
50
|
+
this.composers = new Map();
|
|
51
|
+
this.helpers = {};
|
|
52
|
+
// For push, prepend & stack
|
|
53
|
+
this.pushes = {};
|
|
54
|
+
this.pushStack = [];
|
|
55
|
+
// For components & slots
|
|
56
|
+
this.componentStack = [];
|
|
57
|
+
this.slotStack = [];
|
|
58
|
+
// For fragments
|
|
59
|
+
this.fragmentMode = null;
|
|
60
|
+
// For once directive
|
|
61
|
+
this.onceKeys = new Set();
|
|
62
|
+
this.config = {
|
|
63
|
+
cache: true,
|
|
64
|
+
dev: false,
|
|
65
|
+
extension: '.ark.html',
|
|
66
|
+
...config
|
|
67
|
+
};
|
|
48
68
|
this.compiler = new Compiler_1.Compiler();
|
|
49
|
-
this.templateLoader = new Template_1.Template(config);
|
|
69
|
+
this.templateLoader = new Template_1.Template(this.config);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Share data across all renders.
|
|
73
|
+
*/
|
|
74
|
+
share(key, value) {
|
|
75
|
+
this.sharedData[key] = value;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Add a view composer.
|
|
79
|
+
*/
|
|
80
|
+
composer(template, callback) {
|
|
81
|
+
if (!this.composers.has(template)) {
|
|
82
|
+
this.composers.set(template, []);
|
|
83
|
+
}
|
|
84
|
+
this.composers.get(template).push(callback);
|
|
50
85
|
}
|
|
51
86
|
/**
|
|
52
|
-
* Add a
|
|
87
|
+
* Add a global helper.
|
|
53
88
|
*/
|
|
54
|
-
|
|
55
|
-
this.
|
|
89
|
+
helper(name, callback) {
|
|
90
|
+
this.helpers[name] = callback;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Add a custom directive.
|
|
94
|
+
*/
|
|
95
|
+
directive(name, handler) {
|
|
96
|
+
this.compiler.addDirective(name, handler);
|
|
56
97
|
}
|
|
57
98
|
/**
|
|
58
99
|
* Render a template file.
|
|
@@ -60,9 +101,17 @@ class Engine {
|
|
|
60
101
|
async render(template, data = {}, isInternal = false) {
|
|
61
102
|
if (!isInternal) {
|
|
62
103
|
this.sections = {};
|
|
104
|
+
this.pushes = {};
|
|
105
|
+
this.onceKeys = new Set();
|
|
106
|
+
}
|
|
107
|
+
const mergedData = { ...this.sharedData, ...this.helpers, ...data };
|
|
108
|
+
// Execute composers
|
|
109
|
+
await this.executeComposers(template, mergedData);
|
|
110
|
+
if (this.composers.has('*')) {
|
|
111
|
+
await this.executeComposers('*', mergedData);
|
|
63
112
|
}
|
|
64
113
|
this.parentTemplate = null;
|
|
65
|
-
const content = await this.renderTemplate(template,
|
|
114
|
+
const content = await this.renderTemplate(template, mergedData);
|
|
66
115
|
if (this.parentTemplate) {
|
|
67
116
|
const parent = this.parentTemplate;
|
|
68
117
|
this.parentTemplate = null;
|
|
@@ -71,53 +120,91 @@ class Engine {
|
|
|
71
120
|
return content;
|
|
72
121
|
}
|
|
73
122
|
/**
|
|
74
|
-
*
|
|
123
|
+
* Render a fragment of a template.
|
|
75
124
|
*/
|
|
125
|
+
async renderFragment(template, fragment, data = {}) {
|
|
126
|
+
this.fragmentMode = fragment;
|
|
127
|
+
const result = await this.render(template, data);
|
|
128
|
+
this.fragmentMode = null;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
async executeComposers(template, data) {
|
|
132
|
+
const callbacks = this.composers.get(template);
|
|
133
|
+
if (callbacks) {
|
|
134
|
+
for (const cb of callbacks) {
|
|
135
|
+
await cb(data);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
76
139
|
async renderTemplate(templateName, data) {
|
|
77
|
-
// 1. Check
|
|
140
|
+
// 1. Check Memory Cache
|
|
78
141
|
if (this.config.cache && this.compiledFunctions.has(templateName)) {
|
|
79
|
-
return await this.compiledFunctions.get(templateName)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
142
|
+
return await this.runCompiled(this.compiledFunctions.get(templateName).func, data, templateName);
|
|
143
|
+
}
|
|
144
|
+
// 2. Check Disk Cache (Primary - bypasses file read for speed)
|
|
145
|
+
if (this.config.cache && this.config.cachePath) {
|
|
146
|
+
const cachedFunc = this.loadFromDiskCache(templateName);
|
|
147
|
+
if (cachedFunc) {
|
|
148
|
+
// If we found it on disk, we can skip reading the source!
|
|
149
|
+
// But we don't have the current hash... we'll just use the one from disk.
|
|
150
|
+
this.compiledFunctions.set(templateName, { func: cachedFunc, hash: 'disk-cached' });
|
|
151
|
+
return await this.runCompiled(cachedFunc, data, templateName);
|
|
89
152
|
}
|
|
90
|
-
|
|
91
|
-
|
|
153
|
+
}
|
|
154
|
+
const rawContent = this.templateLoader.read(templateName);
|
|
155
|
+
const contentHash = crypto.createHash('md5').update(rawContent).digest('hex');
|
|
156
|
+
const jsCode = this.compiler.compile(rawContent);
|
|
157
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
158
|
+
// Use 'with' only for data provided to function to allow pure JS expressions
|
|
159
|
+
const wrappedJsCode = `with (_data) {\n${jsCode}\n}`;
|
|
160
|
+
const renderFunc = new AsyncFunction('_engine', '_data', wrappedJsCode);
|
|
161
|
+
if (this.config.cache) {
|
|
162
|
+
this.compiledFunctions.set(templateName, { func: renderFunc, hash: contentHash });
|
|
163
|
+
if (this.config.cachePath) {
|
|
164
|
+
this.saveToDiskCache(templateName, contentHash, jsCode);
|
|
92
165
|
}
|
|
93
166
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
console.error(`View Cache Warning: Failed to write to ${this.config.cachePath}`);
|
|
167
|
+
return await this.runCompiled(renderFunc, data, templateName);
|
|
168
|
+
}
|
|
169
|
+
loadFromDiskCache(templateName, hash) {
|
|
170
|
+
try {
|
|
171
|
+
const cacheKey = crypto.createHash('md5').update(templateName).digest('hex');
|
|
172
|
+
const cacheFile = path.join(this.config.cachePath, `${cacheKey}.js`);
|
|
173
|
+
if (fs.existsSync(cacheFile)) {
|
|
174
|
+
const { hash: cachedHash, code } = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
|
175
|
+
if (!hash || cachedHash === hash) {
|
|
176
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
177
|
+
return new AsyncFunction('_engine', '_data', `with (_data) {\n${code}\n}`);
|
|
108
178
|
}
|
|
109
179
|
}
|
|
110
180
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
181
|
+
catch (e) {
|
|
182
|
+
// Ignore cache errors
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
saveToDiskCache(templateName, hash, code) {
|
|
187
|
+
try {
|
|
188
|
+
if (!fs.existsSync(this.config.cachePath)) {
|
|
189
|
+
fs.mkdirSync(this.config.cachePath, { recursive: true });
|
|
190
|
+
}
|
|
191
|
+
const cacheKey = crypto.createHash('md5').update(templateName).digest('hex');
|
|
192
|
+
const cacheFile = path.join(this.config.cachePath, `${cacheKey}.js`);
|
|
193
|
+
fs.writeFileSync(cacheFile, JSON.stringify({ hash, code }), 'utf8');
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
// Ignore cache errors
|
|
116
197
|
}
|
|
198
|
+
}
|
|
199
|
+
async runCompiled(func, data, templateName) {
|
|
117
200
|
try {
|
|
118
|
-
return await
|
|
201
|
+
return await func(this, data);
|
|
119
202
|
}
|
|
120
203
|
catch (e) {
|
|
204
|
+
if (this.config.dev) {
|
|
205
|
+
// In dev mode, we could enhance the error further
|
|
206
|
+
throw new Error(`Error in ${templateName}: ${e.message}\nStack: ${e.stack}`);
|
|
207
|
+
}
|
|
121
208
|
throw new Error(`Error rendering template "${templateName}": ${e.message}`);
|
|
122
209
|
}
|
|
123
210
|
}
|
|
@@ -139,6 +226,83 @@ class Engine {
|
|
|
139
226
|
yield(name) {
|
|
140
227
|
return this.sections[name] || '';
|
|
141
228
|
}
|
|
229
|
+
// --- PUSH, PREPEND & STACK ---
|
|
230
|
+
startPush(name, previousOutput) {
|
|
231
|
+
this.pushStack.push({ name, type: 'push', previousOutput });
|
|
232
|
+
}
|
|
233
|
+
startPrepend(name, previousOutput) {
|
|
234
|
+
this.pushStack.push({ name, type: 'prepend', previousOutput });
|
|
235
|
+
}
|
|
236
|
+
endPush(content) {
|
|
237
|
+
return this.processEndPush(content);
|
|
238
|
+
}
|
|
239
|
+
endPrepend(content) {
|
|
240
|
+
return this.processEndPush(content);
|
|
241
|
+
}
|
|
242
|
+
processEndPush(content) {
|
|
243
|
+
const push = this.pushStack.pop();
|
|
244
|
+
if (push) {
|
|
245
|
+
if (!this.pushes[push.name]) {
|
|
246
|
+
this.pushes[push.name] = [];
|
|
247
|
+
}
|
|
248
|
+
if (push.type === 'prepend') {
|
|
249
|
+
this.pushes[push.name].unshift(content);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.pushes[push.name].push(content);
|
|
253
|
+
}
|
|
254
|
+
return push.previousOutput;
|
|
255
|
+
}
|
|
256
|
+
return content;
|
|
257
|
+
}
|
|
258
|
+
stack(name) {
|
|
259
|
+
return this.pushes[name] ? this.pushes[name].join('\n') : '';
|
|
260
|
+
}
|
|
261
|
+
// --- COMPONENTS & SLOTS ---
|
|
262
|
+
startComponent(name, data, previousOutput) {
|
|
263
|
+
this.componentStack.push({ name, data, previousOutput, slots: {} });
|
|
264
|
+
}
|
|
265
|
+
startSlot(name, previousOutput) {
|
|
266
|
+
this.slotStack.push({ name, previousOutput });
|
|
267
|
+
}
|
|
268
|
+
endSlot(content) {
|
|
269
|
+
const slot = this.slotStack.pop();
|
|
270
|
+
if (slot) {
|
|
271
|
+
if (this.componentStack.length > 0) {
|
|
272
|
+
const component = this.componentStack[this.componentStack.length - 1];
|
|
273
|
+
component.slots[slot.name] = content;
|
|
274
|
+
}
|
|
275
|
+
return slot.previousOutput;
|
|
276
|
+
}
|
|
277
|
+
return content;
|
|
278
|
+
}
|
|
279
|
+
async renderComponent(defaultSlotContent) {
|
|
280
|
+
const component = this.componentStack.pop();
|
|
281
|
+
if (component) {
|
|
282
|
+
const componentData = {
|
|
283
|
+
...component.data,
|
|
284
|
+
slot: defaultSlotContent,
|
|
285
|
+
...component.slots
|
|
286
|
+
};
|
|
287
|
+
const rendered = await this.render(component.name, componentData, true);
|
|
288
|
+
return component.previousOutput + rendered;
|
|
289
|
+
}
|
|
290
|
+
return defaultSlotContent;
|
|
291
|
+
}
|
|
292
|
+
// --- ONCE ---
|
|
293
|
+
markOnce(id) {
|
|
294
|
+
this.onceKeys.add(id);
|
|
295
|
+
}
|
|
296
|
+
hasOnce(id) {
|
|
297
|
+
return this.onceKeys.has(id);
|
|
298
|
+
}
|
|
299
|
+
// --- FRAGMENTS ---
|
|
300
|
+
isFragmentMode() {
|
|
301
|
+
return this.fragmentMode !== null;
|
|
302
|
+
}
|
|
303
|
+
getFragment() {
|
|
304
|
+
return this.fragmentMode;
|
|
305
|
+
}
|
|
142
306
|
}
|
|
143
307
|
exports.Engine = Engine;
|
|
144
308
|
//# sourceMappingURL=Engine.js.map
|
package/dist/Engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,yCAAsC;AACtC,yCAAsC;
|
|
1
|
+
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,oDAAsC;AACtC,yCAAsC;AACtC,yCAAsC;AAatC,MAAa,MAAM;IA0Bf,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAzB9B,aAAQ,GAA2B,EAAE,CAAC;QACtC,iBAAY,GAA+C,EAAE,CAAC;QAC9D,mBAAc,GAAkB,IAAI,CAAC;QAGrC,sBAAiB,GAAkD,IAAI,GAAG,EAAE,CAAC;QAE7E,eAAU,GAAwB,EAAE,CAAC;QACrC,cAAS,GAAgC,IAAI,GAAG,EAAE,CAAC;QACnD,YAAO,GAA+B,EAAE,CAAC;QAEjD,4BAA4B;QACpB,WAAM,GAA6B,EAAE,CAAC;QACtC,cAAS,GAAyE,EAAE,CAAC;QAE7F,yBAAyB;QACjB,mBAAc,GAAyF,EAAE,CAAC;QAC1G,cAAS,GAA+C,EAAE,CAAC;QAEnE,gBAAgB;QACR,iBAAY,GAAkB,IAAI,CAAC;QAE3C,qBAAqB;QACb,aAAQ,GAAgB,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CAAC;IAED,oBAAoB;IACb,cAAc;QACjB,OAAO,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC;IACtC,CAAC;IACM,WAAW;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AAtTD,wBAsTC"}
|
package/dist/Template.js
CHANGED
|
@@ -54,7 +54,7 @@ class Template {
|
|
|
54
54
|
* Resolve template name to file path.
|
|
55
55
|
*/
|
|
56
56
|
resolvePath(template) {
|
|
57
|
-
const ext = this.config.extension || '.html';
|
|
57
|
+
const ext = this.config.extension || '.ark.html';
|
|
58
58
|
const fileName = template.replace(/\./g, path.sep) + ext;
|
|
59
59
|
return path.join(this.config.viewsPath, fileName);
|
|
60
60
|
}
|
package/dist/Template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAGlC,MAAa,QAAQ;IACjB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAI,CAAC;IAE3C;;OAEG;IACI,IAAI,CAAC,QAAgB;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,QAAgB;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAGlC,MAAa,QAAQ;IACjB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAI,CAAC;IAE3C;;OAEG;IACI,IAAI,CAAC,QAAgB;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,QAAgB;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,WAAW,CAAC;QACjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QACzD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;CACJ;AAtBD,4BAsBC"}
|
package/dist/View.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import { ViewConfig } from './Engine';
|
|
1
|
+
import { ViewConfig, ViewComposer, ViewHelper } from './Engine';
|
|
2
2
|
export declare class View {
|
|
3
3
|
private engine;
|
|
4
4
|
constructor(config: ViewConfig);
|
|
5
5
|
/**
|
|
6
6
|
* Add a custom directive to the template compiler.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
directive(name: string, handler: (expression: string | null, children?: string) => string): this;
|
|
9
|
+
/**
|
|
10
|
+
* Add a view composer.
|
|
11
|
+
*/
|
|
12
|
+
composer(template: string, callback: ViewComposer): this;
|
|
13
|
+
/**
|
|
14
|
+
* Add a global helper.
|
|
15
|
+
*/
|
|
16
|
+
helper(name: string, callback: ViewHelper): this;
|
|
17
|
+
/**
|
|
18
|
+
* Share data explicitly across all templates rendered by this view instance.
|
|
19
|
+
*/
|
|
20
|
+
share(key: string, value: any): this;
|
|
9
21
|
/**
|
|
10
22
|
* Render a template with data.
|
|
11
23
|
*/
|
|
12
|
-
render(template: string, data?:
|
|
24
|
+
render<T = Record<string, any>>(template: string, data?: T): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Render a fragment of a template.
|
|
27
|
+
*/
|
|
28
|
+
renderFragment(template: string, fragment: string, data?: any): Promise<string>;
|
|
13
29
|
}
|
|
14
30
|
//# sourceMappingURL=View.d.ts.map
|
package/dist/View.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"View.d.ts","sourceRoot":"","sources":["../src/View.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"View.d.ts","sourceRoot":"","sources":["../src/View.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAExE,qBAAa,IAAI;IACb,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,UAAU;IAI9B;;OAEG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI;IAKvG;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI;IAK/D;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,IAAI;IAKvD;;OAEG;IACI,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAK3C;;OAEG;IACU,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,CAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlG;;OAEG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,GAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAGnG"}
|
package/dist/View.js
CHANGED
|
@@ -9,8 +9,30 @@ class View {
|
|
|
9
9
|
/**
|
|
10
10
|
* Add a custom directive to the template compiler.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
this.engine.
|
|
12
|
+
directive(name, handler) {
|
|
13
|
+
this.engine.directive(name, handler);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Add a view composer.
|
|
18
|
+
*/
|
|
19
|
+
composer(template, callback) {
|
|
20
|
+
this.engine.composer(template, callback);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Add a global helper.
|
|
25
|
+
*/
|
|
26
|
+
helper(name, callback) {
|
|
27
|
+
this.engine.helper(name, callback);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Share data explicitly across all templates rendered by this view instance.
|
|
32
|
+
*/
|
|
33
|
+
share(key, value) {
|
|
34
|
+
this.engine.share(key, value);
|
|
35
|
+
return this;
|
|
14
36
|
}
|
|
15
37
|
/**
|
|
16
38
|
* Render a template with data.
|
|
@@ -18,6 +40,12 @@ class View {
|
|
|
18
40
|
async render(template, data = {}) {
|
|
19
41
|
return this.engine.render(template, data);
|
|
20
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Render a fragment of a template.
|
|
45
|
+
*/
|
|
46
|
+
async renderFragment(template, fragment, data = {}) {
|
|
47
|
+
return this.engine.renderFragment(template, fragment, data);
|
|
48
|
+
}
|
|
21
49
|
}
|
|
22
50
|
exports.View = View;
|
|
23
51
|
//# sourceMappingURL=View.js.map
|
package/dist/View.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"View.js","sourceRoot":"","sources":["../src/View.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"View.js","sourceRoot":"","sources":["../src/View.ts"],"names":[],"mappings":";;;AAAA,qCAAwE;AAExE,MAAa,IAAI;IAGb,YAAY,MAAkB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,IAAY,EAAE,OAAiE;QAC5F,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,QAAgB,EAAE,QAAsB;QACpD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,IAAY,EAAE,QAAoB;QAC5C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAW,EAAE,KAAU;QAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAA0B,QAAgB,EAAE,OAAU,EAAO;QAC5E,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc,CAAC,QAAgB,EAAE,QAAgB,EAAE,OAAY,EAAE;QAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAChE,CAAC;CACJ;AApDD,oBAoDC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare enum NodeType {
|
|
2
|
+
Root = "Root",
|
|
3
|
+
Text = "Text",
|
|
4
|
+
Expression = "Expression",
|
|
5
|
+
RawExpression = "RawExpression",
|
|
6
|
+
Directive = "Directive"
|
|
7
|
+
}
|
|
8
|
+
export interface Node {
|
|
9
|
+
type: NodeType;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface RootNode extends Node {
|
|
13
|
+
type: NodeType.Root;
|
|
14
|
+
children: Node[];
|
|
15
|
+
}
|
|
16
|
+
export interface TextNode extends Node {
|
|
17
|
+
type: NodeType.Text;
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ExpressionNode extends Node {
|
|
21
|
+
type: NodeType.Expression;
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
export interface RawExpressionNode extends Node {
|
|
25
|
+
type: NodeType.RawExpression;
|
|
26
|
+
content: string;
|
|
27
|
+
}
|
|
28
|
+
export interface DirectiveNode extends Node {
|
|
29
|
+
type: NodeType.Directive;
|
|
30
|
+
name: string;
|
|
31
|
+
expression: string | null;
|
|
32
|
+
children?: Node[];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=AST.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AST.d.ts","sourceRoot":"","sources":["../../../src/Compiler/AST.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAChB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,SAAS,cAAc;CAC1B;AAED,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI;IAClC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,QAAQ,EAAE,IAAI,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI;IAClC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAe,SAAQ,IAAI;IACxC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI;IAC3C,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,IAAI;IACvC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC;CACrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeType = void 0;
|
|
4
|
+
var NodeType;
|
|
5
|
+
(function (NodeType) {
|
|
6
|
+
NodeType["Root"] = "Root";
|
|
7
|
+
NodeType["Text"] = "Text";
|
|
8
|
+
NodeType["Expression"] = "Expression";
|
|
9
|
+
NodeType["RawExpression"] = "RawExpression";
|
|
10
|
+
NodeType["Directive"] = "Directive";
|
|
11
|
+
})(NodeType || (exports.NodeType = NodeType = {}));
|
|
12
|
+
//# sourceMappingURL=AST.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AST.js","sourceRoot":"","sources":["../../../src/Compiler/AST.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAMX;AAND,WAAY,QAAQ;IAChB,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,qCAAyB,CAAA;IACzB,2CAA+B,CAAA;IAC/B,mCAAuB,CAAA;AAC3B,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RootNode } from './AST';
|
|
2
|
+
import { DirectiveRegistry } from './DirectiveRegistry';
|
|
3
|
+
export declare class CodeGenerator {
|
|
4
|
+
private registry;
|
|
5
|
+
constructor(registry: DirectiveRegistry);
|
|
6
|
+
generate(root: RootNode): string;
|
|
7
|
+
private generateNodes;
|
|
8
|
+
private generateNode;
|
|
9
|
+
private cleanExpression;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CodeGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeGenerator.d.ts","sourceRoot":"","sources":["../../../src/Compiler/CodeGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA8E,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAoB;gBAExB,QAAQ,EAAE,iBAAiB;IAIhC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM;IAUvC,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IAiCpB,OAAO,CAAC,eAAe;CAK1B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeGenerator = void 0;
|
|
4
|
+
const AST_1 = require("./AST");
|
|
5
|
+
class CodeGenerator {
|
|
6
|
+
constructor(registry) {
|
|
7
|
+
this.registry = registry;
|
|
8
|
+
}
|
|
9
|
+
generate(root) {
|
|
10
|
+
let jsCode = 'let _output = "";\n';
|
|
11
|
+
jsCode += 'const _escape = (val) => String(val ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/\\\'/g, "'");\n';
|
|
12
|
+
jsCode += this.generateNodes(root.children);
|
|
13
|
+
jsCode += 'return _output;';
|
|
14
|
+
return jsCode;
|
|
15
|
+
}
|
|
16
|
+
generateNodes(nodes) {
|
|
17
|
+
return nodes.map(node => this.generateNode(node)).join('\n');
|
|
18
|
+
}
|
|
19
|
+
generateNode(node) {
|
|
20
|
+
switch (node.type) {
|
|
21
|
+
case AST_1.NodeType.Text:
|
|
22
|
+
const text = node.content
|
|
23
|
+
.replace(/\\/g, '\\\\')
|
|
24
|
+
.replace(/`/g, '\\`')
|
|
25
|
+
.replace(/\${/g, '\\${');
|
|
26
|
+
return `_output += \`${text}\`;`;
|
|
27
|
+
case AST_1.NodeType.Expression:
|
|
28
|
+
return `_output += _escape(${this.cleanExpression(node.content)});`;
|
|
29
|
+
case AST_1.NodeType.RawExpression:
|
|
30
|
+
return `_output += (${this.cleanExpression(node.content)});`;
|
|
31
|
+
case AST_1.NodeType.Directive:
|
|
32
|
+
const dir = node;
|
|
33
|
+
const childrenCode = dir.children ? this.generateNodes(dir.children) : '';
|
|
34
|
+
const result = this.registry.handle(dir.name, dir.expression, childrenCode);
|
|
35
|
+
if (result === null) {
|
|
36
|
+
// Fallback for unknown directives (e.g., CSS @media, @keyframes)
|
|
37
|
+
const originalText = `@${dir.name}${dir.expression ? '(' + dir.expression + ')' : ''}`;
|
|
38
|
+
const sanitized = originalText.replace(/`/g, '\\`').replace(/\${/g, '\\${');
|
|
39
|
+
return `_output += \`${sanitized}\`;\n${childrenCode}`;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
default:
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
cleanExpression(exp) {
|
|
47
|
+
// Strip leading $ from variables to support Laravel-style {{ $var }}
|
|
48
|
+
// This regex finds $ followed by an identifier and replaces it with just the identifier
|
|
49
|
+
return exp.replace(/(^|[^a-zA-Z0-9_])\$([a-zA-Z_][a-zA-Z0-9_]*)/g, '$1$2');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CodeGenerator = CodeGenerator;
|
|
53
|
+
//# sourceMappingURL=CodeGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeGenerator.js","sourceRoot":"","sources":["../../../src/Compiler/CodeGenerator.ts"],"names":[],"mappings":";;;AAAA,+BAA6G;AAG7G,MAAa,aAAa;IAGtB,YAAY,QAA2B;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAEM,QAAQ,CAAC,IAAc;QAC1B,IAAI,MAAM,GAAG,qBAAqB,CAAC;QACnC,MAAM,IAAI,oKAAoK,CAAC;QAE/K,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE5C,MAAM,IAAI,iBAAiB,CAAC;QAC5B,OAAO,MAAM,CAAC;IAClB,CAAC;IAEO,aAAa,CAAC,KAAa;QAC/B,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IAEO,YAAY,CAAC,IAAU;QAC3B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,cAAQ,CAAC,IAAI;gBACd,MAAM,IAAI,GAAI,IAAiB,CAAC,OAAO;qBAClC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;qBACtB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;qBACpB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAC7B,OAAO,gBAAgB,IAAI,KAAK,CAA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
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type DirectiveHandler = (expression: string | null, children?: string) => string;
|
|
2
|
+
export declare class DirectiveRegistry {
|
|
3
|
+
private directives;
|
|
4
|
+
constructor();
|
|
5
|
+
register(name: string, handler: DirectiveHandler): void;
|
|
6
|
+
has(name: string): boolean;
|
|
7
|
+
handle(name: string, expression: string | null, children?: string): string | null;
|
|
8
|
+
private registerDefaultDirectives;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=DirectiveRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DirectiveRegistry.d.ts","sourceRoot":"","sources":["../../../src/Compiler/DirectiveRegistry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAExF,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,UAAU,CAA4C;;IAMvD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAIvD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQxF,OAAO,CAAC,yBAAyB;CAyNpC"}
|