@segnavia/format 0.26.0 → 0.27.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/book.d.ts CHANGED
@@ -93,12 +93,17 @@ export declare const BookView: z.ZodObject<{
93
93
  sandboxed: "sandboxed";
94
94
  }>>;
95
95
  lang: z.ZodOptional<z.ZodString>;
96
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
97
+ app: z.ZodString;
98
+ }, z.core.$strip>, z.ZodObject<{
99
+ local: z.ZodString;
100
+ fallback: z.ZodString;
101
+ }, z.core.$strip>]>>>;
96
102
  title: z.ZodOptional<z.ZodString>;
97
103
  html: z.ZodString;
98
104
  }, z.core.$strip>;
99
105
  export type BookView = z.infer<typeof BookView>;
100
106
  export type BookViewInput = z.input<typeof BookView>;
101
- export declare function isHebrew(lang: string | undefined): boolean;
102
107
  export declare const Book: z.ZodPipe<z.ZodObject<{
103
108
  title: z.ZodString;
104
109
  mode: z.ZodEnum<{
@@ -177,6 +182,12 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
177
182
  html: z.ZodString;
178
183
  runningHead: z.ZodOptional<z.ZodString>;
179
184
  }, z.core.$strip>>;
185
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
186
+ app: z.ZodString;
187
+ }, z.core.$strip>, z.ZodObject<{
188
+ local: z.ZodString;
189
+ fallback: z.ZodString;
190
+ }, z.core.$strip>]>>>;
180
191
  numbering: z.ZodDefault<z.ZodObject<{
181
192
  frontMatter: z.ZodOptional<z.ZodEnum<{
182
193
  arabic: "arabic";
@@ -272,6 +283,12 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
272
283
  } | undefined;
273
284
  dir?: "ltr" | "rtl" | "auto" | undefined;
274
285
  lang?: string | undefined;
286
+ fonts?: ({
287
+ app: string;
288
+ } | {
289
+ local: string;
290
+ fallback: string;
291
+ })[] | undefined;
275
292
  }, {
276
293
  title: string;
277
294
  mode: "continuous" | "paginated";
@@ -323,6 +340,12 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
323
340
  } | undefined;
324
341
  dir?: "ltr" | "rtl" | "auto" | undefined;
325
342
  lang?: string | undefined;
343
+ fonts?: ({
344
+ app: string;
345
+ } | {
346
+ local: string;
347
+ fallback: string;
348
+ })[] | undefined;
326
349
  }>>;
327
350
  export type Book = z.infer<typeof Book>;
328
351
  export type BookInput = z.input<typeof Book>;
package/dist/book.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Direction } from "./direction.js";
2
2
  import { Scripts } from "./scripts.js";
3
- import { NoteMarker, NumberSystem } from "./numbering.js";
3
+ import { FontReference } from "./fonts.js";
4
+ import { NoteMarker, NumberSystem, isHebrew } from "./numbering.js";
4
5
  import { Orientation, Paper, sheetMm } from "./paper.js";
5
6
  import { z } from "zod";
6
7
  //#region src/book.ts
