@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/book.d.ts CHANGED
@@ -11,6 +11,21 @@ export declare const BookSection: z.ZodObject<{
11
11
  contents: z.ZodDefault<z.ZodBoolean>;
12
12
  }, z.core.$strip>;
13
13
  export type BookSection = z.infer<typeof BookSection>;
14
+ export declare const BookContents: z.ZodObject<{
15
+ kind: z.ZodLiteral<"contents">;
16
+ title: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>;
18
+ export type BookContents = z.infer<typeof BookContents>;
19
+ export declare const BookFrontMatterEntry: z.ZodUnion<readonly [z.ZodObject<{
20
+ title: z.ZodOptional<z.ZodString>;
21
+ html: z.ZodString;
22
+ contents: z.ZodDefault<z.ZodBoolean>;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ kind: z.ZodLiteral<"contents">;
25
+ title: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strip>]>;
27
+ export type BookFrontMatterEntry = z.infer<typeof BookFrontMatterEntry>;
28
+ export declare function isBookContents(entry: BookFrontMatterEntry): entry is BookContents;
14
29
  export declare const Chapter: z.ZodObject<{
15
30
  title: z.ZodString;
16
31
  html: z.ZodString;
@@ -90,11 +105,14 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
90
105
  auto: "auto";
91
106
  }>>;
92
107
  lang: z.ZodOptional<z.ZodString>;
93
- frontMatter: z.ZodDefault<z.ZodArray<z.ZodObject<{
108
+ frontMatter: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
94
109
  title: z.ZodOptional<z.ZodString>;
95
110
  html: z.ZodString;
96
111
  contents: z.ZodDefault<z.ZodBoolean>;
97
- }, z.core.$strip>>>;
112
+ }, z.core.$strip>, z.ZodObject<{
113
+ kind: z.ZodLiteral<"contents">;
114
+ title: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strip>]>>>;
98
116
  chapters: z.ZodArray<z.ZodObject<{
99
117
  title: z.ZodString;
100
118
  html: z.ZodString;
@@ -137,10 +155,12 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
137
155
  chapter: "chapter";
138
156
  book: "book";
139
157
  }>>;
158
+ title: z.ZodOptional<z.ZodString>;
140
159
  }, z.core.$strip>>;
141
- rightHandOpenings: z.ZodDefault<z.ZodBoolean>;
160
+ rectoOpenings: z.ZodDefault<z.ZodBoolean>;
142
161
  contents: z.ZodDefault<z.ZodObject<{
143
162
  pageNumbers: z.ZodDefault<z.ZodBoolean>;
163
+ depth: z.ZodDefault<z.ZodNumber>;
144
164
  }, z.core.$strip>>;
