@taprootio/espalier 7.1.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/custom-elements.json +8073 -5734
  3. package/dist/button/paint-registration.js +1 -0
  4. package/dist/cli/theme-check.js +2 -2
  5. package/dist/footer/paint-registration.js +1 -0
  6. package/dist/header/esp-header-button.js +6 -2
  7. package/dist/header/esp-header.js +8 -4
  8. package/dist/header/header-geometry-controller.js +1 -1
  9. package/dist/header/is-tall-header-paint.d.ts +7 -0
  10. package/dist/header/is-tall-header-paint.js +1 -0
  11. package/dist/header/paint-registration.js +1 -0
  12. package/dist/index.d.ts +2 -1
  13. package/dist/menu/esp-menu-group.js +8 -8
  14. package/dist/menu/esp-menu-item.js +8 -8
  15. package/dist/menu/esp-menu.js +10 -6
  16. package/dist/menu/navigation-focus-outline.js +8 -0
  17. package/dist/menu/navigation-paint.js +1 -0
  18. package/dist/menu/paint-registration.js +1 -0
  19. package/dist/shared/color-engine.js +1 -1
  20. package/dist/shared/composed-dom.js +1 -0
  21. package/dist/shared/configured-brand-color.js +1 -0
  22. package/dist/shared/configured-brand.js +5 -5
  23. package/dist/shared/css-named-colors.js +1 -0
  24. package/dist/shared/paint-catalog.d.ts +27 -0
  25. package/dist/shared/paint-catalog.js +1 -0
  26. package/dist/shared/paint-color.d.ts +25 -0
  27. package/dist/shared/paint-color.js +1 -0
  28. package/dist/shared/paint-fit.js +1 -0
  29. package/dist/shared/paint-identity.js +1 -0
  30. package/dist/shared/paint-types.d.ts +88 -0
  31. package/dist/shared/paint-types.js +0 -0
  32. package/dist/shared/theme-fit-report.d.ts +10 -2
  33. package/dist/shared/theme-fit-report.js +1 -1
  34. package/dist/shared/theme.d.ts +3 -24
  35. package/dist/shared/theme.js +1 -1
  36. package/dist/shared/token-pairings.d.ts +25 -0
  37. package/dist/shared/token-pairings.js +1 -0
  38. package/dist/shared/wcag-contrast.d.ts +14 -0
  39. package/dist/shared/wcag-contrast.js +1 -0
  40. package/dist/testing/index.d.ts +7 -0
  41. package/dist/testing/index.js +1 -0
  42. package/dist/testing/observe-paint.d.ts +29 -0
  43. package/dist/testing/observe-paint.iife.js +3 -0
  44. package/dist/testing/observe-paint.js +3 -0
  45. package/dist/testing/paint-bands.js +1 -0
  46. package/dist/testing/paint-coverage.d.ts +14 -0
  47. package/dist/testing/paint-coverage.js +1 -0
  48. package/dist/testing/paint-dom.js +1 -0
  49. package/dist/testing/svg-paint.js +1 -0
  50. package/package.json +6 -1
