@adea-ai/ui 0.147.9 → 0.147.11
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/dist/components/layout/split-layout/model.d.ts +4 -9
- package/dist/components/layout/split-layout/model.d.ts.map +1 -1
- package/dist/components/layout/split-layout/model.js +9 -12
- package/dist/components/layout/split-layout/model.js.map +1 -1
- package/dist/components/theme/theme-persistence.js +4 -4
- package/dist/components/theme/theme-persistence.js.map +1 -1
- package/dist/lib/appearance-font-settings.d.ts.map +1 -1
- package/dist/lib/appearance-font-settings.js +2 -4
- package/dist/lib/appearance-font-settings.js.map +1 -1
- package/dist/r/appearance-editor.json +1 -1
- package/dist/r/lib.json +1 -1
- package/dist/r/registry.json +3 -3
- package/dist/r/src/components/layout/split-layout/model.ts +12 -12
- package/dist/r/src/components/theme/theme-persistence.ts +4 -4
- package/dist/r/src/lib/appearance-font-settings.ts +2 -9
- package/dist/r/theming.json +1 -1
- package/package.json +2 -2
- package/registry.json +3 -3
- package/src/components/layout/split-layout/model.ts +12 -12
- package/src/components/theme/theme-persistence.ts +4 -4
- package/src/lib/appearance-font-settings.ts +2 -9
|
@@ -18,15 +18,10 @@ export type BalancedSplitPaneInput<L extends SplitLayoutLeaf = SplitLayoutLeaf>
|
|
|
18
18
|
export declare function createLayoutState<L extends SplitLayoutLeaf>(center: SplitLayoutNode<L>): SplitLayoutState<L>;
|
|
19
19
|
export declare function splitPane<L extends SplitLayoutLeaf>(state: SplitLayoutState<L>, targetLeafId: string, input: SplitPaneInput<L>): SplitLayoutState<L>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* equal height. Existing opaque leaf objects are preserved. Split IDs are
|
|
26
|
-
* recycled across rebuilt branches, whose axis and descendants can change;
|
|
27
|
-
* resize actions must resolve against the current tree. Ratios are recomputed.
|
|
28
|
-
* This is opt-in: callers
|
|
29
|
-
* that need an explicit axis and ratio should keep using `splitPane`.
|
|
21
|
+
* Reflow into a balanced row-major grid of at most two rows and four columns,
|
|
22
|
+
* preserving opaque leaves. Split IDs are recycled across rebuilt branches, so
|
|
23
|
+
* resize actions must resolve against the current tree. Call `splitPane` instead
|
|
24
|
+
* when the axis and ratio must be explicit.
|
|
30
25
|
*/
|
|
31
26
|
export declare function splitPaneBalanced<L extends SplitLayoutLeaf>(state: SplitLayoutState<L>, targetLeafId: string, input: BalancedSplitPaneInput<L>): SplitLayoutState<L>;
|
|
32
27
|
export declare function closePane<L extends SplitLayoutLeaf>(state: SplitLayoutState<L>, leafId: string, createPlaceholderLeaf: () => L): SplitLayoutState<L>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../../src/components/layout/split-layout/model.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAEjF,cAAc,QAAQ,CAAA;AAEtB,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,QAAQ,CAAC;IACnF,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,SAAS,QAAQ,CAAC;QAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAA;CAC5E,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,QAAQ,CAAC;IACjF,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAC5C,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAA;IAC7B,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AA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,SAAS,EAAE,QAAQ,GAAG,OAAO,EAC7B,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,EAC5C,OAAO,EAAE,MAAM,GACd,gBAAgB,CAAC,CAAC,CAAC,CAYrB;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACnD,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,gBAAgB,CAAC,CAAC,CAAC,CAkBrB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,eAAe,EACvD,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GACzB,gBAAgB,CAAC,CAAC,CAAC,CAcrB;AAED,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,CAAC,SAAS,eAAe,EACpD,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,GACX,CAAC,GAAG,SAAS,CAKf"}
|
|
@@ -23,7 +23,8 @@ function removeLeaf(node, leafId) {
|
|
|
23
23
|
function containsLeaf(node, leafId) {
|
|
24
24
|
return node.kind === "leaf" ? node.id === leafId : containsLeaf(node.children[0], leafId) || containsLeaf(node.children[1], leafId);
|
|
25
25
|
}
|
|
26
|
-
function assertUniqueInput(state, leaf, splitId) {
|
|
26
|
+
function assertUniqueInput(state, leaf, splitId, placement) {
|
|
27
|
+
if (!leaf || leaf.kind !== "leaf" || placement !== "before" && placement !== "after") throw new Error("invalid_state: invalid split input");
|
|
27
28
|
assertLayoutTree(leaf);
|
|
28
29
|
if (typeof splitId !== "string" || splitId.length === 0) throw new Error("invalid_state: split identity must be nonempty");
|
|
29
30
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -76,8 +77,9 @@ function createLayoutState(center) {
|
|
|
76
77
|
}
|
|
77
78
|
function splitPane(state, targetLeafId, input) {
|
|
78
79
|
if (!containsLeaf(state.center, targetLeafId)) return state;
|
|
80
|
+
if (input.direction !== "row" && input.direction !== "column") throw new Error("invalid_state: invalid split input");
|
|
79
81
|
if (countLeaves(state.center) >= 8) throw new Error("limit_exceeded: center layout has eight leaves");
|
|
80
|
-
assertUniqueInput(state, input.leaf, input.splitId);
|
|
82
|
+
assertUniqueInput(state, input.leaf, input.splitId, input.placement);
|
|
81
83
|
const target = listLeaves(state.center).find((leaf) => leaf.id === targetLeafId);
|
|
82
84
|
if (!target) return state;
|
|
83
85
|
const children = input.placement === "before" ? [input.leaf, target] : [target, input.leaf];
|
|
@@ -97,22 +99,17 @@ function splitPane(state, targetLeafId, input) {
|
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* equal height. Existing opaque leaf objects are preserved. Split IDs are
|
|
105
|
-
* recycled across rebuilt branches, whose axis and descendants can change;
|
|
106
|
-
* resize actions must resolve against the current tree. Ratios are recomputed.
|
|
107
|
-
* This is opt-in: callers
|
|
108
|
-
* that need an explicit axis and ratio should keep using `splitPane`.
|
|
102
|
+
* Reflow into a balanced row-major grid of at most two rows and four columns,
|
|
103
|
+
* preserving opaque leaves. Split IDs are recycled across rebuilt branches, so
|
|
104
|
+
* resize actions must resolve against the current tree. Call `splitPane` instead
|
|
105
|
+
* when the axis and ratio must be explicit.
|
|
109
106
|
*/
|
|
110
107
|
function splitPaneBalanced(state, targetLeafId, input) {
|
|
111
108
|
const leaves = [...listLeaves(state.center)];
|
|
112
109
|
const targetIndex = leaves.findIndex((leaf) => leaf.id === targetLeafId);
|
|
113
110
|
if (targetIndex < 0) return state;
|
|
114
111
|
if (leaves.length >= 8) throw new Error("limit_exceeded: center layout has eight leaves");
|
|
115
|
-
const splitIds = assertUniqueInput(state, input.leaf, input.splitId);
|
|
112
|
+
const splitIds = assertUniqueInput(state, input.leaf, input.splitId, input.placement);
|
|
116
113
|
const insertionIndex = targetIndex + (input.placement === "before" ? 0 : 1);
|
|
117
114
|
leaves.splice(insertionIndex, 0, input.leaf);
|
|
118
115
|
const build = (start, end, vertical = false) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../../../src/components/layout/split-layout/model.ts"],"sourcesContent":["/*\n * Copyright (c) 2026 Michael Yong\n * Copyright (c) 2026 Muxy\n * SPDX-License-Identifier: MIT\n *\n * Portions of the binary split behavior are substantially translated from:\n * - get-bb/bb apps/app/src/lib/split-layout/ops.ts (MIT), revision\n * 52a9256373d4d36f9b60e9e2a7f333464091a2ac.\n * - muxy-app/muxy Muxy/Models/Workspace/SplitNode.swift (MIT), revision\n * 5c5be8697c57a2fe70cda97fdbaf7c912e2e31b6.\n * Adapted first in Adea packages/dev-view/src/layout/operations.ts at\n * 0322ab09ff5e9775bfddc0bf2d81e1df436dbef7. Extracted here with opaque\n * host-owned leaves and an injected final-pane placeholder; immutable strict\n * binary operations, accepted limits and undoable close are preserved.\n * See NOTICE and docs/research/dev-view-donor-audit.md.\n */\n\nimport {\n MAX_LAYOUT_LEAVES,\n MAX_LAYOUT_DEPTH,\n MIN_SPLIT_RATIO,\n MAX_SPLIT_RATIO,\n listLeaves,\n countLeaves,\n layoutDepth,\n} from './tree'\nimport type { SplitLayoutLeaf, SplitLayoutBranch, SplitLayoutNode } from './tree'\n\nexport * from './tree'\n\nexport type SplitLayoutState<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<{\n center: SplitLayoutNode<L>\n focusedLeafId: string\n closed: readonly Readonly<{ center: SplitLayoutNode<L>; leafId: string }>[]\n}>\n\nexport type SplitPaneInput<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<{\n direction: SplitLayoutBranch<L>['direction']\n placement: 'before' | 'after'\n leaf: L\n splitId: string\n}>\n\nexport type BalancedSplitPaneInput<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<\n Pick<SplitPaneInput<L>, 'placement' | 'leaf' | 'splitId'>\n>\n\nfunction replaceLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string,\n replacement: SplitLayoutNode<L>\n): SplitLayoutNode<L> {\n if (node.kind === 'leaf') return node.id === leafId ? replacement : node\n const first = replaceLeaf(node.children[0], leafId, replacement)\n const second = replaceLeaf(node.children[1], leafId, replacement)\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n}\n\nfunction removeLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string\n): SplitLayoutNode<L> | null {\n if (node.kind === 'leaf') return node.id === leafId ? null : node\n const first = removeLeaf(node.children[0], leafId)\n const second = removeLeaf(node.children[1], leafId)\n if (!first) return second\n if (!second) return first\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n}\n\nfunction containsLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string\n): boolean {\n return node.kind === 'leaf'\n ? node.id === leafId\n : containsLeaf(node.children[0], leafId) || containsLeaf(node.children[1], leafId)\n}\n\nfunction assertUniqueInput<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leaf: L,\n splitId: string\n) {\n assertLayoutTree(leaf)\n if (typeof splitId !== 'string' || splitId.length === 0)\n throw new Error('invalid_state: split identity must be nonempty')\n const ids = new Set<string>()\n const splitIds: string[] = []\n const visit = (node: SplitLayoutNode<L>) => {\n if (ids.has(node.id)) throw new Error('invalid_state: duplicate pane id')\n ids.add(node.id)\n if (node.kind === 'split') {\n splitIds.push(node.id)\n node.children.forEach(visit)\n }\n }\n visit(state.center)\n if (ids.has(leaf.id) || ids.has(splitId) || leaf.id === splitId)\n throw new Error('invalid_state: duplicate pane id')\n return splitIds\n}\n\n/** Visual-tree validation only; applications still decode and scope persisted preferences. */\nfunction assertLayoutTree<L extends SplitLayoutLeaf>(center: SplitLayoutNode<L>): void {\n const ids = new Set<string>()\n const seen = new WeakSet<object>()\n let leaves = 0\n const visit = (node: SplitLayoutNode<L>, depth: number) => {\n if (depth > MAX_LAYOUT_DEPTH) throw new Error('limit_exceeded: layout depth exceeds eight')\n if (!node || typeof node !== 'object') throw new Error('invalid_state: missing layout node')\n if (seen.has(node)) throw new Error('invalid_state: cyclic or reused layout node')\n seen.add(node)\n if (typeof node.id !== 'string' || node.id.length === 0)\n throw new Error('invalid_state: layout identity must be nonempty')\n if (ids.has(node.id)) throw new Error('invalid_state: duplicate pane id')\n ids.add(node.id)\n if (node.kind === 'leaf') {\n leaves += 1\n if (leaves > MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: layout has more than eight leaves')\n return\n }\n if (\n node.kind !== 'split' ||\n !Array.isArray(node.children) ||\n node.children.length !== 2 ||\n (node.direction !== 'row' && node.direction !== 'column')\n )\n throw new Error('invalid_state: layout must be a strict binary row or column tree')\n visit(node.children[0], depth + 1)\n visit(node.children[1], depth + 1)\n }\n visit(center, 1)\n}\n\nexport function createLayoutState<L extends SplitLayoutLeaf>(\n center: SplitLayoutNode<L>\n): SplitLayoutState<L> {\n assertLayoutTree(center)\n const first = listLeaves(center)[0]\n if (!first) throw new Error('invalid_state: layout requires a leaf')\n return { center, focusedLeafId: first.id, closed: [] }\n}\n\nexport function splitPane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n targetLeafId: string,\n input: SplitPaneInput<L>\n): SplitLayoutState<L> {\n if (!containsLeaf(state.center, targetLeafId)) return state\n if (countLeaves(state.center) >= MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: center layout has eight leaves')\n assertUniqueInput(state, input.leaf, input.splitId)\n const target = listLeaves(state.center).find((leaf) => leaf.id === targetLeafId)\n if (!target) return state\n const children =\n input.placement === 'before' ? ([input.leaf, target] as const) : ([target, input.leaf] as const)\n const center = replaceLeaf(state.center, targetLeafId, {\n kind: 'split',\n id: input.splitId,\n direction: input.direction,\n ratio: 0.5,\n children,\n })\n if (layoutDepth(center) > MAX_LAYOUT_DEPTH)\n throw new Error('limit_exceeded: center layout depth exceeds eight')\n return { ...state, center, focusedLeafId: input.leaf.id, closed: [] }\n}\n\n/**\n * Add a pane beside the selected leaf and reflow the visual tree into a\n * balanced row-major grid. One or two leaves share one row; from three leaves\n * onward, leaves fill a first row and then a second row, with no more than four\n * columns in either. Each row gives its leaves equal width and the two rows\n * equal height. Existing opaque leaf objects are preserved. Split IDs are\n * recycled across rebuilt branches, whose axis and descendants can change;\n * resize actions must resolve against the current tree. Ratios are recomputed.\n * This is opt-in: callers\n * that need an explicit axis and ratio should keep using `splitPane`.\n */\nexport function splitPaneBalanced<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n targetLeafId: string,\n input: BalancedSplitPaneInput<L>\n): SplitLayoutState<L> {\n const leaves = [...listLeaves(state.center)]\n const targetIndex = leaves.findIndex((leaf) => leaf.id === targetLeafId)\n if (targetIndex < 0) return state\n if (leaves.length >= MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: center layout has eight leaves')\n const splitIds = assertUniqueInput(state, input.leaf, input.splitId)\n\n const insertionIndex = targetIndex + (input.placement === 'before' ? 0 : 1)\n leaves.splice(insertionIndex, 0, input.leaf)\n\n const build = (start: number, end: number, vertical = false): SplitLayoutNode<L> => {\n if (end - start === 1) return leaves[start]!\n const middle = start + Math.ceil((end - start) / 2)\n // The new identity belongs to the lowest branch separating the selected\n // pane from its new neighbour. Other branches reuse the existing ID pool.\n const id = middle === targetIndex + 1 ? input.splitId : splitIds.shift()!\n return {\n kind: 'split',\n id,\n direction: vertical ? 'column' : 'row',\n ratio: vertical ? 0.5 : (middle - start) / (end - start),\n children: [build(start, middle), build(middle, end)],\n }\n }\n const center = build(0, leaves.length, leaves.length > 2)\n assertLayoutTree(center)\n return { ...state, center, focusedLeafId: input.leaf.id, closed: [] }\n}\n\nexport function closePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n createPlaceholderLeaf: () => L\n): SplitLayoutState<L> {\n if (!containsLeaf(state.center, leafId)) return state\n const before = state.center\n const readingOrder = listLeaves(before)\n const closedIndex = readingOrder.findIndex((leaf) => leaf.id === leafId)\n const removed = removeLeaf(before, leafId)\n const center: SplitLayoutNode<L> = removed ?? createPlaceholderLeaf()\n if (!removed) {\n if (center.kind !== 'leaf') throw new Error('invalid_state: placeholder must be a leaf')\n assertLayoutTree(center)\n }\n const leaves = listLeaves(center)\n const fallback = leaves[Math.min(closedIndex, leaves.length - 1)] ?? leaves[0]\n if (!fallback) throw new Error('invalid_state: layout requires a leaf')\n return {\n center,\n focusedLeafId: state.focusedLeafId === leafId ? fallback.id : state.focusedLeafId,\n closed: [...state.closed, { center: before, leafId }],\n }\n}\n\nexport function undoClosePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>\n): SplitLayoutState<L> {\n const previous = state.closed.at(-1)\n if (!previous) return state\n return {\n center: previous.center,\n focusedLeafId: previous.leafId,\n closed: state.closed.slice(0, -1),\n }\n}\n\nexport function focusPane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string\n): SplitLayoutState<L> {\n return containsLeaf(state.center, leafId) && state.focusedLeafId !== leafId\n ? { ...state, focusedLeafId: leafId }\n : state\n}\n\nexport function swapPanes<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n firstLeafId: string,\n secondLeafId: string\n): SplitLayoutState<L> {\n if (firstLeafId === secondLeafId) return state\n const leaves = listLeaves(state.center)\n const first = leaves.find((leaf) => leaf.id === firstLeafId)\n const second = leaves.find((leaf) => leaf.id === secondLeafId)\n if (!first || !second) return state\n const swap = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') {\n if (node.id === firstLeafId) return second\n if (node.id === secondLeafId) return first\n return node\n }\n const left = swap(node.children[0])\n const right = swap(node.children[1])\n return left === node.children[0] && right === node.children[1]\n ? node\n : { ...node, children: [left, right] }\n }\n return { ...state, center: swap(state.center), closed: [] }\n}\n\nexport function movePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n targetLeafId: string,\n placement: 'before' | 'after',\n direction: SplitLayoutBranch<L>['direction'],\n splitId: string\n): SplitLayoutState<L> {\n if (leafId === targetLeafId) return state\n const moving = listLeaves(state.center).find((leaf) => leaf.id === leafId)\n if (!moving || !containsLeaf(state.center, targetLeafId)) return state\n const detached = removeLeaf(state.center, leafId)\n if (!detached) return state\n const moved = splitPane(\n { center: detached, focusedLeafId: state.focusedLeafId, closed: state.closed },\n targetLeafId,\n { direction, placement, leaf: moving, splitId }\n )\n return { ...moved, focusedLeafId: leafId }\n}\n\nexport function resizeSplit<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n splitId: string,\n ratio: number\n): SplitLayoutState<L> {\n if (!Number.isFinite(ratio)) return state\n const nextRatio = Math.min(MAX_SPLIT_RATIO, Math.max(MIN_SPLIT_RATIO, ratio))\n let found = false\n const visit = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') return node\n if (node.id === splitId) {\n found = true\n return node.ratio === nextRatio ? node : { ...node, ratio: nextRatio }\n }\n const first = visit(node.children[0])\n const second = visit(node.children[1])\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n }\n const center = visit(state.center)\n return found && center !== state.center ? { ...state, center, closed: [] } : state\n}\n\n/**\n * Pure repair walk ported from bb's size normalization: every split ratio is\n * clamped into the normative range and a non-finite ratio falls back to an\n * even split. Structure, IDs, and focus are untouched.\n */\nexport function normalizeLayout<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>\n): SplitLayoutState<L> {\n const visit = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') return node\n const first = visit(node.children[0])\n const second = visit(node.children[1])\n const ratio = Number.isFinite(node.ratio)\n ? Math.min(MAX_SPLIT_RATIO, Math.max(MIN_SPLIT_RATIO, node.ratio))\n : (MIN_SPLIT_RATIO + MAX_SPLIT_RATIO) / 2\n return first === node.children[0] && second === node.children[1] && ratio === node.ratio\n ? node\n : { ...node, ratio, children: [first, second] }\n }\n const center = visit(state.center)\n return center === state.center ? state : { ...state, center }\n}\n\n/** The leaf immediately after (`1`) or before (`-1`) the given leaf in reading order. */\nexport function neighborLeaf<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n step: 1 | -1\n): L | undefined {\n const leaves = listLeaves(state.center)\n const index = leaves.findIndex((leaf) => leaf.id === leafId)\n if (index < 0) return undefined\n return leaves[index + step]\n}\n"],"mappings":";;AA+CA,SAAS,YACP,MACA,QACA,aACoB;CACpB,IAAI,KAAK,SAAS,QAAQ,OAAO,KAAK,OAAO,SAAS,cAAc;CACpE,MAAM,QAAQ,YAAY,KAAK,SAAS,IAAI,QAAQ,WAAW;CAC/D,MAAM,SAAS,YAAY,KAAK,SAAS,IAAI,QAAQ,WAAW;CAChE,OAAO,UAAU,KAAK,SAAS,MAAM,WAAW,KAAK,SAAS,KAC1D,OACA;EAAE,GAAG;EAAM,UAAU,CAAC,OAAO,MAAM;CAAE;AAC3C;AAEA,SAAS,WACP,MACA,QAC2B;CAC3B,IAAI,KAAK,SAAS,QAAQ,OAAO,KAAK,OAAO,SAAS,OAAO;CAC7D,MAAM,QAAQ,WAAW,KAAK,SAAS,IAAI,MAAM;CACjD,MAAM,SAAS,WAAW,KAAK,SAAS,IAAI,MAAM;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,UAAU,KAAK,SAAS,MAAM,WAAW,KAAK,SAAS,KAC1D,OACA;EAAE,GAAG;EAAM,UAAU,CAAC,OAAO,MAAM;CAAE;AAC3C;AAEA,SAAS,aACP,MACA,QACS;CACT,OAAO,KAAK,SAAS,SACjB,KAAK,OAAO,SACZ,aAAa,KAAK,SAAS,IAAI,MAAM,KAAK,aAAa,KAAK,SAAS,IAAI,MAAM;AACrF;AAEA,SAAS,kBACP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SAAS,SAAiD;EAC9D,IAAI,KAAK,SAAS,QAAQ,OAAO;EACjC,MAAM,QAAQ,MAAM,KAAK,SAAS,EAAE;EACpC,MAAM,SAAS,MAAM,KAAK,SAAS,EAAE;EACrC,MAAM,QAAQ,OAAO,SAAS,KAAK,KAAK,IACpC,KAAK,IAAI,iBAAiB,KAAK,IAAI,iBAAiB,KAAK,KAAK,CAAC,KAC9D,kBAAkB,mBAAmB;EAC1C,OAAO,UAAU,KAAK,SAAS,MAAM,WAAW,KAAK,SAAS,MAAM,UAAU,KAAK,QAC/E,OACA;GAAE,GAAG;GAAM;GAAO,UAAU,CAAC,OAAO,MAAM;EAAE;CAClD;CACA,MAAM,SAAS,MAAM,MAAM,MAAM;CACjC,OAAO,WAAW,MAAM,SAAS,QAAQ;EAAE,GAAG;EAAO;CAAO;AAC9D;;AAGA,SAAgB,aACd,OACA,QACA,MACe;CACf,MAAM,SAAS,WAAW,MAAM,MAAM;CACtC,MAAM,QAAQ,OAAO,WAAW,SAAS,KAAK,OAAO,MAAM;CAC3D,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,OAAO,OAAO,QAAQ;AACxB"}
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../../../src/components/layout/split-layout/model.ts"],"sourcesContent":["/*\n * Copyright (c) 2026 Michael Yong\n * Copyright (c) 2026 Muxy\n * SPDX-License-Identifier: MIT\n *\n * Portions of the binary split behavior are substantially translated from:\n * - get-bb/bb apps/app/src/lib/split-layout/ops.ts (MIT), revision\n * 52a9256373d4d36f9b60e9e2a7f333464091a2ac.\n * - muxy-app/muxy Muxy/Models/Workspace/SplitNode.swift (MIT), revision\n * 5c5be8697c57a2fe70cda97fdbaf7c912e2e31b6.\n * Adapted first in Adea packages/dev-view/src/layout/operations.ts at\n * 0322ab09ff5e9775bfddc0bf2d81e1df436dbef7. Extracted here with opaque\n * host-owned leaves and an injected final-pane placeholder; immutable strict\n * binary operations, accepted limits and undoable close are preserved.\n * See NOTICE and docs/research/dev-view-donor-audit.md.\n */\n\nimport {\n MAX_LAYOUT_LEAVES,\n MAX_LAYOUT_DEPTH,\n MIN_SPLIT_RATIO,\n MAX_SPLIT_RATIO,\n listLeaves,\n countLeaves,\n layoutDepth,\n} from './tree'\nimport type { SplitLayoutLeaf, SplitLayoutBranch, SplitLayoutNode } from './tree'\n\nexport * from './tree'\n\nexport type SplitLayoutState<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<{\n center: SplitLayoutNode<L>\n focusedLeafId: string\n closed: readonly Readonly<{ center: SplitLayoutNode<L>; leafId: string }>[]\n}>\n\nexport type SplitPaneInput<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<{\n direction: SplitLayoutBranch<L>['direction']\n placement: 'before' | 'after'\n leaf: L\n splitId: string\n}>\n\nexport type BalancedSplitPaneInput<L extends SplitLayoutLeaf = SplitLayoutLeaf> = Readonly<\n Pick<SplitPaneInput<L>, 'placement' | 'leaf' | 'splitId'>\n>\n\nfunction replaceLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string,\n replacement: SplitLayoutNode<L>\n): SplitLayoutNode<L> {\n if (node.kind === 'leaf') return node.id === leafId ? replacement : node\n const first = replaceLeaf(node.children[0], leafId, replacement)\n const second = replaceLeaf(node.children[1], leafId, replacement)\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n}\n\nfunction removeLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string\n): SplitLayoutNode<L> | null {\n if (node.kind === 'leaf') return node.id === leafId ? null : node\n const first = removeLeaf(node.children[0], leafId)\n const second = removeLeaf(node.children[1], leafId)\n if (!first) return second\n if (!second) return first\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n}\n\nfunction containsLeaf<L extends SplitLayoutLeaf>(\n node: SplitLayoutNode<L>,\n leafId: string\n): boolean {\n return node.kind === 'leaf'\n ? node.id === leafId\n : containsLeaf(node.children[0], leafId) || containsLeaf(node.children[1], leafId)\n}\n\nfunction assertUniqueInput<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leaf: L,\n splitId: string,\n placement: SplitPaneInput<L>['placement']\n) {\n if (!leaf || leaf.kind !== 'leaf' || (placement !== 'before' && placement !== 'after'))\n throw new Error('invalid_state: invalid split input')\n assertLayoutTree(leaf)\n if (typeof splitId !== 'string' || splitId.length === 0)\n throw new Error('invalid_state: split identity must be nonempty')\n const ids = new Set<string>()\n const splitIds: string[] = []\n const visit = (node: SplitLayoutNode<L>) => {\n if (ids.has(node.id)) throw new Error('invalid_state: duplicate pane id')\n ids.add(node.id)\n if (node.kind === 'split') {\n splitIds.push(node.id)\n node.children.forEach(visit)\n }\n }\n visit(state.center)\n if (ids.has(leaf.id) || ids.has(splitId) || leaf.id === splitId)\n throw new Error('invalid_state: duplicate pane id')\n return splitIds\n}\n\n/** Visual-tree validation only; applications still decode and scope persisted preferences. */\nfunction assertLayoutTree<L extends SplitLayoutLeaf>(center: SplitLayoutNode<L>): void {\n const ids = new Set<string>()\n const seen = new WeakSet<object>()\n let leaves = 0\n const visit = (node: SplitLayoutNode<L>, depth: number) => {\n if (depth > MAX_LAYOUT_DEPTH) throw new Error('limit_exceeded: layout depth exceeds eight')\n if (!node || typeof node !== 'object') throw new Error('invalid_state: missing layout node')\n if (seen.has(node)) throw new Error('invalid_state: cyclic or reused layout node')\n seen.add(node)\n if (typeof node.id !== 'string' || node.id.length === 0)\n throw new Error('invalid_state: layout identity must be nonempty')\n if (ids.has(node.id)) throw new Error('invalid_state: duplicate pane id')\n ids.add(node.id)\n if (node.kind === 'leaf') {\n leaves += 1\n if (leaves > MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: layout has more than eight leaves')\n return\n }\n if (\n node.kind !== 'split' ||\n !Array.isArray(node.children) ||\n node.children.length !== 2 ||\n (node.direction !== 'row' && node.direction !== 'column')\n )\n throw new Error('invalid_state: layout must be a strict binary row or column tree')\n visit(node.children[0], depth + 1)\n visit(node.children[1], depth + 1)\n }\n visit(center, 1)\n}\n\nexport function createLayoutState<L extends SplitLayoutLeaf>(\n center: SplitLayoutNode<L>\n): SplitLayoutState<L> {\n assertLayoutTree(center)\n const first = listLeaves(center)[0]\n if (!first) throw new Error('invalid_state: layout requires a leaf')\n return { center, focusedLeafId: first.id, closed: [] }\n}\n\nexport function splitPane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n targetLeafId: string,\n input: SplitPaneInput<L>\n): SplitLayoutState<L> {\n if (!containsLeaf(state.center, targetLeafId)) return state\n if (input.direction !== 'row' && input.direction !== 'column')\n throw new Error('invalid_state: invalid split input')\n if (countLeaves(state.center) >= MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: center layout has eight leaves')\n assertUniqueInput(state, input.leaf, input.splitId, input.placement)\n const target = listLeaves(state.center).find((leaf) => leaf.id === targetLeafId)\n if (!target) return state\n const children =\n input.placement === 'before' ? ([input.leaf, target] as const) : ([target, input.leaf] as const)\n const center = replaceLeaf(state.center, targetLeafId, {\n kind: 'split',\n id: input.splitId,\n direction: input.direction,\n ratio: 0.5,\n children,\n })\n if (layoutDepth(center) > MAX_LAYOUT_DEPTH)\n throw new Error('limit_exceeded: center layout depth exceeds eight')\n return { ...state, center, focusedLeafId: input.leaf.id, closed: [] }\n}\n\n/**\n * Reflow into a balanced row-major grid of at most two rows and four columns,\n * preserving opaque leaves. Split IDs are recycled across rebuilt branches, so\n * resize actions must resolve against the current tree. Call `splitPane` instead\n * when the axis and ratio must be explicit.\n */\nexport function splitPaneBalanced<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n targetLeafId: string,\n input: BalancedSplitPaneInput<L>\n): SplitLayoutState<L> {\n const leaves = [...listLeaves(state.center)]\n const targetIndex = leaves.findIndex((leaf) => leaf.id === targetLeafId)\n if (targetIndex < 0) return state\n if (leaves.length >= MAX_LAYOUT_LEAVES)\n throw new Error('limit_exceeded: center layout has eight leaves')\n const splitIds = assertUniqueInput(state, input.leaf, input.splitId, input.placement)\n\n const insertionIndex = targetIndex + (input.placement === 'before' ? 0 : 1)\n leaves.splice(insertionIndex, 0, input.leaf)\n\n const build = (start: number, end: number, vertical = false): SplitLayoutNode<L> => {\n if (end - start === 1) return leaves[start]!\n const middle = start + Math.ceil((end - start) / 2)\n // The new identity belongs to the lowest branch separating the selected\n // pane from its new neighbour. Other branches reuse the existing ID pool.\n const id = middle === targetIndex + 1 ? input.splitId : splitIds.shift()!\n return {\n kind: 'split',\n id,\n direction: vertical ? 'column' : 'row',\n ratio: vertical ? 0.5 : (middle - start) / (end - start),\n children: [build(start, middle), build(middle, end)],\n }\n }\n const center = build(0, leaves.length, leaves.length > 2)\n assertLayoutTree(center)\n return { ...state, center, focusedLeafId: input.leaf.id, closed: [] }\n}\n\nexport function closePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n createPlaceholderLeaf: () => L\n): SplitLayoutState<L> {\n if (!containsLeaf(state.center, leafId)) return state\n const before = state.center\n const readingOrder = listLeaves(before)\n const closedIndex = readingOrder.findIndex((leaf) => leaf.id === leafId)\n const removed = removeLeaf(before, leafId)\n const center: SplitLayoutNode<L> = removed ?? createPlaceholderLeaf()\n if (!removed) {\n if (center.kind !== 'leaf') throw new Error('invalid_state: placeholder must be a leaf')\n assertLayoutTree(center)\n }\n const leaves = listLeaves(center)\n const fallback = leaves[Math.min(closedIndex, leaves.length - 1)] ?? leaves[0]\n if (!fallback) throw new Error('invalid_state: layout requires a leaf')\n return {\n center,\n focusedLeafId: state.focusedLeafId === leafId ? fallback.id : state.focusedLeafId,\n closed: [...state.closed, { center: before, leafId }],\n }\n}\n\nexport function undoClosePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>\n): SplitLayoutState<L> {\n const previous = state.closed.at(-1)\n if (!previous) return state\n return {\n center: previous.center,\n focusedLeafId: previous.leafId,\n closed: state.closed.slice(0, -1),\n }\n}\n\nexport function focusPane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string\n): SplitLayoutState<L> {\n return containsLeaf(state.center, leafId) && state.focusedLeafId !== leafId\n ? { ...state, focusedLeafId: leafId }\n : state\n}\n\nexport function swapPanes<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n firstLeafId: string,\n secondLeafId: string\n): SplitLayoutState<L> {\n if (firstLeafId === secondLeafId) return state\n const leaves = listLeaves(state.center)\n const first = leaves.find((leaf) => leaf.id === firstLeafId)\n const second = leaves.find((leaf) => leaf.id === secondLeafId)\n if (!first || !second) return state\n const swap = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') {\n if (node.id === firstLeafId) return second\n if (node.id === secondLeafId) return first\n return node\n }\n const left = swap(node.children[0])\n const right = swap(node.children[1])\n return left === node.children[0] && right === node.children[1]\n ? node\n : { ...node, children: [left, right] }\n }\n return { ...state, center: swap(state.center), closed: [] }\n}\n\nexport function movePane<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n targetLeafId: string,\n placement: 'before' | 'after',\n direction: SplitLayoutBranch<L>['direction'],\n splitId: string\n): SplitLayoutState<L> {\n if (leafId === targetLeafId) return state\n const moving = listLeaves(state.center).find((leaf) => leaf.id === leafId)\n if (!moving || !containsLeaf(state.center, targetLeafId)) return state\n const detached = removeLeaf(state.center, leafId)\n if (!detached) return state\n const moved = splitPane(\n { center: detached, focusedLeafId: state.focusedLeafId, closed: state.closed },\n targetLeafId,\n { direction, placement, leaf: moving, splitId }\n )\n return { ...moved, focusedLeafId: leafId }\n}\n\nexport function resizeSplit<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n splitId: string,\n ratio: number\n): SplitLayoutState<L> {\n if (!Number.isFinite(ratio)) return state\n const nextRatio = Math.min(MAX_SPLIT_RATIO, Math.max(MIN_SPLIT_RATIO, ratio))\n let found = false\n const visit = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') return node\n if (node.id === splitId) {\n found = true\n return node.ratio === nextRatio ? node : { ...node, ratio: nextRatio }\n }\n const first = visit(node.children[0])\n const second = visit(node.children[1])\n return first === node.children[0] && second === node.children[1]\n ? node\n : { ...node, children: [first, second] }\n }\n const center = visit(state.center)\n return found && center !== state.center ? { ...state, center, closed: [] } : state\n}\n\n/**\n * Pure repair walk ported from bb's size normalization: every split ratio is\n * clamped into the normative range and a non-finite ratio falls back to an\n * even split. Structure, IDs, and focus are untouched.\n */\nexport function normalizeLayout<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>\n): SplitLayoutState<L> {\n const visit = (node: SplitLayoutNode<L>): SplitLayoutNode<L> => {\n if (node.kind === 'leaf') return node\n const first = visit(node.children[0])\n const second = visit(node.children[1])\n const ratio = Number.isFinite(node.ratio)\n ? Math.min(MAX_SPLIT_RATIO, Math.max(MIN_SPLIT_RATIO, node.ratio))\n : (MIN_SPLIT_RATIO + MAX_SPLIT_RATIO) / 2\n return first === node.children[0] && second === node.children[1] && ratio === node.ratio\n ? node\n : { ...node, ratio, children: [first, second] }\n }\n const center = visit(state.center)\n return center === state.center ? state : { ...state, center }\n}\n\n/** The leaf immediately after (`1`) or before (`-1`) the given leaf in reading order. */\nexport function neighborLeaf<L extends SplitLayoutLeaf>(\n state: SplitLayoutState<L>,\n leafId: string,\n step: 1 | -1\n): L | undefined {\n const leaves = listLeaves(state.center)\n const index = leaves.findIndex((leaf) => leaf.id === leafId)\n if (index < 0) return undefined\n return leaves[index + step]\n}\n"],"mappings":";;AA+CA,SAAS,YACP,MACA,QACA,aACoB;CACpB,IAAI,KAAK,SAAS,QAAQ,OAAO,KAAK,OAAO,SAAS,cAAc;CACpE,MAAM,QAAQ,YAAY,KAAK,SAAS,IAAI,QAAQ,WAAW;CAC/D,MAAM,SAAS,YAAY,KAAK,SAAS,IAAI,QAAQ,WAAW;CAChE,OAAO,UAAU,KAAK,SAAS,MAAM,WAAW,KAAK,SAAS,KAC1D,OACA;EA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ACjC,OAAO,WAAW,MAAM,SAAS,QAAQ;EAAE,GAAG;EAAO;CAAO;AAC9D;;AAGA,SAAgB,aACd,OACA,QACA,MACe;CACf,MAAM,SAAS,WAAW,MAAM,MAAM;CACtC,MAAM,QAAQ,OAAO,WAAW,SAAS,KAAK,OAAO,MAAM;CAC3D,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,OAAO,OAAO,QAAQ;AACxB"}
|
|
@@ -119,9 +119,9 @@ function createVersionedPersistence(schema, codec, options = {}) {
|
|
|
119
119
|
};
|
|
120
120
|
return {
|
|
121
121
|
read() {
|
|
122
|
-
const storage = storageOf();
|
|
123
|
-
if (!storage) return fallback();
|
|
124
122
|
try {
|
|
123
|
+
const storage = storageOf();
|
|
124
|
+
if (!storage) return fallback();
|
|
125
125
|
const found = readVersionedRecord(storage, recordSchema, options.now);
|
|
126
126
|
if (found.status === "record") {
|
|
127
127
|
previous = found.record;
|
|
@@ -136,9 +136,9 @@ function createVersionedPersistence(schema, codec, options = {}) {
|
|
|
136
136
|
return fallback();
|
|
137
137
|
},
|
|
138
138
|
write(next) {
|
|
139
|
-
const storage = storageOf();
|
|
140
|
-
if (!storage) return;
|
|
141
139
|
try {
|
|
140
|
+
const storage = storageOf();
|
|
141
|
+
if (!storage) return;
|
|
142
142
|
const document = codec.encode(next, previous);
|
|
143
143
|
if (writeVersionedRecord(storage, schema.key, document)) previous = typeof document === "object" && document !== null ? document : void 0;
|
|
144
144
|
} catch {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-persistence.js","names":[],"sources":["../../../src/components/theme/theme-persistence.ts"],"sourcesContent":["import { normalizeCustomAccent } from '#lib/accent-roles'\nimport { accentPresets } from '#lib/accent-presets'\nimport { normalizeAppearanceEditorFontSettings } from '#lib/appearance-font-settings'\nimport { isThemeAccentId } from '#lib/theme-accents'\nimport {\n catalogueThemeAppearance,\n defaultDarkThemeId,\n defaultLightThemeId,\n} from '#lib/theme-defaults'\nimport { normalizeSurface } from '#lib/theme-surface'\nimport {\n defaultPreferenceStorage,\n readLegacyValue,\n readVersionedRecord,\n recoveryKeyFor,\n writeVersionedRecord,\n type PreferenceStorage,\n} from '#lib/preference-store'\nimport { defaultThemeSelection, resolvedDensity, type ThemeSelection } from './theme-state-core'\n\n/**\n * Where a selection is kept between sessions.\n *\n * The provider never touches storage itself; it asks a `ThemePersistence`. The\n * default is {@link localStoragePersistence}, which is what the provider always did.\n * A host that stores the preference in a different shape, under a versioned\n * envelope, or somewhere that is not `localStorage` supplies its own and the\n * resolution and application rules stay the shared ones.\n *\n * The contract is deliberately narrow, so that an implementation cannot make the\n * provider less safe than it was:\n *\n * - `read` is synchronous and runs once, when the provider is created. It may\n * repair or quarantine what it finds, and it must not throw: the provider\n * treats a throw as \"nothing stored\" and starts from the defaults.\n * - `write` runs only from `setSelection`. Never on mount, never from `preview`,\n * never as a side effect of reading, so the first write to a store is always a\n * user's decision. A throw is swallowed, because a full or blocked store must\n * not break the switch.\n */\nexport type ThemePersistence = {\n read(): Partial<ThemeSelection> | undefined\n write(next: ThemeSelection): void\n}\n\n/**\n * The preference store, or nothing.\n *\n * Only ever called inside a `try`: where storage is blocked — a sandboxed iframe, a\n * privacy mode, a denied site-data permission — merely *reading* the `localStorage`\n * global throws (\"Access is denied\", `SecurityError`), so even the `typeof` guard\n * has to sit inside the `try` rather than in front of it. Without a store the\n * preference lives only in the provider's signal for the session.\n */\nfunction preferenceStore(): Storage | undefined {\n return typeof localStorage === 'undefined' ? undefined : localStorage\n}\n\n/**\n * The stored preference, validated against the catalogue's ids (`theme-defaults`), so\n * reading it never loads the catalogue.\n */\nfunction readSelection(storageKey: string): ThemeSelection {\n try {\n const raw = preferenceStore()?.getItem(storageKey)\n if (!raw) return defaultThemeSelection\n const parsed = JSON.parse(raw) as Partial<ThemeSelection>\n const fonts = normalizeAppearanceEditorFontSettings(parsed.fonts, parsed.font).settings\n return {\n appearance:\n parsed.appearance === 'light' ||\n parsed.appearance === 'dark' ||\n parsed.appearance === 'system'\n ? parsed.appearance\n : defaultThemeSelection.appearance,\n // An unknown id would leave the document with no theme at all, so a stale\n // preference from an older catalogue falls back rather than applying nothing.\n lightThemeId:\n catalogueThemeAppearance(parsed.lightThemeId ?? '') === 'light'\n ? (parsed.lightThemeId as string)\n : defaultLightThemeId,\n darkThemeId:\n catalogueThemeAppearance(parsed.darkThemeId ?? '') === 'dark'\n ? (parsed.darkThemeId as string)\n : defaultDarkThemeId,\n // A theme accent is kept whenever it names a slot, even one the stored pair\n // cannot offer: the id is role-shaped so it survives a theme switch, and an\n // unoffered slot already resolves to the theme's own primary when applied. A\n // custom `#rrggbb` is kept in its one stored spelling; its readability is\n // settled when it is painted, not when it is read.\n accent:\n typeof parsed.accent === 'string' &&\n (accentPresets.some((preset) => preset.id === parsed.accent) ||\n isThemeAccentId(parsed.accent))\n ? parsed.accent\n : (normalizeCustomAccent(parsed.accent) ?? defaultThemeSelection.accent),\n font: fonts.ui.family,\n fonts,\n // Every axis has to be read back here, or it is lost twice: the provider's\n // document effect removes the `data-density` that `themeScript` set for the first paint, and\n // the next `setSelection` rewrites the store without it.\n density: resolvedDensity(parsed as ThemeSelection),\n // The newer axes are read back only when the store holds a usable value and are\n // otherwise left `undefined`, never defaulted: `JSON.stringify` drops them, so a\n // consumer that never sets one writes the bytes it always did. An id is kept as\n // stored, known or not, for the same reason a theme id the registry lacks is.\n terminalThemeId:\n typeof parsed.terminalThemeId === 'string' && parsed.terminalThemeId.trim() !== ''\n ? parsed.terminalThemeId\n : undefined,\n surface: normalizeSurface(parsed.surface),\n reduceTransparency:\n typeof parsed.reduceTransparency === 'boolean' ? parsed.reduceTransparency : undefined,\n }\n } catch {\n return defaultThemeSelection\n }\n}\n\n/**\n * The default persistence: one JSON document in `localStorage` under `key`.\n *\n * `read` is the provider's original `readSelection`, moved here unchanged — every\n * stored id is validated against the catalogue, so a stale preference falls back to\n * a default rather than reaching the document. `key` may be a function so a\n * provider whose `storageKey` prop changes writes to the key it is now given.\n *\n * Blocked, full or absent storage is survivable in both directions: a read answers\n * with the defaults and a write is dropped, so the preference simply lasts the\n * session.\n */\nexport function localStoragePersistence(key: string | (() => string)): ThemePersistence {\n const keyOf = () => (typeof key === 'function' ? key() : key)\n return {\n read: () => readSelection(keyOf()),\n write(next) {\n try {\n preferenceStore()?.setItem(keyOf(), JSON.stringify(next))\n } catch {\n // A full, blocked or unavailable store must not break the switch: the\n // preference simply does not survive the reload.\n }\n },\n }\n}\n\n/**\n * What a persistence knows, or nothing.\n *\n * The seam's `read` must not throw, and the provider does not rely on that: a host\n * persistence is code the design system has not seen, and a theme provider that\n * fails to mount because a store misbehaved has turned a lost preference into a\n * blank application.\n */\nexport function readPersisted(persistence: ThemePersistence): Partial<ThemeSelection> | undefined {\n try {\n return persistence.read()\n } catch {\n return undefined\n }\n}\n\n/** Hand a selection to the store; a store that throws loses the preference, not the switch. */\nexport function writePersisted(persistence: ThemePersistence, next: ThemeSelection): void {\n try {\n persistence.write(next)\n } catch {\n // Same contract as a full or blocked `localStorage`: the choice holds for the\n // session and does not survive the reload.\n }\n}\n\n/**\n * Where a host's versioned preference document lives. One schema describes the\n * document to both halves of the system: {@link createVersionedPersistence} reads and\n * writes it, and `themeScript(options)` reads it before first paint, so the two\n * cannot disagree about a key or a version.\n */\nexport type ThemeStorageSchema = {\n /** The storage key of the document. */\n key: string\n /**\n * The only top-level `version` read. Absent, the document is unversioned. A record\n * of any other version is quarantined (see `recoveryKey`), not interpreted.\n */\n version?: number\n /**\n * The document field that holds the appearance preference (`system`, `light`,\n * `dark`). Read by `themeScript`; the persistence leaves field names to the codec.\n * Default `appearance`.\n */\n appearanceField?: 'appearance' | 'mode'\n /**\n * An older single-value key (`light` | `dark` | `system`) read only while `key` is\n * absent, and never deleted. The persistence hands it to the codec's `fromLegacy`.\n */\n legacyAppearanceKey?: string\n /**\n * The stored library of imported themes, for `themeScript` only: an imported\n * theme's id and verbatim tokens, so the first paint can use the right variant. The\n * persistence neither reads nor writes it.\n */\n libraryKey?: string\n /** Where an unreadable document is kept. Default `${key}.recovery`. */\n recoveryKey?: string\n}\n\n/**\n * How a host's document maps to and from the shared {@link ThemeSelection}.\n *\n * The codec is the product schema: it decides which fields a document has, how an\n * unknown value is corrected, and what a fresh install looks like. The engine decides\n * everything about *storage*: what is quarantined, when the legacy key is read, and\n * that nothing is written until `setSelection` asks.\n */\nexport type VersionedCodec<Doc> = {\n /**\n * A readable record (the right JSON shape and version) as a selection patch. Fields\n * it leaves `undefined` fall back to the provider's defaults. It may keep an id the\n * catalogue lacks; the provider resolves it, it does not rewrite it.\n */\n decode(record: Readonly<Record<string, unknown>>): Partial<ThemeSelection>\n /**\n * The legacy key's value (never `null`) as a selection patch, or `undefined` for a\n * value it does not recognise. Called only when the main key is absent.\n */\n fromLegacy?(value: string): Partial<ThemeSelection> | undefined\n /**\n * What a store with nothing readable answers: a fresh install, an unreadable\n * document, a blocked store. Absent, the provider's own defaults apply.\n */\n defaults?(): Partial<ThemeSelection> | undefined\n /**\n * The document to store for a selection. `previous` is the record last read or\n * written, so a codec can carry a field the selection does not model.\n */\n encode(next: ThemeSelection, previous?: Readonly<Record<string, unknown>>): Doc\n}\n\n/** Seams for the storage and the clock; both default to the real ones. */\nexport type VersionedPersistenceOptions = {\n /** The store, or nothing. Called per access; default is `localStorage` (blocked-safe). */\n storage?: () => PreferenceStorage | undefined\n /** The clock for the recovery envelope's `capturedAt`. */\n now?: () => Date\n}\n\n/**\n * A {@link ThemePersistence} over a versioned document and a host codec.\n *\n * `read` follows the engine's rules (`lib/preference-store.ts`): the main key first;\n * an unreadable or unsupported document is quarantined byte for byte into the\n * recovery key and the codec's `defaults` answer; the legacy key only when the main\n * key is absent. It never writes the main key, so the first write is a user's\n * decision. `write` stores `codec.encode(next, previous)` as JSON and swallows a\n * failure.\n *\n * Neither method throws. The stored bytes are exactly what the codec encodes, so a\n * host keeps its keys, field names and bytes by keeping its codec.\n */\nexport function createVersionedPersistence<Doc>(\n schema: ThemeStorageSchema,\n codec: VersionedCodec<Doc>,\n options: VersionedPersistenceOptions = {}\n): ThemePersistence {\n const storageOf = options.storage ?? defaultPreferenceStorage\n const recordSchema = {\n key: schema.key,\n version: schema.version,\n recoveryKey: recoveryKeyFor(schema),\n }\n let previous: Readonly<Record<string, unknown>> | undefined\n\n const fallback = () => {\n try {\n return codec.defaults?.()\n } catch {\n return undefined\n }\n }\n\n return {\n read() {\n const storage = storageOf()\n if (!storage) return fallback()\n try {\n const found = readVersionedRecord(storage, recordSchema, options.now)\n if (found.status === 'record') {\n previous = found.record\n return codec.decode(found.record)\n }\n if (found.status === 'absent' && schema.legacyAppearanceKey && codec.fromLegacy) {\n const legacy = readLegacyValue(storage, schema.legacyAppearanceKey)\n const migrated = legacy === null ? undefined : codec.fromLegacy(legacy)\n if (migrated) return migrated\n }\n } catch {\n // A codec that throws on a record it cannot read is an unreadable store.\n }\n return fallback()\n },\n write(next) {\n const storage = storageOf()\n if (!storage) return\n try {\n const document = codec.encode(next, previous)\n if (writeVersionedRecord(storage, schema.key, document)) {\n previous =\n typeof document === 'object' && document !== null\n ? (document as Readonly<Record<string, unknown>>)\n : undefined\n }\n } catch {\n // An encoder that throws loses the preference, not the switch.\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsDA,SAAS,kBAAuC;CAC9C,OAAO,OAAO,iBAAiB,cAAc,KAAA,IAAY;AAC3D;;;;;AAMA,SAAS,cAAc,YAAoC;CACzD,IAAI;EACF,MAAM,MAAM,gBAAgB,CAAC,EAAE,QAAQ,UAAU;EACjD,IAAI,CAAC,KAAK,OAAO;EACjB,MAAM,SAAS,KAAK,MAAM,GAAG;EAC7B,MAAM,QAAQ,sCAAsC,OAAO,OAAO,OAAO,IAAI,CAAC,CAAC;EAC/E,OAAO;GACL,YACE,OAAO,eAAe,WACtB,OAAO,eAAe,UACtB,OAAO,eAAe,WAClB,OAAO,aACP,sBAAsB;GAG5B,cACE,yBAAyB,OAAO,gBAAgB,EAAE,MAAM,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ACN;EACF;CACF;CAEA,OAAO;EACL,OAAO;GACL,MAAM,UAAU,UAAU;GAC1B,IAAI,CAAC,SAAS,OAAO,SAAS;GAC9B,IAAI;IACF,MAAM,QAAQ,oBAAoB,SAAS,cAAc,QAAQ,GAAG;IACpE,IAAI,MAAM,WAAW,UAAU;KAC7B,WAAW,MAAM;KACjB,OAAO,MAAM,OAAO,MAAM,MAAM;IAClC;IACA,IAAI,MAAM,WAAW,YAAY,OAAO,uBAAuB,MAAM,YAAY;KAC/E,MAAM,SAAS,gBAAgB,SAAS,OAAO,mBAAmB;KAClE,MAAM,WAAW,WAAW,OAAO,KAAA,IAAY,MAAM,WAAW,MAAM;KACtE,IAAI,UAAU,OAAO;IACvB;GACF,QAAQ,CAER;GACA,OAAO,SAAS;EAClB;EACA,MAAM,MAAM;GACV,MAAM,UAAU,UAAU;GAC1B,IAAI,CAAC,SAAS;GACd,IAAI;IACF,MAAM,WAAW,MAAM,OAAO,MAAM,QAAQ;IAC5C,IAAI,qBAAqB,SAAS,OAAO,KAAK,QAAQ,GACpD,WACE,OAAO,aAAa,YAAY,aAAa,OACxC,WACD,KAAA;GAEV,QAAQ,CAER;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"theme-persistence.js","names":[],"sources":["../../../src/components/theme/theme-persistence.ts"],"sourcesContent":["import { normalizeCustomAccent } from '#lib/accent-roles'\nimport { accentPresets } from '#lib/accent-presets'\nimport { normalizeAppearanceEditorFontSettings } from '#lib/appearance-font-settings'\nimport { isThemeAccentId } from '#lib/theme-accents'\nimport {\n catalogueThemeAppearance,\n defaultDarkThemeId,\n defaultLightThemeId,\n} from '#lib/theme-defaults'\nimport { normalizeSurface } from '#lib/theme-surface'\nimport {\n defaultPreferenceStorage,\n readLegacyValue,\n readVersionedRecord,\n recoveryKeyFor,\n writeVersionedRecord,\n type PreferenceStorage,\n} from '#lib/preference-store'\nimport { defaultThemeSelection, resolvedDensity, type ThemeSelection } from './theme-state-core'\n\n/**\n * Where a selection is kept between sessions.\n *\n * The provider never touches storage itself; it asks a `ThemePersistence`. The\n * default is {@link localStoragePersistence}, which is what the provider always did.\n * A host that stores the preference in a different shape, under a versioned\n * envelope, or somewhere that is not `localStorage` supplies its own and the\n * resolution and application rules stay the shared ones.\n *\n * The contract is deliberately narrow, so that an implementation cannot make the\n * provider less safe than it was:\n *\n * - `read` is synchronous and runs once, when the provider is created. It may\n * repair or quarantine what it finds, and it must not throw: the provider\n * treats a throw as \"nothing stored\" and starts from the defaults.\n * - `write` runs only from `setSelection`. Never on mount, never from `preview`,\n * never as a side effect of reading, so the first write to a store is always a\n * user's decision. A throw is swallowed, because a full or blocked store must\n * not break the switch.\n */\nexport type ThemePersistence = {\n read(): Partial<ThemeSelection> | undefined\n write(next: ThemeSelection): void\n}\n\n/**\n * The preference store, or nothing.\n *\n * Only ever called inside a `try`: where storage is blocked — a sandboxed iframe, a\n * privacy mode, a denied site-data permission — merely *reading* the `localStorage`\n * global throws (\"Access is denied\", `SecurityError`), so even the `typeof` guard\n * has to sit inside the `try` rather than in front of it. Without a store the\n * preference lives only in the provider's signal for the session.\n */\nfunction preferenceStore(): Storage | undefined {\n return typeof localStorage === 'undefined' ? undefined : localStorage\n}\n\n/**\n * The stored preference, validated against the catalogue's ids (`theme-defaults`), so\n * reading it never loads the catalogue.\n */\nfunction readSelection(storageKey: string): ThemeSelection {\n try {\n const raw = preferenceStore()?.getItem(storageKey)\n if (!raw) return defaultThemeSelection\n const parsed = JSON.parse(raw) as Partial<ThemeSelection>\n const fonts = normalizeAppearanceEditorFontSettings(parsed.fonts, parsed.font).settings\n return {\n appearance:\n parsed.appearance === 'light' ||\n parsed.appearance === 'dark' ||\n parsed.appearance === 'system'\n ? parsed.appearance\n : defaultThemeSelection.appearance,\n // An unknown id would leave the document with no theme at all, so a stale\n // preference from an older catalogue falls back rather than applying nothing.\n lightThemeId:\n catalogueThemeAppearance(parsed.lightThemeId ?? '') === 'light'\n ? (parsed.lightThemeId as string)\n : defaultLightThemeId,\n darkThemeId:\n catalogueThemeAppearance(parsed.darkThemeId ?? '') === 'dark'\n ? (parsed.darkThemeId as string)\n : defaultDarkThemeId,\n // A theme accent is kept whenever it names a slot, even one the stored pair\n // cannot offer: the id is role-shaped so it survives a theme switch, and an\n // unoffered slot already resolves to the theme's own primary when applied. A\n // custom `#rrggbb` is kept in its one stored spelling; its readability is\n // settled when it is painted, not when it is read.\n accent:\n typeof parsed.accent === 'string' &&\n (accentPresets.some((preset) => preset.id === parsed.accent) ||\n isThemeAccentId(parsed.accent))\n ? parsed.accent\n : (normalizeCustomAccent(parsed.accent) ?? defaultThemeSelection.accent),\n font: fonts.ui.family,\n fonts,\n // Every axis has to be read back here, or it is lost twice: the provider's\n // document effect removes the `data-density` that `themeScript` set for the first paint, and\n // the next `setSelection` rewrites the store without it.\n density: resolvedDensity(parsed as ThemeSelection),\n // The newer axes are read back only when the store holds a usable value and are\n // otherwise left `undefined`, never defaulted: `JSON.stringify` drops them, so a\n // consumer that never sets one writes the bytes it always did. An id is kept as\n // stored, known or not, for the same reason a theme id the registry lacks is.\n terminalThemeId:\n typeof parsed.terminalThemeId === 'string' && parsed.terminalThemeId.trim() !== ''\n ? parsed.terminalThemeId\n : undefined,\n surface: normalizeSurface(parsed.surface),\n reduceTransparency:\n typeof parsed.reduceTransparency === 'boolean' ? parsed.reduceTransparency : undefined,\n }\n } catch {\n return defaultThemeSelection\n }\n}\n\n/**\n * The default persistence: one JSON document in `localStorage` under `key`.\n *\n * `read` is the provider's original `readSelection`, moved here unchanged — every\n * stored id is validated against the catalogue, so a stale preference falls back to\n * a default rather than reaching the document. `key` may be a function so a\n * provider whose `storageKey` prop changes writes to the key it is now given.\n *\n * Blocked, full or absent storage is survivable in both directions: a read answers\n * with the defaults and a write is dropped, so the preference simply lasts the\n * session.\n */\nexport function localStoragePersistence(key: string | (() => string)): ThemePersistence {\n const keyOf = () => (typeof key === 'function' ? key() : key)\n return {\n read: () => readSelection(keyOf()),\n write(next) {\n try {\n preferenceStore()?.setItem(keyOf(), JSON.stringify(next))\n } catch {\n // A full, blocked or unavailable store must not break the switch: the\n // preference simply does not survive the reload.\n }\n },\n }\n}\n\n/**\n * What a persistence knows, or nothing.\n *\n * The seam's `read` must not throw, and the provider does not rely on that: a host\n * persistence is code the design system has not seen, and a theme provider that\n * fails to mount because a store misbehaved has turned a lost preference into a\n * blank application.\n */\nexport function readPersisted(persistence: ThemePersistence): Partial<ThemeSelection> | undefined {\n try {\n return persistence.read()\n } catch {\n return undefined\n }\n}\n\n/** Hand a selection to the store; a store that throws loses the preference, not the switch. */\nexport function writePersisted(persistence: ThemePersistence, next: ThemeSelection): void {\n try {\n persistence.write(next)\n } catch {\n // Same contract as a full or blocked `localStorage`: the choice holds for the\n // session and does not survive the reload.\n }\n}\n\n/**\n * Where a host's versioned preference document lives. One schema describes the\n * document to both halves of the system: {@link createVersionedPersistence} reads and\n * writes it, and `themeScript(options)` reads it before first paint, so the two\n * cannot disagree about a key or a version.\n */\nexport type ThemeStorageSchema = {\n /** The storage key of the document. */\n key: string\n /**\n * The only top-level `version` read. Absent, the document is unversioned. A record\n * of any other version is quarantined (see `recoveryKey`), not interpreted.\n */\n version?: number\n /**\n * The document field that holds the appearance preference (`system`, `light`,\n * `dark`). Read by `themeScript`; the persistence leaves field names to the codec.\n * Default `appearance`.\n */\n appearanceField?: 'appearance' | 'mode'\n /**\n * An older single-value key (`light` | `dark` | `system`) read only while `key` is\n * absent, and never deleted. The persistence hands it to the codec's `fromLegacy`.\n */\n legacyAppearanceKey?: string\n /**\n * The stored library of imported themes, for `themeScript` only: an imported\n * theme's id and verbatim tokens, so the first paint can use the right variant. The\n * persistence neither reads nor writes it.\n */\n libraryKey?: string\n /** Where an unreadable document is kept. Default `${key}.recovery`. */\n recoveryKey?: string\n}\n\n/**\n * How a host's document maps to and from the shared {@link ThemeSelection}.\n *\n * The codec is the product schema: it decides which fields a document has, how an\n * unknown value is corrected, and what a fresh install looks like. The engine decides\n * everything about *storage*: what is quarantined, when the legacy key is read, and\n * that nothing is written until `setSelection` asks.\n */\nexport type VersionedCodec<Doc> = {\n /**\n * A readable record (the right JSON shape and version) as a selection patch. Fields\n * it leaves `undefined` fall back to the provider's defaults. It may keep an id the\n * catalogue lacks; the provider resolves it, it does not rewrite it.\n */\n decode(record: Readonly<Record<string, unknown>>): Partial<ThemeSelection>\n /**\n * The legacy key's value (never `null`) as a selection patch, or `undefined` for a\n * value it does not recognise. Called only when the main key is absent.\n */\n fromLegacy?(value: string): Partial<ThemeSelection> | undefined\n /**\n * What a store with nothing readable answers: a fresh install, an unreadable\n * document, a blocked store. Absent, the provider's own defaults apply.\n */\n defaults?(): Partial<ThemeSelection> | undefined\n /**\n * The document to store for a selection. `previous` is the record last read or\n * written, so a codec can carry a field the selection does not model.\n */\n encode(next: ThemeSelection, previous?: Readonly<Record<string, unknown>>): Doc\n}\n\n/** Seams for the storage and the clock; both default to the real ones. */\nexport type VersionedPersistenceOptions = {\n /** The store, or nothing. Called per access; default is `localStorage` (blocked-safe). */\n storage?: () => PreferenceStorage | undefined\n /** The clock for the recovery envelope's `capturedAt`. */\n now?: () => Date\n}\n\n/**\n * A {@link ThemePersistence} over a versioned document and a host codec.\n *\n * `read` follows the engine's rules (`lib/preference-store.ts`): the main key first;\n * an unreadable or unsupported document is quarantined byte for byte into the\n * recovery key and the codec's `defaults` answer; the legacy key only when the main\n * key is absent. It never writes the main key, so the first write is a user's\n * decision. `write` stores `codec.encode(next, previous)` as JSON and swallows a\n * failure.\n *\n * Neither method throws. The stored bytes are exactly what the codec encodes, so a\n * host keeps its keys, field names and bytes by keeping its codec.\n */\nexport function createVersionedPersistence<Doc>(\n schema: ThemeStorageSchema,\n codec: VersionedCodec<Doc>,\n options: VersionedPersistenceOptions = {}\n): ThemePersistence {\n const storageOf = options.storage ?? defaultPreferenceStorage\n const recordSchema = {\n key: schema.key,\n version: schema.version,\n recoveryKey: recoveryKeyFor(schema),\n }\n let previous: Readonly<Record<string, unknown>> | undefined\n\n const fallback = () => {\n try {\n return codec.defaults?.()\n } catch {\n return undefined\n }\n }\n\n return {\n read() {\n try {\n const storage = storageOf()\n if (!storage) return fallback()\n const found = readVersionedRecord(storage, recordSchema, options.now)\n if (found.status === 'record') {\n previous = found.record\n return codec.decode(found.record)\n }\n if (found.status === 'absent' && schema.legacyAppearanceKey && codec.fromLegacy) {\n const legacy = readLegacyValue(storage, schema.legacyAppearanceKey)\n const migrated = legacy === null ? undefined : codec.fromLegacy(legacy)\n if (migrated) return migrated\n }\n } catch {\n // A codec that throws on a record it cannot read is an unreadable store.\n }\n return fallback()\n },\n write(next) {\n try {\n const storage = storageOf()\n if (!storage) return\n const document = codec.encode(next, previous)\n if (writeVersionedRecord(storage, schema.key, document)) {\n previous =\n typeof document === 'object' && document !== null\n ? (document as Readonly<Record<string, unknown>>)\n : undefined\n }\n } catch {\n // An encoder that throws loses the preference, not the switch.\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsDA,SAAS,kBAAuC;CAC9C,OAAO,OAAO,iBAAiB,cAAc,KAAA,IAAY;AAC3D;;;;;AAMA,SAAS,cAAc,YAAoC;CACzD,IAAI;EACF,MAAM,MAAM,gBAAgB,CAAC,EAAE,QAAQ,UAAU;EACjD,IAAI,CAAC,KAAK,OAAO;EACjB,MAAM,SAAS,KAAK,MAAM,GAAG;EAC7B,MAAM,QAAQ,sCAAsC,OAAO,OAAO,OAAO,IAAI,CAAC,CAAC;EAC/E,OAAO;GACL,YACE,OAAO,eAAe,WACtB,OAAO,eAAe,UACtB,OAAO,eAAe,WAClB,OAAO,aACP,sBAAsB;GAG5B,cACE,yBAAyB,OAAO,gBAAgB,EAAE,MAAM,UACnD,OAAO,eACR;GACN,aACE,yBAAyB,OAAO,eAAe,EAAE,MAAM,SAClD,OAAO,cACR;GAMN,QACE,OAAO,OAAO,WAAW,aACxB,cAAc,MAAM,WAAW,OAAO,OAAO,OAAO,MAAM,KACzD,gBAAgB,OAAO,MAAM,KAC3B,OAAO,S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F;AACpF,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ1F;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,OAAO,EACd,cAAc,CAAC,EAAE,OAAO,GACvB,sCAAsC,CA+CxC;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,iBAAiB,GAAG,cAAc,GAAG,OAAO,CAAC,EACrE,KAAK,EAAE,OAAO,GACb,sCAAsC,CAsBxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAajG"}
|
|
@@ -23,8 +23,6 @@ var DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS = Object.freeze({
|
|
|
23
23
|
size: 12
|
|
24
24
|
})
|
|
25
25
|
});
|
|
26
|
-
var fontFamilyIds = new Set(fontOptions.map((option) => option.id));
|
|
27
|
-
var fontOptionsById = Object.freeze(Object.fromEntries(fontOptions.map((option) => [option.id, option])));
|
|
28
26
|
var fontProjectionById = Object.freeze(Object.fromEntries(fontOptions.map((option) => [option.id, {
|
|
29
27
|
familyVariables: option.familyVariables,
|
|
30
28
|
uiTracking: option.uiTracking,
|
|
@@ -60,7 +58,7 @@ function hasOwn(value, key) {
|
|
|
60
58
|
return Object.prototype.hasOwnProperty.call(value, key);
|
|
61
59
|
}
|
|
62
60
|
function normalizeFamily(value) {
|
|
63
|
-
return typeof value === "string" &&
|
|
61
|
+
return typeof value === "string" && hasOwn(fontProjectionById, value) ? value : void 0;
|
|
64
62
|
}
|
|
65
63
|
function clampFontSize(value) {
|
|
66
64
|
return Math.min(32, Math.max(10, Math.round(value)));
|
|
@@ -123,7 +121,7 @@ function applyAppearanceFontSettings(root, value) {
|
|
|
123
121
|
for (const axis of APPEARANCE_EDITOR_FONT_AXES) {
|
|
124
122
|
const projection = fontAxisProjection[axis];
|
|
125
123
|
const setting = settings[axis];
|
|
126
|
-
const option =
|
|
124
|
+
const option = fontProjectionById[setting.family];
|
|
127
125
|
if (setting.family === "system") root.removeAttribute(projection.familyAttribute);
|
|
128
126
|
else root.setAttribute(projection.familyAttribute, setting.family);
|
|
129
127
|
root.style.setProperty(projection.familyProperty, `var(${option.familyVariables[axis]})`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appearance-font-settings.js","names":[],"sources":["../../src/lib/appearance-font-settings.ts"],"sourcesContent":["import { fontOptions, type FontOption } from '#lib/font-catalog'\nimport { safeScriptStringLiteral } from '#lib/safe-script'\n\nexport const APPEARANCE_EDITOR_FONT_AXES = ['ui', 'content', 'code'] as const\n\nexport type AppearanceEditorFontAxis = (typeof APPEARANCE_EDITOR_FONT_AXES)[number]\nexport type AppearanceEditorFontFamilyId = FontOption['id']\n\nexport type AppearanceEditorFontSetting = Readonly<{\n /** A stable id from the shared font catalogue, never a CSS family string. */\n family: AppearanceEditorFontFamilyId\n /** A pixel size, normalized to the supported range. */\n size: number\n}>\n\n/** The host-owned choices edited by the shared appearance composition. */\nexport type AppearanceEditorFontSettings = Readonly<\n Record<AppearanceEditorFontAxis, AppearanceEditorFontSetting>\n>\n\nexport const APPEARANCE_EDITOR_FONT_SIZE_MIN = 10\nexport const APPEARANCE_EDITOR_FONT_SIZE_MAX = 32\n\n/** New preferences use the platform face in each text role. */\nexport const DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS: AppearanceEditorFontSettings = Object.freeze({\n ui: Object.freeze({ family: 'system', size: 14 }),\n content: Object.freeze({ family: 'system', size: 14 }),\n code: Object.freeze({ family: 'system', size: 12 }),\n})\n\nexport type NormalizedAppearanceEditorFontSettings = Readonly<{\n settings: AppearanceEditorFontSettings\n /** Axes whose persisted family or size was unavailable or outside its limits. */\n recoveredAxes: readonly AppearanceEditorFontAxis[]\n}>\n\nconst fontFamilyIds: ReadonlySet<string> = new Set(fontOptions.map((option) => option.id))\nconst fontOptionsById = Object.freeze(\n Object.fromEntries(fontOptions.map((option) => [option.id, option])) as Record<\n AppearanceEditorFontFamilyId,\n FontOption\n >\n)\nconst fontProjectionById = Object.freeze(\n Object.fromEntries(\n fontOptions.map((option) => [\n option.id,\n {\n familyVariables: option.familyVariables,\n uiTracking: option.uiTracking,\n uiWordSpacing: option.uiWordSpacing,\n },\n ])\n ) as Record<\n AppearanceEditorFontFamilyId,\n Pick<FontOption, 'familyVariables' | 'uiTracking' | 'uiWordSpacing'>\n >\n)\nconst fontAxisProjection = Object.freeze({\n ui: Object.freeze({\n familyAttribute: 'data-ui-font',\n familyProperty: '--font-ui',\n sizeProperty: '--font-ui-size',\n scaleProperty: '--font-ui-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.ui.size,\n }),\n content: Object.freeze({\n familyAttribute: 'data-content-font',\n familyProperty: '--font-content',\n sizeProperty: '--font-content-size',\n scaleProperty: '--font-content-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.content.size,\n }),\n code: Object.freeze({\n familyAttribute: 'data-code-font',\n familyProperty: '--font-code',\n sizeProperty: '--font-code-size',\n scaleProperty: '--font-code-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.code.size,\n }),\n})\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction hasOwn(value: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction normalizeFamily(value: unknown): AppearanceEditorFontFamilyId | undefined {\n return typeof value === 'string' && fontFamilyIds.has(value)\n ? (value as AppearanceEditorFontFamilyId)\n : undefined\n}\n\nfunction clampFontSize(value: number): number {\n return Math.min(\n APPEARANCE_EDITOR_FONT_SIZE_MAX,\n Math.max(APPEARANCE_EDITOR_FONT_SIZE_MIN, Math.round(value))\n )\n}\n\n/** Normalize a single number-input value; invalid edits return the current size. */\nexport function normalizeAppearanceEditorFontSize(value: unknown, fallback: number): number {\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.trim() !== ''\n ? Number(value)\n : Number.NaN\n return Number.isFinite(parsed) ? clampFontSize(parsed) : clampFontSize(fallback)\n}\n\n/**\n * Recover persisted font choices against the shared font catalogue.\n *\n * `legacyUiFamily` lets a host migrate its previous single font field into the\n * UI axis. Content and code remain on the new System defaults during that\n * migration. Missing settings are ordinary defaults; an unknown saved id or an\n * invalid size is reported through `recoveredAxes` for the host's notice.\n */\nexport function normalizeAppearanceEditorFontSettings(\n value: unknown,\n legacyUiFamily?: unknown\n): NormalizedAppearanceEditorFontSettings {\n const source = isRecord(value) ? value : undefined\n const malformedRoot = value !== undefined && value !== null && source === undefined\n const recovered = new Set<AppearanceEditorFontAxis>()\n const settings = {} as Record<AppearanceEditorFontAxis, AppearanceEditorFontSetting>\n\n for (const axis of APPEARANCE_EDITOR_FONT_AXES) {\n const axisPresent = source ? hasOwn(source, axis) : false\n const axisValue = source?.[axis]\n const axisSource = isRecord(axisValue) ? axisValue : undefined\n const fallback = DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS[axis]\n\n if (malformedRoot || (axisPresent && axisSource === undefined)) recovered.add(axis)\n\n const hasFamily = axisSource ? hasOwn(axisSource, 'family') : false\n const familyInput = hasFamily\n ? axisSource?.['family']\n : axis === 'ui' && legacyUiFamily !== undefined\n ? legacyUiFamily\n : undefined\n const family = normalizeFamily(familyInput) ?? fallback.family\n if (\n (hasFamily || (axis === 'ui' && legacyUiFamily !== undefined)) &&\n !normalizeFamily(familyInput)\n ) {\n recovered.add(axis)\n }\n\n const hasSize = axisSource ? hasOwn(axisSource, 'size') : false\n const sizeInput = axisSource?.['size']\n const size = hasSize\n ? normalizeAppearanceEditorFontSize(sizeInput, fallback.size)\n : fallback.size\n if (\n hasSize &&\n (typeof sizeInput !== 'number' || !Number.isFinite(sizeInput) || sizeInput !== size)\n ) {\n recovered.add(axis)\n }\n\n settings[axis] = Object.freeze({ family, size })\n }\n\n return Object.freeze({\n settings: Object.freeze(settings),\n recoveredAxes: Object.freeze(APPEARANCE_EDITOR_FONT_AXES.filter((axis) => recovered.has(axis))),\n })\n}\n\n/**\n * Project normalized font preferences onto a document root.\n *\n * This is shared by `ThemeProvider` and hosts that own their own appearance\n * persistence, so UI/content/code use the same catalogue ids, theme tokens,\n * sizes, and projected CSS variables. The marker activates the optional role\n * stylesheet and survives CSS import reordering.\n */\nexport function applyAppearanceFontSettings(\n root: Pick<HTMLElement, 'removeAttribute' | 'setAttribute' | 'style'>,\n value: unknown\n): NormalizedAppearanceEditorFontSettings {\n const normalized = normalizeAppearanceEditorFontSettings(value)\n const { settings } = normalized\n\n root.removeAttribute('data-font')\n root.setAttribute('data-font-settings', '')\n for (const axis of APPEARANCE_EDITOR_FONT_AXES) {\n const projection = fontAxisProjection[axis]\n const setting = settings[axis]\n const option = fontOptionsById[setting.family]\n if (setting.family === 'system') root.removeAttribute(projection.familyAttribute)\n else root.setAttribute(projection.familyAttribute, setting.family)\n root.style.setProperty(projection.familyProperty, `var(${option.familyVariables[axis]})`)\n root.style.setProperty(projection.sizeProperty, String(setting.size) + 'px')\n root.style.setProperty(projection.scaleProperty, String(setting.size / projection.defaultSize))\n if (axis === 'ui') {\n root.style.setProperty('--ui-tracking', option.uiTracking)\n root.style.setProperty('--ui-word-spacing', option.uiWordSpacing)\n }\n }\n\n return normalized\n}\n\n/**\n * Generate a safe inline prepaint script for a host-owned appearance record.\n *\n * The stored object is read from `localStorage[storageKey].fonts`. A legacy\n * top-level `font` family migrates into UI only; content/code use the shared\n * defaults. The script applies the same catalogue whitelist, limits, attributes,\n * and CSS properties as `applyAppearanceFontSettings` before styles paint. When\n * `persistedVersion` is supplied, only a record with that exact top-level version\n * is used; absent or mismatched records receive the System defaults.\n */\nexport function fontSettingsBootstrapScript(storageKey: string, persistedVersion?: number): string {\n if (persistedVersion !== undefined && !Number.isSafeInteger(persistedVersion)) {\n throw new RangeError('persistedVersion must be a safe integer')\n }\n const axisConfig = JSON.stringify(fontAxisProjection)\n const fontProjection = JSON.stringify(fontProjectionById)\n const fontIds = `[${fontOptions.map((option) => safeScriptStringLiteral(option.id)).join(',')}]`\n const persistedVersionGuard =\n persistedVersion === undefined\n ? ''\n : `&&parsed.version===Number(${safeScriptStringLiteral(String(persistedVersion))})`\n\n return `(function(){var r=document.documentElement;var axes=JSON.parse(${safeScriptStringLiteral(axisConfig)});var projection=JSON.parse(${safeScriptStringLiteral(fontProjection)});var ids=${fontIds};var has=function(v,k){return Object.prototype.hasOwnProperty.call(v,k)};var record=function(v){return typeof v==='object'&&v!==null&&!Array.isArray(v)};var p={};try{var raw=localStorage.getItem(${safeScriptStringLiteral(storageKey)});var parsed=raw?JSON.parse(raw):{};if(record(parsed)${persistedVersionGuard})p=parsed;}catch(e){}var saved=record(p.fonts)?p.fonts:{};var valid=function(v,d){return ids.indexOf(v)!==-1?v:d};var size=function(v,d){var n=typeof v==='number'?v:typeof v==='string'&&v.trim()!==''?Number(v):NaN;return Number.isFinite(n)?Math.min(${APPEARANCE_EDITOR_FONT_SIZE_MAX},Math.max(${APPEARANCE_EDITOR_FONT_SIZE_MIN},Math.round(n))):d};r.setAttribute('data-font-settings','');for(var axis in axes){if(!has(axes,axis))continue;var spec=axes[axis];var candidate=saved[axis];var value=record(candidate)?candidate:{};var legacyUi=axis==='ui'&&!has(value,'family');var family=legacyUi?valid(p.font,'system'):valid(value.family,'system');var font=projection[family];if(family==='system')r.removeAttribute(spec.familyAttribute);else r.setAttribute(spec.familyAttribute,family);r.style.setProperty(spec.familyProperty,'var('+font.familyVariables[axis]+')');var px=size(value.size,spec.defaultSize);r.style.setProperty(spec.sizeProperty,px+'px');r.style.setProperty(spec.scaleProperty,String(px/spec.defaultSize));if(axis==='ui'){r.style.setProperty('--ui-tracking',font.uiTracking);r.style.setProperty('--ui-word-spacing',font.uiWordSpacing);}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,gBAAgB,GAC1E,MAAM,IAAI,WAAW,yCAAyC;CAEhE,MAAM,aAAa,KAAK,UAAU,kBAAkB;CACpD,MAAM,iBAAiB,KAAK,UAAU,kBAAkB;CACxD,MAAM,UAAU,IAAI,YAAY,KAAK,WAAW,wBAAwB,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;CAC9F,MAAM,wBACJ,qBAAqB,KAAA,IACjB,KACA,6BAA6B,wBAAwB,OAAO,gBAAgB,CAAC,EAAE;CAErF,OAAO,kEAAkE,wBAAwB,UAAU,EAAE,8BAA8B,wBAAwB,cAAc,EAAE,YAAY,QAAQ,qMAAqM,wBAAwB,UAAU,EAAE,uDAAuD,sBAAsB;AAC/f"}
|
|
1
|
+
{"version":3,"file":"appearance-font-settings.js","names":[],"sources":["../../src/lib/appearance-font-settings.ts"],"sourcesContent":["import { fontOptions, type FontOption } from '#lib/font-catalog'\nimport { safeScriptStringLiteral } from '#lib/safe-script'\n\nexport const APPEARANCE_EDITOR_FONT_AXES = ['ui', 'content', 'code'] as const\n\nexport type AppearanceEditorFontAxis = (typeof APPEARANCE_EDITOR_FONT_AXES)[number]\nexport type AppearanceEditorFontFamilyId = FontOption['id']\n\nexport type AppearanceEditorFontSetting = Readonly<{\n /** A stable id from the shared font catalogue, never a CSS family string. */\n family: AppearanceEditorFontFamilyId\n /** A pixel size, normalized to the supported range. */\n size: number\n}>\n\n/** The host-owned choices edited by the shared appearance composition. */\nexport type AppearanceEditorFontSettings = Readonly<\n Record<AppearanceEditorFontAxis, AppearanceEditorFontSetting>\n>\n\nexport const APPEARANCE_EDITOR_FONT_SIZE_MIN = 10\nexport const APPEARANCE_EDITOR_FONT_SIZE_MAX = 32\n\n/** New preferences use the platform face in each text role. */\nexport const DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS: AppearanceEditorFontSettings = Object.freeze({\n ui: Object.freeze({ family: 'system', size: 14 }),\n content: Object.freeze({ family: 'system', size: 14 }),\n code: Object.freeze({ family: 'system', size: 12 }),\n})\n\nexport type NormalizedAppearanceEditorFontSettings = Readonly<{\n settings: AppearanceEditorFontSettings\n /** Axes whose persisted family or size was unavailable or outside its limits. */\n recoveredAxes: readonly AppearanceEditorFontAxis[]\n}>\n\nconst fontProjectionById = Object.freeze(\n Object.fromEntries(\n fontOptions.map((option) => [\n option.id,\n {\n familyVariables: option.familyVariables,\n uiTracking: option.uiTracking,\n uiWordSpacing: option.uiWordSpacing,\n },\n ])\n ) as Record<\n AppearanceEditorFontFamilyId,\n Pick<FontOption, 'familyVariables' | 'uiTracking' | 'uiWordSpacing'>\n >\n)\nconst fontAxisProjection = Object.freeze({\n ui: Object.freeze({\n familyAttribute: 'data-ui-font',\n familyProperty: '--font-ui',\n sizeProperty: '--font-ui-size',\n scaleProperty: '--font-ui-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.ui.size,\n }),\n content: Object.freeze({\n familyAttribute: 'data-content-font',\n familyProperty: '--font-content',\n sizeProperty: '--font-content-size',\n scaleProperty: '--font-content-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.content.size,\n }),\n code: Object.freeze({\n familyAttribute: 'data-code-font',\n familyProperty: '--font-code',\n sizeProperty: '--font-code-size',\n scaleProperty: '--font-code-scale',\n defaultSize: DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS.code.size,\n }),\n})\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction hasOwn(value: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction normalizeFamily(value: unknown): AppearanceEditorFontFamilyId | undefined {\n return typeof value === 'string' && hasOwn(fontProjectionById, value)\n ? (value as AppearanceEditorFontFamilyId)\n : undefined\n}\n\nfunction clampFontSize(value: number): number {\n return Math.min(\n APPEARANCE_EDITOR_FONT_SIZE_MAX,\n Math.max(APPEARANCE_EDITOR_FONT_SIZE_MIN, Math.round(value))\n )\n}\n\n/** Normalize a single number-input value; invalid edits return the current size. */\nexport function normalizeAppearanceEditorFontSize(value: unknown, fallback: number): number {\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.trim() !== ''\n ? Number(value)\n : Number.NaN\n return Number.isFinite(parsed) ? clampFontSize(parsed) : clampFontSize(fallback)\n}\n\n/**\n * Recover persisted font choices against the shared font catalogue.\n *\n * `legacyUiFamily` lets a host migrate its previous single font field into the\n * UI axis. Content and code remain on the new System defaults during that\n * migration. Missing settings are ordinary defaults; an unknown saved id or an\n * invalid size is reported through `recoveredAxes` for the host's notice.\n */\nexport function normalizeAppearanceEditorFontSettings(\n value: unknown,\n legacyUiFamily?: unknown\n): NormalizedAppearanceEditorFontSettings {\n const source = isRecord(value) ? value : undefined\n const malformedRoot = value !== undefined && value !== null && source === undefined\n const recovered = new Set<AppearanceEditorFontAxis>()\n const settings = {} as Record<AppearanceEditorFontAxis, AppearanceEditorFontSetting>\n\n for (const axis of APPEARANCE_EDITOR_FONT_AXES) {\n const axisPresent = source ? hasOwn(source, axis) : false\n const axisValue = source?.[axis]\n const axisSource = isRecord(axisValue) ? axisValue : undefined\n const fallback = DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS[axis]\n\n if (malformedRoot || (axisPresent && axisSource === undefined)) recovered.add(axis)\n\n const hasFamily = axisSource ? hasOwn(axisSource, 'family') : false\n const familyInput = hasFamily\n ? axisSource?.['family']\n : axis === 'ui' && legacyUiFamily !== undefined\n ? legacyUiFamily\n : undefined\n const family = normalizeFamily(familyInput) ?? fallback.family\n if (\n (hasFamily || (axis === 'ui' && legacyUiFamily !== undefined)) &&\n !normalizeFamily(familyInput)\n ) {\n recovered.add(axis)\n }\n\n const hasSize = axisSource ? hasOwn(axisSource, 'size') : false\n const sizeInput = axisSource?.['size']\n const size = hasSize\n ? normalizeAppearanceEditorFontSize(sizeInput, fallback.size)\n : fallback.size\n if (\n hasSize &&\n (typeof sizeInput !== 'number' || !Number.isFinite(sizeInput) || sizeInput !== size)\n ) {\n recovered.add(axis)\n }\n\n settings[axis] = Object.freeze({ family, size })\n }\n\n return Object.freeze({\n settings: Object.freeze(settings),\n recoveredAxes: Object.freeze(APPEARANCE_EDITOR_FONT_AXES.filter((axis) => recovered.has(axis))),\n })\n}\n\n/**\n * Project normalized font preferences onto a document root.\n *\n * This is shared by `ThemeProvider` and hosts that own their own appearance\n * persistence, so UI/content/code use the same catalogue ids, theme tokens,\n * sizes, and projected CSS variables. The marker activates the optional role\n * stylesheet and survives CSS import reordering.\n */\nexport function applyAppearanceFontSettings(\n root: Pick<HTMLElement, 'removeAttribute' | 'setAttribute' | 'style'>,\n value: unknown\n): NormalizedAppearanceEditorFontSettings {\n const normalized = normalizeAppearanceEditorFontSettings(value)\n const { settings } = normalized\n\n root.removeAttribute('data-font')\n root.setAttribute('data-font-settings', '')\n for (const axis of APPEARANCE_EDITOR_FONT_AXES) {\n const projection = fontAxisProjection[axis]\n const setting = settings[axis]\n const option = fontProjectionById[setting.family]\n if (setting.family === 'system') root.removeAttribute(projection.familyAttribute)\n else root.setAttribute(projection.familyAttribute, setting.family)\n root.style.setProperty(projection.familyProperty, `var(${option.familyVariables[axis]})`)\n root.style.setProperty(projection.sizeProperty, String(setting.size) + 'px')\n root.style.setProperty(projection.scaleProperty, String(setting.size / projection.defaultSize))\n if (axis === 'ui') {\n root.style.setProperty('--ui-tracking', option.uiTracking)\n root.style.setProperty('--ui-word-spacing', option.uiWordSpacing)\n }\n }\n\n return normalized\n}\n\n/**\n * Generate a safe inline prepaint script for a host-owned appearance record.\n *\n * The stored object is read from `localStorage[storageKey].fonts`. A legacy\n * top-level `font` family migrates into UI only; content/code use the shared\n * defaults. The script applies the same catalogue whitelist, limits, attributes,\n * and CSS properties as `applyAppearanceFontSettings` before styles paint. When\n * `persistedVersion` is supplied, only a record with that exact top-level version\n * is used; absent or mismatched records receive the System defaults.\n */\nexport function fontSettingsBootstrapScript(storageKey: string, persistedVersion?: number): string {\n if (persistedVersion !== undefined && !Number.isSafeInteger(persistedVersion)) {\n throw new RangeError('persistedVersion must be a safe integer')\n }\n const axisConfig = JSON.stringify(fontAxisProjection)\n const fontProjection = JSON.stringify(fontProjectionById)\n const fontIds = `[${fontOptions.map((option) => safeScriptStringLiteral(option.id)).join(',')}]`\n const persistedVersionGuard =\n persistedVersion === undefined\n ? ''\n : `&&parsed.version===Number(${safeScriptStringLiteral(String(persistedVersion))})`\n\n return `(function(){var r=document.documentElement;var axes=JSON.parse(${safeScriptStringLiteral(axisConfig)});var projection=JSON.parse(${safeScriptStringLiteral(fontProjection)});var ids=${fontIds};var has=function(v,k){return Object.prototype.hasOwnProperty.call(v,k)};var record=function(v){return typeof v==='object'&&v!==null&&!Array.isArray(v)};var p={};try{var raw=localStorage.getItem(${safeScriptStringLiteral(storageKey)});var parsed=raw?JSON.parse(raw):{};if(record(parsed)${persistedVersionGuard})p=parsed;}catch(e){}var saved=record(p.fonts)?p.fonts:{};var valid=function(v,d){return ids.indexOf(v)!==-1?v:d};var size=function(v,d){var n=typeof v==='number'?v:typeof v==='string'&&v.trim()!==''?Number(v):NaN;return Number.isFinite(n)?Math.min(${APPEARANCE_EDITOR_FONT_SIZE_MAX},Math.max(${APPEARANCE_EDITOR_FONT_SIZE_MIN},Math.round(n))):d};r.setAttribute('data-font-settings','');for(var axis in axes){if(!has(axes,axis))continue;var spec=axes[axis];var candidate=saved[axis];var value=record(candidate)?candidate:{};var legacyUi=axis==='ui'&&!has(value,'family');var family=legacyUi?valid(p.font,'system'):valid(value.family,'system');var font=projection[family];if(family==='system')r.removeAttribute(spec.familyAttribute);else r.setAttribute(spec.familyAttribute,family);r.style.setProperty(spec.familyProperty,'var('+font.familyVariables[axis]+')');var px=size(value.size,spec.defaultSize);r.style.setProperty(spec.sizeProperty,px+'px');r.style.setProperty(spec.scaleProperty,String(px/spec.defaultSize));if(axis==='ui'){r.style.setProperty('--ui-tracking',font.uiTracking);r.style.setProperty('--ui-word-spac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,KAAK,WAAW,wBAAwB,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;CAC9F,MAAM,wBACJ,qBAAqB,KAAA,IACjB,KACA,6BAA6B,wBAAwB,OAAO,gBAAgB,CAAC,EAAE;CAErF,OAAO,kEAAkE,wBAAwB,UAAU,EAAE,8BAA8B,wBAAwB,cAAc,EAAE,YAAY,QAAQ,qMAAqM,wBAAwB,UAAU,EAAE,uDAAuD,sBAAsB;AAC/f"}
|
package/dist/r/lib.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"title": "Class-name and token helpers",
|
|
5
5
|
"description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
|
|
6
6
|
"dependencies": [
|
|
7
|
-
"@adea-ai/themes@^0.
|
|
7
|
+
"@adea-ai/themes@^0.11.2",
|
|
8
8
|
"class-variance-authority@^0.7.1",
|
|
9
9
|
"cn@^0.4.0"
|
|
10
10
|
],
|
package/dist/r/registry.json
CHANGED
|
@@ -2298,7 +2298,7 @@
|
|
|
2298
2298
|
"title": "Appearance Editor",
|
|
2299
2299
|
"description": "",
|
|
2300
2300
|
"dependencies": [
|
|
2301
|
-
"@adea-ai/themes@^0.
|
|
2301
|
+
"@adea-ai/themes@^0.11.2",
|
|
2302
2302
|
"@kobalte/core@^0.13.14",
|
|
2303
2303
|
"lucide-solid@^1.51.0"
|
|
2304
2304
|
],
|
|
@@ -3458,7 +3458,7 @@
|
|
|
3458
3458
|
"title": "Theming",
|
|
3459
3459
|
"description": "",
|
|
3460
3460
|
"dependencies": [
|
|
3461
|
-
"@adea-ai/themes@^0.
|
|
3461
|
+
"@adea-ai/themes@^0.11.2",
|
|
3462
3462
|
"@kobalte/core@^0.13.14",
|
|
3463
3463
|
"lucide-solid@^1.51.0"
|
|
3464
3464
|
],
|
|
@@ -3643,7 +3643,7 @@
|
|
|
3643
3643
|
"title": "Class-name and token helpers",
|
|
3644
3644
|
"description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
|
|
3645
3645
|
"dependencies": [
|
|
3646
|
-
"@adea-ai/themes@^0.
|
|
3646
|
+
"@adea-ai/themes@^0.11.2",
|
|
3647
3647
|
"class-variance-authority@^0.7.1",
|
|
3648
3648
|
"cn@^0.4.0"
|
|
3649
3649
|
],
|
|
@@ -84,8 +84,11 @@ function containsLeaf<L extends SplitLayoutLeaf>(
|
|
|
84
84
|
function assertUniqueInput<L extends SplitLayoutLeaf>(
|
|
85
85
|
state: SplitLayoutState<L>,
|
|
86
86
|
leaf: L,
|
|
87
|
-
splitId: string
|
|
87
|
+
splitId: string,
|
|
88
|
+
placement: SplitPaneInput<L>['placement']
|
|
88
89
|
) {
|
|
90
|
+
if (!leaf || leaf.kind !== 'leaf' || (placement !== 'before' && placement !== 'after'))
|
|
91
|
+
throw new Error('invalid_state: invalid split input')
|
|
89
92
|
assertLayoutTree(leaf)
|
|
90
93
|
if (typeof splitId !== 'string' || splitId.length === 0)
|
|
91
94
|
throw new Error('invalid_state: split identity must be nonempty')
|
|
@@ -153,9 +156,11 @@ export function splitPane<L extends SplitLayoutLeaf>(
|
|
|
153
156
|
input: SplitPaneInput<L>
|
|
154
157
|
): SplitLayoutState<L> {
|
|
155
158
|
if (!containsLeaf(state.center, targetLeafId)) return state
|
|
159
|
+
if (input.direction !== 'row' && input.direction !== 'column')
|
|
160
|
+
throw new Error('invalid_state: invalid split input')
|
|
156
161
|
if (countLeaves(state.center) >= MAX_LAYOUT_LEAVES)
|
|
157
162
|
throw new Error('limit_exceeded: center layout has eight leaves')
|
|
158
|
-
assertUniqueInput(state, input.leaf, input.splitId)
|
|
163
|
+
assertUniqueInput(state, input.leaf, input.splitId, input.placement)
|
|
159
164
|
const target = listLeaves(state.center).find((leaf) => leaf.id === targetLeafId)
|
|
160
165
|
if (!target) return state
|
|
161
166
|
const children =
|
|
@@ -173,15 +178,10 @@ export function splitPane<L extends SplitLayoutLeaf>(
|
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* equal height. Existing opaque leaf objects are preserved. Split IDs are
|
|
181
|
-
* recycled across rebuilt branches, whose axis and descendants can change;
|
|
182
|
-
* resize actions must resolve against the current tree. Ratios are recomputed.
|
|
183
|
-
* This is opt-in: callers
|
|
184
|
-
* that need an explicit axis and ratio should keep using `splitPane`.
|
|
181
|
+
* Reflow into a balanced row-major grid of at most two rows and four columns,
|
|
182
|
+
* preserving opaque leaves. Split IDs are recycled across rebuilt branches, so
|
|
183
|
+
* resize actions must resolve against the current tree. Call `splitPane` instead
|
|
184
|
+
* when the axis and ratio must be explicit.
|
|
185
185
|
*/
|
|
186
186
|
export function splitPaneBalanced<L extends SplitLayoutLeaf>(
|
|
187
187
|
state: SplitLayoutState<L>,
|
|
@@ -193,7 +193,7 @@ export function splitPaneBalanced<L extends SplitLayoutLeaf>(
|
|
|
193
193
|
if (targetIndex < 0) return state
|
|
194
194
|
if (leaves.length >= MAX_LAYOUT_LEAVES)
|
|
195
195
|
throw new Error('limit_exceeded: center layout has eight leaves')
|
|
196
|
-
const splitIds = assertUniqueInput(state, input.leaf, input.splitId)
|
|
196
|
+
const splitIds = assertUniqueInput(state, input.leaf, input.splitId, input.placement)
|
|
197
197
|
|
|
198
198
|
const insertionIndex = targetIndex + (input.placement === 'before' ? 0 : 1)
|
|
199
199
|
leaves.splice(insertionIndex, 0, input.leaf)
|
|
@@ -281,9 +281,9 @@ export function createVersionedPersistence<Doc>(
|
|
|
281
281
|
|
|
282
282
|
return {
|
|
283
283
|
read() {
|
|
284
|
-
const storage = storageOf()
|
|
285
|
-
if (!storage) return fallback()
|
|
286
284
|
try {
|
|
285
|
+
const storage = storageOf()
|
|
286
|
+
if (!storage) return fallback()
|
|
287
287
|
const found = readVersionedRecord(storage, recordSchema, options.now)
|
|
288
288
|
if (found.status === 'record') {
|
|
289
289
|
previous = found.record
|
|
@@ -300,9 +300,9 @@ export function createVersionedPersistence<Doc>(
|
|
|
300
300
|
return fallback()
|
|
301
301
|
},
|
|
302
302
|
write(next) {
|
|
303
|
-
const storage = storageOf()
|
|
304
|
-
if (!storage) return
|
|
305
303
|
try {
|
|
304
|
+
const storage = storageOf()
|
|
305
|
+
if (!storage) return
|
|
306
306
|
const document = codec.encode(next, previous)
|
|
307
307
|
if (writeVersionedRecord(storage, schema.key, document)) {
|
|
308
308
|
previous =
|
|
@@ -34,13 +34,6 @@ export type NormalizedAppearanceEditorFontSettings = Readonly<{
|
|
|
34
34
|
recoveredAxes: readonly AppearanceEditorFontAxis[]
|
|
35
35
|
}>
|
|
36
36
|
|
|
37
|
-
const fontFamilyIds: ReadonlySet<string> = new Set(fontOptions.map((option) => option.id))
|
|
38
|
-
const fontOptionsById = Object.freeze(
|
|
39
|
-
Object.fromEntries(fontOptions.map((option) => [option.id, option])) as Record<
|
|
40
|
-
AppearanceEditorFontFamilyId,
|
|
41
|
-
FontOption
|
|
42
|
-
>
|
|
43
|
-
)
|
|
44
37
|
const fontProjectionById = Object.freeze(
|
|
45
38
|
Object.fromEntries(
|
|
46
39
|
fontOptions.map((option) => [
|
|
@@ -89,7 +82,7 @@ function hasOwn(value: Record<string, unknown>, key: string): boolean {
|
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
function normalizeFamily(value: unknown): AppearanceEditorFontFamilyId | undefined {
|
|
92
|
-
return typeof value === 'string' &&
|
|
85
|
+
return typeof value === 'string' && hasOwn(fontProjectionById, value)
|
|
93
86
|
? (value as AppearanceEditorFontFamilyId)
|
|
94
87
|
: undefined
|
|
95
88
|
}
|
|
@@ -192,7 +185,7 @@ export function applyAppearanceFontSettings(
|
|
|
192
185
|
for (const axis of APPEARANCE_EDITOR_FONT_AXES) {
|
|
193
186
|
const projection = fontAxisProjection[axis]
|
|
194
187
|
const setting = settings[axis]
|
|
195
|
-
const option =
|
|
188
|
+
const option = fontProjectionById[setting.family]
|
|
196
189
|
if (setting.family === 'system') root.removeAttribute(projection.familyAttribute)
|
|
197
190
|
else root.setAttribute(projection.familyAttribute, setting.family)
|
|
198
191
|
root.style.setProperty(projection.familyProperty, `var(${option.familyVariables[axis]})`)
|
package/dist/r/theming.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/ui",
|
|
3
|
-
"version": "0.147.
|
|
3
|
+
"version": "0.147.11",
|
|
4
4
|
"description": "The Adea design system: Kobalte-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adea",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"check:packed-paste-model": "node scripts/check-packed-paste-model.mjs"
|
|
146
146
|
},
|
|
147
147
|
"dependencies": {
|
|
148
|
-
"@adea-ai/themes": "^0.
|
|
148
|
+
"@adea-ai/themes": "^0.11.2",
|
|
149
149
|
"@corvu/calendar": "^0.1.2",
|
|
150
150
|
"@corvu/drawer": "^0.2.4",
|
|
151
151
|
"@corvu/otp-field": "^0.1.4",
|
package/registry.json
CHANGED
|
@@ -2298,7 +2298,7 @@
|
|
|
2298
2298
|
"title": "Appearance Editor",
|
|
2299
2299
|
"description": "",
|
|
2300
2300
|
"dependencies": [
|
|
2301
|
-
"@adea-ai/themes@^0.
|
|
2301
|
+
"@adea-ai/themes@^0.11.2",
|
|
2302
2302
|
"@kobalte/core@^0.13.14",
|
|
2303
2303
|
"lucide-solid@^1.51.0"
|
|
2304
2304
|
],
|
|
@@ -3458,7 +3458,7 @@
|
|
|
3458
3458
|
"title": "Theming",
|
|
3459
3459
|
"description": "",
|
|
3460
3460
|
"dependencies": [
|
|
3461
|
-
"@adea-ai/themes@^0.
|
|
3461
|
+
"@adea-ai/themes@^0.11.2",
|
|
3462
3462
|
"@kobalte/core@^0.13.14",
|
|
3463
3463
|
"lucide-solid@^1.51.0"
|
|
3464
3464
|
],
|
|
@@ -3643,7 +3643,7 @@
|
|
|
3643
3643
|
"title": "Class-name and token helpers",
|
|
3644
3644
|
"description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
|
|
3645
3645
|
"dependencies": [
|
|
3646
|
-
"@adea-ai/themes@^0.
|
|
3646
|
+
"@adea-ai/themes@^0.11.2",
|
|
3647
3647
|
"class-variance-authority@^0.7.1",
|
|
3648
3648
|
"cn@^0.4.0"
|
|
3649
3649
|
],
|
|
@@ -84,8 +84,11 @@ function containsLeaf<L extends SplitLayoutLeaf>(
|
|
|
84
84
|
function assertUniqueInput<L extends SplitLayoutLeaf>(
|
|
85
85
|
state: SplitLayoutState<L>,
|
|
86
86
|
leaf: L,
|
|
87
|
-
splitId: string
|
|
87
|
+
splitId: string,
|
|
88
|
+
placement: SplitPaneInput<L>['placement']
|
|
88
89
|
) {
|
|
90
|
+
if (!leaf || leaf.kind !== 'leaf' || (placement !== 'before' && placement !== 'after'))
|
|
91
|
+
throw new Error('invalid_state: invalid split input')
|
|
89
92
|
assertLayoutTree(leaf)
|
|
90
93
|
if (typeof splitId !== 'string' || splitId.length === 0)
|
|
91
94
|
throw new Error('invalid_state: split identity must be nonempty')
|
|
@@ -153,9 +156,11 @@ export function splitPane<L extends SplitLayoutLeaf>(
|
|
|
153
156
|
input: SplitPaneInput<L>
|
|
154
157
|
): SplitLayoutState<L> {
|
|
155
158
|
if (!containsLeaf(state.center, targetLeafId)) return state
|
|
159
|
+
if (input.direction !== 'row' && input.direction !== 'column')
|
|
160
|
+
throw new Error('invalid_state: invalid split input')
|
|
156
161
|
if (countLeaves(state.center) >= MAX_LAYOUT_LEAVES)
|
|
157
162
|
throw new Error('limit_exceeded: center layout has eight leaves')
|
|
158
|
-
assertUniqueInput(state, input.leaf, input.splitId)
|
|
163
|
+
assertUniqueInput(state, input.leaf, input.splitId, input.placement)
|
|
159
164
|
const target = listLeaves(state.center).find((leaf) => leaf.id === targetLeafId)
|
|
160
165
|
if (!target) return state
|
|
161
166
|
const children =
|
|
@@ -173,15 +178,10 @@ export function splitPane<L extends SplitLayoutLeaf>(
|
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* equal height. Existing opaque leaf objects are preserved. Split IDs are
|
|
181
|
-
* recycled across rebuilt branches, whose axis and descendants can change;
|
|
182
|
-
* resize actions must resolve against the current tree. Ratios are recomputed.
|
|
183
|
-
* This is opt-in: callers
|
|
184
|
-
* that need an explicit axis and ratio should keep using `splitPane`.
|
|
181
|
+
* Reflow into a balanced row-major grid of at most two rows and four columns,
|
|
182
|
+
* preserving opaque leaves. Split IDs are recycled across rebuilt branches, so
|
|
183
|
+
* resize actions must resolve against the current tree. Call `splitPane` instead
|
|
184
|
+
* when the axis and ratio must be explicit.
|
|
185
185
|
*/
|
|
186
186
|
export function splitPaneBalanced<L extends SplitLayoutLeaf>(
|
|
187
187
|
state: SplitLayoutState<L>,
|
|
@@ -193,7 +193,7 @@ export function splitPaneBalanced<L extends SplitLayoutLeaf>(
|
|
|
193
193
|
if (targetIndex < 0) return state
|
|
194
194
|
if (leaves.length >= MAX_LAYOUT_LEAVES)
|
|
195
195
|
throw new Error('limit_exceeded: center layout has eight leaves')
|
|
196
|
-
const splitIds = assertUniqueInput(state, input.leaf, input.splitId)
|
|
196
|
+
const splitIds = assertUniqueInput(state, input.leaf, input.splitId, input.placement)
|
|
197
197
|
|
|
198
198
|
const insertionIndex = targetIndex + (input.placement === 'before' ? 0 : 1)
|
|
199
199
|
leaves.splice(insertionIndex, 0, input.leaf)
|
|
@@ -281,9 +281,9 @@ export function createVersionedPersistence<Doc>(
|
|
|
281
281
|
|
|
282
282
|
return {
|
|
283
283
|
read() {
|
|
284
|
-
const storage = storageOf()
|
|
285
|
-
if (!storage) return fallback()
|
|
286
284
|
try {
|
|
285
|
+
const storage = storageOf()
|
|
286
|
+
if (!storage) return fallback()
|
|
287
287
|
const found = readVersionedRecord(storage, recordSchema, options.now)
|
|
288
288
|
if (found.status === 'record') {
|
|
289
289
|
previous = found.record
|
|
@@ -300,9 +300,9 @@ export function createVersionedPersistence<Doc>(
|
|
|
300
300
|
return fallback()
|
|
301
301
|
},
|
|
302
302
|
write(next) {
|
|
303
|
-
const storage = storageOf()
|
|
304
|
-
if (!storage) return
|
|
305
303
|
try {
|
|
304
|
+
const storage = storageOf()
|
|
305
|
+
if (!storage) return
|
|
306
306
|
const document = codec.encode(next, previous)
|
|
307
307
|
if (writeVersionedRecord(storage, schema.key, document)) {
|
|
308
308
|
previous =
|
|
@@ -34,13 +34,6 @@ export type NormalizedAppearanceEditorFontSettings = Readonly<{
|
|
|
34
34
|
recoveredAxes: readonly AppearanceEditorFontAxis[]
|
|
35
35
|
}>
|
|
36
36
|
|
|
37
|
-
const fontFamilyIds: ReadonlySet<string> = new Set(fontOptions.map((option) => option.id))
|
|
38
|
-
const fontOptionsById = Object.freeze(
|
|
39
|
-
Object.fromEntries(fontOptions.map((option) => [option.id, option])) as Record<
|
|
40
|
-
AppearanceEditorFontFamilyId,
|
|
41
|
-
FontOption
|
|
42
|
-
>
|
|
43
|
-
)
|
|
44
37
|
const fontProjectionById = Object.freeze(
|
|
45
38
|
Object.fromEntries(
|
|
46
39
|
fontOptions.map((option) => [
|
|
@@ -89,7 +82,7 @@ function hasOwn(value: Record<string, unknown>, key: string): boolean {
|
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
function normalizeFamily(value: unknown): AppearanceEditorFontFamilyId | undefined {
|
|
92
|
-
return typeof value === 'string' &&
|
|
85
|
+
return typeof value === 'string' && hasOwn(fontProjectionById, value)
|
|
93
86
|
? (value as AppearanceEditorFontFamilyId)
|
|
94
87
|
: undefined
|
|
95
88
|
}
|
|
@@ -192,7 +185,7 @@ export function applyAppearanceFontSettings(
|
|
|
192
185
|
for (const axis of APPEARANCE_EDITOR_FONT_AXES) {
|
|
193
186
|
const projection = fontAxisProjection[axis]
|
|
194
187
|
const setting = settings[axis]
|
|
195
|
-
const option =
|
|
188
|
+
const option = fontProjectionById[setting.family]
|
|
196
189
|
if (setting.family === 'system') root.removeAttribute(projection.familyAttribute)
|
|
197
190
|
else root.setAttribute(projection.familyAttribute, setting.family)
|
|
198
191
|
root.style.setProperty(projection.familyProperty, `var(${option.familyVariables[axis]})`)
|