@widgetic/canvas 0.5.46 → 0.5.47

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 (42) hide show
  1. package/README.md +2 -1
  2. package/dist/canvas/DomCanvas.svelte +1 -2
  3. package/dist/canvas/host/CanvasHost.d.ts +0 -3
  4. package/dist/canvas/host/CanvasHost.js +102 -67
  5. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  6. package/dist/canvas/host/pauseCollector.js +45 -0
  7. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  8. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  9. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  10. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  11. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  12. package/dist/canvas/ui/ToolButton.svelte +7 -6
  13. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  14. package/dist/canvas/ui/floatingCard.js +28 -8
  15. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  16. package/dist/canvas/ui/selectionTraits.js +10 -18
  17. package/dist/canvas/view/SelectionOverlay.svelte +2 -2
  18. package/dist/canvas/view/geometry.d.ts +1 -1
  19. package/dist/canvas/view/geometry.js +1 -1
  20. package/dist/components/input-controls/ColorIC.svelte +1 -1
  21. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  22. package/dist/engine/EngineCore.d.ts +33 -8
  23. package/dist/engine/EngineCore.js +66 -30
  24. package/dist/engine/core/brush.d.ts +24 -0
  25. package/dist/engine/core/brush.js +145 -13
  26. package/dist/engine/core/shapeTools.d.ts +23 -18
  27. package/dist/engine/core/shapeTools.js +45 -17
  28. package/dist/engine/core/style.d.ts +18 -2
  29. package/dist/engine/core/style.js +57 -25
  30. package/dist/engine/core/styleMemory.d.ts +88 -0
  31. package/dist/engine/core/styleMemory.js +189 -0
  32. package/dist/engine/input/gestures.d.ts +8 -3
  33. package/dist/engine/input/gestures.js +123 -48
  34. package/dist/engine/input/keyboard.js +7 -2
  35. package/dist/poster/boardPlacement.d.ts +4 -1
  36. package/dist/poster/boardPlacement.js +6 -3
  37. package/dist/settings/rememberedStyles.d.ts +22 -0
  38. package/dist/settings/rememberedStyles.js +47 -0
  39. package/dist/settings/workspaceToolSettings.d.ts +17 -0
  40. package/dist/settings/workspaceToolSettings.js +4 -1
  41. package/dist/tools/hostAdapter.js +0 -1
  42. package/package.json +4 -4
package/README.md CHANGED
@@ -173,7 +173,8 @@ The saved canvas is a versioned document (`CANVAS_DOCUMENT_VERSION = 2`): a flat
173
173
  empty with a notice and is left as it is until something new is added.
174
174
 
175
175
  **The pencil is a brush.** A stroke is thicker where the hand slows down (a pen's own pressure draws it when the device reports
176
- one), a click is a round dot, **Shift** draws a straight line, and a resize makes a stroke longer, never fatter. A board saves
176
+ one), a click is a round dot, **Shift** held while drawing makes a straight line from where the pointer was when it went down (let
177
+ go, the line is kept and the stroke goes on by hand), and a resize makes a stroke longer, never fatter. A board saves
177
178
  each stroke as its line and its pressures (`ink`) and draws the outline again when it is read.
178
179
 
179
180
  **An arrow is two points and a bend.** Its open head keeps its size when the arrow is stretched, a selected arrow has a handle
@@ -78,7 +78,7 @@
78
78
  // selector's indicator is a card of its own at the top.)
79
79
  export let toolbarPosition: ToolbarPosition = DEFAULT_TOOLBAR_POSITION;
80
80
 
81
- // Wireframe mode: hides the colour fields of the selection panel and keeps new objects white with a dark stroke
81
+ // Wireframe mode: new objects start white with a dark stroke (the colour fields of the selection panel are there in either look)
82
82
  export let wireframeMode: CanvasHostProps['wireframeMode'] = DEFAULT_HOST_PROPS.wireframeMode;
83
83
 
84
84
  // The advanced chrome of a widget card: with it on a card can be turned, and the primary widget has its ring. With it off
@@ -529,7 +529,6 @@
529
529
  {host}
530
530
  state={engineState}
531
531
  ui={uiState}
532
- {wireframeMode}
533
532
  canCapture={!!onObjectClick}
534
533
  canConvert={!!(onWidgetRename || onRefreshScreenshot || onWidgetImageClick || onSetPrimaryWidget)}
535
534
  canRename={!!onWidgetRename}
@@ -20,7 +20,6 @@ import type { EngineState, PenStyle, ToolId } from '../../engine/state.js';
20
20
  import { ConversionRegistry } from '../../engine/widgets.js';
21
21
  import type { WidgetMetadata } from '../../engine/widgets.js';
22
22
  import { type WorkspaceCanvasFont } from '../../fonts/workspaceFonts.js';
23
- import type { StylePatch } from '../../engine/core/style.js';
24
23
  import type { PanZoomPosition } from '../panZoomPosition.js';
