@kosatyi/ejs 0.0.110 → 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,813 +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 escapeValue = (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 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
- }
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;
166
226
  }
167
227
  }
168
- const error = (code, content) => {
169
- throw new EjsError(code, content);
170
- };
228
+ }
229
+ const error = (code, content) => {
230
+ throw new EjsError(code, content);
231
+ };
171
232
 
172
- class EjsTemplate {
173
- #path;
174
- #resolver;
175
- #cache;
176
- #compiler;
177
- static exports = ['configure', 'get'];
178
- constructor(options, cache, compiler) {
179
- bindContext(this, this.constructor.exports);
180
- this.#cache = cache;
181
- this.#compiler = compiler;
182
- this.configure(options ?? {});
183
- }
184
- configure(options) {
185
- this.#path = options.path;
186
- if (isFunction(options.resolver)) {
187
- this.#resolver = options.resolver;
188
- }
189
- }
190
- #resolve(template) {
191
- const cached = this.#cache.get(template);
192
- if (cached instanceof Promise) return cached;
193
- const result = Promise.resolve(this.#resolver(this.#path, template, error));
194
- this.#cache.set(template, result);
195
- return result;
196
- }
197
- #compile(content, template) {
198
- const cached = this.#cache.get(template);
199
- if (typeof cached === 'function') return cached;
200
- if (typeof content === 'string') {
201
- content = this.#compiler.compile(content, template);
202
- }
203
- if (typeof content === 'function') {
204
- this.#cache.set(template, content);
205
- return content;
206
- }
207
- }
208
- get(template) {
209
- return this.#resolve(template).then(content => {
210
- return this.#compile(content, template);
211
- });
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);
212
254
  }
213
255
  }
214
-
215
- 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}('`]];
216
- const tokensMatch = (regex, content, callback) => {
217
- let index = 0;
218
- content.replace(regex, function () {
219
- const params = [].slice.call(arguments, 0, -1);
220
- const offset = params.pop();
221
- const match = params.shift();
222
- callback(params, index, offset);
223
- index = offset + match.length;
224
- return match;
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);
225
259
  });
226
- };
227
- class EjsCompiler {
228
- #config = {};
229
- static exports = ['configure', 'compile'];
230
- constructor(options) {
231
- bindContext(this, this.constructor.exports);
232
- this.configure(options);
233
- }
234
- configure(options) {
235
- this.#config.strict = options.strict;
236
- this.#config.rmWhitespace = options.rmWhitespace;
237
- this.#config.token = options.token;
238
- this.#config.vars = options.vars;
239
- this.#config.globals = options.globals;
240
- this.#config.legacy = options.legacy ?? true;
241
- this.#config.slurp = {
242
- match: '[s\t\n]*',
243
- start: [this.#config.token.start, '_'],
244
- end: ['_', this.#config.token.end]
245
- };
246
- this.#config.matches = [];
247
- this.#config.formats = [];
248
- for (const [symbol, format] of tokenList) {
249
- this.#config.matches.push(this.#config.token.start.concat(symbol).concat(this.#config.token.regex).concat(this.#config.token.end));
250
- this.#config.formats.push(format);
251
- }
252
- this.#config.regex = new RegExp(this.#config.matches.join('|').concat('|$'), 'g');
253
- this.#config.slurpStart = new RegExp([this.#config.slurp.match, this.#config.slurp.start.join('')].join(''), 'gm');
254
- this.#config.slurpEnd = new RegExp([this.#config.slurp.end.join(''), this.#config.slurp.match].join(''), 'gm');
255
- if (this.#config.globals.length) {
256
- if (this.#config.legacy) {
257
- this.#config.globalVariables = `const ${this.#config.globals.map(name => `${name}=${this.#config.vars.SCOPE}.${name}`).join(',')};`;
258
- } else {
259
- this.#config.globalVariables = `const {${this.#config.globals.join(',')}} = ${this.#config.vars.SCOPE};`;
260
- }
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, ";");
261
328
  }
262
329
  }
263
- compile(content, path) {
264
- const GLOBALS = this.#config.globalVariables;
265
- const {
266
- SCOPE,
267
- SAFE,
268
- BUFFER,
269
- COMPONENT,
270
- ELEMENT
271
- } = this.#config.vars;
272
- if (this.#config.rmWhitespace) {
273
- content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
274
- }
275
- content = String(content).replace(this.#config.slurpStart, this.#config.token.start).replace(this.#config.slurpEnd, this.#config.token.end);
276
- let OUTPUT = `${BUFFER}('`;
277
- tokensMatch(this.#config.regex, content, (params, index, offset) => {
278
- OUTPUT += symbols(content.slice(index, offset));
279
- params.forEach((value, index) => {
280
- if (value) {
281
- OUTPUT += this.#config.formats[index](value.trim(), BUFFER, SAFE);
282
- }
283
- });
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
+ }
284
351
  });
285
- OUTPUT += `');`;
286
- OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e)}`;
287
- if (this.#config.strict === false) {
288
- OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
289
- }
290
- OUTPUT = `${BUFFER}.start();${OUTPUT}return ${BUFFER}.end();`;
291
- OUTPUT += `\n//# sourceURL=${path}`;
292
- if (GLOBALS) {
293
- OUTPUT = `${GLOBALS}\n${OUTPUT}`;
294
- }
295
- try {
296
- const params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE];
297
- const result = Function.apply(null, params.concat(OUTPUT));
298
- result.source = `(function(${params.join(',')}){\n${OUTPUT}\n});`;
299
- return result;
300
- } catch (error) {
301
- error.filename = path;
302
- error.source = OUTPUT;
303
- throw error;
304
- }
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);
305
372
  }
