@analogjs/vite-plugin-angular 2.5.0-beta.5 → 2.5.0-beta.51
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 +24 -0
- package/package.json +23 -5
- package/src/lib/angular-vite-plugin.d.ts +12 -1
- package/src/lib/angular-vite-plugin.js +107 -284
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.js +2 -2
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +42 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +213 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +44 -0
- package/src/lib/compiler/compile.js +1160 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +18 -0
- package/src/lib/compiler/constants.js +48 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +35 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +47 -0
- package/src/lib/compiler/defer.js +203 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +35 -0
- package/src/lib/compiler/dts-reader.js +526 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +80 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +7 -0
- package/src/lib/compiler/index.js +8 -0
- package/src/lib/compiler/index.js.map +1 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +224 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +269 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +502 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +57 -0
- package/src/lib/compiler/metadata.js +894 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +49 -0
- package/src/lib/compiler/registry.js +273 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +21 -0
- package/src/lib/compiler/resource-inliner.js +200 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +8 -0
- package/src/lib/compiler/style-ast.js +110 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/styles.js +60 -0
- package/src/lib/compiler/styles.js.map +1 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/test-helpers.js +28 -0
- package/src/lib/compiler/test-helpers.js.map +1 -0
- package/src/lib/compiler/type-elision.d.ts +26 -0
- package/src/lib/compiler/type-elision.js +313 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +10 -0
- package/src/lib/compiler/utils.js +95 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +28 -0
- package/src/lib/fast-compile-plugin.js +404 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +45 -0
- package/src/lib/utils/plugin-config.js +89 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/safe-module-paths.d.ts +16 -0
- package/src/lib/utils/safe-module-paths.js +26 -0
- package/src/lib/utils/safe-module-paths.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +4 -0
- package/src/lib/utils/virtual-ids.js +30 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +19 -0
- package/src/lib/utils/virtual-resources.js +47 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import * as vite from 'vite';
|
|
4
|
+
import { createCompilerPlugin, createRolldownCompilerPlugin, } from '../compiler-plugin.js';
|
|
5
|
+
/**
|
|
6
|
+
* TypeScript file extension regex
|
|
7
|
+
* Match .ts / .cts / .mts extensions with an optional ?query suffix.
|
|
8
|
+
* Reject .tsx — and any other `.ts<letter>…` extension like .tsrx — via
|
|
9
|
+
* a negative-lookahead on a following ASCII letter, so only genuine TS
|
|
10
|
+
* files pass.
|
|
11
|
+
*
|
|
12
|
+
* Previous form `/\.[cm]?(ts)[^x]?\??/` was intended to exclude `.tsx`
|
|
13
|
+
* specifically (`[^x]?` = not-an-x), but the `?` quantifier also allows
|
|
14
|
+
* zero characters, and any non-`x` letter was admitted — so `.tsrx`
|
|
15
|
+
* and similar extensions matched by accident.
|
|
16
|
+
*/
|
|
17
|
+
export const TS_EXT_REGEX = /\.[cm]?ts(?![a-z])/;
|
|
18
|
+
export function getTsConfigPath(root, tsconfig, isProd, isTest, isLib) {
|
|
19
|
+
if (tsconfig && isAbsolute(tsconfig)) {
|
|
20
|
+
if (!existsSync(tsconfig)) {
|
|
21
|
+
console.error(`[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the "tsconfig" property with an absolute path.`);
|
|
22
|
+
}
|
|
23
|
+
return tsconfig;
|
|
24
|
+
}
|
|
25
|
+
let tsconfigFilePath = './tsconfig.app.json';
|
|
26
|
+
if (isLib) {
|
|
27
|
+
tsconfigFilePath = isProd
|
|
28
|
+
? './tsconfig.lib.prod.json'
|
|
29
|
+
: './tsconfig.lib.json';
|
|
30
|
+
}
|
|
31
|
+
if (isTest) {
|
|
32
|
+
tsconfigFilePath = './tsconfig.spec.json';
|
|
33
|
+
}
|
|
34
|
+
if (tsconfig) {
|
|
35
|
+
tsconfigFilePath = tsconfig;
|
|
36
|
+
}
|
|
37
|
+
const resolvedPath = resolve(root, tsconfigFilePath);
|
|
38
|
+
if (!existsSync(resolvedPath)) {
|
|
39
|
+
console.error(`[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${resolvedPath}. This causes compilation issues. Check the path or set the "tsconfig" property with an absolute path.`);
|
|
40
|
+
}
|
|
41
|
+
return resolvedPath;
|
|
42
|
+
}
|
|
43
|
+
export function createTsConfigGetter(tsconfigOrGetter) {
|
|
44
|
+
if (typeof tsconfigOrGetter === 'function') {
|
|
45
|
+
return tsconfigOrGetter;
|
|
46
|
+
}
|
|
47
|
+
return () => tsconfigOrGetter || '';
|
|
48
|
+
}
|
|
49
|
+
export function createDepOptimizerConfig(opts) {
|
|
50
|
+
const defineOptions = {
|
|
51
|
+
ngJitMode: 'false',
|
|
52
|
+
ngI18nClosureMode: 'false',
|
|
53
|
+
...(opts.watchMode ? {} : { ngDevMode: 'false' }),
|
|
54
|
+
};
|
|
55
|
+
const rolldownOptions = {
|
|
56
|
+
plugins: [
|
|
57
|
+
createRolldownCompilerPlugin({
|
|
58
|
+
tsconfig: opts.tsconfig,
|
|
59
|
+
sourcemap: !opts.isProd,
|
|
60
|
+
advancedOptimizations: opts.isProd,
|
|
61
|
+
jit: opts.jit,
|
|
62
|
+
incremental: opts.watchMode,
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
const esbuildOptions = {
|
|
67
|
+
plugins: [
|
|
68
|
+
createCompilerPlugin({
|
|
69
|
+
tsconfig: opts.tsconfig,
|
|
70
|
+
sourcemap: !opts.isProd,
|
|
71
|
+
advancedOptimizations: opts.isProd,
|
|
72
|
+
jit: opts.jit,
|
|
73
|
+
incremental: opts.watchMode,
|
|
74
|
+
}, opts.isTest, !opts.isAstroIntegration),
|
|
75
|
+
],
|
|
76
|
+
define: defineOptions,
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
optimizeDeps: {
|
|
80
|
+
include: ['rxjs/operators', 'rxjs'],
|
|
81
|
+
exclude: ['@angular/platform-server'],
|
|
82
|
+
...(vite.rolldownVersion ? { rolldownOptions } : { esbuildOptions }),
|
|
83
|
+
},
|
|
84
|
+
resolve: {
|
|
85
|
+
conditions: ['style'],
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=plugin-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-config.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/plugin-config.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ResolvedConfig } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Mark a style file path as safe in Vite's `safeModulePaths` set so the
|
|
4
|
+
* `?inline` import passes the Denied ID security check without needing
|
|
5
|
+
* the plugin to intercept the load.
|
|
6
|
+
*
|
|
7
|
+
* Vite's own import-analysis transform does the same thing (adds the clean
|
|
8
|
+
* URL to `safeModulePaths` during transform). We additionally add the
|
|
9
|
+
* `?inline` form because `isServerAccessDeniedForTransform` checks *both*
|
|
10
|
+
* `cleanUrl(id)` and the full `id` (with query) against the allow list.
|
|
11
|
+
*
|
|
12
|
+
* This lets `?inline` CSS flow through Vite's native CSS pipeline, which
|
|
13
|
+
* handles preprocessing, `test.css` semantics, and browser-vs-node
|
|
14
|
+
* differences without the plugin having to reimplement any of it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function markStylePathSafe(config: ResolvedConfig | undefined, absPath: string): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { normalizePath } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Mark a style file path as safe in Vite's `safeModulePaths` set so the
|
|
4
|
+
* `?inline` import passes the Denied ID security check without needing
|
|
5
|
+
* the plugin to intercept the load.
|
|
6
|
+
*
|
|
7
|
+
* Vite's own import-analysis transform does the same thing (adds the clean
|
|
8
|
+
* URL to `safeModulePaths` during transform). We additionally add the
|
|
9
|
+
* `?inline` form because `isServerAccessDeniedForTransform` checks *both*
|
|
10
|
+
* `cleanUrl(id)` and the full `id` (with query) against the allow list.
|
|
11
|
+
*
|
|
12
|
+
* This lets `?inline` CSS flow through Vite's native CSS pipeline, which
|
|
13
|
+
* handles preprocessing, `test.css` semantics, and browser-vs-node
|
|
14
|
+
* differences without the plugin having to reimplement any of it.
|
|
15
|
+
*/
|
|
16
|
+
export function markStylePathSafe(config, absPath) {
|
|
17
|
+
if (!config)
|
|
18
|
+
return;
|
|
19
|
+
const normalized = normalizePath(absPath);
|
|
20
|
+
const safeModulePaths = config.safeModulePaths;
|
|
21
|
+
if (safeModulePaths) {
|
|
22
|
+
safeModulePaths.add(normalized);
|
|
23
|
+
safeModulePaths.add(normalized + '?inline');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=safe-module-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-module-paths.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/safe-module-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,MAAM,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAkC,EAClC,OAAe;IAEf,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,eAAe,GAAI,MAAc,CAAC,eAE3B,CAAC;IACd,IAAI,eAAe,EAAE,CAAC;QACpB,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAChC,eAAe,CAAC,GAAG,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const VIRTUAL_RAW_PREFIX = "virtual:@analogjs/vite-plugin-angular:raw:";
|
|
2
|
+
export declare function toVirtualRawId(absPath: string): string;
|
|
3
|
+
export declare function isVirtualRawId(id: string): boolean;
|
|
4
|
+
export declare function fromVirtualRawId(id: string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Virtual module id helpers for external component resources (template files).
|
|
2
|
+
// Routing through virtual ids keeps Vite's built-in plugins (vite:asset, the
|
|
3
|
+
// server.fs Denied ID check) out of the picture: the id Vite sees has no
|
|
4
|
+
// file extension, so extension-based matchers never fire, and it does not
|
|
5
|
+
// match the /[?&](raw|inline)\b/ security regex.
|
|
6
|
+
//
|
|
7
|
+
// Style ?inline imports now flow through Vite's native CSS pipeline via
|
|
8
|
+
// safeModulePaths (see safe-module-paths.ts). Only template ?raw imports
|
|
9
|
+
// still use virtual ids. See #2263 / #2283 / #2310.
|
|
10
|
+
export const VIRTUAL_RAW_PREFIX = 'virtual:@analogjs/vite-plugin-angular:raw:';
|
|
11
|
+
function encode(absPath) {
|
|
12
|
+
return Buffer.from(absPath, 'utf-8').toString('base64url');
|
|
13
|
+
}
|
|
14
|
+
function decode(encoded) {
|
|
15
|
+
return Buffer.from(encoded, 'base64url').toString('utf-8');
|
|
16
|
+
}
|
|
17
|
+
export function toVirtualRawId(absPath) {
|
|
18
|
+
return `${VIRTUAL_RAW_PREFIX}${encode(absPath)}`;
|
|
19
|
+
}
|
|
20
|
+
export function isVirtualRawId(id) {
|
|
21
|
+
return id.replace(/^\0/, '').startsWith(VIRTUAL_RAW_PREFIX);
|
|
22
|
+
}
|
|
23
|
+
export function fromVirtualRawId(id) {
|
|
24
|
+
const normalizedId = id.replace(/^\0/, '');
|
|
25
|
+
if (!normalizedId.startsWith(VIRTUAL_RAW_PREFIX)) {
|
|
26
|
+
throw new Error(`Invalid virtual raw id: ${id}`);
|
|
27
|
+
}
|
|
28
|
+
return decode(normalizedId.slice(VIRTUAL_RAW_PREFIX.length));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=virtual-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-ids.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/virtual-ids.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,6EAA6E;AAC7E,yEAAyE;AACzE,0EAA0E;AAC1E,iDAAiD;AACjD,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,oDAAoD;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAE/E,SAAS,MAAM,CAAC,OAAe;IAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,MAAM,CAAC,OAAe;IAC7B,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,GAAG,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAU;IACzC,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface PluginContextLike {
|
|
2
|
+
addWatchFile(path: string): void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Rewrite a user `.html?raw` import to a virtual raw id. Returns undefined
|
|
6
|
+
* when the id doesn't match, so callers can fall through to the next check.
|
|
7
|
+
*
|
|
8
|
+
* Routed through a virtual id (rather than `?analog-raw`) so the path Vite
|
|
9
|
+
* sees has no file extension — keeps vite:asset / vite:css from re-tagging
|
|
10
|
+
* the id before our load hook runs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rewriteHtmlRawImport(id: string, importer: string | undefined): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Load a virtual raw module: reads the backing file, registers it for HMR
|
|
15
|
+
* watching, and returns its content as a default-exported string. Returns
|
|
16
|
+
* undefined when the id is not a virtual raw id.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadVirtualRawModule(ctx: PluginContextLike, id: string): Promise<string | undefined>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Shared Vite plugin helpers for routing component resources (templates)
|
|
2
|
+
// through virtual module ids. Both angular-vite-plugin and fast-compile-plugin
|
|
3
|
+
// use these so the rewriting + loading behavior stays in sync between them.
|
|
4
|
+
//
|
|
5
|
+
// Style ?inline imports now flow through Vite's native CSS pipeline via
|
|
6
|
+
// safeModulePaths (see safe-module-paths.ts). Only template ?raw imports
|
|
7
|
+
// still use virtual ids.
|
|
8
|
+
import { promises as fsPromises } from 'node:fs';
|
|
9
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
10
|
+
import { normalizePath } from 'vite';
|
|
11
|
+
import { fromVirtualRawId, isVirtualRawId, toVirtualRawId, } from './virtual-ids.js';
|
|
12
|
+
function resolveImportPath(id, importer) {
|
|
13
|
+
const filePath = id.split('?')[0];
|
|
14
|
+
return isAbsolute(filePath)
|
|
15
|
+
? normalizePath(filePath)
|
|
16
|
+
: importer
|
|
17
|
+
? normalizePath(resolve(dirname(importer), filePath))
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Rewrite a user `.html?raw` import to a virtual raw id. Returns undefined
|
|
22
|
+
* when the id doesn't match, so callers can fall through to the next check.
|
|
23
|
+
*
|
|
24
|
+
* Routed through a virtual id (rather than `?analog-raw`) so the path Vite
|
|
25
|
+
* sees has no file extension — keeps vite:asset / vite:css from re-tagging
|
|
26
|
+
* the id before our load hook runs.
|
|
27
|
+
*/
|
|
28
|
+
export function rewriteHtmlRawImport(id, importer) {
|
|
29
|
+
if (!id.includes('.html?raw'))
|
|
30
|
+
return undefined;
|
|
31
|
+
const resolved = resolveImportPath(id, importer);
|
|
32
|
+
return resolved ? toVirtualRawId(resolved) : undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Load a virtual raw module: reads the backing file, registers it for HMR
|
|
36
|
+
* watching, and returns its content as a default-exported string. Returns
|
|
37
|
+
* undefined when the id is not a virtual raw id.
|
|
38
|
+
*/
|
|
39
|
+
export async function loadVirtualRawModule(ctx, id) {
|
|
40
|
+
if (!isVirtualRawId(id))
|
|
41
|
+
return undefined;
|
|
42
|
+
const filePath = fromVirtualRawId(id);
|
|
43
|
+
ctx.addWatchFile(filePath);
|
|
44
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
45
|
+
return `export default ${JSON.stringify(content)}`;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=virtual-resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-resources.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/virtual-resources.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,+EAA+E;AAC/E,4EAA4E;AAC5E,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,yBAAyB;AAEzB,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,kBAAkB,CAAC;AAM1B,SAAS,iBAAiB,CACxB,EAAU,EACV,QAA4B;IAE5B,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,OAAO,UAAU,CAAC,QAAQ,CAAC;QACzB,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;QACzB,CAAC,CAAC,QAAQ;YACR,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC,CAAC,SAAS,CAAC;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,EAAU,EACV,QAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAsB,EACtB,EAAU;IAEV,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACtC,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7D,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;AACrD,CAAC"}
|