@johnoscott/isometric-engine 0.10.1 → 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 (56) hide show
  1. package/EDITOR-GUIDE.md +12 -1
  2. package/README.md +1 -1
  3. package/assets/app.css +37 -0
  4. package/assets/icons.svg +1 -1
  5. package/iso-editor.js +182 -182
  6. package/iso-render.js +105 -105
  7. package/iso-systems.js +108 -108
  8. package/js/iso-editor/commands.js +7 -0
  9. package/js/iso-editor/connections.js +24 -0
  10. package/js/iso-editor/doc.js +4 -0
  11. package/js/iso-editor/model.js +17 -3
  12. package/js/iso-editor/ui/actions.js +22 -24
  13. package/js/iso-editor/ui/canvas.js +277 -20
  14. package/js/iso-editor/ui/mount.js +2 -1
  15. package/js/iso-editor/ui/plain-icons.js +2 -0
  16. package/js/iso-editor/ui/props.js +2 -2
  17. package/js/iso-editor/ui/rename.js +114 -0
  18. package/js/iso-editor/ui/setup.js +3 -1
  19. package/js/iso-objects/board.js +6 -1
  20. package/js/iso-objects/scene.js +3 -2
  21. package/js/iso-viewer/index.js +4 -1
  22. package/js/iso-viewer/viewport.js +17 -5
  23. package/package.json +92 -92
  24. package/src/iso-core/compile-schema.ts +3 -1
  25. package/src/iso-editor/commands.ts +9 -0
  26. package/src/iso-editor/connections.ts +28 -0
  27. package/src/iso-editor/doc.ts +6 -0
  28. package/src/iso-editor/model.ts +17 -3
  29. package/src/iso-editor/ui/actions.ts +20 -23
  30. package/src/iso-editor/ui/app.css +37 -0
  31. package/src/iso-editor/ui/canvas.ts +214 -25
  32. package/src/iso-editor/ui/mount.ts +4 -3
  33. package/src/iso-editor/ui/plain-icons.ts +2 -0
  34. package/src/iso-editor/ui/props.ts +3 -3
  35. package/src/iso-editor/ui/rename.ts +105 -0
  36. package/src/iso-editor/ui/setup.ts +9 -2
  37. package/src/iso-objects/board.ts +6 -2
  38. package/src/iso-objects/scene.ts +4 -2
  39. package/src/iso-viewer/index.ts +2 -2
  40. package/src/iso-viewer/morph.ts +5 -2
  41. package/src/iso-viewer/viewport.ts +25 -5
  42. package/types/iso-core/compile-schema.d.ts +2 -2
  43. package/types/iso-editor/connections.d.ts +8 -0
  44. package/types/iso-editor/model.d.ts +8 -2
  45. package/types/iso-editor/ui/actions.d.ts +5 -2
  46. package/types/iso-editor/ui/canvas.d.ts +18 -1
  47. package/types/iso-editor/ui/monaco-entry.d.ts +2 -0
  48. package/types/iso-editor/ui/mount.d.ts +6 -2
  49. package/types/iso-editor/ui/props.d.ts +1 -1
  50. package/types/iso-editor/ui/rename.d.ts +43 -0
  51. package/types/iso-editor/ui/setup.d.ts +6 -0
  52. package/types/iso-systems/validate.d.ts +4 -0
  53. package/types/iso-viewer/bundle.d.ts +1 -0
  54. package/types/iso-viewer/index.d.ts +2 -2
  55. package/types/iso-viewer/morph.d.ts +6 -3
  56. package/types/iso-viewer/viewport.d.ts +13 -1
