@fluid-topics/ft-wc-utils 1.1.52 → 1.1.54

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.
@@ -8,6 +8,7 @@ export declare class FtLitElement extends ScopedRegistryLitElement {
8
8
  exportpartsPrefixes?: string[];
9
9
  customStylesheet?: string;
10
10
  private adoptedCustomStyleSheet;
11
+ private useAdoptedStyleSheets;
11
12
  private readonly [constructorPrototype];
12
13
  private readonly [constructorName];
13
14
  constructor();
@@ -15,6 +16,7 @@ export declare class FtLitElement extends ScopedRegistryLitElement {
15
16
  connectedCallback(): void;
16
17
  protected updated(props: PropertyValues): void;
17
18
  protected contentAvailableCallback(props: PropertyValues): void;
19
+ private applyCustomStylesheet;
18
20
  private [exportpartsDebouncer];
19
21
  private scheduleExportpartsUpdate;
20
22
  private setExportpartsAttribute;
@@ -16,6 +16,7 @@ export class FtLitElement extends ScopedRegistryLitElement {
16
16
  constructor() {
17
17
  super();
18
18
  this.adoptedCustomStyleSheet = new CSSStyleSheet();
19
+ this.useAdoptedStyleSheets = true;
19
20
  this[_a] = new Debouncer(5);
20
21
  this[constructorName] = this.constructor.name;
21
22
  this[constructorPrototype] = this.constructor.prototype;
@@ -27,23 +28,48 @@ export class FtLitElement extends ScopedRegistryLitElement {
27
28
  }
28
29
  connectedCallback() {
29
30
  super.connectedCallback();
30
- if (this.shadowRoot && !this.shadowRoot.adoptedStyleSheets.includes(this.adoptedCustomStyleSheet)) {
31
- this.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, this.adoptedCustomStyleSheet];
31
+ try {
32
+ if (this.shadowRoot && !this.shadowRoot.adoptedStyleSheets.includes(this.adoptedCustomStyleSheet)) {
33
+ this.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, this.adoptedCustomStyleSheet];
34
+ }
35
+ }
36
+ catch (e) {
37
+ this.useAdoptedStyleSheets = false;
38
+ console.error("Cannot use adopted stylesheets", e);
32
39
  }
33
40
  }
34
41
  updated(props) {
35
- var _b;
36
42
  super.updated(props);
37
- if (props.has("customStylesheet")) {
38
- this.adoptedCustomStyleSheet.replace((_b = this.customStylesheet) !== null && _b !== void 0 ? _b : "");
39
- }
40
43
  this.updateComplete.then(() => {
41
44
  this.contentAvailableCallback(props);
45
+ this.applyCustomStylesheet(props);
42
46
  this.scheduleExportpartsUpdate();
43
47
  });
44
48
  }
45
49
  contentAvailableCallback(props) {
46
50
  }
51
+ applyCustomStylesheet(props) {
52
+ var _b, _c, _d;
53
+ if (this.useAdoptedStyleSheets) {
54
+ if (props.has("customStylesheet")) {
55
+ try {
56
+ this.adoptedCustomStyleSheet.replaceSync((_b = this.customStylesheet) !== null && _b !== void 0 ? _b : "");
57
+ }
58
+ catch (e) {
59
+ console.error(e, this.customStylesheet);
60
+ }
61
+ }
62
+ }
63
+ else {
64
+ ((_d = (_c = this.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelectorAll(".ft-lit-element--custom-stylesheet")) !== null && _d !== void 0 ? _d : []).forEach(e => e.remove());
65
+ if (this.customStylesheet) {
66
+ const customStyles = document.createElement("style");
67
+ customStyles.classList.add("ft-lit-element--custom-stylesheet");
68
+ customStyles.innerHTML = this.customStylesheet;
69
+ this.shadowRoot.append(customStyles);
70
+ }
71
+ }
72
+ }
47
73
  scheduleExportpartsUpdate() {
48
74
  var _b, _c, _d;
49
75
  if (((_b = this.exportpartsPrefix) === null || _b === void 0 ? void 0 : _b.trim()) || ((_d = (_c = this.exportpartsPrefixes) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0 > 0)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-wc-utils",
3
- "version": "1.1.52",
3
+ "version": "1.1.54",
4
4
  "description": "Internal web components tools",
5
5
  "author": "Fluid Topics <devtopics@antidot.net>",
6
6
  "license": "ISC",
@@ -24,5 +24,5 @@
24
24
  "lit": "3.1.0",
25
25
  "mark.js": "8.11.1"
26
26
  },
27
- "gitHead": "8b2c90df3e7d82be373f6e963272a37ebf57b017"
27
+ "gitHead": "b8c7a07061df6fb5c3c03d96879eda48fb73e5c8"
28
28
  }