@cosmicdrift/kumiko-bundled-features 0.419.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/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/shared/tenant-scoped-subject.d.ts +11 -0
- package/dist/shared/tenant-scoped-subject.js +18 -0
- package/dist/signature/feature.js +1 -1
- package/dist/signature/grant.d.ts +1 -1
- package/dist/signature/grant.js +7 -12
- package/dist/signature/png.js +35 -10
- package/dist/template-resolver/api.d.ts +2 -0
- package/dist/template-resolver/api.js +11 -7
- package/dist/template-resolver/compile-document-body.js +6 -5
- package/dist/template-resolver/compile-document-styles.js +42 -4
- package/dist/template-resolver/document-frames.d.ts +1 -0
- package/dist/template-resolver/document-frames.js +39 -2
- package/dist/template-resolver/document-op-blocks.d.ts +258 -24
- package/dist/template-resolver/document-op-blocks.js +111 -20
- package/dist/template-resolver/document-ops.d.ts +1030 -96
- package/dist/template-resolver/document-ops.js +32 -3
- package/dist/template-resolver/document-print-only.d.ts +2 -1
- package/dist/template-resolver/document-print-only.js +23 -0
- package/dist/template-resolver/document-sanitizer.d.ts +1 -1
- package/dist/template-resolver/document-sanitizer.js +6 -1
- package/dist/template-resolver/handlers/create-layout.write.js +1 -1
- package/dist/template-resolver/handlers/patch-draft.write.d.ts +512 -48
- package/dist/template-resolver/handlers/patch-draft.write.js +2 -1
- package/dist/template-resolver/handlers/tenant-settings.d.ts +7 -1
- package/dist/template-resolver/handlers/tenant-settings.js +25 -15
- package/dist/template-resolver/index.d.ts +3 -3
- package/dist/template-resolver/index.js +3 -3
- package/dist/template-resolver/template-meta.d.ts +10 -0
- package/dist/template-resolver/template-meta.js +7 -1
- package/dist/template-resolver/template-preview.js +16 -4
- package/dist/template-resolver/web/constants.d.ts +1 -1
- package/dist/template-resolver/web/constants.js +1 -1
- package/dist/template-resolver/web/document-editor-extensions.js +44 -19
- package/dist/template-resolver/web/document-editor.js +3 -1
- package/dist/template-resolver/web/document-print-decorations.js +53 -6
- package/dist/template-resolver/web/document-print-style.d.ts +81 -2
- package/dist/template-resolver/web/document-print-style.js +114 -2
- package/dist/template-resolver/web/document-repeat-strip.js +2 -26
- package/dist/template-resolver/web/document-schema.d.ts +5 -0
- package/dist/template-resolver/web/document-schema.js +50 -13
- package/dist/template-resolver/web/document-style-css.d.ts +35 -2
- package/dist/template-resolver/web/document-style-css.js +65 -1
- package/dist/template-resolver/web/document-tiptap-bubble.js +71 -8
- package/dist/template-resolver/web/document-tiptap-content.d.ts +1 -1
- package/dist/template-resolver/web/document-tiptap-content.js +5 -2
- package/dist/template-resolver/web/document-tiptap-editor.d.ts +1 -1
- package/dist/template-resolver/web/document-tiptap-editor.js +2 -2
- package/dist/template-resolver/web/document-tiptap-helpers.d.ts +32 -2
- package/dist/template-resolver/web/document-tiptap-helpers.js +99 -24
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.d.ts +11 -0
- package/dist/template-resolver/web/document-tiptap-toolbar-groups.js +41 -3
- package/dist/template-resolver/web/document-tiptap-toolbar.js +13 -8
- package/dist/template-resolver/web/i18n.js +2 -0
- package/dist/template-resolver/web/index.d.ts +1 -1
- package/dist/template-resolver/web/index.js +1 -1
- package/dist/template-resolver/web/pdf-constants.d.ts +5 -0
- package/dist/template-resolver/web/pdf-constants.js +6 -0
- package/dist/template-resolver/web/placeholder-text.d.ts +2 -1
- package/dist/template-resolver/web/placeholder-text.js +5 -2
- package/package.json +19 -11
- package/src/signature/changes.json +6 -0
- package/src/template-resolver/changes.json +24 -0
package/dist/shared/index.d.ts
CHANGED
|
@@ -48,5 +48,6 @@ export { createSearchBucketCleanup, type DerivedStateMode, rebuildAndReindex, ty
|
|
|
48
48
|
export type { SystemQueryFn } from "./system-query.ts";
|
|
49
49
|
export { createTenantDbCache } from "./tenant-db-cache.ts";
|
|
50
50
|
export { EXT_TENANT_DESTRUCTION_HOLD, findTenantDestructionHoldProvider, type TenantDestructionHoldProvider, } from "./tenant-destruction-hold.ts";
|
|
51
|
+
export { parseTenantScopedSubject, peekTenantScopedSubject, type TenantScopedSubject, tenantScopedSubject, } from "./tenant-scoped-subject.ts";
|
|
51
52
|
export { type BurnResult, burnToken, unburnToken } from "./token-burn-store.ts";
|
|
52
53
|
export { unprocessable } from "./unprocessable.ts";
|
package/dist/shared/index.js
CHANGED
|
@@ -47,5 +47,6 @@ export { backfillAggregateStreamTenants, } from "./stream-tenant-backfill.js";
|
|
|
47
47
|
export { createSearchBucketCleanup, rebuildAndReindex, stepFailures, } from "./stream-tenant-derived-state.js";
|
|
48
48
|
export { createTenantDbCache } from "./tenant-db-cache.js";
|
|
49
49
|
export { EXT_TENANT_DESTRUCTION_HOLD, findTenantDestructionHoldProvider, } from "./tenant-destruction-hold.js";
|
|
50
|
+
export { parseTenantScopedSubject, peekTenantScopedSubject, tenantScopedSubject, } from "./tenant-scoped-subject.js";
|
|
50
51
|
export { burnToken, unburnToken } from "./token-burn-store.js";
|
|
51
52
|
export { unprocessable } from "./unprocessable.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
export type TenantScopedSubject = {
|
|
3
|
+
readonly tenantId: TenantId;
|
|
4
|
+
readonly rowId: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function tenantScopedSubject(parts: {
|
|
7
|
+
readonly tenantId: string;
|
|
8
|
+
readonly rowId: string;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function parseTenantScopedSubject(subject: string): TenantScopedSubject | null;
|
|
11
|
+
export declare function peekTenantScopedSubject(token: string): TenantScopedSubject | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isUuid, parseTenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { peekTokenSubject } from "./signed-token.js";
|
|
3
|
+
export function tenantScopedSubject(parts) {
|
|
4
|
+
return `${parts.tenantId}_${parts.rowId}`;
|
|
5
|
+
}
|
|
6
|
+
export function parseTenantScopedSubject(subject) {
|
|
7
|
+
const [rawTenantId, rowId, ...rest] = subject.split("_");
|
|
8
|
+
const tenantId = parseTenantId(rawTenantId);
|
|
9
|
+
if (rest.length > 0 || tenantId === null || !isUuid(rowId))
|
|
10
|
+
return null;
|
|
11
|
+
return { tenantId, rowId };
|
|
12
|
+
}
|
|
13
|
+
// Reads the unverified subject only to pick the tenant to dispatch into; the grant is still
|
|
14
|
+
// verified against the row's current anchor there.
|
|
15
|
+
export function peekTenantScopedSubject(token) {
|
|
16
|
+
const subject = peekTokenSubject(token);
|
|
17
|
+
return subject === null ? null : parseTenantScopedSubject(subject);
|
|
18
|
+
}
|
|
@@ -19,7 +19,7 @@ import { sweepSignatureRequests } from "./sweep.js";
|
|
|
19
19
|
import { signatureDeleteHook, signatureExportHook } from "./user-data.js";
|
|
20
20
|
import { SIGNATURE_FEATURE, SIGNATURE_REQUEST_ENTITY, SIGNATURE_SIGNER_ENTITY, } from "./web/constants.js";
|
|
21
21
|
export function createSignatureFeature(opts) {
|
|
22
|
-
if (opts.authorizeSubject !== undefined && opts.linkSecret === "") {
|
|
22
|
+
if (opts.authorizeSubject !== undefined && opts.linkSecret.trim() === "") {
|
|
23
23
|
throw new Error("authorizeSubject needs a non-empty linkSecret: it also seals the list cursor");
|
|
24
24
|
}
|
|
25
25
|
const signedInAccess = opts.access ?? DEFAULT_SIGNATURE_ACCESS;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
3
|
import { type RowBoundGrantResult, redeemRowBoundGrant } from "../shared/index.ts";
|
|
4
4
|
type AnchorCommit = Parameters<typeof redeemRowBoundGrant>[0]["commitAnchor"];
|
package/dist/signature/grant.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { peekTokenSubject, redeemRowBoundGrant, signRowBoundGrant, } from "../shared/index.js";
|
|
1
|
+
import { parseTenantScopedSubject, peekTenantScopedSubject, redeemRowBoundGrant, signRowBoundGrant, tenantScopedSubject, } from "../shared/index.js";
|
|
3
2
|
import { SIGNATURE_LINK_TTL_DAYS } from "./web/constants.js";
|
|
4
3
|
const SIGNATURE_LINK_PURPOSE = "signature-link";
|
|
5
4
|
const MINUTES_PER_DAY = 24 * 60;
|
|
6
5
|
export function signatureLinkSubject(parts) {
|
|
7
|
-
return
|
|
6
|
+
return tenantScopedSubject({ tenantId: parts.tenantId, rowId: parts.signerId });
|
|
7
|
+
}
|
|
8
|
+
function toSignatureLinkSubject(scoped) {
|
|
9
|
+
return scoped === null ? null : { tenantId: scoped.tenantId, signerId: scoped.rowId };
|
|
8
10
|
}
|
|
9
11
|
export function parseSignatureLinkSubject(subject) {
|
|
10
|
-
|
|
11
|
-
const tenantId = parseTenantId(rawTenantId);
|
|
12
|
-
if (rest.length > 0 || tenantId === null || !isUuid(signerId))
|
|
13
|
-
return null;
|
|
14
|
-
return { tenantId, signerId };
|
|
12
|
+
return toSignatureLinkSubject(parseTenantScopedSubject(subject));
|
|
15
13
|
}
|
|
16
|
-
// Reads the unverified subject only to pick the tenant to dispatch into; the grant is still
|
|
17
|
-
// verified against the signer's current anchor there.
|
|
18
14
|
export function peekSignatureLinkSubject(token) {
|
|
19
|
-
|
|
20
|
-
return subject === null ? null : parseSignatureLinkSubject(subject);
|
|
15
|
+
return toSignatureLinkSubject(peekTenantScopedSubject(token));
|
|
21
16
|
}
|
|
22
17
|
export function signSignatureLinkToken(args) {
|
|
23
18
|
return signRowBoundGrant({
|
package/dist/signature/png.js
CHANGED
|
@@ -4,6 +4,7 @@ const MAX_DIMENSION = 3000;
|
|
|
4
4
|
const MIN_DIMENSION = 16;
|
|
5
5
|
const MAX_PIXELS = 4_000_000;
|
|
6
6
|
const MIN_INK_PIXELS = 20;
|
|
7
|
+
const BACKGROUND_TOLERANCE = 8;
|
|
7
8
|
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
8
9
|
const COLOR_TYPE_GRAY_ALPHA = 4;
|
|
9
10
|
const COLOR_TYPE_RGBA = 6;
|
|
@@ -108,23 +109,47 @@ function countInkPixels(raw, header) {
|
|
|
108
109
|
const bytesPerPixel = header.bytesPerPixel;
|
|
109
110
|
const stride = header.width * bytesPerPixel + 1;
|
|
110
111
|
const pixelStart = (row, column) => row * stride + 1 + column * bytesPerPixel;
|
|
111
|
-
const background = pixelStart(0, 0);
|
|
112
112
|
const alphaOf = (start) => raw[start + bytesPerPixel - 1] ?? 0;
|
|
113
|
+
const pixelKey = (start) => raw.subarray(start, start + bytesPerPixel).join(",");
|
|
114
|
+
const borderStarts = [];
|
|
115
|
+
for (let column = 0; column < header.width; column++) {
|
|
116
|
+
borderStarts.push(pixelStart(0, column), pixelStart(header.height - 1, column));
|
|
117
|
+
}
|
|
118
|
+
for (let row = 1; row < header.height - 1; row++) {
|
|
119
|
+
borderStarts.push(pixelStart(row, 0), pixelStart(row, header.width - 1));
|
|
120
|
+
}
|
|
121
|
+
const opaqueBorderStarts = borderStarts.filter((start) => alphaOf(start) > 0);
|
|
122
|
+
const colorCounts = new Map();
|
|
123
|
+
for (const start of opaqueBorderStarts) {
|
|
124
|
+
const key = pixelKey(start);
|
|
125
|
+
const entry = colorCounts.get(key);
|
|
126
|
+
if (entry === undefined)
|
|
127
|
+
colorCounts.set(key, { count: 1, start });
|
|
128
|
+
else
|
|
129
|
+
entry.count++;
|
|
130
|
+
}
|
|
131
|
+
let background = -1;
|
|
132
|
+
let backgroundCount = 0;
|
|
133
|
+
for (const entry of colorCounts.values()) {
|
|
134
|
+
if (entry.count > backgroundCount) {
|
|
135
|
+
background = entry.start;
|
|
136
|
+
backgroundCount = entry.count;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
113
139
|
const colorMatchesBackground = (start) => {
|
|
140
|
+
if (background < 0)
|
|
141
|
+
return false;
|
|
114
142
|
for (let i = 0; i < bytesPerPixel; i++) {
|
|
115
|
-
|
|
143
|
+
const difference = Math.abs((raw[start + i] ?? 0) - (raw[background + i] ?? 0));
|
|
144
|
+
if (difference > BACKGROUND_TOLERANCE)
|
|
116
145
|
return false;
|
|
117
146
|
}
|
|
118
147
|
return true;
|
|
119
148
|
};
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
pixelStart(header.height - 1, 0),
|
|
125
|
-
pixelStart(header.height - 1, header.width - 1),
|
|
126
|
-
];
|
|
127
|
-
const hasSolidBackground = corners.every((corner) => alphaOf(corner) > 0 && colorMatchesBackground(corner));
|
|
149
|
+
// Most of the border must be opaque and alike for a solid background; a few opaque border pixels
|
|
150
|
+
// on a transparent canvas could be a stroke.
|
|
151
|
+
const nearBackgroundCount = opaqueBorderStarts.filter(colorMatchesBackground).length;
|
|
152
|
+
const hasSolidBackground = nearBackgroundCount * 2 > borderStarts.length;
|
|
128
153
|
let ink = 0;
|
|
129
154
|
for (let row = 0; row < header.height; row++) {
|
|
130
155
|
for (let column = 0; column < header.width; column++) {
|
|
@@ -45,6 +45,8 @@ export type ResolveLayoutRequest = {
|
|
|
45
45
|
readonly slug: string;
|
|
46
46
|
readonly kind: LayoutKind;
|
|
47
47
|
readonly locale: string;
|
|
48
|
+
/** Preview of unpublished content: the tenant's own layout counts in its working version (draft rows and open drafts). System layouts always resolve to their active version. */
|
|
49
|
+
readonly working?: boolean;
|
|
48
50
|
};
|
|
49
51
|
export type TemplateResolverApi = {
|
|
50
52
|
/**
|
|
@@ -6,7 +6,7 @@ import { requireBootstrapExtension } from "../shared/index.js";
|
|
|
6
6
|
import { fileAttachmentsOf, imageLinksOf, parseLinkedResourceEntries, pdfAttachmentLinksOf, } from "./linked-resources.js";
|
|
7
7
|
import { templateResourcesTable } from "./table.js";
|
|
8
8
|
import { deliveryPolicyOf, isRowServed, isServedByCollectionOnly, } from "./template-delivery-policy.js";
|
|
9
|
-
import { activeVersionOf, isSystemAdmin, servedVersionOf } from "./template-draft.js";
|
|
9
|
+
import { activeVersionOf, isSystemAdmin, servedVersionOf, toWorkingRow } from "./template-draft.js";
|
|
10
10
|
import { parseTemplateMeta } from "./template-meta.js";
|
|
11
11
|
import { FALLBACK_LOCALE, SYSTEM_TENANT_ID } from "./web/constants.js";
|
|
12
12
|
export function createTemplateResolverApi(db, registry) {
|
|
@@ -40,7 +40,7 @@ export function createTemplateResolverApi(db, registry) {
|
|
|
40
40
|
}
|
|
41
41
|
throw new TemplateNotFoundError({ slug, kind, locale });
|
|
42
42
|
},
|
|
43
|
-
resolveLayout: async ({ tenantId, slug, kind, locale }) => {
|
|
43
|
+
resolveLayout: async ({ tenantId, slug, kind, locale, working = false }) => {
|
|
44
44
|
for (const tid of [tenantId, SYSTEM_TENANT_ID]) {
|
|
45
45
|
if (!isRowServed(deliveryPolicy, { tenantId: tid, kind, slug }))
|
|
46
46
|
continue;
|
|
@@ -49,7 +49,7 @@ export function createTemplateResolverApi(db, registry) {
|
|
|
49
49
|
slug,
|
|
50
50
|
kind,
|
|
51
51
|
});
|
|
52
|
-
const row =
|
|
52
|
+
const row = pickLayoutRow(rows, locale, working && tid !== SYSTEM_TENANT_ID ? tid : null);
|
|
53
53
|
if (row !== null)
|
|
54
54
|
return toPublic(row);
|
|
55
55
|
}
|
|
@@ -99,10 +99,14 @@ export async function systemTemplateExists(db, kind, slug) {
|
|
|
99
99
|
const rows = await selectMany(db, templateResourcesTable, { tenantId: SYSTEM_TENANT_ID, slug, kind }, { limit: 1 });
|
|
100
100
|
return rows.length > 0;
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
102
|
+
// workingTenantId set: draft rows count too, each shown in its working version.
|
|
103
|
+
function pickLayoutRow(rows, locale, workingTenantId) {
|
|
104
|
+
const candidates = workingTenantId === null
|
|
105
|
+
? rows.filter((row) => row.status === "active")
|
|
106
|
+
: rows
|
|
107
|
+
.filter((row) => row.status === "active" || row.status === "draft")
|
|
108
|
+
.map((row) => toWorkingRow(row, workingTenantId));
|
|
109
|
+
const active = candidates.sort((a, b) => activeVersionOf(b) - activeVersionOf(a) || a.locale.localeCompare(b.locale));
|
|
106
110
|
return (active.find((row) => row.locale === locale) ??
|
|
107
111
|
active.find((row) => row.locale === FALLBACK_LOCALE) ??
|
|
108
112
|
active[0] ??
|
|
@@ -3,7 +3,7 @@ import { isResourceImageContentType } from "../shared/index.js";
|
|
|
3
3
|
import { appendStyle, applyDocumentPrintStyles } from "./compile-document-styles.js";
|
|
4
4
|
import { rewriteStepsBlock } from "./compile-steps-block.js";
|
|
5
5
|
import { conditionScopeElement, withParsedDocument } from "./document-sanitizer.js";
|
|
6
|
-
import { DOCUMENT_CONDITION_ATTRIBUTE, DOCUMENT_TEXT_ALIGNMENTS, isAllowedDocumentUrlHref, isDocumentPlaceholderHref, isDocumentReferenceName, isDocumentResourceKey, } from "./web/document-schema.js";
|
|
6
|
+
import { DOCUMENT_CONDITION_ATTRIBUTE, DOCUMENT_TEXT_ALIGNMENTS, isAllowedDocumentUrlHref, isDocumentPlaceholderHref, isDocumentReferenceName, isDocumentResourceKey, readDocumentDateStyle, } from "./web/document-schema.js";
|
|
7
7
|
// Private-use characters mark where a Handlebars expression goes. Author text
|
|
8
8
|
// is scrubbed of them first and every `{`/`}` is entity-encoded before the
|
|
9
9
|
// markers are swapped for real expressions, so the only Handlebars syntax in
|
|
@@ -37,11 +37,12 @@ function resolveReference(name, scope, variables) {
|
|
|
37
37
|
}
|
|
38
38
|
// The sanitized rich text value always consists of blocks; inside a line of
|
|
39
39
|
// other text it renders inline so no paragraph ends up inside a paragraph.
|
|
40
|
-
function valueExpression(path, def, isWholeBlock) {
|
|
40
|
+
function valueExpression(path, def, isWholeBlock, dateStyle) {
|
|
41
41
|
if (def?.type === "money")
|
|
42
42
|
return `{{money ${path}}}`;
|
|
43
|
-
if (def?.type === "date")
|
|
44
|
-
return `{{date ${path}}}`;
|
|
43
|
+
if (def?.type === "date") {
|
|
44
|
+
return dateStyle === null ? `{{date ${path}}}` : `{{date ${path} dateStyle="${dateStyle}"}}`;
|
|
45
|
+
}
|
|
45
46
|
if (def?.type === "percent")
|
|
46
47
|
return `{{percent ${path}}}`;
|
|
47
48
|
if (def?.type === "richText") {
|
|
@@ -56,7 +57,7 @@ function isImagesVariable(def) {
|
|
|
56
57
|
function rewriteVariable(element, state) {
|
|
57
58
|
const name = element.getAttribute("data-variable") ?? "";
|
|
58
59
|
const replacement = element.ownerDocument.createTextNode(isDocumentReferenceName(name) && !isImagesVariable(pathAndDef(name, element, state)[1])
|
|
59
|
-
? marker(state, valueExpression(...pathAndDef(name, element, state), state.blockRichTextSpans.has(element)))
|
|
60
|
+
? marker(state, valueExpression(...pathAndDef(name, element, state), state.blockRichTextSpans.has(element), readDocumentDateStyle(element)))
|
|
60
61
|
: "");
|
|
61
62
|
element.replaceWith(replacement);
|
|
62
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readBlockStyleAttributes, readCellBackground, readColwidth, readFrameAttributes, readTextStyleAttributes, } from "./web/document-print-style.js";
|
|
2
|
-
import { documentBlockStyleCss, documentCellStyleCss, documentFrameCss, documentTextStyleCss, } from "./web/document-style-css.js";
|
|
1
|
+
import { ROW_LINE_ABOVE_ATTRIBUTE, ROW_LINE_BELOW_ATTRIBUTE, readBlockStyleAttributes, readCellBackground, readCellPaddingMm, readColwidth, readDividerColor, readDividerWeightPt, readFrameAttributes, readImageAlign, readImageWidthMm, readRowLine, readTableAlign, readTableWidthMm, readTextStyleAttributes, } from "./web/document-print-style.js";
|
|
2
|
+
import { documentBlockStyleCss, documentCellStyleCss, documentDividerCss, documentFrameCss, documentImageCss, documentTableCss, documentTextStyleCss, resolveRowEdges, } from "./web/document-style-css.js";
|
|
3
3
|
// Appended after an existing style (data-align) so the alignment survives.
|
|
4
4
|
export function appendStyle(element, style) {
|
|
5
5
|
if (style === "")
|
|
@@ -58,6 +58,9 @@ function applyFrames(root) {
|
|
|
58
58
|
appendStyle(frame, documentFrameCss(box));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
function ownRows(table) {
|
|
62
|
+
return Array.from(table.querySelectorAll("tr")).filter((row) => row.closest("table") === table);
|
|
63
|
+
}
|
|
61
64
|
function applyTables(root) {
|
|
62
65
|
for (const table of Array.from(root.querySelectorAll("table"))) {
|
|
63
66
|
if (table.getAttribute("data-borders") === "none")
|
|
@@ -65,9 +68,42 @@ function applyTables(root) {
|
|
|
65
68
|
const widths = firstRowColumnWidths(table);
|
|
66
69
|
if (widths !== null)
|
|
67
70
|
insertColgroup(table, widths);
|
|
71
|
+
appendStyle(table, documentTableCss({ widthMm: readTableWidthMm(table), align: readTableAlign(table) }));
|
|
72
|
+
const paddingMm = readCellPaddingMm(table);
|
|
73
|
+
const rows = ownRows(table);
|
|
74
|
+
const edges = resolveRowEdges(rows.map((row) => ({
|
|
75
|
+
lineAbove: readRowLine(row, ROW_LINE_ABOVE_ATTRIBUTE),
|
|
76
|
+
lineBelow: readRowLine(row, ROW_LINE_BELOW_ATTRIBUTE),
|
|
77
|
+
repeats: row.hasAttribute("data-each"),
|
|
78
|
+
})));
|
|
79
|
+
rows.forEach((row, rowIndex) => {
|
|
80
|
+
const cells = Array.from(row.children).filter((cell) => cell.matches("td, th"));
|
|
81
|
+
cells.forEach((cell, cellIndex) => {
|
|
82
|
+
appendStyle(cell, documentCellStyleCss({
|
|
83
|
+
background: readCellBackground(cell),
|
|
84
|
+
paddingMm,
|
|
85
|
+
isFirstInRow: cellIndex === 0,
|
|
86
|
+
isLastInRow: cellIndex === cells.length - 1,
|
|
87
|
+
edges: edges[rowIndex],
|
|
88
|
+
}));
|
|
89
|
+
});
|
|
90
|
+
});
|
|
68
91
|
}
|
|
69
|
-
|
|
70
|
-
|
|
92
|
+
}
|
|
93
|
+
// A full-bleed image is placed by the region CSS, which an inline width would override.
|
|
94
|
+
function applyImages(root) {
|
|
95
|
+
for (const image of Array.from(root.querySelectorAll("img[data-width-mm], img[data-align]"))) {
|
|
96
|
+
if (image.hasAttribute("data-bleed"))
|
|
97
|
+
continue;
|
|
98
|
+
appendStyle(image, documentImageCss({ widthMm: readImageWidthMm(image), align: readImageAlign(image) }));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function applyDividers(root) {
|
|
102
|
+
for (const divider of Array.from(root.querySelectorAll("hr[data-color], hr[data-weight-pt]"))) {
|
|
103
|
+
appendStyle(divider, documentDividerCss({
|
|
104
|
+
color: readDividerColor(divider),
|
|
105
|
+
weightPt: readDividerWeightPt(divider),
|
|
106
|
+
}));
|
|
71
107
|
}
|
|
72
108
|
}
|
|
73
109
|
// Runs before the placeholder rewrites: a rich text block host copies its paragraph's
|
|
@@ -75,6 +111,8 @@ function applyTables(root) {
|
|
|
75
111
|
export function applyDocumentPrintStyles(root) {
|
|
76
112
|
applyFrames(root);
|
|
77
113
|
applyTables(root);
|
|
114
|
+
applyImages(root);
|
|
115
|
+
applyDividers(root);
|
|
78
116
|
for (const span of Array.from(root.querySelectorAll("span[data-text-style]"))) {
|
|
79
117
|
appendStyle(span, documentTextStyleCss(readTextStyleAttributes(span)));
|
|
80
118
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type DocumentFrameAttributes } from "./web/document-print-style.ts";
|
|
2
2
|
export declare function readTopLevelFrames(html: string): readonly DocumentFrameAttributes[];
|
|
3
3
|
export declare function flattenFramesForPreview(compiledHtml: string): string;
|
|
4
|
+
export declare function flattenAddressSenderLine(compiledHtml: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
// for the editor preview, which shows the body outside a page where absolute coordinates mean nothing.
|
|
1
|
+
import { appendStyle } from "./compile-document-styles.js";
|
|
3
2
|
import { withParsedDocument } from "./document-sanitizer.js";
|
|
4
3
|
import { readFrameAttributes } from "./web/document-print-style.js";
|
|
4
|
+
import { addressParagraphCss, SENDER_LINE_SIZE_PT } from "./web/document-style-css.js";
|
|
5
5
|
const PREVIEW_FRAME_STYLE = "margin:8px 0;padding:6px;border:1px dashed #9ca3af;white-space:pre-line";
|
|
6
6
|
export function readTopLevelFrames(html) {
|
|
7
7
|
return withParsedDocument(html, (body) => Array.from(body.children).flatMap((child) => {
|
|
@@ -17,3 +17,40 @@ export function flattenFramesForPreview(compiledHtml) {
|
|
|
17
17
|
return body.innerHTML;
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
const TEXT_NODE_TYPE = 3;
|
|
21
|
+
const ELEMENT_NODE_TYPE = 1;
|
|
22
|
+
const SENDER_SIZE_SELECTOR = `[data-size-pt="${SENDER_LINE_SIZE_PT}"]`;
|
|
23
|
+
const ADDRESS_FIRST_PARAGRAPH_SELECTOR = "div.kumiko-frame[data-frame-preset=address] > p:first-child";
|
|
24
|
+
function nonBlankTextNodes(node) {
|
|
25
|
+
if (node.nodeType === TEXT_NODE_TYPE)
|
|
26
|
+
return (node.textContent ?? "").trim() === "" ? [] : [node];
|
|
27
|
+
if (node.nodeType !== ELEMENT_NODE_TYPE)
|
|
28
|
+
return [];
|
|
29
|
+
return Array.from(node.childNodes).flatMap(nonBlankTextNodes);
|
|
30
|
+
}
|
|
31
|
+
// Without the sender checkbox the first paragraph is the recipient and must stay as written.
|
|
32
|
+
function isSenderLine(paragraph) {
|
|
33
|
+
const texts = nonBlankTextNodes(paragraph);
|
|
34
|
+
return (texts.length > 0 &&
|
|
35
|
+
texts.every((text) => text.parentElement?.closest(SENDER_SIZE_SELECTOR) != null));
|
|
36
|
+
}
|
|
37
|
+
// The sender line is a single line, so a multi-line company address has to read with the same
|
|
38
|
+
// separator the editor uses between name and address. Its rule and spacing come from the same
|
|
39
|
+
// CSS builder as the editor decoration.
|
|
40
|
+
export function flattenAddressSenderLine(compiledHtml) {
|
|
41
|
+
if (!compiledHtml.includes("data-frame-preset"))
|
|
42
|
+
return compiledHtml;
|
|
43
|
+
return withParsedDocument(compiledHtml, (body) => {
|
|
44
|
+
let changed = false;
|
|
45
|
+
for (const paragraph of Array.from(body.querySelectorAll(ADDRESS_FIRST_PARAGRAPH_SELECTOR))) {
|
|
46
|
+
if (!isSenderLine(paragraph))
|
|
47
|
+
continue;
|
|
48
|
+
for (const text of nonBlankTextNodes(paragraph)) {
|
|
49
|
+
text.textContent = (text.textContent ?? "").replace(/\s*\r?\n\s*/g, " · ");
|
|
50
|
+
}
|
|
51
|
+
appendStyle(paragraph, addressParagraphCss(true));
|
|
52
|
+
changed = true;
|
|
53
|
+
}
|
|
54
|
+
return changed ? body.innerHTML : compiledHtml;
|
|
55
|
+
});
|
|
56
|
+
}
|