@kubohiroya/sb3-toolchain 0.23.0 → 0.25.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.25.0 - 2026-11-16
4
+
5
+ - ブロックパレットの設定を保つ展開ソース形式 v2 を追加した。設定は作品フォルダでは `block-palette.json` に、SB3 ではスプライト・背景ごとのコメントに入る。設定のない作品は今までどおり v1 で書く(#90)。
6
+ - 読み手は v1 と v2 を受け付け、それ以外の版は出力を変えずに拒否する。
7
+
8
+ ## 0.24.0 - 2026-11-12
9
+
10
+ - ブラウザーから SB3 を v1 作品フォルダのファイルに展開・検証する API を追加した。
11
+ - アセットや拡張の空ディレクトリを含まない Git チェックアウトでも作品フォルダを読み取れるようにした。
12
+
3
13
  ## 0.23.0 - 2026-11-11
4
14
 
5
15
  - fix(fonts): keep legacy font entries without an asset
package/README.ja.md CHANGED
@@ -34,7 +34,7 @@ Scratch 3およびTurboWarpの`.sb3`プロジェクトを、Gitで差分を確
34
34
  再現可能なインストールのため、検証済みのnpmバージョンを固定します。
35
35
 
36
36
  ```bash
37
- pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.23.0
37
+ pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.25.0
38
38
  ```
39
39
 
40
40
  ## クイックスタート
@@ -151,10 +151,17 @@ await unbundleSb3({
151
151
  });
152
152
  ```
153
153
 
154
+ ### ブラウザーで作品フォルダを作る
155
+
156
+ `@kubohiroya/sb3-toolchain/browser` の `unpackSb3(bytes)` は、SB3 のバイト列を作品フォルダ v1 の `Map<string, Uint8Array>` と警告の一覧に変換します。生成されたファイルは `validateSourceFiles(files)` で再検査できます。どちらの関数も Node.js の組み込みモジュールやファイルシステムを使いません。
157
+
158
+ 参照のないハッシュ名の素材と ZIP のディレクトリエントリーは、警告を返して除外します。Plus 拡張マニフェストと参照のない添付ファイルは、対応する作品フォルダで開けないため `Sb3SourceError` の `unsupported-project` として報告します。画像・音声・フォントの参照と内容、埋め込み拡張のファイル構成を確認します。バンドルのビルドと管理対象拡張の完全な検査には CLI の `check` と `build` を使えます。
159
+
154
160
  ## ドキュメント
155
161
 
156
162
  - [`docs/ja/workflows.md`](docs/ja/workflows.md): SB3ソースと機能拡張を管理するワークフロー
157
163
  - [`docs/ja/source-format-v1.md`](docs/ja/source-format-v1.md): 展開ソース形式と決定的出力
164
+ - [`docs/ja/source-format-v2.md`](docs/ja/source-format-v2.md): ブロックパレットの設定を足した形式 v2
158
165
  - [`docs/ja/project-asset-additions.md`](docs/ja/project-asset-additions.md): `--project-assets`のJSON/YAML、backdrop、編集/strict lock仕様
159
166
  - [`docs/ja/extension-id-migration.md`](docs/ja/extension-id-migration.md): プロジェクトで使用中の機能拡張IDの移行
160
167
  - [`docs/ja/extension-api-compatibility.md`](docs/ja/extension-api-compatibility.md): 機能拡張更新時の任意の静的API互換性検査
package/README.md CHANGED
@@ -35,7 +35,7 @@ expanded sources and rebuilding bit-for-bit identical SB3 files from the same in
35
35
  Pin the verified npm version for reproducible installation.
36
36
 
37
37
  ```bash
38
- pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.23.0
38
+ pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.25.0
39
39
  ```
40
40
 
41
41
  ## Quick start
@@ -155,10 +155,17 @@ await unbundleSb3({
155
155
  });
156
156
  ```
157
157
 
158
+ ### Create a project folder in a browser
159
+
160
+ `unpackSb3(bytes)` from `@kubohiroya/sb3-toolchain/browser` expands SB3 bytes into a v1 project folder represented by a `Map<string, Uint8Array>` and a list of warnings. Use `validateSourceFiles(files)` to check the resulting files again. Both functions run without Node.js built-ins or filesystem access.
161
+
162
+ The browser API reports and omits unreferenced assets with hash-based filenames and directory entries. It rejects Plus extension manifests and unsupported attachments with the `Sb3SourceError` code `unsupported-project`. Validation checks image, sound and font references and bytes, and the layout of embedded extensions. Use the CLI `check` and `build` commands for bundle builds and full managed-extension validation.
163
+
158
164
  ## Documentation
159
165
 
160
166
  - [`docs/workflows.md`](docs/workflows.md): SB3 source and extension management workflows
161
167
  - [`docs/source-format-v1.md`](docs/source-format-v1.md): expanded source format and deterministic output
168
+ - [`docs/source-format-v2.md`](docs/source-format-v2.md): format v2, which adds block palette settings
162
169
  - [`docs/project-asset-additions.md`](docs/project-asset-additions.md): JSON/YAML `--project-assets`, backdrops, and editable or strict locks
163
170
  - [`docs/extension-id-migration.md`](docs/extension-id-migration.md): migration of extension IDs already used by a project
164
171
  - [`docs/extension-api-compatibility.md`](docs/extension-api-compatibility.md) ([日本語](docs/ja/extension-api-compatibility.md)): opt-in static API compatibility checks for extension updates
package/dist/archive.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { assert } from "./assert.js";
2
- import path from "node:path";
3
2
  //#region src/archive.ts
4
3
  function validateArchiveEntryName(entryName) {
5
4
  assert(typeof entryName === "string" && entryName.length > 0, "SB3 archive contains an empty entry name.");
6
5
  assert(!entryName.includes("\0"), `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`);
7
6
  assert(!entryName.includes("\\"), `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`);
8
- assert(!path.posix.isAbsolute(entryName) && !/^[A-Za-z]:/u.test(entryName), `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`);
7
+ assert(!entryName.startsWith("/") && !/^[A-Za-z]:/u.test(entryName), `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`);
9
8
  const segments = entryName.replace(/\/$/u, "").split("/");
10
9
  assert(segments.every((segment) => segment !== "" && segment !== "." && segment !== ".."), `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`);
11
10
  return entryName;
@@ -1 +1 @@
1
- {"version":3,"file":"archive.js","names":[],"sources":["../src/archive.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport path from 'node:path';\n\nimport {assert} from './assert';\n\nexport function validateArchiveEntryName(entryName: unknown): string {\n assert(\n typeof entryName === 'string' && entryName.length > 0,\n 'SB3 archive contains an empty entry name.',\n );\n assert(\n !entryName.includes('\\0'),\n `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`,\n );\n assert(\n !entryName.includes('\\\\'),\n `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`,\n );\n assert(\n !path.posix.isAbsolute(entryName) && !/^[A-Za-z]:/u.test(entryName),\n `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`,\n );\n\n const segments = entryName.replace(/\\/$/u, '').split('/');\n assert(\n segments.every((segment) => segment !== '' && segment !== '.' && segment !== '..'),\n `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`,\n );\n return entryName;\n}\n"],"mappings":";;;AAMA,SAAgB,yBAAyB,WAA4B;CACnE,OACE,OAAO,cAAc,YAAY,UAAU,SAAS,GACpD,2CACF;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,0CAA0C,KAAK,UAAU,SAAS,GACpE;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,uCAAuC,KAAK,UAAU,SAAS,GACjE;CACA,OACE,CAAC,KAAK,MAAM,WAAW,SAAS,KAAK,CAAC,cAAc,KAAK,SAAS,GAClE,kCAAkC,KAAK,UAAU,SAAS,GAC5D;CAEA,MAAM,WAAW,UAAU,QAAQ,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG;CACxD,OACE,SAAS,OAAO,YAAY,YAAY,MAAM,YAAY,OAAO,YAAY,IAAI,GACjF,sDAAsD,KAAK,UAAU,SAAS,GAChF;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"archive.js","names":[],"sources":["../src/archive.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {assert} from './assert';\n\nexport function validateArchiveEntryName(entryName: unknown): string {\n assert(\n typeof entryName === 'string' && entryName.length > 0,\n 'SB3 archive contains an empty entry name.',\n );\n assert(\n !entryName.includes('\\0'),\n `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`,\n );\n assert(\n !entryName.includes('\\\\'),\n `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`,\n );\n assert(\n !entryName.startsWith('/') && !/^[A-Za-z]:/u.test(entryName),\n `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`,\n );\n\n const segments = entryName.replace(/\\/$/u, '').split('/');\n assert(\n segments.every((segment) => segment !== '' && segment !== '.' && segment !== '..'),\n `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`,\n );\n return entryName;\n}\n"],"mappings":";;AAIA,SAAgB,yBAAyB,WAA4B;CACnE,OACE,OAAO,cAAc,YAAY,UAAU,SAAS,GACpD,2CACF;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,0CAA0C,KAAK,UAAU,SAAS,GACpE;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,uCAAuC,KAAK,UAAU,SAAS,GACjE;CACA,OACE,CAAC,UAAU,WAAW,GAAG,KAAK,CAAC,cAAc,KAAK,SAAS,GAC3D,kCAAkC,KAAK,UAAU,SAAS,GAC5D;CAEA,MAAM,WAAW,UAAU,QAAQ,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG;CACxD,OACE,SAAS,OAAO,YAAY,YAAY,MAAM,YAAY,OAAO,YAAY,IAAI,GACjF,sDAAsD,KAAK,UAAU,SAAS,GAChF;CACA,OAAO;AACT"}
@@ -0,0 +1,60 @@
1
+ import { ProjectJson, UnknownRecord } from './types';
2
+ export declare const blockPaletteFormatVersion = 1;
3
+ export declare const blockPaletteFile = "block-palette.json";
4
+ export declare const blockPaletteCommentMarker = " // _twplus_palette_";
5
+ export declare const blockPaletteCommentReference = "block-palette:block-palette.json";
6
+ export declare const blockPaletteCommentMaxLength = 8000;
7
+ export declare const blockPaletteSpriteCommentHeader: string;
8
+ export declare const blockPaletteStageCommentHeader: string;
9
+ export interface BlockPaletteTargetSetting {
10
+ groups: string[];
11
+ }
12
+ export interface BlockPaletteSet {
13
+ name: string;
14
+ groups: string[];
15
+ }
16
+ export interface BlockPaletteDocument {
17
+ formatVersion: 1;
18
+ order?: string[];
19
+ sets?: Record<string, BlockPaletteSet>;
20
+ stage?: BlockPaletteTargetSetting;
21
+ sprites?: Record<string, BlockPaletteTargetSetting>;
22
+ }
23
+ export type BlockPaletteWarningCode = 'block-palette-normalized' | 'block-palette-invalid';
24
+ export interface BlockPaletteWarning {
25
+ code: BlockPaletteWarningCode;
26
+ commentId: string;
27
+ message: string;
28
+ target: string;
29
+ }
30
+ export declare function hasBlockPaletteSettings(document: BlockPaletteDocument): boolean;
31
+ /** Validate the shape of `block-palette.json` without looking at the project. */
32
+ export declare function validateBlockPaletteDocument(value: unknown): BlockPaletteDocument;
33
+ export declare function serializeBlockPaletteDocument(document: BlockPaletteDocument): string;
34
+ /**
35
+ * The canonical comment text for one sprite or the stage. Fails when the text is longer than
36
+ * 8000 characters, which Scratch 3 refuses to load.
37
+ */
38
+ export declare function formatBlockPaletteComment(document: BlockPaletteDocument, target: {
39
+ isStage: boolean;
40
+ name: string;
41
+ }): string;
42
+ /**
43
+ * Move palette comments from an SB3 project into a `block-palette.json` document.
44
+ * The project is changed in place: each recognized comment keeps its ID, position, size,
45
+ * state and order, and its text becomes {@link blockPaletteCommentReference}.
46
+ */
47
+ export declare function extractBlockPalette(project: ProjectJson): {
48
+ document: BlockPaletteDocument | null;
49
+ warnings: BlockPaletteWarning[];
50
+ };
51
+ /**
52
+ * Check that `project.source.json` and `block-palette.json` agree, and return the canonical
53
+ * comment text for each reference. `document` is null for source format 1.
54
+ */
55
+ export declare function resolveBlockPaletteReferences(project: ProjectJson, document: BlockPaletteDocument | null): {
56
+ comment: UnknownRecord;
57
+ text: string;
58
+ }[];
59
+ /** Replace each reference comment in a cloned project with its canonical SB3 text. */
60
+ export declare function applyBlockPaletteComments(project: ProjectJson, document: BlockPaletteDocument | null): void;
@@ -0,0 +1,295 @@
1
+ import { assert } from "./assert.js";
2
+ //#region src/block-palette.ts
3
+ /**
4
+ * Block palette settings (source format 2).
5
+ *
6
+ * In an SB3, each sprite or stage carries at most one comment whose second line ends with
7
+ * {@link blockPaletteCommentMarker}. In a source folder, those comments live in
8
+ * `block-palette.json`, and the comment text in `project.source.json` becomes
9
+ * {@link blockPaletteCommentReference}. This module is shared by the Node and browser builds,
10
+ * so it must not import Node built-ins.
11
+ */
12
+ var blockPaletteFormatVersion = 1;
13
+ var blockPaletteFile = "block-palette.json";
14
+ var blockPaletteCommentMarker = " // _twplus_palette_";
15
+ var blockPaletteCommentReference = `block-palette:${blockPaletteFile}`;
16
+ var blockPaletteCommentMaxLength = 8e3;
17
+ var blockPaletteSpriteCommentHeader = "TurboWarp Plus Editor block palette for this sprite. You can delete this comment to reset the palette.";
18
+ var blockPaletteStageCommentHeader = "TurboWarp Plus Editor block palette for the stage. You can delete this comment to reset the palette.";
19
+ var markerToken = "// _twplus_palette_";
20
+ var groupIdPattern = /^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9_-]+)?$/u;
21
+ var setIdPattern = /^[A-Za-z_][A-Za-z0-9_-]*$/u;
22
+ function isRecord(value) {
23
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24
+ }
25
+ function assertOnlyKeys(value, allowed, description) {
26
+ for (const key of Object.keys(value)) assert(allowed.includes(key), `${description} has an unknown key: ${key}`);
27
+ }
28
+ function validateGroupList(value, description) {
29
+ assert(Array.isArray(value), `${description} must be an array of block group IDs.`);
30
+ const seen = /* @__PURE__ */ new Set();
31
+ for (const group of value) {
32
+ assert(typeof group === "string" && groupIdPattern.test(group), `${description} contains an invalid block group ID: ${JSON.stringify(group)}`);
33
+ assert(!seen.has(group), `${description} contains a duplicate block group ID: ${group}`);
34
+ seen.add(group);
35
+ }
36
+ return [...seen];
37
+ }
38
+ function validateTargetSetting(value, description) {
39
+ assert(isRecord(value), `${description} must be an object.`);
40
+ assertOnlyKeys(value, ["groups"], description);
41
+ return { groups: validateGroupList(value.groups, `${description} groups`) };
42
+ }
43
+ function validateSets(value, description) {
44
+ assert(isRecord(value), `${description} must be an object.`);
45
+ return Object.fromEntries(Object.entries(value).map(([setId, set]) => {
46
+ assert(setIdPattern.test(setId), `${description} has an invalid set ID: ${setId}`);
47
+ const setDescription = `${description}.${setId}`;
48
+ assert(isRecord(set), `${setDescription} must be an object.`);
49
+ assertOnlyKeys(set, ["name", "groups"], setDescription);
50
+ assert(typeof set.name === "string" && set.name.length > 0, `${setDescription} name must be a non-empty string.`);
51
+ return [setId, {
52
+ name: set.name,
53
+ groups: validateGroupList(set.groups, `${setDescription} groups`)
54
+ }];
55
+ }));
56
+ }
57
+ function canonicalDocument(parts) {
58
+ const document = { formatVersion: 1 };
59
+ if (parts.order !== void 0) document.order = parts.order;
60
+ if (parts.sets !== void 0) document.sets = parts.sets;
61
+ if (parts.stage !== void 0) document.stage = parts.stage;
62
+ if (parts.sprites !== void 0 && Object.keys(parts.sprites).length > 0) document.sprites = parts.sprites;
63
+ return document;
64
+ }
65
+ function hasBlockPaletteSettings(document) {
66
+ return document.order !== void 0 || document.sets !== void 0 || document.stage !== void 0 || document.sprites !== void 0 && Object.keys(document.sprites).length > 0;
67
+ }
68
+ function stageHasSettings(document) {
69
+ return document.order !== void 0 || document.sets !== void 0 || document.stage !== void 0;
70
+ }
71
+ /** Validate the shape of `block-palette.json` without looking at the project. */
72
+ function validateBlockPaletteDocument(value) {
73
+ const description = blockPaletteFile;
74
+ assert(isRecord(value), `${description} must contain an object.`);
75
+ assertOnlyKeys(value, [
76
+ "formatVersion",
77
+ "order",
78
+ "sets",
79
+ "stage",
80
+ "sprites"
81
+ ], description);
82
+ assert(value.formatVersion === 1, `Unsupported ${description} formatVersion: ${String(value.formatVersion)}`);
83
+ let sprites;
84
+ if (value.sprites !== void 0) {
85
+ assert(isRecord(value.sprites), `${description} sprites must be an object.`);
86
+ assert(Object.keys(value.sprites).length > 0, `${description} sprites must be omitted when it has no sprites.`);
87
+ sprites = Object.fromEntries(Object.entries(value.sprites).map(([name, setting]) => [name, validateTargetSetting(setting, `${description} sprites.${name}`)]));
88
+ }
89
+ const document = canonicalDocument({
90
+ order: value.order === void 0 ? void 0 : validateGroupList(value.order, "order"),
91
+ sets: value.sets === void 0 ? void 0 : validateSets(value.sets, `${description} sets`),
92
+ stage: value.stage === void 0 ? void 0 : validateTargetSetting(value.stage, `${description} stage`),
93
+ sprites
94
+ });
95
+ assert(hasBlockPaletteSettings(document), `${description} has no settings; remove it and use SB3 source format 1.`);
96
+ return document;
97
+ }
98
+ function serializeBlockPaletteDocument(document) {
99
+ return `${JSON.stringify(canonicalDocument(document), null, 2)}\n`;
100
+ }
101
+ /**
102
+ * List each target's comments. In strict mode, a malformed target or comment is an error;
103
+ * otherwise it is skipped so unpacking stays as permissive as it was in source format 1.
104
+ */
105
+ function targetComments(project, strict = true) {
106
+ if (!strict && !Array.isArray(project.targets)) return [];
107
+ assert(Array.isArray(project.targets), "Project targets must be an array.");
108
+ const targets = [];
109
+ for (const [index, target] of project.targets.entries()) {
110
+ if (!strict && !isRecord(target)) continue;
111
+ assert(isRecord(target), `Project target ${index} must be an object.`);
112
+ const comments = target.comments ?? {};
113
+ if (!strict && !isRecord(comments)) continue;
114
+ assert(isRecord(comments), `Project target ${index} comments must be an object.`);
115
+ const records = Object.fromEntries(Object.entries(comments).filter(([id, comment]) => {
116
+ assert(!strict || isRecord(comment), `Project target ${index} comment ${id} must be an object.`);
117
+ return isRecord(comment);
118
+ }));
119
+ targets.push({
120
+ comments: records,
121
+ isStage: target.isStage === true,
122
+ name: typeof target.name === "string" ? target.name : String(index)
123
+ });
124
+ }
125
+ return targets;
126
+ }
127
+ function isMarkedComment(comment) {
128
+ return typeof comment.text === "string" && comment.text.includes(markerToken);
129
+ }
130
+ function isReferenceComment(comment) {
131
+ return comment.text === blockPaletteCommentReference;
132
+ }
133
+ function canonicalCommentText(document, target) {
134
+ let payload;
135
+ if (target.isStage) {
136
+ payload = { formatVersion: 1 };
137
+ if (document.stage) payload.groups = document.stage.groups;
138
+ if (document.order) payload.order = document.order;
139
+ if (document.sets) payload.sets = document.sets;
140
+ } else {
141
+ const setting = document.sprites?.[target.name];
142
+ assert(setting, `${blockPaletteFile} has no setting for sprite ${target.name}.`);
143
+ payload = {
144
+ formatVersion: 1,
145
+ groups: setting.groups
146
+ };
147
+ }
148
+ return `${target.isStage ? blockPaletteStageCommentHeader : blockPaletteSpriteCommentHeader}\n${JSON.stringify(payload)}${blockPaletteCommentMarker}`;
149
+ }
150
+ /**
151
+ * The canonical comment text for one sprite or the stage. Fails when the text is longer than
152
+ * 8000 characters, which Scratch 3 refuses to load.
153
+ */
154
+ function formatBlockPaletteComment(document, target) {
155
+ const text = canonicalCommentText(document, target);
156
+ const length = Array.from(text).length;
157
+ assert(length <= blockPaletteCommentMaxLength, `Block palette comment for ${target.isStage ? "the stage" : `sprite ${target.name}`} has ${length} characters; the limit is ${blockPaletteCommentMaxLength}.`);
158
+ return text;
159
+ }
160
+ function parseMarkedComment(comment, isStage) {
161
+ if (comment.extraText !== void 0) return {
162
+ ok: false,
163
+ reason: "the comment has extraText"
164
+ };
165
+ const markedLines = comment.text.split("\n").filter((line) => line.includes(markerToken));
166
+ if (markedLines.length !== 1) return {
167
+ ok: false,
168
+ reason: "the marker must appear on exactly one line"
169
+ };
170
+ const [line] = markedLines;
171
+ const json = line.slice(0, line.indexOf(markerToken)).trim();
172
+ let value;
173
+ try {
174
+ value = JSON.parse(json);
175
+ } catch {
176
+ return {
177
+ ok: false,
178
+ reason: "the marked line is not valid JSON"
179
+ };
180
+ }
181
+ try {
182
+ assert(isRecord(value), "the JSON must be an object");
183
+ assertOnlyKeys(value, isStage ? [
184
+ "formatVersion",
185
+ "groups",
186
+ "order",
187
+ "sets"
188
+ ] : ["formatVersion", "groups"], "the JSON");
189
+ assert(value.formatVersion === 1, `unsupported formatVersion ${String(value.formatVersion)}`);
190
+ assert(isStage || value.groups !== void 0, "the JSON has no groups");
191
+ const parsed = {
192
+ order: value.order === void 0 ? void 0 : validateGroupList(value.order, "order"),
193
+ sets: value.sets === void 0 ? void 0 : validateSets(value.sets, "sets"),
194
+ stage: value.groups === void 0 ? void 0 : { groups: validateGroupList(value.groups, "groups") }
195
+ };
196
+ assert(parsed.order !== void 0 || parsed.sets !== void 0 || parsed.stage !== void 0, "the JSON has no settings");
197
+ return {
198
+ ok: true,
199
+ value: parsed
200
+ };
201
+ } catch (error) {
202
+ return {
203
+ ok: false,
204
+ reason: error instanceof Error ? error.message : String(error)
205
+ };
206
+ }
207
+ }
208
+ /**
209
+ * Move palette comments from an SB3 project into a `block-palette.json` document.
210
+ * The project is changed in place: each recognized comment keeps its ID, position, size,
211
+ * state and order, and its text becomes {@link blockPaletteCommentReference}.
212
+ */
213
+ function extractBlockPalette(project) {
214
+ const warnings = [];
215
+ const parts = {};
216
+ const sprites = [];
217
+ for (const target of targetComments(project, false)) {
218
+ const marked = Object.entries(target.comments).filter(([, comment]) => isMarkedComment(comment));
219
+ const references = Object.values(target.comments).filter(isReferenceComment);
220
+ assert(references.length === 0, `${target.isStage ? "The stage" : `Sprite ${target.name}`} has a comment whose text is reserved for block palette references: ${blockPaletteCommentReference}`);
221
+ assert(marked.length <= 1, `${target.isStage ? "The stage" : `Sprite ${target.name}`} has ${marked.length} block palette comments; only one is allowed.`);
222
+ if (marked.length === 0) continue;
223
+ const [[commentId, comment]] = marked;
224
+ const parsed = parseMarkedComment(comment, target.isStage);
225
+ if (!parsed.ok) {
226
+ warnings.push({
227
+ code: "block-palette-invalid",
228
+ commentId,
229
+ message: `Block palette comment ${commentId} on ${target.name} was kept as a plain comment and ignored: ${parsed.reason}.`,
230
+ target: target.name
231
+ });
232
+ continue;
233
+ }
234
+ if (target.isStage) Object.assign(parts, parsed.value);
235
+ else {
236
+ assert(!sprites.some(([name]) => name === target.name), `Duplicate sprite name with block palette settings: ${target.name}`);
237
+ sprites.push([target.name, parsed.value.stage]);
238
+ }
239
+ const canonicalText = canonicalCommentText(canonicalDocument({
240
+ ...parts,
241
+ sprites: Object.fromEntries(sprites)
242
+ }), target);
243
+ if (comment.text !== canonicalText) warnings.push({
244
+ code: "block-palette-normalized",
245
+ commentId,
246
+ message: `Block palette comment ${commentId} on ${target.name} is not in the canonical form; it will be rewritten on build.`,
247
+ target: target.name
248
+ });
249
+ comment.text = blockPaletteCommentReference;
250
+ }
251
+ const document = canonicalDocument({
252
+ ...parts,
253
+ sprites: Object.fromEntries(sprites)
254
+ });
255
+ return {
256
+ document: hasBlockPaletteSettings(document) ? document : null,
257
+ warnings
258
+ };
259
+ }
260
+ /**
261
+ * Check that `project.source.json` and `block-palette.json` agree, and return the canonical
262
+ * comment text for each reference. `document` is null for source format 1.
263
+ */
264
+ function resolveBlockPaletteReferences(project, document) {
265
+ const resolved = [];
266
+ const targets = targetComments(project, document !== null);
267
+ if (document === null) {
268
+ for (const target of targets) assert(!Object.values(target.comments).some(isReferenceComment), `project.source.json refers to ${blockPaletteFile}, which requires SB3 source format 2.`);
269
+ return resolved;
270
+ }
271
+ const spriteNames = new Set(targets.filter(({ isStage }) => !isStage).map(({ name }) => name));
272
+ for (const name of Object.keys(document.sprites ?? {})) assert(spriteNames.has(name), `${blockPaletteFile} refers to an unknown sprite: ${name}`);
273
+ for (const target of targets) {
274
+ const label = target.isStage ? "The stage" : `Sprite ${target.name}`;
275
+ const references = Object.values(target.comments).filter(isReferenceComment);
276
+ const marked = Object.values(target.comments).filter(isMarkedComment);
277
+ const expected = target.isStage ? stageHasSettings(document) : document.sprites?.[target.name] !== void 0;
278
+ assert(references.length <= 1, `${label} has ${references.length} block palette references; only one is allowed.`);
279
+ assert(references.length === 0 || marked.length === 0, `${label} has both a block palette reference and a block palette comment.`);
280
+ assert(references.length === (expected ? 1 : 0), expected ? `${label} has block palette settings in ${blockPaletteFile} but no comment that refers to it (${blockPaletteCommentReference}).` : `${label} has a block palette reference but no settings in ${blockPaletteFile}.`);
281
+ if (references.length === 1) resolved.push({
282
+ comment: references[0],
283
+ text: formatBlockPaletteComment(document, target)
284
+ });
285
+ }
286
+ return resolved;
287
+ }
288
+ /** Replace each reference comment in a cloned project with its canonical SB3 text. */
289
+ function applyBlockPaletteComments(project, document) {
290
+ for (const { comment, text } of resolveBlockPaletteReferences(project, document)) comment.text = text;
291
+ }
292
+ //#endregion
293
+ export { applyBlockPaletteComments, blockPaletteCommentMarker, blockPaletteCommentMaxLength, blockPaletteCommentReference, blockPaletteFile, blockPaletteFormatVersion, blockPaletteSpriteCommentHeader, blockPaletteStageCommentHeader, extractBlockPalette, formatBlockPaletteComment, hasBlockPaletteSettings, resolveBlockPaletteReferences, serializeBlockPaletteDocument, validateBlockPaletteDocument };
294
+
295
+ //# sourceMappingURL=block-palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-palette.js","names":[],"sources":["../src/block-palette.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\n/**\n * Block palette settings (source format 2).\n *\n * In an SB3, each sprite or stage carries at most one comment whose second line ends with\n * {@link blockPaletteCommentMarker}. In a source folder, those comments live in\n * `block-palette.json`, and the comment text in `project.source.json` becomes\n * {@link blockPaletteCommentReference}. This module is shared by the Node and browser builds,\n * so it must not import Node built-ins.\n */\n\nimport {assert} from './assert';\nimport type {ProjectJson, UnknownRecord} from './types';\n\nexport const blockPaletteFormatVersion = 1;\nexport const blockPaletteFile = 'block-palette.json';\nexport const blockPaletteCommentMarker = ' // _twplus_palette_';\nexport const blockPaletteCommentReference = `block-palette:${blockPaletteFile}`;\nexport const blockPaletteCommentMaxLength = 8000;\nexport const blockPaletteSpriteCommentHeader =\n 'TurboWarp Plus Editor block palette for this sprite. ' +\n 'You can delete this comment to reset the palette.';\nexport const blockPaletteStageCommentHeader =\n 'TurboWarp Plus Editor block palette for the stage. ' +\n 'You can delete this comment to reset the palette.';\n\nconst markerToken = '// _twplus_palette_';\nconst groupIdPattern = /^[A-Za-z0-9._-]+(?:\\/[A-Za-z0-9_-]+)?$/u;\nconst setIdPattern = /^[A-Za-z_][A-Za-z0-9_-]*$/u;\n\nexport interface BlockPaletteTargetSetting {\n groups: string[];\n}\n\nexport interface BlockPaletteSet {\n name: string;\n groups: string[];\n}\n\nexport interface BlockPaletteDocument {\n formatVersion: 1;\n order?: string[];\n sets?: Record<string, BlockPaletteSet>;\n stage?: BlockPaletteTargetSetting;\n sprites?: Record<string, BlockPaletteTargetSetting>;\n}\n\nexport type BlockPaletteWarningCode = 'block-palette-normalized' | 'block-palette-invalid';\n\nexport interface BlockPaletteWarning {\n code: BlockPaletteWarningCode;\n commentId: string;\n message: string;\n target: string;\n}\n\ninterface ProjectTargetComments {\n comments: Record<string, UnknownRecord>;\n isStage: boolean;\n name: string;\n}\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction assertOnlyKeys(value: UnknownRecord, allowed: string[], description: string): void {\n for (const key of Object.keys(value)) {\n assert(allowed.includes(key), `${description} has an unknown key: ${key}`);\n }\n}\n\nfunction validateGroupList(value: unknown, description: string): string[] {\n assert(Array.isArray(value), `${description} must be an array of block group IDs.`);\n const seen = new Set<string>();\n for (const group of value as unknown[]) {\n assert(\n typeof group === 'string' && groupIdPattern.test(group),\n `${description} contains an invalid block group ID: ${JSON.stringify(group)}`,\n );\n assert(!seen.has(group), `${description} contains a duplicate block group ID: ${group}`);\n seen.add(group);\n }\n return [...seen];\n}\n\nfunction validateTargetSetting(value: unknown, description: string): BlockPaletteTargetSetting {\n assert(isRecord(value), `${description} must be an object.`);\n assertOnlyKeys(value, ['groups'], description);\n return {groups: validateGroupList(value.groups, `${description} groups`)};\n}\n\nfunction validateSets(value: unknown, description: string): Record<string, BlockPaletteSet> {\n assert(isRecord(value), `${description} must be an object.`);\n return Object.fromEntries(\n Object.entries(value).map(([setId, set]) => {\n assert(setIdPattern.test(setId), `${description} has an invalid set ID: ${setId}`);\n const setDescription = `${description}.${setId}`;\n assert(isRecord(set), `${setDescription} must be an object.`);\n assertOnlyKeys(set, ['name', 'groups'], setDescription);\n assert(\n typeof set.name === 'string' && set.name.length > 0,\n `${setDescription} name must be a non-empty string.`,\n );\n return [\n setId,\n {name: set.name, groups: validateGroupList(set.groups, `${setDescription} groups`)},\n ];\n }),\n );\n}\n\nfunction canonicalDocument(parts: Omit<BlockPaletteDocument, 'formatVersion'>) {\n const document: BlockPaletteDocument = {formatVersion: blockPaletteFormatVersion};\n if (parts.order !== undefined) document.order = parts.order;\n if (parts.sets !== undefined) document.sets = parts.sets;\n if (parts.stage !== undefined) document.stage = parts.stage;\n if (parts.sprites !== undefined && Object.keys(parts.sprites).length > 0) {\n document.sprites = parts.sprites;\n }\n return document;\n}\n\nexport function hasBlockPaletteSettings(document: BlockPaletteDocument): boolean {\n return (\n document.order !== undefined ||\n document.sets !== undefined ||\n document.stage !== undefined ||\n (document.sprites !== undefined && Object.keys(document.sprites).length > 0)\n );\n}\n\nfunction stageHasSettings(document: BlockPaletteDocument): boolean {\n return (\n document.order !== undefined || document.sets !== undefined || document.stage !== undefined\n );\n}\n\n/** Validate the shape of `block-palette.json` without looking at the project. */\nexport function validateBlockPaletteDocument(value: unknown): BlockPaletteDocument {\n const description = blockPaletteFile;\n assert(isRecord(value), `${description} must contain an object.`);\n assertOnlyKeys(value, ['formatVersion', 'order', 'sets', 'stage', 'sprites'], description);\n assert(\n value.formatVersion === blockPaletteFormatVersion,\n `Unsupported ${description} formatVersion: ${String(value.formatVersion)}`,\n );\n let sprites: Record<string, BlockPaletteTargetSetting> | undefined;\n if (value.sprites !== undefined) {\n assert(isRecord(value.sprites), `${description} sprites must be an object.`);\n assert(\n Object.keys(value.sprites).length > 0,\n `${description} sprites must be omitted when it has no sprites.`,\n );\n sprites = Object.fromEntries(\n Object.entries(value.sprites).map(([name, setting]) => [\n name,\n validateTargetSetting(setting, `${description} sprites.${name}`),\n ]),\n );\n }\n const document = canonicalDocument({\n order: value.order === undefined ? undefined : validateGroupList(value.order, 'order'),\n sets: value.sets === undefined ? undefined : validateSets(value.sets, `${description} sets`),\n stage:\n value.stage === undefined\n ? undefined\n : validateTargetSetting(value.stage, `${description} stage`),\n sprites,\n });\n assert(\n hasBlockPaletteSettings(document),\n `${description} has no settings; remove it and use SB3 source format 1.`,\n );\n return document;\n}\n\nexport function serializeBlockPaletteDocument(document: BlockPaletteDocument): string {\n return `${JSON.stringify(canonicalDocument(document), null, 2)}\\n`;\n}\n\n/**\n * List each target's comments. In strict mode, a malformed target or comment is an error;\n * otherwise it is skipped so unpacking stays as permissive as it was in source format 1.\n */\nfunction targetComments(project: ProjectJson, strict = true): ProjectTargetComments[] {\n if (!strict && !Array.isArray(project.targets)) return [];\n assert(Array.isArray(project.targets), 'Project targets must be an array.');\n const targets: ProjectTargetComments[] = [];\n for (const [index, target] of (project.targets as unknown[]).entries()) {\n if (!strict && !isRecord(target)) continue;\n assert(isRecord(target), `Project target ${index} must be an object.`);\n const comments: unknown = target.comments ?? {};\n if (!strict && !isRecord(comments)) continue;\n assert(isRecord(comments), `Project target ${index} comments must be an object.`);\n const records = Object.fromEntries(\n Object.entries(comments).filter(([id, comment]) => {\n assert(\n !strict || isRecord(comment),\n `Project target ${index} comment ${id} must be an object.`,\n );\n return isRecord(comment);\n }),\n ) as Record<string, UnknownRecord>;\n targets.push({\n comments: records,\n isStage: target.isStage === true,\n name: typeof target.name === 'string' ? target.name : String(index),\n });\n }\n return targets;\n}\n\nfunction isMarkedComment(comment: UnknownRecord): boolean {\n return typeof comment.text === 'string' && comment.text.includes(markerToken);\n}\n\nfunction isReferenceComment(comment: UnknownRecord): boolean {\n return comment.text === blockPaletteCommentReference;\n}\n\nfunction canonicalCommentText(\n document: BlockPaletteDocument,\n target: {isStage: boolean; name: string},\n): string {\n let payload: UnknownRecord;\n if (target.isStage) {\n payload = {formatVersion: blockPaletteFormatVersion};\n if (document.stage) payload.groups = document.stage.groups;\n if (document.order) payload.order = document.order;\n if (document.sets) payload.sets = document.sets;\n } else {\n const setting = document.sprites?.[target.name];\n assert(setting, `${blockPaletteFile} has no setting for sprite ${target.name}.`);\n payload = {formatVersion: blockPaletteFormatVersion, groups: setting.groups};\n }\n const header = target.isStage ? blockPaletteStageCommentHeader : blockPaletteSpriteCommentHeader;\n return `${header}\\n${JSON.stringify(payload)}${blockPaletteCommentMarker}`;\n}\n\n/**\n * The canonical comment text for one sprite or the stage. Fails when the text is longer than\n * 8000 characters, which Scratch 3 refuses to load.\n */\nexport function formatBlockPaletteComment(\n document: BlockPaletteDocument,\n target: {isStage: boolean; name: string},\n): string {\n const text = canonicalCommentText(document, target);\n const length = Array.from(text).length;\n assert(\n length <= blockPaletteCommentMaxLength,\n `Block palette comment for ${target.isStage ? 'the stage' : `sprite ${target.name}`} has ` +\n `${length} characters; the limit is ${blockPaletteCommentMaxLength}.`,\n );\n return text;\n}\n\ntype ParsedComment =\n | {ok: true; value: Omit<BlockPaletteDocument, 'formatVersion' | 'sprites'>}\n | {ok: false; reason: string};\n\nfunction parseMarkedComment(comment: UnknownRecord, isStage: boolean): ParsedComment {\n if (comment.extraText !== undefined) {\n return {ok: false, reason: 'the comment has extraText'};\n }\n const lines = (comment.text as string).split('\\n');\n const markedLines = lines.filter((line) => line.includes(markerToken));\n if (markedLines.length !== 1) {\n return {ok: false, reason: 'the marker must appear on exactly one line'};\n }\n const [line] = markedLines;\n const json = line.slice(0, line.indexOf(markerToken)).trim();\n let value: unknown;\n try {\n value = JSON.parse(json);\n } catch {\n return {ok: false, reason: 'the marked line is not valid JSON'};\n }\n try {\n assert(isRecord(value), 'the JSON must be an object');\n assertOnlyKeys(\n value,\n isStage ? ['formatVersion', 'groups', 'order', 'sets'] : ['formatVersion', 'groups'],\n 'the JSON',\n );\n assert(\n value.formatVersion === blockPaletteFormatVersion,\n `unsupported formatVersion ${String(value.formatVersion)}`,\n );\n assert(isStage || value.groups !== undefined, 'the JSON has no groups');\n const parsed = {\n order: value.order === undefined ? undefined : validateGroupList(value.order, 'order'),\n sets: value.sets === undefined ? undefined : validateSets(value.sets, 'sets'),\n stage:\n value.groups === undefined\n ? undefined\n : {groups: validateGroupList(value.groups, 'groups')},\n };\n assert(\n parsed.order !== undefined || parsed.sets !== undefined || parsed.stage !== undefined,\n 'the JSON has no settings',\n );\n return {ok: true, value: parsed};\n } catch (error) {\n return {ok: false, reason: error instanceof Error ? error.message : String(error)};\n }\n}\n\n/**\n * Move palette comments from an SB3 project into a `block-palette.json` document.\n * The project is changed in place: each recognized comment keeps its ID, position, size,\n * state and order, and its text becomes {@link blockPaletteCommentReference}.\n */\nexport function extractBlockPalette(project: ProjectJson): {\n document: BlockPaletteDocument | null;\n warnings: BlockPaletteWarning[];\n} {\n const warnings: BlockPaletteWarning[] = [];\n const parts: Omit<BlockPaletteDocument, 'formatVersion'> = {};\n const sprites: [string, BlockPaletteTargetSetting][] = [];\n for (const target of targetComments(project, false)) {\n const marked = Object.entries(target.comments).filter(([, comment]) =>\n isMarkedComment(comment),\n );\n const references = Object.values(target.comments).filter(isReferenceComment);\n assert(\n references.length === 0,\n `${target.isStage ? 'The stage' : `Sprite ${target.name}`} has a comment whose text is ` +\n `reserved for block palette references: ${blockPaletteCommentReference}`,\n );\n assert(\n marked.length <= 1,\n `${target.isStage ? 'The stage' : `Sprite ${target.name}`} has ${marked.length} block ` +\n 'palette comments; only one is allowed.',\n );\n if (marked.length === 0) continue;\n const [[commentId, comment]] = marked;\n const parsed = parseMarkedComment(comment, target.isStage);\n if (!parsed.ok) {\n warnings.push({\n code: 'block-palette-invalid',\n commentId,\n message:\n `Block palette comment ${commentId} on ${target.name} was kept as a plain comment ` +\n `and ignored: ${parsed.reason}.`,\n target: target.name,\n });\n continue;\n }\n if (target.isStage) {\n Object.assign(parts, parsed.value);\n } else {\n assert(\n !sprites.some(([name]) => name === target.name),\n `Duplicate sprite name with block palette settings: ${target.name}`,\n );\n sprites.push([target.name, parsed.value.stage!]);\n }\n const document = canonicalDocument({...parts, sprites: Object.fromEntries(sprites)});\n const canonicalText = canonicalCommentText(document, target);\n if (comment.text !== canonicalText) {\n warnings.push({\n code: 'block-palette-normalized',\n commentId,\n message:\n `Block palette comment ${commentId} on ${target.name} is not in the canonical form; ` +\n 'it will be rewritten on build.',\n target: target.name,\n });\n }\n comment.text = blockPaletteCommentReference;\n }\n const document = canonicalDocument({...parts, sprites: Object.fromEntries(sprites)});\n return {document: hasBlockPaletteSettings(document) ? document : null, warnings};\n}\n\n/**\n * Check that `project.source.json` and `block-palette.json` agree, and return the canonical\n * comment text for each reference. `document` is null for source format 1.\n */\nexport function resolveBlockPaletteReferences(\n project: ProjectJson,\n document: BlockPaletteDocument | null,\n): {comment: UnknownRecord; text: string}[] {\n const resolved: {comment: UnknownRecord; text: string}[] = [];\n const targets = targetComments(project, document !== null);\n if (document === null) {\n for (const target of targets) {\n assert(\n !Object.values(target.comments).some(isReferenceComment),\n `project.source.json refers to ${blockPaletteFile}, which requires SB3 source format 2.`,\n );\n }\n return resolved;\n }\n const spriteNames = new Set(targets.filter(({isStage}) => !isStage).map(({name}) => name));\n for (const name of Object.keys(document.sprites ?? {})) {\n assert(spriteNames.has(name), `${blockPaletteFile} refers to an unknown sprite: ${name}`);\n }\n for (const target of targets) {\n const label = target.isStage ? 'The stage' : `Sprite ${target.name}`;\n const references = Object.values(target.comments).filter(isReferenceComment);\n const marked = Object.values(target.comments).filter(isMarkedComment);\n const expected = target.isStage\n ? stageHasSettings(document)\n : document.sprites?.[target.name] !== undefined;\n assert(\n references.length <= 1,\n `${label} has ${references.length} block palette references; only one is allowed.`,\n );\n assert(\n references.length === 0 || marked.length === 0,\n `${label} has both a block palette reference and a block palette comment.`,\n );\n assert(\n references.length === (expected ? 1 : 0),\n expected\n ? `${label} has block palette settings in ${blockPaletteFile} but no comment that ` +\n `refers to it (${blockPaletteCommentReference}).`\n : `${label} has a block palette reference but no settings in ${blockPaletteFile}.`,\n );\n if (references.length === 1) {\n resolved.push({comment: references[0], text: formatBlockPaletteComment(document, target)});\n }\n }\n return resolved;\n}\n\n/** Replace each reference comment in a cloned project with its canonical SB3 text. */\nexport function applyBlockPaletteComments(\n project: ProjectJson,\n document: BlockPaletteDocument | null,\n): void {\n for (const {comment, text} of resolveBlockPaletteReferences(project, document)) {\n comment.text = text;\n }\n}\n"],"mappings":";;;;;;;;;;;AAeA,IAAa,4BAA4B;AACzC,IAAa,mBAAmB;AAChC,IAAa,4BAA4B;AACzC,IAAa,+BAA+B,iBAAiB;AAC7D,IAAa,+BAA+B;AAC5C,IAAa,kCACX;AAEF,IAAa,iCACX;AAGF,IAAM,cAAc;AACpB,IAAM,iBAAiB;AACvB,IAAM,eAAe;AAkCrB,SAAS,SAAS,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,eAAe,OAAsB,SAAmB,aAA2B;CAC1F,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GACjC,OAAO,QAAQ,SAAS,GAAG,GAAG,GAAG,YAAY,uBAAuB,KAAK;AAE7E;AAEA,SAAS,kBAAkB,OAAgB,aAA+B;CACxE,OAAO,MAAM,QAAQ,KAAK,GAAG,GAAG,YAAY,sCAAsC;CAClF,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,SAAS,OAAoB;EACtC,OACE,OAAO,UAAU,YAAY,eAAe,KAAK,KAAK,GACtD,GAAG,YAAY,uCAAuC,KAAK,UAAU,KAAK,GAC5E;EACA,OAAO,CAAC,KAAK,IAAI,KAAK,GAAG,GAAG,YAAY,wCAAwC,OAAO;EACvF,KAAK,IAAI,KAAK;CAChB;CACA,OAAO,CAAC,GAAG,IAAI;AACjB;AAEA,SAAS,sBAAsB,OAAgB,aAAgD;CAC7F,OAAO,SAAS,KAAK,GAAG,GAAG,YAAY,oBAAoB;CAC3D,eAAe,OAAO,CAAC,QAAQ,GAAG,WAAW;CAC7C,OAAO,EAAC,QAAQ,kBAAkB,MAAM,QAAQ,GAAG,YAAY,QAAQ,EAAC;AAC1E;AAEA,SAAS,aAAa,OAAgB,aAAsD;CAC1F,OAAO,SA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UAAU,OAAO,UAAU,KAAA;EACxC,OACE,WAAW,UAAU,GACrB,GAAG,MAAM,OAAO,WAAW,OAAO,gDACpC;EACA,OACE,WAAW,WAAW,KAAK,OAAO,WAAW,GAC7C,GAAG,MAAM,iEACX;EACA,OACE,WAAW,YAAY,WAAW,IAAI,IACtC,WACI,GAAG,MAAM,iCAAiC,iBAAiB,qCACxC,6BAA6B,MAChD,GAAG,MAAM,oDAAoD,iBAAiB,EACpF;EACA,IAAI,WAAW,WAAW,GACxB,SAAS,KAAK;GAAC,SAAS,WAAW;GAAI,MAAM,0BAA0B,UAAU,MAAM;EAAC,CAAC;CAE7F;CACA,OAAO;AACT;;AAGA,SAAgB,0BACd,SACA,UACM;CACN,KAAK,MAAM,EAAC,SAAS,UAAS,8BAA8B,SAAS,QAAQ,GAC3E,QAAQ,OAAO;AAEnB"}
@@ -0,0 +1,24 @@
1
+ import { BlockPaletteWarningCode } from './block-palette';
2
+ export { Sb3SourceError } from './expand-archive';
3
+ export type { Sb3SourceErrorCode } from './expand-archive';
4
+ export { packageVersion } from './constants';
5
+ export { blockPaletteCommentMarker, blockPaletteCommentMaxLength, blockPaletteCommentReference, blockPaletteFile, blockPaletteFormatVersion, blockPaletteSpriteCommentHeader, blockPaletteStageCommentHeader, formatBlockPaletteComment, serializeBlockPaletteDocument, validateBlockPaletteDocument, } from './block-palette';
6
+ export type { BlockPaletteDocument, BlockPaletteSet, BlockPaletteTargetSetting, } from './block-palette';
7
+ export { blockPaletteSourceFormatVersion, sourceFormatVersion, supportedSourceFormatVersions, } from './source-format';
8
+ export interface UnpackWarning {
9
+ code: 'directory-entry' | 'unreferenced-asset' | BlockPaletteWarningCode;
10
+ /** The archive entry, or `project.json` for block palette comments. */
11
+ path: string;
12
+ /** Present for block palette warnings. */
13
+ commentId?: string;
14
+ message?: string;
15
+ target?: string;
16
+ }
17
+ export interface UnpackedSb3 {
18
+ files: Map<string, Uint8Array>;
19
+ warnings: UnpackWarning[];
20
+ }
21
+ /** Validate the layout and asset bytes of a project folder in memory. */
22
+ export declare function validateSourceFiles(files: ReadonlyMap<string, Uint8Array>): void;
23
+ /** Expand an SB3 into files suitable for opening as an Editor project folder. */
24
+ export declare function unpackSb3(bytes: Uint8Array): UnpackedSb3;