@patternfly/pfe-core 2.0.0-next.8 → 2.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.
Files changed (77) hide show
  1. package/README.md +2 -2
  2. package/controllers/cascade-controller.js +136 -2
  3. package/controllers/cascade-controller.js.map +1 -7
  4. package/controllers/css-variable-controller.js +13 -2
  5. package/controllers/css-variable-controller.js.map +1 -7
  6. package/controllers/floating-dom-controller.d.ts +35 -14
  7. package/controllers/floating-dom-controller.js +115 -2
  8. package/controllers/floating-dom-controller.js.map +1 -7
  9. package/controllers/internals-controller.d.ts +52 -0
  10. package/controllers/internals-controller.js +52 -0
  11. package/controllers/internals-controller.js.map +1 -0
  12. package/controllers/light-dom-controller.js +38 -2
  13. package/controllers/light-dom-controller.js.map +1 -7
  14. package/controllers/logger.js +90 -2
  15. package/controllers/logger.js.map +1 -7
  16. package/controllers/perf-controller.js +36 -2
  17. package/controllers/perf-controller.js.map +1 -7
  18. package/controllers/property-observer-controller.d.ts +3 -3
  19. package/controllers/property-observer-controller.js +33 -2
  20. package/controllers/property-observer-controller.js.map +1 -7
  21. package/controllers/roving-tabindex-controller.d.ts +48 -0
  22. package/controllers/roving-tabindex-controller.js +166 -0
  23. package/controllers/roving-tabindex-controller.js.map +1 -0
  24. package/controllers/scroll-spy-controller.d.ts +37 -0
  25. package/controllers/scroll-spy-controller.js +120 -0
  26. package/controllers/scroll-spy-controller.js.map +1 -0
  27. package/controllers/slot-controller.d.ts +3 -3
  28. package/controllers/slot-controller.js +148 -2
  29. package/controllers/slot-controller.js.map +1 -7
  30. package/controllers/style-controller.js +42 -2
  31. package/controllers/style-controller.js.map +1 -7
  32. package/core.d.ts +1 -1
  33. package/core.js +68 -2
  34. package/core.js.map +1 -7
  35. package/custom-elements.json +6315 -1
  36. package/decorators/bound.js +27 -2
  37. package/decorators/bound.js.map +1 -7
  38. package/decorators/cascades.js +18 -2
  39. package/decorators/cascades.js.map +1 -7
  40. package/decorators/deprecation.d.ts +1 -1
  41. package/decorators/deprecation.js +44 -2
  42. package/decorators/deprecation.js.map +1 -7
  43. package/decorators/initializer.js +21 -2
  44. package/decorators/initializer.js.map +1 -7
  45. package/decorators/observed.d.ts +1 -1
  46. package/decorators/observed.js +52 -2
  47. package/decorators/observed.js.map +1 -7
  48. package/decorators/time.js +36 -2
  49. package/decorators/time.js.map +1 -7
  50. package/decorators/trace.js +21 -2
  51. package/decorators/trace.js.map +1 -7
  52. package/decorators.d.ts +0 -2
  53. package/decorators.js +8 -2
  54. package/decorators.js.map +1 -7
  55. package/functions/debounce.js +28 -2
  56. package/functions/debounce.js.map +1 -7
  57. package/functions/deprecatedCustomEvent.js +12 -2
  58. package/functions/deprecatedCustomEvent.js.map +1 -7
  59. package/functions/isElementInView.d.ts +12 -0
  60. package/functions/isElementInView.js +31 -0
  61. package/functions/isElementInView.js.map +1 -0
  62. package/functions/random.js +9 -2
  63. package/functions/random.js.map +1 -7
  64. package/package.json +13 -24
  65. package/context.d.ts +0 -53
  66. package/context.js +0 -2
  67. package/context.js.map +0 -7
  68. package/controllers/color-context.d.ts +0 -114
  69. package/controllers/color-context.js +0 -2
  70. package/controllers/color-context.js.map +0 -7
  71. package/controllers/color-context.scss +0 -84
  72. package/decorators/color-context.d.ts +0 -4
  73. package/decorators/color-context.js +0 -2
  74. package/decorators/color-context.js.map +0 -7
  75. package/decorators/pfelement.d.ts +0 -10
  76. package/decorators/pfelement.js +0 -2
  77. package/decorators/pfelement.js.map +0 -7
