@dou-ui/flow 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (83) hide show
  1. package/dist/collaboration/index.js +114 -6
  2. package/dist/collaboration/index.js.map +1 -1
  3. package/dist/comments.js +245 -0
  4. package/dist/comments.js.map +1 -0
  5. package/dist/components/default-node.js.map +1 -1
  6. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
  7. package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  8. package/dist/components/default-node2.js.map +1 -1
  9. package/dist/components/flow-comments.js +6 -0
  10. package/dist/components/flow-comments.js.map +1 -0
  11. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
  12. package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/components/flow-port.js.map +1 -1
  14. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
  15. package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
  16. package/dist/components/node-view.js.map +1 -1
  17. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
  18. package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
  19. package/dist/components/port-view.js +6 -0
  20. package/dist/components/port-view.js.map +1 -0
  21. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
  22. package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
  23. package/dist/components/port.js +7 -0
  24. package/dist/components/port.js.map +1 -0
  25. package/dist/context.js.map +1 -1
  26. package/dist/core/edge-types.js +107 -3
  27. package/dist/core/edge-types.js.map +1 -1
  28. package/dist/core/extension.js.map +1 -1
  29. package/dist/core/history.js +26 -0
  30. package/dist/core/history.js.map +1 -1
  31. package/dist/core/model.js.map +1 -1
  32. package/dist/core/node-types.js +39 -1
  33. package/dist/core/node-types.js.map +1 -1
  34. package/dist/core/transaction.js +112 -15
  35. package/dist/core/transaction.js.map +1 -1
  36. package/dist/document.js +1 -1
  37. package/dist/export/render.js +78 -0
  38. package/dist/export/render.js.map +1 -0
  39. package/dist/flow-editor.js.map +1 -1
  40. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +484 -39
  41. package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  42. package/dist/index.js +6 -6
  43. package/dist/index.js.map +1 -1
  44. package/dist/kit.js +1 -1
  45. package/dist/locale.js +21 -9
  46. package/dist/locale.js.map +1 -1
  47. package/dist/style.css +1 -1
  48. package/dist/style.js +1 -1
  49. package/dist/types/collaboration/index.d.ts +32 -4
  50. package/dist/types/comments.d.ts +73 -0
  51. package/dist/types/components/default-node.d.ts +1 -1
  52. package/dist/types/components/flow-comments.vue.d.ts +35 -0
  53. package/dist/types/components/flow-port.vue.d.ts +8 -2
  54. package/dist/types/components/port-view.vue.d.ts +10 -0
  55. package/dist/types/components/port.d.ts +7 -0
  56. package/dist/types/context.d.ts +54 -1
  57. package/dist/types/core/extension.d.ts +9 -1
  58. package/dist/types/core/history.d.ts +10 -0
  59. package/dist/types/core/menu.d.ts +5 -0
  60. package/dist/types/core/model.d.ts +28 -0
  61. package/dist/types/core/node-types.d.ts +18 -2
  62. package/dist/types/core/transaction.d.ts +23 -1
  63. package/dist/types/export/render.d.ts +27 -0
  64. package/dist/types/flow-editor.vue.d.ts +11 -0
  65. package/dist/types/index.d.ts +37 -10
  66. package/dist/types/locale.d.ts +11 -3
  67. package/dist/types/whiteboard/model.d.ts +2 -11
  68. package/dist/types/whiteboard/state.d.ts +2 -0
  69. package/dist/whiteboard/board-node.js.map +1 -1
  70. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +30 -14
  71. package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
  72. package/dist/whiteboard/connector.js +5 -10
  73. package/dist/whiteboard/connector.js.map +1 -1
  74. package/dist/whiteboard/kit.js +63 -8
  75. package/dist/whiteboard/kit.js.map +1 -1
  76. package/dist/whiteboard/model.js +4 -31
  77. package/dist/whiteboard/model.js.map +1 -1
  78. package/dist/whiteboard/state.js +6 -1
  79. package/dist/whiteboard/state.js.map +1 -1
  80. package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
  81. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
  82. package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  83. package/package.json +3 -3
@@ -1,9 +1,8 @@
1
1
  import type { Tone } from 'dou-ui';
2
- import type { FlowPortSpec } from '../core/model';
3
2
  /** What a press on the board does. */
4
- export type WhiteboardTool = 'select' | 'hand' | 'rect' | 'ellipse' | 'diamond' | 'sticky' | 'text' | 'pen' | 'eraser';
3
+ export type WhiteboardTool = 'select' | 'hand' | 'rect' | 'ellipse' | 'diamond' | 'sticky' | 'text' | 'pen' | 'eraser' | 'comment';
5
4
  /** The tools that put down a node with a box. */
6
- export type WhiteboardShapeTool = Exclude<WhiteboardTool, 'select' | 'hand' | 'pen' | 'eraser'>;
5
+ export type WhiteboardShapeTool = Exclude<WhiteboardTool, 'select' | 'hand' | 'pen' | 'eraser' | 'comment'>;
7
6
  export type WhiteboardShape = 'rect' | 'ellipse' | 'diamond';
8
7
  /** What every board node can carry. */
