@jackuait/blok 0.10.0-beta.13 → 0.10.0-beta.15
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/bin/convert-html.mjs +3 -0
- package/dist/blok.mjs +2 -2
- package/dist/chunks/{blok-uTkAJyAg.mjs → blok-1213fGsk.mjs} +275 -260
- package/dist/chunks/{constants-NpHRgdEj.mjs → constants-Cr7GEExc.mjs} +1 -1
- package/dist/chunks/{tools-bN22O_3E.mjs → tools-DBEfU2dP.mjs} +1 -1
- package/dist/convert-html.mjs +631 -0
- package/dist/full.mjs +3 -3
- package/dist/react.mjs +2 -2
- package/dist/tools.mjs +2 -2
- package/package.json +3 -2
- package/src/cli/commands/convert-html/block-builder.ts +382 -0
- package/src/cli/commands/convert-html/id-generator.ts +11 -0
- package/src/cli/commands/convert-html/index.ts +21 -0
- package/src/cli/commands/convert-html/preprocessor.ts +348 -0
- package/src/cli/commands/convert-html/sanitizer.ts +94 -0
- package/src/cli/commands/convert-html/standalone.ts +20 -0
- package/src/cli/commands/convert-html/types.ts +15 -0
- package/src/cli/index.ts +30 -5
- package/src/components/modules/toolbar/index.ts +20 -2
- package/src/components/modules/uiControllers/controllers/blockHover.ts +44 -1
- package/dist/cli.mjs +0 -37
|
@@ -130,7 +130,7 @@ var a = {
|
|
|
130
130
|
RIGHT: 2,
|
|
131
131
|
BACKWARD: 3,
|
|
132
132
|
FORWARD: 4
|
|
133
|
-
}, l = () => "0.10.0-beta.
|
|
133
|
+
}, l = () => "0.10.0-beta.15", u = /* @__PURE__ */ function(e) {
|
|
134
134
|
return e.VERBOSE = "VERBOSE", e.INFO = "INFO", e.WARN = "WARN", e.ERROR = "ERROR", e;
|
|
135
135
|
}({}), d = (e, t, n = "log", r, i = "color: inherit") => {
|
|
136
136
|
let a = typeof console > "u" ? void 0 : console;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as e, $n as t, A as n, B as r, Bt as i, Cn as a, Ct as o, D as s, Dt as c, Et as l, F as u, Ft as d, G as f, H as p, Ht as m, I as h, It as g, J as _, K as v, L as y, Lt as b, M as ee, Mt as x, N as te, Nt as ne, O as re, Ot as ie, P as ae, Pt as oe, Q as se, Qt as S, R as ce, Rt as le, St as ue, Tt as de, U as fe, Ut as pe, V as me, Vt as he, W as ge, Wt as _e, X as ve, Y as ye, Z as be, Zt as xe, _t as Se, a as Ce, at as we, bt as Te, c as Ee, cn as De, ct as Oe, d as ke, dt as Ae, en as je, er as C, et as Me, f as Ne, g as Pe, gt as Fe, h as Ie, ht as Le, i as Re, in as ze, it as Be, j as Ve, jt as He, kt as Ue, l as We, lt as Ge, mt as Ke, n as qe, nt as Je, o as Ye, ot as Xe, p as Ze, pt as Qe, q as $e, qn as et, qt as tt, r as nt, rn as w, rt, s as it, sn as at, st as ot, t as st, tt as ct, u as T, ut as lt, v as ut, wt as dt, xt as ft, yt as pt, z as mt, zt as ht } from "./constants-
|
|
1
|
+
import { $ as e, $n as t, A as n, B as r, Bt as i, Cn as a, Ct as o, D as s, Dt as c, Et as l, F as u, Ft as d, G as f, H as p, Ht as m, I as h, It as g, J as _, K as v, L as y, Lt as b, M as ee, Mt as x, N as te, Nt as ne, O as re, Ot as ie, P as ae, Pt as oe, Q as se, Qt as S, R as ce, Rt as le, St as ue, Tt as de, U as fe, Ut as pe, V as me, Vt as he, W as ge, Wt as _e, X as ve, Y as ye, Z as be, Zt as xe, _t as Se, a as Ce, at as we, bt as Te, c as Ee, cn as De, ct as Oe, d as ke, dt as Ae, en as je, er as C, et as Me, f as Ne, g as Pe, gt as Fe, h as Ie, ht as Le, i as Re, in as ze, it as Be, j as Ve, jt as He, kt as Ue, l as We, lt as Ge, mt as Ke, n as qe, nt as Je, o as Ye, ot as Xe, p as Ze, pt as Qe, q as $e, qn as et, qt as tt, r as nt, rn as w, rt, s as it, sn as at, st as ot, t as st, tt as ct, u as T, ut as lt, v as ut, wt as dt, xt as ft, yt as pt, z as mt, zt as ht } from "./constants-Cr7GEExc.mjs";
|
|
2
2
|
import { t as E } from "./objectSpread2-CWwMYL_U.mjs";
|
|
3
3
|
import { n as D } from "./tw-CqxBf-1Y.mjs";
|
|
4
4
|
//#region src/components/utils/html.ts
|
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import * as e from "node:fs";
|
|
2
|
+
import { JSDOM as t } from "jsdom";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var n = Object.defineProperty, r = (e, t) => () => (e && (t = e(e = 0)), t), i = (e, t) => {
|
|
5
|
+
let r = {};
|
|
6
|
+
for (var i in e) n(r, i, {
|
|
7
|
+
get: e[i],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
return t || n(r, Symbol.toStringTag, { value: "Module" }), r;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/cli/commands/convert-html/preprocessor.ts
|
|
14
|
+
function a(e) {
|
|
15
|
+
o(e), s(e), d(e), f(e), p(e), m(e);
|
|
16
|
+
}
|
|
17
|
+
function o(e) {
|
|
18
|
+
let t = e.ownerDocument;
|
|
19
|
+
for (let n of Array.from(e.querySelectorAll("div[style]"))) {
|
|
20
|
+
if (n.closest("table")) continue;
|
|
21
|
+
let e = u(n);
|
|
22
|
+
if (!e || c(e)) continue;
|
|
23
|
+
let r = t.createElement("aside");
|
|
24
|
+
r.style.backgroundColor = e, r.append(...Array.from(n.childNodes));
|
|
25
|
+
let i;
|
|
26
|
+
for (; (i = Array.from(r.querySelectorAll(":scope > div")).filter((e) => !e.getAttribute("style") && !e.getAttribute("class"))).length > 0;) for (let e of i) e.replaceWith(...Array.from(e.childNodes));
|
|
27
|
+
for (let e of Array.from(r.querySelectorAll("p"))) {
|
|
28
|
+
let t = e.lastElementChild;
|
|
29
|
+
t?.tagName === "BR" && t.remove();
|
|
30
|
+
}
|
|
31
|
+
n.replaceWith(r);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function s(e) {
|
|
35
|
+
let t = e.querySelectorAll("[style*=\"background-color\"]");
|
|
36
|
+
for (let e of Array.from(t)) c(e.style.backgroundColor) && (e.style.removeProperty("background-color"), e.getAttribute("style")?.trim() === "" && e.removeAttribute("style"), l(e) && e.replaceWith(...Array.from(e.childNodes)));
|
|
37
|
+
}
|
|
38
|
+
function c(e) {
|
|
39
|
+
if (!e) return !1;
|
|
40
|
+
let t = e.replace(/\s/g, "").toLowerCase();
|
|
41
|
+
if (t === "transparent") return !0;
|
|
42
|
+
let n = t.match(/^rgba?\((\d+),(\d+),(\d+)(?:,([^)]+))?\)$/);
|
|
43
|
+
if (!n) return !1;
|
|
44
|
+
if ((n[4] === void 0 ? 1 : parseFloat(n[4])) === 0) return !0;
|
|
45
|
+
let r = parseInt(n[1], 10), i = parseInt(n[2], 10), a = parseInt(n[3], 10);
|
|
46
|
+
return r >= _ && i >= _ && a >= _;
|
|
47
|
+
}
|
|
48
|
+
function l(e) {
|
|
49
|
+
return e.attributes.length > 0 ? !1 : (e.textContent ?? "").replace(/[\s\u00A0]/g, "").length === 0;
|
|
50
|
+
}
|
|
51
|
+
function u(e) {
|
|
52
|
+
if (e.style.backgroundColor) return e.style.backgroundColor;
|
|
53
|
+
let t = (e.getAttribute("style") ?? "").match(/background:\s*([^;]+)/i);
|
|
54
|
+
if (t) {
|
|
55
|
+
let e = t[1].trim().match(/^(rgb[a]?\([^)]+\)|#[0-9a-fA-F]{3,8}|[a-z]+)$/i);
|
|
56
|
+
if (e) return e[1];
|
|
57
|
+
}
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
function d(e) {
|
|
61
|
+
let t = e.ownerDocument;
|
|
62
|
+
for (let n of Array.from(e.querySelectorAll("td, th"))) {
|
|
63
|
+
let e = n.querySelectorAll("p");
|
|
64
|
+
if (e.length !== 0) {
|
|
65
|
+
for (let n of Array.from(e)) {
|
|
66
|
+
if (n.innerHTML.trim() === "" || n.innerHTML.trim() === " ") {
|
|
67
|
+
n.remove();
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
let e = t.createDocumentFragment();
|
|
71
|
+
e.append(...Array.from(n.childNodes)), e.append(t.createElement("br")), n.replaceWith(e);
|
|
72
|
+
}
|
|
73
|
+
h(n);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function f(e) {
|
|
78
|
+
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();
|
|
79
|
+
}
|
|
80
|
+
function p(e) {
|
|
81
|
+
let t = e.ownerDocument;
|
|
82
|
+
for (let n of Array.from(e.querySelectorAll("del, strike"))) {
|
|
83
|
+
let e = t.createElement("s");
|
|
84
|
+
e.append(...Array.from(n.childNodes)), n.replaceWith(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function m(e) {
|
|
88
|
+
let t = e.ownerDocument, n = Array.from(e.childNodes), r = null;
|
|
89
|
+
for (let e of n) {
|
|
90
|
+
if (e.nodeType !== Node.ELEMENT_NODE) continue;
|
|
91
|
+
let n = e;
|
|
92
|
+
if (n.tagName !== "P") {
|
|
93
|
+
r = null;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
let i = n.textContent ?? "";
|
|
97
|
+
if (!v.test(i)) {
|
|
98
|
+
r = null;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
r || (r = t.createElement("ul"), n.before(r));
|
|
102
|
+
let a = t.createElement("li"), o = g(n);
|
|
103
|
+
o && (o.textContent = (o.textContent ?? "").replace(v, "")), a.append(...Array.from(n.childNodes)), r.appendChild(a), n.remove();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function h(e) {
|
|
107
|
+
let t = e.lastChild;
|
|
108
|
+
for (; t;) if (t.nodeType === Node.ELEMENT_NODE && t.tagName === "BR") {
|
|
109
|
+
let e = t.previousSibling;
|
|
110
|
+
t.remove(), t = e;
|
|
111
|
+
} else if (t.nodeType === Node.TEXT_NODE && t.textContent?.trim() === "") {
|
|
112
|
+
let e = t.previousSibling;
|
|
113
|
+
t.remove(), t = e;
|
|
114
|
+
} else break;
|
|
115
|
+
}
|
|
116
|
+
function g(e) {
|
|
117
|
+
if (e.nodeType === Node.TEXT_NODE) return e;
|
|
118
|
+
for (let t of Array.from(e.childNodes)) {
|
|
119
|
+
let e = g(t);
|
|
120
|
+
if (e) return e;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
var _, v, y = r((() => {
|
|
125
|
+
_ = 250, v = /^[\u2022\u00B7][\s\u00A0]*|^-\s/;
|
|
126
|
+
}));
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/cli/commands/convert-html/sanitizer.ts
|
|
129
|
+
function b(e) {
|
|
130
|
+
x(e);
|
|
131
|
+
}
|
|
132
|
+
function x(e) {
|
|
133
|
+
let t = Array.from(e.childNodes);
|
|
134
|
+
for (let e of t) {
|
|
135
|
+
if (e.nodeType !== e.ELEMENT_NODE) continue;
|
|
136
|
+
let n = e, r = S[n.tagName];
|
|
137
|
+
if (r === void 0) {
|
|
138
|
+
let e = Array.from(n.childNodes);
|
|
139
|
+
for (let t of e) n.before(t);
|
|
140
|
+
n.remove();
|
|
141
|
+
for (let n of e) n.nodeType === n.ELEMENT_NODE && t.push(n);
|
|
142
|
+
} else {
|
|
143
|
+
if (r !== !0) for (let e of Array.from(n.attributes)) r.has(e.name) || n.removeAttribute(e.name);
|
|
144
|
+
else for (let e of Array.from(n.attributes)) n.removeAttribute(e.name);
|
|
145
|
+
x(n);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
var S, C = r((() => {
|
|
150
|
+
S = {
|
|
151
|
+
B: !0,
|
|
152
|
+
STRONG: !0,
|
|
153
|
+
I: !0,
|
|
154
|
+
EM: !0,
|
|
155
|
+
A: new Set(["href"]),
|
|
156
|
+
S: !0,
|
|
157
|
+
U: !0,
|
|
158
|
+
CODE: !0,
|
|
159
|
+
MARK: new Set(["style"]),
|
|
160
|
+
BR: !0,
|
|
161
|
+
P: !0,
|
|
162
|
+
H1: !0,
|
|
163
|
+
H2: !0,
|
|
164
|
+
H3: !0,
|
|
165
|
+
H4: !0,
|
|
166
|
+
H5: !0,
|
|
167
|
+
H6: !0,
|
|
168
|
+
UL: !0,
|
|
169
|
+
OL: !0,
|
|
170
|
+
LI: new Set(["aria-level"]),
|
|
171
|
+
TABLE: !0,
|
|
172
|
+
THEAD: !0,
|
|
173
|
+
TBODY: !0,
|
|
174
|
+
TR: !0,
|
|
175
|
+
TD: new Set(["style"]),
|
|
176
|
+
TH: new Set(["style"]),
|
|
177
|
+
BLOCKQUOTE: !0,
|
|
178
|
+
PRE: !0,
|
|
179
|
+
HR: !0,
|
|
180
|
+
ASIDE: new Set(["style"]),
|
|
181
|
+
DETAILS: !0,
|
|
182
|
+
SUMMARY: !0,
|
|
183
|
+
IMG: new Set(["src", "style"])
|
|
184
|
+
};
|
|
185
|
+
}));
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/cli/commands/convert-html/id-generator.ts
|
|
188
|
+
function w() {
|
|
189
|
+
let e = /* @__PURE__ */ new Map();
|
|
190
|
+
return (t) => {
|
|
191
|
+
let n = (e.get(t) ?? 0) + 1;
|
|
192
|
+
return e.set(t, n), `${t}-${n}`;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
var T = r((() => {})), E, D, O = r((() => {
|
|
196
|
+
E = [
|
|
197
|
+
{
|
|
198
|
+
name: "gray",
|
|
199
|
+
text: "#787774",
|
|
200
|
+
bg: "#f1f1ef"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "brown",
|
|
204
|
+
text: "#9f6b53",
|
|
205
|
+
bg: "#f4eeee"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "orange",
|
|
209
|
+
text: "#d9730d",
|
|
210
|
+
bg: "#fbecdd"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "yellow",
|
|
214
|
+
text: "#cb9b00",
|
|
215
|
+
bg: "#fbf3db"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: "green",
|
|
219
|
+
text: "#448361",
|
|
220
|
+
bg: "#edf3ec"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "blue",
|
|
224
|
+
text: "#337ea9",
|
|
225
|
+
bg: "#e7f3f8"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "purple",
|
|
229
|
+
text: "#9065b0",
|
|
230
|
+
bg: "#f6f3f9"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "pink",
|
|
234
|
+
text: "#c14c8a",
|
|
235
|
+
bg: "#f9f0f5"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "red",
|
|
239
|
+
text: "#d44c47",
|
|
240
|
+
bg: "#fdebec"
|
|
241
|
+
}
|
|
242
|
+
], D = [
|
|
243
|
+
{
|
|
244
|
+
name: "gray",
|
|
245
|
+
text: "#9b9b9b",
|
|
246
|
+
bg: "#2f2f2f"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "brown",
|
|
250
|
+
text: "#c59177",
|
|
251
|
+
bg: "#452a1c"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "orange",
|
|
255
|
+
text: "#dc8c47",
|
|
256
|
+
bg: "#4d2f14"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: "yellow",
|
|
260
|
+
text: "#d4ab49",
|
|
261
|
+
bg: "#544012"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "green",
|
|
265
|
+
text: "#5db184",
|
|
266
|
+
bg: "#1e432f"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: "blue",
|
|
270
|
+
text: "#5c9fcc",
|
|
271
|
+
bg: "#123a54"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "purple",
|
|
275
|
+
text: "#a67dca",
|
|
276
|
+
bg: "#341d49"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "pink",
|
|
280
|
+
text: "#d45e99",
|
|
281
|
+
bg: "#4b1b33"
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: "red",
|
|
285
|
+
text: "#dd5e5a",
|
|
286
|
+
bg: "#4e1a18"
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
}));
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/components/utils/color-mapping.ts
|
|
292
|
+
function k(e, t, n) {
|
|
293
|
+
let r = t / 100, i = n / 100;
|
|
294
|
+
if (r === 0) {
|
|
295
|
+
let e = Math.round(i * 255);
|
|
296
|
+
return [
|
|
297
|
+
e,
|
|
298
|
+
e,
|
|
299
|
+
e
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
let a = (e) => e < 0 ? e + 1 : e > 1 ? e - 1 : e, o = (e, t, n) => {
|
|
303
|
+
let r = a(n);
|
|
304
|
+
return r < 1 / 6 ? e + (t - e) * 6 * r : r < 1 / 2 ? t : r < 2 / 3 ? e + (t - e) * (2 / 3 - r) * 6 : e;
|
|
305
|
+
}, s = i < .5 ? i * (1 + r) : i + r - i * r, c = 2 * i - s, l = e / 360;
|
|
306
|
+
return [
|
|
307
|
+
Math.round(o(c, s, l + 1 / 3) * 255),
|
|
308
|
+
Math.round(o(c, s, l) * 255),
|
|
309
|
+
Math.round(o(c, s, l - 1 / 3) * 255)
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
function A(e) {
|
|
313
|
+
let t = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);
|
|
314
|
+
if (t) return [
|
|
315
|
+
parseInt(t[1], 16),
|
|
316
|
+
parseInt(t[2], 16),
|
|
317
|
+
parseInt(t[3], 16)
|
|
318
|
+
];
|
|
319
|
+
let n = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})[0-9a-f]{2}$/i.exec(e);
|
|
320
|
+
if (n) return [
|
|
321
|
+
parseInt(n[1], 16),
|
|
322
|
+
parseInt(n[2], 16),
|
|
323
|
+
parseInt(n[3], 16)
|
|
324
|
+
];
|
|
325
|
+
let r = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e);
|
|
326
|
+
if (r) return [
|
|
327
|
+
parseInt(r[1] + r[1], 16),
|
|
328
|
+
parseInt(r[2] + r[2], 16),
|
|
329
|
+
parseInt(r[3] + r[3], 16)
|
|
330
|
+
];
|
|
331
|
+
let i = /^#([0-9a-f])([0-9a-f])([0-9a-f])[0-9a-f]$/i.exec(e);
|
|
332
|
+
if (i) return [
|
|
333
|
+
parseInt(i[1] + i[1], 16),
|
|
334
|
+
parseInt(i[2] + i[2], 16),
|
|
335
|
+
parseInt(i[3] + i[3], 16)
|
|
336
|
+
];
|
|
337
|
+
let a = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
|
|
338
|
+
if (a) return [
|
|
339
|
+
Number(a[1]),
|
|
340
|
+
Number(a[2]),
|
|
341
|
+
Number(a[3])
|
|
342
|
+
];
|
|
343
|
+
let o = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)$/i.exec(e);
|
|
344
|
+
return o ? k(Number(o[1]), Number(o[2]), Number(o[3])) : null;
|
|
345
|
+
}
|
|
346
|
+
function j(e) {
|
|
347
|
+
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;
|
|
348
|
+
if (i === a) return [
|
|
349
|
+
0,
|
|
350
|
+
0,
|
|
351
|
+
o
|
|
352
|
+
];
|
|
353
|
+
let s = i - a, c = o > .5 ? s / (2 - i - a) : s / (i + a);
|
|
354
|
+
return [
|
|
355
|
+
((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,
|
|
356
|
+
c,
|
|
357
|
+
o
|
|
358
|
+
];
|
|
359
|
+
}
|
|
360
|
+
function M(e, t) {
|
|
361
|
+
let n = e[1] < P, r = t[1] < P;
|
|
362
|
+
if (n && r) {
|
|
363
|
+
let n = Math.abs(e[2] - t[2]);
|
|
364
|
+
return n * n;
|
|
365
|
+
}
|
|
366
|
+
if (n !== r) return 1e3;
|
|
367
|
+
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]);
|
|
368
|
+
return 8 * a * a + 1 * o * o + 1 * s * s;
|
|
369
|
+
}
|
|
370
|
+
function N(e, t) {
|
|
371
|
+
let n = A(e);
|
|
372
|
+
if (n === null) return null;
|
|
373
|
+
let r = j(n);
|
|
374
|
+
return [...E, ...D].reduce((e, n) => {
|
|
375
|
+
let i = A(n[t]);
|
|
376
|
+
if (i === null) return e;
|
|
377
|
+
let a = M(r, j(i));
|
|
378
|
+
return e === null || a < e.distance ? {
|
|
379
|
+
name: n.name,
|
|
380
|
+
distance: a
|
|
381
|
+
} : e;
|
|
382
|
+
}, null)?.name ?? null;
|
|
383
|
+
}
|
|
384
|
+
var P, F = r((() => {
|
|
385
|
+
O(), P = .1;
|
|
386
|
+
}));
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region src/cli/commands/convert-html/block-builder.ts
|
|
389
|
+
function I(e) {
|
|
390
|
+
let t = w(), n = [];
|
|
391
|
+
for (let r of Array.from(e.childNodes)) L(r, n, t);
|
|
392
|
+
return n;
|
|
393
|
+
}
|
|
394
|
+
function L(e, t, n) {
|
|
395
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
396
|
+
let r = e.textContent?.trim() ?? "";
|
|
397
|
+
r && t.push({
|
|
398
|
+
id: n("paragraph"),
|
|
399
|
+
type: "paragraph",
|
|
400
|
+
data: { text: r }
|
|
401
|
+
});
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return;
|
|
405
|
+
let r = e, i = r.tagName;
|
|
406
|
+
if (i === "P") {
|
|
407
|
+
t.push({
|
|
408
|
+
id: n("paragraph"),
|
|
409
|
+
type: "paragraph",
|
|
410
|
+
data: { text: r.innerHTML }
|
|
411
|
+
});
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (/^H[1-6]$/.test(i)) {
|
|
415
|
+
let e = Number(i[1]);
|
|
416
|
+
t.push({
|
|
417
|
+
id: n("header"),
|
|
418
|
+
type: "header",
|
|
419
|
+
data: {
|
|
420
|
+
text: r.innerHTML,
|
|
421
|
+
level: e
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (i === "BLOCKQUOTE") {
|
|
427
|
+
t.push({
|
|
428
|
+
id: n("quote"),
|
|
429
|
+
type: "quote",
|
|
430
|
+
data: {
|
|
431
|
+
text: r.innerHTML,
|
|
432
|
+
size: "default"
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (i === "PRE") {
|
|
438
|
+
t.push({
|
|
439
|
+
id: n("code"),
|
|
440
|
+
type: "code",
|
|
441
|
+
data: {
|
|
442
|
+
code: r.textContent ?? "",
|
|
443
|
+
language: "plain-text"
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (i === "HR") {
|
|
449
|
+
t.push({
|
|
450
|
+
id: n("divider"),
|
|
451
|
+
type: "divider",
|
|
452
|
+
data: {}
|
|
453
|
+
});
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (i === "IMG") {
|
|
457
|
+
let e = r.getAttribute("src") ?? "", i = V(r, "width"), a = null;
|
|
458
|
+
if (i) {
|
|
459
|
+
let e = parseInt(i, 10);
|
|
460
|
+
isNaN(e) || (a = e);
|
|
461
|
+
}
|
|
462
|
+
t.push({
|
|
463
|
+
id: n("image"),
|
|
464
|
+
type: "image",
|
|
465
|
+
data: { url: e },
|
|
466
|
+
stretched: null,
|
|
467
|
+
key: null,
|
|
468
|
+
width: a
|
|
469
|
+
});
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (i === "DETAILS") {
|
|
473
|
+
let e = r.querySelector("summary"), i = e ? e.innerHTML : r.innerHTML;
|
|
474
|
+
t.push({
|
|
475
|
+
id: n("toggle"),
|
|
476
|
+
type: "toggle",
|
|
477
|
+
data: { text: i }
|
|
478
|
+
});
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (i === "UL" || i === "OL") {
|
|
482
|
+
R(r, i === "OL" ? "ordered" : "unordered", 0, t, n);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (i === "TABLE") {
|
|
486
|
+
z(r, t, n);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (i === "ASIDE") {
|
|
490
|
+
B(r, t, n);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
t.push({
|
|
494
|
+
id: n("paragraph"),
|
|
495
|
+
type: "paragraph",
|
|
496
|
+
data: { text: r.innerHTML }
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
function R(e, t, n, r, i) {
|
|
500
|
+
let a = e.getAttribute("start"), o = a ? Number(a) : null, s = !0;
|
|
501
|
+
for (let a of Array.from(e.children)) {
|
|
502
|
+
if (a.tagName !== "LI") continue;
|
|
503
|
+
let e = a.cloneNode(!0), c = [];
|
|
504
|
+
for (let t of Array.from(e.querySelectorAll("ul, ol"))) c.push(t.cloneNode(!0)), t.remove();
|
|
505
|
+
let l = e.innerHTML.trim(), u = a.getAttribute("aria-level"), d = n;
|
|
506
|
+
u && (d = Math.max(0, parseInt(u, 10) - 1)), r.push({
|
|
507
|
+
id: i("list"),
|
|
508
|
+
type: "list",
|
|
509
|
+
data: {
|
|
510
|
+
text: l,
|
|
511
|
+
style: t,
|
|
512
|
+
depth: d === 0 ? null : d,
|
|
513
|
+
checked: null,
|
|
514
|
+
start: s && o !== null ? o : null
|
|
515
|
+
}
|
|
516
|
+
}), s = !1;
|
|
517
|
+
for (let e of c) R(e, e.tagName === "OL" ? "ordered" : "unordered", n + 1, r, i);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function z(e, t, n) {
|
|
521
|
+
let r = n("table"), i = Array.from(e.querySelectorAll("tr")), a = !1, o = [];
|
|
522
|
+
for (let e = 0; e < i.length; e++) {
|
|
523
|
+
let s = i[e], c = Array.from(s.querySelectorAll("td, th"));
|
|
524
|
+
e === 0 && c.some((e) => e.tagName === "TH") && (a = !0);
|
|
525
|
+
let l = [];
|
|
526
|
+
for (let e of c) {
|
|
527
|
+
let i = e, a = i.innerHTML.trim();
|
|
528
|
+
if (a) {
|
|
529
|
+
let e = n("paragraph");
|
|
530
|
+
t.push({
|
|
531
|
+
id: e,
|
|
532
|
+
type: "paragraph",
|
|
533
|
+
parent: r,
|
|
534
|
+
data: { text: a }
|
|
535
|
+
});
|
|
536
|
+
let o = V(i, "background-color"), s = V(i, "color");
|
|
537
|
+
l.push({
|
|
538
|
+
blocks: [e],
|
|
539
|
+
color: o ? N(o, "bg") : null,
|
|
540
|
+
textColor: s ? N(s, "text") : null
|
|
541
|
+
});
|
|
542
|
+
} else l.push({
|
|
543
|
+
blocks: [],
|
|
544
|
+
color: null,
|
|
545
|
+
textColor: null
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
o.push(l);
|
|
549
|
+
}
|
|
550
|
+
let s = (i[0] ? Array.from(i[0].querySelectorAll("td, th")) : []).map((e) => {
|
|
551
|
+
let t = V(e, "width");
|
|
552
|
+
if (t) {
|
|
553
|
+
let e = parseInt(t, 10);
|
|
554
|
+
return isNaN(e) ? null : e;
|
|
555
|
+
}
|
|
556
|
+
return null;
|
|
557
|
+
}), c = s.some((e) => e !== null), l = {
|
|
558
|
+
id: r,
|
|
559
|
+
type: "table",
|
|
560
|
+
data: {
|
|
561
|
+
withHeadings: a,
|
|
562
|
+
withHeadingColumn: !1,
|
|
563
|
+
content: o,
|
|
564
|
+
...c ? { colWidths: s } : {}
|
|
565
|
+
}
|
|
566
|
+
}, u = t.findIndex((e) => e.parent === r);
|
|
567
|
+
u >= 0 ? t.splice(u, 0, l) : t.push(l);
|
|
568
|
+
}
|
|
569
|
+
function B(e, t, n) {
|
|
570
|
+
let r = n("callout"), i = V(e, "background-color"), a = i ? N(i, "bg") : null, o = [];
|
|
571
|
+
for (let i of Array.from(e.childNodes)) if (i.nodeType === Node.ELEMENT_NODE) {
|
|
572
|
+
let e = i, a = n("paragraph");
|
|
573
|
+
t.push({
|
|
574
|
+
id: a,
|
|
575
|
+
type: "paragraph",
|
|
576
|
+
parent: r,
|
|
577
|
+
data: { text: e.innerHTML }
|
|
578
|
+
}), o.push(a);
|
|
579
|
+
} else if (i.nodeType === Node.TEXT_NODE) {
|
|
580
|
+
let e = i.textContent?.trim() ?? "";
|
|
581
|
+
if (e) {
|
|
582
|
+
let i = n("paragraph");
|
|
583
|
+
t.push({
|
|
584
|
+
id: i,
|
|
585
|
+
type: "paragraph",
|
|
586
|
+
parent: r,
|
|
587
|
+
data: { text: e }
|
|
588
|
+
}), o.push(i);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
let s = t.findIndex((e) => e.parent === r), c = {
|
|
592
|
+
id: r,
|
|
593
|
+
type: "callout",
|
|
594
|
+
data: {
|
|
595
|
+
emoji: "💡",
|
|
596
|
+
backgroundColor: a ?? "gray"
|
|
597
|
+
},
|
|
598
|
+
content: o
|
|
599
|
+
};
|
|
600
|
+
s >= 0 ? t.splice(s, 0, c) : t.push(c);
|
|
601
|
+
}
|
|
602
|
+
function V(e, t) {
|
|
603
|
+
let n = e.getAttribute("style");
|
|
604
|
+
if (!n) return null;
|
|
605
|
+
let r = RegExp(`(?<![\\-a-z])${t}\\s*:\\s*([^;]+)`).exec(n);
|
|
606
|
+
return r ? r[1].trim() : null;
|
|
607
|
+
}
|
|
608
|
+
var H = r((() => {
|
|
609
|
+
T(), F();
|
|
610
|
+
})), U = /* @__PURE__ */ i({ convertHtml: () => W });
|
|
611
|
+
function W(e) {
|
|
612
|
+
let t = new DOMParser().parseFromString(e, "text/html").body;
|
|
613
|
+
a(t), b(t);
|
|
614
|
+
let n = {
|
|
615
|
+
version: "2.31.0",
|
|
616
|
+
blocks: I(t)
|
|
617
|
+
};
|
|
618
|
+
return JSON.stringify(n);
|
|
619
|
+
}
|
|
620
|
+
var G = r((() => {
|
|
621
|
+
y(), C(), H();
|
|
622
|
+
})), K = new t("");
|
|
623
|
+
globalThis.DOMParser = K.window.DOMParser, globalThis.Node = K.window.Node;
|
|
624
|
+
async function q() {
|
|
625
|
+
let { convertHtml: t } = await Promise.resolve().then(() => (G(), U)), n = t(e.readFileSync("/dev/stdin", "utf-8"));
|
|
626
|
+
process.stdout.write(n);
|
|
627
|
+
}
|
|
628
|
+
q().catch((e) => {
|
|
629
|
+
process.stderr.write(`Error: ${e.message}\n`), process.exitCode = 1;
|
|
630
|
+
});
|
|
631
|
+
//#endregion
|
package/dist/full.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as e, t } from "./chunks/blok-
|
|
2
|
-
import { $n as n } from "./chunks/constants-
|
|
1
|
+
import { n as e, t } from "./chunks/blok-1213fGsk.mjs";
|
|
2
|
+
import { $n as n } from "./chunks/constants-Cr7GEExc.mjs";
|
|
3
3
|
import { t as r } from "./chunks/objectSpread2-CWwMYL_U.mjs";
|
|
4
|
-
import { _ as i, a, c as o, g as s, i as c, l, m as u, n as d, o as f, s as p, t as m, v as h } from "./chunks/tools-
|
|
4
|
+
import { _ as i, a, c as o, g as s, i as c, l, m as u, n as d, o as f, s as p, t as m, v as h } from "./chunks/tools-DBEfU2dP.mjs";
|
|
5
5
|
//#region src/full.ts
|
|
6
6
|
var g = {
|
|
7
7
|
paragraph: {
|
package/dist/react.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "./chunks/blok-
|
|
2
|
-
import "./chunks/constants-
|
|
1
|
+
import { t as e } from "./chunks/blok-1213fGsk.mjs";
|
|
2
|
+
import "./chunks/constants-Cr7GEExc.mjs";
|
|
3
3
|
import { t } from "./chunks/objectSpread2-CWwMYL_U.mjs";
|
|
4
4
|
import { t as n } from "./chunks/objectWithoutProperties-D0XxKB4n.mjs";
|
|
5
5
|
import { forwardRef as r, useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
package/dist/tools.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { m as e } from "./chunks/constants-
|
|
2
|
-
import { _ as t, a as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v } from "./chunks/tools-
|
|
1
|
+
import { m as e } from "./chunks/constants-Cr7GEExc.mjs";
|
|
2
|
+
import { _ as t, a as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v } from "./chunks/tools-DBEfU2dP.mjs";
|
|
3
3
|
export { l as Bold, p as Callout, _ as Code, e as Convert, a as Divider, t as Header, m as InlineCode, r as Italic, h as Link, o as List, f as Marker, v as Paragraph, i as Quote, c as Strikethrough, s as Table, u as Toggle, n as Underline, g as defaultBlockTools, d as defaultInlineTools };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackuait/blok",
|
|
3
|
-
"version": "0.10.0-beta.
|
|
3
|
+
"version": "0.10.0-beta.15",
|
|
4
4
|
"description": "Blok — headless, highly extensible rich text editor built for developers who need to implement a block-based editing experience (similar to Notion) without building it from scratch",
|
|
5
5
|
"module": "dist/blok.mjs",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"bin": {
|
|
53
53
|
"blok": "./bin/blok.mjs",
|
|
54
|
+
"blok-convert-html": "./bin/convert-html.mjs",
|
|
54
55
|
"migrate-from-editorjs": "./codemod/migrate-editorjs-to-blok.js"
|
|
55
56
|
},
|
|
56
57
|
"files": [
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"scripts": {
|
|
84
85
|
"serve": "vite --no-open",
|
|
85
86
|
"serve:docs": "cd docs && vite --port 8080",
|
|
86
|
-
"build": "vite build --mode production && node scripts/build-locales.mjs && node scripts/build-cli.mjs",
|
|
87
|
+
"build": "vite build --mode production && node scripts/build-locales.mjs && node scripts/build-cli.mjs && node scripts/build-convert-html.mjs",
|
|
87
88
|
"build:cli": "node scripts/build-cli.mjs",
|
|
88
89
|
"build:test": "vite build --mode test && node scripts/build-locales.mjs test && node scripts/build-react-vendor.mjs",
|
|
89
90
|
"lint": "sh -c 'eslint .; ESLINT_EXIT=$?; tsc --noEmit; TSC_EXIT=$?; if [ $ESLINT_EXIT -ne 0 ] || [ $TSC_EXIT -ne 0 ]; then exit 1; fi'",
|