@open-artifact/whiteboard-core 0.9.2 → 0.11.0

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 (43) hide show
  1. package/package.json +4 -4
  2. package/src/backdrop.d.ts +4 -2
  3. package/src/backdrop.js +10 -3
  4. package/src/check.d.ts +9 -1
  5. package/src/check.js +91 -11
  6. package/src/drawn-svg/looks.d.ts +166 -0
  7. package/src/drawn-svg/looks.js +594 -0
  8. package/src/drawn-svg/svg-geometry.d.ts +7 -0
  9. package/src/drawn-svg/svg-geometry.js +37 -0
  10. package/src/drawn-svg/vetting.d.ts +4 -2
  11. package/src/drawn-svg/vetting.js +11 -5
  12. package/src/edits.d.ts +2 -2
  13. package/src/edits.js +2 -2
  14. package/src/geometry.js +2 -1
  15. package/src/history/board-diff.d.ts +7 -2
  16. package/src/history/board-diff.js +31 -6
  17. package/src/history/table-steps.d.ts +8 -3
  18. package/src/history/table-steps.js +38 -7
  19. package/src/hit-test.d.ts +2 -1
  20. package/src/hit-test.js +26 -5
  21. package/src/ideas.d.ts +2 -2
  22. package/src/ideas.js +3 -1
  23. package/src/index.d.ts +5 -0
  24. package/src/index.js +5 -0
  25. package/src/links.d.ts +2 -0
  26. package/src/links.js +9 -5
  27. package/src/next-item.d.ts +16 -1
  28. package/src/next-item.js +65 -15
  29. package/src/normalize.d.ts +2 -0
  30. package/src/normalize.js +14 -4
  31. package/src/schema.d.ts +20 -0
  32. package/src/schema.js +6 -0
  33. package/src/selection.js +8 -8
  34. package/src/table-tints.d.ts +84 -0
  35. package/src/table-tints.js +217 -0
  36. package/src/table.d.ts +17 -4
  37. package/src/table.js +59 -6
  38. package/src/text/placeholder.d.ts +17 -0
  39. package/src/text/placeholder.js +16 -0
  40. package/src/text/push-down.d.ts +29 -0
  41. package/src/text/push-down.js +72 -0
  42. package/src/text/turned-anchor.d.ts +19 -0
  43. package/src/text/turned-anchor.js +32 -0
@@ -10,7 +10,7 @@
10
10
  * same answer in the page, a worker and the server.
11
11
  */
12
12
  import { SVG_NAMESPACE } from "../image-source.js";
13
- import { flattenSvgShape, SVG_GEOMETRY_ATTRIBUTES } from "./svg-geometry.js";
13
+ import { flattenSvgShape, splitSvgPathArcs, SVG_GEOMETRY_ATTRIBUTES } from "./svg-geometry.js";
14
14
  import { parseSvgTree } from "./xml.js";
15
15
  /** Elements that draw geometry. */
16
16
  export const SVG_SHAPE_TAGS = new Set(['path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon']);
@@ -90,8 +90,10 @@ export const WHOLE_SVG_PART = 'all of it';
90
90
  export const SVG_VET_CACHE_MAX_CHARS = 4194304;
91
91
  /**
92
92
  * Total outline length of a shape (or of the shapes in a group), used to
93
- * count dash segments. `Infinity` when it cannot be measured cheaply
94
- * (non-numeric geometry, arcs).
93
+ * count dash segments. A path's arc counts as the full circle of its larger
94
+ * radius, plus the straight line between its ends. `Infinity` when it
95
+ * cannot be measured cheaply (non-numeric geometry) or has an arc with a
96
+ * radius under 1.
95
97
  */
