@vielzeug/orbit 26.10.15 → 26.10.16

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.
Files changed (50) hide show
  1. package/dist/_dev.cjs.map +1 -1
  2. package/dist/_dev.js.map +1 -1
  3. package/dist/auto-update.cjs +1 -1
  4. package/dist/auto-update.cjs.map +1 -1
  5. package/dist/auto-update.js +1 -1
  6. package/dist/auto-update.js.map +1 -1
  7. package/dist/containing-block.cjs.map +1 -1
  8. package/dist/containing-block.js.map +1 -1
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/core.js.map +1 -1
  11. package/dist/devtools.cjs.map +1 -1
  12. package/dist/devtools.js.map +1 -1
  13. package/dist/errors.cjs.map +1 -1
  14. package/dist/errors.js.map +1 -1
  15. package/dist/float.cjs.map +1 -1
  16. package/dist/float.js.map +1 -1
  17. package/dist/inline.cjs.map +1 -1
  18. package/dist/inline.js.map +1 -1
  19. package/dist/middleware/arrow.cjs.map +1 -1
  20. package/dist/middleware/arrow.js.map +1 -1
  21. package/dist/middleware/auto-placement.cjs.map +1 -1
  22. package/dist/middleware/auto-placement.js.map +1 -1
  23. package/dist/middleware/flip.cjs +1 -1
  24. package/dist/middleware/flip.cjs.map +1 -1
  25. package/dist/middleware/flip.d.ts.map +1 -1
  26. package/dist/middleware/flip.js +1 -1
  27. package/dist/middleware/flip.js.map +1 -1
  28. package/dist/middleware/hide.cjs.map +1 -1
  29. package/dist/middleware/hide.js.map +1 -1
  30. package/dist/middleware/offset.cjs.map +1 -1
  31. package/dist/middleware/offset.js.map +1 -1
  32. package/dist/middleware/shift.cjs.map +1 -1
  33. package/dist/middleware/shift.js.map +1 -1
  34. package/dist/middleware/size.cjs.map +1 -1
  35. package/dist/middleware/size.js.map +1 -1
  36. package/dist/orbit.cjs +1 -1
  37. package/dist/orbit.cjs.map +1 -1
  38. package/dist/orbit.iife.js +1 -1
  39. package/dist/orbit.iife.js.map +1 -1
  40. package/dist/orbit.js +586 -1
  41. package/dist/orbit.js.map +1 -1
  42. package/dist/overflow.cjs.map +1 -1
  43. package/dist/overflow.js.map +1 -1
  44. package/dist/presets.cjs.map +1 -1
  45. package/dist/presets.js.map +1 -1
  46. package/dist/reactive.cjs.map +1 -1
  47. package/dist/reactive.js.map +1 -1
  48. package/dist/utils.cjs.map +1 -1
  49. package/dist/utils.js.map +1 -1
  50. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"auto-placement.js","names":[],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\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 * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\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 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 };\n}\n"],"mappings":"wIAqBA,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,SAAiC,EAA0D,CAChG,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,CACF"}
1
+ {"version":3,"file":"auto-placement.js","names":["SIDES","getDefaultPlacements","alignment","side","autoPlacement","resolveBoundary","options","state","placements","bestPlacement","bestOverflow","bestSpace","candidate","overflow","getPlacementOverflow","overflowScore","totalOverflow","availableSpace","getAvailableSpace","boundary","padding"],"sources":["../../src/middleware/auto-placement.ts"],"sourcesContent":["import { warn } from '../_dev';\nimport { getAvailableSpace, getPlacementOverflow, resolveBoundary, totalOverflow } from '../overflow';\nimport type { Alignment, DetectOverflowOptions, Middleware, Placement, Side } from '../types';\n\nexport interface AutoPlacementOptions extends DetectOverflowOptions {\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 * Placements to evaluate. When provided, takes precedence over `alignment`.\n * Note: use either `flip` or `autoPlacement`, not both.\n */\n allowedPlacements?: Placement[];\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 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 };\n}\n"],"mappings":"A,wIAqBA,IAAMA,EAAgB,CAAC,MAAO,QAAS,SAAU,MAAM,EAEvD,SAASC,EAAqB,EAA2C,CAOvE,OANIC,IAAc,IAAA,GAAkBF,EAEhCE,IAAc,KACTF,EAAM,QAAS,GAAS,CAACG,EAAM,GAAGA,EAAK,QAAS,GAAGA,EAAK,KAAK,CAAgB,EAG/EH,EAAM,IAAK,GAAS,GAAGG,EAAK,GAAGD,GAAwB,CAChE,CAWA,SAAgBE,EAAc,EAAgC,CAAC,EAAe,CAC5E,OAAO,SAAiC,EAA0D,CAChG,GAAM,CAAE,WAAU,WAAYC,EAAgBC,EAASC,CAAK,EACtDC,EAAaF,EAAQ,mBAAqBL,EAAqBK,EAAQ,SAAS,EAElFE,EAAW,OAIf,IAAIC,EAAgBF,EAAM,UACtBG,EAAe,IACfC,EAAY,KAEhB,IAAK,IAAMC,KAAaJ,EAAY,CAClC,IAAMK,EAAWC,EAAqBP,EAAOK,EAAWN,CAAO,EACzDS,EAAgBC,EAAcH,CAAQ,EACtCI,EAAiBC,EAAkBX,EAAOK,EAAWO,EAAUC,CAAO,GAExEL,EAAgBL,GAAiBK,IAAkBL,GAAgBO,EAAiBN,KACtF,EAAgBC,EAChB,EAAeG,EACf,EAAYE,EAEhB,CAEA,GAAIR,IAAkBF,EAAM,UAC1B,MAAO,CAAE,MAAO,CAAE,UAAWE,CAAc,CAAE,CAEjD,CACF,C"}
@@ -1,2 +1,2 @@
1
- const e=require("../utils.cjs"),t=require("../overflow.cjs");function n(n={}){function r(r){let i=t.detectOverflow(r,n);if(!t.hasOverflow(i))return;let a=e.getSide(r.placement),o=e.getAlignment(r.placement),s=n.fallbackPlacements??[e.withPlacement(e.OPPOSITE[a],o)],c=[r.placement],l=r.placement,u=t.totalOverflow(i);for(let e of s){let i=t.getPlacementOverflow(r,e,n),a=t.totalOverflow(i);if(!t.hasOverflow(i))return{data:{flip:{skippedPlacements:c}},reset:{placement:e}};c.push(e),a<u&&(l=e,u=a)}if(l!==r.placement)return{data:{flip:{skippedPlacements:c}},reset:{placement:l}}}return r}exports.flip=n;
1
+ const e=require("../utils.cjs"),t=require("../overflow.cjs");function n(n={}){function r(r){let i=t.detectOverflow(r,n);if(!t.hasOverflow(i))return;let a=e.getSide(r.placement),o=e.getAlignment(r.placement),s=n.fallbackPlacements??[e.withPlacement(e.OPPOSITE[a],o)],c=[r.placement],l=r.placement,u=t.totalOverflow(t.getPlacementOverflow(r,r.placement,n));for(let e of s){let i=t.getPlacementOverflow(r,e,n),a=t.totalOverflow(i);if(!t.hasOverflow(i))return{data:{flip:{skippedPlacements:c}},reset:{placement:e}};c.push(e),a<u&&(l=e,u=a)}if(l!==r.placement)return{data:{flip:{skippedPlacements:c}},reset:{placement:l}}}return r}exports.flip=n;
2
2
  //# sourceMappingURL=flip.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"flip.cjs","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"6DAgBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAA,eAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAA,YAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAA,aAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAA,cAAc,EAAA,SAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAA,cAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAA,qBAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAA,cAAc,CAAiB,EAE7C,GAAI,CAAC,EAAA,YAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"flip.cjs","names":["detectOverflow","hasOverflow","getSide","getAlignment","withPlacement","OPPOSITE","totalOverflow","getPlacementOverflow","require_utils","require_overflow","flip","flipMiddleware","currentOverflow","state","options","side","align","fallbackPlacements","skipped","bestPlacement","bestScore","candidate","candidateOverflow","score"],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n // Score the current placement at base (un-offset) coordinates, like every candidate below,\n // not at its current post-middleware position. Mixing the two is what makes the choice\n // unstable: with an `offset()` upstream, the current side always looks `offset` px worse\n // than it does at base coords, so when *neither* side fits and their base overflows differ\n // by less than that margin, each pipeline restart prefers the other side and the reset\n // loop runs until `computePosition` throws. Base-scoring both sides makes the pick\n // idempotent: the same placement wins again on the next iteration and the loop settles\n // (with `shift` clamping whatever overflow remains).\n let bestScore = totalOverflow(getPlacementOverflow(state, state.placement, options));\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"A,6DAgBA,SAAgBU,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAASC,EAAe,EAA0D,CAChF,IAAMC,EAAkBZ,EAAAA,eAAea,EAAOC,CAAO,EAErD,GAAI,CAACb,EAAAA,YAAYW,CAAe,EAAG,OAEnC,IAAMG,EAAOb,EAAAA,QAAQW,EAAM,SAAS,EAC9BG,EAAQb,EAAAA,aAAaU,EAAM,SAAS,EACpCI,EAAqBH,EAAQ,oBAAsB,CAACV,EAAAA,cAAcC,EAAAA,SAASU,GAAOC,CAAK,CAAC,EACxFE,EAAuB,CAACL,EAAM,SAAS,EACzCM,EAAgBN,EAAM,UAStBO,EAAYd,EAAAA,cAAcC,EAAAA,qBAAqBM,EAAOA,EAAM,UAAWC,CAAO,CAAC,EAEnF,IAAK,IAAMO,KAAaJ,EAAoB,CAC1C,IAAMK,EAAoBf,EAAAA,qBAAqBM,EAAOQ,EAAWP,CAAO,EAClES,EAAQjB,EAAAA,cAAcgB,CAAiB,EAE7C,GAAI,CAACrB,EAAAA,YAAYqB,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmBJ,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAWG,CAAU,CAChC,EAGFH,EAAQ,KAAKG,CAAS,EAElBE,EAAQH,IACV,EAAgBC,EAChB,EAAYE,EAEhB,CAEA,GAAIJ,IAAkBN,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmBK,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAWC,CAAc,CACpC,CAEJ,CAEA,OAAOR,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG7E,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAyC1D"}
