@syntrologie/adapt-chatbot 2.27.0 → 2.29.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.
Files changed (131) hide show
  1. package/dist/AdaptiveChatBar.composer.test.d.ts +2 -0
  2. package/dist/AdaptiveChatBar.composer.test.d.ts.map +1 -0
  3. package/dist/AdaptiveChatBar.d.ts +212 -0
  4. package/dist/AdaptiveChatBar.d.ts.map +1 -0
  5. package/dist/AdaptiveChatBar.js +11 -0
  6. package/dist/AdaptiveChatBar.js.map +7 -0
  7. package/dist/AdaptiveChatBarMountable.d.ts +82 -0
  8. package/dist/AdaptiveChatBarMountable.d.ts.map +1 -0
  9. package/dist/AdaptiveChatTrail.anchor-scroll.test.d.ts +2 -0
  10. package/dist/AdaptiveChatTrail.anchor-scroll.test.d.ts.map +1 -0
  11. package/dist/AdaptiveChatTrail.d.ts +469 -0
  12. package/dist/AdaptiveChatTrail.d.ts.map +1 -0
  13. package/dist/AdaptiveChatTrail.js +11 -0
  14. package/dist/AdaptiveChatTrail.js.map +7 -0
  15. package/dist/AdaptiveChatTrail.test.d.ts +2 -0
  16. package/dist/AdaptiveChatTrail.test.d.ts.map +1 -0
  17. package/dist/AdaptiveChipsStrip.d.ts +1156 -0
  18. package/dist/AdaptiveChipsStrip.d.ts.map +1 -0
  19. package/dist/AdaptiveChipsStrip.js +11 -0
  20. package/dist/AdaptiveChipsStrip.js.map +7 -0
  21. package/dist/AdaptiveChipsStripMountable.d.ts +24 -0
  22. package/dist/AdaptiveChipsStripMountable.d.ts.map +1 -0
  23. package/dist/ChatAssistantLit.d.ts +22 -50
  24. package/dist/ChatAssistantLit.d.ts.map +1 -1
  25. package/dist/ChatAssistantLit.js +6 -3
  26. package/dist/ChatSession.d.ts +239 -0
  27. package/dist/ChatSession.d.ts.map +1 -0
  28. package/dist/ChatTransport.d.ts +390 -0
  29. package/dist/ChatTransport.d.ts.map +1 -0
  30. package/dist/InlineRegistryWidgetMount.test.d.ts +2 -0
  31. package/dist/InlineRegistryWidgetMount.test.d.ts.map +1 -0
  32. package/dist/InlineWidgetLiveMount.test.d.ts +2 -0
  33. package/dist/InlineWidgetLiveMount.test.d.ts.map +1 -0
  34. package/dist/NavLinkMountable.d.ts +25 -0
  35. package/dist/NavLinkMountable.d.ts.map +1 -0
  36. package/dist/NavLinkMountable.test.d.ts +2 -0
  37. package/dist/NavLinkMountable.test.d.ts.map +1 -0
  38. package/dist/TextAnswerMountable.d.ts +17 -0
  39. package/dist/TextAnswerMountable.d.ts.map +1 -0
  40. package/dist/TextAnswerMountable.test.d.ts +2 -0
  41. package/dist/TextAnswerMountable.test.d.ts.map +1 -0
  42. package/dist/Turnstile.d.ts +83 -0
  43. package/dist/Turnstile.d.ts.map +1 -0
  44. package/dist/chunk-A7RBZLIX.js +1678 -0
  45. package/dist/chunk-A7RBZLIX.js.map +7 -0
  46. package/dist/chunk-EACGDSJI.js +237 -0
  47. package/dist/chunk-EACGDSJI.js.map +7 -0
  48. package/dist/chunk-EWPPVPJ4.js +14 -0
  49. package/dist/chunk-EWPPVPJ4.js.map +7 -0
  50. package/dist/chunk-FXHYE6FY.js +632 -0
  51. package/dist/chunk-FXHYE6FY.js.map +7 -0
  52. package/dist/chunk-OIGVZGSX.js +641 -0
  53. package/dist/chunk-OIGVZGSX.js.map +7 -0
  54. package/dist/chunk-VZIUXXAM.js +4015 -0
  55. package/dist/chunk-VZIUXXAM.js.map +7 -0
  56. package/dist/{chunk-W457NMGD.js → chunk-ZXV4GXMO.js} +2149 -4254
  57. package/dist/chunk-ZXV4GXMO.js.map +7 -0
  58. package/dist/elements/ActionHandler.d.ts +34 -0
  59. package/dist/elements/ActionHandler.d.ts.map +1 -0
  60. package/dist/elements/ElementInstanceStore.d.ts +217 -0
  61. package/dist/elements/ElementInstanceStore.d.ts.map +1 -0
  62. package/dist/elements/ElementInstanceStore.test.d.ts +2 -0
  63. package/dist/elements/ElementInstanceStore.test.d.ts.map +1 -0
  64. package/dist/elements/ElementTypeHandler.d.ts +77 -0
  65. package/dist/elements/ElementTypeHandler.d.ts.map +1 -0
  66. package/dist/elements/ItemHandler.d.ts +60 -0
  67. package/dist/elements/ItemHandler.d.ts.map +1 -0
  68. package/dist/elements/ItemHandler.test.d.ts +2 -0
  69. package/dist/elements/ItemHandler.test.d.ts.map +1 -0
  70. package/dist/elements/TileHandler.d.ts +52 -0
  71. package/dist/elements/TileHandler.d.ts.map +1 -0
  72. package/dist/elements/TileHandler.test.d.ts +2 -0
  73. package/dist/elements/TileHandler.test.d.ts.map +1 -0
  74. package/dist/elements/__tests__/ElementInstanceStore.recall.test.d.ts +2 -0
  75. package/dist/elements/__tests__/ElementInstanceStore.recall.test.d.ts.map +1 -0
  76. package/dist/elements/blockRenderer.d.ts +46 -0
  77. package/dist/elements/blockRenderer.d.ts.map +1 -0
  78. package/dist/elements/blockRenderer.test.d.ts +13 -0
  79. package/dist/elements/blockRenderer.test.d.ts.map +1 -0
  80. package/dist/elements/blocks.d.ts +58 -0
  81. package/dist/elements/blocks.d.ts.map +1 -0
  82. package/dist/elements/envelope.d.ts +24 -0
  83. package/dist/elements/envelope.d.ts.map +1 -0
  84. package/dist/elements/fetcher.d.ts +40 -0
  85. package/dist/elements/fetcher.d.ts.map +1 -0
  86. package/dist/elements/index.d.ts +33 -0
  87. package/dist/elements/index.d.ts.map +1 -0
  88. package/dist/elements/store-singleton.d.ts +4 -0
  89. package/dist/elements/store-singleton.d.ts.map +1 -0
  90. package/dist/elements/types.d.ts +110 -0
  91. package/dist/elements/types.d.ts.map +1 -0
  92. package/dist/observer/__tests__/allowlist.test.d.ts +9 -0
  93. package/dist/observer/__tests__/allowlist.test.d.ts.map +1 -0
  94. package/dist/observer/__tests__/bus-translate.test.d.ts +16 -0
  95. package/dist/observer/__tests__/bus-translate.test.d.ts.map +1 -0
  96. package/dist/observer/__tests__/lifecycle.test.d.ts +2 -0
  97. package/dist/observer/__tests__/lifecycle.test.d.ts.map +1 -0
  98. package/dist/observer/__tests__/observer-enrich.test.d.ts +10 -0
  99. package/dist/observer/__tests__/observer-enrich.test.d.ts.map +1 -0
  100. package/dist/observer/__tests__/observer-isolation.test.d.ts +13 -0
  101. package/dist/observer/__tests__/observer-isolation.test.d.ts.map +1 -0
  102. package/dist/observer/__tests__/queue.test.d.ts +2 -0
  103. package/dist/observer/__tests__/queue.test.d.ts.map +1 -0
  104. package/dist/observer/__tests__/transport.test.d.ts +2 -0
  105. package/dist/observer/__tests__/transport.test.d.ts.map +1 -0
  106. package/dist/observer/allowlist.d.ts +30 -0
  107. package/dist/observer/allowlist.d.ts.map +1 -0
  108. package/dist/observer/bus-translate.d.ts +33 -0
  109. package/dist/observer/bus-translate.d.ts.map +1 -0
  110. package/dist/observer/index.d.ts +44 -0
  111. package/dist/observer/index.d.ts.map +1 -0
  112. package/dist/observer/queue.d.ts +63 -0
  113. package/dist/observer/queue.d.ts.map +1 -0
  114. package/dist/observer/transport.d.ts +27 -0
  115. package/dist/observer/transport.d.ts.map +1 -0
  116. package/dist/personas.d.ts +30 -0
  117. package/dist/personas.d.ts.map +1 -0
  118. package/dist/runtime.d.ts +9 -0
  119. package/dist/runtime.d.ts.map +1 -1
  120. package/dist/runtime.js +2345 -3
  121. package/dist/runtime.js.map +4 -4
  122. package/dist/schema.d.ts +3426 -17
  123. package/dist/schema.d.ts.map +1 -1
  124. package/dist/schema.js +213 -0
  125. package/dist/schema.js.map +2 -2
  126. package/dist/test/setup.d.ts +1 -0
  127. package/dist/test/setup.d.ts.map +1 -0
  128. package/dist/types.d.ts +46 -2
  129. package/dist/types.d.ts.map +1 -1
  130. package/package.json +17 -1
  131. package/dist/chunk-W457NMGD.js.map +0 -7
