@segnavia/format 0.4.0 → 0.6.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.js CHANGED
@@ -2,18 +2,16 @@ import { Direction, firstStrongDirection, languageDirection, resolveDirection }
2
2
  import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.js";
3
3
  import { MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, NAMED_PAPERS, PAPER_MM, PX_PER_MM, Paper, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters } from "./paper.js";
4
4
  import { Scripts } from "./scripts.js";
5
- import { Book, BookMode, BookPage, BookSection, BookShape, Chapter, noteMarkerIssues } from "./book.js";
6
- import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
7
- import { MAX_SLIDE_TIMING_MS, SlideTiming, slideTimingIssues } from "./timing.js";
5
+ import { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, Chapter, isBookContents, noteMarkerIssues } from "./book.js";
6
+ import { MAX_SLIDE_TIMING_MS } from "./timing.js";
8
7
  import { DEFAULT_TRANSITION_DURATION_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, Transition } from "./transition.js";
8
+ import { Annotation, Box, Cue, DECK_SIZE, Deck, DeckShape, Manifest, Narration, Point, PublishedShot, SHOT_KEY, Shot, Size, Slide, SlideContent, Word, annotationCueIssues, exceedsLimits } from "./deck.js";
9
+ import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
10
+ import { deckFromSlides } from "./deck-from-slides.js";
9
11
  import { fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
10
12
  import { shotsUsed } from "./shots-used.js";
11
13
  import { z } from "zod";
12
14
  //#region src/index.ts
13
- const Size = z.object({
14
- width: z.number().int().positive(),
15
- height: z.number().int().positive()
16
- });
17
15
  const Margin = z.object({
18
16
  top: z.number().nonnegative().default(0),
19
17
  right: z.number().nonnegative().default(0),
@@ -140,190 +138,6 @@ const Page = z.object({
140
138
  lang: z.string().optional(),
141
139
  print: Print.optional()
142
140
  });
143
- const Box = z.object({
144
- x: z.number(),
145
- y: z.number(),
146
- width: z.number(),
147
- height: z.number()
148
- });
149
- const Point = z.object({
150
- x: z.number(),
151
- y: z.number()
152
- });
153
- const Annotation = z.object({
154
- ring: Box.nullable(),
155
- badge: z.object({
156
- center: Point,
157
- number: z.number().int()
158
- }).nullable(),
159
- arrow: z.object({
160
- head: Point,
161
- tail: Point,
162
- label: z.string().nullable()
163
- }).nullable()
164
- });
165
- const SHOT_KEY = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
166
- const Shot = z.object({
167
- key: z.string().regex(SHOT_KEY),
168
- title: z.string(),
169
- description: z.string().nullable().default(null),
170
- tags: z.array(z.string()).default([]),
171
- file: z.string(),
172
- annotatedFile: z.string().nullable().default(null),
173
- size: Size,
174
- scale: z.number().positive(),
175
- dir: z.enum(["ltr", "rtl"]).default("ltr"),
176
- annotations: z.array(Annotation),
177
- capturedAt: z.string(),
178
- meta: z.record(z.string(), z.unknown()).default({})
179
- });
180
- const PublishedShot = z.object({
181
- src: z.string(),
182
- shot: Shot
183
- });
184
- const Word = z.object({
185
- text: z.string(),
186
- startMs: z.number().nonnegative(),
187
- endMs: z.number().nonnegative()
188
- });
189
- const Cue = z.object({
190
- word: z.number().int().nonnegative(),
191
- annotation: z.number().int().nonnegative(),
192
- untilWord: z.number().int().nonnegative().optional()
193
- });
194
- const Narration = z.object({
195
- text: z.string(),
196
- lang: z.string().optional(),
197
- dir: Direction.optional(),
198
- voice: z.string().optional(),
199
- words: z.array(Word),
200
- durationMs: z.number().nonnegative(),
201
- audio: z.string().nullable(),
202
- live: z.boolean().default(false),
203
- cues: z.array(Cue).default([])
204
- });
205
- const SlideContent = z.discriminatedUnion("kind", [
206
- z.object({
207
- kind: z.literal("html"),
208
- html: z.string()
209
- }),
210
- z.object({
211
- kind: z.literal("url"),
212
- src: z.string()
213
- }),
214
- z.object({
215
- kind: z.literal("shot"),
216
- src: z.string(),
217
- shot: Shot
218
- }),
219
- z.object({
220
- kind: z.literal("shot-ref"),
221
- href: z.string()
222
- }),
223
- z.object({
224
- kind: z.literal("image"),
225
- src: z.string(),
226
- alt: z.string()
227
- })
228
- ]);
229
- const Slide = z.object({
230
- id: z.string(),
231
- content: SlideContent,
232
- notes: z.string().optional(),
233
- narration: Narration.optional(),
234
- beforeMs: SlideTiming.optional(),
235
- afterMs: SlideTiming.optional(),
236
- holdMs: SlideTiming.optional()
237
- });
238
- const DECK_SIZE = {
239
- width: 1280,
240
- height: 720
241
- };
242
- const DeckShape = z.object({
243
- title: z.string(),
244
- size: Size.default(DECK_SIZE),
245
- scripts: Scripts.default("refuse"),
246
- dir: Direction.optional(),
247
- lang: z.string().optional(),
248
- transition: Transition.optional(),
249
- playback: z.enum(["step", "continuous"]).optional(),
250
- captions: z.enum([
251
- "on",
252
- "off",
253
- "viewer"
254
- ]).optional(),
255
- slides: z.array(Slide).min(1)
256
- });
257
- function annotationCueIssues(narration, annotations) {
258
- if (!narration) return [];
259
- return narration.cues.filter((cue) => cue.annotation >= annotations).map((cue) => `a cue names annotation ${cue.annotation}, but the slide has ${annotations}`);
260
- }
261
- function cueIssues(slide) {
262
- const narration = slide.narration;
263
- if (!narration) return [];
264
- const annotations = slide.content.kind === "shot" ? slide.content.shot.annotations.length : null;
265
- const words = narration.live ? null : narration.words.length;
266
- const issues = [];
267
- for (const cue of narration.cues) {
268
- for (const word of [cue.word, cue.untilWord]) if (word !== void 0 && words !== null && word >= words) issues.push(`a cue names word ${word}, but the narration has ${words} words`);
269
- if (slide.content.kind !== "shot" && slide.content.kind !== "shot-ref") issues.push("a cue names an annotation, but only a shot carries annotations");
270
- }
271
- if (annotations !== null) issues.push(...annotationCueIssues(narration, annotations));
272
- return issues;
273
- }
274
- const Deck = DeckShape.superRefine((deck, ctx) => {
275
- deck.slides.forEach((slide, index) => {
276
- for (const message of cueIssues(slide)) ctx.addIssue({
277
- code: "custom",
278
- path: [
279
- "slides",
280
- index,
281
- "narration",
282
- "cues"
283
- ],
284
- message
285
- });
286
- for (const field of slideTimingIssues(slide)) {
287
- const kind = field === "holdMs" ? "without" : "with";
288
- ctx.addIssue({
289
- code: "custom",
290
- path: [
291
- "slides",
292
- index,
293
- field
294
- ],
295
- message: `${field} is allowed only ${kind} narration`
296
- });
297
- }
298
- });
299
- const ids = /* @__PURE__ */ new Set();
300
- deck.slides.forEach((slide, index) => {
301
- if (ids.has(slide.id)) ctx.addIssue({
302
- code: "custom",
303
- path: [
304
- "slides",
305
- index,
306
- "id"
307
- ],
308
- message: `slide id "${slide.id}" is used twice`
309
- });
310
- ids.add(slide.id);
311
- });
312
- });
313
- const Manifest = z.object({
314
- shots: z.record(z.string(), Shot),
315
- updatedAt: z.string()
316
- });
317
- function exceedsLimits(deck, limits) {
318
- const reasons = [];
319
- const bytes = (text) => new TextEncoder().encode(text).length;
320
- if (limits.maxSlides !== void 0 && deck.slides.length > limits.maxSlides) reasons.push(`the deck has ${deck.slides.length} slides; the limit is ${limits.maxSlides}`);
321
- deck.slides.forEach((slide, index) => {
322
- if (limits.maxSlideBytes !== void 0 && slide.content.kind === "html" && bytes(slide.content.html) > limits.maxSlideBytes) reasons.push(`slide ${index + 1} is ${bytes(slide.content.html)} bytes; the limit is ${limits.maxSlideBytes}`);
323
- if (limits.maxNotesBytes !== void 0 && slide.notes && bytes(slide.notes) > limits.maxNotesBytes) reasons.push(`slide ${index + 1} has ${bytes(slide.notes)} bytes of notes; the limit is ${limits.maxNotesBytes}`);
324
- });
325
- return reasons;
326
- }
327
141
  function jsonSchemas() {
328
142
  return {
329
143
  book: z.toJSONSchema(BookShape, { io: "input" }),
@@ -336,4 +150,4 @@ function jsonSchemas() {
336
150
  };
337
151
  }
338
152
  //#endregion
339
- export { Annotation, Book, BookMode, BookPage, BookSection, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, Imposition, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, Margin, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, Page, PageSize, Paper, Point, Print, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, Size, Slide, SlideContent, Transition, Word, annotationCueIssues, exceedsLimits, firstStrongDirection, fitPage, formatNumber, impose, jsonSchemas, languageDirection, lexiconVersion, mirrorPlacement, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, sheetMm, shotsUsed, toMillimeters };
153
+ export { Annotation, Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, Box, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, Imposition, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, Margin, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, Page, PageSize, Paper, Point, Print, PronunciationEntry, PublishedShot, SHOT_KEY, Scripts, Shot, Size, Slide, SlideContent, Transition, Word, annotationCueIssues, deckFromSlides, exceedsLimits, firstStrongDirection, fitPage, formatNumber, impose, isBookContents, jsonSchemas, languageDirection, lexiconVersion, mirrorPlacement, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, sheetMm, shotsUsed, toMillimeters };
@@ -1,4 +1,5 @@
1
- import { Deck } from "./index.js";
1
+ import { Deck } from "./deck.js";
2
+ import "./index.js";
2
3
  //#region src/shots-used.d.ts
3
4
  export interface ShotUse {
4
5
  slide: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segnavia/format",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {