@segnavia/format 0.25.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 +24 -1
- package/dist/book.js +6 -7
- package/dist/fold.d.ts +16 -0
- package/dist/fold.js +175 -0
- package/dist/fonts.d.ts +77 -0
- package/dist/fonts.js +49 -0
- package/dist/imposition-fit.d.ts +3 -0
- package/dist/imposition-fit.js +33 -0
- package/dist/imposition-marks.js +27 -20
- package/dist/imposition.js +55 -3
- package/dist/index.d.ts +419 -16
- package/dist/index.js +88 -35
- package/dist/motif.d.ts +143 -0
- package/dist/motif.js +175 -0
- package/dist/numbering.d.ts +2 -0
- package/dist/numbering.js +8 -1
- package/dist/paper.d.ts +3 -0
- package/dist/paper.js +3 -1
- package/dist/printed-page-imposition.d.ts +5 -0
- package/dist/printed-page-imposition.js +12 -0
- package/dist/printed-pages.d.ts +118 -0
- package/dist/printed-pages.js +188 -0
- package/package.json +1 -1
|
@@ -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 };
|