vintage-frames 0.13.0 → 0.14.1
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 +16 -0
- package/custom-elements.json +184 -20
- package/dist/components/vf-checkbox.d.ts +6 -5
- package/dist/components/vf-checkbox.js +41 -37
- package/dist/components/vf-container.d.ts +14 -14
- package/dist/components/vf-container.js +58 -28
- package/dist/components/vf-desktop.d.ts +114 -12
- package/dist/components/vf-desktop.js +119 -58
- package/dist/components/vf-fieldset.js +30 -22
- package/dist/components/vf-icon-field.d.ts +1 -1
- package/dist/components/vf-icon.js +111 -104
- package/dist/components/vf-list.js +30 -29
- package/dist/components/vf-menu-bar.d.ts +5 -0
- package/dist/components/vf-menu-bar.js +67 -43
- package/dist/components/vf-menu.js +24 -22
- package/dist/components/vf-number-field.js +32 -30
- package/dist/components/vf-progress-bar.js +28 -29
- package/dist/components/vf-radio.js +3 -4
- package/dist/components/vf-scroll-area.js +27 -26
- package/dist/components/vf-select.js +108 -90
- package/dist/components/vf-separator.d.ts +5 -5
- package/dist/components/vf-separator.js +36 -10
- package/dist/components/vf-swatch.js +47 -45
- package/dist/components/vf-text-area.js +37 -35
- package/dist/components/vf-text-field.js +20 -18
- package/dist/components/vf-window.d.ts +13 -0
- package/dist/components/vf-window.js +101 -72
- package/dist/index.d.ts +12 -1
- package/dist/index.js +61 -59
- package/dist/pattern-fill.d.ts +11 -8
- package/dist/pattern-fill.js +2 -4
- package/dist/position.d.ts +25 -7
- package/dist/position.js +6 -3
- package/dist/shell/alert.d.ts +32 -0
- package/dist/shell/alert.js +44 -0
- package/dist/shell/catalog.d.ts +168 -0
- package/dist/shell/catalog.js +278 -0
- package/dist/shell/clock.d.ts +16 -0
- package/dist/shell/clock.js +36 -0
- package/dist/shell/filing.d.ts +39 -0
- package/dist/shell/filing.js +68 -0
- package/dist/shell/finder.d.ts +116 -0
- package/dist/shell/finder.js +564 -0
- package/dist/shell/geometry.d.ts +196 -0
- package/dist/shell/geometry.js +241 -0
- package/dist/shell/index.d.ts +29 -0
- package/dist/shell/index.js +11 -0
- package/dist/shell/shell.d.ts +150 -0
- package/dist/shell/shell.js +213 -0
- package/dist/shell/state.d.ts +88 -0
- package/dist/shell/state.js +103 -0
- package/dist/shell/storage.d.ts +14 -0
- package/dist/shell/storage.js +41 -0
- package/dist/shell/windows.d.ts +215 -0
- package/dist/shell/windows.js +343 -0
- package/dist/styles/base.d.ts +3 -1
- package/dist/styles/recipes/field.d.ts +10 -6
- package/dist/styles/recipes/field.js +8 -7
- package/dist/styles/recipes/focus.d.ts +7 -3
- package/dist/styles/recipes/rule.d.ts +11 -8
- package/dist/styles/recipes/rule.js +31 -13
- package/dist/styles/recipes/scroll-rail.d.ts +7 -6
- package/dist/styles/recipes/scroll-rail.js +18 -18
- package/dist/styles/recipes/shadow.d.ts +10 -6
- package/dist/styles/recipes/shadow.js +4 -2
- package/dist/styles/recipes/stroke.d.ts +85 -0
- package/dist/styles/recipes/stroke.js +53 -0
- package/dist/styles/recipes/surface.d.ts +8 -4
- package/dist/styles/recipes/surface.js +23 -17
- package/dist/styles/recipes/title-bar.d.ts +7 -0
- package/dist/styles/recipes/title-bar.js +25 -22
- package/dist/styles/recipes/toggle.js +3 -3
- package/dist/window-chrome.d.ts +43 -0
- package/dist/window-chrome.js +13 -0
- package/dist/zoom.d.ts +9 -9
- package/docs/SPEC.md +34 -32
- package/editor/vscode.html-custom-data.json +12 -7
- package/editor/web-types.json +50 -14
- package/package.json +10 -2
package/dist/position.d.ts
CHANGED
|
@@ -97,14 +97,17 @@ type PositionedHost = HTMLElement & {
|
|
|
97
97
|
* re-asserts a coordinate and costs nothing.
|
|
98
98
|
*
|
|
99
99
|
* **Every write it makes is announced** as `vf-placement-change` (bubbles,
|
|
100
|
-
* `composed: false`, detail `{ left, top }` — nulls on a return to flow)
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
100
|
+
* `composed: false`, detail `{ left, top }` — nulls on a return to flow), so
|
|
101
|
+
* a page hears every move the one way: a title-bar drag's steps and its
|
|
102
|
+
* release (an outline drag's single write), an arrow nudge, a drop, a walk's
|
|
103
|
+
* landing, an `origin` re-measure, and its own property writes. Non-composed,
|
|
104
|
+
* because parent and child share one light tree and the event has no reason
|
|
105
|
+
* to leave a consumer's shadow root. It is dispatched from the host's update,
|
|
106
|
+
* with the new pair already on its style: a handler that writes the pair
|
|
107
|
+
* again takes effect on the next update. `vf-scroll-area` listens for it and
|
|
104
108
|
* re-measures, because a placed child moved through `top`/`left` changes the
|
|
105
109
|
* scroll range with no box changing anywhere a ResizeObserver can see — the
|
|
106
|
-
* plane's box is never grown by an absolutely positioned child.
|
|
107
|
-
* covers a drop, an arrow nudge and a page's own `icon.left = …` alike.
|
|
110
|
+
* plane's box is never grown by an absolutely positioned child.
|
|
108
111
|
*
|
|
109
112
|
* **`origin`** names which point of the host's own box the pair places —
|
|
110
113
|
* nine keywords, vertical then horizontal (`top center`, `bottom right`,
|
|
@@ -169,11 +172,26 @@ export declare function placementIn(anchor: Element, clientX: number, clientY: n
|
|
|
169
172
|
left: number;
|
|
170
173
|
top: number;
|
|
171
174
|
};
|
|
172
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* The box a gesture is clamped into, in system px — see {@link PlacementClamp}.
|
|
177
|
+
* `width` and `height` are the positioning parent's box; `top` is the least
|
|
178
|
+
* `top` a placement may take there: 0, or on a desktop's screen the bottom of
|
|
179
|
+
* its menu bar (`vf-desktop.workArea`).
|
|
180
|
+
*/
|
|
173
181
|
export type PlacementBounds = {
|
|
174
182
|
width: number;
|
|
175
183
|
height: number;
|
|
184
|
+
top: number;
|
|
176
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* The detail of `vf-placement-bounds-request`: the handshake a moved host
|
|
188
|
+
* makes when its gesture measures the box it is clamped into. A
|
|
189
|
+
* `vf-desktop` on its light-DOM path fills `bounds` for a host placed on its
|
|
190
|
+
* screen. Internal to the kit's placement.
|
|
191
|
+
*/
|
|
192
|
+
export interface PlacementBoundsRequest {
|
|
193
|
+
bounds: PlacementBounds | null;
|
|
194
|
+
}
|
|
177
195
|
/**
|
|
178
196
|
* A moved host's own containment rule, in system px, against the box measured
|
|
179
197
|
* once at the start of the gesture.
|
package/dist/position.js
CHANGED
|
@@ -193,10 +193,13 @@ var _ = class {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
#i() {
|
|
196
|
-
let
|
|
196
|
+
let t = this.#e, n = { bounds: null };
|
|
197
|
+
if (e(t, "vf-placement-bounds-request", n, { composed: !1 }), n.bounds) return n.bounds;
|
|
198
|
+
let r = t.offsetParent, a = r && r.clientWidth > 0 && r.clientHeight > 0 ? r : null;
|
|
197
199
|
return {
|
|
198
|
-
width: i(
|
|
199
|
-
height: i(
|
|
200
|
+
width: i(a?.clientWidth ?? window.innerWidth, t),
|
|
201
|
+
height: i(a?.clientHeight ?? window.innerHeight, t),
|
|
202
|
+
top: 0
|
|
200
203
|
};
|
|
201
204
|
}
|
|
202
205
|
}, v = /* @__PURE__ */ new Set([
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shell's alert: a plain-framed `vf-dialog` with the site's caution art,
|
|
3
|
+
* a message and a row of buttons, sized to the message — composed from kit
|
|
4
|
+
* elements, as every alert in the kit is.
|
|
5
|
+
*
|
|
6
|
+
* The layout follows the plain frame's body, its width and height less 10:
|
|
7
|
+
* the art and the message 16 in from the body's top-left, the buttons'
|
|
8
|
+
* bottom-right corner 16 in from the body's.
|
|
9
|
+
*/
|
|
10
|
+
/** One button of an alert. */
|
|
11
|
+
export interface AlertButton {
|
|
12
|
+
label: string;
|
|
13
|
+
/** What the alert resolves to when it is pressed. */
|
|
14
|
+
value: string;
|
|
15
|
+
/** The default button, which Return presses. */
|
|
16
|
+
default?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface AlertOptions {
|
|
19
|
+
/** Default: OK, the default button. */
|
|
20
|
+
buttons?: AlertButton[];
|
|
21
|
+
/** The dialog's width, system px. Default 400. */
|
|
22
|
+
width?: number;
|
|
23
|
+
/** The 32×32 art beside the message; default the shell's caution art. */
|
|
24
|
+
art?: string | null;
|
|
25
|
+
/** The dialog's accessible name. Default "Alert". */
|
|
26
|
+
label?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Show an alert inside `host` (the desktop), and resolve the value of the
|
|
30
|
+
* button pressed — or null when it closed any other way, Escape say.
|
|
31
|
+
*/
|
|
32
|
+
export declare function showAlert(host: Element, message: string, options?: AlertOptions): Promise<string | null>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { effectiveScale as e } from "../scale.js";
|
|
2
|
+
import "../index.js";
|
|
3
|
+
//#region src/shell/alert.ts
|
|
4
|
+
var t = 10, n = 16, r = 32, i = 28;
|
|
5
|
+
async function a(a, o, s = {}) {
|
|
6
|
+
let { buttons: c = [{
|
|
7
|
+
label: "OK",
|
|
8
|
+
value: "ok",
|
|
9
|
+
default: !0
|
|
10
|
+
}], width: l = 400, art: u = null, label: d = "Alert" } = s, f = document.createElement("vf-dialog");
|
|
11
|
+
f.frame = "plain", f.label = d, f.width = l, f.height = 120;
|
|
12
|
+
let p = u ? 64 : n;
|
|
13
|
+
if (u) {
|
|
14
|
+
let e = document.createElement("vf-img");
|
|
15
|
+
e.width = r, e.height = r, e.left = n, e.top = n;
|
|
16
|
+
let t = document.createElement("img");
|
|
17
|
+
t.src = u, t.alt = "", e.append(t), f.append(e);
|
|
18
|
+
}
|
|
19
|
+
let m = document.createElement("vf-paragraph");
|
|
20
|
+
m.face = "display", m.width = l - t - p - n, m.left = p, m.top = n, m.textContent = o, f.append(m);
|
|
21
|
+
let h = document.createElement("vf-button-group");
|
|
22
|
+
h.origin = "bottom right";
|
|
23
|
+
let g = c.map((e) => {
|
|
24
|
+
let t = document.createElement("vf-button");
|
|
25
|
+
return t.textContent = e.label, t.dataset.value = e.value, e.default && (t.variant = "default"), t;
|
|
26
|
+
});
|
|
27
|
+
h.append(...g), f.append(h), a.append(f), await Promise.all([
|
|
28
|
+
f.updateComplete,
|
|
29
|
+
m.updateComplete,
|
|
30
|
+
h.updateComplete
|
|
31
|
+
]);
|
|
32
|
+
let _ = Math.ceil(m.getBoundingClientRect().height / e(m)), v = Math.max(u ? 48 : 0, n + _) + n + i + n;
|
|
33
|
+
return f.height = v + t, h.left = l - t - n, h.top = v - n, new Promise((e) => {
|
|
34
|
+
let t = null;
|
|
35
|
+
for (let e of g) e.addEventListener("click", () => {
|
|
36
|
+
t = e.dataset.value ?? null, f.close();
|
|
37
|
+
});
|
|
38
|
+
f.addEventListener("vf-close", () => {
|
|
39
|
+
f.remove(), e(t);
|
|
40
|
+
}, { once: !0 }), f.show();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { a as showAlert };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalog: what is where. Pure and DOM-free — it runs under Node — and
|
|
3
|
+
* the source of truth for what a folder holds; the Finder renders it.
|
|
4
|
+
*
|
|
5
|
+
* - An item is a small record: a name, a kind, the container it sits in
|
|
6
|
+
* (`parent`, a folder's id, or null for the desktop) and, once placed, its
|
|
7
|
+
* position there in whole system px. A kind keeps small data of its own in
|
|
8
|
+
* `data`; a large payload stays in its application's own store, keyed by
|
|
9
|
+
* the item's id, and the kind's `copy` and `onRemove` keep that store in
|
|
10
|
+
* step.
|
|
11
|
+
* - Volumes are containers no one made: the Trash and a startup disk, each
|
|
12
|
+
* if the page wants one. They lead the listing, keep their names, and are
|
|
13
|
+
* never renamed, moved, copied or removed; nothing is made in the Trash.
|
|
14
|
+
* Deleting is a move into the Trash, and only Empty Trash removes. A
|
|
15
|
+
* volume's position is stored on a record of its own id.
|
|
16
|
+
* - A folder never goes into itself or a folder inside it. A parent with no
|
|
17
|
+
* record reads as the desktop.
|
|
18
|
+
* - An item whose kind no application registers is left out of the listing
|
|
19
|
+
* and kept in storage.
|
|
20
|
+
* - Storage is three calls over item records (list, put, remove). The
|
|
21
|
+
* catalog holds every record in memory, writes through to storage, and
|
|
22
|
+
* lists from memory; a position change writes after a short delay, since
|
|
23
|
+
* the resize rule moves every desktop icon on each resize event.
|
|
24
|
+
* - A seed runs once per storage: a persistent one stores a marker record
|
|
25
|
+
* (`#seeded`), so a site that starts in memory and switches its storage
|
|
26
|
+
* seeds once there.
|
|
27
|
+
*/
|
|
28
|
+
import type { Point } from './geometry.js';
|
|
29
|
+
/** The Trash's id. */
|
|
30
|
+
export declare const TRASH = "trash";
|
|
31
|
+
/** The startup disk's id. */
|
|
32
|
+
export declare const DISK = "disk";
|
|
33
|
+
/** A folder's kind. */
|
|
34
|
+
export declare const FOLDER = "folder";
|
|
35
|
+
/** The name a new folder takes, counted up where it is taken. */
|
|
36
|
+
export declare const UNTITLED_FOLDER = "untitled folder";
|
|
37
|
+
/** One item of the catalog. */
|
|
38
|
+
export interface Item {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
/** `folder`, a volume's (`trash`, `disk`), or a kind an application registers. */
|
|
42
|
+
kind: string;
|
|
43
|
+
/** A folder's id, a volume's, or null for the desktop. */
|
|
44
|
+
parent: string | null;
|
|
45
|
+
/** Its place in its container, whole system px; unset, the next free cell. */
|
|
46
|
+
left?: number;
|
|
47
|
+
top?: number;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
modifiedAt: number;
|
|
50
|
+
/** The kind's own, small and serializable. */
|
|
51
|
+
data?: unknown;
|
|
52
|
+
}
|
|
53
|
+
/** The listing: volumes first, then every listed item by creation. */
|
|
54
|
+
export interface CatalogState {
|
|
55
|
+
/** Whether storage answers. Without it the catalog lists the volumes alone. */
|
|
56
|
+
available: boolean;
|
|
57
|
+
items: readonly Item[];
|
|
58
|
+
}
|
|
59
|
+
/** Where item records live. Any object with these three calls will do. */
|
|
60
|
+
export interface CatalogStorage {
|
|
61
|
+
list(): Promise<Item[]>;
|
|
62
|
+
put(item: Item): Promise<unknown>;
|
|
63
|
+
remove(id: string): Promise<unknown>;
|
|
64
|
+
}
|
|
65
|
+
/** What a kind tells the catalog about its items' payloads. */
|
|
66
|
+
export interface KindHooks {
|
|
67
|
+
/** Bytes, for Empty Trash's alert. */
|
|
68
|
+
size?(item: Item): number;
|
|
69
|
+
/** Copy `from`'s payload to `to`, a fresh copy of it. */
|
|
70
|
+
copy?(from: Item, to: Item): void | Promise<void>;
|
|
71
|
+
/** Empty Trash removed the item: drop its payload. */
|
|
72
|
+
onRemove?(item: Item): void | Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/** The volumes a page wants, by name; `false` or unset is none (the Trash defaults on). */
|
|
75
|
+
export interface Volumes {
|
|
76
|
+
trash?: string | false;
|
|
77
|
+
disk?: string | false;
|
|
78
|
+
}
|
|
79
|
+
export interface CatalogOptions {
|
|
80
|
+
storage: CatalogStorage | null;
|
|
81
|
+
volumes?: Volumes;
|
|
82
|
+
/** Whether an application registers `kind`. Folders are always listed. Default: every kind. */
|
|
83
|
+
listed?(kind: string): boolean;
|
|
84
|
+
/** A kind's payload hooks. */
|
|
85
|
+
hooks?(kind: string): KindHooks | undefined;
|
|
86
|
+
now?(): number;
|
|
87
|
+
newId?(): string;
|
|
88
|
+
/** How long a position change waits before it is written, ms. Default 400. */
|
|
89
|
+
placeDelay?: number;
|
|
90
|
+
}
|
|
91
|
+
/** What an operation makes: the new item, or null where it was refused. */
|
|
92
|
+
export interface NewItem {
|
|
93
|
+
name?: string;
|
|
94
|
+
kind?: string;
|
|
95
|
+
parent?: string | null;
|
|
96
|
+
left?: number;
|
|
97
|
+
top?: number;
|
|
98
|
+
data?: unknown;
|
|
99
|
+
/** The creation time, for a batch made in order. Default now. */
|
|
100
|
+
at?: number;
|
|
101
|
+
}
|
|
102
|
+
/** A catalog dumped or restored: its item records. */
|
|
103
|
+
export interface CatalogArchive {
|
|
104
|
+
items: Item[];
|
|
105
|
+
}
|
|
106
|
+
/** Whether `kind` holds other items: a folder or a volume. */
|
|
107
|
+
export declare const isContainerKind: (kind: string) => boolean;
|
|
108
|
+
/** Whether `id` names a volume. */
|
|
109
|
+
export declare const isVolume: (id: string | null | undefined) => boolean;
|
|
110
|
+
/** The item with `id`, or null. */
|
|
111
|
+
export declare function itemOf(state: CatalogState, id: string | null | undefined): Item | null;
|
|
112
|
+
/** The container `parent` resolves to: that container while it is listed, else the desktop (null). */
|
|
113
|
+
export declare function containerOf(state: CatalogState, parent: string | null | undefined): string | null;
|
|
114
|
+
/** The items directly in a container (null: the desktop), in listing order. */
|
|
115
|
+
export declare function childrenOf(state: CatalogState, parent: string | null): Item[];
|
|
116
|
+
/** How many items a container holds directly. */
|
|
117
|
+
export declare function itemCount(state: CatalogState, parent: string | null): number;
|
|
118
|
+
/**
|
|
119
|
+
* Whether `ancestor` is on `id`'s chain of containers. An item is not inside
|
|
120
|
+
* itself; a looping chain stops at its first repeat.
|
|
121
|
+
*/
|
|
122
|
+
export declare function isInside(state: CatalogState, id: string, ancestor: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Container `id` and the containers around it, innermost first. The desktop
|
|
125
|
+
* ends the chain, and so does an id with no container; a loop stops at its
|
|
126
|
+
* first repeat.
|
|
127
|
+
*/
|
|
128
|
+
export declare function enclosingFolders(state: CatalogState, id: string | null | undefined): string[];
|
|
129
|
+
/** Whether `id` is the Trash or anything inside it. */
|
|
130
|
+
export declare function isTrashed(state: CatalogState, id: string | null | undefined): boolean;
|
|
131
|
+
/** Everything under a container, each container before what it holds; a loop is walked once. */
|
|
132
|
+
export declare function descendantsOf(state: CatalogState, parent: string | null): Item[];
|
|
133
|
+
/** The first free folder name in a container: "untitled folder", "untitled folder 2", … */
|
|
134
|
+
export declare function nextFolderName(state: CatalogState, parent: string | null): string;
|
|
135
|
+
/**
|
|
136
|
+
* The name for a copy in a container: `name` itself while no item of its
|
|
137
|
+
* kind there has it, else its base (less " copy" and " copy N") plus " copy",
|
|
138
|
+
* then " copy 2", " copy 3", …
|
|
139
|
+
*/
|
|
140
|
+
export declare function copyName(state: CatalogState, parent: string | null, name: string, kind: string): string;
|
|
141
|
+
/** The catalog's operations, over its listing. */
|
|
142
|
+
export interface Catalog {
|
|
143
|
+
get(): CatalogState;
|
|
144
|
+
subscribe(fn: (state: CatalogState) => void): () => void;
|
|
145
|
+
item(id: string | null | undefined): Item | null;
|
|
146
|
+
refresh(): Promise<void>;
|
|
147
|
+
seed(fn: (catalog: Catalog) => void | Promise<void>): Promise<boolean>;
|
|
148
|
+
create(input?: NewItem): Promise<Item | null>;
|
|
149
|
+
rename(id: string, name: string): Promise<boolean>;
|
|
150
|
+
update(id: string, data: unknown): Promise<boolean>;
|
|
151
|
+
move(ids: readonly string[], parent: string | null, landings?: ReadonlyMap<string, Point | null>): Promise<string[]>;
|
|
152
|
+
place(positions: ReadonlyMap<string, Point>): void;
|
|
153
|
+
flush(): Promise<void>;
|
|
154
|
+
copy(ids: readonly string[], parent: string | null): Promise<Item[]>;
|
|
155
|
+
emptyTrash(): Promise<Item[]>;
|
|
156
|
+
trashSize(): number;
|
|
157
|
+
dump(): CatalogArchive;
|
|
158
|
+
clear(): Promise<void>;
|
|
159
|
+
import(archive: CatalogArchive, options?: {
|
|
160
|
+
mode?: 'merge' | 'replace';
|
|
161
|
+
}): Promise<number>;
|
|
162
|
+
dispose(): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
export declare function createCatalog(options: CatalogOptions): Catalog;
|
|
165
|
+
/** Storage that forgets everything on a reload. Its map is exposed for tests. */
|
|
166
|
+
export declare function memoryStorage(initial?: readonly Item[]): CatalogStorage & {
|
|
167
|
+
records: Map<string, Item>;
|
|
168
|
+
};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//#region src/shell/catalog.ts
|
|
2
|
+
var e = "trash", t = "disk", n = "folder", r = "untitled folder", i = "#seeded", a = (e) => e === "folder" || e === "trash" || e === "disk", o = (e) => e === "trash" || e === "disk";
|
|
3
|
+
function s(e, t) {
|
|
4
|
+
return t == null ? null : e.items.find((e) => e.id === t) ?? null;
|
|
5
|
+
}
|
|
6
|
+
function c(e, t) {
|
|
7
|
+
let n = s(e, t);
|
|
8
|
+
return n && a(n.kind) ? n.id : null;
|
|
9
|
+
}
|
|
10
|
+
function l(e, t) {
|
|
11
|
+
let n = c(e, t);
|
|
12
|
+
return e.items.filter((t) => t.id !== n && c(e, t.parent) === n);
|
|
13
|
+
}
|
|
14
|
+
function u(e, t) {
|
|
15
|
+
return l(e, t).length;
|
|
16
|
+
}
|
|
17
|
+
var d = (e, t) => c(e, s(e, t)?.parent ?? null);
|
|
18
|
+
function f(e, t, n) {
|
|
19
|
+
let r = /* @__PURE__ */ new Set(), i = d(e, t);
|
|
20
|
+
for (; i != null && !r.has(i);) {
|
|
21
|
+
if (i === n) return !0;
|
|
22
|
+
r.add(i), i = d(e, i);
|
|
23
|
+
}
|
|
24
|
+
return !1;
|
|
25
|
+
}
|
|
26
|
+
function p(e, t) {
|
|
27
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = c(e, t ?? null);
|
|
28
|
+
for (; i != null && !r.has(i);) n.push(i), r.add(i), i = d(e, i);
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
function m(e, t) {
|
|
32
|
+
return t == null ? !1 : t === "trash" || f(e, t, "trash");
|
|
33
|
+
}
|
|
34
|
+
function h(e, t) {
|
|
35
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = (t) => {
|
|
36
|
+
for (let o of l(e, t)) r.has(o.id) || (r.add(o.id), n.push(o), a(o.kind) && i(o.id));
|
|
37
|
+
};
|
|
38
|
+
return i(c(e, t)), n;
|
|
39
|
+
}
|
|
40
|
+
function g(e, t) {
|
|
41
|
+
let i = new Set(l(e, t).filter((e) => e.kind === n).map((e) => e.name));
|
|
42
|
+
if (!i.has("untitled folder")) return r;
|
|
43
|
+
for (let e = 2;; e++) {
|
|
44
|
+
let t = `${r} ${e}`;
|
|
45
|
+
if (!i.has(t)) return t;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var _ = (e) => e.replace(/ copy( \d+)?$/, "");
|
|
49
|
+
function v(e, t, n, r) {
|
|
50
|
+
let i = new Set(l(e, t).filter((e) => e.kind === r).map((e) => e.name));
|
|
51
|
+
if (!i.has(n)) return n;
|
|
52
|
+
let a = _(n);
|
|
53
|
+
if (!i.has(`${a} copy`)) return `${a} copy`;
|
|
54
|
+
for (let e = 2;; e++) {
|
|
55
|
+
let t = `${a} copy ${e}`;
|
|
56
|
+
if (!i.has(t)) return t;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var y = (e, t) => e.createdAt - t.createdAt || (e.id < t.id ? -1 : 1);
|
|
60
|
+
function b(e, t) {
|
|
61
|
+
let n = { ...e };
|
|
62
|
+
return t ? (n.left = t.left, n.top = t.top) : (delete n.left, delete n.top), n;
|
|
63
|
+
}
|
|
64
|
+
function x(n) {
|
|
65
|
+
let { storage: r, volumes: l = {}, listed: u = () => !0, hooks: d = () => void 0, placeDelay: p = 400 } = n, _ = () => (n.now ?? Date.now)(), x = () => n.newId ? n.newId() : crypto.randomUUID(), S = [];
|
|
66
|
+
l.disk && S.push({
|
|
67
|
+
id: t,
|
|
68
|
+
name: l.disk,
|
|
69
|
+
kind: t,
|
|
70
|
+
parent: null,
|
|
71
|
+
createdAt: 0,
|
|
72
|
+
modifiedAt: 0
|
|
73
|
+
}), l.trash !== !1 && S.push({
|
|
74
|
+
id: e,
|
|
75
|
+
name: l.trash ?? "Trash",
|
|
76
|
+
kind: e,
|
|
77
|
+
parent: null,
|
|
78
|
+
createdAt: 0,
|
|
79
|
+
modifiedAt: 0
|
|
80
|
+
});
|
|
81
|
+
let C = /* @__PURE__ */ new Map(), w = !1, T = !1, E = O(), D = /* @__PURE__ */ new Set();
|
|
82
|
+
function O() {
|
|
83
|
+
let e = S.map((e) => {
|
|
84
|
+
let t = C.get(e.id);
|
|
85
|
+
return t?.left != null && t.top != null ? {
|
|
86
|
+
...e,
|
|
87
|
+
left: t.left,
|
|
88
|
+
top: t.top
|
|
89
|
+
} : e;
|
|
90
|
+
}), t = [...C.values()].filter((e) => !o(e.id) && (e.kind === "folder" || u(e.kind))).sort(y);
|
|
91
|
+
return {
|
|
92
|
+
available: w,
|
|
93
|
+
items: [...e, ...t]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function k() {
|
|
97
|
+
E = O();
|
|
98
|
+
for (let e of [...D]) e(E);
|
|
99
|
+
}
|
|
100
|
+
let A = () => {
|
|
101
|
+
if (!r) throw Error("storage is unavailable");
|
|
102
|
+
return r;
|
|
103
|
+
};
|
|
104
|
+
async function j(e) {
|
|
105
|
+
await A().put(e), C.set(e.id, e);
|
|
106
|
+
}
|
|
107
|
+
let M = /* @__PURE__ */ new Set(), N = null;
|
|
108
|
+
async function P() {
|
|
109
|
+
N && clearTimeout(N), N = null;
|
|
110
|
+
let e = [...M];
|
|
111
|
+
if (M.clear(), !(!r || !w)) for (let t of e) {
|
|
112
|
+
let e = C.get(t);
|
|
113
|
+
e && await r.put(e).catch(() => {});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let F = (e) => {
|
|
117
|
+
let t = S.find((t) => t.id === e);
|
|
118
|
+
return C.get(e) ?? {
|
|
119
|
+
...t,
|
|
120
|
+
name: ""
|
|
121
|
+
};
|
|
122
|
+
}, I = {
|
|
123
|
+
get: () => E,
|
|
124
|
+
subscribe(e) {
|
|
125
|
+
return D.add(e), () => {
|
|
126
|
+
D.delete(e);
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
item: (e) => s(E, e),
|
|
130
|
+
async refresh() {
|
|
131
|
+
if (!r) {
|
|
132
|
+
C = /* @__PURE__ */ new Map(), w = !1, k();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
let e = await r.list();
|
|
137
|
+
C = /* @__PURE__ */ new Map(), T = !1;
|
|
138
|
+
for (let t of e) t.id === i ? T = !0 : C.set(t.id, t);
|
|
139
|
+
w = !0;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.warn("vintage-frames/shell: the catalog could not be read —", e), C = /* @__PURE__ */ new Map(), w = !1;
|
|
142
|
+
}
|
|
143
|
+
k();
|
|
144
|
+
},
|
|
145
|
+
async seed(e) {
|
|
146
|
+
return !r || !w || T ? !1 : (await e(I), await r.put({
|
|
147
|
+
id: i,
|
|
148
|
+
name: "",
|
|
149
|
+
kind: i,
|
|
150
|
+
parent: null,
|
|
151
|
+
createdAt: _(),
|
|
152
|
+
modifiedAt: _()
|
|
153
|
+
}), T = !0, !0);
|
|
154
|
+
},
|
|
155
|
+
async create(e = {}) {
|
|
156
|
+
let t = c(E, e.parent ?? null);
|
|
157
|
+
if (m(E, t)) return null;
|
|
158
|
+
let n = e.kind ?? "folder", r = e.at ?? _(), i = {
|
|
159
|
+
id: x(),
|
|
160
|
+
name: e.name ?? (n === "folder" ? g(E, t) : "untitled"),
|
|
161
|
+
kind: n,
|
|
162
|
+
parent: t,
|
|
163
|
+
createdAt: r,
|
|
164
|
+
modifiedAt: r
|
|
165
|
+
};
|
|
166
|
+
return e.data !== void 0 && (i.data = e.data), e.left != null && e.top != null && (i = b(i, {
|
|
167
|
+
left: e.left,
|
|
168
|
+
top: e.top
|
|
169
|
+
})), await j(i), k(), i;
|
|
170
|
+
},
|
|
171
|
+
async rename(e, t) {
|
|
172
|
+
let n = C.get(e);
|
|
173
|
+
return !n || o(e) || n.name === t ? !1 : (await j({
|
|
174
|
+
...n,
|
|
175
|
+
name: t,
|
|
176
|
+
modifiedAt: _()
|
|
177
|
+
}), k(), !0);
|
|
178
|
+
},
|
|
179
|
+
async update(e, t) {
|
|
180
|
+
let n = C.get(e);
|
|
181
|
+
return !n || o(e) ? !1 : (await j({
|
|
182
|
+
...n,
|
|
183
|
+
data: t,
|
|
184
|
+
modifiedAt: _()
|
|
185
|
+
}), k(), !0);
|
|
186
|
+
},
|
|
187
|
+
async move(e, t, n) {
|
|
188
|
+
let r = c(E, t), i = [];
|
|
189
|
+
for (let t of e) {
|
|
190
|
+
let e = C.get(t);
|
|
191
|
+
!e || o(t) || r === t || r != null && a(e.kind) && f(E, r, t) || c(E, e.parent) !== r && (M.delete(t), await j(b({
|
|
192
|
+
...e,
|
|
193
|
+
parent: r
|
|
194
|
+
}, n?.get(t) ?? null)), i.push(t));
|
|
195
|
+
}
|
|
196
|
+
return i.length && k(), i;
|
|
197
|
+
},
|
|
198
|
+
place(e) {
|
|
199
|
+
let t = !1;
|
|
200
|
+
for (let [n, r] of e) {
|
|
201
|
+
let e = o(n) ? S.some((e) => e.id === n) ? F(n) : null : C.get(n);
|
|
202
|
+
!e || e.left === r.left && e.top === r.top || (C.set(n, b(e, r)), M.add(n), t = !0);
|
|
203
|
+
}
|
|
204
|
+
t && (k(), N && clearTimeout(N), N = setTimeout(() => void P(), p));
|
|
205
|
+
},
|
|
206
|
+
flush: P,
|
|
207
|
+
async copy(e, t) {
|
|
208
|
+
let n = c(E, t);
|
|
209
|
+
if (m(E, n)) return [];
|
|
210
|
+
let r = [];
|
|
211
|
+
for (let t of e) {
|
|
212
|
+
let e = s(E, t);
|
|
213
|
+
if (!e || o(t)) continue;
|
|
214
|
+
let i = a(e.kind) ? h(E, t) : [], l = /* @__PURE__ */ new Map(), u = async (e, t, n) => {
|
|
215
|
+
let r = _(), i = {
|
|
216
|
+
...e,
|
|
217
|
+
id: x(),
|
|
218
|
+
name: n ? v(E, t, e.name, e.kind) : e.name,
|
|
219
|
+
parent: t,
|
|
220
|
+
createdAt: r,
|
|
221
|
+
modifiedAt: r
|
|
222
|
+
};
|
|
223
|
+
return n && (i = b(i, null)), l.set(e.id, i.id), await j(i), await d(e.kind)?.copy?.(e, i), i;
|
|
224
|
+
};
|
|
225
|
+
r.push(await u(e, n, !0));
|
|
226
|
+
for (let e of i) await u(e, l.get(c(E, e.parent) ?? "") ?? null, !1);
|
|
227
|
+
k();
|
|
228
|
+
}
|
|
229
|
+
return r;
|
|
230
|
+
},
|
|
231
|
+
async emptyTrash() {
|
|
232
|
+
let t = h(E, e);
|
|
233
|
+
for (let e of t) await A().remove(e.id), C.delete(e.id), M.delete(e.id), await d(e.kind)?.onRemove?.(e);
|
|
234
|
+
return t.length && k(), t;
|
|
235
|
+
},
|
|
236
|
+
trashSize() {
|
|
237
|
+
return h(E, e).reduce((e, t) => e + (d(t.kind)?.size?.(t) ?? 0), 0);
|
|
238
|
+
},
|
|
239
|
+
dump() {
|
|
240
|
+
return { items: [...C.values()] };
|
|
241
|
+
},
|
|
242
|
+
async clear() {
|
|
243
|
+
if (r) {
|
|
244
|
+
for (let e of await r.list()) e.id !== i && await r.remove(e.id);
|
|
245
|
+
C = /* @__PURE__ */ new Map(), M.clear(), k();
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
async import(e, { mode: t = "merge" } = {}) {
|
|
249
|
+
let n = e.items.filter((e) => e.id !== i && !o(e.id));
|
|
250
|
+
if (!n.length || !r) return 0;
|
|
251
|
+
let a = t === "replace", s = /* @__PURE__ */ new Map();
|
|
252
|
+
for (let e of n) s.set(e.id, a ? e.id : x());
|
|
253
|
+
let c = (e) => e == null || o(e) ? e : s.get(e) ?? null;
|
|
254
|
+
a && await I.clear();
|
|
255
|
+
for (let e of n) await j({
|
|
256
|
+
...e,
|
|
257
|
+
id: s.get(e.id),
|
|
258
|
+
parent: c(e.parent)
|
|
259
|
+
});
|
|
260
|
+
return k(), n.length;
|
|
261
|
+
},
|
|
262
|
+
async dispose() {
|
|
263
|
+
await P(), D.clear();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
return I;
|
|
267
|
+
}
|
|
268
|
+
function S(e = []) {
|
|
269
|
+
let t = new Map(e.map((e) => [e.id, e]));
|
|
270
|
+
return {
|
|
271
|
+
records: t,
|
|
272
|
+
list: async () => [...t.values()],
|
|
273
|
+
put: async (e) => t.set(e.id, e),
|
|
274
|
+
remove: async (e) => t.delete(e)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
export { t as DISK, n as FOLDER, e as TRASH, r as UNTITLED_FOLDER, l as childrenOf, c as containerOf, v as copyName, x as createCatalog, h as descendantsOf, p as enclosingFolders, a as isContainerKind, f as isInside, m as isTrashed, o as isVolume, u as itemCount, s as itemOf, S as memoryStorage, g as nextFolderName };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The menu bar's clock: a label in the bar's `end` slot showing the time,
|
|
3
|
+
* updated on the minute. A press shows the date for a few seconds; a second
|
|
4
|
+
* press returns to the time early.
|
|
5
|
+
*/
|
|
6
|
+
/** How long a press shows the date, ms. */
|
|
7
|
+
export declare const DATE_HOLD_MS = 3000;
|
|
8
|
+
/** "7:27 PM": 12-hour local time. */
|
|
9
|
+
export declare function formatTime(d: Date): string;
|
|
10
|
+
/** "9/27/26": M/D/YY local date. */
|
|
11
|
+
export declare function formatDate(d: Date): string;
|
|
12
|
+
/** Render the clock into `label` now and on every minute boundary. Returns the stop function. */
|
|
13
|
+
export declare function startClock(label: HTMLElement, { now, holdMs }?: {
|
|
14
|
+
now?: () => number;
|
|
15
|
+
holdMs?: number;
|
|
16
|
+
}): () => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/shell/clock.ts
|
|
2
|
+
var e = 3e3, t = (e) => String(e).padStart(2, "0");
|
|
3
|
+
function n(e) {
|
|
4
|
+
let n = e.getHours();
|
|
5
|
+
return `${n % 12 || 12}:${t(e.getMinutes())} ${n < 12 ? "AM" : "PM"}`;
|
|
6
|
+
}
|
|
7
|
+
function r(e) {
|
|
8
|
+
return `${e.getMonth() + 1}/${e.getDate()}/${t(e.getFullYear() % 100)}`;
|
|
9
|
+
}
|
|
10
|
+
function i(t, { now: i = Date.now, holdMs: a = e } = {}) {
|
|
11
|
+
let o = !1, s = 0, c = 0, l = () => {
|
|
12
|
+
let e = new Date(i());
|
|
13
|
+
t.textContent = o ? r(e) : n(e);
|
|
14
|
+
}, u = () => {
|
|
15
|
+
c = window.setTimeout(() => {
|
|
16
|
+
l(), u();
|
|
17
|
+
}, 6e4 - i() % 6e4 + 20);
|
|
18
|
+
}, d = () => {
|
|
19
|
+
clearTimeout(s), s = 0, o = !1, l();
|
|
20
|
+
}, f = (e) => {
|
|
21
|
+
if (e.button === 0) {
|
|
22
|
+
if (e.preventDefault(), o) {
|
|
23
|
+
d();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
o = !0, l(), s = window.setTimeout(d, a);
|
|
27
|
+
}
|
|
28
|
+
}, p = () => {
|
|
29
|
+
document.hidden || l();
|
|
30
|
+
};
|
|
31
|
+
return l(), u(), t.addEventListener("pointerdown", f), document.addEventListener("visibilitychange", p), () => {
|
|
32
|
+
clearTimeout(c), clearTimeout(s), t.removeEventListener("pointerdown", f), document.removeEventListener("visibilitychange", p);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { e as DATE_HOLD_MS, r as formatDate, n as formatTime, i as startClock };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filing by drag: what a drop of icons means. A drop onto a folder icon
|
|
3
|
+
* files the icons into that folder at its next free cells; a drop into a
|
|
4
|
+
* folder window lands each icon where its outline was let go; a drop out of
|
|
5
|
+
* a window onto the desktop the same. The folder under the pointer wears
|
|
6
|
+
* `target`. A folder never goes into itself or a folder inside it, and a
|
|
7
|
+
* drop over another application's window moves nothing. A drop inside the
|
|
8
|
+
* icons' own field is the kit's: its default action moves them there.
|
|
9
|
+
*
|
|
10
|
+
* The Finder runs it over its catalog; a page of its own can run it over the
|
|
11
|
+
* DOM, with callbacks that say what a container is and what filing does.
|
|
12
|
+
*/
|
|
13
|
+
import type { VfDesktop, VfIcon, VfWindow } from '../index.js';
|
|
14
|
+
import type { Point } from './geometry.js';
|
|
15
|
+
/** What filing needs to know, and what it does. */
|
|
16
|
+
export interface FilingOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The container a window shows — a folder's id — or undefined for a
|
|
19
|
+
* window that holds no icons of the page's: a drop over it moves nothing.
|
|
20
|
+
*/
|
|
21
|
+
folderOfWindow(win: VfWindow): string | undefined;
|
|
22
|
+
/** The container a folder icon opens — its folder's id — or undefined for any other icon. */
|
|
23
|
+
folderOfIcon(icon: VfIcon): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The container an icon sits in: a folder's id, or null for the desktop.
|
|
26
|
+
* Undefined for an icon filing leaves alone, another application's: its
|
|
27
|
+
* drags go by.
|
|
28
|
+
*/
|
|
29
|
+
containerOf(icon: VfIcon): string | null | undefined;
|
|
30
|
+
/** Whether `icons` may go into `folder` (null: the desktop). */
|
|
31
|
+
canFile(icons: VfIcon[], folder: string | null): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* File the icons into `folder` (null: the desktop), each at its landing
|
|
34
|
+
* there in whole system px, or null for the folder's next free cell.
|
|
35
|
+
*/
|
|
36
|
+
file(icons: VfIcon[], folder: string | null, landings: Map<VfIcon, Point | null>): void;
|
|
37
|
+
}
|
|
38
|
+
/** Wire filing by drag on a desktop. Returns the teardown. */
|
|
39
|
+
export declare function fileByDrag(desktop: VfDesktop, options: FilingOptions): () => void;
|