@widgetic/canvas 0.5.46 → 0.5.48

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 (47) hide show
  1. package/README.md +4 -1
  2. package/dist/canvas/DomCanvas.svelte +5 -3
  3. package/dist/canvas/DomCanvas.svelte.d.ts +1 -0
  4. package/dist/canvas/eventScope.js +7 -1
  5. package/dist/canvas/host/CanvasHost.d.ts +5 -3
  6. package/dist/canvas/host/CanvasHost.js +114 -74
  7. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  8. package/dist/canvas/host/pauseCollector.js +45 -0
  9. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  10. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  11. package/dist/canvas/ui/CanvasToolbar.svelte +17 -14
  12. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  13. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  14. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  15. package/dist/canvas/ui/ToolButton.svelte +7 -6
  16. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  17. package/dist/canvas/ui/floatingCard.js +28 -8
  18. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  19. package/dist/canvas/ui/selectionTraits.js +10 -18
  20. package/dist/canvas/view/SelectionOverlay.svelte +5 -5
  21. package/dist/canvas/view/WidgetChromeLayer.svelte +10 -2
  22. package/dist/canvas/view/geometry.d.ts +1 -1
  23. package/dist/canvas/view/geometry.js +1 -1
  24. package/dist/components/input-controls/ColorIC.svelte +1 -1
  25. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  26. package/dist/engine/EngineCore.d.ts +33 -8
  27. package/dist/engine/EngineCore.js +66 -30
  28. package/dist/engine/core/brush.d.ts +24 -0
  29. package/dist/engine/core/brush.js +145 -13
  30. package/dist/engine/core/shapeTools.d.ts +23 -18
  31. package/dist/engine/core/shapeTools.js +45 -17
  32. package/dist/engine/core/style.d.ts +18 -2
  33. package/dist/engine/core/style.js +57 -25
  34. package/dist/engine/core/styleMemory.d.ts +88 -0
  35. package/dist/engine/core/styleMemory.js +189 -0
  36. package/dist/engine/input/gestures.d.ts +8 -3
  37. package/dist/engine/input/gestures.js +123 -48
  38. package/dist/engine/input/keyboard.js +14 -5
  39. package/dist/poster/boardPlacement.d.ts +4 -1
  40. package/dist/poster/boardPlacement.js +6 -3
  41. package/dist/settings/rememberedStyles.d.ts +22 -0
  42. package/dist/settings/rememberedStyles.js +47 -0
  43. package/dist/settings/rememberedTool.js +2 -1
  44. package/dist/settings/workspaceToolSettings.d.ts +17 -0
  45. package/dist/settings/workspaceToolSettings.js +4 -1
  46. package/dist/tools/hostAdapter.js +0 -1
  47. package/package.json +4 -4
@@ -7,7 +7,7 @@
7
7
  import { arrowPointsInWorld, bendTowards, isArrow, reshapeArrow } from '../core/arrow.js';
8
8
  import { pickArrowBinding, positionBoundArrow } from '../core/arrowBinding.js';
9
9
  import { bindingOfEnd, releaseUnmovedEnds } from '../core/arrowBindingRecords.js';
10
- import { buildBrushStroke } from '../core/brush.js';
10
+ import { STRAIGHT_LINE_PRESSURE, buildBrushStroke } from '../core/brush.js';
11
11
  import { ARROW_SNAP_DEGREES, MIN_DRAW_DISTANCE, buildDraggedShape, snapPointAround } from '../core/shapeTools.js';
12
12
  import { distanceBetween, inflateRect, rectContainsPoint, rectFromPoints, rectsIntersect, unionRects } from '../core/geometry.js';
13
13
  import { hitTestLeaf } from '../core/hitTest.js';
@@ -504,18 +504,18 @@ export function createPanGesture(context, start, options = {}) {
504
504
  // ──────────────────────────────────────────────────────────── ink
505
505
  /** A pen whose pressure never moves by more than this has none to report, and draws as a mouse does. */
506
506
  const PEN_PRESSURE_SPREAD = 0.02;
507
- /**
508
- * The pressure a straight line (Shift) is drawn at when the device reports none (a mouse, a finger): the one a stroke drawn by
509
- * hand settles at as soon as the hand moves at an ordinary pace. The straight line is then as thick as the lines drawn by hand
510
- * beside it (a width of 3 is about 3 px on the screen, and not the 6.6 px of a pen pressing at its middle), and as thick at one
511
- * end as at the other.
512
- */
513
- const STRAIGHT_LINE_PRESSURE = 0;
507
+ // A point of the line closer than this many screen pixels to the one before it adds nothing the eye can see.
508
+ const MIN_SAMPLE_DISTANCE = 1;
514
509
  /**
515
510
  * Draws with the brush. The line is as thick as the hand presses: a pen's own pressure, or, for a mouse or a finger, the time the
516
- * hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down to the pointer,
517
- * with the colour and the thickness of the lines drawn without Shift: the brush is the same, held at one pressure. The colour, the
518
- * width and the opacity of the line are the pen's (`EngineState.penStyle`), which the settings panel sets before a line is drawn.
511
+ * hand spends (a slow stroke swells, a quick one thins). The colour, the width and the opacity of the line are the pen's
512
+ * (`EngineState.penStyle`), which the settings panel sets before a line is drawn.
513
+ *
514
+ * Shift holds the line straight for as long as it is down. The straight stretch begins where the pointer is when the key goes down
515
+ * (what the hand has drawn up to there stays as it is) and runs to the pointer, with the colour and the thickness of the line
516
+ * drawn without Shift: the brush is the same, held at one pressure. When Shift is let go the stretch is kept up to where the
517
+ * pointer was, and the hand goes on drawing from there as before; Shift down again starts another stretch. With Shift down as the
518
+ * press begins the whole line is straight from the point of the press.
519
519
  */
520
520
  export function createDrawGesture(context, start) {
521
521
  const { engine } = context;
@@ -524,23 +524,36 @@ export function createDrawGesture(context, start) {
524
524
  // How the line is drawn (its colour, its width, how much of the board shows through it) is the pen as it was set when the press
525
525
  // began: a line already being drawn is not changed by a panel that is touched meanwhile.
526
526
  const { color, width: strokeWidth, opacity } = engine.state.penStyle;
527
+ // The points of the line: where the hand went, and the two ends of every stretch that was held straight.
527
528
  const samples = [];
529
+ // The stretches held straight, as the indexes of the samples they run between and the pressure each is drawn at.
530
+ const straightStretches = [];
528
531
  let leastPressure = Infinity;
529
532
  let mostPressure = -Infinity;
530
- // What a pen has reported so far, to find the pressure a straight line is held at.
531
- let pressureTotal = 0;
532
- let pressureCount = 0;
533
- let straight = start.shiftKey;
533
+ // What a pen has reported since the stretch that is open began, to find the pressure that stretch is held at.
534
+ let stretchPressureTotal = 0;
535
+ let stretchPressureCount = 0;
536
+ // The stretch Shift is holding open: the index of the sample it began at, where that sample is on the screen, and where the
537
+ // pointer is now (in the world, and on the screen). Null while Shift is up.
538
+ let openStretchStart = null;
539
+ let openStretchAnchorScreen = { x: start.x, y: start.y };
540
+ let openStretchEnd = null;
541
+ let openStretchEndScreen = { x: start.x, y: start.y };
534
542
  let lastScreen = { x: start.x, y: start.y };
535
- let lastInput = start;
543
+ // Only a pen's pressure means anything: a mouse and a finger report one fixed value while they are down.
544
+ const reportsPressure = (input) => isPen && typeof input.pressure === 'number';
545
+ const notePressure = (input) => {
546
+ leastPressure = Math.min(leastPressure, input.pressure);
547
+ mostPressure = Math.max(mostPressure, input.pressure);
548
+ if (openStretchStart !== null) {
549
+ stretchPressureTotal += input.pressure;
550
+ stretchPressureCount += 1;
551
+ }
552
+ };
536
553
  const takeSample = (input) => {
537
554
  const world = worldOf(context, input);
538
- // Only a pen's pressure means anything: a mouse and a finger report one fixed value while they are down.
539
- if (isPen && typeof input.pressure === 'number') {
540
- leastPressure = Math.min(leastPressure, input.pressure);
541
- mostPressure = Math.max(mostPressure, input.pressure);
542
- pressureTotal += input.pressure;
543
- pressureCount += 1;
555
+ if (reportsPressure(input)) {
556
+ notePressure(input);
544
557
  samples.push({ ...world, pressure: input.pressure });
545
558
  }
546
559
  else {
@@ -549,19 +562,63 @@ export function createDrawGesture(context, start) {
549
562
  };
550
563
  takeSample(start);
551
564
  const readsPressure = () => isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD;
552
- const isStraight = () => straight && samples.length > 1;
553
- /** The line the hand drew: the samples, or just their two ends when Shift holds it straight. */
554
- const lineDrawn = () => (isStraight() ? [samples[0], samples[samples.length - 1]] : samples);
565
+ /** The pressure a straight stretch is held at: the pen's own average while the stretch was drawn, or the mouse's usual one. */
566
+ const stretchPressure = () => (readsPressure() && stretchPressureCount > 0 ? stretchPressureTotal / stretchPressureCount : STRAIGHT_LINE_PRESSURE);
567
+ /** How far the open stretch reaches, in pixels of the screen: one with no length draws nothing and is not kept. */
568
+ const openStretchReach = () => Math.hypot(openStretchEndScreen.x - openStretchAnchorScreen.x, openStretchEndScreen.y - openStretchAnchorScreen.y);
569
+ /** Shift goes down: a straight stretch begins where the hand is, at the last point of the line, and follows the pointer from there. */
570
+ const openStretch = () => {
571
+ if (openStretchStart !== null)
572
+ return;
573
+ openStretchStart = samples.length - 1;
574
+ openStretchAnchorScreen = lastScreen;
575
+ openStretchEnd = null;
576
+ openStretchEndScreen = lastScreen;
577
+ // The pen's pressure at the point the stretch begins is the first of the ones it is averaged from.
578
+ const anchorPressure = samples[openStretchStart].pressure;
579
+ stretchPressureTotal = typeof anchorPressure === 'number' ? anchorPressure : 0;
580
+ stretchPressureCount = typeof anchorPressure === 'number' ? 1 : 0;
581
+ };
582
+ /** The open stretch ends at the pointer: from there the hand goes on, and the line keeps the stretch as it was drawn. */
583
+ const closeStretch = () => {
584
+ if (openStretchStart === null)
585
+ return;
586
+ const from = openStretchStart;
587
+ const end = openStretchEnd;
588
+ const reach = openStretchReach();
589
+ const pressure = stretchPressure();
590
+ const endScreen = openStretchEndScreen;
591
+ openStretchStart = null;
592
+ openStretchEnd = null;
593
+ if (!end || reach < MIN_SAMPLE_DISTANCE)
594
+ return;
595
+ samples.push(end);
596
+ straightStretches.push({ from, to: samples.length - 1, pressure });
597
+ lastScreen = endScreen;
598
+ };
599
+ /** The open stretch follows the pointer. Only the position is taken here: the pen's pressure is noted event by event. */
600
+ const followPointer = (input, pressure) => {
601
+ const world = worldOf(context, input);
602
+ openStretchEnd = typeof pressure === 'number' ? { ...world, pressure } : world;
603
+ openStretchEndScreen = { x: input.x, y: input.y };
604
+ };
605
+ if (start.shiftKey)
606
+ openStretch();
607
+ /** The line as it is now: the samples and the stretches, the open one drawn all the way to the pointer. */
608
+ const lineNow = () => {
609
+ if (openStretchStart === null || !openStretchEnd || openStretchReach() < MIN_SAMPLE_DISTANCE)
610
+ return { points: samples, stretches: straightStretches };
611
+ const points = [...samples, openStretchEnd];
612
+ return { points, stretches: [...straightStretches, { from: openStretchStart, to: points.length - 1, pressure: stretchPressure() }] };
613
+ };
555
614
  const build = (finished) => {
556
615
  // The brush of the lines beside it: a pen that reports its pressure draws with the pen's brush, anything else with the mouse's.
557
616
  const brushKind = readsPressure() ? 'pen' : 'speed';
558
617
  const look = { createId: () => strokeId, color, strokeWidth, opacity, pressure: brushKind, finished };
559
- if (!isStraight())
560
- return buildBrushStroke(samples, look);
561
- // A straight line has two ends and an even width: one pressure all along (the pen's own average, or the mouse's usual one), and
562
- // it is drawn all the way to the pointer, not trailing behind it as a hand-drawn line does while it is being drawn.
563
- const steadyPressure = brushKind === 'pen' && pressureCount > 0 ? pressureTotal / pressureCount : STRAIGHT_LINE_PRESSURE;
564
- return buildBrushStroke(lineDrawn(), { ...look, steadyPressure });
618
+ // A straight stretch has two ends and an even width (the pen's own average, or the mouse's usual pressure), and it is drawn all
619
+ // the way to the pointer, not trailing behind it as a hand-drawn line does while it is being drawn.
620
+ const { points, stretches } = lineNow();
621
+ return buildBrushStroke(points, { ...look, straightSpans: stretches });
565
622
  };
566
623
  const showPreview = () => engine.setOverlay({ preview: build(false) });
567
624
  showPreview();
@@ -569,37 +626,54 @@ export function createDrawGesture(context, start) {
569
626
  kind: 'draw',
570
627
  pointerId: start.pointerId,
571
628
  move(input) {
572
- lastInput = input;
573
- straight = input.shiftKey;
574
629
  const moved = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
575
- for (const sample of moved) {
576
- // A new sample closer than a pixel to the last one adds nothing the eye can see.
577
- if (Math.hypot(sample.x - lastScreen.x, sample.y - lastScreen.y) < 1)
578
- continue;
579
- takeSample(sample);
580
- lastScreen = { x: sample.x, y: sample.y };
630
+ if (input.shiftKey) {
631
+ // Shift is down (its key may not have been seen, or comes with this very move): the stretch begins where the line ended
632
+ // at the last move, and follows the pointer. The line takes no points while it is held: the stretch has only two ends.
633
+ openStretch();
634
+ for (const event of moved)
635
+ if (reportsPressure(event))
636
+ notePressure(event);
637
+ followPointer(input, reportsPressure(input) ? input.pressure : undefined);
638
+ }
639
+ else {
640
+ // Shift is up: a stretch that was open ends where the pointer was, and the hand goes on from there.
641
+ closeStretch();
642
+ for (const sample of moved) {
643
+ // A new sample closer than a pixel to the last one adds nothing the eye can see.
644
+ if (Math.hypot(sample.x - lastScreen.x, sample.y - lastScreen.y) < MIN_SAMPLE_DISTANCE)
645
+ continue;
646
+ takeSample(sample);
647
+ lastScreen = { x: sample.x, y: sample.y };
648
+ }
581
649
  }
582
650
  showPreview();
583
651
  },
584
652
  end(input) {
585
- straight = input.shiftKey;
586
- // A straight line ends where the pointer was let go, even when that is a little beyond the last move (a fast flick). Only the
587
- // position is taken: a pen reports no pressure once it is lifted, and the line holds one pressure anyway.
588
- if (isStraight() && Math.hypot(input.x - lastScreen.x, input.y - lastScreen.y) >= 1)
589
- takeSample({ x: input.x, y: input.y });
653
+ if (input.shiftKey) {
654
+ // A straight stretch ends where the pointer was let go, even when that is a little beyond the last move (a fast flick).
655
+ // Only the position is taken: a pen reports no pressure once it is lifted, and the stretch holds one pressure anyway.
656
+ openStretch();
657
+ followPointer(input);
658
+ }
659
+ closeStretch();
590
660
  const stroke = build(true);
661
+ const { points } = lineNow();
591
662
  engine.clearOverlay();
592
663
  if (!stroke)
593
664
  return;
594
665
  engine.addObjects([stroke]);
595
- context.options.onStrokeFinished?.(stroke, lineDrawn());
666
+ context.options.onStrokeFinished?.(stroke, points);
596
667
  },
597
668
  cancel() {
598
669
  engine.clearOverlay();
599
670
  },
600
671
  modifiersChanged(modifiers) {
601
- straight = modifiers.shiftKey;
602
- lastInput = { ...lastInput, ...modifiers };
672
+ // Shift goes down: a straight stretch begins at the pointer. Shift goes up: the stretch ends there, and the hand goes on.
673
+ if (modifiers.shiftKey)
674
+ openStretch();
675
+ else
676
+ closeStretch();
603
677
  showPreview();
604
678
  }
605
679
  };
@@ -639,7 +713,8 @@ export function createShapeGesture(context, start, kind, libraryKey) {
639
713
  wireframe: engine.wireframeMode,
640
714
  createId: () => id,
641
715
  random: () => colorSeed,
642
- workspacePaint: engine.workspacePaintForNewShape(engine.wireframeMode)
716
+ // What the person last chose for this kind of shape (the preview and the shape kept are made with the same).
717
+ rememberedStyles: engine.rememberedStyles
643
718
  });
644
719
  if (kind !== 'arrow' || !dragged || input.altKey || shape.type !== 'path' || !isArrow(shape))
645
720
  return { shape, hint: null };
@@ -56,8 +56,8 @@ export const TOOL_DIGITS = Object.freeze({
56
56
  '4': 'arrow',
57
57
  '5': 'text'
58
58
  });
59
- /** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
60
- const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
59
+ /** Sketch tools of the drawing bar: hidden (and so are their letters) when the host turns `showDrawingTools` off. Select stays. */
60
+ const DRAWING_TOOLS = new Set(['erase', 'draw', 'arrow', 'text']);
61
61
  const ARROW_STEPS = Object.freeze({
62
62
  ArrowUp: [0, -1],
63
63
  ArrowDown: [0, 1],
@@ -113,9 +113,14 @@ function handleEscape(host) {
113
113
  if (controller.cancelGesture())
114
114
  return true;
115
115
  if (engine.state.editingTextId) {
116
- engine.endTextEdit();
116
+ // Escape says "done writing": the text that was typed stays on the board and stays selected, so that what comes next (a colour,
117
+ // a size, a move) is for it; the next Escape lets go of it. A text that ended empty is not kept, so there is nothing to select.
118
+ const keptTextId = engine.endTextEdit();
117
119
  engine.setTool('select');
118
- engine.clearSelection();
120
+ if (keptTextId === null)
121
+ engine.clearSelection();
122
+ else if (!engine.state.selectedIds.includes(keptTextId))
123
+ engine.select([keptTextId]);
119
124
  return true;
120
125
  }
121
126
  // A field of the page that is not ours keeps its Escape.
@@ -261,7 +266,11 @@ function handleLayerKey(input, host) {
261
266
  }
262
267
  /** Whether the host lets the person use a tool (and so answers its letter). */
263
268
  export function toolIsAvailable(tool, tools) {
264
- return DRAWING_TOOLS.has(tool) ? tools.drawing : true;
269
+ if (tool === 'select' || tool === 'pan')
270
+ return true;
271
+ if (DRAWING_TOOLS.has(tool) || SHAPE_SHORTCUTS.has(tool) || tool === 'image')
272
+ return tools.drawing;
273
+ return true;
265
274
  }
266
275
  /**
267
276
  * A key was pressed. Returns whether the board used it: the shell then calls `preventDefault()` so the browser
@@ -15,7 +15,7 @@
15
15
  * placement is only used in the layout it was measured in. One that is missing, damaged or from another layout is nothing: the
16
16
  * page draws its empty board as before and the creator draws the rest when it arrives.
17
17
  *
18
- * It holds nothing private: pixel distances and the toolbar's place.
18
+ * It holds nothing private: pixel distances, the toolbar's place, and the workspace key the canvas already keeps its own choices under.
19
19
  */
20
20
  /** Where the placement is kept. The page and the creator are separate programs on one origin, so they meet here. */
21
21
  export declare const BOARD_PLACEMENT_STORAGE_KEY = "widgetic.canvas.boardPlacement";
@@ -42,6 +42,8 @@ export interface BoardPlacement {
42
42
  toolbarPosition: string | null;
43
43
  /** Whether the board shows the drawing tools (the toolbar placeholder draws nothing without them). */
44
44
  showDrawingTools: boolean;
45
+ /** The workspace the canvas keeps its choices under (the tool that is on when the board opens), or null. */
46
+ workspaceId: string | null;
45
47
  }
46
48
  /** The part of a DOM rectangle this file reads. */
47
49
  export interface PlacementRect {
@@ -56,6 +58,7 @@ export interface BoardPlacementDetails {
56
58
  viewportWidth: number;
57
59
  toolbarPosition?: string | null;
58
60
  showDrawingTools?: boolean;
61
+ workspaceId?: string | null;
59
62
  }
60
63
  /** The part of `Storage` this file uses (a test hands in a map). */
61
64
  export interface PlacementStorage {
@@ -15,7 +15,7 @@
15
15
  * placement is only used in the layout it was measured in. One that is missing, damaged or from another layout is nothing: the
16
16
  * page draws its empty board as before and the creator draws the rest when it arrives.
17
17
  *
18
- * It holds nothing private: pixel distances and the toolbar's place.
18
+ * It holds nothing private: pixel distances, the toolbar's place, and the workspace key the canvas already keeps its own choices under.
19
19
  */
20
20
  /** Where the placement is kept. The page and the creator are separate programs on one origin, so they meet here. */
21
21
  export const BOARD_PLACEMENT_STORAGE_KEY = 'widgetic.canvas.boardPlacement';
@@ -62,7 +62,8 @@ export function measureBoardPlacement(host, board, details) {
62
62
  bottom,
63
63
  left,
64
64
  toolbarPosition: typeof details.toolbarPosition === 'string' && details.toolbarPosition.length <= 8 ? details.toolbarPosition : null,
65
- showDrawingTools: details.showDrawingTools !== false
65
+ showDrawingTools: details.showDrawingTools !== false,
66
+ workspaceId: typeof details.workspaceId === 'string' && details.workspaceId.length <= 200 ? details.workspaceId : null
66
67
  };
67
68
  }
68
69
  function defaultStorage() {
@@ -117,6 +118,7 @@ export function recallBoardPlacement(viewportWidth, storage = defaultStorage())
117
118
  if (typeof record.showDrawingTools !== 'boolean')
118
119
  return null;
119
120
  const toolbarPosition = typeof record.toolbarPosition === 'string' && record.toolbarPosition.length <= 8 ? record.toolbarPosition : null;
121
+ const workspaceId = typeof record.workspaceId === 'string' && record.workspaceId.length <= 200 ? record.workspaceId : null;
120
122
  return {
121
123
  version: BOARD_PLACEMENT_VERSION,
122
124
  layout: record.layout,
@@ -125,7 +127,8 @@ export function recallBoardPlacement(viewportWidth, storage = defaultStorage())
125
127
  bottom: record.bottom,
126
128
  left: record.left,
127
129
  toolbarPosition,
128
- showDrawingTools: record.showDrawingTools
130
+ showDrawingTools: record.showDrawingTools,
131
+ workspaceId
129
132
  };
130
133
  }
131
134
  catch {
@@ -0,0 +1,22 @@
1
+ /**
2
+ * How what the person last chose for each kind of element (`engine/core/styleMemory.ts`) is kept for a workspace, and read back.
3
+ *
4
+ * The storage (`workspaceToolSettings.ts`) has a part for each kind: `paint` for the shapes that have an inside, `icon` for the line-only
5
+ * icons of the library, `arrow` and `text`; the pen of the Draw tool has its own part (`pen`), kept by the host from `EngineState.penStyle`.
6
+ * Nothing here touches the storage or the engine: these are the two translations between what the engine remembers and what is stored.
7
+ */
8
+ import type { PatchedStyleKind, RememberedStyles } from '../engine/core/styleMemory.js';
9
+ import type { WorkspaceToolSettingsV1 } from './workspaceToolSettings.js';
10
+ /**
11
+ * The parts of the stored settings that say what the engine remembers for the kinds that changed, to be laid over what is stored (a part
12
+ * keeps the keys the patch does not say, so a kind that did not change is not named and stays as it is). A kind that holds nothing yet is
13
+ * not named either: nothing is written for an element the person never styled.
14
+ */
15
+ export declare function settingsOfRememberedStyles(styles: RememberedStyles, kinds: readonly PatchedStyleKind[]): Partial<WorkspaceToolSettingsV1>;
16
+ /**
17
+ * What the stored settings hold for each kind, to be given to the engine (`EngineCore.setRememberedStyles`, which checks every key).
18
+ * No settings, or settings that never held a part: nothing for that kind.
19
+ */
20
+ export declare function rememberedStylesOfSettings(settings: WorkspaceToolSettingsV1 | null): {
21
+ readonly [kind in PatchedStyleKind]: unknown;
22
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How what the person last chose for each kind of element (`engine/core/styleMemory.ts`) is kept for a workspace, and read back.
3
+ *
4
+ * The storage (`workspaceToolSettings.ts`) has a part for each kind: `paint` for the shapes that have an inside, `icon` for the line-only
5
+ * icons of the library, `arrow` and `text`; the pen of the Draw tool has its own part (`pen`), kept by the host from `EngineState.penStyle`.
6
+ * Nothing here touches the storage or the engine: these are the two translations between what the engine remembers and what is stored.
7
+ */
8
+ /**
9
+ * The parts of the stored settings that say what the engine remembers for the kinds that changed, to be laid over what is stored (a part
10
+ * keeps the keys the patch does not say, so a kind that did not change is not named and stays as it is). A kind that holds nothing yet is
11
+ * not named either: nothing is written for an element the person never styled.
12
+ */
13
+ export function settingsOfRememberedStyles(styles, kinds) {
14
+ const settings = {};
15
+ for (const kind of kinds) {
16
+ const remembered = styles[kind];
17
+ if (Object.keys(remembered).length === 0)
18
+ continue;
19
+ switch (kind) {
20
+ case 'shape':
21
+ settings.paint = { ...remembered };
22
+ break;
23
+ case 'lineIcon':
24
+ settings.icon = { ...remembered };
25
+ break;
26
+ case 'arrow':
27
+ settings.arrow = { ...remembered };
28
+ break;
29
+ case 'text':
30
+ settings.text = { ...remembered };
31
+ break;
32
+ }
33
+ }
34
+ return settings;
35
+ }
36
+ /**
37
+ * What the stored settings hold for each kind, to be given to the engine (`EngineCore.setRememberedStyles`, which checks every key).
38
+ * No settings, or settings that never held a part: nothing for that kind.
39
+ */
40
+ export function rememberedStylesOfSettings(settings) {
41
+ return {
42
+ shape: settings?.paint,
43
+ lineIcon: settings?.icon,
44
+ arrow: settings?.arrow,
45
+ text: settings?.text
46
+ };
47
+ }
@@ -42,8 +42,9 @@ export function toolTheBoardOpensWith(options) {
42
42
  const { rememberedToolId, showDrawingTools } = options;
43
43
  if (!isRememberedTool(rememberedToolId))
44
44
  return defaultFirstTool(showDrawingTools);
45
- if (!showDrawingTools && isDrawingGroupTool(rememberedToolId))
45
+ if (!showDrawingTools && (isDrawingGroupTool(rememberedToolId) || SHAPE_TOOL_IDS.includes(rememberedToolId))) {
46
46
  return defaultFirstTool(showDrawingTools);
47
+ }
47
48
  return rememberedToolId;
48
49
  }
49
50
  /** The tool kept for this workspace and person, or null (nothing kept, no workspace to keep it for, a store that refuses, or a value that is no tool). */
@@ -7,6 +7,12 @@ export interface SettingsStorageAdapter {
7
7
  load(key: string): string | null;
8
8
  save(key: string, value: string): void;
9
9
  }
10
+ /**
11
+ * What the person last chose for each kind of element, so the next element of the kind starts with it (see `engine/core/styleMemory.ts`,
12
+ * which says what each kind is and what is kept of it). `text`, `paint` (the shapes with an inside), `icon` (the line-only icons of the
13
+ * library: a check, a cross, a plus, a minus) and `arrow` hold keys of the settings panel, each only the ones its kind remembers.
14
+ * Values are checked key by key when they are read, so an entry from an older version, or one that was damaged, gives what it can.
15
+ */
10
16
  export interface WorkspaceToolSettingsV1 {
11
17
  v: typeof WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION;
12
18
  text?: {
@@ -17,6 +23,7 @@ export interface WorkspaceToolSettingsV1 {
17
23
  color?: string;
18
24
  align?: 'left' | 'center' | 'right';
19
25
  underline?: boolean;
26
+ opacity?: number;
20
27
  };
21
28
  paint?: {
22
29
  fill?: string;
@@ -26,9 +33,19 @@ export interface WorkspaceToolSettingsV1 {
26
33
  opacity?: number;
27
34
  roundness?: number;
28
35
  };
36
+ /** The line-only icons of the library: the colour of the line, its width and opacity, how round its ends are. Left out until the person styles one. */
37
+ icon?: {
38
+ stroke?: string;
39
+ strokeWidth?: number;
40
+ strokeStyle?: 'solid' | 'dashed' | 'dotted';
41
+ opacity?: number;
42
+ roundness?: number;
43
+ };
29
44
  arrow?: {
30
45
  stroke?: string;
31
46
  strokeWidth?: number;
47
+ strokeStyle?: 'solid' | 'dashed' | 'dotted';
48
+ opacity?: number;
32
49
  headStart?: boolean;
33
50
  headEnd?: boolean;
34
51
  };
@@ -45,7 +45,7 @@ export function parseWorkspaceToolSettings(raw) {
45
45
  export function loadWorkspaceToolSettings(scope, adapter = adapterFromPreferenceStorage()) {
46
46
  return parseWorkspaceToolSettings(adapter.load(storageKey(scope)));
47
47
  }
48
- /** The settings with a patch laid over them: each part (text, paint, arrow, pen, tool) keeps what the patch does not say. */
48
+ /** The settings with a patch laid over them: each part (text, paint, icon, arrow, pen, tool) keeps what the patch does not say. */
49
49
  function mergeSettings(current, patch) {
50
50
  const merged = {
51
51
  v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION,
@@ -53,6 +53,9 @@ function mergeSettings(current, patch) {
53
53
  paint: { ...current.paint, ...patch.paint },
54
54
  arrow: { ...current.arrow, ...patch.arrow }
55
55
  };
56
+ // The line-only icons are written only when the person styled one: settings of a person who never did hold none.
57
+ if (current.icon || patch.icon)
58
+ merged.icon = { ...current.icon, ...patch.icon };
56
59
  // The pen is written only when there is one: settings of a person who never touched it hold none.
57
60
  if (current.pen || patch.pen)
58
61
  merged.pen = { ...current.pen, ...patch.pen };
@@ -26,7 +26,6 @@ export function createCanvasToolHostFromEngine(options) {
26
26
  /** Run several tool calls as a single undo step on the engine. */
27
27
  export function runCanvasToolBatch(host, run, engine) {
28
28
  // When backed by engine, defer commit until batch ends.
29
- const engineHost = host;
30
29
  if (engine) {
31
30
  const snapshot = engine.state.scene;
32
31
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/canvas",
3
- "version": "0.5.46",
3
+ "version": "0.5.48",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -56,7 +56,7 @@
56
56
  "dev": "concurrently -n app,pkg -c blue,green \"npm run dev-sv -- --port 5181\" \"npm run package:watch\"",
57
57
  "dev-sv": "NODE_ENV=development vite dev",
58
58
  "build": "vite build && npm run package",
59
- "package": "NODE_ENV=production svelte-package",
59
+ "package": "svelte-kit sync && NODE_ENV=production svelte-package",
60
60
  "publish-to-npm": "node ../dev-tools/bin/publish-package.mjs",
61
61
  "package:watch": "NODE_ENV=development svelte-package --watch",
62
62
  "test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\" \"tests/engine/*.test.mjs\" \"tests/host/*.test.mjs\" \"tests/settings/*.test.mjs\" \"tests/view/*.test.mjs\" \"tests/ui/*.test.mjs\" \"tests/tools/*.test.mjs\"",
@@ -99,7 +99,7 @@
99
99
  "@tiptap/extension-underline": "^2.9.1",
100
100
  "@tiptap/pm": "^2.9.1",
101
101
  "@tiptap/starter-kit": "^2.9.1",
102
- "@widgetic/design-system": "^0.5.36",
102
+ "@widgetic/design-system": "^0.5.42",
103
103
  "@widgetic/dev-tools": "^0.3.0",
104
104
  "eslint": "^9.18.0",
105
105
  "eslint-config-prettier": "^10.0.1",
@@ -143,7 +143,7 @@
143
143
  "url": "https://gitlab.com/widgeticai/Frontend/canvas.git"
144
144
  },
145
145
  "peerDependencies": {
146
- "@widgetic/design-system": ">=0.5.36",
146
+ "@widgetic/design-system": ">=0.5.41",
147
147
  "svelte": "^5.0.0"
148
148
  }
149
149
  }