@@ -42,6 +43,7 @@ const BookShape = z.object({
42
43
  lang: z.string().optional(),
43
44
  frontMatter: z.array(BookFrontMatterEntry).default([]),
44
45
  chapters: z.array(Chapter).min(1),
46
+ fonts: z.array(FontReference).optional(),
45
47
  numbering: z.object({
46
48
  frontMatter: NumberSystem.optional(),
47
49
  body: NumberSystem.optional()
@@ -68,15 +70,12 @@ const BookView = BookShape.pick({
68
70
  title: true,
69
71
  dir: true,
70
72
  lang: true,
71
- scripts: true
73
+ scripts: true,
74
+ fonts: true
72
75
  }).extend({
73
76
  title: BookShape.shape.title.optional(),
74
77
  html: z.string()
75
78
  });
76
- function isHebrew(lang) {
77
- const primary = lang?.split("-")[0]?.toLowerCase();
78
- return primary === "he" || primary === "iw";
79
- }
80
79
  const Book = BookShape.transform((book) => {
81
80
  const hebrew = isHebrew(book.lang);
82
81
  return {
@@ -137,4 +136,4 @@ function noteMarkerIssues(book, used) {
137
136
  return [`footnote and endnote markers are both ${book.footnotes.marker}; the two must differ when both kinds are used`];
138
137
  }
139
138
  //#endregion
140
- export { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, BookView, Chapter, isBookContents, isHebrew, noteMarkerIssues };
139
+ export { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, BookView, Chapter, isBookContents, noteMarkerIssues };
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ //#region src/fonts.d.ts
3
+ export declare const APP_FONT_NAME: RegExp;
4
+ export declare const APP_FONT_NAME_MESSAGE = "app font names are lowercase letters, digits and hyphens";
5
+ export declare const FontReference: z.ZodUnion<readonly [z.ZodObject<{
6
+ app: z.ZodString;
7
+ }, z.core.$strip>, z.ZodObject<{
8
+ local: z.ZodString;
9
+ fallback: z.ZodString;
10
+ }, z.core.$strip>]>;
11
+ export type FontReference = z.infer<typeof FontReference>;
12
+ export declare const FontReferenceInput: z.ZodUnion<readonly [z.ZodObject<{
13
+ app: z.ZodString;
14
+ }, z.core.$strict>, z.ZodObject<{
15
+ local: z.ZodString;
16
+ fallback: z.ZodString;
17
+ }, z.core.$strict>]>;
18
+ export type FontReferenceInput = z.input<typeof FontReferenceInput>;
19
+ export declare function localFontReferences(references: readonly FontReference[]): Array<{
20
+ local: string;
21
+ fallback: string;
22
+ }>;
23
+ export declare const FONT_FORMATS: readonly ["woff2", "woff", "truetype", "opentype"];
24
+ export type FontFormat = (typeof FONT_FORMATS)[number];
25
+ export declare const LocalFaceTransport: z.ZodObject<{
26
+ family: z.ZodString;
27
+ format: z.ZodEnum<{
28
+ woff2: "woff2";
29
+ woff: "woff";
30
+ truetype: "truetype";
31
+ opentype: "opentype";
32
+ }>;
33
+ weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
34
+ style: z.ZodOptional<z.ZodEnum<{
35
+ normal: "normal";
36
+ italic: "italic";
37
+ }>>;
38
+ data: z.ZodString;
39
+ }, z.core.$strict>;
40
+ export type LocalFaceTransport = z.infer<typeof LocalFaceTransport>;
41
+ export declare const LocalFacesTransport: z.ZodArray<z.ZodObject<{
42
+ family: z.ZodString;
43
+ format: z.ZodEnum<{
44
+ woff2: "woff2";
45
+ woff: "woff";
46
+ truetype: "truetype";
47
+ opentype: "opentype";
48
+ }>;
49
+ weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
50
+ style: z.ZodOptional<z.ZodEnum<{
51
+ normal: "normal";
52
+ italic: "italic";
53
+ }>>;
54
+ data: z.ZodString;
55
+ }, z.core.$strict>>;
56
+ export type LocalFacesInput = LocalFaceTransport[];
57
+ export declare const FONT_GENERICS: readonly ["serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui"];
58
+ export type FontGeneric = (typeof FONT_GENERICS)[number];
59
+ export interface FontFace {
60
+ family: string;
61
+ data: Uint8Array;
62
+ format: FontFormat;
63
+ weight?: number | string;
64
+ style?: 'normal' | 'italic';
65
+ unicodeRange?: string;
66
+ }
67
+ export interface AppFont {
68
+ family: string;
69
+ faces: FontFace[];
70
+ generic?: FontGeneric;
71
+ }
72
+ export interface FontSource {
73
+ font(name: string, options: {
74
+ signal: AbortSignal;
75
+ }): Promise<AppFont | undefined>;
76
+ }
77
+ //#endregion
package/dist/fonts.js ADDED
@@ -0,0 +1,49 @@
1
+ import { z } from "zod";
2
+ //#region src/fonts.ts
3
+ const APP_FONT_NAME = /^[a-z0-9-]+$/;
4
+ const APP_FONT_NAME_MESSAGE = "app font names are lowercase letters, digits and hyphens";
5
+ const AppFontName = z.string().min(1).regex(APP_FONT_NAME, APP_FONT_NAME_MESSAGE);
6
+ const AppFontShape = { app: AppFontName };
7
+ const LocalFontShape = {
8
+ local: z.string().min(1),
9
+ fallback: AppFontName
10
+ };
11
+ const FontReference = z.union([z.object(AppFontShape), z.object(LocalFontShape)]);
12
+ const FontReferenceInput = z.union([z.strictObject(AppFontShape), z.strictObject(LocalFontShape)]);
13
+ function localFontReferences(references) {
14
+ const seen = /* @__PURE__ */ new Set();
15
+ const locals = [];
16
+ for (const reference of references) {
17
+ if (!("local" in reference)) continue;
18
+ const key = JSON.stringify(reference);
19
+ if (seen.has(key)) continue;
20
+ seen.add(key);
21
+ locals.push(reference);
22
+ }
23
+ return locals;
24
+ }
25
+ const FONT_FORMATS = [
26
+ "woff2",
27
+ "woff",
28
+ "truetype",
29
+ "opentype"
30
+ ];
31
+ const LocalFaceTransportShape = {
32
+ family: z.string().min(1),
33
+ format: z.enum(FONT_FORMATS),
34
+ weight: z.union([z.number(), z.string()]).optional(),
35
+ style: z.enum(["normal", "italic"]).optional(),
36
+ data: z.string()
37
+ };
38
+ const LocalFaceTransport = z.strictObject(LocalFaceTransportShape);
39
+ const LocalFacesTransport = z.array(LocalFaceTransport);
40
+ const FONT_GENERICS = [
41
+ "serif",
42
+ "sans-serif",
43
+ "monospace",
44
+ "cursive",
45
+ "fantasy",
46
+ "system-ui"
47
+ ];
48
+ //#endregion
49
+ export { APP_FONT_NAME, APP_FONT_NAME_MESSAGE, FONT_FORMATS, FONT_GENERICS, FontReference, FontReferenceInput, LocalFaceTransport, LocalFacesTransport, localFontReferences };
package/dist/index.d.ts CHANGED
@@ -6,16 +6,20 @@ import { BoardListingGroup, boardListing, boardListingIsEmpty, foldForSearch, na
6
6
  import { GridDropTarget, deriveSectionCells, gridDropMarkerBox, gridDropTarget, insertIntoGrid, layoutSection, removeFromGrid } from "./board-section-grid.js";
7
7
  import { MAKE_ROOM_LIMIT, SECTION_GAP, SECTION_MIN_SIZE, SECTION_PADDING, SECTION_TITLE_ROOM } from "./board-section-constants.js";
8
8
  import { assignMembership, fitSection, fitTouchedSections, makeRoom, settleBoard } from "./board-sections.js";
9
- import { Book, BookContents, BookFrontMatterEntry, BookInput, BookMode, BookPage, BookSection, BookView, BookViewInput, Chapter, isBookContents, isHebrew, noteMarkerIssues } from "./book.js";
9
+ import { Book, BookContents, BookFrontMatterEntry, BookInput, BookMode, BookPage, BookSection, BookView, BookViewInput, Chapter, isBookContents, noteMarkerIssues } from "./book.js";
10
10
  import { DeckFromSlidesOptions, SlideRow, deckFromSlides } from "./deck-from-slides.js";
11
11
  import { Direction, TextDirection, firstStrongDirection, languageDirection, resolveDirection } from "./direction.js";
12
12
  import { PAPER_FIT_TOLERANCE_MM } from "./imposition-fit.js";
13
13
  import { CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, MarkSegment, NAMED_PAPERS, NamedPaper, NamedPaperMetadata, ORIENTATIONS, Orientation, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PX_PER_MM, Paper, PaperBox, PaperGroup, PaperUnit, PrintSetting, PrintSettingInput, fromMillimeters, paperPixels, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters } from "./paper.js";
14
14
  import { FOLD_KINDS, FOLD_TUCK_IN_MM, FoldKind, foldCellPages, foldColumns, foldPageCountMessage, foldPanelMap } from "./fold.js";
15
+ import { APP_FONT_NAME, APP_FONT_NAME_MESSAGE, AppFont, FONT_FORMATS, FONT_GENERICS, FontFace, FontFormat, FontGeneric, FontReference, FontReferenceInput, FontSource, LocalFaceTransport, LocalFacesInput, LocalFacesTransport, localFontReferences } from "./fonts.js";
15
16
  import { Imposed, MillimeterEdges, PageFit, PagePlacementKind, PagePlacementLayout, Placement, fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
16
17
  import { ImpositionMarkEdge, ImpositionSideMarks, MIN_MARK_LENGTH_MM, OmittedImpositionMark, impositionMarks } from "./imposition-marks.js";
17
18
  import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
18
- import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.js";
19
+ import { BOOK_FURNITURE, BookFurniture, LIBRARY_MOTIF_PREFIX, MOTIF_ATTRIBUTE, Motif, MotifField, MotifFieldInput, MotifInput, MotifPlacement, MotifSource, MotifVersion, MotifVersionChoice, MotifVersionInput, PRINTED_PAGE_CONTEXT, PRINTED_PAGE_FOLIO_PATH, PRINTED_PAGE_NUMBER_PATH, PRINTED_PAGE_RUNNING_HEAD_PATH, PRINTED_PAGE_TOTAL_PATH, chooseMotifVersion, motifFieldAttribute } from "./motif.js";
20
+ import { NoteMarker, NumberSystem, defaultPageNumbering, formatNumber, isHebrew, noteMarker } from "./numbering.js";
21
+ import { isPrintedPageIdentityImposition } from "./printed-page-imposition.js";
22
+ import { BOOK_PARENT_NAMES, PRINTED_PAGE_LIMIT, PRINTED_PAGE_ROLES, ParentPage, ParentPageMargin, PrintedPageRole, PrintedPageRules, PrintedPages, ResolvedParentPage, bookParentPages, pagePrintedPagesIssues, printedPagesIssues, resolveParentPages } from "./printed-pages.js";
19
23
  import { Scripts } from "./scripts.js";
20
24
  import { ShotUse, shotsUsed } from "./shots-used.js";
21
25
  import { MAX_SLIDE_TIMING_MS } from "./timing.js";
@@ -358,6 +362,46 @@ export declare const Page: z.ZodObject<{
358
362
  registration: "registration";
359
363
  }>>;
360
364
  }, z.core.$strip>>;
365
+ printedPages: z.ZodOptional<z.ZodObject<{
366
+ parents: z.ZodArray<z.ZodObject<{
367
+ name: z.ZodString;
368
+ basedOn: z.ZodOptional<z.ZodString>;
369
+ margin: z.ZodOptional<z.ZodObject<{
370
+ top: z.ZodNumber;
371
+ bottom: z.ZodNumber;
372
+ inner: z.ZodNumber;
373
+ outer: z.ZodNumber;
374
+ }, z.core.$strip>>;
375
+ head: z.ZodOptional<z.ZodString>;
376
+ foot: z.ZodOptional<z.ZodString>;
377
+ }, z.core.$strip>>;
378
+ rules: z.ZodPipe<z.ZodObject<{
379
+ every: z.ZodString;
380
+ first: z.ZodOptional<z.ZodString>;
381
+ recto: z.ZodOptional<z.ZodString>;
382
+ verso: z.ZodOptional<z.ZodString>;
383
+ last: z.ZodOptional<z.ZodString>;
384
+ }, z.core.$loose>, z.ZodTransform<{
385
+ last?: string | undefined;
386
+ verso?: string | undefined;
387
+ recto?: string | undefined;
388
+ first?: string | undefined;
389
+ every: string;
390
+ }, {
391
+ [x: string]: unknown;
392
+ every: string;
393
+ first?: string | undefined;
394
+ recto?: string | undefined;
395
+ verso?: string | undefined;
396
+ last?: string | undefined;
397
+ }>>;
398
+ numbering: z.ZodOptional<z.ZodEnum<{
399
+ arabic: "arabic";
400
+ "roman-lower": "roman-lower";
401
+ "roman-upper": "roman-upper";
402
+ hebrew: "hebrew";
403
+ }>>;
404
+ }, z.core.$strip>>;
361
405
  slots: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodObject<{
362
406
  key: z.ZodString;
363
407
  label: z.ZodString;
@@ -395,6 +439,12 @@ export declare const Page: z.ZodObject<{
395
439
  placeholder?: string | undefined;
396
440
  minSize?: number | undefined;
397
441
  }>>>>;
442
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
443
+ app: z.ZodString;
444
+ }, z.core.$strip>, z.ZodObject<{
445
+ local: z.ZodString;
446
+ fallback: z.ZodString;
447
+ }, z.core.$strip>]>>>;
398
448
  }, z.core.$strip>;
399
449
  export type Page = z.infer<typeof Page>;
400
450
  export type PageInput = z.input<typeof Page>;
@@ -477,6 +527,12 @@ export declare function jsonSchemas(): {
477
527
  html: z.ZodString;
478
528
  runningHead: z.ZodOptional<z.ZodString>;
479
529
  }, z.core.$strip>>;
530
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
531
+ app: z.ZodString;
532
+ }, z.core.$strip>, z.ZodObject<{
533
+ local: z.ZodString;
534
+ fallback: z.ZodString;
535
+ }, z.core.$strip>]>>>;
480
536
  numbering: z.ZodDefault<z.ZodObject<{
481
537
  frontMatter: z.ZodOptional<z.ZodEnum<{
482
538
  arabic: "arabic";
@@ -533,6 +589,12 @@ export declare function jsonSchemas(): {
533
589
  sandboxed: "sandboxed";
534
590
  }>>;
535
591
  lang: z.ZodOptional<z.ZodString>;
592
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
593
+ app: z.ZodString;
594
+ }, z.core.$strip>, z.ZodObject<{
595
+ local: z.ZodString;
596
+ fallback: z.ZodString;
597
+ }, z.core.$strip>]>>>;
536
598
  title: z.ZodOptional<z.ZodString>;
537
599
  html: z.ZodString;
538
600
  }, z.core.$strip>>;
@@ -612,6 +674,46 @@ export declare function jsonSchemas(): {
612
674
  registration: "registration";
613
675
  }>>;
614
676
  }, z.core.$strip>>;
677
+ printedPages: z.ZodOptional<z.ZodObject<{
678
+ parents: z.ZodArray<z.ZodObject<{
679
+ name: z.ZodString;
680
+ basedOn: z.ZodOptional<z.ZodString>;
681
+ margin: z.ZodOptional<z.ZodObject<{
682
+ top: z.ZodNumber;
683
+ bottom: z.ZodNumber;
684
+ inner: z.ZodNumber;
685
+ outer: z.ZodNumber;
686
+ }, z.core.$strip>>;
687
+ head: z.ZodOptional<z.ZodString>;
688
+ foot: z.ZodOptional<z.ZodString>;
689
+ }, z.core.$strip>>;
690
+ rules: z.ZodPipe<z.ZodObject<{
691
+ every: z.ZodString;
692
+ first: z.ZodOptional<z.ZodString>;
693
+ recto: z.ZodOptional<z.ZodString>;
694
+ verso: z.ZodOptional<z.ZodString>;
695
+ last: z.ZodOptional<z.ZodString>;
696
+ }, z.core.$loose>, z.ZodTransform<{
697
+ last?: string | undefined;
698
+ verso?: string | undefined;
699
+ recto?: string | undefined;
700
+ first?: string | undefined;
701
+ every: string;
702
+ }, {
703
+ [x: string]: unknown;
704
+ every: string;
705
+ first?: string | undefined;
706
+ recto?: string | undefined;
707
+ verso?: string | undefined;
708
+ last?: string | undefined;
709
+ }>>;
710
+ numbering: z.ZodOptional<z.ZodEnum<{
711
+ arabic: "arabic";
712
+ "roman-lower": "roman-lower";
713
+ "roman-upper": "roman-upper";
714
+ hebrew: "hebrew";
715
+ }>>;
716
+ }, z.core.$strip>>;
615
717
  slots: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodObject<{
616
718
  key: z.ZodString;
617
719
  label: z.ZodString;
@@ -649,6 +751,12 @@ export declare function jsonSchemas(): {
649
751
  placeholder?: string | undefined;
650
752
  minSize?: number | undefined;
651
753
  }>>>>;
754
+ fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
755
+ app: z.ZodString;
756
+ }, z.core.$strip>, z.ZodObject<{
757
+ local: z.ZodString;
758
+ fallback: z.ZodString;
759
+ }, z.core.$strip>]>>>;
652
760
  }, z.core.$strip>>;
