@segnavia/format 0.3.0 → 0.4.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 +244 -0
- package/dist/book.js +109 -0
- package/dist/direction.d.ts +6 -0
- package/dist/direction.js +7 -1
- package/dist/index.d.ts +111 -31
- package/dist/index.js +9 -26
- package/dist/lexicon.d.ts +18 -0
- package/dist/lexicon.js +38 -0
- package/dist/numbering.d.ts +19 -0
- package/dist/numbering.js +106 -0
- package/dist/paper.d.ts +20 -1
- package/dist/paper.js +19 -1
- package/dist/scripts.d.ts +8 -0
- package/dist/scripts.js +5 -0
- package/package.json +1 -1
package/dist/book.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/book.d.ts
|
|
3
|
+
export declare const BookMode: z.ZodEnum<{
|
|
4
|
+
continuous: "continuous";
|
|
5
|
+
paginated: "paginated";
|
|
6
|
+
}>;
|
|
7
|
+
export type BookMode = z.infer<typeof BookMode>;
|
|
8
|
+
export declare const BookSection: z.ZodObject<{
|
|
9
|
+
title: z.ZodOptional<z.ZodString>;
|
|
10
|
+
html: z.ZodString;
|
|
11
|
+
contents: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type BookSection = z.infer<typeof BookSection>;
|
|
14
|
+
export declare const Chapter: z.ZodObject<{
|
|
15
|
+
title: z.ZodString;
|
|
16
|
+
html: z.ZodString;
|
|
17
|
+
runningHead: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type Chapter = z.infer<typeof Chapter>;
|
|
20
|
+
export declare const BookPage: z.ZodObject<{
|
|
21
|
+
paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
22
|
+
letter: "letter";
|
|
23
|
+
legal: "legal";
|
|
24
|
+
tabloid: "tabloid";
|
|
25
|
+
a3: "a3";
|
|
26
|
+
a4: "a4";
|
|
27
|
+
a5: "a5";
|
|
28
|
+
}>, z.ZodObject<{
|
|
29
|
+
width: z.ZodNumber;
|
|
30
|
+
height: z.ZodNumber;
|
|
31
|
+
unit: z.ZodEnum<{
|
|
32
|
+
mm: "mm";
|
|
33
|
+
in: "in";
|
|
34
|
+
pt: "pt";
|
|
35
|
+
}>;
|
|
36
|
+
}, z.core.$strip>]>;
|
|
37
|
+
orientation: z.ZodDefault<z.ZodEnum<{
|
|
38
|
+
portrait: "portrait";
|
|
39
|
+
landscape: "landscape";
|
|
40
|
+
}>>;
|
|
41
|
+
margin: z.ZodObject<{
|
|
42
|
+
top: z.ZodNumber;
|
|
43
|
+
bottom: z.ZodNumber;
|
|
44
|
+
inner: z.ZodNumber;
|
|
45
|
+
outer: z.ZodNumber;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type BookPage = z.infer<typeof BookPage>;
|
|
49
|
+
export declare const Book: z.ZodPipe<z.ZodObject<{
|
|
50
|
+
title: z.ZodString;
|
|
51
|
+
mode: z.ZodEnum<{
|
|
52
|
+
continuous: "continuous";
|
|
53
|
+
paginated: "paginated";
|
|
54
|
+
}>;
|
|
55
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
56
|
+
paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
57
|
+
letter: "letter";
|
|
58
|
+
legal: "legal";
|
|
59
|
+
tabloid: "tabloid";
|
|
60
|
+
a3: "a3";
|
|
61
|
+
a4: "a4";
|
|
62
|
+
a5: "a5";
|
|
63
|
+
}>, z.ZodObject<{
|
|
64
|
+
width: z.ZodNumber;
|
|
65
|
+
height: z.ZodNumber;
|
|
66
|
+
unit: z.ZodEnum<{
|
|
67
|
+
mm: "mm";
|
|
68
|
+
in: "in";
|
|
69
|
+
pt: "pt";
|
|
70
|
+
}>;
|
|
71
|
+
}, z.core.$strip>]>;
|
|
72
|
+
orientation: z.ZodDefault<z.ZodEnum<{
|
|
73
|
+
portrait: "portrait";
|
|
74
|
+
landscape: "landscape";
|
|
75
|
+
}>>;
|
|
76
|
+
margin: z.ZodObject<{
|
|
77
|
+
top: z.ZodNumber;
|
|
78
|
+
bottom: z.ZodNumber;
|
|
79
|
+
inner: z.ZodNumber;
|
|
80
|
+
outer: z.ZodNumber;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
}, z.core.$strip>>;
|
|
83
|
+
scripts: z.ZodDefault<z.ZodEnum<{
|
|
84
|
+
refuse: "refuse";
|
|
85
|
+
sandboxed: "sandboxed";
|
|
86
|
+
}>>;
|
|
87
|
+
dir: z.ZodOptional<z.ZodEnum<{
|
|
88
|
+
ltr: "ltr";
|
|
89
|
+
rtl: "rtl";
|
|
90
|
+
auto: "auto";
|
|
91
|
+
}>>;
|
|
92
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
93
|
+
frontMatter: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
94
|
+
title: z.ZodOptional<z.ZodString>;
|
|
95
|
+
html: z.ZodString;
|
|
96
|
+
contents: z.ZodDefault<z.ZodBoolean>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
chapters: z.ZodArray<z.ZodObject<{
|
|
99
|
+
title: z.ZodString;
|
|
100
|
+
html: z.ZodString;
|
|
101
|
+
runningHead: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>>;
|
|
103
|
+
numbering: z.ZodDefault<z.ZodObject<{
|
|
104
|
+
frontMatter: z.ZodOptional<z.ZodEnum<{
|
|
105
|
+
arabic: "arabic";
|
|
106
|
+
"roman-lower": "roman-lower";
|
|
107
|
+
"roman-upper": "roman-upper";
|
|
108
|
+
hebrew: "hebrew";
|
|
109
|
+
}>>;
|
|
110
|
+
body: z.ZodOptional<z.ZodEnum<{
|
|
111
|
+
arabic: "arabic";
|
|
112
|
+
"roman-lower": "roman-lower";
|
|
113
|
+
"roman-upper": "roman-upper";
|
|
114
|
+
hebrew: "hebrew";
|
|
115
|
+
}>>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
footnotes: z.ZodDefault<z.ZodObject<{
|
|
118
|
+
marker: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
119
|
+
arabic: "arabic";
|
|
120
|
+
"roman-lower": "roman-lower";
|
|
121
|
+
"roman-upper": "roman-upper";
|
|
122
|
+
hebrew: "hebrew";
|
|
123
|
+
}>, z.ZodLiteral<"symbols">]>>;
|
|
124
|
+
restart: z.ZodDefault<z.ZodEnum<{
|
|
125
|
+
chapter: "chapter";
|
|
126
|
+
book: "book";
|
|
127
|
+
}>>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
endnotes: z.ZodDefault<z.ZodObject<{
|
|
130
|
+
marker: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
131
|
+
arabic: "arabic";
|
|
132
|
+
"roman-lower": "roman-lower";
|
|
133
|
+
"roman-upper": "roman-upper";
|
|
134
|
+
hebrew: "hebrew";
|
|
135
|
+
}>, z.ZodLiteral<"symbols">]>>;
|
|
136
|
+
placement: z.ZodDefault<z.ZodEnum<{
|
|
137
|
+
chapter: "chapter";
|
|
138
|
+
book: "book";
|
|
139
|
+
}>>;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
rightHandOpenings: z.ZodDefault<z.ZodBoolean>;
|
|
142
|
+
contents: z.ZodDefault<z.ZodObject<{
|
|
143
|
+
pageNumbers: z.ZodDefault<z.ZodBoolean>;
|
|
144
|
+
}, z.core.$strip>>;
|
|
145
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
146
|
+
numbering: {
|
|
147
|
+
frontMatter: "arabic" | "roman-lower" | "roman-upper" | "hebrew";
|
|
148
|
+
body: "arabic" | "roman-lower" | "roman-upper" | "hebrew";
|
|
149
|
+
};
|
|
150
|
+
footnotes: {
|
|
151
|
+
marker: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols";
|
|
152
|
+
restart: "chapter" | "book";
|
|
153
|
+
};
|
|
154
|
+
endnotes: {
|
|
155
|
+
marker: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols";
|
|
156
|
+
placement: "chapter" | "book";
|
|
157
|
+
};
|
|
158
|
+
title: string;
|
|
159
|
+
mode: "continuous" | "paginated";
|
|
160
|
+
scripts: "refuse" | "sandboxed";
|
|
161
|
+
frontMatter: {
|
|
162
|
+
html: string;
|
|
163
|
+
contents: boolean;
|
|
164
|
+
title?: string | undefined;
|
|
165
|
+
}[];
|
|
166
|
+
chapters: {
|
|
167
|
+
title: string;
|
|
168
|
+
html: string;
|
|
169
|
+
runningHead?: string | undefined;
|
|
170
|
+
}[];
|
|
171
|
+
rightHandOpenings: boolean;
|
|
172
|
+
contents: {
|
|
173
|
+
pageNumbers: boolean;
|
|
174
|
+
};
|
|
175
|
+
page?: {
|
|
176
|
+
paper: "letter" | "legal" | "tabloid" | "a3" | "a4" | "a5" | {
|
|
177
|
+
width: number;
|
|
178
|
+
height: number;
|
|
179
|
+
unit: "mm" | "in" | "pt";
|
|
180
|
+
};
|
|
181
|
+
orientation: "portrait" | "landscape";
|
|
182
|
+
margin: {
|
|
183
|
+
top: number;
|
|
184
|
+
bottom: number;
|
|
185
|
+
inner: number;
|
|
186
|
+
outer: number;
|
|
187
|
+
};
|
|
188
|
+
} | undefined;
|
|
189
|
+
dir?: "ltr" | "rtl" | "auto" | undefined;
|
|
190
|
+
lang?: string | undefined;
|
|
191
|
+
}, {
|
|
192
|
+
title: string;
|
|
193
|
+
mode: "continuous" | "paginated";
|
|
194
|
+
scripts: "refuse" | "sandboxed";
|
|
195
|
+
frontMatter: {
|
|
196
|
+
html: string;
|
|
197
|
+
contents: boolean;
|
|
198
|
+
title?: string | undefined;
|
|
199
|
+
}[];
|
|
200
|
+
chapters: {
|
|
201
|
+
title: string;
|
|
202
|
+
html: string;
|
|
203
|
+
runningHead?: string | undefined;
|
|
204
|
+
}[];
|
|
205
|
+
numbering: {
|
|
206
|
+
frontMatter?: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | undefined;
|
|
207
|
+
body?: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | undefined;
|
|
208
|
+
};
|
|
209
|
+
footnotes: {
|
|
210
|
+
restart: "chapter" | "book";
|
|
211
|
+
marker?: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols" | undefined;
|
|
212
|
+
};
|
|
213
|
+
endnotes: {
|
|
214
|
+
placement: "chapter" | "book";
|
|
215
|
+
marker?: "arabic" | "roman-lower" | "roman-upper" | "hebrew" | "symbols" | undefined;
|
|
216
|
+
};
|
|
217
|
+
rightHandOpenings: boolean;
|
|
218
|
+
contents: {
|
|
219
|
+
pageNumbers: boolean;
|
|
220
|
+
};
|
|
221
|
+
page?: {
|
|
222
|
+
paper: "letter" | "legal" | "tabloid" | "a3" | "a4" | "a5" | {
|
|
223
|
+
width: number;
|
|
224
|
+
height: number;
|
|
225
|
+
unit: "mm" | "in" | "pt";
|
|
226
|
+
};
|
|
227
|
+
orientation: "portrait" | "landscape";
|
|
228
|
+
margin: {
|
|
229
|
+
top: number;
|
|
230
|
+
bottom: number;
|
|
231
|
+
inner: number;
|
|
232
|
+
outer: number;
|
|
233
|
+
};
|
|
234
|
+
} | undefined;
|
|
235
|
+
dir?: "ltr" | "rtl" | "auto" | undefined;
|
|
236
|
+
lang?: string | undefined;
|
|
237
|
+
}>>;
|
|
238
|
+
export type Book = z.infer<typeof Book>;
|
|
239
|
+
export type BookInput = z.input<typeof Book>;
|
|
240
|
+
export declare function noteMarkerIssues(book: Book, used: {
|
|
241
|
+
footnotes: boolean;
|
|
242
|
+
endnotes: boolean;
|
|
243
|
+
}): string[];
|
|
244
|
+
//#endregion
|
package/dist/book.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Direction } from "./direction.js";
|
|
2
|
+
import { NoteMarker, NumberSystem } from "./numbering.js";
|
|
3
|
+
import { Paper, sheetMm } from "./paper.js";
|
|
4
|
+
import { Scripts } from "./scripts.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
//#region src/book.ts
|
|
7
|
+
const BookMode = z.enum(["continuous", "paginated"]);
|
|
8
|
+
const BookSection = z.object({
|
|
9
|
+
title: z.string().optional(),
|
|
10
|
+
html: z.string(),
|
|
11
|
+
contents: z.boolean().default(true)
|
|
12
|
+
});
|
|
13
|
+
const Chapter = z.object({
|
|
14
|
+
title: z.string(),
|
|
15
|
+
html: z.string(),
|
|
16
|
+
runningHead: z.string().optional()
|
|
17
|
+
});
|
|
18
|
+
const BookPage = z.object({
|
|
19
|
+
paper: Paper,
|
|
20
|
+
orientation: z.enum(["portrait", "landscape"]).default("portrait"),
|
|
21
|
+
margin: z.object({
|
|
22
|
+
top: z.number().nonnegative(),
|
|
23
|
+
bottom: z.number().nonnegative(),
|
|
24
|
+
inner: z.number().nonnegative(),
|
|
25
|
+
outer: z.number().nonnegative()
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
const BookShape = z.object({
|
|
29
|
+
title: z.string(),
|
|
30
|
+
mode: BookMode,
|
|
31
|
+
page: BookPage.optional(),
|
|
32
|
+
scripts: Scripts.default("refuse"),
|
|
33
|
+
dir: Direction.optional(),
|
|
34
|
+
lang: z.string().optional(),
|
|
35
|
+
frontMatter: z.array(BookSection).default([]),
|
|
36
|
+
chapters: z.array(Chapter).min(1),
|
|
37
|
+
numbering: z.object({
|
|
38
|
+
frontMatter: NumberSystem.optional(),
|
|
39
|
+
body: NumberSystem.optional()
|
|
40
|
+
}).default({}),
|
|
41
|
+
footnotes: z.object({
|
|
42
|
+
marker: NoteMarker.optional(),
|
|
43
|
+
restart: z.enum(["chapter", "book"]).default("chapter")
|
|
44
|
+
}).default({ restart: "chapter" }),
|
|
45
|
+
endnotes: z.object({
|
|
46
|
+
marker: NoteMarker.optional(),
|
|
47
|
+
placement: z.enum(["book", "chapter"]).default("book")
|
|
48
|
+
}).default({ placement: "book" }),
|
|
49
|
+
rightHandOpenings: z.boolean().default(false),
|
|
50
|
+
contents: z.object({ pageNumbers: z.boolean().default(true) }).default({ pageNumbers: true })
|
|
51
|
+
});
|
|
52
|
+
function isHebrew(lang) {
|
|
53
|
+
const primary = lang?.split("-")[0]?.toLowerCase();
|
|
54
|
+
return primary === "he" || primary === "iw";
|
|
55
|
+
}
|
|
56
|
+
const Book = BookShape.transform((book) => {
|
|
57
|
+
const hebrew = isHebrew(book.lang);
|
|
58
|
+
return {
|
|
59
|
+
...book,
|
|
60
|
+
numbering: {
|
|
61
|
+
frontMatter: book.numbering.frontMatter ?? (hebrew ? "arabic" : "roman-lower"),
|
|
62
|
+
body: book.numbering.body ?? (hebrew ? "hebrew" : "arabic")
|
|
63
|
+
},
|
|
64
|
+
footnotes: {
|
|
65
|
+
...book.footnotes,
|
|
66
|
+
marker: book.footnotes.marker ?? (hebrew ? "hebrew" : "symbols")
|
|
67
|
+
},
|
|
68
|
+
endnotes: {
|
|
69
|
+
...book.endnotes,
|
|
70
|
+
marker: book.endnotes.marker ?? "arabic"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}).superRefine((book, ctx) => {
|
|
74
|
+
if (book.mode === "paginated" && !book.page) ctx.addIssue({
|
|
75
|
+
code: "custom",
|
|
76
|
+
path: ["page"],
|
|
77
|
+
message: "a paginated book needs page; set page or use continuous mode"
|
|
78
|
+
});
|
|
79
|
+
if (book.frontMatter.length > 0 && book.numbering.frontMatter === book.numbering.body) ctx.addIssue({
|
|
80
|
+
code: "custom",
|
|
81
|
+
path: ["numbering"],
|
|
82
|
+
message: `front-matter and body numbering are both ${book.numbering.body}; the two must differ when front matter is present`
|
|
83
|
+
});
|
|
84
|
+
if (book.endnotes.placement === "chapter" && book.mode === "continuous") ctx.addIssue({
|
|
85
|
+
code: "custom",
|
|
86
|
+
path: ["endnotes", "placement"],
|
|
87
|
+
message: "endnotes are placed at the end of each chapter only in paginated mode; use book placement or paginated mode"
|
|
88
|
+
});
|
|
89
|
+
if (!book.page) return;
|
|
90
|
+
const trim = sheetMm(book.page);
|
|
91
|
+
const vertical = book.page.margin.top + book.page.margin.bottom;
|
|
92
|
+
const horizontal = book.page.margin.inner + book.page.margin.outer;
|
|
93
|
+
if (vertical >= trim.height) ctx.addIssue({
|
|
94
|
+
code: "custom",
|
|
95
|
+
path: ["page", "margin"],
|
|
96
|
+
message: `the top and bottom margins total ${vertical}mm and the page is ${trim.height}mm high; reduce the vertical margins to leave a text area`
|
|
97
|
+
});
|
|
98
|
+
if (horizontal >= trim.width) ctx.addIssue({
|
|
99
|
+
code: "custom",
|
|
100
|
+
path: ["page", "margin"],
|
|
101
|
+
message: `the inner and outer margins total ${horizontal}mm and the page is ${trim.width}mm wide; reduce the horizontal margins to leave a text area`
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
function noteMarkerIssues(book, used) {
|
|
105
|
+
if (!used.footnotes || !used.endnotes || book.footnotes.marker !== book.endnotes.marker) return [];
|
|
106
|
+
return [`footnote and endnote markers are both ${book.footnotes.marker}; the two must differ when both kinds are used`];
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { Book, BookMode, BookPage, BookSection, BookShape, Chapter, noteMarkerIssues };
|
package/dist/direction.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
//#region src/direction.d.ts
|
|
3
|
+
export declare const Direction: z.ZodEnum<{
|
|
4
|
+
ltr: "ltr";
|
|
5
|
+
rtl: "rtl";
|
|
6
|
+
auto: "auto";
|
|
7
|
+
}>;
|
|
2
8
|
export type TextDirection = 'ltr' | 'rtl';
|
|
3
9
|
export declare function firstStrongDirection(text: string): TextDirection | null;
|
|
4
10
|
export declare function languageDirection(lang: string | undefined): TextDirection | null;
|
package/dist/direction.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
//#region src/direction.ts
|
|
3
|
+
const Direction = z.enum([
|
|
4
|
+
"ltr",
|
|
5
|
+
"rtl",
|
|
6
|
+
"auto"
|
|
7
|
+
]);
|
|
2
8
|
const RTL_LETTER = /[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}\p{Script=Hanifi_Rohingya}\p{Script=Mende_Kikakui}\p{Script=Old_Hungarian}\p{Script=Imperial_Aramaic}\p{Script=Phoenician}]/u;
|
|
3
9
|
const LETTER = /\p{L}/u;
|
|
4
10
|
const RTL_LANGUAGES = /* @__PURE__ */ new Set([
|
|
@@ -36,4 +42,4 @@ function resolveDirection(dir, lang, sample) {
|
|
|
36
42
|
return languageDirection(lang) ?? firstStrongDirection(sample) ?? "ltr";
|
|
37
43
|
}
|
|
38
44
|
//#endregion
|
|
39
|
-
export { firstStrongDirection, languageDirection, resolveDirection };
|
|
45
|
+
export { Direction, firstStrongDirection, languageDirection, resolveDirection };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Book, BookInput, BookMode, BookPage, BookSection, Chapter, noteMarkerIssues } from "./book.js";
|
|
2
|
+
import { Direction, TextDirection, firstStrongDirection, languageDirection, resolveDirection } from "./direction.js";
|
|
3
|
+
import { MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, NAMED_PAPERS, PAPER_MM, PX_PER_MM, Paper, PaperBox, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters } from "./paper.js";
|
|
3
4
|
import { Imposed, MillimeterEdges, PageFit, PagePlacementKind, PagePlacementLayout, Placement, fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
|
|
5
|
+
import { Lexicon, PronunciationEntry, lexiconVersion } from "./lexicon.js";
|
|
6
|
+
import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.js";
|
|
7
|
+
import { Scripts } from "./scripts.js";
|
|
4
8
|
import { ShotUse, shotsUsed } from "./shots-used.js";
|
|
5
9
|
import { MAX_SLIDE_TIMING_MS } from "./timing.js";
|
|
6
10
|
import { DEFAULT_TRANSITION_DURATION_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, Transition, TransitionInput } from "./transition.js";
|
|
@@ -11,34 +15,6 @@ export declare const Size: z.ZodObject<{
|
|
|
11
15
|
height: z.ZodNumber;
|
|
12
16
|
}, z.core.$strip>;
|
|
13
17
|
export type Size = z.infer<typeof Size>;
|
|
14
|
-
export declare const Scripts: z.ZodEnum<{
|
|
15
|
-
refuse: "refuse";
|
|
16
|
-
sandboxed: "sandboxed";
|
|
17
|
-
}>;
|
|
18
|
-
export type Scripts = z.infer<typeof Scripts>;
|
|
19
|
-
export declare const Direction: z.ZodEnum<{
|
|
20
|
-
ltr: "ltr";
|
|
21
|
-
rtl: "rtl";
|
|
22
|
-
auto: "auto";
|
|
23
|
-
}>;
|
|
24
|
-
export declare const NAMED_PAPERS: readonly ["letter", "legal", "tabloid", "a3", "a4", "a5"];
|
|
25
|
-
export declare const Paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
26
|
-
letter: "letter";
|
|
27
|
-
legal: "legal";
|
|
28
|
-
tabloid: "tabloid";
|
|
29
|
-
a3: "a3";
|
|
30
|
-
a4: "a4";
|
|
31
|
-
a5: "a5";
|
|
32
|
-
}>, z.ZodObject<{
|
|
33
|
-
width: z.ZodNumber;
|
|
34
|
-
height: z.ZodNumber;
|
|
35
|
-
unit: z.ZodEnum<{
|
|
36
|
-
mm: "mm";
|
|
37
|
-
in: "in";
|
|
38
|
-
pt: "pt";
|
|
39
|
-
}>;
|
|
40
|
-
}, z.core.$strip>]>;
|
|
41
|
-
export type Paper = z.infer<typeof Paper>;
|
|
42
18
|
export declare const Margin: z.ZodObject<{
|
|
43
19
|
top: z.ZodDefault<z.ZodNumber>;
|
|
44
20
|
right: z.ZodDefault<z.ZodNumber>;
|
|
@@ -723,6 +699,103 @@ export interface DeckLimits {
|
|
|
723
699
|
}
|
|
724
700
|
export declare function exceedsLimits(deck: Deck, limits: DeckLimits): string[];
|
|
725
701
|
export declare function jsonSchemas(): {
|
|
702
|
+
book: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
703
|
+
title: z.ZodString;
|
|
704
|
+
mode: z.ZodEnum<{
|
|
705
|
+
continuous: "continuous";
|
|
706
|
+
paginated: "paginated";
|
|
707
|
+
}>;
|
|
708
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
709
|
+
paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
710
|
+
letter: "letter";
|
|
711
|
+
legal: "legal";
|
|
712
|
+
tabloid: "tabloid";
|
|
713
|
+
a3: "a3";
|
|
714
|
+
a4: "a4";
|
|
715
|
+
a5: "a5";
|
|
716
|
+
}>, z.ZodObject<{
|
|
717
|
+
width: z.ZodNumber;
|
|
718
|
+
height: z.ZodNumber;
|
|
719
|
+
unit: z.ZodEnum<{
|
|
720
|
+
mm: "mm";
|
|
721
|
+
in: "in";
|
|
722
|
+
pt: "pt";
|
|
723
|
+
}>;
|
|
724
|
+
}, z.core.$strip>]>;
|
|
725
|
+
orientation: z.ZodDefault<z.ZodEnum<{
|
|
726
|
+
portrait: "portrait";
|
|
727
|
+
landscape: "landscape";
|
|
728
|
+
}>>;
|
|
729
|
+
margin: z.ZodObject<{
|
|
730
|
+
top: z.ZodNumber;
|
|
731
|
+
bottom: z.ZodNumber;
|
|
732
|
+
inner: z.ZodNumber;
|
|
733
|
+
outer: z.ZodNumber;
|
|
734
|
+
}, z.core.$strip>;
|
|
735
|
+
}, z.core.$strip>>;
|
|
736
|
+
scripts: z.ZodDefault<z.ZodEnum<{
|
|
737
|
+
refuse: "refuse";
|
|
738
|
+
sandboxed: "sandboxed";
|
|
739
|
+
}>>;
|
|
740
|
+
dir: z.ZodOptional<z.ZodEnum<{
|
|
741
|
+
ltr: "ltr";
|
|
742
|
+
rtl: "rtl";
|
|
743
|
+
auto: "auto";
|
|
744
|
+
}>>;
|
|
745
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
746
|
+
frontMatter: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
747
|
+
title: z.ZodOptional<z.ZodString>;
|
|
748
|
+
html: z.ZodString;
|
|
749
|
+
contents: z.ZodDefault<z.ZodBoolean>;
|
|
750
|
+
}, z.core.$strip>>>;
|
|
751
|
+
chapters: z.ZodArray<z.ZodObject<{
|
|
752
|
+
title: z.ZodString;
|
|
753
|
+
html: z.ZodString;
|
|
754
|
+
runningHead: z.ZodOptional<z.ZodString>;
|
|
755
|
+
}, z.core.$strip>>;
|
|
756
|
+
numbering: z.ZodDefault<z.ZodObject<{
|
|
757
|
+
frontMatter: z.ZodOptional<z.ZodEnum<{
|
|
758
|
+
arabic: "arabic";
|
|
759
|
+
"roman-lower": "roman-lower";
|
|
760
|
+
"roman-upper": "roman-upper";
|
|
761
|
+
hebrew: "hebrew";
|
|
762
|
+
}>>;
|
|
763
|
+
body: z.ZodOptional<z.ZodEnum<{
|
|
764
|
+
arabic: "arabic";
|
|
765
|
+
"roman-lower": "roman-lower";
|
|
766
|
+
"roman-upper": "roman-upper";
|
|
767
|
+
hebrew: "hebrew";
|
|
768
|
+
}>>;
|
|
769
|
+
}, z.core.$strip>>;
|
|
770
|
+
footnotes: z.ZodDefault<z.ZodObject<{
|
|
771
|
+
marker: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
772
|
+
arabic: "arabic";
|
|
773
|
+
"roman-lower": "roman-lower";
|
|
774
|
+
"roman-upper": "roman-upper";
|
|
775
|
+
hebrew: "hebrew";
|
|
776
|
+
}>, z.ZodLiteral<"symbols">]>>;
|
|
777
|
+
restart: z.ZodDefault<z.ZodEnum<{
|
|
778
|
+
chapter: "chapter";
|
|
779
|
+
book: "book";
|
|
780
|
+
}>>;
|
|
781
|
+
}, z.core.$strip>>;
|
|
782
|
+
endnotes: z.ZodDefault<z.ZodObject<{
|
|
783
|
+
marker: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
784
|
+
arabic: "arabic";
|
|
785
|
+
"roman-lower": "roman-lower";
|
|
786
|
+
"roman-upper": "roman-upper";
|
|
787
|
+
hebrew: "hebrew";
|
|
788
|
+
}>, z.ZodLiteral<"symbols">]>>;
|
|
789
|
+
placement: z.ZodDefault<z.ZodEnum<{
|
|
790
|
+
chapter: "chapter";
|
|
791
|
+
book: "book";
|
|
792
|
+
}>>;
|
|
793
|
+
}, z.core.$strip>>;
|
|
794
|
+
rightHandOpenings: z.ZodDefault<z.ZodBoolean>;
|
|
795
|
+
contents: z.ZodDefault<z.ZodObject<{
|
|
796
|
+
pageNumbers: z.ZodDefault<z.ZodBoolean>;
|
|
797
|
+
}, z.core.$strip>>;
|
|
798
|
+
}, z.core.$strip>>;
|
|
726
799
|
page: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
727
800
|
html: z.ZodString;
|
|
728
801
|
size: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"fluid">, z.ZodObject<{
|
|
@@ -774,6 +847,13 @@ export declare function jsonSchemas(): {
|
|
|
774
847
|
marks: z.ZodDefault<z.ZodBoolean>;
|
|
775
848
|
}, z.core.$strip>>;
|
|
776
849
|
}, z.core.$strip>>;
|
|
850
|
+
lexicon: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
851
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
852
|
+
term: z.ZodString;
|
|
853
|
+
say: z.ZodString;
|
|
854
|
+
ipa: z.ZodOptional<z.ZodString>;
|
|
855
|
+
}, z.core.$strip>>;
|
|
856
|
+
}, z.core.$strip>>;
|
|
777
857
|
imposition: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
778
858
|
paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
779
859
|
letter: "letter";
|
|
@@ -1064,4 +1144,4 @@ export declare function jsonSchemas(): {
|
|
|
1064
1144
|
}, z.core.$strip>>;
|
|
1065
1145
|
};
|
|
1066
1146
|
//#endregion
|
|
1067
|
-
export { DEFAULT_TRANSITION_DURATION_MS, type Imposed, MARK_GAP_MM, MARK_LENGTH_MM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, MM_PER_PT, type MillimeterEdges, PAPER_MM, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, type PaperBox, type Placement, type ShotUse, type TextDirection, Transition, TransitionInput, firstStrongDirection, fitPage, impose, languageDirection, mirrorPlacement, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, sheetMm, shotsUsed, toMillimeters };
|
|
1147
|
+
export { Book, type BookInput, BookMode, BookPage, BookSection, Chapter, DEFAULT_TRANSITION_DURATION_MS, Direction, type Imposed, Lexicon, MARK_GAP_MM, MARK_LENGTH_MM, MAX_SLIDE_TIMING_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, MM_PER_PT, type MillimeterEdges, NAMED_PAPERS, NoteMarker, NumberSystem, PAPER_MM, PX_PER_MM, type PageFit, type PagePlacementKind, type PagePlacementLayout, Paper, type PaperBox, type Placement, PronunciationEntry, Scripts, type ShotUse, type TextDirection, Transition, TransitionInput, firstStrongDirection, fitPage, formatNumber, impose, languageDirection, lexiconVersion, mirrorPlacement, noteMarker, noteMarkerIssues, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, sheetMm, shotsUsed, toMillimeters };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Direction, firstStrongDirection, languageDirection, resolveDirection } from "./direction.js";
|
|
2
|
+
import { NoteMarker, NumberSystem, formatNumber, noteMarker } from "./numbering.js";
|
|
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
|
+
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";
|
|
2
7
|
import { MAX_SLIDE_TIMING_MS, SlideTiming, slideTimingIssues } from "./timing.js";
|
|
3
8
|
import { DEFAULT_TRANSITION_DURATION_MS, MAX_TRANSITION_DURATION_MS, MIN_TRANSITION_DURATION_MS, Transition } from "./transition.js";
|
|
4
|
-
import { firstStrongDirection, languageDirection, resolveDirection } from "./direction.js";
|
|
5
9
|
import { fitPage, impose, mirrorPlacement, pagePlacementLayout } from "./imposition.js";
|
|
6
10
|
import { shotsUsed } from "./shots-used.js";
|
|
7
11
|
import { z } from "zod";
|
|
@@ -10,29 +14,6 @@ const Size = z.object({
|
|
|
10
14
|
width: z.number().int().positive(),
|
|
11
15
|
height: z.number().int().positive()
|
|
12
16
|
});
|
|
13
|
-
const Scripts = z.enum(["refuse", "sandboxed"]);
|
|
14
|
-
const Direction = z.enum([
|
|
15
|
-
"ltr",
|
|
16
|
-
"rtl",
|
|
17
|
-
"auto"
|
|
18
|
-
]);
|
|
19
|
-
const NAMED_PAPERS = [
|
|
20
|
-
"letter",
|
|
21
|
-
"legal",
|
|
22
|
-
"tabloid",
|
|
23
|
-
"a3",
|
|
24
|
-
"a4",
|
|
25
|
-
"a5"
|
|
26
|
-
];
|
|
27
|
-
const Paper = z.union([z.enum(NAMED_PAPERS), z.object({
|
|
28
|
-
width: z.number().positive(),
|
|
29
|
-
height: z.number().positive(),
|
|
30
|
-
unit: z.enum([
|
|
31
|
-
"mm",
|
|
32
|
-
"in",
|
|
33
|
-
"pt"
|
|
34
|
-
])
|
|
35
|
-
})]);
|
|
36
17
|
const Margin = z.object({
|
|
37
18
|
top: z.number().nonnegative().default(0),
|
|
38
19
|
right: z.number().nonnegative().default(0),
|
|
@@ -345,7 +326,9 @@ function exceedsLimits(deck, limits) {
|
|
|
345
326
|
}
|
|
346
327
|
function jsonSchemas() {
|
|
347
328
|
return {
|
|
329
|
+
book: z.toJSONSchema(BookShape, { io: "input" }),
|
|
348
330
|
page: z.toJSONSchema(Page, { io: "input" }),
|
|
331
|
+
lexicon: z.toJSONSchema(Lexicon, { io: "input" }),
|
|
349
332
|
imposition: z.toJSONSchema(Imposition, { io: "input" }),
|
|
350
333
|
deck: z.toJSONSchema(DeckShape, { io: "input" }),
|
|
351
334
|
manifest: z.toJSONSchema(Manifest, { io: "input" }),
|
|
@@ -353,4 +336,4 @@ function jsonSchemas() {
|
|
|
353
336
|
};
|
|
354
337
|
}
|
|
355
338
|
//#endregion
|
|
356
|
-
export { Annotation, Box, Cue, DECK_SIZE, DEFAULT_TRANSITION_DURATION_MS, Deck, Direction, Imposition, 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, PAPER_MM, PX_PER_MM, Page, PageSize, Paper, Point, Print, PublishedShot, SHOT_KEY, Scripts, Shot, Size, Slide, SlideContent, Transition, Word, annotationCueIssues, exceedsLimits, firstStrongDirection, fitPage, impose, jsonSchemas, languageDirection, mirrorPlacement, pagePlacementLayout, printBoxes, printPadding, printProperties, resolveDirection, roundMillimeters, sheetMm, shotsUsed, toMillimeters };
|
|
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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/lexicon.d.ts
|
|
3
|
+
export declare const PronunciationEntry: z.ZodObject<{
|
|
4
|
+
term: z.ZodString;
|
|
5
|
+
say: z.ZodString;
|
|
6
|
+
ipa: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type PronunciationEntry = z.infer<typeof PronunciationEntry>;
|
|
9
|
+
export declare const Lexicon: z.ZodObject<{
|
|
10
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
11
|
+
term: z.ZodString;
|
|
12
|
+
say: z.ZodString;
|
|
13
|
+
ipa: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type Lexicon = z.infer<typeof Lexicon>;
|
|
17
|
+
export declare function lexiconVersion(lexicon: Lexicon): string;
|
|
18
|
+
//#endregion
|
package/dist/lexicon.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/lexicon.ts
|
|
3
|
+
const SingleWord = z.string().min(1).regex(/^\S+$/u);
|
|
4
|
+
const PronunciationEntry = z.object({
|
|
5
|
+
term: SingleWord,
|
|
6
|
+
say: SingleWord,
|
|
7
|
+
ipa: z.string().optional()
|
|
8
|
+
});
|
|
9
|
+
const Lexicon = z.object({ entries: z.array(PronunciationEntry) }).superRefine((lexicon, ctx) => {
|
|
10
|
+
const terms = /* @__PURE__ */ new Set();
|
|
11
|
+
lexicon.entries.forEach((entry, index) => {
|
|
12
|
+
if (terms.has(entry.term)) ctx.addIssue({
|
|
13
|
+
code: "custom",
|
|
14
|
+
path: [
|
|
15
|
+
"entries",
|
|
16
|
+
index,
|
|
17
|
+
"term"
|
|
18
|
+
],
|
|
19
|
+
message: `the term ${JSON.stringify(entry.term)} appears more than once`
|
|
20
|
+
});
|
|
21
|
+
terms.add(entry.term);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
function lexiconVersion(lexicon) {
|
|
25
|
+
const canonical = [...lexicon.entries].sort((left, right) => left.term < right.term ? -1 : left.term > right.term ? 1 : 0).map(({ term, say, ipa }) => [
|
|
26
|
+
term,
|
|
27
|
+
say,
|
|
28
|
+
ipa ?? null
|
|
29
|
+
]);
|
|
30
|
+
let hash = 14695981039346656037n;
|
|
31
|
+
for (const byte of new TextEncoder().encode(JSON.stringify(canonical))) {
|
|
32
|
+
hash ^= BigInt(byte);
|
|
33
|
+
hash = BigInt.asUintN(64, hash * 1099511628211n);
|
|
34
|
+
}
|
|
35
|
+
return hash.toString(16).padStart(16, "0").slice(0, 12);
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { Lexicon, PronunciationEntry, lexiconVersion };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/numbering.d.ts
|
|
3
|
+
export declare const NumberSystem: z.ZodEnum<{
|
|
4
|
+
arabic: "arabic";
|
|
5
|
+
"roman-lower": "roman-lower";
|
|
6
|
+
"roman-upper": "roman-upper";
|
|
7
|
+
hebrew: "hebrew";
|
|
8
|
+
}>;
|
|
9
|
+
export type NumberSystem = z.infer<typeof NumberSystem>;
|
|
10
|
+
export declare const NoteMarker: z.ZodUnion<readonly [z.ZodEnum<{
|
|
11
|
+
arabic: "arabic";
|
|
12
|
+
"roman-lower": "roman-lower";
|
|
13
|
+
"roman-upper": "roman-upper";
|
|
14
|
+
hebrew: "hebrew";
|
|
15
|
+
}>, z.ZodLiteral<"symbols">]>;
|
|
16
|
+
export type NoteMarker = z.infer<typeof NoteMarker>;
|
|
17
|
+
export declare function formatNumber(value: number, system: NumberSystem): string;
|
|
18
|
+
export declare function noteMarker(index: number, marker: NoteMarker): string;
|
|
19
|
+
//#endregion
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/numbering.ts
|
|
3
|
+
const NumberSystem = z.enum([
|
|
4
|
+
"arabic",
|
|
5
|
+
"roman-lower",
|
|
6
|
+
"roman-upper",
|
|
7
|
+
"hebrew"
|
|
8
|
+
]);
|
|
9
|
+
const NoteMarker = z.union([NumberSystem, z.literal("symbols")]);
|
|
10
|
+
const ROMAN_DIGITS = [
|
|
11
|
+
[1e3, "M"],
|
|
12
|
+
[900, "CM"],
|
|
13
|
+
[500, "D"],
|
|
14
|
+
[400, "CD"],
|
|
15
|
+
[100, "C"],
|
|
16
|
+
[90, "XC"],
|
|
17
|
+
[50, "L"],
|
|
18
|
+
[40, "XL"],
|
|
19
|
+
[10, "X"],
|
|
20
|
+
[9, "IX"],
|
|
21
|
+
[5, "V"],
|
|
22
|
+
[4, "IV"],
|
|
23
|
+
[1, "I"]
|
|
24
|
+
];
|
|
25
|
+
const HEBREW_ONES = [
|
|
26
|
+
"",
|
|
27
|
+
"א",
|
|
28
|
+
"ב",
|
|
29
|
+
"ג",
|
|
30
|
+
"ד",
|
|
31
|
+
"ה",
|
|
32
|
+
"ו",
|
|
33
|
+
"ז",
|
|
34
|
+
"ח",
|
|
35
|
+
"ט"
|
|
36
|
+
];
|
|
37
|
+
const HEBREW_TENS = [
|
|
38
|
+
"",
|
|
39
|
+
"י",
|
|
40
|
+
"כ",
|
|
41
|
+
"ל",
|
|
42
|
+
"מ",
|
|
43
|
+
"נ",
|
|
44
|
+
"ס",
|
|
45
|
+
"ע",
|
|
46
|
+
"פ",
|
|
47
|
+
"צ"
|
|
48
|
+
];
|
|
49
|
+
const NOTE_SYMBOLS = [
|
|
50
|
+
"*",
|
|
51
|
+
"†",
|
|
52
|
+
"‡",
|
|
53
|
+
"§"
|
|
54
|
+
];
|
|
55
|
+
function positiveInteger(value) {
|
|
56
|
+
if (!Number.isInteger(value) || value < 1) throw new RangeError(`value ${value} must be a positive integer`);
|
|
57
|
+
}
|
|
58
|
+
function inRange(value, maximum, system) {
|
|
59
|
+
if (value > maximum) throw new RangeError(`${system} value ${value} is outside the range 1 to ${maximum}`);
|
|
60
|
+
}
|
|
61
|
+
function roman(value) {
|
|
62
|
+
let remaining = value;
|
|
63
|
+
let result = "";
|
|
64
|
+
for (const [amount, digit] of ROMAN_DIGITS) while (remaining >= amount) {
|
|
65
|
+
result += digit;
|
|
66
|
+
remaining -= amount;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function hebrewBelowThousand(value) {
|
|
71
|
+
const hundreds = "ת".repeat(Math.floor(value / 400));
|
|
72
|
+
const underFourHundred = value % 400;
|
|
73
|
+
const hundredsLetter = [
|
|
74
|
+
"",
|
|
75
|
+
"ק",
|
|
76
|
+
"ר",
|
|
77
|
+
"ש"
|
|
78
|
+
][Math.floor(underFourHundred / 100)];
|
|
79
|
+
const remainder = underFourHundred % 100;
|
|
80
|
+
if (remainder === 15) return `${hundreds}${hundredsLetter}טו`;
|
|
81
|
+
if (remainder === 16) return `${hundreds}${hundredsLetter}טז`;
|
|
82
|
+
return `${hundreds}${hundredsLetter}${HEBREW_TENS[Math.floor(remainder / 10)]}${HEBREW_ONES[remainder % 10]}`;
|
|
83
|
+
}
|
|
84
|
+
function hebrew(value) {
|
|
85
|
+
const thousands = Math.floor(value / 1e3);
|
|
86
|
+
const rest = value % 1e3;
|
|
87
|
+
return `${thousands === 0 ? "" : `${HEBREW_ONES[thousands]}׳`}${hebrewBelowThousand(rest)}`;
|
|
88
|
+
}
|
|
89
|
+
function formatNumber(value, system) {
|
|
90
|
+
positiveInteger(value);
|
|
91
|
+
if (system === "arabic") return String(value);
|
|
92
|
+
if (system === "hebrew") {
|
|
93
|
+
inRange(value, 9999, system);
|
|
94
|
+
return hebrew(value);
|
|
95
|
+
}
|
|
96
|
+
inRange(value, 3999, system);
|
|
97
|
+
const result = roman(value);
|
|
98
|
+
return system === "roman-lower" ? result.toLowerCase() : result;
|
|
99
|
+
}
|
|
100
|
+
function noteMarker(index, marker) {
|
|
101
|
+
positiveInteger(index);
|
|
102
|
+
if (marker !== "symbols") return formatNumber(index, marker);
|
|
103
|
+
return NOTE_SYMBOLS[(index - 1) % NOTE_SYMBOLS.length].repeat(Math.ceil(index / NOTE_SYMBOLS.length));
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { NoteMarker, NumberSystem, formatNumber, noteMarker };
|
package/dist/paper.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Print } from "./index.js";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
//#region src/paper.d.ts
|
|
4
|
+
export declare const NAMED_PAPERS: readonly ["letter", "legal", "tabloid", "a3", "a4", "a5"];
|
|
5
|
+
export declare const Paper: z.ZodUnion<readonly [z.ZodEnum<{
|
|
6
|
+
letter: "letter";
|
|
7
|
+
legal: "legal";
|
|
8
|
+
tabloid: "tabloid";
|
|
9
|
+
a3: "a3";
|
|
10
|
+
a4: "a4";
|
|
11
|
+
a5: "a5";
|
|
12
|
+
}>, z.ZodObject<{
|
|
13
|
+
width: z.ZodNumber;
|
|
14
|
+
height: z.ZodNumber;
|
|
15
|
+
unit: z.ZodEnum<{
|
|
16
|
+
mm: "mm";
|
|
17
|
+
in: "in";
|
|
18
|
+
pt: "pt";
|
|
19
|
+
}>;
|
|
20
|
+
}, z.core.$strip>]>;
|
|
21
|
+
export type Paper = z.infer<typeof Paper>;
|
|
3
22
|
export declare const MM_PER_PT: number;
|
|
4
23
|
export declare const MARK_LENGTH_MM = 5;
|
|
5
24
|
export declare const MARK_GAP_MM = 1;
|
package/dist/paper.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
//#region src/paper.ts
|
|
3
|
+
const NAMED_PAPERS = [
|
|
4
|
+
"letter",
|
|
5
|
+
"legal",
|
|
6
|
+
"tabloid",
|
|
7
|
+
"a3",
|
|
8
|
+
"a4",
|
|
9
|
+
"a5"
|
|
10
|
+
];
|
|
11
|
+
const Paper = z.union([z.enum(NAMED_PAPERS), z.object({
|
|
12
|
+
width: z.number().positive(),
|
|
13
|
+
height: z.number().positive(),
|
|
14
|
+
unit: z.enum([
|
|
15
|
+
"mm",
|
|
16
|
+
"in",
|
|
17
|
+
"pt"
|
|
18
|
+
])
|
|
19
|
+
})]);
|
|
2
20
|
const MM_PER_PT = 25.4 / 72;
|
|
3
21
|
const MARK_LENGTH_MM = 5;
|
|
4
22
|
const MARK_GAP_MM = 1;
|
|
@@ -156,4 +174,4 @@ function printBoxes(print) {
|
|
|
156
174
|
};
|
|
157
175
|
}
|
|
158
176
|
//#endregion
|
|
159
|
-
export { MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, PAPER_MM, PX_PER_MM, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters };
|
|
177
|
+
export { MARK_GAP_MM, MARK_LENGTH_MM, MM_PER_PT, NAMED_PAPERS, PAPER_MM, PX_PER_MM, Paper, printBoxes, printPadding, printProperties, roundMillimeters, sheetMm, toMillimeters };
|
package/dist/scripts.js
ADDED