@@ -1,7 +1,7 @@
1
- var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(y,e,t,r);else for(var o=y.length-1;o>=0;o--)(i=y[o])&&(s=(n<3?i(s):n>3?i(e,t,s):i(e,t))||s);return n>3&&s&&Object.defineProperty(e,t,s),s},C;import{css as L,html as E,nothing as m}from"lit";import{customElement as _,eventOptions as H,property as h,state as S}from"lit/decorators.js";import{classMap as g}from"lit/directives/class-map.js";import{createRef as u,ref as p}from"lit/directives/ref.js";import{styleMap as z}from"lit/directives/style-map.js";import{EspalierElementBase as D}from"../shared/esp-element-base.js";import{ESP_EVENTS as x}from"../shared/events.js";import{getEspBus as I}from"../shared/bus-events.js";import{normalizePath as $,pathStartsWithSegment as N,pathsMatch as k}from"../shared/path-matching.js";import{renderConfiguredBrand as G}from"../shared/configured-brand.js";import{FOCUSABLE_SELECTOR as R,OverlayController as T}from"../shared/overlay-controller.js";import{SwipeRevealController as q}from"./swipe-reveal-controller.js";import"./esp-menu-item.js";import"./esp-menu-group.js";import"../burger/esp-burger.js";import{EspalierMenuItem as b}from"./esp-menu-item.js";import{EspalierMenuGroup as v}from"./esp-menu-group.js";import{COMPACT_VIEWPORT_MEDIA_QUERY as U}from"../shared/responsive.js";import{RafThrottle as A}from"../shared/raf-throttle.js";import{viewportSize as B}from"../shared/viewport.js";import{solveDrawerNestedFit as K}from"./drawer-nested-fit.js";import{collectMenuNodes as P,renderMenuNode as W,MENU_SOURCE_CHANGED as M,MENU_PRESENTATION_CHANGED as j,MENU_LAYOUT_CHANGED as Q,MENU_FIT_PROBE_STYLES as V}from"./menu-presentation.js";const X=new Set(["panel","full-screen"]),Y=new Set(["fade","slide-down","slide-up","slide-left","slide-right"]);let a=C=class extends D{ownsDrawerLock(){return this.isFullScreenDrawer}fullScreenInertAnchor(){return C.inertAnchorFor(this)}static inertAnchorFor(e){let t=e,r=e;for(;;){const n=r.parentElement;if(n){if(n.localName==="esp-page"||n.localName==="esp-root")return r;n===document.body&&(t=r),r=n;continue}const s=r.getRootNode();if(s instanceof ShadowRoot&&s.host instanceof HTMLElement){r=s.host;continue}return t}}constructor(){super(),this.itemsSlot=u(),this.railRef=u(),this.scrimRef=u(),this.drawerRef=u(),this.bus=I(),this.closeTransitionTimer=null,this.drawerGroupOpenOverrides=new Map,this.overlay=new T({host:this,getFocusTrapContainer:()=>this.drawerRef.value??null,getFocusScope:()=>this.fullScreenFocusScope(),getInertAnchor:()=>this.fullScreenInertAnchor(),promote:!1,scrollLock:{preserveScrollPosition:!0}}),this.fullScreenSession=!1,this.openedFullScreen=!1,this.drawerKeydownAttached=!1,this.nestedFitProbe=u(),this.nestedFitCapProbe=u(),this.nestedFitFloorProbe=u(),this.nestedFitPadProbe=u(),this.nestedFitTextProbe=u(),this.nestedFit=null,this.nestedFitMeasured=!1,this.nestedFitIdleHandle=null,this.nestedFitFallback=null,this.nestedFitResize=new A(()=>this.measureNestedFit()),this.nestedFitObserver=null,this.onNestedFitResize=()=>{this.headerNavigationOwned&&this.headerLayout.schedule(),this.drawerPresentation==="full-screen"&&this.nestedFitResize.schedule()},this.onNestedFitFontsLoaded=()=>{this.scheduleNestedFit(!0),this.headerNavigationOwned&&this.headerLayout.schedule()},this.onOverlayOpened=e=>{if(e===this.overlay||!this.drawerOpen)return;const t=this.drawerTrigger;this.drawerTrigger=null,t&&e.redirectFocusRestore(t),this.swipeController.closeForHandoff(),this.onDrawerTransitionEnd()},this._sliding=!1,this._mobileCollapsed=!1,this.verticalDrawerQuery=null,this.onVerticalDrawerChange=e=>this.setMobileCollapsed(e.matches),this.mode="horizontal",this.overflow="auto",this.side="left",this.drawerPresentation="panel",this.fullScreenTransition="fade",this.drawerBrand=null,this.liftedCloseControl=null,this.ariaLabel=null,this.autoExpand=!1,this.drawerOpen=!1,this.drawerShown=!1,this.drawerTransitioning=!1,this.drawerTrigger=null,this.headerEndOwner=null,this.promotedItems=new Set,this.observedHeaderRail=null,this.headerLayout=new A(()=>{this.headerNavigationOwned&&this.notifyHeaderLayout()}),this.headerFitObserver=new ResizeObserver(()=>this.headerLayout.schedule()),this.sourceObserver=null,this.onSourceChanged=e=>{const t=e.composedPath()[0];!(t instanceof Element)||!this.contains(t)||t.closest("esp-menu")!==this||(this.headerNavigationOwned||this.drawerOpen||this.drawerTransitioning)&&this.refreshHeaderSources()},this.hasExternalDrawerControl=!1,this.previewCollapseRequested=!1,this.getWidth=()=>{const e=this.railRef.value;return e?Math.max(e.scrollWidth,e.clientWidth):-1},this.onDrawerKeydown=e=>{!this.drawerOpen||!this.openedFullScreen||e.key==="Tab"&&this.overlay.trapFocus(e)},this.onDrawerTransitionEnd=e=>{e&&e.target!==this.drawerRef.value||(this.closeTransitionTimer&&(clearTimeout(this.closeTransitionTimer),this.closeTransitionTimer=null),this.drawerTransitioning=!1,this.drawerOpen||(this.hideDrawerPopover(),this.drawerGroupOpenOverrides.clear()))},this.handleDrawerCloseClick=()=>{this.closeDrawer()},this.swipeController=new q(this,this.side),this.swipeController.enabled=!1}get isFullScreenDrawer(){return X.has(this.drawerPresentation)?this.drawerPresentation==="full-screen":!1}get resolvedFullScreenTransition(){return Y.has(this.fullScreenTransition)?this.fullScreenTransition:"fade"}get sliding(){return this._sliding}set sliding(e){const t=this._sliding;this._sliding=e,this.syncSwipeEnabled(),this.propagateToItems(),this.requestUpdate("sliding",t)}get drawerSide(){return this.overflow==="right-drawer"?"right":this.overflow==="left-drawer"?"left":this.side}get drawerActive(){return this.mode==="drawer"||this._sliding||this.overflow==="left-drawer"||this.overflow==="right-drawer"||this.mode==="vertical"&&(this._mobileCollapsed||this.previewCollapseRequested)&&this.hasExternalDrawerControl}get headerDrawerActive(){return this.drawerActive||this.drawerOpen||this.drawerTransitioning}get headerNavigationOwned(){return this.mode==="horizontal"&&this.headerEndOwner===this.parentElement&&this.slot==="menu"&&this.isConnected}get headerEndNodes(){return this.headerNavigationOwned?P(this.getAssignedChildren(),void 0,{headerEndOnly:!0}):[]}getHeaderNavigationWidths(){return{main:this.railRef.value?.getBoundingClientRect().width??0}}syncHeaderEndSources(){const e=new Set(this.headerEndNodes.flatMap(t=>t.originalItem?[t.originalItem]:[]));for(const t of this.promotedItems)e.has(t)||t.setHeaderEndPromoted(!1);for(const t of this.getAssignedChildren())t instanceof b&&t.setHeaderEndPromoted(e.has(t));this.promotedItems=e}bindHeaderObservation(){const e=this.headerNavigationOwned?this.railRef.value??null:null;e!==this.observedHeaderRail&&(this.headerFitObserver.disconnect(),this.observedHeaderRail=e,e&&this.headerFitObserver.observe(e,{box:"border-box"})),e&&!this.sourceObserver?(this.sourceObserver=new MutationObserver(t=>{t.some(r=>this.isHeaderSourceMutation(r))&&this.refreshHeaderSources()}),this.sourceObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["header-end","url","appearance","style","class"]})):e||(this.sourceObserver?.disconnect(),this.sourceObserver=null)}isHeaderSourceMutation(e){const t=e.target;return t instanceof Element?t===this?!0:t.closest("esp-menu")!==this?!1:e.type==="attributes"?t.parentElement===this&&(t instanceof b||t instanceof v):t instanceof b||t instanceof v:!1}notifyHeaderPresentation(){this.dispatchEvent(new CustomEvent(j))}notifyHeaderLayout(){this.dispatchEvent(new CustomEvent(Q))}refreshHeaderSources(){this.syncHeaderEndSources(),this.requestUpdate(),this.headerNavigationOwned&&this.headerLayout.schedule()}get railMode(){return this.mode==="horizontal"?"horizontal":"vertical"}connectedCallback(){super.connectedCallback(),this.addEventListener(M,this.onSourceChanged),this.updateComplete.then(()=>{this.isConnected&&(this.propagateToItems(),this.bindHeaderObservation())}),this.getAttribute("slot")==="right"&&(this.side="right"),!this.verticalDrawerQuery&&typeof window<"u"&&"matchMedia"in window&&(this.verticalDrawerQuery=window.matchMedia(U),this._mobileCollapsed=this.verticalDrawerQuery.matches,this.verticalDrawerQuery.addEventListener("change",this.onVerticalDrawerChange)),this.syncSwipeEnabled(),T.addOpenListener(this.onOverlayOpened),window.addEventListener("resize",this.onNestedFitResize),typeof document<"u"&&document.fonts&&(document.fonts.addEventListener("loadingdone",this.onNestedFitFontsLoaded),document.fonts.ready.then(()=>{this.isConnected&&this.onNestedFitFontsLoaded()})),!this.nestedFitObserver&&typeof MutationObserver<"u"&&(this.nestedFitObserver=new MutationObserver(()=>this.scheduleNestedFit(!0)),this.nestedFitObserver.observe(this,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["label"]}))}disconnectedCallback(){this.removeEventListener(M,this.onSourceChanged),this.sourceObserver?.disconnect(),this.sourceObserver=null,this.headerFitObserver.disconnect(),this.headerEndOwner=null,this.observedHeaderRail=null,this.headerLayout.cancel();for(const e of this.promotedItems)e.setHeaderEndPromoted(!1);this.promotedItems.clear(),T.removeOpenListener(this.onOverlayOpened),window.removeEventListener("resize",this.onNestedFitResize),document.fonts?.removeEventListener("loadingdone",this.onNestedFitFontsLoaded),this.nestedFitObserver?.disconnect(),this.nestedFitObserver=null,this.nestedFitResize.cancel(),this.cancelNestedFitIdle(),this.nestedFitMeasured=!1,this.verticalDrawerQuery?.removeEventListener("change",this.onVerticalDrawerChange),this.verticalDrawerQuery=null,this.detachDrawerKeydown(),this.fullScreenSession=!1,super.disconnectedCallback()}setMobileCollapsed(e){e!==this._mobileCollapsed&&(this._mobileCollapsed=e,this.mode==="vertical"&&this.applyMobileCollapse())}applyMobileCollapse(){this.swipeController.direction=this.drawerSide,this.syncSwipeEnabled(),this.propagateToItems(),this.requestUpdate(),!this.drawerActive&&this.drawerOpen&&this.swipeController.close(!0)}firstUpdated(e){super.firstUpdated(e),this.propagateToItems(),this.scheduleNestedFit()}willUpdate(e){super.willUpdate(e),this.syncHeaderEndSources()}updated(e){super.updated(e),this.bindHeaderObservation(),["mode","overflow","headerEndOwner"].some(t=>e.has(t))&&this.notifyHeaderLayout(),["drawerOpen","drawerTransitioning","sliding","ariaLabel"].some(t=>e.has(t))&&this.notifyHeaderPresentation(),(e.has("mode")||e.has("overflow")||e.has("headerEndOwner")||e.has("side")||e.has("hasExternalDrawerControl")||e.has("previewCollapseRequested")||e.has("drawerOpen")||e.has("drawerTransitioning"))&&(this.swipeController.direction=this.drawerSide,this.syncSwipeEnabled(),this.propagateToItems(),!this.drawerActive&&this.drawerOpen&&this.swipeController.close(!0)),e.has("drawerPresentation")&&(this.nestedFitMeasured=!1,this.scheduleNestedFit()),this.drawerOpen&&this.openedFullScreen!==this.isFullScreenDrawer&&this.swipeController.close(!0),this.autoExpand&&(e.has("autoExpand")||e.has("mode")&&this.mode!=="horizontal")?this.expandToCurrentPage():this.mode==="horizontal"&&e.has("mode")&&this.closeHorizontalTopLevelGroups()}openDrawer(e){this.drawerActive&&(e?this.drawerTrigger=e:this.drawerOpen||(this.drawerTrigger=null),this.swipeController.open())}closeDrawer(){this.swipeController.close(!0)}toggleDrawer(e){this.drawerOpen?this.closeDrawer():this.openDrawer(e)}get isDrawerOpen(){return this.drawerOpen}syncSwipeEnabled(){this.swipeController.direction=this.drawerSide,this.swipeController.enabled=this.drawerActive}getAssignedChildren(){return this.itemsSlot.value?.assignedElements()??[]}propagateToItems(){const e=this.railMode;for(const t of this.getAssignedChildren())t instanceof b?(t.mode=e,t.depth=0,t.touchDevice=this.swipeController.isTouch):t instanceof v&&(t.mode=e,t.depth=0,t.touchDevice=this.swipeController.isTouch,t.scrollPanelEnabled=e==="horizontal"&&(this.headerNavigationOwned||this.overflow==="scroll")&&!this.headerDrawerActive)}handleSlotChange(){this.propagateToItems(),this.refreshHeaderSources(),this.scheduleNestedFit(!0)}scheduleNestedFit(e=!1){if(this.drawerPresentation!=="full-screen"){this.cancelNestedFitIdle(),this.nestedFit!==null&&(this.nestedFit=null);return}if(e&&(this.nestedFitMeasured=!1),e&&this.drawerShown){this.cancelNestedFitIdle(),this.nestedFitResize.schedule();return}if(this.nestedFitIdleHandle!==null||this.nestedFitFallback!==null)return;const t=()=>{this.nestedFitIdleHandle=null,this.nestedFitFallback=null,this.isConnected&&this.measureNestedFit()};typeof requestIdleCallback=="function"?this.nestedFitIdleHandle=requestIdleCallback(t,{timeout:2e3}):this.nestedFitFallback={stage:"frame",handle:requestAnimationFrame(()=>{this.nestedFitFallback={stage:"timeout",handle:window.setTimeout(t,0)}})}}cancelNestedFitIdle(){this.nestedFitIdleHandle!==null&&(cancelIdleCallback(this.nestedFitIdleHandle),this.nestedFitIdleHandle=null),this.nestedFitFallback!==null&&(this.nestedFitFallback.stage==="frame"?cancelAnimationFrame(this.nestedFitFallback.handle):window.clearTimeout(this.nestedFitFallback.handle),this.nestedFitFallback=null)}ensureNestedFitMeasured(){this.nestedFitMeasured||(this.cancelNestedFitIdle(),this.measureNestedFit())}collectNestedLabels(){const e=[];let t=!1;const r=(n,s)=>{for(const i of n){const o=s>0;i instanceof b?o&&e.push(i.label):i instanceof v&&(o&&(e.push(i.label),i.url&&(t=!0)),r(Array.from(i.children),s+1))}};return r(this.getAssignedChildren(),0),{labels:e,linkedGroup:t}}readNestedFitMetrics(e){const t=this.nestedFitCapProbe.value,r=this.nestedFitFloorProbe.value,n=this.nestedFitPadProbe.value,s=this.nestedFitTextProbe.value;if(!t||!r||!n||!s)return null;const i=parseFloat(getComputedStyle(t).fontSize),o=parseFloat(getComputedStyle(r).fontSize),d=getComputedStyle(n),c=parseFloat(d.paddingInlineStart),F=parseFloat(d.paddingInlineEnd);if(![i,o,c,F].every(w=>Number.isFinite(w)))return null;s.replaceChildren(...e.map(w=>{const O=document.createElement("span");return O.textContent=w,O}));const f=Array.from(s.children,w=>w.getBoundingClientRect().width);return s.replaceChildren(),{capPx:i,floorPx:o,paddingPx:c,smallPx:F,widths:f}}measureNestedFit(){if(!this.isConnected||this.drawerPresentation!=="full-screen")return;const{labels:e,linkedGroup:t}=this.collectNestedLabels();if(this.nestedFitMeasured=!0,e.length===0){this.nestedFit!==null&&(this.nestedFit=null);return}const r=this.readNestedFitMetrics(e);if(!r)return;const n=this.drawerRef.value,s=n&&this.drawerShown?n.getBoundingClientRect().width:0,i=s>0?s:B().width,o=t?2*(2*r.smallPx+4.5):0,d=i-2*r.paddingPx-o,c=K({capPx:r.capPx,floorPx:r.floorPx,availablePx:d,widestAtCapPx:Math.max(0,...r.widths)});this.nestedFit&&this.nestedFit.fontSizePx===c.fontSizePx&&this.nestedFit.wrap===c.wrap||(this.nestedFit=c)}onSwipeRevealChanged(e){e!==this.drawerOpen&&(this.drawerOpen=e,e?(this.openedFullScreen=this.isFullScreenDrawer,this.openedFullScreen&&this.ensureNestedFitMeasured(),this.drawerGroupOpenOverrides.clear(),this.bus.publish("close-popovers",{}),this.updateComplete.then(()=>this.showDrawerPopover())):(this.detachDrawerKeydown(),this.fullScreenSession&&(this.fullScreenSession=!1,this.overlay.close()),this.drawerShown=!1,this.drawerTransitioning=!0,this.updateComplete.then(()=>this.startCloseTransition()),requestAnimationFrame(()=>this.restoreDrawerTriggerFocus())),this.dispatchEvent(new CustomEvent(e?x.MENU_DRAWER_OPENED:x.MENU_DRAWER_CLOSED,{bubbles:!0,composed:!0})))}showDrawerPopover(){const e=this.scrimRef.value,t=this.drawerRef.value;if(!(!e||!t||!this.isConnected)){this.swipeController.drawerElement=t;try{this.openedFullScreen||e.showPopover(),t.showPopover()}catch{}this.dispatchEvent(new CustomEvent(x.MENU_DRAWER_PRESENTED,{bubbles:!0,composed:!0})),t.getBoundingClientRect(),requestAnimationFrame(()=>{!this.drawerOpen||!this.isConnected||(this.drawerTransitioning=!0,this.drawerShown=!0,this.openedFullScreen&&(this.fullScreenSession=!0,this.overlay.open(),this.attachDrawerKeydown(),this.updateComplete.then(()=>{this.drawerOpen&&this.overlay.moveFocusInto()})))})}}attachDrawerKeydown(){this.drawerKeydownAttached||(document.addEventListener("keydown",this.onDrawerKeydown),this.drawerKeydownAttached=!0)}detachDrawerKeydown(){this.drawerKeydownAttached&&(document.removeEventListener("keydown",this.onDrawerKeydown),this.drawerKeydownAttached=!1)}fullScreenFocusScope(){const e=this.drawerRef.value;if(!e)return[];const t=i=>i instanceof HTMLElement&&i.getClientRects().length>0,r=[],n=i=>{if(i.matches(R)&&t(i)&&r.push(i),i.shadowRoot)for(const o of i.shadowRoot.querySelectorAll(R))t(o)&&r.push(o)};for(const i of e.querySelectorAll("*"))if(n(i),i instanceof HTMLSlotElement)for(const o of i.assignedElements({flatten:!0})){n(o);for(const d of o.querySelectorAll("*"))n(d)}const s=this.liftedCloseControl;if(s?.isConnected){const i=s.shadowRoot?.querySelector("button")??s;t(i)&&r.push(i)}return r}static drawerTransitionMs(e){const t=getComputedStyle(e),r=o=>o.split(",").map(d=>d.trim()).filter(Boolean).map(d=>{const c=Number.parseFloat(d);return Number.isFinite(c)?d.endsWith("ms")?c:c*1e3:0}),n=r(t.transitionDuration),s=r(t.transitionDelay);let i=0;return n.forEach((o,d)=>{i=Math.max(i,o+(s[d%Math.max(s.length,1)]??0))}),i}startCloseTransition(){const e=this.drawerRef.value;if(!e){this.hideDrawerPopover();return}this.closeTransitionTimer&&clearTimeout(this.closeTransitionTimer);const t=C.drawerTransitionMs(e);if(t===0){this.onDrawerTransitionEnd();return}this.closeTransitionTimer=setTimeout(()=>{this.closeTransitionTimer=null,!this.drawerOpen&&this.drawerTransitioning&&this.onDrawerTransitionEnd()},t+50)}hideDrawerPopover(){const e=this.scrimRef.value,t=this.drawerRef.value;this.swipeController.drawerElement=null,t&&(t.style.cssText="");try{t?.hidePopover()}catch{}try{e?.hidePopover()}catch{}}restoreDrawerTriggerFocus(){const e=this.drawerTrigger;this.drawerTrigger=null,e?.isConnected&&e.focus({preventScroll:!0})}getAutoExpandedGroups(e=!0){const t=new Set;let r=null;for(const s of this.querySelectorAll("esp-menu-item")){const i=s.url||s.getAttribute("url");if(i&&k(i)){r=s;break}}if(!r)for(const s of this.querySelectorAll("esp-menu-group")){const i=s.url||s.getAttribute("url");if(i&&k(i)){r=s;break}}if(!r&&e){for(const s of this.querySelectorAll("esp-menu-group"))s.parentElement===this&&t.add(s);return t}if(!r)return t;r instanceof v&&t.add(r);let n=r.parentElement;for(;n&&n!==this;)n instanceof v&&t.add(n),n=n.parentElement;return t}isHorizontalTopLevelGroup(e){return e.mode==="horizontal"&&e.depth===0}groupUrlPrefixMatches(e){return N(location.pathname,e.urlPrefix)}groupPathMatches(e){if(this.groupUrlPrefixMatches(e))return!0;const t=e.url||e.getAttribute("url");return t?N(location.pathname,$(t)):!1}expandToCurrentPage(){const e=this.getAutoExpandedGroups(),t=this.querySelectorAll("esp-menu-group");for(const r of t)r.open=e.has(r)&&!this.isHorizontalTopLevelGroup(r)}closeHorizontalTopLevelGroups(){for(const e of this.querySelectorAll("esp-menu-group"))this.isHorizontalTopLevelGroup(e)&&(e.open=!1)}getDrawerAutoExpandedGroups(){return this.getAutoExpandedGroups(!1)}collectDrawerNodes(e){const t=this.getDrawerAutoExpandedGroups();return P(e,r=>this.drawerGroupOpenOverrides.get(r)??(r.open||t.has(r)||this.groupPathMatches(r)))}renderDrawerNode(e){return W(e,{mode:"drawer",sourceStyle:!0,fullScreen:this.openedFullScreen,itemClick:t=>this.handleDrawerItemClick(t),groupToggle:(t,r)=>{this.drawerGroupOpenOverrides.set(t,r),this.isHorizontalTopLevelGroup(t)||(t.open=r)}})}handleDrawerLinkClick(e){const t=e.composedPath().find(r=>r instanceof HTMLAnchorElement);!(t instanceof HTMLAnchorElement)||t.target.toLowerCase()!=="_blank"||setTimeout(()=>{e.defaultPrevented||this.closeDrawer()},0)}handleDrawerItemClick(e){e.dispatchEvent(new CustomEvent(x.CLICKED,{detail:{},bubbles:!0,composed:!0})),this.swipeController.close(!0)}render(){const e=this.drawerOpen||this.drawerTransitioning,t=this.headerDrawerActive,r={rail:!0,horizontal:this.railMode==="horizontal",vertical:this.railMode==="vertical",wrap:this.overflow==="wrap",scroll:this.overflow==="scroll","drawer-forced":this.drawerActive},n=e?this.openedFullScreen:this.isFullScreenDrawer,s={drawer:!0,"drawer-left":this.drawerSide==="left","drawer-right":this.drawerSide==="right","full-screen":n,[`transition-${this.resolvedFullScreenTransition}`]:n,transitioning:this.drawerTransitioning,open:this.drawerShown,"nested-wrap":n&&this.nestedFit?.wrap===!0},i={"--_esp-menu-drawer-nested-font-size":n&&this.nestedFit?`${this.nestedFit.fontSizePx}px`:null},o=e?this.collectDrawerNodes(this.getAssignedChildren()):[],d=this.ariaLabel??"Navigation",c={"--_esp-menu-drawer-brand-color":this.drawerBrand?.brandColor||null},F=n&&e?E`<div class=${g({"drawer-chrome":!0,"has-lifted-close":!!this.liftedCloseControl})}>
1
+ var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(y,e,t,r);else for(var o=y.length-1;o>=0;o--)(i=y[o])&&(s=(n<3?i(s):n>3?i(e,t,s):i(e,t))||s);return n>3&&s&&Object.defineProperty(e,t,s),s},C;import{css as L,html as E,nothing as m}from"lit";import{configuredBrandFocusOutline as _,insetNavigationFocusOutline as H}from"./navigation-focus-outline.js";import{customElement as I,eventOptions as $,property as h,state as S}from"lit/decorators.js";import{classMap as g}from"lit/directives/class-map.js";import{createRef as u,ref as p}from"lit/directives/ref.js";import{styleMap as z}from"lit/directives/style-map.js";import{EspalierElementBase as D}from"../shared/esp-element-base.js";import{ESP_EVENTS as x}from"../shared/events.js";import{getEspBus as G}from"../shared/bus-events.js";import{normalizePath as q,pathStartsWithSegment as N,pathsMatch as k}from"../shared/path-matching.js";import{renderConfiguredBrand as U}from"../shared/configured-brand.js";import{FOCUSABLE_SELECTOR as R,OverlayController as T}from"../shared/overlay-controller.js";import{SwipeRevealController as B}from"./swipe-reveal-controller.js";import"./esp-menu-item.js";import"./esp-menu-group.js";import"../burger/esp-burger.js";import{EspalierMenuItem as b}from"./esp-menu-item.js";import{EspalierMenuGroup as v}from"./esp-menu-group.js";import{COMPACT_VIEWPORT_MEDIA_QUERY as K}from"../shared/responsive.js";import{RafThrottle as A}from"../shared/raf-throttle.js";import{viewportSize as W}from"../shared/viewport.js";import{solveDrawerNestedFit as j}from"./drawer-nested-fit.js";import{collectMenuNodes as P,renderMenuNode as Q,MENU_SOURCE_CHANGED as M,MENU_PRESENTATION_CHANGED as V,MENU_LAYOUT_CHANGED as X,MENU_FIT_PROBE_STYLES as Y}from"./menu-presentation.js";const J=new Set(["panel","full-screen"]),Z=new Set(["fade","slide-down","slide-up","slide-left","slide-right"]);let a=C=class extends D{ownsDrawerLock(){return this.isFullScreenDrawer}fullScreenInertAnchor(){return C.inertAnchorFor(this)}static inertAnchorFor(e){let t=e,r=e;for(;;){const n=r.parentElement;if(n){if(n.localName==="esp-page"||n.localName==="esp-root")return r;n===document.body&&(t=r),r=n;continue}const s=r.getRootNode();if(s instanceof ShadowRoot&&s.host instanceof HTMLElement){r=s.host;continue}return t}}constructor(){super(),this.itemsSlot=u(),this.railRef=u(),this.scrimRef=u(),this.drawerRef=u(),this.bus=G(),this.closeTransitionTimer=null,this.drawerGroupOpenOverrides=new Map,this.overlay=new T({host:this,getFocusTrapContainer:()=>this.drawerRef.value??null,getFocusScope:()=>this.fullScreenFocusScope(),getInertAnchor:()=>this.fullScreenInertAnchor(),promote:!1,scrollLock:{preserveScrollPosition:!0}}),this.fullScreenSession=!1,this.openedFullScreen=!1,this.drawerKeydownAttached=!1,this.nestedFitProbe=u(),this.nestedFitCapProbe=u(),this.nestedFitFloorProbe=u(),this.nestedFitPadProbe=u(),this.nestedFitTextProbe=u(),this.nestedFit=null,this.nestedFitMeasured=!1,this.nestedFitIdleHandle=null,this.nestedFitFallback=null,this.nestedFitResize=new A(()=>this.measureNestedFit()),this.nestedFitObserver=null,this.onNestedFitResize=()=>{this.headerNavigationOwned&&this.headerLayout.schedule(),this.drawerPresentation==="full-screen"&&this.nestedFitResize.schedule()},this.onNestedFitFontsLoaded=()=>{this.scheduleNestedFit(!0),this.headerNavigationOwned&&this.headerLayout.schedule()},this.onOverlayOpened=e=>{if(e===this.overlay||!this.drawerOpen)return;const t=this.drawerTrigger;this.drawerTrigger=null,t&&e.redirectFocusRestore(t),this.swipeController.closeForHandoff(),this.onDrawerTransitionEnd()},this._sliding=!1,this._mobileCollapsed=!1,this.verticalDrawerQuery=null,this.onVerticalDrawerChange=e=>this.setMobileCollapsed(e.matches),this.mode="horizontal",this.overflow="auto",this.side="left",this.drawerPresentation="panel",this.fullScreenTransition="fade",this.drawerBrand=null,this.liftedCloseControl=null,this.ariaLabel=null,this.autoExpand=!1,this.drawerOpen=!1,this.drawerShown=!1,this.drawerTransitioning=!1,this.drawerTrigger=null,this.headerEndOwner=null,this.promotedItems=new Set,this.observedHeaderRail=null,this.headerLayout=new A(()=>{this.headerNavigationOwned&&this.notifyHeaderLayout()}),this.headerFitObserver=new ResizeObserver(()=>this.headerLayout.schedule()),this.sourceObserver=null,this.onSourceChanged=e=>{const t=e.composedPath()[0];!(t instanceof Element)||!this.contains(t)||t.closest("esp-menu")!==this||(this.headerNavigationOwned||this.drawerOpen||this.drawerTransitioning)&&this.refreshHeaderSources()},this.hasExternalDrawerControl=!1,this.previewCollapseRequested=!1,this.getWidth=()=>{const e=this.railRef.value;return e?Math.max(e.scrollWidth,e.clientWidth):-1},this.onDrawerKeydown=e=>{!this.drawerOpen||!this.openedFullScreen||e.key==="Tab"&&this.overlay.trapFocus(e)},this.onDrawerTransitionEnd=e=>{e&&e.target!==this.drawerRef.value||(this.closeTransitionTimer&&(clearTimeout(this.closeTransitionTimer),this.closeTransitionTimer=null),this.drawerTransitioning=!1,this.drawerOpen||(this.hideDrawerPopover(),this.drawerGroupOpenOverrides.clear()))},this.handleDrawerCloseClick=()=>{this.closeDrawer()},this.swipeController=new B(this,this.side),this.swipeController.enabled=!1}get isFullScreenDrawer(){return J.has(this.drawerPresentation)?this.drawerPresentation==="full-screen":!1}get resolvedFullScreenTransition(){return Z.has(this.fullScreenTransition)?this.fullScreenTransition:"fade"}get sliding(){return this._sliding}set sliding(e){const t=this._sliding;this._sliding=e,this.syncSwipeEnabled(),this.propagateToItems(),this.requestUpdate("sliding",t)}get drawerSide(){return this.overflow==="right-drawer"?"right":this.overflow==="left-drawer"?"left":this.side}get drawerActive(){return this.mode==="drawer"||this._sliding||this.overflow==="left-drawer"||this.overflow==="right-drawer"||this.mode==="vertical"&&(this._mobileCollapsed||this.previewCollapseRequested)&&this.hasExternalDrawerControl}get headerDrawerActive(){return this.drawerActive||this.drawerOpen||this.drawerTransitioning}get headerNavigationOwned(){return this.mode==="horizontal"&&this.headerEndOwner===this.parentElement&&this.slot==="menu"&&this.isConnected}get headerEndNodes(){return this.headerNavigationOwned?P(this.getAssignedChildren(),void 0,{headerEndOnly:!0}):[]}getHeaderNavigationWidths(){return{main:this.railRef.value?.getBoundingClientRect().width??0}}syncHeaderEndSources(){const e=new Set(this.headerEndNodes.flatMap(t=>t.originalItem?[t.originalItem]:[]));for(const t of this.promotedItems)e.has(t)||t.setHeaderEndPromoted(!1);for(const t of this.getAssignedChildren())t instanceof b&&t.setHeaderEndPromoted(e.has(t));this.promotedItems=e}bindHeaderObservation(){const e=this.headerNavigationOwned?this.railRef.value??null:null;e!==this.observedHeaderRail&&(this.headerFitObserver.disconnect(),this.observedHeaderRail=e,e&&this.headerFitObserver.observe(e,{box:"border-box"})),e&&!this.sourceObserver?(this.sourceObserver=new MutationObserver(t=>{t.some(r=>this.isHeaderSourceMutation(r))&&this.refreshHeaderSources()}),this.sourceObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["header-end","url","appearance","style","class"]})):e||(this.sourceObserver?.disconnect(),this.sourceObserver=null)}isHeaderSourceMutation(e){const t=e.target;return t instanceof Element?t===this?!0:t.closest("esp-menu")!==this?!1:e.type==="attributes"?t.parentElement===this&&(t instanceof b||t instanceof v):t instanceof b||t instanceof v:!1}notifyHeaderPresentation(){this.dispatchEvent(new CustomEvent(V))}notifyHeaderLayout(){this.dispatchEvent(new CustomEvent(X))}refreshHeaderSources(){this.syncHeaderEndSources(),this.requestUpdate(),this.headerNavigationOwned&&this.headerLayout.schedule()}get railMode(){return this.mode==="horizontal"?"horizontal":"vertical"}connectedCallback(){super.connectedCallback(),this.addEventListener(M,this.onSourceChanged),this.updateComplete.then(()=>{this.isConnected&&(this.propagateToItems(),this.bindHeaderObservation())}),this.getAttribute("slot")==="right"&&(this.side="right"),!this.verticalDrawerQuery&&typeof window<"u"&&"matchMedia"in window&&(this.verticalDrawerQuery=window.matchMedia(K),this._mobileCollapsed=this.verticalDrawerQuery.matches,this.verticalDrawerQuery.addEventListener("change",this.onVerticalDrawerChange)),this.syncSwipeEnabled(),T.addOpenListener(this.onOverlayOpened),window.addEventListener("resize",this.onNestedFitResize),typeof document<"u"&&document.fonts&&(document.fonts.addEventListener("loadingdone",this.onNestedFitFontsLoaded),document.fonts.ready.then(()=>{this.isConnected&&this.onNestedFitFontsLoaded()})),!this.nestedFitObserver&&typeof MutationObserver<"u"&&(this.nestedFitObserver=new MutationObserver(()=>this.scheduleNestedFit(!0)),this.nestedFitObserver.observe(this,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["label"]}))}disconnectedCallback(){this.removeEventListener(M,this.onSourceChanged),this.sourceObserver?.disconnect(),this.sourceObserver=null,this.headerFitObserver.disconnect(),this.headerEndOwner=null,this.observedHeaderRail=null,this.headerLayout.cancel();for(const e of this.promotedItems)e.setHeaderEndPromoted(!1);this.promotedItems.clear(),T.removeOpenListener(this.onOverlayOpened),window.removeEventListener("resize",this.onNestedFitResize),document.fonts?.removeEventListener("loadingdone",this.onNestedFitFontsLoaded),this.nestedFitObserver?.disconnect(),this.nestedFitObserver=null,this.nestedFitResize.cancel(),this.cancelNestedFitIdle(),this.nestedFitMeasured=!1,this.verticalDrawerQuery?.removeEventListener("change",this.onVerticalDrawerChange),this.verticalDrawerQuery=null,this.detachDrawerKeydown(),this.fullScreenSession=!1,super.disconnectedCallback()}setMobileCollapsed(e){e!==this._mobileCollapsed&&(this._mobileCollapsed=e,this.mode==="vertical"&&this.applyMobileCollapse())}applyMobileCollapse(){this.swipeController.direction=this.drawerSide,this.syncSwipeEnabled(),this.propagateToItems(),this.requestUpdate(),!this.drawerActive&&this.drawerOpen&&this.swipeController.close(!0)}firstUpdated(e){super.firstUpdated(e),this.propagateToItems(),this.scheduleNestedFit()}willUpdate(e){super.willUpdate(e),this.syncHeaderEndSources()}updated(e){super.updated(e),this.bindHeaderObservation(),["mode","overflow","headerEndOwner"].some(t=>e.has(t))&&this.notifyHeaderLayout(),["drawerOpen","drawerTransitioning","sliding","ariaLabel"].some(t=>e.has(t))&&this.notifyHeaderPresentation(),(e.has("mode")||e.has("overflow")||e.has("headerEndOwner")||e.has("side")||e.has("hasExternalDrawerControl")||e.has("previewCollapseRequested")||e.has("drawerOpen")||e.has("drawerTransitioning"))&&(this.swipeController.direction=this.drawerSide,this.syncSwipeEnabled(),this.propagateToItems(),!this.drawerActive&&this.drawerOpen&&this.swipeController.close(!0)),e.has("drawerPresentation")&&(this.nestedFitMeasured=!1,this.scheduleNestedFit()),this.drawerOpen&&this.openedFullScreen!==this.isFullScreenDrawer&&this.swipeController.close(!0),this.autoExpand&&(e.has("autoExpand")||e.has("mode")&&this.mode!=="horizontal")?this.expandToCurrentPage():this.mode==="horizontal"&&e.has("mode")&&this.closeHorizontalTopLevelGroups()}openDrawer(e){this.drawerActive&&(e?this.drawerTrigger=e:this.drawerOpen||(this.drawerTrigger=null),this.swipeController.open())}closeDrawer(){this.swipeController.close(!0)}toggleDrawer(e){this.drawerOpen?this.closeDrawer():this.openDrawer(e)}get isDrawerOpen(){return this.drawerOpen}syncSwipeEnabled(){this.swipeController.direction=this.drawerSide,this.swipeController.enabled=this.drawerActive}getAssignedChildren(){return this.itemsSlot.value?.assignedElements()??[]}propagateToItems(){const e=this.railMode;for(const t of this.getAssignedChildren())t instanceof b?(t.mode=e,t.depth=0,t.touchDevice=this.swipeController.isTouch):t instanceof v&&(t.mode=e,t.depth=0,t.touchDevice=this.swipeController.isTouch,t.scrollPanelEnabled=e==="horizontal"&&(this.headerNavigationOwned||this.overflow==="scroll")&&!this.headerDrawerActive)}handleSlotChange(){this.propagateToItems(),this.refreshHeaderSources(),this.scheduleNestedFit(!0)}scheduleNestedFit(e=!1){if(this.drawerPresentation!=="full-screen"){this.cancelNestedFitIdle(),this.nestedFit!==null&&(this.nestedFit=null);return}if(e&&(this.nestedFitMeasured=!1),e&&this.drawerShown){this.cancelNestedFitIdle(),this.nestedFitResize.schedule();return}if(this.nestedFitIdleHandle!==null||this.nestedFitFallback!==null)return;const t=()=>{this.nestedFitIdleHandle=null,this.nestedFitFallback=null,this.isConnected&&this.measureNestedFit()};typeof requestIdleCallback=="function"?this.nestedFitIdleHandle=requestIdleCallback(t,{timeout:2e3}):this.nestedFitFallback={stage:"frame",handle:requestAnimationFrame(()=>{this.nestedFitFallback={stage:"timeout",handle:window.setTimeout(t,0)}})}}cancelNestedFitIdle(){this.nestedFitIdleHandle!==null&&(cancelIdleCallback(this.nestedFitIdleHandle),this.nestedFitIdleHandle=null),this.nestedFitFallback!==null&&(this.nestedFitFallback.stage==="frame"?cancelAnimationFrame(this.nestedFitFallback.handle):window.clearTimeout(this.nestedFitFallback.handle),this.nestedFitFallback=null)}ensureNestedFitMeasured(){this.nestedFitMeasured||(this.cancelNestedFitIdle(),this.measureNestedFit())}collectNestedLabels(){const e=[];let t=!1;const r=(n,s)=>{for(const i of n){const o=s>0;i instanceof b?o&&e.push(i.label):i instanceof v&&(o&&(e.push(i.label),i.url&&(t=!0)),r(Array.from(i.children),s+1))}};return r(this.getAssignedChildren(),0),{labels:e,linkedGroup:t}}readNestedFitMetrics(e){const t=this.nestedFitCapProbe.value,r=this.nestedFitFloorProbe.value,n=this.nestedFitPadProbe.value,s=this.nestedFitTextProbe.value;if(!t||!r||!n||!s)return null;const i=parseFloat(getComputedStyle(t).fontSize),o=parseFloat(getComputedStyle(r).fontSize),d=getComputedStyle(n),c=parseFloat(d.paddingInlineStart),F=parseFloat(d.paddingInlineEnd);if(![i,o,c,F].every(w=>Number.isFinite(w)))return null;s.replaceChildren(...e.map(w=>{const O=document.createElement("span");return O.textContent=w,O}));const f=Array.from(s.children,w=>w.getBoundingClientRect().width);return s.replaceChildren(),{capPx:i,floorPx:o,paddingPx:c,smallPx:F,widths:f}}measureNestedFit(){if(!this.isConnected||this.drawerPresentation!=="full-screen")return;const{labels:e,linkedGroup:t}=this.collectNestedLabels();if(this.nestedFitMeasured=!0,e.length===0){this.nestedFit!==null&&(this.nestedFit=null);return}const r=this.readNestedFitMetrics(e);if(!r)return;const n=this.drawerRef.value,s=n&&this.drawerShown?n.getBoundingClientRect().width:0,i=s>0?s:W().width,o=t?2*(2*r.smallPx+4.5):0,d=i-2*r.paddingPx-o,c=j({capPx:r.capPx,floorPx:r.floorPx,availablePx:d,widestAtCapPx:Math.max(0,...r.widths)});this.nestedFit&&this.nestedFit.fontSizePx===c.fontSizePx&&this.nestedFit.wrap===c.wrap||(this.nestedFit=c)}onSwipeRevealChanged(e){e!==this.drawerOpen&&(this.drawerOpen=e,e?(this.openedFullScreen=this.isFullScreenDrawer,this.openedFullScreen&&this.ensureNestedFitMeasured(),this.drawerGroupOpenOverrides.clear(),this.bus.publish("close-popovers",{}),this.updateComplete.then(()=>this.showDrawerPopover())):(this.detachDrawerKeydown(),this.fullScreenSession&&(this.fullScreenSession=!1,this.overlay.close()),this.drawerShown=!1,this.drawerTransitioning=!0,this.updateComplete.then(()=>this.startCloseTransition()),requestAnimationFrame(()=>this.restoreDrawerTriggerFocus())),this.dispatchEvent(new CustomEvent(e?x.MENU_DRAWER_OPENED:x.MENU_DRAWER_CLOSED,{bubbles:!0,composed:!0})))}showDrawerPopover(){const e=this.scrimRef.value,t=this.drawerRef.value;if(!(!e||!t||!this.isConnected)){this.swipeController.drawerElement=t;try{this.openedFullScreen||e.showPopover(),t.showPopover()}catch{}this.dispatchEvent(new CustomEvent(x.MENU_DRAWER_PRESENTED,{bubbles:!0,composed:!0})),t.getBoundingClientRect(),requestAnimationFrame(()=>{!this.drawerOpen||!this.isConnected||(this.drawerTransitioning=!0,this.drawerShown=!0,this.openedFullScreen&&(this.fullScreenSession=!0,this.overlay.open(),this.attachDrawerKeydown(),this.updateComplete.then(()=>{this.drawerOpen&&this.overlay.moveFocusInto()})))})}}attachDrawerKeydown(){this.drawerKeydownAttached||(document.addEventListener("keydown",this.onDrawerKeydown),this.drawerKeydownAttached=!0)}detachDrawerKeydown(){this.drawerKeydownAttached&&(document.removeEventListener("keydown",this.onDrawerKeydown),this.drawerKeydownAttached=!1)}fullScreenFocusScope(){const e=this.drawerRef.value;if(!e)return[];const t=i=>i instanceof HTMLElement&&i.getClientRects().length>0,r=[],n=i=>{if(i.matches(R)&&t(i)&&r.push(i),i.shadowRoot)for(const o of i.shadowRoot.querySelectorAll(R))t(o)&&r.push(o)};for(const i of e.querySelectorAll("*"))if(n(i),i instanceof HTMLSlotElement)for(const o of i.assignedElements({flatten:!0})){n(o);for(const d of o.querySelectorAll("*"))n(d)}const s=this.liftedCloseControl;if(s?.isConnected){const i=s.shadowRoot?.querySelector("button")??s;t(i)&&r.push(i)}return r}static drawerTransitionMs(e){const t=getComputedStyle(e),r=o=>o.split(",").map(d=>d.trim()).filter(Boolean).map(d=>{const c=Number.parseFloat(d);return Number.isFinite(c)?d.endsWith("ms")?c:c*1e3:0}),n=r(t.transitionDuration),s=r(t.transitionDelay);let i=0;return n.forEach((o,d)=>{i=Math.max(i,o+(s[d%Math.max(s.length,1)]??0))}),i}startCloseTransition(){const e=this.drawerRef.value;if(!e){this.hideDrawerPopover();return}this.closeTransitionTimer&&clearTimeout(this.closeTransitionTimer);const t=C.drawerTransitionMs(e);if(t===0){this.onDrawerTransitionEnd();return}this.closeTransitionTimer=setTimeout(()=>{this.closeTransitionTimer=null,!this.drawerOpen&&this.drawerTransitioning&&this.onDrawerTransitionEnd()},t+50)}hideDrawerPopover(){const e=this.scrimRef.value,t=this.drawerRef.value;this.swipeController.drawerElement=null,t&&(t.style.cssText="");try{t?.hidePopover()}catch{}try{e?.hidePopover()}catch{}}restoreDrawerTriggerFocus(){const e=this.drawerTrigger;this.drawerTrigger=null,e?.isConnected&&e.focus({preventScroll:!0})}getAutoExpandedGroups(e=!0){const t=new Set;let r=null;for(const s of this.querySelectorAll("esp-menu-item")){const i=s.url||s.getAttribute("url");if(i&&k(i)){r=s;break}}if(!r)for(const s of this.querySelectorAll("esp-menu-group")){const i=s.url||s.getAttribute("url");if(i&&k(i)){r=s;break}}if(!r&&e){for(const s of this.querySelectorAll("esp-menu-group"))s.parentElement===this&&t.add(s);return t}if(!r)return t;r instanceof v&&t.add(r);let n=r.parentElement;for(;n&&n!==this;)n instanceof v&&t.add(n),n=n.parentElement;return t}isHorizontalTopLevelGroup(e){return e.mode==="horizontal"&&e.depth===0}groupUrlPrefixMatches(e){return N(location.pathname,e.urlPrefix)}groupPathMatches(e){if(this.groupUrlPrefixMatches(e))return!0;const t=e.url||e.getAttribute("url");return t?N(location.pathname,q(t)):!1}expandToCurrentPage(){const e=this.getAutoExpandedGroups(),t=this.querySelectorAll("esp-menu-group");for(const r of t)r.open=e.has(r)&&!this.isHorizontalTopLevelGroup(r)}closeHorizontalTopLevelGroups(){for(const e of this.querySelectorAll("esp-menu-group"))this.isHorizontalTopLevelGroup(e)&&(e.open=!1)}getDrawerAutoExpandedGroups(){return this.getAutoExpandedGroups(!1)}collectDrawerNodes(e){const t=this.getDrawerAutoExpandedGroups();return P(e,r=>this.drawerGroupOpenOverrides.get(r)??(r.open||t.has(r)||this.groupPathMatches(r)))}renderDrawerNode(e){return Q(e,{mode:"drawer",sourceStyle:!0,fullScreen:this.openedFullScreen,itemClick:t=>this.handleDrawerItemClick(t),groupToggle:(t,r)=>{this.drawerGroupOpenOverrides.set(t,r),this.isHorizontalTopLevelGroup(t)||(t.open=r)}})}handleDrawerLinkClick(e){const t=e.composedPath().find(r=>r instanceof HTMLAnchorElement);!(t instanceof HTMLAnchorElement)||t.target.toLowerCase()!=="_blank"||setTimeout(()=>{e.defaultPrevented||this.closeDrawer()},0)}handleDrawerItemClick(e){e.dispatchEvent(new CustomEvent(x.CLICKED,{detail:{},bubbles:!0,composed:!0})),this.swipeController.close(!0)}render(){const e=this.drawerOpen||this.drawerTransitioning,t=this.headerDrawerActive,r={rail:!0,horizontal:this.railMode==="horizontal",vertical:this.railMode==="vertical",wrap:this.overflow==="wrap",scroll:this.overflow==="scroll","drawer-forced":this.drawerActive},n=e?this.openedFullScreen:this.isFullScreenDrawer,s={drawer:!0,"drawer-left":this.drawerSide==="left","drawer-right":this.drawerSide==="right","full-screen":n,[`transition-${this.resolvedFullScreenTransition}`]:n,transitioning:this.drawerTransitioning,open:this.drawerShown,"nested-wrap":n&&this.nestedFit?.wrap===!0},i={"--_esp-menu-drawer-nested-font-size":n&&this.nestedFit?`${this.nestedFit.fontSizePx}px`:null},o=e?this.collectDrawerNodes(this.getAssignedChildren()):[],d=this.ariaLabel??"Navigation",c={"--_esp-menu-drawer-brand-color":this.drawerBrand?.brandColor||null},F=n&&e?E`<div class=${g({"drawer-chrome":!0,"has-lifted-close":!!this.liftedCloseControl})}>
2
2
  <div class="drawer-brand" style=${z(c)}>
3
3
  <slot name="drawer-brand"
4
- >${this.drawerBrand?G(this.drawerBrand):m}</slot
4
+ >${this.drawerBrand?U(this.drawerBrand):m}</slot
5
5
  >
6
6
  </div>
7
7
  ${this.liftedCloseControl?m:E`
@@ -51,7 +51,7 @@ var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnP
51
51
  <span class="nested-fit-pad" ${p(this.nestedFitPadProbe)}>&#8203;</span>
52
52
  <div class="nested-fit-text" ${p(this.nestedFitTextProbe)}></div>
53
53
  </div>`:m}
54
- `}};a.styles=[...D.styles,V,L`
54
+ `}};a.styles=[...D.styles,Y,L`
55
55
  :host {
56
56
  display: block;
57
57
  min-width: 0;
@@ -308,6 +308,10 @@ var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnP
308
308
  text-decoration: none;
309
309
  }
310
310
 
311
+ .drawer-brand a.configured-brand:focus-visible {
312
+ ${_}
313
+ }
314
+
311
315
  .drawer-brand .brand-logo {
312
316
  width: auto;
313
317
  height: var(--esp-menu-drawer-brand-logo-size, calc(3 * var(--esp-size-medium)));
@@ -331,8 +335,8 @@ var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnP
331
335
  }
332
336
 
333
337
  .drawer-close:focus-visible {
334
- outline: 2px solid var(--esp-color-link);
335
- outline-offset: -2px;
338
+ ${H}
339
+ outline-color: var(--esp-color-link);
336
340
  }
337
341
 
338
342
 
@@ -435,4 +439,4 @@ var l=function(y,e,t,r){var n=arguments.length,s=n<3?e:r===null?r=Object.getOwnP
435
439
  transition: none;
436
440
  }
437
441
  }
