@officedk/pptxdk 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,552 @@
|
|
|
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, pickMotionProps } 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, resolvePlaceholderVisualStyle } from "../shared/style-inheritance.js";
|
|
13
|
+
import { emitVisualModel, gradientDefSvg, paintImageFillSvg, 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, imageAltSchema, imageCoordinateValueSchema, imageCropInputSchema, imageExtentValueSchema, imageFitSchema, imageSourceSchema, imageStyleKeys, 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 omitFill = model.visual.fill.kind === "none" && model.placeholder?.hasLocalFill !== true;
|
|
45
|
+
const properties = emitVisualModel(model.visual, (resource) => emitContext.registerResource(resource), { omitFill });
|
|
46
|
+
const escapedName = xmlEscape(model.name);
|
|
47
|
+
const escapedAlt = model.alt === void 0 ? void 0 : xmlEscape(model.alt);
|
|
48
|
+
let relationshipId;
|
|
49
|
+
try {
|
|
50
|
+
relationshipId = model.image.kind === "external" ? emitContext.registerResource({
|
|
51
|
+
externalTarget: model.image.externalUrl,
|
|
52
|
+
relationshipType: imageRelationshipType
|
|
53
|
+
}) : emitContext.registerResource({
|
|
54
|
+
bytes: model.image.bytes,
|
|
55
|
+
extension: model.image.extension,
|
|
56
|
+
contentType: model.image.contentType,
|
|
57
|
+
relationshipType: imageRelationshipType
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof CapabilityError) throw error;
|
|
61
|
+
throw new CapabilityError("image-resource-failure", error instanceof Error ? error.message : String(error));
|
|
62
|
+
}
|
|
63
|
+
const { sourceCrop } = model.placement;
|
|
64
|
+
const serializedCrop = Object.fromEntries([
|
|
65
|
+
["l", sourceCrop.l],
|
|
66
|
+
["t", sourceCrop.t],
|
|
67
|
+
["r", sourceCrop.r],
|
|
68
|
+
["b", sourceCrop.b]
|
|
69
|
+
].filter(([, fraction]) => fraction !== 0));
|
|
70
|
+
return { xml: imageXml(emitContext.id, escapedName, escapedAlt, {
|
|
71
|
+
kind: model.image.kind === "external" ? "link" : "embed",
|
|
72
|
+
relationshipId
|
|
73
|
+
}, model.placement.box, serializedCrop, properties.xml, properties.opacity, nativeLinkXml(emitContext.nativeLink), model.placeholder === void 0 ? void 0 : {
|
|
74
|
+
nativeRef: model.placeholder.nativeRef,
|
|
75
|
+
...model.placeholder.omitSpPrTransform ? { spPrXml: "<p:spPr/>" } : {}
|
|
76
|
+
}) };
|
|
77
|
+
}
|
|
78
|
+
function roundCropFraction(fraction) {
|
|
79
|
+
return Math.round(fraction * 1e5) / 1e5;
|
|
80
|
+
}
|
|
81
|
+
function paintImageModel(model, paintContext) {
|
|
82
|
+
const { image, placement, visual } = model;
|
|
83
|
+
const { box, sourceCrop } = placement;
|
|
84
|
+
const hasFinitePositiveBox = Number.isFinite(box.x) && Number.isFinite(box.y) && Number.isFinite(box.width) && Number.isFinite(box.height) && box.width > 1e-6 && box.height > 1e-6;
|
|
85
|
+
const externalPlaceholders = [...image.kind === "external" ? [{
|
|
86
|
+
...model.authorId === void 0 ? {} : { id: model.authorId },
|
|
87
|
+
path: paintContext.path,
|
|
88
|
+
url: image.externalUrl
|
|
89
|
+
}] : [], ...visual.fill.kind === "image" && visual.fill.source.kind === "external" ? [{
|
|
90
|
+
...model.authorId === void 0 ? {} : { id: model.authorId },
|
|
91
|
+
path: paintContext.path,
|
|
92
|
+
url: visual.fill.source.externalUrl
|
|
93
|
+
}] : []];
|
|
94
|
+
if (!hasFinitePositiveBox) return {
|
|
95
|
+
svg: "",
|
|
96
|
+
...externalPlaceholders.length === 0 ? {} : { placeholders: externalPlaceholders }
|
|
97
|
+
};
|
|
98
|
+
if (image.kind === "external") {
|
|
99
|
+
const evaluated = evaluateGeometry(visual.geometry, box);
|
|
100
|
+
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("");
|
|
101
|
+
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("") : "";
|
|
102
|
+
return {
|
|
103
|
+
svg: `<g transform="${visualSvgTransform(visual)}">${placeholderShapes}${borderElements}</g>`,
|
|
104
|
+
placeholders: [{
|
|
105
|
+
...model.authorId === void 0 ? {} : { id: model.authorId },
|
|
106
|
+
path: paintContext.path,
|
|
107
|
+
url: image.externalUrl
|
|
108
|
+
}, ...visual.fill.kind === "image" && visual.fill.source.kind === "external" ? [{
|
|
109
|
+
...model.authorId === void 0 ? {} : { id: model.authorId },
|
|
110
|
+
path: paintContext.path,
|
|
111
|
+
url: visual.fill.source.externalUrl
|
|
112
|
+
}] : []]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
let pngBytes;
|
|
116
|
+
try {
|
|
117
|
+
pngBytes = decodeImageToPngBytes(image);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (error instanceof CapabilityError) throw new CapabilityError(error.code, error.message, error.path, {
|
|
120
|
+
...error.details,
|
|
121
|
+
field: "src"
|
|
122
|
+
});
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
const leftCrop = roundCropFraction(sourceCrop.l);
|
|
126
|
+
const topCrop = roundCropFraction(sourceCrop.t);
|
|
127
|
+
const rightCrop = roundCropFraction(sourceCrop.r);
|
|
128
|
+
const bottomCrop = roundCropFraction(sourceCrop.b);
|
|
129
|
+
const widthFactor = 1 - leftCrop - rightCrop;
|
|
130
|
+
const heightFactor = 1 - topCrop - bottomCrop;
|
|
131
|
+
const prefix = `img-s${paintContext.slideNumber}-o${paintContext.objectId}`;
|
|
132
|
+
const defs = [];
|
|
133
|
+
const evaluated = evaluateGeometry(visual.geometry, box);
|
|
134
|
+
const fillablePaths = evaluated.paths.filter((pathItem) => pathItem.fillMode !== "none" && pathItem.d !== "");
|
|
135
|
+
let backgroundElements = "";
|
|
136
|
+
if (visual.fill.kind !== "none" && fillablePaths.length > 0) {
|
|
137
|
+
let fillAttr = "fill=\"none\"";
|
|
138
|
+
if (visual.fill.kind === "solid") fillAttr = `fill="#${visual.fill.color.hex}" fill-opacity="${roundSvgNumber(visual.fill.color.alpha ?? 1)}"`;
|
|
139
|
+
else if (visual.fill.kind === "linear-gradient" || visual.fill.kind === "radial-gradient") {
|
|
140
|
+
const bgDefId = `${prefix}-bg`;
|
|
141
|
+
defs.push(gradientDefSvg(bgDefId, visual.fill));
|
|
142
|
+
fillAttr = `fill="url(#${bgDefId})"`;
|
|
143
|
+
} else if (visual.fill.kind === "image") {
|
|
144
|
+
const bgDefId = `${prefix}-bg`;
|
|
145
|
+
const patternSvg = paintImageFillSvg(visual.fill, bgDefId, box, paintContext.registerRasterResource);
|
|
146
|
+
if (patternSvg !== "") {
|
|
147
|
+
defs.push(patternSvg);
|
|
148
|
+
fillAttr = `fill="url(#${bgDefId})"`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
backgroundElements = fillablePaths.map((pathItem) => `<path d="${pathItem.d}" ${fillAttr} stroke="none" stroke-width="0"/>`).join("");
|
|
152
|
+
}
|
|
153
|
+
const opacity = visual.opacity ?? 1;
|
|
154
|
+
let imageElement = "";
|
|
155
|
+
if (widthFactor > 1e-6 && heightFactor > 1e-6 && fillablePaths.length > 0) {
|
|
156
|
+
const imgWidth = box.width / widthFactor;
|
|
157
|
+
const imgHeight = box.height / heightFactor;
|
|
158
|
+
const imgX = box.x - leftCrop * imgWidth;
|
|
159
|
+
const imgY = box.y - topCrop * imgHeight;
|
|
160
|
+
if (Number.isFinite(imgX) && Number.isFinite(imgY) && Number.isFinite(imgWidth) && Number.isFinite(imgHeight) && imgWidth > 1e-6 && imgHeight > 1e-6) {
|
|
161
|
+
const clipId = `${prefix}-clip`;
|
|
162
|
+
const clipMarkup = fillablePaths.map((pathItem) => `<path d="${pathItem.d}"/>`).join("");
|
|
163
|
+
defs.push(`<clipPath id="${clipId}" clipPathUnits="userSpaceOnUse">${clipMarkup}</clipPath>`);
|
|
164
|
+
const opacityAttr = opacity === 1 ? "" : ` opacity="${roundSvgNumber(opacity)}"`;
|
|
165
|
+
const href = paintContext.registerRasterResource !== void 0 ? paintContext.registerRasterResource({
|
|
166
|
+
contentType: "image/png",
|
|
167
|
+
bytes: pngBytes
|
|
168
|
+
}) : `data:image/png;base64,${Buffer.from(pngBytes).toString("base64")}`;
|
|
169
|
+
imageElement = `<image clip-path="url(#${clipId})" x="${roundSvgNumber(imgX)}" y="${roundSvgNumber(imgY)}" width="${roundSvgNumber(imgWidth)}" height="${roundSvgNumber(imgHeight)}" preserveAspectRatio="none"${opacityAttr} href="${href}"/>`;
|
|
170
|
+
if (visual.softEdge !== void 0 && visual.softEdge > 0) {
|
|
171
|
+
const r = visual.softEdge;
|
|
172
|
+
const minSide = Math.min(box.width, box.height);
|
|
173
|
+
const borderPad = visual.border === void 0 ? 0 : visual.border.width;
|
|
174
|
+
const pad = Math.ceil(r * 2 + borderPad + 8);
|
|
175
|
+
const maskX = roundSvgNumber(box.x - pad);
|
|
176
|
+
const maskY = roundSvgNumber(box.y - pad);
|
|
177
|
+
const maskW = roundSvgNumber(box.width + pad * 2);
|
|
178
|
+
const maskH = roundSvgNumber(box.height + pad * 2);
|
|
179
|
+
const blurId = `${prefix}-soft-blur`;
|
|
180
|
+
const maskId = `${prefix}-soft-mask`;
|
|
181
|
+
const innerStrokeWidth = r >= minSide / 2 ? 0 : Math.min(r, minSide * .45);
|
|
182
|
+
const maskAttrs = innerStrokeWidth > 0 ? `fill="white" stroke="black" stroke-width="${roundSvgNumber(innerStrokeWidth)}" filter="url(#${blurId})"` : `fill="white" stroke="none" filter="url(#${blurId})"`;
|
|
183
|
+
const maskShapes = fillablePaths.map((pathItem) => `<path d="${pathItem.d}" ${maskAttrs}/>`).join("");
|
|
184
|
+
defs.push(`<filter id="${blurId}" filterUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}"><feGaussianBlur stdDeviation="${roundSvgNumber(r / 2)}"/></filter>`);
|
|
185
|
+
defs.push(`<mask id="${maskId}" maskUnits="userSpaceOnUse" x="${maskX}" y="${maskY}" width="${maskW}" height="${maskH}">${maskShapes}</mask>`);
|
|
186
|
+
imageElement = `<g mask="url(#${maskId})">${imageElement}</g>`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
let borderElements = "";
|
|
191
|
+
if (visual.border !== void 0) {
|
|
192
|
+
const strokeAttr = borderStrokeAttributes(visual.border);
|
|
193
|
+
borderElements = evaluated.paths.filter((pathItem) => pathItem.stroke && pathItem.d !== "").map((pathItem) => `<path d="${pathItem.d}" fill="none" ${strokeAttr}/>`).join("");
|
|
194
|
+
}
|
|
195
|
+
let layer = `<g transform="${visualSvgTransform(visual)}">${backgroundElements}${imageElement}${borderElements}</g>`;
|
|
196
|
+
if (visual.boxShadow !== void 0) {
|
|
197
|
+
const shadow = visual.boxShadow;
|
|
198
|
+
const cx = box.x + box.width / 2;
|
|
199
|
+
const cy = box.y + box.height / 2;
|
|
200
|
+
const halfDiag = Math.hypot(box.width, box.height) / 2;
|
|
201
|
+
const rad = shadow.angle * Math.PI / 180;
|
|
202
|
+
const dx = shadow.distance * Math.cos(rad);
|
|
203
|
+
const dy = shadow.distance * Math.sin(rad);
|
|
204
|
+
const sigma = shadow.blur / 2;
|
|
205
|
+
const borderPad = visual.border === void 0 ? 0 : visual.border.width;
|
|
206
|
+
const pad = shadow.blur * 3 + Math.abs(dx) + Math.abs(dy) + borderPad + 16;
|
|
207
|
+
const minX = roundSvgNumber(cx - halfDiag - pad);
|
|
208
|
+
const minY = roundSvgNumber(cy - halfDiag - pad);
|
|
209
|
+
const filterSize = roundSvgNumber((halfDiag + pad) * 2);
|
|
210
|
+
const shadowId = `${prefix}-shadow`;
|
|
211
|
+
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>`);
|
|
212
|
+
layer = `<g filter="url(#${shadowId})">${layer}</g>`;
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
svg: `${defs.length > 0 ? `<defs>${defs.join("")}</defs>` : ""}${layer}`,
|
|
216
|
+
...visual.fill.kind === "image" && visual.fill.source.kind === "external" ? { placeholders: [{
|
|
217
|
+
...model.authorId === void 0 ? {} : { id: model.authorId },
|
|
218
|
+
path: paintContext.path,
|
|
219
|
+
url: visual.fill.source.externalUrl
|
|
220
|
+
}] } : {}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** Shared image placement calculation for native OOXML output and static preview. */
|
|
224
|
+
function imagePlacement(image, fit, crop, allocated) {
|
|
225
|
+
const { width, height } = allocated;
|
|
226
|
+
const box = { ...allocated };
|
|
227
|
+
let l = crop?.l ?? 0;
|
|
228
|
+
let t = crop?.t ?? 0;
|
|
229
|
+
let r = crop?.r ?? 0;
|
|
230
|
+
let b = crop?.b ?? 0;
|
|
231
|
+
if (crop === void 0 && image.width !== void 0 && image.height !== void 0) {
|
|
232
|
+
if (fit === "cover") {
|
|
233
|
+
const imageRatio = image.width / image.height;
|
|
234
|
+
const boxRatio = width / height;
|
|
235
|
+
if (imageRatio > boxRatio) {
|
|
236
|
+
const excess = (1 - boxRatio / imageRatio) / 2;
|
|
237
|
+
l = excess;
|
|
238
|
+
r = excess;
|
|
239
|
+
} else if (imageRatio < boxRatio) {
|
|
240
|
+
const excess = (1 - imageRatio / boxRatio) / 2;
|
|
241
|
+
t = excess;
|
|
242
|
+
b = excess;
|
|
243
|
+
}
|
|
244
|
+
} else if (fit === "contain") {
|
|
245
|
+
const imageRatio = image.width / image.height;
|
|
246
|
+
const boxRatio = width / height;
|
|
247
|
+
if (imageRatio > boxRatio) {
|
|
248
|
+
const fittedHeight = width / imageRatio;
|
|
249
|
+
box.y += (height - fittedHeight) / 2;
|
|
250
|
+
box.height = fittedHeight;
|
|
251
|
+
} else if (imageRatio < boxRatio) {
|
|
252
|
+
const fittedWidth = height * imageRatio;
|
|
253
|
+
box.x += (width - fittedWidth) / 2;
|
|
254
|
+
box.width = fittedWidth;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
box.width = dimension(box.width, "width");
|
|
259
|
+
box.height = dimension(box.height, "height");
|
|
260
|
+
return {
|
|
261
|
+
box,
|
|
262
|
+
sourceCrop: {
|
|
263
|
+
l,
|
|
264
|
+
t,
|
|
265
|
+
r,
|
|
266
|
+
b
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const imageCompatiblePlaceholderRoles = /* @__PURE__ */ new Set([
|
|
271
|
+
"pic",
|
|
272
|
+
"clipArt",
|
|
273
|
+
"obj"
|
|
274
|
+
]);
|
|
275
|
+
const maximumShapeExtentEmu = 2147483647;
|
|
276
|
+
function isRecord(value) {
|
|
277
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
278
|
+
}
|
|
279
|
+
function dimension(value, name, fallback) {
|
|
280
|
+
const actual = value === void 0 ? fallback : value;
|
|
281
|
+
const isExtent = name === "width" || name === "height";
|
|
282
|
+
if (isExtent && typeof actual === "number" && Number.isFinite(actual)) {
|
|
283
|
+
if (actual === 0 || pxToEmu(actual) === 0) throw new CapabilityError("invalid-coordinate", `Computed ${name} is 0px; ${name} must be greater than 0px`);
|
|
284
|
+
if (actual < 0 || pxToEmu(actual) < 1) throw new CapabilityError("invalid-coordinate", `Computed ${name} is ${actual}px; ${name} must be greater than 0px`);
|
|
285
|
+
}
|
|
286
|
+
const parsed = isExtent ? imageExtentValueSchema.safeParse(actual) : imageCoordinateValueSchema.safeParse(actual);
|
|
287
|
+
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`);
|
|
288
|
+
if (isExtent) {
|
|
289
|
+
const extentEmu = pxToEmu(parsed.data);
|
|
290
|
+
if (extentEmu < 1 || extentEmu > maximumShapeExtentEmu) throw new CapabilityError("invalid-coordinate", `${name} must convert to an EMU value between 1 and ${maximumShapeExtentEmu} inclusive`);
|
|
291
|
+
}
|
|
292
|
+
return parsed.data;
|
|
293
|
+
}
|
|
294
|
+
function parseCropValues(value, path) {
|
|
295
|
+
if (value === void 0) return void 0;
|
|
296
|
+
const parsed = imageCropInputSchema.safeParse(value);
|
|
297
|
+
if (!parsed.success) {
|
|
298
|
+
const issue = parsed.error.issues[0];
|
|
299
|
+
if (issue?.code === "unrecognized_keys") throw new CapabilityError("unknown-parameter", `crop contains unknown parameter ${issue.keys[0]}`, path);
|
|
300
|
+
throw new CapabilityError("invalid-crop", issue?.message ?? "crop must be a four-sided fraction object", path);
|
|
301
|
+
}
|
|
302
|
+
const { left, top, right, bottom } = parsed.data;
|
|
303
|
+
return {
|
|
304
|
+
...left === void 0 ? {} : { l: left },
|
|
305
|
+
...top === void 0 ? {} : { t: top },
|
|
306
|
+
...right === void 0 ? {} : { r: right },
|
|
307
|
+
...bottom === void 0 ? {} : { b: bottom }
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function readImageSource(source) {
|
|
311
|
+
const parsed = imageSourceSchema.safeParse(source);
|
|
312
|
+
if (!parsed.success) throw new CapabilityError("invalid-image-source", "Image.src must be a file path, file URL, image bytes, or externalUrl descriptor");
|
|
313
|
+
if (typeof parsed.data === "object" && parsed.data !== null && !(parsed.data instanceof Uint8Array) && !(parsed.data instanceof URL)) {
|
|
314
|
+
const externalParsed = externalImageSourceSchema.safeParse(parsed.data);
|
|
315
|
+
if (externalParsed.success) return {
|
|
316
|
+
kind: "external",
|
|
317
|
+
externalUrl: externalParsed.data.externalUrl
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
kind: "embedded",
|
|
322
|
+
...readImage(parsed.data)
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `image`. */
|
|
326
|
+
const imageMechanism = defineCanvasMechanism({
|
|
327
|
+
key: "image",
|
|
328
|
+
role: "canvas",
|
|
329
|
+
emit: emitImageModel,
|
|
330
|
+
paint: paintImageModel,
|
|
331
|
+
import: imageImportHandler
|
|
332
|
+
});
|
|
333
|
+
/** Typed native canvas mechanism connecting emit, paint, and import for `picture-placeholder`. */
|
|
334
|
+
const picturePlaceholderMechanism = defineCanvasMechanism({
|
|
335
|
+
key: "picture-placeholder",
|
|
336
|
+
role: "canvas",
|
|
337
|
+
emit: emitImageModel,
|
|
338
|
+
paint: paintImageModel,
|
|
339
|
+
import: picturePlaceholderImportHandler
|
|
340
|
+
});
|
|
341
|
+
/** Image module reads and validates formal resources, encapsulates bound state, and emits native picture objects. */
|
|
342
|
+
const imageCapability = {
|
|
343
|
+
declaration: "image",
|
|
344
|
+
codegen: imageCodegen,
|
|
345
|
+
mechanisms: [imageMechanism, picturePlaceholderMechanism],
|
|
346
|
+
bind(input, context) {
|
|
347
|
+
const placeholder = context.placeholder;
|
|
348
|
+
if (placeholder !== void 0) {
|
|
349
|
+
const role = placeholder.layoutPlaceholder?.type ?? placeholder.nativeRef.type;
|
|
350
|
+
if (!imageCompatiblePlaceholderRoles.has(role)) throw new CapabilityError("incompatible-placeholder-content", `Image cannot be bound to ${role} placeholder`);
|
|
351
|
+
}
|
|
352
|
+
const unknown = Object.keys(input.props).find((key) => !imageAllowedParameters.includes(key));
|
|
353
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-parameter", `Image contains unsupported parameter ${unknown}`);
|
|
354
|
+
if (input.children.some((child) => "props" in child || child.text.trim() !== "")) throw new CapabilityError("unsupported-children", "Image does not accept children");
|
|
355
|
+
const requestedName = parseOptionalName(input.props["name"]);
|
|
356
|
+
const morphKey = parseMorphKey(input.props["morphKey"]);
|
|
357
|
+
const link = parseLinkTarget(input.props["link"]);
|
|
358
|
+
const altParsed = imageAltSchema.safeParse(input.props["alt"]);
|
|
359
|
+
if (!altParsed.success) throw new CapabilityError("invalid-parameter", "alt must be a string");
|
|
360
|
+
const altValue = altParsed.data;
|
|
361
|
+
const allowedStyleKeys = new Set(imageStyleKeys);
|
|
362
|
+
const contract = parseCapabilityLayoutContract({
|
|
363
|
+
nativeKind: "pic",
|
|
364
|
+
props: input.props,
|
|
365
|
+
allowedStyleKeys,
|
|
366
|
+
allowPadding: false,
|
|
367
|
+
path: context.path
|
|
368
|
+
});
|
|
369
|
+
const rawSlideStyle = isRecord(input.props["style"]) ? input.props["style"] : void 0;
|
|
370
|
+
const imageStyle = placeholder !== void 0 ? resolvePlaceholderVisualStyle(placeholder, rawSlideStyle) : rawSlideStyle !== void 0 ? { ...rawSlideStyle } : {};
|
|
371
|
+
const hasLocalFill = hasLocalDeclaration(rawSlideStyle, "background");
|
|
372
|
+
const requestedFit = input.props["fit"];
|
|
373
|
+
let fit = "fill";
|
|
374
|
+
if (requestedFit !== void 0) {
|
|
375
|
+
const parsedFit = imageFitSchema.safeParse(requestedFit);
|
|
376
|
+
if (!parsedFit.success) throw new CapabilityError("unsupported-fit", "fit must be fill, cover, or contain");
|
|
377
|
+
fit = parsedFit.data;
|
|
378
|
+
}
|
|
379
|
+
const crop = parseCropValues(input.props["crop"]);
|
|
380
|
+
const image = readImageSource(input.props["src"]);
|
|
381
|
+
const geometry = input.props["geometry"];
|
|
382
|
+
resolveVisualModel({
|
|
383
|
+
theme: context.theme,
|
|
384
|
+
style: imageStyle,
|
|
385
|
+
box: {
|
|
386
|
+
x: 0,
|
|
387
|
+
y: 0,
|
|
388
|
+
width: 100,
|
|
389
|
+
height: 100
|
|
390
|
+
},
|
|
391
|
+
...geometry !== void 0 ? { geometry } : {},
|
|
392
|
+
image: true
|
|
393
|
+
});
|
|
394
|
+
const placeholderGeometry = placeholder === void 0 ? void 0 : resolvePlaceholderGeometry(placeholder, input.props);
|
|
395
|
+
const hasLocalVisualOverride = geometry !== void 0 || [...imageVisualStyleKeys].some((key) => key !== "opacity" && hasLocalDeclaration(rawSlideStyle, key));
|
|
396
|
+
const declaredX = placeholderGeometry?.x;
|
|
397
|
+
const declaredY = placeholderGeometry?.y;
|
|
398
|
+
const requestedWidth = placeholderGeometry?.width ?? contract.explicitPixelSize?.width;
|
|
399
|
+
const requestedHeight = placeholderGeometry?.height ?? contract.explicitPixelSize?.height;
|
|
400
|
+
const hasFixedWidth = placeholderGeometry?.width !== void 0 && placeholderGeometry.width !== "auto" || (contract.fixedAxes?.width ?? false);
|
|
401
|
+
const hasFixedHeight = placeholderGeometry?.height !== void 0 && placeholderGeometry.height !== "auto" || (contract.fixedAxes?.height ?? false);
|
|
402
|
+
const authorId = typeof input.props["id"] === "string" ? input.props["id"] : void 0;
|
|
403
|
+
const motionProps = pickMotionProps(input.props);
|
|
404
|
+
const native = {
|
|
405
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
406
|
+
...requestedName === void 0 ? {} : { hasExplicitName: true },
|
|
407
|
+
...link === void 0 ? {} : { link }
|
|
408
|
+
};
|
|
409
|
+
return {
|
|
410
|
+
contract,
|
|
411
|
+
...morphKey !== void 0 || requestedName !== void 0 || link !== void 0 ? { native } : {},
|
|
412
|
+
measureLayout(request) {
|
|
413
|
+
const declaredWidth = typeof requestedWidth === "number" ? requestedWidth : void 0;
|
|
414
|
+
const declaredHeight = typeof requestedHeight === "number" ? requestedHeight : void 0;
|
|
415
|
+
if (image.kind === "external") {
|
|
416
|
+
if (declaredWidth !== void 0 && declaredHeight !== void 0) return {
|
|
417
|
+
width: declaredWidth,
|
|
418
|
+
height: declaredHeight,
|
|
419
|
+
minContentWidth: hasFixedWidth ? 0 : declaredWidth,
|
|
420
|
+
minContentHeight: hasFixedHeight ? 0 : declaredHeight
|
|
421
|
+
};
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const width = declaredWidth ?? (declaredHeight !== void 0 ? declaredHeight * image.width / image.height : request.widthMode === "exactly" && request.availableWidth !== void 0 ? request.availableWidth : Math.min(image.width, request.availableWidth ?? image.width));
|
|
425
|
+
const height = declaredHeight ?? width * image.height / image.width;
|
|
426
|
+
const intrinsicMinWidth = declaredHeight !== void 0 ? declaredHeight * image.width / image.height : image.width;
|
|
427
|
+
const intrinsicMinHeight = declaredWidth !== void 0 ? declaredWidth * image.height / image.width : image.height;
|
|
428
|
+
return {
|
|
429
|
+
width,
|
|
430
|
+
height,
|
|
431
|
+
minContentWidth: hasFixedWidth ? 0 : intrinsicMinWidth,
|
|
432
|
+
minContentHeight: hasFixedHeight ? 0 : intrinsicMinHeight
|
|
433
|
+
};
|
|
434
|
+
},
|
|
435
|
+
resolve(resolveContext) {
|
|
436
|
+
const x = dimension(resolveContext.layoutBox?.x ?? declaredX, "x", 0);
|
|
437
|
+
const y = dimension(resolveContext.layoutBox?.y ?? declaredY, "y", 0);
|
|
438
|
+
let width;
|
|
439
|
+
let height;
|
|
440
|
+
if (resolveContext.layoutBox !== void 0) {
|
|
441
|
+
width = dimension(resolveContext.layoutBox.width, "width");
|
|
442
|
+
height = dimension(resolveContext.layoutBox.height, "height");
|
|
443
|
+
} else if (image.kind === "external") {
|
|
444
|
+
width = dimension(requestedWidth, "width");
|
|
445
|
+
height = dimension(requestedHeight, "height");
|
|
446
|
+
} else if (requestedWidth === void 0 && requestedHeight === void 0) {
|
|
447
|
+
width = image.width;
|
|
448
|
+
height = image.height;
|
|
449
|
+
} else if (requestedWidth === void 0) {
|
|
450
|
+
height = dimension(requestedHeight, "height");
|
|
451
|
+
width = height * image.width / image.height;
|
|
452
|
+
} else if (requestedHeight === void 0) {
|
|
453
|
+
width = dimension(requestedWidth, "width");
|
|
454
|
+
height = width * image.height / image.width;
|
|
455
|
+
} else {
|
|
456
|
+
width = dimension(requestedWidth, "width");
|
|
457
|
+
height = dimension(requestedHeight, "height");
|
|
458
|
+
}
|
|
459
|
+
width = dimension(width, "width");
|
|
460
|
+
height = dimension(height, "height");
|
|
461
|
+
const placement = imagePlacement(image.kind === "external" ? {} : image, fit, crop, {
|
|
462
|
+
x,
|
|
463
|
+
y,
|
|
464
|
+
width,
|
|
465
|
+
height
|
|
466
|
+
});
|
|
467
|
+
const { box } = placement;
|
|
468
|
+
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;
|
|
469
|
+
const resolvedVisual = resolveVisualModel({
|
|
470
|
+
theme: resolveContext.theme,
|
|
471
|
+
style: imageStyle,
|
|
472
|
+
box,
|
|
473
|
+
...geometry === void 0 ? {} : { geometry },
|
|
474
|
+
image: true
|
|
475
|
+
});
|
|
476
|
+
const name = resolveContext.morphName ?? requestedName ?? placeholder?.layoutPlaceholder?.name ?? `Image ${resolveContext.id - 1}`;
|
|
477
|
+
try {
|
|
478
|
+
assertXml10Characters(name);
|
|
479
|
+
if (altValue !== void 0) assertXml10Characters(altValue);
|
|
480
|
+
} catch {
|
|
481
|
+
throw new CapabilityError("invalid-xml-character", "Image.name or alt contains characters not allowed in XML 1.0");
|
|
482
|
+
}
|
|
483
|
+
const angle = resolvedVisual.rotate;
|
|
484
|
+
const annotations = motionAnnotations(motionProps, {
|
|
485
|
+
kind: "image",
|
|
486
|
+
name,
|
|
487
|
+
...authorId === void 0 ? {} : { authorId },
|
|
488
|
+
textBody: false,
|
|
489
|
+
filled: resolvedVisual.fill.kind !== "none",
|
|
490
|
+
box,
|
|
491
|
+
rotationDegrees: angle,
|
|
492
|
+
hasBackground: resolvedVisual.fill.kind !== "none" || resolvedVisual.border !== void 0
|
|
493
|
+
});
|
|
494
|
+
const omitSpPrTransform = placeholder !== void 0 && placeholderGeometry?.hasLocalBoxOverride !== true && !hasLocalVisualOverride && !boxChangedByFit;
|
|
495
|
+
const model = {
|
|
496
|
+
image,
|
|
497
|
+
placement,
|
|
498
|
+
visual: resolvedVisual,
|
|
499
|
+
name,
|
|
500
|
+
...authorId === void 0 ? {} : { authorId },
|
|
501
|
+
...altValue === void 0 ? {} : { alt: altValue },
|
|
502
|
+
...placeholder === void 0 ? {} : { placeholder: {
|
|
503
|
+
nativeRef: placeholder.nativeRef,
|
|
504
|
+
omitSpPrTransform,
|
|
505
|
+
hasLocalFill
|
|
506
|
+
} }
|
|
507
|
+
};
|
|
508
|
+
const mechanism = placeholder === void 0 ? imageMechanism : picturePlaceholderMechanism;
|
|
509
|
+
const imageObservation = image.kind === "external" ? Object.freeze({
|
|
510
|
+
kind: "external",
|
|
511
|
+
...authorId === void 0 ? {} : { id: authorId },
|
|
512
|
+
path: resolveContext.path,
|
|
513
|
+
url: image.externalUrl,
|
|
514
|
+
placeholder: Object.freeze({
|
|
515
|
+
...authorId === void 0 ? {} : { id: authorId },
|
|
516
|
+
path: resolveContext.path,
|
|
517
|
+
url: image.externalUrl
|
|
518
|
+
})
|
|
519
|
+
}) : Object.freeze({
|
|
520
|
+
kind: "embedded",
|
|
521
|
+
contentType: image.contentType,
|
|
522
|
+
width: image.width,
|
|
523
|
+
height: image.height
|
|
524
|
+
});
|
|
525
|
+
return {
|
|
526
|
+
observation: {
|
|
527
|
+
id: resolveContext.id,
|
|
528
|
+
kind: "image",
|
|
529
|
+
name,
|
|
530
|
+
box,
|
|
531
|
+
image: imageObservation
|
|
532
|
+
},
|
|
533
|
+
transform: {
|
|
534
|
+
box,
|
|
535
|
+
angle,
|
|
536
|
+
flipH: resolvedVisual.flipH,
|
|
537
|
+
flipV: resolvedVisual.flipV
|
|
538
|
+
},
|
|
539
|
+
extensions: [],
|
|
540
|
+
...annotations.length === 0 ? {} : { annotations },
|
|
541
|
+
emit(emitContext) {
|
|
542
|
+
return mechanism.emit(model, emitContext);
|
|
543
|
+
},
|
|
544
|
+
paint(paintContext) {
|
|
545
|
+
return mechanism.paint(model, paintContext);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
export { imageCapability, imageMechanism, picturePlaceholderMechanism };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readInternalDeclarationProps } from "../../../core/dist/document-internals.js";
|
|
2
|
+
import "../../../codegen/dist/index.js";
|
|
3
|
+
import "../../../core/dist/capability.js";
|
|
4
|
+
import { CommonNode } from "../../../core/dist/document.js";
|
|
5
|
+
import { lineStrokeValueSchema } from "../shared/visual.js";
|
|
6
|
+
import { defineObjectCodegen, expr } from "../../../codegen/dist/types.js";
|
|
7
|
+
import { motionPropsShape } from "../motion/motion-schemas.js";
|
|
8
|
+
import { lineAdjustSchema, lineAllowedPropKeyList, lineEndpointSchema, lineRoutingSchema, lineStyleSchema } from "./line-declaration.js";
|
|
9
|
+
// ../capabilities/dist/line/line-codegen.js
|
|
10
|
+
const objectMotionPropKeys = new Set(Object.keys(motionPropsShape));
|
|
11
|
+
const lineAllowedPropKeys = new Set(lineAllowedPropKeyList);
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function isPlainRecord(value) {
|
|
16
|
+
if (!isRecord(value)) return false;
|
|
17
|
+
const proto = Object.getPrototypeOf(value);
|
|
18
|
+
return proto === Object.prototype || proto === null;
|
|
19
|
+
}
|
|
20
|
+
function assertNoLineChildren(node, ctx) {
|
|
21
|
+
for (const child of node.children) {
|
|
22
|
+
if (child instanceof CommonNode) ctx.fail("invalid-document", "Line does not accept child declarations");
|
|
23
|
+
const leaf = child;
|
|
24
|
+
if (leaf.type === "#text" && leaf.text.trim() !== "") ctx.fail("invalid-document", "Line does not accept text children");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function serializeLineStyleProp(style, ctx) {
|
|
28
|
+
if (!isPlainRecord(style)) ctx.fail("unexpressible-value", "Line.style must be a plain object", "@style");
|
|
29
|
+
const parsed = lineStyleSchema.safeParse(style);
|
|
30
|
+
if (!parsed.success) {
|
|
31
|
+
const issue = parsed.error.issues[0];
|
|
32
|
+
const issuePath = issue !== void 0 && issue.path.length > 0 ? `@style.${issue.path.join(".")}` : "@style";
|
|
33
|
+
ctx.fail("unexpressible-value", issue?.message ?? "Line.style cannot be expressed", issuePath);
|
|
34
|
+
}
|
|
35
|
+
const entries = [];
|
|
36
|
+
for (const [key, entryValue] of Object.entries(style)) {
|
|
37
|
+
if (entryValue === void 0) continue;
|
|
38
|
+
entries.push([key, entryValue]);
|
|
39
|
+
}
|
|
40
|
+
if (entries.length === 0) return void 0;
|
|
41
|
+
return expr(ctx.formatProps(entries));
|
|
42
|
+
}
|
|
43
|
+
function validateLinePropValue(key, value, ctx) {
|
|
44
|
+
if (key === "routing" && !lineRoutingSchema.safeParse(value).success) ctx.fail("unexpressible-value", "Line.routing cannot be expressed", `@${key}`);
|
|
45
|
+
if (key === "adjust" && !lineAdjustSchema.safeParse(value).success) ctx.fail("unexpressible-value", "Line.adjust cannot be expressed", `@${key}`);
|
|
46
|
+
if (key === "stroke" && !lineStrokeValueSchema.safeParse(value).success) ctx.fail("unexpressible-value", "Line.stroke cannot be expressed", `@${key}`);
|
|
47
|
+
if ((key === "from" || key === "to") && !lineEndpointSchema.safeParse(value).success) ctx.fail("unexpressible-value", `Line.${key} cannot be expressed`, `@${key}`);
|
|
48
|
+
}
|
|
49
|
+
function collectLineProps(node, ctx) {
|
|
50
|
+
const props = readInternalDeclarationProps(node);
|
|
51
|
+
const extra = ctx.emitObjectExtraProps(props);
|
|
52
|
+
const entries = [];
|
|
53
|
+
for (const [key, value] of Object.entries(props)) {
|
|
54
|
+
if (value === void 0) continue;
|
|
55
|
+
if (!lineAllowedPropKeys.has(key)) ctx.fail("invalid-document", `line declaration does not support property ${JSON.stringify(key)}`, `@${key}`);
|
|
56
|
+
if (objectMotionPropKeys.has(key)) {
|
|
57
|
+
if (Object.hasOwn(extra, key)) entries.push([key, extra[key]]);
|
|
58
|
+
else ctx.fail("unexpressible-value", `Object property ${JSON.stringify(key)} requires motion codegen support`, `@${key}`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (key === "style") {
|
|
62
|
+
const styleExpr = serializeLineStyleProp(value, ctx);
|
|
63
|
+
if (styleExpr !== void 0) entries.push([key, styleExpr]);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
validateLinePropValue(key, value, ctx);
|
|
67
|
+
entries.push([key, value]);
|
|
68
|
+
}
|
|
69
|
+
return entries;
|
|
70
|
+
}
|
|
71
|
+
function emitLineVanilla(node, ctx) {
|
|
72
|
+
assertNoLineChildren(node, ctx);
|
|
73
|
+
const callee = ctx.useImport("line");
|
|
74
|
+
const propsEntries = collectLineProps(node, ctx);
|
|
75
|
+
const args = propsEntries.length === 0 ? [] : [ctx.formatProps(propsEntries)];
|
|
76
|
+
return ctx.formatVanillaCall(callee, args);
|
|
77
|
+
}
|
|
78
|
+
function emitLineReact(node, ctx) {
|
|
79
|
+
assertNoLineChildren(node, ctx);
|
|
80
|
+
const tag = ctx.useImport("Line");
|
|
81
|
+
const propsEntries = collectLineProps(node, ctx);
|
|
82
|
+
return ctx.formatJsxElement(tag, propsEntries);
|
|
83
|
+
}
|
|
84
|
+
/** Source codegen contribution for `line` declarations. */
|
|
85
|
+
const lineCodegen = defineObjectCodegen({ declarations: { line: {
|
|
86
|
+
emitVanilla: emitLineVanilla,
|
|
87
|
+
emitReact: emitLineReact
|
|
88
|
+
} } });
|
|
89
|
+
export { lineCodegen };
|