tempest-react-sdk 0.77.0 → 0.78.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/bin/lib/alias/collect.mjs +20 -3
- package/bin/lib/alias/index.mjs +12 -1
- package/bin/lib/alias/index.test.mjs +24 -0
- package/bin/lib/css/analyze.test.mjs +21 -1
- package/bin/lib/css/collect.mjs +14 -0
- package/bin/lib/css/extract.mjs +63 -5
- package/bin/lib/css/extract.test.mjs +110 -1
- package/bin/lib/css/fix.e2e.test.mjs +50 -0
- package/bin/lib/css/index.mjs +6 -1
- package/bin/lib/fs/contain.mjs +50 -0
- package/bin/lib/icons/generate.mjs +28 -3
- package/bin/lib/icons/generate.test.mjs +57 -1
- package/bin/lib/openapi/escape.mjs +20 -6
- package/bin/lib/openapi/generate.encode.test.mjs +120 -0
- package/bin/lib/openapi/generate.hostile.test.mjs +38 -9
- package/bin/lib/openapi/generate.mjs +41 -6
- package/bin/lib/openapi/generate.test.mjs +7 -2
- package/bin/lib/openapi/schema-to-zod.mjs +5 -3
- package/bin/tempest-gen.test.mjs +188 -0
- package/bin/tempest.mjs +120 -44
- package/dist/auth/create-tempest-auth.cjs +1 -1
- package/dist/auth/create-tempest-auth.cjs.map +1 -1
- package/dist/auth/create-tempest-auth.js +186 -113
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/br/pix.cjs +1 -1
- package/dist/br/pix.cjs.map +1 -1
- package/dist/br/pix.js +30 -27
- package/dist/br/pix.js.map +1 -1
- package/dist/br.d.ts +11 -4
- package/dist/components/CodeBlock/CodeBlock.cjs +1 -1
- package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.js +1 -1
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/CodeBlock/tokenize.cjs +1 -1
- package/dist/components/CodeBlock/tokenize.cjs.map +1 -1
- package/dist/components/CodeBlock/tokenize.js +54 -25
- package/dist/components/CodeBlock/tokenize.js.map +1 -1
- package/dist/components/Markdown/markdown-parse.cjs +6 -6
- package/dist/components/Markdown/markdown-parse.cjs.map +1 -1
- package/dist/components/Markdown/markdown-parse.js +91 -74
- package/dist/components/Markdown/markdown-parse.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +141 -105
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/retry.cjs +1 -1
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.js +5 -6
- package/dist/http/retry.js.map +1 -1
- package/dist/sw/background-sync.cjs +1 -1
- package/dist/sw/background-sync.cjs.map +1 -1
- package/dist/sw/background-sync.js +32 -31
- package/dist/sw/background-sync.js.map +1 -1
- package/dist/sw/credential-headers.cjs.map +1 -1
- package/dist/sw/credential-headers.js.map +1 -1
- package/dist/sw.d.ts +46 -8
- package/dist/telemetry/app-error-reporter.cjs +1 -1
- package/dist/telemetry/app-error-reporter.cjs.map +1 -1
- package/dist/telemetry/app-error-reporter.js +1 -1
- package/dist/telemetry/app-error-reporter.js.map +1 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +214 -12
- package/dist/tempest-react-sdk.js +119 -119
- package/dist/utils/csv.cjs +3 -3
- package/dist/utils/csv.cjs.map +1 -1
- package/dist/utils/csv.js +11 -10
- package/dist/utils/csv.js.map +1 -1
- package/dist/{telemetry/app-error-owner.cjs → utils/owner-fingerprint.cjs} +2 -2
- package/dist/utils/owner-fingerprint.cjs.map +1 -0
- package/dist/{telemetry/app-error-owner.js → utils/owner-fingerprint.js} +3 -3
- package/dist/utils/owner-fingerprint.js.map +1 -0
- package/dist/vite/tempest-csp.cjs +2 -2
- package/dist/vite/tempest-csp.cjs.map +1 -1
- package/dist/vite/tempest-csp.js +69 -58
- package/dist/vite/tempest-csp.js.map +1 -1
- package/dist/vite.d.ts +5 -3
- package/package.json +1 -1
- package/dist/telemetry/app-error-owner.cjs.map +0 -1
- package/dist/telemetry/app-error-owner.js.map +0 -1
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { safeImageUrl as e, safeLinkUrl as t } from "../../utils/safe-url.js";
|
|
2
2
|
//#region src/components/Markdown/markdown-parse.ts
|
|
3
|
-
var n = /^\s{0,3}(`{3,}|~{3,})\s*([\w+-]*)$/, r = /^\s{0,3}(#{1,6})\s+/, i = /^\s{0,3}([-*_])\s*(?:\1\s*){2,}$/, a = /^\s{0,3}>\s?(.*)$/, o = /^(\
|
|
3
|
+
var n = /^\s{0,3}(`{3,}|~{3,})\s*([\w+-]*)$/, r = /^\s{0,3}(#{1,6})\s+/, i = /^\s{0,3}([-*_])\s*(?:\1\s*){2,}$/, a = /^\s{0,3}>\s?(.*)$/, o = /^([^\S\n\r]*)([-*+])[^\S\n\r]+/, s = /^([^\S\n\r]*)(\d{1,9})[.)][^\S\n\r]+/;
|
|
4
|
+
function c(e, t) {
|
|
5
|
+
let n = e.exec(t);
|
|
6
|
+
if (!n) return null;
|
|
7
|
+
let r = t.slice(n[0].length);
|
|
8
|
+
return r.includes("\u2028") || r.includes("\u2029") ? null : {
|
|
9
|
+
indent: n[1],
|
|
10
|
+
marker: n[2],
|
|
11
|
+
content: r
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function l(e) {
|
|
15
|
+
return c(o, e);
|
|
16
|
+
}
|
|
4
17
|
function u(e) {
|
|
18
|
+
return c(s, e);
|
|
19
|
+
}
|
|
20
|
+
var d = /^\s{0,3}\|[\s|:-]*$|^\s{0,3}:?-+:?(\s*\|\s*:?-+:?)+\s*\|?$/, f = 32;
|
|
21
|
+
function p(e) {
|
|
5
22
|
let t = r.exec(e);
|
|
6
23
|
if (!t) return null;
|
|
7
24
|
let n = e.slice(t[0].length).trimEnd(), i = n.length;
|
|
@@ -11,97 +28,97 @@ function u(e) {
|
|
|
11
28
|
text: n
|
|
12
29
|
};
|
|
13
30
|
}
|
|
14
|
-
function
|
|
31
|
+
function m(e) {
|
|
15
32
|
return e.endsWith(" ");
|
|
16
33
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
34
|
+
function h(e) {
|
|
35
|
+
return g(e.replace(/\r\n?/g, "\n").split("\n"), 0);
|
|
19
36
|
}
|
|
20
|
-
function
|
|
21
|
-
if (t >=
|
|
37
|
+
function g(e, t) {
|
|
38
|
+
if (t >= f) {
|
|
22
39
|
let t = e.map((e) => e.trim()).filter(Boolean).join("\n");
|
|
23
40
|
return t ? [{
|
|
24
41
|
type: "paragraph",
|
|
25
|
-
children:
|
|
42
|
+
children: C(t)
|
|
26
43
|
}] : [];
|
|
27
44
|
}
|
|
28
|
-
let r = [],
|
|
29
|
-
for (;
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
32
|
-
|
|
45
|
+
let r = [], o = 0;
|
|
46
|
+
for (; o < e.length;) {
|
|
47
|
+
let s = e[o];
|
|
48
|
+
if (s.trim() === "") {
|
|
49
|
+
o += 1;
|
|
33
50
|
continue;
|
|
34
51
|
}
|
|
35
|
-
let
|
|
36
|
-
if (
|
|
37
|
-
let t =
|
|
38
|
-
for (
|
|
39
|
-
|
|
52
|
+
let c = n.exec(s.trimEnd());
|
|
53
|
+
if (c) {
|
|
54
|
+
let t = c[1][0], n = [];
|
|
55
|
+
for (o += 1; o < e.length && !RegExp(`^\\s{0,3}${t}{3,}\\s*$`).test(e[o]);) n.push(e[o]), o += 1;
|
|
56
|
+
o += 1, r.push({
|
|
40
57
|
type: "code",
|
|
41
|
-
language:
|
|
58
|
+
language: c[2] || null,
|
|
42
59
|
value: n.join("\n")
|
|
43
60
|
});
|
|
44
61
|
continue;
|
|
45
62
|
}
|
|
46
|
-
let
|
|
47
|
-
if (
|
|
63
|
+
let f = p(s);
|
|
64
|
+
if (f) {
|
|
48
65
|
r.push({
|
|
49
66
|
type: "heading",
|
|
50
|
-
level:
|
|
51
|
-
children:
|
|
52
|
-
}),
|
|
67
|
+
level: f.level,
|
|
68
|
+
children: C(f.text)
|
|
69
|
+
}), o += 1;
|
|
53
70
|
continue;
|
|
54
71
|
}
|
|
55
|
-
if (i.test(
|
|
56
|
-
r.push({ type: "rule" }),
|
|
72
|
+
if (i.test(s)) {
|
|
73
|
+
r.push({ type: "rule" }), o += 1;
|
|
57
74
|
continue;
|
|
58
75
|
}
|
|
59
|
-
if (a.test(
|
|
76
|
+
if (a.test(s)) {
|
|
60
77
|
let n = [];
|
|
61
|
-
for (;
|
|
62
|
-
let t = a.exec(e[
|
|
78
|
+
for (; o < e.length;) {
|
|
79
|
+
let t = a.exec(e[o]);
|
|
63
80
|
if (t) {
|
|
64
|
-
n.push(t[1]),
|
|
81
|
+
n.push(t[1]), o += 1;
|
|
65
82
|
continue;
|
|
66
83
|
}
|
|
67
|
-
if (e[
|
|
68
|
-
n.push(e[
|
|
84
|
+
if (e[o].trim() === "") break;
|
|
85
|
+
n.push(e[o]), o += 1;
|
|
69
86
|
}
|
|
70
87
|
r.push({
|
|
71
88
|
type: "quote",
|
|
72
|
-
children:
|
|
89
|
+
children: g(n, t + 1)
|
|
73
90
|
});
|
|
74
91
|
continue;
|
|
75
92
|
}
|
|
76
|
-
if (
|
|
77
|
-
let [n, i] =
|
|
78
|
-
r.push(n),
|
|
93
|
+
if (l(s) || u(s)) {
|
|
94
|
+
let [n, i] = v(e, o, t);
|
|
95
|
+
r.push(n), o = i;
|
|
79
96
|
continue;
|
|
80
97
|
}
|
|
81
|
-
if (
|
|
82
|
-
let [t, n] =
|
|
83
|
-
r.push(t),
|
|
98
|
+
if (o + 1 < e.length && s.includes("|") && d.test(e[o + 1].trimEnd())) {
|
|
99
|
+
let [t, n] = b(e, o);
|
|
100
|
+
r.push(t), o = n;
|
|
84
101
|
continue;
|
|
85
102
|
}
|
|
86
|
-
let
|
|
87
|
-
for (;
|
|
88
|
-
let t = e[
|
|
89
|
-
if (
|
|
90
|
-
|
|
103
|
+
let h = [], y = [];
|
|
104
|
+
for (; o < e.length && e[o].trim() !== "";) {
|
|
105
|
+
let t = e[o];
|
|
106
|
+
if (p(t) || i.test(t) || n.test(t.trimEnd()) || a.test(t) || l(t) || u(t)) break;
|
|
107
|
+
h.push(t.trim()), y.push(m(t)), o += 1;
|
|
91
108
|
}
|
|
92
|
-
|
|
109
|
+
h.length > 0 && r.push({
|
|
93
110
|
type: "paragraph",
|
|
94
|
-
children:
|
|
111
|
+
children: C(_(h, y))
|
|
95
112
|
});
|
|
96
113
|
}
|
|
97
114
|
return r;
|
|
98
115
|
}
|
|
99
|
-
function
|
|
116
|
+
function _(e, t) {
|
|
100
117
|
return e.map((n, r) => t[r] && r < e.length - 1 ? `${n} ` : n).join("\n");
|
|
101
118
|
}
|
|
102
|
-
function
|
|
103
|
-
let r =
|
|
104
|
-
d.length !== 0 && (
|
|
119
|
+
function v(e, t, n) {
|
|
120
|
+
let r = l(e[t]), i = u(e[t]), a = i !== null, o = (i ?? r)?.indent.length ?? 0, s = a ? Number(i?.marker ?? 1) : 1, c = [], d = [], f = t, p = () => {
|
|
121
|
+
d.length !== 0 && (c.push(g(d, n + 1)), d = []);
|
|
105
122
|
};
|
|
106
123
|
for (; f < e.length;) {
|
|
107
124
|
let t = e[f];
|
|
@@ -112,30 +129,30 @@ function h(e, t, n) {
|
|
|
112
129
|
}
|
|
113
130
|
break;
|
|
114
131
|
}
|
|
115
|
-
let n =
|
|
116
|
-
if (i && i
|
|
132
|
+
let n = l(t), r = u(t), i = n ?? r;
|
|
133
|
+
if (i && i.indent.length <= o) {
|
|
117
134
|
if (!(a ? r : n)) break;
|
|
118
|
-
|
|
135
|
+
p(), d.push(i.content), f += 1;
|
|
119
136
|
continue;
|
|
120
137
|
}
|
|
121
138
|
if (i) {
|
|
122
|
-
d.push(t.slice(
|
|
139
|
+
d.push(t.slice(o)), f += 1;
|
|
123
140
|
continue;
|
|
124
141
|
}
|
|
125
|
-
if (t.search(/\S/) >
|
|
142
|
+
if (t.search(/\S/) > o) {
|
|
126
143
|
d.push(t.trim()), f += 1;
|
|
127
144
|
continue;
|
|
128
145
|
}
|
|
129
146
|
break;
|
|
130
147
|
}
|
|
131
|
-
return
|
|
148
|
+
return p(), [{
|
|
132
149
|
type: "list",
|
|
133
150
|
ordered: a,
|
|
134
|
-
start:
|
|
135
|
-
items:
|
|
151
|
+
start: s,
|
|
152
|
+
items: c
|
|
136
153
|
}, f];
|
|
137
154
|
}
|
|
138
|
-
function
|
|
155
|
+
function y(e) {
|
|
139
156
|
let t = e.trim().replace(/^\|/, "").replace(/\|$/, ""), n = [], r = "";
|
|
140
157
|
for (let e = 0; e < t.length; e += 1) {
|
|
141
158
|
if (t[e] === "\\" && t[e + 1] === "|") {
|
|
@@ -150,20 +167,20 @@ function g(e) {
|
|
|
150
167
|
}
|
|
151
168
|
return n.push(r), n.map((e) => e.trim());
|
|
152
169
|
}
|
|
153
|
-
function
|
|
154
|
-
let n =
|
|
170
|
+
function b(e, t) {
|
|
171
|
+
let n = y(e[t]), r = y(e[t + 1]).map((e) => {
|
|
155
172
|
let t = e.startsWith(":"), n = e.endsWith(":");
|
|
156
173
|
return t && n ? "center" : n ? "right" : t ? "left" : null;
|
|
157
174
|
}), i = [], a = t + 2;
|
|
158
|
-
for (; a < e.length && e[a].trim() !== "" && e[a].includes("|");) i.push(
|
|
175
|
+
for (; a < e.length && e[a].trim() !== "" && e[a].includes("|");) i.push(y(e[a]).map(C)), a += 1;
|
|
159
176
|
return [{
|
|
160
177
|
type: "table",
|
|
161
178
|
align: r,
|
|
162
|
-
head: n.map(
|
|
179
|
+
head: n.map(C),
|
|
163
180
|
rows: i
|
|
164
181
|
}, a];
|
|
165
182
|
}
|
|
166
|
-
var
|
|
183
|
+
var x = [
|
|
167
184
|
{
|
|
168
185
|
guard: {
|
|
169
186
|
kind: "link",
|
|
@@ -191,7 +208,7 @@ var v = [
|
|
|
191
208
|
first: "[",
|
|
192
209
|
pattern: /^\[([^\]]*)\]\(((?:[^()\s]|\([^()\s]*\))+)(?:\s+"[^"]*")?\)/,
|
|
193
210
|
build: (e) => {
|
|
194
|
-
let n = t(e[2]), r =
|
|
211
|
+
let n = t(e[2]), r = C(e[1]);
|
|
195
212
|
return n ? {
|
|
196
213
|
type: "link",
|
|
197
214
|
href: n,
|
|
@@ -215,7 +232,7 @@ var v = [
|
|
|
215
232
|
pattern: /^\*\*([\s\S]+?)\*\*/,
|
|
216
233
|
build: (e) => ({
|
|
217
234
|
type: "strong",
|
|
218
|
-
children:
|
|
235
|
+
children: C(e[1])
|
|
219
236
|
})
|
|
220
237
|
},
|
|
221
238
|
{
|
|
@@ -223,7 +240,7 @@ var v = [
|
|
|
223
240
|
pattern: /^__([\s\S]+?)__/,
|
|
224
241
|
build: (e) => ({
|
|
225
242
|
type: "strong",
|
|
226
|
-
children:
|
|
243
|
+
children: C(e[1])
|
|
227
244
|
})
|
|
228
245
|
},
|
|
229
246
|
{
|
|
@@ -231,7 +248,7 @@ var v = [
|
|
|
231
248
|
pattern: /^~~([\s\S]+?)~~/,
|
|
232
249
|
build: (e) => ({
|
|
233
250
|
type: "del",
|
|
234
|
-
children:
|
|
251
|
+
children: C(e[1])
|
|
235
252
|
})
|
|
236
253
|
},
|
|
237
254
|
{
|
|
@@ -239,7 +256,7 @@ var v = [
|
|
|
239
256
|
pattern: /^\*([^*\n]+)\*/,
|
|
240
257
|
build: (e) => ({
|
|
241
258
|
type: "em",
|
|
242
|
-
children:
|
|
259
|
+
children: C(e[1])
|
|
243
260
|
})
|
|
244
261
|
},
|
|
245
262
|
{
|
|
@@ -247,7 +264,7 @@ var v = [
|
|
|
247
264
|
pattern: /^_([^_\n]+)_/,
|
|
248
265
|
build: (e) => ({
|
|
249
266
|
type: "em",
|
|
250
|
-
children:
|
|
267
|
+
children: C(e[1])
|
|
251
268
|
})
|
|
252
269
|
},
|
|
253
270
|
{
|
|
@@ -277,8 +294,8 @@ var v = [
|
|
|
277
294
|
pattern: /^\\\n/,
|
|
278
295
|
build: () => ({ type: "break" })
|
|
279
296
|
}
|
|
280
|
-
],
|
|
281
|
-
function
|
|
297
|
+
], S = new Set(x.map((e) => e.first));
|
|
298
|
+
function C(e) {
|
|
282
299
|
let t = [], n = "", r = 0, i = -1, a = -1, o = -1, s = /[>\s]/g, c = () => {
|
|
283
300
|
n && t.push({
|
|
284
301
|
type: "text",
|
|
@@ -308,12 +325,12 @@ function b(e) {
|
|
|
308
325
|
i - r >= 2 && e[i] === "\n" ? (c(), t.push({ type: "break" }), r = i + 1) : (n += e.slice(r, i), r = i);
|
|
309
326
|
continue;
|
|
310
327
|
}
|
|
311
|
-
if (!
|
|
328
|
+
if (!S.has(e[r])) {
|
|
312
329
|
n += e[r], r += 1;
|
|
313
330
|
continue;
|
|
314
331
|
}
|
|
315
332
|
let i = e.slice(r), o = !1;
|
|
316
|
-
for (let n of
|
|
333
|
+
for (let n of x) {
|
|
317
334
|
if (n.first !== e[r] || !d(n.guard)) continue;
|
|
318
335
|
let s = n.pattern.exec(i);
|
|
319
336
|
if (!s) {
|
|
@@ -331,6 +348,6 @@ function b(e) {
|
|
|
331
348
|
return c(), t;
|
|
332
349
|
}
|
|
333
350
|
//#endregion
|
|
334
|
-
export {
|
|
351
|
+
export { C as parseInline, h as parseMarkdown };
|
|
335
352
|
|
|
336
353
|
//# sourceMappingURL=markdown-parse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-parse.js","names":[],"sources":["../../../src/components/Markdown/markdown-parse.ts"],"sourcesContent":["/**\n * @tempest-limits file-lines, function-lines — a Markdown block parser is a state\n * machine over line kinds: paragraph, heading, fence, list, quote, table and\n * thematic break each need to see the lines around them to know where they end.\n * parseBlocks is that loop, and cutting it into per-kind functions would hand each\n * one the same lookahead cursor.\n */\n// A small Markdown parser for the subset an app actually renders from untrusted\n// text: comments, ticket bodies, release notes, a product description.\n//\n// It produces a node tree, never an HTML string, and the renderer turns that into\n// React elements. No `dangerouslySetInnerHTML` exists anywhere in this component —\n// which is the property that makes rendering somebody else's Markdown safe, and it\n// is structural rather than a promise about escaping.\n//\n// Raw HTML in the input is therefore not \"sanitized\", it is **text**: `<script>` in\n// a comment renders as the four characters somebody typed. That is the whole point,\n// and it is also the documented limit — this is not a CommonMark implementation and\n// does not try to be.\n\nimport { safeImageUrl, safeLinkUrl } from \"@/utils/safe-url\";\n\n/** Inline content. */\nexport type MarkdownInline =\n | { type: \"text\"; value: string }\n | { type: \"strong\"; children: MarkdownInline[] }\n | { type: \"em\"; children: MarkdownInline[] }\n | { type: \"del\"; children: MarkdownInline[] }\n | { type: \"code\"; value: string }\n | { type: \"link\"; href: string; children: MarkdownInline[] }\n | { type: \"image\"; src: string; alt: string }\n | { type: \"break\" };\n\n/** Column alignment of a table, from the delimiter row. */\nexport type MarkdownAlign = \"left\" | \"center\" | \"right\" | null;\n\n/** Block content. */\nexport type MarkdownBlock =\n | { type: \"heading\"; level: number; children: MarkdownInline[] }\n | { type: \"paragraph\"; children: MarkdownInline[] }\n | { type: \"code\"; language: string | null; value: string }\n | { type: \"quote\"; children: MarkdownBlock[] }\n | { type: \"list\"; ordered: boolean; start: number; items: MarkdownBlock[][] }\n | {\n type: \"table\";\n align: MarkdownAlign[];\n head: MarkdownInline[][];\n rows: MarkdownInline[][][];\n }\n | { type: \"rule\" };\n\n/**\n * A fence opener, matched against the line **after** `trimEnd()`.\n *\n * The trailing `\\s*` lives in the `trimEnd()` rather than in the pattern: with it,\n * `\\s*([\\w+-]*)\\s*$` is two whitespace quantifiers separated by one that may be\n * empty, and a fence followed by 20 000 spaces and a stray `!` took 0.36 s (#437).\n */\nconst FENCE = /^\\s{0,3}(`{3,}|~{3,})\\s*([\\w+-]*)$/;\n/**\n * The opening marker of an ATX heading. The text and the optional closing `#` run\n * are cut by {@link matchHeading} with string operations, not by this pattern.\n */\nconst HEADING_OPEN = /^\\s{0,3}(#{1,6})\\s+/;\nconst RULE = /^\\s{0,3}([-*_])\\s*(?:\\1\\s*){2,}$/;\nconst QUOTE = /^\\s{0,3}>\\s?(.*)$/;\nconst BULLET = /^(\\s*)([-*+])\\s+(.*)$/;\nconst ORDERED = /^(\\s*)(\\d{1,9})[.)]\\s+(.*)$/;\n/**\n * A table's delimiter row, matched against the line **after** `trimEnd()`.\n *\n * The `|` is required somewhere in the line, and that is what tells a one-column\n * table (`| --- |`) apart from a thematic break (`---`) — a single column is a\n * legitimate table, and the first version of this regex demanded two. The trailing\n * whitespace is trimmed before the test for the same reason as {@link FENCE}: a\n * `\\s*\\|?\\s*$` tail backtracked quadratically on `- |` plus 50 000 spaces (#437).\n */\nconst TABLE_DELIMITER = /^\\s{0,3}\\|[\\s|:-]*$|^\\s{0,3}:?-+:?(\\s*\\|\\s*:?-+:?)+\\s*\\|?$/;\n\n/**\n * How deep quotes and lists may nest before the rest is read as a paragraph.\n *\n * Each level is one recursive {@link parseBlocks} call and one nested element in\n * the render, so `\"- \".repeat(20000)` used to throw `RangeError: Maximum call stack\n * size exceeded` out of the component (#437). Real documents stop at a handful of\n * levels; past this cap the words are kept, only the nesting is dropped.\n */\nconst MAX_NESTING_DEPTH = 32;\n\n/**\n * Match an ATX heading in linear time.\n *\n * The regex this replaces, `/^\\s{0,3}(#{1,6})\\s+(.*?)\\s*#*\\s*$/`, let a lazy `.*?`\n * and two `\\s*` race for the same run of spaces: `\"# a\" + \" \".repeat(4000) + \"b\"`\n * took about 4.7 s, cubic in the run (#437). Only the opening marker is a regex\n * now. The text is the rest of the line minus the longest suffix shaped like\n * `\\s*#*\\s*` — exactly what the lazy group left behind, so `# título #`,\n * `# título#` and `# #` read as before.\n *\n * @param line - One source line.\n * @returns The level and raw text, or `null` when the line is not a heading.\n */\nfunction matchHeading(line: string): { level: number; text: string } | null {\n const open = HEADING_OPEN.exec(line);\n if (!open) return null;\n let text = line.slice(open[0].length).trimEnd();\n let end = text.length;\n while (end > 0 && text[end - 1] === \"#\") end -= 1;\n text = text.slice(0, end).trimEnd();\n return { level: open[1].length, text };\n}\n\n/**\n * Whether a paragraph line ends in a hard break: two or more trailing spaces.\n *\n * `/ {2,}$/` was quadratic on a line with a long inner run of spaces — it retried\n * the run from every space and failed at the next word each time (0.57 s for\n * 50 000 spaces, #437).\n */\nfunction endsWithHardBreak(line: string): boolean {\n return line.endsWith(\" \");\n}\n\n/**\n * Parse a Markdown document into blocks.\n *\n * @param source - Raw Markdown.\n * @returns Block nodes in document order.\n */\nexport function parseMarkdown(source: string): MarkdownBlock[] {\n const lines = source.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n return parseBlocks(lines, 0);\n}\n\n/**\n * Parse a run of lines into blocks.\n *\n * @param lines - The lines of this container.\n * @param depth - How many quotes and lists enclose them. At\n * {@link MAX_NESTING_DEPTH} the lines become one paragraph instead of more\n * containers, so a hostile document cannot exhaust the stack.\n * @returns The blocks.\n */\nfunction parseBlocks(lines: string[], depth: number): MarkdownBlock[] {\n if (depth >= MAX_NESTING_DEPTH) {\n const source = lines\n .map((line) => line.trim())\n .filter(Boolean)\n .join(\"\\n\");\n return source ? [{ type: \"paragraph\", children: parseInline(source) }] : [];\n }\n const blocks: MarkdownBlock[] = [];\n let i = 0;\n\n while (i < lines.length) {\n const line = lines[i];\n\n if (line.trim() === \"\") {\n i += 1;\n continue;\n }\n\n const fence = FENCE.exec(line.trimEnd());\n if (fence) {\n const marker = fence[1][0];\n const body: string[] = [];\n i += 1;\n while (i < lines.length && !new RegExp(`^\\\\s{0,3}${marker}{3,}\\\\s*$`).test(lines[i])) {\n body.push(lines[i]);\n i += 1;\n }\n // An unterminated fence still yields a code block: the alternative is to\n // render the rest of the document as prose full of backticks.\n i += 1;\n blocks.push({ type: \"code\", language: fence[2] || null, value: body.join(\"\\n\") });\n continue;\n }\n\n const heading = matchHeading(line);\n if (heading) {\n blocks.push({\n type: \"heading\",\n level: heading.level,\n children: parseInline(heading.text),\n });\n i += 1;\n continue;\n }\n\n if (RULE.test(line)) {\n blocks.push({ type: \"rule\" });\n i += 1;\n continue;\n }\n\n if (QUOTE.test(line)) {\n const inner: string[] = [];\n while (i < lines.length) {\n const match = QUOTE.exec(lines[i]);\n if (match) {\n inner.push(match[1]);\n i += 1;\n continue;\n }\n // A blank line ends the quote; a plain line continues it (lazy\n // continuation), which is how people actually write quotes.\n if (lines[i].trim() === \"\") break;\n inner.push(lines[i]);\n i += 1;\n }\n blocks.push({ type: \"quote\", children: parseBlocks(inner, depth + 1) });\n continue;\n }\n\n if (BULLET.test(line) || ORDERED.test(line)) {\n const [list, next] = parseList(lines, i, depth);\n blocks.push(list);\n i = next;\n continue;\n }\n\n if (\n i + 1 < lines.length &&\n line.includes(\"|\") &&\n TABLE_DELIMITER.test(lines[i + 1].trimEnd())\n ) {\n const [table, next] = parseTable(lines, i);\n blocks.push(table);\n i = next;\n continue;\n }\n\n const paragraph: string[] = [];\n const hardBreaks: boolean[] = [];\n while (i < lines.length && lines[i].trim() !== \"\") {\n const current = lines[i];\n if (\n matchHeading(current) ||\n RULE.test(current) ||\n FENCE.test(current.trimEnd()) ||\n QUOTE.test(current) ||\n BULLET.test(current) ||\n ORDERED.test(current)\n ) {\n break;\n }\n paragraph.push(current.trim());\n hardBreaks.push(endsWithHardBreak(current));\n i += 1;\n }\n if (paragraph.length > 0) {\n blocks.push({\n type: \"paragraph\",\n children: parseInline(joinParagraph(paragraph, hardBreaks)),\n });\n }\n }\n\n return blocks;\n}\n\n/**\n * Re-join the lines of a paragraph, keeping the two-space hard break.\n *\n * Every line is trimmed before it is parsed, because leading indentation is not\n * content and a trailing space is invisible noise in almost every line. The one\n * exception is the CommonMark hard break: two or more trailing spaces mean\n * \"break the line here\", so trimming first would delete the only mark that says\n * so and the ` \\n` inline rule could never match. The flag is recorded before\n * the trim and the marker put back here, on every line but the last — a break\n * after the final line of a paragraph would break into nothing.\n *\n * @param lines - The trimmed lines, in order.\n * @param hardBreaks - Whether each line ended in two or more spaces.\n * @returns The paragraph source the inline parser reads.\n */\nfunction joinParagraph(lines: readonly string[], hardBreaks: readonly boolean[]): string {\n return lines\n .map((line, index) => (hardBreaks[index] && index < lines.length - 1 ? `${line} ` : line))\n .join(\"\\n\");\n}\n\n/**\n * Parse a list, including nested lists and multi-line items.\n *\n * Nesting is decided by indentation relative to the **first** item's marker, so a\n * list indented inside a quote or another list still reads correctly.\n *\n * @param lines - The lines of the enclosing container.\n * @param start - Index of the first item's line.\n * @param depth - Nesting depth of the enclosing container.\n * @returns The list node and the index of the first line after it.\n */\nfunction parseList(lines: string[], start: number, depth: number): [MarkdownBlock, number] {\n const bulletStart = BULLET.exec(lines[start]);\n const orderedStart = ORDERED.exec(lines[start]);\n // The two markers are mutually exclusive — `-*+` versus digits — so whichever\n // matched decides the list kind.\n const ordered = orderedStart !== null;\n const first = orderedStart ?? bulletStart;\n const baseIndent = (first?.[1] ?? \"\").length;\n const startNumber = ordered ? Number(orderedStart?.[2] ?? 1) : 1;\n\n const items: MarkdownBlock[][] = [];\n let buffer: string[] = [];\n let i = start;\n\n const flush = (): void => {\n if (buffer.length === 0) return;\n items.push(parseBlocks(buffer, depth + 1));\n buffer = [];\n };\n\n while (i < lines.length) {\n const line = lines[i];\n if (line.trim() === \"\") {\n // A single blank line inside a list is a loose item, not the end. Two in\n // a row end it, which is what a blank-then-paragraph document means.\n if (i + 1 < lines.length && lines[i + 1].trim() !== \"\") {\n buffer.push(\"\");\n i += 1;\n continue;\n }\n break;\n }\n const bullet = BULLET.exec(line);\n const numbered = ORDERED.exec(line);\n const match = bullet ?? numbered;\n\n if (match && match[1].length <= baseIndent) {\n const sameKind = ordered ? Boolean(numbered) : Boolean(bullet);\n if (!sameKind) break;\n flush();\n buffer.push(match[3]);\n i += 1;\n continue;\n }\n if (match) {\n // Deeper marker: keep the indentation so the recursive call sees a list.\n buffer.push(line.slice(baseIndent));\n i += 1;\n continue;\n }\n if (line.search(/\\S/) > baseIndent) {\n buffer.push(line.trim());\n i += 1;\n continue;\n }\n break;\n }\n flush();\n\n return [{ type: \"list\", ordered, start: startNumber, items }, i];\n}\n\n/** Split a table row on unescaped pipes. */\nfunction splitRow(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, \"\").replace(/\\|$/, \"\");\n const cells: string[] = [];\n let current = \"\";\n for (let i = 0; i < trimmed.length; i += 1) {\n if (trimmed[i] === \"\\\\\" && trimmed[i + 1] === \"|\") {\n current += \"|\";\n i += 1;\n continue;\n }\n if (trimmed[i] === \"|\") {\n cells.push(current);\n current = \"\";\n continue;\n }\n current += trimmed[i];\n }\n cells.push(current);\n return cells.map((cell) => cell.trim());\n}\n\n/**\n * Parse a GFM pipe table.\n *\n * @returns The table node and the index of the first line after it.\n */\nfunction parseTable(lines: string[], start: number): [MarkdownBlock, number] {\n const head = splitRow(lines[start]);\n const align: MarkdownAlign[] = splitRow(lines[start + 1]).map((cell) => {\n const left = cell.startsWith(\":\");\n const right = cell.endsWith(\":\");\n if (left && right) return \"center\";\n if (right) return \"right\";\n if (left) return \"left\";\n return null;\n });\n\n const rows: MarkdownInline[][][] = [];\n let i = start + 2;\n while (i < lines.length && lines[i].trim() !== \"\" && lines[i].includes(\"|\")) {\n rows.push(splitRow(lines[i]).map(parseInline));\n i += 1;\n }\n\n return [{ type: \"table\", align, head: head.map(parseInline), rows }, i];\n}\n\n/**\n * The precheck a rule needs before its pattern may run, keyed by the opener the\n * pattern starts with.\n *\n * `link` covers links and images, whose label ends at the first `]`; `autolink`\n * covers `<scheme:...>`, which ends at the first `>` or whitespace. Without the\n * precheck each pattern scanned to the end of the text from every opener, and\n * `\"[\".repeat(50000)` took 0.6 s (#437).\n */\ntype InlineGuard = { kind: \"link\"; opener: \"[\" | \"![\" } | { kind: \"autolink\"; opener: \"<\" };\n\n/** Inline delimiters, longest marker first so `**` wins over `*`. */\nconst INLINE_RULES: Array<{\n first: string;\n pattern: RegExp;\n guard?: InlineGuard;\n build: (match: RegExpExecArray) => MarkdownInline | null;\n}> = [\n {\n guard: { kind: \"link\", opener: \"![\" },\n first: \"!\",\n pattern: /^!\\[([^\\]]*)\\]\\(((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?\\)/,\n build: (match) => {\n const src = safeImageUrl(match[2]);\n return src ? { type: \"image\", src, alt: match[1] } : { type: \"text\", value: match[1] };\n },\n },\n {\n guard: { kind: \"link\", opener: \"[\" },\n first: \"[\",\n pattern: /^\\[([^\\]]*)\\]\\(((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?\\)/,\n build: (match) => {\n const href = safeLinkUrl(match[2]);\n const children = parseInline(match[1]);\n // A rejected URL keeps the label as plain text: dropping the text too\n // would silently delete words somebody wrote.\n return href ? { type: \"link\", href, children } : { type: \"text\", value: match[1] };\n },\n },\n { first: \"`\", pattern: /^`([^`]+)`/, build: (match) => ({ type: \"code\", value: match[1] }) },\n {\n first: \"*\",\n pattern: /^\\*\\*([\\s\\S]+?)\\*\\*/,\n build: (match) => ({ type: \"strong\", children: parseInline(match[1]) }),\n },\n {\n first: \"_\",\n pattern: /^__([\\s\\S]+?)__/,\n build: (match) => ({ type: \"strong\", children: parseInline(match[1]) }),\n },\n {\n first: \"~\",\n pattern: /^~~([\\s\\S]+?)~~/,\n build: (match) => ({ type: \"del\", children: parseInline(match[1]) }),\n },\n {\n first: \"*\",\n pattern: /^\\*([^*\\n]+)\\*/,\n build: (match) => ({ type: \"em\", children: parseInline(match[1]) }),\n },\n {\n first: \"_\",\n pattern: /^_([^_\\n]+)_/,\n build: (match) => ({ type: \"em\", children: parseInline(match[1]) }),\n },\n {\n guard: { kind: \"autolink\", opener: \"<\" },\n first: \"<\",\n pattern: /^<((?:https?:\\/\\/|mailto:)[^>\\s]+)>/,\n build: (match) => {\n const href = safeLinkUrl(match[1]);\n return href\n ? { type: \"link\", href, children: [{ type: \"text\", value: match[1] }] }\n : { type: \"text\", value: match[1] };\n },\n },\n { first: \"\\\\\", pattern: /^\\\\\\n/, build: () => ({ type: \"break\" }) },\n];\n\n/** Characters some inline rule can start with; any other character is text. */\nconst INLINE_FIRST = new Set(INLINE_RULES.map((rule) => rule.first));\n\n/**\n * Parse inline Markdown.\n *\n * A backslash escapes the next character, so `\\*not italic\\*` renders with the\n * asterisks. Anything that matches no rule is text — an unclosed `**` is two\n * asterisks, not a bold run to the end of the paragraph.\n *\n * The parse is linear in the text, which matters because the text is somebody\n * else's (#437):\n *\n * - A run of spaces is consumed whole: it is a hard break when two or more of them\n * end at a newline, and text otherwise. Matching `^ {2,}\\n` from every space\n * rescanned the run each time.\n * - A link or image label ends at the first `]` after the opener, so every opener\n * before the same `]` shares the same `](...)` tail. The position of that `]` is\n * cached, an opener whose `]` is not followed by `(` is skipped without running\n * the pattern, and once a tail has failed no later opener retries it.\n * - An autolink ends at the first `>` or whitespace, also cached; when that stop\n * is not `>` the pattern cannot match and is not run.\n * - A rule runs only at its own first character, so a run of `[` costs one set\n * lookup per character instead of every pattern in the table.\n *\n * @param source - One block's text.\n * @returns Inline nodes.\n */\nexport function parseInline(source: string): MarkdownInline[] {\n const nodes: MarkdownInline[] = [];\n let text = \"\";\n let i = 0;\n\n let bracketAt = -1;\n let deadTailAt = -1;\n let stopAt = -1;\n const stops = /[>\\s]/g;\n\n const flush = (): void => {\n if (text) nodes.push({ type: \"text\", value: text });\n text = \"\";\n };\n\n const closingBracket = (from: number): number => {\n if (bracketAt < from) {\n const found = source.indexOf(\"]\", from);\n bracketAt = found === -1 ? source.length : found;\n }\n return bracketAt;\n };\n\n const autolinkStop = (from: number): number => {\n if (stopAt < from) {\n stops.lastIndex = from;\n stopAt = stops.exec(source)?.index ?? source.length;\n }\n return stopAt;\n };\n\n const allowed = (guard: InlineGuard | undefined): boolean => {\n if (!guard) return true;\n if (!source.startsWith(guard.opener, i)) return false;\n if (guard.kind === \"autolink\") return source[autolinkStop(i + 1)] === \">\";\n const close = closingBracket(i + guard.opener.length);\n return source[close + 1] === \"(\" && close !== deadTailAt;\n };\n\n while (i < source.length) {\n if (source[i] === \"\\\\\" && i + 1 < source.length && source[i + 1] !== \"\\n\") {\n text += source[i + 1];\n i += 2;\n continue;\n }\n\n if (source[i] === \" \") {\n let end = i;\n while (source[end] === \" \") end += 1;\n if (end - i >= 2 && source[end] === \"\\n\") {\n flush();\n nodes.push({ type: \"break\" });\n i = end + 1;\n } else {\n text += source.slice(i, end);\n i = end;\n }\n continue;\n }\n\n if (!INLINE_FIRST.has(source[i])) {\n text += source[i];\n i += 1;\n continue;\n }\n\n const rest = source.slice(i);\n let matched = false;\n for (const rule of INLINE_RULES) {\n if (rule.first !== source[i] || !allowed(rule.guard)) continue;\n const match = rule.pattern.exec(rest);\n if (!match) {\n if (rule.guard?.kind === \"link\") {\n deadTailAt = closingBracket(i + rule.guard.opener.length);\n }\n continue;\n }\n const node = rule.build(match);\n if (!node) continue;\n flush();\n nodes.push(node);\n i += match[0].length;\n matched = true;\n break;\n }\n if (matched) continue;\n\n text += source[i];\n i += 1;\n }\n\n flush();\n return nodes;\n}\n"],"mappings":";;AA0DA,IAAM,IAAQ,sCAKR,IAAe,uBACf,IAAO,oCACP,IAAQ,qBACR,IAAS,yBACT,IAAU,+BAUV,IAAkB,8DAUlB,IAAoB;AAe1B,SAAS,EAAa,GAAsD;CACxE,IAAM,IAAO,EAAa,KAAK,CAAI;CACnC,IAAI,CAAC,GAAM,OAAO;CAClB,IAAI,IAAO,EAAK,MAAM,EAAK,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,GAC1C,IAAM,EAAK;CACf,OAAO,IAAM,KAAK,EAAK,IAAM,OAAO,MAAK;CAEzC,OADA,IAAO,EAAK,MAAM,GAAG,CAAG,CAAC,CAAC,QAAQ,GAC3B;EAAE,OAAO,EAAK,EAAE,CAAC;EAAQ;CAAK;AACzC;AASA,SAAS,EAAkB,GAAuB;CAC9C,OAAO,EAAK,SAAS,IAAI;AAC7B;AAQA,SAAgB,EAAc,GAAiC;CAE3D,OAAO,EADO,EAAO,QAAQ,UAAU,IAAI,CAAC,CAAC,MAAM,IAChC,GAAO,CAAC;AAC/B;AAWA,SAAS,EAAY,GAAiB,GAAgC;CAClE,IAAI,KAAS,GAAmB;EAC5B,IAAM,IAAS,EACV,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,IAAI;GAER;EACJ;EAEA,IAAI,CAAC,EAAa,IAAI,EAAO,EAAE,GAAG;GAE9B,AADA,KAAQ,EAAO,IACf,KAAK;GACL;EACJ;EAEA,IAAM,IAAO,EAAO,MAAM,CAAC,GACvB,IAAU;EACd,KAAK,IAAM,KAAQ,GAAc;GAC7B,IAAI,EAAK,UAAU,EAAO,MAAM,CAAC,EAAQ,EAAK,KAAK,GAAG;GACtD,IAAM,IAAQ,EAAK,QAAQ,KAAK,CAAI;GACpC,IAAI,CAAC,GAAO;IACR,AAAI,EAAK,OAAO,SAAS,WACrB,IAAa,EAAe,IAAI,EAAK,MAAM,OAAO,MAAM;IAE5D;GACJ;GACA,IAAM,IAAO,EAAK,MAAM,CAAK;GACxB,OAIL;IAHA,EAAM,GACN,EAAM,KAAK,CAAI,GACf,KAAK,EAAM,EAAE,CAAC,QACd,IAAU;IACV;GADU;EAEd;EACI,MAEJ,KAAQ,EAAO,IACf,KAAK;CACT;CAGA,OADA,EAAM,GACC;AACX"}
|
|
1
|
+
{"version":3,"file":"markdown-parse.js","names":[],"sources":["../../../src/components/Markdown/markdown-parse.ts"],"sourcesContent":["/**\n * @tempest-limits file-lines, function-lines — a Markdown block parser is a state\n * machine over line kinds: paragraph, heading, fence, list, quote, table and\n * thematic break each need to see the lines around them to know where they end.\n * parseBlocks is that loop, and cutting it into per-kind functions would hand each\n * one the same lookahead cursor.\n */\n// A small Markdown parser for the subset an app actually renders from untrusted\n// text: comments, ticket bodies, release notes, a product description.\n//\n// It produces a node tree, never an HTML string, and the renderer turns that into\n// React elements. No `dangerouslySetInnerHTML` exists anywhere in this component —\n// which is the property that makes rendering somebody else's Markdown safe, and it\n// is structural rather than a promise about escaping.\n//\n// Raw HTML in the input is therefore not \"sanitized\", it is **text**: `<script>` in\n// a comment renders as the four characters somebody typed. That is the whole point,\n// and it is also the documented limit — this is not a CommonMark implementation and\n// does not try to be.\n\nimport { safeImageUrl, safeLinkUrl } from \"@/utils/safe-url\";\n\n/** Inline content. */\nexport type MarkdownInline =\n | { type: \"text\"; value: string }\n | { type: \"strong\"; children: MarkdownInline[] }\n | { type: \"em\"; children: MarkdownInline[] }\n | { type: \"del\"; children: MarkdownInline[] }\n | { type: \"code\"; value: string }\n | { type: \"link\"; href: string; children: MarkdownInline[] }\n | { type: \"image\"; src: string; alt: string }\n | { type: \"break\" };\n\n/** Column alignment of a table, from the delimiter row. */\nexport type MarkdownAlign = \"left\" | \"center\" | \"right\" | null;\n\n/** Block content. */\nexport type MarkdownBlock =\n | { type: \"heading\"; level: number; children: MarkdownInline[] }\n | { type: \"paragraph\"; children: MarkdownInline[] }\n | { type: \"code\"; language: string | null; value: string }\n | { type: \"quote\"; children: MarkdownBlock[] }\n | { type: \"list\"; ordered: boolean; start: number; items: MarkdownBlock[][] }\n | {\n type: \"table\";\n align: MarkdownAlign[];\n head: MarkdownInline[][];\n rows: MarkdownInline[][][];\n }\n | { type: \"rule\" };\n\n/**\n * A fence opener, matched against the line **after** `trimEnd()`.\n *\n * The trailing `\\s*` lives in the `trimEnd()` rather than in the pattern: with it,\n * `\\s*([\\w+-]*)\\s*$` is two whitespace quantifiers separated by one that may be\n * empty, and a fence followed by 20 000 spaces and a stray `!` took 0.36 s (#437).\n */\nconst FENCE = /^\\s{0,3}(`{3,}|~{3,})\\s*([\\w+-]*)$/;\n/**\n * The opening marker of an ATX heading. The text and the optional closing `#` run\n * are cut by {@link matchHeading} with string operations, not by this pattern.\n */\nconst HEADING_OPEN = /^\\s{0,3}(#{1,6})\\s+/;\nconst RULE = /^\\s{0,3}([-*_])\\s*(?:\\1\\s*){2,}$/;\nconst QUOTE = /^\\s{0,3}>\\s?(.*)$/;\n/**\n * The opener of a list item: indentation, marker and the whitespace that\n * separates the marker from the content.\n *\n * The content is sliced off with a string operation rather than captured,\n * because it may not hold U+2028/U+2029. Those are line terminators the old\n * `(.*)$` could not cross, so a line with one after the marker was a paragraph\n * and has to stay one. Capturing the content with a regex that stops at them (a\n * `[^\\u2028\\u2029]*`) would put the separator and the content back to racing for\n * a run of spaces — quadratic, 3.6 s for a bullet padded with 80 000 spaces\n * (#478). Matching only the opener and slicing sidesteps that entirely.\n *\n * The separator is `[^\\S\\n\\r]`: every whitespace character except CR and LF,\n * which a line never contains. That keeps a separator a person pastes from Word\n * or Docs — NBSP, a form feed, a leading BOM — reading as a list, exactly as the\n * old `\\s+` did, instead of silently turning the line into a paragraph.\n */\nconst BULLET_OPENER = /^([^\\S\\n\\r]*)([-*+])[^\\S\\n\\r]+/;\nconst ORDERED_OPENER = /^([^\\S\\n\\r]*)(\\d{1,9})[.)][^\\S\\n\\r]+/;\n\n/** A list item's opener: how far it is indented, its marker and its content. */\ninterface ListOpener {\n indent: string;\n marker: string;\n content: string;\n}\n\n/**\n * Read a list item's opener, or `null` when the line is not one.\n *\n * A line whose content holds U+2028/U+2029 is not a list item: the old `(.*)$`\n * stopped at the separator, never reached `$`, and left the line a paragraph,\n * and {@link parseMarkdown} still splits only on `\\n` and `\\r`. Keeping that\n * here is what lets the opener stay a plain pattern with no `.*` to race.\n *\n * @param pattern - {@link BULLET_OPENER} or {@link ORDERED_OPENER}.\n * @param line - One source line.\n * @returns The opener, or `null` when the line is not a list item.\n */\nfunction matchListOpener(pattern: RegExp, line: string): ListOpener | null {\n const match = pattern.exec(line);\n if (!match) return null;\n const content = line.slice(match[0].length);\n if (content.includes(\"\\u2028\") || content.includes(\"\\u2029\")) return null;\n return { indent: match[1], marker: match[2], content };\n}\n\n/** {@link matchListOpener} for a bullet. */\nfunction matchBullet(line: string): ListOpener | null {\n return matchListOpener(BULLET_OPENER, line);\n}\n\n/** {@link matchListOpener} for an ordered marker. */\nfunction matchOrdered(line: string): ListOpener | null {\n return matchListOpener(ORDERED_OPENER, line);\n}\n/**\n * A table's delimiter row, matched against the line **after** `trimEnd()`.\n *\n * The `|` is required somewhere in the line, and that is what tells a one-column\n * table (`| --- |`) apart from a thematic break (`---`) — a single column is a\n * legitimate table, and the first version of this regex demanded two. The trailing\n * whitespace is trimmed before the test for the same reason as {@link FENCE}: a\n * `\\s*\\|?\\s*$` tail backtracked quadratically on `- |` plus 50 000 spaces (#437).\n */\nconst TABLE_DELIMITER = /^\\s{0,3}\\|[\\s|:-]*$|^\\s{0,3}:?-+:?(\\s*\\|\\s*:?-+:?)+\\s*\\|?$/;\n\n/**\n * How deep quotes and lists may nest before the rest is read as a paragraph.\n *\n * Each level is one recursive {@link parseBlocks} call and one nested element in\n * the render, so `\"- \".repeat(20000)` used to throw `RangeError: Maximum call stack\n * size exceeded` out of the component (#437). Real documents stop at a handful of\n * levels; past this cap the words are kept, only the nesting is dropped.\n */\nconst MAX_NESTING_DEPTH = 32;\n\n/**\n * Match an ATX heading in linear time.\n *\n * The regex this replaces, `/^\\s{0,3}(#{1,6})\\s+(.*?)\\s*#*\\s*$/`, let a lazy `.*?`\n * and two `\\s*` race for the same run of spaces: `\"# a\" + \" \".repeat(4000) + \"b\"`\n * took about 4.7 s, cubic in the run (#437). Only the opening marker is a regex\n * now. The text is the rest of the line minus the longest suffix shaped like\n * `\\s*#*\\s*` — exactly what the lazy group left behind, so `# título #`,\n * `# título#` and `# #` read as before.\n *\n * @param line - One source line.\n * @returns The level and raw text, or `null` when the line is not a heading.\n */\nfunction matchHeading(line: string): { level: number; text: string } | null {\n const open = HEADING_OPEN.exec(line);\n if (!open) return null;\n let text = line.slice(open[0].length).trimEnd();\n let end = text.length;\n while (end > 0 && text[end - 1] === \"#\") end -= 1;\n text = text.slice(0, end).trimEnd();\n return { level: open[1].length, text };\n}\n\n/**\n * Whether a paragraph line ends in a hard break: two or more trailing spaces.\n *\n * `/ {2,}$/` was quadratic on a line with a long inner run of spaces — it retried\n * the run from every space and failed at the next word each time (0.57 s for\n * 50 000 spaces, #437).\n */\nfunction endsWithHardBreak(line: string): boolean {\n return line.endsWith(\" \");\n}\n\n/**\n * Parse a Markdown document into blocks.\n *\n * @param source - Raw Markdown.\n * @returns Block nodes in document order.\n */\nexport function parseMarkdown(source: string): MarkdownBlock[] {\n const lines = source.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n return parseBlocks(lines, 0);\n}\n\n/**\n * Parse a run of lines into blocks.\n *\n * @param lines - The lines of this container.\n * @param depth - How many quotes and lists enclose them. At\n * {@link MAX_NESTING_DEPTH} the lines become one paragraph instead of more\n * containers, so a hostile document cannot exhaust the stack.\n * @returns The blocks.\n */\nfunction parseBlocks(lines: string[], depth: number): MarkdownBlock[] {\n if (depth >= MAX_NESTING_DEPTH) {\n const source = lines\n .map((line) => line.trim())\n .filter(Boolean)\n .join(\"\\n\");\n return source ? [{ type: \"paragraph\", children: parseInline(source) }] : [];\n }\n const blocks: MarkdownBlock[] = [];\n let i = 0;\n\n while (i < lines.length) {\n const line = lines[i];\n\n if (line.trim() === \"\") {\n i += 1;\n continue;\n }\n\n const fence = FENCE.exec(line.trimEnd());\n if (fence) {\n const marker = fence[1][0];\n const body: string[] = [];\n i += 1;\n while (i < lines.length && !new RegExp(`^\\\\s{0,3}${marker}{3,}\\\\s*$`).test(lines[i])) {\n body.push(lines[i]);\n i += 1;\n }\n // An unterminated fence still yields a code block: the alternative is to\n // render the rest of the document as prose full of backticks.\n i += 1;\n blocks.push({ type: \"code\", language: fence[2] || null, value: body.join(\"\\n\") });\n continue;\n }\n\n const heading = matchHeading(line);\n if (heading) {\n blocks.push({\n type: \"heading\",\n level: heading.level,\n children: parseInline(heading.text),\n });\n i += 1;\n continue;\n }\n\n if (RULE.test(line)) {\n blocks.push({ type: \"rule\" });\n i += 1;\n continue;\n }\n\n if (QUOTE.test(line)) {\n const inner: string[] = [];\n while (i < lines.length) {\n const match = QUOTE.exec(lines[i]);\n if (match) {\n inner.push(match[1]);\n i += 1;\n continue;\n }\n // A blank line ends the quote; a plain line continues it (lazy\n // continuation), which is how people actually write quotes.\n if (lines[i].trim() === \"\") break;\n inner.push(lines[i]);\n i += 1;\n }\n blocks.push({ type: \"quote\", children: parseBlocks(inner, depth + 1) });\n continue;\n }\n\n if (matchBullet(line) || matchOrdered(line)) {\n const [list, next] = parseList(lines, i, depth);\n blocks.push(list);\n i = next;\n continue;\n }\n\n if (\n i + 1 < lines.length &&\n line.includes(\"|\") &&\n TABLE_DELIMITER.test(lines[i + 1].trimEnd())\n ) {\n const [table, next] = parseTable(lines, i);\n blocks.push(table);\n i = next;\n continue;\n }\n\n const paragraph: string[] = [];\n const hardBreaks: boolean[] = [];\n while (i < lines.length && lines[i].trim() !== \"\") {\n const current = lines[i];\n if (\n matchHeading(current) ||\n RULE.test(current) ||\n FENCE.test(current.trimEnd()) ||\n QUOTE.test(current) ||\n matchBullet(current) ||\n matchOrdered(current)\n ) {\n break;\n }\n paragraph.push(current.trim());\n hardBreaks.push(endsWithHardBreak(current));\n i += 1;\n }\n if (paragraph.length > 0) {\n blocks.push({\n type: \"paragraph\",\n children: parseInline(joinParagraph(paragraph, hardBreaks)),\n });\n }\n }\n\n return blocks;\n}\n\n/**\n * Re-join the lines of a paragraph, keeping the two-space hard break.\n *\n * Every line is trimmed before it is parsed, because leading indentation is not\n * content and a trailing space is invisible noise in almost every line. The one\n * exception is the CommonMark hard break: two or more trailing spaces mean\n * \"break the line here\", so trimming first would delete the only mark that says\n * so and the ` \\n` inline rule could never match. The flag is recorded before\n * the trim and the marker put back here, on every line but the last — a break\n * after the final line of a paragraph would break into nothing.\n *\n * @param lines - The trimmed lines, in order.\n * @param hardBreaks - Whether each line ended in two or more spaces.\n * @returns The paragraph source the inline parser reads.\n */\nfunction joinParagraph(lines: readonly string[], hardBreaks: readonly boolean[]): string {\n return lines\n .map((line, index) => (hardBreaks[index] && index < lines.length - 1 ? `${line} ` : line))\n .join(\"\\n\");\n}\n\n/**\n * Parse a list, including nested lists and multi-line items.\n *\n * Nesting is decided by indentation relative to the **first** item's marker, so a\n * list indented inside a quote or another list still reads correctly.\n *\n * @param lines - The lines of the enclosing container.\n * @param start - Index of the first item's line.\n * @param depth - Nesting depth of the enclosing container.\n * @returns The list node and the index of the first line after it.\n */\nfunction parseList(lines: string[], start: number, depth: number): [MarkdownBlock, number] {\n const bulletStart = matchBullet(lines[start]);\n const orderedStart = matchOrdered(lines[start]);\n // The two markers are mutually exclusive — `-*+` versus digits — so whichever\n // matched decides the list kind.\n const ordered = orderedStart !== null;\n const first = orderedStart ?? bulletStart;\n const baseIndent = first?.indent.length ?? 0;\n const startNumber = ordered ? Number(orderedStart?.marker ?? 1) : 1;\n\n const items: MarkdownBlock[][] = [];\n let buffer: string[] = [];\n let i = start;\n\n const flush = (): void => {\n if (buffer.length === 0) return;\n items.push(parseBlocks(buffer, depth + 1));\n buffer = [];\n };\n\n while (i < lines.length) {\n const line = lines[i];\n if (line.trim() === \"\") {\n // A single blank line inside a list is a loose item, not the end. Two in\n // a row end it, which is what a blank-then-paragraph document means.\n if (i + 1 < lines.length && lines[i + 1].trim() !== \"\") {\n buffer.push(\"\");\n i += 1;\n continue;\n }\n break;\n }\n const bullet = matchBullet(line);\n const numbered = matchOrdered(line);\n const match = bullet ?? numbered;\n\n if (match && match.indent.length <= baseIndent) {\n const sameKind = ordered ? Boolean(numbered) : Boolean(bullet);\n if (!sameKind) break;\n flush();\n buffer.push(match.content);\n i += 1;\n continue;\n }\n if (match) {\n // Deeper marker: keep the indentation so the recursive call sees a list.\n buffer.push(line.slice(baseIndent));\n i += 1;\n continue;\n }\n if (line.search(/\\S/) > baseIndent) {\n buffer.push(line.trim());\n i += 1;\n continue;\n }\n break;\n }\n flush();\n\n return [{ type: \"list\", ordered, start: startNumber, items }, i];\n}\n\n/** Split a table row on unescaped pipes. */\nfunction splitRow(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, \"\").replace(/\\|$/, \"\");\n const cells: string[] = [];\n let current = \"\";\n for (let i = 0; i < trimmed.length; i += 1) {\n if (trimmed[i] === \"\\\\\" && trimmed[i + 1] === \"|\") {\n current += \"|\";\n i += 1;\n continue;\n }\n if (trimmed[i] === \"|\") {\n cells.push(current);\n current = \"\";\n continue;\n }\n current += trimmed[i];\n }\n cells.push(current);\n return cells.map((cell) => cell.trim());\n}\n\n/**\n * Parse a GFM pipe table.\n *\n * @returns The table node and the index of the first line after it.\n */\nfunction parseTable(lines: string[], start: number): [MarkdownBlock, number] {\n const head = splitRow(lines[start]);\n const align: MarkdownAlign[] = splitRow(lines[start + 1]).map((cell) => {\n const left = cell.startsWith(\":\");\n const right = cell.endsWith(\":\");\n if (left && right) return \"center\";\n if (right) return \"right\";\n if (left) return \"left\";\n return null;\n });\n\n const rows: MarkdownInline[][][] = [];\n let i = start + 2;\n while (i < lines.length && lines[i].trim() !== \"\" && lines[i].includes(\"|\")) {\n rows.push(splitRow(lines[i]).map(parseInline));\n i += 1;\n }\n\n return [{ type: \"table\", align, head: head.map(parseInline), rows }, i];\n}\n\n/**\n * The precheck a rule needs before its pattern may run, keyed by the opener the\n * pattern starts with.\n *\n * `link` covers links and images, whose label ends at the first `]`; `autolink`\n * covers `<scheme:...>`, which ends at the first `>` or whitespace. Without the\n * precheck each pattern scanned to the end of the text from every opener, and\n * `\"[\".repeat(50000)` took 0.6 s (#437).\n */\ntype InlineGuard = { kind: \"link\"; opener: \"[\" | \"![\" } | { kind: \"autolink\"; opener: \"<\" };\n\n/** Inline delimiters, longest marker first so `**` wins over `*`. */\nconst INLINE_RULES: Array<{\n first: string;\n pattern: RegExp;\n guard?: InlineGuard;\n build: (match: RegExpExecArray) => MarkdownInline | null;\n}> = [\n {\n guard: { kind: \"link\", opener: \"![\" },\n first: \"!\",\n pattern: /^!\\[([^\\]]*)\\]\\(((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?\\)/,\n build: (match) => {\n const src = safeImageUrl(match[2]);\n return src ? { type: \"image\", src, alt: match[1] } : { type: \"text\", value: match[1] };\n },\n },\n {\n guard: { kind: \"link\", opener: \"[\" },\n first: \"[\",\n pattern: /^\\[([^\\]]*)\\]\\(((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?\\)/,\n build: (match) => {\n const href = safeLinkUrl(match[2]);\n const children = parseInline(match[1]);\n // A rejected URL keeps the label as plain text: dropping the text too\n // would silently delete words somebody wrote.\n return href ? { type: \"link\", href, children } : { type: \"text\", value: match[1] };\n },\n },\n { first: \"`\", pattern: /^`([^`]+)`/, build: (match) => ({ type: \"code\", value: match[1] }) },\n {\n first: \"*\",\n pattern: /^\\*\\*([\\s\\S]+?)\\*\\*/,\n build: (match) => ({ type: \"strong\", children: parseInline(match[1]) }),\n },\n {\n first: \"_\",\n pattern: /^__([\\s\\S]+?)__/,\n build: (match) => ({ type: \"strong\", children: parseInline(match[1]) }),\n },\n {\n first: \"~\",\n pattern: /^~~([\\s\\S]+?)~~/,\n build: (match) => ({ type: \"del\", children: parseInline(match[1]) }),\n },\n {\n first: \"*\",\n pattern: /^\\*([^*\\n]+)\\*/,\n build: (match) => ({ type: \"em\", children: parseInline(match[1]) }),\n },\n {\n first: \"_\",\n pattern: /^_([^_\\n]+)_/,\n build: (match) => ({ type: \"em\", children: parseInline(match[1]) }),\n },\n {\n guard: { kind: \"autolink\", opener: \"<\" },\n first: \"<\",\n pattern: /^<((?:https?:\\/\\/|mailto:)[^>\\s]+)>/,\n build: (match) => {\n const href = safeLinkUrl(match[1]);\n return href\n ? { type: \"link\", href, children: [{ type: \"text\", value: match[1] }] }\n : { type: \"text\", value: match[1] };\n },\n },\n { first: \"\\\\\", pattern: /^\\\\\\n/, build: () => ({ type: \"break\" }) },\n];\n\n/** Characters some inline rule can start with; any other character is text. */\nconst INLINE_FIRST = new Set(INLINE_RULES.map((rule) => rule.first));\n\n/**\n * Parse inline Markdown.\n *\n * A backslash escapes the next character, so `\\*not italic\\*` renders with the\n * asterisks. Anything that matches no rule is text — an unclosed `**` is two\n * asterisks, not a bold run to the end of the paragraph.\n *\n * The parse is linear in the text, which matters because the text is somebody\n * else's (#437):\n *\n * - A run of spaces is consumed whole: it is a hard break when two or more of them\n * end at a newline, and text otherwise. Matching `^ {2,}\\n` from every space\n * rescanned the run each time.\n * - A link or image label ends at the first `]` after the opener, so every opener\n * before the same `]` shares the same `](...)` tail. The position of that `]` is\n * cached, an opener whose `]` is not followed by `(` is skipped without running\n * the pattern, and once a tail has failed no later opener retries it.\n * - An autolink ends at the first `>` or whitespace, also cached; when that stop\n * is not `>` the pattern cannot match and is not run.\n * - A rule runs only at its own first character, so a run of `[` costs one set\n * lookup per character instead of every pattern in the table.\n *\n * @param source - One block's text.\n * @returns Inline nodes.\n */\nexport function parseInline(source: string): MarkdownInline[] {\n const nodes: MarkdownInline[] = [];\n let text = \"\";\n let i = 0;\n\n let bracketAt = -1;\n let deadTailAt = -1;\n let stopAt = -1;\n const stops = /[>\\s]/g;\n\n const flush = (): void => {\n if (text) nodes.push({ type: \"text\", value: text });\n text = \"\";\n };\n\n const closingBracket = (from: number): number => {\n if (bracketAt < from) {\n const found = source.indexOf(\"]\", from);\n bracketAt = found === -1 ? source.length : found;\n }\n return bracketAt;\n };\n\n const autolinkStop = (from: number): number => {\n if (stopAt < from) {\n stops.lastIndex = from;\n stopAt = stops.exec(source)?.index ?? source.length;\n }\n return stopAt;\n };\n\n const allowed = (guard: InlineGuard | undefined): boolean => {\n if (!guard) return true;\n if (!source.startsWith(guard.opener, i)) return false;\n if (guard.kind === \"autolink\") return source[autolinkStop(i + 1)] === \">\";\n const close = closingBracket(i + guard.opener.length);\n return source[close + 1] === \"(\" && close !== deadTailAt;\n };\n\n while (i < source.length) {\n if (source[i] === \"\\\\\" && i + 1 < source.length && source[i + 1] !== \"\\n\") {\n text += source[i + 1];\n i += 2;\n continue;\n }\n\n if (source[i] === \" \") {\n let end = i;\n while (source[end] === \" \") end += 1;\n if (end - i >= 2 && source[end] === \"\\n\") {\n flush();\n nodes.push({ type: \"break\" });\n i = end + 1;\n } else {\n text += source.slice(i, end);\n i = end;\n }\n continue;\n }\n\n if (!INLINE_FIRST.has(source[i])) {\n text += source[i];\n i += 1;\n continue;\n }\n\n const rest = source.slice(i);\n let matched = false;\n for (const rule of INLINE_RULES) {\n if (rule.first !== source[i] || !allowed(rule.guard)) continue;\n const match = rule.pattern.exec(rest);\n if (!match) {\n if (rule.guard?.kind === \"link\") {\n deadTailAt = closingBracket(i + rule.guard.opener.length);\n }\n continue;\n }\n const node = rule.build(match);\n if (!node) continue;\n flush();\n nodes.push(node);\n i += match[0].length;\n matched = true;\n break;\n }\n if (matched) continue;\n\n text += source[i];\n i += 1;\n }\n\n flush();\n return nodes;\n}\n"],"mappings":";;AA0DA,IAAM,IAAQ,sCAKR,IAAe,uBACf,IAAO,oCACP,IAAQ,qBAkBR,IAAgB,kCAChB,IAAiB;AAqBvB,SAAS,EAAgB,GAAiB,GAAiC;CACvE,IAAM,IAAQ,EAAQ,KAAK,CAAI;CAC/B,IAAI,CAAC,GAAO,OAAO;CACnB,IAAM,IAAU,EAAK,MAAM,EAAM,EAAE,CAAC,MAAM;CAE1C,OADI,EAAQ,SAAS,QAAQ,KAAK,EAAQ,SAAS,QAAQ,IAAU,OAC9D;EAAE,QAAQ,EAAM;EAAI,QAAQ,EAAM;EAAI;CAAQ;AACzD;AAGA,SAAS,EAAY,GAAiC;CAClD,OAAO,EAAgB,GAAe,CAAI;AAC9C;AAGA,SAAS,EAAa,GAAiC;CACnD,OAAO,EAAgB,GAAgB,CAAI;AAC/C;AAUA,IAAM,IAAkB,8DAUlB,IAAoB;AAe1B,SAAS,EAAa,GAAsD;CACxE,IAAM,IAAO,EAAa,KAAK,CAAI;CACnC,IAAI,CAAC,GAAM,OAAO;CAClB,IAAI,IAAO,EAAK,MAAM,EAAK,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,GAC1C,IAAM,EAAK;CACf,OAAO,IAAM,KAAK,EAAK,IAAM,OAAO,MAAK;CAEzC,OADA,IAAO,EAAK,MAAM,GAAG,CAAG,CAAC,CAAC,QAAQ,GAC3B;EAAE,OAAO,EAAK,EAAE,CAAC;EAAQ;CAAK;AACzC;AASA,SAAS,EAAkB,GAAuB;CAC9C,OAAO,EAAK,SAAS,IAAI;AAC7B;AAQ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EAAO,OAAS,QAChC,EAAM,GACN,EAAM,KAAK,EAAE,MAAM,QAAQ,CAAC,GAC5B,IAAI,IAAM,MAEV,KAAQ,EAAO,MAAM,GAAG,CAAG,GAC3B,IAAI;GAER;EACJ;EAEA,IAAI,CAAC,EAAa,IAAI,EAAO,EAAE,GAAG;GAE9B,AADA,KAAQ,EAAO,IACf,KAAK;GACL;EACJ;EAEA,IAAM,IAAO,EAAO,MAAM,CAAC,GACvB,IAAU;EACd,KAAK,IAAM,KAAQ,GAAc;GAC7B,IAAI,EAAK,UAAU,EAAO,MAAM,CAAC,EAAQ,EAAK,KAAK,GAAG;GACtD,IAAM,IAAQ,EAAK,QAAQ,KAAK,CAAI;GACpC,IAAI,CAAC,GAAO;IACR,AAAI,EAAK,OAAO,SAAS,WACrB,IAAa,EAAe,IAAI,EAAK,MAAM,OAAO,MAAM;IAE5D;GACJ;GACA,IAAM,IAAO,EAAK,MAAM,CAAK;GACxB,OAIL;IAHA,EAAM,GACN,EAAM,KAAK,CAAI,GACf,KAAK,EAAM,EAAE,CAAC,QACd,IAAU;IACV;GADU;EAEd;EACI,MAEJ,KAAQ,EAAO,IACf,KAAK;CACT;CAGA,OADA,EAAM,GACC;AACX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../utils/base64.cjs"),t=require("./credential-scope.cjs"),n=require("./csrf.cjs"),r=require("./errors.cjs"),i=require("./retry.cjs"),a=require("./idempotency.cjs");var
|
|
1
|
+
const e=require("../utils/base64.cjs"),t=require("./credential-scope.cjs"),n=require("./csrf.cjs"),r=require("./errors.cjs"),i=require("./retry.cjs"),a=require("../utils/owner-fingerprint.cjs"),o=require("./idempotency.cjs");var s=`1.0.0`,c=5242880,l=class extends Error{reason;constructor(e){super(e===`principal`?`O usuário mudou durante o upload resumível.`:`Os registros de upload resumível foram limpos durante o upload.`),this.name=`ResumableUploadSupersededError`,this.reason=e}},u=new Map,d=new WeakMap;function f(e){if(!e)return!1;try{let t=JSON.parse(e);return typeof t==`object`&&!!t&&typeof t.url==`string`&&typeof t.offset==`number`&&typeof t.size==`number`&&typeof t.idempotencyKey==`string`}catch{return!1}}function p(t){return e.bytesToBase64(new TextEncoder().encode(t))}function m(e){if(!e)return null;let t=Object.entries(e).map(([e,t])=>`${e} ${p(t)}`);return t.length>0?t.join(`,`):null}function h(e,t){let n=t,r=typeof n.name==`string`?n.name:`blob`,i=typeof n.lastModified==`number`?n.lastModified:0;return`${e}|${r}|${t.size}|${t.type}|${i}`}function g(e=`tempest-upload:`){function t(){try{return typeof localStorage>`u`?null:localStorage}catch{return null}}let n={get(n){let r=t()?.getItem(e+n);if(!r)return null;try{return JSON.parse(r)}catch{return null}},set(n,r){t()?.setItem(e+n,JSON.stringify(r))},delete(n){t()?.removeItem(e+n)},clear(){u.set(e,(u.get(e)??0)+1);let n=t();if(!n)return;let r=[];for(let t=0;t<n.length;t+=1){let i=n.key(t);i?.startsWith(e)&&f(n.getItem(i))&&r.push(i)}for(let e of r)n.removeItem(e)}};return d.set(n,()=>u.get(e)??0),n}function _(e){return new Promise((t,n)=>{let i=new XMLHttpRequest;i.open(e.method,e.url),i.withCredentials=e.withCredentials;for(let[t,n]of Object.entries(e.headers))i.setRequestHeader(t,n);if(e.onProgress){let t=e.onProgress;i.upload.onprogress=e=>t(e.loaded)}i.onload=()=>t({status:i.status,text:i.responseText,header:e=>i.getResponseHeader(e)}),i.onerror=()=>n(new r.TempestApiError({status:0,detail:`Falha de rede no upload resumível.`})),i.onabort=()=>n(new DOMException(`Aborted`,`AbortError`)),e.register(i),i.send(e.body)})}function v(e){let t=e.header(`Upload-Offset`);if(t===null)return null;let n=Number(t);return Number.isFinite(n)&&n>=0?n:null}function y(e){if(!e)return null;try{return JSON.parse(e)}catch{return e}}var b=new Set([409,412]);function x(e){return!r.isApiError(e)||b.has(e.status)?!0:r.isRetriableStatus(e.status)}function S(e,t){let n=y(e.text),i=r.buildApiError(e.status,n,{get:e.header}),a=typeof n==`object`&&!!n&&(`detail`in n||`message`in n);return new r.TempestApiError({...i,detail:a?i.detail:t})}function C(e){let t=typeof window>`u`?void 0:window.location.href;try{return new URL(e,t).href}catch{return e}}function w(e){let{endpoint:u,file:f,chunkSize:p=c,metadata:y,headers:b={},getToken:w,getPrincipal:T,trustedOrigins:E,withCredentials:D=!1,csrf:O,key:k=h(u,f),storage:A=g(),retry:j,onProgress:M,onStateChange:N}=e,P=`idle`,F=0,I=null,L=null,R,z=!1,B=A?d.get(A):void 0,V=B?.()??0;function H(){if(T&&a.ownerFingerprint(`p`,T())!==R)throw new l(`principal`);if(B&&B()!==V)throw new l(`cleared`)}let U=null,W=null,G=0;function K(e){P!==e&&(P=e,N?.(e))}function q(e){M?.({loaded:e,total:f.size,fraction:f.size===0?1:e/f.size,resumedFrom:G})}function J(e,r){let i={...b,"Tus-Resumable":s},a=w?.();return a&&!(`Authorization`in i)&&(t.isTrustedCredentialTarget(e,u,E)?i.Authorization=`Bearer ${a}`:t.reportSuppressedCredential(e,u)),Object.assign(i,n.csrfHeaders({method:r,url:e,reference:u,csrf:O,trustedOrigins:E,headers:b})),i}function Y(e){W=e}async function X(){A&&I&&L&&(H(),await A.set(k,{url:I,offset:F,size:f.size,idempotencyKey:L,updatedAt:Date.now(),...R===void 0?{}:{owner:R}}))}async function Z(e){let t=await _({method:`HEAD`,url:e,headers:J(e,`HEAD`),withCredentials:D,register:Y});if(t.status===404||t.status===410)throw new r.TempestApiError({status:t.status,detail:`O upload expirou no servidor. Comece de novo.`});let n=v(t);if(n===null)throw S(t,`HEAD sem Upload-Offset.`);return n}async function ee(){let e=T?a.ownerFingerprint(`p`,T()):void 0;z&&e!==R&&(L=null),R=e,z=!0,V=B?.()??0;let t=A?await A.get(k):null;if(t&&R!==void 0&&t.owner!==R&&(await A?.delete(k),t=null),t&&t.size===f.size&&(L=t.idempotencyKey,t.url))try{return F=await Z(t.url),I=t.url,t.url}catch{F=0}K(`creating`),L??=o.generateIdempotencyKey(),I=null,F=0,A&&await A.set(k,{url:``,offset:0,size:f.size,idempotencyKey:L,updatedAt:Date.now(),...R===void 0?{}:{owner:R}});let n={...J(u,`POST`),"Upload-Length":String(f.size),"Idempotency-Key":L},r=m(y);r&&(n[`Upload-Metadata`]=r);let i=await _({method:`POST`,url:u,headers:n,withCredentials:D,register:Y});if(i.status!==201)throw S(i,`Criação do upload recusada.`);let s=i.header(`Location`);if(!s)throw S(i,`Criação do upload sem cabeçalho Location.`);return I=C(s),await X(),I}async function te(e,t){if(H(),t.needed&&(F=await Z(e),t.needed=!1,q(F),await X(),F>=f.size))return;let n=Math.min(F+p,f.size),r=F,i=await _({method:`PATCH`,url:e,headers:{...J(e,`PATCH`),"Content-Type":`application/offset+octet-stream`,"Upload-Offset":String(r)},body:f.slice(r,n),withCredentials:D,onProgress:e=>q(Math.min(r+e,f.size)),register:Y});if(i.status===409||i.status===412)throw t.needed=!0,S(i,`Offset divergente — o servidor já tinha esses bytes.`);if(i.status!==204&&i.status!==200)throw S(i,`Chunk recusado pelo servidor.`);F=v(i)??n,q(F),await X()}async function ne(){U=null;let e=await ee();G=F,K(`uploading`),q(F);let t={needed:!1};for(;F<f.size&&!U;)await i.retry(()=>te(e,t),{retries:5,...j,shouldRetry:(e,n)=>{if(U||e instanceof l||e instanceof DOMException&&e.name===`AbortError`)return!1;let r=j?.shouldRetry?.(e,n)??x(e);return r&&(t.needed=!0),r}});return U===`pause`?(K(`paused`),null):U===`abort`?(K(`aborted`),null):(K(`done`),A&&await A.delete(k),{url:e,size:f.size})}async function Q(){try{return await ne()}catch(e){if(U!==null||e instanceof DOMException&&e.name===`AbortError`)return K(U===`abort`?`aborted`:`paused`),null;throw K(`error`),e}finally{W=null}}function $(e){U=e,W?.abort(),W=null}return{start:Q,resume:Q,pause:()=>$(`pause`),abort:async({discard:e=!1}={})=>{$(`abort`),K(`aborted`),e&&(I&&await _({method:`DELETE`,url:I,headers:J(I,`DELETE`),withCredentials:D,register:()=>void 0}).catch(()=>void 0),A&&await A.delete(k))},get state(){return P},get offset(){return F},get url(){return I},key:k}}exports.DEFAULT_CHUNK_SIZE=c,exports.ResumableUploadSupersededError=l,exports.TUS_VERSION=s,exports.createLocalUploadStorage=g,exports.createResumableUpload=w,exports.uploadFingerprint=h;
|
|
2
2
|
//# sourceMappingURL=resumable-upload.cjs.map
|