9
8
  export interface WhiteboardNodeData {
@@ -68,12 +67,4 @@ export interface WhiteboardImageData extends WhiteboardNodeData {
68
67
  export declare const whiteboardKeys: Record<WhiteboardTool, string>;
69
68
  /** The key that inserts an image. */
70
69
  export declare const imageKey = "i";
71
- /**
72
- * Four anchors, one on each side. Each is an output and an input at the
73
- * same spot, so a connector can start and end on any of them. Edges in
74
- * data go from an output (`right`) to an input (`left-in`). The order puts
75
- * `right` and `left-in` first, so a node added after another joins it left
76
- * to right.
77
- */
78
- export declare const anchorPorts: FlowPortSpec[];
79
70
  export declare const anchorSides: readonly ["top", "right", "bottom", "left"];
@@ -37,3 +37,5 @@ export interface WhiteboardState {
37
37
  }
38
38
  /** The board's state in an editor, made on first use. */
39
39
  export declare function boardState(context: FlowEditorContext): WhiteboardState;
40
+ /** Whether a tool can be used now: while read-only only select, hand and comment; comment while threads can be started. */
41
+ export declare function usable(ctx: FlowEditorContext, tool: WhiteboardTool): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport DouFlowPort from '../components/flow-port.vue'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"board-node.js","names":["_sfc_main"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\nconst rect = computed(\n () => ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 },\n)\n/**\n * The node's size, for the anchors and the corner handles to share the\n * corners of a small node: each keeps short of the other.\n */\nconst sizeStyle = computed(() => ({\n '--dou-whiteboard-frame-width': `${rect.value.width}px`,\n '--dou-whiteboard-frame-height': `${rect.value.height}px`,\n}))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const box = rect.value\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${box.x}px ${box.y}px`,\n width: `${box.width}px`,\n height: `${box.height}px`,\n ...sizeStyle.value,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"[transform, sizeStyle]\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span\n class=\"dou-whiteboard-node__turn\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"startTurn\"\n >\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"[\n 'dou-whiteboard-node__corner',\n handle.x < 0 ? 'is-left' : 'is-right',\n handle.y < 0 ? 'is-top' : 'is-bottom',\n ]\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { useFlowEditor } from "../context.js";
2
- import flow_port_default from "../components/flow-port.js";
2
+ import { DouFlowPort } from "../components/port.js";
3
3
  import { fitInk, inkOutline, unpack } from "./ink.js";
4
4
  import { anchorSides } from "./model.js";
5
5
  import { boardState } from "./state.js";
@@ -79,17 +79,27 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
79
79
  const resizeHandles = computed(() => kind.value === "image" ? RESIZE_HANDLES.filter((h) => h.x && h.y) : kind.value === "text" ? RESIZE_HANDLES.filter((h) => h.x) : RESIZE_HANDLES);
80
80
  const sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y));
81
81
  const cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y));
82
+ const rect = computed(() => ctx.getNodeRect(props.node.id) ?? {
83
+ ...props.node,
84
+ width: 0,
85
+ height: 0
86
+ });
87
+ /**
88
+ * The node's size, for the anchors and the corner handles to share the
89
+ * corners of a small node: each keeps short of the other.
90
+ */
91
+ const sizeStyle = computed(() => ({
92
+ "--dou-whiteboard-frame-width": `${rect.value.width}px`,
93
+ "--dou-whiteboard-frame-height": `${rect.value.height}px`
94
+ }));
82
95
  /** The node's box, turned with it, for the handles drawn above every node. */
83
96
  const frameStyle = computed(() => {
84
- const rect = ctx.getNodeRect(props.node.id) ?? {
85
- ...props.node,
86
- width: 0,
87
- height: 0
88
- };
97
+ const box = rect.value;
89
98
  return {
90
- translate: `${rect.x}px ${rect.y}px`,
91
- width: `${rect.width}px`,
92
- height: `${rect.height}px`,
99
+ translate: `${box.x}px ${box.y}px`,
100
+ width: `${box.width}px`,
101
+ height: `${box.height}px`,
102
+ ...sizeStyle.value,
93
103
  rotate: rotation.value ? `${rotation.value}deg` : void 0
94
104
  };
95
105
  });
@@ -209,7 +219,7 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
209
219
  "is-erasing": erasing.value
210
220
  }
211
221
  ]]),
212
- style: normalizeStyle(transform.value),
222
+ style: normalizeStyle([transform.value, sizeStyle.value]),
213
223
  onDblclick: withModifiers(edit, ["stop"])
214
224
  }, [
215
225
  kind.value === "shape" ? (openBlock(), createElementBlock("svg", {
@@ -273,10 +283,10 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
273
283
  textContent: toDisplayString(__props.data.text)
274
284
  }, null, 12, _hoisted_11)) : createCommentVNode("", true),
275
285
  kind.value !== "ink" ? (openBlock(), createElementBlock("div", _hoisted_12, [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(anchorSides), (side) => {
276
- return openBlock(), createElementBlock(Fragment, { key: side }, [createVNode(flow_port_default, {
286
+ return openBlock(), createElementBlock(Fragment, { key: side }, [createVNode(unref(DouFlowPort), {
277
287
  id: `${side}-in`,
278
288
  class: "dou-whiteboard-node__anchor"
279
- }, null, 8, ["id"]), createVNode(flow_port_default, {
289
+ }, null, 8, ["id"]), createVNode(unref(DouFlowPort), {
280
290
  id: side,
281
291
  class: "dou-whiteboard-node__anchor"
282
292
  }, null, 8, ["id"])], 64);
@@ -304,6 +314,7 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
304
314
  "aria-hidden": "true"
305
315
  }, [createElementVNode("span", {
306
316
  class: "dou-whiteboard-node__turn",
317
+ "data-flow-handle": "",
307
318
  "data-dou-nodrag": "",
308
319
  onPointerdown: _cache[3] || (_cache[3] = (...args) => unref(startTurn) && unref(startTurn)(...args))
309
320
  }, [..._cache[4] || (_cache[4] = [createElementVNode("span", {
@@ -312,16 +323,21 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
312
323
  }, null, -1)])], 32), (openBlock(true), createElementBlock(Fragment, null, renderList(cornerHandles.value, (handle) => {
313
324
  return openBlock(), createElementBlock("span", {
314
325
  key: `${handle.x},${handle.y}`,
315
- class: "dou-whiteboard-node__corner",
326
+ class: normalizeClass([
327
+ "dou-whiteboard-node__corner",
328
+ handle.x < 0 ? "is-left" : "is-right",
329
+ handle.y < 0 ? "is-top" : "is-bottom"
330
+ ]),
316
331
  style: normalizeStyle({
317
332
  left: place(handle.x),
318
333
  top: place(handle.y),
319
334
  cursor: cursorOf(handle)
320
335
  }),
321
336
  "data-handle": `${handle.x},${handle.y}`,
337
+ "data-flow-handle": "",
322
338
  "data-dou-nodrag": "",
323
339
  onPointerdown: ($event) => onResize($event, handle)
324
- }, null, 44, _hoisted_14);
340
+ }, null, 46, _hoisted_14);
325
341
  }), 128))], 4)], 8, ["to", "disabled"]))], 64)) : createCommentVNode("", true)
326
342
  ], 38);
327
343
  };
@@ -1 +1 @@
1
- {"version":3,"file":"board-node.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","DouFlowPort","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport DouFlowPort from '../components/flow-port.vue'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,OAAO;EACrF,MAAM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lBA,IAAIb,MAAA,KAAA,CAAK,CAAC,QAAQ;KAAQ,UAAQ,CAAGA,MAAA,KAAA,CAAK,CAAC,QAAQ;I,IAC5DG,mBAgBM,OAAA;KAhBD,OAAM;KAA8B,OAAKF,eAAE,WAAA,KAAU;KAAE,eAAY;I,IAItEE,mBAEO,QAAA;KAFD,OAAM;KAA4B,mBAAA;KAAiB,eAAW,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAH,MAAA,SAAA,KAAAA,MAAA,SAAA,CAAA,CAAA,GAAA,IAAA;I,kCACpEG,mBAA8D,QAAA;KAAxD,OAAM;KAA8B,qBAAA;I,uBAE5CN,UAAA,IAAA,GAAAC,mBAQEW,UAAA,MAAAC,WAPiB,cAAA,QAAV,WAAM;KADf,OAAAb,UAAA,GAAAC,mBAQE,QAAA;MANC,KAAG,GAAK,OAAO,EAAC,GAAI,OAAO;MAC5B,OAAM;MACL,OAAKG,eAAA;OAAA,MAAU,MAAM,OAAO,CAAC;OAAA,KAAQ,MAAM,OAAO,CAAC;OAAA,QAAW,SAAS,MAAM;MAAA,CAAA;MAC7E,eAAW,GAAK,OAAO,EAAC,GAAI,OAAO;MACpC,mBAAA;MACC,gBAAW,WAAE,SAAS,QAAQ,MAAM"}
1
+ {"version":3,"file":"board-node.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\nconst rect = computed(\n () => ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 },\n)\n/**\n * The node's size, for the anchors and the corner handles to share the\n * corners of a small node: each keeps short of the other.\n */\nconst sizeStyle = computed(() => ({\n '--dou-whiteboard-frame-width': `${rect.value.width}px`,\n '--dou-whiteboard-frame-height': `${rect.value.height}px`,\n}))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const box = rect.value\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${box.x}px ${box.y}px`,\n width: `${box.width}px`,\n height: `${box.height}px`,\n ...sizeStyle.value,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"[transform, sizeStyle]\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span\n class=\"dou-whiteboard-node__turn\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"startTurn\"\n >\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"[\n 'dou-whiteboard-node__corner',\n handle.x < 0 ? 'is-left' : 'is-right',\n handle.y < 0 ? 'is-top' : 'is-bottom',\n ]\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,OAAO;EACrF,MAAM,QAAQ,eAAgC,MAAM,KAAK,SAAS,MAAM;EACxE,MAAM,OAAO,eACL,MAAM,KAAK,SAAS,KAAK,UAAU,WAAW,YAAY,UAClE;EACA,MAAM,WAAW,eAAe;GAAC;GAAS;GAAU;EAAM,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC;EAEhF,MAAM,MAA4B;GAAE,OAAO;GAAI,QAAQ;GAAI,MAAM;GAAI,KAAK;GAAG,OAAO;EAAG;EACvF,MAAM,WAAW,eAAe,MAAM,KAAK,YAAY,CAAC;EACxD,MAAM,EAAE,SAAS,WAAW,gBAAgB,oBAC1C,KACA,MAAM,OAAO,MAAM,GACnB,UACA;GAAE,OAAO,IAAI,KAAK;GAAQ,QAAQ,IAAI,KAAK;EAAO,CACpD;EAMA,MAAM,YAAY,eAAgB,SAAS,QAAQ,EAAE,QAAQ,GAAG,SAAS,MAAM,KAAK,IAAI,KAAA,CAAU;;;;;;EAMlG,MAAM,gBAAgB,eACpB,KAA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KAA8B,qBAAA;I,uBAE5CN,UAAA,IAAA,GAAAC,mBAaEW,UAAA,MAAAC,WAZiB,cAAA,QAAV,WAAM;KADf,OAAAb,UAAA,GAAAC,mBAaE,QAAA;MAXC,KAAG,GAAK,OAAO,EAAC,GAAI,OAAO;MAC3B,OAAKC,eAAA;;OAA+D,OAAO,IAAC,IAAA,YAAA;OAA6C,OAAO,IAAC,IAAA,WAAA;;MAKjI,OAAKE,eAAA;OAAA,MAAU,MAAM,OAAO,CAAC;OAAA,KAAQ,MAAM,OAAO,CAAC;OAAA,QAAW,SAAS,MAAM;MAAA,CAAA;MAC7E,eAAW,GAAK,OAAO,EAAC,GAAI,OAAO;MACpC,oBAAA;MACA,mBAAA;MACC,gBAAW,WAAE,SAAS,QAAQ,MAAM"}
@@ -1,5 +1,5 @@
1
- import { bezierEdge, defineEdgeType, stepEdge } from "../core/edge-types.js";
2
1
  import { format } from "../locale.js";
2
+ import { bezierEdge, defineEdgeType, stepEdge, straightEdge } from "../core/edge-types.js";
3
3
  import { ArrowEndsIcon, ArrowLeftRightIcon, ArrowRightIcon, ConnectorCurveIcon, ConnectorElbowIcon, ConnectorStraightIcon, LineDashDotIcon, LineDashedIcon, LineDottedIcon, LineSolidIcon, LineStyleIcon, MinusIcon, RouteIcon } from "@dou-ui/icons";
4
4
  // src/whiteboard/connector.ts
5
5
  var ARROW = {
@@ -59,17 +59,12 @@ var connectorEdge = defineEdgeType({
59
59
  const data = edge?.data ?? {};
60
60
  const route = data.route ?? "straight";
61
61
  const straight = route === "straight";
62
- const base = straight ? {
63
- path: `M${p(source)}L${p(target)}`,
64
- label: {
65
- x: (source.x + target.x) / 2,
66
- y: (source.y + target.y) / 2
67
- }
68
- } : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
62
+ const points = edge?.points ?? [];
63
+ const base = straight ? straightEdge.route(source, target, edge) : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
69
64
  const arrow = data.arrow ?? "end";
70
65
  let marks = "";
71
- if (arrow !== "none") marks += arrowhead(target, arrival(target, source, straight));
72
- if (arrow === "both") marks += arrowhead(source, arrival(source, target, straight));
66
+ if (arrow !== "none") marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight));
67
+ if (arrow === "both") marks += arrowhead(source, arrival(source, points[0] ?? target, straight));
73
68
  return {
74
69
  ...base,
75
70
  marks: marks || void 0
@@ -1 +1 @@
1
- {"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { bezierEdge, defineEdgeType, stepEdge, type EdgeAnchor } from '../core/edge-types'\nimport type { FlowToolbarItem } from '../core/menu'\nimport type { FlowEdge, Point, PortSide } from '../core/model'\nimport { format } from '../locale'\nimport type {\n WhiteboardArrow,\n WhiteboardConnectorData,\n WhiteboardDash,\n WhiteboardRoute,\n} from './model'\n\nconst ARROW = { length: 10, spread: 0.45 }\nconst r2 = (v: number) => Math.round(v * 100) / 100\nconst p = (pt: Point) => `${r2(pt.x)} ${r2(pt.y)}`\n\n/** Out of a side, away from the node. */\nconst outward: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\n/** An open arrowhead with its tip at `tip`, pointing along `angle`. */\nfunction arrowhead(tip: Point, angle: number) {\n const wing = (spread: number) => ({\n x: tip.x - ARROW.length * Math.cos(angle + spread),\n y: tip.y - ARROW.length * Math.sin(angle + spread),\n })\n return `M${p(wing(ARROW.spread))}L${p(tip)}L${p(wing(-ARROW.spread))}`\n}\n\n/** The way a run arrives at `end`: straight from `from`, or into the side it faces. */\nfunction arrival(end: EdgeAnchor, from: Point, straight: boolean) {\n if (straight) return Math.atan2(end.y - from.y, end.x - from.x)\n const out = outward[end.side]\n return Math.atan2(-out.y, -out.x)\n}\n\n/** Dash patterns, in px of a 1.5px stroke with round ends: a 0 dash is a dot. */\nconst DASHES: Record<WhiteboardDash, string | undefined> = {\n solid: undefined,\n dashed: '6 5',\n dotted: '0 4',\n 'dash-dot': '8 4 0 4',\n}\n\n/**\n * The whiteboard's line: straight, with right-angled turns or curved\n * (`data.route`), solid or dashed (`data.dash`), with arrowheads at the end,\n * both ends or neither (`data.arrow`).\n */\nexport const connectorEdge = defineEdgeType<WhiteboardConnectorData>({\n type: 'connector',\n route(source, target, edge) {\n const data = edge?.data ?? {}\n const route = data.route ?? 'straight'\n const straight = route === 'straight'\n const base = straight\n ? {\n path: `M${p(source)}L${p(target)}`,\n label: { x: (source.x + target.x) / 2, y: (source.y + target.y) / 2 },\n }\n : (route === 'elbow' ? stepEdge : bezierEdge).route(source, target, edge as FlowEdge)\n const arrow = data.arrow ?? 'end'\n let marks = ''\n if (arrow !== 'none') marks += arrowhead(target, arrival(target, source, straight))\n if (arrow === 'both') marks += arrowhead(source, arrival(source, target, straight))\n return { ...base, marks: marks || undefined }\n },\n style(edge) {\n const dash = DASHES[edge.data?.dash ?? 'solid']\n return dash ? { strokeDasharray: dash } : undefined\n },\n})\n\nconst ROUTES: { value: WhiteboardRoute; icon: Component }[] = [\n { value: 'straight', icon: ConnectorStraightIcon },\n { value: 'elbow', icon: ConnectorElbowIcon },\n { value: 'curve', icon: ConnectorCurveIcon },\n]\nconst DASH_CHOICES: { value: WhiteboardDash; icon: Component }[] = [\n { value: 'solid', icon: LineSolidIcon },\n { value: 'dashed', icon: LineDashedIcon },\n { value: 'dotted', icon: LineDottedIcon },\n { value: 'dash-dot', icon: LineDashDotIcon },\n]\nconst ARROWS: { value: WhiteboardArrow; icon: Component }[] = [\n { value: 'none', icon: MinusIcon },\n { value: 'end', icon: ArrowRightIcon },\n { value: 'both', icon: ArrowLeftRightIcon },\n]\n\nconst data = (edge: FlowEdge) => (edge.data ?? {}) as WhiteboardConnectorData\nconst isConnector = (edge: FlowEdge) => (edge.type ?? 'connector') === 'connector'\n\n/** Route, dash and arrow choices over the selected connectors. */\nexport function connectorToolbar(ctx: FlowEditorContext, edges: FlowEdge[]): FlowToolbarItem[] {\n if (!edges.every(isConnector)) return []\n const t = ctx.messages.value.board\n\n /**\n * One button: its label and icon say the value in use, or that the\n * selected connectors differ; its menu sets one value on all of them.\n */\n function choice<V extends string>(\n key: 'route' | 'dash' | 'arrow',\n fallback: V,\n options: { value: V; icon: Component }[],\n names: Record<V, string>,\n text: { of: string; set: string },\n mixedIcon: Component,\n ): FlowToolbarItem {\n const values = new Set(edges.map((edge) => (data(edge)[key] as V | undefined) ?? fallback))\n const only = values.size === 1 ? [...values][0]! : null\n return {\n key,\n label: format(text.of, { value: only ? names[only] : t.mixed }),\n icon: only ? options.find((item) => item.value === only)!.icon : mixedIcon,\n children: options.map((item) => ({\n key: `${key}-${item.value}`,\n label: names[item.value],\n icon: item.icon,\n checked: item.value === only,\n run() {\n ctx.transact((tr) => {\n for (const edge of edges)\n tr.updateEdge(edge.id, { data: { ...edge.data, [key]: item.value } })\n })\n ctx.announce(format(text.set, { value: names[item.value] }))\n },\n })),\n }\n }\n\n return [\n choice('route', 'straight', ROUTES, t.routes, { of: t.routeOf, set: t.routeSet }, RouteIcon),\n choice(\n 'dash',\n 'solid',\n DASH_CHOICES,\n t.dashes,\n { of: t.dashOf, set: t.dashSet },\n LineStyleIcon,\n ),\n choice('arrow', 'end', ARROWS, t.arrows, { of: t.arrowOf, set: t.arrowSet }, ArrowEndsIcon),\n ]\n}\n"],"mappings":";;;;AA4BA,IAAM,QAAQ;CAAE,QAAQ;CAAI,QAAQ;AAAK;AACzC,IAAM,MAAM,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAChD,IAAM,KAAK,O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,CAAC,CAAC,QAA0B,QAAQ,CAAC;EAC1F,MAAM,OAAO,OAAO,SAAS,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,KAAM;EACnD,OAAO;GACL;GACA,OAAO,OAAO,KAAK,IAAI,EAAE,OAAO,OAAO,MAAM,QAAQ,EAAE,MAAM,CAAC;GAC9D,MAAM,OAAO,QAAQ,MAAM,SAAS,KAAK,UAAU,IAAI,CAAC,CAAE,OAAO;GACjE,UAAU,QAAQ,KAAK,UAAU;IAC/B,KAAK,GAAG,IAAI,GAAG,KAAK;IACpB,OAAO,MAAM,KAAK;IAClB,MAAM,KAAK;IACX,SAAS,KAAK,UAAU;IACxB,MAAM;KACJ,IAAI,UAAU,OAAO;MACnB,KAAK,MAAM,QAAQ,OACjB,GAAG,WAAW,KAAK,IAAI,EAAE,MAAM;OAAE,GAAG,KAAK;QAAO,MAAM,KAAK;MAAM,EAAE,CAAC;KACxE,CAAC;KACD,IAAI,SAAS,OAAO,KAAK,KAAK,EAAE,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC;IAC7D;GACF,EAAE;EACJ;CACF;CAEA,OAAO;EACL,OAAO,SAAS,YAAY,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,SAAS;EAC3F,OACE,QACA,SACA,cACA,EAAE,QACF;GAAE,IAAI,EAAE;GAAQ,KAAK,EAAE;EAAQ,GAC/B,aACF;EACA,OAAO,SAAS,OAAO,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,aAAa;CAC5F;AACF"}
1
+ {"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport {\n bezierEdge,\n defineEdgeType,\n stepEdge,\n straightEdge,\n type EdgeAnchor,\n} from '../core/edge-types'\nimport type { FlowToolbarItem } from '../core/menu'\nimport type { FlowEdge, Point, PortSide } from '../core/model'\nimport { format } from '../locale'\nimport type {\n WhiteboardArrow,\n WhiteboardConnectorData,\n WhiteboardDash,\n WhiteboardRoute,\n} from './model'\n\nconst ARROW = { length: 10, spread: 0.45 }\nconst r2 = (v: number) => Math.round(v * 100) / 100\nconst p = (pt: Point) => `${r2(pt.x)} ${r2(pt.y)}`\n\n/** Out of a side, away from the node. */\nconst outward: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\n/** An open arrowhead with its tip at `tip`, pointing along `angle`. */\nfunction arrowhead(tip: Point, angle: number) {\n const wing = (spread: number) => ({\n x: tip.x - ARROW.length * Math.cos(angle + spread),\n y: tip.y - ARROW.length * Math.sin(angle + spread),\n })\n return `M${p(wing(ARROW.spread))}L${p(tip)}L${p(wing(-ARROW.spread))}`\n}\n\n/** The way a run arrives at `end`: straight from `from`, or into the side it faces. */\nfunction arrival(end: EdgeAnchor, from: Point, straight: boolean) {\n if (straight) return Math.atan2(end.y - from.y, end.x - from.x)\n const out = outward[end.side]\n return Math.atan2(-out.y, -out.x)\n}\n\n/** Dash patterns, in px of a 1.5px stroke with round ends: a 0 dash is a dot. */\nconst DASHES: Record<WhiteboardDash, string | undefined> = {\n solid: undefined,\n dashed: '6 5',\n dotted: '0 4',\n 'dash-dot': '8 4 0 4',\n}\n\n/**\n * The whiteboard's line: straight, with right-angled turns or curved\n * (`data.route`), solid or dashed (`data.dash`), with arrowheads at the end,\n * both ends or neither (`data.arrow`).\n */\nexport const connectorEdge = defineEdgeType<WhiteboardConnectorData>({\n type: 'connector',\n route(source, target, edge) {\n const data = edge?.data ?? {}\n const route = data.route ?? 'straight'\n const straight = route === 'straight'\n // Tidying lays points between the nodes in the way of a long connector.\n const points = edge?.points ?? []\n const base = straight\n ? straightEdge.route(source, target, edge as FlowEdge)\n : (route === 'elbow' ? stepEdge : bezierEdge).route(source, target, edge as FlowEdge)\n const arrow = data.arrow ?? 'end'\n let marks = ''\n if (arrow !== 'none')\n marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight))\n if (arrow === 'both') marks += arrowhead(source, arrival(source, points[0] ?? target, straight))\n return { ...base, marks: marks || undefined }\n },\n style(edge) {\n const dash = DASHES[edge.data?.dash ?? 'solid']\n return dash ? { strokeDasharray: dash } : undefined\n },\n})\n\nconst ROUTES: { value: WhiteboardRoute; icon: Component }[] = [\n { value: 'straight', icon: ConnectorStraightIcon },\n { value: 'elbow', icon: ConnectorElbowIcon },\n { value: 'curve', icon: ConnectorCurveIcon },\n]\nconst DASH_CHOICES: { value: WhiteboardDash; icon: Component }[] = [\n { value: 'solid', icon: LineSolidIcon },\n { value: 'dashed', icon: LineDashedIcon },\n { value: 'dotted', icon: LineDottedIcon },\n { value: 'dash-dot', icon: LineDashDotIcon },\n]\nconst ARROWS: { value: WhiteboardArrow; icon: Component }[] = [\n { value: 'none', icon: MinusIcon },\n { value: 'end', icon: ArrowRightIcon },\n { value: 'both', icon: ArrowLeftRightIcon },\n]\n\nconst data = (edge: FlowEdge) => (edge.data ?? {}) as WhiteboardConnectorData\nconst isConnector = (edge: FlowEdge) => (edge.type ?? 'connector') === 'connector'\n\n/** Route, dash and arrow choices over the selected connectors. */\nexport function connectorToolbar(ctx: FlowEditorContext, edges: FlowEdge[]): FlowToolbarItem[] {\n if (!edges.every(isConnector)) return []\n const t = ctx.messages.value.board\n\n /**\n * One button: its label and icon say the value in use, or that the\n * selected connectors differ; its menu sets one value on all of them.\n */\n function choice<V extends string>(\n key: 'route' | 'dash' | 'arrow',\n fallback: V,\n options: { value: V; icon: Component }[],\n names: Record<V, string>,\n text: { of: string; set: string },\n mixedIcon: Component,\n ): FlowToolbarItem {\n const values = new Set(edges.map((edge) => (data(edge)[key] as V | undefined) ?? fallback))\n const only = values.size === 1 ? [...values][0]! : null\n return {\n key,\n label: format(text.of, { value: only ? names[only] : t.mixed }),\n icon: only ? options.find((item) => item.value === only)!.icon : mixedIcon,\n children: options.map((item) => ({\n key: `${key}-${item.value}`,\n label: names[item.value],\n icon: item.icon,\n checked: item.value === only,\n run() {\n ctx.transact((tr) => {\n for (const edge of edges)\n tr.updateEdge(edge.id, { data: { ...edge.data, [key]: item.value } })\n })\n ctx.announce(format(text.set, { value: names[item.value] }))\n },\n })),\n }\n }\n\n return [\n choice('route', 'straight', ROUTES, t.routes, { of: t.routeOf, set: t.routeSet }, RouteIcon),\n choice(\n 'dash',\n 'solid',\n DASH_CHOICES,\n t.dashes,\n { of: t.dashOf, set: t.dashSet },\n LineStyleIcon,\n ),\n choice('arrow', 'end', ARROWS, t.arrows, { of: t.arrowOf, set: t.arrowSet }, ArrowEndsIcon),\n ]\n}\n"],"mappings":";;;;AAkCA,IAAM,QAAQ;CAAE,QAAQ;CAAI,QAAQ;AAAK;AACzC,IAAM,MAAM,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAChD,IAAM,KAAK,OAAc,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;;AAG/C,IAAM,UAAmC;CACvC,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;CACnB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;;AAGA,SAAS,UAAU,KAAY,OAAe;CAC5C,MAAM,QAAQ,YAAoB;EAChC,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAAM;EACjD,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAA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GAAG,WAAW,KAAK,IAAI,EAAE,MAAM;OAAE,GAAG,KAAK;QAAO,MAAM,KAAK;MAAM,EAAE,CAAC;KACxE,CAAC;KACD,IAAI,SAAS,OAAO,KAAK,KAAK,EAAE,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC;IAC7D;GACF,EAAE;EACJ;CACF;CAEA,OAAO;EACL,OAAO,SAAS,YAAY,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,SAAS;EAC3F,OACE,QACA,SACA,cACA,EAAE,QACF;GAAE,IAAI,EAAE;GAAQ,KAAK,EAAE;EAAQ,GAC/B,aACF;EACA,OAAO,SAAS,OAAO,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,aAAa;CAC5F;AACF"}
@@ -1,9 +1,10 @@
1
+ import { turn } from "../core/geometry.js";
1
2
  import { defineNodeType } from "../core/node-types.js";
2
- import { defineFlowExtension } from "../core/extension.js";
3
3
  import { format } from "../locale.js";
4
+ import { defineFlowExtension } from "../core/extension.js";
4
5
  import { createId } from "../core/model.js";
5
- import { anchorPorts, whiteboardKeys } from "./model.js";
6
- import { boardState } from "./state.js";
6
+ import { whiteboardKeys } from "./model.js";
7
+ import { boardState, usable } from "./state.js";
7
8
  import board_node_default from "./board-node.js";
8
9
  import board_draft_default from "./board-draft.js";
9
10
  import { imageFiles, insertImages, pickImages } from "./image.js";
@@ -33,7 +34,7 @@ var turnedBy = (node) => node.data?.rotation ?? 0;
33
34
  var shapeNode = defineNodeType({
34
35
  type: "shape",
35
36
  component: board_node_default,
36
- ports: anchorPorts,
37
+ ports: "sides",
37
38
  frame: false,
38
39
  resizable: {
39
40
  minWidth: 24,
@@ -52,7 +53,7 @@ var shapeNode = defineNodeType({
52
53
  var stickyNode = defineNodeType({
53
54
  type: "sticky",
54
55
  component: board_node_default,
55
- ports: anchorPorts,
56
+ ports: "sides",
56
57
  frame: false,
57
58
  resizable: {
58
59
  minWidth: 64,
@@ -71,7 +72,7 @@ var stickyNode = defineNodeType({
71
72
  var textNode = defineNodeType({
72
73
  type: "text",
73
74
  component: board_node_default,
74
- ports: anchorPorts,
75
+ ports: "sides",
75
76
  frame: false,
76
77
  resizable: {
77
78
  minWidth: 24,
@@ -107,7 +108,7 @@ var inkNode = defineNodeType({
107
108
  var imageNode = defineNodeType({
108
109
  type: "image",
109
110
  component: board_node_default,
110
- ports: anchorPorts,
111
+ ports: "sides",
111
112
  frame: false,
112
113
  resizable: {
113
114
  minWidth: 24,
@@ -166,6 +167,51 @@ var SIZES = {
166
167
  height: 40
167
168
  }
168
169
  };
170
+ /**
171
+ * The comment tool: a click on a node starts a thread pinned where it was
172
+ * clicked, the point turned back with the node. A press on the empty canvas
173
+ * does nothing; a mouse drag does nothing either, so a thread isn't started
174
+ * by mistake, while a finger's drag moves the view, as it does elsewhere.
175
+ */
176
+ function pinComment(ctx, node, start, event) {
177
+ const client = {
178
+ x: event.clientX,
179
+ y: event.clientY
180
+ };
181
+ const origin = { ...ctx.viewport.value };
182
+ const finger = event.pointerType !== "mouse";
183
+ let moved = false;
184
+ return {
185
+ move(_, move) {
186
+ const dx = move.clientX - client.x;
187
+ const dy = move.clientY - client.y;
188
+ if (!moved && Math.hypot(dx, dy) <= 8) return;
189
+ moved = true;
190
+ if (finger) ctx.setViewport({
191
+ ...origin,
192
+ x: origin.x + dx,
193
+ y: origin.y + dy
194
+ });
195
+ },
196
+ end() {
197
+ const rect = node && !moved ? ctx.getNodeRect(node) : null;
198
+ if (!node || !rect || !rect.width || !rect.height) return;
199
+ const centre = {
200
+ x: rect.x + rect.width / 2,
201
+ y: rect.y + rect.height / 2
202
+ };
203
+ const local = turn(start, centre, -ctx.nodeRotation(node));
204
+ const at = {
205
+ x: (local.x - rect.x) / rect.width,
206
+ y: (local.y - rect.y) / rect.height
207
+ };
208
+ ctx.comment({
209
+ node,
210
+ at
211
+ }, { focus: !finger });
212
+ }
213
+ };
214
+ }
169
215
  /** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */
170
216
  function added(ctx, tool, id) {
171
217
  const state = boardState(ctx);
@@ -201,6 +247,7 @@ function whiteboardKit(options = {}) {
201
247
  state.tool.value = outer.value;
202
248
  stops.push(watch(outer, (tool) => state.tool.value = tool), watch(state.tool, (tool) => outer.value = tool));
203
249
  }
250
+ stops.push(watch(() => usable(ctx, state.tool.value), (ok) => !ok && (state.tool.value = "select"), { immediate: true }));
204
251
  stops.push(watch(state.tool, (tool) => {
205
252
  const root = ctx.root.value;
206
253
  if (root) root.dataset.boardTool = tool;
@@ -250,6 +297,8 @@ function whiteboardKit(options = {}) {
250
297
  const state = boardState(ctx);
251
298
  const tool = state.tool.value;
252
299
  if (tool === "select") return;
300
+ if (ctx.readonly.value && tool !== "hand" && tool !== "comment") return;
301
+ if (tool === "comment") return pinComment(ctx, press.node?.id ?? null, press.point, press.event);
253
302
  state.editing.value = null;
254
303
  if (tool === "hand") {
255
304
  const start = {
@@ -353,6 +402,7 @@ function whiteboardKit(options = {}) {
353
402
  keymap(ctx) {
354
403
  const state = boardState(ctx);
355
404
  const pick = (tool) => () => {
405
+ if (!usable(ctx, tool)) return false;
356
406
  state.tool.value = tool;
357
407
  state.locked.value = false;
358
408
  const t = ctx.messages.value.board;
@@ -367,8 +417,13 @@ function whiteboardKit(options = {}) {
367
417
  pickImages(ctx);
368
418
  },
369
419
  enter: () => {
370
- if (ctx.readonly.value) return false;
371
420
  const tool = state.tool.value;
421
+ if (tool === "comment") {
422
+ const { nodes, edges } = ctx.selection.value;
423
+ if (nodes.length !== 1 || edges.length) return false;
424
+ return ctx.comment({ node: nodes[0] }) || false;
425
+ }
426
+ if (ctx.readonly.value) return false;
372
427
  if (tool !== "select" && tool !== "hand" && tool !== "pen" && tool !== "eraser") {
373
428
  const { type, data } = kindOf(tool);
374
429
  const size = tool === "text" ? {