@officedk/pptxdk 0.0.0-stage → 0.1.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/README.md +48 -2
- package/dist/build.d.ts +94 -0
- package/dist/build.js +148 -0
- package/dist/capabilities/dist/all.js +32 -0
- package/dist/capabilities/dist/box/box-codegen.js +51 -0
- package/dist/capabilities/dist/box/box-declaration.js +31 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +138 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +77 -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 +2272 -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 +1078 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1124 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +298 -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 +190 -0
- package/dist/capabilities/dist/chart/preview/layout.js +519 -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 +48 -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 +148 -0
- package/dist/capabilities/dist/font/font-embedding.js +289 -0
- package/dist/capabilities/dist/font/font-family.js +10 -0
- package/dist/capabilities/dist/font/font-import.js +302 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +25 -0
- package/dist/capabilities/dist/group/group-codegen.js +51 -0
- package/dist/capabilities/dist/group/group-declaration.js +42 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +319 -0
- package/dist/capabilities/dist/group/group-xml.js +7 -0
- package/dist/capabilities/dist/group/group.js +211 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +94 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +221 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +778 -0
- package/dist/capabilities/dist/image/image-schemas.js +149 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +472 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +685 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +21 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +527 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +340 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1033 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2189 -0
- package/dist/capabilities/dist/motion/motion-query.js +420 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +216 -0
- package/dist/capabilities/dist/motion/motion.js +1372 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +20 -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 +35 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +191 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +23 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +12 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +292 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +166 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +57 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +579 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +337 -0
- package/dist/capabilities/dist/shared/geometry.js +1423 -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 +113 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +21390 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +166 -0
- package/dist/capabilities/dist/shared/style-parse.js +11 -0
- package/dist/capabilities/dist/shared/text-schemas.js +216 -0
- package/dist/capabilities/dist/shared/text-service.js +1883 -0
- package/dist/capabilities/dist/shared/visual.js +918 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +161 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +21 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +221 -0
- package/dist/capabilities/dist/table/table-codegen.js +81 -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 +539 -0
- package/dist/capabilities/dist/table/table-schemas.js +279 -0
- package/dist/capabilities/dist/table/table-xml.js +37 -0
- package/dist/capabilities/dist/table/table.js +662 -0
- package/dist/capabilities/dist/text/text-codegen.js +129 -0
- package/dist/capabilities/dist/text/text-declaration.js +19 -0
- package/dist/capabilities/dist/text/text-elements.js +38 -0
- package/dist/capabilities/dist/text/text-import.js +1077 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +335 -0
- package/dist/capabilities/dist/transition/transition-api.js +139 -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-D_xeNVIw.d.ts +29496 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +78 -0
- package/dist/codegen/dist/codegen.js +611 -0
- package/dist/codegen/dist/identifiers.js +193 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +49 -0
- package/dist/core/dist/author-ids.js +48 -0
- package/dist/core/dist/author-schemas.js +313 -0
- package/dist/core/dist/block-flex-layout.js +749 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +13 -0
- package/dist/core/dist/declaration.js +15 -0
- package/dist/core/dist/diagnostics.js +21 -0
- package/dist/core/dist/document-internals.js +13 -0
- package/dist/core/dist/document.js +408 -0
- package/dist/core/dist/geometry-schemas.js +249 -0
- package/dist/core/dist/grid-layout.js +445 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +45 -0
- package/dist/core/dist/layout-protocol.js +66 -0
- package/dist/core/dist/layout-schemas.js +208 -0
- package/dist/core/dist/layout.js +299 -0
- package/dist/core/dist/masters.js +169 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +213 -0
- package/dist/core/dist/query.js +155 -0
- package/dist/core/dist/resolution.js +11 -0
- package/dist/core/dist/resolve.js +1827 -0
- package/dist/core/dist/stage-options.js +67 -0
- package/dist/core/dist/theme.js +931 -0
- package/dist/document-BHPUODPP.d.ts +27759 -0
- package/dist/emit/dist/emit.js +936 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +606 -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 +153 -0
- package/dist/import/dist/fonts.js +250 -0
- package/dist/import/dist/import.js +504 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1153 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +60 -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 +671 -0
- package/dist/import/dist/visual.js +761 -0
- package/dist/import/dist/xml-fragments.js +36 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-B5m3hqjC.d.ts +7 -0
- package/dist/index-CCy-Yo8G.d.ts +1208 -0
- package/dist/index-DpxcZ4Gs.d.ts +725 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +70 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +194 -0
- package/dist/pptxdk/src/cli-commands.js +913 -0
- package/dist/pptxdk/src/compose.js +44 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +240 -0
- package/dist/preview/dist/options.js +53 -0
- package/dist/preview-Cfw0QdMM.d.ts +86 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +27 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +65 -0
- package/dist/react/dist/elements.js +59 -0
- package/dist/react/dist/index.js +68 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +27 -0
- package/dist/transition-Cips9wma.d.ts +82 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +14 -0
- package/package.json +78 -3
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import { CapabilityError } from "./diagnostics.js";
|
|
2
|
+
import { snapshotValue } from "./input-values.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// ../core/dist/theme.js
|
|
5
|
+
const fontFaceStyleSchema = z.enum(["normal", "italic"]);
|
|
6
|
+
const fontWeightNumberSchema = z.int().min(100).max(900).refine((value) => value % 100 === 0, "fontWeight must be normal, bold, or a hundreds integer between 100 and 900");
|
|
7
|
+
const fontWeightSchema = z.union([
|
|
8
|
+
z.literal("normal"),
|
|
9
|
+
z.literal("bold"),
|
|
10
|
+
fontWeightNumberSchema
|
|
11
|
+
]);
|
|
12
|
+
const uint8ArraySchema = z.instanceof(Uint8Array);
|
|
13
|
+
/** Font files provided by the caller can be used for measurement or embedded according to build options. */
|
|
14
|
+
const fontFaceSchema = z.strictObject({
|
|
15
|
+
weight: fontWeightNumberSchema.optional(),
|
|
16
|
+
style: fontFaceStyleSchema.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
|
+
/** Font family and explicit measurement resources referenceable across deck themes and components. */
|
|
21
|
+
const fontSchema = z.strictObject({
|
|
22
|
+
family: nonEmptyTrimmedStringSchema,
|
|
23
|
+
faces: z.array(fontFaceSchema).readonly().optional(),
|
|
24
|
+
substitute: z.boolean().optional(),
|
|
25
|
+
embeddable: z.boolean().optional()
|
|
26
|
+
}).readonly();
|
|
27
|
+
const fontOptionsSchema = z.strictObject({
|
|
28
|
+
substitute: z.boolean().optional(),
|
|
29
|
+
embeddable: z.boolean().optional()
|
|
30
|
+
}).readonly();
|
|
31
|
+
const fontReferenceSchema = z.union([nonEmptyTrimmedStringSchema, fontSchema]);
|
|
32
|
+
const fontTokenSchema = fontReferenceSchema;
|
|
33
|
+
const textLengthPattern = /^(\d+(?:\.\d+)?)(px|pt)$/u;
|
|
34
|
+
const textLengthStringSchema = z.string().regex(textLengthPattern);
|
|
35
|
+
function textLengthToPixels(value) {
|
|
36
|
+
if (typeof value === "number") return value;
|
|
37
|
+
const match = textLengthPattern.exec(value);
|
|
38
|
+
if (match === null) return NaN;
|
|
39
|
+
const amount = Number(match[1]);
|
|
40
|
+
return match[2] === "pt" ? amount * 4 / 3 : amount;
|
|
41
|
+
}
|
|
42
|
+
function fontSizeToPoints(value) {
|
|
43
|
+
if (typeof value === "string" && value.endsWith("pt")) return Number(value.slice(0, -2));
|
|
44
|
+
return textLengthToPixels(value) * .75;
|
|
45
|
+
}
|
|
46
|
+
const fontSizeSchema = z.union([z.number().finite().positive(), textLengthStringSchema.refine((value) => textLengthToPixels(value) > 0, "Text length must be greater than 0")]);
|
|
47
|
+
const validatedFontSizeSchema = fontSizeSchema.refine((value) => {
|
|
48
|
+
const serialized = Math.round(fontSizeToPoints(value) * 100);
|
|
49
|
+
return serialized >= 100 && serialized <= 4e5;
|
|
50
|
+
}, "fontSize converted value must be within DrawingML range of 1 to 4000pt");
|
|
51
|
+
const validatedLineHeightSchema = fontSizeSchema.refine((value) => {
|
|
52
|
+
const centipoints = Math.round(textLengthToPixels(value) * 75);
|
|
53
|
+
return centipoints >= 0 && centipoints <= 158400;
|
|
54
|
+
}, "lineHeight converted value must be within DrawingML range of 0 to 1584pt");
|
|
55
|
+
const textAlignmentSchema = z.enum([
|
|
56
|
+
"left",
|
|
57
|
+
"center",
|
|
58
|
+
"right",
|
|
59
|
+
"justify"
|
|
60
|
+
]);
|
|
61
|
+
const nativeColorSlots = [
|
|
62
|
+
"dk1",
|
|
63
|
+
"lt1",
|
|
64
|
+
"dk2",
|
|
65
|
+
"lt2",
|
|
66
|
+
"accent1",
|
|
67
|
+
"accent2",
|
|
68
|
+
"accent3",
|
|
69
|
+
"accent4",
|
|
70
|
+
"accent5",
|
|
71
|
+
"accent6",
|
|
72
|
+
"hlink",
|
|
73
|
+
"folHlink"
|
|
74
|
+
];
|
|
75
|
+
const nativeColorSlotSchema = z.enum(nativeColorSlots);
|
|
76
|
+
const schemeColorSlots = [
|
|
77
|
+
"bg1",
|
|
78
|
+
"tx1",
|
|
79
|
+
"bg2",
|
|
80
|
+
"tx2",
|
|
81
|
+
"accent1",
|
|
82
|
+
"accent2",
|
|
83
|
+
"accent3",
|
|
84
|
+
"accent4",
|
|
85
|
+
"accent5",
|
|
86
|
+
"accent6",
|
|
87
|
+
"hlink",
|
|
88
|
+
"folHlink"
|
|
89
|
+
];
|
|
90
|
+
z.enum(schemeColorSlots);
|
|
91
|
+
const schemeColorNames = [
|
|
92
|
+
"dk1",
|
|
93
|
+
"lt1",
|
|
94
|
+
"dk2",
|
|
95
|
+
"lt2",
|
|
96
|
+
"bg1",
|
|
97
|
+
"tx1",
|
|
98
|
+
"bg2",
|
|
99
|
+
"tx2",
|
|
100
|
+
"accent1",
|
|
101
|
+
"accent2",
|
|
102
|
+
"accent3",
|
|
103
|
+
"accent4",
|
|
104
|
+
"accent5",
|
|
105
|
+
"accent6",
|
|
106
|
+
"hlink",
|
|
107
|
+
"folHlink"
|
|
108
|
+
];
|
|
109
|
+
const schemeColorNameSchema = z.enum(schemeColorNames);
|
|
110
|
+
/** Native `<p:clrMap>` / `<a:overrideClrMapping>` mapping the 12 scheme slots to 12 theme palette slots. */
|
|
111
|
+
const colorMapSchema = z.strictObject({
|
|
112
|
+
bg1: nativeColorSlotSchema,
|
|
113
|
+
tx1: nativeColorSlotSchema,
|
|
114
|
+
bg2: nativeColorSlotSchema,
|
|
115
|
+
tx2: nativeColorSlotSchema,
|
|
116
|
+
accent1: nativeColorSlotSchema,
|
|
117
|
+
accent2: nativeColorSlotSchema,
|
|
118
|
+
accent3: nativeColorSlotSchema,
|
|
119
|
+
accent4: nativeColorSlotSchema,
|
|
120
|
+
accent5: nativeColorSlotSchema,
|
|
121
|
+
accent6: nativeColorSlotSchema,
|
|
122
|
+
hlink: nativeColorSlotSchema,
|
|
123
|
+
folHlink: nativeColorSlotSchema
|
|
124
|
+
}).readonly();
|
|
125
|
+
const defaultColorMap = Object.freeze({
|
|
126
|
+
bg1: "lt1",
|
|
127
|
+
tx1: "dk1",
|
|
128
|
+
bg2: "lt2",
|
|
129
|
+
tx2: "dk2",
|
|
130
|
+
accent1: "accent1",
|
|
131
|
+
accent2: "accent2",
|
|
132
|
+
accent3: "accent3",
|
|
133
|
+
accent4: "accent4",
|
|
134
|
+
accent5: "accent5",
|
|
135
|
+
accent6: "accent6",
|
|
136
|
+
hlink: "hlink",
|
|
137
|
+
folHlink: "folHlink"
|
|
138
|
+
});
|
|
139
|
+
const colorMapOverrideSchema = z.union([z.literal("master"), colorMapSchema]);
|
|
140
|
+
/** Native theme color represented with DrawingML luminance modulation. */
|
|
141
|
+
const themeShadeSchema = z.strictObject({
|
|
142
|
+
slot: schemeColorNameSchema,
|
|
143
|
+
lumMod: z.number().finite().min(0).max(1),
|
|
144
|
+
lumOff: z.number().finite().min(0).max(1).optional()
|
|
145
|
+
}).readonly();
|
|
146
|
+
const themeColorSchema = z.union([z.string(), themeShadeSchema]);
|
|
147
|
+
/** Color entry can directly provide color, theme slot, or theme token, optionally with alpha. */
|
|
148
|
+
const colorValueSchema = z.union([
|
|
149
|
+
z.string(),
|
|
150
|
+
themeShadeSchema,
|
|
151
|
+
z.strictObject({
|
|
152
|
+
color: themeColorSchema,
|
|
153
|
+
alpha: z.number().finite().min(0).max(1).optional()
|
|
154
|
+
}).readonly()
|
|
155
|
+
]);
|
|
156
|
+
z.strictObject({
|
|
157
|
+
hex: z.string(),
|
|
158
|
+
alpha: z.number().finite().min(0).max(1).optional(),
|
|
159
|
+
slot: nativeColorSlotSchema.optional(),
|
|
160
|
+
scheme: schemeColorNameSchema.optional(),
|
|
161
|
+
lumMod: z.number().finite().min(0).max(1).optional(),
|
|
162
|
+
lumOff: z.number().finite().min(0).max(1).optional()
|
|
163
|
+
}).readonly();
|
|
164
|
+
const gradientStopSchema = z.strictObject({
|
|
165
|
+
color: colorValueSchema,
|
|
166
|
+
position: z.number().finite()
|
|
167
|
+
}).readonly();
|
|
168
|
+
const linearGradientSchema = z.strictObject({
|
|
169
|
+
type: z.literal("linear-gradient"),
|
|
170
|
+
angle: z.number().finite(),
|
|
171
|
+
stops: z.array(gradientStopSchema).readonly()
|
|
172
|
+
}).readonly();
|
|
173
|
+
const radialGradientSchema = z.strictObject({
|
|
174
|
+
type: z.literal("radial-gradient"),
|
|
175
|
+
stops: z.array(gradientStopSchema).readonly()
|
|
176
|
+
}).readonly();
|
|
177
|
+
const shadowSchema = z.strictObject({
|
|
178
|
+
color: colorValueSchema.optional(),
|
|
179
|
+
blur: z.number().finite().nonnegative().optional(),
|
|
180
|
+
distance: z.number().finite().nonnegative().optional(),
|
|
181
|
+
angle: z.number().finite().optional()
|
|
182
|
+
}).readonly();
|
|
183
|
+
/** Visual fields shared across native DrawingML shapes, images, text boxes, and visible Boxes. */
|
|
184
|
+
const visualStyleSchema = z.strictObject({
|
|
185
|
+
backgroundColor: colorValueSchema.optional(),
|
|
186
|
+
backgroundImage: z.union([
|
|
187
|
+
linearGradientSchema,
|
|
188
|
+
radialGradientSchema,
|
|
189
|
+
z.strictObject({ image: z.union([
|
|
190
|
+
z.string(),
|
|
191
|
+
z.instanceof(URL),
|
|
192
|
+
uint8ArraySchema
|
|
193
|
+
]) }).readonly()
|
|
194
|
+
]).optional(),
|
|
195
|
+
borderColor: colorValueSchema.optional(),
|
|
196
|
+
borderWidth: z.number().finite().optional(),
|
|
197
|
+
borderStyle: z.enum([
|
|
198
|
+
"solid",
|
|
199
|
+
"dashed",
|
|
200
|
+
"dotted"
|
|
201
|
+
]).optional(),
|
|
202
|
+
borderRadius: z.number().finite().optional(),
|
|
203
|
+
opacity: z.number().finite().optional(),
|
|
204
|
+
boxShadow: shadowSchema.optional(),
|
|
205
|
+
softEdge: z.number().finite().optional(),
|
|
206
|
+
rotate: z.number().finite().optional()
|
|
207
|
+
}).readonly();
|
|
208
|
+
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) => {
|
|
209
|
+
try {
|
|
210
|
+
const canonical = Intl.getCanonicalLocales(value);
|
|
211
|
+
return Boolean(canonical && canonical.length === 1);
|
|
212
|
+
} catch {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}, "Text language must be a valid BCP 47 language tag");
|
|
216
|
+
const textStyleObjectSchema = z.strictObject({
|
|
217
|
+
fontFamily: fontReferenceSchema.optional(),
|
|
218
|
+
fontSize: validatedFontSizeSchema.optional(),
|
|
219
|
+
fontWeight: fontWeightSchema.optional(),
|
|
220
|
+
fontStyle: fontFaceStyleSchema.optional(),
|
|
221
|
+
color: colorValueSchema.optional(),
|
|
222
|
+
lineHeight: validatedLineHeightSchema.optional(),
|
|
223
|
+
verticalAlign: z.enum([
|
|
224
|
+
"top",
|
|
225
|
+
"middle",
|
|
226
|
+
"bottom"
|
|
227
|
+
]).optional(),
|
|
228
|
+
/** Paragraph alignment when not explicitly overridden. */
|
|
229
|
+
align: textAlignmentSchema.optional(),
|
|
230
|
+
/** Paragraph space-after when not explicitly overridden, in pixels. */
|
|
231
|
+
spacingAfter: z.number().finite().nonnegative().refine((value) => {
|
|
232
|
+
const centipoints = Math.round(value * 75);
|
|
233
|
+
return centipoints >= 0 && centipoints <= 158400;
|
|
234
|
+
}, "spacingAfter converted value must be within DrawingML range of 0 to 1584pt").optional(),
|
|
235
|
+
/** Character spacing in pixels. */
|
|
236
|
+
letterSpacing: z.number().finite().refine((value) => {
|
|
237
|
+
const points = Math.round(value * 75);
|
|
238
|
+
return points >= -4e5 && points <= 4e5;
|
|
239
|
+
}, "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt").optional(),
|
|
240
|
+
textTransform: z.enum(["none", "uppercase"]).optional(),
|
|
241
|
+
textDecoration: z.enum([
|
|
242
|
+
"none",
|
|
243
|
+
"underline",
|
|
244
|
+
"line-through"
|
|
245
|
+
]).optional(),
|
|
246
|
+
textShadow: z.union([shadowSchema, z.literal("none")]).optional(),
|
|
247
|
+
/** Whether the text box wraps normally or keeps each line on a single line. */
|
|
248
|
+
textWrap: z.enum(["normal", "nowrap"]).optional(),
|
|
249
|
+
/** Natural language (BCP 47 language tag, e.g. zh-CN, en-US). */
|
|
250
|
+
lang: bcp47LangSchema.optional()
|
|
251
|
+
});
|
|
252
|
+
const textStyleShape = textStyleObjectSchema.shape;
|
|
253
|
+
/** Inheritable text style fields shared across text objects and containers. */
|
|
254
|
+
const textStyleSchema = textStyleObjectSchema.readonly();
|
|
255
|
+
const formatColorTransformSchema = z.strictObject({
|
|
256
|
+
color: z.union([
|
|
257
|
+
z.literal("phClr"),
|
|
258
|
+
schemeColorNameSchema,
|
|
259
|
+
z.string()
|
|
260
|
+
]),
|
|
261
|
+
alpha: z.number().finite().min(0).max(1).optional(),
|
|
262
|
+
lumMod: z.number().finite().min(0).max(1).optional(),
|
|
263
|
+
lumOff: z.number().finite().min(0).max(1).optional(),
|
|
264
|
+
tint: z.number().finite().min(0).max(1).optional(),
|
|
265
|
+
shade: z.number().finite().min(0).max(1).optional(),
|
|
266
|
+
satMod: z.number().finite().min(0).optional()
|
|
267
|
+
}).readonly();
|
|
268
|
+
const formatGradientStopSchema = z.strictObject({
|
|
269
|
+
position: z.number().finite().min(0).max(1),
|
|
270
|
+
color: formatColorTransformSchema
|
|
271
|
+
}).readonly();
|
|
272
|
+
const formatFillStyleSchema = z.union([
|
|
273
|
+
z.strictObject({ kind: z.literal("none") }).readonly(),
|
|
274
|
+
z.strictObject({
|
|
275
|
+
kind: z.literal("solid"),
|
|
276
|
+
color: formatColorTransformSchema
|
|
277
|
+
}).readonly(),
|
|
278
|
+
z.strictObject({
|
|
279
|
+
kind: z.literal("gradient"),
|
|
280
|
+
rotWithShape: z.boolean().optional(),
|
|
281
|
+
stops: z.array(formatGradientStopSchema).readonly(),
|
|
282
|
+
linear: z.strictObject({
|
|
283
|
+
angle: z.number().finite(),
|
|
284
|
+
scaled: z.boolean().optional()
|
|
285
|
+
}).readonly().optional(),
|
|
286
|
+
path: z.strictObject({
|
|
287
|
+
shape: z.enum([
|
|
288
|
+
"circle",
|
|
289
|
+
"rect",
|
|
290
|
+
"shape"
|
|
291
|
+
]),
|
|
292
|
+
fillToRect: z.strictObject({
|
|
293
|
+
l: z.number().finite(),
|
|
294
|
+
t: z.number().finite(),
|
|
295
|
+
r: z.number().finite(),
|
|
296
|
+
b: z.number().finite()
|
|
297
|
+
}).readonly().optional()
|
|
298
|
+
}).readonly().optional()
|
|
299
|
+
}).readonly()
|
|
300
|
+
]);
|
|
301
|
+
const formatLineStyleSchema = z.strictObject({
|
|
302
|
+
widthEmu: z.number().int().nonnegative().optional(),
|
|
303
|
+
cap: z.enum([
|
|
304
|
+
"rnd",
|
|
305
|
+
"sq",
|
|
306
|
+
"flat"
|
|
307
|
+
]).optional(),
|
|
308
|
+
compound: z.enum([
|
|
309
|
+
"sng",
|
|
310
|
+
"dbl",
|
|
311
|
+
"thickThin",
|
|
312
|
+
"thinThick",
|
|
313
|
+
"tri"
|
|
314
|
+
]).optional(),
|
|
315
|
+
align: z.enum(["ctr", "in"]).optional(),
|
|
316
|
+
dash: z.string().optional(),
|
|
317
|
+
fill: formatFillStyleSchema.optional()
|
|
318
|
+
}).readonly();
|
|
319
|
+
const formatEffectStyleSchema = z.strictObject({ shadow: shadowSchema.optional() }).readonly();
|
|
320
|
+
/** DrawingML `<a:fmtScheme>` style matrix stored on a native theme or theme override. */
|
|
321
|
+
const formatSchemeSchema = z.strictObject({
|
|
322
|
+
name: z.string().optional(),
|
|
323
|
+
fillStyles: z.array(formatFillStyleSchema).readonly().optional(),
|
|
324
|
+
lineStyles: z.array(formatLineStyleSchema).readonly().optional(),
|
|
325
|
+
effectStyles: z.array(formatEffectStyleSchema).readonly().optional(),
|
|
326
|
+
bgFillStyles: z.array(formatFillStyleSchema).readonly().optional()
|
|
327
|
+
}).readonly();
|
|
328
|
+
/** Deck-level or master-level theme input; major/minor fonts are written to native PPTX theme. */
|
|
329
|
+
const themeInputSchema = z.strictObject({
|
|
330
|
+
name: z.string().optional(),
|
|
331
|
+
colors: z.object({
|
|
332
|
+
dk1: z.string().optional(),
|
|
333
|
+
lt1: z.string().optional(),
|
|
334
|
+
dk2: z.string().optional(),
|
|
335
|
+
lt2: z.string().optional(),
|
|
336
|
+
accent1: z.string().optional(),
|
|
337
|
+
accent2: z.string().optional(),
|
|
338
|
+
accent3: z.string().optional(),
|
|
339
|
+
accent4: z.string().optional(),
|
|
340
|
+
accent5: z.string().optional(),
|
|
341
|
+
accent6: z.string().optional(),
|
|
342
|
+
hlink: z.string().optional(),
|
|
343
|
+
folHlink: z.string().optional()
|
|
344
|
+
}).catchall(themeColorSchema).readonly().optional(),
|
|
345
|
+
fonts: z.object({
|
|
346
|
+
major: fontTokenSchema.optional(),
|
|
347
|
+
minor: fontTokenSchema.optional()
|
|
348
|
+
}).catchall(fontTokenSchema).readonly().optional(),
|
|
349
|
+
formatScheme: formatSchemeSchema.optional()
|
|
350
|
+
}).readonly();
|
|
351
|
+
/** Native `<a:themeOverride>` partial override for a SlideLayout or Slide. */
|
|
352
|
+
const themeOverrideSchema = z.strictObject({
|
|
353
|
+
colors: z.strictObject({
|
|
354
|
+
dk1: z.string().optional(),
|
|
355
|
+
lt1: z.string().optional(),
|
|
356
|
+
dk2: z.string().optional(),
|
|
357
|
+
lt2: z.string().optional(),
|
|
358
|
+
accent1: z.string().optional(),
|
|
359
|
+
accent2: z.string().optional(),
|
|
360
|
+
accent3: z.string().optional(),
|
|
361
|
+
accent4: z.string().optional(),
|
|
362
|
+
accent5: z.string().optional(),
|
|
363
|
+
accent6: z.string().optional(),
|
|
364
|
+
hlink: z.string().optional(),
|
|
365
|
+
folHlink: z.string().optional()
|
|
366
|
+
}).readonly().optional(),
|
|
367
|
+
fonts: z.strictObject({
|
|
368
|
+
major: fontTokenSchema.optional(),
|
|
369
|
+
minor: fontTokenSchema.optional()
|
|
370
|
+
}).readonly().optional(),
|
|
371
|
+
formatScheme: formatSchemeSchema.optional()
|
|
372
|
+
}).readonly();
|
|
373
|
+
const themeDataSchema = z.strictObject({
|
|
374
|
+
name: z.string(),
|
|
375
|
+
colors: z.object({
|
|
376
|
+
dk1: z.string(),
|
|
377
|
+
lt1: z.string(),
|
|
378
|
+
dk2: z.string(),
|
|
379
|
+
lt2: z.string(),
|
|
380
|
+
accent1: z.string(),
|
|
381
|
+
accent2: z.string(),
|
|
382
|
+
accent3: z.string(),
|
|
383
|
+
accent4: z.string(),
|
|
384
|
+
accent5: z.string(),
|
|
385
|
+
accent6: z.string(),
|
|
386
|
+
hlink: z.string(),
|
|
387
|
+
folHlink: z.string()
|
|
388
|
+
}).catchall(themeColorSchema).readonly(),
|
|
389
|
+
fonts: z.object({
|
|
390
|
+
major: fontTokenSchema,
|
|
391
|
+
minor: fontTokenSchema
|
|
392
|
+
}).catchall(fontTokenSchema).readonly(),
|
|
393
|
+
formatScheme: formatSchemeSchema.optional()
|
|
394
|
+
}).readonly();
|
|
395
|
+
const themeSchema = themeDataSchema.transform((data) => defineTheme(data));
|
|
396
|
+
/** Local theme scopes on slides or containers can only override color and font tokens already present in the deck. */
|
|
397
|
+
const themeScopeSchema = z.strictObject({
|
|
398
|
+
colors: z.record(z.string(), themeColorSchema).readonly().optional(),
|
|
399
|
+
fonts: z.record(z.string(), fontTokenSchema).readonly().optional()
|
|
400
|
+
}).readonly();
|
|
401
|
+
z.strictObject({
|
|
402
|
+
family: z.string(),
|
|
403
|
+
font: fontSchema.optional(),
|
|
404
|
+
themeFont: z.enum(["major", "minor"]).optional()
|
|
405
|
+
}).readonly();
|
|
406
|
+
const officeColors = {
|
|
407
|
+
dk1: "#000000",
|
|
408
|
+
lt1: "#FFFFFF",
|
|
409
|
+
dk2: "#1F497D",
|
|
410
|
+
lt2: "#EEECE1",
|
|
411
|
+
accent1: "#4F81BD",
|
|
412
|
+
accent2: "#C0504D",
|
|
413
|
+
accent3: "#9BBB59",
|
|
414
|
+
accent4: "#8064A2",
|
|
415
|
+
accent5: "#4BACC6",
|
|
416
|
+
accent6: "#F79646",
|
|
417
|
+
hlink: "#0000FF",
|
|
418
|
+
folHlink: "#800080"
|
|
419
|
+
};
|
|
420
|
+
const contextRecords = /* @__PURE__ */ new WeakMap();
|
|
421
|
+
const textStyleKeys = new Set(Object.keys(textStyleObjectSchema.shape));
|
|
422
|
+
function textStyleErrorForIssue(issue, rawStyle) {
|
|
423
|
+
const field = issue?.path[0];
|
|
424
|
+
if (field === "fontFamily") {
|
|
425
|
+
if (issue?.path[1] === "faces") return new CapabilityError("invalid-font-face", "Font.faces contains invalid weight, style, or resource");
|
|
426
|
+
return new CapabilityError("invalid-font-family", issue?.message ?? "fontFamily must be a font value or non-empty family string");
|
|
427
|
+
}
|
|
428
|
+
if (field === "fontSize") {
|
|
429
|
+
const raw = rawStyle["fontSize"];
|
|
430
|
+
const validLengthSyntax = typeof raw === "number" || typeof raw === "string" && textLengthPattern.test(raw);
|
|
431
|
+
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");
|
|
432
|
+
}
|
|
433
|
+
if (field === "fontWeight") return new CapabilityError("invalid-font-weight", "fontWeight must be normal, bold, or a hundreds integer between 100 and 900");
|
|
434
|
+
if (field === "fontStyle") return new CapabilityError("invalid-font-style", "fontStyle must be normal or italic");
|
|
435
|
+
if (field === "color") return new CapabilityError("invalid-color", "Invalid color value format");
|
|
436
|
+
if (field === "lineHeight") return new CapabilityError("invalid-text-length", "lineHeight must be a positive pixel value or px/pt length within 0 to 1584pt");
|
|
437
|
+
if (field === "verticalAlign") return new CapabilityError("invalid-vertical-align", "verticalAlign must be top, middle, or bottom");
|
|
438
|
+
if (field === "align") return new CapabilityError("invalid-text-alignment", "align must be left, center, right, or justify");
|
|
439
|
+
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");
|
|
440
|
+
if (field === "letterSpacing") return new CapabilityError("invalid-letter-spacing", "letterSpacing converted value must be within DrawingML range of -4000 to 4000pt");
|
|
441
|
+
if (field === "textTransform") return new CapabilityError("invalid-text-transform", "textTransform must be none or uppercase");
|
|
442
|
+
if (field === "textDecoration") return new CapabilityError("invalid-text-decoration", "textDecoration must be none, underline, or line-through");
|
|
443
|
+
if (field === "textWrap") return new CapabilityError("invalid-text-wrap", "textWrap must be normal or nowrap");
|
|
444
|
+
if (field === "textShadow") return new CapabilityError("invalid-shadow", issue?.message ?? "textShadow must be a shadow object or 'none'");
|
|
445
|
+
if (field === "lang") return new CapabilityError("invalid-text-lang", `Text language must be a valid BCP 47 language tag: ${String(rawStyle["lang"])}`);
|
|
446
|
+
return new CapabilityError("invalid-style", issue?.message ?? "Invalid text style");
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Validates inheritable text style fields shared across text objects and containers.
|
|
450
|
+
*/
|
|
451
|
+
function validateTextStyle(style, theme) {
|
|
452
|
+
const candidate = {};
|
|
453
|
+
for (const [key, item] of Object.entries(style)) if (textStyleKeys.has(key) && item !== void 0) candidate[key] = item;
|
|
454
|
+
const parsed = textStyleObjectSchema.safeParse(candidate);
|
|
455
|
+
if (!parsed.success) throw textStyleErrorForIssue(parsed.error.issues[0], candidate);
|
|
456
|
+
const validated = parsed.data;
|
|
457
|
+
if (theme !== void 0) {
|
|
458
|
+
if (typeof validated.fontFamily === "string") theme.resolveFont(validated.fontFamily);
|
|
459
|
+
if (validated.color !== void 0) theme.resolveColor(validated.color);
|
|
460
|
+
if (validated.textShadow !== void 0 && validated.textShadow !== "none" && validated.textShadow.color !== void 0) theme.resolveColor(validated.textShadow.color);
|
|
461
|
+
}
|
|
462
|
+
return style;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Asserts that a value is a valid BCP 47 language tag.
|
|
466
|
+
* Rejects non-string values, empty or whitespace strings, and malformed tags.
|
|
467
|
+
*/
|
|
468
|
+
function assertValidLang(value) {
|
|
469
|
+
const parsed = bcp47LangSchema.safeParse(value);
|
|
470
|
+
if (!parsed.success) throw new CapabilityError("invalid-text-lang", `Text language must be a valid BCP 47 language tag: ${String(value)}`);
|
|
471
|
+
return parsed.data;
|
|
472
|
+
}
|
|
473
|
+
function record(value) {
|
|
474
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
475
|
+
}
|
|
476
|
+
/** Extract inheritable text fields from container style containing layout fields. */
|
|
477
|
+
function textStyleFrom(value, theme) {
|
|
478
|
+
if (value === void 0) return {};
|
|
479
|
+
if (!record(value)) throw new CapabilityError("invalid-style", "style must be an object");
|
|
480
|
+
const extracted = {};
|
|
481
|
+
for (const [key, item] of Object.entries(value)) if (textStyleKeys.has(key) && item !== void 0) extracted[key] = item;
|
|
482
|
+
return validateTextStyle(extracted, theme);
|
|
483
|
+
}
|
|
484
|
+
function nativeSlot(value) {
|
|
485
|
+
return nativeColorSlots.includes(value);
|
|
486
|
+
}
|
|
487
|
+
function schemeSlot(value) {
|
|
488
|
+
return schemeColorSlots.includes(value);
|
|
489
|
+
}
|
|
490
|
+
function schemeColorName(value) {
|
|
491
|
+
return schemeColorNames.includes(value);
|
|
492
|
+
}
|
|
493
|
+
function isSchemeColorSlot(value) {
|
|
494
|
+
return schemeSlot(value);
|
|
495
|
+
}
|
|
496
|
+
function isSchemeColorName(value) {
|
|
497
|
+
return schemeColorName(value);
|
|
498
|
+
}
|
|
499
|
+
function isFont(value) {
|
|
500
|
+
return record(value) && typeof value["family"] === "string";
|
|
501
|
+
}
|
|
502
|
+
const themeBrandSymbol = Symbol.for("@pptxdk/core/theme");
|
|
503
|
+
/** Checks whether a runtime value is an identity-bearing `Theme` instance produced by `defineTheme`. */
|
|
504
|
+
function isTheme(value) {
|
|
505
|
+
return typeof value === "object" && value !== null && themeBrandSymbol in value;
|
|
506
|
+
}
|
|
507
|
+
var NativeThemeRecord = class {
|
|
508
|
+
[themeBrandSymbol] = true;
|
|
509
|
+
#name;
|
|
510
|
+
#colors;
|
|
511
|
+
#fonts;
|
|
512
|
+
#formatScheme;
|
|
513
|
+
constructor(initial) {
|
|
514
|
+
this.#name = initial.name;
|
|
515
|
+
this.#colors = initial.colors;
|
|
516
|
+
this.#fonts = initial.fonts;
|
|
517
|
+
this.#formatScheme = initial.formatScheme;
|
|
518
|
+
Object.defineProperties(this, {
|
|
519
|
+
name: {
|
|
520
|
+
enumerable: true,
|
|
521
|
+
configurable: false,
|
|
522
|
+
get: () => this.#name
|
|
523
|
+
},
|
|
524
|
+
colors: {
|
|
525
|
+
enumerable: true,
|
|
526
|
+
configurable: false,
|
|
527
|
+
get: () => this.#colors
|
|
528
|
+
},
|
|
529
|
+
fonts: {
|
|
530
|
+
enumerable: true,
|
|
531
|
+
configurable: false,
|
|
532
|
+
get: () => this.#fonts
|
|
533
|
+
},
|
|
534
|
+
...initial.formatScheme === void 0 ? {} : { formatScheme: {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
configurable: false,
|
|
537
|
+
get: () => this.#formatScheme
|
|
538
|
+
} }
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
get name() {
|
|
542
|
+
return this.#name;
|
|
543
|
+
}
|
|
544
|
+
get colors() {
|
|
545
|
+
return this.#colors;
|
|
546
|
+
}
|
|
547
|
+
get fonts() {
|
|
548
|
+
return this.#fonts;
|
|
549
|
+
}
|
|
550
|
+
get formatScheme() {
|
|
551
|
+
return this.#formatScheme;
|
|
552
|
+
}
|
|
553
|
+
set(patch) {
|
|
554
|
+
if (this === defaultTheme) throw new TypeError("Cannot mutate defaultTheme");
|
|
555
|
+
if (!record(patch)) throw new TypeError("Theme update must be an object");
|
|
556
|
+
const parsed = themeInputSchema.safeParse(patch);
|
|
557
|
+
if (!parsed.success) {
|
|
558
|
+
const issue = parsed.error.issues[0];
|
|
559
|
+
throw new CapabilityError("invalid-theme", issue?.message ?? "Invalid theme declaration");
|
|
560
|
+
}
|
|
561
|
+
const validPatch = parsed.data;
|
|
562
|
+
if (validPatch.name !== void 0) this.#name = validPatch.name;
|
|
563
|
+
if (validPatch.colors !== void 0) this.#colors = snapshotValue({
|
|
564
|
+
...this.#colors,
|
|
565
|
+
...validPatch.colors
|
|
566
|
+
});
|
|
567
|
+
if (validPatch.fonts !== void 0) this.#fonts = snapshotValue({
|
|
568
|
+
...this.#fonts,
|
|
569
|
+
...validPatch.fonts
|
|
570
|
+
});
|
|
571
|
+
if (validPatch.formatScheme !== void 0) {
|
|
572
|
+
const hadFormatScheme = Object.hasOwn(this, "formatScheme");
|
|
573
|
+
this.#formatScheme = snapshotValue(validPatch.formatScheme);
|
|
574
|
+
if (!hadFormatScheme) Object.defineProperty(this, "formatScheme", {
|
|
575
|
+
enumerable: true,
|
|
576
|
+
configurable: false,
|
|
577
|
+
get: () => this.#formatScheme
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
function parseThemeInputData(input = {}) {
|
|
584
|
+
if (!record(input)) throw new TypeError("Theme must be an object");
|
|
585
|
+
const parsed = themeInputSchema.safeParse(input);
|
|
586
|
+
if (!parsed.success) {
|
|
587
|
+
const issue = parsed.error.issues[0];
|
|
588
|
+
throw new CapabilityError("invalid-theme", issue?.message ?? "Invalid theme declaration");
|
|
589
|
+
}
|
|
590
|
+
const validInput = parsed.data;
|
|
591
|
+
const colors = snapshotValue({
|
|
592
|
+
...officeColors,
|
|
593
|
+
...validInput.colors
|
|
594
|
+
});
|
|
595
|
+
const fonts = snapshotValue({
|
|
596
|
+
...validInput.fonts,
|
|
597
|
+
major: validInput.fonts?.major ?? "Aptos Display",
|
|
598
|
+
minor: validInput.fonts?.minor ?? "Aptos"
|
|
599
|
+
});
|
|
600
|
+
const formatScheme = validInput.formatScheme === void 0 ? void 0 : snapshotValue(validInput.formatScheme);
|
|
601
|
+
return {
|
|
602
|
+
name: validInput.name ?? "Office Theme",
|
|
603
|
+
colors,
|
|
604
|
+
fonts,
|
|
605
|
+
...formatScheme === void 0 ? {} : { formatScheme }
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function normalizeTheme(input) {
|
|
609
|
+
if (input === void 0) return defaultTheme;
|
|
610
|
+
if (isTheme(input)) return input;
|
|
611
|
+
return new NativeThemeRecord(parseThemeInputData(input));
|
|
612
|
+
}
|
|
613
|
+
/** Fill unsupplied theme items using initial Office palette and fonts, returning an identity-bearing `Theme`. */
|
|
614
|
+
function defineTheme(input = {}) {
|
|
615
|
+
return new NativeThemeRecord(parseThemeInputData(input));
|
|
616
|
+
}
|
|
617
|
+
const defaultTheme = defineTheme();
|
|
618
|
+
/** Generate darker variant in PowerPoint native palette. */
|
|
619
|
+
function darker(slot, amount) {
|
|
620
|
+
return {
|
|
621
|
+
slot,
|
|
622
|
+
lumMod: 1 - amount
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
/** Generate lighter variant in PowerPoint native palette. */
|
|
626
|
+
function lighter(slot, amount) {
|
|
627
|
+
return {
|
|
628
|
+
slot,
|
|
629
|
+
lumMod: 1 - amount,
|
|
630
|
+
lumOff: amount
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function isNativeColorSlot(value) {
|
|
634
|
+
return nativeSlot(value);
|
|
635
|
+
}
|
|
636
|
+
function scopeValue(context, name) {
|
|
637
|
+
let current = context;
|
|
638
|
+
while (current !== void 0) {
|
|
639
|
+
const scope = contextRecords.get(current)?.scope;
|
|
640
|
+
if (scope?.colors !== void 0 && Object.hasOwn(scope.colors, name)) return {
|
|
641
|
+
value: scope.colors[name],
|
|
642
|
+
...contextRecords.get(current)?.parent === void 0 ? {} : { parent: contextRecords.get(current).parent }
|
|
643
|
+
};
|
|
644
|
+
current = contextRecords.get(current)?.parent;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function scopeFontValue(context, name) {
|
|
648
|
+
let current = context;
|
|
649
|
+
while (current !== void 0) {
|
|
650
|
+
const scope = contextRecords.get(current)?.scope;
|
|
651
|
+
if (scope?.fonts !== void 0 && Object.hasOwn(scope.fonts, name)) return {
|
|
652
|
+
value: scope.fonts[name],
|
|
653
|
+
...contextRecords.get(current)?.parent === void 0 ? {} : { parent: contextRecords.get(current).parent }
|
|
654
|
+
};
|
|
655
|
+
current = contextRecords.get(current)?.parent;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function rgbChannelsFromHex(hex) {
|
|
659
|
+
return [
|
|
660
|
+
0,
|
|
661
|
+
2,
|
|
662
|
+
4
|
|
663
|
+
].map((start) => Number.parseInt(hex.slice(start, start + 2), 16) / 255);
|
|
664
|
+
}
|
|
665
|
+
function hexFromRgbChannels(r, g, b) {
|
|
666
|
+
return [
|
|
667
|
+
r,
|
|
668
|
+
g,
|
|
669
|
+
b
|
|
670
|
+
].map((channel) => Math.round(Math.min(1, Math.max(0, channel)) * 255).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
671
|
+
}
|
|
672
|
+
function rgbToHsl(r, g, b) {
|
|
673
|
+
const max = Math.max(r, g, b);
|
|
674
|
+
const min = Math.min(r, g, b);
|
|
675
|
+
const lightness = (max + min) / 2;
|
|
676
|
+
const delta = max - min;
|
|
677
|
+
const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
|
|
678
|
+
return [
|
|
679
|
+
delta === 0 ? 0 : max === r ? ((g - b) / delta + 6) % 6 : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4,
|
|
680
|
+
saturation,
|
|
681
|
+
lightness
|
|
682
|
+
];
|
|
683
|
+
}
|
|
684
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
685
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
686
|
+
const x = chroma * (1 - Math.abs(hue % 2 - 1));
|
|
687
|
+
const m = lightness - chroma / 2;
|
|
688
|
+
const [r1, g1, b1] = hue < 1 ? [
|
|
689
|
+
chroma,
|
|
690
|
+
x,
|
|
691
|
+
0
|
|
692
|
+
] : hue < 2 ? [
|
|
693
|
+
x,
|
|
694
|
+
chroma,
|
|
695
|
+
0
|
|
696
|
+
] : hue < 3 ? [
|
|
697
|
+
0,
|
|
698
|
+
chroma,
|
|
699
|
+
x
|
|
700
|
+
] : hue < 4 ? [
|
|
701
|
+
0,
|
|
702
|
+
x,
|
|
703
|
+
chroma
|
|
704
|
+
] : hue < 5 ? [
|
|
705
|
+
x,
|
|
706
|
+
0,
|
|
707
|
+
chroma
|
|
708
|
+
] : [
|
|
709
|
+
chroma,
|
|
710
|
+
0,
|
|
711
|
+
x
|
|
712
|
+
];
|
|
713
|
+
return [
|
|
714
|
+
r1 + m,
|
|
715
|
+
g1 + m,
|
|
716
|
+
b1 + m
|
|
717
|
+
];
|
|
718
|
+
}
|
|
719
|
+
function shadeHex(hex, lumMod, lumOff) {
|
|
720
|
+
const [r, g, b] = rgbChannelsFromHex(hex);
|
|
721
|
+
const [hue, saturation, lightness] = rgbToHsl(r, g, b);
|
|
722
|
+
const [r1, g1, b1] = hslToRgb(hue, saturation, Math.min(1, Math.max(0, lightness * lumMod + lumOff)));
|
|
723
|
+
return hexFromRgbChannels(r1, g1, b1);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Applies DrawingML color modifiers (`tint`, `shade`, `satMod`, `lumMod`, `lumOff`, `alpha`)
|
|
727
|
+
* onto a resolved base color (used by theme format schemes and `<p:bgRef>` evaluation).
|
|
728
|
+
*/
|
|
729
|
+
function applyFormatColorTransforms(base, transform) {
|
|
730
|
+
let [r, g, b] = rgbChannelsFromHex(base.hex);
|
|
731
|
+
if (transform.tint !== void 0) {
|
|
732
|
+
const t = transform.tint;
|
|
733
|
+
r = r * t + (1 - t);
|
|
734
|
+
g = g * t + (1 - t);
|
|
735
|
+
b = b * t + (1 - t);
|
|
736
|
+
}
|
|
737
|
+
if (transform.shade !== void 0) {
|
|
738
|
+
const s = transform.shade;
|
|
739
|
+
r *= s;
|
|
740
|
+
g *= s;
|
|
741
|
+
b *= s;
|
|
742
|
+
}
|
|
743
|
+
if (transform.satMod !== void 0 || transform.lumMod !== void 0 || transform.lumOff !== void 0) {
|
|
744
|
+
const [hue, sat, lum] = rgbToHsl(r, g, b);
|
|
745
|
+
const nextSat = Math.min(1, Math.max(0, sat * (transform.satMod ?? 1)));
|
|
746
|
+
const nextLum = Math.min(1, Math.max(0, lum * (transform.lumMod ?? 1) + (transform.lumOff ?? 0)));
|
|
747
|
+
[r, g, b] = hslToRgb(hue, nextSat, nextLum);
|
|
748
|
+
}
|
|
749
|
+
const alpha = transform.alpha === void 0 ? base.alpha : (base.alpha ?? 1) * transform.alpha;
|
|
750
|
+
return {
|
|
751
|
+
hex: hexFromRgbChannels(r, g, b),
|
|
752
|
+
...alpha === void 0 || alpha === 1 ? {} : { alpha },
|
|
753
|
+
...base.slot === void 0 ? {} : { slot: base.slot },
|
|
754
|
+
...base.scheme === void 0 ? {} : { scheme: base.scheme }
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
function checkedFraction(value, label) {
|
|
758
|
+
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`);
|
|
759
|
+
return value;
|
|
760
|
+
}
|
|
761
|
+
function effectiveThemeColor(context, slot) {
|
|
762
|
+
return contextRecords.get(context)?.themeOverride?.colors?.[slot] ?? context.theme.colors[slot];
|
|
763
|
+
}
|
|
764
|
+
function resolveColorName(raw, context, depth) {
|
|
765
|
+
if (depth > 16) throw new CapabilityError("invalid-color", `Circular color token reference: ${raw}`);
|
|
766
|
+
const value = raw.trim();
|
|
767
|
+
if (value.startsWith("#")) {
|
|
768
|
+
const digits = value.slice(1);
|
|
769
|
+
const expanded = digits.length === 3 || digits.length === 4 ? digits.split("").map((digit) => digit + digit).join("") : digits;
|
|
770
|
+
if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/iu.test(expanded)) throw new CapabilityError("invalid-color", `Invalid color value: ${raw}`);
|
|
771
|
+
const alpha = expanded.length === 8 ? Number.parseInt(expanded.slice(6), 16) / 255 : void 0;
|
|
772
|
+
return {
|
|
773
|
+
hex: expanded.slice(0, 6).toUpperCase(),
|
|
774
|
+
...alpha === void 0 || alpha === 1 ? {} : { alpha }
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
if (schemeSlot(value)) {
|
|
778
|
+
const mappedSlot = context.colorMap[value];
|
|
779
|
+
return {
|
|
780
|
+
...resolveColorName(effectiveThemeColor(context, mappedSlot), rootContext(context), depth + 1),
|
|
781
|
+
slot: mappedSlot,
|
|
782
|
+
scheme: value
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
if (nativeSlot(value)) return {
|
|
786
|
+
...resolveColorName(effectiveThemeColor(context, value), rootContext(context), depth + 1),
|
|
787
|
+
slot: value,
|
|
788
|
+
scheme: value
|
|
789
|
+
};
|
|
790
|
+
const local = scopeValue(context, value);
|
|
791
|
+
if (local !== void 0) return resolveColorValue(local.value, local.parent ?? rootContext(context), depth + 1);
|
|
792
|
+
const configured = context.theme.colors[value];
|
|
793
|
+
if (configured === void 0) throw new CapabilityError("invalid-color", `Unknown color or theme token: ${raw}`);
|
|
794
|
+
return resolveColorValue(configured, context, depth + 1);
|
|
795
|
+
}
|
|
796
|
+
function rootContext(context) {
|
|
797
|
+
let current = context;
|
|
798
|
+
while (contextRecords.get(current)?.parent !== void 0) current = contextRecords.get(current).parent;
|
|
799
|
+
return current;
|
|
800
|
+
}
|
|
801
|
+
function resolveColorValue(value, context, depth) {
|
|
802
|
+
if (typeof value === "string") return resolveColorName(value, context, depth);
|
|
803
|
+
if (!record(value) || !schemeColorName(String(value["slot"])) || typeof value["lumMod"] !== "number" || !Number.isFinite(value["lumMod"])) throw new CapabilityError("invalid-color", "Invalid theme shade value");
|
|
804
|
+
const lumMod = checkedFraction(value["lumMod"], "lumMod");
|
|
805
|
+
const lumOff = value["lumOff"] === void 0 ? void 0 : checkedFraction(value["lumOff"], "lumOff");
|
|
806
|
+
const scheme = value["slot"];
|
|
807
|
+
const base = resolveColorName(scheme, context, depth + 1);
|
|
808
|
+
return {
|
|
809
|
+
hex: shadeHex(base.hex, lumMod, lumOff ?? 0),
|
|
810
|
+
...base.slot === void 0 ? {} : { slot: base.slot },
|
|
811
|
+
scheme,
|
|
812
|
+
lumMod,
|
|
813
|
+
...lumOff === void 0 ? {} : { lumOff }
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function mergeThemeOverrides(base, next) {
|
|
817
|
+
if (base === void 0) return next;
|
|
818
|
+
if (next === void 0) return base;
|
|
819
|
+
const colors = base.colors === void 0 && next.colors === void 0 ? void 0 : {
|
|
820
|
+
...base.colors,
|
|
821
|
+
...next.colors
|
|
822
|
+
};
|
|
823
|
+
const fonts = base.fonts === void 0 && next.fonts === void 0 ? void 0 : {
|
|
824
|
+
...base.fonts,
|
|
825
|
+
...next.fonts
|
|
826
|
+
};
|
|
827
|
+
const formatScheme = next.formatScheme ?? base.formatScheme;
|
|
828
|
+
return Object.freeze({
|
|
829
|
+
...colors === void 0 ? {} : { colors: Object.freeze(colors) },
|
|
830
|
+
...fonts === void 0 ? {} : { fonts: Object.freeze(fonts) },
|
|
831
|
+
...formatScheme === void 0 ? {} : { formatScheme }
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
function createContext(theme, parent, scope, textStyle, colorMap = defaultColorMap, themeOverride) {
|
|
835
|
+
const formatScheme = themeOverride?.formatScheme ?? theme.formatScheme;
|
|
836
|
+
let context;
|
|
837
|
+
context = Object.freeze({
|
|
838
|
+
theme,
|
|
839
|
+
colorMap,
|
|
840
|
+
formatScheme,
|
|
841
|
+
textStyle: Object.freeze(textStyle),
|
|
842
|
+
with(nextScope, style) {
|
|
843
|
+
let checkedScope;
|
|
844
|
+
if (nextScope !== void 0) {
|
|
845
|
+
const parsedScope = themeScopeSchema.safeParse(nextScope);
|
|
846
|
+
if (!parsedScope.success) throw new CapabilityError("invalid-theme-scope", parsedScope.error.issues[0]?.message ?? "Local theme scope is invalid");
|
|
847
|
+
const colors = parsedScope.data.colors;
|
|
848
|
+
for (const name of Object.keys(colors ?? {})) {
|
|
849
|
+
if (schemeColorName(name)) throw new CapabilityError("invalid-theme-scope", `Local theme scope cannot redefine native color slot ${name}`);
|
|
850
|
+
if (!Object.hasOwn(theme.colors, name)) throw new CapabilityError("invalid-theme-scope", `Theme has no color token ${name}`);
|
|
851
|
+
}
|
|
852
|
+
const fonts = parsedScope.data.fonts;
|
|
853
|
+
for (const name of Object.keys(fonts ?? {})) if (!Object.hasOwn(theme.fonts, name)) throw new CapabilityError("invalid-theme-scope", `Theme has no font token ${name}`);
|
|
854
|
+
checkedScope = Object.freeze({
|
|
855
|
+
...colors === void 0 ? {} : { colors: Object.freeze({ ...colors }) },
|
|
856
|
+
...fonts === void 0 ? {} : { fonts: Object.freeze({ ...fonts }) }
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
const candidateContext = createContext(theme, context, checkedScope, context.textStyle, colorMap, themeOverride);
|
|
860
|
+
const validated = style === void 0 ? {} : textStyleFrom(style, candidateContext);
|
|
861
|
+
const nextStyle = {
|
|
862
|
+
...context.textStyle,
|
|
863
|
+
...validated
|
|
864
|
+
};
|
|
865
|
+
return createContext(theme, context, checkedScope, nextStyle, colorMap, themeOverride);
|
|
866
|
+
},
|
|
867
|
+
withTextStyle(style) {
|
|
868
|
+
return createContext(theme, context, void 0, textStyleFrom(style, context), colorMap, themeOverride);
|
|
869
|
+
},
|
|
870
|
+
withNativeOverrides(nextThemeOverride, nextColorMapOverride) {
|
|
871
|
+
const mergedOverride = mergeThemeOverrides(themeOverride, nextThemeOverride);
|
|
872
|
+
const nextColorMap = nextColorMapOverride === void 0 || nextColorMapOverride === "master" ? colorMap : nextColorMapOverride;
|
|
873
|
+
return createContext(theme, context, void 0, context.textStyle, nextColorMap, mergedOverride);
|
|
874
|
+
},
|
|
875
|
+
resolveColor(value) {
|
|
876
|
+
let raw;
|
|
877
|
+
let alpha;
|
|
878
|
+
if (typeof value === "string" || record(value) && "slot" in value) raw = value;
|
|
879
|
+
else if (record(value) && "color" in value) {
|
|
880
|
+
raw = value["color"];
|
|
881
|
+
alpha = value["alpha"] === void 0 ? void 0 : checkedFraction(value["alpha"], "color alpha");
|
|
882
|
+
} else throw new CapabilityError("invalid-color", "Invalid color value format");
|
|
883
|
+
const resolved = typeof raw === "string" ? resolveColorName(raw, context, 0) : resolveColorValue(raw, context, 0);
|
|
884
|
+
if (alpha === void 0) return resolved;
|
|
885
|
+
return {
|
|
886
|
+
...resolved,
|
|
887
|
+
alpha: (resolved.alpha ?? 1) * alpha
|
|
888
|
+
};
|
|
889
|
+
},
|
|
890
|
+
resolveFont(value) {
|
|
891
|
+
if (isFont(value)) return {
|
|
892
|
+
family: value.family,
|
|
893
|
+
font: value
|
|
894
|
+
};
|
|
895
|
+
if (typeof value !== "string" || value.trim() === "") throw new CapabilityError("invalid-font-family", "fontFamily cannot be empty");
|
|
896
|
+
const local = scopeFontValue(context, value);
|
|
897
|
+
const themeFontName = value === "major" || value === "minor" ? value : void 0;
|
|
898
|
+
const overrideFont = themeFontName === void 0 ? void 0 : themeOverride?.fonts?.[themeFontName];
|
|
899
|
+
const token = local?.value ?? overrideFont ?? (Object.hasOwn(theme.fonts, value) ? theme.fonts[value] : value);
|
|
900
|
+
const globalThemeFont = themeFontName === void 0 ? void 0 : overrideFont ?? theme.fonts[themeFontName];
|
|
901
|
+
const globalFamily = isFont(globalThemeFont) ? globalThemeFont.family : globalThemeFont;
|
|
902
|
+
if (isFont(token)) return {
|
|
903
|
+
family: token.family,
|
|
904
|
+
font: token,
|
|
905
|
+
...themeFontName === void 0 || token.family !== globalFamily ? {} : { themeFont: themeFontName }
|
|
906
|
+
};
|
|
907
|
+
return {
|
|
908
|
+
family: token,
|
|
909
|
+
...themeFontName === void 0 || token !== globalFamily ? {} : { themeFont: themeFontName }
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
contextRecords.set(context, {
|
|
914
|
+
...parent === void 0 ? {} : { parent },
|
|
915
|
+
...scope === void 0 ? {} : { scope },
|
|
916
|
+
...themeOverride === void 0 ? {} : { themeOverride }
|
|
917
|
+
});
|
|
918
|
+
return context;
|
|
919
|
+
}
|
|
920
|
+
/** Create a theme chain unique to a single build; local scopes do not mutate the shared theme object. */
|
|
921
|
+
function createThemeContext(input, style, options = {}) {
|
|
922
|
+
if (style !== void 0) {
|
|
923
|
+
if (!record(style)) throw new CapabilityError("invalid-style", "style must be an object");
|
|
924
|
+
const unknown = Object.keys(style).find((key) => !textStyleKeys.has(key));
|
|
925
|
+
if (unknown !== void 0) throw new CapabilityError("invalid-style", `Deck.style contains unsupported text property ${unknown}`);
|
|
926
|
+
}
|
|
927
|
+
const theme = normalizeTheme(input);
|
|
928
|
+
const colorMap = options.colorMap ?? defaultColorMap;
|
|
929
|
+
return createContext(theme, void 0, void 0, textStyleFrom(style, createContext(theme, void 0, void 0, {}, colorMap, options.themeOverride)), colorMap, options.themeOverride);
|
|
930
|
+
}
|
|
931
|
+
export { applyFormatColorTransforms, assertValidLang, bcp47LangSchema, colorMapOverrideSchema, colorMapSchema, colorValueSchema, createThemeContext, darker, defaultColorMap, defaultTheme, defineTheme, fontFaceSchema, fontFaceStyleSchema, fontOptionsSchema, fontReferenceSchema, fontSchema, fontSizeSchema, fontTokenSchema, formatColorTransformSchema, formatEffectStyleSchema, formatFillStyleSchema, formatGradientStopSchema, formatLineStyleSchema, formatSchemeSchema, gradientStopSchema, isFont, isNativeColorSlot, isSchemeColorName, isSchemeColorSlot, isTheme, lighter, linearGradientSchema, nativeColorSlotSchema, nativeColorSlots, radialGradientSchema, schemeColorNameSchema, schemeColorNames, schemeColorSlots, shadowSchema, textAlignmentSchema, textStyleFrom, textStyleKeys, textStyleSchema, textStyleShape, themeColorSchema, themeDataSchema, themeInputSchema, themeOverrideSchema, themeSchema, themeScopeSchema, themeShadeSchema, uint8ArraySchema, validateTextStyle, visualStyleSchema };
|