@@ -0,0 +1,120 @@
1
+ var _ScrollSpyController_instances, _ScrollSpyController_tagNames, _ScrollSpyController_activeAttribute, _ScrollSpyController_io, _ScrollSpyController_passedLinks, _ScrollSpyController_force, _ScrollSpyController_intersected, _ScrollSpyController_root, _ScrollSpyController_rootMargin, _ScrollSpyController_threshold, _ScrollSpyController_rootNode, _ScrollSpyController_getHash, _ScrollSpyController_linkChildren_get, _ScrollSpyController_initIo, _ScrollSpyController_markPassed, _ScrollSpyController_setActive, _ScrollSpyController_nextIntersection, _ScrollSpyController_onIo;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ export class ScrollSpyController {
4
+ get root() {
5
+ return __classPrivateFieldGet(this, _ScrollSpyController_root, "f");
6
+ }
7
+ set root(v) {
8
+ __classPrivateFieldSet(this, _ScrollSpyController_root, v, "f");
9
+ __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
10
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
11
+ }
12
+ get rootMargin() {
13
+ return __classPrivateFieldGet(this, _ScrollSpyController_rootMargin, "f");
14
+ }
15
+ set rootMargin(v) {
16
+ __classPrivateFieldSet(this, _ScrollSpyController_rootMargin, v, "f");
17
+ __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
18
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
19
+ }
20
+ get threshold() {
21
+ return __classPrivateFieldGet(this, _ScrollSpyController_threshold, "f");
22
+ }
23
+ set threshold(v) {
24
+ __classPrivateFieldSet(this, _ScrollSpyController_threshold, v, "f");
25
+ __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.disconnect();
26
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
27
+ }
28
+ constructor(host, options) {
29
+ this.host = host;
30
+ _ScrollSpyController_instances.add(this);
31
+ _ScrollSpyController_tagNames.set(this, void 0);
32
+ _ScrollSpyController_activeAttribute.set(this, void 0);
33
+ _ScrollSpyController_io.set(this, void 0);
34
+ /** Which link's targets have already scrolled past? */
35
+ _ScrollSpyController_passedLinks.set(this, new Set());
36
+ /** Ignore intersections? */
37
+ _ScrollSpyController_force.set(this, false);
38
+ /** Has the intersection observer found an element? */
39
+ _ScrollSpyController_intersected.set(this, false);
40
+ _ScrollSpyController_root.set(this, void 0);
41
+ _ScrollSpyController_rootMargin.set(this, void 0);
42
+ _ScrollSpyController_threshold.set(this, void 0);
43
+ _ScrollSpyController_rootNode.set(this, void 0);
44
+ _ScrollSpyController_getHash.set(this, void 0);
45
+ host.addController(this);
46
+ __classPrivateFieldSet(this, _ScrollSpyController_tagNames, options.tagNames, "f");
47
+ __classPrivateFieldSet(this, _ScrollSpyController_root, options.root, "f");
48
+ __classPrivateFieldSet(this, _ScrollSpyController_rootMargin, options.rootMargin, "f");
49
+ __classPrivateFieldSet(this, _ScrollSpyController_activeAttribute, options.activeAttribute ?? 'active', "f");
50
+ __classPrivateFieldSet(this, _ScrollSpyController_threshold, options.threshold ?? 0.85, "f");
51
+ __classPrivateFieldSet(this, _ScrollSpyController_rootNode, options.rootNode ?? host.getRootNode(), "f");
52
+ __classPrivateFieldSet(this, _ScrollSpyController_getHash, options?.getHash ?? ((el) => el.getAttribute('href')), "f");
53
+ }
54
+ hostConnected() {
55
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_initIo).call(this);
56
+ }
57
+ /** Explicitly set the active item */
58
+ async setActive(link) {
59
+ __classPrivateFieldSet(this, _ScrollSpyController_force, true, "f");
60
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, link);
61
+ let sawActive = false;
62
+ for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
63
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, child, !sawActive);
64
+ if (child === link) {
65
+ sawActive = true;
66
+ }
67
+ }
68
+ await __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_nextIntersection).call(this);
69
+ __classPrivateFieldSet(this, _ScrollSpyController_force, false, "f");
70
+ }
71
+ }
72
+ _ScrollSpyController_tagNames = new WeakMap(), _ScrollSpyController_activeAttribute = new WeakMap(), _ScrollSpyController_io = new WeakMap(), _ScrollSpyController_passedLinks = new WeakMap(), _ScrollSpyController_force = new WeakMap(), _ScrollSpyController_intersected = new WeakMap(), _ScrollSpyController_root = new WeakMap(), _ScrollSpyController_rootMargin = new WeakMap(), _ScrollSpyController_threshold = new WeakMap(), _ScrollSpyController_rootNode = new WeakMap(), _ScrollSpyController_getHash = new WeakMap(), _ScrollSpyController_instances = new WeakSet(), _ScrollSpyController_linkChildren_get = function _ScrollSpyController_linkChildren_get() {
73
+ return Array.from(this.host.querySelectorAll(__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')))
74
+ .filter(__classPrivateFieldGet(this, _ScrollSpyController_getHash, "f"));
75
+ }, _ScrollSpyController_initIo = function _ScrollSpyController_initIo() {
76
+ const rootNode = __classPrivateFieldGet(this, _ScrollSpyController_rootNode, "f");
77
+ if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
78
+ const { rootMargin, threshold, root } = this;
79
+ __classPrivateFieldSet(this, _ScrollSpyController_io, new IntersectionObserver(r => __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_onIo).call(this, r), { root, rootMargin, threshold }), "f");
80
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)
81
+ .map(x => __classPrivateFieldGet(this, _ScrollSpyController_getHash, "f").call(this, x))
82
+ .filter((x) => !!x)
83
+ .map(x => rootNode.getElementById(x.replace('#', '')))
84
+ .filter((x) => !!x)
85
+ .forEach(target => __classPrivateFieldGet(this, _ScrollSpyController_io, "f")?.observe(target));
86
+ }
87
+ }, _ScrollSpyController_markPassed = function _ScrollSpyController_markPassed(link, force) {
88
+ if (force) {
89
+ __classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").add(link);
90
+ }
91
+ else {
92
+ __classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f").delete(link);
93
+ }
94
+ }, _ScrollSpyController_setActive = function _ScrollSpyController_setActive(link) {
95
+ for (const child of __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get)) {
96
+ child.toggleAttribute(__classPrivateFieldGet(this, _ScrollSpyController_activeAttribute, "f"), child === link);
97
+ }
98
+ }, _ScrollSpyController_nextIntersection = async function _ScrollSpyController_nextIntersection() {
99
+ __classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f");
100
+ // safeguard the loop
101
+ setTimeout(() => __classPrivateFieldSet(this, _ScrollSpyController_intersected, false, "f"), 3000);
102
+ while (!__classPrivateFieldGet(this, _ScrollSpyController_intersected, "f")) {
103
+ await new Promise(requestAnimationFrame);
104
+ }
105
+ }, _ScrollSpyController_onIo = async function _ScrollSpyController_onIo(entries) {
106
+ if (!__classPrivateFieldGet(this, _ScrollSpyController_force, "f")) {
107
+ for (const { target, boundingClientRect, intersectionRect } of entries) {
108
+ const selector = `:is(${__classPrivateFieldGet(this, _ScrollSpyController_tagNames, "f").join(',')})[href="#${target.id}"]`;
109
+ const link = this.host.querySelector(selector);
110
+ if (link) {
111
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_markPassed).call(this, link, boundingClientRect.top < intersectionRect.top);
112
+ }
113
+ }
114
+ const link = [...__classPrivateFieldGet(this, _ScrollSpyController_passedLinks, "f")];
115
+ const last = link.at(-1);
116
+ __classPrivateFieldGet(this, _ScrollSpyController_instances, "m", _ScrollSpyController_setActive).call(this, last ?? __classPrivateFieldGet(this, _ScrollSpyController_instances, "a", _ScrollSpyController_linkChildren_get).at(0));
117
+ }
118
+ __classPrivateFieldSet(this, _ScrollSpyController_intersected, true, "f");
119
+ };
120
+ //# sourceMappingURL=scroll-spy-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-spy-controller.js","sourceRoot":"","sources":["scroll-spy-controller.ts"],"names":[],"mappings":";;AA2BA,MAAM,OAAO,mBAAmB;IA2B9B,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,iCAAM,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,CAAC,CAAC;QACR,uBAAA,IAAI,6BAAS,CAAC,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K,MAAA,CAAC;IAC1B,qBAAqB;IACrB,UAAU,CAAC,GAAG,EAAE,CAAC,uBAAA,IAAI,oCAAgB,KAAK,MAAA,EAAE,IAAI,CAAC,CAAC;IAClD,OAAO,CAAC,uBAAA,IAAI,wCAAa,EAAE;QACzB,MAAM,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;KAC1C;AACH,CAAC,8BAED,KAAK,oCAAO,OAAoC;IAC9C,IAAI,CAAC,uBAAA,IAAI,kCAAO,EAAE;QAChB,KAAK,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,IAAI,OAAO,EAAE;YACtE,MAAM,QAAQ,GAAG,OAAO,uBAAA,IAAI,qCAAU,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,MAAM,CAAC,EAAE,IAAI,CAAC;YAC1E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,IAAI,EAAE;gBACR,uBAAA,IAAI,uEAAY,MAAhB,IAAI,EAAa,IAAI,EAAE,kBAAkB,CAAC,GAAG,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;aACvE;SACF;QACD,MAAM,IAAI,GAAG,CAAC,GAAG,uBAAA,IAAI,wCAAa,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,uBAAA,IAAI,sEAAW,MAAf,IAAI,EAAY,IAAI,IAAI,uBAAA,IAAI,6EAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;KACnD;IACD,uBAAA,IAAI,oCAAgB,IAAI,MAAA,CAAC;AAC3B,CAAC","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface ScrollSpyControllerOptions extends IntersectionObserverInit {\n /**\n * Tag names of legal link children.\n * Legal children must have an `href` property/attribute pair, like `<a>`.\n */\n tagNames: string[];\n\n /**\n * Attribute to set on the active link element.\n * @default 'active'\n */\n activeAttribute?: string;\n\n /**\n * The root node to query content for\n * @default the host's root node\n */\n rootNode?: Node;\n /**\n * function to call on link children to get their URL hash (i.e. id to scroll to)\n * @default el => el.getAttribute('href');\n */\n getHash?: (el: Element) => string|null;\n}\n\nexport class ScrollSpyController implements ReactiveController {\n #tagNames: string[];\n #activeAttribute: string;\n\n #io?: IntersectionObserver;\n\n /** Which link's targets have already scrolled past? */\n #passedLinks = new Set<Element>();\n\n /** Ignore intersections? */\n #force = false;\n\n /** Has the intersection observer found an element? */\n #intersected = false;\n\n #root: ScrollSpyControllerOptions['root'];\n #rootMargin?: string;\n #threshold: number|number[];\n\n #rootNode: Node;\n #getHash: (el: Element) => string|null;\n\n get #linkChildren(): Element[] {\n return Array.from(this.host.querySelectorAll(this.#tagNames.join(',')))\n .filter(this.#getHash);\n }\n\n get root() {\n return this.#root;\n }\n\n set root(v) {\n this.#root = v;\n this.#io?.disconnect();\n this.#initIo();\n }\n\n get rootMargin() {\n return this.#rootMargin;\n }\n\n set rootMargin(v) {\n this.#rootMargin = v;\n this.#io?.disconnect();\n this.#initIo();\n }\n\n get threshold() {\n return this.#threshold;\n }\n\n set threshold(v) {\n this.#threshold = v;\n this.#io?.disconnect();\n this.#initIo();\n }\n\n constructor(\n private host: ReactiveControllerHost & HTMLElement,\n options: ScrollSpyControllerOptions,\n ) {\n host.addController(this);\n this.#tagNames = options.tagNames;\n this.#root = options.root;\n this.#rootMargin = options.rootMargin;\n this.#activeAttribute = options.activeAttribute ?? 'active';\n this.#threshold = options.threshold ?? 0.85;\n this.#rootNode = options.rootNode ?? host.getRootNode();\n this.#getHash = options?.getHash ?? ((el: Element) => el.getAttribute('href'));\n }\n\n hostConnected() {\n this.#initIo();\n }\n\n #initIo() {\n const rootNode = this.#rootNode;\n if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {\n const { rootMargin, threshold, root } = this;\n this.#io = new IntersectionObserver(r => this.#onIo(r), { root, rootMargin, threshold });\n this.#linkChildren\n .map(x => this.#getHash(x))\n .filter((x): x is string => !!x)\n .map(x => rootNode.getElementById(x.replace('#', '')))\n .filter((x): x is HTMLElement => !!x)\n .forEach(target => this.#io?.observe(target));\n }\n }\n\n #markPassed(link: Element, force: boolean) {\n if (force) {\n this.#passedLinks.add(link);\n } else {\n this.#passedLinks.delete(link);\n }\n }\n\n #setActive(link?: EventTarget|null) {\n for (const child of this.#linkChildren) {\n child.toggleAttribute(this.#activeAttribute, child === link);\n }\n }\n\n async #nextIntersection() {\n this.#intersected = false;\n // safeguard the loop\n setTimeout(() => this.#intersected = false, 3000);\n while (!this.#intersected) {\n await new Promise(requestAnimationFrame);\n }\n }\n\n async #onIo(entries: IntersectionObserverEntry[]) {\n if (!this.#force) {\n for (const { target, boundingClientRect, intersectionRect } of entries) {\n const selector = `:is(${this.#tagNames.join(',')})[href=\"#${target.id}\"]`;\n const link = this.host.querySelector(selector);\n if (link) {\n this.#markPassed(link, boundingClientRect.top < intersectionRect.top);\n }\n }\n const link = [...this.#passedLinks];\n const last = link.at(-1);\n this.#setActive(last ?? this.#linkChildren.at(0));\n }\n this.#intersected = true;\n }\n\n /** Explicitly set the active item */\n public async setActive(link: EventTarget|null) {\n this.#force = true;\n this.#setActive(link);\n let sawActive = false;\n for (const child of this.#linkChildren) {\n this.#markPassed(child, !sawActive);\n if (child === link) {\n sawActive = true;\n }\n }\n await this.#nextIntersection();\n this.#force = false;\n }\n}\n"]}
@@ -8,17 +8,17 @@ interface NamedSlot extends AnonymousSlot {
8
8
  name: string;
9
9
  initialized: true;
10
10
  }
