diff --git a/INTEGRATION.md b/INTEGRATION.md index b73b025..9d8c5c6 100644 --- a/INTEGRATION.md +++ b/INTEGRATION.md @@ -61,6 +61,8 @@ $env:LAUNCHER_DEVICE_TOKEN = '<设备令牌>' 手机断网、令牌无效或新布局校验失败时,继续显示本地布局。冷启动依次读取主布局、上次有效布局和内置布局,如果三个来源都不可用则显示内存兜底桌面。 +画布的「小组件目录」与「布局发布」共用当前页面的管理员令牌。读取目录后可切换「第三方小组件」和「系统小组件」,并按组件名称、应用名称、组件类名或应用包名搜索并添加到当前页,再调整尺寸和位置。添加到画布后按正常流程发布,设备首次使用组件仍需进行 Android 授权。 + ## HTTP 接口 管理接口使用 `Authorization: Bearer `。设备接口使用 `Authorization: Bearer `。 @@ -70,6 +72,8 @@ $env:LAUNCHER_DEVICE_TOKEN = '<设备令牌>' | `GET /healthz` | 服务健康状态 | | `GET /api/layout` | 下发 v3 布局。设备可传 `If-None-Match`,版本内容相同时返回 304 | | `GET /api/admin/layout` | 获取线上布局及其 `ETag` | +| `GET /api/admin/widget-providers` | 读取系统与第三方 AppWidget Provider 目录 | +| `PUT /api/admin/widget-providers` | 幂等导入目录。每项可用组件字符串,或包含 `component`、`label`、`appLabel` 和可选 `category` 的对象(`system` 或 `third-party`) | | `PUT /api/admin/layout` | 发布布局 JSON。通过 `If-Match` 传入当前线上 `ETag` | | `GET /api/admin/history?before=整数` | 按版本倒序读取历史,每次最多 50 条。首次查询省略 `before` | | `GET /api/admin/history/{revision}` | 获取某一版本的布局 | @@ -91,7 +95,7 @@ $env:LAUNCHER_DEVICE_TOKEN = '<设备令牌>' | --- | --- | | 服务器 | `175.178.213.60`,Debian 12,k3s 单节点,SSH 密钥登录 | | 命名空间 / 工作负载 | `vibe-launcher` / `deploy/vibe-launcher-backend`,单副本 `Recreate` | -| 镜像 | `docker.io/library/vibe-launcher-backend:1.1.0-deploy3`,`imagePullPolicy: IfNotPresent` | +| 镜像 | `docker.io/library/vibe-launcher-backend:1.1.0-deploy7`,`imagePullPolicy: IfNotPresent` | | 端口 | 容器 8080,Service NodePort **30830**(30800 是 youlai-boot,30810 是 tts-server,30820 是 compose-remote-server) | | 公网入口 | `https://api.ttstd.com/launcher/`(灰云直连源站,不走 Cloudflare);nginx 剥掉 `/launcher/` 前缀后反代 `127.0.0.1:30830` | | 数据 | 宿主机 `/opt/vibe-launcher/data/layouts.sqlite` 挂到容器 `/data`,Pod 重建不丢版本历史 | diff --git a/backend/deploy/deploy.yaml b/backend/deploy/deploy.yaml index 41dbd65..b90e870 100644 --- a/backend/deploy/deploy.yaml +++ b/backend/deploy/deploy.yaml @@ -26,7 +26,7 @@ spec: spec: containers: - name: server - image: docker.io/library/vibe-launcher-backend:1.1.0-deploy3 + image: docker.io/library/vibe-launcher-backend:1.1.0-deploy7 imagePullPolicy: IfNotPresent ports: - name: http diff --git a/backend/src/main/java/com/ttstd/launcher/LayoutController.java b/backend/src/main/java/com/ttstd/launcher/LayoutController.java index 492bf5b..dd086f2 100644 --- a/backend/src/main/java/com/ttstd/launcher/LayoutController.java +++ b/backend/src/main/java/com/ttstd/launcher/LayoutController.java @@ -7,7 +7,10 @@ import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.StandardCharsets; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.CacheControl; @@ -28,6 +31,8 @@ import tools.jackson.databind.node.ObjectNode; @RestController class LayoutController { + private static final Pattern WIDGET_COMPONENT = Pattern.compile( + "[a-zA-Z_$][a-zA-Z0-9_.$]*/(?:\\.)?[a-zA-Z_$][a-zA-Z0-9_.$]*"); private static final long MAX_SAFE_INTEGER = 9_007_199_254_740_991L; private static final MediaType JSON = new MediaType("application", "json", StandardCharsets.UTF_8); private static final String EDITOR_CSP = "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; " @@ -78,6 +83,52 @@ class LayoutController { return serve(release); } + @GetMapping("/api/admin/widget-providers") + Map> widgetProviders(HttpServletRequest request, HttpServletResponse response) + throws SQLException { + policy.requireAdmin(request, response); + return Map.of("providers", store.widgetProviders()); + } + + @PutMapping("/api/admin/widget-providers") + Map> addWidgetProviders(HttpServletRequest request, HttpServletResponse response) + throws IOException, SQLException { + policy.requireAdmin(request, response); + var providers = readJson(request).path("providers"); + if (!providers.isArray() || providers.isEmpty() || providers.size() > 1000) { + throw new ApiError(400, "请选择 1–1000 个小组件 Provider"); + } + var components = new ArrayList(); + for (var provider : providers) { + var component = (provider.isObject() ? provider.path("component") : provider).stringValue(""); + if (component.length() > 512 || !WIDGET_COMPONENT.matcher(component).matches()) { + throw new ApiError(400, "小组件 Provider 格式无效"); + } + int slash = component.indexOf('/'); + if (component.charAt(slash + 1) == '.') component = component.substring(0, slash + 1) + + component.substring(0, slash) + component.substring(slash + 1); + var categoryNode = provider.path("category"); + var category = categoryNode.stringValue(""); + if (!categoryNode.isMissingNode() && !category.equals("system") && !category.equals("third-party")) { + throw new ApiError(400, "小组件分类格式无效"); + } + components.add(new LayoutStore.WidgetProvider(component, + widgetLabel(provider.path("label")), widgetLabel(provider.path("appLabel")), + categoryNode.isMissingNode() ? null : category)); + } + store.addWidgetProviders(components); + return Map.of("providers", store.widgetProviders()); + } + + private static String widgetLabel(JsonNode node) { + if (node.isMissingNode() || node.isNull()) return null; + var label = node.stringValue(null); + if (label == null || label.length() > 256 || label.codePoints().anyMatch(Character::isISOControl)) { + throw new ApiError(400, "小组件名称格式无效"); + } + return label.isBlank() ? null : label.strip(); + } + @GetMapping("/api/admin/layout") ResponseEntity adminLayout(HttpServletRequest request, HttpServletResponse response) throws SQLException { policy.requireAdmin(request, response); diff --git a/backend/src/main/java/com/ttstd/launcher/LayoutStore.java b/backend/src/main/java/com/ttstd/launcher/LayoutStore.java index 33c4327..7f590a3 100644 --- a/backend/src/main/java/com/ttstd/launcher/LayoutStore.java +++ b/backend/src/main/java/com/ttstd/launcher/LayoutStore.java @@ -30,6 +30,7 @@ class LayoutStore { return "\"" + java.util.HexFormat.of().formatHex(RequestPolicy.sha256(layout)) + "\""; } } + record WidgetProvider(String component, String label, String appLabel, String category) {} record HistoryEntry(int revision, String publishedAt, Integer restoredFrom) {} record History(List revisions, Integer nextBefore) {} @@ -63,6 +64,22 @@ class LayoutStore { restoredFrom INTEGER REFERENCES releases(revision) ) STRICT """); + statement.execute(""" + CREATE TABLE IF NOT EXISTS widget_providers ( + component TEXT PRIMARY KEY + ) STRICT + """); + for (var column : List.of("label", "app_label", "category")) { + boolean exists; + try (var check = connection.prepareStatement( + "SELECT 1 FROM pragma_table_info('widget_providers') WHERE name = ?")) { + check.setString(1, column); + try (var rows = check.executeQuery()) { + exists = rows.next(); + } + } + if (!exists) statement.execute("ALTER TABLE widget_providers ADD COLUMN " + column + " TEXT"); + } try (var seed = connection.prepareStatement(""" INSERT OR IGNORE INTO releases (revision, layout, publishedAt, restoredFrom) VALUES (1, ?, ?, NULL) @@ -87,6 +104,43 @@ class LayoutStore { } } + List widgetProviders() throws SQLException { + var providers = new ArrayList(); + try (var connection = connect(); var statement = connection.createStatement(); + var rows = statement.executeQuery(""" + SELECT component, label, app_label, COALESCE(category, 'third-party') AS category + FROM widget_providers + ORDER BY COALESCE(app_label, component), COALESCE(label, component), component + """)) { + while (rows.next()) { + providers.add(new WidgetProvider(rows.getString("component"), rows.getString("label"), + rows.getString("app_label"), rows.getString("category"))); + } + } + return providers; + } + + void addWidgetProviders(List providers) throws SQLException { + try (var connection = connect(); var insert = connection.prepareStatement(""" + INSERT INTO widget_providers (component, label, app_label, category) VALUES (?, ?, ?, ?) + ON CONFLICT (component) DO UPDATE SET + label = COALESCE(excluded.label, widget_providers.label), + app_label = COALESCE(excluded.app_label, widget_providers.app_label), + category = COALESCE(excluded.category, widget_providers.category) + """)) { + connection.setAutoCommit(false); + for (var provider : providers) { + insert.setString(1, provider.component()); + insert.setString(2, provider.label()); + insert.setString(3, provider.appLabel()); + insert.setString(4, provider.category()); + insert.addBatch(); + } + insert.executeBatch(); + connection.commit(); + } + } + Release latest() throws SQLException { try (var connection = connect(); var statement = connection.createStatement(); var rows = statement.executeQuery(LATEST)) { diff --git a/backend/src/test/java/com/ttstd/launcher/LayoutApiTest.java b/backend/src/test/java/com/ttstd/launcher/LayoutApiTest.java index cb3ce32..2cc49e3 100644 --- a/backend/src/test/java/com/ttstd/launcher/LayoutApiTest.java +++ b/backend/src/test/java/com/ttstd/launcher/LayoutApiTest.java @@ -34,6 +34,43 @@ class LayoutApiTest { @TempDir Path dir; + @Test + void widgetCatalogRequiresAdminAndPersistsUniqueComponents() throws Exception { + String path = "/api/admin/widget-providers"; + Path database = dir.resolve("widgets.sqlite"); + try (var connection = DriverManager.getConnection("jdbc:sqlite:" + database); + var statement = connection.createStatement()) { + statement.execute("CREATE TABLE widget_providers (component TEXT PRIMARY KEY) STRICT"); + } + MockMvc mvc = mvc(database); + mvc.perform(get(path).header("Authorization", DEVICE)).andExpect(status().isUnauthorized()); + mvc.perform(put(path)).andExpect(status().isUnauthorized()); + mvc.perform(put(path).header("Authorization", ADMIN).contentType(MediaType.APPLICATION_JSON) + .content(""" + {"providers":["com.example/.Widget","invalid"]} + """)) + .andExpect(status().isBadRequest()); + mvc.perform(get(path).header("Authorization", ADMIN)).andExpect(content().json(""" + {"providers":[]} + """)); + mvc.perform(put(path).header("Authorization", ADMIN).contentType(MediaType.APPLICATION_JSON) + .content(""" + {"providers":[{"component":"com.example/.Widget","label":"快捷搜索","appLabel":"示例应用"}, + "com.example/com.example.Widget", + {"component":"com.android.deskclock/.Clock","label":"时钟","category":"system"}, + "com.android.deskclock/com.android.deskclock.Clock"]} + """)) + .andExpect(status().isOk()); + mvc(database).perform(get(path).header("Authorization", ADMIN)) + .andExpect(status().isOk()) + .andExpect(content().json(""" + {"providers":[{"component":"com.example/com.example.Widget","label":"快捷搜索","appLabel":"示例应用", + "category":"third-party"}, + {"component":"com.android.deskclock/com.android.deskclock.Clock","label":"时钟", + "category":"system"}]} + """)); + } + @Test void migratedDatabaseRetainsLayoutsAndSupportsPublishRollbackAndRestart() throws Exception { Path database = dir.resolve("layouts.sqlite"); diff --git a/frontend/canvas.html b/frontend/canvas.html index a6e312b..8f0383c 100644 --- a/frontend/canvas.html +++ b/frontend/canvas.html @@ -361,11 +361,11 @@ const LIB = [ const DEVICES = [ { name:'16 : 9', w:1080, h:1920 }, - { name:'16 : 8', w:1080, h:2160 }, + { name:'18 : 9', w:1080, h:2160 }, { name:'19.5 : 9', w:1080, h:2340 }, - { name:'2K 20:9', w:1440, h:3120 }, + { name:'2K 20:9', w:1440, h:3200 }, { name:'16:10', w:1440, h:2304 }, - { name:'平板 4:3', w:1600, h:2560 }, + { name:'平板 4:3', w:1536, h:2048 }, ]; let state = newState(); @@ -692,7 +692,7 @@ function renderDevices() { } else if (fit === 'elastic' && buildMapper({w:1080,h:2160}, items, fit, anchor).elastic) { const mm = buildMapper({w:1080,h:2160}, items, 'elastic', anchor); $('devSummary').innerHTML = - `弹性行距 · 纵向余量按原空白比例放大到行间距(16:8 上 ×${mm.elastic.k.toFixed(2)}),元素尺寸不变`; + `弹性行距 · 纵向余量按原空白比例放大到行间距(18:9 上 ×${mm.elastic.k.toFixed(2)}),元素尺寸不变`; } else { let vC = 0, hC = 0, mV = 0, mH = 0; DEVICES.forEach(d => { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 425177c..ec131cf 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,14 +1,15 @@ + + diff --git a/frontend/src/LayoutSurface.vue b/frontend/src/LayoutSurface.vue index 40ac947..7d82e8f 100644 --- a/frontend/src/LayoutSurface.vue +++ b/frontend/src/LayoutSurface.vue @@ -12,6 +12,8 @@ const props = defineProps<{ selectedId?: string; editable?: boolean; guides?: boolean; + dragGuides?: { x?: number; y?: number }; + showWhitespace?: boolean; }>(); const emit = defineEmits<{ startDrag: [event: PointerEvent, item: LayoutItem, resize: boolean]; @@ -20,9 +22,20 @@ const emit = defineEmits<{ const canvas = computed(() => props.layout.canvas); const width = computed(() => props.device?.w ?? canvas.value.designWidth); const height = computed(() => props.device?.h ?? canvas.value.designHeight); -const mapper = computed(() => props.device +const deviceMap = computed(() => props.device ? deviceMapper(canvas.value, props.layout.fit, props.page.items, props.device) - : { sx: 1, sy: 1, x: (n: number) => n, y: (n: number) => n }); + : undefined); +const mapper = computed(() => deviceMap.value ?? { sx: 1, sy: 1, x: (n: number) => n, y: (n: number) => n }); +const whitespace = computed(() => { + const insets = deviceMap.value?.insets; + if (!props.showWhitespace || !insets || !Object.values(insets).some(value => value > 0.5)) return undefined; + return { + top: percent(insets.top, height.value), + bottom: percent(insets.bottom, height.value), + left: percent(insets.left, width.value), + right: percent(insets.right, width.value), + }; +}); const items = computed(() => sortedItems(props.page)); const known = new Set(["app_icon", "widget", "shortcut", "dock_bg"]); const visible = computed(() => props.editable ? items.value : items.value.filter(item => known.has(item.type))); @@ -63,5 +76,16 @@ function title(item: LayoutItem) { + + diff --git a/frontend/src/ReleaseDialog.vue b/frontend/src/ReleaseDialog.vue index 97344bb..36c431b 100644 --- a/frontend/src/ReleaseDialog.vue +++ b/frontend/src/ReleaseDialog.vue @@ -9,7 +9,7 @@ interface History { revisions: HistoryEntry[]; nextBefore: number | null } const open = defineModel({ required: true }); const props = defineProps<{ layout: Layout; hasErrors: boolean; confirmReplace: () => Promise; warnings: Issue[] }>(); const emit = defineEmits<{ load: [layout: Layout, online?: boolean]; published: [revision: number] }>(); -const token = ref(""); +const token = defineModel("token", { required: true }); const tag = ref(); const revision = ref(); const history = ref([]); diff --git a/frontend/src/layout.ts b/frontend/src/layout.ts index 58a0c77..5b40861 100644 --- a/frontend/src/layout.ts +++ b/frontend/src/layout.ts @@ -46,11 +46,11 @@ export const templates: Template[] = [ export const devices = [ { name: "16:9", w: 1080, h: 1920 }, - { name: "16:8", w: 1080, h: 2160 }, + { name: "18:9", w: 1080, h: 2160 }, { name: "19.5:9", w: 1080, h: 2340 }, - { name: "2K 20:9", w: 1440, h: 3120 }, + { name: "2K 20:9", w: 1440, h: 3200 }, { name: "16:10", w: 1440, h: 2304 }, - { name: "平板 4:3", w: 1600, h: 2560 }, + { name: "平板 4:3", w: 1536, h: 2048 }, ]; const canvasDefaults = { designWidth: 1080, designHeight: 1920, safeTop: 132, safeBottom: 72 }; @@ -153,11 +153,22 @@ export function validate(layout: Layout): Issue[] { return issues; } -export function deviceMapper(canvas: Layout["canvas"], fit: Layout["fit"], items: LayoutItem[], dev: typeof devices[number]) { +interface DeviceMapping { + mode: "contain" | "elastic" | "stretch"; + sx: number; + sy: number; + x: (value: number) => number; + y: (value: number) => number; + insets?: { left: number; right: number; top: number; bottom: number }; + gapScale?: number; +} + +export function deviceMapper(canvas: Layout["canvas"], fit: Layout["fit"], items: LayoutItem[], + dev: Pick): DeviceMapping { const sx = dev.w / canvas.designWidth; const sy = dev.h / canvas.designHeight; const mode = fit.mode.toLowerCase(); - if (mode === "stretch") return { sx, sy, x: (x: number) => x * sx, y: (y: number) => y * sy }; + if (mode === "stretch") return { mode, sx, sy, x: x => x * sx, y: y => y * sy }; const extra = dev.h - canvas.designHeight * sx; if (mode === "elastic" && extra > 0.5) { const bands: [number, number][] = []; @@ -174,9 +185,10 @@ export function deviceMapper(canvas: Layout["canvas"], fit: Layout["fit"], items previous = bottom; return [top, cumulative] as const; }); - const totalBlank = cumulative + Math.max(0, canvas.designHeight - previous) || 1; + const blankHeight = cumulative + Math.max(0, canvas.designHeight - previous); + const totalBlank = blankHeight > 0.5 ? blankHeight : 1; return { - sx, sy: sx, + mode, sx, sy: sx, gapScale: 1 + extra / totalBlank, x: (x: number) => x * sx, y: (y: number) => { let blank = 0; @@ -189,9 +201,29 @@ export function deviceMapper(canvas: Layout["canvas"], fit: Layout["fit"], items }; } const scale = Math.min(sx, sy); - const ox = (dev.w - canvas.designWidth * scale) / 2; - const oy = (dev.h - canvas.designHeight * scale) * clamp(fit.anchorY, 0, 1); - return { sx: scale, sy: scale, x: (x: number) => ox + x * scale, y: (y: number) => oy + y * scale }; + const horizontal = Math.max(0, dev.w - canvas.designWidth * scale); + const vertical = Math.max(0, dev.h - canvas.designHeight * scale); + const ox = horizontal / 2; + const oy = vertical * clamp(fit.anchorY, 0, 1); + return { + mode: "contain", sx: scale, sy: scale, + x: x => ox + x * scale, y: y => oy + y * scale, + insets: { left: ox, right: horizontal - ox, top: oy, bottom: vertical - oy }, + }; +} + +export function alignmentGuide(start: number, size: number, targetPoints: number[], tolerance: number) { + let nearest: number | undefined; + let bestDistance = Infinity; + for (const target of targetPoints) { + const distance = Math.min(Math.abs(target - start), Math.abs(target - (start + size / 2)), + Math.abs(target - (start + size))); + if (distance <= tolerance && distance < bestDistance) { + nearest = target; + bestDistance = distance; + } + } + return nearest; } export function iconColor(item: LayoutItem) { diff --git a/frontend/src/styles.css b/frontend/src/styles.css index eed82f8..ca286f6 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -56,6 +56,12 @@ small { color: #9caec3; } background: linear-gradient(#b3c8ea12 1px, transparent 1px), linear-gradient(90deg, #b3c8ea12 1px, transparent 1px); background-size: 8.333% 5%; } +.drag-guide { + position: absolute; z-index: 1; pointer-events: none; + background: #ffcb70; box-shadow: 0 0 2px #684418; +} +.drag-guide.vertical { top: 0; bottom: 0; width: 1px; } +.drag-guide.horizontal { left: 0; right: 0; height: 1px; } .safe-zone { position: absolute; left: 0; right: 0; pointer-events: none; background: #4b9cf22a; } .safe-zone.top { top: 0; border-bottom: 1px dashed #79b9fc; } .safe-zone.bottom { bottom: 0; border-top: 1px dashed #79b9fc; } @@ -120,3 +126,22 @@ pre { color: #a7ccea; font-size: 11px; max-width: 100%; overflow: auto; } .editor { order: -1; min-height: 520px; } .settings { display: grid; grid-template-columns: 1fr 1fr; } } +.preview-gap, .preview-content-boundary { + position: absolute; + pointer-events: none; + z-index: 1; +} +.preview-gap, .preview-swatch { + background: repeating-linear-gradient(135deg, #f4bb6655 0 2px, #503a2d66 2px 6px); +} +.preview-gap.top, .preview-gap.bottom { left: 0; right: 0; height: var(--gap-size); } +.preview-gap.left, .preview-gap.right { top: 0; bottom: 0; width: var(--gap-size); } +.preview-gap.top { top: 0; } +.preview-gap.bottom { bottom: 0; } +.preview-gap.left { left: 0; } +.preview-gap.right { right: 0; } +.preview-content-boundary { border: 1px dashed #f4bb66; } +.preview-legend { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; } +.preview-swatch { width: 14px; height: 10px; border: 1px solid #f4bb66; border-radius: 2px; } +.preview-legend, .whitespace-examples p { font-size: 12px; color: #b7c5d7; } +.whitespace-examples { display: grid; gap: 9px; margin-top: 16px; padding-top: 12px; border-top: 1px solid #2a3547; } diff --git a/frontend/test-layout.mjs b/frontend/test-layout.mjs index a89c17a..b5b95c5 100644 --- a/frontend/test-layout.mjs +++ b/frontend/test-layout.mjs @@ -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");