@vendure/email-plugin 2.0.0-next.9 → 2.0.1
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/lib/index.d.ts +2 -0
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/src/common.d.ts +3 -1
- package/lib/src/common.js +10 -1
- package/lib/src/common.js.map +1 -1
- package/lib/src/default-email-handlers.js +9 -9
- package/lib/src/default-email-handlers.js.map +1 -1
- package/lib/src/dev-mailbox.js +9 -6
- package/lib/src/dev-mailbox.js.map +1 -1
- package/lib/src/email-generator.d.ts +25 -0
- package/lib/src/email-generator.js +3 -0
- package/lib/src/email-generator.js.map +1 -0
- package/lib/src/email-processor.d.ts +10 -6
- package/lib/src/email-processor.js +31 -13
- package/lib/src/email-processor.js.map +1 -1
- package/lib/src/email-sender.d.ts +45 -0
- package/lib/src/email-sender.js +3 -0
- package/lib/src/email-sender.js.map +1 -0
- package/lib/src/event-handler.d.ts +14 -2
- package/lib/src/event-handler.js +21 -7
- package/lib/src/event-handler.js.map +1 -1
- package/lib/src/event-listener.d.ts +1 -1
- package/lib/src/event-listener.js +1 -1
- package/lib/src/handlebars-mjml-generator.d.ts +4 -4
- package/lib/src/handlebars-mjml-generator.js +6 -13
- package/lib/src/handlebars-mjml-generator.js.map +1 -1
- package/lib/src/mock-events.js +17 -26
- package/lib/src/mock-events.js.map +1 -1
- package/lib/src/nodemailer-email-sender.d.ts +6 -3
- package/lib/src/nodemailer-email-sender.js +10 -1
- package/lib/src/nodemailer-email-sender.js.map +1 -1
- package/lib/src/noop-email-generator.d.ts +1 -1
- package/lib/src/plugin.d.ts +99 -8
- package/lib/src/plugin.js +143 -14
- package/lib/src/plugin.js.map +1 -1
- package/lib/src/template-loader.d.ts +5 -2
- package/lib/src/template-loader.js +17 -9
- package/lib/src/template-loader.js.map +1 -1
- package/lib/src/types.d.ts +140 -173
- package/package.json +42 -42
package/lib/src/plugin.js
CHANGED
|
@@ -8,15 +8,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var EmailPlugin_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.EmailPlugin = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
14
18
|
const core_1 = require("@nestjs/core");
|
|
15
19
|
const core_2 = require("@vendure/core");
|
|
16
|
-
const
|
|
20
|
+
const common_2 = require("./common");
|
|
17
21
|
const constants_1 = require("./constants");
|
|
18
22
|
const dev_mailbox_1 = require("./dev-mailbox");
|
|
19
23
|
const email_processor_1 = require("./email-processor");
|
|
24
|
+
const template_loader_1 = require("./template-loader");
|
|
20
25
|
/**
|
|
21
26
|
* @description
|
|
22
27
|
* The EmailPlugin creates and sends transactional emails based on Vendure events. By default, it uses an [MJML](https://mjml.io/)-based
|
|
@@ -77,6 +82,14 @@ const email_processor_1 = require("./email-processor");
|
|
|
77
82
|
* `node_modules/\@vendure/email-plugin/templates` to a location of your choice, and then point the `templatePath` config
|
|
78
83
|
* property at that directory.
|
|
79
84
|
*
|
|
85
|
+
* * ### Dynamic Email Templates
|
|
86
|
+
* Instead of passing a static value to `templatePath`, use `templateLoader` to define a template path.
|
|
87
|
+
* ```ts
|
|
88
|
+
* EmailPlugin.init({
|
|
89
|
+
* ...,
|
|
90
|
+
* templateLoader: new FileBasedTemplateLoader(my/order-confirmation/templates)
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
80
93
|
* ## Customizing templates
|
|
81
94
|
*
|
|
82
95
|
* Emails are generated from templates which use [MJML](https://mjml.io/) syntax. MJML is an open-source HTML-like markup
|
|
@@ -112,8 +125,87 @@ const email_processor_1 = require("./email-processor");
|
|
|
112
125
|
*
|
|
113
126
|
* The `defaultEmailHandlers` array defines the default handlers such as for handling new account registration, order confirmation, password reset
|
|
114
127
|
* etc. These defaults can be extended by adding custom templates for languages other than the default, or even completely new types of emails
|
|
115
|
-
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
116
|
-
*
|
|
128
|
+
* which respond to any of the available [VendureEvents](/docs/typescript-api/events/).
|
|
129
|
+
*
|
|
130
|
+
* A good way to learn how to create your own email handlers is to take a look at the
|
|
131
|
+
* [source code of the default handlers](https://github.com/vendure-ecommerce/vendure/blob/master/packages/email-plugin/src/default-email-handlers.ts).
|
|
132
|
+
* New handlers are defined in exactly the same way.
|
|
133
|
+
*
|
|
134
|
+
* It is also possible to modify the default handlers:
|
|
135
|
+
*
|
|
136
|
+
* ```TypeScript
|
|
137
|
+
* // Rather than importing `defaultEmailHandlers`, you can
|
|
138
|
+
* // import the handlers individually
|
|
139
|
+
* import {
|
|
140
|
+
* orderConfirmationHandler,
|
|
141
|
+
* emailVerificationHandler,
|
|
142
|
+
* passwordResetHandler,
|
|
143
|
+
* emailAddressChangeHandler,
|
|
144
|
+
* } from '\@vendure/email-plugin';
|
|
145
|
+
* import { CustomerService } from '\@vendure/core';
|
|
146
|
+
*
|
|
147
|
+
* // This allows you to then customize each handler to your needs.
|
|
148
|
+
* // For example, let's set a new subject line to the order confirmation:
|
|
149
|
+
* orderConfirmationHandler
|
|
150
|
+
* .setSubject(`We received your order!`);
|
|
151
|
+
*
|
|
152
|
+
* // Another example: loading additional data and setting new
|
|
153
|
+
* // template variables.
|
|
154
|
+
* passwordResetHandler
|
|
155
|
+
* .loadData(async ({ event, injector }) => {
|
|
156
|
+
* const customerService = injector.get(CustomerService);
|
|
157
|
+
* const customer = await customerService.findOneByUserId(event.ctx, event.user.id);
|
|
158
|
+
* return { customer };
|
|
159
|
+
* })
|
|
160
|
+
* .setTemplateVars(event => ({
|
|
161
|
+
* passwordResetToken: event.user.getNativeAuthenticationMethod().passwordResetToken,
|
|
162
|
+
* customer: event.data.customer,
|
|
163
|
+
* }));
|
|
164
|
+
*
|
|
165
|
+
* // Then you pass the handlers to the EmailPlugin init method
|
|
166
|
+
* // individually
|
|
167
|
+
* EmailPlugin.init({
|
|
168
|
+
* handlers: [
|
|
169
|
+
* orderConfirmationHandler,
|
|
170
|
+
* emailVerificationHandler,
|
|
171
|
+
* passwordResetHandler,
|
|
172
|
+
* emailAddressChangeHandler,
|
|
173
|
+
* ],
|
|
174
|
+
* // ...
|
|
175
|
+
* }),
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* For all available methods of extending a handler, see the {@link EmailEventHandler} documentation.
|
|
179
|
+
*
|
|
180
|
+
* ## Dynamic SMTP settings
|
|
181
|
+
*
|
|
182
|
+
* Instead of defining static transport settings, you can also provide a function that dynamically resolves
|
|
183
|
+
* channel aware transport settings.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* import { defaultEmailHandlers, EmailPlugin } from '\@vendure/email-plugin';
|
|
188
|
+
* import { MyTransportService } from './transport.services.ts';
|
|
189
|
+
* const config: VendureConfig = {
|
|
190
|
+
* plugins: [
|
|
191
|
+
* EmailPlugin.init({
|
|
192
|
+
* handlers: defaultEmailHandlers,
|
|
193
|
+
* templatePath: path.join(__dirname, 'static/email/templates'),
|
|
194
|
+
* transport: (injector, ctx) => {
|
|
195
|
+
* if (ctx) {
|
|
196
|
+
* return injector.get(MyTransportService).getSettings(ctx);
|
|
197
|
+
* } else {
|
|
198
|
+
* return {
|
|
199
|
+
type: 'smtp',
|
|
200
|
+
host: 'smtp.example.com',
|
|
201
|
+
// ... etc.
|
|
202
|
+
}
|
|
203
|
+
* }
|
|
204
|
+
* }
|
|
205
|
+
* }),
|
|
206
|
+
* ],
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
117
209
|
*
|
|
118
210
|
* ## Dev mode
|
|
119
211
|
*
|
|
@@ -121,7 +213,7 @@ const email_processor_1 = require("./email-processor");
|
|
|
121
213
|
* file transport (See {@link FileTransportOptions}) and outputs emails as rendered HTML files in the directory specified by the
|
|
122
214
|
* `outputPath` property.
|
|
123
215
|
*
|
|
124
|
-
* ```
|
|
216
|
+
* ```TypeScript
|
|
125
217
|
* EmailPlugin.init({
|
|
126
218
|
* devMode: true,
|
|
127
219
|
* route: 'mailbox',
|
|
@@ -165,32 +257,46 @@ const email_processor_1 = require("./email-processor");
|
|
|
165
257
|
* };
|
|
166
258
|
* ```
|
|
167
259
|
*
|
|
168
|
-
* @docsCategory EmailPlugin
|
|
260
|
+
* @docsCategory core plugins/EmailPlugin
|
|
169
261
|
*/
|
|
170
262
|
let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
171
263
|
/** @internal */
|
|
172
|
-
constructor(eventBus, moduleRef, emailProcessor, jobQueueService, processContext) {
|
|
264
|
+
constructor(eventBus, moduleRef, emailProcessor, jobQueueService, processContext, options) {
|
|
173
265
|
this.eventBus = eventBus;
|
|
174
266
|
this.moduleRef = moduleRef;
|
|
175
267
|
this.emailProcessor = emailProcessor;
|
|
176
268
|
this.jobQueueService = jobQueueService;
|
|
177
269
|
this.processContext = processContext;
|
|
270
|
+
this.options = options;
|
|
178
271
|
}
|
|
179
272
|
/**
|
|
180
273
|
* Set the plugin options.
|
|
181
274
|
*/
|
|
182
275
|
static init(options) {
|
|
276
|
+
if (options.templateLoader) {
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
278
|
+
core_2.Logger.info(`Using custom template loader '${options.templateLoader.constructor.name}'`);
|
|
279
|
+
}
|
|
280
|
+
else if (!options.templateLoader && options.templatePath) {
|
|
281
|
+
// TODO: this else-if can be removed when deprecated templatePath is removed,
|
|
282
|
+
// because we will either have a custom template loader, or the default loader with a default path
|
|
283
|
+
options.templateLoader = new template_loader_1.FileBasedTemplateLoader(options.templatePath);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw new Error('You must either supply a templatePath or provide a custom templateLoader');
|
|
287
|
+
}
|
|
183
288
|
this.options = options;
|
|
184
289
|
return EmailPlugin_1;
|
|
185
290
|
}
|
|
186
291
|
/** @internal */
|
|
187
292
|
async onApplicationBootstrap() {
|
|
188
|
-
|
|
293
|
+
await this.initInjectableStrategies();
|
|
189
294
|
await this.setupEventSubscribers();
|
|
190
|
-
|
|
295
|
+
const transport = await (0, common_2.resolveTransportSettings)(this.options, new core_2.Injector(this.moduleRef));
|
|
296
|
+
if (!(0, common_2.isDevModeOptions)(this.options) && transport.type === 'testing') {
|
|
191
297
|
// When running tests, we don't want to go through the JobQueue system,
|
|
192
298
|
// so we just call the email sending logic directly.
|
|
193
|
-
this.testingProcessor = new email_processor_1.EmailProcessor(options);
|
|
299
|
+
this.testingProcessor = new email_processor_1.EmailProcessor(this.options, this.moduleRef);
|
|
194
300
|
await this.testingProcessor.init();
|
|
195
301
|
}
|
|
196
302
|
else {
|
|
@@ -203,14 +309,35 @@ let EmailPlugin = EmailPlugin_1 = class EmailPlugin {
|
|
|
203
309
|
});
|
|
204
310
|
}
|
|
205
311
|
}
|
|
312
|
+
async onApplicationShutdown() {
|
|
313
|
+
await this.destroyInjectableStrategies();
|
|
314
|
+
}
|
|
206
315
|
configure(consumer) {
|
|
207
|
-
|
|
208
|
-
if ((0, common_1.isDevModeOptions)(options) && this.processContext.isServer) {
|
|
316
|
+
if ((0, common_2.isDevModeOptions)(this.options) && this.processContext.isServer) {
|
|
209
317
|
core_2.Logger.info('Creating dev mailbox middleware', constants_1.loggerCtx);
|
|
210
318
|
this.devMailbox = new dev_mailbox_1.DevMailbox();
|
|
211
|
-
consumer.apply(this.devMailbox.serve(options)).forRoutes(options.route);
|
|
319
|
+
consumer.apply(this.devMailbox.serve(this.options)).forRoutes(this.options.route);
|
|
212
320
|
this.devMailbox.handleMockEvent((handler, event) => this.handleEvent(handler, event));
|
|
213
|
-
(0, core_2.registerPluginStartupMessage)('Dev mailbox', options.route);
|
|
321
|
+
(0, core_2.registerPluginStartupMessage)('Dev mailbox', this.options.route);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async initInjectableStrategies() {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
const injector = new core_2.Injector(this.moduleRef);
|
|
327
|
+
if (typeof ((_a = this.options.emailGenerator) === null || _a === void 0 ? void 0 : _a.init) === 'function') {
|
|
328
|
+
await this.options.emailGenerator.init(injector);
|
|
329
|
+
}
|
|
330
|
+
if (typeof ((_b = this.options.emailSender) === null || _b === void 0 ? void 0 : _b.init) === 'function') {
|
|
331
|
+
await this.options.emailSender.init(injector);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async destroyInjectableStrategies() {
|
|
335
|
+
var _a, _b;
|
|
336
|
+
if (typeof ((_a = this.options.emailGenerator) === null || _a === void 0 ? void 0 : _a.destroy) === 'function') {
|
|
337
|
+
await this.options.emailGenerator.destroy();
|
|
338
|
+
}
|
|
339
|
+
if (typeof ((_b = this.options.emailSender) === null || _b === void 0 ? void 0 : _b.destroy) === 'function') {
|
|
340
|
+
await this.options.emailSender.destroy();
|
|
214
341
|
}
|
|
215
342
|
}
|
|
216
343
|
async setupEventSubscribers() {
|
|
@@ -245,12 +372,14 @@ EmailPlugin = EmailPlugin_1 = __decorate([
|
|
|
245
372
|
(0, core_2.VendurePlugin)({
|
|
246
373
|
imports: [core_2.PluginCommonModule],
|
|
247
374
|
providers: [{ provide: constants_1.EMAIL_PLUGIN_OPTIONS, useFactory: () => EmailPlugin_1.options }, email_processor_1.EmailProcessor],
|
|
375
|
+
compatibility: '^2.0.0',
|
|
248
376
|
}),
|
|
377
|
+
__param(5, (0, common_1.Inject)(constants_1.EMAIL_PLUGIN_OPTIONS)),
|
|
249
378
|
__metadata("design:paramtypes", [core_2.EventBus,
|
|
250
379
|
core_1.ModuleRef,
|
|
251
380
|
email_processor_1.EmailProcessor,
|
|
252
381
|
core_2.JobQueueService,
|
|
253
|
-
core_2.ProcessContext])
|
|
382
|
+
core_2.ProcessContext, Object])
|
|
254
383
|
], EmailPlugin);
|
|
255
384
|
exports.EmailPlugin = EmailPlugin;
|
|
256
385
|
//# sourceMappingURL=plugin.js.map
|
package/lib/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,wCAauB;AAGvB,qCAAsE;AACtE,2CAA8D;AAC9D,+CAA2C;AAC3C,uDAAmD;AAEnD,uDAA4D;AAU5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4OG;AAMI,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAMpB,gBAAgB;IAChB,YACY,QAAkB,EAClB,SAAoB,EACpB,cAA8B,EAC9B,eAAgC,EAChC,cAA8B,EACA,OAAsC;QALpE,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAgB;QACA,YAAO,GAAP,OAAO,CAA+B;IAC7E,CAAC;IAEJ;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAuD;QAC/D,IAAI,OAAO,CAAC,cAAc,EAAE;YACxB,4EAA4E;YAC5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AAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;aACnD;iBAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBAC9B,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aAC/C;SACJ;QAAC,OAAO,CAAM,EAAE;YACb,aAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,qBAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;SAC/C;IACL,CAAC;CACJ,CAAA;AAzHY,WAAW;IALvB,IAAA,oBAAa,EAAC;QACX,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,gCAAoB,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,aAAW,CAAC,OAAO,EAAE,EAAE,gCAAc,CAAC;QACrG,aAAa,EAAE,QAAQ;KAC1B,CAAC;IAcO,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;qCALX,eAAQ;QACP,gBAAS;QACJ,gCAAc;QACb,sBAAe;QAChB,qBAAc;GAZjC,WAAW,CAyHvB;AAzHY,kCAAW"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { Injector, RequestContext } from '@vendure/core';
|
|
2
|
+
import { LoadTemplateInput, Partial, TemplateLoader } from './types';
|
|
1
3
|
/**
|
|
2
4
|
* Loads email templates according to the configured TemplateConfig values.
|
|
3
5
|
*/
|
|
4
|
-
export declare class TemplateLoader {
|
|
6
|
+
export declare class FileBasedTemplateLoader implements TemplateLoader {
|
|
5
7
|
private templatePath;
|
|
6
8
|
constructor(templatePath: string);
|
|
7
|
-
loadTemplate(
|
|
9
|
+
loadTemplate(_injector: Injector, _ctx: RequestContext, { type, templateName }: LoadTemplateInput): Promise<string>;
|
|
10
|
+
loadPartials(): Promise<Partial[]>;
|
|
8
11
|
}
|
|
@@ -3,22 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.FileBasedTemplateLoader = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
/**
|
|
10
10
|
* Loads email templates according to the configured TemplateConfig values.
|
|
11
11
|
*/
|
|
12
|
-
class
|
|
12
|
+
class FileBasedTemplateLoader {
|
|
13
13
|
constructor(templatePath) {
|
|
14
14
|
this.templatePath = templatePath;
|
|
15
15
|
}
|
|
16
|
-
async loadTemplate(type,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
async loadTemplate(_injector, _ctx, { type, templateName }) {
|
|
17
|
+
const templatePath = path_1.default.join(this.templatePath, type, templateName);
|
|
18
|
+
return promises_1.default.readFile(templatePath, 'utf-8');
|
|
19
|
+
}
|
|
20
|
+
async loadPartials() {
|
|
21
|
+
const partialsPath = path_1.default.join(this.templatePath, 'partials');
|
|
22
|
+
const partialsFiles = await promises_1.default.readdir(partialsPath);
|
|
23
|
+
return Promise.all(partialsFiles.map(async (file) => {
|
|
24
|
+
return {
|
|
25
|
+
name: path_1.default.basename(file, '.hbs'),
|
|
26
|
+
content: await promises_1.default.readFile(path_1.default.join(partialsPath, file), 'utf-8')
|
|
27
|
+
};
|
|
28
|
+
}));
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
|
-
exports.
|
|
31
|
+
exports.FileBasedTemplateLoader = FileBasedTemplateLoader;
|
|
24
32
|
//# sourceMappingURL=template-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-loader.js","sourceRoot":"","sources":["../../src/template-loader.ts"],"names":[],"mappings":";;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"template-loader.js","sourceRoot":"","sources":["../../src/template-loader.ts"],"names":[],"mappings":";;;;;;AACA,2DAA6B;AAC7B,gDAAwB;AAGxB;;GAEG;AACH,MAAa,uBAAuB;IAEhC,YAAoB,YAAoB;QAApB,iBAAY,GAAZ,YAAY,CAAQ;IAAI,CAAC;IAE7C,KAAK,CAAC,YAAY,CACd,SAAmB,EACnB,IAAoB,EACpB,EAAE,IAAI,EAAE,YAAY,EAAqB;QAEzC,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QACtE,OAAO,kBAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACrD,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,OAAO;gBACH,IAAI,EAAE,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACjC,OAAO,EAAE,MAAM,kBAAE,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC;aACrE,CAAA;QACL,CAAC,CAAC,CAAC,CAAC;IACR,CAAC;CACJ;AAvBD,0DAuBC"}
|