@officedk/pptxdk 0.1.0 → 0.2.1
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/build.d.ts +14 -76
- package/dist/build.js +69 -97
- package/dist/cli.js +1 -1
- package/dist/core/dist/capabilities/audio/audio-declaration.js +7 -0
- package/dist/core/dist/capabilities/audio/audio-source.js +172 -0
- package/dist/core/dist/capabilities/audio/entry.js +122 -0
- package/dist/core/dist/capabilities/box/box-codegen.js +83 -0
- package/dist/core/dist/capabilities/box/box-declaration.js +32 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/box/box.js +32 -29
- package/dist/core/dist/capabilities/box/entry.js +2 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-codegen.js +17 -22
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-declaration.js +2 -2
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-import.js +1025 -471
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-labels.js +30 -3
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-model.js +3 -3
- package/dist/{capabilities/dist/chart/preview/number-format.js → core/dist/capabilities/chart/chart-number-format.js} +1 -1
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-schemas.js +216 -212
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart-xml.js +41 -36
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/chart.js +228 -171
- package/dist/core/dist/capabilities/chart/entry.js +2 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/axes-and-grid.js +23 -10
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/bar-column.js +1 -1
- package/dist/core/dist/capabilities/chart/preview/data-labels.js +474 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/error-bars.js +3 -1
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/index.js +30 -9
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/layout.js +160 -89
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/legend.js +4 -4
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/line-area.js +4 -4
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/markers.js +1 -1
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/pie-doughnut.js +39 -60
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/scales.js +1 -1
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/scatter.js +3 -3
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/style.js +15 -3
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/text-render.js +34 -24
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/trendlines.js +5 -5
- package/dist/{capabilities/dist → core/dist/capabilities}/chart/preview/types.js +1 -1
- package/dist/core/dist/capabilities/comment/comment-codegen.js +25 -0
- package/dist/core/dist/capabilities/comment/comment-declaration.js +37 -0
- package/dist/core/dist/capabilities/comment/comment-import.js +176 -0
- package/dist/core/dist/capabilities/comment/comment.js +141 -0
- package/dist/core/dist/capabilities/comment/entry.js +1 -0
- package/dist/core/dist/capabilities/footer-placeholder/entry.js +2 -0
- package/dist/core/dist/capabilities/footer-placeholder/footer-placeholder-codegen.js +16 -0
- package/dist/{capabilities/dist/masters → core/dist/capabilities/footer-placeholder}/footer-placeholder.js +194 -133
- package/dist/core/dist/capabilities/footer-placeholder/print-header-footer-import.js +121 -0
- package/dist/core/dist/capabilities/footer-placeholder/print-header-footer.js +123 -0
- package/dist/core/dist/capabilities/group/entry.js +2 -0
- package/dist/core/dist/capabilities/group/group-codegen.js +73 -0
- package/dist/core/dist/capabilities/group/group-declaration.js +41 -0
- package/dist/core/dist/capabilities/group/group-import.js +608 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/group/group-xml.js +4 -3
- package/dist/core/dist/capabilities/group/group.js +260 -0
- package/dist/core/dist/capabilities/image/entry.js +4 -0
- package/dist/core/dist/capabilities/image/image-codegen.js +59 -0
- package/dist/core/dist/capabilities/image/image-declaration.js +8 -0
- package/dist/core/dist/capabilities/image/image-import.js +26 -0
- package/dist/core/dist/capabilities/image/image.js +57 -0
- package/dist/core/dist/capabilities/line/entry.js +3 -0
- package/dist/core/dist/capabilities/line/line-codegen.js +88 -0
- package/dist/core/dist/capabilities/line/line-declaration.js +78 -0
- package/dist/core/dist/capabilities/line/line-import.js +424 -0
- package/dist/core/dist/capabilities/line/line-xml.js +9 -0
- package/dist/core/dist/capabilities/line/line.js +329 -0
- package/dist/core/dist/capabilities/masters/entry.js +1 -0
- package/dist/core/dist/capabilities/masters/masters-codegen.js +50 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/masters/masters.js +35 -47
- package/dist/core/dist/capabilities/motion/entry.js +5 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-codegen.js +97 -51
- package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-import.js +653 -102
- package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-plan.js +317 -163
- package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion-query.js +9 -6
- package/dist/{capabilities/dist → core/dist/capabilities}/motion/motion.js +357 -108
- package/dist/core/dist/capabilities/notes/entry.js +2 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-codegen.js +5 -7
- package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-declaration.js +2 -2
- package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-import.js +16 -13
- package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes-schemas.js +12 -9
- package/dist/{capabilities/dist → core/dist/capabilities}/notes/notes.js +20 -42
- package/dist/{import/dist/sections.js → core/dist/capabilities/notes/sections-import.js} +5 -5
- package/dist/core/dist/capabilities/placeholder/entry.js +3 -0
- package/dist/core/dist/capabilities/placeholder/placeholder-codegen.js +44 -0
- package/dist/core/dist/capabilities/placeholder/placeholder-schemas.js +31 -0
- package/dist/core/dist/capabilities/placeholder/placeholder.js +394 -0
- package/dist/core/dist/capabilities/shape/entry.js +6 -0
- package/dist/core/dist/capabilities/shape/shape-codegen.js +112 -0
- package/dist/core/dist/capabilities/shape/shape-import.js +152 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/shape/shape-xml.js +1 -1
- package/dist/{capabilities/dist → core/dist/capabilities}/shape/shape.js +100 -103
- package/dist/core/dist/capabilities/shared/container-slots.js +59 -0
- package/dist/core/dist/capabilities/shared/date-time.js +98 -0
- package/dist/core/dist/capabilities/shared/font/font-embedding.js +118 -0
- package/dist/core/dist/capabilities/shared/font/font-engine.js +855 -0
- package/dist/core/dist/capabilities/shared/font/font-import.js +805 -0
- package/dist/{capabilities/dist → core/dist/capabilities/shared}/font/font-subset.js +24 -9
- package/dist/core/dist/capabilities/shared/font/font.js +72 -0
- package/dist/{capabilities/dist/shape/shape-codegen.js → core/dist/capabilities/shared/geometry-codegen.js} +4 -69
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/geometry.js +384 -123
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/identity.js +56 -38
- package/dist/core/dist/capabilities/shared/image-codegen.js +94 -0
- package/dist/{capabilities/dist/image → core/dist/capabilities/shared}/image-decode.js +17 -56
- package/dist/{capabilities/dist/image → core/dist/capabilities/shared}/image-schemas.js +49 -61
- package/dist/core/dist/capabilities/shared/line-match.js +78 -0
- package/dist/core/dist/capabilities/shared/media-codegen.js +86 -0
- package/dist/core/dist/capabilities/shared/media-import.js +156 -0
- package/dist/core/dist/capabilities/shared/media-placement.js +20 -0
- package/dist/core/dist/capabilities/shared/media-poster.js +50 -0
- package/dist/core/dist/capabilities/shared/media-schemas.js +60 -0
- package/dist/core/dist/capabilities/shared/media-source.js +107 -0
- package/dist/core/dist/capabilities/shared/media-trim.js +102 -0
- package/dist/core/dist/capabilities/shared/media.js +134 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/morph-api.js +5 -5
- package/dist/core/dist/capabilities/shared/motion-api.js +770 -0
- package/dist/core/dist/capabilities/shared/motion-schemas.js +353 -0
- package/dist/{capabilities/dist/image/image-import.js → core/dist/capabilities/shared/picture-import.js} +313 -168
- package/dist/core/dist/capabilities/shared/picture-xml.js +13 -0
- package/dist/core/dist/capabilities/shared/picture.js +510 -0
- package/dist/core/dist/capabilities/shared/placeholder-import.js +268 -0
- package/dist/core/dist/capabilities/shared/placeholder-roles.js +42 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/preset-definitions.js +1221 -188
- package/dist/core/dist/capabilities/shared/print-xml.js +77 -0
- package/dist/core/dist/capabilities/shared/rich-text-codegen.js +119 -0
- package/dist/core/dist/capabilities/shared/rich-text-import.js +472 -0
- package/dist/core/dist/capabilities/shared/shape-declaration.js +45 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/style-inheritance.js +26 -24
- package/dist/core/dist/capabilities/shared/text-declaration.js +31 -0
- package/dist/core/dist/capabilities/shared/text-schemas.js +241 -0
- package/dist/core/dist/capabilities/shared/text-service.js +2563 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/shared/visual.js +441 -137
- package/dist/core/dist/capabilities/slide-background/entry.js +1 -0
- package/dist/core/dist/capabilities/slide-background/slide-background-codegen.js +15 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/slide-background/slide-background-import.js +12 -7
- package/dist/core/dist/capabilities/slide-background/slide-background-xml.js +33 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/slide-background/slide-background.js +61 -50
- package/dist/core/dist/capabilities/table/entry.js +2 -0
- package/dist/core/dist/capabilities/table/table-codegen.js +118 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/table/table-declaration.js +2 -2
- package/dist/{capabilities/dist → core/dist/capabilities}/table/table-import.js +116 -84
- package/dist/core/dist/capabilities/table/table-schemas.js +337 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/table/table-xml.js +13 -15
- package/dist/{capabilities/dist → core/dist/capabilities}/table/table.js +284 -192
- package/dist/core/dist/capabilities/text/entry.js +3 -0
- package/dist/core/dist/capabilities/text/text-codegen.js +66 -0
- package/dist/core/dist/capabilities/text/text-import.js +468 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/text/text-xml.js +3 -4
- package/dist/{capabilities/dist → core/dist/capabilities}/text/text.js +103 -111
- package/dist/core/dist/capabilities/transition/entry.js +3 -0
- package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-api.js +13 -16
- package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-codegen.js +2 -3
- package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition-import.js +25 -27
- package/dist/{capabilities/dist → core/dist/capabilities}/transition/transition.js +23 -23
- package/dist/core/dist/capabilities/video/entry.js +77 -0
- package/dist/core/dist/capabilities/video/video-declaration.js +7 -0
- package/dist/core/dist/capabilities/video/video-source.js +42 -0
- package/dist/{codegen/dist → core/dist/codegen}/assets.js +16 -10
- package/dist/{codegen/dist → core/dist/codegen}/codegen.js +152 -140
- package/dist/{codegen/dist → core/dist/codegen}/identifiers.js +27 -1
- package/dist/{codegen/dist → core/dist/codegen}/index.js +2 -2
- package/dist/{codegen/dist → core/dist/codegen}/printer.js +23 -4
- package/dist/core/dist/document/all.js +41 -0
- package/dist/core/dist/document/default.js +10 -0
- package/dist/core/dist/document/document.js +218 -0
- package/dist/core/dist/document/index.js +62 -0
- package/dist/core/dist/document/stages.js +54 -0
- package/dist/{emit/dist → core/dist/emit}/emit.js +173 -90
- package/dist/core/dist/emit/index.js +6 -0
- package/dist/core/dist/emit/ooxml.js +241 -0
- package/dist/core/dist/import/import.js +547 -0
- package/dist/core/dist/import/index.js +19 -0
- package/dist/{import/dist → core/dist/import}/masters.js +404 -328
- package/dist/core/dist/import/media-timing.js +233 -0
- package/dist/{import/dist → core/dist/import}/notes-masters.js +48 -45
- package/dist/core/dist/index.js +47 -15
- package/dist/core/dist/{author-ids.js → kernel/author-ids.js} +9 -6
- package/dist/core/dist/{author-schemas.js → kernel/author-schemas.js} +105 -127
- package/dist/core/dist/{block-flex-layout.js → kernel/block-flex-layout.js} +225 -142
- package/dist/core/dist/kernel/build.js +4 -0
- package/dist/core/dist/kernel/capability.js +17 -0
- package/dist/core/dist/kernel/codegen.js +97 -0
- package/dist/core/dist/kernel/container-slots.js +104 -0
- package/dist/core/dist/kernel/date-time-format.js +18 -0
- package/dist/core/dist/kernel/declaration-snapshot.js +68 -0
- package/dist/core/dist/{declaration.js → kernel/declaration.js} +3 -2
- package/dist/core/dist/kernel/diagnostics.js +370 -0
- package/dist/core/dist/kernel/document-internals.js +26 -0
- package/dist/core/dist/{document.js → kernel/document.js} +23 -13
- package/dist/core/dist/kernel/drawing-units.js +14 -0
- package/dist/core/dist/kernel/font-seal.js +204 -0
- package/dist/core/dist/{geometry-schemas.js → kernel/geometry-schemas.js} +21 -18
- package/dist/core/dist/{grid-layout.js → kernel/grid-layout.js} +177 -72
- package/dist/core/dist/{host.js → kernel/host.js} +1 -1
- package/dist/core/dist/kernel/index.js +24 -0
- package/dist/core/dist/kernel/input-values.js +62 -0
- package/dist/core/dist/kernel/layout-definition.js +7 -0
- package/dist/core/dist/{layout-protocol.js → kernel/layout-protocol.js} +5 -10
- package/dist/core/dist/{layout-schemas.js → kernel/layout-schemas.js} +33 -44
- package/dist/core/dist/kernel/layout.js +339 -0
- package/dist/core/dist/kernel/masters.js +171 -0
- package/dist/core/dist/{morph.js → kernel/morph.js} +1 -1
- package/dist/core/dist/kernel/placeholders.js +289 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/alternate-content.js +1 -1
- package/dist/{import/dist → core/dist/kernel/pptx-read}/diagnostics.js +33 -29
- package/dist/core/dist/kernel/pptx-read/drawing-list-import.js +251 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/fonts.js +71 -12
- package/dist/core/dist/kernel/pptx-read/index.js +15 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/mechanism.js +1 -1
- package/dist/core/dist/kernel/pptx-read/media.js +26 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/namespaces.js +6 -7
- package/dist/{import/dist → core/dist/kernel/pptx-read}/opc.js +62 -13
- package/dist/{import/dist → core/dist/kernel/pptx-read}/resources.js +1 -1
- package/dist/core/dist/kernel/pptx-read/shape-tree.js +57 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/themes.js +182 -41
- package/dist/{import/dist → core/dist/kernel/pptx-read}/visual.js +175 -88
- package/dist/core/dist/kernel/pptx-read/xml-fragments.js +320 -0
- package/dist/{import/dist → core/dist/kernel/pptx-read}/xml-reader.js +8 -1
- package/dist/{emit/dist → core/dist/kernel/pptx-write}/shape-tree.js +1 -1
- package/dist/core/dist/kernel/pptx-write/timing.js +52 -0
- package/dist/{emit/dist/ooxml.js → core/dist/kernel/pptx-write/xml.js} +133 -290
- package/dist/core/dist/{query.js → kernel/query.js} +76 -37
- package/dist/core/dist/{resolution.js → kernel/resolution.js} +2 -1
- package/dist/core/dist/kernel/resolve-work.js +58 -0
- package/dist/core/dist/{resolve.js → kernel/resolve.js} +797 -409
- package/dist/core/dist/kernel/resource-source.js +11 -0
- package/dist/core/dist/kernel/stage-options.js +312 -0
- package/dist/core/dist/{theme.js → kernel/theme.js} +399 -289
- package/dist/core/dist/kernel/transform-geometry.js +72 -0
- package/dist/core/dist/kernel/xml-values.js +13 -0
- package/dist/document-C0lPlH-L.d.ts +1442 -0
- package/dist/index-B9_OUeA-.d.ts +2238 -0
- package/dist/index-BJEzQxWV.d.ts +75 -0
- package/dist/index-DA9flrlR.d.ts +146 -0
- package/dist/index-GSt0t9VO.d.ts +54 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +75 -61
- package/dist/node.d.ts +37 -35
- package/dist/node.js +125 -51
- package/dist/pptxdk/src/cli-commands.js +79 -81
- package/dist/pptxdk/src/compose.js +32 -24
- package/dist/pptxdk/src/preview-result.js +24 -0
- package/dist/{capabilities/dist/image → preview/dist}/gif-decoder.js +5 -5
- package/dist/preview/dist/index.js +229 -77
- package/dist/preview/dist/options.js +17 -26
- package/dist/preview/dist/raster.js +66 -0
- package/dist/preview/dist/svg-guard.js +1090 -0
- package/dist/preview.d.ts +6 -3
- package/dist/preview.js +8 -24
- package/dist/react/dist/append.js +3 -3
- package/dist/react/dist/author/audio-elements.js +14 -0
- package/dist/{capabilities/dist/box → react/dist/author}/box-elements.js +5 -3
- package/dist/react/dist/author/chart-elements.js +14 -0
- package/dist/react/dist/author/comment-elements.js +15 -0
- package/dist/react/dist/author/group-elements.js +14 -0
- package/dist/react/dist/author/image-elements.js +14 -0
- package/dist/react/dist/author/line-elements.js +14 -0
- package/dist/{capabilities/dist/motion → react/dist/author}/motion-elements.js +6 -4
- package/dist/react/dist/author/notes-elements.js +14 -0
- package/dist/react/dist/author/placeholder-elements.js +14 -0
- package/dist/react/dist/author/shape-elements.js +14 -0
- package/dist/{capabilities/dist/table → react/dist/author}/table-elements.js +6 -4
- package/dist/react/dist/author/text-elements.js +64 -0
- package/dist/react/dist/author/video-elements.js +14 -0
- package/dist/react/dist/document-adapter.js +376 -37
- package/dist/react/dist/elements.js +30 -4
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +47 -12
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +26 -26
- package/dist/react.d.ts +174 -50
- package/dist/react.js +31 -27
- package/dist/stages-DYHSHKt4.d.ts +80 -0
- package/dist/vanilla.d.ts +4 -4
- package/dist/vanilla.js +14 -14
- package/package.json +6 -8
- package/README.md +0 -49
- package/dist/capabilities/dist/all.js +0 -32
- package/dist/capabilities/dist/box/box-codegen.js +0 -51
- package/dist/capabilities/dist/box/box-declaration.js +0 -31
- package/dist/capabilities/dist/chart/chart-elements.js +0 -12
- package/dist/capabilities/dist/chart/preview/data-labels.js +0 -334
- package/dist/capabilities/dist/document.js +0 -148
- package/dist/capabilities/dist/font/font-embedding.js +0 -289
- package/dist/capabilities/dist/font/font-family.js +0 -10
- package/dist/capabilities/dist/font/font-import.js +0 -302
- package/dist/capabilities/dist/font/font.js +0 -25
- package/dist/capabilities/dist/group/group-codegen.js +0 -51
- package/dist/capabilities/dist/group/group-declaration.js +0 -42
- package/dist/capabilities/dist/group/group-elements.js +0 -12
- package/dist/capabilities/dist/group/group-import.js +0 -319
- package/dist/capabilities/dist/group/group.js +0 -211
- package/dist/capabilities/dist/image/image-codegen.js +0 -94
- package/dist/capabilities/dist/image/image-declaration.js +0 -8
- package/dist/capabilities/dist/image/image-elements.js +0 -12
- package/dist/capabilities/dist/image/image-xml.js +0 -12
- package/dist/capabilities/dist/image/image.js +0 -472
- package/dist/capabilities/dist/masters/masters-codegen.js +0 -21
- package/dist/capabilities/dist/motion/motion-api.js +0 -527
- package/dist/capabilities/dist/motion/motion-schemas.js +0 -216
- package/dist/capabilities/dist/notes/notes-elements.js +0 -12
- package/dist/capabilities/dist/notes/notes-xml.js +0 -38
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +0 -23
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +0 -12
- package/dist/capabilities/dist/placeholder/placeholder.js +0 -292
- package/dist/capabilities/dist/shape/shape-declaration.js +0 -57
- package/dist/capabilities/dist/shape/shape-elements.js +0 -12
- package/dist/capabilities/dist/shape/shape-import.js +0 -579
- package/dist/capabilities/dist/shared/placeholder-import.js +0 -113
- package/dist/capabilities/dist/shared/style-parse.js +0 -11
- package/dist/capabilities/dist/shared/text-schemas.js +0 -216
- package/dist/capabilities/dist/shared/text-service.js +0 -1883
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +0 -44
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +0 -21
- package/dist/capabilities/dist/table/table-codegen.js +0 -81
- package/dist/capabilities/dist/table/table-schemas.js +0 -279
- package/dist/capabilities/dist/text/text-codegen.js +0 -129
- package/dist/capabilities/dist/text/text-declaration.js +0 -19
- package/dist/capabilities/dist/text/text-elements.js +0 -38
- package/dist/capabilities/dist/text/text-import.js +0 -1077
- package/dist/capability-D_xeNVIw.d.ts +0 -29496
- package/dist/codegen/dist/types.js +0 -49
- package/dist/core/dist/build.js +0 -4
- package/dist/core/dist/capability.js +0 -13
- package/dist/core/dist/diagnostics.js +0 -21
- package/dist/core/dist/document-internals.js +0 -13
- package/dist/core/dist/input-values.js +0 -45
- package/dist/core/dist/layout.js +0 -299
- package/dist/core/dist/masters.js +0 -169
- package/dist/core/dist/placeholders.js +0 -213
- package/dist/core/dist/stage-options.js +0 -67
- package/dist/document-BHPUODPP.d.ts +0 -27759
- package/dist/emit/dist/index.js +0 -5
- package/dist/import/dist/import.js +0 -504
- package/dist/import/dist/index.js +0 -16
- package/dist/import/dist/xml-fragments.js +0 -36
- package/dist/index-B5m3hqjC.d.ts +0 -7
- package/dist/index-CCy-Yo8G.d.ts +0 -1208
- package/dist/index-DpxcZ4Gs.d.ts +0 -725
- package/dist/pptxdk/src/slide.js +0 -9
- package/dist/preview-Cfw0QdMM.d.ts +0 -86
- package/dist/transition-Cips9wma.d.ts +0 -82
|
@@ -0,0 +1,1090 @@
|
|
|
1
|
+
import { bytesSha256 } from "../../core/dist/kernel/font-seal.js";
|
|
2
|
+
import "../../core/dist/kernel/index.js";
|
|
3
|
+
// ../preview/dist/svg-guard.js
|
|
4
|
+
const EPSILON = 1e-6;
|
|
5
|
+
const SAFE_OFFSCREEN_PAD = 512;
|
|
6
|
+
const MAX_BLUR_STD_DEVIATION = 256;
|
|
7
|
+
const RASTER_TOKEN_PREFIX = "urn:pptxdk-raster:";
|
|
8
|
+
function createPageRasterRegistry(idPrefix) {
|
|
9
|
+
const entries = [];
|
|
10
|
+
const byBytesRef = /* @__PURE__ */ new Map();
|
|
11
|
+
const byDigest = /* @__PURE__ */ new Map();
|
|
12
|
+
return {
|
|
13
|
+
idPrefix,
|
|
14
|
+
get size() {
|
|
15
|
+
return entries.length;
|
|
16
|
+
},
|
|
17
|
+
register(resource) {
|
|
18
|
+
let byType = byBytesRef.get(resource.bytes);
|
|
19
|
+
const refHit = byType?.get(resource.contentType);
|
|
20
|
+
if (refHit !== void 0) return `${RASTER_TOKEN_PREFIX}${refHit.id}`;
|
|
21
|
+
const digestKey = `${resource.contentType}:${bytesSha256(resource.bytes)}`;
|
|
22
|
+
let entry = byDigest.get(digestKey);
|
|
23
|
+
if (entry === void 0) {
|
|
24
|
+
entry = {
|
|
25
|
+
id: entries.length,
|
|
26
|
+
contentType: resource.contentType,
|
|
27
|
+
bytes: resource.bytes
|
|
28
|
+
};
|
|
29
|
+
entries.push(entry);
|
|
30
|
+
byDigest.set(digestKey, entry);
|
|
31
|
+
}
|
|
32
|
+
if (byType === void 0) {
|
|
33
|
+
byType = /* @__PURE__ */ new Map();
|
|
34
|
+
byBytesRef.set(resource.bytes, byType);
|
|
35
|
+
}
|
|
36
|
+
byType.set(resource.contentType, entry);
|
|
37
|
+
return `${RASTER_TOKEN_PREFIX}${entry.id}`;
|
|
38
|
+
},
|
|
39
|
+
getEntry(id) {
|
|
40
|
+
return entries[id];
|
|
41
|
+
},
|
|
42
|
+
getDataUri(entry) {
|
|
43
|
+
entry.dataUri ??= `data:${entry.contentType};base64,${Buffer.from(entry.bytes).toString("base64")}`;
|
|
44
|
+
return entry.dataUri;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const IDENTITY_MATRIX = [
|
|
49
|
+
1,
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
1,
|
|
53
|
+
0,
|
|
54
|
+
0
|
|
55
|
+
];
|
|
56
|
+
function decodeXmlEntities(value) {
|
|
57
|
+
return value.replaceAll(""", "\"").replaceAll("'", "'").replaceAll("<", "<").replaceAll(">", ">").replaceAll("&", "&");
|
|
58
|
+
}
|
|
59
|
+
function encodeXmlAttr(value) {
|
|
60
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
61
|
+
}
|
|
62
|
+
function parseAttributes(raw) {
|
|
63
|
+
const attrs = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const match of raw.matchAll(/([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/gu)) {
|
|
65
|
+
const key = match[1];
|
|
66
|
+
if (key === void 0) continue;
|
|
67
|
+
const val = match[2] ?? match[3] ?? "";
|
|
68
|
+
attrs.set(key, decodeXmlEntities(val));
|
|
69
|
+
}
|
|
70
|
+
return attrs;
|
|
71
|
+
}
|
|
72
|
+
function parseSvgTree(svg) {
|
|
73
|
+
const root = [];
|
|
74
|
+
const stack = [];
|
|
75
|
+
const tagPattern = /<(\/?)([A-Za-z_:][\w:.-]*)([^>]*?)(\/?)>/gu;
|
|
76
|
+
let lastIndex = 0;
|
|
77
|
+
const pushNode = (node) => {
|
|
78
|
+
const parent = stack.at(-1);
|
|
79
|
+
if (parent !== void 0) parent.children.push(node);
|
|
80
|
+
else root.push(node);
|
|
81
|
+
};
|
|
82
|
+
for (const match of svg.matchAll(tagPattern)) {
|
|
83
|
+
const index = match.index ?? 0;
|
|
84
|
+
if (index > lastIndex) {
|
|
85
|
+
const text = svg.slice(lastIndex, index);
|
|
86
|
+
if (text !== "") pushNode({
|
|
87
|
+
kind: "text",
|
|
88
|
+
text
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
lastIndex = index + match[0].length;
|
|
92
|
+
const isClosing = match[1] === "/";
|
|
93
|
+
const tag = match[2];
|
|
94
|
+
const rawAttrs = match[3] ?? "";
|
|
95
|
+
const selfClosing = match[4] === "/";
|
|
96
|
+
if (isClosing) {
|
|
97
|
+
while (stack.length > 0) if (stack.pop().tag === tag) break;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const element = {
|
|
101
|
+
kind: "element",
|
|
102
|
+
tag,
|
|
103
|
+
attrs: parseAttributes(rawAttrs),
|
|
104
|
+
children: [],
|
|
105
|
+
selfClosing
|
|
106
|
+
};
|
|
107
|
+
pushNode(element);
|
|
108
|
+
if (!selfClosing) stack.push(element);
|
|
109
|
+
}
|
|
110
|
+
if (lastIndex < svg.length) {
|
|
111
|
+
const tail = svg.slice(lastIndex);
|
|
112
|
+
if (tail !== "") pushNode({
|
|
113
|
+
kind: "text",
|
|
114
|
+
text: tail
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return root;
|
|
118
|
+
}
|
|
119
|
+
function serializeSvgNode(node) {
|
|
120
|
+
if (node.kind === "text") return node.text;
|
|
121
|
+
const attrsParts = [];
|
|
122
|
+
for (const [key, value] of node.attrs.entries()) attrsParts.push(`${key}="${encodeXmlAttr(value)}"`);
|
|
123
|
+
const attrString = attrsParts.length === 0 ? "" : ` ${attrsParts.join(" ")}`;
|
|
124
|
+
if (node.selfClosing && node.children.length === 0) return `<${node.tag}${attrString}/>`;
|
|
125
|
+
const inner = node.children.map(serializeSvgNode).join("");
|
|
126
|
+
return `<${node.tag}${attrString}>${inner}</${node.tag}>`;
|
|
127
|
+
}
|
|
128
|
+
function formatNumber(value) {
|
|
129
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
130
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
131
|
+
}
|
|
132
|
+
function parseNumber(value) {
|
|
133
|
+
if (value === void 0) return void 0;
|
|
134
|
+
const trimmed = value.trim();
|
|
135
|
+
if (trimmed === "" || trimmed.endsWith("%")) return void 0;
|
|
136
|
+
const parsed = Number(trimmed);
|
|
137
|
+
return Number.isFinite(parsed) ? parsed : NaN;
|
|
138
|
+
}
|
|
139
|
+
function parseLengthAttr(value, referenceSpan, defaultValue) {
|
|
140
|
+
if (value === void 0) return defaultValue;
|
|
141
|
+
const trimmed = value.trim();
|
|
142
|
+
if (trimmed === "") return NaN;
|
|
143
|
+
if (trimmed.endsWith("%")) {
|
|
144
|
+
const pct = Number(trimmed.slice(0, -1));
|
|
145
|
+
return Number.isFinite(pct) ? pct / 100 * referenceSpan : NaN;
|
|
146
|
+
}
|
|
147
|
+
const parsed = Number(trimmed);
|
|
148
|
+
return Number.isFinite(parsed) ? parsed : NaN;
|
|
149
|
+
}
|
|
150
|
+
function hasNonFiniteAttr(element, keys) {
|
|
151
|
+
for (const key of keys) {
|
|
152
|
+
const raw = element.attrs.get(key);
|
|
153
|
+
if (raw === void 0) continue;
|
|
154
|
+
const trimmed = raw.trim();
|
|
155
|
+
if (trimmed === "") return true;
|
|
156
|
+
const numStr = trimmed.endsWith("%") ? trimmed.slice(0, -1) : trimmed;
|
|
157
|
+
if (!Number.isFinite(Number(numStr))) return true;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
function multiplyMatrix(m1, m2) {
|
|
162
|
+
return [
|
|
163
|
+
m1[0] * m2[0] + m1[2] * m2[1],
|
|
164
|
+
m1[1] * m2[0] + m1[3] * m2[1],
|
|
165
|
+
m1[0] * m2[2] + m1[2] * m2[3],
|
|
166
|
+
m1[1] * m2[2] + m1[3] * m2[3],
|
|
167
|
+
m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
|
|
168
|
+
m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
function parseTransformAttr(transformStr) {
|
|
172
|
+
if (transformStr === void 0 || transformStr.trim() === "") return IDENTITY_MATRIX;
|
|
173
|
+
let current = IDENTITY_MATRIX;
|
|
174
|
+
const opPattern = /([A-Za-z]+)\s*\(([^)]*)\)/gu;
|
|
175
|
+
let matchedAny = false;
|
|
176
|
+
for (const match of transformStr.matchAll(opPattern)) {
|
|
177
|
+
matchedAny = true;
|
|
178
|
+
const fn = match[1];
|
|
179
|
+
const nums = (match[2] ?? "").trim().split(/[\s,]+/u).filter((token) => token !== "").map(Number);
|
|
180
|
+
if (nums.some((n) => !Number.isFinite(n))) return null;
|
|
181
|
+
let next;
|
|
182
|
+
switch (fn) {
|
|
183
|
+
case "translate":
|
|
184
|
+
if (nums.length < 1) return null;
|
|
185
|
+
next = [
|
|
186
|
+
1,
|
|
187
|
+
0,
|
|
188
|
+
0,
|
|
189
|
+
1,
|
|
190
|
+
nums[0],
|
|
191
|
+
nums[1] ?? 0
|
|
192
|
+
];
|
|
193
|
+
break;
|
|
194
|
+
case "scale": {
|
|
195
|
+
if (nums.length < 1) return null;
|
|
196
|
+
const sx = nums[0];
|
|
197
|
+
next = [
|
|
198
|
+
sx,
|
|
199
|
+
0,
|
|
200
|
+
0,
|
|
201
|
+
nums[1] ?? sx,
|
|
202
|
+
0,
|
|
203
|
+
0
|
|
204
|
+
];
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case "rotate": {
|
|
208
|
+
if (nums.length < 1) return null;
|
|
209
|
+
const rad = nums[0] * Math.PI / 180;
|
|
210
|
+
const cos = Math.cos(rad);
|
|
211
|
+
const sin = Math.sin(rad);
|
|
212
|
+
const cx = nums[1] ?? 0;
|
|
213
|
+
const cy = nums[2] ?? 0;
|
|
214
|
+
if (cx === 0 && cy === 0) next = [
|
|
215
|
+
cos,
|
|
216
|
+
sin,
|
|
217
|
+
-sin,
|
|
218
|
+
cos,
|
|
219
|
+
0,
|
|
220
|
+
0
|
|
221
|
+
];
|
|
222
|
+
else {
|
|
223
|
+
const toOrigin = [
|
|
224
|
+
1,
|
|
225
|
+
0,
|
|
226
|
+
0,
|
|
227
|
+
1,
|
|
228
|
+
cx,
|
|
229
|
+
cy
|
|
230
|
+
];
|
|
231
|
+
const rot = [
|
|
232
|
+
cos,
|
|
233
|
+
sin,
|
|
234
|
+
-sin,
|
|
235
|
+
cos,
|
|
236
|
+
0,
|
|
237
|
+
0
|
|
238
|
+
];
|
|
239
|
+
const back = [
|
|
240
|
+
1,
|
|
241
|
+
0,
|
|
242
|
+
0,
|
|
243
|
+
1,
|
|
244
|
+
-cx,
|
|
245
|
+
-cy
|
|
246
|
+
];
|
|
247
|
+
next = multiplyMatrix(multiplyMatrix(toOrigin, rot), back);
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case "skewX":
|
|
252
|
+
if (nums.length < 1) return null;
|
|
253
|
+
next = [
|
|
254
|
+
1,
|
|
255
|
+
0,
|
|
256
|
+
Math.tan(nums[0] * Math.PI / 180),
|
|
257
|
+
1,
|
|
258
|
+
0,
|
|
259
|
+
0
|
|
260
|
+
];
|
|
261
|
+
break;
|
|
262
|
+
case "skewY":
|
|
263
|
+
if (nums.length < 1) return null;
|
|
264
|
+
next = [
|
|
265
|
+
1,
|
|
266
|
+
Math.tan(nums[0] * Math.PI / 180),
|
|
267
|
+
0,
|
|
268
|
+
1,
|
|
269
|
+
0,
|
|
270
|
+
0
|
|
271
|
+
];
|
|
272
|
+
break;
|
|
273
|
+
case "matrix":
|
|
274
|
+
if (nums.length !== 6) return null;
|
|
275
|
+
next = [
|
|
276
|
+
nums[0],
|
|
277
|
+
nums[1],
|
|
278
|
+
nums[2],
|
|
279
|
+
nums[3],
|
|
280
|
+
nums[4],
|
|
281
|
+
nums[5]
|
|
282
|
+
];
|
|
283
|
+
break;
|
|
284
|
+
default: return null;
|
|
285
|
+
}
|
|
286
|
+
current = multiplyMatrix(current, next);
|
|
287
|
+
}
|
|
288
|
+
if (!matchedAny) return null;
|
|
289
|
+
if (current.some((v) => !Number.isFinite(v))) return null;
|
|
290
|
+
const det = current[0] * current[3] - current[1] * current[2];
|
|
291
|
+
if (!Number.isFinite(det) || Math.abs(det) <= 1e-12) return null;
|
|
292
|
+
return current;
|
|
293
|
+
}
|
|
294
|
+
function transformBbox(bbox, m) {
|
|
295
|
+
const corners = [
|
|
296
|
+
[bbox.minX, bbox.minY],
|
|
297
|
+
[bbox.maxX, bbox.minY],
|
|
298
|
+
[bbox.maxX, bbox.maxY],
|
|
299
|
+
[bbox.minX, bbox.maxY]
|
|
300
|
+
];
|
|
301
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
302
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
303
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
304
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
305
|
+
for (const [x, y] of corners) {
|
|
306
|
+
const tx = m[0] * x + m[2] * y + m[4];
|
|
307
|
+
const ty = m[1] * x + m[3] * y + m[5];
|
|
308
|
+
if (!Number.isFinite(tx) || !Number.isFinite(ty)) return {
|
|
309
|
+
minX: NaN,
|
|
310
|
+
minY: NaN,
|
|
311
|
+
maxX: NaN,
|
|
312
|
+
maxY: NaN
|
|
313
|
+
};
|
|
314
|
+
if (tx < minX) minX = tx;
|
|
315
|
+
if (ty < minY) minY = ty;
|
|
316
|
+
if (tx > maxX) maxX = tx;
|
|
317
|
+
if (ty > maxY) maxY = ty;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
minX,
|
|
321
|
+
minY,
|
|
322
|
+
maxX,
|
|
323
|
+
maxY
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function boxesIntersect(a, b) {
|
|
327
|
+
if (!Number.isFinite(a.minX) || !Number.isFinite(a.minY) || !Number.isFinite(a.maxX) || !Number.isFinite(a.maxY)) return false;
|
|
328
|
+
return a.maxX >= b.minX && a.minX <= b.maxX && a.maxY >= b.minY && a.minY <= b.maxY;
|
|
329
|
+
}
|
|
330
|
+
function extractUrlId(attrValue) {
|
|
331
|
+
if (attrValue === void 0) return void 0;
|
|
332
|
+
return /^url\(#([^)]+)\)$/u.exec(attrValue.trim())?.[1];
|
|
333
|
+
}
|
|
334
|
+
function pathBbox(d) {
|
|
335
|
+
if (d.trim() === "") return null;
|
|
336
|
+
const tokens = d.match(/[A-Za-z]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?|NaN|Infinity|-Infinity/gu);
|
|
337
|
+
if (tokens === null || tokens.length === 0) return null;
|
|
338
|
+
let index = 0;
|
|
339
|
+
let cmd = "";
|
|
340
|
+
let curX = 0;
|
|
341
|
+
let curY = 0;
|
|
342
|
+
let startX = 0;
|
|
343
|
+
let startY = 0;
|
|
344
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
345
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
346
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
347
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
348
|
+
const recordPoint = (x, y) => {
|
|
349
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return false;
|
|
350
|
+
if (x < minX) minX = x;
|
|
351
|
+
if (y < minY) minY = y;
|
|
352
|
+
if (x > maxX) maxX = x;
|
|
353
|
+
if (y > maxY) maxY = y;
|
|
354
|
+
return true;
|
|
355
|
+
};
|
|
356
|
+
const nextNum = () => {
|
|
357
|
+
const token = tokens[index];
|
|
358
|
+
if (token === void 0 || /^[A-Za-z]$/u.test(token)) return void 0;
|
|
359
|
+
index += 1;
|
|
360
|
+
return Number(token);
|
|
361
|
+
};
|
|
362
|
+
while (index < tokens.length) {
|
|
363
|
+
const tok = tokens[index];
|
|
364
|
+
if (/^[A-Za-z]$/u.test(tok) && tok !== "NaN" && tok !== "Infinity") {
|
|
365
|
+
cmd = tok;
|
|
366
|
+
index += 1;
|
|
367
|
+
if (cmd === "Z" || cmd === "z") {
|
|
368
|
+
curX = startX;
|
|
369
|
+
curY = startY;
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (cmd === "") return null;
|
|
374
|
+
const rel = cmd === cmd.toLowerCase();
|
|
375
|
+
const upper = cmd.toUpperCase();
|
|
376
|
+
switch (upper) {
|
|
377
|
+
case "M":
|
|
378
|
+
case "L":
|
|
379
|
+
case "T": {
|
|
380
|
+
const x = nextNum();
|
|
381
|
+
const y = nextNum();
|
|
382
|
+
if (x === void 0 || y === void 0 || !Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
383
|
+
curX = rel ? curX + x : x;
|
|
384
|
+
curY = rel ? curY + y : y;
|
|
385
|
+
if (!recordPoint(curX, curY)) return null;
|
|
386
|
+
if (upper === "M") {
|
|
387
|
+
startX = curX;
|
|
388
|
+
startY = curY;
|
|
389
|
+
cmd = rel ? "l" : "L";
|
|
390
|
+
}
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
case "H": {
|
|
394
|
+
const x = nextNum();
|
|
395
|
+
if (x === void 0 || !Number.isFinite(x)) return null;
|
|
396
|
+
curX = rel ? curX + x : x;
|
|
397
|
+
if (!recordPoint(curX, curY)) return null;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "V": {
|
|
401
|
+
const y = nextNum();
|
|
402
|
+
if (y === void 0 || !Number.isFinite(y)) return null;
|
|
403
|
+
curY = rel ? curY + y : y;
|
|
404
|
+
if (!recordPoint(curX, curY)) return null;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
case "C": {
|
|
408
|
+
const x1 = nextNum();
|
|
409
|
+
const y1 = nextNum();
|
|
410
|
+
const x2 = nextNum();
|
|
411
|
+
const y2 = nextNum();
|
|
412
|
+
const x = nextNum();
|
|
413
|
+
const y = nextNum();
|
|
414
|
+
if (x1 === void 0 || y1 === void 0 || x2 === void 0 || y2 === void 0 || x === void 0 || y === void 0 || !Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2) || !Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
415
|
+
const ox = rel ? curX : 0;
|
|
416
|
+
const oy = rel ? curY : 0;
|
|
417
|
+
if (!recordPoint(ox + x1, oy + y1) || !recordPoint(ox + x2, oy + y2) || !recordPoint(ox + x, oy + y)) return null;
|
|
418
|
+
curX = ox + x;
|
|
419
|
+
curY = oy + y;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case "S":
|
|
423
|
+
case "Q": {
|
|
424
|
+
const x1 = nextNum();
|
|
425
|
+
const y1 = nextNum();
|
|
426
|
+
const x = nextNum();
|
|
427
|
+
const y = nextNum();
|
|
428
|
+
if (x1 === void 0 || y1 === void 0 || x === void 0 || y === void 0 || !Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
429
|
+
const ox = rel ? curX : 0;
|
|
430
|
+
const oy = rel ? curY : 0;
|
|
431
|
+
if (!recordPoint(ox + x1, oy + y1) || !recordPoint(ox + x, oy + y)) return null;
|
|
432
|
+
curX = ox + x;
|
|
433
|
+
curY = oy + y;
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
case "A": {
|
|
437
|
+
const rx = nextNum();
|
|
438
|
+
const ry = nextNum();
|
|
439
|
+
const rot = nextNum();
|
|
440
|
+
const large = nextNum();
|
|
441
|
+
const sweep = nextNum();
|
|
442
|
+
const x = nextNum();
|
|
443
|
+
const y = nextNum();
|
|
444
|
+
if (rx === void 0 || ry === void 0 || rot === void 0 || large === void 0 || sweep === void 0 || x === void 0 || y === void 0 || !Number.isFinite(rx) || !Number.isFinite(ry) || !Number.isFinite(rot) || !Number.isFinite(large) || !Number.isFinite(sweep) || !Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
445
|
+
const ox = rel ? curX : 0;
|
|
446
|
+
const oy = rel ? curY : 0;
|
|
447
|
+
if (!recordPoint(curX, curY) || !recordPoint(ox + x, oy + y)) return null;
|
|
448
|
+
curX = ox + x;
|
|
449
|
+
curY = oy + y;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
default: return null;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (!Number.isFinite(minX)) return null;
|
|
456
|
+
return {
|
|
457
|
+
minX,
|
|
458
|
+
minY,
|
|
459
|
+
maxX,
|
|
460
|
+
maxY
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function clampRectToSafeViewport(x, y, width, height, safeViewport) {
|
|
464
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height) || width <= EPSILON || height <= EPSILON) return null;
|
|
465
|
+
const minX = Math.max(x, safeViewport.minX);
|
|
466
|
+
const minY = Math.max(y, safeViewport.minY);
|
|
467
|
+
const maxX = Math.min(x + width, safeViewport.maxX);
|
|
468
|
+
const maxY = Math.min(y + height, safeViewport.maxY);
|
|
469
|
+
const clampedW = maxX - minX;
|
|
470
|
+
const clampedH = maxY - minY;
|
|
471
|
+
if (clampedW <= EPSILON || clampedH <= EPSILON) return null;
|
|
472
|
+
return {
|
|
473
|
+
x: minX,
|
|
474
|
+
y: minY,
|
|
475
|
+
width: clampedW,
|
|
476
|
+
height: clampedH
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function extractPointsBbox(pointsAttr) {
|
|
480
|
+
const nums = pointsAttr.trim().split(/[\s,]+/u).filter((token) => token !== "").map(Number);
|
|
481
|
+
if (nums.length < 4 || nums.length % 2 !== 0 || nums.some((n) => !Number.isFinite(n))) return null;
|
|
482
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
483
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
484
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
485
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
486
|
+
for (let i = 0; i < nums.length; i += 2) {
|
|
487
|
+
const x = nums[i];
|
|
488
|
+
const y = nums[i + 1];
|
|
489
|
+
if (x < minX) minX = x;
|
|
490
|
+
if (y < minY) minY = y;
|
|
491
|
+
if (x > maxX) maxX = x;
|
|
492
|
+
if (y > maxY) maxY = y;
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
minX,
|
|
496
|
+
minY,
|
|
497
|
+
maxX,
|
|
498
|
+
maxY
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
function lastGradientStopColor(gradient) {
|
|
502
|
+
const last = gradient.children.filter((child) => child.kind === "element" && child.tag === "stop").at(-1);
|
|
503
|
+
if (last === void 0) return void 0;
|
|
504
|
+
const color = last.attrs.get("stop-color");
|
|
505
|
+
if (color === void 0 || color.trim() === "") return void 0;
|
|
506
|
+
const opacity = last.attrs.get("stop-opacity");
|
|
507
|
+
return {
|
|
508
|
+
color,
|
|
509
|
+
...opacity === void 0 ? {} : { opacity }
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function sanitizeGeometryElementBbox(element, canvas, safeViewport, requireArea) {
|
|
513
|
+
switch (element.tag) {
|
|
514
|
+
case "rect": {
|
|
515
|
+
if (hasNonFiniteAttr(element, [
|
|
516
|
+
"x",
|
|
517
|
+
"y",
|
|
518
|
+
"width",
|
|
519
|
+
"height",
|
|
520
|
+
"rx",
|
|
521
|
+
"ry"
|
|
522
|
+
])) return null;
|
|
523
|
+
const x = parseLengthAttr(element.attrs.get("x"), canvas.width, 0);
|
|
524
|
+
const y = parseLengthAttr(element.attrs.get("y"), canvas.height, 0);
|
|
525
|
+
const width = parseLengthAttr(element.attrs.get("width"), canvas.width, 0);
|
|
526
|
+
const height = parseLengthAttr(element.attrs.get("height"), canvas.height, 0);
|
|
527
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height) || width <= EPSILON || height <= EPSILON) return null;
|
|
528
|
+
if (x < safeViewport.minX || y < safeViewport.minY || x + width > safeViewport.maxX || y + height > safeViewport.maxY) {
|
|
529
|
+
const clamped = clampRectToSafeViewport(x, y, width, height, safeViewport);
|
|
530
|
+
if (clamped === null) return null;
|
|
531
|
+
if (!element.attrs.get("width")?.trim().endsWith("%")) {
|
|
532
|
+
element.attrs.set("x", formatNumber(clamped.x));
|
|
533
|
+
element.attrs.set("y", formatNumber(clamped.y));
|
|
534
|
+
element.attrs.set("width", formatNumber(clamped.width));
|
|
535
|
+
element.attrs.set("height", formatNumber(clamped.height));
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
minX: clamped.x,
|
|
539
|
+
minY: clamped.y,
|
|
540
|
+
maxX: clamped.x + clamped.width,
|
|
541
|
+
maxY: clamped.y + clamped.height
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
minX: x,
|
|
546
|
+
minY: y,
|
|
547
|
+
maxX: x + width,
|
|
548
|
+
maxY: y + height
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
case "image": {
|
|
552
|
+
if (hasNonFiniteAttr(element, [
|
|
553
|
+
"x",
|
|
554
|
+
"y",
|
|
555
|
+
"width",
|
|
556
|
+
"height"
|
|
557
|
+
])) return null;
|
|
558
|
+
const x = parseNumber(element.attrs.get("x")) ?? 0;
|
|
559
|
+
const y = parseNumber(element.attrs.get("y")) ?? 0;
|
|
560
|
+
const width = parseNumber(element.attrs.get("width")) ?? 0;
|
|
561
|
+
const height = parseNumber(element.attrs.get("height")) ?? 0;
|
|
562
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height) || width <= EPSILON || height <= EPSILON) return null;
|
|
563
|
+
return {
|
|
564
|
+
minX: x,
|
|
565
|
+
minY: y,
|
|
566
|
+
maxX: x + width,
|
|
567
|
+
maxY: y + height
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
case "path": {
|
|
571
|
+
const d = element.attrs.get("d");
|
|
572
|
+
if (d === void 0) return null;
|
|
573
|
+
const bbox = pathBbox(d);
|
|
574
|
+
if (bbox === null) return null;
|
|
575
|
+
if (requireArea && (bbox.maxX - bbox.minX <= EPSILON || bbox.maxY - bbox.minY <= EPSILON)) return null;
|
|
576
|
+
return bbox;
|
|
577
|
+
}
|
|
578
|
+
case "circle": {
|
|
579
|
+
if (hasNonFiniteAttr(element, [
|
|
580
|
+
"cx",
|
|
581
|
+
"cy",
|
|
582
|
+
"r"
|
|
583
|
+
])) return null;
|
|
584
|
+
const cx = parseNumber(element.attrs.get("cx")) ?? 0;
|
|
585
|
+
const cy = parseNumber(element.attrs.get("cy")) ?? 0;
|
|
586
|
+
const r = parseNumber(element.attrs.get("r")) ?? 0;
|
|
587
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy) || !Number.isFinite(r) || r <= EPSILON) return null;
|
|
588
|
+
return {
|
|
589
|
+
minX: cx - r,
|
|
590
|
+
minY: cy - r,
|
|
591
|
+
maxX: cx + r,
|
|
592
|
+
maxY: cy + r
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
case "ellipse": {
|
|
596
|
+
if (hasNonFiniteAttr(element, [
|
|
597
|
+
"cx",
|
|
598
|
+
"cy",
|
|
599
|
+
"rx",
|
|
600
|
+
"ry"
|
|
601
|
+
])) return null;
|
|
602
|
+
const cx = parseNumber(element.attrs.get("cx")) ?? 0;
|
|
603
|
+
const cy = parseNumber(element.attrs.get("cy")) ?? 0;
|
|
604
|
+
const rx = parseNumber(element.attrs.get("rx")) ?? 0;
|
|
605
|
+
const ry = parseNumber(element.attrs.get("ry")) ?? 0;
|
|
606
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy) || !Number.isFinite(rx) || !Number.isFinite(ry) || rx <= EPSILON || ry <= EPSILON) return null;
|
|
607
|
+
return {
|
|
608
|
+
minX: cx - rx,
|
|
609
|
+
minY: cy - ry,
|
|
610
|
+
maxX: cx + rx,
|
|
611
|
+
maxY: cy + ry
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
case "line": {
|
|
615
|
+
if (hasNonFiniteAttr(element, [
|
|
616
|
+
"x1",
|
|
617
|
+
"y1",
|
|
618
|
+
"x2",
|
|
619
|
+
"y2"
|
|
620
|
+
])) return null;
|
|
621
|
+
const x1 = parseNumber(element.attrs.get("x1")) ?? 0;
|
|
622
|
+
const y1 = parseNumber(element.attrs.get("y1")) ?? 0;
|
|
623
|
+
const x2 = parseNumber(element.attrs.get("x2")) ?? 0;
|
|
624
|
+
const y2 = parseNumber(element.attrs.get("y2")) ?? 0;
|
|
625
|
+
if (!Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2)) return null;
|
|
626
|
+
return {
|
|
627
|
+
minX: Math.min(x1, x2),
|
|
628
|
+
minY: Math.min(y1, y2),
|
|
629
|
+
maxX: Math.max(x1, x2),
|
|
630
|
+
maxY: Math.max(y1, y2)
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
case "polygon":
|
|
634
|
+
case "polyline": {
|
|
635
|
+
const points = element.attrs.get("points");
|
|
636
|
+
if (points === void 0) return null;
|
|
637
|
+
const bbox = extractPointsBbox(points);
|
|
638
|
+
if (bbox === null) return null;
|
|
639
|
+
if (requireArea && (bbox.maxX - bbox.minX <= EPSILON || bbox.maxY - bbox.minY <= EPSILON)) return null;
|
|
640
|
+
return bbox;
|
|
641
|
+
}
|
|
642
|
+
case "use": {
|
|
643
|
+
if (hasNonFiniteAttr(element, [
|
|
644
|
+
"x",
|
|
645
|
+
"y",
|
|
646
|
+
"width",
|
|
647
|
+
"height"
|
|
648
|
+
])) return null;
|
|
649
|
+
const x = parseNumber(element.attrs.get("x")) ?? 0;
|
|
650
|
+
const y = parseNumber(element.attrs.get("y")) ?? 0;
|
|
651
|
+
const width = parseNumber(element.attrs.get("width")) ?? 1;
|
|
652
|
+
const height = parseNumber(element.attrs.get("height")) ?? 1;
|
|
653
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height) || width <= EPSILON || height <= EPSILON) return null;
|
|
654
|
+
return {
|
|
655
|
+
minX: x,
|
|
656
|
+
minY: y,
|
|
657
|
+
maxX: x + width,
|
|
658
|
+
maxY: y + height
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
default: return null;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function sanitizeDefsBlock(defsElement, canvas, safeViewport, state) {
|
|
665
|
+
const keptDefs = [];
|
|
666
|
+
for (const child of defsElement.children) {
|
|
667
|
+
if (child.kind !== "element") continue;
|
|
668
|
+
const id = child.attrs.get("id");
|
|
669
|
+
switch (child.tag) {
|
|
670
|
+
case "clipPath": {
|
|
671
|
+
const units = child.attrs.get("clipPathUnits") ?? "userSpaceOnUse";
|
|
672
|
+
const keptChildren = [];
|
|
673
|
+
for (const item of child.children) {
|
|
674
|
+
if (item.kind !== "element") continue;
|
|
675
|
+
const localMatrix = parseTransformAttr(item.attrs.get("transform"));
|
|
676
|
+
if (localMatrix === null) continue;
|
|
677
|
+
const bbox = sanitizeGeometryElementBbox(item, canvas, safeViewport, true);
|
|
678
|
+
if (bbox === null) continue;
|
|
679
|
+
if (units === "userSpaceOnUse") {
|
|
680
|
+
if (!boxesIntersect(transformBbox(bbox, localMatrix), safeViewport)) continue;
|
|
681
|
+
}
|
|
682
|
+
keptChildren.push(item);
|
|
683
|
+
}
|
|
684
|
+
if (keptChildren.length === 0) {
|
|
685
|
+
if (id !== void 0) state.droppedClipIds.add(id);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
child.children.length = 0;
|
|
689
|
+
child.children.push(...keptChildren);
|
|
690
|
+
keptDefs.push(child);
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
case "linearGradient": {
|
|
694
|
+
if (hasNonFiniteAttr(child, [
|
|
695
|
+
"x1",
|
|
696
|
+
"y1",
|
|
697
|
+
"x2",
|
|
698
|
+
"y2"
|
|
699
|
+
])) {
|
|
700
|
+
if (id !== void 0) {
|
|
701
|
+
const fallback = lastGradientStopColor(child);
|
|
702
|
+
if (fallback !== void 0) state.gradientFallbacks.set(id, fallback);
|
|
703
|
+
else state.droppedGradientIds.add(id);
|
|
704
|
+
}
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const x1 = parseLengthAttr(child.attrs.get("x1"), 1, 0);
|
|
708
|
+
const y1 = parseLengthAttr(child.attrs.get("y1"), 1, 0);
|
|
709
|
+
const x2 = parseLengthAttr(child.attrs.get("x2"), 1, 1);
|
|
710
|
+
const y2 = parseLengthAttr(child.attrs.get("y2"), 1, 0);
|
|
711
|
+
if (!Number.isFinite(x1) || !Number.isFinite(y1) || !Number.isFinite(x2) || !Number.isFinite(y2) || Math.hypot(x2 - x1, y2 - y1) <= EPSILON) {
|
|
712
|
+
if (id !== void 0) {
|
|
713
|
+
const fallback = lastGradientStopColor(child);
|
|
714
|
+
if (fallback !== void 0) state.gradientFallbacks.set(id, fallback);
|
|
715
|
+
else state.droppedGradientIds.add(id);
|
|
716
|
+
}
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
keptDefs.push(child);
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
case "radialGradient": {
|
|
723
|
+
if (hasNonFiniteAttr(child, [
|
|
724
|
+
"cx",
|
|
725
|
+
"cy",
|
|
726
|
+
"r",
|
|
727
|
+
"fx",
|
|
728
|
+
"fy"
|
|
729
|
+
])) {
|
|
730
|
+
if (id !== void 0) {
|
|
731
|
+
const fallback = lastGradientStopColor(child);
|
|
732
|
+
if (fallback !== void 0) state.gradientFallbacks.set(id, fallback);
|
|
733
|
+
else state.droppedGradientIds.add(id);
|
|
734
|
+
}
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
const r = parseLengthAttr(child.attrs.get("r"), 1, .5);
|
|
738
|
+
if (!Number.isFinite(r) || r <= EPSILON) {
|
|
739
|
+
if (id !== void 0) {
|
|
740
|
+
const fallback = lastGradientStopColor(child);
|
|
741
|
+
if (fallback !== void 0) state.gradientFallbacks.set(id, fallback);
|
|
742
|
+
else state.droppedGradientIds.add(id);
|
|
743
|
+
}
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
keptDefs.push(child);
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
749
|
+
case "filter": {
|
|
750
|
+
if (hasNonFiniteAttr(child, [
|
|
751
|
+
"x",
|
|
752
|
+
"y",
|
|
753
|
+
"width",
|
|
754
|
+
"height"
|
|
755
|
+
])) {
|
|
756
|
+
if (id !== void 0) state.droppedFilterIds.add(id);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
if ((child.attrs.get("filterUnits") ?? "objectBoundingBox") === "userSpaceOnUse") {
|
|
760
|
+
const clamped = clampRectToSafeViewport(parseNumber(child.attrs.get("x")) ?? 0, parseNumber(child.attrs.get("y")) ?? 0, parseNumber(child.attrs.get("width")) ?? 0, parseNumber(child.attrs.get("height")) ?? 0, safeViewport);
|
|
761
|
+
if (clamped === null) {
|
|
762
|
+
if (id !== void 0) state.droppedFilterIds.add(id);
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
child.attrs.set("x", formatNumber(clamped.x));
|
|
766
|
+
child.attrs.set("y", formatNumber(clamped.y));
|
|
767
|
+
child.attrs.set("width", formatNumber(clamped.width));
|
|
768
|
+
child.attrs.set("height", formatNumber(clamped.height));
|
|
769
|
+
}
|
|
770
|
+
let validFilter = true;
|
|
771
|
+
for (const prim of child.children) {
|
|
772
|
+
if (prim.kind !== "element") continue;
|
|
773
|
+
if (hasNonFiniteAttr(prim, [
|
|
774
|
+
"stdDeviation",
|
|
775
|
+
"dx",
|
|
776
|
+
"dy"
|
|
777
|
+
])) {
|
|
778
|
+
validFilter = false;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
const stdRaw = prim.attrs.get("stdDeviation");
|
|
782
|
+
if (stdRaw !== void 0) {
|
|
783
|
+
const std = parseNumber(stdRaw);
|
|
784
|
+
if (std === void 0 || !Number.isFinite(std) || std < 0) {
|
|
785
|
+
validFilter = false;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
if (std > MAX_BLUR_STD_DEVIATION) prim.attrs.set("stdDeviation", formatNumber(MAX_BLUR_STD_DEVIATION));
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (!validFilter) {
|
|
792
|
+
if (id !== void 0) state.droppedFilterIds.add(id);
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
keptDefs.push(child);
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
case "mask":
|
|
799
|
+
if (hasNonFiniteAttr(child, [
|
|
800
|
+
"x",
|
|
801
|
+
"y",
|
|
802
|
+
"width",
|
|
803
|
+
"height"
|
|
804
|
+
])) {
|
|
805
|
+
if (id !== void 0) state.droppedMaskIds.add(id);
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if ((child.attrs.get("maskUnits") ?? "objectBoundingBox") === "userSpaceOnUse") {
|
|
809
|
+
const clamped = clampRectToSafeViewport(parseNumber(child.attrs.get("x")) ?? 0, parseNumber(child.attrs.get("y")) ?? 0, parseNumber(child.attrs.get("width")) ?? 0, parseNumber(child.attrs.get("height")) ?? 0, safeViewport);
|
|
810
|
+
if (clamped === null) {
|
|
811
|
+
if (id !== void 0) state.droppedMaskIds.add(id);
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
child.attrs.set("x", formatNumber(clamped.x));
|
|
815
|
+
child.attrs.set("y", formatNumber(clamped.y));
|
|
816
|
+
child.attrs.set("width", formatNumber(clamped.width));
|
|
817
|
+
child.attrs.set("height", formatNumber(clamped.height));
|
|
818
|
+
}
|
|
819
|
+
keptDefs.push(child);
|
|
820
|
+
break;
|
|
821
|
+
case "pattern":
|
|
822
|
+
if (hasNonFiniteAttr(child, [
|
|
823
|
+
"x",
|
|
824
|
+
"y",
|
|
825
|
+
"width",
|
|
826
|
+
"height"
|
|
827
|
+
])) {
|
|
828
|
+
if (id !== void 0) state.droppedPatternIds.add(id);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if ((child.attrs.get("patternUnits") ?? "objectBoundingBox") === "userSpaceOnUse") {
|
|
832
|
+
const x = parseNumber(child.attrs.get("x")) ?? 0;
|
|
833
|
+
const y = parseNumber(child.attrs.get("y")) ?? 0;
|
|
834
|
+
const width = parseNumber(child.attrs.get("width")) ?? 0;
|
|
835
|
+
const height = parseNumber(child.attrs.get("height")) ?? 0;
|
|
836
|
+
const clamped = clampRectToSafeViewport(x, y, width, height, safeViewport);
|
|
837
|
+
if (clamped === null) {
|
|
838
|
+
if (id !== void 0) state.droppedPatternIds.add(id);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (x < safeViewport.minX || y < safeViewport.minY || x + width > safeViewport.maxX || y + height > safeViewport.maxY) {
|
|
842
|
+
child.attrs.set("x", formatNumber(clamped.x));
|
|
843
|
+
child.attrs.set("y", formatNumber(clamped.y));
|
|
844
|
+
child.attrs.set("width", formatNumber(clamped.width));
|
|
845
|
+
child.attrs.set("height", formatNumber(clamped.height));
|
|
846
|
+
for (const pChild of child.children) {
|
|
847
|
+
if (pChild.kind !== "element") continue;
|
|
848
|
+
if (pChild.tag === "rect" || pChild.tag === "image") {
|
|
849
|
+
const cw = parseNumber(pChild.attrs.get("width")) ?? 0;
|
|
850
|
+
const ch = parseNumber(pChild.attrs.get("height")) ?? 0;
|
|
851
|
+
if (cw > clamped.width) pChild.attrs.set("width", formatNumber(clamped.width));
|
|
852
|
+
if (ch > clamped.height) pChild.attrs.set("height", formatNumber(clamped.height));
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
keptDefs.push(child);
|
|
858
|
+
break;
|
|
859
|
+
default: keptDefs.push(child);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
defsElement.children.length = 0;
|
|
863
|
+
defsElement.children.push(...keptDefs);
|
|
864
|
+
}
|
|
865
|
+
function applyPaintRefFallbacks(element, state) {
|
|
866
|
+
const clipId = extractUrlId(element.attrs.get("clip-path"));
|
|
867
|
+
if (clipId !== void 0 && state.droppedClipIds.has(clipId)) return false;
|
|
868
|
+
const maskId = extractUrlId(element.attrs.get("mask"));
|
|
869
|
+
if (maskId !== void 0 && state.droppedMaskIds.has(maskId)) return false;
|
|
870
|
+
const filterId = extractUrlId(element.attrs.get("filter"));
|
|
871
|
+
if (filterId !== void 0 && state.droppedFilterIds.has(filterId)) element.attrs.delete("filter");
|
|
872
|
+
for (const attr of ["fill", "stroke"]) {
|
|
873
|
+
const refId = extractUrlId(element.attrs.get(attr));
|
|
874
|
+
if (refId === void 0) continue;
|
|
875
|
+
const fallback = state.gradientFallbacks.get(refId);
|
|
876
|
+
if (fallback !== void 0) {
|
|
877
|
+
element.attrs.set(attr, fallback.color);
|
|
878
|
+
if (fallback.opacity !== void 0) element.attrs.set(`${attr}-opacity`, fallback.opacity);
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
if (state.droppedGradientIds.has(refId) || state.droppedPatternIds.has(refId)) element.attrs.set(attr, "none");
|
|
882
|
+
}
|
|
883
|
+
return true;
|
|
884
|
+
}
|
|
885
|
+
function sanitizeBodyNode(node, ctm, canvas, safeViewport, state) {
|
|
886
|
+
if (node.kind === "text") return node;
|
|
887
|
+
if (node.tag === "defs") {
|
|
888
|
+
sanitizeDefsBlock(node, canvas, safeViewport, state);
|
|
889
|
+
return node.children.length === 0 ? null : node;
|
|
890
|
+
}
|
|
891
|
+
const localMatrix = parseTransformAttr(node.attrs.get("transform"));
|
|
892
|
+
if (localMatrix === null) return null;
|
|
893
|
+
const nextCtm = multiplyMatrix(ctm, localMatrix);
|
|
894
|
+
if (nextCtm.some((v) => !Number.isFinite(v))) return null;
|
|
895
|
+
if (!applyPaintRefFallbacks(node, state)) return null;
|
|
896
|
+
if (node.tag === "g") {
|
|
897
|
+
const keptChildren = [];
|
|
898
|
+
for (const child of node.children) {
|
|
899
|
+
const sanitizedChild = sanitizeBodyNode(child, nextCtm, canvas, safeViewport, state);
|
|
900
|
+
if (sanitizedChild !== null) keptChildren.push(sanitizedChild);
|
|
901
|
+
}
|
|
902
|
+
if (keptChildren.length === 0) return null;
|
|
903
|
+
node.children.length = 0;
|
|
904
|
+
node.children.push(...keptChildren);
|
|
905
|
+
return node;
|
|
906
|
+
}
|
|
907
|
+
const hasStroke = node.attrs.get("stroke") !== void 0 && node.attrs.get("stroke") !== "none";
|
|
908
|
+
if (hasNonFiniteAttr(node, [
|
|
909
|
+
"stroke-width",
|
|
910
|
+
"opacity",
|
|
911
|
+
"fill-opacity",
|
|
912
|
+
"stroke-opacity"
|
|
913
|
+
])) return null;
|
|
914
|
+
const strokeWidth = parseNumber(node.attrs.get("stroke-width")) ?? 0;
|
|
915
|
+
if (!Number.isFinite(strokeWidth) || strokeWidth < 0) return null;
|
|
916
|
+
if (node.tag === "rect" && (node.attrs.get("width")?.trim().endsWith("%") || node.attrs.get("height")?.trim().endsWith("%"))) return node;
|
|
917
|
+
const localBbox = sanitizeGeometryElementBbox(node, canvas, safeViewport, !hasStroke);
|
|
918
|
+
if (localBbox === null) return null;
|
|
919
|
+
const pad = hasStroke ? Math.max(2, strokeWidth) : 0;
|
|
920
|
+
if (!boxesIntersect(transformBbox({
|
|
921
|
+
minX: localBbox.minX - pad,
|
|
922
|
+
minY: localBbox.minY - pad,
|
|
923
|
+
maxX: localBbox.maxX + pad,
|
|
924
|
+
maxY: localBbox.maxY + pad
|
|
925
|
+
}, nextCtm), safeViewport)) return null;
|
|
926
|
+
if (!hasStroke && node.attrs.get("fill") === "none" && node.attrs.get("clip-path") === void 0) return null;
|
|
927
|
+
return node;
|
|
928
|
+
}
|
|
929
|
+
function resolveRasterTokensInSvgTree(svgRoot, registry, pendingRasterTokens) {
|
|
930
|
+
const occurrences = [];
|
|
931
|
+
const groups = /* @__PURE__ */ new Map();
|
|
932
|
+
const visitChildren = (parent) => {
|
|
933
|
+
for (let i = 0; i < parent.children.length; i += 1) {
|
|
934
|
+
const child = parent.children[i];
|
|
935
|
+
if (child === void 0 || child.kind !== "element") continue;
|
|
936
|
+
if (child.tag === "image") {
|
|
937
|
+
const href = child.attrs.get("href");
|
|
938
|
+
const token = href === void 0 ? void 0 : pendingRasterTokens?.get(href) ?? href;
|
|
939
|
+
if (token !== void 0 && token.startsWith(RASTER_TOKEN_PREFIX)) {
|
|
940
|
+
const id = Number(token.slice(18));
|
|
941
|
+
const entry = Number.isInteger(id) && id >= 0 ? registry.getEntry(id) : void 0;
|
|
942
|
+
if (entry !== void 0) {
|
|
943
|
+
const x = child.attrs.get("x") ?? "0";
|
|
944
|
+
const y = child.attrs.get("y") ?? "0";
|
|
945
|
+
const width = child.attrs.get("width");
|
|
946
|
+
const height = child.attrs.get("height");
|
|
947
|
+
const preserveAspectRatio = child.attrs.get("preserveAspectRatio");
|
|
948
|
+
const numX = Number(x);
|
|
949
|
+
const numY = Number(y);
|
|
950
|
+
const numW = Number(width);
|
|
951
|
+
const numH = Number(height);
|
|
952
|
+
const groupKey = !(width !== void 0 && height !== void 0 && Number.isFinite(numX) && Number.isFinite(numY) && Number.isFinite(numW) && Number.isFinite(numH) && numW > EPSILON && numH > EPSILON) ? void 0 : preserveAspectRatio === "none" ? `${entry.id}|none` : `${entry.id}|${preserveAspectRatio ?? ""}|${width}|${height}`;
|
|
953
|
+
const occurrence = {
|
|
954
|
+
parent,
|
|
955
|
+
childIndex: i,
|
|
956
|
+
element: child,
|
|
957
|
+
entry,
|
|
958
|
+
x,
|
|
959
|
+
y,
|
|
960
|
+
width,
|
|
961
|
+
height,
|
|
962
|
+
preserveAspectRatio,
|
|
963
|
+
groupKey
|
|
964
|
+
};
|
|
965
|
+
occurrences.push(occurrence);
|
|
966
|
+
if (groupKey !== void 0) {
|
|
967
|
+
let bucket = groups.get(groupKey);
|
|
968
|
+
if (bucket === void 0) {
|
|
969
|
+
bucket = [];
|
|
970
|
+
groups.set(groupKey, bucket);
|
|
971
|
+
}
|
|
972
|
+
bucket.push(occurrence);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
visitChildren(child);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
visitChildren(svgRoot);
|
|
981
|
+
if (occurrences.length === 0) return;
|
|
982
|
+
for (const occurrence of occurrences) if (occurrence.groupKey === void 0 || (groups.get(occurrence.groupKey)?.length ?? 0) < 2) occurrence.element.attrs.set("href", registry.getDataUri(occurrence.entry));
|
|
983
|
+
const sharedDefImages = [];
|
|
984
|
+
let sharedSeq = 0;
|
|
985
|
+
for (const members of groups.values()) {
|
|
986
|
+
if (members.length < 2) continue;
|
|
987
|
+
const first = members[0];
|
|
988
|
+
sharedSeq += 1;
|
|
989
|
+
const sharedId = `${registry.idPrefix}-${sharedSeq}`;
|
|
990
|
+
const isUnitStretch = first.preserveAspectRatio === "none";
|
|
991
|
+
const defAttrs = /* @__PURE__ */ new Map([
|
|
992
|
+
["id", sharedId],
|
|
993
|
+
["x", "0"],
|
|
994
|
+
["y", "0"],
|
|
995
|
+
["width", isUnitStretch ? "1" : first.width],
|
|
996
|
+
["height", isUnitStretch ? "1" : first.height]
|
|
997
|
+
]);
|
|
998
|
+
if (first.preserveAspectRatio !== void 0) defAttrs.set("preserveAspectRatio", first.preserveAspectRatio);
|
|
999
|
+
defAttrs.set("href", registry.getDataUri(first.entry));
|
|
1000
|
+
sharedDefImages.push({
|
|
1001
|
+
kind: "element",
|
|
1002
|
+
tag: "image",
|
|
1003
|
+
attrs: defAttrs,
|
|
1004
|
+
children: [],
|
|
1005
|
+
selfClosing: true
|
|
1006
|
+
});
|
|
1007
|
+
for (const member of members) {
|
|
1008
|
+
const passthroughAttrs = /* @__PURE__ */ new Map();
|
|
1009
|
+
for (const [key, value] of member.element.attrs.entries()) {
|
|
1010
|
+
if (key === "href" || key === "x" || key === "y" || key === "width" || key === "height" || key === "preserveAspectRatio") continue;
|
|
1011
|
+
passthroughAttrs.set(key, value);
|
|
1012
|
+
}
|
|
1013
|
+
const useAttrs = /* @__PURE__ */ new Map([["href", `#${sharedId}`]]);
|
|
1014
|
+
const transform = isUnitStretch ? `translate(${member.x} ${member.y}) scale(${member.width} ${member.height})` : Number(member.x) === 0 && Number(member.y) === 0 ? void 0 : `translate(${member.x} ${member.y})`;
|
|
1015
|
+
if (transform !== void 0) useAttrs.set("transform", transform);
|
|
1016
|
+
const useNode = {
|
|
1017
|
+
kind: "element",
|
|
1018
|
+
tag: "use",
|
|
1019
|
+
attrs: useAttrs,
|
|
1020
|
+
children: [],
|
|
1021
|
+
selfClosing: true
|
|
1022
|
+
};
|
|
1023
|
+
member.parent.children[member.childIndex] = passthroughAttrs.size === 0 ? useNode : {
|
|
1024
|
+
kind: "element",
|
|
1025
|
+
tag: "g",
|
|
1026
|
+
attrs: passthroughAttrs,
|
|
1027
|
+
children: [useNode],
|
|
1028
|
+
selfClosing: false
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
if (sharedDefImages.length > 0) svgRoot.children.unshift({
|
|
1033
|
+
kind: "element",
|
|
1034
|
+
tag: "defs",
|
|
1035
|
+
attrs: /* @__PURE__ */ new Map(),
|
|
1036
|
+
children: sharedDefImages,
|
|
1037
|
+
selfClosing: false
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Sanitizes an assembled single-page SVG before handing it to `@resvg/resvg-js`,
|
|
1042
|
+
* eliminating zero-area clipPaths/masks/filters, degenerate gradients, non-finite numbers,
|
|
1043
|
+
* and extreme off-canvas geometry that trigger Rust `geom.rs` panics, then materializes
|
|
1044
|
+
* registered page raster tokens into either inline `<image>` or shared `<defs>` + `<use>`.
|
|
1045
|
+
*/
|
|
1046
|
+
function sanitizeSvgForRasterization(svg, dimensions, rasterRegistry, pendingRasterTokens) {
|
|
1047
|
+
const width = Number.isFinite(dimensions.width) && dimensions.width > EPSILON ? dimensions.width : 1;
|
|
1048
|
+
const height = Number.isFinite(dimensions.height) && dimensions.height > EPSILON ? dimensions.height : 1;
|
|
1049
|
+
const safeViewport = {
|
|
1050
|
+
minX: -512,
|
|
1051
|
+
minY: -512,
|
|
1052
|
+
maxX: width + SAFE_OFFSCREEN_PAD,
|
|
1053
|
+
maxY: height + SAFE_OFFSCREEN_PAD
|
|
1054
|
+
};
|
|
1055
|
+
const state = {
|
|
1056
|
+
droppedClipIds: /* @__PURE__ */ new Set(),
|
|
1057
|
+
droppedMaskIds: /* @__PURE__ */ new Set(),
|
|
1058
|
+
droppedPatternIds: /* @__PURE__ */ new Set(),
|
|
1059
|
+
droppedFilterIds: /* @__PURE__ */ new Set(),
|
|
1060
|
+
droppedGradientIds: /* @__PURE__ */ new Set(),
|
|
1061
|
+
gradientFallbacks: /* @__PURE__ */ new Map()
|
|
1062
|
+
};
|
|
1063
|
+
const nodes = parseSvgTree(svg);
|
|
1064
|
+
const svgRoot = nodes.find((node) => node.kind === "element" && node.tag === "svg");
|
|
1065
|
+
if (svgRoot === void 0) return svg;
|
|
1066
|
+
const collectDefs = (el) => {
|
|
1067
|
+
for (const child of el.children) {
|
|
1068
|
+
if (child.kind !== "element") continue;
|
|
1069
|
+
if (child.tag === "defs") sanitizeDefsBlock(child, {
|
|
1070
|
+
width,
|
|
1071
|
+
height
|
|
1072
|
+
}, safeViewport, state);
|
|
1073
|
+
else collectDefs(child);
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
collectDefs(svgRoot);
|
|
1077
|
+
const keptRootChildren = [];
|
|
1078
|
+
for (const child of svgRoot.children) {
|
|
1079
|
+
const sanitized = sanitizeBodyNode(child, IDENTITY_MATRIX, {
|
|
1080
|
+
width,
|
|
1081
|
+
height
|
|
1082
|
+
}, safeViewport, state);
|
|
1083
|
+
if (sanitized !== null) keptRootChildren.push(sanitized);
|
|
1084
|
+
}
|
|
1085
|
+
svgRoot.children.length = 0;
|
|
1086
|
+
svgRoot.children.push(...keptRootChildren);
|
|
1087
|
+
if (rasterRegistry !== void 0 && rasterRegistry.size > 0) resolveRasterTokensInSvgTree(svgRoot, rasterRegistry, pendingRasterTokens);
|
|
1088
|
+
return nodes.map(serializeSvgNode).join("");
|
|
1089
|
+
}
|
|
1090
|
+
export { createPageRasterRegistry, sanitizeSvgForRasterization };
|