@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,53 @@
|
|
|
1
|
+
import { BuildError, toBuildDiagnostic } from "../../core/dist/diagnostics.js";
|
|
2
|
+
import { createResolver } from "../../core/dist/resolve.js";
|
|
3
|
+
import "../../core/dist/build.js";
|
|
4
|
+
import { emit, emittedBuildQuery, validateOptions } from "../../emit/dist/emit.js";
|
|
5
|
+
import { CommonNode } from "../../core/dist/document.js";
|
|
6
|
+
import "../../emit/dist/index.js";
|
|
7
|
+
// src/compose.ts
|
|
8
|
+
function isJsxLikeInput(value) {
|
|
9
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof CommonNode) return false;
|
|
10
|
+
if ("$$typeof" in value && typeof value.$$typeof === "symbol") return true;
|
|
11
|
+
return "type" in value && "props" in value && !("children" in value && Array.isArray(value.children));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolves either an editable CommonNode synchronously or a React JSX element via on-demand
|
|
15
|
+
* expansion using the supplied resolver.
|
|
16
|
+
*/
|
|
17
|
+
async function resolveDocumentInput(resolveDeclaration, input, options = {}) {
|
|
18
|
+
if (input instanceof CommonNode) return resolveDeclaration(input, options);
|
|
19
|
+
const { expandDocument } = await import("../../react/dist/index.js");
|
|
20
|
+
return resolveDeclaration(await expandDocument(input, options), options);
|
|
21
|
+
}
|
|
22
|
+
/** Emits a PPTX archive and BuildResult from an immutable Resolution snapshot. */
|
|
23
|
+
function emitBuildResult(resolution, options = {}) {
|
|
24
|
+
const emitted = emit(resolution, options);
|
|
25
|
+
const query = emittedBuildQuery(emitted.report, resolution);
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
pptx: emitted.pptx,
|
|
28
|
+
report: emitted.report,
|
|
29
|
+
slides: query.slides,
|
|
30
|
+
slide: (id) => query.slide(id)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Composes synchronous `resolve` and async-compatible `build` (supporting both JSX and CommonNode)
|
|
35
|
+
* over one capability module set for entrypoints that assemble capabilities directly.
|
|
36
|
+
*/
|
|
37
|
+
function createStagePipeline(modules) {
|
|
38
|
+
const resolveDeclaration = createResolver(modules);
|
|
39
|
+
function resolve(document, options = {}) {
|
|
40
|
+
if (isJsxLikeInput(document)) throw new BuildError([toBuildDiagnostic("deck", "invalid-structure", "Root resolve() synchronously accepts only an expanded CommonNode document, not a JSX/React element; await expandDocument(element) first, call resolveFromSource() from @officedk/pptxdk/node, or use async resolve() from @officedk/pptxdk/build")]);
|
|
41
|
+
return resolveDeclaration(document, options);
|
|
42
|
+
}
|
|
43
|
+
async function build(input, options = {}) {
|
|
44
|
+
validateOptions(options);
|
|
45
|
+
const resolveOptions = options.signal === void 0 ? {} : { signal: options.signal };
|
|
46
|
+
return emitBuildResult(await resolveDocumentInput(resolveDeclaration, input, resolveOptions), options);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
resolve,
|
|
50
|
+
build
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { createStagePipeline, emitBuildResult, resolveDocumentInput };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Slide as Slide$1, SlideLayout as SlideLayout$1, SlideMaster as SlideMaster$1 } from "../../react/dist/elements.js";
|
|
2
|
+
import "../../react/dist/index.js";
|
|
3
|
+
// src/slide.ts
|
|
4
|
+
function Slide(props) {
|
|
5
|
+
return Slide$1(props);
|
|
6
|
+
}
|
|
7
|
+
const SlideMaster = SlideMaster$1;
|
|
8
|
+
const SlideLayout = SlideLayout$1;
|
|
9
|
+
export { Slide, SlideLayout, SlideMaster };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { CapabilityError } from "../../core/dist/diagnostics.js";
|
|
2
|
+
import { PreviewPageRangeError, previewErrorSchema, previewPlaceholderSchema } from "../../core/dist/stage-options.js";
|
|
3
|
+
import "../../core/dist/build.js";
|
|
4
|
+
import { getInternalResolution } from "../../core/dist/resolution.js";
|
|
5
|
+
import { paintOptionsSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, screenGeometrySchema, screenPointSchema, validatePaintOptions } from "./options.js";
|
|
6
|
+
import { createPageRasterRegistry, sanitizeSvgForRasterization } from "./svg-guard.js";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
// ../preview/dist/index.js
|
|
9
|
+
const defaultCanvasBackground = "<rect width=\"100%\" height=\"100%\" fill=\"white\"/>";
|
|
10
|
+
function roundScreenMetric(value) {
|
|
11
|
+
const rounded = Math.round(value * 1e9) / 1e9;
|
|
12
|
+
return Object.is(rounded, -0) ? 0 : rounded;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Computes transformed screen corners and axis-aligned screen bounds for a layout box.
|
|
16
|
+
* Applies the local object transform first, followed by enclosing group transforms outward.
|
|
17
|
+
*/
|
|
18
|
+
function screenGeometry(box, transforms) {
|
|
19
|
+
const corners = [
|
|
20
|
+
{
|
|
21
|
+
x: box.x,
|
|
22
|
+
y: box.y
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
x: box.x + box.width,
|
|
26
|
+
y: box.y
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
x: box.x + box.width,
|
|
30
|
+
y: box.y + box.height
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
x: box.x,
|
|
34
|
+
y: box.y + box.height
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
for (const transform of transforms) {
|
|
38
|
+
const cx = transform.box.x + transform.box.width / 2;
|
|
39
|
+
const cy = transform.box.y + transform.box.height / 2;
|
|
40
|
+
const angle = transform.angle * Math.PI / 180;
|
|
41
|
+
for (const point of corners) {
|
|
42
|
+
const x = (point.x - cx) * (transform.flipH ? -1 : 1);
|
|
43
|
+
const y = (point.y - cy) * (transform.flipV ? -1 : 1);
|
|
44
|
+
point.x = cx + x * Math.cos(angle) - y * Math.sin(angle);
|
|
45
|
+
point.y = cy + x * Math.sin(angle) + y * Math.cos(angle);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const rounded = corners.map((point) => Object.freeze({
|
|
49
|
+
x: roundScreenMetric(point.x),
|
|
50
|
+
y: roundScreenMetric(point.y)
|
|
51
|
+
}));
|
|
52
|
+
const left = Math.min(...rounded.map((point) => point.x));
|
|
53
|
+
const top = Math.min(...rounded.map((point) => point.y));
|
|
54
|
+
const right = Math.max(...rounded.map((point) => point.x));
|
|
55
|
+
const bottom = Math.max(...rounded.map((point) => point.y));
|
|
56
|
+
return {
|
|
57
|
+
corners: Object.freeze(rounded),
|
|
58
|
+
screenBox: Object.freeze({
|
|
59
|
+
x: left,
|
|
60
|
+
y: top,
|
|
61
|
+
width: roundScreenMetric(right - left),
|
|
62
|
+
height: roundScreenMetric(bottom - top)
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
let cachedResvg;
|
|
67
|
+
function getResvg() {
|
|
68
|
+
if (cachedResvg === void 0) {
|
|
69
|
+
const loaded = createRequire(import.meta.url)("@resvg/resvg-js");
|
|
70
|
+
if (typeof loaded !== "object" || loaded === null || !("Resvg" in loaded) || typeof loaded.Resvg !== "function") throw new Error("Failed to load @resvg/resvg-js Resvg constructor");
|
|
71
|
+
cachedResvg = loaded.Resvg;
|
|
72
|
+
}
|
|
73
|
+
return cachedResvg;
|
|
74
|
+
}
|
|
75
|
+
function maxPaintObjectId(layers) {
|
|
76
|
+
let maxId = 0;
|
|
77
|
+
for (const layer of layers) {
|
|
78
|
+
if (layer.paintObjectId > maxId) maxId = layer.paintObjectId;
|
|
79
|
+
const memberMax = maxPaintObjectId(layer.memberLayers);
|
|
80
|
+
if (memberMax > maxId) maxId = memberMax;
|
|
81
|
+
const siblingMax = maxPaintObjectId(layer.siblingLayers);
|
|
82
|
+
if (siblingMax > maxId) maxId = siblingMax;
|
|
83
|
+
}
|
|
84
|
+
return maxId;
|
|
85
|
+
}
|
|
86
|
+
function toPreviewError(error, path, fallbackCapability) {
|
|
87
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
88
|
+
if (error instanceof CapabilityError) {
|
|
89
|
+
const details = error.details ?? {};
|
|
90
|
+
const field = typeof details["field"] === "string" && details["field"] !== "" ? details["field"] : void 0;
|
|
91
|
+
const fieldSpread = field === void 0 ? {} : { field };
|
|
92
|
+
const rawFont = details["font"];
|
|
93
|
+
const fontRecord = typeof rawFont === "object" && rawFont !== null ? rawFont : void 0;
|
|
94
|
+
const family = typeof fontRecord?.["family"] === "string" ? fontRecord["family"] : "unknown";
|
|
95
|
+
const weight = typeof fontRecord?.["weight"] === "number" ? fontRecord["weight"] : 400;
|
|
96
|
+
const style = fontRecord?.["style"] === "italic" ? "italic" : "normal";
|
|
97
|
+
switch (error.code) {
|
|
98
|
+
case "preview-missing-font": return Object.freeze({
|
|
99
|
+
code: "preview-missing-font",
|
|
100
|
+
path,
|
|
101
|
+
...fieldSpread,
|
|
102
|
+
message,
|
|
103
|
+
font: Object.freeze({
|
|
104
|
+
family,
|
|
105
|
+
weight,
|
|
106
|
+
style
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
case "preview-unsupported-font": {
|
|
110
|
+
const optionalWeight = typeof fontRecord?.["weight"] === "number" ? fontRecord["weight"] : void 0;
|
|
111
|
+
const optionalStyle = fontRecord?.["style"] === "italic" || fontRecord?.["style"] === "normal" ? fontRecord["style"] : void 0;
|
|
112
|
+
const reason = typeof details["reason"] === "string" ? details["reason"] : void 0;
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
code: "preview-unsupported-font",
|
|
115
|
+
path,
|
|
116
|
+
...fieldSpread,
|
|
117
|
+
message,
|
|
118
|
+
font: Object.freeze({
|
|
119
|
+
family,
|
|
120
|
+
...optionalWeight === void 0 ? {} : { weight: optionalWeight },
|
|
121
|
+
...optionalStyle === void 0 ? {} : { style: optionalStyle }
|
|
122
|
+
}),
|
|
123
|
+
...reason === void 0 ? {} : { reason }
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
case "preview-missing-glyph": {
|
|
127
|
+
const rawChars = details["characters"];
|
|
128
|
+
const characters = Array.isArray(rawChars) ? rawChars.filter((item) => typeof item === "string") : [];
|
|
129
|
+
return Object.freeze({
|
|
130
|
+
code: "preview-missing-glyph",
|
|
131
|
+
path,
|
|
132
|
+
...fieldSpread,
|
|
133
|
+
message,
|
|
134
|
+
font: Object.freeze({
|
|
135
|
+
family,
|
|
136
|
+
weight,
|
|
137
|
+
style
|
|
138
|
+
}),
|
|
139
|
+
characters: Object.freeze(characters)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
case "preview-corrupt-image": {
|
|
143
|
+
const rawFormat = details["format"];
|
|
144
|
+
const format = rawFormat === "png" || rawFormat === "jpeg" || rawFormat === "gif" ? rawFormat : void 0;
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
code: "preview-corrupt-image",
|
|
147
|
+
path,
|
|
148
|
+
...fieldSpread,
|
|
149
|
+
message,
|
|
150
|
+
...format === void 0 ? {} : { format }
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
case "preview-unsupported-capability": {
|
|
154
|
+
const capability = typeof details["capability"] === "string" ? details["capability"] : fallbackCapability;
|
|
155
|
+
return Object.freeze({
|
|
156
|
+
code: "preview-unsupported-capability",
|
|
157
|
+
path,
|
|
158
|
+
...fieldSpread,
|
|
159
|
+
message,
|
|
160
|
+
capability
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return Object.freeze({
|
|
166
|
+
code: "preview-unsupported-capability",
|
|
167
|
+
path,
|
|
168
|
+
message,
|
|
169
|
+
capability: fallbackCapability
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function recordPaintPlaceholders(placeholders, records, defaultPath, defaultId) {
|
|
173
|
+
if (records === void 0) return;
|
|
174
|
+
for (const item of records) {
|
|
175
|
+
const id = item.id ?? defaultId;
|
|
176
|
+
placeholders.push(Object.freeze({
|
|
177
|
+
...id === void 0 ? {} : { id },
|
|
178
|
+
path: item.path ?? defaultPath,
|
|
179
|
+
url: item.url
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function paintLayer(layer, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource, paintIdOffset = 0, recordNodes = true) {
|
|
184
|
+
const childrenSvg = layer.childComposition === "members" ? layer.memberLayers.map((child) => paintLayer(child, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource, paintIdOffset, recordNodes)).join("") : layer.childComposition === "siblings" ? layer.siblingLayers.map((child) => paintLayer(child, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource, paintIdOffset, recordNodes)).join("") : void 0;
|
|
185
|
+
if (layer.childComposition !== "leaf" && layer.emitsObject && !layer.hasObservation) return "";
|
|
186
|
+
const recordNodeIdentity = () => {
|
|
187
|
+
if (!recordNodes || !layer.hasObservation) return;
|
|
188
|
+
nodePaths.set(layer.objectId, layer.path);
|
|
189
|
+
if (layer.transform !== void 0) transforms.set(layer.objectId, layer.transform);
|
|
190
|
+
};
|
|
191
|
+
if (layer.paint !== void 0) try {
|
|
192
|
+
const output = layer.paint({
|
|
193
|
+
path: layer.path,
|
|
194
|
+
slideNumber: pageNumber,
|
|
195
|
+
objectId: layer.paintObjectId + paintIdOffset,
|
|
196
|
+
...layer.box === void 0 ? {} : { box: layer.box },
|
|
197
|
+
theme: layer.theme,
|
|
198
|
+
...childrenSvg === void 0 ? {} : { childrenSvg },
|
|
199
|
+
registerRasterResource
|
|
200
|
+
});
|
|
201
|
+
recordNodeIdentity();
|
|
202
|
+
recordPaintPlaceholders(placeholders, output.placeholders, layer.path, layer.authorId);
|
|
203
|
+
return output.svg;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
recordNodeIdentity();
|
|
206
|
+
const errorPath = error instanceof CapabilityError && error.path !== void 0 ? `${layer.path}/${error.path}` : layer.path;
|
|
207
|
+
errors.push(toPreviewError(error, errorPath, layer.declarationType));
|
|
208
|
+
return "";
|
|
209
|
+
}
|
|
210
|
+
recordNodeIdentity();
|
|
211
|
+
errors.push(Object.freeze({
|
|
212
|
+
code: "preview-unsupported-capability",
|
|
213
|
+
path: layer.path,
|
|
214
|
+
message: `Preview does not support ${layer.declarationType}`,
|
|
215
|
+
capability: layer.declarationType
|
|
216
|
+
}));
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
/** Paints static preview pages directly from a Resolution without running emit(). */
|
|
220
|
+
function paint(resolution, options = {}) {
|
|
221
|
+
const { pages: requestedPages, signal } = validatePaintOptions(options);
|
|
222
|
+
if (signal?.aborted) throw signal.reason;
|
|
223
|
+
const internal = getInternalResolution(resolution);
|
|
224
|
+
if (requestedPages?.some((page) => page > internal.slides.length)) throw new PreviewPageRangeError(requestedPages, internal.slides.length);
|
|
225
|
+
const selected = requestedPages === void 0 ? void 0 : new Set(requestedPages);
|
|
226
|
+
const pages = [];
|
|
227
|
+
for (const [index, slide] of internal.slides.entries()) {
|
|
228
|
+
const pageNumber = slide.index;
|
|
229
|
+
if (selected !== void 0 && !selected.has(pageNumber)) continue;
|
|
230
|
+
const slideObservation = resolution.report.slides[index];
|
|
231
|
+
if (slideObservation === void 0) throw new Error("Missing resolved slide observation for paint");
|
|
232
|
+
const errors = [];
|
|
233
|
+
const placeholders = [];
|
|
234
|
+
const nodePaths = /* @__PURE__ */ new Map();
|
|
235
|
+
const transforms = /* @__PURE__ */ new Map();
|
|
236
|
+
const rasterRegistry = createPageRasterRegistry(`shared-img-s${pageNumber}`);
|
|
237
|
+
const registerRasterResource = (resource) => rasterRegistry.register(resource);
|
|
238
|
+
const masterOffset = maxPaintObjectId(slide.layers) + 1e3;
|
|
239
|
+
const wrapSharedObjectSvg = (svg) => svg !== "" && internal.mastersCanvas !== void 0 ? internal.mastersCanvas.paintSharedObject(svg).svg : svg;
|
|
240
|
+
const masterLayerFragments = (slide.masterLayers ?? []).map((layer) => wrapSharedObjectSvg(paintLayer(layer, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource, masterOffset, false)));
|
|
241
|
+
const masterLayersSvg = internal.mastersCanvas !== void 0 ? internal.mastersCanvas.paintMasterLayers(masterLayerFragments).svg : masterLayerFragments.join("");
|
|
242
|
+
const layoutOffset = masterOffset + maxPaintObjectId(slide.masterLayers ?? []) + 1e3;
|
|
243
|
+
const layoutLayerFragments = (slide.layoutLayers ?? []).map((layer) => wrapSharedObjectSvg(paintLayer(layer, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource, layoutOffset, false)));
|
|
244
|
+
const layoutLayersSvg = internal.mastersCanvas !== void 0 ? internal.mastersCanvas.paintLayoutLayers(layoutLayerFragments).svg : layoutLayerFragments.join("");
|
|
245
|
+
const layers = slide.layers.map((layer) => paintLayer(layer, pageNumber, errors, placeholders, nodePaths, transforms, registerRasterResource)).join("");
|
|
246
|
+
let background;
|
|
247
|
+
let shapeTreeCapSvg = "";
|
|
248
|
+
let hasExplicitSlideBackground = false;
|
|
249
|
+
for (const slideCap of slide.slideCapabilities) {
|
|
250
|
+
if (slideCap.slot === "background" && slideCap.hasSlideProps) hasExplicitSlideBackground = true;
|
|
251
|
+
const runSlidePaint = slideCap.paint;
|
|
252
|
+
if (runSlidePaint !== void 0) try {
|
|
253
|
+
const previewOutput = runSlidePaint({
|
|
254
|
+
path: slideCap.path,
|
|
255
|
+
dimensions: internal.dimensions,
|
|
256
|
+
theme: slideCap.theme,
|
|
257
|
+
slideNumber: pageNumber,
|
|
258
|
+
registerRasterResource
|
|
259
|
+
});
|
|
260
|
+
if (slideCap.slot === "background" && previewOutput.svg !== "") background = previewOutput.svg;
|
|
261
|
+
else if (slideCap.slot === "shape-tree" && previewOutput.svg !== "") shapeTreeCapSvg += previewOutput.svg;
|
|
262
|
+
recordPaintPlaceholders(placeholders, previewOutput.placeholders, slideCap.path, slide.authorId);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
const errorPath = error instanceof CapabilityError && error.path !== void 0 ? error.path : slideCap.path;
|
|
265
|
+
errors.push(toPreviewError(error, errorPath, slideCap.declaration));
|
|
266
|
+
}
|
|
267
|
+
else if (slideCap.slot === "background" && slideCap.hasSlideProps) errors.push(Object.freeze({
|
|
268
|
+
code: "preview-unsupported-capability",
|
|
269
|
+
path: slideCap.path,
|
|
270
|
+
message: `Preview does not support ${slideCap.declaration}`,
|
|
271
|
+
capability: slideCap.declaration
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
if (!hasExplicitSlideBackground && slide.inheritedBackground?.paint !== void 0) try {
|
|
275
|
+
const inheritedOutput = slide.inheritedBackground.paint({
|
|
276
|
+
path: slide.inheritedBackground.path,
|
|
277
|
+
dimensions: internal.dimensions,
|
|
278
|
+
theme: slide.inheritedBackground.theme,
|
|
279
|
+
slideNumber: pageNumber,
|
|
280
|
+
registerRasterResource
|
|
281
|
+
});
|
|
282
|
+
if (inheritedOutput.svg !== "") background = inheritedOutput.svg;
|
|
283
|
+
recordPaintPlaceholders(placeholders, inheritedOutput.placeholders, slide.inheritedBackground.path);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
const errorPath = error instanceof CapabilityError && error.path !== void 0 ? error.path : slide.inheritedBackground.path;
|
|
286
|
+
errors.push(toPreviewError(error, errorPath, slide.inheritedBackground.declaration));
|
|
287
|
+
}
|
|
288
|
+
const nodes = [];
|
|
289
|
+
const collect = (objects, ancestors = []) => {
|
|
290
|
+
for (const object of objects) {
|
|
291
|
+
const own = transforms.get(object.id);
|
|
292
|
+
const chain = own === void 0 ? ancestors : [own, ...ancestors];
|
|
293
|
+
const screen = object.box === void 0 ? void 0 : screenGeometry(object.box, chain);
|
|
294
|
+
nodes.push(Object.freeze({
|
|
295
|
+
...object,
|
|
296
|
+
...screen === void 0 ? {} : {
|
|
297
|
+
corners: screen.corners,
|
|
298
|
+
bounds: screen.screenBox
|
|
299
|
+
},
|
|
300
|
+
path: nodePaths.get(object.id) ?? object.path
|
|
301
|
+
}));
|
|
302
|
+
if (object.members !== void 0) collect(object.members, chain);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
collect(slideObservation.objects);
|
|
306
|
+
const pageErrors = Object.freeze([...errors]);
|
|
307
|
+
const pagePlaceholders = Object.freeze([...placeholders]);
|
|
308
|
+
if (pageErrors.length > 0) {
|
|
309
|
+
pages.push(Object.freeze({
|
|
310
|
+
id: slide.id,
|
|
311
|
+
page: pageNumber,
|
|
312
|
+
nodes: Object.freeze(nodes),
|
|
313
|
+
layouts: slideObservation.layouts ?? Object.freeze([]),
|
|
314
|
+
errors: pageErrors,
|
|
315
|
+
placeholders: pagePlaceholders
|
|
316
|
+
}));
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const fallbackBackground = internal.mastersCanvas !== void 0 ? internal.mastersCanvas.paintBackdrop({
|
|
320
|
+
theme: slide.theme,
|
|
321
|
+
...slide.hasCustomColorMap ? { hasCustomColorMap: true } : {},
|
|
322
|
+
...slide.effectiveColorMapOverride === void 0 ? {} : { colorMapOverride: slide.effectiveColorMapOverride },
|
|
323
|
+
...slide.effectiveThemeOverride === void 0 ? {} : { themeOverride: slide.effectiveThemeOverride }
|
|
324
|
+
}).svg : defaultCanvasBackground;
|
|
325
|
+
const rawSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="${internal.dimensions.width}" height="${internal.dimensions.height}" viewBox="0 0 ${internal.dimensions.width} ${internal.dimensions.height}">${background ?? fallbackBackground}${masterLayersSvg}${layoutLayersSvg}${shapeTreeCapSvg}${layers}</svg>`;
|
|
326
|
+
const svg = sanitizeSvgForRasterization(rawSvg, internal.dimensions, rasterRegistry);
|
|
327
|
+
const Resvg = getResvg();
|
|
328
|
+
const png = new Uint8Array(new Resvg(svg, { font: { loadSystemFonts: false } }).render().asPng());
|
|
329
|
+
pages.push(Object.freeze({
|
|
330
|
+
id: slide.id,
|
|
331
|
+
page: pageNumber,
|
|
332
|
+
svg,
|
|
333
|
+
png,
|
|
334
|
+
nodes: Object.freeze(nodes),
|
|
335
|
+
layouts: slideObservation.layouts ?? Object.freeze([]),
|
|
336
|
+
errors: pageErrors,
|
|
337
|
+
placeholders: pagePlaceholders
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
return Object.freeze({ pages: Object.freeze(pages) });
|
|
341
|
+
}
|
|
342
|
+
export { PreviewPageRangeError, paint, paintOptionsSchema, previewErrorSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, previewPlaceholderSchema, screenGeometry, screenGeometrySchema, screenPointSchema, validatePaintOptions };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PreviewPageRangeError, previewErrorSchema, previewPlaceholderSchema } from "../../core/dist/stage-options.js";
|
|
2
|
+
import "../../core/dist/build.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// ../preview/dist/options.js
|
|
5
|
+
const rawPreviewPageNumberSchema = z.int().positive();
|
|
6
|
+
const previewPageNumberSchema = rawPreviewPageNumberSchema;
|
|
7
|
+
const rawPreviewPagesSchema = z.array(rawPreviewPageNumberSchema).readonly();
|
|
8
|
+
const previewPagesSchema = rawPreviewPagesSchema;
|
|
9
|
+
const paintOptionsSchema = z.strictObject({
|
|
10
|
+
/** 1-based page numbers to paint. Omit to draw all pages; an empty list draws none. */
|
|
11
|
+
pages: rawPreviewPagesSchema.optional(),
|
|
12
|
+
signal: z.instanceof(AbortSignal).optional()
|
|
13
|
+
}).readonly();
|
|
14
|
+
const previewOptionsSchema = paintOptionsSchema;
|
|
15
|
+
const rawScreenPointSchema = z.object({
|
|
16
|
+
x: z.number(),
|
|
17
|
+
y: z.number()
|
|
18
|
+
}).readonly();
|
|
19
|
+
const screenPointSchema = rawScreenPointSchema;
|
|
20
|
+
const screenGeometrySchema = z.object({
|
|
21
|
+
corners: z.array(rawScreenPointSchema).readonly(),
|
|
22
|
+
screenBox: z.object({
|
|
23
|
+
x: z.number(),
|
|
24
|
+
y: z.number(),
|
|
25
|
+
width: z.number(),
|
|
26
|
+
height: z.number()
|
|
27
|
+
}).readonly()
|
|
28
|
+
}).readonly();
|
|
29
|
+
/** Validates paint/preview options (`pages`, `signal`) via shared pure-data schemas. */
|
|
30
|
+
function validatePaintOptions(options = {}) {
|
|
31
|
+
const parsed = paintOptionsSchema.safeParse(options);
|
|
32
|
+
if (parsed.success) return parsed.data;
|
|
33
|
+
const issue = parsed.error.issues[0];
|
|
34
|
+
if (issue === void 0) throw new TypeError("Preview options must be an object");
|
|
35
|
+
if (issue.path[0] === "pages") throw new RangeError("Preview page numbers must be positive integers");
|
|
36
|
+
if (issue.path[0] === "signal") throw new TypeError("Preview options signal must be an AbortSignal");
|
|
37
|
+
if (issue.path.length === 0 && issue.code === "unrecognized_keys") throw new TypeError(`Preview options contain unknown parameter ${issue.keys[0]}`);
|
|
38
|
+
throw new TypeError("Preview options must be an object");
|
|
39
|
+
}
|
|
40
|
+
export { PreviewPageRangeError, paintOptionsSchema, previewErrorSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, previewPlaceholderSchema, screenGeometrySchema, screenPointSchema, validatePaintOptions };
|