@johnoscott/isometric-engine 0.12.3 → 0.12.6

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 (37) hide show
  1. package/EDITOR-GUIDE.md +1 -0
  2. package/README.md +1 -1
  3. package/assets/app.css +6 -0
  4. package/iso-editor.js +165 -165
  5. package/iso-render.js +82 -82
  6. package/iso-systems.js +79 -79
  7. package/js/iso-editor/commands.js +7 -0
  8. package/js/iso-editor/connections.js +24 -0
  9. package/js/iso-editor/model.js +17 -3
  10. package/js/iso-editor/ui/actions.js +22 -24
  11. package/js/iso-editor/ui/canvas.js +92 -12
  12. package/js/iso-editor/ui/mount.js +2 -1
  13. package/js/iso-editor/ui/props.js +2 -2
  14. package/js/iso-editor/ui/rename.js +114 -0
  15. package/js/iso-editor/ui/setup.js +1 -0
  16. package/js/iso-viewer/viewport.js +17 -5
  17. package/package.json +1 -1
  18. package/src/iso-editor/commands.ts +9 -0
  19. package/src/iso-editor/connections.ts +28 -0
  20. package/src/iso-editor/model.ts +17 -3
  21. package/src/iso-editor/ui/actions.ts +20 -23
  22. package/src/iso-editor/ui/app.css +6 -0
  23. package/src/iso-editor/ui/canvas.ts +84 -15
  24. package/src/iso-editor/ui/mount.ts +4 -3
  25. package/src/iso-editor/ui/props.ts +3 -3
  26. package/src/iso-editor/ui/rename.ts +105 -0
  27. package/src/iso-editor/ui/setup.ts +3 -0
  28. package/src/iso-viewer/viewport.ts +25 -5
  29. package/types/iso-editor/connections.d.ts +8 -0
  30. package/types/iso-editor/model.d.ts +8 -2
  31. package/types/iso-editor/ui/actions.d.ts +5 -2
  32. package/types/iso-editor/ui/canvas.d.ts +10 -1
  33. package/types/iso-editor/ui/mount.d.ts +6 -2
  34. package/types/iso-editor/ui/props.d.ts +1 -1
  35. package/types/iso-editor/ui/rename.d.ts +43 -0
  36. package/types/iso-editor/ui/setup.d.ts +2 -0
  37. package/types/iso-viewer/viewport.d.ts +13 -1