306
373
  }
374
+ }
375
+ _defineProperty(EjsCompiler, "exports", ['configure', 'compile']);
307
376
 
308
- class EjsCache {
309
- static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
310
- #cache = true;
311
- #precompiled;
312
- #list = {};
313
- constructor(options) {
314
- bindContext(this, this.constructor.exports);
315
- this.configure(options);
316
- }
317
- get(key) {
318
- if (this.#cache) {
319
- return this.#list[key];
320
- }
321
- }
322
- set(key, value) {
323
- if (this.#cache) {
324
- this.#list[key] = value;
325
- }
326
- }
327
- exist(key) {
328
- if (this.#cache) {
329
- return this.#list.hasOwnProperty(key);
330
- }
331
- }
332
- clear() {
333
- Object.keys(this.#list).forEach(this.remove);
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];
334
391
  }
335
- remove(key) {
336
- delete this.#list[key];
392
+ }
393
+ set(key, value) {
394
+ if (_classPrivateFieldGet2(_cache$1, this)) {
395
+ _classPrivateFieldGet2(_list, this)[key] = value;
337
396
  }
338
- resolve(key) {
339
- return Promise.resolve(this.get(key));
397
+ }
398
+ exist(key) {
399
+ if (_classPrivateFieldGet2(_cache$1, this)) {
400
+ return _classPrivateFieldGet2(_list, this).hasOwnProperty(key);
340
401
  }
341
- load(data) {
342
- if (this.#cache) {
343
- Object.assign(this.#list, data || {});
344
- }
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 || {});
345
415
  }
346
- configure(options) {
347
- this.#cache = options.cache;
348
- this.#precompiled = options.precompiled;
349
- if (typeof window === 'object') {
350
- this.load(window[this.#precompiled]);
351
- }
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)]);
352
422
  }
353
423
  }
424
+ }
425
+ _defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
354
426
 
355
- const selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
356
- const space = ' ';
357
- const quote = '"';
358
- const equal = '=';
359
- const slash = '/';
360
- const lt = '<';
361
- const gt = '>';
362
- const eachAttribute = _ref => {
363
- let [key, value] = _ref;
364
- if (value !== null && value !== undefined) {
365
- return [entities(key), [quote, entities(value), quote].join('')].join(equal);
366
- }
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);
438
+ }
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);
447
+ }
448
+ if (hasClosedTag) {
449
+ result.push([lt, slash, tag, gt].join(''));
450
+ }
451
+ return result.join('');
452
+ };
453
+
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);
367
470
  };