@@ -2,6 +2,7 @@ const PLAIN_ICON_SVG = {
2
2
  "arrow-up-right": '<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',
3
3
  "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" />',
4
4
  "chevron-down": '<path d="m6 9 6 6 6-6" />',
5
+ "chevron-left": '<path d="m15 18-6-6 6-6" />',
5
6
  "chevron-right": '<path d="m9 18 6-6-6-6" />',
6
7
  "circle-dot": '<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',
7
8
  "circle-x": '<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',
@@ -17,6 +18,7 @@ const PLAIN_ICON_SVG = {
17
18
  "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" />',
18
19
  "plus": '<path d="M5 12h14" /> <path d="M12 5v14" />',
19
20
  "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" />',
21
+ "search": '<path d="m21 21-4.34-4.34" /> <circle cx="11" cy="11" r="8" />',
20
22
  "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" />',
21
23
  "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" />',
22
24
  "x": '<path d="M18 6 6 18" /> <path d="m6 6 12 12" />'
@@ -12,7 +12,7 @@ function propsPanel(body, doc, opts) {
12
12
  let focusInput = false;
13
13
  const K = opts.kit, ui = K.ui;
14
14
  const { setCmd, deleteCmd, insertItemCmd, referencesTo, describe } = K.commands;
15
- const { deletePaths, renameDialog } = K.actions;
15
+ const { deletePaths, rename } = K.actions;
16
16
  const kindOf = (k) => K.kinds.find((x) => x.kind === k);
17
17
  const singular = (k) => kindOf(k)?.singular ?? "item";
18
18
  const names = (s) => Object.keys(getIn(doc.goodDoc.data, kindOf(s)?.section ?? []) ?? {}).filter((k) => !k.startsWith("x-"));
@@ -47,7 +47,7 @@ function propsPanel(body, doc, opts) {
47
47
  }
48
48
  const head = h("div", { class: "sel-headrow" }, h("div", { class: "sel-title" }, describe(target)));
49
49
  const rn = h("button", { type: "button", class: "btn sm quiet icon-only", "aria-label": `Rename ${describe(target)}`, title: "Rename (F2)" }, icon("pencil"));
50
- rn.addEventListener("click", () => renameDialog(doc, target, "props", opts.note));
50
+ rn.addEventListener("click", () => void rename(doc, target, "props", opts.note, { over: true, place: () => head.isConnected ? head.firstElementChild.getBoundingClientRect() : void 0 }));
51
51
  head.append(rn);
52
52
  body.append(head);
53
53
  if (toPointer(p) !== r.path) pendingFocus = toPointer(p);
@@ -0,0 +1,114 @@
1
+ import { h } from "./icons.js";
2
+ import { layer } from "./layer.js";
3
+ let open;
4
+ const renameOpen = () => !!open;
5
+ function renameField(f, at) {
6
+ open?.close();
7
+ return new Promise((resolve) => {
8
+ const back = at.back ?? document.activeElement;
9
+ const id = `rename-${Math.random().toString(36).slice(2, 8)}`;
10
+ const input = h("input", { type: "text", class: "rename-input", "aria-label": f.label, "aria-describedby": id, spellcheck: "false", autocomplete: "off", autocapitalize: "off" });
11
+ const why = h("p", { class: "rename-error", role: "alert", id });
12
+ const box = h("div", { class: `rename-field${at.over ? " over" : ""}` }, input, why);
13
+ input.value = f.value;
14
+ const fitWidth = () => {
15
+ input.size = Math.max(8, Math.min(40, input.value.length + 1));
16
+ };
17
+ fitWidth();
18
+ layer().append(box);
19
+ let done = false, frame = 0, seen = at.at ? { left: at.at.x, top: at.at.y, width: 0, height: 0 } : void 0;
20
+ const put = () => {
21
+ const p = at.place();
22
+ if (p) seen = p;
23
+ const b = at.bounds?.() ?? { left: 0, top: 0, right: innerWidth, bottom: innerHeight }, r = input.getBoundingClientRect();
24
+ const t = seen ?? { left: (b.left + b.right) / 2, top: b.top + 48, width: 0, height: 0 };
25
+ const within = (v, lo, hi) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
26
+ 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`;
27
+ 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`;
28
+ };
29
+ const follow = () => {
30
+ if (done) return;
31
+ if (f.alive && !f.alive()) {
32
+ end(void 0, false);
33
+ return;
34
+ }
35
+ put();
36
+ frame = requestAnimationFrame(follow);
37
+ };
38
+ const check = () => {
39
+ const bad = f.wrong(input.value.trim());
40
+ why.textContent = bad;
41
+ input.setAttribute("aria-invalid", String(!!bad));
42
+ return bad;
43
+ };
44
+ const good = () => {
45
+ const v = input.value.trim();
46
+ return v !== f.value && !f.wrong(v) ? v : void 0;
47
+ };
48
+ function end(v, focusBack, late = false) {
49
+ if (done) return;
50
+ done = true;
51
+ cancelAnimationFrame(frame);
52
+ removeEventListener("pointerdown", outside, true);
53
+ box.remove();
54
+ open = void 0;
55
+ if (focusBack && back?.isConnected) back.focus({ preventScroll: true });
56
+ const save = () => {
57
+ if (v !== void 0 && (!f.alive || f.alive())) f.commit(v);
58
+ resolve(v);
59
+ };
60
+ if (!late || v === void 0) {
61
+ save();
62
+ return;
63
+ }
64
+ const up = () => {
65
+ removeEventListener("pointerup", up, true);
66
+ removeEventListener("pointercancel", up, true);
67
+ setTimeout(wait, 0);
68
+ };
69
+ const wait = () => {
70
+ if (at.busy?.()) setTimeout(wait, 20);
71
+ else save();
72
+ };
73
+ addEventListener("pointerup", up, true);
74
+ addEventListener("pointercancel", up, true);
75
+ }
76
+ const outside = (e) => {
77
+ if (!box.contains(e.target)) end(good(), false, !!at.late?.contains(e.target));
78
+ };
79
+ addEventListener("pointerdown", outside, true);
80
+ input.addEventListener("input", () => {
81
+ fitWidth();
82
+ check();
83
+ });
84
+ input.addEventListener("keydown", (e) => {
85
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "s") {
86
+ end(good(), true);
87
+ return;
88
+ }
89
+ e.stopPropagation();
90
+ if (e.isComposing) return;
91
+ if (e.key === "Escape") {
92
+ e.preventDefault();
93
+ end(void 0, true);
94
+ }
95
+ if (e.key === "Enter") {
96
+ e.preventDefault();
97
+ const v = input.value.trim();
98
+ if (!check()) end(v === f.value ? void 0 : v, true);
99
+ }
100
+ });
101
+ input.addEventListener("keyup", (e) => e.stopPropagation());
102
+ input.addEventListener("blur", () => setTimeout(() => {
103
+ if (!done && document.hasFocus() && document.activeElement !== input && document.activeElement !== document.body) end(good(), false);
104
+ }, 0));
105
+ open = { close: () => end(void 0, false) };
106
+ follow();
107
+ input.focus({ preventScroll: true });
108
+ input.select();
109
+ });
110
+ }
111
+ export {
112
+ renameField,
113
+ renameOpen
114
+ };
@@ -76,7 +76,9 @@ function setupFor(a, v, textPane) {
76
76
  rootClass: "iso-canvas",
77
77
  panKeyClass: "pan-key",
78
78
  newOrder: a.kinds.map((k) => k.kind),
79
- palette: v.palette ? v.palette.map((e) => ({ kind: e.kind, label: e.label, icon: e.icon ?? icon(e.kind), name: e.name, ...e.value === void 0 ? {} : { value: () => structuredClone(e.value) } })) : a.kinds.map((k) => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
79
+ palette: v.palette ? v.palette.map((e) => ({ kind: e.kind, label: e.label, icon: e.icon ?? icon(e.kind), name: e.name, ...e.section === void 0 ? {} : { section: e.section }, ...e.value === void 0 ? {} : { value: () => structuredClone(e.value) } })) : a.kinds.map((k) => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
80
+ ...v.paletteLayout === void 0 ? {} : { paletteLayout: v.paletteLayout },
81
+ ...v.doubleClick === void 0 ? {} : { doubleClick: v.doubleClick },
80
82
  text: {
81
83
  stage: "The file, drawn: arrow keys and Tab move through what is drawn; + and \u2212 zoom, 0 fits",
82
84
  dragGroup: "A drag on nothing",
@@ -5,7 +5,8 @@ import { placeBoard } from "./flat.js";
5
5
  function boardOf(scene, visible = () => true) {
6
6
  const items = scene.layout.items.filter((p) => visible(p.id));
7
7
  const cat = scene.layout.catalog;
8
- const isCard = (p) => p.type === "node" && !p.children.some((c) => c.type === "node" && visible(c.id));
8
+ const bare = !scene.layout.items.some((p) => p.type === "node");
9
+ const isCard = (p) => bare ? !p.children.some((c) => visible(c.id)) : p.type === "node" && !p.children.some((c) => c.type === "node" && visible(c.id));
9
10
  const cardsP = items.filter(isCard);
10
11
  const line = (p) => {
11
12
  const a = [];
@@ -57,6 +58,10 @@ function boardOf(scene, visible = () => true) {
57
58
  } else taken.set(String(c), p.id);
58
59
  }
59
60
  const cards = cardsP.map((p) => {
61
+ if (p.region) {
62
+ const r = p.region;
63
+ return { id: p.id, label: r.label ?? p.id, sub: void 0, role: r.role ?? regionKind(cat, r.kind)?.role ?? "grey", ghost: r.ghost || void 0, cell: cell.get(p.id) };
64
+ }
60
65
  const n = p.node, a = nodeKindOr(cat, n.asset);
61
66
  return { id: p.id, label: n.label ?? p.id, sub: n.sub, role: n.role ?? a.role, ghost: n.ghost || void 0, cell: cell.get(p.id) };
62
67
  });
@@ -160,8 +160,9 @@ function drawFlatRegion(k, cat, r, vis, gridStep = 1) {
160
160
  const style = R["label-style"] ?? rk?.labelStyle;
161
161
  if (R.label && style !== "none") {
162
162
  if (style === "face") {
163
- const big = shape === "slab";
164
- const z = big ? b.z0 + 0.28 : b.z0 + Math.min(0.1, (b.z1 - b.z0) * 0.25);
163
+ const h = b.z1 - b.z0, cap = (f) => f.size * 0.73 / S, thin = shape === "slab" && 0.28 + cap(FONTS.slabname) + 0.08 > h;
164
+ const big = shape === "slab" && !thin;
165
+ 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);
165
166
  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"));
166
167
  } else if (style === "face-right") {
167
168
  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"));
@@ -16,7 +16,7 @@ import { memorySource } from "./timeline-engine.js";
16
16
  import { modeFor, activityOf, mountTimeline } from "./history.js";
17
17
  import { flatSvg, flatCss, measureIn, rectOf } from "./flat-view.js";
18
18
  import { dualView, storedMode, viewToggle, DUAL_VIEW_CSS } from "./dual-view.js";
19
- import { morphSvgs, markConnectors } from "./morph.js";
19
+ import { morphSvgs, markConnectors, buildLayer, ease, clamp } from "./morph.js";
20
20
  export {
21
21
  APPEARS,
22
22
  BASE_FIELDS,
@@ -35,10 +35,13 @@ export {
35
35
  attr,
36
36
  binNext,
37
37
  binStart,
38
+ buildLayer,
38
39
  cardMotion,
40
+ clamp,
39
41
  cls,
40
42
  crumbs,
41
43
  dualView,
44
+ ease,
42
45
  escapeName,
43
46
  extent,
44
47
  findGaps,
@@ -1,3 +1,16 @@
1
+ const INSET = 6;
2
+ function fitted(s, box, also) {
3
+ const pad = 24;
4
+ const most = (len, a0, a1, b0, b1) => Math.min((len - pad * 2) / (a1 - a0), ...b0 === void 0 || b1 === void 0 ? [] : [[b1 - b0, INSET * 2], [b1 - a0, pad + INSET], [a1 - b0, pad + INSET]].map(([d, edges]) => d > 0 ? (len - edges) / d : Infinity));
5
+ 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))));
6
+ const middle = (len, a0, a1, b0, b1) => {
7
+ const c = (a0 + a1) / 2;
8
+ if (b0 === void 0 || b1 === void 0) return c;
9
+ const lo = b1 - (len / 2 - INSET) / k, hi = b0 + (len / 2 - INSET) / k;
10
+ return lo > hi ? (lo + hi) / 2 : Math.max(lo, Math.min(hi, c));
11
+ };
12
+ 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) };
13
+ }
1
14
  const MIN_ZOOM = 0.1, MAX_ZOOM = 8;
2
15
  function viewport(host, o) {
3
16
  let view, full;
@@ -51,11 +64,9 @@ function viewport(host, o) {
51
64
  view = { x: p.x - (px - r.left) / nk, y: p.y - (py - r.top) / nk, w: s.w / nk, h: s.h / nk };
52
65
  applyView();
53
66
  }
54
- function fit(box = full) {
67
+ function fit(box = full, also) {
55
68
  if (!box) return;
56
- const s = size(), pad = 24;
57
- const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min((s.w - pad * 2) / box.w, (s.h - pad * 2) / box.h)));
58
- const cx = box.x + box.w / 2, cy = box.y + box.h / 2;
69
+ const s = size(), { k, cx, cy } = fitted(s, box, also);
59
70
  const next = { x: cx - s.w / k / 2, y: cy - s.h / k / 2, w: s.w / k, h: s.h / k };
60
71
  if (view && Math.abs(next.w / view.w - 1) < 1e-3 && Math.abs(next.h / view.h - 1) < 1e-3 && Math.abs(next.x - view.x) < next.w * 1e-3 && Math.abs(next.y - view.y) < next.h * 1e-3) {
61
72
  applyView();
@@ -72,7 +83,7 @@ function viewport(host, o) {
72
83
  if (key === last) break;
73
84
  last = key;
74
85
  const m = Math.max(24, Math.min(b.w, b.h) * 0.06);
75
- quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }));
86
+ quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }, o.alsoBox?.()));
76
87
  if (!o.marksShowing() || !paintedK || Math.abs(scale() / paintedK - 1) <= 0.02) break;
77
88
  cancelAnimationFrame(rezoom);
78
89
  rezoom = 0;
@@ -173,5 +184,6 @@ function viewport(host, o) {
173
184
  export {
174
185
  MAX_ZOOM,
175
186
  MIN_ZOOM,
187
+ fitted,
176
188
  viewport
177
189
  };