438
- `],l([S()],a.prototype,"nestedFit",void 0),l([h({type:String,reflect:!0})],a.prototype,"mode",void 0),l([h({type:String,reflect:!0})],a.prototype,"overflow",void 0),l([h({type:String,reflect:!0})],a.prototype,"side",void 0),l([h({attribute:"drawer-presentation",type:String,reflect:!0})],a.prototype,"drawerPresentation",void 0),l([h({attribute:"full-screen-transition",type:String,reflect:!0})],a.prototype,"fullScreenTransition",void 0),l([h({attribute:!1})],a.prototype,"drawerBrand",void 0),l([h({attribute:!1})],a.prototype,"liftedCloseControl",void 0),l([h({attribute:"aria-label",type:String})],a.prototype,"ariaLabel",void 0),l([h({type:Boolean,attribute:"auto-expand"})],a.prototype,"autoExpand",void 0),l([h({type:Boolean})],a.prototype,"sliding",null),l([S()],a.prototype,"drawerOpen",void 0),l([S()],a.prototype,"drawerShown",void 0),l([S()],a.prototype,"drawerTransitioning",void 0),l([h({attribute:!1})],a.prototype,"headerEndOwner",void 0),l([h({attribute:!1})],a.prototype,"hasExternalDrawerControl",void 0),l([h({attribute:!1})],a.prototype,"previewCollapseRequested",void 0),l([H({capture:!0})],a.prototype,"handleDrawerLinkClick",null),a=C=l([_("esp-menu")],a);export{a as EspalierMenu};
442
+ `],l([S()],a.prototype,"nestedFit",void 0),l([h({type:String,reflect:!0})],a.prototype,"mode",void 0),l([h({type:String,reflect:!0})],a.prototype,"overflow",void 0),l([h({type:String,reflect:!0})],a.prototype,"side",void 0),l([h({attribute:"drawer-presentation",type:String,reflect:!0})],a.prototype,"drawerPresentation",void 0),l([h({attribute:"full-screen-transition",type:String,reflect:!0})],a.prototype,"fullScreenTransition",void 0),l([h({attribute:!1})],a.prototype,"drawerBrand",void 0),l([h({attribute:!1})],a.prototype,"liftedCloseControl",void 0),l([h({attribute:"aria-label",type:String})],a.prototype,"ariaLabel",void 0),l([h({type:Boolean,attribute:"auto-expand"})],a.prototype,"autoExpand",void 0),l([h({type:Boolean})],a.prototype,"sliding",null),l([S()],a.prototype,"drawerOpen",void 0),l([S()],a.prototype,"drawerShown",void 0),l([S()],a.prototype,"drawerTransitioning",void 0),l([h({attribute:!1})],a.prototype,"headerEndOwner",void 0),l([h({attribute:!1})],a.prototype,"hasExternalDrawerControl",void 0),l([h({attribute:!1})],a.prototype,"previewCollapseRequested",void 0),l([$({capture:!0})],a.prototype,"handleDrawerLinkClick",null),a=C=l([I("esp-menu")],a);export{a as EspalierMenu};
@@ -0,0 +1,8 @@
1
+ import{css as o}from"lit";const r=o`
2
+ outline: 2px solid currentColor;
3
+ outline-offset: -2px;
4
+ `,i=o`
5
+ border-radius: var(--esp-size-border-radius);
6
+ outline: 2px solid var(--esp-color-link);
7
+ outline-offset: 3px;
8
+ `;export{i as configuredBrandFocusOutline,r as insetNavigationFocusOutline};
@@ -0,0 +1 @@
1
+ import{composedParent as t}from"../shared/composed-dom.js";function o(n,e){for(let r=n;r;r=t(r))if(r.matches(e))return r;return null}function a(n){const e=o(n,"nav.drawer");return e?e.classList.contains("full-screen")?"full-screen":"panel":o(n,".is-horizontal > .group-items")?"inline-panel":"inline"}function u(n,e){return n==="inline"?e:`${n}-${e}`}function c(n){switch(n){case"inline":case"inline-panel":return["inlineNav"];case"panel":case"full-screen":return[`drawer:${n}`]}}const s=["rest","hover","focus","hover-focus"],l=n=>n==="hover"||n==="hover-focus",f=n=>n==="focus"||n==="hover-focus";function p(n,e){return n.ownerDocument.defaultView?.getComputedStyle(n).getPropertyValue(e).trim()||void 0}export{s as PAINT_INTERACTIONS,o as closestPaintElement,p as configuredBrandColor,f as isPaintFocus,l as isPaintHover,c as navigationPaintFlags,a as navigationPaintPlacement,u as navigationPaintState};
@@ -0,0 +1 @@
1
+ import{TOKEN_PAIRINGS as M}from"../shared/token-pairings.js";import{PAINT_INTERACTIONS as k,closestPaintElement as d,configuredBrandColor as R,isPaintFocus as b,isPaintHover as P,navigationPaintFlags as H,navigationPaintPlacement as I,navigationPaintState as l}from"./navigation-paint.js";const T=M.linkHover.bg,B="headingsHover",_=["inline","inline-panel","panel","full-screen"];function w(n,e){switch(n){case"inline":return{...e,depth:"top-level"};case"inline-panel":return{...e,depth:"nested"};default:return e}}const q=({element:n,source:e})=>{const r=d(n,".item:not(.button-appearance)"),a=r&&d(r,"esp-menu-item");if(!r||!a||!d(a,"esp-header"))return;const t=r.querySelector(":scope > :is(a, button, [aria-current=page])");if(!t)return;const i=t.matches("[aria-current=page]"),o=I(r),s=o!=="inline"&&r.matches(":hover,:focus-within"),c=g=>i?l(o,s?"current-hover":"current"):l(o,s&&g==="rest"?"row-active":g);if(e==="shadow")return i&&n===r?{element:"nav-current-indicator",owner:t,state:c}:!i&&n===t?{element:"nav-hover-indicator",owner:t,state:c}:void 0;if((e==="fill"||e==="stroke")&&d(n,".icon-area"))return{element:"nav-item-icon",owner:t,state:c};if(e==="outline"&&n===t||e==="text"&&d(n,'[part="menu-text"]'))return{element:t.matches("button")?"nav-item":"nav-link",owner:t,state:c}},F=({element:n,source:e})=>{const r=d(n,".group-header"),a=r&&d(r,"esp-menu-group");if(!r||!a||!d(a,"esp-header"))return;const t=I(r),i=(e==="fill"||e==="stroke")&&d(n,".group-icon");if(i){const u=r.querySelector(".group-toggle");return u?{element:"nav-group-icon",owner:u,state:v=>l(t,i.matches(":hover")?b(v)?"hover-focus":"hover":v)}:void 0}const o=d(n,".group-link, .group-toggle, [aria-current=page]");if(!o)return;const s=o.matches("[aria-current=page]"),c=(t==="panel"||t==="inline-panel")&&r.matches(":hover,:focus-within"),g=u=>s?l(t,c?"current-row-active":"current"):l(t,c&&u==="rest"?"row-active":u);if(e==="shape"&&n.matches(".indicator"))return{element:"nav-group-disclosure",owner:o,state:g};if(e==="text"&&d(n,".group-label-text"))return{element:"nav-group-label",owner:o,state:g};if(e==="outline"&&n===o)return{element:"nav-group-control",owner:o,state:g}},L=({element:n,source:e})=>{const r=d(n,".drawer-brand .configured-brand");if(!r||!d(r,"esp-header"))return;const a=I(r),t=r.matches("a[href]"),i=o=>l(a,t?o:"rest");if(e==="outline"&&n===r&&t)return{element:"drawer-brand-link",owner:r,state:i};if(e==="text"&&d(n,".brand-text"))return{element:"drawer-brand-text",owner:r,state:i,brandColor:R(r,"--_esp-menu-drawer-brand-color")}};function O(n){const e=H(n),r=n==="inline",a=n==="full-screen",t=r?"layer2":"layer1",i=w(n,{kind:"plain",anchor:!0}),o=w(n,{kind:"plain",anchor:!1}),s=[!0,!1].flatMap(u=>{const v=u?"nav-link":"nav-item",A=u?i:o;return(r?k:[...k,"row-active"]).flatMap(p=>{const m=p==="row-active",h=!m&&P(p),N=!m&&b(p),S=h||N||m,C=u&&h?"linkHover":!r&&S?"headingsHover":"text",E=u&&h&&!r&&!a?T:!a&&S?"layer2":t,G=l(n,p),f={element:v,foreground:C,background:E,state:G,kind:"text",flags:e,navigation:A},x={...f,element:"nav-item-icon",kind:"graphic",background:"layer2",navigation:{...A,icon:!0}};if(!N)return[f,x];const y={...f,foreground:"link",kind:"ring"};return r&&h?[f,x,y,{...y,background:B}]:[f,x,y]})}),c={element:"nav-link",foreground:"link",background:a?"layer1":"layer2",state:l(n,"current"),kind:"text",flags:e,navigation:w(n,{kind:"plain",canBeCurrent:!0})},g={...c,element:"nav-item-icon",kind:"graphic",background:"layer2",navigation:{...c.navigation,icon:!0}};return s.push(c,g),r?s.push({element:"nav-hover-indicator",foreground:B,background:"layer2",state:"hover",kind:"graphic",flags:e,navigation:{kind:"plain",depth:"top-level"}},{...c,element:"nav-current-indicator",kind:"graphic",flags:[...e,"headerPaint:standard"]}):s.push({...c,foreground:"headingsHover",state:l(n,"current-hover")},{...g,foreground:"headingsHover",state:l(n,"current-hover")}),s}function z(n){const e=H(n),r=w(n,{kind:"group"}),a=o=>n==="full-screen"?"layer1":n==="inline"||o?"layer2":"layer1",t={element:"nav-group-label",foreground:"link",background:a(!1),state:l(n,"current"),kind:"text",flags:e,navigation:{...r,canBeCurrent:!0}},i=k.flatMap(o=>{const s=b(o),c=a(s||P(o)),g=l(n,o),u={foreground:"text",background:c,state:g,flags:e,navigation:r},v=[{...u,element:"nav-group-label",kind:"text"},{...u,element:"nav-group-disclosure",kind:"graphic"},{...u,element:"nav-group-icon",kind:"graphic",background:"layer2",navigation:{...r,icon:!0}}];return s&&v.push({...u,element:"nav-group-control",foreground:"link",kind:"ring"}),v});if(i.push(t),n==="inline-panel"||n==="panel"){const o=a(!0),s={foreground:"text",background:o,state:l(n,"row-active"),flags:e,navigation:r};i.push({...s,element:"nav-group-label",kind:"text"},{...s,element:"nav-group-disclosure",kind:"graphic"},{...t,background:o,state:l(n,"current-row-active")})}return i}const J={entriesByRole:{header:[..._.flatMap(n=>[...O(n),...z(n)]),...k.flatMap(n=>{const e=l("full-screen",n),r=H("full-screen"),a=b(n),t=P(n),i={element:"drawer-brand-text",foreground:"brand-color",background:t?T:"layer1",state:e,kind:"text",flags:[...r,"brandText",...t||a?["brandLink"]:[]]};return a?[i,{element:"drawer-brand-link",foreground:"link",background:"layer1",state:e,kind:"ring",flags:[...r,"brandLink"]}]:[i]})]},targets:{header:[q,F,L]}};export{J as menuPaintRegistration};
@@ -1 +1 @@
1
- const G=Math.PI/180,h=1e-4,X=50,m="[+-]?(?:\\d+|\\d*\\.\\d+)(?:[eE][+-]?\\d+)?",i="[\\t\\n\\f\\r ]",y=new RegExp(i+"*,"+i+"*"),H=new RegExp(i+"+");function S(t){return t.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g,"")}const b={"":1,deg:1,grad:.9,rad:180/Math.PI,turn:360},U=.4,V=new RegExp("^oklch\\("+i+"*("+m+")(%?)"+i+"+("+m+")(%?)"+i+"+("+m+")(deg|grad|rad|turn)?"+i+"*\\)$","i");function T(t){const n=t.h*G;return{L:t.l,a:t.c*Math.cos(n),b:t.c*Math.sin(n)}}function W(t){const n=t.L+.3963377774*t.a+.2158037573*t.b,r=t.L-.1055613458*t.a-.0638541728*t.b,e=t.L-.0894841775*t.a-1.291485548*t.b,o=n*n*n,u=r*r*r,c=e*e*e;return{r:4.0767416621*o-3.3077115913*u+.2309699292*c,g:-1.2684380046*o+2.6097574011*u-.3413193965*c,b:-.0041960863*o-.7034186147*u+1.707614701*c}}function C(t){return t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055}function z(t){return{r:C(t.r),g:C(t.g),b:C(t.b)}}function Y(t){return t.r>=-h&&t.r<=1+h&&t.g>=-h&&t.g<=1+h&&t.b>=-h&&t.b<=1+h}function x(t){return Math.max(0,Math.min(1,t))}function q(t){const n=S(t).match(V);if(!n)return null;let r=parseFloat(n[1]);n[2]==="%"&&(r/=100);let e=parseFloat(n[3]);n[4]==="%"&&(e=e/100*U);const o=parseFloat(n[5])*b[(n[6]??"").toLowerCase()];return!isFinite(r)||!isFinite(e)||!isFinite(o)?null:{l:Math.max(0,Math.min(1,r)),c:Math.max(0,e),h:(o%360+360)%360}}function st(t){const n=p(t.l,6),r=p(t.c,6),e=p((t.h%360+360)%360,4);return`oklch(${n} ${r} ${e})`}function g(t){return z(W(T(t)))}function A(t){return Y(g(t))}function M(t){if(t.c<=h||A(t))return{...t};let n=0,r=t.c,e={...t};for(let o=0;o<X;o++){const u=(n+r)/2;if(e={l:t.l,c:u,h:t.h},A(e)?n=u:r=u,r-n<h)break}return{l:t.l,c:n,h:t.h}}function K(t,n,r){const e={l:t.l,c:Math.max(n,Math.min(r,t.c)),h:t.h};return M(e)}const _=.022,O=.012,k=.022,w=.57,B=.56,P=1.14,d=.001,R=.027;function I(t){const n=Math.pow(x(t.r),2.4),r=Math.pow(x(t.g),2.4),e=Math.pow(x(t.b),2.4);return .2126729*n+.7151522*r+.072175*e}function F(t,n){const r=g(M(t)),e=g(M(n));let o=I(r),u=I(e);if(o=o>_?o:o+Math.pow(_-o,1.414),u=u>_?u:u+Math.pow(_-u,1.414),Math.abs(u-o)<d)return 0;let c;if(u>o){const a=Math.pow(u,B),s=Math.pow(o,w);if(c=(a-s)*P,c<d)return 0;c=c<R?c-c*k*R:c-k}else{const a=Math.pow(u,B),s=Math.pow(o,w);if(c=(a-s)*P,c>-d)return 0;c=c>-R?c-c*O*R:c+O}return c*100}function j(t,n,r=60){let e=M({...t}),o=Math.abs(F(e,n));if(o>=r)return e;const u=n.l>.5,c=.01,a=u?0:1;for(let s=0;s<100;s++){if(u?e.l=Math.max(a,e.l-c):e.l=Math.min(a,e.l+c),e=M(e),o=Math.abs(F(e,n)),o>=r)return e;if(e.l<=0||e.l>=1)break}return e}function it(t,n){return((t+n)%360+360)%360}function lt(t,n){const r=T(t),e=T(n),o=r.L-e.L,u=r.a-e.a,c=r.b-e.b;return Math.sqrt(o*o+u*u+c*c)}function J(t,n,r,e){return K({l:n,c:t.c,h:t.h},r,e)}function ht(t,n,r,e,o,u=60,c){const a=J(t,n,r,e);return c?.(a),j(a,o,u)}function E(t){return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Q(t){return{r:E(t.r),g:E(t.g),b:E(t.b)}}function Z({r:t,g:n,b:r}){const e=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*r),o=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*r),u=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*r);return{L:.2104542553*e+.793617785*o-.0040720468*u,a:1.9779984951*e-2.428592205*o+.4505937099*u,b:.0259040371*e+.7827717662*o-.808675766*u}}function tt(t){return Z(Q(t))}function nt(t){const n=Math.sqrt(t.a*t.a+t.b*t.b),r=n<1e-12?0:(Math.atan2(t.b,t.a)/G%360+360)%360;return{l:t.L,c:n,h:r}}function rt(t){const n=p(t.c,4);return{l:p(t.l,3),c:n,h:n===0?0:p(t.h,1)}}function f(t){return Math.round(x(t)*255)}function L(t){const n=nt(tt(t)),r=t.r===t.g&&t.g===t.b?{l:n.l,c:0,h:0}:n,e=rt(r);if(A(e)){const o=g(e);if(f(o.r)===f(t.r)&&f(o.g)===f(t.g)&&f(o.b)===f(t.b))return e}return r}function et(t){const n=t.slice(1);if(!/^[0-9a-f]+$/i.test(n))return null;if(n.length===3){const[r,e,o]=n.split("").map(u=>parseInt(u+u,16));return{r:r/255,g:e/255,b:o/255}}return n.length===6?{r:parseInt(n.slice(0,2),16)/255,g:parseInt(n.slice(2,4),16)/255,b:parseInt(n.slice(4,6),16)/255}:null}function D(t,n){const r=t.match(new RegExp("^"+n+"\\("+i+"*([^)]*?)"+i+"*\\)$","i"));if(!r)return null;const e=r[1];if(e.includes("/"))return null;const o=e.includes(","),u=e.split(o?y:H);return u.length!==3||u.some(c=>c.length===0)?null:{args:u,legacy:o}}const ot=new RegExp("^("+m+")([a-z%]*)$","i");function N(t){const n=t.match(ot);if(!n)return null;const r=parseFloat(n[1]);return isFinite(r)?{value:r,unit:n[2].toLowerCase()}:null}function ut(t){if(t.unit!==""&&t.unit!=="%")return null;const n=t.unit==="%"?t.value/100:t.value/255;return Math.max(0,Math.min(1,n))}function ct(t){const n=b[t.unit];return n===void 0?null:t.value*n}function v(t){return t.unit!==""&&t.unit!=="%"?null:Math.max(0,Math.min(1,t.value/100))}function at(t,n,r){const e=(t%360+360)%360,o=u=>{const c=(u+e/30)%12,a=n*Math.min(r,1-r);return r-a*Math.max(-1,Math.min(c-3,9-c,1))};return{r:o(0),g:o(8),b:o(4)}}const ft='"#rrggbb", "#rgb", "rgb(\u2026)", "hsl(\u2026)", "oklch(\u2026)"';function pt(t){const n=S(t);if(n.startsWith("#")){const r=et(n);return r?L(r):null}if(/^oklch\(/i.test(n))return q(n);if(/^rgba?\(/i.test(n)){const r=D(n,"rgba?");if(!r)return null;const e=r.args.map(N);if(e.some(l=>l===null))return null;const o=e;if(r.legacy&&new Set(o.map(l=>l.unit)).size>1)return null;const u=o.map(ut);if(u.some(l=>l===null))return null;const[c,a,s]=u;return L({r:c,g:a,b:s})}if(/^hsla?\(/i.test(n)){const r=D(n,"hsla?");if(!r)return null;const e=r.args.map(N);if(e.some($=>$===null))return null;const[o,u,c]=e;if(r.legacy&&(u.unit!=="%"||c.unit!=="%"))return null;const a=ct(o),s=v(u),l=v(c);return a===null||s===null||l===null?null:L(at(a,s,l))}return null}function p(t,n){const r=Math.pow(10,n);return Math.round(t*r)/r}export{ft as ACCEPTED_COLOR_FORMS,F as apcaContrast,x as clampChannel,K as clampChromaAndGamutMap,lt as deltaEOK,J as deriveSemantic,ht as deriveSemanticWithContrast,j as ensureContrast,E as gammaToLinear,M as gamutMapToSRGB,A as isInSRGBGamut,Z as linearRgbToOklab,nt as oklabToOklch,T as oklchToOklab,g as oklchToSRGB,pt as parseCssColor,q as parseOklch,it as rotateHue,st as serializeOklch,Q as srgbToLinearRGB};
1
+ import{CSS_NAMED_COLORS as w}from"./css-named-colors.js";const B=Math.PI/180,p=1e-4,W=50,d="[+-]?(?:\\d+|\\d*\\.\\d+)(?:[eE][+-]?\\d+)?",h="[\\t\\n\\f\\r ]",z=new RegExp(h+"*,"+h+"*"),Y=new RegExp(h+"+");function _(t){return t.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g,"")}const P={"":1,deg:1,grad:.9,rad:180/Math.PI,turn:360},j=.4,q=new RegExp("^oklch\\("+h+"*("+d+")(%?)"+h+"+("+d+")(%?)"+h+"+("+d+")(deg|grad|rad|turn)?"+h+"*\\)$","i");function k(t){const n=t.h*B;return{L:t.l,a:t.c*Math.cos(n),b:t.c*Math.sin(n)}}function K(t){const n=t.L+.3963377774*t.a+.2158037573*t.b,e=t.L-.1055613458*t.a-.0638541728*t.b,r=t.L-.0894841775*t.a-1.291485548*t.b,o=n*n*n,c=e*e*e,u=r*r*r;return{r:4.0767416621*o-3.3077115913*c+.2309699292*u,g:-1.2684380046*o+2.6097574011*c-.3413193965*u,b:-.0041960863*o-.7034186147*c+1.707614701*u}}function S(t){return t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055}function J(t){return{r:S(t.r),g:S(t.g),b:S(t.b)}}function Q(t){return t.r>=-p&&t.r<=1+p&&t.g>=-p&&t.g<=1+p&&t.b>=-p&&t.b<=1+p}function f(t){return Math.max(0,Math.min(1,t))}function Z(t){const n=_(t).match(q);if(!n)return null;let e=parseFloat(n[1]);n[2]==="%"&&(e/=100);let r=parseFloat(n[3]);n[4]==="%"&&(r=r/100*j);const o=parseFloat(n[5])*P[(n[6]??"").toLowerCase()];return!isFinite(e)||!isFinite(r)||!isFinite(o)?null:{l:Math.max(0,Math.min(1,e)),c:Math.max(0,r),h:(o%360+360)%360}}function mt(t){const n=M(t.l,6),e=M(t.c,6),r=M((t.h%360+360)%360,4);return`oklch(${n} ${e} ${r})`}function R(t){return J(K(k(t)))}function A(t){return Q(R(t))}function C(t){if(t.c<=p||A(t))return{...t};let n=0,e=t.c,r={...t};for(let o=0;o<W;o++){const c=(n+e)/2;if(r={l:t.l,c,h:t.h},A(r)?n=c:e=c,e-n<p)break}return{l:t.l,c:n,h:t.h}}function tt(t,n,e){const r={l:t.l,c:Math.max(n,Math.min(e,t.c)),h:t.h};return C(r)}const b=.022,v=.012,F=.022,I=.57,y=.56,D=1.14,O=.001,L=.027;function N(t){const n=Math.pow(f(t.r),2.4),e=Math.pow(f(t.g),2.4),r=Math.pow(f(t.b),2.4);return .2126729*n+.7151522*e+.072175*r}function $(t,n){const e=R(C(t)),r=R(C(n));let o=N(e),c=N(r);if(o=o>b?o:o+Math.pow(b-o,1.414),c=c>b?c:c+Math.pow(b-c,1.414),Math.abs(c-o)<O)return 0;let u;if(c>o){const a=Math.pow(c,y),l=Math.pow(o,I);if(u=(a-l)*D,u<O)return 0;u=u<L?u-u*F*L:u-F}else{const a=Math.pow(c,y),l=Math.pow(o,I);if(u=(a-l)*D,u>-O)return 0;u=u>-L?u-u*v*L:u+v}return u*100}function nt(t,n,e=60){let r=C({...t}),o=Math.abs($(r,n));if(o>=e)return r;const c=n.l>.5,u=.01,a=c?0:1;for(let l=0;l<100;l++){if(c?r.l=Math.max(a,r.l-u):r.l=Math.min(a,r.l+u),r=C(r),o=Math.abs($(r,n)),o>=e)return r;if(r.l<=0||r.l>=1)break}return r}function Mt(t,n){return((t+n)%360+360)%360}function gt(t,n){const e=k(t),r=k(n),o=e.L-r.L,c=e.a-r.a,u=e.b-r.b;return Math.sqrt(o*o+c*c+u*u)}function rt(t,n,e,r){return tt({l:n,c:t.c,h:t.h},e,r)}function Ct(t,n,e,r,o,c=60,u){const a=rt(t,n,e,r);return u?.(a),nt(a,o,c)}function G(t){return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function et(t){return{r:G(t.r),g:G(t.g),b:G(t.b)}}function ot({r:t,g:n,b:e}){const r=Math.cbrt(.4122214708*t+.5363325363*n+.0514459929*e),o=Math.cbrt(.2119034982*t+.6806995451*n+.1073969566*e),c=Math.cbrt(.0883024619*t+.2817188376*n+.6299787005*e);return{L:.2104542553*r+.793617785*o-.0040720468*c,a:1.9779984951*r-2.428592205*o+.4505937099*c,b:.0259040371*r+.7827717662*o-.808675766*c}}function ct(t){return ot(et(t))}function V(t){const n=Math.sqrt(t.a*t.a+t.b*t.b),e=n<1e-12?0:(Math.atan2(t.b,t.a)/B%360+360)%360;return{l:t.L,c:n,h:e}}function ut(t){const n=M(t.c,4);return{l:M(t.l,3),c:n,h:n===0?0:M(t.h,1)}}function m(t){return Math.round(f(t)*255)}function at(t){const n=V(ct(t)),e=t.r===t.g&&t.g===t.b?{l:n.l,c:0,h:0}:n,r=ut(e);if(A(r)){const o=R(r);if(m(o.r)===m(t.r)&&m(o.g)===m(t.g)&&m(o.b)===m(t.b))return r}return e}function X(t,n){const e=t.slice(1),r=e.length;if(!/^[0-9a-f]+$/i.test(e)||r!==3&&r!==6&&!(n&&(r===4||r===8)))return null;const o=r<=4?1:2,c=u=>{const a=e.slice(u*o,(u+1)*o);return parseInt(o===1?a.repeat(2):a,16)/255};return{space:"srgb",color:{r:c(0),g:c(1),b:c(2)},alpha:r===4||r===8?c(3):1}}function x(t,n,e){const r=t.match(new RegExp("^"+n+"\\("+h+"*([^)]*?)"+h+"*\\)$","i"));if(!r)return null;const o=r[1],c=o.includes(","),u=o.split("/");if(u.length>2||u.length===2&&(c||!e))return null;const l=_(u[0]).split(c?z:Y),i=c&&l.length===4&&e?l.pop():u[1];if(l.length!==3||l.some(g=>g.length===0))return null;const s=i===void 0?1:H(_(i));return s===null?null:{args:l,legacy:c,alpha:s}}const st=new RegExp("^("+d+")([a-z%]*)$","i");function T(t){const n=t.match(st);if(!n)return null;const e=parseFloat(n[1]);return isFinite(e)?{value:e,unit:n[2].toLowerCase()}:null}function H(t){if(t.toLowerCase()==="none")return 0;const n=T(t);return!n||n.unit!==""&&n.unit!=="%"?null:f(n.unit==="%"?n.value/100:n.value)}function lt(t){if(t.unit!==""&&t.unit!=="%")return null;const n=t.unit==="%"?t.value/100:t.value/255;return Math.max(0,Math.min(1,n))}function it(t){const n=P[t.unit];return n===void 0?null:t.value*n}function U(t){return t.unit!==""&&t.unit!=="%"?null:Math.max(0,Math.min(1,t.value/100))}function ht(t,n,e){const r=(t%360+360)%360,o=c=>{const u=(c+r/30)%12,a=n*Math.min(e,1-e);return e-a*Math.max(-1,Math.min(u-3,9-u,1))};return{r:o(0),g:o(8),b:o(4)}}const xt='"#rrggbb", "#rgb", "rgb(\u2026)", "hsl(\u2026)", "oklch(\u2026)"';function dt(t){const n=pt(t,!1);return n?n.space==="oklch"?n.color:at(n.color):null}function pt(t,n){const e=_(t);if(e.startsWith("#"))return X(e,n);if(/^oklch\(/i.test(e)){const r=n?x(e,"oklch",!0):null;if(n&&(!r||r.legacy))return null;const o=Z(r?`oklch(${r.args.map(c=>c.toLowerCase()==="none"?"0":c).join(" ")})`:e);return o?{space:"oklch",color:o,alpha:r?.alpha??1}:null}if(/^rgba?\(/i.test(e)){const r=x(e,"rgba?",n);if(!r)return null;const o=r.args.map(T);if(o.some(s=>s===null))return null;const c=o;if(r.legacy&&new Set(c.map(s=>s.unit)).size>1)return null;const u=c.map(lt);if(u.some(s=>s===null))return null;const[a,l,i]=u;return{space:"srgb",color:{r:a,g:l,b:i},alpha:r.alpha}}if(/^hsla?\(/i.test(e)){const r=x(e,"hsla?",n);if(!r)return null;const o=r.args.map(T);if(o.some(g=>g===null))return null;const[c,u,a]=o;if(r.legacy&&(u.unit!=="%"||a.unit!=="%"))return null;const l=it(c),i=U(u),s=U(a);return l===null||i===null||s===null?null:{space:"srgb",color:ht(l,i,s),alpha:r.alpha}}if(n){if(/^oklab\(/i.test(e)){const c=x(e,"oklab",!0);if(!c||c.legacy)return null;const u=c.args.map(s=>T(s.toLowerCase()==="none"?"0":s));if(u.some(s=>!s||s.unit!==""&&s.unit!=="%"))return null;const[a,l,i]=u.map((s,g)=>{const E=s;return E.unit!=="%"?E.value:E.value/100*(g===0?1:.4)});return{space:"oklch",color:V({L:f(a),a:l,b:i}),alpha:c.alpha}}const r=e.toLowerCase();if(Object.prototype.hasOwnProperty.call(w,r))return X(w[r],n);if(r==="transparent")return{space:"srgb",color:{r:0,g:0,b:0},alpha:0};const o=e.match(new RegExp("^color\\("+h+"*srgb"+h+"+","i"));if(o){const c=x(`color(${e.slice(o[0].length)}`,"color",!0);if(!c||c.legacy)return null;const u=c.args.map(H);if(u.some(s=>s===null))return null;const[a,l,i]=u;return{space:"srgb",color:{r:a,g:l,b:i},alpha:c.alpha}}}return null}function M(t,n){const e=Math.pow(10,n);return Math.round(t*e)/e}export{xt as ACCEPTED_COLOR_FORMS,$ as apcaContrast,f as clampChannel,tt as clampChromaAndGamutMap,gt as deltaEOK,rt as deriveSemantic,Ct as deriveSemanticWithContrast,nt as ensureContrast,G as gammaToLinear,C as gamutMapToSRGB,A as isInSRGBGamut,ot as linearRgbToOklab,V as oklabToOklch,k as oklchToOklab,R as oklchToSRGB,dt as parseCssColor,pt as parseCssColorValue,Z as parseOklch,Mt as rotateHue,mt as serializeOklch,et as srgbToLinearRGB,ct as srgbToOklab};
@@ -0,0 +1 @@
1
+ function n(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in t}function r(t){if(t.assignedSlot)return t.assignedSlot;if(t.parentElement)return t.parentElement;const e=t.parentNode;return e&&n(e)?e.host:null}export{r as composedParent,n as isShadowRoot};
@@ -0,0 +1 @@
1
+ function e(r,o){return r?.trim()||o?.trim()||""}export{e as resolveConfiguredBrandColor};
@@ -1,8 +1,8 @@
1
- import{css as g,html as r,nothing as l}from"lit";function f({scheme:o,brandLogo:n,brandColor:s,lightBrandLogo:a,darkBrandLogo:t,lightBrandColor:d,darkBrandColor:e}){return{brandLogo:(o==="dark"?t:a)||n,brandColor:(o==="dark"?e:d)||s}}const u=g`3 / 1`,$=g`
1
+ import{css as g,html as n,nothing as c}from"lit";import{resolveConfiguredBrandColor as i}from"./configured-brand-color.js";function m({scheme:o,brandLogo:r,brandColor:e,lightBrandLogo:a,darkBrandLogo:t,lightBrandColor:d,darkBrandColor:s}){return{brandLogo:(o==="dark"?t:a)||r,brandColor:i(o==="dark"?s:d,e)}}const B=g`3 / 1`,C=g`
2
2
  .brand-logo {
3
3
  overflow-wrap: anywhere;
4
4
  }
5
- `;function m({brandLogo:o,brandText:n,brandHref:s,brandAlt:a,reserveLogoSpace:t=!1}){if(!o&&!n)return l;const e=o?r`<img class="brand-logo" src=${o} alt=${a||(n?"":"Site logo")} />`:l,c=r`
6
- ${o&&t?r`<span class="brand-logo-reservation">${e}</span>`:e}
7
- ${n?r`<span class="brand-text">${n}</span>`:l}
8
- `;return s?r`<a class="configured-brand" href=${s}>${c}</a>`:r`<span class="configured-brand">${c}</span>`}export{u as CONFIGURED_BRAND_LOGO_ASPECT_RATIO,$ as configuredBrandLogoGeometry,m as renderConfiguredBrand,f as resolveConfiguredBrand};
5
+ `;function $({brandLogo:o,brandText:r,brandHref:e,brandAlt:a,reserveLogoSpace:t=!1}){if(!o&&!r)return c;const s=o?n`<img class="brand-logo" src=${o} alt=${a||(r?"":"Site logo")} />`:c,l=n`
6
+ ${o&&t?n`<span class="brand-logo-reservation">${s}</span>`:s}
7
+ ${r?n`<span class="brand-text">${r}</span>`:c}
8
+ `;return e?n`<a class="configured-brand" href=${e}>${l}</a>`:n`<span class="configured-brand">${l}</span>`}export{B as CONFIGURED_BRAND_LOGO_ASPECT_RATIO,C as configuredBrandLogoGeometry,$ as renderConfiguredBrand,m as resolveConfiguredBrand};
@@ -0,0 +1 @@
1
+ const e=Object.freeze({aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"});export{e as CSS_NAMED_COLORS};
@@ -0,0 +1,27 @@
1
+ import { type PaintColor } from "./paint-color.js";
2
+ import type { PaintColorEnvironment, PaintDerivation, PaintDerivations, PaintEntriesByRole, PaintEntry, PaintKind, PaintNavigationFact, PaintRegistration, PaintSchemeFeatures, PaintTarget, PaintTargetsByRole } from "./paint-types.js";
3
+ export declare const PAINT_TOKEN_IDS: readonly string[];
4
+ export declare const BRAND_PAINT_ID = "brand-color";
5
+ export declare function paintTokenProperty(identifier: string): string | undefined;
6
+ export declare function isPaintName(value: unknown): value is string;
7
+ export declare function isPaintRole(value: unknown): value is string;
8
+ export declare function isPaintKind(value: unknown): value is PaintKind;
9
+ export declare function isPaintFlags(value: unknown): value is readonly string[];
10
+ export declare function isPaintNavigationFact(value: unknown): value is PaintNavigationFact;
11
+ export declare function validatePaintEntries(entriesByRole: unknown, derivations?: PaintDerivations): asserts entriesByRole is PaintEntriesByRole;
12
+ interface PaintCatalog {
13
+ entriesByRole: PaintEntriesByRole;
14
+ targets: PaintTargetsByRole;
15
+ derivations: PaintDerivations;
16
+ }
17
+ /** Assemble component registrations without giving any role special treatment. */
18
+ export declare function createPaintCatalog(registrations: readonly PaintRegistration[]): PaintCatalog;
19
+ export declare const PAINT_CATALOG: Readonly<Record<string, readonly PaintEntry[]>>;
20
+ export declare const PAINT_TARGETS: Readonly<Record<string, readonly PaintTarget[]>>;
21
+ export declare const PAINT_DERIVATIONS: Readonly<Record<string, PaintDerivation>>;
22
+ /** Select rendered entries and resolve brand ink using the active scheme's configured override. */
23
+ export declare function enabledPaintEntries(role: string, features: PaintSchemeFeatures, entriesByRole?: PaintEntriesByRole, { brandColor }?: {
24
+ brandColor?: string;
25
+ }): readonly PaintEntry[];
26
+ export declare function resolvePaintColor(identifier: string, environment: PaintColorEnvironment, derivations?: PaintDerivations): PaintColor | null;
27
+ export {};
@@ -0,0 +1 @@
1
+ import{buttonPaintRegistration as y}from"../button/paint-registration.js";import{footerPaintRegistration as w}from"../footer/paint-registration.js";import{headerPaintRegistration as T}from"../header/paint-registration.js";import{menuPaintRegistration as j}from"../menu/paint-registration.js";import{resolveConfiguredBrandColor as v}from"./configured-brand-color.js";import{parsePaintColor as x}from"./paint-color.js";import{COLOR_SOURCES as A,SEMANTIC_COLOR_NAMES as E,isObjectRecord as p,semanticToCSS as R}from"./theme.js";const u=new Map([...E.map(t=>[t,R(t)]),...A.map(t=>[t,`--esp-color-${t}`])]),U=Object.freeze([...u.keys()]),l="brand-color";function f(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function V(t){return u.get(t)}function c(t){return typeof t=="string"&&t.trim()!==""}function N(t){return c(t)&&t===t.trim()}function C(t){return t==="text"||t==="graphic"||t==="ring"}function $(t){return Array.isArray(t)&&Array.from(t).every(c)}const g={depth:t=>t==="top-level"||t==="nested",kind:t=>t==="button"||t==="plain"||t==="group",anchor:t=>typeof t=="boolean",canBeCurrent:t=>typeof t=="boolean",icon:t=>t===void 0||typeof t=="boolean"};function H(t){return p(t)&&Object.entries(g).every(([e,n])=>n(t[e]))}const k={element:!0,foreground:!0,background:!0,state:!0,kind:!0,flags:!0,navigation:!0,indicator:!0,paintOpacity:!0};function S(t){return p(t)&&Object.entries(t).every(([e,n])=>f(g,e)&&g[e](n))}function I(t,e,n){if(!p(t)||!Object.keys(t).every(o=>f(k,o))||!c(t.element)||!c(t.state)||!C(t.kind)||!$(t.flags))throw new TypeError(`${e} is not a paint entry.`);for(const o of["foreground","background"]){const r=t[o];if(!c(r)||!(u.has(r)||f(n,r)||o==="foreground"&&r===l))throw new TypeError(`${e} has an unknown ${o} paint identifier "${String(r)}".`)}if(t.paintOpacity!==void 0&&(typeof t.paintOpacity!="number"||!Number.isFinite(t.paintOpacity)||t.paintOpacity<0||t.paintOpacity>1))throw new TypeError(`${e} has an invalid paint opacity.`);if(t.navigation!==void 0&&!S(t.navigation))throw new TypeError(`${e} has an invalid navigation predicate.`);if(t.indicator!==void 0&&(t.indicator!=="blurred-shadow"||t.kind==="text"))throw new TypeError(`${e} has an invalid indicator.`)}function _(t,e=O){if(!p(t))throw new TypeError("Paint entries must be grouped by role.");for(const[n,o]of Object.entries(t)){if(!N(n)||!Array.isArray(o))throw new TypeError(`Paint entries for role "${n}" must be an array on a nonempty role without outer whitespace.`);for(let r=0;r<o.length;r+=1)I(o[r],`Paint entry for "${n}" at index ${r}`,e)}}function z(t){const e=Object.create(null),n=Object.create(null),o=Object.create(null);for(const r of t)for(const[i,a]of Object.entries(r.derivations??{})){if(!c(i)||i===l||u.has(i)||i in o)throw new TypeError(`Paint derivation "${i}" must have a unique identifier.`);o[i]=a}for(const r of t){_(r.entriesByRole,o);for(const[i,a]of Object.entries(r.entriesByRole))(e[i]??=[]).push(...a);for(const[i,a]of Object.entries(r.targets))(n[i]??=[]).push(...a)}for(const r of Object.values(e))Object.freeze(r);for(const r of Object.values(n))Object.freeze(r);return{entriesByRole:Object.freeze(e),targets:Object.freeze(n),derivations:Object.freeze(o)}}const b=z([T,w,j,y]),B=b.entriesByRole,J=b.targets,O=b.derivations;function Q(t,e,n=B,{brandColor:o}={}){const r=f(n,t)?n[t]:[],i=new Set(e.flags),a=r.filter(s=>{if(!s.flags.every(d=>i.has(d)))return!1;if(s.navigation===void 0)return!0;const m=Object.entries(s.navigation);return e.navigation.some(d=>m.every(([P,h])=>d[P]===h))});return v(o)?a:a.map(s=>s.foreground===l?{...s,foreground:"headings"}:s)}function W(t,e,n=O){if(f(n,t))return n[t](e);const o=e.readColor(t);return o?x(o):null}export{l as BRAND_PAINT_ID,B as PAINT_CATALOG,O as PAINT_DERIVATIONS,J as PAINT_TARGETS,U as PAINT_TOKEN_IDS,z as createPaintCatalog,Q as enabledPaintEntries,$ as isPaintFlags,C as isPaintKind,c as isPaintName,H as isPaintNavigationFact,N as isPaintRole,V as paintTokenProperty,W as resolvePaintColor,_ as validatePaintEntries};
@@ -0,0 +1,25 @@
1
+ import type { PaintKind } from "./paint-types.js";
2
+ /** Gamma-encoded sRGB and alpha, with all channels in 0–1. */
3
+ export interface PaintColor {
4
+ r: number;
5
+ g: number;
6
+ b: number;
7
+ alpha: number;
8
+ }
9
+ /** Parse absolute CSS paint, retaining its declared alpha. */
10
+ export declare function parsePaintColor(value: string): PaintColor | null;
11
+ /** Change the lightness channel of a relative OKLCH color. */
12
+ export declare function derivePaintLightness(value: string | undefined, lightness: (original: number) => number): PaintColor | null;
13
+ /** Composite foreground over background using CSS source-over alpha. */
14
+ export declare function compositePaint(foreground: PaintColor, background: PaintColor): PaintColor;
15
+ export declare const MIN_SHADOW_INDICATOR_BLUR = 3;
16
+ export declare const MAX_SHADOW_INDICATOR_BLUR = 4;
17
+ export declare const SHADOW_INDICATOR_SAMPLE_OFFSET = 0.1;
18
+ export declare const SHADOW_INDICATOR_MARGIN_SIGMAS = 4;
19
+ export declare function supportsShadowIndicatorBlur(blur: number): boolean;
20
+ /** Lower coverage estimate at the supported straight edge. Hard bands use full alpha. */
21
+ export declare function shadowIndicatorAlpha(shadow: {
22
+ alpha: number;
23
+ blur: number;
24
+ }): number;
25
+ export declare function paintRequiredRatio(kind: PaintKind): 3 | 4.5;
@@ -0,0 +1 @@
1
+ import{clampChannel as l,gamutMapToSRGB as n,oklabToOklch as A,oklchToSRGB as e,parseCssColorValue as c,srgbToOklab as _}from"./color-engine.js";import{AA_NON_TEXT_RATIO as I,AA_TEXT_RATIO as O}from"./wcag-contrast.js";function b(t){const a=c(t,!0);if(!a)return null;const r=a.space==="oklch"?e(n(a.color)):a.color;return{r:l(r.r),g:l(r.g),b:l(r.b),alpha:a.alpha}}function M(t,a){const r=t&&c(t,!0);if(!r)return null;const p=r.space==="oklch"?r.color:A(_(r.color)),o=e(n({...p,l:l(a(p.l))}));return{r:l(o.r),g:l(o.g),b:l(o.b),alpha:r.alpha}}function C(t,a){if(t.alpha===0)return a;if(t.alpha===1||a.alpha===0)return t;const r=a.alpha*(1-t.alpha),p=t.alpha+r;return{r:(t.r*t.alpha+a.r*r)/p,g:(t.g*t.alpha+a.g*r)/p,b:(t.b*t.alpha+a.b*r)/p,alpha:p}}const s=3,R=4,T=.1,h=4;function u(t){return t>=s&&t<=R}const i=1/Math.sqrt(2*Math.PI),x=i*Math.exp(-(h**2)/2)/h,S=.5-T/(s/2)*i-3*x-.05;function E(t){if(t.blur===0)return t.alpha;if(!u(t.blur))throw new RangeError(`Unsupported shadow indicator blur ${t.blur}px. Expected 3\u20134px.`);return t.alpha*S}function m(t){return t==="text"?O:I}export{R as MAX_SHADOW_INDICATOR_BLUR,s as MIN_SHADOW_INDICATOR_BLUR,h as SHADOW_INDICATOR_MARGIN_SIGMAS,T as SHADOW_INDICATOR_SAMPLE_OFFSET,C as compositePaint,M as derivePaintLightness,m as paintRequiredRatio,b as parsePaintColor,E as shadowIndicatorAlpha,u as supportsShadowIndicatorBlur};
@@ -0,0 +1 @@
1
+ import{resolveConfiguredBrandColor as k}from"./configured-brand-color.js";import{BRAND_PAINT_ID as B,PAINT_CATALOG as q,PAINT_DERIVATIONS as D,enabledPaintEntries as v,isPaintFlags as x,isPaintName as j,isPaintNavigationFact as M,isPaintRole as F,paintTokenProperty as L,resolvePaintColor as R,validatePaintEntries as W}from"./paint-catalog.js";import{compositePaint as H,MIN_SHADOW_INDICATOR_BLUR as G,paintRequiredRatio as U,shadowIndicatorAlpha as V}from"./paint-color.js";import{firstPaintByIdentity as z,paintIdentity as J}from"./paint-identity.js";import{SEMANTIC_COLOR_NAMES as K,isObjectRecord as p,semanticToCSS as S}from"./theme.js";import{wcagRatio as Q}from"./wcag-contrast.js";const X=["light","dark"],Y=new Set(K.map(S));function Z(t){return p(t)&&x(t.flags)&&Array.isArray(t.navigation)&&Array.from(t.navigation).every(M)}function rr(t){if(!Array.isArray(t))throw new TypeError("Paint surfaces must be an array.");const o=new Set;for(const a of t){if(!p(a)||!F(a.role))throw new TypeError("Each paint surface requires a nonempty role without outer whitespace.");const{role:e,context:l,brandColors:s,features:i}=a;if(o.has(e))throw new TypeError(`Duplicate paint surface role "${e}".`);if(o.add(e),l!=null&&!j(l))throw new TypeError(`Paint surface "${e}" has an invalid context.`);if(s!==void 0&&(!p(s)||Object.entries(s).some(([r,c])=>!["light","dark","generic"].includes(r)||c!==void 0&&typeof c!="string")))throw new TypeError(`Paint surface "${e}" has invalid brand colors.`);if(!p(i)||!X.every(r=>Z(i[r])))throw new TypeError(`Paint surface "${e}" requires light and dark feature facts.`)}}function tr(t,o,a,e,l,s){const{role:i}=t,r=t.context??null,c=a.get(null),h=a.get(r);if(!c||!h)throw new Error(`Paint surface "${i}" requests undefined ${o} context "${r}".`);const u=k(t.brandColors?.[o],t.brandColors?.generic),w=n=>n==="--_esp-context-shadow"?r===null?void 0:h[S("shadow")]:Y.has(n)||n.startsWith("--esp-l-")||n==="--_esp-surface-polarity"?h[n]:c[n],g={scheme:o,context:r,readProperty:w,readColor:n=>{if(n===B)return u?.startsWith("--esp-color-")?w(u):u;const d=L(n);return d&&w(d)}},A=t.features[o],T={brandColor:u},$=[...v(i,A,e.entriesByRole,T),...v(i,A,l,T)],I=[...z($).values()].map(n=>{const{element:d,foreground:P,background:m,kind:C,state:E}=n,y=R(P,g,e.derivations),f=R(m,g,e.derivations);if(!y||!f||f.alpha!==1)throw new Error(`Paint surface "${i}" (${o}) cannot resolve "${d}" ${E}: ${P} on opaque ${m}.`);const N=y.alpha*(n.paintOpacity??1),O=V({alpha:N,blur:n.indicator==="blurred-shadow"?G:0}),_=H({...y,alpha:O},f),b={element:d,foreground:P,background:m,state:E,kind:C,ratio:Q(_,f),required:U(C)};return s?.(o,J({role:i,...n}),b),b});return{role:i,context:r,pairs:I}}function cr(t,o,a={},e={entriesByRole:q,derivations:D},l){rr(o),W(a,e.derivations);const s=new Set([...Object.entries(e.entriesByRole),...Object.entries(a)].filter(([,r])=>r.length>0).map(([r])=>r));for(const{role:r}of o)if(!s.has(r))throw new TypeError(`Paint surface "${r}" has no registered paint entries.`);const i=r=>o.map(c=>tr(c,r,t[r],e,a,l));return{light:i("light"),dark:i("dark")}}export{cr as measurePaintSurfaces};
@@ -0,0 +1 @@
1
+ function i(t){return JSON.stringify([t.role,t.element,t.state,t.kind,t.foreground,t.background,t.indicator,t.paintOpacity??1])}function d(t){const n=new Map;for(const e of t){const o=i(e);n.has(o)||n.set(o,e)}return n}export{d as firstPaintByIdentity,i as paintIdentity};
@@ -0,0 +1,88 @@
1
+ import type { PaintColor } from "./paint-color.js";
2
+ export type PaintScheme = "light" | "dark";
3
+ export type PaintKind = "text" | "graphic" | "ring";
4
+ export interface PaintNavigationFact {
5
+ depth: "top-level" | "nested";
6
+ kind: "button" | "plain" | "group";
7
+ anchor: boolean;
8
+ canBeCurrent: boolean;
9
+ icon?: boolean;
10
+ }
11
+ export interface PaintSchemeFeatures {
12
+ flags: readonly string[];
13
+ navigation: readonly PaintNavigationFact[];
14
+ }
15
+ export interface PaintEntry {
16
+ element: string;
17
+ foreground: string;
18
+ background: string;
19
+ state: string;
20
+ kind: PaintKind;
21
+ flags: readonly string[];
22
+ navigation?: Partial<PaintNavigationFact>;
23
+ indicator?: "blurred-shadow";
24
+ /** Paint coverage applied outside the declared color, such as SVG stroke-opacity. Defaults to 1. */
25
+ paintOpacity?: number;
26
+ }
27
+ export interface PaintFitSurface {
28
+ role: string;
29
+ /** A null or omitted context selects the root theme. */
30
+ context?: string | null;
31
+ brandColors?: {
32
+ light?: string;
33
+ dark?: string;
34
+ generic?: string;
35
+ };
36
+ features: Record<PaintScheme, PaintSchemeFeatures>;
37
+ }
38
+ export interface PaintFitPair {
39
+ element: string;
40
+ foreground: string;
41
+ background: string;
42
+ state: string;
43
+ kind: PaintKind;
44
+ ratio: number;
45
+ required: 3 | 4.5;
46
+ }
47
+ export interface PaintFitSurfaceReport {
48
+ role: string;
49
+ context: string | null;
50
+ pairs: PaintFitPair[];
51
+ }
52
+ export type PaintFitReport = Record<PaintScheme, PaintFitSurfaceReport[]>;
53
+ export interface PaintColorEnvironment {
54
+ scheme: PaintScheme;
55
+ context: string | null;
56
+ readColor(identifier: string): string | undefined;
57
+ readProperty(property: string): string | undefined;
58
+ }
59
+ export type PaintDerivation = (environment: PaintColorEnvironment) => PaintColor | null;
60
+ export type PaintInteraction = "rest" | "hover" | "focus" | "hover-focus";
61
+ export interface PaintCandidate {
62
+ element: Element;
63
+ kind: PaintKind;
64
+ source: "text" | "fill" | "stroke" | "shape" | "outline" | "shadow";
65
+ text?: Text;
66
+ indicator?: "blurred-shadow";
67
+ }
68
+ export interface PaintAttribution {
69
+ element: string;
70
+ owner: Element;
71
+ state?: (interaction: PaintInteraction) => string;
72
+ brandColor?: string;
73
+ foregroundDerivations?: readonly string[];
74
+ backgroundDerivations?: readonly string[];
75
+ /** Semantic identifiers that are equivalent to a named foreground derivation here. */
76
+ foregroundAliases?: readonly string[];
77
+ /** Semantic identifiers that are equivalent to a named background derivation here. */
78
+ backgroundAliases?: readonly string[];
79
+ }
80
+ export type PaintTarget = (candidate: PaintCandidate) => PaintAttribution | undefined;
81
+ export type PaintEntriesByRole = Readonly<Record<string, readonly PaintEntry[]>>;
82
+ export type PaintTargetsByRole = Readonly<Record<string, readonly PaintTarget[]>>;
83
+ export type PaintDerivations = Readonly<Record<string, PaintDerivation>>;
84
+ export interface PaintRegistration {
85
+ entriesByRole: PaintEntriesByRole;
86
+ targets: PaintTargetsByRole;
87
+ derivations?: PaintDerivations;
88
+ }
File without changes
@@ -50,6 +50,7 @@
50
50
  */
51
51
  import { type ColorVisionSimulation, type DataPalette, type DataSeriesKey } from "./data-colors.js";
52
52
  import { type EspalierTheme, type LightnessReference, type MappingSource, type PartialTheme, type SemanticColorName } from "./theme.js";
53
+ import type { PaintEntriesByRole, PaintFitReport, PaintFitSurface } from "./paint-types.js";
53
54
  /** What APCA enforcement did to one token. */
54
55
  export interface ThemeFitApcaAction {
55
56
  /** The requested value, as an `oklch()` string. */
@@ -225,7 +226,7 @@ export interface ThemeFitDataPaletteLint {
225
226
  message: string;
226
227
  }
227
228
  /** Runtime validation/comparison vocabulary used by the exported field descriptors. */
228
- export type ThemeFitFieldKind = "anchor" | "anchor-record" | "apca" | "boolean" | "data-palette-record" | "explicit" | "fit-lint-id" | "lint-array" | "message" | "number" | "pairing" | "palette-lint-id" | "palette-lint-record" | "report-array" | "scheme" | "semantic" | "semantic-array" | "series-pair" | "simulation" | "string" | "string-array" | "token-array" | "warning";
229
+ export type ThemeFitFieldKind = "anchor" | "anchor-record" | "apca" | "boolean" | "data-palette-record" | "explicit" | "fit-lint-id" | "lint-array" | "message" | "number" | "paint-record" | "pairing" | "palette-lint-id" | "palette-lint-record" | "report-array" | "scheme" | "semantic" | "semantic-array" | "series-pair" | "simulation" | "string" | "string-array" | "token-array" | "warning";
229
230
  /** One runtime field descriptor used by fit-suite validation and comparison. */
230
231
  export interface ThemeFitFieldDescriptor<Field extends PropertyKey = PropertyKey> {
231
232
  readonly field: Field;
@@ -322,6 +323,13 @@ export interface ThemeFitSuite {
322
323
  light: ThemeFitSurfaceReport[];
323
324
  /** One report per surface the dark theme defines. */
324
325
  dark: ThemeFitSurfaceReport[];
326
+ /** WCAG measurements of enabled component paint for explicitly requested roles. */
327
+ paint?: PaintFitReport;
328
+ }
329
+ /** Optional component paint measurements to add to the APCA fit suite. */
330
+ export interface ThemeFitSuiteOptions {
331
+ paintSurfaces?: readonly PaintFitSurface[];
332
+ extraEntries?: PaintEntriesByRole;
325
333
  }
326
334
  /** Runtime schema for every surface-report field. */
327
335
  export declare const THEME_FIT_REPORT_FIELDS: readonly ThemeFitFieldDescriptor<keyof ThemeFitSurfaceReport>[];
@@ -343,5 +351,5 @@ export declare const THEME_FIT_SUITE_FIELDS: readonly ThemeFitFieldDescriptor<ke
343
351
  * seed color is unparseable), because the required palette snapshot cannot be
344
352
  * produced. {@link themeFitReport} retains its narrower empty-report behavior.
345
353
  */
346
- export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme): ThemeFitSuite;
354
+ export declare function themeFitReportSuite(lightPartial: PartialTheme, darkPartial: PartialTheme, options?: ThemeFitSuiteOptions): ThemeFitSuite;
347
355
  export {};
@@ -1 +1 @@
1
- import{apcaContrast as T,deltaEOK as x,parseOklch as _,serializeOklch as $}from"./color-engine.js";import{DATA_SERIES_KEYS as C,auditDataPalette as q,describePaletteCollision as K}from"./data-colors.js";import{DEFAULT_DARK_THEME as G,DEFAULT_LIGHT_THEME as Y,explicitMappingTokens as W,mergeTheme as j,parseAnchorSource as X,resolveContextTheme as J,roleInkProvenance as Q}from"./theme.js";import{computeThemeProperties as Z}from"../root/helpers/compute-theme-properties.js";function ke(e,t,o={}){return H(e,t,o).report}function H(e,t,o={}){let n=e,c=null;if(o.context!==void 0){const s=J(e,o.context);if(!s)throw new Error(`themeFitReport: context "${o.context}" is not defined by the theme.`);n=s,c=new Set(Object.keys(e.contexts[o.context]?.semanticMappings??{}))}const p=[],v=Z(n,t,p),L=W(n),f=Q(n.roles),E=p.map(s=>{const a=ie(s);if(L.has(a.token))a.explicit=c===null||c.has(a.token)?"declared":"inherited";else{const i=f[a.token];i!==void 0&&(a.pairing=i)}return a});return{properties:v,report:{scheme:t,seedColor:n.seedColor,anchors:ce(n.anchors),tokens:E,adjustedTokens:E.filter(s=>s.adjusted).map(s=>s.token)}}}function ee(e){return e.tokens.map(t=>({token:t.token,source:t.source,requested:t.requested,resolved:t.resolved,apca:de(t),anchor:le(t)}))}function ge(e){const t=e.adjustedTokens.length>0?`APCA moved ${e.adjustedTokens.join(", ")}`:"APCA moved nothing";console.info(`Espalier theme fit \u2014 ${e.scheme} scheme, seed ${e.seedColor}. ${t}.`),console.table(ee(e))}function I(e){const t=Object.entries(e).map(([o,n])=>Object.freeze({field:o,kind:n.kind,compared:n.compared}));return Object.freeze(t)}const te={"action-anchor-inversion":!0,"action-canvas-separation":!0,"apca-target-unmet":!0,"link-hover-ordering":!0},fe=Object.freeze(Object.keys(te)),re={"data-palette-cvd-collision":!0},Ee=Object.freeze(Object.keys(re)),ne={declared:!0,inherited:!0},Te=Object.freeze(Object.keys(ne)),oe={declared:!0,derived:!0},_e=Object.freeze(Object.keys(oe)),ae={warning:!0},ve=Object.freeze(Object.keys(ae)),Le=I({token:{kind:"semantic",compared:!0},property:{kind:"string",compared:!0},source:{kind:"string",compared:!0},lightness:{kind:"string",compared:!0},requested:{kind:"string",compared:!0},resolved:{kind:"string",compared:!0},adjusted:{kind:"boolean",compared:!0},sourceResolved:{kind:"boolean",compared:!0},anchor:{kind:"anchor",compared:!0},apca:{kind:"apca",compared:!0},explicit:{kind:"explicit",compared:!0},pairing:{kind:"pairing",compared:!0}}),Ie=I({reference:{kind:"string",compared:!0},color:{kind:"string",compared:!0},deltaE:{kind:"number",compared:!0}}),be=I({from:{kind:"string",compared:!0},to:{kind:"string",compared:!0},targetLc:{kind:"number",compared:!0},against:{kind:"semantic",compared:!0},againstColor:{kind:"string",compared:!0},fromLc:{kind:"number",compared:!0},toLc:{kind:"number",compared:!0}}),Re=I({id:{kind:"fit-lint-id",compared:!0},severity:{kind:"warning",compared:!0},tokens:{kind:"semantic-array",compared:!0},measured:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),Me=I({id:{kind:"palette-lint-id",compared:!0},severity:{kind:"warning",compared:!0},series:{kind:"series-pair",compared:!0},simulation:{kind:"simulation",compared:!0},measured:{kind:"number",compared:!0},threshold:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),D=.045,N=.045,M=75,y={l:0,c:0,h:0},P={l:1,c:0,h:0},B=.5,F=75,se=.045;function V(e){const t=[],o=new Map(e.tokens.map(r=>[r.token,r.resolved])),n=r=>{const d=o.get(r);return d===void 0?null:_(d)},c=n("background"),p=n("actionBackground");if(c&&p){const r=x(p,c);if(r<D){const d=u(r,4);t.push({id:"action-canvas-separation",severity:"warning",tokens:["actionBackground","background"],measured:d,message:`actionBackground sits \u0394E ${d} from background (floor ${D}) \u2014 filled actions vanish into this canvas. Retune the surface apart: move the background stop, or pin actionBackground to a separated stop.`})}}const v=n("link"),L=n("linkHover"),f=n("linkHoverBg");if(c&&v&&L&&f){const r=Math.abs(T(v,c)),d=Math.abs(T(L,f));x(f,c)>=se?d+B<F&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHoverBg","linkHover"],measured:u(F-d,1),message:`linkHover reaches only Lc ${u(d,1)} on the linkHoverBg wash it actually paints (tier ${F}) \u2014 retune linkHoverBg before changing linkHover; the wash has one consumer while the ink has many.`}):d+B<r&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHover","link"],measured:u(r-d,1),message:`linkHover reads weaker than link on the same canvas (Lc ${u(d,1)} vs ${u(r,1)}) \u2014 a dimming hover feels disabled. Retune linkHover toward more contrast than the resting link.`})}const E=r=>Math.abs(T(y,r))>=Math.abs(T(P,r))?"dark":"light",s=e.tokens.find(r=>r.token==="actionBackground"),a=e.tokens.find(r=>r.token==="actionText"),i=[],l=[];let m=0;const h=a?.anchor?_(a.anchor.color):null,g=a?_(a.resolved):null,k=s?.anchor?_(s.anchor.color):null,b=s?_(s.resolved):null,O=g&&b?g.l>b.l?"light":"dark":null;s?.anchor&&k&&b&&O&&s.anchor.deltaE>=N&&E(k)!==O&&(i.push("actionBackground"),m=Math.max(m,s.anchor.deltaE),l.push(`"${s.anchor.reference}" wants ${E(k)} ink but actionBackground renders carrying a ${O} label (\u0394E ${u(s.anchor.deltaE,4)})`)),a?.anchor&&a.pairing!=="derived"&&h&&g&&k&&b&&a.anchor.deltaE>=N&&k.l!==h.l&&Math.sign(k.l-h.l)!==Math.sign(b.l-g.l)&&(i.push("actionText"),m=Math.max(m,a.anchor.deltaE),l.push(`the declared pair puts "${s.anchor.reference}" ${k.l>h.l?"above":"below"} "${a.anchor.reference}" in lightness and the rendered pair puts it ${b.l>g.l?"above":"below"} (\u0394E ${u(a.anchor.deltaE,4)})`)),i.length>0&&t.push({id:"action-anchor-inversion",severity:"warning",tokens:i,measured:u(m,4),message:`The filled action renders the opposite way round from the swatches it names: ${l.join("; ")}. `+(s?.explicit===void 0?"A filled action's ramp stop is chosen by the engine near its mid-band target, so seating the ramp cannot move it the way it moves every other anchored token. Retune by pinning semanticMappings.actionBackground to a stop that carries the swatch":"semanticMappings.actionBackground is already pinned, so the engine did not place this \u2014 retune the stop that pin names")+" \u2014 and check the pair still clears its tier there, because a swatch this far off the band often cannot hold a label at its own lightness."});const A=e.tokens.filter(r=>r.apca!==void 0&&r.apca.toLc<Math.min(r.apca.targetLc,M)).sort((r,d)=>Math.min(d.apca.targetLc,M)-d.apca.toLc-(Math.min(r.apca.targetLc,M)-r.apca.toLc)||(r.token<d.token?-1:r.token>d.token?1:0));if(A.length>0){const r=A[0].apca,d=A.map(R=>`${R.token} reaches Lc ${u(R.apca.toLc,1)} on ${R.apca.against} (floor ${Math.min(R.apca.targetLc,M)})`),w=_(r.againstColor),U=w!==null&&Math.max(Math.abs(T(y,w)),Math.abs(T(P,w)))>=Math.min(r.targetLc,M);t.push({id:"apca-target-unmet",severity:"warning",tokens:A.map(R=>R.token),measured:u(Math.min(r.targetLc,M)-r.toLc,1),message:`${d.join(", ")} \u2014 enforcement moved the ink as far as this ramp allows and the pair still falls short. `+(U?"The opposite ink pole does clear the floor on that ground, so the emitted ink is on the weaker side rather than the ground being impossible \u2014 check the pairing before retuning the ground.":"No ink reaches the floor on that ground, so retune the ground each pair reads against toward a lightness that can carry it.")})}return t}const S=":root",Ae=I({scheme:{kind:"scheme",compared:!0},seedColor:{kind:"string",compared:!0},anchors:{kind:"anchor-record",compared:!0},tokens:{kind:"token-array",compared:!0},adjustedTokens:{kind:"semantic-array",compared:!0},surface:{kind:"string",compared:!0},lints:{kind:"lint-array",compared:!0}}),we=I({surfaces:{kind:"string-array",compared:!0},dataPalette:{kind:"data-palette-record",compared:!0},paletteLints:{kind:"palette-lint-record",compared:!0},light:{kind:"report-array",compared:!0},dark:{kind:"report-array",compared:!0}});function Oe(e,t){const o=j(Y,e),n=j(G,t),c=[S,...[...new Set([...Object.keys(o.contexts),...Object.keys(n.contexts)])].sort()],p=a=>{const i={};for(let l=0;l<C.length;l+=1){const m=C[l],h=`--esp-color-series-${l+1}`,g=a[h];if(g===void 0)throw new Error(`Theme fit report did not emit required property ${h}.`);i[m]=g}return i},v=a=>q(a).map(i=>{const l=u(i.distance,4);return{id:"data-palette-cvd-collision",severity:"warning",series:i.series,simulation:i.simulation,measured:l,threshold:i.threshold,message:K(i)}}),L=(a,i)=>{const l=H(a,i);if(Object.keys(l.properties).length===0)throw new Error(`themeFitReportSuite: ${i} root emitted no properties for seed "${a.seedColor}".`);const m=[{...l.report,surface:S,lints:V(l.report)}];for(const h of c){if(h===S||!(h in a.contexts))continue;const k=H(a,i,{context:h}).report;m.push({...k,surface:h,lints:V(k)})}return{dataPalette:p(l.properties),reports:m}},f=L(o,"light"),E=L(n,"dark"),s={light:f.dataPalette,dark:E.dataPalette};return{surfaces:c,dataPalette:s,paletteLints:{light:v(s.light),dark:v(s.dark)},light:f.reports,dark:E.reports}}function u(e,t){const o=Math.pow(10,t);return Math.round(e*o)/o}function z(e,t){return t===void 0?e:`${e}.${t}`}function ce(e){const t={};for(const[o,n]of Object.entries(e)){if(typeof n=="string"){t[o]=n;continue}for(const[c,p]of Object.entries(n))t[c==="color"?o:z(o,c)]=p}return t}function ie(e){const t=_(e.resolved),o=e.requested===void 0?e.resolved:$(e.requested),n={token:e.token,property:e.property,source:e.source,lightness:e.lightness,requested:o,resolved:e.resolved,adjusted:o!==e.resolved,sourceResolved:e.sourceResolved},c=X(e.source);if(c&&e.sourceResolved&&(n.anchor={reference:z(c.name,c.slot),color:$(e.base),deltaE:u(x(e.base,t),4)}),e.contrast){const p=e.contrast.background;n.apca={from:o,to:e.resolved,targetLc:e.contrast.targetLc,against:e.contrast.against,againstColor:$(p),fromLc:u(Math.abs(T(_(o),p)),1),toLc:u(Math.abs(T(t,p)),1)}}return n}function de(e){if(!e.apca)return"";const{targetLc:t,against:o,fromLc:n,toLc:c}=e.apca;return e.adjusted?`Lc ${t} vs ${o} \u2014 pushed from Lc ${n} to Lc ${c}`:`Lc ${t} vs ${o} \u2014 met at Lc ${n}`}function le(e){return e.anchor?`${e.anchor.reference} \u0394E ${e.anchor.deltaE}`:e.sourceResolved?"":"unresolved \u2014 seed used"}export{S as ROOT_SURFACE,Ie as THEME_FIT_ANCHOR_FIELDS,be as THEME_FIT_APCA_FIELDS,Me as THEME_FIT_DATA_PALETTE_LINT_FIELDS,Ee as THEME_FIT_DATA_PALETTE_LINT_IDS,Te as THEME_FIT_EXPLICIT_VALUES,Re as THEME_FIT_LINT_FIELDS,fe as THEME_FIT_LINT_IDS,ve as THEME_FIT_LINT_SEVERITIES,_e as THEME_FIT_PAIRING_VALUES,Ae as THEME_FIT_REPORT_FIELDS,we as THEME_FIT_SUITE_FIELDS,Le as THEME_FIT_TOKEN_FIELDS,ge as printThemeFitReport,V as themeFitLints,ke as themeFitReport,Oe as themeFitReportSuite,ee as themeFitRows};
1
+ import{apcaContrast as _,deltaEOK as O,parseOklch as v,serializeOklch as $}from"./color-engine.js";import{DATA_SERIES_KEYS as C,auditDataPalette as q,describePaletteCollision as K}from"./data-colors.js";import{DEFAULT_DARK_THEME as G,DEFAULT_LIGHT_THEME as Y,explicitMappingTokens as W,mergeTheme as j,parseAnchorSource as X,resolveContextTheme as J,roleInkProvenance as Q}from"./theme.js";import{measurePaintSurfaces as Z}from"./paint-fit.js";import{computeThemeProperties as ee}from"../root/helpers/compute-theme-properties.js";function fe(e,t,n={}){return H(e,t,n).report}function H(e,t,n={}){let o=e,s=null;if(n.context!==void 0){const a=J(e,n.context);if(!a)throw new Error(`themeFitReport: context "${n.context}" is not defined by the theme.`);o=a,s=new Set(Object.keys(e.contexts[n.context]?.semanticMappings??{}))}const m=[],b=ee(o,t,m),L=W(o),T=Q(o.roles),f=m.map(a=>{const i=de(a);if(L.has(i.token))i.explicit=s===null||s.has(i.token)?"declared":"inherited";else{const l=T[i.token];l!==void 0&&(i.pairing=l)}return i});return{properties:b,report:{scheme:t,seedColor:o.seedColor,anchors:ce(o.anchors),tokens:f,adjustedTokens:f.filter(a=>a.adjusted).map(a=>a.token)}}}function te(e){return e.tokens.map(t=>({token:t.token,source:t.source,requested:t.requested,resolved:t.resolved,apca:le(t),anchor:ue(t)}))}function Ee(e){const t=e.adjustedTokens.length>0?`APCA moved ${e.adjustedTokens.join(", ")}`:"APCA moved nothing";console.info(`Espalier theme fit \u2014 ${e.scheme} scheme, seed ${e.seedColor}. ${t}.`),console.table(te(e))}function I(e){const t=Object.entries(e).map(([n,o])=>Object.freeze({field:n,kind:o.kind,compared:o.compared}));return Object.freeze(t)}const re={"action-anchor-inversion":!0,"action-canvas-separation":!0,"apca-target-unmet":!0,"link-hover-ordering":!0},Te=Object.freeze(Object.keys(re)),ne={"data-palette-cvd-collision":!0},_e=Object.freeze(Object.keys(ne)),oe={declared:!0,inherited:!0},ve=Object.freeze(Object.keys(oe)),ae={declared:!0,derived:!0},Le=Object.freeze(Object.keys(ae)),se={warning:!0},Ie=Object.freeze(Object.keys(se)),be=I({token:{kind:"semantic",compared:!0},property:{kind:"string",compared:!0},source:{kind:"string",compared:!0},lightness:{kind:"string",compared:!0},requested:{kind:"string",compared:!0},resolved:{kind:"string",compared:!0},adjusted:{kind:"boolean",compared:!0},sourceResolved:{kind:"boolean",compared:!0},anchor:{kind:"anchor",compared:!0},apca:{kind:"apca",compared:!0},explicit:{kind:"explicit",compared:!0},pairing:{kind:"pairing",compared:!0}}),Me=I({reference:{kind:"string",compared:!0},color:{kind:"string",compared:!0},deltaE:{kind:"number",compared:!0}}),Re=I({from:{kind:"string",compared:!0},to:{kind:"string",compared:!0},targetLc:{kind:"number",compared:!0},against:{kind:"semantic",compared:!0},againstColor:{kind:"string",compared:!0},fromLc:{kind:"number",compared:!0},toLc:{kind:"number",compared:!0}}),Ae=I({id:{kind:"fit-lint-id",compared:!0},severity:{kind:"warning",compared:!0},tokens:{kind:"semantic-array",compared:!0},measured:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),we=I({id:{kind:"palette-lint-id",compared:!0},severity:{kind:"warning",compared:!0},series:{kind:"series-pair",compared:!0},simulation:{kind:"simulation",compared:!0},measured:{kind:"number",compared:!0},threshold:{kind:"number",compared:!0},message:{kind:"message",compared:!0}}),D=.045,N=.045,A=75,P={l:0,c:0,h:0},y={l:1,c:0,h:0},B=.5,S=75,ie=.045;function V(e){const t=[],n=new Map(e.tokens.map(r=>[r.token,r.resolved])),o=r=>{const c=n.get(r);return c===void 0?null:v(c)},s=o("background"),m=o("actionBackground");if(s&&m){const r=O(m,s);if(r<D){const c=h(r,4);t.push({id:"action-canvas-separation",severity:"warning",tokens:["actionBackground","background"],measured:c,message:`actionBackground sits \u0394E ${c} from background (floor ${D}) \u2014 filled actions vanish into this canvas. Retune the surface apart: move the background stop, or pin actionBackground to a separated stop.`})}}const b=o("link"),L=o("linkHover"),T=o("linkHoverBg");if(s&&b&&L&&T){const r=Math.abs(_(b,s)),c=Math.abs(_(L,T));O(T,s)>=ie?c+B<S&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHoverBg","linkHover"],measured:h(S-c,1),message:`linkHover reaches only Lc ${h(c,1)} on the linkHoverBg wash it actually paints (tier ${S}) \u2014 retune linkHoverBg before changing linkHover; the wash has one consumer while the ink has many.`}):c+B<r&&t.push({id:"link-hover-ordering",severity:"warning",tokens:["linkHover","link"],measured:h(r-c,1),message:`linkHover reads weaker than link on the same canvas (Lc ${h(c,1)} vs ${h(r,1)}) \u2014 a dimming hover feels disabled. Retune linkHover toward more contrast than the resting link.`})}const f=r=>Math.abs(_(P,r))>=Math.abs(_(y,r))?"dark":"light",a=e.tokens.find(r=>r.token==="actionBackground"),i=e.tokens.find(r=>r.token==="actionText"),l=[],u=[];let d=0;const g=i?.anchor?v(i.anchor.color):null,k=i?v(i.resolved):null,p=a?.anchor?v(a.anchor.color):null,E=a?v(a.resolved):null,M=k&&E?k.l>E.l?"light":"dark":null;a?.anchor&&p&&E&&M&&a.anchor.deltaE>=N&&f(p)!==M&&(l.push("actionBackground"),d=Math.max(d,a.anchor.deltaE),u.push(`"${a.anchor.reference}" wants ${f(p)} ink but actionBackground renders carrying a ${M} label (\u0394E ${h(a.anchor.deltaE,4)})`)),i?.anchor&&i.pairing!=="derived"&&g&&k&&p&&E&&i.anchor.deltaE>=N&&p.l!==g.l&&Math.sign(p.l-g.l)!==Math.sign(E.l-k.l)&&(l.push("actionText"),d=Math.max(d,i.anchor.deltaE),u.push(`the declared pair puts "${a.anchor.reference}" ${p.l>g.l?"above":"below"} "${i.anchor.reference}" in lightness and the rendered pair puts it ${E.l>k.l?"above":"below"} (\u0394E ${h(i.anchor.deltaE,4)})`)),l.length>0&&t.push({id:"action-anchor-inversion",severity:"warning",tokens:l,measured:h(d,4),message:`The filled action renders the opposite way round from the swatches it names: ${u.join("; ")}. `+(a?.explicit===void 0?"A filled action's ramp stop is chosen by the engine near its mid-band target, so seating the ramp cannot move it the way it moves every other anchored token. Retune by pinning semanticMappings.actionBackground to a stop that carries the swatch":"semanticMappings.actionBackground is already pinned, so the engine did not place this \u2014 retune the stop that pin names")+" \u2014 and check the pair still clears its tier there, because a swatch this far off the band often cannot hold a label at its own lightness."});const w=e.tokens.filter(r=>r.apca!==void 0&&r.apca.toLc<Math.min(r.apca.targetLc,A)).sort((r,c)=>Math.min(c.apca.targetLc,A)-c.apca.toLc-(Math.min(r.apca.targetLc,A)-r.apca.toLc)||(r.token<c.token?-1:r.token>c.token?1:0));if(w.length>0){const r=w[0].apca,c=w.map(R=>`${R.token} reaches Lc ${h(R.apca.toLc,1)} on ${R.apca.against} (floor ${Math.min(R.apca.targetLc,A)})`),x=v(r.againstColor),U=x!==null&&Math.max(Math.abs(_(P,x)),Math.abs(_(y,x)))>=Math.min(r.targetLc,A);t.push({id:"apca-target-unmet",severity:"warning",tokens:w.map(R=>R.token),measured:h(Math.min(r.targetLc,A)-r.toLc,1),message:`${c.join(", ")} \u2014 enforcement moved the ink as far as this ramp allows and the pair still falls short. `+(U?"The opposite ink pole does clear the floor on that ground, so the emitted ink is on the weaker side rather than the ground being impossible \u2014 check the pairing before retuning the ground.":"No ink reaches the floor on that ground, so retune the ground each pair reads against toward a lightness that can carry it.")})}return t}const F=":root",xe=I({scheme:{kind:"scheme",compared:!0},seedColor:{kind:"string",compared:!0},anchors:{kind:"anchor-record",compared:!0},tokens:{kind:"token-array",compared:!0},adjustedTokens:{kind:"semantic-array",compared:!0},surface:{kind:"string",compared:!0},lints:{kind:"lint-array",compared:!0}}),Oe=I({surfaces:{kind:"string-array",compared:!0},dataPalette:{kind:"data-palette-record",compared:!0},paletteLints:{kind:"palette-lint-record",compared:!0},light:{kind:"report-array",compared:!0},dark:{kind:"report-array",compared:!0},paint:{kind:"paint-record",compared:!1}});function $e(e,t,n={}){const o=j(Y,e),s=j(G,t),m=[F,...[...new Set([...Object.keys(o.contexts),...Object.keys(s.contexts)])].sort()],b=l=>{const u={};for(let d=0;d<C.length;d+=1){const g=C[d],k=`--esp-color-series-${d+1}`,p=l[k];if(p===void 0)throw new Error(`Theme fit report did not emit required property ${k}.`);u[g]=p}return u},L=l=>q(l).map(u=>{const d=h(u.distance,4);return{id:"data-palette-cvd-collision",severity:"warning",series:u.series,simulation:u.simulation,measured:d,threshold:u.threshold,message:K(u)}}),T=(l,u)=>{const d=H(l,u);if(Object.keys(d.properties).length===0)throw new Error(`themeFitReportSuite: ${u} root emitted no properties for seed "${l.seedColor}".`);const g=new Map;n.paintSurfaces!==void 0&&g.set(null,d.properties);const k=[{...d.report,surface:F,lints:V(d.report)}];for(const p of m){if(p===F||!(p in l.contexts))continue;const E=H(l,u,{context:p});n.paintSurfaces!==void 0&&g.set(p,E.properties);const M=E.report;k.push({...M,surface:p,lints:V(M)})}return{dataPalette:b(d.properties),reports:k,paintProperties:g}},f=T(o,"light"),a=T(s,"dark"),i={light:f.dataPalette,dark:a.dataPalette};return{surfaces:m,dataPalette:i,paletteLints:{light:L(i.light),dark:L(i.dark)},light:f.reports,dark:a.reports,...n.paintSurfaces===void 0?{}:{paint:Z({light:f.paintProperties,dark:a.paintProperties},n.paintSurfaces,n.extraEntries)}}}function h(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}function z(e,t){return t===void 0?e:`${e}.${t}`}function ce(e){const t={};for(const[n,o]of Object.entries(e)){if(typeof o=="string"){t[n]=o;continue}for(const[s,m]of Object.entries(o))t[s==="color"?n:z(n,s)]=m}return t}function de(e){const t=v(e.resolved),n=e.requested===void 0?e.resolved:$(e.requested),o={token:e.token,property:e.property,source:e.source,lightness:e.lightness,requested:n,resolved:e.resolved,adjusted:n!==e.resolved,sourceResolved:e.sourceResolved},s=X(e.source);if(s&&e.sourceResolved&&(o.anchor={reference:z(s.name,s.slot),color:$(e.base),deltaE:h(O(e.base,t),4)}),e.contrast){const m=e.contrast.background;o.apca={from:n,to:e.resolved,targetLc:e.contrast.targetLc,against:e.contrast.against,againstColor:$(m),fromLc:h(Math.abs(_(v(n),m)),1),toLc:h(Math.abs(_(t,m)),1)}}return o}function le(e){if(!e.apca)return"";const{targetLc:t,against:n,fromLc:o,toLc:s}=e.apca;return e.adjusted?`Lc ${t} vs ${n} \u2014 pushed from Lc ${o} to Lc ${s}`:`Lc ${t} vs ${n} \u2014 met at Lc ${o}`}function ue(e){return e.anchor?`${e.anchor.reference} \u0394E ${e.anchor.deltaE}`:e.sourceResolved?"":"unresolved \u2014 seed used"}export{F as ROOT_SURFACE,Me as THEME_FIT_ANCHOR_FIELDS,Re as THEME_FIT_APCA_FIELDS,we as THEME_FIT_DATA_PALETTE_LINT_FIELDS,_e as THEME_FIT_DATA_PALETTE_LINT_IDS,ve as THEME_FIT_EXPLICIT_VALUES,Ae as THEME_FIT_LINT_FIELDS,Te as THEME_FIT_LINT_IDS,Ie as THEME_FIT_LINT_SEVERITIES,Le as THEME_FIT_PAIRING_VALUES,xe as THEME_FIT_REPORT_FIELDS,Oe as THEME_FIT_SUITE_FIELDS,be as THEME_FIT_TOKEN_FIELDS,Ee as printThemeFitReport,V as themeFitLints,fe as themeFitReport,$e as themeFitReportSuite,te as themeFitRows};