@johnoscott/isometric-engine 0.10.1 → 0.12.3
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 +11 -1
- package/README.md +1 -1
- package/assets/app.css +31 -0
- package/assets/icons.svg +1 -1
- package/iso-editor.js +178 -178
- package/iso-render.js +97 -97
- package/iso-systems.js +104 -104
- package/js/iso-editor/doc.js +4 -0
- package/js/iso-editor/ui/canvas.js +185 -8
- package/js/iso-editor/ui/plain-icons.js +2 -0
- package/js/iso-editor/ui/setup.js +2 -1
- package/js/iso-objects/board.js +6 -1
- package/js/iso-objects/scene.js +3 -2
- package/js/iso-viewer/index.js +4 -1
- package/package.json +92 -92
- package/src/iso-core/compile-schema.ts +3 -1
- package/src/iso-editor/doc.ts +6 -0
- package/src/iso-editor/ui/app.css +31 -0
- package/src/iso-editor/ui/canvas.ts +130 -10
- package/src/iso-editor/ui/plain-icons.ts +2 -0
- package/src/iso-editor/ui/setup.ts +6 -2
- package/src/iso-objects/board.ts +6 -2
- package/src/iso-objects/scene.ts +4 -2
- package/src/iso-viewer/index.ts +2 -2
- package/src/iso-viewer/morph.ts +5 -2
- package/types/iso-core/compile-schema.d.ts +2 -2
- package/types/iso-editor/ui/canvas.d.ts +8 -0
- package/types/iso-editor/ui/monaco-entry.d.ts +2 -0
- package/types/iso-editor/ui/setup.d.ts +4 -0
- package/types/iso-systems/validate.d.ts +4 -0
- package/types/iso-viewer/bundle.d.ts +1 -0
- package/types/iso-viewer/index.d.ts +2 -2
- package/types/iso-viewer/morph.d.ts +6 -3
|
@@ -54,6 +54,8 @@ body[data-view="text"] #se-canvas, body[data-view="text"] #se-work-grip { displa
|
|
|
54
54
|
/* the stage (canvas.css styles the drawing in it); focused by a click, a quieter ring than the keyboard's */
|
|
55
55
|
.canvas.has-focus .canvas-stage:not(:focus-visible) { outline: 2px solid color-mix(in srgb, var(--focus) 50%, transparent); outline-offset: -2px; }
|
|
56
56
|
.canvas-tools { position: absolute; right: var(--sp-3); bottom: var(--sp-3); display: flex; gap: var(--sp-0); padding: var(--sp-0); background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); }
|
|
57
|
+
/* a canvas too narrow for it: the toolbar wraps onto rows inside it, right-aligned (one row, as ever, when it fits) */
|
|
58
|
+
.canvas-tools { max-width: calc(100% - 2 * var(--sp-3)); flex-wrap: wrap; justify-content: flex-end; }
|
|
57
59
|
.canvas-tools .segmented { margin-right: var(--sp-1); }
|
|
58
60
|
.status .hint-mode { color: var(--ink-3); }
|
|
59
61
|
body[data-view="text"] .status .hint-mode { display: none; }
|
|
@@ -222,7 +224,36 @@ body { position: relative; height: 100%; min-height: 0; font: var(--fw-regular)
|
|
|
222
224
|
.pal-item:hover { background: var(--state-hover); color: var(--ink); }
|
|
223
225
|
.pal-item:active { cursor: grabbing; }
|
|
224
226
|
.pal-item .icon { width: 14px; height: 14px; }
|
|
227
|
+
.pal-section { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
|
|
228
|
+
.pal-head { display: flex; flex-shrink: 0; align-items: center; gap: var(--sp-1); height: var(--ctl-sm); padding: 0 var(--sp-2) 0 var(--sp-1); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-3); font: inherit; font-size: var(--fs-xs); font-weight: var(--fw-strong); letter-spacing: .02em; cursor: pointer; text-align: left; }
|
|
229
|
+
.pal-head:hover { background: var(--state-hover); color: var(--ink); }
|
|
230
|
+
.pal-head .pal-chev { width: 12px; height: 12px; transition: transform var(--dur-1, 0ms); }
|
|
231
|
+
.pal-head[aria-expanded="true"] .pal-chev { transform: rotate(90deg); }
|
|
232
|
+
.pal-body { display: flex; flex-direction: column; gap: 2px; }
|
|
233
|
+
.pal-body[hidden] { display: none; }
|
|
225
234
|
body.read-only .palette { display: none; }
|
|
235
|
+
/* 0.12.0: the palette docked, a pane of its own at the canvas's left (search, sections, a grip, collapsible) */
|
|
236
|
+
.canvas.pal-docked { display: flex; --pal-cur: var(--pal-w, 220px); }
|
|
237
|
+
.canvas.pal-docked.pal-collapsed { --pal-cur: 36px; }
|
|
238
|
+
.canvas.pal-docked > .canvas-stage { flex: 1 1 auto; min-width: 0; position: relative; }
|
|
239
|
+
.canvas.pal-docked > .canvas-empty { left: var(--pal-cur, 220px); }
|
|
240
|
+
/* the toolbar stays on the stage, beside the pane */
|
|
241
|
+
.canvas.pal-docked > .canvas-tools { max-width: calc(100% - var(--pal-cur, 220px) - 2 * var(--sp-3)); }
|
|
242
|
+
.pal-dock { flex: 0 0 var(--pal-cur, 220px); width: var(--pal-cur, 220px); min-width: 0; display: flex; flex-direction: column; background: var(--surface); border-right: var(--bw) solid var(--line); overflow: hidden; z-index: 2; }
|
|
243
|
+
.pal-dock-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1); border-bottom: var(--bw) solid var(--line); }
|
|
244
|
+
.pal-search-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-1); height: var(--ctl-sm); padding: 0 var(--sp-2); border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--ink-3); }
|
|
245
|
+
.pal-search-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
|
|
246
|
+
.pal-search-wrap .icon { width: 14px; height: 14px; flex: none; }
|
|
247
|
+
.pal-search { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; font-size: var(--fs-sm); }
|
|
248
|
+
.pal-dock .palette.pal-list { position: static; flex: 1 1 auto; max-height: none; min-height: 0; border: 0; border-radius: 0; box-shadow: none; background: none; padding: var(--sp-1); }
|
|
249
|
+
.pal-dock .pal-item[hidden], .pal-dock .pal-section[hidden] { display: none; }
|
|
250
|
+
.pal-none { margin: 0; padding: var(--sp-2) var(--sp-3); color: var(--ink-3); font-size: var(--fs-sm); }
|
|
251
|
+
.pal-none[hidden] { display: none; }
|
|
252
|
+
.canvas.pal-collapsed .pal-search-wrap, .canvas.pal-collapsed .palette.pal-list, .canvas.pal-collapsed .pal-none, .canvas.pal-collapsed .pal-grip { display: none; }
|
|
253
|
+
.canvas.pal-collapsed .pal-dock-head { border-bottom: 0; justify-content: center; }
|
|
254
|
+
.pal-grip { flex: none; width: 6px; margin: 0 -3px; cursor: col-resize; z-index: 3; position: relative; }
|
|
255
|
+
.pal-grip:hover, .pal-grip:focus-visible { background: color-mix(in srgb, var(--accent) 30%, transparent); outline: 0; }
|
|
256
|
+
body.read-only .pal-dock, body.read-only .pal-grip { display: none; }
|
|
226
257
|
.pal-ghost { position: absolute; z-index: 5; pointer-events: none; display: flex; align-items: center; gap: var(--sp-1); padding: 2px var(--sp-2); border: var(--bw) solid var(--accent); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font-size: var(--fs-sm); box-shadow: var(--shadow-2, none); }
|
|
227
258
|
.pal-ghost .icon { width: 14px; height: 14px; }
|
|
228
259
|
.pal-ghost.bad { border-color: var(--bad); color: var(--bad); }
|
|
@@ -77,13 +77,23 @@ export interface CanvasUi {
|
|
|
77
77
|
/** the palette's entries: a kind, and (0.10.0) a preset: what a new one starts as (default: the kind's template) and
|
|
78
78
|
* the base of its fresh name (default: the kind's singular) */
|
|
79
79
|
palette: PaletteItem[];
|
|
80
|
+
/** (0.12.0) where the palette is: 'floating' (the default: over the canvas, at its top left) or 'docked' (a pane of
|
|
81
|
+
* its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
|
|
82
|
+
* width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
|
|
83
|
+
paletteLayout?: 'floating' | 'docked';
|
|
80
84
|
text: {
|
|
81
85
|
stage: string; dragGroup: string; dragSelectTip: string; unreadable: string; palette: string;
|
|
82
86
|
/** the end of a pin drag's hint */
|
|
83
87
|
pinHint: string; renameWhy: string; duplicateWhy: string;
|
|
84
88
|
};
|
|
85
89
|
}
|
|
86
|
-
export interface PaletteItem {
|
|
90
|
+
export interface PaletteItem {
|
|
91
|
+
kind: string; icon: IconName; label: string; value?(): unknown; name?: string;
|
|
92
|
+
/** (0.11.0) the header it is listed under: entries with one are grouped by it, in order of first use, each group under
|
|
93
|
+
* a header that collapses (all collapsed but the one last added from, remembered in the host's store as
|
|
94
|
+
* `canvas-palette`); entries without one are listed as before, where they are */
|
|
95
|
+
section?: string;
|
|
96
|
+
}
|
|
87
97
|
/** what the canvas is given of the domain (M: the domain's reading of the file; D: its drawing) */
|
|
88
98
|
export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
89
99
|
draw(model: M, data: unknown, theme: string): D;
|
|
@@ -326,7 +336,11 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
326
336
|
const live = layer?.extent?.() ?? [];
|
|
327
337
|
return union([...ptrs.flatMap(p => elementsFor(p)).filter(e => e.getBBox().width || e.getBBox().height).map(boxOf), ...live]);
|
|
328
338
|
}
|
|
329
|
-
|
|
339
|
+
// (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
|
+
// drawn (the scale, the pointer's place, a resize); floating, the stage is the host's whole area
|
|
341
|
+
const docked = ui.paletteLayout === 'docked';
|
|
342
|
+
const viewEl = docked ? stage : host;
|
|
343
|
+
const V = viewport(viewEl, {
|
|
330
344
|
svg: () => svg,
|
|
331
345
|
onApply: k => {
|
|
332
346
|
svg!.classList.toggle('zoom-near', k >= 1); // a layer's detail shows from 100% up
|
|
@@ -1077,6 +1091,112 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1077
1091
|
return p;
|
|
1078
1092
|
}
|
|
1079
1093
|
const palette = h('div', { class: 'palette', role: 'toolbar', 'aria-label': T.palette, 'aria-orientation': 'vertical' });
|
|
1094
|
+
// (0.11.0) sections: a header (a button, aria-expanded) over its entries; open: the section last added from (the
|
|
1095
|
+
// first, before any); the reader opens and closes the others as they like. The host's store may be off: guarded.
|
|
1096
|
+
const sections = new Map<string, { head: HTMLButtonElement; body: HTMLElement }>();
|
|
1097
|
+
const PAL_KEY = 'canvas-palette';
|
|
1098
|
+
let lastSection: string | undefined;
|
|
1099
|
+
try { const v = JSON.parse(opts.store?.get(PAL_KEY) ?? '{}') as { last?: unknown }; if (typeof v.last === 'string') lastSection = v.last; } catch { /* none */ }
|
|
1100
|
+
const named = [...new Set(ui.palette.map(i => i.section).filter((x): x is string => x !== undefined))];
|
|
1101
|
+
const openAtStart = lastSection !== undefined && named.includes(lastSection) ? lastSection : named[0];
|
|
1102
|
+
const setOpen = (sec: string, open: boolean) => { const g = sections.get(sec); if (!g) return; g.head.setAttribute('aria-expanded', String(open)); g.body.hidden = !open; };
|
|
1103
|
+
function sectionBody(sec: string): HTMLElement {
|
|
1104
|
+
const have = sections.get(sec);
|
|
1105
|
+
if (have) return have.body;
|
|
1106
|
+
const id = `pal-sec-${sections.size}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1107
|
+
const head = h('button', { type: 'button', class: 'pal-head', 'aria-expanded': 'false', 'aria-controls': id, 'data-section-head': sec }, icon('chevron-right', 'pal-chev'), h('span', { class: 'pal-head-label' }, sec)) as HTMLButtonElement;
|
|
1108
|
+
const body = h('div', { class: 'pal-body', id, role: 'group', 'aria-label': sec, 'data-section-body': sec });
|
|
1109
|
+
head.addEventListener('click', () => setOpen(sec, head.getAttribute('aria-expanded') !== 'true'));
|
|
1110
|
+
palette.append(h('div', { class: 'pal-section', 'data-pal-section': sec }, head, body));
|
|
1111
|
+
sections.set(sec, { head, body });
|
|
1112
|
+
setOpen(sec, sec === openAtStart);
|
|
1113
|
+
return body;
|
|
1114
|
+
}
|
|
1115
|
+
// (0.12.0) docked: a pane of its own at the canvas's left (the stage beside it): a search box over the list, a
|
|
1116
|
+
// control that collapses it to a strip, and a grip that resizes it; its width and state in the host's store
|
|
1117
|
+
const DOCK_KEY = 'canvas-palette-dock';
|
|
1118
|
+
const dockPref: { w?: number; collapsed?: boolean } = {};
|
|
1119
|
+
try { const v = JSON.parse(opts.store?.get(DOCK_KEY) ?? '{}') as { w?: unknown; collapsed?: unknown }; if (typeof v.w === 'number' && Number.isFinite(v.w)) dockPref.w = v.w; if (v.collapsed === true) dockPref.collapsed = true; } catch { /* none */ }
|
|
1120
|
+
const saveDock = () => { try { opts.store?.set(DOCK_KEY, JSON.stringify(dockPref)); } catch { /* storage may be off */ } };
|
|
1121
|
+
const DOCK_MIN = 160, DOCK_MAX = 440;
|
|
1122
|
+
const palHome: HTMLElement = docked ? h('aside', { class: 'pal-dock', 'aria-label': 'Palette' }) : palette;
|
|
1123
|
+
const palGrip = h('div', { class: 'pal-grip', role: 'separator', 'aria-orientation': 'vertical', 'aria-label': 'Resize the palette', tabindex: '0' });
|
|
1124
|
+
const search = h('input', { type: 'search', class: 'pal-search', placeholder: 'Search', 'aria-label': 'Search the palette', autocomplete: 'off', spellcheck: 'false' }) as HTMLInputElement;
|
|
1125
|
+
const none = h('p', { class: 'pal-none', role: 'status', hidden: '' });
|
|
1126
|
+
const collapseBtn = h('button', { type: 'button', class: 'btn sm quiet icon-only pal-collapse', 'aria-expanded': 'true', 'aria-label': 'Collapse the palette', title: 'Collapse the palette' }, icon('chevron-left')) as HTMLButtonElement;
|
|
1127
|
+
const visibleItems = () => [...palette.querySelectorAll<HTMLButtonElement>('.pal-item')].filter(b => !b.hidden && !b.closest('[hidden]'));
|
|
1128
|
+
/** the search: every word in the entry's label or its section; sections with a match open while it is on, and the
|
|
1129
|
+
* reader's own open and closed come back when it is cleared */
|
|
1130
|
+
let before: Map<string, boolean> | undefined;
|
|
1131
|
+
function filter() {
|
|
1132
|
+
const words = search.value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
1133
|
+
if (words.length && !before) before = new Map([...sections].map(([k, g]) => [k, g.head.getAttribute('aria-expanded') === 'true']));
|
|
1134
|
+
let shown = 0;
|
|
1135
|
+
for (const b of palette.querySelectorAll<HTMLButtonElement>('.pal-item')) {
|
|
1136
|
+
const item = ui.palette[Number(b.dataset.entry)];
|
|
1137
|
+
const hay = `${item.label} ${item.section ?? ''}`.toLowerCase();
|
|
1138
|
+
b.hidden = !words.every(w => hay.includes(w));
|
|
1139
|
+
if (!b.hidden) shown++;
|
|
1140
|
+
}
|
|
1141
|
+
for (const [sec, g] of sections) {
|
|
1142
|
+
const any = [...g.body.querySelectorAll<HTMLButtonElement>('.pal-item')].some(b => !b.hidden);
|
|
1143
|
+
(g.head.parentElement as HTMLElement).hidden = words.length > 0 && !any;
|
|
1144
|
+
if (words.length) setOpen(sec, any);
|
|
1145
|
+
}
|
|
1146
|
+
if (!words.length && before) { for (const [sec, open] of before) setOpen(sec, open); before = undefined; }
|
|
1147
|
+
none.hidden = shown > 0;
|
|
1148
|
+
none.textContent = shown ? '' : `Nothing matches "${search.value.trim()}"`;
|
|
1149
|
+
}
|
|
1150
|
+
const setDockW = (w: number, keep = true) => { const v = Math.round(Math.min(DOCK_MAX, Math.max(DOCK_MIN, w))); host.style.setProperty('--pal-w', `${v}px`); palGrip.setAttribute('aria-valuenow', String(v)); if (keep) { dockPref.w = v; saveDock(); } };
|
|
1151
|
+
const setCollapsed = (c: boolean, keep = true) => {
|
|
1152
|
+
host.classList.toggle('pal-collapsed', c);
|
|
1153
|
+
collapseBtn.setAttribute('aria-expanded', String(!c));
|
|
1154
|
+
const say = c ? 'Show the palette' : 'Collapse the palette';
|
|
1155
|
+
collapseBtn.setAttribute('aria-label', say); collapseBtn.title = say;
|
|
1156
|
+
collapseBtn.replaceChildren(icon(c ? 'chevron-right' : 'chevron-left'));
|
|
1157
|
+
if (keep) { if (c) dockPref.collapsed = true; else delete dockPref.collapsed; saveDock(); }
|
|
1158
|
+
};
|
|
1159
|
+
if (docked) {
|
|
1160
|
+
host.classList.add('pal-docked');
|
|
1161
|
+
palette.classList.add('pal-list');
|
|
1162
|
+
palHome.append(h('div', { class: 'pal-dock-head' }, collapseBtn, h('label', { class: 'pal-search-wrap' }, icon('search'), search)), palette, none);
|
|
1163
|
+
palGrip.setAttribute('aria-valuemin', String(DOCK_MIN)); palGrip.setAttribute('aria-valuemax', String(DOCK_MAX));
|
|
1164
|
+
setDockW(dockPref.w ?? 220, false);
|
|
1165
|
+
setCollapsed(!!dockPref.collapsed, false);
|
|
1166
|
+
collapseBtn.addEventListener('click', () => { setCollapsed(!host.classList.contains('pal-collapsed')); if (!host.classList.contains('pal-collapsed')) search.focus(); });
|
|
1167
|
+
search.addEventListener('input', filter);
|
|
1168
|
+
search.addEventListener('keydown', e => {
|
|
1169
|
+
if (e.key === 'Escape' && search.value) { e.preventDefault(); e.stopPropagation(); search.value = ''; filter(); }
|
|
1170
|
+
else if (e.key === 'ArrowDown') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.focus(); } }
|
|
1171
|
+
else if (e.key === 'Enter') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); } }
|
|
1172
|
+
});
|
|
1173
|
+
// the list's arrow keys: up and down through what is shown (up from the first: back to the search)
|
|
1174
|
+
palette.addEventListener('keydown', e => {
|
|
1175
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
|
|
1176
|
+
const all = [...palette.querySelectorAll<HTMLButtonElement>('.pal-head, .pal-item')].filter(b => !b.hidden && !b.parentElement?.closest('[hidden]') && (b.classList.contains('pal-head') || !b.closest('.pal-body[hidden]')));
|
|
1177
|
+
const i = all.indexOf(document.activeElement as HTMLButtonElement);
|
|
1178
|
+
if (i < 0) return;
|
|
1179
|
+
e.preventDefault();
|
|
1180
|
+
if (e.key === 'ArrowUp' && i === 0) search.focus(); else all[Math.min(all.length - 1, Math.max(0, i + (e.key === 'ArrowDown' ? 1 : -1)))].focus();
|
|
1181
|
+
});
|
|
1182
|
+
palGrip.addEventListener('pointerdown', e => {
|
|
1183
|
+
if (e.button !== 0) return;
|
|
1184
|
+
try { palGrip.setPointerCapture(e.pointerId); } catch { /* synthetic */ }
|
|
1185
|
+
const x0 = e.clientX, w0 = palHome.getBoundingClientRect().width;
|
|
1186
|
+
const mv = (ev: PointerEvent) => setDockW(w0 + ev.clientX - x0, false);
|
|
1187
|
+
const up = (ev: PointerEvent) => { palGrip.removeEventListener('pointermove', mv); palGrip.removeEventListener('pointerup', up); setDockW(w0 + ev.clientX - x0); };
|
|
1188
|
+
palGrip.addEventListener('pointermove', mv); palGrip.addEventListener('pointerup', up);
|
|
1189
|
+
});
|
|
1190
|
+
palGrip.addEventListener('keydown', e => {
|
|
1191
|
+
const d = e.key === 'ArrowLeft' ? -16 : e.key === 'ArrowRight' ? 16 : 0;
|
|
1192
|
+
if (d) { e.preventDefault(); setDockW(palHome.getBoundingClientRect().width + d); }
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
const usedSection = (item: PaletteItem) => {
|
|
1196
|
+
if (item.section === undefined || item.section === lastSection) return;
|
|
1197
|
+
lastSection = item.section;
|
|
1198
|
+
try { opts.store?.set(PAL_KEY, JSON.stringify({ last: lastSection })); } catch { /* storage may be off */ }
|
|
1199
|
+
};
|
|
1080
1200
|
ui.palette.forEach((item, idx) => {
|
|
1081
1201
|
const { kind: sec, icon: ic, label } = item;
|
|
1082
1202
|
const b = h('button', { type: 'button', class: 'pal-item', 'data-section': sec, 'data-entry': String(idx), title: `Add ${label.toLowerCase()} (click), or drag it where it goes` }, icon(ic), h('span', { class: 'pal-label' }, label));
|
|
@@ -1086,7 +1206,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1086
1206
|
try { b.setPointerCapture(e.pointerId); } catch { /* a synthetic pointer: the events come to the button anyway */ }
|
|
1087
1207
|
const x0 = e.clientX, y0 = e.clientY;
|
|
1088
1208
|
let ghost: HTMLElement | undefined;
|
|
1089
|
-
const over = (ev: PointerEvent) => { const r = stage.getBoundingClientRect(); return ev.clientX >= r.left && ev.clientX <= r.right && ev.clientY >= r.top && ev.clientY <= r.bottom && !
|
|
1209
|
+
const over = (ev: PointerEvent) => { const r = stage.getBoundingClientRect(); return ev.clientX >= r.left && ev.clientX <= r.right && ev.clientY >= r.top && ev.clientY <= r.bottom && !palHome.contains(document.elementFromPoint(ev.clientX, ev.clientY)); };
|
|
1090
1210
|
const mv = (ev: PointerEvent) => {
|
|
1091
1211
|
if (!ghost && Math.hypot(ev.clientX - x0, ev.clientY - y0) < 4) return;
|
|
1092
1212
|
if (!ghost) { ghost = h('div', { class: 'pal-ghost', 'aria-hidden': 'true' }, icon(ic), label); host.append(ghost); }
|
|
@@ -1099,18 +1219,18 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1099
1219
|
const dragged = !!ghost;
|
|
1100
1220
|
ghost?.remove();
|
|
1101
1221
|
if (!drop) return;
|
|
1102
|
-
if (!dragged) addFromPalette(sec, undefined, item);
|
|
1103
|
-
else if (over(ev)) addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item);
|
|
1222
|
+
if (!dragged) { usedSection(item); addFromPalette(sec, undefined, item); }
|
|
1223
|
+
else if (over(ev)) { usedSection(item); addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item); }
|
|
1104
1224
|
};
|
|
1105
1225
|
const upH = (ev: PointerEvent) => done(ev, true), cancelH = (ev: PointerEvent) => done(ev, false);
|
|
1106
1226
|
const esc = (ev: KeyboardEvent) => { if (ev.key === 'Escape') { ev.stopPropagation(); ev.preventDefault(); done(e, false); } };
|
|
1107
1227
|
b.addEventListener('pointermove', mv); b.addEventListener('pointerup', upH); b.addEventListener('pointercancel', cancelH); addEventListener('keydown', esc, true);
|
|
1108
1228
|
});
|
|
1109
1229
|
// the keyboard: Enter or the space key adds (the layout places it)
|
|
1110
|
-
b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); addFromPalette(sec, undefined, item); } });
|
|
1111
|
-
palette.append(b);
|
|
1230
|
+
b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); usedSection(item); addFromPalette(sec, undefined, item); } });
|
|
1231
|
+
(item.section === undefined ? palette : sectionBody(item.section)).append(b);
|
|
1112
1232
|
});
|
|
1113
|
-
host.append(palette);
|
|
1233
|
+
if (docked) host.prepend(palHome, palGrip); else host.append(palette);
|
|
1114
1234
|
|
|
1115
1235
|
function resetLayout() {
|
|
1116
1236
|
// wherever the pins are (x-editor, or the legacy key): removed, and their key too if it holds nothing else
|
|
@@ -1163,7 +1283,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1163
1283
|
}
|
|
1164
1284
|
case 'ContextMenu': case 'F10':
|
|
1165
1285
|
if (e.key === 'F10' && !e.shiftKey) return;
|
|
1166
|
-
{ const b = unionBox(sel); const r =
|
|
1286
|
+
{ const b = unionBox(sel); const r = viewEl.getBoundingClientRect(); const k = scale(); openMenu(menuItems(sel.length ? toPointer(sel[0]) : undefined), b ? { x: r.left + (b.x + b.w - V.view!.x) * k, y: r.top + (b.y - V.view!.y) * k } : { x: r.left + 40, y: r.top + 40 }, 'Canvas'); }
|
|
1167
1287
|
break;
|
|
1168
1288
|
default:
|
|
1169
1289
|
if (mod && e.key.toLowerCase() === 'd' && sel.length === 1 && !ro) { duplicate(doc, sel[0], 'canvas', opts.note); break; }
|
|
@@ -1219,7 +1339,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1219
1339
|
/** the view (3D or 2D), and the 2D layout while it shows */
|
|
1220
1340
|
get mode() { return mode; }, setMode, get flat() { return flat?.layout; },
|
|
1221
1341
|
stage, key, scale: () => scale(), nav, paintNav, outlinesFor, footprints, get drag() { return pinDrag(); }, get lastMarquee() { return lastMarquee; },
|
|
1222
|
-
boxFor, pageXYOf: (p: Path) => { const b = boxFor(p); const r =
|
|
1342
|
+
boxFor, pageXYOf: (p: Path) => { const b = boxFor(p); const r = viewEl.getBoundingClientRect(); const k = scale(); return b && V.view ? { x: r.left + (b.x + b.w / 2 - V.view.x) * k, y: r.top + (b.y + b.h / 2 - V.view.y) * k } : undefined; },
|
|
1223
1343
|
};
|
|
1224
1344
|
// the layer's calls, as they are (its getters stay getters)
|
|
1225
1345
|
if (layer) Object.defineProperties(base, Object.getOwnPropertyDescriptors(layer.api));
|
|
@@ -52,6 +52,7 @@ export const PLAIN_ICON_SVG: Record<string, string> = {
|
|
|
52
52
|
'arrow-up-right': '<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',
|
|
53
53
|
'box': '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" /> <path d="m3.3 7 8.7 5 8.7-5" /> <path d="M12 22V12" />',
|
|
54
54
|
'chevron-down': '<path d="m6 9 6 6 6-6" />',
|
|
55
|
+
'chevron-left': '<path d="m15 18-6-6 6-6" />',
|
|
55
56
|
'chevron-right': '<path d="m9 18 6-6-6-6" />',
|
|
56
57
|
'circle-dot': '<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',
|
|
57
58
|
'circle-x': '<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',
|
|
@@ -67,6 +68,7 @@ export const PLAIN_ICON_SVG: Record<string, string> = {
|
|
|
67
68
|
'pencil': '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" /> <path d="m15 5 4 4" />',
|
|
68
69
|
'plus': '<path d="M5 12h14" /> <path d="M12 5v14" />',
|
|
69
70
|
'rotate-ccw': '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> <path d="M3 3v5h5" />',
|
|
71
|
+
'search': '<path d="m21 21-4.34-4.34" /> <circle cx="11" cy="11" r="8" />',
|
|
70
72
|
'trash-2': '<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />',
|
|
71
73
|
'triangle-alert': '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /> <path d="M12 9v4" /> <path d="M12 17h.01" />',
|
|
72
74
|
'x': '<path d="M18 6 6 18" /> <path d="m6 6 12 12" />',
|
|
@@ -52,7 +52,10 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
52
52
|
keymap?: KeyGroup[];
|
|
53
53
|
/** (0.10.0) the palette's entries: presets of a kind, each with its label, icon, what a new one starts as (a copy of
|
|
54
54
|
* `value`; default: the kind's template) and the base of its fresh name. None: one entry per kind, as before */
|
|
55
|
-
palette?: { kind: string; label: string; icon?: string; value?: unknown; name?: string }[];
|
|
55
|
+
palette?: { kind: string; label: string; icon?: string; value?: unknown; name?: string; section?: string }[];
|
|
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
|
+
* searchable by label and section, resizable and collapsible */
|
|
58
|
+
paletteLayout?: 'floating' | 'docked';
|
|
56
59
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
57
60
|
flat?: CanvasKit<R, D>['flat'];
|
|
58
61
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|
|
@@ -106,8 +109,9 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
106
109
|
const canvasUi: CanvasUi = {
|
|
107
110
|
rootClass: 'iso-canvas', panKeyClass: 'pan-key', newOrder: a.kinds.map(k => k.kind),
|
|
108
111
|
palette: v.palette
|
|
109
|
-
? v.palette.map(e => ({ kind: e.kind, label: e.label, icon: (e.icon ?? icon(e.kind)) as IconName, name: e.name, ...(e.value === undefined ? {} : { value: () => structuredClone(e.value) }) }))
|
|
112
|
+
? 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) }) }))
|
|
110
113
|
: a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
114
|
+
...(v.paletteLayout === undefined ? {} : { paletteLayout: v.paletteLayout }),
|
|
111
115
|
text: {
|
|
112
116
|
stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
|
|
113
117
|
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.',
|
package/src/iso-objects/board.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// card above it, and its column one right of every card left of it, asked of the two things that part them (so each
|
|
6
6
|
// container's rows and columns are its own, and near-aligned boxes share them); a card in no region keeps its place
|
|
7
7
|
// across. Two cards in one cell get a column each. A region (or a node
|
|
8
|
-
// holding nodes) is a panel over the cells of what it holds; one holding nothing has no cell and isn't shown
|
|
8
|
+
// holding nodes) is a panel over the cells of what it holds; one holding nothing has no cell and isn't shown (in a
|
|
9
|
+
// drawing with no nodes at all, the innermost regions are the cards). Routes
|
|
9
10
|
// are links, their ends' sides dropped. What 2D leaves out: sizes (every card is the same size), heights, a route's
|
|
10
11
|
// sides and via points, a region's label style.
|
|
11
12
|
|
|
@@ -22,7 +23,9 @@ import { placeBoard, type Board, type BoardCard, type BoardLink, type BoardPanel
|
|
|
22
23
|
export function boardOf(scene: CompiledScene, visible: (id: string) => boolean = () => true): Required<Board> {
|
|
23
24
|
const items = scene.layout.items.filter(p => visible(p.id));
|
|
24
25
|
const cat = scene.layout.catalog;
|
|
25
|
-
|
|
26
|
+
// (0.12.2) a drawing of regions alone has no nodes to be cards: its innermost regions are (else 2D would be empty)
|
|
27
|
+
const bare = !scene.layout.items.some(p => p.type === 'node');
|
|
28
|
+
const isCard = (p: Placed) => (bare ? !p.children.some(c => visible(c.id)) : p.type === 'node' && !p.children.some(c => c.type === 'node' && visible(c.id)));
|
|
26
29
|
const cardsP = items.filter(isCard);
|
|
27
30
|
// rows and columns: a card is a row below every card above it, and a column right of every card left of it, asked of
|
|
28
31
|
// the two things that part them (the children of their nearest common container holding each: their regions, or the
|
|
@@ -68,6 +71,7 @@ export function boardOf(scene: CompiledScene, visible: (id: string) => boolean =
|
|
|
68
71
|
} else taken.set(String(c), p.id);
|
|
69
72
|
}
|
|
70
73
|
const cards: BoardCard[] = cardsP.map(p => {
|
|
74
|
+
if (p.region) { const r = p.region; return { id: p.id, label: r.label ?? p.id, sub: undefined, role: r.role ?? regionKind(cat, r.kind)?.role ?? 'grey', ghost: r.ghost || undefined, cell: cell.get(p.id)! }; }
|
|
71
75
|
const n = p.node!, a = nodeKindOr(cat, n.asset);
|
|
72
76
|
return { id: p.id, label: n.label ?? p.id, sub: n.sub, role: n.role ?? a.role, ghost: n.ghost || undefined, cell: cell.get(p.id)! };
|
|
73
77
|
});
|
package/src/iso-objects/scene.ts
CHANGED
|
@@ -183,8 +183,10 @@ function drawFlatRegion(k: Kernel, cat: KindCatalog, r: Placed, vis: Attrs, grid
|
|
|
183
183
|
const style = R['label-style'] ?? rk?.labelStyle;
|
|
184
184
|
if (R.label && style !== 'none') {
|
|
185
185
|
if (style === 'face') {
|
|
186
|
-
|
|
187
|
-
const
|
|
186
|
+
// (0.12.2) a thin slab's face can't hold the large name: it has the small one, in the middle of the face
|
|
187
|
+
const h = b.z1 - b.z0, cap = (f: { size: number }) => (f.size * 0.73) / S, thin = shape === 'slab' && 0.28 + cap(FONTS.slabname) + 0.08 > h;
|
|
188
|
+
const big = shape === 'slab' && !thin;
|
|
189
|
+
const z = big ? b.z0 + 0.28 : thin ? b.z0 + Math.max(0.02, (h - cap(FONTS.sm)) / 2) : b.z0 + Math.min(0.1, h * 0.25);
|
|
188
190
|
s += tag('g', attrs, k.faceText(b.x0 + (big ? 0.6 : 0.3), b.y1, z, R.label, big ? 'slabname' : 'slabname sm', big ? FONTS.slabname : FONTS.sm, 'left', 'start'));
|
|
189
191
|
} else if (style === 'face-right') {
|
|
190
192
|
s += tag('g', attrs, k.faceText(b.x1, b.y0 + 0.6, b.z0 + Math.max(0.14, (b.z1 - b.z0) * 0.2), R.label, 'slabname', FONTS.slabname, 'right', 'end'));
|
package/src/iso-viewer/index.ts
CHANGED
|
@@ -36,5 +36,5 @@ export { flatSvg, flatCss, measureIn, rectOf } from './flat-view.ts';
|
|
|
36
36
|
export type { FlatStyle } from './flat-view.ts';
|
|
37
37
|
export { dualView, storedMode, viewToggle, DUAL_VIEW_CSS } from './dual-view.ts';
|
|
38
38
|
export type { ViewMode, DualViewOptions, DualView } from './dual-view.ts';
|
|
39
|
-
export { morphSvgs, markConnectors } from './morph.ts';
|
|
40
|
-
export type { SvgMorph } from './morph.ts';
|
|
39
|
+
export { morphSvgs, markConnectors, buildLayer, ease, clamp } from './morph.ts';
|
|
40
|
+
export type { SvgMorph, MorphLayer } from './morph.ts';
|
package/src/iso-viewer/morph.ts
CHANGED
|
@@ -91,8 +91,11 @@ function topFace(g: Element, origin: DOMRect): { pts: [number, number][]; fill:
|
|
|
91
91
|
return pts.length === 4 ? { pts, fill: getComputedStyle(poly).fill } : undefined;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
export
|
|
94
|
+
/** a morph's layer: append `svg` to the root; `at(t)` paints it t (0 to 1) of the way, in any order (no clock) */
|
|
95
|
+
export interface MorphLayer { svg: SVGSVGElement; at(t: number): void }
|
|
96
|
+
/** the layer a morph draws on: `at(t)` paints it t of the way from one view to the other. Both views are in the root and
|
|
97
|
+
* laid out (hidden is fine, display: none is not): a host seeks it frame by frame (0.12.2: exported). */
|
|
98
|
+
export function buildLayer(root: HTMLElement, fromSvg: SVGSVGElement, toSvg: SVGSVGElement, from: ViewMode): MorphLayer {
|
|
96
99
|
const origin = root.getBoundingClientRect();
|
|
97
100
|
const layer = document.createElementNS(NS, 'svg') as SVGSVGElement;
|
|
98
101
|
layer.setAttribute('class', 'dual-morph');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Ajv2020 as Ajv2020Class } from 'ajv/dist/2020.js';
|
|
2
2
|
import type { ValidateFunction } from 'ajv';
|
|
3
|
-
export declare const Ajv2020: typeof
|
|
3
|
+
export declare const Ajv2020: typeof Ajv2020Class;
|
|
4
4
|
export declare const AJV_OPTIONS: {
|
|
5
5
|
readonly allErrors: true;
|
|
6
6
|
readonly verbose: true;
|
|
@@ -86,6 +86,10 @@ export interface CanvasUi {
|
|
|
86
86
|
/** the palette's entries: a kind, and (0.10.0) a preset: what a new one starts as (default: the kind's template) and
|
|
87
87
|
* the base of its fresh name (default: the kind's singular) */
|
|
88
88
|
palette: PaletteItem[];
|
|
89
|
+
/** (0.12.0) where the palette is: 'floating' (the default: over the canvas, at its top left) or 'docked' (a pane of
|
|
90
|
+
* its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
|
|
91
|
+
* width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
|
|
92
|
+
paletteLayout?: 'floating' | 'docked';
|
|
89
93
|
text: {
|
|
90
94
|
stage: string;
|
|
91
95
|
dragGroup: string;
|
|
@@ -104,6 +108,10 @@ export interface PaletteItem {
|
|
|
104
108
|
label: string;
|
|
105
109
|
value?(): unknown;
|
|
106
110
|
name?: string;
|
|
111
|
+
/** (0.11.0) the header it is listed under: entries with one are grouped by it, in order of first use, each group under
|
|
112
|
+
* a header that collapses (all collapsed but the one last added from, remembered in the host's store as
|
|
113
|
+
* `canvas-palette`); entries without one are listed as before, where they are */
|
|
114
|
+
section?: string;
|
|
107
115
|
}
|
|
108
116
|
/** what the canvas is given of the domain (M: the domain's reading of the file; D: its drawing) */
|
|
109
117
|
export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
@@ -34,7 +34,11 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
34
34
|
icon?: string;
|
|
35
35
|
value?: unknown;
|
|
36
36
|
name?: string;
|
|
37
|
+
section?: string;
|
|
37
38
|
}[];
|
|
39
|
+
/** (0.12.0) the palette 'floating' over the canvas (the default) or 'docked': a pane of its own at the canvas's left,
|
|
40
|
+
* searchable by label and section, resizable and collapsible */
|
|
41
|
+
paletteLayout?: 'floating' | 'docked';
|
|
38
42
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
39
43
|
flat?: CanvasKit<R, D>['flat'];
|
|
40
44
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function playerScript(): string;
|
|
@@ -27,5 +27,5 @@ export { flatSvg, flatCss, measureIn, rectOf } from './flat-view.js';
|
|
|
27
27
|
export type { FlatStyle } from './flat-view.js';
|
|
28
28
|
export { dualView, storedMode, viewToggle, DUAL_VIEW_CSS } from './dual-view.js';
|
|
29
29
|
export type { ViewMode, DualViewOptions, DualView } from './dual-view.js';
|
|
30
|
-
export { morphSvgs, markConnectors } from './morph.js';
|
|
31
|
-
export type { SvgMorph } from './morph.js';
|
|
30
|
+
export { morphSvgs, markConnectors, buildLayer, ease, clamp } from './morph.js';
|
|
31
|
+
export type { SvgMorph, MorphLayer } from './morph.js';
|
|
@@ -21,8 +21,11 @@ export declare function morphSvgs(root: HTMLElement, fromSvg: SVGSVGElement, toS
|
|
|
21
21
|
}): SvgMorph | undefined;
|
|
22
22
|
export declare const clamp: (v: number) => number;
|
|
23
23
|
export declare const ease: (t: number) => number;
|
|
24
|
-
/**
|
|
25
|
-
export
|
|
24
|
+
/** a morph's layer: append `svg` to the root; `at(t)` paints it t (0 to 1) of the way, in any order (no clock) */
|
|
25
|
+
export interface MorphLayer {
|
|
26
26
|
svg: SVGSVGElement;
|
|
27
27
|
at(t: number): void;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
/** the layer a morph draws on: `at(t)` paints it t of the way from one view to the other. Both views are in the root and
|
|
30
|
+
* laid out (hidden is fine, display: none is not): a host seeks it frame by frame (0.12.2: exported). */
|
|
31
|
+
export declare function buildLayer(root: HTMLElement, fromSvg: SVGSVGElement, toSvg: SVGSVGElement, from: ViewMode): MorphLayer;
|