@rcarls/rc-common 0.3.1 → 0.3.2
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/dist/rc-common.js +1 -1
- package/dist/rc-common.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/rc-common.js
CHANGED
|
@@ -93,7 +93,7 @@ class V {
|
|
|
93
93
|
if (!s) return;
|
|
94
94
|
const n = s.closest("li[data-value]");
|
|
95
95
|
if (!n || n.getAttribute("role") !== "option" || n.parentElement !== this._ul) return;
|
|
96
|
-
i.preventDefault();
|
|
96
|
+
i.preventDefault(), i.stopPropagation();
|
|
97
97
|
const o = this.optionForElement(n);
|
|
98
98
|
o && this._onActivate(o);
|
|
99
99
|
}, this._host = t, this._idPrefix = e.idPrefix, this._onInitFromDom = e.onInitFromDom, this._onActivate = e.onActivate, t.addController(this);
|
package/dist/rc-common.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(L,Et){typeof exports=="object"&&typeof module<"u"?Et(exports,require("lit"),require("lit/directive.js"),require("lit/async-directive.js"),require("lit/decorators.js")):typeof define=="function"&&define.amd?define(["exports","lit","lit/directive.js","lit/async-directive.js","lit/decorators.js"],Et):(L=typeof globalThis<"u"?globalThis:L||self,Et(L["rc-common"]={},L.lit,L.directive_js,L.asyncDirective_js,L.decorators_js))})(this,(function(L,Et,ze,Nt,To){"use strict";let Eo=0;class Po{constructor(t,n){this._activeItem=null,this._activeIndex=-1,this._itemCounter=0,this._opts=n,this._instanceId=`rc-adc-${++Eo}`,t.addController(this)}hostConnected(){}hostDisconnected(){this.clear()}get activeItem(){return this._activeItem}get activeIndex(){return this._activeIndex}navigate(t){const n=this._opts.items();if(n.length===0)return;const i=this._opts.wrap??!0;let r=this._activeIndex<0?t>0?-1:n.length:this._activeIndex;const s=n.length;let l=0;do if(r+=t,i?r=(r%s+s)%s:r=Math.max(0,Math.min(s-1,r)),l++,!this._isSkipped(n[r]))break;while(l<s);this._setActive(n[r]??null,r)}navigateToFirst(){const t=this._opts.items(),n=t.findIndex(i=>!this._isSkipped(i));n>=0&&this._setActive(t[n],n)}navigateToLast(){const t=this._opts.items();let n=-1;for(let i=t.length-1;i>=0;i--)if(!this._isSkipped(t[i])){n=i;break}n>=0&&this._setActive(t[n],n)}navigateTo(t){const i=this._opts.items()[t];i&&!this._isSkipped(i)&&this._setActive(i,t)}navigateToItem(t){const i=this._opts.items().indexOf(t);i>=0&&!this._isSkipped(t)&&this._setActive(t,i)}clear(){this._activeItem?.removeAttribute("data-active"),this._activeItem=null,this._activeIndex=-1;const t=this._opts.host();t&&t.removeAttribute("aria-activedescendant")}_isSkipped(t){return!t||t.hidden||t.getAttribute("aria-disabled")==="true"?!0:this._opts.isSkipped?.(t)??!1}_setActive(t,n){this._activeItem?.removeAttribute("data-active"),this._activeItem=t,this._activeIndex=n;const i=this._opts.host();if(i){if(!t){i.removeAttribute("aria-activedescendant");return}t.id||(t.id=`${this._instanceId}-${++this._itemCounter}`),i.setAttribute("aria-activedescendant",t.id),t.setAttribute("data-active",""),t.scrollIntoView({block:"nearest"})}}}class Oo{constructor(t,n){this._ul=null,this._options=[],this._liElements=[],this._createLi=null,this._createOption=null,this._selectedValues=new Set,this._filterText="",this._filterStrategy="contains",this._checkmark=!1,this._optionsInitialized=!1,this._onPointerDown=i=>{const r=i.target;if(!r)return;const s=r.closest("li[data-value]");if(!s||s.getAttribute("role")!=="option"||s.parentElement!==this._ul)return;i.preventDefault();const l=this.optionForElement(s);l&&this._onActivate(l)},this._host=t,this._idPrefix=n.idPrefix,this._onInitFromDom=n.onInitFromDom,this._onActivate=n.onActivate,t.addController(this)}hostConnected(){this._host.addEventListener("pointerdown",this._onPointerDown),this._optionsInitialized||this._bootstrapFromDom()}hostDisconnected(){this._host.removeEventListener("pointerdown",this._onPointerDown)}get allOptions(){return this._options}get selectedValues(){return[...this._selectedValues]}get filterText(){return this._filterText}isSelected(t){return this._selectedValues.has(t)}optionForElement(t){if(t===this._createLi)return this._createOption;const n=this._liElements.indexOf(t);return n===-1?null:this._options[n]??null}get navigableItems(){const t=[];for(let n=0;n<this._liElements.length;n++){const i=this._liElements[n];this._options[n]?.disabled||i.hidden||t.push(i)}return this._createLi!==null&&t.push(this._createLi),t}set checkmark(t){this._checkmark!==t&&(this._checkmark=t,this._syncCheckmarks())}setOptions(t){this._optionsInitialized=!0,this._options=[...t],this._ensureContainer(),this._syncOptionsToDom()}appendOption(t){this._optionsInitialized=!0,this._options=[...this._options,t],this._ensureContainer();const n=this._createLiElement(t,this._options.length-1);this._liElements.push(n),this._createLi?this._ul.insertBefore(n,this._createLi):this._ul.appendChild(n),this._applyFilterToLi(n,t)}setSelectedValues(t){const n=new Set(this._options.filter(i=>i.kind==="action").map(i=>i.value));this._createOption&&n.add(this._createOption.value),this._selectedValues=new Set(t.filter(i=>!n.has(i))),this._syncSelectedToDom()}filterOptions(t,n="contains"){this._filterText=t,this._filterStrategy=n,this._syncFilterToDom()}clearFilter(){this._filterText="",this._syncFilterToDom()}setCreateOption(t){if(t===null){this._createLi?.remove(),this._createLi=null,this._createOption=null;return}const n=t.trim();if(this._createOption={kind:"action",action:"create",value:`create:${n}`,label:`Create "${n}"`,data:{text:n}},!this._createLi){this._ensureContainer();const i=document.createElement("li");i.setAttribute("id",`${this._idPrefix}-create`),i.setAttribute("role","option"),i.setAttribute("aria-selected","false"),i.setAttribute("part","option create-option"),this._checkmark&&this._ensureCheckmark(i),this._ul.appendChild(i),this._createLi=i}this._createLi.setAttribute("data-value",this._createOption.value),this._createLi.setAttribute("data-kind","action"),this._createLi.setAttribute("data-action",this._createOption.action),this._setLabelText(this._createLi,this._createOption.label)}_ensureContainer(){if(this._ul)return this._ul;let t=this._host.querySelector(":scope > ul");return t||(t=document.createElement("ul"),this._host.appendChild(t)),t.setAttribute("role","presentation"),t.setAttribute("aria-hidden","true"),this._ul=t,t}_bootstrapFromDom(){const t=this._host.querySelector(":scope > ul");if(!t)return;this._ul=t,t.setAttribute("role","presentation"),t.setAttribute("aria-hidden","true");const n=Array.from(t.querySelectorAll(":scope > li"));if(n.length===0)return;const i=[];for(let r=0;r<n.length;r++){const s=n[r],l=s.getAttribute("data-value")??s.getAttribute("value")??s.textContent?.trim()??"",c=s.textContent?.trim()??"",a=s.hasAttribute("disabled")||s.getAttribute("aria-disabled")==="true";i.push({value:l,label:c,disabled:a}),s.setAttribute("role","option"),s.setAttribute("id",`${this._idPrefix}-${r}`),s.setAttribute("part","option"),s.setAttribute("data-value",l),s.setAttribute("aria-selected",this._selectedValues.has(l)?"true":"false"),s.setAttribute("aria-disabled",a?"true":"false"),this._checkmark&&this._ensureCheckmark(s)}this._options=i,this._liElements=n,this._onInitFromDom?.(i)}_syncOptionsToDom(){const t=this._ensureContainer();for(const n of this._liElements)n.remove();this._liElements=[];for(let n=0;n<this._options.length;n++){const i=this._createLiElement(this._options[n],n);this._liElements.push(i),t.appendChild(i)}this._createLi&&t.appendChild(this._createLi),this._syncFilterToDom()}_createLiElement(t,n){const i=document.createElement("li");return i.setAttribute("role","option"),i.setAttribute("id",`${this._idPrefix}-${n}`),i.setAttribute("part","option"),i.setAttribute("data-value",t.value),i.setAttribute("data-kind",t.kind??"option"),t.kind==="action"?i.setAttribute("data-action",t.action):i.removeAttribute("data-action"),i.setAttribute("aria-selected",this._selectedValues.has(t.value)?"true":"false"),i.setAttribute("aria-disabled",t.disabled?"true":"false"),this._checkmark&&this._ensureCheckmark(i),this._setLabelText(i,t.label),i}_setLabelText(t,n){for(const i of t.childNodes)if(i.nodeType===Node.TEXT_NODE){i.textContent=n;return}t.appendChild(document.createTextNode(n))}_ensureCheckmark(t){if(t.querySelector('[part="option-checkmark"]'))return;const n=document.createElement("span");n.setAttribute("part","option-checkmark"),n.setAttribute("aria-hidden","true"),n.textContent="✓",t.insertBefore(n,t.firstChild)}_removeCheckmark(t){t.querySelector('[part="option-checkmark"]')?.remove()}_syncCheckmarks(){const t=this._createLi?[...this._liElements,this._createLi]:[...this._liElements];for(const n of t)this._checkmark?this._ensureCheckmark(n):this._removeCheckmark(n)}_syncSelectedToDom(){for(let t=0;t<this._liElements.length;t++){const n=this._options[t];n&&this._liElements[t].setAttribute("aria-selected",this._selectedValues.has(n.value)?"true":"false")}}_syncFilterToDom(){for(let t=0;t<this._liElements.length;t++){const n=this._options[t];n&&this._applyFilterToLi(this._liElements[t],n)}}_applyFilterToLi(t,n){t.hidden=!this._isVisible(n)}_isVisible(t){if(!this._filterText)return!0;const n=t.label.toLowerCase(),i=this._filterText.toLowerCase();return typeof this._filterStrategy=="function"?this._filterStrategy(n,i):this._filterStrategy==="contains"?n.includes(i):n.startsWith(i)}}class Do extends Nt.AsyncDirective{constructor(t){if(super(t),this._options={},this._isPointerFocus=!1,this._onPointerdown=()=>{this._isPointerFocus=!0,this._target?.removeAttribute("data-interaction-mode")},this._onFocusin=()=>{this._isPointerFocus?this._isPointerFocus=!1:this._target?.setAttribute("data-interaction-mode","keyboard")},this._onKeydown=()=>{this._target?.setAttribute("data-interaction-mode","keyboard")},t.type!==ze.PartType.ELEMENT)throw new Error("The `keyInteraction` directive must be used on an element.")}get _target(){return this._options.attributeTarget??this._element?.deref()}_init(){const t=this._element?.deref();t instanceof HTMLElement&&(t.addEventListener("pointerdown",this._onPointerdown,{capture:!0}),t.addEventListener("focusin",this._onFocusin),t.addEventListener("keydown",this._onKeydown))}render(t){return Et.nothing}update(t,[n]){this.isConnected&&this._element?.deref()===void 0&&(this._element=new WeakRef(t.element),this._init()),this._options=n??{}}disconnected(){const t=this._element?.deref();t instanceof HTMLElement&&(t.removeEventListener("pointerdown",this._onPointerdown,{capture:!0}),t.removeEventListener("focusin",this._onFocusin),t.removeEventListener("keydown",this._onKeydown))}reconnected(){this._init()}}const Mo=Nt.directive(Do);class Io extends Nt.AsyncDirective{constructor(t){if(super(t),this._options={},t.type!==ze.PartType.ELEMENT)throw new Error("The `keyNavigation` directive must be used on an element.")}get navigationAxis(){if(this._options.navigationAxis)return this._options.navigationAxis;switch(this._element?.deref()?.role){case"slider":case"tablist":case"toolbar":case"menubar":return this._element?.deref()?.ariaOrientation==="vertical"?"vertical":"horizontal";case"separator":return this._element?.deref()?.ariaOrientation==="vertical"?"horizontal":"vertical";default:return this._element?.deref()?.ariaOrientation==="horizontal"?"horizontal":"vertical"}}_normalizeKey(t){switch(t){case"Up":return"ArrowUp";case"Down":return"ArrowDown";case"Left":return"ArrowLeft";case"Right":return"ArrowRight";default:return t}}_onKeydown(t){const n=this._normalizeKey(t.key),i=this.navigationAxis,r=this._element?.deref(),s=i==="horizontal"&&r!=null&&getComputedStyle(r).direction==="rtl",l=i==="horizontal"?s?"ArrowLeft":"ArrowRight":"ArrowDown",c=i==="horizontal"?s?"ArrowRight":"ArrowLeft":"ArrowUp",a=i==="horizontal"?"ArrowDown":"ArrowRight",o=i==="horizontal"?"ArrowUp":"ArrowLeft";let h;this._options.handleNavAxis!==!1&&(n===l?h=t.shiftKey?"next-large":"next":n===c?h=t.shiftKey?"prev-large":"prev":n==="Home"?h="start":n==="End"&&(h="end")),!h&&this._options.handleOpenAxis&&(n===a?h="open-to-first":n===o&&(h="open-to-last")),h||(n==="Enter"?h=this._options.handleActivate?"activate":"toggle":n===" "&&this._options.handleActivate?h="activate":n==="Escape"&&this._options.handleEscape&&(h="escape")),h!=null&&(this._callback(h),t.stopPropagation(),t.preventDefault())}_init(){const t=this._element?.deref();t!=null&&t instanceof HTMLElement&&(this._keyDownHandle=this._onKeydown.bind(this),t.addEventListener("keydown",this._keyDownHandle))}render(t,n){return Et.nothing}update(t,[n,i]){this.isConnected&&this._element?.deref()===void 0&&(this._element=new WeakRef(t.element),this._init()),this._callback=n.bind(t.options?.host??t.element),typeof i=="boolean"?this._options={}:this._options={...i}}disconnected(){const t=this._element?.deref();t!=null&&t instanceof HTMLElement&&t.removeEventListener("keydown",this._keyDownHandle)}reconnected(){this._init()}}const Ro=Nt.directive(Io);class jo extends Nt.AsyncDirective{constructor(t){if(super(t),this._activePointerId=null,t.type!==ze.PartType.ELEMENT)throw new Error("The `mouseMove` directive must be used on an element.");this._pointerDownHandle=this._onPointerDown.bind(this),this._pointerMoveHandle=this._onPointerMove.bind(this),this._pointerEndHandle=this._onPointerEnd.bind(this)}_onPointerDown(t){if(this._activePointerId!==null)return;t.preventDefault();const n=t.currentTarget;this._activePointerId=t.pointerId,this._capturePointer(n,t.pointerId),n.addEventListener("pointermove",this._pointerMoveHandle),n.addEventListener("pointerup",this._pointerEndHandle),n.addEventListener("pointercancel",this._pointerEndHandle),n.addEventListener("lostpointercapture",this._pointerEndHandle),n.focus()}_onPointerMove(t){t.pointerId===this._activePointerId&&(t.preventDefault(),this._callback(t))}_onPointerEnd(t){if(t.pointerId!==this._activePointerId)return;t.preventDefault();const n=t.currentTarget;this._releasePointer(n,t.pointerId),this._removePointerCycleListeners(n),this._activePointerId=null}_init(){const t=this._element?.deref();t&&(t.removeEventListener("pointerdown",this._pointerDownHandle),t.addEventListener("pointerdown",this._pointerDownHandle))}_removePointerCycleListeners(t){t.removeEventListener("pointermove",this._pointerMoveHandle),t.removeEventListener("pointerup",this._pointerEndHandle),t.removeEventListener("pointercancel",this._pointerEndHandle),t.removeEventListener("lostpointercapture",this._pointerEndHandle)}_capturePointer(t,n){try{t.setPointerCapture(n)}catch{}}_releasePointer(t,n){try{t.hasPointerCapture(n)&&t.releasePointerCapture(n)}catch{}}render(t){return Et.nothing}update(t,[n]){if(this._callback=n.bind(t.options?.host??t.element),!this.isConnected||!(t.element instanceof HTMLElement))return;const i=this._element?.deref();i!==t.element&&(i?.removeEventListener("pointerdown",this._pointerDownHandle),i&&this._removePointerCycleListeners(i),this._activePointerId=null,this._element=new WeakRef(t.element),this._init())}disconnected(){const t=this._element?.deref();t&&(t.removeEventListener("pointerdown",this._pointerDownHandle),this._removePointerCycleListeners(t),this._activePointerId=null)}reconnected(){this._init()}}const Fo=Nt.directive(jo);class $o{constructor(t,n){this._dragging=!1,this._startX=0,this._startY=0,this._startLeft=0,this._startTop=0,this._opts={axis:"both",step:4,disabled:!1,handle:null,bounds:"viewport",...n},this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerUp=this._handlePointerUp.bind(this),this._onPointerCancel=this._cancelDrag.bind(this),this._onLostPointerCapture=this._handleLostPointerCapture.bind(this),this._onKeyDown=this._handleKeyDown.bind(this),t.addController(this)}setOptions(t){const n=this._handle();Object.assign(this._opts,t);const i=this._handle();n!==i&&(this._detachFrom(n),this._attachTo(i))}hostConnected(){this._attachTo(this._handle())}hostDisconnected(){this._detachFrom(this._handle())}_handle(){return this._opts.handle??this._opts.target}_target(){return this._opts.target}_attachTo(t){t.addEventListener("pointerdown",this._onPointerDown),t.addEventListener("keydown",this._onKeyDown),t.hasAttribute("tabindex")||t.setAttribute("tabindex","0")}_detachFrom(t){t.removeEventListener("pointerdown",this._onPointerDown),t.removeEventListener("keydown",this._onKeyDown),t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointercancel",this._onPointerCancel),t.removeEventListener("lostpointercapture",this._onLostPointerCapture)}_handlePointerDown(t){if(this._opts.disabled||t.target.closest('button, [role="button"], a'))return;const n=this._target(),i=n.getBoundingClientRect();getComputedStyle(n).position==="static"&&(n.style.position="fixed"),n.style.translate="none",n.style.inset="auto",n.style.margin="0",n.style.left=`${i.left}px`,n.style.top=`${i.top}px`,this._startX=t.clientX,this._startY=t.clientY,this._startLeft=i.left,this._startTop=i.top,this._dragging=!0;const r=this._handle();r.setPointerCapture(t.pointerId),r.addEventListener("pointermove",this._onPointerMove),r.addEventListener("pointerup",this._onPointerUp),r.addEventListener("pointercancel",this._onPointerCancel),r.addEventListener("lostpointercapture",this._onLostPointerCapture),t.preventDefault()}_handlePointerMove(t){if(!this._dragging)return;const n=this._target(),{axis:i}=this._opts,[r,s,l,c]=this._boundsRect(),a=i!=="y"?Math.min(Math.max(this._startLeft+t.clientX-this._startX,r),l-n.offsetWidth):parseFloat(n.style.left)||0,o=i!=="x"?Math.min(Math.max(this._startTop+t.clientY-this._startY,s),c-n.offsetHeight):parseFloat(n.style.top)||0;n.style.left=`${a}px`,n.style.top=`${o}px`}_handlePointerUp(t){this._cancelDrag()}_handleLostPointerCapture(t){this._cancelDrag()}_cancelDrag(){if(!this._dragging)return;this._dragging=!1;const t=this._handle();t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointercancel",this._onPointerCancel),t.removeEventListener("lostpointercapture",this._onLostPointerCapture)}_handleKeyDown(t){if(this._opts.disabled||t.currentTarget!==t.target)return;const{axis:n}=this._opts,i=t.shiftKey?this._opts.step*10:this._opts.step;let r=0,s=0;switch(t.key){case"ArrowLeft":if(n==="y")return;r=-i;break;case"ArrowRight":if(n==="y")return;r=i;break;case"ArrowUp":if(n==="x")return;s=-i;break;case"ArrowDown":if(n==="x")return;s=i;break;default:return}const l=this._target();if(getComputedStyle(l).position==="static"){const d=l.getBoundingClientRect();l.style.position="fixed",l.style.translate="none",l.style.left=`${d.left}px`,l.style.top=`${d.top}px`}const[c,a,o,h]=this._boundsRect(),u=parseFloat(l.style.left)||0,f=parseFloat(l.style.top)||0;l.style.left=`${Math.min(Math.max(u+r,c),o-l.offsetWidth)}px`,l.style.top=`${Math.min(Math.max(f+s,a),h-l.offsetHeight)}px`,t.preventDefault(),t.stopPropagation()}_boundsRect(){const{bounds:t}=this._opts;if(!t||t==="viewport")return[0,0,window.innerWidth,window.innerHeight];if(t==="parent"){const i=this._opts.target.parentElement;if(!i)return[0,0,window.innerWidth,window.innerHeight];const r=i.getBoundingClientRect();return[r.left,r.top,r.right,r.bottom]}const n=t.getBoundingClientRect();return[n.left,n.top,n.right,n.bottom]}}class No{constructor(t,n){this._resizing=null,this._startX=0,this._startY=0,this._startW=0,this._startH=0,this._startLeft=0,this._startTop=0,this._effectiveMinW=0,this._effectiveMinH=0,this._cornerBtn=null,this._opts={direction:"none",threshold:8,step:4,disabled:!1,minWidth:100,minHeight:60,handle:null,bounds:"viewport",...n},this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerUp=this._handlePointerUp.bind(this),this._onPointerLeave=this._handlePointerLeave.bind(this),this._onKeyDown=this._handleKeyDown.bind(this),t.addController(this)}setOptions(t){Object.assign(this._opts,t)}hostConnected(){if(this._opts.direction==="none")return;const t=this._target();t.addEventListener("pointermove",this._onPointerMove),t.addEventListener("pointerdown",this._onPointerDown,{capture:!0}),t.addEventListener("pointerup",this._onPointerUp),t.addEventListener("pointerleave",this._onPointerLeave),this._injectCornerButton()}hostDisconnected(){const t=this._target();t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerdown",this._onPointerDown,{capture:!0}),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointerleave",this._onPointerLeave),this._removeCornerButton()}_target(){return this._opts.target}_injectCornerButton(){if(this._opts.handle)return;const t=this._target();getComputedStyle(t).position==="static"&&(t.style.position="relative");const n=document.createElement("button");n.setAttribute("data-rc-resize-corner",""),n.setAttribute("aria-label","Resize"),n.type="button",Object.assign(n.style,{position:"absolute",bottom:"0",right:"0",width:"12px",height:"12px",padding:"0",border:"none",background:"transparent",cursor:this._cornerCursor(),zIndex:"1"}),n.addEventListener("keydown",this._onKeyDown),t.appendChild(n),this._cornerBtn=n}_removeCornerButton(){this._cornerBtn&&(this._cornerBtn.removeEventListener("keydown",this._onKeyDown),this._cornerBtn.remove(),this._cornerBtn=null)}_cornerCursor(){switch(this._opts.direction){case"both":return"se-resize";case"horizontal":return"ew-resize";case"vertical":return"ns-resize";default:return"default"}}_edgeCursor(t){return{n:"n-resize",s:"s-resize",e:"e-resize",w:"w-resize",ne:"ne-resize",nw:"nw-resize",se:"se-resize",sw:"sw-resize"}[t]}_detectEdge(t){const{direction:n,threshold:i}=this._opts;if(n==="none")return null;const r=this._target().getBoundingClientRect(),s=t.clientX,l=t.clientY,c=s>=r.right-i&&s<=r.right+i,a=s>=r.left-i&&s<=r.left+i,o=l>=r.bottom-i&&l<=r.bottom+i,h=l>=r.top-i&&l<=r.top+i,u=s>=r.left&&s<=r.right,f=l>=r.top&&l<=r.bottom;if(n==="both"){if(c&&o)return"se";if(a&&o)return"sw";if(c&&h)return"ne";if(a&&h)return"nw";if(c&&f)return"e";if(a&&f)return"w";if(o&&u)return"s";if(h&&u)return"n"}if(n==="horizontal"){if(c&&f)return"e";if(a&&f)return"w"}if(n==="vertical"){if(o&&u)return"s";if(h&&u)return"n"}return null}_pinPosition(t){const n=t.getBoundingClientRect();return getComputedStyle(t).position==="static"&&(t.style.position="fixed"),t.style.translate="none",t.style.inset="auto",t.style.margin="0",t.style.boxSizing="border-box",t.style.left=`${n.left}px`,t.style.top=`${n.top}px`,t.style.width=`${n.width}px`,t.style.height=`${n.height}px`,n}_handlePointerDown(t){if(this._opts.disabled)return;const n=this._detectEdge(t);if(!n)return;t.stopPropagation();const i=this._target(),r=this._pinPosition(i);this._startX=t.clientX,this._startY=t.clientY,this._startW=r.width,this._startH=r.height,this._startLeft=r.left,this._startTop=r.top,this._resizing=n;const s=getComputedStyle(i);this._effectiveMinW=Math.max(this._opts.minWidth,parseFloat(s.minWidth)||0),this._effectiveMinH=Math.max(this._opts.minHeight,parseFloat(s.minHeight)||0),i.setPointerCapture(t.pointerId),t.preventDefault()}_handlePointerMove(t){if(this._resizing){const r=this._target(),[s,l,c,a]=this._boundsRect(),{maxWidth:o,maxHeight:h}=this._opts,u=this._effectiveMinW,f=this._effectiveMinH,d=t.clientX-this._startX,p=t.clientY-this._startY,m=this._resizing;if(m==="e"||m==="se"||m==="ne"){const y=Math.min(o??1/0,c-this._startLeft);r.style.width=`${Math.min(Math.max(this._startW+d,u),y)}px`}if(m==="w"||m==="sw"||m==="nw"){const y=this._startLeft+this._startW,b=Math.min(Math.max(this._startLeft+d,s,o!==void 0?y-o:-1/0),y-u);r.style.left=`${b}px`,r.style.width=`${y-b}px`}if(m==="s"||m==="se"||m==="sw"){const y=Math.min(h??1/0,a-this._startTop);r.style.height=`${Math.min(Math.max(this._startH+p,f),y)}px`}if(m==="n"||m==="ne"||m==="nw"){const y=this._startTop+this._startH,b=Math.min(Math.max(this._startTop+p,l,h!==void 0?y-h:-1/0),y-f);r.style.top=`${b}px`,r.style.height=`${y-b}px`}return}if(this._opts.handle)return;const n=this._detectEdge(t),i=this._target();i.style.cursor=n?this._edgeCursor(n):""}_handlePointerUp(t){this._resizing=null}_handlePointerLeave(t){this._resizing||(this._target().style.cursor="")}_handleKeyDown(t){if(this._opts.disabled)return;const{direction:n}=this._opts,i=t.key==="ArrowRight"||t.key==="ArrowLeft",r=t.key==="ArrowDown"||t.key==="ArrowUp";if(i&&n==="vertical"||r&&n==="horizontal"||!i&&!r)return;t.preventDefault(),t.stopPropagation();const s=this._target(),l=this._pinPosition(s),c=t.shiftKey?this._opts.step*10:this._opts.step,[,,a,o]=this._boundsRect(),{maxWidth:h,maxHeight:u}=this._opts,f=getComputedStyle(s),d=Math.max(this._opts.minWidth,parseFloat(f.minWidth)||0),p=Math.max(this._opts.minHeight,parseFloat(f.minHeight)||0);if(t.key==="ArrowRight"){const m=Math.min(h??1/0,a-l.left);s.style.width=`${Math.min(Math.max(s.offsetWidth+c,d),m)}px`}if(t.key==="ArrowLeft"&&(s.style.width=`${Math.max(s.offsetWidth-c,d)}px`),t.key==="ArrowDown"){const m=Math.min(u??1/0,o-l.top);s.style.height=`${Math.min(Math.max(s.offsetHeight+c,p),m)}px`}t.key==="ArrowUp"&&(s.style.height=`${Math.max(s.offsetHeight-c,p)}px`)}_boundsRect(){const{bounds:t}=this._opts;if(!t||t==="viewport")return[0,0,window.innerWidth,window.innerHeight];if(t==="parent"){const i=this._opts.target.parentElement;if(!i)return[0,0,window.innerWidth,window.innerHeight];const r=i.getBoundingClientRect();return[r.left,r.top,r.right,r.bottom]}const n=t.getBoundingClientRect();return[n.left,n.top,n.right,n.bottom]}}function pe(e,t){const n=`${t}px`;switch(e){case"top":return`position-area: top; margin-bottom: ${n};`;case"top-start":return`bottom: anchor(top); top: auto; left: anchor(left); right: auto; margin-bottom: ${n};`;case"top-end":return`bottom: anchor(top); top: auto; left: auto; right: anchor(right); margin-bottom: ${n};`;case"bottom":return`position-area: bottom; margin-top: ${n};`;case"bottom-start":return`top: anchor(bottom); bottom: auto; left: anchor(left); right: auto; margin-top: ${n};`;case"bottom-end":return`top: anchor(bottom); bottom: auto; left: auto; right: anchor(right); margin-top: ${n};`;case"left":return`position-area: left; margin-right: ${n};`;case"left-start":return`top: anchor(top); bottom: auto; right: anchor(left); left: auto; margin-right: ${n};`;case"left-end":return`top: auto; bottom: anchor(bottom); right: anchor(left); left: auto; margin-right: ${n};`;case"right":return`position-area: right; margin-left: ${n};`;case"right-start":return`top: anchor(top); bottom: auto; left: anchor(right); right: auto; margin-left: ${n};`;case"right-end":return`top: auto; bottom: anchor(bottom); left: anchor(right); right: auto; margin-left: ${n};`}}const Mn={top:"bottom","top-start":"bottom-start","top-end":"bottom-end",bottom:"top","bottom-start":"top-start","bottom-end":"top-end",left:"right","left-start":"right-start","left-end":"right-end",right:"left","right-start":"left-start","right-end":"left-end"},zo={top:"top","top-start":"top-end","top-end":"top-start",bottom:"bottom","bottom-start":"bottom-end","bottom-end":"bottom-start",left:"left","left-start":"left-end","left-end":"left-start",right:"right","right-start":"right-end","right-end":"right-start"},In=CSS.supports("position-try-fallbacks: flip-block")&&CSS.supports("min-width: anchor-size(width)");let Rn=null,We=null;function Wo(){return In?Promise.resolve(null):(We||(We=Promise.resolve().then(()=>Wp).then(e=>(Rn=e.default,Rn)).catch(()=>null)),We)}let Bo=0;class Ho{constructor(t,n){this._styleEl=null,this._adoptedSheet=null,this._opts=n,this._uid=`rc-anchor-${++Bo}`,t.addController(this)}setOptions(t){Object.assign(this._opts,t),this._applyAndPolyfill()}update(){this._applyAndPolyfill()}hostConnected(){this._applyAndPolyfill()}hostDisconnected(){this._cleanup()}_anchor(){const{anchor:t}=this._opts;return typeof t=="function"?t():t}_floating(){const{floating:t}=this._opts;return typeof t=="function"?t():t}_shadowHost(){const{shadowHost:t}=this._opts;return typeof t=="function"?t():t??null}_applyAndPolyfill(){this._apply(),In||this._applyPolyfillOrFallback()}async _applyPolyfillOrFallback(){const t=await Wo(),n=this._shadowHost();t?await t({roots:n?[n]:void 0,useAnimationFrame:!1}):this._positionFallback()}_apply(){if(this._opts.disabled){this._cleanup();return}const t=this._anchor(),n=this._floating();if(!t||!n)return;const i=this._opts.placement??"bottom-start",r=this._opts.offset??4,s=this._opts.flip??!0,l=`--${this._uid}`,c=this._uid;t.style.setProperty("anchor-name",l),n.setAttribute("data-rc-anchor",c);const a=Mn[i],o=zo[i],h=Mn[o],u=s?`
|
|
1
|
+
(function(L,Et){typeof exports=="object"&&typeof module<"u"?Et(exports,require("lit"),require("lit/directive.js"),require("lit/async-directive.js"),require("lit/decorators.js")):typeof define=="function"&&define.amd?define(["exports","lit","lit/directive.js","lit/async-directive.js","lit/decorators.js"],Et):(L=typeof globalThis<"u"?globalThis:L||self,Et(L["rc-common"]={},L.lit,L.directive_js,L.asyncDirective_js,L.decorators_js))})(this,(function(L,Et,ze,Nt,To){"use strict";let Eo=0;class Po{constructor(t,n){this._activeItem=null,this._activeIndex=-1,this._itemCounter=0,this._opts=n,this._instanceId=`rc-adc-${++Eo}`,t.addController(this)}hostConnected(){}hostDisconnected(){this.clear()}get activeItem(){return this._activeItem}get activeIndex(){return this._activeIndex}navigate(t){const n=this._opts.items();if(n.length===0)return;const i=this._opts.wrap??!0;let r=this._activeIndex<0?t>0?-1:n.length:this._activeIndex;const s=n.length;let l=0;do if(r+=t,i?r=(r%s+s)%s:r=Math.max(0,Math.min(s-1,r)),l++,!this._isSkipped(n[r]))break;while(l<s);this._setActive(n[r]??null,r)}navigateToFirst(){const t=this._opts.items(),n=t.findIndex(i=>!this._isSkipped(i));n>=0&&this._setActive(t[n],n)}navigateToLast(){const t=this._opts.items();let n=-1;for(let i=t.length-1;i>=0;i--)if(!this._isSkipped(t[i])){n=i;break}n>=0&&this._setActive(t[n],n)}navigateTo(t){const i=this._opts.items()[t];i&&!this._isSkipped(i)&&this._setActive(i,t)}navigateToItem(t){const i=this._opts.items().indexOf(t);i>=0&&!this._isSkipped(t)&&this._setActive(t,i)}clear(){this._activeItem?.removeAttribute("data-active"),this._activeItem=null,this._activeIndex=-1;const t=this._opts.host();t&&t.removeAttribute("aria-activedescendant")}_isSkipped(t){return!t||t.hidden||t.getAttribute("aria-disabled")==="true"?!0:this._opts.isSkipped?.(t)??!1}_setActive(t,n){this._activeItem?.removeAttribute("data-active"),this._activeItem=t,this._activeIndex=n;const i=this._opts.host();if(i){if(!t){i.removeAttribute("aria-activedescendant");return}t.id||(t.id=`${this._instanceId}-${++this._itemCounter}`),i.setAttribute("aria-activedescendant",t.id),t.setAttribute("data-active",""),t.scrollIntoView({block:"nearest"})}}}class Oo{constructor(t,n){this._ul=null,this._options=[],this._liElements=[],this._createLi=null,this._createOption=null,this._selectedValues=new Set,this._filterText="",this._filterStrategy="contains",this._checkmark=!1,this._optionsInitialized=!1,this._onPointerDown=i=>{const r=i.target;if(!r)return;const s=r.closest("li[data-value]");if(!s||s.getAttribute("role")!=="option"||s.parentElement!==this._ul)return;i.preventDefault(),i.stopPropagation();const l=this.optionForElement(s);l&&this._onActivate(l)},this._host=t,this._idPrefix=n.idPrefix,this._onInitFromDom=n.onInitFromDom,this._onActivate=n.onActivate,t.addController(this)}hostConnected(){this._host.addEventListener("pointerdown",this._onPointerDown),this._optionsInitialized||this._bootstrapFromDom()}hostDisconnected(){this._host.removeEventListener("pointerdown",this._onPointerDown)}get allOptions(){return this._options}get selectedValues(){return[...this._selectedValues]}get filterText(){return this._filterText}isSelected(t){return this._selectedValues.has(t)}optionForElement(t){if(t===this._createLi)return this._createOption;const n=this._liElements.indexOf(t);return n===-1?null:this._options[n]??null}get navigableItems(){const t=[];for(let n=0;n<this._liElements.length;n++){const i=this._liElements[n];this._options[n]?.disabled||i.hidden||t.push(i)}return this._createLi!==null&&t.push(this._createLi),t}set checkmark(t){this._checkmark!==t&&(this._checkmark=t,this._syncCheckmarks())}setOptions(t){this._optionsInitialized=!0,this._options=[...t],this._ensureContainer(),this._syncOptionsToDom()}appendOption(t){this._optionsInitialized=!0,this._options=[...this._options,t],this._ensureContainer();const n=this._createLiElement(t,this._options.length-1);this._liElements.push(n),this._createLi?this._ul.insertBefore(n,this._createLi):this._ul.appendChild(n),this._applyFilterToLi(n,t)}setSelectedValues(t){const n=new Set(this._options.filter(i=>i.kind==="action").map(i=>i.value));this._createOption&&n.add(this._createOption.value),this._selectedValues=new Set(t.filter(i=>!n.has(i))),this._syncSelectedToDom()}filterOptions(t,n="contains"){this._filterText=t,this._filterStrategy=n,this._syncFilterToDom()}clearFilter(){this._filterText="",this._syncFilterToDom()}setCreateOption(t){if(t===null){this._createLi?.remove(),this._createLi=null,this._createOption=null;return}const n=t.trim();if(this._createOption={kind:"action",action:"create",value:`create:${n}`,label:`Create "${n}"`,data:{text:n}},!this._createLi){this._ensureContainer();const i=document.createElement("li");i.setAttribute("id",`${this._idPrefix}-create`),i.setAttribute("role","option"),i.setAttribute("aria-selected","false"),i.setAttribute("part","option create-option"),this._checkmark&&this._ensureCheckmark(i),this._ul.appendChild(i),this._createLi=i}this._createLi.setAttribute("data-value",this._createOption.value),this._createLi.setAttribute("data-kind","action"),this._createLi.setAttribute("data-action",this._createOption.action),this._setLabelText(this._createLi,this._createOption.label)}_ensureContainer(){if(this._ul)return this._ul;let t=this._host.querySelector(":scope > ul");return t||(t=document.createElement("ul"),this._host.appendChild(t)),t.setAttribute("role","presentation"),t.setAttribute("aria-hidden","true"),this._ul=t,t}_bootstrapFromDom(){const t=this._host.querySelector(":scope > ul");if(!t)return;this._ul=t,t.setAttribute("role","presentation"),t.setAttribute("aria-hidden","true");const n=Array.from(t.querySelectorAll(":scope > li"));if(n.length===0)return;const i=[];for(let r=0;r<n.length;r++){const s=n[r],l=s.getAttribute("data-value")??s.getAttribute("value")??s.textContent?.trim()??"",c=s.textContent?.trim()??"",a=s.hasAttribute("disabled")||s.getAttribute("aria-disabled")==="true";i.push({value:l,label:c,disabled:a}),s.setAttribute("role","option"),s.setAttribute("id",`${this._idPrefix}-${r}`),s.setAttribute("part","option"),s.setAttribute("data-value",l),s.setAttribute("aria-selected",this._selectedValues.has(l)?"true":"false"),s.setAttribute("aria-disabled",a?"true":"false"),this._checkmark&&this._ensureCheckmark(s)}this._options=i,this._liElements=n,this._onInitFromDom?.(i)}_syncOptionsToDom(){const t=this._ensureContainer();for(const n of this._liElements)n.remove();this._liElements=[];for(let n=0;n<this._options.length;n++){const i=this._createLiElement(this._options[n],n);this._liElements.push(i),t.appendChild(i)}this._createLi&&t.appendChild(this._createLi),this._syncFilterToDom()}_createLiElement(t,n){const i=document.createElement("li");return i.setAttribute("role","option"),i.setAttribute("id",`${this._idPrefix}-${n}`),i.setAttribute("part","option"),i.setAttribute("data-value",t.value),i.setAttribute("data-kind",t.kind??"option"),t.kind==="action"?i.setAttribute("data-action",t.action):i.removeAttribute("data-action"),i.setAttribute("aria-selected",this._selectedValues.has(t.value)?"true":"false"),i.setAttribute("aria-disabled",t.disabled?"true":"false"),this._checkmark&&this._ensureCheckmark(i),this._setLabelText(i,t.label),i}_setLabelText(t,n){for(const i of t.childNodes)if(i.nodeType===Node.TEXT_NODE){i.textContent=n;return}t.appendChild(document.createTextNode(n))}_ensureCheckmark(t){if(t.querySelector('[part="option-checkmark"]'))return;const n=document.createElement("span");n.setAttribute("part","option-checkmark"),n.setAttribute("aria-hidden","true"),n.textContent="✓",t.insertBefore(n,t.firstChild)}_removeCheckmark(t){t.querySelector('[part="option-checkmark"]')?.remove()}_syncCheckmarks(){const t=this._createLi?[...this._liElements,this._createLi]:[...this._liElements];for(const n of t)this._checkmark?this._ensureCheckmark(n):this._removeCheckmark(n)}_syncSelectedToDom(){for(let t=0;t<this._liElements.length;t++){const n=this._options[t];n&&this._liElements[t].setAttribute("aria-selected",this._selectedValues.has(n.value)?"true":"false")}}_syncFilterToDom(){for(let t=0;t<this._liElements.length;t++){const n=this._options[t];n&&this._applyFilterToLi(this._liElements[t],n)}}_applyFilterToLi(t,n){t.hidden=!this._isVisible(n)}_isVisible(t){if(!this._filterText)return!0;const n=t.label.toLowerCase(),i=this._filterText.toLowerCase();return typeof this._filterStrategy=="function"?this._filterStrategy(n,i):this._filterStrategy==="contains"?n.includes(i):n.startsWith(i)}}class Do extends Nt.AsyncDirective{constructor(t){if(super(t),this._options={},this._isPointerFocus=!1,this._onPointerdown=()=>{this._isPointerFocus=!0,this._target?.removeAttribute("data-interaction-mode")},this._onFocusin=()=>{this._isPointerFocus?this._isPointerFocus=!1:this._target?.setAttribute("data-interaction-mode","keyboard")},this._onKeydown=()=>{this._target?.setAttribute("data-interaction-mode","keyboard")},t.type!==ze.PartType.ELEMENT)throw new Error("The `keyInteraction` directive must be used on an element.")}get _target(){return this._options.attributeTarget??this._element?.deref()}_init(){const t=this._element?.deref();t instanceof HTMLElement&&(t.addEventListener("pointerdown",this._onPointerdown,{capture:!0}),t.addEventListener("focusin",this._onFocusin),t.addEventListener("keydown",this._onKeydown))}render(t){return Et.nothing}update(t,[n]){this.isConnected&&this._element?.deref()===void 0&&(this._element=new WeakRef(t.element),this._init()),this._options=n??{}}disconnected(){const t=this._element?.deref();t instanceof HTMLElement&&(t.removeEventListener("pointerdown",this._onPointerdown,{capture:!0}),t.removeEventListener("focusin",this._onFocusin),t.removeEventListener("keydown",this._onKeydown))}reconnected(){this._init()}}const Mo=Nt.directive(Do);class Io extends Nt.AsyncDirective{constructor(t){if(super(t),this._options={},t.type!==ze.PartType.ELEMENT)throw new Error("The `keyNavigation` directive must be used on an element.")}get navigationAxis(){if(this._options.navigationAxis)return this._options.navigationAxis;switch(this._element?.deref()?.role){case"slider":case"tablist":case"toolbar":case"menubar":return this._element?.deref()?.ariaOrientation==="vertical"?"vertical":"horizontal";case"separator":return this._element?.deref()?.ariaOrientation==="vertical"?"horizontal":"vertical";default:return this._element?.deref()?.ariaOrientation==="horizontal"?"horizontal":"vertical"}}_normalizeKey(t){switch(t){case"Up":return"ArrowUp";case"Down":return"ArrowDown";case"Left":return"ArrowLeft";case"Right":return"ArrowRight";default:return t}}_onKeydown(t){const n=this._normalizeKey(t.key),i=this.navigationAxis,r=this._element?.deref(),s=i==="horizontal"&&r!=null&&getComputedStyle(r).direction==="rtl",l=i==="horizontal"?s?"ArrowLeft":"ArrowRight":"ArrowDown",c=i==="horizontal"?s?"ArrowRight":"ArrowLeft":"ArrowUp",a=i==="horizontal"?"ArrowDown":"ArrowRight",o=i==="horizontal"?"ArrowUp":"ArrowLeft";let h;this._options.handleNavAxis!==!1&&(n===l?h=t.shiftKey?"next-large":"next":n===c?h=t.shiftKey?"prev-large":"prev":n==="Home"?h="start":n==="End"&&(h="end")),!h&&this._options.handleOpenAxis&&(n===a?h="open-to-first":n===o&&(h="open-to-last")),h||(n==="Enter"?h=this._options.handleActivate?"activate":"toggle":n===" "&&this._options.handleActivate?h="activate":n==="Escape"&&this._options.handleEscape&&(h="escape")),h!=null&&(this._callback(h),t.stopPropagation(),t.preventDefault())}_init(){const t=this._element?.deref();t!=null&&t instanceof HTMLElement&&(this._keyDownHandle=this._onKeydown.bind(this),t.addEventListener("keydown",this._keyDownHandle))}render(t,n){return Et.nothing}update(t,[n,i]){this.isConnected&&this._element?.deref()===void 0&&(this._element=new WeakRef(t.element),this._init()),this._callback=n.bind(t.options?.host??t.element),typeof i=="boolean"?this._options={}:this._options={...i}}disconnected(){const t=this._element?.deref();t!=null&&t instanceof HTMLElement&&t.removeEventListener("keydown",this._keyDownHandle)}reconnected(){this._init()}}const Ro=Nt.directive(Io);class jo extends Nt.AsyncDirective{constructor(t){if(super(t),this._activePointerId=null,t.type!==ze.PartType.ELEMENT)throw new Error("The `mouseMove` directive must be used on an element.");this._pointerDownHandle=this._onPointerDown.bind(this),this._pointerMoveHandle=this._onPointerMove.bind(this),this._pointerEndHandle=this._onPointerEnd.bind(this)}_onPointerDown(t){if(this._activePointerId!==null)return;t.preventDefault();const n=t.currentTarget;this._activePointerId=t.pointerId,this._capturePointer(n,t.pointerId),n.addEventListener("pointermove",this._pointerMoveHandle),n.addEventListener("pointerup",this._pointerEndHandle),n.addEventListener("pointercancel",this._pointerEndHandle),n.addEventListener("lostpointercapture",this._pointerEndHandle),n.focus()}_onPointerMove(t){t.pointerId===this._activePointerId&&(t.preventDefault(),this._callback(t))}_onPointerEnd(t){if(t.pointerId!==this._activePointerId)return;t.preventDefault();const n=t.currentTarget;this._releasePointer(n,t.pointerId),this._removePointerCycleListeners(n),this._activePointerId=null}_init(){const t=this._element?.deref();t&&(t.removeEventListener("pointerdown",this._pointerDownHandle),t.addEventListener("pointerdown",this._pointerDownHandle))}_removePointerCycleListeners(t){t.removeEventListener("pointermove",this._pointerMoveHandle),t.removeEventListener("pointerup",this._pointerEndHandle),t.removeEventListener("pointercancel",this._pointerEndHandle),t.removeEventListener("lostpointercapture",this._pointerEndHandle)}_capturePointer(t,n){try{t.setPointerCapture(n)}catch{}}_releasePointer(t,n){try{t.hasPointerCapture(n)&&t.releasePointerCapture(n)}catch{}}render(t){return Et.nothing}update(t,[n]){if(this._callback=n.bind(t.options?.host??t.element),!this.isConnected||!(t.element instanceof HTMLElement))return;const i=this._element?.deref();i!==t.element&&(i?.removeEventListener("pointerdown",this._pointerDownHandle),i&&this._removePointerCycleListeners(i),this._activePointerId=null,this._element=new WeakRef(t.element),this._init())}disconnected(){const t=this._element?.deref();t&&(t.removeEventListener("pointerdown",this._pointerDownHandle),this._removePointerCycleListeners(t),this._activePointerId=null)}reconnected(){this._init()}}const Fo=Nt.directive(jo);class $o{constructor(t,n){this._dragging=!1,this._startX=0,this._startY=0,this._startLeft=0,this._startTop=0,this._opts={axis:"both",step:4,disabled:!1,handle:null,bounds:"viewport",...n},this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerUp=this._handlePointerUp.bind(this),this._onPointerCancel=this._cancelDrag.bind(this),this._onLostPointerCapture=this._handleLostPointerCapture.bind(this),this._onKeyDown=this._handleKeyDown.bind(this),t.addController(this)}setOptions(t){const n=this._handle();Object.assign(this._opts,t);const i=this._handle();n!==i&&(this._detachFrom(n),this._attachTo(i))}hostConnected(){this._attachTo(this._handle())}hostDisconnected(){this._detachFrom(this._handle())}_handle(){return this._opts.handle??this._opts.target}_target(){return this._opts.target}_attachTo(t){t.addEventListener("pointerdown",this._onPointerDown),t.addEventListener("keydown",this._onKeyDown),t.hasAttribute("tabindex")||t.setAttribute("tabindex","0")}_detachFrom(t){t.removeEventListener("pointerdown",this._onPointerDown),t.removeEventListener("keydown",this._onKeyDown),t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointercancel",this._onPointerCancel),t.removeEventListener("lostpointercapture",this._onLostPointerCapture)}_handlePointerDown(t){if(this._opts.disabled||t.target.closest('button, [role="button"], a'))return;const n=this._target(),i=n.getBoundingClientRect();getComputedStyle(n).position==="static"&&(n.style.position="fixed"),n.style.translate="none",n.style.inset="auto",n.style.margin="0",n.style.left=`${i.left}px`,n.style.top=`${i.top}px`,this._startX=t.clientX,this._startY=t.clientY,this._startLeft=i.left,this._startTop=i.top,this._dragging=!0;const r=this._handle();r.setPointerCapture(t.pointerId),r.addEventListener("pointermove",this._onPointerMove),r.addEventListener("pointerup",this._onPointerUp),r.addEventListener("pointercancel",this._onPointerCancel),r.addEventListener("lostpointercapture",this._onLostPointerCapture),t.preventDefault()}_handlePointerMove(t){if(!this._dragging)return;const n=this._target(),{axis:i}=this._opts,[r,s,l,c]=this._boundsRect(),a=i!=="y"?Math.min(Math.max(this._startLeft+t.clientX-this._startX,r),l-n.offsetWidth):parseFloat(n.style.left)||0,o=i!=="x"?Math.min(Math.max(this._startTop+t.clientY-this._startY,s),c-n.offsetHeight):parseFloat(n.style.top)||0;n.style.left=`${a}px`,n.style.top=`${o}px`}_handlePointerUp(t){this._cancelDrag()}_handleLostPointerCapture(t){this._cancelDrag()}_cancelDrag(){if(!this._dragging)return;this._dragging=!1;const t=this._handle();t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointercancel",this._onPointerCancel),t.removeEventListener("lostpointercapture",this._onLostPointerCapture)}_handleKeyDown(t){if(this._opts.disabled||t.currentTarget!==t.target)return;const{axis:n}=this._opts,i=t.shiftKey?this._opts.step*10:this._opts.step;let r=0,s=0;switch(t.key){case"ArrowLeft":if(n==="y")return;r=-i;break;case"ArrowRight":if(n==="y")return;r=i;break;case"ArrowUp":if(n==="x")return;s=-i;break;case"ArrowDown":if(n==="x")return;s=i;break;default:return}const l=this._target();if(getComputedStyle(l).position==="static"){const d=l.getBoundingClientRect();l.style.position="fixed",l.style.translate="none",l.style.left=`${d.left}px`,l.style.top=`${d.top}px`}const[c,a,o,h]=this._boundsRect(),u=parseFloat(l.style.left)||0,f=parseFloat(l.style.top)||0;l.style.left=`${Math.min(Math.max(u+r,c),o-l.offsetWidth)}px`,l.style.top=`${Math.min(Math.max(f+s,a),h-l.offsetHeight)}px`,t.preventDefault(),t.stopPropagation()}_boundsRect(){const{bounds:t}=this._opts;if(!t||t==="viewport")return[0,0,window.innerWidth,window.innerHeight];if(t==="parent"){const i=this._opts.target.parentElement;if(!i)return[0,0,window.innerWidth,window.innerHeight];const r=i.getBoundingClientRect();return[r.left,r.top,r.right,r.bottom]}const n=t.getBoundingClientRect();return[n.left,n.top,n.right,n.bottom]}}class No{constructor(t,n){this._resizing=null,this._startX=0,this._startY=0,this._startW=0,this._startH=0,this._startLeft=0,this._startTop=0,this._effectiveMinW=0,this._effectiveMinH=0,this._cornerBtn=null,this._opts={direction:"none",threshold:8,step:4,disabled:!1,minWidth:100,minHeight:60,handle:null,bounds:"viewport",...n},this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerUp=this._handlePointerUp.bind(this),this._onPointerLeave=this._handlePointerLeave.bind(this),this._onKeyDown=this._handleKeyDown.bind(this),t.addController(this)}setOptions(t){Object.assign(this._opts,t)}hostConnected(){if(this._opts.direction==="none")return;const t=this._target();t.addEventListener("pointermove",this._onPointerMove),t.addEventListener("pointerdown",this._onPointerDown,{capture:!0}),t.addEventListener("pointerup",this._onPointerUp),t.addEventListener("pointerleave",this._onPointerLeave),this._injectCornerButton()}hostDisconnected(){const t=this._target();t.removeEventListener("pointermove",this._onPointerMove),t.removeEventListener("pointerdown",this._onPointerDown,{capture:!0}),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointerleave",this._onPointerLeave),this._removeCornerButton()}_target(){return this._opts.target}_injectCornerButton(){if(this._opts.handle)return;const t=this._target();getComputedStyle(t).position==="static"&&(t.style.position="relative");const n=document.createElement("button");n.setAttribute("data-rc-resize-corner",""),n.setAttribute("aria-label","Resize"),n.type="button",Object.assign(n.style,{position:"absolute",bottom:"0",right:"0",width:"12px",height:"12px",padding:"0",border:"none",background:"transparent",cursor:this._cornerCursor(),zIndex:"1"}),n.addEventListener("keydown",this._onKeyDown),t.appendChild(n),this._cornerBtn=n}_removeCornerButton(){this._cornerBtn&&(this._cornerBtn.removeEventListener("keydown",this._onKeyDown),this._cornerBtn.remove(),this._cornerBtn=null)}_cornerCursor(){switch(this._opts.direction){case"both":return"se-resize";case"horizontal":return"ew-resize";case"vertical":return"ns-resize";default:return"default"}}_edgeCursor(t){return{n:"n-resize",s:"s-resize",e:"e-resize",w:"w-resize",ne:"ne-resize",nw:"nw-resize",se:"se-resize",sw:"sw-resize"}[t]}_detectEdge(t){const{direction:n,threshold:i}=this._opts;if(n==="none")return null;const r=this._target().getBoundingClientRect(),s=t.clientX,l=t.clientY,c=s>=r.right-i&&s<=r.right+i,a=s>=r.left-i&&s<=r.left+i,o=l>=r.bottom-i&&l<=r.bottom+i,h=l>=r.top-i&&l<=r.top+i,u=s>=r.left&&s<=r.right,f=l>=r.top&&l<=r.bottom;if(n==="both"){if(c&&o)return"se";if(a&&o)return"sw";if(c&&h)return"ne";if(a&&h)return"nw";if(c&&f)return"e";if(a&&f)return"w";if(o&&u)return"s";if(h&&u)return"n"}if(n==="horizontal"){if(c&&f)return"e";if(a&&f)return"w"}if(n==="vertical"){if(o&&u)return"s";if(h&&u)return"n"}return null}_pinPosition(t){const n=t.getBoundingClientRect();return getComputedStyle(t).position==="static"&&(t.style.position="fixed"),t.style.translate="none",t.style.inset="auto",t.style.margin="0",t.style.boxSizing="border-box",t.style.left=`${n.left}px`,t.style.top=`${n.top}px`,t.style.width=`${n.width}px`,t.style.height=`${n.height}px`,n}_handlePointerDown(t){if(this._opts.disabled)return;const n=this._detectEdge(t);if(!n)return;t.stopPropagation();const i=this._target(),r=this._pinPosition(i);this._startX=t.clientX,this._startY=t.clientY,this._startW=r.width,this._startH=r.height,this._startLeft=r.left,this._startTop=r.top,this._resizing=n;const s=getComputedStyle(i);this._effectiveMinW=Math.max(this._opts.minWidth,parseFloat(s.minWidth)||0),this._effectiveMinH=Math.max(this._opts.minHeight,parseFloat(s.minHeight)||0),i.setPointerCapture(t.pointerId),t.preventDefault()}_handlePointerMove(t){if(this._resizing){const r=this._target(),[s,l,c,a]=this._boundsRect(),{maxWidth:o,maxHeight:h}=this._opts,u=this._effectiveMinW,f=this._effectiveMinH,d=t.clientX-this._startX,p=t.clientY-this._startY,m=this._resizing;if(m==="e"||m==="se"||m==="ne"){const y=Math.min(o??1/0,c-this._startLeft);r.style.width=`${Math.min(Math.max(this._startW+d,u),y)}px`}if(m==="w"||m==="sw"||m==="nw"){const y=this._startLeft+this._startW,b=Math.min(Math.max(this._startLeft+d,s,o!==void 0?y-o:-1/0),y-u);r.style.left=`${b}px`,r.style.width=`${y-b}px`}if(m==="s"||m==="se"||m==="sw"){const y=Math.min(h??1/0,a-this._startTop);r.style.height=`${Math.min(Math.max(this._startH+p,f),y)}px`}if(m==="n"||m==="ne"||m==="nw"){const y=this._startTop+this._startH,b=Math.min(Math.max(this._startTop+p,l,h!==void 0?y-h:-1/0),y-f);r.style.top=`${b}px`,r.style.height=`${y-b}px`}return}if(this._opts.handle)return;const n=this._detectEdge(t),i=this._target();i.style.cursor=n?this._edgeCursor(n):""}_handlePointerUp(t){this._resizing=null}_handlePointerLeave(t){this._resizing||(this._target().style.cursor="")}_handleKeyDown(t){if(this._opts.disabled)return;const{direction:n}=this._opts,i=t.key==="ArrowRight"||t.key==="ArrowLeft",r=t.key==="ArrowDown"||t.key==="ArrowUp";if(i&&n==="vertical"||r&&n==="horizontal"||!i&&!r)return;t.preventDefault(),t.stopPropagation();const s=this._target(),l=this._pinPosition(s),c=t.shiftKey?this._opts.step*10:this._opts.step,[,,a,o]=this._boundsRect(),{maxWidth:h,maxHeight:u}=this._opts,f=getComputedStyle(s),d=Math.max(this._opts.minWidth,parseFloat(f.minWidth)||0),p=Math.max(this._opts.minHeight,parseFloat(f.minHeight)||0);if(t.key==="ArrowRight"){const m=Math.min(h??1/0,a-l.left);s.style.width=`${Math.min(Math.max(s.offsetWidth+c,d),m)}px`}if(t.key==="ArrowLeft"&&(s.style.width=`${Math.max(s.offsetWidth-c,d)}px`),t.key==="ArrowDown"){const m=Math.min(u??1/0,o-l.top);s.style.height=`${Math.min(Math.max(s.offsetHeight+c,p),m)}px`}t.key==="ArrowUp"&&(s.style.height=`${Math.max(s.offsetHeight-c,p)}px`)}_boundsRect(){const{bounds:t}=this._opts;if(!t||t==="viewport")return[0,0,window.innerWidth,window.innerHeight];if(t==="parent"){const i=this._opts.target.parentElement;if(!i)return[0,0,window.innerWidth,window.innerHeight];const r=i.getBoundingClientRect();return[r.left,r.top,r.right,r.bottom]}const n=t.getBoundingClientRect();return[n.left,n.top,n.right,n.bottom]}}function pe(e,t){const n=`${t}px`;switch(e){case"top":return`position-area: top; margin-bottom: ${n};`;case"top-start":return`bottom: anchor(top); top: auto; left: anchor(left); right: auto; margin-bottom: ${n};`;case"top-end":return`bottom: anchor(top); top: auto; left: auto; right: anchor(right); margin-bottom: ${n};`;case"bottom":return`position-area: bottom; margin-top: ${n};`;case"bottom-start":return`top: anchor(bottom); bottom: auto; left: anchor(left); right: auto; margin-top: ${n};`;case"bottom-end":return`top: anchor(bottom); bottom: auto; left: auto; right: anchor(right); margin-top: ${n};`;case"left":return`position-area: left; margin-right: ${n};`;case"left-start":return`top: anchor(top); bottom: auto; right: anchor(left); left: auto; margin-right: ${n};`;case"left-end":return`top: auto; bottom: anchor(bottom); right: anchor(left); left: auto; margin-right: ${n};`;case"right":return`position-area: right; margin-left: ${n};`;case"right-start":return`top: anchor(top); bottom: auto; left: anchor(right); right: auto; margin-left: ${n};`;case"right-end":return`top: auto; bottom: anchor(bottom); left: anchor(right); right: auto; margin-left: ${n};`}}const Mn={top:"bottom","top-start":"bottom-start","top-end":"bottom-end",bottom:"top","bottom-start":"top-start","bottom-end":"top-end",left:"right","left-start":"right-start","left-end":"right-end",right:"left","right-start":"left-start","right-end":"left-end"},zo={top:"top","top-start":"top-end","top-end":"top-start",bottom:"bottom","bottom-start":"bottom-end","bottom-end":"bottom-start",left:"left","left-start":"left-end","left-end":"left-start",right:"right","right-start":"right-end","right-end":"right-start"},In=CSS.supports("position-try-fallbacks: flip-block")&&CSS.supports("min-width: anchor-size(width)");let Rn=null,We=null;function Wo(){return In?Promise.resolve(null):(We||(We=Promise.resolve().then(()=>Wp).then(e=>(Rn=e.default,Rn)).catch(()=>null)),We)}let Bo=0;class Ho{constructor(t,n){this._styleEl=null,this._adoptedSheet=null,this._opts=n,this._uid=`rc-anchor-${++Bo}`,t.addController(this)}setOptions(t){Object.assign(this._opts,t),this._applyAndPolyfill()}update(){this._applyAndPolyfill()}hostConnected(){this._applyAndPolyfill()}hostDisconnected(){this._cleanup()}_anchor(){const{anchor:t}=this._opts;return typeof t=="function"?t():t}_floating(){const{floating:t}=this._opts;return typeof t=="function"?t():t}_shadowHost(){const{shadowHost:t}=this._opts;return typeof t=="function"?t():t??null}_applyAndPolyfill(){this._apply(),In||this._applyPolyfillOrFallback()}async _applyPolyfillOrFallback(){const t=await Wo(),n=this._shadowHost();t?await t({roots:n?[n]:void 0,useAnimationFrame:!1}):this._positionFallback()}_apply(){if(this._opts.disabled){this._cleanup();return}const t=this._anchor(),n=this._floating();if(!t||!n)return;const i=this._opts.placement??"bottom-start",r=this._opts.offset??4,s=this._opts.flip??!0,l=`--${this._uid}`,c=this._uid;t.style.setProperty("anchor-name",l),n.setAttribute("data-rc-anchor",c);const a=Mn[i],o=zo[i],h=Mn[o],u=s?`
|
|
2
2
|
@position-try --${c}-end { ${pe(o,r)} }
|
|
3
3
|
@position-try --${c}-flip { ${pe(a,r)} }
|
|
4
4
|
@position-try --${c}-both { ${pe(h,r)} }
|