@cosmicdrift/kumiko-document-designer 0.418.0 → 0.420.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/web/apply-layout-dialog.d.ts +7 -0
- package/dist/web/apply-layout-dialog.js +95 -0
- package/dist/web/company-data-rail.d.ts +5 -0
- package/dist/web/company-data-rail.js +51 -0
- package/dist/web/constants.d.ts +1 -0
- package/dist/web/constants.js +2 -0
- package/dist/web/default-translations.js +3 -0
- package/dist/web/frame-position.d.ts +18 -0
- package/dist/web/frame-position.js +28 -0
- package/dist/web/frame-settings-section.d.ts +13 -0
- package/dist/web/frame-settings-section.js +57 -0
- package/dist/web/i18n.js +285 -3
- package/dist/web/index.d.ts +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/layout-appearance-section.d.ts +8 -0
- package/dist/web/layout-appearance-section.js +64 -0
- package/dist/web/layout-editor-body.js +5 -2
- package/dist/web/layout-editor-logic.d.ts +3 -1
- package/dist/web/layout-editor-logic.js +15 -7
- package/dist/web/layout-editor-paper.d.ts +1 -1
- package/dist/web/layout-editor-paper.js +43 -8
- package/dist/web/layout-html.js +2 -2
- package/dist/web/layout-meta.d.ts +49 -0
- package/dist/web/layout-meta.js +155 -1
- package/dist/web/layout-rails.d.ts +7 -1
- package/dist/web/layout-rails.js +10 -5
- package/dist/web/layout-types.d.ts +2 -2
- package/dist/web/layout-usage-section.d.ts +4 -0
- package/dist/web/layout-usage-section.js +71 -0
- package/dist/web/page-canvas.d.ts +6 -3
- package/dist/web/page-canvas.js +23 -32
- package/dist/web/page-ruler.d.ts +6 -0
- package/dist/web/page-ruler.js +33 -0
- package/dist/web/paper-geometry.d.ts +72 -0
- package/dist/web/paper-geometry.js +134 -0
- package/dist/web/paper-sheet.d.ts +11 -0
- package/dist/web/paper-sheet.js +36 -0
- package/dist/web/pdf-editor-chrome.js +3 -3
- package/dist/web/pdf-editor-context.d.ts +2 -0
- package/dist/web/pdf-editor-panes.js +5 -4
- package/dist/web/pdf-editor-view.d.ts +4 -0
- package/dist/web/pdf-editor-view.js +23 -3
- package/dist/web/pdf-left-rail.d.ts +8 -0
- package/dist/web/pdf-left-rail.js +23 -3
- package/dist/web/pdf-template-editor.js +25 -2
- package/dist/web/settings-panel.d.ts +10 -2
- package/dist/web/settings-panel.js +32 -17
- package/dist/web/use-apply-layout.d.ts +28 -0
- package/dist/web/use-apply-layout.js +13 -0
- package/dist/web/use-layout-editor-state.d.ts +5 -0
- package/dist/web/use-layout-editor-state.js +38 -15
- package/dist/web/use-pdf-editor-state.d.ts +5 -0
- package/dist/web/use-pdf-editor-state.js +42 -10
- package/package.json +6 -6
- package/src/changes.json +31 -0
package/dist/web/layout-html.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createElement, useMemo } from "react";
|
|
|
6
6
|
// markup in the admin session. Unknown elements are unwrapped, scripts dropped.
|
|
7
7
|
const TAG_CLASSES = {
|
|
8
8
|
div: "",
|
|
9
|
-
p: "m-0",
|
|
9
|
+
p: "m-0 whitespace-pre-line",
|
|
10
10
|
span: "",
|
|
11
11
|
strong: "font-semibold",
|
|
12
12
|
b: "font-semibold",
|
|
@@ -59,7 +59,7 @@ function renderNode(node, props, path) {
|
|
|
59
59
|
return _jsx("span", { children: renderChildren(node, props, path) }, path);
|
|
60
60
|
const variable = node.getAttribute("data-variable");
|
|
61
61
|
if (variable !== null) {
|
|
62
|
-
return (_jsx("span", { className: "mx-0.5 inline-flex rounded border border-
|
|
62
|
+
return (_jsx("span", { className: "mx-0.5 inline-flex rounded border border-input bg-muted px-1.5 text-xs text-muted-foreground", children: props.systemLabels[variable] ?? variable }, path));
|
|
63
63
|
}
|
|
64
64
|
const align = ALIGN_CLASSES[node.getAttribute("data-align") ?? ""];
|
|
65
65
|
const className = cn(TAG_CLASSES[tag], align, node.getAttribute("data-size") === "small" && "text-xs");
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type DocumentFont, type DocumentLayoutValues, type PdfFoldMarks, type PdfTableStyle } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { type MarginSide } from "./pdf-meta.ts";
|
|
1
3
|
export declare const LAYOUT_WIDTHS: readonly [560, 600, 640];
|
|
2
4
|
export declare const LAYOUT_FONTS: readonly ["sans", "serif"];
|
|
3
5
|
export declare const LAYOUT_ACCENT_LINES: readonly ["branding", "none"];
|
|
@@ -27,3 +29,50 @@ export declare function isHexColor(value: string): boolean;
|
|
|
27
29
|
export declare function appearanceOf(meta: LayoutMeta): LayoutAppearance;
|
|
28
30
|
/** Keeps a field that was already stored, even when it now equals the default; drops every other default. */
|
|
29
31
|
export declare function metaToSave(appearance: LayoutAppearance, stored: LayoutMeta): LayoutMeta;
|
|
32
|
+
/** What a pdf-layout stores; every field is optional and a missing one means the renderer default. */
|
|
33
|
+
export type PdfLayoutMeta = {
|
|
34
|
+
readonly margins?: Readonly<Partial<Record<MarginSide, number>>>;
|
|
35
|
+
readonly fontFamily?: DocumentFont;
|
|
36
|
+
readonly fontSizePt?: number;
|
|
37
|
+
readonly textColor?: string;
|
|
38
|
+
readonly tableStyle?: PdfTableStyle;
|
|
39
|
+
readonly tableHeaderBackground?: string;
|
|
40
|
+
readonly tableLineColor?: string;
|
|
41
|
+
readonly foldMarks?: PdfFoldMarks;
|
|
42
|
+
readonly cornerMarks?: boolean;
|
|
43
|
+
readonly paperColor?: string;
|
|
44
|
+
readonly headerOnFirstPage?: boolean;
|
|
45
|
+
readonly footerOnFirstPage?: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** The pdf-layout look as the form edits it: colors stay text while typed, empty means unset. */
|
|
48
|
+
export type PdfLayoutLook = {
|
|
49
|
+
readonly margins: Readonly<Record<MarginSide, number | "">>;
|
|
50
|
+
readonly fontFamily: DocumentFont;
|
|
51
|
+
readonly fontSizePt: number | "";
|
|
52
|
+
readonly textColor: string;
|
|
53
|
+
readonly tableStyle: PdfTableStyle;
|
|
54
|
+
readonly tableHeaderBackground: string;
|
|
55
|
+
readonly tableLineColor: string;
|
|
56
|
+
readonly foldMarks: PdfFoldMarks;
|
|
57
|
+
readonly cornerMarks: boolean;
|
|
58
|
+
readonly paperColor: string;
|
|
59
|
+
readonly headerOnFirstPage: boolean;
|
|
60
|
+
readonly footerOnFirstPage: boolean;
|
|
61
|
+
};
|
|
62
|
+
export declare const PDF_LAYOUT_FONT_SIZE_RANGE: {
|
|
63
|
+
readonly min: 6;
|
|
64
|
+
readonly max: 24;
|
|
65
|
+
};
|
|
66
|
+
export declare const PDF_LAYOUT_MARGIN_RANGE: {
|
|
67
|
+
readonly min: 0;
|
|
68
|
+
readonly max: 100;
|
|
69
|
+
};
|
|
70
|
+
export declare const DEFAULT_PDF_FONT_SIZE_PT = 10.5;
|
|
71
|
+
export declare const DEFAULT_PDF_LAYOUT_LOOK: PdfLayoutLook;
|
|
72
|
+
export declare function pdfLayoutLookOf(meta: PdfLayoutMeta): PdfLayoutLook;
|
|
73
|
+
export declare function isPdfLayoutLookValid(look: PdfLayoutLook): boolean;
|
|
74
|
+
export declare function samePdfLayoutLook(a: PdfLayoutLook, b: PdfLayoutLook): boolean;
|
|
75
|
+
/** Keeps a field that was already stored, even when it now equals the default; drops every other default. */
|
|
76
|
+
export declare function pdfLayoutMetaToSave(look: PdfLayoutLook, stored: PdfLayoutMeta): PdfLayoutMeta;
|
|
77
|
+
/** What the editor toolbar shows as the value a text select inherits. */
|
|
78
|
+
export declare function layoutValuesOf(look: PdfLayoutLook): DocumentLayoutValues;
|
package/dist/web/layout-meta.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HEX_COLOR_PATTERN, MAIL_LAYOUT_ACCENT_LINES, MAIL_LAYOUT_BUTTON_STYLES, MAIL_LAYOUT_FONTS, MAIL_LAYOUT_WIDTHS, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
1
|
+
import { DOCUMENT_FONTS, HEX_COLOR_PATTERN, MAIL_LAYOUT_ACCENT_LINES, MAIL_LAYOUT_BUTTON_STYLES, MAIL_LAYOUT_FONTS, MAIL_LAYOUT_WIDTHS, PDF_DEFAULT_FONT_SIZE_PT, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { MARGIN_SIDES } from "./pdf-meta.js";
|
|
2
3
|
export const LAYOUT_WIDTHS = MAIL_LAYOUT_WIDTHS;
|
|
3
4
|
export const LAYOUT_FONTS = MAIL_LAYOUT_FONTS;
|
|
4
5
|
export const LAYOUT_ACCENT_LINES = MAIL_LAYOUT_ACCENT_LINES;
|
|
@@ -28,3 +29,156 @@ export function metaToSave(appearance, stored) {
|
|
|
28
29
|
...(keep("buttonStyle") && { buttonStyle: appearance.buttonStyle }),
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
export const PDF_LAYOUT_FONT_SIZE_RANGE = { min: 6, max: 24 };
|
|
33
|
+
export const PDF_LAYOUT_MARGIN_RANGE = { min: 0, max: 100 };
|
|
34
|
+
// The renderer's own defaults, so an untouched layout stores nothing.
|
|
35
|
+
export const DEFAULT_PDF_FONT_SIZE_PT = PDF_DEFAULT_FONT_SIZE_PT;
|
|
36
|
+
export const DEFAULT_PDF_LAYOUT_LOOK = {
|
|
37
|
+
margins: { top: "", right: "", bottom: "", left: "" },
|
|
38
|
+
fontFamily: DOCUMENT_FONTS[0],
|
|
39
|
+
fontSizePt: DEFAULT_PDF_FONT_SIZE_PT,
|
|
40
|
+
textColor: "#222222",
|
|
41
|
+
tableStyle: "plain",
|
|
42
|
+
tableHeaderBackground: "",
|
|
43
|
+
tableLineColor: "",
|
|
44
|
+
foldMarks: "none",
|
|
45
|
+
cornerMarks: false,
|
|
46
|
+
paperColor: "",
|
|
47
|
+
headerOnFirstPage: true,
|
|
48
|
+
footerOnFirstPage: true,
|
|
49
|
+
};
|
|
50
|
+
function marginsLookOf(meta) {
|
|
51
|
+
return {
|
|
52
|
+
top: meta.margins?.top ?? "",
|
|
53
|
+
right: meta.margins?.right ?? "",
|
|
54
|
+
bottom: meta.margins?.bottom ?? "",
|
|
55
|
+
left: meta.margins?.left ?? "",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function textLookOf(meta) {
|
|
59
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
60
|
+
return {
|
|
61
|
+
fontFamily: meta.fontFamily ?? defaults.fontFamily,
|
|
62
|
+
fontSizePt: meta.fontSizePt ?? defaults.fontSizePt,
|
|
63
|
+
textColor: meta.textColor ?? defaults.textColor,
|
|
64
|
+
paperColor: meta.paperColor ?? defaults.paperColor,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function tableLookOf(meta) {
|
|
68
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
69
|
+
return {
|
|
70
|
+
tableStyle: meta.tableStyle ?? defaults.tableStyle,
|
|
71
|
+
tableHeaderBackground: meta.tableHeaderBackground ?? defaults.tableHeaderBackground,
|
|
72
|
+
tableLineColor: meta.tableLineColor ?? defaults.tableLineColor,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function pageLookOf(meta) {
|
|
76
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
77
|
+
return {
|
|
78
|
+
foldMarks: meta.foldMarks ?? defaults.foldMarks,
|
|
79
|
+
cornerMarks: meta.cornerMarks ?? defaults.cornerMarks,
|
|
80
|
+
headerOnFirstPage: meta.headerOnFirstPage ?? defaults.headerOnFirstPage,
|
|
81
|
+
footerOnFirstPage: meta.footerOnFirstPage ?? defaults.footerOnFirstPage,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function pdfLayoutLookOf(meta) {
|
|
85
|
+
return {
|
|
86
|
+
margins: marginsLookOf(meta),
|
|
87
|
+
...textLookOf(meta),
|
|
88
|
+
...tableLookOf(meta),
|
|
89
|
+
...pageLookOf(meta),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function inRange(value, range) {
|
|
93
|
+
return value >= range.min && value <= range.max;
|
|
94
|
+
}
|
|
95
|
+
export function isPdfLayoutLookValid(look) {
|
|
96
|
+
return (isHexColor(look.textColor) &&
|
|
97
|
+
(look.tableHeaderBackground === "" || isHexColor(look.tableHeaderBackground)) &&
|
|
98
|
+
(look.tableLineColor === "" || isHexColor(look.tableLineColor)) &&
|
|
99
|
+
(look.paperColor === "" || isHexColor(look.paperColor)) &&
|
|
100
|
+
(look.fontSizePt === "" || inRange(look.fontSizePt, PDF_LAYOUT_FONT_SIZE_RANGE)) &&
|
|
101
|
+
MARGIN_SIDES.every((side) => {
|
|
102
|
+
const mm = look.margins[side];
|
|
103
|
+
return mm === "" || inRange(mm, PDF_LAYOUT_MARGIN_RANGE);
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
export function samePdfLayoutLook(a, b) {
|
|
107
|
+
return (MARGIN_SIDES.every((side) => a.margins[side] === b.margins[side]) &&
|
|
108
|
+
a.fontFamily === b.fontFamily &&
|
|
109
|
+
a.fontSizePt === b.fontSizePt &&
|
|
110
|
+
a.textColor === b.textColor &&
|
|
111
|
+
a.tableStyle === b.tableStyle &&
|
|
112
|
+
a.tableHeaderBackground === b.tableHeaderBackground &&
|
|
113
|
+
a.tableLineColor === b.tableLineColor &&
|
|
114
|
+
a.foldMarks === b.foldMarks &&
|
|
115
|
+
a.cornerMarks === b.cornerMarks &&
|
|
116
|
+
a.paperColor === b.paperColor &&
|
|
117
|
+
a.headerOnFirstPage === b.headerOnFirstPage &&
|
|
118
|
+
a.footerOnFirstPage === b.footerOnFirstPage);
|
|
119
|
+
}
|
|
120
|
+
function marginsMetaToSave(look) {
|
|
121
|
+
const margins = {};
|
|
122
|
+
for (const side of MARGIN_SIDES) {
|
|
123
|
+
const mm = look.margins[side];
|
|
124
|
+
if (mm !== "")
|
|
125
|
+
margins[side] = mm;
|
|
126
|
+
}
|
|
127
|
+
return Object.keys(margins).length > 0 ? { margins } : {};
|
|
128
|
+
}
|
|
129
|
+
function textMetaToSave(look, keep) {
|
|
130
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
131
|
+
return {
|
|
132
|
+
...(keep("fontFamily", look.fontFamily !== defaults.fontFamily) && {
|
|
133
|
+
fontFamily: look.fontFamily,
|
|
134
|
+
}),
|
|
135
|
+
...(look.fontSizePt !== "" &&
|
|
136
|
+
keep("fontSizePt", look.fontSizePt !== defaults.fontSizePt) && {
|
|
137
|
+
fontSizePt: look.fontSizePt,
|
|
138
|
+
}),
|
|
139
|
+
...(keep("textColor", look.textColor !== defaults.textColor) && { textColor: look.textColor }),
|
|
140
|
+
...(look.paperColor !== "" && { paperColor: look.paperColor }),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function tableMetaToSave(look, keep) {
|
|
144
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
145
|
+
return {
|
|
146
|
+
...(keep("tableStyle", look.tableStyle !== defaults.tableStyle) && {
|
|
147
|
+
tableStyle: look.tableStyle,
|
|
148
|
+
}),
|
|
149
|
+
...(look.tableHeaderBackground !== "" && { tableHeaderBackground: look.tableHeaderBackground }),
|
|
150
|
+
...(look.tableLineColor !== "" && { tableLineColor: look.tableLineColor }),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function pageMetaToSave(look, keep) {
|
|
154
|
+
const defaults = DEFAULT_PDF_LAYOUT_LOOK;
|
|
155
|
+
return {
|
|
156
|
+
...(keep("foldMarks", look.foldMarks !== defaults.foldMarks) && { foldMarks: look.foldMarks }),
|
|
157
|
+
...(keep("cornerMarks", look.cornerMarks !== defaults.cornerMarks) && {
|
|
158
|
+
cornerMarks: look.cornerMarks,
|
|
159
|
+
}),
|
|
160
|
+
...(keep("headerOnFirstPage", look.headerOnFirstPage !== defaults.headerOnFirstPage) && {
|
|
161
|
+
headerOnFirstPage: look.headerOnFirstPage,
|
|
162
|
+
}),
|
|
163
|
+
...(keep("footerOnFirstPage", look.footerOnFirstPage !== defaults.footerOnFirstPage) && {
|
|
164
|
+
footerOnFirstPage: look.footerOnFirstPage,
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** Keeps a field that was already stored, even when it now equals the default; drops every other default. */
|
|
169
|
+
export function pdfLayoutMetaToSave(look, stored) {
|
|
170
|
+
const keep = (key, differs) => differs || key in stored;
|
|
171
|
+
return {
|
|
172
|
+
...marginsMetaToSave(look),
|
|
173
|
+
...textMetaToSave(look, keep),
|
|
174
|
+
...tableMetaToSave(look, keep),
|
|
175
|
+
...pageMetaToSave(look, keep),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** What the editor toolbar shows as the value a text select inherits. */
|
|
179
|
+
export function layoutValuesOf(look) {
|
|
180
|
+
return {
|
|
181
|
+
fontFamily: look.fontFamily,
|
|
182
|
+
...(look.fontSizePt !== "" && { fontSizePt: look.fontSizePt }),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -2,12 +2,18 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import { type LayoutAppearance } from "./layout-meta.ts";
|
|
3
3
|
import type { BrandingView, LayoutKind, LayoutValidation } from "./layout-types.ts";
|
|
4
4
|
import type { OverviewRowView } from "./overview-row.ts";
|
|
5
|
+
export declare function ColorSwatch({ color }: {
|
|
6
|
+
readonly color: string;
|
|
7
|
+
}): ReactNode;
|
|
5
8
|
export declare function BrandingRail({ data, unavailable, }: {
|
|
6
9
|
readonly data: BrandingView | null;
|
|
7
10
|
readonly unavailable: boolean;
|
|
8
11
|
}): ReactNode;
|
|
9
|
-
export declare function PlaceholderRail({ validation, }: {
|
|
12
|
+
export declare function PlaceholderRail({ validation, isMail, regionsHtml, }: {
|
|
10
13
|
readonly validation: LayoutValidation | null;
|
|
14
|
+
readonly isMail: boolean;
|
|
15
|
+
/** The validation never lists system placeholders as used, so the rail reads the regions itself. */
|
|
16
|
+
readonly regionsHtml: string;
|
|
11
17
|
}): ReactNode;
|
|
12
18
|
export declare function RendererRail({ kind }: {
|
|
13
19
|
readonly kind: LayoutKind;
|
package/dist/web/layout-rails.js
CHANGED
|
@@ -4,6 +4,7 @@ import { BRANDING_SCREEN_QN, MANAGED_PAGES_FEATURE_NAME } from "./constants.js";
|
|
|
4
4
|
import { isHexColor, LAYOUT_ACCENT_LINES, LAYOUT_BUTTON_STYLES, LAYOUT_FONTS, LAYOUT_WIDTHS, } from "./layout-meta.js";
|
|
5
5
|
import { layoutUsers } from "./layout-users.js";
|
|
6
6
|
import { PLACEHOLDER_SYMBOL, SYSTEM_PLACEHOLDER_TYPE, systemPlaceholderLabel, } from "./mail-draft.js";
|
|
7
|
+
import { placeholdersUsedIn, railSystemPlaceholders } from "./pdf-left-rail.js";
|
|
7
8
|
import { RailField, RailHint, RailRow, RailSection } from "./rail.js";
|
|
8
9
|
import { statusLabel } from "./status-label.js";
|
|
9
10
|
import { templateTitleText } from "./used-by-label.js";
|
|
@@ -16,8 +17,8 @@ function hostOf(siteUrl) {
|
|
|
16
17
|
return siteUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
17
18
|
}
|
|
18
19
|
// The color is user data, so it goes into a style attribute instead of a class.
|
|
19
|
-
function ColorSwatch({ color }) {
|
|
20
|
-
return (_jsx("span", { "data-testid": "document-designer-accent-swatch", className: "inline-block size-3.5 shrink-0 rounded-sm border", style: { backgroundColor: color } }));
|
|
20
|
+
export function ColorSwatch({ color }) {
|
|
21
|
+
return (_jsx("span", { "data-testid": "document-designer-accent-swatch", className: "inline-block size-3.5 shrink-0 rounded-sm border border-foreground/30", style: { backgroundColor: color } }));
|
|
21
22
|
}
|
|
22
23
|
export function BrandingRail({ data, unavailable, }) {
|
|
23
24
|
const t = useTranslation();
|
|
@@ -40,10 +41,14 @@ export function BrandingRail({ data, unavailable, }) {
|
|
|
40
41
|
: notSet;
|
|
41
42
|
return (_jsxs(RailSection, { title: t("documentDesigner.branding.title"), action: editLink, testId: "document-designer-branding", children: [_jsx(RailRow, { label: t("documentDesigner.branding.productName"), trailing: value(data?.title) }), _jsx(RailRow, { label: t("documentDesigner.branding.accentColor"), trailing: isHexColor(accent) ? (_jsxs("span", { className: "inline-flex items-center gap-1.5", children: [_jsx(ColorSwatch, { color: accent }), _jsx("code", { children: accent })] })) : (value(accent)) }), _jsx(RailRow, { label: t("documentDesigner.branding.logo"), trailing: logo }), _jsx(RailRow, { label: t("documentDesigner.branding.website"), trailing: data?.siteUrl === undefined || data.siteUrl === "" ? notSet : hostOf(data.siteUrl) }), _jsx(RailHint, { children: t("documentDesigner.branding.hint") })] }));
|
|
42
43
|
}
|
|
43
|
-
export function PlaceholderRail({ validation, }) {
|
|
44
|
+
export function PlaceholderRail({ validation, isMail, regionsHtml, }) {
|
|
44
45
|
const t = useTranslation();
|
|
45
|
-
const
|
|
46
|
-
|
|
46
|
+
const systemPlaceholders = validation?.systemPlaceholders ?? [];
|
|
47
|
+
const used = new Set([
|
|
48
|
+
...(validation?.used ?? []),
|
|
49
|
+
...placeholdersUsedIn(regionsHtml, systemPlaceholders),
|
|
50
|
+
]);
|
|
51
|
+
return (_jsxs(RailSection, { title: t("documentDesigner.layoutPlaceholders.title"), testId: "document-designer-placeholders", children: [_jsx(RailRow, { symbol: "\u229E", label: t("documentDesigner.placeholders.content"), required: true, trailing: "\u2713", trailingTone: "ok" }), (isMail ? systemPlaceholders : railSystemPlaceholders(systemPlaceholders)).map((name) => (_jsx(RailRow, { testId: `document-designer-placeholder-${name}`, symbol: PLACEHOLDER_SYMBOL[SYSTEM_PLACEHOLDER_TYPE[name] ?? "text"], label: systemPlaceholderLabel(t, name), trailing: used.has(name) ? "✓" : "–", trailingTone: used.has(name) ? "ok" : "muted" }, name)))] }));
|
|
47
52
|
}
|
|
48
53
|
// Both renderers always run for their kind; the rows say which one produces the output.
|
|
49
54
|
export function RendererRail({ kind }) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LayoutMeta } from "./layout-meta.ts";
|
|
1
|
+
import type { LayoutMeta, PdfLayoutMeta } from "./layout-meta.ts";
|
|
2
2
|
import type { ServedVersionView } from "./types.ts";
|
|
3
3
|
export type LayoutKind = "mail-layout" | "pdf-layout";
|
|
4
4
|
export type ValidationIssue = {
|
|
@@ -61,6 +61,6 @@ export type LayoutSourceView = {
|
|
|
61
61
|
};
|
|
62
62
|
readonly effectiveFormat: "html" | "mjml" | null;
|
|
63
63
|
readonly mjmlSource: string | null;
|
|
64
|
-
readonly meta: LayoutMeta;
|
|
64
|
+
readonly meta: LayoutMeta & PdfLayoutMeta;
|
|
65
65
|
readonly locale: string;
|
|
66
66
|
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TemplateResolverQueries } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
|
+
import { dispatcherErrorText, usePrimitives, useQuery, useTranslation, } from "@cosmicdrift/kumiko-renderer";
|
|
4
|
+
import { pluralKey } from "@cosmicdrift/kumiko-renderer/headless";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { ApplyLayoutDialog } from "./apply-layout-dialog.js";
|
|
7
|
+
import { RailHint, RailSection } from "./rail.js";
|
|
8
|
+
import { statusLabel } from "./status-label.js";
|
|
9
|
+
import { DOCUMENT_PDF_KIND } from "./types.js";
|
|
10
|
+
import { templateOutcomeText, useApplyLayout } from "./use-apply-layout.js";
|
|
11
|
+
import { useOverviewRows } from "./use-overview-rows.js";
|
|
12
|
+
import { templateTitle, templateTitleText } from "./used-by-label.js";
|
|
13
|
+
const PDF_LAYOUT_KIND = "pdf-layout";
|
|
14
|
+
function groupByTemplate(users) {
|
|
15
|
+
const bySlug = new Map();
|
|
16
|
+
for (const user of users)
|
|
17
|
+
bySlug.set(user.slug, [...(bySlug.get(user.slug) ?? []), user]);
|
|
18
|
+
return [...bySlug.entries()].flatMap(([slug, group]) => {
|
|
19
|
+
const [first] = group;
|
|
20
|
+
return first === undefined
|
|
21
|
+
? []
|
|
22
|
+
: [
|
|
23
|
+
{
|
|
24
|
+
slug,
|
|
25
|
+
first,
|
|
26
|
+
draft: group.find((user) => user.status === "draft"),
|
|
27
|
+
draftLocales: group
|
|
28
|
+
.filter((user) => user.status === "draft")
|
|
29
|
+
.map((user) => user.locale),
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function LayoutUsageSection({ slug }) {
|
|
35
|
+
const t = useTranslation();
|
|
36
|
+
const { Button, Banner } = usePrimitives();
|
|
37
|
+
const { publish } = useApplyLayout();
|
|
38
|
+
const layoutRow = useOverviewRows(PDF_LAYOUT_KIND).rows.find((row) => row.slug === slug);
|
|
39
|
+
const layoutTitle = layoutRow === undefined ? slug : templateTitle(t, layoutRow);
|
|
40
|
+
const [open, setOpen] = useState(false);
|
|
41
|
+
const [failed, setFailed] = useState([]);
|
|
42
|
+
const [error, setError] = useState(null);
|
|
43
|
+
const usage = useQuery(TemplateResolverQueries.usage, { slug, kind: PDF_LAYOUT_KIND });
|
|
44
|
+
const users = usage.data?.usedByTemplates ?? [];
|
|
45
|
+
const drafts = users.filter((user) => user.status === "draft");
|
|
46
|
+
const publishDrafts = async () => {
|
|
47
|
+
setError(null);
|
|
48
|
+
const result = await publish.mutate({
|
|
49
|
+
templates: drafts.map(({ slug: draftSlug, locale }) => ({
|
|
50
|
+
slug: draftSlug,
|
|
51
|
+
locale,
|
|
52
|
+
kind: DOCUMENT_PDF_KIND,
|
|
53
|
+
})),
|
|
54
|
+
});
|
|
55
|
+
if (!result.isSuccess) {
|
|
56
|
+
setError(dispatcherErrorText(result.error, t));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setFailed(result.data.failed);
|
|
60
|
+
void usage.refetch();
|
|
61
|
+
};
|
|
62
|
+
return (_jsxs(RailSection, { title: t("documentDesigner.usedBy.title"), testId: "layout-usage-section", children: [users.length === 0 && _jsx(RailHint, { children: t("documentDesigner.usedBy.none") }), groupByTemplate(users).map(({ slug: groupSlug, first, draft, draftLocales }) => (_jsxs("div", { "data-testid": `layout-usage-${groupSlug}`, className: "flex min-h-10 items-center justify-between gap-2 border-b px-3.5", children: [_jsx("span", { className: "min-w-0 wrap-anywhere text-sm", children: draftLocales.length >= 2
|
|
63
|
+
? `${templateTitleText(t, first.title)} (${draftLocales.join(", ")})`
|
|
64
|
+
: templateTitleText(t, first.title) }), _jsx("span", { className: "shrink-0 text-right text-xs text-muted-foreground", children: draft === undefined
|
|
65
|
+
? statusLabel(t, first.status, first.version)
|
|
66
|
+
: t("documentDesigner.status.draft") })] }, groupSlug))), _jsxs("div", { className: "flex flex-col gap-2 px-3.5 py-2", children: [error !== null && _jsx(Banner, { variant: "error", children: error }), failed.length > 0 && (_jsxs(Banner, { variant: "error", children: [_jsx("strong", { children: t("documentDesigner.applyLayout.failed") }), _jsx("ul", { className: "list-disc pl-5", children: failed.map((item) => (_jsx("li", { children: templateOutcomeText(t, item) }, `${item.slug}:${item.locale}`))) })] })), drafts.length > 0 && _jsx(RailHint, { children: t("documentDesigner.usedBy.publishHint") }), drafts.length > 0 && (_jsx(Button, { size: "sm", disabled: publish.pending, loading: publish.pending, onClick: publishDrafts, testId: "layout-usage-publish", children: t(pluralKey("documentDesigner.applyLayout.publish", drafts.length), {
|
|
67
|
+
count: drafts.length,
|
|
68
|
+
}) })), _jsx(Button, { variant: "secondary", size: "sm", onClick: () => setOpen(true), testId: "layout-apply-open", children: t("documentDesigner.applyLayout.open") })] }), open && (_jsx(ApplyLayoutDialog, { layoutSlug: slug, layoutTitle: layoutTitle, onOpenChange: setOpen, onApplied: () => {
|
|
69
|
+
void usage.refetch();
|
|
70
|
+
} }))] }));
|
|
71
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { type DocumentEditorHandle, type DocumentResourcePreview } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
1
|
+
import { type DocumentEditorHandle, type DocumentFrameControl, type DocumentResourcePreview } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { type PdfLayoutMeta } from "./layout-meta.ts";
|
|
4
|
+
import type { PdfMetaDraft } from "./pdf-meta.ts";
|
|
4
5
|
import type { LayoutRegionsHtml } from "./types.ts";
|
|
5
6
|
export type PageCanvasProps = {
|
|
6
7
|
readonly meta: PdfMetaDraft;
|
|
8
|
+
readonly layoutMeta: PdfLayoutMeta;
|
|
7
9
|
readonly content: string;
|
|
8
10
|
readonly onContentChange: (value: string) => void;
|
|
9
11
|
readonly regions: LayoutRegionsHtml | null;
|
|
@@ -15,6 +17,7 @@ export type PageCanvasProps = {
|
|
|
15
17
|
readonly imageVariables: readonly string[];
|
|
16
18
|
readonly resourcePreviews: Readonly<Record<string, DocumentResourcePreview>>;
|
|
17
19
|
readonly onEditorReady: (handle: DocumentEditorHandle | null) => void;
|
|
20
|
+
readonly onFrameControlChange: (control: DocumentFrameControl | null) => void;
|
|
18
21
|
readonly resourceSrc?: (key: string) => string | undefined;
|
|
19
22
|
};
|
|
20
23
|
export declare function PageCanvas(props: PageCanvasProps): ReactNode;
|
package/dist/web/page-canvas.js
CHANGED
|
@@ -1,47 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DocumentContentEditor,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentContentEditor, PDF_DOCUMENT_BLOCKS, } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
3
3
|
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
4
|
-
import { cn } from "@cosmicdrift/kumiko-renderer/web";
|
|
5
|
-
import { useCallback } from "react";
|
|
6
4
|
import { LayoutHtml } from "./layout-html.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const PAGE_WIDTH_CLASSES = {
|
|
11
|
-
"A4-portrait": "max-w-[794px]",
|
|
12
|
-
"A4-landscape": "max-w-[1123px]",
|
|
13
|
-
"Letter-portrait": "max-w-[816px]",
|
|
14
|
-
"Letter-landscape": "max-w-[1056px]",
|
|
15
|
-
};
|
|
5
|
+
import { layoutValuesOf, pdfLayoutLookOf } from "./layout-meta.js";
|
|
6
|
+
import { layoutRegionFlags, paperLookOf, paperSizeMm, resolveMarginsMm } from "./paper-geometry.js";
|
|
7
|
+
import { PaperSheet } from "./paper-sheet.js";
|
|
16
8
|
function RegionBlock({ html, systemLabels, resourceSrc, caption, }) {
|
|
17
9
|
if (html.trim() === "")
|
|
18
10
|
return null;
|
|
19
|
-
return (_jsxs("div", { className: "relative border border-dashed border-border bg-muted/40 p-2 pt-4 text-
|
|
11
|
+
return (_jsxs("div", { className: "relative border border-dashed border-border bg-muted/40 p-2 pt-4 text-muted-foreground", children: [_jsx("span", { className: "absolute left-2 top-0.5 text-[10px] uppercase tracking-wide", children: caption }), _jsx(LayoutHtml, { html: html, systemLabels: systemLabels, ...(resourceSrc !== undefined && { resourceSrc }) })] }));
|
|
20
12
|
}
|
|
21
13
|
// The letterhead is a band across the whole paper, outside the page margins, like on printed letter paper.
|
|
22
14
|
function HeaderBand({ html, systemLabels, resourceSrc, caption, }) {
|
|
23
|
-
return (_jsxs("div", { className: "
|
|
15
|
+
return (_jsxs("div", { className: "absolute inset-x-0 top-0 min-h-(--paper-margin-top) border-b border-border bg-muted pt-[calc(4*var(--paper-mm))] pr-(--paper-margin-right) pb-[calc(2*var(--paper-mm))] pl-(--paper-margin-left) text-(length:--paper-font-size) text-foreground [&_td]:border-0! [&_th]:border-0! [&_p]:text-[length:inherit] [&_p]:leading-[inherit] [&_td]:align-top [&_td:last-child]:whitespace-nowrap", "data-testid": "document-designer-letterhead", children: [_jsx("span", { className: "absolute right-(--paper-margin-right) top-0.5 text-[9px] leading-none uppercase tracking-wide text-muted-foreground", children: caption }), _jsx(LayoutHtml, { html: html, systemLabels: systemLabels, ...(resourceSrc !== undefined && { resourceSrc }) })] }));
|
|
16
|
+
}
|
|
17
|
+
// Anchored to the bottom of page 1 (not the paper end: the sheet grows with long content), like the PDF footer region.
|
|
18
|
+
function FooterBand({ html, systemLabels, resourceSrc, caption, }) {
|
|
19
|
+
return (_jsxs("div", { className: "absolute inset-x-0 top-(--paper-height) flex min-h-(--paper-margin-bottom) -translate-y-full flex-col border-t border-border bg-muted pt-[calc(1.5*var(--paper-mm))] pr-(--paper-margin-right) pb-[calc(2*var(--paper-mm))] pl-(--paper-margin-left) text-(length:--paper-font-size) text-foreground [&_td]:border-0! [&_th]:border-0! [&_p]:text-[length:inherit] [&_p]:leading-[inherit] [&_td]:align-top [&_td:last-child]:whitespace-nowrap", "data-testid": "document-designer-footer-band", children: [_jsx("span", { className: "mb-[calc(1*var(--paper-mm))] block text-[10px] leading-none uppercase tracking-wide text-muted-foreground", children: caption }), _jsx("div", { className: "mt-auto", children: _jsx(LayoutHtml, { html: html, systemLabels: systemLabels, ...(resourceSrc !== undefined && { resourceSrc }) }) })] }));
|
|
24
20
|
}
|
|
25
21
|
export function PageCanvas(props) {
|
|
26
22
|
const t = useTranslation();
|
|
27
23
|
const { meta } = props;
|
|
28
|
-
const showRegions = meta.layoutHeaderFooter
|
|
29
|
-
// The letterhead band
|
|
30
|
-
const showLetterhead =
|
|
31
|
-
|
|
32
|
-
const
|
|
24
|
+
const { showRegions, hasHeader, hasFooter } = layoutRegionFlags(meta.layoutHeaderFooter, props.regions);
|
|
25
|
+
// The letterhead band overlays the top margin; it never pushes the content down.
|
|
26
|
+
const showLetterhead = hasHeader;
|
|
27
|
+
const size = paperSizeMm(meta.pageFormat, meta.orientation);
|
|
28
|
+
const margins = resolveMarginsMm({
|
|
29
|
+
template: meta.margins,
|
|
30
|
+
layout: props.layoutMeta.margins ?? {},
|
|
31
|
+
hasHeader,
|
|
32
|
+
hasFooter,
|
|
33
|
+
});
|
|
33
34
|
const fromLayout = t("documentDesigner.canvas.fromLayout", { layout: props.layoutName });
|
|
34
35
|
const regionCaption = (region) => `${t(`documentDesigner.editor.region.${region}`)} · ${fromLayout}`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (element === null)
|
|
38
|
-
return;
|
|
39
|
-
for (const side of MARGIN_SIDES) {
|
|
40
|
-
const fallbackMm = side === "bottom" && hasFooter ? PDF_FOOTER_MARGIN_MM : PDF_DEFAULT_MARGIN_MM;
|
|
41
|
-
const mm = meta.margins[side] === "" ? fallbackMm : meta.margins[side];
|
|
42
|
-
element.style.setProperty(`--page-margin-${side}`, `${Math.round(mm * MM_TO_PX)}px`);
|
|
43
|
-
}
|
|
44
|
-
}, [meta.margins, hasFooter]);
|
|
45
|
-
const renderPaper = (editable) => (_jsxs("div", { className: "flex w-full flex-col items-center gap-2", children: [_jsxs("div", { "data-testid": "document-designer-page", className: cn("flex min-h-[1000px] w-full flex-col bg-card shadow-md", PAGE_WIDTH_CLASSES[`${meta.pageFormat}-${meta.orientation}`]), children: [showLetterhead && props.regions !== null && (_jsx(HeaderBand, { html: props.regions.header, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: fromLayout })), _jsxs("div", { ref: applyMargins, className: cn("flex min-h-0 flex-1 flex-col pr-(--page-margin-right) pb-(--page-margin-bottom) pl-(--page-margin-left)", !showLetterhead && "pt-(--page-margin-top)"), children: [_jsxs("div", { className: "relative my-2 min-h-0 flex-1 border border-dashed border-primary/40 p-2 pt-5", "data-testid": "document-designer-content-area", children: [_jsx("span", { className: "absolute left-2 top-0.5 text-[10px] uppercase tracking-wide text-primary", children: t("documentDesigner.editor.region.content") }), editable] }), showRegions && props.regions !== null && (_jsxs(_Fragment, { children: [_jsx(RegionBlock, { html: props.regions.signature, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: regionCaption("signature") }), _jsx(RegionBlock, { html: props.regions.footer, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: regionCaption("footer") })] }))] })] }), _jsx("p", { className: "text-xs text-muted-foreground", children: t("documentDesigner.canvas.caption", { format: meta.pageFormat }) })] }));
|
|
46
|
-
return (_jsx("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", "data-testid": "pdf-editor-center", children: _jsx(DocumentContentEditor, { id: "document-designer-content", value: props.content, onChange: props.onContentChange, variables: props.variableNames, imageVariables: props.imageVariables, readOnly: false, blocks: PDF_DOCUMENT_BLOCKS, variableLabels: props.variableLabels, systemVariables: props.systemVariables, resourcePreviews: props.resourcePreviews, chrome: "canvas", renderPaper: renderPaper, onEditorReady: props.onEditorReady }) }));
|
|
36
|
+
const renderPaper = (editable) => (_jsxs("div", { className: "flex w-full flex-col items-center gap-2", children: [_jsxs(PaperSheet, { size: size, margins: margins, look: paperLookOf(pdfLayoutLookOf(props.layoutMeta)), testId: "document-designer-page", children: [showLetterhead && props.regions !== null && (_jsx(HeaderBand, { html: props.regions.header, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: fromLayout })), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col pt-(--paper-margin-top) pr-(--paper-margin-right) pb-(--paper-margin-bottom) pl-(--paper-margin-left)", children: [_jsxs("div", { className: "min-h-0 flex-1 outline-1 outline-dashed outline-primary/40 outline-offset-4", "data-testid": "document-designer-content-area", children: [_jsx("span", { className: "absolute top-[calc(var(--paper-margin-top)-0.75rem)] left-[calc(var(--paper-margin-left)+0.5rem)] z-10 bg-card px-1.5 text-[10px] leading-none uppercase tracking-wide text-primary", children: t("documentDesigner.editor.region.content") }), editable] }), showRegions && props.regions !== null && (_jsx(RegionBlock, { html: props.regions.signature, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: regionCaption("signature") }))] }), hasFooter && props.regions !== null && (_jsx(FooterBand, { html: props.regions.footer, systemLabels: props.systemLabels, resourceSrc: props.resourceSrc, caption: fromLayout }))] }), _jsx("p", { className: "text-xs text-muted-foreground", children: t("documentDesigner.canvas.caption", { format: meta.pageFormat }) })] }));
|
|
37
|
+
return (_jsx("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", "data-testid": "pdf-editor-center", children: _jsx(DocumentContentEditor, { id: "document-designer-content", value: props.content, onChange: props.onContentChange, variables: props.variableNames, imageVariables: props.imageVariables, readOnly: false, blocks: PDF_DOCUMENT_BLOCKS, variableLabels: props.variableLabels, systemVariables: props.systemVariables, resourcePreviews: props.resourcePreviews, chrome: "canvas", renderPaper: renderPaper, layoutValues: layoutValuesOf(pdfLayoutLookOf(props.layoutMeta)), onEditorReady: props.onEditorReady, onFrameControlChange: props.onFrameControlChange }) }));
|
|
47
38
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { applyCssVariables, percentOfExtent, rulerHalfMarks, rulerMarks, } from "./paper-geometry.js";
|
|
3
|
+
const ZONE_EDGE_CLASS = {
|
|
4
|
+
left: "inset-y-0 left-0 w-(--ruler-extent)",
|
|
5
|
+
right: "inset-y-0 right-0 w-(--ruler-extent)",
|
|
6
|
+
top: "inset-x-0 top-0 h-(--ruler-extent)",
|
|
7
|
+
bottom: "inset-x-0 bottom-0 h-(--ruler-extent)",
|
|
8
|
+
};
|
|
9
|
+
function MarginZone({ side, percent, }) {
|
|
10
|
+
return (_jsx("div", { "data-testid": `page-ruler-margin-${side}`, className: `absolute bg-status-warn/20 ${ZONE_EDGE_CLASS[side]}`, ref: (element) => applyCssVariables(element, { "--ruler-extent": `${percent}%` }) }));
|
|
11
|
+
}
|
|
12
|
+
function RulerTick({ cm, percent, axis, }) {
|
|
13
|
+
const horizontal = axis === "horizontal";
|
|
14
|
+
return (_jsxs("span", { "data-ruler-cm": cm, className: horizontal
|
|
15
|
+
? "absolute inset-y-0 left-(--ruler-at) w-0"
|
|
16
|
+
: "absolute inset-x-0 top-(--ruler-at) h-0", ref: (element) => applyCssVariables(element, { "--ruler-at": `${percent}%` }), children: [_jsx("span", { className: horizontal
|
|
17
|
+
? "absolute top-0.5 left-0 -translate-x-1/2 leading-none"
|
|
18
|
+
: "absolute top-0 left-0.5 -translate-y-1/2 leading-none", children: cm }), _jsx("span", { className: horizontal
|
|
19
|
+
? "absolute bottom-0 left-0 h-1.5 border-l border-muted-foreground/70"
|
|
20
|
+
: "absolute top-0 right-0 w-1.5 border-t border-muted-foreground/70" })] }));
|
|
21
|
+
}
|
|
22
|
+
function RulerHalfTick({ mm, percent, axis, }) {
|
|
23
|
+
return (_jsx("span", { "data-ruler-half": mm, className: axis === "horizontal"
|
|
24
|
+
? "absolute bottom-0 left-(--ruler-at) h-1 border-l border-muted-foreground/40"
|
|
25
|
+
: "absolute top-(--ruler-at) right-0 w-1 border-t border-muted-foreground/40", ref: (element) => applyCssVariables(element, { "--ruler-at": `${percent}%` }) }));
|
|
26
|
+
}
|
|
27
|
+
function RulerMarks({ extentMm, axis, }) {
|
|
28
|
+
return (_jsxs(_Fragment, { children: [rulerHalfMarks(extentMm).map((mark) => (_jsx(RulerHalfTick, { mm: mark.mm, percent: mark.percent, axis: axis }, mark.mm))), rulerMarks(extentMm).map((mark) => (_jsx(RulerTick, { cm: mark.cm, percent: mark.percent, axis: axis }, mark.cm)))] }));
|
|
29
|
+
}
|
|
30
|
+
// A child of the paper wrapper: its percentages are the paper's, so it scales with the page.
|
|
31
|
+
export function PageRuler({ size, margins, }) {
|
|
32
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { "data-testid": "page-ruler-top", "aria-hidden": "true", className: "pointer-events-none absolute -top-4 right-0 left-0 h-4 select-none overflow-hidden border-b bg-muted text-[9px] text-muted-foreground", children: [_jsx(MarginZone, { side: "left", percent: percentOfExtent(margins.left, size.widthMm) }), _jsx(MarginZone, { side: "right", percent: percentOfExtent(margins.right, size.widthMm) }), _jsx(RulerMarks, { extentMm: size.widthMm, axis: "horizontal" })] }), _jsxs("div", { "data-testid": "page-ruler-left", "aria-hidden": "true", className: "pointer-events-none absolute top-0 -left-4 h-(--paper-height) w-4 select-none overflow-hidden border-r bg-muted text-[9px] text-muted-foreground", children: [_jsx(MarginZone, { side: "top", percent: percentOfExtent(margins.top, size.heightMm) }), _jsx(MarginZone, { side: "bottom", percent: percentOfExtent(margins.bottom, size.heightMm) }), _jsx(RulerMarks, { extentMm: size.heightMm, axis: "vertical" })] })] }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type PdfFoldMarks, type PdfTableStyle } from "@cosmicdrift/kumiko-bundled-features/template-resolver/web";
|
|
2
|
+
import { type PdfLayoutLook } from "./layout-meta.ts";
|
|
3
|
+
import { type MarginSide, type Orientation, type PageFormat } from "./pdf-meta.ts";
|
|
4
|
+
import type { LayoutRegionsHtml } from "./types.ts";
|
|
5
|
+
export type PaperSize = {
|
|
6
|
+
readonly widthMm: number;
|
|
7
|
+
readonly heightMm: number;
|
|
8
|
+
};
|
|
9
|
+
export type MarginsMm = Readonly<Record<MarginSide, number>>;
|
|
10
|
+
export type PartialMarginsMm = Readonly<Partial<Record<MarginSide, number>>>;
|
|
11
|
+
export type MarginInput = Readonly<Record<MarginSide, number | "">>;
|
|
12
|
+
export declare function paperSizeMm(format: PageFormat, orientation: Orientation): PaperSize;
|
|
13
|
+
export declare function paperWidthPt(size: PaperSize): number;
|
|
14
|
+
export declare const EMPTY_MARGIN_INPUT: MarginInput;
|
|
15
|
+
export declare function resolveMarginsMm(input: {
|
|
16
|
+
readonly template: MarginInput;
|
|
17
|
+
readonly layout: PartialMarginsMm;
|
|
18
|
+
readonly hasHeader: boolean;
|
|
19
|
+
readonly hasFooter: boolean;
|
|
20
|
+
}): MarginsMm;
|
|
21
|
+
export declare function layoutRegionFlags(layoutHeaderFooter: boolean, regions: LayoutRegionsHtml | null): {
|
|
22
|
+
readonly showRegions: boolean;
|
|
23
|
+
readonly hasHeader: boolean;
|
|
24
|
+
readonly hasFooter: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare function percentOfExtent(mm: number, extentMm: number): number;
|
|
27
|
+
export type RulerMark = {
|
|
28
|
+
readonly cm: number;
|
|
29
|
+
readonly percent: number;
|
|
30
|
+
};
|
|
31
|
+
export declare function rulerMarks(extentMm: number): readonly RulerMark[];
|
|
32
|
+
export type RulerHalfMark = {
|
|
33
|
+
readonly mm: number;
|
|
34
|
+
readonly percent: number;
|
|
35
|
+
};
|
|
36
|
+
export declare function rulerHalfMarks(extentMm: number): readonly RulerHalfMark[];
|
|
37
|
+
export type PaperLook = {
|
|
38
|
+
readonly tableStyle: PdfTableStyle;
|
|
39
|
+
readonly fontStack: string | null;
|
|
40
|
+
readonly fontSizePt: number;
|
|
41
|
+
readonly textColor: string | null;
|
|
42
|
+
readonly tableHeaderBackground: string | null;
|
|
43
|
+
readonly tableLineColor: string | null;
|
|
44
|
+
readonly foldMarks: PdfFoldMarks;
|
|
45
|
+
readonly cornerMarks: boolean;
|
|
46
|
+
readonly paperColor: string | null;
|
|
47
|
+
};
|
|
48
|
+
export type FoldMarkLine = {
|
|
49
|
+
readonly topMm: number;
|
|
50
|
+
readonly lengthMm: number;
|
|
51
|
+
};
|
|
52
|
+
export declare function foldMarkLines(foldMarks: PdfFoldMarks): readonly FoldMarkLine[];
|
|
53
|
+
export declare const CORNER_MARK_PLACEMENTS: readonly [{
|
|
54
|
+
readonly vertical: "top";
|
|
55
|
+
readonly horizontal: "left";
|
|
56
|
+
}, {
|
|
57
|
+
readonly vertical: "top";
|
|
58
|
+
readonly horizontal: "right";
|
|
59
|
+
}, {
|
|
60
|
+
readonly vertical: "bottom";
|
|
61
|
+
readonly horizontal: "left";
|
|
62
|
+
}, {
|
|
63
|
+
readonly vertical: "bottom";
|
|
64
|
+
readonly horizontal: "right";
|
|
65
|
+
}];
|
|
66
|
+
export declare function paperVariables(input: {
|
|
67
|
+
readonly size: PaperSize;
|
|
68
|
+
readonly margins: MarginsMm;
|
|
69
|
+
readonly look: PaperLook;
|
|
70
|
+
}): Readonly<Record<string, string>>;
|
|
71
|
+
export declare function applyCssVariables(element: HTMLElement | null, variables: Readonly<Record<string, string>>): void;
|
|
72
|
+
export declare function paperLookOf(look: PdfLayoutLook): PaperLook;
|