@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/browser.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
|
};
|
|
@@ -155,12 +155,26 @@
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
class
|
|
158
|
+
class EjsError extends Error {
|
|
159
|
+
constructor(code, content) {
|
|
160
|
+
super(content);
|
|
161
|
+
this.code = code;
|
|
162
|
+
if (content instanceof Error) {
|
|
163
|
+
this.stack = content.stack;
|
|
164
|
+
this.message = content.message;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const error = (code, content) => {
|
|
169
|
+
throw new EjsError(code, content);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
class EjsTemplate {
|
|
159
173
|
#path;
|
|
160
174
|
#resolver;
|
|
161
175
|
#cache;
|
|
162
176
|
#compiler;
|
|
163
|
-
static exports = ['configure', 'get'
|
|
177
|
+
static exports = ['configure', 'get'];
|
|
164
178
|
constructor(options, cache, compiler) {
|
|
165
179
|
bindContext(this, this.constructor.exports);
|
|
166
180
|
this.#cache = cache;
|
|
@@ -176,11 +190,11 @@
|
|
|
176
190
|
#resolve(template) {
|
|
177
191
|
const cached = this.#cache.get(template);
|
|
178
192
|
if (cached instanceof Promise) return cached;
|
|
179
|
-
const result = Promise.resolve(this.#resolver(this.#path, template));
|
|
193
|
+
const result = Promise.resolve(this.#resolver(this.#path, template, error));
|
|
180
194
|
this.#cache.set(template, result);
|
|
181
195
|
return result;
|
|
182
196
|
}
|
|
183
|
-
compile(content, template) {
|
|
197
|
+
#compile(content, template) {
|
|
184
198
|
const cached = this.#cache.get(template);
|
|
185
199
|
if (typeof cached === 'function') return cached;
|
|
186
200
|
if (typeof content === 'string') {
|
|
@@ -192,7 +206,9 @@
|
|
|
192
206
|
}
|
|
193
207
|
}
|
|
194
208
|
get(template) {
|
|
195
|
-
return this.#resolve(template).then(content =>
|
|
209
|
+
return this.#resolve(template).then(content => {
|
|
210
|
+
return this.#compile(content, template);
|
|
211
|
+
});
|
|
196
212
|
}
|
|
197
213
|
}
|
|
198
214
|
|
|
@@ -208,9 +224,9 @@
|
|
|
208
224
|
return match;
|
|
209
225
|
});
|
|
210
226
|
};
|
|
211
|
-
class
|
|
227
|
+
class EjsCompiler {
|
|
212
228
|
#config = {};
|
|
213
|
-
static exports = ['compile'];
|
|
229
|
+
static exports = ['configure', 'compile'];
|
|
214
230
|
constructor(options) {
|
|
215
231
|
bindContext(this, this.constructor.exports);
|
|
216
232
|
this.configure(options);
|
|
@@ -267,7 +283,7 @@
|
|
|
267
283
|
});
|
|
268
284
|
});
|
|
269
285
|
OUTPUT += `');`;
|
|
270
|
-
OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e
|
|
286
|
+
OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e)}`;
|
|
271
287
|
if (this.#config.strict === false) {
|
|
272
288
|
OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
|
|
273
289
|
}
|
|
@@ -289,7 +305,7 @@
|
|
|
289
305
|
}
|
|
290
306
|
}
|
|
291
307
|
|
|
292
|
-
class
|
|
308
|
+
class EjsCache {
|
|
293
309
|
static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
|
|
294
310
|
#cache = true;
|
|
295
311
|
#precompiled;
|
|
@@ -363,31 +379,13 @@
|
|
|
363
379
|
return result.join('');
|
|
364
380
|
};
|
|
365
381
|
|
|
366
|
-
class TemplateError extends Error {
|
|
367
|
-
name = 'TemplateError';
|
|
368
|
-
constructor(error) {
|
|
369
|
-
super(error);
|
|
370
|
-
if (error instanceof Error) {
|
|
371
|
-
this.stack = error.stack;
|
|
372
|
-
this.filename = error.filename;
|
|
373
|
-
this.lineno = error.lineno;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
class TemplateNotFound extends TemplateError {
|
|
378
|
-
name = 'TemplateNotFound';
|
|
379
|
-
code = 404;
|
|
380
|
-
}
|
|
381
|
-
class TemplateSyntaxError extends TemplateError {
|
|
382
|
-
name = 'TemplateSyntaxError';
|
|
383
|
-
code = 500;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
382
|
const resolve = list => {
|
|
387
|
-
return Promise.all(list || []).then(list => list.join('')).catch(e =>
|
|
383
|
+
return Promise.all(list || []).then(list => list.join('')).catch(e => {
|
|
384
|
+
return error(500, e);
|
|
385
|
+
});
|
|
388
386
|
};
|
|
389
|
-
const reject =
|
|
390
|
-
return Promise.reject(
|
|
387
|
+
const reject = e => {
|
|
388
|
+
return Promise.reject(error(500, e));
|
|
391
389
|
};
|
|
392
390
|
const EjsBuffer = () => {
|
|
393
391
|
let store = [];
|
|
@@ -412,7 +410,7 @@
|
|
|
412
410
|
array = store.pop();
|
|
413
411
|
return resolve(result);
|
|
414
412
|
};
|
|
415
|
-
EjsBuffer.error =
|
|
413
|
+
EjsBuffer.error = e => {
|
|
416
414
|
return reject(e);
|
|
417
415
|
};
|
|
418
416
|
EjsBuffer.end = () => {
|
|
@@ -441,13 +439,6 @@
|
|
|
441
439
|
this[MACRO] = {};
|
|
442
440
|
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
443
441
|
}
|
|
444
|
-
Object.entries(methods).forEach(_ref => {
|
|
445
|
-
let [name, value] = _ref;
|
|
446
|
-
if (isFunction(value) && globals.includes(name)) {
|
|
447
|
-
value = value.bind(EjsContext.prototype);
|
|
448
|
-
}
|
|
449
|
-
EjsContext.prototype[name] = value;
|
|
450
|
-
});
|
|
451
442
|
Object.defineProperty(EjsContext.prototype, BUFFER, {
|
|
452
443
|
value: EjsBuffer()
|
|
453
444
|
});
|
|
@@ -472,36 +463,31 @@
|
|
|
472
463
|
writable: true
|
|
473
464
|
});
|
|
474
465
|
Object.defineProperties(EjsContext.prototype, {
|
|
475
|
-
/** @type {function} */
|
|
476
466
|
setParentTemplate: {
|
|
477
467
|
value(value) {
|
|
478
468
|
this[PARENT] = value;
|
|
479
469
|
return this;
|
|
480
470
|
}
|
|
481
471
|
},
|
|
482
|
-
/** @type {function} */
|
|
483
472
|
getParentTemplate: {
|
|
484
473
|
value() {
|
|
485
474
|
return this[PARENT];
|
|
486
475
|
}
|
|
487
476
|
},
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
get: () => safeValue
|
|
477
|
+
useEscapeValue: {
|
|
478
|
+
get: () => escapeValue
|
|
491
479
|
},
|
|
492
|
-
/** @type {function} */
|
|
493
480
|
useComponent: {
|
|
494
481
|
get() {
|
|
495
482
|
if (isFunction(this[COMPONENT])) {
|
|
496
483
|
return this[COMPONENT].bind(this);
|
|
497
484
|
} else {
|
|
498
|
-
return ()
|
|
485
|
+
return function () {
|
|
499
486
|
throw new Error(`${COMPONENT} must be a function`);
|
|
500
487
|
};
|
|
501
488
|
}
|
|
502
489
|
}
|
|
503
490
|
},
|
|
504
|
-
/** @type {function} */
|
|
505
491
|
useElement: {
|
|
506
492
|
get() {
|
|
507
493
|
if (isFunction(this[ELEMENT])) {
|
|
@@ -513,51 +499,43 @@
|
|
|
513
499
|
}
|
|
514
500
|
}
|
|
515
501
|
},
|
|
516
|
-
/** @type {function} */
|
|
517
502
|
useBuffer: {
|
|
518
503
|
get() {
|
|
519
504
|
return this[BUFFER];
|
|
520
505
|
}
|
|
521
506
|
},
|
|
522
|
-
/** @type {function} */
|
|
523
507
|
getMacro: {
|
|
524
508
|
value() {
|
|
525
509
|
return this[MACRO];
|
|
526
510
|
}
|
|
527
511
|
},
|
|
528
|
-
/** @type {function} */
|
|
529
512
|
getBlocks: {
|
|
530
513
|
value() {
|
|
531
514
|
return this[BLOCKS];
|
|
532
515
|
}
|
|
533
516
|
},
|
|
534
|
-
/** @type {function} */
|
|
535
517
|
setExtend: {
|
|
536
518
|
value(value) {
|
|
537
519
|
this[EXTEND] = value;
|
|
538
520
|
return this;
|
|
539
521
|
}
|
|
540
522
|
},
|
|
541
|
-
/** @type {function} */
|
|
542
523
|
getExtend: {
|
|
543
524
|
value() {
|
|
544
525
|
return this[EXTEND];
|
|
545
526
|
}
|
|
546
527
|
},
|
|
547
|
-
/** @type {function} */
|
|
548
528
|
setLayout: {
|
|
549
529
|
value(layout) {
|
|
550
530
|
this[LAYOUT] = layout;
|
|
551
531
|
return this;
|
|
552
532
|
}
|
|
553
533
|
},
|
|
554
|
-
/** @type {function} */
|
|
555
534
|
getLayout: {
|
|
556
535
|
value() {
|
|
557
536
|
return this[LAYOUT];
|
|
558
537
|
}
|
|
559
538
|
},
|
|
560
|
-
/** @type {function} */
|
|
561
539
|
clone: {
|
|
562
540
|
value(exclude_blocks) {
|
|
563
541
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
@@ -567,32 +545,29 @@
|
|
|
567
545
|
return omit(this, filter);
|
|
568
546
|
}
|
|
569
547
|
},
|
|
570
|
-
/** @type {function} */
|
|
571
548
|
extend: {
|
|
572
549
|
value(layout) {
|
|
573
550
|
this.setExtend(true);
|
|
574
551
|
this.setLayout(layout);
|
|
575
552
|
}
|
|
576
553
|
},
|
|
577
|
-
/** @type {function} */
|
|
578
554
|
echo: {
|
|
579
555
|
value() {
|
|
580
556
|
return [].slice.call(arguments).forEach(this.useBuffer);
|
|
581
557
|
}
|
|
582
558
|
},
|
|
583
|
-
/** @type {function} */
|
|
584
559
|
fn: {
|
|
585
560
|
value(callback) {
|
|
586
|
-
|
|
561
|
+
const context = this;
|
|
562
|
+
return function () {
|
|
587
563
|
if (isFunction(callback)) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return
|
|
564
|
+
context.useBuffer.backup();
|
|
565
|
+
context.useBuffer(callback.apply(context, arguments));
|
|
566
|
+
return context.useBuffer.restore();
|
|
591
567
|
}
|
|
592
568
|
};
|
|
593
569
|
}
|
|
594
570
|
},
|
|
595
|
-
/** @type {function} */
|
|
596
571
|
macro: {
|
|
597
572
|
value(name, callback) {
|
|
598
573
|
const list = this.getMacro();
|
|
@@ -603,7 +578,6 @@
|
|
|
603
578
|
};
|
|
604
579
|
}
|
|
605
580
|
},
|
|
606
|
-
/** @type {function} */
|
|
607
581
|
call: {
|
|
608
582
|
value(name) {
|
|
609
583
|
const list = this.getMacro();
|
|
@@ -614,35 +588,35 @@
|
|
|
614
588
|
}
|
|
615
589
|
}
|
|
616
590
|
},
|
|
617
|
-
/** @type {function} */
|
|
618
591
|
block: {
|
|
619
592
|
value(name, callback) {
|
|
620
593
|
const blocks = this.getBlocks();
|
|
621
594
|
blocks[name] = blocks[name] || [];
|
|
622
595
|
blocks[name].push(this.fn(callback));
|
|
623
596
|
if (this.getExtend()) return;
|
|
597
|
+
const context = this;
|
|
624
598
|
const list = Object.assign([], blocks[name]);
|
|
625
|
-
const shift = ()
|
|
626
|
-
|
|
599
|
+
const shift = function () {
|
|
600
|
+
return list.shift();
|
|
601
|
+
};
|
|
602
|
+
const next = function () {
|
|
627
603
|
const parent = shift();
|
|
628
604
|
if (parent) {
|
|
629
|
-
return ()
|
|
630
|
-
|
|
605
|
+
return function () {
|
|
606
|
+
context.echo(parent(next()));
|
|
631
607
|
};
|
|
632
608
|
} else {
|
|
633
|
-
return ()
|
|
609
|
+
return function () {};
|
|
634
610
|
}
|
|
635
611
|
};
|
|
636
612
|
this.echo(shift()(next()));
|
|
637
613
|
}
|
|
638
614
|
},
|
|
639
|
-
/** @type {function} */
|
|
640
615
|
hasBlock: {
|
|
641
616
|
value(name) {
|
|
642
617
|
return this.getBlocks().hasOwnProperty(name);
|
|
643
618
|
}
|
|
644
619
|
},
|
|
645
|
-
/** @type {function} */
|
|
646
620
|
include: {
|
|
647
621
|
value(path, data, cx) {
|
|
648
622
|
const context = cx === false ? {} : this.clone(true);
|
|
@@ -651,7 +625,6 @@
|
|
|
651
625
|
this.echo(promise);
|
|
652
626
|
}
|
|
653
627
|
},
|
|
654
|
-
/** @type {function} */
|
|
655
628
|
use: {
|
|
656
629
|
value(path, namespace) {
|
|
657
630
|
this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
|
|
@@ -662,13 +635,6 @@
|
|
|
662
635
|
}));
|
|
663
636
|
}
|
|
664
637
|
},
|
|
665
|
-
/** @type {function} */
|
|
666
|
-
async: {
|
|
667
|
-
value(promise, callback) {
|
|
668
|
-
this.echo(Promise.resolve(promise).then(callback));
|
|
669
|
-
}
|
|
670
|
-
},
|
|
671
|
-
/** @type {function} */
|
|
672
638
|
get: {
|
|
673
639
|
value(name, defaults) {
|
|
674
640
|
const path = getPath(this, name, true);
|
|
@@ -677,7 +643,6 @@
|
|
|
677
643
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
678
644
|
}
|
|
679
645
|
},
|
|
680
|
-
/** @type {function} */
|
|
681
646
|
set: {
|
|
682
647
|
value(name, value) {
|
|
683
648
|
const path = getPath(this, name, false);
|
|
@@ -689,7 +654,6 @@
|
|
|
689
654
|
return result[prop] = value;
|
|
690
655
|
}
|
|
691
656
|
},
|
|
692
|
-
/** @type {function} */
|
|
693
657
|
each: {
|
|
694
658
|
value(object, callback) {
|
|
695
659
|
if (isString(object)) {
|
|
@@ -699,7 +663,6 @@
|
|
|
699
663
|
},
|
|
700
664
|
writable: true
|
|
701
665
|
},
|
|
702
|
-
/** @type {function} */
|
|
703
666
|
el: {
|
|
704
667
|
value(tag, attr, content) {
|
|
705
668
|
content = isFunction(content) ? this.fn(content)() : content;
|
|
@@ -707,15 +670,21 @@
|
|
|
707
670
|
},
|
|
708
671
|
writable: true
|
|
709
672
|
},
|
|
710
|
-
/** @type {function} */
|
|
711
673
|
ui: {
|
|
712
|
-
value(
|
|
674
|
+
value() {},
|
|
713
675
|
writable: true
|
|
714
676
|
}
|
|
715
677
|
});
|
|
678
|
+
Object.entries(methods).forEach(_ref => {
|
|
679
|
+
let [name, value] = _ref;
|
|
680
|
+
if (isFunction(value) && globals.includes(name)) {
|
|
681
|
+
value = value.bind(EjsContext.prototype);
|
|
682
|
+
}
|
|
683
|
+
EjsContext.prototype[name] = value;
|
|
684
|
+
});
|
|
716
685
|
return EjsContext;
|
|
717
686
|
};
|
|
718
|
-
class
|
|
687
|
+
class EjsContext {
|
|
719
688
|
#context;
|
|
720
689
|
static exports = ['create', 'globals', 'helpers'];
|
|
721
690
|
constructor(options, methods) {
|
|
@@ -746,10 +715,10 @@
|
|
|
746
715
|
bindContext(this, this.constructor.exports);
|
|
747
716
|
this.#methods = {};
|
|
748
717
|
this.#config = configSchema({}, options);
|
|
749
|
-
this.#context = new
|
|
750
|
-
this.#compiler = new
|
|
751
|
-
this.#cache = new
|
|
752
|
-
this.#template = new
|
|
718
|
+
this.#context = new EjsContext(this.#config, this.#methods);
|
|
719
|
+
this.#compiler = new EjsCompiler(this.#config);
|
|
720
|
+
this.#cache = new EjsCache(this.#config);
|
|
721
|
+
this.#template = new EjsTemplate(this.#config, this.#cache, this.#compiler);
|
|
753
722
|
this.helpers({
|
|
754
723
|
render: this.render,
|
|
755
724
|
require: this.require
|
|
@@ -796,7 +765,7 @@
|
|
|
796
765
|
return name;
|
|
797
766
|
}
|
|
798
767
|
#output(path, data) {
|
|
799
|
-
return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.
|
|
768
|
+
return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useEscapeValue]));
|
|
800
769
|
}
|
|
801
770
|
#renderLayout(name, params, parentTemplate) {
|
|
802
771
|
const data = this.createContext(params);
|
|
@@ -814,30 +783,25 @@
|
|
|
814
783
|
}
|
|
815
784
|
}
|
|
816
785
|
|
|
817
|
-
const httpRequest = (path, template) => {
|
|
786
|
+
const httpRequest = (path, template, error) => {
|
|
818
787
|
return fetch(joinPath(path, template)).then(response => {
|
|
819
788
|
if (response.ok) return response.text();
|
|
820
|
-
|
|
821
|
-
}, reason =>
|
|
822
|
-
return new TemplateError(reason);
|
|
823
|
-
});
|
|
789
|
+
return error(404, `template ${template} not found`);
|
|
790
|
+
}, reason => error(500, reason));
|
|
824
791
|
};
|
|
825
792
|
|
|
826
793
|
const {
|
|
827
794
|
render,
|
|
795
|
+
configure,
|
|
796
|
+
create,
|
|
797
|
+
helpers,
|
|
828
798
|
createContext,
|
|
829
799
|
compile,
|
|
830
|
-
|
|
831
|
-
preload,
|
|
832
|
-
configure,
|
|
833
|
-
create
|
|
800
|
+
preload
|
|
834
801
|
} = new EjsInstance({
|
|
835
802
|
resolver: httpRequest
|
|
836
803
|
});
|
|
837
804
|
|
|
838
|
-
exports.TemplateError = TemplateError;
|
|
839
|
-
exports.TemplateNotFound = TemplateNotFound;
|
|
840
|
-
exports.TemplateSyntaxError = TemplateSyntaxError;
|
|
841
805
|
exports.compile = compile;
|
|
842
806
|
exports.configure = configure;
|
|
843
807
|
exports.create = create;
|
package/dist/umd/browser.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="ejsPrecompiled",s=!0,r="views",i="ejs",o=!0,n=!0,c=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),h=[],a={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},l={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},u=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,p=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},f=t=>Array.isArray(t),g=t=>"function"==typeof t,m=t=>"string"==typeof t,d=t=>"boolean"==typeof t,v=(t,v)=>{return Object.assign(t,{path:p(m,r,t.path,v.path),precompiled:p(m,e,t.export,v.export),resolver:p(g,c,t.resolver,v.resolver),extension:p(m,i,t.extension,v.extension),strict:p(d,n,t.strict,v.strict),rmWhitespace:p(d,o,t.rmWhitespace,v.rmWhitespace),cache:p(d,s,t.cache,v.cache),globals:p(f,h,t.globals,(b=v.globals,!!f(b)&&b.filter((t=>{const e=u.test(t);return!1===e&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),e})))),token:Object.assign({},l,t.token,v.token),vars:Object.assign({},a,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},x={"&":"&","<":"<",">":">",'"':""","'":"'"},y=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),E=y(x),$=y(b),j=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(E,(t=>x[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?j(s):s},w=(t,e,s)=>{let r=t,i=String(e).split("."),o=i.pop();for(let t=0;t<i.length;t++){const e=i[t];if(g(r.toJSON)&&(r=r.toJSON()),s&&!1===r.hasOwnProperty(e)){r={};break}r=r[e]=r[e]||{}}return g(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,g(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{#o={};static exports=["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:o,COMPONENT:n,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=`${o}('`;((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($,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#o.formats[e](t.trim(),o,i))}))})),h+="');",h=`try{${h}}catch(e){return ${o}.error(e,'${e}')}`,!1===this.#o.strict&&(h=`with(${r}){${h}}`),h=`${o}.start();${h}return ${o}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[r,n,c,o,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 L{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#n;#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.#n=t.precompiled,"object"==typeof window&&this.load(window[this.#n])}}const A=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],M=" ",F='"',R="/",q="<",U=">",W=t=>{let[e,s]=t;if(null!=s)return[j(e),[F,j(s),F].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:i,LAYOUT:o,BUFFER:n,SAFE:c,SCOPE:h,COMPONENT:a,ELEMENT:l}=t.vars,u=t.globals||[];function p(t){this[K]=null,this[s]={},this[r]={},Object.assign(this,k(t,[h,n,c,a,l]))}return Object.entries(e).forEach((t=>{let[e,s]=t;g(s)&&u.includes(e)&&(s=s.bind(p.prototype)),p.prototype[e]=s})),Object.defineProperty(p.prototype,n,{value:D()}),Object.defineProperty(p.prototype,s,{value:{},writable:!0}),Object.defineProperty(p.prototype,r,{value:{},writable:!0}),Object.defineProperty(p.prototype,o,{value:!1,writable:!0}),Object.defineProperty(p.prototype,i,{value:!1,writable:!0}),Object.defineProperty(p.prototype,K,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value(t){return this[K]=t,this}},getParentTemplate:{value(){return this[K]}},useSafeValue:{get:()=>O},useComponent:{get(){return g(this[a])?this[a].bind(this):()=>{throw new Error(`${a} must be a function`)}}},useElement:{get(){return g(this[l])?this[l].bind(this):()=>{throw new Error(`${l} must be a function`)}}},useBuffer:{get(){return this[n]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[i]=t,this}},getExtend:{value(){return this[i]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,i,n];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(g(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(g(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(),o=()=>{const t=i();return t?()=>{this.echo(t(o()))}:()=>{}};this.echo(i()(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||{}),o=this.render(t,i);this.echo(o)}},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){m(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=g(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const r=[],i=-1===A.indexOf(t),o=Object.entries(e??{}).map(W).filter((t=>t)).join(M);return r.push([q,t,M,o,U].join("")),s&&i&&r.push(Array.isArray(s)?s.join(""):s),i&&r.push([q,R,t,U].join("")),r.join("")})(t,e,s))))},writable:!0},ui:{value(t){},writable:!0}}),p};class Y{#h;static exports=["create","globals","helpers"];constructor(t,e){S(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#h(t)}helpers(t){Object.assign(this.#h.prototype,t)}configure(t,e){this.#h=X(t,e)}}const{render:Z,createContext:I,compile:G,helpers:H,preload:Q,configure:tt,create:et}=new class{#s;#h;#r;#a;#o={};#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.#o=v({},t),this.#h=new Y(this.#o,this.#l),this.#r=new B(this.#o),this.#s=new L(this.#o),this.#a=new T(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.#h.configure(this.#o,this.#l),this.#r.configure(this.#o),this.#s.configure(this.#o),this.#a.configure(this.#o)),this.#o}createContext(t){return this.#h.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#r.compile(t,e)}helpers(t){this.#h.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.#o.extension&&(t=[t,this.#o.extension].join(".")),t}#u(t,e){return this.#a.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}}({resolver:(t,e)=>fetch(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((s=>{if(s.ok)return s.text();throw new J(`template ${t} / ${e} not found`)}),(t=>new V(t)))});t.TemplateError=V,t.TemplateNotFound=J,t.TemplateSyntaxError=_,t.compile=G,t.configure=tt,t.create=et,t.createContext=I,t.helpers=H,t.preload=Q,t.render=Z}));
|
|
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="ejsPrecompiled",s=!0,i="views",o="ejs",r=!0,n=!0,c=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),h=[],a={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},l={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},u=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,p=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},f=t=>Array.isArray(t),g=t=>"function"==typeof t,m=t=>"string"==typeof t,d=t=>"boolean"==typeof t,v=(t,v)=>{return Object.assign(t,{path:p(m,i,t.path,v.path),precompiled:p(m,e,t.export,v.export),resolver:p(g,c,t.resolver,v.resolver),extension:p(m,o,t.extension,v.extension),strict:p(d,n,t.strict,v.strict),rmWhitespace:p(d,r,t.rmWhitespace,v.rmWhitespace),cache:p(d,s,t.cache,v.cache),globals:p(f,h,t.globals,(b=v.globals,!!f(b)&&b.filter((t=>{const e=u.test(t);return!1===e&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),e})))),token:Object.assign({},l,t.token,v.token),vars:Object.assign({},a,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},x={"&":"&","<":"<",">":">",'"':""","'":"'"},y=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=y(x),E=y(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>x[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let i=t,o=String(e).split("."),r=o.pop();for(let t=0;t<o.length;t++){const e=o[t];if(g(i.toJSON)&&(i=i.toJSON()),s&&!1===i.hasOwnProperty(e)){i={};break}i=i[e]=i[e]||{}}return g(i.toJSON)&&(i=i.toJSON()),[i,r]},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,i=e.length;s<i;s++){const i=e[s];i in t&&(t[i]=t[i].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 N{#t;#e;#s;#i;static exports=["configure","get"];constructor(t,e,s){S(this,this.constructor.exports),this.#s=e,this.#i=s,this.configure(t??{})}configure(t){this.#t=t.path,g(t.resolver)&&(this.#e=t.resolver)}#o(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}#r(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#i.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#o(t).then((e=>this.#r(e,t)))}}const L=[["-",(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{#n={};static exports=["configure","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 L)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:i,SAFE:o,BUFFER:r,COMPONENT:n,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 h=`${r}('`;((t,e,s)=>{let i=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),o=t.shift();return s(t,i,e),i=e+o.length,o}))})(this.#n.regex,t,((e,s,i)=>{h+=(""+t.slice(s,i)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#n.formats[e](t.trim(),r,o))}))})),h+="');",h=`try{${h}}catch(e){return ${r}.error(e)}`,!1===this.#n.strict&&(h=`with(${i}){${h}}`),h=`${r}.start();${h}return ${r}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[i,n,c,r,o],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 F=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],R=" ",q='"',U="/",W="<",V=">",J=t=>{let[e,s]=t;if(null!=s)return[$(e),[q,$(s),q].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:i,EXTEND:o,LAYOUT:r,BUFFER:n,SAFE:c,SCOPE:h,COMPONENT:a,ELEMENT:l}=t.vars,u=t.globals||[];function p(t){this[D]=null,this[s]={},this[i]={},Object.assign(this,k(t,[h,n,c,a,l]))}return Object.defineProperty(p.prototype,n,{value:z()}),Object.defineProperty(p.prototype,s,{value:{},writable:!0}),Object.defineProperty(p.prototype,i,{value:{},writable:!0}),Object.defineProperty(p.prototype,r,{value:!1,writable:!0}),Object.defineProperty(p.prototype,o,{value:!1,writable:!0}),Object.defineProperty(p.prototype,D,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value(t){return this[D]=t,this}},getParentTemplate:{value(){return this[D]}},useEscapeValue:{get:()=>O},useComponent:{get(){return g(this[a])?this[a].bind(this):function(){throw new Error(`${a} must be a function`)}}},useElement:{get(){return g(this[l])?this[l].bind(this):()=>{throw new Error(`${l} must be a function`)}}},useBuffer:{get(){return this[n]}},getMacro:{value(){return this[i]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[o]=t,this}},getExtend:{value(){return this[o]}},setLayout:{value(t){return this[r]=t,this}},getLayout:{value(){return this[r]}},clone:{value(t){const e=[r,o,n];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(g(t))return e.useBuffer.backup(),e.useBuffer(t.apply(e,arguments)),e.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),i=this.fn(e),o=this;s[t]=function(){return o.echo(i.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(g(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 i=this,o=Object.assign([],s[t]),r=function(){return o.shift()},n=function(){const t=r();return t?function(){i.echo(t(n()))}:function(){}};this.echo(r()(n()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const i=!1===s?{}:this.clone(!0),o=Object.assign(i,e||{}),r=this.render(t,o);this.echo(r)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,i)=>{s[[e,i].join(".")]=t}))})))}},get:{value(t,e){const s=w(this,t,!0),i=s.shift(),o=s.pop();return C(i,o)?i[o]:e}},set:{value(t,e){const s=w(this,t,!1),i=s.shift(),o=s.pop();return this.getParentTemplate()&&C(i,o)?i[o]:i[o]=e}},each:{value(t,e){m(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=g(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const i=[],o=-1===F.indexOf(t),r=Object.entries(e??{}).map(J).filter((t=>t)).join(R);return i.push([W,t,R,r,V].join("")),s&&o&&i.push(Array.isArray(s)?s.join(""):s),o&&i.push([W,U,t,V].join("")),i.join("")})(t,e,s))))},writable:!0},ui:{value(){},writable:!0}}),Object.entries(e).forEach((t=>{let[e,s]=t;g(s)&&u.includes(e)&&(s=s.bind(p.prototype)),p.prototype[e]=s})),p};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{render:Y,configure:Z,create:I,helpers:G,createContext:H,compile:Q,preload:tt}=new class{#s;#a;#i;#l;#n={};#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.#n=v({},t),this.#a=new X(this.#n,this.#u),this.#i=new A(this.#n),this.#s=new M(this.#n),this.#l=new N(this.#n,this.#s,this.#i),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.#u),this.#i.configure(this.#n),this.#s.configure(this.#n),this.#l.configure(this.#n)),this.#n}createContext(t){return this.#a.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#i.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.#n.extension&&(t=[t,this.#n.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 i=this.createContext(e);return s&&i.setParentTemplate(s),this.#p(this.#t(t),i).then(this.#f(t,i))}#f(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#g(e.getLayout(),e,t)):s}}({resolver:(t,e,s)=>fetch(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((t=>t.ok?t.text():s(404,`template ${e} not found`)),(t=>s(500,t)))});t.compile=Q,t.configure=Z,t.create=I,t.createContext=H,t.helpers=G,t.preload=tt,t.render=Y}));
|
package/dist/umd/element.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejsElement = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const symbolEntities = {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
28
28
|
return ('' + string).replace(htmlEntitiesMatch, match => htmlEntities[match]);
|
|
29
29
|
};
|
|
30
|
-
const
|
|
30
|
+
const escapeValue = (value, escape) => {
|
|
31
31
|
const check = value;
|
|
32
32
|
return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
|
|
33
33
|
};
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
exports.element = element;
|
|
63
|
-
exports.
|
|
63
|
+
exports.escapeValue = escapeValue;
|
|
64
64
|
|
|
65
65
|
}));
|
package/dist/umd/element.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ejsElement={})}(this,(function(e){"use strict";const n={"&":"&","<":"<",">":">",'"':""","'":"'"},t=e=>new RegExp(["[",Object.keys(e).join(""),"]"].join(""),"g"),o=t(n);t({"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"});const i=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(o,(e=>n[e]))},r=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],u=" ",s='"',l="/",a="<",c=">",f=e=>{let[n,t]=e;if(null!=t)return[i(n),[s,i(t),s].join("")].join("=")};e.element=(e,n,t)=>{const o=[],i=-1===r.indexOf(e),s=Object.entries(n??{}).map(f).filter((e=>e)).join(u);return o.push([a,e,u,s,c].join("")),t&&i&&o.push(Array.isArray(t)?t.join(""):t),i&&o.push([a,l,e,c].join("")),o.join("")},e.escapeValue=(e,n)=>{const t=e;return null==t?"":!0===Boolean(n)?i(t):t}}));
|