96
98
  export function svgShapeLength(element) {
97
99
  if (!SVG_SHAPE_TAGS.has(element.localName))
@@ -105,8 +107,12 @@ export function svgShapeLength(element) {
105
107
  return 2 * (Math.abs(num('width')) + Math.abs(num('height')));
106
108
  if (element.localName === 'circle' || element.localName === 'ellipse')
107
109
  return 2 * Math.PI * Math.max(...['r', 'rx', 'ry'].map((name) => Math.abs(num(name))));
108
- const polylines = /a/i.test(element.getAttribute('d') ?? '') ? undefined : flattenSvgShape(element);
109
- let length = polylines === undefined ? Infinity : 0;
110
+ const d = element.localName === 'path' ? (element.getAttribute('d') ?? '') : '';
111
+ const arcs = /a/i.test(d) ? splitSvgPathArcs(d) : undefined;
112
+ if (/a/i.test(d) && (arcs === undefined || arcs.radii.some((radius) => radius < 1)))
113
+ return Infinity;
114
+ const polylines = flattenSvgShape(arcs === undefined ? element : { localName: 'path', getAttribute: (name) => (name === 'd' ? arcs.lines : element.getAttribute(name)) });
115
+ let length = polylines === undefined ? Infinity : (arcs?.radii ?? []).reduce((total, radius) => total + 2 * Math.PI * radius, 0);
110
116
  for (const polyline of polylines ?? [])
111
117
  for (let index = 2; index + 1 < polyline.length; index += 2)
112
118
  length += Math.hypot((polyline[index] ?? 0) - (polyline[index - 2] ?? 0), (polyline[index + 1] ?? 0) - (polyline[index - 1] ?? 0));
package/src/edits.d.ts CHANGED
@@ -17,8 +17,8 @@ export declare const DEFAULT_ARROW_LENGTH = 160;
17
17
  export declare const DUPLICATE_OFFSET = 24;
18
18
  /** The message shown when an attached arrow is copied or cut without its ends. */
19
19
  export declare function arrowNeedsEndsMessage(verb: string): string;
20
- /** The stored size of a table's cells and columns (what {@link TABLE_LIMITS}.bytes bounds). */
21
- export declare function tableContentBytes(table: Pick<TableElement, 'cols' | 'rows'>): number;
20
+ /** The stored size of a table's cells, columns, fills and heat maps (what {@link TABLE_LIMITS}.bytes bounds). */
21
+ export declare function tableContentBytes(table: Pick<TableElement, 'cols' | 'rows' | 'fills' | 'heat'>): number;
22
22
  /** A new table (at the origin, header row on, white header) from pasted cell text. */
23
23
  export declare function createPastedTable(grid: readonly (readonly string[])[]): TableElement;
24
24
  /** True when pasted text reads as a table: tab-separated, at least two rows. */
package/src/edits.js CHANGED
@@ -32,9 +32,9 @@ export const DUPLICATE_OFFSET = 24;
32
32
  export function arrowNeedsEndsMessage(verb) {
33
33
  return 'To ' + verb + ' an arrow, select what it is attached to as well.';
34
34
  }
35
- /** The stored size of a table's cells and columns (what {@link TABLE_LIMITS}.bytes bounds). */
35
+ /** The stored size of a table's cells, columns, fills and heat maps (what {@link TABLE_LIMITS}.bytes bounds). */
36
36
  export function tableContentBytes(table) {
37
- return escapedJsonByteLength({ cols: table.cols, rows: table.rows });
37
+ return escapedJsonByteLength({ cols: table.cols, rows: table.rows, ...(table.fills !== undefined ? { fills: table.fills } : {}), ...(table.heat !== undefined ? { heat: table.heat } : {}) });
38
38
  }
39
39
  /** A new table (at the origin, header row on, white header) from pasted cell text. */
40
40
  export function createPastedTable(grid) {
package/src/geometry.js CHANGED
@@ -21,6 +21,7 @@ import { edgeCode, encodePoints } from "./geom-codec.js";
21
21
  import { LINK_CARD_SIZE, MAX_ELEMENT_SIZE, TEXT_LINE_HEIGHT, TEXT_SIZE_STYLES, arrowEndIds, elementTurn, } from "./schema.js";
22
22
  import { tableTotalHeight, tableWidth } from "./table.js";
23
23
  import { MAX_LIST_INDENT_LEVEL } from "./text/markup.js";
24
+ import { textOrPlaceholder } from "./text/placeholder.js";
24
25
  /** Strips inline markup (`[text](url)`, `*`, `` ` ``, `\`) and keeps everything else. */
25
26
  function stripInlineMarkup(text) {
26
27
  return text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*`\\]/g, '');
@@ -295,7 +296,7 @@ export function elementLayoutBox(element, measures) {
295
296
  return { x: element.x, y: element.y, w: tableWidth(element), h: measures?.get(element.id)?.h ?? tableTotalHeight(element) };
296
297
  case 'text': {
297
298
  const measured = measures?.get(element.id);
298
- const size = measured?.w !== undefined && measured.h !== undefined ? { w: measured.w, h: measured.h } : estimateTextBlockSize(element.text, element.size, element.wrap);
299
+ const size = measured?.w !== undefined && measured.h !== undefined ? { w: measured.w, h: measured.h } : estimateTextBlockSize(textOrPlaceholder(element), element.size, element.wrap);
299
300
  return { x: element.x, y: element.y, w: element.wrap ?? size.w, h: size.h };
300
301
  }
301
302
  case 'stroke': {
@@ -6,7 +6,8 @@
6
6
  * Applying merges by field groups: only the fields the step changed (and the
7
7
  * fields that go with them) are written, so undoing a move does not revert
8
8
  * someone else's text edit of the same note. Tables, SVG drawings and
9
- * multi-element steps are applied as whole values.
9
+ * multi-element steps are applied as whole values, except a step that only
10
+ * moved or resized its elements.
10
11
  */
11
12
  import { type BoardContent, type BoardElement, type ElementId } from '../schema.ts';
12
13
  /** One element's change: absent `before` means added, absent `after` removed. */
@@ -40,6 +41,10 @@ export declare const FIELD_GROUPS: {
40
41
  export declare const LINKED_FIELD_GROUPS: readonly (readonly string[])[];
41
42
  /** Elements applied whole (their fields do not merge meaningfully). */
42
43
  export declare function isWholeValueElement(element: BoardElement): boolean;
44
+ /** Fields a move or resize changes. */
45
+ export declare const GEOMETRY_FIELDS: ReadonlySet<string>;
46
+ /** True when every element the step modified changed only {@link GEOMETRY_FIELDS}. */
47
+ export declare function diffChangesOnlyGeometry(diff: BoardDiff): boolean;
43
48
  /** True when the step modified more than one existing element. */
44
49
  export declare function diffChangesSeveral(diff: BoardDiff): boolean;
45
50
  /**
@@ -49,7 +54,7 @@ export declare function diffChangesSeveral(diff: BoardDiff): boolean;
49
54
  export declare function diffBoardContents(before: BoardContent, after: BoardContent, scope?: Iterable<ElementId>): BoardDiff | null;
50
55
  /** Moves the `ids` back to where `order` had them, relative to their neighbours. */
51
56
  export declare function restoreRecordedOrder(elements: readonly BoardElement[], order: readonly ElementId[], ids: ReadonlySet<ElementId>): BoardElement[];
52
- /** Keeps a link someone else set on an image when the step did not change it. */
57
+ /** Keeps a link or drawing style someone else set on an image when the step did not change it. */
53
58
  export declare function rebaseImageHref(next: BoardElement, current: BoardElement, base: BoardElement | undefined): BoardElement;
54
59
  /** Keeps a rotation someone else set when the step did not rotate. */
55
60
  export declare function rebaseTurn(next: BoardElement, current: BoardElement, base: BoardElement | undefined): BoardElement;
@@ -6,7 +6,8 @@
6
6
  * Applying merges by field groups: only the fields the step changed (and the
7
7
  * fields that go with them) are written, so undoing a move does not revert
8
8
  * someone else's text edit of the same note. Tables, SVG drawings and
9
- * multi-element steps are applied as whole values.
9
+ * multi-element steps are applied as whole values, except a step that only
10
+ * moved or resized its elements.
10
11
  */
11
12
  import { canonicalValuesEqual } from "../json.js";
12
13
  import { isSvgBase64DataUrl } from "../image-source.js";
@@ -37,6 +38,22 @@ export const LINKED_FIELD_GROUPS = [
37
38
  export function isWholeValueElement(element) {
38
39
  return element.type === 'table' || (element.type === 'image' && isSvgBase64DataUrl(element.src));
39
40
  }
41
+ /** Fields a move or resize changes. */
42
+ export const GEOMETRY_FIELDS = new Set([...FIELD_GROUPS.place, ...FIELD_GROUPS.box, 'turn']);
43
+ /** True when every element the step modified changed only {@link GEOMETRY_FIELDS}. */
44
+ export function diffChangesOnlyGeometry(diff) {
45
+ for (const { before, after } of diff.touched.values()) {
46
+ if (before === undefined || after === undefined)
47
+ continue;
48
+ const beforeFields = new Map(Object.entries(before));
49
+ const afterFields = new Map(Object.entries(after));
50
+ for (const key of new Set([...beforeFields.keys(), ...afterFields.keys()])) {
51
+ if (!GEOMETRY_FIELDS.has(key) && !canonicalValuesEqual(beforeFields.get(key), afterFields.get(key)))
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
40
57
  /** True when the step modified more than one existing element. */
41
58
  export function diffChangesSeveral(diff) {
42
59
  let count = 0;
@@ -114,12 +131,20 @@ export function restoreRecordedOrder(elements, order, ids) {
114
131
  });
115
132
  return kept;
116
133
  }
117
- /** Keeps a link someone else set on an image when the step did not change it. */
134
+ /** Keeps a link or drawing style someone else set on an image when the step did not change it. */
118
135
  export function rebaseImageHref(next, current, base) {
119
- if (next.type !== 'image' || current.type !== 'image' || base?.type !== 'image' || next.href !== base.href || next.href === current.href)
136
+ if (next.type !== 'image' || current.type !== 'image' || base?.type !== 'image')
120
137
  return next;
121
- const { href: _href, ...rest } = next;
122
- return current.href === undefined ? rest : { ...rest, href: current.href };
138
+ let result = next;
139
+ if (next.href === base.href && next.href !== current.href) {
140
+ const { href: _href, ...rest } = result;
141
+ result = current.href === undefined ? rest : { ...rest, href: current.href };
142
+ }
143
+ if (next.style === base.style && next.style !== current.style) {
144
+ const { style: _style, ...rest } = result;
145
+ result = current.style === undefined ? rest : { ...rest, style: current.style };
146
+ }
147
+ return result;
123
148
  }
124
149
  /** Keeps a rotation someone else set when the step did not rotate. */
125
150
  export function rebaseTurn(next, current, base) {
@@ -195,7 +220,7 @@ export function applyBoardDiff(content, diff, direction, force = false) {
195
220
  const endsPresent = (element) => everyArrowEndId(element, (id) => elements.some((item) => item.id === id));
196
221
  const arrowRank = (change) => Number(change.before?.type === 'arrow' && change.after?.type === 'arrow');
197
222
  const onlyLockChanged = [...diff.touched.values()].every((change) => canonicalValuesEqual({ ...change.before, locked: undefined }, { ...change.after, locked: undefined }));
198
- const wholeValues = force || (diffChangesSeveral(diff) && !onlyLockChanged);
223
+ const wholeValues = force || (diffChangesSeveral(diff) && !onlyLockChanged && !diffChangesOnlyGeometry(diff));
199
224
  const entries = [...diff.touched].sort(([, a], [, b]) => arrowRank(a) - arrowRank(b));
200
225
  for (const [id, change] of entries) {
201
226
  const [target, source] = direction === 'forward' ? [change.after, change.before] : [change.before, change.after];
@@ -19,7 +19,8 @@
19
19
  * cell's step is recorded once the edit leaves the cell
20
20
  * ({@link TableEditor.setCell}).
21
21
  */
22
- import type { BoardContent, ElementId, TableElement } from '../schema.ts';
22
+ import type { BoardContent, ElementId, FillColor, TableElement } from '../schema.ts';
23
+ import { type TableAxis } from '../table.ts';
23
24
  import type { StepDocument, StepHistory } from './board-steps.ts';
24
25
  /** What the table editor says when it refuses a change. */
25
26
  export declare const TABLE_STEP_MESSAGES: {
@@ -35,9 +36,9 @@ export type TableCellSwap = readonly [rowId: string, columnId: string, expected:
35
36
  export declare function findTableElement(content: BoardContent, id: ElementId): TableElement | undefined;
36
37
  /** Sets each cell to its value, but only where it still holds the expected text. */
37
38
  export declare function setCellsWhereUnchanged(edits: readonly TableCellSwap[]): TableChange;
38
- /** Removes the rows `rowIds` that are empty. */
39
+ /** Removes the rows `rowIds` that are empty (no text, fill or heat map). */
39
40
  export declare function dropEmptyTableRows(rowIds: readonly string[]): TableChange;
40
- /** Removes the columns `colIds` that are empty. */
41
+ /** Removes the columns `colIds` that are empty (no text, fill or heat map). */
41
42
  export declare function dropEmptyTableColumns(colIds: readonly string[]): TableChange;
42
43
  /**
43
44
  * Replaces the table `id` in the document with `change(table)`. Auto-width
@@ -92,6 +93,10 @@ export interface TableEditor {
92
93
  * past its limits.
93
94
  */
94
95
  fill(id: ElementId, row: string, col: string, grid: readonly (readonly string[])[]): boolean;
96
+ /** Sets cells' fills (`""` clears one) as one step. */
97
+ setFills(id: ElementId, cells: readonly (readonly [row: string, col: string, color: FillColor | ''])[]): boolean;
98
+ /** Sets a heat map on a column or row (`""` takes it off) as one step; see {@link withTableHeat}. */
99
+ setHeat(id: ElementId, axis: TableAxis, line: string, color: FillColor | ''): boolean;
95
100
  }
96
101
  /** Creates a table editor over a document and a history. */
97
102
  export declare function createTableEditor(doc: StepDocument, history: StepHistory, options?: TableEditorOptions): TableEditor;
@@ -20,7 +20,9 @@
20
20
  * ({@link TableEditor.setCell}).
21
21
  */
22
22
  import { tableContentBytes } from "../edits.js";
23
- import { COLUMN_WIDTH_LIMITS, TABLE_LIMITS, addTableColumns, addTableRows, columnWidth, exceedsTableCellLimit, freshTableKey, hasTableCell, pinColumnWidths, removeTableColumn, removeTableRow, resizeColumn, setTableAxisOrder, setTableCell, setTableCells, tableCellValue, tableColumnIds, tableInsertPosition, tableRowIds, widenColumnToFit, } from "../table.js";
23
+ import { canonicalValuesEqual } from "../json.js";
24
+ import { setTableFillsWhereUnchanged, setTableHeatWhereUnchanged, tableCellFill, tableFillSwaps, withTableHeat } from "../table-tints.js";
25
+ import { COLUMN_WIDTH_LIMITS, TABLE_LIMITS, addTableColumns, addTableRows, columnWidth, exceedsTableCellLimit, freshTableKey, hasTableCell, pinColumnWidths, removeTableColumn, removeTableRow, resizeColumn, setTableAxisOrder, setTableCell, setTableCells, tableCellValue, tableColumnIds, tableColumnIsTinted, tableInsertPosition, tableRowIds, tableRowIsTinted, widenColumnToFit, } from "../table.js";
24
26
  import { normalizeBoardContent } from "./content.js";
25
27
  /** What the table editor says when it refuses a change. */
26
28
  export const TABLE_STEP_MESSAGES = {
@@ -37,13 +39,13 @@ export function findTableElement(content, id) {
37
39
  export function setCellsWhereUnchanged(edits) {
38
40
  return (table) => setTableCells(table, edits.flatMap(([row, col, expected, value]) => (tableCellValue(table, row, col) === expected ? [[row, col, value]] : [])));
39
41
  }
40
- /** Removes the rows `rowIds` that are empty. */
42
+ /** Removes the rows `rowIds` that are empty (no text, fill or heat map). */
41
43
  export function dropEmptyTableRows(rowIds) {
42
- return (start) => rowIds.reduce((table, rowId) => (tableColumnIds(table).every((colId) => tableCellValue(table, rowId, colId) === '') ? removeTableRow(table, rowId) : table), start);
44
+ return (start) => rowIds.reduce((table, rowId) => !tableRowIsTinted(table, rowId) && tableColumnIds(table).every((colId) => tableCellValue(table, rowId, colId) === '') ? removeTableRow(table, rowId) : table, start);
43
45
  }
44
- /** Removes the columns `colIds` that are empty. */
46
+ /** Removes the columns `colIds` that are empty (no text, fill or heat map). */
45
47
  export function dropEmptyTableColumns(colIds) {
46
- return (start) => colIds.reduce((table, colId) => (tableRowIds(table).every((rowId) => tableCellValue(table, rowId, colId) === '') ? removeTableColumn(table, colId) : table), start);
48
+ return (start) => colIds.reduce((table, colId) => !tableColumnIsTinted(table, colId) && tableRowIds(table).every((rowId) => tableCellValue(table, rowId, colId) === '') ? removeTableColumn(table, colId) : table, start);
47
49
  }
48
50
  /** Fills cells that are empty now. */
49
51
  function fillEmptyCells(cells) {
@@ -81,6 +83,13 @@ export function replaceTableElement(doc, id, change, refusal = TABLE_STEP_MESSAG
81
83
  doc.setContent(nextContent);
82
84
  return true;
83
85
  }
86
+ /** Brings back the fills and heat map a deleted row or column had, where nothing took their place. */
87
+ function bringBackTints(table, axis, line) {
88
+ const color = table.heat?.[axis]?.[line];
89
+ const lineFills = Object.entries(table.fills ?? {}).flatMap(([rowId, cells]) => axis === 'rows' ? (rowId === line ? [[rowId, cells]] : []) : cells[line] !== undefined ? [[rowId, { [line]: cells[line] }]] : []);
90
+ const swaps = tableFillSwaps({}, { fills: Object.fromEntries(lineFills) });
91
+ return (current) => setTableFillsWhereUnchanged(color !== undefined && current.heat?.[axis]?.[line] === undefined ? withTableHeat(current, axis, line, color) : current, swaps);
92
+ }
84
93
  /** Creates a table editor over a document and a history. */
85
94
  export function createTableEditor(doc, history, options = {}) {
86
95
  const { onRefused, onEdit } = options;
@@ -96,6 +105,12 @@ export function createTableEditor(doc, history, options = {}) {
96
105
  seedUndo(id, label, redo, undo);
97
106
  return true;
98
107
  };
108
+ /** Records the step from `table` to `next` in fills and heat maps, changing only what is still as it was. */
109
+ const seedTints = (id, label, table, next) => {
110
+ const swaps = tableFillSwaps(table, next);
111
+ const back = swaps.map(([row, col, from, to]) => [row, col, to, from]);
112
+ return applyAndSeed(id, label, (current) => setTableFillsWhereUnchanged(setTableHeatWhereUnchanged(current, table.heat, next.heat), swaps), (current) => setTableFillsWhereUnchanged(setTableHeatWhereUnchanged(current, next.heat, table.heat), back));
113
+ };
99
114
  /** Makes room for a new row or column at `index` (renumbering when needed); returns its order key. */
100
115
  const insertAt = (id, axis, index) => {
101
116
  const table = tableOf(id);
@@ -159,7 +174,8 @@ export function createTableEditor(doc, history, options = {}) {
159
174
  if (table === undefined || typeof at !== 'number')
160
175
  return false;
161
176
  const cells = tableColumnIds(table).map((colId) => [rowId, colId, tableCellValue(table, rowId, colId)]);
162
- return applyAndSeed(id, 'Delete row', (current) => removeTableRow(current, rowId), (current) => fillEmptyCells(cells)(setTableAxisOrder(addTableRows(current, [[rowId, at]], true), 'rows', rowId, at)));
177
+ const tints = bringBackTints(table, 'rows', rowId);
178
+ return applyAndSeed(id, 'Delete row', (current) => removeTableRow(current, rowId), (current) => tints(fillEmptyCells(cells)(setTableAxisOrder(addTableRows(current, [[rowId, at]], true), 'rows', rowId, at))));
163
179
  },
164
180
  removeCol(id, colId) {
165
181
  const table = ensurePlaced(id, 'cols', colId);
@@ -168,7 +184,8 @@ export function createTableEditor(doc, history, options = {}) {
168
184
  if (table === undefined || typeof at !== 'number' || width === undefined)
169
185
  return false;
170
186
  const cells = tableRowIds(table).map((rowId) => [rowId, colId, tableCellValue(table, rowId, colId)]);
171
- return applyAndSeed(id, 'Delete column', (current) => removeTableColumn(current, colId), (current) => fillEmptyCells(cells)(addTableColumns(current, [[colId, at, width]], true)));
187
+ const tints = bringBackTints(table, 'cols', colId);
188
+ return applyAndSeed(id, 'Delete column', (current) => removeTableColumn(current, colId), (current) => tints(fillEmptyCells(cells)(addTableColumns(current, [[colId, at, width]], true))));
172
189
  },
173
190
  colWidth(id, col, width, target, settled = target) {
174
191
  const changed = replace(id, (table) => widenColumnToFit(table, col, width, settled));
@@ -216,5 +233,19 @@ export function createTableEditor(doc, history, options = {}) {
216
233
  }));
217
234
  return applyAndSeed(id, 'Paste cells', (target) => setTableCells(addTableColumns(addTableRows(target, newRows, true), newCols.map(([key, at]) => [key, at, COLUMN_WIDTH_LIMITS.fresh]), true), cells.map(([rowId, colId, , value]) => [rowId, colId, value])), (target) => dropEmptyTableColumns(newCols.map(([key]) => key))(dropEmptyTableRows(newRows.map(([key]) => key))(setCellsWhereUnchanged(cells.map(([rowId, colId, before, after]) => [rowId, colId, after, before]))(target))), TABLE_STEP_MESSAGES.tooBigPaste);
218
235
  },
236
+ setFills(id, cells) {
237
+ const table = tableOf(id);
238
+ if (table === undefined)
239
+ return false;
240
+ const next = setTableFillsWhereUnchanged(table, cells.map(([row, col, color]) => [row, col, tableCellFill(table, row, col), color]));
241
+ return next !== table && seedTints(id, 'Fill cells', table, next);
242
+ },
243
+ setHeat(id, axis, line, color) {
244
+ const table = tableOf(id);
245
+ if (table === undefined)
246
+ return false;
247
+ const next = withTableHeat(table, axis, line, color);
248
+ return next !== table && !canonicalValuesEqual(next, table) && seedTints(id, 'Heat map', table, next);
249
+ },
219
250
  };
220
251
  }
package/src/hit-test.d.ts CHANGED
@@ -92,7 +92,8 @@ export declare function arrowLabelBeneath(elements: readonly BoardElement[], ind
92
92
  /**
93
93
  * The topmost element under the point. Section title text wins first, then
94
94
  * any non-section element (front to back), then section title chips, then
95
- * section edges.
95
+ * section edges. A text showing its placeholder is hit only where nothing
96
+ * else is.
96
97
  */
97
98
  export declare function topElementAt(elements: readonly BoardElement[], x: number, y: number, tolerance?: number, measures?: ElementMeasures, byId?: ElementsById, zoom?: number): BoardElement | undefined;
98
99
  export {};
package/src/hit-test.js CHANGED
@@ -23,6 +23,7 @@ import { kindCode } from "./geom-codec.js";
23
23
  import { arrowPolyline, containerTitleBounds, containerTitleTextBounds, elementLayoutBox, geometryHooks, measuredArrowGeometry, measuredArrowLabelBox, noteAuthorBottomPadding, } from "./geometry.js";
24
24
  import { FACE_STICKER_ART, TEXT_SIZE_STYLES, arrowEndIds, arrowHeads, elementTurn, } from "./schema.js";
25
25
  import { shapeTextInsets } from "./shape-paths.js";
26
+ import { PLACEHOLDER_HIT_MIN_PX, showsTextPlaceholder } from "./text/placeholder.js";
26
27
  /** How far (in board units) a pointer may miss: 16 screen px for touch, 6 for a mouse. */
27
28
  export function hitSlop(pointerType, zoom) {
28
29
  return (pointerType === 'touch' ? 16 : 6) / zoom;
@@ -66,10 +67,22 @@ function pushBox(out, box) {
66
67
  else
67
68
  out.push(1, box.x, box.y, box.w, box.h);
68
69
  }
70
+ /**
71
+ * The box a press hits: the layout box, made at least
72
+ * {@link PLACEHOLDER_HIT_MIN_PX} tall on screen (about its middle) for a
73
+ * text showing its placeholder.
74
+ */
75
+ function hitLayoutBox(element, measures, zoom) {
76
+ const box = elementLayoutBox(element, measures);
77
+ if (box === undefined || !showsTextPlaceholder(element))
78
+ return box;
79
+ const least = PLACEHOLDER_HIT_MIN_PX / (zoom !== undefined && zoom > 0 ? zoom : 1);
80
+ return box.h >= least ? box : { ...box, y: box.y - (least - box.h) / 2, h: least };
81
+ }
69
82
  /** The record of an element: what testing a point against it needs. */
70
83
  function buildHitRecord(element, measures, byId, zoom) {
71
84
  const out = [0, BODY_OTHER, elementTurn(element)];
72
- pushBox(out, elementLayoutBox(element, measures));
85
+ pushBox(out, hitLayoutBox(element, measures, zoom));
73
86
  switch (element.type) {
74
87
  case 'arrow': {
75
88
  const line = byId === undefined ? undefined : measuredArrowGeometry(element, byId, measures);
@@ -130,7 +143,7 @@ function hitRecord(element, measures, byId, zoom) {
130
143
  const key = {
131
144
  measures,
132
145
  byId: element.type === 'arrow' ? byId : undefined,
133
- zoom: element.type === 'container' ? zoom : undefined,
146
+ zoom: element.type === 'container' || showsTextPlaceholder(element) ? zoom : undefined,
134
147
  hooks: element.type === 'shape' ? geometryHooks() : undefined,
135
148
  };
136
149
  const cached = hitRecordCache.get(element);
@@ -309,9 +322,17 @@ export function arrowLabelBeneath(elements, index, x, y, tolerance, measures, by
309
322
  /**
310
323
  * The topmost element under the point. Section title text wins first, then
311
324
  * any non-section element (front to back), then section title chips, then
312
- * section edges.
325
+ * section edges. A text showing its placeholder is hit only where nothing
326
+ * else is.
313
327
  */
314
328
  export function topElementAt(elements, x, y, tolerance = 4, measures, byId, zoom) {
315
- const found = wbGeom().top_element_at(hitRecords(elements, measures, byIdOf(elements, byId), zoom), x, y, tolerance);
316
- return found < 0 ? undefined : elements[found];
329
+ const lookup = byIdOf(elements, byId);
330
+ const found = wbGeom().top_element_at(hitRecords(elements, measures, lookup, zoom), x, y, tolerance);
331
+ const hit = found < 0 ? undefined : elements[found];
332
+ if (hit === undefined || !showsTextPlaceholder(hit))
333
+ return hit;
334
+ // An empty text's hint gives way to anything else under the point.
335
+ const others = elements.filter((element) => !showsTextPlaceholder(element));
336
+ const other = wbGeom().top_element_at(hitRecords(others, measures, lookup, zoom), x, y, tolerance);
337
+ return other < 0 ? hit : others[other];
317
338
  }
package/src/ideas.d.ts CHANGED
@@ -126,9 +126,9 @@ export declare const VERSION_EDIT_FIELDS: readonly ["x", "y", "w", "h", "tilt",
126
126
  /** Element types a version may create. */
127
127
  export declare const VERSION_NEW_TYPES: readonly ["note", "shape", "container", "text", "arrow", "sticker", "image", "table", "stroke"];
128
128
  /** Fields a version may set on an element it creates. */
129
- export declare const VERSION_NEW_ELEMENT_FIELDS: readonly ["x", "y", "w", "h", "tilt", "text", "label", "words", "author", "size", "ink", "textAlign", "wrap", "color", "stroke", "hollow", "solid", "kind", "lay", "dash", "head", "heads", "from", "to", "fromSide", "toSide", "jog", "bends", "width", "type", "by", "points", "src", "crop", "cols", "rows", "glyph", "art", "title"];
129
+ export declare const VERSION_NEW_ELEMENT_FIELDS: readonly ["x", "y", "w", "h", "tilt", "text", "label", "words", "author", "size", "ink", "textAlign", "wrap", "color", "stroke", "hollow", "solid", "kind", "lay", "dash", "head", "heads", "from", "to", "fromSide", "toSide", "jog", "bends", "width", "type", "by", "points", "src", "style", "crop", "cols", "rows", "fills", "heat", "placeholder", "glyph", "art", "title"];
130
130
  /** Fields a version may set on a web embed it creates. */
131
- export declare const VERSION_NEW_EMBED_FIELDS: readonly ["x", "y", "w", "h", "tilt", "text", "label", "words", "author", "size", "ink", "textAlign", "wrap", "color", "stroke", "hollow", "solid", "kind", "lay", "dash", "head", "heads", "from", "to", "fromSide", "toSide", "jog", "bends", "width", "type", "by", "points", "src", "crop", "cols", "rows", "glyph", "art", "title", "html", "state"];
131
+ export declare const VERSION_NEW_EMBED_FIELDS: readonly ["x", "y", "w", "h", "tilt", "text", "label", "words", "author", "size", "ink", "textAlign", "wrap", "color", "stroke", "hollow", "solid", "kind", "lay", "dash", "head", "heads", "from", "to", "fromSide", "toSide", "jog", "bends", "width", "type", "by", "points", "src", "style", "crop", "cols", "rows", "fills", "heat", "placeholder", "glyph", "art", "title", "html", "state"];
132
132
  /** Options of {@link parseVersionOptions}. */
133
133
  export interface VersionParseOptions {
134
134
  /** A version may create web embeds. */
package/src/ideas.js CHANGED
@@ -124,7 +124,9 @@ export const VERSION_EDIT_FIELDS = [
124
124
  /** Element types a version may create. */
125
125
  export const VERSION_NEW_TYPES = ['note', 'shape', 'container', 'text', 'arrow', 'sticker', 'image', 'table', 'stroke'];
126
126
  /** Fields a version may set on an element it creates. */
127
- export const VERSION_NEW_ELEMENT_FIELDS = [...VERSION_EDIT_FIELDS, 'type', 'by', 'points', 'src', 'crop', 'cols', 'rows', 'glyph', 'art', 'title'];
127
+ export const VERSION_NEW_ELEMENT_FIELDS = [
128
+ ...VERSION_EDIT_FIELDS, 'type', 'by', 'points', 'src', 'style', 'crop', 'cols', 'rows', 'fills', 'heat', 'placeholder', 'glyph', 'art', 'title',
129
+ ];
128
130
  /** Fields a version may set on a web embed it creates. */
129
131
  export const VERSION_NEW_EMBED_FIELDS = [...VERSION_NEW_ELEMENT_FIELDS, 'html', 'state'];
130
132
  const VERSION_EDIT_ID_PATTERN = /^(?!\.{1,40}$)[A-Za-z0-9_.~:@+-]{1,40}$/;
package/src/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './links.ts';
16
16
  export * from './stickers.ts';
17
17
  export * from './sticker-hosts.ts';
18
18
  export * from './table.ts';
19
+ export * from './table-tints.ts';
19
20
  export * from './timer.ts';
20
21
  export * from './inks.ts';
21
22
  export * from './theme.ts';
@@ -43,6 +44,7 @@ export * from './drawn-svg/svg-geometry.ts';
43
44
  export * from './drawn-svg/vetting.ts';
44
45
  export * from './drawn-svg/restyle.ts';
45
46
  export * from './drawn-svg/contrast.ts';
47
+ export * from './drawn-svg/looks.ts';
46
48
  export * from './text/inline-markdown.ts';
47
49
  export * from './text/note-markdown.ts';
48
50
  export * from './text/text-arrows.ts';
@@ -50,6 +52,9 @@ export * from './text/markup.ts';
50
52
  export * from './text/measure.ts';
51
53
  export * from './text/fit.ts';
52
54
  export * from './text/links.ts';
55
+ export * from './text/placeholder.ts';
56
+ export * from './text/push-down.ts';
57
+ export * from './text/turned-anchor.ts';
53
58
  export * from './sync/index.ts';
54
59
  export * from './history.ts';
55
60
  export * from './version-board.ts';
package/src/index.js CHANGED
@@ -18,6 +18,7 @@ export * from "./links.js";
18
18
  export * from "./stickers.js";
19
19
  export * from "./sticker-hosts.js";
20
20
  export * from "./table.js";
21
+ export * from "./table-tints.js";
21
22
  export * from "./timer.js";
22
23
  export * from "./inks.js";
23
24
  export * from "./theme.js";
@@ -47,6 +48,7 @@ export * from "./drawn-svg/svg-geometry.js";
47
48
  export * from "./drawn-svg/vetting.js";
48
49
  export * from "./drawn-svg/restyle.js";
49
50
  export * from "./drawn-svg/contrast.js";
51
+ export * from "./drawn-svg/looks.js";
50
52
  export * from "./text/inline-markdown.js";
51
53
  export * from "./text/note-markdown.js";
52
54
  export * from "./text/text-arrows.js";
@@ -54,6 +56,9 @@ export * from "./text/markup.js";
54
56
  export * from "./text/measure.js";
55
57
  export * from "./text/fit.js";
56
58
  export * from "./text/links.js";
59
+ export * from "./text/placeholder.js";
60
+ export * from "./text/push-down.js";
61
+ export * from "./text/turned-anchor.js";
57
62
  // Collaboration: live sync, undo history, claims, ideas, comments, the view
58
63
  // context, the clipboard and board files.
59
64
  export * from "./sync/index.js";
package/src/links.d.ts CHANGED
@@ -19,6 +19,8 @@ export declare function normalizeArtifactAddress(href: unknown): string | undefi
19
19
  export declare function normalizeLinkHref(href: unknown): string | undefined;
20
20
  /** True when the card points at another artifact. */
21
21
  export declare function isArtifactLink(href: string): boolean;
22
+ /** A short one-line label: whitespace collapsed, invisible characters dropped, capped at `maxChars`. */
23
+ export declare function sanitizeShortLabel(label: unknown, maxChars: number): string;
22
24
  /** A card title: whitespace collapsed, invisible characters dropped, capped. */
23
25
  export declare function sanitizeLinkTitle(title: unknown): string;
24
26
  /** The link fields of a card, or `undefined` when its address is not allowed. Legacy `kind: "board"` reads as `whiteboard`. */
package/src/links.js CHANGED
@@ -48,16 +48,20 @@ export function normalizeLinkHref(href) {
48
48
  export function isArtifactLink(href) {
49
49
  return normalizeArtifactAddress(href) !== undefined;
50
50
  }
51
- /** A card title: whitespace collapsed, invisible characters dropped, capped. */
52
- export function sanitizeLinkTitle(title) {
53
- if (typeof title !== 'string')
51
+ /** A short one-line label: whitespace collapsed, invisible characters dropped, capped at `maxChars`. */
52
+ export function sanitizeShortLabel(label, maxChars) {
53
+ if (typeof label !== 'string')
54
54
  return '';
55
- const value = title
55
+ const value = label
56
56
  .replace(/\s+/g, ' ')
57
57
  .replace(/(?![‌‍\u{E0020}-\u{E007F}])[\p{Cc}\p{Cf}]/gu, '')
58
58
  .replace(/ +/g, ' ')
59
59
  .trim();
60
- return VISIBLE_TITLE_CHAR_PATTERN.test(value) ? [...value].slice(0, MAX_LINK_TITLE_CHARS).join('') : '';
60
+ return VISIBLE_TITLE_CHAR_PATTERN.test(value) ? [...value].slice(0, maxChars).join('').trim() : '';
61
+ }
62
+ /** A card title: whitespace collapsed, invisible characters dropped, capped. */
63
+ export function sanitizeLinkTitle(title) {
64
+ return sanitizeShortLabel(title, MAX_LINK_TITLE_CHARS);
61
65
  }
62
66
  /** The link fields of a card, or `undefined` when its address is not allowed. Legacy `kind: "board"` reads as `whiteboard`. */
63
67
  export function normalizeLinkFields(input) {
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Where a next item goes: beside an item (Mod+Return while typing), or at
2
+ * Where a next item goes: beside an item (Mod+Return while typing, or a
3
+ * click on one of its side dots, which also need room around them), or at
3
4
  * the free end of an arrow just drawn into empty board (the *next-item
4
5
  * offer*: the editor shows a faint item there that Return or a click adds,
5
6
  * joined to the arrow).
@@ -31,6 +32,20 @@ export declare function boxesNearlyTouch(a: Box, b: Box): boolean;
31
32
  * sits centered inside (its frames) are not in the way.
32
33
  */
33
34
  export declare function placeNextItemBeside<T extends NextItem>(from: BoardElement, template: T, elements: readonly BoardElement[], measures?: ElementMeasures, side?: ArrowSide): T;
35
+ /**
36
+ * Where the item a click on `from`'s `side` dot adds goes: right beside
37
+ * `from` on that side when the spot is clear, else right below `from`, else
38
+ * nowhere (`undefined`). It never steps past items in the way.
39
+ */
40
+ export declare function placeNextItemAtSide<T extends NextItem>(from: BoardElement, template: T, side: ArrowSide, elements: readonly BoardElement[], measures?: ElementMeasures): T | undefined;
41
+ /** Items that take the room a side dot needs: notes, shapes, sections and stickers. */
42
+ export declare const SIDE_DOT_BLOCKING_TYPES: ReadonlySet<ElementType>;
43
+ /**
44
+ * Whether a side dot at (`x`, `y`) has room: no note, shape, section or
45
+ * sticker other than `owner` within `reach` of it. A section counts by its
46
+ * outline, so a dot well inside one still has room.
47
+ */
48
+ export declare function sideDotHasRoom(owner: BoardElement, x: number, y: number, reach: number, elements: readonly BoardElement[], measures?: ElementMeasures): boolean;
34
49
  /** An item offered at an arrow's free end. */
35
50
  export interface ArrowEndOffer {
36
51
  /** The arrow as it was when the offer was made. */