@kosatyi/ejs 0.0.76 → 0.0.78
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/README.md +1 -1
- package/bin/bundler.js +43 -0
- package/dist/cjs/browser.js +44 -11
- package/dist/cjs/bundler.js +171 -0
- package/dist/cjs/index.js +44 -11
- package/dist/cjs/worker.js +1278 -0
- package/dist/esm/browser.js +56 -21
- package/dist/esm/bundler.js +168 -0
- package/dist/esm/index.js +56 -21
- package/dist/esm/worker.js +1034 -0
- package/dist/umd/browser.js +44 -11
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/index.js +44 -11
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +1284 -0
- package/dist/umd/worker.min.js +1 -0
- package/package.json +23 -7
- package/types/bundler.d.ts +30 -0
- package/types/ejs.d.ts +86 -0
- package/types/global.d.ts +2 -87
- package/dist/cjs/package.json +0 -3
|
@@ -0,0 +1,1278 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _regeneratorRuntime() {
|
|
4
|
+
_regeneratorRuntime = function () {
|
|
5
|
+
return e;
|
|
6
|
+
};
|
|
7
|
+
var t,
|
|
8
|
+
e = {},
|
|
9
|
+
r = Object.prototype,
|
|
10
|
+
n = r.hasOwnProperty,
|
|
11
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
12
|
+
t[e] = r.value;
|
|
13
|
+
},
|
|
14
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
+
a = i.iterator || "@@iterator",
|
|
16
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
17
|
+
u = i.toStringTag || "@@toStringTag";
|
|
18
|
+
function define(t, e, r) {
|
|
19
|
+
return Object.defineProperty(t, e, {
|
|
20
|
+
value: r,
|
|
21
|
+
enumerable: !0,
|
|
22
|
+
configurable: !0,
|
|
23
|
+
writable: !0
|
|
24
|
+
}), t[e];
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
define({}, "");
|
|
28
|
+
} catch (t) {
|
|
29
|
+
define = function (t, e, r) {
|
|
30
|
+
return t[e] = r;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function wrap(t, e, r, n) {
|
|
34
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
35
|
+
a = Object.create(i.prototype),
|
|
36
|
+
c = new Context(n || []);
|
|
37
|
+
return o(a, "_invoke", {
|
|
38
|
+
value: makeInvokeMethod(t, r, c)
|
|
39
|
+
}), a;
|
|
40
|
+
}
|
|
41
|
+
function tryCatch(t, e, r) {
|
|
42
|
+
try {
|
|
43
|
+
return {
|
|
44
|
+
type: "normal",
|
|
45
|
+
arg: t.call(e, r)
|
|
46
|
+
};
|
|
47
|
+
} catch (t) {
|
|
48
|
+
return {
|
|
49
|
+
type: "throw",
|
|
50
|
+
arg: t
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
e.wrap = wrap;
|
|
55
|
+
var h = "suspendedStart",
|
|
56
|
+
l = "suspendedYield",
|
|
57
|
+
f = "executing",
|
|
58
|
+
s = "completed",
|
|
59
|
+
y = {};
|
|
60
|
+
function Generator() {}
|
|
61
|
+
function GeneratorFunction() {}
|
|
62
|
+
function GeneratorFunctionPrototype() {}
|
|
63
|
+
var p = {};
|
|
64
|
+
define(p, a, function () {
|
|
65
|
+
return this;
|
|
66
|
+
});
|
|
67
|
+
var d = Object.getPrototypeOf,
|
|
68
|
+
v = d && d(d(values([])));
|
|
69
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
70
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
71
|
+
function defineIteratorMethods(t) {
|
|
72
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
73
|
+
define(t, e, function (t) {
|
|
74
|
+
return this._invoke(e, t);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function AsyncIterator(t, e) {
|
|
79
|
+
function invoke(r, o, i, a) {
|
|
80
|
+
var c = tryCatch(t[r], t, o);
|
|
81
|
+
if ("throw" !== c.type) {
|
|
82
|
+
var u = c.arg,
|
|
83
|
+
h = u.value;
|
|
84
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
85
|
+
invoke("next", t, i, a);
|
|
86
|
+
}, function (t) {
|
|
87
|
+
invoke("throw", t, i, a);
|
|
88
|
+
}) : e.resolve(h).then(function (t) {
|
|
89
|
+
u.value = t, i(u);
|
|
90
|
+
}, function (t) {
|
|
91
|
+
return invoke("throw", t, i, a);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
a(c.arg);
|
|
95
|
+
}
|
|
96
|
+
var r;
|
|
97
|
+
o(this, "_invoke", {
|
|
98
|
+
value: function (t, n) {
|
|
99
|
+
function callInvokeWithMethodAndArg() {
|
|
100
|
+
return new e(function (e, r) {
|
|
101
|
+
invoke(t, n, e, r);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function makeInvokeMethod(e, r, n) {
|
|
109
|
+
var o = h;
|
|
110
|
+
return function (i, a) {
|
|
111
|
+
if (o === f) throw new Error("Generator is already running");
|
|
112
|
+
if (o === s) {
|
|
113
|
+
if ("throw" === i) throw a;
|
|
114
|
+
return {
|
|
115
|
+
value: t,
|
|
116
|
+
done: !0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
for (n.method = i, n.arg = a;;) {
|
|
120
|
+
var c = n.delegate;
|
|
121
|
+
if (c) {
|
|
122
|
+
var u = maybeInvokeDelegate(c, n);
|
|
123
|
+
if (u) {
|
|
124
|
+
if (u === y) continue;
|
|
125
|
+
return u;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
129
|
+
if (o === h) throw o = s, n.arg;
|
|
130
|
+
n.dispatchException(n.arg);
|
|
131
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
132
|
+
o = f;
|
|
133
|
+
var p = tryCatch(e, r, n);
|
|
134
|
+
if ("normal" === p.type) {
|
|
135
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
136
|
+
return {
|
|
137
|
+
value: p.arg,
|
|
138
|
+
done: n.done
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function maybeInvokeDelegate(e, r) {
|
|
146
|
+
var n = r.method,
|
|
147
|
+
o = e.iterator[n];
|
|
148
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
149
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
150
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
151
|
+
var a = i.arg;
|
|
152
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
153
|
+
}
|
|
154
|
+
function pushTryEntry(t) {
|
|
155
|
+
var e = {
|
|
156
|
+
tryLoc: t[0]
|
|
157
|
+
};
|
|
158
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
159
|
+
}
|
|
160
|
+
function resetTryEntry(t) {
|
|
161
|
+
var e = t.completion || {};
|
|
162
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
163
|
+
}
|
|
164
|
+
function Context(t) {
|
|
165
|
+
this.tryEntries = [{
|
|
166
|
+
tryLoc: "root"
|
|
167
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
168
|
+
}
|
|
169
|
+
function values(e) {
|
|
170
|
+
if (e || "" === e) {
|
|
171
|
+
var r = e[a];
|
|
172
|
+
if (r) return r.call(e);
|
|
173
|
+
if ("function" == typeof e.next) return e;
|
|
174
|
+
if (!isNaN(e.length)) {
|
|
175
|
+
var o = -1,
|
|
176
|
+
i = function next() {
|
|
177
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
178
|
+
return next.value = t, next.done = !0, next;
|
|
179
|
+
};
|
|
180
|
+
return i.next = i;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
184
|
+
}
|
|
185
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
186
|
+
value: GeneratorFunctionPrototype,
|
|
187
|
+
configurable: !0
|
|
188
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
189
|
+
value: GeneratorFunction,
|
|
190
|
+
configurable: !0
|
|
191
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
192
|
+
var e = "function" == typeof t && t.constructor;
|
|
193
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
194
|
+
}, e.mark = function (t) {
|
|
195
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
196
|
+
}, e.awrap = function (t) {
|
|
197
|
+
return {
|
|
198
|
+
__await: t
|
|
199
|
+
};
|
|
200
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
201
|
+
return this;
|
|
202
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
203
|
+
void 0 === i && (i = Promise);
|
|
204
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
205
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
206
|
+
return t.done ? t.value : a.next();
|
|
207
|
+
});
|
|
208
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
209
|
+
return this;
|
|
210
|
+
}), define(g, "toString", function () {
|
|
211
|
+
return "[object Generator]";
|
|
212
|
+
}), e.keys = function (t) {
|
|
213
|
+
var e = Object(t),
|
|
214
|
+
r = [];
|
|
215
|
+
for (var n in e) r.push(n);
|
|
216
|
+
return r.reverse(), function next() {
|
|
217
|
+
for (; r.length;) {
|
|
218
|
+
var t = r.pop();
|
|
219
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
220
|
+
}
|
|
221
|
+
return next.done = !0, next;
|
|
222
|
+
};
|
|
223
|
+
}, e.values = values, Context.prototype = {
|
|
224
|
+
constructor: Context,
|
|
225
|
+
reset: function (e) {
|
|
226
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
227
|
+
},
|
|
228
|
+
stop: function () {
|
|
229
|
+
this.done = !0;
|
|
230
|
+
var t = this.tryEntries[0].completion;
|
|
231
|
+
if ("throw" === t.type) throw t.arg;
|
|
232
|
+
return this.rval;
|
|
233
|
+
},
|
|
234
|
+
dispatchException: function (e) {
|
|
235
|
+
if (this.done) throw e;
|
|
236
|
+
var r = this;
|
|
237
|
+
function handle(n, o) {
|
|
238
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
239
|
+
}
|
|
240
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
241
|
+
var i = this.tryEntries[o],
|
|
242
|
+
a = i.completion;
|
|
243
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
244
|
+
if (i.tryLoc <= this.prev) {
|
|
245
|
+
var c = n.call(i, "catchLoc"),
|
|
246
|
+
u = n.call(i, "finallyLoc");
|
|
247
|
+
if (c && u) {
|
|
248
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
249
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
250
|
+
} else if (c) {
|
|
251
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
252
|
+
} else {
|
|
253
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
254
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
abrupt: function (t, e) {
|
|
260
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
261
|
+
var o = this.tryEntries[r];
|
|
262
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
263
|
+
var i = o;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
268
|
+
var a = i ? i.completion : {};
|
|
269
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
270
|
+
},
|
|
271
|
+
complete: function (t, e) {
|
|
272
|
+
if ("throw" === t.type) throw t.arg;
|
|
273
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
274
|
+
},
|
|
275
|
+
finish: function (t) {
|
|
276
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
277
|
+
var r = this.tryEntries[e];
|
|
278
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
catch: function (t) {
|
|
282
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
+
var r = this.tryEntries[e];
|
|
284
|
+
if (r.tryLoc === t) {
|
|
285
|
+
var n = r.completion;
|
|
286
|
+
if ("throw" === n.type) {
|
|
287
|
+
var o = n.arg;
|
|
288
|
+
resetTryEntry(r);
|
|
289
|
+
}
|
|
290
|
+
return o;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
throw new Error("illegal catch attempt");
|
|
294
|
+
},
|
|
295
|
+
delegateYield: function (e, r, n) {
|
|
296
|
+
return this.delegate = {
|
|
297
|
+
iterator: values(e),
|
|
298
|
+
resultName: r,
|
|
299
|
+
nextLoc: n
|
|
300
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
301
|
+
}
|
|
302
|
+
}, e;
|
|
303
|
+
}
|
|
304
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
305
|
+
try {
|
|
306
|
+
var info = gen[key](arg);
|
|
307
|
+
var value = info.value;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
reject(error);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (info.done) {
|
|
313
|
+
resolve(value);
|
|
314
|
+
} else {
|
|
315
|
+
Promise.resolve(value).then(_next, _throw);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function _asyncToGenerator(fn) {
|
|
319
|
+
return function () {
|
|
320
|
+
var self = this,
|
|
321
|
+
args = arguments;
|
|
322
|
+
return new Promise(function (resolve, reject) {
|
|
323
|
+
var gen = fn.apply(self, args);
|
|
324
|
+
function _next(value) {
|
|
325
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
326
|
+
}
|
|
327
|
+
function _throw(err) {
|
|
328
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
329
|
+
}
|
|
330
|
+
_next(undefined);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function _defineProperty(obj, key, value) {
|
|
335
|
+
key = _toPropertyKey(key);
|
|
336
|
+
if (key in obj) {
|
|
337
|
+
Object.defineProperty(obj, key, {
|
|
338
|
+
value: value,
|
|
339
|
+
enumerable: true,
|
|
340
|
+
configurable: true,
|
|
341
|
+
writable: true
|
|
342
|
+
});
|
|
343
|
+
} else {
|
|
344
|
+
obj[key] = value;
|
|
345
|
+
}
|
|
346
|
+
return obj;
|
|
347
|
+
}
|
|
348
|
+
function _toPrimitive(input, hint) {
|
|
349
|
+
if (typeof input !== "object" || input === null) return input;
|
|
350
|
+
var prim = input[Symbol.toPrimitive];
|
|
351
|
+
if (prim !== undefined) {
|
|
352
|
+
var res = prim.call(input, hint || "default");
|
|
353
|
+
if (typeof res !== "object") return res;
|
|
354
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
355
|
+
}
|
|
356
|
+
return (hint === "string" ? String : Number)(input);
|
|
357
|
+
}
|
|
358
|
+
function _toPropertyKey(arg) {
|
|
359
|
+
var key = _toPrimitive(arg, "string");
|
|
360
|
+
return typeof key === "symbol" ? key : String(key);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
var typeProp = function typeProp() {
|
|
364
|
+
var args = [].slice.call(arguments);
|
|
365
|
+
var callback = args.shift();
|
|
366
|
+
return args.filter(callback).pop();
|
|
367
|
+
};
|
|
368
|
+
var isArray = function isArray(v) {
|
|
369
|
+
return Array.isArray(v);
|
|
370
|
+
};
|
|
371
|
+
var isFunction = function isFunction(v) {
|
|
372
|
+
return typeof v === 'function';
|
|
373
|
+
};
|
|
374
|
+
var isString = function isString(v) {
|
|
375
|
+
return typeof v === 'string';
|
|
376
|
+
};
|
|
377
|
+
var isBoolean = function isBoolean(v) {
|
|
378
|
+
return typeof v === 'boolean';
|
|
379
|
+
};
|
|
380
|
+
var isUndefined = function isUndefined(v) {
|
|
381
|
+
return typeof v === 'undefined';
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
385
|
+
var isNode = function isNode() {
|
|
386
|
+
return isNodeEnv;
|
|
387
|
+
};
|
|
388
|
+
var symbolEntities = {
|
|
389
|
+
"'": "'",
|
|
390
|
+
'\\': '\\',
|
|
391
|
+
'\r': 'r',
|
|
392
|
+
'\n': 'n',
|
|
393
|
+
'\t': 't',
|
|
394
|
+
"\u2028": 'u2028',
|
|
395
|
+
"\u2029": 'u2029'
|
|
396
|
+
};
|
|
397
|
+
var htmlEntities = {
|
|
398
|
+
'&': '&',
|
|
399
|
+
'<': '<',
|
|
400
|
+
'>': '>',
|
|
401
|
+
'"': '"',
|
|
402
|
+
"'": '''
|
|
403
|
+
};
|
|
404
|
+
var regexKeys = function regexKeys(obj) {
|
|
405
|
+
return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
|
|
406
|
+
};
|
|
407
|
+
var htmlEntitiesMatch = regexKeys(htmlEntities);
|
|
408
|
+
var symbolEntitiesMatch = regexKeys(symbolEntities);
|
|
409
|
+
var entities = function entities() {
|
|
410
|
+
var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
411
|
+
return ('' + string).replace(htmlEntitiesMatch, function (match) {
|
|
412
|
+
return htmlEntities[match];
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var symbols = function symbols(string) {
|
|
416
|
+
return ('' + string).replace(symbolEntitiesMatch, function (match) {
|
|
417
|
+
return '\\' + symbolEntities[match];
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
var safeValue = function safeValue(value, escape) {
|
|
421
|
+
var check = value;
|
|
422
|
+
return check == null ? '' : escape === true ? entities(check) : check;
|
|
423
|
+
};
|
|
424
|
+
var instanceOf = function instanceOf(object, instance) {
|
|
425
|
+
return Boolean(object instanceof instance);
|
|
426
|
+
};
|
|
427
|
+
var getPath = function getPath(context, name, strict) {
|
|
428
|
+
var data = context;
|
|
429
|
+
var chunks = String(name).split('.');
|
|
430
|
+
var prop = chunks.pop();
|
|
431
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
432
|
+
var part = chunks[i];
|
|
433
|
+
if (isFunction(data['toJSON'])) {
|
|
434
|
+
data = data.toJSON();
|
|
435
|
+
}
|
|
436
|
+
if (strict && data.hasOwnProperty(part) === false) {
|
|
437
|
+
data = {};
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
data = data[part] = data[part] || {};
|
|
441
|
+
}
|
|
442
|
+
if (isFunction(data['toJSON'])) {
|
|
443
|
+
data = data.toJSON();
|
|
444
|
+
}
|
|
445
|
+
return [data, prop];
|
|
446
|
+
};
|
|
447
|
+
var ext = function ext(path, defaults) {
|
|
448
|
+
var ext = path.split('.').pop();
|
|
449
|
+
if (ext !== defaults) {
|
|
450
|
+
path = [path, defaults].join('.');
|
|
451
|
+
}
|
|
452
|
+
return path;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* @type {<T extends {}, U, V, W,Y>(T,U,V,W,Y)=> T & U & V & W & Y}
|
|
457
|
+
*/
|
|
458
|
+
var extend = function extend(target) {
|
|
459
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
460
|
+
args[_key - 1] = arguments[_key];
|
|
461
|
+
}
|
|
462
|
+
return args.filter(function (source) {
|
|
463
|
+
return source;
|
|
464
|
+
}).reduce(function (target, source) {
|
|
465
|
+
return Object.assign(target, source);
|
|
466
|
+
}, target);
|
|
467
|
+
};
|
|
468
|
+
var noop = function noop() {};
|
|
469
|
+
var each = function each(object, callback) {
|
|
470
|
+
var prop;
|
|
471
|
+
for (prop in object) {
|
|
472
|
+
if (hasProp(object, prop)) {
|
|
473
|
+
callback(object[prop], prop, object);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
var map = function map(object, callback, context) {
|
|
478
|
+
var result = [];
|
|
479
|
+
each(object, function (value, key, object) {
|
|
480
|
+
var item = callback(value, key, object);
|
|
481
|
+
if (isUndefined(item) === false) {
|
|
482
|
+
result.push(item);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
return result;
|
|
486
|
+
};
|
|
487
|
+
var filter = function filter(object, callback, context) {
|
|
488
|
+
var isArray = object instanceof Array;
|
|
489
|
+
var result = isArray ? [] : {};
|
|
490
|
+
each(object, function (value, key, object) {
|
|
491
|
+
var item = callback(value, key, object);
|
|
492
|
+
if (isUndefined(item) === false) {
|
|
493
|
+
if (isArray) {
|
|
494
|
+
result.push(item);
|
|
495
|
+
} else {
|
|
496
|
+
result[key] = item;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return result;
|
|
501
|
+
};
|
|
502
|
+
var omit = function omit(object, list) {
|
|
503
|
+
return filter(object, function (value, key) {
|
|
504
|
+
if (list.indexOf(key) === -1) {
|
|
505
|
+
return value;
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
var resolve$1 = function resolve(value, callback, context) {
|
|
510
|
+
return Promise.resolve(value).then(callback.bind(context));
|
|
511
|
+
};
|
|
512
|
+
var hasProp = function hasProp(object, prop) {
|
|
513
|
+
return object && object.hasOwnProperty(prop);
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
var defaults = {};
|
|
517
|
+
defaults["export"] = 'ejsPrecompiled';
|
|
518
|
+
defaults.cache = true;
|
|
519
|
+
defaults.chokidar = null;
|
|
520
|
+
defaults.path = 'views';
|
|
521
|
+
defaults.resolver = function (path, template) {
|
|
522
|
+
return Promise.resolve(['resolver is not defined', path, template].join(' '));
|
|
523
|
+
};
|
|
524
|
+
defaults.extension = 'ejs';
|
|
525
|
+
defaults.rmWhitespace = true;
|
|
526
|
+
defaults.withObject = true;
|
|
527
|
+
defaults.globalHelpers = [];
|
|
528
|
+
defaults.vars = {
|
|
529
|
+
SCOPE: 'ejs',
|
|
530
|
+
COMPONENT: 'ui',
|
|
531
|
+
EXTEND: '$$e',
|
|
532
|
+
BUFFER: '$$a',
|
|
533
|
+
LAYOUT: '$$l',
|
|
534
|
+
BLOCKS: '$$b',
|
|
535
|
+
MACRO: '$$m',
|
|
536
|
+
SAFE: '$$v'
|
|
537
|
+
};
|
|
538
|
+
defaults.token = {
|
|
539
|
+
start: '<%',
|
|
540
|
+
end: '%>',
|
|
541
|
+
regex: '([\\s\\S]+?)'
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
var configSchema = function configSchema(config, options) {
|
|
545
|
+
extend(config, {
|
|
546
|
+
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
547
|
+
"export": typeProp(isString, defaults["export"], config["export"], options["export"]),
|
|
548
|
+
resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
|
|
549
|
+
extension: typeProp(isString, defaults.extension, config.extension, options.extension),
|
|
550
|
+
withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
|
|
551
|
+
rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
|
|
552
|
+
cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
|
|
553
|
+
token: extend({}, defaults.token, config.token, options.token),
|
|
554
|
+
vars: extend({}, defaults.vars, config.vars, options.vars),
|
|
555
|
+
globalHelpers: typeProp(isArray, defaults.globalHelpers, config.globalHelpers, options.globalHelpers)
|
|
556
|
+
});
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
560
|
+
function Cache(config) {
|
|
561
|
+
if (instanceOf(this, Cache) === false) return new Cache();
|
|
562
|
+
var cache = {
|
|
563
|
+
enabled: true,
|
|
564
|
+
list: {}
|
|
565
|
+
};
|
|
566
|
+
this.configure = function (config) {
|
|
567
|
+
cache.enabled = config.cache;
|
|
568
|
+
if (isNode() === false) {
|
|
569
|
+
this.load(global[config["export"]]);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
this.clear = function () {
|
|
573
|
+
cache.list = {};
|
|
574
|
+
};
|
|
575
|
+
this.load = function (data) {
|
|
576
|
+
if (cache.enabled) {
|
|
577
|
+
extend(cache.list, data || {});
|
|
578
|
+
}
|
|
579
|
+
return this;
|
|
580
|
+
};
|
|
581
|
+
this.get = function (key) {
|
|
582
|
+
if (cache.enabled) {
|
|
583
|
+
return cache.list[key];
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
this.set = function (key, value) {
|
|
587
|
+
if (cache.enabled) {
|
|
588
|
+
cache.list[key] = value;
|
|
589
|
+
}
|
|
590
|
+
return this;
|
|
591
|
+
};
|
|
592
|
+
this.resolve = function (key) {
|
|
593
|
+
return Promise.resolve(this.get(key));
|
|
594
|
+
};
|
|
595
|
+
this.remove = function (key) {
|
|
596
|
+
delete cache.list[key];
|
|
597
|
+
};
|
|
598
|
+
this.exist = function (key) {
|
|
599
|
+
return hasProp(cache.list, key);
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
var tagList = [{
|
|
604
|
+
symbol: '-',
|
|
605
|
+
format: function format(value) {
|
|
606
|
+
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
|
|
607
|
+
}
|
|
608
|
+
}, {
|
|
609
|
+
symbol: '=',
|
|
610
|
+
format: function format(value) {
|
|
611
|
+
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
|
|
612
|
+
}
|
|
613
|
+
}, {
|
|
614
|
+
symbol: '#',
|
|
615
|
+
format: function format(value) {
|
|
616
|
+
return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
|
|
617
|
+
}
|
|
618
|
+
}, {
|
|
619
|
+
symbol: '',
|
|
620
|
+
format: function format(value) {
|
|
621
|
+
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
622
|
+
}
|
|
623
|
+
}];
|
|
624
|
+
function matchTokens(regex, text, callback) {
|
|
625
|
+
var index = 0;
|
|
626
|
+
text.replace(regex, function () {
|
|
627
|
+
var params = [].slice.call(arguments, 0, -1);
|
|
628
|
+
var offset = params.pop();
|
|
629
|
+
var match = params.shift();
|
|
630
|
+
callback(params, index, offset);
|
|
631
|
+
index = offset + match.length;
|
|
632
|
+
return match;
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
function Compiler(config) {
|
|
636
|
+
if (instanceOf(this, Compiler) === false) return new Compiler(config);
|
|
637
|
+
var compiler = {};
|
|
638
|
+
this.configure = function (config) {
|
|
639
|
+
compiler.withObject = config.withObject;
|
|
640
|
+
compiler.rmWhitespace = config.rmWhitespace;
|
|
641
|
+
compiler.token = config.token;
|
|
642
|
+
compiler.vars = config.vars;
|
|
643
|
+
compiler.globalHelpers = config.globalHelpers;
|
|
644
|
+
compiler.matches = [];
|
|
645
|
+
compiler.formats = [];
|
|
646
|
+
compiler.slurp = {
|
|
647
|
+
match: '[ \\t]*',
|
|
648
|
+
start: [compiler.token.start, '_'],
|
|
649
|
+
end: ['_', compiler.token.end]
|
|
650
|
+
};
|
|
651
|
+
tagList.forEach(function (item) {
|
|
652
|
+
compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
|
|
653
|
+
compiler.formats.push(item.format.bind(compiler.vars));
|
|
654
|
+
});
|
|
655
|
+
compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
|
|
656
|
+
compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
|
|
657
|
+
compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
|
|
658
|
+
};
|
|
659
|
+
this.compile = function (content, path) {
|
|
660
|
+
var _compiler$vars = compiler.vars,
|
|
661
|
+
SCOPE = _compiler$vars.SCOPE,
|
|
662
|
+
SAFE = _compiler$vars.SAFE,
|
|
663
|
+
BUFFER = _compiler$vars.BUFFER,
|
|
664
|
+
COMPONENT = _compiler$vars.COMPONENT;
|
|
665
|
+
var GLOBALS = compiler.globalHelpers;
|
|
666
|
+
content = String(content);
|
|
667
|
+
if (compiler.rmWhitespace) {
|
|
668
|
+
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
669
|
+
}
|
|
670
|
+
content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
|
|
671
|
+
var source = "".concat(BUFFER, "('");
|
|
672
|
+
matchTokens(compiler.regex, content, function (params, index, offset) {
|
|
673
|
+
source += symbols(content.slice(index, offset));
|
|
674
|
+
params.forEach(function (value, index) {
|
|
675
|
+
if (value) {
|
|
676
|
+
source += compiler.formats[index](value);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
source += "');";
|
|
681
|
+
source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
|
|
682
|
+
if (compiler.withObject) {
|
|
683
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
684
|
+
}
|
|
685
|
+
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
686
|
+
source += "\n//# sourceURL=".concat(path);
|
|
687
|
+
var result = null;
|
|
688
|
+
var params = [SCOPE, COMPONENT, BUFFER, SAFE].concat(GLOBALS);
|
|
689
|
+
try {
|
|
690
|
+
result = Function.apply(null, params.concat(source));
|
|
691
|
+
result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n})");
|
|
692
|
+
} catch (e) {
|
|
693
|
+
e.filename = path;
|
|
694
|
+
e.source = source;
|
|
695
|
+
throw e;
|
|
696
|
+
}
|
|
697
|
+
return result;
|
|
698
|
+
};
|
|
699
|
+
this.configure(config);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function Template(config, cache, compiler) {
|
|
703
|
+
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
704
|
+
if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
|
|
705
|
+
if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
|
|
706
|
+
var template = {};
|
|
707
|
+
var result = function result(template, content) {
|
|
708
|
+
cache.set(template, content);
|
|
709
|
+
return content;
|
|
710
|
+
};
|
|
711
|
+
var resolve = function resolve(path) {
|
|
712
|
+
return template.resolver(template.path, path);
|
|
713
|
+
};
|
|
714
|
+
var compile = function compile(content, template) {
|
|
715
|
+
if (isFunction(content)) {
|
|
716
|
+
return content;
|
|
717
|
+
} else {
|
|
718
|
+
return compiler.compile(content, template);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
this.configure = function (config) {
|
|
722
|
+
template.path = config.path;
|
|
723
|
+
template.cache = config.cache;
|
|
724
|
+
if (isFunction(config.resolver)) {
|
|
725
|
+
template.resolver = config.resolver;
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
this.get = function (template) {
|
|
729
|
+
if (cache.exist(template)) {
|
|
730
|
+
return cache.resolve(template);
|
|
731
|
+
}
|
|
732
|
+
return resolve(template).then(function (content) {
|
|
733
|
+
return result(template, compile(content, template));
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
this.configure(config);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
740
|
+
var space = ' ';
|
|
741
|
+
var quote = '"';
|
|
742
|
+
var equal = '=';
|
|
743
|
+
var slash = '/';
|
|
744
|
+
var lt = '<';
|
|
745
|
+
var gt = '>';
|
|
746
|
+
var element = function element(tag, attrs, content) {
|
|
747
|
+
var result = [];
|
|
748
|
+
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
749
|
+
var attributes = map(attrs, function (value, key) {
|
|
750
|
+
if (value !== null && value !== undefined) {
|
|
751
|
+
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
752
|
+
}
|
|
753
|
+
}).join(space);
|
|
754
|
+
result.push([lt, tag, space, attributes, gt].join(''));
|
|
755
|
+
if (content) {
|
|
756
|
+
result.push(content instanceof Array ? content.join('') : content);
|
|
757
|
+
}
|
|
758
|
+
if (hasClosedTag) {
|
|
759
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
760
|
+
}
|
|
761
|
+
return result.join('');
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
function TemplateError(message) {
|
|
765
|
+
this.code = 1;
|
|
766
|
+
this.name = 'TemplateError';
|
|
767
|
+
this.message = message;
|
|
768
|
+
Error.call(this);
|
|
769
|
+
}
|
|
770
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, Error.prototype);
|
|
771
|
+
function TemplateNotFound(message) {
|
|
772
|
+
TemplateError.call(this);
|
|
773
|
+
this.code = 404;
|
|
774
|
+
this.name = 'TemplateNotFound';
|
|
775
|
+
this.message = message;
|
|
776
|
+
}
|
|
777
|
+
Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
|
|
778
|
+
function TemplateSyntaxError(message) {
|
|
779
|
+
TemplateError.call(this);
|
|
780
|
+
this.code = 500;
|
|
781
|
+
this.name = 'TemplateSyntaxError';
|
|
782
|
+
this.message = message;
|
|
783
|
+
}
|
|
784
|
+
Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
|
|
785
|
+
|
|
786
|
+
function resolve(list) {
|
|
787
|
+
return Promise.all(list || []).then(function (list) {
|
|
788
|
+
return list.join('');
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
function reject(error) {
|
|
792
|
+
return Promise.reject(new TemplateSyntaxError(error.message));
|
|
793
|
+
}
|
|
794
|
+
function createBuffer() {
|
|
795
|
+
var store = [],
|
|
796
|
+
array = [];
|
|
797
|
+
function buffer(value) {
|
|
798
|
+
array.push(value);
|
|
799
|
+
}
|
|
800
|
+
buffer.start = function () {
|
|
801
|
+
array = [];
|
|
802
|
+
};
|
|
803
|
+
buffer.backup = function () {
|
|
804
|
+
store.push(array.concat());
|
|
805
|
+
array = [];
|
|
806
|
+
};
|
|
807
|
+
buffer.restore = function () {
|
|
808
|
+
var result = array.concat();
|
|
809
|
+
array = store.pop();
|
|
810
|
+
return resolve(result);
|
|
811
|
+
};
|
|
812
|
+
buffer.error = function (e) {
|
|
813
|
+
return reject(e);
|
|
814
|
+
};
|
|
815
|
+
buffer.end = function () {
|
|
816
|
+
return resolve(array);
|
|
817
|
+
};
|
|
818
|
+
return buffer;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
function Context(config) {
|
|
822
|
+
if (instanceOf(this, Context) === false) return new Context(config);
|
|
823
|
+
this.configure = function (config, methods) {
|
|
824
|
+
var _Object$definePropert;
|
|
825
|
+
var _config$vars = config.vars,
|
|
826
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
827
|
+
MACRO = _config$vars.MACRO,
|
|
828
|
+
EXTEND = _config$vars.EXTEND,
|
|
829
|
+
LAYOUT = _config$vars.LAYOUT,
|
|
830
|
+
BUFFER = _config$vars.BUFFER,
|
|
831
|
+
COMPONENT = _config$vars.COMPONENT;
|
|
832
|
+
this.create = function (data) {
|
|
833
|
+
return new Scope(data);
|
|
834
|
+
};
|
|
835
|
+
this.helpers = function (methods) {
|
|
836
|
+
extend(Scope.prototype, methods || {});
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* @name ContextScope
|
|
840
|
+
* @param data
|
|
841
|
+
* @constructor
|
|
842
|
+
*/
|
|
843
|
+
function Scope(data) {
|
|
844
|
+
this[BLOCKS] = {};
|
|
845
|
+
this[MACRO] = {};
|
|
846
|
+
extend(this, data || {});
|
|
847
|
+
}
|
|
848
|
+
Scope.prototype = extend({}, methods || {});
|
|
849
|
+
Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_Object$definePropert, BUFFER, {
|
|
850
|
+
value: createBuffer(),
|
|
851
|
+
writable: true,
|
|
852
|
+
configurable: false,
|
|
853
|
+
enumerable: false
|
|
854
|
+
}), _defineProperty(_Object$definePropert, BLOCKS, {
|
|
855
|
+
value: {},
|
|
856
|
+
writable: true,
|
|
857
|
+
configurable: false,
|
|
858
|
+
enumerable: false
|
|
859
|
+
}), _defineProperty(_Object$definePropert, MACRO, {
|
|
860
|
+
value: {},
|
|
861
|
+
writable: true,
|
|
862
|
+
configurable: false,
|
|
863
|
+
enumerable: false
|
|
864
|
+
}), _defineProperty(_Object$definePropert, LAYOUT, {
|
|
865
|
+
value: false,
|
|
866
|
+
writable: true,
|
|
867
|
+
configurable: false,
|
|
868
|
+
enumerable: false
|
|
869
|
+
}), _defineProperty(_Object$definePropert, EXTEND, {
|
|
870
|
+
value: false,
|
|
871
|
+
writable: true,
|
|
872
|
+
configurable: false,
|
|
873
|
+
enumerable: false
|
|
874
|
+
}), _defineProperty(_Object$definePropert, "getMacro", {
|
|
875
|
+
value: function value() {
|
|
876
|
+
return this[MACRO];
|
|
877
|
+
},
|
|
878
|
+
writable: false,
|
|
879
|
+
configurable: false,
|
|
880
|
+
enumerable: false
|
|
881
|
+
}), _defineProperty(_Object$definePropert, "getBuffer", {
|
|
882
|
+
value: function value() {
|
|
883
|
+
return this[BUFFER];
|
|
884
|
+
},
|
|
885
|
+
writable: false,
|
|
886
|
+
configurable: false,
|
|
887
|
+
enumerable: false
|
|
888
|
+
}), _defineProperty(_Object$definePropert, "getComponent", {
|
|
889
|
+
value: function value() {
|
|
890
|
+
var context = this;
|
|
891
|
+
if (COMPONENT in context) {
|
|
892
|
+
return function () {
|
|
893
|
+
return context[COMPONENT].apply(context, arguments);
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
return function () {
|
|
897
|
+
console.log('%s function not defined', COMPONENT);
|
|
898
|
+
};
|
|
899
|
+
},
|
|
900
|
+
writable: false,
|
|
901
|
+
configurable: false,
|
|
902
|
+
enumerable: false
|
|
903
|
+
}), _defineProperty(_Object$definePropert, "getBlocks", {
|
|
904
|
+
value: function value() {
|
|
905
|
+
return this[BLOCKS];
|
|
906
|
+
},
|
|
907
|
+
writable: false,
|
|
908
|
+
configurable: false,
|
|
909
|
+
enumerable: false
|
|
910
|
+
}), _defineProperty(_Object$definePropert, "setExtend", {
|
|
911
|
+
value: function value(_value) {
|
|
912
|
+
this[EXTEND] = _value;
|
|
913
|
+
},
|
|
914
|
+
writable: false,
|
|
915
|
+
configurable: false,
|
|
916
|
+
enumerable: false
|
|
917
|
+
}), _defineProperty(_Object$definePropert, "getExtend", {
|
|
918
|
+
value: function value() {
|
|
919
|
+
return this[EXTEND];
|
|
920
|
+
},
|
|
921
|
+
writable: false,
|
|
922
|
+
configurable: false,
|
|
923
|
+
enumerable: false
|
|
924
|
+
}), _defineProperty(_Object$definePropert, "setLayout", {
|
|
925
|
+
value: function value(layout) {
|
|
926
|
+
this[LAYOUT] = layout;
|
|
927
|
+
},
|
|
928
|
+
writable: false,
|
|
929
|
+
configurable: false,
|
|
930
|
+
enumerable: false
|
|
931
|
+
}), _defineProperty(_Object$definePropert, "getLayout", {
|
|
932
|
+
value: function value() {
|
|
933
|
+
return this[LAYOUT];
|
|
934
|
+
},
|
|
935
|
+
writable: false,
|
|
936
|
+
configurable: false,
|
|
937
|
+
enumerable: false
|
|
938
|
+
}), _defineProperty(_Object$definePropert, "clone", {
|
|
939
|
+
value: function value(exclude_blocks) {
|
|
940
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
941
|
+
if (exclude_blocks === true) {
|
|
942
|
+
filter.push(BLOCKS);
|
|
943
|
+
}
|
|
944
|
+
return omit(this, filter);
|
|
945
|
+
},
|
|
946
|
+
writable: false,
|
|
947
|
+
configurable: false,
|
|
948
|
+
enumerable: false
|
|
949
|
+
}), _defineProperty(_Object$definePropert, "extend", {
|
|
950
|
+
value: function value(layout) {
|
|
951
|
+
this.setExtend(true);
|
|
952
|
+
this.setLayout(layout);
|
|
953
|
+
},
|
|
954
|
+
writable: false,
|
|
955
|
+
configurable: false,
|
|
956
|
+
enumerable: false
|
|
957
|
+
}), _defineProperty(_Object$definePropert, "echo", {
|
|
958
|
+
value: function value(layout) {
|
|
959
|
+
var buffer = this.getBuffer();
|
|
960
|
+
var params = [].slice.call(arguments);
|
|
961
|
+
params.forEach(buffer);
|
|
962
|
+
},
|
|
963
|
+
writable: false,
|
|
964
|
+
configurable: false,
|
|
965
|
+
enumerable: false
|
|
966
|
+
}), _defineProperty(_Object$definePropert, "fn", {
|
|
967
|
+
value: function value(callback) {
|
|
968
|
+
var buffer = this.getBuffer();
|
|
969
|
+
var context = this;
|
|
970
|
+
return function () {
|
|
971
|
+
buffer.backup();
|
|
972
|
+
if (isFunction(callback)) {
|
|
973
|
+
callback.apply(context, arguments);
|
|
974
|
+
}
|
|
975
|
+
return buffer.restore();
|
|
976
|
+
};
|
|
977
|
+
},
|
|
978
|
+
writable: false,
|
|
979
|
+
configurable: false,
|
|
980
|
+
enumerable: false
|
|
981
|
+
}), _defineProperty(_Object$definePropert, "get", {
|
|
982
|
+
value: function value(name, defaults) {
|
|
983
|
+
var path = getPath(this, name, true);
|
|
984
|
+
var result = path.shift();
|
|
985
|
+
var prop = path.pop();
|
|
986
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
987
|
+
},
|
|
988
|
+
writable: true,
|
|
989
|
+
configurable: true,
|
|
990
|
+
enumerable: false
|
|
991
|
+
}), _defineProperty(_Object$definePropert, "set", {
|
|
992
|
+
value: function value(name, _value2) {
|
|
993
|
+
var path = getPath(this, name, false);
|
|
994
|
+
var result = path.shift();
|
|
995
|
+
var prop = path.pop();
|
|
996
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
997
|
+
return result[prop];
|
|
998
|
+
}
|
|
999
|
+
return result[prop] = _value2;
|
|
1000
|
+
},
|
|
1001
|
+
writable: false,
|
|
1002
|
+
configurable: false,
|
|
1003
|
+
enumerable: false
|
|
1004
|
+
}), _defineProperty(_Object$definePropert, "macro", {
|
|
1005
|
+
value: function value(name, callback) {
|
|
1006
|
+
var list = this.getMacro();
|
|
1007
|
+
var macro = this.fn(callback);
|
|
1008
|
+
var context = this;
|
|
1009
|
+
list[name] = function () {
|
|
1010
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
1011
|
+
};
|
|
1012
|
+
},
|
|
1013
|
+
writable: false,
|
|
1014
|
+
configurable: false,
|
|
1015
|
+
enumerable: false
|
|
1016
|
+
}), _defineProperty(_Object$definePropert, "call", {
|
|
1017
|
+
value: function value(name) {
|
|
1018
|
+
var list = this.getMacro();
|
|
1019
|
+
var macro = list[name];
|
|
1020
|
+
var params = [].slice.call(arguments, 1);
|
|
1021
|
+
if (isFunction(macro)) {
|
|
1022
|
+
return macro.apply(macro, params);
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
writable: false,
|
|
1026
|
+
configurable: false,
|
|
1027
|
+
enumerable: false
|
|
1028
|
+
}), _defineProperty(_Object$definePropert, "block", {
|
|
1029
|
+
value: function value(name, callback) {
|
|
1030
|
+
var _this = this;
|
|
1031
|
+
var blocks = this.getBlocks();
|
|
1032
|
+
blocks[name] = blocks[name] || [];
|
|
1033
|
+
blocks[name].push(this.fn(callback));
|
|
1034
|
+
if (this.getExtend()) return;
|
|
1035
|
+
var list = Object.assign([], blocks[name]);
|
|
1036
|
+
var current = function current() {
|
|
1037
|
+
return list.shift();
|
|
1038
|
+
};
|
|
1039
|
+
var next = function next() {
|
|
1040
|
+
var parent = current();
|
|
1041
|
+
if (parent) {
|
|
1042
|
+
return function () {
|
|
1043
|
+
_this.echo(parent(next()));
|
|
1044
|
+
};
|
|
1045
|
+
} else {
|
|
1046
|
+
return noop;
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
this.echo(current()(next()));
|
|
1050
|
+
},
|
|
1051
|
+
writable: false,
|
|
1052
|
+
configurable: false,
|
|
1053
|
+
enumerable: false
|
|
1054
|
+
}), _defineProperty(_Object$definePropert, "include", {
|
|
1055
|
+
value: function value(path, data, cx) {
|
|
1056
|
+
var context = cx === false ? {} : this.clone(true);
|
|
1057
|
+
var params = extend(context, data || {});
|
|
1058
|
+
var promise = this.render(path, params);
|
|
1059
|
+
this.echo(promise);
|
|
1060
|
+
},
|
|
1061
|
+
writable: false,
|
|
1062
|
+
configurable: false,
|
|
1063
|
+
enumerable: false
|
|
1064
|
+
}), _defineProperty(_Object$definePropert, "use", {
|
|
1065
|
+
value: function value(path, namespace) {
|
|
1066
|
+
var promise = this.require(path);
|
|
1067
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
1068
|
+
var list = this.getMacro();
|
|
1069
|
+
each(exports, function (macro, name) {
|
|
1070
|
+
list[[namespace, name].join('.')] = macro;
|
|
1071
|
+
});
|
|
1072
|
+
}, this));
|
|
1073
|
+
},
|
|
1074
|
+
writable: false,
|
|
1075
|
+
configurable: false,
|
|
1076
|
+
enumerable: false
|
|
1077
|
+
}), _defineProperty(_Object$definePropert, "async", {
|
|
1078
|
+
value: function value(promise, callback) {
|
|
1079
|
+
this.echo(resolve$1(promise, function (data) {
|
|
1080
|
+
return this.fn(callback)(data);
|
|
1081
|
+
}, this));
|
|
1082
|
+
},
|
|
1083
|
+
writable: false,
|
|
1084
|
+
configurable: false,
|
|
1085
|
+
enumerable: false
|
|
1086
|
+
}), _defineProperty(_Object$definePropert, "each", {
|
|
1087
|
+
value: function value(object, callback) {
|
|
1088
|
+
if (isString(object)) {
|
|
1089
|
+
object = this.get(object, []);
|
|
1090
|
+
}
|
|
1091
|
+
each(object, callback);
|
|
1092
|
+
},
|
|
1093
|
+
writable: false,
|
|
1094
|
+
configurable: false,
|
|
1095
|
+
enumerable: false
|
|
1096
|
+
}), _defineProperty(_Object$definePropert, "element", {
|
|
1097
|
+
value: function value(tag, attr, content) {
|
|
1098
|
+
return element(tag, attr, content);
|
|
1099
|
+
},
|
|
1100
|
+
writable: false,
|
|
1101
|
+
configurable: false,
|
|
1102
|
+
enumerable: false
|
|
1103
|
+
}), _defineProperty(_Object$definePropert, "el", {
|
|
1104
|
+
value: function value(tag, attr, content) {
|
|
1105
|
+
if (isFunction(content)) {
|
|
1106
|
+
content = this.fn(content)();
|
|
1107
|
+
}
|
|
1108
|
+
this.echo(resolve$1(content, function (content) {
|
|
1109
|
+
return this.element(tag, attr, content);
|
|
1110
|
+
}, this));
|
|
1111
|
+
},
|
|
1112
|
+
writable: false,
|
|
1113
|
+
configurable: false,
|
|
1114
|
+
enumerable: false
|
|
1115
|
+
}), _Object$definePropert));
|
|
1116
|
+
};
|
|
1117
|
+
this.configure(config);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function EJS(options) {
|
|
1121
|
+
if (instanceOf(this, EJS) === false) return new EJS(options);
|
|
1122
|
+
var scope = {};
|
|
1123
|
+
var config = {};
|
|
1124
|
+
configSchema(config, options || {});
|
|
1125
|
+
var context = new Context(config);
|
|
1126
|
+
var compiler = new Compiler(config);
|
|
1127
|
+
var cache = new Cache();
|
|
1128
|
+
var template = new Template(config, cache, compiler);
|
|
1129
|
+
var output = function output(path, scope) {
|
|
1130
|
+
var globalHelpers = config.globalHelpers;
|
|
1131
|
+
var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
|
|
1132
|
+
return isFunction(scope[name]);
|
|
1133
|
+
}).map(function (name) {
|
|
1134
|
+
return scope[name].bind(scope);
|
|
1135
|
+
}));
|
|
1136
|
+
return template.get(path).then(function (callback) {
|
|
1137
|
+
return callback.apply(scope, params);
|
|
1138
|
+
});
|
|
1139
|
+
};
|
|
1140
|
+
var require = function require(name) {
|
|
1141
|
+
var filepath = ext(name, config.extension);
|
|
1142
|
+
var scope = context.create({});
|
|
1143
|
+
return output(filepath, scope).then(function () {
|
|
1144
|
+
return scope.getMacro();
|
|
1145
|
+
});
|
|
1146
|
+
};
|
|
1147
|
+
var render = function render(name, data) {
|
|
1148
|
+
var filepath = ext(name, config.extension);
|
|
1149
|
+
var scope = context.create(data);
|
|
1150
|
+
return output(filepath, scope).then(function (content) {
|
|
1151
|
+
if (scope.getExtend()) {
|
|
1152
|
+
scope.setExtend(false);
|
|
1153
|
+
var layout = scope.getLayout();
|
|
1154
|
+
var _data = scope.clone();
|
|
1155
|
+
return render(layout, _data);
|
|
1156
|
+
}
|
|
1157
|
+
return content;
|
|
1158
|
+
});
|
|
1159
|
+
};
|
|
1160
|
+
this.configure = function (options) {
|
|
1161
|
+
options = options || {};
|
|
1162
|
+
configSchema(config, options);
|
|
1163
|
+
context.configure(config, scope);
|
|
1164
|
+
compiler.configure(config);
|
|
1165
|
+
cache.configure(config);
|
|
1166
|
+
template.configure(config);
|
|
1167
|
+
return config;
|
|
1168
|
+
};
|
|
1169
|
+
this.render = function (name, data) {
|
|
1170
|
+
return render(name, data);
|
|
1171
|
+
};
|
|
1172
|
+
this.helpers = function (methods) {
|
|
1173
|
+
context.helpers(extend(scope, methods));
|
|
1174
|
+
};
|
|
1175
|
+
this.preload = function (list) {
|
|
1176
|
+
return cache.load(list || {});
|
|
1177
|
+
};
|
|
1178
|
+
this.create = function (options) {
|
|
1179
|
+
return new EJS(options);
|
|
1180
|
+
};
|
|
1181
|
+
this.compile = function (content, path) {
|
|
1182
|
+
return compiler.compile(content, path);
|
|
1183
|
+
};
|
|
1184
|
+
this.context = function (data) {
|
|
1185
|
+
return context.create(data);
|
|
1186
|
+
};
|
|
1187
|
+
this.helpers({
|
|
1188
|
+
require: require,
|
|
1189
|
+
render: render
|
|
1190
|
+
});
|
|
1191
|
+
return this;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
var templateCache = {};
|
|
1195
|
+
var ejs = new EJS({
|
|
1196
|
+
cache: false,
|
|
1197
|
+
withObject: false,
|
|
1198
|
+
resolver: function resolver(path, name) {
|
|
1199
|
+
return new Promise(function (resolve, reject) {
|
|
1200
|
+
if (templateCache.hasOwnProperty(name)) {
|
|
1201
|
+
resolve(templateCache[name]);
|
|
1202
|
+
} else {
|
|
1203
|
+
reject(new TemplateNotFound("template ".concat(name, " not found")));
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
var getOrigin = function getOrigin(url, secure) {
|
|
1209
|
+
url = new URL(url);
|
|
1210
|
+
if (secure) url.protocol = 'https:';
|
|
1211
|
+
return url.origin;
|
|
1212
|
+
};
|
|
1213
|
+
function setTemplates(list) {
|
|
1214
|
+
Object.assign(templateCache, list || {});
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* @typedef {Object<string,any>} HonoContext
|
|
1219
|
+
* @property {function(*):Promise<Response>} html
|
|
1220
|
+
* @property {function(name:string,data:{}):Promise<string>} render
|
|
1221
|
+
* @property {function(name:string,data:{}):Promise<string>} ejs
|
|
1222
|
+
* @property {ContextScope} data
|
|
1223
|
+
*/
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
*
|
|
1227
|
+
* @param {Object<string,any>} options
|
|
1228
|
+
* @return {(function(c:Context, next): Promise<any>)|*}
|
|
1229
|
+
*/
|
|
1230
|
+
function setRenderer(_ref) {
|
|
1231
|
+
var _ref$secure = _ref.secure,
|
|
1232
|
+
secure = _ref$secure === void 0 ? true : _ref$secure,
|
|
1233
|
+
_ref$version = _ref.version,
|
|
1234
|
+
version = _ref$version === void 0 ? '1.0' : _ref$version;
|
|
1235
|
+
return /*#__PURE__*/function () {
|
|
1236
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(c, next) {
|
|
1237
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1238
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1239
|
+
case 0:
|
|
1240
|
+
c.data = context({});
|
|
1241
|
+
c.data.set('version', version);
|
|
1242
|
+
c.data.set('origin', getOrigin(c.req.url, secure));
|
|
1243
|
+
c.ejs = function (name, data) {
|
|
1244
|
+
return render(name, Object.assign({}, c.data, data));
|
|
1245
|
+
};
|
|
1246
|
+
c.render = function (name, data) {
|
|
1247
|
+
return c.html(c.ejs(name, data));
|
|
1248
|
+
};
|
|
1249
|
+
_context.next = 7;
|
|
1250
|
+
return next();
|
|
1251
|
+
case 7:
|
|
1252
|
+
case "end":
|
|
1253
|
+
return _context.stop();
|
|
1254
|
+
}
|
|
1255
|
+
}, _callee);
|
|
1256
|
+
}));
|
|
1257
|
+
return function (_x, _x2) {
|
|
1258
|
+
return _ref2.apply(this, arguments);
|
|
1259
|
+
};
|
|
1260
|
+
}();
|
|
1261
|
+
}
|
|
1262
|
+
var render = ejs.render,
|
|
1263
|
+
context = ejs.context,
|
|
1264
|
+
compile = ejs.compile,
|
|
1265
|
+
helpers = ejs.helpers,
|
|
1266
|
+
preload = ejs.preload,
|
|
1267
|
+
configure = ejs.configure,
|
|
1268
|
+
create = ejs.create;
|
|
1269
|
+
|
|
1270
|
+
exports.compile = compile;
|
|
1271
|
+
exports.configure = configure;
|
|
1272
|
+
exports.context = context;
|
|
1273
|
+
exports.create = create;
|
|
1274
|
+
exports.helpers = helpers;
|
|
1275
|
+
exports.preload = preload;
|
|
1276
|
+
exports.render = render;
|
|
1277
|
+
exports.setRenderer = setRenderer;
|
|
1278
|
+
exports.setTemplates = setTemplates;
|