@changerawr/markdown 1.0.3 → 1.0.5

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.
@@ -0,0 +1,2547 @@
1
+ "use strict";
2
+ var ChangerawrMarkdown = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __esm = (fn, res) => function __init() {
25
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
26
+ };
27
+ var __export = (target, all) => {
28
+ for (var name in all)
29
+ __defProp(target, name, { get: all[name], enumerable: true });
30
+ };
31
+ var __copyProps = (to, from, except, desc) => {
32
+ if (from && typeof from === "object" || typeof from === "function") {
33
+ for (let key of __getOwnPropNames(from))
34
+ if (!__hasOwnProp.call(to, key) && key !== except)
35
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
36
+ }
37
+ return to;
38
+ };
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+
41
+ // node_modules/dompurify/dist/purify.es.mjs
42
+ var purify_es_exports = {};
43
+ __export(purify_es_exports, {
44
+ default: () => purify
45
+ });
46
+ function unapply(func) {
47
+ return function(thisArg) {
48
+ if (thisArg instanceof RegExp) {
49
+ thisArg.lastIndex = 0;
50
+ }
51
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
52
+ args[_key - 1] = arguments[_key];
53
+ }
54
+ return apply(func, thisArg, args);
55
+ };
56
+ }
57
+ function unconstruct(func) {
58
+ return function() {
59
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
60
+ args[_key2] = arguments[_key2];
61
+ }
62
+ return construct(func, args);
63
+ };
64
+ }
65
+ function addToSet(set, array) {
66
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
67
+ if (setPrototypeOf) {
68
+ setPrototypeOf(set, null);
69
+ }
70
+ let l = array.length;
71
+ while (l--) {
72
+ let element = array[l];
73
+ if (typeof element === "string") {
74
+ const lcElement = transformCaseFunc(element);
75
+ if (lcElement !== element) {
76
+ if (!isFrozen(array)) {
77
+ array[l] = lcElement;
78
+ }
79
+ element = lcElement;
80
+ }
81
+ }
82
+ set[element] = true;
83
+ }
84
+ return set;
85
+ }
86
+ function cleanArray(array) {
87
+ for (let index = 0; index < array.length; index++) {
88
+ const isPropertyExist = objectHasOwnProperty(array, index);
89
+ if (!isPropertyExist) {
90
+ array[index] = null;
91
+ }
92
+ }
93
+ return array;
94
+ }
95
+ function clone(object) {
96
+ const newObject = create(null);
97
+ for (const [property, value] of entries(object)) {
98
+ const isPropertyExist = objectHasOwnProperty(object, property);
99
+ if (isPropertyExist) {
100
+ if (Array.isArray(value)) {
101
+ newObject[property] = cleanArray(value);
102
+ } else if (value && typeof value === "object" && value.constructor === Object) {
103
+ newObject[property] = clone(value);
104
+ } else {
105
+ newObject[property] = value;
106
+ }
107
+ }
108
+ }
109
+ return newObject;
110
+ }
111
+ function lookupGetter(object, prop) {
112
+ while (object !== null) {
113
+ const desc = getOwnPropertyDescriptor(object, prop);
114
+ if (desc) {
115
+ if (desc.get) {
116
+ return unapply(desc.get);
117
+ }
118
+ if (typeof desc.value === "function") {
119
+ return unapply(desc.value);
120
+ }
121
+ }
122
+ object = getPrototypeOf(object);
123
+ }
124
+ function fallbackValue() {
125
+ return null;
126
+ }
127
+ return fallbackValue;
128
+ }
129
+ function createDOMPurify() {
130
+ let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
131
+ const DOMPurify2 = (root) => createDOMPurify(root);
132
+ DOMPurify2.version = "3.2.6";
133
+ DOMPurify2.removed = [];
134
+ if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
135
+ DOMPurify2.isSupported = false;
136
+ return DOMPurify2;
137
+ }
138
+ let {
139
+ document: document2
140
+ } = window2;
141
+ const originalDocument = document2;
142
+ const currentScript = originalDocument.currentScript;
143
+ const {
144
+ DocumentFragment,
145
+ HTMLTemplateElement,
146
+ Node,
147
+ Element,
148
+ NodeFilter,
149
+ NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
150
+ HTMLFormElement,
151
+ DOMParser,
152
+ trustedTypes
153
+ } = window2;
154
+ const ElementPrototype = Element.prototype;
155
+ const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
156
+ const remove = lookupGetter(ElementPrototype, "remove");
157
+ const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
158
+ const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
159
+ const getParentNode = lookupGetter(ElementPrototype, "parentNode");
160
+ if (typeof HTMLTemplateElement === "function") {
161
+ const template = document2.createElement("template");
162
+ if (template.content && template.content.ownerDocument) {
163
+ document2 = template.content.ownerDocument;
164
+ }
165
+ }
166
+ let trustedTypesPolicy;
167
+ let emptyHTML = "";
168
+ const {
169
+ implementation,
170
+ createNodeIterator,
171
+ createDocumentFragment,
172
+ getElementsByTagName
173
+ } = document2;
174
+ const {
175
+ importNode
176
+ } = originalDocument;
177
+ let hooks = _createHooksMap();
178
+ DOMPurify2.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
179
+ const {
180
+ MUSTACHE_EXPR: MUSTACHE_EXPR2,
181
+ ERB_EXPR: ERB_EXPR2,
182
+ TMPLIT_EXPR: TMPLIT_EXPR2,
183
+ DATA_ATTR: DATA_ATTR2,
184
+ ARIA_ATTR: ARIA_ATTR2,
185
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
186
+ ATTR_WHITESPACE: ATTR_WHITESPACE2,
187
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT2
188
+ } = EXPRESSIONS;
189
+ let {
190
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
191
+ } = EXPRESSIONS;
192
+ let ALLOWED_TAGS2 = null;
193
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
194
+ let ALLOWED_ATTR2 = null;
195
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
196
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
197
+ tagNameCheck: {
198
+ writable: true,
199
+ configurable: false,
200
+ enumerable: true,
201
+ value: null
202
+ },
203
+ attributeNameCheck: {
204
+ writable: true,
205
+ configurable: false,
206
+ enumerable: true,
207
+ value: null
208
+ },
209
+ allowCustomizedBuiltInElements: {
210
+ writable: true,
211
+ configurable: false,
212
+ enumerable: true,
213
+ value: false
214
+ }
215
+ }));
216
+ let FORBID_TAGS = null;
217
+ let FORBID_ATTR = null;
218
+ let ALLOW_ARIA_ATTR = true;
219
+ let ALLOW_DATA_ATTR = true;
220
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
221
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
222
+ let SAFE_FOR_TEMPLATES = false;
223
+ let SAFE_FOR_XML = true;
224
+ let WHOLE_DOCUMENT = false;
225
+ let SET_CONFIG = false;
226
+ let FORCE_BODY = false;
227
+ let RETURN_DOM = false;
228
+ let RETURN_DOM_FRAGMENT = false;
229
+ let RETURN_TRUSTED_TYPE = false;
230
+ let SANITIZE_DOM = true;
231
+ let SANITIZE_NAMED_PROPS = false;
232
+ const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
233
+ let KEEP_CONTENT = true;
234
+ let IN_PLACE = false;
235
+ let USE_PROFILES = {};
236
+ let FORBID_CONTENTS = null;
237
+ 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"]);
238
+ let DATA_URI_TAGS = null;
239
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
240
+ let URI_SAFE_ATTRIBUTES = null;
241
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
242
+ const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
243
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
244
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
245
+ let NAMESPACE = HTML_NAMESPACE;
246
+ let IS_EMPTY_INPUT = false;
247
+ let ALLOWED_NAMESPACES = null;
248
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
249
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
250
+ let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
251
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
252
+ let PARSER_MEDIA_TYPE = null;
253
+ const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
254
+ const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
255
+ let transformCaseFunc = null;
256
+ let CONFIG = null;
257
+ const formElement = document2.createElement("form");
258
+ const isRegexOrFunction = function isRegexOrFunction2(testValue) {
259
+ return testValue instanceof RegExp || testValue instanceof Function;
260
+ };
261
+ const _parseConfig = function _parseConfig2() {
262
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
263
+ if (CONFIG && CONFIG === cfg) {
264
+ return;
265
+ }
266
+ if (!cfg || typeof cfg !== "object") {
267
+ cfg = {};
268
+ }
269
+ cfg = clone(cfg);
270
+ PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
271
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
272
+ transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
273
+ ALLOWED_TAGS2 = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
274
+ ALLOWED_ATTR2 = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
275
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
276
+ 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;
277
+ 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;
278
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
279
+ FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
280
+ FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
281
+ USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
282
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
283
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
284
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
285
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
286
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
287
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
288
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
289
+ RETURN_DOM = cfg.RETURN_DOM || false;
290
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
291
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
292
+ FORCE_BODY = cfg.FORCE_BODY || false;
293
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
294
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
295
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
296
+ IN_PLACE = cfg.IN_PLACE || false;
297
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
298
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
299
+ MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
300
+ HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
301
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
302
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
303
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
304
+ }
305
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
306
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
307
+ }
308
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
309
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
310
+ }
311
+ if (SAFE_FOR_TEMPLATES) {
312
+ ALLOW_DATA_ATTR = false;
313
+ }
314
+ if (RETURN_DOM_FRAGMENT) {
315
+ RETURN_DOM = true;
316
+ }
317
+ if (USE_PROFILES) {
318
+ ALLOWED_TAGS2 = addToSet({}, text);
319
+ ALLOWED_ATTR2 = [];
320
+ if (USE_PROFILES.html === true) {
321
+ addToSet(ALLOWED_TAGS2, html$1);
322
+ addToSet(ALLOWED_ATTR2, html);
323
+ }
324
+ if (USE_PROFILES.svg === true) {
325
+ addToSet(ALLOWED_TAGS2, svg$1);
326
+ addToSet(ALLOWED_ATTR2, svg);
327
+ addToSet(ALLOWED_ATTR2, xml);
328
+ }
329
+ if (USE_PROFILES.svgFilters === true) {
330
+ addToSet(ALLOWED_TAGS2, svgFilters);
331
+ addToSet(ALLOWED_ATTR2, svg);
332
+ addToSet(ALLOWED_ATTR2, xml);
333
+ }
334
+ if (USE_PROFILES.mathMl === true) {
335
+ addToSet(ALLOWED_TAGS2, mathMl$1);
336
+ addToSet(ALLOWED_ATTR2, mathMl);
337
+ addToSet(ALLOWED_ATTR2, xml);
338
+ }
339
+ }
340
+ if (cfg.ADD_TAGS) {
341
+ if (ALLOWED_TAGS2 === DEFAULT_ALLOWED_TAGS) {
342
+ ALLOWED_TAGS2 = clone(ALLOWED_TAGS2);
343
+ }
344
+ addToSet(ALLOWED_TAGS2, cfg.ADD_TAGS, transformCaseFunc);
345
+ }
346
+ if (cfg.ADD_ATTR) {
347
+ if (ALLOWED_ATTR2 === DEFAULT_ALLOWED_ATTR) {
348
+ ALLOWED_ATTR2 = clone(ALLOWED_ATTR2);
349
+ }
350
+ addToSet(ALLOWED_ATTR2, cfg.ADD_ATTR, transformCaseFunc);
351
+ }
352
+ if (cfg.ADD_URI_SAFE_ATTR) {
353
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
354
+ }
355
+ if (cfg.FORBID_CONTENTS) {
356
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
357
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
358
+ }
359
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
360
+ }
361
+ if (KEEP_CONTENT) {
362
+ ALLOWED_TAGS2["#text"] = true;
363
+ }
364
+ if (WHOLE_DOCUMENT) {
365
+ addToSet(ALLOWED_TAGS2, ["html", "head", "body"]);
366
+ }
367
+ if (ALLOWED_TAGS2.table) {
368
+ addToSet(ALLOWED_TAGS2, ["tbody"]);
369
+ delete FORBID_TAGS.tbody;
370
+ }
371
+ if (cfg.TRUSTED_TYPES_POLICY) {
372
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
373
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
374
+ }
375
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
376
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
377
+ }
378
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
379
+ emptyHTML = trustedTypesPolicy.createHTML("");
380
+ } else {
381
+ if (trustedTypesPolicy === void 0) {
382
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
383
+ }
384
+ if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
385
+ emptyHTML = trustedTypesPolicy.createHTML("");
386
+ }
387
+ }
388
+ if (freeze) {
389
+ freeze(cfg);
390
+ }
391
+ CONFIG = cfg;
392
+ };
393
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
394
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
395
+ const _checkValidNamespace = function _checkValidNamespace2(element) {
396
+ let parent = getParentNode(element);
397
+ if (!parent || !parent.tagName) {
398
+ parent = {
399
+ namespaceURI: NAMESPACE,
400
+ tagName: "template"
401
+ };
402
+ }
403
+ const tagName = stringToLowerCase(element.tagName);
404
+ const parentTagName = stringToLowerCase(parent.tagName);
405
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
406
+ return false;
407
+ }
408
+ if (element.namespaceURI === SVG_NAMESPACE) {
409
+ if (parent.namespaceURI === HTML_NAMESPACE) {
410
+ return tagName === "svg";
411
+ }
412
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
413
+ return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
414
+ }
415
+ return Boolean(ALL_SVG_TAGS[tagName]);
416
+ }
417
+ if (element.namespaceURI === MATHML_NAMESPACE) {
418
+ if (parent.namespaceURI === HTML_NAMESPACE) {
419
+ return tagName === "math";
420
+ }
421
+ if (parent.namespaceURI === SVG_NAMESPACE) {
422
+ return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
423
+ }
424
+ return Boolean(ALL_MATHML_TAGS[tagName]);
425
+ }
426
+ if (element.namespaceURI === HTML_NAMESPACE) {
427
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
428
+ return false;
429
+ }
430
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
431
+ return false;
432
+ }
433
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
434
+ }
435
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
436
+ return true;
437
+ }
438
+ return false;
439
+ };
440
+ const _forceRemove = function _forceRemove2(node) {
441
+ arrayPush(DOMPurify2.removed, {
442
+ element: node
443
+ });
444
+ try {
445
+ getParentNode(node).removeChild(node);
446
+ } catch (_) {
447
+ remove(node);
448
+ }
449
+ };
450
+ const _removeAttribute = function _removeAttribute2(name, element) {
451
+ try {
452
+ arrayPush(DOMPurify2.removed, {
453
+ attribute: element.getAttributeNode(name),
454
+ from: element
455
+ });
456
+ } catch (_) {
457
+ arrayPush(DOMPurify2.removed, {
458
+ attribute: null,
459
+ from: element
460
+ });
461
+ }
462
+ element.removeAttribute(name);
463
+ if (name === "is") {
464
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
465
+ try {
466
+ _forceRemove(element);
467
+ } catch (_) {
468
+ }
469
+ } else {
470
+ try {
471
+ element.setAttribute(name, "");
472
+ } catch (_) {
473
+ }
474
+ }
475
+ }
476
+ };
477
+ const _initDocument = function _initDocument2(dirty) {
478
+ let doc = null;
479
+ let leadingWhitespace = null;
480
+ if (FORCE_BODY) {
481
+ dirty = "<remove></remove>" + dirty;
482
+ } else {
483
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
484
+ leadingWhitespace = matches && matches[0];
485
+ }
486
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
487
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
488
+ }
489
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
490
+ if (NAMESPACE === HTML_NAMESPACE) {
491
+ try {
492
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
493
+ } catch (_) {
494
+ }
495
+ }
496
+ if (!doc || !doc.documentElement) {
497
+ doc = implementation.createDocument(NAMESPACE, "template", null);
498
+ try {
499
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
500
+ } catch (_) {
501
+ }
502
+ }
503
+ const body = doc.body || doc.documentElement;
504
+ if (dirty && leadingWhitespace) {
505
+ body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
506
+ }
507
+ if (NAMESPACE === HTML_NAMESPACE) {
508
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
509
+ }
510
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
511
+ };
512
+ const _createNodeIterator = function _createNodeIterator2(root) {
513
+ return createNodeIterator.call(
514
+ root.ownerDocument || root,
515
+ root,
516
+ // eslint-disable-next-line no-bitwise
517
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
518
+ null
519
+ );
520
+ };
521
+ const _isClobbered = function _isClobbered2(element) {
522
+ 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");
523
+ };
524
+ const _isNode = function _isNode2(value) {
525
+ return typeof Node === "function" && value instanceof Node;
526
+ };
527
+ function _executeHooks(hooks2, currentNode, data) {
528
+ arrayForEach(hooks2, (hook) => {
529
+ hook.call(DOMPurify2, currentNode, data, CONFIG);
530
+ });
531
+ }
532
+ const _sanitizeElements = function _sanitizeElements2(currentNode) {
533
+ let content = null;
534
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
535
+ if (_isClobbered(currentNode)) {
536
+ _forceRemove(currentNode);
537
+ return true;
538
+ }
539
+ const tagName = transformCaseFunc(currentNode.nodeName);
540
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
541
+ tagName,
542
+ allowedTags: ALLOWED_TAGS2
543
+ });
544
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
545
+ _forceRemove(currentNode);
546
+ return true;
547
+ }
548
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
549
+ _forceRemove(currentNode);
550
+ return true;
551
+ }
552
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
553
+ _forceRemove(currentNode);
554
+ return true;
555
+ }
556
+ if (!ALLOWED_TAGS2[tagName] || FORBID_TAGS[tagName]) {
557
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
558
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
559
+ return false;
560
+ }
561
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
562
+ return false;
563
+ }
564
+ }
565
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
566
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
567
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
568
+ if (childNodes && parentNode) {
569
+ const childCount = childNodes.length;
570
+ for (let i = childCount - 1; i >= 0; --i) {
571
+ const childClone = cloneNode(childNodes[i], true);
572
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
573
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
574
+ }
575
+ }
576
+ }
577
+ _forceRemove(currentNode);
578
+ return true;
579
+ }
580
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
581
+ _forceRemove(currentNode);
582
+ return true;
583
+ }
584
+ if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
585
+ _forceRemove(currentNode);
586
+ return true;
587
+ }
588
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
589
+ content = currentNode.textContent;
590
+ arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
591
+ content = stringReplace(content, expr, " ");
592
+ });
593
+ if (currentNode.textContent !== content) {
594
+ arrayPush(DOMPurify2.removed, {
595
+ element: currentNode.cloneNode()
596
+ });
597
+ currentNode.textContent = content;
598
+ }
599
+ }
600
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
601
+ return false;
602
+ };
603
+ const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
604
+ if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
605
+ return false;
606
+ }
607
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
608
+ else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
609
+ else if (!ALLOWED_ATTR2[lcName] || FORBID_ATTR[lcName]) {
610
+ if (
611
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
612
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
613
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
614
+ _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)) || // Alternative, second condition checks if it's an `is`-attribute, AND
615
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
616
+ 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))
617
+ ) ;
618
+ else {
619
+ return false;
620
+ }
621
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ;
622
+ else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
623
+ else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
624
+ else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
625
+ else if (value) {
626
+ return false;
627
+ } else ;
628
+ return true;
629
+ };
630
+ const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
631
+ return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
632
+ };
633
+ const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
634
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
635
+ const {
636
+ attributes
637
+ } = currentNode;
638
+ if (!attributes || _isClobbered(currentNode)) {
639
+ return;
640
+ }
641
+ const hookEvent = {
642
+ attrName: "",
643
+ attrValue: "",
644
+ keepAttr: true,
645
+ allowedAttributes: ALLOWED_ATTR2,
646
+ forceKeepAttr: void 0
647
+ };
648
+ let l = attributes.length;
649
+ while (l--) {
650
+ const attr = attributes[l];
651
+ const {
652
+ name,
653
+ namespaceURI,
654
+ value: attrValue
655
+ } = attr;
656
+ const lcName = transformCaseFunc(name);
657
+ const initValue = attrValue;
658
+ let value = name === "value" ? initValue : stringTrim(initValue);
659
+ hookEvent.attrName = lcName;
660
+ hookEvent.attrValue = value;
661
+ hookEvent.keepAttr = true;
662
+ hookEvent.forceKeepAttr = void 0;
663
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
664
+ value = hookEvent.attrValue;
665
+ if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
666
+ _removeAttribute(name, currentNode);
667
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
668
+ }
669
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
670
+ _removeAttribute(name, currentNode);
671
+ continue;
672
+ }
673
+ if (hookEvent.forceKeepAttr) {
674
+ continue;
675
+ }
676
+ if (!hookEvent.keepAttr) {
677
+ _removeAttribute(name, currentNode);
678
+ continue;
679
+ }
680
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
681
+ _removeAttribute(name, currentNode);
682
+ continue;
683
+ }
684
+ if (SAFE_FOR_TEMPLATES) {
685
+ arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
686
+ value = stringReplace(value, expr, " ");
687
+ });
688
+ }
689
+ const lcTag = transformCaseFunc(currentNode.nodeName);
690
+ if (!_isValidAttribute(lcTag, lcName, value)) {
691
+ _removeAttribute(name, currentNode);
692
+ continue;
693
+ }
694
+ if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
695
+ if (namespaceURI) ;
696
+ else {
697
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
698
+ case "TrustedHTML": {
699
+ value = trustedTypesPolicy.createHTML(value);
700
+ break;
701
+ }
702
+ case "TrustedScriptURL": {
703
+ value = trustedTypesPolicy.createScriptURL(value);
704
+ break;
705
+ }
706
+ }
707
+ }
708
+ }
709
+ if (value !== initValue) {
710
+ try {
711
+ if (namespaceURI) {
712
+ currentNode.setAttributeNS(namespaceURI, name, value);
713
+ } else {
714
+ currentNode.setAttribute(name, value);
715
+ }
716
+ if (_isClobbered(currentNode)) {
717
+ _forceRemove(currentNode);
718
+ } else {
719
+ arrayPop(DOMPurify2.removed);
720
+ }
721
+ } catch (_) {
722
+ _removeAttribute(name, currentNode);
723
+ }
724
+ }
725
+ }
726
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
727
+ };
728
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
729
+ let shadowNode = null;
730
+ const shadowIterator = _createNodeIterator(fragment);
731
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
732
+ while (shadowNode = shadowIterator.nextNode()) {
733
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
734
+ _sanitizeElements(shadowNode);
735
+ _sanitizeAttributes(shadowNode);
736
+ if (shadowNode.content instanceof DocumentFragment) {
737
+ _sanitizeShadowDOM2(shadowNode.content);
738
+ }
739
+ }
740
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
741
+ };
742
+ DOMPurify2.sanitize = function(dirty) {
743
+ let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
744
+ let body = null;
745
+ let importedNode = null;
746
+ let currentNode = null;
747
+ let returnNode = null;
748
+ IS_EMPTY_INPUT = !dirty;
749
+ if (IS_EMPTY_INPUT) {
750
+ dirty = "<!-->";
751
+ }
752
+ if (typeof dirty !== "string" && !_isNode(dirty)) {
753
+ if (typeof dirty.toString === "function") {
754
+ dirty = dirty.toString();
755
+ if (typeof dirty !== "string") {
756
+ throw typeErrorCreate("dirty is not a string, aborting");
757
+ }
758
+ } else {
759
+ throw typeErrorCreate("toString is not a function");
760
+ }
761
+ }
762
+ if (!DOMPurify2.isSupported) {
763
+ return dirty;
764
+ }
765
+ if (!SET_CONFIG) {
766
+ _parseConfig(cfg);
767
+ }
768
+ DOMPurify2.removed = [];
769
+ if (typeof dirty === "string") {
770
+ IN_PLACE = false;
771
+ }
772
+ if (IN_PLACE) {
773
+ if (dirty.nodeName) {
774
+ const tagName = transformCaseFunc(dirty.nodeName);
775
+ if (!ALLOWED_TAGS2[tagName] || FORBID_TAGS[tagName]) {
776
+ throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
777
+ }
778
+ }
779
+ } else if (dirty instanceof Node) {
780
+ body = _initDocument("<!---->");
781
+ importedNode = body.ownerDocument.importNode(dirty, true);
782
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
783
+ body = importedNode;
784
+ } else if (importedNode.nodeName === "HTML") {
785
+ body = importedNode;
786
+ } else {
787
+ body.appendChild(importedNode);
788
+ }
789
+ } else {
790
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
791
+ dirty.indexOf("<") === -1) {
792
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
793
+ }
794
+ body = _initDocument(dirty);
795
+ if (!body) {
796
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
797
+ }
798
+ }
799
+ if (body && FORCE_BODY) {
800
+ _forceRemove(body.firstChild);
801
+ }
802
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
803
+ while (currentNode = nodeIterator.nextNode()) {
804
+ _sanitizeElements(currentNode);
805
+ _sanitizeAttributes(currentNode);
806
+ if (currentNode.content instanceof DocumentFragment) {
807
+ _sanitizeShadowDOM(currentNode.content);
808
+ }
809
+ }
810
+ if (IN_PLACE) {
811
+ return dirty;
812
+ }
813
+ if (RETURN_DOM) {
814
+ if (RETURN_DOM_FRAGMENT) {
815
+ returnNode = createDocumentFragment.call(body.ownerDocument);
816
+ while (body.firstChild) {
817
+ returnNode.appendChild(body.firstChild);
818
+ }
819
+ } else {
820
+ returnNode = body;
821
+ }
822
+ if (ALLOWED_ATTR2.shadowroot || ALLOWED_ATTR2.shadowrootmode) {
823
+ returnNode = importNode.call(originalDocument, returnNode, true);
824
+ }
825
+ return returnNode;
826
+ }
827
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
828
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS2["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
829
+ serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
830
+ }
831
+ if (SAFE_FOR_TEMPLATES) {
832
+ arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
833
+ serializedHTML = stringReplace(serializedHTML, expr, " ");
834
+ });
835
+ }
836
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
837
+ };
838
+ DOMPurify2.setConfig = function() {
839
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
840
+ _parseConfig(cfg);
841
+ SET_CONFIG = true;
842
+ };
843
+ DOMPurify2.clearConfig = function() {
844
+ CONFIG = null;
845
+ SET_CONFIG = false;
846
+ };
847
+ DOMPurify2.isValidAttribute = function(tag, attr, value) {
848
+ if (!CONFIG) {
849
+ _parseConfig({});
850
+ }
851
+ const lcTag = transformCaseFunc(tag);
852
+ const lcName = transformCaseFunc(attr);
853
+ return _isValidAttribute(lcTag, lcName, value);
854
+ };
855
+ DOMPurify2.addHook = function(entryPoint, hookFunction) {
856
+ if (typeof hookFunction !== "function") {
857
+ return;
858
+ }
859
+ arrayPush(hooks[entryPoint], hookFunction);
860
+ };
861
+ DOMPurify2.removeHook = function(entryPoint, hookFunction) {
862
+ if (hookFunction !== void 0) {
863
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
864
+ return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
865
+ }
866
+ return arrayPop(hooks[entryPoint]);
867
+ };
868
+ DOMPurify2.removeHooks = function(entryPoint) {
869
+ hooks[entryPoint] = [];
870
+ };
871
+ DOMPurify2.removeAllHooks = function() {
872
+ hooks = _createHooksMap();
873
+ };
874
+ return DOMPurify2;
875
+ }
876
+ var entries, setPrototypeOf, isFrozen, getPrototypeOf, getOwnPropertyDescriptor, freeze, seal, create, apply, construct, arrayForEach, arrayLastIndexOf, arrayPop, arrayPush, arraySplice, stringToLowerCase, stringToString, stringMatch, stringReplace, stringIndexOf, stringTrim, objectHasOwnProperty, regExpTest, typeErrorCreate, html$1, svg$1, svgFilters, svgDisallowed, mathMl$1, mathMlDisallowed, text, html, svg, mathMl, xml, MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR, DATA_ATTR, ARIA_ATTR, IS_ALLOWED_URI, IS_SCRIPT_OR_DATA, ATTR_WHITESPACE, DOCTYPE_NAME, CUSTOM_ELEMENT, EXPRESSIONS, NODE_TYPE, getGlobal, _createTrustedTypesPolicy, _createHooksMap, purify;
877
+ var init_purify_es = __esm({
878
+ "node_modules/dompurify/dist/purify.es.mjs"() {
879
+ "use strict";
880
+ ({
881
+ entries,
882
+ setPrototypeOf,
883
+ isFrozen,
884
+ getPrototypeOf,
885
+ getOwnPropertyDescriptor
886
+ } = Object);
887
+ ({
888
+ freeze,
889
+ seal,
890
+ create
891
+ } = Object);
892
+ ({
893
+ apply,
894
+ construct
895
+ } = typeof Reflect !== "undefined" && Reflect);
896
+ if (!freeze) {
897
+ freeze = function freeze2(x) {
898
+ return x;
899
+ };
900
+ }
901
+ if (!seal) {
902
+ seal = function seal2(x) {
903
+ return x;
904
+ };
905
+ }
906
+ if (!apply) {
907
+ apply = function apply2(fun, thisValue, args) {
908
+ return fun.apply(thisValue, args);
909
+ };
910
+ }
911
+ if (!construct) {
912
+ construct = function construct2(Func, args) {
913
+ return new Func(...args);
914
+ };
915
+ }
916
+ arrayForEach = unapply(Array.prototype.forEach);
917
+ arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
918
+ arrayPop = unapply(Array.prototype.pop);
919
+ arrayPush = unapply(Array.prototype.push);
920
+ arraySplice = unapply(Array.prototype.splice);
921
+ stringToLowerCase = unapply(String.prototype.toLowerCase);
922
+ stringToString = unapply(String.prototype.toString);
923
+ stringMatch = unapply(String.prototype.match);
924
+ stringReplace = unapply(String.prototype.replace);
925
+ stringIndexOf = unapply(String.prototype.indexOf);
926
+ stringTrim = unapply(String.prototype.trim);
927
+ objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
928
+ regExpTest = unapply(RegExp.prototype.test);
929
+ typeErrorCreate = unconstruct(TypeError);
930
+ 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", "section", "select", "shadow", "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"]);
931
+ svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
932
+ 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"]);
933
+ 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"]);
934
+ 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"]);
935
+ mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
936
+ text = freeze(["#text"]);
937
+ 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", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "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", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
938
+ 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", "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"]);
939
+ 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"]);
940
+ xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
941
+ MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
942
+ ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
943
+ TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
944
+ DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
945
+ ARIA_ATTR = seal(/^aria-[\-\w]+$/);
946
+ IS_ALLOWED_URI = seal(
947
+ /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
948
+ // eslint-disable-line no-useless-escape
949
+ );
950
+ IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
951
+ ATTR_WHITESPACE = seal(
952
+ /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
953
+ // eslint-disable-line no-control-regex
954
+ );
955
+ DOCTYPE_NAME = seal(/^html$/i);
956
+ CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
957
+ EXPRESSIONS = /* @__PURE__ */ Object.freeze({
958
+ __proto__: null,
959
+ ARIA_ATTR,
960
+ ATTR_WHITESPACE,
961
+ CUSTOM_ELEMENT,
962
+ DATA_ATTR,
963
+ DOCTYPE_NAME,
964
+ ERB_EXPR,
965
+ IS_ALLOWED_URI,
966
+ IS_SCRIPT_OR_DATA,
967
+ MUSTACHE_EXPR,
968
+ TMPLIT_EXPR
969
+ });
970
+ NODE_TYPE = {
971
+ element: 1,
972
+ attribute: 2,
973
+ text: 3,
974
+ cdataSection: 4,
975
+ entityReference: 5,
976
+ // Deprecated
977
+ entityNode: 6,
978
+ // Deprecated
979
+ progressingInstruction: 7,
980
+ comment: 8,
981
+ document: 9,
982
+ documentType: 10,
983
+ documentFragment: 11,
984
+ notation: 12
985
+ // Deprecated
986
+ };
987
+ getGlobal = function getGlobal2() {
988
+ return typeof window === "undefined" ? null : window;
989
+ };
990
+ _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
991
+ if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
992
+ return null;
993
+ }
994
+ let suffix = null;
995
+ const ATTR_NAME = "data-tt-policy-suffix";
996
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
997
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
998
+ }
999
+ const policyName = "dompurify" + (suffix ? "#" + suffix : "");
1000
+ try {
1001
+ return trustedTypes.createPolicy(policyName, {
1002
+ createHTML(html2) {
1003
+ return html2;
1004
+ },
1005
+ createScriptURL(scriptUrl) {
1006
+ return scriptUrl;
1007
+ }
1008
+ });
1009
+ } catch (_) {
1010
+ console.warn("TrustedTypes policy " + policyName + " could not be created.");
1011
+ return null;
1012
+ }
1013
+ };
1014
+ _createHooksMap = function _createHooksMap2() {
1015
+ return {
1016
+ afterSanitizeAttributes: [],
1017
+ afterSanitizeElements: [],
1018
+ afterSanitizeShadowDOM: [],
1019
+ beforeSanitizeAttributes: [],
1020
+ beforeSanitizeElements: [],
1021
+ beforeSanitizeShadowDOM: [],
1022
+ uponSanitizeAttribute: [],
1023
+ uponSanitizeElement: [],
1024
+ uponSanitizeShadowNode: []
1025
+ };
1026
+ };
1027
+ purify = createDOMPurify();
1028
+ }
1029
+ });
1030
+
1031
+ // src/standalone.ts
1032
+ var standalone_exports = {};
1033
+ __export(standalone_exports, {
1034
+ ChangerawrMarkdown: () => ChangerawrMarkdown,
1035
+ createCumEngine: () => createCumEngine,
1036
+ default: () => standalone_default,
1037
+ parseCum: () => parseCum,
1038
+ renderCum: () => renderCum,
1039
+ renderCumToHtml: () => renderCumToHtml,
1040
+ renderCumToJson: () => renderCumToJson,
1041
+ renderCumToTailwind: () => renderCumToTailwind
1042
+ });
1043
+
1044
+ // src/parser.ts
1045
+ var MarkdownParser = class {
1046
+ constructor(config) {
1047
+ this.rules = [];
1048
+ this.warnings = [];
1049
+ this.config = config || {};
1050
+ }
1051
+ addRule(rule) {
1052
+ this.rules.push(rule);
1053
+ this.rules.sort((a, b) => {
1054
+ if (a.name.includes("alert") || a.name.includes("embed") || a.name.includes("button")) return -1;
1055
+ if (b.name.includes("alert") || b.name.includes("embed") || b.name.includes("button")) return 1;
1056
+ if (a.name === "task-list") return -1;
1057
+ if (b.name === "task-list") return 1;
1058
+ if (a.name === "list" && b.name === "task-list") return 1;
1059
+ if (b.name === "list" && a.name === "task-list") return -1;
1060
+ return a.name.localeCompare(b.name);
1061
+ });
1062
+ }
1063
+ setupDefaultRulesIfEmpty() {
1064
+ const hasDefaultRules = this.rules.some(
1065
+ (rule) => !["alert", "button", "embed"].includes(rule.name)
1066
+ );
1067
+ if (!hasDefaultRules) {
1068
+ this.setupDefaultRules();
1069
+ }
1070
+ }
1071
+ hasRule(name) {
1072
+ return this.rules.some((rule) => rule.name === name);
1073
+ }
1074
+ parse(markdown2) {
1075
+ var _a;
1076
+ this.warnings = [];
1077
+ this.setupDefaultRulesIfEmpty();
1078
+ const processedMarkdown = this.preprocessMarkdown(markdown2);
1079
+ const tokens = [];
1080
+ let remaining = processedMarkdown;
1081
+ let iterationCount = 0;
1082
+ const maxIterations = this.config.maxIterations || markdown2.length * 2;
1083
+ while (remaining.length > 0 && iterationCount < maxIterations) {
1084
+ iterationCount++;
1085
+ let matched = false;
1086
+ let bestMatch = null;
1087
+ for (const rule of this.rules) {
1088
+ try {
1089
+ const pattern = new RegExp(rule.pattern.source, rule.pattern.flags.replace("g", ""));
1090
+ const match = remaining.match(pattern);
1091
+ if (match && match.index !== void 0) {
1092
+ const priority = match.index === 0 ? 1e3 : 1e3 - match.index;
1093
+ if (!bestMatch || priority > bestMatch.priority || priority === bestMatch.priority && match.index < (bestMatch.match.index || 0)) {
1094
+ bestMatch = { rule, match, priority };
1095
+ }
1096
+ }
1097
+ } catch (error) {
1098
+ if (this.config.debugMode) {
1099
+ console.warn(`Error in rule "${rule.name}":`, error);
1100
+ }
1101
+ }
1102
+ }
1103
+ if (bestMatch && bestMatch.match.index !== void 0) {
1104
+ const { rule, match } = bestMatch;
1105
+ const matchIndex = match.index;
1106
+ if (matchIndex > 0) {
1107
+ const textBefore = remaining.slice(0, matchIndex);
1108
+ tokens.push({
1109
+ type: "text",
1110
+ content: textBefore,
1111
+ raw: textBefore
1112
+ });
1113
+ remaining = remaining.slice(matchIndex);
1114
+ continue;
1115
+ }
1116
+ try {
1117
+ const token = rule.render(match);
1118
+ tokens.push(__spreadProps(__spreadValues({}, token), {
1119
+ raw: match[0] || ""
1120
+ }));
1121
+ remaining = remaining.slice(((_a = match[0]) == null ? void 0 : _a.length) || 0);
1122
+ matched = true;
1123
+ } catch (error) {
1124
+ const errorMessage = error instanceof Error ? error.message : String(error);
1125
+ this.warnings.push(`Failed to render ${rule.name}: ${errorMessage}`);
1126
+ const char = remaining[0];
1127
+ if (char) {
1128
+ tokens.push({
1129
+ type: "text",
1130
+ content: char,
1131
+ raw: char
1132
+ });
1133
+ remaining = remaining.slice(1);
1134
+ }
1135
+ }
1136
+ }
1137
+ if (!matched) {
1138
+ const char = remaining[0];
1139
+ if (char) {
1140
+ tokens.push({
1141
+ type: "text",
1142
+ content: char,
1143
+ raw: char
1144
+ });
1145
+ remaining = remaining.slice(1);
1146
+ }
1147
+ }
1148
+ }
1149
+ if (iterationCount >= maxIterations) {
1150
+ this.warnings.push("Parser hit maximum iterations - possible infinite loop detected");
1151
+ }
1152
+ const processedTokens = this.postProcessTokens(tokens);
1153
+ return processedTokens;
1154
+ }
1155
+ getWarnings() {
1156
+ return [...this.warnings];
1157
+ }
1158
+ getConfig() {
1159
+ return __spreadValues({}, this.config);
1160
+ }
1161
+ updateConfig(config) {
1162
+ this.config = __spreadValues(__spreadValues({}, this.config), config);
1163
+ }
1164
+ setDebugMode(enabled) {
1165
+ this.config.debugMode = enabled;
1166
+ }
1167
+ clearWarnings() {
1168
+ this.warnings = [];
1169
+ }
1170
+ getIterationCount() {
1171
+ return 0;
1172
+ }
1173
+ preprocessMarkdown(markdown2) {
1174
+ if (this.config.validateMarkdown) {
1175
+ this.validateMarkdown(markdown2);
1176
+ }
1177
+ return markdown2.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
1178
+ }
1179
+ validateMarkdown(markdown2) {
1180
+ const boldMatches = markdown2.match(/\*\*/g);
1181
+ if (boldMatches && boldMatches.length % 2 !== 0) {
1182
+ this.warnings.push("Unclosed bold markers (**) detected - some bold formatting may not work");
1183
+ }
1184
+ const italicMatches = markdown2.match(new RegExp("(?<!\\*)\\*(?!\\*)", "g"));
1185
+ if (italicMatches && italicMatches.length % 2 !== 0) {
1186
+ this.warnings.push("Unclosed italic markers (*) detected - some italic formatting may not work");
1187
+ }
1188
+ const codeBlockMatches = markdown2.match(/```/g);
1189
+ if (codeBlockMatches && codeBlockMatches.length % 2 !== 0) {
1190
+ this.warnings.push("Unclosed code blocks (```) detected - some code formatting may not work");
1191
+ }
1192
+ const inlineCodeMatches = markdown2.match(/`/g);
1193
+ if (inlineCodeMatches && inlineCodeMatches.length % 2 !== 0) {
1194
+ this.warnings.push("Unclosed inline code markers (`) detected - some code formatting may not work");
1195
+ }
1196
+ }
1197
+ postProcessTokens(tokens) {
1198
+ const processed = [];
1199
+ let i = 0;
1200
+ while (i < tokens.length) {
1201
+ const token = tokens[i];
1202
+ if (token && token.type === "text") {
1203
+ let textContent = token.content || token.raw || "";
1204
+ let j = i + 1;
1205
+ while (j < tokens.length && tokens[j] && tokens[j].type === "text") {
1206
+ const nextToken = tokens[j];
1207
+ textContent += nextToken.content || nextToken.raw || "";
1208
+ j++;
1209
+ }
1210
+ if (textContent.trim().length > 0 || textContent.includes("\n")) {
1211
+ processed.push({
1212
+ type: "text",
1213
+ content: textContent,
1214
+ raw: textContent
1215
+ });
1216
+ }
1217
+ i = j;
1218
+ } else if (token) {
1219
+ processed.push(token);
1220
+ i++;
1221
+ } else {
1222
+ i++;
1223
+ }
1224
+ }
1225
+ return processed;
1226
+ }
1227
+ setupDefaultRules() {
1228
+ this.addRule({
1229
+ name: "heading",
1230
+ pattern: /^(#{1,6})\s+(.+)$/m,
1231
+ render: (match) => {
1232
+ var _a, _b;
1233
+ return {
1234
+ type: "heading",
1235
+ content: ((_a = match[2]) == null ? void 0 : _a.trim()) || "",
1236
+ raw: match[0] || "",
1237
+ attributes: {
1238
+ level: String(((_b = match[1]) == null ? void 0 : _b.length) || 1)
1239
+ }
1240
+ };
1241
+ }
1242
+ });
1243
+ this.addRule({
1244
+ name: "codeblock",
1245
+ pattern: /```(\w+)?\s*\n([\s\S]*?)\n```/,
1246
+ render: (match) => ({
1247
+ type: "codeblock",
1248
+ content: match[2] || "",
1249
+ raw: match[0] || "",
1250
+ attributes: {
1251
+ language: match[1] || "text"
1252
+ }
1253
+ })
1254
+ });
1255
+ this.addRule({
1256
+ name: "hard-break-backslash",
1257
+ pattern: /\\\s*\n/,
1258
+ render: (match) => ({
1259
+ type: "line-break",
1260
+ content: "",
1261
+ raw: match[0] || ""
1262
+ })
1263
+ });
1264
+ this.addRule({
1265
+ name: "hard-break-spaces",
1266
+ pattern: / +\n/,
1267
+ render: (match) => ({
1268
+ type: "line-break",
1269
+ content: "",
1270
+ raw: match[0] || ""
1271
+ })
1272
+ });
1273
+ this.addRule({
1274
+ name: "paragraph-break",
1275
+ pattern: /\n\s*\n/,
1276
+ render: (match) => ({
1277
+ type: "paragraph-break",
1278
+ content: "",
1279
+ raw: match[0] || ""
1280
+ })
1281
+ });
1282
+ this.addRule({
1283
+ name: "bold",
1284
+ pattern: /\*\*((?:(?!\*\*).)+)\*\*/,
1285
+ render: (match) => ({
1286
+ type: "bold",
1287
+ content: match[1] || "",
1288
+ raw: match[0] || ""
1289
+ })
1290
+ });
1291
+ this.addRule({
1292
+ name: "italic",
1293
+ pattern: /\*((?:(?!\*).)+)\*/,
1294
+ render: (match) => ({
1295
+ type: "italic",
1296
+ content: match[1] || "",
1297
+ raw: match[0] || ""
1298
+ })
1299
+ });
1300
+ this.addRule({
1301
+ name: "code",
1302
+ pattern: /`([^`]+)`/,
1303
+ render: (match) => ({
1304
+ type: "code",
1305
+ content: match[1] || "",
1306
+ raw: match[0] || ""
1307
+ })
1308
+ });
1309
+ this.addRule({
1310
+ name: "image",
1311
+ pattern: /!\[([^\]]*)\]\(([^)]+?)(?:\s+"([^"]+)")?\)/,
1312
+ render: (match) => ({
1313
+ type: "image",
1314
+ content: match[1] || "",
1315
+ raw: match[0] || "",
1316
+ attributes: {
1317
+ alt: match[1] || "",
1318
+ src: match[2] || "",
1319
+ title: match[3] || ""
1320
+ }
1321
+ })
1322
+ });
1323
+ this.addRule({
1324
+ name: "link",
1325
+ pattern: /\[([^\]]+)\]\(([^)]+)\)/,
1326
+ render: (match) => ({
1327
+ type: "link",
1328
+ content: match[1] || "",
1329
+ raw: match[0] || "",
1330
+ attributes: {
1331
+ href: match[2] || ""
1332
+ }
1333
+ })
1334
+ });
1335
+ this.addRule({
1336
+ name: "task-list",
1337
+ pattern: /^(\s*)-\s*\[([ xX])\]\s*(.+)$/m,
1338
+ render: (match) => ({
1339
+ type: "task-item",
1340
+ content: match[3] || "",
1341
+ raw: match[0] || "",
1342
+ attributes: {
1343
+ checked: String((match[2] || "").toLowerCase() === "x")
1344
+ }
1345
+ })
1346
+ });
1347
+ this.addRule({
1348
+ name: "list",
1349
+ pattern: /^(\s*)[-*+]\s+(.+)$/m,
1350
+ render: (match) => ({
1351
+ type: "list-item",
1352
+ content: match[2] || "",
1353
+ raw: match[0] || ""
1354
+ })
1355
+ });
1356
+ this.addRule({
1357
+ name: "blockquote",
1358
+ pattern: /^>\s+(.+)$/m,
1359
+ render: (match) => ({
1360
+ type: "blockquote",
1361
+ content: match[1] || "",
1362
+ raw: match[0] || ""
1363
+ })
1364
+ });
1365
+ this.addRule({
1366
+ name: "hr",
1367
+ pattern: /^---$/m,
1368
+ render: (match) => ({
1369
+ type: "hr",
1370
+ content: "",
1371
+ raw: match[0] || ""
1372
+ })
1373
+ });
1374
+ this.addRule({
1375
+ name: "soft-break",
1376
+ pattern: /\n/,
1377
+ render: (match) => ({
1378
+ type: "soft-break",
1379
+ content: " ",
1380
+ // Convert to space for inline text
1381
+ raw: match[0] || ""
1382
+ })
1383
+ });
1384
+ }
1385
+ };
1386
+
1387
+ // src/utils.ts
1388
+ var DOMPurify = {
1389
+ sanitize: (html2) => html2
1390
+ };
1391
+ if (typeof window !== "undefined") {
1392
+ Promise.resolve().then(() => (init_purify_es(), purify_es_exports)).then((module) => {
1393
+ DOMPurify = module.default;
1394
+ }).catch((err) => {
1395
+ console.error("Failed to load DOMPurify", err);
1396
+ });
1397
+ }
1398
+ var ALLOWED_TAGS = [
1399
+ // Standard HTML
1400
+ "h1",
1401
+ "h2",
1402
+ "h3",
1403
+ "h4",
1404
+ "h5",
1405
+ "h6",
1406
+ "p",
1407
+ "br",
1408
+ "strong",
1409
+ "em",
1410
+ "del",
1411
+ "ins",
1412
+ "a",
1413
+ "img",
1414
+ "ul",
1415
+ "ol",
1416
+ "li",
1417
+ "blockquote",
1418
+ "pre",
1419
+ "code",
1420
+ "table",
1421
+ "thead",
1422
+ "tbody",
1423
+ "tr",
1424
+ "th",
1425
+ "td",
1426
+ "div",
1427
+ "span",
1428
+ "sup",
1429
+ "sub",
1430
+ "hr",
1431
+ "input",
1432
+ // Embeds
1433
+ "iframe",
1434
+ "embed",
1435
+ "object",
1436
+ "param",
1437
+ "video",
1438
+ "audio",
1439
+ "source",
1440
+ // SVG
1441
+ "svg",
1442
+ "path",
1443
+ "polyline",
1444
+ "line",
1445
+ "circle",
1446
+ "rect",
1447
+ "g",
1448
+ "defs",
1449
+ "use",
1450
+ // Form elements
1451
+ "form",
1452
+ "fieldset",
1453
+ "legend",
1454
+ "label",
1455
+ "select",
1456
+ "option",
1457
+ "textarea",
1458
+ "button"
1459
+ ];
1460
+ var ALLOWED_ATTR = [
1461
+ // Standard attributes
1462
+ "href",
1463
+ "title",
1464
+ "alt",
1465
+ "src",
1466
+ "class",
1467
+ "id",
1468
+ "target",
1469
+ "rel",
1470
+ "type",
1471
+ "checked",
1472
+ "disabled",
1473
+ "loading",
1474
+ "width",
1475
+ "height",
1476
+ "style",
1477
+ "role",
1478
+ // Iframe attributes
1479
+ "frameborder",
1480
+ "allowfullscreen",
1481
+ "allow",
1482
+ "sandbox",
1483
+ "scrolling",
1484
+ "allowtransparency",
1485
+ "name",
1486
+ "seamless",
1487
+ "srcdoc",
1488
+ // Data attributes (for embeds)
1489
+ "data-*",
1490
+ // SVG attributes
1491
+ "viewBox",
1492
+ "fill",
1493
+ "stroke",
1494
+ "stroke-width",
1495
+ "stroke-linecap",
1496
+ "stroke-linejoin",
1497
+ "d",
1498
+ "points",
1499
+ "x1",
1500
+ "y1",
1501
+ "x2",
1502
+ "y2",
1503
+ "cx",
1504
+ "cy",
1505
+ "r",
1506
+ "rx",
1507
+ "ry",
1508
+ // Media attributes
1509
+ "autoplay",
1510
+ "controls",
1511
+ "loop",
1512
+ "muted",
1513
+ "preload",
1514
+ "poster",
1515
+ // Form attributes
1516
+ "value",
1517
+ "placeholder",
1518
+ "required",
1519
+ "readonly",
1520
+ "maxlength",
1521
+ "minlength",
1522
+ "max",
1523
+ "min",
1524
+ "step",
1525
+ "pattern",
1526
+ "autocomplete",
1527
+ "autofocus"
1528
+ ];
1529
+ function escapeHtml(text2) {
1530
+ const map = {
1531
+ "&": "&amp;",
1532
+ "<": "&lt;",
1533
+ ">": "&gt;",
1534
+ '"': "&quot;",
1535
+ "'": "&#39;"
1536
+ };
1537
+ return text2.replace(/[&<>"']/g, (char) => map[char] || char);
1538
+ }
1539
+ function generateId(text2) {
1540
+ return text2.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").trim();
1541
+ }
1542
+ function sanitizeHtml(html2) {
1543
+ try {
1544
+ if (html2.includes("codepen.io/") || html2.includes("youtube.com/embed/")) {
1545
+ return html2;
1546
+ }
1547
+ if (typeof (DOMPurify == null ? void 0 : DOMPurify.sanitize) === "function") {
1548
+ const sanitized = DOMPurify.sanitize(html2, {
1549
+ ALLOWED_TAGS,
1550
+ ALLOWED_ATTR,
1551
+ ALLOW_DATA_ATTR: true,
1552
+ ALLOW_UNKNOWN_PROTOCOLS: false,
1553
+ SAFE_FOR_TEMPLATES: false,
1554
+ WHOLE_DOCUMENT: false,
1555
+ RETURN_DOM: false,
1556
+ RETURN_DOM_FRAGMENT: false,
1557
+ FORCE_BODY: false,
1558
+ SANITIZE_DOM: false,
1559
+ SANITIZE_NAMED_PROPS: false,
1560
+ FORBID_ATTR: ["onload", "onerror", "onclick", "onmouseover", "onmouseout", "onfocus", "onblur"],
1561
+ ADD_TAGS: ["iframe", "embed", "object", "param"],
1562
+ ADD_ATTR: [
1563
+ "allow",
1564
+ "allowfullscreen",
1565
+ "frameborder",
1566
+ "scrolling",
1567
+ "allowtransparency",
1568
+ "sandbox",
1569
+ "loading",
1570
+ "style",
1571
+ "title",
1572
+ "name",
1573
+ "seamless",
1574
+ "srcdoc"
1575
+ ],
1576
+ ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
1577
+ });
1578
+ if (sanitized.length < html2.length * 0.7) {
1579
+ return basicSanitize(html2);
1580
+ }
1581
+ return sanitized;
1582
+ }
1583
+ return basicSanitize(html2);
1584
+ } catch (error) {
1585
+ console.error("Sanitization failed:", error);
1586
+ return basicSanitize(html2);
1587
+ }
1588
+ }
1589
+ function basicSanitize(html2) {
1590
+ return html2.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/on\w+\s*=\s*"[^"]*"/gi, "").replace(/on\w+\s*=\s*'[^']*'/gi, "").replace(/javascript:/gi, "");
1591
+ }
1592
+ function extractDomain(url) {
1593
+ try {
1594
+ return new URL(url).hostname;
1595
+ } catch (e) {
1596
+ return url;
1597
+ }
1598
+ }
1599
+ function parseOptions(options) {
1600
+ const parsed = {};
1601
+ if (!options) return parsed;
1602
+ options.split(",").forEach((option) => {
1603
+ const [key, value] = option.split(":").map((s) => s.trim());
1604
+ if (key && value) {
1605
+ parsed[key] = value;
1606
+ }
1607
+ });
1608
+ return parsed;
1609
+ }
1610
+
1611
+ // src/renderer.ts
1612
+ var MarkdownRenderer = class {
1613
+ constructor(config) {
1614
+ this.rules = /* @__PURE__ */ new Map();
1615
+ this.warnings = [];
1616
+ this.config = __spreadValues({
1617
+ format: "tailwind",
1618
+ sanitize: true,
1619
+ allowUnsafeHtml: false,
1620
+ debugMode: false
1621
+ }, config);
1622
+ this.setupDefaultRules();
1623
+ }
1624
+ addRule(rule) {
1625
+ this.rules.set(rule.type, rule);
1626
+ }
1627
+ hasRule(type) {
1628
+ return this.rules.has(type);
1629
+ }
1630
+ render(tokens) {
1631
+ this.warnings = [];
1632
+ const htmlParts = tokens.map((token) => this.renderToken(token));
1633
+ const combinedHtml = htmlParts.join("");
1634
+ if (this.config.sanitize && !this.config.allowUnsafeHtml) {
1635
+ return sanitizeHtml(combinedHtml);
1636
+ }
1637
+ return combinedHtml;
1638
+ }
1639
+ getWarnings() {
1640
+ return [...this.warnings];
1641
+ }
1642
+ getConfig() {
1643
+ return __spreadValues({}, this.config);
1644
+ }
1645
+ updateConfig(config) {
1646
+ this.config = __spreadValues(__spreadValues({}, this.config), config);
1647
+ }
1648
+ setDebugMode(enabled) {
1649
+ this.config.debugMode = enabled;
1650
+ }
1651
+ clearWarnings() {
1652
+ this.warnings = [];
1653
+ }
1654
+ renderToken(token) {
1655
+ const rule = this.rules.get(token.type);
1656
+ if (rule) {
1657
+ try {
1658
+ return rule.render(token);
1659
+ } catch (error) {
1660
+ const errorMessage = error instanceof Error ? error.message : String(error);
1661
+ this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
1662
+ return this.createErrorBlock(`Render error for ${token.type}: ${errorMessage}`);
1663
+ }
1664
+ }
1665
+ if (token.type === "text") {
1666
+ return escapeHtml(token.content || token.raw || "");
1667
+ }
1668
+ if (this.config.debugMode) {
1669
+ return this.createDebugBlock(token);
1670
+ }
1671
+ return escapeHtml(token.content || token.raw || "");
1672
+ }
1673
+ createErrorBlock(message) {
1674
+ if (this.config.format === "html") {
1675
+ return `<div style="background-color: #fee; border: 1px solid #fcc; color: #c66; padding: 8px; border-radius: 4px; margin: 8px 0; font-size: 14px;">
1676
+ <strong>Render Error:</strong> ${escapeHtml(message)}
1677
+ </div>`;
1678
+ }
1679
+ return `<div class="bg-red-100 border border-red-300 text-red-800 p-2 rounded text-sm mb-2">
1680
+ <strong>Render Error:</strong> ${escapeHtml(message)}
1681
+ </div>`;
1682
+ }
1683
+ createDebugBlock(token) {
1684
+ if (this.config.format === "html") {
1685
+ return `<div style="background-color: #fffbf0; border: 1px solid #fed; color: #b8860b; padding: 8px; border-radius: 4px; margin: 8px 0; font-size: 14px;">
1686
+ <strong>Unknown token type:</strong> ${escapeHtml(token.type)}<br>
1687
+ <strong>Content:</strong> ${escapeHtml(token.content || token.raw || "")}
1688
+ </div>`;
1689
+ }
1690
+ return `<div class="bg-yellow-100 border border-yellow-300 text-yellow-800 p-2 rounded text-sm mb-2">
1691
+ <strong>Unknown token type:</strong> ${escapeHtml(token.type)}<br>
1692
+ <strong>Content:</strong> ${escapeHtml(token.content || token.raw || "")}
1693
+ </div>`;
1694
+ }
1695
+ setupDefaultRules() {
1696
+ this.addRule({
1697
+ type: "heading",
1698
+ render: (token) => {
1699
+ var _a;
1700
+ const level = parseInt(((_a = token.attributes) == null ? void 0 : _a.level) || "1");
1701
+ const text2 = token.content;
1702
+ const id = generateId(text2);
1703
+ const escapedContent = escapeHtml(text2);
1704
+ if (this.config.format === "html") {
1705
+ return `<h${level} id="${id}">${escapedContent}</h${level}>`;
1706
+ }
1707
+ let headingClasses = "group relative flex items-center gap-2";
1708
+ switch (level) {
1709
+ case 1:
1710
+ headingClasses += " text-3xl font-bold mt-8 mb-4";
1711
+ break;
1712
+ case 2:
1713
+ headingClasses += " text-2xl font-semibold mt-6 mb-3";
1714
+ break;
1715
+ case 3:
1716
+ headingClasses += " text-xl font-medium mt-5 mb-3";
1717
+ break;
1718
+ case 4:
1719
+ headingClasses += " text-lg font-medium mt-4 mb-2";
1720
+ break;
1721
+ case 5:
1722
+ headingClasses += " text-base font-medium mt-3 mb-2";
1723
+ break;
1724
+ case 6:
1725
+ headingClasses += " text-sm font-medium mt-3 mb-2";
1726
+ break;
1727
+ }
1728
+ return `<h${level} id="${id}" class="${headingClasses}">
1729
+ ${escapedContent}
1730
+ <a href="#${id}" class="opacity-0 group-hover:opacity-100 text-muted-foreground transition-opacity">
1731
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
1732
+ <path d="M7.5 4H5.75A3.75 3.75 0 002 7.75v.5a3.75 3.75 0 003.75 3.75h1.5m-1.5-4h3m1.5-4h1.75A3.75 3.75 0 0114 7.75v.5a3.75 3.75 0 01-3.75 3.75H8.5"/>
1733
+ </svg>
1734
+ </a>
1735
+ </h${level}>`;
1736
+ }
1737
+ });
1738
+ this.addRule({
1739
+ type: "bold",
1740
+ render: (token) => {
1741
+ const content = escapeHtml(token.content);
1742
+ if (this.config.format === "html") {
1743
+ return `<strong>${content}</strong>`;
1744
+ }
1745
+ return `<strong class="font-bold">${content}</strong>`;
1746
+ }
1747
+ });
1748
+ this.addRule({
1749
+ type: "italic",
1750
+ render: (token) => {
1751
+ const content = escapeHtml(token.content);
1752
+ if (this.config.format === "html") {
1753
+ return `<em>${content}</em>`;
1754
+ }
1755
+ return `<em class="italic">${content}</em>`;
1756
+ }
1757
+ });
1758
+ this.addRule({
1759
+ type: "code",
1760
+ render: (token) => {
1761
+ const content = escapeHtml(token.content);
1762
+ if (this.config.format === "html") {
1763
+ return `<code style="background-color: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 0.875rem;">${content}</code>`;
1764
+ }
1765
+ return `<code class="bg-muted px-1.5 py-0.5 rounded text-sm font-mono">${content}</code>`;
1766
+ }
1767
+ });
1768
+ this.addRule({
1769
+ type: "codeblock",
1770
+ render: (token) => {
1771
+ var _a;
1772
+ const language = ((_a = token.attributes) == null ? void 0 : _a.language) || "text";
1773
+ const escapedCode = escapeHtml(token.content);
1774
+ if (this.config.format === "html") {
1775
+ return `<pre style="background-color: #f3f4f6; padding: 16px; border-radius: 6px; overflow-x: auto; margin: 16px 0;"><code class="language-${escapeHtml(language)}">${escapedCode}</code></pre>`;
1776
+ }
1777
+ return `<pre class="bg-muted p-4 rounded-md overflow-x-auto my-4"><code class="language-${escapeHtml(language)}">${escapedCode}</code></pre>`;
1778
+ }
1779
+ });
1780
+ this.addRule({
1781
+ type: "link",
1782
+ render: (token) => {
1783
+ var _a;
1784
+ const href = ((_a = token.attributes) == null ? void 0 : _a.href) || "#";
1785
+ const escapedHref = escapeHtml(href);
1786
+ const escapedText = escapeHtml(token.content);
1787
+ if (this.config.format === "html") {
1788
+ return `<a href="${escapedHref}" target="_blank" rel="noopener noreferrer">${escapedText}</a>`;
1789
+ }
1790
+ return `<a href="${escapedHref}" class="text-primary hover:underline inline-flex items-center gap-1" target="_blank" rel="noopener noreferrer">
1791
+ ${escapedText}
1792
+ <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link">
1793
+ <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
1794
+ <polyline points="15 3 21 3 21 9"></polyline>
1795
+ <line x1="10" y1="14" x2="21" y2="3"></line>
1796
+ </svg>
1797
+ </a>`;
1798
+ }
1799
+ });
1800
+ this.addRule({
1801
+ type: "list-item",
1802
+ render: (token) => `<li>${escapeHtml(token.content)}</li>`
1803
+ });
1804
+ this.addRule({
1805
+ type: "blockquote",
1806
+ render: (token) => {
1807
+ const content = escapeHtml(token.content);
1808
+ if (this.config.format === "html") {
1809
+ return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
1810
+ }
1811
+ return `<blockquote class="pl-4 py-2 border-l-2 border-border italic text-muted-foreground my-4">${content}</blockquote>`;
1812
+ }
1813
+ });
1814
+ this.addRule({
1815
+ type: "text",
1816
+ render: (token) => {
1817
+ if (!token.content) return "";
1818
+ return escapeHtml(token.content);
1819
+ }
1820
+ });
1821
+ this.addRule({
1822
+ type: "paragraph",
1823
+ render: (token) => {
1824
+ if (!token.content) return "";
1825
+ const content = token.content.trim();
1826
+ if (!content) return "";
1827
+ const processedContent = content.includes("<br>") ? content : escapeHtml(content);
1828
+ if (this.config.format === "html") {
1829
+ return `<p style="line-height: 1.75; margin-bottom: 16px;">${processedContent}</p>`;
1830
+ }
1831
+ return `<p class="leading-7 mb-4">${processedContent}</p>`;
1832
+ }
1833
+ });
1834
+ this.addRule({
1835
+ type: "task-item",
1836
+ render: (token) => {
1837
+ var _a;
1838
+ const isChecked = ((_a = token.attributes) == null ? void 0 : _a.checked) === "true";
1839
+ const escapedContent = escapeHtml(token.content);
1840
+ if (this.config.format === "html") {
1841
+ return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1842
+ <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1843
+ <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${escapedContent}</span>
1844
+ </div>`;
1845
+ }
1846
+ return `<div class="flex items-center gap-2 my-2 task-list-item">
1847
+ <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1848
+ class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1849
+ <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${escapedContent}</span>
1850
+ </div>`;
1851
+ }
1852
+ });
1853
+ this.addRule({
1854
+ type: "image",
1855
+ render: (token) => {
1856
+ var _a, _b, _c;
1857
+ const src = ((_a = token.attributes) == null ? void 0 : _a.src) || "";
1858
+ const alt = ((_b = token.attributes) == null ? void 0 : _b.alt) || "";
1859
+ const title = ((_c = token.attributes) == null ? void 0 : _c.title) || "";
1860
+ const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
1861
+ if (this.config.format === "html") {
1862
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1863
+ }
1864
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1865
+ }
1866
+ });
1867
+ this.addRule({
1868
+ type: "hr",
1869
+ render: () => {
1870
+ if (this.config.format === "html") {
1871
+ return '<hr style="margin: 24px 0; border: none; border-top: 1px solid #d1d5db;">';
1872
+ }
1873
+ return '<hr class="my-6 border-t border-border">';
1874
+ }
1875
+ });
1876
+ this.addRule({
1877
+ type: "line-break",
1878
+ render: () => "<br>"
1879
+ });
1880
+ this.addRule({
1881
+ type: "paragraph-break",
1882
+ render: () => "</p><p>"
1883
+ });
1884
+ this.addRule({
1885
+ type: "soft-break",
1886
+ render: (token) => token.content || " "
1887
+ });
1888
+ }
1889
+ };
1890
+
1891
+ // src/extensions/alert.ts
1892
+ var AlertExtension = {
1893
+ name: "alert",
1894
+ parseRules: [
1895
+ {
1896
+ name: "alert",
1897
+ pattern: /:::(\w+)(?:\s+(.*?))?\s*\n([\s\S]*?)\n:::/,
1898
+ render: (match) => {
1899
+ var _a;
1900
+ return {
1901
+ type: "alert",
1902
+ content: ((_a = match[3]) == null ? void 0 : _a.trim()) || "",
1903
+ raw: match[0] || "",
1904
+ attributes: {
1905
+ type: match[1] || "info",
1906
+ title: match[2] || ""
1907
+ }
1908
+ };
1909
+ }
1910
+ }
1911
+ ],
1912
+ renderRules: [
1913
+ {
1914
+ type: "alert",
1915
+ render: (token) => {
1916
+ var _a, _b;
1917
+ const type = ((_a = token.attributes) == null ? void 0 : _a.type) || "info";
1918
+ const title = ((_b = token.attributes) == null ? void 0 : _b.title) || "";
1919
+ const typeConfig = {
1920
+ info: {
1921
+ icon: "\u2139\uFE0F",
1922
+ classes: "bg-blue-500/10 border-blue-500/30 text-blue-600 border-l-blue-500"
1923
+ },
1924
+ warning: {
1925
+ icon: "\u26A0\uFE0F",
1926
+ classes: "bg-amber-500/10 border-amber-500/30 text-amber-600 border-l-amber-500"
1927
+ },
1928
+ error: {
1929
+ icon: "\u274C",
1930
+ classes: "bg-red-500/10 border-red-500/30 text-red-600 border-l-red-500"
1931
+ },
1932
+ success: {
1933
+ icon: "\u2705",
1934
+ classes: "bg-green-500/10 border-green-500/30 text-green-600 border-l-green-500"
1935
+ },
1936
+ tip: {
1937
+ icon: "\u{1F4A1}",
1938
+ classes: "bg-purple-500/10 border-purple-500/30 text-purple-600 border-l-purple-500"
1939
+ },
1940
+ note: {
1941
+ icon: "\u{1F4DD}",
1942
+ classes: "bg-gray-500/10 border-gray-500/30 text-gray-600 border-l-gray-500"
1943
+ }
1944
+ };
1945
+ const config = typeConfig[type] || typeConfig.info;
1946
+ const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
1947
+ const classes = `${baseClasses} ${config == null ? void 0 : config.classes}`;
1948
+ const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
1949
+ <span class="text-lg" role="img" aria-label="${type}">${config == null ? void 0 : config.icon}</span>
1950
+ <span>${title}</span>
1951
+ </div>` : `<div class="font-medium mb-2 flex items-center gap-2">
1952
+ <span class="text-lg" role="img" aria-label="${type}">${config == null ? void 0 : config.icon}</span>
1953
+ <span>${type.charAt(0).toUpperCase() + type.slice(1)}</span>
1954
+ </div>`;
1955
+ return `<div class="${classes}" role="alert" aria-live="polite">
1956
+ ${titleHtml}
1957
+ <div class="leading-relaxed">${token.content}</div>
1958
+ </div>`;
1959
+ }
1960
+ }
1961
+ ]
1962
+ };
1963
+
1964
+ // src/extensions/button.ts
1965
+ var ButtonExtension = {
1966
+ name: "button",
1967
+ parseRules: [
1968
+ {
1969
+ name: "button",
1970
+ pattern: /\[button:([^\]]+)\]\(([^)]+)\)(?:\{([^}]+)\})?/,
1971
+ render: (match) => {
1972
+ const text2 = match[1] || "";
1973
+ const href = match[2] || "";
1974
+ const optionsString = match[3] || "";
1975
+ const options = optionsString.split(",").map((opt) => opt.trim()).filter(Boolean);
1976
+ const styleOptions = ["default", "primary", "secondary", "success", "danger", "outline", "ghost"];
1977
+ const style = options.find((opt) => styleOptions.includes(opt)) || "primary";
1978
+ const sizeOptions = ["sm", "md", "lg"];
1979
+ const size = options.find((opt) => sizeOptions.includes(opt)) || "md";
1980
+ const disabled = options.includes("disabled");
1981
+ const target = options.includes("self") ? "_self" : "_blank";
1982
+ return {
1983
+ type: "button",
1984
+ content: text2,
1985
+ raw: match[0] || "",
1986
+ attributes: {
1987
+ href,
1988
+ style,
1989
+ size,
1990
+ disabled: disabled.toString(),
1991
+ target
1992
+ }
1993
+ };
1994
+ }
1995
+ }
1996
+ ],
1997
+ renderRules: [
1998
+ {
1999
+ type: "button",
2000
+ render: (token) => {
2001
+ var _a, _b, _c, _d, _e;
2002
+ const href = ((_a = token.attributes) == null ? void 0 : _a.href) || "#";
2003
+ const style = ((_b = token.attributes) == null ? void 0 : _b.style) || "primary";
2004
+ const size = ((_c = token.attributes) == null ? void 0 : _c.size) || "md";
2005
+ const disabled = ((_d = token.attributes) == null ? void 0 : _d.disabled) === "true";
2006
+ const target = ((_e = token.attributes) == null ? void 0 : _e.target) || "_blank";
2007
+ const text2 = token.content;
2008
+ const classes = buildButtonClasses(style, size);
2009
+ const targetAttr = target === "_blank" ? ' target="_blank" rel="noopener noreferrer"' : target === "_self" ? ' target="_self"' : "";
2010
+ const disabledAttr = disabled ? ' aria-disabled="true" tabindex="-1"' : "";
2011
+ const externalIcon = target === "_blank" && !disabled ? '<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/></svg>' : "";
2012
+ return `<a href="${href}" class="${classes}"${targetAttr}${disabledAttr}>
2013
+ ${text2}${externalIcon}
2014
+ </a>`;
2015
+ }
2016
+ }
2017
+ ]
2018
+ };
2019
+ function buildButtonClasses(style, size) {
2020
+ var _a, _b, _c, _d;
2021
+ const base = [
2022
+ "inline-flex",
2023
+ "items-center",
2024
+ "justify-center",
2025
+ "font-medium",
2026
+ "rounded-lg",
2027
+ "transition-colors",
2028
+ "focus:outline-none",
2029
+ "focus:ring-2",
2030
+ "focus:ring-offset-2",
2031
+ "disabled:opacity-50",
2032
+ "disabled:cursor-not-allowed"
2033
+ ];
2034
+ const sizes = {
2035
+ sm: ["px-3", "py-1.5", "text-sm"],
2036
+ md: ["px-4", "py-2", "text-base"],
2037
+ lg: ["px-6", "py-3", "text-lg"]
2038
+ };
2039
+ const styles = {
2040
+ default: ["bg-slate-600", "text-white", "hover:bg-slate-700", "focus:ring-slate-500"],
2041
+ primary: ["bg-blue-600", "text-white", "hover:bg-blue-700", "focus:ring-blue-500"],
2042
+ secondary: ["bg-gray-600", "text-white", "hover:bg-gray-700", "focus:ring-gray-500"],
2043
+ success: ["bg-green-600", "text-white", "hover:bg-green-700", "focus:ring-green-500"],
2044
+ danger: ["bg-red-600", "text-white", "hover:bg-red-700", "focus:ring-red-500"],
2045
+ outline: ["border", "border-blue-600", "text-blue-600", "hover:bg-blue-50", "focus:ring-blue-500"],
2046
+ ghost: ["text-gray-700", "hover:bg-gray-100", "focus:ring-gray-500"]
2047
+ };
2048
+ const allClasses = [
2049
+ ...base,
2050
+ ...(_b = (_a = sizes[size]) != null ? _a : sizes.md) != null ? _b : [],
2051
+ ...(_d = (_c = styles[style]) != null ? _c : styles.primary) != null ? _d : []
2052
+ ];
2053
+ return allClasses.join(" ");
2054
+ }
2055
+
2056
+ // src/extensions/embed.ts
2057
+ var EmbedExtension = {
2058
+ name: "embed",
2059
+ parseRules: [
2060
+ {
2061
+ name: "embed",
2062
+ pattern: /\[embed:(\w+)\]\(([^)]+)\)(?:\{([^}]+)\})?/,
2063
+ render: (match) => {
2064
+ return {
2065
+ type: "embed",
2066
+ content: match[2] || "",
2067
+ // URL
2068
+ raw: match[0] || "",
2069
+ attributes: {
2070
+ provider: match[1] || "generic",
2071
+ url: match[2] || "",
2072
+ options: match[3] || ""
2073
+ }
2074
+ };
2075
+ }
2076
+ }
2077
+ ],
2078
+ renderRules: [
2079
+ {
2080
+ type: "embed",
2081
+ render: (token) => {
2082
+ var _a, _b, _c;
2083
+ const provider = ((_a = token.attributes) == null ? void 0 : _a.provider) || "generic";
2084
+ const url = ((_b = token.attributes) == null ? void 0 : _b.url) || "";
2085
+ const options = ((_c = token.attributes) == null ? void 0 : _c.options) || "";
2086
+ return renderEmbed(provider, url, options);
2087
+ }
2088
+ }
2089
+ ]
2090
+ };
2091
+ function renderEmbed(provider, url, options) {
2092
+ const baseClasses = "rounded-lg border bg-card text-card-foreground shadow-sm mb-6 overflow-hidden";
2093
+ const parsedOptions = parseOptions(options);
2094
+ switch (provider.toLowerCase()) {
2095
+ case "youtube":
2096
+ return renderYouTubeEmbed(url, parsedOptions, baseClasses);
2097
+ case "codepen":
2098
+ return renderCodePenEmbed(url, parsedOptions, baseClasses);
2099
+ case "figma":
2100
+ return renderFigmaEmbed(url, parsedOptions, baseClasses);
2101
+ case "twitter":
2102
+ case "tweet":
2103
+ return renderTwitterEmbed(url, parsedOptions, baseClasses);
2104
+ case "github":
2105
+ return renderGitHubEmbed(url, parsedOptions, baseClasses);
2106
+ case "vimeo":
2107
+ return renderVimeoEmbed(url, parsedOptions, baseClasses);
2108
+ case "spotify":
2109
+ return renderSpotifyEmbed(url, parsedOptions, baseClasses);
2110
+ case "codesandbox":
2111
+ return renderCodeSandboxEmbed(url, parsedOptions, baseClasses);
2112
+ default:
2113
+ return renderGenericEmbed(url, parsedOptions, baseClasses);
2114
+ }
2115
+ }
2116
+ function renderYouTubeEmbed(url, options, classes) {
2117
+ const videoId = extractYouTubeId(url);
2118
+ if (!videoId) {
2119
+ return createErrorEmbed("Invalid YouTube URL", url, classes);
2120
+ }
2121
+ const params = new URLSearchParams();
2122
+ if (options.autoplay === "1") params.set("autoplay", "1");
2123
+ if (options.mute === "1") params.set("mute", "1");
2124
+ if (options.loop === "1") {
2125
+ params.set("loop", "1");
2126
+ params.set("playlist", videoId);
2127
+ }
2128
+ if (options.controls === "0") params.set("controls", "0");
2129
+ if (options.start) params.set("start", options.start);
2130
+ params.set("rel", "0");
2131
+ params.set("modestbranding", "1");
2132
+ const embedUrl = `https://www.youtube.com/embed/${videoId}?${params.toString()}`;
2133
+ return `
2134
+ <div class="${classes}">
2135
+ <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
2136
+ <iframe
2137
+ style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;"
2138
+ src="${embedUrl}"
2139
+ title="YouTube video player"
2140
+ frameborder="0"
2141
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
2142
+ allowfullscreen>
2143
+ </iframe>
2144
+ </div>
2145
+ </div>`;
2146
+ }
2147
+ function renderCodePenEmbed(url, options, classes) {
2148
+ const match = url.match(/codepen\.io\/([^\/]+)\/(?:pen|embed)\/([^\/\?#]+)/);
2149
+ if (!match) {
2150
+ return createErrorEmbed("Invalid CodePen URL", url, classes);
2151
+ }
2152
+ const [, user, penId] = match;
2153
+ const height = options.height || "400";
2154
+ const theme = options.theme === "light" ? "light" : "dark";
2155
+ const defaultTab = options.tab || "result";
2156
+ const embedParams = new URLSearchParams({
2157
+ "default-tab": defaultTab,
2158
+ "theme-id": theme,
2159
+ "editable": "true"
2160
+ });
2161
+ const embedUrl = `https://codepen.io/${user}/embed/${penId}?${embedParams.toString()}`;
2162
+ return `
2163
+ <div class="${classes}">
2164
+ <iframe
2165
+ height="${height}"
2166
+ style="width: 100%; border: 0;"
2167
+ scrolling="no"
2168
+ title="CodePen Embed - ${penId}"
2169
+ src="${embedUrl}"
2170
+ frameborder="0"
2171
+ loading="lazy"
2172
+ allowtransparency="true"
2173
+ allowfullscreen="true">
2174
+ </iframe>
2175
+ </div>`;
2176
+ }
2177
+ function renderVimeoEmbed(url, options, classes) {
2178
+ const videoId = extractVimeoId(url);
2179
+ if (!videoId) {
2180
+ return createErrorEmbed("Invalid Vimeo URL", url, classes);
2181
+ }
2182
+ const params = new URLSearchParams();
2183
+ if (options.autoplay === "1") params.set("autoplay", "1");
2184
+ if (options.mute === "1") params.set("muted", "1");
2185
+ if (options.loop === "1") params.set("loop", "1");
2186
+ const embedUrl = `https://player.vimeo.com/video/${videoId}?${params.toString()}`;
2187
+ return `
2188
+ <div class="${classes}">
2189
+ <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
2190
+ <iframe
2191
+ style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;"
2192
+ src="${embedUrl}"
2193
+ title="Vimeo video player"
2194
+ frameborder="0"
2195
+ allow="autoplay; fullscreen; picture-in-picture"
2196
+ allowfullscreen>
2197
+ </iframe>
2198
+ </div>
2199
+ </div>`;
2200
+ }
2201
+ function renderSpotifyEmbed(url, options, classes) {
2202
+ const embedUrl = url.replace("open.spotify.com", "open.spotify.com/embed");
2203
+ const height = options.height || "380";
2204
+ return `
2205
+ <div class="${classes}">
2206
+ <iframe
2207
+ style="border-radius: 12px;"
2208
+ src="${embedUrl}"
2209
+ width="100%"
2210
+ height="${height}"
2211
+ frameborder="0"
2212
+ allowfullscreen=""
2213
+ allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
2214
+ loading="lazy">
2215
+ </iframe>
2216
+ </div>`;
2217
+ }
2218
+ function renderCodeSandboxEmbed(url, options, classes) {
2219
+ let embedUrl = url;
2220
+ if (url.includes("/s/")) {
2221
+ embedUrl = url.replace("/s/", "/embed/");
2222
+ }
2223
+ const height = options.height || "500";
2224
+ const view = options.view || "preview";
2225
+ if (!embedUrl.includes("?")) {
2226
+ embedUrl += `?view=${view}`;
2227
+ }
2228
+ return `
2229
+ <div class="${classes}">
2230
+ <iframe
2231
+ src="${embedUrl}"
2232
+ style="width: 100%; height: ${height}px; border: 0; border-radius: 4px; overflow: hidden;"
2233
+ title="CodeSandbox Embed"
2234
+ allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
2235
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts">
2236
+ </iframe>
2237
+ </div>`;
2238
+ }
2239
+ function renderFigmaEmbed(url, options, classes) {
2240
+ const embedUrl = `https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(url)}`;
2241
+ const height = options.height || "450";
2242
+ return `
2243
+ <div class="${classes}">
2244
+ <iframe
2245
+ style="border: none;"
2246
+ width="100%"
2247
+ height="${height}"
2248
+ src="${embedUrl}"
2249
+ allowfullscreen>
2250
+ </iframe>
2251
+ </div>`;
2252
+ }
2253
+ function renderTwitterEmbed(url, _options, classes) {
2254
+ return `
2255
+ <div class="${classes}">
2256
+ <div class="p-4">
2257
+ <div class="flex items-center gap-3 mb-3">
2258
+ <svg class="w-6 h-6 fill-current text-blue-500" viewBox="0 0 24 24">
2259
+ <path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/>
2260
+ </svg>
2261
+ <div>
2262
+ <div class="font-semibold text-foreground">Twitter Post</div>
2263
+ <div class="text-sm text-muted-foreground">External Link</div>
2264
+ </div>
2265
+ </div>
2266
+ <a href="${url}" target="_blank"
2267
+ class="inline-flex items-center gap-2 text-primary hover:text-primary/80 font-medium transition-colors">
2268
+ View on Twitter
2269
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2270
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/>
2271
+ </svg>
2272
+ </a>
2273
+ </div>
2274
+ </div>`;
2275
+ }
2276
+ function renderGitHubEmbed(url, _options, classes) {
2277
+ const parts = url.replace("https://github.com/", "").split("/");
2278
+ const owner = parts[0];
2279
+ const repo = parts[1];
2280
+ if (!owner || !repo) {
2281
+ return createErrorEmbed("Invalid GitHub URL", url, classes);
2282
+ }
2283
+ return `
2284
+ <div class="${classes}">
2285
+ <div class="p-4">
2286
+ <div class="flex items-center gap-3 mb-3">
2287
+ <svg class="w-6 h-6 fill-current" viewBox="0 0 24 24">
2288
+ <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
2289
+ </svg>
2290
+ <div>
2291
+ <div class="font-semibold text-foreground text-lg">${owner}/${repo}</div>
2292
+ <div class="text-sm text-muted-foreground">GitHub Repository</div>
2293
+ </div>
2294
+ </div>
2295
+ <a href="${url}" target="_blank"
2296
+ class="inline-flex items-center gap-2 text-primary hover:text-primary/80 font-medium transition-colors">
2297
+ View on GitHub
2298
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2299
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/>
2300
+ </svg>
2301
+ </a>
2302
+ </div>
2303
+ </div>`;
2304
+ }
2305
+ function renderGenericEmbed(url, _options, classes) {
2306
+ const domain = extractDomain(url);
2307
+ return `
2308
+ <div class="${classes}">
2309
+ <div class="p-4">
2310
+ <div class="flex items-center gap-3 mb-3">
2311
+ <div class="w-10 h-10 rounded-lg bg-muted flex items-center justify-center">
2312
+ <svg class="w-5 h-5 text-muted-foreground" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2313
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"/>
2314
+ </svg>
2315
+ </div>
2316
+ <div>
2317
+ <div class="font-semibold text-foreground">External Link</div>
2318
+ <div class="text-sm text-muted-foreground">${domain}</div>
2319
+ </div>
2320
+ </div>
2321
+ <a href="${url}" target="_blank"
2322
+ class="inline-flex items-center gap-2 text-primary hover:text-primary/80 font-medium transition-colors break-all">
2323
+ ${url}
2324
+ <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2325
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/>
2326
+ </svg>
2327
+ </a>
2328
+ </div>
2329
+ </div>`;
2330
+ }
2331
+ function createErrorEmbed(error, url, classes) {
2332
+ return `
2333
+ <div class="${classes}">
2334
+ <div class="p-4 text-destructive">
2335
+ <div class="font-medium flex items-center gap-2">
2336
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2337
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
2338
+ </svg>
2339
+ ${error}
2340
+ </div>
2341
+ <div class="text-sm text-muted-foreground mt-1 break-all">${url}</div>
2342
+ </div>
2343
+ </div>`;
2344
+ }
2345
+ function extractYouTubeId(url) {
2346
+ const patterns = [
2347
+ /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/shorts\/)([^&\n?#]+)/,
2348
+ /youtube\.com\/watch\?.*v=([^&\n?#]+)/
2349
+ ];
2350
+ for (const pattern of patterns) {
2351
+ const match = url.match(pattern);
2352
+ if (match) return match[1] || null;
2353
+ }
2354
+ return null;
2355
+ }
2356
+ function extractVimeoId(url) {
2357
+ var _a;
2358
+ const match = url.match(/vimeo\.com\/(?:.*\/)?(\d+)/);
2359
+ return (_a = match == null ? void 0 : match[1]) != null ? _a : null;
2360
+ }
2361
+
2362
+ // src/engine.ts
2363
+ var ChangerawrMarkdown = class {
2364
+ constructor(config) {
2365
+ this.extensions = /* @__PURE__ */ new Map();
2366
+ this.parser = new MarkdownParser(config == null ? void 0 : config.parser);
2367
+ this.renderer = new MarkdownRenderer(config == null ? void 0 : config.renderer);
2368
+ this.registerBuiltInExtensions();
2369
+ if (config == null ? void 0 : config.extensions) {
2370
+ config.extensions.forEach((extension) => {
2371
+ this.registerExtension(extension);
2372
+ });
2373
+ }
2374
+ this.parser.setupDefaultRulesIfEmpty();
2375
+ }
2376
+ /**
2377
+ * Register a custom extension
2378
+ */
2379
+ registerExtension(extension) {
2380
+ try {
2381
+ this.extensions.set(extension.name, extension);
2382
+ extension.parseRules.forEach((rule) => {
2383
+ this.parser.addRule(rule);
2384
+ });
2385
+ extension.renderRules.forEach((rule) => {
2386
+ this.renderer.addRule(rule);
2387
+ });
2388
+ return {
2389
+ success: true,
2390
+ extensionName: extension.name
2391
+ };
2392
+ } catch (error) {
2393
+ const errorMessage = error instanceof Error ? error.message : String(error);
2394
+ return {
2395
+ success: false,
2396
+ extensionName: extension.name,
2397
+ error: errorMessage
2398
+ };
2399
+ }
2400
+ }
2401
+ /**
2402
+ * Unregister an extension
2403
+ */
2404
+ unregisterExtension(name) {
2405
+ const extension = this.extensions.get(name);
2406
+ if (!extension) {
2407
+ return false;
2408
+ }
2409
+ try {
2410
+ this.extensions.delete(name);
2411
+ this.rebuildParserAndRenderer();
2412
+ return true;
2413
+ } catch (e) {
2414
+ return false;
2415
+ }
2416
+ }
2417
+ /**
2418
+ * Parse markdown content into tokens
2419
+ */
2420
+ parse(markdown2) {
2421
+ return this.parser.parse(markdown2);
2422
+ }
2423
+ /**
2424
+ * Render tokens to HTML
2425
+ */
2426
+ render(tokens) {
2427
+ return this.renderer.render(tokens);
2428
+ }
2429
+ /**
2430
+ * Parse and render markdown to HTML in one step
2431
+ */
2432
+ toHtml(markdown2) {
2433
+ const tokens = this.parse(markdown2);
2434
+ return this.render(tokens);
2435
+ }
2436
+ /**
2437
+ * Get list of registered extensions
2438
+ */
2439
+ getExtensions() {
2440
+ return Array.from(this.extensions.keys());
2441
+ }
2442
+ /**
2443
+ * Check if extension is registered
2444
+ */
2445
+ hasExtension(name) {
2446
+ return this.extensions.has(name);
2447
+ }
2448
+ /**
2449
+ * Get parser warnings
2450
+ */
2451
+ getWarnings() {
2452
+ return [...this.parser.getWarnings(), ...this.renderer.getWarnings()];
2453
+ }
2454
+ /**
2455
+ * Get debug information from last render
2456
+ */
2457
+ getDebugInfo() {
2458
+ return {
2459
+ warnings: this.getWarnings(),
2460
+ parseTime: 0,
2461
+ renderTime: 0,
2462
+ tokenCount: 0,
2463
+ iterationCount: 0
2464
+ };
2465
+ }
2466
+ /**
2467
+ * Get performance metrics for the last operation
2468
+ */
2469
+ getPerformanceMetrics() {
2470
+ return {
2471
+ parseTime: 0,
2472
+ renderTime: 0,
2473
+ totalTime: 0,
2474
+ tokenCount: 0
2475
+ };
2476
+ }
2477
+ /**
2478
+ * Register built-in extensions
2479
+ */
2480
+ registerBuiltInExtensions() {
2481
+ this.registerExtension(AlertExtension);
2482
+ this.registerExtension(ButtonExtension);
2483
+ this.registerExtension(EmbedExtension);
2484
+ }
2485
+ /**
2486
+ * Rebuild parser and renderer with current extensions
2487
+ */
2488
+ rebuildParserAndRenderer() {
2489
+ const parserConfig = this.parser.getConfig();
2490
+ const rendererConfig = this.renderer.getConfig();
2491
+ this.parser = new MarkdownParser(parserConfig);
2492
+ this.renderer = new MarkdownRenderer(rendererConfig);
2493
+ const extensionsToRegister = Array.from(this.extensions.values());
2494
+ this.extensions.clear();
2495
+ extensionsToRegister.forEach((extension) => {
2496
+ this.registerExtension(extension);
2497
+ });
2498
+ this.parser.setupDefaultRulesIfEmpty();
2499
+ }
2500
+ };
2501
+ var markdown = new ChangerawrMarkdown();
2502
+
2503
+ // src/standalone.ts
2504
+ function renderCum(markdown2, config) {
2505
+ const engine = new ChangerawrMarkdown(config);
2506
+ return engine.toHtml(markdown2);
2507
+ }
2508
+ function parseCum(markdown2, config) {
2509
+ const engine = new ChangerawrMarkdown(config);
2510
+ return engine.parse(markdown2);
2511
+ }
2512
+ function createCumEngine(config) {
2513
+ return new ChangerawrMarkdown(config);
2514
+ }
2515
+ function renderCumToHtml(markdown2) {
2516
+ return renderCum(markdown2, {
2517
+ renderer: { format: "html" }
2518
+ });
2519
+ }
2520
+ function renderCumToTailwind(markdown2) {
2521
+ return renderCum(markdown2, {
2522
+ renderer: { format: "tailwind" }
2523
+ });
2524
+ }
2525
+ function renderCumToJson(markdown2) {
2526
+ return parseCum(markdown2);
2527
+ }
2528
+ var standalone_default = {
2529
+ renderCum,
2530
+ parseCum,
2531
+ createCumEngine,
2532
+ renderCumToHtml,
2533
+ renderCumToTailwind,
2534
+ renderCumToJson,
2535
+ // Legacy aliases
2536
+ render: renderCum,
2537
+ parse: parseCum,
2538
+ // Include the main class
2539
+ ChangerawrMarkdown
2540
+ };
2541
+ return __toCommonJS(standalone_exports);
2542
+ })();
2543
+ /*! Bundled license information:
2544
+
2545
+ dompurify/dist/purify.es.mjs:
2546
+ (*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE *)
2547
+ */