@patternfly/pfe-core 2.0.0-next.0 → 2.0.0-next.10
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/context.js +1 -1
- package/context.js.map +2 -2
- package/controllers/cascade-controller.js +1 -1
- package/controllers/cascade-controller.js.map +2 -2
- package/controllers/color-context.d.ts +115 -0
- package/controllers/color-context.js +2 -0
- package/controllers/color-context.js.map +7 -0
- package/controllers/{color-context-controller.scss → color-context.scss} +58 -17
- package/controllers/css-variable-controller.js.map +2 -2
- package/controllers/floating-dom-controller.d.ts +30 -0
- package/controllers/floating-dom-controller.js +2 -0
- package/controllers/floating-dom-controller.js.map +7 -0
- package/controllers/light-dom-controller.js +1 -1
- package/controllers/light-dom-controller.js.map +2 -2
- package/controllers/logger.js +1 -1
- package/controllers/logger.js.map +3 -3
- package/controllers/perf-controller.js +1 -1
- package/controllers/perf-controller.js.map +2 -2
- package/controllers/property-observer-controller.js +1 -1
- package/controllers/property-observer-controller.js.map +2 -2
- package/controllers/slot-controller.js +1 -1
- package/controllers/slot-controller.js.map +3 -3
- package/controllers/style-controller.js +1 -1
- package/controllers/style-controller.js.map +3 -3
- package/core.d.ts +1 -3
- package/core.js +1 -1
- package/core.js.map +3 -3
- package/decorators/bound.js.map +2 -2
- package/decorators/cascades.js.map +2 -2
- package/decorators/color-context.d.ts +4 -0
- package/decorators/color-context.js +2 -0
- package/decorators/color-context.js.map +7 -0
- package/decorators/deprecation.d.ts +16 -0
- package/decorators/deprecation.js +2 -0
- package/decorators/deprecation.js.map +7 -0
- package/decorators/initializer.js.map +2 -2
- package/decorators/observed.d.ts +1 -1
- package/decorators/observed.js.map +3 -3
- package/decorators/pfelement.d.ts +5 -1
- package/decorators/pfelement.js +1 -1
- package/decorators/pfelement.js.map +3 -3
- package/decorators/time.js.map +2 -2
- package/decorators/trace.js.map +2 -2
- package/decorators.d.ts +2 -0
- package/decorators.js +1 -1
- package/decorators.js.map +2 -2
- package/functions/debounce.js.map +2 -2
- package/functions/deprecatedCustomEvent.js.map +2 -2
- package/functions/random.js.map +2 -2
- package/package.json +29 -26
- package/controllers/color-context-controller.d.ts +0 -41
- package/controllers/color-context-controller.js +0 -55
- package/controllers/color-context-controller.js.map +0 -7
package/context.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function r(e,t){return{name:e,initialValue:t}}var n=class extends Event{constructor(o,l,x){super("context-request",{bubbles:!0,composed:!0});this.context=o;this.callback=l;this.multiple=x}};export{n as ContextEvent,r as createContext};
|
|
2
2
|
//# sourceMappingURL=context.js.map
|
package/context.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["context.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Context Protocol\n * @link https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md\n */\n\n/**\n * A Context object defines an optional initial value for a Context, as well as a name identifier for debugging purposes.\n */\nexport type Context<T> = {\n name: string;\n initialValue?: T;\n};\n\n/**\n * An unknown context typeU\n */\nexport type UnknownContext = Context<unknown>;\n\n/**\n * A helper type which can extract a Context value type from a Context type\n */\nexport type ContextType<T extends UnknownContext> = T extends Context<infer Y>\n ? Y\n : never;\n\n/**\n * A function which creates a Context value object\n */\nexport function createContext<T>(\n name: string,\n initialValue?: T\n): Readonly<Context<T>> {\n return {\n name,\n initialValue,\n };\n}\n\n/**\n * A callback which is provided by a context requester and is called with the value satisfying the request.\n * This callback can be called multiple times by context providers as the requested value is changed.\n */\nexport type ContextCallback<ValueType> = (\n value: ValueType,\n dispose?: () => void\n) => void;\n\n/**\n * An event fired by a context requester to signal it desires a named context.\n *\n * A provider should inspect the `context` property of the event to determine if it has a value that can\n * satisfy the request, calling the `callback` with the requested value if so.\n *\n * If the requested context event contains a truthy `multiple` value, then a provider can call the callback\n * multiple times if the value is changed, if this is the case the provider should pass a `dispose`\n * method to the callback which requesters can invoke to indicate they no longer wish to receive these updates.\n */\nexport class ContextEvent<T extends UnknownContext> extends Event {\n public constructor(\n public readonly context: T,\n public readonly callback: ContextCallback<ContextType<T>>,\n public readonly multiple?: boolean\n ) {\n super('context-request', { bubbles: true, composed: true });\n }\n}\n\ndeclare global {\n interface HTMLElementEventMap {\n /**\n * A 'context-request' event can be emitted by any element which desires\n * a context value to be injected by an external provider.\n */\n 'context-request': ContextEvent<UnknownContext>;\n }\n}\n"],
|
|
5
|
-
"mappings": "AA4BO,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AA4BO,SAASA,EACdC,EACAC,EACsB,CACtB,MAAO,CACL,KAAAD,EACA,aAAAC,CACF,CACF,CAqBO,IAAMC,EAAN,cAAqD,KAAM,CACzD,YACWC,EACAC,EACAC,EAChB,CACA,MAAM,kBAAmB,CAAE,QAAS,GAAM,SAAU,EAAK,CAAC,EAJ1C,aAAAF,EACA,cAAAC,EACA,cAAAC,CAGlB,CACF",
|
|
6
|
+
"names": ["createContext", "name", "initialValue", "ContextEvent", "context", "callback", "multiple"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var h=(a,t,e,s)=>{for(var i=s>1?void 0:s?l(t,e):t,o=a.length-1,r;o>=0;o--)(r=a[o])&&(i=(s?r(t,e,i):r(i))||i);return s&&i&&p(t,e,i),i};import{bound as
|
|
1
|
+
var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var h=(a,t,e,s)=>{for(var i=s>1?void 0:s?l(t,e):t,o=a.length-1,r;o>=0;o--)(r=a[o])&&(i=(s?r(t,e,i):r(i))||i);return s&&i&&p(t,e,i),i};import{bound as f}from"../decorators/bound.js";import{debounce as d}from"../functions/debounce.js";import{Logger as g}from"./logger.js";var n=class{constructor(t,e){this.host=t;this.options=e;this.mo=new MutationObserver(this.parse);this.cache=new Map;this.class=t.constructor,this.logger=new g(this.host),n.instances.set(t,this);let s=this.options?.properties??{};for(let[i,o]of Object.entries(s))this.initProp(i,o);t.addController(this),this.cascadeProperties=d(this.cascadeProperties,1)}hostUpdated(){this.cascadeProperties()}hostConnected(){this.mo.observe(this.host,{attributes:!0,childList:!0}),this.cascadeProperties()}hostDisconnected(){this.mo.disconnect()}cascadeProperties(t=this.host.children){if(this.host.isConnected){let e=this.cache.keys();if(!t)return this._cascadeAttributes(e,this.cache);for(let s of t)if(s instanceof Element){for(let i of e)if(s.matches(i)){let o=this.cache.get(i);for(let r of o??[])this._copyAttribute(r,s)}}}}initProp(t,e){for(let s of[e].flat(1/0).filter(Boolean)){let{attribute:i}=this.class.getPropertyOptions(t),o=typeof i=="string"?i:t.toLowerCase();this.cache.get(s)?this.cache.get(s)?.push(o):this.cache.set(s,[o])}}parse(t){for(let e of t??[])e.type==="childList"&&e.addedNodes.length?this.cascadeProperties(e.addedNodes):e.type==="attributes"&&this._cascadeAttributes(this.cache.keys(),this.cache)}async _copyAttribute(t,e){this.logger.log(`copying ${t} to ${e}`);let s=this.host.getAttribute(t);e.isConnected&&(s==null?e.removeAttribute(t):e.setAttribute(t,s))}_cascadeAttributes(t,e){for(let s of t)for(let i of e.get(s)??[])this._cascadeAttribute(i,s)}_cascadeAttribute(t,e){let s=[...this.host.querySelectorAll(e),...this.host.shadowRoot?.querySelectorAll(e)??[]];for(let i of s)this._copyAttribute(t,i)}},c=n;c.instances=new WeakMap,h([f],c.prototype,"parse",1);export{c as CascadeController};
|
|
2
2
|
//# sourceMappingURL=cascade-controller.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["cascade-controller.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { bound } from '../decorators/bound.js';\nimport { debounce } from '../functions/debounce.js';\nimport { Logger } from './logger.js';\n\nexport interface Options<E extends ReactiveElement> {\n properties: Partial<Record<keyof E, string|string[]>>;\n prefix?: string;\n}\n\nexport class CascadeController<E extends ReactiveElement> implements ReactiveController {\n private class: typeof ReactiveElement;\n\n private logger: Logger;\n\n static instances: WeakMap<ReactiveElement, CascadeController<ReactiveElement>> = new WeakMap();\n\n mo = new MutationObserver(this.parse);\n\n cache = new Map<string, string[]>();\n\n constructor(public host: E, public options?: Options<E>) {\n this.class = host.constructor as typeof ReactiveElement;\n this.logger = new Logger(this.host);\n CascadeController.instances.set(host, this);\n const properties = this.options?.properties ?? {} as Options<E>['properties'];\n for (const [propName, cascade] of Object.entries(properties)) {\n this.initProp(propName, cascade);\n }\n host.addController(this);\n this.cascadeProperties = debounce(this.cascadeProperties, 1);\n }\n\n hostUpdated() {\n this.cascadeProperties();\n }\n\n hostConnected() {\n this.mo.observe(this.host, { attributes: true, childList: true });\n this.cascadeProperties();\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n /**\n * Handles the cascading of properties to nested components when new elements are added\n * Attribute updates/additions are handled by the attribute callback\n */\n cascadeProperties(nodeList: HTMLCollection|NodeList = this.host.children) {\n if (this.host.isConnected) {\n const selectors = this.cache.keys();\n\n // Find out if anything in the nodeList matches any of the observed selectors for cacading properties\n if (!nodeList) {\n return this._cascadeAttributes(selectors, this.cache);\n }\n\n\n for (const node of nodeList) {\n // if this node has a match function (i.e., it's an HTMLElement, not a text node),\n if (node instanceof Element) {\n // see if it matches one of the selectors, otherwise drop it (like it's hot).\n for (const selector of selectors) {\n // console.log('_copyAttribute', name, value, el.getAttribute(name));\n if (node.matches(selector)) {\n const attrNames = this.cache.get(selector);\n // each selector can match multiple properties/attributes, so\n // copy each of them\n for (const attrName of attrNames ?? []) {\n this._copyAttribute(attrName, node);\n }\n }\n }\n }\n }\n }\n }\n\n /**\n * Gets the configured attribute name for the decorated property,\n * falling back to the lowercased property name, and caches the attribute name\n * with it's designated child selectors for value-propagation on change\n */\n initProp(propName: string, cascade: string|string[]) {\n for (const nodeItem of [cascade].flat(Infinity).filter(Boolean) as string[]) {\n const { attribute } = this.class.getPropertyOptions(propName);\n\n const attr =\n typeof attribute === 'string' ? attribute\n : propName.toLowerCase();\n\n // Create an object with the node as the key and an array of attributes\n // that are to be cascaded down to it\n if (!this.cache.get(nodeItem)) {\n this.cache.set(nodeItem, [attr]);\n } else {\n this.cache.get(nodeItem)?.push(attr);\n }\n }\n }\n\n @bound private parse(mutations: MutationRecord[]) {\n // Iterate over the mutation list, look for cascade updates\n for (const mutation of mutations ?? []) {\n // If a new node is added, attempt to cascade attributes to it\n if (mutation.type === 'childList' && mutation.addedNodes.length) {\n this.cascadeProperties(mutation.addedNodes);\n } else if (mutation.type === 'attributes') {\n this._cascadeAttributes(this.cache.keys(), this.cache);\n }\n }\n }\n\n /**\n * Copy the named attribute to a target element.\n */\n private async _copyAttribute(name: string, el: Element) {\n this.logger.log(`copying ${name} to ${el}`);\n const value = this.host.getAttribute(name);\n if (el.isConnected) {\n if (value == null) {\n el.removeAttribute(name);\n } else {\n el.setAttribute(name, value);\n }\n }\n }\n\n private _cascadeAttributes(selectors: IterableIterator<string>, set: this['cache']) {\n for (const selector of selectors) {\n for (const attr of set.get(selector) ?? []) {\n this._cascadeAttribute(attr, selector);\n }\n }\n }\n\n /**\n * Trigger a cascade of the named attribute to any child elements that match\n * the `to` selector. The selector can match elements in the light DOM and\n * shadow DOM.\n * @param name The name of the attribute to cascade (not necessarily the same as the property name).\n * @param to A CSS selector that matches the elements that should received the cascaded attribute. The selector will be applied within `this` element's light and shadow DOM trees.\n */\n private _cascadeAttribute(name: string, to: string) {\n const recipients = [\n ...this.host.querySelectorAll(to),\n ...this.host.shadowRoot?.querySelectorAll(to) ?? [],\n ];\n\n for (const node of recipients) {\n this._copyAttribute(name, node);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "wMAEA
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["bound", "debounce", "Logger", "_CascadeController", "host", "options", "Logger", "properties", "propName", "cascade", "debounce", "nodeList", "selectors", "node", "selector", "attrNames", "attrName", "nodeItem", "attribute", "attr", "mutations", "mutation", "name", "el", "value", "set", "to", "recipients", "CascadeController", "__decorateClass", "bound"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { ReactiveController } from 'lit';
|
|
2
|
+
import type { Context } from '../context.js';
|
|
3
|
+
import { ReactiveElement } from 'lit';
|
|
4
|
+
import { Logger } from './logger.js';
|
|
5
|
+
import { StyleController } from './style-controller.js';
|
|
6
|
+
/**
|
|
7
|
+
* A `ColorPalette` is a collection of specific color values
|
|
8
|
+
* Choosing a palette sets both color properties and, if the component is a context provider,
|
|
9
|
+
* implies a color theme for descendents.
|
|
10
|
+
*
|
|
11
|
+
* `ColorPalette` is associated with the `color-palette` attribute
|
|
12
|
+
*/
|
|
13
|
+
export declare type ColorPalette = ('base' | 'accent' | 'complement' | 'lighter' | 'lightest' | 'darker' | 'darkest');
|
|
14
|
+
/**
|
|
15
|
+
* A Color theme is a context-specific restriction on the available color palettes
|
|
16
|
+
*
|
|
17
|
+
* `ColorTheme` is associated with the `on` attribute and the `--context` css property
|
|
18
|
+
*/
|
|
19
|
+
export declare type ColorTheme = ('dark' | 'light' | 'saturated');
|
|
20
|
+
export interface ColorContextOptions {
|
|
21
|
+
prefix?: string;
|
|
22
|
+
attribute?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Color context is derived from the `--context` css custom property,
|
|
26
|
+
* which can be set by the `on` attribute, but *must* be set by the `color-palette` attribute
|
|
27
|
+
* This property is set (in most cases) in `color-context.scss`,
|
|
28
|
+
* which is added to components via `StyleController`.
|
|
29
|
+
*
|
|
30
|
+
* In this way, we avoid the need to execute javascript in order to convert from a given
|
|
31
|
+
* `ColorPalette` to a given `ColorTheme`, since those relationships are specified in CSS.
|
|
32
|
+
*/
|
|
33
|
+
declare abstract class ColorContextController implements ReactiveController {
|
|
34
|
+
protected host: ReactiveElement;
|
|
35
|
+
abstract update(next: ColorTheme | null): void;
|
|
36
|
+
protected abstract attribute: string;
|
|
37
|
+
/** The context object which describes the host's colour context */
|
|
38
|
+
protected context: Context<ColorTheme | null>;
|
|
39
|
+
/** The style controller which provides the necessary CSS. */
|
|
40
|
+
protected styleController: StyleController;
|
|
41
|
+
/** Prefix for colour context. Set this in Options to create a separate context */
|
|
42
|
+
protected prefix: string;
|
|
43
|
+
/** The last-known color context on the host */
|
|
44
|
+
protected last: ColorTheme | null;
|
|
45
|
+
protected logger: Logger;
|
|
46
|
+
hostUpdate?(): void;
|
|
47
|
+
constructor(host: ReactiveElement, options?: ColorContextOptions);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `ColorContextProvider` is responsible to derive a context value from CSS and provide it to its
|
|
51
|
+
* descendents.
|
|
52
|
+
*/
|
|
53
|
+
export declare class ColorContextProvider extends ColorContextController implements ReactiveController {
|
|
54
|
+
protected attribute: string;
|
|
55
|
+
/** Cache of context callbacks. Call each to update consumers */
|
|
56
|
+
private callbacks;
|
|
57
|
+
/** Mutation observer which updates consumers when `on` or `color-palette` attributes change. */
|
|
58
|
+
private mo;
|
|
59
|
+
/**
|
|
60
|
+
* Cached (live) computed style declaration
|
|
61
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
|
|
62
|
+
*/
|
|
63
|
+
protected style: CSSStyleDeclaration;
|
|
64
|
+
/** Return the current CSS `--context` value, or null */
|
|
65
|
+
protected get contextVariable(): ColorTheme | null;
|
|
66
|
+
constructor(host: ReactiveElement, options?: ColorContextOptions);
|
|
67
|
+
/**
|
|
68
|
+
* When a context provider connects, it listens for context-request events
|
|
69
|
+
* it also fires all previously fired context-request events from their hosts,
|
|
70
|
+
* in case this context provider upgraded after and is closer to a given consumer.
|
|
71
|
+
*/
|
|
72
|
+
hostConnected(): void;
|
|
73
|
+
/**
|
|
74
|
+
* When a context provider disconnects, it disconnects its mutation observer
|
|
75
|
+
*/
|
|
76
|
+
hostDisconnected(): void;
|
|
77
|
+
/** Was the context event fired requesting our colour-context context? */
|
|
78
|
+
private isColorContextEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Provider part of context API
|
|
81
|
+
* When a child connects, claim its context-request event
|
|
82
|
+
* and add its callback to the Set of children if it requests multiple updates
|
|
83
|
+
*/
|
|
84
|
+
private onChildContextEvent;
|
|
85
|
+
/** Sets the `on` attribute on the host and any children that requested multiple updates */
|
|
86
|
+
update(next: ColorTheme | null): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A color context consumer receives sets it's `on` attribute based on the context provided
|
|
90
|
+
* by the closes color context provider.
|
|
91
|
+
* The consumer has no direct access to the context, it must receive it from the provider.
|
|
92
|
+
*/
|
|
93
|
+
export declare class ColorContextConsumer extends ColorContextController implements ReactiveController {
|
|
94
|
+
protected attribute: string;
|
|
95
|
+
private dispose?;
|
|
96
|
+
private override;
|
|
97
|
+
constructor(host: ReactiveElement, options?: ColorContextOptions);
|
|
98
|
+
/**
|
|
99
|
+
* When a color context consumer connects,
|
|
100
|
+
* it requests colour context from the closest context provider,
|
|
101
|
+
* then updates it's host's `on` attribute
|
|
102
|
+
*/
|
|
103
|
+
hostConnected(): void;
|
|
104
|
+
/**
|
|
105
|
+
* When a color context consumer disconnects,
|
|
106
|
+
* it removes itself from the collection of components which request color context
|
|
107
|
+
* then updates it's host's `on` attribute
|
|
108
|
+
*/
|
|
109
|
+
hostDisconnected(): void;
|
|
110
|
+
/** Register the dispose callback for hosts that requested multiple updates, then update the colour-context */
|
|
111
|
+
private contextCallback;
|
|
112
|
+
/** Sets the `on` attribute on the host and any children that requested multiple updates */
|
|
113
|
+
update(next: ColorTheme | null): void;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var i=(a,o,e,t)=>{for(var r=t>1?void 0:t?m(o,e):o,d=a.length-1,p;d>=0;d--)(p=a[d])&&(r=(t?p(o,e,r):p(r))||r);return t&&r&&u(o,e,r),r};import"lit";import{ContextEvent as b,createContext as x}from"../context.js";import{bound as s}from"../decorators/bound.js";import{Logger as C}from"./logger.js";import{StyleController as g}from"./style-controller.js";import{css as v}from"lit";var k=v`:host(:is([on=dark])){--context:dark}:host(:is([on=light])){--context:light}:host(:is([on=saturated])){--context:saturated}:host(:is([color-palette=darker],[color-palette=darkest])){--context:dark;--pfe-broadcasted--text:var(--pfe-theme--color--text--on-dark, #fff);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted--on-dark, #d2d2d2);--pfe-broadcasted--link:var(--pfe-theme--color--link--on-dark, #73bcf7);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover--on-dark, #bee1f4);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus--on-dark, #bee1f4);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited--on-dark, #bee1f4);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration--on-dark, none);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover--on-dark, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus--on-dark, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited--on-dark, none)}:host(:is([color-palette=lighter],[color-palette=lightest],[color-palette=base])){--context:light;--pfe-broadcasted--text:var(--pfe-theme--color--text, #151515);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted, #6a6e73);--pfe-broadcasted--link:var(--pfe-theme--color--link, #06c);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover, #004080);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus, #004080);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited, #6753ac);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration, none);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited, none)}:host(:is([color-palette=accent],[color-palette=complement],[color-palette=saturated])){--context:saturated;--pfe-broadcasted--text:var(--pfe-theme--color--text--on-saturated, #fff);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted--on-saturated, #d2d2d2);--pfe-broadcasted--link:var(--pfe-theme--color--link--on-saturated, #fff);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover--on-saturated, #fafafa);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus--on-saturated, #fafafa);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited--on-saturated, #d2d2d2);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration--on-saturated, underline);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover--on-saturated, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus--on-saturated, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited--on-saturated, underline)}:host(:is([color-palette=lightest])){--pfe-context-background-color:var(--pfe-theme--color--surface--lightest, #fff)}:host(:is([color-palette=lighter])){--pfe-context-background-color:var(--pfe-theme--color--surface--lighter, #ededed)}:host(:is([color-palette=base])){--pfe-context-background-color:var(--pfe-theme--color--surface--base, #ededed)}:host(:is([color-palette=darker])){--pfe-context-background-color:var(--pfe-theme--color--surface--darker, #393f44)}:host(:is([color-palette=darkest])){--pfe-context-background-color:var(--pfe-theme--color--surface--darkest, #292e34)}:host(:is([color-palette=complement])){--pfe-context-background-color:var(--pfe-theme--color--surface--complement, #004368)}:host(:is([color-palette=accent])){--pfe-context-background-color:var(--pfe-theme--color--surface--accent, #00659c)}:host(:is([color-palette])){background-color:var(--pfe-context-background-color,var(--pfe-theme--color--surface--base))}`,f=k;var h=new Map,c=class{constructor(o,e){this.host=o;this.prefix="pfe-";this.last=null;this.prefix=e?.prefix??"pfe-",this.context=x(`${this.prefix}-color-context`),this.logger=new C(o),this.styleController=new g(o,f),o.addController(this)}},n=class extends c{constructor(e,t){super(e,t);this.callbacks=new Set;this.mo=new MutationObserver(()=>this.update(this.contextVariable));this.style=window.getComputedStyle(e),this.attribute=t?.attribute??"color-palette"}get contextVariable(){return this.style.getPropertyValue("--context").trim()||null}hostConnected(){this.host.addEventListener("context-request",this.onChildContextEvent),this.mo.observe(this.host,{attributes:!0,attributeFilter:[this.attribute,"on"]}),this.update(this.contextVariable);for(let[e,t]of h)e.dispatchEvent(t)}hostDisconnected(){this.callbacks.forEach(e=>this.callbacks.delete(e)),this.mo.disconnect()}isColorContextEvent(e){return e.target!==this.host&&e.context.name===`${this.prefix}-color-context`}onChildContextEvent(e){this.isColorContextEvent(e)&&(e.stopPropagation(),e.callback(this.contextVariable),e.multiple&&this.callbacks.add(e.callback))}update(e){for(let t of this.callbacks)t(e)}};i([s],n.prototype,"onChildContextEvent",1),i([s],n.prototype,"update",1);var l=class extends c{constructor(e,t){super(e,t);this.override=null;this.attribute??(this.attribute="on")}hostConnected(){let e=new b(this.context,this.contextCallback,!0);this.override=this.host.getAttribute(this.attribute),this.host.dispatchEvent(e),h.set(this.host,e)}hostDisconnected(){this.dispose?.(),this.dispose=void 0,h.delete(this.host)}contextCallback(e,t){t&&t!==this.dispose&&(this.dispose?.(),this.dispose=t),this.update(e)}update(e){!this.override&&e!==this.last&&(this.last=e,this.logger.log(`setting context from ${this.host.getAttribute(this.attribute)} to ${e}`),e==null?this.host.removeAttribute(this.attribute):this.host.setAttribute(this.attribute,e))}};i([s],l.prototype,"contextCallback",1),i([s],l.prototype,"update",1);export{l as ColorContextConsumer,n as ColorContextProvider};
|
|
2
|
+
//# sourceMappingURL=color-context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["color-context.ts", "color-context.scss"],
|
|
4
|
+
"sourcesContent": ["import type { ReactiveController } from 'lit';\nimport type { Context, ContextCallback, UnknownContext } from '../context.js';\n\nimport { ReactiveElement } from 'lit';\nimport { ContextEvent, createContext } from '../context.js';\nimport { bound } from '../decorators/bound.js';\nimport { Logger } from './logger.js';\nimport { StyleController } from './style-controller.js';\n\nimport CONTEXT_BASE_STYLES from './color-context.scss';\n\n/**\n * A `ColorPalette` is a collection of specific color values\n * Choosing a palette sets both color properties and, if the component is a context provider,\n * implies a color theme for descendents.\n *\n * `ColorPalette` is associated with the `color-palette` attribute\n */\nexport type ColorPalette = (\n | 'base'\n | 'accent'\n | 'complement'\n | 'lighter'\n | 'lightest'\n | 'darker'\n | 'darkest'\n);\n\n/**\n * A Color theme is a context-specific restriction on the available color palettes\n *\n * `ColorTheme` is associated with the `on` attribute and the `--context` css property\n */\nexport type ColorTheme = (\n | 'dark'\n | 'light'\n | 'saturated'\n);\n\nexport interface ColorContextOptions {\n prefix?: string;\n attribute?: string;\n}\n\n/**\n* Maps from consumer host elements to already-fired request events\n* We hold these in memory in order to re-fire the events every time a new provider connects.\n* This is a hedge against cases where an early-upgrading provider claims an early-upgrading\n* consumer before a late-upgrading provider has a chance to register as the rightful provider\n* @example Monkey-in-the-middle error\n* In this example, we must re-fire the event from eager-consumer when late-provider\n* upgrades, so as to ensure that late-provider claims it for itself\n* ```html\n* <early-provider>\n* <late-provider>\n* <eager-consumer>\n* </late-provider>\n* </early-provider>\n* ```\n*/\nconst contextEvents = new Map<ReactiveElement, ContextEvent<UnknownContext>>();\n\n/**\n * Color context is derived from the `--context` css custom property,\n * which can be set by the `on` attribute, but *must* be set by the `color-palette` attribute\n * This property is set (in most cases) in `color-context.scss`,\n * which is added to components via `StyleController`.\n *\n * In this way, we avoid the need to execute javascript in order to convert from a given\n * `ColorPalette` to a given `ColorTheme`, since those relationships are specified in CSS.\n */\nabstract class ColorContextController implements ReactiveController {\n abstract update(next: ColorTheme | null): void;\n\n protected abstract attribute: string;\n\n /** The context object which describes the host's colour context */\n protected context: Context<ColorTheme|null>;\n\n /** The style controller which provides the necessary CSS. */\n protected styleController: StyleController;\n\n /** Prefix for colour context. Set this in Options to create a separate context */\n protected prefix = 'pfe-';\n\n /** The last-known color context on the host */\n protected last: ColorTheme|null = null;\n\n protected logger: Logger;\n\n hostUpdate?(): void\n\n constructor(protected host: ReactiveElement, options?: ColorContextOptions) {\n this.prefix = options?.prefix ?? 'pfe-';\n this.context = createContext(`${this.prefix}-color-context`);\n this.logger = new Logger(host);\n this.styleController = new StyleController(host, CONTEXT_BASE_STYLES);\n host.addController(this as ReactiveController);\n }\n}\n\n/**\n * `ColorContextProvider` is responsible to derive a context value from CSS and provide it to its\n * descendents.\n */\nexport class ColorContextProvider extends ColorContextController implements ReactiveController {\n protected attribute: string;\n\n /** Cache of context callbacks. Call each to update consumers */\n private callbacks = new Set<ContextCallback<ColorTheme|null>>();\n\n /** Mutation observer which updates consumers when `on` or `color-palette` attributes change. */\n private mo = new MutationObserver(() => this.update(this.contextVariable));\n\n /**\n * Cached (live) computed style declaration\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle\n */\n protected style: CSSStyleDeclaration;\n\n /** Return the current CSS `--context` value, or null */\n protected get contextVariable(): ColorTheme | null {\n return this.style.getPropertyValue('--context').trim() as ColorTheme || null;\n }\n\n constructor(host: ReactiveElement, options?: ColorContextOptions) {\n super(host, options);\n this.style = window.getComputedStyle(host);\n this.attribute = options?.attribute ?? 'color-palette';\n }\n\n /**\n * When a context provider connects, it listens for context-request events\n * it also fires all previously fired context-request events from their hosts,\n * in case this context provider upgraded after and is closer to a given consumer.\n */\n hostConnected() {\n this.host.addEventListener('context-request', this.onChildContextEvent);\n this.mo.observe(this.host, { attributes: true, attributeFilter: [this.attribute, 'on'] });\n this.update(this.contextVariable);\n for (const [host, fired] of contextEvents) {\n host.dispatchEvent(fired);\n }\n }\n\n /**\n * When a context provider disconnects, it disconnects its mutation observer\n */\n hostDisconnected() {\n this.callbacks.forEach(x => this.callbacks.delete(x));\n this.mo.disconnect();\n }\n\n /** Was the context event fired requesting our colour-context context? */\n private isColorContextEvent(\n event: ContextEvent<UnknownContext>\n ): event is ContextEvent<Context<ColorTheme|null>> {\n return (\n event.target !== this.host &&\n event.context.name === `${this.prefix}-color-context`\n );\n }\n\n /**\n * Provider part of context API\n * When a child connects, claim its context-request event\n * and add its callback to the Set of children if it requests multiple updates\n */\n @bound private onChildContextEvent(event: ContextEvent<UnknownContext>) {\n // only handle ContextEvents relevant to colour context\n if (this.isColorContextEvent(event)) {\n // claim the context-request event for ourselves (required by context protocol)\n event.stopPropagation();\n\n // Run the callback to initialize the child's colour-context\n event.callback(this.contextVariable);\n\n // Cache the callback for future updates, if requested\n if (event.multiple) {\n this.callbacks.add(event.callback);\n }\n }\n }\n\n /** Sets the `on` attribute on the host and any children that requested multiple updates */\n @bound public update(next: ColorTheme | null) {\n for (const cb of this.callbacks) {\n cb(next);\n }\n }\n}\n\n/**\n * A color context consumer receives sets it's `on` attribute based on the context provided\n * by the closes color context provider.\n * The consumer has no direct access to the context, it must receive it from the provider.\n */\nexport class ColorContextConsumer extends ColorContextController implements ReactiveController {\n protected attribute: string;\n\n private dispose?: () => void;\n\n private override: ColorTheme | null = null;\n\n constructor(host: ReactiveElement, options?: ColorContextOptions) {\n super(host, options);\n this.attribute ??= 'on';\n }\n\n /**\n * When a color context consumer connects,\n * it requests colour context from the closest context provider,\n * then updates it's host's `on` attribute\n */\n hostConnected() {\n const event = new ContextEvent(this.context, this.contextCallback, true);\n this.override = this.host.getAttribute(this.attribute) as ColorTheme;\n this.host.dispatchEvent(event);\n contextEvents.set(this.host, event);\n }\n\n /**\n * When a color context consumer disconnects,\n * it removes itself from the collection of components which request color context\n * then updates it's host's `on` attribute\n */\n hostDisconnected() {\n this.dispose?.();\n this.dispose = undefined;\n contextEvents.delete(this.host);\n }\n\n /** Register the dispose callback for hosts that requested multiple updates, then update the colour-context */\n @bound private contextCallback(value: ColorTheme|null, dispose?: () => void) {\n // protect against changing providers\n if (dispose && dispose !== this.dispose) {\n this.dispose?.();\n this.dispose = dispose;\n }\n this.update(value);\n }\n\n /** Sets the `on` attribute on the host and any children that requested multiple updates */\n @bound public update(next: ColorTheme|null) {\n if (!this.override && next !== this.last) {\n this.last = next;\n this.logger.log(`setting context from ${this.host.getAttribute(this.attribute)} to ${next}`);\n if (next == null) {\n this.host.removeAttribute(this.attribute);\n } else {\n this.host.setAttribute(this.attribute, next);\n }\n }\n }\n}\n\n", "import {css} from 'lit';\nexport const styles = css`:host(:is([on=dark])){--context:dark}:host(:is([on=light])){--context:light}:host(:is([on=saturated])){--context:saturated}:host(:is([color-palette=darker],[color-palette=darkest])){--context:dark;--pfe-broadcasted--text:var(--pfe-theme--color--text--on-dark, #fff);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted--on-dark, #d2d2d2);--pfe-broadcasted--link:var(--pfe-theme--color--link--on-dark, #73bcf7);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover--on-dark, #bee1f4);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus--on-dark, #bee1f4);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited--on-dark, #bee1f4);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration--on-dark, none);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover--on-dark, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus--on-dark, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited--on-dark, none)}:host(:is([color-palette=lighter],[color-palette=lightest],[color-palette=base])){--context:light;--pfe-broadcasted--text:var(--pfe-theme--color--text, #151515);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted, #6a6e73);--pfe-broadcasted--link:var(--pfe-theme--color--link, #06c);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover, #004080);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus, #004080);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited, #6753ac);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration, none);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited, none)}:host(:is([color-palette=accent],[color-palette=complement],[color-palette=saturated])){--context:saturated;--pfe-broadcasted--text:var(--pfe-theme--color--text--on-saturated, #fff);--pfe-broadcasted--text--muted:var(--pfe-theme--color--text--muted--on-saturated, #d2d2d2);--pfe-broadcasted--link:var(--pfe-theme--color--link--on-saturated, #fff);--pfe-broadcasted--link--hover:var(--pfe-theme--color--link--hover--on-saturated, #fafafa);--pfe-broadcasted--link--focus:var(--pfe-theme--color--link--focus--on-saturated, #fafafa);--pfe-broadcasted--link--visited:var(--pfe-theme--color--link--visited--on-saturated, #d2d2d2);--pfe-broadcasted--link-decoration:var(--pfe-theme--link-decoration--on-saturated, underline);--pfe-broadcasted--link-decoration--hover:var(--pfe-theme--link-decoration--hover--on-saturated, underline);--pfe-broadcasted--link-decoration--focus:var(--pfe-theme--link-decoration--focus--on-saturated, underline);--pfe-broadcasted--link-decoration--visited:var(--pfe-theme--link-decoration--visited--on-saturated, underline)}:host(:is([color-palette=lightest])){--pfe-context-background-color:var(--pfe-theme--color--surface--lightest, #fff)}:host(:is([color-palette=lighter])){--pfe-context-background-color:var(--pfe-theme--color--surface--lighter, #ededed)}:host(:is([color-palette=base])){--pfe-context-background-color:var(--pfe-theme--color--surface--base, #ededed)}:host(:is([color-palette=darker])){--pfe-context-background-color:var(--pfe-theme--color--surface--darker, #393f44)}:host(:is([color-palette=darkest])){--pfe-context-background-color:var(--pfe-theme--color--surface--darkest, #292e34)}:host(:is([color-palette=complement])){--pfe-context-background-color:var(--pfe-theme--color--surface--complement, #004368)}:host(:is([color-palette=accent])){--pfe-context-background-color:var(--pfe-theme--color--surface--accent, #00659c)}:host(:is([color-palette])){background-color:var(--pfe-context-background-color,var(--pfe-theme--color--surface--base))}`;\nexport default styles;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["ContextEvent", "createContext", "bound", "Logger", "StyleController", "css", "styles", "color_context_default", "contextEvents", "ColorContextController", "host", "options", "createContext", "Logger", "StyleController", "color_context_default", "ColorContextProvider", "fired", "x", "event", "next", "cb", "__decorateClass", "bound", "ColorContextConsumer", "ContextEvent", "value", "dispose"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
:host([
|
|
2
|
-
:host([
|
|
3
|
-
:host([
|
|
4
|
-
:host([context=saturated]) { --context: saturated; }
|
|
1
|
+
:host(:is([on=dark])) { --context: dark; }
|
|
2
|
+
:host(:is([on=light])) { --context: light; }
|
|
3
|
+
:host(:is([on=saturated])) { --context: saturated; }
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* It's important for `color-palette` to take precedence over `on`
|
|
7
|
+
* when setting `--context`, because a `dark` card that's on a `light`
|
|
8
|
+
* background must create a new `dark` context for its descendents
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
:host(:is([color-palette=darker],[color-palette=darkest])) {
|
|
12
|
+
--context: dark;
|
|
7
13
|
--pfe-broadcasted--text: var(--pfe-theme--color--text--on-dark, #fff);
|
|
8
14
|
--pfe-broadcasted--text--muted: var(--pfe-theme--color--text--muted--on-dark, #d2d2d2);
|
|
9
15
|
--pfe-broadcasted--link: var(--pfe-theme--color--link--on-dark, #73bcf7);
|
|
@@ -16,7 +22,22 @@
|
|
|
16
22
|
--pfe-broadcasted--link-decoration--visited: var(--pfe-theme--link-decoration--visited--on-dark, none);
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
:host([
|
|
25
|
+
:host(:is([color-palette=lighter],[color-palette=lightest],[color-palette=base])) {
|
|
26
|
+
--context: light;
|
|
27
|
+
--pfe-broadcasted--text: var(--pfe-theme--color--text, #151515);
|
|
28
|
+
--pfe-broadcasted--text--muted: var(--pfe-theme--color--text--muted, #6a6e73);
|
|
29
|
+
--pfe-broadcasted--link: var(--pfe-theme--color--link, #06c);
|
|
30
|
+
--pfe-broadcasted--link--hover: var(--pfe-theme--color--link--hover, #004080);
|
|
31
|
+
--pfe-broadcasted--link--focus: var(--pfe-theme--color--link--focus, #004080);
|
|
32
|
+
--pfe-broadcasted--link--visited: var(--pfe-theme--color--link--visited, #6753ac);
|
|
33
|
+
--pfe-broadcasted--link-decoration: var(--pfe-theme--link-decoration, none);
|
|
34
|
+
--pfe-broadcasted--link-decoration--hover: var(--pfe-theme--link-decoration--hover, underline);
|
|
35
|
+
--pfe-broadcasted--link-decoration--focus: var(--pfe-theme--link-decoration--focus, underline);
|
|
36
|
+
--pfe-broadcasted--link-decoration--visited: var(--pfe-theme--link-decoration--visited, none);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:host(:is([color-palette=accent],[color-palette=complement],[color-palette=saturated])) {
|
|
40
|
+
--context: saturated;
|
|
20
41
|
--pfe-broadcasted--text: var(--pfe-theme--color--text--on-saturated, #fff);
|
|
21
42
|
--pfe-broadcasted--text--muted: var(--pfe-theme--color--text--muted--on-saturated, #d2d2d2);
|
|
22
43
|
--pfe-broadcasted--link: var(--pfe-theme--color--link--on-saturated, #fff);
|
|
@@ -29,15 +50,35 @@
|
|
|
29
50
|
--pfe-broadcasted--link-decoration--visited: var(--pfe-theme--link-decoration--visited--on-saturated, underline);
|
|
30
51
|
}
|
|
31
52
|
|
|
32
|
-
:host([
|
|
33
|
-
--pfe-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
--pfe-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
--pfe-
|
|
42
|
-
|
|
53
|
+
:host(:is([color-palette="lightest"])) {
|
|
54
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--lightest, #fff);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host(:is([color-palette="lighter"])) {
|
|
58
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--lighter, #ededed);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:host(:is([color-palette="base"])) {
|
|
62
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--base, #ededed);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:host(:is([color-palette="darker"])) {
|
|
66
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--darker, #393f44);
|
|
43
67
|
}
|
|
68
|
+
|
|
69
|
+
:host(:is([color-palette="darkest"])) {
|
|
70
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--darkest, #292e34);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
:host(:is([color-palette="complement"])) {
|
|
74
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--complement, #004368);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
:host(:is([color-palette="accent"])) {
|
|
78
|
+
--pfe-context-background-color: var(--pfe-theme--color--surface--accent, #00659c);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
:host(:is([color-palette])) {
|
|
82
|
+
background-color: var(--pfe-context-background-color, var(--pfe-theme--color--surface--base));
|
|
83
|
+
}
|
|
84
|
+
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["css-variable-controller.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ReactiveElement, ReactiveController } from 'lit';\n\nexport class CssVariableController implements ReactiveController {\n style: CSSStyleDeclaration;\n\n constructor(public host: ReactiveElement) {\n this.style = window.getComputedStyle(host);\n }\n\n private parseProperty(name: string) {\n return name.substr(0, 2) !== '--' ? `--${name}` : name;\n }\n\n getVariable(name: string) {\n return this.style.getPropertyValue(this.parseProperty(name)).trim() || null;\n }\n\n hostConnected?(): void\n}\n"],
|
|
5
|
-
"mappings": "AAEO,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAEO,IAAMA,EAAN,KAA0D,CAG/D,YAAmBC,EAAuB,CAAvB,UAAAA,EACjB,KAAK,MAAQ,OAAO,iBAAiBA,CAAI,CAC3C,CAEQ,cAAcC,EAAc,CAClC,OAAOA,EAAK,OAAO,EAAG,CAAC,IAAM,KAAO,KAAKA,IAASA,CACpD,CAEA,YAAYA,EAAc,CACxB,OAAO,KAAK,MAAM,iBAAiB,KAAK,cAAcA,CAAI,CAAC,EAAE,KAAK,GAAK,IACzE,CAGF",
|
|
6
|
+
"names": ["CssVariableController", "host", "name"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
|
+
declare type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
3
|
+
declare type Alignment = 'start' | 'end';
|
|
4
|
+
/**
|
|
5
|
+
* Represents the placement of floating DOM
|
|
6
|
+
*/
|
|
7
|
+
export declare type Placement = Direction | `${Direction}-${Alignment}`;
|
|
8
|
+
/**
|
|
9
|
+
* Controls floating DOM within a web component, e.g. tooltips and popovers
|
|
10
|
+
*/
|
|
11
|
+
export declare class FloatingDOMController implements ReactiveController {
|
|
12
|
+
#private;
|
|
13
|
+
private host;
|
|
14
|
+
get initialized(): boolean;
|
|
15
|
+
set initialized(v: boolean);
|
|
16
|
+
/**
|
|
17
|
+
* When true, the floating DOM is visible
|
|
18
|
+
*/
|
|
19
|
+
get open(): boolean;
|
|
20
|
+
set open(value: boolean);
|
|
21
|
+
constructor(host: ReactiveElement);
|
|
22
|
+
hostConnected?(): void;
|
|
23
|
+
/** Show the floating DOM */
|
|
24
|
+
show(): void;
|
|
25
|
+
/** Hide the floating DOM */
|
|
26
|
+
hide(): void;
|
|
27
|
+
/** Initialize the floating DOM */
|
|
28
|
+
create(invoker: Element, content: HTMLElement, placement: Placement, offset?: number[]): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=(t,e,i)=>{if(!e.has(t))throw TypeError("Cannot "+i)};var o=(t,e,i)=>(f(t,e,"read from private field"),i?i.call(t):e.get(t)),l=(t,e,i)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,i)},a=(t,e,i,p)=>(f(t,e,"write to private field"),p?p.call(t,i):e.set(t,i),i);import{applyStyles as c,arrow as h,computeStyles as u,eventListeners as v,flip as y,hide as b,offset as g,popperGenerator as z,popperOffsets as E,preventOverflow as P}from"@popperjs/core";var R=z({defaultModifiers:[v,E,u,c,g,y,P,h,b]}),n,r,s,m=class{constructor(e){this.host=e;l(this,n,!1);l(this,r,void 0);l(this,s,!1);e.addController(this)}get initialized(){return o(this,s)}set initialized(e){a(this,s,e),this.host.requestUpdate()}get open(){return o(this,n)}set open(e){a(this,n,e),e&&o(this,r)?.update(),this.host.requestUpdate()}show(){this.open=!0}hide(){this.open=!1}create(e,i,p,d){e&&i&&(o(this,r)??a(this,r,R(e,i,{placement:p,modifiers:[{name:"offset",options:{offset:d}},{name:"flip",options:{fallbackPlacements:["top","right","left","bottom"]}}]})),this.initialized||(this.initialized=!0))}};n=new WeakMap,r=new WeakMap,s=new WeakMap;export{m as FloatingDOMController};
|
|
2
|
+
//# sourceMappingURL=floating-dom-controller.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["floating-dom-controller.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Instance } from '@popperjs/core';\nimport type { ReactiveController, ReactiveElement } from 'lit';\n\nimport {\n applyStyles,\n arrow,\n computeStyles,\n eventListeners,\n flip,\n hide,\n offset,\n popperGenerator,\n popperOffsets,\n preventOverflow,\n} from '@popperjs/core';\n\ntype Direction =\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n\ntype Alignment =\n | 'start'\n | 'end'\n\n/**\n * Represents the placement of floating DOM\n */\nexport type Placement = Direction | `${Direction}-${Alignment}`;\n\nconst createPopper = popperGenerator({\n defaultModifiers: [\n eventListeners,\n popperOffsets,\n computeStyles,\n applyStyles,\n offset,\n flip,\n preventOverflow,\n arrow,\n hide\n ],\n});\n\n/**\n * Controls floating DOM within a web component, e.g. tooltips and popovers\n */\nexport class FloatingDOMController implements ReactiveController {\n #open = false;\n\n #popper: Instance | undefined;\n\n #initialized = false;\n\n get initialized() {\n return this.#initialized;\n }\n\n set initialized(v: boolean) {\n this.#initialized = v; this.host.requestUpdate();\n }\n\n /**\n * When true, the floating DOM is visible\n */\n get open() {\n return this.#open;\n }\n\n set open(value: boolean) {\n this.#open = value;\n if (value) {\n this.#popper?.update();\n }\n this.host.requestUpdate();\n }\n\n constructor(private host: ReactiveElement) {\n host.addController(this);\n }\n\n hostConnected?(): void;\n\n /** Show the floating DOM */\n show(): void {\n this.open = true;\n }\n\n /** Hide the floating DOM */\n hide(): void {\n this.open = false;\n }\n\n /** Initialize the floating DOM */\n create(invoker: Element, content: HTMLElement, placement: Placement, offset?: number[]): void {\n if (invoker && content) {\n this.#popper ??= createPopper(invoker, content, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset\n }\n },\n {\n name: 'flip',\n options: {\n fallbackPlacements: ['top', 'right', 'left', 'bottom'],\n },\n }\n ]\n });\n this.initialized ||= true;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "mVAGA,OACE,eAAAA,EACA,SAAAC,EACA,iBAAAC,EACA,kBAAAC,EACA,QAAAC,EACA,QAAAC,EACA,UAAAC,EACA,mBAAAC,EACA,iBAAAC,EACA,mBAAAC,MACK,iBAiBP,IAAMC,EAAeC,EAAgB,CACnC,iBAAkB,CAChBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,CACF,CACF,CAAC,EA3CDC,EAAAC,EAAAC,EAgDaC,EAAN,KAA0D,CA8B/D,YAAoBC,EAAuB,CAAvB,UAAAA,EA7BpBC,EAAA,KAAAL,EAAQ,IAERK,EAAA,KAAAJ,EAAA,QAEAI,EAAA,KAAAH,EAAe,IA0BbE,EAAK,cAAc,IAAI,CACzB,CAzBA,IAAI,aAAc,CAChB,OAAOE,EAAA,KAAKJ,EACd,CAEA,IAAI,YAAYK,EAAY,CAC1BC,EAAA,KAAKN,EAAeK,GAAG,KAAK,KAAK,cAAc,CACjD,CAKA,IAAI,MAAO,CACT,OAAOD,EAAA,KAAKN,EACd,CAEA,IAAI,KAAKS,EAAgB,CACvBD,EAAA,KAAKR,EAAQS,GACTA,GACFH,EAAA,KAAKL,IAAS,OAAO,EAEvB,KAAK,KAAK,cAAc,CAC1B,CASA,MAAa,CACX,KAAK,KAAO,EACd,CAGA,MAAa,CACX,KAAK,KAAO,EACd,CAGA,OAAOS,EAAkBC,EAAsBC,EAAsBjB,EAAyB,CACxFe,GAAWC,IACbL,EAAA,KAAKL,IAALO,EAAA,KAAKP,EAAYZ,EAAaqB,EAASC,EAAS,CAC9C,UAAAC,EACA,UAAW,CACT,CACE,KAAM,SACN,QAAS,CACP,OAAAjB,CACF,CACF,EACA,CACE,KAAM,OACN,QAAS,CACP,mBAAoB,CAAC,MAAO,QAAS,OAAQ,QAAQ,CACvD,CACF,CACF,CACF,CAAC,GACD,KAAK,cAAL,KAAK,YAAgB,IAEzB,CACF,EApEEK,EAAA,YAEAC,EAAA,YAEAC,EAAA",
|
|
6
|
+
"names": ["applyStyles", "arrow", "computeStyles", "eventListeners", "flip", "hide", "offset", "popperGenerator", "popperOffsets", "preventOverflow", "createPopper", "popperGenerator", "eventListeners", "popperOffsets", "computeStyles", "applyStyles", "offset", "flip", "preventOverflow", "arrow", "hide", "_open", "_popper", "_initialized", "FloatingDOMController", "host", "__privateAdd", "__privateGet", "v", "__privateSet", "value", "invoker", "content", "placement"]
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Logger as
|
|
1
|
+
import{Logger as o}from"./logger.js";var i=class{constructor(t,e,s){this.host=t;this.options=s;this.initializer=e.bind(t),this.mo=new MutationObserver(this.initializer),this.logger=new o(this.host),t.addController(this)}hostConnected(){this.hasLightDOM()?this.initializer():this.options?.emptyWarning&&this.logger.warn(this.options?.emptyWarning),this.initObserver()}hostDisconnected(){this.mo.disconnect()}initObserver(){(this.options?.observe??!0)&&this.mo.observe(this.host,typeof this.options?.observe!="object"?{childList:!0}:this.options?.observe)}hasLightDOM(){return this.host.children.length>0||(this.host.textContent??"").trim().length>0}};export{i as LightDOMController};
|
|
2
2
|
//# sourceMappingURL=light-dom-controller.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["light-dom-controller.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { Logger } from './logger.js';\n\nexport interface Options {\n observe?: boolean|MutationObserverInit;\n emptyWarning?: string;\n}\n\nexport class LightDOMController implements ReactiveController {\n private mo: MutationObserver;\n private logger: Logger;\n private initializer: () => void;\n\n constructor(private host: ReactiveElement, initializer: () => void, private options?: Options) {\n this.initializer = initializer.bind(host);\n this.mo = new MutationObserver(this.initializer);\n this.logger = new Logger(this.host);\n host.addController(this);\n }\n\n hostConnected() {\n if (this.hasLightDOM()) {\n this.initializer();\n } else if (this.options?.emptyWarning) {\n this.logger.warn(this.options?.emptyWarning);\n }\n\n this.initObserver();\n }\n\n hostDisconnected() {\n this.mo.disconnect();\n }\n\n private initObserver() {\n if (this.options?.observe ?? true) {\n // Use the provided options, or their defaults\n this.mo.observe(\n this.host,\n typeof this.options?.observe !== 'object' ? { childList: true }\n : this.options?.observe as MutationObserverInit\n );\n }\n }\n\n /**\n * Returns a boolean statement of whether or not this component contains any light DOM.\n */\n hasLightDOM(): boolean {\n return !!(\n this.host.children.length > 0 ||\n (this.host.textContent ?? '').trim().length > 0\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "AAEA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAEA,OAAS,UAAAA,MAAc,cAOhB,IAAMC,EAAN,KAAuD,CAK5D,YAAoBC,EAAuBC,EAAiCC,EAAmB,CAA3E,UAAAF,EAAwD,aAAAE,EAC1E,KAAK,YAAcD,EAAY,KAAKD,CAAI,EACxC,KAAK,GAAK,IAAI,iBAAiB,KAAK,WAAW,EAC/C,KAAK,OAAS,IAAIF,EAAO,KAAK,IAAI,EAClCE,EAAK,cAAc,IAAI,CACzB,CAEA,eAAgB,CACV,KAAK,YAAY,EACnB,KAAK,YAAY,EACR,KAAK,SAAS,cACvB,KAAK,OAAO,KAAK,KAAK,SAAS,YAAY,EAG7C,KAAK,aAAa,CACpB,CAEA,kBAAmB,CACjB,KAAK,GAAG,WAAW,CACrB,CAEQ,cAAe,EACjB,KAAK,SAAS,SAAW,KAE3B,KAAK,GAAG,QACN,KAAK,KACH,OAAO,KAAK,SAAS,SAAY,SAAW,CAAE,UAAW,EAAK,EAC9D,KAAK,SAAS,OAClB,CAEJ,CAKA,aAAuB,CACrB,OACE,KAAK,KAAK,SAAS,OAAS,IAC3B,KAAK,KAAK,aAAe,IAAI,KAAK,EAAE,OAAS,CAElD,CACF",
|
|
6
|
+
"names": ["Logger", "LightDOMController", "host", "initializer", "options"]
|
|
7
7
|
}
|
package/controllers/logger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=class{constructor(t){this.host=t;if(e.instances.get(t))return e.instances.get(t);t.addController(this),e.instances.set(t,this)}get prefix(){return`[${this.host.localName}${this.host.id?`#${this.host.id}`:""}]`}static debugLog(t=null){try{return t!==null&&(e.logDebug=!!t,localStorage.pfeLog=!!t),localStorage.pfeLog==="true"}catch{return e.logDebug}}static log(...t){e.debugLog()&&console.log(...t)}static warn(...t){console.warn(...t)}static error(...t){
|
|
1
|
+
var e=class{constructor(t){this.host=t;if(e.instances.get(t))return e.instances.get(t);t.addController(this),e.instances.set(t,this)}get prefix(){return`[${this.host.localName}${this.host.id?`#${this.host.id}`:""}]`}static debugLog(t=null){try{return t!==null&&(e.logDebug=!!t,localStorage.pfeLog=!!t),localStorage.pfeLog==="true"}catch{return e.logDebug}}static log(...t){e.debugLog()&&console.log(...t)}static warn(...t){console.warn(...t)}static error(...t){console.error([...t].join(" "))}log(...t){e.log(this.prefix,...t)}warn(...t){e.warn(this.prefix,...t)}error(...t){e.error(this.prefix,...t)}hostConnected(){this.log("connected")}},n=e;n.instances=new WeakMap;export{n as Logger};
|
|
2
2
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["logger.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nexport class Logger implements ReactiveController {\n private static logDebug: boolean;\n\n private static instances: WeakMap<HTMLElement, Logger> = new WeakMap();\n\n private get prefix() {\n return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;\n }\n\n /**\n * A boolean value that indicates if the logging should be printed to the console; used for debugging.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example Logger.debugLog(true);\n * @tags debug\n */\n static debugLog(preference = null) {\n // wrap localStorage references in a try/catch; merely referencing it can\n // throw errors in some locked down environments\n try {\n if (preference !== null) {\n Logger.logDebug = !!preference;\n localStorage.pfeLog = !!preference;\n }\n return localStorage.pfeLog === 'true';\n } catch (e) {\n return Logger.logDebug;\n }\n }\n\n /**\n * A logging wrapper which checks the debugLog boolean and prints to the console if true.\n *\n * @example Logger.log(\"Hello\");\n */\n static log(...msgs: unknown[]) {\n if (Logger.debugLog()) {\n // eslint-disable-next-line no-console\n console.log(...msgs);\n }\n }\n\n /**\n * A console warning wrapper which formats your output with useful debugging information.\n *\n * @example Logger.warn(\"Hello\");\n */\n static warn(...msgs: unknown[]) {\n console.warn(...msgs); // eslint-disable-line no-console\n }\n\n /**\n * A console error wrapper which formats your output with useful debugging information.\n * For use inside a component's function.\n * @example Logger.error(\"Hello\");\n */\n static error(...msgs: unknown[]) {\n
|
|
5
|
-
"mappings": "AAEO,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nexport class Logger implements ReactiveController {\n private static logDebug: boolean;\n\n private static instances: WeakMap<HTMLElement, Logger> = new WeakMap();\n\n private get prefix() {\n return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;\n }\n\n /**\n * A boolean value that indicates if the logging should be printed to the console; used for debugging.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example Logger.debugLog(true);\n * @tags debug\n */\n static debugLog(preference = null) {\n // wrap localStorage references in a try/catch; merely referencing it can\n // throw errors in some locked down environments\n try {\n if (preference !== null) {\n Logger.logDebug = !!preference;\n localStorage.pfeLog = !!preference;\n }\n return localStorage.pfeLog === 'true';\n } catch (e) {\n return Logger.logDebug;\n }\n }\n\n /**\n * A logging wrapper which checks the debugLog boolean and prints to the console if true.\n *\n * @example Logger.log(\"Hello\");\n */\n static log(...msgs: unknown[]) {\n if (Logger.debugLog()) {\n // eslint-disable-next-line no-console\n console.log(...msgs);\n }\n }\n\n /**\n * A console warning wrapper which formats your output with useful debugging information.\n *\n * @example Logger.warn(\"Hello\");\n */\n static warn(...msgs: unknown[]) {\n console.warn(...msgs); // eslint-disable-line no-console\n }\n\n /**\n * A console error wrapper which formats your output with useful debugging information.\n * For use inside a component's function.\n * @example Logger.error(\"Hello\");\n */\n static error(...msgs: unknown[]) {\n console.error([...msgs].join(' ')); // eslint-disable-line no-console\n }\n\n /**\n * Local logging that outputs the tag name as a prefix automatically\n *\n * @example this.logger.log(\"Hello\");\n */\n log(...msgs: unknown[]) {\n Logger.log(this.prefix, ...msgs);\n }\n\n /**\n * Local warning wrapper that outputs the tag name as a prefix automatically.\n * For use inside a component's function.\n * @example this.logger.warn(\"Hello\");\n */\n warn(...msgs: unknown[]) {\n Logger.warn(this.prefix, ...msgs);\n }\n\n /**\n * Local error wrapper that outputs the tag name as a prefix automatically.\n * For use inside a component's function.\n * @example this.logger.error(\"Hello\");\n */\n error(...msgs: unknown[]) {\n Logger.error(this.prefix, ...msgs);\n }\n\n constructor(private host: ReactiveElement) {\n // We only need one logger instance per host\n if (Logger.instances.get(host)) {\n return Logger.instances.get(host) as Logger;\n }\n host.addController(this);\n Logger.instances.set(host, this);\n }\n\n hostConnected() {\n this.log('connected');\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEO,IAAMA,EAAN,KAA2C,CAsFhD,YAAoBC,EAAuB,CAAvB,UAAAA,EAElB,GAAID,EAAO,UAAU,IAAIC,CAAI,EAC3B,OAAOD,EAAO,UAAU,IAAIC,CAAI,EAElCA,EAAK,cAAc,IAAI,EACvBD,EAAO,UAAU,IAAIC,EAAM,IAAI,CACjC,CAxFA,IAAY,QAAS,CACnB,MAAO,IAAI,KAAK,KAAK,YAAY,KAAK,KAAK,GAAK,IAAI,KAAK,KAAK,KAAO,KACvE,CAQA,OAAO,SAASC,EAAa,KAAM,CAGjC,GAAI,CACF,OAAIA,IAAe,OACjBF,EAAO,SAAW,CAAC,CAACE,EACpB,aAAa,OAAS,CAAC,CAACA,GAEnB,aAAa,SAAW,MACjC,MAAE,CACA,OAAOF,EAAO,QAChB,CACF,CAOA,OAAO,OAAOG,EAAiB,CACzBH,EAAO,SAAS,GAElB,QAAQ,IAAI,GAAGG,CAAI,CAEvB,CAOA,OAAO,QAAQA,EAAiB,CAC9B,QAAQ,KAAK,GAAGA,CAAI,CACtB,CAOA,OAAO,SAASA,EAAiB,CAC/B,QAAQ,MAAM,CAAC,GAAGA,CAAI,EAAE,KAAK,GAAG,CAAC,CACnC,CAOA,OAAOA,EAAiB,CACtBH,EAAO,IAAI,KAAK,OAAQ,GAAGG,CAAI,CACjC,CAOA,QAAQA,EAAiB,CACvBH,EAAO,KAAK,KAAK,OAAQ,GAAGG,CAAI,CAClC,CAOA,SAASA,EAAiB,CACxBH,EAAO,MAAM,KAAK,OAAQ,GAAGG,CAAI,CACnC,CAWA,eAAgB,CACd,KAAK,IAAI,WAAW,CACtB,CACF,EAlGaC,EAANJ,EAAMI,EAGI,UAA0C,IAAI",
|
|
6
|
+
"names": ["_Logger", "host", "preference", "msgs", "Logger"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getRandomId as
|
|
1
|
+
import{getRandomId as a}from"../functions/random.js";var r=class{constructor(e){this.host=e;this.hasMeasured=!1;e.addController(this),e.id?e.id.startsWith("pfe-")&&!e.id.startsWith(e.localName)?this.markId=e.id.replace("pfe",e.localName):this.markId=`${e.localName}-${e.id}`:this.markId=a(e.localName),performance.mark(`${this.markId}-defined`)}hostUpdate(){this.hasMeasured||this.measure()}measure(){this.hasMeasured=!0,performance.mark(`${this.markId}-rendered`),performance.measure(`${this.markId}-from-navigation-to-first-render`,void 0,`${this.markId}-rendered`),performance.measure(`${this.markId}-from-defined-to-first-render`,`${this.markId}-defined`,`${this.markId}-rendered`),this.host.removeController(this)}};export{r as PerfController};
|
|
2
2
|
//# sourceMappingURL=perf-controller.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["perf-controller.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { getRandomId } from '../functions/random.js';\n\nexport class PerfController implements ReactiveController {\n hasMeasured = false;\n\n markId: string;\n\n constructor(private host: ReactiveElement) {\n host.addController(this);\n\n // Set up the mark ID based on existing ID on component if it exists\n if (!host.id) {\n this.markId = getRandomId(host.localName);\n } else if (host.id.startsWith('pfe-') && !host.id.startsWith(host.localName)) {\n this.markId = host.id.replace('pfe', host.localName);\n } else {\n this.markId = `${host.localName}-${host.id}`;\n }\n\n performance.mark(`${this.markId}-defined`);\n }\n\n hostUpdate() {\n if (!this.hasMeasured) {\n this.measure();\n }\n }\n\n measure() {\n this.hasMeasured = true;\n\n performance.mark(`${this.markId}-rendered`);\n\n // Navigation start, i.e., the browser first sees that the user has navigated to the page\n performance.measure(`${this.markId}-from-navigation-to-first-render`, undefined, `${this.markId}-rendered`);\n\n // Render is run before connection unless delayRender is used\n performance.measure(\n `${this.markId}-from-defined-to-first-render`,\n `${this.markId}-defined`,\n `${this.markId}-rendered`\n );\n\n // Once we've measured time to render, we no longer need the controller,\n // so we allow it to be garbage-collected\n this.host.removeController(this);\n }\n}\n"],
|
|
5
|
-
"mappings": "AAEA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAEA,OAAS,eAAAA,MAAmB,yBAErB,IAAMC,EAAN,KAAmD,CAKxD,YAAoBC,EAAuB,CAAvB,UAAAA,EAJpB,iBAAc,GAKZA,EAAK,cAAc,IAAI,EAGlBA,EAAK,GAECA,EAAK,GAAG,WAAW,MAAM,GAAK,CAACA,EAAK,GAAG,WAAWA,EAAK,SAAS,EACzE,KAAK,OAASA,EAAK,GAAG,QAAQ,MAAOA,EAAK,SAAS,EAEnD,KAAK,OAAS,GAAGA,EAAK,aAAaA,EAAK,KAJxC,KAAK,OAASF,EAAYE,EAAK,SAAS,EAO1C,YAAY,KAAK,GAAG,KAAK,gBAAgB,CAC3C,CAEA,YAAa,CACN,KAAK,aACR,KAAK,QAAQ,CAEjB,CAEA,SAAU,CACR,KAAK,YAAc,GAEnB,YAAY,KAAK,GAAG,KAAK,iBAAiB,EAG1C,YAAY,QAAQ,GAAG,KAAK,yCAA0C,OAAW,GAAG,KAAK,iBAAiB,EAG1G,YAAY,QACV,GAAG,KAAK,sCACR,GAAG,KAAK,iBACR,GAAG,KAAK,iBACV,EAIA,KAAK,KAAK,iBAAiB,IAAI,CACjC,CACF",
|
|
6
|
+
"names": ["getRandomId", "PerfController", "host"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var l=Symbol("observed properties controller"),t=class{constructor(e){this.host=e;this.values=new Map;if(t.hosts.get(e))return t.hosts.get(e);e.addController(this),e[l]=this}delete(e){this.values.delete(e)}hostUpdate(){for(let[e,[
|
|
1
|
+
var l=Symbol("observed properties controller"),t=class{constructor(e){this.host=e;this.values=new Map;if(t.hosts.get(e))return t.hosts.get(e);e.addController(this),e[l]=this}delete(e){this.values.delete(e)}hostUpdate(){for(let[e,[o,[r,s]]]of this.values)this.host[o]?.(r,s),this.delete(e)}hostUpdated(){this.host.removeController(this)}cache(e,o,...r){this.values.set(e,[o,r])}},a=t;a.hosts=new WeakMap;export{a as PropertyObserverController,l as observedController};
|
|
2
2
|
//# sourceMappingURL=property-observer-controller.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["property-observer-controller.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ReactiveController, ReactiveElement } from 'lit';\n\nexport const observedController = Symbol('observed properties controller');\n\nexport type ChangeCallback<T = ReactiveElement> = (\n this: T,\n old?: T[keyof T],\n newV?: T[keyof T],\n) => void;\n\nexport type ChangeCallbackName = `_${string}Changed`;\n\nexport type PropertyObserverHost<T> = T & Record<ChangeCallbackName, ChangeCallback<T>> & {\n [observedController]: PropertyObserverController;\n}\n\n/** This controller holds a cache of observed property values which were set before the element updated */\nexport class PropertyObserverController implements ReactiveController {\n private static hosts: WeakMap<HTMLElement, PropertyObserverController> = new WeakMap();\n\n private values = new Map<string, [methodName: string, values: [unknown, unknown]]>();\n\n private delete(key: string) {\n this.values.delete(key);\n }\n\n constructor(private host: ReactiveElement) {\n if (PropertyObserverController.hosts.get(host)) {\n return PropertyObserverController.hosts.get(host) as PropertyObserverController;\n }\n host.addController(this);\n (host as PropertyObserverHost<ReactiveElement>)[observedController] = this;\n }\n\n /** Set any cached valued accumulated between constructor and connectedCallback */\n hostUpdate() {\n for (const [key, [methodName, [oldVal, newVal]]] of this.values) {\n // @ts-expect-error: be cool, typescript\n this.host[methodName as keyof ReactiveElement]?.(oldVal, newVal);\n this.delete(key);\n }\n }\n\n /** Once the element has updated, we no longer need this controller, so we remove it */\n hostUpdated() {\n this.host.removeController(this);\n }\n\n cache(key: string, methodName: string, ...vals: [unknown, unknown]) {\n this.values.set(key, [methodName, vals]);\n }\n}\n"],
|
|
5
|
-
"mappings": "AAEO,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAEO,IAAMA,EAAqB,OAAO,gCAAgC,EAe5DC,EAAN,KAA+D,CASpE,YAAoBC,EAAuB,CAAvB,UAAAA,EANpB,KAAQ,OAAS,IAAI,IAOnB,GAAID,EAA2B,MAAM,IAAIC,CAAI,EAC3C,OAAOD,EAA2B,MAAM,IAAIC,CAAI,EAElDA,EAAK,cAAc,IAAI,EACtBA,EAA+CF,GAAsB,IACxE,CAVQ,OAAOG,EAAa,CAC1B,KAAK,OAAO,OAAOA,CAAG,CACxB,CAWA,YAAa,CACX,OAAW,CAACA,EAAK,CAACC,EAAY,CAACC,EAAQC,CAAM,CAAC,CAAC,IAAK,KAAK,OAEvD,KAAK,KAAKF,KAAuCC,EAAQC,CAAM,EAC/D,KAAK,OAAOH,CAAG,CAEnB,CAGA,aAAc,CACZ,KAAK,KAAK,iBAAiB,IAAI,CACjC,CAEA,MAAMA,EAAaC,KAAuBG,EAA0B,CAClE,KAAK,OAAO,IAAIJ,EAAK,CAACC,EAAYG,CAAI,CAAC,CACzC,CACF,EAlCaC,EAANP,EAAMO,EACI,MAA0D,IAAI",
|
|
6
|
+
"names": ["observedController", "_PropertyObserverController", "host", "key", "methodName", "oldVal", "newVal", "vals", "PropertyObserverController"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
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&&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
|
+
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
2
|
//# sourceMappingURL=slot-controller.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 && 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
|
|
5
|
-
"mappings": "wMAEA
|
|
6
|
-
"names": []
|
|
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": "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",
|
|
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
7
|
}
|