@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,149 @@
|
|
|
1
|
+
import { authorIdSchema } from "../../../core/dist/author-ids.js";
|
|
2
|
+
import { layoutStyleSchema } from "../../../core/dist/layout-schemas.js";
|
|
3
|
+
import { visualStyleSchema } from "../../../core/dist/theme.js";
|
|
4
|
+
import { linkTargetSchema } from "../../../core/dist/author-schemas.js";
|
|
5
|
+
import { geometrySchema } from "../../../core/dist/geometry-schemas.js";
|
|
6
|
+
import { nativePlaceholderRefSchema } from "../../../core/dist/placeholders.js";
|
|
7
|
+
import "../../../core/dist/capability.js";
|
|
8
|
+
import "../../../import/dist/index.js";
|
|
9
|
+
import { ooxmlIntSchema, ooxmlNonNegativeIntSchema, ooxmlPositiveIntSchema } from "../../../import/dist/xml-fragments.js";
|
|
10
|
+
import { motionPropsSchema } from "../motion/motion-schemas.js";
|
|
11
|
+
import "../shared/geometry.js";
|
|
12
|
+
import { optionalNameSchema } from "../shared/identity.js";
|
|
13
|
+
import { morphKeySchema } from "../shared/morph-api.js";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
// ../capabilities/dist/image/image-schemas.js
|
|
16
|
+
const imageFitSchema = z.enum([
|
|
17
|
+
"fill",
|
|
18
|
+
"cover",
|
|
19
|
+
"contain"
|
|
20
|
+
]);
|
|
21
|
+
const cropFractionSchema = z.number().finite().min(0).max(1);
|
|
22
|
+
const imageCropInputSchema = z.strictObject({
|
|
23
|
+
left: cropFractionSchema.optional(),
|
|
24
|
+
top: cropFractionSchema.optional(),
|
|
25
|
+
right: cropFractionSchema.optional(),
|
|
26
|
+
bottom: cropFractionSchema.optional()
|
|
27
|
+
}).superRefine((crop, ctx) => {
|
|
28
|
+
if ((crop.left ?? 0) + (crop.right ?? 0) > 1) ctx.addIssue({
|
|
29
|
+
code: "custom",
|
|
30
|
+
message: "Sum of crop left and right cannot exceed 1",
|
|
31
|
+
path: ["left"]
|
|
32
|
+
});
|
|
33
|
+
if ((crop.top ?? 0) + (crop.bottom ?? 0) > 1) ctx.addIssue({
|
|
34
|
+
code: "custom",
|
|
35
|
+
message: "Sum of crop top and bottom cannot exceed 1",
|
|
36
|
+
path: ["top"]
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
const externalImageSourceSchema = z.strictObject({ externalUrl: z.string().min(1) });
|
|
40
|
+
const imageSourceSchema = z.union([
|
|
41
|
+
z.string(),
|
|
42
|
+
z.instanceof(URL),
|
|
43
|
+
z.custom((value) => value instanceof Uint8Array),
|
|
44
|
+
externalImageSourceSchema
|
|
45
|
+
]);
|
|
46
|
+
const imageCoordinateValueSchema = z.number().finite().min(-1e6).max(1e6);
|
|
47
|
+
const imageExtentValueSchema = z.number().finite().positive();
|
|
48
|
+
const coreVisualShape = visualStyleSchema.unwrap().shape;
|
|
49
|
+
const imageVisualStyleObjectSchema = z.strictObject({
|
|
50
|
+
borderColor: coreVisualShape.borderColor,
|
|
51
|
+
borderWidth: coreVisualShape.borderWidth,
|
|
52
|
+
borderStyle: coreVisualShape.borderStyle,
|
|
53
|
+
opacity: coreVisualShape.opacity,
|
|
54
|
+
boxShadow: coreVisualShape.boxShadow,
|
|
55
|
+
softEdge: coreVisualShape.softEdge,
|
|
56
|
+
rotate: coreVisualShape.rotate
|
|
57
|
+
});
|
|
58
|
+
imageVisualStyleObjectSchema.readonly();
|
|
59
|
+
const imageVisualStyleKeys = new Set(Object.keys(imageVisualStyleObjectSchema.shape));
|
|
60
|
+
const imageStyleSchema = z.strictObject({
|
|
61
|
+
...layoutStyleSchema.unwrap().shape,
|
|
62
|
+
...imageVisualStyleObjectSchema.shape
|
|
63
|
+
}).readonly();
|
|
64
|
+
const motionPropsShape = motionPropsSchema.unwrap().shape;
|
|
65
|
+
const imageDeclarationPropsObjectSchema = z.strictObject({
|
|
66
|
+
id: authorIdSchema.optional(),
|
|
67
|
+
name: optionalNameSchema.optional(),
|
|
68
|
+
placeholder: z.string().optional(),
|
|
69
|
+
nativePlaceholder: nativePlaceholderRefSchema.optional(),
|
|
70
|
+
morphKey: morphKeySchema.optional(),
|
|
71
|
+
link: linkTargetSchema.optional(),
|
|
72
|
+
src: imageSourceSchema,
|
|
73
|
+
/** Alternative text for the image. */
|
|
74
|
+
alt: z.string().optional(),
|
|
75
|
+
/** Position and bounds in px; position defaults to 0, width and height default to original image dimensions. */
|
|
76
|
+
x: imageCoordinateValueSchema.optional(),
|
|
77
|
+
y: imageCoordinateValueSchema.optional(),
|
|
78
|
+
width: imageExtentValueSchema.optional(),
|
|
79
|
+
height: imageExtentValueSchema.optional(),
|
|
80
|
+
geometry: geometrySchema.optional(),
|
|
81
|
+
flipH: z.boolean().optional(),
|
|
82
|
+
flipV: z.boolean().optional(),
|
|
83
|
+
style: imageStyleSchema.optional(),
|
|
84
|
+
/** `fill` stretches, `cover` crops centered, `contain` preserves aspect ratio; defaults to `fill`. */
|
|
85
|
+
fit: imageFitSchema.optional(),
|
|
86
|
+
/** Explicit crop fraction for each side of the original image; takes precedence over `fit` when provided. */
|
|
87
|
+
crop: imageCropInputSchema.optional(),
|
|
88
|
+
enter: motionPropsShape.enter,
|
|
89
|
+
emphasis: motionPropsShape.emphasis,
|
|
90
|
+
motion: motionPropsShape.motion
|
|
91
|
+
});
|
|
92
|
+
const imageDeclarationPropsSchema = imageDeclarationPropsObjectSchema.readonly();
|
|
93
|
+
const imageAllowedParameters = Object.keys(imageDeclarationPropsObjectSchema.shape);
|
|
94
|
+
const nonVisualPicIdSchema = z.object({
|
|
95
|
+
id: ooxmlNonNegativeIntSchema,
|
|
96
|
+
name: z.string().optional(),
|
|
97
|
+
descr: z.string().optional()
|
|
98
|
+
});
|
|
99
|
+
const OoxmlCropFractionSchema = ooxmlNonNegativeIntSchema.refine((value) => value <= 1e5, { message: "Crop value cannot exceed 100000" });
|
|
100
|
+
const srcRectFragmentSchema = z.object({
|
|
101
|
+
l: OoxmlCropFractionSchema.optional(),
|
|
102
|
+
t: OoxmlCropFractionSchema.optional(),
|
|
103
|
+
r: OoxmlCropFractionSchema.optional(),
|
|
104
|
+
b: OoxmlCropFractionSchema.optional()
|
|
105
|
+
}).refine((value) => (value.l ?? 0) + (value.r ?? 0) <= 1e5 && (value.t ?? 0) + (value.b ?? 0) <= 1e5, { message: "Crop sum cannot exceed 100000" });
|
|
106
|
+
const alphaModFixFragmentSchema = z.object({ amt: OoxmlCropFractionSchema });
|
|
107
|
+
const presetGeomFragmentSchema = z.object({ prst: z.string().min(1) });
|
|
108
|
+
const geomGuideFragmentSchema = z.object({
|
|
109
|
+
name: z.string().min(1),
|
|
110
|
+
fmla: z.string().regex(/^val (-?\d+)$/u)
|
|
111
|
+
});
|
|
112
|
+
const customPathAttributesSchema = z.object({
|
|
113
|
+
w: ooxmlPositiveIntSchema.optional(),
|
|
114
|
+
h: ooxmlPositiveIntSchema.optional(),
|
|
115
|
+
fill: z.enum([
|
|
116
|
+
"none",
|
|
117
|
+
"norm",
|
|
118
|
+
"lighten",
|
|
119
|
+
"lightenLess",
|
|
120
|
+
"darken",
|
|
121
|
+
"darkenLess"
|
|
122
|
+
]).optional(),
|
|
123
|
+
stroke: z.enum([
|
|
124
|
+
"0",
|
|
125
|
+
"1",
|
|
126
|
+
"true",
|
|
127
|
+
"false"
|
|
128
|
+
]).optional()
|
|
129
|
+
});
|
|
130
|
+
const customPathPointSchema = z.object({
|
|
131
|
+
x: ooxmlIntSchema,
|
|
132
|
+
y: ooxmlIntSchema
|
|
133
|
+
});
|
|
134
|
+
const lineAttributesFragmentSchema = z.object({ w: ooxmlPositiveIntSchema.optional() });
|
|
135
|
+
const presetDashFragmentSchema = z.object({ val: z.enum([
|
|
136
|
+
"solid",
|
|
137
|
+
"dash",
|
|
138
|
+
"sysDot",
|
|
139
|
+
"dot"
|
|
140
|
+
]) });
|
|
141
|
+
const outerShadowFragmentSchema = z.object({
|
|
142
|
+
blurRad: ooxmlNonNegativeIntSchema.optional(),
|
|
143
|
+
dist: ooxmlNonNegativeIntSchema.optional(),
|
|
144
|
+
dir: ooxmlNonNegativeIntSchema.optional(),
|
|
145
|
+
algn: z.string().optional(),
|
|
146
|
+
rotWithShape: z.string().optional()
|
|
147
|
+
});
|
|
148
|
+
const softEdgeFragmentSchema = z.object({ rad: ooxmlNonNegativeIntSchema });
|
|
149
|
+
export { alphaModFixFragmentSchema, cropFractionSchema, customPathAttributesSchema, customPathPointSchema, externalImageSourceSchema, geomGuideFragmentSchema, imageAllowedParameters, imageCoordinateValueSchema, imageCropInputSchema, imageDeclarationPropsSchema, imageExtentValueSchema, imageFitSchema, imageSourceSchema, imageStyleSchema, imageVisualStyleKeys, lineAttributesFragmentSchema, nonVisualPicIdSchema, outerShadowFragmentSchema, presetDashFragmentSchema, presetGeomFragmentSchema, softEdgeFragmentSchema, srcRectFragmentSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { placeholderRefXml, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
2
|
+
import "../../../emit/dist/index.js";
|
|
3
|
+
// ../capabilities/dist/image/image-xml.js
|
|
4
|
+
/** Internal PresentationML wrapper for native picture objects and their crop/opacity values. */
|
|
5
|
+
function imageXml(id, escapedName, escapedAlt, blipRef, _box, crop, properties, opacity, linkXml, placeholder) {
|
|
6
|
+
const description = escapedAlt === void 0 ? "" : ` descr="${escapedAlt}"`;
|
|
7
|
+
const cropXml = Object.keys(crop).length === 0 ? "" : `<a:srcRect${Object.entries(crop).map(([side, fraction]) => ` ${side}="${Math.round(fraction * 1e5)}"`).join("")}/>`;
|
|
8
|
+
const alpha = opacity === void 0 ? "" : `<a:alphaModFix amt="${Math.round(opacity * 1e5)}"/>`;
|
|
9
|
+
const blipAttr = blipRef.kind === "link" ? `r:link="${xmlEscape(blipRef.relationshipId)}"` : `r:embed="${xmlEscape(blipRef.relationshipId)}"`;
|
|
10
|
+
return `<p:pic><p:nvPicPr><p:cNvPr id="${id}" name="${escapedName}"${description}>${linkXml}</p:cNvPr>${placeholder === void 0 ? "<p:cNvPicPr><a:picLocks noChangeAspect=\"1\"/></p:cNvPicPr>" : "<p:cNvPicPr><a:picLocks noGrp=\"1\" noChangeAspect=\"1\"/></p:cNvPicPr>"}${placeholder === void 0 ? "<p:nvPr/>" : `<p:nvPr>${placeholderRefXml(placeholder.nativeRef)}</p:nvPr>`}</p:nvPicPr><p:blipFill><a:blip ${blipAttr}>${alpha}</a:blip>${cropXml}<a:stretch><a:fillRect/></a:stretch></p:blipFill>${placeholder?.spPrXml ?? properties}</p:pic>`;
|
|
11
|
+
}
|
|
12
|
+
export { imageXml };
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { parseLinkTarget } from "../../../core/dist/author-schemas.js";
|
|
3
|
+
import { parseCapabilityLayoutContract } from "../../../core/dist/layout.js";
|
|
4
|
+
import "../../../core/dist/capability.js";
|
|
5
|
+
import { assertXml10Characters, pxToEmu, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
6
|
+
import "../../../emit/dist/index.js";
|
|
7
|
+
import "../../../import/dist/index.js";
|
|
8
|
+
import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
|
|
9
|
+
import { motionAnnotations } from "../motion/motion-api.js";
|
|
10
|
+
import { evaluateGeometry } from "../shared/geometry.js";
|
|
11
|
+
import { nativeLinkXml, parseMorphKey, parseOptionalName } from "../shared/identity.js";
|
|
12
|
+
import { hasLocalDeclaration, resolvePlaceholderGeometry } from "../shared/style-inheritance.js";
|
|
13
|
+
import { emitVisualModel, resolveVisualModel, visualSvgTransform } from "../shared/visual.js";
|
|
14
|
+
import { imageCodegen } from "./image-codegen.js";
|
|
15
|
+
import "./image-declaration.js";
|
|
16
|
+
import { decodeImageToPngBytes, readImage } from "./image-decode.js";
|
|
17
|
+
import { imageImportHandler, picturePlaceholderImportHandler } from "./image-import.js";
|
|
18
|
+
import { externalImageSourceSchema, imageAllowedParameters, imageCoordinateValueSchema, imageCropInputSchema, imageDeclarationPropsSchema, imageExtentValueSchema, imageFitSchema, imageSourceSchema, imageStyleSchema, imageVisualStyleKeys } from "./image-schemas.js";
|
|
19
|
+
import { imageXml } from "./image-xml.js";
|
|
20
|
+
// ../capabilities/dist/image/image.js
|
|
21
|
+
function roundSvgNumber(value) {
|
|
22
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
23
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
24
|
+
}
|
|
25
|
+
function borderStrokeAttributes(border) {
|
|
26
|
+
const w = Math.max(1, border.width);
|
|
27
|
+
let dashAttr = "";
|
|
28
|
+
switch (border.style) {
|
|
29
|
+
case "solid":
|
|
30
|
+
dashAttr = "";
|
|
31
|
+
break;
|
|
32
|
+
case "dashed":
|
|
33
|
+
dashAttr = ` stroke-dasharray="${roundSvgNumber(w * 4)} ${roundSvgNumber(w * 3)}"`;
|
|
34
|
+
break;
|
|
35
|
+
case "dotted":
|
|
36
|
+
dashAttr = ` stroke-dasharray="${roundSvgNumber(w)} ${roundSvgNumber(w * 2)}"`;
|
|
37
|
+
break;
|
|
38
|
+
default: return border.style;
|
|
39
|
+
}
|
|
40
|
+
return `stroke="#${border.color.hex}" stroke-opacity="${roundSvgNumber(border.color.alpha ?? 1)}" stroke-width="${roundSvgNumber(border.width)}"${dashAttr}`;
|
|
41
|
+
}
|
|
42
|
+
const imageRelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
|
|
43
|
+
function emitImageModel(model, emitContext) {
|
|
44
|
+
const properties = emitVisualModel(model.visual, void 0, { omitFill: true });
|
|
45
|
+
const escapedName = xmlEscape(model.name);
|
|
46
|
+
const escapedAlt = model.alt === void 0 ? void 0 : xmlEscape(model.alt);
|
|
47
|
+
let relationshipId;
|
|
48
|
+
try {
|
|
49
|
+
relationshipId = model.image.kind === "external" ? emitContext.registerResource({
|
|
50
|
+
externalTarget: model.image.externalUrl,
|
|
51
|
+
relationshipType: imageRelationshipType
|
|
52
|
+
}) : emitContext.registerResource({
|
|
53
|
+
bytes: model.image.bytes,
|
|
54
|
+
extension: model.image.extension,
|
|
55
|
+
contentType: model.image.contentType,
|
|
56
|
+
relationshipType: imageRelationshipType
|
|
57
|
+
});
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof CapabilityError) throw error;
|
|
60
|
+
throw new CapabilityError("image-resource-failure", error instanceof Error ? error.message : String(error));
|
|
61
|
+
}
|
|
62
|
+
const { sourceCrop } = model.placement;
|
|
63
|
+
const serializedCrop = Object.fromEntries([
|
|
64
|
+
["l", sourceCrop.l],
|
|
65
|
+
["t", sourceCrop.t],
|
|
66
|
+
["r", sourceCrop.r],
|
|
67
|
+
["b", sourceCrop.b]
|
|
68
|
+
].filter(([, fraction]) => fraction !== 0));
|
|
69
|
+
return { xml: imageXml(emitContext.id, escapedName, escapedAlt, {
|
|
70
|
+
kind: model.image.kind === "external" ? "link" : "embed",
|
|
71
|
+
relationshipId
|
|
72
|
+
}, model.placement.box, serializedCrop, properties.xml, properties.opacity, nativeLinkXml(emitContext.nativeLink), model.placeholder === void 0 ? void 0 : {
|
|
73
|
+
nativeRef: model.placeholder.nativeRef,
|
|
74
|
+
...model.placeholder.omitSpPrTransform ? { spPrXml: "<p:spPr/>" } : {}
|
|
75
|
+
}) };
|
|
76
|
+
}
|
|
77
|
+
function roundCropFraction(fraction) {
|
|
78
|
+
return Math.round(fraction * 1e5) / 1e5;
|
|
79
|
+
}
|
|
80
|
+
function paintImageModel(model, paintContext) {
|
|
81
|
+
const { image, placement, visual } = model;
|
|
82
|
+
const { box, sourceCrop } = placement;
|
|
83
|
+
if (image.kind === "external") {
|
|
84
|
+
const evaluated = evaluateGeometry(visual.geometry, box);
|
|
85
|
+
const placeholderShapes = evaluated.paths.filter((pathItem) => pathItem.fillMode !== "none" && pathItem.d !== "").map((pathItem) => `<path d="${pathItem.d}" fill="#F1F5F9" stroke="#94A3B8" stroke-width="1" stroke-dasharray="4 4"/>`).join("");
|
|
86
|
+
const borderElements = visual.border !== void 0 ? evaluated.paths.filter((pathItem) => pathItem.stroke && pathItem.d !== "").map((pathItem) => `<path d="${pathItem.d}" fill="none" ${borderStrokeAttributes(visual.border)}/>`).join("") : "";
|
|
87
|
+
return {
|
|
88
|
+
svg: `<g transform="${visualSvgTransform(visual)}">${placeholderShapes}${borderElements}</g>`,
|
|
89
|
+
warnings: [{ message: `External linked image (${image.externalUrl}) is unavailable offline; rendered placeholder` }]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const pngBytes = decodeImageToPngBytes(image);
|
|
93
|
+
const leftCrop = roundCropFraction(sourceCrop.l);
|
|
94
|
+
const topCrop = roundCropFraction(sourceCrop.t);
|
|
95
|
+
const rightCrop = roundCropFraction(sourceCrop.r);
|
|
96
|
+
const bottomCrop = roundCropFraction(sourceCrop.b);
|
|
97
|
+
const widthFactor = 1 - leftCrop - rightCrop;
|
|
98
|
+
const heightFactor = 1 - topCrop - bottomCrop;
|
|
99
|
+
const prefix = `img-s${paintContext.slideNumber}-o${paintContext.objectId}`;
|
|
100
|
+
const defs = [];
|
|
101
|
+
const evaluated = evaluateGeometry(visual.geometry, box);
|
|
102
|
+
const fillablePaths = evaluated.paths.filter((pathItem) => pathItem.fillMode !== "none" && pathItem.d !== "");
|
|
103
|
+
const opacity = visual.opacity ?? 1;
|
|
104
|
+
let imageElement = "";
|
|
105
|
+
if (widthFactor > 0 && heightFactor > 0 && fillablePaths.length > 0) {
|
|
106
|
+
const imgWidth = box.width / widthFactor;
|
|
107
|
+
const imgHeight = box.height / heightFactor;
|
|
108
|
+
const imgX = box.x - leftCrop * imgWidth;
|
|
109
|
+
const imgY = box.y - topCrop * imgHeight;
|
|
110
|
+
const clipId = `${prefix}-clip`;
|
|
111
|
+
const clipMarkup = fillablePaths.map((pathItem) => `<path d="${pathItem.d}"/>`).join("");
|
|
112
|
+
defs.push(`<clipPath id="${clipId}" clipPathUnits="userSpaceOnUse">${clipMarkup}</clipPath>`);
|
|
113
|
+
const opacityAttr = opacity === 1 ? "" : ` opacity="${roundSvgNumber(opacity)}"`;
|
|
114
|
+
imageElement = `<image clip-path="url(#${clipId})" x="${roundSvgNumber(imgX)}" y="${roundSvgNumber(imgY)}" width="${roundSvgNumber(imgWidth)}" height="${roundSvgNumber(imgHeight)}" preserveAspectRatio="none"${opacityAttr} href="data:image/png;base64,${Buffer.from(pngBytes).toString("base64")}"/>`;
|
|
115
|
+
if (visual.softEdge !== void 0 && visual.softEdge > 0) {
|
|
116
|
+
const r = visual.softEdge;
|
|
117
|
+
const minSide = Math.min(box.width, box.height);
|
|
118
|
+
const borderPad = visual.border === void 0 ? 0 : visual.border.width;
|
|
119
|
+
const pad = Math.ceil(r * 2 + borderPad + 8);
|
|
120
|
+
const maskX = roundSvgNumber(box.x - pad);
|
|
121
|
+
const maskY = roundSvgNumber(box.y - pad);
|
|
122
|
+
const maskW = roundSvgNumber(box.width + pad * 2);
|
|
123
|
+
const maskH = roundSvgNumber(box.height + pad * 2);
|
|
124
|
+
const blurId = `${prefix}-soft-blur`;
|
|
125
|
+
const maskId = `${prefix}-soft-mask`;
|
|
126
|
+
const innerStrokeWidth = r >= minSide / 2 ? 0 : Math.min(r, minSide * .45);
|
|
127
|
+
const maskAttrs = innerStrokeWidth > 0 ? `fill="white" stroke="black" stroke-width="${roundSvgNumber(innerStrokeWidth)}" filter="url(#${blurId})"` : `fill="white" stroke="none" filter="url(#${blurId})"`;
|
|
128
|
+
const maskShapes = fillablePaths.map((pathItem) => `<path d="${pathItem.d}" ${maskAttrs}/>`).join("");
|
|
129
|
+
defs.push(`<filter id="${blurId}" filterUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}"><feGaussianBlur stdDeviation="${roundSvgNumber(r / 2)}"/></filter>`);
|
|
130
|
+
defs.push(`<mask id="${maskId}" maskUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}">${maskShapes}</mask>`);
|
|
131
|
+
imageElement = `<g mask="url(#${maskId})">${imageElement}</g>`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let borderElements = "";
|
|
135
|
+
if (visual.border !== void 0) {
|
|
136
|
+
const strokeAttr = borderStrokeAttributes(visual.border);
|
|
137
|
+
borderElements = evaluated.paths.filter((pathItem) => pathItem.stroke && pathItem.d !== "").map((pathItem) => `<path d="${pathItem.d}" fill="none" ${strokeAttr}/>`).join("");
|
|
138
|
+
}
|
|
139
|
+
let layer = `<g transform="${visualSvgTransform(visual)}">${imageElement}${borderElements}</g>`;
|
|
140
|
+
if (visual.boxShadow !== void 0) {
|
|
141
|
+
const shadow = visual.boxShadow;
|
|
142
|
+
const cx = box.x + box.width / 2;
|
|
143
|
+
const cy = box.y + box.height / 2;
|
|
144
|
+
const halfDiag = Math.hypot(box.width, box.height) / 2;
|
|
145
|
+
const rad = shadow.angle * Math.PI / 180;
|
|
146
|
+
const dx = shadow.distance * Math.cos(rad);
|
|
147
|
+
const dy = shadow.distance * Math.sin(rad);
|
|
148
|
+
const sigma = shadow.blur / 2;
|
|
149
|
+
const borderPad = visual.border === void 0 ? 0 : visual.border.width;
|
|
150
|
+
const pad = shadow.blur * 3 + Math.abs(dx) + Math.abs(dy) + borderPad + 16;
|
|
151
|
+
const minX = roundSvgNumber(cx - halfDiag - pad);
|
|
152
|
+
const minY = roundSvgNumber(cy - halfDiag - pad);
|
|
153
|
+
const filterSize = roundSvgNumber((halfDiag + pad) * 2);
|
|
154
|
+
const shadowId = `${prefix}-shadow`;
|
|
155
|
+
defs.push(`<filter id="${shadowId}" filterUnits="userSpaceOnUse" x="${minX}" y="${minY}" width="${filterSize}" height="${filterSize}"><feDropShadow dx="${roundSvgNumber(dx)}" dy="${roundSvgNumber(dy)}" stdDeviation="${roundSvgNumber(sigma)}" flood-color="#${shadow.color.hex}" flood-opacity="${roundSvgNumber(shadow.color.alpha ?? 1)}"/></filter>`);
|
|
156
|
+
layer = `<g filter="url(#${shadowId})">${layer}</g>`;
|
|
157
|
+
}
|
|
158
|
+
return { svg: `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${layer}` };
|
|
159
|
+
}
|
|
160
|
+
/** Shared image placement calculation for native OOXML output and static preview. */
|
|
161
|
+
function imagePlacement(image, fit, crop, allocated) {
|
|
162
|
+
const { width, height } = allocated;
|
|
163
|
+
const box = { ...allocated };
|
|
164
|
+
let l = crop?.l ?? 0;
|
|
165
|
+
let t = crop?.t ?? 0;
|
|
166
|
+
let r = crop?.r ?? 0;
|
|
167
|
+
let b = crop?.b ?? 0;
|
|
168
|
+
if (crop === void 0 && image.width !== void 0 && image.height !== void 0) {
|
|
169
|
+
if (fit === "cover") {
|
|
170
|
+
const imageRatio = image.width / image.height;
|
|
171
|
+
const boxRatio = width / height;
|
|
172
|
+
if (imageRatio > boxRatio) {
|
|
173
|
+
const excess = (1 - boxRatio / imageRatio) / 2;
|
|
174
|
+
l = excess;
|
|
175
|
+
r = excess;
|
|
176
|
+
} else if (imageRatio < boxRatio) {
|
|
177
|
+
const excess = (1 - imageRatio / boxRatio) / 2;
|
|
178
|
+
t = excess;
|
|
179
|
+
b = excess;
|
|
180
|
+
}
|
|
181
|
+
} else if (fit === "contain") {
|
|
182
|
+
const imageRatio = image.width / image.height;
|
|
183
|
+
const boxRatio = width / height;
|
|
184
|
+
if (imageRatio > boxRatio) {
|
|
185
|
+
const fittedHeight = width / imageRatio;
|
|
186
|
+
box.y += (height - fittedHeight) / 2;
|
|
187
|
+
box.height = fittedHeight;
|
|
188
|
+
} else if (imageRatio < boxRatio) {
|
|
189
|
+
const fittedWidth = height * imageRatio;
|
|
190
|
+
box.x += (width - fittedWidth) / 2;
|
|
191
|
+
box.width = fittedWidth;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
box.width = dimension(box.width, "width");
|
|
196
|
+
box.height = dimension(box.height, "height");
|
|
197
|
+
return {
|
|
198
|
+
box,
|
|
199
|
+
sourceCrop: {
|
|
200
|
+
l,
|
|
201
|
+
t,
|
|
202
|
+
r,
|
|
203
|
+
b
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const imageCompatiblePlaceholderRoles = /* @__PURE__ */ new Set([
|
|
208
|
+
"pic",
|
|
209
|
+
"clipArt",
|
|
210
|
+
"obj"
|
|
211
|
+
]);
|
|
212
|
+
const maximumShapeExtentEmu = 2147483647;
|
|
213
|
+
function isRecord(value) {
|
|
214
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
215
|
+
}
|
|
216
|
+
function dimension(value, name, fallback) {
|
|
217
|
+
const actual = value === void 0 ? fallback : value;
|
|
218
|
+
const isExtent = name === "width" || name === "height";
|
|
219
|
+
const parsed = isExtent ? imageExtentValueSchema.safeParse(actual) : imageCoordinateValueSchema.safeParse(actual);
|
|
220
|
+
if (!parsed.success) throw new CapabilityError("invalid-coordinate", `${name} must be a finite pixel number, width and height must be greater than 0, and coordinates must be between -1000000 and 1000000`);
|
|
221
|
+
if (isExtent) {
|
|
222
|
+
const extentEmu = pxToEmu(parsed.data);
|
|
223
|
+
if (extentEmu < 1 || extentEmu > maximumShapeExtentEmu) throw new CapabilityError("invalid-coordinate", `${name} must convert to an EMU value between 1 and ${maximumShapeExtentEmu} inclusive`);
|
|
224
|
+
}
|
|
225
|
+
return parsed.data;
|
|
226
|
+
}
|
|
227
|
+
function requestedDimension(style, props, name) {
|
|
228
|
+
const styled = style[name];
|
|
229
|
+
return styled === void 0 ? props[name] : typeof styled === "number" ? styled : void 0;
|
|
230
|
+
}
|
|
231
|
+
function parseCropValues(value, path) {
|
|
232
|
+
if (value === void 0) return void 0;
|
|
233
|
+
const parsed = imageCropInputSchema.safeParse(value);
|
|
234
|
+
if (!parsed.success) {
|
|
235
|
+
const issue = parsed.error.issues[0];
|
|
236
|
+
if (issue?.code === "unrecognized_keys") throw new CapabilityError("unknown-parameter", `crop contains unknown parameter ${issue.keys[0]}`, path);
|
|
237
|
+
throw new CapabilityError("invalid-crop", issue?.message ?? "crop must be a four-sided fraction object", path);
|
|
238
|
+
}
|
|
239
|
+
const { left, top, right, bottom } = parsed.data;
|
|
240
|
+
return {
|
|
241
|
+
...left === void 0 ? {} : { l: left },
|
|
242
|
+
...top === void 0 ? {} : { t: top },
|
|
243
|
+
...right === void 0 ? {} : { r: right },
|
|
244
|
+
...bottom === void 0 ? {} : { b: bottom }
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function readImageSource(source) {
|
|
248
|
+
const parsed = imageSourceSchema.safeParse(source);
|
|
249
|
+
if (!parsed.success) throw new CapabilityError("invalid-image-source", "Image.src must be a file path, file URL, image bytes, or externalUrl descriptor");
|
|
250
|
+
const externalParsed = externalImageSourceSchema.safeParse(parsed.data);
|
|
251
|
+
if (externalParsed.success) return {
|
|
252
|
+
kind: "external",
|
|
253
|
+
externalUrl: externalParsed.data.externalUrl
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
kind: "embedded",
|
|
257
|
+
...readImage(parsed.data)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `image`. */
|
|
261
|
+
const imageMechanism = defineCanvasMechanism({
|
|
262
|
+
key: "image",
|
|
263
|
+
role: "canvas",
|
|
264
|
+
emit: emitImageModel,
|
|
265
|
+
paint: paintImageModel,
|
|
266
|
+
import: imageImportHandler
|
|
267
|
+
});
|
|
268
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `picture-placeholder`. */
|
|
269
|
+
const picturePlaceholderMechanism = defineCanvasMechanism({
|
|
270
|
+
key: "picture-placeholder",
|
|
271
|
+
role: "canvas",
|
|
272
|
+
emit: emitImageModel,
|
|
273
|
+
paint: paintImageModel,
|
|
274
|
+
import: picturePlaceholderImportHandler
|
|
275
|
+
});
|
|
276
|
+
/** Image module reads and validates formal resources, encapsulates bound state, and emits native picture objects. */
|
|
277
|
+
const imageCapability = {
|
|
278
|
+
declaration: "image",
|
|
279
|
+
codegen: imageCodegen,
|
|
280
|
+
mechanisms: [imageMechanism, picturePlaceholderMechanism],
|
|
281
|
+
bind(input, context) {
|
|
282
|
+
const placeholder = context.placeholder;
|
|
283
|
+
if (placeholder !== void 0) {
|
|
284
|
+
const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
|
|
285
|
+
if (!imageCompatiblePlaceholderRoles.has(role)) throw new CapabilityError("incompatible-placeholder-content", `Image cannot be bound to ${role} placeholder`);
|
|
286
|
+
}
|
|
287
|
+
const unknown = Object.keys(input.props).find((key) => !imageAllowedParameters.includes(key));
|
|
288
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-parameter", `Image contains unsupported parameter ${unknown}`);
|
|
289
|
+
if (input.children.some((child) => "props" in child || child.text.trim() !== "")) throw new CapabilityError("unsupported-children", "Image does not accept children");
|
|
290
|
+
const requestedName = parseOptionalName(input.props["name"]);
|
|
291
|
+
const morphKey = parseMorphKey(input.props["morphKey"]);
|
|
292
|
+
const link = parseLinkTarget(input.props["link"]);
|
|
293
|
+
const altParsed = imageDeclarationPropsSchema.unwrap().shape.alt.safeParse(input.props["alt"]);
|
|
294
|
+
if (!altParsed.success) throw new CapabilityError("invalid-parameter", "alt must be a string");
|
|
295
|
+
const altValue = altParsed.data;
|
|
296
|
+
const allowedStyleKeys = new Set(Object.keys(imageStyleSchema.unwrap().shape));
|
|
297
|
+
const contract = parseCapabilityLayoutContract({
|
|
298
|
+
nativeKind: "pic",
|
|
299
|
+
props: input.props,
|
|
300
|
+
allowedStyleKeys,
|
|
301
|
+
allowPadding: false,
|
|
302
|
+
path: context.path
|
|
303
|
+
});
|
|
304
|
+
const imageStyle = isRecord(input.props["style"]) ? { ...input.props["style"] } : {};
|
|
305
|
+
const requestedFit = input.props["fit"];
|
|
306
|
+
let fit = "fill";
|
|
307
|
+
if (requestedFit !== void 0) {
|
|
308
|
+
const parsedFit = imageFitSchema.safeParse(requestedFit);
|
|
309
|
+
if (!parsedFit.success) throw new CapabilityError("unsupported-fit", "fit must be fill, cover, or contain");
|
|
310
|
+
fit = parsedFit.data;
|
|
311
|
+
}
|
|
312
|
+
const crop = parseCropValues(input.props["crop"]);
|
|
313
|
+
const image = readImageSource(input.props["src"]);
|
|
314
|
+
const geometry = input.props["geometry"];
|
|
315
|
+
const flipH = input.props["flipH"];
|
|
316
|
+
const flipV = input.props["flipV"];
|
|
317
|
+
resolveVisualModel({
|
|
318
|
+
theme: context.theme,
|
|
319
|
+
style: imageStyle,
|
|
320
|
+
box: {
|
|
321
|
+
x: 0,
|
|
322
|
+
y: 0,
|
|
323
|
+
width: 100,
|
|
324
|
+
height: 100
|
|
325
|
+
},
|
|
326
|
+
...geometry !== void 0 ? { geometry } : {},
|
|
327
|
+
...flipH !== void 0 ? { flipH } : {},
|
|
328
|
+
...flipV !== void 0 ? { flipV } : {},
|
|
329
|
+
image: true
|
|
330
|
+
});
|
|
331
|
+
const placeholderGeometry = placeholder === void 0 ? void 0 : resolvePlaceholderGeometry(placeholder, input.props);
|
|
332
|
+
const hasLocalVisualOverride = geometry !== void 0 || flipH === true || flipV === true || [...imageVisualStyleKeys].some((key) => key !== "opacity" && hasLocalDeclaration(imageStyle, key));
|
|
333
|
+
const declaredX = placeholderGeometry?.x ?? input.props["x"];
|
|
334
|
+
const declaredY = placeholderGeometry?.y ?? input.props["y"];
|
|
335
|
+
const requestedWidth = requestedDimension(imageStyle, input.props, "width") ?? placeholderGeometry?.width;
|
|
336
|
+
const requestedHeight = requestedDimension(imageStyle, input.props, "height") ?? placeholderGeometry?.height;
|
|
337
|
+
const authorId = typeof input.props["id"] === "string" ? input.props["id"] : void 0;
|
|
338
|
+
const motionProps = {
|
|
339
|
+
...input.props["enter"] !== void 0 ? { enter: input.props["enter"] } : {},
|
|
340
|
+
...input.props["emphasis"] !== void 0 ? { emphasis: input.props["emphasis"] } : {},
|
|
341
|
+
...input.props["motion"] !== void 0 ? { motion: input.props["motion"] } : {}
|
|
342
|
+
};
|
|
343
|
+
const native = {
|
|
344
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
345
|
+
...requestedName === void 0 ? {} : { hasExplicitName: true },
|
|
346
|
+
...link === void 0 ? {} : { link }
|
|
347
|
+
};
|
|
348
|
+
return {
|
|
349
|
+
contract,
|
|
350
|
+
...morphKey !== void 0 || requestedName !== void 0 || link !== void 0 ? { native } : {},
|
|
351
|
+
measureLayout(request) {
|
|
352
|
+
const declaredWidth = typeof requestedWidth === "number" ? requestedWidth : void 0;
|
|
353
|
+
const declaredHeight = typeof requestedHeight === "number" ? requestedHeight : void 0;
|
|
354
|
+
if (image.kind === "external") {
|
|
355
|
+
if (declaredWidth !== void 0 && declaredHeight !== void 0) return {
|
|
356
|
+
width: declaredWidth,
|
|
357
|
+
height: declaredHeight,
|
|
358
|
+
minContentWidth: declaredWidth,
|
|
359
|
+
minContentHeight: declaredHeight
|
|
360
|
+
};
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const width = declaredWidth ?? Math.min(image.width, request.availableWidth ?? image.width);
|
|
364
|
+
return {
|
|
365
|
+
width,
|
|
366
|
+
height: declaredHeight ?? width * image.height / image.width,
|
|
367
|
+
minContentWidth: image.width,
|
|
368
|
+
minContentHeight: image.height
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
resolve(resolveContext) {
|
|
372
|
+
const x = dimension(resolveContext.layoutBox?.x ?? declaredX, "x", 0);
|
|
373
|
+
const y = dimension(resolveContext.layoutBox?.y ?? declaredY, "y", 0);
|
|
374
|
+
let width;
|
|
375
|
+
let height;
|
|
376
|
+
if (resolveContext.layoutBox !== void 0) {
|
|
377
|
+
width = dimension(resolveContext.layoutBox.width, "width");
|
|
378
|
+
height = dimension(resolveContext.layoutBox.height, "height");
|
|
379
|
+
} else if (image.kind === "external") {
|
|
380
|
+
width = dimension(requestedWidth, "width");
|
|
381
|
+
height = dimension(requestedHeight, "height");
|
|
382
|
+
} else if (requestedWidth === void 0 && requestedHeight === void 0) {
|
|
383
|
+
width = image.width;
|
|
384
|
+
height = image.height;
|
|
385
|
+
} else if (requestedWidth === void 0) {
|
|
386
|
+
height = dimension(requestedHeight, "height");
|
|
387
|
+
width = height * image.width / image.height;
|
|
388
|
+
} else if (requestedHeight === void 0) {
|
|
389
|
+
width = dimension(requestedWidth, "width");
|
|
390
|
+
height = width * image.height / image.width;
|
|
391
|
+
} else {
|
|
392
|
+
width = dimension(requestedWidth, "width");
|
|
393
|
+
height = dimension(requestedHeight, "height");
|
|
394
|
+
}
|
|
395
|
+
width = dimension(width, "width");
|
|
396
|
+
height = dimension(height, "height");
|
|
397
|
+
const placement = imagePlacement(image.kind === "external" ? {} : image, fit, crop, {
|
|
398
|
+
x,
|
|
399
|
+
y,
|
|
400
|
+
width,
|
|
401
|
+
height
|
|
402
|
+
});
|
|
403
|
+
const { box } = placement;
|
|
404
|
+
const boxChangedByFit = Math.abs(box.x - x) > .01 || Math.abs(box.y - y) > .01 || Math.abs(box.width - width) > .01 || Math.abs(box.height - height) > .01;
|
|
405
|
+
const resolvedVisual = resolveVisualModel({
|
|
406
|
+
theme: resolveContext.theme,
|
|
407
|
+
style: imageStyle,
|
|
408
|
+
box,
|
|
409
|
+
...geometry === void 0 ? {} : { geometry },
|
|
410
|
+
...flipH === void 0 ? {} : { flipH },
|
|
411
|
+
...flipV === void 0 ? {} : { flipV },
|
|
412
|
+
image: true
|
|
413
|
+
});
|
|
414
|
+
const name = resolveContext.morphName ?? requestedName ?? placeholder?.layoutPlaceholder?.name ?? `Image ${resolveContext.id - 1}`;
|
|
415
|
+
try {
|
|
416
|
+
assertXml10Characters(name);
|
|
417
|
+
if (altValue !== void 0) assertXml10Characters(altValue);
|
|
418
|
+
} catch {
|
|
419
|
+
throw new CapabilityError("invalid-xml-character", "Image.name or alt contains characters not allowed in XML 1.0");
|
|
420
|
+
}
|
|
421
|
+
const angle = resolvedVisual.rotate;
|
|
422
|
+
const annotations = motionAnnotations(motionProps, {
|
|
423
|
+
kind: "image",
|
|
424
|
+
name,
|
|
425
|
+
...authorId === void 0 ? {} : { authorId },
|
|
426
|
+
textBody: false,
|
|
427
|
+
filled: false,
|
|
428
|
+
box,
|
|
429
|
+
rotationDegrees: angle,
|
|
430
|
+
hasBackground: imageStyle["borderColor"] !== void 0 || typeof imageStyle["borderWidth"] === "number" && imageStyle["borderWidth"] > 0
|
|
431
|
+
});
|
|
432
|
+
const omitSpPrTransform = placeholder !== void 0 && placeholderGeometry?.hasLocalBoxOverride !== true && !hasLocalVisualOverride && !boxChangedByFit;
|
|
433
|
+
const model = {
|
|
434
|
+
image,
|
|
435
|
+
placement,
|
|
436
|
+
visual: resolvedVisual,
|
|
437
|
+
name,
|
|
438
|
+
...altValue === void 0 ? {} : { alt: altValue },
|
|
439
|
+
...placeholder === void 0 ? {} : { placeholder: {
|
|
440
|
+
nativeRef: placeholder.nativeRef,
|
|
441
|
+
omitSpPrTransform
|
|
442
|
+
} }
|
|
443
|
+
};
|
|
444
|
+
const mechanism = placeholder === void 0 ? imageMechanism : picturePlaceholderMechanism;
|
|
445
|
+
return {
|
|
446
|
+
observation: {
|
|
447
|
+
id: resolveContext.id,
|
|
448
|
+
kind: "image",
|
|
449
|
+
name,
|
|
450
|
+
box
|
|
451
|
+
},
|
|
452
|
+
transform: {
|
|
453
|
+
box,
|
|
454
|
+
angle,
|
|
455
|
+
flipH: resolvedVisual.flipH,
|
|
456
|
+
flipV: resolvedVisual.flipV
|
|
457
|
+
},
|
|
458
|
+
extensions: [],
|
|
459
|
+
...resolvedVisual.warnings.length === 0 ? {} : { warnings: resolvedVisual.warnings },
|
|
460
|
+
...annotations.length === 0 ? {} : { annotations },
|
|
461
|
+
emit(emitContext) {
|
|
462
|
+
return mechanism.emit(model, emitContext);
|
|
463
|
+
},
|
|
464
|
+
paint(paintContext) {
|
|
465
|
+
return mechanism.paint(model, paintContext);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
export { imageCapability, imageMechanism, picturePlaceholderMechanism };
|