@json-to-office/core-pptx 0.27.0 → 0.28.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/dist/components/image.d.ts.map +1 -1
- package/dist/core/generator.d.ts +6 -0
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/template.d.ts.map +1 -1
- package/dist/index.js +103 -35
- package/dist/index.js.map +1 -1
- package/dist/plugin/createPresentationGenerator.d.ts +6 -0
- package/dist/plugin/createPresentationGenerator.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +7 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/baseDirContext.d.ts +19 -0
- package/dist/utils/baseDirContext.d.ts.map +1 -0
- package/dist/utils/imageSource.d.ts +14 -0
- package/dist/utils/imageSource.d.ts.map +1 -1
- package/dist/utils/warn.d.ts +1 -0
- package/dist/utils/warn.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/components/image.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/components/image.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AASjE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AA4BzE,UAAU,mBAAmB;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA4DD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,CAAC,KAAK,EACtB,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,eAAe,EACtB,QAAQ,CAAC,EAAE,eAAe,EAAE,EAC5B,UAAU,SAAK,EACf,WAAW,SAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAqKf"}
|
package/dist/core/generator.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export interface GenerationOptions extends PresentationPackagingOptions {
|
|
|
28
28
|
services?: ServicesConfig;
|
|
29
29
|
fonts?: FontRuntimeOpts;
|
|
30
30
|
validation?: GenerationValidationOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Directory that relative asset paths (image `path` props, slide
|
|
33
|
+
* background images) resolve against. Defaults to `process.cwd()` when
|
|
34
|
+
* absent (#142).
|
|
35
|
+
*/
|
|
36
|
+
baseDir?: string;
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
33
39
|
* Result from generateBufferWithWarnings
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,EACV,+BAA+B,EAC/B,eAAe,EACf,eAAe,EACf,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9E,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,EACV,+BAA+B,EAC/B,eAAe,EACf,eAAe,EACf,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9E,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,2BAA2B;IAC1C,+EAA+E;IAC/E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,4BAA4B;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/C;;;;OAIG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,UAAU,CAAC,EAAE,2BAA2B,CAAC;IACzC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED,6EAA6E;AAC7E,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;gBAE9B,MAAM,EAAE,eAAe,EAAE;CAStC;AAqBD;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAYhE;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,OAAO,GAClB,UAAU,IAAI,+BAA+B,CAI/C;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,+BAA+B,EACzC,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,eAAe,EAAE,EAC5B,YAAY,CAAC,EAAE,cAAc,EAAE,GAC9B,OAAO,CAAC,SAAS,CAAC,CAgBpB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,GAAG,+BAA+B,EACpD,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,GAAG,+BAA+B,EACpD,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAwD3B;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,GAAG,+BAA+B,EACpD,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;CAQjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,cAAc,EAGf,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/core/render.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,cAAc,EAGf,MAAM,UAAU,CAAC;AAWlB,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,qBAAqB,EAChC,QAAQ,CAAC,EAAE,eAAe,EAAE,EAC5B,YAAY,CAAC,EAAE,cAAc,EAAE,GAC9B,OAAO,CAAC,SAAS,CAAC,CAkQpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,uBAAuB,EACvB,eAAe,EACf,eAAe,EAChB,MAAM,UAAU,CAAC;AAIlB,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,eAAe,EACtB,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA2CrB"}
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ var W = {
|
|
|
19
19
|
CHART_MULTI_SERIES: "CHART_MULTI_SERIES",
|
|
20
20
|
IMAGE_NO_SOURCE: "IMAGE_NO_SOURCE",
|
|
21
21
|
IMAGE_PROBE_FAILED: "IMAGE_PROBE_FAILED",
|
|
22
|
+
IMAGE_PATH_OUTSIDE_ROOTS: "IMAGE_PATH_OUTSIDE_ROOTS",
|
|
22
23
|
MISSING_TEMPLATE: "MISSING_TEMPLATE",
|
|
23
24
|
UNKNOWN_PLACEHOLDER: "UNKNOWN_PLACEHOLDER",
|
|
24
25
|
PLACEHOLDER_NO_POSITION: "PLACEHOLDER_NO_POSITION",
|
|
@@ -741,9 +742,28 @@ function renderTextComponent(slide, props, theme, warnings, slideCtx) {
|
|
|
741
742
|
}
|
|
742
743
|
|
|
743
744
|
// src/components/image.ts
|
|
744
|
-
import
|
|
745
|
+
import path2 from "path";
|
|
745
746
|
import probe from "probe-image-size";
|
|
746
747
|
|
|
748
|
+
// src/utils/imageSource.ts
|
|
749
|
+
import path from "path";
|
|
750
|
+
|
|
751
|
+
// src/utils/baseDirContext.ts
|
|
752
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
753
|
+
import { isAbsolute, resolve } from "path";
|
|
754
|
+
var baseDirStorage = new AsyncLocalStorage();
|
|
755
|
+
function runWithBaseDir(baseDir, callback) {
|
|
756
|
+
return baseDir === void 0 ? callback() : baseDirStorage.run(resolve(baseDir), callback);
|
|
757
|
+
}
|
|
758
|
+
function getBaseDir() {
|
|
759
|
+
return baseDirStorage.getStore();
|
|
760
|
+
}
|
|
761
|
+
function resolveFromBaseDir(filePath) {
|
|
762
|
+
const base = baseDirStorage.getStore();
|
|
763
|
+
if (!base || isAbsolute(filePath)) return filePath;
|
|
764
|
+
return resolve(base, filePath);
|
|
765
|
+
}
|
|
766
|
+
|
|
747
767
|
// src/utils/imageSource.ts
|
|
748
768
|
var hasValue = (v) => typeof v === "string" && v.trim().length > 0;
|
|
749
769
|
function resolveImageSource(props) {
|
|
@@ -755,6 +775,18 @@ function resolveImageSource(props) {
|
|
|
755
775
|
if (hasValue(props.path)) return props.path;
|
|
756
776
|
return void 0;
|
|
757
777
|
}
|
|
778
|
+
function isAllowedLocalPath(resolved) {
|
|
779
|
+
const baseDir = getBaseDir();
|
|
780
|
+
const allowedRoots = baseDir ? [baseDir, process.cwd()] : [process.cwd()];
|
|
781
|
+
return allowedRoots.some(
|
|
782
|
+
(root) => resolved.startsWith(root + path.sep) || resolved === root
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
function safeLocalPath(source) {
|
|
786
|
+
if (/^(https?:\/\/|data:)/.test(source)) return source;
|
|
787
|
+
const resolved = path.resolve(resolveFromBaseDir(source));
|
|
788
|
+
return isAllowedLocalPath(resolved) ? resolved : void 0;
|
|
789
|
+
}
|
|
758
790
|
|
|
759
791
|
// src/components/image.ts
|
|
760
792
|
function isPrivateUrl(urlStr) {
|
|
@@ -785,8 +817,8 @@ async function probeImageSize(imagePath, warnings) {
|
|
|
785
817
|
const result2 = await probe(imagePath, { timeout: 5e3 });
|
|
786
818
|
return { width: result2.width, height: result2.height };
|
|
787
819
|
}
|
|
788
|
-
const resolved =
|
|
789
|
-
if (!resolved
|
|
820
|
+
const resolved = path2.resolve(resolveFromBaseDir(imagePath));
|
|
821
|
+
if (!isAllowedLocalPath(resolved)) return void 0;
|
|
790
822
|
const { createReadStream } = await import("fs");
|
|
791
823
|
const result = await probe(createReadStream(resolved));
|
|
792
824
|
return result ? { width: result.width, height: result.height } : void 0;
|
|
@@ -824,7 +856,17 @@ async function renderImageComponent(slide, props, theme, warnings, slideWidth =
|
|
|
824
856
|
if (source.startsWith("data:")) {
|
|
825
857
|
opts.data = source;
|
|
826
858
|
} else {
|
|
827
|
-
|
|
859
|
+
const resolved = safeLocalPath(source);
|
|
860
|
+
if (resolved === void 0) {
|
|
861
|
+
warn(
|
|
862
|
+
warnings,
|
|
863
|
+
W.IMAGE_PATH_OUTSIDE_ROOTS,
|
|
864
|
+
`Image path resolves outside the document base directory: ${source}`,
|
|
865
|
+
{ component: "image" }
|
|
866
|
+
);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
opts.path = resolved;
|
|
828
870
|
}
|
|
829
871
|
if (props.x !== void 0) opts.x = props.x;
|
|
830
872
|
if (props.y !== void 0) opts.y = props.y;
|
|
@@ -1625,10 +1667,13 @@ function buildSlideTemplateProps(def, theme, warnings) {
|
|
|
1625
1667
|
const result = { title: def.name };
|
|
1626
1668
|
if (def.background) {
|
|
1627
1669
|
if (def.background.color) {
|
|
1628
|
-
result.background = {
|
|
1670
|
+
result.background = {
|
|
1671
|
+
color: resolveColor(def.background.color, theme, warnings)
|
|
1672
|
+
};
|
|
1629
1673
|
} else if (def.background.image) {
|
|
1630
1674
|
if (def.background.image.path) {
|
|
1631
|
-
|
|
1675
|
+
const bgPath = safeLocalPath(def.background.image.path);
|
|
1676
|
+
if (bgPath !== void 0) result.background = { path: bgPath };
|
|
1632
1677
|
} else if (def.background.image.base64) {
|
|
1633
1678
|
result.background = { data: def.background.image.base64 };
|
|
1634
1679
|
}
|
|
@@ -1640,10 +1685,18 @@ function buildSlideTemplateProps(def, theme, warnings) {
|
|
|
1640
1685
|
x: def.slideNumber.x,
|
|
1641
1686
|
y: def.slideNumber.y
|
|
1642
1687
|
};
|
|
1643
|
-
if (def.slideNumber.w !== void 0)
|
|
1644
|
-
|
|
1645
|
-
if (def.slideNumber.
|
|
1646
|
-
|
|
1688
|
+
if (def.slideNumber.w !== void 0)
|
|
1689
|
+
result.slideNumber.w = def.slideNumber.w;
|
|
1690
|
+
if (def.slideNumber.h !== void 0)
|
|
1691
|
+
result.slideNumber.h = def.slideNumber.h;
|
|
1692
|
+
if (def.slideNumber.color)
|
|
1693
|
+
result.slideNumber.color = resolveColor(
|
|
1694
|
+
def.slideNumber.color,
|
|
1695
|
+
theme,
|
|
1696
|
+
warnings
|
|
1697
|
+
);
|
|
1698
|
+
if (def.slideNumber.fontSize)
|
|
1699
|
+
result.slideNumber.fontSize = def.slideNumber.fontSize;
|
|
1647
1700
|
}
|
|
1648
1701
|
return result;
|
|
1649
1702
|
}
|
|
@@ -1736,7 +1789,8 @@ async function renderPresentation(processed, warnings, pendingFills) {
|
|
|
1736
1789
|
};
|
|
1737
1790
|
} else if (slideData.background.image) {
|
|
1738
1791
|
if (slideData.background.image.path) {
|
|
1739
|
-
|
|
1792
|
+
const bgPath = safeLocalPath(slideData.background.image.path);
|
|
1793
|
+
if (bgPath !== void 0) slide.background = { path: bgPath };
|
|
1740
1794
|
} else if (slideData.background.image.base64) {
|
|
1741
1795
|
slide.background = { data: slideData.background.image.base64 };
|
|
1742
1796
|
}
|
|
@@ -2013,24 +2067,24 @@ function remapChartReferences(value, chartIds) {
|
|
|
2013
2067
|
);
|
|
2014
2068
|
}
|
|
2015
2069
|
async function canonicalizeChartIds(zip) {
|
|
2016
|
-
const sourceIds = Object.keys(zip.files).map((
|
|
2070
|
+
const sourceIds = Object.keys(zip.files).map((path3) => path3.match(/^ppt\/charts\/chart(\d+)\.xml$/)?.[1]).filter((value) => value !== void 0).map(Number).sort((a, b) => a - b);
|
|
2017
2071
|
const chartIds = new Map(sourceIds.map((id, index) => [id, index + 1]));
|
|
2018
2072
|
if (chartIds.size === 0) return;
|
|
2019
|
-
for (const [
|
|
2020
|
-
if (entry.dir || !
|
|
2073
|
+
for (const [path3, entry] of Object.entries(zip.files)) {
|
|
2074
|
+
if (entry.dir || !path3.endsWith(".xml") && !path3.endsWith(".rels")) {
|
|
2021
2075
|
continue;
|
|
2022
2076
|
}
|
|
2023
2077
|
const xml = await entry.async("string");
|
|
2024
2078
|
const remapped = remapChartReferences(xml, chartIds);
|
|
2025
|
-
if (remapped !== xml) zip.file(
|
|
2079
|
+
if (remapped !== xml) zip.file(path3, remapped);
|
|
2026
2080
|
}
|
|
2027
2081
|
const renames = [];
|
|
2028
|
-
for (const [
|
|
2082
|
+
for (const [path3, entry] of Object.entries(zip.files)) {
|
|
2029
2083
|
if (entry.dir) continue;
|
|
2030
|
-
const remappedPath = remapChartReferences(
|
|
2031
|
-
if (remappedPath ===
|
|
2084
|
+
const remappedPath = remapChartReferences(path3, chartIds);
|
|
2085
|
+
if (remappedPath === path3) continue;
|
|
2032
2086
|
renames.push({
|
|
2033
|
-
from:
|
|
2087
|
+
from: path3,
|
|
2034
2088
|
to: remappedPath,
|
|
2035
2089
|
data: await entry.async("nodebuffer"),
|
|
2036
2090
|
date: entry.date
|
|
@@ -2060,12 +2114,12 @@ async function canonicalizePackage(zip, generatedAt, depth = 0) {
|
|
|
2060
2114
|
zip.file("docProps/core.xml", coreXml);
|
|
2061
2115
|
}
|
|
2062
2116
|
if (depth < 3) {
|
|
2063
|
-
for (const [
|
|
2064
|
-
if (entry.dir || !EMBEDDED_OFFICE_PACKAGE.test(
|
|
2117
|
+
for (const [path3, entry] of Object.entries(zip.files)) {
|
|
2118
|
+
if (entry.dir || !EMBEDDED_OFFICE_PACKAGE.test(path3)) continue;
|
|
2065
2119
|
try {
|
|
2066
2120
|
const nested = await JSZip.loadAsync(await entry.async("nodebuffer"));
|
|
2067
2121
|
await canonicalizePackage(nested, generatedAt, depth + 1);
|
|
2068
|
-
zip.file(
|
|
2122
|
+
zip.file(path3, await generateZip(nested));
|
|
2069
2123
|
} catch {
|
|
2070
2124
|
}
|
|
2071
2125
|
}
|
|
@@ -2077,8 +2131,8 @@ async function canonicalizePackage(zip, generatedAt, depth = 0) {
|
|
|
2077
2131
|
async function packagePresentationBuffer(buffer, options = {}) {
|
|
2078
2132
|
const zip = await JSZip.loadAsync(buffer);
|
|
2079
2133
|
let changed = false;
|
|
2080
|
-
for (const [
|
|
2081
|
-
if (!
|
|
2134
|
+
for (const [path3, entry] of Object.entries(zip.files)) {
|
|
2135
|
+
if (!path3.match(/^ppt\/slides\/slide\d+\.xml$/)) continue;
|
|
2082
2136
|
let xml = await entry.async("string");
|
|
2083
2137
|
let fileChanged = false;
|
|
2084
2138
|
if (xml.includes(MEDIUM_STYLE_2_ACCENT_1)) {
|
|
@@ -2093,7 +2147,7 @@ async function packagePresentationBuffer(buffer, options = {}) {
|
|
|
2093
2147
|
}
|
|
2094
2148
|
}
|
|
2095
2149
|
if (fileChanged) {
|
|
2096
|
-
zip.file(
|
|
2150
|
+
zip.file(path3, xml);
|
|
2097
2151
|
changed = true;
|
|
2098
2152
|
}
|
|
2099
2153
|
}
|
|
@@ -2152,8 +2206,10 @@ async function generatePresentation(document, options, warnings, pendingFills) {
|
|
|
2152
2206
|
throw new Error("Top-level component must be a pptx component");
|
|
2153
2207
|
}
|
|
2154
2208
|
assertNoContentConflicts(document);
|
|
2155
|
-
|
|
2156
|
-
|
|
2209
|
+
return runWithBaseDir(options?.baseDir, async () => {
|
|
2210
|
+
const processed = processPresentation(document, options);
|
|
2211
|
+
return await renderPresentation(processed, warnings, pendingFills);
|
|
2212
|
+
});
|
|
2157
2213
|
}
|
|
2158
2214
|
async function generateBufferFromJson(jsonConfig, options) {
|
|
2159
2215
|
const result = await generateBufferWithWarnings(jsonConfig, options);
|
|
@@ -2472,7 +2528,8 @@ function createBuilderImpl(state) {
|
|
|
2472
2528
|
services: state.services,
|
|
2473
2529
|
fonts: state.fonts,
|
|
2474
2530
|
validation: state.validation,
|
|
2475
|
-
packaging: state.packaging
|
|
2531
|
+
packaging: state.packaging,
|
|
2532
|
+
baseDir: state.baseDir
|
|
2476
2533
|
};
|
|
2477
2534
|
return createBuilderImpl(
|
|
2478
2535
|
newState
|
|
@@ -2565,12 +2622,22 @@ function createBuilderImpl(state) {
|
|
|
2565
2622
|
state.fonts
|
|
2566
2623
|
);
|
|
2567
2624
|
assertNoContentConflicts(processedDocument);
|
|
2568
|
-
const
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2625
|
+
const { pendingFills, pptx } = await runWithBaseDir(
|
|
2626
|
+
options?.baseDir ?? state.baseDir,
|
|
2627
|
+
async () => {
|
|
2628
|
+
const processed = processPresentation(processedDocument, {
|
|
2629
|
+
theme: resolvedTheme,
|
|
2630
|
+
services: state.services
|
|
2631
|
+
});
|
|
2632
|
+
const pendingFills2 = [];
|
|
2633
|
+
const pptx2 = await renderPresentation(
|
|
2634
|
+
processed,
|
|
2635
|
+
warnings,
|
|
2636
|
+
pendingFills2
|
|
2637
|
+
);
|
|
2638
|
+
return { pendingFills: pendingFills2, pptx: pptx2 };
|
|
2639
|
+
}
|
|
2640
|
+
);
|
|
2574
2641
|
const data = await pptx.write({ outputType: "nodebuffer" });
|
|
2575
2642
|
const buffer = await packagePresentationBuffer(data, {
|
|
2576
2643
|
deterministic: options?.deterministic ?? state.packaging.deterministic,
|
|
@@ -2693,7 +2760,8 @@ function createPresentationGenerator(options = {}) {
|
|
|
2693
2760
|
packaging: {
|
|
2694
2761
|
deterministic: options.deterministic,
|
|
2695
2762
|
generatedAt: options.generatedAt
|
|
2696
|
-
}
|
|
2763
|
+
},
|
|
2764
|
+
baseDir: options.baseDir
|
|
2697
2765
|
};
|
|
2698
2766
|
return createBuilderImpl(initialState);
|
|
2699
2767
|
}
|