11
- export declare type Slot = NamedSlot | AnonymousSlot;
11
+ export type Slot = NamedSlot | AnonymousSlot;
12
12
  export interface SlotsConfig {
13
13
  slots: (string | null)[];
14
14
  /**
15
15
  * Object mapping new slot name keys to deprecated slot name values
16
- * @example `pfe-modal--header` is deprecated in favour of `header`
16
+ * @example `pf-modal--header` is deprecated in favour of `header`
17
17
  * ```js
18
18
  * new SlotController(this, {
19
19
  * slots: ['header'],
20
20
  * deprecations: {
21
- * 'header': 'pfe-modal--header'
21
+ * 'header': 'pf-modal--header'
22
22
  * }
23
23
  * })
24
24
  * ```
@@ -1,2 +1,148 @@
1
- var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var a=(i,t,e,o)=>{for(var s=o>1?void 0:o?m(t,e):t,n=i.length-1,r;n>=0;n--)(r=i[n])&&(s=(o?r(t,e,s):r(s))||s);return o&&s&&c(t,e,s),s};import{bound as h}from"../decorators/bound.js";import{Logger as g}from"./logger.js";function u(i){return i.length===1&&typeof i[0]=="object"&&i[0]!==null}var p=i=>t=>i===l.anonymous?!t.hasAttribute("slot"):t.getAttribute("slot")===i,d=class{constructor(t,...e){this.host=t;this.nodes=new Map;this.firstUpdated=!1;this.mo=new MutationObserver(this.onMutation);this.deprecations={};if(this.logger=new g(this.host),u(e)){let[{slots:o,deprecations:s}]=e;this.slotNames=o,this.deprecations=s??{}}else e.length>=1?(this.slotNames=e,this.deprecations={}):this.slotNames=[null];t.addController(this)}hostConnected(){this.host.addEventListener("slotchange",this.onSlotChange),this.firstUpdated=!1,this.mo.observe(this.host,{childList:!0}),this.init()}hostUpdated(){this.firstUpdated||(this.slotNames.forEach(this.initSlot),this.firstUpdated=!0)}hostDisconnected(){this.mo.disconnect()}hasSlotted(...t){return t.length?t.some(e=>this.nodes.get(e)?.hasContent??!1):(this.logger.warn("Please provide at least one slot name for which to search."),!1)}getSlotted(...t){return t.length?t.flatMap(e=>this.nodes.get(e)?.elements??[]):this.nodes.get(d.anonymous)?.elements??[]}onSlotChange(t){let e=t.target.name;this.initSlot(e),this.host.requestUpdate()}async onMutation(t){let e=[];for(let{addedNodes:o,removedNodes:s}of t)for(let n of[...o,...s])n instanceof HTMLElement&&n.slot&&(this.initSlot(n.slot),e.push(n.slot));e.length&&this.host.requestUpdate()}getChildrenForSlot(t){return Array.from(this.host.children).filter(p(t))}initSlot(t){let e=t||d.anonymous,o=this.nodes.get(e)?.slot?.assignedElements?.()??this.getChildrenForSlot(e),s=t?`slot[name="${t}"]`:"slot:not([name])",n=this.host.shadowRoot?.querySelector?.(s)??null,r=!!o.length;this.nodes.set(e,{elements:o,name:t??"",hasContent:r,slot:n}),this.logger.log(t,r)}init(){this.nodes.clear(),this.slotNames.forEach(this.initSlot),Object.values(this.deprecations).forEach(this.initSlot),this.host.requestUpdate()}},l=d;l.anonymous=Symbol("anonymous slot"),a([h],l.prototype,"onSlotChange",1),a([h],l.prototype,"onMutation",1),a([h],l.prototype,"initSlot",1),a([h],l.prototype,"init",1);export{l as SlotController};
2
- //# sourceMappingURL=slot-controller.js.map
1
+ import { __decorate } from "tslib";
2
+ import { bound } from '../decorators/bound.js';
3
+ import { Logger } from './logger.js';
4
+ function isObjectConfigSpread(config) {
5
+ return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;
6
+ }
7
+ /**
8
+ * If it's a named slot, return its children,
9
+ * for the default slot, look for direct children not assigned to a slot
10
+ */
11
+ const isSlot = (n) => (child) => n === SlotController.anonymous ? !child.hasAttribute('slot')
12
+ : child.getAttribute('slot') === n;
13
+ export class SlotController {
14
+ constructor(host, ...config) {
15
+ this.host = host;
16
+ this.nodes = new Map();
17
+ this.firstUpdated = false;
18
+ this.mo = new MutationObserver(this.onMutation);
19
+ this.deprecations = {};
20
+ this.logger = new Logger(this.host);
21
+ if (isObjectConfigSpread(config)) {
22
+ const [{ slots, deprecations }] = config;
23
+ this.slotNames = slots;
24
+ this.deprecations = deprecations ?? {};
25
+ }
26
+ else if (config.length >= 1) {
27
+ this.slotNames = config;
28
+ this.deprecations = {};
29
+ }
30
+ else {
31
+ this.slotNames = [null];
32
+ }
33
+ host.addController(this);
34
+ }
35
+ hostConnected() {
36
+ this.host.addEventListener('slotchange', this.onSlotChange);
37
+ this.firstUpdated = false;
38
+ this.mo.observe(this.host, { childList: true });
39
+ this.init();
40
+ }
41
+ hostUpdated() {
42
+ if (!this.firstUpdated) {
43
+ this.slotNames.forEach(this.initSlot);
44
+ this.firstUpdated = true;
45
+ }
46
+ }
47
+ hostDisconnected() {
48
+ this.mo.disconnect();
49
+ }
50
+ /**
51
+ * Returns a boolean statement of whether or not any of those slots exists in the light DOM.
52
+ *
53
+ * @param {String|Array} name The slot name.
54
+ * @example this.hasSlotted("header");
55
+ */
56
+ hasSlotted(...names) {
57
+ if (!names.length) {
58
+ this.logger.warn(`Please provide at least one slot name for which to search.`);
59
+ return false;
60
+ }
61
+ else {
62
+ return names.some(x => this.nodes.get(x)?.hasContent ?? false);
63
+ }
64
+ }
65
+ /**
66
+ * Given a slot name or slot names, returns elements assigned to the requested slots as an array.
67
+ * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).
68
+ *
69
+ * @example Get header-slotted elements
70
+ * ```js
71
+ * this.getSlotted('header')
72
+ * ```
73
+ *
74
+ * @example Get header- and footer-slotted elements
75
+ * ```js
76
+ * this.getSlotted('header', 'footer')
77
+ * ```
78
+ *
79
+ * @example Get default-slotted elements
80
+ * ```js
81
+ * this.getSlotted();
82
+ * ```
83
+ */
84
+ getSlotted(...slotNames) {
85
+ if (!slotNames.length) {
86
+ return (this.nodes.get(SlotController.anonymous)?.elements ?? []);
87
+ }
88
+ else {
89
+ return slotNames.flatMap(slotName => this.nodes.get(slotName)?.elements ?? []);
90
+ }
91
+ }
92
+ onSlotChange(event) {
93
+ const slotName = event.target.name;
94
+ this.initSlot(slotName);
95
+ this.host.requestUpdate();
96
+ }
97
+ async onMutation(records) {
98
+ const changed = [];
99
+ for (const { addedNodes, removedNodes } of records) {
100
+ for (const node of [...addedNodes, ...removedNodes]) {
101
+ if (node instanceof HTMLElement && node.slot) {
102
+ this.initSlot(node.slot);
103
+ changed.push(node.slot);
104
+ }
105
+ }
106
+ }
107
+ if (changed.length) {
108
+ this.host.requestUpdate();
109
+ }
110
+ }
111
+ getChildrenForSlot(name) {
112
+ const children = Array.from(this.host.children);
113
+ return children.filter(isSlot(name));
114
+ }
115
+ initSlot(slotName) {
116
+ const name = slotName || SlotController.anonymous;
117
+ const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);
118
+ const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
119
+ const slot = this.host.shadowRoot?.querySelector?.(selector) ?? null;
120
+ const hasContent = !!elements.length;
121
+ this.nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
122
+ this.logger.log(slotName, hasContent);
123
+ }
124
+ /**
125
+ * Maps the defined slots into an object that is easier to query
126
+ */
127
+ init() {
128
+ this.nodes.clear();
129
+ // Loop over the properties provided by the schema
130
+ this.slotNames.forEach(this.initSlot);
131
+ Object.values(this.deprecations).forEach(this.initSlot);
132
+ this.host.requestUpdate();
133
+ }
134
+ }
135
+ SlotController.anonymous = Symbol('anonymous slot');
136
+ __decorate([
137
+ bound
138
+ ], SlotController.prototype, "onSlotChange", null);
139
+ __decorate([
140
+ bound
141
+ ], SlotController.prototype, "onMutation", null);
142
+ __decorate([
143
+ bound
144
+ ], SlotController.prototype, "initSlot", null);
145
+ __decorate([
146
+ bound
147
+ ], SlotController.prototype, "init", null);
148
+ //# sourceMappingURL=slot-controller.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["slot-controller.ts"],
4
- "sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { bound } from '../decorators/bound.js';\nimport { Logger } from './logger.js';\n\ninterface AnonymousSlot {\n hasContent: boolean;\n elements: Element[];\n slot: HTMLSlotElement|null;\n}\n\ninterface NamedSlot extends AnonymousSlot {\n name: string;\n initialized: true;\n}\n\nexport type Slot = NamedSlot|AnonymousSlot;\n\nexport interface SlotsConfig {\n slots: (string|null)[];\n /**\n * Object mapping new slot name keys to deprecated slot name values\n * @example `pfe-modal--header` is deprecated in favour of `header`\n * ```js\n * new SlotController(this, {\n * slots: ['header'],\n * deprecations: {\n * 'header': 'pfe-modal--header'\n * }\n * })\n * ```\n */\n deprecations?: Record<string, string>;\n}\n\nfunction isObjectConfigSpread(config: ([SlotsConfig]|(string|null)[])): config is [SlotsConfig] {\n return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;\n}\n\n/**\n * If it's a named slot, return its children,\n * for the default slot, look for direct children not assigned to a slot\n */\nconst isSlot =\n <T extends Element = Element>(n: string|typeof SlotController.anonymous) =>\n (child: Element): child is T =>\n n === SlotController.anonymous ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static anonymous = Symbol('anonymous slot');\n\n private nodes = new Map<string|typeof SlotController.anonymous, Slot>();\n\n private logger: Logger;\n\n private firstUpdated = false;\n\n private mo = new MutationObserver(this.onMutation);\n\n private slotNames: (string|null)[];\n\n private deprecations: Record<string, string> = {};\n\n constructor(public host: ReactiveElement, ...config: ([SlotsConfig]|(string|null)[])) {\n this.logger = new Logger(this.host);\n\n if (isObjectConfigSpread(config)) {\n const [{ slots, deprecations }] = config;\n this.slotNames = slots;\n this.deprecations = deprecations ?? {};\n } else if (config.length >= 1) {\n this.slotNames = config;\n this.deprecations = {};\n } else {\n this.slotNames = [null];\n }\n\n\n host.addController(this);\n }\n\n hostConnected() {\n this.host.addEventListener('slotchange', this.onSlotChange as EventListener);\n this.firstUpdated = false;\n this.mo.observe(this.host, { childList: true });\n this.init();\n }\n\n hostUpdated() {\n if (!this.firstUpdated) {\n this.slotNames.forEach(this.initSlot);\n this.firstUpdated = true;\n }\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n *\n * @param {String|Array} name The slot name.\n * @example this.hasSlotted(\"header\");\n */\n hasSlotted(...names: string[]): boolean {\n if (!names.length) {\n this.logger.warn(`Please provide at least one slot name for which to search.`);\n return false;\n } else {\n return names.some(x =>\n this.nodes.get(x)?.hasContent ?? false);\n }\n }\n\n /**\n * Given a slot name or slot names, returns elements assigned to the requested slots as an array.\n * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).\n *\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n *\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\n *\n * @example Get default-slotted elements\n * ```js\n * this.getSlotted();\n * ```\n */\n getSlotted<T extends Element = Element>(...slotNames: string[]): T[] {\n if (!slotNames.length) {\n return (this.nodes.get(SlotController.anonymous)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n @bound private onSlotChange(event: Event & { target: HTMLSlotElement }) {\n const slotName = event.target.name;\n this.initSlot(slotName);\n this.host.requestUpdate();\n }\n\n @bound private async onMutation(records: MutationRecord[]) {\n const changed = [];\n for (const { addedNodes, removedNodes } of records) {\n for (const node of [...addedNodes, ...removedNodes]) {\n if (node instanceof HTMLElement && node.slot) {\n this.initSlot(node.slot);\n changed.push(node.slot);\n }\n }\n }\n if (changed.length) {\n this.host.requestUpdate();\n }\n }\n\n private getChildrenForSlot<T extends Element = Element>(name: string|typeof SlotController.anonymous): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n @bound private initSlot(slotName: string|null) {\n const name = slotName || SlotController.anonymous;\n const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n const hasContent = !!elements.length;\n this.nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });\n this.logger.log(slotName, hasContent);\n }\n\n /**\n * Maps the defined slots into an object that is easier to query\n */\n @bound private init() {\n this.nodes.clear();\n // Loop over the properties provided by the schema\n this.slotNames.forEach(this.initSlot);\n Object.values(this.deprecations).forEach(this.initSlot);\n this.host.requestUpdate();\n }\n}\n"],
5
- "mappings": "wMAEA,OAAS,SAAAA,MAAa,yBACtB,OAAS,UAAAC,MAAc,cAgCvB,SAASC,EAAqB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,EACG,UAAY,OAAO,gBAAgB,EA8FlCqB,EAAA,CAAfC,GA/FWtB,EA+FI,4BAMMqB,EAAA,CAArBC,GArGWtB,EAqGU,0BAoBNqB,EAAA,CAAfC,GAzHWtB,EAyHI,wBAaAqB,EAAA,CAAfC,GAtIWtB,EAsII",
6
- "names": ["bound", "Logger", "isObjectConfigSpread", "config", "isSlot", "n", "child", "SlotController", "_SlotController", "host", "Logger", "slots", "deprecations", "names", "x", "slotNames", "slotName", "event", "records", "changed", "addedNodes", "removedNodes", "node", "name", "elements", "selector", "slot", "hasContent", "__decorateClass", "bound"]
7
- }
1
+ {"version":3,"file":"slot-controller.js","sourceRoot":"","sources":["slot-controller.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgCrC,SAAS,oBAAoB,CAAC,MAAuC;IACnE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AACpF,CAAC;AAED;;;GAGG;AACH,MAAM,MAAM,GACV,CAA8B,CAAyC,EAAE,EAAE,CACzE,CAAC,KAAc,EAAc,EAAE,CAC3B,CAAC,KAAK,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;IAC9D,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzC,MAAM,OAAO,cAAc;IAezB,YAAmB,IAAqB,EAAE,GAAG,MAAuC;QAAjE,SAAI,GAAJ,IAAI,CAAiB;QAZhC,UAAK,GAAG,IAAI,GAAG,EAAgD,CAAC;QAIhE,iBAAY,GAAG,KAAK,CAAC;QAErB,OAAE,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,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,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;;AA3Ia,wBAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AA8F5C;IAAN,KAAK;kDAIL;AAEoB;IAApB,KAAK;gDAaL;AAOM;IAAN,KAAK;8CAQL;AAKM;IAAN,KAAK;0CAML","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { bound } from '../decorators/bound.js';\nimport { Logger } from './logger.js';\n\ninterface AnonymousSlot {\n hasContent: boolean;\n elements: Element[];\n slot: HTMLSlotElement|null;\n}\n\ninterface NamedSlot extends AnonymousSlot {\n name: string;\n initialized: true;\n}\n\nexport type Slot = NamedSlot|AnonymousSlot;\n\nexport interface SlotsConfig {\n slots: (string|null)[];\n /**\n * Object mapping new slot name keys to deprecated slot name values\n * @example `pf-modal--header` is deprecated in favour of `header`\n * ```js\n * new SlotController(this, {\n * slots: ['header'],\n * deprecations: {\n * 'header': 'pf-modal--header'\n * }\n * })\n * ```\n */\n deprecations?: Record<string, string>;\n}\n\nfunction isObjectConfigSpread(config: ([SlotsConfig]|(string|null)[])): config is [SlotsConfig] {\n return config.length === 1 && typeof config[0] === 'object' && config[0] !== null;\n}\n\n/**\n * If it's a named slot, return its children,\n * for the default slot, look for direct children not assigned to a slot\n */\nconst isSlot =\n <T extends Element = Element>(n: string|typeof SlotController.anonymous) =>\n (child: Element): child is T =>\n n === SlotController.anonymous ? !child.hasAttribute('slot')\n : child.getAttribute('slot') === n;\n\nexport class SlotController implements ReactiveController {\n public static anonymous = Symbol('anonymous slot');\n\n private nodes = new Map<string|typeof SlotController.anonymous, Slot>();\n\n private logger: Logger;\n\n private firstUpdated = false;\n\n private mo = new MutationObserver(this.onMutation);\n\n private slotNames: (string|null)[];\n\n private deprecations: Record<string, string> = {};\n\n constructor(public host: ReactiveElement, ...config: ([SlotsConfig]|(string|null)[])) {\n this.logger = new Logger(this.host);\n\n if (isObjectConfigSpread(config)) {\n const [{ slots, deprecations }] = config;\n this.slotNames = slots;\n this.deprecations = deprecations ?? {};\n } else if (config.length >= 1) {\n this.slotNames = config;\n this.deprecations = {};\n } else {\n this.slotNames = [null];\n }\n\n\n host.addController(this);\n }\n\n hostConnected() {\n this.host.addEventListener('slotchange', this.onSlotChange as EventListener);\n this.firstUpdated = false;\n this.mo.observe(this.host, { childList: true });\n this.init();\n }\n\n hostUpdated() {\n if (!this.firstUpdated) {\n this.slotNames.forEach(this.initSlot);\n this.firstUpdated = true;\n }\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n /**\n * Returns a boolean statement of whether or not any of those slots exists in the light DOM.\n *\n * @param {String|Array} name The slot name.\n * @example this.hasSlotted(\"header\");\n */\n hasSlotted(...names: string[]): boolean {\n if (!names.length) {\n this.logger.warn(`Please provide at least one slot name for which to search.`);\n return false;\n } else {\n return names.some(x =>\n this.nodes.get(x)?.hasContent ?? false);\n }\n }\n\n /**\n * Given a slot name or slot names, returns elements assigned to the requested slots as an array.\n * If no value is provided, it returns all children not assigned to a slot (without a slot attribute).\n *\n * @example Get header-slotted elements\n * ```js\n * this.getSlotted('header')\n * ```\n *\n * @example Get header- and footer-slotted elements\n * ```js\n * this.getSlotted('header', 'footer')\n * ```\n *\n * @example Get default-slotted elements\n * ```js\n * this.getSlotted();\n * ```\n */\n getSlotted<T extends Element = Element>(...slotNames: string[]): T[] {\n if (!slotNames.length) {\n return (this.nodes.get(SlotController.anonymous)?.elements ?? []) as T[];\n } else {\n return slotNames.flatMap(slotName =>\n this.nodes.get(slotName)?.elements ?? []) as T[];\n }\n }\n\n @bound private onSlotChange(event: Event & { target: HTMLSlotElement }) {\n const slotName = event.target.name;\n this.initSlot(slotName);\n this.host.requestUpdate();\n }\n\n @bound private async onMutation(records: MutationRecord[]) {\n const changed = [];\n for (const { addedNodes, removedNodes } of records) {\n for (const node of [...addedNodes, ...removedNodes]) {\n if (node instanceof HTMLElement && node.slot) {\n this.initSlot(node.slot);\n changed.push(node.slot);\n }\n }\n }\n if (changed.length) {\n this.host.requestUpdate();\n }\n }\n\n private getChildrenForSlot<T extends Element = Element>(name: string|typeof SlotController.anonymous): T[] {\n const children = Array.from(this.host.children) as T[];\n return children.filter(isSlot(name));\n }\n\n @bound private initSlot(slotName: string|null) {\n const name = slotName || SlotController.anonymous;\n const elements = this.nodes.get(name)?.slot?.assignedElements?.() ?? this.getChildrenForSlot(name);\n const selector = slotName ? `slot[name=\"${slotName}\"]` : 'slot:not([name])';\n const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;\n const hasContent = !!elements.length;\n this.nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });\n this.logger.log(slotName, hasContent);\n }\n\n /**\n * Maps the defined slots into an object that is easier to query\n */\n @bound private init() {\n this.nodes.clear();\n // Loop over the properties provided by the schema\n this.slotNames.forEach(this.initSlot);\n Object.values(this.deprecations).forEach(this.initSlot);\n this.host.requestUpdate();\n }\n}\n"]}
@@ -1,2 +1,42 @@
1
- import{getCompatibleStyle as i,supportsAdoptingStyleSheets as n}from"lit";var l=class{constructor(t,e){this.host=t;this.styles=e;this.stylesAdopted=!1;t.addController(this)}hostConnected(){if(this.stylesAdopted||!(this.host.renderRoot instanceof ShadowRoot))return;let t=[this.styles].flatMap(e=>i(e)).filter(e=>!!e);n?this.host.renderRoot.adoptedStyleSheets=[...t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet),...this.host.renderRoot.adoptedStyleSheets??[]]:t.forEach(e=>{let s=document.createElement("style"),o=window.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=e.cssText,this.host.renderRoot.appendChild(s)}),this.stylesAdopted=!0}};export{l as StyleController};
2
- //# sourceMappingURL=style-controller.js.map
1
+ import { getCompatibleStyle, supportsAdoptingStyleSheets } from 'lit';
2
+ /**
3
+ * Controller which adds styles to it's host element.
4
+ * Like `static styles = []`, except a controller.
5
+ * Should typically only be used within other controllers.
6
+ */
7
+ export class StyleController {
8
+ constructor(host,
9
+ /** These styles will be applied to the host element */
10
+ styles) {
11
+ this.host = host;
12
+ this.styles = styles;
13
+ this.stylesAdopted = false;
14
+ host.addController(this);
15
+ }
16
+ hostConnected() {
17
+ if (this.stylesAdopted || !(this.host.renderRoot instanceof ShadowRoot)) {
18
+ return;
19
+ }
20
+ const styles = [this.styles].flatMap(x => getCompatibleStyle(x)).filter(x => !!x);
21
+ if (supportsAdoptingStyleSheets) {
22
+ this.host.renderRoot.adoptedStyleSheets = [
23
+ ...styles.map(x => x instanceof CSSStyleSheet ? x : x.styleSheet),
24
+ ...this.host.renderRoot.adoptedStyleSheets ?? [],
25
+ ];
26
+ }
27
+ else {
28
+ styles.forEach(s => {
29
+ const style = document.createElement('style');
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ const nonce = window['litNonce'];
32
+ if (nonce !== undefined) {
33
+ style.setAttribute('nonce', nonce);
34
+ }
35
+ style.textContent = s.cssText;
36
+ this.host.renderRoot.appendChild(style);
37
+ });
38
+ }
39
+ this.stylesAdopted = true;
40
+ }
41
+ }
42
+ //# sourceMappingURL=style-controller.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["style-controller.ts"],
4
- "sourcesContent": ["import type { ReactiveController, ReactiveElement, CSSResultGroup, CSSResultOrNative, CSSResult } from 'lit';\nimport { getCompatibleStyle, supportsAdoptingStyleSheets } from 'lit';\n\ndeclare global {\n interface ShadowRoot {\n adoptedStyleSheets: CSSStyleSheet[];\n }\n}\n\n/**\n * Controller which adds styles to it's host element.\n * Like `static styles = []`, except a controller.\n * Should typically only be used within other controllers.\n */\nexport class StyleController implements ReactiveController {\n private stylesAdopted = false;\n\n constructor(\n private host: ReactiveElement,\n /** These styles will be applied to the host element */\n private styles: CSSResultGroup,\n ) {\n host.addController(this);\n }\n\n hostConnected(): void {\n if (this.stylesAdopted || !(this.host.renderRoot instanceof ShadowRoot)) {\n return;\n }\n\n const styles = [this.styles].flatMap(x => getCompatibleStyle(x as CSSResultOrNative)).filter(x => !!x);\n\n if (supportsAdoptingStyleSheets) {\n this.host.renderRoot.adoptedStyleSheets = [\n ...styles.map(x => x instanceof CSSStyleSheet ? x : x.styleSheet as CSSStyleSheet),\n ...this.host.renderRoot.adoptedStyleSheets ?? [],\n ];\n } else {\n styles.forEach(s => {\n const style = document.createElement('style');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nonce = (window as any)['litNonce'];\n if (nonce !== undefined) {\n style.setAttribute('nonce', nonce);\n }\n style.textContent = (s as CSSResult).cssText;\n this.host.renderRoot.appendChild(style);\n });\n }\n\n this.stylesAdopted = true;\n }\n}\n"],
5
- "mappings": "AACA,OAAS,sBAAAA,EAAoB,+BAAAC,MAAmC,MAazD,IAAMC,EAAN,KAAoD,CAGzD,YACUC,EAEAC,EACR,CAHQ,UAAAD,EAEA,YAAAC,EALV,KAAQ,cAAgB,GAOtBD,EAAK,cAAc,IAAI,CACzB,CAEA,eAAsB,CACpB,GAAI,KAAK,eAAiB,EAAE,KAAK,KAAK,sBAAsB,YAC1D,OAGF,IAAMC,EAAS,CAAC,KAAK,MAAM,EAAE,QAAQC,GAAKL,EAAmBK,CAAsB,CAAC,EAAE,OAAOA,GAAK,CAAC,CAACA,CAAC,EAEjGJ,EACF,KAAK,KAAK,WAAW,mBAAqB,CACxC,GAAGG,EAAO,IAAIC,GAAKA,aAAa,cAAgBA,EAAIA,EAAE,UAA2B,EACjF,GAAG,KAAK,KAAK,WAAW,oBAAsB,CAAC,CACjD,EAEAD,EAAO,QAAQE,GAAK,CAClB,IAAMC,EAAQ,SAAS,cAAc,OAAO,EAEtCC,EAAS,OAAe,SAC1BA,IAAU,QACZD,EAAM,aAAa,QAASC,CAAK,EAEnCD,EAAM,YAAeD,EAAgB,QACrC,KAAK,KAAK,WAAW,YAAYC,CAAK,CACxC,CAAC,EAGH,KAAK,cAAgB,EACvB,CACF",
6
- "names": ["getCompatibleStyle", "supportsAdoptingStyleSheets", "StyleController", "host", "styles", "x", "s", "style", "nonce"]
7
- }
1
+ {"version":3,"file":"style-controller.js","sourceRoot":"","sources":["style-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,KAAK,CAAC;AAQtE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAG1B,YACU,IAAqB;IAC7B,uDAAuD;IAC/C,MAAsB;QAFtB,SAAI,GAAJ,IAAI,CAAiB;QAErB,WAAM,GAAN,MAAM,CAAgB;QALxB,kBAAa,GAAG,KAAK,CAAC;QAO5B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,aAAa;QACX,IAAI,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,YAAY,UAAU,CAAC,EAAE;YACvE,OAAO;SACR;QAED,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAsB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvG,IAAI,2BAA2B,EAAE;YAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,GAAG;gBACxC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAA2B,CAAC;gBAClF,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,IAAI,EAAE;aACjD,CAAC;SACH;aAAM;YACL,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACjB,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;gBAC9C,8DAA8D;gBAC9D,MAAM,KAAK,GAAI,MAAc,CAAC,UAAU,CAAC,CAAC;gBAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;oBACvB,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;iBACpC;gBACD,KAAK,CAAC,WAAW,GAAI,CAAe,CAAC,OAAO,CAAC;gBAC7C,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import type { ReactiveController, ReactiveElement, CSSResultGroup, CSSResultOrNative, CSSResult } from 'lit';\nimport { getCompatibleStyle, supportsAdoptingStyleSheets } from 'lit';\n\ndeclare global {\n interface ShadowRoot {\n adoptedStyleSheets: CSSStyleSheet[];\n }\n}\n\n/**\n * Controller which adds styles to it's host element.\n * Like `static styles = []`, except a controller.\n * Should typically only be used within other controllers.\n */\nexport class StyleController implements ReactiveController {\n private stylesAdopted = false;\n\n constructor(\n private host: ReactiveElement,\n /** These styles will be applied to the host element */\n private styles: CSSResultGroup,\n ) {\n host.addController(this);\n }\n\n hostConnected(): void {\n if (this.stylesAdopted || !(this.host.renderRoot instanceof ShadowRoot)) {\n return;\n }\n\n const styles = [this.styles].flatMap(x => getCompatibleStyle(x as CSSResultOrNative)).filter(x => !!x);\n\n if (supportsAdoptingStyleSheets) {\n this.host.renderRoot.adoptedStyleSheets = [\n ...styles.map(x => x instanceof CSSStyleSheet ? x : x.styleSheet as CSSStyleSheet),\n ...this.host.renderRoot.adoptedStyleSheets ?? [],\n ];\n } else {\n styles.forEach(s => {\n const style = document.createElement('style');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nonce = (window as any)['litNonce'];\n if (nonce !== undefined) {\n style.setAttribute('nonce', nonce);\n }\n style.textContent = (s as CSSResult).cssText;\n this.host.renderRoot.appendChild(style);\n });\n }\n\n this.stylesAdopted = true;\n }\n}\n"]}
package/core.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { ComplexAttributeConverter } from 'lit';
2
- export type { ColorPalette, ColorTheme } from './controllers/color-context.js';
3
2
  /** PatternFly Elements global config object */
