Add widget catalog and restore canvas preview tools
This commit is contained in:
1 parent
12a8c24441
commit
beeca041ef
13 files changed
+489
-35
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { runInNewContext } from "node:vm";
|
||||
import { normalizeLayout, validate } from "./src/layout.ts";
|
||||
import { alignmentGuide, builtInLayout, deviceMapper, normalizeLayout, validate } from "./src/layout.ts";
|
||||
|
||||
const fixtures = JSON.parse(readFileSync(new URL("../docs/layout-cases.json", import.meta.url), "utf8"));
|
||||
const offline = readFileSync(new URL("./canvas.html", import.meta.url), "utf8");
|
||||
@@ -39,3 +39,31 @@ for (const { name, accepted, layout } of fixtures) {
|
||||
assert.equal(offlineAccepted, accepted, "Offline editor: " + name);
|
||||
}
|
||||
console.log(`${fixtures.length} shared cases passed in both editors`);
|
||||
|
||||
const layout = builtInLayout();
|
||||
const { canvas } = layout;
|
||||
const items = layout.pages[0].items;
|
||||
const tall = { w: 1080, h: 2160 };
|
||||
const wide = { w: 1536, h: 2048 };
|
||||
const centered = { mode: "contain", anchorY: 0.5 };
|
||||
assert.deepEqual(deviceMapper(canvas, centered, items, tall).insets,
|
||||
{ top: 120, bottom: 120, left: 0, right: 0 });
|
||||
assert.deepEqual(deviceMapper(canvas, { ...centered, anchorY: 0 }, items, tall).insets,
|
||||
{ top: 0, bottom: 240, left: 0, right: 0 });
|
||||
assert.deepEqual(deviceMapper(canvas, centered, items, wide).insets,
|
||||
{ top: 0, bottom: 0, left: 192, right: 192 });
|
||||
const elastic = deviceMapper(canvas, { ...centered, mode: "elastic" }, items, tall);
|
||||
assert.equal(elastic.mode, "elastic");
|
||||
assert.ok(elastic.gapScale > 1);
|
||||
assert.equal(elastic.insets, undefined);
|
||||
assert.equal(deviceMapper(canvas, { ...centered, mode: "elastic" }, items, wide).mode, "contain");
|
||||
const stretch = deviceMapper(canvas, { ...centered, mode: "stretch" }, items, tall);
|
||||
assert.equal(stretch.insets, undefined);
|
||||
assert.ok(stretch.sy > stretch.sx);
|
||||
console.log("Tall and wide preview mappings passed");
|
||||
|
||||
assert.equal(alignmentGuide(82, 36, [100, 120], 4), 100);
|
||||
assert.equal(alignmentGuide(82, 36, [120, 118], 4), 118);
|
||||
assert.equal(alignmentGuide(82, 36, [122], 3), undefined);
|
||||
assert.equal(alignmentGuide(0, 36, [0], 0), 0);
|
||||
console.log("Drag alignment guides passed");
|
||||
Reference in new issue
Block a user