@bendyline/squisq-formats 2.6.16 → 2.6.17
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-34KECNZO.js +15 -0
- package/dist/{chunk-SAMQZRJU.js → chunk-53CTG4YR.js} +5 -85
- package/dist/{chunk-EMAPNC32.js → chunk-76BFHBZD.js} +50 -3
- package/dist/chunk-C23JYVPG.js +89 -0
- package/dist/{chunk-TLDBJH7D.js → chunk-JY3T4KOP.js} +247 -20
- package/dist/{chunk-ZDRSDYXN.js → chunk-VJQZMIXU.js} +3 -14
- package/dist/{chunk-EQAHFGGX.js → chunk-YFSFEPBB.js} +160 -15
- package/dist/docx/index.js +1 -1
- package/dist/html/index.d.ts +14 -2
- package/dist/html/index.js +1 -1
- package/dist/{import-D8y5SV0T.d.ts → import-ipP4Ghp8.d.ts} +7 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +13 -10
- package/dist/outside-in/index.d.ts +7 -39
- package/dist/outside-in/index.js +8 -6
- package/dist/outside-in/layout.d.ts +58 -0
- package/dist/outside-in/layout.js +12 -0
- package/dist/pdf/index.js +2 -1
- package/dist/pptx/index.js +1 -1
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +1 -1
- package/dist/{types-Cubj9A8c.d.ts → types-CVv9eldp.d.ts} +1 -1
- package/dist/videoPoster-D7DTZC2L.js +104 -0
- package/package.json +7 -2
- /package/dist/{chunk-VE2ADQ5T.js → chunk-SZDCCL6O.js} +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
upngEncoder
|
|
3
|
+
} from "./chunk-34KECNZO.js";
|
|
4
|
+
|
|
5
|
+
// src/shared/videoPoster.ts
|
|
6
|
+
import { videoEmbedIframeAttributes } from "@bendyline/squisq/markdown";
|
|
7
|
+
var LONG_EDGE = 640;
|
|
8
|
+
var SHORT_EDGE = 360;
|
|
9
|
+
var posterCache = /* @__PURE__ */ new Map();
|
|
10
|
+
function mix(a, b, t) {
|
|
11
|
+
return [0, 1, 2].map((i) => Math.round(a[i] + (b[i] - a[i]) * t));
|
|
12
|
+
}
|
|
13
|
+
function videoPosterPng(portrait) {
|
|
14
|
+
const key = portrait ? "portrait" : "landscape";
|
|
15
|
+
if (posterCache.has(key)) return posterCache.get(key) ?? null;
|
|
16
|
+
if (!upngEncoder) {
|
|
17
|
+
posterCache.set(key, null);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const width = portrait ? SHORT_EDGE : LONG_EDGE;
|
|
21
|
+
const height = portrait ? LONG_EDGE : SHORT_EDGE;
|
|
22
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
23
|
+
const top = [40, 44, 54];
|
|
24
|
+
const bottom = [14, 15, 20];
|
|
25
|
+
for (let y = 0; y < height; y++) {
|
|
26
|
+
const [r, g, b] = mix(top, bottom, y / (height - 1));
|
|
27
|
+
for (let x = 0; x < width; x++) {
|
|
28
|
+
const at = (y * width + x) * 4;
|
|
29
|
+
rgba[at] = r;
|
|
30
|
+
rgba[at + 1] = g;
|
|
31
|
+
rgba[at + 2] = b;
|
|
32
|
+
rgba[at + 3] = 255;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const buttonW = Math.round(Math.min(width, height) * 0.3);
|
|
36
|
+
const buttonH = Math.round(buttonW * 0.7);
|
|
37
|
+
const radius = buttonH * 0.24;
|
|
38
|
+
const left = (width - buttonW) / 2;
|
|
39
|
+
const topY = (height - buttonH) / 2;
|
|
40
|
+
const triH = buttonH * 0.42;
|
|
41
|
+
const triW = triH * 0.9;
|
|
42
|
+
const triLeft = width / 2 - triW * 0.4;
|
|
43
|
+
const triTop = height / 2 - triH / 2;
|
|
44
|
+
const inButton = (px, py) => {
|
|
45
|
+
const dx = Math.max(left + radius - px, 0, px - (left + buttonW - radius));
|
|
46
|
+
const dy = Math.max(topY + radius - py, 0, py - (topY + buttonH - radius));
|
|
47
|
+
return dx * dx + dy * dy <= radius * radius;
|
|
48
|
+
};
|
|
49
|
+
const inTriangle = (px, py) => {
|
|
50
|
+
if (px < triLeft) return false;
|
|
51
|
+
const halfAt = triH / 2 * (1 - (px - triLeft) / triW);
|
|
52
|
+
return Math.abs(py - height / 2) <= halfAt && py >= triTop && py <= triTop + triH;
|
|
53
|
+
};
|
|
54
|
+
const SAMPLES = 4;
|
|
55
|
+
for (let y = Math.floor(topY); y < Math.ceil(topY + buttonH); y++) {
|
|
56
|
+
for (let x = Math.floor(left); x < Math.ceil(left + buttonW); x++) {
|
|
57
|
+
let button = 0;
|
|
58
|
+
let triangle = 0;
|
|
59
|
+
for (let sy = 0; sy < SAMPLES; sy++) {
|
|
60
|
+
for (let sx = 0; sx < SAMPLES; sx++) {
|
|
61
|
+
const px = x + (sx + 0.5) / SAMPLES;
|
|
62
|
+
const py = y + (sy + 0.5) / SAMPLES;
|
|
63
|
+
if (inButton(px, py)) button++;
|
|
64
|
+
if (inTriangle(px, py)) triangle++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!button && !triangle) continue;
|
|
68
|
+
const at = (y * width + x) * 4;
|
|
69
|
+
const base = [rgba[at], rgba[at + 1], rgba[at + 2]];
|
|
70
|
+
const washed = mix(base, [255, 255, 255], 0.18 * (button / SAMPLES ** 2));
|
|
71
|
+
const [r, g, b] = mix(washed, [255, 255, 255], triangle / SAMPLES ** 2);
|
|
72
|
+
rgba[at] = r;
|
|
73
|
+
rgba[at + 1] = g;
|
|
74
|
+
rgba[at + 2] = b;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const data = upngEncoder.encode([rgba.buffer], width, height, 0);
|
|
78
|
+
const poster = { data, contentType: "image/png", width, height };
|
|
79
|
+
posterCache.set(key, poster);
|
|
80
|
+
return poster;
|
|
81
|
+
}
|
|
82
|
+
function officeVideoEmbedUrl(embed) {
|
|
83
|
+
return embed.provider === "youtube" ? embed.embedUrl.replace(/^https:\/\/www\.youtube-nocookie\.com\//, "https://www.youtube.com/") : embed.embedUrl;
|
|
84
|
+
}
|
|
85
|
+
function escapeHtmlAttr(value) {
|
|
86
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
87
|
+
}
|
|
88
|
+
function officeVideoEmbedHtml(embed, title, width, height) {
|
|
89
|
+
const { loading: _lazy, ...attrs } = videoEmbedIframeAttributes(embed, title);
|
|
90
|
+
const all = {
|
|
91
|
+
width: String(width),
|
|
92
|
+
height: String(height),
|
|
93
|
+
...attrs,
|
|
94
|
+
src: officeVideoEmbedUrl(embed),
|
|
95
|
+
frameborder: "0"
|
|
96
|
+
};
|
|
97
|
+
const serialized = Object.entries(all).map(([name, value]) => value === "" ? name : `${name}="${escapeHtmlAttr(value)}"`).join(" ");
|
|
98
|
+
return `<iframe ${serialized}></iframe>`;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
officeVideoEmbedHtml,
|
|
102
|
+
officeVideoEmbedUrl,
|
|
103
|
+
videoPosterPng
|
|
104
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/squisq-formats",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.17",
|
|
4
4
|
"description": "Document format converters — DOCX, PDF, OOXML import/export",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bendyline",
|
|
@@ -108,6 +108,11 @@
|
|
|
108
108
|
"import": "./dist/outside-in/index.js",
|
|
109
109
|
"default": "./dist/outside-in/index.js"
|
|
110
110
|
},
|
|
111
|
+
"./outside-in-layout": {
|
|
112
|
+
"types": "./dist/outside-in/layout.d.ts",
|
|
113
|
+
"import": "./dist/outside-in/layout.js",
|
|
114
|
+
"default": "./dist/outside-in/layout.js"
|
|
115
|
+
},
|
|
111
116
|
"./diagrams": {
|
|
112
117
|
"types": "./dist/diagrams/index.d.ts",
|
|
113
118
|
"import": "./dist/diagrams/index.js",
|
|
@@ -120,7 +125,7 @@
|
|
|
120
125
|
"typecheck": "tsc --noEmit"
|
|
121
126
|
},
|
|
122
127
|
"dependencies": {
|
|
123
|
-
"@bendyline/squisq": "2.11.
|
|
128
|
+
"@bendyline/squisq": "2.11.17",
|
|
124
129
|
"@pdf-lib/fontkit": "1.1.1",
|
|
125
130
|
"@pdf-lib/upng": "1.0.1",
|
|
126
131
|
"@xmldom/xmldom": "0.9.12",
|
|
File without changes
|