@johnoscott/isometric-engine 0.12.6 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +194 -184
- package/iso-render.js +157 -148
- package/iso-systems.js +170 -159
- 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/js/iso-objects/ants.js +36 -0
- package/js/iso-objects/index.js +47 -1
- package/js/iso-objects/looks.js +25 -0
- package/js/iso-objects/motion-builder.js +130 -0
- package/js/iso-objects/motion-doc.js +500 -0
- package/js/iso-objects/motion-entry.js +32 -0
- package/js/iso-objects/motion.js +635 -0
- package/js/iso-objects/resolve.js +238 -0
- package/js/iso-objects/scene.js +15 -13
- package/js/iso-objects/timeline.js +553 -0
- package/js/iso-systems/compile.js +59 -1
- package/js/iso-systems/index.js +4 -1
- package/js/iso-systems/render.js +20 -0
- package/js/iso-systems/schema.json +39 -0
- package/js/iso-viewer/page.js +2 -1
- package/js/iso-viewer/player.js +23 -34
- package/package.json +46 -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/src/iso-objects/ants.ts +53 -0
- package/src/iso-objects/compile.ts +4 -1
- package/src/iso-objects/index.ts +14 -1
- package/src/iso-objects/looks.ts +21 -0
- package/src/iso-objects/motion-builder.ts +79 -0
- package/src/iso-objects/motion-doc.ts +361 -0
- package/src/iso-objects/motion-entry.ts +12 -0
- package/src/iso-objects/motion.ts +616 -0
- package/src/iso-objects/resolve.ts +196 -0
- package/src/iso-objects/scene.ts +29 -13
- package/src/iso-objects/timeline.ts +443 -0
- package/src/iso-objects/types.ts +20 -2
- package/src/iso-systems/compile.ts +58 -3
- package/src/iso-systems/index.ts +4 -1
- package/src/iso-systems/render.ts +41 -0
- package/src/iso-systems/schema.json +39 -0
- package/src/iso-viewer/page.ts +2 -1
- package/src/iso-viewer/player.ts +24 -41
- 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
- package/types/iso-objects/ants.d.ts +33 -0
- package/types/iso-objects/compile.d.ts +3 -0
- package/types/iso-objects/index.d.ts +14 -1
- package/types/iso-objects/looks.d.ts +4 -0
- package/types/iso-objects/motion-builder.d.ts +105 -0
- package/types/iso-objects/motion-doc.d.ts +787 -0
- package/types/iso-objects/motion-entry.d.ts +10 -0
- package/types/iso-objects/motion.d.ts +200 -0
- package/types/iso-objects/resolve.d.ts +20 -0
- package/types/iso-objects/scene.d.ts +11 -0
- package/types/iso-objects/timeline.d.ts +46 -0
- package/types/iso-objects/types.d.ts +32 -0
- package/types/iso-systems/compile.d.ts +20 -3
- package/types/iso-systems/index.d.ts +4 -1
- package/types/iso-systems/render.d.ts +21 -0
|
@@ -29,6 +29,29 @@
|
|
|
29
29
|
"scenes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/scene" } }
|
|
30
30
|
},
|
|
31
31
|
"$defs": {
|
|
32
|
+
"motion": {
|
|
33
|
+
"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
34
|
+
"description": "how this piece (a region: its contents too) moves when the drawing assembles or disassembles",
|
|
35
|
+
"properties": {
|
|
36
|
+
"style": { "enum": ["edge", "drop", "rise", "fly", "pop", "scatter", "build", "fade"], "description": "how it arrives" },
|
|
37
|
+
"out": { "enum": ["explode", "lift-off", "sink", "scatter", "fly-out", "collapse", "fade", "reverse"], "description": "how it leaves" },
|
|
38
|
+
"easing": { "enum": ["linear", "ease", "ease-in", "ease-out", "settle", "spring", "bounce"] },
|
|
39
|
+
"from": { "enum": ["left", "right", "top", "bottom"], "description": "fly: the side it comes from" },
|
|
40
|
+
"delay": { "type": "number", "minimum": 0, "description": "ms after its turn" },
|
|
41
|
+
"duration": { "type": "number", "exclusiveMinimum": 0, "description": "ms its own move takes" }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"variants": {
|
|
45
|
+
"type": "object", "minProperties": 1, "propertyNames": { "$ref": "#/$defs/id" },
|
|
46
|
+
"description": "other looks of it, by name, for a motion to switch to (its box stays as it is)",
|
|
47
|
+
"additionalProperties": {
|
|
48
|
+
"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
49
|
+
"properties": {
|
|
50
|
+
"role": { "type": "string" }, "ghost": { "type": "boolean" }, "label": { "type": "string" }, "sub": { "type": "string" },
|
|
51
|
+
"face": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }, "deco": { "type": "array", "items": { "$ref": "#/$defs/deco" } }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
32
55
|
"id": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]*$" },
|
|
33
56
|
"grid": {
|
|
34
57
|
"type": "object",
|
|
@@ -88,6 +111,18 @@
|
|
|
88
111
|
"properties": {
|
|
89
112
|
"id": { "$ref": "#/$defs/id" },
|
|
90
113
|
"title": { "type": "string" },
|
|
114
|
+
"ants": {
|
|
115
|
+
"description": "its connectors march, showing which way they flow: all that may, these, or with a speed (units a second) and a dash",
|
|
116
|
+
"anyOf": [
|
|
117
|
+
{ "type": "boolean" },
|
|
118
|
+
{ "type": "array", "items": { "type": "string" } },
|
|
119
|
+
{ "type": "object", "additionalProperties": false, "properties": {
|
|
120
|
+
"ids": { "type": "array", "items": { "type": "string" } },
|
|
121
|
+
"speed": { "type": "number" },
|
|
122
|
+
"dash": { "type": "array", "items": { "type": "number", "exclusiveMinimum": 0 }, "minItems": 2, "maxItems": 2 } } }
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"motion": { "type": "object", "description": "the scene's motion document (isomotion/1; its `isomotion: 1` may be left out)" },
|
|
91
126
|
"caption": { "type": "string" },
|
|
92
127
|
"aria": { "type": "string" },
|
|
93
128
|
"gap": { "type": "number", "exclusiveMinimum": 0 },
|
|
@@ -143,6 +178,8 @@
|
|
|
143
178
|
},
|
|
144
179
|
"around": { "type": "array", "items": { "$ref": "#/$defs/id" }, "description": "tunnel: routes it wraps" },
|
|
145
180
|
"regions": { "type": "array", "items": { "$ref": "#/$defs/region" } },
|
|
181
|
+
"motion": { "$ref": "#/$defs/motion" },
|
|
182
|
+
"variants": { "$ref": "#/$defs/variants" },
|
|
146
183
|
"nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } }
|
|
147
184
|
}
|
|
148
185
|
},
|
|
@@ -188,6 +225,8 @@
|
|
|
188
225
|
"dy": { "type": "number" }
|
|
189
226
|
}
|
|
190
227
|
},
|
|
228
|
+
"motion": { "$ref": "#/$defs/motion" },
|
|
229
|
+
"variants": { "$ref": "#/$defs/variants" },
|
|
191
230
|
"nodes": { "type": "array", "items": { "$ref": "#/$defs/node" }, "description": "nodes standing on top of this one" }
|
|
192
231
|
}
|
|
193
232
|
},
|
package/js/iso-viewer/page.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { motionModel } from "../iso-objects/motion.js";
|
|
1
2
|
import { esc } from "../iso-core/kernel.js";
|
|
2
3
|
import { themeCss } from "../iso-core/theme.js";
|
|
3
4
|
import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
|
|
@@ -19,7 +20,7 @@ function stepData(c) {
|
|
|
19
20
|
steps: s.steps.steps.map((st) => ({ ...st, caption: md(st.caption) })),
|
|
20
21
|
assemble: s.assemble,
|
|
21
22
|
grid: !!s.grid.show,
|
|
22
|
-
|
|
23
|
+
motion: motionModel(s)
|
|
23
24
|
}))
|
|
24
25
|
});
|
|
25
26
|
}
|
package/js/iso-viewer/player.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { focusView } from "../iso-objects/focus.js";
|
|
2
|
+
import { paint, planOf } from "../iso-objects/motion.js";
|
|
2
3
|
const NS = "http://www.w3.org/2000/svg";
|
|
3
4
|
const TRAVEL = 1150;
|
|
4
|
-
const EASE_IN = "cubic-bezier(.16,.84,.3,1)";
|
|
5
5
|
function svgEl(tag, attrs, parent) {
|
|
6
6
|
const e = document.createElementNS(NS, tag);
|
|
7
7
|
for (const k in attrs) e.setAttribute(k, String(attrs[k]));
|
|
@@ -59,7 +59,7 @@ function init() {
|
|
|
59
59
|
const flowPath = (id) => svg.querySelector(`[data-hl="${CSS.escape(id)}"] path.flow`);
|
|
60
60
|
if (sd.dim === "all") svg.classList.add("dim-all");
|
|
61
61
|
let cur = 0, playing = false, userPaused = false, active = false, timer = 0, raf = 0, groups = 0, t0 = 0;
|
|
62
|
-
let assembling = false, assembled = false,
|
|
62
|
+
let assembling = false, assembled = false, introTimer = 0, introDone;
|
|
63
63
|
let tokens = [];
|
|
64
64
|
const setGrid = (on) => {
|
|
65
65
|
svg.classList.toggle("show-grid", on);
|
|
@@ -199,53 +199,42 @@ function init() {
|
|
|
199
199
|
userPaused = true;
|
|
200
200
|
stop();
|
|
201
201
|
}
|
|
202
|
-
const
|
|
203
|
-
const layer = (name) => svg.querySelector(`.g-${name}`);
|
|
202
|
+
const plan = planOf(sd.motion, "assemble");
|
|
204
203
|
function finishAssemble() {
|
|
205
|
-
if (
|
|
206
|
-
for (const a of animations) a.finish();
|
|
204
|
+
if (assembling) introDone?.();
|
|
207
205
|
}
|
|
208
206
|
function assemble(freezeAt) {
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
clearTimeout(introTimer);
|
|
208
|
+
introDone = void 0;
|
|
211
209
|
stop();
|
|
212
210
|
if (N) show(cur);
|
|
213
211
|
clearAnim();
|
|
214
212
|
svg.classList.remove("focus", "pre-assemble", "all");
|
|
215
213
|
assembling = true;
|
|
216
|
-
const run = (el, frames, delay, dur, easing = EASE_IN) => animations.push(el.animate(frames, { delay, duration: dur, easing, fill: "backwards" }));
|
|
217
|
-
const solid = ["base", "blocks", "air"].map(layer).filter(Boolean);
|
|
218
|
-
for (const p of A.pieces) {
|
|
219
|
-
const from = `translate(${p.dx}px, ${p.dy}px)`;
|
|
220
|
-
for (const L of solid) L.querySelectorAll(`[data-id="${CSS.escape(p.id)}"]`).forEach((el) => run(el, [{ transform: from }, { transform: "translate(0px, 0px)" }], p.delay, p.dur));
|
|
221
|
-
}
|
|
222
|
-
for (const r of A.routes) {
|
|
223
|
-
const g = layer("flows")?.querySelector(`[data-hl="${CSS.escape(r.id)}"]`);
|
|
224
|
-
const path = g?.querySelector("path.flow");
|
|
225
|
-
if (!g || !path) continue;
|
|
226
|
-
const len = path.getTotalLength();
|
|
227
|
-
run(g, [{ opacity: 0 }, { opacity: 1 }], r.delay, 80, "linear");
|
|
228
|
-
run(path, [{ strokeDasharray: `${len} ${len}`, strokeDashoffset: len }, { strokeDasharray: `${len} ${len}`, strokeDashoffset: 0 }], r.delay, r.dur, "ease-out");
|
|
229
|
-
}
|
|
230
|
-
for (const name of ["floor", "labels", "badges"]) {
|
|
231
|
-
const L = layer(name);
|
|
232
|
-
if (L) run(L, [{ opacity: 0 }, { opacity: 1 }], A.labels.delay, A.labels.dur, "ease-out");
|
|
233
|
-
}
|
|
234
214
|
if (freezeAt !== void 0) {
|
|
235
|
-
|
|
236
|
-
a.pause();
|
|
237
|
-
a.currentTime = freezeAt;
|
|
238
|
-
}
|
|
215
|
+
paint(svg, plan.at(freezeAt));
|
|
239
216
|
return;
|
|
240
217
|
}
|
|
241
|
-
|
|
218
|
+
const start = performance.now();
|
|
219
|
+
introDone = () => {
|
|
220
|
+
clearTimeout(introTimer);
|
|
221
|
+
introDone = void 0;
|
|
222
|
+
paint(svg, {});
|
|
242
223
|
assembling = false;
|
|
243
224
|
assembled = true;
|
|
244
|
-
animations = [];
|
|
245
225
|
if (N) show(cur);
|
|
246
226
|
if (active && !userPaused) play();
|
|
247
|
-
}
|
|
248
|
-
|
|
227
|
+
};
|
|
228
|
+
const step = () => {
|
|
229
|
+
const t = performance.now() - start;
|
|
230
|
+
if (t >= plan.duration) {
|
|
231
|
+
introDone?.();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
paint(svg, plan.at(t));
|
|
235
|
+
introTimer = window.setTimeout(step, 16);
|
|
236
|
+
};
|
|
237
|
+
step();
|
|
249
238
|
}
|
|
250
239
|
asmBtn?.addEventListener("click", () => {
|
|
251
240
|
userPaused = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnoscott/isometric-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "A generic isometric diagram engine: render (L0–L2) and editor (L0–L3), with a 2D view and a YAML diagram format.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -49,6 +49,11 @@
|
|
|
49
49
|
"types": "./iso-systems.d.ts",
|
|
50
50
|
"default": "./iso-systems.js"
|
|
51
51
|
},
|
|
52
|
+
"./motion": {
|
|
53
|
+
"types": "./types/iso-objects/motion-entry.d.ts",
|
|
54
|
+
"source": "./src/iso-objects/motion-entry.ts",
|
|
55
|
+
"default": "./js/iso-objects/motion-entry.js"
|
|
56
|
+
},
|
|
52
57
|
"./modules/iso-core/compile-schema": {
|
|
53
58
|
"types": "./types/iso-core/compile-schema.d.ts",
|
|
54
59
|
"source": "./src/iso-core/compile-schema.ts",
|
|
@@ -109,6 +114,11 @@
|
|
|
109
114
|
"source": "./src/iso-core/vdom.ts",
|
|
110
115
|
"default": "./js/iso-core/vdom.js"
|
|
111
116
|
},
|
|
117
|
+
"./modules/iso-objects/ants": {
|
|
118
|
+
"types": "./types/iso-objects/ants.d.ts",
|
|
119
|
+
"source": "./src/iso-objects/ants.ts",
|
|
120
|
+
"default": "./js/iso-objects/ants.js"
|
|
121
|
+
},
|
|
112
122
|
"./modules/iso-objects/assemble": {
|
|
113
123
|
"types": "./types/iso-objects/assemble.d.ts",
|
|
114
124
|
"source": "./src/iso-objects/assemble.ts",
|
|
@@ -164,11 +174,36 @@
|
|
|
164
174
|
"source": "./src/iso-objects/labels.ts",
|
|
165
175
|
"default": "./js/iso-objects/labels.js"
|
|
166
176
|
},
|
|
177
|
+
"./modules/iso-objects/looks": {
|
|
178
|
+
"types": "./types/iso-objects/looks.d.ts",
|
|
179
|
+
"source": "./src/iso-objects/looks.ts",
|
|
180
|
+
"default": "./js/iso-objects/looks.js"
|
|
181
|
+
},
|
|
182
|
+
"./modules/iso-objects/motion-builder": {
|
|
183
|
+
"types": "./types/iso-objects/motion-builder.d.ts",
|
|
184
|
+
"source": "./src/iso-objects/motion-builder.ts",
|
|
185
|
+
"default": "./js/iso-objects/motion-builder.js"
|
|
186
|
+
},
|
|
187
|
+
"./modules/iso-objects/motion-doc": {
|
|
188
|
+
"types": "./types/iso-objects/motion-doc.d.ts",
|
|
189
|
+
"source": "./src/iso-objects/motion-doc.ts",
|
|
190
|
+
"default": "./js/iso-objects/motion-doc.js"
|
|
191
|
+
},
|
|
192
|
+
"./modules/iso-objects/motion": {
|
|
193
|
+
"types": "./types/iso-objects/motion.d.ts",
|
|
194
|
+
"source": "./src/iso-objects/motion.ts",
|
|
195
|
+
"default": "./js/iso-objects/motion.js"
|
|
196
|
+
},
|
|
167
197
|
"./modules/iso-objects/place": {
|
|
168
198
|
"types": "./types/iso-objects/place.d.ts",
|
|
169
199
|
"source": "./src/iso-objects/place.ts",
|
|
170
200
|
"default": "./js/iso-objects/place.js"
|
|
171
201
|
},
|
|
202
|
+
"./modules/iso-objects/resolve": {
|
|
203
|
+
"types": "./types/iso-objects/resolve.d.ts",
|
|
204
|
+
"source": "./src/iso-objects/resolve.ts",
|
|
205
|
+
"default": "./js/iso-objects/resolve.js"
|
|
206
|
+
},
|
|
172
207
|
"./modules/iso-objects/route": {
|
|
173
208
|
"types": "./types/iso-objects/route.d.ts",
|
|
174
209
|
"source": "./src/iso-objects/route.ts",
|
|
@@ -184,6 +219,11 @@
|
|
|
184
219
|
"source": "./src/iso-objects/steps.ts",
|
|
185
220
|
"default": "./js/iso-objects/steps.js"
|
|
186
221
|
},
|
|
222
|
+
"./modules/iso-objects/timeline": {
|
|
223
|
+
"types": "./types/iso-objects/timeline.d.ts",
|
|
224
|
+
"source": "./src/iso-objects/timeline.ts",
|
|
225
|
+
"default": "./js/iso-objects/timeline.js"
|
|
226
|
+
},
|
|
187
227
|
"./modules/iso-objects/types": {
|
|
188
228
|
"types": "./types/iso-objects/types.d.ts",
|
|
189
229
|
"source": "./src/iso-objects/types.ts",
|
|
@@ -502,6 +542,11 @@
|
|
|
502
542
|
"source": "./src/iso-systems/nodes.ts",
|
|
503
543
|
"default": "./js/iso-systems/nodes.js"
|
|
504
544
|
},
|
|
545
|
+
"./modules/iso-systems/render": {
|
|
546
|
+
"types": "./types/iso-systems/render.d.ts",
|
|
547
|
+
"source": "./src/iso-systems/render.ts",
|
|
548
|
+
"default": "./js/iso-systems/render.js"
|
|
549
|
+
},
|
|
505
550
|
"./modules/iso-systems/validate": {
|
|
506
551
|
"types": "./types/iso-systems/validate.d.ts",
|
|
507
552
|
"source": "./src/iso-systems/validate.ts",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Making way for a dragged thing: which of the things beside it would step aside, and where to. Pure arithmetic on boxes in the
|
|
2
|
+
// container's own grid; the canvas says when (its dwell) and draws it (ui/drag-way.ts).
|
|
3
|
+
// - Only what the dragged thing's cells overlap, and what those then overlap, moves: at most MAX_CHAIN things, all the same way.
|
|
4
|
+
// - The fewest whole cells; among equals, the way the dragged thing was going; never back towards where it came from.
|
|
5
|
+
// - Clear of everything else and of the dragged thing, inside the container's margin. If there is no such place, undefined.
|
|
6
|
+
|
|
7
|
+
/** a drop that overlaps waits this long on one cell before anything shows (ms) */
|
|
8
|
+
export const DWELL_HINT = 150;
|
|
9
|
+
/** and this long, from the same start, before the things in its way give way (ms) */
|
|
10
|
+
export const DWELL_GIVE = 700;
|
|
11
|
+
/** what gave way goes back this long after the dragged thing no longer needs the place (ms) */
|
|
12
|
+
export const BACK_AFTER = 250;
|
|
13
|
+
/** a thing's glide to its place, or back (ms) */
|
|
14
|
+
export const GLIDE = 180;
|
|
15
|
+
/** the jiggle: how far (screen px), and how often (a second) */
|
|
16
|
+
export const JIGGLE = { px: 1.5, hz: 8 };
|
|
17
|
+
/** the most things that may step aside for one drop */
|
|
18
|
+
export const MAX_CHAIN = 3;
|
|
19
|
+
|
|
20
|
+
export interface Rect { x0: number; y0: number; x1: number; y1: number }
|
|
21
|
+
export interface Beside extends Rect {
|
|
22
|
+
id: string;
|
|
23
|
+
/** whether it may be pinned somewhere else */
|
|
24
|
+
movable: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface WayOptions {
|
|
27
|
+
/** where the dragged thing would be */
|
|
28
|
+
foot: Rect;
|
|
29
|
+
/** everything else in the container */
|
|
30
|
+
others: Beside[];
|
|
31
|
+
/** the way it was going: its last step, or from where it started */
|
|
32
|
+
going: [number, number];
|
|
33
|
+
/** what a thing that steps aside must stay in (the container, less its margin); none: anywhere */
|
|
34
|
+
bounds?: Rect;
|
|
35
|
+
max?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const E = 1e-6;
|
|
39
|
+
export const hits = (a: Rect, b: Rect) => a.x0 < b.x1 - E && a.x1 > b.x0 + E && a.y0 < b.y1 - E && a.y1 > b.y0 + E;
|
|
40
|
+
const at = (b: Rect, [dx, dy]: [number, number]): Rect => ({ x0: b.x0 + dx, y0: b.y0 + dy, x1: b.x1 + dx, y1: b.y1 + dy });
|
|
41
|
+
|
|
42
|
+
/** The steps (whole cells) of what would move, by id; undefined: nothing can make way. */
|
|
43
|
+
export function makeWay({ foot, others, going, bounds, max = MAX_CHAIN }: WayOptions): Map<string, [number, number]> | undefined {
|
|
44
|
+
const first = others.filter(o => hits(o, foot));
|
|
45
|
+
if (!first.length) return new Map();
|
|
46
|
+
if (first.some(o => !o.movable)) return undefined;
|
|
47
|
+
const ways: [number, number][] = [[1, 0], [-1, 0], [0, 1], [0, -1]];
|
|
48
|
+
let best: { steps: Map<string, [number, number]>; cells: number; along: number } | undefined;
|
|
49
|
+
for (const w of ways) {
|
|
50
|
+
const along = w[0] * going[0] + w[1] * going[1];
|
|
51
|
+
// back to where it came from: against its larger component
|
|
52
|
+
if (along < 0 && Math.abs(along) >= Math.max(Math.abs(going[0]), Math.abs(going[1])) - E) continue;
|
|
53
|
+
const steps = push(foot, others, w, bounds, max);
|
|
54
|
+
if (!steps) continue;
|
|
55
|
+
const cells = [...steps.values()].reduce((n, [dx, dy]) => n + Math.abs(dx) + Math.abs(dy), 0);
|
|
56
|
+
if (!best || cells < best.cells || (cells === best.cells && along > best.along + E)) best = { steps, cells, along };
|
|
57
|
+
}
|
|
58
|
+
return best?.steps;
|
|
59
|
+
}
|
|
60
|
+
/** all that is in the way, pushed one way by whole cells until each is clear of what pushes it */
|
|
61
|
+
function push(foot: Rect, others: Beside[], w: [number, number], bounds: Rect | undefined, max: number): Map<string, [number, number]> | undefined {
|
|
62
|
+
const far = new Map<string, number>(); // cells, by id
|
|
63
|
+
const byId = new Map<string, Beside>(others.map(o => [o.id, o]));
|
|
64
|
+
const boxOf = (o: Beside) => at(o, [w[0] * (far.get(o.id) ?? 0), w[1] * (far.get(o.id) ?? 0)]);
|
|
65
|
+
// what pushes: the dragged thing first, then each that moved (again, if it moved again)
|
|
66
|
+
const queue: (string | undefined)[] = [undefined];
|
|
67
|
+
for (let guard = 0; queue.length; guard++) {
|
|
68
|
+
if (guard > 100) return undefined;
|
|
69
|
+
const id = queue.shift(), by = id === undefined ? foot : boxOf(byId.get(id)!);
|
|
70
|
+
for (const o of others) {
|
|
71
|
+
if (o.id === id) continue;
|
|
72
|
+
const b = boxOf(o);
|
|
73
|
+
if (!hits(b, by)) continue;
|
|
74
|
+
if (!o.movable) return undefined;
|
|
75
|
+
const gap = w[0] > 0 ? by.x1 - b.x0 : w[0] < 0 ? b.x1 - by.x0 : w[1] > 0 ? by.y1 - b.y0 : b.y1 - by.y0;
|
|
76
|
+
far.set(o.id, (far.get(o.id) ?? 0) + Math.max(1, Math.ceil(gap - E)));
|
|
77
|
+
if (far.size > max) return undefined;
|
|
78
|
+
if (!queue.includes(o.id)) queue.push(o.id);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const steps = new Map([...far].map(([id, n]) => [id, [w[0] * n, w[1] * n] as [number, number]]));
|
|
82
|
+
// clear of everything, the dragged thing too, and inside
|
|
83
|
+
for (const id of steps.keys()) {
|
|
84
|
+
const o = byId.get(id)!, b = boxOf(o);
|
|
85
|
+
if (hits(b, foot) || others.some(q => q.id !== id && hits(b, boxOf(q)))) return undefined;
|
|
86
|
+
if (bounds && (b.x0 < bounds.x0 - E || b.y0 < bounds.y0 - E || b.x1 > bounds.x1 + E || b.y1 > bounds.y1 + E)) return undefined;
|
|
87
|
+
}
|
|
88
|
+
return steps;
|
|
89
|
+
}
|
|
@@ -260,6 +260,10 @@ body.read-only .palette { display: none; }
|
|
|
260
260
|
.pal-grip { flex: none; width: 6px; margin: 0 -3px; cursor: col-resize; z-index: 3; position: relative; }
|
|
261
261
|
.pal-grip:hover, .pal-grip:focus-visible { background: color-mix(in srgb, var(--accent) 30%, transparent); outline: 0; }
|
|
262
262
|
body.read-only .pal-dock, body.read-only .pal-grip { display: none; }
|
|
263
|
+
.palette.looks .pal-item { height: auto; min-height: 40px; }
|
|
264
|
+
.palette.looks .pal-look { display: block; flex: 0 0 44px; width: 44px; height: 36px; margin: 0; padding: 0; background: none; pointer-events: none; overflow: hidden; }
|
|
265
|
+
.palette.looks .pal-scene { display: block; width: 100%; height: 100%; }
|
|
266
|
+
.palette.looks .pal-item > .icon { margin: 0 15px; }
|
|
263
267
|
.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); }
|
|
264
268
|
.pal-ghost .icon { width: 14px; height: 14px; }
|
|
265
269
|
.pal-ghost.bad { border-color: var(--bad); color: var(--bad); }
|