feat(skin): add local sibling ordering

This commit is contained in:
illusia committed 2026-10-10 15:53:50 +08:00
1 parent 11a07eae0f
commit 1499d60bc0
12 files changed
+78 -15

No files matched your search

+5 -2
View File
@@ -58,7 +58,7 @@ test("valid layouts accept only bounded positions and safe visual tokens", () =>
pages: {
home: {
desktop: {
"home.header": { x: -120, y: 40, scale: 1.25, visible: true, foreground: "#aabbcc", radius: 16 },
"home.header": { x: -120, y: 40, scale: 1.25, order: -2, visible: true, foreground: "#aabbcc", radius: 16 },
"control.button": { background: "#010203", border: "#ffffff" },
},
mobile: { "home.join-card": { x: 8, scale: 0.9 } },
@@ -68,6 +68,7 @@ test("valid layouts accept only bounded positions and safe visual tokens", () =>
});
assert.equal(layout.pages.home?.desktop?.["home.header"]?.x, -120);
assert.equal(layout.pages.home?.desktop?.["home.header"]?.foreground, "#aabbcc");
assert.equal(layout.pages.home?.desktop?.["home.header"]?.order, -2);
assert.equal(layout.pages.home?.tablet?.["home.join-card"]?.width, 720);
assert.equal(getSkinLayoutComponents("home").some((component) => component.id === "home.join-card"), true);
assert.equal(getSkinLayoutComponents("voice").some((component) => component.id === "home.join-card"), false);
@@ -128,9 +129,11 @@ test("layout validation fails closed for unknown pages, components, trusted noti
{ schemaVersion: 1, pages: { admin: { desktop: {} } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.not-registered": { x: 0 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { order: -1 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { app: { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { position: "fixed" } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { x: 2001 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { order: 101 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { width: 8 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "voice.connection-status": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { background: "url(https://example.invalid)" } } } } },
@@ -147,7 +150,7 @@ test("registered components carry accessibility, responsive, purpose, and data-s
assert.ok(["core", "optional", "trusted-chrome"].includes(component.category));
if (component.editable) {
assert.deepEqual(component.allowedContainers, ["app"]);
assert.deepEqual(component.layoutModes, ["position", "size", "visibility", "appearance"]);
assert.deepEqual(component.layoutModes, ["position", "size", "visibility", "appearance", "order"]);
assert.ok(component.minWidth > 0 && component.maxWidth >= component.minWidth);
assert.ok(component.minHeight > 0 && component.maxHeight >= component.minHeight);
assert.ok(component.minScale > 0 && component.maxScale >= component.minScale);
+7 -3
View File
@@ -6,6 +6,7 @@ export interface SkinLayoutPlacement {
x?: number;
y?: number;
scale?: number;
order?: number;
width?: number;
height?: number;
foreground?: string;
@@ -28,7 +29,7 @@ export interface SkinLayoutComponent {
purpose: "host-shell" | "host-action" | "session-content" | "identity-content" | "page-content" | "decoration" | "trusted-status";
category: "core" | "optional" | "trusted-chrome";
allowedContainers: readonly string[];
layoutModes: readonly ("position" | "size" | "visibility" | "appearance")[];
layoutModes: readonly ("position" | "size" | "visibility" | "appearance" | "order")[];
dataSensitivity: "none" | "public" | "session" | "identity";
keyboardBehavior: "host-native";
focusOrder: "host-dom";
@@ -341,7 +342,7 @@ function pageOfPart(id: string): SkinLayoutPage | "common" | null {
return null;
}
const LAYOUT_MODES = ["position", "size", "visibility", "appearance"] as const;
const LAYOUT_MODES = ["position", "size", "visibility", "appearance", "order"] as const;
const STYLE_TOKENS = ["foreground", "background", "border", "radius"] as const;
const COMPONENT_NAME_PARTS: Record<string, string> = {
action: "Action", actions: "Actions", activity: "Activity", add: "Add", app: "Application", artwork: "Artwork",
@@ -485,7 +486,7 @@ export function getSkinLayoutComponentId(part: string | undefined, controlKind?:
}
const ALLOWED_PLACEMENT_FIELDS = new Set([
"visible", "x", "y", "scale", "width", "height", "foreground", "background", "border", "radius",
"visible", "x", "y", "scale", "order", "width", "height", "foreground", "background", "border", "radius",
]);
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -544,6 +545,7 @@ export function validateSkinLayout(value: unknown): SkinLayoutDocument {
if (component.layoutModes.includes("position")) { supportedFields.add("x"); supportedFields.add("y"); }
if (component.layoutModes.includes("size")) { supportedFields.add("scale"); supportedFields.add("width"); supportedFields.add("height"); }
if (component.layoutModes.includes("appearance")) component.allowedStyleTokens.forEach((token) => supportedFields.add(token));
if (component.layoutModes.includes("order")) supportedFields.add("order");
assertOnlyKeys(rawPlacement, supportedFields, "Skin component placement");
const placement: SkinLayoutPlacement = {};
if (rawPlacement.visible !== undefined) {
@@ -553,12 +555,14 @@ export function validateSkinLayout(value: unknown): SkinLayoutDocument {
const x = readNumber(rawPlacement.x, "x", -2000, 2000);
const y = readNumber(rawPlacement.y, "y", -2000, 2000);
const scale = readNumber(rawPlacement.scale, "scale", component.minScale, component.maxScale);
const order = readNumber(rawPlacement.order, "order", -100, 100);
const width = readNumber(rawPlacement.width, "width", component.minWidth, component.maxWidth);
const height = readNumber(rawPlacement.height, "height", component.minHeight, component.maxHeight);
const radius = readNumber(rawPlacement.radius, "radius", 0, 64);
if (x !== undefined) placement.x = x;
if (y !== undefined) placement.y = y;
if (scale !== undefined) placement.scale = scale;
if (order !== undefined) placement.order = order;
if (width !== undefined) placement.width = width;
if (height !== undefined) placement.height = height;
if (radius !== undefined) placement.radius = radius;