@kosatyi/ejs 0.0.108 → 0.0.110
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/dist/cjs/browser.js +69 -105
- package/dist/cjs/bundler.js +6 -6
- package/dist/cjs/element.js +2 -2
- package/dist/cjs/index.js +74 -102
- package/dist/cjs/worker.js +64 -99
- package/dist/esm/browser.js +75 -111
- package/dist/esm/bundler.js +6 -6
- package/dist/esm/element.js +2 -2
- package/dist/esm/index.js +80 -106
- package/dist/esm/worker.js +71 -104
- package/dist/kosatyi-ejs-0.0.109.tgz +0 -0
- package/dist/umd/browser.js +69 -105
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/element.js +3 -3
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +74 -102
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +64 -99
- package/dist/umd/worker.min.js +1 -1
- package/package.json +1 -1
- package/types/browser.d.ts +1 -3
- package/types/bundler.d.ts +1 -1
- package/types/context.d.ts +0 -6
- package/types/ejs.d.ts +3 -6
- package/types/element.d.ts +9 -1
- package/types/error.d.ts +9 -12
- package/types/global.d.ts +2 -2
- package/types/index.d.ts +1 -3
- package/types/worker.d.ts +1 -3
- package/dist/kosatyi-ejs-0.0.107.tgz +0 -0
package/dist/umd/worker.js
CHANGED
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
const symbols = string => {
|
|
97
97
|
return ('' + string).replace(symbolEntitiesMatch, match => '\\' + symbolEntities[match]);
|
|
98
98
|
};
|
|
99
|
-
const
|
|
99
|
+
const escapeValue = (value, escape) => {
|
|
100
100
|
const check = value;
|
|
101
101
|
return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
|
|
102
102
|
};
|
|
@@ -150,12 +150,26 @@
|
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
class
|
|
153
|
+
class EjsError extends Error {
|
|
154
|
+
constructor(code, content) {
|
|
155
|
+
super(content);
|
|
156
|
+
this.code = code;
|
|
157
|
+
if (content instanceof Error) {
|
|
158
|
+
this.stack = content.stack;
|
|
159
|
+
this.message = content.message;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const error = (code, content) => {
|
|
164
|
+
throw new EjsError(code, content);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
class EjsTemplate {
|
|
154
168
|
#path;
|
|
155
169
|
#resolver;
|
|
156
170
|
#cache;
|
|
157
171
|
#compiler;
|
|
158
|
-
static exports = ['configure', 'get'
|
|
172
|
+
static exports = ['configure', 'get'];
|
|
159
173
|
constructor(options, cache, compiler) {
|
|
160
174
|
bindContext(this, this.constructor.exports);
|
|
161
175
|
this.#cache = cache;
|
|
@@ -171,11 +185,11 @@
|
|
|
171
185
|
#resolve(template) {
|
|
172
186
|
const cached = this.#cache.get(template);
|
|
173
187
|
if (cached instanceof Promise) return cached;
|
|
174
|
-
const result = Promise.resolve(this.#resolver(this.#path, template));
|
|
188
|
+
const result = Promise.resolve(this.#resolver(this.#path, template, error));
|
|
175
189
|
this.#cache.set(template, result);
|
|
176
190
|
return result;
|
|
177
191
|
}
|
|
178
|
-
compile(content, template) {
|
|
192
|
+
#compile(content, template) {
|
|
179
193
|
const cached = this.#cache.get(template);
|
|
180
194
|
if (typeof cached === 'function') return cached;
|
|
181
195
|
if (typeof content === 'string') {
|
|
@@ -187,7 +201,9 @@
|
|
|
187
201
|
}
|
|
188
202
|
}
|
|
189
203
|
get(template) {
|
|
190
|
-
return this.#resolve(template).then(content =>
|
|
204
|
+
return this.#resolve(template).then(content => {
|
|
205
|
+
return this.#compile(content, template);
|
|
206
|
+
});
|
|
191
207
|
}
|
|
192
208
|
}
|
|
193
209
|
|
|
@@ -203,9 +219,9 @@
|
|
|
203
219
|
return match;
|
|
204
220
|
});
|
|
205
221
|
};
|
|
206
|
-
class
|
|
222
|
+
class EjsCompiler {
|
|
207
223
|
#config = {};
|
|
208
|
-
static exports = ['compile'];
|
|
224
|
+
static exports = ['configure', 'compile'];
|
|
209
225
|
constructor(options) {
|
|
210
226
|
bindContext(this, this.constructor.exports);
|
|
211
227
|
this.configure(options);
|
|
@@ -262,7 +278,7 @@
|
|
|
262
278
|
});
|
|
263
279
|
});
|
|
264
280
|
OUTPUT += `');`;
|
|
265
|
-
OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e
|
|
281
|
+
OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e)}`;
|
|
266
282
|
if (this.#config.strict === false) {
|
|
267
283
|
OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
|
|
268
284
|
}
|
|
@@ -284,7 +300,7 @@
|
|
|
284
300
|
}
|
|
285
301
|
}
|
|
286
302
|
|
|
287
|
-
class
|
|
303
|
+
class EjsCache {
|
|
288
304
|
static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
|
|
289
305
|
#cache = true;
|
|
290
306
|
#precompiled;
|
|
@@ -358,31 +374,13 @@
|
|
|
358
374
|
return result.join('');
|
|
359
375
|
};
|
|
360
376
|
|
|
361
|
-
class TemplateError extends Error {
|
|
362
|
-
name = 'TemplateError';
|
|
363
|
-
constructor(error) {
|
|
364
|
-
super(error);
|
|
365
|
-
if (error instanceof Error) {
|
|
366
|
-
this.stack = error.stack;
|
|
367
|
-
this.filename = error.filename;
|
|
368
|
-
this.lineno = error.lineno;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
class TemplateNotFound extends TemplateError {
|
|
373
|
-
name = 'TemplateNotFound';
|
|
374
|
-
code = 404;
|
|
375
|
-
}
|
|
376
|
-
class TemplateSyntaxError extends TemplateError {
|
|
377
|
-
name = 'TemplateSyntaxError';
|
|
378
|
-
code = 500;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
377
|
const resolve = list => {
|
|
382
|
-
return Promise.all(list || []).then(list => list.join('')).catch(e =>
|
|
378
|
+
return Promise.all(list || []).then(list => list.join('')).catch(e => {
|
|
379
|
+
return error(500, e);
|
|
380
|
+
});
|
|
383
381
|
};
|
|
384
|
-
const reject =
|
|
385
|
-
return Promise.reject(
|
|
382
|
+
const reject = e => {
|
|
383
|
+
return Promise.reject(error(500, e));
|
|
386
384
|
};
|
|
387
385
|
const EjsBuffer = () => {
|
|
388
386
|
let store = [];
|
|
@@ -407,7 +405,7 @@
|
|
|
407
405
|
array = store.pop();
|
|
408
406
|
return resolve(result);
|
|
409
407
|
};
|
|
410
|
-
EjsBuffer.error =
|
|
408
|
+
EjsBuffer.error = e => {
|
|
411
409
|
return reject(e);
|
|
412
410
|
};
|
|
413
411
|
EjsBuffer.end = () => {
|
|
@@ -436,13 +434,6 @@
|
|
|
436
434
|
this[MACRO] = {};
|
|
437
435
|
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
438
436
|
}
|
|
439
|
-
Object.entries(methods).forEach(_ref => {
|
|
440
|
-
let [name, value] = _ref;
|
|
441
|
-
if (isFunction(value) && globals.includes(name)) {
|
|
442
|
-
value = value.bind(EjsContext.prototype);
|
|
443
|
-
}
|
|
444
|
-
EjsContext.prototype[name] = value;
|
|
445
|
-
});
|
|
446
437
|
Object.defineProperty(EjsContext.prototype, BUFFER, {
|
|
447
438
|
value: EjsBuffer()
|
|
448
439
|
});
|
|
@@ -467,36 +458,31 @@
|
|
|
467
458
|
writable: true
|
|
468
459
|
});
|
|
469
460
|
Object.defineProperties(EjsContext.prototype, {
|
|
470
|
-
/** @type {function} */
|
|
471
461
|
setParentTemplate: {
|
|
472
462
|
value(value) {
|
|
473
463
|
this[PARENT] = value;
|
|
474
464
|
return this;
|
|
475
465
|
}
|
|
476
466
|
},
|
|
477
|
-
/** @type {function} */
|
|
478
467
|
getParentTemplate: {
|
|
479
468
|
value() {
|
|
480
469
|
return this[PARENT];
|
|
481
470
|
}
|
|
482
471
|
},
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
get: () => safeValue
|
|
472
|
+
useEscapeValue: {
|
|
473
|
+
get: () => escapeValue
|
|
486
474
|
},
|
|
487
|
-
/** @type {function} */
|
|
488
475
|
useComponent: {
|
|
489
476
|
get() {
|
|
490
477
|
if (isFunction(this[COMPONENT])) {
|
|
491
478
|
return this[COMPONENT].bind(this);
|
|
492
479
|
} else {
|
|
493
|
-
return ()
|
|
480
|
+
return function () {
|
|
494
481
|
throw new Error(`${COMPONENT} must be a function`);
|
|
495
482
|
};
|
|
496
483
|
}
|
|
497
484
|
}
|
|
498
485
|
},
|
|
499
|
-
/** @type {function} */
|
|
500
486
|
useElement: {
|
|
501
487
|
get() {
|
|
502
488
|
if (isFunction(this[ELEMENT])) {
|
|
@@ -508,51 +494,43 @@
|
|
|
508
494
|
}
|
|
509
495
|
}
|
|
510
496
|
},
|
|
511
|
-
/** @type {function} */
|
|
512
497
|
useBuffer: {
|
|
513
498
|
get() {
|
|
514
499
|
return this[BUFFER];
|
|
515
500
|
}
|
|
516
501
|
},
|
|
517
|
-
/** @type {function} */
|
|
518
502
|
getMacro: {
|
|
519
503
|
value() {
|
|
520
504
|
return this[MACRO];
|
|
521
505
|
}
|
|
522
506
|
},
|
|
523
|
-
/** @type {function} */
|
|
524
507
|
getBlocks: {
|
|
525
508
|
value() {
|
|
526
509
|
return this[BLOCKS];
|
|
527
510
|
}
|
|
528
511
|
},
|
|
529
|
-
/** @type {function} */
|
|
530
512
|
setExtend: {
|
|
531
513
|
value(value) {
|
|
532
514
|
this[EXTEND] = value;
|
|
533
515
|
return this;
|
|
534
516
|
}
|
|
535
517
|
},
|
|
536
|
-
/** @type {function} */
|
|
537
518
|
getExtend: {
|
|
538
519
|
value() {
|
|
539
520
|
return this[EXTEND];
|
|
540
521
|
}
|
|
541
522
|
},
|
|
542
|
-
/** @type {function} */
|
|
543
523
|
setLayout: {
|
|
544
524
|
value(layout) {
|
|
545
525
|
this[LAYOUT] = layout;
|
|
546
526
|
return this;
|
|
547
527
|
}
|
|
548
528
|
},
|
|
549
|
-
/** @type {function} */
|
|
550
529
|
getLayout: {
|
|
551
530
|
value() {
|
|
552
531
|
return this[LAYOUT];
|
|
553
532
|
}
|
|
554
533
|
},
|
|
555
|
-
/** @type {function} */
|
|
556
534
|
clone: {
|
|
557
535
|
value(exclude_blocks) {
|
|
558
536
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
@@ -562,32 +540,29 @@
|
|
|
562
540
|
return omit(this, filter);
|
|
563
541
|
}
|
|
564
542
|
},
|
|
565
|
-
/** @type {function} */
|
|
566
543
|
extend: {
|
|
567
544
|
value(layout) {
|
|
568
545
|
this.setExtend(true);
|
|
569
546
|
this.setLayout(layout);
|
|
570
547
|
}
|
|
571
548
|
},
|
|
572
|
-
/** @type {function} */
|
|
573
549
|
echo: {
|
|
574
550
|
value() {
|
|
575
551
|
return [].slice.call(arguments).forEach(this.useBuffer);
|
|
576
552
|
}
|
|
577
553
|
},
|
|
578
|
-
/** @type {function} */
|
|
579
554
|
fn: {
|
|
580
555
|
value(callback) {
|
|
581
|
-
|
|
556
|
+
const context = this;
|
|
557
|
+
return function () {
|
|
582
558
|
if (isFunction(callback)) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return
|
|
559
|
+
context.useBuffer.backup();
|
|
560
|
+
context.useBuffer(callback.apply(context, arguments));
|
|
561
|
+
return context.useBuffer.restore();
|
|
586
562
|
}
|
|
587
563
|
};
|
|
588
564
|
}
|
|
589
565
|
},
|
|
590
|
-
/** @type {function} */
|
|
591
566
|
macro: {
|
|
592
567
|
value(name, callback) {
|
|
593
568
|
const list = this.getMacro();
|
|
@@ -598,7 +573,6 @@
|
|
|
598
573
|
};
|
|
599
574
|
}
|
|
600
575
|
},
|
|
601
|
-
/** @type {function} */
|
|
602
576
|
call: {
|
|
603
577
|
value(name) {
|
|
604
578
|
const list = this.getMacro();
|
|
@@ -609,35 +583,35 @@
|
|
|
609
583
|
}
|
|
610
584
|
}
|
|
611
585
|
},
|
|
612
|
-
/** @type {function} */
|
|
613
586
|
block: {
|
|
614
587
|
value(name, callback) {
|
|
615
588
|
const blocks = this.getBlocks();
|
|
616
589
|
blocks[name] = blocks[name] || [];
|
|
617
590
|
blocks[name].push(this.fn(callback));
|
|
618
591
|
if (this.getExtend()) return;
|
|
592
|
+
const context = this;
|
|
619
593
|
const list = Object.assign([], blocks[name]);
|
|
620
|
-
const shift = ()
|
|
621
|
-
|
|
594
|
+
const shift = function () {
|
|
595
|
+
return list.shift();
|
|
596
|
+
};
|
|
597
|
+
const next = function () {
|
|
622
598
|
const parent = shift();
|
|
623
599
|
if (parent) {
|
|
624
|
-
return ()
|
|
625
|
-
|
|
600
|
+
return function () {
|
|
601
|
+
context.echo(parent(next()));
|
|
626
602
|
};
|
|
627
603
|
} else {
|
|
628
|
-
return ()
|
|
604
|
+
return function () {};
|
|
629
605
|
}
|
|
630
606
|
};
|
|
631
607
|
this.echo(shift()(next()));
|
|
632
608
|
}
|
|
633
609
|
},
|
|
634
|
-
/** @type {function} */
|
|
635
610
|
hasBlock: {
|
|
636
611
|
value(name) {
|
|
637
612
|
return this.getBlocks().hasOwnProperty(name);
|
|
638
613
|
}
|
|
639
614
|
},
|
|
640
|
-
/** @type {function} */
|
|
641
615
|
include: {
|
|
642
616
|
value(path, data, cx) {
|
|
643
617
|
const context = cx === false ? {} : this.clone(true);
|
|
@@ -646,7 +620,6 @@
|
|
|
646
620
|
this.echo(promise);
|
|
647
621
|
}
|
|
648
622
|
},
|
|
649
|
-
/** @type {function} */
|
|
650
623
|
use: {
|
|
651
624
|
value(path, namespace) {
|
|
652
625
|
this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
|
|
@@ -657,13 +630,6 @@
|
|
|
657
630
|
}));
|
|
658
631
|
}
|
|
659
632
|
},
|
|
660
|
-
/** @type {function} */
|
|
661
|
-
async: {
|
|
662
|
-
value(promise, callback) {
|
|
663
|
-
this.echo(Promise.resolve(promise).then(callback));
|
|
664
|
-
}
|
|
665
|
-
},
|
|
666
|
-
/** @type {function} */
|
|
667
633
|
get: {
|
|
668
634
|
value(name, defaults) {
|
|
669
635
|
const path = getPath(this, name, true);
|
|
@@ -672,7 +638,6 @@
|
|
|
672
638
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
673
639
|
}
|
|
674
640
|
},
|
|
675
|
-
/** @type {function} */
|
|
676
641
|
set: {
|
|
677
642
|
value(name, value) {
|
|
678
643
|
const path = getPath(this, name, false);
|
|
@@ -684,7 +649,6 @@
|
|
|
684
649
|
return result[prop] = value;
|
|
685
650
|
}
|
|
686
651
|
},
|
|
687
|
-
/** @type {function} */
|
|
688
652
|
each: {
|
|
689
653
|
value(object, callback) {
|
|
690
654
|
if (isString(object)) {
|
|
@@ -694,7 +658,6 @@
|
|
|
694
658
|
},
|
|
695
659
|
writable: true
|
|
696
660
|
},
|
|
697
|
-
/** @type {function} */
|
|
698
661
|
el: {
|
|
699
662
|
value(tag, attr, content) {
|
|
700
663
|
content = isFunction(content) ? this.fn(content)() : content;
|
|
@@ -702,15 +665,21 @@
|
|
|
702
665
|
},
|
|
703
666
|
writable: true
|
|
704
667
|
},
|
|
705
|
-
/** @type {function} */
|
|
706
668
|
ui: {
|
|
707
|
-
value(
|
|
669
|
+
value() {},
|
|
708
670
|
writable: true
|
|
709
671
|
}
|
|
710
672
|
});
|
|
673
|
+
Object.entries(methods).forEach(_ref => {
|
|
674
|
+
let [name, value] = _ref;
|
|
675
|
+
if (isFunction(value) && globals.includes(name)) {
|
|
676
|
+
value = value.bind(EjsContext.prototype);
|
|
677
|
+
}
|
|
678
|
+
EjsContext.prototype[name] = value;
|
|
679
|
+
});
|
|
711
680
|
return EjsContext;
|
|
712
681
|
};
|
|
713
|
-
class
|
|
682
|
+
class EjsContext {
|
|
714
683
|
#context;
|
|
715
684
|
static exports = ['create', 'globals', 'helpers'];
|
|
716
685
|
constructor(options, methods) {
|
|
@@ -741,10 +710,10 @@
|
|
|
741
710
|
bindContext(this, this.constructor.exports);
|
|
742
711
|
this.#methods = {};
|
|
743
712
|
this.#config = configSchema({}, options);
|
|
744
|
-
this.#context = new
|
|
745
|
-
this.#compiler = new
|
|
746
|
-
this.#cache = new
|
|
747
|
-
this.#template = new
|
|
713
|
+
this.#context = new EjsContext(this.#config, this.#methods);
|
|
714
|
+
this.#compiler = new EjsCompiler(this.#config);
|
|
715
|
+
this.#cache = new EjsCache(this.#config);
|
|
716
|
+
this.#template = new EjsTemplate(this.#config, this.#cache, this.#compiler);
|
|
748
717
|
this.helpers({
|
|
749
718
|
render: this.render,
|
|
750
719
|
require: this.require
|
|
@@ -791,7 +760,7 @@
|
|
|
791
760
|
return name;
|
|
792
761
|
}
|
|
793
762
|
#output(path, data) {
|
|
794
|
-
return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.
|
|
763
|
+
return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useEscapeValue]));
|
|
795
764
|
}
|
|
796
765
|
#renderLayout(name, params, parentTemplate) {
|
|
797
766
|
const data = this.createContext(params);
|
|
@@ -826,12 +795,11 @@
|
|
|
826
795
|
} = new EjsInstance({
|
|
827
796
|
cache: false,
|
|
828
797
|
strict: true,
|
|
829
|
-
async resolver(path, name) {
|
|
798
|
+
async resolver(path, name, error) {
|
|
830
799
|
if (isFunction(templateCache[name])) {
|
|
831
800
|
return templateCache[name];
|
|
832
|
-
} else {
|
|
833
|
-
throw new TemplateNotFound(`template ${name} not found`);
|
|
834
801
|
}
|
|
802
|
+
error(404, `template ${name} not found`);
|
|
835
803
|
}
|
|
836
804
|
});
|
|
837
805
|
|
|
@@ -874,9 +842,6 @@
|
|
|
874
842
|
};
|
|
875
843
|
}
|
|
876
844
|
|
|
877
|
-
exports.TemplateError = TemplateError;
|
|
878
|
-
exports.TemplateNotFound = TemplateNotFound;
|
|
879
|
-
exports.TemplateSyntaxError = TemplateSyntaxError;
|
|
880
845
|
exports.configure = configure;
|
|
881
846
|
exports.createContext = createContext;
|
|
882
847
|
exports.helpers = helpers;
|
package/dist/umd/worker.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejsInstance={})}(this,(function(t){"use strict";const e=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,s=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},r=t=>Array.isArray(t),i=t=>"function"==typeof t,n=t=>"string"==typeof t,o=t=>"boolean"==typeof t,c="ejsPrecompiled",a=!0,h="views",l="ejs",u=!0,p=!0,f=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),g=[],m={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},d={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},v=(t,v)=>{return Object.assign(t,{path:s(n,h,t.path,v.path),precompiled:s(n,c,t.export,v.export),resolver:s(i,f,t.resolver,v.resolver),extension:s(n,l,t.extension,v.extension),strict:s(o,p,t.strict,v.strict),rmWhitespace:s(o,u,t.rmWhitespace,v.rmWhitespace),cache:s(o,a,t.cache,v.cache),globals:s(r,g,t.globals,(b=v.globals,!!r(b)&&b.filter((t=>{const s=e.test(t);return!1===s&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),s})))),token:Object.assign({},d,t.token,v.token),vars:Object.assign({},m,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},y={"&":"&","<":"<",">":">",'"':""","'":"'"},x=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=x(y),E=x(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>y[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let r=t,n=String(e).split("."),o=n.pop();for(let t=0;t<n.length;t++){const e=n[t];if(i(r.toJSON)&&(r=r.toJSON()),s&&!1===r.hasOwnProperty(e)){r={};break}r=r[e]=r[e]||{}}return i(r.toJSON)&&(r=r.toJSON()),[r,o]},P=(t,e)=>{let s;for(s in t)C(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},C=(t,e)=>t&&Object.hasOwn(t,e),S=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,r=e.length;s<r;s++){const r=e[s];r in t&&(t[r]=t[r].bind(t))}};class T{#t;#e;#s;#r;static exports=["configure","get","compile"];constructor(t,e,s){S(this,this.constructor.exports),this.#s=e,this.#r=s,this.configure(t??{})}configure(t){this.#t=t.path,i(t.resolver)&&(this.#e=t.resolver)}#i(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t));return this.#s.set(t,s),s}compile(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#r.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#i(t).then((e=>this.compile(e,t)))}}const N=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class B{#n={};static exports=["compile"];constructor(t){S(this,this.constructor.exports),this.configure(t)}configure(t){this.#n.strict=t.strict,this.#n.rmWhitespace=t.rmWhitespace,this.#n.token=t.token,this.#n.vars=t.vars,this.#n.globals=t.globals,this.#n.legacy=t.legacy??!0,this.#n.slurp={match:"[s\t\n]*",start:[this.#n.token.start,"_"],end:["_",this.#n.token.end]},this.#n.matches=[],this.#n.formats=[];for(const[t,e]of N)this.#n.matches.push(this.#n.token.start.concat(t).concat(this.#n.token.regex).concat(this.#n.token.end)),this.#n.formats.push(e);this.#n.regex=new RegExp(this.#n.matches.join("|").concat("|$"),"g"),this.#n.slurpStart=new RegExp([this.#n.slurp.match,this.#n.slurp.start.join("")].join(""),"gm"),this.#n.slurpEnd=new RegExp([this.#n.slurp.end.join(""),this.#n.slurp.match].join(""),"gm"),this.#n.globals.length&&(this.#n.legacy?this.#n.globalVariables=`const ${this.#n.globals.map((t=>`${t}=${this.#n.vars.SCOPE}.${t}`)).join(",")};`:this.#n.globalVariables=`const {${this.#n.globals.join(",")}} = ${this.#n.vars.SCOPE};`)}compile(t,e){const s=this.#n.globalVariables,{SCOPE:r,SAFE:i,BUFFER:n,COMPONENT:o,ELEMENT:c}=this.#n.vars;this.#n.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#n.slurpStart,this.#n.token.start).replace(this.#n.slurpEnd,this.#n.token.end);let a=`${n}('`;((t,e,s)=>{let r=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),i=t.shift();return s(t,r,e),r=e+i.length,i}))})(this.#n.regex,t,((e,s,r)=>{a+=(""+t.slice(s,r)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(a+=this.#n.formats[e](t.trim(),n,i))}))})),a+="');",a=`try{${a}}catch(e){return ${n}.error(e,'${e}')}`,!1===this.#n.strict&&(a=`with(${r}){${a}}`),a=`${n}.start();${a}return ${n}.end();`,a+=`\n//# sourceURL=${e}`,s&&(a=`${s}\n${a}`);try{const t=[r,o,c,n,i],e=Function.apply(null,t.concat(a));return e.source=`(function(${t.join(",")}){\n${a}\n});`,e}catch(t){throw t.filename=e,t.source=a,t}}}class L{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#o;#c={};constructor(t){S(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#c[t]}set(t,e){this.#s&&(this.#c[t]=e)}exist(t){if(this.#s)return this.#c.hasOwnProperty(t)}clear(){Object.keys(this.#c).forEach(this.remove)}remove(t){delete this.#c[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#c,t||{})}configure(t){this.#s=t.cache,this.#o=t.precompiled,"object"==typeof window&&this.load(window[this.#o])}}const A=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],M=" ",q='"',F="/",R="<",U=">",W=t=>{let[e,s]=t;if(null!=s)return[$(e),[q,$(s),q].join("")].join("=")};class V extends Error{name="TemplateError";constructor(t){super(t),t instanceof Error&&(this.stack=t.stack,this.filename=t.filename,this.lineno=t.lineno)}}class J extends V{name="TemplateNotFound";code=404}class _ extends V{name="TemplateSyntaxError";code=500}const z=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>t)),D=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),z(s)},s.error=(t,e)=>{return s=t,Promise.reject(new _(s));var s},s.end=()=>z(e),s},K=Symbol("EjsContext.parentTemplate"),X=(t,e)=>{const{BLOCKS:s,MACRO:r,EXTEND:o,LAYOUT:c,BUFFER:a,SAFE:h,SCOPE:l,COMPONENT:u,ELEMENT:p}=t.vars,f=t.globals||[];function g(t){this[K]=null,this[s]={},this[r]={},Object.assign(this,k(t,[l,a,h,u,p]))}return Object.entries(e).forEach((t=>{let[e,s]=t;i(s)&&f.includes(e)&&(s=s.bind(g.prototype)),g.prototype[e]=s})),Object.defineProperty(g.prototype,a,{value:D()}),Object.defineProperty(g.prototype,s,{value:{},writable:!0}),Object.defineProperty(g.prototype,r,{value:{},writable:!0}),Object.defineProperty(g.prototype,c,{value:!1,writable:!0}),Object.defineProperty(g.prototype,o,{value:!1,writable:!0}),Object.defineProperty(g.prototype,K,{value:null,writable:!0}),Object.defineProperties(g.prototype,{setParentTemplate:{value(t){return this[K]=t,this}},getParentTemplate:{value(){return this[K]}},useSafeValue:{get:()=>O},useComponent:{get(){return i(this[u])?this[u].bind(this):()=>{throw new Error(`${u} must be a function`)}}},useElement:{get(){return i(this[p])?this[p].bind(this):()=>{throw new Error(`${p} must be a function`)}}},useBuffer:{get(){return this[a]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[o]=t,this}},getExtend:{value(){return this[o]}},setLayout:{value(t){return this[c]=t,this}},getLayout:{value(){return this[c]}},clone:{value(t){const e=[c,o,a];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){return()=>{if(i(t))return this.useBuffer.backup(),this.useBuffer(t.apply(this,arguments)),this.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),r=this.fn(e),i=this;s[t]=function(){return i.echo(r.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(i(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const r=Object.assign([],s[t]),i=()=>r.shift(),n=()=>{const t=i();return t?()=>{this.echo(t(n()))}:()=>{}};this.echo(i()(n()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const r=!1===s?{}:this.clone(!0),i=Object.assign(r,e||{}),n=this.render(t,i);this.echo(n)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,r)=>{s[[e,r].join(".")]=t}))})))}},async:{value(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value(t,e){const s=w(this,t,!0),r=s.shift(),i=s.pop();return C(r,i)?r[i]:e}},set:{value(t,e){const s=w(this,t,!1),r=s.shift(),i=s.pop();return this.getParentTemplate()&&C(r,i)?r[i]:r[i]=e}},each:{value(t,e){n(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=i(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const r=[],i=-1===A.indexOf(t),n=Object.entries(e??{}).map(W).filter((t=>t)).join(M);return r.push([R,t,M,n,U].join("")),s&&i&&r.push(Array.isArray(s)?s.join(""):s),i&&r.push([R,F,t,U].join("")),r.join("")})(t,e,s))))},writable:!0},ui:{value(t){},writable:!0}}),g};class Y{#a;static exports=["create","globals","helpers"];constructor(t,e){S(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#a(t)}helpers(t){Object.assign(this.#a.prototype,t)}configure(t,e){this.#a=X(t,e)}}const Z={},{render:I,createContext:G,helpers:H,configure:Q}=new class{#s;#a;#r;#h;#n={};#l={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};S(this,this.constructor.exports),this.#l={},this.#n=v({},t),this.#a=new Y(this.#n,this.#l),this.#r=new B(this.#n),this.#s=new L(this.#n),this.#h=new T(this.#n,this.#s,this.#r),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#n,t),this.#a.configure(this.#n,this.#l),this.#r.configure(this.#n),this.#s.configure(this.#n),this.#h.configure(this.#n)),this.#n}createContext(t){return this.#a.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#r.compile(t,e)}helpers(t){this.#a.helpers(Object.assign(this.#l,t))}async render(t,e){const s=this.createContext(e);return this.#u(this.#t(t),s).then(this.#p(t,s))}async require(t){const e=this.createContext({});return this.#u(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#n.extension&&(t=[t,this.#n.extension].join(".")),t}#u(t,e){return this.#h.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useSafeValue])))}#f(t,e,s){const r=this.createContext(e);return s&&r.setParentTemplate(s),this.#u(this.#t(t),r).then(this.#p(t,r))}#p(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#f(e.getLayout(),e,t)):s}}({cache:!1,strict:!0,async resolver(t,e){if(i(Z[e]))return Z[e];throw new J(`template ${e} not found`)}});function tt(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(Z,t)}t.TemplateError=V,t.TemplateNotFound=J,t.TemplateSyntaxError=_,t.configure=Q,t.createContext=G,t.helpers=H,t.render=I,t.useRenderer=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return tt(t.templates??{}),async(e,s)=>{var r,i;e.data=G({}),e.data.set("version",t.version),e.data.set("origin",(r=e.req.url,i=t.secure??!0,(r=URL.parse(r)).protocol=i?"https:":"http:",r.origin)),e.data.set("path",e.req.path),e.data.set("query",e.req.query()),e.ejs=async(t,s)=>I(t,Object.assign({param:e.req.param()},e.data,s)),e.helpers=t=>H(t),e.render=async(t,s)=>e.html(e.ejs(t,s)),await s()}},t.useTemplates=tt}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejsInstance={})}(this,(function(t){"use strict";const e=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,s=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},r=t=>Array.isArray(t),i=t=>"function"==typeof t,n=t=>"string"==typeof t,o=t=>"boolean"==typeof t,c="ejsPrecompiled",h=!0,a="views",l="ejs",u=!0,p=!0,f=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),g=[],d={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},m={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},v=(t,v)=>{return Object.assign(t,{path:s(n,a,t.path,v.path),precompiled:s(n,c,t.export,v.export),resolver:s(i,f,t.resolver,v.resolver),extension:s(n,l,t.extension,v.extension),strict:s(o,p,t.strict,v.strict),rmWhitespace:s(o,u,t.rmWhitespace,v.rmWhitespace),cache:s(o,h,t.cache,v.cache),globals:s(r,g,t.globals,(b=v.globals,!!r(b)&&b.filter((t=>{const s=e.test(t);return!1===s&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),s})))),token:Object.assign({},m,t.token,v.token),vars:Object.assign({},d,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},y={"&":"&","<":"<",">":">",'"':""","'":"'"},x=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=x(y),E=x(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>y[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let r=t,n=String(e).split("."),o=n.pop();for(let t=0;t<n.length;t++){const e=n[t];if(i(r.toJSON)&&(r=r.toJSON()),s&&!1===r.hasOwnProperty(e)){r={};break}r=r[e]=r[e]||{}}return i(r.toJSON)&&(r=r.toJSON()),[r,o]},P=(t,e)=>{let s;for(s in t)C(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},C=(t,e)=>t&&Object.hasOwn(t,e),S=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,r=e.length;s<r;s++){const r=e[s];r in t&&(t[r]=t[r].bind(t))}};class T extends Error{constructor(t,e){super(e),this.code=t,e instanceof Error&&(this.stack=e.stack,this.message=e.message)}}const B=(t,e)=>{throw new T(t,e)};class L{#t;#e;#s;#r;static exports=["configure","get"];constructor(t,e,s){S(this,this.constructor.exports),this.#s=e,this.#r=s,this.configure(t??{})}configure(t){this.#t=t.path,i(t.resolver)&&(this.#e=t.resolver)}#i(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t,B));return this.#s.set(t,s),s}#n(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#r.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#i(t).then((e=>this.#n(e,t)))}}const N=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class A{#o={};static exports=["configure","compile"];constructor(t){S(this,this.constructor.exports),this.configure(t)}configure(t){this.#o.strict=t.strict,this.#o.rmWhitespace=t.rmWhitespace,this.#o.token=t.token,this.#o.vars=t.vars,this.#o.globals=t.globals,this.#o.legacy=t.legacy??!0,this.#o.slurp={match:"[s\t\n]*",start:[this.#o.token.start,"_"],end:["_",this.#o.token.end]},this.#o.matches=[],this.#o.formats=[];for(const[t,e]of N)this.#o.matches.push(this.#o.token.start.concat(t).concat(this.#o.token.regex).concat(this.#o.token.end)),this.#o.formats.push(e);this.#o.regex=new RegExp(this.#o.matches.join("|").concat("|$"),"g"),this.#o.slurpStart=new RegExp([this.#o.slurp.match,this.#o.slurp.start.join("")].join(""),"gm"),this.#o.slurpEnd=new RegExp([this.#o.slurp.end.join(""),this.#o.slurp.match].join(""),"gm"),this.#o.globals.length&&(this.#o.legacy?this.#o.globalVariables=`const ${this.#o.globals.map((t=>`${t}=${this.#o.vars.SCOPE}.${t}`)).join(",")};`:this.#o.globalVariables=`const {${this.#o.globals.join(",")}} = ${this.#o.vars.SCOPE};`)}compile(t,e){const s=this.#o.globalVariables,{SCOPE:r,SAFE:i,BUFFER:n,COMPONENT:o,ELEMENT:c}=this.#o.vars;this.#o.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#o.slurpStart,this.#o.token.start).replace(this.#o.slurpEnd,this.#o.token.end);let h=`${n}('`;((t,e,s)=>{let r=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),i=t.shift();return s(t,r,e),r=e+i.length,i}))})(this.#o.regex,t,((e,s,r)=>{h+=(""+t.slice(s,r)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#o.formats[e](t.trim(),n,i))}))})),h+="');",h=`try{${h}}catch(e){return ${n}.error(e)}`,!1===this.#o.strict&&(h=`with(${r}){${h}}`),h=`${n}.start();${h}return ${n}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[r,o,c,n,i],e=Function.apply(null,t.concat(h));return e.source=`(function(${t.join(",")}){\n${h}\n});`,e}catch(t){throw t.filename=e,t.source=h,t}}}class M{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#c;#h={};constructor(t){S(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#h[t]}set(t,e){this.#s&&(this.#h[t]=e)}exist(t){if(this.#s)return this.#h.hasOwnProperty(t)}clear(){Object.keys(this.#h).forEach(this.remove)}remove(t){delete this.#h[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#h,t||{})}configure(t){this.#s=t.cache,this.#c=t.precompiled,"object"==typeof window&&this.load(window[this.#c])}}const q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],R=" ",F='"',U="/",W="<",V=">",J=t=>{let[e,s]=t;if(null!=s)return[$(e),[F,$(s),F].join("")].join("=")},_=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>B(500,t))),z=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),_(s)},s.error=t=>(t=>Promise.reject(B(500,t)))(t),s.end=()=>_(e),s},D=Symbol("EjsContext.parentTemplate"),K=(t,e)=>{const{BLOCKS:s,MACRO:r,EXTEND:o,LAYOUT:c,BUFFER:h,SAFE:a,SCOPE:l,COMPONENT:u,ELEMENT:p}=t.vars,f=t.globals||[];function g(t){this[D]=null,this[s]={},this[r]={},Object.assign(this,k(t,[l,h,a,u,p]))}return Object.defineProperty(g.prototype,h,{value:z()}),Object.defineProperty(g.prototype,s,{value:{},writable:!0}),Object.defineProperty(g.prototype,r,{value:{},writable:!0}),Object.defineProperty(g.prototype,c,{value:!1,writable:!0}),Object.defineProperty(g.prototype,o,{value:!1,writable:!0}),Object.defineProperty(g.prototype,D,{value:null,writable:!0}),Object.defineProperties(g.prototype,{setParentTemplate:{value(t){return this[D]=t,this}},getParentTemplate:{value(){return this[D]}},useEscapeValue:{get:()=>O},useComponent:{get(){return i(this[u])?this[u].bind(this):function(){throw new Error(`${u} must be a function`)}}},useElement:{get(){return i(this[p])?this[p].bind(this):()=>{throw new Error(`${p} must be a function`)}}},useBuffer:{get(){return this[h]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[o]=t,this}},getExtend:{value(){return this[o]}},setLayout:{value(t){return this[c]=t,this}},getLayout:{value(){return this[c]}},clone:{value(t){const e=[c,o,h];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){const e=this;return function(){if(i(t))return e.useBuffer.backup(),e.useBuffer(t.apply(e,arguments)),e.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),r=this.fn(e),i=this;s[t]=function(){return i.echo(r.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(i(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const r=this,i=Object.assign([],s[t]),n=function(){return i.shift()},o=function(){const t=n();return t?function(){r.echo(t(o()))}:function(){}};this.echo(n()(o()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const r=!1===s?{}:this.clone(!0),i=Object.assign(r,e||{}),n=this.render(t,i);this.echo(n)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,r)=>{s[[e,r].join(".")]=t}))})))}},get:{value(t,e){const s=w(this,t,!0),r=s.shift(),i=s.pop();return C(r,i)?r[i]:e}},set:{value(t,e){const s=w(this,t,!1),r=s.shift(),i=s.pop();return this.getParentTemplate()&&C(r,i)?r[i]:r[i]=e}},each:{value(t,e){n(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=i(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const r=[],i=-1===q.indexOf(t),n=Object.entries(e??{}).map(J).filter((t=>t)).join(R);return r.push([W,t,R,n,V].join("")),s&&i&&r.push(Array.isArray(s)?s.join(""):s),i&&r.push([W,U,t,V].join("")),r.join("")})(t,e,s))))},writable:!0},ui:{value(){},writable:!0}}),Object.entries(e).forEach((t=>{let[e,s]=t;i(s)&&f.includes(e)&&(s=s.bind(g.prototype)),g.prototype[e]=s})),g};class X{#a;static exports=["create","globals","helpers"];constructor(t,e){S(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#a(t)}helpers(t){Object.assign(this.#a.prototype,t)}configure(t,e){this.#a=K(t,e)}}const Y={},{render:Z,createContext:I,helpers:G,configure:H}=new class{#s;#a;#r;#l;#o={};#u={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};S(this,this.constructor.exports),this.#u={},this.#o=v({},t),this.#a=new X(this.#o,this.#u),this.#r=new A(this.#o),this.#s=new M(this.#o),this.#l=new L(this.#o,this.#s,this.#r),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#o,t),this.#a.configure(this.#o,this.#u),this.#r.configure(this.#o),this.#s.configure(this.#o),this.#l.configure(this.#o)),this.#o}createContext(t){return this.#a.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#r.compile(t,e)}helpers(t){this.#a.helpers(Object.assign(this.#u,t))}async render(t,e){const s=this.createContext(e);return this.#p(this.#t(t),s).then(this.#f(t,s))}async require(t){const e=this.createContext({});return this.#p(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#o.extension&&(t=[t,this.#o.extension].join(".")),t}#p(t,e){return this.#l.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useEscapeValue])))}#g(t,e,s){const r=this.createContext(e);return s&&r.setParentTemplate(s),this.#p(this.#t(t),r).then(this.#f(t,r))}#f(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#g(e.getLayout(),e,t)):s}}({cache:!1,strict:!0,async resolver(t,e,s){if(i(Y[e]))return Y[e];s(404,`template ${e} not found`)}});function Q(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(Y,t)}t.configure=H,t.createContext=I,t.helpers=G,t.render=Z,t.useRenderer=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Q(t.templates??{}),async(e,s)=>{var r,i;e.data=I({}),e.data.set("version",t.version),e.data.set("origin",(r=e.req.url,i=t.secure??!0,(r=URL.parse(r)).protocol=i?"https:":"http:",r.origin)),e.data.set("path",e.req.path),e.data.set("query",e.req.query()),e.ejs=async(t,s)=>Z(t,Object.assign({param:e.req.param()},e.data,s)),e.helpers=t=>G(t),e.render=async(t,s)=>e.html(e.ejs(t,s)),await s()}},t.useTemplates=Q}));
|
package/package.json
CHANGED
package/types/browser.d.ts
CHANGED
package/types/bundler.d.ts
CHANGED
package/types/context.d.ts
CHANGED
|
@@ -67,12 +67,6 @@ export interface EjsContext {
|
|
|
67
67
|
* @param callback
|
|
68
68
|
*/
|
|
69
69
|
call(name: string, props?: object, callback?: any): any
|
|
70
|
-
/**
|
|
71
|
-
* asynchronous template execution
|
|
72
|
-
* @param promise
|
|
73
|
-
* @param callback
|
|
74
|
-
*/
|
|
75
|
-
async(promise: Promise<any>, callback?: any): any
|
|
76
70
|
/**
|
|
77
71
|
* buffer output
|
|
78
72
|
* @param args
|
package/types/ejs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EjsContext } from './context'
|
|
2
|
-
import {
|
|
1
|
+
import { EjsContext } from './context.js'
|
|
2
|
+
import { EjsError, error } from './error.js'
|
|
3
3
|
|
|
4
4
|
export declare type EjsConfigVars = {
|
|
5
5
|
SCOPE: string
|
|
@@ -61,10 +61,7 @@ export declare type EjsConfig = {
|
|
|
61
61
|
* - For client templates using window.fetch
|
|
62
62
|
* - For worker templates using precompiled Map of templates
|
|
63
63
|
*/
|
|
64
|
-
resolver?: (
|
|
65
|
-
path: string,
|
|
66
|
-
template: string,
|
|
67
|
-
) => Promise<string | TemplateError>
|
|
64
|
+
resolver?: (path: string, template: string, error: error) => Promise<string>
|
|
68
65
|
/**
|
|
69
66
|
* An array of local variables that are always destructured from helpers
|
|
70
67
|
* available even in strict mode.
|
package/types/element.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function escapeValue(value: string, escape?: boolean): string | any
|
|
2
2
|
|
|
3
3
|
export function element(
|
|
4
4
|
tag: string,
|
|
@@ -7,3 +7,11 @@ export function element(
|
|
|
7
7
|
},
|
|
8
8
|
content?: string[] | string,
|
|
9
9
|
): string
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
export interface ejsElement extends Window {
|
|
13
|
+
element: typeof element
|
|
14
|
+
escapeValue: typeof escapeValue
|
|
15
|
+
}
|
|
16
|
+
const ejsElement: ejsElement
|
|
17
|
+
}
|
package/types/error.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
code
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export interface EjsError<N, C> {
|
|
2
|
+
code: N
|
|
3
|
+
content: C;
|
|
4
|
+
(code: N, content: C): EjsError<N, C>
|
|
5
|
+
toString(): C
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
code:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export class TemplateSyntaxError extends TemplateError {
|
|
13
|
-
code: 500
|
|
14
|
-
}
|
|
8
|
+
export type error = <N, C extends string | Error>(
|
|
9
|
+
code: N,
|
|
10
|
+
content: C,
|
|
11
|
+
) => EjsError<N, C>
|
package/types/global.d.ts
CHANGED
package/types/index.d.ts
CHANGED
package/types/worker.d.ts
CHANGED
|
Binary file
|