@kosatyi/ejs 0.0.54 → 0.0.55

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