open-board-format 1.0.5 → 1.1.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/dist/index.d.mts +25 -25
- package/dist/index.mjs +31 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -63,7 +63,7 @@ declare const OBFLicenseSchema: z.ZodObject<{
|
|
|
63
63
|
author_name: z.ZodOptional<z.ZodString>;
|
|
64
64
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
65
65
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
66
|
-
}, z.core.$
|
|
66
|
+
}, z.core.$loose>;
|
|
67
67
|
type OBFLicense = z.infer<typeof OBFLicenseSchema>;
|
|
68
68
|
/**
|
|
69
69
|
* Common properties for media resources (images and sounds).
|
|
@@ -87,8 +87,8 @@ declare const OBFMediaSchema: z.ZodObject<{
|
|
|
87
87
|
author_name: z.ZodOptional<z.ZodString>;
|
|
88
88
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
89
89
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
90
|
-
}, z.core.$
|
|
91
|
-
}, z.core.$
|
|
90
|
+
}, z.core.$loose>>;
|
|
91
|
+
}, z.core.$loose>;
|
|
92
92
|
type OBFMedia = z.infer<typeof OBFMediaSchema>;
|
|
93
93
|
/**
|
|
94
94
|
* Reference to a symbol in a proprietary symbol set (e.g., SymbolStix).
|
|
@@ -96,7 +96,7 @@ type OBFMedia = z.infer<typeof OBFMediaSchema>;
|
|
|
96
96
|
declare const OBFSymbolInfoSchema: z.ZodObject<{
|
|
97
97
|
set: z.ZodString;
|
|
98
98
|
filename: z.ZodString;
|
|
99
|
-
}, z.core.$
|
|
99
|
+
}, z.core.$loose>;
|
|
100
100
|
type OBFSymbolInfo = z.infer<typeof OBFSymbolInfoSchema>;
|
|
101
101
|
/**
|
|
102
102
|
* Image resource, extending {@link OBFMediaSchema} with optional
|
|
@@ -122,12 +122,12 @@ declare const OBFImageSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
122
122
|
author_name: z.ZodOptional<z.ZodString>;
|
|
123
123
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
124
124
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
125
|
-
}, z.core.$
|
|
126
|
-
}, z.core.$
|
|
125
|
+
}, z.core.$loose>>;
|
|
126
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
127
127
|
symbol: z.ZodOptional<z.ZodObject<{
|
|
128
128
|
set: z.ZodString;
|
|
129
129
|
filename: z.ZodString;
|
|
130
|
-
}, z.core.$
|
|
130
|
+
}, z.core.$loose>>;
|
|
131
131
|
width: z.ZodOptional<z.ZodNumber>;
|
|
132
132
|
height: z.ZodOptional<z.ZodNumber>;
|
|
133
133
|
}, z.core.$strip>>;
|
|
@@ -149,8 +149,8 @@ declare const OBFSoundSchema: z.ZodObject<{
|
|
|
149
149
|
author_name: z.ZodOptional<z.ZodString>;
|
|
150
150
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
151
151
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
152
|
-
}, z.core.$
|
|
153
|
-
}, z.core.$
|
|
152
|
+
}, z.core.$loose>>;
|
|
153
|
+
}, z.core.$loose>;
|
|
154
154
|
type OBFSound = z.infer<typeof OBFSoundSchema>;
|
|
155
155
|
/**
|
|
156
156
|
* Reference to another board, resolved by ID, path, or URL.
|
|
@@ -161,7 +161,7 @@ declare const OBFLoadBoardSchema: z.ZodObject<{
|
|
|
161
161
|
data_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
162
162
|
url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
163
163
|
path: z.ZodOptional<z.ZodString>;
|
|
164
|
-
}, z.core.$
|
|
164
|
+
}, z.core.$loose>;
|
|
165
165
|
type OBFLoadBoard = z.infer<typeof OBFLoadBoardSchema>;
|
|
166
166
|
/**
|
|
167
167
|
* Interactive element on a board, optionally linked to images, sounds, and actions.
|
|
@@ -180,14 +180,14 @@ declare const OBFButtonSchema: z.ZodObject<{
|
|
|
180
180
|
data_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
181
181
|
url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
182
182
|
path: z.ZodOptional<z.ZodString>;
|
|
183
|
-
}, z.core.$
|
|
183
|
+
}, z.core.$loose>>;
|
|
184
184
|
background_color: z.ZodOptional<z.ZodString>;
|
|
185
185
|
border_color: z.ZodOptional<z.ZodString>;
|
|
186
186
|
top: z.ZodOptional<z.ZodNumber>;
|
|
187
187
|
left: z.ZodOptional<z.ZodNumber>;
|
|
188
188
|
width: z.ZodOptional<z.ZodNumber>;
|
|
189
189
|
height: z.ZodOptional<z.ZodNumber>;
|
|
190
|
-
}, z.core.$
|
|
190
|
+
}, z.core.$loose>;
|
|
191
191
|
type OBFButton = z.infer<typeof OBFButtonSchema>;
|
|
192
192
|
/**
|
|
193
193
|
* Row-and-column layout that arranges buttons by their IDs.
|
|
@@ -196,7 +196,7 @@ declare const OBFGridSchema: z.ZodObject<{
|
|
|
196
196
|
rows: z.ZodNumber;
|
|
197
197
|
columns: z.ZodNumber;
|
|
198
198
|
order: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>, z.ZodString>, z.ZodNull]>>>;
|
|
199
|
-
}, z.core.$
|
|
199
|
+
}, z.core.$loose>;
|
|
200
200
|
type OBFGrid = z.infer<typeof OBFGridSchema>;
|
|
201
201
|
/**
|
|
202
202
|
* Root object of an `.obf` file: the complete definition of a single communication board.
|
|
@@ -219,14 +219,14 @@ declare const OBFBoardSchema: z.ZodObject<{
|
|
|
219
219
|
data_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
220
220
|
url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
221
221
|
path: z.ZodOptional<z.ZodString>;
|
|
222
|
-
}, z.core.$
|
|
222
|
+
}, z.core.$loose>>;
|
|
223
223
|
background_color: z.ZodOptional<z.ZodString>;
|
|
224
224
|
border_color: z.ZodOptional<z.ZodString>;
|
|
225
225
|
top: z.ZodOptional<z.ZodNumber>;
|
|
226
226
|
left: z.ZodOptional<z.ZodNumber>;
|
|
227
227
|
width: z.ZodOptional<z.ZodNumber>;
|
|
228
228
|
height: z.ZodOptional<z.ZodNumber>;
|
|
229
|
-
}, z.core.$
|
|
229
|
+
}, z.core.$loose>>;
|
|
230
230
|
url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
231
231
|
name: z.ZodOptional<z.ZodString>;
|
|
232
232
|
description_html: z.ZodOptional<z.ZodString>;
|
|
@@ -234,7 +234,7 @@ declare const OBFBoardSchema: z.ZodObject<{
|
|
|
234
234
|
rows: z.ZodNumber;
|
|
235
235
|
columns: z.ZodNumber;
|
|
236
236
|
order: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>, z.ZodString>, z.ZodNull]>>>;
|
|
237
|
-
}, z.core.$
|
|
237
|
+
}, z.core.$loose>;
|
|
238
238
|
images: z.ZodOptional<z.ZodArray<z.ZodIntersection<z.ZodObject<{
|
|
239
239
|
id: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>, z.ZodString>;
|
|
240
240
|
data: z.ZodOptional<z.ZodString>;
|
|
@@ -249,12 +249,12 @@ declare const OBFBoardSchema: z.ZodObject<{
|
|
|
249
249
|
author_name: z.ZodOptional<z.ZodString>;
|
|
250
250
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
251
251
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
252
|
-
}, z.core.$
|
|
253
|
-
}, z.core.$
|
|
252
|
+
}, z.core.$loose>>;
|
|
253
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
254
254
|
symbol: z.ZodOptional<z.ZodObject<{
|
|
255
255
|
set: z.ZodString;
|
|
256
256
|
filename: z.ZodString;
|
|
257
|
-
}, z.core.$
|
|
257
|
+
}, z.core.$loose>>;
|
|
258
258
|
width: z.ZodOptional<z.ZodNumber>;
|
|
259
259
|
height: z.ZodOptional<z.ZodNumber>;
|
|
260
260
|
}, z.core.$strip>>>>;
|
|
@@ -272,8 +272,8 @@ declare const OBFBoardSchema: z.ZodObject<{
|
|
|
272
272
|
author_name: z.ZodOptional<z.ZodString>;
|
|
273
273
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
274
274
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
275
|
-
}, z.core.$
|
|
276
|
-
}, z.core.$
|
|
275
|
+
}, z.core.$loose>>;
|
|
276
|
+
}, z.core.$loose>>>;
|
|
277
277
|
license: z.ZodOptional<z.ZodObject<{
|
|
278
278
|
type: z.ZodString;
|
|
279
279
|
copyright_notice_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
@@ -281,9 +281,9 @@ declare const OBFBoardSchema: z.ZodObject<{
|
|
|
281
281
|
author_name: z.ZodOptional<z.ZodString>;
|
|
282
282
|
author_url: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodURL, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
283
283
|
author_email: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodEmail, z.ZodLiteral<"">]>, z.ZodTransform<string | undefined, string>>>;
|
|
284
|
-
}, z.core.$
|
|
284
|
+
}, z.core.$loose>>;
|
|
285
285
|
strings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
286
|
-
}, z.core.$
|
|
286
|
+
}, z.core.$loose>;
|
|
287
287
|
type OBFBoard = z.infer<typeof OBFBoardSchema>;
|
|
288
288
|
/**
|
|
289
289
|
* Table of contents for an `.obz` package, mapping resource IDs to their archive paths.
|
|
@@ -295,8 +295,8 @@ declare const OBFManifestSchema: z.ZodObject<{
|
|
|
295
295
|
boards: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
296
296
|
images: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
297
297
|
sounds: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
298
|
-
}, z.core.$
|
|
299
|
-
}, z.core.$
|
|
298
|
+
}, z.core.$loose>;
|
|
299
|
+
}, z.core.$loose>;
|
|
300
300
|
type OBFManifest = z.infer<typeof OBFManifestSchema>;
|
|
301
301
|
//#endregion
|
|
302
302
|
//#region src/obf.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -57,7 +57,7 @@ const OBFButtonActionSchema = z.union([OBFSpellingActionSchema, OBFSpecialtyActi
|
|
|
57
57
|
/**
|
|
58
58
|
* License terms and attribution for a resource.
|
|
59
59
|
*/
|
|
60
|
-
const OBFLicenseSchema = z.
|
|
60
|
+
const OBFLicenseSchema = z.looseObject({
|
|
61
61
|
/** Type of the license, e.g., 'CC-BY-SA'. */
|
|
62
62
|
type: z.string(),
|
|
63
63
|
/** URL to the license terms. */
|
|
@@ -79,7 +79,7 @@ const OBFLicenseSchema = z.object({
|
|
|
79
79
|
* 2. path
|
|
80
80
|
* 3. url
|
|
81
81
|
*/
|
|
82
|
-
const OBFMediaSchema = z.
|
|
82
|
+
const OBFMediaSchema = z.looseObject({
|
|
83
83
|
/** Unique identifier for the media resource. */
|
|
84
84
|
id: OBFIDSchema,
|
|
85
85
|
/** Data URI containing the media data. */
|
|
@@ -98,7 +98,7 @@ const OBFMediaSchema = z.object({
|
|
|
98
98
|
/**
|
|
99
99
|
* Reference to a symbol in a proprietary symbol set (e.g., SymbolStix).
|
|
100
100
|
*/
|
|
101
|
-
const OBFSymbolInfoSchema = z.
|
|
101
|
+
const OBFSymbolInfoSchema = z.looseObject({
|
|
102
102
|
/** Name of the symbol set, e.g., 'symbolstix'. */
|
|
103
103
|
set: z.string(),
|
|
104
104
|
/** Filename of the symbol within the set. */
|
|
@@ -129,7 +129,7 @@ const OBFSoundSchema = OBFMediaSchema;
|
|
|
129
129
|
/**
|
|
130
130
|
* Reference to another board, resolved by ID, path, or URL.
|
|
131
131
|
*/
|
|
132
|
-
const OBFLoadBoardSchema = z.
|
|
132
|
+
const OBFLoadBoardSchema = z.looseObject({
|
|
133
133
|
/** Unique identifier of the board to load. */
|
|
134
134
|
id: OBFOptionalIDSchema,
|
|
135
135
|
/** Name of the board to load. */
|
|
@@ -144,7 +144,7 @@ const OBFLoadBoardSchema = z.object({
|
|
|
144
144
|
/**
|
|
145
145
|
* Interactive element on a board, optionally linked to images, sounds, and actions.
|
|
146
146
|
*/
|
|
147
|
-
const OBFButtonSchema = z.
|
|
147
|
+
const OBFButtonSchema = z.looseObject({
|
|
148
148
|
/** Unique identifier for the button. */
|
|
149
149
|
id: OBFIDSchema,
|
|
150
150
|
/** Label text displayed on the button. */
|
|
@@ -177,7 +177,7 @@ const OBFButtonSchema = z.object({
|
|
|
177
177
|
/**
|
|
178
178
|
* Row-and-column layout that arranges buttons by their IDs.
|
|
179
179
|
*/
|
|
180
|
-
const OBFGridSchema = z.
|
|
180
|
+
const OBFGridSchema = z.looseObject({
|
|
181
181
|
/** Number of rows in the grid. */
|
|
182
182
|
rows: z.number().int().min(1),
|
|
183
183
|
/** Number of columns in the grid. */
|
|
@@ -191,7 +191,7 @@ const OBFGridSchema = z.object({
|
|
|
191
191
|
/**
|
|
192
192
|
* Root object of an `.obf` file: the complete definition of a single communication board.
|
|
193
193
|
*/
|
|
194
|
-
const OBFBoardSchema = z.
|
|
194
|
+
const OBFBoardSchema = z.looseObject({
|
|
195
195
|
/** Format version of the Open Board Format, e.g., 'open-board-0.1'. */
|
|
196
196
|
format: OBFFormatVersionSchema,
|
|
197
197
|
/** Unique identifier for the board. */
|
|
@@ -220,13 +220,13 @@ const OBFBoardSchema = z.object({
|
|
|
220
220
|
/**
|
|
221
221
|
* Table of contents for an `.obz` package, mapping resource IDs to their archive paths.
|
|
222
222
|
*/
|
|
223
|
-
const OBFManifestSchema = z.
|
|
223
|
+
const OBFManifestSchema = z.looseObject({
|
|
224
224
|
/** Format version of the Open Board Format, e.g., 'open-board-0.1'. */
|
|
225
225
|
format: OBFFormatVersionSchema,
|
|
226
226
|
/** Path to the root board within the .obz package. */
|
|
227
227
|
root: z.string(),
|
|
228
228
|
/** Mapping of IDs to paths for boards, images, and sounds. */
|
|
229
|
-
paths: z.
|
|
229
|
+
paths: z.looseObject({
|
|
230
230
|
/** Mapping of board IDs to their file paths. */
|
|
231
231
|
boards: z.record(z.string(), z.string()),
|
|
232
232
|
/** Mapping of image IDs to their file paths. */
|
|
@@ -440,15 +440,18 @@ function parseManifest(json) {
|
|
|
440
440
|
* @throws {Error} If `rootBoardId` does not match any of the supplied boards.
|
|
441
441
|
*/
|
|
442
442
|
async function createOBZ(boards, rootBoardId, resources) {
|
|
443
|
+
if (!boards.some((board) => board.id === rootBoardId)) throw new Error(`Invalid OBZ: rootBoardId "${rootBoardId}" does not match any supplied board`);
|
|
443
444
|
const entries = /* @__PURE__ */ new Map();
|
|
444
445
|
const boardPaths = Object.fromEntries(boards.map((board) => [board.id, `boards/${board.id}.obf`]));
|
|
446
|
+
const imagePaths = collectMediaPaths(boards, "images");
|
|
447
|
+
const soundPaths = collectMediaPaths(boards, "sounds");
|
|
445
448
|
const manifest = OBFManifestSchema.parse({
|
|
446
449
|
format: "open-board-0.1",
|
|
447
450
|
root: `boards/${rootBoardId}.obf`,
|
|
448
451
|
paths: {
|
|
449
452
|
boards: boardPaths,
|
|
450
|
-
images:
|
|
451
|
-
sounds: {}
|
|
453
|
+
images: imagePaths,
|
|
454
|
+
...Object.keys(soundPaths).length > 0 ? { sounds: soundPaths } : {}
|
|
452
455
|
}
|
|
453
456
|
});
|
|
454
457
|
const encoder = new TextEncoder();
|
|
@@ -461,6 +464,23 @@ async function createOBZ(boards, rootBoardId, resources) {
|
|
|
461
464
|
const compressed = await zip(entries);
|
|
462
465
|
return new Blob([new Uint8Array(compressed)], { type: "application/zip" });
|
|
463
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Walk every board's media collection and produce the `{ id -> path }` map
|
|
469
|
+
* the spec calls "redundant but still required" for the OBZ manifest.
|
|
470
|
+
*
|
|
471
|
+
* Throws when two boards declare the same media id with conflicting paths
|
|
472
|
+
* — a silent OBZ that points at a non-existent file is worse than a clear error.
|
|
473
|
+
*/
|
|
474
|
+
function collectMediaPaths(boards, kind) {
|
|
475
|
+
const paths = {};
|
|
476
|
+
for (const board of boards) for (const media of board[kind] ?? []) {
|
|
477
|
+
if (media.path === void 0) continue;
|
|
478
|
+
const existing = paths[media.id];
|
|
479
|
+
if (existing !== void 0 && existing !== media.path) throw new Error(`Invalid OBZ: ${kind} id "${media.id}" maps to conflicting paths "${existing}" and "${media.path}"`);
|
|
480
|
+
paths[media.id] = media.path;
|
|
481
|
+
}
|
|
482
|
+
return paths;
|
|
483
|
+
}
|
|
464
484
|
function extractManifest(entries) {
|
|
465
485
|
const manifestBytes = entries.get("manifest.json");
|
|
466
486
|
if (!manifestBytes) throw new Error("Invalid OBZ: missing manifest.json");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "open-board-format",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "Parse, validate, and create Open Board Format (OBF/OBZ) files for AAC applications.",
|
|
6
6
|
"author": "Shay Cojocaru <shayc@outlook.com>",
|
|
7
7
|
"license": "MIT",
|