@kubohiroya/sb3-toolchain 0.11.0 → 0.13.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 (87) hide show
  1. package/CHANGELOG.md +30 -4
  2. package/README.ja.md +17 -1
  3. package/README.md +17 -1
  4. package/dist/archive.d.ts +1 -0
  5. package/dist/archive.js +16 -0
  6. package/dist/archive.js.map +1 -0
  7. package/dist/assert.d.ts +2 -0
  8. package/dist/assert.js +11 -0
  9. package/dist/assert.js.map +1 -0
  10. package/dist/bin.d.ts +1 -0
  11. package/dist/bin.js +12 -0
  12. package/dist/bin.js.map +1 -0
  13. package/dist/build.d.ts +23 -0
  14. package/dist/build.js +111 -0
  15. package/dist/build.js.map +1 -0
  16. package/dist/cli.d.ts +87 -0
  17. package/dist/cli.js +544 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/constants.d.ts +2 -0
  20. package/dist/constants.js +7 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/extension-api-manifest.d.ts +65 -0
  23. package/dist/extension-api-manifest.js +231 -0
  24. package/dist/extension-api-manifest.js.map +1 -0
  25. package/dist/extension-bundle-archive.d.ts +36 -0
  26. package/dist/extension-bundle-archive.js +302 -0
  27. package/dist/extension-bundle-archive.js.map +1 -0
  28. package/dist/extension-bundle-configuration.d.ts +55 -0
  29. package/dist/extension-bundle-configuration.js +200 -0
  30. package/dist/extension-bundle-configuration.js.map +1 -0
  31. package/dist/extension-bundle.d.ts +39 -0
  32. package/dist/extension-bundle.js +580 -0
  33. package/dist/extension-bundle.js.map +1 -0
  34. package/dist/extension-dependencies.d.ts +18 -0
  35. package/dist/extension-dependencies.js +59 -0
  36. package/dist/extension-dependencies.js.map +1 -0
  37. package/dist/extension-id-migration.d.ts +83 -0
  38. package/dist/extension-id-migration.js +292 -0
  39. package/dist/extension-id-migration.js.map +1 -0
  40. package/dist/extension-sync.d.ts +111 -0
  41. package/dist/extension-sync.js +463 -0
  42. package/dist/extension-sync.js.map +1 -0
  43. package/dist/import.d.ts +39 -0
  44. package/dist/import.js +244 -0
  45. package/dist/import.js.map +1 -0
  46. package/dist/index.d.ts +31 -0
  47. package/dist/index.js +18 -0
  48. package/dist/npm-extension-source.d.ts +13 -0
  49. package/dist/npm-extension-source.js +63 -0
  50. package/dist/npm-extension-source.js.map +1 -0
  51. package/dist/output-safety.d.ts +29 -0
  52. package/dist/output-safety.js +213 -0
  53. package/dist/output-safety.js.map +1 -0
  54. package/dist/project-asset-additions.d.ts +29 -0
  55. package/dist/project-asset-additions.js +412 -0
  56. package/dist/project-asset-additions.js.map +1 -0
  57. package/dist/release-snapshot.d.ts +75 -0
  58. package/dist/release-snapshot.js +177 -0
  59. package/dist/release-snapshot.js.map +1 -0
  60. package/dist/source.d.ts +41 -0
  61. package/dist/source.js +282 -0
  62. package/dist/source.js.map +1 -0
  63. package/dist/turbowarp-clean-up.d.ts +18 -0
  64. package/dist/turbowarp-clean-up.js +266 -0
  65. package/dist/turbowarp-clean-up.js.map +1 -0
  66. package/dist/types.d.ts +80 -0
  67. package/package.json +31 -20
  68. package/bin/sb3-toolchain.mjs +0 -9
  69. package/src/archive.js +0 -35
  70. package/src/build.js +0 -188
  71. package/src/cli.js +0 -748
  72. package/src/constants.js +0 -4
  73. package/src/extension-api-manifest.js +0 -336
  74. package/src/extension-bundle-archive.js +0 -422
  75. package/src/extension-bundle-configuration.js +0 -265
  76. package/src/extension-bundle.js +0 -695
  77. package/src/extension-dependencies.js +0 -114
  78. package/src/extension-id-migration.js +0 -496
  79. package/src/extension-sync.js +0 -754
  80. package/src/import.js +0 -397
  81. package/src/index.js +0 -75
  82. package/src/npm-extension-source.js +0 -111
  83. package/src/output-safety.js +0 -322
  84. package/src/project-asset-additions.js +0 -560
  85. package/src/release-snapshot.js +0 -247
  86. package/src/source.js +0 -468
  87. package/src/turbowarp-clean-up.js +0 -295