368
- const element = (tag, attrs, content) => {
369
- const result = [];
370
- const hasClosedTag = selfClosed.indexOf(tag) === -1;
371
- const attributes = Object.entries(attrs ?? {}).map(eachAttribute).filter(e => e).join(space);
372
- result.push([lt, tag, space, attributes, gt].join(''));
373
- if (content && hasClosedTag) {
374
- result.push(Array.isArray(content) ? content.join('') : content);
375
- }
376
- if (hasClosedTag) {
377
- result.push([lt, slash, tag, gt].join(''));
378
- }
379
- return result.join('');
471
+ EjsBuffer.start = () => {
472
+ array = [];
380
473
  };
381
-
382
- const resolve = list => {
383
- return Promise.all(list || []).then(list => list.join('')).catch(e => {
384
- return error(500, e);
385
- });
474
+ EjsBuffer.backup = () => {
475
+ store.push(array.concat());
476
+ array = [];
386
477
  };
387
- const reject = e => {
388
- return Promise.reject(error(500, e));
478
+ EjsBuffer.restore = () => {
479
+ const result = array.concat();
480
+ array = store.pop();
481
+ return resolve(result);
389
482
  };
390
- const EjsBuffer = () => {
391
- let store = [];
392
- let array = [];
393
- /**
394
- *
395
- * @param value
396
- * @constructor
397
- */
398
- const EjsBuffer = value => {
399
- array.push(value);
400
- };
401
- EjsBuffer.start = () => {
402
- array = [];
403
- };
404
- EjsBuffer.backup = () => {
405
- store.push(array.concat());
406
- array = [];
407
- };
408
- EjsBuffer.restore = () => {
409
- const result = array.concat();
410
- array = store.pop();
411
- return resolve(result);
412
- };
413
- EjsBuffer.error = e => {
414
- return reject(e);
415
- };
416
- EjsBuffer.end = () => {
417
- return resolve(array);
418
- };
419
- return EjsBuffer;
483
+ EjsBuffer.error = e => {
484
+ return reject(e);
485
+ };
486
+ EjsBuffer.end = () => {
487
+ return resolve(array);
420
488
  };
489
+ return EjsBuffer;
490
+ };
421
491
 
422
- const PARENT = Symbol('EjsContext.parentTemplate');
423
- const createContext$1 = (config, methods) => {
424
- const {
425
- BLOCKS,
426
- MACRO,
427
- EXTEND,
428
- LAYOUT,
429
- BUFFER,
430
- SAFE,
431
- SCOPE,
432
- COMPONENT,
433
- ELEMENT
434
- } = config.vars;
435
- const globals = config.globals || [];
436
- 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) {
437
508
  this[PARENT] = null;
438
509
  this[BLOCKS] = {};
439
510
  this[MACRO] = {};
440
511
  Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
441
512
  }
442
- Object.defineProperty(EjsContext.prototype, BUFFER, {
513
+ }
514
+ Object.defineProperties(Context.prototype, {
515
+ [BUFFER]: {
443
516
  value: EjsBuffer()
444
- });
445
- Object.defineProperty(EjsContext.prototype, BLOCKS, {
517
+ },
518
+ [BLOCKS]: {
446
519
  value: {},
447
520
  writable: true
448
- });
449
- Object.defineProperty(EjsContext.prototype, MACRO, {
521
+ },
522
+ [MACRO]: {
450
523
  value: {},
451
524
  writable: true
452
- });
453
- Object.defineProperty(EjsContext.prototype, LAYOUT, {
525
+ },
526
+ [LAYOUT]: {
454
527
  value: false,
455
528
  writable: true
456
- });
457
- Object.defineProperty(EjsContext.prototype, EXTEND, {
529
+ },
530
+ [EXTEND]: {
458
531
  value: false,
459
532
  writable: true
460
- });
461
- Object.defineProperty(EjsContext.prototype, PARENT, {
533
+ },
534
+ [PARENT]: {
462
535
  value: null,
463
536
  writable: true
464
- });
465
- Object.defineProperties(EjsContext.prototype, {
466
- setParentTemplate: {
467
- value(value) {
468
- this[PARENT] = value;
469
- return this;
470
- }
471
- },
472
- getParentTemplate: {
473
- value() {
474
- return this[PARENT];
475
- }
476
- },
477
- useEscapeValue: {
478
- get: () => escapeValue
479
- },
480
- useComponent: {
481
- get() {
482
- if (isFunction(this[COMPONENT])) {
483
- return this[COMPONENT].bind(this);
484
- } else {
485
- return function () {
486
- throw new Error(`${COMPONENT} must be a function`);
487
- };
488
- }
489
- }
490
- },
491
- useElement: {
492
- get() {
493
- if (isFunction(this[ELEMENT])) {
494
- return this[ELEMENT].bind(this);
495
- } else {
496
- return () => {
497
- throw new Error(`${ELEMENT} must be a function`);
498
- };
499
- }
500
- }
501
- },
502
- useBuffer: {
503
- get() {
504
- return this[BUFFER];
505
- }
506
- },
507
- getMacro: {
508
- value() {
509
- return this[MACRO];
510
- }
511
- },
512
- getBlocks: {
513
- value() {
514
- return this[BLOCKS];
515
- }
516
- },
517
- setExtend: {
518
- value(value) {
519
- this[EXTEND] = value;
520
- return this;
521
- }
522
- },
523
- getExtend: {
524
- value() {
525
- return this[EXTEND];
526
- }
527
- },
528
- setLayout: {
529
- value(layout) {
530
- this[LAYOUT] = layout;
531
- return this;
532
- }
533
- },
534
- getLayout: {
535
- value() {
536
- return this[LAYOUT];
537
- }
538
- },
539
- clone: {
540
- value(exclude_blocks) {
541
- const filter = [LAYOUT, EXTEND, BUFFER];
542
- if (exclude_blocks === true) {
543
- filter.push(BLOCKS);
544
- }
545
- return omit(this, filter);
546
- }
547
- },
548
- extend: {
549
- value(layout) {
550
- this.setExtend(true);
551
- this.setLayout(layout);
552
- }
553
- },
554
- echo: {
555
- value() {
556
- return [].slice.call(arguments).forEach(this.useBuffer);
557
- }
558
- },
559
- fn: {
560
- value(callback) {
561
- const context = this;
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 {
562
559
  return function () {
563
- if (isFunction(callback)) {
564
- context.useBuffer.backup();
565
- context.useBuffer(callback.apply(context, arguments));
566
- return context.useBuffer.restore();
567
- }
568
- };
569
- }
570
- },
571
- macro: {
572
- value(name, callback) {
573
- const list = this.getMacro();
574
- const macro = this.fn(callback);
575
- const context = this;
576
- list[name] = function () {
577
- return context.echo(macro.apply(undefined, arguments));
560
+ error(2, "".concat(COMPONENT, " must be a function"));
578
561
  };
579
562
  }
580
- },
581
- call: {
582
- value(name) {
583
- const list = this.getMacro();
584
- const macro = list[name];
585
- const params = [].slice.call(arguments, 1);
586
- if (isFunction(macro)) {
587
- return macro.apply(macro, params);
588
- }
589
- }
590
- },
591
- block: {
592
- value(name, callback) {
593
- const blocks = this.getBlocks();
594
- blocks[name] = blocks[name] || [];
595
- blocks[name].push(this.fn(callback));
596
- if (this.getExtend()) return;
597
- const context = this;
598
- const list = Object.assign([], blocks[name]);
599
- const shift = function () {
600
- return list.shift();
601
- };
602
- const next = function () {
603
- const parent = shift();
604
- if (parent) {
605
- return function () {
606
- context.echo(parent(next()));
607
- };
608
- } else {
609
- return function () {};
610
- }
563
+ }
564
+ },
565
+ useElement: {
566
+ value() {
567
+ if (isFunction(this[ELEMENT])) {
568
+ return this[ELEMENT].bind(this);
569
+ } else {
570
+ return () => {
571
+ error(2, "".concat(ELEMENT, " must be a function"));
611
572
  };
612
- this.echo(shift()(next()));
613
573
  }
614
- },
615
- hasBlock: {
616
- value(name) {
617
- return this.getBlocks().hasOwnProperty(name);
618
- }
619
- },
620
- include: {
621
- value(path, data, cx) {
622
- const context = cx === false ? {} : this.clone(true);
623
- const params = Object.assign(context, data || {});
624
- const promise = this.render(path, params);
625
- this.echo(promise);
626
- }
627
- },
628
- use: {
629
- value(path, namespace) {
630
- this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
631
- const list = this.getMacro();
632
- each(exports$1, (macro, name) => {
633
- list[[namespace, name].join('.')] = macro;
634
- });
635
- }));
636
- }
637
- },
638
- get: {
639
- value(name, defaults) {
640
- const path = getPath(this, name, true);
641
- const result = path.shift();
642
- const prop = path.pop();
643
- return hasProp(result, prop) ? result[prop] : defaults;
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);
644
618
  }
645
- },
646
- set: {
647
- value(name, value) {
648
- const path = getPath(this, name, false);
649
- const result = path.shift();
650
- const prop = path.pop();
651
- if (this.getParentTemplate() && hasProp(result, prop)) {
652
- return result[prop];
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();
653
642
  }
654
- return result[prop] = value;
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);
655
663
  }
656
- },
657
- each: {
658
- value(object, callback) {
659
- if (isString(object)) {
660
- object = this.get(object, []);
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 () {};
661
685
  }
662
- each(object, callback);
663
- },
664
- writable: true
665
- },
666
- el: {
667
- value(tag, attr, content) {
668
- content = isFunction(content) ? this.fn(content)() : content;
669
- this.echo(Promise.resolve(content).then(content => element(tag, attr, content)));
670
- },
671
- writable: true
672
- },
673
- ui: {
674
- value() {},
675
- writable: true
686
+ };
687
+ this.echo(shift()(next()));
676
688
  }
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);
689
+ },
690
+ hasBlock: {
691
+ value(name) {
692
+ return this.getBlocks().hasOwnProperty(name);
682
693
  }
683
- EjsContext.prototype[name] = value;
684
- });
685
- return EjsContext;
686
- };
687
- class EjsContext {
688
- #context;
689
- static exports = ['create', 'globals', 'helpers'];
690
- constructor(options, methods) {
691
- bindContext(this, this.constructor.exports);
692
- this.configure(options, methods);
693
- }
694
- create(data) {
695
- return new this.#context(data);
696
- }
697
- helpers(methods) {
698
- Object.assign(this.#context.prototype, methods);
699
- }
700
- configure(options, methods) {
701
- this.#context = createContext$1(options, methods);
702
- }
703
- }
704
-
705
- class EjsInstance {
706
- #cache;
707
- #context;
708
- #compiler;
709
- #template;
710
- #config = {};
711
- #methods = {};
712
- static exports = ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers'];
713
- constructor() {
714
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
715
- bindContext(this, this.constructor.exports);
716
- this.#methods = {};
717
- this.#config = configSchema({}, options);
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);
722
- this.helpers({
723
- render: this.render,
724
- require: this.require
725
- });
726
- }
727
- create(options) {
728
- return new this.constructor(options);
729
- }
730
- configure(options) {
731
- if (options) {
732
- configSchema(this.#config, options);
733
- this.#context.configure(this.#config, this.#methods);
734
- this.#compiler.configure(this.#config);
735
- this.#cache.configure(this.#config);
736
- this.#template.configure(this.#config);
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);
737
701
  }
738
- return this.#config;
739
- }
740
- createContext(data) {
741
- return this.#context.create(data);
742
- }
743
- preload(list) {
744
- return this.#cache.load(list || {});
745
- }
746
- compile(content, path) {
747
- return this.#compiler.compile(content, path);
748
- }
749
- helpers(methods) {
750
- this.#context.helpers(Object.assign(this.#methods, methods));
751
- }
752
- async render(name, params) {
753
- const data = this.createContext(params);
754
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
755
- }
756
- async require(name) {
757
- const data = this.createContext({});
758
- return this.#output(this.#path(name), data).then(() => data.getMacro());
759
- }
760
- #path(name) {
761
- const ext = name.split('.').pop();
762
- if (ext !== this.#config.extension) {
763
- name = [name, this.#config.extension].join('.');
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
+ }));
764
711
  }
