@taprootio/espalier 4.12.0 → 4.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/custom-elements.json +10116 -9383
- package/dist/font-picker/esp-font-picker.d.ts +17 -23
- package/dist/font-picker/esp-font-picker.js +5 -5
- package/dist/font-picker/font-types.d.ts +49 -0
- package/dist/font-picker/font-types.js +1 -0
- package/dist/header/esp-header.js +6 -6
- package/dist/help/esp-help-button.d.ts +1 -1
- package/dist/icons/icon-sprite.generated.d.ts +1 -1
- package/dist/icons/icon-sprite.generated.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/lightbox/esp-lightbox.d.ts +1 -1
- package/dist/menu/drawer-nested-fit.js +1 -0
- package/dist/menu/esp-menu-group.js +5 -0
- package/dist/menu/esp-menu.d.ts +15 -0
- package/dist/menu/esp-menu.js +99 -25
- package/dist/pickers/esp-pick-one.js +4 -4
- package/dist/shared/configured-brand.d.ts +1 -1
- package/dist/shared/font-helpers.d.ts +8 -4
- package/dist/shared/font-helpers.js +1 -1
- package/dist/shared/font-stacks.d.ts +58 -0
- package/dist/shared/font-stacks.js +1 -0
- package/dist/shared/popover-controller.js +1 -1
- package/espalier.css-data.json +8 -0
- package/espalier.token-manifest.json +12 -0
- package/package.json +1 -1
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import "../pickers/esp-pick-one.js";
|
|
2
|
+
import "../tooltip/esp-tooltip.js";
|
|
2
3
|
import { EspalierElementBase } from "../shared/esp-element-base.js";
|
|
3
4
|
import { type EspalierFormField } from "../form-item/esp-form-item.js";
|
|
4
5
|
import { type PropertyValues } from "lit";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
variants: string[];
|
|
8
|
-
subsets: string[];
|
|
9
|
-
version: string;
|
|
10
|
-
lastModified: string;
|
|
11
|
-
files?: Record<string, string>;
|
|
12
|
-
category: FontCategory;
|
|
13
|
-
kind: string;
|
|
14
|
-
};
|
|
15
|
-
export type FontCategory = "serif" | "sans-serif" | "display" | "handwriting" | "monospace" | "not-display";
|
|
16
|
-
export type FontSource = "google" | "web-safe";
|
|
17
|
-
export type WebSafeFont = {
|
|
18
|
-
family: string;
|
|
19
|
-
stack: string;
|
|
20
|
-
category: Extract<FontCategory, "serif" | "sans-serif" | "monospace">;
|
|
21
|
-
kind: "web-safe";
|
|
22
|
-
};
|
|
23
|
-
export type FontPickerFont = GoogleFont | WebSafeFont;
|
|
24
|
-
export type FontPickerValueChangedDetail = FontPickerFont | undefined;
|
|
25
|
-
export declare const WEB_SAFE_FONTS: Array<WebSafeFont>;
|
|
6
|
+
import { type FontCategory, type FontPickerFont, type FontSource, type GoogleFont } from "./font-types.js";
|
|
7
|
+
export { DEVICE_DEFAULT_WEIGHTS, SYSTEM_TEXT_WEIGHTS, WEB_SAFE_FONTS, type FontCategory, type FontPickerFont, type FontPickerValueChangedDetail, type FontSource, type GoogleFont, type WebSafeCategory, type WebSafeFont, } from "./font-types.js";
|
|
26
8
|
/**
|
|
27
9
|
* Load the font catalog from the build-generated `font-definitions.json`
|
|
28
10
|
* file served alongside the font CSS files. The JSON is fetched from
|
|
@@ -30,6 +12,8 @@ export declare const WEB_SAFE_FONTS: Array<WebSafeFont>;
|
|
|
30
12
|
* the nearest `<esp-root>` element's `font-css-root` attribute.
|
|
31
13
|
*
|
|
32
14
|
* Results are cached at the module level so only one fetch occurs per page.
|
|
15
|
+
* A failed request is not cached: it rejects every caller waiting on it,
|
|
16
|
+
* and the next call retries.
|
|
33
17
|
*/
|
|
34
18
|
export declare const getGoogleFonts: () => Promise<Array<GoogleFont>>;
|
|
35
19
|
/**
|
|
@@ -97,7 +81,11 @@ export declare class EspalierFontPicker extends EspalierElementBase implements E
|
|
|
97
81
|
/**
|
|
98
82
|
* Source of fonts to display. `google` preserves the default Google
|
|
99
83
|
* Fonts catalog behavior. `web-safe` shows email-safe/system CSS
|
|
100
|
-
* font stacks and does not load Google font assets.
|
|
84
|
+
* font stacks and does not load Google font assets. `all` lists the
|
|
85
|
+
* device stacks above the Google catalog; every row carries a kind
|
|
86
|
+
* icon, a desktop for a device font and Google's mark for a catalog
|
|
87
|
+
* font, with a tooltip (ESP0206). Selecting a device row loads no
|
|
88
|
+
* preview CSS and no Google stylesheet.
|
|
101
89
|
*
|
|
102
90
|
* ```html
|
|
103
91
|
* <esp-box>
|
|
@@ -115,7 +103,13 @@ export declare class EspalierFontPicker extends EspalierElementBase implements E
|
|
|
115
103
|
* In the default Google Fonts mode this is the font family name, such
|
|
116
104
|
* as `"Aclonica"`. In `font-source="web-safe"` mode this is the full CSS
|
|
117
105
|
* font stack, such as `"Arial, Helvetica, sans-serif"`, so pre-selection
|
|
118
|
-
* via the `value` attribute must use the stack value.
|
|
106
|
+
* via the `value` attribute must use the stack value. In
|
|
107
|
+
* `font-source="all"` either form works: a catalog family (or a stack
|
|
108
|
+
* leading with one) selects the Google font, and a device stack selects
|
|
109
|
+
* the preset it is equivalent to — `system-ui, "Segoe UI", sans-serif`
|
|
110
|
+
* shows System Sans — or, when it matches no preset, shows as its own
|
|
111
|
+
* custom-stack row. Recognition never rewrites this value; only a user
|
|
112
|
+
* selection does.
|
|
119
113
|
*
|
|
120
114
|
* ```html
|
|
121
115
|
* <esp-box>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=function(e,t,o,i){var s=arguments.length,n=s<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,o):i,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,o,i);else for(var l=e.length-1;l>=0;l--)(a=e[l])&&(n=(s<3?a(n):s>3?a(t,o,n):a(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n};import"../pickers/esp-pick-one.js";import"../tooltip/esp-tooltip.js";import{customElement as A,property as F,state as L}from"lit/decorators.js";import{EspalierElementBase as x}from"../shared/esp-element-base.js";import{html as N}from"lit";import{extractFamily as U,getFallbackFont as B,removeRuntimeGoogleFontLink as O,syncRuntimeGoogleFontLink as q}from"../shared/font-helpers.js";import{fontFallbackAliases as W}from"../shared/font-plan.js";import{customWebSafeFont as I,matchWebSafeFont as j}from"../shared/font-stacks.js";import{getIconHrefForHost as P}from"../shared/intent-values.js";import{WEB_SAFE_FONTS as E,isSystemPreset as _}from"./font-types.js";import{DEVICE_DEFAULT_WEIGHTS as ft,SYSTEM_TEXT_WEIGHTS as dt,WEB_SAFE_FONTS as ht}from"./font-types.js";let y,m;const M=async()=>{const e=document.getElementsByTagName("esp-root")[0];if(!e)throw new Error("<esp-font-picker> requires an <esp-root> ancestor. Wrap your application in <esp-root> to use the font picker.");const t=e.fontDefinitionsUrl||`${e.fontCSSRoot}font-definitions.json`,o=await fetch(t);if(!o.ok)throw new Error(`Failed to load font definitions from ${t} (${o.status}). Run 'npm run build-fonts' to generate the font catalog.`);return await o.json()},z=async()=>{if(y)return y;if(!m){const e=M().then(t=>(y=t,t),t=>{throw m===e&&(m=void 0),t});m=e}return m},k="esp-preview-",H=e=>`${k}${e}`,g=new Map,v=async e=>{if(g.has(e))return!0;try{const t=document.getElementsByTagName("esp-root")[0];if(!t)return!1;const o=e.replaceAll(" ","-"),i=await fetch(`${t.fontCSSRoot}${o}.css`);if(!i.ok)return!1;let s=await i.text();s=s.replace(/font-family:\s*'([^']+)'/g,(a,l)=>`font-family: '${k}${l}'`);const n=document.createElement("style");return n.textContent=s,n.dataset.font=e,document.head.appendChild(n),g.set(e,n),!0}catch(t){return console.warn(`Failed to load CSS for font ${e}:`,t),!1}},S=e=>{const t=g.get(e);t&&(t.remove(),g.delete(e))},w="data-esp-font-picker",R="data-esp-font-picker-root",$=e=>e.closest("esp-root"),V=e=>$(e)?.correlationId??"",X=(e,t)=>`link[${w}="${CSS.escape(e)}"][${R}="${CSS.escape(t)}"]`,C=(e,t)=>`picker:${t}:${e}`,b=(e,t)=>{if(!t)return;const o=$(e),i=o?.correlationId??"";if(o?.googleFontLoading==="none"){p(e,t);return}q({owner:C(t,i),family:t,enabled:!0,attributes:{[w]:t,[R]:i}})},p=(e,t)=>{if(!t)return;const o=V(e);Array.from(document.getElementsByTagName("esp-font-picker")).some(s=>V(s)===o&&s.selectedGoogleFamily===t)||(O(C(t,o)),document.head.querySelector(X(t,o))?.remove())},f=e=>e.kind!=="web-safe",G="http://www.w3.org/2000/svg",K=(e,t)=>{const o=document.createElement("esp-tooltip");o.setAttribute("text",t==="device"?"Device font, no download":"Google font"),o.setAttribute("trigger-tabindex","-1"),o.setAttribute("style","display: grid; place-self: center;");const i=document.createElementNS(G,"svg");i.setAttribute("aria-hidden","true"),i.setAttribute("style","display: block; width: var(--esp-size-medium); height: var(--esp-size-medium); margin: var(--esp-size-tiny);");const s=document.createElementNS(G,"use");return s.setAttribute("href",P(t==="device"?"device-desktop":"brand-google",e)),i.append(s),o.append(i),o},T=e=>f(e)?e.family:e.stack,Y=e=>{if(!f(e))return e.stack;const t=W(e.family,400,e.category);return[`"${e.family}"`,...t,`"${H(e.family)}"`,B(e.category)].join(", ")},D=(e,t)=>e.filter(o=>{switch(t){case"not-display":return o.category!=="display";default:return o.category===t}});let d=class extends x{constructor(){super(...arguments),this.loadedFonts=new Set,this.formItemDescription=null,this.formItemLabel=null,this._rangeGeneration=0,this._initGeneration=0,this._fontsReady=Promise.resolve(),this.fonts=[],this.category=null,this.fontSource="google",this.value="",this.placeholder="Choose a font...",this.handleItemsInViewEvent=t=>{t.stopPropagation(),this.handleItemsInView(t.detail)}}focus(){this.shadowRoot?.querySelector("esp-pick-one")?.focus()}setFormItemDescription(t){this.formItemDescription=t,this.syncFormItemDescription()}setFormItemLabel(t){this.formItemLabel=t,this.syncFormItemDescription()}syncFormItemDescription(){const t=this.shadowRoot?.querySelector("esp-pick-one");t?.setFormItemDescription?.(this.formItemDescription),t?.setFormItemLabel?.(this.formItemLabel)}async getUpdateComplete(){const t=await super.getUpdateComplete();return await this._fontsReady,t}firstUpdated(t){super.firstUpdated(t),this._fontsReady=this.initFonts()}updated(t){super.updated(t),this.syncFormItemDescription();const o=t.has("fontSource")&&t.get("fontSource")!==void 0,i=t.has("category")&&t.get("category")!==void 0;if(o||i){if(o&&this.fontSource==="web-safe"){const s=this.value;for(const n of this.loadedFonts)S(n);this.loadedFonts.clear(),this.value="",s&&p(this,s)}this._fontsReady=this.initFonts()}if(t.has("value")&&this.value&&this.fontSource!=="web-safe"){const s=t.get("value"),n=this.googleFamilyFor(this.value),a=s?this.googleFamilyFor(s)??void 0:void 0;n&&s!==this.value?this.ensureFontLoaded(n,this.value,a):!n&&a&&p(this,a)}}get selectedGoogleFamily(){return this.fontSource==="web-safe"?null:this.googleFamilyFor(this.value)}googleFamilyFor(t){if(!t)return null;const o=this.fonts.filter(f);if(o.some(s=>s.family===t))return t;const i=U(t);return o.some(s=>s.family===i)?i:null}resolveSelection(){const t=this.value;if(!t||this.fonts.length===0)return{font:null,rowValue:t};const o=this.fontSource==="web-safe"?null:this.googleFamilyFor(t);if(o)return{font:this.fonts.find(l=>f(l)&&l.family===o)??null,rowValue:o};if(this.fontSource==="google")return{font:null,rowValue:t};const i=this.fonts.filter(a=>!f(a)),s=j(t,i);if(s)return{font:s,rowValue:s.stack};const n=I(t);return{font:n,rowValue:n?.stack??t}}async ensureFontLoaded(t,o,i){await v(t)&&this.loadedFonts.add(t),this.value===o&&(b(this,t),i&&i!==t&&p(this,i))}async initFonts(){const t=++this._initGeneration,o=this.fontSource,i=this.category?D(E,this.category):E;if(o==="web-safe"){this.fonts=i;return}const s=[...i.filter(_),...i.filter(u=>!_(u))];o==="all"&&(this.fonts=s);let n;try{n=await z()}catch(u){if(o!=="all")throw u;console.warn("esp-font-picker: the Google catalog is unavailable; listing device fonts only.",u);return}if(t!==this._initGeneration||this.fontSource!==o)return;const a=this.category?D(n,this.category):n;this.fonts=o==="all"?[...s,...a]:a;const l=this.value,c=this.googleFamilyFor(l);if(c){if(await v(c)){if(t!==this._initGeneration||this.fontSource!==o||this.value!==l){S(c);return}this.loadedFonts.add(c)}if(t!==this._initGeneration||this.fontSource!==o||this.value!==l)return;b(this,c)}}async handleItemsInView(t){if(this.fontSource==="web-safe")return;const o=++this._rangeGeneration,i=3,s=t.items??[],n=new Set,a=new Set(this.fonts.filter(f).map(r=>r.family)),l=Math.max(0,t.first),c=Math.min(t.last+i,s.length);for(let r=l;r<c;r++)a.has(s[r].value)&&n.add(s[r].value);for(const r of n)this.loadedFonts.has(r)||await v(r)&&this.loadedFonts.add(r);if(o!==this._rangeGeneration)return;const u=new Set(Array.from(document.getElementsByTagName("esp-font-picker")).map(r=>r.selectedGoogleFamily).filter(r=>!!r));for(const r of this.loadedFonts)u.has(r)||n.has(r)||(this.loadedFonts.delete(r),S(r))}render(){const t=this.resolveSelection(),o=this.fontSource==="all",s=[...t.font&&!this.fonts.includes(t.font)?[t.font]:[],...this.fonts].map(n=>({text:n.family,value:T(n),selected:t.font===n,styles:{fontFamily:Y(n)},...o?{slotNodes:[K(this,f(n)?"google":"device")]}:{}}));return N`<esp-pick-one
|
|
2
2
|
typeahead
|
|
3
|
-
.pickerItems=${
|
|
4
|
-
.value=${
|
|
3
|
+
.pickerItems=${s}
|
|
4
|
+
.value=${t.rowValue}
|
|
5
5
|
.placeholder=${this.placeholder}
|
|
6
6
|
@esp-picker-menu-range-changed=${this.handleItemsInViewEvent}
|
|
7
|
-
@esp-value-changed=${async
|
|
7
|
+
@esp-value-changed=${async n=>{n.stopPropagation();const a=this.value;if(!n.detail){const r=a?this.googleFamilyFor(a):null;this.value="",r&&p(this,r),this.emitValueChanged(void 0);return}const l=this.fonts.find(r=>T(r)===n.detail.value)??(this.fontSource==="all"?I(n.detail.value)??void 0:void 0),c=n.detail.value;this.value=c,this.emitValueChanged(l);const u=a?this.googleFamilyFor(a):null;if(u&&u!==c&&p(this,u),l&&f(l)){if(await v(c)&&this.loadedFonts.add(c),this.value!==c)return;b(this,c)}}}
|
|
8
8
|
>
|
|
9
|
-
</esp-pick-one>`}};
|
|
9
|
+
</esp-pick-one>`}};h([L()],d.prototype,"fonts",void 0),h([F({attribute:"category",type:String})],d.prototype,"category",void 0),h([F({attribute:"font-source",type:String})],d.prototype,"fontSource",void 0),h([F({type:String})],d.prototype,"value",void 0),h([F({type:String})],d.prototype,"placeholder",void 0),d=h([A("esp-font-picker")],d);const lt=()=>{y=void 0,m=void 0;for(const e of document.head.querySelectorAll("style[data-font]"))e.remove();g.clear();for(const e of document.head.querySelectorAll(`link[${w}]`))e.remove()};export{ft as DEVICE_DEFAULT_WEIGHTS,d as EspalierFontPicker,dt as SYSTEM_TEXT_WEIGHTS,ht as WEB_SAFE_FONTS,Y as getFontPreviewFamily,z as getGoogleFonts,H as previewFontFamily,lt as resetFontCache};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The font picker's data vocabulary: catalog entries, device (web-safe)
|
|
3
|
+
* stacks, and the union the picker reports. Kept free of DOM and network
|
|
4
|
+
* code so `shared/font-helpers` and `shared/font-stacks` can consume it
|
|
5
|
+
* without importing the component.
|
|
6
|
+
*/
|
|
7
|
+
export type GoogleFont = {
|
|
8
|
+
family: string;
|
|
9
|
+
variants: string[];
|
|
10
|
+
subsets: string[];
|
|
11
|
+
version: string;
|
|
12
|
+
lastModified: string;
|
|
13
|
+
files?: Record<string, string>;
|
|
14
|
+
category: FontCategory;
|
|
15
|
+
kind: string;
|
|
16
|
+
};
|
|
17
|
+
export type FontCategory = "serif" | "sans-serif" | "display" | "handwriting" | "monospace" | "not-display";
|
|
18
|
+
/**
|
|
19
|
+
* `google` lists the generated catalog; `web-safe` lists only device stacks;
|
|
20
|
+
* `all` (ESP0206) lists the device stacks above the catalog.
|
|
21
|
+
*/
|
|
22
|
+
export type FontSource = "google" | "web-safe" | "all";
|
|
23
|
+
export type WebSafeCategory = Extract<FontCategory, "serif" | "sans-serif" | "monospace">;
|
|
24
|
+
/**
|
|
25
|
+
* A CSS font stack that resolves to faces already on the reader's device,
|
|
26
|
+
* so choosing it downloads nothing.
|
|
27
|
+
*/
|
|
28
|
+
export type WebSafeFont = {
|
|
29
|
+
family: string;
|
|
30
|
+
stack: string;
|
|
31
|
+
category: WebSafeCategory;
|
|
32
|
+
kind: "web-safe";
|
|
33
|
+
/**
|
|
34
|
+
* Numeric weights the stack's device faces are expected to carry. Devices
|
|
35
|
+
* snap to the nearest weight they have and may synthesize bold, so this is
|
|
36
|
+
* a reasonable offer rather than a guarantee. Absent means 400 and 700.
|
|
37
|
+
*/
|
|
38
|
+
weights?: string[];
|
|
39
|
+
};
|
|
40
|
+
export type FontPickerFont = GoogleFont | WebSafeFont;
|
|
41
|
+
export type FontPickerValueChangedDetail = FontPickerFont | undefined;
|
|
42
|
+
/** Weights the platform UI faces (SF, Segoe UI Variable, Roboto) reliably carry. */
|
|
43
|
+
export declare const SYSTEM_TEXT_WEIGHTS: ReadonlyArray<string>;
|
|
44
|
+
/** Weights a device monospace or classic web-safe face reliably carries. */
|
|
45
|
+
export declare const DEVICE_DEFAULT_WEIGHTS: ReadonlyArray<string>;
|
|
46
|
+
/** The device stacks in their long-standing `web-safe` order; the combined source lists the System entries first. */
|
|
47
|
+
export declare const WEB_SAFE_FONTS: Array<WebSafeFont>;
|
|
48
|
+
/** Whether a preset is one of the platform System entries the combined source leads with. */
|
|
49
|
+
export declare const isSystemPreset: (font: WebSafeFont) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=["300","400","500","600","700"],s=["400","700"],i=[{family:"Arial / Helvetica",stack:"Arial, Helvetica, sans-serif",category:"sans-serif",kind:"web-safe"},{family:"Georgia / Times New Roman",stack:'Georgia, "Times New Roman", Times, serif',category:"serif",kind:"web-safe"},{family:"Verdana / Geneva",stack:"Verdana, Geneva, sans-serif",category:"sans-serif",kind:"web-safe"},{family:"Tahoma / Geneva",stack:"Tahoma, Geneva, sans-serif",category:"sans-serif",kind:"web-safe"},{family:"Trebuchet MS",stack:'"Trebuchet MS", Arial, sans-serif',category:"sans-serif",kind:"web-safe"},{family:"Courier New",stack:'"Courier New", Courier, monospace',category:"monospace",kind:"web-safe"},{family:"System Sans",stack:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',category:"sans-serif",kind:"web-safe",weights:[...e]},{family:"System Serif",stack:'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif',category:"serif",kind:"web-safe",weights:[...e]},{family:"System Monospace",stack:'ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", "Courier New", monospace',category:"monospace",kind:"web-safe"}],o=a=>a.family.startsWith("System ");export{s as DEVICE_DEFAULT_WEIGHTS,e as SYSTEM_TEXT_WEIGHTS,i as WEB_SAFE_FONTS,o as isSystemPreset};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var a=function(h,e,t,s){var n=arguments.length,l=n<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(h,e,t,s);else for(var d=h.length-1;d>=0;d--)(r=h[d])&&(l=(n<3?r(l):n>3?r(e,t,l):r(e,t))||l);return n>3&&l&&Object.defineProperty(e,t,l),l};import{css as B,html as x,nothing as T}from"lit";import{customElement as k,property as i,state as c}from"lit/decorators.js";import{classMap as A}from"lit/directives/class-map.js";import{styleMap as O}from"lit/directives/style-map.js";import"../burger/esp-burger.js";import{createRef as C,ref as D}from"lit/directives/ref.js";import{EspalierMenu as p}from"../menu/esp-menu.js";import{RafThrottle as _}from"../shared/raf-throttle.js";import{renderConfiguredBrand as R,resolveConfiguredBrand as E}from"../shared/configured-brand.js";import{EspalierElementBase as M}from"../shared/esp-element-base.js";import{ESP_EVENTS as z}from"../shared/events.js";const H="(max-width: 36rem)";function u(h,e){const t=new Set(h);return{allowedValues:t,converter:{fromAttribute(n){return n??e},toAttribute(n){return t.has(n)?n:e}},defaultValue:e}}const j=["standard","centered-brand","centered-menu","extended","extended-centered","minimal"],q=["start","center","end"],V=["truncate","wrap","nowrap"],N=["auto","inline","drawer"],U=["hidden","visible"],g=u(j,"standard"),b=u(q,"start"),f=u(V,"truncate"),v=u(N,"auto"),w=u(U,"hidden");let o=class extends M{constructor(){super(...arguments),this.menuOpen=!1,this.menuTooLarge=!1,this.mobileMenu=!1,this.scrolled=!1,this.hiddenByScroll=!1,this.scrollProgress=0,this.showBurger=!1,this.layout=g.defaultValue,this.brandText="",this.brandLogo="",this.lightBrandLogo="",this.darkBrandLogo="",this.brandHref="",this.brandAlt="",this.brandColor="",this.lightBrandColor="",this.darkBrandColor="",this.brandAlign=b.defaultValue,this.brandWrap=f.defaultValue,this.menuDisplay=v.defaultValue,this.themeToggle=w.defaultValue,this.scrollBehavior="none",this.scrollThreshold=16,this.dockOffset=0,this.drawerTarget="",this.previewCollapseRequested=!1,this.fullBleedContent=!1,this.menuContainer=C(),this.menuButton=C(),this.menu=void 0,this.externalDrawerTarget=null,this.lastScrollY=0,this.lastInlineMenuWidth=0,this.mobileMenuQuery=null,this.menuDrawerListenersAttached=!1,this.observingMenuContainer=!1,this.scrollListenersAttached=!1,this.scrollFrame=new _(()=>this.runScrollStateUpdate()),this.resizeObserver=new ResizeObserver(()=>this.syncMenuLayout()),this.menuChildObserver=null,this.updateScrollState=()=>this.scrollFrame.schedule(),this.handleMobileMenuQueryChange=e=>{this.mobileMenu=e.matches,this.syncMenuLayout(),this.syncExternalDrawerControl()},this.toggleTheme=()=>{const e=this.getThemeRoot();if(!e)return;e.scheme=e.scheme==="dark"?"light":"dark";const t=e.scheme==="dark"?"dark":"light";this.dispatchEvent(new CustomEvent(z.HEADER_THEME_TOGGLE,{detail:{scheme:t},bubbles:!0,composed:!0}))},this.handleMenuToggleClicked=()=>{if(this.menuOpen){this.closeNav();return}this.openNav()},this.onMenuDrawerOpened=()=>{this.menuOpen=!0,document.body.classList.add("menu-open"),this.burger&&(this.burger.menuOpen=!0)},this.onMenuDrawerClosed=()=>{this.menuOpen=!1,document.body.classList.remove("menu-open"),this.burger&&(this.burger.menuOpen=!1),this.demoteMenuToggle()},this.onMenuDrawerPresented=e=>{e.target!==this.menu||!this.menu?.isFullScreenDrawer||this.promoteMenuToggle()},this.menuTogglePromoted=!1,this.lastDrawerBrandKey="",this.inertedHeaderChrome=[]}syncMenuLayout(){if(!this.menuContainer.value||!this.menu||!this.menu.getWidth)return;this.positionPromotedToggle();const e=this.menu.getWidth();e>0&&(this.lastInlineMenuWidth=e);const t=this.lastInlineMenuWidth||e,s=this.getExternalDrawerTarget(),n=this.menuDisplay!=="inline",l=this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested,r=n&&this.menuDisplay==="auto",d=r?this.layout==="centered-menu"?this.centeredMenuCapacity():this.menuContainer.value.clientWidth:0;this.menuTooLarge=r&&t>d,this.menu.sliding=n&&!s&&this.hasDrawerableContent()&&(this.menuTooLarge||l||this.mobileMenu)}centeredMenuCapacity(){const e=this.menuContainer.value?.parentElement;if(!(e instanceof HTMLElement))return 0;const t=d=>d?d.getBoundingClientRect().width:0,s=getComputedStyle(e),n=e.clientWidth-(Number.parseFloat(s.paddingLeft)||0)-(Number.parseFloat(s.paddingRight)||0),l=e.querySelector(":scope > section.brand"),r=e.querySelector(":scope > section.buttons");return n-t(l)-t(r)+t(r?.querySelector("esp-header-button.menu-toggle"))}menuHasContent(){return!!(this.menu??this.querySelector(':scope > [slot="menu"]'))?.querySelector("esp-menu-item, esp-menu-group")}hasDrawerableContent(){return this.showBurger||!!this.getExternalDrawerTarget()||this.menuHasContent()}getExternalDrawerTarget(){if(!this.drawerTarget)return null;const e=document.getElementById(this.drawerTarget);return e===this.menu?null:e&&"openDrawer"in e&&typeof e.openDrawer=="function"&&"closeDrawer"in e&&typeof e.closeDrawer=="function"?e:null}getBurgerFocusTarget(){const t=this.shadowRoot?.querySelector("esp-header-button.menu-toggle")?.shadowRoot?.querySelector("button"),s=this.menuButton.value?.shadowRoot?.querySelector("button");return t??s??null}getScrollTokens(){const e=this.scrollBehavior.split(/\s+/).map(t=>t.trim().toLowerCase()).filter(Boolean);return new Set(e.filter(t=>t!=="none"))}getEffectiveScrollThreshold(){return Number.isFinite(this.scrollThreshold)?Math.max(0,this.scrollThreshold):0}clearScrollState(){this.scrolled=!1,this.hiddenByScroll=!1,this.scrollProgress=0}runScrollStateUpdate(){const e=this.getScrollTokens();if(!e.size){this.clearScrollState();return}const t=Math.max(0,window.scrollY||document.documentElement.scrollTop||0),s=this.getEffectiveScrollThreshold(),n=Number.isFinite(this.dockOffset)?Math.max(0,this.dockOffset):s,l=t>(e.has("dock")?n:s),r=t>this.lastScrollY,d=e.has("reveal")&&r&&t>s&&!this.menuOpen;if(this.scrolled=l,this.hiddenByScroll=d,e.has("progress")){const m=document.documentElement,y=Math.max(1,m.scrollHeight-window.innerHeight);this.scrollProgress=Math.min(1,t/y)}else this.scrollProgress=0;this.lastScrollY=t}cancelScrollUpdate(){this.scrollFrame.cancel()}syncScrollListeners(){const e=this.getScrollTokens().size>0;if(e&&!this.scrollListenersAttached?(window.addEventListener("scroll",this.updateScrollState,{passive:!0}),window.addEventListener("resize",this.updateScrollState,{passive:!0}),this.scrollListenersAttached=!0):!e&&this.scrollListenersAttached&&this.removeScrollListeners(),e){this.updateScrollState();return}this.cancelScrollUpdate(),this.clearScrollState()}removeScrollListeners(){this.scrollListenersAttached&&(window.removeEventListener("scroll",this.updateScrollState),window.removeEventListener("resize",this.updateScrollState),this.scrollListenersAttached=!1)}addMenuDrawerListeners(){!this.menu||this.menuDrawerListenersAttached||(this.menu.addEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.menu.addEventListener("esp-menu-drawer-presented",this.onMenuDrawerPresented),this.menu.addEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.menuDrawerListenersAttached=!0)}removeMenuDrawerListeners(){!this.menu||!this.menuDrawerListenersAttached||(this.menu.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.menu.removeEventListener("esp-menu-drawer-presented",this.onMenuDrawerPresented),this.menu.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.menuDrawerListenersAttached=!1)}observeMenuContainer(){if(!this.menuContainer.value||this.observingMenuContainer)return;this.resizeObserver.observe(this.menuContainer.value);const e=this.menuContainer.value.parentElement;if(e){this.resizeObserver.observe(e);for(const t of e.querySelectorAll(":scope > section.brand, :scope > section.buttons"))this.resizeObserver.observe(t)}this.observingMenuContainer=!0}disconnectResizeObserver(){this.observingMenuContainer&&(this.resizeObserver.disconnect(),this.observingMenuContainer=!1)}observeMenuChildren(){!this.menu||this.menuChildObserver||(this.menuChildObserver=new MutationObserver(()=>{this.syncMenuLayout(),this.requestUpdate()}),this.menuChildObserver.observe(this.menu,{childList:!0,subtree:!0}))}syncMobileMenuQuery(){if("matchMedia"in window){if(!this.mobileMenuQuery){this.mobileMenuQuery=window.matchMedia(H),this.mobileMenu=this.mobileMenuQuery.matches,this.mobileMenuQuery.addEventListener("change",this.handleMobileMenuQueryChange);return}this.mobileMenu=this.mobileMenuQuery.matches}}getThemeRoot(){return this.traverseToClosest("esp-root")}syncExternalDrawerTarget(){const e=this.getExternalDrawerTarget(),t=e===this.menu?null:e;t!==this.externalDrawerTarget&&(this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=!1),this.externalDrawerTarget=t,this.externalDrawerTarget?.addEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.addEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed)),this.syncExternalDrawerControl()}burgerVisibleForTarget(){if(this.menuDisplay==="inline")return!1;const e=this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested;return this.menuTooLarge||this.mobileMenu||e}syncExternalDrawerControl(){this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=this.burgerVisibleForTarget())}openNav(){const e=this.getBurgerFocusTarget(),t=this.getExternalDrawerTarget();if(this.burger&&(this.burger.menuOpen=!0),t){this.menuOpen=!0,t.openDrawer(e),document.body.classList.add("menu-open");return}if(this.menu){this.menu.sliding=!0,this.menuOpen=!0,this.menu.isFullScreenDrawer&&this.canPromoteMenuToggle()&&(this.menu.liftedCloseControl=this.getMenuToggleElement()),this.menu.openDrawer(e),document.body.classList.add("menu-open");return}this.burger&&(this.burger.menuOpen=!1)}closeNav(){this.menuOpen=!1,this.burger&&(this.burger.menuOpen=!1),this.demoteMenuToggle();const e=this.getExternalDrawerTarget();if(e){e.closeDrawer(),document.body.classList.remove("menu-open");return}this.menu&&(this.menu.closeDrawer(),document.body.classList.remove("menu-open"))}getMenuToggleElement(){return this.shadowRoot?.querySelector("esp-header-button.menu-toggle")??null}canPromoteMenuToggle(){const e=this.getMenuToggleElement();return!!e&&typeof e?.showPopover=="function"}setHeaderChromeInert(e){if(!e){for(const r of this.inertedHeaderChrome)r.inert=!1;this.inertedHeaderChrome=[];return}const t=this.menuContainer.value?.parentElement,s=this.getMenuToggleElement();if(!t||!s)return;const n=[];for(const r of t.querySelectorAll(":scope > section.brand, :scope > section.topbar"))n.push(r);const l=t.querySelector(":scope > section.buttons");for(const r of l?.children??[])if(!(!(r instanceof HTMLElement)||r===s)){if(r instanceof HTMLSlotElement){for(const d of r.assignedElements())d instanceof HTMLElement&&n.push(d);continue}n.push(r)}for(const r of n)r.inert||(r.inert=!0,this.inertedHeaderChrome.push(r))}promoteMenuToggle(){const e=this.getMenuToggleElement();if(!e||this.menuTogglePromoted||typeof e.showPopover!="function")return;const t=e.getBoundingClientRect();e.setAttribute("popover","manual"),Object.assign(e.style,{position:"fixed",inset:"auto",top:`${t.top}px`,left:`${t.left}px`,margin:"0",padding:"0",border:"0",background:"transparent",overflow:"visible"});try{e.showPopover()}catch{e.removeAttribute("popover"),e.removeAttribute("style"),this.menu&&(this.menu.liftedCloseControl=null);return}this.menuTogglePromoted=!0,this.menu&&(this.menu.liftedCloseControl=e),this.setHeaderChromeInert(!0)}positionPromotedToggle(){if(!this.menuTogglePromoted)return;const e=this.getMenuToggleElement(),t=this.shadowRoot?.querySelector("section.buttons");if(!e||!t)return;const s=t.getBoundingClientRect(),n=e.getBoundingClientRect(),l=getComputedStyle(t).direction==="rtl";e.style.top=`${s.top+(s.height-n.height)/2}px`,e.style.left=`${l?s.left:s.right-n.width}px`}demoteMenuToggle(){if(this.menu?.liftedCloseControl&&(this.menu.liftedCloseControl=null),!this.menuTogglePromoted)return;this.menuTogglePromoted=!1,this.setHeaderChromeInert(!1);const e=this.getMenuToggleElement();if(e){try{e.hidePopover()}catch{}e.removeAttribute("popover"),e.removeAttribute("style")}}syncDrawerBrand(){if(!this.menu)return;const e=E({scheme:this.scheme,brandLogo:this.brandLogo,brandColor:this.brandColor,lightBrandLogo:this.lightBrandLogo,darkBrandLogo:this.darkBrandLogo,lightBrandColor:this.lightBrandColor,darkBrandColor:this.darkBrandColor}),t=e.brandLogo||this.brandText?{brandLogo:e.brandLogo,brandText:this.brandText,brandHref:this.brandHref,brandAlt:this.brandAlt,brandColor:e.brandColor}:null,s=JSON.stringify(t);s!==this.lastDrawerBrandKey&&(this.lastDrawerBrandKey=s,this.menu.drawerBrand=t)}get burger(){return this.menuButton.value??void 0}willUpdate(e){super.willUpdate(e),e.has("layout")&&!g.allowedValues.has(this.layout)&&(this.layout=g.defaultValue),e.has("brandAlign")&&!b.allowedValues.has(this.brandAlign)&&(this.brandAlign=b.defaultValue),e.has("brandWrap")&&!f.allowedValues.has(this.brandWrap)&&(this.brandWrap=f.defaultValue),e.has("menuDisplay")&&!v.allowedValues.has(this.menuDisplay)&&(this.menuDisplay=v.defaultValue),e.has("themeToggle")&&!w.allowedValues.has(this.themeToggle)&&(this.themeToggle=w.defaultValue)}firstUpdated(e){if(super.firstUpdated(e),!this.menuContainer.value)return;const n=(this.menuContainer.value.firstElementChild?.assignedElements()??[])[0];n instanceof p?(this.menu=n,this.addMenuDrawerListeners(),this.observeMenuChildren(),this.syncDrawerBrand()):n&&console.warn("<esp-header>: the menu slot expects an <esp-menu> element, received",n),this.observeMenuContainer(),this.syncExternalDrawerTarget(),this.syncMobileMenuQuery(),this.syncScrollListeners(),this.syncMenuLayout()}updated(e){super.updated(e),this.syncDrawerBrand(),(e.has("showBurger")||e.has("drawerTarget")||e.has("menuDisplay")||e.has("layout")||e.has("previewCollapseRequested"))&&(this.syncExternalDrawerTarget(),this.syncMenuLayout()),(e.has("mobileMenu")||e.has("menuTooLarge"))&&this.syncExternalDrawerControl(),e.has("scrollBehavior")?this.syncScrollListeners():(e.has("scrollThreshold")||e.has("dockOffset"))&&this.updateScrollState()}connectedCallback(){super.connectedCallback(),this.syncScrollListeners(),this.syncMobileMenuQuery(),this.addMenuDrawerListeners(),this.syncExternalDrawerTarget(),this.observeMenuContainer(),this.observeMenuChildren()}disconnectedCallback(){this.removeMenuDrawerListeners(),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=!1),this.externalDrawerTarget=null,this.mobileMenuQuery?.removeEventListener("change",this.handleMobileMenuQueryChange),this.mobileMenuQuery=null,this.removeScrollListeners(),this.cancelScrollUpdate(),this.disconnectResizeObserver(),this.menuChildObserver?.disconnect(),this.menuChildObserver=null,this.demoteMenuToggle(),super.disconnectedCallback()}render(){const{menuOpen:e,menuTooLarge:t,mobileMenu:s}=this,n=this.menuDisplay!=="inline",l=n&&(this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested),r=this.getScrollTokens(),d=r.has("progress"),m=E({scheme:this.scheme,brandLogo:this.brandLogo,brandColor:this.brandColor,lightBrandLogo:this.lightBrandLogo,darkBrandLogo:this.darkBrandLogo,lightBrandColor:this.lightBrandColor,darkBrandColor:this.darkBrandColor}),y={"--_esp-header-brand-color":m.brandColor||null,"--_esp-header-scroll-progress":String(this.scrollProgress)},L={"menu-open":e,"too-wide":n&&this.hasDrawerableContent()&&(t||s||l),[`layout-${this.layout}`]:!0,"is-scrolled":this.scrolled,"hide-on-scroll":this.hiddenByScroll,"scroll-compact":r.has("compact"),"scroll-elevate":r.has("elevate"),"scroll-transparent":r.has("transparent")||r.has("transparent-to-solid"),"scroll-collapse-topbar":r.has("collapse-topbar")},S=this.scheme==="dark"?"light":"dark";return x`
|
|
2
|
-
<header class=${
|
|
1
|
+
var a=function(h,e,t,o){var r=arguments.length,i=r<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(h,e,t,o);else for(var d=h.length-1;d>=0;d--)(n=h[d])&&(i=(r<3?n(i):r>3?n(e,t,i):n(e,t))||i);return r>3&&i&&Object.defineProperty(e,t,i),i};import{css as k,html as x,nothing as T}from"lit";import{customElement as A,property as l,state as c}from"lit/decorators.js";import{classMap as O}from"lit/directives/class-map.js";import{styleMap as _}from"lit/directives/style-map.js";import"../burger/esp-burger.js";import{createRef as C,ref as D}from"lit/directives/ref.js";import{EspalierMenu as p}from"../menu/esp-menu.js";import{RafThrottle as E}from"../shared/raf-throttle.js";import{viewportSize as R}from"../shared/viewport.js";import{renderConfiguredBrand as z,resolveConfiguredBrand as M}from"../shared/configured-brand.js";import{EspalierElementBase as L}from"../shared/esp-element-base.js";import{ESP_EVENTS as H}from"../shared/events.js";const P="(max-width: 36rem)";function u(h,e){const t=new Set(h);return{allowedValues:t,converter:{fromAttribute(r){return r??e},toAttribute(r){return t.has(r)?r:e}},defaultValue:e}}const j=["standard","centered-brand","centered-menu","extended","extended-centered","minimal"],V=["start","center","end"],q=["truncate","wrap","nowrap"],N=["auto","inline","drawer"],U=["hidden","visible"],g=u(j,"standard"),b=u(V,"start"),f=u(q,"truncate"),v=u(N,"auto"),w=u(U,"hidden");let s=class extends L{constructor(){super(...arguments),this.menuOpen=!1,this.menuTooLarge=!1,this.mobileMenu=!1,this.scrolled=!1,this.hiddenByScroll=!1,this.scrollProgress=0,this.showBurger=!1,this.layout=g.defaultValue,this.brandText="",this.brandLogo="",this.lightBrandLogo="",this.darkBrandLogo="",this.brandHref="",this.brandAlt="",this.brandColor="",this.lightBrandColor="",this.darkBrandColor="",this.brandAlign=b.defaultValue,this.brandWrap=f.defaultValue,this.menuDisplay=v.defaultValue,this.themeToggle=w.defaultValue,this.scrollBehavior="none",this.scrollThreshold=16,this.dockOffset=0,this.drawerTarget="",this.previewCollapseRequested=!1,this.fullBleedContent=!1,this.menuContainer=C(),this.menuButton=C(),this.menu=void 0,this.externalDrawerTarget=null,this.lastScrollY=0,this.lastInlineMenuWidth=0,this.mobileMenuQuery=null,this.menuDrawerListenersAttached=!1,this.observingMenuContainer=!1,this.scrollListenersAttached=!1,this.scrollFrame=new E(()=>this.runScrollStateUpdate()),this.resizeObserver=new ResizeObserver(()=>this.syncMenuLayout()),this.menuChildObserver=null,this.updateScrollState=()=>this.scrollFrame.schedule(),this.handleMobileMenuQueryChange=e=>{this.mobileMenu=e.matches,this.syncMenuLayout(),this.syncExternalDrawerControl()},this.toggleTheme=()=>{const e=this.getThemeRoot();if(!e)return;e.scheme=e.scheme==="dark"?"light":"dark";const t=e.scheme==="dark"?"dark":"light";this.dispatchEvent(new CustomEvent(H.HEADER_THEME_TOGGLE,{detail:{scheme:t},bubbles:!0,composed:!0}))},this.handleMenuToggleClicked=()=>{if(this.menuOpen){this.closeNav();return}this.openNav()},this.onMenuDrawerOpened=()=>{this.menuOpen=!0,document.body.classList.add("menu-open"),this.burger&&(this.burger.menuOpen=!0)},this.onMenuDrawerClosed=()=>{this.menuOpen=!1,document.body.classList.remove("menu-open"),this.burger&&(this.burger.menuOpen=!1),this.demoteMenuToggle()},this.onMenuDrawerPresented=e=>{e.target!==this.menu||!this.menu?.isFullScreenDrawer||this.promoteMenuToggle()},this.menuTogglePromoted=!1,this.promotedToggleFrame=new E(()=>this.positionPromotedToggle()),this.handlePromotedViewportResize=()=>this.promotedToggleFrame.schedule(),this.lastDrawerBrandKey="",this.inertedHeaderChrome=[]}syncMenuLayout(){if(!this.menuContainer.value||!this.menu||!this.menu.getWidth)return;this.positionPromotedToggle();const e=this.menu.getWidth();e>0&&(this.lastInlineMenuWidth=e);const t=this.lastInlineMenuWidth||e,o=this.getExternalDrawerTarget(),r=this.menuDisplay!=="inline",i=this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested,n=r&&this.menuDisplay==="auto",d=n?this.layout==="centered-menu"?this.centeredMenuCapacity():this.menuContainer.value.clientWidth:0;this.menuTooLarge=n&&t>d,this.menu.sliding=r&&!o&&this.hasDrawerableContent()&&(this.menuTooLarge||i||this.mobileMenu)}centeredMenuCapacity(){const e=this.menuContainer.value?.parentElement;if(!(e instanceof HTMLElement))return 0;const t=d=>d?d.getBoundingClientRect().width:0,o=getComputedStyle(e),r=e.clientWidth-(Number.parseFloat(o.paddingLeft)||0)-(Number.parseFloat(o.paddingRight)||0),i=e.querySelector(":scope > section.brand"),n=e.querySelector(":scope > section.buttons");return r-t(i)-t(n)+t(n?.querySelector("esp-header-button.menu-toggle"))}menuHasContent(){return!!(this.menu??this.querySelector(':scope > [slot="menu"]'))?.querySelector("esp-menu-item, esp-menu-group")}hasDrawerableContent(){return this.showBurger||!!this.getExternalDrawerTarget()||this.menuHasContent()}getExternalDrawerTarget(){if(!this.drawerTarget)return null;const e=document.getElementById(this.drawerTarget);return e===this.menu?null:e&&"openDrawer"in e&&typeof e.openDrawer=="function"&&"closeDrawer"in e&&typeof e.closeDrawer=="function"?e:null}getBurgerFocusTarget(){const t=this.shadowRoot?.querySelector("esp-header-button.menu-toggle")?.shadowRoot?.querySelector("button"),o=this.menuButton.value?.shadowRoot?.querySelector("button");return t??o??null}getScrollTokens(){const e=this.scrollBehavior.split(/\s+/).map(t=>t.trim().toLowerCase()).filter(Boolean);return new Set(e.filter(t=>t!=="none"))}getEffectiveScrollThreshold(){return Number.isFinite(this.scrollThreshold)?Math.max(0,this.scrollThreshold):0}clearScrollState(){this.scrolled=!1,this.hiddenByScroll=!1,this.scrollProgress=0}runScrollStateUpdate(){const e=this.getScrollTokens();if(!e.size){this.clearScrollState();return}const t=Math.max(0,window.scrollY||document.documentElement.scrollTop||0),o=this.getEffectiveScrollThreshold(),r=Number.isFinite(this.dockOffset)?Math.max(0,this.dockOffset):o,i=t>(e.has("dock")?r:o),n=t>this.lastScrollY,d=e.has("reveal")&&n&&t>o&&!this.menuOpen;if(this.scrolled=i,this.hiddenByScroll=d,e.has("progress")){const m=document.documentElement,y=Math.max(1,m.scrollHeight-window.innerHeight);this.scrollProgress=Math.min(1,t/y)}else this.scrollProgress=0;this.lastScrollY=t}cancelScrollUpdate(){this.scrollFrame.cancel()}syncScrollListeners(){const e=this.getScrollTokens().size>0;if(e&&!this.scrollListenersAttached?(window.addEventListener("scroll",this.updateScrollState,{passive:!0}),window.addEventListener("resize",this.updateScrollState,{passive:!0}),this.scrollListenersAttached=!0):!e&&this.scrollListenersAttached&&this.removeScrollListeners(),e){this.updateScrollState();return}this.cancelScrollUpdate(),this.clearScrollState()}removeScrollListeners(){this.scrollListenersAttached&&(window.removeEventListener("scroll",this.updateScrollState),window.removeEventListener("resize",this.updateScrollState),this.scrollListenersAttached=!1)}addMenuDrawerListeners(){!this.menu||this.menuDrawerListenersAttached||(this.menu.addEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.menu.addEventListener("esp-menu-drawer-presented",this.onMenuDrawerPresented),this.menu.addEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.menuDrawerListenersAttached=!0)}removeMenuDrawerListeners(){!this.menu||!this.menuDrawerListenersAttached||(this.menu.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.menu.removeEventListener("esp-menu-drawer-presented",this.onMenuDrawerPresented),this.menu.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.menuDrawerListenersAttached=!1)}observeMenuContainer(){if(!this.menuContainer.value||this.observingMenuContainer)return;this.resizeObserver.observe(this.menuContainer.value);const e=this.menuContainer.value.parentElement;if(e){this.resizeObserver.observe(e);for(const t of e.querySelectorAll(":scope > section.brand, :scope > section.buttons"))this.resizeObserver.observe(t)}this.observingMenuContainer=!0}disconnectResizeObserver(){this.observingMenuContainer&&(this.resizeObserver.disconnect(),this.observingMenuContainer=!1)}observeMenuChildren(){!this.menu||this.menuChildObserver||(this.menuChildObserver=new MutationObserver(()=>{this.syncMenuLayout(),this.requestUpdate()}),this.menuChildObserver.observe(this.menu,{childList:!0,subtree:!0}))}syncMobileMenuQuery(){if("matchMedia"in window){if(!this.mobileMenuQuery){this.mobileMenuQuery=window.matchMedia(P),this.mobileMenu=this.mobileMenuQuery.matches,this.mobileMenuQuery.addEventListener("change",this.handleMobileMenuQueryChange);return}this.mobileMenu=this.mobileMenuQuery.matches}}getThemeRoot(){return this.traverseToClosest("esp-root")}syncExternalDrawerTarget(){const e=this.getExternalDrawerTarget(),t=e===this.menu?null:e;t!==this.externalDrawerTarget&&(this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=!1),this.externalDrawerTarget=t,this.externalDrawerTarget?.addEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.addEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed)),this.syncExternalDrawerControl()}burgerVisibleForTarget(){if(this.menuDisplay==="inline")return!1;const e=this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested;return this.menuTooLarge||this.mobileMenu||e}syncExternalDrawerControl(){this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=this.burgerVisibleForTarget())}openNav(){const e=this.getBurgerFocusTarget(),t=this.getExternalDrawerTarget();if(this.burger&&(this.burger.menuOpen=!0),t){this.menuOpen=!0,t.openDrawer(e),document.body.classList.add("menu-open");return}if(this.menu){this.menu.sliding=!0,this.menuOpen=!0,this.menu.isFullScreenDrawer&&this.canPromoteMenuToggle()&&(this.menu.liftedCloseControl=this.getMenuToggleElement()),this.menu.openDrawer(e),document.body.classList.add("menu-open");return}this.burger&&(this.burger.menuOpen=!1)}closeNav(){this.menuOpen=!1,this.burger&&(this.burger.menuOpen=!1),this.demoteMenuToggle();const e=this.getExternalDrawerTarget();if(e){e.closeDrawer(),document.body.classList.remove("menu-open");return}this.menu&&(this.menu.closeDrawer(),document.body.classList.remove("menu-open"))}getMenuToggleElement(){return this.shadowRoot?.querySelector("esp-header-button.menu-toggle")??null}canPromoteMenuToggle(){const e=this.getMenuToggleElement();return!!e&&typeof e?.showPopover=="function"}setHeaderChromeInert(e){if(!e){for(const n of this.inertedHeaderChrome)n.inert=!1;this.inertedHeaderChrome=[];return}const t=this.menuContainer.value?.parentElement,o=this.getMenuToggleElement();if(!t||!o)return;const r=[];for(const n of t.querySelectorAll(":scope > section.brand, :scope > section.topbar"))r.push(n);const i=t.querySelector(":scope > section.buttons");for(const n of i?.children??[])if(!(!(n instanceof HTMLElement)||n===o)){if(n instanceof HTMLSlotElement){for(const d of n.assignedElements())d instanceof HTMLElement&&r.push(d);continue}r.push(n)}for(const n of r)n.inert||(n.inert=!0,this.inertedHeaderChrome.push(n))}promoteMenuToggle(){const e=this.getMenuToggleElement();if(!e||this.menuTogglePromoted||typeof e.showPopover!="function")return;const t=e.getBoundingClientRect();e.setAttribute("popover","manual"),Object.assign(e.style,{position:"fixed",inset:"auto",margin:"0",padding:"0",border:"0",background:"transparent",overflow:"visible"}),this.setPromotedTogglePosition(e,t.left,t.top,t.width,t.height);try{e.showPopover()}catch{e.removeAttribute("popover"),e.removeAttribute("style"),this.menu&&(this.menu.liftedCloseControl=null);return}this.menuTogglePromoted=!0,window.addEventListener("resize",this.handlePromotedViewportResize),this.menu&&(this.menu.liftedCloseControl=e),this.setHeaderChromeInert(!0)}positionPromotedToggle(){if(!this.menuTogglePromoted)return;const e=this.getMenuToggleElement(),t=this.shadowRoot?.querySelector("section.buttons");if(!e||!t)return;const o=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=getComputedStyle(t).direction==="rtl";this.setPromotedTogglePosition(e,i?o.left:o.right-r.width,o.top+(o.height-r.height)/2,r.width,r.height)}setPromotedTogglePosition(e,t,o,r,i){const n=R();e.style.left=`${Math.max(0,Math.min(t,n.width-r))}px`,e.style.top=`${Math.max(0,Math.min(o,n.height-i))}px`}demoteMenuToggle(){if(window.removeEventListener("resize",this.handlePromotedViewportResize),this.promotedToggleFrame.cancel(),this.menu?.liftedCloseControl&&(this.menu.liftedCloseControl=null),!this.menuTogglePromoted)return;this.menuTogglePromoted=!1,this.setHeaderChromeInert(!1);const e=this.getMenuToggleElement();if(e){try{e.hidePopover()}catch{}e.removeAttribute("popover"),e.removeAttribute("style")}}syncDrawerBrand(){if(!this.menu)return;const e=M({scheme:this.scheme,brandLogo:this.brandLogo,brandColor:this.brandColor,lightBrandLogo:this.lightBrandLogo,darkBrandLogo:this.darkBrandLogo,lightBrandColor:this.lightBrandColor,darkBrandColor:this.darkBrandColor}),t=e.brandLogo||this.brandText?{brandLogo:e.brandLogo,brandText:this.brandText,brandHref:this.brandHref,brandAlt:this.brandAlt,brandColor:e.brandColor}:null,o=JSON.stringify(t);o!==this.lastDrawerBrandKey&&(this.lastDrawerBrandKey=o,this.menu.drawerBrand=t)}get burger(){return this.menuButton.value??void 0}willUpdate(e){super.willUpdate(e),e.has("layout")&&!g.allowedValues.has(this.layout)&&(this.layout=g.defaultValue),e.has("brandAlign")&&!b.allowedValues.has(this.brandAlign)&&(this.brandAlign=b.defaultValue),e.has("brandWrap")&&!f.allowedValues.has(this.brandWrap)&&(this.brandWrap=f.defaultValue),e.has("menuDisplay")&&!v.allowedValues.has(this.menuDisplay)&&(this.menuDisplay=v.defaultValue),e.has("themeToggle")&&!w.allowedValues.has(this.themeToggle)&&(this.themeToggle=w.defaultValue)}firstUpdated(e){if(super.firstUpdated(e),!this.menuContainer.value)return;const r=(this.menuContainer.value.firstElementChild?.assignedElements()??[])[0];r instanceof p?(this.menu=r,this.addMenuDrawerListeners(),this.observeMenuChildren(),this.syncDrawerBrand()):r&&console.warn("<esp-header>: the menu slot expects an <esp-menu> element, received",r),this.observeMenuContainer(),this.syncExternalDrawerTarget(),this.syncMobileMenuQuery(),this.syncScrollListeners(),this.syncMenuLayout()}updated(e){super.updated(e),this.syncDrawerBrand(),(e.has("showBurger")||e.has("drawerTarget")||e.has("menuDisplay")||e.has("layout")||e.has("previewCollapseRequested"))&&(this.syncExternalDrawerTarget(),this.syncMenuLayout()),(e.has("mobileMenu")||e.has("menuTooLarge"))&&this.syncExternalDrawerControl(),e.has("scrollBehavior")?this.syncScrollListeners():(e.has("scrollThreshold")||e.has("dockOffset"))&&this.updateScrollState()}connectedCallback(){super.connectedCallback(),this.syncScrollListeners(),this.syncMobileMenuQuery(),this.addMenuDrawerListeners(),this.syncExternalDrawerTarget(),this.observeMenuContainer(),this.observeMenuChildren()}disconnectedCallback(){this.removeMenuDrawerListeners(),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-opened",this.onMenuDrawerOpened),this.externalDrawerTarget?.removeEventListener("esp-menu-drawer-closed",this.onMenuDrawerClosed),this.externalDrawerTarget instanceof p&&(this.externalDrawerTarget.hasExternalDrawerControl=!1),this.externalDrawerTarget=null,this.mobileMenuQuery?.removeEventListener("change",this.handleMobileMenuQueryChange),this.mobileMenuQuery=null,this.removeScrollListeners(),this.cancelScrollUpdate(),this.disconnectResizeObserver(),this.menuChildObserver?.disconnect(),this.menuChildObserver=null,this.demoteMenuToggle(),super.disconnectedCallback()}render(){const{menuOpen:e,menuTooLarge:t,mobileMenu:o}=this,r=this.menuDisplay!=="inline",i=r&&(this.showBurger||this.menuDisplay==="drawer"||this.layout==="minimal"||this.previewCollapseRequested),n=this.getScrollTokens(),d=n.has("progress"),m=M({scheme:this.scheme,brandLogo:this.brandLogo,brandColor:this.brandColor,lightBrandLogo:this.lightBrandLogo,darkBrandLogo:this.darkBrandLogo,lightBrandColor:this.lightBrandColor,darkBrandColor:this.darkBrandColor}),y={"--_esp-header-brand-color":m.brandColor||null,"--_esp-header-scroll-progress":String(this.scrollProgress)},S={"menu-open":e,"too-wide":r&&this.hasDrawerableContent()&&(t||o||i),[`layout-${this.layout}`]:!0,"is-scrolled":this.scrolled,"hide-on-scroll":this.hiddenByScroll,"scroll-compact":n.has("compact"),"scroll-elevate":n.has("elevate"),"scroll-transparent":n.has("transparent")||n.has("transparent-to-solid"),"scroll-collapse-topbar":n.has("collapse-topbar")},B=this.scheme==="dark"?"light":"dark";return x`
|
|
2
|
+
<header class=${O(S)} style=${_(y)}>
|
|
3
3
|
<section class="topbar">
|
|
4
4
|
<slot name="topbar"></slot>
|
|
5
5
|
</section>
|
|
6
6
|
|
|
7
7
|
<section class="brand">
|
|
8
8
|
<slot name="brand"
|
|
9
|
-
>${
|
|
9
|
+
>${z({brandLogo:m.brandLogo,brandText:this.brandText,brandHref:this.brandHref,brandAlt:this.brandAlt})}</slot
|
|
10
10
|
>
|
|
11
11
|
</section>
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ var a=function(h,e,t,s){var n=arguments.length,l=n<3?e:s===null?s=Object.getOwnP
|
|
|
19
19
|
${this.themeToggle==="visible"?x`<esp-header-button
|
|
20
20
|
class="theme-toggle"
|
|
21
21
|
icon=${this.scheme==="dark"?"sun":"moon"}
|
|
22
|
-
aria-label=${`Switch to ${
|
|
22
|
+
aria-label=${`Switch to ${B} mode`}
|
|
23
23
|
@esp-clicked=${this.toggleTheme}
|
|
24
24
|
></esp-header-button>`:T}
|
|
25
25
|
<esp-header-button
|
|
@@ -35,7 +35,7 @@ var a=function(h,e,t,s){var n=arguments.length,l=n<3?e:s===null?s=Object.getOwnP
|
|
|
35
35
|
</section>
|
|
36
36
|
${d?x`<div class="scroll-progress" aria-hidden="true"></div>`:T}
|
|
37
37
|
</header>
|
|
38
|
-
`}};
|
|
38
|
+
`}};s.styles=[...L.styles,k`
|
|
39
39
|
:host {
|
|
40
40
|
--_esp-header-current-height: var(--esp-header-height, calc(4.5 * var(--esp-size-small)));
|
|
41
41
|
|
|
@@ -492,4 +492,4 @@ var a=function(h,e,t,s){var n=arguments.length,l=n<3?e:s===null?s=Object.getOwnP
|
|
|
492
492
|
transition: none;
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
`],a([c()],
|
|
495
|
+
`],a([c()],s.prototype,"menuOpen",void 0),a([c()],s.prototype,"menuTooLarge",void 0),a([c()],s.prototype,"mobileMenu",void 0),a([c()],s.prototype,"scrolled",void 0),a([c()],s.prototype,"hiddenByScroll",void 0),a([c()],s.prototype,"scrollProgress",void 0),a([l({attribute:"show-burger",type:Boolean})],s.prototype,"showBurger",void 0),a([l({converter:g.converter,reflect:!0})],s.prototype,"layout",void 0),a([l({attribute:"brand-text",type:String})],s.prototype,"brandText",void 0),a([l({attribute:"brand-logo",type:String})],s.prototype,"brandLogo",void 0),a([l({attribute:"light-brand-logo",type:String})],s.prototype,"lightBrandLogo",void 0),a([l({attribute:"dark-brand-logo",type:String})],s.prototype,"darkBrandLogo",void 0),a([l({attribute:"brand-href",type:String})],s.prototype,"brandHref",void 0),a([l({attribute:"brand-alt",type:String})],s.prototype,"brandAlt",void 0),a([l({attribute:"brand-color",type:String})],s.prototype,"brandColor",void 0),a([l({attribute:"light-brand-color",type:String})],s.prototype,"lightBrandColor",void 0),a([l({attribute:"dark-brand-color",type:String})],s.prototype,"darkBrandColor",void 0),a([l({attribute:"brand-align",converter:b.converter,reflect:!0})],s.prototype,"brandAlign",void 0),a([l({attribute:"brand-wrap",converter:f.converter,reflect:!0})],s.prototype,"brandWrap",void 0),a([l({attribute:"menu-display",converter:v.converter,reflect:!0})],s.prototype,"menuDisplay",void 0),a([l({attribute:"theme-toggle",converter:w.converter,reflect:!0})],s.prototype,"themeToggle",void 0),a([l({attribute:"scroll-behavior",type:String})],s.prototype,"scrollBehavior",void 0),a([l({attribute:"scroll-threshold",type:Number})],s.prototype,"scrollThreshold",void 0),a([l({attribute:"dock-offset",type:Number})],s.prototype,"dockOffset",void 0),a([l({attribute:"drawer-target",type:String})],s.prototype,"drawerTarget",void 0),a([l({attribute:!1})],s.prototype,"previewCollapseRequested",void 0),a([l({attribute:"full-bleed-content",type:Boolean,reflect:!0})],s.prototype,"fullBleedContent",void 0),s=a([A("esp-header")],s);export{s as EspalierHeader};
|
|
@@ -51,7 +51,7 @@ export declare class EspalierHelpButton extends EspalierElementBase {
|
|
|
51
51
|
/** Forward focus to the composed native control. */
|
|
52
52
|
focus(options?: FocusOptions): void;
|
|
53
53
|
protected updated(changed: PropertyValues): void;
|
|
54
|
-
protected render():
|
|
54
|
+
protected render(): import("lit-html").TemplateResult<1> | typeof nothing;
|
|
55
55
|
static styles: import("lit").CSSResult[];
|
|
56
56
|
}
|
|
57
57
|
declare global {
|