@kubohiroya/turbowarp-diagnostic-overlay 0.2.0 → 0.3.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/CHANGELOG.md +8 -0
- package/README.md +2 -2
- package/dist/diagnostic-overlay.js +567 -506
- package/docs/index.html +2 -2
- package/docs/ja/index.html +2 -2
- package/package.json +19 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
このプロジェクトの注目すべき変更を記録します。形式は[Keep a Changelog](https://keepachangelog.com/ja/1.1.0/)に基づき、[Semantic Versioning](https://semver.org/lang/ja/)に従います。
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2026-09-10
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- リポジトリスクリプトを`.mjs`からTypeScriptへ移行し、Nodeのネイティブ型ストリッピングで実行するようにしました。
|
|
10
|
+
- `engines.node`を`>=22.18.0`に引き上げました。型ストリッピングがフラグなしで動作する最初のリリースです。
|
|
11
|
+
- ビルドをVite 8および`vite-plugin-turbowarp-extension` 0.3.0へ更新しました。生成される拡張機能バンドルが再生成されます。
|
|
12
|
+
|
|
5
13
|
## [0.2.0] - 2026-08-25
|
|
6
14
|
|
|
7
15
|
### Changed
|
package/README.md
CHANGED
|
@@ -25,13 +25,13 @@ TurboWarp Desktop and allow it to **run without the sandbox**.
|
|
|
25
25
|
When installing from npm, pin the reviewed version:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
28
|
+
pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.3.0
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
The standalone extension is also available from this version-pinned CDN URL:
|
|
32
32
|
|
|
33
33
|
```text
|
|
34
|
-
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
34
|
+
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.3.0/dist/diagnostic-overlay.js
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## Diagnostic JSON
|
|
@@ -7,568 +7,629 @@
|
|
|
7
7
|
(function (Scratch) {
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
var block_definitions_default = {
|
|
11
|
+
extensionName: "Diagnostic Overlay",
|
|
12
|
+
blocks: [
|
|
13
|
+
{
|
|
14
|
+
"opcode": "showDiagnostic",
|
|
15
|
+
"blockType": "COMMAND",
|
|
16
|
+
"text": "show [SEVERITY] diagnostic [CODE]: [MESSAGE]",
|
|
17
|
+
"description": "Displays a simple diagnostic on the TurboWarp stage.",
|
|
18
|
+
"arguments": {
|
|
19
|
+
"SEVERITY": {
|
|
20
|
+
"type": "STRING",
|
|
21
|
+
"defaultValue": "error",
|
|
22
|
+
"menu": "severityMenu"
|
|
23
|
+
},
|
|
24
|
+
"CODE": {
|
|
25
|
+
"type": "STRING",
|
|
26
|
+
"defaultValue": "APP001"
|
|
27
|
+
},
|
|
28
|
+
"MESSAGE": {
|
|
29
|
+
"type": "STRING",
|
|
30
|
+
"defaultValue": "Something went wrong."
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"opcode": "showDiagnosticJson",
|
|
36
|
+
"blockType": "COMMAND",
|
|
37
|
+
"text": "show diagnostic JSON [DIAGNOSTIC]",
|
|
38
|
+
"description": "Validates and displays one structured diagnostic JSON object.",
|
|
39
|
+
"arguments": { "DIAGNOSTIC": {
|
|
40
|
+
"type": "STRING",
|
|
41
|
+
"defaultValue": "{\"severity\":\"error\",\"code\":\"APP001\",\"message\":\"Something went wrong.\"}"
|
|
42
|
+
} }
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"opcode": "clearDiagnosticOverlay",
|
|
46
|
+
"blockType": "COMMAND",
|
|
47
|
+
"text": "clear diagnostic overlay",
|
|
48
|
+
"description": "Removes the current diagnostic overlay without stopping the project.",
|
|
49
|
+
"arguments": {}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"opcode": "diagnosticOverlayVisible",
|
|
53
|
+
"blockType": "BOOLEAN",
|
|
54
|
+
"text": "diagnostic overlay is visible?",
|
|
55
|
+
"description": "Returns whether a diagnostic overlay is currently visible.",
|
|
56
|
+
"disableMonitor": true,
|
|
57
|
+
"arguments": {}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"opcode": "diagnosticSvg",
|
|
61
|
+
"blockType": "REPORTER",
|
|
62
|
+
"text": "diagnostic SVG for JSON [DIAGNOSTIC]",
|
|
63
|
+
"description": "Returns safe SVG text for one diagnostic without displaying it.",
|
|
64
|
+
"disableMonitor": true,
|
|
65
|
+
"arguments": { "DIAGNOSTIC": {
|
|
66
|
+
"type": "STRING",
|
|
67
|
+
"defaultValue": "{\"severity\":\"warning\",\"code\":\"APP002\",\"message\":\"Please check the input.\"}"
|
|
68
|
+
} }
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"opcode": "lastDiagnosticJson",
|
|
72
|
+
"blockType": "REPORTER",
|
|
73
|
+
"text": "last diagnostic JSON",
|
|
74
|
+
"description": "Returns the last displayed normalized diagnostic as JSON, or an empty string.",
|
|
75
|
+
"disableMonitor": true,
|
|
76
|
+
"arguments": {}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
18
79
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/config.ts
|
|
82
|
+
var extensionConfig = {
|
|
83
|
+
id: "kubohiroyadiagnosticoverlay",
|
|
84
|
+
slug: "diagnostic-overlay",
|
|
85
|
+
name: "Diagnostic Overlay",
|
|
86
|
+
description: "Render structured diagnostics as safe SVG overlays on the TurboWarp stage.",
|
|
87
|
+
author: "Hiroya Kubo",
|
|
88
|
+
license: "MPL-2.0",
|
|
89
|
+
unsandboxed: true
|
|
22
90
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
super(`${path}: ${message}`);
|
|
33
|
-
__publicField(this, "path");
|
|
34
|
-
this.path = path;
|
|
35
|
-
this.name = "DiagnosticValidationError";
|
|
36
|
-
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
93
|
+
function _typeof(o) {
|
|
94
|
+
"@babel/helpers - typeof";
|
|
95
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
96
|
+
return typeof o;
|
|
97
|
+
} : function(o) {
|
|
98
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
99
|
+
}, _typeof(o);
|
|
37
100
|
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
103
|
+
function toPrimitive(t, r) {
|
|
104
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
105
|
+
var e = t[Symbol.toPrimitive];
|
|
106
|
+
if (void 0 !== e) {
|
|
107
|
+
var i = e.call(t, r || "default");
|
|
108
|
+
if ("object" != _typeof(i)) return i;
|
|
109
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
110
|
+
}
|
|
111
|
+
return ("string" === r ? String : Number)(t);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
115
|
+
function toPropertyKey(t) {
|
|
116
|
+
var i = toPrimitive(t, "string");
|
|
117
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
121
|
+
function _defineProperty(e, r, t) {
|
|
122
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
123
|
+
value: t,
|
|
124
|
+
enumerable: !0,
|
|
125
|
+
configurable: !0,
|
|
126
|
+
writable: !0
|
|
127
|
+
}) : e[r] = t, e;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/diagnostic.ts
|
|
131
|
+
var DIAGNOSTIC_SEVERITIES = [
|
|
132
|
+
"info",
|
|
133
|
+
"warning",
|
|
134
|
+
"error",
|
|
135
|
+
"fatal"
|
|
136
|
+
];
|
|
137
|
+
var MAX_JSON_LENGTH = 65536;
|
|
138
|
+
var MAX_CODE_LENGTH = 256;
|
|
139
|
+
var MAX_MESSAGE_LENGTH = 16384;
|
|
140
|
+
var MAX_DETAIL_LENGTH = 32768;
|
|
141
|
+
var MAX_SOURCE_NAME_LENGTH = 2048;
|
|
142
|
+
var MAX_EXCERPT_LENGTH = 32768;
|
|
143
|
+
var DiagnosticValidationError = class extends Error {
|
|
144
|
+
constructor(path, message) {
|
|
145
|
+
super(`${path}: ${message}`);
|
|
146
|
+
_defineProperty(this, "path", void 0);
|
|
147
|
+
this.path = path;
|
|
148
|
+
this.name = "DiagnosticValidationError";
|
|
149
|
+
}
|
|
150
|
+
};
|
|
38
151
|
function parseDiagnosticJson(input) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw new DiagnosticValidationError("$", `invalid JSON (${detail})`);
|
|
48
|
-
}
|
|
49
|
-
return normalizeDiagnostic(value);
|
|
152
|
+
if (input.length > MAX_JSON_LENGTH) throw new DiagnosticValidationError("$", `JSON exceeds ${MAX_JSON_LENGTH} characters`);
|
|
153
|
+
let value;
|
|
154
|
+
try {
|
|
155
|
+
value = JSON.parse(input);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw new DiagnosticValidationError("$", `invalid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
158
|
+
}
|
|
159
|
+
return normalizeDiagnostic(value);
|
|
50
160
|
}
|
|
51
161
|
function normalizeDiagnostic(value) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
...source === void 0 ? {} : { source }
|
|
66
|
-
});
|
|
162
|
+
if (!isRecord(value)) throw new DiagnosticValidationError("$", "expected an object");
|
|
163
|
+
const severity = readSeverity(value.severity);
|
|
164
|
+
const code = readRequiredText(value.code, "$.code", MAX_CODE_LENGTH);
|
|
165
|
+
const message = readRequiredText(value.message, "$.message", MAX_MESSAGE_LENGTH);
|
|
166
|
+
const detail = readOptionalText(value.detail, "$.detail", MAX_DETAIL_LENGTH);
|
|
167
|
+
const source = readSource(value.source);
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
severity,
|
|
170
|
+
code,
|
|
171
|
+
message,
|
|
172
|
+
...detail === void 0 ? {} : { detail },
|
|
173
|
+
...source === void 0 ? {} : { source }
|
|
174
|
+
});
|
|
67
175
|
}
|
|
68
176
|
function diagnosticToJson(diagnostic) {
|
|
69
|
-
|
|
177
|
+
return JSON.stringify(diagnostic);
|
|
70
178
|
}
|
|
71
179
|
function readSeverity(value) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!isDiagnosticSeverity(normalized)) {
|
|
77
|
-
throw new DiagnosticValidationError(
|
|
78
|
-
"$.severity",
|
|
79
|
-
`expected one of ${DIAGNOSTIC_SEVERITIES.join(", ")}`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
return normalized;
|
|
180
|
+
if (typeof value !== "string") throw new DiagnosticValidationError("$.severity", "expected a string");
|
|
181
|
+
const normalized = value.trim().toLowerCase();
|
|
182
|
+
if (!isDiagnosticSeverity(normalized)) throw new DiagnosticValidationError("$.severity", `expected one of ${DIAGNOSTIC_SEVERITIES.join(", ")}`);
|
|
183
|
+
return normalized;
|
|
83
184
|
}
|
|
84
185
|
function readSource(value) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
...line === void 0 ? {} : { line },
|
|
99
|
-
...column === void 0 ? {} : { column },
|
|
100
|
-
...excerpt === void 0 ? {} : { excerpt }
|
|
101
|
-
});
|
|
186
|
+
if (value === void 0 || value === null) return void 0;
|
|
187
|
+
if (!isRecord(value)) throw new DiagnosticValidationError("$.source", "expected an object");
|
|
188
|
+
const name = readOptionalText(value.name, "$.source.name", MAX_SOURCE_NAME_LENGTH);
|
|
189
|
+
const line = readOptionalPosition(value.line, "$.source.line");
|
|
190
|
+
const column = readOptionalPosition(value.column, "$.source.column");
|
|
191
|
+
const excerpt = readOptionalText(value.excerpt, "$.source.excerpt", MAX_EXCERPT_LENGTH);
|
|
192
|
+
if (name === void 0 && line === void 0 && column === void 0 && excerpt === void 0) return;
|
|
193
|
+
return Object.freeze({
|
|
194
|
+
...name === void 0 ? {} : { name },
|
|
195
|
+
...line === void 0 ? {} : { line },
|
|
196
|
+
...column === void 0 ? {} : { column },
|
|
197
|
+
...excerpt === void 0 ? {} : { excerpt }
|
|
198
|
+
});
|
|
102
199
|
}
|
|
103
200
|
function readRequiredText(value, path, maxLength) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (normalized.length > maxLength) {
|
|
110
|
-
throw new DiagnosticValidationError(path, `exceeds ${maxLength} characters`);
|
|
111
|
-
}
|
|
112
|
-
return normalized;
|
|
201
|
+
if (typeof value !== "string") throw new DiagnosticValidationError(path, "expected a string");
|
|
202
|
+
const normalized = value.trim();
|
|
203
|
+
if (!normalized) throw new DiagnosticValidationError(path, "must not be empty");
|
|
204
|
+
if (normalized.length > maxLength) throw new DiagnosticValidationError(path, `exceeds ${maxLength} characters`);
|
|
205
|
+
return normalized;
|
|
113
206
|
}
|
|
114
207
|
function readOptionalText(value, path, maxLength) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (normalized.length > maxLength) {
|
|
122
|
-
throw new DiagnosticValidationError(path, `exceeds ${maxLength} characters`);
|
|
123
|
-
}
|
|
124
|
-
return normalized;
|
|
208
|
+
if (value === void 0 || value === null) return void 0;
|
|
209
|
+
if (typeof value !== "string") throw new DiagnosticValidationError(path, "expected a string");
|
|
210
|
+
const normalized = value.trim();
|
|
211
|
+
if (!normalized) return void 0;
|
|
212
|
+
if (normalized.length > maxLength) throw new DiagnosticValidationError(path, `exceeds ${maxLength} characters`);
|
|
213
|
+
return normalized;
|
|
125
214
|
}
|
|
126
215
|
function readOptionalPosition(value, path) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
return value;
|
|
216
|
+
if (value === void 0 || value === null) return void 0;
|
|
217
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new DiagnosticValidationError(path, "expected a positive integer");
|
|
218
|
+
return value;
|
|
132
219
|
}
|
|
133
220
|
function isDiagnosticSeverity(value) {
|
|
134
|
-
|
|
221
|
+
return DIAGNOSTIC_SEVERITIES.includes(value);
|
|
135
222
|
}
|
|
136
223
|
function isRecord(value) {
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
const blockDefinitions = definitions.blocks;
|
|
140
|
-
class DiagnosticOverlayExtension {
|
|
141
|
-
constructor(scratch, controller) {
|
|
142
|
-
__publicField(this, "scratch");
|
|
143
|
-
__publicField(this, "controller");
|
|
144
|
-
__publicField(this, "runtime");
|
|
145
|
-
__publicField(this, "disposed", false);
|
|
146
|
-
__publicField(this, "dispose", () => {
|
|
147
|
-
if (this.disposed) return;
|
|
148
|
-
this.disposed = true;
|
|
149
|
-
this.runtime.off?.("PROJECT_LOADED", this.clearOnProjectLoad);
|
|
150
|
-
this.runtime.off?.("RUNTIME_DISPOSED", this.dispose);
|
|
151
|
-
this.controller.dispose();
|
|
152
|
-
});
|
|
153
|
-
__publicField(this, "clearOnProjectLoad", () => {
|
|
154
|
-
this.controller.clear();
|
|
155
|
-
});
|
|
156
|
-
this.scratch = scratch;
|
|
157
|
-
this.controller = controller;
|
|
158
|
-
this.runtime = scratch.vm.runtime;
|
|
159
|
-
this.runtime.on?.("PROJECT_LOADED", this.clearOnProjectLoad);
|
|
160
|
-
this.runtime.on?.("RUNTIME_DISPOSED", this.dispose);
|
|
161
|
-
}
|
|
162
|
-
getInfo() {
|
|
163
|
-
return {
|
|
164
|
-
id: extensionConfig.id,
|
|
165
|
-
name: this.scratch.translate(definitions.extensionName),
|
|
166
|
-
color1: "#C44747",
|
|
167
|
-
color2: "#A83B3B",
|
|
168
|
-
color3: "#8C3030",
|
|
169
|
-
blocks: blockDefinitions.map((block) => this.toScratchBlock(block)),
|
|
170
|
-
menus: {
|
|
171
|
-
severityMenu: {
|
|
172
|
-
acceptReporters: true,
|
|
173
|
-
items: ["info", "warning", "error", "fatal"]
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
showDiagnostic(args) {
|
|
179
|
-
const diagnostic = {
|
|
180
|
-
severity: this.severity(args.SEVERITY),
|
|
181
|
-
code: this.string(args.CODE),
|
|
182
|
-
message: this.string(args.MESSAGE)
|
|
183
|
-
};
|
|
184
|
-
this.controller.show(diagnostic);
|
|
185
|
-
}
|
|
186
|
-
showDiagnosticJson(args) {
|
|
187
|
-
this.controller.show(parseDiagnosticJson(this.string(args.DIAGNOSTIC)));
|
|
188
|
-
}
|
|
189
|
-
clearDiagnosticOverlay() {
|
|
190
|
-
this.controller.clear();
|
|
191
|
-
}
|
|
192
|
-
diagnosticOverlayVisible() {
|
|
193
|
-
return this.controller.isVisible();
|
|
194
|
-
}
|
|
195
|
-
diagnosticSvg(args) {
|
|
196
|
-
return this.controller.render(parseDiagnosticJson(this.string(args.DIAGNOSTIC)));
|
|
197
|
-
}
|
|
198
|
-
lastDiagnosticJson() {
|
|
199
|
-
return this.controller.lastDiagnosticJson();
|
|
200
|
-
}
|
|
201
|
-
toScratchBlock(block) {
|
|
202
|
-
return {
|
|
203
|
-
opcode: block.opcode,
|
|
204
|
-
blockType: this.scratch.BlockType[block.blockType],
|
|
205
|
-
text: this.scratch.translate(block.text),
|
|
206
|
-
...block.disableMonitor ? { disableMonitor: true } : {},
|
|
207
|
-
arguments: Object.fromEntries(
|
|
208
|
-
Object.entries(block.arguments).map(([name, argument]) => [
|
|
209
|
-
name,
|
|
210
|
-
{
|
|
211
|
-
type: this.scratch.ArgumentType[argument.type],
|
|
212
|
-
defaultValue: argument.defaultValue,
|
|
213
|
-
...argument.menu ? { menu: argument.menu } : {}
|
|
214
|
-
}
|
|
215
|
-
])
|
|
216
|
-
)
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
string(value) {
|
|
220
|
-
return this.scratch.Cast.toString(value);
|
|
221
|
-
}
|
|
222
|
-
severity(value) {
|
|
223
|
-
const severity = this.string(value).trim().toLowerCase();
|
|
224
|
-
if (severity === "info" || severity === "warning" || severity === "error" || severity === "fatal") {
|
|
225
|
-
return severity;
|
|
226
|
-
}
|
|
227
|
-
throw new Error(`Unsupported diagnostic severity: ${severity}`);
|
|
228
|
-
}
|
|
224
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
229
225
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/extension.ts
|
|
228
|
+
var blockDefinitions = block_definitions_default.blocks;
|
|
229
|
+
var DiagnosticOverlayExtension = class {
|
|
230
|
+
constructor(scratch, controller) {
|
|
231
|
+
_defineProperty(this, "scratch", void 0);
|
|
232
|
+
_defineProperty(this, "controller", void 0);
|
|
233
|
+
_defineProperty(this, "runtime", void 0);
|
|
234
|
+
_defineProperty(this, "disposed", false);
|
|
235
|
+
_defineProperty(this, "dispose", () => {
|
|
236
|
+
if (this.disposed) return;
|
|
237
|
+
this.disposed = true;
|
|
238
|
+
this.runtime.off?.("PROJECT_LOADED", this.clearOnProjectLoad);
|
|
239
|
+
this.runtime.off?.("RUNTIME_DISPOSED", this.dispose);
|
|
240
|
+
this.controller.dispose();
|
|
241
|
+
});
|
|
242
|
+
_defineProperty(this, "clearOnProjectLoad", () => {
|
|
243
|
+
this.controller.clear();
|
|
244
|
+
});
|
|
245
|
+
this.scratch = scratch;
|
|
246
|
+
this.controller = controller;
|
|
247
|
+
this.runtime = scratch.vm.runtime;
|
|
248
|
+
this.runtime.on?.("PROJECT_LOADED", this.clearOnProjectLoad);
|
|
249
|
+
this.runtime.on?.("RUNTIME_DISPOSED", this.dispose);
|
|
250
|
+
}
|
|
251
|
+
getInfo() {
|
|
252
|
+
return {
|
|
253
|
+
id: extensionConfig.id,
|
|
254
|
+
name: this.scratch.translate(block_definitions_default.extensionName),
|
|
255
|
+
color1: "#C44747",
|
|
256
|
+
color2: "#A83B3B",
|
|
257
|
+
color3: "#8C3030",
|
|
258
|
+
blocks: blockDefinitions.map((block) => this.toScratchBlock(block)),
|
|
259
|
+
menus: { severityMenu: {
|
|
260
|
+
acceptReporters: true,
|
|
261
|
+
items: [
|
|
262
|
+
"info",
|
|
263
|
+
"warning",
|
|
264
|
+
"error",
|
|
265
|
+
"fatal"
|
|
266
|
+
]
|
|
267
|
+
} }
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
showDiagnostic(args) {
|
|
271
|
+
const diagnostic = {
|
|
272
|
+
severity: this.severity(args.SEVERITY),
|
|
273
|
+
code: this.string(args.CODE),
|
|
274
|
+
message: this.string(args.MESSAGE)
|
|
275
|
+
};
|
|
276
|
+
this.controller.show(diagnostic);
|
|
277
|
+
}
|
|
278
|
+
showDiagnosticJson(args) {
|
|
279
|
+
this.controller.show(parseDiagnosticJson(this.string(args.DIAGNOSTIC)));
|
|
280
|
+
}
|
|
281
|
+
clearDiagnosticOverlay() {
|
|
282
|
+
this.controller.clear();
|
|
283
|
+
}
|
|
284
|
+
diagnosticOverlayVisible() {
|
|
285
|
+
return this.controller.isVisible();
|
|
286
|
+
}
|
|
287
|
+
diagnosticSvg(args) {
|
|
288
|
+
return this.controller.render(parseDiagnosticJson(this.string(args.DIAGNOSTIC)));
|
|
289
|
+
}
|
|
290
|
+
lastDiagnosticJson() {
|
|
291
|
+
return this.controller.lastDiagnosticJson();
|
|
292
|
+
}
|
|
293
|
+
toScratchBlock(block) {
|
|
294
|
+
return {
|
|
295
|
+
opcode: block.opcode,
|
|
296
|
+
blockType: this.scratch.BlockType[block.blockType],
|
|
297
|
+
text: this.scratch.translate(block.text),
|
|
298
|
+
...block.disableMonitor ? { disableMonitor: true } : {},
|
|
299
|
+
arguments: Object.fromEntries(Object.entries(block.arguments).map(([name, argument]) => [name, {
|
|
300
|
+
type: this.scratch.ArgumentType[argument.type],
|
|
301
|
+
defaultValue: argument.defaultValue,
|
|
302
|
+
...argument.menu ? { menu: argument.menu } : {}
|
|
303
|
+
}]))
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
string(value) {
|
|
307
|
+
return this.scratch.Cast.toString(value);
|
|
308
|
+
}
|
|
309
|
+
severity(value) {
|
|
310
|
+
const severity = this.string(value).trim().toLowerCase();
|
|
311
|
+
if (severity === "info" || severity === "warning" || severity === "error" || severity === "fatal") return severity;
|
|
312
|
+
throw new Error(`Unsupported diagnostic severity: ${severity}`);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/svg-renderer.ts
|
|
317
|
+
var DEFAULT_OPTIONS = {
|
|
318
|
+
width: 480,
|
|
319
|
+
height: 360,
|
|
320
|
+
maxMessageLines: 3,
|
|
321
|
+
maxDetailLines: 4,
|
|
322
|
+
maxExcerptLines: 4
|
|
236
323
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
324
|
+
var THEMES = {
|
|
325
|
+
info: {
|
|
326
|
+
accent: "#4CA6FF",
|
|
327
|
+
label: "INFO"
|
|
328
|
+
},
|
|
329
|
+
warning: {
|
|
330
|
+
accent: "#F0C24B",
|
|
331
|
+
label: "WARNING"
|
|
332
|
+
},
|
|
333
|
+
error: {
|
|
334
|
+
accent: "#FF6B6B",
|
|
335
|
+
label: "ERROR"
|
|
336
|
+
},
|
|
337
|
+
fatal: {
|
|
338
|
+
accent: "#FF3B5C",
|
|
339
|
+
label: "FATAL"
|
|
340
|
+
}
|
|
242
341
|
};
|
|
243
|
-
|
|
342
|
+
var INVALID_XML_CHARACTER = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu;
|
|
244
343
|
function renderDiagnosticSvg(input, options = {}) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
parts.push(textElement([sourceLabel], textX, cursorY, smallSize, "#AEB8CA", 600));
|
|
290
|
-
cursorY += Math.round(smallSize * 1.65);
|
|
291
|
-
}
|
|
292
|
-
if (diagnostic.source?.excerpt) {
|
|
293
|
-
const excerptY = cursorY - Math.round(smallSize * 0.78);
|
|
294
|
-
const availableHeight = panelY + panelHeight - padding - excerptY;
|
|
295
|
-
const possibleLines = Math.max(1, Math.floor(availableHeight / (smallSize * 1.35)));
|
|
296
|
-
const excerptLineLimit = Math.min(resolved.maxExcerptLines, possibleLines);
|
|
297
|
-
const excerptPadding = Math.max(8, Math.round(smallSize * 0.8));
|
|
298
|
-
const excerptWidth = textWidth - excerptPadding * 2;
|
|
299
|
-
const excerptLines = truncateLines(
|
|
300
|
-
wrapText(diagnostic.source.excerpt, maxUnits(excerptWidth, smallSize)),
|
|
301
|
-
excerptLineLimit,
|
|
302
|
-
maxUnits(excerptWidth, smallSize)
|
|
303
|
-
);
|
|
304
|
-
const excerptHeight = lineBlockHeight(excerptLines.length, smallSize) + excerptPadding * 2;
|
|
305
|
-
parts.push(
|
|
306
|
-
`<rect x="${textX}" y="${excerptY}" width="${textWidth}" height="${excerptHeight}" rx="5" fill="#090C12" stroke="#303848"/>`,
|
|
307
|
-
textElement(
|
|
308
|
-
excerptLines,
|
|
309
|
-
textX + excerptPadding,
|
|
310
|
-
excerptY + excerptPadding + smallSize,
|
|
311
|
-
smallSize,
|
|
312
|
-
"#E7ECF5",
|
|
313
|
-
400,
|
|
314
|
-
"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
|
|
315
|
-
)
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
parts.push("</svg>");
|
|
319
|
-
return parts.join("");
|
|
344
|
+
const diagnostic = normalizeDiagnostic(input);
|
|
345
|
+
const resolved = resolveOptions(options);
|
|
346
|
+
const theme = THEMES[diagnostic.severity];
|
|
347
|
+
const padding = Math.max(18, Math.round(resolved.width * .055));
|
|
348
|
+
const panelX = Math.max(8, Math.round(resolved.width * .025));
|
|
349
|
+
const panelY = Math.max(8, Math.round(resolved.height * .035));
|
|
350
|
+
const panelWidth = resolved.width - panelX * 2;
|
|
351
|
+
const panelHeight = resolved.height - panelY * 2;
|
|
352
|
+
const textX = panelX + padding;
|
|
353
|
+
const textWidth = panelWidth - padding * 2;
|
|
354
|
+
const titleSize = clamp(Math.round(resolved.height * .047), 13, 18);
|
|
355
|
+
const messageSize = clamp(Math.round(resolved.height * .054), 15, 21);
|
|
356
|
+
const bodySize = clamp(Math.round(resolved.height * .038), 12, 16);
|
|
357
|
+
const smallSize = clamp(Math.round(resolved.height * .033), 11, 14);
|
|
358
|
+
let cursorY = panelY + padding + titleSize;
|
|
359
|
+
const parts = [];
|
|
360
|
+
parts.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${resolved.width} ${resolved.height}" role="img" aria-labelledby="diagnostic-title diagnostic-description">`, `<title id="diagnostic-title">${escapeXml(`${theme.label} ${diagnostic.code}`)}</title>`, `<desc id="diagnostic-description">${escapeXml(accessibleDiagnosticText(diagnostic))}</desc>`, `<rect width="${resolved.width}" height="${resolved.height}" fill="#05070A" fill-opacity="0.42"/>`, `<rect x="${panelX}" y="${panelY}" width="${panelWidth}" height="${panelHeight}" rx="12" fill="#151922" fill-opacity="0.97" stroke="${theme.accent}" stroke-width="2"/>`, `<rect x="${panelX}" y="${panelY}" width="6" height="${panelHeight}" rx="3" fill="${theme.accent}"/>`, textElement([`${theme.label} ${diagnostic.code}`], textX, cursorY, titleSize, theme.accent, 700));
|
|
361
|
+
cursorY += Math.round(messageSize * 1.7);
|
|
362
|
+
const messageLines = truncateLines(wrapText(diagnostic.message, maxUnits(textWidth, messageSize)), resolved.maxMessageLines, maxUnits(textWidth, messageSize));
|
|
363
|
+
parts.push(textElement(messageLines, textX, cursorY, messageSize, "#FFFFFF", 700));
|
|
364
|
+
cursorY += lineBlockHeight(messageLines.length, messageSize) + Math.round(bodySize * .85);
|
|
365
|
+
if (diagnostic.detail) {
|
|
366
|
+
const detailLines = truncateLines(wrapText(diagnostic.detail, maxUnits(textWidth, bodySize)), resolved.maxDetailLines, maxUnits(textWidth, bodySize));
|
|
367
|
+
parts.push(textElement(detailLines, textX, cursorY, bodySize, "#DCE2EE", 400));
|
|
368
|
+
cursorY += lineBlockHeight(detailLines.length, bodySize) + Math.round(smallSize * .9);
|
|
369
|
+
}
|
|
370
|
+
const sourceLabel = formatSource(diagnostic);
|
|
371
|
+
if (sourceLabel) {
|
|
372
|
+
parts.push(textElement([sourceLabel], textX, cursorY, smallSize, "#AEB8CA", 600));
|
|
373
|
+
cursorY += Math.round(smallSize * 1.65);
|
|
374
|
+
}
|
|
375
|
+
if (diagnostic.source?.excerpt) {
|
|
376
|
+
const excerptY = cursorY - Math.round(smallSize * .78);
|
|
377
|
+
const availableHeight = panelY + panelHeight - padding - excerptY;
|
|
378
|
+
const possibleLines = Math.max(1, Math.floor(availableHeight / (smallSize * 1.35)));
|
|
379
|
+
const excerptLineLimit = Math.min(resolved.maxExcerptLines, possibleLines);
|
|
380
|
+
const excerptPadding = Math.max(8, Math.round(smallSize * .8));
|
|
381
|
+
const excerptWidth = textWidth - excerptPadding * 2;
|
|
382
|
+
const excerptLines = truncateLines(wrapText(diagnostic.source.excerpt, maxUnits(excerptWidth, smallSize)), excerptLineLimit, maxUnits(excerptWidth, smallSize));
|
|
383
|
+
const excerptHeight = lineBlockHeight(excerptLines.length, smallSize) + excerptPadding * 2;
|
|
384
|
+
parts.push(`<rect x="${textX}" y="${excerptY}" width="${textWidth}" height="${excerptHeight}" rx="5" fill="#090C12" stroke="#303848"/>`, textElement(excerptLines, textX + excerptPadding, excerptY + excerptPadding + smallSize, smallSize, "#E7ECF5", 400, "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"));
|
|
385
|
+
}
|
|
386
|
+
parts.push("</svg>");
|
|
387
|
+
return parts.join("");
|
|
320
388
|
}
|
|
321
389
|
function accessibleDiagnosticText(diagnostic) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
390
|
+
return [
|
|
391
|
+
diagnostic.severity.toUpperCase(),
|
|
392
|
+
diagnostic.code,
|
|
393
|
+
diagnostic.message,
|
|
394
|
+
diagnostic.detail,
|
|
395
|
+
formatSource(diagnostic),
|
|
396
|
+
diagnostic.source?.excerpt
|
|
397
|
+
].filter((part) => Boolean(part)).join(". ");
|
|
330
398
|
}
|
|
331
399
|
function escapeXml(value) {
|
|
332
|
-
|
|
400
|
+
return value.replace(INVALID_XML_CHARACTER, "�").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
333
401
|
}
|
|
334
402
|
function resolveOptions(options) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
403
|
+
return {
|
|
404
|
+
width: positiveInteger(options.width, DEFAULT_OPTIONS.width, 160, 4096),
|
|
405
|
+
height: positiveInteger(options.height, DEFAULT_OPTIONS.height, 120, 4096),
|
|
406
|
+
maxMessageLines: positiveInteger(options.maxMessageLines, DEFAULT_OPTIONS.maxMessageLines, 1, 12),
|
|
407
|
+
maxDetailLines: positiveInteger(options.maxDetailLines, DEFAULT_OPTIONS.maxDetailLines, 1, 20),
|
|
408
|
+
maxExcerptLines: positiveInteger(options.maxExcerptLines, DEFAULT_OPTIONS.maxExcerptLines, 1, 20)
|
|
409
|
+
};
|
|
342
410
|
}
|
|
343
411
|
function positiveInteger(value, fallback, min, max) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
412
|
+
if (value === void 0) return fallback;
|
|
413
|
+
if (!Number.isFinite(value)) return fallback;
|
|
414
|
+
return clamp(Math.round(value), min, max);
|
|
347
415
|
}
|
|
348
|
-
function textElement(lines, x, y, size, fill, weight, family =
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
).join("");
|
|
353
|
-
return `<text x="${x}" y="${y}" fill="${fill}" font-family="${escapeXml(family)}" font-size="${size}" font-weight="${weight}" xml:space="preserve">${tspans}</text>`;
|
|
416
|
+
function textElement(lines, x, y, size, fill, weight, family = "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif") {
|
|
417
|
+
const lineHeight = Math.round(size * 1.35);
|
|
418
|
+
const tspans = lines.map((line, index) => `<tspan x="${x}" dy="${index === 0 ? 0 : lineHeight}">${escapeXml(line)}</tspan>`).join("");
|
|
419
|
+
return `<text x="${x}" y="${y}" fill="${fill}" font-family="${escapeXml(family)}" font-size="${size}" font-weight="${weight}" xml:space="preserve">${tspans}</text>`;
|
|
354
420
|
}
|
|
355
421
|
function wrapText(value, limit) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
422
|
+
const lines = [];
|
|
423
|
+
for (const paragraph of value.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n")) {
|
|
424
|
+
if (!paragraph) {
|
|
425
|
+
lines.push(" ");
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
let current = "";
|
|
429
|
+
let units = 0;
|
|
430
|
+
for (const character of Array.from(paragraph)) {
|
|
431
|
+
const nextUnits = characterUnits(character);
|
|
432
|
+
if (current && units + nextUnits > limit) {
|
|
433
|
+
lines.push(current.trimEnd());
|
|
434
|
+
current = character.trimStart();
|
|
435
|
+
units = current ? nextUnits : 0;
|
|
436
|
+
} else {
|
|
437
|
+
current += character;
|
|
438
|
+
units += nextUnits;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (current || lines.length === 0) lines.push(current.trimEnd());
|
|
442
|
+
}
|
|
443
|
+
return lines;
|
|
378
444
|
}
|
|
379
445
|
function truncateLines(lines, limit, lineUnits) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
return result;
|
|
446
|
+
if (lines.length <= limit) return lines;
|
|
447
|
+
const result = lines.slice(0, limit);
|
|
448
|
+
const lastIndex = result.length - 1;
|
|
449
|
+
result[lastIndex] = appendEllipsis(result[lastIndex] ?? "", lineUnits);
|
|
450
|
+
return result;
|
|
386
451
|
}
|
|
387
452
|
function appendEllipsis(value, limit) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
return `${result}${ellipsis}`;
|
|
453
|
+
const ellipsis = "…";
|
|
454
|
+
let result = value.trimEnd();
|
|
455
|
+
while (result && textUnits(result) + characterUnits(ellipsis) > limit) result = Array.from(result).slice(0, -1).join("").trimEnd();
|
|
456
|
+
return `${result}${ellipsis}`;
|
|
394
457
|
}
|
|
395
458
|
function characterUnits(character) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
459
|
+
if (/\p{Mark}/u.test(character)) return 0;
|
|
460
|
+
if (/\s/u.test(character)) return .35;
|
|
461
|
+
if (/^[\u0020-\u007e]$/u.test(character)) return .58;
|
|
462
|
+
return 1;
|
|
400
463
|
}
|
|
401
464
|
function textUnits(value) {
|
|
402
|
-
|
|
465
|
+
return Array.from(value).reduce((total, character) => total + characterUnits(character), 0);
|
|
403
466
|
}
|
|
404
467
|
function maxUnits(width, fontSize) {
|
|
405
|
-
|
|
468
|
+
return Math.max(8, width / fontSize);
|
|
406
469
|
}
|
|
407
470
|
function lineBlockHeight(lineCount, fontSize) {
|
|
408
|
-
|
|
471
|
+
return fontSize + Math.max(0, lineCount - 1) * Math.round(fontSize * 1.35);
|
|
409
472
|
}
|
|
410
473
|
function formatSource(diagnostic) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
].filter((part) => part !== void 0).join(", ");
|
|
417
|
-
if (source.name && position) return `${source.name} — ${position}`;
|
|
418
|
-
return source.name ?? (position || void 0);
|
|
474
|
+
const source = diagnostic.source;
|
|
475
|
+
if (!source) return void 0;
|
|
476
|
+
const position = [source.line === void 0 ? void 0 : `line ${source.line}`, source.column === void 0 ? void 0 : `column ${source.column}`].filter((part) => part !== void 0).join(", ");
|
|
477
|
+
if (source.name && position) return `${source.name} — ${position}`;
|
|
478
|
+
return source.name ?? (position || void 0);
|
|
419
479
|
}
|
|
420
480
|
function clamp(value, min, max) {
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
class DiagnosticOverlayController {
|
|
424
|
-
constructor(host, svgOptions = {}) {
|
|
425
|
-
__publicField(this, "host");
|
|
426
|
-
__publicField(this, "svgOptions");
|
|
427
|
-
__publicField(this, "lastDiagnostic", null);
|
|
428
|
-
this.host = host;
|
|
429
|
-
this.svgOptions = svgOptions;
|
|
430
|
-
}
|
|
431
|
-
show(input) {
|
|
432
|
-
const diagnostic = normalizeDiagnostic(input);
|
|
433
|
-
const svg = renderDiagnosticSvg(diagnostic, this.svgOptions);
|
|
434
|
-
this.host.showSvg(svg, accessibleDiagnosticText(diagnostic));
|
|
435
|
-
this.lastDiagnostic = diagnostic;
|
|
436
|
-
return svg;
|
|
437
|
-
}
|
|
438
|
-
render(input) {
|
|
439
|
-
return renderDiagnosticSvg(normalizeDiagnostic(input), this.svgOptions);
|
|
440
|
-
}
|
|
441
|
-
clear() {
|
|
442
|
-
this.host.clear();
|
|
443
|
-
this.lastDiagnostic = null;
|
|
444
|
-
}
|
|
445
|
-
isVisible() {
|
|
446
|
-
return this.host.isVisible();
|
|
447
|
-
}
|
|
448
|
-
lastDiagnosticJson() {
|
|
449
|
-
return this.lastDiagnostic === null ? "" : diagnosticToJson(this.lastDiagnostic);
|
|
450
|
-
}
|
|
451
|
-
dispose() {
|
|
452
|
-
this.lastDiagnostic = null;
|
|
453
|
-
this.host.dispose();
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
class BrowserStageOverlayHost {
|
|
457
|
-
constructor(canvas, document = canvas.ownerDocument) {
|
|
458
|
-
__publicField(this, "canvas");
|
|
459
|
-
__publicField(this, "document");
|
|
460
|
-
__publicField(this, "container");
|
|
461
|
-
__publicField(this, "parent");
|
|
462
|
-
__publicField(this, "window");
|
|
463
|
-
__publicField(this, "resizeObserver", null);
|
|
464
|
-
__publicField(this, "changedParentPosition", false);
|
|
465
|
-
__publicField(this, "previousParentPosition", "");
|
|
466
|
-
__publicField(this, "disposed", false);
|
|
467
|
-
__publicField(this, "updateGeometry", () => {
|
|
468
|
-
if (this.disposed) return;
|
|
469
|
-
const canvasRect = this.canvas.getBoundingClientRect();
|
|
470
|
-
const parentRect = this.parent.getBoundingClientRect();
|
|
471
|
-
const left = canvasRect.left - parentRect.left + this.parent.scrollLeft;
|
|
472
|
-
const top = canvasRect.top - parentRect.top + this.parent.scrollTop;
|
|
473
|
-
Object.assign(this.container.style, {
|
|
474
|
-
left: `${left}px`,
|
|
475
|
-
top: `${top}px`,
|
|
476
|
-
width: `${canvasRect.width}px`,
|
|
477
|
-
height: `${canvasRect.height}px`
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
this.canvas = canvas;
|
|
481
|
-
this.document = document;
|
|
482
|
-
const parent = canvas.parentElement;
|
|
483
|
-
if (!parent) throw new Error("TurboWarp renderer canvas has no parent element.");
|
|
484
|
-
this.parent = parent;
|
|
485
|
-
this.window = document.defaultView;
|
|
486
|
-
this.container = document.createElement("div");
|
|
487
|
-
this.container.dataset.turbowarpDiagnosticOverlay = "true";
|
|
488
|
-
this.container.setAttribute("role", "alert");
|
|
489
|
-
this.container.setAttribute("aria-live", "assertive");
|
|
490
|
-
this.container.hidden = true;
|
|
491
|
-
Object.assign(this.container.style, {
|
|
492
|
-
position: "absolute",
|
|
493
|
-
pointerEvents: "none",
|
|
494
|
-
overflow: "hidden",
|
|
495
|
-
zIndex: "2147483647"
|
|
496
|
-
});
|
|
497
|
-
const position = this.window?.getComputedStyle(parent).position ?? parent.style.position;
|
|
498
|
-
if (!position || position === "static") {
|
|
499
|
-
this.previousParentPosition = parent.style.position;
|
|
500
|
-
parent.style.position = "relative";
|
|
501
|
-
this.changedParentPosition = true;
|
|
502
|
-
}
|
|
503
|
-
parent.append(this.container);
|
|
504
|
-
this.updateGeometry();
|
|
505
|
-
this.window?.addEventListener("resize", this.updateGeometry);
|
|
506
|
-
const ResizeObserverConstructor = this.window?.ResizeObserver;
|
|
507
|
-
if (ResizeObserverConstructor) {
|
|
508
|
-
const resizeObserver = new ResizeObserverConstructor(this.updateGeometry);
|
|
509
|
-
this.resizeObserver = resizeObserver;
|
|
510
|
-
resizeObserver.observe(canvas);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
showSvg(svg, accessibleText) {
|
|
514
|
-
this.ensureActive();
|
|
515
|
-
const Parser = this.window?.DOMParser ?? globalThis.DOMParser;
|
|
516
|
-
if (!Parser) throw new Error("DOMParser is not available.");
|
|
517
|
-
const parsed = new Parser().parseFromString(svg, "image/svg+xml");
|
|
518
|
-
if (parsed.querySelector("parsererror") || parsed.documentElement.localName !== "svg") {
|
|
519
|
-
throw new Error("Generated diagnostic SVG is invalid.");
|
|
520
|
-
}
|
|
521
|
-
const imported = this.document.importNode(
|
|
522
|
-
parsed.documentElement,
|
|
523
|
-
true
|
|
524
|
-
);
|
|
525
|
-
imported.style.width = "100%";
|
|
526
|
-
imported.style.height = "100%";
|
|
527
|
-
imported.style.display = "block";
|
|
528
|
-
this.container.replaceChildren(imported);
|
|
529
|
-
this.container.setAttribute("aria-label", accessibleText);
|
|
530
|
-
this.updateGeometry();
|
|
531
|
-
this.container.hidden = false;
|
|
532
|
-
}
|
|
533
|
-
clear() {
|
|
534
|
-
if (this.disposed) return;
|
|
535
|
-
this.container.hidden = true;
|
|
536
|
-
this.container.removeAttribute("aria-label");
|
|
537
|
-
this.container.replaceChildren();
|
|
538
|
-
}
|
|
539
|
-
isVisible() {
|
|
540
|
-
return !this.disposed && !this.container.hidden;
|
|
541
|
-
}
|
|
542
|
-
dispose() {
|
|
543
|
-
if (this.disposed) return;
|
|
544
|
-
this.disposed = true;
|
|
545
|
-
this.resizeObserver?.disconnect();
|
|
546
|
-
this.resizeObserver = null;
|
|
547
|
-
this.window?.removeEventListener("resize", this.updateGeometry);
|
|
548
|
-
this.container.remove();
|
|
549
|
-
if (this.changedParentPosition && this.parent.style.position === "relative") {
|
|
550
|
-
this.parent.style.position = this.previousParentPosition;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
ensureActive() {
|
|
554
|
-
if (this.disposed) throw new Error("Diagnostic overlay host has been disposed.");
|
|
555
|
-
}
|
|
481
|
+
return Math.min(max, Math.max(min, value));
|
|
556
482
|
}
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/overlay.ts
|
|
485
|
+
var DiagnosticOverlayController = class {
|
|
486
|
+
constructor(host, svgOptions = {}) {
|
|
487
|
+
_defineProperty(this, "host", void 0);
|
|
488
|
+
_defineProperty(this, "svgOptions", void 0);
|
|
489
|
+
_defineProperty(this, "lastDiagnostic", null);
|
|
490
|
+
this.host = host;
|
|
491
|
+
this.svgOptions = svgOptions;
|
|
492
|
+
}
|
|
493
|
+
show(input) {
|
|
494
|
+
const diagnostic = normalizeDiagnostic(input);
|
|
495
|
+
const svg = renderDiagnosticSvg(diagnostic, this.svgOptions);
|
|
496
|
+
this.host.showSvg(svg, accessibleDiagnosticText(diagnostic));
|
|
497
|
+
this.lastDiagnostic = diagnostic;
|
|
498
|
+
return svg;
|
|
499
|
+
}
|
|
500
|
+
render(input) {
|
|
501
|
+
return renderDiagnosticSvg(normalizeDiagnostic(input), this.svgOptions);
|
|
502
|
+
}
|
|
503
|
+
clear() {
|
|
504
|
+
this.host.clear();
|
|
505
|
+
this.lastDiagnostic = null;
|
|
506
|
+
}
|
|
507
|
+
isVisible() {
|
|
508
|
+
return this.host.isVisible();
|
|
509
|
+
}
|
|
510
|
+
lastDiagnosticJson() {
|
|
511
|
+
return this.lastDiagnostic === null ? "" : diagnosticToJson(this.lastDiagnostic);
|
|
512
|
+
}
|
|
513
|
+
dispose() {
|
|
514
|
+
this.lastDiagnostic = null;
|
|
515
|
+
this.host.dispose();
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
var BrowserStageOverlayHost = class {
|
|
519
|
+
constructor(canvas, document = canvas.ownerDocument) {
|
|
520
|
+
_defineProperty(this, "canvas", void 0);
|
|
521
|
+
_defineProperty(this, "document", void 0);
|
|
522
|
+
_defineProperty(this, "container", void 0);
|
|
523
|
+
_defineProperty(this, "parent", void 0);
|
|
524
|
+
_defineProperty(this, "window", void 0);
|
|
525
|
+
_defineProperty(this, "resizeObserver", null);
|
|
526
|
+
_defineProperty(this, "changedParentPosition", false);
|
|
527
|
+
_defineProperty(this, "previousParentPosition", "");
|
|
528
|
+
_defineProperty(this, "disposed", false);
|
|
529
|
+
_defineProperty(this, "updateGeometry", () => {
|
|
530
|
+
if (this.disposed) return;
|
|
531
|
+
const canvasRect = this.canvas.getBoundingClientRect();
|
|
532
|
+
const parentRect = this.parent.getBoundingClientRect();
|
|
533
|
+
const left = canvasRect.left - parentRect.left + this.parent.scrollLeft;
|
|
534
|
+
const top = canvasRect.top - parentRect.top + this.parent.scrollTop;
|
|
535
|
+
Object.assign(this.container.style, {
|
|
536
|
+
left: `${left}px`,
|
|
537
|
+
top: `${top}px`,
|
|
538
|
+
width: `${canvasRect.width}px`,
|
|
539
|
+
height: `${canvasRect.height}px`
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
this.canvas = canvas;
|
|
543
|
+
this.document = document;
|
|
544
|
+
const parent = canvas.parentElement;
|
|
545
|
+
if (!parent) throw new Error("TurboWarp renderer canvas has no parent element.");
|
|
546
|
+
this.parent = parent;
|
|
547
|
+
this.window = document.defaultView;
|
|
548
|
+
this.container = document.createElement("div");
|
|
549
|
+
this.container.dataset.turbowarpDiagnosticOverlay = "true";
|
|
550
|
+
this.container.setAttribute("role", "alert");
|
|
551
|
+
this.container.setAttribute("aria-live", "assertive");
|
|
552
|
+
this.container.hidden = true;
|
|
553
|
+
Object.assign(this.container.style, {
|
|
554
|
+
position: "absolute",
|
|
555
|
+
pointerEvents: "none",
|
|
556
|
+
overflow: "hidden",
|
|
557
|
+
zIndex: "2147483647"
|
|
558
|
+
});
|
|
559
|
+
const position = this.window?.getComputedStyle(parent).position ?? parent.style.position;
|
|
560
|
+
if (!position || position === "static") {
|
|
561
|
+
this.previousParentPosition = parent.style.position;
|
|
562
|
+
parent.style.position = "relative";
|
|
563
|
+
this.changedParentPosition = true;
|
|
564
|
+
}
|
|
565
|
+
parent.append(this.container);
|
|
566
|
+
this.updateGeometry();
|
|
567
|
+
this.window?.addEventListener("resize", this.updateGeometry);
|
|
568
|
+
const ResizeObserverConstructor = this.window?.ResizeObserver;
|
|
569
|
+
if (ResizeObserverConstructor) {
|
|
570
|
+
const resizeObserver = new ResizeObserverConstructor(this.updateGeometry);
|
|
571
|
+
this.resizeObserver = resizeObserver;
|
|
572
|
+
resizeObserver.observe(canvas);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
showSvg(svg, accessibleText) {
|
|
576
|
+
this.ensureActive();
|
|
577
|
+
const Parser = this.window?.DOMParser ?? globalThis.DOMParser;
|
|
578
|
+
if (!Parser) throw new Error("DOMParser is not available.");
|
|
579
|
+
const parsed = new Parser().parseFromString(svg, "image/svg+xml");
|
|
580
|
+
if (parsed.querySelector("parsererror") || parsed.documentElement.localName !== "svg") throw new Error("Generated diagnostic SVG is invalid.");
|
|
581
|
+
const imported = this.document.importNode(parsed.documentElement, true);
|
|
582
|
+
imported.style.width = "100%";
|
|
583
|
+
imported.style.height = "100%";
|
|
584
|
+
imported.style.display = "block";
|
|
585
|
+
this.container.replaceChildren(imported);
|
|
586
|
+
this.container.setAttribute("aria-label", accessibleText);
|
|
587
|
+
this.updateGeometry();
|
|
588
|
+
this.container.hidden = false;
|
|
589
|
+
}
|
|
590
|
+
clear() {
|
|
591
|
+
if (this.disposed) return;
|
|
592
|
+
this.container.hidden = true;
|
|
593
|
+
this.container.removeAttribute("aria-label");
|
|
594
|
+
this.container.replaceChildren();
|
|
595
|
+
}
|
|
596
|
+
isVisible() {
|
|
597
|
+
return !this.disposed && !this.container.hidden;
|
|
598
|
+
}
|
|
599
|
+
dispose() {
|
|
600
|
+
if (this.disposed) return;
|
|
601
|
+
this.disposed = true;
|
|
602
|
+
this.resizeObserver?.disconnect();
|
|
603
|
+
this.resizeObserver = null;
|
|
604
|
+
this.window?.removeEventListener("resize", this.updateGeometry);
|
|
605
|
+
this.container.remove();
|
|
606
|
+
if (this.changedParentPosition && this.parent.style.position === "relative") this.parent.style.position = this.previousParentPosition;
|
|
607
|
+
}
|
|
608
|
+
ensureActive() {
|
|
609
|
+
if (this.disposed) throw new Error("Diagnostic overlay host has been disposed.");
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/composition.ts
|
|
557
614
|
function createDiagnosticOverlayComposition(scratch, options = {}) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
615
|
+
const runtime = scratch.vm.runtime;
|
|
616
|
+
const host = options.host ?? new BrowserStageOverlayHost(runtime.renderer.canvas);
|
|
617
|
+
const controller = new DiagnosticOverlayController(host, {
|
|
618
|
+
width: runtime.stageWidth ?? 480,
|
|
619
|
+
height: runtime.stageHeight ?? 360,
|
|
620
|
+
...options.svg
|
|
621
|
+
});
|
|
622
|
+
return {
|
|
623
|
+
extension: new DiagnosticOverlayExtension(scratch, controller),
|
|
624
|
+
controller,
|
|
625
|
+
host
|
|
626
|
+
};
|
|
570
627
|
}
|
|
571
|
-
|
|
628
|
+
//#endregion
|
|
629
|
+
//#region src/index.ts
|
|
630
|
+
if (extensionConfig.unsandboxed && !Scratch.extensions.unsandboxed) throw new Error(`${extensionConfig.name} must run unsandboxed.`);
|
|
631
|
+
var { extension } = createDiagnosticOverlayComposition(Scratch);
|
|
572
632
|
Scratch.extensions.register(extension);
|
|
633
|
+
//#endregion
|
|
573
634
|
|
|
574
635
|
})(Scratch);
|
package/docs/index.html
CHANGED
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
|
|
50
50
|
<section class="section" id="install">
|
|
51
51
|
<h2>Install the reviewed build</h2>
|
|
52
|
-
<pre><code>pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
52
|
+
<pre><code>pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.3.0</code></pre>
|
|
53
53
|
<p>For the standalone extension, load this pinned URL without sandboxing:</p>
|
|
54
|
-
<pre><code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
54
|
+
<pre><code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.3.0/dist/diagnostic-overlay.js</code></pre>
|
|
55
55
|
</section>
|
|
56
56
|
|
|
57
57
|
<section class="section" id="composition">
|
package/docs/ja/index.html
CHANGED
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
|
|
50
50
|
<section class="section" id="install">
|
|
51
51
|
<h2>レビュー済みビルドを導入</h2>
|
|
52
|
-
<pre><code>pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
52
|
+
<pre><code>pnpm add --save-exact @kubohiroya/turbowarp-diagnostic-overlay@0.3.0</code></pre>
|
|
53
53
|
<p>単独機能拡張は、次の固定URLをサンドボックスなしで読み込みます。</p>
|
|
54
|
-
<pre><code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.
|
|
54
|
+
<pre><code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-diagnostic-overlay@0.3.0/dist/diagnostic-overlay.js</code></pre>
|
|
55
55
|
</section>
|
|
56
56
|
|
|
57
57
|
<section class="section" id="composition">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-diagnostic-overlay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Render structured diagnostics as safe SVG overlays on the TurboWarp stage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"turbowarp",
|
|
@@ -56,9 +56,19 @@
|
|
|
56
56
|
"access": "public",
|
|
57
57
|
"registry": "https://registry.npmjs.org/"
|
|
58
58
|
},
|
|
59
|
-
"packageManager": "pnpm@11.11.0",
|
|
60
59
|
"engines": {
|
|
61
|
-
"node": ">=22.
|
|
60
|
+
"node": ">=22.18.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@eslint/js": "^10.0.1",
|
|
64
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
65
|
+
"@types/node": "^26.1.2",
|
|
66
|
+
"eslint": "^10.8.0",
|
|
67
|
+
"jsdom": "^30.0.1",
|
|
68
|
+
"typescript": "^5.9.3",
|
|
69
|
+
"typescript-eslint": "^8.65.0",
|
|
70
|
+
"vite": "^8.2.2",
|
|
71
|
+
"vitest": "^4.1.10"
|
|
62
72
|
},
|
|
63
73
|
"scripts": {
|
|
64
74
|
"dev": "vite build --watch",
|
|
@@ -68,25 +78,13 @@
|
|
|
68
78
|
"test": "vitest run",
|
|
69
79
|
"test:coverage": "vitest run --coverage",
|
|
70
80
|
"audit": "pnpm audit --prod --audit-level high",
|
|
71
|
-
"docs": "node scripts/generate-readme.
|
|
72
|
-
"docs:check": "node scripts/generate-readme.
|
|
73
|
-
"site:check": "node scripts/check-site.
|
|
81
|
+
"docs": "node scripts/generate-readme.ts",
|
|
82
|
+
"docs:check": "node scripts/generate-readme.ts --check",
|
|
83
|
+
"site:check": "node scripts/check-site.ts",
|
|
74
84
|
"check:dist": "pnpm run build && git diff --exit-code -- dist",
|
|
75
85
|
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
76
86
|
"release:check": "npm publish --dry-run --access public --ignore-scripts",
|
|
77
|
-
"repo:check": "node scripts/check-repo.
|
|
78
|
-
"check": "pnpm run audit && pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run build && pnpm run docs:check && pnpm run site:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check"
|
|
79
|
-
"prepublishOnly": "pnpm run check"
|
|
80
|
-
},
|
|
81
|
-
"devDependencies": {
|
|
82
|
-
"@eslint/js": "^10.0.1",
|
|
83
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.1.1",
|
|
84
|
-
"@types/node": "^26.1.2",
|
|
85
|
-
"eslint": "^10.8.0",
|
|
86
|
-
"jsdom": "^30.0.1",
|
|
87
|
-
"typescript": "^5.9.3",
|
|
88
|
-
"typescript-eslint": "^8.65.0",
|
|
89
|
-
"vite": "^7.3.6",
|
|
90
|
-
"vitest": "^4.1.10"
|
|
87
|
+
"repo:check": "node scripts/check-repo.ts",
|
|
88
|
+
"check": "pnpm run audit && pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run build && pnpm run docs:check && pnpm run site:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check"
|
|
91
89
|
}
|
|
92
|
-
}
|
|
90
|
+
}
|