@kubohiroya/turbowarp-plus-editor-workbench 0.15.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.
Files changed (52) hide show
  1. package/NOTICE +26 -0
  2. package/README.ja.md +22 -0
  3. package/README.md +22 -0
  4. package/dist/backpack-script.d.ts +2 -0
  5. package/dist/backpack-script.js +23 -0
  6. package/dist/backpack.d.ts +60 -0
  7. package/dist/backpack.js +226 -0
  8. package/dist/browser-tab-title.d.ts +2 -0
  9. package/dist/browser-tab-title.js +5 -0
  10. package/dist/busy-cursor.d.ts +22 -0
  11. package/dist/busy-cursor.js +107 -0
  12. package/dist/edit-menu.d.ts +57 -0
  13. package/dist/edit-menu.js +99 -0
  14. package/dist/info-menu.d.ts +39 -0
  15. package/dist/info-menu.js +157 -0
  16. package/dist/project-file-dialogs.d.ts +70 -0
  17. package/dist/project-file-dialogs.js +625 -0
  18. package/dist/project-file-menu.d.ts +43 -0
  19. package/dist/project-file-menu.js +90 -0
  20. package/dist/project-load-progress-view.d.ts +6 -0
  21. package/dist/project-load-progress-view.js +66 -0
  22. package/dist/project-load-progress.d.ts +26 -0
  23. package/dist/project-load-progress.js +104 -0
  24. package/dist/project-search-box.d.ts +43 -0
  25. package/dist/project-search-box.js +437 -0
  26. package/dist/project-size-approval.d.ts +10 -0
  27. package/dist/project-size-approval.js +64 -0
  28. package/dist/stage-controls-view.d.ts +45 -0
  29. package/dist/stage-controls-view.js +127 -0
  30. package/dist/stage-controls.d.ts +98 -0
  31. package/dist/stage-controls.js +110 -0
  32. package/package.json +97 -28
  33. package/src/backpack-script.ts +21 -0
  34. package/src/backpack.tsx +260 -0
  35. package/src/browser-tab-title.ts +6 -0
  36. package/src/busy-cursor.ts +108 -0
  37. package/src/edit-menu.css +42 -0
  38. package/src/edit-menu.tsx +139 -0
  39. package/src/info-menu.css +172 -0
  40. package/src/info-menu.tsx +221 -0
  41. package/src/project-file-dialogs.ts +654 -0
  42. package/src/project-file-menu.css +94 -0
  43. package/src/project-file-menu.tsx +137 -0
  44. package/src/project-load-progress-view.tsx +75 -0
  45. package/src/project-load-progress.css +57 -0
  46. package/src/project-load-progress.ts +118 -0
  47. package/src/project-search-box.tsx +469 -0
  48. package/src/project-search.css +116 -0
  49. package/src/project-size-approval.ts +74 -0
  50. package/src/stage-controls-view.tsx +178 -0
  51. package/src/stage-controls.css +192 -0
  52. package/src/stage-controls.ts +124 -0