@@ -0,0 +1,266 @@
1
+ import { assert } from "./assert.js";
2
+ //#region src/turbowarp-clean-up.ts
3
+ var turboWarpCleanUpLayout = Object.freeze({
4
+ columnGap: 96,
5
+ columnTolerance: 256,
6
+ rowGap: 72,
7
+ startX: 48,
8
+ startY: 64
9
+ });
10
+ var minimumBlockHeight = 48;
11
+ var minimumBlockWidth = 160;
12
+ var nestedStackIndent = 64;
13
+ var nestedStackPadding = 24;
14
+ var nextBlockOverlap = 4;
15
+ function isObject(value) {
16
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17
+ }
18
+ function isFiniteNumber(value) {
19
+ return typeof value === "number" && Number.isFinite(value);
20
+ }
21
+ function compareNumbers(left, right) {
22
+ return left < right ? -1 : left > right ? 1 : 0;
23
+ }
24
+ function inputBlockId(input, blocks) {
25
+ if (!Array.isArray(input)) return null;
26
+ for (const value of input.slice(1)) if (typeof value === "string" && Object.hasOwn(blocks, value)) return value;
27
+ return null;
28
+ }
29
+ function displayTextLength(block) {
30
+ let length = typeof block.opcode === "string" ? block.opcode.length : 0;
31
+ if (isObject(block.fields)) {
32
+ for (const field of Object.values(block.fields)) if (Array.isArray(field) && field[0] !== void 0 && field[0] !== null) length += String(field[0]).length;
33
+ }
34
+ if (isObject(block.mutation) && typeof block.mutation.proccode === "string") length += block.mutation.proccode.length;
35
+ return length;
36
+ }
37
+ function inputDisplayTextLength(input, blocks) {
38
+ const childId = inputBlockId(input, blocks);
39
+ if (childId) {
40
+ const child = blocks[childId];
41
+ return isObject(child) ? displayTextLength(child) : 0;
42
+ }
43
+ if (!Array.isArray(input)) return 0;
44
+ for (const value of input.slice(1)) {
45
+ if (!Array.isArray(value) || value.length < 2) continue;
46
+ const displayValue = value[1];
47
+ if (typeof displayValue === "string" || typeof displayValue === "number" || typeof displayValue === "boolean") return String(displayValue).length;
48
+ }
49
+ return 0;
50
+ }
51
+ function verticalChildIds(block, blocks) {
52
+ const childIds = [];
53
+ if (isObject(block.inputs)) for (const [inputName, input] of Object.entries(block.inputs)) {
54
+ const childId = inputBlockId(input, blocks);
55
+ if (childId && /^SUBSTACK/u.test(inputName)) childIds.push(childId);
56
+ }
57
+ if (typeof block.next === "string" && Object.hasOwn(blocks, block.next)) childIds.push(block.next);
58
+ return childIds;
59
+ }
60
+ function measureStack(blockId, blocks) {
61
+ const measured = /* @__PURE__ */ new Map();
62
+ const active = /* @__PURE__ */ new Set();
63
+ const work = [{
64
+ blockId,
65
+ finalize: false
66
+ }];
67
+ while (work.length > 0) {
68
+ const frame = work.pop();
69
+ if (!frame) break;
70
+ const block = blocks[frame.blockId];
71
+ if (measured.has(frame.blockId) || !isObject(block)) continue;
72
+ if (!frame.finalize) {
73
+ if (active.has(frame.blockId)) continue;
74
+ active.add(frame.blockId);
75
+ work.push({
76
+ blockId: frame.blockId,
77
+ finalize: true
78
+ });
79
+ const childIds = verticalChildIds(block, blocks);
80
+ for (let index = childIds.length - 1; index >= 0; index -= 1) {
81
+ const childId = childIds[index];
82
+ if (!active.has(childId) && !measured.has(childId)) work.push({
83
+ blockId: childId,
84
+ finalize: false
85
+ });
86
+ }
87
+ continue;
88
+ }
89
+ let height = minimumBlockHeight;
90
+ let width = Math.max(minimumBlockWidth, 80 + displayTextLength(block) * 8);
91
+ if (isObject(block.inputs)) for (const [inputName, input] of Object.entries(block.inputs)) {
92
+ const childId = inputBlockId(input, blocks);
93
+ if (childId && /^SUBSTACK/u.test(inputName)) {
94
+ const nested = measured.get(childId) ?? {
95
+ height: 0,
96
+ width: 0
97
+ };
98
+ height += nested.height + nestedStackPadding;
99
+ width = Math.max(width, nested.width + nestedStackIndent);
100
+ } else width += 24 + inputDisplayTextLength(input, blocks) * 8;
101
+ }
102
+ if (typeof block.next === "string" && Object.hasOwn(blocks, block.next)) {
103
+ const next = measured.get(block.next) ?? {
104
+ height: 0,
105
+ width: 0
106
+ };
107
+ height += Math.max(0, next.height - nextBlockOverlap);
108
+ width = Math.max(width, next.width);
109
+ }
110
+ measured.set(frame.blockId, {
111
+ height,
112
+ width
113
+ });
114
+ active.delete(frame.blockId);
115
+ }
116
+ return measured.get(blockId) ?? {
117
+ height: 0,
118
+ width: 0
119
+ };
120
+ }
121
+ function groupIntoColumns(scripts) {
122
+ const columns = [];
123
+ for (const script of scripts) {
124
+ let bestColumn = null;
125
+ let bestError = Number(turboWarpCleanUpLayout.columnTolerance);
126
+ for (const column of columns) {
127
+ const error = Math.abs(script.originalX - column.x);
128
+ if (error < bestError) {
129
+ bestColumn = column;
130
+ bestError = error;
131
+ }
132
+ }
133
+ if (bestColumn) {
134
+ bestColumn.count += 1;
135
+ bestColumn.x = (bestColumn.x * (bestColumn.count - 1) + script.originalX) / bestColumn.count;
136
+ bestColumn.scripts.push(script);
137
+ } else columns.push({
138
+ count: 1,
139
+ scripts: [script],
140
+ x: script.originalX
141
+ });
142
+ }
143
+ columns.sort((left, right) => compareNumbers(left.x, right.x));
144
+ for (const column of columns) column.scripts.sort((left, right) => compareNumbers(left.originalY, right.originalY) || compareNumbers(left.inputOrder, right.inputOrder));
145
+ return columns;
146
+ }
147
+ function findTopBlockId(blockId, blocks) {
148
+ const visited = /* @__PURE__ */ new Set();
149
+ let currentId = blockId;
150
+ while (typeof currentId === "string" && !visited.has(currentId)) {
151
+ visited.add(currentId);
152
+ const block = blocks[currentId];
153
+ if (!isObject(block)) return null;
154
+ if (block.topLevel === true || block.parent === null) return currentId;
155
+ currentId = block.parent;
156
+ }
157
+ return null;
158
+ }
159
+ function moveAttachedComments(target, blocks, movements) {
160
+ if (!isObject(target.comments)) return 0;
161
+ let movedCommentCount = 0;
162
+ for (const comment of Object.values(target.comments)) {
163
+ if (!isObject(comment) || typeof comment.blockId !== "string") continue;
164
+ const topBlockId = findTopBlockId(comment.blockId, blocks);
165
+ const movement = topBlockId === null ? void 0 : movements.get(topBlockId);
166
+ if (!movement || !movement.deltaX && !movement.deltaY) continue;
167
+ if (isFiniteNumber(comment.x)) comment.x += movement.deltaX;
168
+ if (isFiniteNumber(comment.y)) comment.y += movement.deltaY;
169
+ movedCommentCount += 1;
170
+ }
171
+ return movedCommentCount;
172
+ }
173
+ function attachedCommentWidths(target, blocks) {
174
+ const widths = /* @__PURE__ */ new Map();
175
+ if (!isObject(target.comments)) return widths;
176
+ for (const comment of Object.values(target.comments)) {
177
+ if (!isObject(comment) || typeof comment.blockId !== "string" || !isFiniteNumber(comment.x) || !isFiniteNumber(comment.width)) continue;
178
+ const topBlockId = findTopBlockId(comment.blockId, blocks);
179
+ if (!topBlockId) continue;
180
+ const topBlock = blocks[topBlockId];
181
+ if (!isObject(topBlock) || !isFiniteNumber(topBlock.x)) continue;
182
+ const width = Math.max(comment.width, comment.x + comment.width - topBlock.x);
183
+ widths.set(topBlockId, Math.max(widths.get(topBlockId) ?? 0, width));
184
+ }
185
+ return widths;
186
+ }
187
+ function cleanUpTarget(target, targetIndex) {
188
+ if (target.blocks === void 0) return {
189
+ movedCommentCount: 0,
190
+ movedScriptCount: 0,
191
+ scriptCount: 0
192
+ };
193
+ assert(isObject(target.blocks), `Project target ${targetIndex} blocks must be an object.`);
194
+ const blocks = target.blocks;
195
+ const scripts = [];
196
+ let inputOrder = 0;
197
+ for (const [blockId, block] of Object.entries(blocks)) {
198
+ if (!isObject(block) || block.topLevel !== true) continue;
199
+ assert(isFiniteNumber(block.x) && isFiniteNumber(block.y), `Top-level block ${JSON.stringify(blockId)} in project target ${targetIndex} requires numeric x and y coordinates.`);
200
+ scripts.push({
201
+ block,
202
+ blockId,
203
+ inputOrder,
204
+ originalX: block.x,
205
+ originalY: block.y,
206
+ size: measureStack(blockId, blocks)
207
+ });
208
+ inputOrder += 1;
209
+ }
210
+ const movements = /* @__PURE__ */ new Map();
211
+ const commentWidths = attachedCommentWidths(target, blocks);
212
+ let cursorX = turboWarpCleanUpLayout.startX;
213
+ let movedScriptCount = 0;
214
+ for (const column of groupIntoColumns(scripts)) {
215
+ let cursorY = turboWarpCleanUpLayout.startY;
216
+ let columnWidth = 0;
217
+ for (const script of column.scripts) {
218
+ const deltaX = cursorX - script.originalX;
219
+ const deltaY = cursorY - script.originalY;
220
+ script.block.x = cursorX;
221
+ script.block.y = cursorY;
222
+ movements.set(script.blockId, {
223
+ deltaX,
224
+ deltaY
225
+ });
226
+ if (deltaX || deltaY) movedScriptCount += 1;
227
+ cursorY += script.size.height + turboWarpCleanUpLayout.rowGap;
228
+ columnWidth = Math.max(columnWidth, script.size.width, commentWidths.get(script.blockId) ?? 0);
229
+ }
230
+ cursorX += columnWidth + turboWarpCleanUpLayout.columnGap;
231
+ }
232
+ return {
233
+ movedCommentCount: moveAttachedComments(target, blocks, movements),
234
+ movedScriptCount,
235
+ scriptCount: scripts.length
236
+ };
237
+ }
238
+ function cleanUpTurboWarpBlocks(project) {
239
+ assert(isObject(project), "TurboWarp project must be an object.");
240
+ assert(Array.isArray(project.targets), "TurboWarp project targets must be an array.");
241
+ const cleanedProject = structuredClone(project);
242
+ const targets = cleanedProject.targets;
243
+ let movedCommentCount = 0;
244
+ let movedScriptCount = 0;
245
+ let scriptCount = 0;
246
+ let targetCount = 0;
247
+ for (const [targetIndex, target] of targets.entries()) {
248
+ assert(isObject(target), `Project target ${targetIndex} must be an object.`);
249
+ const result = cleanUpTarget(target, targetIndex);
250
+ if (result.scriptCount > 0) targetCount += 1;
251
+ movedCommentCount += result.movedCommentCount;
252
+ movedScriptCount += result.movedScriptCount;
253
+ scriptCount += result.scriptCount;
254
+ }
255
+ return {
256
+ movedCommentCount,
257
+ movedScriptCount,
258
+ project: cleanedProject,
259
+ scriptCount,
260
+ targetCount
261
+ };
262
+ }
263
+ //#endregion
264
+ export { cleanUpTurboWarpBlocks, turboWarpCleanUpLayout };
265
+
266
+ //# sourceMappingURL=turbowarp-clean-up.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turbowarp-clean-up.js","names":[],"sources":["../src/turbowarp-clean-up.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {assert} from './assert';\nimport type {ProjectJson, UnknownRecord} from './types';\n\nexport const turboWarpCleanUpLayout = Object.freeze({\n columnGap: 96,\n columnTolerance: 256,\n rowGap: 72,\n startX: 48,\n startY: 64,\n});\n\nconst minimumBlockHeight = 48;\nconst minimumBlockWidth = 160;\nconst nestedStackIndent = 64;\nconst nestedStackPadding = 24;\nconst nextBlockOverlap = 4;\n\ninterface BlockSize {\n height: number;\n width: number;\n}\n\ninterface Script {\n block: UnknownRecord;\n blockId: string;\n inputOrder: number;\n originalX: number;\n originalY: number;\n size: BlockSize;\n}\n\ninterface ScriptColumn {\n count: number;\n scripts: Script[];\n x: number;\n}\n\ninterface ScriptMovement {\n deltaX: number;\n deltaY: number;\n}\n\nexport interface TargetCleanUpResult {\n movedCommentCount: number;\n movedScriptCount: number;\n scriptCount: number;\n}\n\nexport interface TurboWarpCleanUpResult extends TargetCleanUpResult {\n project: ProjectJson;\n targetCount: number;\n}\n\nfunction isObject(value: unknown): value is UnknownRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\nfunction compareNumbers(left: number, right: number): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nfunction inputBlockId(input: unknown, blocks: UnknownRecord): string | null {\n if (!Array.isArray(input)) return null;\n for (const value of (input as unknown[]).slice(1)) {\n if (typeof value === 'string' && Object.hasOwn(blocks, value)) return value;\n }\n return null;\n}\n\nfunction displayTextLength(block: UnknownRecord): number {\n let length = typeof block.opcode === 'string' ? block.opcode.length : 0;\n if (isObject(block.fields)) {\n for (const field of Object.values(block.fields)) {\n if (Array.isArray(field) && field[0] !== undefined && field[0] !== null) {\n length += String(field[0]).length;\n }\n }\n }\n if (isObject(block.mutation) && typeof block.mutation.proccode === 'string') {\n length += block.mutation.proccode.length;\n }\n return length;\n}\n\nfunction inputDisplayTextLength(input: unknown, blocks: UnknownRecord): number {\n const childId = inputBlockId(input, blocks);\n if (childId) {\n const child = blocks[childId];\n return isObject(child) ? displayTextLength(child) : 0;\n }\n if (!Array.isArray(input)) return 0;\n for (const value of (input as unknown[]).slice(1)) {\n if (!Array.isArray(value) || value.length < 2) continue;\n const displayValue: unknown = value[1];\n if (\n typeof displayValue === 'string' ||\n typeof displayValue === 'number' ||\n typeof displayValue === 'boolean'\n ) {\n return String(displayValue).length;\n }\n }\n return 0;\n}\n\nfunction verticalChildIds(block: UnknownRecord, blocks: UnknownRecord): string[] {\n const childIds: string[] = [];\n if (isObject(block.inputs)) {\n for (const [inputName, input] of Object.entries(block.inputs)) {\n const childId = inputBlockId(input, blocks);\n if (childId && /^SUBSTACK/u.test(inputName)) childIds.push(childId);\n }\n }\n if (typeof block.next === 'string' && Object.hasOwn(blocks, block.next)) {\n childIds.push(block.next);\n }\n return childIds;\n}\n\nfunction measureStack(blockId: string, blocks: UnknownRecord): BlockSize {\n const measured = new Map<string, BlockSize>();\n const active = new Set<string>();\n const work: {blockId: string; finalize: boolean}[] = [{blockId, finalize: false}];\n\n while (work.length > 0) {\n const frame = work.pop();\n if (!frame) break;\n const block = blocks[frame.blockId];\n if (measured.has(frame.blockId) || !isObject(block)) continue;\n if (!frame.finalize) {\n if (active.has(frame.blockId)) continue;\n active.add(frame.blockId);\n work.push({blockId: frame.blockId, finalize: true});\n const childIds = verticalChildIds(block, blocks);\n for (let index = childIds.length - 1; index >= 0; index -= 1) {\n const childId = childIds[index];\n if (!active.has(childId) && !measured.has(childId)) {\n work.push({blockId: childId, finalize: false});\n }\n }\n continue;\n }\n\n let height = minimumBlockHeight;\n let width = Math.max(minimumBlockWidth, 80 + displayTextLength(block) * 8);\n if (isObject(block.inputs)) {\n for (const [inputName, input] of Object.entries(block.inputs)) {\n const childId = inputBlockId(input, blocks);\n if (childId && /^SUBSTACK/u.test(inputName)) {\n const nested = measured.get(childId) ?? {height: 0, width: 0};\n height += nested.height + nestedStackPadding;\n width = Math.max(width, nested.width + nestedStackIndent);\n } else {\n width += 24 + inputDisplayTextLength(input, blocks) * 8;\n }\n }\n }\n if (typeof block.next === 'string' && Object.hasOwn(blocks, block.next)) {\n const next = measured.get(block.next) ?? {height: 0, width: 0};\n height += Math.max(0, next.height - nextBlockOverlap);\n width = Math.max(width, next.width);\n }\n measured.set(frame.blockId, {height, width});\n active.delete(frame.blockId);\n }\n\n return measured.get(blockId) ?? {height: 0, width: 0};\n}\n\nfunction groupIntoColumns(scripts: Script[]): ScriptColumn[] {\n const columns: ScriptColumn[] = [];\n for (const script of scripts) {\n let bestColumn: ScriptColumn | null = null;\n let bestError = Number(turboWarpCleanUpLayout.columnTolerance);\n for (const column of columns) {\n const error = Math.abs(script.originalX - column.x);\n if (error < bestError) {\n bestColumn = column;\n bestError = error;\n }\n }\n if (bestColumn) {\n bestColumn.count += 1;\n bestColumn.x = (bestColumn.x * (bestColumn.count - 1) + script.originalX) / bestColumn.count;\n bestColumn.scripts.push(script);\n } else {\n columns.push({count: 1, scripts: [script], x: script.originalX});\n }\n }\n columns.sort((left, right) => compareNumbers(left.x, right.x));\n for (const column of columns) {\n column.scripts.sort(\n (left, right) =>\n compareNumbers(left.originalY, right.originalY) ||\n compareNumbers(left.inputOrder, right.inputOrder),\n );\n }\n return columns;\n}\n\nfunction findTopBlockId(blockId: unknown, blocks: UnknownRecord): string | null {\n const visited = new Set<string>();\n let currentId: unknown = blockId;\n while (typeof currentId === 'string' && !visited.has(currentId)) {\n visited.add(currentId);\n const block = blocks[currentId];\n if (!isObject(block)) return null;\n if (block.topLevel === true || block.parent === null) return currentId;\n currentId = block.parent;\n }\n return null;\n}\n\nfunction moveAttachedComments(\n target: UnknownRecord,\n blocks: UnknownRecord,\n movements: Map<string, ScriptMovement>,\n): number {\n if (!isObject(target.comments)) return 0;\n let movedCommentCount = 0;\n for (const comment of Object.values(target.comments)) {\n if (!isObject(comment) || typeof comment.blockId !== 'string') continue;\n const topBlockId = findTopBlockId(comment.blockId, blocks);\n const movement = topBlockId === null ? undefined : movements.get(topBlockId);\n if (!movement || (!movement.deltaX && !movement.deltaY)) continue;\n if (isFiniteNumber(comment.x)) comment.x += movement.deltaX;\n if (isFiniteNumber(comment.y)) comment.y += movement.deltaY;\n movedCommentCount += 1;\n }\n return movedCommentCount;\n}\n\nfunction attachedCommentWidths(target: UnknownRecord, blocks: UnknownRecord): Map<string, number> {\n const widths = new Map<string, number>();\n if (!isObject(target.comments)) return widths;\n for (const comment of Object.values(target.comments)) {\n if (\n !isObject(comment) ||\n typeof comment.blockId !== 'string' ||\n !isFiniteNumber(comment.x) ||\n !isFiniteNumber(comment.width)\n ) {\n continue;\n }\n const topBlockId = findTopBlockId(comment.blockId, blocks);\n if (!topBlockId) continue;\n const topBlock = blocks[topBlockId];\n if (!isObject(topBlock) || !isFiniteNumber(topBlock.x)) continue;\n const width = Math.max(comment.width, comment.x + comment.width - topBlock.x);\n widths.set(topBlockId, Math.max(widths.get(topBlockId) ?? 0, width));\n }\n return widths;\n}\n\nfunction cleanUpTarget(target: UnknownRecord, targetIndex: number): TargetCleanUpResult {\n if (target.blocks === undefined) {\n return {movedCommentCount: 0, movedScriptCount: 0, scriptCount: 0};\n }\n assert(isObject(target.blocks), `Project target ${targetIndex} blocks must be an object.`);\n const blocks = target.blocks;\n const scripts: Script[] = [];\n let inputOrder = 0;\n for (const [blockId, block] of Object.entries(blocks)) {\n if (!isObject(block) || block.topLevel !== true) continue;\n assert(\n isFiniteNumber(block.x) && isFiniteNumber(block.y),\n `Top-level block ${JSON.stringify(blockId)} in project target ${targetIndex} requires numeric x and y coordinates.`,\n );\n scripts.push({\n block,\n blockId,\n inputOrder,\n originalX: block.x,\n originalY: block.y,\n size: measureStack(blockId, blocks),\n });\n inputOrder += 1;\n }\n\n const movements = new Map<string, ScriptMovement>();\n const commentWidths = attachedCommentWidths(target, blocks);\n let cursorX: number = turboWarpCleanUpLayout.startX;\n let movedScriptCount = 0;\n for (const column of groupIntoColumns(scripts)) {\n let cursorY: number = turboWarpCleanUpLayout.startY;\n let columnWidth = 0;\n for (const script of column.scripts) {\n const deltaX = cursorX - script.originalX;\n const deltaY = cursorY - script.originalY;\n script.block.x = cursorX;\n script.block.y = cursorY;\n movements.set(script.blockId, {deltaX, deltaY});\n if (deltaX || deltaY) movedScriptCount += 1;\n cursorY += script.size.height + turboWarpCleanUpLayout.rowGap;\n columnWidth = Math.max(\n columnWidth,\n script.size.width,\n commentWidths.get(script.blockId) ?? 0,\n );\n }\n cursorX += columnWidth + turboWarpCleanUpLayout.columnGap;\n }\n\n return {\n movedCommentCount: moveAttachedComments(target, blocks, movements),\n movedScriptCount,\n scriptCount: scripts.length,\n };\n}\n\nexport function cleanUpTurboWarpBlocks(project: ProjectJson): TurboWarpCleanUpResult {\n assert(isObject(project), 'TurboWarp project must be an object.');\n assert(Array.isArray(project.targets), 'TurboWarp project targets must be an array.');\n const cleanedProject = structuredClone(project);\n const targets = cleanedProject.targets as unknown[];\n let movedCommentCount = 0;\n let movedScriptCount = 0;\n let scriptCount = 0;\n let targetCount = 0;\n\n for (const [targetIndex, target] of targets.entries()) {\n assert(isObject(target), `Project target ${targetIndex} must be an object.`);\n const result = cleanUpTarget(target, targetIndex);\n if (result.scriptCount > 0) targetCount += 1;\n movedCommentCount += result.movedCommentCount;\n movedScriptCount += result.movedScriptCount;\n scriptCount += result.scriptCount;\n }\n\n return {\n movedCommentCount,\n movedScriptCount,\n project: cleanedProject,\n scriptCount,\n targetCount,\n };\n}\n"],"mappings":";;AAKA,IAAa,yBAAyB,OAAO,OAAO;CAClD,WAAW;CACX,iBAAiB;CACjB,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV,CAAC;AAED,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AAsCzB,SAAS,SAAS,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,eAAe,OAAiC;CACvD,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAC3D;AAEA,SAAS,eAAe,MAAc,OAAuB;CAC3D,OAAO,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I,mBAAmB;CACvB,KAAK,MAAM,UAAU,iBAAiB,OAAO,GAAG;EAC9C,IAAI,UAAkB,uBAAuB;EAC7C,IAAI,cAAc;EAClB,KAAK,MAAM,UAAU,OAAO,SAAS;GACnC,MAAM,SAAS,UAAU,OAAO;GAChC,MAAM,SAAS,UAAU,OAAO;GAChC,OAAO,MAAM,IAAI;GACjB,OAAO,MAAM,IAAI;GACjB,UAAU,IAAI,OAAO,SAAS;IAAC;IAAQ;GAAM,CAAC;GAC9C,IAAI,UAAU,QAAQ,oBAAoB;GAC1C,WAAW,OAAO,KAAK,SAAS,uBAAuB;GACvD,cAAc,KAAK,IACjB,aACA,OAAO,KAAK,OACZ,cAAc,IAAI,OAAO,OAAO,KAAK,CACvC;EACF;EACA,WAAW,cAAc,uBAAuB;CAClD;CAEA,OAAO;EACL,mBAAmB,qBAAqB,QAAQ,QAAQ,SAAS;EACjE;EACA,aAAa,QAAQ;CACvB;AACF;AAEA,SAAgB,uBAAuB,SAA8C;CACnF,OAAO,SAAS,OAAO,GAAG,sCAAsC;CAChE,OAAO,MAAM,QAAQ,QAAQ,OAAO,GAAG,6CAA6C;CACpF,MAAM,iBAAiB,gBAAgB,OAAO;CAC9C,MAAM,UAAU,eAAe;CAC/B,IAAI,oBAAoB;CACxB,IAAI,mBAAmB;CACvB,IAAI,cAAc;CAClB,IAAI,cAAc;CAElB,KAAK,MAAM,CAAC,aAAa,WAAW,QAAQ,QAAQ,GAAG;EACrD,OAAO,SAAS,MAAM,GAAG,kBAAkB,YAAY,oBAAoB;EAC3E,MAAM,SAAS,cAAc,QAAQ,WAAW;EAChD,IAAI,OAAO,cAAc,GAAG,eAAe;EAC3C,qBAAqB,OAAO;EAC5B,oBAAoB,OAAO;EAC3B,eAAe,OAAO;CACxB;CAEA,OAAO;EACL;EACA;EACA,SAAS;EACT;EACA;CACF;AACF"}
@@ -0,0 +1,80 @@
1
+ /** Shapes shared across the expanded source format, the CLI, and the SB3 builders. */
2
+ export interface ExtensionApiManifestSource {
3
+ artifact: string;
4
+ path: string;
5
+ formatVersion: number;
6
+ integrity: string;
7
+ }
8
+ export interface GitHubExtensionSource {
9
+ provider: 'github';
10
+ repository: string;
11
+ ref: string;
12
+ resolvedCommit: string;
13
+ artifact: string;
14
+ integrity: string;
15
+ apiManifest?: ExtensionApiManifestSource;
16
+ }
17
+ export interface NpmExtensionSource {
18
+ provider: 'npm';
19
+ package: string;
20
+ version: string;
21
+ artifact: string;
22
+ integrity: string;
23
+ apiManifest?: ExtensionApiManifestSource;
24
+ }
25
+ export type ExtensionSource = GitHubExtensionSource | NpmExtensionSource;
26
+ export type ExtensionEncoding = 'base64' | 'percent';
27
+ export interface EmbeddedExtension {
28
+ id: string;
29
+ path: string;
30
+ mediaType: string;
31
+ parameters: string[];
32
+ encoding: ExtensionEncoding;
33
+ source?: ExtensionSource;
34
+ }
35
+ export interface ExtensionBundleConfiguration {
36
+ id: string;
37
+ name: string;
38
+ members: string[];
39
+ recoveryCapsule?: boolean;
40
+ }
41
+ export interface EmbeddedExtensionManifest {
42
+ formatVersion: number;
43
+ extensions: EmbeddedExtension[];
44
+ extensionBundles?: ExtensionBundleConfiguration[];
45
+ }
46
+ export interface Sb3SourceManifest {
47
+ formatVersion: number;
48
+ project: string;
49
+ embeddedExtensions: string;
50
+ assetsDirectory: string;
51
+ archiveEntries: string[];
52
+ }
53
+ /**
54
+ * `project.json` is treated as an opaque record whose known members are narrowed on demand.
55
+ * Unknown members are preserved verbatim so builds stay byte-for-byte reproducible.
56
+ */
57
+ export interface ProjectJson {
58
+ targets?: unknown;
59
+ extensions?: unknown;
60
+ extensionURLs?: Record<string, unknown>;
61
+ monitors?: unknown;
62
+ [key: string]: unknown;
63
+ }
64
+ export interface ProjectAssetReference {
65
+ assetId?: unknown;
66
+ dataFormat?: unknown;
67
+ md5ext?: unknown;
68
+ name?: unknown;
69
+ [key: string]: unknown;
70
+ }
71
+ export interface ProjectTarget {
72
+ isStage?: unknown;
73
+ name?: unknown;
74
+ costumes?: unknown;
75
+ sounds?: unknown;
76
+ blocks?: unknown;
77
+ comments?: unknown;
78
+ [key: string]: unknown;
79
+ }
80
+ export type UnknownRecord = Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/sb3-toolchain",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Git-friendly source management and deterministic builds for Scratch 3 and TurboWarp SB3 projects",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
@@ -14,18 +14,20 @@
14
14
  "url": "https://github.com/kubohiroya/sb3-toolchain/issues"
