UNPKG

@zumer/orbit

Version:

Orbit builds radial interfaces with CSS geometry and a small JavaScript layout runtime

177 lines (176 loc) • 31.6 kB
/* * orbit * v.2.3.1 * Author Juan Martin Muda - Zumerlab * License MIT */ (()=>{var st=[{name:"--o-dir-x",syntax:"<number>",inherits:!0,initialValue:"0"},{name:"--o-dir-y",syntax:"<number>",inherits:!0,initialValue:"0"},{name:"--o-value-angle",syntax:"<angle>",inherits:!0,initialValue:"0deg"},{name:"--o-ellipse-x",syntax:"<number>",inherits:!0,initialValue:"1"},{name:"--o-ellipse-y",syntax:"<number>",inherits:!0,initialValue:"1"}],G=Symbol.for("zumer.orbit.properties.v1");function M(i=globalThis){let t=i==null?void 0:i.CSS;if(!(!(t!=null&&t.registerProperty)||i[G])){Object.defineProperty(i,G,{value:!0,configurable:!0});for(let e of st)try{t.registerProperty(e)}catch(s){}}}var P=Symbol.for("zumer.orbit.layout.state.v1"),D=Symbol.for("zumer.orbit.layout.registry.v1"),U=Symbol.for("zumer.orbit.layout.probe.v1"),E="o-arc, o-progress",Q={subtree:!0,childList:!0,characterData:!0,attributes:!0,attributeOldValue:!0};function N(i){var t;for(let e of i.classList||[])if(/^orbit-\d+$/.test(e))return Number(e.slice(6));return(t=i.classList)!=null&&t.contains("orbit")?null:void 0}var K=Symbol.for("zumer.orbit.warned.v1");function p(i,t,e){let s=i[K]||(i[K]=new Set);s.has(t)||(s.add(t),console.warn(`[orbit] ${e}`))}function X(i,t){var e,s;for(let r=i;r;r=r.parentElement||((e=r.getRootNode)==null?void 0:e.call(r).host))if((s=r.matches)!=null&&s.call(r,t))return r;return null}var nt=".satellite, .vector, .side, o-arc, o-progress";function S(i){let t=[...i.classList].slice(0,3).map(e=>"."+e).join("");return`<${i.localName}${t?" "+t:""}>`}function ot(i){let t=i.parentElement,e=X(t.parentElement,".bigbang, .satellite");e?e.getClientRects().length&&(!e.clientWidth||!e.clientHeight)&&p(e,"empty",`${S(e)} has no size (${e.clientWidth}\xD7${e.clientHeight}px), so its system is invisible. Give it a width, or place it in a parent with a width.`):p(t,"universe",'A .gravity-spot is not inside a .bigbang, so it measures the viewport. Wrap it: <div class="bigbang"><div class="gravity-spot">\u2026</div></div>.');let s=i.querySelector(":scope > o-arc, :scope > o-progress");if(s){let r=i.ownerDocument.defaultView.getComputedStyle(i),n=r.getPropertyValue("--o-ellipse-x").trim(),o=r.getPropertyValue("--o-ellipse-y").trim();(n&&Number(n)!==1||o&&Number(o)!==1)&&p(i,"ellipse-visual",`${S(s)} is on ${S(i)}, which is stretched into an ellipse (--o-ellipse-x: ${n||1}, --o-ellipse-y: ${o||1}). Arcs and progress are drawn on circles only, so it is hidden. Put it on a round ring.`)}if(X(i,".dev-orbit")){for(let r of i.children)if(N(r)!==void 0)p(r,"nested-ring",`${S(r)} is inside another ring. Rings must be direct children of .gravity-spot; to nest a system, put a .gravity-spot directly inside a .satellite.`);else if(!r.matches(nt))p(r,"ring-child",`${S(r)} is not placed by its ring. A ring holds only .satellite, .vector, .side, <o-arc> and <o-progress>; wrap content as <div class="satellite"><div class="capsule">\u2026</div></div>.`);else if(r.classList.contains("satellite"))for(let n of r.children)n.matches(".capsule, .gravity-spot, .bigbang")||p(n,"satellite-child",`${S(n)} sits directly in a .satellite. Put content in a .capsule so it stays upright and centered.`)}}function m(i,t,e){let s=String(e);i.getAttribute(t)!==s&&i.setAttribute(t,s)}function g(i,t,e){let s=String(e);i.style.getPropertyValue(t)!==s&&i.style.setProperty(t,s)}function A(i,t,e=0,s="number"){let r=String(t||"").trim();if(!r)return e;if(s==="number"&&/^[+-]?(?:\d+\.?\d*|\.\d+)$/.test(r))return Number(r);let n=r.match(/^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|grad|turn)?$/);if(s==="angle"&&n)return Number(n[1])*({deg:1,rad:180/Math.PI,grad:.9,turn:360}[n[2]]||1);let o=i.ownerDocument;if(!(o!=null&&o.documentElement))return e;let l=o[U];l||(l=o.createElement("span"),l.setAttribute("data-orbit-measure",""),l.setAttribute("aria-hidden","true"),l.style.cssText="all:initial!important;position:fixed!important;visibility:hidden!important;pointer-events:none!important;width:0!important;height:0!important;overflow:hidden!important;",o.documentElement.appendChild(l),Object.defineProperty(o,U,{value:l,configurable:!0}));let a=s==="angle"?"rotate":"scale";if(l.style.removeProperty(a),l.style.setProperty(a,r,"important"),!l.style.getPropertyValue(a))return e;let u=o.defaultView.getComputedStyle(l).getPropertyValue(a),c=parseFloat(u);return Number.isFinite(c)?c:e}function at(i){if(i.localName==="o-arc")return i.hasAttribute("start")?null:"arc";for(let t of["satellite","vector","side"])if(i.classList.contains(t))return t;return null}function lt(i){let t={arc:0,satellite:0,vector:0,side:0};for(let n of i.children){let o=at(n);o?g(n,"--o-layout-index",t[o]++-(o==="side"?1:0)):n.localName==="o-progress"&&g(n,"--o-layout-index",0)}let e=Math.max(t.arc,t.satellite,t.vector,1),s=t.satellite||t.vector,r=t.side?String(t.side):s?`max(1, ${e} - var(--o-fit-range, 0))`:String(e);g(i,"--o-layout-angle",`calc(var(--o-range, 360deg) / ${r})`)}function Y(i){return(i==null?void 0:i.nodeType)===9||(i==null?void 0:i.nodeType)===11&&!!i.host}function T(i){var e;if(Y(i))return i;let t=(e=i==null?void 0:i.getRootNode)==null?void 0:e.call(i);return Y(t)?t:null}function _(i,t){var e,s;for(let r=t;r;r=(e=r.getRootNode)==null?void 0:e.call(r).host)if(i===r||(s=i.contains)!=null&&s.call(i,r))return!0;return!1}function ct(i){return i[D]||Object.defineProperty(i,D,{value:{states:new Set},configurable:!0}),i[D]}function H(i){i.frame<0?i.view.clearTimeout(-i.frame):i.frame&&i.view.cancelAnimationFrame(i.frame),i.frame=0}function tt(i){for(let t of i.waiters.splice(0))t()}function W(i){if(!i.disposed){i.disposed=!0,H(i),tt(i),i.observer.disconnect(),i.resize.disconnect();for(let t of i.listeners)t();i.rings.clear(),i.visuals.clear(),i.dirty.clear(),i.registry.states.delete(i),i.scope[P]===i&&delete i.scope[P]}}function B(i){for(let t of i.states)t.scope.host&&!t.scope.host.isConnected&&W(t)}function F(i,t=i.scope){for(let e of i.registry.states)e!==i&&e.scope.host&&_(t,e.scope.host)&&(e.all=!0,e.queue())}function ut(i){return i.nodeType!==1||i.hasAttribute("data-orbit-measure")?!1:N(i)!==void 0||i.matches(".gravity-spot, o-arc, o-progress")?!0:!!i.querySelector(".gravity-spot, .orbit, [data-orbit-ring], o-arc, o-progress")}function ht(i){return i.nodeType===1&&(i.matches('style, link[rel~="stylesheet"]')||!!i.querySelector('style, link[rel~="stylesheet"]'))}var dt=/^(?:--o-|font|letter-spacing|word-spacing)/;function J(i){let t=new Map;for(let e of String(i||"").split(";")){let s=e.indexOf(":");if(s<0)continue;let r=e.slice(0,s).trim();dt.test(r)&&t.set(r,e.slice(s+1).trim())}return t}function ft(i,t){if(i===t)return!1;let e=J(i),s=J(t);if(e.size!==s.size)return!0;for(let[r,n]of e)if(s.get(r)!==n)return!0;return!1}function pt(i,t){var s;let e=i.attributeName;return e==="class"?!0:e==="style"?ft(i.oldValue,t.getAttribute("style")):!!((s=t.matches)!=null&&s.call(t,E))}function gt(i,t){if(i.type==="childList")return[...i.addedNodes,...i.removedNodes].some(ut);if(i.attributeName!=="class")return!1;let e=i.target;return t.rings.has(e)||e.classList.contains("gravity-spot")||N(e)!==void 0||(i.oldValue||"").split(/\s+/).some(s=>s==="gravity-spot"||s==="orbit"||/^orbit-\d+$/.test(s))}function mt(i){let t=i.nodeType===9?i:i.ownerDocument,e=t.defaultView,s=ct(t);M(e);let r={scope:i,doc:t,view:e,registry:s,rings:new Set,visuals:new Set,dirty:new Set,scan:!0,all:!0,frame:0,disposed:!1,listeners:[],waiters:[]},n=(a,u,c,h)=>{a==null||a.addEventListener(u,c,h),r.listeners.push(()=>a==null?void 0:a.removeEventListener(u,c,h))},o=()=>{if(r.disposed||r.frame)return;let a=()=>{r.frame=0,r.flush()};r.frame=t.visibilityState==="hidden"?-e.setTimeout(a,0):e.requestAnimationFrame(a)};r.queue=o,r.flush=()=>vt(r),r.invalidate=(a=i,u=!0)=>{var c,h;if(u&&(a===i||a===t.documentElement||a===t.head))r.all=!0;else{for(let d of r.rings)(d===a||d.contains(a)||u&&((c=a.contains)!=null&&c.call(a,d)))&&r.dirty.add(d);for(let d of r.visuals)(d===a||d.contains(a)||u&&((h=a.contains)!=null&&h.call(a,d)))&&r.dirty.add(d)}(r.all||r.dirty.size||r.scan)&&o()},r.observer=new e.MutationObserver(a=>{var u,c;if(a.some(h=>h.type==="childList")&&B(s),!r.disposed)for(let h of a){let d=h.target.nodeType===3?h.target.parentElement:h.target;if(!d||(u=d.hasAttribute)!=null&&u.call(d,"data-orbit-measure")||h.type==="attributes"&&!pt(h,d))continue;let v=gt(h,r);v&&(r.scan=!0),h.type==="childList"&&[...h.addedNodes,...h.removedNodes].some(ht)||(c=d.closest)!=null&&c.call(d,"head, style")||d.localName==="link"?(r.all=!0,F(r)):h.type==="attributes"&&F(r,d),r.invalidate(d,h.type==="attributes"||v)}}),r.observer.observe(i,Q),r.resize=new e.ResizeObserver(a=>{for(let u of a)r.dirty.add(u.target);o()});let l=()=>{r.all=!0,F(r),o()};return n(t,"visibilitychange",()=>{t.visibilityState==="hidden"&&r.frame>0&&(H(r),o())}),i===t&&(n(e,"resize",l),n(t.fonts,"loadingdone",l)),n(i,"load",a=>{a.target.localName==="link"&&l()},!0),Object.defineProperty(i,P,{value:r,configurable:!0}),s.states.add(r),o(),r}function L(i){let t=i.nodeType===9?i:i.ownerDocument;if(!(t!=null&&t.defaultView)||!t.documentElement||i.host&&!i.host.isConnected)return null;if(i[P]&&i[P].doc!==t&&W(i[P]),i.host){let e=T(i.host);e&&L(e)}return i[P]||mt(i)}function bt(i){let t=new Set,e=new Map;for(let r of i.scope.querySelectorAll(".gravity-spot > *")){let n=N(r);if(n===void 0)continue;let o=e.get(r.parentElement)||0;r.classList.contains("orbit")&&e.set(r.parentElement,++o);let l=n===null?o:n;r.setAttribute("data-orbit-ring",""),g(r,"--o-layout-number",l===0?1e-5:l),t.add(r),i.dirty.add(r),i.rings.has(r)||i.resize.observe(r)}for(let r of i.rings)if(!t.has(r)){i.resize.unobserve(r),r.removeAttribute("data-orbit-ring");for(let n of["--o-layout-number","--o-layout-angle"])r.style.removeProperty(n)}i.rings=t;let s=new Set(i.scope.querySelectorAll(E));for(let r of i.visuals)s.has(r)||i.resize.unobserve(r);for(let r of s)i.visuals.has(r)||(i.resize.observe(r),i.dirty.add(r));i.visuals=s,i.scan=!1}function vt(i){if(i.disposed)return;if(i.scope.host&&!i.scope.host.isConnected){W(i);return}i.observer.disconnect();let t=[];try{i.scan&&bt(i);let e=i.all?new Set([...i.rings,...i.visuals]):i.dirty,s=new Set;for(let r of e)if(r.isConnected)if(i.rings.has(r)){lt(r),ot(r);for(let n of r.querySelectorAll(E))s.add(n)}else i.visuals.has(r)&&s.add(r);for(let r of i.visuals)s.has(r)&&r.update&&(r.update(),t.push(r));i.dirty=new Set,i.all=!1}finally{i.disposed||i.observer.observe(i.scope,Q)}for(let e of t)e.dispatchEvent(new i.view.Event("o-rendered",{bubbles:!0,composed:!0}));i.frame||tt(i)}function C(i=globalThis.document){var s;let t=T(i);if(!t)return;let e=L(t);e&&((s=i==null?void 0:i.matches)!=null&&s.call(i,E)&&!e.visuals.has(i)&&(e.scan=!0),e.invalidate(i||t))}function j(i=globalThis.document){let t=T(i);if(!t)return;let e=L(t);if(e){B(e.registry);for(let s of e.registry.states)s!==e&&(!s.scope.host||!_(i,s.scope.host))||(s.scan=!0,s.all=!0,H(s),s.flush())}}function et(i=globalThis.document){let t=T(i),e=t&&L(t);if(!e)return Promise.resolve();B(e.registry);let s=[...e.registry.states].filter(r=>r===e||r.scope.host&&_(i,r.scope.host));return Promise.all(s.map(r=>new Promise(n=>{r.waiters.push(n),r.queue()}))).then(()=>{})}var k=class extends(globalThis.HTMLElement||class{}){constructor(){super()}connectedCallback(){for(let t of["value","max"])if(Object.prototype.hasOwnProperty.call(this,t)){let e=this[t];delete this[t],this[t]=e}C(this)}get value(){let t=this.getAttribute("value");return t===null||t.trim()===""?null:Number(t)}set value(t){t==null||t===""?this.removeAttribute("value"):this.setAttribute("value",String(t))}get max(){let t=this.getAttribute("max");return t===null?100:Number(t)}set max(t){t==null||t===""?this.removeAttribute("max"):this.setAttribute("max",String(t))}disconnectedCallback(){this._textFrame&&this.ownerDocument.defaultView.cancelAnimationFrame(this._textFrame),this._textFrame=0}readNumber(t,e,s=0){return A(this,t.getPropertyValue(e),s)}readAngle(t,e,s=0){return A(this,t.getPropertyValue(e),s,"angle")}readValue(){let t=this.getAttribute("value");if(t===null||t.trim()==="")return 0;let e=Number(t);return Number.isFinite(e)?e:(p(this,"value:"+t,`<${this.localName} value="${t}"> is not a number, so nothing is drawn.`),0)}readMax(t){let e=this.getAttribute("max");if(e===null){let r=t==null?void 0:t.getPropertyValue("--o-max").trim();if(!r)return 100;let n=A(this,r,NaN);return n>0?n:(p(this,"o-max:"+r,`--o-max: ${r} on <${this.localName}> must be a positive number, so nothing is drawn.`),0)}let s=Number(e);return s>0?s:(p(this,"max:"+e,`<${this.localName} max="${e}"> must be a positive number, so nothing is drawn.`),0)}getCommonAttributes(t){var v;let e=t.ownerDocument.defaultView.getComputedStyle(t),s=parseFloat(e.getPropertyValue("r")),r=Math.max(0,Number.isFinite(s)?s:(((v=t.parentElement)==null?void 0:v.clientWidth)||0)/2),n=Math.max(1e-5,this.readNumber(e,"--o-orbit-number",1)),o=Math.max(0,this.readNumber(e,"--o-size-ratio",1)),l=Math.max(0,this.readNumber(e,"--o-stroke-width",1)),a=t.getAttribute("shape")||"none",u=Math.max(0,r/n*o-l+.3),c=r>0?Math.min(49.999,u*25/r):0,h=0;t.classList.contains("outer-orbit")?h=c:t.classList.contains("quarter-outer-orbit")?h=c*-.5:t.classList.contains("inner-orbit")?h=c*-1:t.classList.contains("quarter-inner-orbit")&&(h=c*.5);let d=50+h;return{orbitRadius:r,arcHeight:u,realRadius:d,arcAngle:0,shape:a,arcHeightPercentage:c,orbitNumber:n,size:o,strokeWidth:l,style:e}}getProgressAngle(t,e,s=100){return!Number.isFinite(e)||!Number.isFinite(s)||s<=0?0:Math.min(1,Math.max(0,e/s))*Math.max(0,Math.min(360,t))}arcPoint(t,e,s=0,r=0){let n=t+s,o=e+r*Math.PI/180;return{x:50+n*Math.cos(o),y:50+n*Math.sin(o)}}calculateCommonArcParameters(t,e,s,r,n,o,l,a=0){let u=Math.PI/2,c=Math.max(0,Math.min(360,t))*Math.PI/180,h=e+s,d=Math.max(.001,e-s),v=Math.min(c*.49,(a+o*1.25)/r/h),x=Math.min(c*.49,(a+o*1.25)/r/d),$=v-u,w=c-v-u,y=x-u,b=c-x-u,q=this.arcPoint(h,$),f=this.arcPoint(h,w),R=this.arcPoint(d,y),I=this.arcPoint(d,b);return{upperArcStart:q,upperArcEnd:f,innerArcStart:R,innerArcEnd:I,bigRadius:h,smallRadius:d,radius:e,upperAngleStart:$,upperAngleEnd:w,innerAngleStart:y,innerAngleEnd:b}}generatePathData(t,e){switch(t){case"rounded":return this.generateRoundedPath(e);case"circle":case"circle-a":case"bullet":return this.generateCirclePath(e,t);case"circle-b":return this.generateCircleBPath(e);case"arrow":return this.generateArrowPath(e);case"backslash":case"slash":return this.generateSlashPath(e,t);case"zigzag":return this.generateZigzagPath(e);default:return this.generateDefaultPath(e)}}pt(t,e){let s=this.arcPoint(t,e);return`${s.x},${s.y}`}arcTo(t,e,s){let r=Math.max(1,Math.ceil(Math.abs(s-e)/(Math.PI/2)-1e-9)),n=s>=e?1:0,o="";for(let l=1;l<=r;l++)o+=` A ${t},${t} 0 0 ${n} ${this.pt(t,e+(s-e)*l/r)}`;return o}linePath(t,e,s){return`M ${this.pt(t,e)}${this.arcTo(t,e,s)}`}ending(t,e){let{bigRadius:s,smallRadius:r}=t,n=(s-r)/2,o=(s+r)/2,l=Math.min(t.upperAngleEnd-t.upperAngleStart,t.innerAngleEnd-t.innerAngleStart),a=Math.max(0,Math.min(n*e,l*r*.49));return{h:n,middle:o,length:a,angle:a/o}}generateDefaultPath(t){let{bigRadius:e,smallRadius:s,upperAngleStart:r,upperAngleEnd:n,innerAngleStart:o,innerAngleEnd:l}=t;return`M ${this.pt(e,r)}${this.arcTo(e,r,n)} L ${this.pt(s,l)}${this.arcTo(s,l,o)} Z`}generateRoundedPath(t){let{bigRadius:e,smallRadius:s,upperAngleStart:r,upperAngleEnd:n,innerAngleStart:o,innerAngleEnd:l}=t,{length:a}=this.ending(t,.5),u=(h,d)=>` A ${a},${a} 0 0 1 ${this.pt(h,d)}`,c=`M ${this.pt(e,r+a/e)}${this.arcTo(e,r+a/e,n-a/e)}`;return c+=`${u(e-a,n)} L ${this.pt(s+a,l)}${u(s,l-a/s)}`,c+=this.arcTo(s,l-a/s,o+a/s),c+=`${u(s+a,o)} L ${this.pt(e-a,r)}${u(e,r+a/e)} Z`,c}generateCirclePath(t,e){let{bigRadius:s,smallRadius:r,upperAngleStart:n,upperAngleEnd:o,innerAngleStart:l,innerAngleEnd:a}=t,u=e==="bullet"?0:1,c=`M ${this.pt(s,n)}${this.arcTo(s,n,o)} A 1,1 0 0 1 ${this.pt(r,a)}`;return c+=`${this.arcTo(r,a,l)} A 1,1 0 0 ${u} ${this.pt(s,n)} Z`,c}generateCircleBPath(t){let{bigRadius:e,smallRadius:s}=t,{h:r,angle:n}=this.ending(t,1),o=t.upperAngleStart+n,l=t.upperAngleEnd-n,a=`M ${this.pt(e,o)}${this.arcTo(e,o,l)} A ${r},${r} 0 0 1 ${this.pt(s,l)}`;return a+=`${this.arcTo(s,l,o)} A ${r},${r} 0 0 1 ${this.pt(e,o)} Z`,a}generateArrowPath(t){let{bigRadius:e,smallRadius:s}=t,{middle:r,angle:n}=this.ending(t,1.6),o=t.upperAngleStart,l=t.upperAngleEnd,a=`M ${this.pt(e,o)}${this.arcTo(e,o,l-n)}`;return a+=` L ${this.pt(r,l)} L ${this.pt(s,l-n)}`,a+=`${this.arcTo(s,l-n,o)} L ${this.pt(r,o+n)} Z`,a}generateSlashPath(t,e){let{bigRadius:s,smallRadius:r}=t,{angle:n}=this.ending(t,1),o=t.upperAngleStart,l=t.upperAngleEnd,[a,u,c,h]=e==="backslash"?[o,l-n,o+n,l]:[o+n,l,o,l-n];return`M ${this.pt(s,a)}${this.arcTo(s,a,u)} L ${this.pt(r,h)}${this.arcTo(r,h,c)} Z`}generateZigzagPath(t){let{bigRadius:e,smallRadius:s}=t,{middle:r,angle:n}=this.ending(t,1.6),o=t.upperAngleStart,l=t.upperAngleEnd,a=`M ${this.pt(e,o+n)}${this.arcTo(e,o+n,l)}`;return a+=` L ${this.pt(r,l-n)} L ${this.pt(s,l)}`,a+=`${this.arcTo(s,l,o+n)} L ${this.pt(r,o)} Z`,a}updateHitArea(t,e,s,r){let n=Math.max(0,Number(this.getAttribute("hit-width"))||0);if(this.fitCanvas(e,this.hasAttribute("interactive")?n:0),!this.hasAttribute("interactive")||!(r>s)||!(e.orbitRadius>0)){t.removeAttribute("d");return}let o=l=>(l-90)*Math.PI/180;m(t,"d",this.linePath(e.realRadius,o(s),o(Math.min(r,s+360)))),g(t,"stroke-width",`${e.arcHeight+e.strokeWidth+2*n}px`)}fitCanvas(t,e){let s=this.shadowRoot.querySelector("svg"),r=t.orbitRadius/50;if(!s||!(r>0))return;let n=((t.realRadius+t.arcHeightPercentage)*r+t.strokeWidth)*(t.reach||1)+e,o=Math.max(0,Math.ceil(n-t.orbitRadius)),l=o/r;m(s,"viewBox",`${-l} ${-l} ${100+2*l} ${100+2*l}`),g(s,"inset",`${-o}px`)}};var V=class extends k{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML=` <style> :host { --o-fill: var(--o-gray-light); --o-stroke: var(--o-fill); --o-stroke-width: 1; --o-back-fill: transparent; --o-back-stroke: none; --o-back-stroke-width: 1; } svg { position: absolute; inset: 0; width: auto; height: auto; overflow: visible; pointer-events: none; } /* Display element by default: never steals clicks (see orbit-arc). Interaction is opt-in via the "interactive" attribute. */ svg * { pointer-events: none; } :host([interactive]) svg * { pointer-events: visiblePainted; } /* The touch area covers the whole track, whatever its colors. */ .hit { fill: none; stroke: transparent; } :host([interactive]) .hit { pointer-events: stroke; } :host([interactive]) { cursor: pointer; } .progress-bar { fill: var(--o-fill); stroke: var(--o-stroke); stroke-width: var(--o-stroke-width); transition: fill 0.25s, stroke 0.25s; stroke-linejoin: round; } .progress-bg { fill: var(--o-back-fill); stroke: var(--o-back-stroke); stroke-width: var(--o-back-stroke-width); } /* variant="stroke": the thin, legible gauge. The default band is a FILLED donut wedge, so everyone building a thin gauge tripped on --o-fill/--o-back-fill. With this variant the paths are open arcs and the data color lives where you expect it: --o-stroke for the bar, --o-back-stroke for the track. */ /* The stroke variant draws a 2px bar over a gray 1px track unless you set your own values on the element. */ :host([variant="stroke"]) { --o-stroke-width: 2; --o-back-stroke: var(--o-gray-light); } :host([variant="stroke"]) .progress-bar { fill: none; stroke: var(--o-stroke); stroke-width: var(--o-stroke-width, 2); stroke-linecap: round; } :host([variant="stroke"]) .progress-bg { fill: none; stroke: var(--o-back-stroke, var(--o-gray-light)); stroke-width: var(--o-back-stroke-width, 1); stroke-linecap: round; } </style> <svg viewBox="0 0 100 100"> <path class="hit" vector-effect="non-scaling-stroke"></path> <path class="progress-bg" shape-rendering="geometricPrecision" vector-effect="non-scaling-stroke"></path> <path class="progress-bar" shape-rendering="geometricPrecision" vector-effect="non-scaling-stroke"></path> </svg> `}update(){let t=this.getAttributes(),e=this.getAttribute("variant")==="stroke",s=e?this.calculateStrokeArc(t,!0):this.calculateArcParameters(t,!0),r=e?this.calculateStrokeArc(t,!1):this.calculateArcParameters(t,!1);m(this.shadowRoot.querySelector(".progress-bg"),"d",s),m(this.shadowRoot.querySelector(".progress-bar"),"d",r),this.updateHitArea(this.shadowRoot.querySelector(".hit"),t,0,t.range);let n=this.parentElement;this._valueRing&&this._valueRing!==n&&this._valueRing.style.removeProperty("--o-value-angle"),this._valueRing=n,n&&g(n,"--o-value-angle",`${this.getProgressAngle(t,!1)}deg`)}disconnectedCallback(){var t;super.disconnectedCallback(),(t=this._valueRing)==null||t.style.removeProperty("--o-value-angle"),this._valueRing=null}calculateStrokeArc(t,e){let{realRadius:s}=t,r=Math.max(0,Math.min(this.getProgressAngle(t,e),360));if(!(r>0)||!(t.orbitRadius>0))return"";let n=-Math.PI/2;return this.linePath(s,n,n+r*Math.PI/180)}getAttributes(){let t=super.getCommonAttributes(this),e=Math.max(0,Math.min(360,this.readAngle(t.style,"--o-range",360))),r=t.style.getPropertyValue("--o-progress").trim()?this.readNumber(t.style,"--o-progress",0):this.readValue(),n=this.readMax(t.style);return{...t,range:e,progress:r,maxValue:n}}getProgressAngle(t,e){let{range:s,progress:r,maxValue:n}=t;return e?s:super.getProgressAngle(s,r,n)}calculateArcParameters(t,e){let{shape:s,realRadius:r,arcHeightPercentage:n,orbitNumber:o,strokeWidth:l,arcHeight:a}=t,u=this.getProgressAngle(t,e);if(!(u>0)||!(t.orbitRadius>0))return"";let c=super.calculateCommonArcParameters(u,r,n,o,s,l,a);return super.generatePathData(s,c)}};var Z=typeof document=="undefined"?null:document.createElement("template");Z&&(Z.innerHTML=` <style> :host { --o-fill: var(--o-gray-light); --o-stroke: var(--o-fill); --o-stroke-width: 1; --o-color: currentcolor; } svg { position: absolute; inset: 0; width: auto; height: auto; overflow: visible; pointer-events: none; } /* Arcs are display elements by default: they must NOT steal clicks from satellites/controls nearby (a painted arc used to capture clicks even at opacity 0, and pointer-events:none on the host could not pierce the shadow). Interaction is opt-in via the "interactive" attribute. */ svg * { pointer-events: none; } :host([interactive]) svg * { pointer-events: visiblePainted; } /* Text lets the pointer through to the band under it: WebKit fires no click on SVG text inside a shadow root. */ :host([interactive]) svg text, :host([interactive]) svg textPath { pointer-events: none; } /* The touch area catches the pointer even where the band is transparent. */ #orbitHit { fill: none; stroke: transparent; } :host([interactive]) #orbitHit { pointer-events: stroke; } :host([interactive]) { cursor: pointer; } #orbitShape { fill: var(--o-fill); stroke: var(--o-stroke); stroke-width: var(--o-stroke-width); transition: fill 0.25s, stroke 0.25s; } text { fill: var(--o-color); } /* Guides for text: never painted and never under the pointer. */ #orbitPath, #measure { fill: none; stroke: none; pointer-events: none; } /* .ripple: a copy of the band grows out from the center of the ring and fades, over and over. The band itself stays. */ #orbitWave { display: none; fill: var(--o-ripple-color, var(--o-fill)); stroke: none; pointer-events: none; transform-origin: 50px 50px; } :host(.ripple) #orbitWave { display: inline; animation: orbit-ripple var(--o-ripple-duration, 1.6s) ease-out infinite; } @keyframes orbit-ripple { from { transform: scale(1); opacity: .9; } to { transform: scale(var(--o-ripple-scale, 1.14)); opacity: 0; } } @media (prefers-reduced-motion: reduce) { :host(.ripple) #orbitWave { display: none; } } </style> <svg viewBox="0 0 100 100"> <path id="orbitHit" vector-effect="non-scaling-stroke"></path> <path id="orbitWave" shape-rendering="geometricPrecision"></path> <path id="orbitShape" shape-rendering="geometricPrecision" vector-effect="non-scaling-stroke"></path> <path id="orbitPath" shape-rendering="geometricPrecision" vector-effect="non-scaling-stroke"></path> <text> <textPath href="#orbitPath" alignment-baseline="middle"></textPath> </text> <text id="measure" visibility="hidden" aria-hidden="true"></text> </svg> `);var z=class extends k{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Z.content.cloneNode(!0))}update(){let t=this.getAttributes(),{fitRange:e,stacked:s}=t;if(s){let c=t.auto&&this.hasAttribute("text-anchor")&&{middle:-.5,end:-1}[t.textAnchor]||0;g(this,"--o-arc-start",`${t.stackOffset+c*t.arcAngle}deg`),c?g(this,"--o-arc-anchor",`${c*t.arcAngle}deg`):this.style.removeProperty("--o-arc-anchor"),g(this,"--o_stack",t.stackOffset+t.arcAngle)}else this.style.removeProperty("--o-arc-start"),this.style.removeProperty("--o-arc-anchor"),this.style.removeProperty("--o_stack");t.flipAuto&&(t.flip=this.readsUpsideDown(t));let r=this.shadowRoot.querySelector("#orbitPath"),n=this.shadowRoot.querySelector("#orbitShape"),o=this.shadowRoot.querySelector("textPath"),{dShape:l}=this.calculateArcParameters(t);m(n,"d",l),m(this.shadowRoot.querySelector("#orbitWave"),"d",l),m(r,"d",this.calculateTextArcParameters(t).dPath),this.updateHitArea(this.shadowRoot.querySelector("#orbitHit"),t,0,t.arcAngle);let a=t.textAnchor,u={start:"0%",middle:"50%",end:"100%"}[a];u&&(m(o,"startOffset",u),m(o,"text-anchor",a)),e?m(o.parentElement,"textLength",r.getTotalLength()):o.parentElement.removeAttribute("textLength"),g(o.parentElement,"font-size",t.svgFontSize),o.textContent!==this.textContent&&(o.textContent=this.textContent),t.auto||this.warnIfTextOverflows(r,o,e)}warnIfTextOverflows(t,e,s){let r=(this.textContent||"").trim();!r||s||!this.isConnected||(this._textFrame&&this.ownerDocument.defaultView.cancelAnimationFrame(this._textFrame),this._textFrame=this.ownerDocument.defaultView.requestAnimationFrame(()=>{if(this._textFrame=0,!!this.isConnected)try{let n=t.getTotalLength(),o=e.parentElement.getComputedTextLength();n>0&&o>n&&this._truncWarned!==r&&(this._truncWarned=r,console.warn(`[orbit] <o-arc> text "${r.length>34?r.slice(0,34)+"\u2026":r}" overflows its arc (${Math.round(o)} > ${Math.round(n)} units) and will clip. Shorten the text, widen --o-range, add range="auto" to fit the arc to the text, or fit-range to squeeze it.`))}catch(n){}}))}getAttributes(){let t=super.getCommonAttributes(this),{style:e}=t,s=Math.max(0,Math.min(360,this.readAngle(e,"--o-range",360))),r=this.getAttribute("flip")==="auto"||this.classList.contains("flip-auto"),n=!r&&(this.hasAttribute("flip")||this.classList.contains("flip")),o=this.hasAttribute("fit-range")||this.classList.contains("fit-range"),l=t.orbitRadius*24/t.orbitNumber||100,a=this.getAttribute("text-anchor")||"middle",u=e.fontSize||"16px",c=Math.max(0,this.readNumber(e,"--o-gap",1)),h=`calc(${u} * (100 / (${l}) * (12 / var(--o-orbit-number)))`,d=this.getAttribute("range")==="auto",v=this.hasAttribute("value"),x=this.hasAttribute("start"),$=d||v||x,w=this.readMax(e),y;d?y=this.measureTextAngle(h,t.realRadius,c):v?y=super.getProgressAngle(s,this.readValue(),w):y=Math.max(0,Math.min(360,this.readAngle(e,"--o-angle",0))),this._autoAngle=d?y:0;let b=0;if(x){if(b=w>0?this.readStart()/w*s:0,!d&&s<360){let f=Math.min(s,b+y);b=Math.max(0,b),y=Math.max(0,f-b)}}else if($)for(let f=this.previousElementSibling;f;f=f.previousElementSibling){if(f.localName!=="o-arc"||f.hasAttribute("start"))continue;let R=this.ownerDocument.defaultView.getComputedStyle(f);if(f.getAttribute("range")==="auto")b+=f._autoAngle||0;else if(f.hasAttribute("value")){let I=this.readMax.call(f,R),it=A(f,R.getPropertyValue("--o-range"),s,"angle");b+=super.getProgressAngle(it,Number(f.getAttribute("value")),I)}else b+=A(f,R.getPropertyValue("--o-angle"),0,"angle")}let q=this.classList.contains("ripple")?Math.max(1,this.readNumber(e,"--o-ripple-scale",1.14)):1;return{...t,gap:c,max:w,arcAngle:y,stackOffset:b,flip:n,flipAuto:r,fitRange:o,length:l,fontSize:u,svgFontSize:h,textAnchor:a,auto:d,placed:x,stacked:$,reach:q}}readStart(){let t=this.getAttribute("start"),e=Number(t);return Number.isFinite(e)?e:(p(this,"start:"+t,`<o-arc start="${t}"> is not a number, so the arc starts at 0.`),0)}measureTextAngle(t,e,s){let r=(this.textContent||"").trim();if(!r||!(e>0))return 0;let n=this.shadowRoot.querySelector("#measure");n.style.fontSize=t,n.textContent=r;let o=0;try{o=n.getComputedTextLength()+parseFloat(this.ownerDocument.defaultView.getComputedStyle(n).fontSize)}catch(l){}return o>0?Math.min(360,o/e*180/Math.PI+s):0}calculateArcParameters(t){let{arcAngle:e,realRadius:s,arcHeightPercentage:r,orbitNumber:n,shape:o,strokeWidth:l,arcHeight:a,gap:u}=t;if(!(e>0)||!(t.orbitRadius>0))return{dShape:""};let c=super.calculateCommonArcParameters(e,s,r,n,o,l,a,u);return{dShape:super.generatePathData(o,c)}}readsUpsideDown(t){let e=t.style.rotate,r=(((!e||e==="none"?0:A(this,e,0,"angle"))+t.arcAngle/2)%360+360)%360;return r>90&&r<270}calculateTextArcParameters(t){let{arcAngle:e,realRadius:s,gap:r,flip:n}=t;if(!(e>0))return{dPath:""};let o=Math.min(r*.5,e*.49),l=(o-90)*Math.PI/180,a=(e-o-90)*Math.PI/180;return{dPath:n?this.linePath(s,a,l):this.linePath(s,l,a)}}resolveAngle(t){return A(this,t,0,"angle")}calcularExpresionCSS(t){return this.resolveAngle(t)}};var O=new WeakMap,yt=/^[+-]?(?:\d+\.?\d*|\.\d+)px$/,rt={refresh:j,ready:et,resize(i){var o,l;let t=typeof i=="string"?(o=globalThis.document)==null?void 0:o.querySelector(i):i;if(!(t!=null&&t.ownerDocument))return console.error("Orbit.resize: element not found:",i),()=>{};(l=O.get(t))==null||l();let e=t.ownerDocument.defaultView,s=a=>{if(!(a>0))return;let u=0;for(let c of t.querySelectorAll(".gravity-spot")){if(!yt.test(e.getComputedStyle(c).getPropertyValue("--o-force").trim()))continue;u++;let h=String(a/500);c.style.getPropertyValue("--o-force-ratio")!==h&&c.style.setProperty("--o-force-ratio",h)}u||p(t,"resize","Orbit.resize() has nothing to do here: every .bigbang already scales with its container. It only scales systems that set a fixed px --o-force."),j(t)},r=new e.ResizeObserver(a=>{for(let u of a)s(u.contentRect.width)});r.observe(t),s(t.clientWidth||t.getBoundingClientRect().width);let n=()=>{r.disconnect(),O.get(t)===n&&O.delete(t)};return O.set(t,n),n}};function At(){typeof customElements=="undefined"||typeof document=="undefined"||(M(window),customElements.get("o-progress")||customElements.define("o-progress",V),customElements.get("o-arc")||customElements.define("o-arc",z),C(document),window.Orbit=rt)}At();})();