@open-artifact/whiteboard-core 0.10.0 → 0.12.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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-artifact/whiteboard-core",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "The Whiteboard artifact model: element schema and normalization, the document codec, geometry, arrows, hand-drawn ink, history, view context and the live sync engine.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,9 +16,9 @@
16
16
  "NOTICE"
17
17
  ],
18
18
  "dependencies": {
19
- "@open-artifact/live-store": "0.10.0",
20
- "@open-artifact/protocol": "0.10.0",
21
- "@open-artifact/wasm-wb-geom": "0.10.0"
19
+ "@open-artifact/live-store": "0.12.0",
20
+ "@open-artifact/protocol": "0.12.0",
21
+ "@open-artifact/wasm-wb-geom": "0.12.0"
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "author": {
package/src/backdrop.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { type Box, type ElementMeasures } from './geometry.ts';
9
9
  import { type BoardElement, type ElementId, type NoteElement, type ShapeElement } from './schema.ts';
10
+ import { type ColorScheme } from './theme.ts';
10
11
  /** Slack (board units) when deciding that text sits inside or overlaps a backdrop. */
11
12
  export declare const TEXT_BACKDROP_TOLERANCE = 4;
12
13
  /** True for elements that hide what is drawn under them. */
@@ -22,6 +23,7 @@ export declare function isRotatedBoxInside(outer: BoardElement, outerBox: Box, i
22
23
  * The fill color (hex) behind each text element that sits on a backdrop:
23
24
  * the topmost opaque element drawn before the text and overlapping it by
24
25
  * more than {@link TEXT_BACKDROP_TOLERANCE}, when that element is a
25
- * backdrop that holds the whole text.
26
+ * backdrop that holds the whole text. Given the board's `scheme`, a
27
+ * drawing whose look lays paper behind it is a backdrop in that paper's tone.
26
28
  */
27
- export declare function textBackdropColors(elements: readonly BoardElement[], measures?: ElementMeasures): Map<ElementId, string>;
29
+ export declare function textBackdropColors(elements: readonly BoardElement[], measures?: ElementMeasures, scheme?: ColorScheme): Map<ElementId, string>;
package/src/backdrop.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import { elementBounds, elementLayoutBox, rotatePointAround } from "./geometry.js";
9
9
  import { elementTurn } from "./schema.js";
10
10
  import { blockColorHex, shapeFillColor } from "./theme.js";
11
+ import { drawingLookPaper, imageDrawingLook } from "./drawn-svg/looks.js";
11
12
  /** Slack (board units) when deciding that text sits inside or overlaps a backdrop. */
12
13
  export const TEXT_BACKDROP_TOLERANCE = 4;
13
14
  /** True for elements that hide what is drawn under them. */
@@ -36,9 +37,10 @@ export function isRotatedBoxInside(outer, outerBox, inner, innerBox) {
36
37
  * The fill color (hex) behind each text element that sits on a backdrop:
37
38
  * the topmost opaque element drawn before the text and overlapping it by
38
39
  * more than {@link TEXT_BACKDROP_TOLERANCE}, when that element is a
39
- * backdrop that holds the whole text.
40
+ * backdrop that holds the whole text. Given the board's `scheme`, a
41
+ * drawing whose look lays paper behind it is a backdrop in that paper's tone.
40
42
  */
41
- export function textBackdropColors(elements, measures) {
43
+ export function textBackdropColors(elements, measures, scheme) {
42
44
  const backdrops = [];
43
45
  const backdropColorByTextId = new Map();
44
46
  for (const element of elements) {
@@ -56,7 +58,12 @@ export function textBackdropColors(elements, measures) {
56
58
  continue;
57
59
  const backdropBox = elementLayoutBox(backdrop, measures);
58
60
  const textBox = elementLayoutBox(element, measures);
59
- if (isTextBackdropElement(backdrop) && backdropBox !== undefined && textBox !== undefined && isRotatedBoxInside(backdrop, backdropBox, element, textBox))
61
+ const look = scheme !== undefined && backdrop.type === 'image' ? imageDrawingLook(backdrop) : undefined;
62
+ const paper = look !== undefined && scheme !== undefined ? drawingLookPaper(look, scheme) : undefined;
63
+ const inside = backdropBox !== undefined && textBox !== undefined && isRotatedBoxInside(backdrop, backdropBox, element, textBox);
64
+ if (inside && paper !== undefined)
65
+ backdropColorByTextId.set(element.id, paper);
66
+ else if (inside && isTextBackdropElement(backdrop))
60
67
  backdropColorByTextId.set(element.id, backdrop.type === 'shape' ? shapeFillColor(backdrop) : blockColorHex(backdrop.color));
61
68
  break;
62
69
  }
package/src/check.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * on its own; info notes are harmless oddities.
9
9
  */
10
10
  import { type DocumentValue } from './codec.ts';
11
+ import { type TableElement } from './schema.ts';
11
12
  import { type TableData } from './table.ts';
12
13
  /** Severity of a board finding. */
13
14
  export type BoardCheckLevel = 'error' | 'warning' | 'info';
@@ -30,7 +31,8 @@ export declare const MAX_DRAWING_GROUP_DEPTH = 5;
30
31
  export declare const MAX_DRAWING_OPACITY = 64;
31
32
  /**
32
33
  * Findings about an image's SVG drawing (`data:image/svg+xml…`): a raw `#`,
33
- * a URI that does not decode or holds no `<svg>`, and what makes the page
34
+ * a URI that does not decode or holds no `<svg>`, a drawing over the size
35
+ * limits (saying by how much), and what makes the page
34
36
  * show a grey box instead (nesting, opacity layers, parts it does not know).
35
37
  * Empty for any other source.
36
38
  */
@@ -58,6 +60,12 @@ export declare function ideaDocumentProblem(data: unknown, path?: string): Docum
58
60
  * breaks its longest word across lines.
59
61
  */
60
62
  export declare function tableColumnFindings(cols: unknown, table?: TableData): Array<[BoardCheckLevel, string]>;
63
+ /**
64
+ * Findings about a stored table's `fills` and `heat`: colors that are not
65
+ * a block color name or `#rrggbb`, and rows or columns the table does not
66
+ * have (the board ignores both). `""` clears a color and is not reported.
67
+ */
68
+ export declare function tableTintFindings(fills: unknown, heat: unknown, table: TableData & Pick<TableElement, 'head'>): Array<[BoardCheckLevel, string]>;
61
69
  /**
62
70
  * Checks a board's documents (path → parsed value). Covers the meta
63
71
  * document, sync limits, element validity, drawing order, the element cap,
package/src/check.js CHANGED
@@ -10,11 +10,11 @@
10
10
  import { BOARD_CLAIM_PREFIX, BOARD_INKS_PATH, BOARD_META_PATH, BOARD_TIMER_PATH, ELEMENTS_COLLECTION, MAX_SYNC_BOARD_BYTES, composeBoard, elementIdOfPath, refuseDocument, } from "./codec.js";
11
11
  import { UNKNOWN_SVG_PART, unknownSvgParts } from "./drawn-svg/vetting.js";
12
12
  import { savedIdeaPath, VERSION_OPTION_LIMITS } from "./ideas.js";
13
- import { UPLOADED_BLOB_PATH_PATTERN, normalizeImageSource } from "./image-source.js";
13
+ import { MAX_SVG_DATA_URL_CHARS, MAX_SVG_SOURCE_CHARS, UPLOADED_BLOB_PATH_PATTERN, normalizeImageSource } from "./image-source.js";
14
14
  import { escapedJsonByteLength } from "./json.js";
15
15
  import { normalizeClaimedAreas, normalizeElement } from "./normalize.js";
16
- import { ELEMENT_ID_PATTERN, MAX_BOARD_ELEMENTS, arrowEndIds, isBoxElement } from "./schema.js";
17
- import { COLUMN_WIDTH_GUIDE, COLUMN_WIDTH_LIMITS, suggestedColumnWidth, toFiniteNumber } from "./table.js";
16
+ import { DRAWING_STYLES, ELEMENT_ID_PATTERN, MAX_BOARD_ELEMENTS, NOTE_COLORS, arrowEndIds, isBoxElement } from "./schema.js";
17
+ import { COLUMN_WIDTH_GUIDE, COLUMN_WIDTH_LIMITS, suggestedColumnWidth, tableRowIds, tableTintColor, toFiniteNumber } from "./table.js";
18
18
  /* -------------------------------------------------------------------------- */
19
19
  /* Drawings */
20
20
  /* -------------------------------------------------------------------------- */
@@ -52,9 +52,35 @@ function groupDepth(svg) {
52
52
  }
53
53
  return deepest;
54
54
  }
55
+ const countText = (count) => count.toLocaleString('en-US');
56
+ /** Findings about a drawing over {@link MAX_SVG_SOURCE_CHARS} or {@link MAX_SVG_DATA_URL_CHARS}, with how much to cut. */
57
+ function drawingSizeFindings(src, svg, base64) {
58
+ const findings = [];
59
+ if (svg.length > MAX_SVG_SOURCE_CHARS) {
60
+ findings.push([
61
+ 'error',
62
+ `The SVG is ${countText(svg.length)} characters, over the ${countText(MAX_SVG_SOURCE_CHARS)} limit: cut at least ${countText(svg.length - MAX_SVG_SOURCE_CHARS)}. The drawing shows as an empty picture.`,
63
+ ]);
64
+ }
65
+ const stored = base64 ? src.length : 'data:image/svg+xml;base64,'.length + 4 * Math.ceil(new TextEncoder().encode(svg).length / 3);
66
+ if (src.length > MAX_SVG_DATA_URL_CHARS) {
67
+ findings.push([
68
+ 'error',
69
+ `The SVG data URI is ${countText(src.length)} characters, over the ${countText(MAX_SVG_DATA_URL_CHARS)} limit: cut at least ${countText(src.length - MAX_SVG_DATA_URL_CHARS)}. The drawing shows as an empty picture.`,
70
+ ]);
71
+ }
72
+ else if (stored > MAX_SVG_DATA_URL_CHARS) {
73
+ findings.push([
74
+ 'error',
75
+ `Stored as base64 this drawing takes ${countText(stored)} characters, over the ${countText(MAX_SVG_DATA_URL_CHARS)} limit: cut its SVG by at least ${countText(Math.ceil(((stored - MAX_SVG_DATA_URL_CHARS) * 3) / 4))} characters. The drawing shows as an empty picture.`,
76
+ ]);
77
+ }
78
+ return findings;
79
+ }
55
80
  /**
56
81
  * Findings about an image's SVG drawing (`data:image/svg+xml…`): a raw `#`,
57
- * a URI that does not decode or holds no `<svg>`, and what makes the page
82
+ * a URI that does not decode or holds no `<svg>`, a drawing over the size
83
+ * limits (saying by how much), and what makes the page
58
84
  * show a grey box instead (nesting, opacity layers, parts it does not know).
59
85
  * Empty for any other source.
60
86
  */
@@ -68,9 +94,9 @@ export function drawingFindings(src) {
68
94
  const svg = drawingText(src);
69
95
  if (svg === undefined)
70
96
  return [['error', 'The SVG data URI does not decode (a lone % is written %25).']];
97
+ const findings = drawingSizeFindings(src, svg, base64);
71
98
  if (!/^\s*(?:<\?xml[^>]*\?>\s*)?<svg[\s>]/i.test(svg))
72
- return [['error', 'The SVG data URI holds no <svg> element.']];
73
- const findings = [];
99
+ return [...findings, ['error', 'The SVG data URI holds no <svg> element.']];
74
100
  const depth = groupDepth(svg);
75
101
  if (depth > MAX_DRAWING_GROUP_DEPTH) {
76
102
  findings.push(['error', `<g> groups nest ${depth} deep; with more than ${MAX_DRAWING_GROUP_DEPTH} nested <g> the page shows a grey box instead of the drawing. Flatten the groups.`]);
@@ -185,6 +211,44 @@ export function tableColumnFindings(cols, table) {
185
211
  }
186
212
  return findings;
187
213
  }
214
+ /**
215
+ * Findings about a stored table's `fills` and `heat`: colors that are not
216
+ * a block color name or `#rrggbb`, and rows or columns the table does not
217
+ * have (the board ignores both). `""` clears a color and is not reported.
218
+ */
219
+ export function tableTintFindings(fills, heat, table) {
220
+ const findings = [];
221
+ const look = (where, value, known) => {
222
+ if (!known)
223
+ findings.push(['warning', `${where} names a row or column the table does not have: the board ignores it.`]);
224
+ else if (value !== '' && tableTintColor(value) === undefined) {
225
+ findings.push(['warning', `${where} is ${JSON.stringify(value)}, not a table color (${NOTE_COLORS.join(', ')} or #rrggbb): the board ignores it.`]);
226
+ }
227
+ };
228
+ for (const [rowId, cells] of isPlainObject(fills) ? Object.entries(fills) : []) {
229
+ for (const [colId, value] of isPlainObject(cells) ? Object.entries(cells) : []) {
230
+ look(`"fills" ${rowId} / ${colId}`, value, Object.hasOwn(table.rows, rowId) && Object.hasOwn(table.cols, colId));
231
+ }
232
+ }
233
+ const heatMaps = isPlainObject(heat) ? heat : {};
234
+ const headRowId = table.head ? tableRowIds(table)[0] : undefined;
235
+ const shaded = { cols: 0, rows: 0 };
236
+ for (const axis of ['cols', 'rows']) {
237
+ const colors = heatMaps[axis];
238
+ for (const [id, value] of isPlainObject(colors) ? Object.entries(colors) : []) {
239
+ if (axis === 'rows' && id === headRowId)
240
+ findings.push(['warning', `"heat" rows ${id} is the header row, which is never shaded: the board ignores it.`]);
241
+ else
242
+ look(`"heat" ${axis} ${id}`, value, Object.hasOwn(table[axis], id));
243
+ if (value !== '')
244
+ shaded[axis] += 1;
245
+ }
246
+ }
247
+ if (shaded.cols > 0 && shaded.rows > 0) {
248
+ findings.push(['info', '"heat" shades both columns and rows; where they cross, the column\'s shade shows. Heat maps read best along one axis: keep "cols" or "rows".']);
249
+ }
250
+ return findings;
251
+ }
188
252
  /** True for paths the board reads. */
189
253
  function isKnownPath(path) {
190
254
  return (path === BOARD_META_PATH ||
@@ -257,6 +321,14 @@ export function checkBoardDocuments(documents, options = {}) {
257
321
  if (!drawing.some(([level]) => level === 'error') && normalizeImageSource(stored.src) === undefined) {
258
322
  add(path, 'error', 'The image "src" is not allowed: use an uploaded /_blob/<id> URL, an https URL, or a small data: URL. It shows as an empty drawing.');
259
323
  }
324
+ if (stored.style !== undefined) {
325
+ if (typeof stored.src !== 'string' || !stored.src.startsWith('data:image/svg+xml')) {
326
+ add(path, 'warning', 'Only SVG drawings take a "style": the board ignores it on this image.');
327
+ }
328
+ else if (!DRAWING_STYLES.includes(stored.style)) {
329
+ add(path, 'error', `"style" is ${JSON.stringify(stored.style)}; a drawing's style is one of ${DRAWING_STYLES.join(', ')}. The board draws it without one.`);
330
+ }
331
+ }
260
332
  const blob = typeof stored.src === 'string' && UPLOADED_BLOB_PATH_PATTERN.test(stored.src) ? stored.src.slice(-32) : undefined;
261
333
  if (blob && options.blobExists && !options.blobExists(blob)) {
262
334
  add(path, 'error', `/_blob/${blob} is not an upload of this board: upload the image first and use the url it prints.`);
@@ -269,9 +341,10 @@ export function checkBoardDocuments(documents, options = {}) {
269
341
  }
270
342
  if (element.id !== raw.id)
271
343
  add(path, 'warning', `The id ${raw.id} is taken: the board gives this element the id ${element.id}.`);
272
- if (element.type === 'table')
273
- for (const [level, message] of tableColumnFindings(stored?.cols, element))
344
+ if (element.type === 'table') {
345
+ for (const [level, message] of [...tableColumnFindings(stored?.cols, element), ...tableTintFindings(stored?.fills, stored?.heat, element)])
274
346
  add(path, level, message);
347
+ }
275
348
  taken.add(element.id);
276
349
  kept.push(element);
277
350
  if (!ordered.has(raw.id))
@@ -313,14 +386,21 @@ export function checkBoardDocuments(documents, options = {}) {
313
386
  if (problem)
314
387
  add(path, 'error', `${problem.message.slice(path.length + 2)} The page drops the idea.`);
315
388
  }
316
- // Agent claims.
389
+ // Agent claims: `{}` ends one; one that still frames something should end once the work is written.
317
390
  for (const [path, value] of documents) {
318
391
  if (!path.startsWith(BOARD_CLAIM_PREFIX))
319
392
  continue;
320
393
  const key = path.slice(BOARD_CLAIM_PREFIX.length);
321
394
  const [claim] = normalizeClaimedAreas([{ ...value, key }]);
322
- if (claim === undefined || Object.keys(claim).length === 1) {
323
- add(path, 'info', 'This claim marks no area and no elements: it only shows the agent is at work.');
395
+ const marks = [
396
+ claim?.x !== undefined ? 'an area' : '',
397
+ claim?.ids !== undefined ? `${claim.ids.length} element${claim.ids.length === 1 ? '' : 's'}` : '',
398
+ ].filter((mark) => mark !== '');
399
+ if (marks.length > 0) {
400
+ add(path, 'warning', `This claim still frames ${marks.join(' and ')} for everyone: once the work is written, set it to {} so the frame goes.`);
401
+ }
402
+ else if (Object.keys(value).length > 0) {
403
+ add(path, 'warning', 'The board reads no area or elements from this claim (x, y, w, h are numbers; ids are element ids): it frames nothing. Set it to {} once the work is written.');
324
404
  }
325
405
  }
326
406
  return findings;
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Drawing looks: how an agent drawing's `style` is drawn.
3
+ *
4
+ * - {@link drawingLookOf} and {@link drawingLookRenderer} pick the look and
5
+ * whether it is a rewrite of the SVG (`svg`) or painted pixels (`raster`).
6
+ * - {@link DRAWING_LOOK_TONES} holds each look's paper and ink per color
7
+ * scheme; {@link drawingLookPaper} is what text over a drawing reads on.
8
+ * - {@link sketchDrawnSvg}, {@link comicDrawnSvg} and
9
+ * {@link blueprintDrawnSvg} rewrite a parsed drawing in place.
10
+ * - {@link drawingPaintPlan} flattens a drawing into filled and stroked
11
+ * parts for the raster looks.
12
+ *
13
+ * Everything works on the core's XML tree, so it runs in Node, the page and
14
+ * workers alike.
15
+ */
16
+ import { type DrawingStyle, type ImageElement } from '../schema.ts';
17
+ import { type ColorScheme } from '../theme.ts';
18
+ import { type SvgPolyline } from './svg-geometry.ts';
19
+ import { XmlElement } from './xml.ts';
20
+ /** A look a drawing is drawn in (one of the styles). */
21
+ export type DrawingLook = DrawingStyle;
22
+ /** How a look is made: a rewrite of the SVG, or pixels painted from its shapes. */
23
+ export type DrawingLookRenderer = 'svg' | 'raster';
24
+ /** True for a known drawing style. */
25
+ export declare function isDrawingStyle(value: string): value is DrawingStyle;
26
+ /** The look for a drawing's `style`: no style or an unknown word draws plain. */
27
+ export declare function drawingLookOf(style: string | undefined): DrawingLook;
28
+ /** The look of an image element, or `undefined` when it is not an SVG drawing. */
29
+ export declare function imageDrawingLook(image: Pick<ImageElement, 'src' | 'style'>): DrawingLook | undefined;
30
+ /** Whether a look rewrites the SVG or paints pixels. */
31
+ export declare function drawingLookRenderer(look: DrawingLook): DrawingLookRenderer;
32
+ /** A look's paper (what it lays behind the drawing, if anything) and ink (`currentColor`). */
33
+ export interface DrawingLookTone {
34
+ paper: string | undefined;
35
+ ink: string;
36
+ }
37
+ /** Paper and ink of every style, per board color scheme. */
38
+ export declare const DRAWING_LOOK_TONES: Readonly<Record<DrawingStyle, Readonly<Record<ColorScheme, DrawingLookTone>>>>;
39
+ /** The paper a look lays behind a drawing in a scheme (`undefined`: the board shows through). */
40
+ export declare function drawingLookPaper(look: DrawingLook, scheme: ColorScheme): string | undefined;
41
+ /** A `#rgb[a]` / `#rrggbb[aa]` color as `#rrggbb` and its alpha; `undefined` for anything else. */
42
+ export declare function solidHex(color: string): {
43
+ hex: string;
44
+ alpha: number;
45
+ } | undefined;
46
+ /** Saturation of a hex color (0–1). */
47
+ export declare function hexSaturation(hex: string): number;
48
+ /** A hex color made flatter and bolder, as printed comic colors are. */
49
+ export declare function comicColor(hex: string): string;
50
+ /** The average color of each gradient (`id` → `#rrggbb`), so painted looks can use it as a flat color. */
51
+ export declare function gradientColors(root: XmlElement): Map<string, string>;
52
+ /** A `0 0 W H` viewBox, or `undefined`. */
53
+ export declare function drawingViewBox(root: XmlElement): [number, number] | undefined;
54
+ /** A deep copy of an element (elements and attributes only), without ids. */
55
+ export declare function cloneSvgElement(element: XmlElement): XmlElement;
56
+ /** A small seeded random generator (xorshift32 over an FNV-1a hash of the seed text). */
57
+ export declare function seededLookRandom(seedText: string): () => number;
58
+ /** Most pencil hatch lines in a drawing. */
59
+ export declare const MAX_SKETCH_HATCH_LINES = 4000;
60
+ /** How faint a filled area's own color stays under its hatching. */
61
+ export declare const SKETCH_FILL_OPACITY = 0.16;
62
+ /**
63
+ * Pencil hatching for a box `[minX, minY, maxX, maxY]`: parallel lines at
64
+ * `angle` (radians) `spacing` apart across the box, each a little crooked
65
+ * and some stopping short, as path data. `undefined` past `budget` lines.
66
+ */
67
+ export declare function pencilHatchPath(bounds: readonly [number, number, number, number], spacing: number, angle: number, budget: number, random: () => number): {
68
+ d: string;
69
+ lines: number;
70
+ } | undefined;
71
+ /**
72
+ * Rewrites a drawing as a pencil sketch (in place): graphite ink, ink lines
73
+ * brushed so they taper, wander and overshoot, with a faint second pass on
74
+ * some of them; filled areas turned to loose hatching over a faint wash of
75
+ * their color; a paper sheet behind. Elements in `skip` are left alone.
76
+ * Returns whether the drawing was rewritten (it needs a `0 0 W H` viewBox).
77
+ */
78
+ export declare function sketchDrawnSvg(root: XmlElement, scheme: ColorScheme, skip?: ReadonlySet<XmlElement>): boolean;
79
+ /** Thickness of a comic drawing's outer outline, as a share of its larger side. */
80
+ export declare const COMIC_OUTLINE_SHARE = 0.016;
81
+ /** How far a comic drawing's hard shadow falls, as a share of its larger side. */
82
+ export declare const COMIC_SHADOW_SHARE = 0.018;
83
+ /**
84
+ * The hard shadow's tone: near-black ink on a light board; on a dark board
85
+ * black would vanish, so the shadow is a lifted warm grey that still reads
86
+ * as a cast shadow under the light rims.
87
+ */
88
+ export declare const COMIC_SHADOW_TONES: Readonly<Record<ColorScheme, {
89
+ color: string;
90
+ opacity: number;
91
+ }>>;
92
+ /**
93
+ * Rewrites a drawing as a comic panel (in place): flat, bolder fills; a
94
+ * thick outline round the whole of each filled mass and thinner ink lines
95
+ * inside; a hard shadow offset under the filled shapes. Elements in `skip`
96
+ * keep their own paint. Returns whether it was rewritten.
97
+ */
98
+ export declare function comicDrawnSvg(root: XmlElement, scheme: ColorScheme, skip?: ReadonlySet<XmlElement>): boolean;
99
+ /** Saturation above which a blueprint keeps a color (what moves or flows). */
100
+ export declare const BLUEPRINT_KEEP_SATURATION = 0.45;
101
+ /**
102
+ * How a kept fill is washed on blue paper: tinted toward white and laid
103
+ * nearly opaque, since a thin wash of a warm color over blue turns olive.
104
+ */
105
+ export declare const BLUEPRINT_KEPT_WASH: {
106
+ readonly tint: 0.3;
107
+ readonly opacity: 0.85;
108
+ };
109
+ /** The fill of a section cut (`class="cut"`): a flat mid-grey, so walls cut through read as solid. */
110
+ export declare const BLUEPRINT_CUT_FILL: Readonly<Record<ColorScheme, string>>;
111
+ /**
112
+ * The parts of a drawing marked as section cuts (`class="cut"` on them or
113
+ * on a group around them). `class` is only a marker here: no CSS applies.
114
+ */
115
+ export declare function drawingCutParts(root: XmlElement): Set<XmlElement>;
116
+ /** Grid lines for a blueprint sheet `width` × `height`: minor lines and every fifth one stronger. */
117
+ export declare function blueprintGridPaths(width: number, height: number): {
118
+ minor: string;
119
+ major: string;
120
+ pitch: number;
121
+ };
122
+ /**
123
+ * Rewrites a drawing as a blueprint (in place): blue paper with a faint
124
+ * grid, pale lines at their own weights (dashes kept), fills as pale
125
+ * washes outlined in line; strongly colored parts (what is meant to stand
126
+ * out) keep their hue in a light, nearly opaque wash, and section cuts
127
+ * (`cuts`, by default the parts marked `class="cut"`) are filled solid
128
+ * mid-grey. Returns whether it was rewritten.
129
+ */
130
+ export declare function blueprintDrawnSvg(root: XmlElement, scheme: ColorScheme, skip?: ReadonlySet<XmlElement>, cuts?: ReadonlySet<XmlElement>): boolean;
131
+ /** One drawn shape as the raster looks paint it, in viewBox coordinates. */
132
+ export interface DrawingPaintPart {
133
+ /** Fill color (`#rrggbb` or `currentColor`) and alpha. */
134
+ fill: {
135
+ color: string;
136
+ alpha: number;
137
+ } | undefined;
138
+ /** Stroke color, alpha and width (viewBox units). */
139
+ stroke: {
140
+ color: string;
141
+ alpha: number;
142
+ width: number;
143
+ dashed: boolean;
144
+ round: boolean;
145
+ } | undefined;
146
+ /** Outlines (flat `x y x y …`). */
147
+ contours: SvgPolyline[];
148
+ /** The outline closes on itself (a stroke runs back to its start). */
149
+ closed: boolean;
150
+ }
151
+ /** A drawing flattened for painting. */
152
+ export interface DrawingPaintPlan {
153
+ width: number;
154
+ height: number;
155
+ parts: DrawingPaintPart[];
156
+ }
157
+ /** Most parts a painted drawing may have. */
158
+ export declare const MAX_PAINT_PARTS = 1500;
159
+ /** Most outline points a painted drawing may have. */
160
+ export declare const MAX_PAINT_POINTS = 80000;
161
+ /**
162
+ * The shapes of a drawing with their resolved paint, back to front, for the
163
+ * raster looks. `undefined` when the drawing has no `0 0 W H` viewBox or is
164
+ * too big to paint. Shapes in `skip` or that cannot be flattened are left out.
165
+ */
166
+ export declare function drawingPaintPlan(root: XmlElement, skip?: ReadonlySet<XmlElement>): DrawingPaintPlan | undefined;