@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.
- package/dist/cjs/browser.js +338 -279
- package/dist/cjs/bundler.js +14 -6
- package/dist/cjs/element.js +3 -3
- package/dist/cjs/index.js +406 -350
- package/dist/cjs/worker.js +341 -298
- package/dist/esm/browser.js +138 -159
- package/dist/esm/bundler.js +14 -6
- package/dist/esm/element.js +2 -2
- package/dist/esm/index.js +258 -280
- package/dist/esm/worker.js +139 -174
- package/dist/umd/browser.js +832 -773
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/element.js +4 -4
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +853 -797
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +341 -298
- package/dist/umd/worker.min.js +1 -1
- package/package.json +4 -4
- package/types/browser.d.ts +0 -6
- package/types/context.d.ts +19 -10
- package/types/ejs.d.ts +2 -5
- package/types/element.d.ts +9 -1
- package/types/error.d.ts +11 -11
- package/types/index.d.ts +0 -2
- package/types/worker.d.ts +0 -12
- package/dist/kosatyi-ejs-0.0.107.tgz +0 -0
- package/dist/kosatyi-ejs-0.0.108.tgz +0 -0
- package/dist/umd/browser.js.map +0 -7
- package/dist/umd/browser.min.js.map +0 -7
package/dist/umd/browser.js
CHANGED
|
@@ -1,849 +1,908 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"'"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
'&': '&',
|
|
147
|
+
'<': '<',
|
|
148
|
+
'>': '>',
|
|
149
|
+
'"': '"',
|
|
150
|
+
"'": '''
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
340
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
361
|
-
|
|
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
|
-
|
|
364
|
-
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
_defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
|
|
365
426
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
382
|
-
|
|
383
|
-
code = 500;
|
|
448
|
+
if (hasClosedTag) {
|
|
449
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
384
450
|
}
|
|
451
|
+
return result.join('');
|
|
452
|
+
};
|
|
385
453
|
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
390
|
-
|
|
471
|
+
EjsBuffer.start = () => {
|
|
472
|
+
array = [];
|
|
391
473
|
};
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
517
|
+
},
|
|
518
|
+
[BLOCKS]: {
|
|
455
519
|
value: {},
|
|
456
520
|
writable: true
|
|
457
|
-
}
|
|
458
|
-
|
|
521
|
+
},
|
|
522
|
+
[MACRO]: {
|
|
459
523
|
value: {},
|
|
460
524
|
writable: true
|
|
461
|
-
}
|
|
462
|
-
|
|
525
|
+
},
|
|
526
|
+
[LAYOUT]: {
|
|
463
527
|
value: false,
|
|
464
528
|
writable: true
|
|
465
|
-
}
|
|
466
|
-
|
|
529
|
+
},
|
|
530
|
+
[EXTEND]: {
|
|
467
531
|
value: false,
|
|
468
532
|
writable: true
|
|
469
|
-
}
|
|
470
|
-
|
|
533
|
+
},
|
|
534
|
+
[PARENT]: {
|
|
471
535
|
value: null,
|
|
472
536
|
writable: true
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
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
|
-
|
|
584
|
-
|
|
585
|
-
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
useElement: {
|
|
566
|
+
value() {
|
|
567
|
+
if (isFunction(this[ELEMENT])) {
|
|
568
|
+
return this[ELEMENT].bind(this);
|
|
569
|
+
} else {
|
|
586
570
|
return () => {
|
|
587
|
-
|
|
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
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
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
|
-
|
|
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
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
-
|
|
732
|
-
|
|
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
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
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
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
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
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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
|
}));
|