@kubohiroya/turbowarp-plus-editor-workbench 0.14.0 → 0.16.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/NOTICE +26 -0
- package/README.ja.md +22 -0
- package/README.md +22 -0
- package/dist/backpack-script.d.ts +2 -0
- package/dist/backpack-script.js +23 -0
- package/dist/backpack.d.ts +60 -0
- package/dist/backpack.js +226 -0
- package/dist/browser-tab-title.d.ts +2 -0
- package/dist/browser-tab-title.js +5 -0
- package/dist/busy-cursor.d.ts +22 -0
- package/dist/busy-cursor.js +107 -0
- package/dist/edit-menu.d.ts +57 -0
- package/dist/edit-menu.js +99 -0
- package/dist/info-menu.d.ts +39 -0
- package/dist/info-menu.js +157 -0
- package/dist/project-file-dialogs.d.ts +70 -0
- package/dist/project-file-dialogs.js +625 -0
- package/dist/project-file-menu.d.ts +43 -0
- package/dist/project-file-menu.js +90 -0
- package/dist/project-load-progress-view.d.ts +6 -0
- package/dist/project-load-progress-view.js +66 -0
- package/dist/project-load-progress.d.ts +26 -0
- package/dist/project-load-progress.js +104 -0
- package/dist/project-search-box.d.ts +43 -0
- package/dist/project-search-box.js +437 -0
- package/dist/project-size-approval.d.ts +10 -0
- package/dist/project-size-approval.js +64 -0
- package/dist/stage-controls-view.d.ts +45 -0
- package/dist/stage-controls-view.js +127 -0
- package/dist/stage-controls.d.ts +98 -0
- package/dist/stage-controls.js +110 -0
- package/package.json +97 -28
- package/src/backpack-script.ts +21 -0
- package/src/backpack.tsx +260 -0
- package/src/browser-tab-title.ts +6 -0
- package/src/busy-cursor.ts +108 -0
- package/src/edit-menu.css +42 -0
- package/src/edit-menu.tsx +139 -0
- package/src/info-menu.css +172 -0
- package/src/info-menu.tsx +221 -0
- package/src/project-file-dialogs.ts +654 -0
- package/src/project-file-menu.css +94 -0
- package/src/project-file-menu.tsx +137 -0
- package/src/project-load-progress-view.tsx +75 -0
- package/src/project-load-progress.css +57 -0
- package/src/project-load-progress.ts +118 -0
- package/src/project-search-box.tsx +469 -0
- package/src/project-search.css +116 -0
- package/src/project-size-approval.ts +74 -0
- package/src/sprite-layout-menu.css +2 -1
- package/src/stage-controls-view.tsx +178 -0
- package/src/stage-controls.css +192 -0
- package/src/stage-controls.ts +124 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
ul:has(> li .tw-project-file-menu__item) {
|
|
2
|
+
background-color: var(--ui-white);
|
|
3
|
+
color: var(--text-primary);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
[data-tw-plus-unsaved-marker] {
|
|
7
|
+
color: var(--looks-secondary, #855cd6);
|
|
8
|
+
color: color-mix(in srgb, var(--looks-secondary, #855cd6) 78%, var(--text-primary, #292929));
|
|
9
|
+
font-weight: 700;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-tw-plus-unsaved-tab] {
|
|
13
|
+
flex: none;
|
|
14
|
+
margin-inline-start: 0.25rem;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
[data-tw-plus-unsaved-tab]::before {
|
|
18
|
+
content: '*';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.tw-project-file-menu__save-menu {
|
|
22
|
+
margin-inline-start: 0.25rem;
|
|
23
|
+
flex: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tw-project-file-menu__save-marker {
|
|
27
|
+
min-inline-size: 1.5rem;
|
|
28
|
+
min-block-size: 1.5rem;
|
|
29
|
+
padding: 0;
|
|
30
|
+
border: 0;
|
|
31
|
+
border-radius: 0.25rem;
|
|
32
|
+
background: transparent;
|
|
33
|
+
font-size: 1rem;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.tw-project-file-menu__save-marker:disabled {
|
|
38
|
+
cursor: default;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.tw-project-file-menu__save-actions,
|
|
42
|
+
.tw-project-file-menu__save-hint {
|
|
43
|
+
position: absolute;
|
|
44
|
+
z-index: 120;
|
|
45
|
+
inset-block-start: calc(100% + 0.25rem);
|
|
46
|
+
inset-inline-start: 0;
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
inline-size: max-content;
|
|
49
|
+
max-inline-size: calc(100vw - 5rem);
|
|
50
|
+
white-space: normal;
|
|
51
|
+
overflow-wrap: anywhere;
|
|
52
|
+
padding: 0.25rem;
|
|
53
|
+
border: 1px solid var(--ui-black-transparent);
|
|
54
|
+
border-radius: 0.25rem;
|
|
55
|
+
background: var(--ui-white);
|
|
56
|
+
color: var(--text-primary);
|
|
57
|
+
box-shadow: 0 2px 8px var(--ui-black-transparent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.tw-project-file-menu__save-hint {
|
|
61
|
+
display: none;
|
|
62
|
+
padding: 0.5rem 0.75rem;
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.tw-project-file-menu__save-marker:is(:hover, :focus-visible) + .tw-project-file-menu__save-hint {
|
|
67
|
+
display: block;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.tw-project-file-menu__save-actions button {
|
|
71
|
+
display: block;
|
|
72
|
+
width: 100%;
|
|
73
|
+
padding: 0.5rem 0.75rem;
|
|
74
|
+
border: 0;
|
|
75
|
+
border-radius: 0.25rem;
|
|
76
|
+
background: transparent;
|
|
77
|
+
color: inherit;
|
|
78
|
+
font: inherit;
|
|
79
|
+
text-align: start;
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.tw-project-file-menu__save-actions button:hover {
|
|
84
|
+
background: var(--ui-black-transparent);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.tw-project-file-menu__shortcut {
|
|
88
|
+
margin-inline-start: 0.75rem;
|
|
89
|
+
color: var(--text-primary);
|
|
90
|
+
opacity: 0.8;
|
|
91
|
+
font: inherit;
|
|
92
|
+
font-size: 0.85em;
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {isMacPlatform} from '@kubohiroya/turbowarp-plus-editor-project-model/project-search-connections';
|
|
3
|
+
import type {Action, FolderActions, ProjectFileStorage} from './project-file-dialogs.js';
|
|
4
|
+
|
|
5
|
+
type Entry = [command: string, label: string, action: Action | undefined, showShortcut?: boolean];
|
|
6
|
+
interface SaveWorkspace {
|
|
7
|
+
saveScope: 'project' | 'tab';
|
|
8
|
+
canSaveActive: boolean;
|
|
9
|
+
saveActive(): void | Promise<void>;
|
|
10
|
+
subscribeSave(listener: () => void): () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type SaveEntries = {storage: ProjectFileStorage; folder?: FolderActions; saveAs?: Action; saveCommit?: Action};
|
|
14
|
+
|
|
15
|
+
function saveEntries(locale: string, {storage, folder, saveAs, saveCommit}: SaveEntries): Entry[] {
|
|
16
|
+
const ja = locale.startsWith('ja');
|
|
17
|
+
return [
|
|
18
|
+
['save', ja ? 'プロジェクトを保存' : 'Save Project', storage.canSave ? storage.overwrite || folder?.save : undefined],
|
|
19
|
+
['save-as', ja ? '名前を変えて保存…' : 'Save As…', storage.canSave ? saveAs : undefined],
|
|
20
|
+
...(saveCommit ? [['save-commit', ja ? '保存してコミット…' : 'Save and Commit…', saveCommit] as Entry] : [])
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ProjectSaveMenu({locale, entries}: {locale: string; entries: SaveEntries}) {
|
|
25
|
+
const label = locale.startsWith('ja') ? '未保存の変更があります。保存メニューを開く' :
|
|
26
|
+
'Unsaved changes. Open the save menu';
|
|
27
|
+
const [open, setOpen] = React.useState(false);
|
|
28
|
+
const trigger = React.useRef<HTMLButtonElement>(null);
|
|
29
|
+
const root = React.useRef<HTMLDivElement>(null);
|
|
30
|
+
const close = () => {
|
|
31
|
+
setOpen(false);
|
|
32
|
+
trigger.current?.focus();
|
|
33
|
+
};
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!open || !root.current) return;
|
|
36
|
+
const node = root.current;
|
|
37
|
+
const dismiss = (event: PointerEvent) => {
|
|
38
|
+
if (!node.contains(event.target as Node)) setOpen(false);
|
|
39
|
+
};
|
|
40
|
+
node.ownerDocument.addEventListener('pointerdown', dismiss, true);
|
|
41
|
+
return () => node.ownerDocument.removeEventListener('pointerdown', dismiss, true);
|
|
42
|
+
}, [open]);
|
|
43
|
+
const actions = saveEntries(locale, entries).filter(([, , action]) => action);
|
|
44
|
+
return <div className="tw-project-file-menu__save-menu" ref={root}
|
|
45
|
+
onBlur={event => {
|
|
46
|
+
if (!event.currentTarget.contains(event.relatedTarget as Node)) setOpen(false);
|
|
47
|
+
}} onKeyDown={event => {
|
|
48
|
+
if (open && event.key === 'Escape') {
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
close();
|
|
51
|
+
}
|
|
52
|
+
}}>
|
|
53
|
+
<button type="button" ref={trigger} className="tw-project-file-menu__save-marker" data-tw-plus-unsaved-marker aria-label={label}
|
|
54
|
+
aria-expanded={actions.length ? open : undefined} disabled={!actions.length}
|
|
55
|
+
onClick={() => setOpen(previous => !previous)}>*</button>
|
|
56
|
+
{!open && <span className="tw-project-file-menu__save-hint" aria-hidden="true">{label}</span>}
|
|
57
|
+
{open && actions.length > 0 && <div className="tw-project-file-menu__save-actions">
|
|
58
|
+
{actions.map(([command, name, action]) => <button type="button" key={command} onClick={() => {
|
|
59
|
+
close();
|
|
60
|
+
action();
|
|
61
|
+
}}>{name}</button>)}
|
|
62
|
+
</div>}
|
|
63
|
+
</div>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default function ProjectFileMenu({locale, MenuItem, MenuSection, close, entries, workspace}: {
|
|
67
|
+
locale: string;
|
|
68
|
+
MenuItem: React.ElementType;
|
|
69
|
+
MenuSection: React.ElementType;
|
|
70
|
+
close: Action;
|
|
71
|
+
workspace?: SaveWorkspace;
|
|
72
|
+
entries: {
|
|
73
|
+
create: Action;
|
|
74
|
+
newWindow?: Action;
|
|
75
|
+
open: Action;
|
|
76
|
+
externalYaml?: React.ReactNode;
|
|
77
|
+
folder?: FolderActions;
|
|
78
|
+
storage: ProjectFileStorage;
|
|
79
|
+
saveAs?: Action;
|
|
80
|
+
saveCommit?: Action;
|
|
81
|
+
exportProject?: Action;
|
|
82
|
+
properties?: Action;
|
|
83
|
+
diagnostics?: Action;
|
|
84
|
+
payloads?: Action;
|
|
85
|
+
extensions?: Action;
|
|
86
|
+
restore: Action;
|
|
87
|
+
git?: React.ReactNode;
|
|
88
|
+
};
|
|
89
|
+
}) {
|
|
90
|
+
const ja = locale.startsWith('ja');
|
|
91
|
+
const [, redraw] = React.useReducer((version: number) => version + 1, 0);
|
|
92
|
+
React.useLayoutEffect(() => workspace?.subscribeSave(redraw), [workspace]);
|
|
93
|
+
const tabShortcut = workspace?.saveScope === 'tab';
|
|
94
|
+
const mac = isMacPlatform();
|
|
95
|
+
const item = ([command, label, action, showShortcut]: Entry) => {
|
|
96
|
+
const run = action && (() => {close(); action();});
|
|
97
|
+
return <MenuItem key={command} command={command} onClick={run}>
|
|
98
|
+
<span className="tw-project-file-menu__item" role="button" aria-disabled={!run || undefined} tabIndex={run ? 0 : -1}
|
|
99
|
+
aria-keyshortcuts={showShortcut ? (mac ? 'Meta+S' : 'Control+S') : undefined}
|
|
100
|
+
style={!run ? {opacity: 0.5, cursor: 'default'} : undefined} onKeyDown={event => {
|
|
101
|
+
if (!run || (event.key !== 'Enter' && event.key !== ' ')) return;
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
run();
|
|
105
|
+
}}>{label}{showShortcut && <kbd className="tw-project-file-menu__shortcut" aria-hidden="true">{mac ? '⌘S' : 'Ctrl+S'}</kbd>}</span>
|
|
106
|
+
</MenuItem>;
|
|
107
|
+
};
|
|
108
|
+
const e = entries;
|
|
109
|
+
return <>
|
|
110
|
+
{item(['new', ja ? '新しいプロジェクトを作成' : 'Create New Project', e.create])}
|
|
111
|
+
{e.newWindow && item(['window', ja ? '新しいウィンドウ' : 'New Window', e.newWindow])}
|
|
112
|
+
<MenuSection>
|
|
113
|
+
{item(['open', ja ? 'SB3ファイルを開く…' : 'Open SB3 File…', e.open])}
|
|
114
|
+
{e.folder && item(['project-folder-open', ja ? 'プロジェクトフォルダを開く…' : 'Open Project Folder…', e.folder.open])}
|
|
115
|
+
{e.git}
|
|
116
|
+
{e.externalYaml}
|
|
117
|
+
</MenuSection>
|
|
118
|
+
<MenuSection>
|
|
119
|
+
{saveEntries(locale, e).map(([command, label, action]) => item([command, label, action,
|
|
120
|
+
command === 'save' && !tabShortcut]))}
|
|
121
|
+
{tabShortcut && item(['save-tab', ja ? 'アクティブなタブを保存' : 'Save Active Tab',
|
|
122
|
+
workspace.canSaveActive ? () => {void workspace.saveActive();} : undefined, true])}
|
|
123
|
+
{e.exportProject && item(['package', ja ? '書き出し…' : 'Export…', e.exportProject])}
|
|
124
|
+
</MenuSection>
|
|
125
|
+
{(e.properties || e.payloads || e.extensions || e.diagnostics) && <MenuSection>
|
|
126
|
+
{([
|
|
127
|
+
['properties', ja ? '作品のプロパティ' : 'Project Properties', e.properties],
|
|
128
|
+
['payloads', ja ? '組み込みデータ…' : 'Project Data…', e.payloads],
|
|
129
|
+
['extension', ja ? '機能拡張…' : 'Extensions…', e.extensions],
|
|
130
|
+
['diagnostics', ja ? '作品の診断…' : 'Project Diagnostics…', e.diagnostics]
|
|
131
|
+
] as Entry[]).filter(([, , callback]) => callback).map(item)}
|
|
132
|
+
</MenuSection>}
|
|
133
|
+
<MenuSection>
|
|
134
|
+
{item(['restore', ja ? '復元ポイント' : 'Restore Points', e.restore])}
|
|
135
|
+
</MenuSection>
|
|
136
|
+
</>;
|
|
137
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, {useEffect, useMemo, useState} from 'react';
|
|
2
|
+
import {projectLoadSnapshot, subscribeProjectLoadProgress} from './project-load-progress.js';
|
|
3
|
+
import type {ProjectLoadPhase} from './project-load-progress.js';
|
|
4
|
+
|
|
5
|
+
const japanese: Record<ProjectLoadPhase, string> = {
|
|
6
|
+
opening: 'プロジェクトの読み込みを準備中…',
|
|
7
|
+
payloads: 'SB3 内の作品データを確認中…',
|
|
8
|
+
archive: 'SB3 を検査・展開中…',
|
|
9
|
+
project: 'プロジェクトを解析中…',
|
|
10
|
+
assets: '画像・音声を読み込み中…',
|
|
11
|
+
extensions: '拡張機能を読み込み中…',
|
|
12
|
+
approval: 'ユーザーの確認待ち…',
|
|
13
|
+
finishing: 'エディターを準備中…'
|
|
14
|
+
};
|
|
15
|
+
const english: Record<ProjectLoadPhase, string> = {
|
|
16
|
+
opening: 'Preparing to open the project…',
|
|
17
|
+
payloads: 'Checking project data in the SB3…',
|
|
18
|
+
archive: 'Validating and unpacking the SB3…',
|
|
19
|
+
project: 'Parsing the project…',
|
|
20
|
+
assets: 'Loading images and sounds…',
|
|
21
|
+
extensions: 'Loading extensions…',
|
|
22
|
+
approval: 'Waiting for your confirmation…',
|
|
23
|
+
finishing: 'Preparing the editor…'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function ProjectLoadProgress({vm, locale, children}: {
|
|
27
|
+
vm: object;
|
|
28
|
+
locale: string;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
}) {
|
|
31
|
+
const [snapshot, setSnapshot] = useState(() => projectLoadSnapshot(vm));
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
let frame: number | undefined;
|
|
34
|
+
const sync = () => setSnapshot(projectLoadSnapshot(vm));
|
|
35
|
+
const unsubscribe = subscribeProjectLoadProgress(vm, () => {
|
|
36
|
+
if (frame !== undefined) return;
|
|
37
|
+
frame = window.requestAnimationFrame(() => {
|
|
38
|
+
frame = undefined;
|
|
39
|
+
sync();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
sync();
|
|
43
|
+
return () => {
|
|
44
|
+
unsubscribe();
|
|
45
|
+
if (frame !== undefined) window.cancelAnimationFrame(frame);
|
|
46
|
+
};
|
|
47
|
+
}, [vm]);
|
|
48
|
+
|
|
49
|
+
const ja = locale.startsWith('ja');
|
|
50
|
+
const labels = ja ? japanese : english;
|
|
51
|
+
const current = snapshot?.current;
|
|
52
|
+
const history = ja ? '読み込み履歴' : 'Loading history';
|
|
53
|
+
const clock = useMemo(() => new Intl.DateTimeFormat(ja ? 'ja' : locale, {
|
|
54
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3, hourCycle: 'h23'
|
|
55
|
+
}), [ja, locale]);
|
|
56
|
+
return <React.Fragment>
|
|
57
|
+
<span hidden={Boolean(current)}>{children}</span>
|
|
58
|
+
{current && <div className="tw-project-load-progress__progress" role="group" tabIndex={0} aria-label={history} data-project-load-progress="">
|
|
59
|
+
<div className="tw-project-load-progress__current" role="status" data-phase={current.phase}>
|
|
60
|
+
{labels[current.phase]}
|
|
61
|
+
{snapshot.assets && ` (${snapshot.assets.finished}/${snapshot.assets.total})`}
|
|
62
|
+
</div>
|
|
63
|
+
<div className="tw-project-load-progress__history" data-project-load-history="">
|
|
64
|
+
<div className="tw-project-load-progress__heading">{history}</div>
|
|
65
|
+
{snapshot.previous.length ? <ol>
|
|
66
|
+
{snapshot.previous.map(({phase, time, elapsed}, index) => <li key={index} data-phase={phase}>
|
|
67
|
+
<time dateTime={new Date(time).toISOString()}>{clock.format(time)}</time>
|
|
68
|
+
<span className="tw-project-load-progress__elapsed">+{(elapsed / 1000).toFixed(2)} {ja ? '秒' : 's'}</span>
|
|
69
|
+
<span>{labels[phase]}</span>
|
|
70
|
+
</li>)}
|
|
71
|
+
</ol> : <div>{ja ? '完了した工程はまだありません。' : 'No previous steps yet.'}</div>}
|
|
72
|
+
</div>
|
|
73
|
+
</div>}
|
|
74
|
+
</React.Fragment>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
.tw-project-load-progress__progress {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: block;
|
|
4
|
+
max-width: min(34rem, 90vw);
|
|
5
|
+
margin-inline: auto;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.tw-project-load-progress__current {
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
white-space: nowrap;
|
|
11
|
+
text-overflow: ellipsis;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tw-project-load-progress__history {
|
|
15
|
+
display: none;
|
|
16
|
+
position: absolute;
|
|
17
|
+
z-index: 1;
|
|
18
|
+
inset-block-start: 100%;
|
|
19
|
+
inset-inline-start: 50%;
|
|
20
|
+
transform: translateX(-50%);
|
|
21
|
+
width: max-content;
|
|
22
|
+
max-width: min(32rem, 90vw);
|
|
23
|
+
max-height: 30vh;
|
|
24
|
+
overflow: auto;
|
|
25
|
+
padding: 0.75rem;
|
|
26
|
+
border: 1px solid var(--ui-black-transparent, #7c838d);
|
|
27
|
+
border-radius: 0.4rem;
|
|
28
|
+
background: var(--popover-background, #222831);
|
|
29
|
+
color: var(--text-primary, white);
|
|
30
|
+
text-align: start;
|
|
31
|
+
font-size: 0.875rem;
|
|
32
|
+
font-weight: normal;
|
|
33
|
+
text-shadow: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.tw-project-load-progress__progress:hover .tw-project-load-progress__history,
|
|
37
|
+
.tw-project-load-progress__progress:focus-within .tw-project-load-progress__history {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.tw-project-load-progress__heading {
|
|
42
|
+
font-weight: 600;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.tw-project-load-progress__history ol {
|
|
46
|
+
margin: 0.4rem 0 0;
|
|
47
|
+
padding-inline-start: 1.4rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.tw-project-load-progress__history li + li {
|
|
51
|
+
margin-block-start: 0.25rem;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.tw-project-load-progress__elapsed {
|
|
55
|
+
margin-inline: 0.6rem;
|
|
56
|
+
font-variant-numeric: tabular-nums;
|
|
57
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export type ProjectLoadPhase = 'opening' | 'payloads' | 'archive' | 'project' |
|
|
2
|
+
'assets' | 'extensions' | 'approval' | 'finishing';
|
|
3
|
+
|
|
4
|
+
interface Step {
|
|
5
|
+
phase: ProjectLoadPhase;
|
|
6
|
+
time: number;
|
|
7
|
+
elapsed: number;
|
|
8
|
+
}
|
|
9
|
+
interface Progress {
|
|
10
|
+
current: Step;
|
|
11
|
+
previous: Step[];
|
|
12
|
+
assets?: {finished: number; total: number};
|
|
13
|
+
}
|
|
14
|
+
type Report = (phase: ProjectLoadPhase, assets?: Progress['assets']) => void;
|
|
15
|
+
interface Load {
|
|
16
|
+
report: Report;
|
|
17
|
+
progress: Progress;
|
|
18
|
+
}
|
|
19
|
+
interface Store {
|
|
20
|
+
active?: Load;
|
|
21
|
+
invoking?: Load;
|
|
22
|
+
listeners: Set<() => void>;
|
|
23
|
+
}
|
|
24
|
+
const stores = new WeakMap<object, Store>();
|
|
25
|
+
|
|
26
|
+
function storeFor(vm: object) {
|
|
27
|
+
let store = stores.get(vm);
|
|
28
|
+
if (!store) {
|
|
29
|
+
store = {listeners: new Set()};
|
|
30
|
+
stores.set(vm, store);
|
|
31
|
+
}
|
|
32
|
+
return store;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function notify(store: Store) {
|
|
36
|
+
for (const listener of store.listeners) {
|
|
37
|
+
try { listener(); } catch { /* Presentation must not change the load result. */ }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function beginProjectLoad(vm: object, input: unknown) {
|
|
42
|
+
// ZIP bytes are the input shared by the editor's local and URL SB3 entry points.
|
|
43
|
+
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input, 0, Math.min(input.byteLength, 2)) : input;
|
|
44
|
+
if (!(bytes instanceof Uint8Array) || bytes[0] !== 0x50 || bytes[1] !== 0x4b) return;
|
|
45
|
+
|
|
46
|
+
const store = storeFor(vm);
|
|
47
|
+
const startedAt = Date.now();
|
|
48
|
+
const start = performance.now();
|
|
49
|
+
let finished = false;
|
|
50
|
+
const load: Load = {
|
|
51
|
+
progress: {current: {phase: 'opening', time: startedAt, elapsed: 0}, previous: []},
|
|
52
|
+
report(phase, assets) {
|
|
53
|
+
if (finished) return;
|
|
54
|
+
const {current, previous, assets: priorAssets} = load.progress;
|
|
55
|
+
if (current.phase !== phase) {
|
|
56
|
+
const elapsed = performance.now() - start;
|
|
57
|
+
load.progress = {current: {phase, elapsed, time: startedAt + elapsed}, previous: [...previous, current], assets};
|
|
58
|
+
} else if (assets && (assets.finished !== priorAssets?.finished || assets.total !== priorAssets?.total)) {
|
|
59
|
+
load.progress = {...load.progress, assets};
|
|
60
|
+
} else if (store.active === load) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
store.active = load;
|
|
64
|
+
notify(store);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
if (!store.active) load.report('opening');
|
|
68
|
+
return {
|
|
69
|
+
invoke<T>(run: () => T) {
|
|
70
|
+
const previous = store.invoking;
|
|
71
|
+
store.invoking = load;
|
|
72
|
+
try { return run(); } finally { store.invoking = previous; }
|
|
73
|
+
},
|
|
74
|
+
finish() {
|
|
75
|
+
finished = true;
|
|
76
|
+
if (store.active !== load) return;
|
|
77
|
+
store.active = undefined;
|
|
78
|
+
notify(store);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Capture the calling load before the VM bridge enters its asynchronous queue.
|
|
84
|
+
export const captureProjectLoad = (vm: object) => stores.get(vm)?.invoking?.report;
|
|
85
|
+
export const projectLoadSnapshot = (vm: object) => stores.get(vm)?.active?.progress;
|
|
86
|
+
export function subscribeProjectLoadProgress(vm: object, listener: () => void) {
|
|
87
|
+
const {listeners} = storeFor(vm);
|
|
88
|
+
listeners.add(listener);
|
|
89
|
+
return () => { listeners.delete(listener); };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function reportProjectAssets(vm: object, finished: number, total: number) {
|
|
93
|
+
const load = stores.get(vm)?.active;
|
|
94
|
+
const phase = load?.progress.current.phase;
|
|
95
|
+
if (total > 0 && (phase === 'opening' || phase === 'project' || phase === 'assets')) {
|
|
96
|
+
load.report('assets', {finished, total});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function reportProjectFinishing(vm: object) {
|
|
101
|
+
stores.get(vm)?.active?.report('finishing');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function duringProjectLoadApproval<T>(vm: object, ask: () => T): Promise<Awaited<T>> {
|
|
105
|
+
const store = stores.get(vm);
|
|
106
|
+
const load = store?.active;
|
|
107
|
+
if (!load) return await ask();
|
|
108
|
+
const {current, assets} = load.progress;
|
|
109
|
+
if (current.phase === 'approval') return await ask();
|
|
110
|
+
load.report('approval');
|
|
111
|
+
try {
|
|
112
|
+
return await ask();
|
|
113
|
+
} finally {
|
|
114
|
+
if (store.active === load && load.progress.current.phase === 'approval') {
|
|
115
|
+
load.report(current.phase, assets);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|