@file-viewer/assets-ppt 3.3.1 → 3.3.3
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/README.en.md +3 -1
- package/README.md +3 -1
- package/README.zh-CN.md +3 -1
- package/package.json +96 -9
- package/viewer/THIRD_PARTY_LICENSES.assets.json +837 -54
- package/viewer/file-viewer-asset-pack.json +20 -31
- package/viewer/vendor/ppt/LICENSE +160 -122
- package/viewer/vendor/ppt/NOTICE.md +30 -0
- package/viewer/vendor/ppt/README.md +86 -0
- package/viewer/vendor/ppt/dist/core/binary.d.ts +31 -0
- package/viewer/vendor/ppt/dist/core/binary.js +102 -0
- package/viewer/vendor/ppt/dist/core/cfb.d.ts +38 -0
- package/viewer/vendor/ppt/dist/core/cfb.js +208 -0
- package/viewer/vendor/ppt/dist/core/crypto.d.ts +12 -0
- package/viewer/vendor/ppt/dist/core/crypto.js +64 -0
- package/viewer/vendor/ppt/dist/core/errors.d.ts +5 -0
- package/viewer/vendor/ppt/dist/core/errors.js +5 -0
- package/viewer/vendor/ppt/dist/core/inflate.d.ts +11 -0
- package/viewer/vendor/ppt/dist/core/inflate.js +337 -0
- package/viewer/vendor/ppt/dist/core/pict.d.ts +14 -0
- package/viewer/vendor/ppt/dist/core/pict.js +472 -0
- package/viewer/vendor/ppt/dist/core/raster.d.ts +7 -0
- package/viewer/vendor/ppt/dist/core/raster.js +101 -0
- package/viewer/vendor/ppt/dist/core/tiff.d.ts +20 -0
- package/viewer/vendor/ppt/dist/core/tiff.js +254 -0
- package/viewer/vendor/ppt/dist/core/utils.d.ts +9 -0
- package/viewer/vendor/ppt/dist/core/utils.js +13 -0
- package/viewer/vendor/ppt/dist/core/vector-font.d.ts +12 -0
- package/viewer/vendor/ppt/dist/core/vector-font.js +29 -0
- package/viewer/vendor/ppt/dist/core/vector.d.ts +19 -0
- package/viewer/vendor/ppt/dist/core/vector.js +1570 -0
- package/viewer/vendor/ppt/dist/core/xml-text.d.ts +1 -0
- package/viewer/vendor/ppt/dist/core/xml-text.js +6 -0
- package/viewer/vendor/ppt/dist/index.d.ts +12 -0
- package/viewer/vendor/ppt/dist/index.js +8 -0
- package/viewer/vendor/ppt/dist/layout/measure.d.ts +15 -0
- package/viewer/vendor/ppt/dist/layout/measure.js +54 -0
- package/viewer/vendor/ppt/dist/layout/text-layout.d.ts +48 -0
- package/viewer/vendor/ppt/dist/layout/text-layout.js +272 -0
- package/viewer/vendor/ppt/dist/manifest.json +13 -0
- package/viewer/vendor/ppt/dist/playback/media.d.ts +11 -0
- package/viewer/vendor/ppt/dist/playback/media.js +37 -0
- package/viewer/vendor/ppt/dist/playback/navigation.d.ts +2 -0
- package/viewer/vendor/ppt/dist/playback/navigation.js +14 -0
- package/viewer/vendor/ppt/dist/playback/timeline.d.ts +47 -0
- package/viewer/vendor/ppt/dist/playback/timeline.js +154 -0
- package/viewer/vendor/ppt/dist/playback/transitions.d.ts +14 -0
- package/viewer/vendor/ppt/dist/playback/transitions.js +41 -0
- package/viewer/vendor/ppt/dist/ppt/animation.d.ts +3 -0
- package/viewer/vendor/ppt/dist/ppt/animation.js +67 -0
- package/viewer/vendor/ppt/dist/ppt/constants.d.ts +72 -0
- package/viewer/vendor/ppt/dist/ppt/constants.js +21 -0
- package/viewer/vendor/ppt/dist/ppt/drawing.d.ts +15 -0
- package/viewer/vendor/ppt/dist/ppt/drawing.js +508 -0
- package/viewer/vendor/ppt/dist/ppt/encryption.d.ts +14 -0
- package/viewer/vendor/ppt/dist/ppt/encryption.js +241 -0
- package/viewer/vendor/ppt/dist/ppt/extras.d.ts +14 -0
- package/viewer/vendor/ppt/dist/ppt/extras.js +225 -0
- package/viewer/vendor/ppt/dist/ppt/geometry.d.ts +29 -0
- package/viewer/vendor/ppt/dist/ppt/geometry.js +448 -0
- package/viewer/vendor/ppt/dist/ppt/headers-footers.d.ts +11 -0
- package/viewer/vendor/ppt/dist/ppt/headers-footers.js +97 -0
- package/viewer/vendor/ppt/dist/ppt/interactions.d.ts +12 -0
- package/viewer/vendor/ppt/dist/ppt/interactions.js +104 -0
- package/viewer/vendor/ppt/dist/ppt/parser.d.ts +12 -0
- package/viewer/vendor/ppt/dist/ppt/parser.js +356 -0
- package/viewer/vendor/ppt/dist/ppt/pictures.d.ts +10 -0
- package/viewer/vendor/ppt/dist/ppt/pictures.js +215 -0
- package/viewer/vendor/ppt/dist/ppt/records.d.ts +13 -0
- package/viewer/vendor/ppt/dist/ppt/records.js +49 -0
- package/viewer/vendor/ppt/dist/ppt/text.d.ts +19 -0
- package/viewer/vendor/ppt/dist/ppt/text.js +789 -0
- package/viewer/vendor/ppt/dist/pptjs.browser.js +9651 -0
- package/viewer/vendor/ppt/dist/pptjs.mjs +9663 -0
- package/viewer/vendor/ppt/dist/pptjs.worker.js +9650 -0
- package/viewer/vendor/ppt/dist/render/effects.d.ts +23 -0
- package/viewer/vendor/ppt/dist/render/effects.js +125 -0
- package/viewer/vendor/ppt/dist/render/fields.d.ts +11 -0
- package/viewer/vendor/ppt/dist/render/fields.js +176 -0
- package/viewer/vendor/ppt/dist/render/geometry.d.ts +11 -0
- package/viewer/vendor/ppt/dist/render/geometry.js +131 -0
- package/viewer/vendor/ppt/dist/render/safe.d.ts +12 -0
- package/viewer/vendor/ppt/dist/render/safe.js +48 -0
- package/viewer/vendor/ppt/dist/render/svg.d.ts +4 -0
- package/viewer/vendor/ppt/dist/render/svg.js +279 -0
- package/viewer/vendor/ppt/dist/render/text.d.ts +9 -0
- package/viewer/vendor/ppt/dist/render/text.js +181 -0
- package/viewer/vendor/ppt/dist/render/three-d.d.ts +32 -0
- package/viewer/vendor/ppt/dist/render/three-d.js +219 -0
- package/viewer/vendor/ppt/dist/render/wordart.d.ts +16 -0
- package/viewer/vendor/ppt/dist/render/wordart.js +214 -0
- package/viewer/vendor/ppt/dist/runtime.d.ts +125 -0
- package/viewer/vendor/ppt/dist/runtime.js +226 -0
- package/viewer/vendor/ppt/dist/types.d.ts +546 -0
- package/viewer/vendor/ppt/dist/types.js +1 -0
- package/viewer/vendor/ppt/dist/viewer.d.ts +3 -0
- package/viewer/vendor/ppt/dist/viewer.js +264 -0
- package/viewer/vendor/ppt/dist/worker-client.d.ts +25 -0
- package/viewer/vendor/ppt/dist/worker-client.js +61 -0
- package/viewer/vendor/ppt/dist/worker.d.ts +1 -0
- package/viewer/vendor/ppt/dist/worker.js +25 -0
- package/viewer/vendor/ppt/package.json +40 -52
- package/viewer/vendor/ppt/NOTICE +0 -229
- package/viewer/vendor/ppt/frame-cache.mjs +0 -731
- package/viewer/vendor/ppt/index.mjs +0 -941
- package/viewer/vendor/ppt/manifest.json +0 -44
- package/viewer/vendor/ppt/ppt-font-cjk.otf +0 -0
- package/viewer/vendor/ppt/ppt-native.wasm +0 -0
- package/viewer/vendor/ppt/worker.mjs +0 -1720
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Diagnostic, GradientStop, Paint, PptShape, TextMeasurer } from '../types.js';
|
|
2
|
+
/** The caller owns IDs and diagnostics, including those of inherited master shapes. */
|
|
3
|
+
export interface EffectContext {
|
|
4
|
+
id: string;
|
|
5
|
+
defs: string[];
|
|
6
|
+
resolveColor: (value: string | undefined, index: number | undefined, fallback?: string) => string;
|
|
7
|
+
warnings?: Diagnostic[];
|
|
8
|
+
slideId?: number;
|
|
9
|
+
textMeasurer?: TextMeasurer;
|
|
10
|
+
bounds?: {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Interpolate a saved stop list, preserving hard transitions at duplicate offsets. */
|
|
16
|
+
export declare function sampleGradient(stops: readonly GradientStop[], position: number, resolve: EffectContext['resolveColor']): {
|
|
17
|
+
color: string;
|
|
18
|
+
opacity: number;
|
|
19
|
+
};
|
|
20
|
+
/** SVG has no rectangular/concentric-path gradient; bounded nested contours implement it. */
|
|
21
|
+
export declare function renderGradient(paint: Paint, ctx: EffectContext, shape?: PptShape): string;
|
|
22
|
+
/** Offset, double, and emboss shadows preserve absolute drawing-axis offsets in groups. */
|
|
23
|
+
export declare function renderShadow(shape: PptShape, html: string, ctx: EffectContext, parent?: [number, number, number, number]): string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { mapPathToBounds, presetGeometry } from './geometry.js';
|
|
2
|
+
import { color, escapeXml, finite, n } from './safe.js';
|
|
3
|
+
const unit = (v) => Math.max(0, Math.min(1, v));
|
|
4
|
+
function rgb(value) {
|
|
5
|
+
const c = color(value, '#000000');
|
|
6
|
+
if (/^#[\da-f]{3}$/i.test(c))
|
|
7
|
+
return [1, 2, 3].map(i => parseInt(c[i] + c[i], 16));
|
|
8
|
+
if (/^#[\da-f]{6,8}$/i.test(c))
|
|
9
|
+
return [1, 3, 5].map(i => parseInt(c.slice(i, i + 2), 16));
|
|
10
|
+
return [0, 0, 0];
|
|
11
|
+
}
|
|
12
|
+
/** Resolve and order colors once; each contour then needs only a binary search. */
|
|
13
|
+
function gradientSampler(stops, resolve) {
|
|
14
|
+
const ordered = stops.map(stop => ({ position: unit(finite(stop.position)), rgb: rgb(resolve(stop.color, stop.colorIndex)), opacity: unit(finite(stop.opacity, 1)) })).sort((a, b) => a.position - b.position);
|
|
15
|
+
return position => {
|
|
16
|
+
if (!ordered.length)
|
|
17
|
+
return { color: '#ffffff', opacity: 1 };
|
|
18
|
+
const at = unit(finite(position));
|
|
19
|
+
let low = 0, high = ordered.length;
|
|
20
|
+
// Upper bound selects the last duplicate at an exact hard-stop position.
|
|
21
|
+
while (low < high) {
|
|
22
|
+
const middle = (low + high) >>> 1;
|
|
23
|
+
if (ordered[middle].position <= at)
|
|
24
|
+
low = middle + 1;
|
|
25
|
+
else
|
|
26
|
+
high = middle;
|
|
27
|
+
}
|
|
28
|
+
const lo = ordered[Math.max(0, low - 1)], hi = ordered[Math.min(low, ordered.length - 1)];
|
|
29
|
+
const t = hi.position > lo.position ? unit((at - lo.position) / (hi.position - lo.position)) : 0;
|
|
30
|
+
return { color: '#' + lo.rgb.map((v, i) => Math.round(v + (hi.rgb[i] - v) * t).toString(16).padStart(2, '0')).join(''), opacity: lo.opacity + (hi.opacity - lo.opacity) * t };
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Interpolate a saved stop list, preserving hard transitions at duplicate offsets. */
|
|
34
|
+
export function sampleGradient(stops, position, resolve) {
|
|
35
|
+
return gradientSampler(stops, resolve)(position);
|
|
36
|
+
}
|
|
37
|
+
function outline(shape) {
|
|
38
|
+
if (shape?.path)
|
|
39
|
+
return `<path d="${escapeXml(mapPathToBounds(shape.path, shape.pathBounds ?? { x: 0, y: 0, width: shape.bounds.width, height: shape.bounds.height }, 1, 1))}"/>`;
|
|
40
|
+
const geometry = presetGeometry(shape?.preset, 1, 1, shape?.source?.properties);
|
|
41
|
+
return `<${geometry.tag} ${geometry.attrs}/>`;
|
|
42
|
+
}
|
|
43
|
+
/** SVG has no rectangular/concentric-path gradient; bounded nested contours implement it. */
|
|
44
|
+
export function renderGradient(paint, ctx, shape) {
|
|
45
|
+
const id = ctx.id, opacity = unit(finite(paint.opacity, 1));
|
|
46
|
+
const stops = paint.stops?.length ? paint.stops : [{ position: 0, color: paint.color ?? '#ffffff', colorIndex: paint.colorIndex }, { position: 1, color: '#000000' }];
|
|
47
|
+
const gradientType = paint.gradientType ?? 'linear';
|
|
48
|
+
const stopMarkup = gradientType === 'rectangular' || gradientType === 'shape' ? '' : stops.map(s => `<stop offset="${n(unit(finite(s.position)))}" stop-color="${ctx.resolveColor(s.color, s.colorIndex)}" stop-opacity="${n(unit(finite(s.opacity, 1)))}"/>`).join('');
|
|
49
|
+
if (gradientType === 'rectangular' || gradientType === 'shape') {
|
|
50
|
+
const r = paint.gradientRect ?? { left: 0, top: 0, right: 0, bottom: 0 };
|
|
51
|
+
const cx = unit(finite(paint.gradientCenter?.x, (r.left + r.right) / 2)), cy = unit(finite(paint.gradientCenter?.y, (r.top + r.bottom) / 2));
|
|
52
|
+
const parts = [], steps = 96, sample = gradientSampler(stops, ctx.resolveColor);
|
|
53
|
+
const geometry = gradientType === 'shape' ? outline(shape) : '';
|
|
54
|
+
for (let i = 0; i <= steps; i++) {
|
|
55
|
+
const t = i / steps, s = sample(t);
|
|
56
|
+
if (gradientType === 'rectangular') {
|
|
57
|
+
const left = unit(finite(r.left)) * t, top = unit(finite(r.top)) * t, right = 1 + (unit(finite(r.right)) - 1) * t, bottom = 1 + (unit(finite(r.bottom)) - 1) * t;
|
|
58
|
+
parts.push(`<rect x="${n(Math.min(left, right))}" y="${n(Math.min(top, bottom))}" width="${n(Math.abs(right - left))}" height="${n(Math.abs(bottom - top))}" fill="${s.color}" fill-opacity="${n(s.opacity)}"/>`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const scale = Math.max(1e-6, 1 - t);
|
|
62
|
+
parts.push(`<g transform="translate(${n(cx * t)} ${n(cy * t)}) scale(${n(scale)})" fill="${s.color}" fill-opacity="${n(s.opacity)}">${geometry}</g>`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Alpha is applied once to the completed gradient; individual nested translucent
|
|
66
|
+
// layers would otherwise accumulate opacity. An alpha mask samples the same contours.
|
|
67
|
+
const opaqueParts = parts.map(p => p.replace(/ fill-opacity="[^"]*"/g, ''));
|
|
68
|
+
if (stops.some(s => finite(s.opacity, 1) !== 1)) {
|
|
69
|
+
const maskId = `${id}-alpha`;
|
|
70
|
+
const mask = parts.map(p => { const alpha = Number(/fill-opacity="([^"]*)"/.exec(p)?.[1] ?? 1), level = Math.round(unit(alpha) * 255).toString(16).padStart(2, '0'); return p.replace(/fill="#[\da-f]+"/g, `fill="#${level}${level}${level}"`).replace(/ fill-opacity="[^"]*"/g, ''); });
|
|
71
|
+
ctx.defs.push(`<mask id="${maskId}" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox" x="0" y="0" width="1" height="1" style="mask-type:luminance">${mask.join('')}</mask>`);
|
|
72
|
+
ctx.defs.push(`<pattern id="${id}" width="1" height="1" viewBox="0 0 1 1" preserveAspectRatio="none"><g mask="url(#${maskId})">${opaqueParts.join('')}</g></pattern>`);
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
ctx.defs.push(`<pattern id="${id}" width="1" height="1" viewBox="0 0 1 1" preserveAspectRatio="none">${opaqueParts.join('')}</pattern>`);
|
|
76
|
+
}
|
|
77
|
+
else if (gradientType === 'radial') {
|
|
78
|
+
const cx = unit(finite(paint.gradientCenter?.x, .5)), cy = unit(finite(paint.gradientCenter?.y, .5));
|
|
79
|
+
ctx.defs.push(`<radialGradient id="${id}" cx="${n(cx)}" cy="${n(cy)}" r="${n(Math.max(cx, 1 - cx, cy, 1 - cy))}">${stopMarkup}</radialGradient>`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// The gradient coordinate system normally stays parallel to the slide axes.
|
|
83
|
+
const angle = finite(paint.angle) - (paint.rotateWithShape === false ? finite(shape?.rotation) : 0), rad = angle * Math.PI / 180, h = paint.rotateWithShape === false && shape?.flipH ? -1 : 1, v = paint.rotateWithShape === false && shape?.flipV ? -1 : 1, dx = Math.cos(rad) * h, dy = Math.sin(rad) * v;
|
|
84
|
+
const bounds = shape?.bounds ?? ctx.bounds;
|
|
85
|
+
if (paint.gradientScaled === false && !shape?.wordArt && bounds && bounds.width > 0 && bounds.height > 0) {
|
|
86
|
+
const w = bounds.width, height = bounds.height, extent = (Math.abs(w * dx) + Math.abs(height * dy)) / 2;
|
|
87
|
+
ctx.defs.push(`<linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="${n(w / 2 - dx * extent)}" y1="${n(height / 2 - dy * extent)}" x2="${n(w / 2 + dx * extent)}" y2="${n(height / 2 + dy * extent)}">${stopMarkup}</linearGradient>`);
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
ctx.defs.push(`<linearGradient id="${id}" x1="${n(.5 - dx * .5)}" y1="${n(.5 - dy * .5)}" x2="${n(.5 + dx * .5)}" y2="${n(.5 + dy * .5)}">${stopMarkup}</linearGradient>`);
|
|
91
|
+
}
|
|
92
|
+
return `fill="url(#${id})" fill-opacity="${n(opacity)}"`;
|
|
93
|
+
}
|
|
94
|
+
/** Offset, double, and emboss shadows preserve absolute drawing-axis offsets in groups. */
|
|
95
|
+
export function renderShadow(shape, html, ctx, parent = [1, 0, 0, 1]) {
|
|
96
|
+
const shadow = shape.shadow;
|
|
97
|
+
if (!shadow)
|
|
98
|
+
return html;
|
|
99
|
+
if (shadow.type !== 0 && shadow.type !== 1 && shadow.type !== 5) {
|
|
100
|
+
ctx.warnings?.push({ code: 'SHADOW_TRANSFORM_UNSUPPORTED', severity: 'warning', message: `Shadow type ${shadow.type} requires a rich/shape/drawing transformation not present in the supported shadow model`, shapeId: shape.id, slideId: ctx.slideId });
|
|
101
|
+
return html;
|
|
102
|
+
}
|
|
103
|
+
const inverse = (x, y) => { const d = parent[0] * parent[3] - parent[1] * parent[2]; return Math.abs(d) > 1e-12 ? [(parent[3] * x - parent[2] * y) / d, (-parent[1] * x + parent[0] * y) / d] : [x, y]; };
|
|
104
|
+
const [dx, dy] = inverse(finite(shadow.offsetX), finite(shadow.offsetY));
|
|
105
|
+
const [sx, sy] = inverse(finite(shadow.secondOffsetX, shadow.type === 5 ? -shadow.offsetX : 0), finite(shadow.secondOffsetY, shadow.type === 5 ? -shadow.offsetY : 0));
|
|
106
|
+
const blur = Math.max(0, finite(shadow.blur)), pad = Math.max(shape.bounds.width, shape.bounds.height, 1) + Math.max(Math.abs(dx) + Math.abs(dy), Math.abs(sx) + Math.abs(sy)) + 3 * blur;
|
|
107
|
+
// Express ordinary shadows through the same SVG 1.1 primitives as the richer
|
|
108
|
+
// layers. This is equivalent to feDropShadow and also works in older exporters.
|
|
109
|
+
const parts = [], merges = [];
|
|
110
|
+
const layer = (name, x, y, c) => {
|
|
111
|
+
parts.push(`<feOffset in="SourceAlpha" dx="${n(x)}" dy="${n(y)}" result="${name}-offset"/>`);
|
|
112
|
+
if (blur)
|
|
113
|
+
parts.push(`<feGaussianBlur in="${name}-offset" stdDeviation="${n(blur)}" result="${name}-offset"/>`);
|
|
114
|
+
parts.push(`<feFlood flood-color="${c}" flood-opacity="${n(unit(finite(shadow.opacity, 1)))}" result="${name}-color"/><feComposite in="${name}-color" in2="${name}-offset" operator="in" result="${name}"/>`);
|
|
115
|
+
if (shadow.obscured)
|
|
116
|
+
parts.push(`<feComposite in="${name}" in2="SourceAlpha" operator="out" result="${name}"/>`);
|
|
117
|
+
merges.push(`<feMergeNode in="${name}"/>`);
|
|
118
|
+
};
|
|
119
|
+
if (shadow.type === 1 || shadow.type === 5)
|
|
120
|
+
layer('highlight', sx, sy, ctx.resolveColor(shadow.highlightColor, shadow.highlightColorIndex, '#cbcbcb'));
|
|
121
|
+
layer('shadow', dx, dy, ctx.resolveColor(shadow.color, shadow.colorIndex, '#808080'));
|
|
122
|
+
const b = shape.bounds;
|
|
123
|
+
ctx.defs.push(`<filter id="${ctx.id}" filterUnits="userSpaceOnUse" x="${n(b.x - pad)}" y="${n(b.y - pad)}" width="${n(b.width + pad * 2)}" height="${n(b.height + pad * 2)}" color-interpolation-filters="sRGB">${parts.join('')}<feMerge>${merges.join('')}<feMergeNode in="SourceGraphic"/></feMerge></filter>`);
|
|
124
|
+
return `<g filter="url(#${ctx.id})">${html}</g>`;
|
|
125
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Diagnostic, PptSlide, RenderOptions, TextFrame } from '../types.js';
|
|
2
|
+
export interface FieldContext {
|
|
3
|
+
slide: PptSlide;
|
|
4
|
+
options: RenderOptions;
|
|
5
|
+
date: Date;
|
|
6
|
+
warnings: Diagnostic[];
|
|
7
|
+
shapeId: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function headerFooterVisible(type: number | undefined, slide: PptSlide): boolean;
|
|
10
|
+
/** Replaces one source UTF-16 marker in transient runs, never modifying source text or offsets. */
|
|
11
|
+
export declare function resolveTextFields(frame: TextFrame, ctx: FieldContext, placeholderType?: number): TextFrame;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const lcidLocales = { 0x0409: 'en-US', 0x0809: 'en-GB', 0x0C09: 'en-AU', 0x0411: 'ja-JP', 0x0404: 'zh-TW', 0x0804: 'zh-CN', 0x1004: 'zh-SG', 0x1404: 'zh-MO', 0x0C04: 'zh-HK', 0x0412: 'ko-KR', 0x0401: 'ar-SA', 0x040D: 'he-IL', 0x041D: 'sv-SE', 0x041E: 'th-TH', 0x042A: 'vi-VN', 0x0439: 'hi-IN', 0x045A: 'syr-SY' };
|
|
2
|
+
const american = [0, 1, 8, 2, 5, 9, 10, 11, 12, 15, 16, 13, 14];
|
|
3
|
+
const chineseClock = ['yyyy年M月d日h时m分', 'yyyy年M月d日星期Wh时m分s秒', 'HH:mm', 'HH:mm:ss', 'AMPMh时m分', 'AMPMh时m分s秒'];
|
|
4
|
+
/** [MS-PPT] 2.9.50 maps the presentation format ID into [MS-OSHARED] indices. */
|
|
5
|
+
const formatMaps = {
|
|
6
|
+
'en-us': american, 'en-gb': [0, 1, 'd MMMM, yyy', 2, 5, 9, 10, 11, 12, 15, 16, 13, 14], 'en-au': [0, 1, 'd MMMM, yyy', 2, 5, 9, 10, 11, 12, 15, 16, 13, 14],
|
|
7
|
+
'zh-cn': [0, 1, 2, 2, 4, 9, 5, ...chineseClock], 'zh-sg': [0, 1, 3, 2, 4, 9, 5, ...chineseClock], 'zh-hk': [0, 1, 3, 2, 4, 9, 5, ...chineseClock], 'zh-mo': [0, 1, 3, 2, 4, 9, 5, ...chineseClock],
|
|
8
|
+
'zh-tw': [0, 1, 3, 7, 12, 9, 10, 4, 11, 'HH:mm', 'HH:mm:ss', 'H:mm AMPM', 'H:mm:ss AMPM'],
|
|
9
|
+
'ja-jp': [4, 8, 7, 3, 0, 9, 5, 11, 12, 'HH:mm', 'HH:mm:ss', 15, 16],
|
|
10
|
+
'ko-kr': [0, 1, 6, 3, 4, 10, 7, 12, 11, 'HH:mm', 'HH:mm:ss', 13, 14],
|
|
11
|
+
'ar-sa': [0, 1, 2, 3, 4, 5, 8, 7, 8, 1, 10, 11, 5], 'he-il': [0, 1, 2, 6, 11, 5, 12, 7, 8, 9, 1, 11, 6],
|
|
12
|
+
'sv-se': [0, 1, 3, 2, 7, 9, 10, 11, 12, 15, 16, 13, 14], 'th-th': [0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14],
|
|
13
|
+
'vi-vn': [0, 1, 2, 3, 5, 6, 10, 11, 12, 13, 14, 15, 16], 'hi-in': [1, 2, 3, 5, 7, 11, 13, 0, 1, 5, 10, 11, 14], 'syr-sy': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
|
14
|
+
};
|
|
15
|
+
function warning(ctx, code, message) { if (!ctx.warnings.some(d => d.code === code && d.shapeId === ctx.shapeId))
|
|
16
|
+
ctx.warnings.push({ code, severity: 'warning', message, slideId: ctx.slide.id, shapeId: ctx.shapeId }); }
|
|
17
|
+
function localeOf(style, ctx) {
|
|
18
|
+
const language = style.language != null && style.language > 0x0400 ? style.language : style.alternateLanguage != null && style.alternateLanguage > 0x0400 ? style.alternateLanguage : undefined;
|
|
19
|
+
const locale = ctx.options.fieldLocale ?? (language == null ? undefined : lcidLocales[language]);
|
|
20
|
+
if (!locale) {
|
|
21
|
+
warning(ctx, 'DATE_LOCALE_FALLBACK', 'A datetime field has no supported source language; en-US formatting is used. Set fieldLocale to override it.');
|
|
22
|
+
return 'en-US';
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return Intl.getCanonicalLocales(locale)[0] ?? 'en-US';
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
warning(ctx, 'DATE_LOCALE_INVALID', 'The requested date locale is invalid; en-US formatting is used');
|
|
29
|
+
return 'en-US';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function formatter(date, locale, options) { return new Intl.DateTimeFormat(locale, options).format(date); }
|
|
33
|
+
/** The common Windows date-picture symbols. Unknown era/numeral forms stay explicit. */
|
|
34
|
+
function patternDate(pattern, date, locale) {
|
|
35
|
+
if (pattern.length > 256)
|
|
36
|
+
return undefined;
|
|
37
|
+
const p = (value, width = 2) => String(value).padStart(width, '0'), year = date.getFullYear(), hour = date.getHours();
|
|
38
|
+
const part = (options, name) => new Intl.DateTimeFormat(locale, options).formatToParts(date).find(p => p.type === name)?.value ?? '';
|
|
39
|
+
const period = () => part({ hour: 'numeric', hour12: true }, 'dayPeriod');
|
|
40
|
+
const values = { yyyy: () => p(year, 4), yyy: () => p(year, 3), yy: () => p(year % 100), y: () => String(year % 100), MMMM: () => formatter(date, locale, { month: 'long' }), MMM: () => formatter(date, locale, { month: 'short' }), MM: () => p(date.getMonth() + 1), M: () => String(date.getMonth() + 1), dddd: () => formatter(date, locale, { weekday: 'long' }), ddd: () => formatter(date, locale, { weekday: 'short' }), dd: () => p(date.getDate()), d: () => String(date.getDate()), HH: () => p(hour), H: () => String(hour), hh: () => p(hour % 12 || 12), h: () => String(hour % 12 || 12), mm: () => p(date.getMinutes()), m: () => String(date.getMinutes()), ss: () => p(date.getSeconds()), s: () => String(date.getSeconds()), AMPM: period, 'AM/PM': period, 'am/pm': period, tt: period, t: () => period().slice(0, 1), W: () => ['日', '一', '二', '三', '四', '五', '六'][date.getDay()], ggg: () => new Intl.DateTimeFormat('ja-JP-u-ca-japanese', { era: 'long' }).formatToParts(date).find(p => p.type === 'era')?.value ?? '', e: () => new Intl.DateTimeFormat('ja-JP-u-ca-japanese', { year: 'numeric' }).formatToParts(date).find(p => p.type === 'year')?.value ?? '' };
|
|
41
|
+
const tokens = /'(?:[^']|'')*'|"[^"]*"|AM\/PM|am\/pm|AMPM|yyyy|yyy|yy|y|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|tt|t|ggg|e|W|[^A-Za-z]/g;
|
|
42
|
+
let result = '', at = 0;
|
|
43
|
+
for (const match of pattern.matchAll(tokens)) {
|
|
44
|
+
if (match.index !== at)
|
|
45
|
+
return undefined;
|
|
46
|
+
const token = match[0];
|
|
47
|
+
at += token.length;
|
|
48
|
+
result += token[0] === "'" || token[0] === '"' ? token.slice(1, -1).replace(/''/g, "'") : values[token]?.() ?? token;
|
|
49
|
+
}
|
|
50
|
+
return at === pattern.length ? result : undefined;
|
|
51
|
+
}
|
|
52
|
+
function indexedDate(index, date, locale, ctx) {
|
|
53
|
+
const key = locale.toLowerCase(), short = () => formatter(date, locale, { year: 'numeric', month: 'numeric', day: 'numeric' }), long = () => formatter(date, locale, { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' });
|
|
54
|
+
if (index === 0)
|
|
55
|
+
return short();
|
|
56
|
+
if (index === 1)
|
|
57
|
+
return long();
|
|
58
|
+
if (key.startsWith('zh') && key !== 'zh-tw') {
|
|
59
|
+
const patterns = { 2: 'yyyy年M月d日星期W', 3: 'yyyy年M月d日', 4: 'yyyy/M/d', 5: 'yy.M.d', 6: 'yyyy年M月d日星期W', 7: 'yyyy年M月d日', 8: 'yyyy年M月d日星期W', 9: 'yyyy年M月', 10: 'yyyy年M月', 11: 'h时m分s秒', 12: 'h时m分', 13: 'H时m分', 14: 'h时m分', 15: 'AMPMh时m分', 16: 'AMPMh时m分' };
|
|
60
|
+
return patterns[index] ? patternDate(patterns[index], date, locale) : undefined;
|
|
61
|
+
}
|
|
62
|
+
if (key === 'ja-jp') {
|
|
63
|
+
const patterns = { 2: 'ggge年M月d日(ddd)', 3: 'yyyy年M月d日', 4: 'yyyy/M/d', 7: 'ggge年M月d日', 8: 'yyyy年M月d日(ddd)', 9: 'ggge年M月', 10: 'yyyy年M月', 11: 'yy/M/d H時m分', 12: 'yy/M/d H時m分s秒', 13: 'AMPMh時m分', 14: 'AMPMh時m分s秒', 15: 'H時m分', 16: 'H時m分s秒', 17: 'ggge年M月d日 dddd' };
|
|
64
|
+
return patterns[index] ? patternDate(patterns[index], date, locale) : undefined;
|
|
65
|
+
}
|
|
66
|
+
// Chinese-era numerals and calendar-specific locale rules are not silently treated as Gregorian English.
|
|
67
|
+
if (['zh-tw', 'ko-kr', 'th-th', 'hi-in'].includes(key)) {
|
|
68
|
+
warning(ctx, 'DATE_FORMAT_APPROXIMATED', 'This datetime locale uses calendar-specific rules that are approximated with the browser locale formatter');
|
|
69
|
+
}
|
|
70
|
+
const pattern = (value) => patternDate(value, date, locale);
|
|
71
|
+
if (index === 2)
|
|
72
|
+
return formatter(date, locale, { year: 'numeric', month: 'long', day: 'numeric' });
|
|
73
|
+
if (index === 3)
|
|
74
|
+
return formatter(date, locale, { year: '2-digit', month: 'numeric', day: 'numeric' });
|
|
75
|
+
if (index === 4)
|
|
76
|
+
return pattern('yyyy-MM-dd');
|
|
77
|
+
if (index === 5) {
|
|
78
|
+
const first = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric' }).formatToParts(date).find(p => p.type === 'year' || p.type === 'month');
|
|
79
|
+
return pattern(first?.type === 'year' ? 'yy-MMM-d' : 'd-MMM-yy');
|
|
80
|
+
}
|
|
81
|
+
if (index === 6) {
|
|
82
|
+
const separator = short().includes('/') ? '.' : '/';
|
|
83
|
+
return new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric' }).formatToParts(date).filter(p => ['year', 'month', 'day'].includes(p.type)).map(p => p.value).join(separator);
|
|
84
|
+
}
|
|
85
|
+
if (index === 7)
|
|
86
|
+
return formatter(date, locale, { year: '2-digit', month: 'short', day: 'numeric' });
|
|
87
|
+
if (index === 8)
|
|
88
|
+
return pattern(key === 'he-il' ? 'd MMMM, yyyy' : 'd MMMM yyyy');
|
|
89
|
+
if (index === 9)
|
|
90
|
+
return formatter(date, locale, { year: '2-digit', month: 'long' });
|
|
91
|
+
if (index === 10)
|
|
92
|
+
return pattern('MMM-yy');
|
|
93
|
+
if (index === 11 || index === 12)
|
|
94
|
+
return `${short()} ${formatter(date, locale, { hour: 'numeric', minute: '2-digit', ...(index === 12 ? { second: '2-digit' } : {}), hour12: true })}`;
|
|
95
|
+
if (index === 13 || index === 14)
|
|
96
|
+
return pattern(index === 13 ? 'h:mm AMPM' : 'h:mm:ss AMPM');
|
|
97
|
+
if (index === 15 || index === 16)
|
|
98
|
+
return pattern(index === 15 ? 'HH:mm' : 'HH:mm:ss');
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
function dateValue(format, style, ctx) {
|
|
102
|
+
if (!Number.isFinite(ctx.date.getTime())) {
|
|
103
|
+
warning(ctx, 'FIELD_DATE_INVALID', 'fieldDate is not a valid date; the original field marker is retained');
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const locale = localeOf(style, ctx);
|
|
107
|
+
let value;
|
|
108
|
+
if (typeof format === 'string')
|
|
109
|
+
value = patternDate(format, ctx.date, locale);
|
|
110
|
+
else {
|
|
111
|
+
const index = format === 13 ? 0 : format ?? 0, map = formatMaps[locale.toLowerCase()] ?? american;
|
|
112
|
+
if (!formatMaps[locale.toLowerCase()])
|
|
113
|
+
warning(ctx, 'DATE_FORMAT_APPROXIMATED', 'This date language has no exact format-ID table in this build; the default mapping is used with the selected locale');
|
|
114
|
+
const mapped = map[index];
|
|
115
|
+
if (typeof mapped === 'string')
|
|
116
|
+
value = patternDate(mapped, ctx.date, locale);
|
|
117
|
+
else if (mapped != null)
|
|
118
|
+
value = indexedDate(mapped, ctx.date, locale, ctx);
|
|
119
|
+
}
|
|
120
|
+
if (value == null)
|
|
121
|
+
warning(ctx, 'DATE_FORMAT_UNSUPPORTED', 'The datetime picture or calendar-specific format is not supported; the original field marker is retained');
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
function fieldValue(field, style, ctx) {
|
|
125
|
+
if (ctx.slide.suppressHeaderFooter && field.type !== 'dateTime')
|
|
126
|
+
return '';
|
|
127
|
+
const hf = ctx.slide.headersFooters;
|
|
128
|
+
switch (field.type) {
|
|
129
|
+
case 'slideNumber': return String(ctx.slide.displayNumber ?? ctx.slide.index + 1);
|
|
130
|
+
case 'header': return hf?.header ?? '';
|
|
131
|
+
case 'footer': return hf?.footer ?? '';
|
|
132
|
+
case 'genericDate':
|
|
133
|
+
if (hf?.useUserDate)
|
|
134
|
+
return hf.userDate ?? '';
|
|
135
|
+
if (hf?.useCurrentDate)
|
|
136
|
+
return dateValue(hf.format, style, ctx);
|
|
137
|
+
return '';
|
|
138
|
+
case 'dateTime': return dateValue(field.format, style, ctx);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function headerFooterVisible(type, slide) {
|
|
142
|
+
if (type == null || ![7, 8, 9, 10].includes(type))
|
|
143
|
+
return true;
|
|
144
|
+
if (slide.suppressHeaderFooter)
|
|
145
|
+
return false;
|
|
146
|
+
const hf = slide.headersFooters;
|
|
147
|
+
return type === 7 ? !!hf?.showDate : type === 8 ? !!hf?.showSlideNumber : type === 9 ? !!hf?.showFooter : !!hf?.showHeader;
|
|
148
|
+
}
|
|
149
|
+
/** Replaces one source UTF-16 marker in transient runs, never modifying source text or offsets. */
|
|
150
|
+
export function resolveTextFields(frame, ctx, placeholderType) {
|
|
151
|
+
if (!frame.fields?.length) {
|
|
152
|
+
if (placeholderType != null && [7, 8, 9, 10].includes(placeholderType) && frame.paragraphs.length) {
|
|
153
|
+
warning(ctx, 'HEADER_FOOTER_FIELD_MISSING', 'A header/footer placeholder has no metacharacter record; its text is recovered from the current slide settings');
|
|
154
|
+
const first = frame.paragraphs[0], run = first.runs[0], type = placeholderType === 7 ? 'genericDate' : placeholderType === 8 ? 'slideNumber' : placeholderType === 9 ? 'footer' : 'header';
|
|
155
|
+
const text = fieldValue({ position: 0, type }, run?.style ?? {}, ctx);
|
|
156
|
+
if (text != null)
|
|
157
|
+
return { ...frame, paragraphs: [{ ...first, runs: [{ ...(run ?? { style: {} }), text }] }] };
|
|
158
|
+
}
|
|
159
|
+
return frame;
|
|
160
|
+
}
|
|
161
|
+
const fields = [...frame.fields].sort((a, b) => a.position - b.position);
|
|
162
|
+
let cursor = 0, nextOffset = 0;
|
|
163
|
+
const paragraphs = frame.paragraphs.map(paragraph => { const runs = paragraph.runs.map(run => { const start = run.sourceStart ?? nextOffset, end = run.sourceEnd ?? start + run.text.length; nextOffset = end; while (cursor < fields.length && fields[cursor].position < start)
|
|
164
|
+
cursor++; let from = 0, changed = false, result = ''; while (cursor < fields.length && fields[cursor].position < end) {
|
|
165
|
+
const field = fields[cursor++], relative = field.position - start;
|
|
166
|
+
if (relative < from || relative >= run.text.length)
|
|
167
|
+
continue;
|
|
168
|
+
const replacement = fieldValue(field, run.style, ctx);
|
|
169
|
+
if (replacement != null) {
|
|
170
|
+
result += run.text.slice(from, relative) + replacement;
|
|
171
|
+
from = relative + 1;
|
|
172
|
+
changed = true;
|
|
173
|
+
}
|
|
174
|
+
} return changed ? { ...run, text: result + run.text.slice(from) } : run; }); nextOffset++; return { ...paragraph, runs }; });
|
|
175
|
+
return { ...frame, paragraphs };
|
|
176
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Rect } from '../types.js';
|
|
2
|
+
/** Remap geometry coordinates, preserving CSS-pixel line widths under a custom path. */
|
|
3
|
+
export declare function mapPathToBounds(path: string, source: Rect, width: number, height: number): string;
|
|
4
|
+
export interface Geometry {
|
|
5
|
+
tag: 'rect' | 'ellipse' | 'path';
|
|
6
|
+
attrs: string;
|
|
7
|
+
supported: boolean;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** OfficeArt MSOSPT values; shapes with an explicit geometry path bypass these defaults. */
|
|
11
|
+
export declare function presetGeometry(preset: number | undefined, width: number, height: number, properties?: Record<string, number>): Geometry;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { n } from './safe.js';
|
|
2
|
+
/** Remap geometry coordinates, preserving CSS-pixel line widths under a custom path. */
|
|
3
|
+
export function mapPathToBounds(path, source, width, height) {
|
|
4
|
+
const tokens = path.match(/[a-zA-Z]|[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/g) ?? [];
|
|
5
|
+
const sx = source.width ? width / source.width : 1, sy = source.height ? height / source.height : 1;
|
|
6
|
+
const counts = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7, Z: 0 };
|
|
7
|
+
let command = '', position = 0;
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const token of tokens) {
|
|
10
|
+
if (/^[a-zA-Z]$/.test(token)) {
|
|
11
|
+
command = token;
|
|
12
|
+
position = 0;
|
|
13
|
+
out.push(token);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const upper = command.toUpperCase(), count = counts[upper];
|
|
17
|
+
if (count == null || count === 0)
|
|
18
|
+
return path;
|
|
19
|
+
const relative = command !== upper, index = position++ % count, value = Number(token);
|
|
20
|
+
let mapped = value;
|
|
21
|
+
if (upper === 'A') {
|
|
22
|
+
if (index === 0)
|
|
23
|
+
mapped = value * Math.abs(sx);
|
|
24
|
+
else if (index === 1)
|
|
25
|
+
mapped = value * Math.abs(sy);
|
|
26
|
+
else if (index === 5)
|
|
27
|
+
mapped = (value - (relative ? 0 : source.x)) * sx;
|
|
28
|
+
else if (index === 6)
|
|
29
|
+
mapped = (value - (relative ? 0 : source.y)) * sy;
|
|
30
|
+
}
|
|
31
|
+
else if (upper === 'H')
|
|
32
|
+
mapped = (value - (relative ? 0 : source.x)) * sx;
|
|
33
|
+
else if (upper === 'V')
|
|
34
|
+
mapped = (value - (relative ? 0 : source.y)) * sy;
|
|
35
|
+
else
|
|
36
|
+
mapped = index % 2 ? (value - (relative ? 0 : source.y)) * sy : (value - (relative ? 0 : source.x)) * sx;
|
|
37
|
+
out.push(n(mapped));
|
|
38
|
+
}
|
|
39
|
+
return out.join(' ');
|
|
40
|
+
}
|
|
41
|
+
/** OfficeArt MSOSPT values; shapes with an explicit geometry path bypass these defaults. */
|
|
42
|
+
export function presetGeometry(preset, width, height, properties = {}) {
|
|
43
|
+
const w = width, h = height, x = (p) => n(w * p), y = (p) => n(h * p);
|
|
44
|
+
const path = (d, open = false) => ({ tag: 'path', attrs: `d="${d}"`, supported: true, open });
|
|
45
|
+
const polygon = (pts) => path(`M${pts.map(p => `${x(p[0])} ${y(p[1])}`).join('L')}Z`);
|
|
46
|
+
switch (preset ?? 1) {
|
|
47
|
+
case 1:
|
|
48
|
+
case 75:
|
|
49
|
+
case 109:
|
|
50
|
+
case 202: return { tag: 'rect', attrs: `width="${n(w)}" height="${n(h)}"`, supported: true };
|
|
51
|
+
// Same source adjustment convention as msdoc-viewer's officeArtRoundRectRadius.
|
|
52
|
+
case 2: return { tag: 'rect', attrs: `width="${n(w)}" height="${n(h)}" rx="${n(Math.min(w, h) * Math.max(0, Math.min(properties['327'] ?? 2592, 10800)) / 21600)}"`, supported: true };
|
|
53
|
+
case 3: return { tag: 'ellipse', attrs: `cx="${x(.5)}" cy="${y(.5)}" rx="${x(.5)}" ry="${y(.5)}"`, supported: true };
|
|
54
|
+
case 4: return polygon([[.5, 0], [1, .5], [.5, 1], [0, .5]]);
|
|
55
|
+
case 5: return polygon([[.5, 0], [1, 1], [0, 1]]);
|
|
56
|
+
case 6: return polygon([[0, 0], [1, 1], [0, 1]]);
|
|
57
|
+
case 7: return polygon([[.2, 0], [1, 0], [.8, 1], [0, 1]]);
|
|
58
|
+
case 8: return polygon([[.2, 0], [.8, 0], [1, 1], [0, 1]]);
|
|
59
|
+
case 9: return polygon([[.25, 0], [.75, 0], [1, .5], [.75, 1], [.25, 1], [0, .5]]);
|
|
60
|
+
case 10: return polygon([[.3, 0], [.7, 0], [1, .3], [1, .7], [.7, 1], [.3, 1], [0, .7], [0, .3]]);
|
|
61
|
+
case 11: return polygon([[.333, 0], [.667, 0], [.667, .333], [1, .333], [1, .667], [.667, .667], [.667, 1], [.333, 1], [.333, .667], [0, .667], [0, .333], [.333, .333]]);
|
|
62
|
+
case 12:
|
|
63
|
+
case 58:
|
|
64
|
+
case 59:
|
|
65
|
+
case 60:
|
|
66
|
+
case 92: {
|
|
67
|
+
const count = preset === 58 ? 8 : preset === 59 ? 16 : preset === 60 ? 32 : preset === 92 ? 24 : 5;
|
|
68
|
+
const points = [];
|
|
69
|
+
for (let i = 0; i < count * 2; i++) {
|
|
70
|
+
const a = -Math.PI / 2 + i * Math.PI / count, r = i % 2 ? .21 : .5;
|
|
71
|
+
points.push([.5 + Math.cos(a) * r, .5 + Math.sin(a) * r]);
|
|
72
|
+
}
|
|
73
|
+
return polygon(points);
|
|
74
|
+
}
|
|
75
|
+
case 13: return polygon([[0, .25], [.75, .25], [.75, 0], [1, .5], [.75, 1], [.75, .75], [0, .75]]);
|
|
76
|
+
case 14: return polygon([[0, .25], [.4, .25], [.4, 0], [1, .5], [.4, 1], [.4, .75], [0, .75], [.2, .5]]);
|
|
77
|
+
case 15: return polygon([[0, 0], [.7, 0], [1, .5], [.7, 1], [0, 1]]);
|
|
78
|
+
case 16: return path(`M${x(.2)} 0H${x(1)}V${y(.8)}L${x(.8)} ${y(1)}H0V${y(.2)}Z M0 ${y(.2)}H${x(.8)}V${y(1)} M${x(.8)} ${y(.2)}L${x(1)} 0`);
|
|
79
|
+
case 17:
|
|
80
|
+
case 61: return polygon([[0, 0], [1, 0], [1, .75], [.5, .75], [.25, 1], [.3, .75], [0, .75]]);
|
|
81
|
+
case 22:
|
|
82
|
+
case 132: return path(`M0 ${y(.12)}C0 ${y(-.04)} ${x(1)} ${y(-.04)} ${x(1)} ${y(.12)}V${y(.88)}C${x(1)} ${y(1.04)} 0 ${y(1.04)} 0 ${y(.88)}Z M0 ${y(.12)}C0 ${y(.28)} ${x(1)} ${y(.28)} ${x(1)} ${y(.12)}`);
|
|
83
|
+
case 23: return { tag: 'path', attrs: `d="M${x(.5)} 0A${x(.5)} ${y(.5)} 0 1 1 ${x(.4999)} 0Z M${x(.5)} ${y(.25)}A${x(.25)} ${y(.25)} 0 1 1 ${x(.4999)} ${y(.25)}Z" fill-rule="evenodd"`, supported: true };
|
|
84
|
+
case 19: return path(`M0 ${y(1)}A${n(w)} ${n(h)} 0 0 1 ${x(1)} 0`, true);
|
|
85
|
+
case 20:
|
|
86
|
+
case 32: return path(`M0 0L${n(w)} ${n(h)}`, true);
|
|
87
|
+
case 33: return path(`M0 0H${n(w)}V${n(h)}`, true);
|
|
88
|
+
case 34: return path(`M0 0H${x(.5)}V${n(h)}H${n(w)}`, true);
|
|
89
|
+
case 35:
|
|
90
|
+
case 36: return path(`M0 0H${x(.333)}V${y(.5)}H${x(.667)}V${n(h)}H${n(w)}`, true);
|
|
91
|
+
case 37:
|
|
92
|
+
case 38:
|
|
93
|
+
case 39:
|
|
94
|
+
case 40: return path(`M0 0C${x(.5)} 0 ${x(.5)} ${n(h)} ${n(w)} ${n(h)}`, true);
|
|
95
|
+
case 55: return polygon([[0, 0], [.75, 0], [1, .5], [.75, 1], [0, 1], [.25, .5]]);
|
|
96
|
+
case 56: return polygon([[.5, 0], [1, .382], [.809, 1], [.191, 1], [0, .382]]);
|
|
97
|
+
case 64:
|
|
98
|
+
case 122: return path(`M0 ${y(.15)}Q${x(.25)} 0 ${x(.5)} ${y(.15)}T${x(1)} ${y(.15)}L${x(1)} ${y(.85)}Q${x(.75)} ${y(1)} ${x(.5)} ${y(.85)}T0 ${y(.85)}Z`);
|
|
99
|
+
case 65: return path(`M0 0H${n(w)}V${y(.8)}L${x(.8)} ${n(h)}H0Z M${n(w)} ${y(.8)}H${x(.8)}V${n(h)}`);
|
|
100
|
+
case 66: return polygon([[1, .25], [.35, .25], [.35, 0], [0, .5], [.35, 1], [.35, .75], [1, .75]]);
|
|
101
|
+
case 68: return polygon([[.25, 1], [.25, .35], [0, .35], [.5, 0], [1, .35], [.75, .35], [.75, 1]]);
|
|
102
|
+
case 67: return polygon([[.25, 0], [.25, .65], [0, .65], [.5, 1], [1, .65], [.75, .65], [.75, 0]]);
|
|
103
|
+
case 69: return polygon([[0, .5], [.25, 0], [.25, .3], [.75, .3], [.75, 0], [1, .5], [.75, 1], [.75, .7], [.25, .7], [.25, 1]]);
|
|
104
|
+
case 70: return polygon([[.5, 0], [1, .25], [.7, .25], [.7, .75], [1, .75], [.5, 1], [0, .75], [.3, .75], [.3, .25], [0, .25]]);
|
|
105
|
+
case 73: return polygon([[.4, 0], [.8, 0], [.6, .4], [1, .4], [.2, 1], [.4, .6], [0, .6]]);
|
|
106
|
+
case 74: return path(`M${x(.5)} ${y(1)}C${x(.4)} ${y(.75)} 0 ${y(.5)} 0 ${y(.25)}C0 ${y(-.05)} ${x(.35)} ${y(-.1)} ${x(.5)} ${y(.2)}C${x(.65)} ${y(-.1)} ${x(1)} ${y(-.05)} ${x(1)} ${y(.25)}C${x(1)} ${y(.5)} ${x(.6)} ${y(.75)} ${x(.5)} ${y(1)}Z`);
|
|
107
|
+
case 85: return path(`M${x(.15)} 0Q0 0 0 ${y(.2)}V${y(.8)}Q0 ${y(1)} ${x(.15)} ${y(1)}`, true);
|
|
108
|
+
case 86: return path(`M${x(.85)} 0Q${x(1)} 0 ${x(1)} ${y(.2)}V${y(.8)}Q${x(1)} ${y(1)} ${x(.85)} ${y(1)}`, true);
|
|
109
|
+
case 87: return path(`M${x(.8)} 0Q${x(.5)} 0 ${x(.5)} ${y(.2)}V${y(.35)}Q${x(.5)} ${y(.5)} 0 ${y(.5)}Q${x(.5)} ${y(.5)} ${x(.5)} ${y(.65)}V${y(.8)}Q${x(.5)} ${y(1)} ${x(.8)} ${y(1)}`, true);
|
|
110
|
+
case 88: return path(`M${x(.2)} 0Q${x(.5)} 0 ${x(.5)} ${y(.2)}V${y(.35)}Q${x(.5)} ${y(.5)} ${x(1)} ${y(.5)}Q${x(.5)} ${y(.5)} ${x(.5)} ${y(.65)}V${y(.8)}Q${x(.5)} ${y(1)} ${x(.2)} ${y(1)}`, true);
|
|
111
|
+
case 110: return polygon([[.5, 0], [1, .5], [.5, 1], [0, .5]]);
|
|
112
|
+
case 111: return polygon([[.2, 0], [1, 0], [.8, 1], [0, 1]]);
|
|
113
|
+
case 112: return path(`M0 0H${n(w)}V${n(h)}H0Z M${x(.15)} 0V${n(h)} M${x(.85)} 0V${n(h)}`);
|
|
114
|
+
case 113: return path(`M0 0H${n(w)}V${n(h)}H0Z M${x(.15)} 0V${n(h)} M0 ${y(.15)}H${n(w)}`);
|
|
115
|
+
case 114: return path(`M0 0H${n(w)}V${y(.85)}Q${x(.75)} ${y(.65)} ${x(.5)} ${y(.85)}T0 ${y(.85)}Z`);
|
|
116
|
+
case 116:
|
|
117
|
+
case 176: return { tag: 'rect', attrs: `width="${n(w)}" height="${n(h)}" rx="${n(Math.min(w, h) * .5)}"`, supported: true };
|
|
118
|
+
case 117: return polygon([[.2, 0], [.8, 0], [1, .5], [.8, 1], [.2, 1], [0, .5]]);
|
|
119
|
+
case 118: return polygon([[0, .2], [1, 0], [1, 1], [0, 1]]);
|
|
120
|
+
case 119: return polygon([[0, 0], [1, 0], [.8, 1], [.2, 1]]);
|
|
121
|
+
case 120: return { tag: 'ellipse', attrs: `cx="${x(.5)}" cy="${y(.5)}" rx="${x(.5)}" ry="${y(.5)}"`, supported: true };
|
|
122
|
+
case 121: return polygon([[.25, 0], [1, 0], [1, 1], [0, 1], [0, .25]]);
|
|
123
|
+
case 125: return polygon([[0, 0], [1, 0], [0, 1], [1, 1]]);
|
|
124
|
+
case 126: return path(`M${x(.5)} 0L${x(1)} ${y(.5)}L${x(.5)} ${y(1)}L0 ${y(.5)}Z M0 ${y(.5)}H${n(w)}`);
|
|
125
|
+
case 127: return polygon([[.5, 0], [1, 1], [0, 1]]);
|
|
126
|
+
case 128: return polygon([[0, 0], [1, 0], [.5, 1]]);
|
|
127
|
+
case 135: return path(`M0 0H${x(.5)}A${x(.5)} ${y(.5)} 0 0 1 ${x(.5)} ${y(1)}H0Z`);
|
|
128
|
+
case 177: return polygon([[0, 0], [1, 0], [1, .6], [.5, 1], [0, .6]]);
|
|
129
|
+
default: return { tag: 'rect', attrs: `width="${n(w)}" height="${n(h)}"`, supported: false };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Output escapes stay independent of a DOM, so rendering also works in Node/Workers. */
|
|
2
|
+
export declare function escapeXml(value: unknown): string;
|
|
3
|
+
export declare function finite(value: unknown, fallback?: number): number;
|
|
4
|
+
export declare function n(value: unknown): string;
|
|
5
|
+
/** Transform coefficients must preserve small scales used by large group coordinate spaces. */
|
|
6
|
+
export declare function transformNumber(value: number): string;
|
|
7
|
+
export declare function color(value: unknown, fallback?: string): string;
|
|
8
|
+
export declare function cssFont(value: unknown): string;
|
|
9
|
+
export declare function imageUrl(value: unknown): string | undefined;
|
|
10
|
+
export declare function linkUrl(value: unknown): string | undefined;
|
|
11
|
+
/** RFC 4648 section 4: standard alphabet, zero pad bits and required '=' padding. */
|
|
12
|
+
export declare function base64(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Output escapes stay independent of a DOM, so rendering also works in Node/Workers. */
|
|
2
|
+
export function escapeXml(value) { return String(value ?? '').replace(/\u000b/g, '\n').replace(/[\u0000-\u0008\u000c\u000e-\u001f\ufffe\uffff]/g, '\ufffd').replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g, '\ufffd').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); }
|
|
3
|
+
export function finite(value, fallback = 0) { return typeof value === 'number' && Number.isFinite(value) ? value : fallback; }
|
|
4
|
+
export function n(value) { return String(Math.round(finite(value) * 10000) / 10000); }
|
|
5
|
+
/** Transform coefficients must preserve small scales used by large group coordinate spaces. */
|
|
6
|
+
export function transformNumber(value) { return String(finite(value)); }
|
|
7
|
+
export function color(value, fallback = '#000000') { const s = String(value ?? ''); return /^(#[\da-f]{3,8}|transparent|none)$/i.test(s) ? s : fallback; }
|
|
8
|
+
export function cssFont(value) { return `'${String(value ?? 'Arial').replace(/[\u0000-\u001f\u007f]/g, '').replace(/\\/g, '\\\\').replace(/'/g, "\\'")}', sans-serif`; }
|
|
9
|
+
export function imageUrl(value) { if (typeof value !== 'string')
|
|
10
|
+
return undefined; return /^(blob:|data:image\/(?:png|jpeg|gif|bmp|webp|tiff|svg\+xml);(?:base64,|charset=utf-8,))/i.test(value) ? value : undefined; }
|
|
11
|
+
export function linkUrl(value) { if (typeof value !== 'string' || /[\u0000-\u0020\u007f]/.test(value))
|
|
12
|
+
return undefined; return /^(?:https?:\/\/|mailto:|tel:|#)/i.test(value) ? value : undefined; }
|
|
13
|
+
const base64Alphabet = Uint8Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', char => char.charCodeAt(0));
|
|
14
|
+
const base64Decoder = new TextDecoder();
|
|
15
|
+
/** RFC 4648 section 4: standard alphabet, zero pad bits and required '=' padding. */
|
|
16
|
+
export function base64(bytes) {
|
|
17
|
+
if (bytes.length === 0)
|
|
18
|
+
return '';
|
|
19
|
+
// Each complete block consumes a multiple of three bytes, so only the final
|
|
20
|
+
// block needs padding. Decode ASCII output directly, without a binary string
|
|
21
|
+
// for the entire asset or a spread call whose arguments scale with its size.
|
|
22
|
+
const inputBlockSize = 49152;
|
|
23
|
+
const output = new Uint8Array(Math.min(65536, Math.ceil(bytes.length / 3) * 4));
|
|
24
|
+
const parts = [];
|
|
25
|
+
for (let start = 0; start < bytes.length; start += inputBlockSize) {
|
|
26
|
+
const end = Math.min(start + inputBlockSize, bytes.length);
|
|
27
|
+
const completeEnd = end - (end - start) % 3;
|
|
28
|
+
let input = start, written = 0;
|
|
29
|
+
while (input < completeEnd) {
|
|
30
|
+
const bits = (bytes[input++] << 16) | (bytes[input++] << 8) | bytes[input++];
|
|
31
|
+
output[written++] = base64Alphabet[bits >>> 18];
|
|
32
|
+
output[written++] = base64Alphabet[(bits >>> 12) & 63];
|
|
33
|
+
output[written++] = base64Alphabet[(bits >>> 6) & 63];
|
|
34
|
+
output[written++] = base64Alphabet[bits & 63];
|
|
35
|
+
}
|
|
36
|
+
if (input < end) {
|
|
37
|
+
const first = bytes[input++];
|
|
38
|
+
const hasSecond = input < end;
|
|
39
|
+
const second = hasSecond ? bytes[input] : 0;
|
|
40
|
+
output[written++] = base64Alphabet[first >>> 2];
|
|
41
|
+
output[written++] = base64Alphabet[((first & 3) << 4) | (second >>> 4)];
|
|
42
|
+
output[written++] = hasSecond ? base64Alphabet[(second & 15) << 2] : 61;
|
|
43
|
+
output[written++] = 61;
|
|
44
|
+
}
|
|
45
|
+
parts.push(base64Decoder.decode(output.subarray(0, written)));
|
|
46
|
+
}
|
|
47
|
+
return parts.join('');
|
|
48
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PptDocument, RenderOptions, RenderResult } from '../types.js';
|
|
2
|
+
export declare const defaultPptCss = ".pptjs-slide{display:block;max-width:100%;max-height:100%;user-select:text}.pptjs-slide *{box-sizing:border-box}.pptjs-slide a:focus{outline:2px solid #2563eb;outline-offset:2px}";
|
|
3
|
+
export declare function renderSlide(doc: PptDocument, index: number, options?: RenderOptions): RenderResult;
|
|
4
|
+
export declare function renderSlideSvg(doc: PptDocument, index: number, options?: RenderOptions): string;
|