@alulore/kumiko 0.15.1 → 0.17.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.
Files changed (91) hide show
  1. package/dist/media-viewer/icons.d.ts +4 -0
  2. package/dist/media-viewer/icons.js +18 -0
  3. package/dist/media-viewer/index.d.ts +4 -0
  4. package/dist/media-viewer/index.js +3 -0
  5. package/dist/media-viewer/media-slide.d.ts +14 -0
  6. package/dist/media-viewer/media-slide.js +67 -0
  7. package/dist/media-viewer/media-viewer.css +611 -0
  8. package/dist/media-viewer/media-viewer.d.ts +17 -0
  9. package/dist/media-viewer/media-viewer.js +241 -0
  10. package/dist/media-viewer/pager-drag.d.ts +10 -0
  11. package/dist/media-viewer/pager-drag.js +53 -0
  12. package/dist/media-viewer/types.d.ts +58 -0
  13. package/dist/media-viewer/types.js +17 -0
  14. package/dist/media-viewer/video-controls.d.ts +3 -0
  15. package/dist/media-viewer/video-controls.js +62 -0
  16. package/dist/media-viewer/view-gesture.d.ts +74 -0
  17. package/dist/media-viewer/view-gesture.js +465 -0
  18. package/dist/media-viewer/viewer-chrome.d.ts +13 -0
  19. package/dist/media-viewer/viewer-chrome.js +35 -0
  20. package/dist/media-viewer/viewer-motion.d.ts +9 -0
  21. package/dist/media-viewer/viewer-motion.js +126 -0
  22. package/dist/media-viewer/zoom-pan.d.ts +35 -0
  23. package/dist/media-viewer/zoom-pan.js +102 -0
  24. package/dist/shortcuts/bindings.d.ts +44 -0
  25. package/dist/shortcuts/bindings.js +71 -0
  26. package/dist/shortcuts/capture.d.ts +7 -0
  27. package/dist/shortcuts/capture.js +92 -0
  28. package/dist/shortcuts/guard.d.ts +9 -0
  29. package/dist/shortcuts/guard.js +48 -0
  30. package/dist/shortcuts/help.d.ts +25 -0
  31. package/dist/shortcuts/help.js +26 -0
  32. package/dist/shortcuts/hints.d.ts +19 -0
  33. package/dist/shortcuts/hints.js +33 -0
  34. package/dist/shortcuts/index.d.ts +11 -0
  35. package/dist/shortcuts/index.js +11 -0
  36. package/dist/shortcuts/judge.d.ts +42 -0
  37. package/dist/shortcuts/judge.js +34 -0
  38. package/dist/shortcuts/keys.d.ts +11 -0
  39. package/dist/shortcuts/keys.js +89 -0
  40. package/dist/shortcuts/list.d.ts +16 -0
  41. package/dist/shortcuts/list.js +43 -0
  42. package/dist/shortcuts/notes.d.ts +28 -0
  43. package/dist/shortcuts/notes.js +27 -0
  44. package/dist/shortcuts/provider.d.ts +98 -0
  45. package/dist/shortcuts/provider.js +116 -0
  46. package/dist/shortcuts/rebinder.d.ts +23 -0
  47. package/dist/shortcuts/rebinder.js +84 -0
  48. package/dist/shortcuts/registration.d.ts +19 -0
  49. package/dist/shortcuts/registration.js +84 -0
  50. package/dist/shortcuts/shortcuts.css +171 -0
  51. package/dist/stored/index.d.ts +4 -0
  52. package/dist/stored/index.js +4 -0
  53. package/dist/stored/storage.d.ts +22 -0
  54. package/dist/stored/storage.js +10 -0
  55. package/dist/stored/stored.d.ts +93 -0
  56. package/dist/stored/stored.js +209 -0
  57. package/dist/stored/use-stored.d.ts +6 -0
  58. package/dist/stored/use-stored.js +12 -0
  59. package/dist/stored/validators.d.ts +6 -0
  60. package/dist/stored/validators.js +13 -0
  61. package/dist/titlebar/index.d.ts +2 -0
  62. package/dist/titlebar/index.js +2 -0
  63. package/dist/titlebar/titlebar-looks.d.ts +53 -0
  64. package/dist/titlebar/titlebar-looks.js +26 -0
  65. package/dist/titlebar/titlebar.css +561 -0
  66. package/dist/titlebar/titlebar.d.ts +54 -0
  67. package/dist/titlebar/titlebar.js +68 -0
  68. package/dist/undo/history.d.ts +62 -0
  69. package/dist/undo/history.js +151 -0
  70. package/dist/undo/index.d.ts +10 -0
  71. package/dist/undo/index.js +10 -0
  72. package/dist/undo/undo-adapter.d.ts +35 -0
  73. package/dist/undo/undo-adapter.js +35 -0
  74. package/dist/undo/undo-feedback.d.ts +28 -0
  75. package/dist/undo/undo-feedback.js +69 -0
  76. package/dist/undo/undo-keys.d.ts +32 -0
  77. package/dist/undo/undo-keys.js +76 -0
  78. package/dist/undo/undo-options.d.ts +51 -0
  79. package/dist/undo/undo-options.js +6 -0
  80. package/dist/undo/undo-panel.d.ts +23 -0
  81. package/dist/undo/undo-panel.js +56 -0
  82. package/dist/undo/undo-provider.d.ts +88 -0
  83. package/dist/undo/undo-provider.js +104 -0
  84. package/dist/undo/undo-reveal.d.ts +9 -0
  85. package/dist/undo/undo-reveal.js +45 -0
  86. package/dist/undo/undo-store.d.ts +89 -0
  87. package/dist/undo/undo-store.js +243 -0
  88. package/dist/undo/undo.css +135 -0
  89. package/dist/undo/use-undo-value.d.ts +43 -0
  90. package/dist/undo/use-undo-value.js +85 -0
  91. package/package.json +42 -1
