@g9tm/lynxcontrols-canvas 2.5.9 → 2.5.11

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene/edit.js","sources":["../../src/scene/edit.ts"],"sourcesContent":["import {\n BOUND_TEXT_PADDING,\n bump,\n compareOrder,\n indexAfter,\n indicesBetween,\n isFrame,\n isLinear,\n isPointsElement,\n measureText,\n newFrame,\n newFreeDraw,\n newImage,\n newLinear,\n newShape,\n newText,\n normalizeText,\n randomId,\n sizeOfPoints,\n} from './elements';\nimport {\n absoluteCoords,\n boundsContain,\n elementBounds,\n hitElement,\n intersectOutline,\n isBindable,\n outlineOf,\n rotate,\n} from './geometry';\nimport type { Scene } from './scene';\nimport type { Bounds, ExElement, ItemStyle, Point, PointBinding } from './types';\n\n/**\n * The editing operations of the whiteboard, as Excalidraw performs them for its own UI: each returns the new versions\n * of every element it touched (made with `bump`), for `scene.commit`. Bound arrows follow the shapes they are bound to,\n * labels follow their containers, a frame takes its children along — on whichever client made the change, because\n * the others only receive the result.\n */\n\nconst BINDING_GAP = 5;\n\n/** Elements to treat as one with `ids`: groups (outermost), labels of containers, children of frames. */\nexport function expandSelection(scene: Scene, ids: Iterable<string>): string[] {\n const result = new Set<string>();\n const visible = scene.visible();\n for (const id of ids) {\n const element = scene.get(id);\n if (!element || element.isDeleted) continue;\n result.add(id);\n const group = element.groupIds?.[element.groupIds.length - 1];\n if (group) for (const other of visible) if (other.groupIds?.includes(group)) result.add(other.id);\n }\n return [...result];\n}\n\n/** The ids that move with a selection: plus labels inside containers and frame children. */\nexport function movingSet(scene: Scene, ids: readonly string[]): string[] {\n const result = new Set(ids);\n for (const id of ids) {\n const element = scene.get(id);\n if (!element) continue;\n for (const bound of element.boundElements ?? []) if (bound.type === 'text') result.add(bound.id);\n if (isFrame(element)) for (const child of scene.visible()) if (child.frameId === id) result.add(child.id);\n }\n return [...result].filter((id) => scene.get(id) && !scene.get(id)!.isDeleted);\n}\n\n/** The topmost element under the point (a label hits its container). */\nexport function hitTest(\n scene: Scene,\n point: Point,\n threshold: number,\n selected: ReadonlySet<string> = new Set(),\n): ExElement | null {\n const visible = scene.visible();\n // A selected element is picked anywhere inside its box (Excalidraw: drag a selection by its inside).\n for (let i = visible.length - 1; i >= 0; i--) {\n const element = visible[i];\n if (!selected.has(element.id)) continue;\n const [x1, y1, x2, y2, cx, cy] = absoluteCoords(element);\n const p = rotate(point, [cx, cy], -(element.angle || 0));\n if (p[0] >= x1 - threshold && p[0] <= x2 + threshold && p[1] >= y1 - threshold && p[1] <= y2 + threshold)\n return element;\n }\n for (let i = visible.length - 1; i >= 0; i--) {\n const element = visible[i];\n if (element.locked) continue;\n if (hitElement(element, point, threshold)) {\n if (element.type === 'text' && element.containerId) return scene.get(element.containerId) ?? element;\n return element;\n }\n }\n return null;\n}\n\n/** Elements entirely inside the box (frames' children count only when the frame is not selected). */\nexport function inBox(scene: Scene, box: Bounds): string[] {\n const ids: string[] = [];\n for (const element of scene.visible()) {\n if (element.locked) continue;\n if (element.type === 'text' && element.containerId) continue;\n if (boundsContain(box, elementBounds(element))) ids.push(element.id);\n }\n return expandSelection(scene, ids);\n}\n\n/** The frame a new element drawn in `bounds` belongs to (fully inside it). */\nfunction frameFor(scene: Scene, bounds: Bounds): string | null {\n const visible = scene.visible();\n for (let i = visible.length - 1; i >= 0; i--) {\n const frame = visible[i];\n if (isFrame(frame) && boundsContain(elementBounds(frame), bounds)) return frame.id;\n }\n return null;\n}\n\n// ------------------------------------------------------------------ create\n\n/** A new rectangle, ellipse, diamond or frame in a box, inside the frame under it. */\nexport function createShape(\n scene: Scene,\n type: 'rectangle' | 'ellipse' | 'diamond' | 'frame',\n box: Bounds,\n style: ItemStyle,\n): ExElement {\n const options = {\n x: box[0],\n y: box[1],\n width: box[2] - box[0],\n height: box[3] - box[1],\n style,\n index: indexAfter(scene.lastIndex()),\n };\n if (type === 'frame') return newFrame({ ...options, index: options.index });\n return newShape(type, { ...options, frameId: frameFor(scene, box) });\n}\n\n/** A new arrow/line from absolute points, bound to the shapes its ends lie on (arrows only). */\nexport function createLinear(\n scene: Scene,\n type: 'arrow' | 'line',\n absolute: Point[],\n style: ItemStyle,\n zoom = 1,\n): ExElement[] {\n const [x, y] = absolute[0];\n let element = newLinear(type, {\n x,\n y,\n style,\n index: indexAfter(scene.lastIndex()),\n points: absolute.map(([px, py]) => [px - x, py - y] as Point),\n startArrowhead: style.startArrowhead,\n endArrowhead: style.endArrowhead,\n frameId: frameFor(scene, [\n Math.min(...absolute.map((p) => p[0])),\n Math.min(...absolute.map((p) => p[1])),\n Math.max(...absolute.map((p) => p[0])),\n Math.max(...absolute.map((p) => p[1])),\n ]),\n });\n if (type !== 'arrow') return [element];\n const touched = new Map<string, ExElement>();\n for (const end of ['start', 'end'] as const) {\n const point = end === 'start' ? absolute[0] : absolute[absolute.length - 1];\n const target = bindableAt(scene, point, 12 / zoom, element.id);\n if (!target) continue;\n const binding: PointBinding = { elementId: target.id, focus: 0, gap: BINDING_GAP };\n element = { ...element, [end === 'start' ? 'startBinding' : 'endBinding']: binding };\n const shape = touched.get(target.id) ?? target;\n if (!(shape.boundElements ?? []).some((bound) => bound.id === element.id))\n touched.set(\n target.id,\n bump(shape, { boundElements: [...(shape.boundElements ?? []), { id: element.id, type: 'arrow' }] }),\n );\n }\n const lookup = (id: string) => touched.get(id) ?? scene.get(id);\n element = followBindings(element, lookup);\n return [element, ...touched.values()];\n}\n\nfunction bindableAt(scene: Scene, point: Point, threshold: number, except: string): ExElement | null {\n const visible = scene.visible();\n for (let i = visible.length - 1; i >= 0; i--) {\n const element = visible[i];\n if (element.id === except || !isBindable(element) || (element.type === 'text' && element.containerId)) continue;\n const [x1, y1, x2, y2, cx, cy] = absoluteCoords(element);\n const p = rotate(point, [cx, cy], -(element.angle || 0));\n if (p[0] >= x1 - threshold && p[0] <= x2 + threshold && p[1] >= y1 - threshold && p[1] <= y2 + threshold)\n return element;\n }\n return null;\n}\n\n/** Puts a bound arrow's ends on the outlines of its shapes (aimed at their centres: focus 0), `gap` away. */\nexport function followBindings(arrow: ExElement, lookup: (id: string) => ExElement | undefined): ExElement {\n const points = (arrow.points ?? []).map(([px, py]) => [px + arrow.x, py + arrow.y] as Point);\n if (points.length < 2) return arrow;\n const start = arrow.startBinding ? lookup(arrow.startBinding.elementId) : undefined;\n const end = arrow.endBinding ? lookup(arrow.endBinding.elementId) : undefined;\n const centre = (element: ExElement): Point => {\n const coords = absoluteCoords(element);\n return [coords[4], coords[5]];\n };\n const snap = (shape: ExElement, from: Point, gap: number): Point | null => {\n const c = centre(shape);\n const hit = intersectOutline(outlineOf(shape), from, c);\n if (!hit) return null;\n const length = Math.hypot(hit[0] - from[0], hit[1] - from[1]);\n if (length < 1e-6) return hit;\n return [hit[0] - ((hit[0] - from[0]) / length) * gap, hit[1] - ((hit[1] - from[1]) / length) * gap];\n };\n let changed = false;\n const last = points.length - 1;\n if (start && !start.isDeleted) {\n const from = points.length === 2 && end && !end.isDeleted ? centre(end) : points[1];\n const next = snap(start, from, arrow.startBinding?.gap ?? BINDING_GAP);\n if (next) {\n points[0] = next;\n changed = true;\n }\n }\n if (end && !end.isDeleted) {\n const from = points.length === 2 && start && !start.isDeleted ? centre(start) : points[last - 1];\n const next = snap(end, from, arrow.endBinding?.gap ?? BINDING_GAP);\n if (next) {\n points[last] = next;\n changed = true;\n }\n }\n if (!changed) return arrow;\n const [ox, oy] = points[0];\n const relative = points.map(([px, py]) => [px - ox, py - oy] as Point);\n const size = sizeOfPoints(relative);\n return { ...arrow, x: ox, y: oy, points: relative, width: size.width, height: size.height };\n}\n\n/** A new free stroke from flat points (pressures, or simulated without them). */\nexport function createFreeDraw(\n scene: Scene,\n flat: readonly number[],\n pressures: readonly number[] | null,\n style: ItemStyle,\n): ExElement {\n const x = flat[0];\n const y = flat[1];\n const points: Point[] = [];\n for (let i = 0; i + 1 < flat.length; i += 2) points.push([flat[i] - x, flat[i + 1] - y]);\n if (points.length === 1) points.push([0.0001, 0.0001]);\n const bounds: Bounds = [\n Math.min(...points.map((p) => p[0])) + x,\n Math.min(...points.map((p) => p[1])) + y,\n Math.max(...points.map((p) => p[0])) + x,\n Math.max(...points.map((p) => p[1])) + y,\n ];\n return newFreeDraw({\n x,\n y,\n style: { ...style, roundness: 'sharp' },\n index: indexAfter(scene.lastIndex()),\n points,\n pressures: pressures ? [...pressures].slice(0, points.length) : [],\n simulatePressure: !pressures,\n frameId: frameFor(scene, bounds),\n });\n}\n\n/** A new text at a point, or a label inside a container (re-centred in it). */\nexport function createText(\n scene: Scene,\n x: number,\n y: number,\n text: string,\n style: ItemStyle,\n container?: ExElement,\n): ExElement[] {\n if (!container) {\n const element = newText({ x, y, text, style, index: indexAfter(scene.lastIndex()) });\n return [{ ...element, frameId: frameFor(scene, elementBounds(element)) }];\n }\n const label = newText({\n x,\n y,\n text,\n style: { ...style, textAlign: 'center' },\n verticalAlign: 'middle',\n containerId: container.id,\n index: indexAfter(container.index ?? scene.lastIndex()),\n autoResize: true,\n });\n const placed = placeLabel(label, container);\n return [\n placed,\n bump(container, {\n boundElements: [\n ...(container.boundElements ?? []).filter((bound) => bound.type !== 'text'),\n { id: label.id, type: 'text' },\n ],\n }),\n ];\n}\n\n/** A container's label centred inside it (Excalidraw's bound text position for a middle-aligned label). */\nexport function placeLabel(label: ExElement, container: ExElement): ExElement {\n const [x1, y1, x2, y2] = absoluteCoords(container);\n const cx = (x1 + x2) / 2;\n const cy = (y1 + y2) / 2;\n return { ...label, x: cx - label.width / 2, y: cy - label.height / 2, angle: container.angle || 0 };\n}\n\n/** New text for a text element (deleted when empty). */\nexport function editText(scene: Scene, id: string, value: string): ExElement[] {\n const element = scene.get(id);\n if (!element) return [];\n const text = normalizeText(value);\n if (!text.trim()) return deleteElements(scene, [id]);\n const metrics = measureText(text, element.fontSize ?? 20, element.fontFamily ?? 5, element.lineHeight ?? 1.25);\n let next = bump(element, { text, originalText: text, width: metrics.width, height: metrics.height });\n if (element.textAlign === 'center' && !element.containerId)\n next = { ...next, x: element.x + (element.width - metrics.width) / 2 };\n else if (element.textAlign === 'right' && !element.containerId)\n next = { ...next, x: element.x + element.width - metrics.width };\n const container = element.containerId ? scene.get(element.containerId) : undefined;\n if (container) next = placeLabel(next, container);\n return [next];\n}\n\n/** A new picture of a file at a place and size. */\nexport function createImage(\n scene: Scene,\n fileId: string,\n x: number,\n y: number,\n width: number,\n height: number,\n style: ItemStyle,\n): ExElement {\n return newImage({\n x,\n y,\n width,\n height,\n style,\n fileId,\n index: indexAfter(scene.lastIndex()),\n frameId: frameFor(scene, [x, y, x + width, y + height]),\n });\n}\n\n// ------------------------------------------------------------------ transform\n\n/** Arrows bound to the changed shapes, re-aimed (those moving along are left as they are). */\nfunction followers(scene: Scene, updated: Map<string, ExElement>, moving: ReadonlySet<string>): ExElement[] {\n const lookup = (id: string) => updated.get(id) ?? scene.get(id);\n const arrows = new Set<string>();\n for (const element of updated.values())\n for (const bound of element.boundElements ?? [])\n if (bound.type === 'arrow' && !moving.has(bound.id)) arrows.add(bound.id);\n const result: ExElement[] = [];\n for (const id of arrows) {\n const arrow = scene.get(id);\n if (!arrow || arrow.isDeleted) continue;\n const next = followBindings(arrow, lookup);\n if (next !== arrow)\n result.push(bump(arrow, { x: next.x, y: next.y, points: next.points, width: next.width, height: next.height }));\n }\n // Labels of changed containers stay centred.\n for (const element of updated.values()) {\n for (const bound of element.boundElements ?? []) {\n if (bound.type !== 'text' || updated.has(bound.id)) continue;\n const label = scene.get(bound.id);\n if (label && !label.isDeleted) {\n const placed = placeLabel(label, element);\n if (placed.x !== label.x || placed.y !== label.y || placed.angle !== label.angle)\n result.push(bump(label, { x: placed.x, y: placed.y, angle: placed.angle }));\n }\n }\n }\n return result;\n}\n\n/** An arrow moved on its own leaves the shapes it was bound to. */\nfunction unbindMoved(\n scene: Scene,\n arrow: ExElement,\n moving: ReadonlySet<string>,\n): { arrow: ExElement; shapes: ExElement[] } {\n const shapes: ExElement[] = [];\n let next = arrow;\n for (const end of ['startBinding', 'endBinding'] as const) {\n const binding = arrow[end];\n if (!binding || moving.has(binding.elementId)) continue;\n next = { ...next, [end]: null };\n const shape = scene.get(binding.elementId);\n const stillBound =\n end === 'startBinding'\n ? arrow.endBinding?.elementId === binding.elementId && !moving.has(binding.elementId)\n : false;\n if (shape && !stillBound && !shapes.some((s) => s.id === shape.id))\n shapes.push(bump(shape, { boundElements: (shape.boundElements ?? []).filter((bound) => bound.id !== arrow.id) }));\n }\n return { arrow: next, shapes };\n}\n\n/** The elements moved by (`dx`, `dy`) with their labels and bound arrows; frames take and drop what moves in and out. */\nexport function moveElements(scene: Scene, ids: readonly string[], dx: number, dy: number): ExElement[] {\n const moving = new Set(movingSet(scene, ids));\n const updated = new Map<string, ExElement>();\n const extra: ExElement[] = [];\n for (const id of moving) {\n const element = scene.get(id);\n if (!element || element.locked) continue;\n let next = { ...element, x: element.x + dx, y: element.y + dy };\n if (element.type === 'arrow') {\n const result = unbindMoved(scene, next, moving);\n next = result.arrow;\n extra.push(...result.shapes);\n }\n updated.set(id, next);\n }\n // A moved element enters or leaves frames.\n for (const [id, element] of updated) {\n if (isFrame(element) || element.containerId) continue;\n if (element.frameId && moving.has(element.frameId)) continue;\n const frame = frameFor(scene, elementBounds(element));\n if (frame !== element.frameId && frame !== id) updated.set(id, { ...element, frameId: frame });\n }\n const bumped = new Map([...updated].map(([id, element]) => [id, bump(scene.get(id)!, element)] as const));\n for (const shape of extra) if (!bumped.has(shape.id)) bumped.set(shape.id, shape);\n return [...bumped.values(), ...followers(scene, bumped, moving)];\n}\n\n/**\n * Resizes the selection from the frame `from` to `to` (both in the frame's own unrotated space; `angle` is the frame's\n * rotation — a single rotated element).\n */\nexport function resizeElements(scene: Scene, ids: readonly string[], from: Bounds, to: Bounds, angle = 0): ExElement[] {\n const fw = from[2] - from[0] || 1;\n const fh = from[3] - from[1] || 1;\n const sx = (to[2] - to[0]) / fw;\n const sy = (to[3] - to[1]) / fh;\n if (!Number.isFinite(sx) || !Number.isFinite(sy) || Math.abs(sx) < 1e-3 || Math.abs(sy) < 1e-3) return [];\n const moving = new Set(movingSet(scene, ids));\n const oldCentre: Point = [(from[0] + from[2]) / 2, (from[1] + from[3]) / 2];\n const updated = new Map<string, ExElement>();\n for (const id of moving) {\n const element = scene.get(id);\n if (\n !element ||\n element.locked ||\n (element.type === 'text' && element.containerId && moving.has(element.containerId))\n )\n continue;\n const [x1, y1, x2, y2, cx, cy] = absoluteCoords(element);\n // The element's centre in the frame's space, mapped, then back to the scene.\n const local = angle ? rotate([cx, cy], oldCentre, -angle) : ([cx, cy] as Point);\n const mapped: Point = [to[0] + (local[0] - from[0]) * sx, to[1] + (local[1] - from[1]) * sy];\n const newCentre = angle ? rotate(mapped, oldCentre, angle) : mapped;\n const w = Math.abs((x2 - x1) * sx);\n const h = Math.abs((y2 - y1) * sy);\n let next: ExElement;\n if (isPointsElement(element)) {\n const points = (element.points ?? []).map(([px, py]) => [px * sx, py * sy] as Point);\n const size = sizeOfPoints(points);\n const minX = Math.min(...points.map((p) => p[0]));\n const minY = Math.min(...points.map((p) => p[1]));\n next = {\n ...element,\n points,\n width: size.width,\n height: size.height,\n x: newCentre[0] - size.width / 2 - minX,\n y: newCentre[1] - size.height / 2 - minY,\n };\n } else if (element.type === 'text') {\n const scale =\n Math.max(Math.abs(sx), Math.abs(sy)) === Math.abs(sx) && ids.length === 1\n ? Math.abs(sx)\n : Math.min(Math.abs(sx), Math.abs(sy));\n const fontSize = Math.max(1, (element.fontSize ?? 20) * scale);\n const metrics = measureText(element.text ?? '', fontSize, element.fontFamily ?? 5, element.lineHeight ?? 1.25);\n next = {\n ...element,\n fontSize,\n width: metrics.width,\n height: metrics.height,\n x: newCentre[0] - metrics.width / 2,\n y: newCentre[1] - metrics.height / 2,\n };\n } else {\n next = { ...element, width: w, height: h, x: newCentre[0] - w / 2, y: newCentre[1] - h / 2 };\n }\n updated.set(id, next);\n }\n // Labels follow their containers.\n for (const [id, element] of updated) {\n for (const bound of element.boundElements ?? []) {\n if (bound.type !== 'text') continue;\n const label = updated.get(bound.id) ?? scene.get(bound.id);\n if (label && !label.isDeleted) updated.set(bound.id, placeLabel(label, element));\n }\n void id;\n }\n const bumped = new Map([...updated].map(([id, element]) => [id, bump(scene.get(id)!, element)] as const));\n return [...bumped.values(), ...followers(scene, bumped, moving)];\n}\n\n/** The elements turned by `delta` (radians) about a pivot. */\nexport function rotateElements(scene: Scene, ids: readonly string[], delta: number, pivot: Point): ExElement[] {\n const moving = new Set(movingSet(scene, ids));\n const updated = new Map<string, ExElement>();\n for (const id of moving) {\n const element = scene.get(id);\n if (!element || element.locked || isFrame(element)) continue;\n const [, , , , cx, cy] = absoluteCoords(element);\n const [nx, ny] = rotate([cx, cy], pivot, delta);\n let angle = ((element.angle || 0) + delta) % (Math.PI * 2);\n if (angle < 0) angle += Math.PI * 2;\n updated.set(id, { ...element, x: element.x + (nx - cx), y: element.y + (ny - cy), angle });\n }\n const bumped = new Map([...updated].map(([id, element]) => [id, bump(scene.get(id)!, element)] as const));\n return [...bumped.values(), ...followers(scene, bumped, moving)];\n}\n\n/** Moves one point of a line/arrow (index in its points) to an absolute position; arrows re-bind at their ends. */\nexport function movePoint(scene: Scene, id: string, index: number, x: number, y: number, zoom = 1): ExElement[] {\n const element = scene.get(id);\n if (!element || !isLinear(element) || !element.points?.[index]) return [];\n const [, , , , cx, cy] = absoluteCoords(element);\n const absolute = element.points.map(([px, py]) =>\n rotate([px + element.x, py + element.y], [cx, cy], element.angle || 0),\n );\n absolute[index] = [x, y];\n const [ox, oy] = absolute[0];\n const points = absolute.map(([px, py]) => [px - ox, py - oy] as Point);\n const size = sizeOfPoints(points);\n let next: ExElement = { ...element, x: ox, y: oy, angle: 0, points, width: size.width, height: size.height };\n const touched: ExElement[] = [];\n if (element.type === 'arrow' && (index === 0 || index === absolute.length - 1)) {\n const key = index === 0 ? 'startBinding' : 'endBinding';\n const previous = element[key];\n const target = bindableAt(scene, [x, y], 12 / zoom, id);\n if (previous && previous.elementId !== target?.id) {\n const shape = scene.get(previous.elementId);\n const other = index === 0 ? element.endBinding : element.startBinding;\n if (shape && other?.elementId !== shape.id)\n touched.push(bump(shape, { boundElements: (shape.boundElements ?? []).filter((bound) => bound.id !== id) }));\n }\n next = { ...next, [key]: target ? { elementId: target.id, focus: 0, gap: BINDING_GAP } : null };\n if (target && previous?.elementId !== target.id && !(target.boundElements ?? []).some((bound) => bound.id === id))\n touched.push(bump(target, { boundElements: [...(target.boundElements ?? []), { id, type: 'arrow' }] }));\n if (target) next = followBindings(next, (other) => touched.find((t) => t.id === other) ?? scene.get(other));\n }\n return [bump(element, next), ...touched];\n}\n\n// ------------------------------------------------------------------ delete, style, order, duplicate\n\n/** The elements deleted with their labels; arrows bound to them let go. */\nexport function deleteElements(scene: Scene, ids: readonly string[]): ExElement[] {\n const doomed = new Set<string>();\n for (const id of ids) {\n const element = scene.get(id);\n if (!element || element.isDeleted) continue;\n doomed.add(id);\n for (const bound of element.boundElements ?? []) if (bound.type === 'text') doomed.add(bound.id);\n if (isFrame(element)) for (const child of scene.visible()) if (child.frameId === id) doomed.add(child.id);\n }\n const result = new Map<string, ExElement>();\n for (const id of doomed) result.set(id, bump(scene.get(id)!, { isDeleted: true }));\n // Arrows lose their bindings to deleted shapes; shapes forget deleted arrows and labels.\n for (const element of scene.visible()) {\n if (doomed.has(element.id)) continue;\n let changes: Partial<ExElement> = {};\n if (element.startBinding && doomed.has(element.startBinding.elementId))\n changes = { ...changes, startBinding: null };\n if (element.endBinding && doomed.has(element.endBinding.elementId)) changes = { ...changes, endBinding: null };\n if (element.boundElements?.some((bound) => doomed.has(bound.id)))\n changes = { ...changes, boundElements: element.boundElements.filter((bound) => !doomed.has(bound.id)) };\n if (element.containerId && doomed.has(element.containerId)) changes = { ...changes, containerId: null };\n if (Object.keys(changes).length) result.set(element.id, bump(element, changes));\n }\n return [...result.values()];\n}\n\n/** Style changes for the selection (`text*`/`font*` only reach texts, arrowheads only arrows…). */\nexport function styleElements(scene: Scene, ids: readonly string[], patch: Partial<ExElement>): ExElement[] {\n const result: ExElement[] = [];\n const targets = new Set(ids);\n for (const id of ids)\n for (const bound of scene.get(id)?.boundElements ?? []) if (bound.type === 'text') targets.add(bound.id);\n for (const id of targets) {\n const element = scene.get(id);\n if (!element || element.isDeleted || element.locked) continue;\n const changes: Partial<ExElement> = {};\n for (const [key, value] of Object.entries(patch) as [keyof ExElement, unknown][]) {\n if ((key === 'fontSize' || key === 'fontFamily' || key === 'textAlign') && element.type !== 'text') continue;\n if ((key === 'startArrowhead' || key === 'endArrowhead') && element.type !== 'arrow') continue;\n if (\n (key === 'backgroundColor' || key === 'fillStyle') &&\n (element.type === 'text' || element.type === 'image' || element.type === 'arrow')\n )\n continue;\n if (key === 'strokeColor' && element.type === 'image') continue;\n if (\n key === 'roundness' &&\n !(\n element.type === 'rectangle' ||\n element.type === 'diamond' ||\n element.type === 'line' ||\n element.type === 'arrow' ||\n element.type === 'image'\n )\n )\n continue;\n (changes as Record<string, unknown>)[key as string] = value;\n }\n if (!Object.keys(changes).length) continue;\n if (element.type === 'text' && (changes.fontSize !== undefined || changes.fontFamily !== undefined)) {\n const fontSize = (changes.fontSize as number | undefined) ?? element.fontSize ?? 20;\n const fontFamily = (changes.fontFamily as number | undefined) ?? element.fontFamily ?? 5;\n const lineHeight =\n changes.fontFamily !== undefined\n ? ({ 5: 1.25, 6: 1.35, 7: 1.15, 8: 1.25, 1: 1.25, 2: 1.15, 3: 1.2, 9: 1.15 }[fontFamily] ?? 1.25)\n : (element.lineHeight ?? 1.25);\n const metrics = measureText(element.text ?? '', fontSize, fontFamily, lineHeight);\n Object.assign(changes, { lineHeight, width: metrics.width, height: metrics.height });\n const container = element.containerId ? scene.get(element.containerId) : undefined;\n if (container) Object.assign(changes, placeLabel({ ...element, ...changes } as ExElement, container));\n }\n result.push(bump(element, changes));\n }\n return result;\n}\n\n/** A move in the stacking order. */\nexport type OrderMove = 'front' | 'back' | 'forward' | 'backward';\n\n/** New fractional indices for the selection (Excalidraw's z-index actions). */\nexport function reorder(scene: Scene, ids: readonly string[], move: OrderMove): ExElement[] {\n const all = scene.all().filter((element) => !element.isDeleted);\n const chosen = all.filter((element) => ids.includes(element.id));\n if (!chosen.length) return [];\n const rest = all.filter((element) => !ids.includes(element.id));\n let lower: string | null = null;\n let upper: string | null = null;\n if (move === 'front') lower = rest.length ? rest[rest.length - 1].index : null;\n else if (move === 'back') upper = rest.length ? rest[0].index : null;\n else if (move === 'forward') {\n const top = all.indexOf(chosen[chosen.length - 1]);\n const above = all.slice(top + 1).find((element) => !ids.includes(element.id));\n if (!above) return [];\n const position = rest.indexOf(above);\n lower = above.index;\n upper = rest[position + 1]?.index ?? null;\n } else {\n const bottom = all.indexOf(chosen[0]);\n const below = [...all.slice(0, bottom)].reverse().find((element) => !ids.includes(element.id));\n if (!below) return [];\n const position = rest.indexOf(below);\n upper = below.index;\n lower = rest[position - 1]?.index ?? null;\n }\n const keys = indicesBetween(lower, upper, chosen.length);\n return chosen.sort(compareOrder).map((element, i) => bump(element, { index: keys[i] }));\n}\n\n/** Copies of the selection 10 px down-right, above everything, with fresh ids (bindings to copied shapes kept). */\nexport function duplicate(\n scene: Scene,\n ids: readonly string[],\n offset = 10,\n): { elements: ExElement[]; selected: string[] } {\n const moving = movingSet(scene, ids);\n const originals = scene.all().filter((element) => moving.includes(element.id) && !element.isDeleted);\n const idMap = new Map(originals.map((element) => [element.id, randomId()]));\n const groupMap = new Map<string, string>();\n const keys = indicesBetween(scene.lastIndex(), null, originals.length);\n const elements = originals.map((element, i) => {\n const copy: ExElement = {\n ...element,\n id: idMap.get(element.id)!,\n x: element.x + offset,\n y: element.y + offset,\n index: keys[i],\n seed: Math.floor(Math.random() * 2 ** 31),\n version: 1,\n versionNonce: Math.floor(Math.random() * 2 ** 31),\n updated: Date.now(),\n groupIds: (element.groupIds ?? []).map(\n (group) => groupMap.get(group) ?? groupMap.set(group, randomId()).get(group)!,\n ),\n boundElements: element.boundElements\n ? element.boundElements\n .filter((bound) => idMap.has(bound.id))\n .map((bound) => ({ ...bound, id: idMap.get(bound.id)! }))\n : null,\n containerId: element.containerId ? (idMap.get(element.containerId) ?? null) : element.containerId,\n frameId: element.frameId ? (idMap.get(element.frameId) ?? element.frameId) : null,\n };\n if (copy.startBinding)\n copy.startBinding = idMap.has(copy.startBinding.elementId)\n ? { ...copy.startBinding, elementId: idMap.get(copy.startBinding.elementId)! }\n : null;\n if (copy.endBinding)\n copy.endBinding = idMap.has(copy.endBinding.elementId)\n ? { ...copy.endBinding, elementId: idMap.get(copy.endBinding.elementId)! }\n : null;\n return copy;\n });\n return { elements, selected: ids.map((id) => idMap.get(id)).filter((id): id is string => Boolean(id)) };\n}\n\n/** Elements the eraser path touches (labels erase their containers and vice versa). */\nexport function erasedBy(scene: Scene, flat: readonly number[], threshold: number): string[] {\n const hit = new Set<string>();\n const visible = scene.visible();\n for (let i = 0; i + 1 < flat.length; i += 2) {\n const point: Point = [flat[i], flat[i + 1]];\n for (const element of visible) {\n if (hit.has(element.id) || element.locked) continue;\n if (hitElement(element, point, threshold)) {\n hit.add(element.id);\n if (element.containerId) hit.add(element.containerId);\n }\n }\n }\n return [...hit];\n}\n\n/** Groups the selection (a new outermost group id). */\nexport function group(scene: Scene, ids: readonly string[]): ExElement[] {\n if (ids.length < 2) return [];\n const groupId = randomId();\n return ids\n .map((id) => scene.get(id))\n .filter((element): element is ExElement => Boolean(element))\n .map((element) => bump(element, { groupIds: [...(element.groupIds ?? []), groupId] }));\n}\n\n/** The elements out of their outermost group. */\nexport function ungroup(scene: Scene, ids: readonly string[]): ExElement[] {\n return ids\n .map((id) => scene.get(id))\n .filter((element): element is ExElement => Boolean(element?.groupIds?.length))\n .map((element) => bump(element, { groupIds: element.groupIds.slice(0, -1) }));\n}\n\n/** The elements locked or unlocked. */\nexport function lockElements(scene: Scene, ids: readonly string[], locked: boolean): ExElement[] {\n return ids\n .map((id) => scene.get(id))\n .filter((element): element is ExElement => Boolean(element))\n .map((element) => bump(element, { locked }));\n}\n"],"names":["BINDING_GAP","expandSelection","scene","ids","result","Set","visible","id","_element_groupIds","element","group","_other_groupIds","other","movingSet","_element_boundElements","bound","isFrame","child","hitTest","point","threshold","selected","i","x1","y1","x2","y2","cx","cy","absoluteCoords","p","rotate","hitElement","_scene_get","inBox","box","boundsContain","elementBounds","frameFor","bounds","frame","createShape","type","style","options","indexAfter","newFrame","newShape","createLinear","absolute","zoom","x","y","newLinear","px","py","Math","touched","Map","end","_touched_get","_shape_boundElements","_shape_boundElements1","target","bindableAt","binding","shape","bump","lookup","followBindings","except","isBindable","arrow","_arrow_points","points","start","undefined","centre","coords","snap","from","gap","c","hit","intersectOutline","outlineOf","length","changed","last","_arrow_startBinding","next","_arrow_endBinding","ox","oy","relative","size","sizeOfPoints","createFreeDraw","flat","pressures","newFreeDraw","createText","text","container","_container_index","_container_boundElements","newText","label","placed","placeLabel","editText","value","_element_fontSize","_element_fontFamily","_element_lineHeight","normalizeText","deleteElements","metrics","measureText","createImage","fileId","width","height","newImage","followers","updated","moving","_updated_get","arrows","_element_boundElements1","unbindMoved","shapes","stillBound","s","moveElements","dx","dy","extra","bumped","resizeElements","to","angle","fw","fh","sx","sy","Number","oldCentre","local","mapped","newCentre","w","h","isPointsElement","_element_points","minX","minY","_element_text","scale","fontSize","rotateElements","delta","pivot","nx","ny","movePoint","index","isLinear","_target_boundElements","_target_boundElements1","key","previous","_touched_find","t","doomed","changes","Object","styleElements","patch","targets","_ref1","_changes_fontSize","_ref2","_changes_fontFamily","_fontFamily","fontFamily","lineHeight","reorder","move","all","chosen","rest","lower","upper","_rest_","top","above","position","_rest_1","bottom","below","keys","indicesBetween","compareOrder","duplicate","offset","originals","idMap","randomId","groupMap","elements","_idMap_get","_idMap_get1","copy","Date","_groupMap_get","Boolean","erasedBy","groupId","ungroup","lockElements","locked"],"mappings":";;AAwCA,MAAMA,cAAc;AAGb,SAASC,gBAAgBC,KAAY,EAAEC,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KACtB,MAAM,CAAC,CAACE;YAA0CD;eAARgN,QAAQhN,QAAAA,UAAAA,KAAAA,IAAAA,QAAAA,CAAAA,oBAAAA,QAAS,QAAQ,AAAD,IAAhBA,KAAAA,IAAAA,kBAAmB,MAAM;OAC3E,GAAG,CAAC,CAACC,UAAY0D,KAAK1D,SAAS;YAAE,UAAUA,QAAQ,QAAQ,CAAC,KAAK,CAAC,GAAG;QAAI;AAC9E;AAGO,SAASmN,aAAa1N,KAAY,EAAEC,GAAsB,EAAE0N,MAAe;IAChF,OAAO1N,IACJ,GAAG,CAAC,CAACI,KAAOL,MAAM,GAAG,CAACK,KACtB,MAAM,CAAC,CAACE,UAAkC+M,QAAQ/M,UAClD,GAAG,CAAC,CAACA,UAAY0D,KAAK1D,SAAS;YAAEoN;QAAO;AAC7C"}
@@ -0,0 +1,394 @@
1
+ import { generateKeyBetween, generateNKeysBetween } from "fractional-indexing";
2
+ const ROUGHNESS = {
3
+ architect: 0,
4
+ artist: 1,
5
+ cartoonist: 2
6
+ };
7
+ const ROUNDNESS = {
8
+ LEGACY: 1,
9
+ PROPORTIONAL_RADIUS: 2,
10
+ ADAPTIVE_RADIUS: 3
11
+ };
12
+ const DEFAULT_PROPORTIONAL_RADIUS = 0.25;
13
+ const DEFAULT_ADAPTIVE_RADIUS = 32;
14
+ const LINE_CONFIRM_THRESHOLD = 8;
15
+ const FONT_FAMILY = {
16
+ Virgil: 1,
17
+ Helvetica: 2,
18
+ Cascadia: 3,
19
+ Excalifont: 5,
20
+ Nunito: 6,
21
+ 'Lilita One': 7,
22
+ 'Comic Shanns': 8,
23
+ 'Liberation Sans': 9
24
+ };
25
+ const DEFAULT_FONT_SIZE = 20;
26
+ const DEFAULT_FONT_FAMILY = FONT_FAMILY.Excalifont;
27
+ const BOUND_TEXT_PADDING = 5;
28
+ const FONT_METRICS = {
29
+ 5: {
30
+ unitsPerEm: 1000,
31
+ ascender: 886,
32
+ descender: -374,
33
+ lineHeight: 1.25
34
+ },
35
+ 6: {
36
+ unitsPerEm: 1000,
37
+ ascender: 1011,
38
+ descender: -353,
39
+ lineHeight: 1.35
40
+ },
41
+ 7: {
42
+ unitsPerEm: 1000,
43
+ ascender: 923,
44
+ descender: -220,
45
+ lineHeight: 1.15
46
+ },
47
+ 8: {
48
+ unitsPerEm: 1000,
49
+ ascender: 750,
50
+ descender: -250,
51
+ lineHeight: 1.25
52
+ },
53
+ 1: {
54
+ unitsPerEm: 1000,
55
+ ascender: 886,
56
+ descender: -374,
57
+ lineHeight: 1.25
58
+ },
59
+ 2: {
60
+ unitsPerEm: 2048,
61
+ ascender: 1577,
62
+ descender: -471,
63
+ lineHeight: 1.15
64
+ },
65
+ 3: {
66
+ unitsPerEm: 2048,
67
+ ascender: 1900,
68
+ descender: -480,
69
+ lineHeight: 1.2
70
+ },
71
+ 9: {
72
+ unitsPerEm: 2048,
73
+ ascender: 1854,
74
+ descender: -434,
75
+ lineHeight: 1.15
76
+ }
77
+ };
78
+ const FRAME_STYLE = {
79
+ strokeColor: '#bbb',
80
+ strokeWidth: 2,
81
+ strokeStyle: 'solid',
82
+ fillStyle: 'solid',
83
+ roughness: 0,
84
+ roundness: null,
85
+ backgroundColor: 'transparent',
86
+ radius: 8,
87
+ nameOffsetY: 3,
88
+ nameColorLightTheme: '#999999',
89
+ nameColorDarkTheme: '#7a7a7a',
90
+ nameFontSize: 14,
91
+ nameLineHeight: 1.25
92
+ };
93
+ const DEFAULT_STYLE = {
94
+ strokeColor: '#1e1e1e',
95
+ backgroundColor: 'transparent',
96
+ fillStyle: 'solid',
97
+ strokeWidth: 2,
98
+ strokeStyle: 'solid',
99
+ roughness: ROUGHNESS.artist,
100
+ opacity: 100,
101
+ roundness: 'round',
102
+ fontSize: DEFAULT_FONT_SIZE,
103
+ fontFamily: DEFAULT_FONT_FAMILY,
104
+ textAlign: 'left',
105
+ startArrowhead: null,
106
+ endArrowhead: 'arrow'
107
+ };
108
+ const STROKE_COLORS = [
109
+ '#1e1e1e',
110
+ '#e03131',
111
+ '#2f9e44',
112
+ '#1971c2',
113
+ '#f08c00',
114
+ '#9c36b5',
115
+ '#0c8599',
116
+ '#846358'
117
+ ];
118
+ const BACKGROUND_COLORS = [
119
+ 'transparent',
120
+ '#ffc9c9',
121
+ '#b2f2bb',
122
+ '#a5d8ff',
123
+ '#ffec99',
124
+ '#eebefa',
125
+ '#99e9f2',
126
+ '#eaddd7'
127
+ ];
128
+ const ID_ALPHABET = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
129
+ function randomBytes(count) {
130
+ const bytes = new Uint8Array(count);
131
+ const crypto = globalThis.crypto;
132
+ try {
133
+ if (null == crypto ? void 0 : crypto.getRandomValues) return crypto.getRandomValues(bytes);
134
+ } catch {}
135
+ for(let i = 0; i < count; i++)bytes[i] = Math.floor(256 * Math.random());
136
+ return bytes;
137
+ }
138
+ function randomId() {
139
+ const bytes = randomBytes(21);
140
+ let id = '';
141
+ for(let i = 0; i < 21; i++)id += ID_ALPHABET[63 & bytes[i]];
142
+ return id;
143
+ }
144
+ function randomInteger() {
145
+ return Math.floor(Math.random() * 2 ** 31);
146
+ }
147
+ function randomFileId() {
148
+ return Array.from(randomBytes(20), (byte)=>byte.toString(16).padStart(2, '0')).join('');
149
+ }
150
+ function defaultRoundness(type, style) {
151
+ if ('round' !== style.roundness) return null;
152
+ if ('line' === type || 'arrow' === type || 'diamond' === type) return {
153
+ type: ROUNDNESS.PROPORTIONAL_RADIUS
154
+ };
155
+ if ('rectangle' === type || 'image' === type || 'embeddable' === type || 'iframe' === type) return {
156
+ type: ROUNDNESS.ADAPTIVE_RADIUS
157
+ };
158
+ return null;
159
+ }
160
+ function base(type, options) {
161
+ var _options_id, _options_width, _options_height, _options_angle, _options_groupIds, _options_frameId, _options_index;
162
+ const style = options.style;
163
+ return {
164
+ id: null != (_options_id = options.id) ? _options_id : randomId(),
165
+ type,
166
+ x: options.x,
167
+ y: options.y,
168
+ width: null != (_options_width = options.width) ? _options_width : 0,
169
+ height: null != (_options_height = options.height) ? _options_height : 0,
170
+ angle: null != (_options_angle = options.angle) ? _options_angle : 0,
171
+ strokeColor: style.strokeColor,
172
+ backgroundColor: style.backgroundColor,
173
+ fillStyle: style.fillStyle,
174
+ strokeWidth: style.strokeWidth,
175
+ strokeStyle: style.strokeStyle,
176
+ roughness: style.roughness,
177
+ opacity: style.opacity,
178
+ groupIds: null != (_options_groupIds = options.groupIds) ? _options_groupIds : [],
179
+ frameId: null != (_options_frameId = options.frameId) ? _options_frameId : null,
180
+ index: null != (_options_index = options.index) ? _options_index : null,
181
+ roundness: void 0 === options.roundness ? defaultRoundness(type, style) : options.roundness,
182
+ seed: randomInteger(),
183
+ version: 1,
184
+ versionNonce: randomInteger(),
185
+ isDeleted: false,
186
+ boundElements: null,
187
+ updated: Date.now(),
188
+ link: null,
189
+ locked: false
190
+ };
191
+ }
192
+ function newShape(type, options) {
193
+ return base(type, options);
194
+ }
195
+ function newFrame(options) {
196
+ var _options_name;
197
+ const style = {
198
+ ...DEFAULT_STYLE,
199
+ ...FRAME_STYLE,
200
+ roundness: 'sharp',
201
+ fillStyle: 'solid',
202
+ strokeStyle: 'solid',
203
+ opacity: 100
204
+ };
205
+ return {
206
+ ...base('frame', {
207
+ ...options,
208
+ style,
209
+ roundness: null
210
+ }),
211
+ name: null != (_options_name = options.name) ? _options_name : null
212
+ };
213
+ }
214
+ function newLinear(type, options) {
215
+ var _options_startArrowhead, _options_endArrowhead;
216
+ const size = sizeOfPoints(options.points);
217
+ const element = {
218
+ ...base(type, {
219
+ ...options,
220
+ width: size.width,
221
+ height: size.height
222
+ }),
223
+ points: options.points,
224
+ lastCommittedPoint: null,
225
+ startBinding: null,
226
+ endBinding: null,
227
+ startArrowhead: 'arrow' === type ? null != (_options_startArrowhead = options.startArrowhead) ? _options_startArrowhead : null : null,
228
+ endArrowhead: 'arrow' === type ? null != (_options_endArrowhead = options.endArrowhead) ? _options_endArrowhead : null : null
229
+ };
230
+ if ('arrow' === type) element.elbowed = false;
231
+ return element;
232
+ }
233
+ function newFreeDraw(options) {
234
+ const size = sizeOfPoints(options.points);
235
+ return {
236
+ ...base('freedraw', {
237
+ ...options,
238
+ width: size.width,
239
+ height: size.height,
240
+ roundness: null
241
+ }),
242
+ points: options.points,
243
+ pressures: options.pressures,
244
+ simulatePressure: options.simulatePressure,
245
+ lastCommittedPoint: options.points.length ? options.points[options.points.length - 1] : null
246
+ };
247
+ }
248
+ function newText(options) {
249
+ var _options_verticalAlign, _options_containerId, _options_autoResize;
250
+ const fontFamily = options.style.fontFamily || DEFAULT_FONT_FAMILY;
251
+ const fontSize = options.style.fontSize || DEFAULT_FONT_SIZE;
252
+ const lineHeight = lineHeightOf(fontFamily);
253
+ const text = normalizeText(options.text);
254
+ const metrics = measureText(text, fontSize, fontFamily, lineHeight);
255
+ return {
256
+ ...base('text', {
257
+ ...options,
258
+ roundness: null
259
+ }),
260
+ text,
261
+ fontSize,
262
+ fontFamily,
263
+ textAlign: options.style.textAlign,
264
+ verticalAlign: null != (_options_verticalAlign = options.verticalAlign) ? _options_verticalAlign : 'top',
265
+ width: false === options.autoResize && options.width ? options.width : metrics.width,
266
+ height: metrics.height,
267
+ containerId: null != (_options_containerId = options.containerId) ? _options_containerId : null,
268
+ originalText: text,
269
+ autoResize: null != (_options_autoResize = options.autoResize) ? _options_autoResize : true,
270
+ lineHeight
271
+ };
272
+ }
273
+ function newImage(options) {
274
+ return {
275
+ ...base('image', options),
276
+ strokeColor: 'transparent',
277
+ status: 'pending',
278
+ fileId: options.fileId,
279
+ scale: [
280
+ 1,
281
+ 1
282
+ ],
283
+ crop: null
284
+ };
285
+ }
286
+ function bump(element, changes = {}) {
287
+ return {
288
+ ...element,
289
+ ...changes,
290
+ version: element.version + 1,
291
+ versionNonce: randomInteger(),
292
+ updated: Date.now()
293
+ };
294
+ }
295
+ function sizeOfPoints(points) {
296
+ if (!points.length) return {
297
+ width: 0,
298
+ height: 0
299
+ };
300
+ let minX = 1 / 0;
301
+ let minY = 1 / 0;
302
+ let maxX = -1 / 0;
303
+ let maxY = -1 / 0;
304
+ for (const [x, y] of points){
305
+ if (x < minX) minX = x;
306
+ if (y < minY) minY = y;
307
+ if (x > maxX) maxX = x;
308
+ if (y > maxY) maxY = y;
309
+ }
310
+ return {
311
+ width: maxX - minX,
312
+ height: maxY - minY
313
+ };
314
+ }
315
+ function lineHeightOf(fontFamily) {
316
+ var _FONT_METRICS_fontFamily;
317
+ return (null != (_FONT_METRICS_fontFamily = FONT_METRICS[fontFamily]) ? _FONT_METRICS_fontFamily : FONT_METRICS[5]).lineHeight;
318
+ }
319
+ function verticalOffset(fontFamily, fontSize, lineHeightPx) {
320
+ var _FONT_METRICS_fontFamily;
321
+ const metrics = null != (_FONT_METRICS_fontFamily = FONT_METRICS[fontFamily]) ? _FONT_METRICS_fontFamily : FONT_METRICS[1];
322
+ const em = fontSize / metrics.unitsPerEm;
323
+ const lineGap = (lineHeightPx - em * metrics.ascender + em * metrics.descender) / 2;
324
+ return em * metrics.ascender + lineGap;
325
+ }
326
+ function normalizeText(text) {
327
+ return text.replace(/\t/g, ' ').replace(/\r?\n|\r/g, '\n');
328
+ }
329
+ function textWidth(line, fontSize, fontFamily) {
330
+ const mono = fontFamily === FONT_FAMILY.Cascadia || fontFamily === FONT_FAMILY['Comic Shanns'];
331
+ let width = 0;
332
+ for (const char of line){
333
+ var _char_codePointAt;
334
+ const code = null != (_char_codePointAt = char.codePointAt(0)) ? _char_codePointAt : 0;
335
+ if (mono) width += code >= 0x2e80 ? 1 : 0.6;
336
+ else if (' ' === char) width += 0.3;
337
+ else if (code >= 0x2e80 && code < 0xd7ff) width += 1;
338
+ else if (code >= 0x0600 && code <= 0x06ff) width += 0.45;
339
+ else if (/[mwMW@]/.test(char)) width += 0.85;
340
+ else if (/[il.,;:'!|ftj]/.test(char)) width += 0.3;
341
+ else if (/[A-Z0-9]/.test(char)) width += 0.62;
342
+ else width += 0.52;
343
+ }
344
+ return width * fontSize;
345
+ }
346
+ function measureText(text, fontSize, fontFamily, lineHeight) {
347
+ const lines = text.split('\n');
348
+ const width = Math.max(...lines.map((line)=>textWidth(line, fontSize, fontFamily)));
349
+ return {
350
+ width,
351
+ height: lines.length * fontSize * lineHeight
352
+ };
353
+ }
354
+ function indexAfter(last) {
355
+ try {
356
+ return generateKeyBetween(null != last ? last : null, null);
357
+ } catch {
358
+ return generateKeyBetween(null, null);
359
+ }
360
+ }
361
+ function indicesBetween(lower, upper, count) {
362
+ try {
363
+ return generateNKeysBetween(null != lower ? lower : null, null != upper ? upper : null, count);
364
+ } catch {
365
+ return generateNKeysBetween(null != lower ? lower : null, null, count);
366
+ }
367
+ }
368
+ function compareOrder(a, b) {
369
+ if (a.index && b.index) {
370
+ if (a.index < b.index) return -1;
371
+ if (a.index > b.index) return 1;
372
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
373
+ }
374
+ if (a.index) return -1;
375
+ if (b.index) return 1;
376
+ return 0;
377
+ }
378
+ function isLinear(element) {
379
+ return 'arrow' === element.type || 'line' === element.type;
380
+ }
381
+ function isPointsElement(element) {
382
+ return 'arrow' === element.type || 'line' === element.type || 'freedraw' === element.type;
383
+ }
384
+ function isFrame(element) {
385
+ return 'frame' === element.type || 'magicframe' === element.type;
386
+ }
387
+ function isTransparent(color) {
388
+ if (!color) return true;
389
+ const value = color.trim().toLowerCase();
390
+ return 'transparent' === value || 'none' === value || 5 === value.length && value.endsWith('0') && value.startsWith('#') || 9 === value.length && value.endsWith('00') && value.startsWith('#');
391
+ }
392
+ export { BACKGROUND_COLORS, BOUND_TEXT_PADDING, DEFAULT_ADAPTIVE_RADIUS, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, DEFAULT_PROPORTIONAL_RADIUS, DEFAULT_STYLE, FONT_FAMILY, FONT_METRICS, FRAME_STYLE, LINE_CONFIRM_THRESHOLD, ROUGHNESS, ROUNDNESS, STROKE_COLORS, bump, compareOrder, defaultRoundness, indexAfter, indicesBetween, isFrame, isLinear, isPointsElement, isTransparent, lineHeightOf, measureText, newFrame, newFreeDraw, newImage, newLinear, newShape, newText, normalizeText, randomFileId, randomId, randomInteger, sizeOfPoints, textWidth, verticalOffset };
393
+
394
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene/elements.js","sources":["../../src/scene/elements.ts"],"sourcesContent":["import { generateKeyBetween, generateNKeysBetween } from 'fractional-indexing';\n\nimport type { Arrowhead, ElementType, ExElement, ItemStyle, Point, Roundness } from './types';\n\n/**\n * New elements and edits, exactly the way Excalidraw 0.18 makes them (`newElement`, `newTextElement`,\n * `newLinearElement`, `newArrowElement`, `newFreeDrawElement`, `newImageElement`, `newFrameElement`, `mutateElement`):\n * the same fields and defaults, so an element drawn here is a normal Excalidraw element in the web app.\n */\n\nexport const ROUGHNESS = { architect: 0, artist: 1, cartoonist: 2 } as const;\n/** Excalidraw's roundness kinds. */\nexport const ROUNDNESS = { LEGACY: 1, PROPORTIONAL_RADIUS: 2, ADAPTIVE_RADIUS: 3 } as const;\n/** The corner of a proportional roundness, as a part of the shorter side. */\nexport const DEFAULT_PROPORTIONAL_RADIUS = 0.25;\n/** The corner of an adaptive roundness (dp). */\nexport const DEFAULT_ADAPTIVE_RADIUS = 32;\n/** How close (dp) a line's end must come to its start to close it. */\nexport const LINE_CONFIRM_THRESHOLD = 8;\n/** Excalidraw's font family ids. */\nexport const FONT_FAMILY = {\n Virgil: 1,\n Helvetica: 2,\n Cascadia: 3,\n Excalifont: 5,\n Nunito: 6,\n 'Lilita One': 7,\n 'Comic Shanns': 8,\n 'Liberation Sans': 9,\n} as const;\n/** A new text's size. */\nexport const DEFAULT_FONT_SIZE = 20;\n/** A new text's font. */\nexport const DEFAULT_FONT_FAMILY = FONT_FAMILY.Excalifont;\n/** The space around a label inside its container. */\nexport const BOUND_TEXT_PADDING = 5;\n\n/** Font metrics Excalidraw positions text with (FONT_METADATA): units per em, ascender, descender, line height. */\nexport const FONT_METRICS: Record<\n number,\n { unitsPerEm: number; ascender: number; descender: number; lineHeight: number }\n> = {\n 5: { unitsPerEm: 1000, ascender: 886, descender: -374, lineHeight: 1.25 },\n 6: { unitsPerEm: 1000, ascender: 1011, descender: -353, lineHeight: 1.35 },\n 7: { unitsPerEm: 1000, ascender: 923, descender: -220, lineHeight: 1.15 },\n 8: { unitsPerEm: 1000, ascender: 750, descender: -250, lineHeight: 1.25 },\n 1: { unitsPerEm: 1000, ascender: 886, descender: -374, lineHeight: 1.25 },\n 2: { unitsPerEm: 2048, ascender: 1577, descender: -471, lineHeight: 1.15 },\n 3: { unitsPerEm: 2048, ascender: 1900, descender: -480, lineHeight: 1.2 },\n 9: { unitsPerEm: 2048, ascender: 1854, descender: -434, lineHeight: 1.15 },\n};\n\n/** How frames are drawn (stroke, radius, name). */\nexport const FRAME_STYLE = {\n strokeColor: '#bbb',\n strokeWidth: 2,\n strokeStyle: 'solid',\n fillStyle: 'solid',\n roughness: 0,\n roundness: null,\n backgroundColor: 'transparent',\n radius: 8,\n nameOffsetY: 3,\n nameColorLightTheme: '#999999',\n nameColorDarkTheme: '#7a7a7a',\n nameFontSize: 14,\n nameLineHeight: 1.25,\n} as const;\n\n/** Excalidraw's default item style (appState `currentItem*`). */\nexport const DEFAULT_STYLE: ItemStyle = {\n strokeColor: '#1e1e1e',\n backgroundColor: 'transparent',\n fillStyle: 'solid',\n strokeWidth: 2,\n strokeStyle: 'solid',\n roughness: ROUGHNESS.artist,\n opacity: 100,\n roundness: 'round',\n fontSize: DEFAULT_FONT_SIZE,\n fontFamily: DEFAULT_FONT_FAMILY,\n textAlign: 'left',\n startArrowhead: null,\n endArrowhead: 'arrow',\n};\n\n/** Excalidraw's quick colour picks (open-color shades it shows first). */\nexport const STROKE_COLORS = ['#1e1e1e', '#e03131', '#2f9e44', '#1971c2', '#f08c00', '#9c36b5', '#0c8599', '#846358'];\n/** Excalidraw's quick background picks (light open-color shades). */\nexport const BACKGROUND_COLORS = [\n 'transparent',\n '#ffc9c9',\n '#b2f2bb',\n '#a5d8ff',\n '#ffec99',\n '#eebefa',\n '#99e9f2',\n '#eaddd7',\n];\n\nconst ID_ALPHABET = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';\n\nfunction randomBytes(count: number): Uint8Array {\n const bytes = new Uint8Array(count);\n const crypto = (globalThis as { crypto?: { getRandomValues?: (array: Uint8Array) => Uint8Array } }).crypto;\n try {\n if (crypto?.getRandomValues) return crypto.getRandomValues(bytes);\n } catch {\n // The main thread of the native engines has no real getRandomValues: Math.random is enough for ids.\n }\n for (let i = 0; i < count; i++) bytes[i] = Math.floor(Math.random() * 256);\n return bytes;\n}\n\n/** A 21-character id like Excalidraw's `nanoid()`. */\nexport function randomId(): string {\n const bytes = randomBytes(21);\n let id = '';\n for (let i = 0; i < 21; i++) id += ID_ALPHABET[bytes[i] & 63];\n return id;\n}\n\n/** Excalidraw's `randomInteger()` (seeds and nonces). */\nexport function randomInteger(): number {\n return Math.floor(Math.random() * 2 ** 31);\n}\n\n/** A file id for a picture (Excalidraw uses a SHA-1 of the data; any unique 40-character hex string works). */\nexport function randomFileId(): string {\n return Array.from(randomBytes(20), (byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n\n/** Rectangles and pictures round adaptively, diamonds and lines proportionally (`getDefaultRoundnessTypeForElement`). */\nexport function defaultRoundness(type: string, style: Pick<ItemStyle, 'roundness'>): Roundness | null {\n if (style.roundness !== 'round') return null;\n if (type === 'line' || type === 'arrow' || type === 'diamond') return { type: ROUNDNESS.PROPORTIONAL_RADIUS };\n if (type === 'rectangle' || type === 'image' || type === 'embeddable' || type === 'iframe')\n return { type: ROUNDNESS.ADAPTIVE_RADIUS };\n return null;\n}\n\ninterface BaseOptions {\n x: number;\n y: number;\n width?: number;\n height?: number;\n angle?: number;\n style: ItemStyle;\n /** Its place in the order (a fractional index); default none (null: after the indexed ones). */\n index?: string | null;\n frameId?: string | null;\n groupIds?: string[];\n roundness?: Roundness | null;\n id?: string;\n}\n\nfunction base(type: ElementType, options: BaseOptions): ExElement {\n const style = options.style;\n return {\n id: options.id ?? randomId(),\n type,\n x: options.x,\n y: options.y,\n width: options.width ?? 0,\n height: options.height ?? 0,\n angle: options.angle ?? 0,\n strokeColor: style.strokeColor,\n backgroundColor: style.backgroundColor,\n fillStyle: style.fillStyle,\n strokeWidth: style.strokeWidth,\n strokeStyle: style.strokeStyle,\n roughness: style.roughness,\n opacity: style.opacity,\n groupIds: options.groupIds ?? [],\n frameId: options.frameId ?? null,\n index: options.index ?? null,\n roundness: options.roundness === undefined ? defaultRoundness(type, style) : options.roundness,\n seed: randomInteger(),\n version: 1,\n versionNonce: randomInteger(),\n isDeleted: false,\n boundElements: null,\n updated: Date.now(),\n link: null,\n locked: false,\n };\n}\n\n/** A new rectangle, ellipse or diamond element. */\nexport function newShape(type: 'rectangle' | 'ellipse' | 'diamond', options: BaseOptions): ExElement {\n return base(type, options);\n}\n\n/** A new frame element (named or not). */\nexport function newFrame(options: Omit<BaseOptions, 'style'> & { name?: string | null }): ExElement {\n const style: ItemStyle = {\n ...DEFAULT_STYLE,\n ...FRAME_STYLE,\n roundness: 'sharp',\n fillStyle: 'solid',\n strokeStyle: 'solid',\n opacity: 100,\n };\n return { ...base('frame', { ...options, style, roundness: null }), name: options.name ?? null };\n}\n\n/** A new line or arrow element through points. */\nexport function newLinear(\n type: 'arrow' | 'line',\n options: BaseOptions & { points: Point[]; startArrowhead?: Arrowhead | null; endArrowhead?: Arrowhead | null },\n): ExElement {\n const size = sizeOfPoints(options.points);\n const element: ExElement = {\n ...base(type, { ...options, width: size.width, height: size.height }),\n points: options.points,\n lastCommittedPoint: null,\n startBinding: null,\n endBinding: null,\n startArrowhead: type === 'arrow' ? (options.startArrowhead ?? null) : null,\n endArrowhead: type === 'arrow' ? (options.endArrowhead ?? null) : null,\n };\n if (type === 'arrow') element.elbowed = false;\n return element;\n}\n\n/** A new free-drawing element. */\nexport function newFreeDraw(\n options: BaseOptions & { points: Point[]; pressures: number[]; simulatePressure: boolean },\n): ExElement {\n const size = sizeOfPoints(options.points);\n return {\n ...base('freedraw', { ...options, width: size.width, height: size.height, roundness: null }),\n points: options.points,\n pressures: options.pressures,\n simulatePressure: options.simulatePressure,\n lastCommittedPoint: options.points.length ? options.points[options.points.length - 1] : null,\n };\n}\n\n/** A new text element (measured; a fixed width when `autoResize` is false). */\nexport function newText(\n options: BaseOptions & {\n text: string;\n containerId?: string | null;\n verticalAlign?: 'top' | 'middle';\n autoResize?: boolean;\n width?: number;\n },\n): ExElement {\n const fontFamily = options.style.fontFamily || DEFAULT_FONT_FAMILY;\n const fontSize = options.style.fontSize || DEFAULT_FONT_SIZE;\n const lineHeight = lineHeightOf(fontFamily);\n const text = normalizeText(options.text);\n const metrics = measureText(text, fontSize, fontFamily, lineHeight);\n return {\n ...base('text', { ...options, roundness: null }),\n text,\n fontSize,\n fontFamily,\n textAlign: options.style.textAlign,\n verticalAlign: options.verticalAlign ?? 'top',\n width: options.autoResize === false && options.width ? options.width : metrics.width,\n height: metrics.height,\n containerId: options.containerId ?? null,\n originalText: text,\n autoResize: options.autoResize ?? true,\n lineHeight,\n };\n}\n\n/** A new picture element of a file. */\nexport function newImage(options: BaseOptions & { fileId: string }): ExElement {\n return {\n ...base('image', options),\n strokeColor: 'transparent',\n status: 'pending',\n fileId: options.fileId,\n scale: [1, 1],\n crop: null,\n };\n}\n\n/** `mutateElement`: the change plus a new version, nonce and timestamp (what makes it win the reconciliation). */\nexport function bump<T extends ExElement>(element: T, changes: Partial<ExElement> = {}): T {\n return {\n ...element,\n ...changes,\n version: element.version + 1,\n versionNonce: randomInteger(),\n updated: Date.now(),\n } as T;\n}\n\n/** The width and height the points span. */\nexport function sizeOfPoints(points: readonly Point[]): { width: number; height: number } {\n if (!points.length) return { width: 0, height: 0 };\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const [x, y] of points) {\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n return { width: maxX - minX, height: maxY - minY };\n}\n\n/** The line height of a font family (Excalidraw's table). */\nexport function lineHeightOf(fontFamily: number): number {\n return (FONT_METRICS[fontFamily] ?? FONT_METRICS[5]).lineHeight;\n}\n\n/** Excalidraw's `getVerticalOffset`: where the first baseline sits below the text's top. */\nexport function verticalOffset(fontFamily: number, fontSize: number, lineHeightPx: number): number {\n const metrics = FONT_METRICS[fontFamily] ?? FONT_METRICS[1];\n const em = fontSize / metrics.unitsPerEm;\n const lineGap = (lineHeightPx - em * metrics.ascender + em * metrics.descender) / 2;\n return em * metrics.ascender + lineGap;\n}\n\n/** Text with tabs as spaces and line breaks unified. */\nexport function normalizeText(text: string): string {\n return text.replace(/\\t/g, ' ').replace(/\\r?\\n|\\r/g, '\\n');\n}\n\n/**\n * Text size without a canvas (the app has none on the native engines): an estimate per character class. The element\n * draws with its host's fonts; Excalidraw measures again with its own when it shows the text.\n */\nexport function textWidth(line: string, fontSize: number, fontFamily: number): number {\n const mono = fontFamily === FONT_FAMILY.Cascadia || fontFamily === FONT_FAMILY['Comic Shanns'];\n let width = 0;\n for (const char of line) {\n const code = char.codePointAt(0) ?? 0;\n if (mono) width += code >= 0x2e80 ? 1 : 0.6;\n else if (char === ' ') width += 0.3;\n else if (code >= 0x2e80 && code < 0xd7ff) width += 1;\n else if (code >= 0x0600 && code <= 0x06ff) width += 0.45;\n else if (/[mwMW@]/.test(char)) width += 0.85;\n else if (/[il.,;:'!|ftj]/.test(char)) width += 0.3;\n else if (/[A-Z0-9]/.test(char)) width += 0.62;\n else width += 0.52;\n }\n return width * fontSize;\n}\n\n/** A text's size in a font (estimated per script; no DOM). */\nexport function measureText(\n text: string,\n fontSize: number,\n fontFamily: number,\n lineHeight: number,\n): { width: number; height: number } {\n const lines = text.split('\\n');\n const width = Math.max(...lines.map((line) => textWidth(line, fontSize, fontFamily)));\n return { width, height: lines.length * fontSize * lineHeight };\n}\n\n/** Fractional index after `last` (or the first index). */\nexport function indexAfter(last: string | null | undefined): string {\n try {\n return generateKeyBetween(last ?? null, null);\n } catch {\n return generateKeyBetween(null, null);\n }\n}\n\n/** Fractional indices between two (for an order). */\nexport function indicesBetween(\n lower: string | null | undefined,\n upper: string | null | undefined,\n count: number,\n): string[] {\n try {\n return generateNKeysBetween(lower ?? null, upper ?? null, count);\n } catch {\n return generateNKeysBetween(lower ?? null, null, count);\n }\n}\n\n/** Excalidraw's order: by fractional index, ties by id; elements without an index last. */\nexport function compareOrder(a: Pick<ExElement, 'index' | 'id'>, b: Pick<ExElement, 'index' | 'id'>): number {\n if (a.index && b.index) {\n if (a.index < b.index) return -1;\n if (a.index > b.index) return 1;\n return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n }\n if (a.index) return -1;\n if (b.index) return 1;\n return 0;\n}\n\n/** A line or an arrow. */\nexport function isLinear(element: Pick<ExElement, 'type'>): boolean {\n return element.type === 'arrow' || element.type === 'line';\n}\n\n/** An element drawn through points (a line, an arrow, a free stroke). */\nexport function isPointsElement(element: Pick<ExElement, 'type'>): boolean {\n return element.type === 'arrow' || element.type === 'line' || element.type === 'freedraw';\n}\n\n/** A frame (or a magic frame). */\nexport function isFrame(element: Pick<ExElement, 'type'>): boolean {\n return element.type === 'frame' || element.type === 'magicframe';\n}\n\n/** A colour that draws nothing (empty, `transparent`, zero alpha). */\nexport function isTransparent(color: string | undefined | null): boolean {\n if (!color) return true;\n const value = color.trim().toLowerCase();\n return (\n value === 'transparent' ||\n value === 'none' ||\n (value.length === 5 && value.endsWith('0') && value.startsWith('#')) ||\n (value.length === 9 && value.endsWith('00') && value.startsWith('#'))\n );\n}\n"],"names":["ROUGHNESS","ROUNDNESS","DEFAULT_PROPORTIONAL_RADIUS","DEFAULT_ADAPTIVE_RADIUS","LINE_CONFIRM_THRESHOLD","FONT_FAMILY","DEFAULT_FONT_SIZE","DEFAULT_FONT_FAMILY","BOUND_TEXT_PADDING","FONT_METRICS","FRAME_STYLE","DEFAULT_STYLE","STROKE_COLORS","BACKGROUND_COLORS","ID_ALPHABET","randomBytes","count","bytes","Uint8Array","crypto","globalThis","i","Math","randomId","id","randomInteger","randomFileId","Array","byte","defaultRoundness","type","style","base","options","_options_id","_options_width","_options_height","_options_angle","_options_groupIds","_options_frameId","_options_index","undefined","Date","newShape","newFrame","_options_name","newLinear","_options_startArrowhead","_options_endArrowhead","size","sizeOfPoints","element","newFreeDraw","newText","_options_verticalAlign","_options_containerId","_options_autoResize","fontFamily","fontSize","lineHeight","lineHeightOf","text","normalizeText","metrics","measureText","newImage","bump","changes","points","minX","Infinity","minY","maxX","maxY","x","y","_FONT_METRICS_fontFamily","verticalOffset","lineHeightPx","em","lineGap","textWidth","line","mono","width","char","_char_codePointAt","code","lines","indexAfter","last","generateKeyBetween","indicesBetween","lower","upper","generateNKeysBetween","compareOrder","a","b","isLinear","isPointsElement","isFrame","isTransparent","color","value"],"mappings":";AAUO,MAAMA,YAAY;IAAE,WAAW;IAAG,QAAQ;IAAG,YAAY;AAAE;AAE3D,MAAMC,YAAY;IAAE,QAAQ;IAAG,qBAAqB;IAAG,iBAAiB;AAAE;AAE1E,MAAMC,8BAA8B;AAEpC,MAAMC,0BAA0B;AAEhC,MAAMC,yBAAyB;AAE/B,MAAMC,cAAc;IACzB,QAAQ;IACR,WAAW;IACX,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,cAAc;IACd,gBAAgB;IAChB,mBAAmB;AACrB;AAEO,MAAMC,oBAAoB;AAE1B,MAAMC,sBAAsBF,YAAY,UAAU;AAElD,MAAMG,qBAAqB;AAG3B,MAAMC,eAGT;IACF,GAAG;QAAE,YAAY;QAAM,UAAU;QAAK,WAAW;QAAM,YAAY;IAAK;IACxE,GAAG;QAAE,YAAY;QAAM,UAAU;QAAM,WAAW;QAAM,YAAY;IAAK;IACzE,GAAG;QAAE,YAAY;QAAM,UAAU;QAAK,WAAW;QAAM,YAAY;IAAK;IACxE,GAAG;QAAE,YAAY;QAAM,U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