@@ -16,6 +16,8 @@ export interface Command {
16
16
  build(text: string): Splice;
17
17
  /** the paths it touched (for the views to refresh and reveal) */
18
18
  touched?: Path[];
19
+ /** (0.12.5) the label of the step it joined (apply's `joins`), given the step's own */
20
+ joined?(label: string): string;
19
21
  /** where a path is after the change (a rename moves paths); null when it no longer exists */
20
22
  remap?(p: Path): Path | null;
21
23
  /** the selection afterwards (default: the old one, remapped) */
@@ -119,8 +121,10 @@ export class EditorModel {
119
121
 
120
122
  // ---------- doing ----------
121
123
 
122
- /** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. */
123
- apply(cmd: Command, origin: Origin = 'api'): boolean {
124
+ /** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. `joins`
125
+ * (0.12.5): the id of an undo step it is part of, when that is the last one, nothing was undone since and the file
126
+ * wasn't saved at it (the saved text must stay a step of its own to come back to). */
127
+ apply(cmd: Command, origin: Origin = 'api', joins?: number): boolean {
124
128
  this.seal();
125
129
  const splice = cmd.build(this._text);
126
130
  if (!splice.steps.some(s => s.length)) return false;
@@ -129,7 +133,15 @@ export class EditorModel {
129
133
  const remap = cmd.remap ?? ((p: Path) => p);
130
134
  this.selection = cmd.select ?? this.selection.map(remap).filter((p): p is Path => p !== null);
131
135
  if (splice.fallback) this.fallbacks++;
132
- this.push({ id: this.nextId++, label: cmd.label, origin, steps: splice.steps, inverse, before, after: { paths: this.selection, text: this.textSel }, time: this.now(), fallback: !!splice.fallback, open: false });
136
+ const top = this.undoStack[this.undoStack.length - 1];
137
+ if (top && joins !== undefined && top.id === joins && !this.redoStack.length && top.id !== this.cleanId) {
138
+ top.label = cmd.joined?.(top.label) ?? top.label;
139
+ top.steps.push(...splice.steps);
140
+ top.inverse.unshift(...inverse);
141
+ top.after = { paths: this.selection, text: this.textSel };
142
+ top.time = this.now();
143
+ top.fallback ||= !!splice.fallback;
144
+ } else this.push({ id: this.nextId++, label: cmd.label, origin, steps: splice.steps, inverse, before, after: { paths: this.selection, text: this.textSel }, time: this.now(), fallback: !!splice.fallback, open: false });
133
145
  this.emit({ kind: 'do', origin, label: cmd.label, steps: splice.steps, version: this._version, remap: cmd.remap });
134
146
  for (const fn of this.selListeners) fn({ paths: this.selection, origin });
135
147
  return true;
@@ -196,6 +208,8 @@ export class EditorModel {
196
208
 
197
209
  get canUndo() { return this.undoStack.length > 0; }
198
210
  get canRedo() { return this.redoStack.length > 0; }
211
+ /** the last undo step's id (what `apply` may join) */
212
+ get undoId() { return this.undoStack[this.undoStack.length - 1]?.id; }
199
213
  get undoLabel() { return this.undoStack[this.undoStack.length - 1]?.label; }
200
214
  get redoLabel() { return this.redoStack[this.redoStack.length - 1]?.label; }
201
215
 
@@ -1,10 +1,11 @@
1
1
  // Actions the canvas and the properties panel share (the tree has its own inline forms of the same commands): delete
2
- // with a references dialog, rename in a dialog, duplicate, select connected. What an object is and how it is named
2
+ // with a references dialog, rename in the inline field, duplicate, select connected. What an object is and how it is named
3
3
  // are the kit's (the domain's commands, objectOf, kinds and name rule); what each kind offers in its own menu is the
4
4
  // domain's too.
5
5
 
6
6
  import { h } from './icons.ts';
7
7
  import { ask } from './dialog.ts';
8
+ import { renameField, type RenameAt } from './rename.ts';
8
9
  import type { EditorModel, Command } from '../model.ts';
9
10
  import type { Commands } from '../commands.ts';
10
11
  import type { ObjectKindInfo, ObjectRef } from '../adapter.ts';
@@ -23,8 +24,8 @@ export interface ActionsKit {
23
24
  nameHint: string;
24
25
  }
25
26
 
26
- export function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void): boolean {
27
- try { return doc.apply(c, origin); } catch (e) { note?.(String((e as Error).message), 'bad'); return false; }
27
+ export function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void, joins?: number): boolean {
28
+ try { return doc.apply(c, origin, joins); } catch (e) { note?.(String((e as Error).message), 'bad'); return false; }
28
29
  }
29
30
 
30
31
  /** Several commands as one undo step. */
@@ -68,26 +69,22 @@ async function deletePaths(doc: EditorModel, paths: Path[], origin: 'canvas' | '
68
69
  return ok;
69
70
  }
70
71
 
71
- /** Rename in a dialog (the canvas has no inline field). */
72
- async function renameDialog(doc: EditorModel, path: Path, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void): Promise<boolean> {
73
- const now = String(path[path.length - 1]);
74
- const input = h('input', { type: 'text', value: now, 'aria-label': 'New name', spellcheck: 'false', autocomplete: 'off', class: 'mono-input' });
75
- input.value = now;
76
- const why = h('p', { class: 'dlg-error', role: 'alert' });
72
+ /** Rename, in the inline field (rename.ts). `joins`: the undo step it becomes part of (an add's, so a drop and its name
73
+ * are one), when that is still the last one. */
74
+ async function rename(doc: EditorModel, path: Path, origin: 'canvas' | 'props' | 'menu', note: ((t: string, tone?: 'bad') => void) | undefined, at: RenameAt & { joins?: number }): Promise<boolean> {
75
+ const now = String(path[path.length - 1]), res = isRes(path);
76
+ let here: Path | null = path;
77
+ const off = doc.on(c => { if (here && c.remap) here = c.remap(here); });
77
78
  const used = () => kit.kinds.flatMap(k => Object.keys((getIn(doc.goodDoc.data, k.section) ?? {}) as Raw));
78
- const check = () => {
79
- const v = input.value.trim();
80
- const bad = !kit.nameRule.test(v) && isRes(path) ? kit.nameHint : v !== now && used().includes(v) ? `"${v}" is already used` : '';
81
- why.textContent = bad;
82
- return bad ? undefined : v;
83
- };
84
- input.addEventListener('input', check);
85
- const go = ask(`Rename ${describe(path)}`, [h('label', { class: 'field' }, h('span', null, 'Name'), input), why, isRes(path) ? h('p', { class: 'sub' }, 'Every reference to it is renamed too.') : ''], [{ label: 'Cancel', value: 'cancel' }, { label: 'Rename', value: 'ok', primary: true }]);
86
- setTimeout(() => { input.focus(); input.select(); }, 0);
87
- if (await go !== 'ok') return false;
88
- const v = check();
89
- if (!v || v === now) return false;
90
- return run(doc, isRes(path) ? renameCmd(path, v) : renameKeyCmd(path, v), origin, note);
79
+ let ok = false;
80
+ await renameField({
81
+ label: `Rename ${describe(path)}`, value: now,
82
+ wrong: v => (!v ? 'A name is needed' : v === now ? '' : res && !kit.nameRule.test(v) ? kit.nameHint : used().includes(v) ? `"${v}" is already used` : ''),
83
+ alive: () => !!here && getIn(doc.goodDoc.data, here) !== undefined,
84
+ commit: v => { if (here) ok = run(doc, { ...(res ? renameCmd(here, v) : renameKeyCmd(here, v)), joined: l => l.replace(` ${now}`, ` ${v}`) }, origin, note, at.joins); },
85
+ }, at);
86
+ off();
87
+ return ok;
91
88
  }
92
89
 
93
90
  const duplicate = (doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void) => {
@@ -114,6 +111,6 @@ function connected(doc: EditorModel, paths: Path[]): Path[] {
114
111
  return [...out.values()];
115
112
  }
116
113
 
117
- return { deletePaths, renameDialog, duplicate, connected };
114
+ return { deletePaths, rename, duplicate, connected };
118
115
  }
119
116
  export type Actions = ReturnType<typeof actionsFor>;
@@ -95,6 +95,12 @@ body[data-view="text"] .status .hint-mode { display: none; }
95
95
  .chip-add { width: auto !important; min-width: 80px; }
96
96
  .props-delete { margin-top: var(--sp-4); align-self: flex-start; }
97
97
  .mono-input { font-family: var(--mono); }
98
+ .rename-field { position: fixed; z-index: var(--z-menu); }
99
+ .rename-field > .rename-input { display: block; width: auto; max-width: calc(100vw - 16px); height: 26px; min-height: 26px; padding: 0 var(--sp-2); font-family: var(--mono); font-size: var(--fs-mono); text-align: center; box-shadow: var(--shadow-3); }
100
+ .rename-field.over > .rename-input { text-align: left; }
101
+ .rename-field > .rename-input[aria-invalid="true"] { border-color: var(--bad); }
102
+ .rename-field > .rename-error { position: absolute; top: 100%; left: 50%; translate: -50% 4px; width: max-content; max-width: 280px; margin: 0; padding: var(--sp-1) var(--sp-2); background: var(--surface); border: var(--bw) solid var(--bad); border-radius: var(--r-md); color: var(--bad); font-size: var(--fs-sm); line-height: 1.35; box-shadow: var(--shadow-2); }
103
+ .rename-field > .rename-error:empty { display: none; }
98
104
  #se-grip { height: 6px; margin: -3px 0; cursor: row-resize; z-index: 2; position: relative; }
99
105
  #se-grip:hover, #se-grip:focus-visible { background: color-mix(in srgb, var(--accent) 30%, transparent); }
100
106
  #se-problems { height: var(--problems-h, 160px); flex: none; overflow: auto; border-top: var(--bw) solid var(--line); background: var(--bg); font-size: var(--fs-sm); }
@@ -14,6 +14,7 @@
14
14
  import { h, icon, type IconName } from './icons.ts';
15
15
  import { openMenu, type MenuItem } from './menu.ts';
16
16
  import { run, type Actions } from './actions.ts';
17
+ import { connectionsOf, nearestOn } from '../connections.ts';
17
18
  import { screenToGrid, localAt, boxSilhouette, floorOf, snapMove, overlaps, paddingOf, type Move } from '../../iso-objects/geometry.ts';
18
19
  import { regionKind, type KindCatalog } from '../../iso-objects/kinds.ts';
19
20
  import type { CompiledScene } from '../../iso-objects/compile.ts';
@@ -81,6 +82,8 @@ export interface CanvasUi {
81
82
  * its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
82
83
  * width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
83
84
  paletteLayout?: 'floating' | 'docked';
85
+ /** (0.12.5) what a double click on an object does: shows it in the text (the default), or renames it */
86
+ doubleClick?: 'text' | 'rename';
84
87
  text: {
85
88
  stage: string; dragGroup: string; dragSelectTip: string; unreadable: string; palette: string;
86
89
  /** the end of a pin drag's hint */
@@ -151,7 +154,7 @@ const SVGNS = 'http://www.w3.org/2000/svg';
151
154
  export function canvasView<M, D extends CanvasDrawing, A extends object = object>(host: HTMLElement, doc: EditorModel, opts: CanvasOpts<M, D, A>) {
152
155
  const K = opts.kit, ui = K.ui, T = ui.text;
153
156
  const { setCmd, deleteCmd, insertCmd, insertItemCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
154
- const { deletePaths, renameDialog, duplicate, connected } = K.actions;
157
+ const { deletePaths, duplicate, connected } = K.actions;
155
158
  const resourceOf = (ptr: string) => K.objectOf(ptr);
156
159
  const kindOf = (k: string) => K.kinds.find(x => x.kind === k)!;
157
160
  const PINS_KEY = K.pins.key;
@@ -237,7 +240,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
237
240
  if (!s3) { showEmpty(T.unreadable); return; }
238
241
  const key = JSON.stringify(data);
239
242
  // nothing new to draw: repaint the marks, unless a drag is showing its grid (it repaints when it ends)
240
- if (key === lastKey && svg) { if (!pinDrag()) paintOverlay(); return; }
243
+ if (key === lastKey && svg) { if (!pinDrag()) paintOverlay(); if (toFit) { toFit = false; fitItems(); } return; }
241
244
  if (mode === '2d' && !flatImpl) {
242
245
  try { await loadFlat(); } catch (e) { mode = '3d'; paintNav(); opts.note(`The 2D view couldn't load: ${(e as Error).message}`, 'warn'); }
243
246
  }
@@ -250,6 +253,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
250
253
  await draw(next);
251
254
  if (cd!.pinNotes.length) opts.note(`Pins: ${cd!.pinNotes.join('; ')}`, 'warn');
252
255
  }
256
+ let toFit = false; // (0.12.5) the next drawing is another document's: fitted
253
257
  let lastS3: M | undefined, lastData: unknown, pendingAfterDrag = false;
254
258
  // ---------- the switch's morph (0.7.5): the 2D view's implementation runs it, over the stage ----------
255
259
  let morphFrom: { svg: SVGSVGElement; mode: '3d' | '2d' } | undefined;
@@ -308,7 +312,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
308
312
  svg = s;
309
313
  const [x, y, w, hh] = full;
310
314
  V.full = { x, y, w, h: hh };
311
- if (!V.view) { V.view = { ...V.full }; autoFit(); } else quietly(applyView);
315
+ if (toFit) { toFit = false; V.view = { ...V.full }; fitItems(); } else if (!V.view) { V.view = { ...V.full }; autoFit(); } else quietly(applyView);
312
316
  empty.hidden = true;
313
317
  layer?.drawn?.();
314
318
  if (pendingReveal && reveal(pendingReveal)) pendingReveal = undefined;
@@ -336,6 +340,12 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
336
340
  const live = layer?.extent?.() ?? [];
337
341
  return union([...ptrs.flatMap(p => elementsFor(p)).filter(e => e.getBBox().width || e.getBBox().height).map(boxOf), ...live]);
338
342
  }
343
+ /** (0.12.6) the connectors and their labels (not a step's marks on them, which a still doesn't show): Fit keeps them on the stage */
344
+ function routesBox() {
345
+ if (!cd || !svg) return undefined;
346
+ const els = Object.keys(cd.scene.rendered.paths).flatMap(id => [...svg!.querySelectorAll<SVGGraphicsElement>(`[data-id="${CSS.escape(id)}"], [data-hl="${CSS.escape(id)}"], [data-for="${CSS.escape(id)}"]`)]).filter(e => !e.closest('.pre, .overlay, .g-marks, .g-badges, .g-anim'));
347
+ return union(els.filter(e => e.getBBox().width || e.getBBox().height).map(boxOf));
348
+ }
339
349
  // (0.12.1) the view is the stage's: docked, the palette's pane shares the host, so the host is wider than what is
340
350
  // drawn (the scale, the pointer's place, a resize); floating, the stage is the host's whole area
341
351
  const docked = ui.paletteLayout === 'docked';
@@ -350,6 +360,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
350
360
  },
351
361
  onRezoom: () => paintOverlay(),
352
362
  itemsBox: () => itemsBox(),
363
+ alsoBox: () => routesBox(),
353
364
  marksShowing: () => !!layer?.showing?.(),
354
365
  });
355
366
  const { size, scale, quietly, applyView, toSvg, zoomAt, fit, fitItems, autoFit, actual, settled } = V;
@@ -399,6 +410,37 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
399
410
  return undefined;
400
411
  };
401
412
 
413
+ // (0.12.4) connections: the routes that are entries of the file's own (src/iso-editor/connections.ts)
414
+ const isRouteId = (id: string) => !!cd && Object.hasOwn(cd.scene.rendered.paths, id);
415
+ const connections = () => (cd ? connectionsOf(cd.pathOf, isRouteId, K.objectOf) : new Map<string, string>());
416
+ /** how near a connection, in the page's pixels, is on it */
417
+ const NEAR = 6;
418
+ /** the drawn thing under a place on the page: a connection within NEAR of it, unless a node is there (a node's always the
419
+ * one meant; a region's floor, or nothing, gives way) or a node hides that part of the connection */
420
+ const pathAt = (target: EventTarget | null, px: number, py: number): string | undefined => {
421
+ const direct = pathAtEvent(target);
422
+ const isNode = (el: Element | null): boolean => {
423
+ const id = el?.closest?.('[data-id]')?.getAttribute('data-id');
424
+ if (!id || !cd || isRouteId(id)) return false;
425
+ if (flat) { const q = toSvg(px, py); return !flat.panelsAt(q.x, q.y).includes(id) && cd.scene.layout.byId.has(id); }
426
+ return cd.scene.layout.byId.get(id)?.type === 'node';
427
+ };
428
+ const el = target as Element | null;
429
+ if (!cd || !svg || !el?.closest || (el !== svg && !svg.contains(el) && el !== stage) || isNode(el)) return direct;
430
+ const conns = connections();
431
+ if (!conns.size || (direct !== undefined && conns.has(direct))) return direct;
432
+ const at = toSvg(px, py), k = scale(), r = viewEl.getBoundingClientRect();
433
+ let best: { ptr: string; dist: number } | undefined;
434
+ for (const ptr of conns.keys()) for (const sh of outlinesFor(ptr)) {
435
+ if (sh.kind !== 'route') continue;
436
+ const q = nearestOn(sh.d, at.x, at.y);
437
+ if (!q || q.dist * k > NEAR || (best && q.dist >= best.dist)) continue;
438
+ if (isNode(fdoc().elementFromPoint(r.left + (q.x - V.view!.x) * k, r.top + (q.y - V.view!.y) * k))) continue;
439
+ best = { ptr, dist: q.dist };
440
+ }
441
+ return best ? best.ptr : direct;
442
+ };
443
+
402
444
  // ---------- the overlay: selection rings, hover, problem badges ----------
403
445
  /**
404
446
  * A resource's drawn shapes, isometric: a node (or a slab, a VM, a platform) is the silhouette of its box (the hexagon
@@ -538,7 +580,13 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
538
580
  stage.addEventListener('pointercancel', up);
539
581
  stage.addEventListener('wheel', wheel, { passive: false });
540
582
  stage.addEventListener('contextmenu', context);
541
- stage.addEventListener('dblclick', e => { const p = pathAtEvent(e.target); if (p !== undefined) opts.showInText(fromPointer(p)); });
583
+ stage.addEventListener('dblclick', e => {
584
+ // (0.12.5) what is under the pointer: the presses were captured, so a real double click's target is the stage
585
+ const p = pathAt(e.target === stage ? fdoc().elementFromPoint(e.clientX, e.clientY) : e.target, e.clientX, e.clientY);
586
+ if (p === undefined) return;
587
+ if (ui.doubleClick === 'rename' && doc.doc.ok && resourceOf(p)?.path === p) rename(fromPointer(p));
588
+ else opts.showInText(fromPointer(p));
589
+ });
542
590
  };
543
591
  // in the page, a pointer's coordinates are already the page's
544
592
  const pageXY = (e: PointerEvent | MouseEvent) => ({ x: e.clientX, y: e.clientY });
@@ -559,7 +607,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
559
607
  const pan = () => { drag = { kind: 'pan', x0: x, y0: y, v0: { ...V.view! } }; svg?.classList.add('panning'); e.preventDefault(); };
560
608
  if (e.button === 1 || spaceKeyDown) { pan(); return; }
561
609
  if (e.button !== 0) return;
562
- const ptr = pathAtEvent(e.target);
610
+ const ptr = pathAt(e.target, x, y);
563
611
  if (ptr === undefined) {
564
612
  // nothing under the pointer: Pan mode pans (⇧ or ⌘ draws a selection instead); Select mode draws a selection (the space key pans)
565
613
  const mod = e.shiftKey || e.metaKey || e.ctrlKey;
@@ -606,7 +654,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
606
654
  return;
607
655
  }
608
656
  if (!drag) {
609
- const p = pathAtEvent(e.target);
657
+ const p = pathAt(e.target, x, y);
610
658
  if (p !== hoverId) { hoverId = p; paintOverlay(); }
611
659
  return;
612
660
  }
@@ -787,7 +835,14 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
787
835
  }
788
836
  }
789
837
  /** end a pin drag: the drop commits one command; an overlap, a cancel or no move puts the drawing back */
838
+ /** drops whose pin isn't written yet (the grid fading out first) */
839
+ let dropping = 0;
790
840
  async function endPin(commit: boolean) {
841
+ if (!pinDrag()) return;
842
+ dropping++;
843
+ try { await endDrop(commit); } finally { dropping--; }
844
+ }
845
+ async function endDrop(commit: boolean) {
791
846
  const g = pinDrag();
792
847
  if (!g) return;
793
848
  drag = undefined;
@@ -876,7 +931,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
876
931
  e.preventDefault();
877
932
  const { x, y } = pageXY(e);
878
933
  if (layer?.context?.(e, { x, y })) return;
879
- const ptr = pathAtEvent(e.target);
934
+ const ptr = pathAt(e.target, x, y);
880
935
  if (ptr !== undefined && !doc.selection.some(p => toPointer(p) === ptr)) doc.select([fromPointer(ptr)], 'canvas');
881
936
  openMenu(menuItems(ptr), { x, y }, 'Canvas');
882
937
  }
@@ -897,7 +952,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
897
952
  if (one) {
898
953
  items.push(...K.objectItems(doc, one, 'canvas', opts.note));
899
954
  if (items.length) items.push({ sep: true });
900
- items.push({ label: 'Rename…', icon: 'pencil', keys: 'F2', disabled: ro || !isRes, why: T.renameWhy, onSelect: () => renameDialog(doc, one, 'canvas', opts.note) });
955
+ items.push({ label: 'Rename…', icon: 'pencil', keys: 'F2', disabled: ro || !isRes, why: T.renameWhy, onSelect: () => rename(one) });
901
956
  items.push({ label: 'Duplicate', icon: 'copy', keys: '⌘D', disabled: ro || !isRes, why: T.duplicateWhy, onSelect: () => duplicate(doc, one, 'canvas', opts.note) });
902
957
  const name = isRes ? resourceOf(toPointer(one))!.name : '';
903
958
  const pinned = !!K.pins.of(doc.goodDoc.data)?.[name];
@@ -982,7 +1037,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
982
1037
  const p = [...k.section, name];
983
1038
  if (run(doc, insertCmd(p.slice(0, -1), name, k.template(), { label: `Add ${k.singular} ${name}` }), 'canvas', opts.note)) {
984
1039
  doc.select([p], 'canvas');
985
- renameDialog(doc, p, 'canvas', opts.note);
1040
+ rename(p, { joins: doc.undoId });
986
1041
  }
987
1042
  }
988
1043
  // ---------- E11: the palette: add a resource by a click, or by a drag onto the canvas ----------
@@ -1085,9 +1140,8 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1085
1140
  if (!run(doc, { ...cmd, select: [p] }, 'canvas', opts.note)) return undefined;
1086
1141
  if (at && !into && !pin) opts.note(mode === '2d' ? `${k.singular} ${name} added; the layout placed it (in 3D a drop pins it where it lands)` : `${k.singular} ${name} added; that spot is taken, so the layout placed it`);
1087
1142
  doc.select([p], 'canvas');
1088
- // (0.10.1) the canvas has the focus while the name is asked, so the dialog gives it back there (⌘Z works at once)
1089
- stage.focus({ preventScroll: true });
1090
- renameDialog(doc, p, 'canvas', opts.note);
1143
+ // (0.12.5) its name, in the inline field above it; the drop and the name are one undo step
1144
+ rename(p, { joins: doc.undoId, at });
1091
1145
  return p;
1092
1146
  }
1093
1147
  const palette = h('div', { class: 'palette', role: 'toolbar', 'aria-label': T.palette, 'aria-orientation': 'vertical' });
@@ -1239,6 +1293,20 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1239
1293
  const only = x && Object.keys(x).length === 1;
1240
1294
  run(doc, { ...deleteCmd(only ? [key] : [key, 'layout']), label: 'Reset the layout' }, 'canvas', opts.note);
1241
1295
  }
1296
+ /** (0.12.5) name it, in the inline field above its drawing; Enter and Esc give the canvas the focus back (⌘Z works at once) */
1297
+ function rename(p: Path, o: { joins?: number; at?: { x: number; y: number } } = {}) {
1298
+ let path: Path | null = p;
1299
+ const off = doc.on(c => { if (path && c.remap) path = c.remap(path); });
1300
+ void K.actions.rename(doc, p, 'canvas', opts.note, {
1301
+ ...o, back: stage, late: stage, busy: () => !!drag || dropping > 0, bounds: () => stage.getBoundingClientRect(),
1302
+ place: () => {
1303
+ const b = path && V.view ? boxFor(path) : undefined;
1304
+ if (!b) return undefined;
1305
+ const r = viewEl.getBoundingClientRect(), k = scale();
1306
+ return { left: r.left + (b.x - V.view!.x) * k, top: r.top + (b.y - V.view!.y) * k, width: b.w * k, height: b.h * k };
1307
+ },
1308
+ }).finally(off);
1309
+ }
1242
1310
  function selectParent() {
1243
1311
  const up = new Map<string, Path>();
1244
1312
  for (const p of doc.selection) {
@@ -1269,10 +1337,11 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1269
1337
  case '@': case '2': if (e.shiftKey || e.key === '@') zoomToSelection(); else return; break;
1270
1338
  case 'Escape': if (linking) { linking = undefined; paintOverlay(); opts.note('Not connected'); break; } if (pinDrag()) { endPin(false); break; } doc.select([], 'canvas'); break;
1271
1339
  case 'Delete': case 'Backspace': if (sel.length && !ro) deletePaths(doc, sel, 'canvas', opts.note); break;
1272
- case 'F2': if (sel.length === 1 && !ro) renameDialog(doc, sel[0], 'canvas', opts.note); break;
1340
+ case 'F2': if (sel.length === 1 && !ro) rename(sel[0]); break;
1273
1341
  case 'ArrowUp': if (mod) { selectParent(); break; } return;
1274
1342
  case 'Tab': case 'ArrowRight': case 'ArrowLeft': case 'ArrowDown': {
1275
- // move through what is drawn, in the file's order
1343
+ // move through what is drawn, in the file's order: the objects, then (0.12.4) the connections
1344
+ drawn.push(...connections().keys());
1276
1345
  if (!drawn.length) return;
1277
1346
  const i = sel.length ? drawn.indexOf(toPointer(sel[0])) : -1;
1278
1347
  const back = e.key === 'ArrowLeft' || (e.key === 'Tab' && e.shiftKey);
@@ -1330,7 +1399,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1330
1399
 
1331
1400
  const base = {
1332
1401
  addFromPalette, palette, groupSelection, startPick, objectsUnder, get linking() { return linking; },
1333
- render, setTheme, paintOverlay, fit: fitItems, fitAll: fit, actual, zoomAt, itemsBox, get moved() { return V.moved; }, settled, get zoom() { return V.zoom; },
1402
+ render, setTheme, paintOverlay, fit: fitItems, fitNext() { toFit = true; }, fitAll: fit, actual, zoomAt, itemsBox, routesBox, get moved() { return V.moved; }, settled, get zoom() { return V.zoom; },
1334
1403
  dispose() { endMorph(); clearTimeout(relayout); V.dispose(); disposed = true; },
1335
1404
  focus: () => stage.focus(),
1336
1405
  /** for the tests */
@@ -69,7 +69,7 @@ export interface ShellFeatures {
69
69
  plan?: { planPanel(el: HTMLElement, o: { has(name: string): boolean; select(name: string): boolean }): { paint(extra: unknown, has: boolean): void } };
70
70
  }
71
71
  /** what the shell calls on a canvas */
72
- export interface ShellCanvas { render(model: unknown, data: unknown): Promise<void>; setTheme(t: 'light' | 'dark'): void; fit(): void; focus(): void; dispose(): void }
72
+ export interface ShellCanvas { render(model: unknown, data: unknown): Promise<void>; setTheme(t: 'light' | 'dark'): void; fit(): void; /** (0.12.5) the next drawing is fitted, whatever the person did with the view before */ fitNext?(): void; focus(): void; dispose(): void }
73
73
  /** what the domain gives the mounted editor */
74
74
  export interface EditorSetup<R, X, A extends object> {
75
75
  kit: MountKit<R, X>;
@@ -184,7 +184,8 @@ export interface EditorState<R = unknown, X = unknown> {
184
184
  checks: number;
185
185
  }
186
186
  export interface Editor {
187
- getText(): string; setText(text: string): void; setReadOnly(ro: boolean): void; setTheme(t: Theme): void;
187
+ /** `fit` (0.12.5): it is another document, so its drawing is fitted once drawn (default: the view stays where it is) */
188
+ getText(): string; setText(text: string, o?: { fit?: boolean }): void; setReadOnly(ro: boolean): void; setTheme(t: Theme): void;
188
189
  addFeatures(names: readonly string[]): Promise<void>; fit(): void; dispose(): void;
189
190
  }
190
191
 
@@ -651,7 +652,7 @@ export function mountEditor<R, X, A extends object = object>(el: HTMLElement, op
651
652
  return {
652
653
  internal,
653
654
  getText: () => doc.text,
654
- setText(text: string) { hideBanner(); doc.load(text); doc.markClean(); paintTitle(); paintHistory(); },
655
+ setText(text: string, o: { fit?: boolean } = {}) { hideBanner(); if (o.fit && !disposed) canvas.fitNext?.(); doc.load(text); doc.markClean(); paintTitle(); paintHistory(); },
655
656
  setReadOnly,
656
657
  setTheme,
657
658
  addFeatures,
@@ -38,7 +38,7 @@ export interface PropsUi {
38
38
  /** what the panel is given of the domain */
39
39
  export interface PropsKit {
40
40
  commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertItemCmd' | 'referencesTo' | 'describe'>;
41
- actions: Pick<Actions, 'deletePaths' | 'renameDialog'>;
41
+ actions: Pick<Actions, 'deletePaths' | 'rename'>;
42
42
  slotAt(ptr: string): RefSlot | undefined;
43
43
  objectOf(ptr: string): ObjectRef | undefined;
44
44
  kinds: ObjectKindInfo[];
@@ -67,7 +67,7 @@ export function propsPanel(body: HTMLElement, doc: EditorModel, opts: PropsOpts)
67
67
  let focusInput = false;
68
68
  const K = opts.kit, ui = K.ui;
69
69
  const { setCmd, deleteCmd, insertItemCmd, referencesTo, describe } = K.commands;
70
- const { deletePaths, renameDialog } = K.actions;
70
+ const { deletePaths, rename } = K.actions;
71
71
  const kindOf = (k: string) => K.kinds.find(x => x.kind === k);
72
72
  const singular = (k: string) => kindOf(k)?.singular ?? 'item';
73
73
 
@@ -101,7 +101,7 @@ export function propsPanel(body: HTMLElement, doc: EditorModel, opts: PropsOpts)
101
101
  if (!r) { settings(p); return; }
102
102
  const head = h('div', { class: 'sel-headrow' }, h('div', { class: 'sel-title' }, describe(target)));
103
103
  const rn = h('button', { type: 'button', class: 'btn sm quiet icon-only', 'aria-label': `Rename ${describe(target)}`, title: 'Rename (F2)' }, icon('pencil'));
104
- rn.addEventListener('click', () => renameDialog(doc, target, 'props', opts.note));
104
+ rn.addEventListener('click', () => void rename(doc, target, 'props', opts.note, { over: true, place: () => (head.isConnected ? head.firstElementChild!.getBoundingClientRect() : undefined) }));
105
105
  head.append(rn);
106
106
  body.append(head);
107
107
  if (toPointer(p) !== r.path) pendingFocus = toPointer(p);
@@ -0,0 +1,105 @@
1
+ // The inline name field (0.12.5): a small text field just above a thing (on the canvas it follows the thing through pan and
2
+ // zoom), the name selected, so typing replaces it. Nothing modal: no backdrop, and what is under it stays live. Enter commits, and so
3
+ // does a press anywhere else or the focus going elsewhere, when the name is a good one (a bad one is dropped, the name as
4
+ // it was); Esc dismisses. What is wrong with a name shows under the field, and Enter then does nothing.
5
+
6
+ import { h } from './icons.ts';
7
+ import { layer } from './layer.ts';
8
+
9
+ export interface RenameAt {
10
+ /** where the thing is on the page now (asked each frame while the field is open); undefined: not drawn */
11
+ place(): { left: number; top: number; width: number; height: number } | undefined;
12
+ /** over the thing's own words, from their left edge (a heading), not above it */
13
+ over?: boolean;
14
+ /** what the field stays inside, on the page (default: the window) */
15
+ bounds?(): { left: number; top: number; right: number; bottom: number };
16
+ /** where it is until the thing is drawn */
17
+ at?: { x: number; y: number };
18
+ /** a press in here saves the name once it is released (the press may be on the thing itself, or drag it: it goes by the
19
+ * name it has); anywhere else at once, before what was pressed acts (Save, Undo) */
20
+ late?: HTMLElement;
21
+ /** what such a press started (a drag of the thing) isn't over yet: the name waits for it */
22
+ busy?(): boolean;
23
+ /** what has the focus after Enter or Esc (default: what had it) */
24
+ back?: HTMLElement;
25
+ }
26
+ export interface RenameField {
27
+ label: string;
28
+ value: string;
29
+ /** what is wrong with a name ('' : nothing) */
30
+ wrong(v: string): string;
31
+ /** Enter on a good name that isn't the one there */
32
+ commit(v: string): void;
33
+ /** false: the thing is gone, and the field with it */
34
+ alive?(): boolean;
35
+ }
36
+
37
+ let open: { close(): void } | undefined;
38
+ export const renameOpen = () => !!open;
39
+
40
+ /** Open the field; resolves with the name committed, or undefined when dismissed. */
41
+ export function renameField(f: RenameField, at: RenameAt): Promise<string | undefined> {
42
+ open?.close();
43
+ return new Promise(resolve => {
44
+ const back = at.back ?? (document.activeElement as HTMLElement | null);
45
+ const id = `rename-${Math.random().toString(36).slice(2, 8)}`;
46
+ const input = h('input', { type: 'text', class: 'rename-input', 'aria-label': f.label, 'aria-describedby': id, spellcheck: 'false', autocomplete: 'off', autocapitalize: 'off' });
47
+ const why = h('p', { class: 'rename-error', role: 'alert', id });
48
+ const box = h('div', { class: `rename-field${at.over ? ' over' : ''}` }, input, why);
49
+ input.value = f.value;
50
+ const fitWidth = () => { input.size = Math.max(8, Math.min(40, input.value.length + 1)); };
51
+ fitWidth();
52
+ layer().append(box);
53
+ let done = false, frame = 0, seen = at.at ? { left: at.at.x, top: at.at.y, width: 0, height: 0 } : undefined;
54
+ const put = () => {
55
+ const p = at.place();
56
+ if (p) seen = p;
57
+ const b = at.bounds?.() ?? { left: 0, top: 0, right: innerWidth, bottom: innerHeight }, r = input.getBoundingClientRect();
58
+ const t = seen ?? { left: (b.left + b.right) / 2, top: b.top + 48, width: 0, height: 0 };
59
+ const within = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
60
+ box.style.left = `${within(at.over ? t.left - 8 : t.left + t.width / 2 - r.width / 2, b.left + 4, b.right - r.width - 4)}px`;
61
+ box.style.top = `${within(at.over ? t.top + t.height / 2 - r.height / 2 : t.top - r.height - 8, b.top + 4, b.bottom - r.height - 4)}px`;
62
+ };
63
+ const follow = () => { if (done) return; if (f.alive && !f.alive()) { end(undefined, false); return; } put(); frame = requestAnimationFrame(follow); };
64
+ const check = () => {
65
+ const bad = f.wrong(input.value.trim());
66
+ why.textContent = bad;
67
+ input.setAttribute('aria-invalid', String(!!bad));
68
+ return bad;
69
+ };
70
+ /** the name to save: a good one that isn't the one there */
71
+ const good = () => { const v = input.value.trim(); return v !== f.value && !f.wrong(v) ? v : undefined; };
72
+ function end(v: string | undefined, focusBack: boolean, late = false) {
73
+ if (done) return;
74
+ done = true;
75
+ cancelAnimationFrame(frame);
76
+ removeEventListener('pointerdown', outside, true);
77
+ box.remove();
78
+ open = undefined;
79
+ if (focusBack && back?.isConnected) back.focus({ preventScroll: true });
80
+ const save = () => { if (v !== undefined && (!f.alive || f.alive())) f.commit(v); resolve(v); };
81
+ if (!late || v === undefined) { save(); return; }
82
+ const up = () => { removeEventListener('pointerup', up, true); removeEventListener('pointercancel', up, true); setTimeout(wait, 0); };
83
+ const wait = () => { if (at.busy?.()) setTimeout(wait, 20); else save(); };
84
+ addEventListener('pointerup', up, true); addEventListener('pointercancel', up, true);
85
+ }
86
+ const outside = (e: Event) => { if (!box.contains(e.target as Node)) end(good(), false, !!at.late?.contains(e.target as Node)); };
87
+ addEventListener('pointerdown', outside, true);
88
+ input.addEventListener('input', () => { fitWidth(); check(); });
89
+ input.addEventListener('keydown', e => {
90
+ // ⌘S saves the file, with the name
91
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 's') { end(good(), true); return; }
92
+ e.stopPropagation(); // the keys are the field's: ⌘Z, Delete and the arrows never reach the canvas
93
+ if (e.isComposing) return;
94
+ if (e.key === 'Escape') { e.preventDefault(); end(undefined, true); }
95
+ if (e.key === 'Enter') { e.preventDefault(); const v = input.value.trim(); if (!check()) end(v === f.value ? undefined : v, true); }
96
+ });
97
+ input.addEventListener('keyup', e => e.stopPropagation());
98
+ // the focus gone elsewhere in the page (not with the window: coming back, the field is as it was)
99
+ input.addEventListener('blur', () => setTimeout(() => { if (!done && document.hasFocus() && document.activeElement !== input && document.activeElement !== document.body) end(good(), false); }, 0));
100
+ open = { close: () => end(undefined, false) };
101
+ follow();
102
+ input.focus({ preventScroll: true });
103
+ input.select();
104
+ });
105
+ }
@@ -56,6 +56,8 @@ export interface DomainView<R, D extends CanvasDrawing> {
56
56
  /** (0.12.0) the palette 'floating' over the canvas (the default) or 'docked': a pane of its own at the canvas's left,
57
57
  * searchable by label and section, resizable and collapsible */
58
58
  paletteLayout?: 'floating' | 'docked';
59
+ /** (0.12.5) what a double click on an object of the canvas does: shows it in the text (the default), or renames it */
60
+ doubleClick?: 'text' | 'rename';
59
61
  /** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
60
62
  flat?: CanvasKit<R, D>['flat'];
61
63
  /** a layer over the canvas, and a part beside the views (A: their calls) */
@@ -112,6 +114,7 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
112
114
  ? v.palette.map(e => ({ kind: e.kind, label: e.label, icon: (e.icon ?? icon(e.kind)) as IconName, name: e.name, ...(e.section === undefined ? {} : { section: e.section }), ...(e.value === undefined ? {} : { value: () => structuredClone(e.value) }) }))
113
115
  : a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
114
116
  ...(v.paletteLayout === undefined ? {} : { paletteLayout: v.paletteLayout }),
117
+ ...(v.doubleClick === undefined ? {} : { doubleClick: v.doubleClick }),
115
118
  text: {
116
119
  stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
117
120
  dragSelectTip: 'Drag draws a selection; hold the space key to pan', unreadable: 'The canvas draws a file that reads cleanly; fix the problems listed to see it.',
@@ -6,6 +6,24 @@
6
6
  // Moved here from the editor canvas (R1 S4); the canvas owns the drawing, the overlay and the pointer.
7
7
 
8
8
  export type View = { x: number; y: number; w: number; h: number };
9
+ /** (0.12.6) how far inside the stage what must be on it is, px */
10
+ const INSET = 6;
11
+ /** What a fit makes of a stage (px) and what it frames, `box` PAD px inside it, and what must be on it too, `also` INSET px inside:
12
+ * the zoom and the middle. Pure. */
13
+ export function fitted(s: { w: number; h: number }, box: View, also?: View): { k: number; cx: number; cy: number } {
14
+ const pad = 24;
15
+ // along one axis: the most zoom that `box`, and `also`, and the one's end and the other's together, allow
16
+ const most = (len: number, a0: number, a1: number, b0?: number, b1?: number) => Math.min((len - pad * 2) / (a1 - a0), ...(b0 === undefined || b1 === undefined ? [] : [[b1 - b0, INSET * 2], [b1 - a0, pad + INSET], [a1 - b0, pad + INSET]].map(([d, edges]) => (d > 0 ? (len - edges) / d : Infinity))));
17
+ const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min(most(s.w, box.x, box.x + box.w, also?.x, also && also.x + also.w), most(s.h, box.y, box.y + box.h, also?.y, also && also.y + also.h))));
18
+ // the middle of `box`, moved only as far as `also` needs
19
+ const middle = (len: number, a0: number, a1: number, b0?: number, b1?: number) => {
20
+ const c = (a0 + a1) / 2;
21
+ if (b0 === undefined || b1 === undefined) return c;
22
+ const lo = b1 - (len / 2 - INSET) / k, hi = b0 + (len / 2 - INSET) / k;
23
+ return lo > hi ? (lo + hi) / 2 : Math.max(lo, Math.min(hi, c));
24
+ };
25
+ return { k, cx: middle(s.w, box.x, box.x + box.w, also?.x, also && also.x + also.w), cy: middle(s.h, box.y, box.y + box.h, also?.y, also && also.y + also.h) };
26
+ }
9
27
  export const MIN_ZOOM = 0.1, MAX_ZOOM = 8;
10
28
 
11
29
  export interface ViewportOpts {
@@ -17,6 +35,8 @@ export interface ViewportOpts {
17
35
  onRezoom(): void;
18
36
  /** what a fit frames (the drawing's own things, the overlay's shown marks), if not the whole scene */
19
37
  itemsBox(): View | undefined;
38
+ /** (0.12.6) what must be on the stage too when the things are fitted (the connectors), a few px from its edges */
39
+ alsoBox?(): View | undefined;
20
40
  /** the overlay has marks that keep their size on screen (a fit repeats while they are showing) */
21
41
  marksShowing(): boolean;
22
42
  }
@@ -59,11 +79,11 @@ export function viewport(host: HTMLElement, o: ViewportOpts) {
59
79
  view = { x: p.x - (px - r.left) / nk, y: p.y - (py - r.top) / nk, w: s.w / nk, h: s.h / nk };
60
80
  applyView();
61
81
  }
62
- function fit(box = full) {
82
+ /** `also` (0.12.6): what must be on the stage too, INSET px from its edges, and nothing more: the zoom and the middle change only as
83
+ * much as that takes (not at all where it is inside already) */
84
+ function fit(box = full, also?: View) {
63
85
  if (!box) return;
64
- const s = size(), pad = 24;
65
- const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min((s.w - pad * 2) / box.w, (s.h - pad * 2) / box.h)));
66
- const cx = box.x + box.w / 2, cy = box.y + box.h / 2;
86
+ const s = size(), { k, cx, cy } = fitted(s, box, also);
67
87
  const next = { x: cx - s.w / k / 2, y: cy - s.h / k / 2, w: s.w / k, h: s.h / k };
68
88
  // v0.4.2: a fit that lands where the view already is (a refit after a resize that changed nothing it fits) leaves
69
89
  // it alone: no new zoom by a rounding error, so nothing on the overlay is redrawn
@@ -82,7 +102,7 @@ export function viewport(host: HTMLElement, o: ViewportOpts) {
82
102
  if (key === last) break;
83
103
  last = key;
84
104
  const m = Math.max(24, Math.min(b.w, b.h) * 0.06);
85
- quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }));
105
+ quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }, o.alsoBox?.()));
86
106
  // the marks are redrawn for a new zoom only past the same 2% the zoom itself uses (applyView's rezoom)
87
107
  if (!o.marksShowing() || !paintedK || Math.abs(scale() / paintedK - 1) <= 0.02) break;
88
108
  cancelAnimationFrame(rezoom); rezoom = 0;
@@ -0,0 +1,8 @@
1
+ /** path → route id, in the file's order as the drawing maps it */
2
+ export declare function connectionsOf(pathOf: ReadonlyMap<string, string>, isRoute: (id: string) => boolean, objectOf: (ptr: string) => unknown): Map<string, string>;
3
+ /** the nearest point of a polyline path ("M x,y L x,y …", the numbers taken in pairs) to a point */
4
+ export declare function nearestOn(d: string, x: number, y: number): {
5
+ x: number;
6
+ y: number;
7
+ dist: number;
8
+ } | undefined;