653
761
  lexicon: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
654
762
  entries: z.ZodArray<z.ZodObject<{
@@ -1336,6 +1444,102 @@ export declare function jsonSchemas(): {
1336
1444
  placeholder?: string | undefined;
1337
1445
  minSize?: number | undefined;
1338
1446
  }>>>;
1447
+ fontReference: z.core.ZodStandardJSONSchemaPayload<z.ZodUnion<readonly [z.ZodObject<{
1448
+ app: z.ZodString;
1449
+ }, z.core.$strip>, z.ZodObject<{
1450
+ local: z.ZodString;
1451
+ fallback: z.ZodString;
1452
+ }, z.core.$strip>]>>;
1453
+ fontReferenceInput: z.core.ZodStandardJSONSchemaPayload<z.ZodUnion<readonly [z.ZodObject<{
1454
+ app: z.ZodString;
1455
+ }, z.core.$strict>, z.ZodObject<{
1456
+ local: z.ZodString;
1457
+ fallback: z.ZodString;
1458
+ }, z.core.$strict>]>>;
1459
+ localFaceTransport: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
1460
+ family: z.ZodString;
1461
+ format: z.ZodEnum<{
1462
+ woff2: "woff2";
1463
+ woff: "woff";
1464
+ truetype: "truetype";
1465
+ opentype: "opentype";
1466
+ }>;
1467
+ weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1468
+ style: z.ZodOptional<z.ZodEnum<{
1469
+ normal: "normal";
1470
+ italic: "italic";
1471
+ }>>;
1472
+ data: z.ZodString;
1473
+ }, z.core.$strict>>;
1474
+ localFacesTransport: z.core.ZodStandardJSONSchemaPayload<z.ZodArray<z.ZodObject<{
1475
+ family: z.ZodString;
1476
+ format: z.ZodEnum<{
1477
+ woff2: "woff2";
1478
+ woff: "woff";
1479
+ truetype: "truetype";
1480
+ opentype: "opentype";
1481
+ }>;
1482
+ weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
1483
+ style: z.ZodOptional<z.ZodEnum<{
1484
+ normal: "normal";
1485
+ italic: "italic";
1486
+ }>>;
1487
+ data: z.ZodString;
1488
+ }, z.core.$strict>>>;
1489
+ motif: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
1490
+ key: z.ZodString;
1491
+ revision: z.ZodString;
1492
+ label: z.ZodString;
1493
+ fields: z.ZodArray<z.ZodObject<{
1494
+ key: z.ZodString;
1495
+ label: z.ZodString;
1496
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
1497
+ default: z.ZodOptional<z.ZodString>;
1498
+ required: z.ZodDefault<z.ZodBoolean>;
1499
+ }, z.core.$strip>>;
1500
+ versions: z.ZodArray<z.ZodObject<{
1501
+ lang: z.ZodString;
1502
+ dir: z.ZodOptional<z.ZodEnum<{
1503
+ ltr: "ltr";
1504
+ rtl: "rtl";
1505
+ }>>;
1506
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1507
+ html: z.ZodString;
1508
+ }, z.core.$strip>>;
1509
+ fonts: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
1510
+ app: z.ZodString;
1511
+ }, z.core.$strip>, z.ZodObject<{
1512
+ local: z.ZodString;
1513
+ fallback: z.ZodString;
1514
+ }, z.core.$strip>]>>>;
1515
+ }, z.core.$strip>>;
1516
+ motifInput: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
1517
+ fields: z.ZodArray<z.ZodObject<{
1518
+ key: z.ZodString;
1519
+ label: z.ZodString;
1520
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
1521
+ default: z.ZodOptional<z.ZodString>;
1522
+ required: z.ZodDefault<z.ZodBoolean>;
1523
+ }, z.core.$strict>>;
1524
+ versions: z.ZodArray<z.ZodObject<{
1525
+ lang: z.ZodString;
1526
+ dir: z.ZodOptional<z.ZodEnum<{
1527
+ ltr: "ltr";
1528
+ rtl: "rtl";
1529
+ }>>;
1530
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1531
+ html: z.ZodString;
1532
+ }, z.core.$strict>>;
1533
+ fonts: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
1534
+ app: z.ZodString;
1535
+ }, z.core.$strict>, z.ZodObject<{
1536
+ local: z.ZodString;
1537
+ fallback: z.ZodString;
1538
+ }, z.core.$strict>]>>>;
1539
+ key: z.ZodString;
1540
+ revision: z.ZodString;
1541
+ label: z.ZodString;
1542
+ }, z.core.$strict>>;
1339
1543
  };
1340
1544
  //#endregion