@@ -0,0 +1,4015 @@
1
+ import {
2
+ __publicField
3
+ } from "./chunk-UVKRO5ER.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(html9) {
227
+ return html9;
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 = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
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
+ import { html as html8, LitElement as LitElement2 } from "lit";
2242
+ function getCtor() {
2243
+ if (typeof window === "undefined") return void 0;
2244
+ const w2 = window;
2245
+ return w2.SpeechRecognition ?? w2.webkitSpeechRecognition;
2246
+ }
2247
+ function isDictationSupported() {
2248
+ return getCtor() !== void 0;
2249
+ }
2250
+ function mapError(engineCode) {
2251
+ switch (engineCode) {
2252
+ case "not-allowed":
2253
+ case "service-not-allowed":
2254
+ return "not-allowed";
2255
+ case "no-speech":
2256
+ return "no-speech";
2257
+ case "aborted":
2258
+ return "aborted";
2259
+ case "network":
2260
+ return "network";
2261
+ default:
2262
+ return "other";
2263
+ }
2264
+ }
2265
+ var MAX_SESSION_MS = 6e4;
2266
+ function createDictation(opts) {
2267
+ let rec = null;
2268
+ let listening = false;
2269
+ let capTimer = null;
2270
+ const finish = () => {
2271
+ if (capTimer !== null) {
2272
+ clearTimeout(capTimer);
2273
+ capTimer = null;
2274
+ }
2275
+ if (!listening) return;
2276
+ listening = false;
2277
+ rec = null;
2278
+ opts.onEnd();
2279
+ };
2280
+ return {
2281
+ get listening() {
2282
+ return listening;
2283
+ },
2284
+ start() {
2285
+ if (listening) return;
2286
+ const Ctor = getCtor();
2287
+ if (!Ctor) return;
2288
+ rec = new Ctor();
2289
+ rec.lang = opts.lang ?? (document.documentElement.lang || "en-US");
2290
+ rec.continuous = true;
2291
+ rec.interimResults = true;
2292
+ rec.onresult = (e) => {
2293
+ if (!listening) return;
2294
+ const parts = [];
2295
+ let allFinal = true;
2296
+ for (let i = 0; i < e.results.length; i++) {
2297
+ const result = e.results[i];
2298
+ const seg = result[0]?.transcript.trim() ?? "";
2299
+ if (!result.isFinal) allFinal = false;
2300
+ if (seg && seg !== parts[parts.length - 1]) parts.push(seg);
2301
+ }
2302
+ opts.onTranscript(parts.join(" "), allFinal);
2303
+ };
2304
+ rec.onerror = (e) => {
2305
+ const code = mapError(e.error);
2306
+ console.debug(`chat.dictation:error ${e.error} -> ${code}`);
2307
+ listening = false;
2308
+ rec = null;
2309
+ opts.onError(code);
2310
+ };
2311
+ rec.onend = finish;
2312
+ listening = true;
2313
+ capTimer = setTimeout(() => {
2314
+ console.debug("chat.dictation:cap 60s session limit reached \u2014 stopping");
2315
+ const active = rec;
2316
+ finish();
2317
+ active?.stop();
2318
+ }, MAX_SESSION_MS);
2319
+ rec.start();
2320
+ },
2321
+ stop() {
2322
+ const active = rec;
2323
+ finish();
2324
+ active?.stop();
2325
+ }
2326
+ };
2327
+ }
2328
+ 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>`;
2329
+ 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>`;
2330
+ var micIcon = html2`<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="6" y="1.5" width="4" height="8" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M3.5 7.5a4.5 4.5 0 0 0 9 0M8 12v2.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>`;
2331
+ function autoResize(e) {
2332
+ const el = e.target;
2333
+ el.style.height = "auto";
2334
+ const capped = Math.min(el.scrollHeight, 150);
2335
+ el.style.height = `${capped}px`;
2336
+ el.style.overflowY = capped >= 150 ? "auto" : "hidden";
2337
+ }
2338
+ function renderChatInput(props) {
2339
+ const canSend = props.value.trim().length > 0 && !props.isStreaming;
2340
+ const buttonLabel = props.isStreaming ? "Stop generation" : "Send message";
2341
+ const buttonAction = props.isStreaming ? props.onStop : props.onSend;
2342
+ const handleInput = (e) => {
2343
+ autoResize(e);
2344
+ props.onInput(e);
2345
+ };
2346
+ const placeholder = props.placeholder ?? "Type a message...";
2347
+ return html2`
2348
+ ${props.suggestions?.length && !props.isStreaming ? html2`<div data-sc-suggestions>
2349
+ ${props.suggestions.map(
2350
+ (s) => html2`<button @click=${() => props.onSuggestion?.(s)}>${s}</button>`
2351
+ )}
2352
+ </div>` : nothing}
2353
+ ${props.beforeInputSlot ?? nothing}
2354
+ <div data-sc-chat-input>
2355
+ <textarea
2356
+ rows="1"
2357
+ placeholder=${placeholder}
2358
+ .value=${props.value}
2359
+ @input=${handleInput}
2360
+ @keydown=${props.onKeyDown}
2361
+ @compositionstart=${props.onCompositionStart}
2362
+ @compositionend=${props.onCompositionEnd}
2363
+ aria-label="Message input"
2364
+ ></textarea>
2365
+ ${props.inputActionsSlot ?? nothing}
2366
+ ${props.showMic ? html2`<button
2367
+ data-sc-mic-btn
2368
+ data-listening=${props.micListening ? "true" : "false"}
2369
+ ?disabled=${props.micDisabled ?? false}
2370
+ @click=${props.onMicClick}
2371
+ aria-pressed=${props.micListening ? "true" : "false"}
2372
+ aria-label=${props.micListening ? "Stop dictation" : "Start dictation"}
2373
+ title=${props.micDisabled ? "Microphone blocked" : props.micListening ? "Stop dictation" : "Dictate"}
2374
+ >${micIcon}</button>` : nothing}
2375
+ <button
2376
+ data-sc-send-btn
2377
+ ?disabled=${!canSend && !props.isStreaming}
2378
+ @click=${buttonAction}
2379
+ aria-label=${buttonLabel}
2380
+ >${props.isStreaming ? stopIcon : sendIcon}</button>
2381
+ </div>
2382
+ `;
2383
+ }
2384
+ function fingerprint(msg) {
2385
+ const tcIds = msg.toolCalls?.map((tc) => {
2386
+ let resultKey = "-";
2387
+ if (tc.result !== void 0) {
2388
+ try {
2389
+ const json = JSON.stringify(tc.result);
2390
+ resultKey = json === void 0 ? "u" : String(json.length);
2391
+ } catch {
2392
+ resultKey = String(String(tc.result).length);
2393
+ }
2394
+ }
2395
+ return `${tc.id}:${tc.status}:${tc.interruptId ?? ""}:${resultKey}:${tc.error ?? ""}`;
2396
+ }).join(",") ?? "";
2397
+ return `${msg.id}:${msg.role}:${msg.content.length}:${msg.status}:${tcIds}`;
2398
+ }
2399
+ var marked = new B({ async: false, gfm: true, breaks: true });
2400
+ function escapeAttr(s) {
2401
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2402
+ }
2403
+ var codeRenderer = {
2404
+ code({ text: text2, lang }) {
2405
+ const safeLang = lang ? escapeAttr(lang) : "";
2406
+ const langAttr = safeLang ? ` class="language-${safeLang}"` : "";
2407
+ return `<div data-sc-code-block${safeLang ? ` data-lang="${safeLang}"` : ""}><pre><code${langAttr}>${text2}</code></pre></div>
2408
+ `;
2409
+ }
2410
+ };
2411
+ marked.use({ renderer: codeRenderer });
2412
+ function renderMarkdown(text2) {
2413
+ if (!text2) return "";
2414
+ const raw = marked.parse(text2);
2415
+ if (typeof window === "undefined") return raw;
2416
+ return purify.sanitize(raw, {
2417
+ ADD_ATTR: ["data-sc-code-block", "data-lang", "data-sc-copy-btn"]
2418
+ });
2419
+ }
2420
+ 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>`;
2421
+ 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>`;
2422
+ function renderActionBar(props) {
2423
+ const showRegenerate = props.role === "assistant" && props.onRegenerate;
2424
+ return html22`
2425
+ <div data-sc-action-bar>
2426
+ <button
2427
+ @click=${() => props.onCopy(props.content)}
2428
+ aria-label="Copy message"
2429
+ title="Copy"
2430
+ >${copyIcon}</button>
2431
+ ${showRegenerate ? html22`<button
2432
+ @click=${() => props.onRegenerate(props.messageId)}
2433
+ aria-label="Regenerate response"
2434
+ title="Regenerate"
2435
+ >${regenerateIcon}</button>` : ""}
2436
+ </div>
2437
+ `;
2438
+ }
2439
+ 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>`;
2440
+ 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>`;
2441
+ 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>`;
2442
+ 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>`;
2443
+ function statusIcon(status) {
2444
+ switch (status) {
2445
+ case "args-streaming":
2446
+ case "running":
2447
+ return spinnerIcon;
2448
+ case "done":
2449
+ return checkIcon;
2450
+ case "error":
2451
+ return errorIcon;
2452
+ default:
2453
+ return toolIcon;
2454
+ }
2455
+ }
2456
+ var STATUS_TEXT = {
2457
+ "args-streaming": "Running\u2026",
2458
+ running: "Running\u2026",
2459
+ pending: "Needs approval",
2460
+ done: "Done",
2461
+ error: "Failed",
2462
+ cancelled: "Cancelled"
2463
+ };
2464
+ function humanizeToolName(name) {
2465
+ const words = name.replace(/[_-]+/g, " ").trim();
2466
+ return words ? words.charAt(0).toUpperCase() + words.slice(1) : name;
2467
+ }
2468
+ var ARGS_SUMMARY_MAX = 90;
2469
+ var ARG_VALUE_MAX = 48;
2470
+ function summarizeArgs(args) {
2471
+ if (!args) return "";
2472
+ const bits = [];
2473
+ for (const [key, value] of Object.entries(args)) {
2474
+ if (value === null || value === void 0) continue;
2475
+ const t = typeof value;
2476
+ if (t !== "string" && t !== "number" && t !== "boolean") continue;
2477
+ let rendered = String(value);
2478
+ if (rendered.length > ARG_VALUE_MAX) rendered = `${rendered.slice(0, ARG_VALUE_MAX)}\u2026`;
2479
+ bits.push(`${key}: ${rendered}`);
2480
+ if (bits.join(" \xB7 ").length >= ARGS_SUMMARY_MAX) break;
2481
+ }
2482
+ let summary = bits.join(" \xB7 ");
2483
+ if (summary.length > ARGS_SUMMARY_MAX) summary = `${summary.slice(0, ARGS_SUMMARY_MAX)}\u2026`;
2484
+ return summary;
2485
+ }
2486
+ function renderToolCallCard(props) {
2487
+ const { toolCall, toolLabel, approve, deny } = props;
2488
+ const displayName = toolLabel ?? humanizeToolName(toolCall.name);
2489
+ const isActive = toolCall.status === "args-streaming" || toolCall.status === "running";
2490
+ const statusText = STATUS_TEXT[toolCall.status] ?? "";
2491
+ const argsSummary = summarizeArgs(toolCall.args);
2492
+ return html3`
2493
+ <div data-sc-tool-card ?data-sc-active=${isActive} data-sc-tool-phase=${toolCall.status}>
2494
+ <div data-sc-tool-header>
2495
+ <span data-sc-tool-icon data-sc-status=${toolCall.status}>${statusIcon(toolCall.status)}</span>
2496
+ <span data-sc-tool-name>${displayName}</span>
2497
+ ${statusText ? html3`<span data-sc-tool-status-text data-sc-status=${toolCall.status}>${statusText}</span>` : nothing2}
2498
+ </div>
2499
+ ${argsSummary ? html3`<div data-sc-tool-args>${argsSummary}</div>` : nothing2}
2500
+ ${toolCall.status === "error" && toolCall.error ? html3`<div data-sc-tool-error>${toolCall.error}</div>` : nothing2}
2501
+ ${toolCall.status === "pending" ? html3`<div data-sc-tool-actions>
2502
+ <button data-sc-approve @click=${approve} aria-label="Approve ${displayName}">Approve</button>
2503
+ <button data-sc-deny @click=${deny} aria-label="Deny ${displayName}">Deny</button>
2504
+ </div>` : nothing2}
2505
+ </div>
2506
+ `;
2507
+ }
2508
+ 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>`;
2509
+ function renderBubbleContent(message) {
2510
+ if (message.role === "user") {
2511
+ return html4`<div data-sc-msg-user>${message.content}</div>`;
2512
+ }
2513
+ return html4`<div data-sc-msg-assistant>${unsafeHTML(renderMarkdown(message.content))}</div>`;
2514
+ }
2515
+ function renderMessageBubble(props) {
2516
+ const { message, toolLabels, toolRenderers, toolContext, defaultToolRenderer } = props;
2517
+ const isUser = message.role === "user";
2518
+ const toolCards = message.toolCalls?.map((tc) => {
2519
+ const approve = (payload) => props.onToolApprove(tc.id, payload);
2520
+ const deny = () => props.onToolDeny(tc.id);
2521
+ const context = toolContext?.[tc.name];
2522
+ const customRenderer = toolRenderers?.[tc.name];
2523
+ if (customRenderer) {
2524
+ return customRenderer.render({
2525
+ toolCall: tc,
2526
+ phase: tc.status,
2527
+ approve,
2528
+ deny,
2529
+ context
2530
+ });
2531
+ }
2532
+ if (defaultToolRenderer) {
2533
+ return defaultToolRenderer.render({
2534
+ toolCall: tc,
2535
+ phase: tc.status,
2536
+ approve,
2537
+ deny,
2538
+ context
2539
+ });
2540
+ }
2541
+ return renderToolCallCard({
2542
+ toolCall: tc,
2543
+ toolLabel: toolLabels?.[tc.name],
2544
+ approve: () => approve(),
2545
+ deny
2546
+ });
2547
+ });
2548
+ return html4`
2549
+ <div data-sc-msg-row data-sc-role=${message.role} data-sc-msg-id=${message.id}>
2550
+ ${!isUser ? assistantIcon : nothing3}
2551
+ <div data-sc-msg-content>
2552
+ ${renderBubbleContent(message)}
2553
+ ${message.status === "error" ? html4`<div data-sc-msg-error>${isUser ? "Failed to send" : "Response interrupted"}</div>` : nothing3}
2554
+ ${toolCards ?? nothing3}
2555
+ ${renderActionBar({
2556
+ messageId: message.id,
2557
+ content: message.content,
2558
+ role: message.role,
2559
+ onCopy: props.onCopy,
2560
+ onRegenerate: isUser ? void 0 : props.onRegenerate
2561
+ })}
2562
+ </div>
2563
+ </div>
2564
+ `;
2565
+ }
2566
+ function renderTypingIndicator() {
2567
+ return html5`
2568
+ <div data-sc-typing aria-label="Assistant is typing">
2569
+ <span></span><span></span><span></span>
2570
+ </div>
2571
+ `;
2572
+ }
2573
+ function renderMessageList(props) {
2574
+ if (props.messages.length === 0 && !props.isTyping) {
2575
+ return html6`<div role="log" aria-live="polite" aria-label="Chat messages">
2576
+ ${props.emptyStateSlot ?? nothing4}
2577
+ </div>`;
2578
+ }
2579
+ return html6`
2580
+ <div role="log" aria-live="polite" aria-label="Chat messages" data-sc-msg-list>
2581
+ ${repeat(
2582
+ props.messages,
2583
+ (msg) => msg.id,
2584
+ (msg) => guard(
2585
+ [fingerprint(msg), props.toolContext],
2586
+ () => renderMessageBubble({
2587
+ message: msg,
2588
+ toolLabels: props.toolLabels,
2589
+ toolRenderers: props.toolRenderers,
2590
+ toolContext: props.toolContext,
2591
+ defaultToolRenderer: props.defaultToolRenderer,
2592
+ onCopy: props.onCopy,
2593
+ onRegenerate: props.onRegenerate,
2594
+ onToolApprove: props.onToolApprove,
2595
+ onToolDeny: props.onToolDeny
2596
+ })
2597
+ )
2598
+ )}
2599
+ ${props.isTyping ? props.typingIndicatorSlot ?? renderTypingIndicator() : nothing4}
2600
+ </div>
2601
+ `;
2602
+ }
2603
+ var STYLE_ID = "sc-chat-styles";
2604
+ var STYLE_RULES = `
2605
+ @keyframes sc-fade-in {
2606
+ from { opacity: 0; transform: translateY(6px); }
2607
+ to { opacity: 1; transform: translateY(0); }
2608
+ }
2609
+
2610
+ @keyframes sc-typing-bounce {
2611
+ 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
2612
+ 40% { transform: scale(1); opacity: 1; }
2613
+ }
2614
+
2615
+ @keyframes sc-spin {
2616
+ to { transform: rotate(360deg); }
2617
+ }
2618
+
2619
+ [data-sc-chat] {
2620
+ font-family: var(--sc-font-family, system-ui, -apple-system, sans-serif);
2621
+ color: var(--sc-content-text-color, #1a1a2e);
2622
+ line-height: var(--sc-chat-line-height, 1.5);
2623
+ font-size: var(--sc-chat-font-size, 0.9375rem);
2624
+ }
2625
+
2626
+ /* \u2500\u2500 Message list \u2500\u2500 */
2627
+ [data-sc-chat] [data-sc-msg-list] {
2628
+ display: flex;
2629
+ flex-direction: column;
2630
+ gap: var(--sc-chat-msg-gap, 4px);
2631
+ padding: var(--sc-chat-msg-list-padding, 16px 16px 8px);
2632
+ }
2633
+
2634
+ /* \u2500\u2500 Message row (avatar + content) \u2500\u2500 */
2635
+ [data-sc-chat] [data-sc-msg-row] {
2636
+ display: flex;
2637
+ gap: 10px;
2638
+ align-items: flex-start;
2639
+ animation: sc-fade-in 0.25s ease-out;
2640
+ }
2641
+
2642
+ [data-sc-chat] [data-sc-msg-row][data-sc-role="user"] {
2643
+ flex-direction: row-reverse;
2644
+ }
2645
+
2646
+ [data-sc-chat] [data-sc-msg-content] {
2647
+ min-width: 0;
2648
+ max-width: 80%;
2649
+ }
2650
+
2651
+ [data-sc-chat] [data-sc-msg-row][data-sc-role="user"] [data-sc-msg-content] {
2652
+ display: flex;
2653
+ flex-direction: column;
2654
+ align-items: flex-end;
2655
+ }
2656
+
2657
+ /* \u2500\u2500 Avatar \u2500\u2500 */
2658
+ [data-sc-chat] [data-sc-avatar] {
2659
+ flex-shrink: 0;
2660
+ margin-top: 2px;
2661
+ }
2662
+
2663
+ /* \u2500\u2500 Bubbles \u2500\u2500 */
2664
+ [data-sc-chat] [data-sc-msg-user] {
2665
+ background: var(--sc-chat-msg-user-bg, var(--sc-color-primary, #6a59ce));
2666
+ color: var(--sc-chat-msg-user-color, var(--sc-color-primary-text, #ffffff));
2667
+ border-radius: var(--sc-chat-msg-user-radius, 18px 18px 4px 18px);
2668
+ padding: var(--sc-chat-msg-user-padding, 10px 16px);
2669
+ word-break: break-word;
2670
+ }
2671
+
2672
+ [data-sc-chat] [data-sc-msg-assistant] {
2673
+ background: var(--sc-chat-msg-assistant-bg, var(--sc-chat-assistant-bubble-bg, #f4f4f8));
2674
+ color: var(--sc-chat-msg-assistant-color, var(--sc-content-text-color, #1a1a2e));
2675
+ border-radius: var(--sc-chat-msg-assistant-radius, 18px 18px 18px 4px);
2676
+ padding: var(--sc-chat-msg-assistant-padding, 10px 16px);
2677
+ box-shadow: var(--sc-chat-msg-assistant-shadow, 0 1px 2px rgba(0, 0, 0, 0.04));
2678
+ word-break: break-word;
2679
+ }
2680
+
2681
+ [data-sc-chat] [data-sc-msg-assistant] > :first-child { margin-top: 0; }
2682
+ [data-sc-chat] [data-sc-msg-assistant] > :last-child { margin-bottom: 0; }
2683
+
2684
+ [data-sc-chat] [data-sc-msg-assistant] p,
2685
+ [data-sc-chat] [data-sc-msg-assistant] ul,
2686
+ [data-sc-chat] [data-sc-msg-assistant] ol,
2687
+ [data-sc-chat] [data-sc-msg-assistant] pre,
2688
+ [data-sc-chat] [data-sc-msg-assistant] blockquote {
2689
+ margin: 0.25em 0;
2690
+ }
2691
+
2692
+ [data-sc-chat] [data-sc-msg-assistant] code:not(pre code) {
2693
+ background: rgba(0, 0, 0, 0.06);
2694
+ padding: 1px 5px;
2695
+ border-radius: 4px;
2696
+ font-size: 0.85em;
2697
+ }
2698
+
2699
+ [data-sc-chat] [data-sc-msg-assistant] ul,
2700
+ [data-sc-chat] [data-sc-msg-assistant] ol {
2701
+ padding-left: 1.2em;
2702
+ }
2703
+
2704
+ [data-sc-chat] [data-sc-msg-assistant] h1,
2705
+ [data-sc-chat] [data-sc-msg-assistant] h2,
2706
+ [data-sc-chat] [data-sc-msg-assistant] h3 {
2707
+ margin: 0.5rem 0 0.25rem;
2708
+ color: var(--sc-content-heading-color, #1a1a2e);
2709
+ }
2710
+
2711
+ /* \u2500\u2500 Code blocks \u2500\u2500 */
2712
+ [data-sc-chat] [data-sc-code-block] {
2713
+ position: relative;
2714
+ margin: 0.5rem 0;
2715
+ }
2716
+
2717
+ [data-sc-chat] [data-sc-code-block]::before {
2718
+ content: attr(data-lang);
2719
+ position: absolute;
2720
+ top: 0;
2721
+ right: 0;
2722
+ padding: 2px 10px;
2723
+ font-size: 0.7rem;
2724
+ color: rgba(255, 255, 255, 0.4);
2725
+ text-transform: uppercase;
2726
+ letter-spacing: 0.05em;
2727
+ }
2728
+
2729
+ [data-sc-chat] [data-sc-code-block] pre {
2730
+ background: var(--sc-chat-code-bg, #1e1e2e);
2731
+ color: #e0e0e0;
2732
+ border-radius: 10px;
2733
+ padding: 14px;
2734
+ overflow-x: auto;
2735
+ font-size: 0.825em;
2736
+ margin: 0;
2737
+ line-height: 1.6;
2738
+ }
2739
+
2740
+ [data-sc-chat] [data-sc-code-block] [data-sc-copy-btn] {
2741
+ position: absolute;
2742
+ top: 8px;
2743
+ right: 8px;
2744
+ background: rgba(255, 255, 255, 0.08);
2745
+ border: none;
2746
+ color: rgba(255, 255, 255, 0.5);
2747
+ border-radius: 6px;
2748
+ padding: 4px 10px;
2749
+ cursor: pointer;
2750
+ font-size: 0.7rem;
2751
+ opacity: 0;
2752
+ transition: opacity 0.15s, background 0.15s;
2753
+ }
2754
+
2755
+ [data-sc-chat] [data-sc-code-block]:hover [data-sc-copy-btn] {
2756
+ opacity: 1;
2757
+ }
2758
+
2759
+ [data-sc-chat] [data-sc-code-block] [data-sc-copy-btn]:hover {
2760
+ background: rgba(255, 255, 255, 0.16);
2761
+ color: rgba(255, 255, 255, 0.8);
2762
+ }
2763
+
2764
+ /* \u2500\u2500 Scrollbar \u2500\u2500 */
2765
+ [data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar {
2766
+ width: 4px;
2767
+ }
2768
+ [data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-track {
2769
+ background: transparent;
2770
+ }
2771
+ [data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-thumb {
2772
+ background: rgba(0, 0, 0, 0.12);
2773
+ border-radius: 4px;
2774
+ }
2775
+ [data-sc-chat] [data-sc-scroll-area]::-webkit-scrollbar-thumb:hover {
2776
+ background: rgba(0, 0, 0, 0.2);
2777
+ }
2778
+
2779
+ [data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar {
2780
+ height: 4px;
2781
+ }
2782
+ [data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar-track {
2783
+ background: transparent;
2784
+ }
2785
+ [data-sc-chat] [data-sc-code-block] pre::-webkit-scrollbar-thumb {
2786
+ background: rgba(255, 255, 255, 0.15);
2787
+ border-radius: 4px;
2788
+ }
2789
+
2790
+ /* \u2500\u2500 Chat input area \u2500\u2500 */
2791
+ [data-sc-chat] [data-sc-chat-input] {
2792
+ display: flex;
2793
+ align-items: flex-end;
2794
+ gap: 8px;
2795
+ padding: var(--sc-chat-input-padding, 12px 16px);
2796
+ border-top: 1px solid var(--sc-content-border-color, #e8e8ee);
2797
+ background: var(--sc-chat-input-bg, #ffffff);
2798
+ }
2799
+
2800
+ [data-sc-chat] [data-sc-chat-input] textarea {
2801
+ flex: 1;
2802
+ border: 1px solid var(--sc-content-border-color, #e8e8ee);
2803
+ border-radius: var(--sc-chat-textarea-radius, 14px);
2804
+ padding: var(--sc-chat-textarea-padding, 10px 16px);
2805
+ font-family: inherit;
2806
+ /* >= 16px: iOS Safari auto-zooms a focused input < 16px and never zooms back
2807
+ out (same class as the vela AdaptiveChatBar composer fix). 0.9rem was 14.4px
2808
+ \u2192 zoom-on-focus + stuck-zoomed on the native <syntro-chat> mobile surfaces.
2809
+ A workspace can still override the token, but must keep it >= 16px on mobile. */
2810
+ font-size: var(--sc-chat-textarea-font-size, 1rem);
2811
+ resize: none;
2812
+ outline: none;
2813
+ background: var(--sc-chat-input-bg, #ffffff);
2814
+ color: var(--sc-content-text-color, #1a1a2e);
2815
+ min-height: 42px;
2816
+ max-height: 150px;
2817
+ line-height: 1.4;
2818
+ transition: border-color 0.2s, box-shadow 0.2s;
2819
+ overflow-y: hidden;
2820
+ }
2821
+
2822
+ [data-sc-chat] [data-sc-chat-input] textarea:focus {
2823
+ border-color: var(--sc-color-primary, #6a59ce);
2824
+ box-shadow: 0 0 0 3px var(--sc-chat-focus-ring, rgba(106, 89, 206, 0.1));
2825
+ }
2826
+
2827
+ [data-sc-chat] [data-sc-send-btn] {
2828
+ background: var(--sc-color-primary, #6a59ce);
2829
+ color: var(--sc-color-primary-text, #ffffff);
2830
+ border: none;
2831
+ border-radius: var(--sc-chat-send-btn-radius, 50%);
2832
+ width: var(--sc-chat-send-btn-size, 38px);
2833
+ height: var(--sc-chat-send-btn-size, 38px);
2834
+ cursor: pointer;
2835
+ display: flex;
2836
+ align-items: center;
2837
+ justify-content: center;
2838
+ flex-shrink: 0;
2839
+ transition: background 0.2s, transform 0.15s, opacity 0.2s;
2840
+ }
2841
+
2842
+ [data-sc-chat] [data-sc-send-btn]:hover:not(:disabled) {
2843
+ background: var(--sc-color-primary-hover, #5a49be);
2844
+ transform: scale(1.05);
2845
+ }
2846
+
2847
+ [data-sc-chat] [data-sc-send-btn]:active:not(:disabled) {
2848
+ transform: scale(0.95);
2849
+ }
2850
+
2851
+ [data-sc-chat] [data-sc-send-btn]:disabled {
2852
+ background: var(--sc-content-border-color, #e8e8ee);
2853
+ color: var(--sc-content-text-secondary-color, #87919f);
2854
+ cursor: default;
2855
+ }
2856
+
2857
+ [data-sc-chat] [data-sc-send-btn] svg {
2858
+ display: block;
2859
+ }
2860
+
2861
+ [data-sc-chat] [data-sc-mic-btn] {
2862
+ background: transparent;
2863
+ color: var(--sc-content-text-secondary-color, #87919f);
2864
+ border: none;
2865
+ border-radius: 50%;
2866
+ width: var(--sc-chat-send-btn-size, 38px);
2867
+ height: var(--sc-chat-send-btn-size, 38px);
2868
+ cursor: pointer;
2869
+ display: flex;
2870
+ align-items: center;
2871
+ justify-content: center;
2872
+ flex-shrink: 0;
2873
+ transition: color 0.2s, transform 0.15s, opacity 0.2s;
2874
+ }
2875
+
2876
+ [data-sc-chat] [data-sc-mic-btn]:hover:not(:disabled) {
2877
+ color: var(--sc-color-primary, #6a59ce);
2878
+ }
2879
+
2880
+ [data-sc-chat] [data-sc-mic-btn]:disabled {
2881
+ opacity: 0.35;
2882
+ cursor: not-allowed;
2883
+ }
2884
+
2885
+ [data-sc-chat] [data-sc-mic-btn][data-listening='true'] {
2886
+ background: var(--sc-color-primary, #6a59ce);
2887
+ color: var(--sc-color-primary-text, #ffffff);
2888
+ animation: sc-mic-ring 1.5s ease-out infinite;
2889
+ }
2890
+
2891
+ @keyframes sc-mic-ring {
2892
+ 0% {
2893
+ box-shadow: 0 0 0 0 color-mix(in srgb, var(--sc-color-primary, #6a59ce) 45%, transparent);
2894
+ transform: scale(1);
2895
+ }
2896
+ 50% { transform: scale(1.08); }
2897
+ 70% { box-shadow: 0 0 0 12px transparent; }
2898
+ 100% {
2899
+ box-shadow: 0 0 0 0 transparent;
2900
+ transform: scale(1);
2901
+ }
2902
+ }
2903
+
2904
+ @media (prefers-reduced-motion: reduce) {
2905
+ [data-sc-chat] [data-sc-mic-btn][data-listening='true'] {
2906
+ animation: none;
2907
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--sc-color-primary, #6a59ce) 35%, transparent);
2908
+ }
2909
+ }
2910
+
2911
+ [data-sc-chat] [data-sc-mic-btn] svg {
2912
+ display: block;
2913
+ }
2914
+
2915
+ /* \u2500\u2500 Typing indicator (compact: three bouncing dots) \u2500\u2500 */
2916
+ [data-sc-chat] [data-sc-typing] {
2917
+ display: flex;
2918
+ gap: 4px;
2919
+ padding: 12px 16px;
2920
+ background: var(--sc-chat-loading-bg, #f4f4f8);
2921
+ border-radius: 18px 18px 18px 4px;
2922
+ width: fit-content;
2923
+ margin-left: 34px;
2924
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
2925
+ }
2926
+
2927
+ [data-sc-chat] [data-sc-typing] span {
2928
+ width: 6px;
2929
+ height: 6px;
2930
+ border-radius: 50%;
2931
+ background: var(--sc-content-text-secondary-color, #87919f);
2932
+ animation: sc-typing-bounce 1.4s infinite ease-in-out both;
2933
+ }
2934
+
2935
+ [data-sc-chat] [data-sc-typing] span:nth-child(2) { animation-delay: 0.16s; }
2936
+ [data-sc-chat] [data-sc-typing] span:nth-child(3) { animation-delay: 0.32s; }
2937
+
2938
+ /* \u2500\u2500 Suggestion chips \u2500\u2500 */
2939
+ [data-sc-chat] [data-sc-suggestions] {
2940
+ display: flex;
2941
+ flex-wrap: wrap;
2942
+ gap: 8px;
2943
+ padding: 8px 16px;
2944
+ }
2945
+
2946
+ [data-sc-chat] [data-sc-suggestions] button {
2947
+ background: transparent;
2948
+ border: 1px solid var(--sc-content-border-color, #e8e8ee);
2949
+ border-radius: 20px;
2950
+ padding: 7px 16px;
2951
+ font-size: 0.84rem;
2952
+ cursor: pointer;
2953
+ color: var(--sc-content-text-color, #1a1a2e);
2954
+ transition: all 0.2s;
2955
+ }
2956
+
2957
+ [data-sc-chat] [data-sc-suggestions] button:hover {
2958
+ background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
2959
+ border-color: var(--sc-color-primary, #6a59ce);
2960
+ color: var(--sc-color-primary, #6a59ce);
2961
+ transform: translateY(-1px);
2962
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
2963
+ }
2964
+
2965
+ /* \u2500\u2500 Action bar (hover-revealed message actions: copy, regenerate) \u2500\u2500 */
2966
+ [data-sc-chat] [data-sc-action-bar] {
2967
+ display: none;
2968
+ gap: 2px;
2969
+ padding-top: 2px;
2970
+ }
2971
+
2972
+ [data-sc-chat] [data-sc-msg-row]:hover [data-sc-action-bar] {
2973
+ display: flex;
2974
+ }
2975
+
2976
+ [data-sc-chat] [data-sc-action-bar] button {
2977
+ background: transparent;
2978
+ border: none;
2979
+ border-radius: 6px;
2980
+ padding: 5px;
2981
+ cursor: pointer;
2982
+ color: var(--sc-content-text-secondary-color, #87919f);
2983
+ display: flex;
2984
+ align-items: center;
2985
+ justify-content: center;
2986
+ width: 28px;
2987
+ height: 28px;
2988
+ transition: background 0.15s, color 0.15s;
2989
+ }
2990
+
2991
+ [data-sc-chat] [data-sc-action-bar] button:hover {
2992
+ background: var(--sc-chat-action-bar-bg, rgba(0, 0, 0, 0.06));
2993
+ color: var(--sc-content-text-color, #1a1a2e);
2994
+ }
2995
+
2996
+ /* \u2500\u2500 Tool call cards (compact: bordered card + icon) \u2500\u2500 */
2997
+ [data-sc-chat] [data-sc-tool-card] {
2998
+ border: 1px solid var(--sc-content-border-color, #e8e8ee);
2999
+ border-left: 3px solid var(--sc-color-primary, #6a59ce);
3000
+ border-radius: 4px 10px 10px 4px;
3001
+ padding: 10px 14px;
3002
+ margin-top: 8px;
3003
+ font-size: 0.84rem;
3004
+ background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
3005
+ transition: border-color 0.2s;
3006
+ }
3007
+
3008
+ [data-sc-chat] [data-sc-tool-card][data-sc-active] {
3009
+ border-left-color: #3b82f6;
3010
+ }
3011
+
3012
+ [data-sc-chat] [data-sc-tool-header] {
3013
+ display: flex;
3014
+ align-items: center;
3015
+ gap: 8px;
3016
+ }
3017
+
3018
+ [data-sc-chat] [data-sc-tool-icon] {
3019
+ display: flex;
3020
+ color: var(--sc-color-primary, #6a59ce);
3021
+ }
3022
+
3023
+ [data-sc-chat] [data-sc-tool-icon][data-sc-status="done"] {
3024
+ color: #22c55e;
3025
+ }
3026
+
3027
+ [data-sc-chat] [data-sc-tool-icon][data-sc-status="error"] {
3028
+ color: #ef4444;
3029
+ }
3030
+
3031
+ [data-sc-chat] [data-sc-tool-icon][data-sc-status="running"],
3032
+ [data-sc-chat] [data-sc-tool-icon][data-sc-status="args-streaming"] {
3033
+ color: #3b82f6;
3034
+ }
3035
+
3036
+ [data-sc-chat] [data-sc-spinner] {
3037
+ animation: sc-spin 0.8s linear infinite;
3038
+ }
3039
+
3040
+ [data-sc-chat] [data-sc-tool-name] {
3041
+ font-weight: 600;
3042
+ }
3043
+
3044
+ [data-sc-chat] [data-sc-tool-status-text] {
3045
+ margin-left: auto;
3046
+ font-size: 0.72rem;
3047
+ font-weight: 500;
3048
+ letter-spacing: 0.02em;
3049
+ text-transform: uppercase;
3050
+ color: var(--sc-content-text-secondary-color, #6b6b80);
3051
+ white-space: nowrap;
3052
+ }
3053
+
3054
+ [data-sc-chat] [data-sc-tool-status-text][data-sc-status="done"] {
3055
+ color: #22c55e;
3056
+ }
3057
+
3058
+ [data-sc-chat] [data-sc-tool-status-text][data-sc-status="error"] {
3059
+ color: #ef4444;
3060
+ }
3061
+
3062
+ [data-sc-chat] [data-sc-tool-status-text][data-sc-status="running"],
3063
+ [data-sc-chat] [data-sc-tool-status-text][data-sc-status="args-streaming"] {
3064
+ color: #3b82f6;
3065
+ }
3066
+
3067
+ [data-sc-chat] [data-sc-tool-status-text][data-sc-status="cancelled"] {
3068
+ color: var(--sc-content-text-secondary-color, #6b6b80);
3069
+ text-decoration: line-through;
3070
+ }
3071
+
3072
+ [data-sc-chat] [data-sc-tool-args] {
3073
+ margin-top: 6px;
3074
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
3075
+ font-size: 0.76rem;
3076
+ color: var(--sc-content-text-secondary-color, #6b6b80);
3077
+ overflow: hidden;
3078
+ text-overflow: ellipsis;
3079
+ white-space: nowrap;
3080
+ }
3081
+
3082
+ [data-sc-chat] [data-sc-tool-card][data-sc-tool-phase="cancelled"] {
3083
+ opacity: 0.65;
3084
+ border-left-color: var(--sc-content-border-color, #e8e8ee);
3085
+ }
3086
+
3087
+ [data-sc-chat] [data-sc-tool-error] {
3088
+ color: #ef4444;
3089
+ font-size: 0.8rem;
3090
+ margin-top: 6px;
3091
+ }
3092
+
3093
+ [data-sc-chat] [data-sc-tool-actions] {
3094
+ display: flex;
3095
+ gap: 8px;
3096
+ margin-top: 10px;
3097
+ }
3098
+
3099
+ [data-sc-chat] [data-sc-tool-actions] button {
3100
+ padding: 5px 14px;
3101
+ border-radius: 8px;
3102
+ font-size: 0.8rem;
3103
+ cursor: pointer;
3104
+ border: 1px solid var(--sc-content-border-color, #e8e8ee);
3105
+ background: transparent;
3106
+ transition: all 0.15s;
3107
+ }
3108
+
3109
+ [data-sc-chat] [data-sc-tool-actions] [data-sc-approve] {
3110
+ background: var(--sc-color-primary, #6a59ce);
3111
+ color: var(--sc-color-primary-text, #ffffff);
3112
+ border-color: transparent;
3113
+ }
3114
+
3115
+ [data-sc-chat] [data-sc-tool-actions] [data-sc-approve]:hover {
3116
+ filter: brightness(1.1);
3117
+ }
3118
+
3119
+ [data-sc-chat] [data-sc-tool-actions] [data-sc-deny] {
3120
+ color: var(--sc-content-text-secondary-color, #87919f);
3121
+ }
3122
+
3123
+ [data-sc-chat] [data-sc-tool-actions] [data-sc-deny]:hover {
3124
+ border-color: #ef4444;
3125
+ color: #ef4444;
3126
+ }
3127
+
3128
+ /* \u2500\u2500 Error banner \u2500\u2500 */
3129
+ [data-sc-chat] [data-sc-error] {
3130
+ background: #fef2f2;
3131
+ border-left: 3px solid #ef4444;
3132
+ padding: 8px 12px;
3133
+ border-radius: 0 8px 8px 0;
3134
+ font-size: 0.84rem;
3135
+ color: #dc2626;
3136
+ }
3137
+
3138
+ [data-sc-chat] [data-sc-msg-error] {
3139
+ font-size: 0.8rem;
3140
+ color: #ef4444;
3141
+ margin-top: 4px;
3142
+ }
3143
+
3144
+ /* \u2500\u2500 "Scroll to most recent" pill \u2500\u2500 */
3145
+ [data-sc-chat] [data-sc-scroll-btn] {
3146
+ position: absolute;
3147
+ bottom: 80px;
3148
+ left: 50%;
3149
+ transform: translateX(-50%);
3150
+ background: var(--sc-chat-assistant-bubble-bg, #f4f4f8);
3151
+ color: var(--sc-content-text-color, #1a1a2e);
3152
+ border: 1px solid var(--sc-content-border-color, #e8e8ee);
3153
+ border-radius: 9999px;
3154
+ height: 28px;
3155
+ padding: 0 10px;
3156
+ display: flex;
3157
+ align-items: center;
3158
+ justify-content: center;
3159
+ gap: 5px;
3160
+ font-size: 12px;
3161
+ font-weight: 500;
3162
+ line-height: 1;
3163
+ white-space: nowrap;
3164
+ cursor: pointer;
3165
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
3166
+ z-index: 1;
3167
+ transition: box-shadow 0.2s;
3168
+ }
3169
+
3170
+ [data-sc-chat] [data-sc-scroll-btn]:hover {
3171
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
3172
+ }
3173
+
3174
+ [data-sc-chat] [data-sc-scroll-btn] svg {
3175
+ display: block;
3176
+ }
3177
+
3178
+
3179
+ `.trim();
3180
+ function injectChatStyles(root = typeof document === "undefined" ? void 0 : document) {
3181
+ if (!root) return;
3182
+ if (root.getElementById?.(STYLE_ID) ?? root.querySelector(`#${STYLE_ID}`)) return;
3183
+ const style = document.createElement("style");
3184
+ style.id = STYLE_ID;
3185
+ style.textContent = STYLE_RULES;
3186
+ if (root instanceof Document) {
3187
+ root.head.appendChild(style);
3188
+ return;
3189
+ }
3190
+ root.insertBefore(style, root.firstChild ?? null);
3191
+ }
3192
+ var _SyntroChat = class _SyntroChat2 extends LitElement {
3193
+ constructor() {
3194
+ super(...arguments);
3195
+ this.voiceInput = false;
3196
+ this._messages = [];
3197
+ this._micListening = false;
3198
+ this._micDisabled = false;
3199
+ this._micBase = "";
3200
+ this._micNetworkErrors = 0;
3201
+ this._dictation = null;
3202
+ this._isTyping = false;
3203
+ this._inputValue = "";
3204
+ this._isComposing = false;
3205
+ this._isStreaming = false;
3206
+ this._unsubscribe = null;
3207
+ this._scrollContainer = null;
3208
+ this._errorMessage = null;
3209
+ this._stickToBottom = true;
3210
+ this._messagesBelow = 0;
3211
+ this._lastUserScrollIntentTs = 0;
3212
+ this._markUserScrollIntent = () => {
3213
+ this._lastUserScrollIntentTs = Date.now();
3214
+ };
3215
+ this._handleScroll = () => {
3216
+ if (!this._scrollContainer) return;
3217
+ const atBottom = this._isAtBottom();
3218
+ this._messagesBelow = atBottom ? 0 : this._countMessagesBelow();
3219
+ const isUserDriven = Date.now() - this._lastUserScrollIntentTs < _SyntroChat2._USER_SCROLL_INTENT_WINDOW_MS;
3220
+ if (isUserDriven) {
3221
+ this._stickToBottom = atBottom;
3222
+ }
3223
+ };
3224
+ this._resumeFollowing = () => {
3225
+ this._stickToBottom = true;
3226
+ this._scrollToBottom();
3227
+ };
3228
+ this._handleEvent = (event) => {
3229
+ switch (event.type) {
3230
+ case "session-ready":
3231
+ break;
3232
+ case "messages-snapshot":
3233
+ this._messages = [...event.messages];
3234
+ this._isStreaming = event.messages.some((m2) => m2.status === "streaming");
3235
+ this._stickToBottom = true;
3236
+ this._scrollToBottom();
3237
+ break;
3238
+ case "message-append":
3239
+ if (!this._messages.some((m2) => m2.id === event.message.id)) {
3240
+ this._messages = [...this._messages, event.message];
3241
+ }
3242
+ this._isStreaming = event.message.status === "streaming";
3243
+ if (event.message.role === "user") {
3244
+ this._anchorToMessage(event.message.id);
3245
+ } else {
3246
+ this._onContentGrowth();
3247
+ }
3248
+ break;
3249
+ case "message-delta": {
3250
+ this._messages = this._messages.map(
3251
+ (m2) => m2.id === event.messageId ? { ...m2, content: m2.content + event.delta } : m2
3252
+ );
3253
+ this._onContentGrowth();
3254
+ break;
3255
+ }
3256
+ case "message-complete":
3257
+ this._messages = this._messages.map(
3258
+ (m2) => m2.id === event.messageId ? { ...m2, status: "complete" } : m2
3259
+ );
3260
+ this._isStreaming = false;
3261
+ break;
3262
+ case "typing":
3263
+ this._isTyping = event.isTyping;
3264
+ if (event.isTyping) this._onContentGrowth();
3265
+ break;
3266
+ case "tool-call": {
3267
+ const hasParent = this._messages.some((m2) => m2.id === event.messageId);
3268
+ if (!hasParent) {
3269
+ this._messages = [
3270
+ ...this._messages,
3271
+ {
3272
+ id: event.messageId,
3273
+ role: "assistant",
3274
+ content: "",
3275
+ timestamp: Date.now(),
3276
+ status: "streaming"
3277
+ }
3278
+ ];
3279
+ }
3280
+ this._messages = this._messages.map((m2) => {
3281
+ if (m2.id !== event.messageId) return m2;
3282
+ const existing = (m2.toolCalls ?? []).findIndex((tc) => tc.id === event.toolCall.id);
3283
+ if (existing >= 0) {
3284
+ const toolCalls = [...m2.toolCalls ?? []];
3285
+ toolCalls[existing] = event.toolCall;
3286
+ return { ...m2, toolCalls };
3287
+ }
3288
+ return { ...m2, toolCalls: [...m2.toolCalls ?? [], event.toolCall] };
3289
+ });
3290
+ if (this.autoExecTools?.has(event.toolCall.name) && event.toolCall.status === "pending") {
3291
+ this._markToolDone(event.toolCall.id);
3292
+ this.transport.send({
3293
+ type: "tool-result",
3294
+ toolCallId: event.toolCall.id,
3295
+ result: null,
3296
+ approved: true
3297
+ });
3298
+ }
3299
+ break;
3300
+ }
3301
+ case "tool-call-args-delta": {
3302
+ this._messages = this._messages.map((m2) => {
3303
+ if (!m2.toolCalls) return m2;
3304
+ const toolCalls = m2.toolCalls.map(
3305
+ (tc) => tc.id === event.toolCallId ? { ...tc, argsBuffer: tc.argsBuffer + event.delta } : tc
3306
+ );
3307
+ return { ...m2, toolCalls };
3308
+ });
3309
+ break;
3310
+ }
3311
+ case "tool-call-done": {
3312
+ this._messages = this._messages.map((m2) => {
3313
+ if (!m2.toolCalls) return m2;
3314
+ const toolCalls = m2.toolCalls.map((tc) => {
3315
+ if (tc.id !== event.toolCallId) return tc;
3316
+ let args;
3317
+ try {
3318
+ args = JSON.parse(tc.argsBuffer);
3319
+ } catch {
3320
+ args = void 0;
3321
+ }
3322
+ return { ...tc, status: "done", args };
3323
+ });
3324
+ return { ...m2, toolCalls };
3325
+ });
3326
+ break;
3327
+ }
3328
+ case "tool-call-deferred": {
3329
+ this._messages = this._messages.map((m2) => {
3330
+ if (!m2.toolCalls) return m2;
3331
+ const toolCalls = m2.toolCalls.map(
3332
+ (tc) => tc.id === event.toolCallId ? { ...tc, interruptId: event.interruptId, status: "pending" } : tc
3333
+ );
3334
+ return { ...m2, toolCalls };
3335
+ });
3336
+ break;
3337
+ }
3338
+ case "tool-call-cancelled": {
3339
+ this._messages = this._messages.map((m2) => {
3340
+ if (!m2.toolCalls) return m2;
3341
+ const toolCalls = m2.toolCalls.map(
3342
+ (tc) => tc.id === event.toolCallId ? { ...tc, status: "cancelled" } : tc
3343
+ );
3344
+ return { ...m2, toolCalls };
3345
+ });
3346
+ break;
3347
+ }
3348
+ case "tool-call-result": {
3349
+ let foundToolName;
3350
+ let lastIdx = -1;
3351
+ for (let i = this._messages.length - 1; i >= 0; i--) {
3352
+ if (this._messages[i].toolCalls?.some((tc) => tc.id === event.toolCallId)) {
3353
+ lastIdx = i;
3354
+ break;
3355
+ }
3356
+ }
3357
+ this._messages = this._messages.map((m2, idx) => {
3358
+ if (idx !== lastIdx || !m2.toolCalls) return m2;
3359
+ const toolCalls = m2.toolCalls.map((tc) => {
3360
+ if (tc.id !== event.toolCallId) return tc;
3361
+ foundToolName = tc.name;
3362
+ const status = tc.status === "cancelled" ? "cancelled" : "done";
3363
+ return { ...tc, result: event.result, status };
3364
+ });
3365
+ return { ...m2, toolCalls };
3366
+ });
3367
+ this.dispatchEvent(
3368
+ new CustomEvent("tool-result-received", {
3369
+ detail: {
3370
+ toolCallId: event.toolCallId,
3371
+ toolName: foundToolName,
3372
+ result: event.result
3373
+ },
3374
+ bubbles: true,
3375
+ composed: true
3376
+ })
3377
+ );
3378
+ break;
3379
+ }
3380
+ case "error": {
3381
+ const isSoftTurnEnd = event.code === "USAGE_LIMIT";
3382
+ this._isStreaming = false;
3383
+ this._messages = this._messages.map((m2) => {
3384
+ const wasStreaming = m2.status === "streaming";
3385
+ const hasLiveTool = m2.toolCalls?.some(
3386
+ (tc) => tc.status === "args-streaming" || tc.status === "running"
3387
+ );
3388
+ if (!wasStreaming && !hasLiveTool) return m2;
3389
+ const toolCalls = hasLiveTool ? m2.toolCalls?.map((tc) => {
3390
+ if (tc.status !== "args-streaming" && tc.status !== "running") return tc;
3391
+ return isSoftTurnEnd ? { ...tc, status: "cancelled" } : { ...tc, status: "error", error: tc.error ?? event.message };
3392
+ }) : m2.toolCalls;
3393
+ const nextStatus = wasStreaming ? isSoftTurnEnd ? "complete" : "error" : m2.status;
3394
+ return { ...m2, status: nextStatus, toolCalls };
3395
+ });
3396
+ if (isSoftTurnEnd) {
3397
+ const id = `usage-limit-${this._messages.length}-${event.message.length}`;
3398
+ this._messages = [
3399
+ ...this._messages,
3400
+ {
3401
+ id,
3402
+ role: "assistant",
3403
+ content: event.message,
3404
+ timestamp: Date.now(),
3405
+ status: "complete"
3406
+ }
3407
+ ];
3408
+ } else {
3409
+ console.warn("[syntro-chat] run error:", event.message);
3410
+ this._errorMessage = "Hmm, that didn't go through. Please try again.";
3411
+ }
3412
+ break;
3413
+ }
3414
+ case "a2ui":
3415
+ break;
3416
+ }
3417
+ };
3418
+ this._onInput = (e) => {
3419
+ if (this._micListening) this._dictation?.stop();
3420
+ this._inputValue = e.target.value;
3421
+ };
3422
+ this._onMicClick = () => {
3423
+ if (this._micListening) {
3424
+ this._dictation?.stop();
3425
+ return;
3426
+ }
3427
+ this._micBase = this._inputValue;
3428
+ this._dictation = createDictation({
3429
+ onTranscript: (text2) => {
3430
+ this._micNetworkErrors = 0;
3431
+ this._inputValue = this._micBase + (this._micBase ? " " : "") + text2;
3432
+ },
3433
+ onEnd: () => {
3434
+ this._micListening = false;
3435
+ },
3436
+ onError: (code) => {
3437
+ this._micListening = false;
3438
+ if (code === "not-allowed") this._micDisabled = true;
3439
+ if (code === "network" && ++this._micNetworkErrors >= 2) this._micDisabled = true;
3440
+ }
3441
+ });
3442
+ this._dictation.start();
3443
+ this._micListening = this._dictation.listening;
3444
+ };
3445
+ this._onSend = () => {
3446
+ if (this._micListening) this._dictation?.stop();
3447
+ const text2 = this._inputValue.trim();
3448
+ if (!text2) return;
3449
+ this._appendUserMessage(text2);
3450
+ this.transport.send({ type: "user-message", text: text2 });
3451
+ this._inputValue = "";
3452
+ };
3453
+ this._onStop = () => {
3454
+ this.transport.send({ type: "stop-generation" });
3455
+ };
3456
+ this._onKeyDown = (e) => {
3457
+ if (e.key === "Enter" && !e.shiftKey && !this._isComposing) {
3458
+ e.preventDefault();
3459
+ if (this._isStreaming) {
3460
+ this._onStop();
3461
+ } else {
3462
+ this._onSend();
3463
+ }
3464
+ }
3465
+ };
3466
+ this._onCopy = (content) => {
3467
+ navigator.clipboard?.writeText(content);
3468
+ };
3469
+ this._onRegenerate = (messageId) => {
3470
+ this.transport.send({ type: "regenerate", messageId });
3471
+ };
3472
+ this._onToolApprove = (toolCallId, payload, _retryCount = 0) => {
3473
+ const interruptId = this._findInterruptId(toolCallId);
3474
+ if (interruptId) {
3475
+ this._markToolDone(toolCallId);
3476
+ this.transport.send({
3477
+ type: "deferred-tool-resume",
3478
+ interruptId,
3479
+ decision: "approve",
3480
+ ...payload?.editedArgs ? { editedArgs: payload.editedArgs } : {}
3481
+ });
3482
+ return;
3483
+ }
3484
+ if (this._isPendingClientTool(toolCallId)) {
3485
+ this._markToolDone(toolCallId);
3486
+ this.transport.send({
3487
+ type: "tool-result",
3488
+ toolCallId,
3489
+ result: payload?.editedArgs ?? null,
3490
+ approved: true
3491
+ });
3492
+ return;
3493
+ }
3494
+ if (_retryCount < 10) {
3495
+ setTimeout(() => this._onToolApprove(toolCallId, payload, _retryCount + 1), 200);
3496
+ return;
3497
+ }
3498
+ this._markToolDone(toolCallId);
3499
+ this.transport.send({
3500
+ type: "tool-result",
3501
+ toolCallId,
3502
+ result: payload?.editedArgs ?? null,
3503
+ approved: true
3504
+ });
3505
+ };
3506
+ this._onToolDeny = (toolCallId, _retryCount = 0) => {
3507
+ const interruptId = this._findInterruptId(toolCallId);
3508
+ if (interruptId) {
3509
+ this._markToolCancelled(toolCallId);
3510
+ this.transport.send({
3511
+ type: "deferred-tool-resume",
3512
+ interruptId,
3513
+ decision: "deny"
3514
+ });
3515
+ return;
3516
+ }
3517
+ if (this._isPendingClientTool(toolCallId)) {
3518
+ this._markToolCancelled(toolCallId);
3519
+ this.transport.send({
3520
+ type: "tool-result",
3521
+ toolCallId,
3522
+ result: null,
3523
+ approved: false
3524
+ });
3525
+ return;
3526
+ }
3527
+ if (_retryCount < 10) {
3528
+ setTimeout(() => this._onToolDeny(toolCallId, _retryCount + 1), 200);
3529
+ return;
3530
+ }
3531
+ this._markToolCancelled(toolCallId);
3532
+ this.transport.send({
3533
+ type: "tool-result",
3534
+ toolCallId,
3535
+ result: null,
3536
+ approved: false
3537
+ });
3538
+ };
3539
+ this._onCompositionStart = () => {
3540
+ this._isComposing = true;
3541
+ };
3542
+ this._onCompositionEnd = () => {
3543
+ this._isComposing = false;
3544
+ };
3545
+ this._onSuggestion = (text2) => {
3546
+ this.sendUserMessage(text2);
3547
+ };
3548
+ }
3549
+ // ── Public API: thread navigation ──────────────────────────────────
3550
+ //
3551
+ // Composing elements (the per-surface wrappers like
3552
+ // <ap-action-plan-chat>) call these to load past threads and start
3553
+ // new ones. The chat element doesn't own the thread index — that's
3554
+ // the consumer's job (typically a sibling <syntro-chat-thread-list>
3555
+ // + the consumer's REST endpoint). This element just owns the
3556
+ // visible message state.
3557
+ /**
3558
+ * Replace the chat's message history wholesale. Used by the host
3559
+ * shell when switching threads (after fetching the new thread's
3560
+ * messages from persistence) or when restoring a session.
3561
+ *
3562
+ * Emits `chat-messages-replaced` so dependent UI (overlay cards,
3563
+ * action plan sidebar) can react.
3564
+ */
3565
+ replaceMessages(messages) {
3566
+ this._messages = [...messages];
3567
+ this._isStreaming = messages.some((m2) => m2.status === "streaming");
3568
+ this._stickToBottom = true;
3569
+ requestAnimationFrame(() => this._scrollToBottom());
3570
+ this.dispatchEvent(
3571
+ new CustomEvent("chat-messages-replaced", {
3572
+ detail: { messageCount: messages.length },
3573
+ bubbles: true,
3574
+ composed: true
3575
+ })
3576
+ );
3577
+ }
3578
+ /**
3579
+ * Clear the chat for a fresh conversation. Equivalent to
3580
+ * `replaceMessages([])` plus a state reset.
3581
+ */
3582
+ reset() {
3583
+ this._messages = [];
3584
+ this._isStreaming = false;
3585
+ this._isTyping = false;
3586
+ this._inputValue = "";
3587
+ this._stickToBottom = true;
3588
+ this._messagesBelow = 0;
3589
+ this._errorMessage = null;
3590
+ }
3591
+ /**
3592
+ * Externally drive the typing indicator. Used by the surface's
3593
+ * run-state restore (BUG-1781288061): a remounted thread whose durable
3594
+ * producer run is still in flight shows the indicator and polls — the
3595
+ * transport's own 'typing' events only exist while the SSE stream lives.
3596
+ */
3597
+ setTyping(isTyping) {
3598
+ this._isTyping = isTyping;
3599
+ if (isTyping) this._scrollToBottom();
3600
+ }
3601
+ createRenderRoot() {
3602
+ return this;
3603
+ }
3604
+ connectedCallback() {
3605
+ super.connectedCallback();
3606
+ this._ensureStylesInRoot();
3607
+ if (this.transport) {
3608
+ this._unsubscribe = this.transport.subscribe(this._handleEvent);
3609
+ this.transport.connect();
3610
+ }
3611
+ }
3612
+ disconnectedCallback() {
3613
+ super.disconnectedCallback();
3614
+ this._unsubscribe?.();
3615
+ this._unsubscribe = null;
3616
+ this.transport?.disconnect();
3617
+ this._scrollContainer?.removeEventListener("scroll", this._handleScroll);
3618
+ this._scrollContainer?.removeEventListener("wheel", this._markUserScrollIntent);
3619
+ this._scrollContainer?.removeEventListener("touchmove", this._markUserScrollIntent);
3620
+ this._scrollContainer = null;
3621
+ }
3622
+ firstUpdated() {
3623
+ this._ensureStylesInRoot();
3624
+ this._attachScrollListener();
3625
+ }
3626
+ /** Attach the scroll listener if not already attached. Called from both
3627
+ * firstUpdated (initial mount) and updated (re-mounts — Lit never
3628
+ * re-fires firstUpdated for the same element instance, and
3629
+ * disconnectedCallback tears the listener down). */
3630
+ _attachScrollListener() {
3631
+ if (this._scrollContainer) return;
3632
+ this._scrollContainer = this.querySelector("[data-sc-scroll-area]");
3633
+ this._scrollContainer?.addEventListener("scroll", this._handleScroll);
3634
+ this._scrollContainer?.addEventListener("wheel", this._markUserScrollIntent, {
3635
+ passive: true
3636
+ });
3637
+ this._scrollContainer?.addEventListener("touchmove", this._markUserScrollIntent, {
3638
+ passive: true
3639
+ });
3640
+ }
3641
+ /**
3642
+ * Resolve the *effective* rendering root for this chat instance.
3643
+ *
3644
+ * `this.getRootNode()` will follow shadow boundaries, but in the editor
3645
+ * surface the chat is created via `document.createElement('syntro-chat')`
3646
+ * and then committed into the smart-canvas shadow tree by Lit several
3647
+ * frames after `connectedCallback`. During that window
3648
+ * `getRootNode()` returns Document even though the element ultimately
3649
+ * lives in a shadow root (BUG-1779636600).
3650
+ *
3651
+ * Walk the parent chain manually, hopping across shadow boundaries via
3652
+ * `.host`, and return the deepest enclosing `ShadowRoot` we can reach.
3653
+ * Fall back to `getRootNode()` (Document or self) when no shadow root
3654
+ * is in the chain — that's the host-page chatbot case.
3655
+ */
3656
+ _resolveStyleRoot() {
3657
+ let node = this;
3658
+ while (node) {
3659
+ const parent = node.parentNode;
3660
+ if (parent) {
3661
+ node = parent;
3662
+ continue;
3663
+ }
3664
+ if (node instanceof ShadowRoot) return node;
3665
+ break;
3666
+ }
3667
+ const r = this.getRootNode();
3668
+ return r instanceof ShadowRoot || r instanceof Document ? r : document;
3669
+ }
3670
+ _ensureStylesInRoot() {
3671
+ injectChatStyles(this._resolveStyleRoot());
3672
+ }
3673
+ updated() {
3674
+ this._attachScrollListener();
3675
+ this._injectCodeCopyButtons();
3676
+ }
3677
+ _injectCodeCopyButtons() {
3678
+ const blocks = this.querySelectorAll("[data-sc-code-block]:not(:has([data-sc-copy-btn]))");
3679
+ for (const block of blocks) {
3680
+ const btn = document.createElement("button");
3681
+ btn.setAttribute("data-sc-copy-btn", "");
3682
+ btn.textContent = "Copy";
3683
+ btn.addEventListener("click", () => {
3684
+ const code = block.querySelector("code");
3685
+ if (code) navigator.clipboard?.writeText(code.textContent ?? "");
3686
+ btn.textContent = "Copied!";
3687
+ setTimeout(() => {
3688
+ btn.textContent = "Copy";
3689
+ }, 1500);
3690
+ });
3691
+ block.appendChild(btn);
3692
+ }
3693
+ }
3694
+ _isAtBottom() {
3695
+ if (!this._scrollContainer) return true;
3696
+ const { scrollTop, scrollHeight, clientHeight } = this._scrollContainer;
3697
+ return scrollHeight - scrollTop - clientHeight <= _SyntroChat2._BOTTOM_EPSILON_PX;
3698
+ }
3699
+ /** Count messages whose bottom edge hasn't entered the viewport yet.
3700
+ * At the bottom this is 0 (pill hidden); it decrements one-by-one as the
3701
+ * visitor scrolls down past each message. */
3702
+ _countMessagesBelow() {
3703
+ const container = this._scrollContainer;
3704
+ if (!container) return 0;
3705
+ if (this._isAtBottom()) return 0;
3706
+ const viewportBottom = container.getBoundingClientRect().top + container.clientHeight;
3707
+ let count = 0;
3708
+ for (const row of this.querySelectorAll("[data-sc-msg-row]")) {
3709
+ if (row.getBoundingClientRect().bottom > viewportBottom + 4) count += 1;
3710
+ }
3711
+ return count > 0 ? count : 1;
3712
+ }
3713
+ /** Recompute `_messagesBelow` from live geometry. Called on scroll AND on
3714
+ * content growth (deltas grow scrollHeight without a scroll event). */
3715
+ _syncScrollState() {
3716
+ this._messagesBelow = this._isAtBottom() ? 0 : this._countMessagesBelow();
3717
+ }
3718
+ _scrollToBottom() {
3719
+ if (!this._stickToBottom) return;
3720
+ requestAnimationFrame(() => {
3721
+ if (this._scrollContainer?.scrollTo) {
3722
+ this._scrollContainer.scrollTo({
3723
+ top: this._scrollContainer.scrollHeight,
3724
+ behavior: "smooth"
3725
+ });
3726
+ }
3727
+ this._syncScrollState();
3728
+ });
3729
+ }
3730
+ /**
3731
+ * Anchor the view so the given (just-sent) user message sits at the TOP of
3732
+ * the scroll area: the visitor sees their message, then reads the reply
3733
+ * top-down instead of chasing an auto-scrolling tail.
3734
+ */
3735
+ _anchorToMessage(messageId) {
3736
+ this._stickToBottom = false;
3737
+ requestAnimationFrame(() => {
3738
+ const container = this._scrollContainer;
3739
+ if (!container?.scrollTo) return;
3740
+ const row = this.querySelector(`[data-sc-msg-id="${messageId}"]`);
3741
+ if (!row) return;
3742
+ const top = row.getBoundingClientRect().top - container.getBoundingClientRect().top + container.scrollTop;
3743
+ container.scrollTo({ top, behavior: "smooth" });
3744
+ this._syncScrollState();
3745
+ });
3746
+ }
3747
+ /** Content grew (delta/typing/append while anchored): don't move the
3748
+ * view, but re-evaluate whether the pill should show. */
3749
+ _onContentGrowth() {
3750
+ if (this._stickToBottom) {
3751
+ this._scrollToBottom();
3752
+ return;
3753
+ }
3754
+ requestAnimationFrame(() => this._syncScrollState());
3755
+ }
3756
+ _appendUserMessage(text2) {
3757
+ const msg = {
3758
+ id: `user-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
3759
+ role: "user",
3760
+ content: text2,
3761
+ timestamp: Date.now(),
3762
+ status: "complete"
3763
+ };
3764
+ this._messages = [...this._messages, msg];
3765
+ this._anchorToMessage(msg.id);
3766
+ }
3767
+ _isPendingClientTool(toolCallId) {
3768
+ for (const m2 of this._messages) {
3769
+ const tc = m2.toolCalls?.find((t) => t.id === toolCallId);
3770
+ if (tc) return tc.status === "pending" && !tc.interruptId;
3771
+ }
3772
+ return false;
3773
+ }
3774
+ _findInterruptId(toolCallId) {
3775
+ for (const m2 of this._messages) {
3776
+ const tc = m2.toolCalls?.find((t) => t.id === toolCallId);
3777
+ if (tc?.interruptId) return tc.interruptId;
3778
+ }
3779
+ return void 0;
3780
+ }
3781
+ _markToolDone(toolCallId) {
3782
+ this._markToolStatus(toolCallId, "done");
3783
+ }
3784
+ /** Deny paths mark 'cancelled' — the frozen card must READ as rejected
3785
+ * ("Rejected" label), never as the done-phase "Approved". */
3786
+ _markToolCancelled(toolCallId) {
3787
+ this._markToolStatus(toolCallId, "cancelled");
3788
+ }
3789
+ _markToolStatus(toolCallId, status) {
3790
+ this._messages = this._messages.map((m2) => {
3791
+ if (!m2.toolCalls) return m2;
3792
+ const toolCalls = m2.toolCalls.map((tc) => tc.id === toolCallId ? { ...tc, status } : tc);
3793
+ return { ...m2, toolCalls };
3794
+ });
3795
+ }
3796
+ /**
3797
+ * Append a user message to the local log and forward it to the
3798
+ * transport. Equivalent to typing `text` and pressing Send — exposed
3799
+ * publicly so consumers that render their own input affordances (e.g.
3800
+ * suggestion rows inside a custom empty-state slot) get the same
3801
+ * optimistic-append behavior the built-in input has, without
3802
+ * duplicating logic.
3803
+ */
3804
+ sendUserMessage(text2) {
3805
+ if (this._micListening) this._dictation?.stop();
3806
+ const trimmed = text2.trim();
3807
+ if (!trimmed) return;
3808
+ this._appendUserMessage(trimmed);
3809
+ this.transport.send({ type: "user-message", text: trimmed });
3810
+ }
3811
+ render() {
3812
+ const headerSlot = this.slots?.header;
3813
+ const emptyState = this.slots?.emptyState ?? (this.greeting ? html7`<div
3814
+ style="padding:24px;text-align:center;color:var(--sc-content-text-secondary-color,#87919f)"
3815
+ >
3816
+ ${this.greeting}
3817
+ </div>` : void 0);
3818
+ return html7`
3819
+ <div data-sc-chat style="display:flex;flex-direction:column;height:100%;position:relative;">
3820
+ ${headerSlot && typeof headerSlot === "object" && "values" in headerSlot ? headerSlot : nothing5}
3821
+ <div data-sc-scroll-area style="flex:1;overflow-y:auto;">
3822
+ ${renderMessageList({
3823
+ messages: this._messages,
3824
+ isTyping: this._isTyping,
3825
+ toolLabels: this.toolLabels,
3826
+ toolRenderers: this.toolRenderers,
3827
+ toolContext: this.toolContext,
3828
+ defaultToolRenderer: this.defaultToolRenderer,
3829
+ onCopy: this._onCopy,
3830
+ onRegenerate: this._onRegenerate,
3831
+ onToolApprove: this._onToolApprove,
3832
+ onToolDeny: this._onToolDeny,
3833
+ emptyStateSlot: emptyState,
3834
+ typingIndicatorSlot: this.slots?.typingIndicator
3835
+ })}
3836
+ </div>
3837
+ ${this._messagesBelow > 0 ? html7`<button data-sc-scroll-btn @click=${this._resumeFollowing} aria-label="Scroll to most recent — ${this._messagesBelow} ${this._messagesBelow === 1 ? "message" : "messages"} below"><svg width="14" height="14" 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><span>${this._messagesBelow} ${this._messagesBelow === 1 ? "message" : "messages"}</span></button>` : nothing5}
3838
+ ${this._errorMessage ? html7`<div data-sc-error role="alert">${this._errorMessage}</div>` : nothing5}
3839
+ ${renderChatInput({
3840
+ value: this._inputValue,
3841
+ isStreaming: this._isStreaming || this._isTyping,
3842
+ isComposing: this._isComposing,
3843
+ onInput: this._onInput,
3844
+ onSend: this._onSend,
3845
+ onStop: this._onStop,
3846
+ onKeyDown: this._onKeyDown,
3847
+ onCompositionStart: this._onCompositionStart,
3848
+ onCompositionEnd: this._onCompositionEnd,
3849
+ suggestions: this._messages.length === 0 ? this.suggestions : void 0,
3850
+ onSuggestion: this._onSuggestion,
3851
+ inputActionsSlot: this.slots?.inputActions,
3852
+ beforeInputSlot: this.slots?.beforeInput,
3853
+ // Listening is a mode the visitor must be able to see AND exit:
3854
+ // the placeholder doubles as the tap-to-stop instruction.
3855
+ placeholder: this._micListening ? "Listening \u2014 tap the mic to stop" : this.placeholder,
3856
+ showMic: this.voiceInput && isDictationSupported(),
3857
+ micListening: this._micListening,
3858
+ micDisabled: this._micDisabled,
3859
+ onMicClick: this._onMicClick
3860
+ })}
3861
+ </div>
3862
+ `;
3863
+ }
3864
+ };
3865
+ _SyntroChat.properties = {
3866
+ transport: { attribute: false },
3867
+ greeting: { type: String },
3868
+ suggestions: { attribute: false },
3869
+ toolLabels: { attribute: false },
3870
+ toolRenderers: { attribute: false },
3871
+ toolContext: { attribute: false },
3872
+ defaultToolRenderer: { attribute: false },
3873
+ autoExecTools: { attribute: false },
3874
+ placeholder: { type: String },
3875
+ slots: { attribute: false },
3876
+ voiceInput: { type: Boolean, attribute: "voice-input" },
3877
+ _messages: { state: true },
3878
+ _micListening: { state: true },
3879
+ _micDisabled: { state: true },
3880
+ _isTyping: { state: true },
3881
+ _inputValue: { state: true },
3882
+ _isComposing: { state: true },
3883
+ _isStreaming: { state: true },
3884
+ _messagesBelow: { state: true },
3885
+ _errorMessage: { state: true }
3886
+ };
3887
+ _SyntroChat._BOTTOM_EPSILON_PX = 50;
3888
+ _SyntroChat._USER_SCROLL_INTENT_WINDOW_MS = 1200;
3889
+ var SyntroChat = _SyntroChat;
3890
+ var SyntroChatThreadList = class extends LitElement2 {
3891
+ constructor() {
3892
+ super(...arguments);
3893
+ this.threadsEndpoint = "";
3894
+ this.activeThreadId = null;
3895
+ this.newThreadLabel = "New thread";
3896
+ this.emptyStateLabel = "No threads yet";
3897
+ this._threads = [];
3898
+ this._loading = false;
3899
+ this._error = null;
3900
+ this._onThreadClick = (threadId) => {
3901
+ if (threadId === this.activeThreadId) return;
3902
+ this.dispatchEvent(
3903
+ new CustomEvent("thread-selected", {
3904
+ detail: { threadId },
3905
+ bubbles: true,
3906
+ composed: true
3907
+ })
3908
+ );
3909
+ };
3910
+ }
3911
+ createRenderRoot() {
3912
+ return this;
3913
+ }
3914
+ connectedCallback() {
3915
+ super.connectedCallback();
3916
+ if (this.threadsEndpoint) void this.refresh();
3917
+ }
3918
+ updated(changed) {
3919
+ if (changed.has("threadsEndpoint") && this.threadsEndpoint) {
3920
+ void this.refresh();
3921
+ }
3922
+ }
3923
+ /** Re-fetch the thread index. Call after creating/archiving a thread. */
3924
+ async refresh() {
3925
+ if (!this.threadsEndpoint) return;
3926
+ this._loading = true;
3927
+ this._error = null;
3928
+ try {
3929
+ const res = await fetch(this.threadsEndpoint, {
3930
+ method: "GET",
3931
+ headers: { ...this.authHeaders ?? {}, Accept: "application/json" }
3932
+ });
3933
+ if (!res.ok) {
3934
+ this._error = `Failed to load threads (${res.status})`;
3935
+ this._threads = [];
3936
+ return;
3937
+ }
3938
+ const data = await res.json();
3939
+ this._threads = (data.threads ?? []).filter((t) => t.status !== "archived");
3940
+ } catch (e) {
3941
+ this._error = e instanceof Error ? e.message : "Failed to load threads";
3942
+ this._threads = [];
3943
+ } finally {
3944
+ this._loading = false;
3945
+ }
3946
+ }
3947
+ /** Imperative: request the host to start a new thread.
3948
+ * Fires `new-thread-requested`. The host clears the chat element and
3949
+ * drops `activeThreadId` so the next user message goes to a fresh
3950
+ * backend thread.
3951
+ */
3952
+ createNewThread() {
3953
+ this.dispatchEvent(new CustomEvent("new-thread-requested", { bubbles: true, composed: true }));
3954
+ }
3955
+ render() {
3956
+ return html8`
3957
+ <div data-sc-thread-list>
3958
+ <button
3959
+ type="button"
3960
+ data-sc-new-thread-btn
3961
+ @click=${() => this.createNewThread()}
3962
+ aria-label=${this.newThreadLabel}
3963
+ >
3964
+ ${this.newThreadLabel}
3965
+ </button>
3966
+ ${this._loading ? html8`<div data-sc-thread-list-loading>Loading…</div>` : this._error ? html8`<div data-sc-thread-list-error>${this._error}</div>` : this._threads.length === 0 ? html8`<div data-sc-thread-list-empty>${this.emptyStateLabel}</div>` : html8`<ul data-sc-thread-list-items role="list">
3967
+ ${this._threads.map(
3968
+ (t) => html8`
3969
+ <li
3970
+ data-sc-thread-list-item
3971
+ ?data-sc-active=${t.remoteId === this.activeThreadId}
3972
+ >
3973
+ <button
3974
+ type="button"
3975
+ @click=${() => this._onThreadClick(t.remoteId)}
3976
+ title=${t.title ?? t.remoteId}
3977
+ >
3978
+ ${t.title || "Untitled thread"}
3979
+ </button>
3980
+ </li>
3981
+ `
3982
+ )}
3983
+ </ul>`}
3984
+ </div>
3985
+ `;
3986
+ }
3987
+ };
3988
+ SyntroChatThreadList.properties = {
3989
+ threadsEndpoint: { type: String, attribute: "threads-endpoint" },
3990
+ authHeaders: { attribute: false },
3991
+ activeThreadId: { type: String, attribute: "active-thread-id" },
3992
+ newThreadLabel: { type: String, attribute: "new-thread-label" },
3993
+ emptyStateLabel: { type: String, attribute: "empty-state-label" },
3994
+ _threads: { state: true },
3995
+ _loading: { state: true },
3996
+ _error: { state: true }
3997
+ };
3998
+ if (!customElements.get("syntro-chat-thread-list")) {
3999
+ customElements.define("syntro-chat-thread-list", SyntroChatThreadList);
4000
+ }
4001
+ if (!customElements.get("syntro-chat")) {
4002
+ customElements.define("syntro-chat", SyntroChat);
4003
+ }
4004
+
4005
+ export {
4006
+ isDictationSupported,
4007
+ createDictation,
4008
+ renderMarkdown
4009
+ };
4010
+ /*! Bundled license information:
4011
+
4012
+ dompurify/dist/purify.es.mjs:
4013
+ (*! @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 *)
4014
+ */
4015
+ //# sourceMappingURL=chunk-VZIUXXAM.js.map