@guodun/antdv 1.4.6 → 1.4.8
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { isSafeContractImageUrl as e } from "./image-url.mjs";
|
|
2
2
|
import t from "dompurify";
|
|
3
3
|
//#region src/components/pro-contract-template-designer/src/utils/word-paste.ts
|
|
4
|
-
var n = 4 * 1024 * 1024, r = new Set([
|
|
4
|
+
var n = 4 * 1024 * 1024, r = "Noto Serif SC, Source Han Serif SC, Songti SC, STSong, SimSun, serif", i = "16px", a = "1.75", o = new Set([
|
|
5
5
|
"image/png",
|
|
6
6
|
"image/jpeg",
|
|
7
7
|
"image/gif",
|
|
8
8
|
"image/webp",
|
|
9
9
|
"image/bmp"
|
|
10
|
-
]),
|
|
11
|
-
RegExp(`<(?:img|v:imagedata)\\b[^>]+\\bsrc\\s*=\\s*["']\\s*${
|
|
12
|
-
var
|
|
10
|
+
]), s = "(?:file:|cid:|mhtml:|wordml:|blob:)", c = RegExp(`^${s}`, "i");
|
|
11
|
+
RegExp(`<(?:img|v:imagedata)\\b[^>]+\\bsrc\\s*=\\s*["']\\s*${s}`, "i");
|
|
12
|
+
var l = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.strike.del.sup.sub.blockquote.pre.code.a.ul.ol.li.table.thead.tbody.tfoot.tr.th.td.img".split("."), u = [
|
|
13
13
|
"style",
|
|
14
14
|
"href",
|
|
15
15
|
"target",
|
|
@@ -24,7 +24,7 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
24
24
|
"title",
|
|
25
25
|
"width",
|
|
26
26
|
"height"
|
|
27
|
-
],
|
|
27
|
+
], d = new Set(u), f = new Set([
|
|
28
28
|
"script",
|
|
29
29
|
"style",
|
|
30
30
|
"meta",
|
|
@@ -50,7 +50,7 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
50
50
|
"math",
|
|
51
51
|
"xml",
|
|
52
52
|
"template"
|
|
53
|
-
]),
|
|
53
|
+
]), p = new Set([
|
|
54
54
|
"font-weight",
|
|
55
55
|
"font-style",
|
|
56
56
|
"text-decoration",
|
|
@@ -60,7 +60,7 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
60
60
|
"font-size",
|
|
61
61
|
"font-family",
|
|
62
62
|
"vertical-align"
|
|
63
|
-
]),
|
|
63
|
+
]), m = new Set([
|
|
64
64
|
"font-weight",
|
|
65
65
|
"font-style",
|
|
66
66
|
"text-decoration",
|
|
@@ -77,7 +77,7 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
77
77
|
"padding-left",
|
|
78
78
|
"text-indent",
|
|
79
79
|
"direction"
|
|
80
|
-
]),
|
|
80
|
+
]), h = new Set([
|
|
81
81
|
"font-weight",
|
|
82
82
|
"font-style",
|
|
83
83
|
"text-decoration",
|
|
@@ -95,7 +95,7 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
95
95
|
"text-indent",
|
|
96
96
|
"direction",
|
|
97
97
|
"list-style-type"
|
|
98
|
-
]),
|
|
98
|
+
]), g = new Set([
|
|
99
99
|
"width",
|
|
100
100
|
"max-width",
|
|
101
101
|
"min-width",
|
|
@@ -103,31 +103,31 @@ var o = /* @__PURE__ */ "p.div.span.br.hr.h1.h2.h3.h4.h5.h6.strong.b.em.i.u.s.st
|
|
|
103
103
|
"border-collapse",
|
|
104
104
|
"margin-left",
|
|
105
105
|
"margin-right"
|
|
106
|
-
]),
|
|
106
|
+
]), ee = new Set(/* @__PURE__ */ "font-weight.font-style.text-decoration.text-decoration-line.color.background-color.font-size.font-family.text-align.line-height.margin-top.margin-bottom.margin-left.text-indent.direction.width.height.min-width.vertical-align.padding.padding-top.padding-right.padding-bottom.padding-left.border.border-top.border-right.border-bottom.border-left".split(".")), te = [
|
|
107
107
|
/urn:schemas-microsoft-com:office/i,
|
|
108
108
|
/xmlns:(?:o|w|m)\s*=/i,
|
|
109
109
|
/class\s*=\s*["'][^"']*\bMso/i,
|
|
110
110
|
/\bmso-[\w-]+\s*:/i,
|
|
111
111
|
/\[if\s+(?:gte\s+)?mso/i,
|
|
112
112
|
/Microsoft Word/i
|
|
113
|
-
],
|
|
113
|
+
], ne = [
|
|
114
114
|
/\bListContainerWrapper\b/i,
|
|
115
115
|
/\bdata-listid\s*=/i,
|
|
116
116
|
/\bdata-list-defn-props\s*=/i,
|
|
117
117
|
/\bdata-ccp-props\s*=/i,
|
|
118
118
|
/\bdata-contrast\s*=/i
|
|
119
|
-
],
|
|
119
|
+
], _ = [
|
|
120
120
|
/\b(?:WPS Office|Kingsoft)\b/i,
|
|
121
121
|
/\bwpsoffice\b/i,
|
|
122
122
|
/\bwps-(?:office|list|paragraph)\b/i
|
|
123
123
|
];
|
|
124
|
-
function _(e) {
|
|
125
|
-
return /\bdata-pm-slice\s*=/i.test(e) ? "internal" : ee.some((t) => t.test(e)) ? "wps" : g.some((t) => t.test(e)) ? "word-online" : h.some((t) => t.test(e)) ? /Microsoft Word|Mso|xmlns:w/i.test(e) ? "word" : "office" : "generic";
|
|
126
|
-
}
|
|
127
124
|
function v(e) {
|
|
125
|
+
return /\bdata-pm-slice\s*=/i.test(e) ? "internal" : _.some((t) => t.test(e)) ? "wps" : ne.some((t) => t.test(e)) ? "word-online" : te.some((t) => t.test(e)) ? /Microsoft Word|Mso|xmlns:w/i.test(e) ? "word" : "office" : "generic";
|
|
126
|
+
}
|
|
127
|
+
function y(e) {
|
|
128
128
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'").split(/\r?\n\r?\n/).map((e) => `<p>${e.replace(/\r?\n/g, "<br>") || "<br>"}</p>`).join("");
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function re(e) {
|
|
131
131
|
let t = /(?:^|;)\s*mso-list\s*:\s*(?:l(\d+)\s+)?level(\d+)(?:\s+lfo(\d+))?/i.exec(e);
|
|
132
132
|
if (t) return {
|
|
133
133
|
id: t[1] ?? "0",
|
|
@@ -135,8 +135,8 @@ function te(e) {
|
|
|
135
135
|
lfo: t[3] ?? "0"
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
let n = t.toLowerCase(), r = n === "td" || n === "th" ?
|
|
138
|
+
function b(e, t = "span") {
|
|
139
|
+
let n = t.toLowerCase(), r = n === "td" || n === "th" ? ee : n === "table" ? g : n === "ul" || n === "ol" ? h : /^(?:p|div|h[1-6]|blockquote|li)$/.test(n) ? m : p, i = w(e), a = i.find(([e]) => e.trim().toLowerCase() === "direction")?.[1]?.trim().toLowerCase() === "rtl" ? "rtl" : "ltr", o = /* @__PURE__ */ new Map();
|
|
140
140
|
for (let [e, t] of i) {
|
|
141
141
|
let n = e.toLowerCase().trim(), i = t.trim().replace(/\s*!important\s*$/i, "");
|
|
142
142
|
if (n === "mso-highlight" || n === "background") n = "background-color";
|
|
@@ -144,47 +144,47 @@ function y(e, t = "span") {
|
|
|
144
144
|
else if (n === "mso-border-alt") n = "border";
|
|
145
145
|
else if (/^mso-border-(top|right|bottom|left)-alt$/.test(n)) n = n.replace(/^mso-border-(top|right|bottom|left)-alt$/, "border-$1");
|
|
146
146
|
else if (n.startsWith("mso-")) continue;
|
|
147
|
-
r.has(n) && (n === "text-align" && /^(?:start|end)$/i.test(i) && (i = T(i, a)), i =
|
|
147
|
+
r.has(n) && (n === "text-align" && /^(?:start|end)$/i.test(i) && (i = T(i, a)), i = se(n, i), i && o.set(n === "text-decoration-line" ? "text-decoration" : n, i));
|
|
148
148
|
}
|
|
149
149
|
return Array.from(o.entries()).map(([e, t]) => `${e}: ${t}`).join("; ");
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function x(e) {
|
|
152
152
|
if (!e || e.length > 12582912 * 3) return [];
|
|
153
153
|
let t = [], n = 0, r = 0;
|
|
154
154
|
for (; r < e.length;) {
|
|
155
155
|
let i = e.indexOf("{\\pict", r);
|
|
156
156
|
if (i < 0) break;
|
|
157
|
-
let a =
|
|
157
|
+
let a = $(e, i);
|
|
158
158
|
if (a < 0) break;
|
|
159
159
|
let o = e.slice(i, a + 1);
|
|
160
160
|
r = i + 6;
|
|
161
|
-
let s =
|
|
161
|
+
let s = _e(o), c = /\\pngblip\b/i.test(s) ? "image/png" : /\\jpe?gblip\b/i.test(s) ? "image/jpeg" : "";
|
|
162
162
|
if (!c) continue;
|
|
163
163
|
let l = s.replace(/^\{\\pict\b/i, "").replace(/\\[a-z]+-?\d*\s?/gi, "").replace(/\\[^a-z]/gi, "").replace(/[{}\s]/g, "");
|
|
164
164
|
if (!l || l.length % 2 || /[^\da-f]/i.test(l)) continue;
|
|
165
165
|
let u = l.length / 2;
|
|
166
|
-
u > 5242880 || n + u > 12582912 ||
|
|
166
|
+
u > 5242880 || n + u > 12582912 || ye(l, c) && (n += u, t.push(`data:${c};base64,${ve(l)}`));
|
|
167
167
|
}
|
|
168
168
|
return t;
|
|
169
169
|
}
|
|
170
|
-
async function
|
|
171
|
-
let n = [],
|
|
172
|
-
for (let
|
|
173
|
-
let e =
|
|
174
|
-
if (!
|
|
170
|
+
async function S(e, t) {
|
|
171
|
+
let n = [], r = 0;
|
|
172
|
+
for (let i of e) {
|
|
173
|
+
let e = i.type.toLowerCase();
|
|
174
|
+
if (!o.has(e) || i.size <= 0 || i.size > 5242880) {
|
|
175
175
|
n.push(Promise.resolve(null));
|
|
176
176
|
continue;
|
|
177
177
|
}
|
|
178
|
-
if (
|
|
178
|
+
if (r + i.size > 12582912) {
|
|
179
179
|
n.push(Promise.resolve(null));
|
|
180
180
|
continue;
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
r += i.size, n.push((t ? t(i) : be(i)).then((e) => e && Y(e) ? e : null).catch(() => null));
|
|
183
183
|
}
|
|
184
184
|
return Promise.all(n);
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
let i =
|
|
186
|
+
function C(e, r = {}) {
|
|
187
|
+
let i = v(e);
|
|
188
188
|
if (i === "internal" && r.trustedInternal) return {
|
|
189
189
|
html: e,
|
|
190
190
|
source: i,
|
|
@@ -192,7 +192,7 @@ function S(e, r = {}) {
|
|
|
192
192
|
fallback: !1,
|
|
193
193
|
recoveredImageCount: 0
|
|
194
194
|
};
|
|
195
|
-
let a =
|
|
195
|
+
let a = y(r.plainText ?? oe(e));
|
|
196
196
|
if (!e || e.length > n || typeof window > "u" || typeof DOMParser > "u") return {
|
|
197
197
|
html: a,
|
|
198
198
|
source: i,
|
|
@@ -201,21 +201,25 @@ function S(e, r = {}) {
|
|
|
201
201
|
recoveredImageCount: 0
|
|
202
202
|
};
|
|
203
203
|
try {
|
|
204
|
-
let n = i !== "generic" && i !== "internal",
|
|
205
|
-
(n || d) &&
|
|
206
|
-
let f = n ?
|
|
204
|
+
let n = i !== "generic" && i !== "internal", o = ie(e), s = new DOMParser().parseFromString(n ? ae(o) : o, "text/html"), c = j(s), d = c.size > 0 || N(s);
|
|
205
|
+
(n || d) && M(s, c), n && (P(s), F(s));
|
|
206
|
+
let f = n ? x(r.rtf ?? "") : [], p = !!r.preferClipboardImages && f.length === 0, m = G(s, {
|
|
207
207
|
office: n,
|
|
208
208
|
replacementImages: f.length ? f : r.clipboardImages ?? [],
|
|
209
209
|
appendClipboardImages: f.length === 0 ? r.clipboardImages ?? [] : [],
|
|
210
210
|
preferClipboardImages: p
|
|
211
|
-
}), h = t(window), g = String(h.sanitize(
|
|
212
|
-
ALLOWED_TAGS:
|
|
213
|
-
ALLOWED_ATTR:
|
|
211
|
+
}), h = t(window), g = String(h.sanitize(s.body.innerHTML, {
|
|
212
|
+
ALLOWED_TAGS: l,
|
|
213
|
+
ALLOWED_ATTR: u,
|
|
214
214
|
ALLOW_DATA_ATTR: !1,
|
|
215
215
|
ALLOW_ARIA_ATTR: !1,
|
|
216
216
|
KEEP_CONTENT: !0,
|
|
217
217
|
RETURN_TRUSTED_TYPE: !1
|
|
218
218
|
}));
|
|
219
|
+
if (g) {
|
|
220
|
+
let e = new DOMParser().parseFromString(g, "text/html");
|
|
221
|
+
K(e), g = e.body.innerHTML;
|
|
222
|
+
}
|
|
219
223
|
return {
|
|
220
224
|
html: g || a,
|
|
221
225
|
source: i,
|
|
@@ -233,16 +237,16 @@ function S(e, r = {}) {
|
|
|
233
237
|
};
|
|
234
238
|
}
|
|
235
239
|
}
|
|
236
|
-
function
|
|
240
|
+
function ie(e) {
|
|
237
241
|
return /<!--StartFragment-->([\s\S]*?)<!--EndFragment-->/i.exec(e)?.[1] ?? e;
|
|
238
242
|
}
|
|
239
|
-
function
|
|
243
|
+
function ae(e) {
|
|
240
244
|
return e.replace(/<!--\s*\[if\s+!supportLists\]\s*>([\s\S]*?)<!\s*\[endif\]\s*-->/gi, "$1").replace(/<!\s*\[if\s+!supportLists\]\s*>([\s\S]*?)<!\s*\[endif\]\s*>/gi, "$1");
|
|
241
245
|
}
|
|
242
|
-
function
|
|
246
|
+
function oe(e) {
|
|
243
247
|
return e.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(?:p|div|li|h[1-6]|tr)>/gi, "\n").replace(/<[^>]*>/g, "").replace(/ /gi, " ").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").trim();
|
|
244
248
|
}
|
|
245
|
-
function
|
|
249
|
+
function w(e) {
|
|
246
250
|
let t = [], n = 0, r = "", i = 0;
|
|
247
251
|
for (let a = 0; a <= e.length; a++) {
|
|
248
252
|
let o = e[a] ?? ";";
|
|
@@ -263,7 +267,7 @@ function C(e) {
|
|
|
263
267
|
}
|
|
264
268
|
return t;
|
|
265
269
|
}
|
|
266
|
-
function
|
|
270
|
+
function se(e, t) {
|
|
267
271
|
let n = t.trim();
|
|
268
272
|
if (!n || n.length > 220 || /(?:url\s*\(|expression\s*\(|javascript:|vbscript:|data:|@import|var\s*\()/i.test(n)) return "";
|
|
269
273
|
if (e === "font-size") return E(n, {
|
|
@@ -272,7 +276,7 @@ function w(e, t) {
|
|
|
272
276
|
convertPt: !0,
|
|
273
277
|
allowPercent: !0
|
|
274
278
|
});
|
|
275
|
-
if (e === "padding") return
|
|
279
|
+
if (e === "padding") return A(n);
|
|
276
280
|
if (/^(?:margin-(?:top|bottom|left|right)|text-indent)$/.test(e)) return E(n, {
|
|
277
281
|
min: -2e3,
|
|
278
282
|
max: 2e3,
|
|
@@ -292,7 +296,7 @@ function w(e, t) {
|
|
|
292
296
|
allowPercent: !0
|
|
293
297
|
});
|
|
294
298
|
}
|
|
295
|
-
return e === "color" || e === "background-color" ? O(n) : e === "font-family" ? /^[\w\s,'"\-\u00A0-\uFFFF]+$/.test(n) ? n : "" : e === "font-weight" ? /^(?:normal|bold|bolder|lighter|[1-9]00)$/i.test(n) ? n.toLowerCase() : "" : e === "font-style" ? /^(?:normal|italic|oblique)$/i.test(n) ? n.toLowerCase() : "" : e === "text-decoration" ? /^(?:(?:none|underline|line-through|overline)\s*)+$/i.test(n) ? n.toLowerCase() : "" : e === "text-align" ? /^(?:left|right|center|justify|start|end)$/i.test(n) ? T(n, "ltr") : "" : e === "vertical-align" ? /^(?:top|middle|bottom|baseline|sub|super)$/i.test(n) ? n.toLowerCase() : "" : e === "direction" ? /^(?:ltr|rtl)$/i.test(n) ? n.toLowerCase() : "" : e === "list-style-type" ? /^(?:disc|circle|square|decimal|lower-alpha|upper-alpha|lower-roman|upper-roman|cjk-ideographic)$/i.test(n) ? n.toLowerCase() : "" : e === "table-layout" ? /^(?:auto|fixed)$/i.test(n) ? n.toLowerCase() : "" : e === "border-collapse" ? /^(?:collapse|separate)$/i.test(n) ? n.toLowerCase() : "" : /^border(?:-(?:top|right|bottom|left))?$/.test(e) ?
|
|
299
|
+
return e === "color" || e === "background-color" ? O(n) : e === "font-family" ? /^[\w\s,'"\-\u00A0-\uFFFF]+$/.test(n) ? n : "" : e === "font-weight" ? /^(?:normal|bold|bolder|lighter|[1-9]00)$/i.test(n) ? n.toLowerCase() : "" : e === "font-style" ? /^(?:normal|italic|oblique)$/i.test(n) ? n.toLowerCase() : "" : e === "text-decoration" ? /^(?:(?:none|underline|line-through|overline)\s*)+$/i.test(n) ? n.toLowerCase() : "" : e === "text-align" ? /^(?:left|right|center|justify|start|end)$/i.test(n) ? T(n, "ltr") : "" : e === "vertical-align" ? /^(?:top|middle|bottom|baseline|sub|super)$/i.test(n) ? n.toLowerCase() : "" : e === "direction" ? /^(?:ltr|rtl)$/i.test(n) ? n.toLowerCase() : "" : e === "list-style-type" ? /^(?:disc|circle|square|decimal|lower-alpha|upper-alpha|lower-roman|upper-roman|cjk-ideographic)$/i.test(n) ? n.toLowerCase() : "" : e === "table-layout" ? /^(?:auto|fixed)$/i.test(n) ? n.toLowerCase() : "" : e === "border-collapse" ? /^(?:collapse|separate)$/i.test(n) ? n.toLowerCase() : "" : /^border(?:-(?:top|right|bottom|left))?$/.test(e) ? k(n) : "";
|
|
296
300
|
}
|
|
297
301
|
function T(e, t) {
|
|
298
302
|
let n = e.toLowerCase();
|
|
@@ -313,7 +317,7 @@ function D(e) {
|
|
|
313
317
|
function O(e) {
|
|
314
318
|
return /^(?:windowtext|buttontext|canvastext)$/i.test(e) ? "black" : /^(?:window|buttonface|canvas)$/i.test(e) ? "white" : /^(?:transparent|currentcolor|black|white|red|green|blue|gray|grey|yellow|orange|purple|navy|teal|maroon|silver|fuchsia|aqua|lime)$/i.test(e) || /^#[\da-f]{3,8}$/i.test(e) ? e.toLowerCase() : /^(?:rgb|rgba|hsl|hsla)\(\s*[-\d.%]+(?:\s*[,/]\s*[-\d.%]+){2,3}\s*\)$/i.test(e) ? e : "";
|
|
315
319
|
}
|
|
316
|
-
function
|
|
320
|
+
function k(e) {
|
|
317
321
|
if (/^none$/i.test(e)) return "none";
|
|
318
322
|
let t = /^((?:\d+(?:\.\d+)?|\.\d+)(?:px|pt))\s+(solid|dashed|dotted|double)\s+(.+)$/i.exec(e), n = /^(solid|dashed|dotted|double)\s+(.+?)\s+((?:\d+(?:\.\d+)?|\.\d+)(?:px|pt))$/i.exec(e), r = t?.[1] ?? n?.[3], i = t?.[2] ?? n?.[1], a = t?.[3] ?? n?.[2];
|
|
319
323
|
if (!r || !i || !a) return "";
|
|
@@ -324,7 +328,7 @@ function ae(e) {
|
|
|
324
328
|
}), s = O(a.trim());
|
|
325
329
|
return o && s ? `${o} ${i.toLowerCase()} ${s}` : "";
|
|
326
330
|
}
|
|
327
|
-
function
|
|
331
|
+
function A(e) {
|
|
328
332
|
let t = e.trim().split(/\s+/);
|
|
329
333
|
if (t.length < 1 || t.length > 4) return "";
|
|
330
334
|
let n = t.map((e) => E(e, {
|
|
@@ -334,7 +338,7 @@ function oe(e) {
|
|
|
334
338
|
}));
|
|
335
339
|
return n.every(Boolean) ? n.join(" ") : "";
|
|
336
340
|
}
|
|
337
|
-
function
|
|
341
|
+
function j(e) {
|
|
338
342
|
let t = /* @__PURE__ */ new Map();
|
|
339
343
|
for (let n of Array.from(e.querySelectorAll("style"))) {
|
|
340
344
|
let e = n.textContent ?? "", r = /([^{}]+)\{([^{}]*)\}/g, i = r.exec(e);
|
|
@@ -348,26 +352,26 @@ function k(e) {
|
|
|
348
352
|
}
|
|
349
353
|
return t;
|
|
350
354
|
}
|
|
351
|
-
function
|
|
355
|
+
function M(e, t) {
|
|
352
356
|
for (let n of Array.from(e.body.querySelectorAll("[class]"))) {
|
|
353
357
|
let e = Array.from(n.classList).map((e) => t.get(e) ?? "").filter(Boolean).join(";");
|
|
354
358
|
e && n.setAttribute("style", `${e};${n.getAttribute("style") ?? ""}`);
|
|
355
359
|
}
|
|
356
360
|
}
|
|
357
|
-
function
|
|
361
|
+
function N(e) {
|
|
358
362
|
return !!e.body.querySelector("p[align],div[align],h1[align],h2[align],h3[align],h4[align],h5[align],h6[align],center,font");
|
|
359
363
|
}
|
|
360
|
-
function
|
|
364
|
+
function P(e) {
|
|
361
365
|
for (let t of Array.from(e.body.querySelectorAll("p,div"))) {
|
|
362
366
|
let n = t.className, r = t.getAttribute("style") ?? "", i = /(?:Mso)?Heading\s*([1-6])|MsoHeading([1-6])/i.exec(`${n};${r}`), a = i ? Number(i[1] ?? i[2]) : /MsoTitle/i.test(n) ? 1 : /MsoSubtitle/i.test(n) ? 2 : 0;
|
|
363
|
-
a &&
|
|
367
|
+
a && W(e, t, `h${a}`);
|
|
364
368
|
}
|
|
365
369
|
}
|
|
366
|
-
function
|
|
370
|
+
function F(e) {
|
|
367
371
|
let t = [e.body, ...Array.from(e.body.querySelectorAll("td,th,div,blockquote"))];
|
|
368
|
-
for (let n of t.reverse())
|
|
372
|
+
for (let n of t.reverse()) I(e, n);
|
|
369
373
|
}
|
|
370
|
-
function
|
|
374
|
+
function I(e, t) {
|
|
371
375
|
let n = Array.from(t.childNodes), r = [];
|
|
372
376
|
for (let i of n) {
|
|
373
377
|
if (i.nodeType === 3 && !(i.textContent ?? "").trim()) continue;
|
|
@@ -375,7 +379,7 @@ function P(e, t) {
|
|
|
375
379
|
r = [];
|
|
376
380
|
continue;
|
|
377
381
|
}
|
|
378
|
-
let n = i, a =
|
|
382
|
+
let n = i, a = L(n);
|
|
379
383
|
if (!a) {
|
|
380
384
|
r = [];
|
|
381
385
|
continue;
|
|
@@ -397,15 +401,15 @@ function P(e, t) {
|
|
|
397
401
|
}, r[o - 1] = s;
|
|
398
402
|
}
|
|
399
403
|
let c = e.createElement("li");
|
|
400
|
-
for (
|
|
404
|
+
for (V(n); n.firstChild;) c.appendChild(n.firstChild);
|
|
401
405
|
s.list.appendChild(c), s.lastItem = c, s.expectedStart = a.kind === "ol" ? (a.start ?? s.expectedStart ?? 1) + 1 : void 0, n.remove();
|
|
402
406
|
}
|
|
403
407
|
}
|
|
404
|
-
function
|
|
408
|
+
function L(e) {
|
|
405
409
|
if (!/^(?:p|div)$/i.test(e.tagName)) return;
|
|
406
|
-
let t =
|
|
410
|
+
let t = re(e.getAttribute("style") ?? "");
|
|
407
411
|
if (!t) return;
|
|
408
|
-
let n =
|
|
412
|
+
let n = H(e), r = n.text, i = n.font;
|
|
409
413
|
if (/[•·●○■□◆◇▪▫]/.test(r) || /(?:Symbol|Wingdings|Webdings)/i.test(i)) {
|
|
410
414
|
let e = /[○◇▫]/.test(r) ? "circle" : /[■□▪]/.test(r) ? "square" : "disc";
|
|
411
415
|
return {
|
|
@@ -415,7 +419,7 @@ function F(e) {
|
|
|
415
419
|
listStyleType: e
|
|
416
420
|
};
|
|
417
421
|
}
|
|
418
|
-
let a =
|
|
422
|
+
let a = R(r);
|
|
419
423
|
return {
|
|
420
424
|
...t,
|
|
421
425
|
session: `${t.id}:${t.lfo}`,
|
|
@@ -425,7 +429,7 @@ function F(e) {
|
|
|
425
429
|
start: a?.start
|
|
426
430
|
};
|
|
427
431
|
}
|
|
428
|
-
function
|
|
432
|
+
function R(e) {
|
|
429
433
|
let t = e.trim().replace(/^[((]/, "").replace(/[))\..、]\s*$/, "").trim();
|
|
430
434
|
if (/^\d+$/.test(t)) return {
|
|
431
435
|
start: Math.max(1, Number(t)),
|
|
@@ -435,7 +439,7 @@ function I(e) {
|
|
|
435
439
|
if (/^[ivxlcdm]+$/i.test(t)) {
|
|
436
440
|
let e = t === t.toUpperCase();
|
|
437
441
|
return {
|
|
438
|
-
start:
|
|
442
|
+
start: B(t),
|
|
439
443
|
type: e ? "I" : "i",
|
|
440
444
|
listStyleType: e ? "upper-roman" : "lower-roman"
|
|
441
445
|
};
|
|
@@ -449,12 +453,12 @@ function I(e) {
|
|
|
449
453
|
};
|
|
450
454
|
}
|
|
451
455
|
if (/^[零〇一二三四五六七八九十百千万]+$/.test(t)) return {
|
|
452
|
-
start:
|
|
456
|
+
start: z(t),
|
|
453
457
|
type: void 0,
|
|
454
458
|
listStyleType: "cjk-ideographic"
|
|
455
459
|
};
|
|
456
460
|
}
|
|
457
|
-
function
|
|
461
|
+
function z(e) {
|
|
458
462
|
let t = {
|
|
459
463
|
零: 0,
|
|
460
464
|
〇: 0,
|
|
@@ -483,7 +487,7 @@ function L(e) {
|
|
|
483
487
|
}
|
|
484
488
|
return Math.max(1, r + i + a);
|
|
485
489
|
}
|
|
486
|
-
function
|
|
490
|
+
function B(e) {
|
|
487
491
|
let t = {
|
|
488
492
|
i: 1,
|
|
489
493
|
v: 5,
|
|
@@ -499,17 +503,17 @@ function R(e) {
|
|
|
499
503
|
}
|
|
500
504
|
return Math.max(1, n);
|
|
501
505
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
506
|
+
function V(e) {
|
|
507
|
+
H(e).element?.remove(), e.firstChild?.nodeType === 3 && (e.firstChild.textContent = e.firstChild.textContent?.replace(/^[\s\u00A0]+/, "") ?? "");
|
|
504
508
|
}
|
|
505
|
-
function
|
|
509
|
+
function H(e) {
|
|
506
510
|
let t = Array.from(e.querySelectorAll("span")).find((e) => /mso-list\s*:\s*ignore/i.test(e.getAttribute("style") ?? ""));
|
|
507
511
|
if (t) return {
|
|
508
512
|
element: t,
|
|
509
|
-
text:
|
|
513
|
+
text: U(t.textContent ?? ""),
|
|
510
514
|
font: t.style.fontFamily
|
|
511
515
|
};
|
|
512
|
-
let n = e.querySelector("span"), r =
|
|
516
|
+
let n = e.querySelector("span"), r = U(n?.textContent ?? ""), i = n?.style.fontFamily ?? "";
|
|
513
517
|
return /[•·●○■□◆◇▪▫]/.test(r) || /(?:Symbol|Wingdings|Webdings)/i.test(i) || /^(?:\d+|[a-z]|[ivxlcdm]+)[.)、]$/i.test(r) || /^[((]?[零〇一二三四五六七八九十百千万]+[))\..、]$/.test(r) ? {
|
|
514
518
|
element: n ?? void 0,
|
|
515
519
|
text: r,
|
|
@@ -519,37 +523,37 @@ function B(e) {
|
|
|
519
523
|
font: ""
|
|
520
524
|
};
|
|
521
525
|
}
|
|
522
|
-
function
|
|
526
|
+
function U(e) {
|
|
523
527
|
return e.replace(/[\u00A0\s]+/g, " ").trim();
|
|
524
528
|
}
|
|
525
|
-
function
|
|
529
|
+
function W(e, t, n) {
|
|
526
530
|
let r = e.createElement(n);
|
|
527
531
|
for (let e of Array.from(t.attributes)) r.setAttribute(e.name, e.value);
|
|
528
532
|
for (; t.firstChild;) r.appendChild(t.firstChild);
|
|
529
533
|
return t.replaceWith(r), r;
|
|
530
534
|
}
|
|
531
|
-
function
|
|
532
|
-
|
|
535
|
+
function G(e, t) {
|
|
536
|
+
Q(e.body), de(e), fe(e), ce(e);
|
|
533
537
|
let n = 0, r = 0, i = 0;
|
|
534
538
|
for (let a of Array.from(e.body.querySelectorAll("*"))) {
|
|
535
539
|
let o = a.tagName.toLowerCase();
|
|
536
|
-
if (
|
|
540
|
+
if (f.has(o)) {
|
|
537
541
|
a.remove();
|
|
538
542
|
continue;
|
|
539
543
|
}
|
|
540
544
|
if (q(a), o === "img") {
|
|
541
|
-
let e = n < t.replacementImages.length, o =
|
|
545
|
+
let e = n < t.replacementImages.length, o = pe(a, t.replacementImages[n], e, t.preferClipboardImages === !0);
|
|
542
546
|
if (o.consumedReplacement && n++, o.usedReplacement && r++, !o.kept) continue;
|
|
543
547
|
i++;
|
|
544
|
-
} else o === "a" &&
|
|
545
|
-
let s =
|
|
546
|
-
s ? a.setAttribute("style", s) : a.removeAttribute("style"),
|
|
548
|
+
} else o === "a" && me(a);
|
|
549
|
+
let s = b(a.getAttribute("style") ?? "", o);
|
|
550
|
+
s ? a.setAttribute("style", s) : a.removeAttribute("style"), ue(e, a), le(e, a), ge(a);
|
|
547
551
|
for (let e of Array.from(a.attributes)) {
|
|
548
552
|
let t = e.name.toLowerCase();
|
|
549
|
-
(!
|
|
553
|
+
(!d.has(t) || t.startsWith("on") || t.startsWith("data-") || t === "class" || t === "id" || t === "lang" || t.includes(":")) && a.removeAttribute(e.name);
|
|
550
554
|
}
|
|
551
|
-
let
|
|
552
|
-
(
|
|
555
|
+
let c = a.style.verticalAlign;
|
|
556
|
+
(c === "super" || c === "sub") && o === "span" && W(e, a, c === "super" ? "sup" : "sub");
|
|
553
557
|
}
|
|
554
558
|
if (!i && t.appendClipboardImages.length) for (let n of t.appendClipboardImages) {
|
|
555
559
|
if (!n || !Y(n)) continue;
|
|
@@ -558,14 +562,39 @@ function U(e, t) {
|
|
|
558
562
|
}
|
|
559
563
|
return r;
|
|
560
564
|
}
|
|
561
|
-
function
|
|
562
|
-
|
|
563
|
-
for (let
|
|
565
|
+
function K(e) {
|
|
566
|
+
let t = /^(?:p|div|blockquote|li)$/, n = Array.from(e.body.querySelectorAll("*"));
|
|
567
|
+
for (let e of n) {
|
|
568
|
+
let n = e.tagName.toLowerCase(), o = /* @__PURE__ */ new Map();
|
|
569
|
+
for (let [t, n] of w(e.getAttribute("style") ?? "")) {
|
|
570
|
+
let e = t.trim().toLowerCase();
|
|
571
|
+
e && o.set(e, n.trim());
|
|
572
|
+
}
|
|
573
|
+
let s = o.has("font-family");
|
|
574
|
+
!t.test(n) && !s || (o.set("font-family", r), /^(?:p|div|blockquote|li)$/.test(n) && (o.set("line-height", a), o.set("font-size", i), o.set("margin-top", "0"), o.set("margin-bottom", "10px")), e.setAttribute("style", Array.from(o, ([e, t]) => `${e}: ${t}`).join("; ")));
|
|
575
|
+
}
|
|
576
|
+
let o = e.createTreeWalker(e.body, e.defaultView?.NodeFilter?.SHOW_TEXT ?? 4), s = [], c = o.nextNode();
|
|
577
|
+
for (; c;) s.push(c), c = o.nextNode();
|
|
578
|
+
for (let e of s) {
|
|
579
|
+
let t = e.nodeValue ?? "";
|
|
580
|
+
if (!t) continue;
|
|
581
|
+
let n = e.parentElement;
|
|
582
|
+
if (n?.closest("h1,h2,h3,h4,h5,h6,pre,code")) continue;
|
|
583
|
+
let r = t.replace(/[\t\r\n \u00a0]+/g, (e) => e.includes("\xA0") ? "\xA0".repeat(e.length) : " ");
|
|
584
|
+
if (!r.trim() && !r.includes("\xA0")) {
|
|
585
|
+
let t = (e) => !!(e && /^(?:a|b|strong|em|i|u|s|strike|del|sup|sub|span|img)$/.test(e.tagName.toLowerCase()));
|
|
586
|
+
n && (t(e.previousElementSibling) || t(e.nextElementSibling)) ? e.nodeValue = " " : e.remove();
|
|
587
|
+
} else e.nodeValue = r;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function ce(e) {
|
|
591
|
+
for (let t of Array.from(e.body.querySelectorAll("font"))) q(t), W(e, t, "span");
|
|
592
|
+
for (let t of Array.from(e.body.querySelectorAll("center"))) t.setAttribute("style", `${t.getAttribute("style") ?? ""};text-align:center`), W(e, t, "div");
|
|
564
593
|
}
|
|
565
|
-
function
|
|
594
|
+
function le(e, t) {
|
|
566
595
|
let n = t.tagName.toLowerCase();
|
|
567
596
|
if (!/^(?:b|strong|em|i|u|s|strike|del|sup|sub|a)$/.test(n)) return;
|
|
568
|
-
let r =
|
|
597
|
+
let r = w(t.getAttribute("style") ?? ""), i = [], a = [];
|
|
569
598
|
for (let [e, t] of r) {
|
|
570
599
|
let n = e.trim().toLowerCase(), r = t.trim();
|
|
571
600
|
(n === "font-family" || n === "font-size" || n === "color" || n === "background-color" ? i : a).push(`${n}: ${r}`);
|
|
@@ -576,13 +605,13 @@ function se(e, t) {
|
|
|
576
605
|
for (o.setAttribute("style", i.join("; ")); t.firstChild;) o.appendChild(t.firstChild);
|
|
577
606
|
t.appendChild(o);
|
|
578
607
|
}
|
|
579
|
-
function
|
|
608
|
+
function ue(e, t) {
|
|
580
609
|
let n = t.tagName.toLowerCase();
|
|
581
610
|
if (!/^(?:p|div|h[1-6]|blockquote|li|td|th)$/.test(n)) return;
|
|
582
|
-
let r =
|
|
611
|
+
let r = w(t.getAttribute("style") ?? ""), i = [], a = [];
|
|
583
612
|
for (let [e, t] of r) {
|
|
584
613
|
let r = e.trim().toLowerCase(), o = t.trim();
|
|
585
|
-
(
|
|
614
|
+
(p.has(r) && r !== "vertical-align" && !((n === "td" || n === "th") && r === "background-color") ? i : a).push(`${r}: ${o}`);
|
|
586
615
|
}
|
|
587
616
|
if (!i.length) return;
|
|
588
617
|
a.length ? t.setAttribute("style", a.join("; ")) : t.removeAttribute("style");
|
|
@@ -590,7 +619,7 @@ function G(e, t) {
|
|
|
590
619
|
for (o.setAttribute("style", i.join("; ")); t.firstChild;) o.appendChild(t.firstChild);
|
|
591
620
|
t.appendChild(o);
|
|
592
621
|
}
|
|
593
|
-
function
|
|
622
|
+
function de(e) {
|
|
594
623
|
for (let t of Array.from(e.body.querySelectorAll("*"))) {
|
|
595
624
|
if (t.tagName.toLowerCase() !== "v:imagedata") continue;
|
|
596
625
|
let n = e.createElement("img");
|
|
@@ -602,7 +631,7 @@ function K(e) {
|
|
|
602
631
|
} else t.replaceWith(n);
|
|
603
632
|
}
|
|
604
633
|
}
|
|
605
|
-
function
|
|
634
|
+
function fe(e) {
|
|
606
635
|
for (let t of Array.from(e.body.querySelectorAll("*")).reverse()) {
|
|
607
636
|
let e = t.tagName.toLowerCase();
|
|
608
637
|
if (e.includes(":")) {
|
|
@@ -623,19 +652,19 @@ function q(e) {
|
|
|
623
652
|
function J(e) {
|
|
624
653
|
return e ? /^\d+(?:\.\d+)?$/.test(e.trim()) ? `${e.trim()}px` : e.trim() : "";
|
|
625
654
|
}
|
|
626
|
-
function
|
|
627
|
-
let i = e.getAttribute("src") ?? "",
|
|
628
|
-
if (
|
|
655
|
+
function pe(e, t, n = !1, r = !1) {
|
|
656
|
+
let i = e.getAttribute("src") ?? "", a = c.test(i.trim()), o = (r || a) && n, s = !!(t && Y(t)), l = o && s, u = l && t ? t : i;
|
|
657
|
+
if (c.test(u.trim()) || !Y(u)) return e.remove(), {
|
|
629
658
|
kept: !1,
|
|
630
659
|
usedReplacement: !1,
|
|
631
|
-
consumedReplacement:
|
|
660
|
+
consumedReplacement: o
|
|
632
661
|
};
|
|
633
662
|
e.setAttribute("src", u.trim());
|
|
634
663
|
let d = X(e.getAttribute("width") ?? e.style.width), f = X(e.getAttribute("height") ?? e.style.height);
|
|
635
664
|
return d ? e.setAttribute("width", d) : e.removeAttribute("width"), f ? e.setAttribute("height", f) : e.removeAttribute("height"), e.setAttribute("alt", (e.getAttribute("alt") ?? "").slice(0, 500)), e.hasAttribute("title") && e.setAttribute("title", (e.getAttribute("title") ?? "").slice(0, 500)), {
|
|
636
665
|
kept: !0,
|
|
637
666
|
usedReplacement: l,
|
|
638
|
-
consumedReplacement:
|
|
667
|
+
consumedReplacement: o
|
|
639
668
|
};
|
|
640
669
|
}
|
|
641
670
|
function Y(t) {
|
|
@@ -648,32 +677,32 @@ function X(e) {
|
|
|
648
677
|
let n = Number(t[1]), r = D((t[2] ?? "px").toLowerCase()), i = Math.round(n * r);
|
|
649
678
|
return i >= 1 && i <= 2400 ? String(i) : "";
|
|
650
679
|
}
|
|
651
|
-
function
|
|
680
|
+
function me(e) {
|
|
652
681
|
let t = (e.getAttribute("href") ?? "").trim();
|
|
653
|
-
if (!
|
|
682
|
+
if (!he(t)) {
|
|
654
683
|
e.removeAttribute("href"), e.removeAttribute("target"), e.removeAttribute("rel");
|
|
655
684
|
return;
|
|
656
685
|
}
|
|
657
686
|
e.setAttribute("href", t), e.getAttribute("target") === "_blank" ? e.setAttribute("rel", "noopener noreferrer") : (e.removeAttribute("target"), e.removeAttribute("rel"));
|
|
658
687
|
}
|
|
659
|
-
function
|
|
688
|
+
function he(e) {
|
|
660
689
|
if (!e) return !1;
|
|
661
690
|
let t = e.replace(/[\u0000-\u0020\u007F]+/g, "");
|
|
662
691
|
return /^(?:javascript|vbscript|data|file):/i.test(t) ? !1 : /^(?:https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(t) || !/^[a-z][a-z\d+.-]*:/i.test(t);
|
|
663
692
|
}
|
|
664
|
-
function
|
|
693
|
+
function ge(e) {
|
|
665
694
|
let t = e.tagName.toLowerCase();
|
|
666
|
-
if ((t === "td" || t === "th") && (
|
|
695
|
+
if ((t === "td" || t === "th") && (Z(e, "rowspan", 1, 100), Z(e, "colspan", 1, 100)), t === "td" || t === "th") {
|
|
667
696
|
let t = (e.getAttribute("colwidth") ?? "").split(",").map((e) => Number.parseInt(e.trim(), 10)).filter((e) => Number.isFinite(e) && e >= 1 && e <= 2400).slice(0, 100);
|
|
668
697
|
t.length ? e.setAttribute("colwidth", t.join(",")) : e.removeAttribute("colwidth");
|
|
669
698
|
}
|
|
670
699
|
if (t === "ol") {
|
|
671
|
-
|
|
700
|
+
Z(e, "start", 1, 1e5);
|
|
672
701
|
let t = e.getAttribute("type");
|
|
673
702
|
(!t || !/^(?:1|a|A|i|I)$/.test(t)) && e.removeAttribute("type");
|
|
674
703
|
}
|
|
675
704
|
}
|
|
676
|
-
function
|
|
705
|
+
function Z(e, t, n, r) {
|
|
677
706
|
let i = Number.parseInt(e.getAttribute(t) ?? "", 10);
|
|
678
707
|
if (!Number.isFinite(i)) {
|
|
679
708
|
e.removeAttribute(t);
|
|
@@ -681,10 +710,10 @@ function Q(e, t, n, r) {
|
|
|
681
710
|
}
|
|
682
711
|
e.setAttribute(t, String(Math.max(n, Math.min(r, i))));
|
|
683
712
|
}
|
|
684
|
-
function
|
|
685
|
-
for (let t of Array.from(e.childNodes)) t.nodeType === 8 ? t.remove() :
|
|
713
|
+
function Q(e) {
|
|
714
|
+
for (let t of Array.from(e.childNodes)) t.nodeType === 8 ? t.remove() : Q(t);
|
|
686
715
|
}
|
|
687
|
-
function
|
|
716
|
+
function $(e, t) {
|
|
688
717
|
let n = 0;
|
|
689
718
|
for (let r = t; r < e.length; r++) {
|
|
690
719
|
if (e[r] === "\\") {
|
|
@@ -696,7 +725,7 @@ function fe(e, t) {
|
|
|
696
725
|
}
|
|
697
726
|
return -1;
|
|
698
727
|
}
|
|
699
|
-
function
|
|
728
|
+
function _e(e) {
|
|
700
729
|
let t = 0, n = "";
|
|
701
730
|
for (let r = 0; r < e.length; r++) {
|
|
702
731
|
let i = e[r];
|
|
@@ -718,20 +747,20 @@ function pe(e) {
|
|
|
718
747
|
}
|
|
719
748
|
return n;
|
|
720
749
|
}
|
|
721
|
-
function
|
|
750
|
+
function ve(e) {
|
|
722
751
|
let t = [], n = new Uint8Array(e.length / 2);
|
|
723
752
|
for (let t = 0; t < n.length; t++) n[t] = Number.parseInt(e.slice(t * 2, t * 2 + 2), 16);
|
|
724
753
|
for (let e = 0; e < n.length; e += 32768) t.push(String.fromCharCode(...Array.from(n.subarray(e, e + 32768))));
|
|
725
754
|
return btoa(t.join(""));
|
|
726
755
|
}
|
|
727
|
-
function
|
|
756
|
+
function ye(e, t) {
|
|
728
757
|
return t === "image/png" ? e.toLowerCase().startsWith("89504e470d0a1a0a") : t === "image/jpeg" ? e.toLowerCase().startsWith("ffd8ff") : !1;
|
|
729
758
|
}
|
|
730
|
-
function
|
|
759
|
+
function be(e) {
|
|
731
760
|
return new Promise((t, n) => {
|
|
732
761
|
let r = new FileReader();
|
|
733
762
|
r.onerror = () => n(r.error ?? /* @__PURE__ */ Error("clipboard image read failed")), r.onload = () => t(typeof r.result == "string" ? r.result : ""), r.readAsDataURL(e);
|
|
734
763
|
});
|
|
735
764
|
}
|
|
736
765
|
//#endregion
|
|
737
|
-
export {
|
|
766
|
+
export { v as detectClipboardHtmlSource, x as extractRtfImageDataUrls, b as normalizeOfficeStyle, C as normalizeWordClipboardHtml, y as plainTextToSafeHtml, S as readClipboardImageFiles };
|