1341
- export { Annotation, type ArrangeOptions, Board, type BoardInput, BoardItem, type BoardItemAnchor, BoardLabel, type BoardListingGroup, BoardSection, type BoardShapes, type BoardView, Book, BookContents, BookFrontMatterEntry, type BookInput, BookMode, BookPage, BookSection, BookView, type BookViewInput, Box, CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, type DeckFromSlidesOptions, type DeckInput, type DeckLimits, Direction, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, FOLD_KINDS, FOLD_TUCK_IN_MM, Fill, FillValues, type FoldKind, GridCell, type GridDropTarget, ImageFit, type Imposed, type ImpositionMarkEdge, type ImpositionSideMarks, Lexicon, MAKE_ROOM_LIMIT, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ITEM_WIDTH, MIN_BOARD_ZOOM, MIN_MARK_LENGTH_MM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, type MarkSegment, type MillimeterEdges, NAMED_PAPERS, type NamedPaper, type NamedPaperMetadata, Narration, NoteMarker, NumberSystem, ORIENTATIONS, type OmittedImpositionMark, Orientation, PAPER_FIT_TOLERANCE_MM, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PLAYBACK_MODES, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, Paper, type PaperBox, type PaperGroup, PaperUnit, type Placement, Playback, type PlaybackMode, Point, PrintSetting, PrintSettingInput, PronunciationEntry, PublishedShot, SECTION_GAP, SECTION_MIN_SIZE, SECTION_PADDING, SECTION_TITLE_ROOM, SHOT_KEY, SLOT_TYPES, Scripts, Shot, type ShotUse, Size, Slide, SlideContent, type SlideRow, SlotDeclaration, SlotDeclarationInput, SlotKey, SlotReport, SlotSource, SlotState, SlotType, SlotValue, Slots, SlotsInput, SlotsOptions, TextDirection, Transition, TransitionInput, Word, type ZoomBounds, addItem, annotationCueIssues, arrange, assignMembership, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, deckFromSlides, deriveSectionCells, exceedsLimits, firstStrongDirection, fitPage, fitSection, fitTouchedSections, foldCellPages, foldColumns, foldForSearch, foldPageCountMessage, foldPanelMap, formatNumber, fromMillimeters, gridDropMarkerBox, gridDropTarget, impose, impositionMarks, insertIntoGrid, isBookContents, isHebrew, itemAt, itemHeight, languageDirection, layoutSection, lexiconVersion, makeRoom, mergeSlotDeclarations, mirrorPlacement, moveItems, moveSection, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, paperPixels, parsePlayback, printBoxes, printPadding, printProperties, removeFromGrid, removeItems, resizeItem, resolveDirection, revealView, roundMillimeters, screenToBoard, settleBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
1545
+ export { APP_FONT_NAME, APP_FONT_NAME_MESSAGE, Annotation, type AppFont, type ArrangeOptions, BOOK_FURNITURE, BOOK_PARENT_NAMES, Board, type BoardInput, BoardItem, type BoardItemAnchor, BoardLabel, type BoardListingGroup, BoardSection, type BoardShapes, type BoardView, Book, BookContents, BookFrontMatterEntry, BookFurniture, type BookInput, BookMode, BookPage, BookSection, BookView, type BookViewInput, Box, CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, type DeckFromSlidesOptions, type DeckInput, type DeckLimits, Direction, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, FOLD_KINDS, FOLD_TUCK_IN_MM, FONT_FORMATS, FONT_GENERICS, Fill, FillValues, type FoldKind, type FontFace, type FontFormat, type FontGeneric, FontReference, FontReferenceInput, type FontSource, GridCell, type GridDropTarget, ImageFit, type Imposed, type ImpositionMarkEdge, type ImpositionSideMarks, LIBRARY_MOTIF_PREFIX, Lexicon, LocalFaceTransport, type LocalFacesInput, LocalFacesTransport, MAKE_ROOM_LIMIT, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ITEM_WIDTH, MIN_BOARD_ZOOM, MIN_MARK_LENGTH_MM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, MOTIF_ATTRIBUTE, Manifest, type MarkSegment, type MillimeterEdges, Motif, MotifField, MotifFieldInput, MotifInput, MotifPlacement, MotifSource, MotifVersion, MotifVersionChoice, MotifVersionInput, NAMED_PAPERS, type NamedPaper, type NamedPaperMetadata, Narration, NoteMarker, NumberSystem, ORIENTATIONS, type OmittedImpositionMark, Orientation, PAPER_FIT_TOLERANCE_MM, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PLAYBACK_MODES, PRINTED_PAGE_CONTEXT, PRINTED_PAGE_FOLIO_PATH, PRINTED_PAGE_LIMIT, PRINTED_PAGE_NUMBER_PATH, PRINTED_PAGE_ROLES, PRINTED_PAGE_RUNNING_HEAD_PATH, PRINTED_PAGE_TOTAL_PATH, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, Paper, type PaperBox, type PaperGroup, PaperUnit, ParentPage, ParentPageMargin, type Placement, Playback, type PlaybackMode, Point, PrintSetting, PrintSettingInput, PrintedPageRole, PrintedPageRules, PrintedPages, PronunciationEntry, PublishedShot, ResolvedParentPage, SECTION_GAP, SECTION_MIN_SIZE, SECTION_PADDING, SECTION_TITLE_ROOM, SHOT_KEY, SLOT_TYPES, Scripts, Shot, type ShotUse, Size, Slide, SlideContent, type SlideRow, SlotDeclaration, SlotDeclarationInput, SlotKey, SlotReport, SlotSource, SlotState, SlotType, SlotValue, Slots, SlotsInput, SlotsOptions, TextDirection, Transition, TransitionInput, Word, type ZoomBounds, addItem, annotationCueIssues, arrange, assignMembership, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, bookParentPages, chooseMotifVersion, deckFromSlides, defaultPageNumbering, deriveSectionCells, exceedsLimits, firstStrongDirection, fitPage, fitSection, fitTouchedSections, foldCellPages, foldColumns, foldForSearch, foldPageCountMessage, foldPanelMap, formatNumber, fromMillimeters, gridDropMarkerBox, gridDropTarget, impose, impositionMarks, insertIntoGrid, isBookContents, isHebrew, isPrintedPageIdentityImposition, itemAt, itemHeight, languageDirection, layoutSection, lexiconVersion, localFontReferences, makeRoom, mergeSlotDeclarations, mirrorPlacement, motifFieldAttribute, moveItems, moveSection, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, pagePrintedPagesIssues, paperPixels, parsePlayback, printBoxes, printPadding, printProperties, printedPagesIssues, removeFromGrid, removeItems, resizeItem, resolveDirection, resolveParentPages, revealView, roundMillimeters, screenToBoard, settleBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
package/dist/index.js CHANGED
@@ -5,12 +5,15 @@ import { MAX_SLIDE_TIMING_MS } from "./timing.js";
5
5
  import { DEFAULT_TRANSITION_DURATION_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, Transition } from "./transition.js";
6
6
  import { Annotation, Box, Cue, DECK_SIZE, Deck, DeckShape, ImageFit, Manifest, Narration, PLAYBACK_MODES, Playback, Point, PublishedShot, SHOT_KEY, Shot, Size, Slide, SlideContent, Word, annotationCueIssues, exceedsLimits, parsePlayback } from "./deck.js";
7
7
  import { Board, BoardItem, BoardLabel, BoardSection, GridCell } from "./board.js";
8
- import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.js";
8
+ import { APP_FONT_NAME, APP_FONT_NAME_MESSAGE, FONT_FORMATS, FONT_GENERICS, FontReference, FontReferenceInput, LocalFaceTransport, LocalFacesTransport, localFontReferences } from "./fonts.js";
9
+ import { NoteMarker, NumberSystem, defaultPageNumbering, formatNumber, isHebrew, noteMarker } from "./numbering.js";
9
10
  import { CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, NAMED_PAPERS, ORIENTATIONS, Orientation, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PX_PER_MM, Paper, PaperUnit, PrintSetting, PrintSettingInput, fromMillimeters, paperPixels, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters } from "./paper.js";
10
- import { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, BookView, Chapter, isBookContents, isHebrew, noteMarkerIssues } from "./book.js";
11
+ import { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, BookView, Chapter, isBookContents, noteMarkerIssues } from "./book.js";
11
12
  import { PAPER_FIT_TOLERANCE_MM, refuseOverflow, refuseSafe } from "./imposition-fit.js";
12
13
  import { FOLD_KINDS, FOLD_TUCK_IN_MM, foldCellPages, foldColumns, foldPageCountMessage, foldPanelMap, refineFold, resolveImposition } from "./fold.js";
13
14
  import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
15
+ import { BOOK_FURNITURE, LIBRARY_MOTIF_PREFIX, MOTIF_ATTRIBUTE, Motif, MotifField, MotifFieldInput, MotifInput, MotifVersion, MotifVersionInput, PRINTED_PAGE_CONTEXT, PRINTED_PAGE_FOLIO_PATH, PRINTED_PAGE_NUMBER_PATH, PRINTED_PAGE_RUNNING_HEAD_PATH, PRINTED_PAGE_TOTAL_PATH, chooseMotifVersion, motifFieldAttribute } from "./motif.js";
16
+ import { BOOK_PARENT_NAMES, PRINTED_PAGE_LIMIT, PRINTED_PAGE_ROLES, ParentPage, ParentPageMargin, PrintedPageRules, PrintedPages, bookParentPages, pagePrintedPagesIssues, printedPagesIssues, resolveParentPages } from "./printed-pages.js";
14
17
  import { MIN_BOARD_ITEM_WIDTH, addItem, moveItems, moveSection, removeItems, resizeItem } from "./board-edit.js";
15
18
  import { MAX_BOARD_ZOOM, MIN_BOARD_ZOOM, arrange, boardBounds, boardToScreen, itemAt, itemHeight, revealView, screenToBoard, visibleItems, zoomAt, zoomToFit } from "./board-geometry.js";
16
19
  import { boardListing, boardListingIsEmpty, foldForSearch, nameMatches } from "./board-listing.js";
@@ -20,6 +23,7 @@ import { assignMembership, fitSection, fitTouchedSections, makeRoom, settleBoard
20
23
  import { deckFromSlides } from "./deck-from-slides.js";
21
24
  import { fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
22
25
  import { MIN_MARK_LENGTH_MM, impositionMarks } from "./imposition-marks.js";
26
+ import { isPrintedPageIdentityImposition } from "./printed-page-imposition.js";
23
27
  import { shotsUsed } from "./shots-used.js";
24
28
  import { z } from "zod";
25
29
  //#region src/index.ts
@@ -186,7 +190,14 @@ const Page = z.object({
186
190
  dir: Direction.optional(),
187
191
  lang: z.string().optional(),
188
192
  print: Print.optional(),
189
- slots: Slots.optional()
193
+ printedPages: PrintedPages.optional(),
194
+ slots: Slots.optional(),
195
+ fonts: z.array(FontReference).optional()
196
+ }).superRefine((page, ctx) => {
197
+ for (const issue of pagePrintedPagesIssues(page)) ctx.addIssue({
198
+ code: "custom",
199
+ ...issue
200
+ });
190
201
  });
191
202
  function jsonSchemas() {
192
203
  return {
@@ -202,8 +213,14 @@ function jsonSchemas() {
202
213
  printSetting: z.toJSONSchema(PrintSetting, { io: "input" }),
203
214
  printSettingInput: z.toJSONSchema(PrintSettingInput, { io: "input" }),
204
215
  slotDeclaration: z.toJSONSchema(SlotDeclaration, { io: "input" }),
205
- slotDeclarationInput: z.toJSONSchema(SlotDeclarationInput, { io: "input" })
216
+ slotDeclarationInput: z.toJSONSchema(SlotDeclarationInput, { io: "input" }),
217
+ fontReference: z.toJSONSchema(FontReference, { io: "input" }),
218
+ fontReferenceInput: z.toJSONSchema(FontReferenceInput, { io: "input" }),
219
+ localFaceTransport: z.toJSONSchema(LocalFaceTransport, { io: "input" }),
220
+ localFacesTransport: z.toJSONSchema(LocalFacesTransport, { io: "input" }),
221
+ motif: z.toJSONSchema(Motif, { io: "input" }),
222
+ motifInput: z.toJSONSchema(MotifInput, { io: "input" })
206
223
  };
207
224
  }
208
225
  //#endregion
209
- export { Annotation, Board, BoardItem, BoardLabel, BoardSection, Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookView, Box, CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, FOLD_KINDS, FOLD_TUCK_IN_MM, FillValues, GridCell, ImageFit, Imposition, Lexicon, MAKE_ROOM_LIMIT, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ITEM_WIDTH, MIN_BOARD_ZOOM, MIN_MARK_LENGTH_MM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, Manifest, Margin, MarkColor, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, ORIENTATIONS, Orientation, PAPER_FIT_TOLERANCE_MM, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PLAYBACK_MODES, PX_PER_MM, Page, PageSize, Paper, PaperUnit, Playback, Point, Print, PrintSetting, PrintSettingInput, PronunciationEntry, PublishedShot, SECTION_GAP, SECTION_MIN_SIZE, SECTION_PADDING, SECTION_TITLE_ROOM, SHOT_KEY, SLOT_TYPES, Scripts, Shot, Size, Slide, SlideContent, SlotDeclaration, SlotDeclarationInput, SlotKey, SlotType, SlotValue, Slots, SlotsInput, TextDirection, Transition, Word, addItem, annotationCueIssues, arrange, assignMembership, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, deckFromSlides, deriveSectionCells, exceedsLimits, firstStrongDirection, fitPage, fitSection, fitTouchedSections, foldCellPages, foldColumns, foldForSearch, foldPageCountMessage, foldPanelMap, formatNumber, fromMillimeters, gridDropMarkerBox, gridDropTarget, impose, impositionMarks, insertIntoGrid, isBookContents, isHebrew, itemAt, itemHeight, jsonSchemas, languageDirection, layoutSection, lexiconVersion, makeRoom, mergeSlotDeclarations, mirrorPlacement, moveItems, moveSection, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, paperPixels, parsePlayback, printBoxes, printPadding, printProperties, removeFromGrid, removeItems, resizeItem, resolveDirection, revealView, roundMillimeters, screenToBoard, settleBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
226
+ export { APP_FONT_NAME, APP_FONT_NAME_MESSAGE, Annotation, BOOK_FURNITURE, BOOK_PARENT_NAMES, Board, BoardItem, BoardLabel, BoardSection, Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookView, Box, CUSTOM_PAPER_MAX_MM, CUSTOM_PAPER_MIN_MM, Chapter, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, FOLD_DASH_OFF_MM, FOLD_DASH_ON_MM, FOLD_KINDS, FOLD_TUCK_IN_MM, FONT_FORMATS, FONT_GENERICS, FillValues, FontReference, FontReferenceInput, GridCell, ImageFit, Imposition, LIBRARY_MOTIF_PREFIX, Lexicon, LocalFaceTransport, LocalFacesTransport, MAKE_ROOM_LIMIT, MARK_GAP_MM, MARK_LENGTH_MM, MAX_BOARD_ZOOM, MAX_IMPOSITION_CELLS, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_BOARD_ITEM_WIDTH, MIN_BOARD_ZOOM, MIN_MARK_LENGTH_MM, MIN_TRANSITION_DURATION_MS, MM_PER_PT, MOTIF_ATTRIBUTE, Manifest, Margin, MarkColor, Motif, MotifField, MotifFieldInput, MotifInput, MotifVersion, MotifVersionInput, NAMED_PAPERS, Narration, NoteMarker, NumberSystem, ORIENTATIONS, Orientation, PAPER_FIT_TOLERANCE_MM, PAPER_GROUPS, PAPER_METADATA, PAPER_MM, PAPER_UNITS, PLAYBACK_MODES, PRINTED_PAGE_CONTEXT, PRINTED_PAGE_FOLIO_PATH, PRINTED_PAGE_LIMIT, PRINTED_PAGE_NUMBER_PATH, PRINTED_PAGE_ROLES, PRINTED_PAGE_RUNNING_HEAD_PATH, PRINTED_PAGE_TOTAL_PATH, PX_PER_MM, Page, PageSize, Paper, PaperUnit, ParentPage, ParentPageMargin, Playback, Point, Print, PrintSetting, PrintSettingInput, PrintedPageRules, PrintedPages, PronunciationEntry, PublishedShot, SECTION_GAP, SECTION_MIN_SIZE, SECTION_PADDING, SECTION_TITLE_ROOM, SHOT_KEY, SLOT_TYPES, Scripts, Shot, Size, Slide, SlideContent, SlotDeclaration, SlotDeclarationInput, SlotKey, SlotType, SlotValue, Slots, SlotsInput, TextDirection, Transition, Word, addItem, annotationCueIssues, arrange, assignMembership, boardBounds, boardListing, boardListingIsEmpty, boardToScreen, bookParentPages, chooseMotifVersion, deckFromSlides, defaultPageNumbering, deriveSectionCells, exceedsLimits, firstStrongDirection, fitPage, fitSection, fitTouchedSections, foldCellPages, foldColumns, foldForSearch, foldPageCountMessage, foldPanelMap, formatNumber, fromMillimeters, gridDropMarkerBox, gridDropTarget, impose, impositionMarks, insertIntoGrid, isBookContents, isHebrew, isPrintedPageIdentityImposition, itemAt, itemHeight, jsonSchemas, languageDirection, layoutSection, lexiconVersion, localFontReferences, makeRoom, mergeSlotDeclarations, mirrorPlacement, motifFieldAttribute, moveItems, moveSection, nameMatches, noteMarker, noteMarkerIssues, pagePlacementLayout, pagePrintedPagesIssues, paperPixels, parsePlayback, printBoxes, printPadding, printProperties, printedPagesIssues, removeFromGrid, removeItems, resizeItem, resolveDirection, resolveParentPages, revealView, roundMillimeters, screenToBoard, settleBoard, sheetMm, shotsUsed, toMillimeters, visibleItems, zoomAt, zoomToFit };
@@ -0,0 +1,143 @@
1
+ import { z } from "zod";
2
+ //#region src/motif.d.ts
3
+ export declare const MOTIF_ATTRIBUTE = "data-motif";
4
+ export declare const PRINTED_PAGE_CONTEXT = "printedPage";
5
+ export declare const PRINTED_PAGE_NUMBER_PATH = "printedPage.number";
6
+ export declare const PRINTED_PAGE_TOTAL_PATH = "printedPage.total";
7
+ export declare const PRINTED_PAGE_FOLIO_PATH = "printedPage.folio";
8
+ export declare const PRINTED_PAGE_RUNNING_HEAD_PATH = "printedPage.runningHead";
9
+ export declare const LIBRARY_MOTIF_PREFIX = "segnavia:";
10
+ export declare const BOOK_FURNITURE: readonly [{
11
+ readonly key: "segnavia:folio";
12
+ readonly path: "printedPage.folio";
13
+ readonly value: "folio";
14
+ readonly className: "segnavia-folio";
15
+ readonly region: "foot";
16
+ }, {
17
+ readonly key: "segnavia:running-head";
18
+ readonly path: "printedPage.runningHead";
19
+ readonly value: "runningHead";
20
+ readonly className: "segnavia-running-head";
21
+ readonly region: "head";
22
+ }];
23
+ export type BookFurniture = (typeof BOOK_FURNITURE)[number];
24
+ export declare const motifFieldAttribute: (key: string) => string;
25
+ export declare const MotifField: z.ZodObject<{
26
+ key: z.ZodString;
27
+ label: z.ZodString;
28
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ default: z.ZodOptional<z.ZodString>;
30
+ required: z.ZodDefault<z.ZodBoolean>;
31
+ }, z.core.$strip>;
32
+ export type MotifField = z.infer<typeof MotifField>;
33
+ export declare const MotifFieldInput: z.ZodObject<{
34
+ key: z.ZodString;
35
+ label: z.ZodString;
36
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
37
+ default: z.ZodOptional<z.ZodString>;
38
+ required: z.ZodDefault<z.ZodBoolean>;
39
+ }, z.core.$strict>;
40
+ export type MotifFieldInput = z.input<typeof MotifFieldInput>;
41
+ export declare const MotifVersion: z.ZodObject<{
42
+ lang: z.ZodString;
43
+ dir: z.ZodOptional<z.ZodEnum<{
44
+ ltr: "ltr";
45
+ rtl: "rtl";
46
+ }>>;
47
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
48
+ html: z.ZodString;
49
+ }, z.core.$strip>;
50
+ export type MotifVersion = z.infer<typeof MotifVersion>;
51
+ export declare const MotifVersionInput: z.ZodObject<{
52
+ lang: z.ZodString;
53
+ dir: z.ZodOptional<z.ZodEnum<{
54
+ ltr: "ltr";
55
+ rtl: "rtl";
56
+ }>>;
57
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
58
+ html: z.ZodString;
59
+ }, z.core.$strict>;
60
+ export type MotifVersionInput = z.input<typeof MotifVersionInput>;
61
+ export declare const Motif: z.ZodObject<{
62
+ key: z.ZodString;
63
+ revision: z.ZodString;
64
+ label: z.ZodString;
65
+ fields: z.ZodArray<z.ZodObject<{
66
+ key: z.ZodString;
67
+ label: z.ZodString;
68
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ default: z.ZodOptional<z.ZodString>;
70
+ required: z.ZodDefault<z.ZodBoolean>;
71
+ }, z.core.$strip>>;
72
+ versions: z.ZodArray<z.ZodObject<{
73
+ lang: z.ZodString;
74
+ dir: z.ZodOptional<z.ZodEnum<{
75
+ ltr: "ltr";
76
+ rtl: "rtl";
77
+ }>>;
78
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
79
+ html: z.ZodString;
80
+ }, z.core.$strip>>;
81
+ fonts: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
82
+ app: z.ZodString;
83
+ }, z.core.$strip>, z.ZodObject<{
84
+ local: z.ZodString;
85
+ fallback: z.ZodString;
86
+ }, z.core.$strip>]>>>;
87
+ }, z.core.$strip>;
88
+ export type Motif = z.infer<typeof Motif>;
89
+ export declare const MotifInput: z.ZodObject<{
90
+ fields: z.ZodArray<z.ZodObject<{
91
+ key: z.ZodString;
92
+ label: z.ZodString;
93
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
+ default: z.ZodOptional<z.ZodString>;
95
+ required: z.ZodDefault<z.ZodBoolean>;
96
+ }, z.core.$strict>>;
97
+ versions: z.ZodArray<z.ZodObject<{
98
+ lang: z.ZodString;
99
+ dir: z.ZodOptional<z.ZodEnum<{
100
+ ltr: "ltr";
101
+ rtl: "rtl";
102
+ }>>;
103
+ when: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
104
+ html: z.ZodString;
105
+ }, z.core.$strict>>;
106
+ fonts: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
107
+ app: z.ZodString;
108
+ }, z.core.$strict>, z.ZodObject<{
109
+ local: z.ZodString;
110
+ fallback: z.ZodString;
111
+ }, z.core.$strict>]>>>;
112
+ key: z.ZodString;
113
+ revision: z.ZodString;
114
+ label: z.ZodString;
115
+ }, z.core.$strict>;
116
+ export type MotifInput = z.input<typeof MotifInput>;
117
+ export interface MotifPlacement {
118
+ key: string;
119
+ revision: string;
120
+ lang: string;
121
+ fields: Record<string, string>;
122
+ }
123
+ export interface MotifSource {
124
+ motif(key: string, options: {
125
+ revision?: string;
126
+ signal: AbortSignal;
127
+ }): Promise<Motif | undefined>;
128
+ data?(placement: MotifPlacement, options: {
129
+ signal: AbortSignal;
130
+ }): Promise<Record<string, unknown>>;
131
+ }
132
+ export type MotifVersionChoice = {
133
+ ok: true;
134
+ version: MotifVersion;
135
+ index: number;
136
+ } | {
137
+ ok: false;
138
+ reason: string;
139
+ };
140
+ export declare function chooseMotifVersion(motif: Motif, values: {
141
+ lang?: string;
142
+ } & Record<string, string | undefined>): MotifVersionChoice;
143
+ //#endregion
package/dist/motif.js ADDED
@@ -0,0 +1,175 @@
1
+ import { SlotKey } from "./slots.js";
2
+ import { FontReference, FontReferenceInput } from "./fonts.js";
3
+ import { z } from "zod";
4
+ //#region src/motif.ts
5
+ const MOTIF_ATTRIBUTE = "data-motif";
6
+ const PRINTED_PAGE_CONTEXT = "printedPage";
7
+ const PRINTED_PAGE_NUMBER_PATH = `${PRINTED_PAGE_CONTEXT}.number`;
8
+ const PRINTED_PAGE_TOTAL_PATH = `${PRINTED_PAGE_CONTEXT}.total`;
9
+ const PRINTED_PAGE_FOLIO_PATH = `${PRINTED_PAGE_CONTEXT}.folio`;
10
+ const PRINTED_PAGE_RUNNING_HEAD_PATH = `${PRINTED_PAGE_CONTEXT}.runningHead`;
11
+ const LIBRARY_MOTIF_PREFIX = "segnavia:";
12
+ const BOOK_FURNITURE = [{
13
+ key: "segnavia:folio",
14
+ path: PRINTED_PAGE_FOLIO_PATH,
15
+ value: "folio",
16
+ className: "segnavia-folio",
17
+ region: "foot"
18
+ }, {
19
+ key: "segnavia:running-head",
20
+ path: PRINTED_PAGE_RUNNING_HEAD_PATH,
21
+ value: "runningHead",
22
+ className: "segnavia-running-head",
23
+ region: "head"
24
+ }];
25
+ const motifFieldAttribute = (key) => `${MOTIF_ATTRIBUTE}-${key}`;
26
+ const uniqueChoices = (field, ctx) => {
27
+ if (field.choices && new Set(field.choices).size !== field.choices.length) ctx.addIssue({
28
+ code: "custom",
29
+ path: ["choices"],
30
+ message: "choices must be unique"
31
+ });
32
+ if (field.choices && field.default !== void 0 && !field.choices.includes(field.default)) ctx.addIssue({
33
+ code: "custom",
34
+ path: ["default"],
35
+ message: "default must be one of the field choices"
36
+ });
37
+ };
38
+ const MotifFieldShape = {
39
+ key: SlotKey,
40
+ label: z.string().min(1),
41
+ choices: z.array(z.string()).min(1).optional(),
42
+ default: z.string().optional(),
43
+ required: z.boolean().default(false)
44
+ };
45
+ const MotifField = z.object(MotifFieldShape).superRefine(uniqueChoices);
46
+ const MotifFieldInput = z.strictObject(MotifFieldShape).superRefine(uniqueChoices);
47
+ const MotifVersionShape = {
48
+ lang: z.string().min(1),
49
+ dir: z.enum(["ltr", "rtl"]).optional(),
50
+ when: z.record(SlotKey, z.string()).optional(),
51
+ html: z.string()
52
+ };
53
+ const MotifVersion = z.object(MotifVersionShape);
54
+ const MotifVersionInput = z.strictObject(MotifVersionShape);
55
+ const validateMotif = (motif, ctx) => {
56
+ const fields = new Map(motif.fields.map((field) => [field.key, field]));
57
+ const fieldCases = /* @__PURE__ */ new Map();
58
+ motif.fields.forEach((field, index) => {
59
+ const normalized = field.key.toLowerCase();
60
+ if (field.key.toLowerCase() === "lang") ctx.addIssue({
61
+ code: "custom",
62
+ path: [
63
+ "fields",
64
+ index,
65
+ "key"
66
+ ],
67
+ message: "lang is always present and must not be declared"
68
+ });
69
+ const previous = fieldCases.get(normalized);
70
+ if (previous !== void 0) ctx.addIssue({
71
+ code: "custom",
72
+ path: [
73
+ "fields",
74
+ index,
75
+ "key"
76
+ ],
77
+ message: `field key differs only by case from field ${previous + 1}`
78
+ });
79
+ else fieldCases.set(normalized, index);
80
+ });
81
+ const seen = /* @__PURE__ */ new Map();
82
+ motif.versions.forEach((version, index) => {
83
+ for (const [key, value] of Object.entries(version.when ?? {})) {
84
+ const field = fields.get(key);
85
+ if (!field?.choices) ctx.addIssue({
86
+ code: "custom",
87
+ path: [
88
+ "versions",
89
+ index,
90
+ "when",
91
+ key
92
+ ],
93
+ message: `when key "${key}" must name a choice field`
94
+ });
95
+ else if (!field.choices.includes(value)) ctx.addIssue({
96
+ code: "custom",
97
+ path: [
98
+ "versions",
99
+ index,
100
+ "when",
101
+ key
102
+ ],
103
+ message: `when value "${value}" must be one of the choices for "${key}"`
104
+ });
105
+ }
106
+ const conditions = Object.entries(version.when ?? {}).sort(([left], [right]) => left.localeCompare(right));
107
+ const signature = JSON.stringify([version.lang.toLowerCase(), conditions]);
108
+ const previous = seen.get(signature);
109
+ if (previous !== void 0) ctx.addIssue({
110
+ code: "custom",
111
+ path: ["versions", index],
112
+ message: `version duplicates version ${previous + 1} for the same lang and when values`
113
+ });
114
+ else seen.set(signature, index);
115
+ });
116
+ };
117
+ const MotifShape = {
118
+ key: SlotKey,
119
+ revision: z.string().min(1),
120
+ label: z.string().min(1),
121
+ fields: z.array(MotifField),
122
+ versions: z.array(MotifVersion).min(1),
123
+ fonts: z.array(FontReference).default([])
124
+ };
125
+ const MotifInputShape = {
126
+ ...MotifShape,
127
+ fields: z.array(MotifFieldInput),
128
+ versions: z.array(MotifVersionInput).min(1),
129
+ fonts: z.array(FontReferenceInput).default([])
130
+ };
131
+ const Motif = z.object(MotifShape).superRefine(validateMotif);
132
+ const MotifInput = z.strictObject(MotifInputShape).superRefine(validateMotif);
133
+ function chooseMotifVersion(motif, values) {
134
+ const suppliedLang = values.lang;
135
+ const langs = new Map(motif.versions.map((version) => [version.lang.toLowerCase(), version.lang]));
136
+ const lang = suppliedLang ?? (langs.size === 1 ? langs.values().next().value : void 0);
137
+ if (!lang) return {
138
+ ok: false,
139
+ reason: "no language was supplied and the motif has more than one language"
140
+ };
141
+ const resolved = Object.fromEntries(motif.fields.map((field) => [field.key, values[field.key] ?? field.default]));
142
+ const normalized = lang.toLowerCase();
143
+ const primary = normalized.split("-")[0];
144
+ const matches = motif.versions.map((version, index) => ({
145
+ version,
146
+ index
147
+ })).filter(({ version }) => {
148
+ const versionLang = version.lang.toLowerCase();
149
+ const versionPrimary = versionLang.split("-")[0];
150
+ if (versionLang !== normalized && versionPrimary !== primary) return false;
151
+ return Object.entries(version.when ?? {}).every(([key, value]) => resolved[key] === value);
152
+ }).map((match) => ({
153
+ ...match,
154
+ exact: match.version.lang.toLowerCase() === normalized,
155
+ specificity: Object.keys(match.version.when ?? {}).length
156
+ }));
157
+ if (matches.length === 0) return {
158
+ ok: false,
159
+ reason: `no version matches language "${lang}" and the supplied field values`
160
+ };
161
+ matches.sort((left, right) => Number(right.exact) - Number(left.exact) || right.specificity - left.specificity);
162
+ const best = matches[0];
163
+ const tied = matches.filter((match) => match.exact === best.exact && match.specificity === best.specificity);
164
+ if (tied.length > 1) return {
165
+ ok: false,
166
+ reason: `versions ${tied.map((match) => match.index + 1).join(", ")} match equally specifically`
167
+ };
168
+ return {
169
+ ok: true,
170
+ version: best.version,
171
+ index: best.index
172
+ };
173
+ }
174
+ //#endregion
175
+ export { BOOK_FURNITURE, LIBRARY_MOTIF_PREFIX, MOTIF_ATTRIBUTE, Motif, MotifField, MotifFieldInput, MotifInput, MotifVersion, MotifVersionInput, PRINTED_PAGE_CONTEXT, PRINTED_PAGE_FOLIO_PATH, PRINTED_PAGE_NUMBER_PATH, PRINTED_PAGE_RUNNING_HEAD_PATH, PRINTED_PAGE_TOTAL_PATH, chooseMotifVersion, motifFieldAttribute };
@@ -7,6 +7,8 @@ export declare const NumberSystem: z.ZodEnum<{
7
7
  hebrew: "hebrew";
8
8
  }>;
9
9
  export type NumberSystem = z.infer<typeof NumberSystem>;
10
+ export declare function isHebrew(lang: string | undefined): boolean;
11
+ export declare function defaultPageNumbering(lang: string | undefined): NumberSystem;
10
12
  export declare const NoteMarker: z.ZodUnion<readonly [z.ZodEnum<{
11
13
  arabic: "arabic";
12
14
  "roman-lower": "roman-lower";
package/dist/numbering.js CHANGED
@@ -6,6 +6,13 @@ const NumberSystem = z.enum([
6
6
  "roman-upper",
7
7
  "hebrew"
8
8
  ]);
9
+ function isHebrew(lang) {
10
+ const primary = lang?.split("-")[0]?.toLowerCase();
11
+ return primary === "he" || primary === "iw";
12
+ }
13
+ function defaultPageNumbering(lang) {
14
+ return isHebrew(lang) ? "hebrew" : "arabic";
15
+ }
9
16
  const NoteMarker = z.union([NumberSystem, z.literal("symbols")]);
10
17
  const ROMAN_DIGITS = [
11
18
  [1e3, "M"],
@@ -103,4 +110,4 @@ function noteMarker(index, marker) {
103
110
  return NOTE_SYMBOLS[(index - 1) % NOTE_SYMBOLS.length].repeat(Math.ceil(index / NOTE_SYMBOLS.length));
104
111
  }
105
112
  //#endregion
106
- export { NoteMarker, NumberSystem, formatNumber, noteMarker };
113
+ export { NoteMarker, NumberSystem, defaultPageNumbering, formatNumber, isHebrew, noteMarker };
@@ -0,0 +1,5 @@
1
+ import { Imposition, Print } from "./index.js";
2
+ //#region src/printed-page-imposition.d.ts
3
+ /** True when an imposition leaves one printed page unchanged on one paper. */
4
+ export declare function isPrintedPageIdentityImposition(print: Print, imposition: Imposition): boolean;
5
+ //#endregion
@@ -0,0 +1,12 @@
1
+ import { sheetMm, toMillimeters } from "./paper.js";
2
+ //#region src/printed-page-imposition.ts
3
+ const close = (left, right) => Math.abs(left - right) <= .01;
4
+ /** True when an imposition leaves one printed page unchanged on one paper. */
5
+ function isPrintedPageIdentityImposition(print, imposition) {
6
+ const pagePaper = sheetMm(print);
7
+ const imposedPaper = sheetMm(imposition);
8
+ const mm = (value) => toMillimeters(value, imposition.unit);
9
+ return print.orientation === imposition.orientation && close(pagePaper.width, imposedPaper.width) && close(pagePaper.height, imposedPaper.height) && imposition.columns === 1 && imposition.rows === 1 && close(mm(imposition.cell.width ?? 0), pagePaper.width) && close(mm(imposition.cell.height), pagePaper.height) && Object.values(imposition.margin).every((value) => value === 0) && imposition.gap.column === 0 && imposition.gap.row === 0 && imposition.bleed === 0 && imposition.marks === false && imposition.cornerMarks === false && imposition.fill === "sequence" && imposition.sides !== "two" && imposition.skip === 0 && imposition.fold === void 0;
10
+ }
11
+ //#endregion
12
+ export { isPrintedPageIdentityImposition };
@@ -0,0 +1,118 @@
1
+ import { z } from "zod";
2
+ //#region src/printed-pages.d.ts
3
+ export declare const PRINTED_PAGE_LIMIT = 500;
4
+ export declare const PRINTED_PAGE_ROLES: readonly ["every", "first", "recto", "verso", "last"];
5
+ export type PrintedPageRole = (typeof PRINTED_PAGE_ROLES)[number];
6
+ export declare const ParentPageMargin: z.ZodObject<{
7
+ top: z.ZodNumber;
8
+ bottom: z.ZodNumber;
9
+ inner: z.ZodNumber;
10
+ outer: z.ZodNumber;
11
+ }, z.core.$strip>;
12
+ export declare const ParentPage: z.ZodObject<{
13
+ name: z.ZodString;
14
+ basedOn: z.ZodOptional<z.ZodString>;
15
+ margin: z.ZodOptional<z.ZodObject<{
16
+ top: z.ZodNumber;
17
+ bottom: z.ZodNumber;
18
+ inner: z.ZodNumber;
19
+ outer: z.ZodNumber;
20
+ }, z.core.$strip>>;
21
+ head: z.ZodOptional<z.ZodString>;
22
+ foot: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strip>;
24
+ export declare const PrintedPageRules: z.ZodPipe<z.ZodObject<{
25
+ every: z.ZodString;
26
+ first: z.ZodOptional<z.ZodString>;
27
+ recto: z.ZodOptional<z.ZodString>;
28
+ verso: z.ZodOptional<z.ZodString>;
29
+ last: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$loose>, z.ZodTransform<{
31
+ last?: string | undefined;
32
+ verso?: string | undefined;
33
+ recto?: string | undefined;
34
+ first?: string | undefined;
35
+ every: string;
36
+ }, {
37
+ [x: string]: unknown;
38
+ every: string;
39
+ first?: string | undefined;
40
+ recto?: string | undefined;
41
+ verso?: string | undefined;
42
+ last?: string | undefined;
43
+ }>>;
44
+ export declare const PrintedPages: z.ZodObject<{
45
+ parents: z.ZodArray<z.ZodObject<{
46
+ name: z.ZodString;
47
+ basedOn: z.ZodOptional<z.ZodString>;
48
+ margin: z.ZodOptional<z.ZodObject<{
49
+ top: z.ZodNumber;
50
+ bottom: z.ZodNumber;
51
+ inner: z.ZodNumber;
52
+ outer: z.ZodNumber;
53
+ }, z.core.$strip>>;
54
+ head: z.ZodOptional<z.ZodString>;
55
+ foot: z.ZodOptional<z.ZodString>;
56
+ }, z.core.$strip>>;
57
+ rules: z.ZodPipe<z.ZodObject<{
58
+ every: z.ZodString;
59
+ first: z.ZodOptional<z.ZodString>;
60
+ recto: z.ZodOptional<z.ZodString>;
61
+ verso: z.ZodOptional<z.ZodString>;
62
+ last: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$loose>, z.ZodTransform<{
64
+ last?: string | undefined;
65
+ verso?: string | undefined;
66
+ recto?: string | undefined;
67
+ first?: string | undefined;
68
+ every: string;
69
+ }, {
70
+ [x: string]: unknown;
71
+ every: string;
72
+ first?: string | undefined;
73
+ recto?: string | undefined;
74
+ verso?: string | undefined;
75
+ last?: string | undefined;
76
+ }>>;
77
+ numbering: z.ZodOptional<z.ZodEnum<{
78
+ arabic: "arabic";
79
+ "roman-lower": "roman-lower";
80
+ "roman-upper": "roman-upper";
81
+ hebrew: "hebrew";
82
+ }>>;
83
+ }, z.core.$strip>;
84
+ export type ParentPageMargin = z.infer<typeof ParentPageMargin>;
85
+ export type ParentPage = z.infer<typeof ParentPage>;
86
+ export type PrintedPageRules = z.infer<typeof PrintedPageRules>;
87
+ export type PrintedPages = z.infer<typeof PrintedPages>;
88
+ export declare const BOOK_PARENT_NAMES: {
89
+ readonly recto: "segnavia:recto";
90
+ readonly verso: "segnavia:verso";
91
+ readonly opener: "segnavia:opener";
92
+ readonly blank: "segnavia:blank";
93
+ };
94
+ export declare function bookParentPages(margin: ParentPageMargin): ParentPage[];
95
+ export interface ResolvedParentPage {
96
+ name: string;
97
+ margin: ParentPageMargin;
98
+ head: string;
99
+ foot: string;
100
+ }
101
+ export declare function resolveParentPages(parents: ParentPage[]): ResolvedParentPage[];
102
+ export declare function printedPagesIssues(value: PrintedPages): Array<{
103
+ path: (string | number)[];
104
+ message: string;
105
+ }>;
106
+ export declare function pagePrintedPagesIssues(page: {
107
+ scripts: 'refuse' | 'sandboxed';
108
+ print?: {
109
+ margin?: unknown;
110
+ bleed: number;
111
+ marks: boolean;
112
+ };
113
+ printedPages?: PrintedPages;
114
+ }): Array<{
115
+ path: (string | number)[];
116
+ message: string;
117
+ }>;
118
+ //#endregion
@@ -0,0 +1,188 @@
1
+ import { NumberSystem } from "./numbering.js";
2
+ import { BOOK_FURNITURE } from "./motif.js";
3
+ import { z } from "zod";
4
+ //#region src/printed-pages.ts
5
+ const PRINTED_PAGE_LIMIT = 500;
6
+ const PRINTED_PAGE_ROLES = [
7
+ "every",
8
+ "first",
9
+ "recto",
10
+ "verso",
11
+ "last"
12
+ ];
13
+ const ParentPageMargin = z.object({
14
+ top: z.number().nonnegative(),
15
+ bottom: z.number().nonnegative(),
16
+ inner: z.number().nonnegative(),
17
+ outer: z.number().nonnegative()
18
+ });
19
+ const ParentPage = z.object({
20
+ name: z.string().min(1),
21
+ basedOn: z.string().min(1).optional(),
22
+ margin: ParentPageMargin.optional(),
23
+ head: z.string().optional(),
24
+ foot: z.string().optional()
25
+ });
26
+ const ParentName = z.string().min(1);
27
+ const PrintedPageRules = z.object({
28
+ every: z.string({ error: "every is required; name the default parent page to clear this refusal" }).min(1),
29
+ first: ParentName.optional(),
30
+ recto: ParentName.optional(),
31
+ verso: ParentName.optional(),
32
+ last: ParentName.optional()
33
+ }).passthrough().superRefine((rules, ctx) => {
34
+ const unknown = Object.keys(rules).filter((key) => !PRINTED_PAGE_ROLES.includes(key));
35
+ if (unknown.length) ctx.addIssue({
36
+ code: "custom",
37
+ message: `unknown printed-page role ${unknown.map((key) => JSON.stringify(key)).join(", ")}; use only every, first, recto, verso or last to clear this refusal`
38
+ });
39
+ }).transform(({ every, first, recto, verso, last }) => ({
40
+ every,
41
+ ...first === void 0 ? {} : { first },
42
+ ...recto === void 0 ? {} : { recto },
43
+ ...verso === void 0 ? {} : { verso },
44
+ ...last === void 0 ? {} : { last }
45
+ }));
46
+ const PrintedPages = z.object({
47
+ parents: z.array(ParentPage).min(1),
48
+ rules: PrintedPageRules,
49
+ numbering: NumberSystem.optional()
50
+ });
51
+ const BOOK_PARENT_NAMES = {
52
+ recto: "segnavia:recto",
53
+ verso: "segnavia:verso",
54
+ opener: "segnavia:opener",
55
+ blank: "segnavia:blank"
56
+ };
57
+ function furniture(region) {
58
+ return BOOK_FURNITURE.filter((item) => item.region === region).map((item) => `<div class="${item.className}" data-motif="${item.key}"></div>`).join("");
59
+ }
60
+ function bookParentPages(margin) {
61
+ const held = () => ({ ...margin });
62
+ const head = furniture("head");
63
+ const foot = furniture("foot");
64
+ return [
65
+ {
66
+ name: BOOK_PARENT_NAMES.recto,
67
+ margin: held(),
68
+ head,
69
+ foot
70
+ },
71
+ {
72
+ name: BOOK_PARENT_NAMES.verso,
73
+ margin: held(),
74
+ head,
75
+ foot
76
+ },
77
+ {
78
+ name: BOOK_PARENT_NAMES.opener,
79
+ margin: held(),
80
+ foot
81
+ },
82
+ {
83
+ name: BOOK_PARENT_NAMES.blank,
84
+ margin: held()
85
+ }
86
+ ];
87
+ }
88
+ const ZERO_PARENT_MARGIN = {
89
+ top: 0,
90
+ bottom: 0,
91
+ inner: 0,
92
+ outer: 0
93
+ };
94
+ function resolveParentPages(parents) {
95
+ const source = new Map(parents.map((parent) => [parent.name, parent]));
96
+ const resolved = /* @__PURE__ */ new Map();
97
+ const resolve = (parent) => {
98
+ const held = resolved.get(parent.name);
99
+ if (held) return held;
100
+ const baseParent = parent.basedOn ? source.get(parent.basedOn) : void 0;
101
+ const base = baseParent ? resolve(baseParent) : void 0;
102
+ const result = {
103
+ name: parent.name,
104
+ margin: parent.margin ?? base?.margin ?? ZERO_PARENT_MARGIN,
105
+ head: parent.head ?? base?.head ?? "",
106
+ foot: parent.foot ?? base?.foot ?? ""
107
+ };
108
+ resolved.set(parent.name, result);
109
+ return result;
110
+ };
111
+ return parents.map(resolve);
112
+ }
113
+ function printedPagesIssues(value) {
114
+ const issues = [];
115
+ const parents = /* @__PURE__ */ new Map();
116
+ value.parents.forEach((parent, index) => {
117
+ if (parents.has(parent.name)) issues.push({
118
+ path: [
119
+ "parents",
120
+ index,
121
+ "name"
122
+ ],
123
+ message: `parent page "${parent.name}" is duplicated; give every parent page a unique name to clear this refusal`
124
+ });
125
+ parents.set(parent.name, parent);
126
+ });
127
+ for (const [role, name] of Object.entries(value.rules)) {
128
+ if (name === void 0) continue;
129
+ if (!parents.has(name)) issues.push({
130
+ path: ["rules", role],
131
+ message: `${role} names unknown parent page "${name}"; add that parent page or name an existing one to clear this refusal`
132
+ });
133
+ }
134
+ value.parents.forEach((parent, index) => {
135
+ if (parent.basedOn && !parents.has(parent.basedOn)) issues.push({
136
+ path: [
137
+ "parents",
138
+ index,
139
+ "basedOn"
140
+ ],
141
+ message: `parent page "${parent.name}" is based on unknown parent page "${parent.basedOn}"; add that parent page or remove basedOn to clear this refusal`
142
+ });
143
+ const path = [];
144
+ let cursor = parent;
145
+ while (cursor) {
146
+ if (path.includes(cursor.name)) {
147
+ issues.push({
148
+ path: [
149
+ "parents",
150
+ index,
151
+ "basedOn"
152
+ ],
153
+ message: `parent page inheritance has a cycle ${[...path, cursor.name].join(" -> ")}; remove a basedOn link to clear this refusal`
154
+ });
155
+ break;
156
+ }
157
+ path.push(cursor.name);
158
+ cursor = cursor.basedOn ? parents.get(cursor.basedOn) : void 0;
159
+ }
160
+ });
161
+ return issues;
162
+ }
163
+ function pagePrintedPagesIssues(page) {
164
+ if (!page.printedPages) return [];
165
+ const issues = printedPagesIssues(page.printedPages).map((issue) => ({
166
+ ...issue,
167
+ path: ["printedPages", ...issue.path]
168
+ }));
169
+ if (!page.print) issues.push({
170
+ path: ["print"],
171
+ message: "printedPages could not establish a paper; add print.paper to clear this refusal"
172
+ });
173
+ if (page.scripts !== "refuse") issues.push({
174
+ path: ["scripts"],
175
+ message: "printedPages could not establish deterministic cloned content; set scripts to \"refuse\" to clear this refusal"
176
+ });
177
+ if (page.print?.margin) issues.push({
178
+ path: ["print", "margin"],
179
+ message: "printedPages and print.margin both own the margins; remove print.margin to clear this refusal"
180
+ });
181
+ if (page.print && (page.print.bleed > 0 || page.print.marks)) issues.push({
182
+ path: ["print"],
183
+ message: "printedPages could not establish one composed paper with bleed or marks; remove bleed and marks to clear this refusal"
184
+ });
185
+ return issues;
186
+ }
187
+ //#endregion
188
+ export { BOOK_PARENT_NAMES, PRINTED_PAGE_LIMIT, PRINTED_PAGE_ROLES, ParentPage, ParentPageMargin, PrintedPageRules, PrintedPages, bookParentPages, pagePrintedPagesIssues, printedPagesIssues, resolveParentPages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segnavia/format",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {