@jackuait/blok-cli 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,673 @@
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
+ //#endregion
137
+ //#region src/components/utils/color-mapping.ts
138
+ function a(e, t, n) {
139
+ let r = t / 100, i = n / 100;
140
+ if (r === 0) {
141
+ let e = Math.round(i * 255);
142
+ return [
143
+ e,
144
+ e,
145
+ e
146
+ ];
147
+ }
148
+ let a = (e) => e < 0 ? e + 1 : e > 1 ? e - 1 : e, o = (e, t, n) => {
149
+ let r = a(n);
150
+ return r < 1 / 6 ? e + (t - e) * 6 * r : r < 1 / 2 ? t : r < 2 / 3 ? e + (t - e) * (2 / 3 - r) * 6 : e;
151
+ }, s = i < .5 ? i * (1 + r) : i + r - i * r, c = 2 * i - s, l = e / 360;
152
+ return [
153
+ Math.round(o(c, s, l + 1 / 3) * 255),
154
+ Math.round(o(c, s, l) * 255),
155
+ Math.round(o(c, s, l - 1 / 3) * 255)
156
+ ];
157
+ }
158
+ function o(e) {
159
+ let t = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);
160
+ if (t) return [
161
+ parseInt(t[1], 16),
162
+ parseInt(t[2], 16),
163
+ parseInt(t[3], 16)
164
+ ];
165
+ let n = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})[0-9a-f]{2}$/i.exec(e);
166
+ if (n) return [
167
+ parseInt(n[1], 16),
168
+ parseInt(n[2], 16),
169
+ parseInt(n[3], 16)
170
+ ];
171
+ let r = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e);
172
+ if (r) return [
173
+ parseInt(r[1] + r[1], 16),
174
+ parseInt(r[2] + r[2], 16),
175
+ parseInt(r[3] + r[3], 16)
176
+ ];
177
+ let i = /^#([0-9a-f])([0-9a-f])([0-9a-f])[0-9a-f]$/i.exec(e);
178
+ if (i) return [
179
+ parseInt(i[1] + i[1], 16),
180
+ parseInt(i[2] + i[2], 16),
181
+ parseInt(i[3] + i[3], 16)
182
+ ];
183
+ let o = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
184
+ if (o) return [
185
+ Number(o[1]),
186
+ Number(o[2]),
187
+ Number(o[3])
188
+ ];
189
+ let s = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
190
+ return s ? a(Number(s[1]), Number(s[2]), Number(s[3])) : null;
191
+ }
192
+ var s = .1;
193
+ function c(e) {
194
+ 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;
195
+ if (i === a) return [
196
+ 0,
197
+ 0,
198
+ o
199
+ ];
200
+ let s = i - a, c = o > .5 ? s / (2 - i - a) : s / (i + a);
201
+ return [
202
+ ((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,
203
+ c,
204
+ o
205
+ ];
206
+ }
207
+ function l(e, t) {
208
+ let n = e[1] < s, r = t[1] < s;
209
+ if (n && r) {
210
+ let n = Math.abs(e[2] - t[2]);
211
+ return n * n;
212
+ }
213
+ if (n !== r) return 1e3;
214
+ let i = Math.abs(e[0] - t[0]), a = Math.min(i, 360 - i) / 180, o = Math.abs(e[1] - t[1]), c = Math.abs(e[2] - t[2]);
215
+ return 8 * a * a + 1 * o * o + 1 * c * c;
216
+ }
217
+ function u(t, r) {
218
+ if (r === "bg" && (n(t) || i(t))) return t;
219
+ let a = o(t);
220
+ if (a === null) return t;
221
+ let s = c(a);
222
+ return e.reduce((e, t) => {
223
+ let n = o(t[r]);
224
+ if (n === null) return e;
225
+ let i = l(s, c(n));
226
+ return i < e.distance ? {
227
+ color: t[r],
228
+ distance: i
229
+ } : e;
230
+ }, {
231
+ color: t,
232
+ distance: Infinity
233
+ }).color;
234
+ }
235
+ function d(r, a) {
236
+ if (a === "bg" && (n(r) || i(r))) return null;
237
+ let s = o(r);
238
+ if (s === null) return null;
239
+ let u = c(s);
240
+ return [...e, ...t].reduce((e, t) => {
241
+ let n = o(t[a]);
242
+ if (n === null) return e;
243
+ let r = l(u, c(n));
244
+ return e === null || r < e.distance ? {
245
+ name: t.name,
246
+ distance: r
247
+ } : e;
248
+ }, null)?.name ?? null;
249
+ }
250
+ //#endregion
251
+ //#region src/cli/commands/convert-html/preprocessor.ts
252
+ function f(e) {
253
+ p(e), _(e), x(e), C(e), w(e), E(e);
254
+ }
255
+ function p(e) {
256
+ let t = e.ownerDocument;
257
+ for (let n of Array.from(e.querySelectorAll("div[style]"))) {
258
+ if (n.closest("table")) continue;
259
+ let e = b(n);
260
+ if (!e || v(e)) continue;
261
+ let r = t.createElement("aside");
262
+ r.style.backgroundColor = e, r.append(...Array.from(n.childNodes)), m(r), h(r), n.replaceWith(r);
263
+ }
264
+ }
265
+ function m(e) {
266
+ for (;;) {
267
+ let t = Array.from(e.querySelectorAll(":scope > div")).filter((e) => !e.getAttribute("style") && !e.getAttribute("class"));
268
+ if (t.length === 0) break;
269
+ for (let e of t) e.replaceWith(...Array.from(e.childNodes));
270
+ }
271
+ }
272
+ function h(e) {
273
+ for (let t of Array.from(e.querySelectorAll("p"))) {
274
+ let e = t.lastElementChild;
275
+ e?.tagName === "BR" && e.remove();
276
+ }
277
+ }
278
+ var g = 250;
279
+ function _(e) {
280
+ let t = e.querySelectorAll("[style*=\"background-color\"]");
281
+ for (let e of Array.from(t)) v(e.style.backgroundColor) && (e.style.removeProperty("background-color"), e.getAttribute("style")?.trim() === "" && e.removeAttribute("style"), y(e) && e.replaceWith(...Array.from(e.childNodes)));
282
+ }
283
+ function v(e) {
284
+ if (!e) return !1;
285
+ let t = e.replace(/\s/g, "").toLowerCase();
286
+ if (t === "transparent") return !0;
287
+ let n = t.match(/^rgba?\((\d+),(\d+),(\d+)(?:,([^)]+))?\)$/);
288
+ if (!n) return !1;
289
+ if ((n[4] === void 0 ? 1 : parseFloat(n[4])) === 0) return !0;
290
+ let r = parseInt(n[1], 10), i = parseInt(n[2], 10), a = parseInt(n[3], 10);
291
+ return r >= g && i >= g && a >= g;
292
+ }
293
+ function y(e) {
294
+ return e.attributes.length > 0 ? !1 : (e.textContent ?? "").replace(/[\s\u00A0]/g, "").length === 0;
295
+ }
296
+ function b(e) {
297
+ if (e.style.backgroundColor) return e.style.backgroundColor;
298
+ let t = (e.getAttribute("style") ?? "").match(/background:\s*([^;]+)/i);
299
+ if (t) {
300
+ let e = t[1].trim().match(/^(rgb[a]?\([^)]+\)|#[0-9a-fA-F]{3,8}|[a-z]+)$/i);
301
+ if (e) return e[1];
302
+ }
303
+ return "";
304
+ }
305
+ function x(e) {
306
+ for (let t of Array.from(e.querySelectorAll("td, th"))) {
307
+ let e = t.querySelectorAll("p");
308
+ if (e.length !== 0) {
309
+ for (let t of Array.from(e)) S(t);
310
+ A(t);
311
+ }
312
+ }
313
+ }
314
+ function S(e) {
315
+ if (e.innerHTML.trim() === "" || e.innerHTML.trim() === "&nbsp;") {
316
+ e.remove();
317
+ return;
318
+ }
319
+ let t = e.ownerDocument, n = t.createDocumentFragment();
320
+ n.append(...Array.from(e.childNodes)), n.append(t.createElement("br")), e.replaceWith(n);
321
+ }
322
+ function C(e) {
323
+ for (let t of Array.from(e.querySelectorAll("p"))) t.closest("td") || t.closest("th") || (t.textContent ?? "").replace(/[\s\u00A0]/g, "").length === 0 && t.remove();
324
+ }
325
+ function w(e) {
326
+ let t = e.ownerDocument;
327
+ for (let n of Array.from(e.querySelectorAll("del, strike"))) {
328
+ let e = t.createElement("s");
329
+ e.append(...Array.from(n.childNodes)), n.replaceWith(e);
330
+ }
331
+ }
332
+ var T = /^[\u2022\u00B7][\s\u00A0]*|^-\s/;
333
+ function E(e) {
334
+ let t = e.ownerDocument, n = O(e);
335
+ for (let e of n) {
336
+ let n = t.createElement("ul");
337
+ e[0].before(n);
338
+ for (let t of e) D(t, n);
339
+ }
340
+ }
341
+ function D(e, t) {
342
+ let n = e.ownerDocument.createElement("li"), r = j(e);
343
+ r && (r.textContent = (r.textContent ?? "").replace(T, "")), n.append(...Array.from(e.childNodes)), t.appendChild(n), e.remove();
344
+ }
345
+ function O(e) {
346
+ let t = [], n = Array.from(e.childNodes);
347
+ for (let e of n) {
348
+ if (e.nodeType !== Node.ELEMENT_NODE) continue;
349
+ let n = e;
350
+ if (!(n.tagName === "P" && T.test(n.textContent ?? ""))) continue;
351
+ let r = t[t.length - 1], i = k(n);
352
+ r && i !== null && r[r.length - 1] === i ? r.push(n) : t.push([n]);
353
+ }
354
+ return t;
355
+ }
356
+ function k(e) {
357
+ let t = e.previousSibling;
358
+ return t && t.nodeType === Node.ELEMENT_NODE ? t : null;
359
+ }
360
+ function A(e) {
361
+ for (;;) {
362
+ let t = e.lastChild;
363
+ if (!t) break;
364
+ let n = t.nodeType === Node.ELEMENT_NODE && t.tagName === "BR", r = t.nodeType === Node.TEXT_NODE && t.textContent?.trim() === "";
365
+ if (!n && !r) break;
366
+ t.remove();
367
+ }
368
+ }
369
+ function j(e) {
370
+ if (e.nodeType === Node.TEXT_NODE) return e;
371
+ for (let t of Array.from(e.childNodes)) {
372
+ let e = j(t);
373
+ if (e) return e;
374
+ }
375
+ return null;
376
+ }
377
+ //#endregion
378
+ //#region src/cli/commands/convert-html/sanitizer.ts
379
+ var M = {
380
+ B: !0,
381
+ STRONG: !0,
382
+ I: !0,
383
+ EM: !0,
384
+ A: new Set(["href"]),
385
+ S: !0,
386
+ U: !0,
387
+ CODE: !0,
388
+ MARK: new Set(["style"]),
389
+ BR: !0,
390
+ P: !0,
391
+ H1: !0,
392
+ H2: !0,
393
+ H3: !0,
394
+ H4: !0,
395
+ H5: !0,
396
+ H6: !0,
397
+ UL: !0,
398
+ OL: !0,
399
+ LI: new Set(["aria-level"]),
400
+ TABLE: !0,
401
+ THEAD: !0,
402
+ TBODY: !0,
403
+ TR: !0,
404
+ TD: new Set(["style"]),
405
+ TH: new Set(["style"]),
406
+ BLOCKQUOTE: !0,
407
+ PRE: !0,
408
+ HR: !0,
409
+ ASIDE: new Set(["style"]),
410
+ DETAILS: !0,
411
+ SUMMARY: !0,
412
+ IMG: new Set(["src", "style"])
413
+ };
414
+ function N(e) {
415
+ I(e);
416
+ }
417
+ function P(e) {
418
+ let t = Array.from(e.childNodes);
419
+ for (let n of t) e.before(n);
420
+ return e.remove(), t.filter((e) => e.nodeType === e.ELEMENT_NODE);
421
+ }
422
+ function F(e, t) {
423
+ for (let n of Array.from(e.attributes)) (t === !0 || !t.has(n.name)) && e.removeAttribute(n.name);
424
+ }
425
+ function I(e) {
426
+ let t = Array.from(e.childNodes);
427
+ for (let e of t) {
428
+ if (e.nodeType !== e.ELEMENT_NODE) continue;
429
+ let n = e, r = M[n.tagName];
430
+ if (r === void 0) {
431
+ t.push(...P(n));
432
+ continue;
433
+ }
434
+ F(n, r), I(n);
435
+ }
436
+ }
437
+ //#endregion
438
+ //#region src/cli/commands/convert-html/id-generator.ts
439
+ function L() {
440
+ let e = /* @__PURE__ */ new Map();
441
+ return (t) => {
442
+ let n = (e.get(t) ?? 0) + 1;
443
+ return e.set(t, n), `${t}-${n}`;
444
+ };
445
+ }
446
+ //#endregion
447
+ //#region src/cli/commands/convert-html/block-builder.ts
448
+ function R(e) {
449
+ let t = L(), n = [];
450
+ for (let r of Array.from(e.childNodes)) z(r, n, t);
451
+ return n;
452
+ }
453
+ function z(e, t, n) {
454
+ if (e.nodeType === Node.TEXT_NODE) {
455
+ let r = e.textContent?.trim() ?? "";
456
+ r && t.push({
457
+ id: n("paragraph"),
458
+ type: "paragraph",
459
+ data: { text: r }
460
+ });
461
+ return;
462
+ }
463
+ if (e.nodeType !== Node.ELEMENT_NODE) return;
464
+ let r = e, i = r.tagName;
465
+ if (i === "P") {
466
+ t.push({
467
+ id: n("paragraph"),
468
+ type: "paragraph",
469
+ data: { text: r.innerHTML }
470
+ });
471
+ return;
472
+ }
473
+ if (/^H[1-6]$/.test(i)) {
474
+ let e = Number(i[1]);
475
+ t.push({
476
+ id: n("header"),
477
+ type: "header",
478
+ data: {
479
+ text: r.innerHTML,
480
+ level: e
481
+ }
482
+ });
483
+ return;
484
+ }
485
+ if (i === "BLOCKQUOTE") {
486
+ t.push({
487
+ id: n("quote"),
488
+ type: "quote",
489
+ data: {
490
+ text: r.innerHTML,
491
+ size: "default"
492
+ }
493
+ });
494
+ return;
495
+ }
496
+ if (i === "PRE") {
497
+ t.push({
498
+ id: n("code"),
499
+ type: "code",
500
+ data: {
501
+ code: r.textContent ?? "",
502
+ language: "plain-text"
503
+ }
504
+ });
505
+ return;
506
+ }
507
+ if (i === "HR") {
508
+ t.push({
509
+ id: n("divider"),
510
+ type: "divider",
511
+ data: {}
512
+ });
513
+ return;
514
+ }
515
+ if (i === "IMG") {
516
+ let e = r.getAttribute("src") ?? "", i = G(r, "width");
517
+ t.push({
518
+ id: n("image"),
519
+ type: "image",
520
+ data: { url: e },
521
+ stretched: null,
522
+ key: null,
523
+ width: i
524
+ });
525
+ return;
526
+ }
527
+ if (i === "DETAILS") {
528
+ let e = r.querySelector("summary"), i = e ? e.innerHTML : r.innerHTML;
529
+ t.push({
530
+ id: n("toggle"),
531
+ type: "toggle",
532
+ data: { text: i }
533
+ });
534
+ return;
535
+ }
536
+ if (i === "UL" || i === "OL") {
537
+ B(r, i === "OL" ? "ordered" : "unordered", 0, t, n);
538
+ return;
539
+ }
540
+ if (i === "TABLE") {
541
+ V(r, t, n);
542
+ return;
543
+ }
544
+ if (i === "ASIDE") {
545
+ H(r, t, n);
546
+ return;
547
+ }
548
+ t.push({
549
+ id: n("paragraph"),
550
+ type: "paragraph",
551
+ data: { text: r.innerHTML }
552
+ });
553
+ }
554
+ function B(e, t, n, r, i) {
555
+ let a = e.getAttribute("start"), o = a ? Number(a) : null, s = Array.from(e.children).filter((e) => e.tagName === "LI");
556
+ for (let [e, a] of s.entries()) {
557
+ let s = a.cloneNode(!0), c = [];
558
+ for (let e of Array.from(s.querySelectorAll("ul, ol"))) c.push(e.cloneNode(!0)), e.remove();
559
+ let l = s.innerHTML.trim(), u = a.getAttribute("aria-level"), d = u ? Math.max(0, parseInt(u, 10) - 1) : n;
560
+ r.push({
561
+ id: i("list"),
562
+ type: "list",
563
+ data: {
564
+ text: l,
565
+ style: t,
566
+ depth: d === 0 ? null : d,
567
+ checked: null,
568
+ start: e === 0 && o !== null ? o : null
569
+ }
570
+ });
571
+ for (let e of c) B(e, e.tagName === "OL" ? "ordered" : "unordered", n + 1, r, i);
572
+ }
573
+ }
574
+ function V(e, t, n) {
575
+ let r = n("table"), i = Array.from(e.querySelectorAll("tr")), a = [];
576
+ for (let e of i) {
577
+ let i = Array.from(e.querySelectorAll("td, th")).map((e) => U(e, r, t, n));
578
+ a.push(i);
579
+ }
580
+ let o = i[0] ? Array.from(i[0].querySelectorAll("td, th")) : [], s = o.some((e) => e.tagName === "TH"), c = o.map((e) => {
581
+ let t = K(e, "width");
582
+ if (t) {
583
+ let e = parseInt(t, 10);
584
+ return isNaN(e) ? null : e;
585
+ }
586
+ return null;
587
+ }), l = {
588
+ id: r,
589
+ type: "table",
590
+ data: {
591
+ withHeadings: s,
592
+ withHeadingColumn: !1,
593
+ content: a,
594
+ ...c.some((e) => e !== null) ? { colWidths: c } : {}
595
+ }
596
+ }, u = t.findIndex((e) => e.parent === r);
597
+ u >= 0 ? t.splice(u, 0, l) : t.push(l);
598
+ }
599
+ function H(e, t, r) {
600
+ let a = r("callout"), o = K(e, "background-color"), s = o && !n(o) && !i(o) ? d(o, "bg") : null, c = [];
601
+ for (let n of Array.from(e.childNodes)) {
602
+ let e = W(n, a, t, r);
603
+ e && c.push(e);
604
+ }
605
+ let l = t.findIndex((e) => e.parent === a), u = {
606
+ id: a,
607
+ type: "callout",
608
+ data: {
609
+ emoji: "💡",
610
+ backgroundColor: s
611
+ },
612
+ content: c
613
+ };
614
+ l >= 0 ? t.splice(l, 0, u) : t.push(u);
615
+ }
616
+ function U(e, t, r, a) {
617
+ let o = e.innerHTML.trim();
618
+ if (!o) return {
619
+ blocks: [],
620
+ color: null,
621
+ textColor: null
622
+ };
623
+ let s = a("paragraph");
624
+ r.push({
625
+ id: s,
626
+ type: "paragraph",
627
+ parent: t,
628
+ data: { text: o }
629
+ });
630
+ let c = K(e, "background-color"), l = K(e, "color"), u = c && !n(c) && !i(c) ? d(c, "bg") : null;
631
+ return {
632
+ blocks: [s],
633
+ color: u,
634
+ textColor: l ? d(l, "text") : null
635
+ };
636
+ }
637
+ function W(e, t, n, r) {
638
+ if (e.nodeType === Node.ELEMENT_NODE) {
639
+ let i = e, a = r("paragraph");
640
+ return n.push({
641
+ id: a,
642
+ type: "paragraph",
643
+ parent: t,
644
+ data: { text: i.innerHTML }
645
+ }), a;
646
+ }
647
+ if (e.nodeType === Node.TEXT_NODE) {
648
+ let i = e.textContent?.trim() ?? "";
649
+ if (!i) return null;
650
+ let a = r("paragraph");
651
+ return n.push({
652
+ id: a,
653
+ type: "paragraph",
654
+ parent: t,
655
+ data: { text: i }
656
+ }), a;
657
+ }
658
+ return null;
659
+ }
660
+ function G(e, t) {
661
+ let n = K(e, t);
662
+ if (!n) return null;
663
+ let r = parseInt(n, 10);
664
+ return isNaN(r) ? null : r;
665
+ }
666
+ function K(e, t) {
667
+ let n = e.getAttribute("style");
668
+ if (!n) return null;
669
+ let r = RegExp(`(?<![\\-a-z])${t}\\s*:\\s*([^;]+)`).exec(n);
670
+ return r ? r[1].trim() : null;
671
+ }
672
+ //#endregion
673
+ export { i as a, u as i, N as n, n as o, f as r, R as t };
package/dist/cli.mjs CHANGED
@@ -41,14 +41,14 @@ var t = "# Migrating from EditorJS to Blok\n\nThis guide covers the breaking cha
41
41
  case "convert-html": {
42
42
  let e = new (await (import("jsdom"))).JSDOM("");
43
43
  globalThis.DOMParser = e.window.DOMParser, globalThis.Node = e.window.Node;
44
- let { convertHtml: t } = await import("./convert-html-DzNIWUBh.mjs");
44
+ let { convertHtml: t } = await import("./convert-html-DPcdNESm.mjs");
45
45
  r(t((await import("node:fs")).readFileSync("/dev/stdin", "utf-8")), s);
46
46
  break;
47
47
  }
48
48
  case "convert-gdocs": {
49
49
  let e = new (await (import("jsdom"))).JSDOM("");
50
50
  globalThis.DOMParser = e.window.DOMParser, globalThis.Node = e.window.Node, globalThis.document = e.window.document;
51
- let { convertGdocs: t } = await import("./convert-gdocs-B1oeKXdN.mjs");
51
+ let { convertGdocs: t } = await import("./convert-gdocs-CE9U-ffM.mjs");
52
52
  r(t((await import("node:fs")).readFileSync("/dev/stdin", "utf-8")), s);
53
53
  break;
54
54
  }
@@ -0,0 +1,165 @@
1
+ import { a as e, i as t, n, o as r, r as i, t as a } from "./block-builder-B_eFe3eS.mjs";
2
+ //#region src/components/modules/paste/google-docs-preprocessor.ts
3
+ function o(e) {
4
+ let t = document.createElement("div");
5
+ t.innerHTML = e;
6
+ let n = p(t);
7
+ return w(t, n), n && (E(t), f(t)), t.innerHTML;
8
+ }
9
+ function s(e, t) {
10
+ let n = e.parentElement;
11
+ return n === null ? null : n === t ? e : s(n, t);
12
+ }
13
+ function c(e, t, n) {
14
+ let r = e.cloneNode(!1), i = [];
15
+ for (let n of Array.from(e.childNodes)) {
16
+ if (n === t) break;
17
+ i.push(n);
18
+ }
19
+ return i.forEach((e) => r.appendChild(e)), n !== null && r.appendChild(n), r.childNodes.length > 0 ? r : null;
20
+ }
21
+ function l(e, t, n) {
22
+ let r = e.cloneNode(!1), i = Array.from(e.childNodes), a = i.findIndex((e) => e === t), o = i.slice(a + 1);
23
+ return n !== null && r.appendChild(n), o.forEach((e) => r.appendChild(e)), r.childNodes.length > 0 ? r : null;
24
+ }
25
+ function u(e, t) {
26
+ let n = (e, r, i) => {
27
+ if (e === t) return {
28
+ before: r,
29
+ after: i
30
+ };
31
+ let a = e.parentElement;
32
+ return a === null ? {
33
+ before: r,
34
+ after: i
35
+ } : n(a, c(a, e, r), l(a, e, i));
36
+ };
37
+ return n(e, null, null);
38
+ }
39
+ function d(e, t) {
40
+ let n = e.parentElement;
41
+ return n === null || n === t ? !1 : n.tagName === "TABLE" ? !0 : d(n, t);
42
+ }
43
+ function f(e) {
44
+ let t = Array.from(e.querySelectorAll("img"));
45
+ for (let n of t) {
46
+ if (d(n, e)) continue;
47
+ let t = s(n, e);
48
+ if (!t) continue;
49
+ let { before: r, after: i } = u(n, t), a = document.createDocumentFragment();
50
+ r && a.appendChild(r), a.appendChild(n), i && a.appendChild(i), t.replaceWith(a);
51
+ }
52
+ }
53
+ function p(e) {
54
+ let t = e.querySelector("b[id^=\"docs-internal-guid-\"]");
55
+ if (!t) return !1;
56
+ let n = document.createDocumentFragment();
57
+ for (; t.firstChild;) n.appendChild(t.firstChild);
58
+ return t.replaceWith(n), !0;
59
+ }
60
+ function m(e, t, n) {
61
+ return e ? `background-color: ${n}` : t ? "background-color: transparent" : "";
62
+ }
63
+ function h(e) {
64
+ let t = e.replace(/\s/g, "");
65
+ return t === "rgb(0,0,0)" || t === "#000000";
66
+ }
67
+ function g(e) {
68
+ let t = e.replace(/\s/g, "").toLowerCase(), n = /^rgba?\((\d+),(\d+),(\d+)(?:,[\d.]+)?\)$/.exec(t);
69
+ if (n) {
70
+ let e = parseInt(n[1], 10) / 255, t = parseInt(n[2], 10) / 255, r = parseInt(n[3], 10) / 255;
71
+ return .2126 * e + .7152 * t + .0722 * r;
72
+ }
73
+ let r = /^hsla?\(([\d.]+),([\d.]+)%,([\d.]+)%(?:,[\d.]+)?\)$/.exec(t);
74
+ if (r) {
75
+ let e = parseFloat(r[1]) / 360, t = parseFloat(r[2]) / 100, n = parseFloat(r[3]) / 100;
76
+ if (t === 0) return .2126 * n + .7152 * n + .0722 * n;
77
+ let i = n < .5 ? n * (1 + t) : n + t - n * t, a = 2 * n - i, o = (e) => {
78
+ let t = e < 0 ? e + 1 : e > 1 ? e - 1 : e;
79
+ return t < 1 / 6 ? a + (i - a) * 6 * t : t < 1 / 2 ? i : t < 2 / 3 ? a + (i - a) * (2 / 3 - t) * 6 : a;
80
+ }, s = o(e + 1 / 3), c = o(e), l = o(e - 1 / 3);
81
+ return .2126 * s + .7152 * c + .0722 * l;
82
+ }
83
+ let i = /^#([0-9a-f]{6}|[0-9a-f]{3})$/.exec(t);
84
+ if (i) {
85
+ let e = i[1], t = e.length === 3 ? [
86
+ e[0] + e[0],
87
+ e[1] + e[1],
88
+ e[2] + e[2]
89
+ ] : [
90
+ e.substring(0, 2),
91
+ e.substring(2, 4),
92
+ e.substring(4, 6)
93
+ ], n = parseInt(t[0], 16) / 255, r = parseInt(t[1], 16) / 255, a = parseInt(t[2], 16) / 255;
94
+ return .2126 * n + .7152 * r + .0722 * a;
95
+ }
96
+ return -1;
97
+ }
98
+ var _ = r, v = e;
99
+ function y(e) {
100
+ let t = g(e);
101
+ return t >= 0 && t > .75;
102
+ }
103
+ function b(e, n, r, i, a) {
104
+ if (!n && !r) return e;
105
+ let o = n && i !== void 0 ? t(i, "text") : "", s = r && a !== void 0 ? t(a, "bg") : "", c = [n ? `color: ${o}` : "", m(r, n, s)].filter(Boolean).join("; ");
106
+ return c ? `<mark style="${c};">${e}</mark>` : e;
107
+ }
108
+ var x = new Set([
109
+ "H1",
110
+ "H2",
111
+ "H3",
112
+ "H4",
113
+ "H5",
114
+ "H6"
115
+ ]);
116
+ function S(e) {
117
+ let t = e.parentElement;
118
+ return t === null ? !1 : x.has(t.tagName) ? !0 : S(t);
119
+ }
120
+ function C(e, t) {
121
+ let n = e.getAttribute("style") ?? "", r = /font-weight\s*:\s*(700|bold)/i.test(n) && !S(e), i = /font-style\s*:\s*italic/i.test(n), a = /(?<![a-z-])color\s*:\s*([^;]+)/i.exec(n), o = /background-color\s*:\s*([^;]+)/i.exec(n), s = a?.[1]?.trim(), c = o?.[1]?.trim(), l = t ? s !== void 0 && !h(s) : s !== void 0 && !h(s) && !y(s), u = c !== void 0 && c !== "transparent" && !_(c) && !v(c);
122
+ if (!r && !i && !l && !u) return null;
123
+ let d = b(e.innerHTML, l, u, s, c), f = i ? `<i>${d}</i>` : d;
124
+ return r ? `<b>${f}</b>` : f;
125
+ }
126
+ function w(e, t) {
127
+ for (let n of Array.from(e.querySelectorAll("span[style]"))) {
128
+ let e = C(n, t);
129
+ e !== null && n.replaceWith(document.createRange().createContextualFragment(e));
130
+ }
131
+ t && T(e);
132
+ }
133
+ function T(e) {
134
+ for (let n of Array.from(e.querySelectorAll("a[style]"))) {
135
+ let e = n.getAttribute("style") ?? "", r = /(?<![a-z-])color\s*:\s*([^;]+)/i.exec(e), i = /background-color\s*:\s*([^;]+)/i.exec(e), a = r?.[1]?.trim(), o = i?.[1]?.trim(), s = a !== void 0 && !h(a) && a !== "inherit", c = o !== void 0 && o !== "transparent" && o !== "inherit";
136
+ if (!s && !c) continue;
137
+ let l = s ? t(a, "text") : "", u = c ? t(o, "bg") : "", d = [s ? `color: ${l}` : "", m(c, s, u)].filter(Boolean).join("; "), f = n;
138
+ f.innerHTML = `<mark style="${d};">${f.innerHTML}</mark>`, f.style.removeProperty("color"), f.style.removeProperty("background-color");
139
+ }
140
+ }
141
+ function E(e) {
142
+ for (let t of Array.from(e.querySelectorAll("td, th"))) {
143
+ let e = t.querySelectorAll("p");
144
+ if (e.length !== 0) {
145
+ for (let t of Array.from(e)) {
146
+ let e = document.createRange().createContextualFragment(t.innerHTML + "<br>");
147
+ t.replaceWith(e);
148
+ }
149
+ t.innerHTML = t.innerHTML.replace(/(<br\s*\/?>|\s)+$/i, "");
150
+ }
151
+ }
152
+ }
153
+ //#endregion
154
+ //#region src/cli/commands/convert-gdocs/index.ts
155
+ function D(e) {
156
+ let t = o(e), r = new DOMParser().parseFromString(t, "text/html").body;
157
+ i(r), n(r);
158
+ let s = {
159
+ version: "0.13.1",
160
+ blocks: a(r)
161
+ };
162
+ return JSON.stringify(s);
163
+ }
164
+ //#endregion
165
+ export { D as convertGdocs };
@@ -0,0 +1,13 @@
1
+ import { n as e, r as t, t as n } from "./block-builder-B_eFe3eS.mjs";
2
+ //#region src/cli/commands/convert-html/index.ts
3
+ function r(r) {
4
+ let i = new DOMParser().parseFromString(r, "text/html").body;
5
+ t(i), e(i);
6
+ let a = {
7
+ version: "0.13.1",
8
+ blocks: n(i)
9
+ };
10
+ return JSON.stringify(a);
11
+ }
12
+ //#endregion
13
+ export { r as convertHtml };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackuait/blok-cli",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "CLI tools for Blok — convert HTML to Blok JSON, generate migration guides",
5
5
  "bin": {
6
6
  "blok-cli": "bin/blok-cli.mjs"