@syntrologie/adapt-chatbot 2.16.0 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChatAssistantLit.d.ts +8 -56
- package/dist/ChatAssistantLit.d.ts.map +1 -1
- package/dist/ChatAssistantLit.js +8 -389
- package/dist/ChatAssistantLit.js.map +7 -0
- package/dist/cdn.d.ts +2 -6
- package/dist/cdn.d.ts.map +1 -1
- package/dist/chunk-FI7F22ED.js +3331 -0
- package/dist/chunk-FI7F22ED.js.map +7 -0
- package/dist/chunk-V6TY7KAL.js +8 -0
- package/dist/chunk-V6TY7KAL.js.map +7 -0
- package/dist/editor-lit.d.ts +37 -0
- package/dist/editor-lit.d.ts.map +1 -0
- package/dist/editor-lit.js +134 -0
- package/dist/editor-lit.js.map +7 -0
- package/dist/runtime-lit.d.ts +3 -24
- package/dist/runtime-lit.d.ts.map +1 -1
- package/dist/runtime.d.ts +1 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +29 -40
- package/dist/runtime.js.map +7 -0
- package/dist/schema.d.ts +13 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +29 -31
- package/dist/schema.js.map +7 -0
- package/dist/types.d.ts +1 -39
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -23
- package/dist/ChatAssistant.d.ts +0 -18
- package/dist/ChatAssistant.d.ts.map +0 -1
- package/dist/ChatAssistant.js +0 -178
- package/dist/SyntroChatbot.d.ts +0 -14
- package/dist/SyntroChatbot.d.ts.map +0 -1
- package/dist/SyntroChatbot.js +0 -56
- package/dist/actionParser.d.ts +0 -15
- package/dist/actionParser.d.ts.map +0 -1
- package/dist/actionParser.js +0 -52
- package/dist/apiClient.d.ts +0 -23
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/apiClient.js +0 -51
- package/dist/cdn.js +0 -37
- package/dist/editor.d.ts +0 -17
- package/dist/editor.d.ts.map +0 -1
- package/dist/editor.js +0 -36
- package/dist/runtime-lit.js +0 -32
- package/dist/tools/bridge.d.ts +0 -26
- package/dist/tools/bridge.d.ts.map +0 -1
- package/dist/tools/bridge.js +0 -25
- package/dist/tools/expanders.d.ts +0 -17
- package/dist/tools/expanders.d.ts.map +0 -1
- package/dist/tools/expanders.js +0 -41
- package/dist/tools/index.d.ts +0 -14
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -11
- package/dist/tools/registrations/GetContextTool.d.ts +0 -7
- package/dist/tools/registrations/GetContextTool.d.ts.map +0 -1
- package/dist/tools/registrations/GetContextTool.js +0 -18
- package/dist/tools/registrations/ScrollToTool.d.ts +0 -7
- package/dist/tools/registrations/ScrollToTool.d.ts.map +0 -1
- package/dist/tools/registrations/ScrollToTool.js +0 -38
- package/dist/tools/registrations/ShowOverlayTool.d.ts +0 -7
- package/dist/tools/registrations/ShowOverlayTool.d.ts.map +0 -1
- package/dist/tools/registrations/ShowOverlayTool.js +0 -47
- package/dist/tools/registrations/index.d.ts +0 -19
- package/dist/tools/registrations/index.d.ts.map +0 -1
- package/dist/tools/registrations/index.js +0 -7
- package/dist/types.js +0 -6
- package/dist/useChat.d.ts +0 -25
- package/dist/useChat.d.ts.map +0 -1
- package/dist/useChat.js +0 -106
|
@@ -0,0 +1,3331 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-V6TY7KAL.js";
|
|
4
|
+
|
|
5
|
+
// ../../chat/dist/index.js
|
|
6
|
+
import { html as html7, LitElement, nothing as nothing5 } from "lit";
|
|
7
|
+
import { html as html2, nothing } from "lit";
|
|
8
|
+
import { html as html6, nothing as nothing4 } from "lit";
|
|
9
|
+
import { guard } from "lit/directives/guard.js";
|
|
10
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
11
|
+
import { html as html4, nothing as nothing3 } from "lit";
|
|
12
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
13
|
+
|
|
14
|
+
// ../../../node_modules/dompurify/dist/purify.es.mjs
|
|
15
|
+
var {
|
|
16
|
+
entries,
|
|
17
|
+
setPrototypeOf,
|
|
18
|
+
isFrozen,
|
|
19
|
+
getPrototypeOf,
|
|
20
|
+
getOwnPropertyDescriptor
|
|
21
|
+
} = Object;
|
|
22
|
+
var {
|
|
23
|
+
freeze,
|
|
24
|
+
seal,
|
|
25
|
+
create
|
|
26
|
+
} = Object;
|
|
27
|
+
var {
|
|
28
|
+
apply,
|
|
29
|
+
construct
|
|
30
|
+
} = typeof Reflect !== "undefined" && Reflect;
|
|
31
|
+
if (!freeze) {
|
|
32
|
+
freeze = function freeze2(x2) {
|
|
33
|
+
return x2;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (!seal) {
|
|
37
|
+
seal = function seal2(x2) {
|
|
38
|
+
return x2;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!apply) {
|
|
42
|
+
apply = function apply2(func, thisArg) {
|
|
43
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
44
|
+
args[_key - 2] = arguments[_key];
|
|
45
|
+
}
|
|
46
|
+
return func.apply(thisArg, args);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (!construct) {
|
|
50
|
+
construct = function construct2(Func) {
|
|
51
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
52
|
+
args[_key2 - 1] = arguments[_key2];
|
|
53
|
+
}
|
|
54
|
+
return new Func(...args);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var arrayForEach = unapply(Array.prototype.forEach);
|
|
58
|
+
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
59
|
+
var arrayPop = unapply(Array.prototype.pop);
|
|
60
|
+
var arrayPush = unapply(Array.prototype.push);
|
|
61
|
+
var arraySplice = unapply(Array.prototype.splice);
|
|
62
|
+
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
63
|
+
var stringToString = unapply(String.prototype.toString);
|
|
64
|
+
var stringMatch = unapply(String.prototype.match);
|
|
65
|
+
var stringReplace = unapply(String.prototype.replace);
|
|
66
|
+
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
67
|
+
var stringTrim = unapply(String.prototype.trim);
|
|
68
|
+
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
69
|
+
var regExpTest = unapply(RegExp.prototype.test);
|
|
70
|
+
var typeErrorCreate = unconstruct(TypeError);
|
|
71
|
+
function unapply(func) {
|
|
72
|
+
return function(thisArg) {
|
|
73
|
+
if (thisArg instanceof RegExp) {
|
|
74
|
+
thisArg.lastIndex = 0;
|
|
75
|
+
}
|
|
76
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
77
|
+
args[_key3 - 1] = arguments[_key3];
|
|
78
|
+
}
|
|
79
|
+
return apply(func, thisArg, args);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function unconstruct(Func) {
|
|
83
|
+
return function() {
|
|
84
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
85
|
+
args[_key4] = arguments[_key4];
|
|
86
|
+
}
|
|
87
|
+
return construct(Func, args);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function addToSet(set, array) {
|
|
91
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
92
|
+
if (setPrototypeOf) {
|
|
93
|
+
setPrototypeOf(set, null);
|
|
94
|
+
}
|
|
95
|
+
let l = array.length;
|
|
96
|
+
while (l--) {
|
|
97
|
+
let element = array[l];
|
|
98
|
+
if (typeof element === "string") {
|
|
99
|
+
const lcElement = transformCaseFunc(element);
|
|
100
|
+
if (lcElement !== element) {
|
|
101
|
+
if (!isFrozen(array)) {
|
|
102
|
+
array[l] = lcElement;
|
|
103
|
+
}
|
|
104
|
+
element = lcElement;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
set[element] = true;
|
|
108
|
+
}
|
|
109
|
+
return set;
|
|
110
|
+
}
|
|
111
|
+
function cleanArray(array) {
|
|
112
|
+
for (let index = 0; index < array.length; index++) {
|
|
113
|
+
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
114
|
+
if (!isPropertyExist) {
|
|
115
|
+
array[index] = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return array;
|
|
119
|
+
}
|
|
120
|
+
function clone(object) {
|
|
121
|
+
const newObject = create(null);
|
|
122
|
+
for (const [property, value] of entries(object)) {
|
|
123
|
+
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
124
|
+
if (isPropertyExist) {
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
newObject[property] = cleanArray(value);
|
|
127
|
+
} else if (value && typeof value === "object" && value.constructor === Object) {
|
|
128
|
+
newObject[property] = clone(value);
|
|
129
|
+
} else {
|
|
130
|
+
newObject[property] = value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return newObject;
|
|
135
|
+
}
|
|
136
|
+
function lookupGetter(object, prop) {
|
|
137
|
+
while (object !== null) {
|
|
138
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
139
|
+
if (desc) {
|
|
140
|
+
if (desc.get) {
|
|
141
|
+
return unapply(desc.get);
|
|
142
|
+
}
|
|
143
|
+
if (typeof desc.value === "function") {
|
|
144
|
+
return unapply(desc.value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
object = getPrototypeOf(object);
|
|
148
|
+
}
|
|
149
|
+
function fallbackValue() {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return fallbackValue;
|
|
153
|
+
}
|
|
154
|
+
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"]);
|
|
155
|
+
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"]);
|
|
156
|
+
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"]);
|
|
157
|
+
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"]);
|
|
158
|
+
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"]);
|
|
159
|
+
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
|
160
|
+
var text = freeze(["#text"]);
|
|
161
|
+
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"]);
|
|
162
|
+
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"]);
|
|
163
|
+
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"]);
|
|
164
|
+
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
|
165
|
+
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
|
166
|
+
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
167
|
+
var TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
|
|
168
|
+
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
169
|
+
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
170
|
+
var IS_ALLOWED_URI = seal(
|
|
171
|
+
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
172
|
+
// eslint-disable-line no-useless-escape
|
|
173
|
+
);
|
|
174
|
+
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
175
|
+
var ATTR_WHITESPACE = seal(
|
|
176
|
+
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
177
|
+
// eslint-disable-line no-control-regex
|
|
178
|
+
);
|
|
179
|
+
var DOCTYPE_NAME = seal(/^html$/i);
|
|
180
|
+
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
181
|
+
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
|
182
|
+
__proto__: null,
|
|
183
|
+
ARIA_ATTR,
|
|
184
|
+
ATTR_WHITESPACE,
|
|
185
|
+
CUSTOM_ELEMENT,
|
|
186
|
+
DATA_ATTR,
|
|
187
|
+
DOCTYPE_NAME,
|
|
188
|
+
ERB_EXPR,
|
|
189
|
+
IS_ALLOWED_URI,
|
|
190
|
+
IS_SCRIPT_OR_DATA,
|
|
191
|
+
MUSTACHE_EXPR,
|
|
192
|
+
TMPLIT_EXPR
|
|
193
|
+
});
|
|
194
|
+
var NODE_TYPE = {
|
|
195
|
+
element: 1,
|
|
196
|
+
attribute: 2,
|
|
197
|
+
text: 3,
|
|
198
|
+
cdataSection: 4,
|
|
199
|
+
entityReference: 5,
|
|
200
|
+
// Deprecated
|
|
201
|
+
entityNode: 6,
|
|
202
|
+
// Deprecated
|
|
203
|
+
progressingInstruction: 7,
|
|
204
|
+
comment: 8,
|
|
205
|
+
document: 9,
|
|
206
|
+
documentType: 10,
|
|
207
|
+
documentFragment: 11,
|
|
208
|
+
notation: 12
|
|
209
|
+
// Deprecated
|
|
210
|
+
};
|
|
211
|
+
var getGlobal = function getGlobal2() {
|
|
212
|
+
return typeof window === "undefined" ? null : window;
|
|
213
|
+
};
|
|
214
|
+
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
215
|
+
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
let suffix = null;
|
|
219
|
+
const ATTR_NAME = "data-tt-policy-suffix";
|
|
220
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
221
|
+
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
222
|
+
}
|
|
223
|
+
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
224
|
+
try {
|
|
225
|
+
return trustedTypes.createPolicy(policyName, {
|
|
226
|
+
createHTML(html8) {
|
|
227
|
+
return html8;
|
|
228
|
+
},
|
|
229
|
+
createScriptURL(scriptUrl) {
|
|
230
|
+
return scriptUrl;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
} catch (_2) {
|
|
234
|
+
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var _createHooksMap = function _createHooksMap2() {
|
|
239
|
+
return {
|
|
240
|
+
afterSanitizeAttributes: [],
|
|
241
|
+
afterSanitizeElements: [],
|
|
242
|
+
afterSanitizeShadowDOM: [],
|
|
243
|
+
beforeSanitizeAttributes: [],
|
|
244
|
+
beforeSanitizeElements: [],
|
|
245
|
+
beforeSanitizeShadowDOM: [],
|
|
246
|
+
uponSanitizeAttribute: [],
|
|
247
|
+
uponSanitizeElement: [],
|
|
248
|
+
uponSanitizeShadowNode: []
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
function createDOMPurify() {
|
|
252
|
+
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
253
|
+
const DOMPurify = (root) => createDOMPurify(root);
|
|
254
|
+
DOMPurify.version = "3.3.1";
|
|
255
|
+
DOMPurify.removed = [];
|
|
256
|
+
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
|
|
257
|
+
DOMPurify.isSupported = false;
|
|
258
|
+
return DOMPurify;
|
|
259
|
+
}
|
|
260
|
+
let {
|
|
261
|
+
document: document2
|
|
262
|
+
} = window2;
|
|
263
|
+
const originalDocument = document2;
|
|
264
|
+
const currentScript = originalDocument.currentScript;
|
|
265
|
+
const {
|
|
266
|
+
DocumentFragment,
|
|
267
|
+
HTMLTemplateElement,
|
|
268
|
+
Node,
|
|
269
|
+
Element,
|
|
270
|
+
NodeFilter,
|
|
271
|
+
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
|
272
|
+
HTMLFormElement,
|
|
273
|
+
DOMParser,
|
|
274
|
+
trustedTypes
|
|
275
|
+
} = window2;
|
|
276
|
+
const ElementPrototype = Element.prototype;
|
|
277
|
+
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
278
|
+
const remove = lookupGetter(ElementPrototype, "remove");
|
|
279
|
+
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
280
|
+
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
281
|
+
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
282
|
+
if (typeof HTMLTemplateElement === "function") {
|
|
283
|
+
const template = document2.createElement("template");
|
|
284
|
+
if (template.content && template.content.ownerDocument) {
|
|
285
|
+
document2 = template.content.ownerDocument;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let trustedTypesPolicy;
|
|
289
|
+
let emptyHTML = "";
|
|
290
|
+
const {
|
|
291
|
+
implementation,
|
|
292
|
+
createNodeIterator,
|
|
293
|
+
createDocumentFragment,
|
|
294
|
+
getElementsByTagName
|
|
295
|
+
} = document2;
|
|
296
|
+
const {
|
|
297
|
+
importNode
|
|
298
|
+
} = originalDocument;
|
|
299
|
+
let hooks = _createHooksMap();
|
|
300
|
+
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
301
|
+
const {
|
|
302
|
+
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
|
303
|
+
ERB_EXPR: ERB_EXPR2,
|
|
304
|
+
TMPLIT_EXPR: TMPLIT_EXPR2,
|
|
305
|
+
DATA_ATTR: DATA_ATTR2,
|
|
306
|
+
ARIA_ATTR: ARIA_ATTR2,
|
|
307
|
+
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
|
308
|
+
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
|
309
|
+
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
|
310
|
+
} = EXPRESSIONS;
|
|
311
|
+
let {
|
|
312
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
313
|
+
} = EXPRESSIONS;
|
|
314
|
+
let ALLOWED_TAGS = null;
|
|
315
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
316
|
+
let ALLOWED_ATTR = null;
|
|
317
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
318
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
319
|
+
tagNameCheck: {
|
|
320
|
+
writable: true,
|
|
321
|
+
configurable: false,
|
|
322
|
+
enumerable: true,
|
|
323
|
+
value: null
|
|
324
|
+
},
|
|
325
|
+
attributeNameCheck: {
|
|
326
|
+
writable: true,
|
|
327
|
+
configurable: false,
|
|
328
|
+
enumerable: true,
|
|
329
|
+
value: null
|
|
330
|
+
},
|
|
331
|
+
allowCustomizedBuiltInElements: {
|
|
332
|
+
writable: true,
|
|
333
|
+
configurable: false,
|
|
334
|
+
enumerable: true,
|
|
335
|
+
value: false
|
|
336
|
+
}
|
|
337
|
+
}));
|
|
338
|
+
let FORBID_TAGS = null;
|
|
339
|
+
let FORBID_ATTR = null;
|
|
340
|
+
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
341
|
+
tagCheck: {
|
|
342
|
+
writable: true,
|
|
343
|
+
configurable: false,
|
|
344
|
+
enumerable: true,
|
|
345
|
+
value: null
|
|
346
|
+
},
|
|
347
|
+
attributeCheck: {
|
|
348
|
+
writable: true,
|
|
349
|
+
configurable: false,
|
|
350
|
+
enumerable: true,
|
|
351
|
+
value: null
|
|
352
|
+
}
|
|
353
|
+
}));
|
|
354
|
+
let ALLOW_ARIA_ATTR = true;
|
|
355
|
+
let ALLOW_DATA_ATTR = true;
|
|
356
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
357
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
358
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
359
|
+
let SAFE_FOR_XML = true;
|
|
360
|
+
let WHOLE_DOCUMENT = false;
|
|
361
|
+
let SET_CONFIG = false;
|
|
362
|
+
let FORCE_BODY = false;
|
|
363
|
+
let RETURN_DOM = false;
|
|
364
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
365
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
366
|
+
let SANITIZE_DOM = true;
|
|
367
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
368
|
+
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
369
|
+
let KEEP_CONTENT = true;
|
|
370
|
+
let IN_PLACE = false;
|
|
371
|
+
let USE_PROFILES = {};
|
|
372
|
+
let FORBID_CONTENTS = null;
|
|
373
|
+
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"]);
|
|
374
|
+
let DATA_URI_TAGS = null;
|
|
375
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
376
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
377
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
|
378
|
+
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
379
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
380
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
381
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
382
|
+
let IS_EMPTY_INPUT = false;
|
|
383
|
+
let ALLOWED_NAMESPACES = null;
|
|
384
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
385
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
|
386
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
|
387
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
|
388
|
+
let PARSER_MEDIA_TYPE = null;
|
|
389
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
390
|
+
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
391
|
+
let transformCaseFunc = null;
|
|
392
|
+
let CONFIG = null;
|
|
393
|
+
const formElement = document2.createElement("form");
|
|
394
|
+
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
395
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
396
|
+
};
|
|
397
|
+
const _parseConfig = function _parseConfig2() {
|
|
398
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
399
|
+
if (CONFIG && CONFIG === cfg) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (!cfg || typeof cfg !== "object") {
|
|
403
|
+
cfg = {};
|
|
404
|
+
}
|
|
405
|
+
cfg = clone(cfg);
|
|
406
|
+
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
407
|
+
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
408
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
409
|
+
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
410
|
+
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
411
|
+
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
412
|
+
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;
|
|
413
|
+
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;
|
|
414
|
+
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
415
|
+
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
|
|
416
|
+
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
|
|
417
|
+
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
|
418
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
419
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
420
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
421
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
422
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
423
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
424
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
425
|
+
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
426
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
427
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
428
|
+
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
429
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
430
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
431
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
432
|
+
IN_PLACE = cfg.IN_PLACE || false;
|
|
433
|
+
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
434
|
+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
435
|
+
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
436
|
+
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
437
|
+
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
438
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
439
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
440
|
+
}
|
|
441
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
442
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
443
|
+
}
|
|
444
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
|
445
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
446
|
+
}
|
|
447
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
448
|
+
ALLOW_DATA_ATTR = false;
|
|
449
|
+
}
|
|
450
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
451
|
+
RETURN_DOM = true;
|
|
452
|
+
}
|
|
453
|
+
if (USE_PROFILES) {
|
|
454
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
455
|
+
ALLOWED_ATTR = [];
|
|
456
|
+
if (USE_PROFILES.html === true) {
|
|
457
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
458
|
+
addToSet(ALLOWED_ATTR, html);
|
|
459
|
+
}
|
|
460
|
+
if (USE_PROFILES.svg === true) {
|
|
461
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
462
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
463
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
464
|
+
}
|
|
465
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
466
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
467
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
468
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
469
|
+
}
|
|
470
|
+
if (USE_PROFILES.mathMl === true) {
|
|
471
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
472
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
473
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (cfg.ADD_TAGS) {
|
|
477
|
+
if (typeof cfg.ADD_TAGS === "function") {
|
|
478
|
+
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
479
|
+
} else {
|
|
480
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
481
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
482
|
+
}
|
|
483
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (cfg.ADD_ATTR) {
|
|
487
|
+
if (typeof cfg.ADD_ATTR === "function") {
|
|
488
|
+
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
489
|
+
} else {
|
|
490
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
491
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
492
|
+
}
|
|
493
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
497
|
+
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
498
|
+
}
|
|
499
|
+
if (cfg.FORBID_CONTENTS) {
|
|
500
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
501
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
502
|
+
}
|
|
503
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
504
|
+
}
|
|
505
|
+
if (cfg.ADD_FORBID_CONTENTS) {
|
|
506
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
507
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
508
|
+
}
|
|
509
|
+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
510
|
+
}
|
|
511
|
+
if (KEEP_CONTENT) {
|
|
512
|
+
ALLOWED_TAGS["#text"] = true;
|
|
513
|
+
}
|
|
514
|
+
if (WHOLE_DOCUMENT) {
|
|
515
|
+
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
|
516
|
+
}
|
|
517
|
+
if (ALLOWED_TAGS.table) {
|
|
518
|
+
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
519
|
+
delete FORBID_TAGS.tbody;
|
|
520
|
+
}
|
|
521
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
522
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
|
523
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
524
|
+
}
|
|
525
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
|
526
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
527
|
+
}
|
|
528
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
529
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
530
|
+
} else {
|
|
531
|
+
if (trustedTypesPolicy === void 0) {
|
|
532
|
+
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
533
|
+
}
|
|
534
|
+
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
|
535
|
+
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (freeze) {
|
|
539
|
+
freeze(cfg);
|
|
540
|
+
}
|
|
541
|
+
CONFIG = cfg;
|
|
542
|
+
};
|
|
543
|
+
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
544
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
545
|
+
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
|
546
|
+
let parent = getParentNode(element);
|
|
547
|
+
if (!parent || !parent.tagName) {
|
|
548
|
+
parent = {
|
|
549
|
+
namespaceURI: NAMESPACE,
|
|
550
|
+
tagName: "template"
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
554
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
555
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
559
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
560
|
+
return tagName === "svg";
|
|
561
|
+
}
|
|
562
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
563
|
+
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
564
|
+
}
|
|
565
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
566
|
+
}
|
|
567
|
+
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
568
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
569
|
+
return tagName === "math";
|
|
570
|
+
}
|
|
571
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
572
|
+
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
573
|
+
}
|
|
574
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
575
|
+
}
|
|
576
|
+
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
577
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
584
|
+
}
|
|
585
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
return false;
|
|
589
|
+
};
|
|
590
|
+
const _forceRemove = function _forceRemove2(node) {
|
|
591
|
+
arrayPush(DOMPurify.removed, {
|
|
592
|
+
element: node
|
|
593
|
+
});
|
|
594
|
+
try {
|
|
595
|
+
getParentNode(node).removeChild(node);
|
|
596
|
+
} catch (_2) {
|
|
597
|
+
remove(node);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const _removeAttribute = function _removeAttribute2(name, element) {
|
|
601
|
+
try {
|
|
602
|
+
arrayPush(DOMPurify.removed, {
|
|
603
|
+
attribute: element.getAttributeNode(name),
|
|
604
|
+
from: element
|
|
605
|
+
});
|
|
606
|
+
} catch (_2) {
|
|
607
|
+
arrayPush(DOMPurify.removed, {
|
|
608
|
+
attribute: null,
|
|
609
|
+
from: element
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
element.removeAttribute(name);
|
|
613
|
+
if (name === "is") {
|
|
614
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
615
|
+
try {
|
|
616
|
+
_forceRemove(element);
|
|
617
|
+
} catch (_2) {
|
|
618
|
+
}
|
|
619
|
+
} else {
|
|
620
|
+
try {
|
|
621
|
+
element.setAttribute(name, "");
|
|
622
|
+
} catch (_2) {
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const _initDocument = function _initDocument2(dirty) {
|
|
628
|
+
let doc = null;
|
|
629
|
+
let leadingWhitespace = null;
|
|
630
|
+
if (FORCE_BODY) {
|
|
631
|
+
dirty = "<remove></remove>" + dirty;
|
|
632
|
+
} else {
|
|
633
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
634
|
+
leadingWhitespace = matches && matches[0];
|
|
635
|
+
}
|
|
636
|
+
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
|
637
|
+
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
|
638
|
+
}
|
|
639
|
+
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
640
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
641
|
+
try {
|
|
642
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
643
|
+
} catch (_2) {
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (!doc || !doc.documentElement) {
|
|
647
|
+
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
648
|
+
try {
|
|
649
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
650
|
+
} catch (_2) {
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const body = doc.body || doc.documentElement;
|
|
654
|
+
if (dirty && leadingWhitespace) {
|
|
655
|
+
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
656
|
+
}
|
|
657
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
658
|
+
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
659
|
+
}
|
|
660
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
661
|
+
};
|
|
662
|
+
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
663
|
+
return createNodeIterator.call(
|
|
664
|
+
root.ownerDocument || root,
|
|
665
|
+
root,
|
|
666
|
+
// eslint-disable-next-line no-bitwise
|
|
667
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
|
668
|
+
null
|
|
669
|
+
);
|
|
670
|
+
};
|
|
671
|
+
const _isClobbered = function _isClobbered2(element) {
|
|
672
|
+
return element instanceof HTMLFormElement && (typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function");
|
|
673
|
+
};
|
|
674
|
+
const _isNode = function _isNode2(value) {
|
|
675
|
+
return typeof Node === "function" && value instanceof Node;
|
|
676
|
+
};
|
|
677
|
+
function _executeHooks(hooks2, currentNode, data) {
|
|
678
|
+
arrayForEach(hooks2, (hook) => {
|
|
679
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
683
|
+
let content = null;
|
|
684
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
685
|
+
if (_isClobbered(currentNode)) {
|
|
686
|
+
_forceRemove(currentNode);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
690
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
691
|
+
tagName,
|
|
692
|
+
allowedTags: ALLOWED_TAGS
|
|
693
|
+
});
|
|
694
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
|
|
695
|
+
_forceRemove(currentNode);
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
699
|
+
_forceRemove(currentNode);
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
703
|
+
_forceRemove(currentNode);
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
|
|
707
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
708
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
716
|
+
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
717
|
+
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
718
|
+
if (childNodes && parentNode) {
|
|
719
|
+
const childCount = childNodes.length;
|
|
720
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
721
|
+
const childClone = cloneNode(childNodes[i], true);
|
|
722
|
+
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
723
|
+
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
_forceRemove(currentNode);
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
731
|
+
_forceRemove(currentNode);
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
735
|
+
_forceRemove(currentNode);
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
739
|
+
content = currentNode.textContent;
|
|
740
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
741
|
+
content = stringReplace(content, expr, " ");
|
|
742
|
+
});
|
|
743
|
+
if (currentNode.textContent !== content) {
|
|
744
|
+
arrayPush(DOMPurify.removed, {
|
|
745
|
+
element: currentNode.cloneNode()
|
|
746
|
+
});
|
|
747
|
+
currentNode.textContent = content;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
751
|
+
return false;
|
|
752
|
+
};
|
|
753
|
+
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
|
754
|
+
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
|
758
|
+
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
|
759
|
+
else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ;
|
|
760
|
+
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
761
|
+
if (
|
|
762
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
763
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
764
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
765
|
+
_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
|
|
766
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
767
|
+
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))
|
|
768
|
+
) ;
|
|
769
|
+
else {
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
773
|
+
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
774
|
+
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
775
|
+
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
776
|
+
else if (value) {
|
|
777
|
+
return false;
|
|
778
|
+
} else ;
|
|
779
|
+
return true;
|
|
780
|
+
};
|
|
781
|
+
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
782
|
+
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
|
783
|
+
};
|
|
784
|
+
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
785
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
786
|
+
const {
|
|
787
|
+
attributes
|
|
788
|
+
} = currentNode;
|
|
789
|
+
if (!attributes || _isClobbered(currentNode)) {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const hookEvent = {
|
|
793
|
+
attrName: "",
|
|
794
|
+
attrValue: "",
|
|
795
|
+
keepAttr: true,
|
|
796
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
797
|
+
forceKeepAttr: void 0
|
|
798
|
+
};
|
|
799
|
+
let l = attributes.length;
|
|
800
|
+
while (l--) {
|
|
801
|
+
const attr = attributes[l];
|
|
802
|
+
const {
|
|
803
|
+
name,
|
|
804
|
+
namespaceURI,
|
|
805
|
+
value: attrValue
|
|
806
|
+
} = attr;
|
|
807
|
+
const lcName = transformCaseFunc(name);
|
|
808
|
+
const initValue = attrValue;
|
|
809
|
+
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
810
|
+
hookEvent.attrName = lcName;
|
|
811
|
+
hookEvent.attrValue = value;
|
|
812
|
+
hookEvent.keepAttr = true;
|
|
813
|
+
hookEvent.forceKeepAttr = void 0;
|
|
814
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
815
|
+
value = hookEvent.attrValue;
|
|
816
|
+
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
|
817
|
+
_removeAttribute(name, currentNode);
|
|
818
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
819
|
+
}
|
|
820
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
|
|
821
|
+
_removeAttribute(name, currentNode);
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
825
|
+
_removeAttribute(name, currentNode);
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
if (hookEvent.forceKeepAttr) {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (!hookEvent.keepAttr) {
|
|
832
|
+
_removeAttribute(name, currentNode);
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
836
|
+
_removeAttribute(name, currentNode);
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
840
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
841
|
+
value = stringReplace(value, expr, " ");
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
845
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
846
|
+
_removeAttribute(name, currentNode);
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
|
850
|
+
if (namespaceURI) ;
|
|
851
|
+
else {
|
|
852
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
853
|
+
case "TrustedHTML": {
|
|
854
|
+
value = trustedTypesPolicy.createHTML(value);
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
case "TrustedScriptURL": {
|
|
858
|
+
value = trustedTypesPolicy.createScriptURL(value);
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (value !== initValue) {
|
|
865
|
+
try {
|
|
866
|
+
if (namespaceURI) {
|
|
867
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
868
|
+
} else {
|
|
869
|
+
currentNode.setAttribute(name, value);
|
|
870
|
+
}
|
|
871
|
+
if (_isClobbered(currentNode)) {
|
|
872
|
+
_forceRemove(currentNode);
|
|
873
|
+
} else {
|
|
874
|
+
arrayPop(DOMPurify.removed);
|
|
875
|
+
}
|
|
876
|
+
} catch (_2) {
|
|
877
|
+
_removeAttribute(name, currentNode);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
882
|
+
};
|
|
883
|
+
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
884
|
+
let shadowNode = null;
|
|
885
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
886
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
887
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
888
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
889
|
+
_sanitizeElements(shadowNode);
|
|
890
|
+
_sanitizeAttributes(shadowNode);
|
|
891
|
+
if (shadowNode.content instanceof DocumentFragment) {
|
|
892
|
+
_sanitizeShadowDOM2(shadowNode.content);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
896
|
+
};
|
|
897
|
+
DOMPurify.sanitize = function(dirty) {
|
|
898
|
+
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
899
|
+
let body = null;
|
|
900
|
+
let importedNode = null;
|
|
901
|
+
let currentNode = null;
|
|
902
|
+
let returnNode = null;
|
|
903
|
+
IS_EMPTY_INPUT = !dirty;
|
|
904
|
+
if (IS_EMPTY_INPUT) {
|
|
905
|
+
dirty = "<!-->";
|
|
906
|
+
}
|
|
907
|
+
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
908
|
+
if (typeof dirty.toString === "function") {
|
|
909
|
+
dirty = dirty.toString();
|
|
910
|
+
if (typeof dirty !== "string") {
|
|
911
|
+
throw typeErrorCreate("dirty is not a string, aborting");
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
throw typeErrorCreate("toString is not a function");
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (!DOMPurify.isSupported) {
|
|
918
|
+
return dirty;
|
|
919
|
+
}
|
|
920
|
+
if (!SET_CONFIG) {
|
|
921
|
+
_parseConfig(cfg);
|
|
922
|
+
}
|
|
923
|
+
DOMPurify.removed = [];
|
|
924
|
+
if (typeof dirty === "string") {
|
|
925
|
+
IN_PLACE = false;
|
|
926
|
+
}
|
|
927
|
+
if (IN_PLACE) {
|
|
928
|
+
if (dirty.nodeName) {
|
|
929
|
+
const tagName = transformCaseFunc(dirty.nodeName);
|
|
930
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
931
|
+
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
} else if (dirty instanceof Node) {
|
|
935
|
+
body = _initDocument("<!---->");
|
|
936
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
937
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
|
938
|
+
body = importedNode;
|
|
939
|
+
} else if (importedNode.nodeName === "HTML") {
|
|
940
|
+
body = importedNode;
|
|
941
|
+
} else {
|
|
942
|
+
body.appendChild(importedNode);
|
|
943
|
+
}
|
|
944
|
+
} else {
|
|
945
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
946
|
+
dirty.indexOf("<") === -1) {
|
|
947
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
948
|
+
}
|
|
949
|
+
body = _initDocument(dirty);
|
|
950
|
+
if (!body) {
|
|
951
|
+
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (body && FORCE_BODY) {
|
|
955
|
+
_forceRemove(body.firstChild);
|
|
956
|
+
}
|
|
957
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
958
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
959
|
+
_sanitizeElements(currentNode);
|
|
960
|
+
_sanitizeAttributes(currentNode);
|
|
961
|
+
if (currentNode.content instanceof DocumentFragment) {
|
|
962
|
+
_sanitizeShadowDOM(currentNode.content);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
if (IN_PLACE) {
|
|
966
|
+
return dirty;
|
|
967
|
+
}
|
|
968
|
+
if (RETURN_DOM) {
|
|
969
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
970
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
971
|
+
while (body.firstChild) {
|
|
972
|
+
returnNode.appendChild(body.firstChild);
|
|
973
|
+
}
|
|
974
|
+
} else {
|
|
975
|
+
returnNode = body;
|
|
976
|
+
}
|
|
977
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
978
|
+
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
979
|
+
}
|
|
980
|
+
return returnNode;
|
|
981
|
+
}
|
|
982
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
983
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
984
|
+
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
985
|
+
}
|
|
986
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
987
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
988
|
+
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
992
|
+
};
|
|
993
|
+
DOMPurify.setConfig = function() {
|
|
994
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
995
|
+
_parseConfig(cfg);
|
|
996
|
+
SET_CONFIG = true;
|
|
997
|
+
};
|
|
998
|
+
DOMPurify.clearConfig = function() {
|
|
999
|
+
CONFIG = null;
|
|
1000
|
+
SET_CONFIG = false;
|
|
1001
|
+
};
|
|
1002
|
+
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
1003
|
+
if (!CONFIG) {
|
|
1004
|
+
_parseConfig({});
|
|
1005
|
+
}
|
|
1006
|
+
const lcTag = transformCaseFunc(tag);
|
|
1007
|
+
const lcName = transformCaseFunc(attr);
|
|
1008
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
1009
|
+
};
|
|
1010
|
+
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
1011
|
+
if (typeof hookFunction !== "function") {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
1015
|
+
};
|
|
1016
|
+
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
1017
|
+
if (hookFunction !== void 0) {
|
|
1018
|
+
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
1019
|
+
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
1020
|
+
}
|
|
1021
|
+
return arrayPop(hooks[entryPoint]);
|
|
1022
|
+
};
|
|
1023
|
+
DOMPurify.removeHooks = function(entryPoint) {
|
|
1024
|
+
hooks[entryPoint] = [];
|
|
1025
|
+
};
|
|
1026
|
+
DOMPurify.removeAllHooks = function() {
|
|
1027
|
+
hooks = _createHooksMap();
|
|
1028
|
+
};
|
|
1029
|
+
return DOMPurify;
|
|
1030
|
+
}
|
|
1031
|
+
var purify = createDOMPurify();
|
|
1032
|
+
|
|
1033
|
+
// ../../../node_modules/marked/lib/marked.esm.js
|
|
1034
|
+
function M() {
|
|
1035
|
+
return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
|
|
1036
|
+
}
|
|
1037
|
+
var T = M();
|
|
1038
|
+
function G(u3) {
|
|
1039
|
+
T = u3;
|
|
1040
|
+
}
|
|
1041
|
+
var _ = { exec: () => null };
|
|
1042
|
+
function k(u3, e = "") {
|
|
1043
|
+
let t = typeof u3 == "string" ? u3 : u3.source, n = { replace: (r, i) => {
|
|
1044
|
+
let s = typeof i == "string" ? i : i.source;
|
|
1045
|
+
return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
|
|
1046
|
+
}, getRegex: () => new RegExp(t, e) };
|
|
1047
|
+
return n;
|
|
1048
|
+
}
|
|
1049
|
+
var Re = (() => {
|
|
1050
|
+
try {
|
|
1051
|
+
return !!new RegExp("(?<=1)(?<!1)");
|
|
1052
|
+
} catch {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
})();
|
|
1056
|
+
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, 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, 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"), blockquoteBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}>`) };
|
|
1057
|
+
var Te = /^(?:[ \t]*(?:\n|$))+/;
|
|
1058
|
+
var Oe = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
1059
|
+
var we = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
1060
|
+
var A = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
1061
|
+
var ye = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
1062
|
+
var N = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
|
|
1063
|
+
var re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
1064
|
+
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();
|
|
1065
|
+
var Pe = 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();
|
|
1066
|
+
var Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
1067
|
+
var Se = /^[^\n]+/;
|
|
1068
|
+
var j = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
|
|
1069
|
+
var $e = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", j).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
|
|
1070
|
+
var _e = k(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex();
|
|
1071
|
+
var q = "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";
|
|
1072
|
+
var F = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
1073
|
+
var Le = 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", F).replace("tag", q).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
1074
|
+
var ie = k(Q).replace("hr", A).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[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", q).getRegex();
|
|
1075
|
+
var Me = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex();
|
|
1076
|
+
var U = { blockquote: Me, code: Oe, def: $e, fences: we, heading: ye, hr: A, html: Le, lheading: se, list: _e, newline: Te, paragraph: ie, table: _, text: Se };
|
|
1077
|
+
var te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", A).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[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", q).getRegex();
|
|
1078
|
+
var ze = { ...U, lheading: Pe, table: te, paragraph: k(Q).replace("hr", A).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[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", q).getRegex() };
|
|
1079
|
+
var Ee = { ...U, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", F).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: _, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(Q).replace("hr", A).replace("heading", ` *#{1,6} *[^
|
|
1080
|
+
]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
|
|
1081
|
+
var Ie = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
1082
|
+
var Ae = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
1083
|
+
var oe = /^( {2,}|\\)\n(?!\s*$)/;
|
|
1084
|
+
var Ce = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
1085
|
+
var v = /[\p{P}\p{S}]/u;
|
|
1086
|
+
var K = /[\s\p{P}\p{S}]/u;
|
|
1087
|
+
var ae = /[^\s\p{P}\p{S}]/u;
|
|
1088
|
+
var Be = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex();
|
|
1089
|
+
var le = /(?!~)[\p{P}\p{S}]/u;
|
|
1090
|
+
var De = /(?!~)[\s\p{P}\p{S}]/u;
|
|
1091
|
+
var qe = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
1092
|
+
var ue = /(?![*_])[\p{P}\p{S}]/u;
|
|
1093
|
+
var ve = /(?![*_])[\s\p{P}\p{S}]/u;
|
|
1094
|
+
var He = /(?:[^\s\p{P}\p{S}]|[*_])/u;
|
|
1095
|
+
var Ge = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Re ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
|
|
1096
|
+
var pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
|
|
1097
|
+
var Ze = k(pe, "u").replace(/punct/g, v).getRegex();
|
|
1098
|
+
var Ne = k(pe, "u").replace(/punct/g, le).getRegex();
|
|
1099
|
+
var ce = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
|
|
1100
|
+
var Qe = k(ce, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, v).getRegex();
|
|
1101
|
+
var je = k(ce, "gu").replace(/notPunctSpace/g, qe).replace(/punctSpace/g, De).replace(/punct/g, le).getRegex();
|
|
1102
|
+
var Fe = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, v).getRegex();
|
|
1103
|
+
var Ue = k(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, ue).getRegex();
|
|
1104
|
+
var Ke = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)";
|
|
1105
|
+
var We = k(Ke, "gu").replace(/notPunctSpace/g, He).replace(/punctSpace/g, ve).replace(/punct/g, ue).getRegex();
|
|
1106
|
+
var Xe = k(/\\(punct)/, "gu").replace(/punct/g, v).getRegex();
|
|
1107
|
+
var Je = 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();
|
|
1108
|
+
var Ve = k(F).replace("(?:-->|$)", "-->").getRegex();
|
|
1109
|
+
var Ye = 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", Ve).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
1110
|
+
var D = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
|
|
1111
|
+
var et = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", D).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
1112
|
+
var he = k(/^!?\[(label)\]\[(ref)\]/).replace("label", D).replace("ref", j).getRegex();
|
|
1113
|
+
var ke = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", j).getRegex();
|
|
1114
|
+
var tt = k("reflink|nolink(?!\\()", "g").replace("reflink", he).replace("nolink", ke).getRegex();
|
|
1115
|
+
var ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
|
|
1116
|
+
var W = { _backpedal: _, anyPunctuation: Xe, autolink: Je, blockSkip: Ge, br: oe, code: Ae, del: _, delLDelim: _, delRDelim: _, emStrongLDelim: Ze, emStrongRDelimAst: Qe, emStrongRDelimUnd: Fe, escape: Ie, link: et, nolink: ke, punctuation: Be, reflink: he, reflinkSearch: tt, tag: Ye, text: Ce, url: _ };
|
|
1117
|
+
var nt = { ...W, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", D).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", D).getRegex() };
|
|
1118
|
+
var Z = { ...W, emStrongRDelimAst: je, emStrongLDelim: Ne, delLDelim: Ue, delRDelim: We, 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() };
|
|
1119
|
+
var rt = { ...Z, br: k(oe).replace("{2,}", "*").getRegex(), text: k(Z.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
|
|
1120
|
+
var C = { normal: U, gfm: ze, pedantic: Ee };
|
|
1121
|
+
var z = { normal: W, gfm: Z, breaks: rt, pedantic: nt };
|
|
1122
|
+
var st = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
1123
|
+
var de = (u3) => st[u3];
|
|
1124
|
+
function O(u3, e) {
|
|
1125
|
+
if (e) {
|
|
1126
|
+
if (m.escapeTest.test(u3)) return u3.replace(m.escapeReplace, de);
|
|
1127
|
+
} else if (m.escapeTestNoEncode.test(u3)) return u3.replace(m.escapeReplaceNoEncode, de);
|
|
1128
|
+
return u3;
|
|
1129
|
+
}
|
|
1130
|
+
function X(u3) {
|
|
1131
|
+
try {
|
|
1132
|
+
u3 = encodeURI(u3).replace(m.percentDecode, "%");
|
|
1133
|
+
} catch {
|
|
1134
|
+
return null;
|
|
1135
|
+
}
|
|
1136
|
+
return u3;
|
|
1137
|
+
}
|
|
1138
|
+
function J(u3, e) {
|
|
1139
|
+
let t = u3.replace(m.findPipe, (i, s, a) => {
|
|
1140
|
+
let o = false, l = s;
|
|
1141
|
+
for (; --l >= 0 && a[l] === "\\"; ) o = !o;
|
|
1142
|
+
return o ? "|" : " |";
|
|
1143
|
+
}), n = t.split(m.splitPipe), r = 0;
|
|
1144
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
|
|
1145
|
+
else for (; n.length < e; ) n.push("");
|
|
1146
|
+
for (; r < n.length; r++) n[r] = n[r].trim().replace(m.slashPipe, "|");
|
|
1147
|
+
return n;
|
|
1148
|
+
}
|
|
1149
|
+
function E(u3, e, t) {
|
|
1150
|
+
let n = u3.length;
|
|
1151
|
+
if (n === 0) return "";
|
|
1152
|
+
let r = 0;
|
|
1153
|
+
for (; r < n; ) {
|
|
1154
|
+
let i = u3.charAt(n - r - 1);
|
|
1155
|
+
if (i === e && !t) r++;
|
|
1156
|
+
else if (i !== e && t) r++;
|
|
1157
|
+
else break;
|
|
1158
|
+
}
|
|
1159
|
+
return u3.slice(0, n - r);
|
|
1160
|
+
}
|
|
1161
|
+
function ge(u3, e) {
|
|
1162
|
+
if (u3.indexOf(e[1]) === -1) return -1;
|
|
1163
|
+
let t = 0;
|
|
1164
|
+
for (let n = 0; n < u3.length; n++) if (u3[n] === "\\") n++;
|
|
1165
|
+
else if (u3[n] === e[0]) t++;
|
|
1166
|
+
else if (u3[n] === e[1] && (t--, t < 0)) return n;
|
|
1167
|
+
return t > 0 ? -2 : -1;
|
|
1168
|
+
}
|
|
1169
|
+
function fe(u3, e = 0) {
|
|
1170
|
+
let t = e, n = "";
|
|
1171
|
+
for (let r of u3) if (r === " ") {
|
|
1172
|
+
let i = 4 - t % 4;
|
|
1173
|
+
n += " ".repeat(i), t += i;
|
|
1174
|
+
} else n += r, t++;
|
|
1175
|
+
return n;
|
|
1176
|
+
}
|
|
1177
|
+
function me(u3, e, t, n, r) {
|
|
1178
|
+
let i = e.href, s = e.title || null, a = u3[1].replace(r.other.outputLinkReplace, "$1");
|
|
1179
|
+
n.state.inLink = true;
|
|
1180
|
+
let o = { type: u3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
|
|
1181
|
+
return n.state.inLink = false, o;
|
|
1182
|
+
}
|
|
1183
|
+
function it(u3, e, t) {
|
|
1184
|
+
let n = u3.match(t.other.indentCodeCompensation);
|
|
1185
|
+
if (n === null) return e;
|
|
1186
|
+
let r = n[1];
|
|
1187
|
+
return e.split(`
|
|
1188
|
+
`).map((i) => {
|
|
1189
|
+
let s = i.match(t.other.beginningSpace);
|
|
1190
|
+
if (s === null) return i;
|
|
1191
|
+
let [a] = s;
|
|
1192
|
+
return a.length >= r.length ? i.slice(r.length) : i;
|
|
1193
|
+
}).join(`
|
|
1194
|
+
`);
|
|
1195
|
+
}
|
|
1196
|
+
var w = class {
|
|
1197
|
+
constructor(e) {
|
|
1198
|
+
__publicField(this, "options");
|
|
1199
|
+
__publicField(this, "rules");
|
|
1200
|
+
__publicField(this, "lexer");
|
|
1201
|
+
this.options = e || T;
|
|
1202
|
+
}
|
|
1203
|
+
space(e) {
|
|
1204
|
+
let t = this.rules.block.newline.exec(e);
|
|
1205
|
+
if (t && t[0].length > 0) return { type: "space", raw: t[0] };
|
|
1206
|
+
}
|
|
1207
|
+
code(e) {
|
|
1208
|
+
let t = this.rules.block.code.exec(e);
|
|
1209
|
+
if (t) {
|
|
1210
|
+
let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
1211
|
+
return { type: "code", raw: t[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : E(n, `
|
|
1212
|
+
`) };
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
fences(e) {
|
|
1216
|
+
let t = this.rules.block.fences.exec(e);
|
|
1217
|
+
if (t) {
|
|
1218
|
+
let n = t[0], r = it(n, t[3] || "", this.rules);
|
|
1219
|
+
return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: r };
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
heading(e) {
|
|
1223
|
+
let t = this.rules.block.heading.exec(e);
|
|
1224
|
+
if (t) {
|
|
1225
|
+
let n = t[2].trim();
|
|
1226
|
+
if (this.rules.other.endingHash.test(n)) {
|
|
1227
|
+
let r = E(n, "#");
|
|
1228
|
+
(this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
|
|
1229
|
+
}
|
|
1230
|
+
return { type: "heading", raw: t[0], depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
hr(e) {
|
|
1234
|
+
let t = this.rules.block.hr.exec(e);
|
|
1235
|
+
if (t) return { type: "hr", raw: E(t[0], `
|
|
1236
|
+
`) };
|
|
1237
|
+
}
|
|
1238
|
+
blockquote(e) {
|
|
1239
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
1240
|
+
if (t) {
|
|
1241
|
+
let n = E(t[0], `
|
|
1242
|
+
`).split(`
|
|
1243
|
+
`), r = "", i = "", s = [];
|
|
1244
|
+
for (; n.length > 0; ) {
|
|
1245
|
+
let a = false, o = [], l;
|
|
1246
|
+
for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = true;
|
|
1247
|
+
else if (!a) o.push(n[l]);
|
|
1248
|
+
else break;
|
|
1249
|
+
n = n.slice(l);
|
|
1250
|
+
let p = o.join(`
|
|
1251
|
+
`), c = p.replace(this.rules.other.blockquoteSetextReplace, `
|
|
1252
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
1253
|
+
r = r ? `${r}
|
|
1254
|
+
${p}` : p, i = i ? `${i}
|
|
1255
|
+
${c}` : c;
|
|
1256
|
+
let d = this.lexer.state.top;
|
|
1257
|
+
if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = d, n.length === 0) break;
|
|
1258
|
+
let h = s.at(-1);
|
|
1259
|
+
if (h?.type === "code") break;
|
|
1260
|
+
if (h?.type === "blockquote") {
|
|
1261
|
+
let R = h, f = R.raw + `
|
|
1262
|
+
` + n.join(`
|
|
1263
|
+
`), S = this.blockquote(f);
|
|
1264
|
+
s[s.length - 1] = S, r = r.substring(0, r.length - R.raw.length) + S.raw, i = i.substring(0, i.length - R.text.length) + S.text;
|
|
1265
|
+
break;
|
|
1266
|
+
} else if (h?.type === "list") {
|
|
1267
|
+
let R = h, f = R.raw + `
|
|
1268
|
+
` + n.join(`
|
|
1269
|
+
`), S = this.list(f);
|
|
1270
|
+
s[s.length - 1] = S, r = r.substring(0, r.length - h.raw.length) + S.raw, i = i.substring(0, i.length - R.raw.length) + S.raw, n = f.substring(s.at(-1).raw.length).split(`
|
|
1271
|
+
`);
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
return { type: "blockquote", raw: r, tokens: s, text: i };
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
list(e) {
|
|
1279
|
+
let t = this.rules.block.list.exec(e);
|
|
1280
|
+
if (t) {
|
|
1281
|
+
let n = t[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
|
|
1282
|
+
n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
|
|
1283
|
+
let s = this.rules.other.listItemRegex(n), a = false;
|
|
1284
|
+
for (; e; ) {
|
|
1285
|
+
let l = false, p = "", c = "";
|
|
1286
|
+
if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
|
|
1287
|
+
p = t[0], e = e.substring(p.length);
|
|
1288
|
+
let d = fe(t[2].split(`
|
|
1289
|
+
`, 1)[0], t[1].length), h = e.split(`
|
|
1290
|
+
`, 1)[0], R = !d.trim(), f = 0;
|
|
1291
|
+
if (this.options.pedantic ? (f = 2, c = d.trimStart()) : R ? f = t[1].length + 1 : (f = d.search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = d.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
|
|
1292
|
+
`, e = e.substring(h.length + 1), l = true), !l) {
|
|
1293
|
+
let S = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), xe = this.rules.other.htmlBeginRegex(f), be = this.rules.other.blockquoteBeginRegex(f);
|
|
1294
|
+
for (; e; ) {
|
|
1295
|
+
let H = e.split(`
|
|
1296
|
+
`, 1)[0], I;
|
|
1297
|
+
if (h = H, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), I = h) : I = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || xe.test(h) || be.test(h) || S.test(h) || V.test(h)) break;
|
|
1298
|
+
if (I.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) c += `
|
|
1299
|
+
` + I.slice(f);
|
|
1300
|
+
else {
|
|
1301
|
+
if (R || d.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(d) || ee.test(d) || V.test(d)) break;
|
|
1302
|
+
c += `
|
|
1303
|
+
` + h;
|
|
1304
|
+
}
|
|
1305
|
+
R = !h.trim(), p += H + `
|
|
1306
|
+
`, e = e.substring(H.length + 1), d = I.slice(f);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
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;
|
|
1310
|
+
}
|
|
1311
|
+
let o = i.items.at(-1);
|
|
1312
|
+
if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
|
|
1313
|
+
else return;
|
|
1314
|
+
i.raw = i.raw.trimEnd();
|
|
1315
|
+
for (let l of i.items) {
|
|
1316
|
+
if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
|
|
1317
|
+
if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
|
|
1318
|
+
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, "");
|
|
1319
|
+
for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
|
|
1320
|
+
this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
let p = this.rules.other.listTaskCheckbox.exec(l.raw);
|
|
1325
|
+
if (p) {
|
|
1326
|
+
let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
|
|
1327
|
+
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);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
if (!i.loose) {
|
|
1331
|
+
let p = l.tokens.filter((d) => d.type === "space"), c = p.length > 0 && p.some((d) => this.rules.other.anyLine.test(d.raw));
|
|
1332
|
+
i.loose = c;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (i.loose) for (let l of i.items) {
|
|
1336
|
+
l.loose = true;
|
|
1337
|
+
for (let p of l.tokens) p.type === "text" && (p.type = "paragraph");
|
|
1338
|
+
}
|
|
1339
|
+
return i;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
html(e) {
|
|
1343
|
+
let t = this.rules.block.html.exec(e);
|
|
1344
|
+
if (t) return { type: "html", block: true, raw: t[0], pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: t[0] };
|
|
1345
|
+
}
|
|
1346
|
+
def(e) {
|
|
1347
|
+
let t = this.rules.block.def.exec(e);
|
|
1348
|
+
if (t) {
|
|
1349
|
+
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];
|
|
1350
|
+
return { type: "def", tag: n, raw: t[0], href: r, title: i };
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
table(e) {
|
|
1354
|
+
let t = this.rules.block.table.exec(e);
|
|
1355
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
|
|
1356
|
+
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(`
|
|
1357
|
+
`) : [], s = { type: "table", raw: t[0], header: [], align: [], rows: [] };
|
|
1358
|
+
if (n.length === r.length) {
|
|
1359
|
+
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);
|
|
1360
|
+
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] });
|
|
1361
|
+
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] })));
|
|
1362
|
+
return s;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
lheading(e) {
|
|
1366
|
+
let t = this.rules.block.lheading.exec(e);
|
|
1367
|
+
if (t) return { type: "heading", raw: t[0], depth: t[2].charAt(0) === "=" ? 1 : 2, text: t[1], tokens: this.lexer.inline(t[1]) };
|
|
1368
|
+
}
|
|
1369
|
+
paragraph(e) {
|
|
1370
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
1371
|
+
if (t) {
|
|
1372
|
+
let n = t[1].charAt(t[1].length - 1) === `
|
|
1373
|
+
` ? t[1].slice(0, -1) : t[1];
|
|
1374
|
+
return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
text(e) {
|
|
1378
|
+
let t = this.rules.block.text.exec(e);
|
|
1379
|
+
if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
|
|
1380
|
+
}
|
|
1381
|
+
escape(e) {
|
|
1382
|
+
let t = this.rules.inline.escape.exec(e);
|
|
1383
|
+
if (t) return { type: "escape", raw: t[0], text: t[1] };
|
|
1384
|
+
}
|
|
1385
|
+
tag(e) {
|
|
1386
|
+
let t = this.rules.inline.tag.exec(e);
|
|
1387
|
+
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] };
|
|
1388
|
+
}
|
|
1389
|
+
link(e) {
|
|
1390
|
+
let t = this.rules.inline.link.exec(e);
|
|
1391
|
+
if (t) {
|
|
1392
|
+
let n = t[2].trim();
|
|
1393
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
|
|
1394
|
+
if (!this.rules.other.endAngleBracket.test(n)) return;
|
|
1395
|
+
let s = E(n.slice(0, -1), "\\");
|
|
1396
|
+
if ((n.length - s.length) % 2 === 0) return;
|
|
1397
|
+
} else {
|
|
1398
|
+
let s = ge(t[2], "()");
|
|
1399
|
+
if (s === -2) return;
|
|
1400
|
+
if (s > -1) {
|
|
1401
|
+
let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
|
|
1402
|
+
t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
let r = t[2], i = "";
|
|
1406
|
+
if (this.options.pedantic) {
|
|
1407
|
+
let s = this.rules.other.pedanticHrefTitle.exec(r);
|
|
1408
|
+
s && (r = s[1], i = s[3]);
|
|
1409
|
+
} else i = t[3] ? t[3].slice(1, -1) : "";
|
|
1410
|
+
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)), me(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);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
reflink(e, t) {
|
|
1414
|
+
let n;
|
|
1415
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
1416
|
+
let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t[r.toLowerCase()];
|
|
1417
|
+
if (!i) {
|
|
1418
|
+
let s = n[0].charAt(0);
|
|
1419
|
+
return { type: "text", raw: s, text: s };
|
|
1420
|
+
}
|
|
1421
|
+
return me(n, i, n[0], this.lexer, this.rules);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
emStrong(e, t, n = "") {
|
|
1425
|
+
let r = this.rules.inline.emStrongLDelim.exec(e);
|
|
1426
|
+
if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
|
|
1427
|
+
if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
1428
|
+
let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
1429
|
+
for (c.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = c.exec(t)) != null; ) {
|
|
1430
|
+
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
|
|
1431
|
+
if (o = [...a].length, r[3] || r[4]) {
|
|
1432
|
+
l += o;
|
|
1433
|
+
continue;
|
|
1434
|
+
} else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
|
|
1435
|
+
p += o;
|
|
1436
|
+
continue;
|
|
1437
|
+
}
|
|
1438
|
+
if (l -= o, l > 0) continue;
|
|
1439
|
+
o = Math.min(o, o + l + p);
|
|
1440
|
+
let d = [...r[0]][0].length, h = e.slice(0, s + r.index + d + o);
|
|
1441
|
+
if (Math.min(s, o) % 2) {
|
|
1442
|
+
let f = h.slice(1, -1);
|
|
1443
|
+
return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
|
|
1444
|
+
}
|
|
1445
|
+
let R = h.slice(2, -2);
|
|
1446
|
+
return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
codespan(e) {
|
|
1451
|
+
let t = this.rules.inline.code.exec(e);
|
|
1452
|
+
if (t) {
|
|
1453
|
+
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);
|
|
1454
|
+
return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
br(e) {
|
|
1458
|
+
let t = this.rules.inline.br.exec(e);
|
|
1459
|
+
if (t) return { type: "br", raw: t[0] };
|
|
1460
|
+
}
|
|
1461
|
+
del(e, t, n = "") {
|
|
1462
|
+
let r = this.rules.inline.delLDelim.exec(e);
|
|
1463
|
+
if (!r) return;
|
|
1464
|
+
if (!(r[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
1465
|
+
let s = [...r[0]].length - 1, a, o, l = s, p = this.rules.inline.delRDelim;
|
|
1466
|
+
for (p.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = p.exec(t)) != null; ) {
|
|
1467
|
+
if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a || (o = [...a].length, o !== s)) continue;
|
|
1468
|
+
if (r[3] || r[4]) {
|
|
1469
|
+
l += o;
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
if (l -= o, l > 0) continue;
|
|
1473
|
+
o = Math.min(o, o + l);
|
|
1474
|
+
let c = [...r[0]][0].length, d = e.slice(0, s + r.index + c + o), h = d.slice(s, -s);
|
|
1475
|
+
return { type: "del", raw: d, text: h, tokens: this.lexer.inlineTokens(h) };
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
autolink(e) {
|
|
1480
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
1481
|
+
if (t) {
|
|
1482
|
+
let n, r;
|
|
1483
|
+
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 }] };
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
url(e) {
|
|
1487
|
+
let t;
|
|
1488
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
1489
|
+
let n, r;
|
|
1490
|
+
if (t[2] === "@") n = t[0], r = "mailto:" + n;
|
|
1491
|
+
else {
|
|
1492
|
+
let i;
|
|
1493
|
+
do
|
|
1494
|
+
i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
1495
|
+
while (i !== t[0]);
|
|
1496
|
+
n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
|
|
1497
|
+
}
|
|
1498
|
+
return { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
inlineText(e) {
|
|
1502
|
+
let t = this.rules.inline.text.exec(e);
|
|
1503
|
+
if (t) {
|
|
1504
|
+
let n = this.lexer.state.inRawBlock;
|
|
1505
|
+
return { type: "text", raw: t[0], text: t[0], escaped: n };
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
var x = class u {
|
|
1510
|
+
constructor(e) {
|
|
1511
|
+
__publicField(this, "tokens");
|
|
1512
|
+
__publicField(this, "options");
|
|
1513
|
+
__publicField(this, "state");
|
|
1514
|
+
__publicField(this, "inlineQueue");
|
|
1515
|
+
__publicField(this, "tokenizer");
|
|
1516
|
+
this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new w(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
|
|
1517
|
+
let t = { other: m, block: C.normal, inline: z.normal };
|
|
1518
|
+
this.options.pedantic ? (t.block = C.pedantic, t.inline = z.pedantic) : this.options.gfm && (t.block = C.gfm, this.options.breaks ? t.inline = z.breaks : t.inline = z.gfm), this.tokenizer.rules = t;
|
|
1519
|
+
}
|
|
1520
|
+
static get rules() {
|
|
1521
|
+
return { block: C, inline: z };
|
|
1522
|
+
}
|
|
1523
|
+
static lex(e, t) {
|
|
1524
|
+
return new u(t).lex(e);
|
|
1525
|
+
}
|
|
1526
|
+
static lexInline(e, t) {
|
|
1527
|
+
return new u(t).inlineTokens(e);
|
|
1528
|
+
}
|
|
1529
|
+
lex(e) {
|
|
1530
|
+
e = e.replace(m.carriageReturn, `
|
|
1531
|
+
`), this.blockTokens(e, this.tokens);
|
|
1532
|
+
for (let t = 0; t < this.inlineQueue.length; t++) {
|
|
1533
|
+
let n = this.inlineQueue[t];
|
|
1534
|
+
this.inlineTokens(n.src, n.tokens);
|
|
1535
|
+
}
|
|
1536
|
+
return this.inlineQueue = [], this.tokens;
|
|
1537
|
+
}
|
|
1538
|
+
blockTokens(e, t = [], n = false) {
|
|
1539
|
+
for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e; ) {
|
|
1540
|
+
let r;
|
|
1541
|
+
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;
|
|
1542
|
+
if (r = this.tokenizer.space(e)) {
|
|
1543
|
+
e = e.substring(r.raw.length);
|
|
1544
|
+
let s = t.at(-1);
|
|
1545
|
+
r.raw.length === 1 && s !== void 0 ? s.raw += `
|
|
1546
|
+
` : t.push(r);
|
|
1547
|
+
continue;
|
|
1548
|
+
}
|
|
1549
|
+
if (r = this.tokenizer.code(e)) {
|
|
1550
|
+
e = e.substring(r.raw.length);
|
|
1551
|
+
let s = t.at(-1);
|
|
1552
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
1553
|
+
`) ? "" : `
|
|
1554
|
+
`) + r.raw, s.text += `
|
|
1555
|
+
` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1558
|
+
if (r = this.tokenizer.fences(e)) {
|
|
1559
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
if (r = this.tokenizer.heading(e)) {
|
|
1563
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1564
|
+
continue;
|
|
1565
|
+
}
|
|
1566
|
+
if (r = this.tokenizer.hr(e)) {
|
|
1567
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1568
|
+
continue;
|
|
1569
|
+
}
|
|
1570
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
1571
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
if (r = this.tokenizer.list(e)) {
|
|
1575
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
if (r = this.tokenizer.html(e)) {
|
|
1579
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
if (r = this.tokenizer.def(e)) {
|
|
1583
|
+
e = e.substring(r.raw.length);
|
|
1584
|
+
let s = t.at(-1);
|
|
1585
|
+
s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
1586
|
+
`) ? "" : `
|
|
1587
|
+
`) + r.raw, s.text += `
|
|
1588
|
+
` + 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));
|
|
1589
|
+
continue;
|
|
1590
|
+
}
|
|
1591
|
+
if (r = this.tokenizer.table(e)) {
|
|
1592
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
1596
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
let i = e;
|
|
1600
|
+
if (this.options.extensions?.startBlock) {
|
|
1601
|
+
let s = 1 / 0, a = e.slice(1), o;
|
|
1602
|
+
this.options.extensions.startBlock.forEach((l) => {
|
|
1603
|
+
o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
|
|
1604
|
+
}), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
|
|
1605
|
+
}
|
|
1606
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
1607
|
+
let s = t.at(-1);
|
|
1608
|
+
n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
|
|
1609
|
+
`) ? "" : `
|
|
1610
|
+
`) + r.raw, s.text += `
|
|
1611
|
+
` + 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);
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
if (r = this.tokenizer.text(e)) {
|
|
1615
|
+
e = e.substring(r.raw.length);
|
|
1616
|
+
let s = t.at(-1);
|
|
1617
|
+
s?.type === "text" ? (s.raw += (s.raw.endsWith(`
|
|
1618
|
+
`) ? "" : `
|
|
1619
|
+
`) + r.raw, s.text += `
|
|
1620
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
if (e) {
|
|
1624
|
+
let s = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
1625
|
+
if (this.options.silent) {
|
|
1626
|
+
console.error(s);
|
|
1627
|
+
break;
|
|
1628
|
+
} else throw new Error(s);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return this.state.top = true, t;
|
|
1632
|
+
}
|
|
1633
|
+
inline(e, t = []) {
|
|
1634
|
+
return this.inlineQueue.push({ src: e, tokens: t }), t;
|
|
1635
|
+
}
|
|
1636
|
+
inlineTokens(e, t = []) {
|
|
1637
|
+
let n = e, r = null;
|
|
1638
|
+
if (this.tokens.links) {
|
|
1639
|
+
let o = Object.keys(this.tokens.links);
|
|
1640
|
+
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));
|
|
1641
|
+
}
|
|
1642
|
+
for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
1643
|
+
let i;
|
|
1644
|
+
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);
|
|
1645
|
+
n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
1646
|
+
let s = false, a = "";
|
|
1647
|
+
for (; e; ) {
|
|
1648
|
+
s || (a = ""), s = false;
|
|
1649
|
+
let o;
|
|
1650
|
+
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;
|
|
1651
|
+
if (o = this.tokenizer.escape(e)) {
|
|
1652
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1655
|
+
if (o = this.tokenizer.tag(e)) {
|
|
1656
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
if (o = this.tokenizer.link(e)) {
|
|
1660
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
if (o = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
1664
|
+
e = e.substring(o.raw.length);
|
|
1665
|
+
let p = t.at(-1);
|
|
1666
|
+
o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
if (o = this.tokenizer.emStrong(e, n, a)) {
|
|
1670
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
if (o = this.tokenizer.codespan(e)) {
|
|
1674
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1675
|
+
continue;
|
|
1676
|
+
}
|
|
1677
|
+
if (o = this.tokenizer.br(e)) {
|
|
1678
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
if (o = this.tokenizer.del(e, n, a)) {
|
|
1682
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1685
|
+
if (o = this.tokenizer.autolink(e)) {
|
|
1686
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
if (!this.state.inLink && (o = this.tokenizer.url(e))) {
|
|
1690
|
+
e = e.substring(o.raw.length), t.push(o);
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
let l = e;
|
|
1694
|
+
if (this.options.extensions?.startInline) {
|
|
1695
|
+
let p = 1 / 0, c = e.slice(1), d;
|
|
1696
|
+
this.options.extensions.startInline.forEach((h) => {
|
|
1697
|
+
d = h.call({ lexer: this }, c), typeof d == "number" && d >= 0 && (p = Math.min(p, d));
|
|
1698
|
+
}), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
|
|
1699
|
+
}
|
|
1700
|
+
if (o = this.tokenizer.inlineText(l)) {
|
|
1701
|
+
e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
|
|
1702
|
+
let p = t.at(-1);
|
|
1703
|
+
p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
if (e) {
|
|
1707
|
+
let p = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
1708
|
+
if (this.options.silent) {
|
|
1709
|
+
console.error(p);
|
|
1710
|
+
break;
|
|
1711
|
+
} else throw new Error(p);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return t;
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
var y = class {
|
|
1718
|
+
constructor(e) {
|
|
1719
|
+
__publicField(this, "options");
|
|
1720
|
+
__publicField(this, "parser");
|
|
1721
|
+
this.options = e || T;
|
|
1722
|
+
}
|
|
1723
|
+
space(e) {
|
|
1724
|
+
return "";
|
|
1725
|
+
}
|
|
1726
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
1727
|
+
let r = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
|
|
1728
|
+
`;
|
|
1729
|
+
return r ? '<pre><code class="language-' + O(r) + '">' + (n ? i : O(i, true)) + `</code></pre>
|
|
1730
|
+
` : "<pre><code>" + (n ? i : O(i, true)) + `</code></pre>
|
|
1731
|
+
`;
|
|
1732
|
+
}
|
|
1733
|
+
blockquote({ tokens: e }) {
|
|
1734
|
+
return `<blockquote>
|
|
1735
|
+
${this.parser.parse(e)}</blockquote>
|
|
1736
|
+
`;
|
|
1737
|
+
}
|
|
1738
|
+
html({ text: e }) {
|
|
1739
|
+
return e;
|
|
1740
|
+
}
|
|
1741
|
+
def(e) {
|
|
1742
|
+
return "";
|
|
1743
|
+
}
|
|
1744
|
+
heading({ tokens: e, depth: t }) {
|
|
1745
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
1746
|
+
`;
|
|
1747
|
+
}
|
|
1748
|
+
hr(e) {
|
|
1749
|
+
return `<hr>
|
|
1750
|
+
`;
|
|
1751
|
+
}
|
|
1752
|
+
list(e) {
|
|
1753
|
+
let t = e.ordered, n = e.start, r = "";
|
|
1754
|
+
for (let a = 0; a < e.items.length; a++) {
|
|
1755
|
+
let o = e.items[a];
|
|
1756
|
+
r += this.listitem(o);
|
|
1757
|
+
}
|
|
1758
|
+
let i = t ? "ol" : "ul", s = t && n !== 1 ? ' start="' + n + '"' : "";
|
|
1759
|
+
return "<" + i + s + `>
|
|
1760
|
+
` + r + "</" + i + `>
|
|
1761
|
+
`;
|
|
1762
|
+
}
|
|
1763
|
+
listitem(e) {
|
|
1764
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
1765
|
+
`;
|
|
1766
|
+
}
|
|
1767
|
+
checkbox({ checked: e }) {
|
|
1768
|
+
return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
|
|
1769
|
+
}
|
|
1770
|
+
paragraph({ tokens: e }) {
|
|
1771
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
1772
|
+
`;
|
|
1773
|
+
}
|
|
1774
|
+
table(e) {
|
|
1775
|
+
let t = "", n = "";
|
|
1776
|
+
for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
|
|
1777
|
+
t += this.tablerow({ text: n });
|
|
1778
|
+
let r = "";
|
|
1779
|
+
for (let i = 0; i < e.rows.length; i++) {
|
|
1780
|
+
let s = e.rows[i];
|
|
1781
|
+
n = "";
|
|
1782
|
+
for (let a = 0; a < s.length; a++) n += this.tablecell(s[a]);
|
|
1783
|
+
r += this.tablerow({ text: n });
|
|
1784
|
+
}
|
|
1785
|
+
return r && (r = `<tbody>${r}</tbody>`), `<table>
|
|
1786
|
+
<thead>
|
|
1787
|
+
` + t + `</thead>
|
|
1788
|
+
` + r + `</table>
|
|
1789
|
+
`;
|
|
1790
|
+
}
|
|
1791
|
+
tablerow({ text: e }) {
|
|
1792
|
+
return `<tr>
|
|
1793
|
+
${e}</tr>
|
|
1794
|
+
`;
|
|
1795
|
+
}
|
|
1796
|
+
tablecell(e) {
|
|
1797
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
1798
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
1799
|
+
`;
|
|
1800
|
+
}
|
|
1801
|
+
strong({ tokens: e }) {
|
|
1802
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
1803
|
+
}
|
|
1804
|
+
em({ tokens: e }) {
|
|
1805
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
1806
|
+
}
|
|
1807
|
+
codespan({ text: e }) {
|
|
1808
|
+
return `<code>${O(e, true)}</code>`;
|
|
1809
|
+
}
|
|
1810
|
+
br(e) {
|
|
1811
|
+
return "<br>";
|
|
1812
|
+
}
|
|
1813
|
+
del({ tokens: e }) {
|
|
1814
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
1815
|
+
}
|
|
1816
|
+
link({ href: e, title: t, tokens: n }) {
|
|
1817
|
+
let r = this.parser.parseInline(n), i = X(e);
|
|
1818
|
+
if (i === null) return r;
|
|
1819
|
+
e = i;
|
|
1820
|
+
let s = '<a href="' + e + '"';
|
|
1821
|
+
return t && (s += ' title="' + O(t) + '"'), s += ">" + r + "</a>", s;
|
|
1822
|
+
}
|
|
1823
|
+
image({ href: e, title: t, text: n, tokens: r }) {
|
|
1824
|
+
r && (n = this.parser.parseInline(r, this.parser.textRenderer));
|
|
1825
|
+
let i = X(e);
|
|
1826
|
+
if (i === null) return O(n);
|
|
1827
|
+
e = i;
|
|
1828
|
+
let s = `<img src="${e}" alt="${O(n)}"`;
|
|
1829
|
+
return t && (s += ` title="${O(t)}"`), s += ">", s;
|
|
1830
|
+
}
|
|
1831
|
+
text(e) {
|
|
1832
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : O(e.text);
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
var $ = class {
|
|
1836
|
+
strong({ text: e }) {
|
|
1837
|
+
return e;
|
|
1838
|
+
}
|
|
1839
|
+
em({ text: e }) {
|
|
1840
|
+
return e;
|
|
1841
|
+
}
|
|
1842
|
+
codespan({ text: e }) {
|
|
1843
|
+
return e;
|
|
1844
|
+
}
|
|
1845
|
+
del({ text: e }) {
|
|
1846
|
+
return e;
|
|
1847
|
+
}
|
|
1848
|
+
html({ text: e }) {
|
|
1849
|
+
return e;
|
|
1850
|
+
}
|
|
1851
|
+
text({ text: e }) {
|
|
1852
|
+
return e;
|
|
1853
|
+
}
|
|
1854
|
+
link({ text: e }) {
|
|
1855
|
+
return "" + e;
|
|
1856
|
+
}
|
|
1857
|
+
image({ text: e }) {
|
|
1858
|
+
return "" + e;
|
|
1859
|
+
}
|
|
1860
|
+
br() {
|
|
1861
|
+
return "";
|
|
1862
|
+
}
|
|
1863
|
+
checkbox({ raw: e }) {
|
|
1864
|
+
return e;
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
var b = class u2 {
|
|
1868
|
+
constructor(e) {
|
|
1869
|
+
__publicField(this, "options");
|
|
1870
|
+
__publicField(this, "renderer");
|
|
1871
|
+
__publicField(this, "textRenderer");
|
|
1872
|
+
this.options = e || T, this.options.renderer = this.options.renderer || new y(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
|
|
1873
|
+
}
|
|
1874
|
+
static parse(e, t) {
|
|
1875
|
+
return new u2(t).parse(e);
|
|
1876
|
+
}
|
|
1877
|
+
static parseInline(e, t) {
|
|
1878
|
+
return new u2(t).parseInline(e);
|
|
1879
|
+
}
|
|
1880
|
+
parse(e) {
|
|
1881
|
+
let t = "";
|
|
1882
|
+
for (let n = 0; n < e.length; n++) {
|
|
1883
|
+
let r = e[n];
|
|
1884
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
1885
|
+
let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
|
|
1886
|
+
if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
|
|
1887
|
+
t += a || "";
|
|
1888
|
+
continue;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
let i = r;
|
|
1892
|
+
switch (i.type) {
|
|
1893
|
+
case "space": {
|
|
1894
|
+
t += this.renderer.space(i);
|
|
1895
|
+
break;
|
|
1896
|
+
}
|
|
1897
|
+
case "hr": {
|
|
1898
|
+
t += this.renderer.hr(i);
|
|
1899
|
+
break;
|
|
1900
|
+
}
|
|
1901
|
+
case "heading": {
|
|
1902
|
+
t += this.renderer.heading(i);
|
|
1903
|
+
break;
|
|
1904
|
+
}
|
|
1905
|
+
case "code": {
|
|
1906
|
+
t += this.renderer.code(i);
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
case "table": {
|
|
1910
|
+
t += this.renderer.table(i);
|
|
1911
|
+
break;
|
|
1912
|
+
}
|
|
1913
|
+
case "blockquote": {
|
|
1914
|
+
t += this.renderer.blockquote(i);
|
|
1915
|
+
break;
|
|
1916
|
+
}
|
|
1917
|
+
case "list": {
|
|
1918
|
+
t += this.renderer.list(i);
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
case "checkbox": {
|
|
1922
|
+
t += this.renderer.checkbox(i);
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
case "html": {
|
|
1926
|
+
t += this.renderer.html(i);
|
|
1927
|
+
break;
|
|
1928
|
+
}
|
|
1929
|
+
case "def": {
|
|
1930
|
+
t += this.renderer.def(i);
|
|
1931
|
+
break;
|
|
1932
|
+
}
|
|
1933
|
+
case "paragraph": {
|
|
1934
|
+
t += this.renderer.paragraph(i);
|
|
1935
|
+
break;
|
|
1936
|
+
}
|
|
1937
|
+
case "text": {
|
|
1938
|
+
t += this.renderer.text(i);
|
|
1939
|
+
break;
|
|
1940
|
+
}
|
|
1941
|
+
default: {
|
|
1942
|
+
let s = 'Token with "' + i.type + '" type was not found.';
|
|
1943
|
+
if (this.options.silent) return console.error(s), "";
|
|
1944
|
+
throw new Error(s);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
return t;
|
|
1949
|
+
}
|
|
1950
|
+
parseInline(e, t = this.renderer) {
|
|
1951
|
+
let n = "";
|
|
1952
|
+
for (let r = 0; r < e.length; r++) {
|
|
1953
|
+
let i = e[r];
|
|
1954
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
1955
|
+
let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
1956
|
+
if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
|
|
1957
|
+
n += a || "";
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
let s = i;
|
|
1962
|
+
switch (s.type) {
|
|
1963
|
+
case "escape": {
|
|
1964
|
+
n += t.text(s);
|
|
1965
|
+
break;
|
|
1966
|
+
}
|
|
1967
|
+
case "html": {
|
|
1968
|
+
n += t.html(s);
|
|
1969
|
+
break;
|
|
1970
|
+
}
|
|
1971
|
+
case "link": {
|
|
1972
|
+
n += t.link(s);
|
|
1973
|
+
break;
|
|
1974
|
+
}
|
|
1975
|
+
case "image": {
|
|
1976
|
+
n += t.image(s);
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
case "checkbox": {
|
|
1980
|
+
n += t.checkbox(s);
|
|
1981
|
+
break;
|
|
1982
|
+
}
|
|
1983
|
+
case "strong": {
|
|
1984
|
+
n += t.strong(s);
|
|
1985
|
+
break;
|
|
1986
|
+
}
|
|
1987
|
+
case "em": {
|
|
1988
|
+
n += t.em(s);
|
|
1989
|
+
break;
|
|
1990
|
+
}
|
|
1991
|
+
case "codespan": {
|
|
1992
|
+
n += t.codespan(s);
|
|
1993
|
+
break;
|
|
1994
|
+
}
|
|
1995
|
+
case "br": {
|
|
1996
|
+
n += t.br(s);
|
|
1997
|
+
break;
|
|
1998
|
+
}
|
|
1999
|
+
case "del": {
|
|
2000
|
+
n += t.del(s);
|
|
2001
|
+
break;
|
|
2002
|
+
}
|
|
2003
|
+
case "text": {
|
|
2004
|
+
n += t.text(s);
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
default: {
|
|
2008
|
+
let a = 'Token with "' + s.type + '" type was not found.';
|
|
2009
|
+
if (this.options.silent) return console.error(a), "";
|
|
2010
|
+
throw new Error(a);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
return n;
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
var _a;
|
|
2018
|
+
var P = (_a = class {
|
|
2019
|
+
constructor(e) {
|
|
2020
|
+
__publicField(this, "options");
|
|
2021
|
+
__publicField(this, "block");
|
|
2022
|
+
this.options = e || T;
|
|
2023
|
+
}
|
|
2024
|
+
preprocess(e) {
|
|
2025
|
+
return e;
|
|
2026
|
+
}
|
|
2027
|
+
postprocess(e) {
|
|
2028
|
+
return e;
|
|
2029
|
+
}
|
|
2030
|
+
processAllTokens(e) {
|
|
2031
|
+
return e;
|
|
2032
|
+
}
|
|
2033
|
+
emStrongMask(e) {
|
|
2034
|
+
return e;
|
|
2035
|
+
}
|
|
2036
|
+
provideLexer() {
|
|
2037
|
+
return this.block ? x.lex : x.lexInline;
|
|
2038
|
+
}
|
|
2039
|
+
provideParser() {
|
|
2040
|
+
return this.block ? b.parse : b.parseInline;
|
|
2041
|
+
}
|
|
2042
|
+
}, __publicField(_a, "passThroughHooks", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"])), __publicField(_a, "passThroughHooksRespectAsync", /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"])), _a);
|
|
2043
|
+
var B = class {
|
|
2044
|
+
constructor(...e) {
|
|
2045
|
+
__publicField(this, "defaults", M());
|
|
2046
|
+
__publicField(this, "options", this.setOptions);
|
|
2047
|
+
__publicField(this, "parse", this.parseMarkdown(true));
|
|
2048
|
+
__publicField(this, "parseInline", this.parseMarkdown(false));
|
|
2049
|
+
__publicField(this, "Parser", b);
|
|
2050
|
+
__publicField(this, "Renderer", y);
|
|
2051
|
+
__publicField(this, "TextRenderer", $);
|
|
2052
|
+
__publicField(this, "Lexer", x);
|
|
2053
|
+
__publicField(this, "Tokenizer", w);
|
|
2054
|
+
__publicField(this, "Hooks", P);
|
|
2055
|
+
this.use(...e);
|
|
2056
|
+
}
|
|
2057
|
+
walkTokens(e, t) {
|
|
2058
|
+
let n = [];
|
|
2059
|
+
for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
|
|
2060
|
+
case "table": {
|
|
2061
|
+
let i = r;
|
|
2062
|
+
for (let s of i.header) n = n.concat(this.walkTokens(s.tokens, t));
|
|
2063
|
+
for (let s of i.rows) for (let a of s) n = n.concat(this.walkTokens(a.tokens, t));
|
|
2064
|
+
break;
|
|
2065
|
+
}
|
|
2066
|
+
case "list": {
|
|
2067
|
+
let i = r;
|
|
2068
|
+
n = n.concat(this.walkTokens(i.items, t));
|
|
2069
|
+
break;
|
|
2070
|
+
}
|
|
2071
|
+
default: {
|
|
2072
|
+
let i = r;
|
|
2073
|
+
this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
|
|
2074
|
+
let a = i[s].flat(1 / 0);
|
|
2075
|
+
n = n.concat(this.walkTokens(a, t));
|
|
2076
|
+
}) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
return n;
|
|
2080
|
+
}
|
|
2081
|
+
use(...e) {
|
|
2082
|
+
let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
2083
|
+
return e.forEach((n) => {
|
|
2084
|
+
let r = { ...n };
|
|
2085
|
+
if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
|
|
2086
|
+
if (!i.name) throw new Error("extension name required");
|
|
2087
|
+
if ("renderer" in i) {
|
|
2088
|
+
let s = t.renderers[i.name];
|
|
2089
|
+
s ? t.renderers[i.name] = function(...a) {
|
|
2090
|
+
let o = i.renderer.apply(this, a);
|
|
2091
|
+
return o === false && (o = s.apply(this, a)), o;
|
|
2092
|
+
} : t.renderers[i.name] = i.renderer;
|
|
2093
|
+
}
|
|
2094
|
+
if ("tokenizer" in i) {
|
|
2095
|
+
if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
|
|
2096
|
+
let s = t[i.level];
|
|
2097
|
+
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]));
|
|
2098
|
+
}
|
|
2099
|
+
"childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
|
|
2100
|
+
}), r.extensions = t), n.renderer) {
|
|
2101
|
+
let i = this.defaults.renderer || new y(this.defaults);
|
|
2102
|
+
for (let s in n.renderer) {
|
|
2103
|
+
if (!(s in i)) throw new Error(`renderer '${s}' does not exist`);
|
|
2104
|
+
if (["options", "parser"].includes(s)) continue;
|
|
2105
|
+
let a = s, o = n.renderer[a], l = i[a];
|
|
2106
|
+
i[a] = (...p) => {
|
|
2107
|
+
let c = o.apply(i, p);
|
|
2108
|
+
return c === false && (c = l.apply(i, p)), c || "";
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
r.renderer = i;
|
|
2112
|
+
}
|
|
2113
|
+
if (n.tokenizer) {
|
|
2114
|
+
let i = this.defaults.tokenizer || new w(this.defaults);
|
|
2115
|
+
for (let s in n.tokenizer) {
|
|
2116
|
+
if (!(s in i)) throw new Error(`tokenizer '${s}' does not exist`);
|
|
2117
|
+
if (["options", "rules", "lexer"].includes(s)) continue;
|
|
2118
|
+
let a = s, o = n.tokenizer[a], l = i[a];
|
|
2119
|
+
i[a] = (...p) => {
|
|
2120
|
+
let c = o.apply(i, p);
|
|
2121
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
r.tokenizer = i;
|
|
2125
|
+
}
|
|
2126
|
+
if (n.hooks) {
|
|
2127
|
+
let i = this.defaults.hooks || new P();
|
|
2128
|
+
for (let s in n.hooks) {
|
|
2129
|
+
if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
|
|
2130
|
+
if (["options", "block"].includes(s)) continue;
|
|
2131
|
+
let a = s, o = n.hooks[a], l = i[a];
|
|
2132
|
+
P.passThroughHooks.has(s) ? i[a] = (p) => {
|
|
2133
|
+
if (this.defaults.async && P.passThroughHooksRespectAsync.has(s)) return (async () => {
|
|
2134
|
+
let d = await o.call(i, p);
|
|
2135
|
+
return l.call(i, d);
|
|
2136
|
+
})();
|
|
2137
|
+
let c = o.call(i, p);
|
|
2138
|
+
return l.call(i, c);
|
|
2139
|
+
} : i[a] = (...p) => {
|
|
2140
|
+
if (this.defaults.async) return (async () => {
|
|
2141
|
+
let d = await o.apply(i, p);
|
|
2142
|
+
return d === false && (d = await l.apply(i, p)), d;
|
|
2143
|
+
})();
|
|
2144
|
+
let c = o.apply(i, p);
|
|
2145
|
+
return c === false && (c = l.apply(i, p)), c;
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
r.hooks = i;
|
|
2149
|
+
}
|
|
2150
|
+
if (n.walkTokens) {
|
|
2151
|
+
let i = this.defaults.walkTokens, s = n.walkTokens;
|
|
2152
|
+
r.walkTokens = function(a) {
|
|
2153
|
+
let o = [];
|
|
2154
|
+
return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
this.defaults = { ...this.defaults, ...r };
|
|
2158
|
+
}), this;
|
|
2159
|
+
}
|
|
2160
|
+
setOptions(e) {
|
|
2161
|
+
return this.defaults = { ...this.defaults, ...e }, this;
|
|
2162
|
+
}
|
|
2163
|
+
lexer(e, t) {
|
|
2164
|
+
return x.lex(e, t ?? this.defaults);
|
|
2165
|
+
}
|
|
2166
|
+
parser(e, t) {
|
|
2167
|
+
return b.parse(e, t ?? this.defaults);
|
|
2168
|
+
}
|
|
2169
|
+
parseMarkdown(e) {
|
|
2170
|
+
return (n, r) => {
|
|
2171
|
+
let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
|
|
2172
|
+
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."));
|
|
2173
|
+
if (typeof n > "u" || n === null) return a(new Error("marked(): input parameter is undefined or null"));
|
|
2174
|
+
if (typeof n != "string") return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
2175
|
+
if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async) return (async () => {
|
|
2176
|
+
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;
|
|
2177
|
+
s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
|
|
2178
|
+
let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
|
|
2179
|
+
return s.hooks ? await s.hooks.postprocess(h) : h;
|
|
2180
|
+
})().catch(a);
|
|
2181
|
+
try {
|
|
2182
|
+
s.hooks && (n = s.hooks.preprocess(n));
|
|
2183
|
+
let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
|
|
2184
|
+
s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
|
|
2185
|
+
let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
|
|
2186
|
+
return s.hooks && (c = s.hooks.postprocess(c)), c;
|
|
2187
|
+
} catch (o) {
|
|
2188
|
+
return a(o);
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
onError(e, t) {
|
|
2193
|
+
return (n) => {
|
|
2194
|
+
if (n.message += `
|
|
2195
|
+
Please report this to https://github.com/markedjs/marked.`, e) {
|
|
2196
|
+
let r = "<p>An error occurred:</p><pre>" + O(n.message + "", true) + "</pre>";
|
|
2197
|
+
return t ? Promise.resolve(r) : r;
|
|
2198
|
+
}
|
|
2199
|
+
if (t) return Promise.reject(n);
|
|
2200
|
+
throw n;
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
var L = new B();
|
|
2205
|
+
function g(u3, e) {
|
|
2206
|
+
return L.parse(u3, e);
|
|
2207
|
+
}
|
|
2208
|
+
g.options = g.setOptions = function(u3) {
|
|
2209
|
+
return L.setOptions(u3), g.defaults = L.defaults, G(g.defaults), g;
|
|
2210
|
+
};
|
|
2211
|
+
g.getDefaults = M;
|
|
2212
|
+
g.defaults = T;
|
|
2213
|
+
g.use = function(...u3) {
|
|
2214
|
+
return L.use(...u3), g.defaults = L.defaults, G(g.defaults), g;
|
|
2215
|
+
};
|
|
2216
|
+
g.walkTokens = function(u3, e) {
|
|
2217
|
+
return L.walkTokens(u3, e);
|
|
2218
|
+
};
|
|
2219
|
+
g.parseInline = L.parseInline;
|
|
2220
|
+
g.Parser = b;
|
|
2221
|
+
g.parser = b.parse;
|
|
2222
|
+
g.Renderer = y;
|
|
2223
|
+
g.TextRenderer = $;
|
|
2224
|
+
g.Lexer = x;
|
|
2225
|
+
g.lexer = x.lex;
|
|
2226
|
+
g.Tokenizer = w;
|
|
2227
|
+
g.Hooks = P;
|
|
2228
|
+
g.parse = g;
|
|
2229
|
+
var Ut = g.options;
|
|
2230
|
+
var Kt = g.setOptions;
|
|
2231
|
+
var Wt = g.use;
|
|
2232
|
+
var Xt = g.walkTokens;
|
|
2233
|
+
var Jt = g.parseInline;
|
|
2234
|
+
var Yt = b.parse;
|
|
2235
|
+
var en = x.lex;
|
|
2236
|
+
|
|
2237
|
+
// ../../chat/dist/index.js
|
|
2238
|
+
import { html as html22 } from "lit";
|
|
2239
|
+
import { html as html3, nothing as nothing2 } from "lit";
|
|
2240
|
+
import { html as html5 } from "lit";
|
|
2241
|
+
var sendIcon = html2`<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 14V2M8 2L3 7M8 2L13 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
2242
|
+
var stopIcon = html2`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><rect x="1" y="1" width="12" height="12" rx="2" fill="currentColor"/></svg>`;
|
|
2243
|
+
function autoResize(e) {
|
|
2244
|
+
const el = e.target;
|
|
2245
|
+
el.style.height = "auto";
|
|
2246
|
+
el.style.height = `${Math.min(el.scrollHeight, 150)}px`;
|
|
2247
|
+
}
|
|
2248
|
+
function renderChatInput(props) {
|
|
2249
|
+
const canSend = props.value.trim().length > 0 && !props.isStreaming;
|
|
2250
|
+
const buttonLabel = props.isStreaming ? "Stop generation" : "Send message";
|
|
2251
|
+
const buttonAction = props.isStreaming ? props.onStop : props.onSend;
|
|
2252
|
+
const handleInput = (e) => {
|
|
2253
|
+
autoResize(e);
|
|
2254
|
+
props.onInput(e);
|
|
2255
|
+
};
|
|
2256
|
+
return html2`
|
|
2257
|
+
${props.suggestions?.length && !props.isStreaming ? html2`<div data-sc-suggestions>
|
|
2258
|
+
${props.suggestions.map(
|
|
2259
|
+
(s) => html2`<button @click=${() => props.onSuggestion?.(s)}>${s}</button>`
|
|
2260
|
+
)}
|
|
2261
|
+
</div>` : nothing}
|
|
2262
|
+
${props.beforeInputSlot ?? nothing}
|
|
2263
|
+
<div data-sc-chat-input>
|
|
2264
|
+
<textarea
|
|
2265
|
+
rows="1"
|
|
2266
|
+
placeholder="Type a message..."
|
|
2267
|
+
.value=${props.value}
|
|
2268
|
+
@input=${handleInput}
|
|
2269
|
+
@keydown=${props.onKeyDown}
|
|
2270
|
+
@compositionstart=${props.onCompositionStart}
|
|
2271
|
+
@compositionend=${props.onCompositionEnd}
|
|
2272
|
+
aria-label="Message input"
|
|
2273
|
+
></textarea>
|
|
2274
|
+
${props.inputActionsSlot ?? nothing}
|
|
2275
|
+
<button
|
|
2276
|
+
data-sc-send-btn
|
|
2277
|
+
?disabled=${!canSend && !props.isStreaming}
|
|
2278
|
+
@click=${buttonAction}
|
|
2279
|
+
aria-label=${buttonLabel}
|
|
2280
|
+
>${props.isStreaming ? stopIcon : sendIcon}</button>
|
|
2281
|
+
</div>
|
|
2282
|
+
`;
|
|
2283
|
+
}
|
|
2284
|
+
function fingerprint(msg) {
|
|
2285
|
+
const tcIds = msg.toolCalls?.map((tc) => `${tc.id}:${tc.status}`).join(",") ?? "";
|
|
2286
|
+
return `${msg.id}:${msg.role}:${msg.content.length}:${msg.status}:${tcIds}`;
|
|
2287
|
+
}
|
|
2288
|
+
var marked = new B({ async: false, gfm: true, breaks: true });
|
|
2289
|
+
function escapeAttr(s) {
|
|
2290
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
2291
|
+
}
|
|
2292
|
+
var codeRenderer = {
|
|
2293
|
+
code({ text: text2, lang }) {
|
|
2294
|
+
const safeLang = lang ? escapeAttr(lang) : "";
|
|
2295
|
+
const langAttr = safeLang ? ` class="language-${safeLang}"` : "";
|
|
2296
|
+
return `<div data-sc-code-block${safeLang ? ` data-lang="${safeLang}"` : ""}><pre><code${langAttr}>${text2}</code></pre></div>
|
|
2297
|
+
`;
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
marked.use({ renderer: codeRenderer });
|
|
2301
|
+
function renderMarkdown(text2) {
|
|
2302
|
+
if (!text2) return "";
|
|
2303
|
+
const raw = marked.parse(text2);
|
|
2304
|
+
if (typeof window === "undefined") return raw;
|
|
2305
|
+
return purify.sanitize(raw, {
|
|
2306
|
+
ADD_ATTR: ["data-sc-code-block", "data-lang", "data-sc-copy-btn"]
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
var copyIcon = html22`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><rect x="4.5" y="0.5" width="9" height="9" rx="1.5" stroke="currentColor"/><rect x="0.5" y="4.5" width="9" height="9" rx="1.5" stroke="currentColor" fill="var(--sc-chat-action-bar-bg, rgba(0,0,0,0.05))"/></svg>`;
|
|
2310
|
+
var regenerateIcon = html22`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M1.5 7a5.5 5.5 0 0 1 9.9-3.3M12.5 7a5.5 5.5 0 0 1-9.9 3.3" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/><path d="M11.5 1v3h-3M2.5 13v-3h3" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
2311
|
+
function renderActionBar(props) {
|
|
2312
|
+
const showRegenerate = props.role === "assistant" && props.onRegenerate;
|
|
2313
|
+
return html22`
|
|
2314
|
+
<div data-sc-action-bar>
|
|
2315
|
+
<button
|
|
2316
|
+
@click=${() => props.onCopy(props.content)}
|
|
2317
|
+
aria-label="Copy message"
|
|
2318
|
+
title="Copy"
|
|
2319
|
+
>${copyIcon}</button>
|
|
2320
|
+
${showRegenerate ? html22`<button
|
|
2321
|
+
@click=${() => props.onRegenerate(props.messageId)}
|
|
2322
|
+
aria-label="Regenerate response"
|
|
2323
|
+
title="Regenerate"
|
|
2324
|
+
>${regenerateIcon}</button>` : ""}
|
|
2325
|
+
</div>
|
|
2326
|
+
`;
|
|
2327
|
+
}
|
|
2328
|
+
var spinnerIcon = html3`<svg data-sc-spinner width="14" height="14" viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5.5" stroke="currentColor" stroke-width="1.5" opacity="0.2"/><path d="M12.5 7a5.5 5.5 0 0 0-5.5-5.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>`;
|
|
2329
|
+
var checkIcon = html3`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M3 7.5L6 10.5L11 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
2330
|
+
var errorIcon = html3`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="6" stroke="currentColor" stroke-width="1.3"/><path d="M5 5l4 4M9 5l-4 4" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>`;
|
|
2331
|
+
var toolIcon = html3`<svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M8.5 2.5l3 3-7.5 7.5H1v-3l7.5-7.5z" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
2332
|
+
function statusIcon(status) {
|
|
2333
|
+
switch (status) {
|
|
2334
|
+
case "args-streaming":
|
|
2335
|
+
case "running":
|
|
2336
|
+
return spinnerIcon;
|
|
2337
|
+
case "done":
|
|
2338
|
+
return checkIcon;
|
|
2339
|
+
case "error":
|
|
2340
|
+
return errorIcon;
|
|
2341
|
+
default:
|
|
2342
|
+
return toolIcon;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
function renderToolCallCard(props) {
|
|
2346
|
+
const { toolCall, toolLabel, approve, deny } = props;
|
|
2347
|
+
const displayName = toolLabel ?? toolCall.name;
|
|
2348
|
+
const isActive = toolCall.status === "args-streaming" || toolCall.status === "running";
|
|
2349
|
+
return html3`
|
|
2350
|
+
<div data-sc-tool-card ?data-sc-active=${isActive}>
|
|
2351
|
+
<div data-sc-tool-header>
|
|
2352
|
+
<span data-sc-tool-icon data-sc-status=${toolCall.status}>${statusIcon(toolCall.status)}</span>
|
|
2353
|
+
<span data-sc-tool-name>${displayName}</span>
|
|
2354
|
+
</div>
|
|
2355
|
+
${toolCall.status === "error" && toolCall.error ? html3`<div data-sc-tool-error>${toolCall.error}</div>` : nothing2}
|
|
2356
|
+
${toolCall.status === "pending" ? html3`<div data-sc-tool-actions>
|
|
2357
|
+
<button data-sc-approve @click=${approve} aria-label="Approve ${displayName}">Approve</button>
|
|
2358
|
+
<button data-sc-deny @click=${deny} aria-label="Deny ${displayName}">Deny</button>
|
|
2359
|
+
</div>` : nothing2}
|
|
2360
|
+
</div>
|
|
2361
|
+
`;
|
|
2362
|
+
}
|
|
2363
|
+
var assistantIcon = html4`<svg data-sc-avatar width="24" height="24" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="12" fill="var(--sc-color-primary, #6a59ce)"/><path d="M12 4l1.4 3.6L17 9l-3.6 1.4L12 14l-1.4-3.6L7 9l3.6-1.4L12 4z" fill="#fff"/><path d="M16.5 13l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7.5-1.8z" fill="#fff" opacity="0.7"/></svg>`;
|
|
2364
|
+
function renderBubbleContent(message) {
|
|
2365
|
+
if (message.role === "user") {
|
|
2366
|
+
return html4`<div data-sc-msg-user>${message.content}</div>`;
|
|
2367
|
+
}
|
|
2368
|
+
return html4`<div data-sc-msg-assistant>${unsafeHTML(renderMarkdown(message.content))}</div>`;
|
|
2369
|
+
}
|
|
2370
|
+
function renderMessageBubble(props) {
|
|
2371
|
+
const { message, toolLabels, toolRenderers } = props;
|
|
2372
|
+
const isUser = message.role === "user";
|
|
2373
|
+
const toolCards = message.toolCalls?.map((tc) => {
|
|
2374
|
+
const approve = () => props.onToolApprove(tc.id);
|
|
2375
|
+
const deny = () => props.onToolDeny(tc.id);
|
|
2376
|
+
const customRenderer = toolRenderers?.[tc.name];
|
|
2377
|
+
if (customRenderer) {
|
|
2378
|
+
return customRenderer.render({
|
|
2379
|
+
toolCall: tc,
|
|
2380
|
+
phase: tc.status,
|
|
2381
|
+
approve,
|
|
2382
|
+
deny
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
return renderToolCallCard({
|
|
2386
|
+
toolCall: tc,
|
|
2387
|
+
toolLabel: toolLabels?.[tc.name],
|
|
2388
|
+
approve,
|
|
2389
|
+
deny
|
|
2390
|
+
});
|
|
2391
|
+
});
|
|
2392
|
+
return html4`
|
|
2393
|
+
<div data-sc-msg-row data-sc-role=${message.role}>
|
|
2394
|
+
${!isUser ? assistantIcon : nothing3}
|
|
2395
|
+
<div data-sc-msg-content>
|
|
2396
|
+
${renderBubbleContent(message)}
|
|
2397
|
+
${message.status === "error" ? html4`<div data-sc-msg-error>Failed to send</div>` : nothing3}
|
|
2398
|
+
${toolCards ?? nothing3}
|
|
2399
|
+
${renderActionBar({
|
|
2400
|
+
messageId: message.id,
|
|
2401
|
+
content: message.content,
|
|
2402
|
+
role: message.role,
|
|
2403
|
+
onCopy: props.onCopy,
|
|
2404
|
+
onRegenerate: isUser ? void 0 : props.onRegenerate
|
|
2405
|
+
})}
|
|
2406
|
+
</div>
|
|
2407
|
+
</div>
|
|
2408
|
+
`;
|
|
2409
|
+
}
|
|
2410
|
+
function renderTypingIndicator() {
|
|
2411
|
+
return html5`
|
|
2412
|
+
<div data-sc-typing aria-label="Assistant is typing">
|
|
2413
|
+
<span></span><span></span><span></span>
|
|
2414
|
+
</div>
|
|
2415
|
+
`;
|
|
2416
|
+
}
|
|
2417
|
+
function renderMessageList(props) {
|
|
2418
|
+
if (props.messages.length === 0 && !props.isTyping) {
|
|
2419
|
+
return html6`<div role="log" aria-live="polite" aria-label="Chat messages">
|
|
2420
|
+
${props.emptyStateSlot ?? nothing4}
|
|
2421
|
+
</div>`;
|
|
2422
|
+
}
|
|
2423
|
+
return html6`
|
|
2424
|
+
<div role="log" aria-live="polite" aria-label="Chat messages" data-sc-msg-list>
|
|
2425
|
+
${repeat(
|
|
2426
|
+
props.messages,
|
|
2427
|
+
(msg) => msg.id,
|
|
2428
|
+
(msg) => guard(
|
|
2429
|
+
[fingerprint(msg)],
|
|
2430
|
+
() => renderMessageBubble({
|
|
2431
|
+
message: msg,
|
|
2432
|
+
toolLabels: props.toolLabels,
|
|
2433
|
+
toolRenderers: props.toolRenderers,
|
|
2434
|
+
onCopy: props.onCopy,
|
|
2435
|
+
onRegenerate: props.onRegenerate,
|
|
2436
|
+
onToolApprove: props.onToolApprove,
|
|
2437
|
+
onToolDeny: props.onToolDeny
|
|
2438
|
+
})
|
|
2439
|
+
)
|
|
2440
|
+
)}
|
|
2441
|
+
${props.isTyping ? props.typingIndicatorSlot ?? renderTypingIndicator() : nothing4}
|
|
2442
|
+
</div>
|
|
2443
|
+
`;
|
|
2444
|
+
}
|
|
2445
|
+
var STYLE_ID = "sc-chat-styles";
|
|
2446
|
+
var STYLE_RULES = `
|
|
2447
|
+
@keyframes sc-fade-in {
|
|
2448
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
2449
|
+
to { opacity: 1; transform: translateY(0); }
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
@keyframes sc-typing-bounce {
|
|
2453
|
+
0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
|
|
2454
|
+
40% { transform: scale(1); opacity: 1; }
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
@keyframes sc-spin {
|
|
2458
|
+
to { transform: rotate(360deg); }
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
[data-sc-chat] {
|
|
2462
|
+
font-family: var(--sc-font-family, system-ui, -apple-system, sans-serif);
|
|
2463
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2464
|
+
line-height: 1.5;
|
|
2465
|
+
font-size: 0.9375rem;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
/* \u2500\u2500 Message list \u2500\u2500 */
|
|
2469
|
+
[data-sc-chat] [data-sc-msg-list] {
|
|
2470
|
+
display: flex;
|
|
2471
|
+
flex-direction: column;
|
|
2472
|
+
gap: 4px;
|
|
2473
|
+
padding: 16px 16px 8px;
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
/* \u2500\u2500 Message row (avatar + content) \u2500\u2500 */
|
|
2477
|
+
[data-sc-chat] [data-sc-msg-row] {
|
|
2478
|
+
display: flex;
|
|
2479
|
+
gap: 10px;
|
|
2480
|
+
align-items: flex-start;
|
|
2481
|
+
animation: sc-fade-in 0.25s ease-out;
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
[data-sc-chat] [data-sc-msg-row][data-sc-role="user"] {
|
|
2485
|
+
flex-direction: row-reverse;
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
[data-sc-chat] [data-sc-msg-content] {
|
|
2489
|
+
min-width: 0;
|
|
2490
|
+
max-width: 80%;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
[data-sc-chat] [data-sc-msg-row][data-sc-role="user"] [data-sc-msg-content] {
|
|
2494
|
+
display: flex;
|
|
2495
|
+
flex-direction: column;
|
|
2496
|
+
align-items: flex-end;
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
/* \u2500\u2500 Avatar \u2500\u2500 */
|
|
2500
|
+
[data-sc-chat] [data-sc-avatar] {
|
|
2501
|
+
flex-shrink: 0;
|
|
2502
|
+
margin-top: 2px;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
/* \u2500\u2500 Bubbles \u2500\u2500 */
|
|
2506
|
+
[data-sc-chat] [data-sc-msg-user] {
|
|
2507
|
+
background: var(--sc-color-primary, #6a59ce);
|
|
2508
|
+
color: var(--sc-color-primary-text, #ffffff);
|
|
2509
|
+
border-radius: 18px 18px 4px 18px;
|
|
2510
|
+
padding: 10px 16px;
|
|
2511
|
+
word-break: break-word;
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
[data-sc-chat] [data-sc-msg-assistant] {
|
|
2515
|
+
background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
|
|
2516
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2517
|
+
border-radius: 18px 18px 18px 4px;
|
|
2518
|
+
padding: 10px 16px;
|
|
2519
|
+
word-break: break-word;
|
|
2520
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
[data-sc-chat] [data-sc-msg-assistant] > :first-child { margin-top: 0; }
|
|
2524
|
+
[data-sc-chat] [data-sc-msg-assistant] > :last-child { margin-bottom: 0; }
|
|
2525
|
+
|
|
2526
|
+
[data-sc-chat] [data-sc-msg-assistant] p,
|
|
2527
|
+
[data-sc-chat] [data-sc-msg-assistant] ul,
|
|
2528
|
+
[data-sc-chat] [data-sc-msg-assistant] ol,
|
|
2529
|
+
[data-sc-chat] [data-sc-msg-assistant] pre,
|
|
2530
|
+
[data-sc-chat] [data-sc-msg-assistant] blockquote {
|
|
2531
|
+
margin: 0.25em 0;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
[data-sc-chat] [data-sc-msg-assistant] code:not(pre code) {
|
|
2535
|
+
background: rgba(0, 0, 0, 0.06);
|
|
2536
|
+
padding: 1px 5px;
|
|
2537
|
+
border-radius: 4px;
|
|
2538
|
+
font-size: 0.85em;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
[data-sc-chat] [data-sc-msg-assistant] ul,
|
|
2542
|
+
[data-sc-chat] [data-sc-msg-assistant] ol {
|
|
2543
|
+
padding-left: 1.2em;
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
[data-sc-chat] [data-sc-msg-assistant] h1,
|
|
2547
|
+
[data-sc-chat] [data-sc-msg-assistant] h2,
|
|
2548
|
+
[data-sc-chat] [data-sc-msg-assistant] h3 {
|
|
2549
|
+
margin: 0.5rem 0 0.25rem;
|
|
2550
|
+
color: var(--sc-content-heading-color, #1a1a2e);
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
/* \u2500\u2500 Code blocks \u2500\u2500 */
|
|
2554
|
+
[data-sc-chat] [data-sc-code-block] {
|
|
2555
|
+
position: relative;
|
|
2556
|
+
margin: 0.5rem 0;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
[data-sc-chat] [data-sc-code-block]::before {
|
|
2560
|
+
content: attr(data-lang);
|
|
2561
|
+
position: absolute;
|
|
2562
|
+
top: 0;
|
|
2563
|
+
right: 0;
|
|
2564
|
+
padding: 2px 10px;
|
|
2565
|
+
font-size: 0.7rem;
|
|
2566
|
+
color: rgba(255, 255, 255, 0.4);
|
|
2567
|
+
text-transform: uppercase;
|
|
2568
|
+
letter-spacing: 0.05em;
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
[data-sc-chat] [data-sc-code-block] pre {
|
|
2572
|
+
background: var(--sc-chat-code-bg, #1e1e2e);
|
|
2573
|
+
color: #e0e0e0;
|
|
2574
|
+
border-radius: 10px;
|
|
2575
|
+
padding: 14px;
|
|
2576
|
+
overflow-x: auto;
|
|
2577
|
+
font-size: 0.825em;
|
|
2578
|
+
margin: 0;
|
|
2579
|
+
line-height: 1.6;
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
[data-sc-chat] [data-sc-code-block] [data-sc-copy-btn] {
|
|
2583
|
+
position: absolute;
|
|
2584
|
+
top: 8px;
|
|
2585
|
+
right: 8px;
|
|
2586
|
+
background: rgba(255, 255, 255, 0.08);
|
|
2587
|
+
border: none;
|
|
2588
|
+
color: rgba(255, 255, 255, 0.5);
|
|
2589
|
+
border-radius: 6px;
|
|
2590
|
+
padding: 4px 10px;
|
|
2591
|
+
cursor: pointer;
|
|
2592
|
+
font-size: 0.7rem;
|
|
2593
|
+
opacity: 0;
|
|
2594
|
+
transition: opacity 0.15s, background 0.15s;
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
[data-sc-chat] [data-sc-code-block]:hover [data-sc-copy-btn] {
|
|
2598
|
+
opacity: 1;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
[data-sc-chat] [data-sc-code-block] [data-sc-copy-btn]:hover {
|
|
2602
|
+
background: rgba(255, 255, 255, 0.16);
|
|
2603
|
+
color: rgba(255, 255, 255, 0.8);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
/* \u2500\u2500 Scrollbar \u2500\u2500 */
|
|
2607
|
+
[data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar {
|
|
2608
|
+
width: 4px;
|
|
2609
|
+
}
|
|
2610
|
+
[data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-track {
|
|
2611
|
+
background: transparent;
|
|
2612
|
+
}
|
|
2613
|
+
[data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-thumb {
|
|
2614
|
+
background: rgba(0, 0, 0, 0.12);
|
|
2615
|
+
border-radius: 4px;
|
|
2616
|
+
}
|
|
2617
|
+
[data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-thumb:hover {
|
|
2618
|
+
background: rgba(0, 0, 0, 0.2);
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
[data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar {
|
|
2622
|
+
height: 4px;
|
|
2623
|
+
}
|
|
2624
|
+
[data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar-track {
|
|
2625
|
+
background: transparent;
|
|
2626
|
+
}
|
|
2627
|
+
[data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar-thumb {
|
|
2628
|
+
background: rgba(255, 255, 255, 0.15);
|
|
2629
|
+
border-radius: 4px;
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
/* \u2500\u2500 Chat input area \u2500\u2500 */
|
|
2633
|
+
[data-sc-chat] [data-sc-chat-input] {
|
|
2634
|
+
display: flex;
|
|
2635
|
+
align-items: flex-end;
|
|
2636
|
+
gap: 8px;
|
|
2637
|
+
padding: 12px 16px;
|
|
2638
|
+
border-top: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2639
|
+
background: var(--sc-chat-input-bg, #ffffff);
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
[data-sc-chat] [data-sc-chat-input] textarea {
|
|
2643
|
+
flex: 1;
|
|
2644
|
+
border: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2645
|
+
border-radius: 14px;
|
|
2646
|
+
padding: 10px 16px;
|
|
2647
|
+
font-family: inherit;
|
|
2648
|
+
font-size: 0.9rem;
|
|
2649
|
+
resize: none;
|
|
2650
|
+
outline: none;
|
|
2651
|
+
background: var(--sc-chat-input-bg, #ffffff);
|
|
2652
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2653
|
+
min-height: 42px;
|
|
2654
|
+
max-height: 150px;
|
|
2655
|
+
line-height: 1.4;
|
|
2656
|
+
transition: border-color 0.2s, box-shadow 0.2s;
|
|
2657
|
+
overflow-y: auto;
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
[data-sc-chat] [data-sc-chat-input] textarea:focus {
|
|
2661
|
+
border-color: var(--sc-color-primary, #6a59ce);
|
|
2662
|
+
box-shadow: 0 0 0 3px rgba(106, 89, 206, 0.1);
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
[data-sc-chat] [data-sc-send-btn] {
|
|
2666
|
+
background: var(--sc-color-primary, #6a59ce);
|
|
2667
|
+
color: var(--sc-color-primary-text, #ffffff);
|
|
2668
|
+
border: none;
|
|
2669
|
+
border-radius: 50%;
|
|
2670
|
+
width: 38px;
|
|
2671
|
+
height: 38px;
|
|
2672
|
+
cursor: pointer;
|
|
2673
|
+
display: flex;
|
|
2674
|
+
align-items: center;
|
|
2675
|
+
justify-content: center;
|
|
2676
|
+
flex-shrink: 0;
|
|
2677
|
+
transition: background 0.2s, transform 0.15s, opacity 0.2s;
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
[data-sc-chat] [data-sc-send-btn]:hover:not(:disabled) {
|
|
2681
|
+
background: var(--sc-color-primary-hover, #5a49be);
|
|
2682
|
+
transform: scale(1.05);
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
[data-sc-chat] [data-sc-send-btn]:active:not(:disabled) {
|
|
2686
|
+
transform: scale(0.95);
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
[data-sc-chat] [data-sc-send-btn]:disabled {
|
|
2690
|
+
background: var(--sc-content-border-color, #e8e8ee);
|
|
2691
|
+
color: var(--sc-content-text-secondary-color, #87919f);
|
|
2692
|
+
cursor: default;
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
[data-sc-chat] [data-sc-send-btn] svg {
|
|
2696
|
+
display: block;
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/* \u2500\u2500 Typing indicator \u2500\u2500 */
|
|
2700
|
+
[data-sc-chat] [data-sc-typing] {
|
|
2701
|
+
display: flex;
|
|
2702
|
+
gap: 4px;
|
|
2703
|
+
padding: 12px 16px;
|
|
2704
|
+
background: var(--sc-chat-loading-bg, #f4f4f8);
|
|
2705
|
+
border-radius: 18px 18px 18px 4px;
|
|
2706
|
+
width: fit-content;
|
|
2707
|
+
margin-left: 34px;
|
|
2708
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
[data-sc-chat] [data-sc-typing] span {
|
|
2712
|
+
width: 6px;
|
|
2713
|
+
height: 6px;
|
|
2714
|
+
border-radius: 50%;
|
|
2715
|
+
background: var(--sc-content-text-secondary-color, #87919f);
|
|
2716
|
+
animation: sc-typing-bounce 1.4s infinite ease-in-out both;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
[data-sc-chat] [data-sc-typing] span:nth-child(2) { animation-delay: 0.16s; }
|
|
2720
|
+
[data-sc-chat] [data-sc-typing] span:nth-child(3) { animation-delay: 0.32s; }
|
|
2721
|
+
|
|
2722
|
+
/* \u2500\u2500 Suggestion chips \u2500\u2500 */
|
|
2723
|
+
[data-sc-chat] [data-sc-suggestions] {
|
|
2724
|
+
display: flex;
|
|
2725
|
+
flex-wrap: wrap;
|
|
2726
|
+
gap: 8px;
|
|
2727
|
+
padding: 8px 16px;
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
[data-sc-chat] [data-sc-suggestions] button {
|
|
2731
|
+
background: transparent;
|
|
2732
|
+
border: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2733
|
+
border-radius: 20px;
|
|
2734
|
+
padding: 7px 16px;
|
|
2735
|
+
font-size: 0.84rem;
|
|
2736
|
+
cursor: pointer;
|
|
2737
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2738
|
+
transition: all 0.2s;
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
[data-sc-chat] [data-sc-suggestions] button:hover {
|
|
2742
|
+
background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
|
|
2743
|
+
border-color: var(--sc-color-primary, #6a59ce);
|
|
2744
|
+
color: var(--sc-color-primary, #6a59ce);
|
|
2745
|
+
transform: translateY(-1px);
|
|
2746
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
/* \u2500\u2500 Action bar \u2500\u2500 */
|
|
2750
|
+
[data-sc-chat] [data-sc-action-bar] {
|
|
2751
|
+
display: none;
|
|
2752
|
+
gap: 2px;
|
|
2753
|
+
padding-top: 2px;
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
[data-sc-chat] [data-sc-msg-row]:hover [data-sc-action-bar] {
|
|
2757
|
+
display: flex;
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
[data-sc-chat] [data-sc-action-bar] button {
|
|
2761
|
+
background: transparent;
|
|
2762
|
+
border: none;
|
|
2763
|
+
border-radius: 6px;
|
|
2764
|
+
padding: 5px;
|
|
2765
|
+
cursor: pointer;
|
|
2766
|
+
color: var(--sc-content-text-secondary-color, #87919f);
|
|
2767
|
+
display: flex;
|
|
2768
|
+
align-items: center;
|
|
2769
|
+
justify-content: center;
|
|
2770
|
+
width: 28px;
|
|
2771
|
+
height: 28px;
|
|
2772
|
+
transition: background 0.15s, color 0.15s;
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
[data-sc-chat] [data-sc-action-bar] button:hover {
|
|
2776
|
+
background: var(--sc-chat-action-bar-bg, rgba(0, 0, 0, 0.06));
|
|
2777
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
/* \u2500\u2500 Tool call cards \u2500\u2500 */
|
|
2781
|
+
[data-sc-chat] [data-sc-tool-card] {
|
|
2782
|
+
border: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2783
|
+
border-left: 3px solid var(--sc-color-primary, #6a59ce);
|
|
2784
|
+
border-radius: 4px 10px 10px 4px;
|
|
2785
|
+
padding: 10px 14px;
|
|
2786
|
+
margin-top: 8px;
|
|
2787
|
+
font-size: 0.84rem;
|
|
2788
|
+
background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
|
|
2789
|
+
transition: border-color 0.2s;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
[data-sc-chat] [data-sc-tool-card][data-sc-active] {
|
|
2793
|
+
border-left-color: #3b82f6;
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
[data-sc-chat] [data-sc-tool-header] {
|
|
2797
|
+
display: flex;
|
|
2798
|
+
align-items: center;
|
|
2799
|
+
gap: 8px;
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
[data-sc-chat] [data-sc-tool-icon] {
|
|
2803
|
+
display: flex;
|
|
2804
|
+
color: var(--sc-color-primary, #6a59ce);
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
[data-sc-chat] [data-sc-tool-icon][data-sc-status="done"] {
|
|
2808
|
+
color: #22c55e;
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
[data-sc-chat] [data-sc-tool-icon][data-sc-status="error"] {
|
|
2812
|
+
color: #ef4444;
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
[data-sc-chat] [data-sc-tool-icon][data-sc-status="running"],
|
|
2816
|
+
[data-sc-chat] [data-sc-tool-icon][data-sc-status="args-streaming"] {
|
|
2817
|
+
color: #3b82f6;
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
[data-sc-chat] [data-sc-spinner] {
|
|
2821
|
+
animation: sc-spin 0.8s linear infinite;
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
[data-sc-chat] [data-sc-tool-name] {
|
|
2825
|
+
font-weight: 500;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
[data-sc-chat] [data-sc-tool-error] {
|
|
2829
|
+
color: #ef4444;
|
|
2830
|
+
font-size: 0.8rem;
|
|
2831
|
+
margin-top: 6px;
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
[data-sc-chat] [data-sc-tool-actions] {
|
|
2835
|
+
display: flex;
|
|
2836
|
+
gap: 8px;
|
|
2837
|
+
margin-top: 10px;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
[data-sc-chat] [data-sc-tool-actions] button {
|
|
2841
|
+
padding: 5px 14px;
|
|
2842
|
+
border-radius: 8px;
|
|
2843
|
+
font-size: 0.8rem;
|
|
2844
|
+
cursor: pointer;
|
|
2845
|
+
border: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2846
|
+
background: transparent;
|
|
2847
|
+
transition: all 0.15s;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
[data-sc-chat] [data-sc-tool-actions] [data-sc-approve] {
|
|
2851
|
+
background: var(--sc-color-primary, #6a59ce);
|
|
2852
|
+
color: var(--sc-color-primary-text, #ffffff);
|
|
2853
|
+
border-color: transparent;
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
[data-sc-chat] [data-sc-tool-actions] [data-sc-approve]:hover {
|
|
2857
|
+
filter: brightness(1.1);
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
[data-sc-chat] [data-sc-tool-actions] [data-sc-deny] {
|
|
2861
|
+
color: var(--sc-content-text-secondary-color, #87919f);
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
[data-sc-chat] [data-sc-tool-actions] [data-sc-deny]:hover {
|
|
2865
|
+
border-color: #ef4444;
|
|
2866
|
+
color: #ef4444;
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
/* \u2500\u2500 Error banner \u2500\u2500 */
|
|
2870
|
+
[data-sc-chat] [data-sc-error] {
|
|
2871
|
+
background: #fef2f2;
|
|
2872
|
+
border-left: 3px solid #ef4444;
|
|
2873
|
+
padding: 8px 12px;
|
|
2874
|
+
border-radius: 0 8px 8px 0;
|
|
2875
|
+
font-size: 0.84rem;
|
|
2876
|
+
color: #dc2626;
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
[data-sc-chat] [data-sc-msg-error] {
|
|
2880
|
+
font-size: 0.8rem;
|
|
2881
|
+
color: #ef4444;
|
|
2882
|
+
margin-top: 4px;
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
/* \u2500\u2500 Scroll-to-bottom \u2500\u2500 */
|
|
2886
|
+
[data-sc-chat] [data-sc-scroll-btn] {
|
|
2887
|
+
position: absolute;
|
|
2888
|
+
bottom: 80px;
|
|
2889
|
+
left: 50%;
|
|
2890
|
+
transform: translateX(-50%);
|
|
2891
|
+
background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
|
|
2892
|
+
color: var(--sc-content-text-color, #1a1a2e);
|
|
2893
|
+
border: 1px solid var(--sc-content-border-color, #e8e8ee);
|
|
2894
|
+
border-radius: 50%;
|
|
2895
|
+
width: 36px;
|
|
2896
|
+
height: 36px;
|
|
2897
|
+
display: flex;
|
|
2898
|
+
align-items: center;
|
|
2899
|
+
justify-content: center;
|
|
2900
|
+
cursor: pointer;
|
|
2901
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
2902
|
+
z-index: 1;
|
|
2903
|
+
transition: box-shadow 0.2s;
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
[data-sc-chat] [data-sc-scroll-btn]:hover {
|
|
2907
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
[data-sc-chat] [data-sc-scroll-btn] svg {
|
|
2911
|
+
display: block;
|
|
2912
|
+
}
|
|
2913
|
+
`.trim();
|
|
2914
|
+
function injectChatStyles() {
|
|
2915
|
+
if (typeof document === "undefined") return;
|
|
2916
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
2917
|
+
const style = document.createElement("style");
|
|
2918
|
+
style.id = STYLE_ID;
|
|
2919
|
+
style.textContent = STYLE_RULES;
|
|
2920
|
+
document.head.appendChild(style);
|
|
2921
|
+
}
|
|
2922
|
+
var SyntroChat = class extends LitElement {
|
|
2923
|
+
constructor() {
|
|
2924
|
+
super(...arguments);
|
|
2925
|
+
this._messages = [];
|
|
2926
|
+
this._isTyping = false;
|
|
2927
|
+
this._isConnected = false;
|
|
2928
|
+
this._sessionId = null;
|
|
2929
|
+
this._inputValue = "";
|
|
2930
|
+
this._isComposing = false;
|
|
2931
|
+
this._isStreaming = false;
|
|
2932
|
+
this._unsubscribe = null;
|
|
2933
|
+
this._scrollContainer = null;
|
|
2934
|
+
this._userScrolledUp = false;
|
|
2935
|
+
this._errorMessage = null;
|
|
2936
|
+
this._handleScroll = () => {
|
|
2937
|
+
if (!this._scrollContainer) return;
|
|
2938
|
+
const { scrollTop, scrollHeight, clientHeight } = this._scrollContainer;
|
|
2939
|
+
this._userScrolledUp = scrollHeight - scrollTop - clientHeight > 50;
|
|
2940
|
+
};
|
|
2941
|
+
this._handleEvent = (event) => {
|
|
2942
|
+
switch (event.type) {
|
|
2943
|
+
case "session-ready":
|
|
2944
|
+
this._sessionId = event.sessionId;
|
|
2945
|
+
this._isConnected = true;
|
|
2946
|
+
break;
|
|
2947
|
+
case "messages-snapshot":
|
|
2948
|
+
this._messages = [...event.messages];
|
|
2949
|
+
this._isStreaming = event.messages.some((m2) => m2.status === "streaming");
|
|
2950
|
+
this._scrollToBottom();
|
|
2951
|
+
break;
|
|
2952
|
+
case "message-append":
|
|
2953
|
+
this._messages = [...this._messages, event.message];
|
|
2954
|
+
this._isStreaming = event.message.status === "streaming";
|
|
2955
|
+
this._scrollToBottom();
|
|
2956
|
+
break;
|
|
2957
|
+
case "message-delta": {
|
|
2958
|
+
this._messages = this._messages.map(
|
|
2959
|
+
(m2) => m2.id === event.messageId ? { ...m2, content: m2.content + event.delta } : m2
|
|
2960
|
+
);
|
|
2961
|
+
this._scrollToBottom();
|
|
2962
|
+
break;
|
|
2963
|
+
}
|
|
2964
|
+
case "message-complete":
|
|
2965
|
+
this._messages = this._messages.map(
|
|
2966
|
+
(m2) => m2.id === event.messageId ? { ...m2, status: "complete" } : m2
|
|
2967
|
+
);
|
|
2968
|
+
this._isStreaming = false;
|
|
2969
|
+
break;
|
|
2970
|
+
case "typing":
|
|
2971
|
+
this._isTyping = event.isTyping;
|
|
2972
|
+
if (event.isTyping) this._scrollToBottom();
|
|
2973
|
+
break;
|
|
2974
|
+
case "tool-call": {
|
|
2975
|
+
this._messages = this._messages.map(
|
|
2976
|
+
(m2) => m2.id === event.messageId ? { ...m2, toolCalls: [...m2.toolCalls ?? [], event.toolCall] } : m2
|
|
2977
|
+
);
|
|
2978
|
+
if (this.autoExecTools?.has(event.toolCall.name) && event.toolCall.status === "pending") {
|
|
2979
|
+
this.transport.send({
|
|
2980
|
+
type: "tool-result",
|
|
2981
|
+
toolCallId: event.toolCall.id,
|
|
2982
|
+
result: null,
|
|
2983
|
+
approved: true
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
break;
|
|
2987
|
+
}
|
|
2988
|
+
case "tool-call-args-delta": {
|
|
2989
|
+
this._messages = this._messages.map((m2) => {
|
|
2990
|
+
if (!m2.toolCalls) return m2;
|
|
2991
|
+
const toolCalls = m2.toolCalls.map(
|
|
2992
|
+
(tc) => tc.id === event.toolCallId ? { ...tc, argsBuffer: tc.argsBuffer + event.delta } : tc
|
|
2993
|
+
);
|
|
2994
|
+
return { ...m2, toolCalls };
|
|
2995
|
+
});
|
|
2996
|
+
break;
|
|
2997
|
+
}
|
|
2998
|
+
case "tool-call-done": {
|
|
2999
|
+
this._messages = this._messages.map((m2) => {
|
|
3000
|
+
if (!m2.toolCalls) return m2;
|
|
3001
|
+
const toolCalls = m2.toolCalls.map((tc) => {
|
|
3002
|
+
if (tc.id !== event.toolCallId) return tc;
|
|
3003
|
+
let args;
|
|
3004
|
+
try {
|
|
3005
|
+
args = JSON.parse(tc.argsBuffer);
|
|
3006
|
+
} catch {
|
|
3007
|
+
args = void 0;
|
|
3008
|
+
}
|
|
3009
|
+
return { ...tc, status: "done", args };
|
|
3010
|
+
});
|
|
3011
|
+
return { ...m2, toolCalls };
|
|
3012
|
+
});
|
|
3013
|
+
break;
|
|
3014
|
+
}
|
|
3015
|
+
case "error":
|
|
3016
|
+
this._errorMessage = event.message;
|
|
3017
|
+
break;
|
|
3018
|
+
case "a2ui":
|
|
3019
|
+
break;
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
this._onInput = (e) => {
|
|
3023
|
+
this._inputValue = e.target.value;
|
|
3024
|
+
};
|
|
3025
|
+
this._onSend = () => {
|
|
3026
|
+
const text2 = this._inputValue.trim();
|
|
3027
|
+
if (!text2) return;
|
|
3028
|
+
this.transport.send({ type: "user-message", text: text2 });
|
|
3029
|
+
this._inputValue = "";
|
|
3030
|
+
};
|
|
3031
|
+
this._onStop = () => {
|
|
3032
|
+
this.transport.send({ type: "stop-generation" });
|
|
3033
|
+
};
|
|
3034
|
+
this._onKeyDown = (e) => {
|
|
3035
|
+
if (e.key === "Enter" && !e.shiftKey && !this._isComposing) {
|
|
3036
|
+
e.preventDefault();
|
|
3037
|
+
if (this._isStreaming) {
|
|
3038
|
+
this._onStop();
|
|
3039
|
+
} else {
|
|
3040
|
+
this._onSend();
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
};
|
|
3044
|
+
this._onCopy = (content) => {
|
|
3045
|
+
navigator.clipboard?.writeText(content);
|
|
3046
|
+
};
|
|
3047
|
+
this._onRegenerate = (messageId) => {
|
|
3048
|
+
this.transport.send({ type: "regenerate", messageId });
|
|
3049
|
+
};
|
|
3050
|
+
this._onToolApprove = (toolCallId) => {
|
|
3051
|
+
this.transport.send({
|
|
3052
|
+
type: "tool-result",
|
|
3053
|
+
toolCallId,
|
|
3054
|
+
result: null,
|
|
3055
|
+
approved: true
|
|
3056
|
+
});
|
|
3057
|
+
};
|
|
3058
|
+
this._onToolDeny = (toolCallId) => {
|
|
3059
|
+
this.transport.send({
|
|
3060
|
+
type: "tool-result",
|
|
3061
|
+
toolCallId,
|
|
3062
|
+
result: null,
|
|
3063
|
+
approved: false
|
|
3064
|
+
});
|
|
3065
|
+
};
|
|
3066
|
+
this._onCompositionStart = () => {
|
|
3067
|
+
this._isComposing = true;
|
|
3068
|
+
};
|
|
3069
|
+
this._onCompositionEnd = () => {
|
|
3070
|
+
this._isComposing = false;
|
|
3071
|
+
};
|
|
3072
|
+
this._onSuggestion = (text2) => {
|
|
3073
|
+
this.transport.send({ type: "user-message", text: text2 });
|
|
3074
|
+
};
|
|
3075
|
+
}
|
|
3076
|
+
createRenderRoot() {
|
|
3077
|
+
return this;
|
|
3078
|
+
}
|
|
3079
|
+
connectedCallback() {
|
|
3080
|
+
super.connectedCallback();
|
|
3081
|
+
injectChatStyles();
|
|
3082
|
+
if (this.transport) {
|
|
3083
|
+
this._unsubscribe = this.transport.subscribe(this._handleEvent);
|
|
3084
|
+
this.transport.connect();
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
disconnectedCallback() {
|
|
3088
|
+
super.disconnectedCallback();
|
|
3089
|
+
this._unsubscribe?.();
|
|
3090
|
+
this._unsubscribe = null;
|
|
3091
|
+
this.transport?.disconnect();
|
|
3092
|
+
}
|
|
3093
|
+
firstUpdated() {
|
|
3094
|
+
this._scrollContainer = this.querySelector("[data-sc-scroll-area]");
|
|
3095
|
+
this._scrollContainer?.addEventListener("scroll", this._handleScroll);
|
|
3096
|
+
}
|
|
3097
|
+
updated() {
|
|
3098
|
+
this._injectCodeCopyButtons();
|
|
3099
|
+
}
|
|
3100
|
+
_injectCodeCopyButtons() {
|
|
3101
|
+
const blocks = this.querySelectorAll("[data-sc-code-block]:not(:has([data-sc-copy-btn]))");
|
|
3102
|
+
for (const block of blocks) {
|
|
3103
|
+
const btn = document.createElement("button");
|
|
3104
|
+
btn.setAttribute("data-sc-copy-btn", "");
|
|
3105
|
+
btn.textContent = "Copy";
|
|
3106
|
+
btn.addEventListener("click", () => {
|
|
3107
|
+
const code = block.querySelector("code");
|
|
3108
|
+
if (code) navigator.clipboard?.writeText(code.textContent ?? "");
|
|
3109
|
+
btn.textContent = "Copied!";
|
|
3110
|
+
setTimeout(() => {
|
|
3111
|
+
btn.textContent = "Copy";
|
|
3112
|
+
}, 1500);
|
|
3113
|
+
});
|
|
3114
|
+
block.appendChild(btn);
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
_scrollToBottom() {
|
|
3118
|
+
if (this._userScrolledUp) return;
|
|
3119
|
+
requestAnimationFrame(() => {
|
|
3120
|
+
if (this._scrollContainer?.scrollTo) {
|
|
3121
|
+
this._scrollContainer.scrollTo({
|
|
3122
|
+
top: this._scrollContainer.scrollHeight,
|
|
3123
|
+
behavior: "smooth"
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
});
|
|
3127
|
+
}
|
|
3128
|
+
render() {
|
|
3129
|
+
const headerSlot = this.slots?.header;
|
|
3130
|
+
const emptyState = this.slots?.emptyState ?? (this.greeting ? html7`<div style="padding:24px;text-align:center;color:var(--sc-content-text-secondary-color,#87919f)">${this.greeting}</div>` : void 0);
|
|
3131
|
+
return html7`
|
|
3132
|
+
<div data-sc-chat style="display:flex;flex-direction:column;height:100%;position:relative;">
|
|
3133
|
+
${headerSlot && typeof headerSlot === "object" && "values" in headerSlot ? headerSlot : nothing5}
|
|
3134
|
+
<div data-sc-scroll-area style="flex:1;overflow-y:auto;">
|
|
3135
|
+
${renderMessageList({
|
|
3136
|
+
messages: this._messages,
|
|
3137
|
+
isTyping: this._isTyping,
|
|
3138
|
+
toolLabels: this.toolLabels,
|
|
3139
|
+
toolRenderers: this.toolRenderers,
|
|
3140
|
+
onCopy: this._onCopy,
|
|
3141
|
+
onRegenerate: this._onRegenerate,
|
|
3142
|
+
onToolApprove: this._onToolApprove,
|
|
3143
|
+
onToolDeny: this._onToolDeny,
|
|
3144
|
+
emptyStateSlot: emptyState,
|
|
3145
|
+
typingIndicatorSlot: this.slots?.typingIndicator
|
|
3146
|
+
})}
|
|
3147
|
+
</div>
|
|
3148
|
+
${this._userScrolledUp ? html7`<button data-sc-scroll-btn @click=${() => {
|
|
3149
|
+
this._userScrolledUp = false;
|
|
3150
|
+
this._scrollToBottom();
|
|
3151
|
+
}} aria-label="Scroll to bottom"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M4 6l4 4 4-4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>` : nothing5}
|
|
3152
|
+
${this._errorMessage ? html7`<div data-sc-error role="alert">${this._errorMessage}</div>` : nothing5}
|
|
3153
|
+
${renderChatInput({
|
|
3154
|
+
value: this._inputValue,
|
|
3155
|
+
isStreaming: this._isStreaming || this._isTyping,
|
|
3156
|
+
isComposing: this._isComposing,
|
|
3157
|
+
onInput: this._onInput,
|
|
3158
|
+
onSend: this._onSend,
|
|
3159
|
+
onStop: this._onStop,
|
|
3160
|
+
onKeyDown: this._onKeyDown,
|
|
3161
|
+
onCompositionStart: this._onCompositionStart,
|
|
3162
|
+
onCompositionEnd: this._onCompositionEnd,
|
|
3163
|
+
suggestions: this._messages.length === 0 ? this.suggestions : void 0,
|
|
3164
|
+
onSuggestion: this._onSuggestion,
|
|
3165
|
+
inputActionsSlot: this.slots?.inputActions,
|
|
3166
|
+
beforeInputSlot: this.slots?.beforeInput
|
|
3167
|
+
})}
|
|
3168
|
+
</div>
|
|
3169
|
+
`;
|
|
3170
|
+
}
|
|
3171
|
+
};
|
|
3172
|
+
SyntroChat.properties = {
|
|
3173
|
+
transport: { attribute: false },
|
|
3174
|
+
greeting: { type: String },
|
|
3175
|
+
suggestions: { attribute: false },
|
|
3176
|
+
toolLabels: { attribute: false },
|
|
3177
|
+
toolRenderers: { attribute: false },
|
|
3178
|
+
autoExecTools: { attribute: false },
|
|
3179
|
+
slots: { attribute: false },
|
|
3180
|
+
_messages: { state: true },
|
|
3181
|
+
_isTyping: { state: true },
|
|
3182
|
+
_isConnected: { state: true },
|
|
3183
|
+
_sessionId: { state: true },
|
|
3184
|
+
_inputValue: { state: true },
|
|
3185
|
+
_isComposing: { state: true },
|
|
3186
|
+
_isStreaming: { state: true },
|
|
3187
|
+
_userScrolledUp: { state: true },
|
|
3188
|
+
_errorMessage: { state: true }
|
|
3189
|
+
};
|
|
3190
|
+
if (!customElements.get("syntro-chat")) {
|
|
3191
|
+
customElements.define("syntro-chat", SyntroChat);
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
// ../../chat/dist/transport/sse-post.js
|
|
3195
|
+
var A2UI_KEYS = /* @__PURE__ */ new Set([
|
|
3196
|
+
"updateDataModel",
|
|
3197
|
+
"createSurface",
|
|
3198
|
+
"updateComponents",
|
|
3199
|
+
"deleteSurface"
|
|
3200
|
+
]);
|
|
3201
|
+
function isA2UIEnvelope(data) {
|
|
3202
|
+
for (const key of Object.keys(data)) {
|
|
3203
|
+
if (A2UI_KEYS.has(key)) return true;
|
|
3204
|
+
}
|
|
3205
|
+
return false;
|
|
3206
|
+
}
|
|
3207
|
+
var SsePostTransport = class {
|
|
3208
|
+
constructor(options) {
|
|
3209
|
+
this._eventSource = null;
|
|
3210
|
+
this._connected = false;
|
|
3211
|
+
this._handlers = /* @__PURE__ */ new Set();
|
|
3212
|
+
this._sseUrl = options.sseUrl;
|
|
3213
|
+
this._postUrl = options.postUrl;
|
|
3214
|
+
this._headers = options.headers ?? {};
|
|
3215
|
+
this._onA2UIEvent = options.onA2UIEvent;
|
|
3216
|
+
}
|
|
3217
|
+
get connected() {
|
|
3218
|
+
return this._connected;
|
|
3219
|
+
}
|
|
3220
|
+
connect(sessionId) {
|
|
3221
|
+
const url = sessionId ? `${this._sseUrl}?sessionId=${encodeURIComponent(sessionId)}` : this._sseUrl;
|
|
3222
|
+
this._eventSource = new EventSource(url, { withCredentials: true });
|
|
3223
|
+
this._eventSource.onopen = () => {
|
|
3224
|
+
this._connected = true;
|
|
3225
|
+
};
|
|
3226
|
+
this._eventSource.onmessage = (evt) => {
|
|
3227
|
+
this._handleMessage(evt.data);
|
|
3228
|
+
};
|
|
3229
|
+
this._eventSource.onerror = () => {
|
|
3230
|
+
this._connected = false;
|
|
3231
|
+
this._emit({ type: "error", message: "SSE connection error" });
|
|
3232
|
+
};
|
|
3233
|
+
}
|
|
3234
|
+
disconnect() {
|
|
3235
|
+
this._eventSource?.close();
|
|
3236
|
+
this._eventSource = null;
|
|
3237
|
+
this._connected = false;
|
|
3238
|
+
}
|
|
3239
|
+
send(action) {
|
|
3240
|
+
const headers = {
|
|
3241
|
+
"Content-Type": "application/json",
|
|
3242
|
+
...typeof this._headers === "function" ? this._headers() : this._headers
|
|
3243
|
+
};
|
|
3244
|
+
fetch(this._postUrl, {
|
|
3245
|
+
method: "POST",
|
|
3246
|
+
headers,
|
|
3247
|
+
credentials: "include",
|
|
3248
|
+
body: JSON.stringify(action)
|
|
3249
|
+
}).catch(() => {
|
|
3250
|
+
this._emit({ type: "error", message: "Failed to send action" });
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3253
|
+
subscribe(handler) {
|
|
3254
|
+
this._handlers.add(handler);
|
|
3255
|
+
return () => this._handlers.delete(handler);
|
|
3256
|
+
}
|
|
3257
|
+
_handleMessage(raw) {
|
|
3258
|
+
let data;
|
|
3259
|
+
try {
|
|
3260
|
+
data = JSON.parse(raw);
|
|
3261
|
+
} catch {
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
if (isA2UIEnvelope(data)) {
|
|
3265
|
+
this._onA2UIEvent?.(data);
|
|
3266
|
+
this._emit({ type: "a2ui", payload: data });
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
if ("type" in data) {
|
|
3270
|
+
this._emit(data);
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
_emit(event) {
|
|
3274
|
+
for (const handler of this._handlers) {
|
|
3275
|
+
handler(event);
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
|
|
3280
|
+
// src/ChatAssistantLit.ts
|
|
3281
|
+
var ChatAssistantLitMountable = {
|
|
3282
|
+
mount(container, mountConfig) {
|
|
3283
|
+
const {
|
|
3284
|
+
config,
|
|
3285
|
+
runtime,
|
|
3286
|
+
tileId = "chatbot-widget"
|
|
3287
|
+
} = mountConfig ?? {};
|
|
3288
|
+
if (!config || !runtime) {
|
|
3289
|
+
container.innerHTML = '<div style="padding:16px;color:var(--sc-content-text-secondary-color,#87919f)">Chat widget requires config and runtime.</div>';
|
|
3290
|
+
return () => {
|
|
3291
|
+
container.innerHTML = "";
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
const baseUrl = config.backendUrl.replace(/\/$/, "");
|
|
3295
|
+
const transport = new SsePostTransport({
|
|
3296
|
+
sseUrl: `${baseUrl}/api/adaptive/session`,
|
|
3297
|
+
postUrl: `${baseUrl}/api/adaptive/action`,
|
|
3298
|
+
onA2UIEvent: (payload) => {
|
|
3299
|
+
runtime.actions.applyBatch([payload]).then(() => {
|
|
3300
|
+
runtime.events.publish("chatbot.a2ui_applied", {
|
|
3301
|
+
tileId
|
|
3302
|
+
});
|
|
3303
|
+
}).catch((err) => {
|
|
3304
|
+
console.error("[adaptive-chatbot] A2UI apply failed:", err);
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
const el = document.createElement("syntro-chat");
|
|
3309
|
+
el.transport = transport;
|
|
3310
|
+
el.greeting = config.greeting;
|
|
3311
|
+
if (config.suggestions) {
|
|
3312
|
+
el.suggestions = config.suggestions;
|
|
3313
|
+
}
|
|
3314
|
+
el.style.cssText = "display:flex;flex-direction:column;height:100%;width:100%;";
|
|
3315
|
+
container.appendChild(el);
|
|
3316
|
+
return () => {
|
|
3317
|
+
transport.disconnect();
|
|
3318
|
+
el.remove();
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
};
|
|
3322
|
+
|
|
3323
|
+
export {
|
|
3324
|
+
ChatAssistantLitMountable
|
|
3325
|
+
};
|
|
3326
|
+
/*! Bundled license information:
|
|
3327
|
+
|
|
3328
|
+
dompurify/dist/purify.es.mjs:
|
|
3329
|
+
(*! @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 *)
|
|
3330
|
+
*/
|
|
3331
|
+
//# sourceMappingURL=chunk-FI7F22ED.js.map
|