@bloklabs/cli 1.15.1 → 1.16.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/block-builder-Cg5bL2dS.mjs +1460 -0
- package/dist/cli.mjs +15 -14
- package/dist/convert-gdocs-ZqRLNT9X.mjs +13 -0
- package/dist/convert-html-RCkTt7d_.mjs +13 -0
- package/package.json +1 -1
- package/dist/block-builder-DaGEOJ2S.mjs +0 -831
- package/dist/block-builder-Dc6PL7RK.mjs +0 -825
- package/dist/convert-gdocs--8aPMm3f.mjs +0 -205
- package/dist/convert-gdocs-CB-kubaI.mjs +0 -208
- package/dist/convert-gdocs-CizVIpiR.mjs +0 -205
- package/dist/convert-html-BcYeUJKw.mjs +0 -13
- package/dist/convert-html-DEW3D-Ub.mjs +0 -13
- package/dist/convert-html-Oocfb7JD.mjs +0 -13
|
@@ -0,0 +1,1460 @@
|
|
|
1
|
+
//#region src/components/shared/color-presets.ts
|
|
2
|
+
var e = [
|
|
3
|
+
{
|
|
4
|
+
name: "gray",
|
|
5
|
+
text: "#787774",
|
|
6
|
+
bg: "#f1f1ef"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: "brown",
|
|
10
|
+
text: "#9f6b53",
|
|
11
|
+
bg: "#f4eeee"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "orange",
|
|
15
|
+
text: "#d9730d",
|
|
16
|
+
bg: "#fbecdd"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "yellow",
|
|
20
|
+
text: "#cb9b00",
|
|
21
|
+
bg: "#fbf3db"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "green",
|
|
25
|
+
text: "#448361",
|
|
26
|
+
bg: "#edf3ec"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "blue",
|
|
30
|
+
text: "#337ea9",
|
|
31
|
+
bg: "#e7f3f8"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "purple",
|
|
35
|
+
text: "#9065b0",
|
|
36
|
+
bg: "#f6f3f9"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "pink",
|
|
40
|
+
text: "#c14c8a",
|
|
41
|
+
bg: "#f9f0f5"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "red",
|
|
45
|
+
text: "#d44c47",
|
|
46
|
+
bg: "#fdebec"
|
|
47
|
+
}
|
|
48
|
+
], t = [
|
|
49
|
+
{
|
|
50
|
+
name: "gray",
|
|
51
|
+
text: "#9b9b9b",
|
|
52
|
+
bg: "#2f2f2f"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "brown",
|
|
56
|
+
text: "#c59177",
|
|
57
|
+
bg: "#452a1c"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "orange",
|
|
61
|
+
text: "#dc8c47",
|
|
62
|
+
bg: "#4d2f14"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "yellow",
|
|
66
|
+
text: "#d4ab49",
|
|
67
|
+
bg: "#544012"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "green",
|
|
71
|
+
text: "#5db184",
|
|
72
|
+
bg: "#1e432f"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "blue",
|
|
76
|
+
text: "#5c9fcc",
|
|
77
|
+
bg: "#123a54"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "purple",
|
|
81
|
+
text: "#a67dca",
|
|
82
|
+
bg: "#341d49"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "pink",
|
|
86
|
+
text: "#d45e99",
|
|
87
|
+
bg: "#4b1b33"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "red",
|
|
91
|
+
text: "#dd5e5a",
|
|
92
|
+
bg: "#4e1a18"
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/components/utils/default-page-colors.ts
|
|
97
|
+
function n(e) {
|
|
98
|
+
let t = e.replace(/\s/g, "").toLowerCase();
|
|
99
|
+
return t === "rgb(255,255,255)" || t === "#ffffff" || t === "#fff" || t === "white";
|
|
100
|
+
}
|
|
101
|
+
function r(e) {
|
|
102
|
+
let t = e.replace(/\s/g, "").toLowerCase(), n = /^rgba?\((\d+),(\d+),(\d+)(?:,[\d.]+)?\)$/.exec(t);
|
|
103
|
+
if (n) {
|
|
104
|
+
let e = parseInt(n[1], 10) / 255, t = parseInt(n[2], 10) / 255, r = parseInt(n[3], 10) / 255;
|
|
105
|
+
return .2126 * e + .7152 * t + .0722 * r;
|
|
106
|
+
}
|
|
107
|
+
let r = /^hsla?\(([\d.]+),([\d.]+)%,([\d.]+)%(?:,[\d.]+)?\)$/.exec(t);
|
|
108
|
+
if (r) {
|
|
109
|
+
let e = parseFloat(r[1]) / 360, t = parseFloat(r[2]) / 100, n = parseFloat(r[3]) / 100;
|
|
110
|
+
if (t === 0) return .2126 * n + .7152 * n + .0722 * n;
|
|
111
|
+
let i = n < .5 ? n * (1 + t) : n + t - n * t, a = 2 * n - i, o = (e) => e < 0 ? e + 1 : e > 1 ? e - 1 : e, s = (e) => {
|
|
112
|
+
let t = o(e);
|
|
113
|
+
return t < 1 / 6 ? a + (i - a) * 6 * t : t < 1 / 2 ? i : t < 2 / 3 ? a + (i - a) * (2 / 3 - t) * 6 : a;
|
|
114
|
+
}, c = s(e + 1 / 3), l = s(e), u = s(e - 1 / 3);
|
|
115
|
+
return .2126 * c + .7152 * l + .0722 * u;
|
|
116
|
+
}
|
|
117
|
+
let i = /^#([0-9a-f]{6}|[0-9a-f]{3})$/.exec(t);
|
|
118
|
+
if (i) {
|
|
119
|
+
let e = i[1], t = e.length === 3 ? [
|
|
120
|
+
e[0] + e[0],
|
|
121
|
+
e[1] + e[1],
|
|
122
|
+
e[2] + e[2]
|
|
123
|
+
] : [
|
|
124
|
+
e.substring(0, 2),
|
|
125
|
+
e.substring(2, 4),
|
|
126
|
+
e.substring(4, 6)
|
|
127
|
+
], n = parseInt(t[0], 16) / 255, r = parseInt(t[1], 16) / 255, a = parseInt(t[2], 16) / 255;
|
|
128
|
+
return .2126 * n + .7152 * r + .0722 * a;
|
|
129
|
+
}
|
|
130
|
+
return -1;
|
|
131
|
+
}
|
|
132
|
+
function i(e) {
|
|
133
|
+
let t = r(e);
|
|
134
|
+
return t >= 0 && t < .12;
|
|
135
|
+
}
|
|
136
|
+
var a = 250;
|
|
137
|
+
function o(e) {
|
|
138
|
+
let t = e.replace(/\s/g, "").toLowerCase();
|
|
139
|
+
if (t === "transparent") return {
|
|
140
|
+
r: 0,
|
|
141
|
+
g: 0,
|
|
142
|
+
b: 0,
|
|
143
|
+
a: 0
|
|
144
|
+
};
|
|
145
|
+
if (t === "white") return {
|
|
146
|
+
r: 255,
|
|
147
|
+
g: 255,
|
|
148
|
+
b: 255,
|
|
149
|
+
a: 1
|
|
150
|
+
};
|
|
151
|
+
let n = /^rgba?\((\d+),(\d+),(\d+)(?:,([\d.]+))?\)$/.exec(t);
|
|
152
|
+
if (n) return {
|
|
153
|
+
r: parseInt(n[1], 10),
|
|
154
|
+
g: parseInt(n[2], 10),
|
|
155
|
+
b: parseInt(n[3], 10),
|
|
156
|
+
a: n[4] === void 0 ? 1 : parseFloat(n[4])
|
|
157
|
+
};
|
|
158
|
+
let r = /^#([0-9a-f]{6}|[0-9a-f]{3})$/.exec(t);
|
|
159
|
+
if (r) {
|
|
160
|
+
let e = r[1], t = e.length === 3 ? [
|
|
161
|
+
e[0] + e[0],
|
|
162
|
+
e[1] + e[1],
|
|
163
|
+
e[2] + e[2]
|
|
164
|
+
] : [
|
|
165
|
+
e.substring(0, 2),
|
|
166
|
+
e.substring(2, 4),
|
|
167
|
+
e.substring(4, 6)
|
|
168
|
+
];
|
|
169
|
+
return {
|
|
170
|
+
r: parseInt(t[0], 16),
|
|
171
|
+
g: parseInt(t[1], 16),
|
|
172
|
+
b: parseInt(t[2], 16),
|
|
173
|
+
a: 1
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function s(e) {
|
|
179
|
+
let t = o(e);
|
|
180
|
+
return t !== null && (t.a === 0 || t.r >= a && t.g >= a && t.b >= a) || i(e);
|
|
181
|
+
}
|
|
182
|
+
var c = 40;
|
|
183
|
+
function l(e) {
|
|
184
|
+
let t = o(e);
|
|
185
|
+
return t !== null && t.r <= c && t.g <= c && t.b <= c;
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/components/utils/color-mapping.ts
|
|
189
|
+
function u(e, t, n) {
|
|
190
|
+
let r = t / 100, i = n / 100;
|
|
191
|
+
if (r === 0) {
|
|
192
|
+
let e = Math.round(i * 255);
|
|
193
|
+
return [
|
|
194
|
+
e,
|
|
195
|
+
e,
|
|
196
|
+
e
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
let a = (e) => e < 0 ? e + 1 : e > 1 ? e - 1 : e, o = (e, t, n) => {
|
|
200
|
+
let r = a(n);
|
|
201
|
+
return r < 1 / 6 ? e + (t - e) * 6 * r : r < 1 / 2 ? t : r < 2 / 3 ? e + (t - e) * (2 / 3 - r) * 6 : e;
|
|
202
|
+
}, s = i < .5 ? i * (1 + r) : i + r - i * r, c = 2 * i - s, l = e / 360;
|
|
203
|
+
return [
|
|
204
|
+
Math.round(o(c, s, l + 1 / 3) * 255),
|
|
205
|
+
Math.round(o(c, s, l) * 255),
|
|
206
|
+
Math.round(o(c, s, l - 1 / 3) * 255)
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
function d(e) {
|
|
210
|
+
let t = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);
|
|
211
|
+
if (t) return [
|
|
212
|
+
parseInt(t[1], 16),
|
|
213
|
+
parseInt(t[2], 16),
|
|
214
|
+
parseInt(t[3], 16)
|
|
215
|
+
];
|
|
216
|
+
let n = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})[0-9a-f]{2}$/i.exec(e);
|
|
217
|
+
if (n) return [
|
|
218
|
+
parseInt(n[1], 16),
|
|
219
|
+
parseInt(n[2], 16),
|
|
220
|
+
parseInt(n[3], 16)
|
|
221
|
+
];
|
|
222
|
+
let r = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e);
|
|
223
|
+
if (r) return [
|
|
224
|
+
parseInt(r[1] + r[1], 16),
|
|
225
|
+
parseInt(r[2] + r[2], 16),
|
|
226
|
+
parseInt(r[3] + r[3], 16)
|
|
227
|
+
];
|
|
228
|
+
let i = /^#([0-9a-f])([0-9a-f])([0-9a-f])[0-9a-f]$/i.exec(e);
|
|
229
|
+
if (i) return [
|
|
230
|
+
parseInt(i[1] + i[1], 16),
|
|
231
|
+
parseInt(i[2] + i[2], 16),
|
|
232
|
+
parseInt(i[3] + i[3], 16)
|
|
233
|
+
];
|
|
234
|
+
let a = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
|
|
235
|
+
if (a) return [
|
|
236
|
+
Number(a[1]),
|
|
237
|
+
Number(a[2]),
|
|
238
|
+
Number(a[3])
|
|
239
|
+
];
|
|
240
|
+
let o = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
|
|
241
|
+
return o ? u(Number(o[1]), Number(o[2]), Number(o[3])) : null;
|
|
242
|
+
}
|
|
243
|
+
var f = .1;
|
|
244
|
+
function p(e) {
|
|
245
|
+
let t = e[0] / 255, n = e[1] / 255, r = e[2] / 255, i = Math.max(t, n, r), a = Math.min(t, n, r), o = (i + a) / 2;
|
|
246
|
+
if (i === a) return [
|
|
247
|
+
0,
|
|
248
|
+
0,
|
|
249
|
+
o
|
|
250
|
+
];
|
|
251
|
+
let s = i - a, c = o > .5 ? s / (2 - i - a) : s / (i + a);
|
|
252
|
+
return [
|
|
253
|
+
((e) => e === t ? ((n - r) / s + (n < r ? 6 : 0)) / 6 : e === n ? ((r - t) / s + 2) / 6 : ((t - n) / s + 4) / 6)(i) * 360,
|
|
254
|
+
c,
|
|
255
|
+
o
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
function m(e, t) {
|
|
259
|
+
let n = e[1] < f, r = t[1] < f;
|
|
260
|
+
if (n && r) {
|
|
261
|
+
let n = Math.abs(e[2] - t[2]);
|
|
262
|
+
return n * n;
|
|
263
|
+
}
|
|
264
|
+
if (n !== r) return 1e3;
|
|
265
|
+
let i = Math.abs(e[0] - t[0]), a = Math.min(i, 360 - i) / 180, o = Math.abs(e[1] - t[1]), s = Math.abs(e[2] - t[2]);
|
|
266
|
+
return 8 * a * a + 1 * o * o + 1 * s * s;
|
|
267
|
+
}
|
|
268
|
+
function h(t, r) {
|
|
269
|
+
if (r === "bg" && (n(t) || i(t))) return t;
|
|
270
|
+
let a = d(t);
|
|
271
|
+
if (a === null) return t;
|
|
272
|
+
let o = p(a);
|
|
273
|
+
return e.reduce((e, t) => {
|
|
274
|
+
let n = d(t[r]);
|
|
275
|
+
if (n === null) return e;
|
|
276
|
+
let i = m(o, p(n));
|
|
277
|
+
return i < e.distance ? {
|
|
278
|
+
color: t[r],
|
|
279
|
+
distance: i
|
|
280
|
+
} : e;
|
|
281
|
+
}, {
|
|
282
|
+
color: t,
|
|
283
|
+
distance: Infinity
|
|
284
|
+
}).color;
|
|
285
|
+
}
|
|
286
|
+
function g(r, a) {
|
|
287
|
+
if (a === "bg" && (n(r) || i(r))) return null;
|
|
288
|
+
let o = d(r);
|
|
289
|
+
if (o === null) return null;
|
|
290
|
+
let s = p(o);
|
|
291
|
+
return [...e, ...t].reduce((e, t) => {
|
|
292
|
+
let n = d(t[a]);
|
|
293
|
+
if (n === null) return e;
|
|
294
|
+
let r = m(s, p(n));
|
|
295
|
+
return e === null || r < e.distance ? {
|
|
296
|
+
name: t.name,
|
|
297
|
+
distance: r
|
|
298
|
+
} : e;
|
|
299
|
+
}, null)?.name ?? null;
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/shared/page-reference.ts
|
|
303
|
+
var _ = "data-blok-page-id", ee = "Page", te = (e) => {
|
|
304
|
+
let t = e.getAttribute(_);
|
|
305
|
+
return t !== null && t !== "" ? (e.textContent = ee, { [_]: !0 }) : {
|
|
306
|
+
href: !0,
|
|
307
|
+
target: !0,
|
|
308
|
+
rel: !0
|
|
309
|
+
};
|
|
310
|
+
}, v = /* @__PURE__ */ new Set([
|
|
311
|
+
"A",
|
|
312
|
+
"B",
|
|
313
|
+
"STRONG",
|
|
314
|
+
"I",
|
|
315
|
+
"EM",
|
|
316
|
+
"U",
|
|
317
|
+
"S",
|
|
318
|
+
"DEL",
|
|
319
|
+
"INS",
|
|
320
|
+
"MARK",
|
|
321
|
+
"CODE",
|
|
322
|
+
"SUB",
|
|
323
|
+
"SUP",
|
|
324
|
+
"SMALL",
|
|
325
|
+
"SPAN",
|
|
326
|
+
"FONT"
|
|
327
|
+
]), ne = new Set([...v].filter((e) => e !== "A")), re = /* @__PURE__ */ new Set([
|
|
328
|
+
"IMG",
|
|
329
|
+
"IFRAME",
|
|
330
|
+
"VIDEO",
|
|
331
|
+
"AUDIO",
|
|
332
|
+
"INPUT",
|
|
333
|
+
"SVG",
|
|
334
|
+
"CANVAS",
|
|
335
|
+
"OBJECT",
|
|
336
|
+
"EMBED"
|
|
337
|
+
]), ie = /* @__PURE__ */ new Set([
|
|
338
|
+
"U",
|
|
339
|
+
"S",
|
|
340
|
+
"DEL",
|
|
341
|
+
"INS"
|
|
342
|
+
]), ae = /* @__PURE__ */ new Set([
|
|
343
|
+
"background-color",
|
|
344
|
+
"background",
|
|
345
|
+
"text-decoration",
|
|
346
|
+
"text-decoration-line",
|
|
347
|
+
"border",
|
|
348
|
+
"border-bottom",
|
|
349
|
+
"box-shadow",
|
|
350
|
+
"outline"
|
|
351
|
+
]), oe = /* @__PURE__ */ new Set([
|
|
352
|
+
"",
|
|
353
|
+
"none",
|
|
354
|
+
"transparent",
|
|
355
|
+
"initial",
|
|
356
|
+
"unset"
|
|
357
|
+
]), y = (e) => {
|
|
358
|
+
let t = e.attributes.filter((e) => e.name.toLowerCase() !== "style").map((e) => `${e.name.toLowerCase()}=${e.value}`).sort(), n = e.styleDeclarations.map((e) => `${e.property.toLowerCase()}:${e.value.trim()}`).sort();
|
|
359
|
+
return `${e.tagName}|${t.join("|")}|${n.join(";")}`;
|
|
360
|
+
}, b = (e) => e.attributes.some((t) => {
|
|
361
|
+
let n = t.name.toLowerCase();
|
|
362
|
+
return n === "id" || e.tagName === "A" && n === "data-blok-page-id";
|
|
363
|
+
}), se = (e) => ie.has(e.tagName) ? !0 : e.styleDeclarations.some((e) => ae.has(e.property.toLowerCase()) && !oe.has(e.value.trim().toLowerCase())), ce = (e) => {
|
|
364
|
+
if (!ne.has(e.tagName)) return !1;
|
|
365
|
+
let t = e.text();
|
|
366
|
+
return t.trim().length > 0 || e.hasVoidContentDescendant() ? !1 : t.length === 0 || !se(e);
|
|
367
|
+
}, le = (e, t) => !v.has(e.tagName) || b(e) || b(t) ? !1 : y(e) === y(t), ue = (e, t) => {
|
|
368
|
+
if (!v.has(e.tagName) || b(e)) return !1;
|
|
369
|
+
let n = y(e);
|
|
370
|
+
return t.some((e) => y(e) === n);
|
|
371
|
+
}, x = { current: void 0 };
|
|
372
|
+
function de(e) {
|
|
373
|
+
x.current ??= document.implementation.createHTMLDocument("");
|
|
374
|
+
let t = x.current.createElement("div");
|
|
375
|
+
return t.innerHTML = e, t;
|
|
376
|
+
}
|
|
377
|
+
function fe(e) {
|
|
378
|
+
return new DOMParser().parseFromString(e, "text/html");
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/components/utils/inline-normalization.ts
|
|
382
|
+
var S = (e) => {
|
|
383
|
+
let t = e.style, n = Array.from({ length: t.length }, (e, n) => {
|
|
384
|
+
let r = t.item(n);
|
|
385
|
+
return {
|
|
386
|
+
property: r,
|
|
387
|
+
value: t.getPropertyValue(r)
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
return {
|
|
391
|
+
tagName: e.tagName.toUpperCase(),
|
|
392
|
+
attributes: Array.from(e.attributes).map((e) => ({
|
|
393
|
+
name: e.name,
|
|
394
|
+
value: e.value
|
|
395
|
+
})),
|
|
396
|
+
styleDeclarations: n,
|
|
397
|
+
text: () => e.textContent ?? "",
|
|
398
|
+
hasVoidContentDescendant: () => Array.from(e.querySelectorAll("*")).some((e) => re.has(e.tagName.toUpperCase()))
|
|
399
|
+
};
|
|
400
|
+
}, C = (e, t) => {
|
|
401
|
+
let n = e.parentElement;
|
|
402
|
+
return n === null || n === t ? [] : [S(n), ...C(n, t)];
|
|
403
|
+
}, pe = (e) => {
|
|
404
|
+
let t = e.parentNode;
|
|
405
|
+
if (t !== null) {
|
|
406
|
+
for (; e.firstChild !== null;) t.insertBefore(e.firstChild, e);
|
|
407
|
+
t.removeChild(e);
|
|
408
|
+
}
|
|
409
|
+
}, me = (e) => {
|
|
410
|
+
let t = (t) => e.contains(t), n = (e) => t(e) && v.has(e.tagName.toUpperCase()), r = Array.from(e.querySelectorAll("*")).filter((t) => {
|
|
411
|
+
if (!n(t)) return !1;
|
|
412
|
+
let r = S(t);
|
|
413
|
+
return ce(r) || ue(r, C(t, e));
|
|
414
|
+
});
|
|
415
|
+
r.forEach(pe);
|
|
416
|
+
let i = (e, t) => {
|
|
417
|
+
let n = e.nextSibling;
|
|
418
|
+
if (n === null || n.nodeType !== Node.ELEMENT_NODE || !le(t, S(n))) return !1;
|
|
419
|
+
let r = n;
|
|
420
|
+
for (; r.firstChild !== null;) e.appendChild(r.firstChild);
|
|
421
|
+
return r.remove(), i(e, t), !0;
|
|
422
|
+
}, a = Array.from(e.querySelectorAll("*")).filter(n).map((e) => t(e) && i(e, S(e))).some(Boolean);
|
|
423
|
+
return r.length > 0 || a;
|
|
424
|
+
}, w = (e) => {
|
|
425
|
+
let t = (n) => n === 0 || !me(e) ? !1 : (t(n - 1), !0), n = t(10);
|
|
426
|
+
return n && e.normalize?.(), n;
|
|
427
|
+
}, he = "data-blok-columns-candidate", ge = /(<br\s*\/?>)/i, _e = /^<br\s*\/?>$/i;
|
|
428
|
+
function T(e) {
|
|
429
|
+
let t = e.split(ge), n = t.reduce((e, t, n) => _e.test(t) || t.trim() === "" ? e : n, -1);
|
|
430
|
+
return t.slice(0, n + 1).join("").trimEnd();
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/components/utils/spacer-paragraph.ts
|
|
434
|
+
function E(e, t = {}) {
|
|
435
|
+
let { lineBreaksAreContent: n = !0 } = t, r = Array.from(e.children);
|
|
436
|
+
return !(n ? r.length > 0 : r.some((e) => e.tagName !== "BR")) && (e.textContent ?? "").replace(/\s/g, "") === "";
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/tools/list/paste-handler.ts
|
|
440
|
+
var ve = /* @__PURE__ */ new Set(/* @__PURE__ */ "decimal.decimal-leading-zero.lower-roman.upper-roman.lower-greek.lower-latin.upper-latin.lower-alpha.upper-alpha.arabic-indic.armenian.bengali.cambodian.cjk-decimal.devanagari.georgian.gujarati.gurmukhi.hebrew.kannada.khmer.lao.malayalam.mongolian.myanmar.oriya.persian.telugu.thai.tibetan".split(".")), ye = /* @__PURE__ */ new Set([
|
|
441
|
+
"disc",
|
|
442
|
+
"circle",
|
|
443
|
+
"square",
|
|
444
|
+
"none"
|
|
445
|
+
]), be = (e) => {
|
|
446
|
+
let t = e.getAttribute("data-list-style");
|
|
447
|
+
if (t === "ordered") return "ordered";
|
|
448
|
+
if (t === "unordered") return "unordered";
|
|
449
|
+
let n = e.getAttribute("style");
|
|
450
|
+
if (!n) return null;
|
|
451
|
+
let r = n.match(/list-style-type\s*:\s*([^;]+)/);
|
|
452
|
+
if (!r) return null;
|
|
453
|
+
let i = r[1].trim().toLowerCase();
|
|
454
|
+
return ve.has(i) ? "ordered" : ye.has(i) ? "unordered" : null;
|
|
455
|
+
}, D = (e) => {
|
|
456
|
+
if (e instanceof HTMLInputElement && e.type === "checkbox") return e;
|
|
457
|
+
let t = e.querySelector("input[type=\"checkbox\"]");
|
|
458
|
+
return t instanceof HTMLInputElement ? t : null;
|
|
459
|
+
}, xe = (e, t) => {
|
|
460
|
+
let n = e.parentElement, r = D(e) !== null;
|
|
461
|
+
return n?.tagName === "OL" ? "ordered" : n?.tagName === "UL" ? r ? "checklist" : "unordered" : be(e) || (r ? "checklist" : t);
|
|
462
|
+
}, Se = (e) => {
|
|
463
|
+
let t = D(e);
|
|
464
|
+
if (t === null) return {
|
|
465
|
+
text: e.innerHTML || e.textContent || "",
|
|
466
|
+
checked: !1
|
|
467
|
+
};
|
|
468
|
+
let n = e.cloneNode(!0);
|
|
469
|
+
return n.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove()), {
|
|
470
|
+
text: n.innerHTML.trim(),
|
|
471
|
+
checked: t.checked
|
|
472
|
+
};
|
|
473
|
+
}, Ce = (e) => {
|
|
474
|
+
let t = e.getAttribute("aria-level");
|
|
475
|
+
if (t) return Math.max(0, parseInt(t, 10) - 1);
|
|
476
|
+
let n = O(e) - 1;
|
|
477
|
+
return n > 0 ? n : 0;
|
|
478
|
+
}, O = (e) => {
|
|
479
|
+
let t = e.parentElement;
|
|
480
|
+
return t === null ? 0 : +(t.tagName === "UL" || t.tagName === "OL") + O(t);
|
|
481
|
+
}, we = /<br\s*\/?>/i, Te = (e) => e.split(we).map((e) => e.trim()).filter(Boolean), Ee = (e) => e instanceof HTMLElement && (e.tagName === "UL" || e.tagName === "OL"), De = (e) => Array.from(e.querySelectorAll("li")).map((t) => {
|
|
482
|
+
let n = xe(t, e.tagName === "OL" ? "ordered" : "unordered"), r = Ce(t), i = t.cloneNode(!0);
|
|
483
|
+
i.querySelectorAll("ul, ol").forEach((e) => e.remove());
|
|
484
|
+
let { text: a, checked: o } = Se(i);
|
|
485
|
+
return {
|
|
486
|
+
tool: "list",
|
|
487
|
+
data: {
|
|
488
|
+
text: T(a).trim(),
|
|
489
|
+
style: n,
|
|
490
|
+
checked: o,
|
|
491
|
+
depth: r
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}), k = (e) => Array.from(e.querySelectorAll("tr")).filter((t) => {
|
|
495
|
+
let n = t.closest("table")?.parentElement?.closest("table");
|
|
496
|
+
return n == null || !e.contains(n);
|
|
497
|
+
}), A = (e) => Array.from(e.children).filter((e) => e.tagName === "TD" || e.tagName === "TH"), Oe = (e) => {
|
|
498
|
+
let t = e.cloneNode(!0);
|
|
499
|
+
return t.querySelectorAll("br").forEach((e) => e.replaceWith("\n")), t.textContent ?? "";
|
|
500
|
+
}, ke = [
|
|
501
|
+
"h1",
|
|
502
|
+
"h2",
|
|
503
|
+
"h3",
|
|
504
|
+
"h4",
|
|
505
|
+
"h5",
|
|
506
|
+
"h6",
|
|
507
|
+
"blockquote"
|
|
508
|
+
].flatMap((e) => [`td ${e}`, `th ${e}`]).join(", "), Ae = (e) => {
|
|
509
|
+
for (let t of Array.from(e.querySelectorAll(ke))) {
|
|
510
|
+
let e = t.ownerDocument;
|
|
511
|
+
t.replaceWith(e.createElement("br"), ...Array.from(t.childNodes), e.createElement("br"));
|
|
512
|
+
}
|
|
513
|
+
}, je = (e) => e instanceof HTMLElement && (e.tagName === "PRE" || e.tagName === "BLOK-CELL-CODE"), j = (e) => {
|
|
514
|
+
let t = [], n = [], r = () => {
|
|
515
|
+
Te(n.join("")).forEach((e) => t.push({
|
|
516
|
+
tool: "paragraph",
|
|
517
|
+
data: { text: e }
|
|
518
|
+
})), n.length = 0;
|
|
519
|
+
};
|
|
520
|
+
for (let i of e) Ee(i) ? (r(), t.push(...De(i))) : i instanceof HTMLElement && (i.tagName === "P" || i.tagName === "DIV") ? (r(), n.push(i.innerHTML), r()) : je(i) ? (r(), t.push({
|
|
521
|
+
tool: "code",
|
|
522
|
+
data: { code: Oe(i) }
|
|
523
|
+
})) : i instanceof HTMLElement && i.tagName === "TABLE" ? (r(), k(i).flatMap(A).forEach((e) => t.push(...j(Array.from(e.childNodes))))) : n.push(i instanceof HTMLElement ? i.outerHTML : i.textContent ?? "");
|
|
524
|
+
return r(), t;
|
|
525
|
+
}, Me = (e) => {
|
|
526
|
+
let t = de(e), n = j(Array.from(t.childNodes));
|
|
527
|
+
return n.length > 0 ? n : [{
|
|
528
|
+
tool: "paragraph",
|
|
529
|
+
data: { text: "" }
|
|
530
|
+
}];
|
|
531
|
+
}, Ne = /* @__PURE__ */ new Set(/* @__PURE__ */ "aliceblue.antiquewhite.aqua.aquamarine.azure.beige.bisque.black.blanchedalmond.blue.blueviolet.brown.burlywood.cadetblue.chartreuse.chocolate.coral.cornflowerblue.cornsilk.crimson.cyan.darkblue.darkcyan.darkgoldenrod.darkgray.darkgreen.darkgrey.darkkhaki.darkmagenta.darkolivegreen.darkorange.darkorchid.darkred.darksalmon.darkseagreen.darkslateblue.darkslategray.darkslategrey.darkturquoise.darkviolet.deeppink.deepskyblue.dimgray.dimgrey.dodgerblue.firebrick.floralwhite.forestgreen.fuchsia.gainsboro.ghostwhite.gold.goldenrod.gray.green.greenyellow.grey.honeydew.hotpink.indianred.indigo.ivory.khaki.lavender.lavenderblush.lawngreen.lemonchiffon.lightblue.lightcoral.lightcyan.lightgoldenrodyellow.lightgray.lightgreen.lightgrey.lightpink.lightsalmon.lightseagreen.lightskyblue.lightslategray.lightslategrey.lightsteelblue.lightyellow.lime.limegreen.linen.magenta.maroon.mediumaquamarine.mediumblue.mediumorchid.mediumpurple.mediumseagreen.mediumslateblue.mediumspringgreen.mediumturquoise.mediumvioletred.midnightblue.mintcream.mistyrose.moccasin.navajowhite.navy.oldlace.olive.olivedrab.orange.orangered.orchid.palegoldenrod.palegreen.paleturquoise.palevioletred.papayawhip.peachpuff.peru.pink.plum.powderblue.purple.rebeccapurple.red.rosybrown.royalblue.saddlebrown.salmon.sandybrown.seagreen.seashell.sienna.silver.skyblue.slateblue.slategray.slategrey.snow.springgreen.steelblue.tan.teal.thistle.tomato.turquoise.violet.wheat.white.whitesmoke.yellow.yellowgreen".split(".")), Pe = /* @__PURE__ */ new Set(["transparent", "currentcolor"]), Fe = 256, M = "[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)", N = `${M}%?`, P = `${M}%`, F = `${M}(?:deg|grad|rad|turn)?`, I = " *, *", L = " +", R = `(?: */ *${N})?`, Ie = RegExp(`^rgba?\\( *${N}${I}${N}${I}${N}(?:${I}${N})? *\\)$`, "i"), Le = RegExp(`^rgba?\\( *${N}${L}${N}${L}${N}${R} *\\)$`, "i"), Re = RegExp(`^hsla?\\( *${F}${I}${P}${I}${P}(?:${I}${N})? *\\)$`, "i"), ze = RegExp(`^hsla?\\( *${F}${L}${N}${L}${N}${R} *\\)$`, "i"), Be = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, Ve = /^var\(--[a-zA-Z0-9_-]+\)$/, z = (e) => {
|
|
532
|
+
if (typeof e != "string" || e.length === 0 || e.length > Fe) return !1;
|
|
533
|
+
let t = e.toLowerCase();
|
|
534
|
+
return Ne.has(t) || Pe.has(t) || Be.test(e) || Ve.test(e) || Ie.test(e) || Le.test(e) || Re.test(e) || ze.test(e);
|
|
535
|
+
};
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/components/modules/paste/google-docs-preprocessor.ts
|
|
538
|
+
function He(e, { keepTables: t = !1 } = {}) {
|
|
539
|
+
let n = de(e), r = qe(n);
|
|
540
|
+
return nt(n, r), r && !t && it(n), ct(n), r && !t && at(n), r && Ke(n), w(n), n.innerHTML;
|
|
541
|
+
}
|
|
542
|
+
function B(e, t) {
|
|
543
|
+
let n = e.parentElement;
|
|
544
|
+
return n === null ? null : n === t ? e : B(n, t);
|
|
545
|
+
}
|
|
546
|
+
function Ue(e, t, n) {
|
|
547
|
+
let r = e.cloneNode(!1), i = [];
|
|
548
|
+
for (let n of Array.from(e.childNodes)) {
|
|
549
|
+
if (n === t) break;
|
|
550
|
+
i.push(n);
|
|
551
|
+
}
|
|
552
|
+
return i.forEach((e) => r.appendChild(e)), n !== null && r.appendChild(n), r.childNodes.length > 0 ? r : null;
|
|
553
|
+
}
|
|
554
|
+
function We(e, t, n) {
|
|
555
|
+
let r = e.cloneNode(!1), i = Array.from(e.childNodes), a = i.findIndex((e) => e === t), o = i.slice(a + 1);
|
|
556
|
+
return n !== null && r.appendChild(n), o.forEach((e) => r.appendChild(e)), r.childNodes.length > 0 ? r : null;
|
|
557
|
+
}
|
|
558
|
+
function Ge(e, t) {
|
|
559
|
+
let n = (e, r, i) => {
|
|
560
|
+
if (e === t) return {
|
|
561
|
+
before: r,
|
|
562
|
+
after: i
|
|
563
|
+
};
|
|
564
|
+
let a = e.parentElement;
|
|
565
|
+
if (a === null) return {
|
|
566
|
+
before: r,
|
|
567
|
+
after: i
|
|
568
|
+
};
|
|
569
|
+
let o = Ue(a, e, r), s = We(a, e, i);
|
|
570
|
+
return n(a, o, s);
|
|
571
|
+
};
|
|
572
|
+
return n(e, null, null);
|
|
573
|
+
}
|
|
574
|
+
function V(e, t) {
|
|
575
|
+
let n = e.parentElement;
|
|
576
|
+
return n === null || n === t ? !1 : n.tagName === "TABLE" || V(n, t);
|
|
577
|
+
}
|
|
578
|
+
function Ke(e) {
|
|
579
|
+
let t = Array.from(e.querySelectorAll("img"));
|
|
580
|
+
for (let n of t) {
|
|
581
|
+
if (V(n, e)) continue;
|
|
582
|
+
let t = B(n, e);
|
|
583
|
+
if (!t) continue;
|
|
584
|
+
let { before: r, after: i } = Ge(n, t), a = document.createDocumentFragment();
|
|
585
|
+
r && a.appendChild(r), a.appendChild(n), i && a.appendChild(i), t.replaceWith(a);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function qe(e) {
|
|
589
|
+
let t = e.querySelector("b[id^=\"docs-internal-guid-\"]");
|
|
590
|
+
if (!t) return !1;
|
|
591
|
+
let n = document.createDocumentFragment();
|
|
592
|
+
for (; t.firstChild;) n.appendChild(t.firstChild);
|
|
593
|
+
return t.replaceWith(n), !0;
|
|
594
|
+
}
|
|
595
|
+
function Je(e, t, n) {
|
|
596
|
+
return e ? `background-color: ${n}` : t ? "background-color: transparent" : "";
|
|
597
|
+
}
|
|
598
|
+
function H(e) {
|
|
599
|
+
if (e.closest("a") !== null) return !0;
|
|
600
|
+
let t = e.querySelector("a");
|
|
601
|
+
return t !== null && t.textContent?.trim() === e.textContent?.trim();
|
|
602
|
+
}
|
|
603
|
+
function Ye(e) {
|
|
604
|
+
let t = e.replace(/\s/g, "").toLowerCase(), n = /^rgba?\((\d+),(\d+),(\d+)(?:,[\d.]+)?\)$/.exec(t);
|
|
605
|
+
if (n) {
|
|
606
|
+
let e = parseInt(n[1], 10) / 255, t = parseInt(n[2], 10) / 255, r = parseInt(n[3], 10) / 255;
|
|
607
|
+
return .2126 * e + .7152 * t + .0722 * r;
|
|
608
|
+
}
|
|
609
|
+
let r = /^hsla?\(([\d.]+),([\d.]+)%,([\d.]+)%(?:,[\d.]+)?\)$/.exec(t);
|
|
610
|
+
if (r) {
|
|
611
|
+
let e = parseFloat(r[1]) / 360, t = parseFloat(r[2]) / 100, n = parseFloat(r[3]) / 100;
|
|
612
|
+
if (t === 0) return .2126 * n + .7152 * n + .0722 * n;
|
|
613
|
+
let i = n < .5 ? n * (1 + t) : n + t - n * t, a = 2 * n - i, o = (e) => {
|
|
614
|
+
let t = e < 0 ? e + 1 : e > 1 ? e - 1 : e;
|
|
615
|
+
return t < 1 / 6 ? a + (i - a) * 6 * t : t < 1 / 2 ? i : t < 2 / 3 ? a + (i - a) * (2 / 3 - t) * 6 : a;
|
|
616
|
+
}, s = o(e + 1 / 3), c = o(e), l = o(e - 1 / 3);
|
|
617
|
+
return .2126 * s + .7152 * c + .0722 * l;
|
|
618
|
+
}
|
|
619
|
+
let i = /^#([0-9a-f]{6}|[0-9a-f]{3})$/.exec(t);
|
|
620
|
+
if (i) {
|
|
621
|
+
let e = i[1], t = e.length === 3 ? [
|
|
622
|
+
e[0] + e[0],
|
|
623
|
+
e[1] + e[1],
|
|
624
|
+
e[2] + e[2]
|
|
625
|
+
] : [
|
|
626
|
+
e.substring(0, 2),
|
|
627
|
+
e.substring(2, 4),
|
|
628
|
+
e.substring(4, 6)
|
|
629
|
+
], n = parseInt(t[0], 16) / 255, r = parseInt(t[1], 16) / 255, a = parseInt(t[2], 16) / 255;
|
|
630
|
+
return .2126 * n + .7152 * r + .0722 * a;
|
|
631
|
+
}
|
|
632
|
+
return -1;
|
|
633
|
+
}
|
|
634
|
+
function Xe(e) {
|
|
635
|
+
let t = Ye(e);
|
|
636
|
+
return t >= 0 && t > .75;
|
|
637
|
+
}
|
|
638
|
+
function Ze(e, t, n, r, i) {
|
|
639
|
+
if (!t && !n) return e;
|
|
640
|
+
let a = t && r !== void 0 ? h(r, "text") : "", o = n && i !== void 0 ? h(i, "bg") : "", s = [t ? `color: ${a}` : "", Je(n, t, o)].filter(Boolean).join("; ");
|
|
641
|
+
return s ? `<mark style="${s};">${e}</mark>` : e;
|
|
642
|
+
}
|
|
643
|
+
var Qe = /* @__PURE__ */ new Set([
|
|
644
|
+
"H1",
|
|
645
|
+
"H2",
|
|
646
|
+
"H3",
|
|
647
|
+
"H4",
|
|
648
|
+
"H5",
|
|
649
|
+
"H6"
|
|
650
|
+
]);
|
|
651
|
+
function U(e) {
|
|
652
|
+
let t = e.parentElement;
|
|
653
|
+
return t === null ? !1 : Qe.has(t.tagName) ? !0 : U(t);
|
|
654
|
+
}
|
|
655
|
+
var $e = {
|
|
656
|
+
super: "sup",
|
|
657
|
+
sub: "sub"
|
|
658
|
+
};
|
|
659
|
+
function et(e) {
|
|
660
|
+
let t = /background-color\s*:\s*([^;]+)/i.exec(e)?.[1];
|
|
661
|
+
if (t !== void 0) return t.trim();
|
|
662
|
+
if (!/(?<![a-z-])background\s*:/i.test(e)) return;
|
|
663
|
+
let n = document.implementation.createHTMLDocument("").createElement("div");
|
|
664
|
+
n.style.cssText = e;
|
|
665
|
+
let r = n.style.backgroundColor;
|
|
666
|
+
return z(r) && r.toLowerCase() !== "currentcolor" ? r : void 0;
|
|
667
|
+
}
|
|
668
|
+
function tt(e, t) {
|
|
669
|
+
let n = e.getAttribute("style") ?? "", r = /font-weight\s*:\s*(700|bold)/i.test(n) && !U(e), i = /font-style\s*:\s*italic/i.test(n), a = /(?<![a-z-])color\s*:\s*([^;]+)/i.exec(n)?.[1]?.trim(), o = et(n), c = !(a !== void 0 && H(e)) && (t ? a !== void 0 && !l(a) : a !== void 0 && !l(a) && !Xe(a)), u = o !== void 0 && !s(o), d = t ? /text-decoration(?:-line)?\s*:\s*([^;]+)/i.exec(n)?.[1] ?? "" : "", f = t ? /vertical-align\s*:\s*([^;]+)/i.exec(n)?.[1]?.trim() ?? "" : "", p = /underline/i.test(d) && !H(e), m = /line-through/i.test(d), h = $e[f.toLowerCase()];
|
|
670
|
+
if (!r && !i && !c && !u && !p && !m && h === void 0) return null;
|
|
671
|
+
let g = Ze(e.innerHTML, c, u, a, o);
|
|
672
|
+
return [
|
|
673
|
+
r ? "b" : "",
|
|
674
|
+
i ? "i" : "",
|
|
675
|
+
p ? "u" : "",
|
|
676
|
+
m ? "s" : "",
|
|
677
|
+
h ?? ""
|
|
678
|
+
].filter(Boolean).reduceRight((e, t) => `<${t}>${e}</${t}>`, g);
|
|
679
|
+
}
|
|
680
|
+
function nt(e, t) {
|
|
681
|
+
for (let n of Array.from(e.querySelectorAll("span[style]"))) {
|
|
682
|
+
let e = tt(n, t);
|
|
683
|
+
e !== null && n.replaceWith(n.ownerDocument.createRange().createContextualFragment(e));
|
|
684
|
+
}
|
|
685
|
+
t && rt(e);
|
|
686
|
+
}
|
|
687
|
+
function rt(e) {
|
|
688
|
+
for (let t of Array.from(e.querySelectorAll("a[style]"))) {
|
|
689
|
+
let e = t.getAttribute("style") ?? "", n = /background-color\s*:\s*([^;]+)/i.exec(e)?.[1]?.trim(), r = n !== void 0 && n !== "transparent" && n !== "inherit", i = t;
|
|
690
|
+
i.style.removeProperty("color"), r && (i.innerHTML = `<mark style="background-color: ${h(n, "bg")};">${i.innerHTML}</mark>`, i.style.removeProperty("background-color"));
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function it(e) {
|
|
694
|
+
if (e.querySelector("google-sheets-html-origin") === null) for (let t of Array.from(e.querySelectorAll("table"))) {
|
|
695
|
+
if (t.parentElement?.closest("table") !== null) continue;
|
|
696
|
+
let e = k(t).map(A);
|
|
697
|
+
e.length === 0 || e.some((e) => e.length !== 1) || (e.length === 1 || t.querySelector("img") !== null) && t.replaceWith(...e.flatMap(([e]) => Array.from(e.childNodes)));
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function at(e) {
|
|
701
|
+
if (e.querySelector("google-sheets-html-origin") === null) for (let t of Array.from(e.querySelectorAll("table"))) {
|
|
702
|
+
if (t.parentElement?.closest("table") !== null) continue;
|
|
703
|
+
let e = k(t).map(A);
|
|
704
|
+
if (e.length === 0) continue;
|
|
705
|
+
let n = e[0].length;
|
|
706
|
+
if (!e.every((e) => e.length === n)) continue;
|
|
707
|
+
let r = e.length === 1 && (n === 2 || n === 3), i = e.length > 1 && n === 2 && t.querySelector("img") !== null;
|
|
708
|
+
(r || i) && t.setAttribute(he, "");
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function ot(e) {
|
|
712
|
+
if (E(e)) {
|
|
713
|
+
e.remove();
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
let t = e.ownerDocument.createRange().createContextualFragment(e.innerHTML + "<br>");
|
|
717
|
+
e.replaceWith(t);
|
|
718
|
+
}
|
|
719
|
+
var W = /(?<![a-z-])text-align\s*:\s*([^;]+)/i;
|
|
720
|
+
function st(e) {
|
|
721
|
+
let t = W.exec(e.getAttribute("style") ?? "")?.[1], n = e.getAttribute("align")?.trim();
|
|
722
|
+
return (t ?? (n !== void 0 && /^[a-z]+$/i.test(n) ? n : void 0))?.trim().toLowerCase();
|
|
723
|
+
}
|
|
724
|
+
function G(e) {
|
|
725
|
+
let t = e.getAttribute("style") ?? "";
|
|
726
|
+
if (W.test(t)) return;
|
|
727
|
+
let n = Array.from(e.querySelectorAll("p")).filter((t) => t.closest("td, th") === e && !E(t)), r = new Set(n.map(st)), [i] = r;
|
|
728
|
+
r.size === 1 && i !== void 0 && e.setAttribute("style", t === "" ? `text-align:${i}` : `${t};text-align:${i}`);
|
|
729
|
+
}
|
|
730
|
+
function ct(e) {
|
|
731
|
+
let t = Array.from(e.querySelectorAll("td, th"));
|
|
732
|
+
t.forEach(G);
|
|
733
|
+
for (let e of t) {
|
|
734
|
+
let t = e.querySelectorAll("p");
|
|
735
|
+
t.length !== 0 && (Array.from(t).forEach(ot), e.innerHTML = T(e.innerHTML));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
//#endregion
|
|
739
|
+
//#region src/tools/table/table-operations.ts
|
|
740
|
+
var lt = 1e3, ut = 65534, K = (e, t, n) => {
|
|
741
|
+
let r = Number.parseInt(e.getAttribute(t) ?? "", 10);
|
|
742
|
+
return !Number.isFinite(r) || r < 1 ? 1 : Math.min(r, n);
|
|
743
|
+
}, dt = (e, t) => {
|
|
744
|
+
let n = Array.from(e), r = n.map(() => []), i = { hasMerges: !1 }, a = (e, t) => e[t] === void 0 ? t : a(e, t + 1), o = (e, n, i, a) => {
|
|
745
|
+
Array.from({ length: i }).forEach((i, o) => {
|
|
746
|
+
Array.from({ length: a }).forEach((i, a) => {
|
|
747
|
+
(o !== 0 || a !== 0) && (r[e + o][n + a] ??= t.covered([e, n]));
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
n.forEach((e, s) => {
|
|
752
|
+
A(e).reduce((e, c) => {
|
|
753
|
+
let l = a(r[s], e), u = K(c, "colspan", lt), d = Math.min(K(c, "rowspan", ut), n.length - s);
|
|
754
|
+
return r[s][l] = t.cell(c, {
|
|
755
|
+
colspan: u,
|
|
756
|
+
rowspan: d
|
|
757
|
+
}), (u > 1 || d > 1) && (i.hasMerges = !0, o(s, l, d, u)), l + u;
|
|
758
|
+
}, 0);
|
|
759
|
+
});
|
|
760
|
+
let s = i.hasMerges ? r : r.filter((e) => e.length > 0), c = s.reduce((e, t) => Math.max(e, t.length), 0);
|
|
761
|
+
return s.map((e) => Array.from({ length: c }, (n, r) => e[r] ?? t.filler()));
|
|
762
|
+
}, q = "data-latex", ft = /* @__PURE__ */ new Set(["color", "background-color"]), pt = {
|
|
763
|
+
br: !0,
|
|
764
|
+
strong: {},
|
|
765
|
+
b: {},
|
|
766
|
+
em: {},
|
|
767
|
+
i: {},
|
|
768
|
+
u: {},
|
|
769
|
+
s: {},
|
|
770
|
+
del: {},
|
|
771
|
+
a: te,
|
|
772
|
+
code: {},
|
|
773
|
+
sup: {},
|
|
774
|
+
sub: {},
|
|
775
|
+
mark: (e) => {
|
|
776
|
+
let t = e.style, n = Array.from({ length: t.length }, (e, n) => t.item(n));
|
|
777
|
+
for (let e of n) ft.has(e) || t.removeProperty(e);
|
|
778
|
+
return t.length > 0 ? { style: !0 } : {};
|
|
779
|
+
},
|
|
780
|
+
span: (e) => {
|
|
781
|
+
let t = e.getAttribute(q);
|
|
782
|
+
return t !== null && (e.textContent !== t && (e.textContent = t), { [q]: !0 });
|
|
783
|
+
}
|
|
784
|
+
}, mt = [
|
|
785
|
+
"left",
|
|
786
|
+
"center",
|
|
787
|
+
"right"
|
|
788
|
+
], ht = [
|
|
789
|
+
"top",
|
|
790
|
+
"middle",
|
|
791
|
+
"bottom"
|
|
792
|
+
], gt = {
|
|
793
|
+
left: "right",
|
|
794
|
+
center: "center",
|
|
795
|
+
right: "left"
|
|
796
|
+
};
|
|
797
|
+
function _t(e, t) {
|
|
798
|
+
return t === "rtl" ? gt[e] : e;
|
|
799
|
+
}
|
|
800
|
+
function vt(e, t, n = "ltr") {
|
|
801
|
+
let r = e?.trim().toLowerCase(), i = mt.find((e) => e === r), a = r === "end" || r?.replace(/\s+/g, "") === "var(--_blok-end-side,right)" ? "right" : "left", o = i === void 0 ? a : _t(i, n), s = ht.find((e) => e === t?.trim().toLowerCase()) ?? "top";
|
|
802
|
+
if (o !== "left" || s !== "top") return `${s}-${o}`;
|
|
803
|
+
}
|
|
804
|
+
({ ...pt });
|
|
805
|
+
function yt(e) {
|
|
806
|
+
let t = /background-color\s*:\s*([^;]+)/i.exec(e)?.[1];
|
|
807
|
+
if (t !== void 0) return t.trim();
|
|
808
|
+
if (!/(?<![a-z-])background\s*:/i.test(e)) return;
|
|
809
|
+
let n = document.implementation.createHTMLDocument("").createElement("div");
|
|
810
|
+
return n.style.cssText = e, n.style.backgroundColor || void 0;
|
|
811
|
+
}
|
|
812
|
+
function J(e) {
|
|
813
|
+
let t = (/(?<![a-z-])direction\s*:\s*(rtl|ltr)\b/i.exec(e.getAttribute("style") ?? "")?.[1] ?? e.getAttribute("dir"))?.trim().toLowerCase();
|
|
814
|
+
return t === "rtl" || t === "ltr" ? t : e.parentElement === null ? "ltr" : J(e.parentElement);
|
|
815
|
+
}
|
|
816
|
+
function bt(e, t = "ltr") {
|
|
817
|
+
let n = {}, r = yt(e);
|
|
818
|
+
r !== void 0 && !s(r) && (n.color = h(r, "bg"));
|
|
819
|
+
let i = /(?<![a-z-])color\s*:\s*([^;]+)/i.exec(e)?.[1]?.trim();
|
|
820
|
+
i !== void 0 && !l(i) && (n.textColor = h(i, "text"));
|
|
821
|
+
let a = vt(/(?<![a-z-])text-align\s*:\s*([^;]+)/i.exec(e)?.[1], /vertical-align\s*:\s*([^;]+)/i.exec(e)?.[1], t);
|
|
822
|
+
return a !== void 0 && (n.placement = a), n;
|
|
823
|
+
}
|
|
824
|
+
function xt(e, t = "ltr") {
|
|
825
|
+
let n = e.getAttribute("style") ?? "", r = [n], i = e.getAttribute("align")?.trim(), a = e.getAttribute("valign")?.trim(), o = e.getAttribute("bgcolor")?.trim();
|
|
826
|
+
return i !== void 0 && /^[a-z]+$/i.test(i) && !/(?<![a-z-])text-align\s*:/i.test(n) && r.push(`text-align:${i}`), a !== void 0 && /^[a-z]+$/i.test(a) && !/vertical-align\s*:/i.test(n) && r.push(`vertical-align:${a}`), z(o) && !/(?<![a-z-])background(?:-color)?\s*:/i.test(n) && r.push(`background-color:${o}`), bt(r.join(";"), t);
|
|
827
|
+
}
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/components/modules/paste/table-direction-preprocessor.ts
|
|
830
|
+
function St(e) {
|
|
831
|
+
if (!/<table[\s>]/i.test(e)) return e;
|
|
832
|
+
let t = fe(e), n = Array.from(t.querySelectorAll("table")).filter((e) => {
|
|
833
|
+
let t = e.getAttribute("dir")?.trim().toLowerCase() === "rtl" ? "rtl" : "ltr";
|
|
834
|
+
return J(e) !== t;
|
|
835
|
+
});
|
|
836
|
+
return n.length === 0 ? e : (n.forEach((e) => e.setAttribute("dir", J(e))), t.documentElement.outerHTML);
|
|
837
|
+
}
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/preprocess/legacy-cms-html.ts
|
|
840
|
+
function Ct(e) {
|
|
841
|
+
wt(e), Dt(e), At(e), Mt(e), Nt(e), Ft(e);
|
|
842
|
+
}
|
|
843
|
+
function wt(e) {
|
|
844
|
+
let t = e.ownerDocument;
|
|
845
|
+
for (let n of Array.from(e.querySelectorAll("div[style]"))) {
|
|
846
|
+
if (n.closest("table")) continue;
|
|
847
|
+
let e = kt(n);
|
|
848
|
+
if (!e || X(e)) continue;
|
|
849
|
+
let r = t.createElement("aside");
|
|
850
|
+
r.style.backgroundColor = e, r.append(...Array.from(n.childNodes)), Tt(r), Et(r), n.replaceWith(r);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
function Tt(e) {
|
|
854
|
+
for (;;) {
|
|
855
|
+
let t = Array.from(e.querySelectorAll(":scope > div")).filter((e) => !e.getAttribute("style") && !e.getAttribute("class"));
|
|
856
|
+
if (t.length === 0) break;
|
|
857
|
+
for (let e of t) e.replaceWith(...Array.from(e.childNodes));
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
function Et(e) {
|
|
861
|
+
for (let t of Array.from(e.querySelectorAll("p"))) {
|
|
862
|
+
let e = t.lastElementChild;
|
|
863
|
+
e?.tagName === "BR" && e.remove();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
var Y = 250;
|
|
867
|
+
function Dt(e) {
|
|
868
|
+
let t = e.querySelectorAll("[style*=\"background-color\"]");
|
|
869
|
+
for (let e of Array.from(t)) X(e.style.backgroundColor) && (e.style.removeProperty("background-color"), e.getAttribute("style")?.trim() === "" && e.removeAttribute("style"), Ot(e) && e.replaceWith(...Array.from(e.childNodes)));
|
|
870
|
+
}
|
|
871
|
+
function X(e) {
|
|
872
|
+
if (!e) return !1;
|
|
873
|
+
let t = e.replace(/\s/g, "").toLowerCase();
|
|
874
|
+
if (t === "transparent") return !0;
|
|
875
|
+
let n = t.match(/^rgba?\((\d+),(\d+),(\d+)(?:,([^)]+))?\)$/);
|
|
876
|
+
if (!n) return !1;
|
|
877
|
+
if ((n[4] === void 0 ? 1 : parseFloat(n[4])) === 0) return !0;
|
|
878
|
+
let r = parseInt(n[1], 10), i = parseInt(n[2], 10), a = parseInt(n[3], 10);
|
|
879
|
+
return r >= Y && i >= Y && a >= Y;
|
|
880
|
+
}
|
|
881
|
+
function Ot(e) {
|
|
882
|
+
return e.attributes.length > 0 ? !1 : (e.textContent ?? "").replace(/[\s\u00A0]/g, "").length === 0;
|
|
883
|
+
}
|
|
884
|
+
function kt(e) {
|
|
885
|
+
if (e.style.backgroundColor) return e.style.backgroundColor;
|
|
886
|
+
let t = (e.getAttribute("style") ?? "").match(/background:\s*([^;]+)/i);
|
|
887
|
+
if (t) {
|
|
888
|
+
let e = t[1].trim().match(/^(rgb[a]?\([^)]+\)|#[0-9a-fA-F]{3,8}|[a-z]+)$/i);
|
|
889
|
+
if (e) return e[1];
|
|
890
|
+
}
|
|
891
|
+
return "";
|
|
892
|
+
}
|
|
893
|
+
function At(e) {
|
|
894
|
+
for (let t of Array.from(e.querySelectorAll("td, th"))) {
|
|
895
|
+
let e = t.querySelectorAll("p");
|
|
896
|
+
if (e.length !== 0) {
|
|
897
|
+
for (let t of Array.from(e)) jt(t);
|
|
898
|
+
Rt(t);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function jt(e) {
|
|
903
|
+
if (e.innerHTML.trim() === "" || e.innerHTML.trim() === " ") {
|
|
904
|
+
e.remove();
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
let t = e.ownerDocument, n = t.createDocumentFragment();
|
|
908
|
+
n.append(...Array.from(e.childNodes)), n.append(t.createElement("br")), e.replaceWith(n);
|
|
909
|
+
}
|
|
910
|
+
function Mt(e) {
|
|
911
|
+
for (let t of Array.from(e.querySelectorAll("p"))) t.closest("td") || t.closest("th") || E(t, { lineBreaksAreContent: !1 }) && t.remove();
|
|
912
|
+
}
|
|
913
|
+
function Nt(e) {
|
|
914
|
+
let t = e.ownerDocument;
|
|
915
|
+
for (let n of Array.from(e.querySelectorAll("del, strike"))) {
|
|
916
|
+
let e = t.createElement("s");
|
|
917
|
+
e.append(...Array.from(n.childNodes)), n.replaceWith(e);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
var Pt = /^[\u2022\u00B7][\s\u00A0]*|^-\s/;
|
|
921
|
+
function Ft(e) {
|
|
922
|
+
let t = e.ownerDocument, n = Lt(e);
|
|
923
|
+
for (let e of n) {
|
|
924
|
+
let n = t.createElement("ul");
|
|
925
|
+
e[0].before(n);
|
|
926
|
+
for (let t of e) It(t, n);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function It(e, t) {
|
|
930
|
+
let n = e.ownerDocument.createElement("li"), r = zt(e);
|
|
931
|
+
r && (r.textContent = (r.textContent ?? "").replace(Pt, "")), n.append(...Array.from(e.childNodes)), t.appendChild(n), e.remove();
|
|
932
|
+
}
|
|
933
|
+
function Lt(e) {
|
|
934
|
+
let t = [], n = Array.from(e.childNodes);
|
|
935
|
+
for (let e of n) {
|
|
936
|
+
if (e.nodeType !== Node.ELEMENT_NODE) continue;
|
|
937
|
+
let n = e;
|
|
938
|
+
if (!(n.tagName === "P" && Pt.test(n.textContent ?? ""))) continue;
|
|
939
|
+
let r = t[t.length - 1], i = n.previousElementSibling;
|
|
940
|
+
r && i !== null && r[r.length - 1] === i ? r.push(n) : t.push([n]);
|
|
941
|
+
}
|
|
942
|
+
return t;
|
|
943
|
+
}
|
|
944
|
+
function Rt(e) {
|
|
945
|
+
for (;;) {
|
|
946
|
+
let t = e.lastChild;
|
|
947
|
+
if (!t) break;
|
|
948
|
+
let n = t.nodeType === Node.ELEMENT_NODE && t.tagName === "BR", r = t.nodeType === Node.TEXT_NODE && t.textContent?.trim() === "";
|
|
949
|
+
if (!n && !r) break;
|
|
950
|
+
t.remove();
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
function zt(e) {
|
|
954
|
+
if (e.nodeType === Node.TEXT_NODE) return e;
|
|
955
|
+
for (let t of Array.from(e.childNodes)) {
|
|
956
|
+
let e = zt(t);
|
|
957
|
+
if (e) return e;
|
|
958
|
+
}
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region src/cli/commands/convert-html/sanitizer.ts
|
|
963
|
+
var Bt = {
|
|
964
|
+
B: !0,
|
|
965
|
+
STRONG: !0,
|
|
966
|
+
I: !0,
|
|
967
|
+
EM: !0,
|
|
968
|
+
A: /* @__PURE__ */ new Set(["href"]),
|
|
969
|
+
S: !0,
|
|
970
|
+
U: !0,
|
|
971
|
+
CODE: !0,
|
|
972
|
+
MARK: /* @__PURE__ */ new Set(["style"]),
|
|
973
|
+
BR: !0,
|
|
974
|
+
P: !0,
|
|
975
|
+
H1: !0,
|
|
976
|
+
H2: !0,
|
|
977
|
+
H3: !0,
|
|
978
|
+
H4: !0,
|
|
979
|
+
H5: !0,
|
|
980
|
+
H6: !0,
|
|
981
|
+
UL: !0,
|
|
982
|
+
OL: !0,
|
|
983
|
+
LI: /* @__PURE__ */ new Set(["aria-level"]),
|
|
984
|
+
TABLE: /* @__PURE__ */ new Set(["dir"]),
|
|
985
|
+
THEAD: !0,
|
|
986
|
+
TBODY: !0,
|
|
987
|
+
TR: !0,
|
|
988
|
+
CAPTION: !0,
|
|
989
|
+
TD: /* @__PURE__ */ new Set([
|
|
990
|
+
"style",
|
|
991
|
+
"colspan",
|
|
992
|
+
"rowspan",
|
|
993
|
+
"align",
|
|
994
|
+
"valign",
|
|
995
|
+
"bgcolor"
|
|
996
|
+
]),
|
|
997
|
+
TH: /* @__PURE__ */ new Set([
|
|
998
|
+
"style",
|
|
999
|
+
"colspan",
|
|
1000
|
+
"rowspan",
|
|
1001
|
+
"align",
|
|
1002
|
+
"valign",
|
|
1003
|
+
"bgcolor"
|
|
1004
|
+
]),
|
|
1005
|
+
BLOCKQUOTE: !0,
|
|
1006
|
+
PRE: !0,
|
|
1007
|
+
HR: !0,
|
|
1008
|
+
ASIDE: /* @__PURE__ */ new Set(["style"]),
|
|
1009
|
+
DETAILS: !0,
|
|
1010
|
+
SUMMARY: !0,
|
|
1011
|
+
IMG: /* @__PURE__ */ new Set([
|
|
1012
|
+
"src",
|
|
1013
|
+
"alt",
|
|
1014
|
+
"style"
|
|
1015
|
+
])
|
|
1016
|
+
};
|
|
1017
|
+
function Vt(e) {
|
|
1018
|
+
Wt(e);
|
|
1019
|
+
}
|
|
1020
|
+
function Ht(e) {
|
|
1021
|
+
let t = Array.from(e.childNodes);
|
|
1022
|
+
for (let n of t) e.before(n);
|
|
1023
|
+
return e.remove(), t.filter((e) => e.nodeType === e.ELEMENT_NODE);
|
|
1024
|
+
}
|
|
1025
|
+
function Ut(e, t) {
|
|
1026
|
+
for (let n of Array.from(e.attributes)) (t === !0 || !t.has(n.name)) && e.removeAttribute(n.name);
|
|
1027
|
+
}
|
|
1028
|
+
function Wt(e) {
|
|
1029
|
+
let t = Array.from(e.childNodes);
|
|
1030
|
+
for (let e of t) {
|
|
1031
|
+
if (e.nodeType !== e.ELEMENT_NODE) continue;
|
|
1032
|
+
let n = e, r = Bt[n.tagName];
|
|
1033
|
+
if (r === void 0) {
|
|
1034
|
+
t.push(...Ht(n));
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
Ut(n, r), Wt(n);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/cli/commands/convert-html/id-generator.ts
|
|
1042
|
+
function Gt() {
|
|
1043
|
+
let e = /* @__PURE__ */ new Map();
|
|
1044
|
+
return (t) => {
|
|
1045
|
+
let n = (e.get(t) ?? 0) + 1;
|
|
1046
|
+
return e.set(t, n), `${t}-${n}`;
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/components/modules/normalizeInlineImages.ts
|
|
1051
|
+
var Kt = (e) => {
|
|
1052
|
+
let t = document.createElement("template");
|
|
1053
|
+
return t.content.append(e), {
|
|
1054
|
+
html: t.innerHTML,
|
|
1055
|
+
empty: (t.content.textContent ?? "").trim() === "" && t.content.querySelector("img") === null
|
|
1056
|
+
};
|
|
1057
|
+
}, qt = (e) => {
|
|
1058
|
+
if (!/<img\b/i.test(e)) return null;
|
|
1059
|
+
let t = document.createElement("template");
|
|
1060
|
+
t.innerHTML = e;
|
|
1061
|
+
let n = t.content, r = Array.from(n.querySelectorAll("img")).filter((e) => (e.getAttribute("src") ?? "") !== "");
|
|
1062
|
+
if (r.length === 0) return null;
|
|
1063
|
+
let i = [], a = (n.ownerDocument ?? document).createRange();
|
|
1064
|
+
for (let e of r) a.setStart(n, 0), a.setEndBefore(e), i.push({
|
|
1065
|
+
kind: "text",
|
|
1066
|
+
...Kt(a.extractContents())
|
|
1067
|
+
}), i.push({
|
|
1068
|
+
kind: "image",
|
|
1069
|
+
url: e.getAttribute("src") ?? "",
|
|
1070
|
+
alt: e.getAttribute("alt")
|
|
1071
|
+
}), e.remove();
|
|
1072
|
+
return a.selectNodeContents(n), i.push({
|
|
1073
|
+
kind: "text",
|
|
1074
|
+
...Kt(a.extractContents())
|
|
1075
|
+
}), i;
|
|
1076
|
+
}, Jt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-", Yt = (e) => {
|
|
1077
|
+
let [t, n] = Array.from(e).reduce(([e, t], n) => {
|
|
1078
|
+
let r = n.charCodeAt(0);
|
|
1079
|
+
return [Math.imul(e ^ r, 2654435761), Math.imul(t ^ r, 1597334677)];
|
|
1080
|
+
}, [3735928559, 1103547991]), r = Math.imul(t ^ t >>> 16, 2246822507) ^ Math.imul(n ^ n >>> 13, 3266489909);
|
|
1081
|
+
return [r, Math.imul(n ^ n >>> 16, 2246822507) ^ Math.imul(r ^ r >>> 13, 3266489909)].flatMap((e) => [
|
|
1082
|
+
0,
|
|
1083
|
+
6,
|
|
1084
|
+
12,
|
|
1085
|
+
18,
|
|
1086
|
+
24
|
|
1087
|
+
].map((t) => Jt[e >>> t & 63])).join("");
|
|
1088
|
+
}, Z = (e, t, n, r = 0) => {
|
|
1089
|
+
let i = Yt(`${e}:${t}:${r}`);
|
|
1090
|
+
return n.has(i) ? Z(e, t, n, r + 1) : (n.add(i), i);
|
|
1091
|
+
}, Xt = (e, t, n, r, i) => {
|
|
1092
|
+
let a = [], o = r.find((e) => e.kind === "text" && !e.empty);
|
|
1093
|
+
for (let [s, c] of r.entries()) {
|
|
1094
|
+
if (c.kind === "image") {
|
|
1095
|
+
a.push({
|
|
1096
|
+
id: Z(t, s, i),
|
|
1097
|
+
tool: "image",
|
|
1098
|
+
data: c.alt !== null && c.alt !== "" ? {
|
|
1099
|
+
url: c.url,
|
|
1100
|
+
alt: c.alt
|
|
1101
|
+
} : { url: c.url },
|
|
1102
|
+
isValid: !0,
|
|
1103
|
+
parentId: n
|
|
1104
|
+
});
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
if (c.empty) continue;
|
|
1108
|
+
if (c === o) {
|
|
1109
|
+
a.push({
|
|
1110
|
+
...e,
|
|
1111
|
+
data: {
|
|
1112
|
+
...e.data,
|
|
1113
|
+
text: c.html
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
continue;
|
|
1117
|
+
}
|
|
1118
|
+
let r = {
|
|
1119
|
+
...e,
|
|
1120
|
+
id: Z(t, s, i),
|
|
1121
|
+
data: {
|
|
1122
|
+
...e.data,
|
|
1123
|
+
text: c.html
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
delete r.contentIds, a.push(r);
|
|
1127
|
+
}
|
|
1128
|
+
return o === void 0 && a.push({
|
|
1129
|
+
...e,
|
|
1130
|
+
data: {
|
|
1131
|
+
...e.data,
|
|
1132
|
+
text: ""
|
|
1133
|
+
}
|
|
1134
|
+
}), a;
|
|
1135
|
+
}, Zt = (e) => {
|
|
1136
|
+
let t = /* @__PURE__ */ new Map();
|
|
1137
|
+
for (let n of e) n.id !== void 0 && t.set(n.id, n);
|
|
1138
|
+
if (!e.some((e) => e.tool === "table")) return e;
|
|
1139
|
+
let n = /* @__PURE__ */ new Map(), r = new Set(t.keys());
|
|
1140
|
+
for (let i of e) {
|
|
1141
|
+
if (i.tool !== "paragraph" || i.id === void 0 || i.parentId === void 0 || i.parentId === null) continue;
|
|
1142
|
+
let e = t.get(i.parentId), a = i.data?.text;
|
|
1143
|
+
if (e === void 0 || e.tool !== "table" || typeof a != "string") continue;
|
|
1144
|
+
let o = qt(a);
|
|
1145
|
+
o !== null && n.set(i.id, {
|
|
1146
|
+
parentTableId: i.parentId,
|
|
1147
|
+
blocks: Xt(i, i.id, i.parentId, o, r)
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
if (n.size === 0) return e;
|
|
1151
|
+
let i = /* @__PURE__ */ new Map();
|
|
1152
|
+
for (let { parentTableId: e } of n.values()) {
|
|
1153
|
+
let n = t.get(e);
|
|
1154
|
+
if (n === void 0 || i.has(e)) continue;
|
|
1155
|
+
let r = { ...n }, a = n.data;
|
|
1156
|
+
a?.content !== void 0 && (r.data = {
|
|
1157
|
+
...n.data,
|
|
1158
|
+
content: a.content.map((e) => e.map((e) => ({
|
|
1159
|
+
...e,
|
|
1160
|
+
blocks: [...e.blocks]
|
|
1161
|
+
})))
|
|
1162
|
+
}), r.contentIds = n.contentIds === void 0 ? [] : [...n.contentIds], i.set(e, r);
|
|
1163
|
+
}
|
|
1164
|
+
for (let [e, t] of n) {
|
|
1165
|
+
let n = i.get(t.parentTableId);
|
|
1166
|
+
if (n === void 0) continue;
|
|
1167
|
+
let r = t.blocks.map((e) => e.id ?? ""), a = n.data;
|
|
1168
|
+
if (a?.content === void 0) continue;
|
|
1169
|
+
a.content.flat().forEach((t) => {
|
|
1170
|
+
let n = t.blocks.indexOf(e);
|
|
1171
|
+
n !== -1 && t.blocks.splice(n, 1, ...r);
|
|
1172
|
+
});
|
|
1173
|
+
let o = n.contentIds ?? [], s = o.indexOf(e);
|
|
1174
|
+
s === -1 ? o.push(...r.filter((t) => t !== e)) : o.splice(s, 1, ...r), n.contentIds = o;
|
|
1175
|
+
}
|
|
1176
|
+
let a = [];
|
|
1177
|
+
for (let t of e) {
|
|
1178
|
+
let e = t.id;
|
|
1179
|
+
if (e !== void 0 && i.has(e)) {
|
|
1180
|
+
a.push(i.get(e));
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
let r = e === void 0 ? void 0 : n.get(e);
|
|
1184
|
+
if (r !== void 0) {
|
|
1185
|
+
a.push(...r.blocks);
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
a.push(t);
|
|
1189
|
+
}
|
|
1190
|
+
return a;
|
|
1191
|
+
};
|
|
1192
|
+
//#endregion
|
|
1193
|
+
//#region src/cli/commands/convert-html/block-builder.ts
|
|
1194
|
+
function Qt(e) {
|
|
1195
|
+
let t = Gt(), n = [];
|
|
1196
|
+
for (let r of Array.from(e.childNodes)) en(r, n, t);
|
|
1197
|
+
return $t(n);
|
|
1198
|
+
}
|
|
1199
|
+
function $t(e) {
|
|
1200
|
+
let t = new Map(e.map((e) => [e.id, e])), n = e.map((e) => ({
|
|
1201
|
+
id: e.id,
|
|
1202
|
+
tool: e.type,
|
|
1203
|
+
data: e.data,
|
|
1204
|
+
parentId: e.parent,
|
|
1205
|
+
contentIds: e.content,
|
|
1206
|
+
isValid: !0
|
|
1207
|
+
})), r = Zt(n);
|
|
1208
|
+
if (r === n) return e;
|
|
1209
|
+
let i = new Set(n);
|
|
1210
|
+
return r.map((e) => {
|
|
1211
|
+
let n = t.get(e.id);
|
|
1212
|
+
return n !== void 0 && i.has(e) ? n : {
|
|
1213
|
+
...n ?? {
|
|
1214
|
+
id: e.id,
|
|
1215
|
+
type: e.tool,
|
|
1216
|
+
parent: e.parentId
|
|
1217
|
+
},
|
|
1218
|
+
data: e.data,
|
|
1219
|
+
...n?.content === void 0 ? {} : { content: e.contentIds }
|
|
1220
|
+
};
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
function en(e, t, n) {
|
|
1224
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
1225
|
+
let r = e.textContent?.trim() ?? "";
|
|
1226
|
+
r && t.push({
|
|
1227
|
+
id: n("paragraph"),
|
|
1228
|
+
type: "paragraph",
|
|
1229
|
+
data: { text: r }
|
|
1230
|
+
});
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return;
|
|
1234
|
+
let r = e, i = r.tagName;
|
|
1235
|
+
if (i === "P") {
|
|
1236
|
+
t.push({
|
|
1237
|
+
id: n("paragraph"),
|
|
1238
|
+
type: "paragraph",
|
|
1239
|
+
data: { text: r.innerHTML }
|
|
1240
|
+
});
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
if (/^H[1-6]$/.test(i)) {
|
|
1244
|
+
let e = Number(i[1]);
|
|
1245
|
+
t.push({
|
|
1246
|
+
id: n("header"),
|
|
1247
|
+
type: "header",
|
|
1248
|
+
data: {
|
|
1249
|
+
text: r.innerHTML,
|
|
1250
|
+
level: e
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (i === "BLOCKQUOTE") {
|
|
1256
|
+
t.push({
|
|
1257
|
+
id: n("quote"),
|
|
1258
|
+
type: "quote",
|
|
1259
|
+
data: {
|
|
1260
|
+
text: r.innerHTML,
|
|
1261
|
+
size: "default"
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
if (i === "PRE") {
|
|
1267
|
+
t.push({
|
|
1268
|
+
id: n("code"),
|
|
1269
|
+
type: "code",
|
|
1270
|
+
data: {
|
|
1271
|
+
code: r.textContent ?? "",
|
|
1272
|
+
language: "plain-text"
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (i === "HR") {
|
|
1278
|
+
t.push({
|
|
1279
|
+
id: n("divider"),
|
|
1280
|
+
type: "divider",
|
|
1281
|
+
data: {}
|
|
1282
|
+
});
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (i === "IMG") {
|
|
1286
|
+
let e = r.getAttribute("src") ?? "", i = r.getAttribute("alt") ?? "", a = on(r, "width");
|
|
1287
|
+
t.push({
|
|
1288
|
+
id: n("image"),
|
|
1289
|
+
type: "image",
|
|
1290
|
+
data: i === "" ? { url: e } : {
|
|
1291
|
+
url: e,
|
|
1292
|
+
alt: i
|
|
1293
|
+
},
|
|
1294
|
+
stretched: null,
|
|
1295
|
+
key: null,
|
|
1296
|
+
width: a
|
|
1297
|
+
});
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
if (i === "DETAILS") {
|
|
1301
|
+
let e = r.querySelector("summary"), i = e ? e.innerHTML : r.innerHTML;
|
|
1302
|
+
t.push({
|
|
1303
|
+
id: n("toggle"),
|
|
1304
|
+
type: "toggle",
|
|
1305
|
+
data: { text: i }
|
|
1306
|
+
});
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
if (i === "UL" || i === "OL") {
|
|
1310
|
+
Q(r, i === "OL" ? "ordered" : "unordered", 0, t, n);
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
if (i === "TABLE") {
|
|
1314
|
+
tn(r, t, n);
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
if (i === "ASIDE") {
|
|
1318
|
+
nn(r, t, n);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
t.push({
|
|
1322
|
+
id: n("paragraph"),
|
|
1323
|
+
type: "paragraph",
|
|
1324
|
+
data: { text: r.innerHTML }
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
function Q(e, t, n, r, i) {
|
|
1328
|
+
let a = e.getAttribute("start"), o = a ? Number(a) : null, s = Array.from(e.children).filter((e) => e.tagName === "LI");
|
|
1329
|
+
for (let [e, a] of s.entries()) {
|
|
1330
|
+
let s = a.cloneNode(!0), c = [];
|
|
1331
|
+
for (let e of Array.from(s.querySelectorAll("ul, ol"))) c.push(e.cloneNode(!0)), e.remove();
|
|
1332
|
+
let l = s.innerHTML.trim(), u = a.getAttribute("aria-level"), d = u ? Math.max(0, parseInt(u, 10) - 1) : n;
|
|
1333
|
+
r.push({
|
|
1334
|
+
id: i("list"),
|
|
1335
|
+
type: "list",
|
|
1336
|
+
data: {
|
|
1337
|
+
text: l,
|
|
1338
|
+
style: t,
|
|
1339
|
+
depth: d === 0 ? null : d,
|
|
1340
|
+
checked: null,
|
|
1341
|
+
start: e === 0 && o !== null ? o : null
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
for (let e of c) Q(e, e.tagName === "OL" ? "ordered" : "unordered", n + 1, r, i);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
function tn(e, t, n) {
|
|
1348
|
+
let r = Array.from(e.children).find((e) => e.tagName === "CAPTION")?.innerHTML.trim() ?? "";
|
|
1349
|
+
r && t.push({
|
|
1350
|
+
id: n("paragraph"),
|
|
1351
|
+
type: "paragraph",
|
|
1352
|
+
data: { text: r }
|
|
1353
|
+
}), Ae(e);
|
|
1354
|
+
let i = n("table"), a = k(e), o = dt(a, {
|
|
1355
|
+
cell: (e, t) => ({
|
|
1356
|
+
kind: "cell",
|
|
1357
|
+
el: e,
|
|
1358
|
+
...t
|
|
1359
|
+
}),
|
|
1360
|
+
covered: (e) => ({
|
|
1361
|
+
kind: "covered",
|
|
1362
|
+
origin: e
|
|
1363
|
+
}),
|
|
1364
|
+
filler: () => ({ kind: "filler" })
|
|
1365
|
+
}), s = J(e), c = o.map((e) => e.map((e) => e.kind === "covered" ? {
|
|
1366
|
+
blocks: [],
|
|
1367
|
+
mergedInto: e.origin
|
|
1368
|
+
} : e.kind === "filler" ? {
|
|
1369
|
+
blocks: [],
|
|
1370
|
+
color: null,
|
|
1371
|
+
textColor: null
|
|
1372
|
+
} : rn(e, s, i, t, n))), l = (e) => e?.tagName === "TH", u = a[0] ? A(a[0]) : [], d = a.some((e) => e.parentElement?.tagName === "THEAD") || u.length > 0 && u.every(l), f = a.length >= 2 && a.every((e) => l(A(e)[0])), p = (o[0] ?? []).map((e) => {
|
|
1373
|
+
if (e.kind !== "cell" || e.colspan > 1) return null;
|
|
1374
|
+
let t = parseInt($(e.el, "width") ?? "", 10);
|
|
1375
|
+
return isNaN(t) ? null : t;
|
|
1376
|
+
}), m = {
|
|
1377
|
+
id: i,
|
|
1378
|
+
type: "table",
|
|
1379
|
+
data: {
|
|
1380
|
+
withHeadings: d,
|
|
1381
|
+
withHeadingColumn: f,
|
|
1382
|
+
content: c,
|
|
1383
|
+
...p.some((e) => e !== null) ? { colWidths: p } : {}
|
|
1384
|
+
}
|
|
1385
|
+
}, h = t.findIndex((e) => e.parent === i);
|
|
1386
|
+
h >= 0 ? t.splice(h, 0, m) : t.push(m);
|
|
1387
|
+
}
|
|
1388
|
+
function nn(e, t, r) {
|
|
1389
|
+
let a = r("callout"), o = $(e, "background-color"), s = o && !n(o) && !i(o) ? g(o, "bg") : null, c = [];
|
|
1390
|
+
for (let n of Array.from(e.childNodes)) {
|
|
1391
|
+
let e = an(n, a, t, r);
|
|
1392
|
+
e && c.push(e);
|
|
1393
|
+
}
|
|
1394
|
+
let l = t.findIndex((e) => e.parent === a), u = {
|
|
1395
|
+
id: a,
|
|
1396
|
+
type: "callout",
|
|
1397
|
+
data: {
|
|
1398
|
+
emoji: "💡",
|
|
1399
|
+
backgroundColor: s
|
|
1400
|
+
},
|
|
1401
|
+
content: c
|
|
1402
|
+
};
|
|
1403
|
+
l >= 0 ? t.splice(l, 0, u) : t.push(u);
|
|
1404
|
+
}
|
|
1405
|
+
function rn(e, t, n, r, i) {
|
|
1406
|
+
let a = e.el, { color: o, textColor: s, placement: c } = xt(a, t), l = a.innerHTML.trim();
|
|
1407
|
+
return {
|
|
1408
|
+
blocks: l ? Me(l).map((e) => {
|
|
1409
|
+
let t = i(e.tool);
|
|
1410
|
+
return r.push({
|
|
1411
|
+
id: t,
|
|
1412
|
+
type: e.tool,
|
|
1413
|
+
parent: n,
|
|
1414
|
+
data: e.data
|
|
1415
|
+
}), t;
|
|
1416
|
+
}) : [],
|
|
1417
|
+
color: o === void 0 ? null : g(o, "bg"),
|
|
1418
|
+
textColor: s === void 0 ? null : g(s, "text"),
|
|
1419
|
+
...c === void 0 ? {} : { placement: c },
|
|
1420
|
+
...e.colspan > 1 ? { colspan: e.colspan } : {},
|
|
1421
|
+
...e.rowspan > 1 ? { rowspan: e.rowspan } : {}
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
function an(e, t, n, r) {
|
|
1425
|
+
if (e.nodeType === Node.ELEMENT_NODE) {
|
|
1426
|
+
let i = e, a = r("paragraph");
|
|
1427
|
+
return n.push({
|
|
1428
|
+
id: a,
|
|
1429
|
+
type: "paragraph",
|
|
1430
|
+
parent: t,
|
|
1431
|
+
data: { text: i.innerHTML }
|
|
1432
|
+
}), a;
|
|
1433
|
+
}
|
|
1434
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
1435
|
+
let i = e.textContent?.trim() ?? "";
|
|
1436
|
+
if (!i) return null;
|
|
1437
|
+
let a = r("paragraph");
|
|
1438
|
+
return n.push({
|
|
1439
|
+
id: a,
|
|
1440
|
+
type: "paragraph",
|
|
1441
|
+
parent: t,
|
|
1442
|
+
data: { text: i }
|
|
1443
|
+
}), a;
|
|
1444
|
+
}
|
|
1445
|
+
return null;
|
|
1446
|
+
}
|
|
1447
|
+
function on(e, t) {
|
|
1448
|
+
let n = $(e, t);
|
|
1449
|
+
if (!n) return null;
|
|
1450
|
+
let r = parseInt(n, 10);
|
|
1451
|
+
return isNaN(r) ? null : r;
|
|
1452
|
+
}
|
|
1453
|
+
function $(e, t) {
|
|
1454
|
+
let n = e.getAttribute("style");
|
|
1455
|
+
if (!n) return null;
|
|
1456
|
+
let r = RegExp(`(?<![\\-a-z])${t}\\s*:\\s*([^;]+)`).exec(n);
|
|
1457
|
+
return r ? r[1].trim() : null;
|
|
1458
|
+
}
|
|
1459
|
+
//#endregion
|
|
1460
|
+
export { G as a, St as i, Vt as n, He as o, Ct as r, w as s, Qt as t };
|