15
15
  },
16
16
  "exports": {
17
- ".": "./src/index.js",
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
18
21
  "./package.json": "./package.json"
19
22
  },
20
23
  "bin": {
21
- "sb3-toolchain": "bin/sb3-toolchain.mjs"
24
+ "sb3-toolchain": "./dist/bin.js"
22
25
  },
23
26
  "files": [
24
- "bin/",
27
+ "dist/",
25
28
  "docs/",
26
29
  "repo-policy.json",
27
30
  "CHANGELOG.md",
28
- "src/",
29
31
  "README.md",
30
32
  "README.ja.md",
31
33
  "LICENSE"
@@ -34,6 +36,21 @@
34
36
  "access": "public",
35
37
  "registry": "https://registry.npmjs.org/"
36
38
  },
39
+ "packageManager": "pnpm@11.11.0",
40
+ "scripts": {
41
+ "build": "vite build",
42
+ "lint": "eslint .",
43
+ "format": "prettier --check .github docs scripts src test CHANGELOG.md eslint.config.ts package.json README.md README.ja.md repo-policy.json tsconfig.json vite.config.ts",
44
+ "format:write": "prettier --write .github docs scripts src test CHANGELOG.md eslint.config.ts package.json README.md README.ja.md repo-policy.json tsconfig.json vite.config.ts",
45
+ "typecheck": "tsc --project tsconfig.json",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest",
48
+ "pack:check": "npm pack --dry-run --ignore-scripts",
49
+ "release:check": "npm publish --dry-run --access public",
50
+ "repo:check": "node --experimental-strip-types scripts/check-repo.ts",
51
+ "check": "pnpm run lint && pnpm run format && pnpm run typecheck && pnpm run test && pnpm run build && pnpm run repo:check && pnpm run pack:check",
52
+ "prepack": "pnpm run check"
53
+ },
37
54
  "dependencies": {
38
55
  "fflate": "0.8.3",
39
56
  "music-metadata": "11.14.0",
@@ -41,13 +58,18 @@
41
58
  },
