@g9tm/lynxcontrols-studio 0.0.0-stage → 2.8.1

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 (76) hide show
  1. package/README.md +184 -2
  2. package/catalog/cards/G9NleTimeline.md +17 -0
  3. package/catalog/cards/G9Surface.md +16 -0
  4. package/catalog/cards/G9TransformBox.md +17 -0
  5. package/catalog/catalog.json +2255 -0
  6. package/catalog/index.md +7 -0
  7. package/dist/.tsbuildinfo +1 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.jsx +3 -0
  11. package/dist/nle-timeline/core.d.ts +5 -0
  12. package/dist/nle-timeline/core.d.ts.map +1 -0
  13. package/dist/nle-timeline/core.js +4 -0
  14. package/dist/nle-timeline/core.jsx +4 -0
  15. package/dist/nle-timeline/edits.d.ts +65 -0
  16. package/dist/nle-timeline/edits.d.ts.map +1 -0
  17. package/dist/nle-timeline/edits.js +344 -0
  18. package/dist/nle-timeline/edits.js.map +1 -0
  19. package/dist/nle-timeline/edits.jsx +342 -0
  20. package/dist/nle-timeline/engine.d.ts +159 -0
  21. package/dist/nle-timeline/engine.d.ts.map +1 -0
  22. package/dist/nle-timeline/engine.js +899 -0
  23. package/dist/nle-timeline/engine.js.map +1 -0
  24. package/dist/nle-timeline/engine.jsx +897 -0
  25. package/dist/nle-timeline/index.d.ts +6 -0
  26. package/dist/nle-timeline/index.d.ts.map +1 -0
  27. package/dist/nle-timeline/index.jsx +5 -0
  28. package/dist/nle-timeline/layout.d.ts +116 -0
  29. package/dist/nle-timeline/layout.d.ts.map +1 -0
  30. package/dist/nle-timeline/layout.js +310 -0
  31. package/dist/nle-timeline/layout.js.map +1 -0
  32. package/dist/nle-timeline/layout.jsx +308 -0
  33. package/dist/nle-timeline/model.d.ts +140 -0
  34. package/dist/nle-timeline/model.d.ts.map +1 -0
  35. package/dist/nle-timeline/model.js +155 -0
  36. package/dist/nle-timeline/model.js.map +1 -0
  37. package/dist/nle-timeline/model.jsx +153 -0
  38. package/dist/nle-timeline/nle.d.ts +72 -0
  39. package/dist/nle-timeline/nle.d.ts.map +1 -0
  40. package/dist/nle-timeline/nle.jsx +92 -0
  41. package/dist/surface/core.d.ts +2 -0
  42. package/dist/surface/core.d.ts.map +1 -0
  43. package/dist/surface/core.js +1 -0
  44. package/dist/surface/core.jsx +1 -0
  45. package/dist/surface/index.d.ts +3 -0
  46. package/dist/surface/index.d.ts.map +1 -0
  47. package/dist/surface/index.jsx +2 -0
  48. package/dist/surface/protocol.d.ts +40 -0
  49. package/dist/surface/protocol.d.ts.map +1 -0
  50. package/dist/surface/protocol.js +19 -0
  51. package/dist/surface/protocol.js.map +1 -0
  52. package/dist/surface/protocol.jsx +17 -0
  53. package/dist/surface/surface.d.ts +53 -0
  54. package/dist/surface/surface.d.ts.map +1 -0
  55. package/dist/surface/surface.jsx +62 -0
  56. package/dist/transform-box/core.d.ts +3 -0
  57. package/dist/transform-box/core.d.ts.map +1 -0
  58. package/dist/transform-box/core.js +2 -0
  59. package/dist/transform-box/core.jsx +2 -0
  60. package/dist/transform-box/engine.d.ts +152 -0
  61. package/dist/transform-box/engine.d.ts.map +1 -0
  62. package/dist/transform-box/engine.js +636 -0
  63. package/dist/transform-box/engine.js.map +1 -0
  64. package/dist/transform-box/engine.jsx +634 -0
  65. package/dist/transform-box/geometry.d.ts +129 -0
  66. package/dist/transform-box/geometry.d.ts.map +1 -0
  67. package/dist/transform-box/geometry.js +506 -0
  68. package/dist/transform-box/geometry.js.map +1 -0
  69. package/dist/transform-box/geometry.jsx +504 -0
  70. package/dist/transform-box/index.d.ts +4 -0
  71. package/dist/transform-box/index.d.ts.map +1 -0
  72. package/dist/transform-box/index.jsx +3 -0
  73. package/dist/transform-box/transform-box.d.ts +65 -0
  74. package/dist/transform-box/transform-box.d.ts.map +1 -0
  75. package/dist/transform-box/transform-box.jsx +104 -0
  76. package/package.json +56 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-box/geometry.js","sources":["../../src/transform-box/geometry.ts"],"sourcesContent":["// The transform box's geometry (G9TransformBox): boxes on a stage, the stage fitted into the element with a zoom and a\n// pan, handles, resizing in a box's own (rotated) frame, rotation, and the smart guides (edges, centres, equal\n// spacing, the stage and its safe zones). Pure TypeScript: no DOM, no Intl. It knows boxes, not what is in them.\n\n/** A box on the stage: top-left of the unrotated box, its size, degrees clockwise about its centre. Stage units. */\nexport interface TbBox {\n readonly id: string;\n readonly x: number;\n readonly y: number;\n readonly w: number;\n readonly h: number;\n readonly rotation: number;\n /** Selectable, not movable. */\n readonly locked?: boolean;\n /** Corner handles keep the ratio unless shift; true keeps it on edges too. */\n readonly keepAspect?: boolean;\n}\n\n/** An axis-aligned rectangle (stage units): the stage, a safe zone. */\nexport interface TbRect {\n readonly x: number;\n readonly y: number;\n readonly w: number;\n readonly h: number;\n readonly label?: string;\n}\n\n/** A box by its centre (what resizing and rotation work in). */\nexport interface TbFrame {\n readonly cx: number;\n readonly cy: number;\n readonly w: number;\n readonly h: number;\n readonly rotation: number;\n}\n\n/** Stage → element: `screen = offset + stage × scale`. */\nexport interface TbFit {\n readonly scale: number;\n readonly ox: number;\n readonly oy: number;\n}\n\n/** Axis-aligned bounds (stage units). */\nexport interface TbAabb {\n readonly x0: number;\n readonly y0: number;\n readonly x1: number;\n readonly y1: number;\n}\n\n/** A handle of the selection frame: the eight resize handles by compass point, and `rot`. */\nexport type TbHandle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'rot';\n\n/** Each resize handle's direction from the frame's centre (-1, 0 or 1 per axis). */\nexport const HANDLE_SIGNS: Record<Exclude<TbHandle, 'rot'>, readonly [number, number]> = {\n nw: [-1, -1],\n n: [0, -1],\n ne: [1, -1],\n e: [1, 0],\n se: [1, 1],\n s: [0, 1],\n sw: [-1, 1],\n w: [-1, 0],\n};\n\nconst DEG = Math.PI / 180;\n\n/** The stage fitted inside the element (with padding), then zoomed and panned (CSS px). */\nexport function fitOf(\n stage: { readonly w: number; readonly h: number },\n view: { readonly w: number; readonly h: number },\n zoom: number,\n panX: number,\n panY: number,\n padding = 16,\n): TbFit {\n const base = Math.max(1e-6, Math.min((view.w - padding * 2) / stage.w, (view.h - padding * 2) / stage.h));\n const scale = base * zoom;\n return { scale, ox: (view.w - stage.w * scale) / 2 + panX, oy: (view.h - stage.h * scale) / 2 + panY };\n}\n\n/** Stage units to element px under a fit. */\nexport function toScreen(fit: TbFit, x: number, y: number): [number, number] {\n return [fit.ox + x * fit.scale, fit.oy + y * fit.scale];\n}\n\n/** Element px to stage units under a fit. */\nexport function toStage(fit: TbFit, sx: number, sy: number): [number, number] {\n return [(sx - fit.ox) / fit.scale, (sy - fit.oy) / fit.scale];\n}\n\n/** Rotates a vector by `deg` degrees clockwise (screen axes). */\nexport function rotate(x: number, y: number, deg: number): [number, number] {\n if (!deg) return [x, y];\n const c = Math.cos(deg * DEG);\n const s = Math.sin(deg * DEG);\n return [x * c - y * s, x * s + y * c];\n}\n\n/** A box as a frame: its centre, size and rotation. */\nexport function frameOf(box: TbBox): TbFrame {\n return { cx: box.x + box.w / 2, cy: box.y + box.h / 2, w: box.w, h: box.h, rotation: box.rotation };\n}\n\n/** A frame back as a box with `id`, keeping `from`'s other fields (locked, keepAspect). */\nexport function boxOfFrame(id: string, frame: TbFrame, from?: TbBox): TbBox {\n return {\n ...(from ?? { id }),\n id,\n x: frame.cx - frame.w / 2,\n y: frame.cy - frame.h / 2,\n w: frame.w,\n h: frame.h,\n rotation: frame.rotation,\n };\n}\n\n/** Corners nw, ne, se, sw. */\nexport function cornersOf(frame: TbFrame): [number, number][] {\n const hw = frame.w / 2;\n const hh = frame.h / 2;\n return [\n [-hw, -hh],\n [hw, -hh],\n [hw, hh],\n [-hw, hh],\n ].map(([x, y]) => {\n const [rx, ry] = rotate(x as number, y as number, frame.rotation);\n return [frame.cx + rx, frame.cy + ry] as [number, number];\n });\n}\n\n/** The axis-aligned bounds of rotated frames. */\nexport function aabbOf(frames: readonly TbFrame[]): TbAabb {\n let x0 = Infinity;\n let y0 = Infinity;\n let x1 = -Infinity;\n let y1 = -Infinity;\n for (const f of frames)\n for (const [x, y] of cornersOf(f)) {\n x0 = Math.min(x0, x);\n y0 = Math.min(y0, y);\n x1 = Math.max(x1, x);\n y1 = Math.max(y1, y);\n }\n return { x0, y0, x1, y1 };\n}\n\n/** The frame the handles sit on: a box's own for one, the bounding box for several. */\nexport function selectionFrame(boxes: readonly TbBox[]): TbFrame | null {\n if (!boxes.length) return null;\n if (boxes.length === 1) return frameOf(boxes[0] as TbBox);\n const a = aabbOf(boxes.map(frameOf));\n return { cx: (a.x0 + a.x1) / 2, cy: (a.y0 + a.y1) / 2, w: a.x1 - a.x0, h: a.y1 - a.y0, rotation: 0 };\n}\n\n/** Whether a point lies inside a rotated frame, `slack` stage units around it included. */\nexport function contains(frame: TbFrame, x: number, y: number, slack = 0): boolean {\n const [lx, ly] = rotate(x - frame.cx, y - frame.cy, -frame.rotation);\n return Math.abs(lx) <= frame.w / 2 + slack && Math.abs(ly) <= frame.h / 2 + slack;\n}\n\n/** The top box under a stage point (the last one drawn wins). */\nexport function hitBox(boxes: readonly TbBox[], x: number, y: number, slack = 0): TbBox | null {\n for (let i = boxes.length - 1; i >= 0; i--) {\n const box = boxes[i] as TbBox;\n if (contains(frameOf(box), x, y, slack)) return box;\n }\n return null;\n}\n\n/** Handle positions in element px; the rotation handle sits `rotGap` px above the top edge. */\nexport function handlePoints(frame: TbFrame, fit: TbFit, rotGap = 28): { handle: TbHandle; x: number; y: number }[] {\n const out: { handle: TbHandle; x: number; y: number }[] = [];\n for (const handle of Object.keys(HANDLE_SIGNS) as Exclude<TbHandle, 'rot'>[]) {\n const [hx, hy] = HANDLE_SIGNS[handle];\n const [rx, ry] = rotate((hx * frame.w) / 2, (hy * frame.h) / 2, frame.rotation);\n const [sx, sy] = toScreen(fit, frame.cx + rx, frame.cy + ry);\n out.push({ handle, x: sx, y: sy });\n }\n const [rx, ry] = rotate(0, -frame.h / 2 - rotGap / fit.scale, frame.rotation);\n const [sx, sy] = toScreen(fit, frame.cx + rx, frame.cy + ry);\n out.push({ handle: 'rot', x: sx, y: sy });\n return out;\n}\n\n/** The handle within `radius` px of an element point; edge handles only when the box is big enough on screen. */\nexport function hitHandle(frame: TbFrame, fit: TbFit, x: number, y: number, radius: number): TbHandle | null {\n const small = Math.min(frame.w, frame.h) * fit.scale < radius * 4;\n let best: { handle: TbHandle; d: number } | null = null;\n for (const p of handlePoints(frame, fit)) {\n if (small && p.handle.length === 1) continue;\n const d = Math.hypot(p.x - x, p.y - y);\n if (d <= radius && (!best || d < best.d)) best = { handle: p.handle, d };\n }\n return best?.handle ?? null;\n}\n\n/** How a resize behaves: keep the aspect, scale from the centre, the smallest side. */\nexport interface ResizeOptions {\n readonly keepAspect: boolean;\n readonly fromCenter: boolean;\n /** Smallest side (stage units). */\n readonly min: number;\n}\n\n/** Resizes `start` by dragging `handle` to stage point (x, y), in the frame's own rotated axes. */\nexport function resizeFrame(\n start: TbFrame,\n handle: Exclude<TbHandle, 'rot'>,\n x: number,\n y: number,\n o: ResizeOptions,\n): TbFrame {\n const [hx, hy] = HANDLE_SIGNS[handle];\n const [px, py] = rotate(x - start.cx, y - start.cy, -start.rotation);\n const ax = o.fromCenter ? 0 : (-hx * start.w) / 2;\n const ay = o.fromCenter ? 0 : (-hy * start.h) / 2;\n const k = o.fromCenter ? 2 : 1;\n let w = hx ? Math.max(o.min, hx * (px - ax) * k) : start.w;\n let h = hy ? Math.max(o.min, hy * (py - ay) * k) : start.h;\n if (o.keepAspect) {\n const ratio = start.w / start.h;\n if (hx && hy) {\n const s = Math.max(w / start.w, h / start.h);\n w = Math.max(o.min, start.w * s);\n h = Math.max(o.min, w / ratio);\n } else if (hx) h = Math.max(o.min, w / ratio);\n else w = Math.max(o.min, h * ratio);\n }\n // the new centre in the frame's axes: the anchor plus half the new size toward the handle\n const lcx = o.fromCenter || !hx ? 0 : ax + (hx * w) / 2;\n const lcy = o.fromCenter || !hy ? 0 : ay + (hy * h) / 2;\n const [rx, ry] = rotate(lcx, lcy, start.rotation);\n return { cx: start.cx + rx, cy: start.cy + ry, w, h, rotation: start.rotation };\n}\n\n/** Maps boxes from one selection frame to another (scaled inside it; each keeps its rotation). */\nexport function mapBoxes(boxes: readonly TbBox[], from: TbFrame, to: TbFrame): TbBox[] {\n const sx = to.w / Math.max(1e-9, from.w);\n const sy = to.h / Math.max(1e-9, from.h);\n if (boxes.length === 1) return [boxOfFrame((boxes[0] as TbBox).id, to, boxes[0])];\n return boxes.map((box) => {\n const f = frameOf(box);\n const [lx, ly] = rotate(f.cx - from.cx, f.cy - from.cy, -from.rotation);\n const [rx, ry] = rotate(lx * sx, ly * sy, to.rotation);\n const rel = (((box.rotation - from.rotation) % 180) + 180) % 180;\n const quarter = Math.abs(rel - 90) < 1;\n const straight = rel < 1 || rel > 179;\n const w = straight ? f.w * sx : quarter ? f.w * sy : f.w * Math.sqrt(sx * sy);\n const h = straight ? f.h * sy : quarter ? f.h * sx : f.h * Math.sqrt(sx * sy);\n return boxOfFrame(box.id, { cx: to.cx + rx, cy: to.cy + ry, w, h, rotation: box.rotation }, box);\n });\n}\n\n/** Rotates boxes about a point by `delta` degrees. */\nexport function rotateBoxes(boxes: readonly TbBox[], cx: number, cy: number, delta: number): TbBox[] {\n return boxes.map((box) => {\n const f = frameOf(box);\n const [rx, ry] = rotate(f.cx - cx, f.cy - cy, delta);\n return boxOfFrame(box.id, { ...f, cx: cx + rx, cy: cy + ry, rotation: normDeg(box.rotation + delta) }, box);\n });\n}\n\n/** The boxes moved by `dx`, `dy` stage units. */\nexport function moveBoxes(boxes: readonly TbBox[], dx: number, dy: number): TbBox[] {\n return boxes.map((b) => ({ ...b, x: b.x + dx, y: b.y + dy }));\n}\n\n/** Degrees in (-180, 180]. */\nexport function normDeg(d: number): number {\n let v = d % 360;\n if (v <= -180) v += 360;\n if (v > 180) v -= 360;\n return Math.round(v * 1000) / 1000;\n}\n\n/** Shift snaps to `step` degrees; otherwise right angles pull within `magnet`. */\nexport function snapAngle(deg: number, step: number | null, magnet = 3): number {\n if (step) return normDeg(Math.round(deg / step) * step);\n const right = Math.round(deg / 90) * 90;\n return Math.abs(deg - right) <= magnet ? normDeg(right) : normDeg(deg);\n}\n\n/** A guide line to draw (stage units): vertical at x = `at` (axis x) or horizontal at y = `at`. */\nexport interface TbGuide {\n readonly axis: 'x' | 'y';\n readonly at: number;\n readonly from: number;\n readonly to: number;\n readonly kind: 'edge' | 'center' | 'gap';\n}\n\n/** A move after snapping: the corrected offset and the guides to draw. */\nexport interface SnapResult {\n readonly dx: number;\n readonly dy: number;\n readonly guides: TbGuide[];\n}\n\ninterface Target {\n readonly v: number;\n readonly kind: 'edge' | 'center';\n readonly span: [number, number];\n}\n\nfunction targetsOf(\n axis: 'x' | 'y',\n others: readonly TbAabb[],\n stage: { w: number; h: number },\n zones: readonly TbRect[],\n): Target[] {\n const out: Target[] = [];\n const full: [number, number] = axis === 'x' ? [0, stage.h] : [0, stage.w];\n const size = axis === 'x' ? stage.w : stage.h;\n out.push(\n { v: 0, kind: 'edge', span: full },\n { v: size / 2, kind: 'center', span: full },\n { v: size, kind: 'edge', span: full },\n );\n for (const z of zones) {\n const a = axis === 'x' ? z.x : z.y;\n const len = axis === 'x' ? z.w : z.h;\n const span: [number, number] = axis === 'x' ? [z.y, z.y + z.h] : [z.x, z.x + z.w];\n out.push({ v: a, kind: 'edge', span }, { v: a + len, kind: 'edge', span });\n }\n for (const o of others) {\n const a0 = axis === 'x' ? o.x0 : o.y0;\n const a1 = axis === 'x' ? o.x1 : o.y1;\n const span: [number, number] = axis === 'x' ? [o.y0, o.y1] : [o.x0, o.x1];\n out.push({ v: a0, kind: 'edge', span }, { v: (a0 + a1) / 2, kind: 'center', span }, { v: a1, kind: 'edge', span });\n }\n return out;\n}\n\nfunction snapAxis(\n axis: 'x' | 'y',\n m: TbAabb,\n others: readonly TbAabb[],\n stage: { w: number; h: number },\n zones: readonly TbRect[],\n within: number,\n): { d: number; guides: TbGuide[] } {\n const a0 = axis === 'x' ? m.x0 : m.y0;\n const a1 = axis === 'x' ? m.x1 : m.y1;\n const mine: { v: number; kind: 'edge' | 'center' }[] = [\n { v: a0, kind: 'edge' },\n { v: (a0 + a1) / 2, kind: 'center' },\n { v: a1, kind: 'edge' },\n ];\n const mSpan: [number, number] = axis === 'x' ? [m.y0, m.y1] : [m.x0, m.x1];\n let best: { d: number; at: number; span: [number, number]; kind: 'edge' | 'center' } | null = null;\n for (const t of targetsOf(axis, others, stage, zones))\n for (const v of mine) {\n const d = t.v - v.v;\n if (Math.abs(d) <= within && (!best || Math.abs(d) < Math.abs(best.d) - 1e-9))\n best = { d, at: t.v, span: t.span, kind: v.kind === 'center' && t.kind === 'center' ? 'center' : 'edge' };\n }\n\n // equal spacing: the nearest neighbours on both sides that overlap across the axis\n let gap: { d: number; guides: TbGuide[] } | null = null;\n const across = (o: TbAabb) => (axis === 'x' ? o.y0 < m.y1 && o.y1 > m.y0 : o.x0 < m.x1 && o.x1 > m.x0);\n let before: TbAabb | null = null;\n let after: TbAabb | null = null;\n for (const o of others) {\n if (!across(o)) continue;\n const o0 = axis === 'x' ? o.x0 : o.y0;\n const o1 = axis === 'x' ? o.x1 : o.y1;\n if (o1 <= a0 + within && (!before || o1 > (axis === 'x' ? before.x1 : before.y1))) before = o;\n if (o0 >= a1 - within && (!after || o0 < (axis === 'x' ? after.x0 : after.y0))) after = o;\n }\n if (before && after) {\n const b1 = axis === 'x' ? before.x1 : before.y1;\n const f0 = axis === 'x' ? after.x0 : after.y0;\n const size = a1 - a0;\n const want = (b1 + f0) / 2 - size / 2;\n const d = want - a0;\n if (Math.abs(d) <= within && f0 - b1 > size) {\n const mid = (mSpan[0] + mSpan[1]) / 2;\n const other: 'x' | 'y' = axis === 'x' ? 'y' : 'x';\n gap = {\n d,\n guides: [\n { axis: other, at: mid, from: b1, to: want, kind: 'gap' },\n { axis: other, at: mid, from: want + size, to: f0, kind: 'gap' },\n ],\n };\n }\n }\n if (gap && (!best || Math.abs(gap.d) < Math.abs(best.d))) return gap;\n if (!best) return { d: 0, guides: [] };\n const from = Math.min(best.span[0], mSpan[0]);\n const to = Math.max(best.span[1], mSpan[1]);\n return { d: best.d, guides: [{ axis, at: best.at, from, to, kind: best.kind }] };\n}\n\n/** Snaps a moving bounding box to the stage, its safe zones and the other boxes, within `within` stage units. */\nexport function snapMove(\n moving: TbAabb,\n others: readonly TbAabb[],\n stage: { w: number; h: number },\n zones: readonly TbRect[],\n within: number,\n): SnapResult {\n const x = snapAxis('x', moving, others, stage, zones, within);\n const y = snapAxis('y', moving, others, stage, zones, within);\n return { dx: x.d, dy: y.d, guides: [...x.guides, ...y.guides] };\n}\n\n/** Snaps the moved edges of an unrotated frame being resized (the far edges stay). */\nexport function snapResize(\n frame: TbFrame,\n handle: Exclude<TbHandle, 'rot'>,\n others: readonly TbAabb[],\n stage: { w: number; h: number },\n zones: readonly TbRect[],\n within: number,\n): { frame: TbFrame; guides: TbGuide[] } {\n if (frame.rotation !== 0) return { frame, guides: [] };\n const [hx, hy] = HANDLE_SIGNS[handle];\n let x0 = frame.cx - frame.w / 2;\n let x1 = frame.cx + frame.w / 2;\n let y0 = frame.cy - frame.h / 2;\n let y1 = frame.cy + frame.h / 2;\n const guides: TbGuide[] = [];\n const pick = (axis: 'x' | 'y', v: number, span: [number, number]): number => {\n let best: Target | null = null;\n for (const t of targetsOf(axis, others, stage, zones))\n if (Math.abs(t.v - v) <= within && (!best || Math.abs(t.v - v) < Math.abs(best.v - v))) best = t;\n if (!best) return v;\n guides.push({\n axis,\n at: best.v,\n from: Math.min(span[0], best.span[0]),\n to: Math.max(span[1], best.span[1]),\n kind: 'edge',\n });\n return best.v;\n };\n if (hx > 0) x1 = pick('x', x1, [y0, y1]);\n if (hx < 0) x0 = pick('x', x0, [y0, y1]);\n if (hy > 0) y1 = pick('y', y1, [x0, x1]);\n if (hy < 0) y0 = pick('y', y0, [x0, x1]);\n return { frame: { cx: (x0 + x1) / 2, cy: (y0 + y1) / 2, w: x1 - x0, h: y1 - y0, rotation: 0 }, guides };\n}\n"],"names":["HANDLE_SIGNS","DEG","Math","fitOf","stage","view","zoom","panX","panY","padding","base","scale","toScreen","fit","x","y","toStage","sx","sy","rotate","deg","c","s","frameOf","box","boxOfFrame","id","frame","from","cornersOf","hw","hh","rx","ry","aabbOf","frames","x0","Infinity","y0","x1","y1","f","selectionFrame","boxes","a","contains","slack","lx","ly","hitBox","i","handlePoints","rotGap","out","handle","Object","hx","hy","hitHandle","radius","small","best","p","d","resizeFrame","start","o","px","py","ax","ay","k","w","h","ratio","lcx","lcy","mapBoxes","to","rel","quarter","straight","rotateBoxes","cx","cy","delta","normDeg","moveBoxes","dx","dy","b","v","snapAngle","step","magnet","right","targetsOf","axis","others","zones","full","size","z","len","span","a0","a1","snapAxis","m","within","mine","mSpan","t","gap","across","before","after","o0","o1","b1","f0","want","mid","other","snapMove","moving","snapResize","guides","pick"],"mappings":"AAuDO,MAAMA,eAA4E;IACvF,IAAI;QAAC;QAAI;KAAG;IACZ,GAAG;QAAC;QAAG;KAAG;IACV,IAAI;QAAC;QAAG;KAAG;IACX,GAAG;QAAC;QAAG;KAAE;IACT,IAAI;QAAC;QAAG;KAAE;IACV,GAAG;QAAC;QAAG;KAAE;IACT,IAAI;QAAC;QAAI;KAAE;IACX,GAAG;QAAC;QAAI;KAAE;AACZ;AAEA,MAAMC,MAAMC,KAAK,EAAE,GAAG;AAGf,SAASC,MACdC,KAAiD,EACjDC,IAAgD,EAChDC,IAAY,EACZC,IAAY,EACZC,IAAY,EACZC,UAAU,EAAE;IAEZ,MAAMC,OAAOR,KAAK,GAAG,CAAC,MAAMA,KAAK,GAAG,CAAEG,AAAAA,CAAAA,KAAK,CAAC,GAAGI,AAAU,IAAVA,OAAU,IAAKL,MAAM,CAAC,EAAGC,AAAAA,CAAAA,KAAK,CAAC,GAAGI,AAAU,IAAVA,OAAU,IAAKL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KAAK,IAAI,CAAC,EAAE;YAClC,MAAM;QACR;QACA,OAAOA,KAAK,CAAC;IACf;IACA,IAAIL,KAAK,GAAGjB,KAAKyF,KAAK,KAAKzF,IAAI;QAACD;QAAIE;KAAG;IACvC,IAAIgB,KAAK,GAAGpB,KAAK4F,KAAK,KAAK5F,IAAI;QAACE;QAAIE;KAAG;IACvC,IAAIiB,KAAK,GAAGjB,KAAKwF,KAAK,KAAKxF,IAAI;QAACJ;QAAIG;KAAG;IACvC,IAAIkB,KAAK,GAAGnB,KAAK0F,KAAK,KAAK1F,IAAI;QAACF;QAAIG;KAAG;IACvC,OAAO;QAAE,OAAO;YAAE,IAAKH,AAAAA,CAAAA,KAAKG,EAAC,IAAK;YAAG,IAAKD,AAAAA,CAAAA,KAAKE,EAAC,IAAK;YAAG,GAAGD,KAAKH;YAAI,GAAGI,KAAKF;YAAI,UAAU;QAAE;QAAGyF;IAAO;AACxG"}