765
- return name;
766
- }
767
- #output(path, data) {
768
- return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useEscapeValue]));
769
- }
770
- #renderLayout(name, params, parentTemplate) {
771
- const data = this.createContext(params);
772
- if (parentTemplate) data.setParentTemplate(parentTemplate);
773
- return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
774
- }
775
- #outputContent(name, data) {
776
- return content => {
777
- if (data.getExtend()) {
778
- data.setExtend(false);
779
- return this.#renderLayout(data.getLayout(), data, name);
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];
728
+ }
729
+ return result[prop] = value;
730
+ }
731
+ },
732
+ each: {
733
+ value(object, callback) {
734
+ if (isString(object)) {
735
+ object = this.get(object, []);
780
736
  }
781
- return content;
782
- };
737
+ each(object, callback);
738
+ },
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)));
745
+ },
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
759
+ }
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);
783
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);
784
776
  }
777
+ create(data) {
778
+ return new (_classPrivateFieldGet2(_context$1, this))(data);
779
+ }
780
+ helpers(methods) {
781
+ Object.assign(_classPrivateFieldGet2(_context$1, this).prototype, methods);
782
+ }
783
+ configure(options, methods) {
784
+ _classPrivateFieldSet2(_context$1, this, createContext$1(options, methods));
785
+ }
786
+ }
787
+ _defineProperty(EjsContext, "exports", ['create', 'globals', 'helpers']);
785
788
 
786
- const httpRequest = (path, template, error) => {
787
- return fetch(joinPath(path, template)).then(response => {
788
- if (response.ok) return response.text();
789
- return error(404, `template ${template} not found`);
790
- }, reason => error(500, 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
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;
791
878
  };
879
+ }
880
+ _defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
792
881
 
793
- const {
794
- render,
795
- configure,
796
- create,
797
- helpers,
798
- createContext,
799
- compile,
800
- preload
801
- } = new EjsInstance({
802
- resolver: httpRequest
803
- });
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
+ });
804
899
 
805
- exports.compile = compile;
806
- exports.configure = configure;
807
- exports.create = create;
808
- exports.createContext = createContext;
809
- exports.helpers = helpers;
810
- exports.preload = preload;
811
- 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;
812
907
 
813
908
  }));