@kernlize/core 0.12.0 → 0.14.0
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/README.md +1 -1
- package/dist/{chunk-E7SNLTN2.js → chunk-ALAK4MW6.js} +8 -1
- package/dist/chunk-ALAK4MW6.js.map +1 -0
- package/dist/index.d.ts +1368 -133
- package/dist/index.js +3563 -487
- package/dist/index.js.map +1 -1
- package/dist/wm/index.d.ts +7 -0
- package/dist/wm/index.js +1 -1
- package/package.json +4 -3
- package/dist/chunk-E7SNLTN2.js.map +0 -1
package/dist/wm/index.d.ts
CHANGED
|
@@ -185,6 +185,13 @@ interface WindowManager {
|
|
|
185
185
|
move(id: string, rect: Rect): void;
|
|
186
186
|
/** Mark a window's applet as stopped: it loses focus, is no longer reported to, and waits to be closed. */
|
|
187
187
|
stop(id: string): void;
|
|
188
|
+
/**
|
|
189
|
+
* The window's applet starts again under the id `next`: the window keeps its rectangle, its place
|
|
190
|
+
* in the opening order and in any arrangement, is shown, is no longer stopped, and comes to the
|
|
191
|
+
* front, focused. Its old target is reported to no more; the new applet is attached under `next`.
|
|
192
|
+
* Does nothing when `id` is not open or `next` already is.
|
|
193
|
+
*/
|
|
194
|
+
replace(id: string, next: string): void;
|
|
188
195
|
/** Report this window's visibility to `target`, now and after every change. Called once per window, when its applet is mounted. */
|
|
189
196
|
attach(id: string, target: VisibilityTarget): void;
|
|
190
197
|
/** What the guard is told about a window when it asks. An unknown window is neither visible nor focused. */
|
package/dist/wm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernlize/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Opinionated shell composition over kehto and applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@internet-privacy/marmot-ts": "^0.9.0",
|
|
37
37
|
"@kehto/acl": "^0.20.6",
|
|
38
|
+
"@kehto/firewall": "^0.10.0",
|
|
38
39
|
"@kehto/nip": "^0.8.0",
|
|
39
40
|
"@kehto/rate-limit": "^0.2.0",
|
|
40
41
|
"@kehto/runtime": "^0.30.1",
|
|
@@ -55,8 +56,8 @@
|
|
|
55
56
|
"blossom-client-sdk": "5.1.0",
|
|
56
57
|
"nostr-double-ratchet": "^0.0.187",
|
|
57
58
|
"rxjs": "^7.8.2",
|
|
58
|
-
"@kernlize/
|
|
59
|
-
"@kernlize/
|
|
59
|
+
"@kernlize/guard": "^0.3.0",
|
|
60
|
+
"@kernlize/bridges": "^0.3.0",
|
|
60
61
|
"@kernlize/messaging": "^0.4.1"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/wm/layouts.ts","../src/wm/layout-registry.ts","../src/wm/window-manager.ts"],"sourcesContent":["import type { LayoutStrategy, Rect, WindowPlacement, WindowState } from '@kehto/wm';\n\n/** Spacing options shared by the tiling layouts. */\nexport interface LayoutOptions {\n /** Pixels between windows. Defaults to 0. */\n readonly gap?: number;\n /** Pixels between the windows and the container edge. Defaults to `gap`. */\n readonly margin?: number;\n}\n\n/** Options for {@link createMasterStackLayout}. */\nexport interface MasterStackOptions extends LayoutOptions {\n /** Share of the width the master window takes. Defaults to 0.6. */\n readonly ratio?: number;\n}\n\n/**\n * Windows keep the rectangles they have. The strategy for a free-floating desktop.\n *\n * @example\n * ```ts\n * floatingLayout.arrange(windows, { x: 0, y: 0, w: 1200, h: 800 });\n * // every window keeps the rect it already had\n * ```\n */\nexport const floatingLayout: LayoutStrategy = {\n arrange: (windows) => windows.map(({ id, rect }) => ({ id, rect: { ...rect } })),\n};\n\nfunction visible(windows: ReadonlyArray<WindowState>): WindowState[] {\n return windows.filter((window) => !window.minimized);\n}\n\ninterface Spacing {\n readonly gap: number;\n readonly margin: number;\n}\n\nfunction spacing(options: LayoutOptions): Spacing {\n const gap = options.gap ?? 0;\n return { gap, margin: options.margin ?? gap };\n}\n\nfunction inset(rect: Rect, margin: number): Rect {\n return { x: rect.x + margin, y: rect.y + margin, w: Math.max(0, rect.w - margin * 2), h: Math.max(0, rect.h - margin * 2) };\n}\n\n/** Round the edges, not the sizes: two windows that share an edge then agree on where it is, so they never overlap or leave a hole. */\nfunction place(id: string, rect: Rect): WindowPlacement {\n const x = Math.round(rect.x);\n const y = Math.round(rect.y);\n return { id, rect: { x, y, w: Math.round(rect.x + rect.w) - x, h: Math.round(rect.y + rect.h) - y } };\n}\n\nfunction splitRows(area: Rect, count: number, gap: number): Rect[] {\n const h = (area.h - gap * (count - 1)) / count;\n return Array.from({ length: count }, (_, index) => ({ x: area.x, y: area.y + index * (h + gap), w: area.w, h }));\n}\n\nfunction splitColumns(area: Rect, count: number, gap: number): Rect[] {\n const w = (area.w - gap * (count - 1)) / count;\n return Array.from({ length: count }, (_, index) => ({ x: area.x + index * (w + gap), y: area.y, w, h: area.h }));\n}\n\n/**\n * The dwindle layout: each window after the first takes half of the remaining\n * area, splitting vertically then horizontally in turn, so the last window\n * ends up in the smallest corner. Minimised windows are left out.\n *\n * @param options - Gap between windows and margin at the container edge.\n * @returns A `LayoutStrategy`.\n * @example\n * ```ts\n * createDwindleLayout({ gap: 8 }).arrange(windows, { x: 0, y: 0, w: 1200, h: 800 });\n * ```\n */\nexport function createDwindleLayout(options: LayoutOptions = {}): LayoutStrategy {\n const { gap, margin } = spacing(options);\n return {\n arrange(windows, containerRect) {\n const shown = visible(windows);\n const placements: WindowPlacement[] = [];\n let remaining = inset(containerRect, margin);\n shown.forEach((window, index) => {\n if (index === shown.length - 1) {\n placements.push(place(window.id, remaining));\n return;\n }\n const splitVertically = index % 2 === 0;\n const [first, rest] = splitVertically ? splitColumns(remaining, 2, gap) : splitRows(remaining, 2, gap);\n placements.push(place(window.id, first as Rect));\n remaining = rest as Rect;\n });\n return placements;\n },\n };\n}\n\n/**\n * Equal-width columns in window order. Minimised windows are left out.\n *\n * @param options - Gap between windows and margin at the container edge.\n * @returns A `LayoutStrategy`.\n * @example\n * ```ts\n * createColumnsLayout().arrange(windows, container)[0]?.rect.x; // 0\n * ```\n */\nexport function createColumnsLayout(options: LayoutOptions = {}): LayoutStrategy {\n const { gap, margin } = spacing(options);\n return {\n arrange(windows, containerRect) {\n const shown = visible(windows);\n const columns = splitColumns(inset(containerRect, margin), shown.length, gap);\n return shown.map((window, index) => place(window.id, columns[index] as Rect));\n },\n };\n}\n\n/**\n * One master window on the left, the rest stacked on the right. The focused\n * window is the master; without focus, the first window is. Minimised windows\n * are left out and a single window fills the container.\n *\n * @param options - Master width ratio, gap and margin.\n * @returns A `LayoutStrategy`.\n * @example\n * ```ts\n * createMasterStackLayout({ ratio: 0.5, gap: 4 }).arrange(windows, container);\n * ```\n */\nexport function createMasterStackLayout(options: MasterStackOptions = {}): LayoutStrategy {\n const { gap, margin } = spacing(options);\n const ratio = options.ratio ?? 0.6;\n return {\n arrange(windows, containerRect) {\n const shown = visible(windows);\n if (shown.length === 0) return [];\n const area = inset(containerRect, margin);\n const master = shown.find((window) => window.focused) ?? (shown[0] as WindowState);\n const stack = shown.filter((window) => window !== master);\n if (stack.length === 0) return [place(master.id, area)];\n const masterWidth = (area.w - gap) * ratio;\n const masterRect: Rect = { x: area.x, y: area.y, w: masterWidth, h: area.h };\n const stackArea: Rect = { x: area.x + masterWidth + gap, y: area.y, w: area.w - masterWidth - gap, h: area.h };\n const rows = splitRows(stackArea, stack.length, gap);\n return [place(master.id, masterRect), ...stack.map((window, index) => place(window.id, rows[index] as Rect))];\n },\n };\n}\n","import type { LayoutStrategy } from '@kehto/wm';\nimport { createColumnsLayout, createDwindleLayout, createMasterStackLayout, floatingLayout, type LayoutOptions } from './layouts.js';\n\n/** A layout as the person picks it: a stable id and the words the shell shows. */\nexport interface LayoutChoice {\n /** Stable id, kept in storage as the person's choice. */\n readonly id: string;\n /** What the shell calls the layout. */\n readonly label: string;\n}\n\n/** A named layout strategy. */\nexport interface LayoutEntry extends LayoutChoice {\n /** Where the windows go. */\n readonly strategy: LayoutStrategy;\n /**\n * True when the person places the windows and the strategy hands their rectangles back.\n * A window manager lets windows be moved and resized only in a freeform layout.\n */\n readonly freeform?: boolean;\n}\n\n/** The layouts a window manager offers, in the order the shell lists them. */\nexport interface LayoutRegistry {\n /**\n * Add a layout.\n * @throws `invalid:duplicate-layout` when the id is taken.\n */\n register(entry: LayoutEntry): void;\n /** The layout with this id, if there is one. */\n get(id: string): LayoutEntry | undefined;\n /** Every layout, in registration order. */\n list(): readonly LayoutEntry[];\n}\n\n/**\n * Create a layout registry, optionally holding some layouts already.\n *\n * @param entries - Layouts to register, in order.\n * @returns A `LayoutRegistry`.\n * @example\n * ```ts\n * const layouts = createLayoutRegistry([{ id: 'floating', label: 'floating', strategy: floatingLayout, freeform: true }]);\n * layouts.register({ id: 'columns', label: 'columns', strategy: createColumnsLayout({ gap: 8 }) });\n * layouts.list().map((layout) => layout.id); // ['floating', 'columns']\n * ```\n */\nexport function createLayoutRegistry(entries: readonly LayoutEntry[] = []): LayoutRegistry {\n const layouts = new Map<string, LayoutEntry>();\n const registry: LayoutRegistry = {\n register(entry) {\n if (layouts.has(entry.id)) throw new Error('invalid:duplicate-layout');\n layouts.set(entry.id, entry);\n },\n get: (id) => layouts.get(id),\n list: () => [...layouts.values()],\n };\n for (const entry of entries) registry.register(entry);\n return registry;\n}\n\n/**\n * The layouts kernl ships, floating first: `floating`, `dwindle` (shown as \"tiled\"), `columns` and\n * `master-stack` (shown as \"main and stack\"). The spacing applies to the three that arrange windows.\n *\n * @param options - Gap between windows and margin at the container edge, for the tiling layouts.\n * @returns A `LayoutRegistry` holding the four layouts; register your own on top.\n * @example\n * ```ts\n * const layouts = createDefaultLayouts({ gap: 8, margin: 0 });\n * layouts.register({ id: 'rows', label: 'rows', strategy: myRowsLayout });\n * ```\n */\nexport function createDefaultLayouts(options: LayoutOptions = {}): LayoutRegistry {\n return createLayoutRegistry([\n { id: 'floating', label: 'floating', strategy: floatingLayout, freeform: true },\n { id: 'dwindle', label: 'tiled', strategy: createDwindleLayout(options) },\n { id: 'columns', label: 'columns', strategy: createColumnsLayout(options) },\n { id: 'master-stack', label: 'main and stack', strategy: createMasterStackLayout(options) },\n ]);\n}\n","import type { Rect } from '@kehto/wm';\nimport type { WindowVisibility } from '@kernlize/guard';\nimport { BehaviorSubject, type Observable } from 'rxjs';\nimport { createDefaultLayouts, type LayoutChoice, type LayoutEntry, type LayoutRegistry } from './layout-registry.js';\n\n/** A width and a height in CSS pixels. */\nexport interface WindowSize {\n readonly w: number;\n readonly h: number;\n}\n\n/** One window as the manager has it now. */\nexport interface ManagedWindow {\n readonly id: string;\n /** Where the window is drawn: the layout's placement, or the window's own rectangle when the layout leaves it out. */\n readonly rect: Rect;\n /** Stacking order. The highest is in front. */\n readonly z: number;\n /** Whether the person is working in this window. */\n readonly focused: boolean;\n readonly minimised: boolean;\n /** Its applet was stopped. The window stays until it is closed, takes no focus and is never reported visible. */\n readonly stopped: boolean;\n}\n\n/** Everything a shell needs to draw its windows. A new object is published after every change. */\nexport interface WindowManagerState {\n /** Every window, in opening order. The order never changes while a window lives, so a frame is never moved in the document. */\n readonly windows: readonly ManagedWindow[];\n readonly focusedId: string | null;\n /** The layout in use. */\n readonly layout: LayoutChoice;\n /** The rectangle windows are laid out in. */\n readonly area: Rect;\n /** The area is narrow: every window fills it, whatever the layout. */\n readonly compact: boolean;\n /** Whether the person may move and resize windows now. */\n readonly freeform: boolean;\n}\n\n/** What the manager reports a window's visibility to. An `AppletHandle` is one. */\nexport interface VisibilityTarget {\n setVisibility(visibility: WindowVisibility): void;\n}\n\n/**\n * Where windows are, which one has the person's attention, and what the guard is told about each.\n *\n * A shell draws from `state$` and calls the methods from its own events. One obligation is fixed for\n * every implementation: `visibilityOf` and the reports sent to each attached target must be true. A\n * window the person cannot see is not visible, and a window they are not working in is not focused.\n * The guard holds a hidden applet's requests and gives an unfocused one a smaller budget on the\n * strength of these reports. Everything else is the implementation's choice.\n */\nexport interface WindowManager {\n /** The current state, then every state after it. */\n readonly state$: Observable<WindowManagerState>;\n /** The current state. */\n snapshot(): WindowManagerState;\n /** The layouts the person can choose between. */\n layouts(): readonly LayoutChoice[];\n /** Add a window in front, focused. Opening an id that is already open brings that window to the front. */\n open(id: string): void;\n /** Remove a window and stop reporting to it. */\n close(id: string): void;\n /** Bring a window to the front and give it the person's attention. Shows it if it was minimised. */\n focus(id: string): void;\n /** The person is working in the shell itself; no window is focused. */\n blur(): void;\n /** Hide a window without closing it. */\n minimise(id: string): void;\n /** Move or resize a window. Ignored unless the state is `freeform`. */\n move(id: string, rect: Rect): void;\n /** Mark a window's applet as stopped: it loses focus, is no longer reported to, and waits to be closed. */\n stop(id: string): void;\n /** Report this window's visibility to `target`, now and after every change. Called once per window, when its applet is mounted. */\n attach(id: string, target: VisibilityTarget): void;\n /** What the guard is told about a window when it asks. An unknown window is neither visible nor focused. */\n visibilityOf(id: string): WindowVisibility;\n /** Set the rectangle windows are laid out in. */\n setArea(area: Rect): void;\n /**\n * Switch layout.\n * @throws `invalid:unknown-layout` when no layout has this id.\n */\n setLayout(id: string): void;\n /** Tell the manager whether the page itself can be seen. A hidden page hides every window. */\n setPageVisible(visible: boolean): void;\n /** Stop reporting and complete `state$`. */\n destroy(): void;\n}\n\n/** Options for {@link createWindowManager}. */\nexport interface WindowManagerOptions {\n /** The layouts on offer. Defaults to `createDefaultLayouts()`. */\n readonly layouts?: LayoutRegistry;\n /** The id of the layout to start in. Defaults to the first registered; an id that is not registered is ignored. */\n readonly layout?: string;\n /** The rectangle to lay windows out in until `setArea` is called. Defaults to 1280 by 800 at the origin. */\n readonly area?: Rect;\n /** At or below this area width every window fills the area. Defaults to 720; 0 turns it off. */\n readonly compactWidth?: number;\n /** The size a new window opens at. Defaults to 720 by 660. */\n readonly windowSize?: WindowSize;\n /** The smallest a window may be made. Defaults to 280 by 160. */\n readonly minSize?: WindowSize;\n /** Called with the id after every `setLayout`, so the choice can be remembered. */\n readonly onLayout?: (id: string) => void;\n /** Clock for `msSinceFocusGain`. Defaults to `Date.now`. */\n readonly now?: () => number;\n}\n\ninterface Entry {\n readonly id: string;\n own: Rect;\n z: number;\n minimised: boolean;\n stopped: boolean;\n focusGainedAt: number;\n target: VisibilityTarget | undefined;\n}\n\ninterface Desk {\n readonly entries: Entry[];\n layout: LayoutEntry;\n area: Rect;\n focusedId: string | null;\n pageVisible: boolean;\n nextZ: number;\n}\n\nconst DEFAULT_AREA: Rect = { x: 0, y: 0, w: 1280, h: 800 };\nconst DEFAULT_SIZE: WindowSize = { w: 720, h: 660 };\nconst MIN_SIZE: WindowSize = { w: 280, h: 160 };\nconst DEFAULT_COMPACT_WIDTH = 720;\nconst CASCADE_STEP = 32;\nconst CASCADE_WRAP = 8;\n\n/** Keep a window inside the area, no smaller than `min` and no larger than the area. */\nfunction clamp(rect: Rect, area: Rect, min: WindowSize): Rect {\n const w = Math.min(Math.max(rect.w, min.w), area.w);\n const h = Math.min(Math.max(rect.h, min.h), area.h);\n const x = Math.min(Math.max(rect.x, area.x), area.x + area.w - w);\n const y = Math.min(Math.max(rect.y, area.y), area.y + area.h - h);\n return { x, y, w, h };\n}\n\n/** Step each new window down and right so it does not hide the one before; start over after eight. */\nfunction cascade(index: number, area: Rect, size: WindowSize, min: WindowSize): Rect {\n const offset = (index % CASCADE_WRAP) * CASCADE_STEP;\n return clamp({ x: area.x + 40 + offset, y: area.y + 24 + offset, ...size }, area, min);\n}\n\nfunction startingLayout(layouts: LayoutRegistry, wanted: string | undefined): LayoutEntry {\n const layout = layouts.get(wanted ?? '') ?? layouts.list()[0];\n if (!layout) throw new Error('invalid:no-layouts');\n return layout;\n}\n\nconst sameRect = (a: Rect, b: Rect): boolean => a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;\n\nconst find = (desk: Desk, id: string): Entry | undefined => desk.entries.find((entry) => entry.id === id);\n\n/** The front-most window the person can see. */\nfunction front(desk: Desk): Entry | undefined {\n return desk.entries\n .filter((entry) => !entry.minimised && !entry.stopped)\n .reduce<Entry | undefined>((best, entry) => (best && best.z > entry.z ? best : entry), undefined);\n}\n\nfunction visibility(desk: Desk, id: string, now: () => number): WindowVisibility {\n const entry = find(desk, id);\n if (!entry) return { visible: false, focused: false };\n const visible = desk.pageVisible && !entry.minimised && !entry.stopped;\n const focused = visible && desk.focusedId === id;\n return focused ? { visible, focused, msSinceFocusGain: now() - entry.focusGainedAt } : { visible, focused };\n}\n\n/**\n * Run the layout. A strategy is told the front-most window is the focused one, so an arrangement that\n * follows focus does not reshuffle when the person turns to the shell's own panels and no window is focused.\n */\nfunction arrange(desk: Desk, compact: boolean): Map<string, Rect> {\n const placed = new Map<string, Rect>();\n if (compact) return placed;\n const leader = front(desk);\n const states = desk.entries.map((entry) => ({ id: entry.id, focused: entry === leader, minimized: entry.minimised || entry.stopped, rect: { ...entry.own } }));\n for (const placement of desk.layout.strategy.arrange(states, { ...desk.area })) placed.set(placement.id, placement.rect);\n return placed;\n}\n\nfunction describe(desk: Desk, compactWidth: number): WindowManagerState {\n const compact = desk.area.w <= compactWidth;\n const placed = arrange(desk, compact);\n const rectOf = (entry: Entry): Rect => ({ ...(compact ? desk.area : (placed.get(entry.id) ?? entry.own)) });\n return {\n windows: desk.entries.map((entry) => ({\n id: entry.id,\n rect: rectOf(entry),\n z: entry.z,\n focused: desk.focusedId === entry.id,\n minimised: entry.minimised,\n stopped: entry.stopped,\n })),\n focusedId: desk.focusedId,\n layout: { id: desk.layout.id, label: desk.layout.label },\n area: { ...desk.area },\n compact,\n freeform: !compact && desk.layout.freeform === true,\n };\n}\n\n/**\n * Create kernl's window manager: windows cascade as they open, the person picks a layout from a\n * registry, a narrow area shows one window at a time, and each attached applet is told whether it\n * can be seen and whether it has the person's attention.\n *\n * It holds no DOM and draws nothing. Feed it the shell's events, draw from `state$`, and answer\n * `KernlHost.getVisibility` with `visibilityOf`.\n *\n * @param options - Layouts, starting layout, sizes and a clock.\n * @returns A `WindowManager`.\n * @throws `invalid:no-layouts` when the registry is empty.\n * @example\n * ```ts\n * const windows = createWindowManager({ layouts: createDefaultLayouts({ gap: 8, margin: 0 }) });\n * windows.state$.subscribe((state) => draw(state.windows));\n * windows.setArea({ x: 0, y: 0, w: 1440, h: 900 });\n * windows.open(plan.windowId);\n * windows.attach(plan.windowId, kernl.mount(plan, frame));\n * windows.setLayout('columns');\n * ```\n */\nexport function createWindowManager(options: WindowManagerOptions = {}): WindowManager {\n const layouts = options.layouts ?? createDefaultLayouts();\n const now = options.now ?? Date.now;\n const compactWidth = options.compactWidth ?? DEFAULT_COMPACT_WIDTH;\n const size = options.windowSize ?? DEFAULT_SIZE;\n const min = options.minSize ?? MIN_SIZE;\n const desk: Desk = { entries: [], layout: startingLayout(layouts, options.layout), area: options.area ?? DEFAULT_AREA, focusedId: null, pageVisible: true, nextZ: 1 };\n const state = new BehaviorSubject(describe(desk, compactWidth));\n\n const report = (): void => {\n for (const entry of desk.entries) entry.target?.setVisibility(visibility(desk, entry.id, now));\n };\n const publish = (): void => state.next(describe(desk, compactWidth));\n /** Focus moved or a window was shown or hidden: tell the applets first, then redraw. */\n const changed = (): void => {\n report();\n publish();\n };\n const focusOn = (entry: Entry | undefined): void => {\n desk.focusedId = entry?.id ?? null;\n if (entry) entry.focusGainedAt = now();\n };\n const leave = (id: string): void => {\n if (desk.focusedId === id) focusOn(front(desk));\n };\n\n const manager: WindowManager = {\n state$: state.asObservable(),\n snapshot: () => state.value,\n layouts: () => layouts.list().map(({ id, label }) => ({ id, label })),\n open(id) {\n if (!find(desk, id)) {\n const own = cascade(desk.entries.length, desk.area, size, min);\n desk.entries.push({ id, own, z: 0, minimised: false, stopped: false, focusGainedAt: 0, target: undefined });\n }\n manager.focus(id);\n },\n close(id) {\n const index = desk.entries.findIndex((entry) => entry.id === id);\n if (index === -1) return;\n desk.entries.splice(index, 1);\n leave(id);\n changed();\n },\n focus(id) {\n const entry = find(desk, id);\n if (!entry || entry.stopped) return;\n entry.minimised = false;\n if (desk.focusedId !== id) focusOn(entry);\n entry.z = desk.nextZ++;\n changed();\n },\n blur() {\n if (desk.focusedId === null) return;\n focusOn(undefined);\n changed();\n },\n minimise(id) {\n const entry = find(desk, id);\n if (!entry) return;\n entry.minimised = true;\n leave(id);\n changed();\n },\n move(id, rect) {\n const entry = find(desk, id);\n if (!entry || !state.value.freeform) return;\n entry.own = clamp(rect, desk.area, min);\n publish();\n },\n stop(id) {\n const entry = find(desk, id);\n if (!entry) return;\n entry.stopped = true;\n entry.target = undefined;\n leave(id);\n changed();\n },\n attach(id, target) {\n const entry = find(desk, id);\n if (!entry || entry.target) return;\n entry.target = target;\n target.setVisibility(visibility(desk, id, now));\n },\n visibilityOf: (id) => visibility(desk, id, now),\n setArea(area) {\n if (sameRect(area, desk.area)) return;\n desk.area = { ...area };\n for (const entry of desk.entries) entry.own = clamp(entry.own, desk.area, min);\n publish();\n },\n setLayout(id) {\n const layout = layouts.get(id);\n if (!layout) throw new Error('invalid:unknown-layout');\n desk.layout = layout;\n options.onLayout?.(id);\n publish();\n },\n setPageVisible(visible) {\n if (visible === desk.pageVisible) return;\n desk.pageVisible = visible;\n report();\n },\n destroy() {\n for (const entry of desk.entries) entry.target = undefined;\n state.complete();\n },\n };\n return manager;\n}\n"],"mappings":";AAyBO,IAAM,iBAAiC;AAAA,EAC5C,SAAS,CAAC,YAAY,QAAQ,IAAI,CAAC,EAAE,IAAI,KAAK,OAAO,EAAE,IAAI,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE;AACjF;AAEA,SAAS,QAAQ,SAAoD;AACnE,SAAO,QAAQ,OAAO,CAAC,WAAW,CAAC,OAAO,SAAS;AACrD;AAOA,SAAS,QAAQ,SAAiC;AAChD,QAAM,MAAM,QAAQ,OAAO;AAC3B,SAAO,EAAE,KAAK,QAAQ,QAAQ,UAAU,IAAI;AAC9C;AAEA,SAAS,MAAM,MAAY,QAAsB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