@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
5 lines • 14.1 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{h as e,r as n,H as t}from"./index-BQlHOxik.js";import{B as i}from"./variant-quote-y0Z1TRdz.js";import{t as o}from"./i18n-Br16IAnY.js";import"./common-Cx_AGO_M.js";import{c as a,b as r,n as l}from"./normalizers-m3s9sgmq.js";import{l as s}from"./label-KTv-zMW0.js";import{m as h,u as m,c}from"./value-number-clamped-47tM199y.js";import{B as d}from"./base-controller-CXhqh4cR.js";import"./i18n-B2d_exHc.js";import"./_Uint8Array-kJHDjtoP.js";import"./isArray-CcrBs4JM.js";const u=a("high",0,r);const p=a("low",0,r);const b=a("min",0,r);const f=a("optimum",0,r);const k=["horizontal","vertical"];const v=a("orientation","horizontal",(e=>{const n=l(e);if(k.includes(n)){return n}throw new Error(`Invalid orientation: ${n}`)}));const g=a("value",0,r,(e=>e>=0));function w(e,n,t,i,o,a){const r=i!==null&&i!==void 0?i:n;const l=o!==null&&o!==void 0?o:t;if(a===undefined){const n=e>=r&&e<=l;return n?"optimum":"suboptimal"}const s=e<r;const h=e>l;const m=!s&&!h;const c=a<r;const d=a>l;if(c){if(s)return"optimum";if(m)return"suboptimal";return"critical"}else if(d){if(h)return"optimum";if(m)return"suboptimal";return"critical"}else{if(m)return"optimum";return"suboptimal"}}const y=n=>{const{high:t,label:i,low:a,liveValue:r,max:l,min:s,optimum:h,orientation:m,unit:c,value:d}=n;const u=m==="vertical";const p=c==="%";const b=p?Math.round((d-s)/(l-s)*100):d;const f=p?`${Math.round((r-s)/(l-s)*100)}`:r;const k=w(d,s,l,a,t,h);const v=a!==undefined||t!==undefined;const g=v?o(`kol-meter-state-${k}`):"";const y=p?o("kol-live-value",{placeholders:{value:String(f),unit:c}}):o("kol-live-value-bounded",{placeholders:{value:String(f),max:String(l),unit:c}});const x=v?`${y} – ${g}`:y;const _=l.toString().length>s.toString().length?l.toString().length+"ch":s.toString().length+"ch";return e("div",{class:{"kol-meter":true,"kol-meter--vertical":u}},e("div",{class:"kol-meter__bar"},e("div",{class:"kol-meter__bar-label"},i,v&&e("span",{class:`kol-meter__bar-state kol-meter__bar-state--${k}`}," – ",g)),e("div",{class:"kol-meter__bar-track"},e("meter",{"aria-label":i,high:t,low:a,max:l,min:s,optimum:h,value:d})),e("span",{class:"kol-meter__value-unit"},e("span",{class:"kol-meter__value",style:{"min-width":_}},b),e("span",{class:"kol-meter__unit"},c))),e("span",{"aria-live":"polite","aria-relevant":"additions text",class:"visually-hidden"},x))};const x={optional:[b,v,m],required:[s,h,g]};class _ extends d{constructor(e){super(e,x);this.meterData={high:undefined,low:undefined,optimum:undefined}}componentWillLoad(e){const{high:n,label:t,low:i,max:o,min:a,optimum:r,orientation:l,unit:s,value:h}=e;this.watchHigh(n);this.watchLabel(t);this.watchLow(i);this.watchMax(o);this.watchMin(a);this.watchOptimum(r);this.watchOrientation(l);this.watchUnit(s);this.watchValue(h);this.setState("liveValue",this.getRenderProp("value"));this.startLiveValueInterval()}destroy(){if(this.interval){clearInterval(this.interval);this.interval=undefined}}getMeterData(){return this.meterData}watchHigh(e){if(e===undefined){this.meterData.high=undefined}else{u.apply(e,(e=>{this.meterData.high=e}))}}watchLabel(e){s.apply(e,(e=>{this.setRenderProp("label",e)}))}watchLow(e){if(e===undefined){this.meterData.low=undefined}else{p.apply(e,(e=>{this.meterData.low=e}))}}watchMax(e){h.apply(e,(e=>{this.setRenderProp("max",e);this.watchValue(this.getRawProp("value"))}))}watchMin(e){b.apply(e,(e=>{this.setRenderProp("min",e);this.watchValue(this.getRawProp("value"))}))}watchOptimum(e){if(e===undefined){this.meterData.optimum=undefined}else{f.apply(e,(e=>{this.meterData.optimum=e}))}}watchOrientation(e){v.apply(e,(e=>{this.setRenderProp("orientation",e)}))}watchUnit(e){m.apply(e,(e=>{this.setRenderProp("unit",e)}))}watchValue(e){this.setRawProp("value",e);c.apply(e,(e=>{this.setRenderProp("value",e)}),{min:this.getRenderProp("min"),max:this.getRenderProp("max")})}startLiveValueInterval(){this.interval=setInterval((()=>{const e=this.getRenderProp("value");if(this.getState("liveValue")!==e){this.setState("liveValue",e)}}),5e3)}}const z='/* forward the rem function */\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without verifying the contrast ratio of its background and font colors.\n * By initially setting the background color to white and the font color to black,\n * the contrast ratio is ensured and explicit adjustment is forced.\n */\n color: black;\n background-color: white;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n /*\n * Text should be aligned left by default to provide a predictable starting point.\n */\n text-align: left;\n }\n * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n word-break: break-word;\n }\n /*\n * All interactive elements should have a minimum size of to-rem(44).\n */\n /* input:not([type=\'checkbox\'], [type=\'radio\'], [type=\'range\']), */\n /* option, */\n /* select, */\n /* textarea, */\n button,\n .kol-input .input {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n }\n /*\n * Some interactive elements should not inherit the font-family and font-size.\n */\n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n /*\n * All elements should inherit the text color from his parent element.\n */\n color: inherit;\n /*\n * All elements should inherit the font family from his parent element.\n */\n font-family: inherit;\n /*\n * All elements should inherit the font size from his parent element.\n */\n font-size: inherit;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /**\n * Sometimes we need the semantic element for accessibility reasons,\n * but we don\'t want to show it.\n *\n * - https://www.a11yproject.com/posts/how-to-hide-content/\n */\n .visually-hidden {\n position: fixed;\n top: 0;\n left: 0;\n width: 1px;\n height: 1px;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n}\n@layer kol-global {\n /*\n * Dieses CSS stellt sicher, dass der Standard-Style\n * von A und Button resettet werden.\n */\n :is(a, button) {\n background-color: transparent;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n /* 100% needed for custom width from outside */\n }\n /*\n * Ensure elements with hidden attribute to be actually not visible\n * @see https://meowni.ca/hidden.is.a.lie.html\n */\n [hidden] {\n display: none !important;\n }\n .badge-text-hint {\n color: black;\n background-color: white;\n }\n}\n@layer kol-global {\n :host {\n /*\n * The max-width is needed to prevent the table from overflowing the\n * parent node, if the table is wider than the parent node.\n */\n max-width: 100%;\n font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n }\n * {\n /*\n * We prefer to box-sizing: border-box for all elements.\n */\n box-sizing: border-box;\n }\n .kol-span {\n /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: center;\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n }\n .kol-span__container {\n display: flex;\n align-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .kol-span .kol-span__label--hide-label .kol-span__label {\n display: none;\n }\n /* Reset browser agent style. */\n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n outline: none;\n cursor: not-allowed;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n .hastooltip {\n z-index: 900 !important;\n }\n}\n@layer kol-component {\n .kol-meter {\n --color-optimal: var(--kol-meter-color-optimal, #2ea32e);\n --color-suboptimal: var(--kol-meter-color-suboptimal, #c8a000);\n --color-critical: var(--kol-meter-color-critical, #c00);\n --vertical-height: var(--kol-meter-vertical-height, 128);\n --horizontal-height: var(--kol-meter-horizontal-height, 12);\n }\n .kol-meter__bar {\n display: grid;\n align-items: center;\n grid-template-areas: "label label" "bar value";\n grid-template-columns: 1fr auto;\n }\n .kol-meter__bar-label {\n grid-column-end: 2;\n grid-area: label;\n }\n .kol-meter__bar-track {\n display: flex;\n min-width: 100%;\n grid-area: bar;\n }\n .kol-meter__value-unit {\n grid-area: value;\n }\n .kol-meter:not(.kol-meter--vertical) .kol-meter__value {\n display: inline-block;\n text-align: right;\n }\n .kol-meter--vertical {\n min-height: 100%;\n }\n .kol-meter--vertical .kol-meter__bar {\n min-height: 100%;\n align-items: end;\n justify-items: center;\n grid-template-areas: "label" "bar" "value";\n grid-template-columns: 1fr;\n grid-template-rows: min-content 1fr min-content;\n }\n .kol-meter--vertical .kol-meter__bar-label {\n text-align: center;\n }\n .kol-meter--vertical .kol-meter__bar-track {\n position: relative;\n min-width: 0;\n min-height: calc(var(--vertical-height) * 1rem / var(--kolibri-root-font-size, 16));\n align-items: center;\n }\n .kol-meter--vertical .kol-meter__bar meter {\n transform: rotate(-90deg);\n transform-origin: left bottom;\n position: absolute;\n bottom: 0;\n width: calc(var(--vertical-height) * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-meter {\n /* Base meter styling */\n }\n .kol-meter meter {\n width: 100%;\n height: calc(var(--horizontal-height) * 1rem / var(--kolibri-root-font-size, 16));\n /* Remove default appearance in some browsers */\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n }\n .kol-meter {\n /* Chrome, Safari, Edge (WebKit/Blink) */\n }\n .kol-meter meter::-webkit-meter-bar {\n background: white;\n height: calc(var(--horizontal-height) * 1rem / var(--kolibri-root-font-size, 16));\n border: 1px solid black;\n }\n .kol-meter meter::-webkit-meter-optimum-value {\n background: var(--color-optimal);\n }\n .kol-meter meter::-webkit-meter-suboptimum-value {\n background: var(--color-suboptimal);\n }\n .kol-meter meter::-webkit-meter-even-less-good-value {\n background: var(--color-critical);\n }\n .kol-meter {\n /* Firefox */\n }\n @supports (selector(::-moz-meter-bar)) {\n .kol-meter meter {\n background: white;\n border: 1px solid black;\n }\n }\n .kol-meter meter::-moz-meter-bar {\n background: var(--color-optimal);\n }\n .kol-meter meter:-moz-meter-sub-optimum::-moz-meter-bar {\n background: var(--color-suboptimal);\n }\n .kol-meter meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {\n background: var(--color-critical);\n }\n}';const j=class extends i{constructor(e){super();n(this,e);this.ctrl=new _(this.stateAccess);this._max=1;this._min=0;this._orientation="horizontal";this._unit="%";this.liveValue=0}watchHigh(e){this.ctrl.watchHigh(e)}watchLabel(e){this.ctrl.watchLabel(e)}watchLow(e){this.ctrl.watchLow(e)}watchMax(e){this.ctrl.watchMax(e)}watchMin(e){this.ctrl.watchMin(e)}watchOptimum(e){this.ctrl.watchOptimum(e)}watchOrientation(e){this.ctrl.watchOrientation(e)}watchUnit(e){this.ctrl.watchUnit(e)}watchValue(e){this.ctrl.watchValue(e)}componentWillLoad(){this.ctrl.componentWillLoad({high:this._high,label:this._label,low:this._low,max:this._max,min:this._min,optimum:this._optimum,orientation:this._orientation,unit:this._unit,value:this._value})}disconnectedCallback(){this.ctrl.destroy()}render(){const{high:n,low:i,optimum:o}=this.ctrl.getMeterData();return e(t,{key:"f984ca58fde313ec89e7c3706bcc8abc78ccd0c9"},e(y,{key:"cc748329ed165491feb61315348e0b44c8797197",high:n,label:this.ctrl.getRenderProp("label"),low:i,liveValue:this.liveValue,max:this.ctrl.getRenderProp("max"),min:this.ctrl.getRenderProp("min"),optimum:o,orientation:this.ctrl.getRenderProp("orientation"),unit:this.ctrl.getRenderProp("unit"),value:this.ctrl.getRenderProp("value")}))}static get watchers(){return{_high:["watchHigh"],_label:["watchLabel"],_low:["watchLow"],_max:["watchMax"],_min:["watchMin"],_optimum:["watchOptimum"],_orientation:["watchOrientation"],_unit:["watchUnit"],_value:["watchValue"]}}};j.style={default:z};export{j as kol_meter};
//# sourceMappingURL=kol-meter.entry.js.map