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

+4
View File
@@ -81,6 +81,10 @@
<label><span>{{ editor.labels.value.height }}</span><output>{{ Math.round(editor.selectedHeight.value) }} px</output></label>
<input type="range" :min="editor.selectedSizeBounds.value.minHeight" :max="editor.selectedSizeBounds.value.maxHeight" step="4" :value="editor.selectedHeight.value" @input="editor.setHeight(Number(($event.target as HTMLInputElement).value))" />
</div>
<div class="skin-layout-range" :title="editor.labels.value.orderHint">
<label><span>{{ editor.labels.value.order }}</span><output>{{ editor.selectedOrder.value }}</output></label>
<input type="range" min="-100" max="100" step="1" :value="editor.selectedOrder.value" @input="editor.setOrder(Number(($event.target as HTMLInputElement).value))" />
</div>
<div class="skin-layout-colors">
<label><span>{{ editor.labels.value.foreground }}</span><input type="color" :value="editor.selectedForeground.value" @input="editor.setForeground(($event.target as HTMLInputElement).value)" /></label>
@@ -109,6 +109,7 @@ export function useSkinLayoutEditor() {
const selectedHeight = computed(() => selectedPlacement.value.height ?? 160);
const selectedX = computed(() => selectedPlacement.value.x ?? 0);
const selectedY = computed(() => selectedPlacement.value.y ?? 0);
const selectedOrder = computed(() => selectedPlacement.value.order ?? 0);
const selectedForeground = computed(() => selectedPlacement.value.foreground ?? "#ffffff");
const selectedBackground = computed(() => selectedPlacement.value.background ?? "#ffffff");
const selectedBorder = computed(() => selectedPlacement.value.border ?? "#ffffff");
@@ -344,6 +345,7 @@ export function useSkinLayoutEditor() {
function setVisible(value: boolean): void { updateSelected("visible", value); }
function setX(value: number): void { updateSelected("x", clampSkinLayoutOffset(value, offsetBounds("x") ?? { minimum: -2000, maximum: 2000 })); }
function setY(value: number): void { updateSelected("y", clampSkinLayoutOffset(value, offsetBounds("y") ?? { minimum: -2000, maximum: 2000 })); }
function setOrder(value: number): void { updateSelected("order", Math.max(-100, Math.min(100, Math.round(value)))); }
function setScale(value: number): void { updateSelected("scale", Math.max(selectedSizeBounds.value.minScale, Math.min(selectedSizeBounds.value.maxScale, value))); }
function setWidth(value: number): void { updateSelected("width", Math.max(selectedSizeBounds.value.minWidth, Math.min(selectedSizeBounds.value.maxWidth, Math.round(value)))); }
function setHeight(value: number): void { updateSelected("height", Math.max(selectedSizeBounds.value.minHeight, Math.min(selectedSizeBounds.value.maxHeight, Math.round(value)))); }
@@ -631,6 +633,7 @@ export function useSkinLayoutEditor() {
focusPreviewTargets,
selectedX,
selectedY,
selectedOrder,
selectedForeground,
selectedBackground,
selectedBorder,
@@ -650,6 +653,7 @@ export function useSkinLayoutEditor() {
setVisible,
setX,
setY,
setOrder,
setScale,
setWidth,
setHeight,
+12
View File
@@ -12,6 +12,8 @@ type SkinLayoutLabels = {
size: string;
width: string;
height: string;
order: string;
orderHint: string;
foreground: string;
background: string;
border: string;
@@ -55,6 +57,8 @@ export const skinLayoutLabels: Record<Language, SkinLayoutLabels> = {
size: "缩放",
width: "宽度",
height: "高度",
order: "排列顺序",
orderHint: "仅在父容器使用 Flex 或 Grid 时影响同级顺序;键盘焦点顺序保持不变。",
foreground: "文字颜色",
background: "背景颜色",
border: "边框颜色",
@@ -96,6 +100,8 @@ export const skinLayoutLabels: Record<Language, SkinLayoutLabels> = {
size: "Scale",
width: "Width",
height: "Height",
order: "Display order",
orderHint: "Affects sibling order only inside a flex or grid parent. Keyboard focus order stays unchanged.",
foreground: "Text color",
background: "Background",
border: "Border color",
@@ -137,6 +143,8 @@ export const skinLayoutLabels: Record<Language, SkinLayoutLabels> = {
size: "Skalierung",
width: "Breite",
height: "Höhe",
order: "Anzeigereihenfolge",
orderHint: "Wirkt nur auf Geschwister in einem Flex- oder Grid-Container. Die Tastaturreihenfolge bleibt unverändert.",
foreground: "Textfarbe",
background: "Hintergrund",
border: "Rahmenfarbe",
@@ -178,6 +186,8 @@ export const skinLayoutLabels: Record<Language, SkinLayoutLabels> = {
size: "Масштаб",
width: "Ширина",
height: "Высота",
order: "Порядок отображения",
orderHint: "Меняет порядок соседей только внутри flex- или grid-контейнера. Порядок клавиатурного фокуса не меняется.",
foreground: "Цвет текста",
background: "Фон",
border: "Цвет границы",
@@ -219,6 +229,8 @@ export const skinLayoutLabels: Record<Language, SkinLayoutLabels> = {
size: "拡大縮小",
width: "幅",
height: "高さ",
order: "表示順序",
orderHint: "Flex または Grid の親要素内の兄弟要素にのみ適用されます。キーボードのフォーカス順は変わりません。",
foreground: "文字色",
background: "背景色",
border: "枠線の色",
+3 -2
View File
@@ -88,10 +88,10 @@ function setVariable(element: HTMLElement, dataFlag: string, variable: string, v
}
function clearLayoutAttributes(element: HTMLElement): void {
for (const key of ["wsLayoutActive", "wsLayoutHidden", "wsLayoutSelected", "wsLayoutForeground", "wsLayoutBackground", "wsLayoutBorder", "wsLayoutRadius", "wsLayoutWidth", "wsLayoutHeight", "wsLayoutTouchTarget"]) {
for (const key of ["wsLayoutActive", "wsLayoutHidden", "wsLayoutSelected", "wsLayoutForeground", "wsLayoutBackground", "wsLayoutBorder", "wsLayoutRadius", "wsLayoutWidth", "wsLayoutHeight", "wsLayoutOrder", "wsLayoutTouchTarget"]) {
delete element.dataset[key];
}
for (const key of ["--ws-layout-x", "--ws-layout-y", "--ws-layout-scale", "--ws-layout-width", "--ws-layout-height", "--ws-layout-foreground", "--ws-layout-background", "--ws-layout-border", "--ws-layout-radius"]) {
for (const key of ["--ws-layout-x", "--ws-layout-y", "--ws-layout-scale", "--ws-layout-order", "--ws-layout-width", "--ws-layout-height", "--ws-layout-foreground", "--ws-layout-background", "--ws-layout-border", "--ws-layout-radius"]) {
element.style.removeProperty(key);
}
}
@@ -147,6 +147,7 @@ function applyRoot(root: HTMLElement): void {
else element.style.removeProperty("--ws-layout-y");
if (placement.scale !== undefined) element.style.setProperty("--ws-layout-scale", String(placement.scale));
else element.style.removeProperty("--ws-layout-scale");
setVariable(element, "wsLayoutOrder", "--ws-layout-order", placement.order === undefined ? undefined : String(placement.order));
setVariable(element, "wsLayoutWidth", "--ws-layout-width", placement.width === undefined ? undefined : placement.width + "px");
setVariable(element, "wsLayoutHeight", "--ws-layout-height", placement.height === undefined ? undefined : placement.height + "px");
setVariable(element, "wsLayoutForeground", "--ws-layout-foreground", placement.foreground);
+2 -1
View File
@@ -84,9 +84,10 @@ test("version 2 layout overrides can be saved, loaded, and cleared per skin", ()
withLocalStorage((storage) => {
saveSkinLayoutOverrides("community.illusia-voice", {
schemaVersion: 1,
pages: { home: { mobile: { "home.header": { x: 8, visible: true } } } },
pages: { home: { mobile: { "home.header": { x: 8, visible: true, order: 2 } } } },
});
assert.equal(loadSkinLayoutOverrides("community.illusia-voice").pages.home?.mobile?.["home.header"]?.x, 8);
assert.equal(loadSkinLayoutOverrides("community.illusia-voice").pages.home?.mobile?.["home.header"]?.order, 2);
clearSkinLayoutOverrides("community.illusia-voice");
assert.deepEqual(loadSkinLayoutOverrides("community.illusia-voice"), { schemaVersion: 1, pages: {} });
assert.equal(JSON.parse(storage.getItem(SKIN_LAYOUT_STORAGE_KEY) ?? "null").schemaVersion, 2);
+4
View File
@@ -8,6 +8,10 @@
scale: var(--ws-layout-scale, 1) !important;
}
.ws-skin-root [data-ws-layout-order="true"] {
order: var(--ws-layout-order) !important;
}
.ws-skin-root [data-ws-layout-width="true"] {
width: var(--ws-layout-width) !important;
}