@activecollab/components 2.0.469 → 2.0.470

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 (29) hide show
  1. package/dist/cjs/components/StackedCard/StackedCard.js.map +1 -1
  2. package/dist/cjs/components/StackedCard/Styles.js.map +1 -1
  3. package/dist/cjs/components/StackedCard/resizePolicy.js +141 -60
  4. package/dist/cjs/components/StackedCard/resizePolicy.js.map +1 -1
  5. package/dist/cjs/components/StackedCard/resizePolicy.test.js +362 -15
  6. package/dist/cjs/components/StackedCard/resizePolicy.test.js.map +1 -1
  7. package/dist/cjs/components/StackedCard/useStackedCardResize.js +35 -14
  8. package/dist/cjs/components/StackedCard/useStackedCardResize.js.map +1 -1
  9. package/dist/esm/components/StackedCard/StackedCard.d.ts +5 -5
  10. package/dist/esm/components/StackedCard/StackedCard.d.ts.map +1 -1
  11. package/dist/esm/components/StackedCard/StackedCard.js.map +1 -1
  12. package/dist/esm/components/StackedCard/Styles.d.ts +2 -2
  13. package/dist/esm/components/StackedCard/Styles.d.ts.map +1 -1
  14. package/dist/esm/components/StackedCard/Styles.js.map +1 -1
  15. package/dist/esm/components/StackedCard/resizePolicy.d.ts +85 -40
  16. package/dist/esm/components/StackedCard/resizePolicy.d.ts.map +1 -1
  17. package/dist/esm/components/StackedCard/resizePolicy.js +139 -60
  18. package/dist/esm/components/StackedCard/resizePolicy.js.map +1 -1
  19. package/dist/esm/components/StackedCard/resizePolicy.test.js +359 -16
  20. package/dist/esm/components/StackedCard/resizePolicy.test.js.map +1 -1
  21. package/dist/esm/components/StackedCard/useStackedCardResize.d.ts +25 -13
  22. package/dist/esm/components/StackedCard/useStackedCardResize.d.ts.map +1 -1
  23. package/dist/esm/components/StackedCard/useStackedCardResize.js +35 -14
  24. package/dist/esm/components/StackedCard/useStackedCardResize.js.map +1 -1
  25. package/dist/index.js +179 -74
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.min.js +1 -1
  28. package/dist/index.min.js.map +1 -1
  29. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"resizePolicy.js","names":["DEFAULT_KEYBOARD_STEP","SHIFT_STEP_MULTIPLIER","RESIZE_KEYS","isResizeKey","key","includes","clamp","v","lo","hi","Math","min","Number","POSITIVE_INFINITY","max","snap","step","round","makeStart","size","contentMin","w","h","effectiveBounds","policy","_policy$minW","_policy$minH","_policy$maxW","_policy$maxH","wMin","minW","hMin","minH","wMax","maxW","hMax","maxH","hasFloor","policyMin","undefined","applyResize","start","delta","opts","_effectiveBounds","widthOnly","axis","dx","dy","proportional","constrain","sW","sH","scale","abs","scaleMin","scaleMax","keyboardResize","base","shiftKey","b","apply","jump","_extends","isFinite","measurePercent","_effectiveBounds2"],"sources":["../../../../src/components/StackedCard/resizePolicy.ts"],"sourcesContent":["/**\n * StackedCard resize policy — pure math.\n *\n * The card reports intent; the HOST applies a resize policy (spec §7). This\n * module is that policy, packaged as pure functions so the SAME code path\n * serves the pointer drag and the keyboard resize. Nothing here touches the\n * DOM, React or the card's content: it takes a start size, a delta and a\n * policy, and returns a clamped size. `useStackedCardResize` wires events to\n * it; the card's intrinsic content minimum is measured by the host and passed\n * in as `contentMin`, so this module knows nothing about heroes or footers.\n *\n * The policy has four parts:\n * - bounds — optional min/max per axis; unset means unbounded.\n * - proportional — lock the aspect ratio captured at the start of the gesture;\n * the scale is clamped by the BINDING axis so the ratio never\n * distorts at a bound.\n * - step — optional grid snap; proportion wins over the grid.\n * - content min — the effective min is max(policyMin, contentMin) per axis,\n * so a card can never be crushed below what its content needs.\n */\n\nexport interface StackedCardSize {\n w: number;\n h: number;\n}\n\n/** The card's intrinsic minimum, measured from its real content. */\nexport interface StackedCardContentMin {\n w: number;\n h: number;\n}\n\nexport interface StackedCardResizePolicy {\n minW?: number;\n maxW?: number;\n minH?: number;\n maxH?: number;\n /** Lock the aspect ratio for the whole gesture. */\n proportional: boolean;\n /** Grid snap increment in px; omitted / 0 means continuous. */\n step?: number;\n}\n\n/** The size captured at the start of a gesture (pointer down or a key press). */\nexport interface StackedCardResizeStart {\n w: number;\n h: number;\n contentMin: StackedCardContentMin;\n}\n\nexport interface StackedCardResizeDelta {\n dx: number;\n dy: number;\n}\n\nexport interface StackedCardResizeBounds {\n wMin: number;\n wMax: number;\n hMin: number;\n hMax: number;\n}\n\n/**\n * `width` locks the vertical axis: an auto-height card takes a width and lets\n * its rows set the height, so the gesture's vertical component is ignored.\n */\nexport type StackedCardResizeAxis = \"both\" | \"width\";\n\n/** Which input drove a resize event. Hosts log undo entries per source. */\nexport type StackedCardResizeSource = \"pointer\" | \"keyboard\";\n\n/** Keyboard resize nudges by the policy step, or this when no step is set. */\nexport const DEFAULT_KEYBOARD_STEP = 8;\n\n/** Shift + arrow resizes by a larger increment (the familiar coarse nudge). */\nexport const SHIFT_STEP_MULTIPLIER = 4;\n\n/** Keys the separator handles; everything else falls through to the browser. */\nexport const RESIZE_KEYS: ReadonlyArray<string> = [\n \"ArrowLeft\",\n \"ArrowRight\",\n \"ArrowUp\",\n \"ArrowDown\",\n \"Home\",\n \"End\",\n];\n\nexport const isResizeKey = (key: string): boolean => RESIZE_KEYS.includes(key);\n\nexport const clamp = (v: number, lo: number, hi?: number): number =>\n Math.min(hi ?? Number.POSITIVE_INFINITY, Math.max(lo, v));\n\nexport const snap = (v: number, step?: number): number =>\n step && step > 0 ? Math.round(v / step) * step : v;\n\nexport const makeStart = (\n size: StackedCardSize,\n contentMin: StackedCardContentMin\n): StackedCardResizeStart => ({\n w: size.w,\n h: size.h,\n contentMin,\n});\n\n/**\n * The effective bounds a size is clamped to: the policy min floored by the\n * content min, and the policy max (unbounded when unset). Independent of any\n * live gesture, so a host can also use it for the aria value and Home/End.\n */\nexport const effectiveBounds = (\n policy: StackedCardResizePolicy,\n contentMin: StackedCardContentMin\n): StackedCardResizeBounds => ({\n wMin: Math.max(policy.minW ?? 0, contentMin.w),\n hMin: Math.max(policy.minH ?? 0, contentMin.h),\n wMax: policy.maxW ?? Number.POSITIVE_INFINITY,\n hMax: policy.maxH ?? Number.POSITIVE_INFINITY,\n});\n\n/**\n * Whether an axis has a floor anyone asked for. `effectiveBounds` reports 0 for\n * an unset minimum — correct as a clamp, but not something Home should jump to:\n * an axis nobody gave a minimum must not collapse to nothing.\n */\nconst hasFloor = (policyMin: number | undefined, contentMin: number): boolean =>\n policyMin !== undefined || contentMin > 0;\n\n/**\n * Apply a delta to the start size under the policy — the single path for both\n * inputs.\n *\n * `constrain` is the transient Shift-to-constrain lock: a free-form policy\n * behaves proportionally for that one gesture; a proportional policy is already\n * locked and ignores it. `axis: \"width\"` drops the gesture's vertical component;\n * the height then holds still in free-form mode, and still follows the ratio in\n * proportional mode (that is what proportional means).\n */\nexport const applyResize = (\n start: StackedCardResizeStart,\n delta: StackedCardResizeDelta,\n policy: StackedCardResizePolicy,\n opts: { constrain?: boolean; axis?: StackedCardResizeAxis } = {}\n): StackedCardSize => {\n const { wMin, hMin, wMax, hMax } = effectiveBounds(policy, start.contentMin);\n const widthOnly = opts.axis === \"width\";\n const dx = delta.dx;\n const dy = widthOnly ? 0 : delta.dy;\n\n // A ratio needs two non-zero sides to be a ratio at all; a width-only card\n // parks a placeholder height, so fall back to free-form rather than dividing\n // by zero.\n const proportional =\n (policy.proportional || opts.constrain === true) &&\n start.w > 0 &&\n start.h > 0;\n\n let w: number;\n let h: number;\n\n if (proportional) {\n // one scale drives both axes; the corner's dominant direction wins, so a\n // vertical drag is as effective as a horizontal one\n const sW = (start.w + dx) / start.w;\n const sH = (start.h + dy) / start.h;\n let scale = Math.abs(sW - 1) >= Math.abs(sH - 1) ? sW : sH;\n\n // step: proportion wins over the grid. Snap through the SCALE (driven off\n // the width edge) so both axes move together and the ratio survives; the\n // grid yields whenever honouring it would cost the ratio.\n if (policy.step) {\n scale = snap(start.w * scale, policy.step) / start.w;\n }\n\n // Then clamp the scale so both axes stay in bounds (the binding constraint):\n // the ratio can never break at a bound — whichever edge is limiting stops\n // both. The clamp comes last on purpose: a bound is a hard stop, so the card\n // sits exactly on it rather than at the nearest grid line inside it.\n const scaleMin = Math.max(wMin / start.w, hMin / start.h);\n const scaleMax = Math.min(wMax / start.w, hMax / start.h);\n scale = clamp(scale, scaleMin, Math.max(scaleMin, scaleMax));\n\n w = start.w * scale;\n h = start.h * scale;\n } else {\n w = clamp(snap(start.w + dx, policy.step), wMin, wMax);\n h = widthOnly\n ? start.h\n : clamp(snap(start.h + dy, policy.step), hMin, hMax);\n }\n\n return { w: Math.round(w), h: Math.round(h) };\n};\n\n/**\n * Translate a resize key into the next size, reusing `applyResize` so the\n * keyboard clamps exactly like the pointer. Arrows nudge by the step (Shift ×4);\n * Home/End jump to the min/max of the allowed range, leaving any axis without\n * that bound where it is. Returns null for a key the handle does not own, and\n * for a vertical key on a width-only card.\n */\nexport const keyboardResize = (\n key: string,\n size: StackedCardSize,\n policy: StackedCardResizePolicy,\n contentMin: StackedCardContentMin,\n opts: { shiftKey?: boolean; axis?: StackedCardResizeAxis } = {}\n): StackedCardSize | null => {\n const widthOnly = opts.axis === \"width\";\n if (widthOnly && (key === \"ArrowUp\" || key === \"ArrowDown\")) return null;\n\n const base =\n policy.step && policy.step > 0 ? policy.step : DEFAULT_KEYBOARD_STEP;\n const step = base * (opts.shiftKey ? SHIFT_STEP_MULTIPLIER : 1);\n const start = makeStart(size, contentMin);\n const b = effectiveBounds(policy, contentMin);\n const apply = (delta: StackedCardResizeDelta): StackedCardSize =>\n applyResize(start, delta, policy, { axis: opts.axis });\n\n /**\n * Home and End are absolute jumps to a bound, not nudges, so they ignore the\n * grid: landing 4px off the minimum because that is where the nearest grid\n * line fell would mean the keyboard could never reach the bound the pointer\n * stops at.\n */\n const jump = (delta: StackedCardResizeDelta): StackedCardSize =>\n applyResize(start, delta, { ...policy, step: 0 }, { axis: opts.axis });\n\n switch (key) {\n case \"ArrowRight\":\n return apply({ dx: step, dy: 0 });\n case \"ArrowLeft\":\n return apply({ dx: -step, dy: 0 });\n case \"ArrowDown\":\n return apply({ dx: 0, dy: step });\n case \"ArrowUp\":\n return apply({ dx: 0, dy: -step });\n case \"Home\":\n // jump to the min corner; an axis with no floor of its own stays put\n return jump({\n dx: hasFloor(policy.minW, contentMin.w) ? b.wMin - size.w : 0,\n dy:\n !widthOnly && hasFloor(policy.minH, contentMin.h)\n ? b.hMin - size.h\n : 0,\n });\n case \"End\":\n // jump to the max corner; an unbounded axis simply doesn't move\n return jump({\n dx: Number.isFinite(b.wMax) ? b.wMax - size.w : 0,\n dy: !widthOnly && Number.isFinite(b.hMax) ? b.hMax - size.h : 0,\n });\n default:\n return null;\n }\n};\n\n/**\n * The handle's `aria-valuenow`: the current size as a percent (0–100) of its\n * allowed range. The corner resizes both axes, but the value must be a single\n * number, so it reports the WIDTH axis — the one axis the fixed-box and the\n * width-only cards share. Returns 0 when the range isn't finite (no max bound).\n */\nexport const measurePercent = (\n size: StackedCardSize,\n policy: StackedCardResizePolicy,\n contentMin: StackedCardContentMin\n): number => {\n const { wMin, wMax } = effectiveBounds(policy, contentMin);\n if (!Number.isFinite(wMax) || wMax <= wMin) return 0;\n return Math.round(clamp(((size.w - wMin) / (wMax - wMin)) * 100, 0, 100));\n};\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;;AAiBA;;AAmBA;AACA;AACA;AACA;;AAGA;;AAGA;AACA,OAAO,MAAMA,qBAAqB,GAAG,CAAC;;AAEtC;AACA,OAAO,MAAMC,qBAAqB,GAAG,CAAC;;AAEtC;AACA,OAAO,MAAMC,WAAkC,GAAG,CAChD,WAAW,EACX,YAAY,EACZ,SAAS,EACT,WAAW,EACX,MAAM,EACN,KAAK,CACN;AAED,OAAO,MAAMC,WAAW,GAAIC,GAAW,IAAcF,WAAW,CAACG,QAAQ,CAACD,GAAG,CAAC;AAE9E,OAAO,MAAME,KAAK,GAAGA,CAACC,CAAS,EAAEC,EAAU,EAAEC,EAA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,UAAiC,KACtB;EACX,MAAA8C,iBAAA,GAAuB3C,eAAe,CAACC,MAAM,EAAEJ,UAAU,CAAC;IAAlDS,IAAI,GAAAqC,iBAAA,CAAJrC,IAAI;IAAEI,IAAI,GAAAiC,iBAAA,CAAJjC,IAAI;EAClB,IAAI,CAACrB,MAAM,CAACoD,QAAQ,CAAC/B,IAAI,CAAC,IAAIA,IAAI,IAAIJ,IAAI,EAAE,OAAO,CAAC;EACpD,OAAOnB,IAAI,CAACO,KAAK,CAACX,KAAK,CAAE,CAACa,IAAI,CAACE,CAAC,GAAGQ,IAAI,KAAKI,IAAI,GAAGJ,IAAI,CAAC,GAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3E,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"resizePolicy.js","names":["RESIZE_ANCHORS","DEFAULT_RESIZE_ANCHOR","DEFAULT_KEYBOARD_STEP","SHIFT_STEP_MULTIPLIER","RESIZE_KEYS","isResizeKey","key","includes","clamp","v","lo","hi","Math","min","Number","POSITIVE_INFINITY","max","snap","step","round","makeStart","box","contentMin","_box$x","_box$y","w","h","x","y","effectiveBounds","policy","_policy$minW","_policy$minH","_policy$maxW","_policy$maxH","wMin","minW","hMin","minH","wMax","maxW","hMax","maxH","hasFloor","policyMin","undefined","anchorSigns","anchor","sx","sy","snapMovingEdge","origin","startLength","length","sign","anchoredOrigin","applyResize","start","delta","opts","_opts$anchor","_effectiveBounds","widthOnly","axis","_anchorSigns","anchorSy","dx","dy","proportional","constrain","sW","sH","drivenByWidth","abs","scale","scaleMin","scaleMax","keyboardResize","_opts$anchor2","_anchorSigns2","horizontalKey","verticalKey","base","shiftKey","b","resizeOpts","apply","jump","growW","growH","_extends","isFinite","measurePercent","size","_effectiveBounds2"],"sources":["../../../../src/components/StackedCard/resizePolicy.ts"],"sourcesContent":["/**\n * Resize policy — pure math, shared by every resizable element.\n *\n * The element reports intent; the HOST applies a resize policy (StackedCard\n * spec §7). This module is that policy, packaged as pure functions so the SAME\n * code path serves the pointer drag and the keyboard resize, a card's single\n * bottom-right grip and a shape's eight handles. Nothing here touches the DOM,\n * React or the element's content: it takes a start box, a delta, a policy and\n * the handle being dragged, and returns a clamped box — size AND position.\n * `useStackedCardResize` wires events to it; an element's intrinsic content\n * minimum is measured by the host and passed in as `contentMin`, so this module\n * knows nothing about heroes or footers.\n *\n * The policy has four parts:\n * - bounds — optional min/max per axis; unset means unbounded.\n * - proportional — lock the aspect ratio captured at the start of the gesture;\n * the scale is clamped by the BINDING axis so the ratio never\n * distorts at a bound.\n * - step — optional grid snap; proportion wins over the grid.\n * - content min — the effective min is max(policyMin, contentMin) per axis,\n * so an element can never be crushed below what its content\n * needs.\n *\n * The anchor is the handle being dragged. The edge or corner OPPOSITE to it\n * never moves — not while the pointer travels, and not when a bound stops the\n * resize — which is what makes a resize feel like a resize rather than a nudge.\n * A `left` handle moves the position by exactly the amount the width grew; a\n * `right` handle leaves it alone. An edge handle touches one axis only.\n */\n\nexport interface ResizeSize {\n w: number;\n h: number;\n}\n\nexport interface ResizePosition {\n x: number;\n y: number;\n}\n\n/** A resized element: its size and where its top-left corner now sits. */\nexport interface ResizeBox extends ResizeSize, ResizePosition {}\n\n/** The element's intrinsic minimum, measured from its real content. */\nexport interface ResizeContentMin {\n w: number;\n h: number;\n}\n\nexport interface ResizePolicy {\n minW?: number;\n maxW?: number;\n minH?: number;\n maxH?: number;\n /** Lock the aspect ratio for the whole gesture. */\n proportional: boolean;\n /** Grid snap increment in px; omitted / 0 means continuous. */\n step?: number;\n}\n\n/**\n * The handle being dragged, named after the edge or corner it sits on. The\n * opposite edge or corner is held in place.\n */\nexport type ResizeAnchor =\n | \"top-left\"\n | \"top\"\n | \"top-right\"\n | \"right\"\n | \"bottom-right\"\n | \"bottom\"\n | \"bottom-left\"\n | \"left\";\n\nexport const RESIZE_ANCHORS: ReadonlyArray<ResizeAnchor> = [\n \"top-left\",\n \"top\",\n \"top-right\",\n \"right\",\n \"bottom-right\",\n \"bottom\",\n \"bottom-left\",\n \"left\",\n];\n\n/** A card's single grip: the top-left corner stays put. */\nexport const DEFAULT_RESIZE_ANCHOR: ResizeAnchor = \"bottom-right\";\n\n/**\n * The box captured at the start of a gesture (pointer down or a key press).\n * A host that only tracks a size leaves the position at the origin.\n */\nexport interface ResizeStart extends ResizeBox {\n contentMin: ResizeContentMin;\n}\n\nexport interface ResizeDelta {\n dx: number;\n dy: number;\n}\n\nexport interface ResizeBounds {\n wMin: number;\n wMax: number;\n hMin: number;\n hMax: number;\n}\n\n/**\n * `width` locks the vertical axis: an auto-height card takes a width and lets\n * its rows set the height, so the gesture's vertical component is ignored.\n */\nexport type ResizeAxis = \"both\" | \"width\";\n\n/** Which input drove a resize event. Hosts log undo entries per source. */\nexport type ResizeSource = \"pointer\" | \"keyboard\";\n\nexport interface ResizeOptions {\n /** Shift-to-constrain: one gesture behaves proportionally. */\n constrain?: boolean;\n axis?: ResizeAxis;\n /** The handle being dragged. Defaults to a card's bottom-right grip. */\n anchor?: ResizeAnchor;\n}\n\n/** Keyboard resize nudges by the policy step, or this when no step is set. */\nexport const DEFAULT_KEYBOARD_STEP = 8;\n\n/** Shift + arrow resizes by a larger increment (the familiar coarse nudge). */\nexport const SHIFT_STEP_MULTIPLIER = 4;\n\n/** Keys the separator handles; everything else falls through to the browser. */\nexport const RESIZE_KEYS: ReadonlyArray<string> = [\n \"ArrowLeft\",\n \"ArrowRight\",\n \"ArrowUp\",\n \"ArrowDown\",\n \"Home\",\n \"End\",\n];\n\nexport const isResizeKey = (key: string): boolean => RESIZE_KEYS.includes(key);\n\nexport const clamp = (v: number, lo: number, hi?: number): number =>\n Math.min(hi ?? Number.POSITIVE_INFINITY, Math.max(lo, v));\n\nexport const snap = (v: number, step?: number): number =>\n step && step > 0 ? Math.round(v / step) * step : v;\n\nexport const makeStart = (\n box: ResizeSize & Partial<ResizePosition>,\n contentMin: ResizeContentMin\n): ResizeStart => ({\n w: box.w,\n h: box.h,\n x: box.x ?? 0,\n y: box.y ?? 0,\n contentMin,\n});\n\n/**\n * The effective bounds a size is clamped to: the policy min floored by the\n * content min, and the policy max (unbounded when unset). Independent of any\n * live gesture, so a host can also use it for the aria value and Home/End.\n */\nexport const effectiveBounds = (\n policy: ResizePolicy,\n contentMin: ResizeContentMin\n): ResizeBounds => ({\n wMin: Math.max(policy.minW ?? 0, contentMin.w),\n hMin: Math.max(policy.minH ?? 0, contentMin.h),\n wMax: policy.maxW ?? Number.POSITIVE_INFINITY,\n hMax: policy.maxH ?? Number.POSITIVE_INFINITY,\n});\n\n/**\n * Whether an axis has a floor anyone asked for. `effectiveBounds` reports 0 for\n * an unset minimum — correct as a clamp, but not something Home should jump to:\n * an axis nobody gave a minimum must not collapse to nothing.\n */\nconst hasFloor = (policyMin: number | undefined, contentMin: number): boolean =>\n policyMin !== undefined || contentMin > 0;\n\ntype AxisSign = -1 | 0 | 1;\n\n/**\n * Which way each axis grows for a handle: +1 when the handle is on the far\n * edge (right/bottom), −1 when it is on the near edge (left/top), 0 when the\n * handle does not touch that axis at all.\n */\nexport const anchorSigns = (\n anchor: ResizeAnchor\n): { sx: AxisSign; sy: AxisSign } => ({\n sx: anchor.includes(\"left\") ? -1 : anchor.includes(\"right\") ? 1 : 0,\n sy: anchor.includes(\"top\") ? -1 : anchor.includes(\"bottom\") ? 1 : 0,\n});\n\n/**\n * Snap the MOVING edge of one axis to the grid and return the length that\n * leaves the anchored edge exactly where it was. A far-edge handle snaps\n * `origin + length`; a near-edge handle snaps `origin + startLength − length`.\n * With no step this is the identity.\n */\nconst snapMovingEdge = (\n origin: number,\n startLength: number,\n length: number,\n sign: AxisSign,\n step?: number\n): number => {\n if (!step || sign === 0) return length;\n return sign > 0\n ? snap(origin + length, step) - origin\n : origin + startLength - snap(origin + startLength - length, step);\n};\n\n/** The position that keeps the anchored edge of one axis in place. */\nconst anchoredOrigin = (\n origin: number,\n startLength: number,\n length: number,\n sign: AxisSign\n): number => (sign < 0 ? origin + startLength - length : origin);\n\n/**\n * Apply a delta to the start box under the policy — the single path for both\n * inputs and for every handle.\n *\n * `constrain` is the transient Shift-to-constrain lock: a free-form policy\n * behaves proportionally for that one gesture; a proportional policy is already\n * locked and ignores it. `axis: \"width\"` drops the gesture's vertical component;\n * the height then holds still in free-form mode, and still follows the ratio in\n * proportional mode (that is what proportional means). `anchor` is the handle\n * being dragged: the opposite edge or corner is held, so the returned position\n * moves only when a near-edge handle (left/top) grew or shrank the box.\n */\nexport const applyResize = (\n start: ResizeStart,\n delta: ResizeDelta,\n policy: ResizePolicy,\n opts: ResizeOptions = {}\n): ResizeBox => {\n const { wMin, hMin, wMax, hMax } = effectiveBounds(policy, start.contentMin);\n const widthOnly = opts.axis === \"width\";\n const { sx, sy: anchorSy } = anchorSigns(\n opts.anchor ?? DEFAULT_RESIZE_ANCHOR\n );\n const sy: AxisSign = widthOnly ? 0 : anchorSy;\n const dx = sx * delta.dx;\n const dy = sy * delta.dy;\n\n // A ratio needs two non-zero sides to be a ratio at all; a width-only card\n // parks a placeholder height, so fall back to free-form rather than dividing\n // by zero.\n const proportional =\n (policy.proportional || opts.constrain === true) &&\n start.w > 0 &&\n start.h > 0;\n\n let w: number;\n let h: number;\n\n if (proportional) {\n // one scale drives both axes; the corner's dominant direction wins, so a\n // vertical drag is as effective as a horizontal one. An edge handle has\n // only its own axis to drive with.\n const sW = sx === 0 ? 1 : (start.w + dx) / start.w;\n const sH = sy === 0 ? 1 : (start.h + dy) / start.h;\n const drivenByWidth =\n sx !== 0 && (sy === 0 || Math.abs(sW - 1) >= Math.abs(sH - 1));\n let scale = drivenByWidth ? sW : sH;\n\n // step: proportion wins over the grid. Snap through the SCALE, driven off\n // the moving edge of the driving axis, so both axes move together and the\n // ratio survives; the grid yields whenever honouring it would cost the\n // ratio.\n if (policy.step) {\n scale = drivenByWidth\n ? snapMovingEdge(start.x, start.w, start.w * scale, sx, policy.step) /\n start.w\n : snapMovingEdge(start.y, start.h, start.h * scale, sy, policy.step) /\n start.h;\n }\n\n // Then clamp the scale so both axes stay in bounds (the binding constraint):\n // the ratio can never break at a bound — whichever edge is limiting stops\n // both. The clamp comes last on purpose: a bound is a hard stop, so the\n // element sits exactly on it rather than at the nearest grid line inside it.\n const scaleMin = Math.max(wMin / start.w, hMin / start.h);\n const scaleMax = Math.min(wMax / start.w, hMax / start.h);\n scale = clamp(scale, scaleMin, Math.max(scaleMin, scaleMax));\n\n w = start.w * scale;\n h = start.h * scale;\n } else {\n // An axis the handle does not touch holds its start value exactly — it is\n // neither snapped nor clamped, because nothing about it changed.\n w =\n sx === 0\n ? start.w\n : clamp(\n snapMovingEdge(start.x, start.w, start.w + dx, sx, policy.step),\n wMin,\n wMax\n );\n h =\n sy === 0\n ? start.h\n : clamp(\n snapMovingEdge(start.y, start.h, start.h + dy, sy, policy.step),\n hMin,\n hMax\n );\n }\n\n // Round the size first and derive the position from the rounded size, so\n // the anchored edge lands on exactly the coordinate it started at.\n w = Math.round(w);\n h = Math.round(h);\n\n return {\n w,\n h,\n x: anchoredOrigin(start.x, start.w, w, sx),\n y: anchoredOrigin(start.y, start.h, h, sy),\n };\n};\n\n/**\n * Translate a resize key into the next box, reusing `applyResize` so the\n * keyboard clamps exactly like the pointer. Arrows move the HANDLE by the step\n * (Shift ×4) — so on a left handle ArrowLeft grows the element and ArrowRight\n * shrinks it — and Home/End jump the handle to the min/max of the allowed\n * range, leaving any axis without that bound where it is. Returns null for a\n * key the handle does not own: a key on an axis the handle does not touch, or a\n * vertical key on a width-only card.\n */\nexport const keyboardResize = (\n key: string,\n box: ResizeSize & Partial<ResizePosition>,\n policy: ResizePolicy,\n contentMin: ResizeContentMin,\n opts: { shiftKey?: boolean; axis?: ResizeAxis; anchor?: ResizeAnchor } = {}\n): ResizeBox | null => {\n const widthOnly = opts.axis === \"width\";\n const anchor = opts.anchor ?? DEFAULT_RESIZE_ANCHOR;\n const { sx, sy: anchorSy } = anchorSigns(anchor);\n const sy: AxisSign = widthOnly ? 0 : anchorSy;\n const horizontalKey = key === \"ArrowLeft\" || key === \"ArrowRight\";\n const verticalKey = key === \"ArrowUp\" || key === \"ArrowDown\";\n if ((horizontalKey && sx === 0) || (verticalKey && sy === 0)) return null;\n\n const base =\n policy.step && policy.step > 0 ? policy.step : DEFAULT_KEYBOARD_STEP;\n const step = base * (opts.shiftKey ? SHIFT_STEP_MULTIPLIER : 1);\n const start = makeStart(box, contentMin);\n const b = effectiveBounds(policy, contentMin);\n const resizeOpts: ResizeOptions = { axis: opts.axis, anchor };\n const apply = (delta: ResizeDelta): ResizeBox =>\n applyResize(start, delta, policy, resizeOpts);\n\n /**\n * Home and End are absolute jumps to a bound, not nudges, so they ignore the\n * grid: landing 4px off the minimum because that is where the nearest grid\n * line fell would mean the keyboard could never reach the bound the pointer\n * stops at. The jump is expressed as handle travel, so a near-edge handle\n * moves the opposite way to reach the same size.\n */\n const jump = (growW: number, growH: number): ResizeBox =>\n applyResize(\n start,\n { dx: sx * growW, dy: sy * growH },\n { ...policy, step: 0 },\n resizeOpts\n );\n\n switch (key) {\n case \"ArrowRight\":\n return apply({ dx: step, dy: 0 });\n case \"ArrowLeft\":\n return apply({ dx: -step, dy: 0 });\n case \"ArrowDown\":\n return apply({ dx: 0, dy: step });\n case \"ArrowUp\":\n return apply({ dx: 0, dy: -step });\n case \"Home\":\n // jump to the min corner; an axis with no floor of its own stays put\n return jump(\n sx !== 0 && hasFloor(policy.minW, contentMin.w) ? b.wMin - box.w : 0,\n sy !== 0 && hasFloor(policy.minH, contentMin.h) ? b.hMin - box.h : 0\n );\n case \"End\":\n // jump to the max corner; an unbounded axis simply doesn't move\n return jump(\n sx !== 0 && Number.isFinite(b.wMax) ? b.wMax - box.w : 0,\n sy !== 0 && Number.isFinite(b.hMax) ? b.hMax - box.h : 0\n );\n default:\n return null;\n }\n};\n\n/**\n * The handle's `aria-valuenow`: the current size as a percent (0–100) of its\n * allowed range. The corner resizes both axes, but the value must be a single\n * number, so it reports the WIDTH axis — the one axis the fixed-box and the\n * width-only cards share. Returns 0 when the range isn't finite (no max bound).\n */\nexport const measurePercent = (\n size: ResizeSize,\n policy: ResizePolicy,\n contentMin: ResizeContentMin\n): number => {\n const { wMin, wMax } = effectiveBounds(policy, contentMin);\n if (!Number.isFinite(wMax) || wMax <= wMin) return 0;\n return Math.round(clamp(((size.w - wMin) / (wMax - wMin)) * 100, 0, 100));\n};\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;;AAGA;;AAiBA;AACA;AACA;AACA;;AAWA,OAAO,MAAMA,cAA2C,GAAG,CACzD,UAAU,EACV,KAAK,EACL,WAAW,EACX,OAAO,EACP,cAAc,EACd,QAAQ,EACR,aAAa,EACb,MAAM,CACP;;AAED;AACA,OAAO,MAAMC,qBAAmC,GAAG,cAAc;;AAEjE;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;;AAGA;;AAWA;AACA,OAAO,MAAMC,qBAAqB,GAAG,CAAC;;AAEtC;AACA,OAAO,MAAMC,qBAAqB,GAAG,CAAC;;AAEtC;AACA,OAAO,MAAMC,WAAkC,GAAG,CAChD,WAAW,EACX,YAAY,EACZ,SAAS,EACT,WAAW,EACX,MAAM,EACN,KAAK,CACN;AAED,OAAO,MAAMC,WAAW,GAAIC,GAAW,IAAcF,WAAW,CAACG,QAAQ,CAACD,GAAG,CAAC;AAE9E,OAAO,MAAME,KAAK,GAAGA,CAACC,CAAS,EAAEC,EAAU,EAAEC,EAAW,KACtDC,IAAI,CAACC,GAAG,CAACF,EAAE,WAAFA,EAAE,GAAIG,MAAM,CAACC,iBAAiB,EAAEH,IAAI,CAACI,GAAG,CAACN,EAAE,EAAED,CAAC,CAAC,CAAC;AAE3D,OAAO,MAAMQ,IAAI,GAAGA,CAACR,CAAS,EAAES,IAAa,KAC3CA,IAAI,IAAIA,IAAI,GAAG,CAAC,GA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KAAK,CAAC,IAAInC,MAAM,CAAC6E,QAAQ,CAACP,CAAC,CAAC3C,IAAI,CAAC,GAAG2C,CAAC,CAAC3C,IAAI,GAAGpB,GAAG,CAACK,CAAC,GAAG,CACzD,CAAC;IACH;MACE,OAAO,IAAI;EACf;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMkE,cAAc,GAAGA,CAC5BC,IAAgB,EAChB/D,MAAoB,EACpBR,UAA4B,KACjB;EACX,MAAAwE,iBAAA,GAAuBjE,eAAe,CAACC,MAAM,EAAER,UAAU,CAAC;IAAlDa,IAAI,GAAA2D,iBAAA,CAAJ3D,IAAI;IAAEI,IAAI,GAAAuD,iBAAA,CAAJvD,IAAI;EAClB,IAAI,CAACzB,MAAM,CAAC6E,QAAQ,CAACpD,IAAI,CAAC,IAAIA,IAAI,IAAIJ,IAAI,EAAE,OAAO,CAAC;EACpD,OAAOvB,IAAI,CAACO,KAAK,CAACX,KAAK,CAAE,CAACqF,IAAI,CAACpE,CAAC,GAAGU,IAAI,KAAKI,IAAI,GAAGJ,IAAI,CAAC,GAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3E,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { DEFAULT_KEYBOARD_STEP, RESIZE_KEYS, SHIFT_STEP_MULTIPLIER, applyResize, clamp, effectiveBounds, isResizeKey, keyboardResize, makeStart, measurePercent, snap } from "./resizePolicy";
2
+ import { DEFAULT_KEYBOARD_STEP, RESIZE_ANCHORS, RESIZE_KEYS, SHIFT_STEP_MULTIPLIER, anchorSigns, applyResize, clamp, effectiveBounds, isResizeKey, keyboardResize, makeStart, measurePercent, snap } from "./resizePolicy";
3
3
  const FREE = {
4
4
  proportional: false
5
5
  };
@@ -164,7 +164,7 @@ describe("applyResize — proportional", () => {
164
164
  expect(applyResize(proportionalStart, {
165
165
  dx: +400,
166
166
  dy: 0
167
- }, policy)).toEqual({
167
+ }, policy)).toMatchObject({
168
168
  w: 620,
169
169
  h: 413
170
170
  });
@@ -174,7 +174,7 @@ describe("applyResize — proportional", () => {
174
174
  expect(applyResize(proportionalStart, {
175
175
  dx: -400,
176
176
  dy: 0
177
- }, policy)).toEqual({
177
+ }, policy)).toMatchObject({
178
178
  w: 108,
179
179
  h: 72
180
180
  });
@@ -189,7 +189,7 @@ describe("applyResize — proportional", () => {
189
189
  expect(applyResize(start(300, 200), {
190
190
  dx: 0,
191
191
  dy: +100
192
- }, free)).toEqual({
192
+ }, free)).toMatchObject({
193
193
  w: 450,
194
194
  h: 300
195
195
  });
@@ -211,7 +211,7 @@ describe("applyResize — proportional", () => {
211
211
  }, policy);
212
212
 
213
213
  // 337 snaps to 336, and the height follows the same scale.
214
- expect(result).toEqual({
214
+ expect(result).toMatchObject({
215
215
  w: 336,
216
216
  h: 224
217
217
  });
@@ -245,7 +245,7 @@ describe("applyResize — shift to constrain", () => {
245
245
  });
246
246
 
247
247
  // 1.5× on both axes, from a purely horizontal drag.
248
- expect(result).toEqual({
248
+ expect(result).toMatchObject({
249
249
  w: 450,
250
250
  h: 300
251
251
  });
@@ -254,7 +254,7 @@ describe("applyResize — shift to constrain", () => {
254
254
  expect(applyResize(start(300, 200), {
255
255
  dx: +150,
256
256
  dy: 0
257
- }, FREE)).toEqual({
257
+ }, FREE)).toMatchObject({
258
258
  w: 450,
259
259
  h: 200
260
260
  });
@@ -269,7 +269,7 @@ describe("applyResize — shift to constrain", () => {
269
269
  };
270
270
  expect(applyResize(start(300, 200), delta, policy, {
271
271
  constrain: true
272
- })).toEqual(applyResize(start(300, 200), delta, policy));
272
+ })).toMatchObject(applyResize(start(300, 200), delta, policy));
273
273
  });
274
274
  });
275
275
  describe("applyResize — width-only axis", () => {
@@ -294,7 +294,7 @@ describe("applyResize — width-only axis", () => {
294
294
  }, policy, {
295
295
  axis: "width"
296
296
  });
297
- expect(result).toEqual({
297
+ expect(result).toMatchObject({
298
298
  w: 216,
299
299
  h: 240
300
300
  });
@@ -310,7 +310,7 @@ describe("applyResize — width-only axis", () => {
310
310
  }, {
311
311
  axis: "width"
312
312
  });
313
- expect(result).toEqual({
313
+ expect(result).toMatchObject({
314
314
  w: 450,
315
315
  h: 300
316
316
  });
@@ -361,11 +361,11 @@ describe("keyboardResize", () => {
361
361
  })) == null ? void 0 : _keyboardResize7.w).toBe(180);
362
362
  });
363
363
  it("jumps to the minimum on Home and the maximum on End", () => {
364
- expect(keyboardResize("Home", size, policy, contentMin)).toEqual({
364
+ expect(keyboardResize("Home", size, policy, contentMin)).toMatchObject({
365
365
  w: 180,
366
366
  h: 120
367
367
  });
368
- expect(keyboardResize("End", size, policy, contentMin)).toEqual({
368
+ expect(keyboardResize("End", size, policy, contentMin)).toMatchObject({
369
369
  w: 420,
370
370
  h: 400
371
371
  });
@@ -379,7 +379,7 @@ describe("keyboardResize", () => {
379
379
  expect(keyboardResize("End", size, unbounded, {
380
380
  w: 180,
381
381
  h: 0
382
- })).toEqual({
382
+ })).toMatchObject({
383
383
  w: 420,
384
384
  h: 200
385
385
  });
@@ -390,7 +390,7 @@ describe("keyboardResize", () => {
390
390
  expect(keyboardResize("Home", size, FREE, {
391
391
  w: 0,
392
392
  h: 0
393
- })).toEqual(size);
393
+ })).toMatchObject(size);
394
394
  });
395
395
  it("ignores the vertical keys on a width-only card", () => {
396
396
  expect(keyboardResize("ArrowUp", size, policy, contentMin, {
@@ -403,13 +403,13 @@ describe("keyboardResize", () => {
403
403
  it("holds the height on a width-only Home and End", () => {
404
404
  expect(keyboardResize("Home", size, policy, contentMin, {
405
405
  axis: "width"
406
- })).toEqual({
406
+ })).toMatchObject({
407
407
  w: 180,
408
408
  h: 200
409
409
  });
410
410
  expect(keyboardResize("End", size, policy, contentMin, {
411
411
  axis: "width"
412
- })).toEqual({
412
+ })).toMatchObject({
413
413
  w: 420,
414
414
  h: 200
415
415
  });
@@ -467,4 +467,347 @@ describe("measurePercent", () => {
467
467
  }, FREE, contentMin)).toBe(0);
468
468
  });
469
469
  });
470
+ describe("applyResize — anchors", () => {
471
+ /* The worked examples from the task: the edge or corner OPPOSITE to the
472
+ dragged handle never moves, including when a bound stops the resize. */
473
+ const box = makeStart({
474
+ x: 100,
475
+ y: 100,
476
+ w: 300,
477
+ h: 200
478
+ }, {
479
+ w: 0,
480
+ h: 0
481
+ });
482
+ const right = b => b.x + b.w;
483
+ const bottom = b => b.y + b.h;
484
+ it("defaults to the bottom-right grip and leaves the position where it was", () => {
485
+ expect(applyResize(box, {
486
+ dx: 40,
487
+ dy: 30
488
+ }, FREE)).toEqual({
489
+ w: 340,
490
+ h: 230,
491
+ x: 100,
492
+ y: 100
493
+ });
494
+ });
495
+ it("grows up and left from the top-left handle and moves x and y by the growth", () => {
496
+ expect(applyResize(box, {
497
+ dx: -40,
498
+ dy: -30
499
+ }, FREE, {
500
+ anchor: "top-left"
501
+ })).toEqual({
502
+ w: 340,
503
+ h: 230,
504
+ x: 60,
505
+ y: 70
506
+ });
507
+ });
508
+ it.each(RESIZE_ANCHORS)("holds the edge opposite to the %s handle while it grows", anchor => {
509
+ const _anchorSigns = anchorSigns(anchor),
510
+ sx = _anchorSigns.sx,
511
+ sy = _anchorSigns.sy;
512
+ const result = applyResize(box, {
513
+ dx: 50 * sx,
514
+ dy: 40 * sy
515
+ }, FREE, {
516
+ anchor
517
+ });
518
+ if (sx < 0) expect(right(result)).toBe(right(box));
519
+ if (sx > 0) expect(result.x).toBe(box.x);
520
+ if (sy < 0) expect(bottom(result)).toBe(bottom(box));
521
+ if (sy > 0) expect(result.y).toBe(box.y);
522
+ expect(result.w).toBe(sx === 0 ? 300 : 350);
523
+ expect(result.h).toBe(sy === 0 ? 200 : 240);
524
+ });
525
+ it("keeps the anchored edge in place when a bound stops the resize", () => {
526
+ const result = applyResize(box, {
527
+ dx: 150,
528
+ dy: 0
529
+ }, {
530
+ minW: 200,
531
+ proportional: false
532
+ }, {
533
+ anchor: "top-left"
534
+ });
535
+
536
+ // width wants 150, clamped up to 200; the right edge stays at 400, not 350
537
+ expect(result).toEqual({
538
+ w: 200,
539
+ h: 200,
540
+ x: 200,
541
+ y: 100
542
+ });
543
+ });
544
+ it("follows the ratio and the position when a proportional element hits its ceiling", () => {
545
+ const circle = makeStart({
546
+ x: 100,
547
+ y: 100,
548
+ w: 200,
549
+ h: 200
550
+ }, {
551
+ w: 0,
552
+ h: 0
553
+ });
554
+ const result = applyResize(circle, {
555
+ dx: -400,
556
+ dy: 0
557
+ }, {
558
+ maxW: 300,
559
+ maxH: 300,
560
+ proportional: true
561
+ }, {
562
+ anchor: "top-left"
563
+ });
564
+
565
+ // scale wants 3.0; scaleMax = 1.5 → 300×300 with the bottom-right corner held at (300, 300)
566
+ expect(result).toEqual({
567
+ w: 300,
568
+ h: 300,
569
+ x: 0,
570
+ y: 0
571
+ });
572
+ });
573
+ it("touches only the width from a right or left edge handle", () => {
574
+ expect(applyResize(box, {
575
+ dx: 40,
576
+ dy: 999
577
+ }, FREE, {
578
+ anchor: "right"
579
+ })).toEqual({
580
+ w: 340,
581
+ h: 200,
582
+ x: 100,
583
+ y: 100
584
+ });
585
+ expect(applyResize(box, {
586
+ dx: -40,
587
+ dy: 999
588
+ }, FREE, {
589
+ anchor: "left"
590
+ })).toEqual({
591
+ w: 340,
592
+ h: 200,
593
+ x: 60,
594
+ y: 100
595
+ });
596
+ });
597
+ it("touches only the height from a top or bottom edge handle", () => {
598
+ expect(applyResize(box, {
599
+ dx: 999,
600
+ dy: 30
601
+ }, FREE, {
602
+ anchor: "bottom"
603
+ })).toEqual({
604
+ w: 300,
605
+ h: 230,
606
+ x: 100,
607
+ y: 100
608
+ });
609
+ expect(applyResize(box, {
610
+ dx: 999,
611
+ dy: -30
612
+ }, FREE, {
613
+ anchor: "top"
614
+ })).toEqual({
615
+ w: 300,
616
+ h: 230,
617
+ x: 100,
618
+ y: 70
619
+ });
620
+ });
621
+ it("leaves an untouched axis alone even when it sits off the grid or outside the bounds", () => {
622
+ const odd = makeStart({
623
+ x: 100,
624
+ y: 100,
625
+ w: 303,
626
+ h: 10
627
+ }, {
628
+ w: 0,
629
+ h: 0
630
+ });
631
+ const result = applyResize(odd, {
632
+ dx: 0,
633
+ dy: 40
634
+ }, {
635
+ minH: 20,
636
+ proportional: false,
637
+ step: 8
638
+ }, {
639
+ anchor: "bottom"
640
+ });
641
+ expect(result.w).toBe(303);
642
+ // the bottom edge 110 + 40 = 150 snaps to 152
643
+ expect(result.h).toBe(52);
644
+ });
645
+ it("snaps the moving edge to the grid and leaves the anchored edge off it", () => {
646
+ const offGrid = makeStart({
647
+ x: 103,
648
+ y: 101,
649
+ w: 300,
650
+ h: 200
651
+ }, {
652
+ w: 0,
653
+ h: 0
654
+ });
655
+ const step = {
656
+ proportional: false,
657
+ step: 8
658
+ };
659
+
660
+ // right handle: the right edge 403 + 37 = 440 is on the grid already; 403 + 35 = 438 → 440
661
+ expect(applyResize(offGrid, {
662
+ dx: 35,
663
+ dy: 0
664
+ }, step, {
665
+ anchor: "right"
666
+ })).toEqual({
667
+ w: 337,
668
+ h: 200,
669
+ x: 103,
670
+ y: 101
671
+ });
672
+ // left handle: the left edge 103 − 35 = 68 → 72; the right edge stays at 403
673
+ expect(applyResize(offGrid, {
674
+ dx: -35,
675
+ dy: 0
676
+ }, step, {
677
+ anchor: "left"
678
+ })).toEqual({
679
+ w: 331,
680
+ h: 200,
681
+ x: 72,
682
+ y: 101
683
+ });
684
+ });
685
+ it("snaps a proportional resize through the moving edge of the driving axis", () => {
686
+ const offGrid = makeStart({
687
+ x: 103,
688
+ y: 100,
689
+ w: 300,
690
+ h: 200
691
+ }, {
692
+ w: 0,
693
+ h: 0
694
+ });
695
+ const result = applyResize(offGrid, {
696
+ dx: -35,
697
+ dy: 0
698
+ }, {
699
+ proportional: true,
700
+ step: 8
701
+ }, {
702
+ anchor: "left"
703
+ });
704
+
705
+ // the left edge lands on 72, so the width is 331 and the height follows the ratio
706
+ expect(result.x).toBe(72);
707
+ expect(result.w).toBe(331);
708
+ expect(result.h).toBe(Math.round(200 * 331 / 300));
709
+ expect(right(result)).toBe(403);
710
+ });
711
+ it("holds the ratio from an edge handle by driving the scale off that handle's axis", () => {
712
+ const result = applyResize(box, {
713
+ dx: 999,
714
+ dy: 100
715
+ }, {
716
+ proportional: true
717
+ }, {
718
+ anchor: "bottom"
719
+ });
720
+
721
+ // +100 on a 200-tall element is 1.5×; the horizontal travel is ignored
722
+ expect(result).toEqual({
723
+ w: 450,
724
+ h: 300,
725
+ x: 100,
726
+ y: 100
727
+ });
728
+ });
729
+ });
730
+ describe("keyboardResize — anchors", () => {
731
+ const policy = {
732
+ minW: 180,
733
+ maxW: 420,
734
+ minH: 120,
735
+ maxH: 400,
736
+ proportional: false
737
+ };
738
+ const none = {
739
+ w: 0,
740
+ h: 0
741
+ };
742
+ const box = {
743
+ w: 300,
744
+ h: 200,
745
+ x: 100,
746
+ y: 100
747
+ };
748
+ it("moves the handle: ArrowLeft grows a left handle and shrinks a right one", () => {
749
+ expect(keyboardResize("ArrowLeft", box, policy, none, {
750
+ anchor: "left"
751
+ })).toEqual({
752
+ w: 308,
753
+ h: 200,
754
+ x: 92,
755
+ y: 100
756
+ });
757
+ expect(keyboardResize("ArrowLeft", box, policy, none, {
758
+ anchor: "right"
759
+ })).toEqual({
760
+ w: 292,
761
+ h: 200,
762
+ x: 100,
763
+ y: 100
764
+ });
765
+ });
766
+ it("moves the position with an arrow press on the top-left handle", () => {
767
+ expect(keyboardResize("ArrowUp", box, policy, none, {
768
+ anchor: "top-left"
769
+ })).toEqual({
770
+ w: 300,
771
+ h: 208,
772
+ x: 100,
773
+ y: 92
774
+ });
775
+ });
776
+ it("returns null for a key on an axis the handle does not touch", () => {
777
+ expect(keyboardResize("ArrowUp", box, policy, none, {
778
+ anchor: "right"
779
+ })).toBeNull();
780
+ expect(keyboardResize("ArrowLeft", box, policy, none, {
781
+ anchor: "bottom"
782
+ })).toBeNull();
783
+ });
784
+ it("jumps a near-edge handle to the bounds while holding the far edge", () => {
785
+ expect(keyboardResize("Home", box, policy, none, {
786
+ anchor: "top-left"
787
+ })).toEqual({
788
+ w: 180,
789
+ h: 120,
790
+ x: 220,
791
+ y: 180
792
+ });
793
+ expect(keyboardResize("End", box, policy, none, {
794
+ anchor: "top-left"
795
+ })).toEqual({
796
+ w: 420,
797
+ h: 400,
798
+ x: -20,
799
+ y: -100
800
+ });
801
+ });
802
+ it("jumps only the handle's own axis on an edge handle", () => {
803
+ expect(keyboardResize("End", box, policy, none, {
804
+ anchor: "left"
805
+ })).toEqual({
806
+ w: 420,
807
+ h: 200,
808
+ x: -20,
809
+ y: 100
810
+ });
811
+ });
812
+ });
470
813
  //# sourceMappingURL=resizePolicy.test.js.map