4
3
  export interface PfeConfig {
5
4
  /** Set to false to disable client-side page load performance tracking */
@@ -34,3 +33,4 @@ declare global {
34
33
  PfeConfig: PfeConfig;
35
34
  }
36
35
  }
36
+ export {};
package/core.js CHANGED
@@ -1,2 +1,68 @@
1
- var o=Symbol();function r(e){return document.head.querySelector(`meta[name="${e}"]`)?.content}function l(e=o){return e!==o&&(window.PfeConfig.trackPerformance=!!e),window.PfeConfig.trackPerformance}var i={fromAttribute(e){return typeof e!="string"?null:e.split(",").map(t=>t.trim()).map(t=>parseInt(t,10))},toAttribute(e){return e.join(",")}},n=class extends Event{constructor(t,f){super(t,{bubbles:!0,composed:!0,...f})}},a=document.body.hasAttribute("no-auto-reveal");window.PfeConfig=Object.assign(window.PfeConfig??{},{trackPerformance:window.PfeConfig?.trackPerformance??r("pfe-track-performance")==="true",autoReveal:window.PfeConfig?.autoReveal??(a?!a:r("pfe-auto-reveal")==="true"),get log(){return!!localStorage.pfeLog},set log(e){e?localStorage.setItem("pfeLog",`${!0}`):localStorage.removeItem("pfeLog")}});export{n as ComposedEvent,i as NumberListConverter,l as trackPerformance};
2
- //# sourceMappingURL=core.js.map
1
+ const noPref = Symbol();
2
+ /** Retrieve an HTML metadata item */
3
+ function getMeta(name) {
4
+ return document.head.querySelector(`meta[name="${name}"]`)?.content;
5
+ }
6
+ /**
7
+ * A boolean value that indicates if the performance should be tracked.
8
+ * For use in a JS file or script tag; can also be added in the constructor of a component during development.
9
+ * @example trackPerformance(true);
10
+ */
11
+ export function trackPerformance(preference = noPref) {
12
+ if (preference !== noPref) {
13
+ window.PfeConfig.trackPerformance = !!preference;
14
+ }
15
+ return window.PfeConfig.trackPerformance;
16
+ }
17
+ /**
18
+ * A LitElement property converter which represents a list of numbers as a comma separated string
19
+ * @see https://lit.dev/docs/components/properties/#conversion-converter
20
+ */
21
+ export const NumberListConverter = {
22
+ fromAttribute(value) {
23
+ if (typeof value !== 'string') {
24
+ return null;
25
+ }
26
+ else {
27
+ return value.split(',').map(x => x.trim()).map(x => parseInt(x, 10));
28
+ }
29
+ },
30
+ toAttribute(value) {
31
+ return value.join(',');
32
+ },
33
+ };
34
+ /**
35
+ * A composed, bubbling event for UI interactions
36
+ * e.g. when an accordion panel opens.
37
+ */
38
+ export class ComposedEvent extends Event {
39
+ constructor(type, init) {
40
+ super(type, {
41
+ bubbles: true,
42
+ composed: true,
43
+ ...init
44
+ });
45
+ }
46
+ }
47
+ const bodyNoAutoReveal = document.body.hasAttribute('no-auto-reveal');
48
+ /** Global patternfly elements config */
49
+ window.PfeConfig = Object.assign(window.PfeConfig ?? {}, {
50
+ trackPerformance: window.PfeConfig?.trackPerformance ?? getMeta('pf-track-performance') === 'true',
51
+ // if the body tag has `no-auto-reveal` attribute, reveal immediately
52
+ // if `<meta name="pf-auto-reveal">` exists, and it's `content` is 'true',
53
+ // then auto-reveal the body
54
+ autoReveal: window.PfeConfig?.autoReveal ?? (bodyNoAutoReveal ? !bodyNoAutoReveal
55
+ : getMeta('pf-auto-reveal') === 'true'),
56
+ get log() {
57
+ return !!localStorage.pfeLog;
58
+ },
59
+ set log(v) {
60
+ if (v) {
61
+ localStorage.setItem('pfeLog', `${true}`);
62
+ }
63
+ else {
64
+ localStorage.removeItem('pfeLog');
65
+ }
66
+ },
67
+ });
68
+ //# sourceMappingURL=core.js.map
package/core.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["core.ts"],
4
- "sourcesContent": ["import type { ComplexAttributeConverter } from 'lit';\n\nexport type { ColorPalette, ColorTheme } from './controllers/color-context.js';\n\n/** PatternFly Elements global config object */\nexport interface PfeConfig {\n /** Set to false to disable client-side page load performance tracking */\n trackPerformance?: boolean;\n /** Set to false to disable various debug logs */\n log?: boolean;\n /** Set to false to disable automatically removing `unresolved` attr from body */\n autoReveal?: boolean;\n}\n\nconst noPref = Symbol();\n\n/** Retrieve an HTML metadata item */\nfunction getMeta(name: string): string|undefined {\n return document.head.querySelector<HTMLMetaElement>(`meta[name=\"${name}\"]`)?.content;\n}\n\n/**\n * A boolean value that indicates if the performance should be tracked.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example trackPerformance(true);\n */\nexport function trackPerformance(preference: boolean | typeof noPref = noPref) {\n if (preference !== noPref) {\n window.PfeConfig.trackPerformance = !!preference;\n }\n return window.PfeConfig.trackPerformance;\n}\n\n/**\n * A LitElement property converter which represents a list of numbers as a comma separated string\n * @see https://lit.dev/docs/components/properties/#conversion-converter\n */\nexport const NumberListConverter: ComplexAttributeConverter<null|number[]> = {\n fromAttribute(value: string) {\n if (typeof value !== 'string') {\n return null;\n } else {\n return value.split(',').map(x => x.trim()).map(x => parseInt(x, 10));\n }\n },\n toAttribute(value: number[]) {\n return value.join(',');\n },\n};\n\n/**\n * A composed, bubbling event for UI interactions\n * e.g. when an accordion panel opens.\n */\nexport class ComposedEvent extends Event {\n constructor(type: string, init?: EventInit) {\n super(type, {\n bubbles: true,\n composed: true,\n ...init\n });\n }\n}\n\n// \uD83D\uDC47 SIDE EFFECTS \uD83D\uDC47\n\ndeclare global {\n interface Window {\n /** Global configuration settings for PatternFly Elements */\n PfeConfig: PfeConfig;\n }\n}\n\nconst bodyNoAutoReveal = document.body.hasAttribute('no-auto-reveal');\n\n/** Global patternfly elements config */\nwindow.PfeConfig = Object.assign(window.PfeConfig ?? {}, {\n trackPerformance: window.PfeConfig?.trackPerformance ?? getMeta('pfe-track-performance') === 'true',\n // if the body tag has `no-auto-reveal` attribute, reveal immediately\n // if `<meta name=\"pfe-auto-reveal\">` exists, and it's `content` is 'true',\n // then auto-reveal the body\n autoReveal: window.PfeConfig?.autoReveal ?? (\n bodyNoAutoReveal ? !bodyNoAutoReveal\n : getMeta('pfe-auto-reveal') === 'true'\n ),\n get log() {\n return !!localStorage.pfeLog;\n },\n set log(v: boolean) {\n if (v) {\n localStorage.setItem('pfeLog', `${true}`);\n } else {\n localStorage.removeItem('pfeLog');\n }\n },\n});\n"],
5
- "mappings": "AAcA,IAAMA,EAAS,OAAO,EAGtB,SAASC,EAAQC,EAAgC,CAC/C,OAAO,SAAS,KAAK,cAA+B,cAAcA,KAAQ,GAAG,OAC/E,CAOO,SAASC,EAAiBC,EAAsCJ,EAAQ,CAC7E,OAAII,IAAeJ,IACjB,OAAO,UAAU,iBAAmB,CAAC,CAACI,GAEjC,OAAO,UAAU,gBAC1B,CAMO,IAAMC,EAAgE,CAC3E,cAAcC,EAAe,CAC3B,OAAI,OAAOA,GAAU,SACZ,KAEAA,EAAM,MAAM,GAAG,EAAE,IAAIC,GAAKA,EAAE,KAAK,CAAC,EAAE,IAAIA,GAAK,SAASA,EAAG,EAAE,CAAC,CAEvE,EACA,YAAYD,EAAiB,CAC3B,OAAOA,EAAM,KAAK,GAAG,CACvB,CACF,EAMaE,EAAN,cAA4B,KAAM,CACvC,YAAYC,EAAcC,EAAkB,CAC1C,MAAMD,EAAM,CACV,QAAS,GACT,SAAU,GACV,GAAGC,CACL,CAAC,CACH,CACF,EAWMC,EAAmB,SAAS,KAAK,aAAa,gBAAgB,EAGpE,OAAO,UAAY,OAAO,OAAO,OAAO,WAAa,CAAC,EAAG,CACvD,iBAAkB,OAAO,WAAW,kBAAoBV,EAAQ,uBAAuB,IAAM,OAI7F,WAAY,OAAO,WAAW,aAC1BU,EAAmB,CAACA,EACpBV,EAAQ,iBAAiB,IAAM,QAEnC,IAAI,KAAM,CACR,MAAO,CAAC,CAAC,aAAa,MACxB,EACA,IAAI,IAAIW,EAAY,CACdA,EACF,aAAa,QAAQ,SAAU,GAAG,IAAM,EAExC,aAAa,WAAW,QAAQ,CAEpC,CACF,CAAC",
6
- "names": ["noPref", "getMeta", "name", "trackPerformance", "preference", "NumberListConverter", "value", "x", "ComposedEvent", "type", "init", "bodyNoAutoReveal", "v"]
7
- }
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;AAExB,qCAAqC;AACrC,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAkB,cAAc,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,aAAsC,MAAM;IAC3E,IAAI,UAAU,KAAK,MAAM,EAAE;QACzB,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAG,CAAC,CAAC,UAAU,CAAC;KAClD;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA6C;IAC3E,aAAa,CAAC,KAAa;QACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,CAAC;SACb;aAAM;YACL,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;SACtE;IACH,CAAC;IACD,WAAW,CAAC,KAAe;QACzB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,IAAY,EAAE,IAAgB;QACxC,KAAK,CAAC,IAAI,EAAE;YACV,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;AAWD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAEtE,wCAAwC;AACxC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE;IACvD,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,CAAC,KAAK,MAAM;IAClG,qEAAqE;IACrE,0EAA0E;IAC1E,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,UAAU,IAAI,CACxC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB;QACtC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,MAAM,CACvC;IACD,IAAI,GAAG;QACL,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC;IAC/B,CAAC;IACD,IAAI,GAAG,CAAC,CAAU;QAChB,IAAI,CAAC,EAAE;YACL,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;SAC3C;aAAM;YACL,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SACnC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { ComplexAttributeConverter } from 'lit';\n\n/** PatternFly Elements global config object */\nexport interface PfeConfig {\n /** Set to false to disable client-side page load performance tracking */\n trackPerformance?: boolean;\n /** Set to false to disable various debug logs */\n log?: boolean;\n /** Set to false to disable automatically removing `unresolved` attr from body */\n autoReveal?: boolean;\n}\n\nconst noPref = Symbol();\n\n/** Retrieve an HTML metadata item */\nfunction getMeta(name: string): string|undefined {\n return document.head.querySelector<HTMLMetaElement>(`meta[name=\"${name}\"]`)?.content;\n}\n\n/**\n * A boolean value that indicates if the performance should be tracked.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example trackPerformance(true);\n */\nexport function trackPerformance(preference: boolean | typeof noPref = noPref) {\n if (preference !== noPref) {\n window.PfeConfig.trackPerformance = !!preference;\n }\n return window.PfeConfig.trackPerformance;\n}\n\n/**\n * A LitElement property converter which represents a list of numbers as a comma separated string\n * @see https://lit.dev/docs/components/properties/#conversion-converter\n */\nexport const NumberListConverter: ComplexAttributeConverter<null|number[]> = {\n fromAttribute(value: string) {\n if (typeof value !== 'string') {\n return null;\n } else {\n return value.split(',').map(x => x.trim()).map(x => parseInt(x, 10));\n }\n },\n toAttribute(value: number[]) {\n return value.join(',');\n },\n};\n\n/**\n * A composed, bubbling event for UI interactions\n * e.g. when an accordion panel opens.\n */\nexport class ComposedEvent extends Event {\n constructor(type: string, init?: EventInit) {\n super(type, {\n bubbles: true,\n composed: true,\n ...init\n });\n }\n}\n\n// 👇 SIDE EFFECTS 👇\n\ndeclare global {\n interface Window {\n /** Global configuration settings for PatternFly Elements */\n PfeConfig: PfeConfig;\n }\n}\n\nconst bodyNoAutoReveal = document.body.hasAttribute('no-auto-reveal');\n\n/** Global patternfly elements config */\nwindow.PfeConfig = Object.assign(window.PfeConfig ?? {}, {\n trackPerformance: window.PfeConfig?.trackPerformance ?? getMeta('pf-track-performance') === 'true',\n // if the body tag has `no-auto-reveal` attribute, reveal immediately\n // if `<meta name=\"pf-auto-reveal\">` exists, and it's `content` is 'true',\n // then auto-reveal the body\n autoReveal: window.PfeConfig?.autoReveal ?? (\n bodyNoAutoReveal ? !bodyNoAutoReveal\n : getMeta('pf-auto-reveal') === 'true'\n ),\n get log() {\n return !!localStorage.pfeLog;\n },\n set log(v: boolean) {\n if (v) {\n localStorage.setItem('pfeLog', `${true}`);\n } else {\n localStorage.removeItem('pfeLog');\n }\n },\n});\n"]}