@kosatyi/ejs 0.0.109 → 0.0.111

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.
@@ -1,849 +1,908 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejsInstance = {}));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejsInstance = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- /**
8
- * @type {EjsConfig}
9
- */
10
- const ejsDefaults = {
11
- precompiled: 'ejsPrecompiled',
12
- cache: true,
13
- path: 'views',
14
- extension: 'ejs',
15
- rmWhitespace: true,
16
- strict: true,
17
- resolver: (path, template) => {
18
- return Promise.resolve(['resolver is not defined', path, template].join(' '));
19
- },
20
- globals: [],
21
- vars: {
22
- SCOPE: 'ejs',
23
- COMPONENT: 'ui',
24
- ELEMENT: 'el',
25
- EXTEND: '$$e',
26
- BUFFER: '$$a',
27
- LAYOUT: '$$l',
28
- BLOCKS: '$$b',
29
- MACRO: '$$m',
30
- SAFE: '$$v'
31
- },
32
- token: {
33
- start: '<%',
34
- end: '%>',
35
- regex: '([\\s\\S]+?)'
36
- }
37
- };
38
-
39
- const jsVariableName = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
40
- const typeProp = function () {
41
- const args = [].slice.call(arguments);
42
- const callback = args.shift();
43
- return args.filter(callback).pop();
44
- };
45
- const isArray = value => Array.isArray(value);
46
- const isFunction = value => typeof value === 'function';
47
- const isString = value => typeof value === 'string';
48
- const isBoolean = value => typeof value === 'boolean';
49
- const isArrayOfVariables = value => {
50
- if (!isArray(value)) return false;
51
- return value.filter(name => {
52
- const valid = jsVariableName.test(name);
53
- if (valid === false) console.log(`ejsConfig.globals: expected '${name}' to be valid variable name --> skipped`);
54
- return valid;
7
+ function _assertClassBrand(e, t, n) {
8
+ if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
9
+ throw new TypeError("Private element is not present on this object");
10
+ }
11
+ function _checkPrivateRedeclaration(e, t) {
12
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
13
+ }
14
+ function _classPrivateFieldGet2(s, a) {
15
+ return s.get(_assertClassBrand(s, a));
16
+ }
17
+ function _classPrivateFieldInitSpec(e, t, a) {
18
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
19
+ }
20
+ function _classPrivateFieldSet2(s, a, r) {
21
+ return s.set(_assertClassBrand(s, a), r), r;
22
+ }
23
+ function _classPrivateMethodInitSpec(e, a) {
24
+ _checkPrivateRedeclaration(e, a), a.add(e);
25
+ }
26
+ function _defineProperty(e, r, t) {
27
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
28
+ value: t,
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true
32
+ }) : e[r] = t, e;
33
+ }
34
+ function ownKeys(e, r) {
35
+ var t = Object.keys(e);
36
+ if (Object.getOwnPropertySymbols) {
37
+ var o = Object.getOwnPropertySymbols(e);
38
+ r && (o = o.filter(function (r) {
39
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
40
+ })), t.push.apply(t, o);
41
+ }
42
+ return t;
43
+ }
44
+ function _objectSpread2(e) {
45
+ for (var r = 1; r < arguments.length; r++) {
46
+ var t = null != arguments[r] ? arguments[r] : {};
47
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
48
+ _defineProperty(e, r, t[r]);
49
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
50
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
55
51
  });
56
- };
52
+ }
53
+ return e;
54
+ }
55
+ function _toPrimitive(t, r) {
56
+ if ("object" != typeof t || !t) return t;
57
+ var e = t[Symbol.toPrimitive];
58
+ if (void 0 !== e) {
59
+ var i = e.call(t, r);
60
+ if ("object" != typeof i) return i;
61
+ throw new TypeError("@@toPrimitive must return a primitive value.");
62
+ }
63
+ return ("string" === r ? String : Number)(t);
64
+ }
65
+ function _toPropertyKey(t) {
66
+ var i = _toPrimitive(t, "string");
67
+ return "symbol" == typeof i ? i : i + "";
68
+ }
57
69
 