25
24
  import type { ToolbarPosition } from '../toolbarPosition.js';
26
25
  import type { Translate as CatalogTranslate } from '@widgetic/design-system/i18n';
@@ -234,8 +233,6 @@ export declare class CanvasHost {
234
233
  constructor(initialProps?: Partial<CanvasHostProps>);
235
234
  /** The page changed some props. */
236
235
  setProps(patch: Partial<CanvasHostProps>): void;
237
- /** Persists tool style changes for this workspace (called from the selection panel). */
238
- persistWorkspaceStyle(patch: StylePatch): void;
239
236
  /**
240
237
  * Sets the pen, the line the Draw tool draws next (its colour, its width, how much of the board shows through it), and keeps it
241
238
  * for this workspace, so the pen is the same when the page is opened again. The settings panel calls it while the Draw tool is
@@ -26,8 +26,9 @@ import { ensureInterFontLoaded } from '../../fonts/interFont.js';
26
26
  import { registerWorkspaceFonts } from '../../fonts/workspaceFonts.js';
27
27
  import { isCanvasOwnedTarget } from '../outsideClickDeselect.js';
28
28
  import { flushWorkspaceToolSettingsPending, loadWorkspaceToolSettings, saveWorkspaceToolSettingsDebounced } from '../../settings/workspaceToolSettings.js';
29
+ import { rememberedStylesOfSettings, settingsOfRememberedStyles } from '../../settings/rememberedStyles.js';
29
30
  import { isDrawingGroupTool, readRememberedToolId, toolTheBoardOpensWith, toolToRemember } from '../../settings/rememberedTool.js';
30
- import { canvasLog, canvasWarn, setCanvasLogsEnabled } from '../canvasLogger.js';
31
+ import { canvasLog, canvasWarn, isCanvasLogsEnabled, setCanvasLogsEnabled } from '../canvasLogger.js';
31
32
  import { CANVAS_OPEN_MARKS, markCanvasOpenStep } from '../openMarks.js';
32
33
  import { eventIsForScope, getEventOrigin, shouldTakeFocusBack } from '../eventScope.js';
33
34
  import { getShapeImageStore, shapeImageRef } from '../shapes/shapeImageStore.js';
@@ -42,6 +43,7 @@ import { createPictureSaveMemory } from './pictureSaves.js';
42
43
  // `countPicturesInView` is only used by the log of `#resolveStoredImages` that is commented out.
43
44
  import { /* countPicturesInView, */ fillPictures, picturesStillMissing, startLoadingPictures, waitUpTo } from './storedPictures.js';
44
45
  import { isShapeSnapOn, snapDrawnStroke } from './strokeSnap.js';
46
+ import { createPauseCollector } from './pauseCollector.js';
45
47
  import { createCanvasToolHostFromEngine, executeCanvasTool, summarizeScene } from '../../tools/index.js';
46
48
  import { isCanvasToolName } from '../../tools/definitions.js';
47
49
  /** What each prop is until the page sets it (the values the canvas this one replaces had, but for `panZoomPosition`). */
@@ -210,6 +212,11 @@ const isActivatableTarget = (element) => {
210
212
  };
211
213
  /** The part of the page a paste is not meant for (the creator's own panels and lists). */
212
214
  const PASTE_EXCLUDED_SELECTOR = '.widget-details-floating-panel, .widgets-list-panel, [data-widget-details]';
215
+ /**
216
+ * How long the person has to pause before the console says what the next elements start with: as long as the settings of a workspace
217
+ * wait to be written (`workspaceToolSettings.ts`), so a drag of a slider or of a colour picker says it once, and not for every step.
218
+ */
219
+ const STYLE_LOG_DELAY_MS = 400;
213
220
  // ──────────────────────────────────────────────────────────── the host