42
59
  "devDependencies": {
43
60
  "@types/node": "^24.0.0",
61
+ "@vitest/eslint-plugin": "^1.6.27",
44
62
  "eslint": "^9.0.0",
63
+ "jiti": "^2.7.0",
45
64
  "prettier": "^3.0.0",
46
65
  "typescript": "^5.9.0",
47
- "typescript-eslint": "^8.70.0"
66
+ "typescript-eslint": "^8.69.0",
67
+ "vite": "^8.2.2",
68
+ "vite-plugin-dts": "^5.1.0",
69
+ "vitest": "^5.0.0"
48
70
  },
49
71
  "engines": {
50
- "node": ">=22.18.0"
72
+ "node": ">=22.12.0"
51
73
  },
52
74
  "keywords": [
53
75
  "sb3",
@@ -55,16 +77,5 @@
55
77
  "turbowarp",
56
78
  "source-control",
57
79
  "reproducible-builds"
58
- ],
59
- "scripts": {
60
- "lint": "eslint src bin scripts test",
61
- "format": "prettier --check .github bin docs scripts src test CHANGELOG.md package.json README.md README.ja.md repo-policy.json tsconfig.json",
62
- "format:write": "prettier --write .github bin docs scripts src test CHANGELOG.md package.json README.md README.ja.md repo-policy.json tsconfig.json",
63
- "typecheck": "tsc --project tsconfig.json",
64
- "test": "node --test test/*.test.mjs",
65
- "pack:check": "npm pack --dry-run --ignore-scripts",
66
- "release:check": "npm publish --dry-run --access public",
67
- "repo:check": "node scripts/check-repo.ts",
68
- "check": "pnpm run lint && pnpm run format && pnpm run typecheck && pnpm run test && pnpm run repo:check && pnpm run pack:check"
69
- }
70
- }
80
+ ]
81
+ }
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- // SPDX-License-Identifier: MPL-2.0
3
-
4
- import {runCli} from '../src/cli.js';
5
-
6
- runCli(process.argv.slice(2)).catch((error) => {
7
- console.error(error.message);
8
- process.exitCode = 1;
9
- });
package/src/archive.js DELETED
@@ -1,35 +0,0 @@
1
- // SPDX-License-Identifier: MPL-2.0
2
-
3
- import path from 'node:path';
4
-
5
- function assert(condition, message) {
6
- if (!condition) {
7
- throw new Error(message);
8
- }
9
- }
10
-
11
- export function validateArchiveEntryName(entryName) {
12
- assert(
13
- typeof entryName === 'string' && entryName.length > 0,
14
- 'SB3 archive contains an empty entry name.',
15
- );
16
- assert(
17
- !entryName.includes('\0'),
18
- `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`,
19
- );
20
- assert(
21
- !entryName.includes('\\'),
22
- `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`,
23
- );
24
- assert(
25
- !path.posix.isAbsolute(entryName) && !/^[A-Za-z]:/u.test(entryName),
26
- `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`,
27
- );
28
-
29
- const segments = entryName.replace(/\/$/u, '').split('/');
30
- assert(
31
- segments.every((segment) => segment !== '' && segment !== '.' && segment !== '..'),
32
- `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`,
33
- );
34
- return entryName;
35
- }