@workflow-code/cli 0.2.4-20261011005.codex-cli-web → 0.2.4-20261011007.codex-cli-web
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-HLMW6LAQ.js +908 -0
- package/dist/{chunk-G7PZDTYW.js → chunk-MNY562W5.js} +1 -1
- package/dist/{chunk-BP2VDZQV.js → chunk-P6K3NB5S.js} +1 -0
- package/dist/{chunk-T4FXQ7AQ.js → chunk-WN7VAGK6.js} +2 -2
- package/dist/index.js +4 -4
- package/dist/{local-7HMZSBG2.js → local-QLYFH4WT.js} +3 -3
- package/dist/{mcp-5H6U7H4S.js → mcp-LQ2IV6VA.js} +2 -2
- package/dist/web/kanban-data.mjs +613 -0
- package/dist/web/kanban-workspace.css +2354 -0
- package/dist/web/kanban-workspace.js +4530 -0
- package/dist/web/worker.mjs +7 -1
- package/dist/web/workflow-ui.js +6 -2
- package/dist/web/workflow-workspace.js +30 -4
- package/dist/{web-A3HVQRKB.js → web-KEM7Y2ZR.js} +751 -62
- package/dist/{workspace-G7SB6MS5.js → workspace-V3UXVFK6.js} +9 -76
- package/package.json +3 -2
|
@@ -0,0 +1,4530 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// node_modules/.pnpm/marked@17.0.1/node_modules/marked/lib/marked.esm.js
|
|
4
|
+
function L() {
|
|
5
|
+
return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
|
|
6
|
+
}
|
|
7
|
+
var T = L();
|
|
8
|
+
function Z(u3) {
|
|
9
|
+
T = u3;
|
|
10
|
+
}
|
|
11
|
+
var C = { exec: () => null };
|
|
12
|
+
function k(u3, e = "") {
|
|
13
|
+
let t = typeof u3 == "string" ? u3 : u3.source, n = { replace: (r, i) => {
|
|
14
|
+
let s = typeof i == "string" ? i : i.source;
|
|
15
|
+
return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
|
|
16
|
+
}, getRegex: () => new RegExp(t, e) };
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
var me = (() => {
|
|
20
|
+
try {
|
|
21
|
+
return !!new RegExp("(?<=1)(?<!1)");
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceTabs: /^\t+/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (u3) => new RegExp(`^( {0,3}${u3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}#`), htmlBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}<(?:[a-z].*>|!--)`, "i") };
|
|
27
|
+
var xe = /^(?:[ \t]*(?:\n|$))+/;
|
|
28
|
+
var be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
29
|
+
var Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
30
|
+
var I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
31
|
+
var Te = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
32
|
+
var N = /(?:[*+-]|\d{1,9}[.)])/;
|
|
33
|
+
var re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
34
|
+
var se = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
|
|
35
|
+
var Oe = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
|
|
36
|
+
var Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
37
|
+
var we = /^[^\n]+/;
|
|
38
|
+
var F = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
|
|
39
|
+
var ye = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", F).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
|
|
40
|
+
var Pe = k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex();
|
|
41
|
+
var v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
42
|
+
var j = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
43
|
+
var Se = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", j).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
44
|
+
var ie = k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
|
|
45
|
+
var $e = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex();
|
|
46
|
+
var U = { blockquote: $e, code: be, def: ye, fences: Re, heading: Te, hr: I, html: Se, lheading: se, list: Pe, newline: xe, paragraph: ie, table: C, text: we };
|
|
47
|
+
var te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
|
|
48
|
+
var _e = { ...U, lheading: Oe, table: te, paragraph: k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", te).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex() };
|
|
49
|
+
var Le = { ...U, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", j).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: C, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(Q).replace("hr", I).replace("heading", ` *#{1,6} *[^
|
|
50
|
+
]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
|
|
51
|
+
var Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
52
|
+
var ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
53
|
+
var oe = /^( {2,}|\\)\n(?!\s*$)/;
|
|
54
|
+
var Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
55
|
+
var D = /[\p{P}\p{S}]/u;
|
|
56
|
+
var K = /[\s\p{P}\p{S}]/u;
|
|
57
|
+
var ae = /[^\s\p{P}\p{S}]/u;
|
|
58
|
+
var Ce = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex();
|
|
59
|
+
var le = /(?!~)[\p{P}\p{S}]/u;
|
|
60
|
+
var Ie = /(?!~)[\s\p{P}\p{S}]/u;
|
|
61
|
+
var Ee = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
62
|
+
var Be = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", me ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
|
|
63
|
+
var ue = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
|
|
64
|
+
var qe = k(ue, "u").replace(/punct/g, D).getRegex();
|
|
65
|
+
var ve = k(ue, "u").replace(/punct/g, le).getRegex();
|
|
66
|
+
var pe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
|
|
67
|
+
var De = k(pe, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
|
|
68
|
+
var He = k(pe, "gu").replace(/notPunctSpace/g, Ee).replace(/punctSpace/g, Ie).replace(/punct/g, le).getRegex();
|
|
69
|
+
var Ze = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
|
|
70
|
+
var Ge = k(/\\(punct)/, "gu").replace(/punct/g, D).getRegex();
|
|
71
|
+
var Ne = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
|
|
72
|
+
var Qe = k(j).replace("(?:-->|$)", "-->").getRegex();
|
|
73
|
+
var Fe = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Qe).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
74
|
+
var q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
|
|
75
|
+
var je = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
76
|
+
var ce = k(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", F).getRegex();
|
|
77
|
+
var he = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", F).getRegex();
|
|
78
|
+
var Ue = k("reflink|nolink(?!\\()", "g").replace("reflink", ce).replace("nolink", he).getRegex();
|
|
79
|
+
var ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
|
|
80
|
+
var W = { _backpedal: C, anyPunctuation: Ge, autolink: Ne, blockSkip: Be, br: oe, code: ze, del: C, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ze, escape: Me, link: je, nolink: he, punctuation: Ce, reflink: ce, reflinkSearch: Ue, tag: Fe, text: Ae, url: C };
|
|
81
|
+
var Ke = { ...W, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() };
|
|
82
|
+
var G = { ...W, emStrongRDelimAst: He, emStrongLDelim: ve, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ne).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ne).getRegex() };
|
|
83
|
+
var We = { ...G, br: k(oe).replace("{2,}", "*").getRegex(), text: k(G.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
|
|
84
|
+
var E = { normal: U, gfm: _e, pedantic: Le };
|
|
85
|
+
var M = { normal: W, gfm: G, breaks: We, pedantic: Ke };
|
|
86
|
+
var Xe = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
87
|
+
var ke = (u3) => Xe[u3];
|
|
88
|
+
function w(u3, e) {
|
|
89
|
+
if (e) {
|
|
90
|
+
if (m.escapeTest.test(u3)) return u3.replace(m.escapeReplace, ke);
|
|
91
|
+
} else if (m.escapeTestNoEncode.test(u3)) return u3.replace(m.escapeReplaceNoEncode, ke);
|
|
92
|
+
return u3;
|
|
93
|
+
}
|
|
94
|
+
function X(u3) {
|
|
95
|
+
try {
|
|
96
|
+
u3 = encodeURI(u3).replace(m.percentDecode, "%");
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return u3;
|
|
101
|
+
}
|
|
102
|
+
function J(u3, e) {
|
|
103
|
+
let t = u3.replace(m.findPipe, (i, s, a) => {
|
|
104
|
+
let o = false, l = s;
|
|
105
|
+
for (; --l >= 0 && a[l] === "\\"; ) o = !o;
|
|
106
|
+
return o ? "|" : " |";
|
|
107
|
+
}), n = t.split(m.splitPipe), r = 0;
|
|
108
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
|
|
109
|
+
else for (; n.length < e; ) n.push("");
|
|
110
|
+
for (; r < n.length; r++) n[r] = n[r].trim().replace(m.slashPipe, "|");
|
|
111
|
+
return n;
|
|
112
|
+
}
|
|
113
|
+
function z(u3, e, t) {
|
|
114
|
+
let n = u3.length;
|
|
115
|
+
if (n === 0) return "";
|
|
116
|
+
let r = 0;
|
|
117
|
+
for (; r < n; ) {
|
|
118
|
+
let i = u3.charAt(n - r - 1);
|
|
119
|
+
if (i === e && !t) r++;
|
|
120
|
+
else if (i !== e && t) r++;
|
|
121
|
+
else break;
|
|
122
|
+
}
|
|
123
|
+
return u3.slice(0, n - r);
|
|
124
|
+
}
|
|
125
|
+
function de(u3, e) {
|
|
126
|
+
if (u3.indexOf(e[1]) === -1) return -1;
|
|
127
|
+
let t = 0;
|
|
128
|
+
for (let n = 0; n < u3.length; n++) if (u3[n] === "\\") n++;
|
|
129
|
+
else if (u3[n] === e[0]) t++;
|
|
130
|
+
else if (u3[n] === e[1] && (t--, t < 0)) return n;
|
|
131
|
+
return t > 0 ? -2 : -1;
|
|
132
|
+
}
|
|
133
|
+
function ge(u3, e, t, n, r) {
|
|
134
|
+
let i = e.href, s = e.title || null, a = u3[1].replace(r.other.outputLinkReplace, "$1");
|
|
135
|
+
n.state.inLink = true;
|
|
136
|
+
let o = { type: u3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
|
|
137
|
+
return n.state.inLink = false, o;
|
|
138
|
+
}
|
|
139
|
+
function Je(u3, e, t) {
|
|
140
|
+
let n = u3.match(t.other.indentCodeCompensation);
|
|
141
|
+
if (n === null) return e;
|
|
142
|
+
let r = n[1];
|
|
143
|
+
return e.split(`
|
|
144
|
+
`).map((i) => {
|
|
145
|
+
let s = i.match(t.other.beginningSpace);
|
|
146
|
+
if (s === null) return i;
|
|
147
|
+
let [a] = s;
|
|
148
|
+
return a.length >= r.length ? i.slice(r.length) : i;
|
|
149
|
+
}).join(`
|
|
150
|
+
`);
|
|
151
|
+
}
|
|
152
|
+
var y = class {
|
|
153
|
+
options;
|
|
154
|
+
rules;
|
|
155
|
+
lexer;
|
|
156
|
+
constructor(e) {
|
|
157
|
+
this.options = e || T;
|
|
158
|
+
}
|
|
159
|
+
space(e) {
|
|
160
|
+
let t = this.rules.block.newline.exec(e);
|
|
161
|
+
if (t && t[0].length > 0) return { type: "space", raw: t[0] };
|
|
162
|
+
}
|
|
163
|
+
code(e) {
|
|
164
|
+
let t = this.rules.block.code.exec(e);
|
|
165
|
+
if (t) {
|
|
166
|
+
let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
167
|
+
return { type: "code", raw: t[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
|
|
168
|
+
`) };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
fences(e) {
|
|
172
|
+
let t = this.rules.block.fences.exec(e);
|
|
173
|
+
if (t) {
|
|
174
|
+
let n = t[0], r = Je(n, t[3] || "", this.rules);
|
|
175
|
+
return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: r };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
heading(e) {
|
|
179
|
+
let t = this.rules.block.heading.exec(e);
|
|
180
|
+
if (t) {
|
|
181
|
+
let n = t[2].trim();
|
|
182
|
+
if (this.rules.other.endingHash.test(n)) {
|
|
183
|
+
let r = z(n, "#");
|
|
184
|
+
(this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
|
|
185
|
+
}
|
|
186
|
+
return { type: "heading", raw: t[0], depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
hr(e) {
|
|
190
|
+
let t = this.rules.block.hr.exec(e);
|
|
191
|
+
if (t) return { type: "hr", raw: z(t[0], `
|
|
192
|
+
`) };
|
|
193
|
+
}
|
|
194
|
+
blockquote(e) {
|
|
195
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
196
|
+
if (t) {
|
|
197
|
+
let n = z(t[0], `
|
|
198
|
+
`).split(`
|
|
199
|
+
`), r = "", i = "", s = [];
|
|
200
|
+
for (; n.length > 0; ) {
|
|
201
|
+
let a = false, o = [], l;
|
|
202
|
+
for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = true;
|
|
203
|
+
else if (!a) o.push(n[l]);
|
|
204
|
+
else break;
|
|
205
|
+
n = n.slice(l);
|
|
206
|
+
let p = o.join(`
|
|
207
|
+
`), c = p.replace(this.rules.other.blockquoteSetextReplace, `
|
|
208
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
209
|
+
r = r ? `${r}
|
|
210
|
+
${p}` : p, i = i ? `${i}
|
|
211
|
+
${c}` : c;
|
|
212
|
+
let g = this.lexer.state.top;
|
|
213
|
+
if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0) break;
|
|
214
|
+
let h = s.at(-1);
|
|
215
|
+
if (h?.type === "code") break;
|
|
216
|
+
if (h?.type === "blockquote") {
|
|
217
|
+
let R = h, f = R.raw + `
|
|
218
|
+
` + n.join(`
|
|
219
|
+
`), O = this.blockquote(f);
|
|
220
|
+
s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i = i.substring(0, i.length - R.text.length) + O.text;
|
|
221
|
+
break;
|
|
222
|
+
} else if (h?.type === "list") {
|
|
223
|
+
let R = h, f = R.raw + `
|
|
224
|
+
` + n.join(`
|
|
225
|
+
`), O = this.list(f);
|
|
226
|
+
s[s.length - 1] = O, r = r.substring(0, r.length - h.raw.length) + O.raw, i = i.substring(0, i.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
|
|
227
|
+
`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return { type: "blockquote", raw: r, tokens: s, text: i };
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
list(e) {
|
|
235
|
+
let t = this.rules.block.list.exec(e);
|
|
236
|
+
if (t) {
|
|
237
|
+
let n = t[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
|
|
238
|
+
n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
|
|
239
|
+
let s = this.rules.other.listItemRegex(n), a = false;
|
|
240
|
+
for (; e; ) {
|
|
241
|
+
let l = false, p = "", c = "";
|
|
242
|
+
if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
|
|
243
|
+
p = t[0], e = e.substring(p.length);
|
|
244
|
+
let g = t[2].split(`
|
|
245
|
+
`, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h = e.split(`
|
|
246
|
+
`, 1)[0], R = !g.trim(), f = 0;
|
|
247
|
+
if (this.options.pedantic ? (f = 2, c = g.trimStart()) : R ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = g.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
|
|
248
|
+
`, e = e.substring(h.length + 1), l = true), !l) {
|
|
249
|
+
let O = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), fe = this.rules.other.htmlBeginRegex(f);
|
|
250
|
+
for (; e; ) {
|
|
251
|
+
let H = e.split(`
|
|
252
|
+
`, 1)[0], A;
|
|
253
|
+
if (h = H, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), A = h) : A = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || fe.test(h) || O.test(h) || V.test(h)) break;
|
|
254
|
+
if (A.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) c += `
|
|
255
|
+
` + A.slice(f);
|
|
256
|
+
else {
|
|
257
|
+
if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g)) break;
|
|
258
|
+
c += `
|
|
259
|
+
` + h;
|
|
260
|
+
}
|
|
261
|
+
!R && !h.trim() && (R = true), p += H + `
|
|
262
|
+
`, e = e.substring(H.length + 1), g = A.slice(f);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
i.loose || (a ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i.raw += p;
|
|
266
|
+
}
|
|
267
|
+
let o = i.items.at(-1);
|
|
268
|
+
if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
|
|
269
|
+
else return;
|
|
270
|
+
i.raw = i.raw.trimEnd();
|
|
271
|
+
for (let l of i.items) {
|
|
272
|
+
if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
|
|
273
|
+
if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
|
|
274
|
+
l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
|
|
275
|
+
for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
|
|
276
|
+
this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
let p = this.rules.other.listTaskCheckbox.exec(l.raw);
|
|
281
|
+
if (p) {
|
|
282
|
+
let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
|
|
283
|
+
l.checked = c.checked, i.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (!i.loose) {
|
|
287
|
+
let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
|
|
288
|
+
i.loose = c;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (i.loose) for (let l of i.items) {
|
|
292
|
+
l.loose = true;
|
|
293
|
+
for (let p of l.tokens) p.type === "text" && (p.type = "paragraph");
|
|
294
|
+
}
|
|
295
|
+
return i;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
html(e) {
|
|
299
|
+
let t = this.rules.block.html.exec(e);
|
|
300
|
+
if (t) return { type: "html", block: true, raw: t[0], pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: t[0] };
|
|
301
|
+
}
|
|
302
|
+
def(e) {
|
|
303
|
+
let t = this.rules.block.def.exec(e);
|
|
304
|
+
if (t) {
|
|
305
|
+
let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
|
|
306
|
+
return { type: "def", tag: n, raw: t[0], href: r, title: i };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
table(e) {
|
|
310
|
+
let t = this.rules.block.table.exec(e);
|
|
311
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
|
|
312
|
+
let n = J(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
|
|
313
|
+
`) : [], s = { type: "table", raw: t[0], header: [], align: [], rows: [] };
|
|
314
|
+
if (n.length === r.length) {
|
|
315
|
+
for (let a of r) this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
|
|
316
|
+
for (let a = 0; a < n.length; a++) s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
|
|
317
|
+
for (let a of i) s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
|
|
318
|
+
return s;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
lheading(e) {
|
|
322
|
+
let t = this.rules.block.lheading.exec(e);
|
|
323
|
+
if (t) return { type: "heading", raw: t[0], depth: t[2].charAt(0) === "=" ? 1 : 2, text: t[1], tokens: this.lexer.inline(t[1]) };
|
|
324
|
+
}
|
|
325
|
+
paragraph(e) {
|
|
326
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
327
|
+
if (t) {
|
|
328
|
+
let n = t[1].charAt(t[1].length - 1) === `
|
|
329
|
+
` ? t[1].slice(0, -1) : t[1];
|
|
330
|
+
return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
text(e) {
|
|
334
|
+
let t = this.rules.block.text.exec(e);
|
|
335
|
+
if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
|
|
336
|
+
}
|
|
337
|
+
escape(e) {
|
|
338
|
+
let t = this.rules.inline.escape.exec(e);
|
|
339
|
+
if (t) return { type: "escape", raw: t[0], text: t[1] };
|
|
340
|
+
}
|
|
341
|
+
tag(e) {
|
|
342
|
+
let t = this.rules.inline.tag.exec(e);
|
|
343
|
+
if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
|
|
344
|
+
}
|
|
345
|
+
link(e) {
|
|
346
|
+
let t = this.rules.inline.link.exec(e);
|
|
347
|
+
if (t) {
|
|
348
|
+
let n = t[2].trim();
|
|
349
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
|
|
350
|
+
if (!this.rules.other.endAngleBracket.test(n)) return;
|
|
351
|
+
let s = z(n.slice(0, -1), "\\");
|
|
352
|
+
if ((n.length - s.length) % 2 === 0) return;
|
|
353
|
+
} else {
|
|
354
|
+
let s = de(t[2], "()");
|
|
355
|
+
if (s === -2) return;
|
|
356
|
+
if (s > -1) {
|
|
357
|
+
let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
|
|
358
|
+
t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
let r = t[2], i = "";
|
|
362
|
+
if (this.options.pedantic) {
|
|
363
|
+
let s = this.rules.other.pedanticHrefTitle.exec(r);
|
|
364
|
+
s && (r = s[1], i = s[3]);
|
|
365
|
+
} else i = t[3] ? t[3].slice(1, -1) : "";
|
|
366
|
+
return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i && i.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
reflink(e, t) {
|
|
370
|
+
let n;
|
|
371
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
372
|
+
let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t[r.toLowerCase()];
|
|
373
|
+
if (!i) {
|
|
374
|
+
let s = n[0].charAt(0);
|
|
375
|
+
return { type: "text", raw: s, text: s };
|
|
376
|
+
}
|
|
377
|
+
return ge(n, i, n[0], this.lexer, this.rules);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
emStrong(e, t, n = "") {
|
|
381
|
+
let r = this.rules.inline.emStrongLDelim.exec(e);
|
|
382
|
+
if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
|
|
383
|
+
if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
384
|
+
let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
385
|
+
for (c.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = c.exec(t)) != null; ) {
|
|
386
|
+
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
|
|
387
|
+
if (o = [...a].length, r[3] || r[4]) {
|
|
388
|
+
l += o;
|
|
389
|
+
continue;
|
|
390
|
+
} else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
|
|
391
|
+
p += o;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (l -= o, l > 0) continue;
|
|
395
|
+
o = Math.min(o, o + l + p);
|
|
396
|
+
let g = [...r[0]][0].length, h = e.slice(0, s + r.index + g + o);
|
|
397
|
+
if (Math.min(s, o) % 2) {
|
|
398
|
+
let f = h.slice(1, -1);
|
|
399
|
+
return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
|
|
400
|
+
}
|
|
401
|
+
let R = h.slice(2, -2);
|
|
402
|
+
return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
codespan(e) {
|
|
407
|
+
let t = this.rules.inline.code.exec(e);
|
|
408
|
+
if (t) {
|
|
409
|
+
let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
|
|
410
|
+
return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
br(e) {
|
|
414
|
+
let t = this.rules.inline.br.exec(e);
|
|
415
|
+
if (t) return { type: "br", raw: t[0] };
|
|
416
|
+
}
|
|
417
|
+
del(e) {
|
|
418
|
+
let t = this.rules.inline.del.exec(e);
|
|
419
|
+
if (t) return { type: "del", raw: t[0], text: t[2], tokens: this.lexer.inlineTokens(t[2]) };
|
|
420
|
+
}
|
|
421
|
+
autolink(e) {
|
|
422
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
423
|
+
if (t) {
|
|
424
|
+
let n, r;
|
|
425
|
+
return t[2] === "@" ? (n = t[1], r = "mailto:" + n) : (n = t[1], r = n), { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
url(e) {
|
|
429
|
+
let t;
|
|
430
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
431
|
+
let n, r;
|
|
432
|
+
if (t[2] === "@") n = t[0], r = "mailto:" + n;
|
|
433
|
+
else {
|
|
434
|
+
let i;
|
|
435
|
+
do
|
|
436
|
+
i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
437
|
+
while (i !== t[0]);
|
|
438
|
+
n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
|
|
439
|
+
}
|
|
440
|
+
return { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
inlineText(e) {
|
|
444
|
+
let t = this.rules.inline.text.exec(e);
|
|
445
|
+
if (t) {
|
|
446
|
+
let n = this.lexer.state.inRawBlock;
|
|
447
|
+
return { type: "text", raw: t[0], text: t[0], escaped: n };
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
var x = class u {
|
|
452
|
+
tokens;
|
|
453
|
+
options;
|
|
454
|
+
state;
|
|
455
|
+
inlineQueue;
|
|
456
|
+
tokenizer;
|
|
457
|
+
constructor(e) {
|
|
458
|
+
this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new y(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
|
|
459
|
+
let t = { other: m, block: E.normal, inline: M.normal };
|
|
460
|
+
this.options.pedantic ? (t.block = E.pedantic, t.inline = M.pedantic) : this.options.gfm && (t.block = E.gfm, this.options.breaks ? t.inline = M.breaks : t.inline = M.gfm), this.tokenizer.rules = t;
|
|
461
|
+
}
|
|
462
|
+
static get rules() {
|
|
463
|
+
return { block: E, inline: M };
|
|
464
|
+
}
|
|
465
|
+
static lex(e, t) {
|
|
466
|
+
return new u(t).lex(e);
|
|
467
|
+
}
|
|
468
|
+
static lexInline(e, t) {
|
|
469
|
+
return new u(t).inlineTokens(e);
|
|
470
|
+
}
|
|
471
|
+
lex(e) {
|
|
472
|
+
e = e.replace(m.carriageReturn, `
|
|
473
|
+
`), this.blockTokens(e, this.tokens);
|
|
474
|
+
for (let t = 0; t < this.inlineQueue.length; t++) {
|
|
475
|
+
let n = this.inlineQueue[t];
|
|
476
|
+
this.inlineTokens(n.src, n.tokens);
|
|
477
|
+
}
|
|
478
|
+
return this.inlineQueue = [], this.tokens;
|
|
479
|
+
}
|
|
480
|
+
blockTokens(e, t = [], n = false) {
|
|
481
|
+
for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e; ) {
|
|
482
|
+
let r;
|
|
483
|
+
if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false)) continue;
|
|
484
|
+
if (r = this.tokenizer.space(e)) {
|
|
485
|
+
e = e.substring(r.raw.length);
|
|
486
|
+
let s = t.at(-1);
|
|
487
|
+
r.raw.length === 1 && s !== void 0 ? s.raw += `
|
|
488
|
+
` : t.push(r);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (r = this.tokenizer.code(e)) {
|
|
492
|
+
e = e.substring(r.raw.length);
|
|
493
|
+
let s = t.at(-1);
|
|
494
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
495
|
+
`) ? "" : `
|
|
496
|
+
`) + r.raw, s.text += `
|
|
497
|
+
` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (r = this.tokenizer.fences(e)) {
|
|
501
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
if (r = this.tokenizer.heading(e)) {
|
|
505
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (r = this.tokenizer.hr(e)) {
|
|
509
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
513
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (r = this.tokenizer.list(e)) {
|
|
517
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (r = this.tokenizer.html(e)) {
|
|
521
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (r = this.tokenizer.def(e)) {
|
|
525
|
+
e = e.substring(r.raw.length);
|
|
526
|
+
let s = t.at(-1);
|
|
527
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
528
|
+
`) ? "" : `
|
|
529
|
+
`) + r.raw, s.text += `
|
|
530
|
+
` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (r = this.tokenizer.table(e)) {
|
|
534
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
538
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
let i = e;
|
|
542
|
+
if (this.options.extensions?.startBlock) {
|
|
543
|
+
let s = 1 / 0, a = e.slice(1), o;
|
|
544
|
+
this.options.extensions.startBlock.forEach((l) => {
|
|
545
|
+
o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
|
|
546
|
+
}), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
|
|
547
|
+
}
|
|
548
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
549
|
+
let s = t.at(-1);
|
|
550
|
+
n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
|
|
551
|
+
`) ? "" : `
|
|
552
|
+
`) + r.raw, s.text += `
|
|
553
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (r = this.tokenizer.text(e)) {
|
|
557
|
+
e = e.substring(r.raw.length);
|
|
558
|
+
let s = t.at(-1);
|
|
559
|
+
s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
560
|
+
`) ? "" : `
|
|
561
|
+
`) + r.raw, s.text += `
|
|
562
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (e) {
|
|
566
|
+
let s = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
567
|
+
if (this.options.silent) {
|
|
568
|
+
console.error(s);
|
|
569
|
+
break;
|
|
570
|
+
} else throw new Error(s);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return this.state.top = true, t;
|
|
574
|
+
}
|
|
575
|
+
inline(e, t = []) {
|
|
576
|
+
return this.inlineQueue.push({ src: e, tokens: t }), t;
|
|
577
|
+
}
|
|
578
|
+
inlineTokens(e, t = []) {
|
|
579
|
+
let n = e, r = null;
|
|
580
|
+
if (this.tokens.links) {
|
|
581
|
+
let o = Object.keys(this.tokens.links);
|
|
582
|
+
if (o.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; ) o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
|
|
583
|
+
}
|
|
584
|
+
for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
585
|
+
let i;
|
|
586
|
+
for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; ) i = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
587
|
+
n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
588
|
+
let s = false, a = "";
|
|
589
|
+
for (; e; ) {
|
|
590
|
+
s || (a = ""), s = false;
|
|
591
|
+
let o;
|
|
592
|
+
if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false)) continue;
|
|
593
|
+
if (o = this.tokenizer.escape(e)) {
|
|
594
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (o = this.tokenizer.tag(e)) {
|
|
598
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
if (o = this.tokenizer.link(e)) {
|
|
602
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
606
|
+
e = e.substring(o.raw.length);
|
|
607
|
+
let p = t.at(-1);
|
|
608
|
+
o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
if (o = this.tokenizer.emStrong(e, n, a)) {
|
|
612
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (o = this.tokenizer.codespan(e)) {
|
|
616
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
if (o = this.tokenizer.br(e)) {
|
|
620
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (o = this.tokenizer.del(e)) {
|
|
624
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (o = this.tokenizer.autolink(e)) {
|
|
628
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
if (!this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
632
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
let l = e;
|
|
636
|
+
if (this.options.extensions?.startInline) {
|
|
637
|
+
let p = 1 / 0, c = e.slice(1), g;
|
|
638
|
+
this.options.extensions.startInline.forEach((h) => {
|
|
639
|
+
g = h.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
|
|
640
|
+
}), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
|
|
641
|
+
}
|
|
642
|
+
if (o = this.tokenizer.inlineText(l)) {
|
|
643
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
|
|
644
|
+
let p = t.at(-1);
|
|
645
|
+
p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
if (e) {
|
|
649
|
+
let p = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
650
|
+
if (this.options.silent) {
|
|
651
|
+
console.error(p);
|
|
652
|
+
break;
|
|
653
|
+
} else throw new Error(p);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return t;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
var P = class {
|
|
660
|
+
options;
|
|
661
|
+
parser;
|
|
662
|
+
constructor(e) {
|
|
663
|
+
this.options = e || T;
|
|
664
|
+
}
|
|
665
|
+
space(e) {
|
|
666
|
+
return "";
|
|
667
|
+
}
|
|
668
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
669
|
+
let r = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
|
|
670
|
+
`;
|
|
671
|
+
return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
|
|
672
|
+
` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
|
|
673
|
+
`;
|
|
674
|
+
}
|
|
675
|
+
blockquote({ tokens: e }) {
|
|
676
|
+
return `<blockquote>
|
|
677
|
+
${this.parser.parse(e)}</blockquote>
|
|
678
|
+
`;
|
|
679
|
+
}
|
|
680
|
+
html({ text: e }) {
|
|
681
|
+
return e;
|
|
682
|
+
}
|
|
683
|
+
def(e) {
|
|
684
|
+
return "";
|
|
685
|
+
}
|
|
686
|
+
heading({ tokens: e, depth: t }) {
|
|
687
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
688
|
+
`;
|
|
689
|
+
}
|
|
690
|
+
hr(e) {
|
|
691
|
+
return `<hr>
|
|
692
|
+
`;
|
|
693
|
+
}
|
|
694
|
+
list(e) {
|
|
695
|
+
let t = e.ordered, n = e.start, r = "";
|
|
696
|
+
for (let a = 0; a < e.items.length; a++) {
|
|
697
|
+
let o = e.items[a];
|
|
698
|
+
r += this.listitem(o);
|
|
699
|
+
}
|
|
700
|
+
let i = t ? "ol" : "ul", s = t && n !== 1 ? ' start="' + n + '"' : "";
|
|
701
|
+
return "<" + i + s + `>
|
|
702
|
+
` + r + "</" + i + `>
|
|
703
|
+
`;
|
|
704
|
+
}
|
|
705
|
+
listitem(e) {
|
|
706
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
707
|
+
`;
|
|
708
|
+
}
|
|
709
|
+
checkbox({ checked: e }) {
|
|
710
|
+
return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
|
|
711
|
+
}
|
|
712
|
+
paragraph({ tokens: e }) {
|
|
713
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
714
|
+
`;
|
|
715
|
+
}
|
|
716
|
+
table(e) {
|
|
717
|
+
let t = "", n = "";
|
|
718
|
+
for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
|
|
719
|
+
t += this.tablerow({ text: n });
|
|
720
|
+
let r = "";
|
|
721
|
+
for (let i = 0; i < e.rows.length; i++) {
|
|
722
|
+
let s = e.rows[i];
|
|
723
|
+
n = "";
|
|
724
|
+
for (let a = 0; a < s.length; a++) n += this.tablecell(s[a]);
|
|
725
|
+
r += this.tablerow({ text: n });
|
|
726
|
+
}
|
|
727
|
+
return r && (r = `<tbody>${r}</tbody>`), `<table>
|
|
728
|
+
<thead>
|
|
729
|
+
` + t + `</thead>
|
|
730
|
+
` + r + `</table>
|
|
731
|
+
`;
|
|
732
|
+
}
|
|
733
|
+
tablerow({ text: e }) {
|
|
734
|
+
return `<tr>
|
|
735
|
+
${e}</tr>
|
|
736
|
+
`;
|
|
737
|
+
}
|
|
738
|
+
tablecell(e) {
|
|
739
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
740
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
741
|
+
`;
|
|
742
|
+
}
|
|
743
|
+
strong({ tokens: e }) {
|
|
744
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
745
|
+
}
|
|
746
|
+
em({ tokens: e }) {
|
|
747
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
748
|
+
}
|
|
749
|
+
codespan({ text: e }) {
|
|
750
|
+
return `<code>${w(e, true)}</code>`;
|
|
751
|
+
}
|
|
752
|
+
br(e) {
|
|
753
|
+
return "<br>";
|
|
754
|
+
}
|
|
755
|
+
del({ tokens: e }) {
|
|
756
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
757
|
+
}
|
|
758
|
+
link({ href: e, title: t, tokens: n }) {
|
|
759
|
+
let r = this.parser.parseInline(n), i = X(e);
|
|
760
|
+
if (i === null) return r;
|
|
761
|
+
e = i;
|
|
762
|
+
let s = '<a href="' + e + '"';
|
|
763
|
+
return t && (s += ' title="' + w(t) + '"'), s += ">" + r + "</a>", s;
|
|
764
|
+
}
|
|
765
|
+
image({ href: e, title: t, text: n, tokens: r }) {
|
|
766
|
+
r && (n = this.parser.parseInline(r, this.parser.textRenderer));
|
|
767
|
+
let i = X(e);
|
|
768
|
+
if (i === null) return w(n);
|
|
769
|
+
e = i;
|
|
770
|
+
let s = `<img src="${e}" alt="${n}"`;
|
|
771
|
+
return t && (s += ` title="${w(t)}"`), s += ">", s;
|
|
772
|
+
}
|
|
773
|
+
text(e) {
|
|
774
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
var $ = class {
|
|
778
|
+
strong({ text: e }) {
|
|
779
|
+
return e;
|
|
780
|
+
}
|
|
781
|
+
em({ text: e }) {
|
|
782
|
+
return e;
|
|
783
|
+
}
|
|
784
|
+
codespan({ text: e }) {
|
|
785
|
+
return e;
|
|
786
|
+
}
|
|
787
|
+
del({ text: e }) {
|
|
788
|
+
return e;
|
|
789
|
+
}
|
|
790
|
+
html({ text: e }) {
|
|
791
|
+
return e;
|
|
792
|
+
}
|
|
793
|
+
text({ text: e }) {
|
|
794
|
+
return e;
|
|
795
|
+
}
|
|
796
|
+
link({ text: e }) {
|
|
797
|
+
return "" + e;
|
|
798
|
+
}
|
|
799
|
+
image({ text: e }) {
|
|
800
|
+
return "" + e;
|
|
801
|
+
}
|
|
802
|
+
br() {
|
|
803
|
+
return "";
|
|
804
|
+
}
|
|
805
|
+
checkbox({ raw: e }) {
|
|
806
|
+
return e;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
var b = class u2 {
|
|
810
|
+
options;
|
|
811
|
+
renderer;
|
|
812
|
+
textRenderer;
|
|
813
|
+
constructor(e) {
|
|
814
|
+
this.options = e || T, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
|
|
815
|
+
}
|
|
816
|
+
static parse(e, t) {
|
|
817
|
+
return new u2(t).parse(e);
|
|
818
|
+
}
|
|
819
|
+
static parseInline(e, t) {
|
|
820
|
+
return new u2(t).parseInline(e);
|
|
821
|
+
}
|
|
822
|
+
parse(e) {
|
|
823
|
+
let t = "";
|
|
824
|
+
for (let n = 0; n < e.length; n++) {
|
|
825
|
+
let r = e[n];
|
|
826
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
827
|
+
let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
|
|
828
|
+
if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
|
|
829
|
+
t += a || "";
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
let i = r;
|
|
834
|
+
switch (i.type) {
|
|
835
|
+
case "space": {
|
|
836
|
+
t += this.renderer.space(i);
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
case "hr": {
|
|
840
|
+
t += this.renderer.hr(i);
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
case "heading": {
|
|
844
|
+
t += this.renderer.heading(i);
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
case "code": {
|
|
848
|
+
t += this.renderer.code(i);
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
case "table": {
|
|
852
|
+
t += this.renderer.table(i);
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
case "blockquote": {
|
|
856
|
+
t += this.renderer.blockquote(i);
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
case "list": {
|
|
860
|
+
t += this.renderer.list(i);
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
case "checkbox": {
|
|
864
|
+
t += this.renderer.checkbox(i);
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
case "html": {
|
|
868
|
+
t += this.renderer.html(i);
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
case "def": {
|
|
872
|
+
t += this.renderer.def(i);
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
case "paragraph": {
|
|
876
|
+
t += this.renderer.paragraph(i);
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
case "text": {
|
|
880
|
+
t += this.renderer.text(i);
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
default: {
|
|
884
|
+
let s = 'Token with "' + i.type + '" type was not found.';
|
|
885
|
+
if (this.options.silent) return console.error(s), "";
|
|
886
|
+
throw new Error(s);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return t;
|
|
891
|
+
}
|
|
892
|
+
parseInline(e, t = this.renderer) {
|
|
893
|
+
let n = "";
|
|
894
|
+
for (let r = 0; r < e.length; r++) {
|
|
895
|
+
let i = e[r];
|
|
896
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
897
|
+
let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
898
|
+
if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
|
|
899
|
+
n += a || "";
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
let s = i;
|
|
904
|
+
switch (s.type) {
|
|
905
|
+
case "escape": {
|
|
906
|
+
n += t.text(s);
|
|
907
|
+
break;
|
|
908
|
+
}
|
|
909
|
+
case "html": {
|
|
910
|
+
n += t.html(s);
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
913
|
+
case "link": {
|
|
914
|
+
n += t.link(s);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
case "image": {
|
|
918
|
+
n += t.image(s);
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
case "checkbox": {
|
|
922
|
+
n += t.checkbox(s);
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case "strong": {
|
|
926
|
+
n += t.strong(s);
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
case "em": {
|
|
930
|
+
n += t.em(s);
|
|
931
|
+
break;
|
|
932
|
+
}
|
|
933
|
+
case "codespan": {
|
|
934
|
+
n += t.codespan(s);
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
case "br": {
|
|
938
|
+
n += t.br(s);
|
|
939
|
+
break;
|
|
940
|
+
}
|
|
941
|
+
case "del": {
|
|
942
|
+
n += t.del(s);
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
case "text": {
|
|
946
|
+
n += t.text(s);
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
default: {
|
|
950
|
+
let a = 'Token with "' + s.type + '" type was not found.';
|
|
951
|
+
if (this.options.silent) return console.error(a), "";
|
|
952
|
+
throw new Error(a);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return n;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
var S = class {
|
|
960
|
+
options;
|
|
961
|
+
block;
|
|
962
|
+
constructor(e) {
|
|
963
|
+
this.options = e || T;
|
|
964
|
+
}
|
|
965
|
+
static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
|
|
966
|
+
static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
|
|
967
|
+
preprocess(e) {
|
|
968
|
+
return e;
|
|
969
|
+
}
|
|
970
|
+
postprocess(e) {
|
|
971
|
+
return e;
|
|
972
|
+
}
|
|
973
|
+
processAllTokens(e) {
|
|
974
|
+
return e;
|
|
975
|
+
}
|
|
976
|
+
emStrongMask(e) {
|
|
977
|
+
return e;
|
|
978
|
+
}
|
|
979
|
+
provideLexer() {
|
|
980
|
+
return this.block ? x.lex : x.lexInline;
|
|
981
|
+
}
|
|
982
|
+
provideParser() {
|
|
983
|
+
return this.block ? b.parse : b.parseInline;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
var B = class {
|
|
987
|
+
defaults = L();
|
|
988
|
+
options = this.setOptions;
|
|
989
|
+
parse = this.parseMarkdown(true);
|
|
990
|
+
parseInline = this.parseMarkdown(false);
|
|
991
|
+
Parser = b;
|
|
992
|
+
Renderer = P;
|
|
993
|
+
TextRenderer = $;
|
|
994
|
+
Lexer = x;
|
|
995
|
+
Tokenizer = y;
|
|
996
|
+
Hooks = S;
|
|
997
|
+
constructor(...e) {
|
|
998
|
+
this.use(...e);
|
|
999
|
+
}
|
|
1000
|
+
walkTokens(e, t) {
|
|
1001
|
+
let n = [];
|
|
1002
|
+
for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
|
|
1003
|
+
case "table": {
|
|
1004
|
+
let i = r;
|
|
1005
|
+
for (let s of i.header) n = n.concat(this.walkTokens(s.tokens, t));
|
|
1006
|
+
for (let s of i.rows) for (let a of s) n = n.concat(this.walkTokens(a.tokens, t));
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case "list": {
|
|
1010
|
+
let i = r;
|
|
1011
|
+
n = n.concat(this.walkTokens(i.items, t));
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
default: {
|
|
1015
|
+
let i = r;
|
|
1016
|
+
this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
|
|
1017
|
+
let a = i[s].flat(1 / 0);
|
|
1018
|
+
n = n.concat(this.walkTokens(a, t));
|
|
1019
|
+
}) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return n;
|
|
1023
|
+
}
|
|
1024
|
+
use(...e) {
|
|
1025
|
+
let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
1026
|
+
return e.forEach((n) => {
|
|
1027
|
+
let r = { ...n };
|
|
1028
|
+
if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
|
|
1029
|
+
if (!i.name) throw new Error("extension name required");
|
|
1030
|
+
if ("renderer" in i) {
|
|
1031
|
+
let s = t.renderers[i.name];
|
|
1032
|
+
s ? t.renderers[i.name] = function(...a) {
|
|
1033
|
+
let o = i.renderer.apply(this, a);
|
|
1034
|
+
return o === false && (o = s.apply(this, a)), o;
|
|
1035
|
+
} : t.renderers[i.name] = i.renderer;
|
|
1036
|
+
}
|
|
1037
|
+
if ("tokenizer" in i) {
|
|
1038
|
+
if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
|
|
1039
|
+
let s = t[i.level];
|
|
1040
|
+
s ? s.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
|
|
1041
|
+
}
|
|
1042
|
+
"childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
|
|
1043
|
+
}), r.extensions = t), n.renderer) {
|
|
1044
|
+
let i = this.defaults.renderer || new P(this.defaults);
|
|
1045
|
+
for (let s in n.renderer) {
|
|
1046
|
+
if (!(s in i)) throw new Error(`renderer '${s}' does not exist`);
|
|
1047
|
+
if (["options", "parser"].includes(s)) continue;
|
|
1048
|
+
let a = s, o = n.renderer[a], l = i[a];
|
|
1049
|
+
i[a] = (...p) => {
|
|
1050
|
+
let c = o.apply(i, p);
|
|
1051
|
+
return c === false && (c = l.apply(i, p)), c || "";
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
r.renderer = i;
|
|
1055
|
+
}
|
|
1056
|
+
if (n.tokenizer) {
|
|
1057
|
+
let i = this.defaults.tokenizer || new y(this.defaults);
|
|
1058
|
+
for (let s in n.tokenizer) {
|
|
1059
|
+
if (!(s in i)) throw new Error(`tokenizer '${s}' does not exist`);
|
|
1060
|
+
if (["options", "rules", "lexer"].includes(s)) continue;
|
|
1061
|
+
let a = s, o = n.tokenizer[a], l = i[a];
|
|
1062
|
+
i[a] = (...p) => {
|
|
1063
|
+
let c = o.apply(i, p);
|
|
1064
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
r.tokenizer = i;
|
|
1068
|
+
}
|
|
1069
|
+
if (n.hooks) {
|
|
1070
|
+
let i = this.defaults.hooks || new S();
|
|
1071
|
+
for (let s in n.hooks) {
|
|
1072
|
+
if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
|
|
1073
|
+
if (["options", "block"].includes(s)) continue;
|
|
1074
|
+
let a = s, o = n.hooks[a], l = i[a];
|
|
1075
|
+
S.passThroughHooks.has(s) ? i[a] = (p) => {
|
|
1076
|
+
if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return (async () => {
|
|
1077
|
+
let g = await o.call(i, p);
|
|
1078
|
+
return l.call(i, g);
|
|
1079
|
+
})();
|
|
1080
|
+
let c = o.call(i, p);
|
|
1081
|
+
return l.call(i, c);
|
|
1082
|
+
} : i[a] = (...p) => {
|
|
1083
|
+
if (this.defaults.async) return (async () => {
|
|
1084
|
+
let g = await o.apply(i, p);
|
|
1085
|
+
return g === false && (g = await l.apply(i, p)), g;
|
|
1086
|
+
})();
|
|
1087
|
+
let c = o.apply(i, p);
|
|
1088
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
r.hooks = i;
|
|
1092
|
+
}
|
|
1093
|
+
if (n.walkTokens) {
|
|
1094
|
+
let i = this.defaults.walkTokens, s = n.walkTokens;
|
|
1095
|
+
r.walkTokens = function(a) {
|
|
1096
|
+
let o = [];
|
|
1097
|
+
return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
this.defaults = { ...this.defaults, ...r };
|
|
1101
|
+
}), this;
|
|
1102
|
+
}
|
|
1103
|
+
setOptions(e) {
|
|
1104
|
+
return this.defaults = { ...this.defaults, ...e }, this;
|
|
1105
|
+
}
|
|
1106
|
+
lexer(e, t) {
|
|
1107
|
+
return x.lex(e, t ?? this.defaults);
|
|
1108
|
+
}
|
|
1109
|
+
parser(e, t) {
|
|
1110
|
+
return b.parse(e, t ?? this.defaults);
|
|
1111
|
+
}
|
|
1112
|
+
parseMarkdown(e) {
|
|
1113
|
+
return (n, r) => {
|
|
1114
|
+
let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
|
|
1115
|
+
if (this.defaults.async === true && i.async === false) return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
1116
|
+
if (typeof n > "u" || n === null) return a(new Error("marked(): input parameter is undefined or null"));
|
|
1117
|
+
if (typeof n != "string") return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
1118
|
+
if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async) return (async () => {
|
|
1119
|
+
let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
|
|
1120
|
+
s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
|
|
1121
|
+
let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
|
|
1122
|
+
return s.hooks ? await s.hooks.postprocess(h) : h;
|
|
1123
|
+
})().catch(a);
|
|
1124
|
+
try {
|
|
1125
|
+
s.hooks && (n = s.hooks.preprocess(n));
|
|
1126
|
+
let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
|
|
1127
|
+
s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
|
|
1128
|
+
let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
|
|
1129
|
+
return s.hooks && (c = s.hooks.postprocess(c)), c;
|
|
1130
|
+
} catch (o) {
|
|
1131
|
+
return a(o);
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
onError(e, t) {
|
|
1136
|
+
return (n) => {
|
|
1137
|
+
if (n.message += `
|
|
1138
|
+
Please report this to https://github.com/markedjs/marked.`, e) {
|
|
1139
|
+
let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
|
|
1140
|
+
return t ? Promise.resolve(r) : r;
|
|
1141
|
+
}
|
|
1142
|
+
if (t) return Promise.reject(n);
|
|
1143
|
+
throw n;
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
var _ = new B();
|
|
1148
|
+
function d(u3, e) {
|
|
1149
|
+
return _.parse(u3, e);
|
|
1150
|
+
}
|
|
1151
|
+
d.options = d.setOptions = function(u3) {
|
|
1152
|
+
return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
1153
|
+
};
|
|
1154
|
+
d.getDefaults = L;
|
|
1155
|
+
d.defaults = T;
|
|
1156
|
+
d.use = function(...u3) {
|
|
1157
|
+
return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
|
|
1158
|
+
};
|
|
1159
|
+
d.walkTokens = function(u3, e) {
|
|
1160
|
+
return _.walkTokens(u3, e);
|
|
1161
|
+
};
|
|
1162
|
+
d.parseInline = _.parseInline;
|
|
1163
|
+
d.Parser = b;
|
|
1164
|
+
d.parser = b.parse;
|
|
1165
|
+
d.Renderer = P;
|
|
1166
|
+
d.TextRenderer = $;
|
|
1167
|
+
d.Lexer = x;
|
|
1168
|
+
d.lexer = x.lex;
|
|
1169
|
+
d.Tokenizer = y;
|
|
1170
|
+
d.Hooks = S;
|
|
1171
|
+
d.parse = d;
|
|
1172
|
+
var Dt = d.options;
|
|
1173
|
+
var Ht = d.setOptions;
|
|
1174
|
+
var Zt = d.use;
|
|
1175
|
+
var Gt = d.walkTokens;
|
|
1176
|
+
var Nt = d.parseInline;
|
|
1177
|
+
var Ft = b.parse;
|
|
1178
|
+
var jt = x.lex;
|
|
1179
|
+
|
|
1180
|
+
// node_modules/.pnpm/dompurify@3.3.1/node_modules/dompurify/dist/purify.es.mjs
|
|
1181
|
+
var {
|
|
1182
|
+
entries,
|
|
1183
|
+
setPrototypeOf,
|
|
1184
|
+
isFrozen,
|
|
1185
|
+
getPrototypeOf,
|
|
1186
|
+
getOwnPropertyDescriptor
|
|
1187
|
+
} = Object;
|
|
1188
|
+
var {
|
|
1189
|
+
freeze,
|
|
1190
|
+
seal,
|
|
1191
|
+
create
|
|
1192
|
+
} = Object;
|
|
1193
|
+
var {
|
|
1194
|
+
apply,
|
|
1195
|
+
construct
|
|
1196
|
+
} = typeof Reflect !== "undefined" && Reflect;
|
|
1197
|
+
if (!freeze) {
|
|
1198
|
+
freeze = function freeze2(x2) {
|
|
1199
|
+
return x2;
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
if (!seal) {
|
|
1203
|
+
seal = function seal2(x2) {
|
|
1204
|
+
return x2;
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
if (!apply) {
|
|
1208
|
+
apply = function apply2(func, thisArg) {
|
|
1209
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1210
|
+
args[_key - 2] = arguments[_key];
|
|
1211
|
+
}
|
|
1212
|
+
return func.apply(thisArg, args);
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
if (!construct) {
|
|
1216
|
+
construct = function construct2(Func) {
|
|
1217
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1218
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1219
|
+
}
|
|
1220
|
+
return new Func(...args);
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
var arrayForEach = unapply(Array.prototype.forEach);
|
|
1224
|
+
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
1225
|
+
var arrayPop = unapply(Array.prototype.pop);
|
|
1226
|
+
var arrayPush = unapply(Array.prototype.push);
|
|
1227
|
+
var arraySplice = unapply(Array.prototype.splice);
|
|
1228
|
+
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
1229
|
+
var stringToString = unapply(String.prototype.toString);
|
|
1230
|
+
var stringMatch = unapply(String.prototype.match);
|
|
1231
|
+
var stringReplace = unapply(String.prototype.replace);
|
|
1232
|
+
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
1233
|
+
var stringTrim = unapply(String.prototype.trim);
|
|
1234
|
+
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
1235
|
+
var regExpTest = unapply(RegExp.prototype.test);
|
|
1236
|
+
var typeErrorCreate = unconstruct(TypeError);
|
|
1237
|
+
function unapply(func) {
|
|
1238
|
+
return function(thisArg) {
|
|
1239
|
+
if (thisArg instanceof RegExp) {
|
|
1240
|
+
thisArg.lastIndex = 0;
|
|
1241
|
+
}
|
|
1242
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
1243
|
+
args[_key3 - 1] = arguments[_key3];
|
|
1244
|
+
}
|
|
1245
|
+
return apply(func, thisArg, args);
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
function unconstruct(Func) {
|
|
1249
|
+
return function() {
|
|
1250
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1251
|
+
args[_key4] = arguments[_key4];
|
|
1252
|
+
}
|
|
1253
|
+
return construct(Func, args);
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
function addToSet(set, array) {
|
|
1257
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
1258
|
+
if (setPrototypeOf) {
|
|
1259
|
+
setPrototypeOf(set, null);
|
|
1260
|
+
}
|
|
1261
|
+
let l = array.length;
|
|
1262
|
+
while (l--) {
|
|
1263
|
+
let element2 = array[l];
|
|
1264
|
+
if (typeof element2 === "string") {
|
|
1265
|
+
const lcElement = transformCaseFunc(element2);
|
|
1266
|
+
if (lcElement !== element2) {
|
|
1267
|
+
if (!isFrozen(array)) {
|
|
1268
|
+
array[l] = lcElement;
|
|
1269
|
+
}
|
|
1270
|
+
element2 = lcElement;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
set[element2] = true;
|
|
1274
|
+
}
|
|
1275
|
+
return set;
|
|
1276
|
+
}
|
|
1277
|
+
function cleanArray(array) {
|
|
1278
|
+
for (let index = 0; index < array.length; index++) {
|
|
1279
|
+
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
1280
|
+
if (!isPropertyExist) {
|
|
1281
|
+
array[index] = null;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return array;
|
|
1285
|
+
}
|
|
1286
|
+
function clone(object) {
|
|
1287
|
+
const newObject = create(null);
|
|
1288
|
+
for (const [property, value] of entries(object)) {
|
|
1289
|
+
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
1290
|
+
if (isPropertyExist) {
|
|
1291
|
+
if (Array.isArray(value)) {
|
|
1292
|
+
newObject[property] = cleanArray(value);
|
|
1293
|
+
} else if (value && typeof value === "object" && value.constructor === Object) {
|
|
1294
|
+
newObject[property] = clone(value);
|
|
1295
|
+
} else {
|
|
1296
|
+
newObject[property] = value;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return newObject;
|
|
1301
|
+
}
|
|
1302
|
+
function lookupGetter(object, prop) {
|
|
1303
|
+
while (object !== null) {
|
|
1304
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
1305
|
+
if (desc) {
|
|
1306
|
+
if (desc.get) {
|
|
1307
|
+
return unapply(desc.get);
|
|
1308
|
+
}
|
|
1309
|
+
if (typeof desc.value === "function") {
|
|
1310
|
+
return unapply(desc.value);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
object = getPrototypeOf(object);
|
|
1314
|
+
}
|
|
1315
|
+
function fallbackValue() {
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
return fallbackValue;
|
|
1319
|
+
}
|
|
1320
|
+
var html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
|
|
1321
|
+
var svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
|
|
1322
|
+
var svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
|
|
1323
|
+
var svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
|
|
1324
|
+
var mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
|
|
1325
|
+
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
|
1326
|
+
var text = freeze(["#text"]);
|
|
1327
|
+
var html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
|
|
1328
|
+
var svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
|
|
1329
|
+
var mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
|
|
1330
|
+
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
|
1331
|
+
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
|
1332
|
+
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
1333
|
+
var TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
|
|
1334
|
+
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
1335
|
+
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
1336
|
+
var IS_ALLOWED_URI = seal(
|
|
1337
|
+
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
1338
|
+
// eslint-disable-line no-useless-escape
|
|
1339
|
+
);
|
|
1340
|
+
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
1341
|
+
var ATTR_WHITESPACE = seal(
|
|
1342
|
+
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
1343
|
+
// eslint-disable-line no-control-regex
|
|
1344
|
+
);
|
|
1345
|
+
var DOCTYPE_NAME = seal(/^html$/i);
|
|
1346
|
+
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
1347
|
+
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
|
1348
|
+
__proto__: null,
|
|
1349
|
+
ARIA_ATTR,
|
|
1350
|
+
ATTR_WHITESPACE,
|
|
1351
|
+
CUSTOM_ELEMENT,
|
|
1352
|
+
DATA_ATTR,
|
|
1353
|
+
DOCTYPE_NAME,
|
|
1354
|
+
ERB_EXPR,
|
|
1355
|
+
IS_ALLOWED_URI,
|
|
1356
|
+
IS_SCRIPT_OR_DATA,
|
|
1357
|
+
MUSTACHE_EXPR,
|
|
1358
|
+
TMPLIT_EXPR
|
|
1359
|
+
});
|
|
1360
|
+
var NODE_TYPE = {
|
|
1361
|
+
element: 1,
|
|
1362
|
+
attribute: 2,
|
|
1363
|
+
text: 3,
|
|
1364
|
+
cdataSection: 4,
|
|
1365
|
+
entityReference: 5,
|
|
1366
|
+
// Deprecated
|
|
1367
|
+
entityNode: 6,
|
|
1368
|
+
// Deprecated
|
|
1369
|
+
progressingInstruction: 7,
|
|
1370
|
+
comment: 8,
|
|
1371
|
+
document: 9,
|
|
1372
|
+
documentType: 10,
|
|
1373
|
+
documentFragment: 11,
|
|
1374
|
+
notation: 12
|
|
1375
|
+
// Deprecated
|
|
1376
|
+
};
|
|
1377
|
+
var getGlobal = function getGlobal2() {
|
|
1378
|
+
return typeof window === "undefined" ? null : window;
|
|
1379
|
+
};
|
|
1380
|
+
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
1381
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
let suffix = null;
|
|
1385
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
1386
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
1387
|
+
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
1388
|
+
}
|
|
1389
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
1390
|
+
try {
|
|
1391
|
+
return trustedTypes.createPolicy(policyName, {
|
|
1392
|
+
createHTML(html2) {
|
|
1393
|
+
return html2;
|
|
1394
|
+
},
|
|
1395
|
+
createScriptURL(scriptUrl) {
|
|
1396
|
+
return scriptUrl;
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
} catch (_2) {
|
|
1400
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
1401
|
+
return null;
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
var _createHooksMap = function _createHooksMap2() {
|
|
1405
|
+
return {
|
|
1406
|
+
afterSanitizeAttributes: [],
|
|
1407
|
+
afterSanitizeElements: [],
|
|
1408
|
+
afterSanitizeShadowDOM: [],
|
|
1409
|
+
beforeSanitizeAttributes: [],
|
|
1410
|
+
beforeSanitizeElements: [],
|
|
1411
|
+
beforeSanitizeShadowDOM: [],
|
|
1412
|
+
uponSanitizeAttribute: [],
|
|
1413
|
+
uponSanitizeElement: [],
|
|
1414
|
+
uponSanitizeShadowNode: []
|
|
1415
|
+
};
|
|
1416
|
+
};
|
|
1417
|
+
function createDOMPurify() {
|
|
1418
|
+
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
1419
|
+
const DOMPurify = (root) => createDOMPurify(root);
|
|
1420
|
+
DOMPurify.version = "3.3.1";
|
|
1421
|
+
DOMPurify.removed = [];
|
|
1422
|
+
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
|
|
1423
|
+
DOMPurify.isSupported = false;
|
|
1424
|
+
return DOMPurify;
|
|
1425
|
+
}
|
|
1426
|
+
let {
|
|
1427
|
+
document: document2
|
|
1428
|
+
} = window2;
|
|
1429
|
+
const originalDocument = document2;
|
|
1430
|
+
const currentScript = originalDocument.currentScript;
|
|
1431
|
+
const {
|
|
1432
|
+
DocumentFragment,
|
|
1433
|
+
HTMLTemplateElement,
|
|
1434
|
+
Node,
|
|
1435
|
+
Element,
|
|
1436
|
+
NodeFilter,
|
|
1437
|
+
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
|
1438
|
+
HTMLFormElement,
|
|
1439
|
+
DOMParser,
|
|
1440
|
+
trustedTypes
|
|
1441
|
+
} = window2;
|
|
1442
|
+
const ElementPrototype = Element.prototype;
|
|
1443
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
1444
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
1445
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
1446
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
1447
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
1448
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
1449
|
+
const template = document2.createElement("template");
|
|
1450
|
+
if (template.content && template.content.ownerDocument) {
|
|
1451
|
+
document2 = template.content.ownerDocument;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
let trustedTypesPolicy;
|
|
1455
|
+
let emptyHTML = "";
|
|
1456
|
+
const {
|
|
1457
|
+
implementation,
|
|
1458
|
+
createNodeIterator,
|
|
1459
|
+
createDocumentFragment,
|
|
1460
|
+
getElementsByTagName
|
|
1461
|
+
} = document2;
|
|
1462
|
+
const {
|
|
1463
|
+
importNode
|
|
1464
|
+
} = originalDocument;
|
|
1465
|
+
let hooks = _createHooksMap();
|
|
1466
|
+
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
1467
|
+
const {
|
|
1468
|
+
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
|
1469
|
+
ERB_EXPR: ERB_EXPR2,
|
|
1470
|
+
TMPLIT_EXPR: TMPLIT_EXPR2,
|
|
1471
|
+
DATA_ATTR: DATA_ATTR2,
|
|
1472
|
+
ARIA_ATTR: ARIA_ATTR2,
|
|
1473
|
+
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
|
1474
|
+
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
|
1475
|
+
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
|
1476
|
+
} = EXPRESSIONS;
|
|
1477
|
+
let {
|
|
1478
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
1479
|
+
} = EXPRESSIONS;
|
|
1480
|
+
let ALLOWED_TAGS = null;
|
|
1481
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
1482
|
+
let ALLOWED_ATTR = null;
|
|
1483
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
1484
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1485
|
+
tagNameCheck: {
|
|
1486
|
+
writable: true,
|
|
1487
|
+
configurable: false,
|
|
1488
|
+
enumerable: true,
|
|
1489
|
+
value: null
|
|
1490
|
+
},
|
|
1491
|
+
attributeNameCheck: {
|
|
1492
|
+
writable: true,
|
|
1493
|
+
configurable: false,
|
|
1494
|
+
enumerable: true,
|
|
1495
|
+
value: null
|
|
1496
|
+
},
|
|
1497
|
+
allowCustomizedBuiltInElements: {
|
|
1498
|
+
writable: true,
|
|
1499
|
+
configurable: false,
|
|
1500
|
+
enumerable: true,
|
|
1501
|
+
value: false
|
|
1502
|
+
}
|
|
1503
|
+
}));
|
|
1504
|
+
let FORBID_TAGS = null;
|
|
1505
|
+
let FORBID_ATTR = null;
|
|
1506
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
1507
|
+
tagCheck: {
|
|
1508
|
+
writable: true,
|
|
1509
|
+
configurable: false,
|
|
1510
|
+
enumerable: true,
|
|
1511
|
+
value: null
|
|
1512
|
+
},
|
|
1513
|
+
attributeCheck: {
|
|
1514
|
+
writable: true,
|
|
1515
|
+
configurable: false,
|
|
1516
|
+
enumerable: true,
|
|
1517
|
+
value: null
|
|
1518
|
+
}
|
|
1519
|
+
}));
|
|
1520
|
+
let ALLOW_ARIA_ATTR = true;
|
|
1521
|
+
let ALLOW_DATA_ATTR = true;
|
|
1522
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
1523
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
1524
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
1525
|
+
let SAFE_FOR_XML = true;
|
|
1526
|
+
let WHOLE_DOCUMENT = false;
|
|
1527
|
+
let SET_CONFIG = false;
|
|
1528
|
+
let FORCE_BODY = false;
|
|
1529
|
+
let RETURN_DOM = false;
|
|
1530
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
1531
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
1532
|
+
let SANITIZE_DOM = true;
|
|
1533
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
1534
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
1535
|
+
let KEEP_CONTENT = true;
|
|
1536
|
+
let IN_PLACE = false;
|
|
1537
|
+
let USE_PROFILES = {};
|
|
1538
|
+
let FORBID_CONTENTS = null;
|
|
1539
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
|
1540
|
+
let DATA_URI_TAGS = null;
|
|
1541
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
1542
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
1543
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
|
1544
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
1545
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
1546
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
1547
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
1548
|
+
let IS_EMPTY_INPUT = false;
|
|
1549
|
+
let ALLOWED_NAMESPACES = null;
|
|
1550
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
1551
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
|
1552
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
|
1553
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
|
1554
|
+
let PARSER_MEDIA_TYPE = null;
|
|
1555
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
1556
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
1557
|
+
let transformCaseFunc = null;
|
|
1558
|
+
let CONFIG = null;
|
|
1559
|
+
const formElement = document2.createElement("form");
|
|
1560
|
+
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
1561
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
1562
|
+
};
|
|
1563
|
+
const _parseConfig = function _parseConfig2() {
|
|
1564
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1565
|
+
if (CONFIG && CONFIG === cfg) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
if (!cfg || typeof cfg !== "object") {
|
|
1569
|
+
cfg = {};
|
|
1570
|
+
}
|
|
1571
|
+
cfg = clone(cfg);
|
|
1572
|
+
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
1573
|
+
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
1574
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
1575
|
+
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
1576
|
+
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
1577
|
+
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
1578
|
+
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
1579
|
+
DATA_URI_TAGS = objectHasOwnProperty(cfg, "ADD_DATA_URI_TAGS") ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
|
1580
|
+
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
1581
|
+
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
|
|
1582
|
+
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
|
|
1583
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
|
1584
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
1585
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
1586
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
1587
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
1588
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
1589
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
1590
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
1591
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
1592
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
1593
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
1594
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
1595
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
1596
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
1597
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
1598
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
1599
|
+
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
1600
|
+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
1601
|
+
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
1602
|
+
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
1603
|
+
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
1604
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
1605
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
1606
|
+
}
|
|
1607
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
1608
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
1609
|
+
}
|
|
1610
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
|
1611
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
1612
|
+
}
|
|
1613
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1614
|
+
ALLOW_DATA_ATTR = false;
|
|
1615
|
+
}
|
|
1616
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
1617
|
+
RETURN_DOM = true;
|
|
1618
|
+
}
|
|
1619
|
+
if (USE_PROFILES) {
|
|
1620
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
1621
|
+
ALLOWED_ATTR = [];
|
|
1622
|
+
if (USE_PROFILES.html === true) {
|
|
1623
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
1624
|
+
addToSet(ALLOWED_ATTR, html);
|
|
1625
|
+
}
|
|
1626
|
+
if (USE_PROFILES.svg === true) {
|
|
1627
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
1628
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1629
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1630
|
+
}
|
|
1631
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
1632
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
1633
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
1634
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1635
|
+
}
|
|
1636
|
+
if (USE_PROFILES.mathMl === true) {
|
|
1637
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
1638
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
1639
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
if (cfg.ADD_TAGS) {
|
|
1643
|
+
if (typeof cfg.ADD_TAGS === "function") {
|
|
1644
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
1645
|
+
} else {
|
|
1646
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
1647
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
1648
|
+
}
|
|
1649
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
if (cfg.ADD_ATTR) {
|
|
1653
|
+
if (typeof cfg.ADD_ATTR === "function") {
|
|
1654
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
1655
|
+
} else {
|
|
1656
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
1657
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
1658
|
+
}
|
|
1659
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
1663
|
+
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
1664
|
+
}
|
|
1665
|
+
if (cfg.FORBID_CONTENTS) {
|
|
1666
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
1667
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1668
|
+
}
|
|
1669
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
1670
|
+
}
|
|
1671
|
+
if (cfg.ADD_FORBID_CONTENTS) {
|
|
1672
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
1673
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1674
|
+
}
|
|
1675
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
1676
|
+
}
|
|
1677
|
+
if (KEEP_CONTENT) {
|
|
1678
|
+
ALLOWED_TAGS["#text"] = true;
|
|
1679
|
+
}
|
|
1680
|
+
if (WHOLE_DOCUMENT) {
|
|
1681
|
+
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
|
1682
|
+
}
|
|
1683
|
+
if (ALLOWED_TAGS.table) {
|
|
1684
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
1685
|
+
delete FORBID_TAGS.tbody;
|
|
1686
|
+
}
|
|
1687
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
1688
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
|
1689
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
1690
|
+
}
|
|
1691
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
|
1692
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
1693
|
+
}
|
|
1694
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
1695
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
1696
|
+
} else {
|
|
1697
|
+
if (trustedTypesPolicy === void 0) {
|
|
1698
|
+
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
1699
|
+
}
|
|
1700
|
+
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
|
1701
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (freeze) {
|
|
1705
|
+
freeze(cfg);
|
|
1706
|
+
}
|
|
1707
|
+
CONFIG = cfg;
|
|
1708
|
+
};
|
|
1709
|
+
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
1710
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
1711
|
+
const _checkValidNamespace = function _checkValidNamespace2(element2) {
|
|
1712
|
+
let parent = getParentNode(element2);
|
|
1713
|
+
if (!parent || !parent.tagName) {
|
|
1714
|
+
parent = {
|
|
1715
|
+
namespaceURI: NAMESPACE,
|
|
1716
|
+
tagName: "template"
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
const tagName = stringToLowerCase(element2.tagName);
|
|
1720
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
1721
|
+
if (!ALLOWED_NAMESPACES[element2.namespaceURI]) {
|
|
1722
|
+
return false;
|
|
1723
|
+
}
|
|
1724
|
+
if (element2.namespaceURI === SVG_NAMESPACE) {
|
|
1725
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1726
|
+
return tagName === "svg";
|
|
1727
|
+
}
|
|
1728
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
1729
|
+
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
1730
|
+
}
|
|
1731
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
1732
|
+
}
|
|
1733
|
+
if (element2.namespaceURI === MATHML_NAMESPACE) {
|
|
1734
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1735
|
+
return tagName === "math";
|
|
1736
|
+
}
|
|
1737
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
1738
|
+
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
1739
|
+
}
|
|
1740
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
1741
|
+
}
|
|
1742
|
+
if (element2.namespaceURI === HTML_NAMESPACE) {
|
|
1743
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
1744
|
+
return false;
|
|
1745
|
+
}
|
|
1746
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
1747
|
+
return false;
|
|
1748
|
+
}
|
|
1749
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
1750
|
+
}
|
|
1751
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element2.namespaceURI]) {
|
|
1752
|
+
return true;
|
|
1753
|
+
}
|
|
1754
|
+
return false;
|
|
1755
|
+
};
|
|
1756
|
+
const _forceRemove = function _forceRemove2(node) {
|
|
1757
|
+
arrayPush(DOMPurify.removed, {
|
|
1758
|
+
element: node
|
|
1759
|
+
});
|
|
1760
|
+
try {
|
|
1761
|
+
getParentNode(node).removeChild(node);
|
|
1762
|
+
} catch (_2) {
|
|
1763
|
+
remove(node);
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
const _removeAttribute = function _removeAttribute2(name, element2) {
|
|
1767
|
+
try {
|
|
1768
|
+
arrayPush(DOMPurify.removed, {
|
|
1769
|
+
attribute: element2.getAttributeNode(name),
|
|
1770
|
+
from: element2
|
|
1771
|
+
});
|
|
1772
|
+
} catch (_2) {
|
|
1773
|
+
arrayPush(DOMPurify.removed, {
|
|
1774
|
+
attribute: null,
|
|
1775
|
+
from: element2
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
element2.removeAttribute(name);
|
|
1779
|
+
if (name === "is") {
|
|
1780
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
1781
|
+
try {
|
|
1782
|
+
_forceRemove(element2);
|
|
1783
|
+
} catch (_2) {
|
|
1784
|
+
}
|
|
1785
|
+
} else {
|
|
1786
|
+
try {
|
|
1787
|
+
element2.setAttribute(name, "");
|
|
1788
|
+
} catch (_2) {
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
const _initDocument = function _initDocument2(dirty2) {
|
|
1794
|
+
let doc = null;
|
|
1795
|
+
let leadingWhitespace = null;
|
|
1796
|
+
if (FORCE_BODY) {
|
|
1797
|
+
dirty2 = "<remove></remove>" + dirty2;
|
|
1798
|
+
} else {
|
|
1799
|
+
const matches = stringMatch(dirty2, /^[\r\n\t ]+/);
|
|
1800
|
+
leadingWhitespace = matches && matches[0];
|
|
1801
|
+
}
|
|
1802
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
|
1803
|
+
dirty2 = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty2 + "</body></html>";
|
|
1804
|
+
}
|
|
1805
|
+
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty2) : dirty2;
|
|
1806
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
1807
|
+
try {
|
|
1808
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
1809
|
+
} catch (_2) {
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
if (!doc || !doc.documentElement) {
|
|
1813
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
1814
|
+
try {
|
|
1815
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
1816
|
+
} catch (_2) {
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const body = doc.body || doc.documentElement;
|
|
1820
|
+
if (dirty2 && leadingWhitespace) {
|
|
1821
|
+
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
1822
|
+
}
|
|
1823
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
1824
|
+
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
1825
|
+
}
|
|
1826
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
1827
|
+
};
|
|
1828
|
+
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
1829
|
+
return createNodeIterator.call(
|
|
1830
|
+
root.ownerDocument || root,
|
|
1831
|
+
root,
|
|
1832
|
+
// eslint-disable-next-line no-bitwise
|
|
1833
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
|
1834
|
+
null
|
|
1835
|
+
);
|
|
1836
|
+
};
|
|
1837
|
+
const _isClobbered = function _isClobbered2(element2) {
|
|
1838
|
+
return element2 instanceof HTMLFormElement && (typeof element2.nodeName !== "string" || typeof element2.textContent !== "string" || typeof element2.removeChild !== "function" || !(element2.attributes instanceof NamedNodeMap) || typeof element2.removeAttribute !== "function" || typeof element2.setAttribute !== "function" || typeof element2.namespaceURI !== "string" || typeof element2.insertBefore !== "function" || typeof element2.hasChildNodes !== "function");
|
|
1839
|
+
};
|
|
1840
|
+
const _isNode = function _isNode2(value) {
|
|
1841
|
+
return typeof Node === "function" && value instanceof Node;
|
|
1842
|
+
};
|
|
1843
|
+
function _executeHooks(hooks2, currentNode, data) {
|
|
1844
|
+
arrayForEach(hooks2, (hook) => {
|
|
1845
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
1849
|
+
let content = null;
|
|
1850
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
1851
|
+
if (_isClobbered(currentNode)) {
|
|
1852
|
+
_forceRemove(currentNode);
|
|
1853
|
+
return true;
|
|
1854
|
+
}
|
|
1855
|
+
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
1856
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
1857
|
+
tagName,
|
|
1858
|
+
allowedTags: ALLOWED_TAGS
|
|
1859
|
+
});
|
|
1860
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
|
|
1861
|
+
_forceRemove(currentNode);
|
|
1862
|
+
return true;
|
|
1863
|
+
}
|
|
1864
|
+
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
1865
|
+
_forceRemove(currentNode);
|
|
1866
|
+
return true;
|
|
1867
|
+
}
|
|
1868
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
1869
|
+
_forceRemove(currentNode);
|
|
1870
|
+
return true;
|
|
1871
|
+
}
|
|
1872
|
+
if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
|
|
1873
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
1874
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
1875
|
+
return false;
|
|
1876
|
+
}
|
|
1877
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
1878
|
+
return false;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
1882
|
+
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
1883
|
+
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
1884
|
+
if (childNodes && parentNode) {
|
|
1885
|
+
const childCount = childNodes.length;
|
|
1886
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
1887
|
+
const childClone = cloneNode(childNodes[i], true);
|
|
1888
|
+
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
1889
|
+
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
_forceRemove(currentNode);
|
|
1894
|
+
return true;
|
|
1895
|
+
}
|
|
1896
|
+
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
1897
|
+
_forceRemove(currentNode);
|
|
1898
|
+
return true;
|
|
1899
|
+
}
|
|
1900
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
1901
|
+
_forceRemove(currentNode);
|
|
1902
|
+
return true;
|
|
1903
|
+
}
|
|
1904
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
1905
|
+
content = currentNode.textContent;
|
|
1906
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
1907
|
+
content = stringReplace(content, expr, " ");
|
|
1908
|
+
});
|
|
1909
|
+
if (currentNode.textContent !== content) {
|
|
1910
|
+
arrayPush(DOMPurify.removed, {
|
|
1911
|
+
element: currentNode.cloneNode()
|
|
1912
|
+
});
|
|
1913
|
+
currentNode.textContent = content;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
1917
|
+
return false;
|
|
1918
|
+
};
|
|
1919
|
+
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
|
1920
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
|
1921
|
+
return false;
|
|
1922
|
+
}
|
|
1923
|
+
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
|
1924
|
+
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
|
1925
|
+
else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ;
|
|
1926
|
+
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
1927
|
+
if (
|
|
1928
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
1929
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1930
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
1931
|
+
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
1932
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1933
|
+
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
|
1934
|
+
) ;
|
|
1935
|
+
else {
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
1938
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
1939
|
+
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
1940
|
+
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
1941
|
+
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
1942
|
+
else if (value) {
|
|
1943
|
+
return false;
|
|
1944
|
+
} else ;
|
|
1945
|
+
return true;
|
|
1946
|
+
};
|
|
1947
|
+
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
1948
|
+
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
|
1949
|
+
};
|
|
1950
|
+
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
1951
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
1952
|
+
const {
|
|
1953
|
+
attributes
|
|
1954
|
+
} = currentNode;
|
|
1955
|
+
if (!attributes || _isClobbered(currentNode)) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
const hookEvent = {
|
|
1959
|
+
attrName: "",
|
|
1960
|
+
attrValue: "",
|
|
1961
|
+
keepAttr: true,
|
|
1962
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
1963
|
+
forceKeepAttr: void 0
|
|
1964
|
+
};
|
|
1965
|
+
let l = attributes.length;
|
|
1966
|
+
while (l--) {
|
|
1967
|
+
const attr = attributes[l];
|
|
1968
|
+
const {
|
|
1969
|
+
name,
|
|
1970
|
+
namespaceURI,
|
|
1971
|
+
value: attrValue
|
|
1972
|
+
} = attr;
|
|
1973
|
+
const lcName = transformCaseFunc(name);
|
|
1974
|
+
const initValue = attrValue;
|
|
1975
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
1976
|
+
hookEvent.attrName = lcName;
|
|
1977
|
+
hookEvent.attrValue = value;
|
|
1978
|
+
hookEvent.keepAttr = true;
|
|
1979
|
+
hookEvent.forceKeepAttr = void 0;
|
|
1980
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
1981
|
+
value = hookEvent.attrValue;
|
|
1982
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
|
1983
|
+
_removeAttribute(name, currentNode);
|
|
1984
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1985
|
+
}
|
|
1986
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
|
|
1987
|
+
_removeAttribute(name, currentNode);
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
1991
|
+
_removeAttribute(name, currentNode);
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
if (hookEvent.forceKeepAttr) {
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
if (!hookEvent.keepAttr) {
|
|
1998
|
+
_removeAttribute(name, currentNode);
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
2002
|
+
_removeAttribute(name, currentNode);
|
|
2003
|
+
continue;
|
|
2004
|
+
}
|
|
2005
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
2006
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
2007
|
+
value = stringReplace(value, expr, " ");
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
2011
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
2012
|
+
_removeAttribute(name, currentNode);
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
|
2016
|
+
if (namespaceURI) ;
|
|
2017
|
+
else {
|
|
2018
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
2019
|
+
case "TrustedHTML": {
|
|
2020
|
+
value = trustedTypesPolicy.createHTML(value);
|
|
2021
|
+
break;
|
|
2022
|
+
}
|
|
2023
|
+
case "TrustedScriptURL": {
|
|
2024
|
+
value = trustedTypesPolicy.createScriptURL(value);
|
|
2025
|
+
break;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
if (value !== initValue) {
|
|
2031
|
+
try {
|
|
2032
|
+
if (namespaceURI) {
|
|
2033
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
2034
|
+
} else {
|
|
2035
|
+
currentNode.setAttribute(name, value);
|
|
2036
|
+
}
|
|
2037
|
+
if (_isClobbered(currentNode)) {
|
|
2038
|
+
_forceRemove(currentNode);
|
|
2039
|
+
} else {
|
|
2040
|
+
arrayPop(DOMPurify.removed);
|
|
2041
|
+
}
|
|
2042
|
+
} catch (_2) {
|
|
2043
|
+
_removeAttribute(name, currentNode);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
2048
|
+
};
|
|
2049
|
+
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
2050
|
+
let shadowNode = null;
|
|
2051
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
2052
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
2053
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
2054
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
2055
|
+
_sanitizeElements(shadowNode);
|
|
2056
|
+
_sanitizeAttributes(shadowNode);
|
|
2057
|
+
if (shadowNode.content instanceof DocumentFragment) {
|
|
2058
|
+
_sanitizeShadowDOM2(shadowNode.content);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
2062
|
+
};
|
|
2063
|
+
DOMPurify.sanitize = function(dirty2) {
|
|
2064
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2065
|
+
let body = null;
|
|
2066
|
+
let importedNode = null;
|
|
2067
|
+
let currentNode = null;
|
|
2068
|
+
let returnNode = null;
|
|
2069
|
+
IS_EMPTY_INPUT = !dirty2;
|
|
2070
|
+
if (IS_EMPTY_INPUT) {
|
|
2071
|
+
dirty2 = "<!-->";
|
|
2072
|
+
}
|
|
2073
|
+
if (typeof dirty2 !== "string" && !_isNode(dirty2)) {
|
|
2074
|
+
if (typeof dirty2.toString === "function") {
|
|
2075
|
+
dirty2 = dirty2.toString();
|
|
2076
|
+
if (typeof dirty2 !== "string") {
|
|
2077
|
+
throw typeErrorCreate("dirty is not a string, aborting");
|
|
2078
|
+
}
|
|
2079
|
+
} else {
|
|
2080
|
+
throw typeErrorCreate("toString is not a function");
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (!DOMPurify.isSupported) {
|
|
2084
|
+
return dirty2;
|
|
2085
|
+
}
|
|
2086
|
+
if (!SET_CONFIG) {
|
|
2087
|
+
_parseConfig(cfg);
|
|
2088
|
+
}
|
|
2089
|
+
DOMPurify.removed = [];
|
|
2090
|
+
if (typeof dirty2 === "string") {
|
|
2091
|
+
IN_PLACE = false;
|
|
2092
|
+
}
|
|
2093
|
+
if (IN_PLACE) {
|
|
2094
|
+
if (dirty2.nodeName) {
|
|
2095
|
+
const tagName = transformCaseFunc(dirty2.nodeName);
|
|
2096
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
2097
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
} else if (dirty2 instanceof Node) {
|
|
2101
|
+
body = _initDocument("<!---->");
|
|
2102
|
+
importedNode = body.ownerDocument.importNode(dirty2, true);
|
|
2103
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
|
2104
|
+
body = importedNode;
|
|
2105
|
+
} else if (importedNode.nodeName === "HTML") {
|
|
2106
|
+
body = importedNode;
|
|
2107
|
+
} else {
|
|
2108
|
+
body.appendChild(importedNode);
|
|
2109
|
+
}
|
|
2110
|
+
} else {
|
|
2111
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
2112
|
+
dirty2.indexOf("<") === -1) {
|
|
2113
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty2) : dirty2;
|
|
2114
|
+
}
|
|
2115
|
+
body = _initDocument(dirty2);
|
|
2116
|
+
if (!body) {
|
|
2117
|
+
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
if (body && FORCE_BODY) {
|
|
2121
|
+
_forceRemove(body.firstChild);
|
|
2122
|
+
}
|
|
2123
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty2 : body);
|
|
2124
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
2125
|
+
_sanitizeElements(currentNode);
|
|
2126
|
+
_sanitizeAttributes(currentNode);
|
|
2127
|
+
if (currentNode.content instanceof DocumentFragment) {
|
|
2128
|
+
_sanitizeShadowDOM(currentNode.content);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
if (IN_PLACE) {
|
|
2132
|
+
return dirty2;
|
|
2133
|
+
}
|
|
2134
|
+
if (RETURN_DOM) {
|
|
2135
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
2136
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
2137
|
+
while (body.firstChild) {
|
|
2138
|
+
returnNode.appendChild(body.firstChild);
|
|
2139
|
+
}
|
|
2140
|
+
} else {
|
|
2141
|
+
returnNode = body;
|
|
2142
|
+
}
|
|
2143
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
2144
|
+
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
2145
|
+
}
|
|
2146
|
+
return returnNode;
|
|
2147
|
+
}
|
|
2148
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
2149
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
2150
|
+
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
2151
|
+
}
|
|
2152
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
2153
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
2154
|
+
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
2158
|
+
};
|
|
2159
|
+
DOMPurify.setConfig = function() {
|
|
2160
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2161
|
+
_parseConfig(cfg);
|
|
2162
|
+
SET_CONFIG = true;
|
|
2163
|
+
};
|
|
2164
|
+
DOMPurify.clearConfig = function() {
|
|
2165
|
+
CONFIG = null;
|
|
2166
|
+
SET_CONFIG = false;
|
|
2167
|
+
};
|
|
2168
|
+
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
2169
|
+
if (!CONFIG) {
|
|
2170
|
+
_parseConfig({});
|
|
2171
|
+
}
|
|
2172
|
+
const lcTag = transformCaseFunc(tag);
|
|
2173
|
+
const lcName = transformCaseFunc(attr);
|
|
2174
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
2175
|
+
};
|
|
2176
|
+
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
2177
|
+
if (typeof hookFunction !== "function") {
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
2181
|
+
};
|
|
2182
|
+
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
2183
|
+
if (hookFunction !== void 0) {
|
|
2184
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
2185
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
2186
|
+
}
|
|
2187
|
+
return arrayPop(hooks[entryPoint]);
|
|
2188
|
+
};
|
|
2189
|
+
DOMPurify.removeHooks = function(entryPoint) {
|
|
2190
|
+
hooks[entryPoint] = [];
|
|
2191
|
+
};
|
|
2192
|
+
DOMPurify.removeAllHooks = function() {
|
|
2193
|
+
hooks = _createHooksMap();
|
|
2194
|
+
};
|
|
2195
|
+
return DOMPurify;
|
|
2196
|
+
}
|
|
2197
|
+
var purify = createDOMPurify();
|
|
2198
|
+
|
|
2199
|
+
// src/web/ui/ui.ts
|
|
2200
|
+
var iconHtml = (name) => `<span class="codicon codicon-${name}" aria-hidden="true"></span>`;
|
|
2201
|
+
var escapeHtml = (text2) => text2.replace(/[&<>"']/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[char]);
|
|
2202
|
+
function managedFileForUrl(url, files) {
|
|
2203
|
+
let value = url;
|
|
2204
|
+
try {
|
|
2205
|
+
value = decodeURIComponent(url);
|
|
2206
|
+
} catch {
|
|
2207
|
+
}
|
|
2208
|
+
const id = value.match(/(?:^|[/?#])(wf_[a-f0-9]{32})(?:$|[/?#])/i)?.[1];
|
|
2209
|
+
return files.find((file) => file.id === id || value === file.path || value === file.url || value === `file://${file.path}`);
|
|
2210
|
+
}
|
|
2211
|
+
function markdownHtml(text2, files = []) {
|
|
2212
|
+
const renderer = new d.Renderer();
|
|
2213
|
+
renderer.image = (token) => {
|
|
2214
|
+
const file = managedFileForUrl(token.href, files);
|
|
2215
|
+
return `<img src="${escapeHtml(file?.previewUrl ?? token.href)}" alt="${escapeHtml(token.text)}"${token.title ? ` title="${escapeHtml(token.title)}"` : ""}${file ? ` data-workflow-file="${escapeHtml(file.id)}"` : ""}>`;
|
|
2216
|
+
};
|
|
2217
|
+
renderer.link = (token) => {
|
|
2218
|
+
const file = managedFileForUrl(token.href, files);
|
|
2219
|
+
return `<a href="${escapeHtml(file?.previewUrl ?? token.href)}"${token.title ? ` title="${escapeHtml(token.title)}"` : ""}${file ? ` data-workflow-file="${escapeHtml(file.id)}"` : ""}>${renderer.parser.parseInline(token.tokens)}</a>`;
|
|
2220
|
+
};
|
|
2221
|
+
const fragment = purify.sanitize(d.parse(text2, { async: false, breaks: true, renderer }), {
|
|
2222
|
+
ALLOWED_TAGS: ["p", "br", "strong", "em", "del", "code", "pre", "ul", "ol", "li", "blockquote", "h1", "h2", "h3", "h4", "table", "thead", "tbody", "tr", "th", "td", "hr", "a", "img", "details", "summary", "input"],
|
|
2223
|
+
ALLOWED_ATTR: ["href", "title", "src", "alt", "class", "open", "data-workflow-file", "type", "checked", "disabled"],
|
|
2224
|
+
RETURN_DOM_FRAGMENT: true
|
|
2225
|
+
});
|
|
2226
|
+
for (const input of Array.from(fragment.querySelectorAll("input"))) {
|
|
2227
|
+
input.type = "checkbox";
|
|
2228
|
+
input.disabled = true;
|
|
2229
|
+
}
|
|
2230
|
+
const container = document.createElement("div");
|
|
2231
|
+
container.append(fragment);
|
|
2232
|
+
return container.innerHTML;
|
|
2233
|
+
}
|
|
2234
|
+
function iconButton(name, label, action2) {
|
|
2235
|
+
const button = document.createElement("button");
|
|
2236
|
+
button.type = "button";
|
|
2237
|
+
button.className = "icon-button";
|
|
2238
|
+
button.title = button.ariaLabel = label;
|
|
2239
|
+
button.innerHTML = iconHtml(name);
|
|
2240
|
+
button.addEventListener("click", action2);
|
|
2241
|
+
return button;
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
// src/web/ui/account.ts
|
|
2245
|
+
var AccountPanel = class {
|
|
2246
|
+
constructor(menu2, request2) {
|
|
2247
|
+
this.request = request2;
|
|
2248
|
+
this.button.id = "web-account";
|
|
2249
|
+
this.button.className = "web-account";
|
|
2250
|
+
this.button.type = "button";
|
|
2251
|
+
this.button.hidden = true;
|
|
2252
|
+
this.button.setAttribute("aria-haspopup", "dialog");
|
|
2253
|
+
this.button.setAttribute("aria-controls", "account-dialog");
|
|
2254
|
+
this.button.innerHTML = '<span class="web-avatar"></span><span class="web-account-name"></span>';
|
|
2255
|
+
this.button.addEventListener("click", () => this.open());
|
|
2256
|
+
menu2.append(this.button);
|
|
2257
|
+
this.dialog.id = "account-dialog";
|
|
2258
|
+
this.dialog.className = "conversation-dialog account-dialog";
|
|
2259
|
+
this.dialog.setAttribute("aria-labelledby", "account-title");
|
|
2260
|
+
this.dialog.innerHTML = `
|
|
2261
|
+
<header><span class="codicon codicon-account" aria-hidden="true"></span><h2 id="account-title">Workflow \u8D26\u53F7</h2><button id="close-account" type="button" class="icon-button" title="\u5173\u95ED\u8D26\u53F7" aria-label="\u5173\u95ED\u8D26\u53F7">${iconHtml("close")}</button></header>
|
|
2262
|
+
<div class="dialog-body account-body">
|
|
2263
|
+
<div id="account-status" role="status"></div>
|
|
2264
|
+
<form id="login-form">
|
|
2265
|
+
<label for="server-url">\u670D\u52A1\u5668</label><input id="server-url" type="url" required spellcheck="false" autocomplete="url">
|
|
2266
|
+
<label for="login-email">\u90AE\u7BB1</label><input id="login-email" type="email" required autocomplete="username">
|
|
2267
|
+
<label for="login-password">\u5BC6\u7801</label><div class="account-password"><input id="login-password" type="password" required autocomplete="current-password"><button id="show-password" type="button" class="icon-button" title="\u663E\u793A\u5BC6\u7801" aria-label="\u663E\u793A\u5BC6\u7801">${iconHtml("eye")}</button></div>
|
|
2268
|
+
<div class="account-actions"><button id="login-submit" type="submit" class="account-primary">${iconHtml("sign-in")}<span>\u767B\u5F55</span></button><button id="browser-login" type="button" class="account-secondary">${iconHtml("link-external")}<span>\u6D4F\u89C8\u5668\u767B\u5F55</span></button></div>
|
|
2269
|
+
</form>
|
|
2270
|
+
<section id="account-profile" hidden>
|
|
2271
|
+
<div class="account-identity"><span class="account-avatar"></span><div><h3 id="account-display-name"></h3><div id="account-email" class="account-muted"></div></div></div>
|
|
2272
|
+
<dl><dt>\u670D\u52A1\u5668</dt><dd id="account-server"></dd><dt>\u6709\u6548\u671F</dt><dd id="account-expiry"></dd></dl>
|
|
2273
|
+
<div class="account-actions"><button id="verify-login" type="button" class="account-secondary">${iconHtml("verified")}<span>\u9A8C\u8BC1\u767B\u5F55</span></button><button id="account-logout" type="button" class="account-secondary">${iconHtml("sign-out")}<span>\u9000\u51FA\u767B\u5F55</span></button></div>
|
|
2274
|
+
</section>
|
|
2275
|
+
<div id="account-error" role="alert" hidden></div>
|
|
2276
|
+
</div>`;
|
|
2277
|
+
document.body.append(this.dialog);
|
|
2278
|
+
this.element("#close-account").addEventListener("click", () => this.dialog.close());
|
|
2279
|
+
this.dialog.addEventListener("close", () => {
|
|
2280
|
+
this.element("#login-password").value = "";
|
|
2281
|
+
this.button.focus();
|
|
2282
|
+
});
|
|
2283
|
+
this.element("#login-form").addEventListener("submit", (event) => {
|
|
2284
|
+
event.preventDefault();
|
|
2285
|
+
if (this.pending || !this.element("#login-form").reportValidity()) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
const password = this.element("#login-password");
|
|
2289
|
+
const action2 = { type: "login", serverUrl: this.element("#server-url").value, email: this.element("#login-email").value, password: password.value };
|
|
2290
|
+
password.value = "";
|
|
2291
|
+
void this.perform(action2);
|
|
2292
|
+
});
|
|
2293
|
+
this.element("#browser-login").addEventListener("click", () => {
|
|
2294
|
+
const server = this.element("#server-url");
|
|
2295
|
+
if (!this.pending && server.reportValidity()) {
|
|
2296
|
+
void this.perform({ type: "login", serverUrl: server.value });
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
this.element("#show-password").addEventListener("click", (event) => {
|
|
2300
|
+
const password = this.element("#login-password");
|
|
2301
|
+
const visible = password.type === "password";
|
|
2302
|
+
password.type = visible ? "text" : "password";
|
|
2303
|
+
const button = event.currentTarget;
|
|
2304
|
+
button.innerHTML = iconHtml(visible ? "eye-closed" : "eye");
|
|
2305
|
+
button.title = button.ariaLabel = visible ? "\u9690\u85CF\u5BC6\u7801" : "\u663E\u793A\u5BC6\u7801";
|
|
2306
|
+
});
|
|
2307
|
+
this.element("#verify-login").addEventListener("click", () => {
|
|
2308
|
+
if (!this.pending) {
|
|
2309
|
+
void this.perform({ type: "verify" });
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
this.element("#account-logout").addEventListener("click", () => {
|
|
2313
|
+
if (!this.pending) {
|
|
2314
|
+
void this.perform({ type: "logout" });
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
request;
|
|
2319
|
+
button = document.createElement("button");
|
|
2320
|
+
dialog = document.createElement("dialog");
|
|
2321
|
+
state;
|
|
2322
|
+
pending = false;
|
|
2323
|
+
avatarKey = "";
|
|
2324
|
+
element(selector) {
|
|
2325
|
+
return this.dialog.querySelector(selector);
|
|
2326
|
+
}
|
|
2327
|
+
open() {
|
|
2328
|
+
this.render();
|
|
2329
|
+
if (!this.dialog.open) {
|
|
2330
|
+
this.dialog.showModal();
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
update(state2) {
|
|
2334
|
+
this.state = state2;
|
|
2335
|
+
this.button.hidden = false;
|
|
2336
|
+
this.pending = state2.status === "checking";
|
|
2337
|
+
this.render();
|
|
2338
|
+
}
|
|
2339
|
+
render() {
|
|
2340
|
+
const state2 = this.state;
|
|
2341
|
+
if (!state2) {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
const signedIn = !!state2.user && ["authenticated", "checking", "error"].includes(state2.status);
|
|
2345
|
+
const name = signedIn ? state2.user.displayName || state2.user.email || "Workflow" : this.pending ? "\u767B\u5F55\u4E2D..." : "\u767B\u5F55 Workflow";
|
|
2346
|
+
this.button.querySelector(".web-account-name").textContent = name;
|
|
2347
|
+
this.button.title = this.button.ariaLabel = state2.error || state2.user?.email || name;
|
|
2348
|
+
const avatarKey = `${state2.serverUrl}
|
|
2349
|
+
${state2.user?.avatarUrl ?? ""}`;
|
|
2350
|
+
if (avatarKey !== this.avatarKey) {
|
|
2351
|
+
this.avatarKey = avatarKey;
|
|
2352
|
+
for (const avatar of [this.button.querySelector(".web-avatar"), this.element(".account-avatar")]) {
|
|
2353
|
+
avatar.innerHTML = iconHtml("account");
|
|
2354
|
+
if (!state2.user?.avatarUrl) {
|
|
2355
|
+
continue;
|
|
2356
|
+
}
|
|
2357
|
+
let url;
|
|
2358
|
+
try {
|
|
2359
|
+
url = new URL(state2.user.avatarUrl, `${state2.serverUrl}/`);
|
|
2360
|
+
} catch {
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) {
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
const image = document.createElement("img");
|
|
2367
|
+
image.src = url.toString();
|
|
2368
|
+
image.alt = "";
|
|
2369
|
+
image.hidden = true;
|
|
2370
|
+
image.referrerPolicy = "no-referrer";
|
|
2371
|
+
image.addEventListener("load", () => {
|
|
2372
|
+
image.hidden = false;
|
|
2373
|
+
avatar.firstElementChild.hidden = true;
|
|
2374
|
+
});
|
|
2375
|
+
image.addEventListener("error", () => {
|
|
2376
|
+
image.hidden = true;
|
|
2377
|
+
avatar.firstElementChild.hidden = false;
|
|
2378
|
+
});
|
|
2379
|
+
avatar.append(image);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
this.element("#login-form").hidden = signedIn;
|
|
2383
|
+
this.element("#account-profile").hidden = !signedIn;
|
|
2384
|
+
const server = this.element("#server-url");
|
|
2385
|
+
if (!server.value || signedIn && document.activeElement !== server) {
|
|
2386
|
+
server.value = state2.serverUrl;
|
|
2387
|
+
}
|
|
2388
|
+
this.dialog.querySelectorAll("input, #login-submit, #browser-login, #verify-login, #account-logout").forEach((element2) => {
|
|
2389
|
+
element2.disabled = this.pending;
|
|
2390
|
+
});
|
|
2391
|
+
this.element("#login-submit > span:last-child").textContent = this.pending ? "\u767B\u5F55\u4E2D..." : "\u767B\u5F55";
|
|
2392
|
+
const status = this.element("#account-status");
|
|
2393
|
+
status.textContent = state2.status === "authenticated" ? "\u5DF2\u767B\u5F55\uFF0C\u8D26\u53F7\u9A8C\u8BC1\u901A\u8FC7" : this.pending ? "\u6B63\u5728\u9A8C\u8BC1\u8D26\u53F7..." : state2.status === "expired" ? "\u767B\u5F55\u5DF2\u5931\u6548" : state2.status === "error" && state2.user ? "\u8FDE\u63A5\u672A\u9A8C\u8BC1" : "\u672A\u767B\u5F55";
|
|
2394
|
+
status.classList.toggle("connected", state2.status === "authenticated");
|
|
2395
|
+
this.showError(state2.error);
|
|
2396
|
+
if (state2.user) {
|
|
2397
|
+
this.element("#account-display-name").textContent = state2.user.displayName || state2.user.email;
|
|
2398
|
+
this.element("#account-email").textContent = state2.user.email;
|
|
2399
|
+
this.element("#account-server").textContent = state2.serverUrl;
|
|
2400
|
+
this.element("#account-expiry").textContent = state2.expiresAt ? new Date(state2.expiresAt).toLocaleString("zh-CN") : "\u7531\u670D\u52A1\u5668\u7BA1\u7406";
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
showError(message) {
|
|
2404
|
+
const error = this.element("#account-error");
|
|
2405
|
+
error.textContent = message ?? "";
|
|
2406
|
+
error.hidden = !message;
|
|
2407
|
+
}
|
|
2408
|
+
async perform(action2) {
|
|
2409
|
+
this.pending = true;
|
|
2410
|
+
this.render();
|
|
2411
|
+
this.showError();
|
|
2412
|
+
try {
|
|
2413
|
+
await this.request(action2);
|
|
2414
|
+
} catch (error) {
|
|
2415
|
+
this.pending = false;
|
|
2416
|
+
this.render();
|
|
2417
|
+
this.showError(error.message);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
|
|
2422
|
+
// src/web/ui/connection.ts
|
|
2423
|
+
var ConnectionError = class extends Error {
|
|
2424
|
+
};
|
|
2425
|
+
var BrowserConnection = class {
|
|
2426
|
+
constructor(emit) {
|
|
2427
|
+
this.emit = emit;
|
|
2428
|
+
if (this.token) {
|
|
2429
|
+
sessionStorage.setItem("workflow-web-session", this.token);
|
|
2430
|
+
history.replaceState(null, "", `${location.pathname}${location.search}`);
|
|
2431
|
+
}
|
|
2432
|
+
queueMicrotask(() => {
|
|
2433
|
+
this.banner = document.createElement("div");
|
|
2434
|
+
this.banner.id = "connection-status";
|
|
2435
|
+
this.banner.className = "connection-banner";
|
|
2436
|
+
this.banner.setAttribute("role", "status");
|
|
2437
|
+
this.banner.setAttribute("aria-live", "polite");
|
|
2438
|
+
this.banner.innerHTML = `<span class="connection-icon" aria-hidden="true"></span><div class="connection-copy"><strong></strong><span></span></div><button type="button" class="connection-retry">${iconHtml("refresh")}<span>\u91CD\u65B0\u8FDE\u63A5</span></button>`;
|
|
2439
|
+
this.banner.querySelector("button").addEventListener("click", () => {
|
|
2440
|
+
void this.connect();
|
|
2441
|
+
});
|
|
2442
|
+
document.querySelector("main").prepend(this.banner);
|
|
2443
|
+
void this.connect();
|
|
2444
|
+
});
|
|
2445
|
+
addEventListener("offline", () => {
|
|
2446
|
+
this.source?.close();
|
|
2447
|
+
clearTimeout(this.retry);
|
|
2448
|
+
this.update("offline");
|
|
2449
|
+
});
|
|
2450
|
+
addEventListener("online", () => {
|
|
2451
|
+
void this.connect();
|
|
2452
|
+
});
|
|
2453
|
+
addEventListener("pagehide", () => {
|
|
2454
|
+
this.closed = true;
|
|
2455
|
+
clearTimeout(this.retry);
|
|
2456
|
+
this.source?.close();
|
|
2457
|
+
}, { once: true });
|
|
2458
|
+
}
|
|
2459
|
+
emit;
|
|
2460
|
+
clientId = crypto.randomUUID();
|
|
2461
|
+
source;
|
|
2462
|
+
banner;
|
|
2463
|
+
connecting;
|
|
2464
|
+
retry;
|
|
2465
|
+
status = "connecting";
|
|
2466
|
+
attempts = 0;
|
|
2467
|
+
closed = false;
|
|
2468
|
+
token = new URLSearchParams(location.hash.slice(1)).get("session") ?? sessionStorage.getItem("workflow-web-session");
|
|
2469
|
+
update(status) {
|
|
2470
|
+
this.status = status;
|
|
2471
|
+
this.emit({ type: "connection", status });
|
|
2472
|
+
if (!this.banner) {
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
this.banner.hidden = status === "connected";
|
|
2476
|
+
this.banner.dataset.status = status;
|
|
2477
|
+
const retrying = status === "connecting" || status === "reconnecting";
|
|
2478
|
+
this.banner.querySelector(".connection-icon").innerHTML = iconHtml(retrying ? "loading" : status === "expired" ? "warning" : "debug-disconnect");
|
|
2479
|
+
this.banner.querySelector("strong").textContent = status === "connecting" ? "\u6B63\u5728\u8FDE\u63A5\u9879\u76EE" : status === "expired" ? "\u9879\u76EE\u8FDE\u63A5\u5DF2\u5931\u6548" : "\u8FDE\u63A5\u5DF2\u4E2D\u65AD";
|
|
2480
|
+
this.banner.querySelector(".connection-copy > span").textContent = status === "reconnecting" ? "\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5..." : status === "offline" ? "\u7F51\u7EDC\u6062\u590D\u540E\u5C06\u81EA\u52A8\u91CD\u8FDE\u3002" : status === "expired" ? "\u8BF7\u4F7F\u7528\u9879\u76EE\u8FD0\u884C\u5730\u5740\u91CD\u65B0\u6253\u5F00\u3002" : "";
|
|
2481
|
+
this.banner.querySelector("button").disabled = status === "offline" || !!this.connecting;
|
|
2482
|
+
}
|
|
2483
|
+
interrupted() {
|
|
2484
|
+
this.source?.close();
|
|
2485
|
+
clearTimeout(this.retry);
|
|
2486
|
+
this.update(navigator.onLine ? "reconnecting" : "offline");
|
|
2487
|
+
if (!this.closed && navigator.onLine) {
|
|
2488
|
+
this.retry = setTimeout(() => {
|
|
2489
|
+
void this.connect();
|
|
2490
|
+
}, Math.min(2e3 * 2 ** this.attempts++, 3e4));
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
connect() {
|
|
2494
|
+
if (this.connecting) {
|
|
2495
|
+
return this.connecting;
|
|
2496
|
+
}
|
|
2497
|
+
clearTimeout(this.retry);
|
|
2498
|
+
if (this.closed) {
|
|
2499
|
+
return Promise.resolve();
|
|
2500
|
+
}
|
|
2501
|
+
if (!navigator.onLine) {
|
|
2502
|
+
this.update("offline");
|
|
2503
|
+
return Promise.resolve();
|
|
2504
|
+
}
|
|
2505
|
+
this.source?.close();
|
|
2506
|
+
this.update(this.attempts ? "reconnecting" : "connecting");
|
|
2507
|
+
this.connecting = (async () => {
|
|
2508
|
+
try {
|
|
2509
|
+
if (this.token) {
|
|
2510
|
+
const session2 = await fetch("/api/session", { method: "POST", headers: { Authorization: `Bearer ${this.token}` }, signal: AbortSignal.timeout(1e4) });
|
|
2511
|
+
if (session2.status === 401) {
|
|
2512
|
+
this.update("expired");
|
|
2513
|
+
return;
|
|
2514
|
+
}
|
|
2515
|
+
if (!session2.ok) {
|
|
2516
|
+
throw new Error("Cannot connect to the project.");
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
const session = await fetch("/api/session", { headers: this.headers(), signal: AbortSignal.timeout(1e4) });
|
|
2520
|
+
if (session.status === 401) {
|
|
2521
|
+
this.update("expired");
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
if (!session.ok) {
|
|
2525
|
+
throw new Error("Cannot connect to the project.");
|
|
2526
|
+
}
|
|
2527
|
+
const eventsUrl = new URL(this.fileUrl("/api/events"), location.href);
|
|
2528
|
+
eventsUrl.searchParams.set("clientId", this.clientId);
|
|
2529
|
+
const source = this.source = new EventSource(eventsUrl.href);
|
|
2530
|
+
source.onopen = () => {
|
|
2531
|
+
this.attempts = 0;
|
|
2532
|
+
this.update("connected");
|
|
2533
|
+
};
|
|
2534
|
+
source.onmessage = (event) => {
|
|
2535
|
+
this.emit(this.publicFiles(JSON.parse(event.data)));
|
|
2536
|
+
};
|
|
2537
|
+
source.onerror = () => {
|
|
2538
|
+
if (this.source === source && !this.closed) {
|
|
2539
|
+
this.interrupted();
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2542
|
+
} catch {
|
|
2543
|
+
if (!this.closed) {
|
|
2544
|
+
this.interrupted();
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
})().finally(() => {
|
|
2548
|
+
this.connecting = void 0;
|
|
2549
|
+
if (this.banner) {
|
|
2550
|
+
this.banner.querySelector("button").disabled = this.status === "offline";
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
return this.connecting;
|
|
2554
|
+
}
|
|
2555
|
+
async request(message) {
|
|
2556
|
+
await this.connecting;
|
|
2557
|
+
if (this.status !== "connected") {
|
|
2558
|
+
throw new ConnectionError("\u8FDE\u63A5\u5DF2\u4E2D\u65AD\u3002");
|
|
2559
|
+
}
|
|
2560
|
+
let response;
|
|
2561
|
+
try {
|
|
2562
|
+
const body = ["kanban-method-state", "kanban-method-reply"].includes(message.type) ? { ...message, clientId: this.clientId } : message;
|
|
2563
|
+
response = await fetch("/api/message", { method: "POST", headers: { ...this.headers(), "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
|
2564
|
+
} catch {
|
|
2565
|
+
this.interrupted();
|
|
2566
|
+
throw new ConnectionError("\u8FDE\u63A5\u5DF2\u4E2D\u65AD\u3002");
|
|
2567
|
+
}
|
|
2568
|
+
if (response.status === 401) {
|
|
2569
|
+
this.source?.close();
|
|
2570
|
+
this.update("expired");
|
|
2571
|
+
throw new ConnectionError("\u9879\u76EE\u8FDE\u63A5\u5DF2\u5931\u6548\u3002");
|
|
2572
|
+
}
|
|
2573
|
+
let reply;
|
|
2574
|
+
try {
|
|
2575
|
+
reply = await response.json();
|
|
2576
|
+
} catch {
|
|
2577
|
+
this.interrupted();
|
|
2578
|
+
throw new ConnectionError("\u8FDE\u63A5\u5DF2\u4E2D\u65AD\u3002");
|
|
2579
|
+
}
|
|
2580
|
+
if (!response.ok) {
|
|
2581
|
+
throw new Error(reply.message || "Request failed.");
|
|
2582
|
+
}
|
|
2583
|
+
return (reply.messages ?? []).map((message2) => this.publicFiles(message2));
|
|
2584
|
+
}
|
|
2585
|
+
headers() {
|
|
2586
|
+
return this.token ? { Authorization: `Bearer ${this.token}` } : {};
|
|
2587
|
+
}
|
|
2588
|
+
fileUrl(path) {
|
|
2589
|
+
return this.token ? `${path}?session=${encodeURIComponent(this.token)}` : path;
|
|
2590
|
+
}
|
|
2591
|
+
publicFiles(value) {
|
|
2592
|
+
if (Array.isArray(value)) {
|
|
2593
|
+
return value.map((entry) => this.publicFiles(entry));
|
|
2594
|
+
}
|
|
2595
|
+
if (!value || typeof value !== "object") {
|
|
2596
|
+
return value;
|
|
2597
|
+
}
|
|
2598
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
2599
|
+
key,
|
|
2600
|
+
key === "previewUrl" && typeof entry === "string" && entry.startsWith("/api/file/") ? this.fileUrl(entry) : this.publicFiles(entry)
|
|
2601
|
+
]));
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
|
|
2605
|
+
// src/web/ui/action-dialog.ts
|
|
2606
|
+
function requestAction(options) {
|
|
2607
|
+
return new Promise((resolve) => {
|
|
2608
|
+
const dialog = document.createElement("dialog");
|
|
2609
|
+
dialog.className = "conversation-dialog action-dialog";
|
|
2610
|
+
const title = document.createElement("h2");
|
|
2611
|
+
title.id = `action-${crypto.randomUUID()}`;
|
|
2612
|
+
title.textContent = options.title;
|
|
2613
|
+
dialog.setAttribute("aria-labelledby", title.id);
|
|
2614
|
+
const header = document.createElement("header");
|
|
2615
|
+
header.append(title, iconButton("close", "\u5173\u95ED", () => dialog.close()));
|
|
2616
|
+
const form = document.createElement("form");
|
|
2617
|
+
form.className = "dialog-body";
|
|
2618
|
+
let input, result;
|
|
2619
|
+
if (options.label) {
|
|
2620
|
+
const label = document.createElement("label");
|
|
2621
|
+
label.textContent = options.label;
|
|
2622
|
+
input = document.createElement("input");
|
|
2623
|
+
input.type = "text";
|
|
2624
|
+
input.required = true;
|
|
2625
|
+
input.autofocus = true;
|
|
2626
|
+
input.value = options.value ?? "";
|
|
2627
|
+
label.append(input);
|
|
2628
|
+
form.append(label);
|
|
2629
|
+
}
|
|
2630
|
+
const actions = document.createElement("div");
|
|
2631
|
+
actions.className = "prompt-navigation";
|
|
2632
|
+
const cancel = document.createElement("button");
|
|
2633
|
+
cancel.type = "button";
|
|
2634
|
+
cancel.className = "prompt-button";
|
|
2635
|
+
cancel.textContent = "\u53D6\u6D88";
|
|
2636
|
+
cancel.onclick = () => dialog.close();
|
|
2637
|
+
const confirm = document.createElement("button");
|
|
2638
|
+
confirm.type = "submit";
|
|
2639
|
+
confirm.className = "prompt-button";
|
|
2640
|
+
confirm.textContent = options.confirm;
|
|
2641
|
+
if (options.danger) {
|
|
2642
|
+
confirm.classList.add("danger");
|
|
2643
|
+
}
|
|
2644
|
+
actions.append(cancel, confirm);
|
|
2645
|
+
form.append(actions);
|
|
2646
|
+
dialog.append(header, form);
|
|
2647
|
+
form.onsubmit = (event) => {
|
|
2648
|
+
event.preventDefault();
|
|
2649
|
+
if (input && !input.value.trim()) {
|
|
2650
|
+
input.focus();
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
result = input?.value.trim() ?? "";
|
|
2654
|
+
dialog.close();
|
|
2655
|
+
};
|
|
2656
|
+
dialog.addEventListener("close", () => {
|
|
2657
|
+
dialog.remove();
|
|
2658
|
+
resolve(result);
|
|
2659
|
+
}, { once: true });
|
|
2660
|
+
document.body.append(dialog);
|
|
2661
|
+
dialog.showModal();
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
// src/web/ui/host.ts
|
|
2666
|
+
function acquireWorkflowHost() {
|
|
2667
|
+
const embedded = globalThis.acquireVsCodeApi;
|
|
2668
|
+
if (embedded) {
|
|
2669
|
+
return embedded();
|
|
2670
|
+
}
|
|
2671
|
+
if (document.documentElement.dataset.theme === "auto") {
|
|
2672
|
+
const dark = matchMedia("(prefers-color-scheme: dark)");
|
|
2673
|
+
const applyTheme = () => {
|
|
2674
|
+
document.documentElement.dataset.theme = dark.matches ? "dark" : "light";
|
|
2675
|
+
};
|
|
2676
|
+
applyTheme();
|
|
2677
|
+
dark.addEventListener("change", applyTheme);
|
|
2678
|
+
}
|
|
2679
|
+
const storageKey = `workflow-web:${document.querySelector("meta[name=workflow-project]")?.content ?? location.pathname}`;
|
|
2680
|
+
const emit = (message) => window.dispatchEvent(new MessageEvent("message", { data: message }));
|
|
2681
|
+
const connection = new BrowserConnection((message) => {
|
|
2682
|
+
if (message.type === "state" && message.account) {
|
|
2683
|
+
accountPanel.update(message.account);
|
|
2684
|
+
}
|
|
2685
|
+
emit(message);
|
|
2686
|
+
});
|
|
2687
|
+
const request2 = async (message) => {
|
|
2688
|
+
for (const entry of await connection.request(message)) {
|
|
2689
|
+
handleReply(entry);
|
|
2690
|
+
}
|
|
2691
|
+
};
|
|
2692
|
+
addEventListener("message", (event) => {
|
|
2693
|
+
if (window.parent === window || event.source !== window.parent || event.data?.type !== "workflow-host") {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2696
|
+
if (event.data.theme === "dark" || event.data.theme === "light") {
|
|
2697
|
+
document.documentElement.dataset.theme = event.data.theme;
|
|
2698
|
+
}
|
|
2699
|
+
if (event.data.command === "new" || event.data.command === "history") {
|
|
2700
|
+
emit({ type: "assistant-command", command: event.data.command });
|
|
2701
|
+
}
|
|
2702
|
+
});
|
|
2703
|
+
const handleReply = (reply) => {
|
|
2704
|
+
if (reply.type === "download") {
|
|
2705
|
+
const url = URL.createObjectURL(new Blob([reply.content], { type: reply.mimeType ?? "application/json" }));
|
|
2706
|
+
const link = document.createElement("a");
|
|
2707
|
+
link.href = url;
|
|
2708
|
+
link.download = reply.name;
|
|
2709
|
+
link.click();
|
|
2710
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
2711
|
+
} else if (reply.type === "preview") {
|
|
2712
|
+
const dialog = document.createElement("dialog");
|
|
2713
|
+
dialog.className = "conversation-dialog";
|
|
2714
|
+
const header = document.createElement("header");
|
|
2715
|
+
const title = document.createElement("h2");
|
|
2716
|
+
title.textContent = reply.title;
|
|
2717
|
+
const close = document.createElement("button");
|
|
2718
|
+
close.className = "icon-button";
|
|
2719
|
+
close.title = "\u5173\u95ED";
|
|
2720
|
+
close.setAttribute("aria-label", close.title);
|
|
2721
|
+
close.innerHTML = '<span class="codicon codicon-close"></span>';
|
|
2722
|
+
close.onclick = () => dialog.close();
|
|
2723
|
+
header.append(title, close);
|
|
2724
|
+
const body = document.createElement("pre");
|
|
2725
|
+
body.className = "dialog-body web-preview";
|
|
2726
|
+
body.textContent = typeof reply.content === "string" ? reply.content : JSON.stringify(reply.content, null, 2);
|
|
2727
|
+
dialog.append(header, body);
|
|
2728
|
+
document.body.append(dialog);
|
|
2729
|
+
dialog.addEventListener("close", () => dialog.remove());
|
|
2730
|
+
dialog.showModal();
|
|
2731
|
+
} else {
|
|
2732
|
+
emit(reply);
|
|
2733
|
+
}
|
|
2734
|
+
};
|
|
2735
|
+
const chooseFiles = (message) => {
|
|
2736
|
+
const picker = document.createElement("input");
|
|
2737
|
+
picker.type = "file";
|
|
2738
|
+
picker.multiple = true;
|
|
2739
|
+
if (Array.isArray(message.accept)) {
|
|
2740
|
+
picker.accept = message.accept.join(",");
|
|
2741
|
+
}
|
|
2742
|
+
picker.addEventListener("change", async () => {
|
|
2743
|
+
try {
|
|
2744
|
+
const files = await Promise.all(Array.from(picker.files ?? []).map((file) => new Promise((resolve, reject) => {
|
|
2745
|
+
if (file.size > 50 * 1024 * 1024) {
|
|
2746
|
+
reject(new Error("Attachment exceeds 50 MiB."));
|
|
2747
|
+
return;
|
|
2748
|
+
}
|
|
2749
|
+
const reader = new FileReader();
|
|
2750
|
+
reader.onload = () => resolve({ name: file.name, mimeType: file.type, data: String(reader.result).split(",")[1] });
|
|
2751
|
+
reader.onerror = () => reject(reader.error);
|
|
2752
|
+
reader.readAsDataURL(file);
|
|
2753
|
+
})));
|
|
2754
|
+
await request2({ ...message, type: "upload", files });
|
|
2755
|
+
} catch (error) {
|
|
2756
|
+
emit({ type: "error", requestType: "attach", sessionId: message.sessionId, message: String(error.message) });
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
picker.addEventListener("cancel", () => emit({ type: "attachment-cancelled", sessionId: message.sessionId }));
|
|
2760
|
+
picker.click();
|
|
2761
|
+
};
|
|
2762
|
+
let accountPanel;
|
|
2763
|
+
queueMicrotask(() => {
|
|
2764
|
+
accountPanel = new AccountPanel(document.querySelector("#project-menu"), request2);
|
|
2765
|
+
});
|
|
2766
|
+
return {
|
|
2767
|
+
postMessage: async (message) => {
|
|
2768
|
+
if (message.type === "ready") {
|
|
2769
|
+
return;
|
|
2770
|
+
}
|
|
2771
|
+
if (message.type === "copy") {
|
|
2772
|
+
void navigator.clipboard.writeText(message.text).catch((error) => emit({ type: "error", message: error.message }));
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
if (message.type === "attach") {
|
|
2776
|
+
chooseFiles(message);
|
|
2777
|
+
return;
|
|
2778
|
+
}
|
|
2779
|
+
if (message.type === "session-action" && message.action === "rename") {
|
|
2780
|
+
const title = await requestAction({ title: "\u91CD\u547D\u540D\u5BF9\u8BDD", label: "\u5BF9\u8BDD\u540D\u79F0", value: message.currentTitle, confirm: "\u4FDD\u5B58" });
|
|
2781
|
+
if (title === void 0) {
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
message = { ...message, title };
|
|
2785
|
+
}
|
|
2786
|
+
if (message.type === "session-action" && message.action === "delete" && await requestAction({ title: "\u5220\u9664\u8FD9\u4E2A\u5BF9\u8BDD\uFF1F", confirm: "\u5220\u9664", danger: true }) === void 0) {
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
if (message.type === "open-file") {
|
|
2790
|
+
window.open(connection.fileUrl(`/api/file/${encodeURIComponent(message.id)}`), "_blank", "noopener");
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
if (message.type === "login") {
|
|
2794
|
+
accountPanel.open();
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
void request2(message).catch((error) => emit({ type: "error", silent: error instanceof ConnectionError, requestType: message.type, sessionId: message.sessionId, messageId: message.messageId, requestId: message.requestId, message: error.message }));
|
|
2798
|
+
},
|
|
2799
|
+
getState: () => {
|
|
2800
|
+
try {
|
|
2801
|
+
return JSON.parse(localStorage.getItem(storageKey) ?? "null");
|
|
2802
|
+
} catch {
|
|
2803
|
+
return void 0;
|
|
2804
|
+
}
|
|
2805
|
+
},
|
|
2806
|
+
setState: (state2) => {
|
|
2807
|
+
try {
|
|
2808
|
+
localStorage.setItem(storageKey, JSON.stringify(state2));
|
|
2809
|
+
} catch {
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
// src/web/workflow-types.ts
|
|
2816
|
+
function workflowParamValue(field, value = field.defaultValue ?? "") {
|
|
2817
|
+
if (field.type === "file" || field.control === "audio" || !(field.multiple || field.control === "checkboxes") || Array.isArray(value)) {
|
|
2818
|
+
return value;
|
|
2819
|
+
}
|
|
2820
|
+
if (!value.trim()) {
|
|
2821
|
+
return [];
|
|
2822
|
+
}
|
|
2823
|
+
try {
|
|
2824
|
+
const parsed = JSON.parse(value);
|
|
2825
|
+
if (Array.isArray(parsed)) {
|
|
2826
|
+
return parsed.filter((entry) => ["string", "number", "boolean"].includes(typeof entry)).map(String);
|
|
2827
|
+
}
|
|
2828
|
+
} catch {
|
|
2829
|
+
}
|
|
2830
|
+
return [value];
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
// src/web/ui/parameter-actions.ts
|
|
2834
|
+
var icon = (name) => {
|
|
2835
|
+
const element2 = document.createElement("span");
|
|
2836
|
+
element2.className = `codicon codicon-${name}`;
|
|
2837
|
+
element2.ariaHidden = "true";
|
|
2838
|
+
return element2;
|
|
2839
|
+
};
|
|
2840
|
+
function parameterSelectionLabel(field, value, state2) {
|
|
2841
|
+
const options = state2?.resolvedOptions ?? field.options ?? [];
|
|
2842
|
+
if (!options.length) {
|
|
2843
|
+
return "\u6682\u65E0\u9009\u9879";
|
|
2844
|
+
}
|
|
2845
|
+
if (Array.isArray(value)) {
|
|
2846
|
+
if (value.length > 1) {
|
|
2847
|
+
return `\u5DF2\u9009 ${value.length} \u9879`;
|
|
2848
|
+
}
|
|
2849
|
+
value = value[0];
|
|
2850
|
+
}
|
|
2851
|
+
return options.find((option) => option.value === value)?.label || value || "\u672A\u9009\u62E9";
|
|
2852
|
+
}
|
|
2853
|
+
var ParameterActions = class {
|
|
2854
|
+
constructor(container, options) {
|
|
2855
|
+
this.container = container;
|
|
2856
|
+
this.options = options;
|
|
2857
|
+
this.popup = document.createElement("div");
|
|
2858
|
+
this.popup.id = "parameter-popover";
|
|
2859
|
+
this.popup.className = "parameter-popover";
|
|
2860
|
+
this.popup.tabIndex = -1;
|
|
2861
|
+
this.popup.hidden = true;
|
|
2862
|
+
document.body.append(this.popup);
|
|
2863
|
+
document.addEventListener("pointerdown", (event) => {
|
|
2864
|
+
if (this.active && !this.popup.contains(event.target) && !this.active.button.contains(event.target)) {
|
|
2865
|
+
this.close();
|
|
2866
|
+
}
|
|
2867
|
+
});
|
|
2868
|
+
document.addEventListener("focusin", (event) => {
|
|
2869
|
+
if (this.active && !this.popup.contains(event.target) && !this.active.button.contains(event.target)) {
|
|
2870
|
+
this.close();
|
|
2871
|
+
}
|
|
2872
|
+
});
|
|
2873
|
+
this.popup.addEventListener("keydown", (event) => {
|
|
2874
|
+
if (event.key === "Escape") {
|
|
2875
|
+
event.preventDefault();
|
|
2876
|
+
event.stopPropagation();
|
|
2877
|
+
this.close(true);
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key) || this.active?.action.kind !== "quick") {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
const buttons = Array.from(this.popup.querySelectorAll("[role=menuitem]:not(:disabled), [role=option]:not(:disabled)")).filter((button) => button.getClientRects().length > 0);
|
|
2884
|
+
const index = buttons.indexOf(document.activeElement);
|
|
2885
|
+
if (!buttons.length) {
|
|
2886
|
+
return;
|
|
2887
|
+
}
|
|
2888
|
+
event.preventDefault();
|
|
2889
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length;
|
|
2890
|
+
buttons[next].focus();
|
|
2891
|
+
});
|
|
2892
|
+
window.addEventListener("resize", () => this.position());
|
|
2893
|
+
window.addEventListener("scroll", () => this.position(), true);
|
|
2894
|
+
new ResizeObserver(() => this.position()).observe(document.querySelector("main"));
|
|
2895
|
+
}
|
|
2896
|
+
container;
|
|
2897
|
+
options;
|
|
2898
|
+
parameters = { fields: [] };
|
|
2899
|
+
views = [];
|
|
2900
|
+
popup;
|
|
2901
|
+
active;
|
|
2902
|
+
activeParam;
|
|
2903
|
+
render(parameters) {
|
|
2904
|
+
this.close();
|
|
2905
|
+
this.parameters = parameters;
|
|
2906
|
+
this.views.length = 0;
|
|
2907
|
+
this.container.replaceChildren();
|
|
2908
|
+
for (const action2 of parameters.paramLayout?.actions ?? []) {
|
|
2909
|
+
const button = document.createElement("button");
|
|
2910
|
+
button.type = "button";
|
|
2911
|
+
button.className = "param-action";
|
|
2912
|
+
button.dataset.paramAction = action2.kind;
|
|
2913
|
+
button.dataset.actionId = action2.kind === "mode" ? action2.name : action2.id;
|
|
2914
|
+
const label = document.createElement("span");
|
|
2915
|
+
label.className = "param-action-label";
|
|
2916
|
+
const view = { action: action2, button, label };
|
|
2917
|
+
if (action2.kind === "auxiliary") {
|
|
2918
|
+
button.append(icon("settings"));
|
|
2919
|
+
view.count = document.createElement("small");
|
|
2920
|
+
}
|
|
2921
|
+
button.append(label);
|
|
2922
|
+
if (view.count) {
|
|
2923
|
+
button.append(view.count);
|
|
2924
|
+
}
|
|
2925
|
+
if (action2.kind !== "mode") {
|
|
2926
|
+
button.append(icon("chevron-up"));
|
|
2927
|
+
button.setAttribute("aria-haspopup", action2.kind === "quick" ? "menu" : "dialog");
|
|
2928
|
+
button.setAttribute("aria-controls", this.popup.id);
|
|
2929
|
+
button.setAttribute("aria-expanded", "false");
|
|
2930
|
+
}
|
|
2931
|
+
button.addEventListener("click", () => {
|
|
2932
|
+
if (action2.kind === "mode") {
|
|
2933
|
+
const field = this.field(action2.name);
|
|
2934
|
+
if (!field) {
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
const choices = this.visibleOptions(field).filter((option) => !this.options.current().states[field.name]?.options?.[option.value]?.disabled);
|
|
2938
|
+
const index = Math.max(0, choices.findIndex((option) => option.value === this.options.current().values[field.name]));
|
|
2939
|
+
if (choices.length > 1) {
|
|
2940
|
+
this.options.onChange(field.name, choices[(index + 1) % choices.length].value);
|
|
2941
|
+
}
|
|
2942
|
+
} else if (this.active === view) {
|
|
2943
|
+
this.close(true);
|
|
2944
|
+
} else {
|
|
2945
|
+
this.open(view);
|
|
2946
|
+
}
|
|
2947
|
+
});
|
|
2948
|
+
this.container.append(button);
|
|
2949
|
+
this.views.push(view);
|
|
2950
|
+
}
|
|
2951
|
+
this.update();
|
|
2952
|
+
}
|
|
2953
|
+
field(name) {
|
|
2954
|
+
return this.parameters.fields.find((field) => field.name === name);
|
|
2955
|
+
}
|
|
2956
|
+
visibleOptions(field) {
|
|
2957
|
+
const state2 = this.options.current().states[field.name];
|
|
2958
|
+
return (state2?.resolvedOptions ?? field.options ?? []).filter((option) => state2?.options?.[option.value]?.visible !== false);
|
|
2959
|
+
}
|
|
2960
|
+
groupFields(action2) {
|
|
2961
|
+
return action2.params.map((name) => this.field(name)).filter((field) => !!field && this.options.current().states[field.name]?.visible !== false);
|
|
2962
|
+
}
|
|
2963
|
+
update() {
|
|
2964
|
+
const { values: values2, states, disabled, loading } = this.options.current();
|
|
2965
|
+
for (const view of this.views) {
|
|
2966
|
+
const { action: action2 } = view;
|
|
2967
|
+
if (action2.kind === "mode") {
|
|
2968
|
+
const field = this.field(action2.name);
|
|
2969
|
+
const choices = field ? this.visibleOptions(field) : [];
|
|
2970
|
+
view.button.hidden = !field || states[action2.name]?.visible === false || choices.length < 2;
|
|
2971
|
+
view.button.disabled = disabled || loading || states[action2.name]?.disabled === true;
|
|
2972
|
+
view.label.textContent = field ? `${field.label || field.name}: ${parameterSelectionLabel(field, values2[field.name], states[field.name])}` : "";
|
|
2973
|
+
} else {
|
|
2974
|
+
const fields2 = this.groupFields(action2);
|
|
2975
|
+
view.button.hidden = fields2.length === 0;
|
|
2976
|
+
view.button.disabled = disabled || (action2.kind === "auxiliary" ? loading : fields2.every((field) => states[field.name]?.disabled === true || this.visibleOptions(field).length === 0));
|
|
2977
|
+
const summaries = action2.summary?.map((name) => fields2.find((field) => field.name === name)).filter((field) => !!field && !!values2[field.name]?.length).map((field) => parameterSelectionLabel(field, values2[field.name], states[field.name])) ?? [];
|
|
2978
|
+
view.label.textContent = action2.kind === "quick" && summaries.length ? `${action2.label}: ${summaries.join(" \xB7 ")}` : action2.label;
|
|
2979
|
+
if (view.count) {
|
|
2980
|
+
view.count.textContent = String(fields2.length);
|
|
2981
|
+
}
|
|
2982
|
+
view.button.setAttribute("aria-busy", String(loading));
|
|
2983
|
+
}
|
|
2984
|
+
view.button.title = view.label.textContent || "";
|
|
2985
|
+
view.button.ariaLabel = view.label.textContent || "";
|
|
2986
|
+
}
|
|
2987
|
+
if (this.active) {
|
|
2988
|
+
if (disabled || this.active.button.hidden) {
|
|
2989
|
+
this.close();
|
|
2990
|
+
} else if (this.active.action.kind === "quick") {
|
|
2991
|
+
this.renderQuick();
|
|
2992
|
+
} else {
|
|
2993
|
+
const body = this.popup.querySelector(".parameter-popover-fields");
|
|
2994
|
+
for (const field of this.groupFields(this.active.action)) {
|
|
2995
|
+
const root = this.options.fieldRoot(field.name);
|
|
2996
|
+
if (root.parentElement !== body) {
|
|
2997
|
+
body.append(root);
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
this.position();
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
openForField(name) {
|
|
3005
|
+
const view = this.views.find((view2) => view2.action.kind !== "mode" && view2.action.params.includes(name));
|
|
3006
|
+
if (!view || view.action.kind === "mode") {
|
|
3007
|
+
return false;
|
|
3008
|
+
}
|
|
3009
|
+
this.open(view, name);
|
|
3010
|
+
return true;
|
|
3011
|
+
}
|
|
3012
|
+
open(view, name) {
|
|
3013
|
+
this.close();
|
|
3014
|
+
this.active = view;
|
|
3015
|
+
this.activeParam = view.action.kind === "quick" ? name : void 0;
|
|
3016
|
+
view.button.setAttribute("aria-expanded", "true");
|
|
3017
|
+
this.popup.hidden = false;
|
|
3018
|
+
this.popup.dataset.kind = view.action.kind;
|
|
3019
|
+
this.popup.ariaLabel = view.action.label;
|
|
3020
|
+
this.popup.setAttribute("role", view.action.kind === "quick" ? "menu" : "dialog");
|
|
3021
|
+
if (view.action.kind === "quick") {
|
|
3022
|
+
this.renderQuick();
|
|
3023
|
+
} else {
|
|
3024
|
+
const header = document.createElement("div");
|
|
3025
|
+
header.className = "parameter-popover-heading";
|
|
3026
|
+
const title = document.createElement("strong");
|
|
3027
|
+
title.textContent = view.action.label;
|
|
3028
|
+
const close = document.createElement("button");
|
|
3029
|
+
close.type = "button";
|
|
3030
|
+
close.className = "icon-button";
|
|
3031
|
+
close.title = close.ariaLabel = "\u5173\u95ED\u53C2\u6570";
|
|
3032
|
+
close.append(icon("close"));
|
|
3033
|
+
close.addEventListener("click", () => this.close(true));
|
|
3034
|
+
header.append(title, close);
|
|
3035
|
+
const body = document.createElement("div");
|
|
3036
|
+
body.className = "parameter-popover-fields";
|
|
3037
|
+
for (const field of this.groupFields(view.action)) {
|
|
3038
|
+
body.append(this.options.fieldRoot(field.name));
|
|
3039
|
+
}
|
|
3040
|
+
this.popup.replaceChildren(header, body);
|
|
3041
|
+
}
|
|
3042
|
+
this.position();
|
|
3043
|
+
if (name && view.action.kind === "auxiliary") {
|
|
3044
|
+
this.options.fieldRoot(name).querySelector("input, select, textarea")?.focus();
|
|
3045
|
+
} else {
|
|
3046
|
+
this.popup.querySelector("[role=option][aria-selected=true], [role=menuitem]:not(:disabled), button:not(:disabled)")?.focus();
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
close(restoreFocus = false) {
|
|
3050
|
+
const button = this.active?.button;
|
|
3051
|
+
button?.setAttribute("aria-expanded", "false");
|
|
3052
|
+
this.active = void 0;
|
|
3053
|
+
this.activeParam = void 0;
|
|
3054
|
+
this.popup.hidden = true;
|
|
3055
|
+
if (restoreFocus) {
|
|
3056
|
+
button?.focus();
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
renderQuick() {
|
|
3060
|
+
if (!this.active) {
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
const action2 = this.active.action;
|
|
3064
|
+
const fields2 = this.groupFields(action2);
|
|
3065
|
+
const { values: values2, states, disabled, loading } = this.options.current();
|
|
3066
|
+
const focused = this.popup.contains(document.activeElement) ? document.activeElement.dataset.focusKey : void 0;
|
|
3067
|
+
const previousScroll = this.popup.querySelector(".quick-options-list")?.scrollTop ?? 0;
|
|
3068
|
+
const menu2 = document.createElement("div");
|
|
3069
|
+
menu2.className = "quick-panel quick-menu";
|
|
3070
|
+
const title = document.createElement("div");
|
|
3071
|
+
title.className = "parameter-popover-heading";
|
|
3072
|
+
title.textContent = action2.label;
|
|
3073
|
+
menu2.append(title);
|
|
3074
|
+
for (const field2 of fields2) {
|
|
3075
|
+
const row = document.createElement("button");
|
|
3076
|
+
row.type = "button";
|
|
3077
|
+
row.className = "quick-param-row";
|
|
3078
|
+
row.setAttribute("role", "menuitem");
|
|
3079
|
+
row.setAttribute("aria-haspopup", "listbox");
|
|
3080
|
+
row.dataset.param = field2.name;
|
|
3081
|
+
row.dataset.focusKey = `field:${field2.name}`;
|
|
3082
|
+
row.disabled = disabled || loading || states[field2.name]?.disabled === true || this.visibleOptions(field2).length === 0;
|
|
3083
|
+
row.setAttribute("aria-expanded", String(this.activeParam === field2.name));
|
|
3084
|
+
const label = document.createElement("span");
|
|
3085
|
+
label.textContent = field2.label || field2.name;
|
|
3086
|
+
const value = document.createElement("span");
|
|
3087
|
+
value.className = "quick-param-value";
|
|
3088
|
+
value.textContent = parameterSelectionLabel(field2, values2[field2.name], states[field2.name]);
|
|
3089
|
+
row.append(label, value, icon("chevron-right"));
|
|
3090
|
+
row.addEventListener("click", () => {
|
|
3091
|
+
this.activeParam = field2.name;
|
|
3092
|
+
this.renderQuick();
|
|
3093
|
+
this.position();
|
|
3094
|
+
this.popup.querySelector("[role=option][aria-selected=true], [role=option]:not(:disabled)")?.focus();
|
|
3095
|
+
});
|
|
3096
|
+
menu2.append(row);
|
|
3097
|
+
}
|
|
3098
|
+
const reset = document.createElement("button");
|
|
3099
|
+
reset.type = "button";
|
|
3100
|
+
reset.className = "quick-reset";
|
|
3101
|
+
reset.setAttribute("role", "menuitem");
|
|
3102
|
+
reset.dataset.focusKey = "reset";
|
|
3103
|
+
reset.disabled = disabled || loading;
|
|
3104
|
+
reset.textContent = "\u91CD\u7F6E\u9009\u9879";
|
|
3105
|
+
reset.append(icon("discard"));
|
|
3106
|
+
reset.addEventListener("click", () => {
|
|
3107
|
+
this.activeParam = void 0;
|
|
3108
|
+
this.options.onReset(fields2.map((field2) => field2.name));
|
|
3109
|
+
});
|
|
3110
|
+
menu2.append(reset);
|
|
3111
|
+
const field = fields2.find((field2) => field2.name === this.activeParam && states[field2.name]?.disabled !== true);
|
|
3112
|
+
this.activeParam = field?.name;
|
|
3113
|
+
const panels = [menu2];
|
|
3114
|
+
if (field) {
|
|
3115
|
+
const detail = document.createElement("div");
|
|
3116
|
+
detail.className = "quick-panel quick-detail";
|
|
3117
|
+
const back = document.createElement("button");
|
|
3118
|
+
back.type = "button";
|
|
3119
|
+
back.className = "quick-detail-heading";
|
|
3120
|
+
back.title = back.ariaLabel = `\u8FD4\u56DE ${action2.label}`;
|
|
3121
|
+
back.append(icon("arrow-left"), document.createTextNode(field.label || field.name));
|
|
3122
|
+
back.addEventListener("click", () => {
|
|
3123
|
+
this.activeParam = void 0;
|
|
3124
|
+
this.renderQuick();
|
|
3125
|
+
this.position();
|
|
3126
|
+
this.popup.querySelectorAll("[data-param]").forEach((button) => {
|
|
3127
|
+
if (button.dataset.param === field.name) {
|
|
3128
|
+
button.focus();
|
|
3129
|
+
}
|
|
3130
|
+
});
|
|
3131
|
+
});
|
|
3132
|
+
const list2 = document.createElement("div");
|
|
3133
|
+
list2.className = "quick-options-list";
|
|
3134
|
+
list2.setAttribute("role", "listbox");
|
|
3135
|
+
list2.ariaLabel = field.label || field.name;
|
|
3136
|
+
const multiple = field.multiple || field.control === "checkboxes";
|
|
3137
|
+
if (multiple) {
|
|
3138
|
+
list2.setAttribute("aria-multiselectable", "true");
|
|
3139
|
+
}
|
|
3140
|
+
for (const option of this.visibleOptions(field)) {
|
|
3141
|
+
const selected = multiple ? Array.isArray(values2[field.name]) && values2[field.name].includes(option.value) : values2[field.name] === option.value;
|
|
3142
|
+
const button = document.createElement("button");
|
|
3143
|
+
button.type = "button";
|
|
3144
|
+
button.className = "quick-option-row";
|
|
3145
|
+
button.setAttribute("role", "option");
|
|
3146
|
+
button.setAttribute("aria-selected", String(selected));
|
|
3147
|
+
button.dataset.focusKey = `option:${option.value}`;
|
|
3148
|
+
button.disabled = disabled || loading || states[field.name]?.options?.[option.value]?.disabled === true;
|
|
3149
|
+
const check = document.createElement("span");
|
|
3150
|
+
check.className = "quick-option-check";
|
|
3151
|
+
if (selected) {
|
|
3152
|
+
check.append(icon("check"));
|
|
3153
|
+
}
|
|
3154
|
+
const copy = document.createElement("span");
|
|
3155
|
+
copy.className = "quick-option-copy";
|
|
3156
|
+
const label = document.createElement("span");
|
|
3157
|
+
label.textContent = option.label || option.value;
|
|
3158
|
+
copy.append(label);
|
|
3159
|
+
if (option.description) {
|
|
3160
|
+
const description = document.createElement("small");
|
|
3161
|
+
description.textContent = option.description;
|
|
3162
|
+
copy.append(description);
|
|
3163
|
+
}
|
|
3164
|
+
button.append(check, copy);
|
|
3165
|
+
button.addEventListener("click", () => {
|
|
3166
|
+
const current = this.options.current().values[field.name];
|
|
3167
|
+
const next = multiple ? selected ? (Array.isArray(current) ? current : []).filter((value) => value !== option.value) : [...Array.isArray(current) ? current : [], option.value] : option.value;
|
|
3168
|
+
if (!multiple) {
|
|
3169
|
+
this.activeParam = void 0;
|
|
3170
|
+
}
|
|
3171
|
+
this.options.onChange(field.name, next);
|
|
3172
|
+
if (!multiple) {
|
|
3173
|
+
this.popup.querySelectorAll("[data-param]").forEach((row) => {
|
|
3174
|
+
if (row.dataset.param === field.name) {
|
|
3175
|
+
row.focus();
|
|
3176
|
+
}
|
|
3177
|
+
});
|
|
3178
|
+
}
|
|
3179
|
+
});
|
|
3180
|
+
list2.append(button);
|
|
3181
|
+
}
|
|
3182
|
+
detail.append(back, list2);
|
|
3183
|
+
panels.push(detail);
|
|
3184
|
+
}
|
|
3185
|
+
this.popup.replaceChildren(...panels);
|
|
3186
|
+
const list = this.popup.querySelector(".quick-options-list");
|
|
3187
|
+
if (list) {
|
|
3188
|
+
list.scrollTop = previousScroll;
|
|
3189
|
+
}
|
|
3190
|
+
if (focused) {
|
|
3191
|
+
this.popup.querySelectorAll("[data-focus-key]").forEach((element2) => {
|
|
3192
|
+
if (element2.dataset.focusKey === focused) {
|
|
3193
|
+
element2.focus();
|
|
3194
|
+
}
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
position() {
|
|
3199
|
+
if (!this.active) {
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
const anchor = this.active.button.getBoundingClientRect();
|
|
3203
|
+
const boundary = document.querySelector("main").getBoundingClientRect();
|
|
3204
|
+
const leftEdge = Math.max(12, boundary.left + 8);
|
|
3205
|
+
const rightEdge = Math.min(window.innerWidth - 12, boundary.right - 8);
|
|
3206
|
+
const available = Math.max(0, rightEdge - leftEdge);
|
|
3207
|
+
const quick = this.active.action.kind === "quick";
|
|
3208
|
+
const width = Math.min(quick ? 292 : 336, available);
|
|
3209
|
+
let left = Math.min(Math.max(leftEdge, quick ? anchor.right - width : anchor.left), rightEdge - width);
|
|
3210
|
+
let total = width;
|
|
3211
|
+
let compact = false;
|
|
3212
|
+
this.popup.dataset.detailSide = "";
|
|
3213
|
+
if (quick && this.activeParam) {
|
|
3214
|
+
const detailWidth = Math.min(320, available);
|
|
3215
|
+
const placeLeft = left - leftEdge >= detailWidth + 8;
|
|
3216
|
+
const placeRight = rightEdge - (left + width) >= detailWidth + 8;
|
|
3217
|
+
compact = !placeLeft && !placeRight;
|
|
3218
|
+
if (!compact) {
|
|
3219
|
+
if (placeLeft) {
|
|
3220
|
+
left -= detailWidth + 8;
|
|
3221
|
+
}
|
|
3222
|
+
total += detailWidth + 8;
|
|
3223
|
+
}
|
|
3224
|
+
this.popup.dataset.detailSide = placeLeft ? "left" : "right";
|
|
3225
|
+
}
|
|
3226
|
+
this.popup.dataset.compact = String(compact);
|
|
3227
|
+
this.popup.style.left = `${left}px`;
|
|
3228
|
+
this.popup.style.bottom = `${window.innerHeight - anchor.top + 8}px`;
|
|
3229
|
+
this.popup.style.width = `${total}px`;
|
|
3230
|
+
this.popup.style.maxHeight = `${Math.max(40, Math.min(380, anchor.top - 20))}px`;
|
|
3231
|
+
}
|
|
3232
|
+
};
|
|
3233
|
+
|
|
3234
|
+
// src/web/ui/workflow-fields.ts
|
|
3235
|
+
var WorkflowFields = class {
|
|
3236
|
+
constructor(root, actions, options) {
|
|
3237
|
+
this.root = root;
|
|
3238
|
+
this.options = options;
|
|
3239
|
+
this.actions = new ParameterActions(actions, {
|
|
3240
|
+
current: () => ({ values: options.values(), states: options.states(), disabled: options.disabled(), loading: options.loading() }),
|
|
3241
|
+
fieldRoot: (name) => this.fields.get(name).root,
|
|
3242
|
+
onChange: (name, value) => options.change(name, value),
|
|
3243
|
+
onReset: (names) => {
|
|
3244
|
+
for (const name of names) {
|
|
3245
|
+
options.change(name, workflowParamValue(this.fields.get(name).field));
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
root;
|
|
3251
|
+
options;
|
|
3252
|
+
parameters = { fields: [] };
|
|
3253
|
+
fields = /* @__PURE__ */ new Map();
|
|
3254
|
+
actions;
|
|
3255
|
+
close() {
|
|
3256
|
+
this.actions.close();
|
|
3257
|
+
}
|
|
3258
|
+
render(parameters) {
|
|
3259
|
+
this.parameters = parameters;
|
|
3260
|
+
this.fields.clear();
|
|
3261
|
+
this.root.replaceChildren();
|
|
3262
|
+
const inActions = new Set(parameters.paramLayout?.actions.flatMap((action2) => action2.kind === "mode" ? [action2.name] : action2.params) ?? []);
|
|
3263
|
+
for (const field of parameters.fields) {
|
|
3264
|
+
const view = this.field(field);
|
|
3265
|
+
this.fields.set(field.name, view);
|
|
3266
|
+
if (!inActions.has(field.name) || field.panel === "main") {
|
|
3267
|
+
this.root.append(view.root);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
this.actions.render(parameters);
|
|
3271
|
+
this.update();
|
|
3272
|
+
}
|
|
3273
|
+
field(field) {
|
|
3274
|
+
const root = document.createElement("div");
|
|
3275
|
+
root.className = `param-field${field.type === "boolean" ? " boolean-field" : ""}`;
|
|
3276
|
+
root.dataset.param = field.name;
|
|
3277
|
+
const label = document.createElement("label");
|
|
3278
|
+
label.className = "field-label";
|
|
3279
|
+
label.textContent = `${field.label || field.name}${field.required ? " *" : ""}`;
|
|
3280
|
+
label.title = field.description ?? "";
|
|
3281
|
+
root.append(label);
|
|
3282
|
+
const view = { field, root, controls: [] };
|
|
3283
|
+
if (field.control === "radio" || field.control === "checkboxes") {
|
|
3284
|
+
const choices = document.createElement("div");
|
|
3285
|
+
choices.className = "field-choices";
|
|
3286
|
+
root.append(choices);
|
|
3287
|
+
} else if (field.type === "file" || field.control === "audio") {
|
|
3288
|
+
const summary = document.createElement("span");
|
|
3289
|
+
summary.className = "param-file-summary";
|
|
3290
|
+
const button = iconButton("attach", "\u9009\u62E9\u6587\u4EF6", () => this.options.file(field.name));
|
|
3291
|
+
button.classList.add("param-file-button");
|
|
3292
|
+
root.append(summary, button);
|
|
3293
|
+
} else {
|
|
3294
|
+
const control = field.control === "select" || field.options !== void 0 ? document.createElement("select") : field.control === "textarea" || field.format === "json" ? document.createElement("textarea") : document.createElement("input");
|
|
3295
|
+
if (control instanceof HTMLInputElement) {
|
|
3296
|
+
control.type = field.type === "boolean" ? "checkbox" : field.type === "number" ? "number" : field.control === "datetime" ? "datetime-local" : ["date", "time"].includes(field.control ?? "") ? field.control : /password|secret|token|key/i.test(field.name) ? "password" : "text";
|
|
3297
|
+
if (control.type === "number") {
|
|
3298
|
+
control.step = "any";
|
|
3299
|
+
}
|
|
3300
|
+
if (control.type === "checkbox") {
|
|
3301
|
+
control.setAttribute("role", "switch");
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
if (control instanceof HTMLSelectElement) {
|
|
3305
|
+
control.multiple = !!field.multiple;
|
|
3306
|
+
}
|
|
3307
|
+
if (control instanceof HTMLTextAreaElement) {
|
|
3308
|
+
control.rows = 3;
|
|
3309
|
+
}
|
|
3310
|
+
control.id = `workflow-param-${field.name}`;
|
|
3311
|
+
label.htmlFor = control.id;
|
|
3312
|
+
control.className = "field-control";
|
|
3313
|
+
control.required = !!field.required && field.type !== "boolean";
|
|
3314
|
+
control.addEventListener(control instanceof HTMLSelectElement || field.type === "boolean" ? "change" : "input", () => {
|
|
3315
|
+
const value = control instanceof HTMLInputElement && control.type === "checkbox" ? String(control.checked) : control instanceof HTMLSelectElement && control.multiple ? Array.from(control.selectedOptions, (option) => option.value) : control.value;
|
|
3316
|
+
this.options.change(field.name, value);
|
|
3317
|
+
});
|
|
3318
|
+
view.controls.push(control);
|
|
3319
|
+
root.append(control);
|
|
3320
|
+
}
|
|
3321
|
+
if (field.description) {
|
|
3322
|
+
const description = document.createElement("small");
|
|
3323
|
+
description.textContent = field.description;
|
|
3324
|
+
description.className = "option-description";
|
|
3325
|
+
root.append(description);
|
|
3326
|
+
}
|
|
3327
|
+
return view;
|
|
3328
|
+
}
|
|
3329
|
+
update() {
|
|
3330
|
+
const values2 = this.options.values(), states = this.options.states();
|
|
3331
|
+
for (const [name, view] of this.fields) {
|
|
3332
|
+
const state2 = states[name], field = view.field;
|
|
3333
|
+
view.root.hidden = state2?.visible === false;
|
|
3334
|
+
const options = (state2?.resolvedOptions ?? field.options ?? []).filter((option) => state2?.options?.[option.value]?.visible !== false);
|
|
3335
|
+
const signature2 = JSON.stringify([options, state2?.options]);
|
|
3336
|
+
if (signature2 !== view.signature) {
|
|
3337
|
+
view.signature = signature2;
|
|
3338
|
+
const control = view.controls[0];
|
|
3339
|
+
if (control instanceof HTMLSelectElement) {
|
|
3340
|
+
control.replaceChildren();
|
|
3341
|
+
if (!control.multiple) {
|
|
3342
|
+
control.append(new Option("\u9009\u62E9...", ""));
|
|
3343
|
+
}
|
|
3344
|
+
for (const option of options) {
|
|
3345
|
+
const item = new Option(option.label || option.value, option.value);
|
|
3346
|
+
item.disabled = !!state2?.options?.[option.value]?.disabled;
|
|
3347
|
+
item.title = option.description ?? "";
|
|
3348
|
+
control.append(item);
|
|
3349
|
+
}
|
|
3350
|
+
} else if (field.control === "radio" || field.control === "checkboxes") {
|
|
3351
|
+
const choices = view.root.querySelector(".field-choices");
|
|
3352
|
+
choices.replaceChildren();
|
|
3353
|
+
view.controls = options.map((option) => {
|
|
3354
|
+
const label = document.createElement("label"), control2 = document.createElement("input");
|
|
3355
|
+
control2.type = field.control === "checkboxes" ? "checkbox" : "radio";
|
|
3356
|
+
control2.name = `workflow-param-${name}`;
|
|
3357
|
+
control2.value = option.value;
|
|
3358
|
+
control2.addEventListener("change", () => this.options.change(name, field.control === "checkboxes" ? view.controls.filter((item) => item instanceof HTMLInputElement && item.checked).map((item) => item.value) : option.value));
|
|
3359
|
+
label.append(control2, document.createTextNode(option.label || option.value));
|
|
3360
|
+
label.title = option.description ?? "";
|
|
3361
|
+
choices.append(label);
|
|
3362
|
+
return control2;
|
|
3363
|
+
});
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
const value = values2[name];
|
|
3367
|
+
for (const control of view.controls) {
|
|
3368
|
+
if (control instanceof HTMLInputElement && control.type === "checkbox") {
|
|
3369
|
+
control.checked = field.control === "checkboxes" ? Array.isArray(value) && value.includes(control.value) : value === "true";
|
|
3370
|
+
} else if (control instanceof HTMLInputElement && control.type === "radio") {
|
|
3371
|
+
control.checked = control.value === value;
|
|
3372
|
+
} else if (control instanceof HTMLSelectElement && control.multiple) {
|
|
3373
|
+
for (const option of Array.from(control.options)) {
|
|
3374
|
+
option.selected = Array.isArray(value) && value.includes(option.value);
|
|
3375
|
+
}
|
|
3376
|
+
} else {
|
|
3377
|
+
const next = typeof value === "string" ? value : "";
|
|
3378
|
+
if (control.value !== next) {
|
|
3379
|
+
control.value = next;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
control.disabled = this.options.disabled() || !!state2?.disabled || ["radio", "checkboxes"].includes(field.control ?? "") && !!state2?.options?.[control.value]?.disabled;
|
|
3383
|
+
}
|
|
3384
|
+
if (field.type === "file" || field.control === "audio") {
|
|
3385
|
+
try {
|
|
3386
|
+
const files = JSON.parse(String(value || "[]"));
|
|
3387
|
+
const list = Array.isArray(files) ? files : [files];
|
|
3388
|
+
const summary = view.root.querySelector(".param-file-summary");
|
|
3389
|
+
if (this.options.downloadFile && summary.getAttribute("data-value") !== String(value)) {
|
|
3390
|
+
summary.setAttribute("data-value", String(value));
|
|
3391
|
+
summary.replaceChildren();
|
|
3392
|
+
for (const file of list.filter((file2) => file2 && typeof file2.id === "string")) {
|
|
3393
|
+
const row = document.createElement("span");
|
|
3394
|
+
row.className = "param-file-row";
|
|
3395
|
+
const name2 = document.createElement("span");
|
|
3396
|
+
name2.textContent = file.name;
|
|
3397
|
+
row.append(name2);
|
|
3398
|
+
const download = iconButton("cloud-download", "\u4E0B\u8F7D\u6587\u4EF6", () => this.options.downloadFile(file.id));
|
|
3399
|
+
const remove = iconButton("close", "\u79FB\u9664\u6587\u4EF6", () => this.options.change(field.name, JSON.stringify(list.filter((item) => item !== file))));
|
|
3400
|
+
download.classList.add("param-file-download");
|
|
3401
|
+
remove.classList.add("param-file-remove");
|
|
3402
|
+
row.append(download, remove);
|
|
3403
|
+
summary.append(row);
|
|
3404
|
+
}
|
|
3405
|
+
} else if (!this.options.downloadFile) {
|
|
3406
|
+
summary.textContent = list.map((file) => file?.name ?? "").join(", ");
|
|
3407
|
+
}
|
|
3408
|
+
for (const button of summary.querySelectorAll("button")) {
|
|
3409
|
+
button.disabled = this.options.disabled() || button.classList.contains("param-file-remove") && this.options.loading();
|
|
3410
|
+
}
|
|
3411
|
+
} catch {
|
|
3412
|
+
view.root.querySelector(".param-file-summary").textContent = "";
|
|
3413
|
+
}
|
|
3414
|
+
view.root.querySelector(".param-file-button").disabled = this.options.disabled() || this.options.loading() || !!state2?.disabled;
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
this.root.hidden = !Array.from(this.root.children).some((root) => !root.hidden);
|
|
3418
|
+
this.actions.update();
|
|
3419
|
+
}
|
|
3420
|
+
};
|
|
3421
|
+
|
|
3422
|
+
// src/web/ui/conversation-tools.ts
|
|
3423
|
+
var ConversationTools = class {
|
|
3424
|
+
dialog = document.createElement("dialog");
|
|
3425
|
+
body = document.createElement("div");
|
|
3426
|
+
title = document.createElement("h2");
|
|
3427
|
+
usageOpen = false;
|
|
3428
|
+
refresh;
|
|
3429
|
+
constructor() {
|
|
3430
|
+
this.dialog.className = "conversation-dialog";
|
|
3431
|
+
const header = document.createElement("header");
|
|
3432
|
+
header.append(this.title, iconButton("close", "\u5173\u95ED", () => this.close()));
|
|
3433
|
+
this.body.className = "dialog-body";
|
|
3434
|
+
this.dialog.append(header, this.body);
|
|
3435
|
+
document.body.append(this.dialog);
|
|
3436
|
+
this.dialog.addEventListener("click", (event) => {
|
|
3437
|
+
if (event.target === this.dialog) {
|
|
3438
|
+
const rect = this.dialog.getBoundingClientRect();
|
|
3439
|
+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) {
|
|
3440
|
+
this.close();
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
get open() {
|
|
3446
|
+
return this.dialog.open;
|
|
3447
|
+
}
|
|
3448
|
+
close() {
|
|
3449
|
+
this.dialog.close();
|
|
3450
|
+
this.usageOpen = false;
|
|
3451
|
+
this.refresh?.remove();
|
|
3452
|
+
this.refresh = void 0;
|
|
3453
|
+
}
|
|
3454
|
+
show(title) {
|
|
3455
|
+
this.close();
|
|
3456
|
+
this.title.textContent = title;
|
|
3457
|
+
this.body.replaceChildren();
|
|
3458
|
+
this.dialog.showModal();
|
|
3459
|
+
}
|
|
3460
|
+
plan(content) {
|
|
3461
|
+
this.show("\u8BA1\u5212");
|
|
3462
|
+
const article = document.createElement("article");
|
|
3463
|
+
article.className = "message-content";
|
|
3464
|
+
article.innerHTML = markdownHtml(content);
|
|
3465
|
+
this.body.append(article);
|
|
3466
|
+
}
|
|
3467
|
+
image(src, title) {
|
|
3468
|
+
this.show(title || "\u56FE\u7247");
|
|
3469
|
+
const image = document.createElement("img");
|
|
3470
|
+
image.src = src;
|
|
3471
|
+
image.alt = title;
|
|
3472
|
+
image.className = "image-preview";
|
|
3473
|
+
this.body.append(image);
|
|
3474
|
+
}
|
|
3475
|
+
permissions(parameters, policies, changed) {
|
|
3476
|
+
this.show("\u5DE5\u5177\u6743\u9650");
|
|
3477
|
+
const tools = parameters.tools ?? [];
|
|
3478
|
+
const count = document.createElement("p");
|
|
3479
|
+
count.className = "tool-count";
|
|
3480
|
+
count.textContent = `${tools.length} \u4E2A\u5DE5\u5177`;
|
|
3481
|
+
this.body.append(count);
|
|
3482
|
+
const table = document.createElement("table");
|
|
3483
|
+
table.className = "permissions-table";
|
|
3484
|
+
table.innerHTML = "<thead><tr><th>\u5DE5\u5177</th><th>\u542F\u7528</th><th>\u81EA\u52A8\u6279\u51C6</th></tr></thead>";
|
|
3485
|
+
const body = document.createElement("tbody");
|
|
3486
|
+
const draft = {};
|
|
3487
|
+
for (const tool of tools) {
|
|
3488
|
+
draft[tool.name] = { enabled: policies[tool.name]?.enabled ?? tool.enabled ?? true, autoApprove: policies[tool.name]?.autoApprove ?? tool.autoApprove ?? false };
|
|
3489
|
+
const row = document.createElement("tr");
|
|
3490
|
+
const label = document.createElement("td");
|
|
3491
|
+
label.textContent = tool.label || tool.name;
|
|
3492
|
+
label.title = tool.description || tool.name;
|
|
3493
|
+
row.append(label);
|
|
3494
|
+
for (const property of ["enabled", "autoApprove"]) {
|
|
3495
|
+
const cell = document.createElement("td");
|
|
3496
|
+
const checkbox = document.createElement("input");
|
|
3497
|
+
checkbox.type = "checkbox";
|
|
3498
|
+
checkbox.checked = draft[tool.name][property];
|
|
3499
|
+
checkbox.ariaLabel = `${tool.label || tool.name} ${property === "enabled" ? "\u542F\u7528" : "\u81EA\u52A8\u6279\u51C6"}`;
|
|
3500
|
+
checkbox.addEventListener("change", () => {
|
|
3501
|
+
draft[tool.name][property] = checkbox.checked;
|
|
3502
|
+
changed(draft);
|
|
3503
|
+
});
|
|
3504
|
+
cell.append(checkbox);
|
|
3505
|
+
row.append(cell);
|
|
3506
|
+
}
|
|
3507
|
+
body.append(row);
|
|
3508
|
+
}
|
|
3509
|
+
table.append(body);
|
|
3510
|
+
this.body.append(table);
|
|
3511
|
+
if (!tools.length) {
|
|
3512
|
+
const empty = document.createElement("p");
|
|
3513
|
+
empty.textContent = "\u9879\u76EE\u672A\u58F0\u660E\u5DE5\u5177";
|
|
3514
|
+
this.body.append(empty);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
usage(load) {
|
|
3518
|
+
this.show("\u7CFB\u7EDF AI");
|
|
3519
|
+
this.usageOpen = true;
|
|
3520
|
+
const refresh = this.refresh = iconButton("refresh", "\u5237\u65B0\u7528\u91CF", () => {
|
|
3521
|
+
this.body.textContent = "\u52A0\u8F7D\u4E2D...";
|
|
3522
|
+
load();
|
|
3523
|
+
});
|
|
3524
|
+
this.dialog.querySelector("header").insertBefore(refresh, this.dialog.querySelector("header > button:last-child"));
|
|
3525
|
+
this.body.textContent = "\u52A0\u8F7D\u4E2D...";
|
|
3526
|
+
load();
|
|
3527
|
+
}
|
|
3528
|
+
usageResult(data, error) {
|
|
3529
|
+
if (!this.usageOpen) {
|
|
3530
|
+
return;
|
|
3531
|
+
}
|
|
3532
|
+
this.body.replaceChildren();
|
|
3533
|
+
if (error) {
|
|
3534
|
+
this.body.textContent = error;
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
if (!data) {
|
|
3538
|
+
return;
|
|
3539
|
+
}
|
|
3540
|
+
const balance = document.createElement("p");
|
|
3541
|
+
balance.textContent = `\u8D26\u6237\u4F59\u989D $${Number(data.balance ?? 0).toFixed(2)}`;
|
|
3542
|
+
this.body.append(balance);
|
|
3543
|
+
const labels = { daily: "\u6BCF\u65E5", weekly: "\u6BCF\u5468", monthly: "\u6BCF\u6708" };
|
|
3544
|
+
const plans = data.groups.filter((group) => group.subscriptionType === "subscription" && group.subscription?.status === "active");
|
|
3545
|
+
if (!plans.length) {
|
|
3546
|
+
const empty = document.createElement("p");
|
|
3547
|
+
empty.textContent = "\u6682\u65E0\u5DF2\u8BA2\u9605\u5957\u9910";
|
|
3548
|
+
this.body.append(empty);
|
|
3549
|
+
}
|
|
3550
|
+
for (const plan of plans) {
|
|
3551
|
+
const section = document.createElement("section");
|
|
3552
|
+
section.className = "usage-plan";
|
|
3553
|
+
const title = document.createElement("h3");
|
|
3554
|
+
title.textContent = plan.name;
|
|
3555
|
+
section.append(title);
|
|
3556
|
+
for (const period of ["daily", "weekly", "monthly"]) {
|
|
3557
|
+
const limit = plan.subscription[`${period}LimitUsd`];
|
|
3558
|
+
const used = Number(plan.subscription[`${period}UsageUsd`] ?? 0);
|
|
3559
|
+
const row = document.createElement("div");
|
|
3560
|
+
const label = document.createElement("span");
|
|
3561
|
+
label.textContent = `${labels[period]} $${used.toFixed(2)} / ${limit === null ? "\u4E0D\u9650" : `$${Number(limit).toFixed(2)}`}`;
|
|
3562
|
+
row.append(label);
|
|
3563
|
+
if (limit !== null && limit > 0) {
|
|
3564
|
+
const progress = document.createElement("progress");
|
|
3565
|
+
progress.max = limit;
|
|
3566
|
+
progress.value = used;
|
|
3567
|
+
row.append(progress);
|
|
3568
|
+
}
|
|
3569
|
+
section.append(row);
|
|
3570
|
+
}
|
|
3571
|
+
this.body.append(section);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
};
|
|
3575
|
+
|
|
3576
|
+
// .shared/kanban-project/methods.ts
|
|
3577
|
+
var KANBAN_METHOD_CATALOG_MESSAGE = "workflow-code:kanban-method-catalog";
|
|
3578
|
+
var KANBAN_METHOD_INVOKE_MESSAGE = "workflow-code:kanban-method-invoke";
|
|
3579
|
+
var KANBAN_METHOD_RESULT_MESSAGE = "workflow-code:kanban-method-result";
|
|
3580
|
+
var KANBAN_METHOD_CANCEL_MESSAGE = "workflow-code:kanban-method-cancel";
|
|
3581
|
+
var KANBAN_METHOD_MAX_JSON_CHARS = 65536;
|
|
3582
|
+
var KANBAN_METHOD_TIMEOUT_MS = 15e3;
|
|
3583
|
+
var MAX_METHODS = 32;
|
|
3584
|
+
function assertKanbanMethodJson(value) {
|
|
3585
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3586
|
+
const visit = (node, depth) => {
|
|
3587
|
+
if (depth > 32) return false;
|
|
3588
|
+
if (node === null || typeof node === "string" || typeof node === "boolean") return true;
|
|
3589
|
+
if (typeof node === "number") return Number.isFinite(node);
|
|
3590
|
+
if (typeof node !== "object" || seen.has(node)) return false;
|
|
3591
|
+
seen.add(node);
|
|
3592
|
+
const valid = Array.isArray(node) ? node.every((item) => visit(item, depth + 1)) : Object.getPrototypeOf(node) === Object.prototype && Object.values(node).every((item) => visit(item, depth + 1));
|
|
3593
|
+
seen.delete(node);
|
|
3594
|
+
return valid;
|
|
3595
|
+
};
|
|
3596
|
+
if (!visit(value, 0) || JSON.stringify(value).length > KANBAN_METHOD_MAX_JSON_CHARS) {
|
|
3597
|
+
throw methodError("KANBAN_METHOD_INVALID_JSON", "Kanban method data must be JSON, at most 32 levels deep and 64 Ki characters.");
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
function parseKanbanMethodDefinitions(value) {
|
|
3601
|
+
assertKanbanMethodJson(value);
|
|
3602
|
+
if (!Array.isArray(value) || value.length > MAX_METHODS) throw methodError("KANBAN_METHOD_INVALID_CATALOG", "Invalid Kanban method catalog.");
|
|
3603
|
+
const names = /* @__PURE__ */ new Set();
|
|
3604
|
+
for (const item of value) {
|
|
3605
|
+
if (!isRecord(item) || Object.keys(item).some((key) => !["name", "description", "inputSchema", "readOnly"].includes(key)) || typeof item.name !== "string" || !/^[a-zA-Z][a-zA-Z0-9_.-]{0,79}$/.test(item.name) || names.has(item.name) || typeof item.description !== "string" || !item.description.trim() || item.description.length > 2e3 || !isRecord(item.inputSchema) || item.inputSchema.type !== "object" || JSON.stringify(item.inputSchema).length > 8192 || item.readOnly !== void 0 && typeof item.readOnly !== "boolean") {
|
|
3606
|
+
throw methodError("KANBAN_METHOD_INVALID_CATALOG", "Invalid Kanban method definition.");
|
|
3607
|
+
}
|
|
3608
|
+
names.add(item.name);
|
|
3609
|
+
}
|
|
3610
|
+
return JSON.parse(JSON.stringify(value));
|
|
3611
|
+
}
|
|
3612
|
+
function createKanbanMethodSession(options) {
|
|
3613
|
+
const instanceId = globalThis.crypto.randomUUID();
|
|
3614
|
+
let ready = false;
|
|
3615
|
+
let closed = false;
|
|
3616
|
+
let revision = 0;
|
|
3617
|
+
let documentId;
|
|
3618
|
+
let methods = [];
|
|
3619
|
+
const pending2 = /* @__PURE__ */ new Map();
|
|
3620
|
+
const post = (message) => options.postMessage({ ...message, nonce: options.nonce });
|
|
3621
|
+
return {
|
|
3622
|
+
instanceId,
|
|
3623
|
+
getState() {
|
|
3624
|
+
const configuration = options.getConfiguration();
|
|
3625
|
+
return {
|
|
3626
|
+
ready,
|
|
3627
|
+
configurationId: configuration?.id ?? "",
|
|
3628
|
+
configurationName: configuration?.name ?? "",
|
|
3629
|
+
presentation: options.getPresentation(),
|
|
3630
|
+
methods: JSON.parse(JSON.stringify(methods))
|
|
3631
|
+
};
|
|
3632
|
+
},
|
|
3633
|
+
async invoke(call, signal) {
|
|
3634
|
+
if (closed || !ready) throw methodError("KANBAN_METHOD_INSTANCE_UNAVAILABLE", "The Kanban preview is not ready or has closed.");
|
|
3635
|
+
if (call.configurationId !== (options.getConfiguration()?.id ?? "")) throw methodError("KANBAN_METHOD_STALE", "The Kanban configuration changed. List instances again.");
|
|
3636
|
+
if (!methods.some((method) => method.name === call.method)) throw methodError("KANBAN_METHOD_UNAVAILABLE", "The Kanban page has not registered this method.");
|
|
3637
|
+
assertKanbanMethodJson(call.args);
|
|
3638
|
+
if (pending2.size >= 4) throw methodError("KANBAN_METHOD_BUSY", "Too many Kanban method calls are pending.");
|
|
3639
|
+
if (signal?.aborted) throw methodError("KANBAN_METHOD_CANCELLED", "Kanban method call was cancelled.");
|
|
3640
|
+
const requestId = globalThis.crypto.randomUUID();
|
|
3641
|
+
return new Promise((resolve, reject) => {
|
|
3642
|
+
const cancel = (code, message) => {
|
|
3643
|
+
pending2.get(requestId)?.finish(methodError(code, message));
|
|
3644
|
+
try {
|
|
3645
|
+
post({ type: KANBAN_METHOD_CANCEL_MESSAGE, requestId });
|
|
3646
|
+
} catch {
|
|
3647
|
+
}
|
|
3648
|
+
};
|
|
3649
|
+
const onAbort = () => cancel("KANBAN_METHOD_CANCELLED", "Kanban method call was cancelled.");
|
|
3650
|
+
const timer = setTimeout(() => cancel("KANBAN_METHOD_TIMEOUT", "Kanban method call timed out. Its effects may already have occurred; inspect state before retrying."), options.timeoutMs ?? KANBAN_METHOD_TIMEOUT_MS);
|
|
3651
|
+
pending2.set(requestId, {
|
|
3652
|
+
finish(error, value) {
|
|
3653
|
+
if (!pending2.delete(requestId)) return;
|
|
3654
|
+
clearTimeout(timer);
|
|
3655
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3656
|
+
if (error) reject(error);
|
|
3657
|
+
else resolve(value);
|
|
3658
|
+
}
|
|
3659
|
+
});
|
|
3660
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3661
|
+
try {
|
|
3662
|
+
post({ type: KANBAN_METHOD_INVOKE_MESSAGE, requestId, documentId, revision, configurationId: call.configurationId, method: call.method, input: call.args });
|
|
3663
|
+
} catch {
|
|
3664
|
+
pending2.get(requestId)?.finish(methodError("KANBAN_METHOD_INSTANCE_UNAVAILABLE", "The Kanban preview is unavailable."));
|
|
3665
|
+
}
|
|
3666
|
+
});
|
|
3667
|
+
},
|
|
3668
|
+
receive(message) {
|
|
3669
|
+
if (closed || message.nonce !== options.nonce) return;
|
|
3670
|
+
if (message.type === "workflow-code:kanban-ready") {
|
|
3671
|
+
if (typeof message.documentId === "string" && documentId !== message.documentId) {
|
|
3672
|
+
for (const request3 of pending2.values()) request3.finish(methodError("KANBAN_METHOD_INSTANCE_UNAVAILABLE", "The Kanban document refreshed."));
|
|
3673
|
+
documentId = message.documentId;
|
|
3674
|
+
revision = 0;
|
|
3675
|
+
methods = [];
|
|
3676
|
+
}
|
|
3677
|
+
ready = true;
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3680
|
+
if (message.type === KANBAN_METHOD_CATALOG_MESSAGE) {
|
|
3681
|
+
if (message.documentId !== documentId) return;
|
|
3682
|
+
if (message.configurationId !== (options.getConfiguration()?.id ?? "") || !Number.isSafeInteger(message.revision) || message.revision < revision) return;
|
|
3683
|
+
try {
|
|
3684
|
+
methods = parseKanbanMethodDefinitions(message.methods);
|
|
3685
|
+
revision = message.revision;
|
|
3686
|
+
} catch {
|
|
3687
|
+
return;
|
|
3688
|
+
}
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
if (message.type !== KANBAN_METHOD_RESULT_MESSAGE || typeof message.requestId !== "string") return;
|
|
3692
|
+
const request2 = pending2.get(message.requestId);
|
|
3693
|
+
if (!request2) return;
|
|
3694
|
+
if (message.ok === true) {
|
|
3695
|
+
try {
|
|
3696
|
+
assertKanbanMethodJson(message.value);
|
|
3697
|
+
request2.finish(void 0, message.value);
|
|
3698
|
+
} catch {
|
|
3699
|
+
request2.finish(methodError("KANBAN_METHOD_INVALID_RESULT", "The Kanban method returned invalid or oversized JSON."));
|
|
3700
|
+
}
|
|
3701
|
+
} else if (message.ok === false) {
|
|
3702
|
+
const error = isRecord(message.error) ? message.error : {};
|
|
3703
|
+
request2.finish(methodError(
|
|
3704
|
+
typeof error.code === "string" && /^KANBAN_METHOD_[A-Z_]+$/.test(error.code) ? error.code : "KANBAN_METHOD_FAILED",
|
|
3705
|
+
typeof error.message === "string" ? error.message.slice(0, 2e3) : "Kanban method failed."
|
|
3706
|
+
));
|
|
3707
|
+
}
|
|
3708
|
+
},
|
|
3709
|
+
close() {
|
|
3710
|
+
closed = true;
|
|
3711
|
+
ready = false;
|
|
3712
|
+
methods = [];
|
|
3713
|
+
for (const [requestId, request2] of pending2) {
|
|
3714
|
+
request2.finish(methodError("KANBAN_METHOD_INSTANCE_UNAVAILABLE", "The Kanban preview closed, refreshed, or changed configuration."));
|
|
3715
|
+
try {
|
|
3716
|
+
post({ type: KANBAN_METHOD_CANCEL_MESSAGE, requestId });
|
|
3717
|
+
} catch {
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3723
|
+
function methodError(code, message) {
|
|
3724
|
+
return Object.assign(new Error(message), { code });
|
|
3725
|
+
}
|
|
3726
|
+
function isRecord(value) {
|
|
3727
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
// .shared/project-info/index.ts
|
|
3731
|
+
var WORKFLOW_RELATED_PROJECT_ALIAS_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
3732
|
+
var WORKFLOW_RELATED_PROJECT_KEY_LIMIT = 1024;
|
|
3733
|
+
|
|
3734
|
+
// .shared/kanban-project/index.ts
|
|
3735
|
+
var KANBAN_PREVIEW_READY_MESSAGE = "workflow-code:kanban-ready";
|
|
3736
|
+
var KANBAN_BRIDGE_REQUEST_MESSAGE = "workflow-code:kanban-bridge-request";
|
|
3737
|
+
var KANBAN_BRIDGE_RESPONSE_MESSAGE = "workflow-code:kanban-bridge-response";
|
|
3738
|
+
var KANBAN_FILE_MAX_BYTES = 50 * 1024 * 1024;
|
|
3739
|
+
var KANBAN_BRIDGE_MAX_PENDING_REQUESTS = 16;
|
|
3740
|
+
var KANBAN_BRIDGE_SAFE_ERRORS = {
|
|
3741
|
+
KANBAN_BRIDGE_INVALID_REQUEST: "The Kanban bridge request is invalid.",
|
|
3742
|
+
KANBAN_BRIDGE_BUSY: "Too many Kanban bridge requests are pending.",
|
|
3743
|
+
KANBAN_BRIDGE_TIMEOUT: "Kanban bridge request timed out.",
|
|
3744
|
+
KANBAN_BRIDGE_UNAVAILABLE: "Kanban project data is unavailable in this host.",
|
|
3745
|
+
KANBAN_BRIDGE_SESSION_INVALID: "The Kanban preview session is invalid or expired.",
|
|
3746
|
+
KANBAN_BRIDGE_SERVER_ERROR: "Kanban project data operation failed.",
|
|
3747
|
+
KANBAN_DATA_OPERATION_FAILED: "Kanban project data operation failed.",
|
|
3748
|
+
KANBAN_RELATED_PROJECT_UNAVAILABLE: "Kanban related project is unavailable.",
|
|
3749
|
+
KANBAN_FILE_UNAVAILABLE: "Kanban file is unavailable in this project.",
|
|
3750
|
+
KANBAN_FILE_TOO_LARGE: "Kanban files cannot exceed 50 MiB."
|
|
3751
|
+
};
|
|
3752
|
+
var KANBAN_BRIDGE_CALL_FIELDS = /* @__PURE__ */ new Set(["requestId", "operation", "input"]);
|
|
3753
|
+
var MAX_KNOWLEDGE_DOCUMENT_PAGE_SIZE = 100;
|
|
3754
|
+
var MAX_KNOWLEDGE_SEARCH_PAGE_SIZE = 1e3;
|
|
3755
|
+
var MAX_KNOWLEDGE_CONTEXT_LINES = 50;
|
|
3756
|
+
var MAX_KNOWLEDGE_LINE_RANGE = 1e3;
|
|
3757
|
+
var KANBAN_BRIDGE_INPUT_FIELDS = {
|
|
3758
|
+
"runtime.getLocale": [],
|
|
3759
|
+
"files.createFile": ["name", "mimeType", "base64"],
|
|
3760
|
+
"files.readFile": ["fileId"],
|
|
3761
|
+
"files.deleteFile": ["fileId"],
|
|
3762
|
+
"kv.getValue": ["key"],
|
|
3763
|
+
"kv.setValue": ["key", "value"],
|
|
3764
|
+
"relatedProject.kv.getValue": ["alias", "key"],
|
|
3765
|
+
"relatedProject.kv.setValue": ["alias", "key", "value"],
|
|
3766
|
+
"knowledge.listDocuments": ["pageSize", "cursor"],
|
|
3767
|
+
"knowledge.getDocument": ["documentId"],
|
|
3768
|
+
"knowledge.createDocument": ["id", "title", "markdown"],
|
|
3769
|
+
"knowledge.editDocument": ["documentId", "title", "markdown"],
|
|
3770
|
+
"knowledge.deleteDocument": ["documentId"],
|
|
3771
|
+
"knowledge.searchDocuments": [
|
|
3772
|
+
"query",
|
|
3773
|
+
"documentId",
|
|
3774
|
+
"beforeLines",
|
|
3775
|
+
"afterLines",
|
|
3776
|
+
"maxMatches",
|
|
3777
|
+
"pageSize",
|
|
3778
|
+
"cursor"
|
|
3779
|
+
],
|
|
3780
|
+
"knowledge.readDocumentLines": ["documentId", "startLine", "endLine"]
|
|
3781
|
+
};
|
|
3782
|
+
function parseKanbanBridgeCall(value) {
|
|
3783
|
+
if (!isRecord2(value)) throw new Error("Kanban bridge request must be an object.");
|
|
3784
|
+
if (Object.keys(value).some((key) => !KANBAN_BRIDGE_CALL_FIELDS.has(key))) {
|
|
3785
|
+
throw new Error("Kanban bridge request contains unsupported fields.");
|
|
3786
|
+
}
|
|
3787
|
+
const requestId = readNonEmptyString(value["requestId"], "bridge.requestId");
|
|
3788
|
+
const operation = value["operation"];
|
|
3789
|
+
if (!isKanbanBridgeOperation(operation)) {
|
|
3790
|
+
throw new Error(`Unsupported Kanban bridge operation "${String(operation)}".`);
|
|
3791
|
+
}
|
|
3792
|
+
const input = value["input"];
|
|
3793
|
+
if (!isRecord2(input)) throw new Error("Kanban bridge input must be an object.");
|
|
3794
|
+
validateKanbanBridgeInput(operation, input);
|
|
3795
|
+
return { requestId, operation, input };
|
|
3796
|
+
}
|
|
3797
|
+
function createKanbanBridgeError(reason) {
|
|
3798
|
+
if (isRecord2(reason)) {
|
|
3799
|
+
const code = reason["code"];
|
|
3800
|
+
if (typeof code === "string" && Object.prototype.hasOwnProperty.call(KANBAN_BRIDGE_SAFE_ERRORS, code)) {
|
|
3801
|
+
return {
|
|
3802
|
+
code,
|
|
3803
|
+
message: KANBAN_BRIDGE_SAFE_ERRORS[code]
|
|
3804
|
+
};
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
return {
|
|
3808
|
+
code: "KANBAN_BRIDGE_ERROR",
|
|
3809
|
+
message: "Kanban bridge request failed."
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3812
|
+
function isKanbanJsonValue(value, seen = /* @__PURE__ */ new Set()) {
|
|
3813
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
3814
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
3815
|
+
if (typeof value !== "object") return false;
|
|
3816
|
+
if (seen.has(value)) return false;
|
|
3817
|
+
seen.add(value);
|
|
3818
|
+
const valid = Array.isArray(value) ? value.every((item) => isKanbanJsonValue(item, seen)) : Object.getPrototypeOf(value) === Object.prototype && Object.values(value).every((item) => isKanbanJsonValue(item, seen));
|
|
3819
|
+
seen.delete(value);
|
|
3820
|
+
return valid;
|
|
3821
|
+
}
|
|
3822
|
+
function validateKanbanBridgeInput(operation, input) {
|
|
3823
|
+
const allowedFields = new Set(KANBAN_BRIDGE_INPUT_FIELDS[operation]);
|
|
3824
|
+
if (Object.keys(input).some((key) => !allowedFields.has(key))) {
|
|
3825
|
+
throw new Error(`Kanban bridge ${operation} input contains unsupported fields.`);
|
|
3826
|
+
}
|
|
3827
|
+
switch (operation) {
|
|
3828
|
+
case "runtime.getLocale":
|
|
3829
|
+
return;
|
|
3830
|
+
case "files.createFile": {
|
|
3831
|
+
const name = readNonEmptyString(input["name"], "bridge.input.name");
|
|
3832
|
+
if (name.length > 255 || /[\\/\\\\\0]/.test(name)) {
|
|
3833
|
+
throw new Error("Kanban file name must be a plain file name.");
|
|
3834
|
+
}
|
|
3835
|
+
const mimeType = readOptionalNonEmptyString(input["mimeType"], "bridge.input.mimeType");
|
|
3836
|
+
if (mimeType !== void 0 && !/^[a-zA-Z0-9!#$&^_.+-]+\/[a-zA-Z0-9!#$&^_.+-]+$/.test(mimeType)) {
|
|
3837
|
+
throw new Error("Kanban file MIME type is invalid.");
|
|
3838
|
+
}
|
|
3839
|
+
const base64 = readRequiredString(input["base64"], "bridge.input.base64");
|
|
3840
|
+
if (base64.length > Math.ceil(KANBAN_FILE_MAX_BYTES / 3) * 4) {
|
|
3841
|
+
throw Object.assign(new Error(KANBAN_BRIDGE_SAFE_ERRORS.KANBAN_FILE_TOO_LARGE), { code: "KANBAN_FILE_TOO_LARGE" });
|
|
3842
|
+
}
|
|
3843
|
+
if (base64.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(base64)) {
|
|
3844
|
+
throw new Error("Kanban file content must be base64 encoded.");
|
|
3845
|
+
}
|
|
3846
|
+
const size = base64.length / 4 * 3 - (base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0);
|
|
3847
|
+
if (size > KANBAN_FILE_MAX_BYTES) {
|
|
3848
|
+
throw Object.assign(new Error(KANBAN_BRIDGE_SAFE_ERRORS.KANBAN_FILE_TOO_LARGE), { code: "KANBAN_FILE_TOO_LARGE" });
|
|
3849
|
+
}
|
|
3850
|
+
return;
|
|
3851
|
+
}
|
|
3852
|
+
case "files.readFile":
|
|
3853
|
+
case "files.deleteFile":
|
|
3854
|
+
if (!/^wf_[a-f0-9]+$/.test(readNonEmptyString(input["fileId"], "bridge.input.fileId"))) {
|
|
3855
|
+
throw new Error("Kanban file id is invalid.");
|
|
3856
|
+
}
|
|
3857
|
+
return;
|
|
3858
|
+
case "kv.getValue":
|
|
3859
|
+
readNonEmptyString(input["key"], "bridge.input.key");
|
|
3860
|
+
return;
|
|
3861
|
+
case "kv.setValue":
|
|
3862
|
+
readNonEmptyString(input["key"], "bridge.input.key");
|
|
3863
|
+
if (input["value"] === void 0 || !isKanbanJsonValue(input["value"])) {
|
|
3864
|
+
throw new Error("Kanban bridge KV value must be JSON-serializable and cannot be undefined.");
|
|
3865
|
+
}
|
|
3866
|
+
return;
|
|
3867
|
+
case "relatedProject.kv.getValue":
|
|
3868
|
+
case "relatedProject.kv.setValue": {
|
|
3869
|
+
const alias = readNonEmptyString(input["alias"], "bridge.input.alias");
|
|
3870
|
+
if (!WORKFLOW_RELATED_PROJECT_ALIAS_PATTERN.test(alias)) {
|
|
3871
|
+
throw new Error("Kanban bridge related-project alias is invalid.");
|
|
3872
|
+
}
|
|
3873
|
+
const key = readNonEmptyString(input["key"], "bridge.input.key");
|
|
3874
|
+
if (key.length > WORKFLOW_RELATED_PROJECT_KEY_LIMIT) {
|
|
3875
|
+
throw new Error("Kanban bridge related-project key is too long.");
|
|
3876
|
+
}
|
|
3877
|
+
if (operation === "relatedProject.kv.setValue" && (input["value"] === void 0 || !isKanbanJsonValue(input["value"]))) {
|
|
3878
|
+
throw new Error(
|
|
3879
|
+
"Kanban bridge related-project KV value must be JSON-serializable and cannot be undefined."
|
|
3880
|
+
);
|
|
3881
|
+
}
|
|
3882
|
+
return;
|
|
3883
|
+
}
|
|
3884
|
+
case "knowledge.listDocuments":
|
|
3885
|
+
readOptionalIntegerInRange(
|
|
3886
|
+
input["pageSize"],
|
|
3887
|
+
"bridge.input.pageSize",
|
|
3888
|
+
1,
|
|
3889
|
+
MAX_KNOWLEDGE_DOCUMENT_PAGE_SIZE
|
|
3890
|
+
);
|
|
3891
|
+
readOptionalNonEmptyString(input["cursor"], "bridge.input.cursor");
|
|
3892
|
+
return;
|
|
3893
|
+
case "knowledge.getDocument":
|
|
3894
|
+
case "knowledge.deleteDocument":
|
|
3895
|
+
readNonEmptyString(input["documentId"], "bridge.input.documentId");
|
|
3896
|
+
return;
|
|
3897
|
+
case "knowledge.createDocument":
|
|
3898
|
+
readOptionalNonEmptyString(input["id"], "bridge.input.id");
|
|
3899
|
+
readNonEmptyString(input["title"], "bridge.input.title");
|
|
3900
|
+
readRequiredString(input["markdown"], "bridge.input.markdown");
|
|
3901
|
+
return;
|
|
3902
|
+
case "knowledge.editDocument":
|
|
3903
|
+
readNonEmptyString(input["documentId"], "bridge.input.documentId");
|
|
3904
|
+
if (input["title"] === void 0 && input["markdown"] === void 0) {
|
|
3905
|
+
throw new Error("Kanban bridge knowledge edit requires title or markdown.");
|
|
3906
|
+
}
|
|
3907
|
+
readOptionalStringValue(input["title"], "bridge.input.title");
|
|
3908
|
+
readOptionalStringValue(input["markdown"], "bridge.input.markdown");
|
|
3909
|
+
return;
|
|
3910
|
+
case "knowledge.searchDocuments":
|
|
3911
|
+
readNonEmptyString(input["query"], "bridge.input.query");
|
|
3912
|
+
readOptionalNonEmptyString(input["documentId"], "bridge.input.documentId");
|
|
3913
|
+
readOptionalIntegerInRange(
|
|
3914
|
+
input["beforeLines"],
|
|
3915
|
+
"bridge.input.beforeLines",
|
|
3916
|
+
0,
|
|
3917
|
+
MAX_KNOWLEDGE_CONTEXT_LINES
|
|
3918
|
+
);
|
|
3919
|
+
readOptionalIntegerInRange(
|
|
3920
|
+
input["afterLines"],
|
|
3921
|
+
"bridge.input.afterLines",
|
|
3922
|
+
0,
|
|
3923
|
+
MAX_KNOWLEDGE_CONTEXT_LINES
|
|
3924
|
+
);
|
|
3925
|
+
readOptionalIntegerInRange(
|
|
3926
|
+
input["maxMatches"],
|
|
3927
|
+
"bridge.input.maxMatches",
|
|
3928
|
+
1,
|
|
3929
|
+
MAX_KNOWLEDGE_SEARCH_PAGE_SIZE
|
|
3930
|
+
);
|
|
3931
|
+
readOptionalIntegerInRange(
|
|
3932
|
+
input["pageSize"],
|
|
3933
|
+
"bridge.input.pageSize",
|
|
3934
|
+
1,
|
|
3935
|
+
MAX_KNOWLEDGE_SEARCH_PAGE_SIZE
|
|
3936
|
+
);
|
|
3937
|
+
readOptionalNonEmptyString(input["cursor"], "bridge.input.cursor");
|
|
3938
|
+
return;
|
|
3939
|
+
case "knowledge.readDocumentLines":
|
|
3940
|
+
readNonEmptyString(input["documentId"], "bridge.input.documentId");
|
|
3941
|
+
const startLine = readPositiveInteger(input["startLine"], "bridge.input.startLine");
|
|
3942
|
+
const endLine = readPositiveInteger(input["endLine"], "bridge.input.endLine");
|
|
3943
|
+
if (endLine < startLine || endLine - startLine + 1 > MAX_KNOWLEDGE_LINE_RANGE) {
|
|
3944
|
+
throw new Error("Kanban bridge knowledge line range is invalid or too large.");
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
function isKanbanBridgeOperation(value) {
|
|
3949
|
+
return value === "runtime.getLocale" || value === "files.createFile" || value === "files.readFile" || value === "files.deleteFile" || value === "kv.getValue" || value === "kv.setValue" || value === "relatedProject.kv.getValue" || value === "relatedProject.kv.setValue" || value === "knowledge.listDocuments" || value === "knowledge.getDocument" || value === "knowledge.createDocument" || value === "knowledge.editDocument" || value === "knowledge.deleteDocument" || value === "knowledge.searchDocuments" || value === "knowledge.readDocumentLines";
|
|
3950
|
+
}
|
|
3951
|
+
function readRequiredString(value, field) {
|
|
3952
|
+
if (typeof value !== "string") throw new Error(`Kanban ${field} must be a string.`);
|
|
3953
|
+
return value;
|
|
3954
|
+
}
|
|
3955
|
+
function readOptionalStringValue(value, field) {
|
|
3956
|
+
if (value === void 0) return void 0;
|
|
3957
|
+
return readRequiredString(value, field);
|
|
3958
|
+
}
|
|
3959
|
+
function readOptionalNonEmptyString(value, field) {
|
|
3960
|
+
if (value === void 0) return void 0;
|
|
3961
|
+
return readNonEmptyString(value, field);
|
|
3962
|
+
}
|
|
3963
|
+
function readOptionalIntegerInRange(value, field, minimum, maximum) {
|
|
3964
|
+
if (value === void 0) return void 0;
|
|
3965
|
+
if (!Number.isInteger(value) || value < minimum || value > maximum) {
|
|
3966
|
+
throw new Error(`Kanban ${field} must be an integer from ${minimum} to ${maximum}.`);
|
|
3967
|
+
}
|
|
3968
|
+
return value;
|
|
3969
|
+
}
|
|
3970
|
+
function readPositiveInteger(value, field) {
|
|
3971
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
3972
|
+
throw new Error(`Kanban ${field} must be a positive integer.`);
|
|
3973
|
+
}
|
|
3974
|
+
return value;
|
|
3975
|
+
}
|
|
3976
|
+
function readNonEmptyString(value, field) {
|
|
3977
|
+
if (typeof value !== "string" || value.trim() === "") throw new Error(`kanban.json ${field} must be a non-empty string.`);
|
|
3978
|
+
return value.trim();
|
|
3979
|
+
}
|
|
3980
|
+
function isRecord2(value) {
|
|
3981
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
// src/web/ui/kanban-main.ts
|
|
3985
|
+
var app = document.querySelector("#app");
|
|
3986
|
+
var host = acquireWorkflowHost();
|
|
3987
|
+
app.classList.add("kanban-app");
|
|
3988
|
+
app.innerHTML = `
|
|
3989
|
+
<header class="toolbar"><div class="project-title"><button id="menu-toggle" class="icon-button" aria-label="\u663E\u793A\u770B\u677F\u914D\u7F6E" title="\u663E\u793A\u770B\u677F\u914D\u7F6E">${iconHtml("layout-sidebar-left")}</button><span class="project-icon">${iconHtml("layout")}</span><h1 id="kanban-title">Kanban</h1></div><div class="toolbar-actions"><div id="preview-modes" class="kanban-modes" role="group" aria-label="\u9884\u89C8\u5C3A\u5BF8"></div><button id="dimensions" class="icon-button" title="\u8C03\u6574\u9884\u89C8\u5C3A\u5BF8" aria-label="\u8C03\u6574\u9884\u89C8\u5C3A\u5BF8" hidden>${iconHtml("settings")}</button><button id="refresh" class="icon-button" title="\u5237\u65B0\u770B\u677F" aria-label="\u5237\u65B0\u770B\u677F">${iconHtml("refresh")}</button><button id="usage" class="icon-button" title="\u7CFB\u7EDF AI \u7528\u91CF" aria-label="\u7CFB\u7EDF AI \u7528\u91CF" hidden>${iconHtml("dashboard")}</button><button id="methods" class="icon-button" title="\u9875\u9762\u65B9\u6CD5" aria-label="\u9875\u9762\u65B9\u6CD5">${iconHtml("tools")}</button></div></header>
|
|
3990
|
+
<aside id="project-menu" class="project-menu" aria-label="\u770B\u677F\u914D\u7F6E"><div class="menu-heading"><span>\u770B\u677F\u914D\u7F6E</span><button id="hide-menu" class="icon-button" title="\u9690\u85CF\u770B\u677F\u914D\u7F6E" aria-label="\u9690\u85CF\u770B\u677F\u914D\u7F6E">${iconHtml("chevron-left")}</button></div><div id="configuration-editor"><div class="kanban-configuration-controls"><select id="configuration" aria-label="\u5F53\u524D\u914D\u7F6E"></select><button id="create" class="icon-button" title="\u65B0\u5EFA\u914D\u7F6E" aria-label="\u65B0\u5EFA\u914D\u7F6E">${iconHtml("add")}</button><button id="configuration-actions" class="icon-button" title="\u914D\u7F6E\u64CD\u4F5C" aria-label="\u914D\u7F6E\u64CD\u4F5C">${iconHtml("ellipsis")}</button></div><div id="save-error" class="error" hidden role="alert"><span></span><button id="retry-save" class="icon-button" title="\u91CD\u8BD5\u4FDD\u5B58" aria-label="\u91CD\u8BD5\u4FDD\u5B58">${iconHtml("refresh")}</button></div><div id="kanban-fields"></div><div id="parameter-actions"></div></div></aside>
|
|
3991
|
+
<main><div id="error" class="error" hidden role="alert"></div><div id="related-warning" class="kanban-warning" hidden role="status"></div><div id="preview-stage"><div id="preview-viewport"><iframe id="kanban-preview" title="Kanban" sandbox="allow-scripts"></iframe><button id="resize-preview" class="kanban-resize" title="\u8C03\u6574\u9884\u89C8\u5C3A\u5BF8" aria-label="\u8C03\u6574\u9884\u89C8\u5C3A\u5BF8" hidden>${iconHtml("arrow-both")}</button></div><div id="preview-status" class="kanban-status" role="status"><span class="codicon codicon-loading"></span><span>\u6B63\u5728\u52A0\u8F7D\u770B\u677F</span><button id="retry-preview" class="icon-button" title="\u91CD\u8BD5" aria-label="\u91CD\u8BD5" hidden>${iconHtml("refresh")}</button></div><div id="preview-offline" hidden></div></div></main>
|
|
3992
|
+
<dialog id="configuration-dialog" class="conversation-dialog"><header><h2>\u914D\u7F6E\u64CD\u4F5C</h2><button id="close-configurations" class="icon-button" title="\u5173\u95ED" aria-label="\u5173\u95ED">${iconHtml("close")}</button></header><div class="dialog-body configuration-command-list"></div></dialog>
|
|
3993
|
+
<dialog id="dimensions-dialog" class="conversation-dialog"><header><h2>\u9884\u89C8\u5C3A\u5BF8</h2><button id="close-dimensions" class="icon-button" title="\u5173\u95ED" aria-label="\u5173\u95ED">${iconHtml("close")}</button></header><form class="dialog-body"><label>\u5BBD\u5EA6<input id="preview-width" type="number" min="160" max="4096" required></label><label>\u9AD8\u5EA6<input id="preview-height" type="number" min="96" max="4096" required></label><div class="dimension-actions"><button id="reset-dimensions" type="button">${iconHtml("discard")}\u91CD\u7F6E</button><button type="submit">${iconHtml("check")}\u5E94\u7528</button></div></form></dialog>
|
|
3994
|
+
<dialog id="methods-dialog" class="conversation-dialog"><header><h2>\u9875\u9762\u65B9\u6CD5</h2><button id="close-methods" class="icon-button" title="\u5173\u95ED" aria-label="\u5173\u95ED">${iconHtml("close")}</button></header><div class="dialog-body"><select id="method-name" aria-label="\u9875\u9762\u65B9\u6CD5"></select><p id="method-description"></p><pre id="method-schema"></pre><label class="method-input">\u53C2\u6570 JSON<textarea id="method-args" rows="5">{}</textarea></label><button id="invoke-method" type="button">${iconHtml("play")}\u6267\u884C</button><pre id="method-result" role="status"></pre></div></dialog>`;
|
|
3995
|
+
var element = (id) => document.getElementById(id);
|
|
3996
|
+
var frame = element("kanban-preview");
|
|
3997
|
+
var dialogs = new ConversationTools();
|
|
3998
|
+
var pending = /* @__PURE__ */ new Map();
|
|
3999
|
+
var narrow = matchMedia("(max-width: 820px)");
|
|
4000
|
+
var saved = host.getState();
|
|
4001
|
+
var defaults = { phone: { width: 390, height: 844 }, tablet: { width: 768, height: 1024 }, card: { width: 360, height: 200 } };
|
|
4002
|
+
var sizes = { ...defaults, ...saved?.sizes };
|
|
4003
|
+
var mode = saved?.mode ?? "fullscreen";
|
|
4004
|
+
if (!["fullscreen", "phone", "tablet", "card"].includes(mode)) {
|
|
4005
|
+
mode = "fullscreen";
|
|
4006
|
+
}
|
|
4007
|
+
var menuOpen = saved?.menuOpen ?? !narrow.matches;
|
|
4008
|
+
var state;
|
|
4009
|
+
var project;
|
|
4010
|
+
var connected = false;
|
|
4011
|
+
var working = false;
|
|
4012
|
+
var methodWorking = false;
|
|
4013
|
+
var transitioning = false;
|
|
4014
|
+
var dirty = false;
|
|
4015
|
+
var editing = 0;
|
|
4016
|
+
var signature = "";
|
|
4017
|
+
var previewKey = "";
|
|
4018
|
+
var authRevision = -1;
|
|
4019
|
+
var values = {};
|
|
4020
|
+
var saveTimer;
|
|
4021
|
+
var readyTimer;
|
|
4022
|
+
var pendingBridge = 0;
|
|
4023
|
+
var methodSession;
|
|
4024
|
+
var methodCalls = /* @__PURE__ */ new Map();
|
|
4025
|
+
var fields = new WorkflowFields(element("kanban-fields"), element("parameter-actions"), {
|
|
4026
|
+
values: () => values,
|
|
4027
|
+
states: () => ({}),
|
|
4028
|
+
disabled: () => !connected || transitioning,
|
|
4029
|
+
loading: () => working,
|
|
4030
|
+
change: (name, value) => {
|
|
4031
|
+
values[name] = value;
|
|
4032
|
+
dirty = true;
|
|
4033
|
+
editing++;
|
|
4034
|
+
controls();
|
|
4035
|
+
clearTimeout(saveTimer);
|
|
4036
|
+
saveTimer = setTimeout(() => void save().catch(showError), 250);
|
|
4037
|
+
},
|
|
4038
|
+
file: (name) => void chooseFile(name).catch(showError),
|
|
4039
|
+
downloadFile: (id) => void downloadFile(id).catch(showError)
|
|
4040
|
+
});
|
|
4041
|
+
function persist() {
|
|
4042
|
+
host.setState({ menuOpen, mode, sizes });
|
|
4043
|
+
}
|
|
4044
|
+
function menu(open) {
|
|
4045
|
+
menuOpen = open;
|
|
4046
|
+
app.classList.toggle("menu-open", open);
|
|
4047
|
+
element("menu-toggle").hidden = open;
|
|
4048
|
+
element("menu-toggle").setAttribute("aria-expanded", String(open));
|
|
4049
|
+
persist();
|
|
4050
|
+
layoutPreview();
|
|
4051
|
+
}
|
|
4052
|
+
function request(message) {
|
|
4053
|
+
if (!connected) {
|
|
4054
|
+
return Promise.reject(new Error("\u8FDE\u63A5\u5DF2\u4E2D\u65AD\u3002"));
|
|
4055
|
+
}
|
|
4056
|
+
const requestId = crypto.randomUUID();
|
|
4057
|
+
return new Promise((resolve, reject) => {
|
|
4058
|
+
const timer = setTimeout(() => {
|
|
4059
|
+
pending.delete(requestId);
|
|
4060
|
+
reject(new Error("\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u5F53\u524D\u72B6\u6001\u3002"));
|
|
4061
|
+
}, message.call?.operation?.startsWith("files.") ? 12e4 : 2e4);
|
|
4062
|
+
pending.set(requestId, { resolve, reject, timer });
|
|
4063
|
+
host.postMessage({ projectUri: project?.uri, ...message, requestId });
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
function showError(error) {
|
|
4067
|
+
element("error").textContent = error.message ?? String(error);
|
|
4068
|
+
element("error").hidden = false;
|
|
4069
|
+
}
|
|
4070
|
+
function configurationValues(current) {
|
|
4071
|
+
const stored = current.configurations.find((item) => item.id === current.activeConfigurationId)?.values ?? {};
|
|
4072
|
+
return Object.fromEntries(current.params.map((field) => [field.name, workflowParamValue(field, stored[field.name] ?? field.defaultValue ?? "")]));
|
|
4073
|
+
}
|
|
4074
|
+
async function save() {
|
|
4075
|
+
clearTimeout(saveTimer);
|
|
4076
|
+
if (!dirty || !state || working) {
|
|
4077
|
+
return;
|
|
4078
|
+
}
|
|
4079
|
+
const version = editing, id = state.activeConfigurationId;
|
|
4080
|
+
working = true;
|
|
4081
|
+
controls();
|
|
4082
|
+
try {
|
|
4083
|
+
const encoded = Object.fromEntries(Object.entries(values).map(([name, value]) => [name, Array.isArray(value) ? JSON.stringify(value) : value]));
|
|
4084
|
+
const reply = await request({ type: "kanban-configuration", action: "save", id, revision: state.revision, values: encoded });
|
|
4085
|
+
state = reply.kanban;
|
|
4086
|
+
if (editing === version) {
|
|
4087
|
+
dirty = false;
|
|
4088
|
+
values = configurationValues(state);
|
|
4089
|
+
}
|
|
4090
|
+
inject();
|
|
4091
|
+
element("save-error").hidden = true;
|
|
4092
|
+
} catch (error) {
|
|
4093
|
+
element("save-error").querySelector("span").textContent = error.message;
|
|
4094
|
+
element("save-error").hidden = false;
|
|
4095
|
+
throw error;
|
|
4096
|
+
} finally {
|
|
4097
|
+
working = false;
|
|
4098
|
+
controls();
|
|
4099
|
+
if (dirty && connected && editing !== version) {
|
|
4100
|
+
saveTimer = setTimeout(() => void save().catch(showError), 250);
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
async function action(action2, extra = {}) {
|
|
4105
|
+
if (working || !state) {
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4108
|
+
await save();
|
|
4109
|
+
working = true;
|
|
4110
|
+
transitioning = true;
|
|
4111
|
+
controls();
|
|
4112
|
+
try {
|
|
4113
|
+
const reply = await request({ type: "kanban-configuration", action: action2, id: state.activeConfigurationId, revision: state.revision, ...extra });
|
|
4114
|
+
dirty = false;
|
|
4115
|
+
update(reply.kanban);
|
|
4116
|
+
element("error").hidden = true;
|
|
4117
|
+
} finally {
|
|
4118
|
+
working = false;
|
|
4119
|
+
transitioning = false;
|
|
4120
|
+
controls();
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
function controls() {
|
|
4124
|
+
fields.update();
|
|
4125
|
+
for (const id of ["configuration", "create", "configuration-actions", "refresh", "retry-save"]) {
|
|
4126
|
+
element(id).disabled = !connected || working;
|
|
4127
|
+
}
|
|
4128
|
+
element("methods").disabled = !connected || !methodSession?.getState().ready;
|
|
4129
|
+
element("invoke-method").disabled = !connected || methodWorking || !methodSession?.getState().methods.length;
|
|
4130
|
+
element("preview-offline").hidden = connected;
|
|
4131
|
+
app.dataset.connection = connected ? "connected" : "disconnected";
|
|
4132
|
+
app.dataset.saving = String(working || dirty);
|
|
4133
|
+
}
|
|
4134
|
+
function update(next) {
|
|
4135
|
+
if (state && next.revision < state.revision) {
|
|
4136
|
+
return;
|
|
4137
|
+
}
|
|
4138
|
+
const changed = next.activeConfigurationId !== state?.activeConfigurationId;
|
|
4139
|
+
state = next;
|
|
4140
|
+
if (changed || !dirty && !working) {
|
|
4141
|
+
values = configurationValues(next);
|
|
4142
|
+
dirty = false;
|
|
4143
|
+
}
|
|
4144
|
+
const select = element("configuration");
|
|
4145
|
+
select.replaceChildren(...next.configurations.map((item) => new Option(item.name, item.id)));
|
|
4146
|
+
select.value = next.activeConfigurationId ?? "";
|
|
4147
|
+
const nextSignature = JSON.stringify(next.params);
|
|
4148
|
+
if (signature !== nextSignature) {
|
|
4149
|
+
signature = nextSignature;
|
|
4150
|
+
fields.render({ fields: next.params });
|
|
4151
|
+
}
|
|
4152
|
+
element("configuration-editor").hidden = !next.params.length;
|
|
4153
|
+
element("related-warning").textContent = next.relatedProjectWarning || (next.missingRelatedProjectAliases.length ? `\u5173\u8054\u9879\u76EE\u4E0D\u53EF\u7528\uFF1A${next.missingRelatedProjectAliases.join(", ")}` : "");
|
|
4154
|
+
element("related-warning").hidden = !element("related-warning").textContent;
|
|
4155
|
+
if (previewKey !== next.preview.url) {
|
|
4156
|
+
mountPreview();
|
|
4157
|
+
} else {
|
|
4158
|
+
inject();
|
|
4159
|
+
}
|
|
4160
|
+
controls();
|
|
4161
|
+
}
|
|
4162
|
+
function inject() {
|
|
4163
|
+
if (!state) {
|
|
4164
|
+
return;
|
|
4165
|
+
}
|
|
4166
|
+
frame.style.colorScheme = document.documentElement.dataset.theme ?? "normal";
|
|
4167
|
+
for (const message of [
|
|
4168
|
+
{ type: "workflow-code:kanban-configuration", configuration: state.configuration },
|
|
4169
|
+
{ type: "workflow-code:kanban-theme", theme: document.documentElement.dataset.theme },
|
|
4170
|
+
{ type: "workflow-code:kanban-presentation", presentation: { mode } },
|
|
4171
|
+
...state.relatedProjectRevisions.map((item) => ({ type: "workflow-code:kanban-related-project-revision", ...item }))
|
|
4172
|
+
]) {
|
|
4173
|
+
frame.contentWindow?.postMessage({ ...message, nonce: state.preview.nonce }, "*");
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
function publishMethods() {
|
|
4177
|
+
if (connected && state && methodSession) {
|
|
4178
|
+
host.postMessage({ type: "kanban-method-state", nonce: state.preview.nonce, instanceId: methodSession.instanceId, ...methodSession.getState() });
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
function mountPreview() {
|
|
4182
|
+
if (!state) {
|
|
4183
|
+
return;
|
|
4184
|
+
}
|
|
4185
|
+
clearTimeout(readyTimer);
|
|
4186
|
+
methodSession?.close();
|
|
4187
|
+
pendingBridge = 0;
|
|
4188
|
+
previewKey = state.preview.url;
|
|
4189
|
+
methodSession = createKanbanMethodSession({ nonce: state.preview.nonce, getConfiguration: () => state?.configuration, getPresentation: () => ({ mode }), postMessage: (message) => frame.contentWindow?.postMessage(message, "*") });
|
|
4190
|
+
element("preview-status").hidden = false;
|
|
4191
|
+
element("preview-status").dataset.error = "false";
|
|
4192
|
+
element("preview-status").querySelector("span:nth-child(2)").textContent = "\u6B63\u5728\u52A0\u8F7D\u770B\u677F";
|
|
4193
|
+
element("retry-preview").hidden = true;
|
|
4194
|
+
readyTimer = setTimeout(() => {
|
|
4195
|
+
element("preview-status").dataset.error = "true";
|
|
4196
|
+
element("preview-status").querySelector("span:nth-child(2)").textContent = "\u770B\u677F\u52A0\u8F7D\u5931\u8D25";
|
|
4197
|
+
element("retry-preview").hidden = false;
|
|
4198
|
+
}, 1e4);
|
|
4199
|
+
frame.sandbox.add("allow-forms", "allow-downloads");
|
|
4200
|
+
frame.src = state.preview.url;
|
|
4201
|
+
frame.title = project?.name ?? "Kanban";
|
|
4202
|
+
layoutPreview();
|
|
4203
|
+
}
|
|
4204
|
+
frame.addEventListener("load", inject);
|
|
4205
|
+
async function downloadFile(id) {
|
|
4206
|
+
const reply = await request({ type: "kanban-bridge", nonce: state.preview.nonce, call: { requestId: crypto.randomUUID(), operation: "files.readFile", input: { fileId: id } } });
|
|
4207
|
+
if (!reply.ok) {
|
|
4208
|
+
throw new Error(reply.error.message);
|
|
4209
|
+
}
|
|
4210
|
+
const bytes = Uint8Array.from(atob(reply.value.base64), (value) => value.charCodeAt(0));
|
|
4211
|
+
const url = URL.createObjectURL(new Blob([bytes], { type: reply.value.file.mimeType }));
|
|
4212
|
+
const link = document.createElement("a");
|
|
4213
|
+
link.href = url;
|
|
4214
|
+
link.download = reply.value.file.name;
|
|
4215
|
+
link.click();
|
|
4216
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
4217
|
+
}
|
|
4218
|
+
async function chooseFile(name) {
|
|
4219
|
+
const picker = document.createElement("input");
|
|
4220
|
+
picker.type = "file";
|
|
4221
|
+
const field = state?.params.find((field2) => field2.name === name);
|
|
4222
|
+
picker.multiple = !!field?.multiple;
|
|
4223
|
+
picker.accept = field?.accept?.join(",") ?? "";
|
|
4224
|
+
picker.onchange = async () => {
|
|
4225
|
+
const id = state?.activeConfigurationId;
|
|
4226
|
+
try {
|
|
4227
|
+
const files = await Promise.all(Array.from(picker.files ?? []).map((file) => new Promise((resolve, reject) => {
|
|
4228
|
+
if (file.size > 50 * 1024 * 1024) {
|
|
4229
|
+
reject(new Error("\u6587\u4EF6\u8D85\u8FC7 50 MiB\u3002"));
|
|
4230
|
+
return;
|
|
4231
|
+
}
|
|
4232
|
+
const reader = new FileReader();
|
|
4233
|
+
reader.onerror = () => reject(reader.error);
|
|
4234
|
+
reader.onload = () => resolve({ name: file.name, mimeType: file.type || "application/octet-stream", base64: String(reader.result).split(",")[1] });
|
|
4235
|
+
reader.readAsDataURL(file);
|
|
4236
|
+
})));
|
|
4237
|
+
if (files.length > 32) {
|
|
4238
|
+
throw new Error("\u6700\u591A\u9009\u62E9 32 \u4E2A\u6587\u4EF6\u3002");
|
|
4239
|
+
}
|
|
4240
|
+
const references = [];
|
|
4241
|
+
for (const file of files) {
|
|
4242
|
+
const reply = await request({ type: "kanban-bridge", nonce: state.preview.nonce, call: { requestId: crypto.randomUUID(), operation: "files.createFile", input: file } });
|
|
4243
|
+
if (!reply.ok) {
|
|
4244
|
+
throw new Error(reply.error.message);
|
|
4245
|
+
}
|
|
4246
|
+
references.push(reply.value);
|
|
4247
|
+
}
|
|
4248
|
+
if (id !== state?.activeConfigurationId) {
|
|
4249
|
+
return;
|
|
4250
|
+
}
|
|
4251
|
+
const previous = field?.multiple ? JSON.parse(String(values[name] || "[]")) : [];
|
|
4252
|
+
values[name] = JSON.stringify([...previous, ...references]);
|
|
4253
|
+
dirty = true;
|
|
4254
|
+
editing++;
|
|
4255
|
+
fields.update();
|
|
4256
|
+
await save();
|
|
4257
|
+
} catch (error) {
|
|
4258
|
+
showError(error);
|
|
4259
|
+
}
|
|
4260
|
+
};
|
|
4261
|
+
picker.click();
|
|
4262
|
+
}
|
|
4263
|
+
function layoutPreview() {
|
|
4264
|
+
const stage = element("preview-stage"), viewport = element("preview-viewport");
|
|
4265
|
+
app.dataset.previewMode = mode;
|
|
4266
|
+
element("dimensions").hidden = mode === "fullscreen";
|
|
4267
|
+
element("resize-preview").hidden = mode === "fullscreen";
|
|
4268
|
+
for (const button of Array.from(element("preview-modes").children)) {
|
|
4269
|
+
button.setAttribute("aria-pressed", String(button.dataset.mode === mode));
|
|
4270
|
+
}
|
|
4271
|
+
if (mode === "fullscreen") {
|
|
4272
|
+
viewport.style.cssText = "";
|
|
4273
|
+
frame.style.width = "100%";
|
|
4274
|
+
frame.style.height = "100%";
|
|
4275
|
+
frame.style.transform = "";
|
|
4276
|
+
} else {
|
|
4277
|
+
const size = sizes[mode], scale = Math.min(1, Math.max(0.1, (stage.clientWidth - 24) / size.width), Math.max(0.1, (stage.clientHeight - 24) / size.height));
|
|
4278
|
+
viewport.style.width = `${size.width * scale}px`;
|
|
4279
|
+
viewport.style.height = `${size.height * scale}px`;
|
|
4280
|
+
frame.style.width = `${size.width}px`;
|
|
4281
|
+
frame.style.height = `${size.height}px`;
|
|
4282
|
+
frame.style.transform = `scale(${scale})`;
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
for (const [value, label, icon2] of [["fullscreen", "\u5168\u5C4F", "screen-full"], ["phone", "\u624B\u673A", "device-mobile"], ["tablet", "\u5E73\u677F", "device-desktop"], ["card", "\u5361\u7247", "preview"]]) {
|
|
4286
|
+
const button = iconButton(icon2, label, () => {
|
|
4287
|
+
mode = value;
|
|
4288
|
+
layoutPreview();
|
|
4289
|
+
inject();
|
|
4290
|
+
persist();
|
|
4291
|
+
});
|
|
4292
|
+
button.dataset.mode = value;
|
|
4293
|
+
element("preview-modes").append(button);
|
|
4294
|
+
}
|
|
4295
|
+
element("menu-toggle").onclick = () => menu(true);
|
|
4296
|
+
element("hide-menu").onclick = () => menu(false);
|
|
4297
|
+
element("configuration").onchange = () => {
|
|
4298
|
+
const id = element("configuration").value;
|
|
4299
|
+
void action("select", { id }).catch(showError);
|
|
4300
|
+
};
|
|
4301
|
+
element("create").onclick = () => void action("create").catch(showError);
|
|
4302
|
+
element("retry-save").onclick = () => void save().then(() => {
|
|
4303
|
+
element("error").hidden = true;
|
|
4304
|
+
}).catch(showError);
|
|
4305
|
+
element("configuration-actions").onclick = () => {
|
|
4306
|
+
const dialog = element("configuration-dialog"), body = dialog.querySelector(".dialog-body");
|
|
4307
|
+
body.replaceChildren();
|
|
4308
|
+
for (const [actionName, title, icon2] of [["rename", "\u91CD\u547D\u540D", "edit"], ["duplicate", "\u590D\u5236", "copy"], ["delete", "\u5220\u9664", "trash"]]) {
|
|
4309
|
+
const button = document.createElement("button");
|
|
4310
|
+
button.innerHTML = `${iconHtml(icon2)}<span>${title}</span>`;
|
|
4311
|
+
button.disabled = actionName === "delete" && (state?.configurations.length ?? 0) <= 1;
|
|
4312
|
+
button.onclick = async () => {
|
|
4313
|
+
dialog.close();
|
|
4314
|
+
const name = actionName === "rename" ? await requestAction({ title: "\u91CD\u547D\u540D\u914D\u7F6E", label: "\u914D\u7F6E\u540D\u79F0", value: state?.configuration.name, confirm: "\u4FDD\u5B58" }) : actionName === "delete" ? await requestAction({ title: "\u5220\u9664\u8FD9\u4E2A\u914D\u7F6E\uFF1F", confirm: "\u5220\u9664", danger: true }) : "";
|
|
4315
|
+
if (name !== void 0) {
|
|
4316
|
+
void action(actionName, { name }).catch(showError);
|
|
4317
|
+
}
|
|
4318
|
+
};
|
|
4319
|
+
body.append(button);
|
|
4320
|
+
}
|
|
4321
|
+
dialog.showModal();
|
|
4322
|
+
};
|
|
4323
|
+
element("close-configurations").onclick = () => element("configuration-dialog").close();
|
|
4324
|
+
element("refresh").onclick = element("retry-preview").onclick = () => {
|
|
4325
|
+
void (async () => {
|
|
4326
|
+
await save();
|
|
4327
|
+
const result = await request({ type: "kanban-refresh" });
|
|
4328
|
+
update(result.kanban);
|
|
4329
|
+
})().catch(showError);
|
|
4330
|
+
};
|
|
4331
|
+
element("dimensions").onclick = () => {
|
|
4332
|
+
if (mode === "fullscreen") {
|
|
4333
|
+
return;
|
|
4334
|
+
}
|
|
4335
|
+
element("preview-width").value = String(sizes[mode].width);
|
|
4336
|
+
element("preview-height").value = String(sizes[mode].height);
|
|
4337
|
+
element("dimensions-dialog").showModal();
|
|
4338
|
+
};
|
|
4339
|
+
element("close-dimensions").onclick = () => element("dimensions-dialog").close();
|
|
4340
|
+
element("dimensions-dialog").querySelector("form").onsubmit = (event) => {
|
|
4341
|
+
event.preventDefault();
|
|
4342
|
+
if (mode === "fullscreen") {
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4345
|
+
sizes[mode] = { width: Number(element("preview-width").value), height: Number(element("preview-height").value) };
|
|
4346
|
+
layoutPreview();
|
|
4347
|
+
persist();
|
|
4348
|
+
element("dimensions-dialog").close();
|
|
4349
|
+
};
|
|
4350
|
+
element("reset-dimensions").onclick = () => {
|
|
4351
|
+
if (mode !== "fullscreen") {
|
|
4352
|
+
sizes[mode] = { ...defaults[mode] };
|
|
4353
|
+
element("preview-width").value = String(sizes[mode].width);
|
|
4354
|
+
element("preview-height").value = String(sizes[mode].height);
|
|
4355
|
+
}
|
|
4356
|
+
};
|
|
4357
|
+
element("resize-preview").onpointerdown = (event) => {
|
|
4358
|
+
if (mode === "fullscreen") {
|
|
4359
|
+
return;
|
|
4360
|
+
}
|
|
4361
|
+
const selected = mode, initial = { ...sizes[selected] }, x2 = event.clientX, y2 = event.clientY, button = element("resize-preview");
|
|
4362
|
+
button.setPointerCapture(event.pointerId);
|
|
4363
|
+
button.onpointermove = (move) => {
|
|
4364
|
+
sizes[selected] = { width: Math.max(160, Math.min(4096, initial.width + move.clientX - x2)), height: Math.max(96, Math.min(4096, initial.height + move.clientY - y2)) };
|
|
4365
|
+
layoutPreview();
|
|
4366
|
+
};
|
|
4367
|
+
button.onpointerup = () => {
|
|
4368
|
+
button.onpointermove = null;
|
|
4369
|
+
persist();
|
|
4370
|
+
};
|
|
4371
|
+
};
|
|
4372
|
+
function methodDescription() {
|
|
4373
|
+
const selected = methodSession?.getState().methods.find((item) => item.name === element("method-name").value);
|
|
4374
|
+
element("method-description").textContent = selected?.description ?? "\u9875\u9762\u6682\u672A\u6CE8\u518C\u65B9\u6CD5";
|
|
4375
|
+
element("method-schema").textContent = selected ? JSON.stringify(selected.inputSchema, null, 2) : "";
|
|
4376
|
+
element("invoke-method").disabled = !selected || !connected;
|
|
4377
|
+
}
|
|
4378
|
+
element("methods").onclick = () => {
|
|
4379
|
+
element("method-name").replaceChildren(...(methodSession?.getState().methods ?? []).map((item) => new Option(item.name, item.name)));
|
|
4380
|
+
methodDescription();
|
|
4381
|
+
element("method-result").textContent = "";
|
|
4382
|
+
element("methods-dialog").showModal();
|
|
4383
|
+
};
|
|
4384
|
+
element("method-name").onchange = methodDescription;
|
|
4385
|
+
element("close-methods").onclick = () => element("methods-dialog").close();
|
|
4386
|
+
element("invoke-method").onclick = async () => {
|
|
4387
|
+
if (!connected || methodWorking) {
|
|
4388
|
+
return;
|
|
4389
|
+
}
|
|
4390
|
+
methodWorking = true;
|
|
4391
|
+
controls();
|
|
4392
|
+
try {
|
|
4393
|
+
const result = await methodSession.invoke({ instanceId: methodSession.instanceId, configurationId: state.configuration.id, method: element("method-name").value, args: JSON.parse(element("method-args").value) });
|
|
4394
|
+
element("method-result").textContent = JSON.stringify(result, null, 2);
|
|
4395
|
+
} catch (error) {
|
|
4396
|
+
element("method-result").textContent = error.message;
|
|
4397
|
+
} finally {
|
|
4398
|
+
methodWorking = false;
|
|
4399
|
+
controls();
|
|
4400
|
+
}
|
|
4401
|
+
};
|
|
4402
|
+
element("usage").onclick = () => dialogs.usage(() => host.postMessage({ type: "usage" }));
|
|
4403
|
+
window.addEventListener("message", (event) => {
|
|
4404
|
+
const message = event.data;
|
|
4405
|
+
if (event.source === frame.contentWindow) {
|
|
4406
|
+
if (!state || message?.nonce !== state.preview.nonce) {
|
|
4407
|
+
return;
|
|
4408
|
+
}
|
|
4409
|
+
methodSession?.receive(message);
|
|
4410
|
+
controls();
|
|
4411
|
+
if (message.type === KANBAN_PREVIEW_READY_MESSAGE || message.type === "workflow-code:kanban-method-catalog") {
|
|
4412
|
+
publishMethods();
|
|
4413
|
+
}
|
|
4414
|
+
if (message.type === KANBAN_PREVIEW_READY_MESSAGE) {
|
|
4415
|
+
clearTimeout(readyTimer);
|
|
4416
|
+
element("preview-status").hidden = true;
|
|
4417
|
+
frame.contentWindow?.postMessage({ type: "workflow-code:kanban-theme", nonce: state.preview.nonce, theme: document.documentElement.dataset.theme }, "*");
|
|
4418
|
+
frame.contentWindow?.postMessage({ type: "workflow-code:kanban-presentation", nonce: state.preview.nonce, presentation: { mode } }, "*");
|
|
4419
|
+
return;
|
|
4420
|
+
}
|
|
4421
|
+
if (message.type !== KANBAN_BRIDGE_REQUEST_MESSAGE) {
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
const nonce = state.preview.nonce, target = frame.contentWindow, generation = methodSession;
|
|
4425
|
+
const respond = (reply) => {
|
|
4426
|
+
if (generation === methodSession && nonce === state?.preview.nonce) {
|
|
4427
|
+
target?.postMessage({ type: KANBAN_BRIDGE_RESPONSE_MESSAGE, nonce, requestId: message.requestId, ...reply }, "*");
|
|
4428
|
+
}
|
|
4429
|
+
};
|
|
4430
|
+
if (!connected || pendingBridge >= KANBAN_BRIDGE_MAX_PENDING_REQUESTS) {
|
|
4431
|
+
respond({ ok: false, error: { code: connected ? "KANBAN_BRIDGE_BUSY" : "KANBAN_BRIDGE_UNAVAILABLE", message: "\u770B\u677F\u8FDE\u63A5\u4E0D\u53EF\u7528\u3002" } });
|
|
4432
|
+
return;
|
|
4433
|
+
}
|
|
4434
|
+
let call;
|
|
4435
|
+
try {
|
|
4436
|
+
if (Object.keys(message).some((key) => !["type", "nonce", "requestId", "operation", "input"].includes(key))) {
|
|
4437
|
+
throw new Error("Invalid request.");
|
|
4438
|
+
}
|
|
4439
|
+
call = parseKanbanBridgeCall({ requestId: message.requestId, operation: message.operation, input: message.input });
|
|
4440
|
+
} catch (error) {
|
|
4441
|
+
respond({ ok: false, error: createKanbanBridgeError(error) });
|
|
4442
|
+
return;
|
|
4443
|
+
}
|
|
4444
|
+
pendingBridge++;
|
|
4445
|
+
void request({ type: "kanban-bridge", nonce, call }).then((reply) => respond({ ok: reply.ok, value: reply.value, error: reply.error })).catch((error) => respond({ ok: false, error: createKanbanBridgeError(error) })).finally(() => {
|
|
4446
|
+
pendingBridge = Math.max(0, pendingBridge - 1);
|
|
4447
|
+
});
|
|
4448
|
+
return;
|
|
4449
|
+
}
|
|
4450
|
+
if (event.source !== null) {
|
|
4451
|
+
return;
|
|
4452
|
+
}
|
|
4453
|
+
if (!message || typeof message.type !== "string") {
|
|
4454
|
+
return;
|
|
4455
|
+
}
|
|
4456
|
+
if (message.type === "kanban-method-invoke" && message.instanceId === methodSession?.instanceId) {
|
|
4457
|
+
const abort = new AbortController();
|
|
4458
|
+
methodCalls.set(message.requestId, abort);
|
|
4459
|
+
void methodSession.invoke({ instanceId: message.instanceId, configurationId: message.configurationId, method: message.method, args: message.args }, abort.signal).then((value) => host.postMessage({ type: "kanban-method-reply", requestId: message.requestId, instanceId: message.instanceId, ok: true, value })).catch((error) => host.postMessage({ type: "kanban-method-reply", requestId: message.requestId, instanceId: message.instanceId, ok: false, error: error.message })).finally(() => methodCalls.delete(message.requestId));
|
|
4460
|
+
return;
|
|
4461
|
+
}
|
|
4462
|
+
if (message.type === "kanban-method-cancel") {
|
|
4463
|
+
methodCalls.get(message.requestId)?.abort();
|
|
4464
|
+
return;
|
|
4465
|
+
}
|
|
4466
|
+
if (message.requestId && pending.has(message.requestId)) {
|
|
4467
|
+
const waiting = pending.get(message.requestId);
|
|
4468
|
+
clearTimeout(waiting.timer);
|
|
4469
|
+
pending.delete(message.requestId);
|
|
4470
|
+
message.type === "error" ? waiting.reject(new Error(message.message)) : waiting.resolve(message);
|
|
4471
|
+
}
|
|
4472
|
+
if (message.type === "connection") {
|
|
4473
|
+
connected = message.status === "connected";
|
|
4474
|
+
controls();
|
|
4475
|
+
if (connected) {
|
|
4476
|
+
publishMethods();
|
|
4477
|
+
if (dirty) {
|
|
4478
|
+
clearTimeout(saveTimer);
|
|
4479
|
+
saveTimer = setTimeout(() => void save().catch(showError), 250);
|
|
4480
|
+
}
|
|
4481
|
+
} else {
|
|
4482
|
+
for (const waiting of pending.values()) {
|
|
4483
|
+
clearTimeout(waiting.timer);
|
|
4484
|
+
waiting.reject(new Error("\u8FDE\u63A5\u5DF2\u4E2D\u65AD\u3002"));
|
|
4485
|
+
}
|
|
4486
|
+
pending.clear();
|
|
4487
|
+
for (const call of methodCalls.values()) {
|
|
4488
|
+
call.abort();
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
if (message.type === "state") {
|
|
4493
|
+
project = message.project;
|
|
4494
|
+
element("kanban-title").textContent = project.name;
|
|
4495
|
+
if (authRevision !== message.authenticationRevision) {
|
|
4496
|
+
authRevision = message.authenticationRevision;
|
|
4497
|
+
previewKey = "";
|
|
4498
|
+
}
|
|
4499
|
+
element("usage").hidden = message.account.status !== "authenticated";
|
|
4500
|
+
update(message.kanban);
|
|
4501
|
+
}
|
|
4502
|
+
if (message.type === "usage") {
|
|
4503
|
+
dialogs.usageResult(message.usage);
|
|
4504
|
+
}
|
|
4505
|
+
if (message.type === "error" && message.requestType === "usage") {
|
|
4506
|
+
dialogs.usageResult(void 0, message.message);
|
|
4507
|
+
return;
|
|
4508
|
+
}
|
|
4509
|
+
if (message.type === "error" && !message.silent && !message.requestId) {
|
|
4510
|
+
showError(message.message);
|
|
4511
|
+
}
|
|
4512
|
+
});
|
|
4513
|
+
new ResizeObserver(layoutPreview).observe(element("preview-stage"));
|
|
4514
|
+
new MutationObserver(inject).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
|
4515
|
+
var methodHeartbeat = setInterval(publishMethods, 5e3);
|
|
4516
|
+
narrow.addEventListener("change", layoutPreview);
|
|
4517
|
+
menu(menuOpen);
|
|
4518
|
+
controls();
|
|
4519
|
+
addEventListener("pagehide", () => {
|
|
4520
|
+
methodSession?.close();
|
|
4521
|
+
clearTimeout(saveTimer);
|
|
4522
|
+
clearTimeout(readyTimer);
|
|
4523
|
+
clearInterval(methodHeartbeat);
|
|
4524
|
+
});
|
|
4525
|
+
})();
|
|
4526
|
+
/*! Bundled license information:
|
|
4527
|
+
|
|
4528
|
+
dompurify/dist/purify.es.mjs:
|
|
4529
|
+
(*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE *)
|
|
4530
|
+
*/
|