@drawback/core 0.2.0-rc.20261201121350 → 0.2.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 (56) hide show
  1. package/dist/geometry/index.d.mts +1 -1
  2. package/dist/geometry/index.mjs +1 -1
  3. package/dist/{geometry-Brsa66kT.mjs → geometry-B6555wfO.mjs} +2 -8
  4. package/dist/grid/index.d.mts +1 -1
  5. package/dist/grid/index.mjs +1 -1
  6. package/dist/{grid-BR8od5w8.mjs → grid-BjZ79Ib6.mjs} +1 -4
  7. package/dist/{index-CYSqrhal.d.mts → index-BUdcJ8w8.d.mts} +1 -4
  8. package/dist/{index-Bt8yLTLG.d.mts → index-CukXdXbn.d.mts} +1 -4
  9. package/dist/index.d.mts +39 -157
  10. package/dist/index.mjs +48 -129
  11. package/package.json +1 -1
  12. package/src/assets/references.ts +1 -4
  13. package/src/assets/types.ts +1 -5
  14. package/src/assets/url.ts +1 -4
  15. package/src/bindings/bindings.ts +2 -15
  16. package/src/bindings/derive.ts +1 -4
  17. package/src/clipboard/format.ts +1 -4
  18. package/src/clipboard/insert.ts +1 -4
  19. package/src/commands/builtin.ts +13 -0
  20. package/src/editing-host.ts +3 -15
  21. package/src/editor.ts +7 -27
  22. package/src/events.ts +1 -4
  23. package/src/frames/frames.ts +2 -16
  24. package/src/geometry/curves.ts +1 -4
  25. package/src/geometry/simplify.ts +1 -4
  26. package/src/grid/math.ts +1 -4
  27. package/src/groups/cleanup.ts +1 -4
  28. package/src/image/images.ts +1 -4
  29. package/src/input/handle-sessions.ts +2 -7
  30. package/src/input/router.ts +1 -4
  31. package/src/interactions/interactions.ts +1 -4
  32. package/src/linear/elbow.ts +2 -8
  33. package/src/linear/linear.ts +1 -4
  34. package/src/links/links.ts +3 -14
  35. package/src/model/elements.ts +3 -12
  36. package/src/model/frame.ts +2 -9
  37. package/src/model/linear.ts +2 -8
  38. package/src/model/settings.ts +2 -5
  39. package/src/model/style.ts +2 -8
  40. package/src/modes/modes.ts +1 -0
  41. package/src/permissions/capabilities.ts +1 -0
  42. package/src/permissions/permissions.ts +6 -8
  43. package/src/plugins/plugins.ts +1 -6
  44. package/src/presence/presence.ts +1 -4
  45. package/src/scene/scene.ts +1 -5
  46. package/src/selection/selection.ts +1 -4
  47. package/src/snapping/snapping.ts +1 -2
  48. package/src/styles/styles.ts +1 -4
  49. package/src/sync/projection.ts +1 -4
  50. package/src/text/layout.ts +1 -4
  51. package/src/text/measure.ts +2 -8
  52. package/src/text/text.ts +1 -4
  53. package/src/transform/transform.ts +1 -2
  54. package/src/tx/derivation.ts +2 -10
  55. package/src/tx/document-steps.ts +1 -4
  56. package/src/tx/record-writer.ts +1 -4
package/src/editor.ts CHANGED
@@ -300,10 +300,7 @@ export interface ElementApi<Definitions extends readonly ElementDefinition[]> {
300
300
  input: ElementCreateInput<Type, PropsFor<Definitions, Type>>,
301
301
  ): ElementId;
302
302
  createMany(inputs: readonly ElementCreateInput[]): readonly ElementId[];
303
- /**
304
- * Fields merged over the `data` of every element this editor creates (tools, paste,
305
- * duplicate and API), e.g. the creating user's id. `undefined` stops stamping.
306
- */
303
+ /** Fields merged into new elements' `data` (e.g. the creator's id); `undefined` stops it. */
307
304
  setCreateData(data: JsonObject | undefined): void;
308
305
  update(id: ElementId, patch: ElementUpdate, options?: TransactionOptions): void;
309
306
  delete(id: ElementId): void;
@@ -356,10 +353,7 @@ export interface TransactionApi<Definitions extends readonly ElementDefinition[]
356
353
  readonly settings: TransactionSettingsApi;
357
354
  }
358
355
 
