@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,1023 @@
|
|
|
1
|
+
import { CapabilityError } from "./diagnostics.js";
|
|
2
|
+
import { isSealedFont } from "./font-seal.js";
|
|
3
|
+
import { snapshotValue } from "./input-values.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ../core/dist/theme.js
|
|
6
|
+
const rawFontFaceStyleSchema = z.enum(["normal", "italic"]);
|
|
7
|
+
const fontWeightNumberSchema = z.number().int("fontWeight must be normal, bold, or an integer between 1 and 1000").min(1, "fontWeight must be normal, bold, or an integer between 1 and 1000").max(1e3, "fontWeight must be normal, bold, or an integer between 1 and 1000");
|
|
8
|
+
const fontWeightSchema = z.union([
|
|
9
|
+
z.literal("normal"),
|
|
10
|
+
z.literal("bold"),
|
|
11
|
+
fontWeightNumberSchema
|
|
12
|
+
]);
|
|
13
|
+
const uint8ArraySchema = z.instanceof(Uint8Array);
|
|
14
|
+
const rawFontFaceSchema = z.strictObject({
|
|
15
|
+
weight: fontWeightNumberSchema.optional(),
|
|
16
|
+
style: rawFontFaceStyleSchema.optional(),
|
|
17
|
+
data: uint8ArraySchema.refine((bytes) => bytes.byteLength > 0, "Font face data cannot be empty").optional()
|
|
18
|
+
}).readonly();
|
|
19
|
+
const nonEmptyTrimmedStringSchema = z.string().refine((value) => value.trim() !== "", "Value cannot be empty");
|
|
20
|
+
const unsealedFontObjectSchema = z.strictObject({
|
|
21
|
+
family: nonEmptyTrimmedStringSchema,
|
|
22
|
+
faces: z.array(rawFontFaceSchema).readonly().optional(),
|
|
23
|
+
substitute: z.boolean().optional(),
|
|
24
|
+
embeddable: z.boolean().optional()
|
|
25
|
+
}).readonly();
|
|
26
|
+
const sealedFontSchema = z.custom(isSealedFont);
|
|
27
|
+
const rawFontSchema = z.union([sealedFontSchema, unsealedFontObjectSchema]);
|
|
28
|
+
/** Internal schema used by `font()` constructor to report exact per-field validation issues. */
|
|
29
|
+
const unsealedFontSchema = unsealedFontObjectSchema;
|
|
30
|
+
const fontOptionsSchema = z.strictObject({
|
|
31
|
+
substitute: z.boolean().optional(),
|
|
32
|
+
embeddable: z.boolean().optional()
|
|
33
|
+
}).readonly();
|
|
34
|
+
const themeFontSlots = ["major", "minor"];
|
|
35
|
+
const themeFontSlotSchema = z.enum(themeFontSlots);
|
|
36
|
+
function isThemeFontSlot(value) {
|
|
37
|
+
return value === "major" || value === "minor";
|
|
38
|
+
}
|
|
39
|
+
const rawFontReferenceSchema = z.union([
|
|
40
|
+
nonEmptyTrimmedStringSchema,
|
|
41
|
+
sealedFontSchema,
|
|
42
|
+
unsealedFontObjectSchema
|
|
43
|
+
]);
|
|
44
|
+
const reservedThemeFontPattern = /^(?:major|minor|\+(?:mj|mn)-)/iu;
|
|
45
|
+
const themeFontReservedSlotMessage = "Theme font slot cannot use reserved placeholders 'major', 'minor', '+mj-*', or '+mn-*'";
|
|
46
|
+
function isAllowedThemeFontFamily(family) {
|
|
47
|
+
const trimmed = family.trim();
|
|
48
|
+
return trimmed !== "" && !reservedThemeFontPattern.test(trimmed);
|
|
49
|
+
}
|
|
50
|
+
const allowedThemeSealedFontSchema = z.custom((value) => isSealedFont(value) && isAllowedThemeFontFamily(value.family), { message: themeFontReservedSlotMessage });
|
|
51
|
+
const rawThemeFontValueSchema = z.union([
|
|
52
|
+
nonEmptyTrimmedStringSchema.refine(isAllowedThemeFontFamily, themeFontReservedSlotMessage),
|
|
53
|
+
allowedThemeSealedFontSchema,
|
|
54
|
+
unsealedFontObjectSchema.refine((fontValue) => isAllowedThemeFontFamily(fontValue.family), themeFontReservedSlotMessage)
|
|
55
|
+
]);
|
|
56
|
+
const textLengthPattern = /^(\d+(?:\.\d+)?)(px|pt)$/u;
|
|
57
|
+
const textLengthStringSchema = z.string().regex(textLengthPattern);
|
|
58
|
+
function textLengthToPixels(value) {
|
|
59
|
+
if (typeof value === "number") return value;
|
|
60
|
+
const match = textLengthPattern.exec(value);
|
|
61
|
+
if (match === null) return NaN;
|
|
62
|
+
const amount = Number(match[1]);
|
|
63
|
+
return match[2] === "pt" ? amount * 4 / 3 : amount;
|
|
64
|
+
}
|
|
65
|
+
function fontSizeToPoints(value) {
|
|
66
|
+
if (typeof value === "string" && value.endsWith("pt")) return Number(value.slice(0, -2));
|
|
67
|
+
return textLengthToPixels(value) * .75;
|
|
68
|
+
}
|
|
69
|
+
const rawFontSizeSchema = z.union([z.number().finite().positive(), textLengthStringSchema.refine((value) => textLengthToPixels(value) > 0, "Text length must be greater than 0")]);
|
|
70
|
+
const validatedFontSizeSchema = rawFontSizeSchema.refine((value) => {
|
|
71
|
+
const serialized = Math.round(fontSizeToPoints(value) * 100);
|
|
72
|
+
return serialized >= 100 && serialized <= 4e5;
|
|
73
|
+
}, "fontSize converted value must be within DrawingML range of 1 to 4000pt");
|
|
74
|
+
const lineHeightPercentPattern = /^(\d+(?:\.\d+)?)%$/u;
|
|
75
|
+
const lineHeightPercentStringSchema = z.string().regex(lineHeightPercentPattern);
|
|
76
|
+
function parseLineHeightPercentThousandths(value) {
|
|
77
|
+
const match = lineHeightPercentPattern.exec(value);
|
|
78
|
+
if (match === null) return void 0;
|
|
79
|
+
const pct = Number(match[1]);
|
|
80
|
+
if (!Number.isFinite(pct)) return void 0;
|
|
81
|
+
const thousandths = Math.round(pct * 1e3);
|
|
82
|
+
if (thousandths < 1 || thousandths > 132e5) return void 0;
|
|
83
|
+
return thousandths;
|
|
84
|
+
}
|
|
85
|
+
const validatedLineHeightSchema = z.union([rawFontSizeSchema, lineHeightPercentStringSchema.refine((value) => parseLineHeightPercentThousandths(value) !== void 0, "lineHeight percentage must be greater than 0% and within DrawingML ST_TextSpacingPercent range (up to 13200%)")]).refine((value) => {
|
|
86
|
+
if (typeof value === "string" && value.endsWith("%")) return parseLineHeightPercentThousandths(value) !== void 0;
|
|
87
|
+
const centipoints = Math.round(textLengthToPixels(value) * 75);
|
|
88
|
+
return centipoints >= 0 && centipoints <= 158400;
|
|
89
|
+
}, "lineHeight must be a positive pixel value, px/pt length within 0 to 1584pt, or percentage within 0% to 13200%");
|
|
90
|
+
const rawTextAlignmentSchema = z.enum([
|
|
91
|
+
"left",
|
|
92
|
+
"center",
|
|
93
|
+
"right",
|
|
94
|
+
"justify"
|
|
95
|
+
]);
|
|
96
|
+
const nativeColorSlots = [
|
|
97
|
+
"dk1",
|
|
98
|
+
"lt1",
|
|
99
|
+
"dk2",
|
|
100
|
+
"lt2",
|
|
101
|
+
"accent1",
|
|
102
|
+
"accent2",
|
|
103
|
+
"accent3",
|
|
104
|
+
"accent4",
|
|
105
|
+
"accent5",
|
|
106
|
+
"accent6",
|
|
107
|
+
"hlink",
|
|
108
|
+
"folHlink"
|
|
109
|
+
];
|
|
110
|
+
const rawNativeColorSlotSchema = z.enum(nativeColorSlots);
|
|
111
|
+
const schemeColorSlots = [
|
|
112
|
+
"bg1",
|
|
113
|
+
"tx1",
|
|
114
|
+
"bg2",
|
|
115
|
+
"tx2",
|
|
116
|
+
"accent1",
|
|
117
|
+
"accent2",
|
|
118
|
+
"accent3",
|
|
119
|
+
"accent4",
|
|
120
|
+
"accent5",
|
|
121
|
+
"accent6",
|
|
122
|
+
"hlink",
|
|
123
|
+
"folHlink"
|
|
124
|
+
];
|
|
125
|
+
z.enum(schemeColorSlots);
|
|
126
|
+
const schemeColorNames = [
|
|
127
|
+
"dk1",
|
|
128
|
+
"lt1",
|
|
129
|
+
"dk2",
|
|
130
|
+
"lt2",
|
|
131
|
+
"bg1",
|
|
132
|
+
"tx1",
|
|
133
|
+
"bg2",
|
|
134
|
+
"tx2",
|
|
135
|
+
"accent1",
|
|
136
|
+
"accent2",
|
|
137
|
+
"accent3",
|
|
138
|
+
"accent4",
|
|
139
|
+
"accent5",
|
|
140
|
+
"accent6",
|
|
141
|
+
"hlink",
|
|
142
|
+
"folHlink"
|
|
143
|
+
];
|
|
144
|
+
const rawSchemeColorNameSchema = z.enum(schemeColorNames);
|
|
145
|
+
const schemeColorNameSchema = rawSchemeColorNameSchema;
|
|
146
|
+
const rawColorMapSchema = z.strictObject({
|
|
147
|
+
bg1: rawNativeColorSlotSchema,
|
|
148
|
+
tx1: rawNativeColorSlotSchema,
|
|
149
|
+
bg2: rawNativeColorSlotSchema,
|
|
150
|
+
tx2: rawNativeColorSlotSchema,
|
|
151
|
+
accent1: rawNativeColorSlotSchema,
|
|
152
|
+
accent2: rawNativeColorSlotSchema,
|
|
153
|
+
accent3: rawNativeColorSlotSchema,
|
|
154
|
+
accent4: rawNativeColorSlotSchema,
|
|
155
|
+
accent5: rawNativeColorSlotSchema,
|
|
156
|
+
accent6: rawNativeColorSlotSchema,
|
|
157
|
+
hlink: rawNativeColorSlotSchema,
|
|
158
|
+
folHlink: rawNativeColorSlotSchema
|
|
159
|
+
}).readonly();
|
|
160
|
+
/** Native `<p:clrMap>` / `<a:overrideClrMapping>` mapping the 12 scheme slots to 12 theme palette slots. */
|
|
161
|
+
const colorMapSchema = rawColorMapSchema;
|
|
162
|
+
const defaultColorMap = Object.freeze({
|
|
163
|
+
bg1: "lt1",
|
|
164
|
+
tx1: "dk1",
|
|
165
|
+
bg2: "lt2",
|
|
166
|
+
tx2: "dk2",
|
|
167
|
+
accent1: "accent1",
|
|
168
|
+
accent2: "accent2",
|
|
169
|
+
accent3: "accent3",
|
|
170
|
+
accent4: "accent4",
|
|
171
|
+
accent5: "accent5",
|
|
172
|
+
accent6: "accent6",
|
|
173
|
+
hlink: "hlink",
|
|
174
|
+
folHlink: "folHlink"
|
|
175
|
+
});
|
|
176
|
+
const colorMapOverrideSchema = z.union([z.literal("master"), rawColorMapSchema]);
|
|
177
|
+
const rawThemeShadeSchema = z.strictObject({
|
|
178
|
+
slot: rawSchemeColorNameSchema,
|
|
179
|
+
lumMod: z.number().finite().min(0).max(1),
|
|
180
|
+
lumOff: z.number().finite().min(0).max(1).optional()
|
|
181
|
+
}).readonly();
|
|
182
|
+
const themeHexColorPattern = /^\s*#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})\s*$/u;
|
|
183
|
+
const styleHexColorPattern = /^\s*#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\s*$/u;
|
|
184
|
+
function normalizeThemeHexColor(raw) {
|
|
185
|
+
const digits = raw.trim().slice(1);
|
|
186
|
+
return `#${(digits.length === 3 ? digits.split("").map((digit) => digit + digit).join("") : digits).toUpperCase()}`;
|
|
187
|
+
}
|
|
188
|
+
const rawThemeHexColorSchema = z.string().regex(themeHexColorPattern, "Theme color slot must be an opaque #RGB or #RRGGBB hex color").transform(normalizeThemeHexColor);
|
|
189
|
+
const rawStyleHexColorSchema = z.string().regex(styleHexColorPattern, "Color hex value must be #RGB, #RGBA, #RRGGBB, or #RRGGBBAA");
|
|
190
|
+
const rawThemeColorSchema = z.union([
|
|
191
|
+
rawSchemeColorNameSchema,
|
|
192
|
+
rawStyleHexColorSchema,
|
|
193
|
+
rawThemeShadeSchema
|
|
194
|
+
]);
|
|
195
|
+
const rawColorValueSchema = z.union([
|
|
196
|
+
rawSchemeColorNameSchema,
|
|
197
|
+
rawStyleHexColorSchema,
|
|
198
|
+
rawThemeShadeSchema,
|
|
199
|
+
z.strictObject({
|
|
200
|
+
color: rawThemeColorSchema,
|
|
201
|
+
alpha: z.number().finite().min(0).max(1).optional()
|
|
202
|
+
}).readonly()
|
|
203
|
+
]);
|
|
204
|
+
/** Color entry can directly provide a scheme color, hex color, or theme shade, optionally with alpha. */
|
|
205
|
+
const colorValueSchema = rawColorValueSchema;
|
|
206
|
+
z.strictObject({
|
|
207
|
+
hex: z.string(),
|
|
208
|
+
alpha: z.number().finite().min(0).max(1).optional(),
|
|
209
|
+
slot: rawNativeColorSlotSchema.optional(),
|
|
210
|
+
scheme: rawSchemeColorNameSchema.optional(),
|
|
211
|
+
lumMod: z.number().finite().min(0).max(1).optional(),
|
|
212
|
+
lumOff: z.number().finite().min(0).max(1).optional()
|
|
213
|
+
}).readonly();
|
|
214
|
+
const rawGradientStopSchema = z.strictObject({
|
|
215
|
+
color: rawColorValueSchema,
|
|
216
|
+
position: z.number().finite()
|
|
217
|
+
}).readonly();
|
|
218
|
+
const rawLinearGradientSchema = z.strictObject({
|
|
219
|
+
type: z.literal("linear-gradient"),
|
|
220
|
+
angle: z.number().finite(),
|
|
221
|
+
stops: z.array(rawGradientStopSchema).readonly()
|
|
222
|
+
}).readonly();
|
|
223
|
+
const linearGradientSchema = rawLinearGradientSchema;
|
|
224
|
+
const rawRadialGradientSchema = z.strictObject({
|
|
225
|
+
type: z.literal("radial-gradient"),
|
|
226
|
+
stops: z.array(rawGradientStopSchema).readonly()
|
|
227
|
+
}).readonly();
|
|
228
|
+
const radialGradientSchema = rawRadialGradientSchema;
|
|
229
|
+
const rawImageBackgroundFitSchema = z.enum([
|
|
230
|
+
"fill",
|
|
231
|
+
"cover",
|
|
232
|
+
"contain"
|
|
233
|
+
]);
|
|
234
|
+
const imageBackgroundFitSchema = rawImageBackgroundFitSchema;
|
|
235
|
+
const positionPercentSchema = z.string().regex(/^(-?(?:\d+(?:\.\d*)?|\.\d+))%$/u);
|
|
236
|
+
const positionCoordinateSchema = z.union([z.number().finite(), positionPercentSchema]);
|
|
237
|
+
const rawImageBackgroundPositionKeywordSchema = z.enum([
|
|
238
|
+
"center",
|
|
239
|
+
"top",
|
|
240
|
+
"bottom",
|
|
241
|
+
"left",
|
|
242
|
+
"right",
|
|
243
|
+
"top left",
|
|
244
|
+
"top right",
|
|
245
|
+
"bottom left",
|
|
246
|
+
"bottom right"
|
|
247
|
+
]);
|
|
248
|
+
const imageBackgroundPositionKeywordSchema = rawImageBackgroundPositionKeywordSchema;
|
|
249
|
+
const rawImageBackgroundPositionSchema = z.union([rawImageBackgroundPositionKeywordSchema, z.strictObject({
|
|
250
|
+
x: positionCoordinateSchema.optional(),
|
|
251
|
+
y: positionCoordinateSchema.optional()
|
|
252
|
+
}).readonly()]);
|
|
253
|
+
const imageBackgroundPositionSchema = rawImageBackgroundPositionSchema;
|
|
254
|
+
const rawExternalImageFillSourceSchema = z.strictObject({ externalUrl: z.string().min(1) }).readonly();
|
|
255
|
+
const externalImageFillSourceSchema = rawExternalImageFillSourceSchema;
|
|
256
|
+
const rawImageFillSourceSchema = z.union([
|
|
257
|
+
z.string(),
|
|
258
|
+
z.instanceof(URL),
|
|
259
|
+
uint8ArraySchema,
|
|
260
|
+
rawExternalImageFillSourceSchema
|
|
261
|
+
]);
|
|
262
|
+
const imageFillSourceSchema = rawImageFillSourceSchema;
|
|
263
|
+
const rawImageBackgroundSchema = z.strictObject({
|
|
264
|
+
image: rawImageFillSourceSchema,
|
|
265
|
+
fit: rawImageBackgroundFitSchema.optional(),
|
|
266
|
+
position: rawImageBackgroundPositionSchema.optional(),
|
|
267
|
+
opacity: z.number().finite().min(0).max(1).optional()
|
|
268
|
+
}).readonly();
|
|
269
|
+
const imageBackgroundSchema = rawImageBackgroundSchema;
|
|
270
|
+
const rawBackgroundValueSchema = z.union([
|
|
271
|
+
z.literal("none"),
|
|
272
|
+
rawColorValueSchema,
|
|
273
|
+
rawLinearGradientSchema,
|
|
274
|
+
rawRadialGradientSchema,
|
|
275
|
+
rawImageBackgroundSchema
|
|
276
|
+
]);
|
|
277
|
+
const backgroundValueSchema = rawBackgroundValueSchema;
|
|
278
|
+
const rawBorderStyleSchema = z.enum([
|
|
279
|
+
"solid",
|
|
280
|
+
"dashed",
|
|
281
|
+
"dotted"
|
|
282
|
+
]);
|
|
283
|
+
const borderStyleSchema = rawBorderStyleSchema;
|
|
284
|
+
const borderObjectRawSchema = z.strictObject({
|
|
285
|
+
color: rawColorValueSchema,
|
|
286
|
+
width: z.number().finite().nonnegative().optional(),
|
|
287
|
+
style: rawBorderStyleSchema.optional()
|
|
288
|
+
});
|
|
289
|
+
const borderObjectShape = borderObjectRawSchema.shape;
|
|
290
|
+
const rawBorderObjectSchema = borderObjectRawSchema.readonly();
|
|
291
|
+
const borderObjectSchema = rawBorderObjectSchema;
|
|
292
|
+
const rawBorderValueSchema = z.union([z.literal("none"), rawBorderObjectSchema]);
|
|
293
|
+
const borderValueSchema = rawBorderValueSchema;
|
|
294
|
+
const rawShadowSchema = z.strictObject({
|
|
295
|
+
color: rawColorValueSchema.optional(),
|
|
296
|
+
blur: z.number().finite().nonnegative().optional(),
|
|
297
|
+
distance: z.number().finite().nonnegative().optional(),
|
|
298
|
+
angle: z.number().finite().optional()
|
|
299
|
+
}).readonly();
|
|
300
|
+
const shadowSchema = rawShadowSchema;
|
|
301
|
+
const rawBoxShadowValueSchema = z.union([z.literal("none"), rawShadowSchema]);
|
|
302
|
+
const boxShadowValueSchema = rawBoxShadowValueSchema;
|
|
303
|
+
const visualStyleObjectSchema = z.strictObject({
|
|
304
|
+
background: rawBackgroundValueSchema.optional(),
|
|
305
|
+
border: rawBorderValueSchema.optional(),
|
|
306
|
+
borderRadius: z.number().finite().optional(),
|
|
307
|
+
opacity: z.number().finite().optional(),
|
|
308
|
+
boxShadow: rawBoxShadowValueSchema.optional(),
|
|
309
|
+
softEdge: z.number().finite().optional(),
|
|
310
|
+
rotate: z.number().finite().optional(),
|
|
311
|
+
flipH: z.boolean().optional(),
|
|
312
|
+
flipV: z.boolean().optional()
|
|
313
|
+
});
|
|
314
|
+
const visualStyleShape = visualStyleObjectSchema.shape;
|
|
315
|
+
visualStyleObjectSchema.readonly();
|
|
316
|
+
const bcp47LangSchema = z.string().refine((value) => value.trim() !== "" && /^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$/.test(value), "Text language must be a valid BCP 47 language tag").refine((value) => {
|
|
317
|
+
try {
|
|
318
|
+
const canonical = Intl.getCanonicalLocales(value);
|
|
319
|
+
return Boolean(canonical && canonical.length === 1);
|
|
320
|
+
} catch {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}, "Text language must be a valid BCP 47 language tag");
|
|
324
|
+
const textStyleObjectSchema = z.strictObject({
|
|
325
|
+
fontFamily: rawFontReferenceSchema.optional(),
|
|
326
|
+
eastAsianFontFamily: rawFontReferenceSchema.optional(),
|
|
327
|
+
fontSize: validatedFontSizeSchema.optional(),
|
|
328
|
+
fontWeight: fontWeightSchema.optional(),
|
|
329
|
+
fontStyle: rawFontFaceStyleSchema.optional(),
|
|
330
|
+
color: rawColorValueSchema.optional(),
|
|
331
|
+
lineHeight: validatedLineHeightSchema.optional(),
|
|
332
|
+
verticalAlign: z.enum([
|
|
333
|
+
"top",
|
|
334
|
+
"middle",
|
|
335
|
+
"bottom"
|
|
336
|
+
]).optional(),
|
|
337
|
+
/** Paragraph alignment when not explicitly overridden. */
|
|
338
|
+
align: rawTextAlignmentSchema.optional(),
|
|
339
|
+
/** Paragraph space-after when not explicitly overridden, in pixels. */
|
|
340
|
+
spacingAfter: z.number().finite().nonnegative().refine((value) => {
|
|
341
|
+
const centipoints = Math.round(value * 75);
|
|
342
|
+
return centipoints >= 0 && centipoints <= 158400;
|
|
343
|
+
}, "spacingAfter converted value must be within DrawingML range of 0 to 1584pt").optional(),
|
|
344
|
+
/** Character spacing in pixels. */
|
|
345
|
+
letterSpacing: z.number().finite().refine((value) => {
|
|
346
|
+
const points = Math.round(value * 75);
|
|
347
|
+
return points >= -4e5 && points <= 4e5;
|
|
348
|
+
}, "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt").optional(),
|
|
349
|
+
textTransform: z.enum(["none", "uppercase"]).optional(),
|
|
350
|
+
textDecoration: z.enum([
|
|
351
|
+
"none",
|
|
352
|
+
"underline",
|
|
353
|
+
"line-through"
|
|
354
|
+
]).optional(),
|
|
355
|
+
textShadow: z.union([rawShadowSchema, z.literal("none")]).optional(),
|
|
356
|
+
/** Whether the text box wraps normally or keeps each line on a single line. */
|
|
357
|
+
textWrap: z.enum(["normal", "nowrap"]).optional(),
|
|
358
|
+
/** Natural language (BCP 47 language tag, e.g. zh-CN, en-US). */
|
|
359
|
+
lang: bcp47LangSchema.optional()
|
|
360
|
+
});
|
|
361
|
+
const textStyleShape = textStyleObjectSchema.shape;
|
|
362
|
+
/** Inheritable text style fields shared across text objects and containers. */
|
|
363
|
+
const textStyleSchema = textStyleObjectSchema.readonly();
|
|
364
|
+
const rawFormatColorTransformSchema = z.strictObject({
|
|
365
|
+
color: z.union([
|
|
366
|
+
z.literal("phClr"),
|
|
367
|
+
rawSchemeColorNameSchema,
|
|
368
|
+
z.string()
|
|
369
|
+
]),
|
|
370
|
+
alpha: z.number().finite().min(0).max(1).optional(),
|
|
371
|
+
lumMod: z.number().finite().min(0).max(1).optional(),
|
|
372
|
+
lumOff: z.number().finite().min(0).max(1).optional(),
|
|
373
|
+
tint: z.number().finite().min(0).max(1).optional(),
|
|
374
|
+
shade: z.number().finite().min(0).max(1).optional(),
|
|
375
|
+
satMod: z.number().finite().min(0).optional()
|
|
376
|
+
}).readonly();
|
|
377
|
+
const rawFormatGradientStopSchema = z.strictObject({
|
|
378
|
+
position: z.number().finite().min(0).max(1),
|
|
379
|
+
color: rawFormatColorTransformSchema
|
|
380
|
+
}).readonly();
|
|
381
|
+
const rawFormatFillStyleSchema = z.union([
|
|
382
|
+
z.strictObject({ kind: z.literal("none") }).readonly(),
|
|
383
|
+
z.strictObject({
|
|
384
|
+
kind: z.literal("solid"),
|
|
385
|
+
color: rawFormatColorTransformSchema
|
|
386
|
+
}).readonly(),
|
|
387
|
+
z.strictObject({
|
|
388
|
+
kind: z.literal("gradient"),
|
|
389
|
+
rotWithShape: z.boolean().optional(),
|
|
390
|
+
stops: z.array(rawFormatGradientStopSchema).readonly(),
|
|
391
|
+
linear: z.strictObject({
|
|
392
|
+
angle: z.number().finite(),
|
|
393
|
+
scaled: z.boolean().optional()
|
|
394
|
+
}).readonly().optional(),
|
|
395
|
+
path: z.strictObject({
|
|
396
|
+
shape: z.enum([
|
|
397
|
+
"circle",
|
|
398
|
+
"rect",
|
|
399
|
+
"shape"
|
|
400
|
+
]),
|
|
401
|
+
fillToRect: z.strictObject({
|
|
402
|
+
l: z.number().finite(),
|
|
403
|
+
t: z.number().finite(),
|
|
404
|
+
r: z.number().finite(),
|
|
405
|
+
b: z.number().finite()
|
|
406
|
+
}).readonly().optional()
|
|
407
|
+
}).readonly().optional()
|
|
408
|
+
}).readonly()
|
|
409
|
+
]);
|
|
410
|
+
const rawFormatLineStyleSchema = z.strictObject({
|
|
411
|
+
widthEmu: z.number().int().nonnegative().optional(),
|
|
412
|
+
cap: z.enum([
|
|
413
|
+
"rnd",
|
|
414
|
+
"sq",
|
|
415
|
+
"flat"
|
|
416
|
+
]).optional(),
|
|
417
|
+
compound: z.enum([
|
|
418
|
+
"sng",
|
|
419
|
+
"dbl",
|
|
420
|
+
"thickThin",
|
|
421
|
+
"thinThick",
|
|
422
|
+
"tri"
|
|
423
|
+
]).optional(),
|
|
424
|
+
align: z.enum(["ctr", "in"]).optional(),
|
|
425
|
+
dash: z.string().optional(),
|
|
426
|
+
fill: rawFormatFillStyleSchema.optional()
|
|
427
|
+
}).readonly();
|
|
428
|
+
const rawFormatEffectStyleSchema = z.strictObject({ shadow: rawShadowSchema.optional() }).readonly();
|
|
429
|
+
const rawFormatSchemeSchema = z.strictObject({
|
|
430
|
+
name: z.string().optional(),
|
|
431
|
+
fillStyles: z.array(rawFormatFillStyleSchema).readonly().optional(),
|
|
432
|
+
lineStyles: z.array(rawFormatLineStyleSchema).readonly().optional(),
|
|
433
|
+
effectStyles: z.array(rawFormatEffectStyleSchema).readonly().optional(),
|
|
434
|
+
bgFillStyles: z.array(rawFormatFillStyleSchema).readonly().optional()
|
|
435
|
+
}).readonly();
|
|
436
|
+
/** DrawingML `<a:fmtScheme>` style matrix stored on a native theme or theme override. */
|
|
437
|
+
const formatSchemeSchema = rawFormatSchemeSchema;
|
|
438
|
+
/** Deck-level or master-level theme input; major/minor fonts and 12 native color slots are written to native PPTX theme. */
|
|
439
|
+
const themeInputSchema = z.strictObject({
|
|
440
|
+
name: z.string().optional(),
|
|
441
|
+
colors: z.strictObject({
|
|
442
|
+
dk1: rawThemeHexColorSchema.optional(),
|
|
443
|
+
lt1: rawThemeHexColorSchema.optional(),
|
|
444
|
+
dk2: rawThemeHexColorSchema.optional(),
|
|
445
|
+
lt2: rawThemeHexColorSchema.optional(),
|
|
446
|
+
accent1: rawThemeHexColorSchema.optional(),
|
|
447
|
+
accent2: rawThemeHexColorSchema.optional(),
|
|
448
|
+
accent3: rawThemeHexColorSchema.optional(),
|
|
449
|
+
accent4: rawThemeHexColorSchema.optional(),
|
|
450
|
+
accent5: rawThemeHexColorSchema.optional(),
|
|
451
|
+
accent6: rawThemeHexColorSchema.optional(),
|
|
452
|
+
hlink: rawThemeHexColorSchema.optional(),
|
|
453
|
+
folHlink: rawThemeHexColorSchema.optional()
|
|
454
|
+
}).readonly().optional(),
|
|
455
|
+
fonts: z.strictObject({
|
|
456
|
+
major: rawThemeFontValueSchema.optional(),
|
|
457
|
+
minor: rawThemeFontValueSchema.optional(),
|
|
458
|
+
majorEastAsian: rawThemeFontValueSchema.optional(),
|
|
459
|
+
minorEastAsian: rawThemeFontValueSchema.optional()
|
|
460
|
+
}).readonly().optional(),
|
|
461
|
+
formatScheme: rawFormatSchemeSchema.optional()
|
|
462
|
+
}).readonly();
|
|
463
|
+
/** Native `<a:themeOverride>` partial override for a SlideLayout or Slide. */
|
|
464
|
+
const themeOverrideSchema = z.strictObject({
|
|
465
|
+
colors: z.strictObject({
|
|
466
|
+
dk1: rawThemeHexColorSchema.optional(),
|
|
467
|
+
lt1: rawThemeHexColorSchema.optional(),
|
|
468
|
+
dk2: rawThemeHexColorSchema.optional(),
|
|
469
|
+
lt2: rawThemeHexColorSchema.optional(),
|
|
470
|
+
accent1: rawThemeHexColorSchema.optional(),
|
|
471
|
+
accent2: rawThemeHexColorSchema.optional(),
|
|
472
|
+
accent3: rawThemeHexColorSchema.optional(),
|
|
473
|
+
accent4: rawThemeHexColorSchema.optional(),
|
|
474
|
+
accent5: rawThemeHexColorSchema.optional(),
|
|
475
|
+
accent6: rawThemeHexColorSchema.optional(),
|
|
476
|
+
hlink: rawThemeHexColorSchema.optional(),
|
|
477
|
+
folHlink: rawThemeHexColorSchema.optional()
|
|
478
|
+
}).readonly().optional(),
|
|
479
|
+
fonts: z.strictObject({
|
|
480
|
+
major: rawThemeFontValueSchema.optional(),
|
|
481
|
+
minor: rawThemeFontValueSchema.optional(),
|
|
482
|
+
majorEastAsian: rawThemeFontValueSchema.optional(),
|
|
483
|
+
minorEastAsian: rawThemeFontValueSchema.optional()
|
|
484
|
+
}).readonly().optional(),
|
|
485
|
+
formatScheme: rawFormatSchemeSchema.optional()
|
|
486
|
+
}).readonly();
|
|
487
|
+
const rawThemeDataSchema = z.strictObject({
|
|
488
|
+
name: z.string(),
|
|
489
|
+
colors: z.strictObject({
|
|
490
|
+
dk1: rawThemeHexColorSchema,
|
|
491
|
+
lt1: rawThemeHexColorSchema,
|
|
492
|
+
dk2: rawThemeHexColorSchema,
|
|
493
|
+
lt2: rawThemeHexColorSchema,
|
|
494
|
+
accent1: rawThemeHexColorSchema,
|
|
495
|
+
accent2: rawThemeHexColorSchema,
|
|
496
|
+
accent3: rawThemeHexColorSchema,
|
|
497
|
+
accent4: rawThemeHexColorSchema,
|
|
498
|
+
accent5: rawThemeHexColorSchema,
|
|
499
|
+
accent6: rawThemeHexColorSchema,
|
|
500
|
+
hlink: rawThemeHexColorSchema,
|
|
501
|
+
folHlink: rawThemeHexColorSchema
|
|
502
|
+
}).readonly(),
|
|
503
|
+
fonts: z.strictObject({
|
|
504
|
+
major: rawThemeFontValueSchema,
|
|
505
|
+
minor: rawThemeFontValueSchema,
|
|
506
|
+
majorEastAsian: rawThemeFontValueSchema.optional(),
|
|
507
|
+
minorEastAsian: rawThemeFontValueSchema.optional()
|
|
508
|
+
}).readonly(),
|
|
509
|
+
formatScheme: rawFormatSchemeSchema.optional()
|
|
510
|
+
}).readonly();
|
|
511
|
+
const themeDataSchema = rawThemeDataSchema;
|
|
512
|
+
const themeSchema = rawThemeDataSchema.transform((data) => defineTheme(data));
|
|
513
|
+
z.strictObject({
|
|
514
|
+
family: z.string(),
|
|
515
|
+
font: rawFontSchema.optional(),
|
|
516
|
+
themeFont: z.enum(["major", "minor"]).optional()
|
|
517
|
+
}).readonly();
|
|
518
|
+
const officeColors = {
|
|
519
|
+
dk1: "#000000",
|
|
520
|
+
lt1: "#FFFFFF",
|
|
521
|
+
dk2: "#1F497D",
|
|
522
|
+
lt2: "#EEECE1",
|
|
523
|
+
accent1: "#4F81BD",
|
|
524
|
+
accent2: "#C0504D",
|
|
525
|
+
accent3: "#9BBB59",
|
|
526
|
+
accent4: "#8064A2",
|
|
527
|
+
accent5: "#4BACC6",
|
|
528
|
+
accent6: "#F79646",
|
|
529
|
+
hlink: "#0000FF",
|
|
530
|
+
folHlink: "#800080"
|
|
531
|
+
};
|
|
532
|
+
const contextRecords = /* @__PURE__ */ new WeakMap();
|
|
533
|
+
const textStyleKeys = new Set(Object.keys(textStyleObjectSchema.shape));
|
|
534
|
+
function textStyleErrorForIssue(issue, rawStyle) {
|
|
535
|
+
const field = issue?.path[0];
|
|
536
|
+
if (field === "fontFamily" || field === "eastAsianFontFamily") {
|
|
537
|
+
if (issue?.path[1] === "faces" || issue?.code === "invalid_union" && issue.errors.some((branch) => branch.some((sub) => sub.path[0] === "faces"))) return new CapabilityError("invalid-font-face", "Font.faces contains invalid weight, style, or resource");
|
|
538
|
+
return new CapabilityError("invalid-font-family", issue?.message ?? `${field} must be a font value or non-empty family string`);
|
|
539
|
+
}
|
|
540
|
+
if (field === "fontSize") {
|
|
541
|
+
const raw = rawStyle["fontSize"];
|
|
542
|
+
const validLengthSyntax = typeof raw === "number" || typeof raw === "string" && textLengthPattern.test(raw);
|
|
543
|
+
return new CapabilityError(validLengthSyntax ? "invalid-font-size" : "invalid-text-length", validLengthSyntax ? "fontSize must be greater than 0 and within DrawingML range of 1 to 4000pt" : "fontSize must be a positive pixel value or px/pt length");
|
|
544
|
+
}
|
|
545
|
+
if (field === "fontWeight") return new CapabilityError("invalid-font-weight", "fontWeight must be normal, bold, or an integer between 1 and 1000");
|
|
546
|
+
if (field === "fontStyle") return new CapabilityError("invalid-font-style", "fontStyle must be normal or italic");
|
|
547
|
+
if (field === "color") return new CapabilityError("invalid-color", "Invalid color value format", void 0, { field: "style.color" });
|
|
548
|
+
if (field === "lineHeight") return new CapabilityError("invalid-text-length", "lineHeight must be a positive pixel value, px/pt length within 0 to 1584pt, or percentage within 0% to 13200%");
|
|
549
|
+
if (field === "verticalAlign") return new CapabilityError("invalid-vertical-align", "verticalAlign must be top, middle, or bottom");
|
|
550
|
+
if (field === "align") return new CapabilityError("invalid-text-alignment", "align must be left, center, right, or justify");
|
|
551
|
+
if (field === "spacingAfter") return new CapabilityError("invalid-paragraph-spacing", "spacingAfter must be a finite non-negative pixel number within DrawingML range of 0 to 1584pt");
|
|
552
|
+
if (field === "letterSpacing") return new CapabilityError("invalid-letter-spacing", "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt");
|
|
553
|
+
if (field === "textTransform") return new CapabilityError("invalid-text-transform", "textTransform must be none or uppercase");
|
|
554
|
+
if (field === "textDecoration") return new CapabilityError("invalid-text-decoration", "textDecoration must be none, underline, or line-through");
|
|
555
|
+
if (field === "textWrap") return new CapabilityError("invalid-text-wrap", "textWrap must be normal or nowrap");
|
|
556
|
+
if (field === "textShadow") {
|
|
557
|
+
if (issue?.path[1] === "color") return new CapabilityError("invalid-color", "Invalid color value format", void 0, { field: "style.textShadow.color" });
|
|
558
|
+
return new CapabilityError("invalid-shadow", issue?.message ?? "textShadow must be a shadow object or 'none'");
|
|
559
|
+
}
|
|
560
|
+
if (field === "lang") return new CapabilityError("invalid-text-lang", `Text language must be a valid BCP 47 language tag: ${String(rawStyle["lang"])}`);
|
|
561
|
+
return new CapabilityError("invalid-style", issue?.message ?? "Invalid text style");
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Validates inheritable text style fields shared across text objects and containers.
|
|
565
|
+
*/
|
|
566
|
+
function validateTextStyle(style, theme) {
|
|
567
|
+
const candidate = {};
|
|
568
|
+
for (const [key, item] of Object.entries(style)) if (textStyleKeys.has(key) && item !== void 0) candidate[key] = item;
|
|
569
|
+
const parsed = textStyleObjectSchema.safeParse(candidate);
|
|
570
|
+
if (!parsed.success) throw textStyleErrorForIssue(parsed.error.issues[0], candidate);
|
|
571
|
+
const validated = parsed.data;
|
|
572
|
+
if (theme !== void 0) {
|
|
573
|
+
if (typeof validated.fontFamily === "string") theme.resolveFont(validated.fontFamily);
|
|
574
|
+
if (typeof validated.eastAsianFontFamily === "string") theme.resolveEastAsianFont(validated.eastAsianFontFamily);
|
|
575
|
+
if (validated.color !== void 0) theme.resolveColor(validated.color);
|
|
576
|
+
if (validated.textShadow !== void 0 && validated.textShadow !== "none" && validated.textShadow.color !== void 0) theme.resolveColor(validated.textShadow.color);
|
|
577
|
+
}
|
|
578
|
+
return style;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Asserts that a value is a valid BCP 47 language tag.
|
|
582
|
+
* Rejects non-string values, empty or whitespace strings, and malformed tags.
|
|
583
|
+
*/
|
|
584
|
+
function assertValidLang(value) {
|
|
585
|
+
const parsed = bcp47LangSchema.safeParse(value);
|
|
586
|
+
if (!parsed.success) throw new CapabilityError("invalid-text-lang", `Text language must be a valid BCP 47 language tag: ${String(value)}`);
|
|
587
|
+
return parsed.data;
|
|
588
|
+
}
|
|
589
|
+
function record(value) {
|
|
590
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
591
|
+
}
|
|
592
|
+
/** Extract inheritable text fields from container style containing layout fields. */
|
|
593
|
+
function textStyleFrom(value, theme) {
|
|
594
|
+
if (value === void 0) return {};
|
|
595
|
+
if (!record(value)) throw new CapabilityError("invalid-style", "style must be an object");
|
|
596
|
+
const extracted = {};
|
|
597
|
+
for (const [key, item] of Object.entries(value)) if (textStyleKeys.has(key) && item !== void 0) extracted[key] = item;
|
|
598
|
+
return validateTextStyle(extracted, theme);
|
|
599
|
+
}
|
|
600
|
+
function nativeSlot(value) {
|
|
601
|
+
return nativeColorSlots.includes(value);
|
|
602
|
+
}
|
|
603
|
+
function schemeSlot(value) {
|
|
604
|
+
return schemeColorSlots.includes(value);
|
|
605
|
+
}
|
|
606
|
+
function schemeColorName(value) {
|
|
607
|
+
return schemeColorNames.includes(value);
|
|
608
|
+
}
|
|
609
|
+
function isSchemeColorSlot(value) {
|
|
610
|
+
return schemeSlot(value);
|
|
611
|
+
}
|
|
612
|
+
function isSchemeColorName(value) {
|
|
613
|
+
return schemeColorName(value);
|
|
614
|
+
}
|
|
615
|
+
function isFont(value) {
|
|
616
|
+
return record(value) && typeof value["family"] === "string";
|
|
617
|
+
}
|
|
618
|
+
const themeBrandSymbol = Symbol.for("@pptxdk/core/theme");
|
|
619
|
+
/** Checks whether a runtime value is an identity-bearing `Theme` instance produced by `defineTheme`. */
|
|
620
|
+
function isTheme(value) {
|
|
621
|
+
return typeof value === "object" && value !== null && themeBrandSymbol in value;
|
|
622
|
+
}
|
|
623
|
+
var NativeThemeRecord = class {
|
|
624
|
+
[themeBrandSymbol] = true;
|
|
625
|
+
#name;
|
|
626
|
+
#colors;
|
|
627
|
+
#fonts;
|
|
628
|
+
#formatScheme;
|
|
629
|
+
constructor(initial) {
|
|
630
|
+
this.#name = initial.name;
|
|
631
|
+
this.#colors = initial.colors;
|
|
632
|
+
this.#fonts = initial.fonts;
|
|
633
|
+
this.#formatScheme = initial.formatScheme;
|
|
634
|
+
Object.defineProperties(this, {
|
|
635
|
+
name: {
|
|
636
|
+
enumerable: true,
|
|
637
|
+
configurable: false,
|
|
638
|
+
get: () => this.#name
|
|
639
|
+
},
|
|
640
|
+
colors: {
|
|
641
|
+
enumerable: true,
|
|
642
|
+
configurable: false,
|
|
643
|
+
get: () => this.#colors
|
|
644
|
+
},
|
|
645
|
+
fonts: {
|
|
646
|
+
enumerable: true,
|
|
647
|
+
configurable: false,
|
|
648
|
+
get: () => this.#fonts
|
|
649
|
+
},
|
|
650
|
+
...initial.formatScheme === void 0 ? {} : { formatScheme: {
|
|
651
|
+
enumerable: true,
|
|
652
|
+
configurable: false,
|
|
653
|
+
get: () => this.#formatScheme
|
|
654
|
+
} }
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
get name() {
|
|
658
|
+
return this.#name;
|
|
659
|
+
}
|
|
660
|
+
get colors() {
|
|
661
|
+
return this.#colors;
|
|
662
|
+
}
|
|
663
|
+
get fonts() {
|
|
664
|
+
return this.#fonts;
|
|
665
|
+
}
|
|
666
|
+
get formatScheme() {
|
|
667
|
+
return this.#formatScheme;
|
|
668
|
+
}
|
|
669
|
+
set(patch) {
|
|
670
|
+
if (this === defaultTheme) throw new TypeError("Cannot mutate defaultTheme");
|
|
671
|
+
if (!record(patch)) throw new TypeError("Theme update must be an object");
|
|
672
|
+
const parsed = themeInputSchema.safeParse(patch);
|
|
673
|
+
if (!parsed.success) {
|
|
674
|
+
const issue = parsed.error.issues[0];
|
|
675
|
+
const field = issue !== void 0 && issue.path.length > 0 ? `theme.${issue.path.join(".")}` : "theme";
|
|
676
|
+
throw new CapabilityError("invalid-theme", issue?.message ?? "Invalid theme declaration", void 0, { field });
|
|
677
|
+
}
|
|
678
|
+
const validPatch = parsed.data;
|
|
679
|
+
if (validPatch.name !== void 0) this.#name = validPatch.name;
|
|
680
|
+
if (validPatch.colors !== void 0) this.#colors = snapshotValue({
|
|
681
|
+
...this.#colors,
|
|
682
|
+
...validPatch.colors
|
|
683
|
+
});
|
|
684
|
+
if (validPatch.fonts !== void 0) {
|
|
685
|
+
const mergedFonts = { ...this.#fonts };
|
|
686
|
+
for (const [key, value] of Object.entries(validPatch.fonts)) if (value !== void 0) mergedFonts[key] = value;
|
|
687
|
+
this.#fonts = snapshotValue(mergedFonts);
|
|
688
|
+
}
|
|
689
|
+
if (validPatch.formatScheme !== void 0) {
|
|
690
|
+
const hadFormatScheme = Object.hasOwn(this, "formatScheme");
|
|
691
|
+
this.#formatScheme = snapshotValue(validPatch.formatScheme);
|
|
692
|
+
if (!hadFormatScheme) Object.defineProperty(this, "formatScheme", {
|
|
693
|
+
enumerable: true,
|
|
694
|
+
configurable: false,
|
|
695
|
+
get: () => this.#formatScheme
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
return this;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
function parseThemeInputData(input = {}) {
|
|
702
|
+
if (!record(input)) throw new TypeError("Theme must be an object");
|
|
703
|
+
const parsed = themeInputSchema.safeParse(input);
|
|
704
|
+
if (!parsed.success) {
|
|
705
|
+
const issue = parsed.error.issues[0];
|
|
706
|
+
const field = issue !== void 0 && issue.path.length > 0 ? `theme.${issue.path.join(".")}` : "theme";
|
|
707
|
+
throw new CapabilityError("invalid-theme", issue?.message ?? "Invalid theme declaration", void 0, { field });
|
|
708
|
+
}
|
|
709
|
+
const validInput = parsed.data;
|
|
710
|
+
const colors = snapshotValue({
|
|
711
|
+
...officeColors,
|
|
712
|
+
...validInput.colors
|
|
713
|
+
});
|
|
714
|
+
const fonts = snapshotValue({
|
|
715
|
+
major: validInput.fonts?.major ?? "Aptos Display",
|
|
716
|
+
minor: validInput.fonts?.minor ?? "Aptos",
|
|
717
|
+
...validInput.fonts?.majorEastAsian === void 0 ? {} : { majorEastAsian: validInput.fonts.majorEastAsian },
|
|
718
|
+
...validInput.fonts?.minorEastAsian === void 0 ? {} : { minorEastAsian: validInput.fonts.minorEastAsian }
|
|
719
|
+
});
|
|
720
|
+
const formatScheme = validInput.formatScheme === void 0 ? void 0 : snapshotValue(validInput.formatScheme);
|
|
721
|
+
return {
|
|
722
|
+
name: validInput.name ?? "Office Theme",
|
|
723
|
+
colors,
|
|
724
|
+
fonts,
|
|
725
|
+
...formatScheme === void 0 ? {} : { formatScheme }
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
function normalizeTheme(input) {
|
|
729
|
+
if (input === void 0) return defaultTheme;
|
|
730
|
+
if (isTheme(input)) return input;
|
|
731
|
+
return new NativeThemeRecord(parseThemeInputData(input));
|
|
732
|
+
}
|
|
733
|
+
/** Fill unsupplied theme items using initial Office palette and fonts, returning an identity-bearing `Theme`. */
|
|
734
|
+
function defineTheme(input = {}) {
|
|
735
|
+
return new NativeThemeRecord(parseThemeInputData(input));
|
|
736
|
+
}
|
|
737
|
+
const defaultTheme = defineTheme();
|
|
738
|
+
/** Generate darker variant in PowerPoint native palette. */
|
|
739
|
+
function darker(slot, amount) {
|
|
740
|
+
return {
|
|
741
|
+
slot,
|
|
742
|
+
lumMod: 1 - amount
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
/** Generate lighter variant in PowerPoint native palette. */
|
|
746
|
+
function lighter(slot, amount) {
|
|
747
|
+
return {
|
|
748
|
+
slot,
|
|
749
|
+
lumMod: 1 - amount,
|
|
750
|
+
lumOff: amount
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function isNativeColorSlot(value) {
|
|
754
|
+
return nativeSlot(value);
|
|
755
|
+
}
|
|
756
|
+
function rgbChannelsFromHex(hex) {
|
|
757
|
+
return [
|
|
758
|
+
0,
|
|
759
|
+
2,
|
|
760
|
+
4
|
|
761
|
+
].map((start) => Number.parseInt(hex.slice(start, start + 2), 16) / 255);
|
|
762
|
+
}
|
|
763
|
+
function hexFromRgbChannels(r, g, b) {
|
|
764
|
+
return [
|
|
765
|
+
r,
|
|
766
|
+
g,
|
|
767
|
+
b
|
|
768
|
+
].map((channel) => Math.round(Math.min(1, Math.max(0, channel)) * 255).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
769
|
+
}
|
|
770
|
+
function rgbToHsl(r, g, b) {
|
|
771
|
+
const max = Math.max(r, g, b);
|
|
772
|
+
const min = Math.min(r, g, b);
|
|
773
|
+
const lightness = (max + min) / 2;
|
|
774
|
+
const delta = max - min;
|
|
775
|
+
const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
|
|
776
|
+
return [
|
|
777
|
+
delta === 0 ? 0 : max === r ? ((g - b) / delta + 6) % 6 : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4,
|
|
778
|
+
saturation,
|
|
779
|
+
lightness
|
|
780
|
+
];
|
|
781
|
+
}
|
|
782
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
783
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
784
|
+
const x = chroma * (1 - Math.abs(hue % 2 - 1));
|
|
785
|
+
const m = lightness - chroma / 2;
|
|
786
|
+
const [r1, g1, b1] = hue < 1 ? [
|
|
787
|
+
chroma,
|
|
788
|
+
x,
|
|
789
|
+
0
|
|
790
|
+
] : hue < 2 ? [
|
|
791
|
+
x,
|
|
792
|
+
chroma,
|
|
793
|
+
0
|
|
794
|
+
] : hue < 3 ? [
|
|
795
|
+
0,
|
|
796
|
+
chroma,
|
|
797
|
+
x
|
|
798
|
+
] : hue < 4 ? [
|
|
799
|
+
0,
|
|
800
|
+
x,
|
|
801
|
+
chroma
|
|
802
|
+
] : hue < 5 ? [
|
|
803
|
+
x,
|
|
804
|
+
0,
|
|
805
|
+
chroma
|
|
806
|
+
] : [
|
|
807
|
+
chroma,
|
|
808
|
+
0,
|
|
809
|
+
x
|
|
810
|
+
];
|
|
811
|
+
return [
|
|
812
|
+
r1 + m,
|
|
813
|
+
g1 + m,
|
|
814
|
+
b1 + m
|
|
815
|
+
];
|
|
816
|
+
}
|
|
817
|
+
function shadeHex(hex, lumMod, lumOff) {
|
|
818
|
+
const [r, g, b] = rgbChannelsFromHex(hex);
|
|
819
|
+
const [hue, saturation, lightness] = rgbToHsl(r, g, b);
|
|
820
|
+
const [r1, g1, b1] = hslToRgb(hue, saturation, Math.min(1, Math.max(0, lightness * lumMod + lumOff)));
|
|
821
|
+
return hexFromRgbChannels(r1, g1, b1);
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Applies DrawingML color modifiers (`tint`, `shade`, `satMod`, `lumMod`, `lumOff`, `alpha`)
|
|
825
|
+
* onto a resolved base color (used by theme format schemes and `<p:bgRef>` evaluation).
|
|
826
|
+
*/
|
|
827
|
+
function applyFormatColorTransforms(base, transform) {
|
|
828
|
+
let [r, g, b] = rgbChannelsFromHex(base.hex);
|
|
829
|
+
if (transform.tint !== void 0) {
|
|
830
|
+
const t = transform.tint;
|
|
831
|
+
r = r * t + (1 - t);
|
|
832
|
+
g = g * t + (1 - t);
|
|
833
|
+
b = b * t + (1 - t);
|
|
834
|
+
}
|
|
835
|
+
if (transform.shade !== void 0) {
|
|
836
|
+
const s = transform.shade;
|
|
837
|
+
r *= s;
|
|
838
|
+
g *= s;
|
|
839
|
+
b *= s;
|
|
840
|
+
}
|
|
841
|
+
if (transform.satMod !== void 0 || transform.lumMod !== void 0 || transform.lumOff !== void 0) {
|
|
842
|
+
const [hue, sat, lum] = rgbToHsl(r, g, b);
|
|
843
|
+
const nextSat = Math.min(1, Math.max(0, sat * (transform.satMod ?? 1)));
|
|
844
|
+
const nextLum = Math.min(1, Math.max(0, lum * (transform.lumMod ?? 1) + (transform.lumOff ?? 0)));
|
|
845
|
+
[r, g, b] = hslToRgb(hue, nextSat, nextLum);
|
|
846
|
+
}
|
|
847
|
+
const alpha = transform.alpha === void 0 ? base.alpha : (base.alpha ?? 1) * transform.alpha;
|
|
848
|
+
return {
|
|
849
|
+
hex: hexFromRgbChannels(r, g, b),
|
|
850
|
+
...alpha === void 0 || alpha === 1 ? {} : { alpha },
|
|
851
|
+
...base.slot === void 0 ? {} : { slot: base.slot },
|
|
852
|
+
...base.scheme === void 0 ? {} : { scheme: base.scheme }
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function checkedFraction(value, label) {
|
|
856
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new CapabilityError("invalid-color", `${label} must be a number between 0 and 1`);
|
|
857
|
+
return value;
|
|
858
|
+
}
|
|
859
|
+
function effectiveThemeColor(context, slot) {
|
|
860
|
+
return contextRecords.get(context)?.colors?.[slot] ?? context.theme.colors[slot];
|
|
861
|
+
}
|
|
862
|
+
function parseThemeHexValue(raw) {
|
|
863
|
+
const digits = raw.trim().slice(1);
|
|
864
|
+
const expanded = digits.length === 3 || digits.length === 4 ? digits.split("").map((digit) => digit + digit).join("") : digits;
|
|
865
|
+
if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/iu.test(expanded)) throw new CapabilityError("invalid-color", `Invalid color value: ${raw}`);
|
|
866
|
+
const alpha = expanded.length === 8 ? Number.parseInt(expanded.slice(6), 16) / 255 : void 0;
|
|
867
|
+
return {
|
|
868
|
+
hex: expanded.slice(0, 6).toUpperCase(),
|
|
869
|
+
...alpha === void 0 || alpha === 1 ? {} : { alpha }
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function resolveColorName(raw, context) {
|
|
873
|
+
const value = raw.trim();
|
|
874
|
+
if (value.startsWith("#")) return parseThemeHexValue(value);
|
|
875
|
+
if (schemeSlot(value)) {
|
|
876
|
+
const mappedSlot = context.colorMap[value];
|
|
877
|
+
const configured = effectiveThemeColor(context, mappedSlot);
|
|
878
|
+
if (!configured.trim().startsWith("#")) throw new CapabilityError("invalid-color", `Invalid color value: ${configured}`);
|
|
879
|
+
return {
|
|
880
|
+
...parseThemeHexValue(configured),
|
|
881
|
+
slot: mappedSlot,
|
|
882
|
+
scheme: value
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
if (nativeSlot(value)) {
|
|
886
|
+
const configured = effectiveThemeColor(context, value);
|
|
887
|
+
if (!configured.trim().startsWith("#")) throw new CapabilityError("invalid-color", `Invalid color value: ${configured}`);
|
|
888
|
+
return {
|
|
889
|
+
...parseThemeHexValue(configured),
|
|
890
|
+
slot: value,
|
|
891
|
+
scheme: value
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
throw new CapabilityError("invalid-color", `Unknown color or scheme color slot: ${raw}`);
|
|
895
|
+
}
|
|
896
|
+
function resolveColorValue(value, context) {
|
|
897
|
+
if (typeof value === "string") return resolveColorName(value, context);
|
|
898
|
+
if (!record(value) || !schemeColorName(String(value["slot"])) || typeof value["lumMod"] !== "number" || !Number.isFinite(value["lumMod"])) throw new CapabilityError("invalid-color", "Invalid theme shade value");
|
|
899
|
+
const lumMod = checkedFraction(value["lumMod"], "lumMod");
|
|
900
|
+
const lumOff = value["lumOff"] === void 0 ? void 0 : checkedFraction(value["lumOff"], "lumOff");
|
|
901
|
+
const scheme = value["slot"];
|
|
902
|
+
const base = resolveColorName(scheme, context);
|
|
903
|
+
return {
|
|
904
|
+
hex: shadeHex(base.hex, lumMod, lumOff ?? 0),
|
|
905
|
+
...base.slot === void 0 ? {} : { slot: base.slot },
|
|
906
|
+
scheme,
|
|
907
|
+
lumMod,
|
|
908
|
+
...lumOff === void 0 ? {} : { lumOff }
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
function mergeThemeOverrides(base, next) {
|
|
912
|
+
if (base === void 0) return next;
|
|
913
|
+
if (next === void 0) return base;
|
|
914
|
+
const colors = base.colors === void 0 && next.colors === void 0 ? void 0 : {
|
|
915
|
+
...base.colors,
|
|
916
|
+
...next.colors
|
|
917
|
+
};
|
|
918
|
+
const fonts = base.fonts === void 0 && next.fonts === void 0 ? void 0 : {
|
|
919
|
+
...base.fonts,
|
|
920
|
+
...next.fonts
|
|
921
|
+
};
|
|
922
|
+
const formatScheme = next.formatScheme ?? base.formatScheme;
|
|
923
|
+
return Object.freeze({
|
|
924
|
+
...colors === void 0 ? {} : { colors: Object.freeze(colors) },
|
|
925
|
+
...fonts === void 0 ? {} : { fonts: Object.freeze(fonts) },
|
|
926
|
+
...formatScheme === void 0 ? {} : { formatScheme }
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
function createContext(theme, textStyle, colorMap = defaultColorMap, themeOverride) {
|
|
930
|
+
const formatScheme = themeOverride?.formatScheme ?? theme.formatScheme;
|
|
931
|
+
let context;
|
|
932
|
+
context = Object.freeze({
|
|
933
|
+
theme,
|
|
934
|
+
colorMap,
|
|
935
|
+
formatScheme,
|
|
936
|
+
textStyle: Object.freeze(textStyle),
|
|
937
|
+
with(style) {
|
|
938
|
+
const validated = style === void 0 ? {} : textStyleFrom(style, context);
|
|
939
|
+
return createContext(theme, {
|
|
940
|
+
...context.textStyle,
|
|
941
|
+
...validated
|
|
942
|
+
}, colorMap, themeOverride);
|
|
943
|
+
},
|
|
944
|
+
withTextStyle(style) {
|
|
945
|
+
return createContext(theme, textStyleFrom(style, context), colorMap, themeOverride);
|
|
946
|
+
},
|
|
947
|
+
withNativeOverrides(nextThemeOverride, nextColorMapOverride) {
|
|
948
|
+
const mergedOverride = mergeThemeOverrides(themeOverride, nextThemeOverride);
|
|
949
|
+
const nextColorMap = nextColorMapOverride === void 0 || nextColorMapOverride === "master" ? colorMap : nextColorMapOverride;
|
|
950
|
+
return createContext(theme, context.textStyle, nextColorMap, mergedOverride);
|
|
951
|
+
},
|
|
952
|
+
resolveColor(value) {
|
|
953
|
+
let raw;
|
|
954
|
+
let alpha;
|
|
955
|
+
if (typeof value === "string" || record(value) && "slot" in value) raw = value;
|
|
956
|
+
else if (record(value) && "color" in value) {
|
|
957
|
+
raw = value["color"];
|
|
958
|
+
alpha = value["alpha"] === void 0 ? void 0 : checkedFraction(value["alpha"], "color alpha");
|
|
959
|
+
} else throw new CapabilityError("invalid-color", "Invalid color value format");
|
|
960
|
+
const resolved = typeof raw === "string" ? resolveColorName(raw, context) : resolveColorValue(raw, context);
|
|
961
|
+
if (alpha === void 0) return resolved;
|
|
962
|
+
return {
|
|
963
|
+
...resolved,
|
|
964
|
+
alpha: (resolved.alpha ?? 1) * alpha
|
|
965
|
+
};
|
|
966
|
+
},
|
|
967
|
+
resolveFont(value) {
|
|
968
|
+
if (isFont(value)) return {
|
|
969
|
+
family: value.family,
|
|
970
|
+
font: value
|
|
971
|
+
};
|
|
972
|
+
if (typeof value !== "string" || value.trim() === "") throw new CapabilityError("invalid-font-family", "fontFamily cannot be empty");
|
|
973
|
+
if (isThemeFontSlot(value)) {
|
|
974
|
+
const slotFont = themeOverride?.fonts?.[value] ?? theme.fonts[value];
|
|
975
|
+
if (isFont(slotFont)) return {
|
|
976
|
+
family: slotFont.family,
|
|
977
|
+
font: slotFont,
|
|
978
|
+
themeFont: value
|
|
979
|
+
};
|
|
980
|
+
return {
|
|
981
|
+
family: slotFont,
|
|
982
|
+
themeFont: value
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
return { family: value.trim() };
|
|
986
|
+
},
|
|
987
|
+
resolveEastAsianFont(value) {
|
|
988
|
+
if (isFont(value)) return {
|
|
989
|
+
family: value.family,
|
|
990
|
+
font: value
|
|
991
|
+
};
|
|
992
|
+
if (typeof value !== "string" || value.trim() === "") throw new CapabilityError("invalid-font-family", "eastAsianFontFamily cannot be empty");
|
|
993
|
+
if (isThemeFontSlot(value)) {
|
|
994
|
+
const eaKey = value === "major" ? "majorEastAsian" : "minorEastAsian";
|
|
995
|
+
const slotFont = themeOverride?.fonts?.[eaKey] ?? theme.fonts[eaKey] ?? themeOverride?.fonts?.[value] ?? theme.fonts[value];
|
|
996
|
+
if (isFont(slotFont)) return {
|
|
997
|
+
family: slotFont.family,
|
|
998
|
+
font: slotFont,
|
|
999
|
+
themeFont: value
|
|
1000
|
+
};
|
|
1001
|
+
return {
|
|
1002
|
+
family: slotFont,
|
|
1003
|
+
themeFont: value
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
return { family: value.trim() };
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
if (themeOverride !== void 0) contextRecords.set(context, themeOverride);
|
|
1010
|
+
return context;
|
|
1011
|
+
}
|
|
1012
|
+
/** Create a theme chain unique to a single build; container text defaults do not mutate the shared theme object. */
|
|
1013
|
+
function createThemeContext(input, style, options = {}) {
|
|
1014
|
+
if (style !== void 0) {
|
|
1015
|
+
if (!record(style)) throw new CapabilityError("invalid-style", "style must be an object");
|
|
1016
|
+
const unknown = Object.keys(style).find((key) => !textStyleKeys.has(key));
|
|
1017
|
+
if (unknown !== void 0) throw new CapabilityError("invalid-style", `Deck.style contains unsupported text property ${unknown}`);
|
|
1018
|
+
}
|
|
1019
|
+
const theme = normalizeTheme(input);
|
|
1020
|
+
const colorMap = options.colorMap ?? defaultColorMap;
|
|
1021
|
+
return createContext(theme, textStyleFrom(style, createContext(theme, {}, colorMap, options.themeOverride)), colorMap, options.themeOverride);
|
|
1022
|
+
}
|
|
1023
|
+
export { applyFormatColorTransforms, assertValidLang, backgroundValueSchema, bcp47LangSchema, borderObjectSchema, borderObjectShape, borderStyleSchema, borderValueSchema, boxShadowValueSchema, colorMapOverrideSchema, colorMapSchema, colorValueSchema, createThemeContext, darker, defaultColorMap, defaultTheme, defineTheme, externalImageFillSourceSchema, fontOptionsSchema, formatSchemeSchema, imageBackgroundFitSchema, imageBackgroundPositionKeywordSchema, imageBackgroundPositionSchema, imageBackgroundSchema, imageFillSourceSchema, isFont, isNativeColorSlot, isSchemeColorName, isSchemeColorSlot, isTheme, isThemeFontSlot, lighter, linearGradientSchema, nativeColorSlots, radialGradientSchema, schemeColorNameSchema, schemeColorNames, schemeColorSlots, shadowSchema, textStyleFrom, textStyleKeys, textStyleSchema, textStyleShape, themeDataSchema, themeFontSlotSchema, themeFontSlots, themeInputSchema, themeOverrideSchema, themeSchema, uint8ArraySchema, unsealedFontSchema, validateTextStyle, visualStyleShape };
|