Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / lib / codex / modules / useFloatingMenu.cjs
blob6b56d541fd837c7d42a1f8c1d810553528838aa5
1 "use strict";var U=Object.defineProperty,q=Object.defineProperties;var A=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var C=(e,l,n)=>l in e?U(e,l,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[l]=n,$=(e,l)=>{for(var n in l||(l={}))F.call(l,n)&&C(e,n,l[n]);if(B)for(var n of B(l))I.call(l,n)&&C(e,n,l[n]);return e},H=(e,l)=>q(e,A(l));const t=require("vue"),s=require("./floating-ui.dom.js");function S(e){return e!=null&&typeof e=="object"&&"$el"in e}function _(e){if(S(e)){const l=e.$el;return s.isNode(l)&&s.getNodeName(l)==="#comment"?null:l}return e}function L(e){return typeof window=="undefined"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function j(e,l){const n=L(e);return Math.round(l*n)/n}function z(e,l,n){n===void 0&&(n={});const g=n.whileElementsMounted,y=t.computed(()=>{var u;return(u=t.unref(n.open))!=null?u:!0}),R=t.computed(()=>t.unref(n.middleware)),b=t.computed(()=>{var u;return(u=t.unref(n.placement))!=null?u:"bottom"}),p=t.computed(()=>{var u;return(u=t.unref(n.strategy))!=null?u:"absolute"}),x=t.computed(()=>{var u;return(u=t.unref(n.transform))!=null?u:!0}),d=t.computed(()=>_(e.value)),r=t.computed(()=>_(l.value)),m=t.ref(0),o=t.ref(0),a=t.ref(p.value),i=t.ref(b.value),c=t.shallowRef({}),h=t.ref(!1),w=t.computed(()=>{const u={position:a.value,left:"0",top:"0"};if(!r.value)return u;const D=j(r.value,m.value),M=j(r.value,o.value);return x.value?$(H($({},u),{transform:"translate("+D+"px, "+M+"px)"}),L(r.value)>=1.5&&{willChange:"transform"}):{position:a.value,left:D+"px",top:M+"px"}});let f;function v(){d.value==null||r.value==null||s.computePosition(d.value,r.value,{middleware:R.value,placement:b.value,strategy:p.value}).then(u=>{m.value=u.x,o.value=u.y,a.value=u.strategy,i.value=u.placement,c.value=u.middlewareData,h.value=!0})}function O(){typeof f=="function"&&(f(),f=void 0)}function T(){if(O(),g===void 0){v();return}if(d.value!=null&&r.value!=null){f=g(d.value,r.value,v);return}}function N(){y.value||(h.value=!1)}return t.watch([R,b,p],v,{flush:"sync"}),t.watch([d,r],T,{flush:"sync"}),t.watch(y,N,{flush:"sync"}),t.getCurrentScope()&&t.onScopeDispose(O),{x:t.shallowReadonly(m),y:t.shallowReadonly(o),strategy:t.shallowReadonly(a),placement:t.shallowReadonly(i),middlewareData:t.shallowReadonly(c),isPositioned:t.shallowReadonly(h),floatingStyles:w,update:v}}function P(e){return e&&"$el"in e?e.$el:e}const E=16,W=128;function k(e,l,n){var m;const g=()=>{var o;return(o=l.value)==null?void 0:o.isExpanded()},y=[s.offset(n==null?void 0:n.offset),s.size({padding:E,apply({rects:o,elements:a,availableHeight:i,availableWidth:c}){Object.assign(a.floating.style,{width:"".concat(n!=null&&n.useAvailableWidth?c:o.reference.width,"px"),maxHeight:"".concat(Math.max(W,i),"px")})}}),s.flip({padding:E}),s.hide({strategy:"escaped"}),s.hide()],{floatingStyles:R,placement:b,middlewareData:p,update:x}=z(e,l,{middleware:y,placement:(m=n==null?void 0:n.placement)!=null?m:"bottom"}),d=t.computed(()=>{var a,i;return!g()||!!((a=p.value.hide)!=null&&a.escaped)||((i=p.value.hide)==null?void 0:i.referenceHidden)?"hidden":"visible"});t.watch([R,d,b],([o,a,i])=>{var c,h,w,f,v;Object.assign((h=(c=l.value)==null?void 0:c.$el.style)!=null?h:{},{visibility:a,position:o.position,top:"".concat(o.top,"px"),right:"unset",left:"".concat(o.left,"px"),transform:(w=o.transform)!=null?w:"none",borderTopLeftRadius:i==="bottom"&&a==="visible"?"0":"",borderTopRightRadius:i==="bottom"&&a==="visible"?"0":"",borderBottomLeftRadius:i==="top"&&a==="visible"?"0":"",borderBottomRightRadius:i==="top"&&a==="visible"?"0":""}),Object.assign((v=(f=P(e.value))==null?void 0:f.style)!=null?v:{},{borderTopLeftRadius:i==="top"&&a==="visible"?"0":"",borderTopRightRadius:i==="top"&&a==="visible"?"0":"",borderBottomLeftRadius:i==="bottom"&&a==="visible"?"0":"",borderBottomRightRadius:i==="bottom"&&a==="visible"?"0":""})});let r=null;t.watch(g,o=>{var a;o?r=s.autoUpdate(e.value&&"$el"in e.value?e.value.$el:e,(a=l.value)==null?void 0:a.$el,x):r&&(r(),r=null)})}module.exports=k;