359
- /**
360
- * `amend` folds a patch into the history entries that created the patched records (e.g. the
361
- * upload result of a pending asset), so undo and redo use the amended records.
362
- */
356
+ /** Folds a patch into the history entries that created the records, so undo/redo use it. */
363
357
  export type HistoryMode = 'record' | 'skip' | 'merge' | 'amend';
364
358
 
365
359
  export interface TransactionOptions {
@@ -420,10 +414,7 @@ export interface ApplyChangesOptions {
420
414
  readonly partial?: boolean;
421
415
  readonly onMissing?: 'skip' | 'reject';
422
416
  readonly trust?: 'authoritative' | 'checked';
423
- /**
424
- * With `trust: 'checked'`, enforces permissions for this actor (through `canAs`) instead of
425
- * the editor's local actor and mode. Pass `undefined` explicitly to check an anonymous actor.
426
- */
417
+ /** With `trust: 'checked'`, checks permissions as this actor; pass `undefined` for anonymous. */
427
418
  readonly actor?: JsonValue | undefined;
428
419
  }
429
420
 
@@ -469,12 +460,7 @@ export interface SyncApi {
469
460
  validate(changeSet: unknown, options?: ApplyChangesOptions): ChangeSetValidationResult;
470
461
  changesSince(revision: number): readonly ChangeSet[];
471
462
  stripPreviousValues(changeSet: ChangeSet): ChangeSet;
472
- /**
473
- * What `actor` may see of a change set that was just committed (call it inside
474
- * `document.onChange` or right after `applyChanges`, before the next commit). Records the actor
475
- * cannot view are dropped, visibility changes become `put`/`delete` operations, and assets
476
- * follow the visibility of the elements that reference them.
477
- */
463
+ /** What `actor` may see of the just-committed change set; call it before the next commit. */
478
464
  project(
479
465
  changeSet: ChangeSet,
480
466
  actor: JsonValue | undefined,
@@ -497,11 +483,7 @@ export type CommitHookResult = void | { readonly reject: string };
497
483
  export type CommitHook = (changeSet: ChangeSet, context: CommitContext) => CommitHookResult;
498
484
 
499
485
  export interface CommitHookOptions {
500
- /**
501
- * Also run for remote changes applied with `trust: 'checked'`. Hooks always run for local
502
- * origins (`local-user`, `local-api`, `plugin`, `history`) and never for `load` or
503
- * authoritative remote changes.
504
- */
486
+ /** Also run for checked remote changes; never for `load` or authoritative remote changes. */
505
487
  readonly trusted?: boolean;
506
488
  }
507
489
 
@@ -1013,8 +995,7 @@ export class EditorInstance<
1013
995
  this.#maskRegistry,
1014
996
  () => this.#scene.rebuild(this.#records),
1015
997
  );
1016
- // Commit derivation order: an image's size comes from its asset, text may resize its
1017
- // box, frames move children, connectors follow all of that, then empty groups go.
998
+ // Order: image size, text box, frame children, then connectors follow; empty groups last.
1018
999
  this.#commitDerivations = [
1019
1000
  imageDerivation(this.#imagesController),
1020
1001
  textDerivation(this.#textController),
@@ -1739,8 +1720,7 @@ export class EditorInstance<
1739
1720
  keys: () => before.keys(),
1740
1721
  };
1741
1722
  const staged = new RecordOverlay(this.#records);
1742
- // Nothing committed since the draft captured its records: they are already normalized and
1743
- // can be staged as they are. Otherwise the draft is rebased as field-level patches.
1723
+ // Unchanged since the draft captured its records: stage as-is, else rebase as patches.
1744
1724
  const unchangedBase = [...changedKeys].every(
1745
1725
  (key) => before.get(key) === this.#records.get(key),
1746
1726
  );
package/src/events.ts CHANGED
@@ -209,10 +209,7 @@ export interface EventApi {
209
209
  name: EventName,
210
210
  listener: EditorEventListener<EventName>,
211
211
  ): () => void;
212
- /**
213
- * Called for every dispatched event after its specific listeners. Per-element events
214
- * (`element.create/update/delete`) are only produced when something listens to them by name.
215
- */
212
+ /** Called for every event; per-element events only fire when someone listens by name. */
216
213
  onAny(listener: AnyEventListener): () => void;
217
214
  onError(listener: (event: EditorErrorEvent) => void): () => void;
218
215
  reportError(error: Error, context: string): void;
@@ -14,10 +14,7 @@ type HostEditor = EditorSlice<{
14
14
  }>;
15
15
 
16
16
  export interface FrameSettings {
17
- /**
18
- * Local edits put an element into the smallest frame that fully contains it, and take it out
19
- * when it no longer overlaps its frame (default true). Remote changes are never adjusted.
20
- */
17
+ /** Auto-assign elements to the smallest containing frame on local edits (default true). */
21
18
  readonly autoAssign: boolean;
22
19
  }
23
20
 
@@ -161,8 +158,6 @@ export class FramesController {
161
158
  return this.#settingsValue;
162
159
  }
163
160
 
164
- // ---------------------------------------------------------------- index
165
-
166
161
  rebuild(records: Iterable<DocumentRecord>): void {
167
162
  this.#frames.clear();
168
163
  this.#childrenOf.clear();
@@ -218,14 +213,7 @@ export class FramesController {
218
213
  }
219
214
  }
220
215
 
221
- // ---------------------------------------------------------------- derivation
222
-
223
- /**
224
- * Adjusts a local transaction before it commits: deleting a frame deletes its children,
225
- * translating a frame moves its children, and (with `autoAssign`) elements join the frame
226
- * that contains them and leave a frame they no longer overlap. Returns the element ids it
227
- * changed.
228
- */
216
+ /** Local commit step: frames carry children on delete and move; `autoAssign` joins and leaves. */
229
217
  deriveCommit(operations: readonly ChangeOperation[], staged: FrameCommitAccess): ElementId[] {
230
218
  const editor = this.#host.editor;
231
219
  const changed = new Set<ElementId>();
@@ -441,8 +429,6 @@ export class FramesController {
441
429
  return result;
442
430
  }
443
431
 
444
- // ---------------------------------------------------------------- api
445
-
446
432
  #assign(
447
433
  ids: readonly ElementId[],
448
434
  frameId: ElementId | undefined,
@@ -2,10 +2,7 @@ import { DEFAULT_CURVE_TOLERANCE, distance, pointLineDistance, shapeSubpaths } f
2
2
 
3
3
  import type { PathSegment, Point, Shape } from './types.js';
4
4
 
5
- /**
6
- * Converts a Catmull-Rom spline through `points` (uniform, tension 0.5) into cubic Bézier
7
- * segments. The curve passes through every point.
8
- */
5
+ /** Catmull-Rom spline (uniform, tension 0.5) through `points` as cubic Bézier segments. */
9
6
  export function catmullRomSegments(points: readonly Point[], closed = false): PathSegment[] {
10
7
  const first = points[0];
11
8
 
@@ -1,10 +1,7 @@
1
1
  import { pointLineDistance } from './shapes.js';
2
2
  import type { Point } from './types.js';
3
3
 
4
- /**
5
- * Ramer–Douglas–Peucker simplification. Keeps the first and last point; every removed point
6
- * lies within `tolerance` of the simplified polyline. Returns indices of kept points.
7
- */
4
+ /** Ramer–Douglas–Peucker; returns indices of kept points (first and last always kept). */
8
5
  export function simplifyIndices(points: readonly Point[], tolerance: number): number[] {
9
6
  const count = points.length;
10
7
 
package/src/grid/math.ts CHANGED
@@ -51,10 +51,7 @@ function hexLocal(grid: GridGeometry, q: number, r: number): Point {
51
51
  : { x: size * 1.5 * q, y: size * ((SQRT3 / 2) * q + SQRT3 * r) };
52
52
  }
53
53
 
54
- /**
55
- * Fractional grid coordinates of a world point. Square/dot: cell units with (0, 0) at
56
- * the origin corner. Hex: fractional axial coordinates with hex (0, 0) centered on the origin.
57
- */
54
+ /** Fractional grid coordinates: cells from the origin corner, or axial for hex. */
58
55
  export function worldToGrid(grid: GridGeometry, point: Point): Point {
59
56
  const local = toLocal(grid, point);
60
57
 
@@ -1,10 +1,7 @@
1
1
  import { recordKey } from '../model/records.js';
2
2
  import type { CommitDerivation } from '../tx/derivation.js';
3
3
 
4
- /**
5
- * Removes groups a local transaction left empty (and their parents, if they became empty in
6
- * turn), in the same change set.
7
- */
4
+ /** Removes groups a local transaction emptied (and emptied parents) in the same change set. */
8
5
  export const emptyGroupDerivation: CommitDerivation = {
9
6
  id: 'groups',
10
7
  derive: ({ operations, committed, record, records, deleteRecord }) => {
@@ -666,10 +666,7 @@ export class ImagesController {
666
666
  };
667
667
  }
668
668
 
669
- /**
670
- * Keeps image elements consistent with their assets for local commits: natural size
671
- * follows the asset when it is known or changes, and crops are clamped to it.
672
- */
669
+ /** Keeps images consistent with their assets on local commits (natural size, crop clamp). */
673
670
  normalize(
674
671
  element: ElementRecord,
675
672
  assetOf: (id: AssetId) => AssetRecord | undefined,
@@ -30,11 +30,7 @@ export interface HandleSessionDependencies {
30
30
  report(error: unknown, context: string): void;
31
31
  }
32
32
 
33
- /**
34
- * Starts the pointer session for a selection handle: resize, rotate, a point handle or a
35
- * definition's custom handle. Returns `undefined` when nothing is selected or the handle has
36
- * no session.
37
- */
33
+ /** Pointer session for a selection handle; `undefined` without a selection or session. */
38
34
  export function startHandleSession(
39
35
  deps: HandleSessionDependencies,
40
36
  handle: SelectionHandle,
@@ -76,8 +72,7 @@ export function startHandleSession(
76
72
  const outline = deps.selection.outline();
77
73
  const center = outline?.center ?? (single !== undefined ? elementCenter(single) : { x: 0, y: 0 });
78
74
  const startAngle = Math.atan2(down.world.y - center.y, down.world.x - center.x);
79
- // Handles sit on the padded outline and sides can be grabbed anywhere along them: resize as
80
- // if the shape's own corner or side was grabbed, keeping that offset, so nothing jumps.
75
+ // Handles sit on the padded outline: keep the grab offset so nothing jumps.
81
76
  const anchor =
82
77
  handle.kind === 'resize' && handle.handle !== undefined && outline !== undefined
83
78
  ? handlePosition(outline, handle.handle)
@@ -670,10 +670,7 @@ export class InputController {
670
670
  this.#pointSessions = factory;
671
671
  }
672
672
 
673
- /**
674
- * Knob handles (corners, rotation, points, custom) win within `handleSize`; otherwise a side
675
- * resize handle is hit anywhere within half that distance of its side.
676
- */
673
+ /** Knobs win within `handleSize`; sides hit within half that distance of the side. */
677
674
  #hitHandle(event: CanvasPointerEvent): SelectionHandle | undefined {
678
675
  const zoom = this.#host.editor.viewport.get().zoom;
679
676
  const radius = this.#selection.options().handleSize / zoom;
@@ -107,10 +107,7 @@ export interface InteractionsApi {
107
107
  cancel(): boolean;
108
108
  onConflict(handler: ((conflict: InteractionConflict) => ConflictResolution) | undefined): void;
109
109
  applyRemotePreview(peerId: string, preview: InteractionPreviewEvent | unknown): void;
110
- /**
111
- * What `actor` may see of a preview: patches and creations of elements the actor cannot view
112
- * are dropped. `undefined` when nothing is left to send (unless the preview is `done`).
113
- */
110
+ /** What `actor` may see of a preview; `undefined` when nothing is left (unless `done`). */
114
111
  project(
115
112
  preview: InteractionPreviewEvent,
116
113
  actor: JsonValue | undefined,
@@ -170,10 +170,7 @@ interface Node {
170
170
  readonly y: number;
171
171
  }
172
172
 
173
- /**
174
- * Orthogonal leg from `from` (leaving along `leave`) to `to` (arriving along `arrive`) that keeps
175
- * out of `boxes`. Cost is length plus a penalty per bend; ties resolve deterministically.
176
- */
173
+ /** Orthogonal leg avoiding `boxes`; cost is length plus a per-bend penalty, ties fixed. */
177
174
  function leg(
178
175
  from: Point,
179
176
  leave: ElbowHeading,
@@ -358,10 +355,7 @@ export function simplifyOrthogonal(points: readonly Point[]): Point[] {
358
355
  return result;
359
356
  }
360
357
 
361
- /**
362
- * Orthogonal route between two ends. Bound ends leave their target along `heading`, the route
363
- * avoids the padded targets and passes through pinned segments in order. Deterministic.
364
- */
358
+ /** Deterministic orthogonal route around padded targets, through pinned segments. */
365
359
  export function routeElbow(
366
360
  start: ElbowEnd,
367
361
  end: ElbowEnd,
@@ -75,10 +75,7 @@ export interface LinearApi {
75
75
  curved: boolean,
76
76
  options?: TransactionOptions,
77
77
  ): void;
78
- /**
79
- * Sets how arrows are drawn: straight segments, a curve through the points, or an elbow route.
80
- * Switching resets pinned elbow segments; leaving the elbow type keeps only the end points.
81
- */
78
+ /** Sets the arrow type; resets pinned elbow segments, and leaving elbow keeps only the ends. */
82
79
  setArrowType(
83
80
  ids: ElementId | readonly ElementId[],
84
81
  type: ArrowType,
@@ -79,11 +79,7 @@ function pageUrl(): ParsedUrl | undefined {
79
79
  return typeof href === 'string' ? parseUrl(href) : undefined;
80
80
  }
81
81
 
82
- /**
83
- * Default element links, like Excalidraw's "Copy link to object": the current page with
84
- * `?element=<id>` (other query parameters and the hash are kept). A URL counts as an element
85
- * link when it has the same origin and path as the current page and an `element` parameter.
86
- */
82
+ /** Default element links, like Excalidraw: the current page with `?element=<id>`. */
87
83
  export const pageElementLinks: ElementLinkFormat = {
88
84
  toUrl: (id) => {
89
85
  const url = pageUrl();
@@ -114,10 +110,7 @@ export interface LinksApi {
114
110
  get(id: ElementId): string | undefined;
115
111
  /** Sets or clears a link in an ordinary transaction (needs `core.edit.content`). */
116
112
  set(id: ElementId, url: string | undefined, options?: TransactionOptions): void;
117
- /**
118
- * Handles a URL scheme (without `:`), and allows it. `''` handles scheme-less (relative) links.
119
- * Replaces the default `http`/`https`/`mailto` opener when registered for those schemes.
120
- */
113
+ /** Handles and allows a scheme (no `:`; `''` = relative), overriding the default openers. */
121
114
  registerScheme(scheme: string, handler: LinkSchemeHandler): () => void;
122
115
  setAllowedSchemes(schemes: readonly string[]): void;
123
116
  allowedSchemes(): readonly string[];
@@ -126,11 +119,7 @@ export interface LinksApi {
126
119
  /** Allowed scheme and never `javascript:`, `data:`, `vbscript:` or `file:`. */
127
120
  isAllowed(url: string): boolean;
128
121
  canOpen(url: string, options?: { readonly elementId?: ElementId }): boolean;
129
- /**
130
- * Opens an element's link or a URL through its scheme handler; `false` when blocked. A link
131
- * to an element of this document (see `elementOf`) centers the view on that element (without selecting it)
132
- * on it instead.
133
- */
122
+ /** Opens a link via its scheme handler (`false` if blocked); element links center the view. */
134
123
  open(
135
124
  target: ElementId | { readonly url: string },
136
125
  options?: { readonly source?: LinkOpenSource },
@@ -90,10 +90,7 @@ export interface ConnectorHooks<Record extends ElementRecord = ElementRecord> {
90
90
  endpoints(element: Record): ConnectorBindings;
91
91
  /** Path points in element-local space (at least two). */
92
92
  path(element: Record): readonly Point[];
93
- /**
94
- * Returns an update that moves the given endpoints to world positions. `startTarget` and
95
- * `endTarget` are the world bounds of the bound targets.
96
- */
93
+ /** Update moving the given endpoints to world positions; targets are world bounds. */
97
94
  withEndpoints(
98
95
  element: Record,
99
96
  resolved: {
@@ -103,10 +100,7 @@ export interface ConnectorHooks<Record extends ElementRecord = ElementRecord> {
103
100
  readonly endTarget?: Box;
104
101
  },
105
102
  ): ElementUpdate;
106
- /**
107
- * Connectors whose whole path derives from their ends and targets (e.g. elbow routes). They are
108
- * re-derived whenever they or their targets change, not only when an end moves.
109
- */
103
+ /** Connectors whose path derives from ends and targets, re-derived when either changes. */
110
104
  routed?(element: Record): boolean;
111
105
  /** Returns an update that replaces the given bindings. */
112
106
  withBindings(
@@ -203,10 +197,7 @@ function typeLabel(type: string): string {
203
197
  return words.length === 0 ? type : words[0]!.toUpperCase() + words.slice(1);
204
198
  }
205
199
 
206
- /**
207
- * Display name and icon id: the record's `name`, then the definition's `describe`, then a
208
- * built-in label (text elements use their first line), then a label derived from the type.
209
- */
200
+ /** Display name and icon: `name`, then `describe`, then a built-in label, then the type. */
210
201
  export function describeElement(
211
202
  element: ElementRecord,
212
203
  definition: ElementDefinition | undefined,
@@ -27,10 +27,7 @@ export function frameName(element: Pick<ElementRecord, 'name'>): string {
27
27
  : DEFAULT_FRAME_NAME;
28
28
  }
29
29
 
30
- /**
31
- * Frame-local box of the name label at `zoom` (the label keeps its screen size). The width is
32
- * estimated from the name length and never exceeds the frame width.
33
- */
30
+ /** Frame-local name label box at `zoom`, estimated from the name, capped to the frame width. */
34
31
  export function frameLabelBox(element: ElementRecord, zoom: number): Box {
35
32
  const scale = 1 / Math.max(zoom, 1e-6);
36
33
  const width = Math.min(
@@ -41,11 +38,7 @@ export function frameLabelBox(element: ElementRecord, zoom: number): Box {
41
38
  return { minX: 0, minY: maxY - FRAME_LABEL.height * scale, maxX: width, maxY };
42
39
  }
43
40
 
44
- /**
45
- * A frame groups the elements inside it: it clips them, moves them along and is deleted and
46
- * duplicated with them. Children store the frame in `frameId`. Frames are hit on their border
47
- * and name label only, so clicks inside reach the canvas and the children.
48
- */
41
+ /** Frames clip, move and delete with their children; hit only on border and name label. */
49
42
  export const frameElement = defineElement({
50
43
  type: FRAME_TYPE,
51
44
  version: 1,
@@ -206,10 +206,7 @@ function elbowEnd(point: Point, box: Box | undefined, other: Point): ElbowEnd {
206
206
  : { point, heading: headingFromBox(point, box), box };
207
207
  }
208
208
 
209
- /**
210
- * Re-routes an elbow arrow between world end points, keeping its pinned segments. `targets` are
211
- * the world bounds of bound targets.
212
- */
209
+ /** Re-routes an elbow arrow between world ends, keeping pinned segments. */
213
210
  export function elbowArrowUpdate(
214
211
  element: ElementRecord,
215
212
  ends: { readonly start: Point; readonly end: Point },
@@ -276,10 +273,7 @@ export interface LinearPlacement {
276
273
  readonly points: readonly LocalPoint[];
277
274
  }
278
275
 
279
- /**
280
- * Computes box and normalized local points for world-space points, keeping the element's
281
- * rotation and flips. `quantum` rounds local points (e.g. `0.01`).
282
- */
276
+ /** Box and normalized local points for world points, keeping rotation and flips. */
283
277
  export function linearFromWorldPoints(
284
278
  element: Pick<ElementRecord, 'rotation' | 'flipX' | 'flipY'>,
285
279
  world: readonly Point[],
@@ -18,12 +18,9 @@ export interface GridConfig {
18
18
  readonly opacity: number;
19
19
  /** Screen pixels. */
20
20
  readonly lineWidth: number;
21
- /** Square/dot: every N cells is drawn as a major line. */
21
+ /** Major line every N cells; hex: super-hexes of radius N - 1. 1 = none. */
22
22
  readonly majorEvery?: number;
23
- /**
24
- * Major lines' color; defaults to `color`. Lines between majors use `color` at reduced opacity,
25
- * so `color` alone styles the whole grid.
26
- */
23
+ /** Major line color (defaults to `color`); minor lines use `color` at reduced opacity. */
27
24
  readonly majorColor?: string;
28
25
  }
29
26
 
@@ -335,19 +335,13 @@ export function mergeStyleDefaults(
335
335
  return Object.freeze(result) as unknown as ElementStyle;
336
336
  }
337
337
 
338
- /**
339
- * Tolerant render-time resolution: valid stored values win, invalid or missing ones
340
- * fall back to `defaults` and then to {@link DEFAULT_ELEMENT_STYLE}.
341
- */
338
+ /** Valid stored values, then `defaults`, then {@link DEFAULT_ELEMENT_STYLE}. */
342
339
  const NO_DEFAULTS: ElementStyleDefaults = Object.freeze({});
343
340
  const NO_STYLE = Object.freeze({});
344
341
  /** Resolved styles by defaults object, then style object; both are immutable in practice. */
345
342
  const resolvedStyles = new WeakMap<object, WeakMap<object, ElementStyle>>();
346
343
 
347
- /**
348
- * The element's style over `defaults`, with every key present. Results are cached per
349
- * (defaults, style) object pair and frozen, so callers must not mutate them.
350
- */
344
+ /** Full style over `defaults`, cached per (defaults, style) pair and frozen: never mutate. */
351
345
  export function resolveStyle(
352
346
  element: Pick<ElementRecord, 'style'>,
353
347
  defaults: ElementStyleDefaults = NO_DEFAULTS,
@@ -63,6 +63,7 @@ export const VIEW_MODE_RESTRICTIONS: readonly string[] = [
63
63
  'core.group',
64
64
  'core.lock',
65
65
  'core.manage-layers',
66
+ 'core.rename',
66
67
  'core.edit.assets',
67
68
  'core.manage-grid',
68
69
  'core.manage-canvas',
@@ -35,6 +35,7 @@ export const CORE_CAPABILITIES: readonly (readonly [string, readonly CapabilityT
35
35
  ['core.group', ['element', 'group', 'editor']],
36
36
  ['core.lock', ['element', 'layer', 'group']],
37
37
  ['core.manage-layers', ['layer', 'editor']],
38
+ ['core.rename', ['layer']],
38
39
  ['core.manage-permissions', ALL_TARGETS],
39
40
  ['core.interact', ['element']],
40
41
  ['core.bind', ['element']],
@@ -41,10 +41,7 @@ export interface PermissionResolverTarget {
41
41
  export interface PermissionResolverContext {
42
42
  readonly editor: AnyEditor;
43
43
  readonly actor: JsonValue | undefined;
44
- /**
45
- * Reads records in the state being evaluated: the committed document, a staged commit, or the
46
- * state before a projected change. Prefer it over `editor.document` inside resolvers.
47
- */
44
+ /** Records in the state being evaluated; prefer it over `editor.document` in resolvers. */
48
45
  readonly get: (kind: RecordKind, id: string) => DocumentRecord | undefined;
49
46
  }
50
47
 
@@ -77,10 +74,7 @@ export interface PermissionsChangeEvent {
77
74
 
78
75
  export interface PermissionsApi {
79
76
  can(capability: string, target?: PermissionTarget): boolean;
80
- /**
81
- * Evaluates a capability for another actor (e.g. a remote client) through the same
82
- * defaults, overrides and resolver, ignoring local mode restrictions and caches.
83
- */
77
+ /** Evaluates a capability for another actor, ignoring local mode restrictions and caches. */
84
78
  canAs(actor: JsonValue | undefined, capability: string, target?: PermissionTarget): boolean;
85
79
  effective(target?: PermissionTarget): CapabilitySet;
86
80
  explain(capability: string, target?: PermissionTarget): PermissionExplanation;
@@ -715,6 +709,10 @@ export class PermissionController {
715
709
  }
716
710
 
717
711
  requirements.push({ capability: map[field] ?? fallback, target });
712
+
713
+ if (kind === 'layer' && field === 'name') {
714
+ requirements.push({ capability: 'core.rename', target });
715
+ }
718
716
  }
719
717
 
720
718
  if (kind === 'element' && after?.kind === 'element') {
@@ -10,12 +10,7 @@ import type { ElementDefinition } from '../model/elements.js';
10
10
  import type { CapabilityRegistration } from '../permissions/capabilities.js';
11
11
  import type { ToolDefinition } from '../tools/tools.js';
12
12
 
13
- /**
14
- * Parts of a plugin that other packages install: `@drawback/canvas` adds `canvas`
15
- * (renderers, overlays) and `@drawback/ui` adds `ui` (toolbar, menus, property editors,
16
- * icons) through declaration merging. A view or UI mounted on an editor installs the facets
17
- * of the editor's plugins.
18
- */
13
+ /** Plugin facets other packages add via declaration merging (`canvas`, `ui`). */
19
14
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
20
15
  export interface PluginFacets {}
21
16
 
@@ -97,10 +97,7 @@ export interface PresenceRemoteOptions {
97
97
  readonly showSelections: boolean;
98
98
  readonly showViewports: boolean;
99
99
  readonly showLasers: boolean;
100
- /**
101
- * Milliseconds remote cursors glide to each new position (0 jumps). Matches the default remote
102
- * preview interpolation, so a dragged element and its peer's cursor move together.
103
- */
100
+ /** Ms remote cursors glide to a new position (0 jumps); matches remote preview easing. */
104
101
  readonly cursorInterpolation: number;
105
102
  /** Milliseconds after its last move a remote cursor hides (`undefined` keeps it shown). */
106
103
  readonly cursorIdleTimeout: number | undefined;
@@ -84,11 +84,7 @@ export class SceneIndex {
84
84
  #viewFilter: ((element: ElementRecord) => boolean) | undefined;
85
85
  /** Frames are hit on a screen-sized name label outside their indexed bounds. */
86
86
  readonly #frameIds = new Set<ElementId>();
87
- /**
88
- * Geometry and bounds per record. Records are immutable, so a record is its own cache key;
89
- * anything else they depend on (definitions, style defaults, text layout, fonts, masks)
90
- * rebuilds the scene, which drops the caches.
91
- */
87
+ /** Geometry and bounds keyed by immutable record; other inputs rebuild the scene. */
92
88
  #geometryCache = new WeakMap<ElementRecord, ElementGeometryResult>();
93
89
  #boundsCache = new WeakMap<ElementRecord, Partial<Record<BoundsKind, Box>>>();
94
90
  /** Whole-document results (queries, content bounds) for the current document version. */
@@ -40,10 +40,7 @@ export interface SelectionHandle {
40
40
  readonly index?: number;
41
41
  /** Set on `point` handles whose point is selected in edit mode. */
42
42
  readonly selected?: boolean;
43
- /**
44
- * Side resize handles cover their whole side: the pointer hits anywhere along this segment,
45
- * and renderers draw no knob for them (`position` is the side's midpoint).
46
- */
43
+ /** Side handles cover the whole side; `position` is its midpoint and no knob is drawn. */
47
44
  readonly span?: readonly [Point, Point];
48
45
  }
49
46
 
@@ -157,8 +157,7 @@ const DEFAULT_SETTINGS: SnapSettings = Object.freeze({
157
157
  enabled: true,
158
158
  grid: 'auto',
159
159
  gridTarget: 'auto',
160
- // Off by default like Excalidraw: shapes snap to the grid (while shown) and to anchors, but
161
- // not to other shapes' edges and centers until "Snap to objects" is turned on.
160
+ // Off by default like Excalidraw: only grid and anchors snap until "Snap to objects".
162
161
  objects: false,
163
162
  connectionPoints: true,
164
163
  angleStep: 15,
@@ -53,10 +53,7 @@ export interface StyleSummary {
53
53
  readonly keys: Readonly<Record<StyleKey, StyleValueSummary>>;
54
54
  }
55
55
 
56
- /**
57
- * Known keys take a valid value or `null` (reset to the defaults chain); namespaced
58
- * extension keys take any JSON value or `null` (delete).
59
- */
56
+ /** Known keys take a valid value or `null` (reset); namespaced keys any JSON or `null`. */
60
57
  export type StyleApplyPatch = { readonly [key: string]: JsonValue | null };
61
58
 
62
59
  export interface StyleApplyOptions {
@@ -11,10 +11,7 @@ import type { RecordLookup } from '../permissions/permissions.js';
11
11
  import type { ChangeOperation, ChangeSet, PatchOperation } from '../tx/change-set.js';
12
12
  import type { InteractionPreviewEvent } from '../interactions/interactions.js';
13
13
 
14
- /**
15
- * Rewrites a record before it reaches a viewer. Returning `undefined` hides the record from
16
- * that viewer as if it lacked `core.view`.
17
- */
14
+ /** Rewrites a record for a viewer; `undefined` hides it as if it lacked `core.view`. */
18
15
  export type ProjectionTransform = (
19
16
  record: DocumentRecord,
20
17
  actor: JsonValue | undefined,
@@ -160,10 +160,7 @@ function wrapParagraph(
160
160
  return lines;
161
161
  }
162
162
 
163
- /**
164
- * Lays out plain text. Break decisions use unit widths; final line widths are
165
- * measured on whole lines so they match what the renderer draws.
166
- */
163
+ /** Lays out plain text; widths are measured per whole line to match the renderer. */
167
164
  export function layoutText(
168
165
  text: string,
169
166
  options: TextLayoutOptions,
@@ -73,10 +73,7 @@ export function graphemeSegments(text: string): string[] {
73
73
  return Array.from(graphemes.segment(text), (part) => part.segment);
74
74
  }
75
75
 
76
- /**
77
- * Deterministic measurer for headless editors: widths come from per-script em
78
- * advances, so results are identical on every machine.
79
- */
76
+ /** Headless measurer from per-script em advances: identical results on every machine. */
80
77
  export function createApproximateMeasurer(
81
78
  metricsOf: (family: FontId) => FontMetrics | undefined = () => undefined,
82
79
  ): TextMeasurer {
@@ -118,10 +115,7 @@ export function fontSpecKey(font: FontSpec): string {
118
115
  return `${font.style}|${font.weight}|${font.size}|${font.family}`;
119
116
  }
120
117
 
121
- /**
122
- * Wraps a measurer with a two-generation width cache keyed by font and string: entries
123
- * used since the last rotation survive, so the hot set stays cached in O(1) per lookup.
124
- */
118
+ /** Two-generation width cache by font and string: O(1) lookups that keep the hot set. */
125
119
  export function cachedMeasurer(
126
120
  measurer: TextMeasurer,
127
121
  capacity = 20_000,