@vielzeug/orbit 1.1.3 → 1.1.4
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/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -1
- package/dist/_dev.js.map +1 -1
- package/dist/auto-update.cjs +1 -1
- package/dist/auto-update.cjs.map +1 -1
- package/dist/auto-update.js +1 -1
- package/dist/auto-update.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/middleware/arrow.cjs +1 -1
- package/dist/middleware/arrow.cjs.map +1 -1
- package/dist/middleware/arrow.js +1 -1
- package/dist/middleware/arrow.js.map +1 -1
- package/dist/middleware/auto-placement.cjs +1 -1
- package/dist/middleware/auto-placement.cjs.map +1 -1
- package/dist/middleware/auto-placement.js +1 -1
- package/dist/middleware/auto-placement.js.map +1 -1
- package/dist/middleware/shift.cjs +1 -1
- package/dist/middleware/shift.cjs.map +1 -1
- package/dist/orbit.cjs +1 -1
- package/dist/orbit.cjs.map +1 -1
- package/dist/orbit.iife.js +1 -1
- package/dist/orbit.iife.js.map +1 -1
- package/dist/orbit.js +1 -1
- package/dist/orbit.js.map +1 -1
- package/dist/reactive.cjs.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +5 -5
package/dist/_dev.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function e(e){}function t(e){}exports.devOnly=t,exports.warn=e;
|
|
2
2
|
//# sourceMappingURL=_dev.cjs.map
|
package/dist/_dev.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ORBIT_PROD__?: boolean }).__ORBIT_PROD__;\n\n/** @internal @security Messages may include user-supplied element dimensions or computed styles. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/orbit] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ORBIT_PROD__?: boolean }).__ORBIT_PROD__;\n\n/** @internal @security Messages may include user-supplied element dimensions or computed styles. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/orbit] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAGA,SAAgB,EAAK,EAAmB,CAExC,CAGA,SAAgB,EAAQ,EAAsB,CAE9C"}
|
package/dist/_dev.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function e(e){}function t(e){}export{t as devOnly,e as warn};
|
|
2
2
|
//# sourceMappingURL=_dev.js.map
|
package/dist/_dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ORBIT_PROD__?: boolean }).__ORBIT_PROD__;\n\n/** @internal @security Messages may include user-supplied element dimensions or computed styles. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/orbit] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ORBIT_PROD__?: boolean }).__ORBIT_PROD__;\n\n/** @internal @security Messages may include user-supplied element dimensions or computed styles. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/orbit] ${msg}`);\n}\n\n/** @internal — Run fn only in dev builds. Use when dev-only logic goes beyond a single warn() / error() call. */\nexport function devOnly(fn: () => void): void {\n if (isDev) fn();\n}\n"],"mappings":"AAGA,SAAgB,EAAK,EAAmB,CAExC,CAGA,SAAgB,EAAQ,EAAsB,CAE9C"}
|
package/dist/auto-update.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./utils.cjs");let t=require("@vielzeug/arsenal");function n(t){let n=[],r=e.flatTreeParent(t);for(;r;){let t=getComputedStyle(r),i=t.overflow+t.overflowX+t.overflowY;/auto|scroll|overlay/.test(i)&&n.push(r),r=e.flatTreeParent(r)}return n}function r(r,i,a,{animationFrame:o=!1,observeAncestors:s=!0,observeFloating:c=!0,observeVisualViewport:l=!0,pauseWhenHidden:u=!0,throttle:d=0}={}){let f=d>0?(0,t.throttle)(a,d,{leading:!0,trailing:!0}):null,p=f??a,m=!0,h=()=>{m&&p()};p();let g=[];if(u&&e.isElement(r)&&typeof IntersectionObserver<`u`){let e=new IntersectionObserver(e=>{m=e.at(-1)?.isIntersecting??!0,m&&p()});e.observe(r),g.push(()=>e.disconnect())}if(e.isElement(r)&&s){let e=n(r);for(let t of e)t.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>t.removeEventListener(`scroll`,h));window.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>window.removeEventListener(`scroll`,h))}else{let e=e=>{e.composedPath().includes(i)||h()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),g.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,h,{passive:!0}),g.push(()=>window.removeEventListener(`resize`,h));let _=l?window.visualViewport:null;_&&(_.addEventListener(`resize`,h,{passive:!0}),_.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>{_.removeEventListener(`resize`,h),_.removeEventListener(`scroll`,h)}));let v=new ResizeObserver(h);e.isElement(r)&&v.observe(r),c&&v.observe(i),g.push(()=>v.disconnect());let y=0;if(o){let e=()=>{h(),y=window.requestAnimationFrame(e)};y=window.requestAnimationFrame(e),g.push(()=>window.cancelAnimationFrame(y))}return()=>{f?.cancel();for(let e of g)e()}}exports.autoUpdate=r;
|
|
1
|
+
const e=require("./utils.cjs");let t=require("@vielzeug/arsenal/function");function n(t){let n=[],r=e.flatTreeParent(t);for(;r;){let t=getComputedStyle(r),i=t.overflow+t.overflowX+t.overflowY;/auto|scroll|overlay/.test(i)&&n.push(r),r=e.flatTreeParent(r)}return n}function r(r,i,a,{animationFrame:o=!1,observeAncestors:s=!0,observeFloating:c=!0,observeVisualViewport:l=!0,pauseWhenHidden:u=!0,throttle:d=0}={}){let f=d>0?(0,t.throttle)(a,d,{leading:!0,trailing:!0}):null,p=f??a,m=!0,h=()=>{m&&p()};p();let g=[];if(u&&e.isElement(r)&&typeof IntersectionObserver<`u`){let e=new IntersectionObserver(e=>{m=e.at(-1)?.isIntersecting??!0,m&&p()});e.observe(r),g.push(()=>e.disconnect())}if(e.isElement(r)&&s){let e=n(r);for(let t of e)t.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>t.removeEventListener(`scroll`,h));window.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>window.removeEventListener(`scroll`,h))}else{let e=e=>{e.composedPath().includes(i)||h()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),g.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,h,{passive:!0}),g.push(()=>window.removeEventListener(`resize`,h));let _=l?window.visualViewport:null;_&&(_.addEventListener(`resize`,h,{passive:!0}),_.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>{_.removeEventListener(`resize`,h),_.removeEventListener(`scroll`,h)}));let v=new ResizeObserver(h);e.isElement(r)&&v.observe(r),c&&v.observe(i),g.push(()=>v.disconnect());let y=0;if(o){let e=()=>{h(),y=window.requestAnimationFrame(e)};y=window.requestAnimationFrame(e),g.push(()=>window.cancelAnimationFrame(y))}return()=>{f?.cancel();for(let e of g)e()}}exports.autoUpdate=r;
|
|
2
2
|
//# sourceMappingURL=auto-update.cjs.map
|
package/dist/auto-update.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-update.cjs","names":[],"sources":["../src/auto-update.ts"],"sourcesContent":["import { throttle } from '@vielzeug/arsenal';\n\nimport type { ReferenceElement } from './types';\n\nimport { flatTreeParent, isElement } from './utils';\n\nexport interface AutoUpdateOptions {\n /** Watch the floating element for size changes. Default: `true`. */\n observeFloating?: boolean;\n /**\n * Listen to scroll events on ancestor scroll containers of the reference element\n * in addition to the window. More efficient in deeply nested DOMs.\n * Set to `false` to use only a capture-phase window listener.\n * Default: `true`.\n */\n observeAncestors?: boolean;\n /** Track visual viewport scroll and resize (useful for pinch-zoom). Default: `true`. */\n observeVisualViewport?: boolean;\n /** Re-position on every animation frame. Use only when the reference itself animates. Default: `false`. */\n animationFrame?: boolean;\n /**\n * Throttle update calls to at most once every `throttle` milliseconds.\n * Uses a leading + trailing strategy: fires immediately, then once more after the interval.\n * Default: `0` (no throttling).\n */\n throttle?: number;\n /**\n * Pause position updates while the reference element is scrolled out of the viewport.\n * Uses IntersectionObserver to detect visibility. When the reference becomes visible again,\n * one position update is fired immediately.\n * Default: `true`.\n */\n pauseWhenHidden?: boolean;\n}\n\n/**\n * Collects the ancestor scroll containers of an element (up to and including the\n * nearest scrollable ancestor). Used to scope scroll listeners to the minimal\n * set of elements rather than relying on a capture-phase window listener.\n *\n * Walks the flat (rendering) tree via `flatTreeParent` — not light-DOM `parentElement` alone —\n * so a scroll container that lives inside the shadow tree a component's light-DOM content is\n * *projected into* (e.g. a dialog's own internal scroll region, reached only by crossing its\n * `<slot>`) is still found, instead of silently skipped.\n */\nfunction getScrollAncestors(el: Element): Element[] {\n const ancestors: Element[] = [];\n let current: Element | null = flatTreeParent(el);\n\n while (current) {\n const style = getComputedStyle(current);\n const overflow = style.overflow + style.overflowX + style.overflowY;\n\n if (/auto|scroll|overlay/.test(overflow)) {\n ancestors.push(current);\n }\n\n current = flatTreeParent(current);\n }\n\n return ancestors;\n}\n\n/**\n * Calls `update` immediately and re-calls it whenever the reference or floating element\n * could have changed position: scroll, resize, ResizeObserver, or animation frames.\n *\n * By default, scroll listeners are attached to both ancestor scroll containers of the reference\n * AND the window (for document scroll). The ancestor listeners fire for nested container scrolls;\n * the window listener fires for page-level scroll. Set `observeAncestors: false` to use only a\n * capture-phase window listener.\n *\n * Returns a cleanup function that removes all listeners.\n *\n * @example\n * ```ts\n * const cleanup = autoUpdate(reference, floating, () => {\n * const { x, y } = computePosition(reference, floating, options);\n * floating.style.left = `${x}px`;\n * floating.style.top = `${y}px`;\n * });\n * // later:\n * cleanup();\n * ```\n */\nexport function autoUpdate(\n reference: ReferenceElement,\n floating: HTMLElement,\n update: () => void,\n {\n animationFrame = false,\n observeAncestors = true,\n observeFloating = true,\n observeVisualViewport = true,\n pauseWhenHidden = true,\n throttle: throttleMs = 0,\n }: AutoUpdateOptions = {},\n): () => void {\n const throttled = throttleMs > 0 ? throttle(update, throttleMs, { leading: true, trailing: true }) : null;\n const notify = throttled ?? update;\n\n // ── Visibility guard ─────────────────────────────────────────────────────────\n let referenceVisible = true;\n const conditionalNotify = (): void => {\n if (referenceVisible) notify();\n };\n\n // Initial call always runs regardless of visibility state.\n notify();\n\n const cleanups: Array<() => void> = [];\n\n // IntersectionObserver: pause updates when reference is off-screen.\n if (pauseWhenHidden && isElement(reference) && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n referenceVisible = entries.at(-1)?.isIntersecting ?? true;\n\n if (referenceVisible) notify(); // Re-position immediately when becoming visible.\n });\n\n io.observe(reference);\n cleanups.push(() => io.disconnect());\n }\n\n // ── Scroll listeners ────────────────────────────────────────────────────────\n if (isElement(reference) && observeAncestors) {\n // Targeted ancestor listeners for nested container scroll.\n const ancestors = getScrollAncestors(reference);\n\n for (const ancestor of ancestors) {\n ancestor.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => ancestor.removeEventListener('scroll', conditionalNotify));\n }\n\n // Always add window scroll for document-level scroll (non-capture, doesn't fire for nested containers).\n window.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('scroll', conditionalNotify));\n } else {\n // VirtualReference or observeAncestors: false — capture-phase window listener catches all scrolls.\n const scrollHandler = (e: Event): void => {\n if (e.composedPath().includes(floating)) return;\n\n conditionalNotify();\n };\n\n window.addEventListener('scroll', scrollHandler, { capture: true, passive: true });\n cleanups.push(() => window.removeEventListener('scroll', scrollHandler, { capture: true }));\n }\n\n window.addEventListener('resize', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('resize', conditionalNotify));\n\n const vv = observeVisualViewport ? window.visualViewport : null;\n\n if (vv) {\n vv.addEventListener('resize', conditionalNotify, { passive: true });\n vv.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => {\n vv.removeEventListener('resize', conditionalNotify);\n vv.removeEventListener('scroll', conditionalNotify);\n });\n }\n\n const ro = new ResizeObserver(conditionalNotify);\n\n if (isElement(reference)) ro.observe(reference);\n\n if (observeFloating) ro.observe(floating);\n\n cleanups.push(() => ro.disconnect());\n\n let frameId = 0;\n\n if (animationFrame) {\n const frameLoop = (): void => {\n conditionalNotify();\n frameId = window.requestAnimationFrame(frameLoop);\n };\n\n frameId = window.requestAnimationFrame(frameLoop);\n cleanups.push(() => window.cancelAnimationFrame(frameId));\n }\n\n return (): void => {\n throttled?.cancel();\n\n for (const fn of cleanups) fn();\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-update.cjs","names":[],"sources":["../src/auto-update.ts"],"sourcesContent":["import { throttle } from '@vielzeug/arsenal/function';\n\nimport type { ReferenceElement } from './types';\n\nimport { flatTreeParent, isElement } from './utils';\n\nexport interface AutoUpdateOptions {\n /** Watch the floating element for size changes. Default: `true`. */\n observeFloating?: boolean;\n /**\n * Listen to scroll events on ancestor scroll containers of the reference element\n * in addition to the window. More efficient in deeply nested DOMs.\n * Set to `false` to use only a capture-phase window listener.\n * Default: `true`.\n */\n observeAncestors?: boolean;\n /** Track visual viewport scroll and resize (useful for pinch-zoom). Default: `true`. */\n observeVisualViewport?: boolean;\n /** Re-position on every animation frame. Use only when the reference itself animates. Default: `false`. */\n animationFrame?: boolean;\n /**\n * Throttle update calls to at most once every `throttle` milliseconds.\n * Uses a leading + trailing strategy: fires immediately, then once more after the interval.\n * Default: `0` (no throttling).\n */\n throttle?: number;\n /**\n * Pause position updates while the reference element is scrolled out of the viewport.\n * Uses IntersectionObserver to detect visibility. When the reference becomes visible again,\n * one position update is fired immediately.\n * Default: `true`.\n */\n pauseWhenHidden?: boolean;\n}\n\n/**\n * Collects the ancestor scroll containers of an element (up to and including the\n * nearest scrollable ancestor). Used to scope scroll listeners to the minimal\n * set of elements rather than relying on a capture-phase window listener.\n *\n * Walks the flat (rendering) tree via `flatTreeParent` — not light-DOM `parentElement` alone —\n * so a scroll container that lives inside the shadow tree a component's light-DOM content is\n * *projected into* (e.g. a dialog's own internal scroll region, reached only by crossing its\n * `<slot>`) is still found, instead of silently skipped.\n */\nfunction getScrollAncestors(el: Element): Element[] {\n const ancestors: Element[] = [];\n let current: Element | null = flatTreeParent(el);\n\n while (current) {\n const style = getComputedStyle(current);\n const overflow = style.overflow + style.overflowX + style.overflowY;\n\n if (/auto|scroll|overlay/.test(overflow)) {\n ancestors.push(current);\n }\n\n current = flatTreeParent(current);\n }\n\n return ancestors;\n}\n\n/**\n * Calls `update` immediately and re-calls it whenever the reference or floating element\n * could have changed position: scroll, resize, ResizeObserver, or animation frames.\n *\n * By default, scroll listeners are attached to both ancestor scroll containers of the reference\n * AND the window (for document scroll). The ancestor listeners fire for nested container scrolls;\n * the window listener fires for page-level scroll. Set `observeAncestors: false` to use only a\n * capture-phase window listener.\n *\n * Returns a cleanup function that removes all listeners.\n *\n * @example\n * ```ts\n * const cleanup = autoUpdate(reference, floating, () => {\n * const { x, y } = computePosition(reference, floating, options);\n * floating.style.left = `${x}px`;\n * floating.style.top = `${y}px`;\n * });\n * // later:\n * cleanup();\n * ```\n */\nexport function autoUpdate(\n reference: ReferenceElement,\n floating: HTMLElement,\n update: () => void,\n {\n animationFrame = false,\n observeAncestors = true,\n observeFloating = true,\n observeVisualViewport = true,\n pauseWhenHidden = true,\n throttle: throttleMs = 0,\n }: AutoUpdateOptions = {},\n): () => void {\n const throttled = throttleMs > 0 ? throttle(update, throttleMs, { leading: true, trailing: true }) : null;\n const notify = throttled ?? update;\n\n // ── Visibility guard ─────────────────────────────────────────────────────────\n let referenceVisible = true;\n const conditionalNotify = (): void => {\n if (referenceVisible) notify();\n };\n\n // Initial call always runs regardless of visibility state.\n notify();\n\n const cleanups: Array<() => void> = [];\n\n // IntersectionObserver: pause updates when reference is off-screen.\n if (pauseWhenHidden && isElement(reference) && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n referenceVisible = entries.at(-1)?.isIntersecting ?? true;\n\n if (referenceVisible) notify(); // Re-position immediately when becoming visible.\n });\n\n io.observe(reference);\n cleanups.push(() => io.disconnect());\n }\n\n // ── Scroll listeners ────────────────────────────────────────────────────────\n if (isElement(reference) && observeAncestors) {\n // Targeted ancestor listeners for nested container scroll.\n const ancestors = getScrollAncestors(reference);\n\n for (const ancestor of ancestors) {\n ancestor.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => ancestor.removeEventListener('scroll', conditionalNotify));\n }\n\n // Always add window scroll for document-level scroll (non-capture, doesn't fire for nested containers).\n window.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('scroll', conditionalNotify));\n } else {\n // VirtualReference or observeAncestors: false — capture-phase window listener catches all scrolls.\n const scrollHandler = (e: Event): void => {\n if (e.composedPath().includes(floating)) return;\n\n conditionalNotify();\n };\n\n window.addEventListener('scroll', scrollHandler, { capture: true, passive: true });\n cleanups.push(() => window.removeEventListener('scroll', scrollHandler, { capture: true }));\n }\n\n window.addEventListener('resize', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('resize', conditionalNotify));\n\n const vv = observeVisualViewport ? window.visualViewport : null;\n\n if (vv) {\n vv.addEventListener('resize', conditionalNotify, { passive: true });\n vv.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => {\n vv.removeEventListener('resize', conditionalNotify);\n vv.removeEventListener('scroll', conditionalNotify);\n });\n }\n\n const ro = new ResizeObserver(conditionalNotify);\n\n if (isElement(reference)) ro.observe(reference);\n\n if (observeFloating) ro.observe(floating);\n\n cleanups.push(() => ro.disconnect());\n\n let frameId = 0;\n\n if (animationFrame) {\n const frameLoop = (): void => {\n conditionalNotify();\n frameId = window.requestAnimationFrame(frameLoop);\n };\n\n frameId = window.requestAnimationFrame(frameLoop);\n cleanups.push(() => window.cancelAnimationFrame(frameId));\n }\n\n return (): void => {\n throttled?.cancel();\n\n for (const fn of cleanups) fn();\n };\n}\n"],"mappings":"2EA6CA,SAAS,EAAmB,EAAwB,CAClD,IAAM,EAAuB,CAAC,EAC1B,EAA0B,EAAA,eAAe,CAAE,EAE/C,KAAO,GAAS,CACd,IAAM,EAAQ,iBAAiB,CAAO,EAChC,EAAW,EAAM,SAAW,EAAM,UAAY,EAAM,UAEtD,sBAAsB,KAAK,CAAQ,GACrC,EAAU,KAAK,CAAO,EAGxB,EAAU,EAAA,eAAe,CAAO,CAClC,CAEA,OAAO,CACT,CAwBA,SAAgB,EACd,EACA,EACA,EACA,CACE,iBAAiB,GACjB,mBAAmB,GACnB,kBAAkB,GAClB,wBAAwB,GACxB,kBAAkB,GAClB,SAAU,EAAa,GACF,CAAC,EACZ,CACZ,IAAM,EAAY,EAAa,GAAA,EAAI,EAAA,SAAA,CAAS,EAAQ,EAAY,CAAE,QAAS,GAAM,SAAU,EAAK,CAAC,EAAI,KAC/F,EAAS,GAAa,EAGxB,EAAmB,GACjB,MAAgC,CAChC,GAAkB,EAAO,CAC/B,EAGA,EAAO,EAEP,IAAM,EAA8B,CAAC,EAGrC,GAAI,GAAmB,EAAA,UAAU,CAAS,GAAK,OAAO,qBAAyB,IAAa,CAC1F,IAAM,EAAK,IAAI,qBAAsB,GAAY,CAC/C,EAAmB,EAAQ,GAAG,EAAE,CAAC,EAAE,gBAAkB,GAEjD,GAAkB,EAAO,CAC/B,CAAC,EAED,EAAG,QAAQ,CAAS,EACpB,EAAS,SAAW,EAAG,WAAW,CAAC,CACrC,CAGA,GAAI,EAAA,UAAU,CAAS,GAAK,EAAkB,CAE5C,IAAM,EAAY,EAAmB,CAAS,EAE9C,IAAK,IAAM,KAAY,EACrB,EAAS,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACxE,EAAS,SAAW,EAAS,oBAAoB,SAAU,CAAiB,CAAC,EAI/E,OAAO,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACtE,EAAS,SAAW,OAAO,oBAAoB,SAAU,CAAiB,CAAC,CAC7E,KAAO,CAEL,IAAM,EAAiB,GAAmB,CACpC,EAAE,aAAa,CAAC,CAAC,SAAS,CAAQ,GAEtC,EAAkB,CACpB,EAEA,OAAO,iBAAiB,SAAU,EAAe,CAAE,QAAS,GAAM,QAAS,EAAK,CAAC,EACjF,EAAS,SAAW,OAAO,oBAAoB,SAAU,EAAe,CAAE,QAAS,EAAK,CAAC,CAAC,CAC5F,CAEA,OAAO,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACtE,EAAS,SAAW,OAAO,oBAAoB,SAAU,CAAiB,CAAC,EAE3E,IAAM,EAAK,EAAwB,OAAO,eAAiB,KAEvD,IACF,EAAG,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EAClE,EAAG,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EAClE,EAAS,SAAW,CAClB,EAAG,oBAAoB,SAAU,CAAiB,EAClD,EAAG,oBAAoB,SAAU,CAAiB,CACpD,CAAC,GAGH,IAAM,EAAK,IAAI,eAAe,CAAiB,EAE3C,EAAA,UAAU,CAAS,GAAG,EAAG,QAAQ,CAAS,EAE1C,GAAiB,EAAG,QAAQ,CAAQ,EAExC,EAAS,SAAW,EAAG,WAAW,CAAC,EAEnC,IAAI,EAAU,EAEd,GAAI,EAAgB,CAClB,IAAM,MAAwB,CAC5B,EAAkB,EAClB,EAAU,OAAO,sBAAsB,CAAS,CAClD,EAEA,EAAU,OAAO,sBAAsB,CAAS,EAChD,EAAS,SAAW,OAAO,qBAAqB,CAAO,CAAC,CAC1D,CAEA,UAAmB,CACjB,GAAW,OAAO,EAElB,IAAK,IAAM,KAAM,EAAU,EAAG,CAChC,CACF"}
|
package/dist/auto-update.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{flatTreeParent as e,isElement as t}from"./utils.js";import{throttle as n}from"@vielzeug/arsenal";function r(t){let n=[],r=e(t);for(;r;){let t=getComputedStyle(r),i=t.overflow+t.overflowX+t.overflowY;/auto|scroll|overlay/.test(i)&&n.push(r),r=e(r)}return n}function i(e,i,a,{animationFrame:o=!1,observeAncestors:s=!0,observeFloating:c=!0,observeVisualViewport:l=!0,pauseWhenHidden:u=!0,throttle:d=0}={}){let f=d>0?n(a,d,{leading:!0,trailing:!0}):null,p=f??a,m=!0,h=()=>{m&&p()};p();let g=[];if(u&&t(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{m=e.at(-1)?.isIntersecting??!0,m&&p()});t.observe(e),g.push(()=>t.disconnect())}if(t(e)&&s){let t=r(e);for(let e of t)e.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>e.removeEventListener(`scroll`,h));window.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>window.removeEventListener(`scroll`,h))}else{let e=e=>{e.composedPath().includes(i)||h()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),g.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,h,{passive:!0}),g.push(()=>window.removeEventListener(`resize`,h));let _=l?window.visualViewport:null;_&&(_.addEventListener(`resize`,h,{passive:!0}),_.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>{_.removeEventListener(`resize`,h),_.removeEventListener(`scroll`,h)}));let v=new ResizeObserver(h);t(e)&&v.observe(e),c&&v.observe(i),g.push(()=>v.disconnect());let y=0;if(o){let e=()=>{h(),y=window.requestAnimationFrame(e)};y=window.requestAnimationFrame(e),g.push(()=>window.cancelAnimationFrame(y))}return()=>{f?.cancel();for(let e of g)e()}}export{i as autoUpdate};
|
|
1
|
+
import{flatTreeParent as e,isElement as t}from"./utils.js";import{throttle as n}from"@vielzeug/arsenal/function";function r(t){let n=[],r=e(t);for(;r;){let t=getComputedStyle(r),i=t.overflow+t.overflowX+t.overflowY;/auto|scroll|overlay/.test(i)&&n.push(r),r=e(r)}return n}function i(e,i,a,{animationFrame:o=!1,observeAncestors:s=!0,observeFloating:c=!0,observeVisualViewport:l=!0,pauseWhenHidden:u=!0,throttle:d=0}={}){let f=d>0?n(a,d,{leading:!0,trailing:!0}):null,p=f??a,m=!0,h=()=>{m&&p()};p();let g=[];if(u&&t(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{m=e.at(-1)?.isIntersecting??!0,m&&p()});t.observe(e),g.push(()=>t.disconnect())}if(t(e)&&s){let t=r(e);for(let e of t)e.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>e.removeEventListener(`scroll`,h));window.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>window.removeEventListener(`scroll`,h))}else{let e=e=>{e.composedPath().includes(i)||h()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),g.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,h,{passive:!0}),g.push(()=>window.removeEventListener(`resize`,h));let _=l?window.visualViewport:null;_&&(_.addEventListener(`resize`,h,{passive:!0}),_.addEventListener(`scroll`,h,{passive:!0}),g.push(()=>{_.removeEventListener(`resize`,h),_.removeEventListener(`scroll`,h)}));let v=new ResizeObserver(h);t(e)&&v.observe(e),c&&v.observe(i),g.push(()=>v.disconnect());let y=0;if(o){let e=()=>{h(),y=window.requestAnimationFrame(e)};y=window.requestAnimationFrame(e),g.push(()=>window.cancelAnimationFrame(y))}return()=>{f?.cancel();for(let e of g)e()}}export{i as autoUpdate};
|
|
2
2
|
//# sourceMappingURL=auto-update.js.map
|
package/dist/auto-update.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-update.js","names":[],"sources":["../src/auto-update.ts"],"sourcesContent":["import { throttle } from '@vielzeug/arsenal';\n\nimport type { ReferenceElement } from './types';\n\nimport { flatTreeParent, isElement } from './utils';\n\nexport interface AutoUpdateOptions {\n /** Watch the floating element for size changes. Default: `true`. */\n observeFloating?: boolean;\n /**\n * Listen to scroll events on ancestor scroll containers of the reference element\n * in addition to the window. More efficient in deeply nested DOMs.\n * Set to `false` to use only a capture-phase window listener.\n * Default: `true`.\n */\n observeAncestors?: boolean;\n /** Track visual viewport scroll and resize (useful for pinch-zoom). Default: `true`. */\n observeVisualViewport?: boolean;\n /** Re-position on every animation frame. Use only when the reference itself animates. Default: `false`. */\n animationFrame?: boolean;\n /**\n * Throttle update calls to at most once every `throttle` milliseconds.\n * Uses a leading + trailing strategy: fires immediately, then once more after the interval.\n * Default: `0` (no throttling).\n */\n throttle?: number;\n /**\n * Pause position updates while the reference element is scrolled out of the viewport.\n * Uses IntersectionObserver to detect visibility. When the reference becomes visible again,\n * one position update is fired immediately.\n * Default: `true`.\n */\n pauseWhenHidden?: boolean;\n}\n\n/**\n * Collects the ancestor scroll containers of an element (up to and including the\n * nearest scrollable ancestor). Used to scope scroll listeners to the minimal\n * set of elements rather than relying on a capture-phase window listener.\n *\n * Walks the flat (rendering) tree via `flatTreeParent` — not light-DOM `parentElement` alone —\n * so a scroll container that lives inside the shadow tree a component's light-DOM content is\n * *projected into* (e.g. a dialog's own internal scroll region, reached only by crossing its\n * `<slot>`) is still found, instead of silently skipped.\n */\nfunction getScrollAncestors(el: Element): Element[] {\n const ancestors: Element[] = [];\n let current: Element | null = flatTreeParent(el);\n\n while (current) {\n const style = getComputedStyle(current);\n const overflow = style.overflow + style.overflowX + style.overflowY;\n\n if (/auto|scroll|overlay/.test(overflow)) {\n ancestors.push(current);\n }\n\n current = flatTreeParent(current);\n }\n\n return ancestors;\n}\n\n/**\n * Calls `update` immediately and re-calls it whenever the reference or floating element\n * could have changed position: scroll, resize, ResizeObserver, or animation frames.\n *\n * By default, scroll listeners are attached to both ancestor scroll containers of the reference\n * AND the window (for document scroll). The ancestor listeners fire for nested container scrolls;\n * the window listener fires for page-level scroll. Set `observeAncestors: false` to use only a\n * capture-phase window listener.\n *\n * Returns a cleanup function that removes all listeners.\n *\n * @example\n * ```ts\n * const cleanup = autoUpdate(reference, floating, () => {\n * const { x, y } = computePosition(reference, floating, options);\n * floating.style.left = `${x}px`;\n * floating.style.top = `${y}px`;\n * });\n * // later:\n * cleanup();\n * ```\n */\nexport function autoUpdate(\n reference: ReferenceElement,\n floating: HTMLElement,\n update: () => void,\n {\n animationFrame = false,\n observeAncestors = true,\n observeFloating = true,\n observeVisualViewport = true,\n pauseWhenHidden = true,\n throttle: throttleMs = 0,\n }: AutoUpdateOptions = {},\n): () => void {\n const throttled = throttleMs > 0 ? throttle(update, throttleMs, { leading: true, trailing: true }) : null;\n const notify = throttled ?? update;\n\n // ── Visibility guard ─────────────────────────────────────────────────────────\n let referenceVisible = true;\n const conditionalNotify = (): void => {\n if (referenceVisible) notify();\n };\n\n // Initial call always runs regardless of visibility state.\n notify();\n\n const cleanups: Array<() => void> = [];\n\n // IntersectionObserver: pause updates when reference is off-screen.\n if (pauseWhenHidden && isElement(reference) && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n referenceVisible = entries.at(-1)?.isIntersecting ?? true;\n\n if (referenceVisible) notify(); // Re-position immediately when becoming visible.\n });\n\n io.observe(reference);\n cleanups.push(() => io.disconnect());\n }\n\n // ── Scroll listeners ────────────────────────────────────────────────────────\n if (isElement(reference) && observeAncestors) {\n // Targeted ancestor listeners for nested container scroll.\n const ancestors = getScrollAncestors(reference);\n\n for (const ancestor of ancestors) {\n ancestor.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => ancestor.removeEventListener('scroll', conditionalNotify));\n }\n\n // Always add window scroll for document-level scroll (non-capture, doesn't fire for nested containers).\n window.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('scroll', conditionalNotify));\n } else {\n // VirtualReference or observeAncestors: false — capture-phase window listener catches all scrolls.\n const scrollHandler = (e: Event): void => {\n if (e.composedPath().includes(floating)) return;\n\n conditionalNotify();\n };\n\n window.addEventListener('scroll', scrollHandler, { capture: true, passive: true });\n cleanups.push(() => window.removeEventListener('scroll', scrollHandler, { capture: true }));\n }\n\n window.addEventListener('resize', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('resize', conditionalNotify));\n\n const vv = observeVisualViewport ? window.visualViewport : null;\n\n if (vv) {\n vv.addEventListener('resize', conditionalNotify, { passive: true });\n vv.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => {\n vv.removeEventListener('resize', conditionalNotify);\n vv.removeEventListener('scroll', conditionalNotify);\n });\n }\n\n const ro = new ResizeObserver(conditionalNotify);\n\n if (isElement(reference)) ro.observe(reference);\n\n if (observeFloating) ro.observe(floating);\n\n cleanups.push(() => ro.disconnect());\n\n let frameId = 0;\n\n if (animationFrame) {\n const frameLoop = (): void => {\n conditionalNotify();\n frameId = window.requestAnimationFrame(frameLoop);\n };\n\n frameId = window.requestAnimationFrame(frameLoop);\n cleanups.push(() => window.cancelAnimationFrame(frameId));\n }\n\n return (): void => {\n throttled?.cancel();\n\n for (const fn of cleanups) fn();\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-update.js","names":[],"sources":["../src/auto-update.ts"],"sourcesContent":["import { throttle } from '@vielzeug/arsenal/function';\n\nimport type { ReferenceElement } from './types';\n\nimport { flatTreeParent, isElement } from './utils';\n\nexport interface AutoUpdateOptions {\n /** Watch the floating element for size changes. Default: `true`. */\n observeFloating?: boolean;\n /**\n * Listen to scroll events on ancestor scroll containers of the reference element\n * in addition to the window. More efficient in deeply nested DOMs.\n * Set to `false` to use only a capture-phase window listener.\n * Default: `true`.\n */\n observeAncestors?: boolean;\n /** Track visual viewport scroll and resize (useful for pinch-zoom). Default: `true`. */\n observeVisualViewport?: boolean;\n /** Re-position on every animation frame. Use only when the reference itself animates. Default: `false`. */\n animationFrame?: boolean;\n /**\n * Throttle update calls to at most once every `throttle` milliseconds.\n * Uses a leading + trailing strategy: fires immediately, then once more after the interval.\n * Default: `0` (no throttling).\n */\n throttle?: number;\n /**\n * Pause position updates while the reference element is scrolled out of the viewport.\n * Uses IntersectionObserver to detect visibility. When the reference becomes visible again,\n * one position update is fired immediately.\n * Default: `true`.\n */\n pauseWhenHidden?: boolean;\n}\n\n/**\n * Collects the ancestor scroll containers of an element (up to and including the\n * nearest scrollable ancestor). Used to scope scroll listeners to the minimal\n * set of elements rather than relying on a capture-phase window listener.\n *\n * Walks the flat (rendering) tree via `flatTreeParent` — not light-DOM `parentElement` alone —\n * so a scroll container that lives inside the shadow tree a component's light-DOM content is\n * *projected into* (e.g. a dialog's own internal scroll region, reached only by crossing its\n * `<slot>`) is still found, instead of silently skipped.\n */\nfunction getScrollAncestors(el: Element): Element[] {\n const ancestors: Element[] = [];\n let current: Element | null = flatTreeParent(el);\n\n while (current) {\n const style = getComputedStyle(current);\n const overflow = style.overflow + style.overflowX + style.overflowY;\n\n if (/auto|scroll|overlay/.test(overflow)) {\n ancestors.push(current);\n }\n\n current = flatTreeParent(current);\n }\n\n return ancestors;\n}\n\n/**\n * Calls `update` immediately and re-calls it whenever the reference or floating element\n * could have changed position: scroll, resize, ResizeObserver, or animation frames.\n *\n * By default, scroll listeners are attached to both ancestor scroll containers of the reference\n * AND the window (for document scroll). The ancestor listeners fire for nested container scrolls;\n * the window listener fires for page-level scroll. Set `observeAncestors: false` to use only a\n * capture-phase window listener.\n *\n * Returns a cleanup function that removes all listeners.\n *\n * @example\n * ```ts\n * const cleanup = autoUpdate(reference, floating, () => {\n * const { x, y } = computePosition(reference, floating, options);\n * floating.style.left = `${x}px`;\n * floating.style.top = `${y}px`;\n * });\n * // later:\n * cleanup();\n * ```\n */\nexport function autoUpdate(\n reference: ReferenceElement,\n floating: HTMLElement,\n update: () => void,\n {\n animationFrame = false,\n observeAncestors = true,\n observeFloating = true,\n observeVisualViewport = true,\n pauseWhenHidden = true,\n throttle: throttleMs = 0,\n }: AutoUpdateOptions = {},\n): () => void {\n const throttled = throttleMs > 0 ? throttle(update, throttleMs, { leading: true, trailing: true }) : null;\n const notify = throttled ?? update;\n\n // ── Visibility guard ─────────────────────────────────────────────────────────\n let referenceVisible = true;\n const conditionalNotify = (): void => {\n if (referenceVisible) notify();\n };\n\n // Initial call always runs regardless of visibility state.\n notify();\n\n const cleanups: Array<() => void> = [];\n\n // IntersectionObserver: pause updates when reference is off-screen.\n if (pauseWhenHidden && isElement(reference) && typeof IntersectionObserver !== 'undefined') {\n const io = new IntersectionObserver((entries) => {\n referenceVisible = entries.at(-1)?.isIntersecting ?? true;\n\n if (referenceVisible) notify(); // Re-position immediately when becoming visible.\n });\n\n io.observe(reference);\n cleanups.push(() => io.disconnect());\n }\n\n // ── Scroll listeners ────────────────────────────────────────────────────────\n if (isElement(reference) && observeAncestors) {\n // Targeted ancestor listeners for nested container scroll.\n const ancestors = getScrollAncestors(reference);\n\n for (const ancestor of ancestors) {\n ancestor.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => ancestor.removeEventListener('scroll', conditionalNotify));\n }\n\n // Always add window scroll for document-level scroll (non-capture, doesn't fire for nested containers).\n window.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('scroll', conditionalNotify));\n } else {\n // VirtualReference or observeAncestors: false — capture-phase window listener catches all scrolls.\n const scrollHandler = (e: Event): void => {\n if (e.composedPath().includes(floating)) return;\n\n conditionalNotify();\n };\n\n window.addEventListener('scroll', scrollHandler, { capture: true, passive: true });\n cleanups.push(() => window.removeEventListener('scroll', scrollHandler, { capture: true }));\n }\n\n window.addEventListener('resize', conditionalNotify, { passive: true });\n cleanups.push(() => window.removeEventListener('resize', conditionalNotify));\n\n const vv = observeVisualViewport ? window.visualViewport : null;\n\n if (vv) {\n vv.addEventListener('resize', conditionalNotify, { passive: true });\n vv.addEventListener('scroll', conditionalNotify, { passive: true });\n cleanups.push(() => {\n vv.removeEventListener('resize', conditionalNotify);\n vv.removeEventListener('scroll', conditionalNotify);\n });\n }\n\n const ro = new ResizeObserver(conditionalNotify);\n\n if (isElement(reference)) ro.observe(reference);\n\n if (observeFloating) ro.observe(floating);\n\n cleanups.push(() => ro.disconnect());\n\n let frameId = 0;\n\n if (animationFrame) {\n const frameLoop = (): void => {\n conditionalNotify();\n frameId = window.requestAnimationFrame(frameLoop);\n };\n\n frameId = window.requestAnimationFrame(frameLoop);\n cleanups.push(() => window.cancelAnimationFrame(frameId));\n }\n\n return (): void => {\n throttled?.cancel();\n\n for (const fn of cleanups) fn();\n };\n}\n"],"mappings":"iHA6CA,SAAS,EAAmB,EAAwB,CAClD,IAAM,EAAuB,CAAC,EAC1B,EAA0B,EAAe,CAAE,EAE/C,KAAO,GAAS,CACd,IAAM,EAAQ,iBAAiB,CAAO,EAChC,EAAW,EAAM,SAAW,EAAM,UAAY,EAAM,UAEtD,sBAAsB,KAAK,CAAQ,GACrC,EAAU,KAAK,CAAO,EAGxB,EAAU,EAAe,CAAO,CAClC,CAEA,OAAO,CACT,CAwBA,SAAgB,EACd,EACA,EACA,EACA,CACE,iBAAiB,GACjB,mBAAmB,GACnB,kBAAkB,GAClB,wBAAwB,GACxB,kBAAkB,GAClB,SAAU,EAAa,GACF,CAAC,EACZ,CACZ,IAAM,EAAY,EAAa,EAAI,EAAS,EAAQ,EAAY,CAAE,QAAS,GAAM,SAAU,EAAK,CAAC,EAAI,KAC/F,EAAS,GAAa,EAGxB,EAAmB,GACjB,MAAgC,CAChC,GAAkB,EAAO,CAC/B,EAGA,EAAO,EAEP,IAAM,EAA8B,CAAC,EAGrC,GAAI,GAAmB,EAAU,CAAS,GAAK,OAAO,qBAAyB,IAAa,CAC1F,IAAM,EAAK,IAAI,qBAAsB,GAAY,CAC/C,EAAmB,EAAQ,GAAG,EAAE,CAAC,EAAE,gBAAkB,GAEjD,GAAkB,EAAO,CAC/B,CAAC,EAED,EAAG,QAAQ,CAAS,EACpB,EAAS,SAAW,EAAG,WAAW,CAAC,CACrC,CAGA,GAAI,EAAU,CAAS,GAAK,EAAkB,CAE5C,IAAM,EAAY,EAAmB,CAAS,EAE9C,IAAK,IAAM,KAAY,EACrB,EAAS,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACxE,EAAS,SAAW,EAAS,oBAAoB,SAAU,CAAiB,CAAC,EAI/E,OAAO,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACtE,EAAS,SAAW,OAAO,oBAAoB,SAAU,CAAiB,CAAC,CAC7E,KAAO,CAEL,IAAM,EAAiB,GAAmB,CACpC,EAAE,aAAa,CAAC,CAAC,SAAS,CAAQ,GAEtC,EAAkB,CACpB,EAEA,OAAO,iBAAiB,SAAU,EAAe,CAAE,QAAS,GAAM,QAAS,EAAK,CAAC,EACjF,EAAS,SAAW,OAAO,oBAAoB,SAAU,EAAe,CAAE,QAAS,EAAK,CAAC,CAAC,CAC5F,CAEA,OAAO,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EACtE,EAAS,SAAW,OAAO,oBAAoB,SAAU,CAAiB,CAAC,EAE3E,IAAM,EAAK,EAAwB,OAAO,eAAiB,KAEvD,IACF,EAAG,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EAClE,EAAG,iBAAiB,SAAU,EAAmB,CAAE,QAAS,EAAK,CAAC,EAClE,EAAS,SAAW,CAClB,EAAG,oBAAoB,SAAU,CAAiB,EAClD,EAAG,oBAAoB,SAAU,CAAiB,CACpD,CAAC,GAGH,IAAM,EAAK,IAAI,eAAe,CAAiB,EAE3C,EAAU,CAAS,GAAG,EAAG,QAAQ,CAAS,EAE1C,GAAiB,EAAG,QAAQ,CAAQ,EAExC,EAAS,SAAW,EAAG,WAAW,CAAC,EAEnC,IAAI,EAAU,EAEd,GAAI,EAAgB,CAClB,IAAM,MAAwB,CAC5B,EAAkB,EAClB,EAAU,OAAO,sBAAsB,CAAS,CAClD,EAEA,EAAU,OAAO,sBAAsB,CAAS,EAChD,EAAS,SAAW,OAAO,qBAAqB,CAAO,CAAC,CAC1D,CAEA,UAAmB,CACjB,GAAW,OAAO,EAElB,IAAK,IAAM,KAAM,EAAU,EAAG,CAChC,CACF"}
|
package/dist/core.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs"),t=require("./utils.cjs")
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./utils.cjs");require("./_dev.cjs");function n(e,n){return{floating:t.toRect(n.getBoundingClientRect()),reference:t.toRect(e.getBoundingClientRect())}}function r(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var i=8;function a(e,t,n){return Promise.resolve().then(()=>s(e,t,n))}function o(e,t,n){return new Promise((r,i)=>{requestAnimationFrame(()=>{try{r(s(e,t,n))}catch(e){i(e)}})})}function s(a,o,{boundary:s,containingBlock:c,middleware:l=[],padding:u,placement:d=`bottom`}={}){let f=l.filter(Boolean),p=f.map(e=>{let n=e[t.MIDDLEWARE_NAME];return typeof n==`string`?n:null});t.validateMiddlewareNames(p);let m=d,h={},g=n(a,o);for(let e=0;e<i;e+=1){let e={...t.baseCoords(m,g.reference,g.floating),boundary:s,elements:{floating:o,reference:a},initialPlacement:d,middlewareData:h,padding:u,placement:m,rects:g},i;for(let t of f){let n=t(e);if(e=r(e,n),h=e.middlewareData,i=n?.reset,i)break}if(!i){let t={middlewareData:e.middlewareData,placement:e.placement,x:e.x,y:e.y};if(c){let e=c.getBoundingClientRect();return{...t,x:t.x-e.x,y:t.y-e.y}}return t}i.remeasure?g=n(a,o):i.rects!=null&&(g=i.rects),m=i.placement??e.placement}throw new e.OrbitConfigError(`Middleware triggered too many resets in a single compute cycle.`)}exports.computePosition=s,exports.computePositionAsync=a,exports.computePositionRaf=o,exports.getRects=n;
|
|
2
2
|
//# sourceMappingURL=core.cjs.map
|
package/dist/core.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n ComputePositionOptions,\n ComputePositionResult,\n Middleware,\n MiddlewareData,\n MiddlewareReset,\n MiddlewareResult,\n MiddlewareState,\n ReferenceElement,\n} from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { OrbitConfigError } from './errors';\nimport { baseCoords, MIDDLEWARE_NAME, toRect, validateMiddlewareNames } from './utils';\n\n// ── DOM helpers ────────────────────────────────────────────────────────────────────────────────\n\n/** Reads the bounding rects of the reference and floating elements from the DOM. */\nexport function getRects(reference: ReferenceElement, floating: HTMLElement): MiddlewareState['rects'] {\n return {\n floating: toRect(floating.getBoundingClientRect()),\n reference: toRect(reference.getBoundingClientRect()),\n };\n}\n\n// ── Internal state helpers ───────────────────────────────────────────────────────────\n\nfunction mergeState(state: MiddlewareState, result: MiddlewareResult | void): MiddlewareState {\n if (!result) return state;\n\n return {\n ...state,\n middlewareData: result.data\n ? (Object.assign(Object.create(null), state.middlewareData, result.data) as MiddlewareData)\n : state.middlewareData,\n placement: result.placement ?? state.placement,\n x: result.x ?? state.x,\n y: result.y ?? state.y,\n };\n}\n\n// ── Constants ─────────────────────────────────────────────────────────────────────────────────\n\n/** Maximum number of pipeline restarts allowed per `computePosition` call before throwing. */\nconst MAX_RESETS = 8;\n\n// ── Public API ────────────────────────────────────────────────────────────────────────────────\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **microtask** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful for async component lifecycles (e.g. `await nextTick()` in Vue/React) where the\n * synchronous `computePosition` would read stale DOM measurements because layout has not been\n * committed yet. Note: this defers to the microtask queue, not the next animation frame — if you\n * need post-layout measurements use `requestAnimationFrame` instead.\n *\n * @example\n * ```ts\n * const result = await computePositionAsync(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionAsync(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return Promise.resolve().then(() => computePosition(reference, floating, options));\n}\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **animation frame** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful when the layout has not yet committed (e.g. immediately after DOM insertion). Unlike\n * `computePositionAsync` which defers to the microtask queue, this waits for the next\n * `requestAnimationFrame` tick — guaranteeing post-layout DOM measurements.\n *\n * @example\n * ```ts\n * const result = await computePositionRaf(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionRaf(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return new Promise((resolve, reject) => {\n requestAnimationFrame(() => {\n try {\n resolve(computePosition(reference, floating, options));\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\n/**\n * Runs the middleware pipeline and returns the final position.\n *\n * Position is computed in viewport-relative coordinates assuming `position: fixed`.\n */\nexport function computePosition(\n reference: ReferenceElement,\n floating: HTMLElement,\n { boundary, containingBlock, middleware = [], padding, placement = 'bottom' }: ComputePositionOptions = {},\n): ComputePositionResult {\n const mws = middleware.filter(Boolean) as Middleware[];\n\n if (reference === floating) {\n warn('computePosition: reference and floating are the same element.');\n }\n\n const names = mws.map((mw) => {\n const tag = (mw as unknown as Record<symbol, unknown>)[MIDDLEWARE_NAME];\n\n return typeof tag === 'string' ? tag : null;\n });\n\n validateMiddlewareNames(names);\n\n let currentPlacement = placement;\n let middlewareData: MiddlewareData = {};\n let rects = getRects(reference, floating);\n\n devOnly(() => {\n if (rects.floating.width === 0 && rects.floating.height === 0) {\n warn('computePosition: floating element has zero dimensions — is it hidden or detached from the DOM?');\n }\n\n const pos = getComputedStyle(floating).position;\n\n if (pos !== 'fixed' && pos !== 'absolute') {\n warn(\n `computePosition: floating element has \\`position: ${pos}\\`. ` +\n 'Orbit computes viewport-relative coordinates and expects position: fixed ' +\n '(or absolute for scoped stacking contexts).',\n );\n }\n });\n\n for (let resets = 0; resets < MAX_RESETS; resets += 1) {\n let state: MiddlewareState = {\n ...baseCoords(currentPlacement, rects.reference, rects.floating),\n boundary,\n elements: { floating, reference },\n initialPlacement: placement,\n middlewareData,\n padding,\n placement: currentPlacement,\n rects,\n };\n\n let reset: MiddlewareReset | undefined;\n\n for (const mw of mws) {\n const result = mw(state);\n\n state = mergeState(state, result);\n middlewareData = state.middlewareData;\n reset = result?.reset;\n\n if (reset) break;\n }\n\n if (!reset) {\n const result: ComputePositionResult = {\n middlewareData: state.middlewareData,\n placement: state.placement,\n x: state.x,\n y: state.y,\n };\n\n if (containingBlock) {\n const cb = containingBlock.getBoundingClientRect();\n\n return { ...result, x: result.x - cb.x, y: result.y - cb.y };\n }\n\n return result;\n }\n\n if (reset.remeasure) {\n rects = getRects(reference, floating);\n } else if (reset.rects != null) {\n rects = reset.rects;\n }\n\n currentPlacement = reset.placement ?? state.placement;\n }\n\n throw new OrbitConfigError('Middleware triggered too many resets in a single compute cycle.');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n ComputePositionOptions,\n ComputePositionResult,\n Middleware,\n MiddlewareData,\n MiddlewareReset,\n MiddlewareResult,\n MiddlewareState,\n ReferenceElement,\n} from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { OrbitConfigError } from './errors';\nimport { baseCoords, MIDDLEWARE_NAME, toRect, validateMiddlewareNames } from './utils';\n\n// ── DOM helpers ────────────────────────────────────────────────────────────────────────────────\n\n/** Reads the bounding rects of the reference and floating elements from the DOM. */\nexport function getRects(reference: ReferenceElement, floating: HTMLElement): MiddlewareState['rects'] {\n return {\n floating: toRect(floating.getBoundingClientRect()),\n reference: toRect(reference.getBoundingClientRect()),\n };\n}\n\n// ── Internal state helpers ───────────────────────────────────────────────────────────\n\nfunction mergeState(state: MiddlewareState, result: MiddlewareResult | void): MiddlewareState {\n if (!result) return state;\n\n return {\n ...state,\n middlewareData: result.data\n ? (Object.assign(Object.create(null), state.middlewareData, result.data) as MiddlewareData)\n : state.middlewareData,\n placement: result.placement ?? state.placement,\n x: result.x ?? state.x,\n y: result.y ?? state.y,\n };\n}\n\n// ── Constants ─────────────────────────────────────────────────────────────────────────────────\n\n/** Maximum number of pipeline restarts allowed per `computePosition` call before throwing. */\nconst MAX_RESETS = 8;\n\n// ── Public API ────────────────────────────────────────────────────────────────────────────────\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **microtask** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful for async component lifecycles (e.g. `await nextTick()` in Vue/React) where the\n * synchronous `computePosition` would read stale DOM measurements because layout has not been\n * committed yet. Note: this defers to the microtask queue, not the next animation frame — if you\n * need post-layout measurements use `requestAnimationFrame` instead.\n *\n * @example\n * ```ts\n * const result = await computePositionAsync(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionAsync(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return Promise.resolve().then(() => computePosition(reference, floating, options));\n}\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **animation frame** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful when the layout has not yet committed (e.g. immediately after DOM insertion). Unlike\n * `computePositionAsync` which defers to the microtask queue, this waits for the next\n * `requestAnimationFrame` tick — guaranteeing post-layout DOM measurements.\n *\n * @example\n * ```ts\n * const result = await computePositionRaf(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionRaf(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return new Promise((resolve, reject) => {\n requestAnimationFrame(() => {\n try {\n resolve(computePosition(reference, floating, options));\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\n/**\n * Runs the middleware pipeline and returns the final position.\n *\n * Position is computed in viewport-relative coordinates assuming `position: fixed`.\n */\nexport function computePosition(\n reference: ReferenceElement,\n floating: HTMLElement,\n { boundary, containingBlock, middleware = [], padding, placement = 'bottom' }: ComputePositionOptions = {},\n): ComputePositionResult {\n const mws = middleware.filter(Boolean) as Middleware[];\n\n if (reference === floating) {\n warn('computePosition: reference and floating are the same element.');\n }\n\n const names = mws.map((mw) => {\n const tag = (mw as unknown as Record<symbol, unknown>)[MIDDLEWARE_NAME];\n\n return typeof tag === 'string' ? tag : null;\n });\n\n validateMiddlewareNames(names);\n\n let currentPlacement = placement;\n let middlewareData: MiddlewareData = {};\n let rects = getRects(reference, floating);\n\n devOnly(() => {\n if (rects.floating.width === 0 && rects.floating.height === 0) {\n warn('computePosition: floating element has zero dimensions — is it hidden or detached from the DOM?');\n }\n\n const pos = getComputedStyle(floating).position;\n\n if (pos !== 'fixed' && pos !== 'absolute') {\n warn(\n `computePosition: floating element has \\`position: ${pos}\\`. ` +\n 'Orbit computes viewport-relative coordinates and expects position: fixed ' +\n '(or absolute for scoped stacking contexts).',\n );\n }\n });\n\n for (let resets = 0; resets < MAX_RESETS; resets += 1) {\n let state: MiddlewareState = {\n ...baseCoords(currentPlacement, rects.reference, rects.floating),\n boundary,\n elements: { floating, reference },\n initialPlacement: placement,\n middlewareData,\n padding,\n placement: currentPlacement,\n rects,\n };\n\n let reset: MiddlewareReset | undefined;\n\n for (const mw of mws) {\n const result = mw(state);\n\n state = mergeState(state, result);\n middlewareData = state.middlewareData;\n reset = result?.reset;\n\n if (reset) break;\n }\n\n if (!reset) {\n const result: ComputePositionResult = {\n middlewareData: state.middlewareData,\n placement: state.placement,\n x: state.x,\n y: state.y,\n };\n\n if (containingBlock) {\n const cb = containingBlock.getBoundingClientRect();\n\n return { ...result, x: result.x - cb.x, y: result.y - cb.y };\n }\n\n return result;\n }\n\n if (reset.remeasure) {\n rects = getRects(reference, floating);\n } else if (reset.rects != null) {\n rects = reset.rects;\n }\n\n currentPlacement = reset.placement ?? state.placement;\n }\n\n throw new OrbitConfigError('Middleware triggered too many resets in a single compute cycle.');\n}\n"],"mappings":"+EAkBA,SAAgB,EAAS,EAA6B,EAAiD,CACrG,MAAO,CACL,SAAU,EAAA,OAAO,EAAS,sBAAsB,CAAC,EACjD,UAAW,EAAA,OAAO,EAAU,sBAAsB,CAAC,CACrD,CACF,CAIA,SAAS,EAAW,EAAwB,EAAkD,CAG5F,OAFK,EAEE,CACL,GAAG,EACH,eAAgB,EAAO,KAClB,OAAO,OAAO,OAAO,OAAO,IAAI,EAAG,EAAM,eAAgB,EAAO,IAAI,EACrE,EAAM,eACV,UAAW,EAAO,WAAa,EAAM,UACrC,EAAG,EAAO,GAAK,EAAM,EACrB,EAAG,EAAO,GAAK,EAAM,CACvB,EAVoB,CAWtB,CAKA,IAAM,EAAa,EAoBnB,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAO,QAAQ,QAAQ,CAAC,CAAC,SAAW,EAAgB,EAAW,EAAU,CAAO,CAAC,CACnF,CAiBA,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,0BAA4B,CAC1B,GAAI,CACF,EAAQ,EAAgB,EAAW,EAAU,CAAO,CAAC,CACvD,OAAS,EAAK,CACZ,EAAO,CAAG,CACZ,CACF,CAAC,CACH,CAAC,CACH,CAOA,SAAgB,EACd,EACA,EACA,CAAE,WAAU,kBAAiB,aAAa,CAAC,EAAG,UAAS,YAAY,UAAqC,CAAC,EAClF,CACvB,IAAM,EAAM,EAAW,OAAO,OAAO,EAM/B,EAAQ,EAAI,IAAK,GAAO,CAC5B,IAAM,EAAO,EAA0C,EAAA,iBAEvD,OAAO,OAAO,GAAQ,SAAW,EAAM,IACzC,CAAC,EAED,EAAA,wBAAwB,CAAK,EAE7B,IAAI,EAAmB,EACnB,EAAiC,CAAC,EAClC,EAAQ,EAAS,EAAW,CAAQ,EAkBxC,IAAK,IAAI,EAAS,EAAG,EAAS,EAAY,GAAU,EAAG,CACrD,IAAI,EAAyB,CAC3B,GAAG,EAAA,WAAW,EAAkB,EAAM,UAAW,EAAM,QAAQ,EAC/D,WACA,SAAU,CAAE,WAAU,WAAU,EAChC,iBAAkB,EAClB,iBACA,UACA,UAAW,EACX,OACF,EAEI,EAEJ,IAAK,IAAM,KAAM,EAAK,CACpB,IAAM,EAAS,EAAG,CAAK,EAMvB,GAJA,EAAQ,EAAW,EAAO,CAAM,EAChC,EAAiB,EAAM,eACvB,EAAQ,GAAQ,MAEZ,EAAO,KACb,CAEA,GAAI,CAAC,EAAO,CACV,IAAM,EAAgC,CACpC,eAAgB,EAAM,eACtB,UAAW,EAAM,UACjB,EAAG,EAAM,EACT,EAAG,EAAM,CACX,EAEA,GAAI,EAAiB,CACnB,IAAM,EAAK,EAAgB,sBAAsB,EAEjD,MAAO,CAAE,GAAG,EAAQ,EAAG,EAAO,EAAI,EAAG,EAAG,EAAG,EAAO,EAAI,EAAG,CAAE,CAC7D,CAEA,OAAO,CACT,CAEI,EAAM,UACR,EAAQ,EAAS,EAAW,CAAQ,EAC3B,EAAM,OAAS,OACxB,EAAQ,EAAM,OAGhB,EAAmB,EAAM,WAAa,EAAM,SAC9C,CAEA,MAAM,IAAI,EAAA,iBAAiB,iEAAiE,CAC9F"}
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{OrbitConfigError as e}from"./errors.js";import{MIDDLEWARE_NAME as t,baseCoords as n,toRect as r,validateMiddlewareNames as i}from"./utils.js";import
|
|
1
|
+
import{OrbitConfigError as e}from"./errors.js";import{MIDDLEWARE_NAME as t,baseCoords as n,toRect as r,validateMiddlewareNames as i}from"./utils.js";import"./_dev.js";function a(e,t){return{floating:r(t.getBoundingClientRect()),reference:r(e.getBoundingClientRect())}}function o(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var s=8;function c(e,t,n){return Promise.resolve().then(()=>u(e,t,n))}function l(e,t,n){return new Promise((r,i)=>{requestAnimationFrame(()=>{try{r(u(e,t,n))}catch(e){i(e)}})})}function u(r,c,{boundary:l,containingBlock:u,middleware:d=[],padding:f,placement:p=`bottom`}={}){let m=d.filter(Boolean),h=m.map(e=>{let n=e[t];return typeof n==`string`?n:null});i(h);let g=p,_={},v=a(r,c);for(let e=0;e<s;e+=1){let e={...n(g,v.reference,v.floating),boundary:l,elements:{floating:c,reference:r},initialPlacement:p,middlewareData:_,padding:f,placement:g,rects:v},t;for(let n of m){let r=n(e);if(e=o(e,r),_=e.middlewareData,t=r?.reset,t)break}if(!t){let t={middlewareData:e.middlewareData,placement:e.placement,x:e.x,y:e.y};if(u){let e=u.getBoundingClientRect();return{...t,x:t.x-e.x,y:t.y-e.y}}return t}t.remeasure?v=a(r,c):t.rects!=null&&(v=t.rects),g=t.placement??e.placement}throw new e(`Middleware triggered too many resets in a single compute cycle.`)}export{u as computePosition,c as computePositionAsync,l as computePositionRaf,a as getRects};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n ComputePositionOptions,\n ComputePositionResult,\n Middleware,\n MiddlewareData,\n MiddlewareReset,\n MiddlewareResult,\n MiddlewareState,\n ReferenceElement,\n} from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { OrbitConfigError } from './errors';\nimport { baseCoords, MIDDLEWARE_NAME, toRect, validateMiddlewareNames } from './utils';\n\n// ── DOM helpers ────────────────────────────────────────────────────────────────────────────────\n\n/** Reads the bounding rects of the reference and floating elements from the DOM. */\nexport function getRects(reference: ReferenceElement, floating: HTMLElement): MiddlewareState['rects'] {\n return {\n floating: toRect(floating.getBoundingClientRect()),\n reference: toRect(reference.getBoundingClientRect()),\n };\n}\n\n// ── Internal state helpers ───────────────────────────────────────────────────────────\n\nfunction mergeState(state: MiddlewareState, result: MiddlewareResult | void): MiddlewareState {\n if (!result) return state;\n\n return {\n ...state,\n middlewareData: result.data\n ? (Object.assign(Object.create(null), state.middlewareData, result.data) as MiddlewareData)\n : state.middlewareData,\n placement: result.placement ?? state.placement,\n x: result.x ?? state.x,\n y: result.y ?? state.y,\n };\n}\n\n// ── Constants ─────────────────────────────────────────────────────────────────────────────────\n\n/** Maximum number of pipeline restarts allowed per `computePosition` call before throwing. */\nconst MAX_RESETS = 8;\n\n// ── Public API ────────────────────────────────────────────────────────────────────────────────\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **microtask** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful for async component lifecycles (e.g. `await nextTick()` in Vue/React) where the\n * synchronous `computePosition` would read stale DOM measurements because layout has not been\n * committed yet. Note: this defers to the microtask queue, not the next animation frame — if you\n * need post-layout measurements use `requestAnimationFrame` instead.\n *\n * @example\n * ```ts\n * const result = await computePositionAsync(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionAsync(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return Promise.resolve().then(() => computePosition(reference, floating, options));\n}\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **animation frame** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful when the layout has not yet committed (e.g. immediately after DOM insertion). Unlike\n * `computePositionAsync` which defers to the microtask queue, this waits for the next\n * `requestAnimationFrame` tick — guaranteeing post-layout DOM measurements.\n *\n * @example\n * ```ts\n * const result = await computePositionRaf(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionRaf(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return new Promise((resolve, reject) => {\n requestAnimationFrame(() => {\n try {\n resolve(computePosition(reference, floating, options));\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\n/**\n * Runs the middleware pipeline and returns the final position.\n *\n * Position is computed in viewport-relative coordinates assuming `position: fixed`.\n */\nexport function computePosition(\n reference: ReferenceElement,\n floating: HTMLElement,\n { boundary, containingBlock, middleware = [], padding, placement = 'bottom' }: ComputePositionOptions = {},\n): ComputePositionResult {\n const mws = middleware.filter(Boolean) as Middleware[];\n\n if (reference === floating) {\n warn('computePosition: reference and floating are the same element.');\n }\n\n const names = mws.map((mw) => {\n const tag = (mw as unknown as Record<symbol, unknown>)[MIDDLEWARE_NAME];\n\n return typeof tag === 'string' ? tag : null;\n });\n\n validateMiddlewareNames(names);\n\n let currentPlacement = placement;\n let middlewareData: MiddlewareData = {};\n let rects = getRects(reference, floating);\n\n devOnly(() => {\n if (rects.floating.width === 0 && rects.floating.height === 0) {\n warn('computePosition: floating element has zero dimensions — is it hidden or detached from the DOM?');\n }\n\n const pos = getComputedStyle(floating).position;\n\n if (pos !== 'fixed' && pos !== 'absolute') {\n warn(\n `computePosition: floating element has \\`position: ${pos}\\`. ` +\n 'Orbit computes viewport-relative coordinates and expects position: fixed ' +\n '(or absolute for scoped stacking contexts).',\n );\n }\n });\n\n for (let resets = 0; resets < MAX_RESETS; resets += 1) {\n let state: MiddlewareState = {\n ...baseCoords(currentPlacement, rects.reference, rects.floating),\n boundary,\n elements: { floating, reference },\n initialPlacement: placement,\n middlewareData,\n padding,\n placement: currentPlacement,\n rects,\n };\n\n let reset: MiddlewareReset | undefined;\n\n for (const mw of mws) {\n const result = mw(state);\n\n state = mergeState(state, result);\n middlewareData = state.middlewareData;\n reset = result?.reset;\n\n if (reset) break;\n }\n\n if (!reset) {\n const result: ComputePositionResult = {\n middlewareData: state.middlewareData,\n placement: state.placement,\n x: state.x,\n y: state.y,\n };\n\n if (containingBlock) {\n const cb = containingBlock.getBoundingClientRect();\n\n return { ...result, x: result.x - cb.x, y: result.y - cb.y };\n }\n\n return result;\n }\n\n if (reset.remeasure) {\n rects = getRects(reference, floating);\n } else if (reset.rects != null) {\n rects = reset.rects;\n }\n\n currentPlacement = reset.placement ?? state.placement;\n }\n\n throw new OrbitConfigError('Middleware triggered too many resets in a single compute cycle.');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n ComputePositionOptions,\n ComputePositionResult,\n Middleware,\n MiddlewareData,\n MiddlewareReset,\n MiddlewareResult,\n MiddlewareState,\n ReferenceElement,\n} from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { OrbitConfigError } from './errors';\nimport { baseCoords, MIDDLEWARE_NAME, toRect, validateMiddlewareNames } from './utils';\n\n// ── DOM helpers ────────────────────────────────────────────────────────────────────────────────\n\n/** Reads the bounding rects of the reference and floating elements from the DOM. */\nexport function getRects(reference: ReferenceElement, floating: HTMLElement): MiddlewareState['rects'] {\n return {\n floating: toRect(floating.getBoundingClientRect()),\n reference: toRect(reference.getBoundingClientRect()),\n };\n}\n\n// ── Internal state helpers ───────────────────────────────────────────────────────────\n\nfunction mergeState(state: MiddlewareState, result: MiddlewareResult | void): MiddlewareState {\n if (!result) return state;\n\n return {\n ...state,\n middlewareData: result.data\n ? (Object.assign(Object.create(null), state.middlewareData, result.data) as MiddlewareData)\n : state.middlewareData,\n placement: result.placement ?? state.placement,\n x: result.x ?? state.x,\n y: result.y ?? state.y,\n };\n}\n\n// ── Constants ─────────────────────────────────────────────────────────────────────────────────\n\n/** Maximum number of pipeline restarts allowed per `computePosition` call before throwing. */\nconst MAX_RESETS = 8;\n\n// ── Public API ────────────────────────────────────────────────────────────────────────────────\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **microtask** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful for async component lifecycles (e.g. `await nextTick()` in Vue/React) where the\n * synchronous `computePosition` would read stale DOM measurements because layout has not been\n * committed yet. Note: this defers to the microtask queue, not the next animation frame — if you\n * need post-layout measurements use `requestAnimationFrame` instead.\n *\n * @example\n * ```ts\n * const result = await computePositionAsync(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionAsync(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return Promise.resolve().then(() => computePosition(reference, floating, options));\n}\n\n/**\n * Deferred position computation. Runs `computePosition` in the next **animation frame** and\n * returns a `Promise<ComputePositionResult>`.\n *\n * Useful when the layout has not yet committed (e.g. immediately after DOM insertion). Unlike\n * `computePositionAsync` which defers to the microtask queue, this waits for the next\n * `requestAnimationFrame` tick — guaranteeing post-layout DOM measurements.\n *\n * @example\n * ```ts\n * const result = await computePositionRaf(reference, floating, { placement: 'top' });\n * floating.style.left = `${result.x}px`;\n * floating.style.top = `${result.y}px`;\n * ```\n */\nexport function computePositionRaf(\n reference: ReferenceElement,\n floating: HTMLElement,\n options?: ComputePositionOptions,\n): Promise<ComputePositionResult> {\n return new Promise((resolve, reject) => {\n requestAnimationFrame(() => {\n try {\n resolve(computePosition(reference, floating, options));\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\n/**\n * Runs the middleware pipeline and returns the final position.\n *\n * Position is computed in viewport-relative coordinates assuming `position: fixed`.\n */\nexport function computePosition(\n reference: ReferenceElement,\n floating: HTMLElement,\n { boundary, containingBlock, middleware = [], padding, placement = 'bottom' }: ComputePositionOptions = {},\n): ComputePositionResult {\n const mws = middleware.filter(Boolean) as Middleware[];\n\n if (reference === floating) {\n warn('computePosition: reference and floating are the same element.');\n }\n\n const names = mws.map((mw) => {\n const tag = (mw as unknown as Record<symbol, unknown>)[MIDDLEWARE_NAME];\n\n return typeof tag === 'string' ? tag : null;\n });\n\n validateMiddlewareNames(names);\n\n let currentPlacement = placement;\n let middlewareData: MiddlewareData = {};\n let rects = getRects(reference, floating);\n\n devOnly(() => {\n if (rects.floating.width === 0 && rects.floating.height === 0) {\n warn('computePosition: floating element has zero dimensions — is it hidden or detached from the DOM?');\n }\n\n const pos = getComputedStyle(floating).position;\n\n if (pos !== 'fixed' && pos !== 'absolute') {\n warn(\n `computePosition: floating element has \\`position: ${pos}\\`. ` +\n 'Orbit computes viewport-relative coordinates and expects position: fixed ' +\n '(or absolute for scoped stacking contexts).',\n );\n }\n });\n\n for (let resets = 0; resets < MAX_RESETS; resets += 1) {\n let state: MiddlewareState = {\n ...baseCoords(currentPlacement, rects.reference, rects.floating),\n boundary,\n elements: { floating, reference },\n initialPlacement: placement,\n middlewareData,\n padding,\n placement: currentPlacement,\n rects,\n };\n\n let reset: MiddlewareReset | undefined;\n\n for (const mw of mws) {\n const result = mw(state);\n\n state = mergeState(state, result);\n middlewareData = state.middlewareData;\n reset = result?.reset;\n\n if (reset) break;\n }\n\n if (!reset) {\n const result: ComputePositionResult = {\n middlewareData: state.middlewareData,\n placement: state.placement,\n x: state.x,\n y: state.y,\n };\n\n if (containingBlock) {\n const cb = containingBlock.getBoundingClientRect();\n\n return { ...result, x: result.x - cb.x, y: result.y - cb.y };\n }\n\n return result;\n }\n\n if (reset.remeasure) {\n rects = getRects(reference, floating);\n } else if (reset.rects != null) {\n rects = reset.rects;\n }\n\n currentPlacement = reset.placement ?? state.placement;\n }\n\n throw new OrbitConfigError('Middleware triggered too many resets in a single compute cycle.');\n}\n"],"mappings":"uKAkBA,SAAgB,EAAS,EAA6B,EAAiD,CACrG,MAAO,CACL,SAAU,EAAO,EAAS,sBAAsB,CAAC,EACjD,UAAW,EAAO,EAAU,sBAAsB,CAAC,CACrD,CACF,CAIA,SAAS,EAAW,EAAwB,EAAkD,CAG5F,OAFK,EAEE,CACL,GAAG,EACH,eAAgB,EAAO,KAClB,OAAO,OAAO,OAAO,OAAO,IAAI,EAAG,EAAM,eAAgB,EAAO,IAAI,EACrE,EAAM,eACV,UAAW,EAAO,WAAa,EAAM,UACrC,EAAG,EAAO,GAAK,EAAM,EACrB,EAAG,EAAO,GAAK,EAAM,CACvB,EAVoB,CAWtB,CAKA,IAAM,EAAa,EAoBnB,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAO,QAAQ,QAAQ,CAAC,CAAC,SAAW,EAAgB,EAAW,EAAU,CAAO,CAAC,CACnF,CAiBA,SAAgB,EACd,EACA,EACA,EACgC,CAChC,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,0BAA4B,CAC1B,GAAI,CACF,EAAQ,EAAgB,EAAW,EAAU,CAAO,CAAC,CACvD,OAAS,EAAK,CACZ,EAAO,CAAG,CACZ,CACF,CAAC,CACH,CAAC,CACH,CAOA,SAAgB,EACd,EACA,EACA,CAAE,WAAU,kBAAiB,aAAa,CAAC,EAAG,UAAS,YAAY,UAAqC,CAAC,EAClF,CACvB,IAAM,EAAM,EAAW,OAAO,OAAO,EAM/B,EAAQ,EAAI,IAAK,GAAO,CAC5B,IAAM,EAAO,EAA0C,GAEvD,OAAO,OAAO,GAAQ,SAAW,EAAM,IACzC,CAAC,EAED,EAAwB,CAAK,EAE7B,IAAI,EAAmB,EACnB,EAAiC,CAAC,EAClC,EAAQ,EAAS,EAAW,CAAQ,EAkBxC,IAAK,IAAI,EAAS,EAAG,EAAS,EAAY,GAAU,EAAG,CACrD,IAAI,EAAyB,CAC3B,GAAG,EAAW,EAAkB,EAAM,UAAW,EAAM,QAAQ,EAC/D,WACA,SAAU,CAAE,WAAU,WAAU,EAChC,iBAAkB,EAClB,iBACA,UACA,UAAW,EACX,OACF,EAEI,EAEJ,IAAK,IAAM,KAAM,EAAK,CACpB,IAAM,EAAS,EAAG,CAAK,EAMvB,GAJA,EAAQ,EAAW,EAAO,CAAM,EAChC,EAAiB,EAAM,eACvB,EAAQ,GAAQ,MAEZ,EAAO,KACb,CAEA,GAAI,CAAC,EAAO,CACV,IAAM,EAAgC,CACpC,eAAgB,EAAM,eACtB,UAAW,EAAM,UACjB,EAAG,EAAM,EACT,EAAG,EAAM,CACX,EAEA,GAAI,EAAiB,CACnB,IAAM,EAAK,EAAgB,sBAAsB,EAEjD,MAAO,CAAE,GAAG,EAAQ,EAAG,EAAO,EAAI,EAAG,EAAG,EAAG,EAAO,EAAI,EAAG,CAAE,CAC7D,CAEA,OAAO,CACT,CAEI,EAAM,UACR,EAAQ,EAAS,EAAW,CAAQ,EAC3B,EAAM,OAAS,OACxB,EAAQ,EAAM,OAGhB,EAAmB,EAAM,WAAa,EAAM,SAC9C,CAEA,MAAM,IAAI,EAAiB,iEAAiE,CAC9F"}
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all orbit errors. Use `instanceof OrbitError` to catch any orbit-originated error. */\nexport class OrbitError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is OrbitError {\n return err instanceof OrbitError;\n }\n}\n\n/** Thrown when a middleware pipeline is configured incorrectly. */\nexport class OrbitConfigError extends OrbitError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all orbit errors. Use `instanceof OrbitError` to catch any orbit-originated error. */\nexport class OrbitError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is OrbitError {\n return err instanceof OrbitError;\n }\n}\n\n/** Thrown when a middleware pipeline is configured incorrectly. */\nexport class OrbitConfigError extends OrbitError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAsC,CAAW,CAAC"}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all orbit errors. Use `instanceof OrbitError` to catch any orbit-originated error. */\nexport class OrbitError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is OrbitError {\n return err instanceof OrbitError;\n }\n}\n\n/** Thrown when a middleware pipeline is configured incorrectly. */\nexport class OrbitConfigError extends OrbitError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all orbit errors. Use `instanceof OrbitError` to catch any orbit-originated error. */\nexport class OrbitError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is OrbitError {\n return err instanceof OrbitError;\n }\n}\n\n/** Thrown when a middleware pipeline is configured incorrectly. */\nexport class OrbitConfigError extends OrbitError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAAsC,CAAW,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils.cjs");let t=require("@vielzeug/arsenal");function n({element:n,padding:r=0}){function i(i){let a=e.getSide(i.placement),o=e.toSideObject(r),s=e.toRect(n.getBoundingClientRect());if(a===`top`||a===`bottom`){let e=i.rects.reference.x+i.rects.reference.width/2-i.x-s.width/2,n=o.left,r=
|
|
1
|
+
const e=require("../utils.cjs");let t=require("@vielzeug/arsenal/math");function n({element:n,padding:r=0}){function i(i){let a=e.getSide(i.placement),o=e.toSideObject(r),s=e.toRect(n.getBoundingClientRect());if(a===`top`||a===`bottom`){let e=i.rects.reference.x+i.rects.reference.width/2-i.x-s.width/2,n=o.left,r=Math.max(n,i.rects.floating.width-s.width-o.right),a=(0,t.clamp)(e,n,r);return{data:{arrow:{centerOffset:e-a,constrained:a!==e,x:a}}}}let c=i.rects.reference.y+i.rects.reference.height/2-i.y-s.height/2,l=o.top,u=Math.max(l,i.rects.floating.height-s.height-o.bottom),d=(0,t.clamp)(c,l,u);return{data:{arrow:{centerOffset:c-d,constrained:d!==c,y:d}}}}return e.tagMiddleware(i,`arrow`)}exports.arrow=n;
|
|
2
2
|
//# sourceMappingURL=arrow.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"arrow.cjs","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"wEA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAAwD,CACjG,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,CAAO,EAC5B,EAAY,EAAA,OAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,GAAA,EAAI,EAAA,MAAA,CAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,GAAA,EAAI,EAAA,MAAA,CAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,EAAA,cAA0D,EAAiB,OAAO,CAC3F"}
|
package/dist/middleware/arrow.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{clamp as e,getSide as t,tagMiddleware as n,toRect as r,toSideObject as i}from"../utils.js";function a({element:a,padding:o=0}){function s(n){let s=t(n.placement),c=i(o),l=r(a.getBoundingClientRect());if(s===`top`||s===`bottom`){let t=n.rects.reference.x+n.rects.reference.width/2-n.x-l.width/2,r=c.left,i=
|
|
1
|
+
import{clamp as e,getSide as t,tagMiddleware as n,toRect as r,toSideObject as i}from"../utils.js";function a({element:a,padding:o=0}){function s(n){let s=t(n.placement),c=i(o),l=r(a.getBoundingClientRect());if(s===`top`||s===`bottom`){let t=n.rects.reference.x+n.rects.reference.width/2-n.x-l.width/2,r=c.left,i=Math.max(r,n.rects.floating.width-l.width-c.right),a=e(t,r,i);return{data:{arrow:{centerOffset:t-a,constrained:a!==t,x:a}}}}let u=n.rects.reference.y+n.rects.reference.height/2-n.y-l.height/2,d=c.top,f=Math.max(d,n.rects.floating.height-l.height-c.bottom),p=e(u,d,f);return{data:{arrow:{centerOffset:u-p,constrained:p!==u,y:p}}}}return n(s,`arrow`)}export{a as arrow};
|
|
2
2
|
//# sourceMappingURL=arrow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.js","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"kGA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAAwD,CACjG,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,CAAO,EAC5B,EAAY,EAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,
|
|
1
|
+
{"version":3,"file":"arrow.js","names":[],"sources":["../../src/middleware/arrow.ts"],"sourcesContent":["import type { ArrowData, Middleware, Padding, TypedMiddleware } from '../types';\n\nimport { clamp, getSide, tagMiddleware, toRect, toSideObject } from '../utils';\n\nexport interface ArrowOptions {\n /** The arrow DOM element. Must be a child of the floating element. */\n element: HTMLElement;\n /** Padding to keep the arrow from the floating element's corners. */\n padding?: Padding;\n}\n\n/**\n * Positions an arrow element inside the floating element, pointed toward the reference.\n * Writes `{ x?, y?, centerOffset }` to `middlewareData.arrow`.\n *\n * Must come **after** flip(), shift(), and autoPlacement() in the middleware pipeline.\n *\n * @example\n * ```ts\n * const result = computePosition(ref, floating, {\n * middleware: [offset(8), flip(), shift(), arrow({ element: arrowEl })],\n * });\n * const { x, y } = result.middlewareData.arrow!;\n * arrowEl.style.left = x != null ? `${x}px` : '';\n * arrowEl.style.top = y != null ? `${y}px` : '';\n * ```\n */\nexport function arrow({ element, padding = 0 }: ArrowOptions): TypedMiddleware<'arrow', ArrowData> {\n function arrowMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const inset = toSideObject(padding);\n const arrowRect = toRect(element.getBoundingClientRect());\n\n if (side === 'top' || side === 'bottom') {\n const idealX = state.rects.reference.x + state.rects.reference.width / 2 - state.x - arrowRect.width / 2;\n const minX = inset.left;\n const maxX = Math.max(minX, state.rects.floating.width - arrowRect.width - inset.right);\n const x = clamp(idealX, minX, maxX);\n\n return { data: { arrow: { centerOffset: idealX - x, constrained: x !== idealX, x } } };\n }\n\n const idealY = state.rects.reference.y + state.rects.reference.height / 2 - state.y - arrowRect.height / 2;\n const minY = inset.top;\n const maxY = Math.max(minY, state.rects.floating.height - arrowRect.height - inset.bottom);\n const y = clamp(idealY, minY, maxY);\n\n return { data: { arrow: { centerOffset: idealY - y, constrained: y !== idealY, y } } };\n }\n\n return tagMiddleware<'arrow', ArrowData, typeof arrowMiddleware>(arrowMiddleware, 'arrow');\n}\n"],"mappings":"kGA2BA,SAAgB,EAAM,CAAE,UAAS,UAAU,GAAwD,CACjG,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,CAAO,EAC5B,EAAY,EAAO,EAAQ,sBAAsB,CAAC,EAExD,GAAI,IAAS,OAAS,IAAS,SAAU,CACvC,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,MAAQ,EAAI,EAAM,EAAI,EAAU,MAAQ,EACjG,EAAO,EAAM,KACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,MAAQ,EAAU,MAAQ,EAAM,KAAK,EAChF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,IAAM,EAAS,EAAM,MAAM,UAAU,EAAI,EAAM,MAAM,UAAU,OAAS,EAAI,EAAM,EAAI,EAAU,OAAS,EACnG,EAAO,EAAM,IACb,EAAO,KAAK,IAAI,EAAM,EAAM,MAAM,SAAS,OAAS,EAAU,OAAS,EAAM,MAAM,EACnF,EAAI,EAAM,EAAQ,EAAM,CAAI,EAElC,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,aAAc,EAAS,EAAG,YAAa,IAAM,EAAQ,GAAE,CAAE,CAAE,CACvF,CAEA,OAAO,EAA0D,EAAiB,OAAO,CAC3F"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils.cjs")
|
|
1
|
+
const e=require("../utils.cjs");require("../_dev.cjs");const t=require("../overflow.cjs");var n=[`top`,`right`,`bottom`,`left`];function r(e){return e===void 0?n:e===null?n.flatMap(e=>[e,`${e}-start`,`${e}-end`]):n.map(t=>`${t}-${e}`)}function i(n={}){return e.tagMiddleware(function(e){let{boundary:i,padding:a}=t.resolveBoundary(n,e),o=n.allowedPlacements??r(n.alignment);o.length;let s=e.placement,c=1/0,l=-1/0;for(let r of o){let o=t.getPlacementOverflow(e,r,n),u=t.totalOverflow(o),d=t.getAvailableSpace(e,r,i,a);(u<c||u===c&&d>l)&&(s=r,c=u,l=d)}if(s!==e.placement)return{reset:{placement:s}}},`autoPlacement`)}exports.autoPlacement=i;
|
|
2
2
|
//# sourceMappingURL=auto-placement.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-placement.cjs","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-placement.cjs","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"0FAuBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,EAAA,cAAc,SAAiC,EAA0D,CAC9G,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAA,qBAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAA,cAAc,CAAQ,EACtC,EAAiB,EAAA,kBAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,EAAG,eAAe,CACpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{tagMiddleware as e}from"../utils.js";import
|
|
1
|
+
import{tagMiddleware as e}from"../utils.js";import"../_dev.js";import{getAvailableSpace as t,getPlacementOverflow as n,resolveBoundary as r,totalOverflow as i}from"../overflow.js";var a=[`top`,`right`,`bottom`,`left`];function o(e){return e===void 0?a:e===null?a.flatMap(e=>[e,`${e}-start`,`${e}-end`]):a.map(t=>`${t}-${e}`)}function s(a={}){return e(function(e){let{boundary:s,padding:c}=r(a,e),l=a.allowedPlacements??o(a.alignment);l.length;let u=e.placement,d=1/0,f=-1/0;for(let r of l){let o=n(e,r,a),l=i(o),p=t(e,r,s,c);(l<d||l===d&&p>f)&&(u=r,d=l,f=p)}if(u!==e.placement)return{reset:{placement:u}}},`autoPlacement`)}export{s as autoPlacement};
|
|
2
2
|
//# sourceMappingURL=auto-placement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nimport { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport { tagMiddleware } from '../utils';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\n /**\n * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\n /**\n * Constrains auto-placement to variants with the given alignment.\n *\n * - `'start'` — evaluates only `top-start`, `right-start`, `bottom-start`, `left-start`.\n * - `'end'` — evaluates only `top-end`, `right-end`, `bottom-end`, `left-end`.\n * - `null` — evaluates all 12 variants (4 cardinal + 4 start + 4 end).\n * - omitted (default) — evaluates the 4 cardinal sides only.\n */\n alignment?: Alignment | null;\n}\n\nconst SIDES: Side[] = ['top', 'right', 'bottom', 'left'];\n\nfunction getDefaultPlacements(alignment?: Alignment | null): Placement[] {\n if (alignment === undefined) return SIDES;\n\n if (alignment === null) {\n return SIDES.flatMap((side) => [side, `${side}-start`, `${side}-end`] as Placement[]);\n }\n\n return SIDES.map((side) => `${side}-${alignment}` as Placement);\n}\n\n/**\n * Automatically selects the placement with the most available space and least overflow.\n * Evaluates all allowed placements and picks the optimal one.\n *\n * Use the `alignment` option to restrict evaluation to aligned variants (e.g. `'start'`)\n * when you want to preserve a consistent alignment across all candidate sides.\n *\n * @see {@link flip} for simple opposite-side flipping.\n */\nexport function autoPlacement(options: AutoPlacementOptions = {}): Middleware {\n return tagMiddleware(function autoPlacementMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const placements = options.allowedPlacements ?? getDefaultPlacements(options.alignment);\n\n if (placements.length === 0) {\n warn('autoPlacement: allowedPlacements is empty — no placement will be evaluated.');\n }\n\n let bestPlacement = state.placement;\n let bestOverflow = Number.POSITIVE_INFINITY;\n let bestSpace = Number.NEGATIVE_INFINITY;\n\n for (const candidate of placements) {\n const overflow = getPlacementOverflow(state, candidate, options);\n const overflowScore = totalOverflow(overflow);\n const availableSpace = getAvailableSpace(state, candidate, boundary, padding);\n\n if (overflowScore < bestOverflow || (overflowScore === bestOverflow && availableSpace > bestSpace)) {\n bestPlacement = candidate;\n bestOverflow = overflowScore;\n bestSpace = availableSpace;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return { reset: { placement: bestPlacement } };\n }\n }, 'autoPlacement');\n}\n"],"mappings":"oLAuBA,IAAM,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAAS,EAAqB,EAA2C,CAOvE,OANI,IAAc,IAAA,GAAkB,EAEhC,IAAc,KACT,EAAM,QAAS,GAAS,CAAC,EAAM,GAAG,EAAK,QAAS,GAAG,EAAK,KAAK,CAAgB,EAG/E,EAAM,IAAK,GAAS,GAAG,EAAK,GAAG,GAAwB,CAChE,CAWA,SAAgB,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,EAAc,SAAiC,EAA0D,CAC9G,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAa,EAAQ,mBAAqB,EAAqB,EAAQ,SAAS,EAElF,EAAW,OAIf,IAAI,EAAgB,EAAM,UACtB,EAAe,IACf,EAAY,KAEhB,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAW,EAAqB,EAAO,EAAW,CAAO,EACzD,EAAgB,EAAc,CAAQ,EACtC,EAAiB,EAAkB,EAAO,EAAW,EAAU,CAAO,GAExE,EAAgB,GAAiB,IAAkB,GAAgB,EAAiB,KACtF,EAAgB,EAChB,EAAe,EACf,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAW,CAAc,CAAE,CAEjD,EAAG,eAAe,CACpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils.cjs"),t=require("../overflow.cjs");let n=require("@vielzeug/arsenal");function r(t={}){return(r,i)=>{let{placement:a,rects:o,x:s,y:c}=r,l=e.getSide(a),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(r):t.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[r,a]=e<=t?[e,t]:[t,e],c=(0,n.clamp)(s+i.crossAxis,r,a);return{...i,crossAxis:c-s}}let f=o.reference.y-d,p=o.reference.y+o.reference.height+d-o.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=(0,n.clamp)(c+i.crossAxis,m,h);return{...i,crossAxis:g-c}}}function i(n={}){let{crossAxis:r=!0,limiter:i,mainAxis:a=!1}=n;function o(o){let s=t.detectOverflow(o,n),c=e.getSide(o.placement),l=c===`top`||c===`bottom`,u=Math.max(s.left,0)-Math.max(s.right,0),d=Math.max(s.top,0)-Math.max(s.bottom,0),f=l?r:a,p=l?a:r,m=f?u:0,h=p?d:0;if(i){let e=i(o,{crossAxis:l?m:h,mainAxis:l?h:m});m=l?e.crossAxis:e.mainAxis,h=l?e.mainAxis:e.crossAxis}return{data:{shift:{x:m,y:h}},x:o.x+m,y:o.y+h}}return e.tagMiddleware(o,`shift`)}exports.limitShift=r,exports.shift=i;
|
|
1
|
+
const e=require("../utils.cjs"),t=require("../overflow.cjs");let n=require("@vielzeug/arsenal/math");function r(t={}){return(r,i)=>{let{placement:a,rects:o,x:s,y:c}=r,l=e.getSide(a),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(r):t.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[r,a]=e<=t?[e,t]:[t,e],c=(0,n.clamp)(s+i.crossAxis,r,a);return{...i,crossAxis:c-s}}let f=o.reference.y-d,p=o.reference.y+o.reference.height+d-o.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=(0,n.clamp)(c+i.crossAxis,m,h);return{...i,crossAxis:g-c}}}function i(n={}){let{crossAxis:r=!0,limiter:i,mainAxis:a=!1}=n;function o(o){let s=t.detectOverflow(o,n),c=e.getSide(o.placement),l=c===`top`||c===`bottom`,u=Math.max(s.left,0)-Math.max(s.right,0),d=Math.max(s.top,0)-Math.max(s.bottom,0),f=l?r:a,p=l?a:r,m=f?u:0,h=p?d:0;if(i){let e=i(o,{crossAxis:l?m:h,mainAxis:l?h:m});m=l?e.crossAxis:e.mainAxis,h=l?e.mainAxis:e.crossAxis}return{data:{shift:{x:m,y:h}},x:o.x+m,y:o.y+h}}return e.tagMiddleware(o,`shift`)}exports.limitShift=r,exports.shift=i;
|
|
2
2
|
//# sourceMappingURL=shift.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import type { DetectOverflowOptions, Middleware, MiddlewareState, ShiftData, TypedMiddleware } from '../types';\n\nimport { detectOverflow } from '../overflow';\nimport { clamp, getSide, tagMiddleware } from '../utils';\n\n/**\n * A limiter function passed to `shift()` that constrains the maximum allowed drift.\n * Receives the current middleware state and the proposed shift correction (as deltas),\n * and returns the clamped correction.\n */\nexport type ShiftLimiter = (\n state: MiddlewareState,\n correction: { crossAxis: number; mainAxis: number },\n) => { crossAxis: number; mainAxis: number };\n\nexport interface LimitShiftOptions {\n /**\n * Extra pixels of allowed drift past the reference's cross-axis extent before clamping kicks in.\n * Can be a static number or a function returning a number based on current state.\n * Default: `0`.\n */\n offset?: number | ((state: MiddlewareState) => number);\n}\n\n/**\n * Returns a {@link ShiftLimiter} that constrains `shift()` so the floating element\n * stays visually connected to the reference along the cross axis.\n *\n * Without a limiter, `shift()` will push the float as far as needed to fit in the boundary —\n * potentially sliding it far away from the reference. `limitShift` clamps the drift so the\n * float stays within the reference's cross-axis extent (± `offset` pixels).\n *\n * @example\n * ```ts\n * // Tooltip stays above the button even when viewport clips it.\n * shift({ padding: 6, limiter: limitShift() })\n *\n * // Allow up to 10px of drift beyond the reference's edges.\n * shift({ padding: 6, limiter: limitShift({ offset: 10 }) })\n * ```\n */\nexport function limitShift(options: LimitShiftOptions = {}): ShiftLimiter {\n return (state, correction) => {\n const { placement, rects, x, y } = state;\n const side = getSide(placement);\n const isVertical = side === 'top' || side === 'bottom';\n const extra = typeof options.offset === 'function' ? options.offset(state) : (options.offset ?? 0);\n\n if (isVertical) {\n // Cross axis is x. Clamp float.left to [ref.left-extra, ref.right+extra-float.width].\n const lo = rects.reference.x - extra;\n const hi = rects.reference.x + rects.reference.width + extra - rects.floating.width;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(x + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - x };\n }\n\n // Cross axis is y. Clamp float.top to [ref.top-extra, ref.bottom+extra-float.height].\n const lo = rects.reference.y - extra;\n const hi = rects.reference.y + rects.reference.height + extra - rects.floating.height;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(y + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - y };\n };\n}\n\nexport interface ShiftOptions extends DetectOverflowOptions {\n /**\n * Whether to shift along the main axis (the axis away from the reference).\n * Default: `false` — main-axis overflow is better handled by `flip`.\n */\n mainAxis?: boolean;\n /**\n * Whether to shift along the cross axis (perpendicular to the reference direction).\n * Default: `true`.\n */\n crossAxis?: boolean;\n /**\n * Constrains how far `shift()` can move the floating element along the cross axis.\n * Pass `limitShift()` to keep the float within the reference's extent.\n */\n limiter?: ShiftLimiter;\n}\n\n/**\n * Shifts the floating element along the cross axis to keep it inside the boundary.\n *\n * By default only the cross axis is corrected. Enable `mainAxis` to also shift\n * along the main axis (useful when `flip` is not in the pipeline).\n *\n * | Placement | Cross axis | Main axis |\n * |------------------|------------|-----------|\n * | `top` / `bottom` | horizontal | vertical |\n * | `left` / `right` | vertical | horizontal|\n */\nexport function shift(options: ShiftOptions = {}): TypedMiddleware<'shift', ShiftData> {\n const { crossAxis = true, limiter, mainAxis = false } = options;\n\n function shiftMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const overflow = detectOverflow(state, options);\n const side = getSide(state.placement);\n const isVertical = side === 'top' || side === 'bottom';\n\n const xCorrection = Math.max(overflow.left, 0) - Math.max(overflow.right, 0);\n const yCorrection = Math.max(overflow.top, 0) - Math.max(overflow.bottom, 0);\n const applyX = isVertical ? crossAxis : mainAxis;\n const applyY = isVertical ? mainAxis : crossAxis;\n\n let dx = applyX ? xCorrection : 0;\n let dy = applyY ? yCorrection : 0;\n\n if (limiter) {\n const limited = limiter(state, {\n crossAxis: isVertical ? dx : dy,\n mainAxis: isVertical ? dy : dx,\n });\n\n dx = isVertical ? limited.crossAxis : limited.mainAxis;\n dy = isVertical ? limited.mainAxis : limited.crossAxis;\n }\n\n return { data: { shift: { x: dx, y: dy } }, x: state.x + dx, y: state.y + dy };\n }\n\n return tagMiddleware<'shift', ShiftData, typeof shiftMiddleware>(shiftMiddleware, 'shift');\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import type { DetectOverflowOptions, Middleware, MiddlewareState, ShiftData, TypedMiddleware } from '../types';\n\nimport { detectOverflow } from '../overflow';\nimport { clamp, getSide, tagMiddleware } from '../utils';\n\n/**\n * A limiter function passed to `shift()` that constrains the maximum allowed drift.\n * Receives the current middleware state and the proposed shift correction (as deltas),\n * and returns the clamped correction.\n */\nexport type ShiftLimiter = (\n state: MiddlewareState,\n correction: { crossAxis: number; mainAxis: number },\n) => { crossAxis: number; mainAxis: number };\n\nexport interface LimitShiftOptions {\n /**\n * Extra pixels of allowed drift past the reference's cross-axis extent before clamping kicks in.\n * Can be a static number or a function returning a number based on current state.\n * Default: `0`.\n */\n offset?: number | ((state: MiddlewareState) => number);\n}\n\n/**\n * Returns a {@link ShiftLimiter} that constrains `shift()` so the floating element\n * stays visually connected to the reference along the cross axis.\n *\n * Without a limiter, `shift()` will push the float as far as needed to fit in the boundary —\n * potentially sliding it far away from the reference. `limitShift` clamps the drift so the\n * float stays within the reference's cross-axis extent (± `offset` pixels).\n *\n * @example\n * ```ts\n * // Tooltip stays above the button even when viewport clips it.\n * shift({ padding: 6, limiter: limitShift() })\n *\n * // Allow up to 10px of drift beyond the reference's edges.\n * shift({ padding: 6, limiter: limitShift({ offset: 10 }) })\n * ```\n */\nexport function limitShift(options: LimitShiftOptions = {}): ShiftLimiter {\n return (state, correction) => {\n const { placement, rects, x, y } = state;\n const side = getSide(placement);\n const isVertical = side === 'top' || side === 'bottom';\n const extra = typeof options.offset === 'function' ? options.offset(state) : (options.offset ?? 0);\n\n if (isVertical) {\n // Cross axis is x. Clamp float.left to [ref.left-extra, ref.right+extra-float.width].\n const lo = rects.reference.x - extra;\n const hi = rects.reference.x + rects.reference.width + extra - rects.floating.width;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(x + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - x };\n }\n\n // Cross axis is y. Clamp float.top to [ref.top-extra, ref.bottom+extra-float.height].\n const lo = rects.reference.y - extra;\n const hi = rects.reference.y + rects.reference.height + extra - rects.floating.height;\n const [min, max] = lo <= hi ? [lo, hi] : [hi, lo];\n const clamped = clamp(y + correction.crossAxis, min, max);\n\n return { ...correction, crossAxis: clamped - y };\n };\n}\n\nexport interface ShiftOptions extends DetectOverflowOptions {\n /**\n * Whether to shift along the main axis (the axis away from the reference).\n * Default: `false` — main-axis overflow is better handled by `flip`.\n */\n mainAxis?: boolean;\n /**\n * Whether to shift along the cross axis (perpendicular to the reference direction).\n * Default: `true`.\n */\n crossAxis?: boolean;\n /**\n * Constrains how far `shift()` can move the floating element along the cross axis.\n * Pass `limitShift()` to keep the float within the reference's extent.\n */\n limiter?: ShiftLimiter;\n}\n\n/**\n * Shifts the floating element along the cross axis to keep it inside the boundary.\n *\n * By default only the cross axis is corrected. Enable `mainAxis` to also shift\n * along the main axis (useful when `flip` is not in the pipeline).\n *\n * | Placement | Cross axis | Main axis |\n * |------------------|------------|-----------|\n * | `top` / `bottom` | horizontal | vertical |\n * | `left` / `right` | vertical | horizontal|\n */\nexport function shift(options: ShiftOptions = {}): TypedMiddleware<'shift', ShiftData> {\n const { crossAxis = true, limiter, mainAxis = false } = options;\n\n function shiftMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const overflow = detectOverflow(state, options);\n const side = getSide(state.placement);\n const isVertical = side === 'top' || side === 'bottom';\n\n const xCorrection = Math.max(overflow.left, 0) - Math.max(overflow.right, 0);\n const yCorrection = Math.max(overflow.top, 0) - Math.max(overflow.bottom, 0);\n const applyX = isVertical ? crossAxis : mainAxis;\n const applyY = isVertical ? mainAxis : crossAxis;\n\n let dx = applyX ? xCorrection : 0;\n let dy = applyY ? yCorrection : 0;\n\n if (limiter) {\n const limited = limiter(state, {\n crossAxis: isVertical ? dx : dy,\n mainAxis: isVertical ? dy : dx,\n });\n\n dx = isVertical ? limited.crossAxis : limited.mainAxis;\n dy = isVertical ? limited.mainAxis : limited.crossAxis;\n }\n\n return { data: { shift: { x: dx, y: dy } }, x: state.x + dx, y: state.y + dy };\n }\n\n return tagMiddleware<'shift', ShiftData, typeof shiftMiddleware>(shiftMiddleware, 'shift');\n}\n"],"mappings":"qGAyCA,SAAgB,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAM,EAC7B,EAAO,EAAA,QAAQ,CAAS,EACxB,EAAa,IAAS,OAAS,IAAS,SACxC,EAAQ,OAAO,EAAQ,QAAW,WAAa,EAAQ,OAAO,CAAK,EAAK,EAAQ,QAAU,EAEhG,GAAI,EAAY,CAEd,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,MAAQ,EAAQ,EAAM,SAAS,MACxE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,GAAA,EAAU,EAAA,MAAA,CAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CAGA,IAAM,EAAK,EAAM,UAAU,EAAI,EACzB,EAAK,EAAM,UAAU,EAAI,EAAM,UAAU,OAAS,EAAQ,EAAM,SAAS,OACzE,CAAC,EAAK,GAAO,GAAM,EAAK,CAAC,EAAI,CAAE,EAAI,CAAC,EAAI,CAAE,EAC1C,GAAA,EAAU,EAAA,MAAA,CAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CACF,CA+BA,SAAgB,EAAM,EAAwB,CAAC,EAAwC,CACrF,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAU,EAExD,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAW,EAAA,eAAe,EAAO,CAAO,EACxC,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAa,IAAS,OAAS,IAAS,SAExC,EAAc,KAAK,IAAI,EAAS,KAAM,CAAC,EAAI,KAAK,IAAI,EAAS,MAAO,CAAC,EACrE,EAAc,KAAK,IAAI,EAAS,IAAK,CAAC,EAAI,KAAK,IAAI,EAAS,OAAQ,CAAC,EACrE,EAAS,EAAa,EAAY,EAClC,EAAS,EAAa,EAAW,EAEnC,EAAK,EAAS,EAAc,EAC5B,EAAK,EAAS,EAAc,EAEhC,GAAI,EAAS,CACX,IAAM,EAAU,EAAQ,EAAO,CAC7B,UAAW,EAAa,EAAK,EAC7B,SAAU,EAAa,EAAK,CAC9B,CAAC,EAED,EAAK,EAAa,EAAQ,UAAY,EAAQ,SAC9C,EAAK,EAAa,EAAQ,SAAW,EAAQ,SAC/C,CAEA,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,EAAG,EAAI,EAAG,CAAG,CAAE,EAAG,EAAG,EAAM,EAAI,EAAI,EAAG,EAAM,EAAI,CAAG,CAC/E,CAEA,OAAO,EAAA,cAA0D,EAAiB,OAAO,CAC3F"}
|
package/dist/orbit.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@vielzeug/arsenal");var t=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},n=class extends t{},r=!globalThis.__ORBIT_PROD__;function i(e){r&&console.warn(`[@vielzeug/orbit] ${e}`)}function a(e){r&&e()}var o={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function s(e){return e.split(`-`)[0]}function c(e){return e.split(`-`)[1]??null}function l(e,t){return t?`${e}-${t}`:e}function u({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function d(e=0){return typeof e==`number`?{bottom:e,left:e,right:e,top:e}:{bottom:e.bottom??0,left:e.left??0,right:e.right??0,top:e.top??0}}function f(e){return typeof Element<`u`&&e instanceof Element}function p(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}var m=[[`arrow`,`flip`],[`arrow`,`shift`],[`arrow`,`autoPlacement`],[`flip`,`inline`],[`shift`,`inline`],[`autoPlacement`,`inline`],[`size`,`flip`],[`size`,`autoPlacement`]];function h(e){for(let[t,r]of m){let i=e.indexOf(t),a=e.indexOf(r);if(i!==-1&&a!==-1&&i<a)throw new n(`"${t}" must come after "${r}" in the middleware pipeline. Recommended order: inline → offset → flip/autoPlacement → shift → size → arrow.`)}if(e.includes(`flip`)&&e.includes(`autoPlacement`))throw new n(`use either flip() or autoPlacement() in the middleware pipeline, not both.`)}var g=Symbol.for(`@vielzeug/orbit/name`);function _(e,t){return e[g]=t,e}function v(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function y(e,t,n){let r=s(e),i=c(e);switch(r){case`bottom`:return{x:v(i,t.x,t.width,n.width),y:t.y+t.height};case`left`:return{x:t.x-n.width,y:v(i,t.y,t.height,n.height)};case`right`:return{x:t.x+t.width,y:v(i,t.y,t.height,n.height)};case`top`:return{x:v(i,t.x,t.width,n.width),y:t.y-n.height}}}function b(e,t){return{floating:u(t.getBoundingClientRect()),reference:u(e.getBoundingClientRect())}}function x(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var S=8;function C(e,t,n){return Promise.resolve().then(()=>T(e,t,n))}function w(e,t,n){return new Promise((r,i)=>{requestAnimationFrame(()=>{try{r(T(e,t,n))}catch(e){i(e)}})})}function T(e,t,{boundary:r,containingBlock:o,middleware:s=[],padding:c,placement:l=`bottom`}={}){let u=s.filter(Boolean);e===t&&i(`computePosition: reference and floating are the same element.`),h(u.map(e=>{let t=e[g];return typeof t==`string`?t:null}));let d=l,f={},p=b(e,t);a(()=>{p.floating.width===0&&p.floating.height===0&&i(`computePosition: floating element has zero dimensions — is it hidden or detached from the DOM?`);let e=getComputedStyle(t).position;e!==`fixed`&&e!==`absolute`&&i(`computePosition: floating element has \`position: ${e}\`. Orbit computes viewport-relative coordinates and expects position: fixed (or absolute for scoped stacking contexts).`)});for(let n=0;n<S;n+=1){let n={...y(d,p.reference,p.floating),boundary:r,elements:{floating:t,reference:e},initialPlacement:l,middlewareData:f,padding:c,placement:d,rects:p},i;for(let e of u){let t=e(n);if(n=x(n,t),f=n.middlewareData,i=t?.reset,i)break}if(!i){let e={middlewareData:n.middlewareData,placement:n.placement,x:n.x,y:n.y};if(o){let t=o.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}i.remeasure?p=b(e,t):i.rects!=null&&(p=i.rects),d=i.placement??n.placement}throw new n(`Middleware triggered too many resets in a single compute cycle.`)}function E(){let e=window.visualViewport;return e?{height:e.height,width:e.width,x:e.offsetLeft,y:e.offsetTop}:{height:window.innerHeight,width:window.innerWidth,x:0,y:0}}function ee(e){if(!e)return E();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var D=/(hidden|clip|scroll|auto|overlay)/;function O(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{height:Math.max(0,a-r),width:Math.max(0,i-n),x:n,y:r}}function k(e){let t=p(e),n=E();for(;t;){let e=getComputedStyle(t);if(D.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=O(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=p(t)}return n}function A(e,t){return{boundary:ee(e.boundary??t.boundary),padding:d(e.padding??t.padding)}}function j(e){return{...e.rects.floating,x:e.x,y:e.y}}function M(e,t,n){return{bottom:e.y+e.height-(t.y+t.height-n.bottom),left:t.x+n.left-e.x,right:e.x+e.width-(t.x+t.width-n.right),top:t.y+n.top-e.y}}function N(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function P(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function F(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function I(e,t,n,r){let i=e.rects.reference;switch(s(t)){case`bottom`:return n.y+n.height-r.bottom-(i.y+i.height);case`left`:return i.x-(n.x+r.left);case`right`:return n.x+n.width-r.right-(i.x+i.width);case`top`:return i.y-(n.y+r.top)}}function L(e,t,n={}){let{x:r,y:i}=y(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=A(n,e);return M({...e.rects.floating,x:r,y:i},a,o)}function R(e,t={}){let{boundary:n,padding:r}=A(t,e);return M(j(e),n,r)}var z=[`transform`,`perspective`,`filter`],B=[`layout`,`paint`,`strict`,`content`];function V(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&z.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&B.some(t=>e.contain.includes(t))}function H(e){let t=p(e);for(;t;){if(V(getComputedStyle(t)))return t;t=p(t)}return null}function U(e){let t=[],n=p(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=p(n)}return t}function W(t,n,r,{animationFrame:i=!1,observeAncestors:a=!0,observeFloating:o=!0,observeVisualViewport:s=!0,pauseWhenHidden:c=!0,throttle:l=0}={}){let u=l>0?(0,e.throttle)(r,l,{leading:!0,trailing:!0}):null,d=u??r,p=!0,m=()=>{p&&d()};d();let h=[];if(c&&f(t)&&typeof IntersectionObserver<`u`){let e=new IntersectionObserver(e=>{p=e.at(-1)?.isIntersecting??!0,p&&d()});e.observe(t),h.push(()=>e.disconnect())}if(f(t)&&a){let e=U(t);for(let t of e)t.addEventListener(`scroll`,m,{passive:!0}),h.push(()=>t.removeEventListener(`scroll`,m));window.addEventListener(`scroll`,m,{passive:!0}),h.push(()=>window.removeEventListener(`scroll`,m))}else{let e=e=>{e.composedPath().includes(n)||m()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),h.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,m,{passive:!0}),h.push(()=>window.removeEventListener(`resize`,m));let g=s?window.visualViewport:null;g&&(g.addEventListener(`resize`,m,{passive:!0}),g.addEventListener(`scroll`,m,{passive:!0}),h.push(()=>{g.removeEventListener(`resize`,m),g.removeEventListener(`scroll`,m)}));let _=new ResizeObserver(m);f(t)&&_.observe(t),o&&_.observe(n),h.push(()=>_.disconnect());let v=0;if(i){let e=()=>{m(),v=window.requestAnimationFrame(e)};v=window.requestAnimationFrame(e),h.push(()=>window.cancelAnimationFrame(v))}return()=>{u?.cancel();for(let e of h)e()}}function G(e,t,n){let r=new AbortController,i=!1;return{get disposalSignal(){return r.signal},dispose(){i||(i=!0,r.abort(),e())},get disposed(){return i},getPosition:t,[Symbol.dispose](){this.dispose()},update:n}}function K(){return typeof CSS<`u`&&CSS.supports(`anchor-name`,`--orbit`)}var q=0,J={bottom:`block-end center`,"bottom-end":`block-end span-inline-end`,"bottom-start":`block-end span-inline-start`,left:`inline-start center`,"left-end":`inline-start span-block-end`,"left-start":`inline-start span-block-start`,right:`inline-end center`,"right-end":`inline-end span-block-end`,"right-start":`inline-end span-block-start`,top:`block-start center`,"top-end":`block-start span-inline-end`,"top-start":`block-start span-inline-start`};function Y(e,t){let n={};for(let r of Object.keys(t)){let i=e.style.getPropertyValue(r);n[r]=i===``?void 0:i,e.style.setProperty(r,t[r])}return()=>{for(let r of Object.keys(t)){let t=n[r];t===void 0?e.style.removeProperty(r):e.style.setProperty(r,t)}}}function X(e,t,n,r){let i=`--orbit-${++q}`,a=Y(e,{"anchor-name":i}),o=Y(t,{position:`fixed`,"position-anchor":i,"position-area":J[n],"position-try-fallbacks":r});return()=>{a(),o()}}function te(e,t,{fallbacks:n=`flip-block, flip-inline, flip-block flip-inline`,placement:r=`bottom`}={}){let i=X(e,t,r,n),a=G(()=>i(),()=>null,()=>{});return Object.assign(a,{cssAnchor:!0})}function Z(e,t){t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function Q(e,t,{apply:n,autoUpdate:r={},boundary:i,containingBlock:a,middleware:o,padding:s,placement:c=`bottom`}={}){let l=null,u=n??(e=>Z(e,t));function d(){let n=T(e,t,{boundary:i,containingBlock:a,middleware:o,padding:s,placement:c});l=n,u(n)}if(r===!1)return d(),G(()=>{},()=>l,d);let f=W(e,t,d,r);return G(()=>f(),()=>l,d)}function ne(...e){return e.filter(Boolean)}function re({element:t,padding:n=0}){function r(r){let i=s(r.placement),a=d(n),o=u(t.getBoundingClientRect());if(i===`top`||i===`bottom`){let t=r.rects.reference.x+r.rects.reference.width/2-r.x-o.width/2,n=a.left,i=(0,e.clamp)(t,n,Math.max(n,r.rects.floating.width-o.width-a.right));return{data:{arrow:{centerOffset:t-i,constrained:i!==t,x:i}}}}let c=r.rects.reference.y+r.rects.reference.height/2-r.y-o.height/2,l=a.top,f=(0,e.clamp)(c,l,Math.max(l,r.rects.floating.height-o.height-a.bottom));return{data:{arrow:{centerOffset:c-f,constrained:f!==c,y:f}}}}return _(r,`arrow`)}var $=[`top`,`right`,`bottom`,`left`];function ie(e){return e===void 0?$:e===null?$.flatMap(e=>[e,`${e}-start`,`${e}-end`]):$.map(t=>`${t}-${e}`)}function ae(e={}){return _(function(t){let{boundary:n,padding:r}=A(e,t),a=e.allowedPlacements??ie(e.alignment);a.length===0&&i(`autoPlacement: allowedPlacements is empty — no placement will be evaluated.`);let o=t.placement,s=1/0,c=-1/0;for(let i of a){let a=N(L(t,i,e)),l=I(t,i,n,r);(a<s||a===s&&l>c)&&(o=i,s=a,c=l)}if(o!==t.placement)return{reset:{placement:o}}},`autoPlacement`)}function oe(e={}){function t(t){let n=R(t,e);if(!P(n))return;let r=s(t.placement),i=c(t.placement),a=e.fallbackPlacements??[l(o[r],i)],u=[t.placement],d=t.placement,f=N(n);for(let n of a){let r=L(t,n,e),i=N(r);if(!P(r))return{data:{flip:{skippedPlacements:u}},reset:{placement:n}};u.push(n),i<f&&(d=n,f=i)}if(d!==t.placement)return{data:{flip:{skippedPlacements:u}},reset:{placement:d}}}return _(t,`flip`)}function se(e={}){let t=e.strategy??`both`;function n(n){let{boundary:r,padding:i}=A(e,n),a={};if(t===`escaped`||t===`both`){let e=j(n),t=M(e,r,i);a.escaped=F(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=M(n.rects.reference,r,i);a.referenceHidden=F(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return _(n,`hide`)}function ce(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(u).filter(e=>e.width>0||e.height>0)}function le(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function ue(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function de(e={}){function t(t){let n=ce(t.elements.reference);if(n.length<=1)return;let r=d(e.padding??2),i=s(t.placement),a=n[0];if(e.x!=null&&e.y!=null)a=n.find(t=>le(t,e.x,e.y,r))??a;else if(i===`top`||i===`bottom`){let e=t.x+t.rects.floating.width/2;a=n.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},a)}else{let e=t.y+t.rects.floating.height/2;a=n.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},a)}if(!ue(a,t.rects.reference))return{reset:{rects:{...t.rects,reference:a}}}}return _(t,`inline`)}function fe(e,t){let n=typeof e==`function`?e(t):e;return typeof n==`number`?{crossAxis:0,mainAxis:n}:{crossAxis:n.crossAxis??0,mainAxis:n.mainAxis??0}}function pe(e){return _(function(t){let n=s(t.placement),{crossAxis:r,mainAxis:i}=fe(e,t);switch(n){case`bottom`:return{x:t.x+r,y:t.y+i};case`left`:return{x:t.x-i,y:t.y+r};case`right`:return{x:t.x+i,y:t.y+r};case`top`:return{x:t.x+r,y:t.y-i}}},`offset`)}function me(t={}){return(n,r)=>{let{placement:i,rects:a,x:o,y:c}=n,l=s(i),u=l===`top`||l===`bottom`,d=typeof t.offset==`function`?t.offset(n):t.offset??0;if(u){let t=a.reference.x-d,n=a.reference.x+a.reference.width+d-a.floating.width,[i,s]=t<=n?[t,n]:[n,t],c=(0,e.clamp)(o+r.crossAxis,i,s);return{...r,crossAxis:c-o}}let f=a.reference.y-d,p=a.reference.y+a.reference.height+d-a.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=(0,e.clamp)(c+r.crossAxis,m,h);return{...r,crossAxis:g-c}}}function he(e={}){let{crossAxis:t=!0,limiter:n,mainAxis:r=!1}=e;function i(i){let a=R(i,e),o=s(i.placement),c=o===`top`||o===`bottom`,l=Math.max(a.left,0)-Math.max(a.right,0),u=Math.max(a.top,0)-Math.max(a.bottom,0),d=c?t:r,f=c?r:t,p=d?l:0,m=f?u:0;if(n){let e=n(i,{crossAxis:c?p:m,mainAxis:c?m:p});p=c?e.crossAxis:e.mainAxis,m=c?e.mainAxis:e.crossAxis}return{data:{shift:{x:p,y:m}},x:i.x+p,y:i.y+m}}return _(i,`shift`)}function ge(e={}){function t(t){let{boundary:n,padding:r}=A(e,t),i=s(t.placement),a=n.y+r.top,o=n.x+n.width-r.right,c=n.y+n.height-r.bottom,l=n.x+r.left;return{data:{size:{availableHeight:i===`bottom`?Math.max(0,c-t.y):i===`top`?Math.max(0,t.rects.reference.y-a):Math.max(0,c-a),availableWidth:i===`right`?Math.max(0,o-t.x):i===`left`?Math.max(0,t.rects.reference.x-l):Math.max(0,o-l)}}}}return _(t,`size`)}exports.OrbitConfigError=n,exports.OrbitError=t,exports.arrow=re,exports.autoPlacement=ae,exports.autoUpdate=W,exports.compose=ne,exports.computePosition=T,exports.computePositionAsync=C,exports.computePositionRaf=w,exports.detectOverflow=R,exports.flip=oe,exports.float=Q,exports.floatWithAnchor=te,exports.getAlignment=c,exports.getClippingAncestorRect=k,exports.getContainingBlock=H,exports.getRects=b,exports.getSide=s,exports.hide=se,exports.inline=de,exports.isCssAnchorSupported=K,exports.limitShift=me,exports.offset=pe,exports.shift=he,exports.size=ge;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{};function n(e,t,n){return t!=null&&e<t?t:n!=null&&e>n?n:e}var r={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function i(e){return e.split(`-`)[0]}function a(e){return e.split(`-`)[1]??null}function o(e,t){return t?`${e}-${t}`:e}function s({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function c(e=0){return typeof e==`number`?{bottom:e,left:e,right:e,top:e}:{bottom:e.bottom??0,left:e.left??0,right:e.right??0,top:e.top??0}}function l(e){return typeof Element<`u`&&e instanceof Element}function u(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}var d=[[`arrow`,`flip`],[`arrow`,`shift`],[`arrow`,`autoPlacement`],[`flip`,`inline`],[`shift`,`inline`],[`autoPlacement`,`inline`],[`size`,`flip`],[`size`,`autoPlacement`]];function f(e){for(let[n,r]of d){let i=e.indexOf(n),a=e.indexOf(r);if(i!==-1&&a!==-1&&i<a)throw new t(`"${n}" must come after "${r}" in the middleware pipeline. Recommended order: inline → offset → flip/autoPlacement → shift → size → arrow.`)}if(e.includes(`flip`)&&e.includes(`autoPlacement`))throw new t(`use either flip() or autoPlacement() in the middleware pipeline, not both.`)}var p=Symbol.for(`@vielzeug/orbit/name`);function m(e,t){return e[p]=t,e}function h(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function g(e,t,n){let r=i(e),o=a(e);switch(r){case`bottom`:return{x:h(o,t.x,t.width,n.width),y:t.y+t.height};case`left`:return{x:t.x-n.width,y:h(o,t.y,t.height,n.height)};case`right`:return{x:t.x+t.width,y:h(o,t.y,t.height,n.height)};case`top`:return{x:h(o,t.x,t.width,n.width),y:t.y-n.height}}}function _(e,t){return{floating:s(t.getBoundingClientRect()),reference:s(e.getBoundingClientRect())}}function v(e,t){return t?{...e,middlewareData:t.data?Object.assign(Object.create(null),e.middlewareData,t.data):e.middlewareData,placement:t.placement??e.placement,x:t.x??e.x,y:t.y??e.y}:e}var y=8;function b(e,t,n){return Promise.resolve().then(()=>S(e,t,n))}function x(e,t,n){return new Promise((r,i)=>{requestAnimationFrame(()=>{try{r(S(e,t,n))}catch(e){i(e)}})})}function S(e,n,{boundary:r,containingBlock:i,middleware:a=[],padding:o,placement:s=`bottom`}={}){let c=a.filter(Boolean);f(c.map(e=>{let t=e[p];return typeof t==`string`?t:null}));let l=s,u={},d=_(e,n);for(let t=0;t<y;t+=1){let t={...g(l,d.reference,d.floating),boundary:r,elements:{floating:n,reference:e},initialPlacement:s,middlewareData:u,padding:o,placement:l,rects:d},a;for(let e of c){let n=e(t);if(t=v(t,n),u=t.middlewareData,a=n?.reset,a)break}if(!a){let e={middlewareData:t.middlewareData,placement:t.placement,x:t.x,y:t.y};if(i){let t=i.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}a.remeasure?d=_(e,n):a.rects!=null&&(d=a.rects),l=a.placement??t.placement}throw new t(`Middleware triggered too many resets in a single compute cycle.`)}function C(){let e=window.visualViewport;return e?{height:e.height,width:e.width,x:e.offsetLeft,y:e.offsetTop}:{height:window.innerHeight,width:window.innerWidth,x:0,y:0}}function w(e){if(!e)return C();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var ee=/(hidden|clip|scroll|auto|overlay)/;function T(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{height:Math.max(0,a-r),width:Math.max(0,i-n),x:n,y:r}}function E(e){let t=u(e),n=C();for(;t;){let e=getComputedStyle(t);if(ee.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=T(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=u(t)}return n}function D(e,t){return{boundary:w(e.boundary??t.boundary),padding:c(e.padding??t.padding)}}function O(e){return{...e.rects.floating,x:e.x,y:e.y}}function k(e,t,n){return{bottom:e.y+e.height-(t.y+t.height-n.bottom),left:t.x+n.left-e.x,right:e.x+e.width-(t.x+t.width-n.right),top:t.y+n.top-e.y}}function A(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function j(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function M(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function N(e,t,n,r){let a=e.rects.reference;switch(i(t)){case`bottom`:return n.y+n.height-r.bottom-(a.y+a.height);case`left`:return a.x-(n.x+r.left);case`right`:return n.x+n.width-r.right-(a.x+a.width);case`top`:return a.y-(n.y+r.top)}}function P(e,t,n={}){let{x:r,y:i}=g(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=D(n,e);return k({...e.rects.floating,x:r,y:i},a,o)}function F(e,t={}){let{boundary:n,padding:r}=D(t,e);return k(O(e),n,r)}var I=[`transform`,`perspective`,`filter`],L=[`layout`,`paint`,`strict`,`content`];function R(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&I.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&L.some(t=>e.contain.includes(t))}function z(e){let t=u(e);for(;t;){if(R(getComputedStyle(t)))return t;t=u(t)}return null}function B(e,t=700,n={leading:!0,trailing:!1}){let r=n.leading??!0,i=n.trailing??!1,a,o=-1/0,s,c,l=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},u=e=>{a=setTimeout(p,e)},d=t=>{if(o=t,l(),!s)return;let n=s;return s=void 0,c=e(...n),c},f=e=>t-(e-o),p=()=>{let e=Date.now();s&&f(e)<=0?d(e):s?u(f(e)):l()};return Object.assign((...e)=>{let t=Date.now();o===-1/0&&!r&&(o=t),s=e;let n=f(t);return n<=0?d(t):(i&&!a&&u(n),c)},{cancel:()=>{l(),s=void 0,o=-1/0},flush:()=>{if(s)return d(Date.now())},pending:()=>s!==void 0||a!==void 0})}function V(e){let t=[],n=u(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=u(n)}return t}function H(e,t,n,{animationFrame:r=!1,observeAncestors:i=!0,observeFloating:a=!0,observeVisualViewport:o=!0,pauseWhenHidden:s=!0,throttle:c=0}={}){let u=c>0?B(n,c,{leading:!0,trailing:!0}):null,d=u??n,f=!0,p=()=>{f&&d()};d();let m=[];if(s&&l(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{f=e.at(-1)?.isIntersecting??!0,f&&d()});t.observe(e),m.push(()=>t.disconnect())}if(l(e)&&i){let t=V(e);for(let e of t)e.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>e.removeEventListener(`scroll`,p));window.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>window.removeEventListener(`scroll`,p))}else{let e=e=>{e.composedPath().includes(t)||p()};window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),m.push(()=>window.removeEventListener(`scroll`,e,{capture:!0}))}window.addEventListener(`resize`,p,{passive:!0}),m.push(()=>window.removeEventListener(`resize`,p));let h=o?window.visualViewport:null;h&&(h.addEventListener(`resize`,p,{passive:!0}),h.addEventListener(`scroll`,p,{passive:!0}),m.push(()=>{h.removeEventListener(`resize`,p),h.removeEventListener(`scroll`,p)}));let g=new ResizeObserver(p);l(e)&&g.observe(e),a&&g.observe(t),m.push(()=>g.disconnect());let _=0;if(r){let e=()=>{p(),_=window.requestAnimationFrame(e)};_=window.requestAnimationFrame(e),m.push(()=>window.cancelAnimationFrame(_))}return()=>{u?.cancel();for(let e of m)e()}}function U(e,t,n){let r=new AbortController,i=!1;return{get disposalSignal(){return r.signal},dispose(){i||(i=!0,r.abort(),e())},get disposed(){return i},getPosition:t,[Symbol.dispose](){this.dispose()},update:n}}function W(){return typeof CSS<`u`&&CSS.supports(`anchor-name`,`--orbit`)}var G=0,K={bottom:`block-end center`,"bottom-end":`block-end span-inline-end`,"bottom-start":`block-end span-inline-start`,left:`inline-start center`,"left-end":`inline-start span-block-end`,"left-start":`inline-start span-block-start`,right:`inline-end center`,"right-end":`inline-end span-block-end`,"right-start":`inline-end span-block-start`,top:`block-start center`,"top-end":`block-start span-inline-end`,"top-start":`block-start span-inline-start`};function q(e,t){let n={};for(let r of Object.keys(t)){let i=e.style.getPropertyValue(r);n[r]=i===``?void 0:i,e.style.setProperty(r,t[r])}return()=>{for(let r of Object.keys(t)){let t=n[r];t===void 0?e.style.removeProperty(r):e.style.setProperty(r,t)}}}function te(e,t,n,r){let i=`--orbit-${++G}`,a=q(e,{"anchor-name":i}),o=q(t,{position:`fixed`,"position-anchor":i,"position-area":K[n],"position-try-fallbacks":r});return()=>{a(),o()}}function J(e,t,{fallbacks:n=`flip-block, flip-inline, flip-block flip-inline`,placement:r=`bottom`}={}){let i=te(e,t,r,n),a=U(()=>i(),()=>null,()=>{});return Object.assign(a,{cssAnchor:!0})}function Y(e,t){t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function X(e,t,{apply:n,autoUpdate:r={},boundary:i,containingBlock:a,middleware:o,padding:s,placement:c=`bottom`}={}){let l=null,u=n??(e=>Y(e,t));function d(){let n=S(e,t,{boundary:i,containingBlock:a,middleware:o,padding:s,placement:c});l=n,u(n)}if(r===!1)return d(),U(()=>{},()=>l,d);let f=H(e,t,d,r);return U(()=>f(),()=>l,d)}function Z(...e){return e.filter(Boolean)}function Q({element:e,padding:t=0}){function r(r){let a=i(r.placement),o=c(t),l=s(e.getBoundingClientRect());if(a===`top`||a===`bottom`){let e=r.rects.reference.x+r.rects.reference.width/2-r.x-l.width/2,t=o.left,i=n(e,t,Math.max(t,r.rects.floating.width-l.width-o.right));return{data:{arrow:{centerOffset:e-i,constrained:i!==e,x:i}}}}let u=r.rects.reference.y+r.rects.reference.height/2-r.y-l.height/2,d=o.top,f=n(u,d,Math.max(d,r.rects.floating.height-l.height-o.bottom));return{data:{arrow:{centerOffset:u-f,constrained:f!==u,y:f}}}}return m(r,`arrow`)}var $=[`top`,`right`,`bottom`,`left`];function ne(e){return e===void 0?$:e===null?$.flatMap(e=>[e,`${e}-start`,`${e}-end`]):$.map(t=>`${t}-${e}`)}function re(e={}){return m(function(t){let{boundary:n,padding:r}=D(e,t),i=e.allowedPlacements??ne(e.alignment);i.length;let a=t.placement,o=1/0,s=-1/0;for(let c of i){let i=A(P(t,c,e)),l=N(t,c,n,r);(i<o||i===o&&l>s)&&(a=c,o=i,s=l)}if(a!==t.placement)return{reset:{placement:a}}},`autoPlacement`)}function ie(e={}){function t(t){let n=F(t,e);if(!j(n))return;let s=i(t.placement),c=a(t.placement),l=e.fallbackPlacements??[o(r[s],c)],u=[t.placement],d=t.placement,f=A(n);for(let n of l){let r=P(t,n,e),i=A(r);if(!j(r))return{data:{flip:{skippedPlacements:u}},reset:{placement:n}};u.push(n),i<f&&(d=n,f=i)}if(d!==t.placement)return{data:{flip:{skippedPlacements:u}},reset:{placement:d}}}return m(t,`flip`)}function ae(e={}){let t=e.strategy??`both`;function n(n){let{boundary:r,padding:i}=D(e,n),a={};if(t===`escaped`||t===`both`){let e=O(n),t=k(e,r,i);a.escaped=M(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=k(n.rects.reference,r,i);a.referenceHidden=M(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return m(n,`hide`)}function oe(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(s).filter(e=>e.width>0||e.height>0)}function se(e,t,n,r){return t>=e.x-r.left&&t<=e.x+e.width+r.right&&n>=e.y-r.top&&n<=e.y+e.height+r.bottom}function ce(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function le(e={}){function t(t){let n=oe(t.elements.reference);if(n.length<=1)return;let r=c(e.padding??2),a=i(t.placement),o=n[0];if(e.x!=null&&e.y!=null)o=n.find(t=>se(t,e.x,e.y,r))??o;else if(a===`top`||a===`bottom`){let e=t.x+t.rects.floating.width/2;o=n.reduce((t,n)=>{let r=Math.abs(t.x+t.width/2-e);return Math.abs(n.x+n.width/2-e)<r?n:t},o)}else{let e=t.y+t.rects.floating.height/2;o=n.reduce((t,n)=>{let r=Math.abs(t.y+t.height/2-e);return Math.abs(n.y+n.height/2-e)<r?n:t},o)}if(!ce(o,t.rects.reference))return{reset:{rects:{...t.rects,reference:o}}}}return m(t,`inline`)}function ue(e,t){let n=typeof e==`function`?e(t):e;return typeof n==`number`?{crossAxis:0,mainAxis:n}:{crossAxis:n.crossAxis??0,mainAxis:n.mainAxis??0}}function de(e){return m(function(t){let n=i(t.placement),{crossAxis:r,mainAxis:a}=ue(e,t);switch(n){case`bottom`:return{x:t.x+r,y:t.y+a};case`left`:return{x:t.x-a,y:t.y+r};case`right`:return{x:t.x+a,y:t.y+r};case`top`:return{x:t.x+r,y:t.y-a}}},`offset`)}function fe(e={}){return(t,r)=>{let{placement:a,rects:o,x:s,y:c}=t,l=i(a),u=l===`top`||l===`bottom`,d=typeof e.offset==`function`?e.offset(t):e.offset??0;if(u){let e=o.reference.x-d,t=o.reference.x+o.reference.width+d-o.floating.width,[i,a]=e<=t?[e,t]:[t,e],c=n(s+r.crossAxis,i,a);return{...r,crossAxis:c-s}}let f=o.reference.y-d,p=o.reference.y+o.reference.height+d-o.floating.height,[m,h]=f<=p?[f,p]:[p,f],g=n(c+r.crossAxis,m,h);return{...r,crossAxis:g-c}}}function pe(e={}){let{crossAxis:t=!0,limiter:n,mainAxis:r=!1}=e;function a(a){let o=F(a,e),s=i(a.placement),c=s===`top`||s===`bottom`,l=Math.max(o.left,0)-Math.max(o.right,0),u=Math.max(o.top,0)-Math.max(o.bottom,0),d=c?t:r,f=c?r:t,p=d?l:0,m=f?u:0;if(n){let e=n(a,{crossAxis:c?p:m,mainAxis:c?m:p});p=c?e.crossAxis:e.mainAxis,m=c?e.mainAxis:e.crossAxis}return{data:{shift:{x:p,y:m}},x:a.x+p,y:a.y+m}}return m(a,`shift`)}function me(e={}){function t(t){let{boundary:n,padding:r}=D(e,t),a=i(t.placement),o=n.y+r.top,s=n.x+n.width-r.right,c=n.y+n.height-r.bottom,l=n.x+r.left;return{data:{size:{availableHeight:a===`bottom`?Math.max(0,c-t.y):a===`top`?Math.max(0,t.rects.reference.y-o):Math.max(0,c-o),availableWidth:a===`right`?Math.max(0,s-t.x):a===`left`?Math.max(0,t.rects.reference.x-l):Math.max(0,s-l)}}}}return m(t,`size`)}exports.OrbitConfigError=t,exports.OrbitError=e,exports.arrow=Q,exports.autoPlacement=re,exports.autoUpdate=H,exports.compose=Z,exports.computePosition=S,exports.computePositionAsync=b,exports.computePositionRaf=x,exports.detectOverflow=F,exports.flip=ie,exports.float=X,exports.floatWithAnchor=J,exports.getAlignment=a,exports.getClippingAncestorRect=E,exports.getContainingBlock=z,exports.getRects=_,exports.getSide=i,exports.hide=ae,exports.inline=le,exports.isCssAnchorSupported=W,exports.limitShift=fe,exports.offset=de,exports.shift=pe,exports.size=me;
|
|
2
2
|
//# sourceMappingURL=orbit.cjs.map
|