@tearleads/windowing 0.2.23 → 0.2.25

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.
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { createRequiredContext } from "../createRequiredContext.js";
4
+ import { loadStoredPreference, saveStoredPreference, } from "../launcher/storedPreference.js";
5
+ import { findWallpaper } from "./wallpapers.js";
6
+ const wallpaperContext = createRequiredContext("useWallpaper must be used within a WallpaperProvider");
7
+ /**
8
+ * Owns the desktop wallpaper: the host's `wallpapers` and the user's choice
9
+ * among them, which {@link DesktopWallpaper} paints and Display Properties
10
+ * changes. Mount one above every desktop that shares the choice.
11
+ *
12
+ * Only an explicit choice persists. A stored id the host no longer offers
13
+ * counts as no choice, so the default shows.
14
+ */
15
+ export function WallpaperProvider({ children, defaultWallpaper, storageKey, wallpapers, }) {
16
+ const [choice, setChoice] = useState(() => loadStoredPreference(storageKey, (stored) => stored));
17
+ const activeWallpaper = findWallpaper(wallpapers, choice) ??
18
+ findWallpaper(wallpapers, defaultWallpaper) ??
19
+ wallpapers[0];
20
+ if (!activeWallpaper) {
21
+ throw new Error("WallpaperProvider needs at least one wallpaper");
22
+ }
23
+ const setWallpaper = useCallback((id) => {
24
+ if (!findWallpaper(wallpapers, id)) {
25
+ return;
26
+ }
27
+ setChoice(id);
28
+ saveStoredPreference(storageKey, id);
29
+ }, [storageKey, wallpapers]);
30
+ const value = useMemo(() => ({ activeWallpaper, setWallpaper, wallpapers }), [activeWallpaper, setWallpaper, wallpapers]);
31
+ return (_jsx(wallpaperContext.context.Provider, { value: value, children: children }));
32
+ }
33
+ export const useWallpaper = wallpaperContext.useRequired;
34
+ // Non-throwing accessor: a desktop rendered without a provider shows no
35
+ // wallpaper, and Display Properties leaves out its Background section.
36
+ export const useOptionalWallpaper = wallpaperContext.useOptional;
37
+ //# sourceMappingURL=WallpaperProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WallpaperProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/wallpaper/WallpaperProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA0B,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAA4B,MAAM,cAAc,CAAC;AAWvE,MAAM,gBAAgB,GAAG,qBAAqB,CAC5C,sDAAsD,CACvD,CAAC;AAcF;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAoB,EACnD,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,UAAU,GACiB;IAC3B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CACxC,oBAAoB,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CACrD,CAAC;IACF,MAAM,eAAe,GACnB,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC;QACjC,aAAa,CAAC,UAAU,EAAE,gBAAgB,CAAC;QAC3C,UAAU,CAAC,CAAC,CAAC,CAAC;IAChB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,EAAU,EAAE,EAAE;QACb,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QACD,SAAS,CAAC,EAAE,CAAC,CAAC;QACd,oBAAoB,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,UAAU,EAAE,UAAU,CAAC,CACzB,CAAC;IAEF,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,EACrD,CAAC,eAAe,EAAE,YAAY,EAAE,UAAU,CAAC,CAC5C,CAAC;IAEF,OAAO,CACL,KAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC5C,QAAQ,GACyB,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC,WAAW,CAAC;AAEzD,wEAAwE;AACxE,uEAAuE;AACvE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,WAAW,CAAC","sourcesContent":["import { type PropsWithChildren, useCallback, useMemo, useState } from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n loadStoredPreference,\n saveStoredPreference,\n} from \"../launcher/storedPreference\";\nimport { findWallpaper, type WallpaperDefinition } from \"./wallpapers\";\n\ninterface WallpaperContextValue {\n /** The wallpaper showing: the user's choice, or the host's default. */\n activeWallpaper: WallpaperDefinition;\n /** Records a wallpaper the host offers as the user's choice. */\n setWallpaper: (id: string) => void;\n /** Every wallpaper the host offers, in order. */\n wallpapers: readonly WallpaperDefinition[];\n}\n\nconst wallpaperContext = createRequiredContext<WallpaperContextValue>(\n \"useWallpaper must be used within a WallpaperProvider\",\n);\n\ninterface WallpaperProviderProps<Id extends string> extends PropsWithChildren {\n /** The wallpaper until the user picks one. Defaults to the first. */\n defaultWallpaper?: NoInfer<Id> | undefined;\n /** Where the user's choice persists in localStorage. */\n storageKey: string;\n /**\n * The wallpapers the host offers, in the order Display Properties lists\n * them. Define the list once, outside render.\n */\n wallpapers: readonly WallpaperDefinition<Id>[];\n}\n\n/**\n * Owns the desktop wallpaper: the host's `wallpapers` and the user's choice\n * among them, which {@link DesktopWallpaper} paints and Display Properties\n * changes. Mount one above every desktop that shares the choice.\n *\n * Only an explicit choice persists. A stored id the host no longer offers\n * counts as no choice, so the default shows.\n */\nexport function WallpaperProvider<Id extends string>({\n children,\n defaultWallpaper,\n storageKey,\n wallpapers,\n}: WallpaperProviderProps<Id>) {\n const [choice, setChoice] = useState(() =>\n loadStoredPreference(storageKey, (stored) => stored),\n );\n const activeWallpaper =\n findWallpaper(wallpapers, choice) ??\n findWallpaper(wallpapers, defaultWallpaper) ??\n wallpapers[0];\n if (!activeWallpaper) {\n throw new Error(\"WallpaperProvider needs at least one wallpaper\");\n }\n\n const setWallpaper = useCallback(\n (id: string) => {\n if (!findWallpaper(wallpapers, id)) {\n return;\n }\n setChoice(id);\n saveStoredPreference(storageKey, id);\n },\n [storageKey, wallpapers],\n );\n\n const value = useMemo<WallpaperContextValue>(\n () => ({ activeWallpaper, setWallpaper, wallpapers }),\n [activeWallpaper, setWallpaper, wallpapers],\n );\n\n return (\n <wallpaperContext.context.Provider value={value}>\n {children}\n </wallpaperContext.context.Provider>\n );\n}\n\nexport const useWallpaper = wallpaperContext.useRequired;\n\n// Non-throwing accessor: a desktop rendered without a provider shows no\n// wallpaper, and Display Properties leaves out its Background section.\nexport const useOptionalWallpaper = wallpaperContext.useOptional;\n"]}
@@ -0,0 +1,13 @@
1
+ import type { WallpaperDefinition } from "./wallpapers.js";
2
+ /** Cubes seen corner-on, each in three shades: the tumbling-blocks quilt. */
3
+ export declare const BLOCKS_WALLPAPER: WallpaperDefinition<"blocks">;
4
+ /** Outlined hexagons, as a honeycomb. */
5
+ export declare const HONEYCOMB_WALLPAPER: WallpaperDefinition<"honeycomb">;
6
+ /** Equilateral triangles, alternately dark and light. */
7
+ export declare const TRIANGLES_WALLPAPER: WallpaperDefinition<"triangles">;
8
+ /** Diamonds on a lighter ground, as a harlequin's coat. */
9
+ export declare const HARLEQUIN_WALLPAPER: WallpaperDefinition<"harlequin">;
10
+ /** Zigzag bands. */
11
+ export declare const CHEVRON_WALLPAPER: WallpaperDefinition<"chevron">;
12
+ /** No pattern: the theme's desk color alone. */
13
+ export declare const PLAIN_WALLPAPER: WallpaperDefinition<"plain">;
@@ -0,0 +1,151 @@
1
+ // Ready-made wallpapers: quiet tessellations of the plane, each one tile of
2
+ // SVG repeated edge to edge. A host lists the ones it offers, alongside its
3
+ // own, in its WallpaperProvider. Shapes that cross a tile's edge are drawn in
4
+ // full from every neighboring cell, so the clipped halves meet seamlessly.
5
+ const SQRT3 = Math.sqrt(3);
6
+ function round(value) {
7
+ return String(Math.round(value * 100) / 100);
8
+ }
9
+ function tile(width, height, body) {
10
+ const w = round(width);
11
+ const h = round(height);
12
+ return {
13
+ height: Number(h),
14
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}">${body}</svg>`,
15
+ width: Number(w),
16
+ };
17
+ }
18
+ function polygon(points, opacity = 1) {
19
+ const list = points.map(([x, y]) => `${round(x)},${round(y)}`).join(" ");
20
+ const fill = opacity === 1 ? "" : ` fill-opacity="${opacity}"`;
21
+ return `<polygon points="${list}"${fill}/>`;
22
+ }
23
+ // The whole tile at one shade, beneath the shapes drawn over it.
24
+ function ground(width, height, opacity) {
25
+ return `<rect width="${round(width)}" height="${round(height)}" fill-opacity="${opacity}"/>`;
26
+ }
27
+ // A pointy-topped hexagon's corners, clockwise from the top.
28
+ function hexagon([cx, cy], radius) {
29
+ const half = (radius * SQRT3) / 2;
30
+ return [
31
+ [cx, cy - radius],
32
+ [cx + half, cy - radius / 2],
33
+ [cx + half, cy + radius / 2],
34
+ [cx, cy + radius],
35
+ [cx - half, cy + radius / 2],
36
+ [cx - half, cy - radius / 2],
37
+ ];
38
+ }
39
+ // Hexagon centers covering one w-by-3r cell of a pointy-topped hex grid,
40
+ // including every neighbor whose outline reaches into the cell.
41
+ function hexCenters(width, radius) {
42
+ const rows = [
43
+ [0, [0, width]],
44
+ [1.5 * radius, [-width / 2, width / 2, 1.5 * width]],
45
+ [3 * radius, [0, width]],
46
+ ];
47
+ return rows.flatMap(([y, xs]) => xs.map((x) => [x, y]));
48
+ }
49
+ /** Cubes seen corner-on, each in three shades: the tumbling-blocks quilt. */
50
+ export const BLOCKS_WALLPAPER = (() => {
51
+ const radius = 18;
52
+ const width = radius * SQRT3;
53
+ const centers = [
54
+ [width / 2, radius],
55
+ [0, 2.5 * radius],
56
+ [width, 2.5 * radius],
57
+ [0, -0.5 * radius],
58
+ [width, -0.5 * radius],
59
+ ];
60
+ // The ground is the darkest face's shade, so faces never meet over a gap
61
+ // of bare base where their antialiased edges would show as seams.
62
+ const faces = centers
63
+ .map((center) => {
64
+ const [top, upperRight, , bottom, lowerLeft, upperLeft] = hexagon(center, radius);
65
+ return [
66
+ polygon([top, upperRight, center, upperLeft], 1),
67
+ polygon([upperLeft, center, bottom, lowerLeft], 0.55),
68
+ ].join("");
69
+ })
70
+ .join("");
71
+ const height = 3 * radius;
72
+ return {
73
+ id: "blocks",
74
+ label: "Blocks",
75
+ tile: tile(width, height, `${ground(width, height, 0.2)}${faces}`),
76
+ };
77
+ })();
78
+ /** Outlined hexagons, as a honeycomb. */
79
+ export const HONEYCOMB_WALLPAPER = (() => {
80
+ const radius = 16;
81
+ const width = radius * SQRT3;
82
+ const body = hexCenters(width, radius)
83
+ .map((center) => polygon(hexagon(center, radius)))
84
+ .join("");
85
+ return {
86
+ id: "honeycomb",
87
+ label: "Honeycomb",
88
+ tile: tile(width, 3 * radius, `<g fill="none" stroke="#000" stroke-width="1.5">${body}</g>`),
89
+ };
90
+ })();
91
+ /** Equilateral triangles, alternately dark and light. */
92
+ export const TRIANGLES_WALLPAPER = (() => {
93
+ const side = 36;
94
+ const height = (side * SQRT3) / 2;
95
+ const half = side / 2;
96
+ // Inverted triangles are the lighter ground between the upright ones.
97
+ const upright = [
98
+ // The first row's upright triangle.
99
+ polygon([
100
+ [0, height],
101
+ [side, height],
102
+ [half, 0],
103
+ ]),
104
+ // The second row's, offset by half a side.
105
+ polygon([
106
+ [0, height],
107
+ [-half, 2 * height],
108
+ [half, 2 * height],
109
+ ]),
110
+ polygon([
111
+ [side, height],
112
+ [half, 2 * height],
113
+ [side + half, 2 * height],
114
+ ]),
115
+ ].join("");
116
+ return {
117
+ id: "triangles",
118
+ label: "Triangles",
119
+ tile: tile(side, 2 * height, `${ground(side, 2 * height, 0.4)}${upright}`),
120
+ };
121
+ })();
122
+ /** Diamonds on a lighter ground, as a harlequin's coat. */
123
+ export const HARLEQUIN_WALLPAPER = {
124
+ id: "harlequin",
125
+ label: "Harlequin",
126
+ tile: tile(32, 48, `${ground(32, 48, 0.35)}${polygon([
127
+ [16, 0],
128
+ [32, 24],
129
+ [16, 48],
130
+ [0, 24],
131
+ ])}`),
132
+ };
133
+ /** Zigzag bands. */
134
+ export const CHEVRON_WALLPAPER = {
135
+ id: "chevron",
136
+ label: "Chevron",
137
+ tile: tile(40, 20, polygon([
138
+ [0, 0],
139
+ [20, 10],
140
+ [40, 0],
141
+ [40, 10],
142
+ [20, 20],
143
+ [0, 10],
144
+ ])),
145
+ };
146
+ /** No pattern: the theme's desk color alone. */
147
+ export const PLAIN_WALLPAPER = {
148
+ id: "plain",
149
+ label: "None",
150
+ };
151
+ //# sourceMappingURL=tessellations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tessellations.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/wallpaper/tessellations.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAM3E,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE3B,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,IAAI,CAAC,KAAa,EAAE,MAAc,EAAE,IAAY;IACvD,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;I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,CAAC,MAAM,mBAAmB,GAAqC;IACnE,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,IAAI,CACR,EAAE,EACF,EAAE,EACF,GAAG,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC;QAChC,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,CAAC,EAAE,EAAE,CAAC;KACR,CAAC,EAAE,CACL;CACF,CAAC;AAEF,oBAAoB;AACpB,MAAM,CAAC,MAAM,iBAAiB,GAAmC;IAC/D,EAAE,EAAE,SAAS;IACb,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,IAAI,CACR,EAAE,EACF,EAAE,EACF,OAAO,CAAC;QACN,CAAC,CAAC,EAAE,CAAC,CAAC;QACN,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,EAAE,EAAE,EAAE,CAAC;QACR,CAAC,CAAC,EAAE,EAAE,CAAC;KACR,CAAC,CACH;CACF,CAAC;AAEF,gDAAgD;AAChD,MAAM,CAAC,MAAM,eAAe,GAAiC;IAC3D,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,MAAM;CACd,CAAC","sourcesContent":["// Ready-made wallpapers: quiet tessellations of the plane, each one tile of\n// SVG repeated edge to edge. A host lists the ones it offers, alongside its\n// own, in its WallpaperProvider. Shapes that cross a tile's edge are drawn in\n// full from every neighboring cell, so the clipped halves meet seamlessly.\n\nimport type { WallpaperDefinition, WallpaperTile } from \"./wallpapers\";\n\ntype Point = readonly [x: number, y: number];\n\nconst SQRT3 = Math.sqrt(3);\n\nfunction round(value: number): string {\n return String(Math.round(value * 100) / 100);\n}\n\nfunction tile(width: number, height: number, body: string): WallpaperTile {\n const w = round(width);\n const h = round(height);\n return {\n height: Number(h),\n svg: `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${w}\" height=\"${h}\" viewBox=\"0 0 ${w} ${h}\">${body}</svg>`,\n width: Number(w),\n };\n}\n\nfunction polygon(points: ReadonlyArray<Point>, opacity = 1): string {\n const list = points.map(([x, y]) => `${round(x)},${round(y)}`).join(\" \");\n const fill = opacity === 1 ? \"\" : ` fill-opacity=\"${opacity}\"`;\n return `<polygon points=\"${list}\"${fill}/>`;\n}\n\n// The whole tile at one shade, beneath the shapes drawn over it.\nfunction ground(width: number, height: number, opacity: number): string {\n return `<rect width=\"${round(width)}\" height=\"${round(height)}\" fill-opacity=\"${opacity}\"/>`;\n}\n\ntype Hexagon = readonly [Point, Point, Point, Point, Point, Point];\n\n// A pointy-topped hexagon's corners, clockwise from the top.\nfunction hexagon([cx, cy]: Point, radius: number): Hexagon {\n const half = (radius * SQRT3) / 2;\n return [\n [cx, cy - radius],\n [cx + half, cy - radius / 2],\n [cx + half, cy + radius / 2],\n [cx, cy + radius],\n [cx - half, cy + radius / 2],\n [cx - half, cy - radius / 2],\n ];\n}\n\n// Hexagon centers covering one w-by-3r cell of a pointy-topped hex grid,\n// including every neighbor whose outline reaches into the cell.\nfunction hexCenters(width: number, radius: number): Point[] {\n const rows: ReadonlyArray<readonly [y: number, xs: number[]]> = [\n [0, [0, width]],\n [1.5 * radius, [-width / 2, width / 2, 1.5 * width]],\n [3 * radius, [0, width]],\n ];\n return rows.flatMap(([y, xs]) => xs.map((x): Point => [x, y]));\n}\n\n/** Cubes seen corner-on, each in three shades: the tumbling-blocks quilt. */\nexport const BLOCKS_WALLPAPER: WallpaperDefinition<\"blocks\"> = (() => {\n const radius = 18;\n const width = radius * SQRT3;\n const centers: Point[] = [\n [width / 2, radius],\n [0, 2.5 * radius],\n [width, 2.5 * radius],\n [0, -0.5 * radius],\n [width, -0.5 * radius],\n ];\n // The ground is the darkest face's shade, so faces never meet over a gap\n // of bare base where their antialiased edges would show as seams.\n const faces = centers\n .map((center) => {\n const [top, upperRight, , bottom, lowerLeft, upperLeft] = hexagon(\n center,\n radius,\n );\n return [\n polygon([top, upperRight, center, upperLeft], 1),\n polygon([upperLeft, center, bottom, lowerLeft], 0.55),\n ].join(\"\");\n })\n .join(\"\");\n const height = 3 * radius;\n return {\n id: \"blocks\",\n label: \"Blocks\",\n tile: tile(width, height, `${ground(width, height, 0.2)}${faces}`),\n };\n})();\n\n/** Outlined hexagons, as a honeycomb. */\nexport const HONEYCOMB_WALLPAPER: WallpaperDefinition<\"honeycomb\"> = (() => {\n const radius = 16;\n const width = radius * SQRT3;\n const body = hexCenters(width, radius)\n .map((center) => polygon(hexagon(center, radius)))\n .join(\"\");\n return {\n id: \"honeycomb\",\n label: \"Honeycomb\",\n tile: tile(\n width,\n 3 * radius,\n `<g fill=\"none\" stroke=\"#000\" stroke-width=\"1.5\">${body}</g>`,\n ),\n };\n})();\n\n/** Equilateral triangles, alternately dark and light. */\nexport const TRIANGLES_WALLPAPER: WallpaperDefinition<\"triangles\"> = (() => {\n const side = 36;\n const height = (side * SQRT3) / 2;\n const half = side / 2;\n // Inverted triangles are the lighter ground between the upright ones.\n const upright = [\n // The first row's upright triangle.\n polygon([\n [0, height],\n [side, height],\n [half, 0],\n ]),\n // The second row's, offset by half a side.\n polygon([\n [0, height],\n [-half, 2 * height],\n [half, 2 * height],\n ]),\n polygon([\n [side, height],\n [half, 2 * height],\n [side + half, 2 * height],\n ]),\n ].join(\"\");\n return {\n id: \"triangles\",\n label: \"Triangles\",\n tile: tile(side, 2 * height, `${ground(side, 2 * height, 0.4)}${upright}`),\n };\n})();\n\n/** Diamonds on a lighter ground, as a harlequin's coat. */\nexport const HARLEQUIN_WALLPAPER: WallpaperDefinition<\"harlequin\"> = {\n id: \"harlequin\",\n label: \"Harlequin\",\n tile: tile(\n 32,\n 48,\n `${ground(32, 48, 0.35)}${polygon([\n [16, 0],\n [32, 24],\n [16, 48],\n [0, 24],\n ])}`,\n ),\n};\n\n/** Zigzag bands. */\nexport const CHEVRON_WALLPAPER: WallpaperDefinition<\"chevron\"> = {\n id: \"chevron\",\n label: \"Chevron\",\n tile: tile(\n 40,\n 20,\n polygon([\n [0, 0],\n [20, 10],\n [40, 0],\n [40, 10],\n [20, 20],\n [0, 10],\n ]),\n ),\n};\n\n/** No pattern: the theme's desk color alone. */\nexport const PLAIN_WALLPAPER: WallpaperDefinition<\"plain\"> = {\n id: \"plain\",\n label: \"None\",\n};\n"]}
@@ -0,0 +1,52 @@
1
+ import type { CSSProperties } from "react";
2
+ /**
3
+ * One tile of a repeating wallpaper pattern. The tile's SVG is a mask, not a
4
+ * picture: where its shapes are opaque the wallpaper paints its ink, where
5
+ * they are translucent (`fill-opacity`, `stroke-opacity`) it paints that share
6
+ * of the ink, and elsewhere the base shows. The markup's own colors are
7
+ * ignored, so one tile follows every theme.
8
+ */
9
+ export interface WallpaperTile {
10
+ /** The tile's height in CSS pixels; the pattern repeats at this size. */
11
+ readonly height: number;
12
+ /**
13
+ * The tile as a standalone SVG document (with its `xmlns`), drawn edge to
14
+ * edge across `width` by `height` so neighboring tiles meet seamlessly.
15
+ */
16
+ readonly svg: string;
17
+ /** The tile's width in CSS pixels. */
18
+ readonly width: number;
19
+ }
20
+ /**
21
+ * A desktop wallpaper a host offers: a base color and, optionally, a pattern
22
+ * repeated over it in an ink color. Unless it names its own, the colors come
23
+ * from the theme: the `--desktop-wallpaper-base` and `--desktop-wallpaper-ink`
24
+ * tokens where a host sets them, else the desk color (`--desktop-background`,
25
+ * then `--color-light`) under a faint wash of `--color-dark`.
26
+ */
27
+ export interface WallpaperDefinition<Id extends string = string> {
28
+ /** A CSS color under the pattern. */
29
+ readonly base?: string | undefined;
30
+ readonly id: Id;
31
+ /** A CSS color the pattern paints in. */
32
+ readonly ink?: string | undefined;
33
+ /** The wallpaper's name, as Display Properties lists it. */
34
+ readonly label: string;
35
+ /** The repeating pattern. Without one the wallpaper is its base alone. */
36
+ readonly tile?: WallpaperTile | undefined;
37
+ }
38
+ type WallpaperStyle = CSSProperties & {
39
+ "--wallpaper-base": string;
40
+ "--wallpaper-ink": string;
41
+ "--wallpaper-mask"?: string;
42
+ "--wallpaper-size"?: string;
43
+ };
44
+ /** The tile's SVG as a `url()` value. */
45
+ export declare function wallpaperTileUrl(tile: WallpaperTile): string;
46
+ /**
47
+ * The custom properties a `.wallpaper-pattern` element paints a wallpaper
48
+ * from: its colors, and its tile as a mask repeated at the tile's size.
49
+ */
50
+ export declare function wallpaperStyle(wallpaper: WallpaperDefinition): WallpaperStyle;
51
+ export declare function findWallpaper<Id extends string>(wallpapers: readonly WallpaperDefinition<Id>[], id: string | null | undefined): WallpaperDefinition<Id> | undefined;
52
+ export {};
@@ -0,0 +1,28 @@
1
+ // The theme's colors, resolved on the wallpaper's own element, so a theme
2
+ // scoped below the document root reaches the desktop and the previews alike.
3
+ const THEME_BASE = "var(--desktop-wallpaper-base, var(--desktop-background, var(--color-light)))";
4
+ const THEME_INK = "var(--desktop-wallpaper-ink, color-mix(in srgb, var(--color-dark) 12%, transparent))";
5
+ /** The tile's SVG as a `url()` value. */
6
+ export function wallpaperTileUrl(tile) {
7
+ return `url("data:image/svg+xml,${encodeURIComponent(tile.svg)}")`;
8
+ }
9
+ /**
10
+ * The custom properties a `.wallpaper-pattern` element paints a wallpaper
11
+ * from: its colors, and its tile as a mask repeated at the tile's size.
12
+ */
13
+ export function wallpaperStyle(wallpaper) {
14
+ const style = {
15
+ "--wallpaper-base": wallpaper.base ?? THEME_BASE,
16
+ "--wallpaper-ink": wallpaper.ink ?? THEME_INK,
17
+ };
18
+ if (wallpaper.tile) {
19
+ style["--wallpaper-mask"] = wallpaperTileUrl(wallpaper.tile);
20
+ style["--wallpaper-size"] =
21
+ `${wallpaper.tile.width}px ${wallpaper.tile.height}px`;
22
+ }
23
+ return style;
24
+ }
25
+ export function findWallpaper(wallpapers, id) {
26
+ return wallpapers.find((wallpaper) => wallpaper.id === id);
27
+ }
28
+ //# sourceMappingURL=wallpapers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallpapers.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/wallpaper/wallpapers.ts"],"names":[],"mappings":"AAwCA,0EAA0E;AAC1E,6EAA6E;AAC7E,MAAM,UAAU,GACd,8EAA8E,CAAC;AACjF,MAAM,SAAS,GACb,sFAAsF,CAAC;AASzF,yCAAyC;AACzC,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,OAAO,2BAA2B,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,SAA8B;IAC3D,MAAM,KAAK,GAAmB;QAC5B,kBAAkB,EAAE,SAAS,CAAC,IAAI,IAAI,UAAU;QAChD,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,SAAS;KAC9C,CAAC;IACF,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,CAAC,kBAAkB,CAAC,GAAG,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC7D,KAAK,CAAC,kBAAkB,CAAC;YACvB,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,UAA8C,EAC9C,EAA6B;IAE7B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["import type { CSSProperties } from \"react\";\n\n/**\n * One tile of a repeating wallpaper pattern. The tile's SVG is a mask, not a\n * picture: where its shapes are opaque the wallpaper paints its ink, where\n * they are translucent (`fill-opacity`, `stroke-opacity`) it paints that share\n * of the ink, and elsewhere the base shows. The markup's own colors are\n * ignored, so one tile follows every theme.\n */\nexport interface WallpaperTile {\n /** The tile's height in CSS pixels; the pattern repeats at this size. */\n readonly height: number;\n /**\n * The tile as a standalone SVG document (with its `xmlns`), drawn edge to\n * edge across `width` by `height` so neighboring tiles meet seamlessly.\n */\n readonly svg: string;\n /** The tile's width in CSS pixels. */\n readonly width: number;\n}\n\n/**\n * A desktop wallpaper a host offers: a base color and, optionally, a pattern\n * repeated over it in an ink color. Unless it names its own, the colors come\n * from the theme: the `--desktop-wallpaper-base` and `--desktop-wallpaper-ink`\n * tokens where a host sets them, else the desk color (`--desktop-background`,\n * then `--color-light`) under a faint wash of `--color-dark`.\n */\nexport interface WallpaperDefinition<Id extends string = string> {\n /** A CSS color under the pattern. */\n readonly base?: string | undefined;\n readonly id: Id;\n /** A CSS color the pattern paints in. */\n readonly ink?: string | undefined;\n /** The wallpaper's name, as Display Properties lists it. */\n readonly label: string;\n /** The repeating pattern. Without one the wallpaper is its base alone. */\n readonly tile?: WallpaperTile | undefined;\n}\n\n// The theme's colors, resolved on the wallpaper's own element, so a theme\n// scoped below the document root reaches the desktop and the previews alike.\nconst THEME_BASE =\n \"var(--desktop-wallpaper-base, var(--desktop-background, var(--color-light)))\";\nconst THEME_INK =\n \"var(--desktop-wallpaper-ink, color-mix(in srgb, var(--color-dark) 12%, transparent))\";\n\ntype WallpaperStyle = CSSProperties & {\n \"--wallpaper-base\": string;\n \"--wallpaper-ink\": string;\n \"--wallpaper-mask\"?: string;\n \"--wallpaper-size\"?: string;\n};\n\n/** The tile's SVG as a `url()` value. */\nexport function wallpaperTileUrl(tile: WallpaperTile): string {\n return `url(\"data:image/svg+xml,${encodeURIComponent(tile.svg)}\")`;\n}\n\n/**\n * The custom properties a `.wallpaper-pattern` element paints a wallpaper\n * from: its colors, and its tile as a mask repeated at the tile's size.\n */\nexport function wallpaperStyle(wallpaper: WallpaperDefinition): WallpaperStyle {\n const style: WallpaperStyle = {\n \"--wallpaper-base\": wallpaper.base ?? THEME_BASE,\n \"--wallpaper-ink\": wallpaper.ink ?? THEME_INK,\n };\n if (wallpaper.tile) {\n style[\"--wallpaper-mask\"] = wallpaperTileUrl(wallpaper.tile);\n style[\"--wallpaper-size\"] =\n `${wallpaper.tile.width}px ${wallpaper.tile.height}px`;\n }\n return style;\n}\n\nexport function findWallpaper<Id extends string>(\n wallpapers: readonly WallpaperDefinition<Id>[],\n id: string | null | undefined,\n): WallpaperDefinition<Id> | undefined {\n return wallpapers.find((wallpaper) => wallpaper.id === id);\n}\n"]}
package/window/Window.js CHANGED
@@ -183,9 +183,9 @@ function WindowInnerContent({ ContentBoundary, entry, historyBack, isTop, }) {
183
183
  const viewMenuItems = useWindowViewMenuItems();
184
184
  const { sidebar } = useWindowSidebar();
185
185
  const hasSidebar = hasWindowSidebar(sidebar);
186
- const { handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
186
+ const { applyGeometry, handlePointerDown, handleResizePointerDown, position, size, ...stepped } = useWindowGeometry(entry, maximized, windowRef);
187
187
  const { showStatusMessage, statusText } = useWindowStatusMessage();
188
- const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { overlayHost, windowRef }, showStatusMessage);
188
+ const { contentFit, geometryMenuItems } = useWindowGeometryMenu(entry, stepped, { applyGeometry, overlayHost, windowRef }, showStatusMessage);
189
189
  const actions = useWindowActions(entry, fileMenuItems, viewMenuItems, geometryMenuItems, hasSidebar);
190
190
  // A maximized window fills its surface without a laid-out position.
191
191
  useFocusWindowOnShow(windowRef, {
@@ -1 +1 @@
1
- {"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CA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EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,iBAAiB,EAChC,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,iBAAiB,GACpC,EACF,KAAC,qBAAqB,IACpB,KAAK,EAAE,OAAO,CAAC,WAAW,EAC1B,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,KACxB,UAAU,EACd,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe,YAEhC,KAAC,qBAAqB,IACpB,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,OAAO,CAAC,WAAW,YAE/B,eAAe,CAAC,CAAC,CAAC,CACjB,KAAC,eAAe,IAAC,KAAK,EAAE,KAAK,YAC1B,SAAS,IAAI,KAAC,SAAS,KAAG,GACX,CACnB,CAAC,CAAC,CAAC,CACF,SAAS,IAAI,KAAC,SAAS,KAAG,CAC3B,GACqB,GACF,EACxB,KAAC,eAAe,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,GAAI,EACpE,CAAC,SAAS,IAAI,CACb,KAAC,mBAAmB,IAClB,uBAAuB,EAAE,uBAAuB,GAChD,CACH,IACO,CACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,WAAW,EACX,cAAc,EACd,QAAQ,GAIR;IACA,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7C,OAAO,CACL,KAAC,UAAU,IACT,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,WAAW,IAAI,UAAU,EACtC,OAAO,EAAE,OAAO,YAEf,QAAQ,GACE,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type PropsWithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometryMenu } from \"./useWindowFit\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport { useFocusWindowOnShow } from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowFrameStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n background: string | undefined,\n): WindowStyle {\n return {\n ...getWindowFrameStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const { contentFit, geometryMenuItems } = useWindowGeometryMenu(\n entry,\n stepped,\n { overlayHost, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex, background);\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n {...contentFit}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
1
+ {"version":3,"file":"Window.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/Window.tsx"],"names":[],"mappings":";AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EA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ithChildren,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport \"./Window.css\";\nimport { CurrentWindowProvider } from \"./CurrentWindowContext\";\nimport { useWindowGeometryMenu } from \"./useWindowFit\";\nimport { useWindowGeometry } from \"./useWindowGeometry\";\nimport { useFocusWindowOnShow } from \"./useWindowKeyboardGeometry\";\nimport { WindowBody } from \"./WindowBody\";\nimport { WindowMenuBar, type WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowFileMenuItems,\n useWindowViewMenuItems,\n WindowMenuProvider,\n} from \"./WindowMenuContext\";\nimport { WindowResizeHandles } from \"./WindowResizeHandle\";\nimport {\n hasWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./WindowSidebarContext\";\nimport {\n findTopWindow,\n useWindowActions as useWindowStateActions,\n useWindowStateData,\n type WindowEntry,\n type WindowPosition,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { WindowStatusBar } from \"./WindowStatusBar\";\nimport { WindowTitleBar } from \"./WindowTitleBar\";\nimport { WindowToolBar } from \"./WindowToolBar\";\n\n// Wraps a window's content so the host can give it app-specific context (a\n// route, an error boundary) without the window layer knowing about apps.\nexport type WindowContentBoundary = ComponentType<\n PropsWithChildren<{ entry: WindowEntry }>\n>;\n\ninterface WindowProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n /**\n * Whether the toolbar offers Back through the window's own route history,\n * reserving its row from the start (see `WindowToolBar`). Defaults to whether\n * the window has an `appId`. Pass false for an app that never routes, so its\n * window has no toolbar row until the app first registers toolbar actions.\n */\n historyBack?: boolean | undefined;\n windowId: string;\n}\n\nconst WINDOW_STATUS_MESSAGE_DURATION_MS = 2500;\n\nexport function Window({\n ContentBoundary,\n historyBack,\n windowId,\n}: WindowProps) {\n const { windowMap, windows } = useWindowStateData();\n const entry = windowMap.get(windowId);\n const isTop =\n findTopWindow(windows, (candidate) => !candidate.minimized)?.id ===\n windowId;\n\n if (!entry) return null;\n\n return (\n <WindowInner\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack ?? entry.appId !== undefined}\n isTop={isTop}\n />\n );\n}\n\nfunction useWindowActions(\n entry: WindowEntry,\n fileMenuItems: WindowMenuItem[],\n viewMenuItems: WindowMenuItem[],\n geometryMenuItems: WindowMenuItem[],\n hasSidebar: boolean,\n) {\n const { close, minimize, moveBackward, moveForward, toggleMaximize } =\n useWindowStateActions();\n const [showStatusBar, setShowStatusBar] = useState(true);\n const [showSidebar, setShowSidebar] = useState(\n entry.initialShowSidebar ?? true,\n );\n const handleClose = useCallback(() => close(entry.id), [close, entry.id]);\n const handleMinimize = useCallback(\n () => minimize(entry.id),\n [entry.id, minimize],\n );\n const handleMoveForward = useCallback(\n () => moveForward(entry.id),\n [entry.id, moveForward],\n );\n const handleMoveBackward = useCallback(\n () => moveBackward(entry.id),\n [entry.id, moveBackward],\n );\n const handleMaximize = useCallback(\n () => toggleMaximize(entry.id),\n [entry.id, toggleMaximize],\n );\n const toggleStatusBar = useCallback(\n () => setShowStatusBar((previous) => !previous),\n [],\n );\n const toggleSidebar = useCallback(\n () => setShowSidebar((previous) => !previous),\n [],\n );\n const menus = useMemo(\n () => [\n {\n label: \"File\",\n items: [\n ...fileMenuItems,\n { id: \"close\", label: \"Close\", onClick: handleClose },\n ],\n },\n {\n label: \"View\",\n items: [\n ...viewMenuItems,\n ...geometryMenuItems,\n {\n id: \"toggle-status-bar\",\n label: `${showStatusBar ? \"Hide\" : \"Show\"} Status Bar`,\n onClick: toggleStatusBar,\n },\n ...(hasSidebar\n ? [\n {\n id: \"toggle-sidebar\",\n label: `${showSidebar ? \"Hide\" : \"Show\"} Sidebar`,\n onClick: toggleSidebar,\n },\n ]\n : []),\n ],\n },\n ],\n [\n geometryMenuItems,\n hasSidebar,\n handleClose,\n fileMenuItems,\n showSidebar,\n showStatusBar,\n toggleSidebar,\n toggleStatusBar,\n viewMenuItems,\n ],\n );\n\n return {\n handleClose,\n handleMaximize,\n handleMinimize,\n handleMoveBackward,\n handleMoveForward,\n menus,\n showSidebar,\n showStatusBar,\n };\n}\n\n// The window paints with `--window-background`, which a background its content\n// sets (see `useWindowBackground`) overrides inline.\ninterface WindowStyle extends CSSProperties {\n \"--window-background\"?: string | undefined;\n}\n\nfunction getWindowFrameStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n): CSSProperties {\n if (maximized) {\n return { top: 0, left: 0, width: \"100%\", height: \"100%\", zIndex };\n }\n if (!position) {\n // Hidden until laid out; a requested size applies already so the first\n // clamp measures the window at the size it will show.\n return {\n visibility: \"hidden\",\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n }\n\n return {\n left: position.x,\n top: position.y,\n zIndex,\n ...(size ? { width: size.width, height: size.height } : {}),\n };\n}\n\nfunction getWindowStyle(\n maximized: boolean,\n position: WindowPosition | null,\n size: WindowSize | null,\n zIndex: number,\n background: string | undefined,\n): WindowStyle {\n return {\n ...getWindowFrameStyle(maximized, position, size, zIndex),\n \"--window-background\": background,\n };\n}\n\nfunction useWindowStatusMessage() {\n const [statusText, setStatusText] = useState(\"\");\n const statusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const showStatusMessage = useCallback((message: string) => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n setStatusText(message);\n statusTimeoutRef.current = setTimeout(() => {\n setStatusText(\"\");\n statusTimeoutRef.current = null;\n }, WINDOW_STATUS_MESSAGE_DURATION_MS);\n }, []);\n\n useEffect(() => {\n return () => {\n if (statusTimeoutRef.current) {\n clearTimeout(statusTimeoutRef.current);\n }\n };\n }, []);\n\n return { showStatusMessage, statusText };\n}\n\n// Refcounted so overlapping overlays (one closing as another opens) never leave\n// the row hidden, and never flash it back for a frame between the two.\nfunction useWindowToolbarSuppression() {\n const [suppressionCount, setSuppressionCount] = useState(0);\n const suppressToolbar = useCallback(() => {\n setSuppressionCount((count) => count + 1);\n return () => setSuppressionCount((count) => Math.max(0, count - 1));\n }, []);\n\n return { suppressToolbar, toolbarSuppressed: suppressionCount > 0 };\n}\n\ninterface WindowInnerProps {\n ContentBoundary?: WindowContentBoundary | undefined;\n entry: WindowEntry;\n historyBack: boolean;\n // Whether this is the foremost visible window, the one that takes focus.\n isTop: boolean;\n}\n\nfunction WindowInner({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n return (\n <WindowMenuProvider>\n <WindowSidebarProvider>\n <WindowInnerContent\n ContentBoundary={ContentBoundary}\n entry={entry}\n historyBack={historyBack}\n isTop={isTop}\n />\n </WindowSidebarProvider>\n </WindowMenuProvider>\n );\n}\n\n// The bars above the body: title, menus, and the toolbar row a full-pane overlay\n// can stand down (see `useWindowToolbarSuppression`).\nfunction WindowChrome({\n actions,\n entry,\n historyBack,\n onGoBack,\n onPointerDown,\n titleId,\n toolbarSuppressed,\n}: {\n actions: ReturnType<typeof useWindowActions>;\n entry: WindowEntry;\n historyBack: boolean;\n onGoBack: () => void;\n onPointerDown: (event: ReactPointerEvent) => void;\n titleId: string;\n toolbarSuppressed: boolean;\n}) {\n return (\n <>\n <WindowTitleBar\n title={entry.title}\n titleId={titleId}\n onPointerDown={onPointerDown}\n onMinimize={actions.handleMinimize}\n onMaximize={actions.handleMaximize}\n onClose={actions.handleClose}\n onMoveForward={actions.handleMoveForward}\n onMoveBackward={actions.handleMoveBackward}\n />\n <WindowMenuBar menus={actions.menus} />\n {!toolbarSuppressed && (\n <WindowToolBar\n canGoBack={(entry.routeHistory?.length ?? 0) > 0}\n showHistoryBack={historyBack}\n onGoBack={onGoBack}\n />\n )}\n </>\n );\n}\n\n// Handlers on the window root: its Back caret, raising it on any press inside,\n// and keeping background context menus from opening under window-local ones.\nfunction useWindowRootHandlers(windowId: string) {\n // The toolbar renders above the route boundary, so the window's own Back stack\n // is threaded in from here rather than read from context.\n const { bringToFront, goBackRoute } = useWindowStateActions();\n const handleGoBack = useCallback(() => {\n goBackRoute(windowId);\n }, [windowId, goBackRoute]);\n const handleWindowPointerDown = useCallback(() => {\n bringToFront(windowId);\n }, [bringToFront, windowId]);\n const handleWindowContextMenu = useCallback((event: ReactMouseEvent) => {\n // Keep background pane context menus from opening underneath window-local menus.\n event.stopPropagation();\n }, []);\n const windowContextMenuTrapProps: Pick<\n HTMLAttributes<HTMLElement>,\n \"onContextMenu\"\n > = {\n onContextMenu: handleWindowContextMenu,\n };\n\n return { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps };\n}\n\nfunction WindowInnerContent({\n ContentBoundary,\n entry,\n historyBack,\n isTop,\n}: WindowInnerProps) {\n const { maximized, minimized, zIndex, component: Component } = entry;\n const windowRef = useRef<HTMLElement>(null);\n const titleId = useId();\n const [overlayHost, setOverlayHost] = useState<HTMLElement | null>(null);\n const [background, setBackground] = useState<string | undefined>();\n const fileMenuItems = useWindowFileMenuItems();\n const viewMenuItems = useWindowViewMenuItems();\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n const {\n applyGeometry,\n handlePointerDown,\n handleResizePointerDown,\n position,\n size,\n ...stepped\n } = useWindowGeometry(entry, maximized, windowRef);\n const { showStatusMessage, statusText } = useWindowStatusMessage();\n const { contentFit, geometryMenuItems } = useWindowGeometryMenu(\n entry,\n stepped,\n { applyGeometry, overlayHost, windowRef },\n showStatusMessage,\n );\n const actions = useWindowActions(\n entry,\n fileMenuItems,\n viewMenuItems,\n geometryMenuItems,\n hasSidebar,\n );\n // A maximized window fills its surface without a laid-out position.\n useFocusWindowOnShow(windowRef, {\n isTop,\n shown: !minimized && (maximized || position !== null),\n });\n const { suppressToolbar, toolbarSuppressed } = useWindowToolbarSuppression();\n const { handleGoBack, handleWindowPointerDown, windowContextMenuTrapProps } =\n useWindowRootHandlers(entry.id);\n const style = getWindowStyle(maximized, position, size, zIndex, background);\n\n if (minimized) {\n return null;\n }\n\n // A section labelled by its title is a region landmark. Windows are\n // non-modal and freely arranged, so they are not dialogs; hosts keep that\n // role for the modals they open inside a window.\n return (\n <section\n ref={windowRef}\n aria-labelledby={titleId}\n className={maximized ? \"window window--maximized\" : \"window\"}\n tabIndex={-1}\n {...windowContextMenuTrapProps}\n onPointerDownCapture={handleWindowPointerDown}\n style={style}\n >\n <WindowChrome\n actions={actions}\n entry={entry}\n historyBack={historyBack}\n onGoBack={handleGoBack}\n onPointerDown={handlePointerDown}\n titleId={titleId}\n toolbarSuppressed={toolbarSuppressed}\n />\n <CurrentWindowProvider\n close={actions.handleClose}\n id={entry.id}\n overlayHost={overlayHost}\n setBackground={setBackground}\n {...contentFit}\n showStatusMessage={showStatusMessage}\n suppressToolbar={suppressToolbar}\n >\n <WindowBodyWithSidebar\n overlayHostRef={setOverlayHost}\n showSidebar={actions.showSidebar}\n >\n {ContentBoundary ? (\n <ContentBoundary entry={entry}>\n {Component && <Component />}\n </ContentBoundary>\n ) : (\n Component && <Component />\n )}\n </WindowBodyWithSidebar>\n </CurrentWindowProvider>\n <WindowStatusBar text={statusText} visible={actions.showStatusBar} />\n {!maximized && (\n <WindowResizeHandles\n handleResizePointerDown={handleResizePointerDown}\n />\n )}\n </section>\n );\n}\n\nfunction WindowBodyWithSidebar({\n showSidebar,\n overlayHostRef,\n children,\n}: PropsWithChildren<{\n overlayHostRef: (element: HTMLDivElement | null) => void;\n showSidebar: boolean;\n}>) {\n const { sidebar } = useWindowSidebar();\n const hasSidebar = hasWindowSidebar(sidebar);\n\n return (\n <WindowBody\n contentRef={overlayHostRef}\n showSidebar={showSidebar && hasSidebar}\n sidebar={sidebar}\n >\n {children}\n </WindowBody>\n );\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import { type RefObject } from "react";
2
2
  import { useWindowGeometryMenuItems } from "./useWindowKeyboardGeometry.js";
3
3
  import type { WindowMenuItem } from "./WindowMenuBar.js";
4
- import { type WindowEntry, type WindowSize } from "./WindowStateProvider/index.js";
4
+ import { type WindowEntry, type WindowGeometry, type WindowSize } from "./WindowStateProvider/index.js";
5
5
  interface WindowFitHost {
6
+ applyGeometry: (geometry: WindowGeometry) => void;
6
7
  overlayHost: HTMLElement | null;
7
8
  windowRef: RefObject<HTMLElement | null>;
8
9
  }
@@ -81,8 +81,8 @@ function useFitOnLoad(entry, contentSize, fit, windowRef) {
81
81
  // natural size (see `useWindowContentSize`). It measures the window's chrome
82
82
  // as rendered, so it allows for whichever bars and sidebar show, and restores
83
83
  // a maximized window first.
84
- function useWindowFit(entry, { overlayHost, windowRef }) {
85
- const { setGeometry, toggleMaximize } = useWindowActions();
84
+ function useWindowFit(entry, { applyGeometry, overlayHost, windowRef }) {
85
+ const { toggleMaximize } = useWindowActions();
86
86
  const [contentSize, setContentSize] = useState();
87
87
  const { id, maximized, position } = entry;
88
88
  // Whether the window fitted: one that is not rendered, or whose surface is
@@ -102,15 +102,15 @@ function useWindowFit(entry, { overlayHost, windowRef }) {
102
102
  if (maximized) {
103
103
  toggleMaximize(id);
104
104
  }
105
- setGeometry(id, geometry);
105
+ applyGeometry(geometry);
106
106
  return true;
107
107
  }, [
108
+ applyGeometry,
108
109
  contentSize,
109
110
  id,
110
111
  maximized,
111
112
  overlayHost,
112
113
  position,
113
- setGeometry,
114
114
  toggleMaximize,
115
115
  windowRef,
116
116
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EACL,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAyB,MAAM,kBAAkB,CAAC;AAE5E,MAAM,oBAAoB,GACxB,+EAA+E,CAAC;AAElF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UAAU,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClE,MAAM,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import {\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useWindowGeometryMenuItems } from \"./useWindowKeyboardGeometry\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { fitWindowGeometry, type WindowFitMetrics } from \"./windowGeometry\";\n\nconst SCROLL_PANE_SELECTOR =\n \":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll\";\n\n// The pane's scrollbars, forced on before its own overflow is put back. Layout\n// is read between the writes, so nothing is painted meanwhile.\nfunction measureScrollbars(pane: HTMLElement): WindowSize {\n const { overflow } = pane.style;\n pane.style.overflow = \"scroll\";\n const scrollbar = {\n height: pane.offsetHeight - pane.clientHeight,\n width: pane.offsetWidth - pane.clientWidth,\n };\n pane.style.overflow = overflow;\n return scrollbar;\n}\n\nfunction measureWindowFit(\n windowElement: HTMLElement,\n pane: HTMLElement,\n): WindowFitMetrics {\n const frame = windowElement.getBoundingClientRect();\n const paneRect = pane.getBoundingClientRect();\n const style = getComputedStyle(pane);\n const px = (value: string) => Number.parseFloat(value) || 0;\n\n return {\n chrome: {\n height: frame.height - paneRect.height,\n width: frame.width - paneRect.width,\n },\n padding: {\n height: px(style.paddingTop) + px(style.paddingBottom),\n width: px(style.paddingLeft) + px(style.paddingRight),\n },\n scrollbar: measureScrollbars(pane),\n };\n}\n\ninterface WindowFitHost {\n overlayHost: HTMLElement | null;\n windowRef: RefObject<HTMLElement | null>;\n}\n\n// A window opened with `fitToContent` fits once, the first time its content\n// has both marked itself loaded and reported a size while the window shows. A\n// window maximized by then (as a host opens windows on narrow screens, before\n// they are ever laid out) stays maximized and does not fit later. A hidden\n// surface (an inactive workspace) has no size to fit against, so the fit waits\n// until it has one.\nfunction useFitOnLoad(\n entry: WindowEntry,\n contentSize: WindowSize | undefined,\n fit: () => boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const [loaded, setLoaded] = useState(false);\n const pending = useRef(entry.fitToContent === true);\n const markContentLoaded = useCallback(() => setLoaded(true), []);\n const { maximized, minimized, position } = entry;\n\n useEffect(() => {\n if (!pending.current || !loaded || minimized) {\n return;\n }\n if (maximized) {\n pending.current = false;\n return;\n }\n if (!contentSize) {\n return;\n }\n const attempt = () => {\n if (fit()) {\n pending.current = false;\n }\n return !pending.current;\n };\n if (!position || attempt()) {\n return;\n }\n const surface = windowRef.current?.parentElement;\n if (!surface || typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(() => {\n if (attempt()) {\n observer.disconnect();\n }\n });\n observer.observe(surface);\n return () => observer.disconnect();\n }, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);\n\n return markContentLoaded;\n}\n\n// Fit to Content, offered in the View menu while the window's content has a\n// natural size (see `useWindowContentSize`). It measures the window's chrome\n// as rendered, so it allows for whichever bars and sidebar show, and restores\n// a maximized window first.\nfunction useWindowFit(\n entry: WindowEntry,\n { overlayHost, windowRef }: WindowFitHost,\n) {\n const { setGeometry, toggleMaximize } = useWindowActions();\n const [contentSize, setContentSize] = useState<WindowSize | undefined>();\n const { id, maximized, position } = entry;\n\n // Whether the window fitted: one that is not rendered, or whose surface is\n // hidden, has nothing to measure.\n const fitToContent = useCallback(() => {\n const element = windowRef.current;\n const surface = element?.parentElement;\n const pane = overlayHost?.querySelector<HTMLElement>(SCROLL_PANE_SELECTOR);\n if (\n !contentSize ||\n !element ||\n !surface ||\n !pane ||\n (surface.clientWidth === 0 && surface.clientHeight === 0)\n ) {\n return false;\n }\n const geometry = fitWindowGeometry(\n contentSize,\n measureWindowFit(element, pane),\n { height: surface.clientHeight, width: surface.clientWidth },\n position ?? { x: 0, y: 0 },\n );\n if (maximized) {\n toggleMaximize(id);\n }\n setGeometry(id, geometry);\n return true;\n }, [\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\n setGeometry,\n toggleMaximize,\n windowRef,\n ]);\n\n const fitMenuItems = useMemo<WindowMenuItem[]>(\n () =>\n contentSize\n ? [\n {\n id: \"fit-to-content\",\n label: \"Fit to Content\",\n onClick: fitToContent,\n },\n ]\n : [],\n [contentSize, fitToContent],\n );\n\n const markContentLoaded = useFitOnLoad(\n entry,\n contentSize,\n fitToContent,\n windowRef,\n );\n\n return { fitMenuItems, markContentLoaded, setContentSize };\n}\n\n// The View menu's geometry entries: keyboard move and resize, then Fit to\n// Content while the content has a natural size. `contentFit` is the content's\n// side of fitting, `setContentSize` and `markContentLoaded`, which the window\n// passes to its content.\nexport function useWindowGeometryMenu(\n entry: WindowEntry,\n stepped: Parameters<typeof useWindowGeometryMenuItems>[0],\n host: WindowFitHost,\n announce: (message: string) => void,\n) {\n const keyboardItems = useWindowGeometryMenuItems(\n stepped,\n {\n maximized: entry.maximized,\n minimized: entry.minimized,\n windowRef: host.windowRef,\n },\n announce,\n );\n const { fitMenuItems, ...contentFit } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { contentFit, geometryMenuItems };\n}\n"]}
1
+ {"version":3,"file":"useWindowFit.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/useWindowFit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EACL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AAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,EACD,QAAQ,CACT,CAAC;IACF,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClE,MAAM,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,YAAY,CAAC,EACzC,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import {\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useWindowGeometryMenuItems } from \"./useWindowKeyboardGeometry\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport {\n useWindowActions,\n type WindowEntry,\n type WindowGeometry,\n type WindowSize,\n} from \"./WindowStateProvider\";\nimport { fitWindowGeometry, type WindowFitMetrics } from \"./windowGeometry\";\n\nconst SCROLL_PANE_SELECTOR =\n \":scope > .window-body-content-scroll, :scope > .window-sidebar-content-scroll\";\n\n// The pane's scrollbars, forced on before its own overflow is put back. Layout\n// is read between the writes, so nothing is painted meanwhile.\nfunction measureScrollbars(pane: HTMLElement): WindowSize {\n const { overflow } = pane.style;\n pane.style.overflow = \"scroll\";\n const scrollbar = {\n height: pane.offsetHeight - pane.clientHeight,\n width: pane.offsetWidth - pane.clientWidth,\n };\n pane.style.overflow = overflow;\n return scrollbar;\n}\n\nfunction measureWindowFit(\n windowElement: HTMLElement,\n pane: HTMLElement,\n): WindowFitMetrics {\n const frame = windowElement.getBoundingClientRect();\n const paneRect = pane.getBoundingClientRect();\n const style = getComputedStyle(pane);\n const px = (value: string) => Number.parseFloat(value) || 0;\n\n return {\n chrome: {\n height: frame.height - paneRect.height,\n width: frame.width - paneRect.width,\n },\n padding: {\n height: px(style.paddingTop) + px(style.paddingBottom),\n width: px(style.paddingLeft) + px(style.paddingRight),\n },\n scrollbar: measureScrollbars(pane),\n };\n}\n\ninterface WindowFitHost {\n applyGeometry: (geometry: WindowGeometry) => void;\n overlayHost: HTMLElement | null;\n windowRef: RefObject<HTMLElement | null>;\n}\n\n// A window opened with `fitToContent` fits once, the first time its content\n// has both marked itself loaded and reported a size while the window shows. A\n// window maximized by then (as a host opens windows on narrow screens, before\n// they are ever laid out) stays maximized and does not fit later. A hidden\n// surface (an inactive workspace) has no size to fit against, so the fit waits\n// until it has one.\nfunction useFitOnLoad(\n entry: WindowEntry,\n contentSize: WindowSize | undefined,\n fit: () => boolean,\n windowRef: RefObject<HTMLElement | null>,\n) {\n const [loaded, setLoaded] = useState(false);\n const pending = useRef(entry.fitToContent === true);\n const markContentLoaded = useCallback(() => setLoaded(true), []);\n const { maximized, minimized, position } = entry;\n\n useEffect(() => {\n if (!pending.current || !loaded || minimized) {\n return;\n }\n if (maximized) {\n pending.current = false;\n return;\n }\n if (!contentSize) {\n return;\n }\n const attempt = () => {\n if (fit()) {\n pending.current = false;\n }\n return !pending.current;\n };\n if (!position || attempt()) {\n return;\n }\n const surface = windowRef.current?.parentElement;\n if (!surface || typeof ResizeObserver === \"undefined\") {\n return;\n }\n const observer = new ResizeObserver(() => {\n if (attempt()) {\n observer.disconnect();\n }\n });\n observer.observe(surface);\n return () => observer.disconnect();\n }, [contentSize, fit, loaded, maximized, minimized, position, windowRef]);\n\n return markContentLoaded;\n}\n\n// Fit to Content, offered in the View menu while the window's content has a\n// natural size (see `useWindowContentSize`). It measures the window's chrome\n// as rendered, so it allows for whichever bars and sidebar show, and restores\n// a maximized window first.\nfunction useWindowFit(\n entry: WindowEntry,\n { applyGeometry, overlayHost, windowRef }: WindowFitHost,\n) {\n const { toggleMaximize } = useWindowActions();\n const [contentSize, setContentSize] = useState<WindowSize | undefined>();\n const { id, maximized, position } = entry;\n\n // Whether the window fitted: one that is not rendered, or whose surface is\n // hidden, has nothing to measure.\n const fitToContent = useCallback(() => {\n const element = windowRef.current;\n const surface = element?.parentElement;\n const pane = overlayHost?.querySelector<HTMLElement>(SCROLL_PANE_SELECTOR);\n if (\n !contentSize ||\n !element ||\n !surface ||\n !pane ||\n (surface.clientWidth === 0 && surface.clientHeight === 0)\n ) {\n return false;\n }\n const geometry = fitWindowGeometry(\n contentSize,\n measureWindowFit(element, pane),\n { height: surface.clientHeight, width: surface.clientWidth },\n position ?? { x: 0, y: 0 },\n );\n if (maximized) {\n toggleMaximize(id);\n }\n applyGeometry(geometry);\n return true;\n }, [\n applyGeometry,\n contentSize,\n id,\n maximized,\n overlayHost,\n position,\n toggleMaximize,\n windowRef,\n ]);\n\n const fitMenuItems = useMemo<WindowMenuItem[]>(\n () =>\n contentSize\n ? [\n {\n id: \"fit-to-content\",\n label: \"Fit to Content\",\n onClick: fitToContent,\n },\n ]\n : [],\n [contentSize, fitToContent],\n );\n\n const markContentLoaded = useFitOnLoad(\n entry,\n contentSize,\n fitToContent,\n windowRef,\n );\n\n return { fitMenuItems, markContentLoaded, setContentSize };\n}\n\n// The View menu's geometry entries: keyboard move and resize, then Fit to\n// Content while the content has a natural size. `contentFit` is the content's\n// side of fitting, `setContentSize` and `markContentLoaded`, which the window\n// passes to its content.\nexport function useWindowGeometryMenu(\n entry: WindowEntry,\n stepped: Parameters<typeof useWindowGeometryMenuItems>[0],\n host: WindowFitHost,\n announce: (message: string) => void,\n) {\n const keyboardItems = useWindowGeometryMenuItems(\n stepped,\n {\n maximized: entry.maximized,\n minimized: entry.minimized,\n windowRef: host.windowRef,\n },\n announce,\n );\n const { fitMenuItems, ...contentFit } = useWindowFit(entry, host);\n const geometryMenuItems = useMemo(\n () => [...keyboardItems, ...fitMenuItems],\n [fitMenuItems, keyboardItems],\n );\n\n return { contentFit, geometryMenuItems };\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import { type PointerEvent as ReactPointerEvent, type RefObject } from "react";
2
2
  import type { ResizeEdge } from "./WindowResizeHandle.js";
3
- import { type WindowEntry, type WindowPosition, type WindowSize } from "./WindowStateProvider/index.js";
3
+ import { type WindowEntry, type WindowGeometry, type WindowPosition, type WindowSize } from "./WindowStateProvider/index.js";
4
4
  import { type LiveGeometry } from "./windowGeometry.js";
5
5
  export declare function useWindowGeometry(entry: WindowEntry, maximized: boolean, windowRef: RefObject<HTMLElement | null>): {
6
+ applyGeometry: (geometry: WindowGeometry) => void;
6
7
  commit: () => void;
7
8
  hold: (holding: boolean) => void;
8
9
  handlePointerDown: (event: ReactPointerEvent) => void;
@@ -73,12 +73,19 @@ function useLiveGeometry(entry) {
73
73
  });
74
74
  }
75
75
  }, [entry.id, setGeometry]);
76
+ // Fit and other window-owned changes must update the live frame before
77
+ // publication: a surface observer can commit again before the passive mirror.
78
+ const applyGeometry = useCallback((geometry) => {
79
+ setPosition(geometry.position);
80
+ setSize(geometry.size ?? null);
81
+ commit();
82
+ }, [commit, setPosition, setSize]);
76
83
  // The committed size is the source of truth between gestures: a restored
77
84
  // layout or host call applies it, and clearing it restores the default size.
78
85
  useEffect(() => {
79
86
  setSize(entry.size ?? null);
80
87
  }, [entry.size, setSize]);
81
- return { commit, live, position, setPosition, setSize, size };
88
+ return { applyGeometry, commit, live, position, setPosition, setSize, size };
82
89
  }
83
90
  // Stepwise geometry for keyboard move and resize. Steps stay local until the
84
91
  // caller commits, like a pointer gesture; restore puts a snapshot back.
@@ -182,7 +189,7 @@ function useGestureStarts(windowRef, maximized, position, dragging, resizing) {
182
189
  return { handlePointerDown, handleResizePointerDown };
183
190
  }
184
191
  export function useWindowGeometry(entry, maximized, windowRef) {
185
- const { commit, live, position, setPosition, setSize, size } = useLiveGeometry(entry);
192
+ const { applyGeometry, commit, live, position, setPosition, setSize, size } = useLiveGeometry(entry);
186
193
  const dragging = useRef(null);
187
194
  const resizing = useRef(null);
188
195
  // Maximizing or minimizing mid-gesture (a second touch on the title bar's
@@ -232,6 +239,7 @@ export function useWindowGeometry(entry, maximized, windowRef) {
232
239
  const stepped = useSteppedGeometry(windowRef, maximized, live, clamp, setPosition, setSize);
233
240
  return {
234
241
  ...stepped,
242
+ applyGeometry,
235
243
  commit,
236
244
  hold,
237
245
  handlePointerDown,