@@ -0,0 +1,127 @@
1
+ import React from 'react';
2
+ /**
3
+ * The debugger add-on's button, kept on the menu bar on its own rather than in the extension tray:
4
+ * it is always there once the add-on is on, whereas the tray holds what the project's extensions
5
+ * registered. Its add-on icon is a shell prompt; like a browser's own "more tools" entry point it is
6
+ * drawn as "…" instead (see the stylesheet), and given the name and keyboard handling of a button.
7
+ */
8
+ function DebuggerButton({ element, label }) {
9
+ const mount = React.useRef(null);
10
+ React.useLayoutEffect(() => {
11
+ const root = mount.current;
12
+ root.appendChild(element);
13
+ return () => {
14
+ if (element.parentNode === root)
15
+ element.remove();
16
+ };
17
+ }, [element]);
18
+ React.useLayoutEffect(() => {
19
+ const button = element.querySelector('[data-tw-stage-button]');
20
+ if (!button)
21
+ return;
22
+ const activate = (event) => {
23
+ if (event.key !== 'Enter' && event.key !== ' ')
24
+ return;
25
+ event.preventDefault();
26
+ button.click();
27
+ };
28
+ button.setAttribute('role', 'button');
29
+ button.setAttribute('tabindex', '0');
30
+ button.setAttribute('aria-label', label);
31
+ button.title = label;
32
+ button.addEventListener('keydown', activate);
33
+ return () => button.removeEventListener('keydown', activate);
34
+ }, [element, label]);
35
+ return React.createElement("div", { className: "tw-stage-controls__debugger-button", ref: mount });
36
+ }
37
+ /**
38
+ * The stage recorder add-on's control as an icon button, on the menu bar on its own beside the
39
+ * debugger for the same reason: it is always there once the add-on is on. The add-on's own element stays out of the
40
+ * document: it keeps its click handler and writes its state into its text, which this button reads.
41
+ * While idle the button is the icon alone; otherwise the state ("Stop recording", a countdown, ...)
42
+ * is shown beside it so it is clear that recording is in progress and how to stop it.
43
+ */
44
+ function RecordButton({ element, idleText }) {
45
+ const read = () => ({ text: (element.textContent || '').trim(), title: element.title });
46
+ const [state, setState] = React.useState(read);
47
+ React.useEffect(() => {
48
+ setState(read());
49
+ const Observer = element.ownerDocument.defaultView?.MutationObserver ?? MutationObserver;
50
+ const observer = new Observer(() => setState(read()));
51
+ observer.observe(element, { childList: true, characterData: true, subtree: true, attributes: true,
52
+ attributeFilter: ['title'] });
53
+ return () => observer.disconnect();
54
+ }, [element]);
55
+ const busy = state.text !== '' && state.text !== idleText;
56
+ const label = state.text || idleText;
57
+ return (React.createElement("button", { "aria-label": label, "aria-pressed": busy, className: "tw-stage-controls__record-button", "data-addon-stage-control": "mediarecorder", title: state.title || label, type: "button", onClick: () => element.click() },
58
+ React.createElement("span", { "aria-hidden": "true", className: "tw-stage-controls__icon" }, "\uD83C\uDFA5"),
59
+ busy && React.createElement("span", { className: "tw-stage-controls__label" }, state.text)));
60
+ }
61
+ class StageControlsView extends React.PureComponent {
62
+ constructor(props) {
63
+ super(props);
64
+ this.state = this.readService();
65
+ this.handleChange = this.handleChange.bind(this);
66
+ this.mountPanel = this.mountPanel.bind(this);
67
+ }
68
+ readService() {
69
+ const { service } = this.props;
70
+ return { controls: service.snapshot(), panel: service.panel?.() || null, debuggerButton: service.debuggerButton(),
71
+ recordButton: service.recordButton?.() || null };
72
+ }
73
+ bindService() {
74
+ this.unsubscribe?.();
75
+ this.unsubscribe = this.props.service.subscribe(this.handleChange);
76
+ this.handleChange();
77
+ }
78
+ componentDidMount() {
79
+ this.bindService();
80
+ }
81
+ componentDidUpdate(previous) {
82
+ if (previous.service !== this.props.service)
83
+ this.bindService();
84
+ this.mountPanel(this.panelRoot);
85
+ }
86
+ componentWillUnmount() {
87
+ this.unsubscribe?.();
88
+ this.mountPanel(null);
89
+ }
90
+ handleChange() {
91
+ this.setState(this.readService());
92
+ }
93
+ mountPanel(node) {
94
+ const panel = node ? this.state.panel : null;
95
+ if (this.mountedPanel && this.mountedPanel !== panel && this.mountedPanel.parentNode === this.panelRoot) {
96
+ this.panelRoot.removeChild(this.mountedPanel);
97
+ }
98
+ this.panelRoot = node;
99
+ this.mountedPanel = panel;
100
+ if (node && panel && panel.parentNode !== node)
101
+ node.appendChild(panel);
102
+ }
103
+ render() {
104
+ const { isSmall, menuLocale } = this.props;
105
+ const { panel, debuggerButton, recordButton } = this.state;
106
+ // On the menu bar a control is its icon alone, to keep the tray narrow; its label is the
107
+ // tooltip and the accessible name. Beside the stage, where there is room, the text shows too.
108
+ const showText = !isSmall && menuLocale === undefined;
109
+ const buttons = this.state.controls.filter(control => control.visible).map(control => (React.createElement("button", { "aria-expanded": control.expanded, "aria-haspopup": "dialog", "aria-label": control.label, className: "tw-stage-controls__control", "data-extension-stage-control": control.id, "data-runtime-dock-control": control.id, key: control.id, ref: control.ref, title: control.label, type: "button", onClick: control.onClick },
110
+ React.createElement("span", { "aria-hidden": "true", className: "tw-stage-controls__icon" }, control.icon),
111
+ showText && control.text !== '' && React.createElement("span", { className: "tw-stage-controls__label" }, control.text))));
112
+ if (menuLocale === undefined)
113
+ return React.createElement(React.Fragment, null,
114
+ buttons,
115
+ panel && React.createElement("div", { className: "tw-stage-controls__panel", ref: this.mountPanel }));
116
+ if (!buttons.length && !debuggerButton && !recordButton && !panel)
117
+ return null;
118
+ const japanese = /^ja(?:-|$)/i.test(menuLocale);
119
+ return React.createElement(React.Fragment, null,
120
+ recordButton && React.createElement(RecordButton, { element: recordButton.element, idleText: recordButton.idleText }),
121
+ debuggerButton && React.createElement(DebuggerButton, { element: debuggerButton, label: japanese ? 'デバッグ' : 'Debugger' }),
122
+ (buttons.length > 0 || panel) && React.createElement("div", { className: "tw-stage-controls__menu-dock" },
123
+ buttons.length > 0 && React.createElement("div", { className: "tw-stage-controls__control-group", role: "group", "aria-label": japanese ? '機能拡張コントロールボタン領域' : 'Extension controls' }, buttons),
124
+ panel && React.createElement("div", { className: "tw-stage-controls__menu-panel", ref: this.mountPanel })));
125
+ }
126
+ }
127
+ export default StageControlsView;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The stage controls an extension registered, which this distribution owns.
3
+ *
4
+ * The distribution's view subscribes to the service and is placed in the GUI's optional slot.
5
+ * Extensions describe controls; the view owns their markup, styling and DOM lifetime.
6
+ *
7
+ * One service per VM, because two callers need the same one. The controls bar reads the snapshot
8
+ * and `Scratch.gui.stageControls` hands the API to extensions: if those were different services, a
9
+ * control registered through the API would never appear in the bar.
10
+ */
11
+ interface StageControlOptions {
12
+ id: string;
13
+ label: string;
14
+ text?: string;
15
+ icon?: string;
16
+ onClick(): void;
17
+ }
18
+ interface StageControl extends Required<StageControlOptions> {
19
+ visible: boolean;
20
+ expanded: boolean;
21
+ element: HTMLButtonElement | null;
22
+ ref(element: HTMLButtonElement | null): void;
23
+ }
24
+ export interface RecordButton {
25
+ element: HTMLElement;
26
+ idleText: string;
27
+ }
28
+ export declare const createStageControlsService: () => {
29
+ api: Readonly<{
30
+ addButton({ id, label, text, icon, onClick }: StageControlOptions): Readonly<{
31
+ update(state: Partial<Pick<StageControl, "label" | "text" | "visible" | "expanded">>): void;
32
+ focus(): void;
33
+ dispose(): void;
34
+ }>;
35
+ }>;
36
+ setDebuggerButton(element: HTMLElement | null): void;
37
+ debuggerButton: () => HTMLElement;
38
+ /**
39
+ * The stage recorder add-on's control. The add-on keeps the element and writes its state
40
+ * into the element's text; the view shows it as an icon and forwards clicks to it.
41
+ * @param element The add-on's element, or null to remove the control.
42
+ * @param idleText What the element reads while nothing is being recorded.
43
+ */
44
+ setRecordButton(element: HTMLElement | null, idleText?: string): void;
45
+ recordButton: () => RecordButton;
46
+ placePanel(element: HTMLElement | null): void;
47
+ panel: () => HTMLElement;
48
+ snapshot: () => {
49
+ visible: boolean;
50
+ expanded: boolean;
51
+ element: HTMLButtonElement | null;
52
+ ref(element: HTMLButtonElement | null): void;
53
+ id: string;
54
+ label: string;
55
+ text: string;
56
+ icon: string;
57
+ onClick: () => void;
58
+ }[];
59
+ subscribe(listener: () => void): () => boolean;
60
+ clear(): void;
61
+ };
62
+ declare const getStageControls: (vm: {
63
+ on(event: string, listener: () => void): void;
64
+ }) => {
65
+ api: Readonly<{
66
+ addButton({ id, label, text, icon, onClick }: StageControlOptions): Readonly<{
67
+ update(state: Partial<Pick<StageControl, "label" | "text" | "visible" | "expanded">>): void;
68
+ focus(): void;
69
+ dispose(): void;
70
+ }>;
71
+ }>;
72
+ setDebuggerButton(element: HTMLElement | null): void;
73
+ debuggerButton: () => HTMLElement;
74
+ /**
75
+ * The stage recorder add-on's control. The add-on keeps the element and writes its state
76
+ * into the element's text; the view shows it as an icon and forwards clicks to it.
77
+ * @param element The add-on's element, or null to remove the control.
78
+ * @param idleText What the element reads while nothing is being recorded.
79
+ */
80
+ setRecordButton(element: HTMLElement | null, idleText?: string): void;
81
+ recordButton: () => RecordButton;
82
+ placePanel(element: HTMLElement | null): void;
83
+ panel: () => HTMLElement;
84
+ snapshot: () => {
85
+ visible: boolean;
86
+ expanded: boolean;
87
+ element: HTMLButtonElement | null;
88
+ ref(element: HTMLButtonElement | null): void;
89
+ id: string;
90
+ label: string;
91
+ text: string;
92
+ icon: string;
93
+ onClick: () => void;
94
+ }[];
95
+ subscribe(listener: () => void): () => boolean;
96
+ clear(): void;
97
+ };
98
+ export default getStageControls;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The stage controls an extension registered, which this distribution owns.
3
+ *
4
+ * The distribution's view subscribes to the service and is placed in the GUI's optional slot.
5
+ * Extensions describe controls; the view owns their markup, styling and DOM lifetime.
6
+ *
7
+ * One service per VM, because two callers need the same one. The controls bar reads the snapshot
8
+ * and `Scratch.gui.stageControls` hands the API to extensions: if those were different services, a
9
+ * control registered through the API would never appear in the bar.
10
+ */
11
+ const services = new WeakMap();
12
+ export const createStageControlsService = () => {
13
+ const entries = new Map();
14
+ const listeners = new Set();
15
+ const notify = () => listeners.forEach(listener => listener());
16
+ const api = Object.freeze({
17
+ addButton({ id, label, text = '', icon = '↻', onClick }) {
18
+ if (typeof id !== 'string' || !id || typeof label !== 'string' || !label ||
19
+ typeof onClick !== 'function' || typeof text !== 'string' ||
20
+ typeof icon !== 'string')
21
+ throw new TypeError('Invalid stage control');
22
+ const entry = {
23
+ id, label, text, icon, onClick, visible: false, expanded: false, element: null,
24
+ ref(element) { entry.element = element; }
25
+ };
26
+ entries.set(id, entry);
27
+ notify();
28
+ return Object.freeze({
29
+ update(state) {
30
+ if (entries.get(id) !== entry)
31
+ return;
32
+ for (const key of ['label', 'text']) {
33
+ if (typeof state[key] === 'string')
34
+ entry[key] = state[key];
35
+ }
36
+ for (const key of ['visible', 'expanded']) {
37
+ if (typeof state[key] === 'boolean')
38
+ entry[key] = state[key];
39
+ }
40
+ notify();
41
+ },
42
+ focus() {
43
+ if (entries.get(id) === entry && entry.visible && entry.element)
44
+ entry.element.focus();
45
+ },
46
+ dispose() {
47
+ if (entries.get(id) !== entry)
48
+ return;
49
+ entries.delete(id);
50
+ notify();
51
+ }
52
+ });
53
+ }
54
+ });
55
+ // What a control shows while it is expanded. The element belongs to whoever registered the
56
+ // control; this only carries it to the host, which mounts it and nothing more.
57
+ let panel = null;
58
+ // The editor add-ons belong to the VM across project loads.
59
+ let debuggerButton = null;
60
+ let recordButton = null;
61
+ return {
62
+ api,
63
+ setDebuggerButton(element) {
64
+ if (debuggerButton === element)
65
+ return;
66
+ debuggerButton = element;
67
+ notify();
68
+ },
69
+ debuggerButton: () => debuggerButton,
70
+ /**
71
+ * The stage recorder add-on's control. The add-on keeps the element and writes its state
72
+ * into the element's text; the view shows it as an icon and forwards clicks to it.
73
+ * @param element The add-on's element, or null to remove the control.
74
+ * @param idleText What the element reads while nothing is being recorded.
75
+ */
76
+ setRecordButton(element, idleText = '') {
77
+ if (recordButton?.element === element && (!element || recordButton.idleText === idleText))
78
+ return;
79
+ recordButton = element ? { element, idleText } : null;
80
+ notify();
81
+ },
82
+ recordButton: () => recordButton,
83
+ placePanel(element) {
84
+ if (panel === element)
85
+ return;
86
+ panel = element || null;
87
+ notify();
88
+ },
89
+ panel: () => panel,
90
+ snapshot: () => Array.from(entries.values()).map(entry => ({ ...entry })),
91
+ subscribe(listener) {
92
+ listeners.add(listener);
93
+ return () => listeners.delete(listener);
94
+ },
95
+ clear() {
96
+ entries.clear();
97
+ panel = null;
98
+ notify();
99
+ }
100
+ };
101
+ };
102
+ const getStageControls = (vm) => {
103
+ if (!services.has(vm)) {
104
+ const service = createStageControlsService();
105
+ vm.on('PROJECT_LOADED', service.clear);
106
+ services.set(vm, service);
107
+ }
108
+ return services.get(vm);
109
+ };
110
+ export default getStageControls;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "The TurboWarp Plus Editor workbench: layout, dockable sprite tabs, stage, debugger tab and file menu",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
@@ -9,39 +9,97 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "default": "./dist/index.js"
11
11
  },
