@johnoscott/isometric-engine 0.12.6 → 0.14.1
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.
- package/EDITOR-GUIDE.md +9 -2
- package/README.md +1 -1
- package/assets/app.css +6 -0
- package/assets/marks.css +2 -0
- package/iso-editor.js +188 -187
- package/js/iso-editor/make-way.js +62 -0
- package/js/iso-editor/ui/canvas.js +477 -216
- package/js/iso-editor/ui/palette-look.js +53 -0
- package/js/iso-editor/ui/setup.js +3 -0
- package/package.json +1 -1
- package/src/iso-editor/make-way.ts +89 -0
- package/src/iso-editor/ui/app.css +4 -0
- package/src/iso-editor/ui/canvas.ts +390 -170
- package/src/iso-editor/ui/marks.css +2 -0
- package/src/iso-editor/ui/palette-look.ts +51 -0
- package/src/iso-editor/ui/setup.ts +8 -0
- package/types/iso-editor/make-way.d.ts +40 -0
- package/types/iso-editor/ui/canvas.d.ts +33 -12
- package/types/iso-editor/ui/palette-look.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +5 -0
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
@layer views {
|
|
8
8
|
.iso-canvas { --iso-sel: var(--accent); --iso-sel-fill: color-mix(in srgb, var(--iso-sel) 12%, transparent);
|
|
9
9
|
--iso-sel-faint: color-mix(in srgb, var(--iso-sel) 6%, transparent); --iso-bad: var(--bad); --iso-warn: var(--warn); }
|
|
10
|
+
/* a drag moves things, it doesn't select the drawing's words */
|
|
11
|
+
.iso-canvas svg.scene { user-select: none; -webkit-user-select: none; }
|
|
10
12
|
.iso-canvas svg.scene [data-id] { cursor: pointer; }
|
|
11
13
|
.iso-canvas svg.scene.mode-pan { cursor: grab; }
|
|
12
14
|
.iso-canvas svg.scene.mode-select { cursor: crosshair; }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The palette's entries as what they make (0.14.0): each thing drawn alone, small, in the drawing's own style. The canvas takes it as
|
|
2
|
+
// its kit's `looks`; a host that doesn't ask for it bundles none of it.
|
|
3
|
+
|
|
4
|
+
import { buildSvg } from '../../iso-core/svg-dom.ts';
|
|
5
|
+
import { boxSilhouette } from '../../iso-objects/geometry.ts';
|
|
6
|
+
import { applyStep } from '../splice.ts';
|
|
7
|
+
import type { Path } from '../path.ts';
|
|
8
|
+
import { h } from './icons.ts';
|
|
9
|
+
import type { CanvasDrawing, CanvasKit, CanvasUi, PaletteItem } from './canvas.ts';
|
|
10
|
+
|
|
11
|
+
type Kit<M, D extends CanvasDrawing> = Pick<CanvasKit<M, D>, 'kinds' | 'commands' | 'trial'>;
|
|
12
|
+
/** The kit's `looks`: the entries that show, one at a time, each once; an entry that can't be drawn alone keeps its icon. */
|
|
13
|
+
export const paletteLooks = <M, D extends CanvasDrawing>(K: Kit<M, D>): NonNullable<CanvasKit<M, D>['looks']> => (palette, data, ui: CanvasUi, theme) => {
|
|
14
|
+
palette.classList.add('looks');
|
|
15
|
+
let soon = 0;
|
|
16
|
+
return function draw() {
|
|
17
|
+
if (soon) return;
|
|
18
|
+
soon = window.setTimeout(() => {
|
|
19
|
+
soon = 0;
|
|
20
|
+
const b = [...palette.querySelectorAll<HTMLButtonElement>('.pal-item:not([data-look])')].find(q => !q.hidden && !q.closest('[hidden]')), d = data();
|
|
21
|
+
if (!b || !d) return;
|
|
22
|
+
const s = lookOf(K, ui.palette[Number(b.dataset.entry)], d, theme);
|
|
23
|
+
b.dataset.look = s ? 'object' : 'icon';
|
|
24
|
+
if (s) b.querySelector('.icon')?.replaceWith(h('span', { class: `${ui.rootClass} pal-look` }, s as unknown as HTMLElement));
|
|
25
|
+
draw();
|
|
26
|
+
}, 0);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** the thing an entry makes: the file with nothing in it but its plain values, and one of it; its own elements, without labels,
|
|
30
|
+
* framed by its outline. Undefined where that can't be drawn. */
|
|
31
|
+
function lookOf<M, D extends CanvasDrawing>(K: Kit<M, D>, item: PaletteItem, data: unknown, theme: string): SVGSVGElement | undefined {
|
|
32
|
+
const k = K.kinds.find(x => x.kind === item.kind);
|
|
33
|
+
if (!k) return undefined;
|
|
34
|
+
const name = K.commands.freshName('', item.name ?? k.singular), path = [...k.section, name] as Path;
|
|
35
|
+
const bare = Object.entries((data ?? {}) as Record<string, unknown>).filter(([, v]) => v === null || typeof v !== 'object').map(([n, v]) => `${JSON.stringify(n)}: ${JSON.stringify(v)}\n`).join('');
|
|
36
|
+
let d: D | undefined;
|
|
37
|
+
try { d = K.trial(K.commands.insertCmd(path.slice(0, -1), name, (item.value?.() ?? k.template()) as Record<string, unknown>).build(bare).steps.reduce((t, st) => applyStep(t, st), bare), theme); } catch { /* it needs more around it */ }
|
|
38
|
+
const id = d?.pinId.get(name), it = id ? d!.scene.layout.byId.get(id) : undefined;
|
|
39
|
+
if (!d || d.diags.length || !id || !it) return undefined;
|
|
40
|
+
const s = buildSvg(d.svg), all = [...s.querySelectorAll<SVGElement>('[data-id]')];
|
|
41
|
+
if (!all.some(e => e.getAttribute('data-id') === id)) return undefined;
|
|
42
|
+
for (const e of all) if (e.getAttribute('data-id') !== id) e.remove();
|
|
43
|
+
for (const e of s.querySelectorAll('text, title, desc, .g-labels, .g-floor')) e.remove();
|
|
44
|
+
const pts = boxSilhouette(it.box), xs = pts.map(q => q[0]), ys = pts.map(q => q[1]), m = 3;
|
|
45
|
+
s.setAttribute('viewBox', [Math.min(...xs) - m, Math.min(...ys) - m, Math.max(...xs) - Math.min(...xs) + 2 * m, Math.max(...ys) - Math.min(...ys) + 2 * m].map(v => v.toFixed(1)).join(' '));
|
|
46
|
+
for (const a of ['width', 'height', 'role', 'tabindex', 'aria-label']) s.removeAttribute(a);
|
|
47
|
+
for (const e of s.querySelectorAll('[tabindex]')) { e.removeAttribute('tabindex'); e.removeAttribute('role'); }
|
|
48
|
+
s.setAttribute('preserveAspectRatio', 'xMidYMid meet'); s.setAttribute('aria-hidden', 'true'); s.setAttribute('focusable', 'false');
|
|
49
|
+
s.classList.add('pal-scene');
|
|
50
|
+
return s;
|
|
51
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// The text pane is given, not imported: Monaco is a big dependency, and a host without it still gets the canvas, the
|
|
8
8
|
// tree and the panel.
|
|
9
9
|
|
|
10
|
+
import { paletteLooks } from './palette-look.ts';
|
|
10
11
|
import type { DomainAdapter, FileRole, ObjectRef } from '../adapter.ts';
|
|
11
12
|
import type { Path } from '../path.ts';
|
|
12
13
|
import { toPointer } from '../path.ts';
|
|
@@ -58,6 +59,11 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
58
59
|
paletteLayout?: 'floating' | 'docked';
|
|
59
60
|
/** (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
61
|
doubleClick?: 'text' | 'rename';
|
|
62
|
+
/** (0.14.0) the palette's entries with their icon (the default), or with the thing itself, drawn small in the current theme */
|
|
63
|
+
paletteLook?: 'icon' | 'object';
|
|
64
|
+
/** (0.14.0) what is in a drag's way jiggles before it gives way, and glides: 'always' (the default), or 'respect': not where
|
|
65
|
+
* the viewer prefers reduced motion */
|
|
66
|
+
dragMotion?: 'always' | 'respect';
|
|
61
67
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
62
68
|
flat?: CanvasKit<R, D>['flat'];
|
|
63
69
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|
|
@@ -115,6 +121,7 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
115
121
|
: a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
116
122
|
...(v.paletteLayout === undefined ? {} : { paletteLayout: v.paletteLayout }),
|
|
117
123
|
...(v.doubleClick === undefined ? {} : { doubleClick: v.doubleClick }),
|
|
124
|
+
...(v.dragMotion === undefined ? {} : { dragMotion: v.dragMotion }),
|
|
118
125
|
text: {
|
|
119
126
|
stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
|
|
120
127
|
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.',
|
|
@@ -128,6 +135,7 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
128
135
|
...(a.dropInto ? { dropOnto: (t: ObjectRef, v: unknown, k: string, d: unknown) => a.dropInto!(t, v, k, d) } : {}),
|
|
129
136
|
trial: (text, theme) => { const r = read(text); return r.read === undefined || r.diags.some(d => d.severity === 'error') ? undefined : v.draw(r.read as R, (r.read as { data?: unknown }).data, theme); },
|
|
130
137
|
};
|
|
138
|
+
if (v.paletteLook === 'object') canvas.looks = paletteLooks(canvas);
|
|
131
139
|
const kit: MountKit<R, undefined> = {
|
|
132
140
|
async check(text) {
|
|
133
141
|
const r = analyse(a, text, { fileName: v.fileName });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** a drop that overlaps waits this long on one cell before anything shows (ms) */
|
|
2
|
+
export declare const DWELL_HINT = 150;
|
|
3
|
+
/** and this long, from the same start, before the things in its way give way (ms) */
|
|
4
|
+
export declare const DWELL_GIVE = 700;
|
|
5
|
+
/** what gave way goes back this long after the dragged thing no longer needs the place (ms) */
|
|
6
|
+
export declare const BACK_AFTER = 250;
|
|
7
|
+
/** a thing's glide to its place, or back (ms) */
|
|
8
|
+
export declare const GLIDE = 180;
|
|
9
|
+
/** the jiggle: how far (screen px), and how often (a second) */
|
|
10
|
+
export declare const JIGGLE: {
|
|
11
|
+
px: number;
|
|
12
|
+
hz: number;
|
|
13
|
+
};
|
|
14
|
+
/** the most things that may step aside for one drop */
|
|
15
|
+
export declare const MAX_CHAIN = 3;
|
|
16
|
+
export interface Rect {
|
|
17
|
+
x0: number;
|
|
18
|
+
y0: number;
|
|
19
|
+
x1: number;
|
|
20
|
+
y1: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Beside extends Rect {
|
|
23
|
+
id: string;
|
|
24
|
+
/** whether it may be pinned somewhere else */
|
|
25
|
+
movable: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface WayOptions {
|
|
28
|
+
/** where the dragged thing would be */
|
|
29
|
+
foot: Rect;
|
|
30
|
+
/** everything else in the container */
|
|
31
|
+
others: Beside[];
|
|
32
|
+
/** the way it was going: its last step, or from where it started */
|
|
33
|
+
going: [number, number];
|
|
34
|
+
/** what a thing that steps aside must stay in (the container, less its margin); none: anywhere */
|
|
35
|
+
bounds?: Rect;
|
|
36
|
+
max?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const hits: (a: Rect, b: Rect) => boolean;
|
|
39
|
+
/** The steps (whole cells) of what would move, by id; undefined: nothing can make way. */
|
|
40
|
+
export declare function makeWay({ foot, others, going, bounds, max }: WayOptions): Map<string, [number, number]> | undefined;
|
|
@@ -4,9 +4,10 @@ import { type Actions } from './actions.js';
|
|
|
4
4
|
import { type Move } from '../../iso-objects/geometry.js';
|
|
5
5
|
import { type KindCatalog } from '../../iso-objects/kinds.js';
|
|
6
6
|
import type { CompiledScene } from '../../iso-objects/compile.js';
|
|
7
|
-
import type { EditorModel } from '../model.js';
|
|
7
|
+
import type { EditorModel, Command } from '../model.js';
|
|
8
8
|
import type { Problem } from '../validate.js';
|
|
9
9
|
import { type Commands } from '../commands.js';
|
|
10
|
+
import { type Beside } from '../make-way.js';
|
|
10
11
|
import type { ObjectKindInfo, ObjectRef, ConnectPlan, GroupPlan } from '../adapter.js';
|
|
11
12
|
import { type Path } from '../path.js';
|
|
12
13
|
import { type View } from '../../iso-viewer/viewport.js';
|
|
@@ -90,8 +91,12 @@ export interface CanvasUi {
|
|
|
90
91
|
* its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
|
|
91
92
|
* width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
|
|
92
93
|
paletteLayout?: 'floating' | 'docked';
|
|
93
|
-
/** (0.12.5) what a double click on an object does: shows it in the text (the default), or renames it
|
|
94
|
+
/** (0.12.5) what a double click on an object does: shows it in the text (the default), or renames it (0.14.1: what has no
|
|
95
|
+
* name, a connection, does nothing then) */
|
|
94
96
|
doubleClick?: 'text' | 'rename';
|
|
97
|
+
/** (0.14.0) whether what is in a drag's way jiggles before it gives way, and glides: 'always' (the default), or
|
|
98
|
+
* 'respect': not where the viewer prefers reduced motion (the outlines of where it would go still show) */
|
|
99
|
+
dragMotion?: 'always' | 'respect';
|
|
95
100
|
text: {
|
|
96
101
|
stage: string;
|
|
97
102
|
dragGroup: string;
|
|
@@ -134,6 +139,9 @@ export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
|
134
139
|
} | undefined;
|
|
135
140
|
/** (0.10.0) the selection made into a new container (the adapter's group): Group, ⌘G, one undo step */
|
|
136
141
|
group?(members: ObjectRef[], data: unknown): GroupPlan | undefined;
|
|
142
|
+
/** (0.14.0) the palette's entries as what they make, drawn small (palette-look.ts): what draws those that show and aren't
|
|
143
|
+
* drawn yet. None: the entries' icons */
|
|
144
|
+
looks?(palette: HTMLElement, data: () => unknown, ui: CanvasUi, theme: string): () => void;
|
|
137
145
|
actions: Actions;
|
|
138
146
|
/** what an object's own menu offers, beyond rename, duplicate and delete */
|
|
139
147
|
objectItems(doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void): MenuItem[];
|
|
@@ -182,6 +190,12 @@ export interface CanvasOpts<M, D extends CanvasDrawing, A extends object = objec
|
|
|
182
190
|
/** a layer over the drawing (none: the drawing and its marks only) */
|
|
183
191
|
layer?: (ctx: CanvasCtx<D>) => CanvasLayer<A>;
|
|
184
192
|
}
|
|
193
|
+
/** a new thing as a drag would make it: inside what (none: the canvas), by which command */
|
|
194
|
+
export interface FreshPlan {
|
|
195
|
+
into?: string;
|
|
196
|
+
label: string;
|
|
197
|
+
add: Command;
|
|
198
|
+
}
|
|
185
199
|
export declare function canvasView<M, D extends CanvasDrawing, A extends object = object>(host: HTMLElement, doc: EditorModel, opts: CanvasOpts<M, D, A>): {
|
|
186
200
|
addFromPalette: (sec: string, at?: {
|
|
187
201
|
x: number;
|
|
@@ -190,10 +204,6 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
190
204
|
palette: HTMLDivElement;
|
|
191
205
|
groupSelection: () => void;
|
|
192
206
|
startPick: () => void;
|
|
193
|
-
objectsUnder: (at: {
|
|
194
|
-
x: number;
|
|
195
|
-
y: number;
|
|
196
|
-
}) => ObjectRef[];
|
|
197
207
|
readonly linking: {
|
|
198
208
|
from: ObjectRef;
|
|
199
209
|
x?: number;
|
|
@@ -266,6 +276,7 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
266
276
|
z0?: number;
|
|
267
277
|
size?: [number, number];
|
|
268
278
|
parent?: {
|
|
279
|
+
id: string;
|
|
269
280
|
w: number;
|
|
270
281
|
d: number;
|
|
271
282
|
pad: number;
|
|
@@ -277,17 +288,27 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
277
288
|
};
|
|
278
289
|
label: string;
|
|
279
290
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
y0: number;
|
|
283
|
-
x1: number;
|
|
284
|
-
y1: number;
|
|
285
|
-
}[];
|
|
291
|
+
/** (0.14.0) how far the view was moved to keep the container still on screen (a trial may lay it out elsewhere) */
|
|
292
|
+
shifted?: [number, number];
|
|
286
293
|
move?: Move;
|
|
287
294
|
invalid?: boolean;
|
|
288
295
|
step?: number;
|
|
289
296
|
origCd?: D;
|
|
290
297
|
gridShown?: boolean;
|
|
298
|
+
/** what stands beside it in its container, where it stood when the drag began */
|
|
299
|
+
beside?: Beside[];
|
|
300
|
+
/** (0.14.0) what gave way to it, by how many cells; what would, while the drop waits; the last cell it could drop on */
|
|
301
|
+
given?: Map<string, [number, number]>;
|
|
302
|
+
way?: Map<string, [number, number]>;
|
|
303
|
+
clearAt?: [number, number];
|
|
304
|
+
/** (0.14.0) a new thing, from the palette (origCd: the drawing without it): the drawing with it, and what it is made as */
|
|
305
|
+
fresh?: {
|
|
306
|
+
base: D;
|
|
307
|
+
name: string;
|
|
308
|
+
path: Path;
|
|
309
|
+
plan: FreshPlan;
|
|
310
|
+
text: string;
|
|
311
|
+
};
|
|
291
312
|
/** siblings that flow after the dragged item, pinned where they stand so the drag doesn't push them */
|
|
292
313
|
keep?: [string, [number, number]][];
|
|
293
314
|
sel0?: Path[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CanvasDrawing, CanvasKit } from './canvas.js';
|
|
2
|
+
type Kit<M, D extends CanvasDrawing> = Pick<CanvasKit<M, D>, 'kinds' | 'commands' | 'trial'>;
|
|
3
|
+
/** The kit's `looks`: the entries that show, one at a time, each once; an entry that can't be drawn alone keeps its icon. */
|
|
4
|
+
export declare const paletteLooks: <M, D extends CanvasDrawing>(K: Kit<M, D>) => NonNullable<CanvasKit<M, D>['looks']>;
|
|
5
|
+
export {};
|
|
@@ -41,6 +41,11 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
41
41
|
paletteLayout?: 'floating' | 'docked';
|
|
42
42
|
/** (0.12.5) what a double click on an object of the canvas does: shows it in the text (the default), or renames it */
|
|
43
43
|
doubleClick?: 'text' | 'rename';
|
|
44
|
+
/** (0.14.0) the palette's entries with their icon (the default), or with the thing itself, drawn small in the current theme */
|
|
45
|
+
paletteLook?: 'icon' | 'object';
|
|
46
|
+
/** (0.14.0) what is in a drag's way jiggles before it gives way, and glides: 'always' (the default), or 'respect': not where
|
|
47
|
+
* the viewer prefers reduced motion */
|
|
48
|
+
dragMotion?: 'always' | 'respect';
|
|
44
49
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
45
50
|
flat?: CanvasKit<R, D>['flat'];
|
|
46
51
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|