1
+ {"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/middleware/flip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG7E,MAAM,WAAW,WAAY,SAAQ,qBAAqB;IACxD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,UAAU,CAiD1D"}
@@ -1,2 +1,2 @@
1
- import{OPPOSITE as e,getAlignment as t,getSide as n,withPlacement as r}from"../utils.js";import{detectOverflow as i,getPlacementOverflow as a,hasOverflow as o,totalOverflow as s}from"../overflow.js";function c(c={}){function l(l){let u=i(l,c);if(!o(u))return;let d=n(l.placement),f=t(l.placement),p=c.fallbackPlacements??[r(e[d],f)],m=[l.placement],h=l.placement,g=s(u);for(let e of p){let t=a(l,e,c),n=s(t);if(!o(t))return{data:{flip:{skippedPlacements:m}},reset:{placement:e}};m.push(e),n<g&&(h=e,g=n)}if(h!==l.placement)return{data:{flip:{skippedPlacements:m}},reset:{placement:h}}}return l}export{c as flip};
1
+ import{OPPOSITE as e,getAlignment as t,getSide as n,withPlacement as r}from"../utils.js";import{detectOverflow as i,getPlacementOverflow as a,hasOverflow as o,totalOverflow as s}from"../overflow.js";function c(c={}){function l(l){let u=i(l,c);if(!o(u))return;let d=n(l.placement),f=t(l.placement),p=c.fallbackPlacements??[r(e[d],f)],m=[l.placement],h=l.placement,g=s(a(l,l.placement,c));for(let e of p){let t=a(l,e,c),n=s(t);if(!o(t))return{data:{flip:{skippedPlacements:m}},reset:{placement:e}};m.push(e),n<g&&(h=e,g=n)}if(h!==l.placement)return{data:{flip:{skippedPlacements:m}},reset:{placement:h}}}return l}export{c as flip};
2
2
  //# sourceMappingURL=flip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"flip.js","names":[],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n let bestScore = totalOverflow(currentOverflow);\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"uMAgBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,IAAM,EAAkB,EAAe,EAAO,CAAO,EAErD,GAAI,CAAC,EAAY,CAAe,EAAG,OAEnC,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAQ,EAAa,EAAM,SAAS,EACpC,EAAqB,EAAQ,oBAAsB,CAAC,EAAc,EAAS,GAAO,CAAK,CAAC,EACxF,EAAuB,CAAC,EAAM,SAAS,EACzC,EAAgB,EAAM,UACtB,EAAY,EAAc,CAAe,EAE7C,IAAK,IAAM,KAAa,EAAoB,CAC1C,IAAM,EAAoB,EAAqB,EAAO,EAAW,CAAO,EAClE,EAAQ,EAAc,CAAiB,EAE7C,GAAI,CAAC,EAAY,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAU,CAChC,EAGF,EAAQ,KAAK,CAAS,EAElB,EAAQ,IACV,EAAgB,EAChB,EAAY,EAEhB,CAEA,GAAI,IAAkB,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmB,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAW,CAAc,CACpC,CAEJ,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"flip.js","names":["flip","flipMiddleware","currentOverflow","detectOverflow","state","options","hasOverflow","side","getSide","align","getAlignment","fallbackPlacements","withPlacement","OPPOSITE","skipped","bestPlacement","bestScore","totalOverflow","getPlacementOverflow","candidate","candidateOverflow","score"],"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import { detectOverflow, getPlacementOverflow, hasOverflow, totalOverflow } from '../overflow';\nimport type { DetectOverflowOptions, Middleware, Placement } from '../types';\nimport { getAlignment, getSide, OPPOSITE, withPlacement } from '../utils';\n\nexport interface FlipOptions extends DetectOverflowOptions {\n /**\n * Ordered list of candidate placements to try when the floating element overflows.\n * Defaults to the opposite side, preserving the current alignment.\n */\n fallbackPlacements?: Placement[];\n}\n\n/**\n * Flips the floating element to the opposite side when it overflows the boundary.\n * Falls back to the candidate with the least total overflow when no candidate fits.\n */\nexport function flip(options: FlipOptions = {}): Middleware {\n function flipMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const currentOverflow = detectOverflow(state, options);\n\n if (!hasOverflow(currentOverflow)) return;\n\n const side = getSide(state.placement);\n const align = getAlignment(state.placement);\n const fallbackPlacements = options.fallbackPlacements ?? [withPlacement(OPPOSITE[side], align)];\n const skipped: Placement[] = [state.placement];\n let bestPlacement = state.placement;\n // Score the current placement at base (un-offset) coordinates, like every candidate below,\n // not at its current post-middleware position. Mixing the two is what makes the choice\n // unstable: with an `offset()` upstream, the current side always looks `offset` px worse\n // than it does at base coords, so when *neither* side fits and their base overflows differ\n // by less than that margin, each pipeline restart prefers the other side and the reset\n // loop runs until `computePosition` throws. Base-scoring both sides makes the pick\n // idempotent: the same placement wins again on the next iteration and the loop settles\n // (with `shift` clamping whatever overflow remains).\n let bestScore = totalOverflow(getPlacementOverflow(state, state.placement, options));\n\n for (const candidate of fallbackPlacements) {\n const candidateOverflow = getPlacementOverflow(state, candidate, options);\n const score = totalOverflow(candidateOverflow);\n\n if (!hasOverflow(candidateOverflow)) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: candidate },\n };\n }\n\n skipped.push(candidate);\n\n if (score < bestScore) {\n bestPlacement = candidate;\n bestScore = score;\n }\n }\n\n if (bestPlacement !== state.placement) {\n return {\n data: { flip: { skippedPlacements: skipped } },\n reset: { placement: bestPlacement },\n };\n }\n }\n\n return flipMiddleware;\n}\n"],"mappings":"A,uMAgBA,SAAgBA,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAASC,EAAe,EAA0D,CAChF,IAAMC,EAAkBC,EAAeC,EAAOC,CAAO,EAErD,GAAI,CAACC,EAAYJ,CAAe,EAAG,OAEnC,IAAMK,EAAOC,EAAQJ,EAAM,SAAS,EAC9BK,EAAQC,EAAaN,EAAM,SAAS,EACpCO,EAAqBN,EAAQ,oBAAsB,CAACO,EAAcC,EAASN,GAAOE,CAAK,CAAC,EACxFK,EAAuB,CAACV,EAAM,SAAS,EACzCW,EAAgBX,EAAM,UAStBY,EAAYC,EAAcC,EAAqBd,EAAOA,EAAM,UAAWC,CAAO,CAAC,EAEnF,IAAK,IAAMc,KAAaR,EAAoB,CAC1C,IAAMS,EAAoBF,EAAqBd,EAAOe,EAAWd,CAAO,EAClEgB,EAAQJ,EAAcG,CAAiB,EAE7C,GAAI,CAACd,EAAYc,CAAiB,EAChC,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmBN,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAWK,CAAU,CAChC,EAGFL,EAAQ,KAAKK,CAAS,EAElBE,EAAQL,IACV,EAAgBG,EAChB,EAAYE,EAEhB,CAEA,GAAIN,IAAkBX,EAAM,UAC1B,MAAO,CACL,KAAM,CAAE,KAAM,CAAE,kBAAmBU,CAAQ,CAAE,EAC7C,MAAO,CAAE,UAAWC,CAAc,CACpC,CAEJ,CAEA,OAAOd,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"hide.cjs","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'`: whether the reference itself is off-screen.\n * - `'escaped'`: whether the floating element has fully exited the boundary.\n * - `'both'` (default): both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"mCAkBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAA,gBAAgB,CAAK,EACpC,EAAiB,EAAA,qBAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAA,eAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAA,qBAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAA,eAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"hide.cjs","names":["resolveBoundary","getFloatingRect","detectOverflowAtRect","isFullyClipped","require_overflow","hide","strategy","options","hideMiddleware","state","next","floatingRect","escapedOffsets","boundary","padding","referenceHiddenOffsets"],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'`: whether the reference itself is off-screen.\n * - `'escaped'`: whether the floating element has fully exited the boundary.\n * - `'both'` (default): both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"A,mCAkBA,SAAgBK,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAMC,EAAWC,EAAQ,UAAY,OAErC,SAASC,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAYR,EAAAA,gBAAgBO,EAASE,CAAK,EACtDC,EAAiB,CAAC,EAExB,GAAIJ,IAAa,WAAaA,IAAa,OAAQ,CACjD,IAAMK,EAAeV,EAAAA,gBAAgBQ,CAAK,EACpCG,EAAiBV,EAAAA,qBAAqBS,EAAcE,EAAUC,CAAO,EAE3E,EAAK,QAAUX,EAAAA,eAAeQ,EAAcC,CAAc,EAC1D,EAAK,eAAiBA,CACxB,CAEA,GAAIN,IAAa,mBAAqBA,IAAa,OAAQ,CACzD,IAAMS,EAAyBb,EAAAA,qBAAqBO,EAAM,MAAM,UAAWI,EAAUC,CAAO,EAE5F,EAAK,gBAAkBX,EAAAA,eAAeM,EAAM,MAAM,UAAWM,CAAsB,EACnF,EAAK,uBAAyBA,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAML,CAAK,CAAE,CAChC,CAEA,OAAOF,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"hide.js","names":[],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'`: whether the reference itself is off-screen.\n * - `'escaped'`: whether the floating element has fully exited the boundary.\n * - `'both'` (default): both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"oHAkBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAM,EAAW,EAAQ,UAAY,OAErC,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAiB,CAAC,EAExB,GAAI,IAAa,WAAa,IAAa,OAAQ,CACjD,IAAM,EAAe,EAAgB,CAAK,EACpC,EAAiB,EAAqB,EAAc,EAAU,CAAO,EAE3E,EAAK,QAAU,EAAe,EAAc,CAAc,EAC1D,EAAK,eAAiB,CACxB,CAEA,GAAI,IAAa,mBAAqB,IAAa,OAAQ,CACzD,IAAM,EAAyB,EAAqB,EAAM,MAAM,UAAW,EAAU,CAAO,EAE5F,EAAK,gBAAkB,EAAe,EAAM,MAAM,UAAW,CAAsB,EACnF,EAAK,uBAAyB,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAM,CAAK,CAAE,CAChC,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"hide.js","names":["hide","strategy","options","hideMiddleware","resolveBoundary","state","next","floatingRect","getFloatingRect","escapedOffsets","detectOverflowAtRect","boundary","padding","isFullyClipped","referenceHiddenOffsets"],"sources":["../../src/middleware/hide.ts"],"sourcesContent":["import { detectOverflowAtRect, getFloatingRect, isFullyClipped, resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, HideData, Middleware } from '../types';\n\nexport interface HideOptions extends DetectOverflowOptions {\n /**\n * Which hidden states to compute.\n * - `'referenceHidden'`: whether the reference itself is off-screen.\n * - `'escaped'`: whether the floating element has fully exited the boundary.\n * - `'both'` (default): both of the above.\n */\n strategy?: 'referenceHidden' | 'escaped' | 'both';\n}\n\n/**\n * Detects when the reference or floating element is hidden outside the boundary.\n * Writes `{ referenceHidden, referenceHiddenOffsets, escaped, escapedOffsets }` to\n * `middlewareData.hide`.\n */\nexport function hide(options: HideOptions = {}): Middleware {\n const strategy = options.strategy ?? 'both';\n\n function hideMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const next: HideData = {};\n\n if (strategy === 'escaped' || strategy === 'both') {\n const floatingRect = getFloatingRect(state);\n const escapedOffsets = detectOverflowAtRect(floatingRect, boundary, padding);\n\n next.escaped = isFullyClipped(floatingRect, escapedOffsets);\n next.escapedOffsets = escapedOffsets;\n }\n\n if (strategy === 'referenceHidden' || strategy === 'both') {\n const referenceHiddenOffsets = detectOverflowAtRect(state.rects.reference, boundary, padding);\n\n next.referenceHidden = isFullyClipped(state.rects.reference, referenceHiddenOffsets);\n next.referenceHiddenOffsets = referenceHiddenOffsets;\n }\n\n return { data: { hide: next } };\n }\n\n return hideMiddleware;\n}\n"],"mappings":"A,oHAkBA,SAAgBA,EAAK,EAAuB,CAAC,EAAe,CAC1D,IAAMC,EAAWC,EAAQ,UAAY,OAErC,SAASC,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAYC,EAAgBF,EAASG,CAAK,EACtDC,EAAiB,CAAC,EAExB,GAAIL,IAAa,WAAaA,IAAa,OAAQ,CACjD,IAAMM,EAAeC,EAAgBH,CAAK,EACpCI,EAAiBC,EAAqBH,EAAcI,EAAUC,CAAO,EAE3E,EAAK,QAAUC,EAAeN,EAAcE,CAAc,EAC1D,EAAK,eAAiBA,CACxB,CAEA,GAAIR,IAAa,mBAAqBA,IAAa,OAAQ,CACzD,IAAMa,EAAyBJ,EAAqBL,EAAM,MAAM,UAAWM,EAAUC,CAAO,EAE5F,EAAK,gBAAkBC,EAAeR,EAAM,MAAM,UAAWS,CAAsB,EACnF,EAAK,uBAAyBA,CAChC,CAEA,MAAO,CAAE,KAAM,CAAE,KAAMR,CAAK,CAAE,CAChC,CAEA,OAAOH,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"offset.cjs","names":[],"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware, MiddlewareState } from '../types';\n\nimport { getSide } from '../utils';\n\nexport type OffsetConfig = {\n /** Offset perpendicular to the main axis. */\n crossAxis?: number;\n /** Offset along the axis away from the reference. */\n mainAxis?: number;\n};\n\nexport type OffsetValue = number | OffsetConfig | ((state: MiddlewareState) => number | OffsetConfig);\n\nfunction resolveOffsetConfig(value: OffsetValue, state: MiddlewareState): Required<OffsetConfig> {\n const raw = typeof value === 'function' ? value(state) : value;\n\n if (typeof raw === 'number') return { crossAxis: 0, mainAxis: raw };\n\n return { crossAxis: raw.crossAxis ?? 0, mainAxis: raw.mainAxis ?? 0 };\n}\n\n/**\n * Shifts the floating element along the main axis (away from reference) and/or\n * the cross axis. Accepts a number, config object, or a function for dynamic values.\n *\n * Must be the **first** middleware in the pipeline.\n */\nexport function offset(value: OffsetValue): Middleware {\n return function offsetMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const { crossAxis, mainAxis } = resolveOffsetConfig(value, state);\n\n switch (side) {\n case 'bottom':\n return { x: state.x + crossAxis, y: state.y + mainAxis };\n case 'left':\n return { x: state.x - mainAxis, y: state.y + crossAxis };\n case 'right':\n return { x: state.x + mainAxis, y: state.y + crossAxis };\n case 'top':\n return { x: state.x + crossAxis, y: state.y - mainAxis };\n }\n };\n}\n"],"mappings":"gCAaA,SAAS,EAAoB,EAAoB,EAAgD,CAC/F,IAAM,EAAM,OAAO,GAAU,WAAa,EAAM,CAAK,EAAI,EAIzD,OAFI,OAAO,GAAQ,SAAiB,CAAE,UAAW,EAAG,SAAU,CAAI,EAE3D,CAAE,UAAW,EAAI,WAAa,EAAG,SAAU,EAAI,UAAY,CAAE,CACtE,CAQA,SAAgB,EAAO,EAAgC,CACrD,OAAO,SAA0B,EAA0D,CACzF,IAAM,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,CAAE,YAAW,YAAa,EAAoB,EAAO,CAAK,EAEhE,OAAQ,EAAR,CACE,IAAK,SACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAW,EAAG,EAAM,EAAI,CAAS,EACzD,IAAK,OACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAU,EAAG,EAAM,EAAI,CAAU,EACzD,IAAK,QACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAU,EAAG,EAAM,EAAI,CAAU,EACzD,IAAK,MACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAW,EAAG,EAAM,EAAI,CAAS,CAC3D,CACF,CACF"}