12
- "./standard-layout": {
13
- "types": "./dist/standard-layout.d.ts",
14
- "default": "./dist/standard-layout.js"
12
+ "./ai-agents": {
13
+ "types": "./dist/ai-agents.d.ts",
14
+ "default": "./dist/ai-agents.js"
15
15
  },
16
- "./stage-surface": {
17
- "types": "./dist/stage-surface.d.ts",
18
- "default": "./dist/stage-surface.js"
16
+ "./backpack": {
17
+ "types": "./dist/backpack.d.ts",
18
+ "default": "./dist/backpack.js"
19
19
  },
20
- "./editor.css": "./src/editor.css",
21
- "./targets.css": "./src/targets.css",
22
- "./project-messages": {
23
- "types": "./dist/project-messages.d.ts",
24
- "default": "./dist/project-messages.js"
20
+ "./browser-tab-title": {
21
+ "types": "./dist/browser-tab-title.d.ts",
22
+ "default": "./dist/browser-tab-title.js"
25
23
  },
26
- "./sprite-tabs": {
27
- "types": "./dist/sprite-tabs.d.ts",
28
- "default": "./dist/sprite-tabs.js"
24
+ "./busy-cursor": {
25
+ "types": "./dist/busy-cursor.d.ts",
26
+ "default": "./dist/busy-cursor.js"
29
27
  },
30
- "./sprite-layout-menu.css": "./src/sprite-layout-menu.css",
31
- "./dockview-styles": "./dist/dockview-styles.js",
32
28
  "./debugger-panel": {
33
29
  "types": "./dist/debugger-panel.d.ts",
34
30
  "default": "./dist/debugger-panel.js"
35
31
  },
36
32
  "./debugger-panel.css": "./src/debugger-panel.css",
37
- "./ai-agents": {
38
- "types": "./dist/ai-agents.d.ts",
39
- "default": "./dist/ai-agents.js"
33
+ "./dockview-styles": "./dist/dockview-styles.js",
34
+ "./edit-menu": {
35
+ "types": "./dist/edit-menu.d.ts",
36
+ "default": "./dist/edit-menu.js"
40
37
  },
38
+ "./edit-menu.css": "./src/edit-menu.css",
39
+ "./editor.css": "./src/editor.css",
41
40
  "./extension-file-menu": {
42
41
  "types": "./dist/extension-file-menu.d.ts",
43
42
  "default": "./dist/extension-file-menu.js"
44
- }
43
+ },
44
+ "./info-menu.css": "./src/info-menu.css",
45
+ "./project-file-dialogs": {
46
+ "types": "./dist/project-file-dialogs.d.ts",
47
+ "default": "./dist/project-file-dialogs.js"
48
+ },
49
+ "./project-file-menu": {
50
+ "types": "./dist/project-file-menu.d.ts",
51
+ "default": "./dist/project-file-menu.js"
52
+ },
53
+ "./project-file-menu.css": "./src/project-file-menu.css",
54
+ "./project-info-menu": {
55
+ "types": "./dist/info-menu.d.ts",
56
+ "default": "./dist/info-menu.js"
57
+ },
58
+ "./project-load-progress": {
59
+ "types": "./dist/project-load-progress.d.ts",
60
+ "default": "./dist/project-load-progress.js"
61
+ },
62
+ "./project-load-progress-view": {
63
+ "types": "./dist/project-load-progress-view.d.ts",
64
+ "default": "./dist/project-load-progress-view.js"
65
+ },
66
+ "./project-load-progress.css": "./src/project-load-progress.css",
67
+ "./project-messages": {
68
+ "types": "./dist/project-messages.d.ts",
69
+ "default": "./dist/project-messages.js"
70
+ },
71
+ "./project-search": {
72
+ "types": "./dist/project-search-box.d.ts",
73
+ "default": "./dist/project-search-box.js"
74
+ },
75
+ "./project-search.css": "./src/project-search.css",
76
+ "./project-size-approval": {
77
+ "types": "./dist/project-size-approval.d.ts",
78
+ "default": "./dist/project-size-approval.js"
79
+ },
80
+ "./sprite-layout-menu.css": "./src/sprite-layout-menu.css",
81
+ "./sprite-tabs": {
82
+ "types": "./dist/sprite-tabs.d.ts",
83
+ "default": "./dist/sprite-tabs.js"
84
+ },
85
+ "./stage-controls": {
86
+ "types": "./dist/stage-controls.d.ts",
87
+ "default": "./dist/stage-controls.js"
88
+ },
89
+ "./stage-controls-view": {
90
+ "types": "./dist/stage-controls-view.d.ts",
91
+ "default": "./dist/stage-controls-view.js"
92
+ },
93
+ "./stage-controls.css": "./src/stage-controls.css",
94
+ "./stage-surface": {
95
+ "types": "./dist/stage-surface.d.ts",
96
+ "default": "./dist/stage-surface.js"
97
+ },
98
+ "./standard-layout": {
99
+ "types": "./dist/standard-layout.d.ts",
100
+ "default": "./dist/standard-layout.js"
101
+ },
102
+ "./targets.css": "./src/targets.css"
45
103
  },
46
104
  "files": [
47
105
  "dist",
@@ -49,7 +107,8 @@
49
107
  "tsconfig.json",
50
108
  "README.md",
51
109
  "README.ja.md",
52
- "LICENSE"
110
+ "LICENSE",
111
+ "NOTICE"
53
112
  ],
54
113
  "scripts": {
55
114
  "build": "tsc -p tsconfig.json && tsc -p example/tsconfig.json",
@@ -58,26 +117,36 @@
58
117
  "test:browser": "npm run build && node --test test/*.browser.ts"
59
118
  },
60
119
  "devDependencies": {
120
+ "@kubohiroya/turbowarp-plus-editor-git": "0.21.0",
121
+ "@kubohiroya/turbowarp-plus-editor-windows": "0.2.0",
61
122
  "@playwright/test": "1.64.1",
62
- "react": "18.3.1",
63
- "react-dom": "18.3.1",
64
- "typescript": "^6.0.3",
65
- "jsdom": "26.1.0",
66
123
  "@types/react": "18.3.31",
67
124
  "@types/react-dom": "18.3.7",
68
- "fake-indexeddb": "6.2.6"
125
+ "fake-indexeddb": "6.2.6",
126
+ "jsdom": "26.1.0",
127
+ "react": "18.3.1",
128
+ "react-dom": "18.3.1",
129
+ "typescript": "^6.0.3"
69
130
  },
70
131
  "repository": {
71
132
  "type": "git",
72
133
  "url": "git+https://github.com/kubohiroya/turbowarp-plus-editor-workbench.git"
73
134
  },
74
135
  "dependencies": {
75
- "@kubohiroya/turbowarp-plus-editor-project-model": "0.1.2",
136
+ "@kubohiroya/turbowarp-plus-editor-project-model": "0.2.0",
76
137
  "@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.5.0",
138
+ "@kubohiroya/turbowarp-script-transfer": "0.1.5",
77
139
  "dockview": "8.8.3"
78
140
  },
79
141
  "peerDependencies": {
142
+ "@kubohiroya/turbowarp-plus-editor-git": ">=0.21.0 <0.22.0",
143
+ "@kubohiroya/turbowarp-plus-editor-windows": ">=0.2.0 <0.3.0",
80
144
  "react": ">=16.14",
81
145
  "react-dom": ">=16.14"
146
+ },
147
+ "peerDependenciesMeta": {
148
+ "@kubohiroya/turbowarp-plus-editor-git": {
149
+ "optional": true
150
+ }
82
151
  }
83
152
  }
@@ -0,0 +1,21 @@
1
+ import {FORMAT, MAX_BYTES, validateScript} from '@kubohiroya/turbowarp-script-transfer';
2
+
3
+ const stockOpcode = /^(motion|looks|sound|event|control|sensing|operator|math|text|colour|note)_|^(text|colour_picker)$/;
4
+
5
+ export const jsonDataUrl = 'data:application/json;base64,';
6
+
7
+ export async function readBackpackScript(url: string, signal?: AbortSignal) {
8
+ if (!url.startsWith(jsonDataUrl)) throw new Error('Unsupported Backpack script URL');
9
+ if (url.length > MAX_BYTES * 2) throw new Error('Backpack script too large');
10
+ const response = await fetch(url, {signal});
11
+ if (!response.ok) throw new Error('Backpack item unavailable');
12
+ const bytes = await response.arrayBuffer();
13
+ if (bytes.byteLength > MAX_BYTES) throw new Error('Backpack script too large');
14
+ const raw = JSON.parse(new TextDecoder().decode(bytes));
15
+ if (!Array.isArray(raw) || !raw.length) throw new Error('Unsupported Backpack script');
16
+ const script = validateScript({format: FORMAT, version: 1, blocks: raw, variables: [], extensionURLs: {}});
17
+ if (script.blocks.some(block => block.comment || !stockOpcode.test(block.opcode))) {
18
+ throw new Error('This Backpack script requires unsupported project dependencies');
19
+ }
20
+ return script;
21
+ }