@@ -0,0 +1,504 @@
1
+ const HANDLE_SIGNS = {
2
+ nw: [
3
+ -1,
4
+ -1
5
+ ],
6
+ n: [
7
+ 0,
8
+ -1
9
+ ],
10
+ ne: [
11
+ 1,
12
+ -1
13
+ ],
14
+ e: [
15
+ 1,
16
+ 0
17
+ ],
18
+ se: [
19
+ 1,
20
+ 1
21
+ ],
22
+ s: [
23
+ 0,
24
+ 1
25
+ ],
26
+ sw: [
27
+ -1,
28
+ 1
29
+ ],
30
+ w: [
31
+ -1,
32
+ 0
33
+ ]
34
+ };
35
+ const DEG = Math.PI / 180;
36
+ function fitOf(stage, view, zoom, panX, panY, padding = 16) {
37
+ const base = Math.max(1e-6, Math.min((view.w - 2 * padding) / stage.w, (view.h - 2 * padding) / stage.h));
38
+ const scale = base * zoom;
39
+ return {
40
+ scale,
41
+ ox: (view.w - stage.w * scale) / 2 + panX,
42
+ oy: (view.h - stage.h * scale) / 2 + panY
43
+ };
44
+ }
45
+ function toScreen(fit, x, y) {
46
+ return [
47
+ fit.ox + x * fit.scale,
48
+ fit.oy + y * fit.scale
49
+ ];
50
+ }
51
+ function toStage(fit, sx, sy) {
52
+ return [
53
+ (sx - fit.ox) / fit.scale,
54
+ (sy - fit.oy) / fit.scale
55
+ ];
56
+ }
57
+ function rotate(x, y, deg) {
58
+ if (!deg) return [
59
+ x,
60
+ y
61
+ ];
62
+ const c = Math.cos(deg * DEG);
63
+ const s = Math.sin(deg * DEG);
64
+ return [
65
+ x * c - y * s,
66
+ x * s + y * c
67
+ ];
68
+ }
69
+ function frameOf(box) {
70
+ return {
71
+ cx: box.x + box.w / 2,
72
+ cy: box.y + box.h / 2,
73
+ w: box.w,
74
+ h: box.h,
75
+ rotation: box.rotation
76
+ };
77
+ }
78
+ function boxOfFrame(id, frame, from) {
79
+ return {
80
+ ...null != from ? from : {
81
+ id
82
+ },
83
+ id,
84
+ x: frame.cx - frame.w / 2,
85
+ y: frame.cy - frame.h / 2,
86
+ w: frame.w,
87
+ h: frame.h,
88
+ rotation: frame.rotation
89
+ };
90
+ }
91
+ function cornersOf(frame) {
92
+ const hw = frame.w / 2;
93
+ const hh = frame.h / 2;
94
+ return [
95
+ [
96
+ -hw,
97
+ -hh
98
+ ],
99
+ [
100
+ hw,
101
+ -hh
102
+ ],
103
+ [
104
+ hw,
105
+ hh
106
+ ],
107
+ [
108
+ -hw,
109
+ hh
110
+ ]
111
+ ].map(([x, y])=>{
112
+ const [rx, ry] = rotate(x, y, frame.rotation);
113
+ return [
114
+ frame.cx + rx,
115
+ frame.cy + ry
116
+ ];
117
+ });
118
+ }
119
+ function aabbOf(frames) {
120
+ let x0 = 1 / 0;
121
+ let y0 = 1 / 0;
122
+ let x1 = -1 / 0;
123
+ let y1 = -1 / 0;
124
+ for (const f of frames)for (const [x, y] of cornersOf(f)){
125
+ x0 = Math.min(x0, x);
126
+ y0 = Math.min(y0, y);
127
+ x1 = Math.max(x1, x);
128
+ y1 = Math.max(y1, y);
129
+ }
130
+ return {
131
+ x0,
132
+ y0,
133
+ x1,
134
+ y1
135
+ };
136
+ }
137
+ function selectionFrame(boxes) {
138
+ if (!boxes.length) return null;
139
+ if (1 === boxes.length) return frameOf(boxes[0]);
140
+ const a = aabbOf(boxes.map(frameOf));
141
+ return {
142
+ cx: (a.x0 + a.x1) / 2,
143
+ cy: (a.y0 + a.y1) / 2,
144
+ w: a.x1 - a.x0,
145
+ h: a.y1 - a.y0,
146
+ rotation: 0
147
+ };
148
+ }
149
+ function contains(frame, x, y, slack = 0) {
150
+ const [lx, ly] = rotate(x - frame.cx, y - frame.cy, -frame.rotation);
151
+ return Math.abs(lx) <= frame.w / 2 + slack && Math.abs(ly) <= frame.h / 2 + slack;
152
+ }
153
+ function hitBox(boxes, x, y, slack = 0) {
154
+ for(let i = boxes.length - 1; i >= 0; i--){
155
+ const box = boxes[i];
156
+ if (contains(frameOf(box), x, y, slack)) return box;
157
+ }
158
+ return null;
159
+ }
160
+ function handlePoints(frame, fit, rotGap = 28) {
161
+ const out = [];
162
+ for (const handle of Object.keys(HANDLE_SIGNS)){
163
+ const [hx, hy] = HANDLE_SIGNS[handle];
164
+ const [rx, ry] = rotate(hx * frame.w / 2, hy * frame.h / 2, frame.rotation);
165
+ const [sx, sy] = toScreen(fit, frame.cx + rx, frame.cy + ry);
166
+ out.push({
167
+ handle,
168
+ x: sx,
169
+ y: sy
170
+ });
171
+ }
172
+ const [rx, ry] = rotate(0, -frame.h / 2 - rotGap / fit.scale, frame.rotation);
173
+ const [sx, sy] = toScreen(fit, frame.cx + rx, frame.cy + ry);
174
+ out.push({
175
+ handle: 'rot',
176
+ x: sx,
177
+ y: sy
178
+ });
179
+ return out;
180
+ }
181
+ function hitHandle(frame, fit, x, y, radius) {
182
+ var _ref;
183
+ const small = Math.min(frame.w, frame.h) * fit.scale < 4 * radius;
184
+ let best = null;
185
+ for (const p of handlePoints(frame, fit)){
186
+ if (small && 1 === p.handle.length) continue;
187
+ const d = Math.hypot(p.x - x, p.y - y);
188
+ if (d <= radius && (!best || d < best.d)) best = {
189
+ handle: p.handle,
190
+ d
191
+ };
192
+ }
193
+ return null != (_ref = null == best ? void 0 : best.handle) ? _ref : null;
194
+ }
195
+ function resizeFrame(start, handle, x, y, o) {
196
+ const [hx, hy] = HANDLE_SIGNS[handle];
197
+ const [px, py] = rotate(x - start.cx, y - start.cy, -start.rotation);
198
+ const ax = o.fromCenter ? 0 : -hx * start.w / 2;
199
+ const ay = o.fromCenter ? 0 : -hy * start.h / 2;
200
+ const k = o.fromCenter ? 2 : 1;
201
+ let w = hx ? Math.max(o.min, hx * (px - ax) * k) : start.w;
202
+ let h = hy ? Math.max(o.min, hy * (py - ay) * k) : start.h;
203
+ if (o.keepAspect) {
204
+ const ratio = start.w / start.h;
205
+ if (hx && hy) {
206
+ const s = Math.max(w / start.w, h / start.h);
207
+ w = Math.max(o.min, start.w * s);
208
+ h = Math.max(o.min, w / ratio);
209
+ } else if (hx) h = Math.max(o.min, w / ratio);
210
+ else w = Math.max(o.min, h * ratio);
211
+ }
212
+ const lcx = o.fromCenter || !hx ? 0 : ax + hx * w / 2;
213
+ const lcy = o.fromCenter || !hy ? 0 : ay + hy * h / 2;
214
+ const [rx, ry] = rotate(lcx, lcy, start.rotation);
215
+ return {
216
+ cx: start.cx + rx,
217
+ cy: start.cy + ry,
218
+ w,
219
+ h,
220
+ rotation: start.rotation
221
+ };
222
+ }
223
+ function mapBoxes(boxes, from, to) {
224
+ const sx = to.w / Math.max(1e-9, from.w);
225
+ const sy = to.h / Math.max(1e-9, from.h);
226
+ if (1 === boxes.length) return [
227
+ boxOfFrame(boxes[0].id, to, boxes[0])
228
+ ];
229
+ return boxes.map((box)=>{
230
+ const f = frameOf(box);
231
+ const [lx, ly] = rotate(f.cx - from.cx, f.cy - from.cy, -from.rotation);
232
+ const [rx, ry] = rotate(lx * sx, ly * sy, to.rotation);
233
+ const rel = ((box.rotation - from.rotation) % 180 + 180) % 180;
234
+ const quarter = Math.abs(rel - 90) < 1;
235
+ const straight = rel < 1 || rel > 179;
236
+ const w = straight ? f.w * sx : quarter ? f.w * sy : f.w * Math.sqrt(sx * sy);
237
+ const h = straight ? f.h * sy : quarter ? f.h * sx : f.h * Math.sqrt(sx * sy);
238
+ return boxOfFrame(box.id, {
239
+ cx: to.cx + rx,
240
+ cy: to.cy + ry,
241
+ w,
242
+ h,
243
+ rotation: box.rotation
244
+ }, box);
245
+ });
246
+ }
247
+ function rotateBoxes(boxes, cx, cy, delta) {
248
+ return boxes.map((box)=>{
249
+ const f = frameOf(box);
250
+ const [rx, ry] = rotate(f.cx - cx, f.cy - cy, delta);
251
+ return boxOfFrame(box.id, {
252
+ ...f,
253
+ cx: cx + rx,
254
+ cy: cy + ry,
255
+ rotation: normDeg(box.rotation + delta)
256
+ }, box);
257
+ });
258
+ }
259
+ function moveBoxes(boxes, dx, dy) {
260
+ return boxes.map((b)=>({
261
+ ...b,
262
+ x: b.x + dx,
263
+ y: b.y + dy
264
+ }));
265
+ }
266
+ function normDeg(d) {
267
+ let v = d % 360;
268
+ if (v <= -180) v += 360;
269
+ if (v > 180) v -= 360;
270
+ return Math.round(1000 * v) / 1000;
271
+ }
272
+ function snapAngle(deg, step, magnet = 3) {
273
+ if (step) return normDeg(Math.round(deg / step) * step);
274
+ const right = 90 * Math.round(deg / 90);
275
+ return Math.abs(deg - right) <= magnet ? normDeg(right) : normDeg(deg);
276
+ }
277
+ function targetsOf(axis, others, stage, zones) {
278
+ const out = [];
279
+ const full = 'x' === axis ? [
280
+ 0,
281
+ stage.h
282
+ ] : [
283
+ 0,
284
+ stage.w
285
+ ];
286
+ const size = 'x' === axis ? stage.w : stage.h;
287
+ out.push({
288
+ v: 0,
289
+ kind: 'edge',
290
+ span: full
291
+ }, {
292
+ v: size / 2,
293
+ kind: 'center',
294
+ span: full
295
+ }, {
296
+ v: size,
297
+ kind: 'edge',
298
+ span: full
299
+ });
300
+ for (const z of zones){
301
+ const a = 'x' === axis ? z.x : z.y;
302
+ const len = 'x' === axis ? z.w : z.h;
303
+ const span = 'x' === axis ? [
304
+ z.y,
305
+ z.y + z.h
306
+ ] : [
307
+ z.x,
308
+ z.x + z.w
309
+ ];
310
+ out.push({
311
+ v: a,
312
+ kind: 'edge',
313
+ span
314
+ }, {
315
+ v: a + len,
316
+ kind: 'edge',
317
+ span
318
+ });
319
+ }
320
+ for (const o of others){
321
+ const a0 = 'x' === axis ? o.x0 : o.y0;
322
+ const a1 = 'x' === axis ? o.x1 : o.y1;
323
+ const span = 'x' === axis ? [
324
+ o.y0,
325
+ o.y1
326
+ ] : [
327
+ o.x0,
328
+ o.x1
329
+ ];
330
+ out.push({
331
+ v: a0,
332
+ kind: 'edge',
333
+ span
334
+ }, {
335
+ v: (a0 + a1) / 2,
336
+ kind: 'center',
337
+ span
338
+ }, {
339
+ v: a1,
340
+ kind: 'edge',
341
+ span
342
+ });
343
+ }
344
+ return out;
345
+ }
346
+ function snapAxis(axis, m, others, stage, zones, within) {
347
+ const a0 = 'x' === axis ? m.x0 : m.y0;
348
+ const a1 = 'x' === axis ? m.x1 : m.y1;
349
+ const mine = [
350
+ {
351
+ v: a0,
352
+ kind: 'edge'
353
+ },
354
+ {
355
+ v: (a0 + a1) / 2,
356
+ kind: 'center'
357
+ },
358
+ {
359
+ v: a1,
360
+ kind: 'edge'
361
+ }
362
+ ];
363
+ const mSpan = 'x' === axis ? [
364
+ m.y0,
365
+ m.y1
366
+ ] : [
367
+ m.x0,
368
+ m.x1
369
+ ];
370
+ let best = null;
371
+ for (const t of targetsOf(axis, others, stage, zones))for (const v of mine){
372
+ const d = t.v - v.v;
373
+ if (Math.abs(d) <= within && (!best || Math.abs(d) < Math.abs(best.d) - 1e-9)) best = {
374
+ d,
375
+ at: t.v,
376
+ span: t.span,
377
+ kind: 'center' === v.kind && 'center' === t.kind ? 'center' : 'edge'
378
+ };
379
+ }
380
+ let gap = null;
381
+ const across = (o)=>'x' === axis ? o.y0 < m.y1 && o.y1 > m.y0 : o.x0 < m.x1 && o.x1 > m.x0;
382
+ let before = null;
383
+ let after = null;
384
+ for (const o of others){
385
+ if (!across(o)) continue;
386
+ const o0 = 'x' === axis ? o.x0 : o.y0;
387
+ const o1 = 'x' === axis ? o.x1 : o.y1;
388
+ if (o1 <= a0 + within && (!before || o1 > ('x' === axis ? before.x1 : before.y1))) before = o;
389
+ if (o0 >= a1 - within && (!after || o0 < ('x' === axis ? after.x0 : after.y0))) after = o;
390
+ }
391
+ if (before && after) {
392
+ const b1 = 'x' === axis ? before.x1 : before.y1;
393
+ const f0 = 'x' === axis ? after.x0 : after.y0;
394
+ const size = a1 - a0;
395
+ const want = (b1 + f0) / 2 - size / 2;
396
+ const d = want - a0;
397
+ if (Math.abs(d) <= within && f0 - b1 > size) {
398
+ const mid = (mSpan[0] + mSpan[1]) / 2;
399
+ const other = 'x' === axis ? 'y' : 'x';
400
+ gap = {
401
+ d,
402
+ guides: [
403
+ {
404
+ axis: other,
405
+ at: mid,
406
+ from: b1,
407
+ to: want,
408
+ kind: 'gap'
409
+ },
410
+ {
411
+ axis: other,
412
+ at: mid,
413
+ from: want + size,
414
+ to: f0,
415
+ kind: 'gap'
416
+ }
417
+ ]
418
+ };
419
+ }
420
+ }
421
+ if (gap && (!best || Math.abs(gap.d) < Math.abs(best.d))) return gap;
422
+ if (!best) return {
423
+ d: 0,
424
+ guides: []
425
+ };
426
+ const from = Math.min(best.span[0], mSpan[0]);
427
+ const to = Math.max(best.span[1], mSpan[1]);
428
+ return {
429
+ d: best.d,
430
+ guides: [
431
+ {
432
+ axis,
433
+ at: best.at,
434
+ from,
435
+ to,
436
+ kind: best.kind
437
+ }
438
+ ]
439
+ };
440
+ }
441
+ function snapMove(moving, others, stage, zones, within) {
442
+ const x = snapAxis('x', moving, others, stage, zones, within);
443
+ const y = snapAxis('y', moving, others, stage, zones, within);
444
+ return {
445
+ dx: x.d,
446
+ dy: y.d,
447
+ guides: [
448
+ ...x.guides,
449
+ ...y.guides
450
+ ]
451
+ };
452
+ }
453
+ function snapResize(frame, handle, others, stage, zones, within) {
454
+ if (0 !== frame.rotation) return {
455
+ frame,
456
+ guides: []
457
+ };
458
+ const [hx, hy] = HANDLE_SIGNS[handle];
459
+ let x0 = frame.cx - frame.w / 2;
460
+ let x1 = frame.cx + frame.w / 2;
461
+ let y0 = frame.cy - frame.h / 2;
462
+ let y1 = frame.cy + frame.h / 2;
463
+ const guides = [];
464
+ const pick = (axis, v, span)=>{
465
+ let best = null;
466
+ for (const t of targetsOf(axis, others, stage, zones))if (Math.abs(t.v - v) <= within && (!best || Math.abs(t.v - v) < Math.abs(best.v - v))) best = t;
467
+ if (!best) return v;
468
+ guides.push({
469
+ axis,
470
+ at: best.v,
471
+ from: Math.min(span[0], best.span[0]),
472
+ to: Math.max(span[1], best.span[1]),
473
+ kind: 'edge'
474
+ });
475
+ return best.v;
476
+ };
477
+ if (hx > 0) x1 = pick('x', x1, [
478
+ y0,
479
+ y1
480
+ ]);
481
+ if (hx < 0) x0 = pick('x', x0, [
482
+ y0,
483
+ y1
484
+ ]);
485
+ if (hy > 0) y1 = pick('y', y1, [
486
+ x0,
487
+ x1
488
+ ]);
489
+ if (hy < 0) y0 = pick('y', y0, [
490
+ x0,
491
+ x1
492
+ ]);
493
+ return {
494
+ frame: {
495
+ cx: (x0 + x1) / 2,
496
+ cy: (y0 + y1) / 2,
497
+ w: x1 - x0,
498
+ h: y1 - y0,
499
+ rotation: 0
500
+ },
501
+ guides
502
+ };
503
+ }
504
+ export { HANDLE_SIGNS, aabbOf, boxOfFrame, contains, cornersOf, fitOf, frameOf, handlePoints, hitBox, hitHandle, mapBoxes, moveBoxes, normDeg, resizeFrame, rotate, rotateBoxes, selectionFrame, snapAngle, snapMove, snapResize, toScreen, toStage };
@@ -0,0 +1,4 @@
1
+ export { TB_KEYS, TbEngine, type TbEvents, type TbKeyInput, type TbKind, type TbMessage, type TbPointer, type TbVia, type TbView, type TbWheel, } from './engine.js';
2
+ export { aabbOf, fitOf, frameOf, hitBox, hitHandle, mapBoxes, normDeg, resizeFrame, rotateBoxes, selectionFrame, snapAngle, snapMove, type TbAabb, type TbBox, type TbFit, type TbFrame, type TbGuide, type TbHandle, type TbRect, toScreen, toStage, } from './geometry.js';
3
+ export { G9TransformBox, type G9TransformBoxElementProps, G9TransformBoxPort, type G9TransformBoxProps, } from './transform-box.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transform-box/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,OAAO,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,SAAS,EACT,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,QAAQ,EACR,OAAO,GACR,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAC/B,kBAAkB,EAClB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { TB_KEYS, TbEngine } from "./engine.jsx";
2
+ export { aabbOf, fitOf, frameOf, hitBox, hitHandle, mapBoxes, normDeg, resizeFrame, rotateBoxes, selectionFrame, snapAngle, snapMove, toScreen, toStage } from "./geometry.jsx";
3
+ export { G9TransformBox, G9TransformBoxPort } from "./transform-box.jsx";
@@ -0,0 +1,65 @@
1
+ import { type ReactNode } from '@lynx-js/react';
2
+ import type { NodesRef } from '@lynx-js/types';
3
+ import type { TbEvents, TbMessage } from './engine.js';
4
+ import type { TbBox } from './geometry.js';
5
+ /** The page's way to the element. */
6
+ export declare class G9TransformBoxPort {
7
+ private target;
8
+ private state;
9
+ apply: (message: TbMessage) => void;
10
+ /** Keeps the port's copy in step (the element already shows its own transforms). */
11
+ note(message: TbMessage): void;
12
+ /** What the port holds (the boxes as the page last knew them). */
13
+ get boxes(): readonly TbBox[];
14
+ get selection(): readonly string[];
15
+ attach(target: NodesRef | null): void;
16
+ get attached(): boolean;
17
+ }
18
+ type Handler<K extends keyof TbEvents> = (detail: TbEvents[K]) => void;
19
+ /** Props of {@link G9TransformBox}. */
20
+ export interface G9TransformBoxProps {
21
+ readonly id?: string;
22
+ readonly port: G9TransformBoxPort;
23
+ /** Smart guides and snapping. Default true. */
24
+ readonly guides?: boolean;
25
+ /** Draw the safe zones. Default true. */
26
+ readonly safeZones?: boolean;
27
+ /** False: select and look only. Default true. */
28
+ readonly editable?: boolean;
29
+ /** px between the fitted stage and the element's edge. Default 16. */
30
+ readonly padding?: number;
31
+ /** The app's theme; a change makes the element read the theme's colour tokens again. */
32
+ readonly theme?: 'light' | 'dark';
33
+ readonly className?: string;
34
+ readonly style?: Record<string, string | number>;
35
+ readonly onSelect?: Handler<'tbselect'>;
36
+ readonly onTransform?: Handler<'tbtransform'>;
37
+ readonly onView?: Handler<'tbview'>;
38
+ readonly onCommand?: Handler<'tbcommand'>;
39
+ readonly onOpen?: Handler<'tbopen'>;
40
+ readonly onTap?: Handler<'tbtap'>;
41
+ }
42
+ /** The `<g9-transform-box>` host element's attributes and events, as G9TransformBox sets them. */
43
+ export interface G9TransformBoxElementProps {
44
+ readonly ref?: unknown;
45
+ readonly id?: string;
46
+ readonly className?: string;
47
+ readonly style?: Record<string, string | number>;
48
+ readonly guides?: string;
49
+ readonly safe?: string;
50
+ readonly editable?: string;
51
+ readonly padding?: string;
52
+ readonly theme?: string;
53
+ readonly [event: `bind${string}`]: ((e: {
54
+ detail: unknown;
55
+ }) => void) | undefined;
56
+ }
57
+ declare module '@lynx-js/types' {
58
+ interface IntrinsicElements {
59
+ 'g9-transform-box': G9TransformBoxElementProps;
60
+ }
61
+ }
62
+ /** Selection boxes and handles over any content (`<g9-transform-box>`): move, scale, rotate, smart guides, safe zones, pinch and wheel zoom. Boxes go in through the port; transforms, the selection and the view come out as events. */
63
+ export declare function G9TransformBox(props: G9TransformBoxProps): ReactNode;
64
+ export {};
65
+ //# sourceMappingURL=transform-box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-box.d.ts","sourceRoot":"","sources":["../../src/transform-box/transform-box.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAU,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,YAAY,CAAC;AAEhD,qCAAqC;AACrC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,KAAK,CAMoB;IAEjC,KAAK,GAAI,SAAS,SAAS,KAAG,IAAI,CAGhC;IAEF,oFAAoF;IACpF,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI;IAoB9B,kEAAkE;IAClE,IAAI,KAAK,IAAI,SAAS,KAAK,EAAE,CAE5B;IAED,IAAI,SAAS,IAAI,SAAS,MAAM,EAAE,CAEjC;IAED,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI;IAKrC,IAAI,QAAQ,IAAI,OAAO,CAEtB;CACF;AAED,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEvE,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAA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