@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,260 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { textStyleFrom } from "../../../core/dist/theme.js";
|
|
3
|
+
import { parseLinkTarget } from "../../../core/dist/author-schemas.js";
|
|
4
|
+
import { parseCapabilityLayoutContract } from "../../../core/dist/layout.js";
|
|
5
|
+
import "../../../core/dist/capability.js";
|
|
6
|
+
import { pxToEmu, xmlEscape } from "../../../emit/dist/ooxml.js";
|
|
7
|
+
import "../../../emit/dist/index.js";
|
|
8
|
+
import "../../../import/dist/index.js";
|
|
9
|
+
import { defineCanvasMechanism } from "../../../import/dist/mechanism.js";
|
|
10
|
+
import { motionContainerAnnotations, pickMotionProps, validateMotionFlag } from "../motion/motion-api.js";
|
|
11
|
+
import { nativeLinkXml, parseMorphKey, parseOptionalName } from "../shared/identity.js";
|
|
12
|
+
import { groupCodegen } from "./group-codegen.js";
|
|
13
|
+
import { groupDeclarationPropsKeys, groupStyleKeys, groupTransformShape } from "./group-declaration.js";
|
|
14
|
+
import { groupImportHandler } from "./group-import.js";
|
|
15
|
+
import { groupXml } from "./group-xml.js";
|
|
16
|
+
// ../capabilities/dist/group/group.js
|
|
17
|
+
const allowedParameters = groupDeclarationPropsKeys;
|
|
18
|
+
const emuPerPixel = 9525;
|
|
19
|
+
const maximumGroupExtentEmu = 2147483647;
|
|
20
|
+
function motionMembers(objects) {
|
|
21
|
+
return objects.map((object) => ({
|
|
22
|
+
id: object.id,
|
|
23
|
+
kind: object.kind,
|
|
24
|
+
name: object.name,
|
|
25
|
+
...object.authorId === void 0 ? {} : { authorId: object.authorId },
|
|
26
|
+
...object.box === void 0 ? {} : { box: object.box },
|
|
27
|
+
...object.members === void 0 ? {} : { members: motionMembers(object.members) }
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
function bounds(members) {
|
|
31
|
+
if (members.length === 0) throw new CapabilityError("empty-group", "Group requires at least one native object member");
|
|
32
|
+
const memberBoxes = members.map((member) => {
|
|
33
|
+
const box = member.box;
|
|
34
|
+
if (box === void 0 || !Number.isFinite(box.x) || !Number.isFinite(box.y) || !Number.isFinite(box.width) || !Number.isFinite(box.height) || box.width < 0 || box.height < 0 || box.width === 0 && box.height === 0) throw new CapabilityError("member-without-geometry", `Group member ${member.name} is missing composable geometry bounds`);
|
|
35
|
+
const x = pxToEmu(box.x);
|
|
36
|
+
const y = pxToEmu(box.y);
|
|
37
|
+
return {
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
right: x + pxToEmu(box.width),
|
|
41
|
+
bottom: y + pxToEmu(box.height)
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
const x = Math.min(...memberBoxes.map((box) => box.x));
|
|
45
|
+
const y = Math.min(...memberBoxes.map((box) => box.y));
|
|
46
|
+
const right = Math.max(...memberBoxes.map((box) => box.right));
|
|
47
|
+
const bottom = Math.max(...memberBoxes.map((box) => box.bottom));
|
|
48
|
+
const width = right - x;
|
|
49
|
+
const height = bottom - y;
|
|
50
|
+
if (width < 1) throw new CapabilityError("invalid-group-geometry", "Computed Group width is 0px; width must be greater than 0px");
|
|
51
|
+
if (height < 1) throw new CapabilityError("invalid-group-geometry", "Computed Group height is 0px; height must be greater than 0px");
|
|
52
|
+
if (width > maximumGroupExtentEmu || height > maximumGroupExtentEmu) throw new CapabilityError("invalid-group-geometry", "Group member bounds exceed writable PresentationML dimensions");
|
|
53
|
+
return {
|
|
54
|
+
emu: {
|
|
55
|
+
x,
|
|
56
|
+
y,
|
|
57
|
+
width,
|
|
58
|
+
height
|
|
59
|
+
},
|
|
60
|
+
pixels: {
|
|
61
|
+
x: x / emuPerPixel,
|
|
62
|
+
y: y / emuPerPixel,
|
|
63
|
+
width: width / emuPerPixel,
|
|
64
|
+
height: height / emuPerPixel
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const groupAllowedStyleKeys = new Set(groupStyleKeys);
|
|
69
|
+
function roundSvgNumber(value) {
|
|
70
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
71
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
72
|
+
}
|
|
73
|
+
function emitGroupModel(model, emitContext) {
|
|
74
|
+
return { xml: groupXml(emitContext.id, model.escapedName, model.emu, emitContext.childrenXml, model.rotation, nativeLinkXml(emitContext.nativeLink), model.flipH, model.flipV) };
|
|
75
|
+
}
|
|
76
|
+
function paintGroupModel(model, paintContext) {
|
|
77
|
+
const childrenSvg = paintContext.childrenSvg ?? "";
|
|
78
|
+
const cxNum = model.box.x + model.box.width / 2;
|
|
79
|
+
const cyNum = model.box.y + model.box.height / 2;
|
|
80
|
+
const cx = roundSvgNumber(cxNum);
|
|
81
|
+
const cy = roundSvgNumber(cyNum);
|
|
82
|
+
return { svg: `<g transform="${model.flipH || model.flipV ? `translate(${cx} ${cy}) rotate(${roundSvgNumber(model.angle)}) scale(${model.flipH ? -1 : 1} ${model.flipV ? -1 : 1}) translate(${roundSvgNumber(-cxNum)} ${roundSvgNumber(-cyNum)})` : `rotate(${roundSvgNumber(model.angle)} ${cx} ${cy})`}">${childrenSvg}</g>` };
|
|
83
|
+
}
|
|
84
|
+
/** Native canvas mechanism for PresentationML `<p:grpSp>` native groups. */
|
|
85
|
+
const groupMechanism = defineCanvasMechanism({
|
|
86
|
+
key: "group",
|
|
87
|
+
role: "canvas",
|
|
88
|
+
emit: emitGroupModel,
|
|
89
|
+
paint: paintGroupModel,
|
|
90
|
+
import: groupImportHandler
|
|
91
|
+
});
|
|
92
|
+
/** Preserves members as native objects and writes group bounds according to final member geometry; layout participation uses generic container collaboration. */
|
|
93
|
+
const groupCapability = {
|
|
94
|
+
declaration: "group",
|
|
95
|
+
codegen: groupCodegen,
|
|
96
|
+
mechanisms: [groupMechanism],
|
|
97
|
+
bind(input, context) {
|
|
98
|
+
const unknown = Object.keys(input.props).find((key) => !allowedParameters.includes(key));
|
|
99
|
+
if (unknown !== void 0) throw new CapabilityError("unknown-parameter", `Group contains unsupported parameter ${unknown}`);
|
|
100
|
+
validateMotionFlag(input.props["motion"]);
|
|
101
|
+
const requestedName = parseOptionalName(input.props["name"]);
|
|
102
|
+
const morphKey = parseMorphKey(input.props["morphKey"]);
|
|
103
|
+
const link = parseLinkTarget(input.props["link"]);
|
|
104
|
+
const contract = parseCapabilityLayoutContract({
|
|
105
|
+
nativeKind: "grpSp",
|
|
106
|
+
props: input.props,
|
|
107
|
+
allowedStyleKeys: groupAllowedStyleKeys,
|
|
108
|
+
allowPadding: true,
|
|
109
|
+
isContainer: true,
|
|
110
|
+
path: context.path
|
|
111
|
+
});
|
|
112
|
+
const rawStyle = input.props["style"];
|
|
113
|
+
const styleRecord = typeof rawStyle === "object" && rawStyle !== null && !Array.isArray(rawStyle) ? rawStyle : {};
|
|
114
|
+
const rawRotation = styleRecord["rotate"];
|
|
115
|
+
if (rawRotation !== void 0 && !groupTransformShape.rotate.safeParse(rawRotation).success) throw new CapabilityError("invalid-visual-style", "rotate must be a finite angle");
|
|
116
|
+
const rotation = rawRotation;
|
|
117
|
+
const rawFlipH = styleRecord["flipH"];
|
|
118
|
+
if (rawFlipH !== void 0 && !groupTransformShape.flipH.safeParse(rawFlipH).success) throw new CapabilityError("invalid-visual-style", "flipH must be a boolean");
|
|
119
|
+
const rawFlipV = styleRecord["flipV"];
|
|
120
|
+
if (rawFlipV !== void 0 && !groupTransformShape.flipV.safeParse(rawFlipV).success) throw new CapabilityError("invalid-visual-style", "flipV must be a boolean");
|
|
121
|
+
const flipH = Boolean(rawFlipH);
|
|
122
|
+
const flipV = Boolean(rawFlipV);
|
|
123
|
+
const theme = context.theme.with(textStyleFrom(styleRecord));
|
|
124
|
+
const authorId = typeof input.props["id"] === "string" ? input.props["id"] : void 0;
|
|
125
|
+
const motionProps = pickMotionProps(input.props);
|
|
126
|
+
const container = {
|
|
127
|
+
children: input.children,
|
|
128
|
+
theme,
|
|
129
|
+
emitsObject: true,
|
|
130
|
+
childComposition: "members",
|
|
131
|
+
restrictsMemberContinuity: true,
|
|
132
|
+
observesLayout: false,
|
|
133
|
+
propagatesBaseline: false
|
|
134
|
+
};
|
|
135
|
+
const native = {
|
|
136
|
+
...morphKey === void 0 ? {} : { morphKey },
|
|
137
|
+
...requestedName === void 0 ? {} : { hasExplicitName: true },
|
|
138
|
+
...link === void 0 ? {} : { link }
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
contract,
|
|
142
|
+
container,
|
|
143
|
+
...morphKey !== void 0 || requestedName !== void 0 || link !== void 0 ? { native } : {},
|
|
144
|
+
resolve(resolveContext) {
|
|
145
|
+
const resolvedChildren = resolveContext.resolveChildren(input.children);
|
|
146
|
+
const geometry = bounds(resolvedChildren.objects);
|
|
147
|
+
const layoutBox = resolveContext.layoutBox;
|
|
148
|
+
const isPositioned = contract.positioned === true;
|
|
149
|
+
const fixedAxes = contract.fixedAxes ?? {
|
|
150
|
+
width: false,
|
|
151
|
+
height: false
|
|
152
|
+
};
|
|
153
|
+
const sizedAxes = resolveContext.layoutSizedAxes ?? fixedAxes;
|
|
154
|
+
const hasLayoutWidth = sizedAxes.width;
|
|
155
|
+
const hasLayoutHeight = sizedAxes.height;
|
|
156
|
+
let outputGeometry;
|
|
157
|
+
if (isPositioned) {
|
|
158
|
+
const memberBounds = geometry.pixels;
|
|
159
|
+
if (layoutBox !== void 0) {
|
|
160
|
+
const resolvedWidth = fixedAxes.width || hasLayoutWidth && layoutBox.width > 0 ? layoutBox.width : memberBounds.width > 0 ? Math.max(layoutBox.width, memberBounds.width, memberBounds.x + memberBounds.width - layoutBox.x) : layoutBox.width;
|
|
161
|
+
const resolvedHeight = fixedAxes.height || hasLayoutHeight && layoutBox.height > 0 ? layoutBox.height : memberBounds.height > 0 ? Math.max(layoutBox.height, memberBounds.height, memberBounds.y + memberBounds.height - layoutBox.y) : layoutBox.height;
|
|
162
|
+
outputGeometry = {
|
|
163
|
+
x: layoutBox.x,
|
|
164
|
+
y: layoutBox.y,
|
|
165
|
+
width: resolvedWidth,
|
|
166
|
+
height: resolvedHeight
|
|
167
|
+
};
|
|
168
|
+
} else outputGeometry = memberBounds;
|
|
169
|
+
} else {
|
|
170
|
+
const memberBounds = geometry.pixels;
|
|
171
|
+
const useLayoutWidth = fixedAxes.width || hasLayoutWidth && layoutBox !== void 0 && layoutBox.width > 0;
|
|
172
|
+
const useLayoutHeight = fixedAxes.height || hasLayoutHeight && layoutBox !== void 0 && layoutBox.height > 0;
|
|
173
|
+
if (layoutBox !== void 0 && useLayoutWidth && useLayoutHeight) outputGeometry = layoutBox;
|
|
174
|
+
else if (layoutBox !== void 0 && layoutBox.width > 0 && layoutBox.height > 0) {
|
|
175
|
+
const x = useLayoutWidth ? layoutBox.x : memberBounds.width > 0 ? Math.min(layoutBox.x, memberBounds.x) : layoutBox.x;
|
|
176
|
+
const y = useLayoutHeight ? layoutBox.y : memberBounds.height > 0 ? Math.min(layoutBox.y, memberBounds.y) : layoutBox.y;
|
|
177
|
+
const right = useLayoutWidth ? layoutBox.x + layoutBox.width : memberBounds.width > 0 ? Math.max(layoutBox.x + layoutBox.width, memberBounds.x + memberBounds.width) : layoutBox.x + layoutBox.width;
|
|
178
|
+
const bottom = useLayoutHeight ? layoutBox.y + layoutBox.height : memberBounds.height > 0 ? Math.max(layoutBox.y + layoutBox.height, memberBounds.y + memberBounds.height) : layoutBox.y + layoutBox.height;
|
|
179
|
+
outputGeometry = {
|
|
180
|
+
x,
|
|
181
|
+
y,
|
|
182
|
+
width: right - x,
|
|
183
|
+
height: bottom - y
|
|
184
|
+
};
|
|
185
|
+
} else if (layoutBox !== void 0 && (useLayoutWidth || useLayoutHeight)) outputGeometry = {
|
|
186
|
+
x: useLayoutWidth ? layoutBox.x : memberBounds.x,
|
|
187
|
+
y: useLayoutHeight ? layoutBox.y : memberBounds.y,
|
|
188
|
+
width: useLayoutWidth ? layoutBox.width : memberBounds.width,
|
|
189
|
+
height: useLayoutHeight ? layoutBox.height : memberBounds.height
|
|
190
|
+
};
|
|
191
|
+
else outputGeometry = memberBounds;
|
|
192
|
+
}
|
|
193
|
+
if (outputGeometry.width === 0 || pxToEmu(outputGeometry.width) === 0) throw new CapabilityError("invalid-group-geometry", "Computed Group width is 0px; width must be greater than 0px");
|
|
194
|
+
if (outputGeometry.width < 0 || pxToEmu(outputGeometry.width) < 1) throw new CapabilityError("invalid-group-geometry", `Computed Group width is ${outputGeometry.width}px; width must be greater than 0px`);
|
|
195
|
+
if (outputGeometry.height === 0 || pxToEmu(outputGeometry.height) === 0) throw new CapabilityError("invalid-group-geometry", "Computed Group height is 0px; height must be greater than 0px");
|
|
196
|
+
if (outputGeometry.height < 0 || pxToEmu(outputGeometry.height) < 1) throw new CapabilityError("invalid-group-geometry", `Computed Group height is ${outputGeometry.height}px; height must be greater than 0px`);
|
|
197
|
+
const outputEmu = {
|
|
198
|
+
x: pxToEmu(outputGeometry.x),
|
|
199
|
+
y: pxToEmu(outputGeometry.y),
|
|
200
|
+
width: pxToEmu(outputGeometry.width),
|
|
201
|
+
height: pxToEmu(outputGeometry.height)
|
|
202
|
+
};
|
|
203
|
+
if (outputEmu.width > maximumGroupExtentEmu || outputEmu.height > maximumGroupExtentEmu) throw new CapabilityError("invalid-group-geometry", "Group bounds exceed writable PresentationML dimensions");
|
|
204
|
+
const name = resolveContext.morphName ?? requestedName ?? `Group ${resolveContext.id - 1}`;
|
|
205
|
+
let escapedName;
|
|
206
|
+
try {
|
|
207
|
+
escapedName = xmlEscape(name);
|
|
208
|
+
} catch {
|
|
209
|
+
throw new CapabilityError("invalid-xml-character", "Group.name contains characters not allowed in XML 1.0");
|
|
210
|
+
}
|
|
211
|
+
const members = motionMembers(resolvedChildren.objects);
|
|
212
|
+
const annotations = motionContainerAnnotations(motionProps, {
|
|
213
|
+
kind: "group",
|
|
214
|
+
name,
|
|
215
|
+
...authorId === void 0 ? {} : { authorId },
|
|
216
|
+
textBody: false,
|
|
217
|
+
filled: false,
|
|
218
|
+
box: outputGeometry,
|
|
219
|
+
rotationDegrees: rotation ?? 0,
|
|
220
|
+
members
|
|
221
|
+
});
|
|
222
|
+
const angle = rotation ?? 0;
|
|
223
|
+
const resolvedModel = {
|
|
224
|
+
escapedName,
|
|
225
|
+
box: outputGeometry,
|
|
226
|
+
emu: outputEmu,
|
|
227
|
+
angle,
|
|
228
|
+
...rotation === void 0 ? {} : { rotation },
|
|
229
|
+
flipH,
|
|
230
|
+
flipV
|
|
231
|
+
};
|
|
232
|
+
const transform = {
|
|
233
|
+
box: outputGeometry,
|
|
234
|
+
angle,
|
|
235
|
+
flipH,
|
|
236
|
+
flipV
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
observation: {
|
|
240
|
+
id: resolveContext.id,
|
|
241
|
+
kind: "group",
|
|
242
|
+
name,
|
|
243
|
+
box: outputGeometry,
|
|
244
|
+
members: resolvedChildren.objects
|
|
245
|
+
},
|
|
246
|
+
transform,
|
|
247
|
+
extensions: [],
|
|
248
|
+
...annotations.length === 0 ? {} : { annotations },
|
|
249
|
+
emit(emitContext) {
|
|
250
|
+
return groupMechanism.emit(resolvedModel, emitContext);
|
|
251
|
+
},
|
|
252
|
+
paint(paintContext) {
|
|
253
|
+
return groupMechanism.paint(resolvedModel, paintContext);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
export { groupCapability, groupMechanism };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import "../../../core/dist/capability.js";
|
|
3
|
+
// ../capabilities/dist/image/gif-decoder.js
|
|
4
|
+
function corruptGif(message) {
|
|
5
|
+
throw new CapabilityError("preview-corrupt-image", message);
|
|
6
|
+
}
|
|
7
|
+
function u16LE(bytes, offset) {
|
|
8
|
+
return (bytes[offset] ?? 0) + ((bytes[offset + 1] ?? 0) << 8);
|
|
9
|
+
}
|
|
10
|
+
function skipSubBlocks(bytes, startOffset) {
|
|
11
|
+
let offset = startOffset;
|
|
12
|
+
while (offset < bytes.length) {
|
|
13
|
+
const size = bytes[offset] ?? 0;
|
|
14
|
+
offset += 1;
|
|
15
|
+
if (size === 0) return offset;
|
|
16
|
+
offset += size;
|
|
17
|
+
if (offset > bytes.length) corruptGif("Failed to decode GIF image: truncated extension sub-block");
|
|
18
|
+
}
|
|
19
|
+
corruptGif("Failed to decode GIF image: unterminated extension sub-block");
|
|
20
|
+
}
|
|
21
|
+
function collectSubBlocks(bytes, startOffset) {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
let totalLength = 0;
|
|
24
|
+
let offset = startOffset;
|
|
25
|
+
while (offset < bytes.length) {
|
|
26
|
+
const size = bytes[offset] ?? 0;
|
|
27
|
+
offset += 1;
|
|
28
|
+
if (size === 0) {
|
|
29
|
+
const merged = new Uint8Array(totalLength);
|
|
30
|
+
let cursor = 0;
|
|
31
|
+
for (const chunk of chunks) {
|
|
32
|
+
merged.set(chunk, cursor);
|
|
33
|
+
cursor += chunk.length;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
data: merged,
|
|
37
|
+
nextOffset: offset
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (offset + size > bytes.length) corruptGif("Failed to decode GIF image: truncated image data sub-block");
|
|
41
|
+
chunks.push(bytes.subarray(offset, offset + size));
|
|
42
|
+
totalLength += size;
|
|
43
|
+
offset += size;
|
|
44
|
+
}
|
|
45
|
+
corruptGif("Failed to decode GIF image: unterminated image data sub-block");
|
|
46
|
+
}
|
|
47
|
+
function decompressLzw(compressed, lzwMinCodeSize, expectedPixels) {
|
|
48
|
+
if (lzwMinCodeSize < 2 || lzwMinCodeSize > 11) corruptGif(`Failed to decode GIF image: invalid LZW minimum code size ${lzwMinCodeSize}`);
|
|
49
|
+
if (compressed.length === 0) corruptGif("Failed to decode GIF image: empty LZW compressed stream");
|
|
50
|
+
const clearCode = 1 << lzwMinCodeSize;
|
|
51
|
+
const eoiCode = clearCode + 1;
|
|
52
|
+
const indices = new Uint8Array(expectedPixels);
|
|
53
|
+
const prefix = /* @__PURE__ */ new Int32Array(4096);
|
|
54
|
+
const suffix = /* @__PURE__ */ new Uint8Array(4096);
|
|
55
|
+
const pixelStack = /* @__PURE__ */ new Uint8Array(4096);
|
|
56
|
+
for (let i = 0; i < clearCode; i += 1) {
|
|
57
|
+
prefix[i] = -1;
|
|
58
|
+
suffix[i] = i;
|
|
59
|
+
}
|
|
60
|
+
let codeSize = lzwMinCodeSize + 1;
|
|
61
|
+
let nextCode = eoiCode + 1;
|
|
62
|
+
let oldCode = -1;
|
|
63
|
+
let firstChar = 0;
|
|
64
|
+
let pixelOut = 0;
|
|
65
|
+
let bytePos = 0;
|
|
66
|
+
let bitBuffer = 0;
|
|
67
|
+
let bitCount = 0;
|
|
68
|
+
const readCode = () => {
|
|
69
|
+
while (bitCount < codeSize) {
|
|
70
|
+
if (bytePos >= compressed.length) corruptGif("Failed to decode GIF image: truncated LZW bit stream");
|
|
71
|
+
bitBuffer |= (compressed[bytePos] ?? 0) << bitCount;
|
|
72
|
+
bytePos += 1;
|
|
73
|
+
bitCount += 8;
|
|
74
|
+
}
|
|
75
|
+
const mask = (1 << codeSize) - 1;
|
|
76
|
+
const code = bitBuffer & mask;
|
|
77
|
+
bitBuffer >>>= codeSize;
|
|
78
|
+
bitCount -= codeSize;
|
|
79
|
+
return code;
|
|
80
|
+
};
|
|
81
|
+
while (pixelOut < expectedPixels) {
|
|
82
|
+
const rawCode = readCode();
|
|
83
|
+
if (rawCode === clearCode) {
|
|
84
|
+
codeSize = lzwMinCodeSize + 1;
|
|
85
|
+
nextCode = eoiCode + 1;
|
|
86
|
+
oldCode = -1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (rawCode === eoiCode) break;
|
|
90
|
+
if (rawCode > nextCode || rawCode === nextCode && oldCode === -1) corruptGif(`Failed to decode GIF image: out-of-range LZW code ${rawCode} (nextCode=${nextCode})`);
|
|
91
|
+
let code = rawCode;
|
|
92
|
+
let stackTop = 0;
|
|
93
|
+
if (code === nextCode) {
|
|
94
|
+
pixelStack[stackTop] = firstChar;
|
|
95
|
+
stackTop += 1;
|
|
96
|
+
code = oldCode;
|
|
97
|
+
}
|
|
98
|
+
while (code >= clearCode) {
|
|
99
|
+
if (stackTop >= 4096) corruptGif("Failed to decode GIF image: corrupt LZW dictionary cycle");
|
|
100
|
+
pixelStack[stackTop] = suffix[code] ?? 0;
|
|
101
|
+
stackTop += 1;
|
|
102
|
+
code = prefix[code] ?? -1;
|
|
103
|
+
if (code < 0) corruptGif("Failed to decode GIF image: invalid LZW prefix reference");
|
|
104
|
+
}
|
|
105
|
+
firstChar = suffix[code] ?? 0;
|
|
106
|
+
pixelStack[stackTop] = firstChar;
|
|
107
|
+
stackTop += 1;
|
|
108
|
+
for (let i = stackTop - 1; i >= 0 && pixelOut < expectedPixels; i -= 1) {
|
|
109
|
+
indices[pixelOut] = pixelStack[i] ?? 0;
|
|
110
|
+
pixelOut += 1;
|
|
111
|
+
}
|
|
112
|
+
if (oldCode !== -1 && nextCode < 4096) {
|
|
113
|
+
prefix[nextCode] = oldCode;
|
|
114
|
+
suffix[nextCode] = firstChar;
|
|
115
|
+
nextCode += 1;
|
|
116
|
+
if (nextCode === 1 << codeSize && codeSize < 12) codeSize += 1;
|
|
117
|
+
}
|
|
118
|
+
oldCode = rawCode;
|
|
119
|
+
}
|
|
120
|
+
if (pixelOut < expectedPixels) corruptGif(`Failed to decode GIF image: truncated pixel stream (${pixelOut}/${expectedPixels} pixels)`);
|
|
121
|
+
return indices;
|
|
122
|
+
}
|
|
123
|
+
const interlacePasses = [
|
|
124
|
+
{
|
|
125
|
+
start: 0,
|
|
126
|
+
step: 8
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
start: 4,
|
|
130
|
+
step: 8
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
start: 2,
|
|
134
|
+
step: 4
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
start: 1,
|
|
138
|
+
step: 2
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
/**
|
|
142
|
+
* Decodes the static first frame of a GIF87a or GIF89a byte stream into RGBA pixels.
|
|
143
|
+
* Supports GCT/LCT palettes, Graphic Control Extension transparency, and 4-pass interlacing.
|
|
144
|
+
*/
|
|
145
|
+
function decodeGifFirstFrame(bytes) {
|
|
146
|
+
if (bytes.length < 14) corruptGif("Failed to decode GIF image: truncated header");
|
|
147
|
+
const signature = String.fromCharCode(...bytes.subarray(0, 6));
|
|
148
|
+
if (signature !== "GIF87a" && signature !== "GIF89a") corruptGif("Failed to decode GIF image: invalid GIF signature");
|
|
149
|
+
const screenW = u16LE(bytes, 6);
|
|
150
|
+
const screenH = u16LE(bytes, 8);
|
|
151
|
+
if (screenW < 1 || screenH < 1) corruptGif("Failed to decode GIF image: invalid logical screen dimensions");
|
|
152
|
+
const packed = bytes[10] ?? 0;
|
|
153
|
+
const hasGct = (packed & 128) !== 0;
|
|
154
|
+
const gctSize = 1 << (packed & 7) + 1;
|
|
155
|
+
let offset = 13;
|
|
156
|
+
let gct;
|
|
157
|
+
if (hasGct) {
|
|
158
|
+
const gctEnd = offset + gctSize * 3;
|
|
159
|
+
if (gctEnd > bytes.length) corruptGif("Failed to decode GIF image: truncated global color table");
|
|
160
|
+
gct = bytes.subarray(offset, gctEnd);
|
|
161
|
+
offset = gctEnd;
|
|
162
|
+
}
|
|
163
|
+
let transparentIndex;
|
|
164
|
+
let foundImage = false;
|
|
165
|
+
while (offset < bytes.length) {
|
|
166
|
+
const block = bytes[offset];
|
|
167
|
+
offset += 1;
|
|
168
|
+
if (block === 44) {
|
|
169
|
+
foundImage = true;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (block === 59) corruptGif("Failed to decode GIF image: no image frame before trailer");
|
|
173
|
+
if (block === 33) {
|
|
174
|
+
if (offset >= bytes.length) corruptGif("Failed to decode GIF image: truncated extension header");
|
|
175
|
+
const label = bytes[offset] ?? 0;
|
|
176
|
+
offset += 1;
|
|
177
|
+
if (label === 249) {
|
|
178
|
+
if ((bytes[offset] ?? 0) !== 4 || offset + 5 >= bytes.length) corruptGif("Failed to decode GIF image: invalid graphic control extension");
|
|
179
|
+
const transparentFlag = ((bytes[offset + 1] ?? 0) & 1) !== 0;
|
|
180
|
+
const transIdx = bytes[offset + 4] ?? 0;
|
|
181
|
+
transparentIndex = transparentFlag ? transIdx : void 0;
|
|
182
|
+
offset = skipSubBlocks(bytes, offset);
|
|
183
|
+
} else offset = skipSubBlocks(bytes, offset);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
corruptGif(`Failed to decode GIF image: unexpected block introducer 0x${(block ?? 0).toString(16)}`);
|
|
187
|
+
}
|
|
188
|
+
if (!foundImage || offset + 9 > bytes.length) corruptGif("Failed to decode GIF image: missing image descriptor");
|
|
189
|
+
const left = u16LE(bytes, offset);
|
|
190
|
+
const top = u16LE(bytes, offset + 2);
|
|
191
|
+
const frameW = u16LE(bytes, offset + 4);
|
|
192
|
+
const frameH = u16LE(bytes, offset + 6);
|
|
193
|
+
const imgPacked = bytes[offset + 8] ?? 0;
|
|
194
|
+
offset += 9;
|
|
195
|
+
if (frameW < 1 || frameH < 1) corruptGif("Failed to decode GIF image: invalid frame dimensions");
|
|
196
|
+
const hasLct = (imgPacked & 128) !== 0;
|
|
197
|
+
const interlaced = (imgPacked & 64) !== 0;
|
|
198
|
+
const lctSize = 1 << (imgPacked & 7) + 1;
|
|
199
|
+
let palette = gct;
|
|
200
|
+
if (hasLct) {
|
|
201
|
+
const lctEnd = offset + lctSize * 3;
|
|
202
|
+
if (lctEnd > bytes.length) corruptGif("Failed to decode GIF image: truncated local color table");
|
|
203
|
+
palette = bytes.subarray(offset, lctEnd);
|
|
204
|
+
offset = lctEnd;
|
|
205
|
+
}
|
|
206
|
+
if (palette === void 0 || palette.length < 3) corruptGif("Failed to decode GIF image: missing color table");
|
|
207
|
+
if (offset >= bytes.length) corruptGif("Failed to decode GIF image: missing LZW minimum code size");
|
|
208
|
+
const lzwMinCodeSize = bytes[offset] ?? 0;
|
|
209
|
+
offset += 1;
|
|
210
|
+
const { data: compressed } = collectSubBlocks(bytes, offset);
|
|
211
|
+
const indices = decompressLzw(compressed, lzwMinCodeSize, frameW * frameH);
|
|
212
|
+
const rgba = new Uint8Array(screenW * screenH * 4);
|
|
213
|
+
const rowMap = new Int32Array(frameH);
|
|
214
|
+
if (interlaced) {
|
|
215
|
+
let srcY = 0;
|
|
216
|
+
for (const pass of interlacePasses) for (let destY = pass.start; destY < frameH; destY += pass.step) {
|
|
217
|
+
rowMap[srcY] = destY;
|
|
218
|
+
srcY += 1;
|
|
219
|
+
}
|
|
220
|
+
} else for (let y = 0; y < frameH; y += 1) rowMap[y] = y;
|
|
221
|
+
for (let srcY = 0; srcY < frameH; srcY += 1) {
|
|
222
|
+
const destY = top + (rowMap[srcY] ?? 0);
|
|
223
|
+
for (let x = 0; x < frameW; x += 1) {
|
|
224
|
+
const colorIdx = indices[srcY * frameW + x] ?? 0;
|
|
225
|
+
if (colorIdx === transparentIndex) continue;
|
|
226
|
+
const palOffset = colorIdx * 3;
|
|
227
|
+
if (palOffset + 2 >= palette.length) corruptGif(`Failed to decode GIF image: palette index ${colorIdx} out of bounds`);
|
|
228
|
+
const destX = left + x;
|
|
229
|
+
if (destX >= 0 && destX < screenW && destY >= 0 && destY < screenH) {
|
|
230
|
+
const outOffset = (destY * screenW + destX) * 4;
|
|
231
|
+
rgba[outOffset] = palette[palOffset] ?? 0;
|
|
232
|
+
rgba[outOffset + 1] = palette[palOffset + 1] ?? 0;
|
|
233
|
+
rgba[outOffset + 2] = palette[palOffset + 2] ?? 0;
|
|
234
|
+
rgba[outOffset + 3] = 255;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
width: screenW,
|
|
240
|
+
height: screenH,
|
|
241
|
+
data: rgba
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export { decodeGifFirstFrame };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { readInternalDeclarationProps } from "../../../core/dist/document-internals.js";
|
|
2
|
+
import { imageBackgroundSchema } from "../../../core/dist/theme.js";
|
|
3
|
+
import { nativePlaceholderRefSchema } from "../../../core/dist/placeholders.js";
|
|
4
|
+
import "../../../codegen/dist/index.js";
|
|
5
|
+
import "../../../core/dist/capability.js";
|
|
6
|
+
import { CommonNode } from "../../../core/dist/document.js";
|
|
7
|
+
import { motionPropKeySet } from "../motion/motion-schemas.js";
|
|
8
|
+
import { defineObjectCodegen, expr } from "../../../codegen/dist/types.js";
|
|
9
|
+
import { serializeGeometryProp } from "../shape/shape-codegen.js";
|
|
10
|
+
import { readImage } from "./image-decode.js";
|
|
11
|
+
import { externalImageSourceSchema, imageAllowedParameters, imageStyleSchema } from "./image-schemas.js";
|
|
12
|
+
// ../capabilities/dist/image/image-codegen.js
|
|
13
|
+
const objectMotionPropKeys = motionPropKeySet;
|
|
14
|
+
const imageDescriptorAllowedKeys = /* @__PURE__ */ new Set([
|
|
15
|
+
"image",
|
|
16
|
+
"fit",
|
|
17
|
+
"position",
|
|
18
|
+
"opacity"
|
|
19
|
+
]);
|
|
20
|
+
const imageAllowedPropKeys = new Set(imageAllowedParameters);
|
|
21
|
+
const dummyImageBytes = new Uint8Array([0]);
|
|
22
|
+
function isPlainObject(value) {
|
|
23
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
24
|
+
const proto = Object.getPrototypeOf(value);
|
|
25
|
+
return proto === Object.prototype || proto === null;
|
|
26
|
+
}
|
|
27
|
+
function assertNoImageChildren(node, ctx) {
|
|
28
|
+
for (const child of node.children) {
|
|
29
|
+
if (child instanceof CommonNode) ctx.fail("invalid-document", "Image does not accept child declarations");
|
|
30
|
+
const leaf = child;
|
|
31
|
+
if (leaf.type === "#text" && leaf.text.trim() !== "") ctx.fail("invalid-document", "Image does not accept text children");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function serializeImageSrcProp(value, ctx) {
|
|
35
|
+
if (isPlainObject(value) && Object.hasOwn(value, "externalUrl")) {
|
|
36
|
+
const parsedExternal = externalImageSourceSchema.safeParse(value);
|
|
37
|
+
if (!parsedExternal.success) ctx.fail("unexpressible-value", "Image.src externalUrl must be a non-empty string", "@src");
|
|
38
|
+
return expr(ctx.emitValueExpr({ externalUrl: parsedExternal.data.externalUrl }, "@src"));
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const loaded = readImage(value);
|
|
42
|
+
const assetVar = ctx.registerImageAsset(loaded.bytes, loaded.extension);
|
|
43
|
+
return expr(assetVar);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
ctx.fail("unexpressible-value", error instanceof Error ? error.message : "Image.src could not be read or decoded", "@src");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function validateImageNativePlaceholder(value, ctx) {
|
|
49
|
+
const parsed = nativePlaceholderRefSchema.safeParse(value);
|
|
50
|
+
if (!parsed.success) ctx.fail("unexpressible-value", parsed.error.issues[0]?.message ?? "Image.nativePlaceholder cannot be expressed", "@nativePlaceholder");
|
|
51
|
+
}
|
|
52
|
+
function serializeImageStyleProp(style, ctx) {
|
|
53
|
+
if (!isPlainObject(style)) ctx.fail("unexpressible-value", "Image.style must be a plain object", "@style");
|
|
54
|
+
const parsed = imageStyleSchema.safeParse(style);
|
|
55
|
+
if (!parsed.success) {
|
|
56
|
+
const issue = parsed.error.issues[0];
|
|
57
|
+
const issuePath = issue !== void 0 && issue.path.length > 0 ? `@style.${issue.path.join(".")}` : "@style";
|
|
58
|
+
ctx.fail("unexpressible-value", issue?.message ?? "Image.style cannot be expressed", issuePath);
|
|
59
|
+
}
|
|
60
|
+
const styleEntries = [];
|
|
61
|
+
for (const [key, entryValue] of Object.entries(style)) {
|
|
62
|
+
if (entryValue === void 0) continue;
|
|
63
|
+
if (key === "background") {
|
|
64
|
+
const serializedBg = serializeImageDescriptorValue(entryValue, ctx);
|
|
65
|
+
styleEntries.push([key, serializedBg ?? entryValue]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
styleEntries.push([key, entryValue]);
|
|
69
|
+
}
|
|
70
|
+
return expr(ctx.formatProps(styleEntries));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serializes an `{ image, fit?, position?, opacity? }` descriptor (used in `style.background`
|
|
74
|
+
* and `Slide.background`) by reading/validating embedded image bytes or `{ externalUrl }`
|
|
75
|
+
* and emitting a formatted descriptor expression.
|
|
76
|
+
*/
|
|
77
|
+
function serializeImageDescriptorValue(value, ctx) {
|
|
78
|
+
if (!isPlainObject(value) || value["image"] === void 0) return;
|
|
79
|
+
const definedKeys = Object.keys(value).filter((key) => value[key] !== void 0);
|
|
80
|
+
if (definedKeys.length === 0 || !definedKeys.every((key) => imageDescriptorAllowedKeys.has(key))) return;
|
|
81
|
+
const subPath = ctx.path.includes("@") ? void 0 : "@style.background";
|
|
82
|
+
const rawSource = value["image"];
|
|
83
|
+
let imageExpr;
|
|
84
|
+
if (isPlainObject(rawSource) && Object.hasOwn(rawSource, "externalUrl")) {
|
|
85
|
+
const parsedExternal = externalImageSourceSchema.safeParse(rawSource);
|
|
86
|
+
if (!parsedExternal.success) ctx.fail("unexpressible-value", "Background image externalUrl must be a non-empty string", subPath);
|
|
87
|
+
imageExpr = expr(ctx.emitValueExpr({ externalUrl: parsedExternal.data.externalUrl }, subPath));
|
|
88
|
+
} else try {
|
|
89
|
+
const loaded = readImage(rawSource);
|
|
90
|
+
const assetVar = ctx.registerImageAsset(loaded.bytes, loaded.extension);
|
|
91
|
+
imageExpr = expr(assetVar);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
ctx.fail("unexpressible-value", error instanceof Error ? error.message : "Background image source could not be read or decoded", subPath);
|
|
94
|
+
}
|
|
95
|
+
const parsedOptions = imageBackgroundSchema.safeParse({
|
|
96
|
+
...value,
|
|
97
|
+
image: dummyImageBytes
|
|
98
|
+
});
|
|
99
|
+
if (!parsedOptions.success) ctx.fail("unexpressible-value", parsedOptions.error.issues[0]?.message ?? "Background image descriptor options are invalid", subPath);
|
|
100
|
+
const descriptorEntries = [["image", imageExpr]];
|
|
101
|
+
for (const optionKey of [
|
|
102
|
+
"fit",
|
|
103
|
+
"position",
|
|
104
|
+
"opacity"
|
|
105
|
+
]) {
|
|
106
|
+
const optionValue = value[optionKey];
|
|
107
|
+
if (optionValue !== void 0) descriptorEntries.push([optionKey, expr(ctx.emitValueExpr(optionValue, subPath))]);
|
|
108
|
+
}
|
|
109
|
+
return expr(ctx.formatProps(descriptorEntries));
|
|
110
|
+
}
|
|
111
|
+
function collectImageProps(node, ctx) {
|
|
112
|
+
assertNoImageChildren(node, ctx);
|
|
113
|
+
const props = readInternalDeclarationProps(node);
|
|
114
|
+
const extra = ctx.emitObjectExtraProps(props);
|
|
115
|
+
const entries = [];
|
|
116
|
+
let sawSrc = false;
|
|
117
|
+
for (const [key, value] of Object.entries(props)) {
|
|
118
|
+
if (value === void 0) continue;
|
|
119
|
+
if (!imageAllowedPropKeys.has(key)) ctx.fail("invalid-document", `image declaration does not support property ${JSON.stringify(key)}`, `@${key}`);
|
|
120
|
+
if (key === "src") {
|
|
121
|
+
sawSrc = true;
|
|
122
|
+
entries.push(["src", serializeImageSrcProp(value, ctx)]);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (key === "nativePlaceholder") {
|
|
126
|
+
validateImageNativePlaceholder(value, ctx);
|
|
127
|
+
entries.push([key, value]);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (key === "geometry") {
|
|
131
|
+
entries.push([key, serializeGeometryProp(value, ctx)]);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (key === "style") {
|
|
135
|
+
entries.push([key, serializeImageStyleProp(value, ctx)]);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (objectMotionPropKeys.has(key)) {
|
|
139
|
+
if (Object.hasOwn(extra, key)) entries.push([key, extra[key]]);
|
|
140
|
+
else ctx.fail("unexpressible-value", `Object property ${JSON.stringify(key)} requires motion codegen support`, `@${key}`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
entries.push([key, value]);
|
|
144
|
+
}
|
|
145
|
+
if (!sawSrc) ctx.fail("unexpressible-value", "Image declaration is missing src", "@src");
|
|
146
|
+
return entries;
|
|
147
|
+
}
|
|
148
|
+
/** Source codegen contribution for `image` declarations and `{ image, fit?, position?, opacity? }` descriptors. */
|
|
149
|
+
const imageCodegen = defineObjectCodegen({
|
|
150
|
+
declarations: { image: {
|
|
151
|
+
emitVanilla: (node, ctx) => {
|
|
152
|
+
const callee = ctx.useImport("image");
|
|
153
|
+
const props = collectImageProps(node, ctx);
|
|
154
|
+
return ctx.formatVanillaCall(callee, [ctx.formatProps(props)]);
|
|
155
|
+
},
|
|
156
|
+
emitReact: (node, ctx) => {
|
|
157
|
+
const tag = ctx.useImport("Image");
|
|
158
|
+
const props = collectImageProps(node, ctx);
|
|
159
|
+
return ctx.formatJsxElement(tag, props);
|
|
160
|
+
}
|
|
161
|
+
} },
|
|
162
|
+
valueSerializers: [serializeImageDescriptorValue]
|
|
163
|
+
});
|
|
164
|
+
export { imageCodegen, serializeImageDescriptorValue };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CommonNode } from "../../../core/dist/document.js";
|
|
2
|
+
import { imageVisualStyleKeys } from "./image-schemas.js";
|
|
3
|
+
// ../capabilities/dist/image/image-declaration.js
|
|
4
|
+
/** Creates the editable native image shared by the command factory and the Image JSX element. */
|
|
5
|
+
function createImageNode(props) {
|
|
6
|
+
return new CommonNode("image", "image", props);
|
|
7
|
+
}
|
|
8
|
+
export { createImageNode, imageVisualStyleKeys };
|