@officedk/pptxdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,2252 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { hasFontFaceBytes, peekFontFaceResource, resolveFontClassification } from "../../../core/dist/font-seal.js";
|
|
3
|
+
import { isFont, textStyleKeys, validateTextStyle } from "../../../core/dist/theme.js";
|
|
4
|
+
import "../../../core/dist/placeholders.js";
|
|
5
|
+
import { paddingStyleKeys } from "../../../core/dist/block-flex-layout.js";
|
|
6
|
+
import "../../../core/dist/capability.js";
|
|
7
|
+
import { pxToEmu, resolvedColorXml, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
8
|
+
import "../../../emit/dist/index.js";
|
|
9
|
+
import { fontPresentationContributions, requiresFontGlyph, requiresVisibleFontGlyph } from "../font/font-embedding.js";
|
|
10
|
+
import { findMissingFontGlyphs, isTrueTypeFontEmbeddable, openMeasureFontFace, resolveDeclaredFaceSlot, shapeFontAdvances, shapeFontOutlines, validateFontFaceResource } from "../font/font-engine.js";
|
|
11
|
+
import { parseStepDeclarationProps, pickMotionProps, validateMotionFlag } from "../motion/motion-api.js";
|
|
12
|
+
import { motionPropKeySet } from "../motion/motion-schemas.js";
|
|
13
|
+
import { hasLocalDeclaration, localDeclaredKeySet, resolvePlaceholderBaseTextStyle, resolvePlaceholderLevelTextStyle } from "./style-inheritance.js";
|
|
14
|
+
import { parseBaselineShiftThousandths, parseParagraphStyle, parseRunStyle, parseTextInsets } from "./text-schemas.js";
|
|
15
|
+
import { resolveShadow, textShadowXml } from "./visual.js";
|
|
16
|
+
import LineBreakerImplementation from "linebreak";
|
|
17
|
+
// ../capabilities/dist/shared/text-service.js
|
|
18
|
+
/**
|
|
19
|
+
* Author metadata accepted on P, Span, and SlideNumber declarations.
|
|
20
|
+
*
|
|
21
|
+
* Scoped id validation belongs to the formal build around these nodes; the shared text parser must
|
|
22
|
+
* skip the field while resolving styles instead of reporting it as an unimplemented parameter.
|
|
23
|
+
*/
|
|
24
|
+
const textAuthorMetadataKeys = /* @__PURE__ */ new Set(["id"]);
|
|
25
|
+
const LineBreaker = LineBreakerImplementation;
|
|
26
|
+
const graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
27
|
+
const defaultTextStyle = Object.freeze({
|
|
28
|
+
fontFamily: "minor",
|
|
29
|
+
eastAsianFontFamily: "minor",
|
|
30
|
+
fontSize: 24,
|
|
31
|
+
fontWeight: "normal",
|
|
32
|
+
fontStyle: "normal",
|
|
33
|
+
color: "tx1"
|
|
34
|
+
});
|
|
35
|
+
function record(value) {
|
|
36
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
function escapedXml(value) {
|
|
39
|
+
try {
|
|
40
|
+
return xmlEscape(value);
|
|
41
|
+
} catch {
|
|
42
|
+
throw new CapabilityError("invalid-xml-character", "Text content or font name contains characters not allowed in XML 1.0");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isHostText(child) {
|
|
46
|
+
return child.type === "#text" && "text" in child;
|
|
47
|
+
}
|
|
48
|
+
function hostChild(value) {
|
|
49
|
+
if (!record(value) || typeof value["type"] !== "string") return false;
|
|
50
|
+
if (value["type"] === "#text") return typeof value["text"] === "string";
|
|
51
|
+
return value["type"].trim() !== "" && record(value["props"]) && Array.isArray(value["children"]);
|
|
52
|
+
}
|
|
53
|
+
function styleRecord(value, label) {
|
|
54
|
+
if (value === void 0) return {};
|
|
55
|
+
if (!record(value)) throw new CapabilityError("invalid-style", `${label} must be an object`);
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function onlyKnownKeys(value, allowed, label) {
|
|
59
|
+
const unknown = Object.keys(value).find((key) => !allowed.includes(key));
|
|
60
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-style-property", `${label} contains unimplemented style ${unknown}`);
|
|
61
|
+
}
|
|
62
|
+
function positiveLength(value, label) {
|
|
63
|
+
let pixels;
|
|
64
|
+
if (typeof value === "number") pixels = value;
|
|
65
|
+
else if (typeof value === "string") {
|
|
66
|
+
const match = /^(\d+(?:\.\d+)?)(px|pt)$/u.exec(value);
|
|
67
|
+
if (match === null) throw new CapabilityError("invalid-text-length", `${label} must be a positive pixel value or px/pt length`);
|
|
68
|
+
const amount = Number(match[1]);
|
|
69
|
+
pixels = match[2] === "pt" ? amount * 4 / 3 : amount;
|
|
70
|
+
} else throw new CapabilityError("invalid-text-length", `${label} must be a positive pixel value or px/pt length`);
|
|
71
|
+
if (!Number.isFinite(pixels) || pixels <= 0) throw new CapabilityError("invalid-text-length", `${label} must be greater than 0`);
|
|
72
|
+
return pixels;
|
|
73
|
+
}
|
|
74
|
+
const lineHeightPercentPattern = /^(\d+(?:\.\d+)?)%$/u;
|
|
75
|
+
function isLineHeightPercent(value) {
|
|
76
|
+
return typeof value === "string" && value.endsWith("%");
|
|
77
|
+
}
|
|
78
|
+
function lineHeightPercentThousandths(value) {
|
|
79
|
+
const match = lineHeightPercentPattern.exec(value);
|
|
80
|
+
if (match === null) throw new CapabilityError("invalid-text-length", "lineHeight percentage must be greater than 0% and within DrawingML ST_TextSpacingPercent range (up to 13200%)");
|
|
81
|
+
const pct = Number(match[1]);
|
|
82
|
+
const thousandths = Math.round(pct * 1e3);
|
|
83
|
+
if (!Number.isFinite(pct) || thousandths < 1 || thousandths > 132e5) throw new CapabilityError("invalid-text-length", "lineHeight percentage must be greater than 0% and within DrawingML ST_TextSpacingPercent range (up to 13200%)");
|
|
84
|
+
return thousandths;
|
|
85
|
+
}
|
|
86
|
+
function lineSpacingXml(value) {
|
|
87
|
+
if (value === void 0) return "";
|
|
88
|
+
if (isLineHeightPercent(value)) return `<a:lnSpc><a:spcPct val="${lineHeightPercentThousandths(value)}"/></a:lnSpc>`;
|
|
89
|
+
return `<a:lnSpc><a:spcPts val="${spacingCentipoints(positiveLength(value, "lineHeight"), "lineHeight")}"/></a:lnSpc>`;
|
|
90
|
+
}
|
|
91
|
+
function centipoints(value) {
|
|
92
|
+
return Math.round(value * 100);
|
|
93
|
+
}
|
|
94
|
+
function spacingCentipoints(pixels, label) {
|
|
95
|
+
const value = Math.round(pixels * 75);
|
|
96
|
+
if (value < 0 || value > 158400) throw new CapabilityError(label === "lineHeight" ? "invalid-text-length" : "invalid-paragraph-spacing", `${label} converted value must be within DrawingML range of 0 to 1584pt`);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function letterSpacingCentipoints(value) {
|
|
100
|
+
const points = Math.round(value * 75);
|
|
101
|
+
if (!Number.isFinite(value) || points < -4e5 || points > 4e5) throw new CapabilityError("invalid-letter-spacing", "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt");
|
|
102
|
+
return points;
|
|
103
|
+
}
|
|
104
|
+
function fontSizePoints(value) {
|
|
105
|
+
let points;
|
|
106
|
+
if (value === void 0) points = positiveLength(defaultTextStyle.fontSize, "fontSize") * .75;
|
|
107
|
+
else if (typeof value === "string" && value.endsWith("pt")) {
|
|
108
|
+
points = Number(value.slice(0, -2));
|
|
109
|
+
if (!Number.isFinite(points) || points <= 0) throw new CapabilityError("invalid-font-size", "fontSize must be greater than 0");
|
|
110
|
+
} else points = positiveLength(value, "fontSize") * .75;
|
|
111
|
+
const serialized = centipoints(points);
|
|
112
|
+
if (serialized < 100 || serialized > 4e5) throw new CapabilityError("invalid-font-size", "fontSize converted value must be within DrawingML range of 1 to 4000pt");
|
|
113
|
+
return serialized / 100;
|
|
114
|
+
}
|
|
115
|
+
function weightValue(value) {
|
|
116
|
+
if (value === void 0 || value === "normal") return 400;
|
|
117
|
+
if (value === "bold") return 700;
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function fontFamilyValue(value) {
|
|
121
|
+
if (value === void 0) return { family: "Aptos" };
|
|
122
|
+
return typeof value === "string" ? { family: value } : value;
|
|
123
|
+
}
|
|
124
|
+
function normalizedFontsForReference(fontRef, fontWeight, fontStyle) {
|
|
125
|
+
const family = fontFamilyValue(fontRef);
|
|
126
|
+
const weight = weightValue(fontWeight);
|
|
127
|
+
const faceStyle = fontStyle ?? "normal";
|
|
128
|
+
const providedFaces = (family.faces ?? []).filter((candidate) => {
|
|
129
|
+
const slot = resolveDeclaredFaceSlot(candidate);
|
|
130
|
+
if (slot.matchAnyWeightOnFvarOrCorrupt) return candidate.style === void 0 || slot.style === faceStyle;
|
|
131
|
+
return slot.weight === weight && slot.style === faceStyle;
|
|
132
|
+
}).filter((candidate) => hasFontFaceBytes(candidate));
|
|
133
|
+
if (providedFaces.length === 0) return [{
|
|
134
|
+
family: family.family,
|
|
135
|
+
weight,
|
|
136
|
+
style: faceStyle,
|
|
137
|
+
substitute: family.substitute ?? false,
|
|
138
|
+
embeddable: family.embeddable ?? true,
|
|
139
|
+
hasResource: false,
|
|
140
|
+
identity: "missing"
|
|
141
|
+
}];
|
|
142
|
+
return providedFaces.flatMap((face) => {
|
|
143
|
+
const faceResource = peekFontFaceResource(face);
|
|
144
|
+
if (faceResource === void 0) return [];
|
|
145
|
+
return [{
|
|
146
|
+
family: family.family,
|
|
147
|
+
weight,
|
|
148
|
+
style: faceStyle,
|
|
149
|
+
substitute: family.substitute ?? false,
|
|
150
|
+
embeddable: family.embeddable ?? true,
|
|
151
|
+
hasResource: true,
|
|
152
|
+
identity: faceResource.sha256,
|
|
153
|
+
data: faceResource.bytes
|
|
154
|
+
}];
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function normalizedFonts(style) {
|
|
158
|
+
return normalizedFontsForReference(style.fontFamily, style.fontWeight, style.fontStyle);
|
|
159
|
+
}
|
|
160
|
+
function isEastAsianCodePoint(cp) {
|
|
161
|
+
return cp >= 11904 && cp <= 12031 || cp >= 12032 && cp <= 12255 || cp >= 12272 && cp <= 12351 || cp >= 12352 && cp <= 12543 || cp >= 12544 && cp <= 12591 || cp >= 12592 && cp <= 12687 || cp >= 12704 && cp <= 12735 || cp >= 12784 && cp <= 12799 || cp >= 12800 && cp <= 13311 || cp >= 13312 && cp <= 19903 || cp >= 19968 && cp <= 40959 || cp >= 4352 && cp <= 4607 || cp >= 43360 && cp <= 43391 || cp >= 44032 && cp <= 55295 || cp >= 63744 && cp <= 64255 || cp >= 65040 && cp <= 65055 || cp >= 65072 && cp <= 65135 || cp >= 65281 && cp <= 65376 || cp >= 65377 && cp <= 65503 || cp >= 65504 && cp <= 65510 || cp >= 110592 && cp <= 110959 || cp >= 131072 && cp <= 205743;
|
|
162
|
+
}
|
|
163
|
+
function isNeutralScriptChar(ch, cp) {
|
|
164
|
+
return cp !== 12288 && /^[\p{White_Space}\p{Cc}\p{Default_Ignorable_Code_Point}]$/u.test(ch);
|
|
165
|
+
}
|
|
166
|
+
function sameFontReference(left, right) {
|
|
167
|
+
if (left === right) return true;
|
|
168
|
+
if (left === void 0 || right === void 0) return false;
|
|
169
|
+
if (typeof left === "string" && typeof right === "string") return left === right;
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
function effectiveEastAsianRunStyle(style) {
|
|
173
|
+
if (style.eastAsianFontFamily === void 0 || sameFontReference(style.eastAsianFontFamily, style.fontFamily)) return style;
|
|
174
|
+
return {
|
|
175
|
+
...style,
|
|
176
|
+
fontFamily: style.eastAsianFontFamily,
|
|
177
|
+
themeFont: style.eastAsianThemeFont
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function splitRunForEffectiveScripts(text, style) {
|
|
181
|
+
if (text === "") return [{
|
|
182
|
+
script: "latin",
|
|
183
|
+
text: "",
|
|
184
|
+
style
|
|
185
|
+
}];
|
|
186
|
+
const eaStyle = effectiveEastAsianRunStyle(style);
|
|
187
|
+
if (eaStyle === style) return [{
|
|
188
|
+
script: "latin",
|
|
189
|
+
text,
|
|
190
|
+
style
|
|
191
|
+
}];
|
|
192
|
+
const segments = [];
|
|
193
|
+
let activeScript;
|
|
194
|
+
let buffer = "";
|
|
195
|
+
let leadingNeutral = "";
|
|
196
|
+
for (const ch of text) {
|
|
197
|
+
const cp = ch.codePointAt(0);
|
|
198
|
+
if (cp === void 0) continue;
|
|
199
|
+
if (isNeutralScriptChar(ch, cp)) {
|
|
200
|
+
if (activeScript === void 0) leadingNeutral += ch;
|
|
201
|
+
else buffer += ch;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const nextScript = isEastAsianCodePoint(cp) ? "ea" : "latin";
|
|
205
|
+
if (activeScript === void 0) {
|
|
206
|
+
activeScript = nextScript;
|
|
207
|
+
buffer = leadingNeutral + ch;
|
|
208
|
+
leadingNeutral = "";
|
|
209
|
+
} else if (nextScript === activeScript) buffer += ch;
|
|
210
|
+
else {
|
|
211
|
+
segments.push({
|
|
212
|
+
script: activeScript,
|
|
213
|
+
text: buffer,
|
|
214
|
+
style: activeScript === "ea" ? eaStyle : style
|
|
215
|
+
});
|
|
216
|
+
activeScript = nextScript;
|
|
217
|
+
buffer = ch;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (activeScript === void 0) return [{
|
|
221
|
+
script: "latin",
|
|
222
|
+
text: leadingNeutral,
|
|
223
|
+
style
|
|
224
|
+
}];
|
|
225
|
+
if (buffer !== "") segments.push({
|
|
226
|
+
script: activeScript,
|
|
227
|
+
text: buffer,
|
|
228
|
+
style: activeScript === "ea" ? eaStyle : style
|
|
229
|
+
});
|
|
230
|
+
return segments;
|
|
231
|
+
}
|
|
232
|
+
function hasIndependentThemeMinorEa(theme) {
|
|
233
|
+
if (theme.theme.fonts.minorEastAsian !== void 0) return true;
|
|
234
|
+
const ea = theme.resolveEastAsianFont("minor");
|
|
235
|
+
const lt = theme.resolveFont("minor");
|
|
236
|
+
return (ea.font ?? ea.family) !== (lt.font ?? lt.family);
|
|
237
|
+
}
|
|
238
|
+
function validateRunStyle(style) {
|
|
239
|
+
const { themeFont: _themeFont, eastAsianThemeFont: _eastAsianThemeFont, color, baselineShift, ...rest } = style;
|
|
240
|
+
validateTextStyle({
|
|
241
|
+
...rest,
|
|
242
|
+
...color !== void 0 && !isResolvedColor(color) ? { color } : {}
|
|
243
|
+
});
|
|
244
|
+
if (baselineShift !== void 0 && parseBaselineShiftThousandths(baselineShift) === void 0) throw new CapabilityError("invalid-baseline-shift", "baselineShift must be a non-zero finite percentage string within DrawingML ST_Percentage range", void 0, { field: "style.baselineShift" });
|
|
245
|
+
return style;
|
|
246
|
+
}
|
|
247
|
+
function readRunStyle(value, label = "Span.style") {
|
|
248
|
+
return parseRunStyle(value, label);
|
|
249
|
+
}
|
|
250
|
+
function mergeRunStyle(parent, child, theme) {
|
|
251
|
+
const declared = Object.fromEntries(Object.entries(child).filter(([, value]) => value !== void 0));
|
|
252
|
+
if (child.fontFamily !== void 0) {
|
|
253
|
+
const font = theme.resolveFont(child.fontFamily);
|
|
254
|
+
declared["fontFamily"] = font.font ?? font.family;
|
|
255
|
+
if (child.themeFont === void 0 && font.themeFont === void 0) delete declared["themeFont"];
|
|
256
|
+
else declared["themeFont"] = child.themeFont ?? font.themeFont;
|
|
257
|
+
}
|
|
258
|
+
if (child.eastAsianFontFamily !== void 0) {
|
|
259
|
+
const eaFont = theme.resolveEastAsianFont(child.eastAsianFontFamily);
|
|
260
|
+
declared["eastAsianFontFamily"] = eaFont.font ?? eaFont.family;
|
|
261
|
+
if (child.eastAsianThemeFont === void 0 && eaFont.themeFont === void 0) delete declared["eastAsianThemeFont"];
|
|
262
|
+
else declared["eastAsianThemeFont"] = child.eastAsianThemeFont ?? eaFont.themeFont;
|
|
263
|
+
}
|
|
264
|
+
if (child.color !== void 0 && !isResolvedColor(child.color)) declared["color"] = theme.resolveColor(child.color);
|
|
265
|
+
if (child.lang !== void 0) declared["lang"] = child.lang;
|
|
266
|
+
const merged = {
|
|
267
|
+
...parent,
|
|
268
|
+
...declared
|
|
269
|
+
};
|
|
270
|
+
if (child.textShadow === "none") delete merged.textShadow;
|
|
271
|
+
if (child.fontFamily !== void 0 && declared["themeFont"] === void 0) delete merged.themeFont;
|
|
272
|
+
if (child.eastAsianFontFamily !== void 0 && declared["eastAsianThemeFont"] === void 0) delete merged.eastAsianThemeFont;
|
|
273
|
+
return validateRunStyle(merged);
|
|
274
|
+
}
|
|
275
|
+
function isResolvedColor(value) {
|
|
276
|
+
return record(value) && typeof value["hex"] === "string";
|
|
277
|
+
}
|
|
278
|
+
function outputBold(font) {
|
|
279
|
+
const fallback = font.weight >= 600;
|
|
280
|
+
if (!font.hasResource || font.substitute || font.data === void 0) return fallback;
|
|
281
|
+
try {
|
|
282
|
+
return validateFontFaceResource({
|
|
283
|
+
family: font.family,
|
|
284
|
+
weight: font.weight,
|
|
285
|
+
style: font.style,
|
|
286
|
+
substitute: font.substitute,
|
|
287
|
+
data: font.data,
|
|
288
|
+
identity: font.identity
|
|
289
|
+
}).os2Bold;
|
|
290
|
+
} catch {
|
|
291
|
+
return fallback;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function mergeLocalRunDeclared(parent, child, theme) {
|
|
295
|
+
const declared = { ...parent };
|
|
296
|
+
for (const [key, value] of Object.entries(child)) {
|
|
297
|
+
if (!Object.hasOwn(child, key) || value === void 0) continue;
|
|
298
|
+
declared[key] = value;
|
|
299
|
+
}
|
|
300
|
+
if (hasLocalDeclaration(child, "fontFamily")) {
|
|
301
|
+
const resolved = theme.resolveFont(child["fontFamily"]);
|
|
302
|
+
declared["fontFamily"] = resolved.font ?? resolved.family;
|
|
303
|
+
if (resolved.themeFont === void 0) delete declared["themeFont"];
|
|
304
|
+
else declared["themeFont"] = resolved.themeFont;
|
|
305
|
+
}
|
|
306
|
+
if (hasLocalDeclaration(child, "eastAsianFontFamily")) {
|
|
307
|
+
const resolvedEa = theme.resolveEastAsianFont(child["eastAsianFontFamily"]);
|
|
308
|
+
declared["eastAsianFontFamily"] = resolvedEa.font ?? resolvedEa.family;
|
|
309
|
+
if (resolvedEa.themeFont === void 0) delete declared["eastAsianThemeFont"];
|
|
310
|
+
else declared["eastAsianThemeFont"] = resolvedEa.themeFont;
|
|
311
|
+
}
|
|
312
|
+
if (hasLocalDeclaration(child, "color") && !isResolvedColor(child["color"])) declared["color"] = theme.resolveColor(child["color"]);
|
|
313
|
+
return declared;
|
|
314
|
+
}
|
|
315
|
+
function resolveRunStyleFromRecord(style, theme) {
|
|
316
|
+
const font = theme.resolveFont(style["fontFamily"] ?? defaultTextStyle.fontFamily);
|
|
317
|
+
const rawEa = style["eastAsianFontFamily"];
|
|
318
|
+
const eaFont = rawEa !== void 0 ? theme.resolveEastAsianFont(rawEa) : hasIndependentThemeMinorEa(theme) ? theme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? theme.resolveEastAsianFont(font.themeFont) : void 0;
|
|
319
|
+
const includeEa = rawEa !== void 0 || hasIndependentThemeMinorEa(theme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
|
|
320
|
+
const rawColor = style["color"];
|
|
321
|
+
const color = rawColor === void 0 ? theme.resolveColor(defaultTextStyle.color) : isResolvedColor(rawColor) ? rawColor : theme.resolveColor(rawColor);
|
|
322
|
+
return validateRunStyle({
|
|
323
|
+
fontFamily: font.font ?? font.family,
|
|
324
|
+
...includeEa && eaFont !== void 0 ? {
|
|
325
|
+
eastAsianFontFamily: eaFont.font ?? eaFont.family,
|
|
326
|
+
...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
|
|
327
|
+
} : {},
|
|
328
|
+
fontSize: style["fontSize"] ?? defaultTextStyle.fontSize,
|
|
329
|
+
fontWeight: style["fontWeight"] ?? defaultTextStyle.fontWeight,
|
|
330
|
+
fontStyle: style["fontStyle"] ?? defaultTextStyle.fontStyle,
|
|
331
|
+
color,
|
|
332
|
+
...font.themeFont === void 0 ? {} : { themeFont: font.themeFont },
|
|
333
|
+
...style["letterSpacing"] === void 0 ? {} : { letterSpacing: style["letterSpacing"] },
|
|
334
|
+
...style["textTransform"] === void 0 ? {} : { textTransform: style["textTransform"] },
|
|
335
|
+
...style["textDecoration"] === void 0 ? {} : { textDecoration: style["textDecoration"] },
|
|
336
|
+
...style["textShadow"] === void 0 || style["textShadow"] === "none" ? {} : { textShadow: style["textShadow"] },
|
|
337
|
+
...style["lang"] === void 0 ? {} : { lang: style["lang"] }
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function readPlaceholderTextStyle(value, label, placeholder) {
|
|
341
|
+
const props = styleRecord(value, label);
|
|
342
|
+
onlyKnownKeys(props, [...textStyleKeys], label);
|
|
343
|
+
const localDeclaredStyle = {};
|
|
344
|
+
for (const key of textStyleKeys) if (hasLocalDeclaration(props, key)) localDeclaredStyle[key] = props[key];
|
|
345
|
+
const effectiveBase = resolvePlaceholderBaseTextStyle(placeholder, localDeclaredStyle);
|
|
346
|
+
const masterTheme = placeholder.masterTheme;
|
|
347
|
+
const eaDeclared = effectiveBase["eastAsianFontFamily"] !== void 0;
|
|
348
|
+
const merged = {
|
|
349
|
+
...defaultTextStyle,
|
|
350
|
+
...effectiveBase
|
|
351
|
+
};
|
|
352
|
+
const font = masterTheme.resolveFont(merged.fontFamily ?? defaultTextStyle.fontFamily);
|
|
353
|
+
const eaFont = eaDeclared ? masterTheme.resolveEastAsianFont(effectiveBase["eastAsianFontFamily"]) : hasIndependentThemeMinorEa(masterTheme) ? masterTheme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? masterTheme.resolveEastAsianFont(font.themeFont) : void 0;
|
|
354
|
+
const includeEa = eaDeclared || hasIndependentThemeMinorEa(masterTheme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
|
|
355
|
+
if (merged.color !== void 0 && !isResolvedColor(merged.color)) masterTheme.resolveColor(merged.color);
|
|
356
|
+
validateTextStyle({
|
|
357
|
+
...merged,
|
|
358
|
+
fontFamily: font.font ?? font.family,
|
|
359
|
+
...includeEa && eaFont !== void 0 ? { eastAsianFontFamily: eaFont.font ?? eaFont.family } : { eastAsianFontFamily: void 0 },
|
|
360
|
+
...isResolvedColor(merged.color) ? { color: void 0 } : {}
|
|
361
|
+
});
|
|
362
|
+
const result = {
|
|
363
|
+
...merged,
|
|
364
|
+
fontFamily: font.font ?? font.family,
|
|
365
|
+
...includeEa && eaFont !== void 0 ? {
|
|
366
|
+
eastAsianFontFamily: eaFont.font ?? eaFont.family,
|
|
367
|
+
...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
|
|
368
|
+
} : { eastAsianFontFamily: void 0 },
|
|
369
|
+
...font.themeFont === void 0 ? {} : { themeFont: font.themeFont }
|
|
370
|
+
};
|
|
371
|
+
if (result.textShadow === "none") delete result.textShadow;
|
|
372
|
+
return {
|
|
373
|
+
style: result,
|
|
374
|
+
localDeclaredStyle
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function readTextStyle(value, label, theme) {
|
|
378
|
+
const props = styleRecord(value, label);
|
|
379
|
+
onlyKnownKeys(props, [...textStyleKeys], label);
|
|
380
|
+
const rawCombined = {
|
|
381
|
+
...theme.textStyle,
|
|
382
|
+
...props
|
|
383
|
+
};
|
|
384
|
+
const eaDeclared = rawCombined["eastAsianFontFamily"] !== void 0;
|
|
385
|
+
const style = {
|
|
386
|
+
...defaultTextStyle,
|
|
387
|
+
...theme.textStyle,
|
|
388
|
+
...props
|
|
389
|
+
};
|
|
390
|
+
const font = theme.resolveFont(style.fontFamily ?? defaultTextStyle.fontFamily);
|
|
391
|
+
const eaFont = eaDeclared ? theme.resolveEastAsianFont(rawCombined["eastAsianFontFamily"]) : hasIndependentThemeMinorEa(theme) ? theme.resolveEastAsianFont("minor") : font.themeFont !== void 0 ? theme.resolveEastAsianFont(font.themeFont) : void 0;
|
|
392
|
+
const includeEa = eaDeclared || hasIndependentThemeMinorEa(theme) || eaFont !== void 0 && (eaFont.font ?? eaFont.family) !== (font.font ?? font.family);
|
|
393
|
+
if (style.color !== void 0 && !isResolvedColor(style.color)) theme.resolveColor(style.color);
|
|
394
|
+
validateTextStyle({
|
|
395
|
+
...style,
|
|
396
|
+
fontFamily: font.font ?? font.family,
|
|
397
|
+
...includeEa && eaFont !== void 0 ? { eastAsianFontFamily: eaFont.font ?? eaFont.family } : { eastAsianFontFamily: void 0 },
|
|
398
|
+
...isResolvedColor(style.color) ? { color: void 0 } : {}
|
|
399
|
+
});
|
|
400
|
+
const result = {
|
|
401
|
+
...style,
|
|
402
|
+
fontFamily: font.font ?? font.family,
|
|
403
|
+
...includeEa && eaFont !== void 0 ? {
|
|
404
|
+
eastAsianFontFamily: eaFont.font ?? eaFont.family,
|
|
405
|
+
...eaFont.themeFont === void 0 ? {} : { eastAsianThemeFont: eaFont.themeFont }
|
|
406
|
+
} : { eastAsianFontFamily: void 0 },
|
|
407
|
+
...font.themeFont === void 0 ? {} : { themeFont: font.themeFont }
|
|
408
|
+
};
|
|
409
|
+
if (result.textShadow === "none") delete result.textShadow;
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
function paragraphStyle(value) {
|
|
413
|
+
return parseParagraphStyle(value, "P.style");
|
|
414
|
+
}
|
|
415
|
+
function collectRuns(children, style, runs, theme, fields, localDeclared) {
|
|
416
|
+
for (const child of children) {
|
|
417
|
+
if (!hostChild(child)) throw new CapabilityError("invalid-text-child", "Text content tree contains invalid nodes");
|
|
418
|
+
if (isHostText(child)) {
|
|
419
|
+
if (child.text !== "") runs.push({
|
|
420
|
+
text: child.text,
|
|
421
|
+
style,
|
|
422
|
+
...localDeclared === void 0 ? {} : { localDeclared }
|
|
423
|
+
});
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (child.type !== "span" && child.type !== "sup" && child.type !== "sub" && child.type !== "slide-number") throw new CapabilityError("unsupported-text-child", `${child.type} cannot be used as text paragraph or run`);
|
|
427
|
+
const unknown = Object.keys(child.props).find((key) => key !== "style" && !textAuthorMetadataKeys.has(key));
|
|
428
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-parameter", `Span contains unimplemented parameter ${unknown}`);
|
|
429
|
+
const label = child.type === "sup" ? "Sup.style" : child.type === "sub" ? "Sub.style" : child.type === "slide-number" ? "SlideNumber.style" : "Span.style";
|
|
430
|
+
const parsedSpanStyle = readRunStyle(child.props["style"], label);
|
|
431
|
+
let spanStyle = parsedSpanStyle;
|
|
432
|
+
if (child.type === "sup" || child.type === "sub") {
|
|
433
|
+
const defaultShift = child.type === "sup" ? "30%" : "-25%";
|
|
434
|
+
const expectedMilli = child.type === "sup" ? 3e4 : -25e3;
|
|
435
|
+
const tagLabel = child.type === "sup" ? "Sup" : "Sub";
|
|
436
|
+
if (parsedSpanStyle.baselineShift !== void 0) {
|
|
437
|
+
if (parseBaselineShiftThousandths(parsedSpanStyle.baselineShift) !== expectedMilli) throw new CapabilityError("conflicting-baseline-shift", `${tagLabel} cannot declare conflicting baselineShift ${parsedSpanStyle.baselineShift}`, void 0, { field: "style.baselineShift" });
|
|
438
|
+
}
|
|
439
|
+
if (style.baselineShift !== void 0) {
|
|
440
|
+
if (parseBaselineShiftThousandths(style.baselineShift) !== expectedMilli) throw new CapabilityError("conflicting-baseline-shift", `${tagLabel} cannot be nested inside conflicting baselineShift ${style.baselineShift}`, void 0, { field: "style.baselineShift" });
|
|
441
|
+
}
|
|
442
|
+
spanStyle = {
|
|
443
|
+
...parsedSpanStyle,
|
|
444
|
+
baselineShift: defaultShift
|
|
445
|
+
};
|
|
446
|
+
} else if (parsedSpanStyle.baselineShift !== void 0 && style.baselineShift !== void 0) {
|
|
447
|
+
if (parseBaselineShiftThousandths(parsedSpanStyle.baselineShift) !== parseBaselineShiftThousandths(style.baselineShift)) throw new CapabilityError("conflicting-baseline-shift", `Nested baselineShift ${parsedSpanStyle.baselineShift} conflicts with inherited ${style.baselineShift}`, void 0, { field: "style.baselineShift" });
|
|
448
|
+
}
|
|
449
|
+
const nextStyle = mergeRunStyle(style, spanStyle, theme);
|
|
450
|
+
const nextLocalDeclared = localDeclared === void 0 ? void 0 : mergeLocalRunDeclared(localDeclared, spanStyle, theme);
|
|
451
|
+
if (child.type === "slide-number") {
|
|
452
|
+
if (child.children.length > 0) throw new CapabilityError("invalid-slide-number", "SlideNumber cannot contain children");
|
|
453
|
+
runs.push({
|
|
454
|
+
text: String(fields.slideNumber),
|
|
455
|
+
style: nextStyle,
|
|
456
|
+
...nextLocalDeclared === void 0 ? {} : { localDeclared: nextLocalDeclared },
|
|
457
|
+
field: {
|
|
458
|
+
id: fields.createId?.() ?? "00000000-0000-4000-8000-000000000001",
|
|
459
|
+
type: "slidenum"
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
collectRuns(child.children, nextStyle, runs, theme, fields, nextLocalDeclared);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function resolveDecoration(value) {
|
|
468
|
+
return value ?? "none";
|
|
469
|
+
}
|
|
470
|
+
function resolveTransform(value) {
|
|
471
|
+
return value ?? "none";
|
|
472
|
+
}
|
|
473
|
+
function resolveTextShadowModel(theme, value) {
|
|
474
|
+
if (value === void 0 || value === "none") return { kind: "none" };
|
|
475
|
+
return {
|
|
476
|
+
kind: "shadow",
|
|
477
|
+
shadow: resolveShadow(theme, value, "textShadow")
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function resolveAlign(value, fallback = "left") {
|
|
481
|
+
return value ?? fallback;
|
|
482
|
+
}
|
|
483
|
+
function resolveVerticalAlign(value) {
|
|
484
|
+
return value ?? "top";
|
|
485
|
+
}
|
|
486
|
+
function resolveListModel(value) {
|
|
487
|
+
if (value === void 0) return void 0;
|
|
488
|
+
switch (value.type) {
|
|
489
|
+
case "bullet": return {
|
|
490
|
+
type: "bullet",
|
|
491
|
+
character: value.character ?? "•",
|
|
492
|
+
level: value.level ?? 0
|
|
493
|
+
};
|
|
494
|
+
case "number": return {
|
|
495
|
+
type: "number",
|
|
496
|
+
style: value.style ?? "arabicPeriod",
|
|
497
|
+
startAt: value.startAt ?? 1,
|
|
498
|
+
level: value.level ?? 0
|
|
499
|
+
};
|
|
500
|
+
default: return value;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function decorationAttribute(decoration) {
|
|
504
|
+
switch (decoration) {
|
|
505
|
+
case "none": return [];
|
|
506
|
+
case "underline": return ["u=\"sng\""];
|
|
507
|
+
case "line-through": return ["strike=\"sngStrike\""];
|
|
508
|
+
default: return decoration;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function transformAttribute(transform) {
|
|
512
|
+
switch (transform) {
|
|
513
|
+
case "none": return [];
|
|
514
|
+
case "uppercase": return ["cap=\"all\""];
|
|
515
|
+
default: return transform;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function fontClassificationAttrsForRun(fontRef, themeFont, weight, faceStyle) {
|
|
519
|
+
if (themeFont !== void 0 || !isFont(fontRef)) return "";
|
|
520
|
+
const cls = resolveFontClassification(fontRef, weightValue(weight), faceStyle ?? "normal");
|
|
521
|
+
if (cls === void 0) return "";
|
|
522
|
+
return `${cls.panose === void 0 ? "" : ` panose="${cls.panose}"`} pitchFamily="${cls.pitchFamily}"`;
|
|
523
|
+
}
|
|
524
|
+
function runFontSlotsXml(style, differential = false) {
|
|
525
|
+
const hasLatin = style.fontFamily !== void 0 || style.themeFont !== void 0;
|
|
526
|
+
const hasEa = style.eastAsianFontFamily !== void 0 || style.eastAsianThemeFont !== void 0;
|
|
527
|
+
let latinXml = "";
|
|
528
|
+
let csXml = "";
|
|
529
|
+
if (!differential || hasLatin) {
|
|
530
|
+
const latinFont = normalizedFonts(style)[0];
|
|
531
|
+
const latinClsAttrs = fontClassificationAttrsForRun(style.fontFamily, style.themeFont, style.fontWeight, style.fontStyle);
|
|
532
|
+
const latinTypeface = style.themeFont === "major" ? "+mj-lt" : style.themeFont === "minor" ? "+mn-lt" : latinFont.family;
|
|
533
|
+
const csTypeface = style.themeFont === "major" ? "+mj-cs" : style.themeFont === "minor" ? "+mn-cs" : latinFont.family;
|
|
534
|
+
latinXml = `<a:latin typeface="${escapedXml(latinTypeface)}"${latinClsAttrs}/>`;
|
|
535
|
+
csXml = `<a:cs typeface="${escapedXml(csTypeface)}"/>`;
|
|
536
|
+
}
|
|
537
|
+
let eaXml = "";
|
|
538
|
+
if (!differential || hasEa) {
|
|
539
|
+
const eaRef = hasEa ? style.eastAsianFontFamily : style.fontFamily;
|
|
540
|
+
const eaTheme = hasEa ? style.eastAsianThemeFont : style.themeFont;
|
|
541
|
+
const eaFont = normalizedFontsForReference(eaRef, style.fontWeight, style.fontStyle)[0];
|
|
542
|
+
const eaClsAttrs = fontClassificationAttrsForRun(eaRef, eaTheme, style.fontWeight, style.fontStyle);
|
|
543
|
+
eaXml = `<a:ea typeface="${escapedXml(eaTheme === "major" ? "+mj-ea" : eaTheme === "minor" ? "+mn-ea" : eaFont.family)}"${eaClsAttrs}/>`;
|
|
544
|
+
}
|
|
545
|
+
return `${latinXml}${eaXml}${csXml}`;
|
|
546
|
+
}
|
|
547
|
+
function runPropertiesXml(style, tag, theme, differential = false) {
|
|
548
|
+
if (differential) {
|
|
549
|
+
const attributes = [];
|
|
550
|
+
if (style.lang !== void 0) attributes.push(`lang="${escapedXml(style.lang)}"`);
|
|
551
|
+
if (style.fontSize !== void 0) attributes.push(`sz="${centipoints(fontSizePoints(style.fontSize))}"`);
|
|
552
|
+
if (style.fontWeight !== void 0) {
|
|
553
|
+
const font = normalizedFonts(style)[0];
|
|
554
|
+
attributes.push(`b="${outputBold(font) ? 1 : 0}"`);
|
|
555
|
+
}
|
|
556
|
+
if (style.fontStyle !== void 0) attributes.push(`i="${style.fontStyle === "italic" ? 1 : 0}"`);
|
|
557
|
+
if (style.textDecoration !== void 0) attributes.push(...decorationAttribute(resolveDecoration(style.textDecoration)));
|
|
558
|
+
if (style.textTransform !== void 0) attributes.push(...transformAttribute(resolveTransform(style.textTransform)));
|
|
559
|
+
if (style.letterSpacing !== void 0) attributes.push(`spc="${letterSpacingCentipoints(style.letterSpacing)}"`);
|
|
560
|
+
if (style.baselineShift !== void 0) {
|
|
561
|
+
const baseline = parseBaselineShiftThousandths(style.baselineShift);
|
|
562
|
+
if (baseline !== void 0) attributes.push(`baseline="${baseline}"`);
|
|
563
|
+
}
|
|
564
|
+
const fillXml = style.color === void 0 ? "" : `<a:solidFill>${resolvedColorXml(isResolvedColor(style.color) ? style.color : theme.resolveColor(style.color))}</a:solidFill>`;
|
|
565
|
+
const shadowXml = style.textShadow === void 0 ? "" : style.textShadow === "none" ? "<a:effectLst/>" : textShadowXml(theme, style.textShadow);
|
|
566
|
+
const fontXml = style.fontFamily !== void 0 || style.themeFont !== void 0 || style.eastAsianFontFamily !== void 0 || style.eastAsianThemeFont !== void 0 ? runFontSlotsXml(style, true) : "";
|
|
567
|
+
const attrText = attributes.length === 0 ? "" : ` ${attributes.join(" ")}`;
|
|
568
|
+
const childrenXml = `${fillXml}${shadowXml}${fontXml}`;
|
|
569
|
+
return childrenXml === "" ? `<${tag}${attrText}/>` : `<${tag}${attrText}>${childrenXml}</${tag}>`;
|
|
570
|
+
}
|
|
571
|
+
const font = normalizedFonts(style)[0];
|
|
572
|
+
const points = fontSizePoints(style.fontSize);
|
|
573
|
+
const bold = outputBold(font);
|
|
574
|
+
const color = isResolvedColor(style.color) ? style.color : theme.resolveColor(style.color ?? "dk1");
|
|
575
|
+
const fontSlots = runFontSlotsXml(style);
|
|
576
|
+
const decoration = resolveDecoration(style.textDecoration);
|
|
577
|
+
const transform = resolveTransform(style.textTransform);
|
|
578
|
+
const baselineAttr = style.baselineShift === void 0 ? [] : (() => {
|
|
579
|
+
const baseline = parseBaselineShiftThousandths(style.baselineShift);
|
|
580
|
+
return baseline === void 0 ? [] : [`baseline="${baseline}"`];
|
|
581
|
+
})();
|
|
582
|
+
return `<${tag} ${[
|
|
583
|
+
...style.lang !== void 0 ? [`lang="${escapedXml(style.lang)}"`] : [],
|
|
584
|
+
`sz="${centipoints(points)}"`,
|
|
585
|
+
`b="${bold ? 1 : 0}"`,
|
|
586
|
+
`i="${font.style === "italic" ? 1 : 0}"`,
|
|
587
|
+
...decorationAttribute(decoration),
|
|
588
|
+
...transformAttribute(transform),
|
|
589
|
+
...style.letterSpacing === void 0 || style.letterSpacing === 0 ? [] : [`spc="${letterSpacingCentipoints(style.letterSpacing)}"`],
|
|
590
|
+
...baselineAttr
|
|
591
|
+
].join(" ")}><a:solidFill>${resolvedColorXml(color)}</a:solidFill>${textShadowXml(theme, style.textShadow)}${fontSlots}</${tag}>`;
|
|
592
|
+
}
|
|
593
|
+
function displayedText(run) {
|
|
594
|
+
return run.style.textTransform === "uppercase" ? run.text.toUpperCase() : run.text;
|
|
595
|
+
}
|
|
596
|
+
/** Emits a native `<a:fld type="slidenum">` run using a fresh or preallocated field GUID. */
|
|
597
|
+
function emitSlideNumberRunXml(run, theme, createFieldId, differential = false) {
|
|
598
|
+
const fieldId = createFieldId !== void 0 ? createFieldId() : run.field?.id ?? "00000000-0000-4000-8000-000000000001";
|
|
599
|
+
const fieldType = run.field?.type ?? "slidenum";
|
|
600
|
+
const rPr = differential ? runPropertiesXml(run.localDeclared ?? {}, "a:rPr", theme, true) : runPropertiesXml(run.style, "a:rPr", theme, false);
|
|
601
|
+
return `<a:fld id="${escapedXml(fieldId)}" type="${fieldType}">${rPr}<a:t>${escapedXml(run.text)}</a:t></a:fld>`;
|
|
602
|
+
}
|
|
603
|
+
function runXml(run, theme, differential = false) {
|
|
604
|
+
if (run.field !== void 0) return emitSlideNumberRunXml(run, theme, void 0, differential);
|
|
605
|
+
const text = escapedXml(run.text);
|
|
606
|
+
return `<a:r>${differential ? runPropertiesXml(run.localDeclared ?? {}, "a:rPr", theme, true) : runPropertiesXml(run.style, "a:rPr", theme, false)}<a:t xml:space="preserve">${text}</a:t></a:r>`;
|
|
607
|
+
}
|
|
608
|
+
function textResourceClaims(runs) {
|
|
609
|
+
const used = /* @__PURE__ */ new Map();
|
|
610
|
+
for (const run of runs) {
|
|
611
|
+
const scriptSegments = splitRunForEffectiveScripts(displayedText(run) + (run.field?.type === "slidenum" ? "0123456789" : ""), run.style);
|
|
612
|
+
for (const seg of scriptSegments) for (const font of normalizedFonts(seg.style)) {
|
|
613
|
+
const key = `${font.family.toLocaleLowerCase("en-US")}\u0000${font.weight}\u0000${font.style}`;
|
|
614
|
+
const entry = used.get(key) ?? {
|
|
615
|
+
fonts: [],
|
|
616
|
+
fontPolicies: /* @__PURE__ */ new Map(),
|
|
617
|
+
text: []
|
|
618
|
+
};
|
|
619
|
+
if (!entry.fonts.some(({ identity }) => identity === font.identity)) entry.fonts.push(font);
|
|
620
|
+
const policyKey = `${font.identity}\u0000${font.substitute ? 1 : 0}\u0000${font.embeddable ? 1 : 0}`;
|
|
621
|
+
entry.fontPolicies.set(policyKey, font);
|
|
622
|
+
entry.text.push(seg.text);
|
|
623
|
+
used.set(key, entry);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const resourceClaims = [];
|
|
627
|
+
const fontUses = [];
|
|
628
|
+
const fontUsages = [];
|
|
629
|
+
const missingGlyphErrors = [];
|
|
630
|
+
const missingResourceMap = /* @__PURE__ */ new Map();
|
|
631
|
+
const missingGlyphSets = /* @__PURE__ */ new Map();
|
|
632
|
+
const missingGlyphFonts = /* @__PURE__ */ new Map();
|
|
633
|
+
const referencedFontMap = /* @__PURE__ */ new Map();
|
|
634
|
+
for (const [key, entry] of used) {
|
|
635
|
+
for (const font of entry.fontPolicies.values()) fontUses.push({
|
|
636
|
+
family: font.family,
|
|
637
|
+
weight: font.weight,
|
|
638
|
+
style: font.style,
|
|
639
|
+
claimKey: key,
|
|
640
|
+
identity: font.identity,
|
|
641
|
+
...font.data === void 0 ? {} : { bytes: font.data },
|
|
642
|
+
substitute: font.substitute,
|
|
643
|
+
embeddable: font.embeddable,
|
|
644
|
+
bold: outputBold(font),
|
|
645
|
+
italic: font.style === "italic"
|
|
646
|
+
});
|
|
647
|
+
for (const font of entry.fonts) {
|
|
648
|
+
if (!referencedFontMap.has(key)) referencedFontMap.set(key, {
|
|
649
|
+
family: font.family,
|
|
650
|
+
weight: font.weight,
|
|
651
|
+
style: font.style
|
|
652
|
+
});
|
|
653
|
+
if (!font.hasResource) {
|
|
654
|
+
fontUsages.push({
|
|
655
|
+
family: font.family,
|
|
656
|
+
weight: font.weight,
|
|
657
|
+
style: font.style,
|
|
658
|
+
hasResource: false,
|
|
659
|
+
...font.substitute ? { substitute: true } : {}
|
|
660
|
+
});
|
|
661
|
+
if (!missingResourceMap.has(key)) missingResourceMap.set(key, {
|
|
662
|
+
family: font.family,
|
|
663
|
+
weight: font.weight,
|
|
664
|
+
style: font.style
|
|
665
|
+
});
|
|
666
|
+
} else {
|
|
667
|
+
const validatedFace = validateFontFaceResource({
|
|
668
|
+
family: font.family,
|
|
669
|
+
weight: font.weight,
|
|
670
|
+
style: font.style,
|
|
671
|
+
substitute: font.substitute,
|
|
672
|
+
data: font.data,
|
|
673
|
+
identity: font.identity
|
|
674
|
+
});
|
|
675
|
+
resourceClaims.push({
|
|
676
|
+
kind: "font-face",
|
|
677
|
+
key,
|
|
678
|
+
identity: font.identity,
|
|
679
|
+
characters: entry.text.join("")
|
|
680
|
+
});
|
|
681
|
+
const missing = findMissingFontGlyphs(validatedFace, entry.text.join(""), requiresVisibleFontGlyph);
|
|
682
|
+
const embeddable = isTrueTypeFontEmbeddable(font.data, font.family, font.substitute, font.embeddable, font.identity);
|
|
683
|
+
fontUsages.push({
|
|
684
|
+
family: font.family,
|
|
685
|
+
weight: font.weight,
|
|
686
|
+
style: font.style,
|
|
687
|
+
hasResource: true,
|
|
688
|
+
...font.substitute ? { substitute: true } : {},
|
|
689
|
+
embeddable,
|
|
690
|
+
...missing.length > 0 ? { missingGlyphs: missing } : {}
|
|
691
|
+
});
|
|
692
|
+
if (missing.length > 0) {
|
|
693
|
+
const set = missingGlyphSets.get(key) ?? /* @__PURE__ */ new Set();
|
|
694
|
+
for (const ch of missing) set.add(ch);
|
|
695
|
+
missingGlyphSets.set(key, set);
|
|
696
|
+
if (!missingGlyphFonts.has(key)) missingGlyphFonts.set(key, {
|
|
697
|
+
family: font.family,
|
|
698
|
+
weight: font.weight,
|
|
699
|
+
style: font.style
|
|
700
|
+
});
|
|
701
|
+
const shown = missing.slice(0, 10).join(" ");
|
|
702
|
+
const extra = missing.length - 10;
|
|
703
|
+
const message = `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`;
|
|
704
|
+
missingGlyphErrors.push({
|
|
705
|
+
message,
|
|
706
|
+
font: {
|
|
707
|
+
family: font.family,
|
|
708
|
+
weight: font.weight,
|
|
709
|
+
style: font.style
|
|
710
|
+
},
|
|
711
|
+
characters: missing
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
resourceClaims,
|
|
719
|
+
fontUses,
|
|
720
|
+
fontUsages,
|
|
721
|
+
missingGlyphErrors,
|
|
722
|
+
unmeasuredIssues: {
|
|
723
|
+
missingResourceFonts: [...missingResourceMap.values()],
|
|
724
|
+
missingGlyphFonts: [...missingGlyphFonts.entries()].map(([key, descriptor]) => ({
|
|
725
|
+
...descriptor,
|
|
726
|
+
missingGlyphs: [...missingGlyphSets.get(key) ?? []]
|
|
727
|
+
})),
|
|
728
|
+
referencedFonts: [...referencedFontMap.values()]
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function alignmentValue(value) {
|
|
733
|
+
if (value === void 0) return void 0;
|
|
734
|
+
switch (value) {
|
|
735
|
+
case "left": return "l";
|
|
736
|
+
case "center": return "ctr";
|
|
737
|
+
case "right": return "r";
|
|
738
|
+
case "justify": return "just";
|
|
739
|
+
default: return value;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function paragraphXml(paragraph, theme, differential = false) {
|
|
743
|
+
const style = differential ? paragraph.localStyle ?? {} : paragraph.style;
|
|
744
|
+
const { runs } = paragraph;
|
|
745
|
+
const attributes = [];
|
|
746
|
+
const align = alignmentValue(style.align);
|
|
747
|
+
if (align !== void 0) attributes.push(`algn="${align}"`);
|
|
748
|
+
if (paragraphBaseDirection(runs.map((run) => displayedText(run)).join("")) === "rtl") attributes.push("rtl=\"1\"");
|
|
749
|
+
const resolvedList = resolveListModel(style.list);
|
|
750
|
+
if (resolvedList !== void 0) attributes.push(`lvl="${resolvedList.level}"`);
|
|
751
|
+
if (!differential && paragraph.resolvedListIndent !== void 0) {
|
|
752
|
+
const marL = Math.min(51206400, Math.max(0, pxToEmu(paragraph.resolvedListIndent.marginLeft)));
|
|
753
|
+
const hangingEmu = Math.min(51206400, Math.max(0, pxToEmu(-paragraph.resolvedListIndent.indent)));
|
|
754
|
+
attributes.push(`marL="${marL}"`, `indent="${-hangingEmu}"`);
|
|
755
|
+
}
|
|
756
|
+
const lineSpacing = lineSpacingXml(style.lineHeight);
|
|
757
|
+
const spacingAfter = style.spacingAfter === void 0 || style.spacingAfter === 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
|
|
758
|
+
let list = "";
|
|
759
|
+
if (resolvedList !== void 0) switch (resolvedList.type) {
|
|
760
|
+
case "bullet":
|
|
761
|
+
list = `<a:buChar char="${xmlEscape(resolvedList.character)}"/>`;
|
|
762
|
+
break;
|
|
763
|
+
case "number":
|
|
764
|
+
list = `<a:buAutoNum type="${resolvedList.style}" startAt="${resolvedList.startAt}"/>`;
|
|
765
|
+
break;
|
|
766
|
+
default: return resolvedList;
|
|
767
|
+
}
|
|
768
|
+
const endStyle = differential ? paragraph.localEndStyle ?? {} : paragraph.endStyle;
|
|
769
|
+
let defRPr = "";
|
|
770
|
+
if (runs.length === 0) {
|
|
771
|
+
const candidate = runPropertiesXml(endStyle, "a:defRPr", theme, differential);
|
|
772
|
+
defRPr = differential && candidate === "<a:defRPr/>" ? "" : candidate;
|
|
773
|
+
}
|
|
774
|
+
const pPrChildren = `${lineSpacing}${spacingAfter}${list}${defRPr}`;
|
|
775
|
+
const pPr = attributes.length + pPrChildren.length === 0 ? "" : `<a:pPr${attributes.length === 0 ? "" : ` ${attributes.join(" ")}`}${pPrChildren.length === 0 ? "/>" : `>${pPrChildren}</a:pPr>`}`;
|
|
776
|
+
const endProperties = runs.length === 0 ? runPropertiesXml(endStyle, "a:rPr", theme, differential).replace(/<(\/?)a:rPr\b/gu, "<$1a:endParaRPr") : "";
|
|
777
|
+
return `<a:p>${pPr}${runs.map((run) => runXml(run, theme, differential)).join("")}${endProperties}</a:p>`;
|
|
778
|
+
}
|
|
779
|
+
function normalizeParagraphs(children, textStyle, theme, fields, placeholder, localSlideDeclaredStyle, allowParagraphMotion = false) {
|
|
780
|
+
const baseRunStyle = {
|
|
781
|
+
fontFamily: textStyle.fontFamily,
|
|
782
|
+
...textStyle.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: textStyle.eastAsianFontFamily },
|
|
783
|
+
fontSize: textStyle.fontSize,
|
|
784
|
+
fontWeight: textStyle.fontWeight,
|
|
785
|
+
fontStyle: textStyle.fontStyle,
|
|
786
|
+
color: textStyle.color,
|
|
787
|
+
themeFont: textStyle.themeFont,
|
|
788
|
+
...textStyle.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: textStyle.eastAsianThemeFont },
|
|
789
|
+
letterSpacing: textStyle.letterSpacing,
|
|
790
|
+
textTransform: textStyle.textTransform,
|
|
791
|
+
textDecoration: textStyle.textDecoration,
|
|
792
|
+
textShadow: textStyle.textShadow,
|
|
793
|
+
lang: textStyle.lang
|
|
794
|
+
};
|
|
795
|
+
validateRunStyle(baseRunStyle);
|
|
796
|
+
const localSlideRunDeclared = placeholder === void 0 ? void 0 : mergeLocalRunDeclared({}, localSlideDeclaredStyle ?? {}, placeholder.masterTheme);
|
|
797
|
+
const localSlidePStyle = placeholder === void 0 ? void 0 : {
|
|
798
|
+
...hasLocalDeclaration(localSlideDeclaredStyle, "lineHeight") ? { lineHeight: localSlideDeclaredStyle["lineHeight"] } : {},
|
|
799
|
+
...hasLocalDeclaration(localSlideDeclaredStyle, "align") ? { align: localSlideDeclaredStyle["align"] } : {},
|
|
800
|
+
...hasLocalDeclaration(localSlideDeclaredStyle, "spacingAfter") ? { spacingAfter: localSlideDeclaredStyle["spacingAfter"] } : {}
|
|
801
|
+
};
|
|
802
|
+
const paragraphs = [];
|
|
803
|
+
const paragraphMotions = [];
|
|
804
|
+
let inline = [];
|
|
805
|
+
const baseParagraphStyle = {
|
|
806
|
+
...textStyle.lineHeight === void 0 ? {} : { lineHeight: textStyle.lineHeight },
|
|
807
|
+
...textStyle.align === void 0 ? {} : { align: textStyle.align },
|
|
808
|
+
...textStyle.spacingAfter === void 0 ? {} : { spacingAfter: textStyle.spacingAfter },
|
|
809
|
+
...textStyle.lang === void 0 ? {} : { lang: textStyle.lang }
|
|
810
|
+
};
|
|
811
|
+
const flushInline = () => {
|
|
812
|
+
if (inline.length > 0) {
|
|
813
|
+
paragraphs.push({
|
|
814
|
+
runs: inline,
|
|
815
|
+
style: baseParagraphStyle,
|
|
816
|
+
...localSlidePStyle === void 0 ? {} : { localStyle: localSlidePStyle },
|
|
817
|
+
endStyle: baseRunStyle,
|
|
818
|
+
...localSlideRunDeclared === void 0 ? {} : { localEndStyle: localSlideRunDeclared },
|
|
819
|
+
wrap: textStyle.textWrap ?? "normal"
|
|
820
|
+
});
|
|
821
|
+
inline = [];
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
const appendParagraphNode = (node, currentStep) => {
|
|
825
|
+
flushInline();
|
|
826
|
+
const unknown = Object.keys(node.props).find((key) => key !== "style" && !textAuthorMetadataKeys.has(key) && !(allowParagraphMotion && motionPropKeySet.has(key)));
|
|
827
|
+
if (unknown !== void 0) {
|
|
828
|
+
if (motionPropKeySet.has(unknown)) throw new CapabilityError("unsupported-motion-host", "Paragraph motion properties are only supported inside page-level Text and Shape");
|
|
829
|
+
throw new CapabilityError("unknown-parameter", `P contains unimplemented parameter ${unknown}`);
|
|
830
|
+
}
|
|
831
|
+
if (allowParagraphMotion) {
|
|
832
|
+
const motionProps = pickMotionProps(node.props);
|
|
833
|
+
validateMotionFlag(motionProps["motion"]);
|
|
834
|
+
if (Object.keys(motionProps).length > 0) paragraphMotions.push({
|
|
835
|
+
paragraphIndex: paragraphs.length,
|
|
836
|
+
props: motionProps,
|
|
837
|
+
...currentStep === void 0 ? {} : { step: currentStep }
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const localPStyle = paragraphStyle(node.props["style"]);
|
|
841
|
+
const rawLevel = localPStyle.list?.level ?? 0;
|
|
842
|
+
const levelBase = placeholder === void 0 ? void 0 : resolvePlaceholderLevelTextStyle(placeholder, rawLevel, localSlideDeclaredStyle);
|
|
843
|
+
const effectiveTheme = placeholder?.masterTheme ?? theme;
|
|
844
|
+
const effectiveBaseP = levelBase === void 0 ? baseParagraphStyle : {
|
|
845
|
+
...levelBase.lineHeight === void 0 ? {} : { lineHeight: levelBase.lineHeight },
|
|
846
|
+
...levelBase.align === void 0 ? {} : { align: levelBase.align },
|
|
847
|
+
...levelBase.spacingAfter === void 0 ? {} : { spacingAfter: levelBase.spacingAfter },
|
|
848
|
+
...levelBase.lang === void 0 ? {} : { lang: levelBase.lang },
|
|
849
|
+
...levelBase.list === void 0 ? {} : { list: levelBase.list }
|
|
850
|
+
};
|
|
851
|
+
const levelRunBase = levelBase === void 0 ? baseRunStyle : resolveRunStyleFromRecord(levelBase, effectiveTheme);
|
|
852
|
+
const style = {
|
|
853
|
+
...effectiveBaseP,
|
|
854
|
+
...localPStyle
|
|
855
|
+
};
|
|
856
|
+
const paragraphRunStyle = mergeRunStyle(levelRunBase, {
|
|
857
|
+
fontFamily: style.fontFamily,
|
|
858
|
+
eastAsianFontFamily: style.eastAsianFontFamily,
|
|
859
|
+
fontSize: style.fontSize,
|
|
860
|
+
fontWeight: style.fontWeight,
|
|
861
|
+
fontStyle: style.fontStyle,
|
|
862
|
+
color: style.color,
|
|
863
|
+
letterSpacing: style.letterSpacing,
|
|
864
|
+
textTransform: style.textTransform,
|
|
865
|
+
textDecoration: style.textDecoration,
|
|
866
|
+
textShadow: style.textShadow,
|
|
867
|
+
lang: style.lang
|
|
868
|
+
}, effectiveTheme);
|
|
869
|
+
const mergedLocalPStyle = placeholder === void 0 ? void 0 : {
|
|
870
|
+
...localSlidePStyle,
|
|
871
|
+
...localPStyle
|
|
872
|
+
};
|
|
873
|
+
const localPRunDeclared = placeholder === void 0 ? void 0 : mergeLocalRunDeclared(localSlideRunDeclared ?? {}, localPStyle, effectiveTheme);
|
|
874
|
+
const runs = [];
|
|
875
|
+
collectRuns(node.children, paragraphRunStyle, runs, effectiveTheme, fields, localPRunDeclared);
|
|
876
|
+
paragraphs.push({
|
|
877
|
+
runs,
|
|
878
|
+
style,
|
|
879
|
+
...mergedLocalPStyle === void 0 ? {} : { localStyle: mergedLocalPStyle },
|
|
880
|
+
endStyle: paragraphRunStyle,
|
|
881
|
+
...localPRunDeclared === void 0 ? {} : { localEndStyle: localPRunDeclared },
|
|
882
|
+
wrap: textStyle.textWrap ?? "normal"
|
|
883
|
+
});
|
|
884
|
+
};
|
|
885
|
+
for (const child of children) {
|
|
886
|
+
if (!hostChild(child)) throw new CapabilityError("invalid-text-child", "Text content tree contains invalid nodes");
|
|
887
|
+
if (isHostText(child) || child.type === "span" || child.type === "sup" || child.type === "sub" || child.type === "slide-number") {
|
|
888
|
+
collectRuns([child], baseRunStyle, inline, theme, fields, localSlideRunDeclared);
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
if (child.type === "motion-step") {
|
|
892
|
+
if (!allowParagraphMotion) throw new CapabilityError("unsupported-text-child", "Step cannot be used directly inside this text container");
|
|
893
|
+
flushInline();
|
|
894
|
+
const step = parseStepDeclarationProps(child.props);
|
|
895
|
+
for (const nested of child.children) {
|
|
896
|
+
if (!hostChild(nested) || isHostText(nested) || nested.type !== "paragraph") throw new CapabilityError("unsupported-text-child", "Step inside Text or Shape can only contain P paragraphs");
|
|
897
|
+
appendParagraphNode(nested, step);
|
|
898
|
+
}
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
if (child.type !== "paragraph") throw new CapabilityError("unsupported-text-child", `${child.type} cannot be used directly in text box`);
|
|
902
|
+
appendParagraphNode(child);
|
|
903
|
+
}
|
|
904
|
+
flushInline();
|
|
905
|
+
if (paragraphs.length === 0) paragraphs.push({
|
|
906
|
+
runs: [],
|
|
907
|
+
style: baseParagraphStyle,
|
|
908
|
+
...localSlidePStyle === void 0 ? {} : { localStyle: localSlidePStyle },
|
|
909
|
+
endStyle: baseRunStyle,
|
|
910
|
+
...localSlideRunDeclared === void 0 ? {} : { localEndStyle: localSlideRunDeclared },
|
|
911
|
+
wrap: textStyle.textWrap ?? "normal"
|
|
912
|
+
});
|
|
913
|
+
return {
|
|
914
|
+
paragraphs,
|
|
915
|
+
paragraphMotions
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function fontDetailsFromSource(source) {
|
|
919
|
+
return { font: {
|
|
920
|
+
family: source.family,
|
|
921
|
+
weight: source.weight,
|
|
922
|
+
style: source.style
|
|
923
|
+
} };
|
|
924
|
+
}
|
|
925
|
+
function fontDetailsFromRunStyle(style) {
|
|
926
|
+
const normalized = normalizedFonts(style)[0];
|
|
927
|
+
if (normalized !== void 0) return {
|
|
928
|
+
family: normalized.family,
|
|
929
|
+
weight: normalized.weight,
|
|
930
|
+
style: normalized.style
|
|
931
|
+
};
|
|
932
|
+
return {
|
|
933
|
+
family: fontFamilyValue(style.fontFamily).family,
|
|
934
|
+
weight: weightValue(style.fontWeight),
|
|
935
|
+
style: style.fontStyle ?? "normal"
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function measureFace(source) {
|
|
939
|
+
if (!source.hasResource || source.data === void 0) throw new CapabilityError("font-measurement-unavailable", `Content-sized text is missing explicit font resource for ${source.family} ${source.weight} ${source.style}`, void 0, fontDetailsFromSource(source));
|
|
940
|
+
return openMeasureFontFace({
|
|
941
|
+
family: source.family,
|
|
942
|
+
weight: source.weight,
|
|
943
|
+
style: source.style,
|
|
944
|
+
substitute: source.substitute,
|
|
945
|
+
data: source.data,
|
|
946
|
+
identity: source.identity
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
function measureRunFace(style) {
|
|
950
|
+
const candidates = normalizedFonts(style).filter((candidate) => candidate.hasResource);
|
|
951
|
+
const unique = candidates.filter((candidate, index) => candidates.findIndex((other) => other.identity === candidate.identity) === index);
|
|
952
|
+
if (unique.length !== 1) {
|
|
953
|
+
const descriptor = fontDetailsFromRunStyle(style);
|
|
954
|
+
throw new CapabilityError(unique.length === 0 ? "font-measurement-unavailable" : "conflicting-resource", unique.length === 0 ? "Content-sized text must provide a font file for each actually used weight and style" : "Multiple metrics files found for the same font weight and style; cannot determine measurement basis", void 0, {
|
|
955
|
+
font: descriptor,
|
|
956
|
+
...unique.length === 0 ? {} : { reason: "conflicting-resource" }
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
return measureFace(unique[0]);
|
|
960
|
+
}
|
|
961
|
+
function missingCharacters(face, text) {
|
|
962
|
+
return findMissingFontGlyphs(face, text, requiresVisibleFontGlyph);
|
|
963
|
+
}
|
|
964
|
+
function rangeWidth(pieces, text, start, end) {
|
|
965
|
+
const nativeEighthPointGrid = 8;
|
|
966
|
+
const twipsPerPoint = 20;
|
|
967
|
+
let natural = 0;
|
|
968
|
+
let eighthPoint = 0;
|
|
969
|
+
let twips = 0;
|
|
970
|
+
let spacing = 0;
|
|
971
|
+
let hasVisibleGrapheme = false;
|
|
972
|
+
let pendingTracking = 0;
|
|
973
|
+
for (const piece of pieces) {
|
|
974
|
+
const from = Math.max(start, piece.start);
|
|
975
|
+
const to = Math.min(end, piece.end);
|
|
976
|
+
if (from >= to) continue;
|
|
977
|
+
const source = text.slice(from, to);
|
|
978
|
+
const transformed = piece.style.textTransform === "uppercase" ? source.toUpperCase() : source;
|
|
979
|
+
const visible = Array.from(transformed).filter(requiresFontGlyph).join("");
|
|
980
|
+
if (visible === "") continue;
|
|
981
|
+
const face = piece.face;
|
|
982
|
+
const advances = shapeFontAdvances(face, visible);
|
|
983
|
+
const unscaledPoints = fontSizePoints(piece.style.fontSize);
|
|
984
|
+
const points = piece.style.baselineShift !== void 0 ? unscaledPoints * .65 : unscaledPoints;
|
|
985
|
+
const tenths = Math.ceil(centipoints(points) / 10) / 10;
|
|
986
|
+
for (const xAdvance of advances) {
|
|
987
|
+
const advance = xAdvance / face.unitsPerEm * points;
|
|
988
|
+
natural += advance;
|
|
989
|
+
eighthPoint += Math.round(advance * nativeEighthPointGrid) / nativeEighthPointGrid;
|
|
990
|
+
const tenthAdvance = xAdvance / face.unitsPerEm * tenths;
|
|
991
|
+
twips += Math.round(tenthAdvance * twipsPerPoint) / twipsPerPoint;
|
|
992
|
+
}
|
|
993
|
+
const pieceTracking = piece.style.letterSpacing ?? 0;
|
|
994
|
+
const visibleCount = Array.from(graphemes.segment(visible)).length;
|
|
995
|
+
if (visibleCount > 0) {
|
|
996
|
+
if (hasVisibleGrapheme) spacing += pendingTracking;
|
|
997
|
+
spacing += pieceTracking * (visibleCount - 1);
|
|
998
|
+
hasVisibleGrapheme = true;
|
|
999
|
+
pendingTracking = pieceTracking;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return Math.max(natural, eighthPoint, twips) * (4 / 3) + spacing;
|
|
1003
|
+
}
|
|
1004
|
+
function trimLineEnd(text, start, end) {
|
|
1005
|
+
let trimmed = end;
|
|
1006
|
+
while (trimmed > start && /\s/u.test(text[trimmed - 1] ?? "")) trimmed -= 1;
|
|
1007
|
+
return trimmed;
|
|
1008
|
+
}
|
|
1009
|
+
function graphemeEnds(text, start, end) {
|
|
1010
|
+
const result = [];
|
|
1011
|
+
for (const segment of graphemes.segment(text)) {
|
|
1012
|
+
const boundary = segment.index + segment.segment.length;
|
|
1013
|
+
if (boundary > start && boundary <= end) result.push(boundary);
|
|
1014
|
+
}
|
|
1015
|
+
return result;
|
|
1016
|
+
}
|
|
1017
|
+
function trimMandatoryBreakEnd(text, start, end) {
|
|
1018
|
+
let trimmed = end;
|
|
1019
|
+
while (trimmed > start && /[\n\r\v\f\u0085\u2028\u2029]/u.test(text[trimmed - 1] ?? "")) trimmed -= 1;
|
|
1020
|
+
return trimmed;
|
|
1021
|
+
}
|
|
1022
|
+
function wrapParagraph(text, pieces, width) {
|
|
1023
|
+
if (text === "") return {
|
|
1024
|
+
lines: [{
|
|
1025
|
+
start: 0,
|
|
1026
|
+
end: 0,
|
|
1027
|
+
width: 0
|
|
1028
|
+
}],
|
|
1029
|
+
width: 0
|
|
1030
|
+
};
|
|
1031
|
+
const breaks = [];
|
|
1032
|
+
const breaker = new LineBreaker(text);
|
|
1033
|
+
let position = 0;
|
|
1034
|
+
for (let next = breaker.nextBreak(); next !== null; next = breaker.nextBreak()) {
|
|
1035
|
+
if (next.position > position) breaks.push(next);
|
|
1036
|
+
position = next.position;
|
|
1037
|
+
}
|
|
1038
|
+
if (position < text.length) breaks.push({
|
|
1039
|
+
position: text.length,
|
|
1040
|
+
required: false
|
|
1041
|
+
});
|
|
1042
|
+
const lines = [];
|
|
1043
|
+
const epsilon = .01;
|
|
1044
|
+
let lineStart = 0;
|
|
1045
|
+
let lineEnd = 0;
|
|
1046
|
+
let unitStart = 0;
|
|
1047
|
+
let endedWithRequiredBreak = false;
|
|
1048
|
+
for (const lineBreak of breaks) {
|
|
1049
|
+
const unitEnd = lineBreak.position;
|
|
1050
|
+
const breakContentEnd = trimMandatoryBreakEnd(text, unitStart, unitEnd);
|
|
1051
|
+
const required = lineBreak.required || breakContentEnd < unitEnd;
|
|
1052
|
+
if (rangeWidth(pieces, text, lineStart, trimLineEnd(text, lineStart, unitEnd)) <= width + epsilon) {
|
|
1053
|
+
lineEnd = unitEnd;
|
|
1054
|
+
if (required) {
|
|
1055
|
+
lines.push({
|
|
1056
|
+
start: lineStart,
|
|
1057
|
+
end: lineEnd
|
|
1058
|
+
});
|
|
1059
|
+
lineStart = unitEnd;
|
|
1060
|
+
lineEnd = unitEnd;
|
|
1061
|
+
}
|
|
1062
|
+
unitStart = unitEnd;
|
|
1063
|
+
endedWithRequiredBreak = required;
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
if (lineEnd > lineStart) {
|
|
1067
|
+
lines.push({
|
|
1068
|
+
start: lineStart,
|
|
1069
|
+
end: lineEnd
|
|
1070
|
+
});
|
|
1071
|
+
lineStart = unitStart;
|
|
1072
|
+
lineEnd = unitStart;
|
|
1073
|
+
}
|
|
1074
|
+
if (rangeWidth(pieces, text, unitStart, trimLineEnd(text, unitStart, unitEnd)) <= width + epsilon) lineEnd = unitEnd;
|
|
1075
|
+
else {
|
|
1076
|
+
let chunkStart = unitStart;
|
|
1077
|
+
let previous = chunkStart;
|
|
1078
|
+
const fallbackEnd = required ? breakContentEnd : unitEnd;
|
|
1079
|
+
for (const boundary of graphemeEnds(text, unitStart, fallbackEnd)) {
|
|
1080
|
+
if (rangeWidth(pieces, text, chunkStart, trimLineEnd(text, chunkStart, boundary)) > width + epsilon && previous > chunkStart) {
|
|
1081
|
+
lines.push({
|
|
1082
|
+
start: chunkStart,
|
|
1083
|
+
end: previous
|
|
1084
|
+
});
|
|
1085
|
+
chunkStart = previous;
|
|
1086
|
+
}
|
|
1087
|
+
if (rangeWidth(pieces, text, chunkStart, trimLineEnd(text, chunkStart, boundary)) > width + epsilon && previous === chunkStart) {
|
|
1088
|
+
lines.push({
|
|
1089
|
+
start: chunkStart,
|
|
1090
|
+
end: boundary
|
|
1091
|
+
});
|
|
1092
|
+
chunkStart = boundary;
|
|
1093
|
+
}
|
|
1094
|
+
previous = boundary;
|
|
1095
|
+
}
|
|
1096
|
+
lineStart = chunkStart;
|
|
1097
|
+
lineEnd = fallbackEnd;
|
|
1098
|
+
}
|
|
1099
|
+
if (required) {
|
|
1100
|
+
if (lineEnd > lineStart) lines.push({
|
|
1101
|
+
start: lineStart,
|
|
1102
|
+
end: lineEnd
|
|
1103
|
+
});
|
|
1104
|
+
lineStart = unitEnd;
|
|
1105
|
+
lineEnd = unitEnd;
|
|
1106
|
+
}
|
|
1107
|
+
unitStart = unitEnd;
|
|
1108
|
+
endedWithRequiredBreak = required;
|
|
1109
|
+
}
|
|
1110
|
+
if (lineStart < text.length || lineEnd > lineStart || lines.length === 0) lines.push({
|
|
1111
|
+
start: lineStart,
|
|
1112
|
+
end: text.length
|
|
1113
|
+
});
|
|
1114
|
+
else if (endedWithRequiredBreak) lines.push({
|
|
1115
|
+
start: text.length,
|
|
1116
|
+
end: text.length
|
|
1117
|
+
});
|
|
1118
|
+
const lineWidths = lines.map(({ start, end }) => rangeWidth(pieces, text, start, trimLineEnd(text, start, end)));
|
|
1119
|
+
return {
|
|
1120
|
+
lines: lines.map((line, index) => ({
|
|
1121
|
+
...line,
|
|
1122
|
+
width: lineWidths[index]
|
|
1123
|
+
})),
|
|
1124
|
+
width: Math.max(0, ...lineWidths)
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
function paragraphLineHeight(paragraph) {
|
|
1128
|
+
if (paragraph.style.lineHeight !== void 0 && !isLineHeightPercent(paragraph.style.lineHeight)) return spacingCentipoints(positiveLength(paragraph.style.lineHeight, "lineHeight"), "lineHeight") / 75;
|
|
1129
|
+
const styles = paragraph.runs.length > 0 ? paragraph.runs.flatMap((run) => run.text === "" ? [run.style] : splitRunForEffectiveScripts(displayedText(run), run.style).map((seg) => seg.style)) : [paragraph.endStyle];
|
|
1130
|
+
let maximum = 0;
|
|
1131
|
+
for (const style of styles) {
|
|
1132
|
+
const face = measureRunFace(style);
|
|
1133
|
+
const lineHeight = (face.ascent - face.descent + face.lineGap) / face.unitsPerEm * fontSizePoints(style.fontSize) * (4 / 3);
|
|
1134
|
+
if (!Number.isFinite(lineHeight) || lineHeight <= 0) throw new CapabilityError("font-metrics-invalid", "Font line metrics must produce a finite positive value", void 0, {
|
|
1135
|
+
font: fontDetailsFromRunStyle(style),
|
|
1136
|
+
reason: "font-metrics-invalid"
|
|
1137
|
+
});
|
|
1138
|
+
maximum = Math.max(maximum, lineHeight);
|
|
1139
|
+
}
|
|
1140
|
+
if (maximum === 0) throw new CapabilityError("font-measurement-unavailable", "Content-sized text is missing font to determine line spacing", void 0, { font: fontDetailsFromRunStyle(paragraph.endStyle) });
|
|
1141
|
+
if (paragraph.style.lineHeight !== void 0) {
|
|
1142
|
+
const factor = lineHeightPercentThousandths(paragraph.style.lineHeight) / 1e5;
|
|
1143
|
+
const scaled = maximum * factor;
|
|
1144
|
+
if (!Number.isFinite(scaled) || scaled <= 0) throw new CapabilityError("font-metrics-invalid", "Font line metrics must produce a finite positive value");
|
|
1145
|
+
return scaled;
|
|
1146
|
+
}
|
|
1147
|
+
return spacingCentipoints(maximum, "lineHeight") / 75;
|
|
1148
|
+
}
|
|
1149
|
+
function paragraphBaseline(paragraph) {
|
|
1150
|
+
if (paragraph.runs.length !== 1 || paragraph.runs[0].text === "") return;
|
|
1151
|
+
const run = paragraph.runs[0];
|
|
1152
|
+
const segments = splitRunForEffectiveScripts(displayedText(run), run.style);
|
|
1153
|
+
if (segments.length !== 1) return;
|
|
1154
|
+
const style = segments[0].style;
|
|
1155
|
+
const face = measureRunFace(style);
|
|
1156
|
+
const fontSize = fontSizePoints(style.fontSize) * (4 / 3);
|
|
1157
|
+
const naturalLineHeight = (face.ascent - face.descent + face.lineGap) / face.unitsPerEm * fontSize;
|
|
1158
|
+
const leading = (paragraphLineHeight(paragraph) - naturalLineHeight) / 2;
|
|
1159
|
+
return face.ascent / face.unitsPerEm * fontSize + leading;
|
|
1160
|
+
}
|
|
1161
|
+
function paragraphPieces(paragraph) {
|
|
1162
|
+
const sourceRuns = paragraph.runs.length > 0 ? paragraph.runs : [{
|
|
1163
|
+
text: "",
|
|
1164
|
+
style: paragraph.endStyle
|
|
1165
|
+
}];
|
|
1166
|
+
const pieces = [];
|
|
1167
|
+
let start = 0;
|
|
1168
|
+
for (const run of sourceRuns) {
|
|
1169
|
+
const segments = splitRunForEffectiveScripts(displayedText(run), run.style);
|
|
1170
|
+
for (const seg of segments) {
|
|
1171
|
+
const face = measureRunFace(seg.style);
|
|
1172
|
+
const letterSpacing = seg.style.letterSpacing === void 0 ? void 0 : letterSpacingCentipoints(seg.style.letterSpacing) / 75;
|
|
1173
|
+
const measureStyle = letterSpacing === void 0 ? seg.style : {
|
|
1174
|
+
...seg.style,
|
|
1175
|
+
letterSpacing
|
|
1176
|
+
};
|
|
1177
|
+
pieces.push({
|
|
1178
|
+
text: seg.text,
|
|
1179
|
+
style: measureStyle,
|
|
1180
|
+
start,
|
|
1181
|
+
end: start + seg.text.length,
|
|
1182
|
+
face
|
|
1183
|
+
});
|
|
1184
|
+
start += seg.text.length;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return {
|
|
1188
|
+
text: pieces.map((piece) => piece.text).join(""),
|
|
1189
|
+
pieces
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function computeDefaultListIndentMetrics(paragraph) {
|
|
1193
|
+
const resolvedList = resolveListModel(paragraph.style.list);
|
|
1194
|
+
if (resolvedList === void 0) return void 0;
|
|
1195
|
+
const baseFontPx = fontSizePoints((paragraph.runs[0]?.style ?? paragraph.endStyle).fontSize) * 4 / 3;
|
|
1196
|
+
const hangingIndent = Math.max(baseFontPx * 1.25, 20);
|
|
1197
|
+
const levelIndent = resolvedList.level * (baseFontPx * 1.5);
|
|
1198
|
+
return {
|
|
1199
|
+
levelIndent,
|
|
1200
|
+
hangingIndent,
|
|
1201
|
+
contentIndent: levelIndent + hangingIndent,
|
|
1202
|
+
baseFontPx
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
function listIndentMetrics(paragraph) {
|
|
1206
|
+
const defaults = computeDefaultListIndentMetrics(paragraph);
|
|
1207
|
+
if (defaults === void 0) return {
|
|
1208
|
+
levelIndent: 0,
|
|
1209
|
+
hangingIndent: 0,
|
|
1210
|
+
contentIndent: 0,
|
|
1211
|
+
baseFontPx: 0
|
|
1212
|
+
};
|
|
1213
|
+
if (paragraph.resolvedListIndent !== void 0) {
|
|
1214
|
+
const hangingIndent = Math.max(0, -paragraph.resolvedListIndent.indent);
|
|
1215
|
+
const contentIndent = Math.max(0, paragraph.resolvedListIndent.marginLeft);
|
|
1216
|
+
return {
|
|
1217
|
+
levelIndent: Math.max(0, contentIndent - hangingIndent),
|
|
1218
|
+
hangingIndent,
|
|
1219
|
+
contentIndent,
|
|
1220
|
+
baseFontPx: defaults.baseFontPx
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
return defaults;
|
|
1224
|
+
}
|
|
1225
|
+
function paragraphMinContentWidth(paragraph) {
|
|
1226
|
+
const { text, pieces } = paragraphPieces(paragraph);
|
|
1227
|
+
const { contentIndent } = listIndentMetrics(paragraph);
|
|
1228
|
+
if (text === "") return contentIndent;
|
|
1229
|
+
if (paragraph.wrap === "nowrap") return wrapParagraph(text, pieces, Number.MAX_VALUE).width + contentIndent;
|
|
1230
|
+
const breaker = new LineBreaker(text);
|
|
1231
|
+
let start = 0;
|
|
1232
|
+
let widest = 0;
|
|
1233
|
+
for (let next = breaker.nextBreak(); next !== null; next = breaker.nextBreak()) {
|
|
1234
|
+
const contentEnd = trimMandatoryBreakEnd(text, start, next.position);
|
|
1235
|
+
widest = Math.max(widest, rangeWidth(pieces, text, start, trimLineEnd(text, start, contentEnd)));
|
|
1236
|
+
start = next.position;
|
|
1237
|
+
}
|
|
1238
|
+
return widest + contentIndent;
|
|
1239
|
+
}
|
|
1240
|
+
function paragraphMeasurement(paragraph, width) {
|
|
1241
|
+
const { text, pieces } = paragraphPieces(paragraph);
|
|
1242
|
+
const { contentIndent } = listIndentMetrics(paragraph);
|
|
1243
|
+
const wrapped = wrapParagraph(text, pieces, paragraph.wrap === "nowrap" ? Number.MAX_VALUE : Math.max(1, width - contentIndent));
|
|
1244
|
+
const spacingAfter = paragraph.style.spacingAfter === void 0 ? 0 : spacingCentipoints(paragraph.style.spacingAfter, "spacingAfter") / 75;
|
|
1245
|
+
return {
|
|
1246
|
+
lineCount: wrapped.lines.length,
|
|
1247
|
+
lines: wrapped.lines,
|
|
1248
|
+
text,
|
|
1249
|
+
pieces,
|
|
1250
|
+
width: wrapped.width + contentIndent,
|
|
1251
|
+
lineHeight: paragraphLineHeight(paragraph),
|
|
1252
|
+
spacingAfter
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function assertParagraphsHaveVisibleGlyphs(paragraphs) {
|
|
1256
|
+
for (const paragraph of paragraphs) {
|
|
1257
|
+
for (const run of paragraph.runs) {
|
|
1258
|
+
const textToCheck = displayedText(run) + (run.field?.type === "slidenum" ? "0123456789" : "");
|
|
1259
|
+
if (!Array.from(textToCheck).some(requiresVisibleFontGlyph)) continue;
|
|
1260
|
+
for (const seg of splitRunForEffectiveScripts(textToCheck, run.style)) {
|
|
1261
|
+
if (!Array.from(seg.text).some(requiresVisibleFontGlyph)) continue;
|
|
1262
|
+
const missing = missingCharacters(measureRunFace(seg.style), seg.text);
|
|
1263
|
+
if (missing.length > 0) {
|
|
1264
|
+
const font = fontDetailsFromRunStyle(seg.style);
|
|
1265
|
+
const shown = missing.slice(0, 10).join(" ");
|
|
1266
|
+
const extra = missing.length - 10;
|
|
1267
|
+
throw new CapabilityError("font-missing-glyph", `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`, void 0, {
|
|
1268
|
+
font,
|
|
1269
|
+
characters: missing
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
const list = paragraph.style.list;
|
|
1275
|
+
if (list !== void 0) {
|
|
1276
|
+
const markerText = list.type === "bullet" ? list.character ?? "•" : "0123456789.";
|
|
1277
|
+
const markerStyle = paragraph.runs[0]?.style ?? paragraph.endStyle;
|
|
1278
|
+
for (const seg of splitRunForEffectiveScripts(markerText, markerStyle)) {
|
|
1279
|
+
const missing = missingCharacters(measureRunFace(seg.style), seg.text);
|
|
1280
|
+
if (missing.length > 0) {
|
|
1281
|
+
const font = fontDetailsFromRunStyle(seg.style);
|
|
1282
|
+
const shown = missing.slice(0, 10).join(" ");
|
|
1283
|
+
const extra = missing.length - 10;
|
|
1284
|
+
throw new CapabilityError("font-missing-glyph", `${font.family} is missing glyphs for characters ${shown}${extra > 0 ? `, and ${extra} more characters` : ""}`, void 0, {
|
|
1285
|
+
font,
|
|
1286
|
+
characters: missing
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
function measureParagraphs(paragraphs, width) {
|
|
1294
|
+
assertParagraphsHaveVisibleGlyphs(paragraphs);
|
|
1295
|
+
const measured = paragraphs.map((paragraph) => paragraphMeasurement(paragraph, width));
|
|
1296
|
+
let height = 0;
|
|
1297
|
+
measured.forEach((paragraph, index) => {
|
|
1298
|
+
height += paragraph.lineCount * paragraph.lineHeight;
|
|
1299
|
+
if (index < measured.length - 1) height += paragraph.spacingAfter;
|
|
1300
|
+
});
|
|
1301
|
+
return {
|
|
1302
|
+
width: Math.max(0, ...measured.map((paragraph) => paragraph.width)),
|
|
1303
|
+
height,
|
|
1304
|
+
paragraphs: measured
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
function roundSvgNumber(value) {
|
|
1308
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
1309
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
1310
|
+
}
|
|
1311
|
+
function decorationForSegment(decoration, face, fontPx, startX, endX, color, textShadow) {
|
|
1312
|
+
if (endX <= startX) return void 0;
|
|
1313
|
+
const unitsPerEm = face.unitsPerEm;
|
|
1314
|
+
switch (decoration) {
|
|
1315
|
+
case "none": return;
|
|
1316
|
+
case "underline": {
|
|
1317
|
+
const thickness = Math.max(1, face.underlineThickness ? face.underlineThickness / unitsPerEm * fontPx : fontPx * .07);
|
|
1318
|
+
return {
|
|
1319
|
+
x: startX,
|
|
1320
|
+
y: (face.underlinePosition ? -face.underlinePosition / unitsPerEm * fontPx : fontPx * .12) - thickness / 2,
|
|
1321
|
+
width: endX - startX,
|
|
1322
|
+
height: thickness,
|
|
1323
|
+
color,
|
|
1324
|
+
...textShadow === void 0 ? {} : { textShadow }
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
case "line-through": {
|
|
1328
|
+
const thickness = Math.max(1, face.yStrikeoutSize ? face.yStrikeoutSize / unitsPerEm * fontPx : fontPx * .07);
|
|
1329
|
+
return {
|
|
1330
|
+
x: startX,
|
|
1331
|
+
y: -(face.yStrikeoutPosition ? face.yStrikeoutPosition / unitsPerEm * fontPx : fontPx * .3) - thickness / 2,
|
|
1332
|
+
width: endX - startX,
|
|
1333
|
+
height: thickness,
|
|
1334
|
+
color,
|
|
1335
|
+
...textShadow === void 0 ? {} : { textShadow }
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
default: return decoration;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function bidiCharType(ch) {
|
|
1342
|
+
if (ch === "") return "R";
|
|
1343
|
+
if (ch === "") return "L";
|
|
1344
|
+
if (/^\p{Mark}$/u.test(ch)) return "NSM";
|
|
1345
|
+
if (/^[\u0660-\u0669\u06F0-\u06F9]$/u.test(ch)) return "AN";
|
|
1346
|
+
if (/^\p{Nd}$/u.test(ch)) return "EN";
|
|
1347
|
+
if (/^[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\uFB50-\uFDFF\uFE70-\uFEFF]$/u.test(ch) && /^\p{Letter}$/u.test(ch)) return "AL";
|
|
1348
|
+
if (/^[\p{Script=Hebrew}\uFB1D-\uFB4F]$/u.test(ch) && /^\p{Letter}$/u.test(ch)) return "R";
|
|
1349
|
+
if (/^\p{Letter}$/u.test(ch)) return "L";
|
|
1350
|
+
if (ch === "+" || ch === "-" || ch === "−") return "ES";
|
|
1351
|
+
if (ch === "," || ch === "." || ch === ":" || ch === "/") return "CS";
|
|
1352
|
+
if (ch === "%" || /^\p{Sc}$/u.test(ch)) return "ET";
|
|
1353
|
+
return "ON";
|
|
1354
|
+
}
|
|
1355
|
+
function paragraphBaseDirection(text) {
|
|
1356
|
+
for (const ch of text) {
|
|
1357
|
+
const type = bidiCharType(ch);
|
|
1358
|
+
if (type === "R" || type === "AL") return "rtl";
|
|
1359
|
+
if (type === "L") return "ltr";
|
|
1360
|
+
}
|
|
1361
|
+
return "ltr";
|
|
1362
|
+
}
|
|
1363
|
+
function computeLineBidiLevels(lineText, baseOffset, baseDir) {
|
|
1364
|
+
const cps = [];
|
|
1365
|
+
let offset = baseOffset;
|
|
1366
|
+
for (const ch of lineText) {
|
|
1367
|
+
cps.push({
|
|
1368
|
+
start: offset,
|
|
1369
|
+
end: offset + ch.length,
|
|
1370
|
+
ch
|
|
1371
|
+
});
|
|
1372
|
+
offset += ch.length;
|
|
1373
|
+
}
|
|
1374
|
+
const n = cps.length;
|
|
1375
|
+
if (n === 0) return [];
|
|
1376
|
+
const embeddingLevel = baseDir === "rtl" ? 1 : 0;
|
|
1377
|
+
const dirStrong = embeddingLevel === 0 ? "L" : "R";
|
|
1378
|
+
const types = cps.map((cp) => bidiCharType(cp.ch));
|
|
1379
|
+
let prevW1 = dirStrong;
|
|
1380
|
+
for (let i = 0; i < n; i += 1) if (types[i] === "NSM") types[i] = prevW1;
|
|
1381
|
+
else prevW1 = types[i];
|
|
1382
|
+
let lastStrongW2 = dirStrong;
|
|
1383
|
+
for (let i = 0; i < n; i += 1) {
|
|
1384
|
+
const t = types[i];
|
|
1385
|
+
if (t === "L" || t === "R" || t === "AL") lastStrongW2 = t;
|
|
1386
|
+
else if (t === "EN" && lastStrongW2 === "AL") types[i] = "AN";
|
|
1387
|
+
}
|
|
1388
|
+
for (let i = 0; i < n; i += 1) if (types[i] === "AL") types[i] = "R";
|
|
1389
|
+
for (let i = 1; i < n - 1; i += 1) {
|
|
1390
|
+
const t = types[i];
|
|
1391
|
+
const prev = types[i - 1];
|
|
1392
|
+
const next = types[i + 1];
|
|
1393
|
+
if (t === "ES" && prev === "EN" && next === "EN") types[i] = "EN";
|
|
1394
|
+
else if (t === "CS" && (prev === "EN" && next === "EN" || prev === "AN" && next === "AN")) types[i] = prev;
|
|
1395
|
+
}
|
|
1396
|
+
for (let i = 0; i < n; i += 1) {
|
|
1397
|
+
if (types[i] !== "ET") continue;
|
|
1398
|
+
let end = i;
|
|
1399
|
+
while (end < n && types[end] === "ET") end += 1;
|
|
1400
|
+
const prevEn = i > 0 && types[i - 1] === "EN";
|
|
1401
|
+
const nextEn = end < n && types[end] === "EN";
|
|
1402
|
+
if (prevEn || nextEn) for (let k = i; k < end; k += 1) types[k] = "EN";
|
|
1403
|
+
i = end - 1;
|
|
1404
|
+
}
|
|
1405
|
+
for (let i = 0; i < n; i += 1) {
|
|
1406
|
+
const t = types[i];
|
|
1407
|
+
if (t === "ES" || t === "ET" || t === "CS") types[i] = "ON";
|
|
1408
|
+
}
|
|
1409
|
+
let lastStrongW7 = dirStrong;
|
|
1410
|
+
for (let i = 0; i < n; i += 1) {
|
|
1411
|
+
const t = types[i];
|
|
1412
|
+
if (t === "L" || t === "R") lastStrongW7 = t;
|
|
1413
|
+
else if (t === "EN" && lastStrongW7 === "L") types[i] = "L";
|
|
1414
|
+
}
|
|
1415
|
+
const neutralEffective = (t) => {
|
|
1416
|
+
if (t === "L") return "L";
|
|
1417
|
+
if (t === "R" || t === "EN" || t === "AN") return "R";
|
|
1418
|
+
};
|
|
1419
|
+
for (let i = 0; i < n; i += 1) {
|
|
1420
|
+
if (types[i] !== "ON") continue;
|
|
1421
|
+
let end = i;
|
|
1422
|
+
while (end < n && types[end] === "ON") end += 1;
|
|
1423
|
+
const leftSide = i === 0 ? dirStrong : neutralEffective(types[i - 1]) ?? dirStrong;
|
|
1424
|
+
const resolved = leftSide === (end === n ? dirStrong : neutralEffective(types[end]) ?? dirStrong) ? leftSide : dirStrong;
|
|
1425
|
+
for (let k = i; k < end; k += 1) types[k] = resolved;
|
|
1426
|
+
i = end - 1;
|
|
1427
|
+
}
|
|
1428
|
+
return cps.map((cp, index) => {
|
|
1429
|
+
const t = types[index];
|
|
1430
|
+
let level;
|
|
1431
|
+
if (embeddingLevel === 0) level = t === "L" ? 0 : t === "R" ? 1 : 2;
|
|
1432
|
+
else level = t === "R" ? 1 : 2;
|
|
1433
|
+
return {
|
|
1434
|
+
start: cp.start,
|
|
1435
|
+
end: cp.end,
|
|
1436
|
+
level
|
|
1437
|
+
};
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
function buildVisualLineSegments(text, lineStart, trimmedEnd, pieces, baseDir) {
|
|
1441
|
+
if (lineStart >= trimmedEnd) return [];
|
|
1442
|
+
const spans = computeLineBidiLevels(text.slice(lineStart, trimmedEnd), lineStart, baseDir);
|
|
1443
|
+
const segments = [];
|
|
1444
|
+
let spanIdx = 0;
|
|
1445
|
+
for (const piece of pieces) {
|
|
1446
|
+
const pStart = Math.max(lineStart, piece.start);
|
|
1447
|
+
const pEnd = Math.min(trimmedEnd, piece.end);
|
|
1448
|
+
if (pStart >= pEnd) continue;
|
|
1449
|
+
while (spanIdx < spans.length && spans[spanIdx].end <= pStart) spanIdx += 1;
|
|
1450
|
+
let segStart = pStart;
|
|
1451
|
+
let currentLevel;
|
|
1452
|
+
while (spanIdx < spans.length && spans[spanIdx].start < pEnd) {
|
|
1453
|
+
const sp = spans[spanIdx];
|
|
1454
|
+
if (currentLevel === void 0) {
|
|
1455
|
+
currentLevel = sp.level;
|
|
1456
|
+
segStart = Math.max(pStart, sp.start);
|
|
1457
|
+
} else if (sp.level !== currentLevel) {
|
|
1458
|
+
const segEnd = Math.min(pEnd, sp.start);
|
|
1459
|
+
if (segEnd > segStart) segments.push({
|
|
1460
|
+
text: text.slice(segStart, segEnd),
|
|
1461
|
+
piece,
|
|
1462
|
+
level: currentLevel,
|
|
1463
|
+
isRtl: currentLevel % 2 === 1
|
|
1464
|
+
});
|
|
1465
|
+
currentLevel = sp.level;
|
|
1466
|
+
segStart = segEnd;
|
|
1467
|
+
}
|
|
1468
|
+
if (sp.end <= pEnd) spanIdx += 1;
|
|
1469
|
+
else break;
|
|
1470
|
+
}
|
|
1471
|
+
if (currentLevel !== void 0 && pEnd > segStart) segments.push({
|
|
1472
|
+
text: text.slice(segStart, pEnd),
|
|
1473
|
+
piece,
|
|
1474
|
+
level: currentLevel,
|
|
1475
|
+
isRtl: currentLevel % 2 === 1
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
const maxLevel = Math.max(0, ...segments.map((seg) => seg.level));
|
|
1479
|
+
for (let lvl = maxLevel; lvl >= 1; lvl -= 1) {
|
|
1480
|
+
let i = 0;
|
|
1481
|
+
while (i < segments.length) {
|
|
1482
|
+
if (segments[i].level < lvl) {
|
|
1483
|
+
i += 1;
|
|
1484
|
+
continue;
|
|
1485
|
+
}
|
|
1486
|
+
let j = i;
|
|
1487
|
+
while (j < segments.length && segments[j].level >= lvl) j += 1;
|
|
1488
|
+
let left = i;
|
|
1489
|
+
let right = j - 1;
|
|
1490
|
+
while (left < right) {
|
|
1491
|
+
const tmp = segments[left];
|
|
1492
|
+
segments[left] = segments[right];
|
|
1493
|
+
segments[right] = tmp;
|
|
1494
|
+
left += 1;
|
|
1495
|
+
right -= 1;
|
|
1496
|
+
}
|
|
1497
|
+
i = j;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
return segments;
|
|
1501
|
+
}
|
|
1502
|
+
function shapeSegmentOutlines(face, text, isRtl, lang) {
|
|
1503
|
+
const visible = Array.from(text).filter(requiresFontGlyph).join("");
|
|
1504
|
+
if (visible === "") return [];
|
|
1505
|
+
return shapeFontOutlines(face, visible, isRtl, lang);
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Converts font-measurement/outline unavailability errors encountered during paint()
|
|
1509
|
+
* into `preview-missing-font` or `preview-unsupported-font` while preserving `resolve()` error semantics.
|
|
1510
|
+
*/
|
|
1511
|
+
function withPreviewFontBoundary(fn) {
|
|
1512
|
+
try {
|
|
1513
|
+
return fn();
|
|
1514
|
+
} catch (error) {
|
|
1515
|
+
if (error instanceof CapabilityError) {
|
|
1516
|
+
if (error.code === "preview-missing-font" || error.code === "preview-unsupported-font" || error.code === "preview-missing-glyph") throw error;
|
|
1517
|
+
if (error.code === "font-measurement-unavailable") throw new CapabilityError("preview-missing-font", "Preview requires an explicit monochrome outline font file for each used font weight and style", error.path, error.details);
|
|
1518
|
+
if (error.code === "font-missing-glyph") throw new CapabilityError("preview-missing-glyph", error.message, error.path, error.details);
|
|
1519
|
+
if (error.code === "font-format-unsupported" || error.code === "unsupported-font-format" || error.code === "font-substitution-required" || error.code === "font-face-mismatch" || error.code === "font-weight-mismatch" || error.code === "font-style-mismatch" || error.code === "font-metrics-invalid" || error.code === "conflicting-resource") throw new CapabilityError("preview-unsupported-font", error.message, error.path, error.details);
|
|
1520
|
+
}
|
|
1521
|
+
throw error;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Extracts vector glyph outlines for one paragraph using its formal measurement / line-break ranges.
|
|
1526
|
+
* Coordinates are relative to each line's baseline, in pixels.
|
|
1527
|
+
*/
|
|
1528
|
+
function previewParagraphOutlines(paragraph, widthOrMeasured) {
|
|
1529
|
+
const { measured, text, pieces, baseDir } = withPreviewFontBoundary(() => {
|
|
1530
|
+
const resolvedMeasured = typeof widthOrMeasured === "number" ? paragraphMeasurement(paragraph, widthOrMeasured) : widthOrMeasured;
|
|
1531
|
+
for (const piece of resolvedMeasured.pieces) if (piece.face.hasColorOrBitmapTable) throw new CapabilityError("preview-unsupported-font", "Preview requires monochrome outline fonts", void 0, {
|
|
1532
|
+
font: fontDetailsFromRunStyle(piece.style),
|
|
1533
|
+
reason: "color-or-bitmap-font"
|
|
1534
|
+
});
|
|
1535
|
+
return {
|
|
1536
|
+
measured: resolvedMeasured,
|
|
1537
|
+
text: resolvedMeasured.text,
|
|
1538
|
+
pieces: resolvedMeasured.pieces,
|
|
1539
|
+
baseDir: paragraphBaseDirection(resolvedMeasured.text)
|
|
1540
|
+
};
|
|
1541
|
+
});
|
|
1542
|
+
return {
|
|
1543
|
+
lines: measured.lines.map((line, lineIndex) => {
|
|
1544
|
+
let cursor = 0;
|
|
1545
|
+
let pendingTracking = 0;
|
|
1546
|
+
const glyphs = [];
|
|
1547
|
+
const decorations = [];
|
|
1548
|
+
let ascent = 0;
|
|
1549
|
+
let descent = 0;
|
|
1550
|
+
const trimmedEnd = trimLineEnd(text, line.start, line.end);
|
|
1551
|
+
buildVisualLineSegments(text, line.start, trimmedEnd, pieces, baseDir).forEach((seg, segIndex) => {
|
|
1552
|
+
const { piece } = seg;
|
|
1553
|
+
const missing = missingCharacters(piece.face, seg.text);
|
|
1554
|
+
if (missing.length > 0) throw new CapabilityError("preview-missing-glyph", "Preview requires every visible glyph in the supplied font", void 0, {
|
|
1555
|
+
font: fontDetailsFromRunStyle(piece.style),
|
|
1556
|
+
characters: missing
|
|
1557
|
+
});
|
|
1558
|
+
const shaped = shapeSegmentOutlines(piece.face, seg.text, seg.isRtl, piece.style.lang);
|
|
1559
|
+
if (shaped.length === 0) return;
|
|
1560
|
+
const face = piece.face;
|
|
1561
|
+
const unscaledFontPx = fontSizePoints(piece.style.fontSize) * 4 / 3;
|
|
1562
|
+
const baselineMilli = piece.style.baselineShift !== void 0 ? parseBaselineShiftThousandths(piece.style.baselineShift) : void 0;
|
|
1563
|
+
const fontPx = baselineMilli !== void 0 ? unscaledFontPx * .65 : unscaledFontPx;
|
|
1564
|
+
const scale = fontPx / face.unitsPerEm;
|
|
1565
|
+
const unscaledScale = unscaledFontPx / face.unitsPerEm;
|
|
1566
|
+
const baselineShiftPx = baselineMilli !== void 0 ? -(baselineMilli / 1e5) * unscaledFontPx : 0;
|
|
1567
|
+
const trackingPx = piece.style.letterSpacing ?? 0;
|
|
1568
|
+
ascent = Math.max(ascent, face.ascent * unscaledScale);
|
|
1569
|
+
descent = Math.max(descent, -face.descent * unscaledScale);
|
|
1570
|
+
let segStartX;
|
|
1571
|
+
let segEndX = cursor;
|
|
1572
|
+
const glyphStart = glyphs.length;
|
|
1573
|
+
let lastCluster;
|
|
1574
|
+
let clusterHadAdvance = false;
|
|
1575
|
+
for (const item of shaped) {
|
|
1576
|
+
if (lastCluster !== void 0 && item.cluster !== lastCluster) {
|
|
1577
|
+
if (clusterHadAdvance && pendingTracking !== 0) {
|
|
1578
|
+
cursor += pendingTracking;
|
|
1579
|
+
pendingTracking = 0;
|
|
1580
|
+
}
|
|
1581
|
+
clusterHadAdvance = false;
|
|
1582
|
+
} else if (lastCluster === void 0 && pendingTracking !== 0) {
|
|
1583
|
+
cursor += pendingTracking;
|
|
1584
|
+
pendingTracking = 0;
|
|
1585
|
+
}
|
|
1586
|
+
lastCluster = item.cluster;
|
|
1587
|
+
if (segStartX === void 0) segStartX = cursor;
|
|
1588
|
+
glyphs.push({
|
|
1589
|
+
path: item.path,
|
|
1590
|
+
x: cursor + item.xOffset * scale,
|
|
1591
|
+
y: baselineShiftPx - item.yOffset * scale,
|
|
1592
|
+
scale,
|
|
1593
|
+
color: piece.style.color,
|
|
1594
|
+
...piece.style.textShadow === void 0 ? {} : { textShadow: piece.style.textShadow },
|
|
1595
|
+
isSpace: item.isSpace && item.xAdvance > 0,
|
|
1596
|
+
clusterKey: `${segIndex}:${item.cluster}`
|
|
1597
|
+
});
|
|
1598
|
+
cursor += item.xAdvance * scale;
|
|
1599
|
+
segEndX = cursor;
|
|
1600
|
+
if (item.xAdvance > 0) {
|
|
1601
|
+
clusterHadAdvance = true;
|
|
1602
|
+
pendingTracking = trackingPx;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
const glyphEnd = glyphs.length;
|
|
1606
|
+
if (segStartX !== void 0 && glyphEnd > glyphStart) {
|
|
1607
|
+
const decoration = decorationForSegment(resolveDecoration(piece.style.textDecoration), face, fontPx, segStartX, segEndX, piece.style.color, piece.style.textShadow);
|
|
1608
|
+
if (decoration !== void 0) decorations.push({
|
|
1609
|
+
...decoration,
|
|
1610
|
+
y: decoration.y + baselineShiftPx,
|
|
1611
|
+
glyphStart,
|
|
1612
|
+
glyphEnd
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
if (glyphs.length === 0 && pieces.length > 0) {
|
|
1617
|
+
const fallbackPiece = pieces[0];
|
|
1618
|
+
const fallbackFace = fallbackPiece.face;
|
|
1619
|
+
const fallbackScale = fontSizePoints(fallbackPiece.style.fontSize) * 4 / (3 * fallbackFace.unitsPerEm);
|
|
1620
|
+
ascent = fallbackFace.ascent * fallbackScale;
|
|
1621
|
+
descent = -fallbackFace.descent * fallbackScale;
|
|
1622
|
+
}
|
|
1623
|
+
const endsWithMandatoryBreak = trimMandatoryBreakEnd(text, line.start, line.end) < line.end || line.end < text.length && /[\n\r\v\f\u0085\u2028\u2029]/u.test(text[line.end] ?? "");
|
|
1624
|
+
const canJustify = lineIndex < measured.lines.length - 1 && !endsWithMandatoryBreak;
|
|
1625
|
+
return {
|
|
1626
|
+
...line,
|
|
1627
|
+
glyphs,
|
|
1628
|
+
...decorations.length === 0 ? {} : { decorations },
|
|
1629
|
+
ascent,
|
|
1630
|
+
descent,
|
|
1631
|
+
advance: cursor,
|
|
1632
|
+
canJustify
|
|
1633
|
+
};
|
|
1634
|
+
}),
|
|
1635
|
+
lineHeight: measured.lineHeight,
|
|
1636
|
+
spacingAfter: measured.spacingAfter,
|
|
1637
|
+
baseDir
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
function applyJustifyLine(line, availableWidth) {
|
|
1641
|
+
const slack = availableWidth - line.advance;
|
|
1642
|
+
if (!line.canJustify || slack <= .01 || line.glyphs.length <= 1) return {
|
|
1643
|
+
glyphs: line.glyphs,
|
|
1644
|
+
decorations: line.decorations,
|
|
1645
|
+
advance: line.advance
|
|
1646
|
+
};
|
|
1647
|
+
const count = line.glyphs.length;
|
|
1648
|
+
const deltaBefore = Array.from({ length: count }).fill(0);
|
|
1649
|
+
const spaceCount = line.glyphs.filter((g) => g.isSpace === true).length;
|
|
1650
|
+
if (spaceCount > 0) {
|
|
1651
|
+
const extraPerSpace = slack / spaceCount;
|
|
1652
|
+
let cumulative = 0;
|
|
1653
|
+
for (let i = 0; i < count; i += 1) {
|
|
1654
|
+
deltaBefore[i] = cumulative;
|
|
1655
|
+
if (line.glyphs[i].isSpace === true) cumulative += extraPerSpace;
|
|
1656
|
+
}
|
|
1657
|
+
} else {
|
|
1658
|
+
let clusterTransitions = 0;
|
|
1659
|
+
for (let i = 1; i < count; i += 1) if (line.glyphs[i].clusterKey !== line.glyphs[i - 1].clusterKey) clusterTransitions += 1;
|
|
1660
|
+
if (clusterTransitions <= 0) return {
|
|
1661
|
+
glyphs: line.glyphs,
|
|
1662
|
+
decorations: line.decorations,
|
|
1663
|
+
advance: line.advance
|
|
1664
|
+
};
|
|
1665
|
+
const extraPerCluster = slack / clusterTransitions;
|
|
1666
|
+
let cumulative = 0;
|
|
1667
|
+
for (let i = 1; i < count; i += 1) {
|
|
1668
|
+
if (line.glyphs[i].clusterKey !== line.glyphs[i - 1].clusterKey) cumulative += extraPerCluster;
|
|
1669
|
+
deltaBefore[i] = cumulative;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
return {
|
|
1673
|
+
glyphs: line.glyphs.map((glyph, index) => ({
|
|
1674
|
+
...glyph,
|
|
1675
|
+
x: glyph.x + deltaBefore[index]
|
|
1676
|
+
})),
|
|
1677
|
+
decorations: line.decorations?.map((deco) => {
|
|
1678
|
+
const gStart = deco.glyphStart ?? 0;
|
|
1679
|
+
const gEnd = deco.glyphEnd ?? count;
|
|
1680
|
+
const startDelta = deltaBefore[gStart] ?? 0;
|
|
1681
|
+
const endDelta = gEnd < count ? deltaBefore[gEnd] ?? 0 : deltaBefore[Math.max(gStart, gEnd - 1)] ?? 0;
|
|
1682
|
+
return {
|
|
1683
|
+
...deco,
|
|
1684
|
+
x: deco.x + startDelta,
|
|
1685
|
+
width: deco.width + (endDelta - startDelta)
|
|
1686
|
+
};
|
|
1687
|
+
}),
|
|
1688
|
+
advance: availableWidth
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
function shapeListPrefix(paragraph, prefixText) {
|
|
1692
|
+
const segments = splitRunForEffectiveScripts(prefixText, paragraph.runs[0]?.style ?? paragraph.endStyle);
|
|
1693
|
+
let cursor = 0;
|
|
1694
|
+
const glyphs = [];
|
|
1695
|
+
for (const seg of segments) {
|
|
1696
|
+
const prefixFace = withPreviewFontBoundary(() => {
|
|
1697
|
+
const face = measureRunFace(seg.style);
|
|
1698
|
+
if (face.hasColorOrBitmapTable) throw new CapabilityError("preview-unsupported-font", "Preview requires monochrome outline fonts", void 0, {
|
|
1699
|
+
font: fontDetailsFromRunStyle(seg.style),
|
|
1700
|
+
reason: "color-or-bitmap-font"
|
|
1701
|
+
});
|
|
1702
|
+
return face;
|
|
1703
|
+
});
|
|
1704
|
+
const missingPrefix = missingCharacters(prefixFace, seg.text);
|
|
1705
|
+
if (missingPrefix.length > 0) throw new CapabilityError("preview-missing-glyph", "Preview requires every visible glyph in the supplied font", void 0, {
|
|
1706
|
+
font: fontDetailsFromRunStyle(seg.style),
|
|
1707
|
+
characters: missingPrefix
|
|
1708
|
+
});
|
|
1709
|
+
const shaped = shapeSegmentOutlines(prefixFace, seg.text, false, seg.style.lang);
|
|
1710
|
+
const scale = fontSizePoints(seg.style.fontSize) * 4 / (3 * prefixFace.unitsPerEm);
|
|
1711
|
+
for (const item of shaped) {
|
|
1712
|
+
glyphs.push({
|
|
1713
|
+
path: item.path,
|
|
1714
|
+
x: cursor + item.xOffset * scale,
|
|
1715
|
+
y: -item.yOffset * scale,
|
|
1716
|
+
scale,
|
|
1717
|
+
color: seg.style.color,
|
|
1718
|
+
...seg.style.textShadow === void 0 ? {} : { textShadow: seg.style.textShadow }
|
|
1719
|
+
});
|
|
1720
|
+
cursor += item.xAdvance * scale;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return {
|
|
1724
|
+
glyphs,
|
|
1725
|
+
advance: cursor
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Positions paragraph glyph outlines inside a compiled box with insets, horizontal alignment,
|
|
1730
|
+
* and vertical alignment. Reuses pre-computed formal build line measurements when provided.
|
|
1731
|
+
*/
|
|
1732
|
+
function previewTextBoxOutlines(options) {
|
|
1733
|
+
const { paragraphs, box, insets = {
|
|
1734
|
+
top: 0,
|
|
1735
|
+
right: 0,
|
|
1736
|
+
bottom: 0,
|
|
1737
|
+
left: 0
|
|
1738
|
+
}, verticalAlign: rawVerticalAlign, measuredLayout } = options;
|
|
1739
|
+
const verticalAlign = resolveVerticalAlign(rawVerticalAlign);
|
|
1740
|
+
const innerWidth = Math.max(0, box.width - insets.left - insets.right);
|
|
1741
|
+
const useBoundMeasurement = measuredLayout !== void 0 && measuredLayout.paragraphs.length === paragraphs.length;
|
|
1742
|
+
const outlinedParagraphs = paragraphs.map((paragraph, index) => ({
|
|
1743
|
+
paragraph,
|
|
1744
|
+
layout: previewParagraphOutlines(paragraph, useBoundMeasurement ? measuredLayout.paragraphs[index] : innerWidth)
|
|
1745
|
+
}));
|
|
1746
|
+
const totalHeight = outlinedParagraphs.reduce((total, { layout }, index) => total + layout.lines.length * layout.lineHeight + (index < outlinedParagraphs.length - 1 ? layout.spacingAfter : 0), 0);
|
|
1747
|
+
const freeHeight = box.height - insets.top - insets.bottom - totalHeight;
|
|
1748
|
+
let top = box.y + insets.top + (verticalAlign === "middle" ? freeHeight / 2 : verticalAlign === "bottom" ? freeHeight : 0);
|
|
1749
|
+
const activeNumberSeq = /* @__PURE__ */ new Map();
|
|
1750
|
+
return outlinedParagraphs.flatMap(({ paragraph, layout }) => {
|
|
1751
|
+
const resolvedList = resolveListModel(paragraph.style.list);
|
|
1752
|
+
let prefixText;
|
|
1753
|
+
if (resolvedList === void 0) activeNumberSeq.clear();
|
|
1754
|
+
else switch (resolvedList.type) {
|
|
1755
|
+
case "bullet":
|
|
1756
|
+
for (const key of activeNumberSeq.keys()) if (key >= resolvedList.level) activeNumberSeq.delete(key);
|
|
1757
|
+
prefixText = resolvedList.character;
|
|
1758
|
+
break;
|
|
1759
|
+
case "number": {
|
|
1760
|
+
for (const key of activeNumberSeq.keys()) if (key > resolvedList.level) activeNumberSeq.delete(key);
|
|
1761
|
+
const existing = activeNumberSeq.get(resolvedList.level);
|
|
1762
|
+
if (existing !== void 0 && existing.startAt === resolvedList.startAt) existing.current += 1;
|
|
1763
|
+
else activeNumberSeq.set(resolvedList.level, {
|
|
1764
|
+
startAt: resolvedList.startAt,
|
|
1765
|
+
current: resolvedList.startAt
|
|
1766
|
+
});
|
|
1767
|
+
prefixText = `${activeNumberSeq.get(resolvedList.level).current}.`;
|
|
1768
|
+
break;
|
|
1769
|
+
}
|
|
1770
|
+
default: return resolvedList;
|
|
1771
|
+
}
|
|
1772
|
+
const listPrefix = prefixText === void 0 ? void 0 : shapeListPrefix(paragraph, prefixText);
|
|
1773
|
+
const listIndent = listIndentMetrics(paragraph);
|
|
1774
|
+
const availableLineWidth = Math.max(1, innerWidth - listIndent.contentIndent);
|
|
1775
|
+
const align = resolveAlign(paragraph.style.align, layout.baseDir === "rtl" ? "right" : "left");
|
|
1776
|
+
const lines = layout.lines.map((line, lineIndex) => {
|
|
1777
|
+
const justified = align === "justify" ? applyJustifyLine(line, availableLineWidth) : {
|
|
1778
|
+
glyphs: line.glyphs,
|
|
1779
|
+
decorations: line.decorations,
|
|
1780
|
+
advance: line.advance
|
|
1781
|
+
};
|
|
1782
|
+
let horizontalOffset;
|
|
1783
|
+
let prefixOffset = 0;
|
|
1784
|
+
if (layout.baseDir === "rtl" && resolvedList !== void 0) switch (align) {
|
|
1785
|
+
case "center":
|
|
1786
|
+
horizontalOffset = (availableLineWidth - justified.advance) / 2;
|
|
1787
|
+
prefixOffset = horizontalOffset + justified.advance + .4 * listIndent.baseFontPx;
|
|
1788
|
+
break;
|
|
1789
|
+
case "left":
|
|
1790
|
+
case "justify":
|
|
1791
|
+
horizontalOffset = 0;
|
|
1792
|
+
prefixOffset = innerWidth - listIndent.levelIndent - (listPrefix?.advance ?? 0);
|
|
1793
|
+
break;
|
|
1794
|
+
case "right":
|
|
1795
|
+
horizontalOffset = availableLineWidth - justified.advance;
|
|
1796
|
+
prefixOffset = innerWidth - listIndent.levelIndent - (listPrefix?.advance ?? 0);
|
|
1797
|
+
break;
|
|
1798
|
+
default: return align;
|
|
1799
|
+
}
|
|
1800
|
+
else switch (align) {
|
|
1801
|
+
case "center":
|
|
1802
|
+
horizontalOffset = listIndent.contentIndent + (availableLineWidth - justified.advance) / 2;
|
|
1803
|
+
prefixOffset = horizontalOffset - (listPrefix?.advance ?? 0) - .4 * listIndent.baseFontPx;
|
|
1804
|
+
break;
|
|
1805
|
+
case "right":
|
|
1806
|
+
horizontalOffset = listIndent.contentIndent + (availableLineWidth - justified.advance);
|
|
1807
|
+
prefixOffset = horizontalOffset - (listPrefix?.advance ?? 0) - .4 * listIndent.baseFontPx;
|
|
1808
|
+
break;
|
|
1809
|
+
case "left":
|
|
1810
|
+
case "justify":
|
|
1811
|
+
horizontalOffset = listIndent.contentIndent;
|
|
1812
|
+
prefixOffset = listIndent.levelIndent;
|
|
1813
|
+
break;
|
|
1814
|
+
default: return align;
|
|
1815
|
+
}
|
|
1816
|
+
const left = box.x + insets.left + horizontalOffset;
|
|
1817
|
+
const baseline = top + line.ascent + (layout.lineHeight - line.ascent - line.descent) / 2;
|
|
1818
|
+
top += layout.lineHeight;
|
|
1819
|
+
const prefixGlyphs = lineIndex === 0 && listPrefix !== void 0 ? listPrefix.glyphs.map((glyph) => ({
|
|
1820
|
+
...glyph,
|
|
1821
|
+
x: box.x + insets.left + prefixOffset + glyph.x,
|
|
1822
|
+
y: baseline + glyph.y
|
|
1823
|
+
})) : [];
|
|
1824
|
+
return {
|
|
1825
|
+
start: line.start,
|
|
1826
|
+
end: line.end,
|
|
1827
|
+
baseline,
|
|
1828
|
+
glyphs: [...prefixGlyphs, ...justified.glyphs.map((glyph) => ({
|
|
1829
|
+
...glyph,
|
|
1830
|
+
x: left + glyph.x,
|
|
1831
|
+
y: baseline + glyph.y
|
|
1832
|
+
}))],
|
|
1833
|
+
...justified.decorations === void 0 ? {} : { decorations: justified.decorations.map((deco) => ({
|
|
1834
|
+
...deco,
|
|
1835
|
+
x: left + deco.x,
|
|
1836
|
+
y: baseline + deco.y
|
|
1837
|
+
})) }
|
|
1838
|
+
};
|
|
1839
|
+
});
|
|
1840
|
+
top += layout.spacingAfter;
|
|
1841
|
+
return lines;
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
/** Serializes a single positioned glyph outline to an SVG path element. */
|
|
1845
|
+
function renderGlyphPathSvg(glyph, theme) {
|
|
1846
|
+
if (glyph.path === "") return "";
|
|
1847
|
+
const color = isResolvedColor(glyph.color) ? glyph.color : theme.resolveColor(glyph.color ?? "tx1");
|
|
1848
|
+
return `<path d="${xmlEscape(glyph.path)}" fill="#${color.hex}" fill-opacity="${color.alpha ?? 1}" transform="translate(${glyph.x} ${glyph.y}) scale(${glyph.scale} ${-glyph.scale})"/>`;
|
|
1849
|
+
}
|
|
1850
|
+
function renderDecorationRectSvg(deco, theme) {
|
|
1851
|
+
const color = isResolvedColor(deco.color) ? deco.color : theme.resolveColor(deco.color ?? "tx1");
|
|
1852
|
+
return `<rect x="${roundSvgNumber(deco.x)}" y="${roundSvgNumber(deco.y)}" width="${roundSvgNumber(deco.width)}" height="${roundSvgNumber(deco.height)}" fill="#${color.hex}" fill-opacity="${color.alpha ?? 1}"/>`;
|
|
1853
|
+
}
|
|
1854
|
+
/** Renders box-level positioned glyph outlines into SVG path fragments without importing textCapability. */
|
|
1855
|
+
function renderTextOutlinesSvg(options) {
|
|
1856
|
+
const { theme, idPrefix = "txt", rotate = 0, ...layoutOptions } = options;
|
|
1857
|
+
const lines = previewTextBoxOutlines(layoutOptions);
|
|
1858
|
+
const defs = [];
|
|
1859
|
+
const shadowFilterIds = /* @__PURE__ */ new Map();
|
|
1860
|
+
let shadowIndex = 0;
|
|
1861
|
+
const filterIdForShadow = (rawShadow) => {
|
|
1862
|
+
const resolved = resolveTextShadowModel(theme, rawShadow);
|
|
1863
|
+
switch (resolved.kind) {
|
|
1864
|
+
case "none": return;
|
|
1865
|
+
case "shadow": {
|
|
1866
|
+
const { shadow } = resolved;
|
|
1867
|
+
const rad = shadow.angle * Math.PI / 180;
|
|
1868
|
+
const worldDx = shadow.distance * Math.cos(rad);
|
|
1869
|
+
const worldDy = shadow.distance * Math.sin(rad);
|
|
1870
|
+
const rotRad = -rotate * Math.PI / 180;
|
|
1871
|
+
const localDx = worldDx * Math.cos(rotRad) - worldDy * Math.sin(rotRad);
|
|
1872
|
+
const localDy = worldDx * Math.sin(rotRad) + worldDy * Math.cos(rotRad);
|
|
1873
|
+
const sigma = shadow.blur / 2;
|
|
1874
|
+
const alpha = shadow.color.alpha ?? 1;
|
|
1875
|
+
const key = `${shadow.color.hex}:${roundSvgNumber(alpha)}:${roundSvgNumber(sigma)}:${roundSvgNumber(localDx)}:${roundSvgNumber(localDy)}`;
|
|
1876
|
+
const existing = shadowFilterIds.get(key);
|
|
1877
|
+
if (existing !== void 0) return existing;
|
|
1878
|
+
const id = `${idPrefix}-tshdw-${shadowIndex++}`;
|
|
1879
|
+
shadowFilterIds.set(key, id);
|
|
1880
|
+
const pad = shadow.blur * 3 + Math.abs(localDx) + Math.abs(localDy) + 64;
|
|
1881
|
+
const fx = roundSvgNumber(options.box.x - pad);
|
|
1882
|
+
const fy = roundSvgNumber(options.box.y - pad);
|
|
1883
|
+
const fw = roundSvgNumber(options.box.width + pad * 2);
|
|
1884
|
+
const fh = roundSvgNumber(options.box.height + pad * 2);
|
|
1885
|
+
defs.push(`<filter id="${id}" filterUnits="userSpaceOnUse" x="${fx}" y="${fy}" width="${fw}" height="${fh}"><feDropShadow dx="${roundSvgNumber(localDx)}" dy="${roundSvgNumber(localDy)}" stdDeviation="${roundSvgNumber(sigma)}" flood-color="#${shadow.color.hex}" flood-opacity="${roundSvgNumber(alpha)}"/></filter>`);
|
|
1886
|
+
return id;
|
|
1887
|
+
}
|
|
1888
|
+
default: return resolved;
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
const parts = [];
|
|
1892
|
+
let activeFilter;
|
|
1893
|
+
let activeGroup = [];
|
|
1894
|
+
const flushGroup = () => {
|
|
1895
|
+
if (activeGroup.length === 0) return;
|
|
1896
|
+
const joined = activeGroup.join("");
|
|
1897
|
+
parts.push(activeFilter === void 0 ? joined : `<g filter="url(#${activeFilter})">${joined}</g>`);
|
|
1898
|
+
activeGroup = [];
|
|
1899
|
+
};
|
|
1900
|
+
const pushElement = (elementSvg, rawShadow) => {
|
|
1901
|
+
if (elementSvg === "") return;
|
|
1902
|
+
const filterId = filterIdForShadow(rawShadow);
|
|
1903
|
+
if (filterId !== activeFilter) {
|
|
1904
|
+
flushGroup();
|
|
1905
|
+
activeFilter = filterId;
|
|
1906
|
+
}
|
|
1907
|
+
activeGroup.push(elementSvg);
|
|
1908
|
+
};
|
|
1909
|
+
for (const line of lines) {
|
|
1910
|
+
for (const glyph of line.glyphs) pushElement(renderGlyphPathSvg(glyph, theme), glyph.textShadow);
|
|
1911
|
+
for (const deco of line.decorations ?? []) pushElement(renderDecorationRectSvg(deco, theme), deco.textShadow);
|
|
1912
|
+
}
|
|
1913
|
+
flushGroup();
|
|
1914
|
+
return `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${parts.join("")}`;
|
|
1915
|
+
}
|
|
1916
|
+
/** Returns layout dimensions based on actual fonts and line breaking rules from normalized paragraphs. */
|
|
1917
|
+
function measureTextLayoutFromParagraphs(paragraphs, style, availableWidth) {
|
|
1918
|
+
const measured = measureParagraphs(paragraphs, availableWidth ?? Number.POSITIVE_INFINITY);
|
|
1919
|
+
const minContentWidth = Math.max(0, ...paragraphs.map(paragraphMinContentWidth));
|
|
1920
|
+
let baseline;
|
|
1921
|
+
if (style.verticalAlign === void 0 || style.verticalAlign === "top") {
|
|
1922
|
+
if (paragraphs[0] === void 0) baseline = void 0;
|
|
1923
|
+
else try {
|
|
1924
|
+
baseline = paragraphBaseline(paragraphs[0]) ?? "unavailable";
|
|
1925
|
+
} catch {
|
|
1926
|
+
baseline = "unavailable";
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
return {
|
|
1930
|
+
width: measured.width,
|
|
1931
|
+
height: measured.height,
|
|
1932
|
+
minContentWidth,
|
|
1933
|
+
minContentHeight: measured.height,
|
|
1934
|
+
...baseline === void 0 ? {} : { baseline }
|
|
1935
|
+
};
|
|
1936
|
+
}
|
|
1937
|
+
function bodyAnchor(verticalAlign) {
|
|
1938
|
+
return {
|
|
1939
|
+
top: "t",
|
|
1940
|
+
middle: "ctr",
|
|
1941
|
+
bottom: "b"
|
|
1942
|
+
}[verticalAlign ?? "top"];
|
|
1943
|
+
}
|
|
1944
|
+
function textInsets(value, placeholder) {
|
|
1945
|
+
if (placeholder === void 0) return parseTextInsets(value);
|
|
1946
|
+
const effective = {};
|
|
1947
|
+
const layers = [
|
|
1948
|
+
placeholder.masterPlaceholder?.style,
|
|
1949
|
+
placeholder.layoutPlaceholder?.style,
|
|
1950
|
+
record(value) ? value : void 0
|
|
1951
|
+
];
|
|
1952
|
+
for (const layer of layers) {
|
|
1953
|
+
if (layer === void 0) continue;
|
|
1954
|
+
for (const key of paddingStyleKeys) if (hasLocalDeclaration(layer, key)) {
|
|
1955
|
+
if (key === "padding") {
|
|
1956
|
+
delete effective["paddingTop"];
|
|
1957
|
+
delete effective["paddingRight"];
|
|
1958
|
+
delete effective["paddingBottom"];
|
|
1959
|
+
delete effective["paddingLeft"];
|
|
1960
|
+
}
|
|
1961
|
+
effective[key] = layer[key];
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
return parseTextInsets(effective);
|
|
1965
|
+
}
|
|
1966
|
+
/** Parses text children, validates element structure, and resolves paragraphs and text styles once. */
|
|
1967
|
+
function parseTextContent(children, styleValue, theme, fields = { slideNumber: 1 }, label = "Text.style", placeholder, fullSlideStyle, options) {
|
|
1968
|
+
const allowParagraphMotion = options?.allowParagraphMotion === true;
|
|
1969
|
+
if (placeholder === void 0) {
|
|
1970
|
+
const style = readTextStyle(styleValue, label, theme);
|
|
1971
|
+
const { paragraphs, paragraphMotions } = normalizeParagraphs(children, style, theme, fields, void 0, void 0, allowParagraphMotion);
|
|
1972
|
+
return {
|
|
1973
|
+
paragraphs,
|
|
1974
|
+
paragraphMotions,
|
|
1975
|
+
style
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
const { style, localDeclaredStyle } = readPlaceholderTextStyle(styleValue, label, placeholder);
|
|
1979
|
+
const fullRecord = record(fullSlideStyle) ? fullSlideStyle : void 0;
|
|
1980
|
+
const localBodyDeclared = localDeclaredKeySet(fullRecord, [
|
|
1981
|
+
"textWrap",
|
|
1982
|
+
"verticalAlign",
|
|
1983
|
+
...paddingStyleKeys
|
|
1984
|
+
]);
|
|
1985
|
+
const { paragraphs, paragraphMotions } = normalizeParagraphs(children, style, placeholder.masterTheme, fields, placeholder, localDeclaredStyle, allowParagraphMotion);
|
|
1986
|
+
return {
|
|
1987
|
+
paragraphs,
|
|
1988
|
+
paragraphMotions,
|
|
1989
|
+
style,
|
|
1990
|
+
localBodyDeclared
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
const parseTextParagraphs = parseTextContent;
|
|
1994
|
+
function validateEmittableParagraphs(paragraphs, theme) {
|
|
1995
|
+
for (const paragraph of paragraphs) {
|
|
1996
|
+
if (paragraph.style.list?.type === "bullet") escapedXml(paragraph.style.list.character ?? "•");
|
|
1997
|
+
if (paragraph.runs.length === 0) {
|
|
1998
|
+
for (const font of normalizedFonts(paragraph.endStyle)) escapedXml(font.family);
|
|
1999
|
+
if (paragraph.endStyle.eastAsianFontFamily !== void 0) for (const eaFont of normalizedFontsForReference(paragraph.endStyle.eastAsianFontFamily, paragraph.endStyle.fontWeight, paragraph.endStyle.fontStyle)) escapedXml(eaFont.family);
|
|
2000
|
+
if (paragraph.endStyle.lang !== void 0) escapedXml(paragraph.endStyle.lang);
|
|
2001
|
+
if (paragraph.endStyle.textShadow !== void 0 && paragraph.endStyle.textShadow !== "none") textShadowXml(theme, paragraph.endStyle.textShadow);
|
|
2002
|
+
centipoints(fontSizePoints(paragraph.endStyle.fontSize));
|
|
2003
|
+
continue;
|
|
2004
|
+
}
|
|
2005
|
+
for (const run of paragraph.runs) {
|
|
2006
|
+
escapedXml(run.text);
|
|
2007
|
+
for (const font of normalizedFonts(run.style)) escapedXml(font.family);
|
|
2008
|
+
if (run.style.eastAsianFontFamily !== void 0) for (const eaFont of normalizedFontsForReference(run.style.eastAsianFontFamily, run.style.fontWeight, run.style.fontStyle)) escapedXml(eaFont.family);
|
|
2009
|
+
if (run.style.lang !== void 0) escapedXml(run.style.lang);
|
|
2010
|
+
if (run.style.textShadow !== void 0 && run.style.textShadow !== "none") textShadowXml(theme, run.style.textShadow);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const TEXT_FIT_EPSILON = .01;
|
|
2015
|
+
/** Computes tri-state TextMetrics from a resolved text body and its finalized available content dimensions. */
|
|
2016
|
+
function computeTextMetrics(resolved, availableWidth, availableHeight) {
|
|
2017
|
+
const { missingResourceFonts, missingGlyphFonts, referencedFonts } = resolved.unmeasuredIssues;
|
|
2018
|
+
if (missingResourceFonts.length > 0) return {
|
|
2019
|
+
status: "unmeasured",
|
|
2020
|
+
reason: "missing-font-resource",
|
|
2021
|
+
fonts: missingResourceFonts
|
|
2022
|
+
};
|
|
2023
|
+
if (missingGlyphFonts.length > 0) return {
|
|
2024
|
+
status: "unmeasured",
|
|
2025
|
+
reason: "missing-glyphs",
|
|
2026
|
+
fonts: missingGlyphFonts
|
|
2027
|
+
};
|
|
2028
|
+
if (resolved.measuredLayout === void 0) return {
|
|
2029
|
+
status: "unmeasured",
|
|
2030
|
+
reason: "missing-font-resource",
|
|
2031
|
+
fonts: referencedFonts
|
|
2032
|
+
};
|
|
2033
|
+
const available = {
|
|
2034
|
+
width: Math.max(0, availableWidth),
|
|
2035
|
+
height: Math.max(0, availableHeight)
|
|
2036
|
+
};
|
|
2037
|
+
const content = {
|
|
2038
|
+
width: resolved.measuredLayout.width,
|
|
2039
|
+
height: resolved.measuredLayout.height,
|
|
2040
|
+
lineCount: resolved.measuredLayout.paragraphs.reduce((sum, paragraph) => sum + paragraph.lineCount, 0)
|
|
2041
|
+
};
|
|
2042
|
+
return {
|
|
2043
|
+
status: "measured",
|
|
2044
|
+
available,
|
|
2045
|
+
content,
|
|
2046
|
+
fits: content.width <= available.width + TEXT_FIT_EPSILON && content.height <= available.height + TEXT_FIT_EPSILON
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Resolves text layout, wrapping metrics, overset diagnostics, plain-text observations,
|
|
2051
|
+
* and font resource claims from pre-parsed paragraphs without assigning emit-only field IDs.
|
|
2052
|
+
*/
|
|
2053
|
+
function resolveTextBody(rawParagraphs, style, theme, verticalAlign = "top", layout, destination = "text-box", placeholderOptions) {
|
|
2054
|
+
const paragraphs = placeholderOptions?.isPlaceholder === true ? rawParagraphs : rawParagraphs.map((paragraph) => {
|
|
2055
|
+
const metrics = computeDefaultListIndentMetrics(paragraph);
|
|
2056
|
+
return metrics === void 0 ? paragraph : {
|
|
2057
|
+
...paragraph,
|
|
2058
|
+
resolvedListIndent: {
|
|
2059
|
+
marginLeft: metrics.contentIndent,
|
|
2060
|
+
indent: -metrics.hangingIndent
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
});
|
|
2064
|
+
const runs = paragraphs.flatMap((paragraph) => paragraph.runs.length > 0 ? paragraph.runs : [{
|
|
2065
|
+
text: "",
|
|
2066
|
+
style: paragraph.endStyle
|
|
2067
|
+
}]);
|
|
2068
|
+
const listRuns = paragraphs.flatMap((paragraph) => {
|
|
2069
|
+
const list = paragraph.style.list;
|
|
2070
|
+
if (list === void 0) return [];
|
|
2071
|
+
return [{
|
|
2072
|
+
text: list.type === "bullet" ? list.character ?? "•" : "0123456789.",
|
|
2073
|
+
style: paragraph.runs[0]?.style ?? paragraph.endStyle
|
|
2074
|
+
}];
|
|
2075
|
+
});
|
|
2076
|
+
const { resourceClaims, fontUses, fontUsages, missingGlyphErrors, unmeasuredIssues } = textResourceClaims([...runs, ...listRuns]);
|
|
2077
|
+
let measured;
|
|
2078
|
+
let measurementError;
|
|
2079
|
+
if (layout !== void 0) try {
|
|
2080
|
+
measured = measureParagraphs(paragraphs, layout.width === "max-content" ? Number.MAX_VALUE : layout.width);
|
|
2081
|
+
} catch (error) {
|
|
2082
|
+
if (layout.contentSized === true) throw error;
|
|
2083
|
+
if (error instanceof CapabilityError) measurementError = error;
|
|
2084
|
+
}
|
|
2085
|
+
if (layout?.contentSized === true && measured === void 0) {
|
|
2086
|
+
const missingFont = unmeasuredIssues.missingResourceFonts[0] ?? unmeasuredIssues.referencedFonts[0];
|
|
2087
|
+
throw new CapabilityError("font-measurement-unavailable", "Content-sized text is missing complete font measurement basis", void 0, missingFont === void 0 ? void 0 : {
|
|
2088
|
+
font: missingFont,
|
|
2089
|
+
reason: "missing-resource"
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
const outputParagraphs = layout?.contentSized === true && measured !== void 0 ? paragraphs.map((paragraph, index) => paragraph.style.lineHeight !== void 0 ? paragraph : {
|
|
2093
|
+
...paragraph,
|
|
2094
|
+
style: {
|
|
2095
|
+
...paragraph.style,
|
|
2096
|
+
lineHeight: measured.paragraphs[index].lineHeight
|
|
2097
|
+
}
|
|
2098
|
+
}) : paragraphs;
|
|
2099
|
+
validateEmittableParagraphs(outputParagraphs, theme);
|
|
2100
|
+
const text = outputParagraphs.map(({ runs: paragraphRuns }) => paragraphRuns.map(({ text: part }) => part).join("")).join("\n");
|
|
2101
|
+
const textMetrics = layout === void 0 ? void 0 : computeTextMetrics({
|
|
2102
|
+
...measured === void 0 ? {} : { measuredLayout: measured },
|
|
2103
|
+
unmeasuredIssues
|
|
2104
|
+
}, layout.width === "max-content" ? measured?.width ?? 0 : layout.width, layout.height ?? measured?.height ?? 0);
|
|
2105
|
+
return {
|
|
2106
|
+
paragraphs: outputParagraphs,
|
|
2107
|
+
style,
|
|
2108
|
+
verticalAlign,
|
|
2109
|
+
...layout === void 0 ? {} : { layout },
|
|
2110
|
+
destination,
|
|
2111
|
+
...placeholderOptions?.isPlaceholder === true ? { isPlaceholder: true } : {},
|
|
2112
|
+
...placeholderOptions?.localBodyDeclared === void 0 ? {} : { localBodyDeclared: placeholderOptions.localBodyDeclared },
|
|
2113
|
+
text,
|
|
2114
|
+
paragraphCount: outputParagraphs.length,
|
|
2115
|
+
resourceClaims,
|
|
2116
|
+
fontUses,
|
|
2117
|
+
fontUsages,
|
|
2118
|
+
...measured === void 0 ? {} : {
|
|
2119
|
+
measurement: {
|
|
2120
|
+
width: measured.width,
|
|
2121
|
+
height: measured.height
|
|
2122
|
+
},
|
|
2123
|
+
measuredLayout: measured
|
|
2124
|
+
},
|
|
2125
|
+
...measurementError === void 0 ? {} : { measurementError },
|
|
2126
|
+
missingGlyphErrors,
|
|
2127
|
+
unmeasuredIssues,
|
|
2128
|
+
...textMetrics === void 0 ? {} : { textMetrics }
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Emits PresentationML txBody XML and font embedding contributions from resolved text facts.
|
|
2133
|
+
* Preserves native paragraph/run structure without converting soft wraps into hard line breaks.
|
|
2134
|
+
*/
|
|
2135
|
+
function emitTextBody(resolved, theme, options = {}) {
|
|
2136
|
+
const { createFieldId, embedFonts } = options;
|
|
2137
|
+
if ((embedFonts === "full" || embedFonts === "subset") && resolved.missingGlyphErrors.length > 0) {
|
|
2138
|
+
const issue = resolved.missingGlyphErrors[0];
|
|
2139
|
+
throw new CapabilityError("font-missing-glyph", issue.message, void 0, {
|
|
2140
|
+
font: issue.font,
|
|
2141
|
+
characters: issue.characters
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
const emittedParagraphs = createFieldId !== void 0 ? resolved.paragraphs.map((paragraph) => ({
|
|
2145
|
+
...paragraph,
|
|
2146
|
+
runs: paragraph.runs.map((run) => run.field !== void 0 ? {
|
|
2147
|
+
...run,
|
|
2148
|
+
field: {
|
|
2149
|
+
...run.field,
|
|
2150
|
+
id: createFieldId()
|
|
2151
|
+
}
|
|
2152
|
+
} : run)
|
|
2153
|
+
})) : resolved.paragraphs;
|
|
2154
|
+
const { style, verticalAlign, layout, destination, isPlaceholder } = resolved;
|
|
2155
|
+
let xml;
|
|
2156
|
+
if (destination === "table-cell") xml = `<a:txBody><a:bodyPr/><a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme)).join("")}</a:txBody>`;
|
|
2157
|
+
else if (isPlaceholder) {
|
|
2158
|
+
const localBody = resolved.localBodyDeclared ?? /* @__PURE__ */ new Set();
|
|
2159
|
+
const bodyAttrs = [];
|
|
2160
|
+
if (localBody.has("textWrap")) bodyAttrs.push(`wrap="${style.textWrap === "nowrap" ? "none" : "square"}"`);
|
|
2161
|
+
if (paddingStyleKeys.some((key) => localBody.has(key)) && layout?.insets !== void 0) bodyAttrs.push(`lIns="${pxToEmu(layout.insets.left)}"`, `tIns="${pxToEmu(layout.insets.top)}"`, `rIns="${pxToEmu(layout.insets.right)}"`, `bIns="${pxToEmu(layout.insets.bottom)}"`);
|
|
2162
|
+
if (localBody.has("verticalAlign")) bodyAttrs.push(`anchor="${bodyAnchor(style.verticalAlign ?? verticalAlign)}"`);
|
|
2163
|
+
xml = `<p:txBody>${bodyAttrs.length === 0 ? "<a:bodyPr/>" : `<a:bodyPr ${bodyAttrs.join(" ")}/>`}<a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme, true)).join("")}</p:txBody>`;
|
|
2164
|
+
} else xml = `<p:txBody><a:bodyPr wrap="${style.textWrap === "nowrap" ? "none" : "square"}" lIns="${pxToEmu(layout?.insets?.left ?? 0)}" tIns="${pxToEmu(layout?.insets?.top ?? 0)}" rIns="${pxToEmu(layout?.insets?.right ?? 0)}" bIns="${pxToEmu(layout?.insets?.bottom ?? 0)}" anchor="${bodyAnchor(style.verticalAlign ?? verticalAlign)}"><a:noAutofit/></a:bodyPr><a:lstStyle/>${emittedParagraphs.map((paragraph) => paragraphXml(paragraph, theme)).join("")}</p:txBody>`;
|
|
2165
|
+
return {
|
|
2166
|
+
xml,
|
|
2167
|
+
presentationContributions: fontPresentationContributions(resolved.fontUses, embedFonts)
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
/** Generates shared font styles for native chart text and registers font claims based on actual categories, series, and label text. */
|
|
2171
|
+
function writeChartTextProperties(styleValue, texts, label, theme) {
|
|
2172
|
+
const style = readTextStyle(styleValue, label, theme);
|
|
2173
|
+
const runStyle = {
|
|
2174
|
+
fontFamily: style.fontFamily,
|
|
2175
|
+
...style.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: style.eastAsianFontFamily },
|
|
2176
|
+
fontSize: style.fontSize,
|
|
2177
|
+
fontWeight: style.fontWeight,
|
|
2178
|
+
fontStyle: style.fontStyle,
|
|
2179
|
+
color: style.color,
|
|
2180
|
+
themeFont: style.themeFont,
|
|
2181
|
+
...style.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: style.eastAsianThemeFont },
|
|
2182
|
+
letterSpacing: style.letterSpacing,
|
|
2183
|
+
textTransform: style.textTransform,
|
|
2184
|
+
textDecoration: style.textDecoration,
|
|
2185
|
+
textShadow: style.textShadow,
|
|
2186
|
+
lang: style.lang
|
|
2187
|
+
};
|
|
2188
|
+
validateRunStyle(runStyle);
|
|
2189
|
+
const runs = texts.map((text) => ({
|
|
2190
|
+
text,
|
|
2191
|
+
style: runStyle
|
|
2192
|
+
}));
|
|
2193
|
+
for (const text of texts) escapedXml(text);
|
|
2194
|
+
const { resourceClaims, fontUses, fontUsages, missingGlyphErrors } = textResourceClaims(runs);
|
|
2195
|
+
const defaultProperties = runPropertiesXml(runStyle, "a:defRPr", theme);
|
|
2196
|
+
const outputText = texts.join("\n");
|
|
2197
|
+
const lineSpacing = lineSpacingXml(style.lineHeight);
|
|
2198
|
+
const alignment = alignmentValue(style.align);
|
|
2199
|
+
const paragraphAlignment = alignment === void 0 ? "" : ` algn="${alignment}"`;
|
|
2200
|
+
const spacingAfter = style.spacingAfter === void 0 || style.spacingAfter === 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
|
|
2201
|
+
const endParaLang = runStyle.lang !== void 0 ? ` lang="${escapedXml(runStyle.lang)}"` : "";
|
|
2202
|
+
return {
|
|
2203
|
+
xml: `<c:txPr><a:bodyPr anchor="${bodyAnchor(style.verticalAlign)}"/><a:lstStyle/><a:p><a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr><a:endParaRPr${endParaLang}/></a:p></c:txPr>`,
|
|
2204
|
+
text: outputText,
|
|
2205
|
+
resourceClaims,
|
|
2206
|
+
fontUses,
|
|
2207
|
+
fontUsages,
|
|
2208
|
+
missingGlyphErrors
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
/** Emits a native chart or axis title with actual run properties, not canvas text. */
|
|
2212
|
+
function writeChartTitle(text, styleValue, label, theme, rotationDegrees) {
|
|
2213
|
+
const style = readTextStyle(styleValue, label, theme);
|
|
2214
|
+
const runStyle = {
|
|
2215
|
+
fontFamily: style.fontFamily,
|
|
2216
|
+
...style.eastAsianFontFamily === void 0 ? {} : { eastAsianFontFamily: style.eastAsianFontFamily },
|
|
2217
|
+
fontSize: style.fontSize,
|
|
2218
|
+
fontWeight: style.fontWeight,
|
|
2219
|
+
fontStyle: style.fontStyle,
|
|
2220
|
+
color: style.color,
|
|
2221
|
+
themeFont: style.themeFont,
|
|
2222
|
+
...style.eastAsianThemeFont === void 0 ? {} : { eastAsianThemeFont: style.eastAsianThemeFont },
|
|
2223
|
+
letterSpacing: style.letterSpacing,
|
|
2224
|
+
textTransform: style.textTransform,
|
|
2225
|
+
textDecoration: style.textDecoration,
|
|
2226
|
+
textShadow: style.textShadow,
|
|
2227
|
+
lang: style.lang
|
|
2228
|
+
};
|
|
2229
|
+
validateRunStyle(runStyle);
|
|
2230
|
+
const escapedText = escapedXml(text);
|
|
2231
|
+
const { resourceClaims, fontUses, fontUsages, missingGlyphErrors } = textResourceClaims([{
|
|
2232
|
+
text,
|
|
2233
|
+
style: runStyle
|
|
2234
|
+
}]);
|
|
2235
|
+
const runProperties = runPropertiesXml(runStyle, "a:rPr", theme);
|
|
2236
|
+
const defaultProperties = runPropertiesXml(runStyle, "a:defRPr", theme);
|
|
2237
|
+
const lineSpacing = lineSpacingXml(style.lineHeight);
|
|
2238
|
+
const alignment = alignmentValue(style.align);
|
|
2239
|
+
const paragraphAlignment = alignment === void 0 ? "" : ` algn="${alignment}"`;
|
|
2240
|
+
const spacingAfter = style.spacingAfter === void 0 || style.spacingAfter === 0 ? "" : `<a:spcAft><a:spcPts val="${spacingCentipoints(style.spacingAfter, "spacingAfter")}"/></a:spcAft>`;
|
|
2241
|
+
const endParaLang = runStyle.lang !== void 0 ? ` lang="${escapedXml(runStyle.lang)}"` : "";
|
|
2242
|
+
const bodyProperties = `<a:bodyPr${rotationDegrees !== void 0 && rotationDegrees !== 0 ? ` rot="${Math.round(rotationDegrees * 6e4)}"` : ""} anchor="${bodyAnchor(style.verticalAlign)}"/>`;
|
|
2243
|
+
return {
|
|
2244
|
+
xml: `<c:title><c:tx><c:rich>${bodyProperties}<a:lstStyle/><a:p><a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr><a:r>${runProperties}<a:t>${escapedText}</a:t></a:r><a:endParaRPr${endParaLang}/></a:p></c:rich></c:tx><c:overlay val="0"/><c:txPr>${bodyProperties}<a:lstStyle/><a:p><a:pPr${paragraphAlignment}>${lineSpacing}${spacingAfter}${defaultProperties}</a:pPr><a:endParaRPr${endParaLang}/></a:p></c:txPr></c:title>`,
|
|
2245
|
+
text,
|
|
2246
|
+
resourceClaims,
|
|
2247
|
+
fontUses,
|
|
2248
|
+
fontUsages,
|
|
2249
|
+
missingGlyphErrors
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
export { computeTextMetrics, emitSlideNumberRunXml, emitTextBody, measureTextLayoutFromParagraphs, parseTextContent, parseTextParagraphs, previewParagraphOutlines, previewTextBoxOutlines, renderGlyphPathSvg, renderTextOutlinesSvg, resolveTextBody, textInsets, withPreviewFontBoundary, writeChartTextProperties, writeChartTitle };
|