@kubohiroya/turbowarp-plus-editor-workbench 0.27.0 → 0.28.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 (49) hide show
  1. package/EDITOR-MIGRATION.md +5 -0
  2. package/README.ja.md +9 -0
  3. package/dist/basic-panel.d.ts +52 -0
  4. package/dist/basic-panel.js +153 -0
  5. package/dist/editor-tabs.d.ts +37 -0
  6. package/dist/editor-tabs.js +550 -0
  7. package/dist/popup-layout.d.ts +20 -0
  8. package/dist/popup-layout.js +59 -0
  9. package/dist/project-folder-workflows.d.ts +31 -0
  10. package/dist/project-folder-workflows.js +1 -0
  11. package/dist/project-payload-forms.d.ts +8 -0
  12. package/dist/project-payload-forms.js +184 -0
  13. package/dist/project-tools/diagnostics.d.ts +13 -0
  14. package/dist/project-tools/diagnostics.js +65 -0
  15. package/dist/project-tools/dialog.d.ts +21 -0
  16. package/dist/project-tools/dialog.js +363 -0
  17. package/dist/project-tools/history.d.ts +8 -0
  18. package/dist/project-tools/history.js +22 -0
  19. package/dist/project-tools/integration.d.ts +65 -0
  20. package/dist/project-tools/integration.js +356 -0
  21. package/dist/project-tools/links.d.ts +3 -0
  22. package/dist/project-tools/links.js +36 -0
  23. package/dist/project-tools/properties.d.ts +51 -0
  24. package/dist/project-tools/properties.js +268 -0
  25. package/dist/sprite-tabs.d.ts +1 -0
  26. package/dist/sprite-tabs.js +1 -0
  27. package/dist/stage-display-menu.d.ts +21 -0
  28. package/dist/stage-display-menu.js +156 -0
  29. package/dist/stage-panel.d.ts +29 -0
  30. package/dist/stage-panel.js +105 -0
  31. package/package.json +78 -9
  32. package/src/basic-panel.tsx +207 -0
  33. package/src/editor-tabs.tsx +591 -0
  34. package/src/popup-layout.css +4 -0
  35. package/src/popup-layout.tsx +81 -0
  36. package/src/project-dialog.css +39 -0
  37. package/src/project-folder-workflows.ts +32 -0
  38. package/src/project-payload-forms.ts +179 -0
  39. package/src/project-snackbar.css +85 -0
  40. package/src/project-tools/diagnostics.ts +51 -0
  41. package/src/project-tools/dialog.ts +341 -0
  42. package/src/project-tools/history.ts +20 -0
  43. package/src/project-tools/integration.ts +366 -0
  44. package/src/project-tools/links.ts +31 -0
  45. package/src/project-tools/properties.ts +251 -0
  46. package/src/sprite-tabs.ts +2 -1
  47. package/src/stage-display-menu.css +28 -0
  48. package/src/stage-display-menu.tsx +177 -0
  49. package/src/stage-panel.tsx +127 -0
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ import React from 'react';
3
+ import {IconMenuButton} from '@kubohiroya/turbowarp-plus-editor-windows';
4
+
5
+ export type PopupWindowMode = 'normal' | 'minimized' | 'maximized';
6
+ export type PopupWindowAction = 'maximize' | 'minimize' | 'restore';
7
+ export interface PopupWindowControls {
8
+ onMode(listener: (mode: PopupWindowMode) => void): () => void;
9
+ mode(): Promise<PopupWindowMode>;
10
+ change(action: PopupWindowAction): Promise<PopupWindowMode>;
11
+ }
12
+ export interface PopupLayoutProps {
13
+ window: Window;
14
+ locale: string;
15
+ onDock(): void;
16
+ onDuplicate?(): void;
17
+ }
18
+
19
+ export function createPopupLayout({styles, getWindowControls}: {
20
+ styles: Record<string, string>; getWindowControls(window: Window): PopupWindowControls | undefined;
21
+ }) {
22
+
23
+
24
+ const labels = {
25
+ ja: {
26
+ title: 'レイアウト変更',
27
+ undock: '別窓で開く(アンドック)',
28
+ dock: '元の画面に戻す(ドックする)',
29
+ duplicate: 'この編集画面をもう一枚開く(別のビューを開く)',
30
+ maximize: 'この画面を最大化する',
31
+ minimize: 'この画面を最小化する',
32
+ restore: '通常のウィンドウに戻す'
33
+ },
34
+ en: {
35
+ title: 'Window layout',
36
+ undock: 'Open in a separate window (undock)',
37
+ dock: 'Return to the editor (dock)',
38
+ duplicate: 'Open another view of this editor',
39
+ maximize: 'Maximize this window',
40
+ minimize: 'Minimize this window',
41
+ restore: 'Restore normal window'
42
+ }
43
+ };
44
+
45
+ const layoutIcon = (
46
+ <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4">
47
+ <rect x="2" y="3" width="12" height="10" rx="1.5" />
48
+ <path d="M2 6h12M7 6v7" />
49
+ </svg>
50
+ );
51
+
52
+ function PopupLayout({window, locale, onDock, onDuplicate}: PopupLayoutProps) {
53
+ const [mode, setMode] = React.useState<PopupWindowMode>('normal');
54
+ const controls = getWindowControls(window);
55
+ React.useEffect(() => {
56
+ if (!controls) return;
57
+ let mounted = true;
58
+ const unsubscribe = controls.onMode(next => {if (mounted) setMode(next);});
59
+ void controls.mode().then(next => {if (mounted) setMode(next);}, () => {});
60
+ return () => {
61
+ mounted = false;
62
+ unsubscribe();
63
+ };
64
+ }, [controls]);
65
+ const change = (action: PopupWindowAction) => controls ? () => {
66
+ void controls.change(action).then(setMode, () => {});
67
+ } : undefined;
68
+ const text = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
69
+ const items = [
70
+ {id: 'undock', current: true},
71
+ {id: 'dock', onSelect: onDock},
72
+ {id: 'duplicate', onSelect: onDuplicate},
73
+ {id: 'maximize', current: mode === 'maximized', onSelect: change('maximize')},
74
+ {id: 'minimize', current: mode === 'minimized', onSelect: change('minimize')},
75
+ {id: 'restore', current: mode === 'normal', onSelect: change('restore')}
76
+ ].map(item => ({...item, label: text[item.id], disabled: item.current || !item.onSelect}));
77
+ return <IconMenuButton label={text.title} icon={layoutIcon} items={items} className={styles.root} />;
78
+ }
79
+
80
+ return {PopupLayout};
81
+ }
@@ -0,0 +1,39 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+ .dialog {
3
+ box-sizing: border-box;
4
+ width: min(640px, 94vw);
5
+ max-height: 90vh;
6
+ overflow: auto;
7
+ border: 1px solid var(--ui-black-transparent, #64748b);
8
+ border-radius: 12px;
9
+ padding: 24px;
10
+ color: var(--ui-modal-foreground, #172033);
11
+ background: var(--ui-modal-background, white);
12
+ font: 14px/1.5 system-ui, sans-serif;
13
+ }
14
+ .dialog::backdrop { background: #111827a6; }
15
+ .dialog h2 { margin-top: 0; }
16
+ .dialog label:not([hidden]) { display: block; margin: 12px 0; font-weight: 600; }
17
+ .dialog input:not([type="checkbox"]), .dialog textarea, .dialog select {
18
+ box-sizing: border-box;
19
+ display: block;
20
+ width: 100%;
21
+ margin-top: 4px;
22
+ padding: 8px;
23
+ border: 1px solid var(--ui-black-transparent, #64748b);
24
+ border-radius: 5px;
25
+ color: inherit;
26
+ background: var(--input-background, #f7f8fa);
27
+ font: inherit;
28
+ }
29
+ .dialog textarea { resize: vertical; }
30
+ .dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; }
31
+ .dialog dd { margin: 0; }
32
+ .dialog a { color: var(--link-color, #1d4ed8); text-decoration: underline; }
33
+ .dialog button { padding: 8px 16px; border: 1px solid var(--ui-black-transparent, #64748b); border-radius: 5px;
34
+ color: inherit; background: var(--ui-secondary, #f7f8fa); font: inherit; cursor: pointer; }
35
+ .dialog button:disabled { opacity: .5; cursor: default; }
36
+ .dialog :focus-visible { outline: 3px solid var(--looks-secondary, #3b82f6); outline-offset: 2px; }
37
+ .preview { white-space: pre-wrap; overflow-wrap: anywhere; }
38
+ .dialog pre { white-space: pre-wrap; overflow-wrap: anywhere; }
39
+ .dialog summary { cursor: pointer; }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ import type {NewProjectRepositoryCreation} from './new-project.ts';
3
+ import type {ProjectCommitPort} from '@kubohiroya/turbowarp-plus-editor-git/project-commit-dialog';
4
+ import type {ProjectPublicationPort} from '@kubohiroya/turbowarp-plus-editor-git/project-publication';
5
+ import type {RepositoryCreationControls} from '@kubohiroya/turbowarp-plus-editor-git/project-repository-creation';
6
+ export type ProjectRepositoryCreation = Omit<NewProjectRepositoryCreation, 'start'> & RepositoryCreationControls & {
7
+ start(draft: Parameters<NewProjectRepositoryCreation['start']>[0], serialize: () => Promise<Uint8Array>,
8
+ current: () => boolean, signal: AbortSignal, target?: Parameters<NewProjectRepositoryCreation['start']>[4]):
9
+ ReturnType<NewProjectRepositoryCreation['start']>;
10
+ };
11
+ export interface ProjectFolderWorkflows {
12
+ /**
13
+ * Creates a project folder from the current project and opens it. `title` names a folder made in the browser, where
14
+ * the user names a new folder instead of picking one. `destination` is `browser` for a new folder in the browser's
15
+ * storage, or an empty folder already picked on the device; without it the folder follows `folderLocation`.
16
+ */
17
+ createFolder?(serialize: () => Promise<Uint8Array>, current: () => boolean, title?: string,
18
+ destination?: 'browser' | FileSystemDirectoryHandle): Promise<boolean>;
19
+ /** Writes the current project into a new folder and leaves the open project as it is (Save a Copy, #679). */
20
+ copyFolder?(serialize: () => Promise<Uint8Array>, current: () => boolean, title?: string): Promise<boolean>;
21
+ /** Picks an empty folder on the device for a new project; `null` when the person cancelled or it was not empty. */
22
+ pickEmptyFolder?(language: string): Promise<FileSystemDirectoryHandle | null>;
23
+ /** Where new project folders can be made: the browser's own storage, and folders picked on the device. */
24
+ locations?: {browser: boolean; device: boolean};
25
+ /** Marks the open project as saved, for a new default project that is about to be replaced by its folder. */
26
+ markSaved?(): void;
27
+ /** `browser` when new project folders go to the browser's own storage, where there is no folder picker. */
28
+ folderLocation?: 'device' | 'browser';
29
+ repositoryCreation?: ProjectRepositoryCreation;
30
+ commit?: ProjectCommitPort;
31
+ publication?: ProjectPublicationPort;
32
+ }
@@ -0,0 +1,179 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ import {dialogAction, dialogActions} from '@kubohiroya/turbowarp-plus-editor-windows';
3
+ import {sb3SaveFormats} from '@kubohiroya/turbowarp-sb3-save-format';
4
+
5
+ const formatLabels = {
6
+ '': ['標準の格納方式を使う', 'Use default storage'],
7
+ 'remote-non-cacheable': ['HTTPS から毎回取得', 'Fetch from HTTPS each time'],
8
+ 'remote-cacheable': ['HTTPS から取得・キャッシュ可', 'Fetch from HTTPS, caching allowed'],
9
+ 'embedded-file': ['SB3 内のファイル', 'File in the SB3'],
10
+ 'embedded-data': ['作品 JSON 内のデータ', 'Data in the project JSON']
11
+ };
12
+
13
+ export function renderPayloadForm(document, edit, locale, close) {
14
+ const ja = locale.startsWith('ja');
15
+ const label = (jp, en) => ja ? jp : en;
16
+ const make = (tag: string, text?: string) => {
17
+ const node = document.createElement(tag);
18
+ if (text) node.textContent = text;
19
+ return node;
20
+ };
21
+ const controller = new AbortController();
22
+ const form = make('form');
23
+ const inputs = new Map();
24
+ const intro = make('p', label(
25
+ '設定した形式は次の SB3 保存に使われます。リモート形式の URL は現在の内容と一致する必要があります。',
26
+ 'These formats are used the next time you save an SB3. Remote URLs must serve the current bytes.'));
27
+ form.append(intro);
28
+ for (const [kind, heading] of [
29
+ ['source', label('ソースデータ', 'Source Data')], ['assets', label('アセット', 'Assets')]
30
+ ]) {
31
+ const group = make('fieldset');
32
+ group.append(make('legend', heading));
33
+ const items = edit.items.filter(item => item.kind === kind);
34
+ if (!items.length) group.append(make('p', label('設定できる項目がありません。', 'No items are available.')));
35
+ for (const item of items) {
36
+ const row = make('label', item.label);
37
+ const format = make('select');
38
+ format.setAttribute('aria-label', `${heading} – ${item.label}`);
39
+ for (const id of ['', ...sb3SaveFormats]) {
40
+ const option = make('option', label(formatLabels[id][0], formatLabels[id][1]));
41
+ option.value = id;
42
+ format.append(option);
43
+ }
44
+ format.value = item.format || '';
45
+ row.append(format);
46
+ const urlRow = make('label', `${item.label} HTTPS URL`);
47
+ const url = make('input');
48
+ url.inputMode = 'url';
49
+ url.value = item.url || '';
50
+ urlRow.append(url);
51
+ const update = () => {
52
+ const needed = format.value.startsWith('remote-');
53
+ urlRow.hidden = !needed;
54
+ url.required = needed;
55
+ url.disabled = !needed;
56
+ };
57
+ format.addEventListener('change', update);
58
+ update();
59
+ group.append(row, urlRow);
60
+ inputs.set(item.id, {format, url});
61
+ }
62
+ form.append(group);
63
+ }
64
+ const error = make('p');
65
+ error.setAttribute('role', 'alert');
66
+ const cancel = make('button', label('キャンセル', 'Cancel'));
67
+ cancel.type = 'button';
68
+ cancel.addEventListener('click', close);
69
+ const apply = make('button', label('適用', 'Apply'));
70
+ apply.type = 'submit';
71
+ apply.disabled = !inputs.size;
72
+ form.append(error, dialogActions(document, dialogAction(cancel, 'cancel'), dialogAction(apply, 'confirm')));
73
+ form.addEventListener('submit', async event => {
74
+ event.preventDefault();
75
+ if (apply.disabled) return;
76
+ apply.disabled = true;
77
+ error.textContent = '';
78
+ const choices = new Map([...inputs].filter(([, {format}]) => format.value)
79
+ .map(([id, {format, url}]) => [id, {format: format.value, url: url.value.trim()}]));
80
+ try {
81
+ await edit.apply(choices, controller.signal);
82
+ if (!controller.signal.aborted) close();
83
+ } catch (failure) {
84
+ if (controller.signal.aborted) return;
85
+ error.textContent = failure.message;
86
+ apply.disabled = false;
87
+ }
88
+ });
89
+ return {form, dispose: () => controller.abort()};
90
+ }
91
+
92
+ export function renderBundleAssetForm(document, conversion, locale, close) {
93
+ const ja = locale.startsWith('ja');
94
+ const label = (jp, en) => ja ? jp : en;
95
+ const make = (tag: string, text?: string) => {
96
+ const node = document.createElement(tag);
97
+ if (text) node.textContent = text;
98
+ return node;
99
+ };
100
+ const controller = new AbortController();
101
+ const form = make('form');
102
+ const select = title => {
103
+ const row = make('label', title);
104
+ const input = make('select');
105
+ row.append(input);
106
+ form.append(row);
107
+ return input;
108
+ };
109
+ const fill = (input, choices) => {
110
+ input.replaceChildren(...choices.map(([value, text]) => {
111
+ const option = make('option', text);
112
+ option.value = value;
113
+ return option;
114
+ }));
115
+ };
116
+ const intro = make('p', label(
117
+ '選んだ素材を作品に追加します。紙芝居から使う元の素材はバンドル内に保持します。',
118
+ 'Add the selected material to the project. The original stays in the bundle for Kamishibai.'));
119
+ form.append(intro);
120
+ const material = select(label('バンドル素材', 'Bundle material'));
121
+ const kind = select(label('追加する種類', 'Add as'));
122
+ const target = select(label('追加先', 'Target'));
123
+ const kinds = {
124
+ costume: label('コスチューム', 'Costume'),
125
+ backdrop: label('背景', 'Backdrop'),
126
+ sound: label('音', 'Sound')
127
+ };
128
+ const targetsFor = type => type ? conversion.targets.filter(item => type === 'sound' ||
129
+ (type === 'backdrop' ? item.stage : !item.stage)) : [];
130
+ const status = make('p');
131
+ status.setAttribute('role', 'status');
132
+ const error = make('p');
133
+ error.setAttribute('role', 'alert');
134
+ const cancel = make('button', label('閉じる', 'Close'));
135
+ cancel.type = 'button';
136
+ cancel.addEventListener('click', close);
137
+ const add = make('button', label('作品に追加', 'Add to project'));
138
+ add.type = 'submit';
139
+ form.append(status, error, dialogActions(document, dialogAction(cancel, 'close'), dialogAction(add, 'confirm')));
140
+ const showTargets = () => {
141
+ fill(target, targetsFor(kind.value).map(item => [item.id, item.stage ? label('ステージ', 'Stage') : item.name]));
142
+ add.disabled = !target.value;
143
+ };
144
+ const showKinds = () => {
145
+ const selected = conversion.materials.find(item => item.key === material.value);
146
+ fill(kind, (selected?.kinds || []).filter(type => targetsFor(type).length).map(type => [type, kinds[type]]));
147
+ showTargets();
148
+ };
149
+ fill(material, conversion.materials.map(item => [item.key, item.label]));
150
+ if (!conversion.materials.length) {
151
+ status.textContent = label('追加できる画像や音がありません。', 'There are no supported images or sounds.');
152
+ }
153
+ material.addEventListener('change', showKinds);
154
+ kind.addEventListener('change', showTargets);
155
+ showKinds();
156
+ form.addEventListener('submit', async event => {
157
+ event.preventDefault();
158
+ if (add.disabled) return;
159
+ const choice = {key: material.value, kind: kind.value, targetId: target.value};
160
+ for (const control of [material, kind, target, add]) control.disabled = true;
161
+ status.textContent = '';
162
+ error.textContent = '';
163
+ try {
164
+ const name = await conversion.add(choice, controller.signal);
165
+ if (controller.signal.aborted) return;
166
+ status.textContent = label(`「${name}」を追加しました。作品を SB3 に保存できます。`,
167
+ `Added “${name}”. You can save the project as an SB3.`);
168
+ } catch (failure) {
169
+ if (controller.signal.aborted) return;
170
+ error.textContent = label(`素材を追加できませんでした。${failure.message}`,
171
+ `Could not add the material. ${failure.message}`);
172
+ } finally {
173
+ if (!controller.signal.aborted) {
174
+ for (const control of [material, kind, target, add]) control.disabled = false;
175
+ }
176
+ }
177
+ });
178
+ return {form, dispose: () => controller.abort()};
179
+ }
@@ -0,0 +1,85 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+ /* The host gives warnings and load failures the same viewport anchor and appearance. */
3
+ .snackbar,
4
+ :global(body .twextsec-review > .twextsec-warning),
5
+ :global(body .twextsec-review[data-mode="add"] > .twextsec-warning) {
6
+ box-sizing: border-box;
7
+ position: fixed;
8
+ grid-area: auto;
9
+ /* Fixed bottom/right can follow an overflowing layout viewport on mobile. */
10
+ bottom: auto;
11
+ top: 100vh;
12
+ top: 100dvh;
13
+ left: 50vw;
14
+ right: auto;
15
+ transform: translate(-50%, -100%);
16
+ z-index: 10000;
17
+ display: flex;
18
+ align-items: flex-start;
19
+ flex-wrap: wrap;
20
+ gap: 16px;
21
+ width: calc(100vw - 32px);
22
+ max-width: 760px;
23
+ max-height: calc(100vh - 32px);
24
+ max-height: calc(100dvh - 32px);
25
+ margin: 0 auto;
26
+ padding: 14px 16px;
27
+ padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
28
+ overflow: auto;
29
+ border: 1px solid #90a4bf;
30
+ border-radius: 8px;
31
+ background: #243247;
32
+ color: #fff;
33
+ font: 14px/1.5 system-ui, sans-serif;
34
+ box-shadow: 0 4px 20px #0006;
35
+ }
36
+
37
+ /* Leave the add dialog's fixed action row reachable while its notice is open. */
38
+ :global(body .twextsec-review[data-mode="add"] > .twextsec-warning) {
39
+ position: absolute;
40
+ grid-area: 1 / 1 / 2 / 2;
41
+ top: auto;
42
+ bottom: 12px;
43
+ left: 16px;
44
+ right: 16px;
45
+ width: auto;
46
+ max-height: calc(100% - 24px);
47
+ transform: none;
48
+ }
49
+
50
+ .snackbar > span,
51
+ :global(body .twextsec-review > .twextsec-warning > span) {
52
+ flex: 1 1 200px;
53
+ min-width: 0;
54
+ overflow-wrap: anywhere;
55
+ }
56
+
57
+ .snackbar > button,
58
+ :global(body .twextsec-review > .twextsec-warning > button) {
59
+ flex: none;
60
+ min-width: 64px;
61
+ min-height: 44px;
62
+ padding: 8px 12px;
63
+ border: 1px solid currentColor;
64
+ border-radius: 6px;
65
+ background: transparent;
66
+ color: inherit;
67
+ font: inherit;
68
+ cursor: pointer;
69
+ }
70
+
71
+ .snackbar > button:hover,
72
+ :global(body .twextsec-review > .twextsec-warning > button:hover) {
73
+ background: #ffffff1a;
74
+ }
75
+
76
+ .snackbar > button:focus-visible,
77
+ :global(body .twextsec-review > .twextsec-warning > button:focus-visible) {
78
+ outline: 3px solid #ffd166;
79
+ outline-offset: 2px;
80
+ }
81
+
82
+ /* A failure takes priority until it is dismissed or its diagnostics are opened. */
83
+ :global(body:has(> [data-testid="project-diagnostics-snackbar"]) .twextsec-warning) {
84
+ visibility: hidden;
85
+ }
@@ -0,0 +1,51 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ const text = (value: unknown) => value === undefined || value === null ? undefined : String(value).slice(0, 16384);
3
+
4
+ /** Bounded, in-memory load attempts. A failed attempt remains available after the editor returns to a new project. */
5
+ export const createProjectDiagnostics = ({now = () => new Date().toISOString()} = {}) => {
6
+ const sessions = [];
7
+ const listeners = new Set<() => void>();
8
+ let serial = 0;
9
+ const notify = () => {
10
+ for (const listener of listeners) { try { listener(); } catch (error) { /* Diagnostics must not affect execution. */ } }
11
+ };
12
+ const begin = (title = '') => {
13
+ sessions.unshift({id: ++serial, title: text(title), startedAt: now(), phase: 'loading', events: [], extensions: []});
14
+ sessions.splice(5); notify();
15
+ };
16
+ const current = () => { if (!sessions.length) begin(); return sessions[0]; };
17
+ const api = {
18
+ begin,
19
+ record (event) {
20
+ const session = current();
21
+ const safe: Record<string, string | string[] | boolean> = {time: now()};
22
+ for (const field of ['type', 'id', 'sha256', 'code', 'message', 'execution', 'attempt', 'attempts']) {
23
+ const value = text(event[field]); if (value !== undefined) safe[field] = value;
24
+ }
25
+ if (Array.isArray(event.ids)) safe.ids = event.ids.map(text).slice(0, 200);
26
+ if (event.source) safe.source = text(event.source.url || event.source.path);
27
+ if (typeof event.cached === 'boolean') safe.cached = event.cached;
28
+ session.events.push(safe); session.events.splice(0, Math.max(0, session.events.length - 50));
29
+ notify();
30
+ },
31
+ describe (manifest) {
32
+ current().extensions = (manifest?.extensions || []).slice(0, 200).map(spec => ({
33
+ id: text(spec.id), source: text(spec.source?.url || spec.source?.path), execution: text(spec.execution),
34
+ sha256: text(spec.sha256)}));
35
+ notify();
36
+ },
37
+ finish (state, title = '') {
38
+ const session = current(); session.phase = state.phase; session.title = text(title);
39
+ if (state.phase === 'failed' && !session.events.some(event => event.type === 'project-error')) {
40
+ api.record({type: 'project-error', code: state.code || 'LOAD_FAILED', message: state.message});
41
+ }
42
+ notify();
43
+ },
44
+ snapshot: () => JSON.parse(JSON.stringify(sessions)),
45
+ subscribe (listener: () => void) { listeners.add(listener); return () => listeners.delete(listener); },
46
+ dispose () { listeners.clear(); sessions.length = 0; }
47
+ };
48
+ return api;
49
+ };
50
+
51
+ export const diagnosticText = session => session ? JSON.stringify(session, null, 2) : '';