145
165
  }, z.core.$strip>, z.ZodTransform<{
146
166
  numbering: {
@@ -153,24 +173,29 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
153
173
  };
154
174
  endnotes: {
155
175
  marker: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols";
176
+ title: string;
156
177
  placement: "chapter" | "book";
157
178
  };
158
179
  title: string;
159
180
  mode: "continuous" | "paginated";
160
181
  scripts: "refuse" | "sandboxed";
161
- frontMatter: {
182
+ frontMatter: ({
162
183
  html: string;
163
184
  contents: boolean;
164
185
  title?: string | undefined;
165
- }[];
186
+ } | {
187
+ kind: "contents";
188
+ title?: string | undefined;
189
+ })[];
166
190
  chapters: {
167
191
  title: string;
168
192
  html: string;
169
193
  runningHead?: string | undefined;
170
194
  }[];
171
- rightHandOpenings: boolean;
195
+ rectoOpenings: boolean;
172
196
  contents: {
173
197
  pageNumbers: boolean;
198
+ depth: number;
174
199
  };
175
200
  page?: {
176
201
  paper: "letter" | "legal" | "tabloid" | "a3" | "a4" | "a5" | {
@@ -192,11 +217,14 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
192
217
  title: string;
193
218
  mode: "continuous" | "paginated";
194
219
  scripts: "refuse" | "sandboxed";
195
- frontMatter: {
220
+ frontMatter: ({
196
221
  html: string;
197
222
  contents: boolean;
198
223
  title?: string | undefined;
199
- }[];
224
+ } | {
225
+ kind: "contents";
226
+ title?: string | undefined;
227
+ })[];
200
228
  chapters: {
201
229
  title: string;
202
230
  html: string;
@@ -213,10 +241,12 @@ export declare const Book: z.ZodPipe<z.ZodObject<{
213
241
  endnotes: {
214
242
  placement: "chapter" | "book";
215
243
  marker?: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols" | undefined;
244
+ title?: string | undefined;
216
245
  };
217
- rightHandOpenings: boolean;
246
+ rectoOpenings: boolean;
218
247
  contents: {
219
248
  pageNumbers: boolean;
249
+ depth: number;
220
250
  };
221
251
  page?: {
222
252
  paper: "letter" | "legal" | "tabloid" | "a3" | "a4" | "a5" | {
package/dist/book.js CHANGED
@@ -10,6 +10,14 @@ const BookSection = z.object({
10
10
  html: z.string(),
11
11
  contents: z.boolean().default(true)
12
12
  });
13
+ const BookContents = z.object({
14
+ kind: z.literal("contents"),
15
+ title: z.string().optional()
16
+ });
17
+ const BookFrontMatterEntry = z.union([BookSection, BookContents]);
18
+ function isBookContents(entry) {
19
+ return "kind" in entry && entry.kind === "contents";
20
+ }
13
21
  const Chapter = z.object({
14
22
  title: z.string(),
15
23
  html: z.string(),
@@ -32,7 +40,7 @@ const BookShape = z.object({
32
40
  scripts: Scripts.default("refuse"),
33
41
  dir: Direction.optional(),
34
42
  lang: z.string().optional(),
35
- frontMatter: z.array(BookSection).default([]),
43
+ frontMatter: z.array(BookFrontMatterEntry).default([]),
36
44
  chapters: z.array(Chapter).min(1),
37
45
  numbering: z.object({
38
46
  frontMatter: NumberSystem.optional(),
@@ -44,10 +52,17 @@ const BookShape = z.object({
44
52
  }).default({ restart: "chapter" }),
45
53
  endnotes: z.object({
46
54
  marker: NoteMarker.optional(),
47
- placement: z.enum(["book", "chapter"]).default("book")
55
+ placement: z.enum(["book", "chapter"]).default("book"),
56
+ title: z.string().optional()
48
57
  }).default({ placement: "book" }),
49
- rightHandOpenings: z.boolean().default(false),
50
- contents: z.object({ pageNumbers: z.boolean().default(true) }).default({ pageNumbers: true })
58
+ rectoOpenings: z.boolean().default(false),
59
+ contents: z.object({
60
+ pageNumbers: z.boolean().default(true),
61
+ depth: z.number().int().min(1).max(6).default(2)
62
+ }).default({
63
+ pageNumbers: true,
64
+ depth: 2
65
+ })
51
66
  });
52
67
  function isHebrew(lang) {
53
68
  const primary = lang?.split("-")[0]?.toLowerCase();
@@ -67,10 +82,17 @@ const Book = BookShape.transform((book) => {
67
82
  },
68
83
  endnotes: {
69
84
  ...book.endnotes,
70
- marker: book.endnotes.marker ?? "arabic"
85
+ marker: book.endnotes.marker ?? "arabic",
86
+ title: book.endnotes.title ?? (hebrew ? "הערות" : "Notes")
71
87
  }
72
88
  };
73
89
  }).superRefine((book, ctx) => {
90
+ const contentsPositions = book.frontMatter.flatMap((entry, index) => isBookContents(entry) ? [index + 1] : []);
91
+ if (contentsPositions.length > 1) ctx.addIssue({
92
+ code: "custom",
93
+ path: ["frontMatter"],
94
+ message: `front-matter entries at positions ${contentsPositions[0]} and ${contentsPositions[1]} are both contents entries; one must go`
95
+ });
74
96
  if (book.mode === "paginated" && !book.page) ctx.addIssue({
75
97
  code: "custom",
76
98
  path: ["page"],
@@ -106,4 +128,4 @@ function noteMarkerIssues(book, used) {
106
128
  return [`footnote and endnote markers are both ${book.footnotes.marker}; the two must differ when both kinds are used`];
107
129
  }
108
130
  //#endregion
109
- export { Book, BookMode, BookPage, BookSection, BookShape, Chapter, noteMarkerIssues };
131
+ export { Book, BookContents, BookFrontMatterEntry, BookMode, BookPage, BookSection, BookShape, Chapter, isBookContents, noteMarkerIssues };
@@ -0,0 +1,116 @@
1
+ import { DeckInput } from "./deck.js";
2
+ //#region src/deck-from-slides.d.ts
3
+ type SlideInput = DeckInput['slides'][number];
4
+ type SlideFields = Omit<SlideInput, 'content'>;
5
+ type ShotContent = Extract<SlideInput['content'], {
6
+ kind: 'shot';
7
+ }>;
8
+ export type SlideRow = SlideFields & ({
9
+ kind: 'html';
10
+ html: string;
11
+ } | ShotContent);
12
+ export type DeckFromSlidesOptions = Omit<DeckInput, 'slides'> & {
13
+ omitNotes?: boolean;
14
+ };
15
+ export declare function deckFromSlides(rows: SlideRow[], options: DeckFromSlidesOptions): {
16
+ title: string;
17
+ size: {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ scripts: "refuse" | "sandboxed";
22
+ slides: {
23
+ id: string;
24
+ content: {
25
+ kind: "html";
26
+ html: string;
27
+ } | {
28
+ kind: "url";
29
+ src: string;
30
+ } | {
31
+ kind: "shot";
32
+ src: string;
33
+ shot: {
34
+ key: string;
35
+ title: string;
36
+ description: string | null;
37
+ tags: string[];
38
+ file: string;
39
+ annotatedFile: string | null;
40
+ size: {
41
+ width: number;
42
+ height: number;
43
+ };
44
+ scale: number;
45
+ dir: "ltr" | "rtl";
46
+ annotations: {
47
+ ring: {
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ } | null;
53
+ badge: {
54
+ center: {
55
+ x: number;
56
+ y: number;
57
+ };
58
+ number: number;
59
+ } | null;
60
+ arrow: {
61
+ head: {
62
+ x: number;
63
+ y: number;
64
+ };
65
+ tail: {
66
+ x: number;
67
+ y: number;
68
+ };
69
+ label: string | null;
70
+ } | null;
71
+ }[];
72
+ capturedAt: string;
73
+ meta: Record<string, unknown>;
74
+ };
75
+ } | {
76
+ kind: "shot-ref";
77
+ href: string;
78
+ } | {
79
+ kind: "image";
80
+ src: string;
81
+ alt: string;
82
+ };
83
+ notes?: string | undefined;
84
+ narration?: {
85
+ text: string;
86
+ words: {
87
+ text: string;
88
+ startMs: number;
89
+ endMs: number;
90
+ }[];
91
+ durationMs: number;
92
+ audio: string | null;
93
+ live: boolean;
94
+ cues: {
95
+ word: number;
96
+ annotation: number;
97
+ untilWord?: number | undefined;
98
+ }[];
99
+ lang?: string | undefined;
100
+ dir?: "ltr" | "rtl" | "auto" | undefined;
101
+ voice?: string | undefined;
102
+ } | undefined;
103
+ beforeMs?: number | undefined;
104
+ afterMs?: number | undefined;
105
+ holdMs?: number | undefined;
106
+ }[];
107
+ dir?: "ltr" | "rtl" | "auto" | undefined;
108
+ lang?: string | undefined;
109
+ transition?: {
110
+ kind: "none" | "fade" | "slide";
111
+ duration: number;
112
+ } | undefined;
113
+ playback?: "continuous" | "step" | undefined;
114
+ captions?: "on" | "off" | "viewer" | undefined;
115
+ };
116
+ //#endregion
@@ -0,0 +1,36 @@
1
+ import { Deck } from "./deck.js";
2
+ //#region src/deck-from-slides.ts
3
+ function deckFromSlides(rows, options) {
4
+ const { omitNotes = false, ...deckOptions } = options;
5
+ const slides = rows.map(({ kind, ...row }) => {
6
+ const { id, notes, narration, beforeMs, afterMs, holdMs } = row;
7
+ const common = {
8
+ id,
9
+ ...!omitNotes && notes !== void 0 ? { notes } : {},
10
+ ...narration !== void 0 ? { narration } : {},
11
+ ...beforeMs !== void 0 ? { beforeMs } : {},
12
+ ...afterMs !== void 0 ? { afterMs } : {},
13
+ ...holdMs !== void 0 ? { holdMs } : {}
14
+ };
15
+ return kind === "html" ? {
16
+ ...common,
17
+ content: {
18
+ kind,
19
+ html: row.html
20
+ }
21
+ } : {
22
+ ...common,
23
+ content: {
24
+ kind,
25
+ src: row.src,
26
+ shot: row.shot
27
+ }
28
+ };
29
+ });
30
+ return Deck.parse({
31
+ ...deckOptions,
32
+ slides
33
+ });
34
+ }
35
+ //#endregion
36
+ export { deckFromSlides };