214
221
  export class CanvasHost {
215
222
  engine;
@@ -266,9 +273,14 @@ export class CanvasHost {
266
273
  #wasEditingText = false;
267
274
  /** The board is about to take the keyboard back from a text field that left the page (asked for the next frame). */
268
275
  #keyboardReturnQueued = false;
269
- #loadedWorkspaceSettings = null;
270
- /** The workspace and the person whose pen was last taken from the storage (null: none yet), so that the pen is read once for each. */
271
- #penScopeApplied = null;
276
+ /**
277
+ * The workspace and the person whose tool settings (the style the next elements start with, the pen, the font of the texts) were last
278
+ * taken from the storage into the engine (null: none yet), so that they are read once for each. After that the engine is the one that
279
+ * knows: what the person has just chosen may not be in the storage yet.
280
+ */
281
+ #toolSettingsScopeApplied = null;
282
+ /** The kinds of element whose style changed since the console last said so (the line is written once the person pauses, see `#logStyleRememberedSoon`). */
283
+ #styleChangesToLog = createPauseCollector(STYLE_LOG_DELAY_MS, (kinds) => this.#logStyleRemembered(kinds));
272
284
  /** The tool at the last change of the engine (null: none yet), to tell the moment the Draw tool is left from any other change. */
273
285
  #toolAtLastEngineState = null;
274
286
  /** The animation frame that steps the eraser's trail (null: none asked for), and when the trail was last stepped (null: the clock is idle). */
@@ -292,6 +304,9 @@ export class CanvasHost {
292
304
  const preferredTextFontFamily = readPreferredTextFontFamily();
293
305
  if (preferredTextFontFamily)
294
306
  this.engine.setPreferredTextFontFamily(preferredTextFontFamily);
307
+ // What was kept for this workspace and this person (the style the next elements start with, the pen, the font of the texts): taken
308
+ // now, before anything can be drawn, and again only when the page says it is another workspace or person (see `setProps`).
309
+ this.#applyWorkspaceToolSettings();
295
310
  this.controller = new PointerController(this.engine, {
296
311
  snapEnabled: () => true,
297
312
  onStrokeFinished: (stroke, handLine) => this.#handleStrokeFinished(stroke, handLine),
@@ -343,6 +358,9 @@ export class CanvasHost {
343
358
  if (this.props.isExternalDataLoading !== previous.isExternalDataLoading) {
344
359
  queueMicrotask(() => this.#syncEmptyHintGate());
345
360
  }
361
+ // Another workspace or another person: their tool settings are the board's from now on (read at once, not after the fonts).
362
+ if (this.props.workspaceId !== previous.workspaceId || this.props.userId !== previous.userId)
363
+ this.#applyWorkspaceToolSettings();
346
364
  if (this.props.workspaceId !== previous.workspaceId ||
347
365
  this.props.userId !== previous.userId ||
348
366
  this.props.workspaceFonts !== previous.workspaceFonts) {
@@ -356,50 +374,48 @@ export class CanvasHost {
356
374
  });
357
375
  }
358
376
  }
359
- #compactStylePatch(fields) {
360
- const compact = Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
361
- return Object.keys(compact).length > 0 ? compact : undefined;
362
- }
363
- /** Persists tool style changes for this workspace (called from the selection panel). */
364
- persistWorkspaceStyle(patch) {
377
+ /**
378
+ * The person restyled something, and so changed what the next element of some kinds starts with (the engine remembers it, and says
379
+ * which kinds changed: `EngineHooks.onStyleRemembered`). The engine is what makes the next shape, arrow or text start that way, from
380
+ * the very next one; this keeps it for the workspace and the person, so a board opened again starts that way too. The write waits a
381
+ * moment, so a drag of a slider or a colour picker writes once, and is flushed when the page is hidden; each kind is written to its
382
+ * own part of the settings, so restyling an arrow never changes what the shapes or the texts keep. Without a workspace nothing is
383
+ * kept: the engine remembers for as long as the board is open.
384
+ */
385
+ #onStyleRemembered(kinds) {
386
+ this.#logStyleRememberedSoon(kinds);
365
387
  const workspaceId = this.props.workspaceId;
366
388
  if (!workspaceId)
367
389
  return;
368
- const textPatch = patch.fontFamily !== undefined ||
369
- patch.fontSize !== undefined ||
370
- patch.fontWeight !== undefined ||
371
- patch.fontStyle !== undefined ||
372
- patch.color !== undefined ||
373
- patch.align !== undefined ||
374
- patch.underline !== undefined
375
- ? this.#compactStylePatch({
376
- fontFamily: patch.fontFamily,
377
- fontSize: patch.fontSize,
378
- fontWeight: patch.fontWeight,
379
- fontStyle: patch.fontStyle,
380
- color: patch.color,
381
- align: patch.align,
382
- underline: patch.underline
383
- })
384
- : undefined;
385
- const paintPatch = patch.fill !== undefined ||
386
- patch.stroke !== undefined ||
387
- patch.strokeWidth !== undefined ||
388
- patch.strokeStyle !== undefined ||
389
- patch.opacity !== undefined ||
390
- patch.roundness !== undefined
391
- ? this.#compactStylePatch({
392
- fill: patch.fill,
393
- stroke: patch.stroke,
394
- strokeWidth: patch.strokeWidth,
395
- strokeStyle: patch.strokeStyle,
396
- opacity: patch.opacity,
397
- roundness: patch.roundness
398
- })
399
- : undefined;
400
- if (!textPatch && !paintPatch)
390
+ try {
391
+ const patchedKinds = kinds.filter((kind) => kind !== 'pen');
392
+ const settings = settingsOfRememberedStyles(this.engine.rememberedStyles, patchedKinds);
393
+ if (Object.keys(settings).length > 0)
394
+ saveWorkspaceToolSettingsDebounced({ workspaceId, userId: this.props.userId }, settings);
395
+ // A line drawn by hand that was restyled is the pen of the Draw tool from then on: kept with the pen's other writes.
396
+ if (kinds.includes('pen'))
397
+ this.#persistPenStyle(this.engine.state.penStyle);
398
+ }
399
+ catch (error) {
400
+ canvasWarn('Canvas: the style of the next elements could not be kept', error);
401
+ }
402
+ }
403
+ /**
404
+ * Says in the console, once the person pauses (not for every step of a drag), which kinds of element start differently from now on and
405
+ * with what: one line for a burst of changes. Nothing is gathered when the page has the canvas logs off.
406
+ */
407
+ #logStyleRememberedSoon(kinds) {
408
+ if (!isCanvasLogsEnabled() || this.#destroyed)
401
409
  return;
402
- saveWorkspaceToolSettingsDebounced({ workspaceId, userId: this.props.userId }, { text: textPatch, paint: paintPatch });
410
+ this.#styleChangesToLog.add(kinds);
411
+ }
412
+ /** The line of the console for the kinds that changed (see `#logStyleRememberedSoon`), with what each starts with now. */
413
+ #logStyleRemembered(kinds) {
414
+ if (this.#destroyed)
415
+ return;
416
+ const remembered = this.engine.rememberedStyles;
417
+ const startsWith = Object.fromEntries(kinds.map((kind) => [kind, kind === 'pen' ? { ...this.engine.state.penStyle } : { ...remembered[kind] }]));
418
+ canvasLog('Canvas: the next elements start with the style just chosen', startsWith);
403
419
  }
404
420
  /**
405
421
  * Sets the pen, the line the Draw tool draws next (its colour, its width, how much of the board shows through it), and keeps it
@@ -436,32 +452,45 @@ export class CanvasHost {
436
452
  setWorkspaceFontFamilies(fonts.map((font) => font.family));
437
453
  await registerWorkspaceFonts(fonts);
438
454
  this.engine.notifyFontsChanged();
455
+ // The tool settings of the workspace are taken from the storage when the workspace is known (the constructor, `setProps`), not
456
+ // here: this runs again each time the page passes its fonts, and by now the person may have chosen something the storage does not
457
+ // hold yet. Called all the same, it takes nothing back for a workspace and person it has already read.
458
+ this.#applyWorkspaceToolSettings();
459
+ }
460
+ /**
461
+ * Takes what was kept for this workspace and this person into the engine: the style the next shapes, arrows and texts start with
462
+ * (what the person last chose for each kind of element), the font the next text uses, and the pen of the Draw tool. A workspace and
463
+ * a person that were never styled start from the standard looks. Done once for each workspace and person: after that the engine is
464
+ * the one that knows, and what the storage holds may be a moment behind (the write waits for the person to pause), so a page that
465
+ * passes its fonts again must not take any of it back. Without a workspace nothing is read, and nothing is kept either.
466
+ */
467
+ #applyWorkspaceToolSettings() {
439
468
  const workspaceId = this.props.workspaceId;
440
469
  if (!workspaceId)
441
470
  return;
442
- this.#loadedWorkspaceSettings = loadWorkspaceToolSettings({ workspaceId, userId: this.props.userId });
443
- const textFamily = this.#loadedWorkspaceSettings?.text?.fontFamily;
444
- if (textFamily) {
445
- this.engine.setPreferredTextFontFamily(textFamily);
446
- writePreferredTextFontFamily(textFamily);
447
- }
448
- else {
449
- this.engine.setPreferredTextFontFamily(TEXT_DEFAULTS.fontFamily);
450
- }
451
- this.engine.setWorkspaceToolDefaults({
452
- text: this.#loadedWorkspaceSettings?.text ?? null,
453
- paint: this.#loadedWorkspaceSettings?.paint ?? null
454
- });
455
- // The pen of this workspace and this person: the one that was kept, or the standard pen where none was. Set once for each
456
- // workspace and person: a page that passes its fonts again later (another list) does not take the pen back to what the storage
457
- // holds, which may be a moment behind what the person has just set.
458
- const penScope = `${workspaceId}\u0000${this.props.userId ?? ''}`;
459
- if (penScope !== this.#penScopeApplied) {
460
- this.#penScopeApplied = penScope;
461
- // What the storage holds is checked key by key by `setPenStyle`: a key that is no value stays what the standard pen has.
471
+ const scope = `${workspaceId}\u0000${this.props.userId ?? ''}`;
472
+ if (scope === this.#toolSettingsScopeApplied)
473
+ return;
474
+ this.#toolSettingsScopeApplied = scope;
475
+ try {
476
+ const settings = loadWorkspaceToolSettings({ workspaceId, userId: this.props.userId });
477
+ const textFamily = settings?.text?.fontFamily;
478
+ if (textFamily) {
479
+ this.engine.setPreferredTextFontFamily(textFamily);
480
+ writePreferredTextFontFamily(textFamily);
481
+ }
482
+ else {
483
+ this.engine.setPreferredTextFontFamily(TEXT_DEFAULTS.fontFamily);
484
+ }
485
+ // What the storage holds is checked key by key by the engine: a key that is no value of its kind is dropped.
486
+ this.engine.setRememberedStyles(rememberedStylesOfSettings(settings));
487
+ // The pen: the one that was kept, or the standard pen where none was (checked key by key by `setPenStyle` as well).
462
488
  this.engine.setPenStyle(DEFAULT_PEN_STYLE);
463
- if (this.#loadedWorkspaceSettings?.pen)
464
- this.engine.setPenStyle(this.#loadedWorkspaceSettings.pen);
489
+ if (settings?.pen)
490
+ this.engine.setPenStyle(settings.pen);
491
+ }
492
+ catch (error) {
493
+ canvasWarn('Canvas: the tool settings of the workspace could not be read', error);
465
494
  }
466
495
  }
467
496
  /**
@@ -670,6 +699,9 @@ export class CanvasHost {
670
699
  cancelAnimationFrame(this.#scribbleFrame);
671
700
  this.#scribbleFrame = null;
672
701
  this.#scribbleClockLast = null;
702
+ // The console line about the style the person just chose is not written for a board that is gone (what is kept for the workspace
703
+ // is written by the storage's own timer, which outlives the host).
704
+ this.#styleChangesToLog.cancel();
673
705
  this.#scheduler.dispose();
674
706
  for (const remove of this.#removeListeners)
675
707
  remove();
@@ -1119,6 +1151,8 @@ export class CanvasHost {
1119
1151
  onDraftChange: () => this.#markDirty(),
1120
1152
  onCleared: (cause) => this.#safely(() => this.props.onCanvasCleared?.(cause), 'onCanvasCleared'),
1121
1153
  onSelectionChange: (ids) => this.#onSelectionChange(ids),
1154
+ // The person restyled something: the next elements of that kind start that way, and it is kept for the workspace.
1155
+ onStyleRemembered: (kinds) => this.#onStyleRemembered(kinds),
1122
1156
  confirmWidgetDeletion: (widgetId) => {
1123
1157
  const ask = this.props.onWidgetShapeDeleting;
1124
1158
  return ask ? ask(widgetId) : true;
@@ -1818,7 +1852,8 @@ export class CanvasHost {
1818
1852
  wireframe: this.engine.wireframeMode,
1819
1853
  createId: this.engine.services.createId,
1820
1854
  random: this.engine.services.random,
1821
- workspacePaint: this.engine.workspacePaintForNewShape(this.engine.wireframeMode)
1855
+ // What the person last chose for this kind of shape (the panel's last edit), as for a shape dragged out
1856
+ rememberedStyles: this.engine.rememberedStyles
1822
1857
  });
1823
1858
  }
1824
1859
  addRect() {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
3
+ * pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
4
+ *
5
+ * It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
6
+ * The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
7
+ */
8
+ export interface PauseCollector<Item> {
9
+ /** Notes what happened and starts the wait again: the pause is counted from the last thing that happened. */
10
+ add(items: readonly Item[]): void;
11
+ /** Forgets what was gathered and says nothing about it (the board is gone). */
12
+ cancel(): void;
13
+ }
14
+ /**
15
+ * @param delayMs How long nothing may happen before what was gathered is handed over.
16
+ * @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
17
+ */
18
+ export declare function createPauseCollector<Item>(delayMs: number, onPause: (items: Item[]) => void): PauseCollector<Item>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
3
+ * pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
4
+ *
5
+ * It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
6
+ * The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
7
+ */
8
+ import { canvasWarn } from '../canvasLogger.js';
9
+ /**
10
+ * @param delayMs How long nothing may happen before what was gathered is handed over.
11
+ * @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
12
+ */
13
+ export function createPauseCollector(delayMs, onPause) {
14
+ const gathered = new Set();
15
+ let timer = null;
16
+ const cancel = () => {
17
+ if (timer !== null)
18
+ clearTimeout(timer);
19
+ timer = null;
20
+ gathered.clear();
21
+ };
22
+ return {
23
+ add(items) {
24
+ if (items.length === 0)
25
+ return;
26
+ for (const item of items)
27
+ gathered.add(item);
28
+ if (timer !== null)
29
+ clearTimeout(timer);
30
+ timer = setTimeout(() => {
31
+ timer = null;
32
+ const burst = [...gathered];
33
+ gathered.clear();
34
+ // A handler that fails must not take the page with it: it is a console line.
35
+ try {
36
+ onPause(burst);
37
+ }
38
+ catch (error) {
39
+ canvasWarn('Canvas: a pause handler failed', error);
40
+ }
41
+ }, delayMs);
42
+ },
43
+ cancel
44
+ };
45
+ }
@@ -17,7 +17,14 @@
17
17
  import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
18
18
  import { ariaKeyShortcut, isApplePlatform, menuChordText } from './keyHints.js';
19
19
  import type { Chord } from './keyHints.js';
20
- import { CANVAS_OVERLAY_Z_CLASS, LAYER_MENU_PADDING_CLASS, MENU_PADDING_CLASS, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
20
+ import {
21
+ CANVAS_OVERLAY_Z_CLASS,
22
+ LAYER_MENU_ALIGN_OFFSET_PX,
23
+ LAYER_MENU_PADDING_CLASS,
24
+ MENU_PADDING_CLASS,
25
+ OVERLAY_REDUCED_MOTION_CLASSES,
26
+ SUBMENU_SLIDE_UP_CLASSES
27
+ } from './floatingCard.js';
21
28
  import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
22
29
 
23
30
  interface Props {
@@ -109,6 +116,31 @@
109
116
  event.preventDefault();
110
117
  host.focusBoard();
111
118
  }
119
+
120
+ /**
121
+ * How far, in pixels, the mouse must travel from where the menu opened before letting go over an entry is a choice (press,
122
+ * drag to an entry, release: the way a menu of the system works). Less than that is the hand's own shake while it clicks.
123
+ */
124
+ const RELEASE_TRAVEL_IN_PIXELS = 4;
125
+
126
+ /**
127
+ * The right button opens the menu as it goes down (on a Mac and on Linux), so its release comes after the menu is on the page,
128
+ * and the menu can be under the pointer by then: drawn upward, when the press was low on the board, its last entry ("Delete")
129
+ * is at the pointer, and while the design system's menu slides in it is a few pixels lower still. The menu's own handling of a
130
+ * release that was not pressed on an entry is to choose that entry, so a right click low on the board could delete what was
131
+ * selected. A release that has not left the point where the menu opened ends the press that opened it: it is not a choice, and
132
+ * the entry under it is left alone (the touch case is `choose`, above). A release after a real drag onto an entry is a choice.
133
+ */
134
+ function keepReleaseOfOpeningPressFromChoosing(event: PointerEvent): void {
135
+ try {
136
+ if (event.pointerType === 'touch' || !point || !board) return;
137
+ const rect = board.getBoundingClientRect();
138
+ const travelInPixels = Math.hypot(event.clientX - (rect.left + point.x), event.clientY - (rect.top + point.y));
139
+ if (travelInPixels < RELEASE_TRAVEL_IN_PIXELS) event.preventDefault();
140
+ } catch (error) {
141
+ console.warn('[CanvasContextMenu] could not tell the release of the opening press from a choice', error);
142
+ }
143
+ }
112
144
  </script>
113
145
 
114
146
  <!-- The keys are written beside the name for the eye (hidden from the name a screen reader reads) and given as `aria-keyshortcuts`. -->
@@ -156,6 +188,7 @@
156
188
  sideOffset={point?.byTouch ? TOUCH_MENU_OFFSET : 0}
157
189
  portalProps={canvasOverlayPortalProps($floatingLayer)}
158
190
  onCloseAutoFocus={returnFocusToBoard}
191
+ onpointerupcapture={keepReleaseOfOpeningPressFromChoosing}
159
192
  aria-label={$t('canvas.panel.actions')}
160
193
  data-canvas-ui
161
194
  data-canvas-context-menu
@@ -173,13 +206,17 @@
173
206
  <DropdownMenu.SubTrigger class="h-8 min-h-8 gap-2 px-2 py-1.5" disabled={!hasSelection}>
174
207
  <span class="flex-1 text-body">{$t('canvas.layer.title')}</span>
175
208
  </DropdownMenu.SubTrigger>
209
+ <!--
210
+ The first row of the submenu stands level with "Layer order" (`LAYER_MENU_ALIGN_OFFSET_PX` lifts the card by its border and
211
+ padding), and the submenu fades in and slides up like the Shapes menu (`SUBMENU_SLIDE_UP_CLASSES`).
212
+ -->
176
213
  <DropdownMenu.SubContent
177
214
  align="start"
178
- alignOffset={12}
215
+ alignOffset={LAYER_MENU_ALIGN_OFFSET_PX}
179
216
  sideOffset={13}
180
217
  aria-label={$t('canvas.layer.title')}
181
218
  data-canvas-layer-menu
182
- class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}"
219
+ class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {SUBMENU_SLIDE_UP_CLASSES} {OVERLAY_REDUCED_MOTION_CLASSES}"
183
220
  >
184
221
  {#each layerRows as row (row.mode)}
185
222
  {@render layerMenuRowView(row)}
@@ -3,10 +3,13 @@
3
3
  board and never in the way of the pointer. It is shown while the board holds nothing, and goes the moment something is
4
4
  drawn. A page that words the line under the title as an empty message (`messages`) gets the tile and the title only.
5
5
 
6
- Where it stands: in the middle of the board above the toolbar (the toolbar is 44 px high and stands 16 px from the bottom,
7
- so the room above it ends 60 px from the bottom), so a short board such as the 320 px card of the Home page shows the whole
8
- hint. Figma puts it 312 px from the top of a tall board and it stays there: the space over the hint is capped at 312 px,
9
- the rest goes under it. A phone (max-md) centres it on the whole board, as before.
6
+ Where it stands: on the middle of the board, at any height and any width. A board that is dragged taller (the sketch card of
7
+ the Home page) keeps the hint half way down, as far from the top as from the bottom; it is not held at a fixed distance from the
8
+ top (the design's 312 px), which left it high on a tall board. The toolbar is 44 px high and stands 16 px from the bottom, so a
9
+ board as short as the 320 px card of the Home page still shows the whole hint above it.
10
+
11
+ Its words are said as the design system's empty state says them ("No widgets yet" in an empty project): the title and the line
12
+ under it in the muted colour. The tile keeps the board's own look: the board is `muted`, so a tile of that colour would vanish.
10
13
  -->
11
14
  <script lang="ts">
12
15
  import { useCanvasLanguage } from '../../i18n/language.js';
@@ -18,17 +21,15 @@
18
21
  const hintDescription = $derived($t('canvas.hint.description'));
19
22
  </script>
20
23
 
21
- <div class="pointer-events-none absolute inset-x-0 top-0 bottom-[60px] flex flex-col items-center max-md:inset-0 max-md:justify-center max-md:p-6" data-canvas-hint>
22
- <!-- The space over the hint and the space under it share what the board has left; the one over it never grows past 312 px. -->
23
- <div class="max-h-[312px] min-h-0 flex-1 max-md:hidden"></div>
24
+ <!-- The hint is centred on the whole board (the same on a phone); the 24 px at the sides keep it off the edges of a narrow board. -->
25
+ <div class="pointer-events-none absolute inset-0 flex items-center justify-center px-6" data-canvas-hint>
24
26
  <div class="flex w-80 max-w-full flex-col items-center gap-2.5 text-center">
25
27
  <div class="flex size-9 items-center justify-center rounded-lg border border-border bg-background text-foreground">
26
28
  <IconPencil class="size-4 stroke-[1.333]" aria-hidden="true" />
27
29
  </div>
28
- <p class="text-body-medium text-foreground">{$t('canvas.hint.title')}</p>
30
+ <p class="text-body-medium text-muted-foreground">{$t('canvas.hint.title')}</p>
29
31
  {#if hintDescription}
30
32
  <p class="text-body text-muted-foreground" data-canvas-hint-description>{hintDescription}</p>
31
33
  {/if}
32
34
  </div>
33
- <div class="min-h-0 flex-1 max-md:hidden"></div>
34
35
  </div>
@@ -27,6 +27,7 @@
27
27
  import type { Attachment } from 'svelte/attachments';
28
28
  import { IconButton, NumberControls, Select, Slider } from '@widgetic/design-system/components';
29
29
  import { MIN_BRUSH_WIDTH } from '../../engine/core/brush.js';
30
+ import { MAX_STROKE_WIDTH } from '../../engine/core/style.js';
30
31
  import type { StylePatch } from '../../engine/core/style.js';
31
32
  import { MIN_PEN_OPACITY } from '../../engine/state.js';
32
33
  import type { EngineState, PenStyle } from '../../engine/state.js';
@@ -61,8 +62,6 @@
61
62
  host: CanvasHost;
62
63
  state: EngineState;
63
64
  ui: HostUiState;
64
- /** The page hides the colour fields (the wireframe mode keeps every shape white with a grey outline). */
65
- wireframeMode: boolean;
66
65
  canCapture: boolean;
67
66
  canConvert: boolean;
68
67
  canRename: boolean;
@@ -79,7 +78,7 @@
79
78
  widgetCardHasNoSettings?: boolean;
80
79
  }
81
80
 
82
- let { host, state, ui, wireframeMode, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance, widgetCardHasNoSettings = false }: Props = $props();
81
+ let { host, state, ui, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance, widgetCardHasNoSettings = false }: Props = $props();
83
82
 
84
83
  const { t } = useCanvasLanguage();
85
84
  const floatingLayer = useFloatingLayer();
@@ -140,7 +139,12 @@
140
139
  host.changePenStyle(penPatch, { final });
141
140
  }
142
141
 
143
- /** Changes how the selection looks (or the pen, while the panel is about the pen). `commit` is false while a drag is going. */
142
+ /**
143
+ * Changes how the selection looks (or the pen, while the panel is about the pen). `commit` is false while a drag is going.
144
+ *
145
+ * The engine remembers what was chosen for the next elements of this kind at every change (a drag of a slider included), and the host
146
+ * keeps it for the workspace: the panel has nothing more to do than change the selection.
147
+ */
144
148
  function changeStyle(patch: StylePatch, commit = true): void {
145
149
  if (editsPen) {
146
150
  changePen(patch, commit);
@@ -149,10 +153,7 @@
149
153
  try {
150
154
  host.engine.setStyle(patch, { commit });
151
155
  stopCommitTimer();
152
- if (commit) {
153
- host.engine.commit();
154
- host.persistWorkspaceStyle(patch);
155
- }
156
+ if (commit) host.engine.commit();
156
157
  else commitTimer = setTimeout(() => host.engine.commit(), COMMIT_AFTER_MS);
157
158
  } catch (error) {
158
159
  console.warn('Canvas: the selection panel could not change the selection', error);
@@ -234,9 +235,10 @@
234
235
  (!selectionIsAWidgetWithoutSettings &&
235
236
  ((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert)))
236
237
  );
237
- const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
238
- // The pen's colour is shown in the wireframe look too: a line drawn by hand keeps its colour there.
239
- const showStrokeColor = $derived(editsPen || showStrokeColorRow(traits, wireframeMode));
238
+ // The colour rows follow what is selected (and the pen's colour, which is the Stroke of its traits), on every board: the wireframe
239
+ // look only decides how a new shape starts (white with a grey outline), not which colours can be changed afterwards.
240
+ const showFillColor = $derived(showFillColorRow(traits));
241
+ const showStrokeColor = $derived(showStrokeColorRow(traits));
240
242
  const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
241
243
  const panelAnchorClass = $derived(
242
244
  `${clearance.belowTopCards ? 'top-16' : 'top-4'} ${PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}`
@@ -301,7 +303,7 @@
301
303
  value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
302
304
  fallbackValue={strokeWidthValue}
303
305
  min={strokeWidthMin}
304
- max={200}
306
+ max={MAX_STROKE_WIDTH}
305
307
  step={1}
306
308
  onChange={(next) => changeStyle({ strokeWidth: next })}
307
309
  />
@@ -5,8 +5,6 @@ interface Props {
5
5
  host: CanvasHost;
6
6
  state: EngineState;
7
7
  ui: HostUiState;
8
- /** The page hides the colour fields (the wireframe mode keeps every shape white with a grey outline). */
9
- wireframeMode: boolean;
10
8
  canCapture: boolean;
11
9
  canConvert: boolean;
12
10
  canRename: boolean;
@@ -26,11 +26,12 @@
26
26
  import {
27
27
  CANVAS_OVERLAY_Z_CLASS,
28
28
  MENU_PADDING_CLASS,
29
- MENU_TRIGGER_RING_CLASSES,
30
29
  OVERLAY_REDUCED_MOTION_CLASSES,
31
30
  SHAPE_LIBRARY_STROKE_WIDTH,
31
+ SUBMENU_SLIDE_UP_CLASSES,
32
32
  TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES,
33
- TOOLBAR_ICON_STROKE_CLASSES
33
+ TOOLBAR_ICON_STROKE_CLASSES,
34
+ TOOLBAR_NO_RING_CLASSES
34
35
  } from './floatingCard.js';
35
36
  import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
36
37
  import { usePopoverSide } from './popoverSide.js';
@@ -132,7 +133,7 @@
132
133
  type="button"
133
134
  aria-label={$t('canvas.tool.shapes')}
134
135
  data-active={shapeToolInUse ? '' : undefined}
135
- class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:bg-accent focus-visible:outline-hidden data-[active]:bg-brand-subtle {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} {MENU_TRIGGER_RING_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
136
+ class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:bg-accent {TOOLBAR_NO_RING_CLASSES} data-[active]:bg-brand-subtle {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
136
137
  >
137
138
  <IconCategory />
138
139
  <IconChevronDown class="transition-transform duration-fast motion-reduce:transition-none data-[open]:rotate-180" data-open={open ? '' : undefined} />
@@ -185,7 +186,8 @@
185
186
  <DropdownMenu.Separator />
186
187
  <DropdownMenu.Sub>
187
188
  <DropdownMenu.SubTrigger>{$t('canvas.tool.moreShapes')}</DropdownMenu.SubTrigger>
188
- <DropdownMenu.SubContent aria-label={$t('canvas.tool.moreShapes')} class="{CANVAS_OVERLAY_Z_CLASS} max-h-[min(24rem,70vh)] w-[220px] overflow-y-auto {MENU_PADDING_CLASS} shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}">
189
+ <!-- It fades in and slides up like the Shapes menu (`SUBMENU_SLIDE_UP_CLASSES`): without it the slide it inherited came from the bottom left. -->
190
+ <DropdownMenu.SubContent aria-label={$t('canvas.tool.moreShapes')} class="{CANVAS_OVERLAY_Z_CLASS} max-h-[min(24rem,70vh)] w-[220px] overflow-y-auto {MENU_PADDING_CLASS} shadow-floating {SUBMENU_SLIDE_UP_CLASSES} {OVERLAY_REDUCED_MOTION_CLASSES}">
189
191
  {#each libraryGroups as [category, shapes] (category)}
190
192
  <DropdownMenu.Label>{categoryLabel(category, $t)}</DropdownMenu.Label>
191
193
  <div class="grid grid-cols-5 gap-1 px-1 pb-1" role="presentation">