ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
1 lines • 45.1 kB
JavaScript
var ranui_popover=(function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=class{_events=new Map;tap=(e,t)=>{this._events.get(e)&&e!==Symbol.for(`NEW_LISTENER`)&&this.call(Symbol.for(`NEW_LISTENER`),e);let n=this._events.get(e)||new Set;return typeof t==`function`?n.add({name:e,callback:t}):n.add(t),this._events.set(e,n),this};call=(e,...t)=>((this._events.get(e)||new Set).forEach(e=>{let{callback:n}=e;n(...t)}),this);callSync=async(e,...t)=>{let n=this._events.get(e)||new Set;for(let e of n){let{callback:n}=e;await n(...t)}return this};once=(e,t)=>{let n;if(typeof t==`function`)n={name:e,callback:(...r)=>{t(...r),this.off(e,n)},initialCallback:t};else{let{callback:r}=t;n={name:e,callback:(...t)=>{r(...t),this.off(e,n)},initialCallback:r}}return this.tap(e,n),this};off=(e,t)=>{let n=[...this._events.get(e)||new Set].filter(e=>{if(typeof t==`function`)return e.callback!==t&&e.initialCallback!==t;{let{callback:n}=t;return e.callback!==n&&e.initialCallback!==n}});return this._events.set(e,new Set(n)),this}};Math.PI/180,180/Math.PI,2*Math.PI;var n=(e=8)=>Math.random().toString(36).substring(2,e+2);Object.freeze({});var r=e=>typeof e==`function`,i=12e4,a=`__ranuts_bridge__`,o=`default`,s=new class{bridges=new Set;attachedWindow=null;handleMessage=e=>{for(let t of Array.from(this.bridges))t.receive(e)};add(e){this.bridges.add(e),typeof window<`u`&&this.attachedWindow!==window&&(window.addEventListener(`message`,this.handleMessage),this.attachedWindow=window)}remove(e){this.bridges.delete(e),this.bridges.size===0&&this.attachedWindow&&(this.attachedWindow.removeEventListener(`message`,this.handleMessage),this.attachedWindow=null)}},c=class{targetWindow;targetOrigin;messageHandlers;pendingRequests;channel;senderId;available;constructor(e,t=`*`,r=o){this.targetOrigin=t,this.channel=r,this.senderId=n(12),this.messageHandlers=new Map,this.pendingRequests=new Map,this.available=typeof window<`u`,this.available?(this.targetWindow=e??window,s.add(this)):this.targetWindow=void 0}post(e,t){let n={...t,__bridge:a,channel:this.channel,senderId:this.senderId};e.postMessage(n,this.targetOrigin)}receive=e=>{if(!this.available||this.targetOrigin!==`*`&&e.origin!==this.targetOrigin||e.source&&e.source!==this.targetWindow)return;let t=e.data;if(!t||typeof t!=`object`||t.__bridge!==`__ranuts_bridge__`||(t.channel??`default`)!==this.channel)return;let{type:n,payload:i,id:a,isResponse:o,isError:s,senderId:c}=t;if(o&&a){let e=this.pendingRequests.get(a);e&&(s?e.reject(Error(typeof i==`string`?i:`Bridge request failed`)):e.resolve(i),this.pendingRequests.delete(a));return}if(c&&c===this.senderId||typeof n!=`string`||!this.messageHandlers.has(n))return;let l=this.messageHandlers.get(n);if(r(l)){let t=e.source??this.targetWindow;Promise.resolve(l(i)).then(e=>{a&&this.post(t,{type:n,payload:e,id:a,isResponse:!0})}).catch(e=>{a&&this.post(t,{type:n,payload:e instanceof Error?e.message:String(e),id:a,isResponse:!0,isError:!0})})}};on=(e,t)=>{this.messageHandlers.set(e,t)};off=e=>{this.messageHandlers.delete(e)};send=async(e,t)=>{if(!this.available)return Promise.reject(Error(`PostMessageBridge is unavailable outside a browser environment`));let r=n(10);return new Promise((n,a)=>{let o=setTimeout(()=>{this.pendingRequests.has(r)&&(this.pendingRequests.delete(r),a(Error(`Request timeout`)))},i),s=e=>{clearTimeout(o),a(e)};this.pendingRequests.set(r,{resolve:e=>{clearTimeout(o),n(e)},reject:s});try{this.post(this.targetWindow,{type:e,payload:t,id:r})}catch(e){this.pendingRequests.delete(r),s(e instanceof Error?e:Error(`Failed to post message`))}})};broadcast=e=>{if(this.available)try{this.post(this.targetWindow,{type:e.type,payload:e.payload})}catch{}};destroy=()=>{s.remove(this),this.messageHandlers.clear(),this.pendingRequests.forEach(e=>{e.reject(Error(`Bridge destroyed`))}),this.pendingRequests.clear()}};(class e{static instance;bridges=new Map;constructor(){}static getInstance(){return e.instance||=new e,e.instance}connectClient=({id:e,targetOrigin:t,targetWindow:r,channel:i})=>{let a=new c(r,t,i);if(e||=n(10),this.bridges.has(e))throw Error(`Bridge ${e} already exists`);return this.bridges.set(e,a),{bridge:a,id:e}};getClient=e=>this.bridges.get(e);removeClient=e=>{let t=this.bridges.get(e);t&&(t.destroy(),this.bridges.delete(e))};removeAllClient=()=>{this.bridges.forEach(e=>{e.destroy()}),this.bridges.clear()};broadcast=e=>{this.bridges.forEach(t=>{t.broadcast(e)})};sendTo=(e,t,n)=>{let r=this.getClient(e);return r?r.send(t,n):Promise.reject(Error(`Bridge ${e} not found`))}}).getInstance(),new t;var l=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=class{highOrder;lowOrder;constructor(e,t){this.highOrder=e,this.lowOrder=t}};new u(l[0],3609767458),new u(l[1],602891725),new u(l[2],3964484399),new u(l[3],2173295548),new u(l[4],4081628472),new u(l[5],3053834265),new u(l[6],2937671579),new u(l[7],3664609560),new u(l[8],2734883394),new u(l[9],1164996542),new u(l[10],1323610764),new u(l[11],3590304994),new u(l[12],4068182383),new u(l[13],991336113),new u(l[14],633803317),new u(l[15],3479774868),new u(l[16],2666613458),new u(l[17],944711139),new u(l[18],2341262773),new u(l[19],2007800933),new u(l[20],1495990901),new u(l[21],1856431235),new u(l[22],3175218132),new u(l[23],2198950837),new u(l[24],3999719339),new u(l[25],766784016),new u(l[26],2566594879),new u(l[27],3203337956),new u(l[28],1034457026),new u(l[29],2466948901),new u(l[30],3758326383),new u(l[31],168717936),new u(l[32],1188179964),new u(l[33],1546045734),new u(l[34],1522805485),new u(l[35],2643833823),new u(l[36],2343527390),new u(l[37],1014477480),new u(l[38],1206759142),new u(l[39],344077627),new u(l[40],1290863460),new u(l[41],3158454273),new u(l[42],3505952657),new u(l[43],106217008),new u(l[44],3606008344),new u(l[45],1432725776),new u(l[46],1467031594),new u(l[47],851169720),new u(l[48],3100823752),new u(l[49],1363258195),new u(l[50],3750685593),new u(l[51],3785050280),new u(l[52],3318307427),new u(l[53],3812723403),new u(l[54],2003034995),new u(l[55],3602036899),new u(l[56],1575990012),new u(l[57],1125592928),new u(l[58],2716904306),new u(l[59],442776044),new u(l[60],593698344),new u(l[61],3733110249),new u(l[62],2999351573),new u(l[63],3815920427),new u(3391569614,3928383900),new u(3515267271,566280711),new u(3940187606,3454069534),new u(4118630271,4000239992),new u(116418474,1914138554),new u(174292421,2731055270),new u(289380356,3203993006),new u(460393269,320620315),new u(685471733,587496836),new u(852142971,1086792851),new u(1017036298,365543100),new u(1126000580,2618297676),new u(1288033470,3409855158),new u(1501505948,4234509866),new u(1607167915,987167468),new u(1816402316,1246189591),new u(0,1),new u(0,32898),new u(2147483648,32906),new u(2147483648,2147516416),new u(0,32907),new u(0,2147483649),new u(2147483648,2147516545),new u(2147483648,32777),new u(0,138),new u(0,136),new u(0,2147516425),new u(0,2147483658),new u(0,2147516555),new u(2147483648,139),new u(2147483648,32905),new u(2147483648,32771),new u(2147483648,32770),new u(2147483648,128),new u(0,32778),new u(2147483648,2147483658),new u(2147483648,2147516545),new u(2147483648,32896),new u(0,2147483649),new u(2147483648,2147516424);var d=(e,t=500)=>{let n,r=null,i=null,a=()=>{if(r=null,!i)return;let t=i,a=n;i=null,n=void 0,e.apply(a,t)},o=function(...e){n=this,i=e,r!==null&&clearTimeout(r),r=setTimeout(a,t)};return o.cancel=()=>{r!==null&&clearTimeout(r),r=null,i=null,n=void 0},o.flush=()=>{r!==null&&(clearTimeout(r),a())},o.pending=()=>r!==null,o},f=()=>typeof window<`u`,p=()=>{if(!f())return!1;let e=window.navigator.userAgent;return!!/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(e)},m=(e,t)=>{if(typeof document>`u`)return;let n=e.classList;n.contains(t)||n.add(t)},h=(e,t)=>{if(typeof document>`u`)return;let n=e.classList;n.contains(t)&&n.remove(t)},g=/["'&<>]/;function _(e){let t=``+e,n=g.exec(t);if(!n)return t;let r,i=``,a=0,o=0;for(a=n.index;a<t.length;a++){switch(t.charCodeAt(a)){case 34:r=`"`;break;case 38:r=`&`;break;case 39:r=`'`;break;case 60:r=`<`;break;case 62:r=`>`;break;default:continue}o!==a&&(i+=t.substring(o,a)),o=a+1,i+=r}return o===a?i:i+t.substring(o,a)}var ee=new Map,te=new Map,v=`data-adopted-style`,y=`data-adopted-sheet`,b=(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}},x=(e,t,n=v)=>{if(typeof document<`u`&&t&&!b(e,t,ee)&&!e.querySelector(`style[${n}]`)){let r=document.createElement(`style`);r.setAttribute(n,``),r.textContent=t,e.appendChild(r)}},S=(e,t,n=y)=>{if(typeof document<`u`&&t&&!b(e,t,te)&&!Array.from(e.querySelectorAll(`style[${n}]`)).some(e=>e.textContent===t)){let r=document.createElement(`style`);r.setAttribute(n,``),r.textContent=t,e.appendChild(r)}};(()=>{let e=new Uint8Array(128);for(let t=0;t<78;t++)e[`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.,!?;:'"()[]{}`.charCodeAt(t)]=1;return e})();var C=(e,t,n,r)=>e===`end`?t+n-r:e===`center`?t+(n-r)/2:t,ne=e=>{let{anchor:t,floating:n,offset:r=0,padding:i=8}=e,a=e.boundary??{top:0,left:0,width:typeof window<`u`?window.innerWidth:1/0,height:typeof window<`u`?window.innerHeight:1/0},[o,s]=e.placement.split(`-`),c=s??`start`,l=o,u=l===`top`||l===`bottom`,d=t.width>0&&t.height>0&&n.width>0&&n.height>0;if(d&&u){let e=a.top+a.height-(t.top+t.height),i=t.top-a.top;l===`bottom`&&e<n.height+r&&i>e?l=`top`:l===`top`&&i<n.height+r&&e>i&&(l=`bottom`)}else if(d){let e=a.left+a.width-(t.left+t.width),i=t.left-a.left;l===`right`&&e<n.width+r&&i>e?l=`left`:l===`left`&&i<n.width+r&&e>i&&(l=`right`)}let f=(e,t,n)=>C(c,e,t,n),p,m;if(l===`bottom`?(p=t.top+t.height+r,m=f(t.left,t.width,n.width)):l===`top`?(p=t.top-n.height-r,m=f(t.left,t.width,n.width)):l===`right`?(p=f(t.top,t.height,n.height),m=t.left+t.width+r):(p=f(t.top,t.height,n.height),m=t.left-n.width-r),d&&u){let e=a.left+i,t=a.left+a.width-n.width-i;t>=e&&(m=Math.min(Math.max(m,e),t))}else if(d){let e=a.top+i,t=a.top+a.height-n.height-i;t>=e&&(p=Math.min(Math.max(p,e),t))}return{top:p,left:m,placement:s?`${l}-${c}`:l,side:l,align:c}},w=new Map([[100,`Continue`],[101,`Switching Protocols`],[102,`Processing`],[103,`Early Hints`],[200,`OK`],[201,`Created`],[202,`Accepted`],[203,`Non-Authoritative Information`],[204,`No Content`],[205,`Reset Content`],[206,`Partial Content`],[207,`Multi-Status`],[208,`Already Reported`],[226,`IM Used`],[300,`Multiple Choices`],[301,`Moved Permanently`],[302,`Found`],[303,`See Other`],[304,`Not Modified`],[305,`Use Proxy`],[307,`Temporary Redirect`],[308,`Permanent Redirect`],[400,`Bad Request`],[401,`Unauthorized`],[402,`Payment Required`],[403,`Forbidden`],[404,`Not Found`],[405,`Method Not Allowed`],[406,`Not Acceptable`],[407,`Proxy Authentication Required`],[408,`Request Timeout`],[409,`Conflict`],[410,`Gone`],[411,`Length Required`],[412,`Precondition Failed`],[413,`Payload Too Large`],[414,`URI Too Long`],[415,`Unsupported Media Type`],[416,`Range Not Satisfiable`],[417,`Expectation Failed`],[418,`I'm a Teapot`],[421,`Misdirected Request`],[422,`Unprocessable Entity`],[423,`Locked`],[424,`Failed Dependency`],[425,`Too Early`],[426,`Upgrade Required`],[428,`Precondition Required`],[429,`Too Many Requests`],[431,`Request Header Fields Too Large`],[451,`Unavailable For Legal Reasons`],[500,`Internal Server Error`],[501,`Not Implemented`],[502,`Bad Gateway`],[503,`Service Unavailable`],[504,`Gateway Timeout`],[505,`HTTP Version Not Supported`],[506,`Variant Also Negotiates`],[507,`Insufficient Storage`],[508,`Loop Detected`],[509,`Bandwidth Limit Exceeded`],[510,`Not Extended`],[511,`Network Authentication Required`]]);(function(e){let t=new Map;for(let[n,r]of e)t.set(r.toLowerCase(),n);return t})(w),function(e){let t=[];for(let[n,r]of e)t.push(n);return t}(w);var T=typeof document>`u`,re=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}},E=0,ie=1,D=2,O=null,k=null,ae=0,A=new Set,j=!1;function oe(e,t){let n=t?.equals??Object.is,r={value:e,observers:new Set};return[()=>(le(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)F(e,D);ae===0&&ue()}}]}function M(e){let t=se(e,!0);return ce(t),fe(t),()=>I(t)}function N(e){let t={owned:[],cleanups:[],owner:k},n=k,r=O;k=t,O=null;try{return e(()=>me(t))}finally{k=n,O=r}}function P(e){k&&k.cleanups.push(e)}function se(e,t,n){return{fn:e,sources:new Set,isEffect:t,running:!1,disposed:!1,state:D,observers:new Set,value:void 0,equals:n??Object.is,owned:[],cleanups:[],owner:k}}function ce(e){k&&k.owned.push(e)}function le(e){O&&(O.sources.add(e),e.observers.add(O))}function F(e,t){if(e.disposed||e.state>=t)return;let n=e.state===E;if(e.state=t,e.isEffect)A.add(e);else if(n)for(let t of e.observers)F(t,ie)}function ue(){if(!(ae>0||j)){j=!0;try{for(;A.size>0;){let e=[...A];A.clear();for(let t of e)t.disposed||de(t)}}finally{j=!1}}}function de(e){if(!(e.disposed||e.state===E)){if(e.state===ie)for(let t of e.sources)`fn`in t&&de(t);e.state===D&&fe(e),e.state=E}}function fe(e){if(e.running)throw Error(`ranui reactivity: cyclic dependency detected (a computation triggered itself).`);pe(e);let t=O,n=k;O=e,k=e,e.running=!0,e.state=E;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)F(t,D)}}finally{e.running=!1,O=t,k=n}}function pe(e){for(let t of e.owned)I(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 I(e){e.disposed||(e.disposed=!0,pe(e),e.observers.clear())}function me(e){for(let t of e.owned)I(t);e.owned.length=0;for(let t of e.cleanups)t();e.cleanups.length=0}function he(e){return _(e)}var ge=e=>typeof e!=`string`&&`tagName`in e&&`childrenList`in e,_e=`.#[`;function ve(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&&!_e.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 ye=(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()},be=(e,t)=>{let n=t.trim();if(!n)return!1;let r=ve(n);return r!==null&&r.every(t=>ye(e,t))},L=(e,t,n)=>{for(let r of e)ge(r)&&(be(r,t)&&n.push(r),L(r.childrenList,t,n))},R=class{childrenList=[];appendChild(e){return this.childrenList.push(e),e}serialize(){return this.childrenList.map(e=>typeof e==`string`?_(e):e.serialize()).join(``)}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return L(this.childrenList,e,t),t}},z=class{tagName;attributes=new Map;inlineStyles=new Map;childrenList=[];shadowRoot=null;textContent=null;content;eventListeners=new Map;style={setProperty:(e,t)=>{let n=e.startsWith(`--`)?e:e.replace(/([A-Z])/g,`-$1`).toLowerCase();this.inlineStyles.set(n,t)},removeProperty:e=>this.inlineStyles.delete(e)};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._innerHTML}set innerHTML(e){this._innerHTML=e,this.tagName===`template`&&this.content&&(this.content.childrenList=[e])}constructor(e=`div`){this.tagName=e.toLowerCase(),this.tagName===`template`&&(this.content=new R)}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}attachShadow(e){return this.shadowRoot=new xe(this,e),this.shadowRoot}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return L(this.childrenList,e,t),t}addEventListener(e,t){let n=this.eventListeners.get(e)||new Set;n.add(t),this.eventListeners.set(e,n)}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,n=Array.from(this.attributes.entries()).map(([e,t])=>` ${e}="${he(t)}"`).join(``),r=Array.from(this.inlineStyles.entries()).map(([e,t])=>`${e}:${t}`).join(`;`),i=r?` style="${he(r)}"`:``,a=``;return this.shadowRoot&&(a+=this.shadowRoot.serialize()),this.textContent===null?this._innerHTML?a+=this._innerHTML:a+=this.childrenList.map(e=>typeof e==`string`?_(e):(e instanceof R,e.serialize())).join(``):a+=_(this.textContent),[`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`].includes(t)&&!a?`<${t}${n}${i} />`:`<${t}${n}${i}>${a}</${t}>`}},xe=class{host;options;childrenList=[];adoptedStyleSheets=[];constructor(e,t){this.host=e,this.options=t}appendChild(e){return this.childrenList.push(e),e}querySelector(e){let t=this.querySelectorAll(e);return t.length>0?t[0]:null}querySelectorAll(e){let t=[];return L(this.childrenList,e,t),t}serialize(){return`<template shadowrootmode="${this.options.mode}"${this.options.delegatesFocus?` shadowrootdelegatesfocus`:``}>${this.adoptedStyleSheets.map(e=>`<style>${_(e)}</style>`).join(``)}${this.childrenList.map(e=>typeof e==`string`?_(e):(e instanceof R,e.serialize())).join(``)}</template>`}},B=()=>({current:null}),Se=e=>e.reduce((e,t)=>Array.isArray(t)?e.concat(Se(t)):e.concat(t),[]),V=e=>e==null?null:e instanceof Pe?e.build():typeof e==`string`?T?e:document.createTextNode(e):e,Ce=(e,t)=>{if(T){H(e,[t()]);return}let n=document.createComment(``),r=document.createComment(``);e.appendChild(n),e.appendChild(r);let i=null,a=()=>{i?.(),i=null;let e=n.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}};M(()=>{let e=t();a();let n=document.createDocumentFragment();i=N(t=>(H(n,[e]),t)),r.parentNode?.insertBefore(n,r)}),P(()=>i?.())},we=`__ranFor`,Te=e=>typeof e==`object`&&!!e&&e[we]===!0,Ee=(e,t,n)=>{let[r,i]=oe(t),a=null,o=N(t=>{let i=V(n(e,r));return a=typeof i==`string`?document.createTextNode(i):i,t});return{node:a,index:i,dispose:o}},De=(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},Oe=(e,t)=>{if(T){(t.each()??[]).forEach((n,r)=>{let i=V(t.render(n,()=>r));i!=null&&e.appendChild(i)});return}let n=document.createComment(``);e.appendChild(n);let r=new Map;P(()=>{for(let e of r.values())e.dispose();r.clear()}),M(()=>{let e=t.each()??[],i=new Map,a=[];e.forEach((e,n)=>{let o=t.key(e,n);if(i.has(o))return;let s=r.get(o);s?(r.delete(o),s.index(n)):s=Ee(e,n,t.render),i.set(o,s),s.node&&a.push(s.node)});for(let e of r.values())e.node?.parentNode?.removeChild(e.node),e.dispose();De(n,a),r=i})},ke=`__ranIndex`,Ae=e=>typeof e==`object`&&!!e&&e[ke]===!0,je=(e,t,n)=>{let[r,i]=oe(e),a=null,o=N(e=>{let i=V(n(r,t));return a=typeof i==`string`?document.createTextNode(i):i,e});return{node:a,setItem:i,dispose:o}},Me=(e,t)=>{if(T){(t.each()??[]).forEach((n,r)=>{let i=V(t.render(()=>n,r));i!=null&&e.appendChild(i)});return}let n=document.createComment(``);e.appendChild(n);let r=[];P(()=>{for(let e of r)e.dispose();r=[]}),M(()=>{let e=t.each()??[];for(let n=0;n<e.length;n++)n<r.length?r[n].setItem(e[n]):r.push(je(e[n],n,t.render));for(let t=r.length-1;t>=e.length;t--){let{node:e}=r[t];e?.parentNode?.removeChild(e),r[t].dispose(),r.pop()}De(n,r.map(e=>e.node).filter(e=>e!=null))})},H=(e,t)=>{Se(t).forEach(t=>{if(Te(t)){Oe(e,t);return}if(Ae(t)){Me(e,t);return}if(typeof t==`function`){Ce(e,t);return}let n=V(t);n!=null&&e.appendChild(n)})},Ne=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(`.`)),Pe=class{el;constructor(e,t){let n=t??(Ne.has(e)?`http://www.w3.org/2000/svg`:void 0);this.el=T?new z(e):n?document.createElementNS(n,e):document.createElement(e)}id(e){return this.el.setAttribute(`id`,e),this}bind(e,t){typeof e==`function`?M(()=>t(e())):t(e)}class(e){return this.bind(e,e=>{T?this.el.attributes.set(`class`,e):this.el.className=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 H(this.el,e),this}replaceChildren(...e){if(T){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}ref(e){return e.current=this.el,this}shadow(e={mode:`closed`}){let t=this.el.attachShadow(e);return new Fe(this.el,t,e)}build(){return this.el}serialize(){if(T)return this.el.serialize();let e=document.createElement(`div`);return e.appendChild(this.el.cloneNode(!0)),e.innerHTML}},Fe=class{root;hostEl;options;constructor(e,t,n){this.hostEl=e,this.root=t,this.options=n}children(...e){return H(this.root,e),this}adoptSheet(...e){return this.root.adoptedStyleSheets=[...this.root.adoptedStyleSheets,...e],this}css(e){if(T)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 T?this.root.serialize():this.root.innerHTML}},U=e=>new Pe(e),W=()=>U(`div`),G=()=>U(`slot`),Ie=new Map;function K(e,t){T?(Ie.set(e,t),t.prototype._ssrTag=e):customElements.get(e)||customElements.define(e,t)}var q=typeof document<`u`?HTMLElement:z,Le=`data-ranui`,Re=`data-ranui-sheet`,ze=(e,t)=>x(e,t,Le),Be=(e,t)=>S(e,t,Re),Ve=new WeakMap,He=`@media (prefers-reduced-motion: reduce){*,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important;scroll-behavior:auto !important}}`,Ue=new Map,We=e=>{let t=Ue.get(e);if(t!==void 0)return t;let n=e?`${e}\n${He}`:He;return Ue.set(e,n),n},J=(e,t=``,n={mode:`closed`})=>{let r=e.shadowRoot||Ve.get(e)||e.attachShadow(n);return Ve.set(e,r),ze(r,We(t)),r},Y=(e,t)=>{if(e.current===null)throw Error(`ranui: ${t} is missing its .ref() on the builder`);return e.current},X=(e,t,n=``)=>e.getAttribute(t)??n,Z=(e,t,n,r={})=>{if(r.removeEmpty&&!n){e.removeAttribute(t);return}e.setAttribute(t,n??``)},Ge=(e,t,n,r,i)=>{if(n!==`sheet`||r===i)return;let a=e.getAttribute(`sheet`)||``;a&&Be(t,a)},Ke=`:host{visibility:hidden;position:absolute}`;K(`r-content`,class extends q{observer;_shadowDom;_slot;constructor(){super(),this._shadowDom=J(this,Ke);let e=G().class(`slot`).build();this._shadowDom.appendChild(e),this._slot=e,this.observer=new MutationObserver(this.callback)}callback=e=>{for(let t of e)(t.type===`childList`||t.type===`attributes`)&&this.onChange(t)};onChange=e=>{this.dispatchEvent(new CustomEvent(`change`,{detail:{type:e.type,value:{content:this.children,mutation:e}}}))};connectedCallback(){this.observer.observe(this,{attributes:!0,childList:!0,subtree:!0})}disconnectedCallback(){this.observer.disconnect()}});var qe=`@keyframes ranui-dropdown-up-in{0%{transform-origin:100% 100%;opacity:0;transform:scaleY(.8)}to{transform-origin:100% 100%;opacity:1;transform:scaleY(1)}}@keyframes ranui-dropdown-up-out{0%{transform-origin:100% 100%;opacity:1;transform:scaleY(1)}to{transform-origin:100% 100%;opacity:0;transform:scaleY(.8)}}@keyframes ranui-dropdown-down-in{0%{transform-origin:0 0;opacity:0;transform:scaleY(.8)}to{transform-origin:0 0;opacity:1;transform:scaleY(1)}}@keyframes ranui-dropdown-down-out{0%{transform-origin:0 0;opacity:1;transform:scaleY(1)}to{transform-origin:0 0;opacity:0;transform:scaleY(.8)}}@keyframes ranui-dropdown-left-in{0%{transform-origin:100% 0;opacity:0;transform:scaleX(.8)}to{transform-origin:100% 0;opacity:1;transform:scaleX(1)}}@keyframes ranui-dropdown-left-out{0%{transform-origin:100% 0;opacity:1;transform:scaleX(1)}to{transform-origin:100% 0;opacity:0;transform:scaleX(.8)}}@keyframes ranui-dropdown-right-in{0%{transform-origin:0 0;opacity:0;transform:scaleX(.8)}to{transform-origin:0 0;opacity:1;transform:scaleX(1)}}@keyframes ranui-dropdown-right-out{0%{transform-origin:0 0;opacity:1;transform:scaleX(1)}to{transform-origin:0 0;opacity:0;transform:scaleX(.8)}}.ran-dropdown-down-in{animation:ranui-dropdown-down-in var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-down-out{animation:ranui-dropdown-down-out var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-up-in{animation:ranui-dropdown-up-in var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-up-out{animation:ranui-dropdown-up-out var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-left-in{animation:ranui-dropdown-left-in var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-left-out{animation:ranui-dropdown-left-out var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-right-in{animation:ranui-dropdown-right-in var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}.ran-dropdown-right-out{animation:ranui-dropdown-right-out var(--ran-dropdown-animation-duration,.3s);animation-fill-mode:forwards}:host{text-align:var(--ran-dropdown-host-text-align,left);z-index:var(--ran-dropdown-host-z-index,var(--ran-z-dropdown,1100))}:host([hidden]){display:none}.ranui-dropdown{transform-origin:var(--ran-x,50%) var(--ran-y,50%);box-sizing:var(--ran-dropdown-box-sizing,border-box);margin:var(--ran-dropdown-margin,0);padding:var(--ran-dropdown-padding,0);color:var(--ran-dropdown-color,var(--ran-color-text,#000000e0));font-size:var(--ran-dropdown-font-size,var(--ran-text-label-1,14px));font-weight:var(--ran-dropdown-font-weight,var(--ran-text-label-weight,500));list-style:var(--ran-dropdown-list-style,none);font-family:var(--ran-dropdown-font-family,var(--ran-skin-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"));z-index:var(--ran-dropdown-z-index,1050);overflow:var(--ran-dropdown-overflow,hidden);font-variant:var(--ran-dropdown-font-variant,initial);background:var(--ran-dropdown-background,var(--ran-color-bg-elevated,#fff));border:var(--ran-dropdown-border,1px solid var(--ran-color-border,#eaeaea));border-radius:var(--ran-dropdown-border-radius,var(--ran-radius-md,12px));outline:var(--ran-dropdown-outline,none);box-shadow:var(--ran-dropdown-box-shadow,var(--ran-shadow-menu,var(--ran-shadow-elevated,0 6px 16px 0 #00000014, 0 3px 6px -4px #0000001f, 0 9px 28px 8px #0000000d)));cursor:var(--ran-dropdown-cursor,auto);width:var(--ran-dropdown-width,100%);height:var(--ran-dropdown-height,100%);min-height:var(--ran-dropdown-min-height,100%);min-width:var(--ran-dropdown-min-width,100%)}.ranui-dropdown-container{position:var(--ran-dropdown-container-position,relative);display:var(--ran-dropdown-container-display,block);width:var(--ran-dropdown-container-width,100%);height:var(--ran-dropdown-container-height,100%);box-sizing:var(--ran-dropdown-container-box-sizing,border-box)}.ranui-dropdown-container .top{transform:translateX(calc(0px - var(--ran-dropdown-arrow-width,16px) / 2 + var(--ran-dropdown-arrow-anchor-offset,0px))) translateY(calc(-1 * var(--ran-dropdown-arrow-height,var(--ran-dropdown-arrow-width,16px)) + var(--ran-dropdown-arrow-overlap,2px))) rotate(0deg);top:0;left:50%}.ranui-dropdown-container .bottom{transform:translateX(calc(0px - var(--ran-dropdown-arrow-width,16px) / 2 + var(--ran-dropdown-arrow-anchor-offset,0px))) translateY(var(--ran-dropdown-arrow-overlap,2px)) rotate(180deg);left:50%;top:max(0px, calc(100% - calc(var(--ran-dropdown-arrow-width,16px) / 4)))}.ranui-dropdown-container .left{transform:translateX(calc(0px - var(--ran-dropdown-arrow-width,16px) + var(--ran-dropdown-arrow-overlap,2px))) translateY(calc(var(--ran-dropdown-arrow-width,16px) / 2 + var(--ran-dropdown-arrow-shape-offset,calc(var(--ran-dropdown-arrow-width,16px) * -.301126)) + var(--ran-dropdown-arrow-anchor-offset-y,0px))) rotate(270deg);top:max(0px, calc(var(--ran-dropdown-arrow-anchor-height,var(--ran-dropdown-min-height,100%)) / 2 - var(--ran-dropdown-arrow-width,16px)))}.ranui-dropdown-container .right{transform:translateX(calc(0px - var(--ran-dropdown-arrow-overlap,2px))) translateY(calc(var(--ran-dropdown-arrow-anchor-height,var(--ran-dropdown-min-height,100%)) / 2 - calc(var(--ran-dropdown-arrow-width,16px) / 2) + var(--ran-dropdown-arrow-shape-offset,calc(var(--ran-dropdown-arrow-width,16px) * -.301126)) + var(--ran-dropdown-arrow-anchor-offset-y,0px))) rotate(90deg);top:0;left:100%}.ranui-dropdown-arrow{position:var(--ran-dropdown-arrow-position,absolute);box-sizing:var(--ran-dropdown-arrow-box-sizing,border-box);z-index:var(--ran-dropdown-arrow-z-index,1);display:var(--ran-dropdown-arrow-display,block);pointer-events:var(--ran-dropdown-arrow-pointer-events,none);width:var(--ran-dropdown-arrow-width,var(--ran-dropdown-arrow-width,16px));height:var(--ran-dropdown-arrow-height,var(--ran-dropdown-arrow-width,16px));overflow:var(--ran-dropdown-arrow-overflow,hidden)}.ranui-dropdown-arrow svg{width:100%;height:100%;display:block;overflow:visible}.ranui-dropdown-arrow path{fill:var(--ran-dropdown-arrow-fill-background,var(--ran-dropdown-arrow-tip-background,var(--ran-color-bg-elevated,#fff)));filter:var(--ran-dropdown-arrow-shadow,drop-shadow(2px 2px 3px #0000000d))}@media (prefers-reduced-motion:reduce){.ran-dropdown-down-in,.ran-dropdown-down-out,.ran-dropdown-up-in,.ran-dropdown-up-out,.ran-dropdown-left-in,.ran-dropdown-left-out,.ran-dropdown-right-in,.ran-dropdown-right-out{animation:none}}`;K(`r-dropdown`,class extends q{dropdown;_slot;_shadowDom;arrowIcon;container;static get observedAttributes(){return[`transit`,`arrow`,`sheet`]}constructor(){super(),this._shadowDom=J(this,qe);let e=B(),t=B(),n=W().class(`ranui-dropdown-container`).children(W().style(`-webkit-tap-highlight-color`,`transparent`).style(`outline`,`0`).class(`ranui-dropdown`).ref(e).part(`dropdown`).children(G().class(`slot`).ref(t))).build();this._shadowDom.appendChild(n),this.container=n,this.dropdown=Y(e,`ranui dropdown`),this._slot=Y(t,`slot`)}get transit(){return X(this,`transit`)}set transit(e){Z(this,`transit`,e,{removeEmpty:!0})}get arrow(){return X(this,`arrow`)}set arrow(e){Z(this,`arrow`,e,{removeEmpty:!0})}get sheet(){return X(this,`sheet`)}set sheet(e){Z(this,`sheet`,e)}handlerExternalCss=()=>{Ge(this,this._shadowDom,`sheet`,null,this.sheet)};appliedTransit=``;handlerTransit=()=>{this.dropdown&&(this.appliedTransit&&h(this.dropdown,this.appliedTransit),this.appliedTransit=this.transit,this.appliedTransit&&m(this.dropdown,this.appliedTransit))};getAnimationTarget=()=>this.dropdown;handlerArrow=()=>{let e=(this.arrow||``).trim();if(!e){this.arrowIcon&&this.container.contains(this.arrowIcon)&&this.container.removeChild(this.arrowIcon),this.arrowIcon=void 0;return}!this.arrowIcon&&this.container&&(this.arrowIcon=W().class(`ranui-dropdown-arrow`).build(),this.arrowIcon.innerHTML=`<svg viewBox="0 0 16 16" preserveAspectRatio="none" aria-hidden="true" focusable="false"><path d="M 0 16 A 4 4 0 0 0 2.82842712474619 14.82842712474619 L 6.585786437626905 11.050252531694166 A 2 2 0 0 1 9.414213562373096 11.050252531694166 L 13.17157287525381 14.82842712474619 A 4 4 0 0 0 16 16 Z"/></svg>`,this.container.appendChild(this.arrowIcon)),this.arrowIcon&&(this.arrowIcon.className=`ranui-dropdown-arrow ${e}`)};stopPropagation=e=>{e.stopPropagation()};connectedCallback(){this.handlerExternalCss(),this.handlerTransit(),this.handlerArrow()}disconnectedCallback(){}attributeChangedCallback(e,t,n){e===`transit`&&this.handlerTransit(),e===`arrow`&&this.handlerArrow(),e===`sheet`&&t!==n&&this.handlerExternalCss()}});var Je=`:host{display:var(--ran-popover-host-display,block)}.ran-popover{box-sizing:var(--ran-popover-box-sizing,border-box);position:var(--ran-popover-position,relative);display:var(--ran-popover-display,block);margin:var(--ran-popover-margin,0);padding:var(--ran-popover-padding,0)}.ran-popover-block{display:var(--ran-popover-block-display,block)}`,Ye={bottom:{enter:`ran-dropdown-down-in`,exit:`ran-dropdown-down-out`},top:{enter:`ran-dropdown-up-in`,exit:`ran-dropdown-up-out`},left:{enter:`ran-dropdown-left-in`,exit:`ran-dropdown-left-out`},right:{enter:`ran-dropdown-right-in`,exit:`ran-dropdown-right-out`}},Xe=e=>e.getAnimationTarget?.()??e,Ze=(e,t)=>{let n=Xe(e);if(typeof n.getAnimations!=`function`||typeof requestAnimationFrame!=`function`){t();return}requestAnimationFrame(()=>{let e=n.getAnimations();if(!e.length){t();return}(async()=>{await Promise.allSettled(e.map(e=>e.finished)),t()})()})},Qe=class{options;repositionBound=!1;opened=!1;repositionFrame=0;generation=0;constructor(e){this.options=e}get anchor(){return this.options.anchor?.()??this.options.host}apply=e=>{let{host:t}=this.options;t.setAttribute(`aria-expanded`,e?`true`:`false`);let n=this.options.panel();if(!n||e===this.opened)return;this.opened=e;let r=++this.generation;if(e){t.dispatchEvent(new CustomEvent(`show`)),n.style.setProperty(`display`,`block`),this.attachReposition(),this.position(!0),Ze(n,()=>{r===this.generation&&(n.removeAttribute(`transit`),t.dispatchEvent(new CustomEvent(`after-show`)))});return}this.detachReposition(),t.dispatchEvent(new CustomEvent(`hide`)),n.setAttribute(`transit`,Ye[this.side()].exit),Ze(n,()=>{r===this.generation&&(n.style.setProperty(`display`,`none`),n.removeAttribute(`transit`),t.dispatchEvent(new CustomEvent(`after-hide`)))})};side=()=>this.options.placement().split(`-`)[0];position=(e=!1)=>{if(!this.options.panel())return;let t=()=>{let t=this.options.panel();t&&this.write(t,e)};e&&typeof requestAnimationFrame==`function`?requestAnimationFrame(t):t()};write(e,t){let{offset:n=0,containerId:r,beforeMeasure:i,measurePanel:a,adjust:o,afterPosition:s}=this.options,c=this.anchor.getBoundingClientRect();i?.(c,e);let l=this.options.host.getRootNode(),u=r?.()??``,d=u?l.getElementById?.(u)??document.getElementById(u):null,f=e.getBoundingClientRect(),p=a?.(e),m=f,h=p?.width??f.width,g=p?.height??f.height,_=this.options.placement(),[ee,te]=_.split(`-`),v=te??`start`,y,b,x=ee;if(d){let e=d.getBoundingClientRect();x===`top`||x===`bottom`?(y=x===`bottom`?c.bottom-e.top+n:c.top-e.top-g-n,b=C(v,c.left,c.width,h)-e.left):(y=C(v,c.top,c.height,g)-e.top,b=x===`right`?c.right-e.left+n:c.left-e.left-h-n)}else{let e=ne({anchor:{top:c.top,left:c.left,width:c.width,height:c.height},floating:{width:h,height:g},placement:_,offset:n});x=e.side,y=e.top+window.scrollY,b=e.left+window.scrollX}let S={top:y,left:b,side:x,align:v,anchorRect:c,panelRect:m,container:d},w=o?.(S,e);w&&(S.top=w.top,S.left=w.left),e.style.setProperty(`position`,`absolute`),e.style.setProperty(`inset`,`${S.top}px auto auto ${S.left}px`),e.style.setProperty(`--ran-x`,`${S.left}px`),e.style.setProperty(`--ran-y`,`${S.top}px`),t&&e.setAttribute(`transit`,Ye[S.side].enter),s?.(S,e)}reposition=()=>{if(!(!this.opened||this.repositionFrame)){if(typeof requestAnimationFrame!=`function`){this.position();return}this.repositionFrame=requestAnimationFrame(()=>{this.repositionFrame=0,this.opened&&this.position()})}};attachReposition(){this.repositionBound||typeof window>`u`||(window.addEventListener(`scroll`,this.reposition,!0),window.addEventListener(`resize`,this.reposition),this.repositionBound=!0)}detachReposition(){!this.repositionBound||typeof window>`u`||(window.removeEventListener(`scroll`,this.reposition,!0),window.removeEventListener(`resize`,this.reposition),this.repositionBound=!1)}destroy=()=>{this.generation++,this.opened=!1,this.repositionFrame&&typeof cancelAnimationFrame==`function`&&(cancelAnimationFrame(this.repositionFrame),this.repositionFrame=0),this.detachReposition()}};function $e(e){return e.key===`Enter`||e.key===` `||e.key===`Spacebar`}var et=8,tt=300,Q=16,nt=function(e){return e.TOP=`top`,e.BOTTOM=`bottom`,e.LEFT=`left`,e.RIGHT=`right`,e}({}),rt={top:`bottom`,bottom:`top`,left:`right`,right:`left`},$=class extends q{_events=new re;_slot;popoverBlock;popoverContent;popoverInner;popoverInnerBlock;_shadowDom;removeTimeId;_repositionBound=!1;_floating=new Qe({host:this,panel:()=>this.popoverContent,anchor:()=>Array.from(this.children).find(e=>e.tagName!==`R-CONTENT`)??this,placement:()=>this.placement,offset:et,containerId:()=>this.getPopupContainerId,afterPosition:(e,t)=>{let{anchorRect:n,panelRect:r,side:i}=e,a=rt[i];a&&t.setAttribute(`arrow`,a),t.style.setProperty(`--ran-dropdown-arrow-anchor-width`,`${n.width}px`),t.style.setProperty(`--ran-dropdown-arrow-anchor-height`,`${n.height}px`),t.style.setProperty(`--ran-dropdown-min-width`,`${r.width}px`),t.style.setProperty(`--ran-dropdown-min-height`,`${r.height}px`);let o=t.getBoundingClientRect(),s=n.left+n.width/2,c=o.left+o.width/2;t.style.setProperty(`--ran-dropdown-arrow-anchor-offset`,`${s-c}px`),t.style.setProperty(`--ran-dropdown-arrow-anchor-offset-y`,`${n.top-o.top}px`)}});static get observedAttributes(){return[`open`,`placement`,`trigger`,`sheet`]}closePopover=()=>{this.setDropdownDisplayNone()};constructor(){super(),this._shadowDom=J(this,Je);let e=B(),t=W().class(`ran-popover-block`).role(`tooltip`).children(G().class(`slot`).ref(e)).build();this._shadowDom.appendChild(t),this.popoverBlock=t,this._slot=Y(e,`slot`)}get placement(){return X(this,`placement`,`top`)}set placement(e){Z(this,`placement`,e)}get placementSide(){return this.placement.split(`-`)[0]}get open(){return this.hasAttribute(`open`)}set open(e){e?this.setAttribute(`open`,``):this.removeAttribute(`open`)}_applyOpen=()=>{this._floating.apply(this.open)};show=()=>{this.open=!0};hide=()=>{this.open=!1};toggle=()=>{this.open=!this.open};get trigger(){return X(this,`trigger`,`hover`)}set trigger(e){Z(this,`trigger`,e)}get getPopupContainerId(){return X(this,`getPopupContainerId`)}set getPopupContainerId(e){Z(this,`getPopupContainerId`,e)}get sheet(){return X(this,`sheet`)}set sheet(e){Z(this,`sheet`,e)}handlerExternalCss=()=>{Ge(this,this._shadowDom,`sheet`,null,this.sheet)};initAria=()=>{this.hasAttribute(`tabindex`)||(this.tabIndex=0),this.setAttribute(`aria-haspopup`,`dialog`),this.setAttribute(`aria-expanded`,`false`)};updateAriaExpanded=e=>{this.setAttribute(`aria-expanded`,e?`true`:`false`)};stopPropagation=e=>{e.stopPropagation()};createContent=e=>{if(e){if(!this.popoverContent){let e=getComputedStyle(this).getPropertyValue(`--ran-popover-content-padding`).trim()||`12px`;this.popoverContent=U(`r-dropdown`).class(`ran-popover-dropdown`).style(`display`,`none`).style(`position`,`absolute`).cssVar(`ran-dropdown-padding`,e).build(),this.popoverContent?.addEventListener(`click`,this.stopPropagation);let t=W().children(this.popoverContent).build();this.popoverInner=t,this.trigger.includes(`hover`)&&!p()&&(this.popoverContent?.addEventListener(`mouseleave`,this.blur),this.popoverContent?.addEventListener(`mouseenter`,this.removeDropDownTimeId));let n=this.getRootNode();((n.getElementById?n.getElementById(this.getPopupContainerId):null)||document.getElementById(this.getPopupContainerId)||document.body).appendChild(t)}if(this.popoverContent&&e.length>0){this.popoverContent.innerHTML=``;let t=document.createDocumentFragment();for(let n of e)t.appendChild(n);this.popoverContent.appendChild(t)}}};watchContent=e=>{let{value:t}=e.detail;this.createContent(t.content)};blur=d(()=>{this.removeTimeId&&this.removeDropDownTimeId(),this.removeTimeId=setTimeout(()=>{this.removeDropDownTimeId(),this.setDropdownDisplayNone()},tt)},Q);removeDropDownTimeId=d(()=>{this.trigger.includes(`hover`)&&!p()&&(clearTimeout(this.removeTimeId),this.removeTimeId=void 0)},Q);setDropdownDisplayBlock=d(()=>{this.open=!0},Q);setDropdownDisplayNone=d(()=>{this.open=!1},Q);placementPosition=()=>{this._floating.position()};hoverPopover=e=>{e.stopPropagation(),e.preventDefault(),this.setDropdownDisplayBlock()};clickContent=e=>{e.stopPropagation()};clickPopover=e=>{e.stopPropagation(),e.preventDefault(),this.toggle()};keydownPopover=e=>{$e(e)&&(e.preventDefault(),this.setDropdownDisplayBlock()),e.key===`Escape`&&(e.preventDefault(),this.setDropdownDisplayNone())};clickRemovePopover=e=>{this.hoverRemovePopover(e)};popoverTrigger=()=>{this._events.abort();for(let e of this.children)e.tagName===`R-CONTENT`&&this._events.on(e,`change`,this.watchContent);this.trigger.includes(`hover`)&&(this._events.on(this,`mouseenter`,this.hoverPopover),this._events.on(this,`mouseleave`,this.blur)),this._events.on(this,`click`,this.clickPopover).on(this,`keydown`,this.keydownPopover).on(document,`click`,this.clickRemovePopover)};hoverRemovePopover=e=>{e.stopPropagation(),this.setDropdownDisplayNone()};changePlacement=d(()=>{if(!this.getPopupContainerId&&this.open)return;let e=rt[this.placementSide];e&&this.popoverContent?.setAttribute(`arrow`,e)},Q);connectedCallback(){this.initAria(),this.handlerExternalCss();for(let e of this.children)e.tagName===`R-CONTENT`&&this.createContent(e.children);this.popoverTrigger(),this.changePlacement()}disconnectedCallback(){this._events.abort(),this.setDropdownDisplayBlock.cancel(),this.setDropdownDisplayNone.cancel(),this.blur.cancel(),this.removeDropDownTimeId.cancel(),this._floating.destroy(),clearTimeout(this.removeTimeId),this.removeTimeId=void 0,this.popoverInner?.remove(),this.popoverInner=void 0,this.popoverContent=void 0}attributeChangedCallback(e,t,n){t!==n&&(e===`trigger`&&this.popoverTrigger(),e===`placement`&&this.changePlacement(),e===`sheet`&&this.handlerExternalCss(),e===`open`&&this._applyOpen())}};return K(`r-popover`,$),e.PLACEMENT_TYPE=nt,e.Popover=$,e.default=$,e})({});