ooxml-ui 1.33.0 → 1.35.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/{chunk-VSHQNHDG.js → chunk-BOTLS2PR.js} +5 -0
- package/dist/{chunk-6TS7ASDJ.js → chunk-C4KI635Q.js} +2 -17
- package/dist/chunk-D5IRYZLP.js +19 -0
- package/dist/{chunk-XPUXFZNB.js → chunk-FFM3WVLU.js} +18 -4
- package/dist/{chunk-CALEXPBD.js → chunk-GZNBWWJ5.js} +840 -51
- package/dist/{chunk-QK5DQR6L.js → chunk-TGG36HHF.js} +2 -2
- package/dist/docx/print-picture.d.ts +4 -0
- package/dist/docx.js +46 -7
- package/dist/fonts/catalog.d.ts +0 -1
- package/dist/image-native-size.d.ts +43 -0
- package/dist/image-native-size.d.ts.map +1 -0
- package/dist/index.js +4 -4
- package/dist/picture-artistic-filters.d.ts +9 -0
- package/dist/picture-artistic-filters.d.ts.map +1 -0
- package/dist/picture-artistic-preview.d.ts +3 -0
- package/dist/picture-artistic-preview.d.ts.map +1 -0
- package/dist/picture-effects.d.ts +3 -1
- package/dist/picture-effects.d.ts.map +1 -0
- package/dist/picture-paint.d.ts +23 -0
- package/dist/picture-paint.d.ts.map +1 -0
- package/dist/picture-pixels.d.ts +11 -0
- package/dist/picture-pixels.d.ts.map +1 -0
- package/dist/picture-standard-filter.d.ts +6 -0
- package/dist/picture-standard-filter.d.ts.map +1 -0
- package/dist/picture-view.d.ts +10 -0
- package/dist/picture-view.d.ts.map +1 -0
- package/dist/pptx/{chart-3d-view-scene-HNL4NWJT.mjs → chart-3d-view-scene-BKNMGRGO.mjs} +3 -25
- package/dist/pptx/{chart-3d-view-scene-OPVBTZL5.cjs → chart-3d-view-scene-V55XPBBF.cjs} +39 -61
- package/dist/pptx/{chunk-7DT3UJQB.mjs → chunk-5EERUTDC.mjs} +7 -3
- package/dist/pptx/{chunk-S3L5NNCK.cjs → chunk-FROIGMTI.cjs} +1 -1
- package/dist/pptx/{chunk-ZS5EVODY.cjs → chunk-GKQULDFF.cjs} +52 -48
- package/dist/pptx/{chunk-CH4Z6H6C.mjs → chunk-GPQP2R5Y.mjs} +1017 -371
- package/dist/pptx/{chunk-S5I64Y55.cjs → chunk-HIRBPTML.cjs} +12 -12
- package/dist/pptx/{chunk-D4LJJ7Z7.cjs → chunk-KJICUZXM.cjs} +171 -540
- package/dist/pptx/{chunk-TDIJHLS5.cjs → chunk-NPYNJOK2.cjs} +1351 -699
- package/dist/pptx/{chunk-RZVEPTLN.mjs → chunk-QK6LJT3K.mjs} +140 -529
- package/dist/pptx/{chunk-LCCRLB7Q.mjs → chunk-UHDWWRTX.mjs} +1 -1
- package/dist/pptx/{chunk-SPOECCPV.mjs → chunk-WZHYA2B3.mjs} +1 -1
- package/dist/pptx/dom/elements/smartart.d.ts.map +1 -1
- package/dist/pptx/dom/index.cjs +424 -424
- package/dist/pptx/dom/index.mjs +8 -8
- package/dist/pptx/export/html2canvas-clone.cjs +6 -6
- package/dist/pptx/export/html2canvas-clone.mjs +1 -1
- package/dist/pptx/index.cjs +3356 -3352
- package/dist/pptx/index.mjs +4 -4
- package/dist/pptx/render/chart-3d-projection.d.ts +5 -54
- package/dist/pptx/render/chart-3d-projection.d.ts.map +1 -1
- package/dist/pptx/render/chart-3d-shading.d.ts +7 -10
- package/dist/pptx/render/chart-3d-shading.d.ts.map +1 -1
- package/dist/pptx/render/chart-combo-stock.cjs +3 -3
- package/dist/pptx/render/chart-combo-stock.mjs +1 -1
- package/dist/pptx/render/chart-funnel-sunburst.d.ts +1 -1
- package/dist/pptx/render/chart-funnel-sunburst.d.ts.map +1 -1
- package/dist/pptx/render/chart-map-projection.d.ts +2 -37
- package/dist/pptx/render/chart-map-projection.d.ts.map +1 -1
- package/dist/pptx/render/chart-overlays.cjs +7 -7
- package/dist/pptx/render/chart-overlays.mjs +1 -1
- package/dist/pptx/render/chart-region-map-alias.d.ts +1 -11
- package/dist/pptx/render/chart-region-map-alias.d.ts.map +1 -1
- package/dist/pptx/render/chart-region-map-colors.d.ts +1 -3
- package/dist/pptx/render/chart-region-map-colors.d.ts.map +1 -1
- package/dist/pptx/render/chart-region-map-data.d.ts +2 -44
- package/dist/pptx/render/chart-region-map-data.d.ts.map +1 -1
- package/dist/pptx/render/chart-region-map-view.d.ts.map +1 -1
- package/dist/pptx/render/chart-surface-treemap.cjs +4 -4
- package/dist/pptx/render/chart-surface-treemap.mjs +1 -1
- package/dist/pptx/render/chart-view-model-types.d.ts +2 -0
- package/dist/pptx/render/chart-view-model-types.d.ts.map +1 -1
- package/dist/pptx/render/chart-view-model.cjs +44 -44
- package/dist/pptx/render/chart-view-model.mjs +1 -1
- package/dist/pptx/render/chart-waterfall-map.cjs +6 -6
- package/dist/pptx/render/chart-waterfall-map.mjs +1 -1
- package/dist/pptx/render/editor-key-target.d.ts.map +1 -1
- package/dist/pptx/render/image-effect-filter-values.d.ts +1 -10
- package/dist/pptx/render/image-effect-filter-values.d.ts.map +1 -1
- package/dist/pptx/render/image-effects.d.ts +1 -0
- package/dist/pptx/render/image-effects.d.ts.map +1 -1
- package/dist/pptx/render/image-native-size.d.ts +1 -42
- package/dist/pptx/render/image-native-size.d.ts.map +1 -1
- package/dist/pptx/render/image-tiling.d.ts.map +1 -1
- package/dist/pptx/render/index.d.ts +1 -1
- package/dist/pptx/render/index.d.ts.map +1 -1
- package/dist/pptx/render/render-cache.d.ts +1 -3
- package/dist/pptx/render/render-cache.d.ts.map +1 -1
- package/dist/pptx/render/smartart-drawing.d.ts +3 -0
- package/dist/pptx/render/smartart-drawing.d.ts.map +1 -1
- package/dist/pptx/render/smartart-picture-image.d.ts +9 -0
- package/dist/pptx/render/smartart-picture-image.d.ts.map +1 -0
- package/dist/pptx/render/smartart-reflow-to-shapes.d.ts.map +1 -1
- package/dist/pptx/{smartart-insert-preview-RQUFRLSV.mjs → smartart-insert-preview-6BITTUI4.mjs} +5 -5
- package/dist/pptx/{smartart-insert-preview-YKNB37GE.cjs → smartart-insert-preview-BUOS5XQR.cjs} +6 -6
- package/dist/{presentation-preview-DKJC6TUJ.js → presentation-preview-ZVJNGOJO.js} +1 -1
- package/dist/render-cache.d.ts +4 -0
- package/dist/render-cache.d.ts.map +1 -0
- package/dist/smartart/smartart-paint.d.ts +2 -1
- package/dist/smartart/smartart-picture.d.ts +4 -3
- package/dist/smartart.d.ts +3 -0
- package/dist/smartart.js +1 -1
- package/dist/teams/i18n/locales/de.d.ts +1 -0
- package/dist/teams/i18n/locales/en/shell.d.ts +1 -0
- package/dist/teams/i18n/locales/en.d.ts +1 -0
- package/dist/teams/i18n/locales/es.d.ts +1 -0
- package/dist/teams/i18n/locales/fr.d.ts +1 -0
- package/dist/teams/i18n/locales/zh-CN.d.ts +1 -0
- package/dist/teams.js +2 -2
- package/dist/theme-bridge.d.ts +0 -1
- package/dist/visio/viewer-chart-editor.d.ts +2 -1
- package/dist/visio.js +43 -11
- package/dist/xlsx/dialogs/custom-autofilter.d.ts +12 -0
- package/dist/xlsx/dialogs/filter-dates.d.ts +4 -0
- package/dist/xlsx/dialogs/help-dialogs.d.ts +2 -2
- package/dist/xlsx/dialogs/text-to-columns.d.ts +0 -7
- package/dist/xlsx/dialogs/top10-filter.d.ts +5 -0
- package/dist/xlsx/grid/filter-buttons.d.ts +11 -0
- package/dist/xlsx/grid/filter-menu.d.ts +10 -0
- package/dist/xlsx/grid/filter-presets.d.ts +19 -0
- package/dist/xlsx/grid/styles.d.ts +1 -1
- package/dist/xlsx.js +875 -169
- package/package.json +2 -2
|
@@ -3,9 +3,9 @@ import { OfficeElement, controlStyles, definer } from './chunk-QLHCGV4C.js';
|
|
|
3
3
|
import { html, nothing } from 'lit';
|
|
4
4
|
import { hexToRgbChannels } from 'ooxml-core/color';
|
|
5
5
|
import { resolveDrawingColor, buildRectPathGradientSvg, DIAGRAM_COLOR_SECTIONS, DIAGRAM_COLOR_ENTRIES, DIAGRAM_STYLE_ENTRIES, diagramDesignEdit, diagramNodeOutline } from 'ooxml-core/diagram';
|
|
6
|
-
import { evaluatePresetShape, imageRectFromCrop } from 'ooxml-core/geometry';
|
|
7
|
-
import { drawingPathData, resolveDrawingOuterShadow, pictureLuminanceTransfer } from 'ooxml-core/drawingml';
|
|
8
|
-
import { wrapStyledRuns, designTextWidthEm } from 'ooxml-core/text';
|
|
6
|
+
import { evaluatePresetShape, pictureFillCounterTransform, imageRectFromCrop, pictureTileGeometry } from 'ooxml-core/geometry';
|
|
7
|
+
import { drawingPathData, resolveDrawingOuterShadow, pictureLuminanceTransfer, applyPictureHslPixels, resolveDrawingColor as resolveDrawingColor$1, buildImageLuminanceTransfer } from 'ooxml-core/drawingml';
|
|
8
|
+
import { wrapStyledRuns, getSubstituteFontFamily, designTextWidthEm } from 'ooxml-core/text';
|
|
9
9
|
|
|
10
10
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
11
11
|
function diagramShapeElement(doc, shape, approximated) {
|
|
@@ -48,52 +48,818 @@ function diagramShapeElement(doc, shape, approximated) {
|
|
|
48
48
|
rect2.setAttribute("data-approximated", shape.geometry);
|
|
49
49
|
return rect2;
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
// src/picture-artistic-filters.ts
|
|
53
|
+
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
54
|
+
function buildDiscreteTable(steps) {
|
|
55
|
+
const values = [];
|
|
56
|
+
for (let i = 0; i < steps; i++) {
|
|
57
|
+
const v = Math.round(i / (steps - 1) * 100) / 100;
|
|
58
|
+
const count = Math.ceil(256 / steps);
|
|
59
|
+
for (let j = 0; j < count; j++) {
|
|
60
|
+
values.push(v);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return values.slice(0, 256).join(" ");
|
|
64
|
+
}
|
|
65
|
+
function buildArtisticFilterMarkup(effectName, radius) {
|
|
66
|
+
const normalizedRadius = clamp(radius, 0, 100) / 100;
|
|
67
|
+
switch (effectName) {
|
|
68
|
+
case "artisticFilmGrain":
|
|
69
|
+
case "filmGrain": {
|
|
70
|
+
const freq = 0.5 + normalizedRadius * 0.5;
|
|
71
|
+
const opacity = 0.15 + normalizedRadius * 0.25;
|
|
72
|
+
return `<feTurbulence type="fractalNoise" baseFrequency="${freq}" numOctaves="4" seed="1" stitchTiles="stitch" result="grain"/><feColorMatrix in="grain" type="saturate" values="0" result="grainGray"/><feBlend in="SourceGraphic" in2="grainGray" mode="overlay"/><feComponentTransfer><feFuncR type="linear" slope="${1 + opacity * 0.3}" intercept="${opacity * 0.02}"/><feFuncG type="linear" slope="${1 + opacity * 0.3}" intercept="${opacity * 0.02}"/><feFuncB type="linear" slope="${1 + opacity * 0.3}" intercept="${opacity * 0.02}"/></feComponentTransfer>`;
|
|
73
|
+
}
|
|
74
|
+
case "artisticCutout":
|
|
75
|
+
case "cutout": {
|
|
76
|
+
const steps = Math.max(2, Math.round(4 + normalizedRadius * 4));
|
|
77
|
+
const tableValues = buildDiscreteTable(steps);
|
|
78
|
+
return `<feComponentTransfer><feFuncR type="discrete" tableValues="${tableValues}"/><feFuncG type="discrete" tableValues="${tableValues}"/><feFuncB type="discrete" tableValues="${tableValues}"/></feComponentTransfer>`;
|
|
79
|
+
}
|
|
80
|
+
case "artisticCement":
|
|
81
|
+
case "cement": {
|
|
82
|
+
const freq = 1.5 + normalizedRadius * 2.5;
|
|
83
|
+
const desat = Math.max(0, 0.4 - normalizedRadius * 0.3);
|
|
84
|
+
return `<feColorMatrix type="saturate" values="${desat}" result="desat"/><feTurbulence type="fractalNoise" baseFrequency="${freq}" numOctaves="5" seed="2" stitchTiles="stitch" result="cementNoise"/><feColorMatrix in="cementNoise" type="saturate" values="0" result="cementGray"/><feBlend in="desat" in2="cementGray" mode="multiply"/><feComponentTransfer><feFuncR type="linear" slope="1.2" intercept="0"/><feFuncG type="linear" slope="1.2" intercept="0"/><feFuncB type="linear" slope="1.2" intercept="0"/></feComponentTransfer>`;
|
|
85
|
+
}
|
|
86
|
+
case "artisticTexturizer":
|
|
87
|
+
case "texturizer": {
|
|
88
|
+
const freq = 2 + normalizedRadius * 3;
|
|
89
|
+
return `<feTurbulence type="fractalNoise" baseFrequency="${freq}" numOctaves="3" seed="3" stitchTiles="stitch" result="texNoise"/><feColorMatrix in="texNoise" type="saturate" values="0" result="texGray"/><feBlend in="SourceGraphic" in2="texGray" mode="overlay"/><feComponentTransfer><feFuncR type="linear" slope="1.1" intercept="0.02"/><feFuncG type="linear" slope="1.1" intercept="0.02"/><feFuncB type="linear" slope="1.1" intercept="0.02"/></feComponentTransfer>`;
|
|
90
|
+
}
|
|
91
|
+
case "artisticCrisscrossEtching":
|
|
92
|
+
case "crisscrossEtching": {
|
|
93
|
+
const freq = 0.08 + normalizedRadius * 0.12;
|
|
94
|
+
return `<feColorMatrix type="saturate" values="0" result="gray"/><feTurbulence type="turbulence" baseFrequency="${freq} ${freq * 3}" numOctaves="1" seed="7" result="lines"/><feColorMatrix in="lines" type="saturate" values="0" result="linesGray"/><feBlend in="gray" in2="linesGray" mode="multiply"/><feComponentTransfer><feFuncR type="linear" slope="1.3" intercept="-0.05"/><feFuncG type="linear" slope="1.3" intercept="-0.05"/><feFuncB type="linear" slope="1.3" intercept="-0.05"/></feComponentTransfer>`;
|
|
95
|
+
}
|
|
96
|
+
case "artisticMosaic":
|
|
97
|
+
case "artisticMosaicBubbles":
|
|
98
|
+
case "artisticMosiaicBubbles":
|
|
99
|
+
case "mosaicBubbles":
|
|
100
|
+
case "mosaic": {
|
|
101
|
+
const blurAmount = Math.max(2, Math.round(radius * 0.8));
|
|
102
|
+
const freq = 0.02 + normalizedRadius * 0.03;
|
|
103
|
+
return `<feGaussianBlur in="SourceGraphic" stdDeviation="${blurAmount}" result="blurred"/><feTurbulence type="turbulence" baseFrequency="${freq}" numOctaves="1" seed="4" result="cells"/><feDisplacementMap in="blurred" in2="cells" scale="${blurAmount * 0.5}" xChannelSelector="R" yChannelSelector="G" result="mosaic"/><feComponentTransfer in="mosaic"><feFuncR type="linear" slope="1.05" intercept="0"/><feFuncG type="linear" slope="1.05" intercept="0"/><feFuncB type="linear" slope="1.05" intercept="0"/></feComponentTransfer>`;
|
|
104
|
+
}
|
|
105
|
+
case "artisticGlowEdges":
|
|
106
|
+
case "glowEdges":
|
|
107
|
+
case "glow_edges": {
|
|
108
|
+
const edgeBlur = Math.max(1, Math.round(normalizedRadius * 3));
|
|
109
|
+
return `<feColorMatrix type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" result="inverted"/><feGaussianBlur in="inverted" stdDeviation="${edgeBlur}" result="blurredInv"/><feBlend in="SourceGraphic" in2="blurredInv" mode="screen"/><feComponentTransfer><feFuncR type="linear" slope="2" intercept="-0.3"/><feFuncG type="linear" slope="2" intercept="-0.3"/><feFuncB type="linear" slope="2" intercept="-0.3"/></feComponentTransfer>`;
|
|
110
|
+
}
|
|
111
|
+
case "artisticChalkSketch":
|
|
112
|
+
case "chalkSketch":
|
|
113
|
+
case "chalk": {
|
|
114
|
+
const freq = 1 + normalizedRadius * 2;
|
|
115
|
+
const desat = Math.max(0, 0.2 - normalizedRadius * 0.2);
|
|
116
|
+
return `<feColorMatrix type="saturate" values="${desat}" result="gray"/><feTurbulence type="fractalNoise" baseFrequency="${freq}" numOctaves="4" seed="5" stitchTiles="stitch" result="chalkTex"/><feColorMatrix in="chalkTex" type="saturate" values="0" result="chalkGray"/><feBlend in="gray" in2="chalkGray" mode="overlay"/><feComponentTransfer><feFuncR type="linear" slope="1.5" intercept="0.05"/><feFuncG type="linear" slope="1.5" intercept="0.05"/><feFuncB type="linear" slope="1.5" intercept="0.05"/></feComponentTransfer>`;
|
|
117
|
+
}
|
|
118
|
+
case "artisticPencilSketch":
|
|
119
|
+
case "pencilSketch": {
|
|
120
|
+
const blurAmt = Math.max(3, Math.round(4 + normalizedRadius * 8));
|
|
121
|
+
return `<feColorMatrix type="saturate" values="0" result="gray"/><feColorMatrix in="gray" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" result="invGray"/><feGaussianBlur in="invGray" stdDeviation="${blurAmt}" result="blurInv"/><feBlend in="blurInv" in2="gray" mode="screen" result="sketch"/><feComponentTransfer in="sketch"><feFuncR type="linear" slope="1.6" intercept="-0.15"/><feFuncG type="linear" slope="1.6" intercept="-0.15"/><feFuncB type="linear" slope="1.6" intercept="-0.15"/></feComponentTransfer>`;
|
|
122
|
+
}
|
|
123
|
+
case "artisticPencilGrayscale":
|
|
124
|
+
case "pencilGrayscale":
|
|
125
|
+
case "grayPencil": {
|
|
126
|
+
const sharpenBlur = Math.max(0.5, 1 + normalizedRadius * 2);
|
|
127
|
+
return `<feColorMatrix type="saturate" values="0" result="gray"/><feGaussianBlur in="gray" stdDeviation="${sharpenBlur}" result="grayBlur"/><feComposite in="gray" in2="grayBlur" operator="arithmetic" k1="0" k2="1.5" k3="-0.5" k4="0"/>`;
|
|
128
|
+
}
|
|
129
|
+
default:
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
var normalizeRadius01 = (radius) => clamp(radius / 100, 0, 1);
|
|
134
|
+
function buildSimpleArtisticCss(effect, radius) {
|
|
135
|
+
switch (effect) {
|
|
136
|
+
case "blur":
|
|
137
|
+
case "glassEffect":
|
|
138
|
+
return `blur(${Math.min(radius, 20)}px)`;
|
|
139
|
+
case "artisticBlur":
|
|
140
|
+
return `blur(${Math.min(radius, 20)}px)`;
|
|
141
|
+
case "artisticGaussianBlur":
|
|
142
|
+
return `blur(${Math.min(Math.round(radius * 1.2), 24)}px)`;
|
|
143
|
+
case "lineDrawing":
|
|
144
|
+
return "grayscale(100%) contrast(150%)";
|
|
145
|
+
case "artisticLineDrawing":
|
|
146
|
+
return "grayscale(100%) contrast(150%)";
|
|
147
|
+
case "paintStrokes":
|
|
148
|
+
case "watercolorSponge":
|
|
149
|
+
return `blur(${Math.min(radius, 8)}px) saturate(140%) brightness(105%)`;
|
|
150
|
+
case "artisticPaintStrokes":
|
|
151
|
+
return `blur(${Math.min(radius, 8)}px) saturate(140%) brightness(105%)`;
|
|
152
|
+
case "artisticWatercolorSponge":
|
|
153
|
+
return `blur(${Math.min(radius, 8)}px) saturate(150%) brightness(108%)`;
|
|
154
|
+
case "artisticPaint":
|
|
155
|
+
case "paint":
|
|
156
|
+
return `blur(${Math.min(radius, 5)}px) saturate(160%) contrast(110%)`;
|
|
157
|
+
case "artisticPaintBrush":
|
|
158
|
+
case "paintBrush":
|
|
159
|
+
return `blur(${Math.min(radius, 6)}px) saturate(130%)`;
|
|
160
|
+
case "photocopy":
|
|
161
|
+
return "grayscale(100%) contrast(200%) brightness(120%)";
|
|
162
|
+
case "artisticPhotocopy":
|
|
163
|
+
return "grayscale(100%) contrast(200%) brightness(120%)";
|
|
164
|
+
case "pastelsSmooth":
|
|
165
|
+
case "pastels":
|
|
166
|
+
return `blur(${Math.min(radius, 6)}px) saturate(85%) brightness(105%)`;
|
|
167
|
+
case "artisticPastelsSmooth":
|
|
168
|
+
case "artisticPastels":
|
|
169
|
+
return `blur(${Math.min(radius, 6)}px) saturate(85%) brightness(105%)`;
|
|
170
|
+
case "artisticMarker":
|
|
171
|
+
case "marker":
|
|
172
|
+
return "contrast(130%) saturate(150%)";
|
|
173
|
+
case "artisticPlasticWrap":
|
|
174
|
+
case "plasticWrap":
|
|
175
|
+
return "contrast(150%) brightness(115%) saturate(80%)";
|
|
176
|
+
case "artisticLightScreen":
|
|
177
|
+
case "lightScreen":
|
|
178
|
+
return `brightness(${1.2 + normalizeRadius01(radius) * 0.3}) saturate(${Math.max(
|
|
179
|
+
0.5,
|
|
180
|
+
0.8 - normalizeRadius01(radius) * 0.3
|
|
181
|
+
)})`;
|
|
182
|
+
case "artisticGlowDiffused":
|
|
183
|
+
case "glowDiffused":
|
|
184
|
+
return `blur(${Math.min(radius, 6)}px) brightness(${1.15 + normalizeRadius01(radius) * 0.15})`;
|
|
185
|
+
case "artisticSharpenEdges":
|
|
186
|
+
case "sharpen":
|
|
187
|
+
return "contrast(160%) brightness(105%)";
|
|
188
|
+
case "glass":
|
|
189
|
+
case "artisticGlass":
|
|
190
|
+
return `blur(${Math.min(radius, 6)}px) brightness(110%)`;
|
|
191
|
+
// Inspector-gallery entries with no DrawingML counterpart. Without these
|
|
192
|
+
// they fell through to the generic default below, so picking Sepia or
|
|
193
|
+
// Grayscale in the gallery previewed the effect but rendered a near no-op.
|
|
194
|
+
case "sepia":
|
|
195
|
+
return "sepia(100%)";
|
|
196
|
+
case "grayscale":
|
|
197
|
+
return "grayscale(100%)";
|
|
198
|
+
default:
|
|
199
|
+
return "contrast(105%) saturate(105%)";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
var ARTISTIC_PREVIEW_EFFECTS = /* @__PURE__ */ new Set([
|
|
203
|
+
"artisticBlur",
|
|
204
|
+
"artisticCement",
|
|
205
|
+
"artisticChalkSketch",
|
|
206
|
+
"artisticCrisscrossEtching",
|
|
207
|
+
"artisticCutout",
|
|
208
|
+
"artisticFilmGrain",
|
|
209
|
+
"artisticGaussianBlur",
|
|
210
|
+
"artisticGlass",
|
|
211
|
+
"artisticGlowDiffused",
|
|
212
|
+
"artisticGlowEdges",
|
|
213
|
+
"artisticLightScreen",
|
|
214
|
+
"artisticLineDrawing",
|
|
215
|
+
"artisticMarker",
|
|
216
|
+
"artisticMosaic",
|
|
217
|
+
"artisticMosaicBubbles",
|
|
218
|
+
"artisticMosiaicBubbles",
|
|
219
|
+
"artisticPaint",
|
|
220
|
+
"artisticPaintBrush",
|
|
221
|
+
"artisticPaintStrokes",
|
|
222
|
+
"artisticPastels",
|
|
223
|
+
"artisticPastelsSmooth",
|
|
224
|
+
"artisticPencilGrayscale",
|
|
225
|
+
"artisticPencilSketch",
|
|
226
|
+
"artisticPhotocopy",
|
|
227
|
+
"artisticPlasticWrap",
|
|
228
|
+
"artisticSharpenEdges",
|
|
229
|
+
"artisticTexturizer",
|
|
230
|
+
"artisticWatercolorSponge",
|
|
231
|
+
"blur",
|
|
232
|
+
"cement",
|
|
233
|
+
"chalk",
|
|
234
|
+
"chalkSketch",
|
|
235
|
+
"crisscrossEtching",
|
|
236
|
+
"cutout",
|
|
237
|
+
"filmGrain",
|
|
238
|
+
"glass",
|
|
239
|
+
"glassEffect",
|
|
240
|
+
"glowDiffused",
|
|
241
|
+
"glowEdges",
|
|
242
|
+
"glow_edges",
|
|
243
|
+
"grayPencil",
|
|
244
|
+
"grayscale",
|
|
245
|
+
"lightScreen",
|
|
246
|
+
"lineDrawing",
|
|
247
|
+
"marker",
|
|
248
|
+
"mosaic",
|
|
249
|
+
"mosaicBubbles",
|
|
250
|
+
"paint",
|
|
251
|
+
"paintBrush",
|
|
252
|
+
"paintStrokes",
|
|
253
|
+
"pastels",
|
|
254
|
+
"pastelsSmooth",
|
|
255
|
+
"pencilGrayscale",
|
|
256
|
+
"pencilSketch",
|
|
257
|
+
"photocopy",
|
|
258
|
+
"plasticWrap",
|
|
259
|
+
"sepia",
|
|
260
|
+
"sharpen",
|
|
261
|
+
"texturizer",
|
|
262
|
+
"watercolorSponge"
|
|
263
|
+
]);
|
|
264
|
+
|
|
265
|
+
// src/picture-artistic-preview.ts
|
|
51
266
|
var NS = "http://www.w3.org/2000/svg";
|
|
267
|
+
function artisticPictureNodes(doc, name, radius) {
|
|
268
|
+
if (!ARTISTIC_PREVIEW_EFFECTS.has(name) || !Number.isFinite(radius) || radius < 0 || radius > 100)
|
|
269
|
+
return void 0;
|
|
270
|
+
const markup = buildArtisticFilterMarkup(name, radius);
|
|
271
|
+
if (markup) {
|
|
272
|
+
const holder = doc.createElementNS(NS, "svg");
|
|
273
|
+
holder.innerHTML = markup;
|
|
274
|
+
return Array.from(holder.children);
|
|
275
|
+
}
|
|
276
|
+
const css = buildSimpleArtisticCss(name, radius);
|
|
277
|
+
if (!css) return void 0;
|
|
278
|
+
const nodes = [];
|
|
279
|
+
for (const match of css.matchAll(/([a-z-]+)\(([-\d.]+)(%|px|deg)?\)/g)) {
|
|
280
|
+
const effect = match[1], value = Number(match[2]) / (match[3] === "%" ? 100 : 1);
|
|
281
|
+
let node;
|
|
282
|
+
if (effect === "blur") {
|
|
283
|
+
node = doc.createElementNS(NS, "feGaussianBlur");
|
|
284
|
+
node.setAttribute("stdDeviation", String(value));
|
|
285
|
+
} else if (effect === "saturate" || effect === "grayscale") {
|
|
286
|
+
node = doc.createElementNS(NS, "feColorMatrix");
|
|
287
|
+
node.setAttribute("type", "saturate");
|
|
288
|
+
node.setAttribute("values", String(effect === "grayscale" ? 1 - value : value));
|
|
289
|
+
} else if (effect === "brightness" || effect === "contrast") {
|
|
290
|
+
node = doc.createElementNS(NS, "feComponentTransfer");
|
|
291
|
+
for (const ch of ["R", "G", "B"]) {
|
|
292
|
+
const fn = doc.createElementNS(NS, `feFunc${ch}`);
|
|
293
|
+
fn.setAttribute("type", "linear");
|
|
294
|
+
fn.setAttribute("slope", String(value));
|
|
295
|
+
fn.setAttribute("intercept", String(effect === "contrast" ? (1 - value) / 2 : 0));
|
|
296
|
+
node.append(fn);
|
|
297
|
+
}
|
|
298
|
+
} else if (effect === "sepia") {
|
|
299
|
+
node = doc.createElementNS(NS, "feColorMatrix");
|
|
300
|
+
node.setAttribute("type", "matrix");
|
|
301
|
+
node.setAttribute(
|
|
302
|
+
"values",
|
|
303
|
+
"0.393 0.769 0.189 0 0 0.349 0.686 0.168 0 0 0.272 0.534 0.131 0 0 0 0 0 1 0"
|
|
304
|
+
);
|
|
305
|
+
} else return void 0;
|
|
306
|
+
nodes.push(node);
|
|
307
|
+
}
|
|
308
|
+
return nodes.length ? nodes : void 0;
|
|
309
|
+
}
|
|
310
|
+
var NS2 = "http://www.w3.org/2000/svg";
|
|
311
|
+
var thresholdTable = (n) => Array.from({ length: 256 }, (_, i) => i / 255 >= n ? "1" : "0").join(" ");
|
|
312
|
+
function standardPictureFilter(doc, effect, scheme = {}, prefix = "picture") {
|
|
313
|
+
const nodes = [];
|
|
314
|
+
const node = (name, attributes = {}) => {
|
|
315
|
+
const item = doc.createElementNS(NS2, name);
|
|
316
|
+
for (const [key, value2] of Object.entries(attributes)) item.setAttribute(key, String(value2));
|
|
317
|
+
return item;
|
|
318
|
+
};
|
|
319
|
+
const transfer = (channels, attributes) => {
|
|
320
|
+
const item = node("feComponentTransfer");
|
|
321
|
+
for (const channel of channels) item.append(node(`feFunc${channel}`, attributes));
|
|
322
|
+
nodes.push(item);
|
|
323
|
+
};
|
|
324
|
+
const value = effect.values ?? {};
|
|
325
|
+
const colors = effect.colors?.map((color) => {
|
|
326
|
+
const resolved = resolveDrawingColor$1(color, { scheme: (name) => scheme[name] });
|
|
327
|
+
const rgb = resolved ? hexToRgbChannels(resolved.hex) : void 0;
|
|
328
|
+
return rgb && resolved ? { r: rgb.r / 255, g: rgb.g / 255, b: rgb.b / 255, a: resolved.alpha } : void 0;
|
|
329
|
+
});
|
|
330
|
+
switch (effect.name) {
|
|
331
|
+
case "alphaInv":
|
|
332
|
+
transfer(["A"], { type: "linear", slope: -1, intercept: 1 });
|
|
333
|
+
{
|
|
334
|
+
const c = colors?.[0] ?? { r: 0, g: 0, b: 0, a: 1 };
|
|
335
|
+
nodes.push(
|
|
336
|
+
node("feColorMatrix", {
|
|
337
|
+
type: "matrix",
|
|
338
|
+
values: `0 0 0 0 ${c.r} 0 0 0 0 ${c.g} 0 0 0 0 ${c.b} 0 0 0 ${c.a} 0`
|
|
339
|
+
})
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
break;
|
|
343
|
+
case "alphaCeiling":
|
|
344
|
+
transfer(["A"], { type: "discrete", tableValues: ["0", ...Array(255).fill("1")].join(" ") });
|
|
345
|
+
break;
|
|
346
|
+
case "alphaFloor":
|
|
347
|
+
transfer(["A"], { type: "discrete", tableValues: [...Array(255).fill("0"), "1"].join(" ") });
|
|
348
|
+
break;
|
|
349
|
+
case "alphaRepl":
|
|
350
|
+
transfer(["A"], { type: "linear", slope: 0, intercept: value.amount ?? 1 });
|
|
351
|
+
break;
|
|
352
|
+
case "alphaMod":
|
|
353
|
+
transfer(["A"], { type: "gamma", amplitude: value.amount ?? 1, exponent: 2, offset: 0 });
|
|
354
|
+
break;
|
|
355
|
+
case "alphaBiLevel":
|
|
356
|
+
transfer(["A"], {
|
|
357
|
+
type: "discrete",
|
|
358
|
+
tableValues: thresholdTable(value.threshold ?? 0)
|
|
359
|
+
});
|
|
360
|
+
break;
|
|
361
|
+
case "biLevel":
|
|
362
|
+
nodes.push(node("feColorMatrix", { type: "saturate", values: 0 }));
|
|
363
|
+
transfer(["R", "G", "B"], {
|
|
364
|
+
type: "discrete",
|
|
365
|
+
tableValues: thresholdTable(value.threshold ?? 0)
|
|
366
|
+
});
|
|
367
|
+
break;
|
|
368
|
+
case "blur":
|
|
369
|
+
nodes.push(node("feGaussianBlur", { stdDeviation: (value.radiusEmu ?? 0) / 3 }));
|
|
370
|
+
break;
|
|
371
|
+
case "hsl":
|
|
372
|
+
case "tint":
|
|
373
|
+
if (value.hue !== void 0)
|
|
374
|
+
nodes.push(node("feColorMatrix", { type: "hueRotate", values: value.hue }));
|
|
375
|
+
if (value.saturation !== void 0)
|
|
376
|
+
nodes.push(
|
|
377
|
+
node("feColorMatrix", { type: "saturate", values: Math.max(0, 1 + value.saturation) })
|
|
378
|
+
);
|
|
379
|
+
if (value.luminance !== void 0 || value.amount !== void 0) {
|
|
380
|
+
const x = buildImageLuminanceTransfer((value.luminance ?? value.amount ?? 0) * 100);
|
|
381
|
+
transfer(["R", "G", "B"], { type: "linear", slope: x.slope, intercept: x.intercept });
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
case "duotone": {
|
|
385
|
+
const a = colors?.[0], b = colors?.[1];
|
|
386
|
+
if (!a || !b) return { nodes: [], unapplied: "duotone:colour" };
|
|
387
|
+
nodes.push(node("feColorMatrix", { type: "saturate", values: 0 }));
|
|
388
|
+
const map = node("feComponentTransfer");
|
|
389
|
+
for (const channel of ["R", "G", "B"]) {
|
|
390
|
+
const key = channel.toLowerCase();
|
|
391
|
+
map.append(
|
|
392
|
+
node(`feFunc${channel}`, { type: "linear", slope: b[key] - a[key], intercept: a[key] })
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
nodes.push(map);
|
|
396
|
+
if (a.a !== 1 || b.a !== 1) return { nodes, unapplied: "duotone:colour-alpha" };
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case "clrRepl": {
|
|
400
|
+
const c = colors?.[0];
|
|
401
|
+
if (!c) return { nodes: [], unapplied: "clrRepl:colour" };
|
|
402
|
+
nodes.push(
|
|
403
|
+
node("feColorMatrix", {
|
|
404
|
+
type: "matrix",
|
|
405
|
+
values: `0 0 0 0 ${c.r} 0 0 0 0 ${c.g} 0 0 0 0 ${c.b} 0 0 0 ${c.a} 0`
|
|
406
|
+
})
|
|
407
|
+
);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
case "clrChange": {
|
|
411
|
+
const a = colors?.[0], b = colors?.[1];
|
|
412
|
+
if (!a || !b) return { nodes: [], unapplied: "clrChange:colour" };
|
|
413
|
+
if (effect.useAlpha !== false && a.a !== 1)
|
|
414
|
+
return { nodes: [], unapplied: "clrChange:source-alpha" };
|
|
415
|
+
const opaque = node("feComponentTransfer", {
|
|
416
|
+
in: "PICTURE_INPUT",
|
|
417
|
+
result: `${prefix}-opaque`
|
|
418
|
+
});
|
|
419
|
+
opaque.append(node("feFuncA", { type: "linear", slope: 0, intercept: 1 }));
|
|
420
|
+
nodes.push(opaque);
|
|
421
|
+
const from = node("feFlood", {
|
|
422
|
+
"flood-color": `rgb(${a.r * 255},${a.g * 255},${a.b * 255})`,
|
|
423
|
+
result: `${prefix}-key`
|
|
424
|
+
});
|
|
425
|
+
nodes.push(from);
|
|
426
|
+
nodes.push(
|
|
427
|
+
node("feBlend", {
|
|
428
|
+
in: `${prefix}-opaque`,
|
|
429
|
+
in2: `${prefix}-key`,
|
|
430
|
+
mode: "difference",
|
|
431
|
+
result: `${prefix}-distance`
|
|
432
|
+
})
|
|
433
|
+
);
|
|
434
|
+
nodes.push(
|
|
435
|
+
node("feColorMatrix", {
|
|
436
|
+
in: `${prefix}-distance`,
|
|
437
|
+
type: "matrix",
|
|
438
|
+
values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0"
|
|
439
|
+
})
|
|
440
|
+
);
|
|
441
|
+
transfer(["A"], { type: "discrete", tableValues: ["1", ...Array(255).fill("0")].join(" ") });
|
|
442
|
+
nodes[nodes.length - 1].setAttribute("result", `${prefix}-mask`);
|
|
443
|
+
nodes.push(
|
|
444
|
+
node("feColorMatrix", {
|
|
445
|
+
in: "PICTURE_INPUT",
|
|
446
|
+
type: "matrix",
|
|
447
|
+
values: `0 0 0 0 ${b.r} 0 0 0 0 ${b.g} 0 0 0 0 ${b.b} 0 0 0 ${b.a} 0`,
|
|
448
|
+
result: `${prefix}-replacement`
|
|
449
|
+
})
|
|
450
|
+
);
|
|
451
|
+
nodes.push(
|
|
452
|
+
node("feComposite", {
|
|
453
|
+
in: `${prefix}-replacement`,
|
|
454
|
+
in2: `${prefix}-mask`,
|
|
455
|
+
operator: "in",
|
|
456
|
+
result: `${prefix}-matched`
|
|
457
|
+
})
|
|
458
|
+
);
|
|
459
|
+
nodes.push(
|
|
460
|
+
node("feComposite", {
|
|
461
|
+
in: "PICTURE_INPUT",
|
|
462
|
+
in2: `${prefix}-mask`,
|
|
463
|
+
operator: "out",
|
|
464
|
+
result: `${prefix}-rest`
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
nodes.push(
|
|
468
|
+
node("feComposite", { in: `${prefix}-matched`, in2: `${prefix}-rest`, operator: "over" })
|
|
469
|
+
);
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return { nodes };
|
|
474
|
+
}
|
|
475
|
+
var NS3 = "http://www.w3.org/2000/svg";
|
|
52
476
|
var serial = 0;
|
|
53
|
-
function pictureEffectFilter(doc, defs, effects) {
|
|
54
|
-
const filter = doc.createElementNS(
|
|
477
|
+
function pictureEffectFilter(doc, defs, effects, scheme = {}) {
|
|
478
|
+
const filter = doc.createElementNS(NS3, "filter");
|
|
55
479
|
filter.id = `office-picture-effects-${++serial}`;
|
|
56
480
|
filter.setAttribute("color-interpolation-filters", "sRGB");
|
|
57
481
|
const unapplied = [];
|
|
482
|
+
const approximated = [];
|
|
483
|
+
let previous = "SourceGraphic", step = 0;
|
|
58
484
|
for (const effect of effects) {
|
|
59
485
|
if (effect.kind === "unsupported") {
|
|
60
486
|
unapplied.push(effect.name);
|
|
61
487
|
continue;
|
|
62
488
|
}
|
|
489
|
+
if (effect.kind === "artistic") {
|
|
490
|
+
if (effect.unhandled?.length) unapplied.push(...effect.unhandled);
|
|
491
|
+
if (effect.baked) continue;
|
|
492
|
+
const nodes = artisticPictureNodes(doc, effect.name, effect.radius);
|
|
493
|
+
if (!nodes) {
|
|
494
|
+
unapplied.push(effect.name);
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
approximated.push(effect.name);
|
|
498
|
+
const input = previous;
|
|
499
|
+
const names = new Map(
|
|
500
|
+
nodes.flatMap(
|
|
501
|
+
(node) => node.hasAttribute("result") ? [[node.getAttribute("result"), `${filter.id}-art${step++}`]] : []
|
|
502
|
+
)
|
|
503
|
+
);
|
|
504
|
+
for (const node of nodes) {
|
|
505
|
+
for (const attribute of ["in", "in2"]) {
|
|
506
|
+
const ref = node.getAttribute(attribute);
|
|
507
|
+
if (ref === "SourceGraphic") node.setAttribute(attribute, input);
|
|
508
|
+
else if (ref && names.has(ref)) node.setAttribute(attribute, names.get(ref));
|
|
509
|
+
}
|
|
510
|
+
const result = node.getAttribute("result");
|
|
511
|
+
if (result && names.has(result)) node.setAttribute("result", names.get(result));
|
|
512
|
+
else node.setAttribute("result", `${filter.id}-r${step++}`);
|
|
513
|
+
if (!node.hasAttribute("in") && !["feTurbulence", "feFlood"].includes(node.localName))
|
|
514
|
+
node.setAttribute("in", previous);
|
|
515
|
+
previous = node.getAttribute("result");
|
|
516
|
+
filter.append(node);
|
|
517
|
+
}
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (effect.kind === "standard") {
|
|
521
|
+
const result = standardPictureFilter(doc, effect, scheme, `${filter.id}-${step++}`);
|
|
522
|
+
if (result.unapplied) unapplied.push(result.unapplied);
|
|
523
|
+
if (["hsl", "tint", "clrChange"].includes(effect.name)) approximated.push(effect.name);
|
|
524
|
+
const input = previous;
|
|
525
|
+
for (const item of result.nodes) {
|
|
526
|
+
if (item.getAttribute("in") === "PICTURE_INPUT") item.setAttribute("in", input);
|
|
527
|
+
else if (!item.hasAttribute("in") && item.localName !== "feFlood")
|
|
528
|
+
item.setAttribute("in", previous);
|
|
529
|
+
if (!item.hasAttribute("result")) item.setAttribute("result", `${filter.id}-r${step++}`);
|
|
530
|
+
previous = item.getAttribute("result");
|
|
531
|
+
filter.append(item);
|
|
532
|
+
}
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
63
535
|
if (effect.kind === "grayscale") {
|
|
64
|
-
const node = doc.createElementNS(
|
|
536
|
+
const node = doc.createElementNS(NS3, "feColorMatrix");
|
|
65
537
|
node.setAttribute("type", "saturate");
|
|
66
538
|
node.setAttribute("values", "0");
|
|
539
|
+
node.setAttribute("in", previous);
|
|
540
|
+
node.setAttribute("result", `${filter.id}-r${step++}`);
|
|
541
|
+
previous = node.getAttribute("result");
|
|
67
542
|
filter.append(node);
|
|
68
543
|
} else {
|
|
69
|
-
const transfer = doc.createElementNS(
|
|
544
|
+
const transfer = doc.createElementNS(NS3, "feComponentTransfer");
|
|
70
545
|
if (effect.kind === "alphaModFix") {
|
|
71
|
-
const channel = doc.createElementNS(
|
|
546
|
+
const channel = doc.createElementNS(NS3, "feFuncA");
|
|
72
547
|
channel.setAttribute("type", "linear");
|
|
73
548
|
channel.setAttribute("slope", String(effect.amount));
|
|
74
549
|
transfer.append(channel);
|
|
75
550
|
} else {
|
|
76
551
|
const { slope, intercept } = pictureLuminanceTransfer(effect.brightness, effect.contrast);
|
|
77
552
|
for (const name of ["R", "G", "B"]) {
|
|
78
|
-
const channel = doc.createElementNS(
|
|
553
|
+
const channel = doc.createElementNS(NS3, `feFunc${name}`);
|
|
79
554
|
channel.setAttribute("type", "linear");
|
|
80
555
|
channel.setAttribute("slope", String(slope));
|
|
81
556
|
channel.setAttribute("intercept", String(intercept));
|
|
82
557
|
transfer.append(channel);
|
|
83
558
|
}
|
|
84
559
|
}
|
|
560
|
+
transfer.setAttribute("in", previous);
|
|
561
|
+
transfer.setAttribute("result", `${filter.id}-r${step++}`);
|
|
562
|
+
previous = transfer.getAttribute("result");
|
|
85
563
|
filter.append(transfer);
|
|
86
564
|
}
|
|
87
565
|
}
|
|
88
566
|
if (!filter.childNodes.length) return { unapplied };
|
|
89
567
|
defs.append(filter);
|
|
90
|
-
return {
|
|
568
|
+
return {
|
|
569
|
+
filter: `url(#${filter.id})`,
|
|
570
|
+
unapplied,
|
|
571
|
+
...approximated.length ? { approximated } : {}
|
|
572
|
+
};
|
|
91
573
|
}
|
|
92
574
|
|
|
93
|
-
// src/
|
|
94
|
-
var
|
|
575
|
+
// src/render-cache.ts
|
|
576
|
+
var RENDER_CACHE_MAX_BYTES = 8 * 1024 * 1024;
|
|
577
|
+
function setBoundedRenderCache(cache2, key, value, maxEntries) {
|
|
578
|
+
const bytesOf = (entryKey, entryValue) => (entryKey.length + (typeof entryValue === "string" ? entryValue.length : 0)) * 2;
|
|
579
|
+
cache2.delete(key);
|
|
580
|
+
if (bytesOf(key, value) > RENDER_CACHE_MAX_BYTES) return;
|
|
581
|
+
cache2.set(key, value);
|
|
582
|
+
let bytes = 0;
|
|
583
|
+
for (const [entryKey, entryValue] of cache2) bytes += bytesOf(entryKey, entryValue);
|
|
584
|
+
while (cache2.size > maxEntries || bytes > RENDER_CACHE_MAX_BYTES) {
|
|
585
|
+
const first = cache2.entries().next().value;
|
|
586
|
+
if (!first) break;
|
|
587
|
+
bytes -= bytesOf(first[0], first[1]);
|
|
588
|
+
cache2.delete(first[0]);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/picture-pixels.ts
|
|
593
|
+
var cache = /* @__PURE__ */ new Map();
|
|
594
|
+
var pending = /* @__PURE__ */ new Map();
|
|
595
|
+
var keyOf = (url, effects, scheme) => JSON.stringify([url, effects, scheme]);
|
|
596
|
+
var needsPicturePixels = (effects) => effects.some(
|
|
597
|
+
(e) => e.kind === "standard" && (e.name === "hsl" || e.name === "tint" || e.name === "blur")
|
|
598
|
+
);
|
|
599
|
+
function cachedPicturePixels(url, effects, scheme = {}) {
|
|
600
|
+
const value = cache.get(keyOf(url, effects, scheme));
|
|
601
|
+
return value ? JSON.parse(value) : void 0;
|
|
602
|
+
}
|
|
603
|
+
function probePicturePixels(doc, url, effects, scheme = {}) {
|
|
604
|
+
const key = keyOf(url, effects, scheme);
|
|
605
|
+
const cached = cachedPicturePixels(url, effects, scheme);
|
|
606
|
+
if (cached) return Promise.resolve(cached);
|
|
607
|
+
const running = pending.get(key);
|
|
608
|
+
if (running) return running;
|
|
609
|
+
const load = (source) => new Promise((resolve, reject) => {
|
|
610
|
+
const image = doc.createElement("img");
|
|
611
|
+
image.onload = () => resolve(image);
|
|
612
|
+
image.onerror = () => reject(new Error("Picture decode failed"));
|
|
613
|
+
image.src = source;
|
|
614
|
+
});
|
|
615
|
+
const task = (async () => {
|
|
616
|
+
const source = await load(url);
|
|
617
|
+
const canvas = doc.createElement("canvas");
|
|
618
|
+
canvas.width = source.naturalWidth;
|
|
619
|
+
canvas.height = source.naturalHeight;
|
|
620
|
+
if (!canvas.width || !canvas.height || canvas.width * canvas.height > 16777216)
|
|
621
|
+
return void 0;
|
|
622
|
+
const context = canvas.getContext("2d");
|
|
623
|
+
if (!context) return void 0;
|
|
624
|
+
context.drawImage(source, 0, 0);
|
|
625
|
+
let dataUrl = canvas.toDataURL("image/png");
|
|
626
|
+
let queue = [];
|
|
627
|
+
const flush = async () => {
|
|
628
|
+
if (!queue.length) return;
|
|
629
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
630
|
+
const svg = doc.createElementNS(ns, "svg");
|
|
631
|
+
svg.setAttribute("xmlns", ns);
|
|
632
|
+
svg.setAttribute("width", String(canvas.width));
|
|
633
|
+
svg.setAttribute("height", String(canvas.height));
|
|
634
|
+
const defs = doc.createElementNS(ns, "defs");
|
|
635
|
+
svg.append(defs);
|
|
636
|
+
const result2 = pictureEffectFilter(doc, defs, queue, scheme);
|
|
637
|
+
const image = doc.createElementNS(ns, "image");
|
|
638
|
+
image.setAttribute("href", dataUrl);
|
|
639
|
+
image.setAttribute("width", String(canvas.width));
|
|
640
|
+
image.setAttribute("height", String(canvas.height));
|
|
641
|
+
if (result2.filter) image.setAttribute("filter", result2.filter);
|
|
642
|
+
svg.append(image);
|
|
643
|
+
const flattened = await load(`data:image/svg+xml,${encodeURIComponent(svg.outerHTML)}`);
|
|
644
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
645
|
+
context.drawImage(flattened, 0, 0);
|
|
646
|
+
dataUrl = canvas.toDataURL("image/png");
|
|
647
|
+
queue = [];
|
|
648
|
+
};
|
|
649
|
+
for (const effect of effects) {
|
|
650
|
+
if (effect.kind === "standard" && (effect.name === "hsl" || effect.name === "tint")) {
|
|
651
|
+
await flush();
|
|
652
|
+
const image = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
653
|
+
applyPictureHslPixels(image.data, effect);
|
|
654
|
+
context.putImageData(image, 0, 0);
|
|
655
|
+
dataUrl = canvas.toDataURL("image/png");
|
|
656
|
+
} else queue.push(effect);
|
|
657
|
+
}
|
|
658
|
+
await flush();
|
|
659
|
+
const result = { url: dataUrl, width: canvas.width, height: canvas.height };
|
|
660
|
+
setBoundedRenderCache(cache, key, JSON.stringify(result), 64);
|
|
661
|
+
return result;
|
|
662
|
+
})().catch(() => void 0).finally(() => pending.delete(key));
|
|
663
|
+
pending.set(key, task);
|
|
664
|
+
return task;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// src/image-native-size.ts
|
|
668
|
+
var CACHE_MAX = 128;
|
|
669
|
+
var cacheEpoch = 0;
|
|
670
|
+
var sizeCache = /* @__PURE__ */ new Map();
|
|
671
|
+
var pendingProbes = /* @__PURE__ */ new Map();
|
|
672
|
+
function getCachedNativeImageSize(src) {
|
|
673
|
+
return src ? sizeCache.get(src) : void 0;
|
|
674
|
+
}
|
|
675
|
+
function probeNativeImageSize(src) {
|
|
676
|
+
const cached = sizeCache.get(src);
|
|
677
|
+
if (cached) {
|
|
678
|
+
return Promise.resolve(cached);
|
|
679
|
+
}
|
|
680
|
+
const inflight = pendingProbes.get(src);
|
|
681
|
+
if (inflight) {
|
|
682
|
+
return inflight;
|
|
683
|
+
}
|
|
684
|
+
const rememberPending = pendingProbes.size < CACHE_MAX;
|
|
685
|
+
const epoch = cacheEpoch;
|
|
686
|
+
const probe = new Promise((resolve) => {
|
|
687
|
+
if (typeof Image === "undefined") {
|
|
688
|
+
resolve(void 0);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const img = new Image();
|
|
692
|
+
img.onload = () => {
|
|
693
|
+
const size = { width: img.naturalWidth, height: img.naturalHeight };
|
|
694
|
+
resolve(size.width > 0 && size.height > 0 ? size : void 0);
|
|
695
|
+
};
|
|
696
|
+
img.onerror = () => resolve(void 0);
|
|
697
|
+
img.src = src;
|
|
698
|
+
}).then((size) => {
|
|
699
|
+
if (pendingProbes.get(src) === probe) pendingProbes.delete(src);
|
|
700
|
+
if (size && epoch === cacheEpoch) {
|
|
701
|
+
setBoundedRenderCache(sizeCache, src, size, CACHE_MAX);
|
|
702
|
+
}
|
|
703
|
+
return size;
|
|
704
|
+
});
|
|
705
|
+
if (rememberPending) pendingProbes.set(src, probe);
|
|
706
|
+
return probe;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/picture-paint.ts
|
|
710
|
+
var NS4 = "http://www.w3.org/2000/svg";
|
|
95
711
|
var serial2 = 0;
|
|
96
|
-
function
|
|
712
|
+
function picturePaint(doc, defs, fill, media, context = { width: 1, height: 1 }) {
|
|
713
|
+
if (fill.unsupportedPicture?.length)
|
|
714
|
+
return { paint: "#d1d5db", unapplied: fill.unsupportedPicture };
|
|
715
|
+
const source = typeof media === "string" ? { url: media } : { ...media };
|
|
716
|
+
const pattern = doc.createElementNS(NS4, "pattern");
|
|
717
|
+
pattern.id = `office-picture-${++serial2}`;
|
|
718
|
+
pattern.setAttribute("patternUnits", "userSpaceOnUse");
|
|
719
|
+
const unapplied = [];
|
|
720
|
+
const crop = { cropLeft: 0, cropTop: 0, cropRight: 0, cropBottom: 0, ...fill.crop };
|
|
721
|
+
const spanX = 1 - crop.cropLeft - crop.cropRight, spanY = 1 - crop.cropTop - crop.cropBottom;
|
|
722
|
+
const counter = fill.layout?.rotWithShape === false ? pictureFillCounterTransform(
|
|
723
|
+
context.width,
|
|
724
|
+
context.height,
|
|
725
|
+
context.rotation,
|
|
726
|
+
context.flipHorizontal,
|
|
727
|
+
context.flipVertical
|
|
728
|
+
) : void 0;
|
|
729
|
+
if (counter) pattern.setAttribute("patternTransform", counter);
|
|
730
|
+
const originalEffects = fill.effects ?? [];
|
|
731
|
+
const pixelCache = needsPicturePixels(originalEffects) ? cachedPicturePixels(source.url, originalEffects, context.scheme) : void 0;
|
|
732
|
+
const images = [];
|
|
733
|
+
const effects = pictureEffectFilter(doc, defs, originalEffects, context.scheme);
|
|
734
|
+
let pixelReady = Boolean(pixelCache);
|
|
735
|
+
if (pixelCache) {
|
|
736
|
+
source.url = pixelCache.url;
|
|
737
|
+
source.width = pixelCache.width;
|
|
738
|
+
source.height = pixelCache.height;
|
|
739
|
+
pattern.dataset.pixelEffectsReady = "true";
|
|
740
|
+
} else if (needsPicturePixels(originalEffects))
|
|
741
|
+
void probePicturePixels(doc, source.url, originalEffects, context.scheme).then((result) => {
|
|
742
|
+
if (!result) return;
|
|
743
|
+
source.url = result.url;
|
|
744
|
+
pixelReady = true;
|
|
745
|
+
for (const image of images) {
|
|
746
|
+
image.setAttribute("href", result.url);
|
|
747
|
+
image.removeAttribute("filter");
|
|
748
|
+
}
|
|
749
|
+
pattern.dataset.pixelEffectsReady = "true";
|
|
750
|
+
});
|
|
751
|
+
unapplied.push(...effects.unapplied);
|
|
752
|
+
if (effects.approximated?.length)
|
|
753
|
+
pattern.dataset.approximatedPictureEffects = effects.approximated.join(",");
|
|
754
|
+
const appendImage = (parent, x, y, width, height) => {
|
|
755
|
+
const image = doc.createElementNS(NS4, "image");
|
|
756
|
+
for (const [key, value] of Object.entries({ x, y, width, height }))
|
|
757
|
+
image.setAttribute(key, String(value));
|
|
758
|
+
image.setAttribute("href", source.url);
|
|
759
|
+
images.push(image);
|
|
760
|
+
image.setAttribute("preserveAspectRatio", "none");
|
|
761
|
+
if (effects.filter && !pixelReady) image.setAttribute("filter", effects.filter);
|
|
762
|
+
parent.append(image);
|
|
763
|
+
};
|
|
764
|
+
if (spanX <= 0 || spanY <= 0) {
|
|
765
|
+
unapplied.push("invalid-crop");
|
|
766
|
+
pattern.dataset.unapplied = "invalid-crop";
|
|
767
|
+
} else if (fill.layout?.tile) {
|
|
768
|
+
pattern.setAttribute("patternContentUnits", "userSpaceOnUse");
|
|
769
|
+
const paint = (size2) => {
|
|
770
|
+
if (!size2) {
|
|
771
|
+
unapplied.push("tile-image-size");
|
|
772
|
+
pattern.dataset.unapplied = "tile-image-size";
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const tile = fill.layout.tile;
|
|
776
|
+
const cell = pictureTileGeometry(
|
|
777
|
+
context,
|
|
778
|
+
// Office scales the uncropped bitmap to set the tile period; srcRect
|
|
779
|
+
// expands its image inside that fixed cell (native PowerPoint probe).
|
|
780
|
+
size2,
|
|
781
|
+
tile,
|
|
782
|
+
fill.layout?.dpi
|
|
783
|
+
);
|
|
784
|
+
if (!cell) {
|
|
785
|
+
unapplied.push("invalid-tile");
|
|
786
|
+
pattern.dataset.unapplied = "invalid-tile";
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
pattern.replaceChildren();
|
|
790
|
+
for (const [key, value] of Object.entries({
|
|
791
|
+
x: cell.x,
|
|
792
|
+
y: cell.y,
|
|
793
|
+
width: cell.width * cell.columns,
|
|
794
|
+
height: cell.height * cell.rows
|
|
795
|
+
}))
|
|
796
|
+
pattern.setAttribute(key, String(value));
|
|
797
|
+
for (let row = 0; row < cell.rows; row++)
|
|
798
|
+
for (let col = 0; col < cell.columns; col++) {
|
|
799
|
+
const clip = doc.createElementNS(NS4, "clipPath");
|
|
800
|
+
clip.id = `office-picture-clip-${++serial2}`;
|
|
801
|
+
const rect2 = doc.createElementNS(NS4, "rect");
|
|
802
|
+
rect2.setAttribute("width", String(cell.width));
|
|
803
|
+
rect2.setAttribute("height", String(cell.height));
|
|
804
|
+
clip.append(rect2);
|
|
805
|
+
defs.append(clip);
|
|
806
|
+
const group = doc.createElementNS(NS4, "g");
|
|
807
|
+
group.setAttribute(
|
|
808
|
+
"transform",
|
|
809
|
+
`translate(${(col + col % 2) * cell.width} ${(row + row % 2) * cell.height}) scale(${col % 2 ? -1 : 1} ${row % 2 ? -1 : 1})`
|
|
810
|
+
);
|
|
811
|
+
group.setAttribute("clip-path", `url(#${clip.id})`);
|
|
812
|
+
const image = imageRectFromCrop(
|
|
813
|
+
{ x: 0, y: 0, width: cell.width, height: cell.height },
|
|
814
|
+
crop
|
|
815
|
+
);
|
|
816
|
+
appendImage(group, image.x, image.y, image.width, image.height);
|
|
817
|
+
pattern.append(group);
|
|
818
|
+
}
|
|
819
|
+
pattern.dataset.ready = "true";
|
|
820
|
+
};
|
|
821
|
+
const size = source.width && source.height ? { width: source.width, height: source.height } : getCachedNativeImageSize(source.url);
|
|
822
|
+
if (size) paint(size);
|
|
823
|
+
else void probeNativeImageSize(source.url).then(paint);
|
|
824
|
+
} else {
|
|
825
|
+
pattern.setAttribute("width", String(context.width));
|
|
826
|
+
pattern.setAttribute("height", String(context.height));
|
|
827
|
+
pattern.setAttribute("patternContentUnits", "objectBoundingBox");
|
|
828
|
+
const insets = fill.layout?.fillRect ?? { l: 0, t: 0, r: 0, b: 0 };
|
|
829
|
+
const frame = {
|
|
830
|
+
x: insets.l,
|
|
831
|
+
y: insets.t,
|
|
832
|
+
width: 1 - insets.l - insets.r,
|
|
833
|
+
height: 1 - insets.t - insets.b
|
|
834
|
+
};
|
|
835
|
+
if (frame.width <= 0 || frame.height <= 0) {
|
|
836
|
+
unapplied.push("invalid-fillRect");
|
|
837
|
+
pattern.dataset.unapplied = "invalid-fillRect";
|
|
838
|
+
} else {
|
|
839
|
+
const rect2 = imageRectFromCrop(frame, crop);
|
|
840
|
+
const clip = doc.createElementNS(NS4, "clipPath");
|
|
841
|
+
clip.id = `office-picture-clip-${++serial2}`;
|
|
842
|
+
clip.setAttribute("clipPathUnits", "userSpaceOnUse");
|
|
843
|
+
const box = doc.createElementNS(NS4, "rect");
|
|
844
|
+
for (const [key, value] of Object.entries(frame)) box.setAttribute(key, String(value));
|
|
845
|
+
clip.append(box);
|
|
846
|
+
defs.append(clip);
|
|
847
|
+
const group = doc.createElementNS(NS4, "g");
|
|
848
|
+
group.setAttribute("clip-path", `url(#${clip.id})`);
|
|
849
|
+
appendImage(group, rect2.x, rect2.y, rect2.width, rect2.height);
|
|
850
|
+
pattern.append(group);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
defs.append(pattern);
|
|
854
|
+
return {
|
|
855
|
+
paint: `url(#${pattern.id})`,
|
|
856
|
+
unapplied,
|
|
857
|
+
...effects.approximated?.length ? { approximated: effects.approximated } : {}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/smartart/smartart-picture.ts
|
|
862
|
+
function diagramPictureFill(doc, defs, fill, part, resolve, report, context) {
|
|
97
863
|
const fail = (reason) => {
|
|
98
864
|
const key = `picture:${reason}`;
|
|
99
865
|
if (!report.approximatedFills.includes(key)) report.approximatedFills.push(key);
|
|
@@ -104,22 +870,7 @@ function diagramPictureFill(doc, defs, fill, part, resolve, report) {
|
|
|
104
870
|
if (!part || !resolve) return fail("unresolved");
|
|
105
871
|
const url = resolve(part);
|
|
106
872
|
if (!url) return fail("missing-media");
|
|
107
|
-
const
|
|
108
|
-
if (1 - crop.cropLeft - crop.cropRight <= 0 || 1 - crop.cropTop - crop.cropBottom <= 0)
|
|
109
|
-
return fail("invalid-crop");
|
|
110
|
-
const rect2 = imageRectFromCrop({ x: 0, y: 0, width: 1, height: 1 }, crop);
|
|
111
|
-
const pattern = doc.createElementNS(NS2, "pattern");
|
|
112
|
-
pattern.id = `office-smartart-picture-${++serial2}`;
|
|
113
|
-
pattern.setAttribute("width", "1");
|
|
114
|
-
pattern.setAttribute("height", "1");
|
|
115
|
-
pattern.setAttribute("patternContentUnits", "objectBoundingBox");
|
|
116
|
-
const image = doc.createElementNS(NS2, "image");
|
|
117
|
-
for (const key of ["x", "y", "width", "height"])
|
|
118
|
-
image.setAttribute(key, String(rect2[key]));
|
|
119
|
-
image.setAttribute("href", url);
|
|
120
|
-
image.setAttribute("preserveAspectRatio", "none");
|
|
121
|
-
const effects = pictureEffectFilter(doc, defs, fill.effects ?? []);
|
|
122
|
-
if (effects.filter) image.setAttribute("filter", effects.filter);
|
|
873
|
+
const effects = picturePaint(doc, defs, fill, url, context);
|
|
123
874
|
if (effects.unapplied.length)
|
|
124
875
|
report.unappliedEffects = [
|
|
125
876
|
.../* @__PURE__ */ new Set([
|
|
@@ -127,13 +878,13 @@ function diagramPictureFill(doc, defs, fill, part, resolve, report) {
|
|
|
127
878
|
...effects.unapplied.map((name) => `picture:${name}`)
|
|
128
879
|
])
|
|
129
880
|
];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
881
|
+
if (effects.approximated?.length)
|
|
882
|
+
report.approximatedFills.push(...effects.approximated.map((name) => `picture:${name}`));
|
|
883
|
+
return effects.paint;
|
|
133
884
|
}
|
|
134
|
-
var
|
|
885
|
+
var NS5 = "http://www.w3.org/2000/svg";
|
|
135
886
|
var serial3 = 0;
|
|
136
|
-
function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolvePicture) {
|
|
887
|
+
function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolvePicture, pictureContext) {
|
|
137
888
|
if (!fill || fill.kind === "none") return "none";
|
|
138
889
|
if (fill.kind === "solid") return colorToCss(fill.color, scheme, report) ?? "none";
|
|
139
890
|
if (fill.kind === "picture")
|
|
@@ -143,7 +894,8 @@ function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolve
|
|
|
143
894
|
fill,
|
|
144
895
|
fill.relId ? pictureParts[fill.relId] : void 0,
|
|
145
896
|
resolvePicture,
|
|
146
|
-
report
|
|
897
|
+
report,
|
|
898
|
+
pictureContext
|
|
147
899
|
) ?? "#d1d5db";
|
|
148
900
|
if (fill.kind !== "gradient") {
|
|
149
901
|
if (!report.approximatedFills.includes(fill.kind)) report.approximatedFills.push(fill.kind);
|
|
@@ -155,12 +907,12 @@ function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolve
|
|
|
155
907
|
const color = resolveDrawingColor(stop.color, { scheme: (name) => scheme[name] });
|
|
156
908
|
return color ? [{ position: stop.position, color: color.hex, opacity: color.alpha }] : [];
|
|
157
909
|
});
|
|
158
|
-
const pattern = doc.createElementNS(
|
|
910
|
+
const pattern = doc.createElementNS(NS5, "pattern");
|
|
159
911
|
pattern.id = id;
|
|
160
912
|
pattern.setAttribute("width", "1");
|
|
161
913
|
pattern.setAttribute("height", "1");
|
|
162
914
|
pattern.setAttribute("patternContentUnits", "objectBoundingBox");
|
|
163
|
-
const image = doc.createElementNS(
|
|
915
|
+
const image = doc.createElementNS(NS5, "image");
|
|
164
916
|
image.setAttribute("width", "1");
|
|
165
917
|
image.setAttribute("height", "1");
|
|
166
918
|
image.setAttribute("preserveAspectRatio", "none");
|
|
@@ -173,7 +925,7 @@ function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolve
|
|
|
173
925
|
return `url(#${id})`;
|
|
174
926
|
}
|
|
175
927
|
const radial = Boolean(fill.path);
|
|
176
|
-
const gradient = doc.createElementNS(
|
|
928
|
+
const gradient = doc.createElementNS(NS5, radial ? "radialGradient" : "linearGradient");
|
|
177
929
|
gradient.id = id;
|
|
178
930
|
if (radial) {
|
|
179
931
|
const rect2 = fill.fillToRect;
|
|
@@ -192,7 +944,7 @@ function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolve
|
|
|
192
944
|
gradient.setAttribute("y2", String(0.5 + dy));
|
|
193
945
|
}
|
|
194
946
|
for (const stop of fill.stops) {
|
|
195
|
-
const element = doc.createElementNS(
|
|
947
|
+
const element = doc.createElementNS(NS5, "stop");
|
|
196
948
|
element.setAttribute("offset", `${stop.position}%`);
|
|
197
949
|
element.setAttribute("stop-color", colorToCss(stop.color, scheme, report) ?? "#808080");
|
|
198
950
|
gradient.append(element);
|
|
@@ -200,7 +952,7 @@ function diagramFill(doc, defs, fill, scheme, report, pictureParts = {}, resolve
|
|
|
200
952
|
defs.append(gradient);
|
|
201
953
|
return `url(#${id})`;
|
|
202
954
|
}
|
|
203
|
-
var
|
|
955
|
+
var NS6 = "http://www.w3.org/2000/svg";
|
|
204
956
|
function runStyle(element, run, fonts, scheme, report) {
|
|
205
957
|
if (run.sizePt !== void 0) element.setAttribute("font-size", String(run.sizePt * 96 / 72));
|
|
206
958
|
if (run.bold !== void 0) element.setAttribute("font-weight", run.bold ? "700" : "400");
|
|
@@ -212,7 +964,7 @@ function runStyle(element, run, fonts, scheme, report) {
|
|
|
212
964
|
element.setAttribute("fill", colorToCss(run.color, scheme, report) ?? "currentColor");
|
|
213
965
|
const typeface = run.typeface;
|
|
214
966
|
const font = typeface === "+mj-lt" ? fonts.major : typeface === "+mn-lt" ? fonts.minor : typeface;
|
|
215
|
-
if (font) element.setAttribute("font-family", font);
|
|
967
|
+
if (font) element.setAttribute("font-family", getSubstituteFontFamily(font));
|
|
216
968
|
}
|
|
217
969
|
function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
218
970
|
const frame = shape.textFrame ?? shape.frame;
|
|
@@ -258,7 +1010,7 @@ function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
|
258
1010
|
});
|
|
259
1011
|
const first = paragraphs[0]?.runs[0];
|
|
260
1012
|
const size = (first?.sizePt ?? 12) * 96 / 72;
|
|
261
|
-
const text = doc.createElementNS(
|
|
1013
|
+
const text = doc.createElementNS(NS6, "text");
|
|
262
1014
|
text.setAttribute("x", String(ox + w / 2));
|
|
263
1015
|
text.setAttribute("y", String(oy + h / 2));
|
|
264
1016
|
text.setAttribute("text-anchor", "middle");
|
|
@@ -270,7 +1022,7 @@ function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
|
270
1022
|
);
|
|
271
1023
|
const ref = shape.style?.font?.fontIndex;
|
|
272
1024
|
const inherited = ref === "major" ? fonts.major : ref === "minor" ? fonts.minor : void 0;
|
|
273
|
-
if (inherited) text.setAttribute("font-family", inherited);
|
|
1025
|
+
if (inherited) text.setAttribute("font-family", getSubstituteFontFamily(inherited));
|
|
274
1026
|
if (first) runStyle(text, first, fonts, scheme, report);
|
|
275
1027
|
const body = shape.body?.bodyProperties;
|
|
276
1028
|
if (body?.scene3d || body?.shape3d)
|
|
@@ -300,7 +1052,7 @@ function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
|
300
1052
|
let y = anchor === "t" ? contentY : anchor === "b" ? contentY + contentHeight - totalHeight : contentY + (contentHeight - totalHeight) / 2;
|
|
301
1053
|
paragraphs.forEach((paragraph, index) => {
|
|
302
1054
|
if (paragraph.separatorBefore) text.append(doc.createTextNode(paragraph.separatorBefore));
|
|
303
|
-
const line2 = doc.createElementNS(
|
|
1055
|
+
const line2 = doc.createElementNS(NS6, "tspan");
|
|
304
1056
|
const align = paragraph.align;
|
|
305
1057
|
const x = align === "l" ? contentX : align === "r" ? contentX + contentWidth : contentX + contentWidth / 2;
|
|
306
1058
|
const height = heights[index] ?? { line: size, before: 0, after: 0 };
|
|
@@ -309,7 +1061,7 @@ function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
|
309
1061
|
line2.setAttribute("y", String(y + height.line / 2));
|
|
310
1062
|
line2.setAttribute("text-anchor", align === "l" ? "start" : align === "r" ? "end" : "middle");
|
|
311
1063
|
for (const run of paragraph.runs) {
|
|
312
|
-
const span = doc.createElementNS(
|
|
1064
|
+
const span = doc.createElementNS(NS6, "tspan");
|
|
313
1065
|
span.textContent = run.text;
|
|
314
1066
|
runStyle(
|
|
315
1067
|
span,
|
|
@@ -325,7 +1077,7 @@ function diagramTextElement(doc, shape, scheme, fonts, report) {
|
|
|
325
1077
|
});
|
|
326
1078
|
return text;
|
|
327
1079
|
}
|
|
328
|
-
var
|
|
1080
|
+
var NS7 = "http://www.w3.org/2000/svg";
|
|
329
1081
|
var serial4 = 0;
|
|
330
1082
|
function diagramEffects(doc, defs, body, shape, scheme, report) {
|
|
331
1083
|
for (const effect of shape.effects?.effects ?? []) {
|
|
@@ -334,7 +1086,7 @@ function diagramEffects(doc, defs, body, shape, scheme, report) {
|
|
|
334
1086
|
report.unappliedEffects = [.../* @__PURE__ */ new Set([...report.unappliedEffects ?? [], effect.kind])];
|
|
335
1087
|
continue;
|
|
336
1088
|
}
|
|
337
|
-
const filter = doc.createElementNS(
|
|
1089
|
+
const filter = doc.createElementNS(NS7, "filter");
|
|
338
1090
|
filter.id = `office-smartart-shadow-${++serial4}`;
|
|
339
1091
|
filter.setAttribute("filterUnits", "userSpaceOnUse");
|
|
340
1092
|
const pad = Math.max(
|
|
@@ -347,7 +1099,7 @@ function diagramEffects(doc, defs, body, shape, scheme, report) {
|
|
|
347
1099
|
filter.setAttribute("width", String(shape.frame.width / 9525 + pad * 2));
|
|
348
1100
|
filter.setAttribute("height", String(shape.frame.height / 9525 + pad * 2));
|
|
349
1101
|
filter.setAttribute("color-interpolation-filters", "sRGB");
|
|
350
|
-
const drop = doc.createElementNS(
|
|
1102
|
+
const drop = doc.createElementNS(NS7, "feDropShadow");
|
|
351
1103
|
drop.setAttribute("dx", String(shadow.dx));
|
|
352
1104
|
drop.setAttribute("dy", String(shadow.dy));
|
|
353
1105
|
drop.setAttribute("stdDeviation", String(shadow.blur / 2));
|
|
@@ -411,7 +1163,13 @@ function renderDiagramDrawing(doc, drawing, scheme = {}, fonts = {}, resolvePict
|
|
|
411
1163
|
const body = diagramShapeElement(doc, shape, report.approximatedGeometries);
|
|
412
1164
|
body.setAttribute(
|
|
413
1165
|
"fill",
|
|
414
|
-
diagramFill(doc, defs, shape.fill, scheme, report, drawing.pictureParts, resolvePicture
|
|
1166
|
+
diagramFill(doc, defs, shape.fill, scheme, report, drawing.pictureParts, resolvePicture, {
|
|
1167
|
+
width: frame.width / EMU_PER_PX,
|
|
1168
|
+
height: frame.height / EMU_PER_PX,
|
|
1169
|
+
...shape.rotation !== void 0 ? { rotation: shape.rotation } : {},
|
|
1170
|
+
...shape.flipHorizontal ? { flipHorizontal: true } : {},
|
|
1171
|
+
...shape.flipVertical ? { flipVertical: true } : {}
|
|
1172
|
+
})
|
|
415
1173
|
);
|
|
416
1174
|
diagramEffects(doc, defs, body, shape, scheme, report);
|
|
417
1175
|
const stroke = shape.line?.fill && shape.line.widthEmu !== 0 ? diagramFill(
|
|
@@ -437,7 +1195,10 @@ function renderDiagramDrawing(doc, drawing, scheme = {}, fonts = {}, resolvePict
|
|
|
437
1195
|
if (shape.text?.text) group.append(diagramTextElement(doc, shape, scheme, fonts, report));
|
|
438
1196
|
svg.append(group);
|
|
439
1197
|
}
|
|
440
|
-
svg.setAttribute(
|
|
1198
|
+
svg.setAttribute(
|
|
1199
|
+
"viewBox",
|
|
1200
|
+
`0 0 ${Math.max(drawing.extentEmu ? drawing.extentEmu.width / EMU_PER_PX : right, 1)} ${Math.max(drawing.extentEmu ? drawing.extentEmu.height / EMU_PER_PX : bottom, 1)}`
|
|
1201
|
+
);
|
|
441
1202
|
svg.setAttribute("overflow", "visible");
|
|
442
1203
|
return { svg, report };
|
|
443
1204
|
}
|
|
@@ -1231,4 +1992,32 @@ var SmartArtTextPaneController = class {
|
|
|
1231
1992
|
}
|
|
1232
1993
|
};
|
|
1233
1994
|
|
|
1234
|
-
|
|
1995
|
+
// src/picture-view.ts
|
|
1996
|
+
function pictureNeedsSvg(fill) {
|
|
1997
|
+
return Boolean(
|
|
1998
|
+
fill && (fill.crop || fill.layout?.tile || Object.values(fill.layout?.fillRect ?? {}).some((n) => n !== 0) || fill.effects?.some((effect) => effect.kind !== "unsupported"))
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
function pictureSvg(doc, fill, url, width, height, context = {}) {
|
|
2002
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
2003
|
+
const svg = doc.createElementNS(ns, "svg");
|
|
2004
|
+
svg.setAttribute("width", String(width));
|
|
2005
|
+
svg.setAttribute("height", String(height));
|
|
2006
|
+
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
2007
|
+
svg.style.width = "100%";
|
|
2008
|
+
svg.style.height = "100%";
|
|
2009
|
+
const defs = doc.createElementNS(ns, "defs");
|
|
2010
|
+
svg.append(defs);
|
|
2011
|
+
const result = picturePaint(doc, defs, fill, url, { width, height, ...context });
|
|
2012
|
+
const rect2 = doc.createElementNS(ns, "rect");
|
|
2013
|
+
rect2.setAttribute("width", String(width));
|
|
2014
|
+
rect2.setAttribute("height", String(height));
|
|
2015
|
+
rect2.setAttribute("fill", result.paint);
|
|
2016
|
+
svg.append(rect2);
|
|
2017
|
+
if (result.unapplied.length) svg.dataset.unappliedPictureEffects = result.unapplied.join(",");
|
|
2018
|
+
if (result.approximated?.length)
|
|
2019
|
+
svg.dataset.approximatedPictureEffects = result.approximated.join(",");
|
|
2020
|
+
return svg;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
export { OfficeUiSmartArt, OfficeUiSmartArtPicker, OfficeUiSmartArtTextPane, SmartArtTextPaneController, cachedPicturePixels, defineSmartArt, defineSmartArtPicker, defineSmartArtTextPane, needsPicturePixels, pictureEffectFilter, pictureNeedsSvg, picturePaint, pictureSvg, probePicturePixels, renderDiagramDrawing, safeColor, smartArtColorsGalleryState, smartArtLayoutTileSvg, smartArtStylesGalleryState, smartArtTileSvg, svgTile };
|