1
+ {"version":3,"file":"offset.cjs","names":["getSide","require_utils","resolveOffsetConfig","raw","value","state","offset","side","crossAxis","mainAxis"],"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware, MiddlewareState } from '../types';\n\nimport { getSide } from '../utils';\n\nexport type OffsetConfig = {\n /** Offset perpendicular to the main axis. */\n crossAxis?: number;\n /** Offset along the axis away from the reference. */\n mainAxis?: number;\n};\n\nexport type OffsetValue = number | OffsetConfig | ((state: MiddlewareState) => number | OffsetConfig);\n\nfunction resolveOffsetConfig(value: OffsetValue, state: MiddlewareState): Required<OffsetConfig> {\n const raw = typeof value === 'function' ? value(state) : value;\n\n if (typeof raw === 'number') return { crossAxis: 0, mainAxis: raw };\n\n return { crossAxis: raw.crossAxis ?? 0, mainAxis: raw.mainAxis ?? 0 };\n}\n\n/**\n * Shifts the floating element along the main axis (away from reference) and/or\n * the cross axis. Accepts a number, config object, or a function for dynamic values.\n *\n * Must be the **first** middleware in the pipeline.\n */\nexport function offset(value: OffsetValue): Middleware {\n return function offsetMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const { crossAxis, mainAxis } = resolveOffsetConfig(value, state);\n\n switch (side) {\n case 'bottom':\n return { x: state.x + crossAxis, y: state.y + mainAxis };\n case 'left':\n return { x: state.x - mainAxis, y: state.y + crossAxis };\n case 'right':\n return { x: state.x + mainAxis, y: state.y + crossAxis };\n case 'top':\n return { x: state.x + crossAxis, y: state.y - mainAxis };\n }\n };\n}\n"],"mappings":"A,gCAaA,SAASE,EAAoB,EAAoB,EAAgD,CAC/F,IAAMC,EAAM,OAAOC,GAAU,WAAaA,EAAMC,CAAK,EAAID,EAIzD,OAFI,OAAOD,GAAQ,SAAiB,CAAE,UAAW,EAAG,SAAUA,CAAI,EAE3D,CAAE,UAAWA,EAAI,WAAa,EAAG,SAAUA,EAAI,UAAY,CAAE,CACtE,CAQA,SAAgBG,EAAO,EAAgC,CACrD,OAAO,SAA0B,EAA0D,CACzF,IAAMC,EAAOP,EAAAA,QAAQK,EAAM,SAAS,EAC9B,CAAE,YAAW,YAAaH,EAAoBE,EAAOC,CAAK,EAEhE,OAAQE,EAAR,CACE,IAAK,SACH,MAAO,CAAE,EAAGF,EAAM,EAAIG,EAAW,EAAGH,EAAM,EAAII,CAAS,EACzD,IAAK,OACH,MAAO,CAAE,EAAGJ,EAAM,EAAII,EAAU,EAAGJ,EAAM,EAAIG,CAAU,EACzD,IAAK,QACH,MAAO,CAAE,EAAGH,EAAM,EAAII,EAAU,EAAGJ,EAAM,EAAIG,CAAU,EACzD,IAAK,MACH,MAAO,CAAE,EAAGH,EAAM,EAAIG,EAAW,EAAGH,EAAM,EAAII,CAAS,CAC3D,CACF,CACF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"offset.js","names":[],"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware, MiddlewareState } from '../types';\n\nimport { getSide } from '../utils';\n\nexport type OffsetConfig = {\n /** Offset perpendicular to the main axis. */\n crossAxis?: number;\n /** Offset along the axis away from the reference. */\n mainAxis?: number;\n};\n\nexport type OffsetValue = number | OffsetConfig | ((state: MiddlewareState) => number | OffsetConfig);\n\nfunction resolveOffsetConfig(value: OffsetValue, state: MiddlewareState): Required<OffsetConfig> {\n const raw = typeof value === 'function' ? value(state) : value;\n\n if (typeof raw === 'number') return { crossAxis: 0, mainAxis: raw };\n\n return { crossAxis: raw.crossAxis ?? 0, mainAxis: raw.mainAxis ?? 0 };\n}\n\n/**\n * Shifts the floating element along the main axis (away from reference) and/or\n * the cross axis. Accepts a number, config object, or a function for dynamic values.\n *\n * Must be the **first** middleware in the pipeline.\n */\nexport function offset(value: OffsetValue): Middleware {\n return function offsetMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const { crossAxis, mainAxis } = resolveOffsetConfig(value, state);\n\n switch (side) {\n case 'bottom':\n return { x: state.x + crossAxis, y: state.y + mainAxis };\n case 'left':\n return { x: state.x - mainAxis, y: state.y + crossAxis };\n case 'right':\n return { x: state.x + mainAxis, y: state.y + crossAxis };\n case 'top':\n return { x: state.x + crossAxis, y: state.y - mainAxis };\n }\n };\n}\n"],"mappings":"sCAaA,SAAS,EAAoB,EAAoB,EAAgD,CAC/F,IAAM,EAAM,OAAO,GAAU,WAAa,EAAM,CAAK,EAAI,EAIzD,OAFI,OAAO,GAAQ,SAAiB,CAAE,UAAW,EAAG,SAAU,CAAI,EAE3D,CAAE,UAAW,EAAI,WAAa,EAAG,SAAU,EAAI,UAAY,CAAE,CACtE,CAQA,SAAgB,EAAO,EAAgC,CACrD,OAAO,SAA0B,EAA0D,CACzF,IAAM,EAAO,EAAQ,EAAM,SAAS,EAC9B,CAAE,YAAW,YAAa,EAAoB,EAAO,CAAK,EAEhE,OAAQ,EAAR,CACE,IAAK,SACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAW,EAAG,EAAM,EAAI,CAAS,EACzD,IAAK,OACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAU,EAAG,EAAM,EAAI,CAAU,EACzD,IAAK,QACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAU,EAAG,EAAM,EAAI,CAAU,EACzD,IAAK,MACH,MAAO,CAAE,EAAG,EAAM,EAAI,EAAW,EAAG,EAAM,EAAI,CAAS,CAC3D,CACF,CACF"}
1
+ {"version":3,"file":"offset.js","names":["resolveOffsetConfig","raw","value","state","offset","side","getSide","crossAxis","mainAxis"],"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware, MiddlewareState } from '../types';\n\nimport { getSide } from '../utils';\n\nexport type OffsetConfig = {\n /** Offset perpendicular to the main axis. */\n crossAxis?: number;\n /** Offset along the axis away from the reference. */\n mainAxis?: number;\n};\n\nexport type OffsetValue = number | OffsetConfig | ((state: MiddlewareState) => number | OffsetConfig);\n\nfunction resolveOffsetConfig(value: OffsetValue, state: MiddlewareState): Required<OffsetConfig> {\n const raw = typeof value === 'function' ? value(state) : value;\n\n if (typeof raw === 'number') return { crossAxis: 0, mainAxis: raw };\n\n return { crossAxis: raw.crossAxis ?? 0, mainAxis: raw.mainAxis ?? 0 };\n}\n\n/**\n * Shifts the floating element along the main axis (away from reference) and/or\n * the cross axis. Accepts a number, config object, or a function for dynamic values.\n *\n * Must be the **first** middleware in the pipeline.\n */\nexport function offset(value: OffsetValue): Middleware {\n return function offsetMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const side = getSide(state.placement);\n const { crossAxis, mainAxis } = resolveOffsetConfig(value, state);\n\n switch (side) {\n case 'bottom':\n return { x: state.x + crossAxis, y: state.y + mainAxis };\n case 'left':\n return { x: state.x - mainAxis, y: state.y + crossAxis };\n case 'right':\n return { x: state.x + mainAxis, y: state.y + crossAxis };\n case 'top':\n return { x: state.x + crossAxis, y: state.y - mainAxis };\n }\n };\n}\n"],"mappings":"A,sCAaA,SAASA,EAAoB,EAAoB,EAAgD,CAC/F,IAAMC,EAAM,OAAOC,GAAU,WAAaA,EAAMC,CAAK,EAAID,EAIzD,OAFI,OAAOD,GAAQ,SAAiB,CAAE,UAAW,EAAG,SAAUA,CAAI,EAE3D,CAAE,UAAWA,EAAI,WAAa,EAAG,SAAUA,EAAI,UAAY,CAAE,CACtE,CAQA,SAAgBG,EAAO,EAAgC,CACrD,OAAO,SAA0B,EAA0D,CACzF,IAAMC,EAAOC,EAAQH,EAAM,SAAS,EAC9B,CAAE,YAAW,YAAaH,EAAoBE,EAAOC,CAAK,EAEhE,OAAQE,EAAR,CACE,IAAK,SACH,MAAO,CAAE,EAAGF,EAAM,EAAII,EAAW,EAAGJ,EAAM,EAAIK,CAAS,EACzD,IAAK,OACH,MAAO,CAAE,EAAGL,EAAM,EAAIK,EAAU,EAAGL,EAAM,EAAII,CAAU,EACzD,IAAK,QACH,MAAO,CAAE,EAAGJ,EAAM,EAAIK,EAAU,EAAGL,EAAM,EAAII,CAAU,EACzD,IAAK,MACH,MAAO,CAAE,EAAGJ,EAAM,EAAII,EAAW,EAAGJ,EAAM,EAAIK,CAAS,CAC3D,CACF,CACF,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"shift.cjs","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } 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 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 * 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\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 = {}): Middleware {\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 shiftMiddleware;\n}\n"],"mappings":"gGA0CA,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,EAAe,CAC5D,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,CACT"}
1
+ {"version":3,"file":"shift.cjs","names":["getSide","clamp","detectOverflow","require_utils","require_overflow","_vielzeug_arsenal","limitShift","state","side","placement","isVertical","extra","options","lo","rects","hi","min","max","clamped","x","correction","y","shift","shiftMiddleware","overflow","xCorrection","yCorrection","applyX","crossAxis","mainAxis","applyY","dx","dy","limiter","limited"],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } 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 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 * 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\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 = {}): Middleware {\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 shiftMiddleware;\n}\n"],"mappings":"A,gGA0CA,SAAgBM,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAMC,EAC7BC,EAAOR,EAAAA,QAAQS,CAAS,EACxBC,EAAaF,IAAS,OAASA,IAAS,SACxCG,EAAQ,OAAOC,EAAQ,QAAW,WAAaA,EAAQ,OAAOL,CAAK,EAAKK,EAAQ,QAAU,EAEhG,GAAIF,EAAY,CAEd,IAAMG,EAAKC,EAAM,UAAU,EAAIH,EACzBI,EAAKD,EAAM,UAAU,EAAIA,EAAM,UAAU,MAAQH,EAAQG,EAAM,SAAS,MACxE,CAACE,EAAKC,GAAOJ,GAAME,EAAK,CAACF,EAAIE,CAAE,EAAI,CAACA,EAAIF,CAAE,EAC1CK,GAAA,EAAUjB,EAAAA,MAAAA,CAAMkB,EAAIC,EAAW,UAAWJ,EAAKC,CAAG,EAExD,MAAO,CAAE,GAAGG,EAAY,UAAWF,EAAUC,CAAE,CACjD,CAGA,IAAMN,EAAKC,EAAM,UAAU,EAAIH,EACzBI,EAAKD,EAAM,UAAU,EAAIA,EAAM,UAAU,OAASH,EAAQG,EAAM,SAAS,OACzE,CAACE,EAAKC,GAAOJ,GAAME,EAAK,CAACF,EAAIE,CAAE,EAAI,CAACA,EAAIF,CAAE,EAC1CK,GAAA,EAAUjB,EAAAA,MAAAA,CAAMoB,EAAID,EAAW,UAAWJ,EAAKC,CAAG,EAExD,MAAO,CAAE,GAAGG,EAAY,UAAWF,EAAUG,CAAE,CACjD,CACF,CA+BA,SAAgBC,EAAM,EAAwB,CAAC,EAAe,CAC5D,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAUV,EAExD,SAASW,EAAgB,EAA0D,CACjF,IAAMC,EAAWtB,EAAAA,eAAeK,EAAOK,CAAO,EACxCJ,EAAOR,EAAAA,QAAQO,EAAM,SAAS,EAC9BG,EAAaF,IAAS,OAASA,IAAS,SAExCiB,EAAc,KAAK,IAAID,EAAS,KAAM,CAAC,EAAI,KAAK,IAAIA,EAAS,MAAO,CAAC,EACrEE,EAAc,KAAK,IAAIF,EAAS,IAAK,CAAC,EAAI,KAAK,IAAIA,EAAS,OAAQ,CAAC,EACrEG,EAASjB,EAAakB,EAAYC,EAClCC,EAASpB,EAAamB,EAAWD,EAEnCG,EAAKJ,EAASF,EAAc,EAC5BO,EAAKF,EAASJ,EAAc,EAEhC,GAAIO,EAAS,CACX,IAAMC,EAAUD,EAAQ1B,EAAO,CAC7B,UAAWG,EAAaqB,EAAKC,EAC7B,SAAUtB,EAAasB,EAAKD,CAC9B,CAAC,EAED,EAAKrB,EAAawB,EAAQ,UAAYA,EAAQ,SAC9C,EAAKxB,EAAawB,EAAQ,SAAWA,EAAQ,SAC/C,CAEA,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,EAAGH,EAAI,EAAGC,CAAG,CAAE,EAAG,EAAGzB,EAAM,EAAIwB,EAAI,EAAGxB,EAAM,EAAIyB,CAAG,CAC/E,CAEA,OAAOT,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"shift.js","names":[],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } 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 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 * 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\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 = {}): Middleware {\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 shiftMiddleware;\n}\n"],"mappings":"gIA0CA,SAAgB,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAM,EAC7B,EAAO,EAAQ,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,EAAU,EAAM,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,EAAU,EAAM,EAAI,EAAW,UAAW,EAAK,CAAG,EAExD,MAAO,CAAE,GAAG,EAAY,UAAW,EAAU,CAAE,CACjD,CACF,CA+BA,SAAgB,EAAM,EAAwB,CAAC,EAAe,CAC5D,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAU,EAExD,SAAS,EAAgB,EAA0D,CACjF,IAAM,EAAW,EAAe,EAAO,CAAO,EACxC,EAAO,EAAQ,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,CACT"}
1
+ {"version":3,"file":"shift.js","names":["limitShift","state","side","getSide","placement","isVertical","extra","options","lo","rects","hi","min","max","clamped","clamp","x","correction","y","shift","shiftMiddleware","overflow","detectOverflow","xCorrection","yCorrection","applyX","crossAxis","mainAxis","applyY","dx","dy","limiter","limited"],"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { detectOverflow } from '../overflow';\n\nimport type { DetectOverflowOptions, Middleware, MiddlewareState } from '../types';\nimport { getSide } 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 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 * 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\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 = {}): Middleware {\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 shiftMiddleware;\n}\n"],"mappings":"A,gIA0CA,SAAgBA,EAAW,EAA6B,CAAC,EAAiB,CACxE,OAAQ,EAAO,IAAe,CAC5B,GAAM,CAAE,YAAW,QAAO,IAAG,KAAMC,EAC7BC,EAAOC,EAAQC,CAAS,EACxBC,EAAaH,IAAS,OAASA,IAAS,SACxCI,EAAQ,OAAOC,EAAQ,QAAW,WAAaA,EAAQ,OAAON,CAAK,EAAKM,EAAQ,QAAU,EAEhG,GAAIF,EAAY,CAEd,IAAMG,EAAKC,EAAM,UAAU,EAAIH,EACzBI,EAAKD,EAAM,UAAU,EAAIA,EAAM,UAAU,MAAQH,EAAQG,EAAM,SAAS,MACxE,CAACE,EAAKC,GAAOJ,GAAME,EAAK,CAACF,EAAIE,CAAE,EAAI,CAACA,EAAIF,CAAE,EAC1CK,EAAUC,EAAMC,EAAIC,EAAW,UAAWL,EAAKC,CAAG,EAExD,MAAO,CAAE,GAAGI,EAAY,UAAWH,EAAUE,CAAE,CACjD,CAGA,IAAMP,EAAKC,EAAM,UAAU,EAAIH,EACzBI,EAAKD,EAAM,UAAU,EAAIA,EAAM,UAAU,OAASH,EAAQG,EAAM,SAAS,OACzE,CAACE,EAAKC,GAAOJ,GAAME,EAAK,CAACF,EAAIE,CAAE,EAAI,CAACA,EAAIF,CAAE,EAC1CK,EAAUC,EAAMG,EAAID,EAAW,UAAWL,EAAKC,CAAG,EAExD,MAAO,CAAE,GAAGI,EAAY,UAAWH,EAAUI,CAAE,CACjD,CACF,CA+BA,SAAgBC,EAAM,EAAwB,CAAC,EAAe,CAC5D,GAAM,CAAE,YAAY,GAAM,UAAS,WAAW,IAAUX,EAExD,SAASY,EAAgB,EAA0D,CACjF,IAAMC,EAAWC,EAAepB,EAAOM,CAAO,EACxCL,EAAOC,EAAQF,EAAM,SAAS,EAC9BI,EAAaH,IAAS,OAASA,IAAS,SAExCoB,EAAc,KAAK,IAAIF,EAAS,KAAM,CAAC,EAAI,KAAK,IAAIA,EAAS,MAAO,CAAC,EACrEG,EAAc,KAAK,IAAIH,EAAS,IAAK,CAAC,EAAI,KAAK,IAAIA,EAAS,OAAQ,CAAC,EACrEI,EAASnB,EAAaoB,EAAYC,EAClCC,EAAStB,EAAaqB,EAAWD,EAEnCG,EAAKJ,EAASF,EAAc,EAC5BO,EAAKF,EAASJ,EAAc,EAEhC,GAAIO,EAAS,CACX,IAAMC,EAAUD,EAAQ7B,EAAO,CAC7B,UAAWI,EAAauB,EAAKC,EAC7B,SAAUxB,EAAawB,EAAKD,CAC9B,CAAC,EAED,EAAKvB,EAAa0B,EAAQ,UAAYA,EAAQ,SAC9C,EAAK1B,EAAa0B,EAAQ,SAAWA,EAAQ,SAC/C,CAEA,MAAO,CAAE,KAAM,CAAE,MAAO,CAAE,EAAGH,EAAI,EAAGC,CAAG,CAAE,EAAG,EAAG5B,EAAM,EAAI2B,EAAI,EAAG3B,EAAM,EAAI4B,CAAG,CAC/E,CAEA,OAAOV,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"size.cjs","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"6DAwBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAA,gBAAgB,EAAS,CAAK,EACtD,EAAO,EAAA,QAAQ,EAAM,SAAS,EAC9B,EAAM,EAAS,EAAI,EAAQ,IAC3B,EAAQ,EAAS,EAAI,EAAS,MAAQ,EAAQ,MAC9C,EAAS,EAAS,EAAI,EAAS,OAAS,EAAQ,OAChD,EAAO,EAAS,EAAI,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvB,IAAS,SACL,KAAK,IAAI,EAAG,EAAS,EAAM,CAAC,EAC5B,IAAS,MACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAG,EACzC,KAAK,IAAI,EAAG,EAAS,CAAG,EASU,eANxC,IAAS,QACL,KAAK,IAAI,EAAG,EAAQ,EAAM,CAAC,EAC3B,IAAS,OACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAI,EAC1C,KAAK,IAAI,EAAG,EAAQ,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"size.cjs","names":["resolveBoundary","getSide","require_utils","require_overflow","size","sizeMiddleware","options","state","side","top","boundary","padding","right","bottom","left"],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"A,6DAwBA,SAAgBI,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAASC,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAYL,EAAAA,gBAAgBM,EAASC,CAAK,EACtDC,EAAOP,EAAAA,QAAQM,EAAM,SAAS,EAC9BE,EAAMC,EAAS,EAAIC,EAAQ,IAC3BC,EAAQF,EAAS,EAAIA,EAAS,MAAQC,EAAQ,MAC9CE,EAASH,EAAS,EAAIA,EAAS,OAASC,EAAQ,OAChDG,EAAOJ,EAAS,EAAIC,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvBH,IAAS,SACL,KAAK,IAAI,EAAGK,EAASN,EAAM,CAAC,EAC5BC,IAAS,MACP,KAAK,IAAI,EAAGD,EAAM,MAAM,UAAU,EAAIE,CAAG,EACzC,KAAK,IAAI,EAAGI,EAASJ,CAAG,EASU,eANxCD,IAAS,QACL,KAAK,IAAI,EAAGI,EAAQL,EAAM,CAAC,EAC3BC,IAAS,OACP,KAAK,IAAI,EAAGD,EAAM,MAAM,UAAU,EAAIO,CAAI,EAC1C,KAAK,IAAI,EAAGF,EAAQE,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAOT,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"size.js","names":[],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"uFAwBA,SAAgB,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAAS,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAY,EAAgB,EAAS,CAAK,EACtD,EAAO,EAAQ,EAAM,SAAS,EAC9B,EAAM,EAAS,EAAI,EAAQ,IAC3B,EAAQ,EAAS,EAAI,EAAS,MAAQ,EAAQ,MAC9C,EAAS,EAAS,EAAI,EAAS,OAAS,EAAQ,OAChD,EAAO,EAAS,EAAI,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvB,IAAS,SACL,KAAK,IAAI,EAAG,EAAS,EAAM,CAAC,EAC5B,IAAS,MACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAG,EACzC,KAAK,IAAI,EAAG,EAAS,CAAG,EASU,eANxC,IAAS,QACL,KAAK,IAAI,EAAG,EAAQ,EAAM,CAAC,EAC3B,IAAS,OACP,KAAK,IAAI,EAAG,EAAM,MAAM,UAAU,EAAI,CAAI,EAC1C,KAAK,IAAI,EAAG,EAAQ,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAO,CACT"}
1
+ {"version":3,"file":"size.js","names":["size","sizeMiddleware","resolveBoundary","options","state","side","getSide","top","boundary","padding","right","bottom","left"],"sources":["../../src/middleware/size.ts"],"sourcesContent":["import { resolveBoundary } from '../overflow';\nimport type { DetectOverflowOptions, Middleware } from '../types';\nimport { getSide } from '../utils';\n\nexport type SizeOptions = DetectOverflowOptions;\n\n/**\n * Reports the available space between the reference and boundary edges.\n *\n * Available dimensions are written to `middlewareData.size`.\n *\n * Read `result.middlewareData.size` in the positioner `apply` option or after `computePosition()`\n * to constrain the floating element's dimensions.\n *\n * @example\n * ```ts\n * const positioner = createPositioner(ref, el, {\n * middleware: [offset(8), flip(), shift(), size()],\n * apply(result) {\n * el.style.maxHeight = `${(result.middlewareData.size as SizeData).availableHeight}px`;\n * },\n * });\n * ```\n */\nexport function size(options: SizeOptions = {}): Middleware {\n function sizeMiddleware(state: Parameters<Middleware>[0]): ReturnType<Middleware> {\n const { boundary, padding } = resolveBoundary(options, state);\n const side = getSide(state.placement);\n const top = boundary.y + padding.top;\n const right = boundary.x + boundary.width - padding.right;\n const bottom = boundary.y + boundary.height - padding.bottom;\n const left = boundary.x + padding.left;\n\n const availableHeight =\n side === 'bottom'\n ? Math.max(0, bottom - state.y)\n : side === 'top'\n ? Math.max(0, state.rects.reference.y - top)\n : Math.max(0, bottom - top);\n\n const availableWidth =\n side === 'right'\n ? Math.max(0, right - state.x)\n : side === 'left'\n ? Math.max(0, state.rects.reference.x - left)\n : Math.max(0, right - left);\n\n return { data: { size: { availableHeight, availableWidth } } };\n }\n\n return sizeMiddleware;\n}\n"],"mappings":"A,uFAwBA,SAAgBA,EAAK,EAAuB,CAAC,EAAe,CAC1D,SAASC,EAAe,EAA0D,CAChF,GAAM,CAAE,WAAU,WAAYC,EAAgBC,EAASC,CAAK,EACtDC,EAAOC,EAAQF,EAAM,SAAS,EAC9BG,EAAMC,EAAS,EAAIC,EAAQ,IAC3BC,EAAQF,EAAS,EAAIA,EAAS,MAAQC,EAAQ,MAC9CE,EAASH,EAAS,EAAIA,EAAS,OAASC,EAAQ,OAChDG,EAAOJ,EAAS,EAAIC,EAAQ,KAgBlC,MAAO,CAAE,KAAM,CAAE,KAAM,CAAE,gBAbvBJ,IAAS,SACL,KAAK,IAAI,EAAGM,EAASP,EAAM,CAAC,EAC5BC,IAAS,MACP,KAAK,IAAI,EAAGD,EAAM,MAAM,UAAU,EAAIG,CAAG,EACzC,KAAK,IAAI,EAAGI,EAASJ,CAAG,EASU,eANxCF,IAAS,QACL,KAAK,IAAI,EAAGK,EAAQN,EAAM,CAAC,EAC3BC,IAAS,OACP,KAAK,IAAI,EAAGD,EAAM,MAAM,UAAU,EAAIQ,CAAI,EAC1C,KAAK,IAAI,EAAGF,EAAQE,CAAI,CAEyB,CAAE,CAAE,CAC/D,CAEA,OAAOX,CACT,C"}
package/dist/orbit.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@vielzeug/arsenal");var t={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function getSide(e){return e.split(`-`)[0]}function getAlignment(e){return e.split(`-`)[1]??null}function withPlacement(e,t){return t?`${e}-${t}`:e}function toRect({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function toSideObject(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 isElement(e){return typeof Element<`u`&&e instanceof Element}function flatTreeParent(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}function alignedOffset(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function baseCoords(e,t,n){let r=getSide(e),i=getAlignment(e);switch(r){case`bottom`:return{x:alignedOffset(i,t.x,t.width,n.width),y:t.y+t.height};case`left`:return{x:t.x-n.width,y:alignedOffset(i,t.y,t.height,n.height)};case`right`:return{x:t.x+t.width,y:alignedOffset(i,t.y,t.height,n.height)};case`top`:return{x:alignedOffset(i,t.x,t.width,n.width),y:t.y-n.height}}}function throttle(e,t){let n,r=0,throttled=(()=>{let i=Date.now(),a=t-(i-r);if(a<=0){n!==void 0&&clearTimeout(n),n=void 0,r=i,e();return}n===void 0&&(n=setTimeout(()=>{n=void 0,r=Date.now(),e()},a))});return throttled.cancel=()=>{n!==void 0&&clearTimeout(n),n=void 0},throttled}function getScrollAncestors(e){let t=[],n=flatTreeParent(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=flatTreeParent(n)}return t}function autoUpdate(e,t,n,{animationFrame:r=!1,observeAncestors:i=!0,observeFloating:a=!0,observeVisualViewport:o=!0,pauseWhenHidden:s=!0,throttle:c=0}={}){let l=c>0?throttle(n,c):null,u=l??n,d=!0,conditionalNotify=()=>{d&&u()};u();let f=[];if(s&&isElement(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{d=e.at(-1)?.isIntersecting??!0,d&&u()});t.observe(e),f.push(()=>t.disconnect())}if(isElement(e)&&i){let t=getScrollAncestors(e);for(let e of t)e.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>e.removeEventListener(`scroll`,conditionalNotify));window.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>window.removeEventListener(`scroll`,conditionalNotify))}else{let scrollHandler=e=>{e.composedPath().includes(t)||conditionalNotify()};window.addEventListener(`scroll`,scrollHandler,{capture:!0,passive:!0}),f.push(()=>window.removeEventListener(`scroll`,scrollHandler,{capture:!0}))}window.addEventListener(`resize`,conditionalNotify,{passive:!0}),f.push(()=>window.removeEventListener(`resize`,conditionalNotify));let p=o?window.visualViewport:null;p&&(p.addEventListener(`resize`,conditionalNotify,{passive:!0}),p.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>{p.removeEventListener(`resize`,conditionalNotify),p.removeEventListener(`scroll`,conditionalNotify)}));let m=new ResizeObserver(conditionalNotify);isElement(e)&&m.observe(e),a&&m.observe(t),f.push(()=>m.disconnect());let h=0;if(r){let frameLoop=()=>{conditionalNotify(),h=window.requestAnimationFrame(frameLoop)};h=window.requestAnimationFrame(frameLoop),f.push(()=>window.cancelAnimationFrame(h))}return()=>{l?.cancel();for(let e of f)e()}}var OrbitError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},OrbitConfigError=class extends OrbitError{};function getRects(e,t){return{floating:toRect(t.getBoundingClientRect()),reference:toRect(e.getBoundingClientRect())}}function mergeState(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 n=8;function computePosition(e,t,{boundary:r,containingBlock:i,middleware:a=[],padding:o,placement:s=`bottom`}={}){let c=a,l=s,u={},d=getRects(e,t);for(let a=0;a<n;a+=1){let n={...baseCoords(l,d.reference,d.floating),boundary:r,elements:{floating:t,reference:e},initialPlacement:s,middlewareData:u,padding:o,placement:l,rects:d},a;for(let e of c){let t=e(n);if(n=mergeState(n,t),u=n.middlewareData,a=t?.reset,a)break}if(!a){let e={middlewareData:n.middlewareData,placement:n.placement,x:n.x,y:n.y};if(i){let t=i.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}a.remeasure?d=getRects(e,t):a.rects!=null&&(d=a.rects),l=a.placement??n.placement}throw new OrbitConfigError(`Middleware triggered too many resets in a single compute cycle.`)}var r=[`transform`,`perspective`,`filter`],i=[`layout`,`paint`,`strict`,`content`];function establishesFixedContainingBlock(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&r.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&i.some(t=>e.contain.includes(t))}function getContainingBlock(e){let t=flatTreeParent(e);for(;t;){if(establishesFixedContainingBlock(getComputedStyle(t)))return t;t=flatTreeParent(t)}return null}function getViewportRect(){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 getBoundaryRect(e){if(!e)return getViewportRect();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var a=/(hidden|clip|scroll|auto|overlay)/;function intersectRect(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 getClippingAncestorRect(e){let t=flatTreeParent(e),n=getViewportRect();for(;t;){let e=getComputedStyle(t);if(a.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=intersectRect(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=flatTreeParent(t)}return n}function resolveBoundary(e,t){return{boundary:getBoundaryRect(e.boundary??t.boundary),padding:toSideObject(e.padding??t.padding)}}function getFloatingRect(e){return{...e.rects.floating,x:e.x,y:e.y}}function detectOverflowAtRect(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 totalOverflow(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function hasOverflow(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function isFullyClipped(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function getAvailableSpace(e,t,n,r){let i=e.rects.reference;switch(getSide(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 getPlacementOverflow(e,t,n={}){let{x:r,y:i}=baseCoords(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=resolveBoundary(n,e);return detectOverflowAtRect({...e.rects.floating,x:r,y:i},a,o)}function detectOverflow(e,t={}){let{boundary:n,padding:r}=resolveBoundary(t,e);return detectOverflowAtRect(getFloatingRect(e),n,r)}function resolveContainingBlock(e,t){return t===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:getContainingBlock(e)}function applyDefault(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function createPositioner(e,t,{apply:n,autoUpdate:r={},boundary:i=`clippingAncestors`,middleware:a,padding:o,placement:s=`bottom`,strategy:c=`fixed`}={}){let l=new AbortController,u=!0,d=!1,f,p;function update(){if(!u)return;let r=resolveContainingBlock(t,c),l=computePosition(e,t,{boundary:i===`clippingAncestors`?getClippingAncestorRect(t):i,containingBlock:r,middleware:a,padding:o,placement:s});p=l,(n??(e=>applyDefault(e,t,c)))(l)}let m={get disposalSignal(){return l.signal},dispose(){d||(d=!0,u=!1,l.abort(),f?.())},get disposed(){return d},getPosition:()=>p,[Symbol.dispose](){this.dispose()},update(){d||update()}};return r===!1?update():f=autoUpdate(e,t,update,r),m}function getClientRects(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(toRect).filter(e=>e.width>0||e.height>0)}function rectContainsPoint(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 sameRect(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function inline(e={}){function inlineMiddleware(t){let n=getClientRects(t.elements.reference);if(n.length<=1)return;let r=toSideObject(e.padding??2),i=getSide(t.placement),a=n[0];if(e.x!=null&&e.y!=null)a=n.find(t=>rectContainsPoint(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(!sameRect(a,t.rects.reference))return{reset:{rects:{...t.rects,reference:a}}}}return inlineMiddleware}function arrow({element:t,padding:n=0}){function arrowMiddleware(r){let i=getSide(r.placement),a=toSideObject(n),o=toRect(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=Math.max(n,r.rects.floating.width-o.width-a.right),s=(0,e.clamp)(t,n,i);return{data:{arrow:{centerOffset:t-s,constrained:s!==t,x:s}}}}let s=r.rects.reference.y+r.rects.reference.height/2-r.y-o.height/2,c=a.top,l=Math.max(c,r.rects.floating.height-o.height-a.bottom),u=(0,e.clamp)(s,c,l);return{data:{arrow:{centerOffset:s-u,constrained:u!==s,y:u}}}}return arrowMiddleware}var o=[`top`,`right`,`bottom`,`left`];function getDefaultPlacements(e){return e===void 0?o:e===null?o.flatMap(e=>[e,`${e}-start`,`${e}-end`]):o.map(t=>`${t}-${e}`)}function autoPlacement(e={}){return function autoPlacementMiddleware(t){let{boundary:n,padding:r}=resolveBoundary(e,t),i=e.allowedPlacements??getDefaultPlacements(e.alignment);i.length;let a=t.placement,o=1/0,s=-1/0;for(let c of i){let i=totalOverflow(getPlacementOverflow(t,c,e)),l=getAvailableSpace(t,c,n,r);(i<o||i===o&&l>s)&&(a=c,o=i,s=l)}if(a!==t.placement)return{reset:{placement:a}}}}function flip(e={}){function flipMiddleware(n){let r=detectOverflow(n,e);if(!hasOverflow(r))return;let i=getSide(n.placement),a=getAlignment(n.placement),o=e.fallbackPlacements??[withPlacement(t[i],a)],s=[n.placement],c=n.placement,l=totalOverflow(r);for(let t of o){let r=getPlacementOverflow(n,t,e),i=totalOverflow(r);if(!hasOverflow(r))return{data:{flip:{skippedPlacements:s}},reset:{placement:t}};s.push(t),i<l&&(c=t,l=i)}if(c!==n.placement)return{data:{flip:{skippedPlacements:s}},reset:{placement:c}}}return flipMiddleware}function hide(e={}){let t=e.strategy??`both`;function hideMiddleware(n){let{boundary:r,padding:i}=resolveBoundary(e,n),a={};if(t===`escaped`||t===`both`){let e=getFloatingRect(n),t=detectOverflowAtRect(e,r,i);a.escaped=isFullyClipped(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=detectOverflowAtRect(n.rects.reference,r,i);a.referenceHidden=isFullyClipped(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return hideMiddleware}function resolveOffsetConfig(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 offset(e){return function offsetMiddleware(t){let n=getSide(t.placement),{crossAxis:r,mainAxis:i}=resolveOffsetConfig(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}}}}function limitShift(t={}){return(n,r)=>{let{placement:i,rects:a,x:o,y:s}=n,c=getSide(i),l=c===`top`||c===`bottom`,u=typeof t.offset==`function`?t.offset(n):t.offset??0;if(l){let t=a.reference.x-u,n=a.reference.x+a.reference.width+u-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 d=a.reference.y-u,f=a.reference.y+a.reference.height+u-a.floating.height,[p,m]=d<=f?[d,f]:[f,d],h=(0,e.clamp)(s+r.crossAxis,p,m);return{...r,crossAxis:h-s}}}function shift(e={}){let{crossAxis:t=!0,limiter:n,mainAxis:r=!1}=e;function shiftMiddleware(i){let a=detectOverflow(i,e),o=getSide(i.placement),s=o===`top`||o===`bottom`,c=Math.max(a.left,0)-Math.max(a.right,0),l=Math.max(a.top,0)-Math.max(a.bottom,0),u=s?t:r,d=s?r:t,f=u?c:0,p=d?l:0;if(n){let e=n(i,{crossAxis:s?f:p,mainAxis:s?p:f});f=s?e.crossAxis:e.mainAxis,p=s?e.mainAxis:e.crossAxis}return{data:{shift:{x:f,y:p}},x:i.x+f,y:i.y+p}}return shiftMiddleware}function size(e={}){function sizeMiddleware(t){let{boundary:n,padding:r}=resolveBoundary(e,t),i=getSide(t.placement),a=n.y+r.top,o=n.x+n.width-r.right,s=n.y+n.height-r.bottom,c=n.x+r.left;return{data:{size:{availableHeight:i===`bottom`?Math.max(0,s-t.y):i===`top`?Math.max(0,t.rects.reference.y-a):Math.max(0,s-a),availableWidth:i===`right`?Math.max(0,o-t.x):i===`left`?Math.max(0,t.rects.reference.x-c):Math.max(0,o-c)}}}}return sizeMiddleware}exports.OrbitConfigError=OrbitConfigError,exports.OrbitError=OrbitError,exports.arrow=arrow,exports.autoPlacement=autoPlacement,exports.autoUpdate=autoUpdate,exports.computePosition=computePosition,exports.createPositioner=createPositioner,exports.detectOverflow=detectOverflow,exports.flip=flip,exports.getAlignment=getAlignment,exports.getBoundaryRect=getBoundaryRect,exports.getClippingAncestorRect=getClippingAncestorRect,exports.getSide=getSide,exports.hide=hide,exports.inline=inline,exports.limitShift=limitShift,exports.offset=offset,exports.shift=shift,exports.size=size;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@vielzeug/arsenal");var t={bottom:`top`,left:`right`,right:`left`,top:`bottom`};function getSide(e){return e.split(`-`)[0]}function getAlignment(e){return e.split(`-`)[1]??null}function withPlacement(e,t){return t?`${e}-${t}`:e}function toRect({height:e,width:t,x:n,y:r}){return{height:e,width:t,x:n,y:r}}function toSideObject(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 isElement(e){return typeof Element<`u`&&e instanceof Element}function flatTreeParent(e){return e.assignedSlot?e.assignedSlot:e.parentElement??(e.getRootNode()instanceof ShadowRoot?e.getRootNode().host:null)}function alignedOffset(e,t,n,r){return e===`start`?t:e===`end`?t+n-r:t+(n-r)/2}function baseCoords(e,t,n){let r=getSide(e),i=getAlignment(e);switch(r){case`bottom`:return{x:alignedOffset(i,t.x,t.width,n.width),y:t.y+t.height};case`left`:return{x:t.x-n.width,y:alignedOffset(i,t.y,t.height,n.height)};case`right`:return{x:t.x+t.width,y:alignedOffset(i,t.y,t.height,n.height)};case`top`:return{x:alignedOffset(i,t.x,t.width,n.width),y:t.y-n.height}}}function throttle(e,t){let n,r=0,throttled=(()=>{let i=Date.now(),a=t-(i-r);a<=0?(n!==void 0&&clearTimeout(n),n=void 0,r=i,e()):n===void 0&&(n=setTimeout(()=>{n=void 0,r=Date.now(),e()},a))});return throttled.cancel=()=>{n!==void 0&&clearTimeout(n),n=void 0},throttled}function getScrollAncestors(e){let t=[],n=flatTreeParent(e);for(;n;){let e=getComputedStyle(n),r=e.overflow+e.overflowX+e.overflowY;/auto|scroll|overlay/.test(r)&&t.push(n),n=flatTreeParent(n)}return t}function autoUpdate(e,t,n,{animationFrame:r=!1,observeAncestors:i=!0,observeFloating:a=!0,observeVisualViewport:o=!0,pauseWhenHidden:s=!0,throttle:c=0}={}){let l=c>0?throttle(n,c):null,u=l??n,d=!0,conditionalNotify=()=>{d&&u()};u();let f=[];if(s&&isElement(e)&&typeof IntersectionObserver<`u`){let t=new IntersectionObserver(e=>{d=e.at(-1)?.isIntersecting??!0,d&&u()});t.observe(e),f.push(()=>t.disconnect())}if(isElement(e)&&i){let t=getScrollAncestors(e);for(let e of t)e.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>e.removeEventListener(`scroll`,conditionalNotify));window.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>window.removeEventListener(`scroll`,conditionalNotify))}else{let scrollHandler=e=>{e.composedPath().includes(t)||conditionalNotify()};window.addEventListener(`scroll`,scrollHandler,{capture:!0,passive:!0}),f.push(()=>window.removeEventListener(`scroll`,scrollHandler,{capture:!0}))}window.addEventListener(`resize`,conditionalNotify,{passive:!0}),f.push(()=>window.removeEventListener(`resize`,conditionalNotify));let p=o?window.visualViewport:null;p&&(p.addEventListener(`resize`,conditionalNotify,{passive:!0}),p.addEventListener(`scroll`,conditionalNotify,{passive:!0}),f.push(()=>{p.removeEventListener(`resize`,conditionalNotify),p.removeEventListener(`scroll`,conditionalNotify)}));let m=new ResizeObserver(conditionalNotify);isElement(e)&&m.observe(e),a&&m.observe(t),f.push(()=>m.disconnect());let h=0;if(r){let frameLoop=()=>{conditionalNotify(),h=window.requestAnimationFrame(frameLoop)};h=window.requestAnimationFrame(frameLoop),f.push(()=>window.cancelAnimationFrame(h))}return()=>{l?.cancel();for(let e of f)e()}}var OrbitError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},OrbitConfigError=class extends OrbitError{};function getRects(e,t){return{floating:toRect(t.getBoundingClientRect()),reference:toRect(e.getBoundingClientRect())}}function mergeState(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 n=8;function computePosition(e,t,{boundary:r,containingBlock:i,middleware:a=[],padding:o,placement:s=`bottom`}={}){let c=a,l=s,u={},d=getRects(e,t);for(let a=0;a<n;a+=1){let n={...baseCoords(l,d.reference,d.floating),boundary:r,elements:{floating:t,reference:e},initialPlacement:s,middlewareData:u,padding:o,placement:l,rects:d},a;for(let e of c){let t=e(n);if(n=mergeState(n,t),u=n.middlewareData,a=t?.reset,a)break}if(!a){let e={middlewareData:n.middlewareData,placement:n.placement,x:n.x,y:n.y};if(i){let t=i.getBoundingClientRect();return{...e,x:e.x-t.x,y:e.y-t.y}}return e}a.remeasure?d=getRects(e,t):a.rects!=null&&(d=a.rects),l=a.placement??n.placement}throw new OrbitConfigError(`Middleware triggered too many resets in a single compute cycle.`)}var r=[`transform`,`perspective`,`filter`],i=[`layout`,`paint`,`strict`,`content`];function establishesFixedContainingBlock(e){return e.transform!==`none`||e.perspective!==`none`||e.filter!==`none`||e.backdropFilter&&e.backdropFilter!==`none`||e.willChange!==`auto`&&r.some(t=>e.willChange.includes(t))?!0:e.contain!==`none`&&i.some(t=>e.contain.includes(t))}function getContainingBlock(e){let t=flatTreeParent(e);for(;t;){if(establishesFixedContainingBlock(getComputedStyle(t)))return t;t=flatTreeParent(t)}return null}function getViewportRect(){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 getBoundaryRect(e){if(!e)return getViewportRect();if(e instanceof Element){let t=e.getBoundingClientRect();return{height:t.height,width:t.width,x:t.x,y:t.y}}return e}var a=/(hidden|clip|scroll|auto|overlay)/;function intersectRect(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 getClippingAncestorRect(e){let t=flatTreeParent(e),n=getViewportRect();for(;t;){let e=getComputedStyle(t);if(a.test(`${e.overflow}${e.overflowX}${e.overflowY}`)){let e=t.getBoundingClientRect();n=intersectRect(n,{height:e.height,width:e.width,x:e.x,y:e.y})}t=flatTreeParent(t)}return n}function resolveBoundary(e,t){return{boundary:getBoundaryRect(e.boundary??t.boundary),padding:toSideObject(e.padding??t.padding)}}function getFloatingRect(e){return{...e.rects.floating,x:e.x,y:e.y}}function detectOverflowAtRect(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 totalOverflow(e){return Math.max(e.top,0)+Math.max(e.right,0)+Math.max(e.bottom,0)+Math.max(e.left,0)}function hasOverflow(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function isFullyClipped(e,t){return t.top>=e.height||t.right>=e.width||t.bottom>=e.height||t.left>=e.width}function getAvailableSpace(e,t,n,r){let i=e.rects.reference;switch(getSide(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 getPlacementOverflow(e,t,n={}){let{x:r,y:i}=baseCoords(t,e.rects.reference,e.rects.floating),{boundary:a,padding:o}=resolveBoundary(n,e);return detectOverflowAtRect({...e.rects.floating,x:r,y:i},a,o)}function detectOverflow(e,t={}){let{boundary:n,padding:r}=resolveBoundary(t,e);return detectOverflowAtRect(getFloatingRect(e),n,r)}function resolveContainingBlock(e,t){return t===`absolute`?e.offsetParent instanceof Element?e.offsetParent:null:getContainingBlock(e)}function applyDefault(e,t,n){t.style.position=n,t.style.left=`${e.x}px`,t.style.top=`${e.y}px`}function createPositioner(e,t,{apply:n,autoUpdate:r={},boundary:i=`clippingAncestors`,middleware:a,padding:o,placement:s=`bottom`,strategy:c=`fixed`}={}){let l=new AbortController,u=!0,d=!1,f,p;function update(){if(!u)return;let r=resolveContainingBlock(t,c),l=computePosition(e,t,{boundary:i===`clippingAncestors`?getClippingAncestorRect(t):i,containingBlock:r,middleware:a,padding:o,placement:s});p=l,(n??(e=>applyDefault(e,t,c)))(l)}let m={get disposalSignal(){return l.signal},dispose(){d||(d=!0,u=!1,l.abort(),f?.())},get disposed(){return d},getPosition:()=>p,[Symbol.dispose](){this.dispose()},update(){d||update()}};return r===!1?update():f=autoUpdate(e,t,update,r),m}function getClientRects(e){return!(`getClientRects`in e)||typeof e.getClientRects!=`function`?[]:Array.from(e.getClientRects()).map(toRect).filter(e=>e.width>0||e.height>0)}function rectContainsPoint(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 sameRect(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function inline(e={}){function inlineMiddleware(t){let n=getClientRects(t.elements.reference);if(n.length<=1)return;let r=toSideObject(e.padding??2),i=getSide(t.placement),a=n[0];if(e.x!=null&&e.y!=null)a=n.find(t=>rectContainsPoint(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(!sameRect(a,t.rects.reference))return{reset:{rects:{...t.rects,reference:a}}}}return inlineMiddleware}function arrow({element:t,padding:n=0}){function arrowMiddleware(r){let i=getSide(r.placement),a=toSideObject(n),o=toRect(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=Math.max(n,r.rects.floating.width-o.width-a.right),s=(0,e.clamp)(t,n,i);return{data:{arrow:{centerOffset:t-s,constrained:s!==t,x:s}}}}let s=r.rects.reference.y+r.rects.reference.height/2-r.y-o.height/2,c=a.top,l=Math.max(c,r.rects.floating.height-o.height-a.bottom),u=(0,e.clamp)(s,c,l);return{data:{arrow:{centerOffset:s-u,constrained:u!==s,y:u}}}}return arrowMiddleware}var o=[`top`,`right`,`bottom`,`left`];function getDefaultPlacements(e){return e===void 0?o:e===null?o.flatMap(e=>[e,`${e}-start`,`${e}-end`]):o.map(t=>`${t}-${e}`)}function autoPlacement(e={}){return function autoPlacementMiddleware(t){let{boundary:n,padding:r}=resolveBoundary(e,t),i=e.allowedPlacements??getDefaultPlacements(e.alignment);i.length;let a=t.placement,o=1/0,s=-1/0;for(let c of i){let i=totalOverflow(getPlacementOverflow(t,c,e)),l=getAvailableSpace(t,c,n,r);(i<o||i===o&&l>s)&&(a=c,o=i,s=l)}if(a!==t.placement)return{reset:{placement:a}}}}function flip(e={}){function flipMiddleware(n){if(!hasOverflow(detectOverflow(n,e)))return;let r=getSide(n.placement),i=getAlignment(n.placement),a=e.fallbackPlacements??[withPlacement(t[r],i)],o=[n.placement],s=n.placement,c=totalOverflow(getPlacementOverflow(n,n.placement,e));for(let t of a){let r=getPlacementOverflow(n,t,e),i=totalOverflow(r);if(!hasOverflow(r))return{data:{flip:{skippedPlacements:o}},reset:{placement:t}};o.push(t),i<c&&(s=t,c=i)}if(s!==n.placement)return{data:{flip:{skippedPlacements:o}},reset:{placement:s}}}return flipMiddleware}function hide(e={}){let t=e.strategy??`both`;function hideMiddleware(n){let{boundary:r,padding:i}=resolveBoundary(e,n),a={};if(t===`escaped`||t===`both`){let e=getFloatingRect(n),t=detectOverflowAtRect(e,r,i);a.escaped=isFullyClipped(e,t),a.escapedOffsets=t}if(t===`referenceHidden`||t===`both`){let e=detectOverflowAtRect(n.rects.reference,r,i);a.referenceHidden=isFullyClipped(n.rects.reference,e),a.referenceHiddenOffsets=e}return{data:{hide:a}}}return hideMiddleware}function resolveOffsetConfig(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 offset(e){return function offsetMiddleware(t){let n=getSide(t.placement),{crossAxis:r,mainAxis:i}=resolveOffsetConfig(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}}}}function limitShift(t={}){return(n,r)=>{let{placement:i,rects:a,x:o,y:s}=n,c=getSide(i),l=c===`top`||c===`bottom`,u=typeof t.offset==`function`?t.offset(n):t.offset??0;if(l){let t=a.reference.x-u,n=a.reference.x+a.reference.width+u-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 d=a.reference.y-u,f=a.reference.y+a.reference.height+u-a.floating.height,[p,m]=d<=f?[d,f]:[f,d],h=(0,e.clamp)(s+r.crossAxis,p,m);return{...r,crossAxis:h-s}}}function shift(e={}){let{crossAxis:t=!0,limiter:n,mainAxis:r=!1}=e;function shiftMiddleware(i){let a=detectOverflow(i,e),o=getSide(i.placement),s=o===`top`||o===`bottom`,c=Math.max(a.left,0)-Math.max(a.right,0),l=Math.max(a.top,0)-Math.max(a.bottom,0),u=s?t:r,d=s?r:t,f=u?c:0,p=d?l:0;if(n){let e=n(i,{crossAxis:s?f:p,mainAxis:s?p:f});f=s?e.crossAxis:e.mainAxis,p=s?e.mainAxis:e.crossAxis}return{data:{shift:{x:f,y:p}},x:i.x+f,y:i.y+p}}return shiftMiddleware}function size(e={}){function sizeMiddleware(t){let{boundary:n,padding:r}=resolveBoundary(e,t),i=getSide(t.placement),a=n.y+r.top,o=n.x+n.width-r.right,s=n.y+n.height-r.bottom,c=n.x+r.left;return{data:{size:{availableHeight:i===`bottom`?Math.max(0,s-t.y):i===`top`?Math.max(0,t.rects.reference.y-a):Math.max(0,s-a),availableWidth:i===`right`?Math.max(0,o-t.x):i===`left`?Math.max(0,t.rects.reference.x-c):Math.max(0,o-c)}}}}return sizeMiddleware}exports.OrbitConfigError=OrbitConfigError,exports.OrbitError=OrbitError,exports.arrow=arrow,exports.autoPlacement=autoPlacement,exports.autoUpdate=autoUpdate,exports.computePosition=computePosition,exports.createPositioner=createPositioner,exports.detectOverflow=detectOverflow,exports.flip=flip,exports.getAlignment=getAlignment,exports.getBoundaryRect=getBoundaryRect,exports.getClippingAncestorRect=getClippingAncestorRect,exports.getSide=getSide,exports.hide=hide,exports.inline=inline,exports.limitShift=limitShift,exports.offset=offset,exports.shift=shift,exports.size=size;
2
2
  //# sourceMappingURL=orbit.cjs.map