@uipath/du-utils 1.0.0-rc.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/CHANGELOG.md +26 -0
- package/LICENSE +9 -0
- package/README.md +191 -0
- package/package.json +30 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/lib/load-web-component.d.ts +37 -0
- package/src/lib/load-web-component.js +145 -0
- package/src/lib/load-web-component.js.map +1 -0
- package/src/lib/shared/classification-station-wc.d.ts +181 -0
- package/src/lib/shared/classification-station-wc.js +3 -0
- package/src/lib/shared/classification-station-wc.js.map +1 -0
- package/src/lib/shared/index.d.ts +4 -0
- package/src/lib/shared/index.js +8 -0
- package/src/lib/shared/index.js.map +1 -0
- package/src/lib/shared/types.d.ts +11 -0
- package/src/lib/shared/types.js +10 -0
- package/src/lib/shared/types.js.map +1 -0
- package/src/lib/shared/validation-station-wc.d.ts +487 -0
- package/src/lib/shared/validation-station-wc.js +11 -0
- package/src/lib/shared/validation-station-wc.js.map +1 -0
- package/src/lib/shared/wc-lifecycle.d.ts +84 -0
- package/src/lib/shared/wc-lifecycle.js +81 -0
- package/src/lib/shared/wc-lifecycle.js.map +1 -0
- package/src/lib/url.util.d.ts +7 -0
- package/src/lib/url.util.js +18 -0
- package/src/lib/url.util.js.map +1 -0
- package/src/lib/wc-shared-styles.d.ts +31 -0
- package/src/lib/wc-shared-styles.js +204 -0
- package/src/lib/wc-shared-styles.js.map +1 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPersistentCustomElement = exports.getCustomElementConstructorWithLifecycle = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the constructor for a previously-registered custom element, falling
|
|
6
|
+
* back to the provided constructor if the element isn't yet registered.
|
|
7
|
+
*
|
|
8
|
+
* Centralises the structural cast required to expose the connect/disconnect
|
|
9
|
+
* lifecycle methods (see {@link IWcLifecycleConstructor}). Use this when
|
|
10
|
+
* defining a "persistent" subclass that overrides those methods.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const Base = getCustomElementConstructorWithLifecycle(
|
|
15
|
+
* 'ui-foo-element',
|
|
16
|
+
* FooElement,
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* class PersistentFooElement extends Base {
|
|
20
|
+
* override disconnectedCallback(): void {}
|
|
21
|
+
* override connectedCallback(): void { super.connectedCallback(); }
|
|
22
|
+
* forceDestroy(): void {
|
|
23
|
+
* this.remove();
|
|
24
|
+
* super.disconnectedCallback();
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const getCustomElementConstructorWithLifecycle = (tagName, fallback) => { var _a; return ((_a = customElements.get(tagName)) !== null && _a !== void 0 ? _a : fallback); };
|
|
30
|
+
exports.getCustomElementConstructorWithLifecycle = getCustomElementConstructorWithLifecycle;
|
|
31
|
+
/**
|
|
32
|
+
* Builds a "persistent" subclass of an Angular Elements custom element — one that
|
|
33
|
+
* survives DOM detachment (e.g. mat-tab portal swaps) instead of tearing down its
|
|
34
|
+
* inner Angular component on every disconnect.
|
|
35
|
+
*
|
|
36
|
+
* - `disconnectedCallback` is a no-op, so detaching the element does NOT destroy
|
|
37
|
+
* the inner component.
|
|
38
|
+
* - `connectedCallback` runs Angular's bootstrap only once. Angular Elements'
|
|
39
|
+
* `subscribeToEvents` re-subscribes to `strategy.events` on every
|
|
40
|
+
* `connectedCallback`; because `disconnectedCallback` is suppressed those
|
|
41
|
+
* subscriptions would never be cleaned up, so N re-attaches would fire each
|
|
42
|
+
* output N times. The original subscription stays live across detach/reattach.
|
|
43
|
+
* - `forceDestroy()` is the explicit teardown the consumer must call (e.g. in
|
|
44
|
+
* `ngOnDestroy`) when permanently removing the element. It removes the element
|
|
45
|
+
* first so `super.disconnectedCallback()` runs while `isConnected === false`,
|
|
46
|
+
* matching the browser's normal contract.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const element = createCustomElement(FooComponent, { injector });
|
|
51
|
+
* customElements.define('ui-foo-element', element);
|
|
52
|
+
* customElements.define(
|
|
53
|
+
* 'ui-foo-persistent-element',
|
|
54
|
+
* createPersistentCustomElement('ui-foo-element', element),
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const createPersistentCustomElement = (tagName, element) => {
|
|
59
|
+
const Base = (0, exports.getCustomElementConstructorWithLifecycle)(tagName, element);
|
|
60
|
+
return class extends Base {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(...arguments);
|
|
63
|
+
this._didInitialConnect = false;
|
|
64
|
+
}
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
66
|
+
disconnectedCallback() { }
|
|
67
|
+
connectedCallback() {
|
|
68
|
+
if (this._didInitialConnect) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this._didInitialConnect = true;
|
|
72
|
+
super.connectedCallback();
|
|
73
|
+
}
|
|
74
|
+
forceDestroy() {
|
|
75
|
+
this.remove();
|
|
76
|
+
super.disconnectedCallback();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
exports.createPersistentCustomElement = createPersistentCustomElement;
|
|
81
|
+
//# sourceMappingURL=wc-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wc-lifecycle.js","sourceRoot":"","sources":["../../../../../../../../../libs/du/shared/util/du-utils/src/lib/shared/wc-lifecycle.ts"],"names":[],"mappings":";;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACI,MAAM,wCAAwC,GAAG,CACpD,OAAe,EACf,QAAkC,EACX,EAAE,WACzB,OAAA,CAAC,MAAA,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,mCAAI,QAAQ,CAAuC,CAAA,EAAA,CAAC;AAJvE,QAAA,wCAAwC,4CAI+B;AAYpF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACI,MAAM,6BAA6B,GAAG,CACzC,OAAe,EACf,OAAiC,EACT,EAAE;IAC1B,MAAM,IAAI,GAAG,IAAA,gDAAwC,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAExE,OAAO,KAAM,SAAQ,IAAI;QAAlB;;YACK,uBAAkB,GAAG,KAAK,CAAC;QAiBvC,CAAC;QAfG,gEAAgE;QACvD,oBAAoB,KAAU,CAAC;QAE/B,iBAAiB;YACtB,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBAC1B,OAAO;YACX,CAAC;YACD,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAC/B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9B,CAAC;QAED,YAAY;YACR,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AAzBW,QAAA,6BAA6B,iCAyBxC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip trailing slashes from a URL so concatenating `${base}/${file}` never yields a `//`.
|
|
3
|
+
*
|
|
4
|
+
* Done without a regex on purpose: `/\/+$/` is unanchored and backtracks quadratically on a string
|
|
5
|
+
* of many slashes followed by a non-slash (CodeQL flags it as polynomial ReDoS on uncontrolled input).
|
|
6
|
+
*/
|
|
7
|
+
export declare const stripTrailingSlashes: (url: string) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripTrailingSlashes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Strip trailing slashes from a URL so concatenating `${base}/${file}` never yields a `//`.
|
|
6
|
+
*
|
|
7
|
+
* Done without a regex on purpose: `/\/+$/` is unanchored and backtracks quadratically on a string
|
|
8
|
+
* of many slashes followed by a non-slash (CodeQL flags it as polynomial ReDoS on uncontrolled input).
|
|
9
|
+
*/
|
|
10
|
+
const stripTrailingSlashes = (url) => {
|
|
11
|
+
let end = url.length;
|
|
12
|
+
while (end > 0 && url.charCodeAt(end - 1) === 47 /* '/' */) {
|
|
13
|
+
end--;
|
|
14
|
+
}
|
|
15
|
+
return url.slice(0, end);
|
|
16
|
+
};
|
|
17
|
+
exports.stripTrailingSlashes = stripTrailingSlashes;
|
|
18
|
+
//# sourceMappingURL=url.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.util.js","sourceRoot":"","sources":["../../../../../../../../libs/du/shared/util/du-utils/src/lib/url.util.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAU,EAAE;IACxD,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,OAAO,GAAG,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,CAAC;QACzD,GAAG,EAAE,CAAC;IACV,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-register the app's theme CSS so {@link adoptWcThemeStyleSheet} builds the shared
|
|
3
|
+
* stylesheet from it instead of fetching `styles.css` over the network. Call BEFORE the first
|
|
4
|
+
* WC element is constructed (a sheet already built from a successful fetch is not rebuilt).
|
|
5
|
+
*
|
|
6
|
+
* This is what the published npm package's generated `styles` side-effect entry does; it is
|
|
7
|
+
* also exported for consumers/hosts that obtain the CSS text through their own channel.
|
|
8
|
+
*/
|
|
9
|
+
export declare const registerWcThemeCss: (appName: string, cssText: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Record the WC bundle's own deployment base, derived from the entry module's URL. Call once from
|
|
12
|
+
* the WC's `main.ts`, passing `import.meta.url`; `adoptWcThemeStyleSheet` / `ensureWcFontsLoaded`
|
|
13
|
+
* resolve `styles.css` / `fonts.css` against it. (Lives here rather than reading `import.meta`
|
|
14
|
+
* directly so the lib stays compilable under ts-jest / the tsc publish build.)
|
|
15
|
+
*/
|
|
16
|
+
export declare const setWcAssetsBaseUrl: (appName: string, bundleModuleUrl: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Adopt the app's shared theme stylesheet into the host element's shadow root once it has
|
|
19
|
+
* loaded. No-op if the element has no shadow root. Idempotent — the same sheet is never
|
|
20
|
+
* adopted twice into the same root.
|
|
21
|
+
*/
|
|
22
|
+
export declare const adoptWcThemeStyleSheet: (host: HTMLElement | null | undefined, appName: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Inject the WC's `fonts.css` as a light-DOM `<link rel="stylesheet">` into the document head,
|
|
25
|
+
* deduped per app. `@font-face` must live in the light DOM (it is ignored inside a shadow root),
|
|
26
|
+
* so this cannot be adopted into the shadow root like the theme.
|
|
27
|
+
*
|
|
28
|
+
* Used by the loader's `includeFonts` path, and by the WC component when it detects the Apps host
|
|
29
|
+
* (Apps does not ship Apollo fonts globally, unlike Action Center / DU Center).
|
|
30
|
+
*/
|
|
31
|
+
export declare const ensureWcFontsLoaded: (appName: string) => void;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared Shadow-DOM theme adoption for the DU web components (VS, CS, …).
|
|
3
|
+
//
|
|
4
|
+
// Each WC app emits its heavy Material/Apollo theme as a standalone `styles.css` (NOT inlined
|
|
5
|
+
// into `main.js`). This module sources that CSS ONCE per app, builds a single `CSSStyleSheet`,
|
|
6
|
+
// and adopts it into every shadow root — so the deployment carries the theme once and the
|
|
7
|
+
// browser parses it once, no matter how many WC instances are on the page. The theme CANNOT be
|
|
8
|
+
// a document-level <link> (global Material rules would bleed onto the host page and would not
|
|
9
|
+
// reach shadow content), so it must be adopted per shadow root.
|
|
10
|
+
//
|
|
11
|
+
// The CSS text comes from one of two sources, in priority order:
|
|
12
|
+
// 1. A pre-registered CSS string (see `registerWcThemeCss`) — the npm-package path. Bundled
|
|
13
|
+
// npm consumers cannot rely on the fetch below: `import.meta.url` resolves to the
|
|
14
|
+
// CONSUMER's emitted chunk, styles.css is not deployed next to it, and the fetch 404s.
|
|
15
|
+
// The published package therefore ships a generated side-effect entry
|
|
16
|
+
// (`@uipath/du-validation-station-wc/styles`) that carries the CSS text and registers it
|
|
17
|
+
// up front.
|
|
18
|
+
// 2. A fetch of `styles.css` relative to the WC bundle's own deployment base — the CDN /
|
|
19
|
+
// loader path. The loader (`load-web-component.ts`) preloads it
|
|
20
|
+
// (`<link rel="preload" as="fetch">`) so this fetch is cache-warm.
|
|
21
|
+
//
|
|
22
|
+
// Framework-agnostic on purpose (no `@angular/core`): keeps this lib publishable for the
|
|
23
|
+
// non-Angular loader consumers and tree-shakeable.
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.ensureWcFontsLoaded = exports.adoptWcThemeStyleSheet = exports.setWcAssetsBaseUrl = exports.registerWcThemeCss = void 0;
|
|
26
|
+
const tslib_1 = require("tslib");
|
|
27
|
+
const url_util_1 = require("./url.util");
|
|
28
|
+
const THEME_STYLESHEET = 'styles.css';
|
|
29
|
+
const FONTS_STYLESHEET = 'fonts.css';
|
|
30
|
+
// Well-known global carrying pre-registered theme CSS per app name. A global (not module
|
|
31
|
+
// state) on purpose: the npm package's generated `styles.js` entry lives outside any bundler
|
|
32
|
+
// graph that could share this module instance, so a module-level map could never see its
|
|
33
|
+
// registration. KEEP THE KEY IN SYNC with `generateStylesEntry` in
|
|
34
|
+
// tools/scripts/release-libs/publish-public.mjs, which emits code writing to it.
|
|
35
|
+
const THEME_CSS_REGISTRY_KEY = '__uipathDuWcThemeCss';
|
|
36
|
+
const getThemeCssRegistry = () => {
|
|
37
|
+
var _a;
|
|
38
|
+
const globals = globalThis;
|
|
39
|
+
return ((_a = globals[THEME_CSS_REGISTRY_KEY]) !== null && _a !== void 0 ? _a : (globals[THEME_CSS_REGISTRY_KEY] = {}));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Pre-register the app's theme CSS so {@link adoptWcThemeStyleSheet} builds the shared
|
|
43
|
+
* stylesheet from it instead of fetching `styles.css` over the network. Call BEFORE the first
|
|
44
|
+
* WC element is constructed (a sheet already built from a successful fetch is not rebuilt).
|
|
45
|
+
*
|
|
46
|
+
* This is what the published npm package's generated `styles` side-effect entry does; it is
|
|
47
|
+
* also exported for consumers/hosts that obtain the CSS text through their own channel.
|
|
48
|
+
*/
|
|
49
|
+
const registerWcThemeCss = (appName, cssText) => {
|
|
50
|
+
getThemeCssRegistry()[appName] = cssText;
|
|
51
|
+
};
|
|
52
|
+
exports.registerWcThemeCss = registerWcThemeCss;
|
|
53
|
+
// Deployment base per app (the directory `main.js` loaded from), recorded once by the WC's
|
|
54
|
+
// `main.ts` from `import.meta.url`. Assets are co-located with `main.js` wherever the bundle is
|
|
55
|
+
// deployed, so it resolves them from its own location.
|
|
56
|
+
const baseByApp = new Map();
|
|
57
|
+
/**
|
|
58
|
+
* Record the WC bundle's own deployment base, derived from the entry module's URL. Call once from
|
|
59
|
+
* the WC's `main.ts`, passing `import.meta.url`; `adoptWcThemeStyleSheet` / `ensureWcFontsLoaded`
|
|
60
|
+
* resolve `styles.css` / `fonts.css` against it. (Lives here rather than reading `import.meta`
|
|
61
|
+
* directly so the lib stays compilable under ts-jest / the tsc publish build.)
|
|
62
|
+
*/
|
|
63
|
+
const setWcAssetsBaseUrl = (appName, bundleModuleUrl) => {
|
|
64
|
+
try {
|
|
65
|
+
baseByApp.set(appName, (0, url_util_1.stripTrailingSlashes)(new URL('.', bundleModuleUrl).href));
|
|
66
|
+
}
|
|
67
|
+
catch (_a) {
|
|
68
|
+
// Fail-safe: a malformed bundle URL must not crash bootstrap. Resolution then falls back
|
|
69
|
+
// to the relative path (see resolveThemeUrl / ensureWcFontsLoaded).
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.setWcAssetsBaseUrl = setWcAssetsBaseUrl;
|
|
73
|
+
// One cached sheet promise per app name. Each WC app is a separate bundle/runtime, so this
|
|
74
|
+
// module-level cache is per-app; keying by app name is defensive (one app ⇒ one theme).
|
|
75
|
+
const sheetByApp = new Map();
|
|
76
|
+
/**
|
|
77
|
+
* Adopt the app's shared theme stylesheet into the host element's shadow root once it has
|
|
78
|
+
* loaded. No-op if the element has no shadow root. Idempotent — the same sheet is never
|
|
79
|
+
* adopted twice into the same root.
|
|
80
|
+
*/
|
|
81
|
+
const adoptWcThemeStyleSheet = (host, appName) => {
|
|
82
|
+
const shadowRoot = host === null || host === void 0 ? void 0 : host.shadowRoot;
|
|
83
|
+
if (!shadowRoot) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
void getThemeSheet(appName)
|
|
87
|
+
.then((sheet) => {
|
|
88
|
+
if (sheet && !shadowRoot.adoptedStyleSheets.includes(sheet)) {
|
|
89
|
+
shadowRoot.adoptedStyleSheets = [
|
|
90
|
+
...shadowRoot.adoptedStyleSheets,
|
|
91
|
+
sheet,
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
.catch((error) => {
|
|
96
|
+
// Defensive: never surface an unhandled rejection on the host page.
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.error(`Failed to adopt theme stylesheet for web component "${appName}"`, error);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
exports.adoptWcThemeStyleSheet = adoptWcThemeStyleSheet;
|
|
102
|
+
const getThemeSheet = (appName) => {
|
|
103
|
+
let promise = sheetByApp.get(appName);
|
|
104
|
+
if (!promise) {
|
|
105
|
+
// Don't let a failure stick: if the sheet can't be built (transient network/CORS
|
|
106
|
+
// error, or no Constructable Stylesheet support), evict the cache entry so a later WC
|
|
107
|
+
// instance retries instead of being stuck unstyled for the page's lifetime.
|
|
108
|
+
promise = buildThemeSheet(appName)
|
|
109
|
+
.then((sheet) => {
|
|
110
|
+
if (!sheet) {
|
|
111
|
+
sheetByApp.delete(appName);
|
|
112
|
+
}
|
|
113
|
+
return sheet;
|
|
114
|
+
})
|
|
115
|
+
.catch((error) => {
|
|
116
|
+
// Guarantee the cached promise never rejects, and allow a later retry.
|
|
117
|
+
sheetByApp.delete(appName);
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.error(`Failed to build theme stylesheet for web component "${appName}"`, error);
|
|
120
|
+
return undefined;
|
|
121
|
+
});
|
|
122
|
+
sheetByApp.set(appName, promise);
|
|
123
|
+
}
|
|
124
|
+
return promise;
|
|
125
|
+
};
|
|
126
|
+
const buildThemeSheet = (appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
// Constructable Stylesheets aren't implemented in jsdom (used by Jest), so the adopt
|
|
128
|
+
// approach can't run there. Bail out — unit tests don't depend on visual theming and the
|
|
129
|
+
// real browser environment supports them fine. Accept either `replaceSync` or the async
|
|
130
|
+
// `replace` so a runtime that ships only the async variant still gets themed.
|
|
131
|
+
if (typeof CSSStyleSheet === 'undefined' ||
|
|
132
|
+
(typeof CSSStyleSheet.prototype.replaceSync !== 'function' &&
|
|
133
|
+
typeof CSSStyleSheet.prototype.replace !== 'function')) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
// Pre-registered CSS (npm-package path) wins over the network — see registerWcThemeCss.
|
|
137
|
+
// `fetch` is only required for the network fallback, so a fetch-less environment that
|
|
138
|
+
// supports constructable stylesheets can still adopt pre-registered CSS.
|
|
139
|
+
const registeredCss = getThemeCssRegistry()[appName];
|
|
140
|
+
if (registeredCss == null && typeof fetch === 'undefined') {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const cssText = registeredCss !== null && registeredCss !== void 0 ? registeredCss : (yield fetchThemeCss(appName));
|
|
145
|
+
const sheet = new CSSStyleSheet();
|
|
146
|
+
if (typeof sheet.replaceSync === 'function') {
|
|
147
|
+
sheet.replaceSync(cssText);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
yield sheet.replace(cssText);
|
|
151
|
+
}
|
|
152
|
+
return sheet;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
// Non-fatal: the WC still renders (just without the adopted theme). Log so a network/CORS
|
|
156
|
+
// misconfiguration is visible without breaking the host page.
|
|
157
|
+
// eslint-disable-next-line no-console
|
|
158
|
+
console.error(`Failed to load ${THEME_STYLESHEET} for web component "${appName}"`, error);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const fetchThemeCss = (appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
// `credentials: 'omit'` matches the loader's `<link rel="preload" as="fetch" crossorigin>`,
|
|
164
|
+
// so this fetch is served from the warm cache rather than re-hitting the network.
|
|
165
|
+
const response = yield fetch(resolveThemeUrl(appName), { credentials: 'omit' });
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
throw new Error(`Unexpected response ${response.status} fetching ${THEME_STYLESHEET}`);
|
|
168
|
+
}
|
|
169
|
+
return response.text();
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* Resolve the absolute URL of the emitted `styles.css`, co-located with the bundle (see
|
|
173
|
+
* {@link setWcAssetsBaseUrl}). Falls back to a document-relative path if the base was never
|
|
174
|
+
* recorded (e.g. local `nx serve`, where the app is served from the origin root).
|
|
175
|
+
*/
|
|
176
|
+
const resolveThemeUrl = (appName) => {
|
|
177
|
+
const base = baseByApp.get(appName);
|
|
178
|
+
return base ? `${base}/${THEME_STYLESHEET}` : THEME_STYLESHEET;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Inject the WC's `fonts.css` as a light-DOM `<link rel="stylesheet">` into the document head,
|
|
182
|
+
* deduped per app. `@font-face` must live in the light DOM (it is ignored inside a shadow root),
|
|
183
|
+
* so this cannot be adopted into the shadow root like the theme.
|
|
184
|
+
*
|
|
185
|
+
* Used by the loader's `includeFonts` path, and by the WC component when it detects the Apps host
|
|
186
|
+
* (Apps does not ship Apollo fonts globally, unlike Action Center / DU Center).
|
|
187
|
+
*/
|
|
188
|
+
const ensureWcFontsLoaded = (appName) => {
|
|
189
|
+
if (typeof document === 'undefined') {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const id = `du-wc-fonts-${appName}`;
|
|
193
|
+
if (document.getElementById(id)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const base = baseByApp.get(appName);
|
|
197
|
+
const link = document.createElement('link');
|
|
198
|
+
link.id = id;
|
|
199
|
+
link.rel = 'stylesheet';
|
|
200
|
+
link.href = base ? `${base}/${FONTS_STYLESHEET}` : FONTS_STYLESHEET;
|
|
201
|
+
document.head.appendChild(link);
|
|
202
|
+
};
|
|
203
|
+
exports.ensureWcFontsLoaded = ensureWcFontsLoaded;
|
|
204
|
+
//# sourceMappingURL=wc-shared-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wc-shared-styles.js","sourceRoot":"","sources":["../../../../../../../../libs/du/shared/util/du-utils/src/lib/wc-shared-styles.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,EAAE;AACF,8FAA8F;AAC9F,+FAA+F;AAC/F,0FAA0F;AAC1F,+FAA+F;AAC/F,8FAA8F;AAC9F,gEAAgE;AAChE,EAAE;AACF,iEAAiE;AACjE,4FAA4F;AAC5F,qFAAqF;AACrF,0FAA0F;AAC1F,yEAAyE;AACzE,4FAA4F;AAC5F,eAAe;AACf,yFAAyF;AACzF,mEAAmE;AACnE,sEAAsE;AACtE,EAAE;AACF,yFAAyF;AACzF,mDAAmD;;;;AA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