@alixex/ranui-cdn 0.0.0-stage → 1.0.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.
- package/README.md +32 -2
- package/dist/IIFE-LICENSES.md +2415 -0
- package/dist/iife/attachments.iife.js +1 -0
- package/dist/iife/button.iife.js +111 -0
- package/dist/iife/card.iife.js +1 -0
- package/dist/iife/checkbox.iife.js +1 -0
- package/dist/iife/colorpicker.iife.js +111 -0
- package/dist/iife/content.iife.js +1 -0
- package/dist/iife/conversation.iife.js +1 -0
- package/dist/iife/disclosure-row.iife.js +1 -0
- package/dist/iife/dropdown.iife.js +1 -0
- package/dist/iife/fan-gallery.iife.js +1 -0
- package/dist/iife/glass.iife.js +290 -0
- package/dist/iife/icon.iife.js +111 -0
- package/dist/iife/image.iife.js +1 -0
- package/dist/iife/input.iife.js +111 -0
- package/dist/iife/link.iife.js +1 -0
- package/dist/iife/loading.iife.js +1 -0
- package/dist/iife/markdown.iife.js +4048 -0
- package/dist/iife/math.iife.js +206 -0
- package/dist/iife/menubar.iife.js +70 -0
- package/dist/iife/mermaid.iife.js +3700 -0
- package/dist/iife/message.iife.js +111 -0
- package/dist/iife/modal.iife.js +111 -0
- package/dist/iife/player.iife.js +175 -0
- package/dist/iife/popover.iife.js +1 -0
- package/dist/iife/progress.iife.js +1 -0
- package/dist/iife/radar.iife.js +1 -0
- package/dist/iife/reasoning.iife.js +3 -0
- package/dist/iife/route.iife.js +1 -0
- package/dist/iife/router.iife.js +1 -0
- package/dist/iife/scratch.iife.js +1 -0
- package/dist/iife/section.iife.js +1 -0
- package/dist/iife/select.iife.js +111 -0
- package/dist/iife/skeleton.iife.js +1 -0
- package/dist/iife/state-dot.iife.js +1 -0
- package/dist/iife/surface-switch.iife.js +111 -0
- package/dist/iife/tab.iife.js +111 -0
- package/dist/iife/tabpane.iife.js +1 -0
- package/dist/iife/theme-switch.iife.js +111 -0
- package/dist/iife/token-meter.iife.js +2 -0
- package/dist/iife/tool-card.iife.js +4 -0
- package/dist/iife/voice-button.iife.js +1 -0
- package/dist/index.iife.js +47 -0
- package/package.json +30 -3
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
var ranui_glass=(function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=`:host{display:var(--ran-glass-display, inline-block);position:var(--ran-glass-position, relative);border-radius:var(--ran-glass-radius, var(--ran-radius-lg, 16px));isolation:isolate;-webkit-tap-highlight-color:transparent}.ran-glass-defs{position:absolute;width:0;height:0;overflow:hidden;pointer-events:none}.ran-glass{position:relative;box-sizing:border-box;min-width:var(--ran-glass-min-width, 0);min-height:var(--ran-glass-min-height, 0);padding:var(--ran-glass-padding, 0);border-radius:inherit;overflow:hidden;color:var(--ran-glass-ink, var(--ran-backdrop-ink-dark));contain:layout paint;-webkit-backdrop-filter:var(--ran-glass-refraction, saturate(1)) blur(var(--ran-glass-blur, 16px)) saturate(var(--ran-glass-saturate, 170%)) brightness(var(--ran-glass-brightness, 1.06));backdrop-filter:var(--ran-glass-refraction, saturate(1)) blur(var(--ran-glass-blur, 16px)) saturate(var(--ran-glass-saturate, 170%)) brightness(var(--ran-glass-brightness, 1.06));--glass-fill: var(--ran-glass-tint, rgba(255, 255, 255, var(--ran-glass-tint-alpha, .12)));background:var(--glass-fill);border:var(--ran-glass-border, .5px solid rgba(166, 166, 166, .55));box-shadow:var(--ran-glass-shadow, 0 18px 48px rgba(0, 0, 0, .45), 0 0 0 .5px rgba(166, 166, 166, .55), -1.25px 0 0 -.75px rgba(166, 166, 166, .45), 1.25px 0 0 -.75px rgba(166, 166, 166, .45), inset 0 1px 0 rgba(255, 255, 255, .55), inset 0 -1px 0 rgba(255, 255, 255, .22), inset 0 0 0 .5px rgba(255, 255, 255, .28), inset 0 -24px 48px rgba(255, 255, 255, .05), inset 0 24px 48px rgba(255, 255, 255, .04));transition:var(--ran-glass-transition, transform var(--ran-motion-duration-base, .2s) var(--ran-motion-ease-standard, cubic-bezier(.2, 0, 0, 1)))}.ran-glass-specular{position:absolute;inset:0;border-radius:inherit;pointer-events:none;opacity:var(--ran-glass-specular-opacity, var(--ran-glass-specular-strength, 1));background:var(--ran-glass-specular-background, linear-gradient(180deg, rgba(255, 255, 255, .28) 0%, rgba(255, 255, 255, .08) 22%, transparent 48%), linear-gradient(0deg, rgba(255, 255, 255, .18) 0%, transparent 28%), radial-gradient(120% 55% at 50% -8%, rgba(255, 255, 255, .22), transparent 58%))}.ran-glass[data-tone=light]{color:var(--ran-glass-ink, var(--ran-backdrop-ink-light));border:var(--ran-glass-border, .5px solid rgba(219, 219, 219, .9));box-shadow:var(--ran-glass-shadow, 0 18px 48px rgba(0, 0, 0, .25), 0 0 0 .5px rgba(219, 219, 219, .95), -1.25px 0 0 -.75px rgba(219, 219, 219, .85), 1.25px 0 0 -.75px rgba(219, 219, 219, .85), inset 0 1px 0 rgba(255, 255, 255, .85), inset 0 -1px 0 rgba(255, 255, 255, .35), inset 0 0 0 .5px rgba(255, 255, 255, .4), inset 0 -24px 48px rgba(255, 255, 255, .1), inset 0 24px 48px rgba(255, 255, 255, .06))}.ran-glass[data-tone=light] .ran-glass-specular{background:var(--ran-glass-specular-background, linear-gradient(180deg, rgba(255, 255, 255, .42) 0%, rgba(255, 255, 255, .12) 24%, transparent 48%), linear-gradient(0deg, rgba(255, 255, 255, .22) 0%, transparent 30%), radial-gradient(120% 55% at 50% -8%, rgba(255, 255, 255, .32), transparent 58%))}.ran-glass-refraction{position:absolute;inset:0;display:none;border-radius:inherit;pointer-events:none}.ran-glass[data-refracting] .ran-glass-refraction{display:block}.ran-glass-refraction:after{content:"";position:absolute;inset:0;background:var(--glass-fill)}.ran-glass-refraction canvas{position:absolute;inset:0;width:100%;height:100%}.ran-glass-rim{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}.ran-glass-specular:after{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(105deg,transparent 42%,rgba(255,255,255,.4) 50%,transparent 58%);transform:translate(-130%);opacity:0}:host([sheen]) .ran-glass-specular:after{opacity:.7;animation:ran-glass-sheen var(--ran-glass-sheen-duration, 6s) ease-in-out infinite}@keyframes ran-glass-sheen{50%{transform:translate(130%)}}.ran-glass ::slotted(*){position:relative;z-index:1}:host([interactive]) .ran-glass{cursor:pointer}:host([interactive]:hover) .ran-glass{transform:translateY(-2px)}:host([interactive]:active) .ran-glass{transform:translateY(0) scale(.98);transition-duration:var(--ran-motion-duration-fast, .14s)}@media(prefers-reduced-motion:reduce){:host([sheen]) .ran-glass-specular:after{animation:none;opacity:0}.ran-glass{transition:none}}@media(prefers-reduced-transparency:reduce){.ran-glass{backdrop-filter:none;-webkit-backdrop-filter:none;background:var(--ran-glass-reduced-transparency-background, var(--ran-color-bg-elevated));box-shadow:var(--ran-glass-reduced-transparency-shadow, var(--ran-shadow-elevated))}.ran-glass-specular,.ran-glass-refraction{display:none}}`,n=typeof document>`u`,r=/["'&<>]/;function i(e){let t=``+e,n=r.exec(t);if(!n)return t;let i,a=``,o=0,s=0;for(o=n.index;o<t.length;o++){switch(t.charCodeAt(o)){case 34:i=`"`;break;case 38:i=`&`;break;case 39:i=`'`;break;case 60:i=`<`;break;case 62:i=`>`;break;default:continue}s!==o&&(a+=t.substring(s,o)),s=o+1,a+=i}return s===o?a:a+t.substring(s,o)}var a=class{ac=null;get signal(){return this.ac??=new AbortController,this.ac.signal}on(e,t,n,r){return e.addEventListener(t,n,{...r,signal:this.signal}),this}delegate(e,t,n,r,i){return e.addEventListener(n,n=>{let i=n.target?.closest(t);i&&e.contains(i)&&r(n,i)},{...i,signal:this.signal}),this}abort(){this.ac?.abort(),this.ac=null}},o=new Map,s=`data-adopted-style`,c=(e,t,n)=>{if(typeof CSSStyleSheet>`u`)return!1;try{if(!n.has(t)){let e=new CSSStyleSheet;e.replaceSync(t),n.set(t,e)}let r=n.get(t);return e.adoptedStyleSheets.includes(r)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,r]),!0}catch{return!1}},l=(e,t,n=s)=>{if(t){if(typeof document>`u`){let n=e.adoptedStyleSheets;Array.isArray(n)&&!n.includes(t)&&n.push(t);return}if(!c(e,t,o)&&!e.querySelector(`style[${n}]`)){let r=document.createElement(`style`);r.setAttribute(n,``),r.textContent=t,e.appendChild(r)}}},u=0,d=1,f=2,p=null,m=null,h=0,g=new Set,_=!1;function v(e,t){let n=t?.equals??Object.is,r={value:e,observers:new Set};return[()=>(T(r),r.value),e=>{let t=typeof e==`function`?e(r.value):e;if(!n(r.value,t)){r.value=t;for(let e of r.observers)E(e,f);h===0&&D()}}]}function y(e){let t=C(e,!0);return w(t),k(t),()=>j(t)}function b(e){let t=p;p=null;try{return e()}finally{p=t}}function x(e){let t={owned:[],cleanups:[],owner:m},n=m,r=p;m=t,p=null;try{return e(()=>M(t))}finally{m=n,p=r}}function S(e){m&&m.cleanups.push(e)}function C(e,t,n){return{fn:e,sources:new Set,isEffect:t,running:!1,disposed:!1,state:f,observers:new Set,value:void 0,equals:n??Object.is,owned:[],cleanups:[],owner:m}}function w(e){m&&m.owned.push(e)}function T(e){p&&(p.sources.add(e),e.observers.add(p))}function E(e,t){if(e.disposed||e.state>=t)return;let n=e.state===u;if(e.state=t,e.isEffect)g.add(e);else if(n)for(let t of e.observers)E(t,d)}function D(){if(!(h>0||_)){_=!0;try{for(;g.size>0;){let e=[...g];g.clear();for(let t of e)t.disposed||O(t)}}finally{_=!1}}}function O(e){if(!(e.disposed||e.state===u)){if(e.state===d)for(let t of e.sources)`fn`in t&&O(t);e.state===f&&k(e),e.state=u}}function k(e){if(e.running)throw Error(`ranview reactivity: cyclic dependency detected (a computation triggered itself).`);A(e);let t=p,n=m;p=e,m=e,e.running=!0,e.state=u;try{let t=e.fn();if(e.isEffect)typeof t==`function`&&e.cleanups.push(t);else{let n=e.value;if(e.value=t,e.observers.size>0&&!e.equals(n,t))for(let t of e.observers)E(t,f)}}finally{e.running=!1,p=t,m=n}}function A(e){for(let t of e.owned)j(t);e.owned.length=0;for(let t of e.cleanups)t();e.cleanups.length=0;for(let t of e.sources)t.observers.delete(e);e.sources.clear()}function j(e){e.disposed||(e.disposed=!0,A(e),e.observers.clear())}function M(e){for(let t of e.owned)j(t);e.owned.length=0;for(let t of e.cleanups)t();e.cleanups.length=0}function N(e){return i(e)}var ee=e=>typeof e!=`string`&&`tagName`in e&&`childrenList`in e,te=`.#[`;function ne(e){let t=[],n=0,r=/^[a-zA-Z][\w-]*/.exec(e);for(r!==null&&(t.push(r[0]),n=r[0].length);n<e.length;){let r=e[n];if(r===`[`){let r=e.indexOf(`]`,n+1);if(r===-1)return null;t.push(e.slice(n,r+1)),n=r+1;continue}if(r!==`.`&&r!==`#`)return null;let i=n+1;for(;i<e.length&&!te.includes(e[i]);)i+=1;if(i===n+1)return null;t.push(e.slice(n,i)),n=i}return t.length>0?t:null}var re=(e,t)=>{let n=t;if(n.startsWith(`.`))return e.classList.contains(n.slice(1));if(n.startsWith(`#`))return e.getAttribute(`id`)===n.slice(1);if(n.startsWith(`[`)&&n.endsWith(`]`)){let[t,r]=n.slice(1,-1).trim().split(`=`),i=(t||``).trim();if(!i)return!1;if(r==null)return e.hasAttribute(i);let a=r.trim().replace(/^['"]|['"]$/g,``);return e.getAttribute(i)===a}return e.tagName===n.toLowerCase()},ie=(e,t)=>{let n=t.trim();if(!n)return!1;let r=ne(n);return r!==null&&r.every(t=>re(e,t))},P=(e,t,n)=>{for(let r of e)ee(r)&&(ie(r,t)&&n.push(r),P(r.childrenList,t,n))};function F(e,t,n){if(n==null)return e.push(t),t;let r=e.indexOf(n);return r===-1?e.push(t):e.splice(r,0,t),t}var I=class{childrenList=[];appendChild(e){return this.childrenList.push(e),e}insertBefore(e,t){return F(this.childrenList,e,t)}serialize(){return this.childrenList.map(e=>typeof e==`string`?i(e):e.serialize()).join(``)}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return P(this.childrenList,e,t),t}},ae=new Map,L=class{tagName;attributes=new Map;_inlineStyles=null;get inlineStyles(){return this._inlineStyles??ae}childrenList=[];shadowRoot=null;_textContent=null;get textContent(){return this._textContent}set textContent(e){this._textContent=e}content;eventListeners=null;_style=null;_classList=null;get style(){return this._style??={setProperty:(e,t)=>{let n=e.startsWith(`--`)?e:e.replace(/([A-Z])/g,`-$1`).toLowerCase();(this._inlineStyles??=new Map).set(n,t)},removeProperty:e=>this._inlineStyles?.delete(e)??!1}}get classList(){return this._classList??={add:(...e)=>{let t=this.attributes.get(`class`)||``,n=new Set([...t.split(` `).filter(Boolean),...e]);this.attributes.set(`class`,Array.from(n).join(` `))},remove:(...e)=>{let t=(this.attributes.get(`class`)||``).split(` `).filter(t=>!e.includes(t));this.attributes.set(`class`,t.join(` `))},toggle:e=>{this.classList.contains(e)?this.classList.remove(e):this.classList.add(e)},contains:e=>(this.attributes.get(`class`)||``).split(` `).includes(e)}}_innerHTML=``;get innerHTML(){return this._textContent===null?this._innerHTML:i(this._textContent)}set innerHTML(e){this._innerHTML=e,this._textContent=null,this.tagName===`template`&&this.content&&(this.content.childrenList=[e])}constructor(e=`div`){this.tagName=e.toLowerCase(),this.tagName===`template`&&(this.content=new I)}get hidden(){return this.hasAttribute(`hidden`)}set hidden(e){e?this.setAttribute(`hidden`,``):this.removeAttribute(`hidden`)}setAttribute(e,t){this.attributes.set(e,t)}getAttribute(e){return this.attributes.get(e)||null}removeAttribute(e){this.attributes.delete(e)}hasAttribute(e){return this.attributes.has(e)}appendChild(e){return this.childrenList.push(e),e}insertBefore(e,t){return F(this.childrenList,e,t)}attachShadow(e){return this.shadowRoot=new oe(this,e),this.shadowRoot}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return P(this.childrenList,e,t),t}addEventListener(e,t){let n=this.eventListeners??=new Map,r=n.get(e)||new Set;r.add(t),n.set(e,r)}removeEventListener(e,t){let n=this.eventListeners?.get(e);n&&(n.delete(t),n.size===0&&this.eventListeners?.delete(e))}dispatchEvent(e){let t=this.eventListeners?.get(e.type);if(!t||t.size===0)return!0;for(let n of t)typeof n==`function`?n.call(this,e):n.handleEvent(e);return!e.defaultPrevented}serialize(e){typeof this._preSerialize==`function`&&this._preSerialize();let t=e||this._ssrTag||this.tagName;this.shadowRoot&&!this.hasAttribute(`data-ran-dsd`)&&this.setAttribute(`data-ran-dsd`,``);let n=Array.from(this.attributes.entries()).map(([e,t])=>` ${e}="${N(t)}"`).join(``),r=this._inlineStyles?Array.from(this._inlineStyles.entries()).map(([e,t])=>`${e}:${t}`).join(`;`):``,a=r?` style="${N(r)}"`:``,o=``;return this.shadowRoot&&(o+=this.shadowRoot.serialize()),this.textContent===null?this._innerHTML?o+=this._innerHTML:o+=this.childrenList.map(e=>typeof e==`string`?i(e):(e instanceof I,e.serialize())).join(``):o+=i(this.textContent),[`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`].includes(t)&&!o?`<${t}${n}${a} />`:`<${t}${n}${a}>${o}</${t}>`}},oe=class{host;options;childrenList=[];adoptedStyleSheets=[];constructor(e,t){this.host=e,this.options=t}get children(){return this.childrenList.filter(e=>typeof e!=`string`&&!(e instanceof I))}appendChild(e){return this.childrenList.push(e),e}insertBefore(e,t){return F(this.childrenList,e,t)}replaceChildren(...e){this.childrenList=e.filter(e=>e!=null)}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return P(this.childrenList,e,t),t}serialize(){return`<template shadowrootmode="${this.options.mode}"${this.options.delegatesFocus?` shadowrootdelegatesfocus`:``}>${this.adoptedStyleSheets.map(e=>`<style>${String(e).replace(/<\/style/gi,`<\\/style`)}</style>`).join(``)}${this.childrenList.map(e=>typeof e==`string`?i(e):(e instanceof I,e.serialize())).join(``)}</template>`}},R={bind(e,t){t(typeof e==`function`?e():e)},append(e,t){for(let r of t){if(r==null)continue;if(Array.isArray(r)){R.append(e,r);continue}if(typeof r==`function`){R.append(e,[r()]);continue}if(typeof r==`object`&&(`__ranFor`in r||`__ranIndex`in r))throw TypeError(`Import For and Index from the static entry when using static builders`);let t=r instanceof z?r.build():typeof r==`string`&&!n?document.createTextNode(r):r;e.appendChild(t)}}},se=`http://www.w3.org/2000/svg`,ce=new Set(`svg.circle.clipPath.defs.desc.ellipse.feBlend.feColorMatrix.feComposite.feDropShadow.feFlood.feGaussianBlur.feMerge.feMergeNode.feOffset.filter.foreignObject.g.image.line.linearGradient.marker.mask.path.pattern.polygon.polyline.radialGradient.rect.stop.switch.symbol.text.textPath.tspan.use`.split(`.`)),z=class{runtime;el;constructor(e,t,r=R){this.runtime=r;let i=t??(ce.has(e)?`http://www.w3.org/2000/svg`:void 0);this.el=n?new L(e):i?document.createElementNS(i,e):document.createElement(e)}id(e){return this.el.setAttribute(`id`,e),this}bind(e,t){this.runtime.bind(e,t)}class(e){return this.bind(e,e=>{n?this.el.attributes.set(`class`,e):this.el.setAttribute(`class`,e)}),this}addClass(...e){return e.forEach(e=>this.el.classList.add(e)),this}removeClass(...e){return e.forEach(e=>this.el.classList.remove(e)),this}attr(e,t){return this.bind(t,t=>this.el.setAttribute(e,t)),this}attrs(e){return Object.entries(e).forEach(([e,t])=>{t!=null&&this.el.setAttribute(e,String(t))}),this}boolAttr(e,t,n=``){return this.bind(t,t=>{t?this.el.setAttribute(e,n):this.el.removeAttribute(e)}),this}part(e){return this.attr(`part`,e)}data(e,t){return this.attr(`data-${e}`,t)}style(e,t){return typeof e==`string`?this.bind(t??``,t=>this.el.style.setProperty(e,t)):Object.entries(e).forEach(([e,t])=>this.el.style.setProperty(e,t)),this}cssVar(e,t){let n=e.startsWith(`--`)?e:`--${e}`;return this.style(n,t)}aria(e,t){return this.attr(`aria-${e}`,t)}role(e){return this.attr(`role`,e)}tabIndex(e){return this.attr(`tabindex`,String(e))}label(e){return this.aria(`label`,e)}labelledBy(e){return this.aria(`labelledby`,e)}describedBy(e){return this.aria(`describedby`,e)}ariaHidden(e=!0){return this.aria(`hidden`,String(e))}on(e,t,n){return this.el.addEventListener(e,t,n),this}listen(e,t,n,r){return e.on(this.el,t,n,r),this}delegate(e,t,n,r,i){return e.delegate(this.el,t,n,r,i),this}children(...e){return this.runtime.append(this.el,e),this}replaceChildren(...e){if(n){let e=this.el;e.childrenList=[]}else this.el.replaceChildren();return this.children(...e)}text(e){return this.bind(e,e=>{this.el.textContent=e}),this}unsafeHtml(e){return this.bind(e,e=>{this.el.innerHTML=e}),this}ref(e){return e.current=this.el,this}shadow(e={mode:`closed`}){let t=this.el.attachShadow(e);return new le(this.el,t,e,this.runtime)}build(){return this.el}serialize(){if(n)return this.el.serialize();let e=document.createElement(`div`);return e.appendChild(this.el.cloneNode(!0)),e.innerHTML}},le=class{runtime;root;hostEl;constructor(e,t,n,r=R){this.runtime=r,this.hostEl=e,this.root=t}children(...e){return this.runtime.append(this.root,e),this}adoptSheet(...e){return this.root.adoptedStyleSheets=[...this.root.adoptedStyleSheets,...e],this}css(e){if(n)return this.root.adoptedStyleSheets.push(e),this;if(typeof CSSStyleSheet<`u`)try{let t=new CSSStyleSheet;return t.replaceSync(e),this.root.adoptedStyleSheets=[...this.root.adoptedStyleSheets,t],this}catch{}let t=document.createElement(`style`);return t.textContent=e,this.root.appendChild(t),this}done(){return{host:this.hostEl,shadow:this.root}}serialize(){return n?this.root.serialize():this.root.innerHTML}},ue=()=>({current:null}),de=e=>e.reduce((e,t)=>Array.isArray(t)?e.concat(de(t)):e.concat(t),[]),B=e=>e==null?null:e instanceof z?e.build():typeof e==`string`?n?e:document.createTextNode(e):e,fe=(e,t)=>{if(n){V(e,[t()]);return}let r=document.createComment(``),i=document.createComment(``);e.appendChild(r),e.appendChild(i);let a=null,o=()=>{a?.(),a=null;let e=r.nextSibling;for(;e&&e!==i;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}};y(()=>{let e=t();o();let n=document.createDocumentFragment();a=x(t=>(V(n,[e]),t)),i.parentNode?.insertBefore(n,i)}),S(()=>a?.())},pe=`__ranFor`,me=e=>typeof e==`object`&&!!e&&e[pe]===!0,he=(e,t,n)=>{let[r,i]=v(t),a=null,o=x(t=>{let i=B(n(e,r));return a=typeof i==`string`?document.createTextNode(i):i,t});return{node:a,index:i,dispose:o}},ge=(e,t)=>{let n=e.parentNode;if(!n)return;let r=e;for(let e of t)r.nextSibling!==e&&n.insertBefore(e,r.nextSibling),r=e},_e=(e,t)=>{if(n){(t.each()??[]).forEach((n,r)=>{let i=B(t.render(n,()=>r));i!=null&&e.appendChild(i)});return}let r=document.createComment(``);e.appendChild(r);let i=new Map;S(()=>{for(let e of i.values())e.dispose();i.clear()}),y(()=>{let e=t.each()??[],n=new Map,a=[];e.forEach((e,r)=>{let o=t.key(e,r);if(n.has(o)){Ce()&&console.error(`[ranview For] duplicate key "${String(o)}" — keys must be unique; ignoring the duplicate item.`);return}let s=i.get(o);s?(i.delete(o),s.index(r)):s=he(e,r,t.render),n.set(o,s),s.node&&a.push(s.node)});for(let e of i.values())e.node?.parentNode?.removeChild(e.node),e.dispose();ge(r,a),i=n})},ve=`__ranIndex`,ye=e=>typeof e==`object`&&!!e&&e[ve]===!0,be=(e,t,n)=>{let[r,i]=v(e),a=null,o=x(e=>{let i=B(n(r,t));return a=typeof i==`string`?document.createTextNode(i):i,e});return{node:a,setItem:i,dispose:o}},xe=(e,t)=>{if(n){(t.each()??[]).forEach((n,r)=>{let i=B(t.render(()=>n,r));i!=null&&e.appendChild(i)});return}let r=document.createComment(``);e.appendChild(r);let i=[];S(()=>{for(let e of i)e.dispose();i=[]}),y(()=>{let e=t.each()??[];for(let n=0;n<e.length;n++)n<i.length?i[n].setItem(e[n]):i.push(be(e[n],n,t.render));for(let t=i.length-1;t>=e.length;t--){let{node:e}=i[t];e?.parentNode?.removeChild(e),i[t].dispose(),i.pop()}ge(r,i.map(e=>e.node).filter(e=>e!=null))})},V=(e,t)=>{n?b(()=>Se(e,t)):Se(e,t)},Se=(e,t)=>{de(t).forEach(t=>{if(me(t)){_e(e,t);return}if(ye(t)){xe(e,t);return}if(typeof t==`function`){fe(e,t);return}let n=B(t);n!=null&&e.appendChild(n)})},Ce=()=>!1,we={bind(e,t){typeof e==`function`?n?b(()=>t(e())):y(()=>t(e())):t(e)},append:V},Te=class extends z{constructor(e,t){super(e,t,we)}};function Ee(e){let t=t=>new e(t);return{View:t,Div:()=>t(`div`),Svg:t=>new e(t,se),Span:()=>t(`span`),Slot:()=>t(`slot`),ButtonBuilder:()=>t(`button`),InputBuilder:()=>t(`input`),Style:()=>t(`style`),Label:()=>t(`label`),Ul:()=>t(`ul`),Li:()=>t(`li`),Section:()=>t(`section`),Article:()=>t(`article`),Nav:()=>t(`nav`),Header:()=>t(`header`),Footer:()=>t(`footer`),Main:()=>t(`main`),DeclarativeShadow:(e=`open`,n=!1)=>{let r=t(`template`);return r.attr(`shadowrootmode`,e),n&&r.attr(`shadowrootdelegatesfocus`,``),r}}}var{View:De,Div:H,Svg:Oe,Span:ke,Slot:Ae,ButtonBuilder:je,InputBuilder:Me,Style:Ne,Label:Pe,Ul:Fe,Li:Ie,Section:Le,Article:Re,Nav:ze,Header:Be,Footer:Ve,Main:He,DeclarativeShadow:Ue}=Ee(Te),We=new Map;function Ge(e,t){n?(We.set(e,t),t.prototype._ssrTag=e):customElements.get(e)||customElements.define(e,t)}var Ke=typeof document<`u`?HTMLElement:L,qe=`data-ranui`,Je=(e,t)=>{if(typeof document>`u`&&t){let n=e.adoptedStyleSheets;Array.isArray(n)&&!n.includes(t)&&n.push(t)}l(e,t,qe)},Ye=new WeakMap,Xe=new WeakMap,Ze=`@media (prefers-reduced-motion: reduce){*,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important;scroll-behavior:auto !important}}`,Qe=`:host([hidden]){display:none}`,U=new Map,W=e=>{let t=U.get(e);if(t!==void 0)return t;let n=`${Qe}\n${Ze}`,r=e?`${e}\n${n}`:n;return U.set(e,r),r},G=e=>{let t=Xe.get(e);if(t)return t;try{let t=e.attachInternals;if(typeof t!=`function`)return;let n=t.call(e);return Xe.set(e,n),n}catch{return}},$e=(e,t=``,n={mode:`closed`},r)=>{let i=r??G(e),a=e.shadowRoot||Ye.get(e)||i?.shadowRoot||e.attachShadow(n);return Ye.set(e,a),Je(a,W(t)),a},et=(e,t,...n)=>{e.replaceChildren(...n),Je(e,W(t))},K=(e,t)=>{if(e.current===null)throw Error(`ranui: ${t} is missing its .ref() on the builder`);return e.current},q=(e,t,n=``)=>e.getAttribute(t)??n,J=(e,t,n,r={})=>{r.removeEmpty&&!n?e.removeAttribute(t):e.setAttribute(t,n??``)};function tt(e){return e.key===`Enter`||e.key===` `||e.key===`Spacebar`}var nt=`
|
|
2
|
+
struct Uniforms {
|
|
3
|
+
resolution: vec2<f32>,
|
|
4
|
+
radius: f32,
|
|
5
|
+
dpr: f32,
|
|
6
|
+
bevel: f32,
|
|
7
|
+
strength: f32,
|
|
8
|
+
tone: f32,
|
|
9
|
+
pad: f32,
|
|
10
|
+
};
|
|
11
|
+
@group(0) @binding(0) var<uniform> u: Uniforms;
|
|
12
|
+
|
|
13
|
+
fn sdRoundRect(p: vec2<f32>, halfSize: vec2<f32>, r: f32) -> f32 {
|
|
14
|
+
let q = abs(p) - halfSize + r;
|
|
15
|
+
return length(max(q, vec2<f32>(0.0, 0.0))) + min(max(q.x, q.y), 0.0) - r;
|
|
16
|
+
}
|
|
17
|
+
fn hash(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }
|
|
18
|
+
fn noise(v: f32) -> f32 {
|
|
19
|
+
let i = floor(v);
|
|
20
|
+
let f = fract(v);
|
|
21
|
+
return mix(hash(i), hash(i + 1.0), f * f * (3.0 - 2.0 * f));
|
|
22
|
+
}
|
|
23
|
+
fn bell(x: f32, w: f32) -> f32 { return exp(-(x * x) / (w * w)); }
|
|
24
|
+
|
|
25
|
+
@vertex
|
|
26
|
+
fn vs_main(@builtin(vertex_index) idx: u32) -> @builtin(position) vec4<f32> {
|
|
27
|
+
// Same one-triangle-covers-the-viewport trick as the WebGL vertex shader —
|
|
28
|
+
// clip space is identical between the two APIs, so this half needs no change.
|
|
29
|
+
var pos = array<vec2<f32>, 3>(
|
|
30
|
+
vec2<f32>(-1.0, -1.0),
|
|
31
|
+
vec2<f32>(3.0, -1.0),
|
|
32
|
+
vec2<f32>(-1.0, 3.0),
|
|
33
|
+
);
|
|
34
|
+
return vec4<f32>(pos[idx], 0.0, 1.0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A line-for-line port of FRAGMENT_SRC in rim.ts; the comments there explain each term.
|
|
38
|
+
@fragment
|
|
39
|
+
fn fs_main(@builtin(position) fragCoord: vec4<f32>) -> @location(0) vec4<f32> {
|
|
40
|
+
let halfSize = u.resolution * 0.5;
|
|
41
|
+
// WGSL's @builtin(position) already has origin top-left, Y down — the CSS
|
|
42
|
+
// convention rim.ts's GLSL flips to explicitly. No flip needed here.
|
|
43
|
+
let p = fragCoord.xy - halfSize;
|
|
44
|
+
let r = min(u.radius, min(halfSize.x, halfSize.y));
|
|
45
|
+
let d = sdRoundRect(p, halfSize, r);
|
|
46
|
+
let band = max(u.bevel * u.dpr, 4.0 * u.dpr);
|
|
47
|
+
if (d > 2.0 * u.dpr || d < -band) {
|
|
48
|
+
discard;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let eps = max(u.dpr, 1.0);
|
|
52
|
+
let n = normalize(vec2<f32>(
|
|
53
|
+
sdRoundRect(p + vec2<f32>(eps, 0.0), halfSize, r) - sdRoundRect(p - vec2<f32>(eps, 0.0), halfSize, r),
|
|
54
|
+
sdRoundRect(p + vec2<f32>(0.0, eps), halfSize, r) - sdRoundRect(p - vec2<f32>(0.0, eps), halfSize, r),
|
|
55
|
+
) + vec2<f32>(1e-5, 1e-5));
|
|
56
|
+
|
|
57
|
+
let arc = atan2(p.y, p.x) * length(halfSize);
|
|
58
|
+
let grain = 10.0 * u.dpr;
|
|
59
|
+
let thickness = 0.7 + 0.6 * noise(arc / (grain * 3.0) + 13.0);
|
|
60
|
+
let shimmer = 0.6 + 0.8 * noise(arc / grain);
|
|
61
|
+
|
|
62
|
+
let rim = bell(d + u.dpr, 1.2 * u.dpr * thickness + 0.5);
|
|
63
|
+
let inner = bell(d + band * 0.55, 1.4 * u.dpr / thickness + 0.5) * smoothstep(0.2, 0.85, noise(arc / (grain * 9.0) + 41.0));
|
|
64
|
+
|
|
65
|
+
let key = pow(clamp(dot(n, normalize(vec2<f32>(-0.6, -0.8))), 0.0, 1.0), 1.6);
|
|
66
|
+
let fill = pow(clamp(dot(n, normalize(vec2<f32>(0.7, 0.7))), 0.0, 1.0), 3.0);
|
|
67
|
+
|
|
68
|
+
let spacing = grain * 5.0;
|
|
69
|
+
let cell = floor(arc / spacing);
|
|
70
|
+
let glintAt = (cell + 0.2 + 0.6 * hash(cell + 17.0)) * spacing;
|
|
71
|
+
let glint = step(0.72, hash(cell + 7.0)) * bell(arc - glintAt, grain * 0.9) * bell(d + u.dpr, u.dpr) * key;
|
|
72
|
+
|
|
73
|
+
let light = rim * (0.2 + 0.8 * key + 0.35 * fill) * shimmer + inner * (0.45 * key * key + 0.2 * fill) + glint * 1.4;
|
|
74
|
+
|
|
75
|
+
let off = 1.2 * u.dpr;
|
|
76
|
+
let rimR = bell(d + u.dpr - off, 1.2 * u.dpr + 0.5);
|
|
77
|
+
let rimB = bell(d + u.dpr + off, 1.2 * u.dpr + 0.5);
|
|
78
|
+
let fringe = vec3<f32>(rimR, 0.0, rimB) * 0.3 * (key + fill);
|
|
79
|
+
|
|
80
|
+
let shade = u.tone * (rim * 0.55 + inner * 0.12) * (1.0 - 0.7 * key);
|
|
81
|
+
let highlight = mix(light, light * key, u.tone);
|
|
82
|
+
let color = vec3<f32>(highlight) + fringe * (1.0 - u.tone) + vec3<f32>(0.18, 0.23, 0.33) * shade;
|
|
83
|
+
let alpha = clamp(highlight + shade + max(rimR, rimB) * 0.1 * (1.0 - u.tone), 0.0, 1.0);
|
|
84
|
+
let strength = clamp(u.strength, 0.0, 2.0);
|
|
85
|
+
let outAlpha = clamp(alpha * strength, 0.0, 1.0);
|
|
86
|
+
return vec4<f32>(min(color * strength, vec3<f32>(outAlpha)), outAlpha);
|
|
87
|
+
}
|
|
88
|
+
`;async function rt(e){let t=navigator.gpu;if(!t)return null;let n,r=null,i,a=!1,o=()=>{a||(a=!0,r?.unconfigure(),i?.destroy(),n?.destroy())};try{if(n=await(await t.requestAdapter())?.requestDevice(),!n)return null;if(r=e.getContext(`webgpu`),!r)return o(),null;let s=t.getPreferredCanvasFormat();r.configure({device:n,format:s,alphaMode:`premultiplied`});let c=n.createShaderModule({code:nt}),l=n.createRenderPipeline({layout:`auto`,vertex:{module:c,entryPoint:`vs_main`},fragment:{module:c,entryPoint:`fs_main`,targets:[{format:s,blend:{color:{srcFactor:`one`,dstFactor:`one-minus-src-alpha`,operation:`add`},alpha:{srcFactor:`one`,dstFactor:`one-minus-src-alpha`,operation:`add`}}}]},primitive:{topology:`triangle-list`}});i=n.createBuffer({size:32,usage:72});let u=n.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:i}}]}),d=new Float32Array(8),f=n,p=r,m=i;return{lost:n.lost,draw(t,n,r,i){if(a||t<=0||n<=0)return;e.width=t,e.height=n,d.set([t,n,r.radius*i,i,r.bevel,r.strength,+(r.tone===`light`),0]),f.queue.writeBuffer(m,0,d);let o=f.createCommandEncoder(),s=o.beginRenderPass({colorAttachments:[{view:p.getCurrentTexture().createView(),clearValue:{r:0,g:0,b:0,a:0},loadOp:`clear`,storeOp:`store`}]});s.setPipeline(l),s.setBindGroup(0,u),s.draw(3),s.end(),f.queue.submit([o.finish()])},destroy:o}}catch{return o(),null}}var it=`
|
|
89
|
+
attribute vec2 a_position;
|
|
90
|
+
void main() {
|
|
91
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
92
|
+
}
|
|
93
|
+
`,at=`
|
|
94
|
+
// The hash below multiplies values in the thousands; at fp16 mediump that is noise, and the
|
|
95
|
+
// edge texture would no longer match the WebGPU backend's f32.
|
|
96
|
+
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
97
|
+
precision highp float;
|
|
98
|
+
#else
|
|
99
|
+
precision mediump float;
|
|
100
|
+
#endif
|
|
101
|
+
uniform vec2 u_resolution;
|
|
102
|
+
uniform float u_radius;
|
|
103
|
+
uniform float u_dpr;
|
|
104
|
+
uniform float u_bevel;
|
|
105
|
+
uniform float u_strength;
|
|
106
|
+
uniform float u_tone;
|
|
107
|
+
|
|
108
|
+
float sdRoundRect(vec2 p, vec2 halfSize, float r) {
|
|
109
|
+
vec2 q = abs(p) - halfSize + r;
|
|
110
|
+
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
|
|
111
|
+
}
|
|
112
|
+
float hash(float n) { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }
|
|
113
|
+
// Smooth 1D value noise: glass light varies slowly along an edge instead of being one stroke.
|
|
114
|
+
float noise(float u) {
|
|
115
|
+
float i = floor(u);
|
|
116
|
+
float f = fract(u);
|
|
117
|
+
return mix(hash(i), hash(i + 1.0), f * f * (3.0 - 2.0 * f));
|
|
118
|
+
}
|
|
119
|
+
float bell(float x, float w) { return exp(-(x * x) / (w * w)); }
|
|
120
|
+
|
|
121
|
+
void main() {
|
|
122
|
+
vec2 halfSize = u_resolution * 0.5;
|
|
123
|
+
// gl_FragCoord is bottom-up; flip Y so "light from the top-left" reads as
|
|
124
|
+
// top-left on screen, matching the CSS specular gradient's own highlight.
|
|
125
|
+
vec2 p = vec2(gl_FragCoord.x, u_resolution.y - gl_FragCoord.y) - halfSize;
|
|
126
|
+
float r = min(u_radius, min(halfSize.x, halfSize.y));
|
|
127
|
+
float d = sdRoundRect(p, halfSize, r);
|
|
128
|
+
float band = max(u_bevel * u_dpr, 4.0 * u_dpr);
|
|
129
|
+
if (d > 2.0 * u_dpr || d < -band) discard;
|
|
130
|
+
|
|
131
|
+
float eps = max(u_dpr, 1.0);
|
|
132
|
+
vec2 n = normalize(vec2(
|
|
133
|
+
sdRoundRect(p + vec2(eps, 0.0), halfSize, r) - sdRoundRect(p - vec2(eps, 0.0), halfSize, r),
|
|
134
|
+
sdRoundRect(p + vec2(0.0, eps), halfSize, r) - sdRoundRect(p - vec2(0.0, eps), halfSize, r)
|
|
135
|
+
) + 1e-5);
|
|
136
|
+
|
|
137
|
+
// Arc length around the pane, so texture along the edge keeps its scale at any size.
|
|
138
|
+
float arc = atan(p.y, p.x) * length(halfSize);
|
|
139
|
+
float grain = 10.0 * u_dpr;
|
|
140
|
+
float thickness = 0.7 + 0.6 * noise(arc / (grain * 3.0) + 13.0);
|
|
141
|
+
float shimmer = 0.6 + 0.8 * noise(arc / grain);
|
|
142
|
+
|
|
143
|
+
// Two walls: the outer rim, and a fainter line where the bevel meets the flat face.
|
|
144
|
+
float rim = bell(d + u_dpr, 1.2 * u_dpr * thickness + 0.5);
|
|
145
|
+
float inner = bell(d + band * 0.55, 1.4 * u_dpr / thickness + 0.5) * smoothstep(0.2, 0.85, noise(arc / (grain * 9.0) + 41.0));
|
|
146
|
+
|
|
147
|
+
// A key light from the top left and a dim, cool fill from the bottom right.
|
|
148
|
+
float key = pow(clamp(dot(n, normalize(vec2(-0.6, -0.8))), 0.0, 1.0), 1.6);
|
|
149
|
+
float fill = pow(clamp(dot(n, normalize(vec2(0.7, 0.7))), 0.0, 1.0), 3.0);
|
|
150
|
+
|
|
151
|
+
// Short glints where the key light catches an uneven patch of the rim.
|
|
152
|
+
float spacing = grain * 5.0;
|
|
153
|
+
float cell = floor(arc / spacing);
|
|
154
|
+
float glintAt = (cell + 0.2 + 0.6 * hash(cell + 17.0)) * spacing;
|
|
155
|
+
float glint = step(0.72, hash(cell + 7.0)) * bell(arc - glintAt, grain * 0.9) * bell(d + u_dpr, u_dpr) * key;
|
|
156
|
+
|
|
157
|
+
float light = rim * (0.2 + 0.8 * key + 0.35 * fill) * shimmer + inner * (0.45 * key * key + 0.2 * fill) + glint * 1.4;
|
|
158
|
+
|
|
159
|
+
// Chromatic fringe: the rim line split along the normal, warm outside and cool inside.
|
|
160
|
+
float off = 1.2 * u_dpr;
|
|
161
|
+
float rimR = bell(d + u_dpr - off, 1.2 * u_dpr + 0.5);
|
|
162
|
+
float rimB = bell(d + u_dpr + off, 1.2 * u_dpr + 0.5);
|
|
163
|
+
vec3 fringe = vec3(rimR, 0.0, rimB) * 0.3 * (key + fill);
|
|
164
|
+
|
|
165
|
+
// On a pale backdrop a white line vanishes, so the walls are shaded with a cool ink and
|
|
166
|
+
// only the key-lit part keeps a highlight.
|
|
167
|
+
float shade = u_tone * (rim * 0.55 + inner * 0.12) * (1.0 - 0.7 * key);
|
|
168
|
+
float highlight = mix(light, light * key, u_tone);
|
|
169
|
+
vec3 color = vec3(highlight) + fringe * (1.0 - u_tone) + vec3(0.18, 0.23, 0.33) * shade;
|
|
170
|
+
float alpha = clamp(highlight + shade + max(rimR, rimB) * 0.1 * (1.0 - u_tone), 0.0, 1.0);
|
|
171
|
+
float strength = clamp(u_strength, 0.0, 2.0);
|
|
172
|
+
// Premultiplied output: no channel may exceed alpha.
|
|
173
|
+
float outAlpha = clamp(alpha * strength, 0.0, 1.0);
|
|
174
|
+
gl_FragColor = vec4(min(color * strength, vec3(outAlpha)), outAlpha);
|
|
175
|
+
}
|
|
176
|
+
`;function ot(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null}function Y(e){let t=e.getContext(`webgl`,{alpha:!0,premultipliedAlpha:!0,antialias:!0});if(!t)return null;let n=ot(t,t.VERTEX_SHADER,it),r=ot(t,t.FRAGMENT_SHADER,at),i=t.createProgram();if(!n||!r||!i||(t.attachShader(i,n),t.attachShader(i,r),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)))return null;let a=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,a),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),t.STATIC_DRAW);let o=t.getAttribLocation(i,`a_position`),s=e=>t.getUniformLocation(i,e),c=s(`u_resolution`),l=s(`u_radius`),u=s(`u_dpr`),d=s(`u_bevel`),f=s(`u_strength`),p=s(`u_tone`);return t.useProgram(i),t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),{draw(n,r,i,a){n<=0||r<=0||(e.width=n,e.height=r,t.viewport(0,0,n,r),t.uniform2f(c,n,r),t.uniform1f(l,i.radius*a),t.uniform1f(u,a),t.uniform1f(d,i.bevel),t.uniform1f(f,i.strength),t.uniform1f(p,+(i.tone===`light`)),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.drawArrays(t.TRIANGLES,0,3))},destroy(){t.getExtension(`WEBGL_lose_context`)?.loseContext()}}}var st=2;function ct(e){let t={radius:20,bevel:22,strength:1,tone:`dark`},n=!1,r=()=>{let t=document.createElement(`canvas`);return t.className=`ran-glass-rim`,t.setAttribute(`part`,`rim`),t.setAttribute(`aria-hidden`,`true`),e.appendChild(t),t},i=()=>{let e=r();return e.addEventListener(`webglcontextlost`,t=>{t.preventDefault(),a&&o===e&&(a=null)}),e.addEventListener(`webglcontextrestored`,()=>{n||s||o!==e||(a=Y(e),u())}),e},a=null,o=i();a=Y(o);let s=null,c=null,l=()=>{let t=e.getBoundingClientRect(),n=Math.min(typeof window<`u`&&window.devicePixelRatio||1,st);return{width:Math.max(1,Math.round(t.width*n)),height:Math.max(1,Math.round(t.height*n)),dpr:n}},u=()=>{if(n)return;let{width:e,height:r,dpr:i}=l();(s??a)?.draw(e,r,t,i)},d=typeof ResizeObserver<`u`?new ResizeObserver(u):null;return d?.observe(e),u(),typeof navigator<`u`&&navigator.gpu&&(c=r(),c.style.display=`none`,rt(c).then(e=>{n?e?.destroy():e?(s=e,a?.destroy(),a=null,o.remove(),c.style.display=``,u(),e.lost?.then(()=>{n||s!==e||(e.destroy(),s=null,c?.remove(),c=null,o=i(),a=Y(o),u())})):(c?.remove(),c=null)})),{set(e){t=e,u()},destroy(){n||(n=!0,d?.disconnect(),s?.destroy(),a?.destroy(),o.remove(),c?.remove())}}}var lt=(e,t,n)=>Math.max(1,Math.min(n,Math.min(e,t)/2)),ut=(e,t,n,r)=>Math.min(Math.max(n,r),Math.min(e,t)/2),dt=e=>{let t=Math.min(1,Math.max(0,e)),n=t*t*(3-2*t);return n*n*n},ft=(e,t,n,r)=>{let i=new Uint8ClampedArray(e*t*4),a=e/2,o=t/2,s=lt(e,t,r),c=ut(e,t,n,s);for(let n=0;n<t;n++)for(let t=0;t<e;t++){let r=t+.5-a,l=n+.5-o,u=Math.abs(r)-a+c,d=Math.abs(l)-o+c,f,p,m;if(u>0&&d>0){let e=Math.hypot(u,d);m=e-c,f=u/e*Math.sign(r),p=d/e*Math.sign(l)}else u>d?(m=u-c,f=Math.sign(r),p=0):(m=d-c,f=0,p=Math.sign(l));let h=dt(Math.min(1,Math.max(0,1+m/s))),g=(n*e+t)*4;i[g]=128-f*h*127,i[g+1]=128-p*h*127,i[g+2]=Math.round(128+h*127),i[g+3]=255}return i},pt=`#version 300 es
|
|
177
|
+
in vec2 aPosition;
|
|
178
|
+
void main() { gl_Position = vec4(aPosition, 0.0, 1.0); }
|
|
179
|
+
`,mt=`#version 300 es
|
|
180
|
+
precision highp float;
|
|
181
|
+
uniform sampler2D uImage;
|
|
182
|
+
uniform vec2 uTexSize;
|
|
183
|
+
uniform vec2 uSize;
|
|
184
|
+
uniform float uDpr;
|
|
185
|
+
// Pane origin relative to the drawn image content, and the content's size, in CSS px.
|
|
186
|
+
uniform vec2 uOrigin;
|
|
187
|
+
uniform vec2 uContent;
|
|
188
|
+
// The source element's box relative to the pane: nothing outside it is sampled.
|
|
189
|
+
uniform vec4 uClip;
|
|
190
|
+
uniform float uRadius;
|
|
191
|
+
uniform float uBevel;
|
|
192
|
+
uniform float uDisplace;
|
|
193
|
+
uniform float uDispersion;
|
|
194
|
+
uniform float uBlur;
|
|
195
|
+
uniform float uSaturate;
|
|
196
|
+
uniform float uSpecular;
|
|
197
|
+
uniform float uTone;
|
|
198
|
+
out vec4 outColor;
|
|
199
|
+
|
|
200
|
+
const int BANDS = 7;
|
|
201
|
+
|
|
202
|
+
float sdRoundRect(vec2 p, vec2 halfSize, float r) {
|
|
203
|
+
vec2 q = abs(p) - halfSize + r;
|
|
204
|
+
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
|
|
205
|
+
}
|
|
206
|
+
float bell(float x, float w) { return exp(-(x * x) / (w * w)); }
|
|
207
|
+
|
|
208
|
+
// One point of the source, at mip level lod; transparent outside the source element.
|
|
209
|
+
vec4 source(vec2 q, float lod) {
|
|
210
|
+
vec2 uv = (q + uOrigin) / uContent;
|
|
211
|
+
vec2 local = q - uClip.xy;
|
|
212
|
+
float inside = step(0.0, local.x) * step(0.0, local.y) * step(local.x, uClip.z) * step(local.y, uClip.w);
|
|
213
|
+
inside *= step(0.0, uv.x) * step(0.0, uv.y) * step(uv.x, 1.0) * step(uv.y, 1.0);
|
|
214
|
+
return textureLod(uImage, uv, lod) * inside;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// The frosted source: a mip level near the blur radius, smoothed by a ring of taps so the
|
|
218
|
+
// level's blocks do not show.
|
|
219
|
+
vec4 frost(vec2 q, float radius) {
|
|
220
|
+
float texelsPerPx = uTexSize.x / max(uContent.x, 1.0);
|
|
221
|
+
float lod = log2(max(1.0, radius * texelsPerPx * 0.5));
|
|
222
|
+
vec4 sum = source(q, lod) * 2.0;
|
|
223
|
+
for (int i = 0; i < 8; i++) {
|
|
224
|
+
float a = float(i) * 0.785398;
|
|
225
|
+
sum += source(q + vec2(cos(a), sin(a)) * radius * 0.6, lod);
|
|
226
|
+
}
|
|
227
|
+
return sum / 10.0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// How much of red, green and blue a band of the spectrum carries; t runs red (0) to blue (1).
|
|
231
|
+
vec3 spectrum(float t) {
|
|
232
|
+
return vec3(bell(t, 0.42), bell(t - 0.5, 0.3), bell(t - 1.0, 0.42));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
void main() {
|
|
236
|
+
vec2 q = vec2(gl_FragCoord.x, uSize.y * uDpr - gl_FragCoord.y) / uDpr;
|
|
237
|
+
vec2 halfSize = uSize * 0.5;
|
|
238
|
+
vec2 p = q - halfSize;
|
|
239
|
+
float band = clamp(uBevel, 1.0, min(halfSize.x, halfSize.y));
|
|
240
|
+
// Same profile as lens.ts: the lens corner is at least as round as the bevel.
|
|
241
|
+
float r = min(max(uRadius, band), min(halfSize.x, halfSize.y));
|
|
242
|
+
float d = sdRoundRect(p, halfSize, r);
|
|
243
|
+
vec2 n = normalize(vec2(
|
|
244
|
+
sdRoundRect(p + vec2(0.5, 0.0), halfSize, r) - sdRoundRect(p - vec2(0.5, 0.0), halfSize, r),
|
|
245
|
+
sdRoundRect(p + vec2(0.0, 0.5), halfSize, r) - sdRoundRect(p - vec2(0.0, 0.5), halfSize, r)
|
|
246
|
+
) + 1e-5);
|
|
247
|
+
float u = clamp(1.0 + d / band, 0.0, 1.0);
|
|
248
|
+
// Match lens.bendAt: smoothstep then cube — thin liquid lip, soft face.
|
|
249
|
+
float s = u * u * (3.0 - 2.0 * u);
|
|
250
|
+
float bend = s * s * s;
|
|
251
|
+
|
|
252
|
+
// Each band of the spectrum is pulled inward by its own amount: blue the most.
|
|
253
|
+
float spread = uDispersion / 100.0;
|
|
254
|
+
// The texture is premultiplied, so a band that samples past the source's edge adds
|
|
255
|
+
// transparency, not black.
|
|
256
|
+
vec3 color = vec3(0.0);
|
|
257
|
+
vec3 weight = vec3(0.0);
|
|
258
|
+
float alpha = 0.0;
|
|
259
|
+
for (int i = 0; i < BANDS; i++) {
|
|
260
|
+
float t = float(i) / float(BANDS - 1);
|
|
261
|
+
float pull = uDisplace * bend * (1.0 + (t - 0.5) * spread);
|
|
262
|
+
vec4 ink = frost(q - n * pull, max(uBlur, 0.5));
|
|
263
|
+
vec3 w = spectrum(t);
|
|
264
|
+
color += ink.rgb * w;
|
|
265
|
+
alpha += ink.a;
|
|
266
|
+
weight += w;
|
|
267
|
+
}
|
|
268
|
+
color /= weight;
|
|
269
|
+
alpha /= float(BANDS);
|
|
270
|
+
color /= max(alpha, 1e-4);
|
|
271
|
+
|
|
272
|
+
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
|
|
273
|
+
color = mix(vec3(luma), color, uSaturate / 100.0) * 1.05;
|
|
274
|
+
|
|
275
|
+
// The rim reflects the backdrop just outside it, heavily blurred: a curved edge mirrors
|
|
276
|
+
// its surroundings, which is what makes it read as glass rather than a stroke.
|
|
277
|
+
float specular = uSpecular / 100.0;
|
|
278
|
+
vec4 env = frost(q + n * band * 0.8, max(uBlur, 4.0) * 3.0);
|
|
279
|
+
float fresnel = pow(u, 3.0) * 0.45 * specular;
|
|
280
|
+
color = mix(color, env.rgb / max(env.a, 1e-4) * 1.15 + 0.08 * (1.0 - uTone), fresnel * env.a);
|
|
281
|
+
// Light focused by the bevel lands as a soft band just inside it, brightest under the
|
|
282
|
+
// key light at the top left.
|
|
283
|
+
float key = 0.5 + 0.5 * dot(n, normalize(vec2(-0.6, -0.8)));
|
|
284
|
+
color += bell(u - 0.45, 0.18) * key * 0.08 * specular * (1.0 - 0.6 * uTone);
|
|
285
|
+
|
|
286
|
+
float coverage = 1.0 - smoothstep(-0.75, 0.75, d);
|
|
287
|
+
alpha *= coverage;
|
|
288
|
+
outColor = vec4(clamp(color, 0.0, 1.0) * alpha, alpha);
|
|
289
|
+
}
|
|
290
|
+
`,ht=2,X=24,gt=.62,_t=2048,vt=(e,t,n)=>{let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:null):null},yt=e=>{let t=vt(e,e.VERTEX_SHADER,pt),n=vt(e,e.FRAGMENT_SHADER,mt),r=e.createProgram(),i=e.createTexture();if(!t||!n||!r||!i||(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS)))return null;e.useProgram(r),e.bindBuffer(e.ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),e.STATIC_DRAW);let a=e.getAttribLocation(r,`aPosition`);e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0),e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);let o=new Map;return{program:r,texture:i,uniform:t=>(o.has(t)||o.set(t,e.getUniformLocation(r,t)),o.get(t)??null)}},bt=e=>e instanceof HTMLVideoElement?[e.videoWidth,e.videoHeight]:[e.naturalWidth,e.naturalHeight],xt=e=>e instanceof HTMLVideoElement?e.readyState>=2:e.complete&&e.naturalWidth>0,Z=(e,t)=>{if(!e)return t/2;if(e.endsWith(`%`))return t*Number.parseFloat(e)/100;if(e===`left`||e===`top`)return 0;if(e===`right`||e===`bottom`)return t;if(e===`center`)return t/2;let n=Number.parseFloat(e);return Number.isFinite(n)?n:t/2},St=(e,t,n,r)=>{let[i,a]=t;if(n===`fill`||!i||!a)return[e.left,e.top,e.width,e.height];let o=Math.min(e.width/i,e.height/a),s=n===`cover`?Math.max(e.width/i,e.height/a):n===`none`?1:n===`scale-down`?Math.min(1,o):o,c=i*s,l=a*s,[u,d]=r.split(/\s+/);return[e.left+Z(u,e.width-c),e.top+Z(d,e.height-l),c,l]},Ct=(e,t,n,r)=>{if(typeof document>`u`)return null;let i=document.createElement(`canvas`);i.setAttribute(`aria-hidden`,`true`);let a=i.getContext(`webgl2`,{alpha:!0,premultipliedAlpha:!0,antialias:!1});if(!a)return null;let o=yt(a);if(!o)return null;e.appendChild(i);let s=null,c=!1,l=!1,u=!1,d=``,f=-1,p=0,m=!0,h=null,g=-1/0,_=null,v=[1,1],y=()=>{l=!0,T(),r.onActive(!1)},b=()=>{if(!o||!xt(n))return!1;let[e,t]=bt(n),r=Math.min(_t,a.getParameter(a.MAX_TEXTURE_SIZE)),i=Math.min(1,r/Math.max(e,t));try{let r=n;if(i<1){let a=document.createElement(`canvas`);a.width=Math.max(1,Math.floor(e*i)),a.height=Math.max(1,Math.floor(t*i)),a.getContext(`2d`)?.drawImage(n,0,0,a.width,a.height),r=a}a.bindTexture(a.TEXTURE_2D,o.texture),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,r),a.generateMipmap(a.TEXTURE_2D),v=i<1?[r.width,r.height]:[e,t]}catch{return y(),!1}return a.getError()===a.NO_ERROR?(u=!0,!0):(y(),!1)},x=()=>{let e=document.createElement(`canvas`);e.width=X,e.height=X;let t=e.getContext(`2d`,{willReadFrequently:!0});if(t)try{t.drawImage(n,0,0,X,X);let{data:e}=t.getImageData(0,0,X,X);h=new Float32Array(576);for(let t=0;t<h.length;t++)h[t]=(.2126*e[t*4]+.7152*e[t*4+1]+.0722*e[t*4+2])/255}catch{h=null}},S=(e,t,n,i)=>{if(!h)return;let a=0,o=0,s=Math.max(0,Math.floor(e*X)),c=Math.min(23,Math.ceil(n*X)-1),l=Math.max(0,Math.floor(t*X)),u=Math.min(23,Math.ceil(i*X)-1);for(let e=l;e<=u;e++)for(let t=s;t<=c;t++)a+=h[e*X+t],o++;if(!o)return;let d=a/o>gt?`light`:`dark`,f=a/o;_===`light`&&f>.58||_===`dark`&&f<.66||d!==_&&(_=d,r.onTone(d))},C=()=>{if(!o||!s||l)return;let e=t.clientWidth,c=t.clientHeight;if(!e||!c||!i.isConnected)return;if(!n.isConnected){r.onActive(!1);return}let p=n instanceof HTMLVideoElement;if(p&&n.currentTime!==f&&(f=n.currentTime,u=!1),!u&&!b())return;let m=t.getBoundingClientRect(),_=m.left+t.clientLeft,y=m.top+t.clientTop,C=n.getBoundingClientRect(),w=getComputedStyle(n),[T,E,D,O]=St(C,bt(n),w.objectFit,w.objectPosition),k=Math.min(window.devicePixelRatio||1,ht),A=[e,c,k,_,y,C.left,C.top,C.width,C.height,T,E,D,O,f,...Object.values(s)].join();if(A===d)return;d=A,(!h||p&&performance.now()-g>1e3)&&(g=performance.now(),x()),S((_-T)/D,(y-E)/O,(_+e-T)/D,(y+c-E)/O);let j=Math.round(e*k),M=Math.round(c*k);(i.width!==j||i.height!==M)&&(i.width=j,i.height=M,a.viewport(0,0,j,M));let{uniform:N}=o;a.uniform1i(N(`uImage`),0),a.uniform2f(N(`uTexSize`),v[0],v[1]),a.uniform2f(N(`uSize`),e,c),a.uniform1f(N(`uDpr`),k),a.uniform2f(N(`uOrigin`),_-T,y-E),a.uniform2f(N(`uContent`),D,O),a.uniform4f(N(`uClip`),C.left-_,C.top-y,C.width,C.height),a.uniform1f(N(`uRadius`),s.radius),a.uniform1f(N(`uBevel`),lt(e,c,s.bevel)),a.uniform1f(N(`uDisplace`),s.displace),a.uniform1f(N(`uDispersion`),s.dispersion),a.uniform1f(N(`uBlur`),s.blur),a.uniform1f(N(`uSaturate`),s.saturate),a.uniform1f(N(`uSpecular`),s.specular),a.uniform1f(N(`uTone`),+(s.tone===`light`)),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,3),r.onActive(!0)},w=()=>{p=requestAnimationFrame(w),C()};function T(){cancelAnimationFrame(p),p=0}let E=()=>{!p&&m&&!l&&!c&&(p=requestAnimationFrame(w))};E();let D=typeof IntersectionObserver<`u`?new IntersectionObserver(e=>{m=e.some(e=>e.isIntersecting),m?E():T()}):null;D?.observe(t);let O=()=>{u=!1,l=!1,h=null,d=``,E()};return n.addEventListener(`load`,O),n.addEventListener(`loadeddata`,O),i.addEventListener(`webglcontextlost`,e=>{e.preventDefault(),o=null}),i.addEventListener(`webglcontextrestored`,()=>{c||(o=yt(a),u=!1,d=``)}),{source:n,set(e){s=e},destroy(){c||(c=!0,T(),D?.disconnect(),n.removeEventListener(`load`,O),n.removeEventListener(`loadeddata`,O),a.getExtension(`WEBGL_lose_context`)?.loseContext(),i.remove())}}},Q={regular:{blur:16,saturate:170,displace:78,bevel:24,dispersion:20,specular:100,tint:`0.12`},thin:{blur:6,saturate:160,displace:48,bevel:14,dispersion:20,specular:100,tint:`0.08`},thick:{blur:22,saturate:180,displace:56,bevel:28,dispersion:20,specular:90,tint:`0.2`},clear:{blur:4,saturate:150,displace:90,bevel:20,dispersion:25,specular:110,tint:`0.03`}},wt=0,Tt=384,$=class extends Ke{_shadowDom;_glass;_specular;_refractionLayer;_defs=null;_uid=`ran-glass-${wt+=1}`;_events=new a;_tabIndexOwnedByComponent=!1;_rimRenderer=null;_refraction=null;_resize=null;_mutations=null;_lensFrame=0;_lensKey=``;_lensUrl=``;_measuredTone=null;_internals=null;static get observedAttributes(){return[`material`,`blur`,`saturate`,`displace`,`bevel`,`dispersion`,`specular`,`radius`,`tint`,`tone`,`interactive`,`rim`,`backdrop`]}constructor(){super(),this._internals=G(this)??null,this._shadowDom=$e(this,t,{mode:`closed`},this._internals??void 0);let e=ue(),n=ue();this._glass=H().class(`ran-glass`).attr(`part`,`glass`).children(H().class(`ran-glass-refraction`).ref(n).attr(`part`,`refraction`),H().class(`ran-glass-specular`).ref(e).attr(`part`,`specular`),Ae()).build(),et(this._shadowDom,t,this._glass),this._specular=K(e,`specular layer`),this._refractionLayer=K(n,`refraction layer`)}get material(){return q(this,`material`)}set material(e){J(this,`material`,e,{removeEmpty:!0})}get saturate(){return q(this,`saturate`)}set saturate(e){J(this,`saturate`,e,{removeEmpty:!0})}get displace(){return q(this,`displace`)}set displace(e){J(this,`displace`,e,{removeEmpty:!0})}get bevel(){return q(this,`bevel`)}set bevel(e){J(this,`bevel`,e,{removeEmpty:!0})}get dispersion(){return q(this,`dispersion`)}set dispersion(e){J(this,`dispersion`,e,{removeEmpty:!0})}get specular(){return q(this,`specular`)}set specular(e){J(this,`specular`,e,{removeEmpty:!0})}get radius(){return q(this,`radius`)}set radius(e){J(this,`radius`,e,{removeEmpty:!0})}get tint(){return q(this,`tint`)}set tint(e){J(this,`tint`,e,{removeEmpty:!0})}get tone(){return q(this,`tone`)}set tone(e){J(this,`tone`,e,{removeEmpty:!0})}get backdrop(){return q(this,`backdrop`)}set backdrop(e){J(this,`backdrop`,e)}get sheen(){return this.hasAttribute(`sheen`)}set sheen(e){this.toggleAttribute(`sheen`,e)}get interactive(){return this.hasAttribute(`interactive`)}set interactive(e){this.toggleAttribute(`interactive`,e)}get rim(){return this.hasAttribute(`rim`)}set rim(e){this.toggleAttribute(`rim`,e)}get optics(){let e=this._preset,t=t=>{let n=Number.parseFloat(this.getAttribute(t)??``);return Number.isFinite(n)?Math.max(0,n):e[t]};return{blur:t(`blur`),saturate:t(`saturate`),displace:t(`displace`),bevel:t(`bevel`),dispersion:t(`dispersion`),specular:t(`specular`)}}get _preset(){return Object.hasOwn(Q,this.material)?Q[this.material]:Q.regular}get _radius(){let e=Number.parseFloat(this.radius);return Number.isFinite(e)?Math.max(0,e):20}get _tone(){return this.tone===`light`||this.tone===`dark`?this.tone:this._measuredTone??`dark`}_syncStyle(){let e=this.optics,t=this._preset;this.style.setProperty(`--ran-glass-blur`,`${e.blur}px`),this.style.setProperty(`--ran-glass-saturate`,`${e.saturate}%`),this.style.setProperty(`--ran-glass-specular-strength`,`${e.specular/100}`),this._setVar(`--ran-glass-radius`,this.radius,`px`),this._setVar(`--ran-glass-tint`,this.tint),this._setVar(`--ran-glass-tint-alpha`,t.tint);let n=this._tone;this._glass.dataset.tone=n;let r=this._internals?.states;try{r?.delete(n===`light`?`dark`:`light`),r?.add(n)}catch{}}_setVar(e,t,n=``){if(t==null||t===``){this.style.removeProperty(e);return}let r=n&&/^-?\d*\.?\d+$/.test(t.trim());this.style.setProperty(e,r?`${t.trim()}${n}`:t)}_scheduleLens=()=>{this._lensFrame||typeof requestAnimationFrame>`u`||(this._lensFrame=requestAnimationFrame(()=>{this._lensFrame=0,this._renderLens()}))};_renderLens(){if(typeof document>`u`)return;this._defs||(this._defs=document.createElement(`div`),this._defs.className=`ran-glass-defs`,this._defs.setAttribute(`aria-hidden`,`true`),this._shadowDom.insertBefore(this._defs,this._shadowDom.firstChild),this.style.setProperty(`--ran-glass-refraction`,`url(#${this._uid})`));let e=this._glass.offsetWidth,t=this._glass.offsetHeight,{displace:n,bevel:r,dispersion:i}=this.optics,a=e>0&&t>0&&n>0?this._lensImage(e,t,r):``,o=`<feOffset/>`,s=a?Math.ceil(n*1.35):0;if(a){let r=n*2,s=i/100/2,c=`<feImage href="${a}" x="0" y="0" width="${e}" height="${t}" preserveAspectRatio="none" result="lens"/>`,l=(e,t)=>`<feDisplacementMap in="SourceGraphic" in2="lens" scale="${(r*e).toFixed(2)}" xChannelSelector="R" yChannelSelector="G" result="${t}"/>`;if(s<=0)o=c+l(1,`out`);else{let e=[`1 0 0 0 0`,`0 1 0 0 0`,`0 0 1 0 0`],t=(t,n,r)=>`<feColorMatrix in="${n}" type="matrix" values="${e.map((e,n)=>n===t?e:`0 0 0 0 0`).join(` `)} 0 0 0 1 0" result="${r}"/>`;o=c+l(1-s,`dr`)+l(1,`dg`)+l(1+s,`db`)+t(0,`dr`,`r`)+t(1,`dg`,`g`)+t(2,`db`,`b`)+`<feComposite in="r" in2="g" operator="arithmetic" k2="1" k3="1" result="rg"/><feComposite in="rg" in2="b" operator="arithmetic" k2="1" k3="1"/>`}}this._defs.innerHTML=`<svg width="0" height="0"><filter id="${this._uid}" x="${-s}" y="${-s}" width="${(e||1)+s*2}" height="${(t||1)+s*2}" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse" color-interpolation-filters="sRGB">${o}</filter></svg>`}_lensImage(e,t,n){let r=`${e}x${t}:${this._radius}:${n}`;if(r===this._lensKey)return this._lensUrl;let i=Math.min(1,Tt/Math.max(e,t)),a=Math.max(1,Math.round(e*i)),o=Math.max(1,Math.round(t*i)),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=s.getContext(`2d`);return c?(c.putImageData(new ImageData(ft(a,o,this._radius*i,n*i),a,o),0,0),this._lensKey=r,this._lensUrl=s.toDataURL(),this._lensUrl):``}_ensureRim(){this.isConnected&&!this._rimRenderer&&typeof document<`u`&&(this._rimRenderer=ct(this._specular),this._syncRim())}_teardownRim(){this._rimRenderer?.destroy(),this._rimRenderer=null}_syncRim(){let{bevel:e,specular:t}=this.optics;this._rimRenderer?.set({radius:this._radius,bevel:e,strength:t/100,tone:this._tone})}_backdropSource(){if(!this.hasAttribute(`backdrop`))return null;let e=this.backdrop.trim(),t=this.getRootNode(),n=null;try{n=e?t.querySelector(e):this.parentElement?.querySelector(`img, video`)??null}catch{return null}return n instanceof HTMLImageElement||n instanceof HTMLVideoElement?n:null}_syncRefraction(){this._watchBackdrop();let e=this.isConnected?this._backdropSource():null;this._refraction&&this._refraction.source!==e&&this._teardownRefraction(),e&&!this._refraction&&(this._refraction=Ct(this._refractionLayer,this._glass,e,{onActive:e=>{this._glass.hasAttribute(`data-refracting`)!==e&&this._glass.toggleAttribute(`data-refracting`,e)},onTone:e=>{this._measuredTone=e,this._syncStyle(),this._syncRim(),this._syncRefractionParams()}})),this._syncRefractionParams()}_watchBackdrop(){this.isConnected&&this.hasAttribute(`backdrop`)?this._mutations||typeof MutationObserver>`u`||(this._mutations=new MutationObserver(()=>this._syncRefraction()),this._mutations.observe(this.getRootNode(),{childList:!0,subtree:!0})):(this._mutations?.disconnect(),this._mutations=null)}_syncRefractionParams(){this._refraction?.set({...this.optics,radius:this._radius,tone:this._tone})}_teardownRefraction(){this.isConnected&&this.hasAttribute(`backdrop`)||this._watchBackdrop(),this._refraction?.destroy(),this._refraction=null,this._measuredTone=null,this._glass.removeAttribute(`data-refracting`)}_onKeydown=e=>{this.interactive&&tt(e)&&(e.preventDefault(),this.click())};_syncInteractive(){this.interactive?(this.setAttribute(`role`,`button`),this.hasAttribute(`tabindex`)||(this.tabIndex=0,this._tabIndexOwnedByComponent=!0)):(this.removeAttribute(`role`),this._tabIndexOwnedByComponent&&=(this.removeAttribute(`tabindex`),!1))}connectedCallback(){this._syncStyle(),this._renderLens(),this._syncInteractive(),this.rim&&this._ensureRim(),this._syncRefraction(),this._events.on(this,`keydown`,this._onKeydown),typeof ResizeObserver<`u`&&(this._resize=new ResizeObserver(this._scheduleLens),this._resize.observe(this._glass))}disconnectedCallback(){this._events.abort(),this._teardownRim(),this._teardownRefraction(),this._resize?.disconnect(),this._resize=null,this._lensFrame&&cancelAnimationFrame(this._lensFrame),this._lensFrame=0}attributeChangedCallback(e,t,n){t!==n&&(e===`interactive`?this._syncInteractive():e===`rim`?this.rim?this._ensureRim():this._teardownRim():(this._syncStyle(),this.isConnected&&(e===`backdrop`?this._syncRefraction():([`material`,`displace`,`bevel`,`dispersion`,`radius`].includes(e)&&this._scheduleLens(),this._syncRim(),this._syncRefractionParams()))))}};return Ge(`r-glass`,$),e.GLASS_MATERIALS=Q,e.Glass=$,e.default=$,e})({});
|