@@ -0,0 +1,171 @@
1
+ @import "../motion/motion.css";
2
+
3
+ @layer kumiko {
4
+ :where(:root) {
5
+ --kumiko-shortcuts-gap: 0.6rem;
6
+ --kumiko-shortcuts-heading-fg: color-mix(in oklab, CanvasText 60%, Canvas);
7
+ --kumiko-shortcuts-row-border: color-mix(in oklab, CanvasText 12%, transparent);
8
+ --kumiko-shortcuts-accent: Highlight;
9
+ --kumiko-shortcuts-danger: #b42318;
10
+ --kumiko-shortcuts-panel-width: 24rem;
11
+ }
12
+
13
+ .kumiko-shortcuts-sheet {
14
+ display: flex;
15
+ flex-direction: column;
16
+ gap: var(--kumiko-shortcuts-gap);
17
+ font-size: 0.875rem;
18
+ }
19
+
20
+ .kumiko-shortcuts-sheet input[type="search"] {
21
+ padding: 0.4rem 0.6rem;
22
+ }
23
+
24
+ .kumiko-shortcuts-list section + section {
25
+ margin-block-start: var(--kumiko-shortcuts-gap);
26
+ }
27
+
28
+ .kumiko-shortcuts-list h3 {
29
+ margin: 0 0 0.25rem;
30
+ color: var(--kumiko-shortcuts-heading-fg);
31
+ font-size: 0.75rem;
32
+ font-weight: 600;
33
+ letter-spacing: 0.04em;
34
+ text-transform: uppercase;
35
+ }
36
+
37
+ .kumiko-shortcuts-list ul {
38
+ margin: 0;
39
+ padding: 0;
40
+ list-style: none;
41
+ }
42
+
43
+ .kumiko-shortcuts-list li {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: 0.35rem 0.75rem;
47
+ align-items: center;
48
+ justify-content: space-between;
49
+ padding: 0.4rem 0;
50
+ border-block-end: 1px solid var(--kumiko-shortcuts-row-border);
51
+ }
52
+
53
+ .kumiko-shortcuts-list li[data-unavailable] .kumiko-shortcuts-name {
54
+ opacity: 0.55;
55
+ }
56
+
57
+ .kumiko-shortcuts-keys,
58
+ .kumiko-shortcuts-editor {
59
+ display: flex;
60
+ flex-wrap: wrap;
61
+ gap: 0.35rem 0.5rem;
62
+ align-items: center;
63
+ }
64
+
65
+ .kumiko-shortcuts-key {
66
+ display: inline-flex;
67
+ gap: 0.25rem;
68
+ align-items: center;
69
+ padding: 0.15rem;
70
+ border-radius: 0.5rem;
71
+ }
72
+
73
+ .kumiko-shortcuts-key[data-changing] {
74
+ outline: 2px solid var(--kumiko-shortcuts-accent);
75
+ }
76
+
77
+ .kumiko-shortcuts-sheet button {
78
+ padding: 0.2rem 0.55rem;
79
+ border: 1px solid var(--kumiko-shortcuts-row-border);
80
+ border-radius: 0.5rem;
81
+ background: transparent;
82
+ color: inherit;
83
+ font: inherit;
84
+ font-size: 0.8125rem;
85
+ cursor: var(--kumiko-press-cursor, pointer);
86
+ }
87
+
88
+ @media (pointer: coarse) {
89
+ .kumiko-shortcuts-sheet button,
90
+ .kumiko-shortcuts-sheet input,
91
+ .kumiko-shortcuts-sheet select {
92
+ min-block-size: var(--kumiko-touch-target, 2.75rem);
93
+ }
94
+ }
95
+
96
+ .kumiko-shortcuts-capture-wrap {
97
+ flex-basis: 100%;
98
+ }
99
+
100
+ .kumiko-shortcuts-capture {
101
+ display: flex;
102
+ flex-wrap: wrap;
103
+ gap: 0.4rem 0.6rem;
104
+ align-items: center;
105
+ margin: 0;
106
+ padding: 0.5rem 0.6rem;
107
+ border: 1px dashed var(--kumiko-shortcuts-accent);
108
+ border-radius: 0.6rem;
109
+ }
110
+
111
+ .kumiko-shortcuts-capture p {
112
+ flex-basis: 100%;
113
+ margin: 0;
114
+ }
115
+
116
+ .kumiko-shortcuts-message {
117
+ margin: 0.3rem 0 0;
118
+ color: var(--kumiko-shortcuts-danger);
119
+ }
120
+
121
+ .kumiko-shortcuts-empty,
122
+ .kumiko-shortcuts-foot,
123
+ .kumiko-shortcuts-none {
124
+ margin: 0;
125
+ color: var(--kumiko-shortcuts-heading-fg);
126
+ }
127
+
128
+ :where([data-slot$="popover-content"].kumiko-shortcuts-popover) {
129
+ inline-size: min(26rem, 100dvw - 2rem);
130
+ max-block-size: 70dvh;
131
+ }
132
+
133
+ /* The panel sits against the inline-end edge and takes the page's full height. */
134
+ [data-slot$="dialog-content"].kumiko-shortcuts-dialog[data-kumiko-shortcuts="panel"]:not(
135
+ [data-presentation="sheet"]
136
+ ) {
137
+ inset-block: 0;
138
+ inset-inline: auto 0;
139
+ margin: 0;
140
+ inline-size: min(var(--kumiko-shortcuts-panel-width), 100dvw);
141
+ block-size: 100dvh;
142
+ max-block-size: 100dvh;
143
+ border-start-end-radius: 0;
144
+ border-end-end-radius: 0;
145
+ }
146
+
147
+ /* A key badge sits on the corner of its control and shows while the mod key is held. */
148
+ .kumiko-shortcuts-target {
149
+ position: relative;
150
+ display: inline-flex;
151
+ }
152
+
153
+ .kumiko-shortcuts-badge {
154
+ position: absolute;
155
+ inset-block-start: -0.7rem;
156
+ inset-inline-end: -0.4rem;
157
+ opacity: 0;
158
+ pointer-events: none;
159
+ transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
160
+ }
161
+
162
+ .kumiko-shortcuts-badge[data-shown] {
163
+ opacity: 1;
164
+ }
165
+
166
+ @media (forced-colors: active) {
167
+ .kumiko-shortcuts-key[data-changing] {
168
+ outline-color: Highlight;
169
+ }
170
+ }
171
+ }
@@ -0,0 +1,4 @@
1
+ export { backendFor, type StoredBackend, type StoredBackendFactory, type StoredStorage } from "./storage";
2
+ export { defineStored, type Stored, type StoredDefinition, type StoredFormat, type StoredInvalid, type StoredOptions, type StoredStatus, type StoredUpdate, type StoredWrites } from "./stored";
3
+ export { useStored } from "./use-stored";
4
+ export { isStringList, numberBetween, oneOf } from "./validators";
@@ -0,0 +1,4 @@
1
+ export { backendFor } from "./storage";
2
+ export { defineStored } from "./stored";
3
+ export { useStored } from "./use-stored";
4
+ export { isStringList, numberBetween, oneOf } from "./validators";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The narrow seam between a stored value and wherever it is kept. ui-sdk's
3
+ * `createLocalStorage(id)` and `createSessionStorage(id)` already fit it, and
4
+ * so does anything an app writes with the same four methods.
5
+ */
6
+ export interface StoredBackend {
7
+ /** The saved text, or null when nothing is saved or reading fails. */
8
+ get: () => string | null;
9
+ /** Saves text. Returns false when the write fails. */
10
+ set: (value: string) => boolean;
11
+ /** Removes the text. Returns false when the removal fails. */
12
+ remove: () => boolean;
13
+ /** Hears the saved text change elsewhere (another tab, another instance). */
14
+ subscribe: (listener: (value: string | null) => void) => () => void;
15
+ /** Whether saving appears possible. Optional; a missing method means yes. */
16
+ available?: () => boolean;
17
+ }
18
+ /** Makes the backend for one key. */
19
+ export type StoredBackendFactory = (id: string) => StoredBackend;
20
+ /** Where a value lives: localStorage, sessionStorage, or an app's own backend. */
21
+ export type StoredStorage = "local" | "session" | StoredBackendFactory;
22
+ export declare function backendFor(storage: StoredStorage, key: string): StoredBackend;
@@ -0,0 +1,10 @@
1
+ import { createLocalStorage, createSessionStorage } from "@ui-sdk/core";
2
+ export function backendFor(storage, key) {
3
+ if (storage === "local") {
4
+ return createLocalStorage(key);
5
+ }
6
+ if (storage === "session") {
7
+ return createSessionStorage(key);
8
+ }
9
+ return storage(key);
10
+ }
@@ -0,0 +1,93 @@
1
+ import { type StoredStorage } from "./storage";
2
+ /** What a saved value that fails `validate` does: stay in storage, or go. */
3
+ export type StoredInvalid = "keep" | "remove";
4
+ /** When a change is written: at once, or once changes stop for `delay` ms. */
5
+ export type StoredWrites = "immediate" | "debounced";
6
+ /** How a value is written to storage: as JSON, or as the plain text it is. */
7
+ export type StoredFormat = "json" | "text";
8
+ export interface StoredOptions<T> {
9
+ /** The storage key. A scope is added after it, like `rows.folded:board-2`. */
10
+ key: string;
11
+ /** The value used when nothing valid is saved, and on the server. */
12
+ fallback: T;
13
+ /**
14
+ * How the value is written. "text" keeps a string as it is, with no JSON
15
+ * quotes, for values an app already saved as bare text. Only string values
16
+ * can use it.
17
+ * @defaultValue "json"
18
+ */
19
+ format?: StoredFormat;
20
+ /** Whether a parsed saved value is allowed. Anything else counts as invalid. */
21
+ validate: (value: unknown) => value is T;
22
+ /**
23
+ * Where it lives.
24
+ * @defaultValue "local"
25
+ */
26
+ storage?: StoredStorage;
27
+ /**
28
+ * Whether changes made in other windows show up live. False keeps the
29
+ * value read at first use until the page reloads.
30
+ * @defaultValue true
31
+ */
32
+ follow?: boolean;
33
+ /**
34
+ * A saved value that fails validation always shows the fallback. "keep"
35
+ * leaves the bad text in storage, "remove" deletes it.
36
+ * @defaultValue "keep"
37
+ */
38
+ invalid?: StoredInvalid;
39
+ /**
40
+ * "debounced" writes after `delay` ms without a change, and also when
41
+ * the page is hidden.
42
+ * @defaultValue "immediate"
43
+ */
44
+ writes?: StoredWrites;
45
+ /**
46
+ * The quiet time for debounced writes, in milliseconds.
47
+ * @defaultValue 300
48
+ */
49
+ delay?: number;
50
+ }
51
+ export interface StoredStatus {
52
+ /** Whether the storage appears to accept writes. */
53
+ available: boolean;
54
+ /** Whether the last write or removal failed (blocked or full). */
55
+ writeFailed: boolean;
56
+ /** Whether the saved text was invalid the last time it was read. */
57
+ invalid: boolean;
58
+ /** Whether a debounced write is still waiting. */
59
+ pending: boolean;
60
+ }
61
+ export type StoredUpdate<T> = T | ((current: T) => T);
62
+ export interface Stored<T> {
63
+ key: string;
64
+ /** The current value. The same reference until it changes. */
65
+ get: () => T;
66
+ set: (next: StoredUpdate<T>) => void;
67
+ /** Goes back to the fallback and removes the saved text. */
68
+ reset: () => void;
69
+ /** Hears any change to the value or the status. Returns the stop function. */
70
+ subscribe: (listener: () => void) => () => void;
71
+ /** The status. The same object until it changes. */
72
+ status: () => StoredStatus;
73
+ /** Writes a waiting debounced change now. */
74
+ flush: () => void;
75
+ }
76
+ export interface StoredDefinition<T> {
77
+ options: StoredOptions<T>;
78
+ /** The stored value for a scope, such as a board id. The same one each time. */
79
+ open: (scope?: string) => Stored<T>;
80
+ /** Flushes every waiting write of this definition. */
81
+ flush: () => void;
82
+ }
83
+ export declare const serverStatus: StoredStatus;
84
+ /**
85
+ * Describes one saved value. Open it for a scope (or none) to read and
86
+ * change it, or give it to `useStored`.
87
+ */
88
+ export declare function defineStored<T extends string>(options: StoredOptions<T> & {
89
+ format: "text";
90
+ }): StoredDefinition<T>;
91
+ export declare function defineStored<T>(options: StoredOptions<T> & {
92
+ format?: "json";
93
+ }): StoredDefinition<T>;
@@ -0,0 +1,209 @@
1
+ import { backendFor } from "./storage";
2
+ export const serverStatus = {
3
+ available: true,
4
+ writeFailed: false,
5
+ invalid: false,
6
+ pending: false
7
+ };
8
+ const waiting = new Set();
9
+ let hooked = false;
10
+ const runWaiting = () => {
11
+ for (const flush of waiting) {
12
+ flush();
13
+ }
14
+ };
15
+ /* Waiting writes must not be lost when the tab is closed or hidden. */
16
+ function hookPageHide() {
17
+ if (hooked || typeof window === "undefined") {
18
+ return;
19
+ }
20
+ hooked = true;
21
+ window.addEventListener("pagehide", runWaiting);
22
+ document.addEventListener("visibilitychange", () => {
23
+ if (document.visibilityState === "hidden") {
24
+ runWaiting();
25
+ }
26
+ });
27
+ }
28
+ function isUpdater(next) {
29
+ return typeof next === "function";
30
+ }
31
+ function parse(text, validate, format) {
32
+ try {
33
+ const parsed = format === "text" ? text : JSON.parse(text);
34
+ return validate(parsed) ? parsed : undefined;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ }
40
+ class StoredCell {
41
+ key;
42
+ options;
43
+ listeners = new Set();
44
+ backend;
45
+ stopFollowing;
46
+ loaded = false;
47
+ value;
48
+ /* The text storage held when we last looked or wrote. */
49
+ raw = null;
50
+ current = serverStatus;
51
+ timer;
52
+ constructor(options, key) {
53
+ this.options = options;
54
+ this.key = key;
55
+ this.value = options.fallback;
56
+ }
57
+ notify() {
58
+ for (const listener of this.listeners) {
59
+ listener();
60
+ }
61
+ }
62
+ patch(change) {
63
+ this.current = { ...this.current, ...change };
64
+ }
65
+ availableNow() {
66
+ return this.backend?.available?.() ?? true;
67
+ }
68
+ load() {
69
+ this.loaded = true;
70
+ const storage = this.options.storage ?? "local";
71
+ /* The browser's own storages do not exist on the server. An app's own backend works anywhere. */
72
+ if (typeof storage === "string" && typeof window === "undefined") {
73
+ return;
74
+ }
75
+ this.backend = backendFor(storage, this.key);
76
+ this.patch({ available: this.availableNow() });
77
+ this.apply(this.backend.get());
78
+ }
79
+ /* Turns saved text into the value, handling an invalid one per the option. */
80
+ apply(text) {
81
+ this.raw = text;
82
+ const parsed = text === null ? undefined : parse(text, this.options.validate, this.options.format);
83
+ if (text === null || parsed !== undefined) {
84
+ this.value = parsed ?? this.options.fallback;
85
+ this.patch({ invalid: false });
86
+ return;
87
+ }
88
+ this.value = this.options.fallback;
89
+ this.patch({ invalid: true });
90
+ if (this.options.invalid === "remove" && this.backend) {
91
+ const removed = this.backend.remove();
92
+ this.patch({ writeFailed: !removed });
93
+ this.raw = removed ? null : text;
94
+ }
95
+ }
96
+ persist() {
97
+ waiting.delete(this.flush);
98
+ this.timer = undefined;
99
+ if (!this.backend) {
100
+ return;
101
+ }
102
+ const text = this.options.format === "text" ? String(this.value) : JSON.stringify(this.value);
103
+ /* Set first: the backend may announce the write before it returns. */
104
+ this.raw = text;
105
+ const written = this.backend.set(text);
106
+ this.patch({ writeFailed: !written, available: this.availableNow(), pending: false });
107
+ this.notify();
108
+ }
109
+ heard = (text) => {
110
+ /* Our own writes echo back; a waiting local change wins over a remote one. */
111
+ if (text === this.raw || this.timer !== undefined) {
112
+ return;
113
+ }
114
+ this.apply(text);
115
+ this.notify();
116
+ };
117
+ get = () => {
118
+ if (!this.loaded) {
119
+ this.load();
120
+ }
121
+ return this.value;
122
+ };
123
+ status = () => {
124
+ this.get();
125
+ return this.current;
126
+ };
127
+ set = (next) => {
128
+ const current = this.get();
129
+ const resolved = isUpdater(next) ? next(current) : next;
130
+ if (Object.is(resolved, this.value)) {
131
+ return;
132
+ }
133
+ this.value = resolved;
134
+ if (this.options.writes !== "debounced") {
135
+ this.persist();
136
+ return;
137
+ }
138
+ clearTimeout(this.timer);
139
+ this.timer = setTimeout(() => this.persist(), this.options.delay ?? 300);
140
+ waiting.add(this.flush);
141
+ hookPageHide();
142
+ this.patch({ pending: true });
143
+ this.notify();
144
+ };
145
+ reset = () => {
146
+ this.get();
147
+ clearTimeout(this.timer);
148
+ this.timer = undefined;
149
+ waiting.delete(this.flush);
150
+ this.value = this.options.fallback;
151
+ const removed = this.backend?.remove() ?? true;
152
+ if (removed) {
153
+ this.raw = null;
154
+ }
155
+ this.patch({
156
+ writeFailed: !removed,
157
+ available: this.availableNow(),
158
+ pending: false,
159
+ invalid: false
160
+ });
161
+ this.notify();
162
+ };
163
+ flush = () => {
164
+ if (this.timer !== undefined) {
165
+ clearTimeout(this.timer);
166
+ this.persist();
167
+ }
168
+ };
169
+ subscribe = (listener) => {
170
+ this.get();
171
+ this.listeners.add(listener);
172
+ if ((this.options.follow ?? true) && this.backend && this.listeners.size === 1) {
173
+ /* Catch up on anything missed while nobody was listening. */
174
+ const latest = this.backend.get();
175
+ if (latest !== this.raw && this.timer === undefined) {
176
+ this.apply(latest);
177
+ }
178
+ this.stopFollowing = this.backend.subscribe(this.heard);
179
+ }
180
+ return () => {
181
+ this.listeners.delete(listener);
182
+ if (this.listeners.size === 0) {
183
+ this.stopFollowing?.();
184
+ this.stopFollowing = undefined;
185
+ }
186
+ };
187
+ };
188
+ }
189
+ export function defineStored(options) {
190
+ const opened = new Map();
191
+ return {
192
+ options,
193
+ open: (scope) => {
194
+ const key = scope === undefined ? options.key : `${options.key}:${scope}`;
195
+ const existing = opened.get(key);
196
+ if (existing) {
197
+ return existing;
198
+ }
199
+ const created = new StoredCell(options, key);
200
+ opened.set(key, created);
201
+ return created;
202
+ },
203
+ flush: () => {
204
+ for (const stored of opened.values()) {
205
+ stored.flush();
206
+ }
207
+ }
208
+ };
209
+ }
@@ -0,0 +1,6 @@
1
+ import { type StoredDefinition, type StoredStatus, type StoredUpdate } from "./stored";
2
+ /**
3
+ * Reads and changes a stored value: `[value, set, status, reset]`. The server
4
+ * and the first hydration render use the fallback, then the saved value shows.
5
+ */
6
+ export declare function useStored<T>(definition: StoredDefinition<T>, scope?: string): [T, (next: StoredUpdate<T>) => void, StoredStatus, () => void];
@@ -0,0 +1,12 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { serverStatus } from "./stored";
3
+ /**
4
+ * Reads and changes a stored value: `[value, set, status, reset]`. The server
5
+ * and the first hydration render use the fallback, then the saved value shows.
6
+ */
7
+ export function useStored(definition, scope) {
8
+ const stored = definition.open(scope);
9
+ const value = useSyncExternalStore(stored.subscribe, stored.get, () => definition.options.fallback);
10
+ const status = useSyncExternalStore(stored.subscribe, stored.status, () => serverStatus);
11
+ return [value, stored.set, status, stored.reset];
12
+ }
@@ -0,0 +1,6 @@
1
+ /** A value from a fixed list, like a density or a view mode. */
2
+ export declare function oneOf<T extends string | number>(choices: readonly T[]): (value: unknown) => value is T;
3
+ /** A finite number inside a range, ends included. */
4
+ export declare function numberBetween(min: number, max: number): (value: unknown) => value is number;
5
+ /** A list of strings, like the ids of folded rows. */
6
+ export declare function isStringList(value: unknown): value is string[];
@@ -0,0 +1,13 @@
1
+ /* Ready-made `validate` functions for the usual shapes of saved values. */
2
+ /** A value from a fixed list, like a density or a view mode. */
3
+ export function oneOf(choices) {
4
+ return (value) => choices.some((choice) => choice === value);
5
+ }
6
+ /** A finite number inside a range, ends included. */
7
+ export function numberBetween(min, max) {
8
+ return (value) => typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
9
+ }
10
+ /** A list of strings, like the ids of folded rows. */
11
+ export function isStringList(value) {
12
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string");
13
+ }
@@ -0,0 +1,2 @@
1
+ export { Titlebar, TitlebarButton, TitlebarWindowControls, useWindowActive, type TitlebarButtonProps, type TitlebarProps, type WindowControls, type WindowControlsProps } from "./titlebar";
2
+ export { titlebarWords, type TitlebarButtonLook, type TitlebarDivider, type TitlebarEdge, type TitlebarHeight, type TitlebarLayout, type TitlebarLooks } from "./titlebar-looks";
@@ -0,0 +1,2 @@
1
+ export { Titlebar, TitlebarButton, TitlebarWindowControls, useWindowActive } from "./titlebar";
2
+ export { titlebarWords } from "./titlebar-looks";
@@ -0,0 +1,53 @@
1
+ /** Where the brand sits: only the mark at the start and the name centred in the bar, or the name next to the mark. */
2
+ export type TitlebarLayout = "center" | "start";
3
+ /** The bar's height through its token: compact, regular or tall. */
4
+ export type TitlebarHeight = "compact" | "regular" | "tall";
5
+ /** The bar's bottom edge: a soft shadow, a line, or nothing. */
6
+ export type TitlebarEdge = "shadow" | "line" | "none";
7
+ /** A tool button's look: a rounded square wash, a round wash, or ghost (no wash, only the colour changes). */
8
+ export type TitlebarButtonLook = "square" | "round" | "ghost";
9
+ /** The divider between the brand and the middle: a small diamond, a thin line, or none. */
10
+ export type TitlebarDivider = "diamond" | "line" | "none";
11
+ /** The looks of a bar. Each is a prop, or a word on any container such as `data-kumiko-titlebar="height-compact edge-none"`. */
12
+ export interface TitlebarLooks {
13
+ /**
14
+ * Word: `layout-center` or `layout-start`.
15
+ * @defaultValue "center"
16
+ */
17
+ layout?: TitlebarLayout;
18
+ /**
19
+ * Word: `height-compact`, `height-regular` or `height-tall`. An app that feeds the height to its window sets
20
+ * `--kumiko-titlebar-height` itself and leaves this out.
21
+ * @defaultValue "regular"
22
+ */
23
+ height?: TitlebarHeight;
24
+ /**
25
+ * Word: `edge-shadow`, `edge-line` or `edge-none`. The edge's room is kept either way, so the height never changes.
26
+ * @defaultValue "shadow"
27
+ */
28
+ edge?: TitlebarEdge;
29
+ /**
30
+ * The look of the tool buttons. Word: `look-square`, `look-round` or `look-ghost`.
31
+ * @defaultValue "square"
32
+ */
33
+ look?: TitlebarButtonLook;
34
+ /**
35
+ * Tool button icons tilt on hover (and a gear spins) as well as the button growing. Word: `tilt` or `no-tilt`.
36
+ * @defaultValue false
37
+ */
38
+ tilt?: boolean;
39
+ /**
40
+ * Word: `divider-diamond`, `divider-line` or `divider-none`.
41
+ * @defaultValue "diamond"
42
+ */
43
+ divider?: TitlebarDivider;
44
+ /**
45
+ * Fade the bar's contents while the window is not focused. Word: `dim-inactive` or `no-dim-inactive`.
46
+ * @defaultValue true
47
+ */
48
+ dimInactive?: boolean;
49
+ }
50
+ /** The words the looks become, or nothing when no look is set. A look left out sets no word, so a container's word can pick. */
51
+ export declare function titlebarWords(looks: TitlebarLooks): string | undefined;
52
+ /** A tool button's tilt as its data attribute: on, off, or nothing so the bar's word decides. */
53
+ export declare function tiltAttribute(tilt: boolean | undefined): "on" | "off" | undefined;
@@ -0,0 +1,26 @@
1
+ function onOff(value, word) {
2
+ if (value === undefined) {
3
+ return undefined;
4
+ }
5
+ return value ? word : `no-${word}`;
6
+ }
7
+ /** The words the looks become, or nothing when no look is set. A look left out sets no word, so a container's word can pick. */
8
+ export function titlebarWords(looks) {
9
+ const words = [
10
+ looks.layout && `layout-${looks.layout}`,
11
+ looks.height && `height-${looks.height}`,
12
+ looks.edge && `edge-${looks.edge}`,
13
+ looks.look && `look-${looks.look}`,
14
+ onOff(looks.tilt, "tilt"),
15
+ looks.divider && `divider-${looks.divider}`,
16
+ onOff(looks.dimInactive, "dim-inactive")
17
+ ].filter(Boolean);
18
+ return words.length > 0 ? words.join(" ") : undefined;
19
+ }
20
+ /** A tool button's tilt as its data attribute: on, off, or nothing so the bar's word decides. */
21
+ export function tiltAttribute(tilt) {
22
+ if (tilt === undefined) {
23
+ return undefined;
24
+ }
25
+ return tilt ? "on" : "off";
26
+ }