58
- const configSchema = (config, options) => {
59
- return Object.assign(config, {
60
- path: typeProp(isString, ejsDefaults.path, config.path, options.path),
61
- precompiled: typeProp(isString, ejsDefaults.precompiled, config.export, options.export),
62
- resolver: typeProp(isFunction, ejsDefaults.resolver, config.resolver, options.resolver),
63
- extension: typeProp(isString, ejsDefaults.extension, config.extension, options.extension),
64
- strict: typeProp(isBoolean, ejsDefaults.strict, config.strict, options.strict),
65
- rmWhitespace: typeProp(isBoolean, ejsDefaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
66
- cache: typeProp(isBoolean, ejsDefaults.cache, config.cache, options.cache),
67
- globals: typeProp(isArray, ejsDefaults.globals, config.globals, isArrayOfVariables(options.globals)),
68
- token: Object.assign({}, ejsDefaults.token, config.token, options.token),
69
- vars: Object.assign({}, ejsDefaults.vars, config.vars, options.vars)
70
- });
71
- };
70
+ /**
71
+ * @type {EjsConfig}
72
+ */
73
+ const ejsDefaults = {
74
+ precompiled: 'ejsPrecompiled',
75
+ cache: true,
76
+ path: 'views',
77
+ extension: 'ejs',
78
+ rmWhitespace: true,
79
+ strict: true,
80
+ resolver: (path, template) => {
81
+ return Promise.resolve(['resolver is not defined', path, template].join(' '));
82
+ },
83
+ globals: [],
84
+ vars: {
85
+ SCOPE: 'ejs',
86
+ COMPONENT: 'ui',
87
+ ELEMENT: 'el',
88
+ EXTEND: '$$e',
89
+ BUFFER: '$$a',
90
+ LAYOUT: '$$l',
91
+ BLOCKS: '$$b',
92
+ MACRO: '$$m',
93
+ SAFE: '$$v'
94
+ },
95
+ token: {
96
+ start: '<%',
97
+ end: '%>',
98
+ regex: '([\\s\\S]+?)'
99
+ }
100
+ };
72
101
 
73
- const symbolEntities = {
74
- "'": "'",
75
- '\\': '\\',
76
- '\r': 'r',
77
- '\n': 'n',
78
- '\t': 't',
79
- '\u2028': 'u2028',
80
- '\u2029': 'u2029'
81
- };
82
- const htmlEntities = {
83
- '&': '&amp;',
84
- '<': '&lt;',
85
- '>': '&gt;',
86
- '"': '&quot;',
87
- "'": '&#x27;'
88
- };
89
- const regexKeys = obj => new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
90
- const htmlEntitiesMatch = regexKeys(htmlEntities);
91
- const symbolEntitiesMatch = regexKeys(symbolEntities);
92
- const entities = function () {
93
- let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
94
- return ('' + string).replace(htmlEntitiesMatch, match => htmlEntities[match]);
95
- };
96
- const symbols = string => {
97
- return ('' + string).replace(symbolEntitiesMatch, match => '\\' + symbolEntities[match]);
98
- };
99
- const safeValue = (value, escape) => {
100
- const check = value;
101
- return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
102
- };
103
- const getPath = (context, name, strict) => {
104
- let data = context;
105
- let chunks = String(name).split('.');
106
- let prop = chunks.pop();
107
- for (let i = 0; i < chunks.length; i++) {
108
- const part = chunks[i];
109
- if (isFunction(data['toJSON'])) {
110
- data = data.toJSON();
111
- }
112
- if (strict && data.hasOwnProperty(part) === false) {
113
- data = {};
114
- break;
115
- }
116
- data = data[part] = data[part] || {};
117
- }
102
+ const jsVariableName = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
103
+ const typeProp = function () {
104
+ const args = [].slice.call(arguments);
105
+ const callback = args.shift();
106
+ return args.filter(callback).pop();
107
+ };
108
+ const isArray = value => Array.isArray(value);
109
+ const isFunction = value => typeof value === 'function';
110
+ const isString = value => typeof value === 'string';
111
+ const isBoolean = value => typeof value === 'boolean';
112
+ const isArrayOfVariables = value => {
113
+ if (!isArray(value)) return false;
114
+ return value.filter(name => {
115
+ const valid = jsVariableName.test(name);
116
+ if (valid === false) console.log("ejsConfig.globals: expected '".concat(name, "' to be valid variable name --> skipped"));
117
+ return valid;
118
+ });
119
+ };
120
+
121
+ const configSchema = (config, options) => {
122
+ return Object.assign(config, {
123
+ path: typeProp(isString, ejsDefaults.path, config.path, options.path),
124
+ precompiled: typeProp(isString, ejsDefaults.precompiled, config.export, options.export),
125
+ resolver: typeProp(isFunction, ejsDefaults.resolver, config.resolver, options.resolver),
126
+ extension: typeProp(isString, ejsDefaults.extension, config.extension, options.extension),
127
+ strict: typeProp(isBoolean, ejsDefaults.strict, config.strict, options.strict),
128
+ rmWhitespace: typeProp(isBoolean, ejsDefaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
129
+ cache: typeProp(isBoolean, ejsDefaults.cache, config.cache, options.cache),
130
+ globals: typeProp(isArray, ejsDefaults.globals, config.globals, isArrayOfVariables(options.globals)),
131
+ token: Object.assign({}, ejsDefaults.token, config.token, options.token),
132
+ vars: Object.assign({}, ejsDefaults.vars, config.vars, options.vars)
133
+ });
134
+ };
135
+
136
+ const symbolEntities = {
137
+ "'": "'",
138
+ '\\': '\\',
139
+ '\r': 'r',
140
+ '\n': 'n',
141
+ '\t': 't',
142
+ '\u2028': 'u2028',
143
+ '\u2029': 'u2029'
144
+ };
145
+ const htmlEntities = {
146
+ '&': '&amp;',
147
+ '<': '&lt;',
148
+ '>': '&gt;',
149
+ '"': '&quot;',
150
+ "'": '&#x27;'
151
+ };
152
+ const regexKeys = obj => new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
153
+ const htmlEntitiesMatch = regexKeys(htmlEntities);
154
+ const symbolEntitiesMatch = regexKeys(symbolEntities);
155
+ const entities = function () {
156
+ let string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
157
+ return ('' + string).replace(htmlEntitiesMatch, match => htmlEntities[match]);
158
+ };
159
+ const symbols = string => {
160
+ return ('' + string).replace(symbolEntitiesMatch, match => '\\' + symbolEntities[match]);
161
+ };
162
+ const escapeValue = (value, escape) => {
163
+ const check = value;
164
+ return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
165
+ };
166
+ const getPath = (context, name, strict) => {
167
+ let data = context;
168
+ let chunks = String(name).split('.');
169
+ let prop = chunks.pop();
170
+ for (let i = 0; i < chunks.length; i++) {
171
+ const part = chunks[i];
118
172
  if (isFunction(data['toJSON'])) {
119
173
  data = data.toJSON();
120
174
  }
121
- return [data, prop];
122
- };
123
- const each = (object, callback) => {
124
- let prop;
125
- for (prop in object) {
126
- if (hasProp(object, prop)) {
127
- callback(object[prop], prop, object);
128
- }
175
+ if (strict && data.hasOwnProperty(part) === false) {
176
+ data = {};
177
+ break;
129
178
  }
130
- };
131
- const omit = (object, list) => {
132
- const result = {
133
- ...object
134
- };
135
- for (const key of list) {
136
- delete result[key];
179
+ data = data[part] = data[part] || {};
180
+ }
181
+ if (isFunction(data['toJSON'])) {
182
+ data = data.toJSON();
183
+ }
184
+ return [data, prop];
185
+ };
186
+ const each = (object, callback) => {
187
+ let prop;
188
+ for (prop in object) {
189
+ if (hasProp(object, prop)) {
190
+ callback(object[prop], prop, object);
137
191
  }
138
- return result;
139
- };
140
- const hasProp = (object, prop) => {
141
- return object && Object.hasOwn(object, prop);
142
- };
143
- const joinPath = (path, template) => {
144
- template = [path, template].join('/');
145
- template = template.replace(/\/\//g, '/');
146
- return template;
147
- };
148
- const bindContext = function (object) {
149
- let methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
150
- for (let i = 0, len = methods.length; i < len; i++) {
151
- const name = methods[i];
152
- if (name in object) {
153
- object[name] = object[name].bind(object);
154
- }
192
+ }
193
+ };
194
+ const omit = (object, list) => {
195
+ const result = _objectSpread2({}, object);
196
+ for (const key of list) {
197
+ delete result[key];
198
+ }
199
+ return result;
200
+ };
201
+ const hasProp = (object, prop) => {
202
+ return object && Object.hasOwn(object, prop);
203
+ };
204
+ const joinPath = (path, template) => {
205
+ template = [path, template].join('/');
206
+ template = template.replace(/\/\//g, '/');
207
+ return template;
208
+ };
209
+ const bindContext = function (object) {
210
+ let methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
211
+ for (let i = 0, len = methods.length; i < len; i++) {
212
+ const name = methods[i];
213
+ if (name in object) {
214
+ object[name] = object[name].bind(object);
155
215
  }
156
- };
216
+ }
217
+ };
157
218
 
158
- class Template {
159
- #path;
160
- #resolver;
161
- #cache;
162
- #compiler;
163
- static exports = ['configure', 'get', 'compile'];
164
- constructor(options, cache, compiler) {
165
- bindContext(this, this.constructor.exports);
166
- this.#cache = cache;
167
- this.#compiler = compiler;
168
- this.configure(options ?? {});
169
- }
170
- configure(options) {
171
- this.#path = options.path;
172
- if (isFunction(options.resolver)) {
173
- this.#resolver = options.resolver;
174
- }
175
- }
176
- #resolve(template) {
177
- const cached = this.#cache.get(template);
178
- if (cached instanceof Promise) return cached;
179
- const result = Promise.resolve(this.#resolver(this.#path, template));
180
- this.#cache.set(template, result);
181
- return result;
182
- }
183
- compile(content, template) {
184
- const cached = this.#cache.get(template);
185
- if (typeof cached === 'function') return cached;
186
- if (typeof content === 'string') {
187
- content = this.#compiler.compile(content, template);
188
- }
189
- if (typeof content === 'function') {
190
- this.#cache.set(template, content);
191
- return content;
192
- }
193
- }
194
- get(template) {
195
- return this.#resolve(template).then(content => this.compile(content, template));
219
+ class EjsError extends Error {
220
+ constructor(code, content) {
221
+ super(content);
222
+ this.code = code;
223
+ if (content instanceof Error) {
224
+ this.stack = content.stack;
225
+ this.message = content.message;
196
226
  }
197
227
  }
228
+ }
229
+ const error = (code, content) => {
230
+ throw new EjsError(code, content);
231
+ };
198
232
 
199
- const tokenList = [['-', (v, b, s) => `')\n${b}(${s}(${v},1))\n${b}('`], ['=', (v, b, s) => `')\n${b}(${s}(${v}))\n${b}('`], ['#', (v, b) => `')\n/**${v}**/\n${b}('`], ['', (v, b) => `')\n${v}\n${b}('`]];
200
- const tokensMatch = (regex, content, callback) => {
201
- let index = 0;
202
- content.replace(regex, function () {
203
- const params = [].slice.call(arguments, 0, -1);
204
- const offset = params.pop();
205
- const match = params.shift();
206
- callback(params, index, offset);
207
- index = offset + match.length;
208
- return match;
209
- });
210
- };
211
- class Compiler {
212
- #config = {};
213
- static exports = ['compile'];
214
- constructor(options) {
215
- bindContext(this, this.constructor.exports);
216
- this.configure(options);
233
+ var _path$1 = /*#__PURE__*/new WeakMap();
234
+ var _resolver = /*#__PURE__*/new WeakMap();
235
+ var _cache$2 = /*#__PURE__*/new WeakMap();
236
+ var _compiler$1 = /*#__PURE__*/new WeakMap();
237
+ var _EjsTemplate_brand = /*#__PURE__*/new WeakSet();
238
+ class EjsTemplate {
239
+ constructor(options, cache, compiler) {
240
+ _classPrivateMethodInitSpec(this, _EjsTemplate_brand);
241
+ _classPrivateFieldInitSpec(this, _path$1, void 0);
242
+ _classPrivateFieldInitSpec(this, _resolver, void 0);
243
+ _classPrivateFieldInitSpec(this, _cache$2, void 0);
244
+ _classPrivateFieldInitSpec(this, _compiler$1, void 0);
245
+ bindContext(this, this.constructor.exports);
246
+ _classPrivateFieldSet2(_cache$2, this, cache);
247
+ _classPrivateFieldSet2(_compiler$1, this, compiler);
248
+ this.configure(options !== null && options !== void 0 ? options : {});
249
+ }
250
+ configure(options) {
251
+ _classPrivateFieldSet2(_path$1, this, options.path);
252
+ if (isFunction(options.resolver)) {
253
+ _classPrivateFieldSet2(_resolver, this, options.resolver);
217
254
  }
218
- configure(options) {
219
- this.#config.strict = options.strict;
220
- this.#config.rmWhitespace = options.rmWhitespace;
221
- this.#config.token = options.token;
222
- this.#config.vars = options.vars;
223
- this.#config.globals = options.globals;
224
- this.#config.legacy = options.legacy ?? true;
225
- this.#config.slurp = {
226
- match: '[s\t\n]*',
227
- start: [this.#config.token.start, '_'],
228
- end: ['_', this.#config.token.end]
229
- };
230
- this.#config.matches = [];
231
- this.#config.formats = [];
232
- for (const [symbol, format] of tokenList) {
233
- this.#config.matches.push(this.#config.token.start.concat(symbol).concat(this.#config.token.regex).concat(this.#config.token.end));
234
- this.#config.formats.push(format);
235
- }
236
- this.#config.regex = new RegExp(this.#config.matches.join('|').concat('|$'), 'g');
237
- this.#config.slurpStart = new RegExp([this.#config.slurp.match, this.#config.slurp.start.join('')].join(''), 'gm');
238
- this.#config.slurpEnd = new RegExp([this.#config.slurp.end.join(''), this.#config.slurp.match].join(''), 'gm');
239
- if (this.#config.globals.length) {
240
- if (this.#config.legacy) {
241
- this.#config.globalVariables = `const ${this.#config.globals.map(name => `${name}=${this.#config.vars.SCOPE}.${name}`).join(',')};`;
242
- } else {
243
- this.#config.globalVariables = `const {${this.#config.globals.join(',')}} = ${this.#config.vars.SCOPE};`;
244
- }
255
+ }
256
+ get(template) {
257
+ return _assertClassBrand(_EjsTemplate_brand, this, _resolve).call(this, template).then(content => {
258
+ return _assertClassBrand(_EjsTemplate_brand, this, _compile).call(this, content, template);
259
+ });
260
+ }
261
+ }
262
+ function _resolve(template) {
263
+ const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
264
+ if (cached instanceof Promise) return cached;
265
+ const result = Promise.resolve(_classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path$1, this), template, error));
266
+ _classPrivateFieldGet2(_cache$2, this).set(template, result);
267
+ return result;
268
+ }
269
+ function _compile(content, template) {
270
+ const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
271
+ if (typeof cached === 'function') return cached;
272
+ if (typeof content === 'string') {
273
+ content = _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
274
+ }
275
+ if (typeof content === 'function') {
276
+ _classPrivateFieldGet2(_cache$2, this).set(template, content);
277
+ return content;
278
+ }
279
+ }
280
+ _defineProperty(EjsTemplate, "exports", ['configure', 'get']);
281
+
282
+ const tokenList = [['-', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, ",1))\n").concat(b, "('")], ['=', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, "))\n").concat(b, "('")], ['#', (v, b) => "')\n/**".concat(v, "**/\n").concat(b, "('")], ['', (v, b) => "')\n".concat(v, "\n").concat(b, "('")]];
283
+ const tokensMatch = (regex, content, callback) => {
284
+ let index = 0;
285
+ content.replace(regex, function () {
286
+ const params = [].slice.call(arguments, 0, -1);
287
+ const offset = params.pop();
288
+ const match = params.shift();
289
+ callback(params, index, offset);
290
+ index = offset + match.length;
291
+ return match;
292
+ });
293
+ };
294
+ var _config$1 = /*#__PURE__*/new WeakMap();
295
+ class EjsCompiler {
296
+ constructor(options) {
297
+ _classPrivateFieldInitSpec(this, _config$1, {});
298
+ bindContext(this, this.constructor.exports);
299
+ this.configure(options);
300
+ }
301
+ configure(options) {
302
+ var _options$legacy;
303
+ _classPrivateFieldGet2(_config$1, this).strict = options.strict;
304
+ _classPrivateFieldGet2(_config$1, this).rmWhitespace = options.rmWhitespace;
305
+ _classPrivateFieldGet2(_config$1, this).token = options.token;
306
+ _classPrivateFieldGet2(_config$1, this).vars = options.vars;
307
+ _classPrivateFieldGet2(_config$1, this).globals = options.globals;
308
+ _classPrivateFieldGet2(_config$1, this).legacy = (_options$legacy = options.legacy) !== null && _options$legacy !== void 0 ? _options$legacy : true;
309
+ _classPrivateFieldGet2(_config$1, this).slurp = {
310
+ match: '[s\t\n]*',
311
+ start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
312
+ end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
313
+ };
314
+ _classPrivateFieldGet2(_config$1, this).matches = [];
315
+ _classPrivateFieldGet2(_config$1, this).formats = [];
316
+ for (const [symbol, format] of tokenList) {
317
+ _classPrivateFieldGet2(_config$1, this).matches.push(_classPrivateFieldGet2(_config$1, this).token.start.concat(symbol).concat(_classPrivateFieldGet2(_config$1, this).token.regex).concat(_classPrivateFieldGet2(_config$1, this).token.end));
318
+ _classPrivateFieldGet2(_config$1, this).formats.push(format);
319
+ }
320
+ _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
321
+ _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
322
+ _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
323
+ if (_classPrivateFieldGet2(_config$1, this).globals.length) {
324
+ if (_classPrivateFieldGet2(_config$1, this).legacy) {
325
+ _classPrivateFieldGet2(_config$1, this).globalVariables = "const ".concat(_classPrivateFieldGet2(_config$1, this).globals.map(name => "".concat(name, "=").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ".").concat(name)).join(','), ";");
326
+ } else {
327
+ _classPrivateFieldGet2(_config$1, this).globalVariables = "const {".concat(_classPrivateFieldGet2(_config$1, this).globals.join(','), "} = ").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ";");
245
328
  }
246
329
  }
247
- compile(content, path) {
248
- const GLOBALS = this.#config.globalVariables;
249
- const {
250
- SCOPE,
251
- SAFE,
252
- BUFFER,
253
- COMPONENT,
254
- ELEMENT
255
- } = this.#config.vars;
256
- if (this.#config.rmWhitespace) {
257
- content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
258
- }
259
- content = String(content).replace(this.#config.slurpStart, this.#config.token.start).replace(this.#config.slurpEnd, this.#config.token.end);
260
- let OUTPUT = `${BUFFER}('`;
261
- tokensMatch(this.#config.regex, content, (params, index, offset) => {
262
- OUTPUT += symbols(content.slice(index, offset));
263
- params.forEach((value, index) => {
264
- if (value) {
265
- OUTPUT += this.#config.formats[index](value.trim(), BUFFER, SAFE);
266
- }
267
- });
330
+ }
331
+ compile(content, path) {
332
+ const GLOBALS = _classPrivateFieldGet2(_config$1, this).globalVariables;
333
+ const {
334
+ SCOPE,
335
+ SAFE,
336
+ BUFFER,
337
+ COMPONENT,
338
+ ELEMENT
339
+ } = _classPrivateFieldGet2(_config$1, this).vars;
340
+ if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
341
+ content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
342
+ }
343
+ content = String(content).replace(_classPrivateFieldGet2(_config$1, this).slurpStart, _classPrivateFieldGet2(_config$1, this).token.start).replace(_classPrivateFieldGet2(_config$1, this).slurpEnd, _classPrivateFieldGet2(_config$1, this).token.end);
344
+ let OUTPUT = "".concat(BUFFER, "('");
345
+ tokensMatch(_classPrivateFieldGet2(_config$1, this).regex, content, (params, index, offset) => {
346
+ OUTPUT += symbols(content.slice(index, offset));
347
+ params.forEach((value, index) => {
348
+ if (value) {
349
+ OUTPUT += _classPrivateFieldGet2(_config$1, this).formats[index](value.trim(), BUFFER, SAFE);
350
+ }
268
351
  });
269
- OUTPUT += `');`;
270
- OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e,'${path}')}`;
271
- if (this.#config.strict === false) {
272
- OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
273
- }
274
- OUTPUT = `${BUFFER}.start();${OUTPUT}return ${BUFFER}.end();`;
275
- OUTPUT += `\n//# sourceURL=${path}`;
276
- if (GLOBALS) {
277
- OUTPUT = `${GLOBALS}\n${OUTPUT}`;
278
- }
279
- try {
280
- const params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE];
281
- const result = Function.apply(null, params.concat(OUTPUT));
282
- result.source = `(function(${params.join(',')}){\n${OUTPUT}\n});`;
283
- return result;
284
- } catch (error) {
285
- error.filename = path;
286
- error.source = OUTPUT;
287
- throw error;
288
- }
352
+ });
353
+ OUTPUT += "');";
354
+ OUTPUT = "try{".concat(OUTPUT, "}catch(e){return ").concat(BUFFER, ".error(e)}");
355
+ if (_classPrivateFieldGet2(_config$1, this).strict === false) {
356
+ OUTPUT = "with(".concat(SCOPE, "){").concat(OUTPUT, "}");
357
+ }
358
+ OUTPUT = "".concat(BUFFER, ".start();").concat(OUTPUT, "return ").concat(BUFFER, ".end();");
359
+ OUTPUT += "\n//# sourceURL=".concat(path);
360
+ if (GLOBALS) {
361
+ OUTPUT = "".concat(GLOBALS, "\n").concat(OUTPUT);
362
+ }
363
+ try {
364
+ const params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE];
365
+ const result = Function.apply(null, params.concat(OUTPUT));
366
+ result.source = "(function(".concat(params.join(','), "){\n").concat(OUTPUT, "\n});");
367
+ return result;
368
+ } catch (e) {
369
+ e.filename = path;
370
+ e.source = OUTPUT;
371
+ error(0, e);
289
372
  }
290
373
  }
374
+ }
375
+ _defineProperty(EjsCompiler, "exports", ['configure', 'compile']);
291
376
 
292
- class Cache {
293
- static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
294
- #cache = true;
295
- #precompiled;
296
- #list = {};
297
- constructor(options) {
298
- bindContext(this, this.constructor.exports);
299
- this.configure(options);
300
- }
301
- get(key) {
302
- if (this.#cache) {
303
- return this.#list[key];
304
- }
305
- }
306
- set(key, value) {
307
- if (this.#cache) {
308
- this.#list[key] = value;
309
- }
310
- }
311
- exist(key) {
312
- if (this.#cache) {
313
- return this.#list.hasOwnProperty(key);
314
- }
315
- }
316
- clear() {
317
- Object.keys(this.#list).forEach(this.remove);
318
- }
319
- remove(key) {
320
- delete this.#list[key];
321
- }
322
- resolve(key) {
323
- return Promise.resolve(this.get(key));
324
- }
325
- load(data) {
326
- if (this.#cache) {
327
- Object.assign(this.#list, data || {});
328
- }
377
+ var _cache$1 = /*#__PURE__*/new WeakMap();
378
+ var _precompiled = /*#__PURE__*/new WeakMap();
379
+ var _list = /*#__PURE__*/new WeakMap();
380
+ class EjsCache {
381
+ constructor(options) {
382
+ _classPrivateFieldInitSpec(this, _cache$1, true);
383
+ _classPrivateFieldInitSpec(this, _precompiled, void 0);
384
+ _classPrivateFieldInitSpec(this, _list, {});
385
+ bindContext(this, this.constructor.exports);
386
+ this.configure(options);
387
+ }
388
+ get(key) {
389
+ if (_classPrivateFieldGet2(_cache$1, this)) {
390
+ return _classPrivateFieldGet2(_list, this)[key];
329
391
  }
330
- configure(options) {
331
- this.#cache = options.cache;
332
- this.#precompiled = options.precompiled;
333
- if (typeof window === 'object') {
334
- this.load(window[this.#precompiled]);
335
- }
392
+ }
393
+ set(key, value) {
394
+ if (_classPrivateFieldGet2(_cache$1, this)) {
395
+ _classPrivateFieldGet2(_list, this)[key] = value;
336
396
  }
337
397
  }
338
-
339
- const selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
340
- const space = ' ';
341
- const quote = '"';
342
- const equal = '=';
343
- const slash = '/';
344
- const lt = '<';
345
- const gt = '>';
346
- const eachAttribute = _ref => {
347
- let [key, value] = _ref;
348
- if (value !== null && value !== undefined) {
349
- return [entities(key), [quote, entities(value), quote].join('')].join(equal);
398
+ exist(key) {
399
+ if (_classPrivateFieldGet2(_cache$1, this)) {
400
+ return _classPrivateFieldGet2(_list, this).hasOwnProperty(key);
350
401
  }
351
- };
352
- const element = (tag, attrs, content) => {
353
- const result = [];
354
- const hasClosedTag = selfClosed.indexOf(tag) === -1;
355
- const attributes = Object.entries(attrs ?? {}).map(eachAttribute).filter(e => e).join(space);
356
- result.push([lt, tag, space, attributes, gt].join(''));
357
- if (content && hasClosedTag) {
358
- result.push(Array.isArray(content) ? content.join('') : content);
402
+ }
403
+ clear() {
404
+ Object.keys(_classPrivateFieldGet2(_list, this)).forEach(this.remove);
405
+ }
406
+ remove(key) {
407
+ delete _classPrivateFieldGet2(_list, this)[key];
408
+ }
409
+ resolve(key) {
410
+ return Promise.resolve(this.get(key));
411
+ }
412
+ load(data) {
413
+ if (_classPrivateFieldGet2(_cache$1, this)) {
414
+ Object.assign(_classPrivateFieldGet2(_list, this), data || {});
359
415
  }
360
- if (hasClosedTag) {
361
- result.push([lt, slash, tag, gt].join(''));
416
+ }
417
+ configure(options) {
418
+ _classPrivateFieldSet2(_cache$1, this, options.cache);
419
+ _classPrivateFieldSet2(_precompiled, this, options.precompiled);
420
+ if (typeof window === 'object') {
421
+ this.load(window[_classPrivateFieldGet2(_precompiled, this)]);
362
422
  }
363
- return result.join('');
364
- };
423
+ }
424
+ }
425
+ _defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
365
426
 
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
- }
427
+ const selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
428
+ const space = ' ';
429
+ const quote = '"';
430
+ const equal = '=';
431
+ const slash = '/';
432
+ const lt = '<';
433
+ const gt = '>';
434
+ const eachAttribute = _ref => {
435
+ let [key, value] = _ref;
436
+ if (value !== null && value !== undefined) {
437
+ return [entities(key), [quote, entities(value), quote].join('')].join(equal);
376
438
  }
377
- class TemplateNotFound extends TemplateError {
378
- name = 'TemplateNotFound';
379
- code = 404;
439
+ };
440
+ const element = (tag, attrs, content) => {
441
+ const result = [];
442
+ const hasClosedTag = selfClosed.indexOf(tag) === -1;
443
+ const attributes = Object.entries(attrs !== null && attrs !== void 0 ? attrs : {}).map(eachAttribute).filter(e => e).join(space);
444
+ result.push([lt, tag, space, attributes, gt].join(''));
445
+ if (content && hasClosedTag) {
446
+ result.push(Array.isArray(content) ? content.join('') : content);
380
447
  }
381
- class TemplateSyntaxError extends TemplateError {
382
- name = 'TemplateSyntaxError';
383
- code = 500;
448
+ if (hasClosedTag) {
449
+ result.push([lt, slash, tag, gt].join(''));
384
450
  }
451
+ return result.join('');
452
+ };
385
453
 
386
- const resolve = list => {
387
- return Promise.all(list || []).then(list => list.join('')).catch(e => e);
454
+ const resolve = list => {
455
+ return Promise.all(list || []).then(list => list.join('')).catch(e => error(0, e));
456
+ };
457
+ const reject = e => {
458
+ return Promise.reject(error(0, e));
459
+ };
460
+ const EjsBuffer = () => {
461
+ let store = [];
462
+ let array = [];
463
+ /**
464
+ *
465
+ * @param value
466
+ * @constructor
467
+ */
468
+ const EjsBuffer = value => {
469
+ array.push(value);
388
470
  };
389
- const reject = error => {
390
- return Promise.reject(new TemplateSyntaxError(error));
471
+ EjsBuffer.start = () => {
472
+ array = [];
391
473
  };
392
- const EjsBuffer = () => {
393
- let store = [];
394
- let array = [];
395
- /**
396
- *
397
- * @param value
398
- * @constructor
399
- */
400
- const EjsBuffer = value => {
401
- array.push(value);
402
- };
403
- EjsBuffer.start = () => {
404
- array = [];
405
- };
406
- EjsBuffer.backup = () => {
407
- store.push(array.concat());
408
- array = [];
409
- };
410
- EjsBuffer.restore = () => {
411
- const result = array.concat();
412
- array = store.pop();
413
- return resolve(result);
414
- };
415
- EjsBuffer.error = (e, filename) => {
416
- return reject(e);
417
- };
418
- EjsBuffer.end = () => {
419
- return resolve(array);
420
- };
421
- return EjsBuffer;
474
+ EjsBuffer.backup = () => {
475
+ store.push(array.concat());
476
+ array = [];
477
+ };
478
+ EjsBuffer.restore = () => {
479
+ const result = array.concat();
480
+ array = store.pop();
481
+ return resolve(result);
482
+ };
483
+ EjsBuffer.error = e => {
484
+ return reject(e);
422
485
  };
486
+ EjsBuffer.end = () => {
487
+ return resolve(array);
488
+ };
489
+ return EjsBuffer;
490
+ };
423
491
 
424
- const PARENT = Symbol('EjsContext.parentTemplate');
425
- const createContext$1 = (config, methods) => {
426
- const {
427
- BLOCKS,
428
- MACRO,
429
- EXTEND,
430
- LAYOUT,
431
- BUFFER,
432
- SAFE,
433
- SCOPE,
434
- COMPONENT,
435
- ELEMENT
436
- } = config.vars;
437
- const globals = config.globals || [];
438
- function EjsContext(data) {
492
+ const PARENT = Symbol('EjsContext.parentTemplate');
493
+ const createContext$1 = (config, methods) => {
494
+ const globals = config.globals || [];
495
+ const {
496
+ BLOCKS,
497
+ MACRO,
498
+ EXTEND,
499
+ LAYOUT,
500
+ BUFFER,
501
+ SAFE,
502
+ SCOPE,
503
+ COMPONENT,
504
+ ELEMENT
505
+ } = config.vars;
506
+ class Context {
507
+ constructor(data) {
439
508
  this[PARENT] = null;
440
509
  this[BLOCKS] = {};
441
510
  this[MACRO] = {};
442
511
  Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
443
512
  }
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
- Object.defineProperty(EjsContext.prototype, BUFFER, {
513
+ }
514
+ Object.defineProperties(Context.prototype, {
515
+ [BUFFER]: {
452
516
  value: EjsBuffer()
453
- });
454
- Object.defineProperty(EjsContext.prototype, BLOCKS, {
517
+ },
518
+ [BLOCKS]: {
455
519
  value: {},
456
520
  writable: true
457
- });
458
- Object.defineProperty(EjsContext.prototype, MACRO, {
521
+ },
522
+ [MACRO]: {
459
523
  value: {},
460
524
  writable: true
461
- });
462
- Object.defineProperty(EjsContext.prototype, LAYOUT, {
525
+ },
526
+ [LAYOUT]: {
463
527
  value: false,
464
528
  writable: true
465
- });
466
- Object.defineProperty(EjsContext.prototype, EXTEND, {
529
+ },
530
+ [EXTEND]: {
467
531
  value: false,
468
532
  writable: true
469
- });
470
- Object.defineProperty(EjsContext.prototype, PARENT, {
533
+ },
534
+ [PARENT]: {
471
535
  value: null,
472
536
  writable: true
473
- });
474
- Object.defineProperties(EjsContext.prototype, {
475
- /** @type {function} */
476
- setParentTemplate: {
477
- value(value) {
478
- this[PARENT] = value;
479
- return this;
480
- }
481
- },
482
- /** @type {function} */
483
- getParentTemplate: {
484
- value() {
485
- return this[PARENT];
486
- }
487
- },
488
- /** @type {function} */
489
- useSafeValue: {
490
- get: () => safeValue
491
- },
492
- /** @type {function} */
493
- useComponent: {
494
- get() {
495
- if (isFunction(this[COMPONENT])) {
496
- return this[COMPONENT].bind(this);
497
- } else {
498
- return () => {
499
- throw new Error(`${COMPONENT} must be a function`);
500
- };
501
- }
502
- }
503
- },
504
- /** @type {function} */
505
- useElement: {
506
- get() {
507
- if (isFunction(this[ELEMENT])) {
508
- return this[ELEMENT].bind(this);
509
- } else {
510
- return () => {
511
- throw new Error(`${ELEMENT} must be a function`);
512
- };
513
- }
514
- }
515
- },
516
- /** @type {function} */
517
- useBuffer: {
518
- get() {
519
- return this[BUFFER];
520
- }
521
- },
522
- /** @type {function} */
523
- getMacro: {
524
- value() {
525
- return this[MACRO];
526
- }
527
- },
528
- /** @type {function} */
529
- getBlocks: {
530
- value() {
531
- return this[BLOCKS];
532
- }
533
- },
534
- /** @type {function} */
535
- setExtend: {
536
- value(value) {
537
- this[EXTEND] = value;
538
- return this;
539
- }
540
- },
541
- /** @type {function} */
542
- getExtend: {
543
- value() {
544
- return this[EXTEND];
545
- }
546
- },
547
- /** @type {function} */
548
- setLayout: {
549
- value(layout) {
550
- this[LAYOUT] = layout;
551
- return this;
552
- }
553
- },
554
- /** @type {function} */
555
- getLayout: {
556
- value() {
557
- return this[LAYOUT];
558
- }
559
- },
560
- /** @type {function} */
561
- clone: {
562
- value(exclude_blocks) {
563
- const filter = [LAYOUT, EXTEND, BUFFER];
564
- if (exclude_blocks === true) {
565
- filter.push(BLOCKS);
566
- }
567
- return omit(this, filter);
568
- }
569
- },
570
- /** @type {function} */
571
- extend: {
572
- value(layout) {
573
- this.setExtend(true);
574
- this.setLayout(layout);
575
- }
576
- },
577
- /** @type {function} */
578
- echo: {
579
- value() {
580
- return [].slice.call(arguments).forEach(this.useBuffer);
537
+ },
538
+ setParentTemplate: {
539
+ value(value) {
540
+ this[PARENT] = value;
541
+ return this;
542
+ }
543
+ },
544
+ getParentTemplate: {
545
+ value() {
546
+ return this[PARENT];
547
+ }
548
+ },
549
+ useEscapeValue: {
550
+ value() {
551
+ return escapeValue;
552
+ }
553
+ },
554
+ useComponent: {
555
+ value() {
556
+ if (isFunction(this[COMPONENT])) {
557
+ return this[COMPONENT].bind(this);
558
+ } else {
559
+ return function () {
560
+ error(2, "".concat(COMPONENT, " must be a function"));
561
+ };
581
562
  }
582
- },
583
- /** @type {function} */
584
- fn: {
585
- value(callback) {
563
+ }
564
+ },
565
+ useElement: {
566
+ value() {
567
+ if (isFunction(this[ELEMENT])) {
568
+ return this[ELEMENT].bind(this);
569
+ } else {
586
570
  return () => {
587
- if (isFunction(callback)) {
588
- this.useBuffer.backup();
589
- this.useBuffer(callback.apply(this, arguments));
590
- return this.useBuffer.restore();
591
- }
571
+ error(2, "".concat(ELEMENT, " must be a function"));
592
572
  };
593
573
  }
594
- },
595
- /** @type {function} */
596
- macro: {
597
- value(name, callback) {
598
- const list = this.getMacro();
599
- const macro = this.fn(callback);
600
- const context = this;
601
- list[name] = function () {
602
- return context.echo(macro.apply(undefined, arguments));
603
- };
574
+ }
575
+ },
576
+ useBuffer: {
577
+ value() {
578
+ return this[BUFFER];
579
+ }
580
+ },
581
+ getMacro: {
582
+ value() {
583
+ return this[MACRO];
584
+ }
585
+ },
586
+ getBlocks: {
587
+ value() {
588
+ return this[BLOCKS];
589
+ }
590
+ },
591
+ setExtend: {
592
+ value(value) {
593
+ this[EXTEND] = value;
594
+ return this;
595
+ }
596
+ },
597
+ getExtend: {
598
+ value() {
599
+ return this[EXTEND];
600
+ }
601
+ },
602
+ setLayout: {
603
+ value(layout) {
604
+ this[LAYOUT] = layout;
605
+ return this;
606
+ }
607
+ },
608
+ getLayout: {
609
+ value() {
610
+ return this[LAYOUT];
611
+ }
612
+ },
613
+ clone: {
614
+ value(exclude_blocks) {
615
+ const filter = [LAYOUT, EXTEND, BUFFER];
616
+ if (exclude_blocks === true) {
617
+ filter.push(BLOCKS);
604
618
  }
605
- },
606
- /** @type {function} */
607
- call: {
608
- value(name) {
609
- const list = this.getMacro();
610
- const macro = list[name];
611
- const params = [].slice.call(arguments, 1);
612
- if (isFunction(macro)) {
613
- return macro.apply(macro, params);
619
+ return omit(this, filter);
620
+ }
621
+ },
622
+ extend: {
623
+ value(layout) {
624
+ this.setExtend(true);
625
+ this.setLayout(layout);
626
+ }
627
+ },
628
+ echo: {
629
+ value() {
630
+ return [].slice.call(arguments).forEach(this.useBuffer());
631
+ }
632
+ },
633
+ fn: {
634
+ value(callback) {
635
+ const buffer = this.useBuffer();
636
+ const context = this;
637
+ return function () {
638
+ if (isFunction(callback)) {
639
+ buffer.backup();
640
+ buffer(callback.apply(context, arguments));
641
+ return buffer.restore();
614
642
  }
643
+ };
644
+ }
645
+ },
646
+ macro: {
647
+ value(name, callback) {
648
+ const list = this.getMacro();
649
+ const macro = this.fn(callback);
650
+ const context = this;
651
+ list[name] = function () {
652
+ return context.echo(macro.apply(undefined, arguments));
653
+ };
654
+ }
655
+ },
656
+ call: {
657
+ value(name) {
658
+ const list = this.getMacro();
659
+ const macro = list[name];
660
+ const params = [].slice.call(arguments, 1);
661
+ if (isFunction(macro)) {
662
+ return macro.apply(macro, params);
615
663
  }
616
- },
617
- /** @type {function} */
618
- block: {
619
- value(name, callback) {
620
- const blocks = this.getBlocks();
621
- blocks[name] = blocks[name] || [];
622
- blocks[name].push(this.fn(callback));
623
- if (this.getExtend()) return;
624
- const list = Object.assign([], blocks[name]);
625
- const shift = () => list.shift();
626
- const next = () => {
627
- const parent = shift();
628
- if (parent) {
629
- return () => {
630
- this.echo(parent(next()));
631
- };
632
- } else {
633
- return () => {};
634
- }
635
- };
636
- this.echo(shift()(next()));
637
- }
638
- },
639
- /** @type {function} */
640
- hasBlock: {
641
- value(name) {
642
- return this.getBlocks().hasOwnProperty(name);
643
- }
644
- },
645
- /** @type {function} */
646
- include: {
647
- value(path, data, cx) {
648
- const context = cx === false ? {} : this.clone(true);
649
- const params = Object.assign(context, data || {});
650
- const promise = this.render(path, params);
651
- this.echo(promise);
652
- }
653
- },
654
- /** @type {function} */
655
- use: {
656
- value(path, namespace) {
657
- this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
658
- const list = this.getMacro();
659
- each(exports$1, (macro, name) => {
660
- list[[namespace, name].join('.')] = macro;
661
- });
662
- }));
663
- }
664
- },
665
- /** @type {function} */
666
- async: {
667
- value(promise, callback) {
668
- this.echo(Promise.resolve(promise).then(callback));
669
- }
670
- },
671
- /** @type {function} */
672
- get: {
673
- value(name, defaults) {
674
- const path = getPath(this, name, true);
675
- const result = path.shift();
676
- const prop = path.pop();
677
- return hasProp(result, prop) ? result[prop] : defaults;
678
- }
679
- },
680
- /** @type {function} */
681
- set: {
682
- value(name, value) {
683
- const path = getPath(this, name, false);
684
- const result = path.shift();
685
- const prop = path.pop();
686
- if (this.getParentTemplate() && hasProp(result, prop)) {
687
- return result[prop];
664
+ }
665
+ },
666
+ block: {
667
+ value(name, callback) {
668
+ const blocks = this.getBlocks();
669
+ blocks[name] = blocks[name] || [];
670
+ blocks[name].push(this.fn(callback));
671
+ if (this.getExtend()) return;
672
+ const context = this;
673
+ const list = Object.assign([], blocks[name]);
674
+ const shift = function () {
675
+ return list.shift();
676
+ };
677
+ const next = function () {
678
+ const parent = shift();
679
+ if (parent) {
680
+ return function () {
681
+ context.echo(parent(next()));
682
+ };
683
+ } else {
684
+ return function () {};
688
685
  }
689
- return result[prop] = value;
686
+ };
687
+ this.echo(shift()(next()));
688
+ }
689
+ },
690
+ hasBlock: {
691
+ value(name) {
692
+ return this.getBlocks().hasOwnProperty(name);
693
+ }
694
+ },
695
+ include: {
696
+ value(path, data, cx) {
697
+ const context = cx === false ? {} : this.clone(true);
698
+ const params = Object.assign(context, data || {});
699
+ const promise = this.render(path, params);
700
+ this.echo(promise);
701
+ }
702
+ },
703
+ use: {
704
+ value(path, namespace) {
705
+ this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
706
+ const list = this.getMacro();
707
+ each(exports$1, (macro, name) => {
708
+ list[[namespace, name].join('.')] = macro;
709
+ });
710
+ }));
711
+ }
712
+ },
713
+ get: {
714
+ value(name, defaults) {
715
+ const path = getPath(this, name, true);
716
+ const result = path.shift();
717
+ const prop = path.pop();
718
+ return hasProp(result, prop) ? result[prop] : defaults;
719
+ }
720
+ },
721
+ set: {
722
+ value(name, value) {
723
+ const path = getPath(this, name, false);
724
+ const result = path.shift();
725
+ const prop = path.pop();
726
+ if (this.getParentTemplate() && hasProp(result, prop)) {
727
+ return result[prop];
690
728
  }
729
+ return result[prop] = value;
730
+ }
731
+ },
732
+ each: {
733
+ value(object, callback) {
734
+ if (isString(object)) {
735
+ object = this.get(object, []);
736
+ }
737
+ each(object, callback);
691
738
  },
692
- /** @type {function} */
693
- each: {
694
- value(object, callback) {
695
- if (isString(object)) {
696
- object = this.get(object, []);
697
- }
698
- each(object, callback);
699
- },
700
- writable: true
701
- },
702
- /** @type {function} */
703
- el: {
704
- value(tag, attr, content) {
705
- content = isFunction(content) ? this.fn(content)() : content;
706
- this.echo(Promise.resolve(content).then(content => element(tag, attr, content)));
707
- },
708
- writable: true
739
+ writable: true
740
+ },
741
+ el: {
742
+ value(tag, attr, content) {
743
+ content = isFunction(content) ? this.fn(content)() : content;
744
+ this.echo(Promise.resolve(content).then(content => element(tag, attr, content)));
709
745
  },
710
- /** @type {function} */
711
- ui: {
712
- value(layout) {},
713
- writable: true
714
- }
715
- });
716
- return EjsContext;
717
- };
718
- class Context {
719
- #context;
720
- static exports = ['create', 'globals', 'helpers'];
721
- constructor(options, methods) {
722
- bindContext(this, this.constructor.exports);
723
- this.configure(options, methods);
724
- }
725
- create(data) {
726
- return new this.#context(data);
727
- }
728
- helpers(methods) {
729
- Object.assign(this.#context.prototype, methods);
746
+ writable: true
747
+ },
748
+ ui: {
749
+ value() {},
750
+ writable: true
751
+ },
752
+ require: {
753
+ value() {},
754
+ writable: true
755
+ },
756
+ render: {
757
+ value() {},
758
+ writable: true
730
759
  }
731
- configure(options, methods) {
732
- this.#context = createContext$1(options, methods);
760
+ });
761
+ Object.entries(methods).forEach(_ref => {
762
+ let [name, value] = _ref;
763
+ if (isFunction(value) && globals.includes(name)) {
764
+ value = value.bind(Context.prototype);
733
765
  }
766
+ Context.prototype[name] = value;
767
+ });
768
+ return Context;
769
+ };
770
+ var _context$1 = /*#__PURE__*/new WeakMap();
771
+ class EjsContext {
772
+ constructor(options, methods) {
773
+ _classPrivateFieldInitSpec(this, _context$1, void 0);
774
+ bindContext(this, this.constructor.exports);
775
+ this.configure(options, methods);
734
776
  }
735
-
736
- class EjsInstance {
737
- #cache;
738
- #context;
739
- #compiler;
740
- #template;
741
- #config = {};
742
- #methods = {};
743
- static exports = ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers'];
744
- constructor() {
745
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
746
- bindContext(this, this.constructor.exports);
747
- this.#methods = {};
748
- this.#config = configSchema({}, options);
749
- this.#context = new Context(this.#config, this.#methods);
750
- this.#compiler = new Compiler(this.#config);
751
- this.#cache = new Cache(this.#config);
752
- this.#template = new Template(this.#config, this.#cache, this.#compiler);
753
- this.helpers({
754
- render: this.render,
755
- require: this.require
756
- });
757
- }
758
- create(options) {
759
- return new this.constructor(options);
760
- }
761
- configure(options) {
762
- if (options) {
763
- configSchema(this.#config, options);
764
- this.#context.configure(this.#config, this.#methods);
765
- this.#compiler.configure(this.#config);
766
- this.#cache.configure(this.#config);
767
- this.#template.configure(this.#config);
768
- }
769
- return this.#config;
770
- }
771
- createContext(data) {
772
- return this.#context.create(data);
773
- }
774
- preload(list) {
775
- return this.#cache.load(list || {});
776
- }
777
- compile(content, path) {
778
- return this.#compiler.compile(content, path);
779
- }
780
- helpers(methods) {
781
- this.#context.helpers(Object.assign(this.#methods, methods));
782
- }
783
- async render(name, params) {
784
- const data = this.createContext(params);
785
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
786
- }
787
- async require(name) {
788
- const data = this.createContext({});
789
- return this.#output(this.#path(name), data).then(() => data.getMacro());
790
- }
791
- #path(name) {
792
- const ext = name.split('.').pop();
793
- if (ext !== this.#config.extension) {
794
- name = [name, this.#config.extension].join('.');
795
- }
796
- return name;
797
- }
798
- #output(path, data) {
799
- return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useSafeValue]));
800
- }
801
- #renderLayout(name, params, parentTemplate) {
802
- const data = this.createContext(params);
803
- if (parentTemplate) data.setParentTemplate(parentTemplate);
804
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
805
- }
806
- #outputContent(name, data) {
807
- return content => {
808
- if (data.getExtend()) {
809
- data.setExtend(false);
810
- return this.#renderLayout(data.getLayout(), data, name);
811
- }
812
- return content;
813
- };
814
- }
777
+ create(data) {
778
+ return new (_classPrivateFieldGet2(_context$1, this))(data);
779
+ }
780
+ helpers(methods) {
781
+ Object.assign(_classPrivateFieldGet2(_context$1, this).prototype, methods);
815
782
  }
783
+ configure(options, methods) {
784
+ _classPrivateFieldSet2(_context$1, this, createContext$1(options, methods));
785
+ }
786
+ }
787
+ _defineProperty(EjsContext, "exports", ['create', 'globals', 'helpers']);
816
788
 
817
- const httpRequest = (path, template) => {
818
- return fetch(joinPath(path, template)).then(response => {
819
- if (response.ok) return response.text();
820
- throw new TemplateNotFound(`template ${path} / ${template} not found`);
821
- }, reason => {
822
- return new TemplateError(reason);
789
+ var _cache = /*#__PURE__*/new WeakMap();
790
+ var _context = /*#__PURE__*/new WeakMap();
791
+ var _compiler = /*#__PURE__*/new WeakMap();
792
+ var _template = /*#__PURE__*/new WeakMap();
793
+ var _config = /*#__PURE__*/new WeakMap();
794
+ var _methods = /*#__PURE__*/new WeakMap();
795
+ var _EjsInstance_brand = /*#__PURE__*/new WeakSet();
796
+ class EjsInstance {
797
+ /**
798
+ *
799
+ * @param {EjsConfig} options
800
+ */
801
+ constructor() {
802
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
803
+ _classPrivateMethodInitSpec(this, _EjsInstance_brand);
804
+ _classPrivateFieldInitSpec(this, _cache, void 0);
805
+ _classPrivateFieldInitSpec(this, _context, void 0);
806
+ _classPrivateFieldInitSpec(this, _compiler, void 0);
807
+ _classPrivateFieldInitSpec(this, _template, void 0);
808
+ _classPrivateFieldInitSpec(this, _config, {});
809
+ _classPrivateFieldInitSpec(this, _methods, {});
810
+ bindContext(this, this.constructor.exports);
811
+ _classPrivateFieldSet2(_methods, this, {});
812
+ _classPrivateFieldSet2(_config, this, configSchema({}, options));
813
+ _classPrivateFieldSet2(_context, this, new EjsContext(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this)));
814
+ _classPrivateFieldSet2(_compiler, this, new EjsCompiler(_classPrivateFieldGet2(_config, this)));
815
+ _classPrivateFieldSet2(_cache, this, new EjsCache(_classPrivateFieldGet2(_config, this)));
816
+ _classPrivateFieldSet2(_template, this, new EjsTemplate(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
817
+ this.helpers({
818
+ render: this.render,
819
+ require: this.require
823
820
  });
821
+ }
822
+ create(options) {
823
+ return new this.constructor(options);
824
+ }
825
+ configure(options) {
826
+ if (options) {
827
+ configSchema(_classPrivateFieldGet2(_config, this), options);
828
+ _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this));
829
+ _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
830
+ _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
831
+ _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
832
+ }
833
+ return _classPrivateFieldGet2(_config, this);
834
+ }
835
+ createContext(data) {
836
+ return _classPrivateFieldGet2(_context, this).create(data);
837
+ }
838
+ preload(list) {
839
+ return _classPrivateFieldGet2(_cache, this).load(list || {});
840
+ }
841
+ compile(content, path) {
842
+ return _classPrivateFieldGet2(_compiler, this).compile(content, path);
843
+ }
844
+ helpers(methods) {
845
+ _classPrivateFieldGet2(_context, this).helpers(Object.assign(_classPrivateFieldGet2(_methods, this), methods));
846
+ }
847
+ async render(name, params) {
848
+ const data = this.createContext(params);
849
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
850
+ }
851
+ async require(name) {
852
+ const data = this.createContext({});
853
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(() => data.getMacro());
854
+ }
855
+ }
856
+ function _path(name) {
857
+ const ext = name.split('.').pop();
858
+ if (ext !== _classPrivateFieldGet2(_config, this).extension) {
859
+ name = [name, _classPrivateFieldGet2(_config, this).extension].join('.');
860
+ }
861
+ return name;
862
+ }
863
+ function _output(path, data) {
864
+ return _classPrivateFieldGet2(_template, this).get(path).then(callback => callback.apply(data, [data, data.useComponent(), data.useElement(), data.useBuffer(), data.useEscapeValue()]));
865
+ }
866
+ function _renderLayout(name, params, parentTemplate) {
867
+ const data = this.createContext(params);
868
+ if (parentTemplate) data.setParentTemplate(parentTemplate);
869
+ return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
870
+ }
871
+ function _outputContent(name, data) {
872
+ return content => {
873
+ if (data.getExtend()) {
874
+ data.setExtend(false);
875
+ return _assertClassBrand(_EjsInstance_brand, this, _renderLayout).call(this, data.getLayout(), data, name);
876
+ }
877
+ return content;
824
878
  };
879
+ }
880
+ _defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
825
881
 
826
- const {
827
- render,
828
- createContext,
829
- compile,
830
- helpers,
831
- preload,
832
- configure,
833
- create
834
- } = new EjsInstance({
835
- resolver: httpRequest
836
- });
882
+ const resolver = async (path, template, error) => {
883
+ return fetch(joinPath(path, template)).then(response => {
884
+ if (response.ok) return response.text();
885
+ return error(1, "template ".concat(template, " not found"));
886
+ }, reason => error(0, reason));
887
+ };
888
+ const {
889
+ render,
890
+ configure,
891
+ create,
892
+ helpers,
893
+ createContext,
894
+ compile,
895
+ preload
896
+ } = new EjsInstance({
897
+ resolver
898
+ });
837
899
 
838
- exports.TemplateError = TemplateError;
839
- exports.TemplateNotFound = TemplateNotFound;
840
- exports.TemplateSyntaxError = TemplateSyntaxError;
841
- exports.compile = compile;
842
- exports.configure = configure;
843
- exports.create = create;
844
- exports.createContext = createContext;
845
- exports.helpers = helpers;
846
- exports.preload = preload;
847
- exports.render = render;
900
+ exports.compile = compile;
901
+ exports.configure = configure;
902
+ exports.create = create;
903
+ exports.createContext = createContext;
904
+ exports.helpers = helpers;
905
+ exports.preload = preload;
906
+ exports.render = render;
848
907
 
849
908
  }));