summaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/application-legacy.js (renamed from app/assets/javascripts/application.js)131
-rw-r--r--app/assets/javascripts/attachments.js14
-rw-r--r--app/assets/javascripts/quote_reply.js44
-rw-r--r--app/assets/javascripts/turndown-7.2.0.min.js8
4 files changed, 136 insertions, 61 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application-legacy.js
index 19578bee8..1219e1ef8 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application-legacy.js
@@ -43,10 +43,18 @@ function toggleRowGroup(el) {
}
function toggleExpendCollapseIcon(el) {
+ const svg = el.getElementsByTagName('svg').item(0)
+
+ if (svg === null) {
+ return false;
+ }
+
if (el.classList.contains('icon-expanded')) {
- updateSVGIcon(el, 'angle-down')
+ updateSVGIcon(svg, 'angle-down')
+ svg.classList.remove('icon-rtl')
} else {
- updateSVGIcon(el, 'angle-right')
+ updateSVGIcon(svg, 'angle-right')
+ svg.classList.add('icon-rtl')
}
}
@@ -61,13 +69,20 @@ function updateSVGIcon(element, icon) {
iconElement.setAttribute('href', iconPath.replace(/#.*$/g, "#icon--" + icon))
}
+function createSVGIcon(icon) {
+ const clonedIcon = document.querySelector('#icon-copy-source svg').cloneNode(true);
+ updateSVGIcon(clonedIcon, icon);
+ return clonedIcon
+}
+
function collapseAllRowGroups(el) {
var tbody = $(el).parents('tbody').first();
tbody.children('tr').each(function(index) {
if ($(this).hasClass('group')) {
$(this).removeClass('open');
- $(this).find('.expander').switchClass('icon-expanded', 'icon-collapsed');
- updateSVGIcon($(this).find('.expander')[0], 'angle-right')
+ var expander = $(this).find('.expander');
+ expander.switchClass('icon-expanded', 'icon-collapsed');
+ toggleExpendCollapseIcon(expander[0]);
} else {
$(this).hide();
}
@@ -79,8 +94,9 @@ function expandAllRowGroups(el) {
tbody.children('tr').each(function(index) {
if ($(this).hasClass('group')) {
$(this).addClass('open');
- $(this).find('.expander').switchClass('icon-collapsed', 'icon-expanded');
- updateSVGIcon($(this).find('.expander')[0], 'angle-down')
+ var expander = $(this).find('.expander');
+ expander.switchClass('icon-collapsed', 'icon-expanded');
+ toggleExpendCollapseIcon(expander[0]);
} else {
$(this).show();
}
@@ -212,8 +228,7 @@ function buildFilterRow(field, operator, values) {
case "list_status":
case "list_subprojects":
const iconType = values.length > 1 ? 'toggle-minus' : 'toggle-plus';
- const clonedIcon = document.querySelector('#icon-copy-source svg').cloneNode(true);
- updateSVGIcon(clonedIcon, iconType);
+ const iconSvg = createSVGIcon(iconType)
tr.find('.values').append(
$('<span>', { style: 'display:none;' }).append(
@@ -223,7 +238,7 @@ function buildFilterRow(field, operator, values) {
name: `v[${field}][]`,
}),
'\n',
- $('<span>', { class: `toggle-multiselect icon-only icon-${iconType}` }).append(clonedIcon)
+ $('<span>', { class: `toggle-multiselect icon-only icon-${iconType}` }).append(iconSvg)
)
);
select = tr.find('.values select');
@@ -411,7 +426,7 @@ function showIssueHistory(journal, url) {
tab_content.find('.journal').show();
tab_content.find('.journal:not(.has-notes)').hide();
tab_content.find('.journal .wiki').show();
- tab_content.find('.journal .contextual .journal-actions').show();
+ tab_content.find('.journal .journal-actions > *').show();
// always show thumbnails in notes tab
var thumbnails = tab_content.find('.journal .thumbnails');
@@ -424,13 +439,15 @@ function showIssueHistory(journal, url) {
tab_content.find('.journal:not(.has-details)').hide();
tab_content.find('.journal .wiki').hide();
tab_content.find('.journal .thumbnails').hide();
- tab_content.find('.journal .contextual .journal-actions').hide();
+ tab_content.find('.journal .journal-actions > *').hide();
+ // Show reaction button in properties tab
+ tab_content.find('.journal .journal-actions .reaction-button-wrapper').show();
break;
default:
tab_content.find('.journal').show();
tab_content.find('.journal .wiki').show();
tab_content.find('.journal .thumbnails').show();
- tab_content.find('.journal .contextual .journal-actions').show();
+ tab_content.find('.journal .journal-actions > *').show();
}
return false;
@@ -586,19 +603,23 @@ function expandScmEntry(id) {
function scmEntryClick(id, url) {
var el = $('#'+id);
+ var expander = el.find('.expander');
+ var folder = el.find('.icon-folder');
if (el.hasClass('open')) {
collapseScmEntry(id);
el.find('.expander').switchClass('icon-expanded', 'icon-collapsed');
el.addClass('collapsed');
- updateSVGIcon(el.find('.icon-folder')[0], 'folder')
+ updateSVGIcon(folder[0], 'folder')
+ toggleExpendCollapseIcon(expander[0]);
return false;
} else if (el.hasClass('loaded')) {
expandScmEntry(id);
el.find('.expander').switchClass('icon-collapsed', 'icon-expanded');
el.removeClass('collapsed');
- updateSVGIcon(el.find('.icon-folder-open')[0], 'folder-open')
+ updateSVGIcon(folder[0], 'folder-open')
+ toggleExpendCollapseIcon(expander[0]);
return false;
}
@@ -611,8 +632,9 @@ function scmEntryClick(id, url) {
success: function(data) {
el.after(data);
el.addClass('open').addClass('loaded').removeClass('loading');
- updateSVGIcon(el.find('.icon-folder')[0], 'folder-open')
el.find('.expander').switchClass('icon-collapsed', 'icon-expanded');
+ updateSVGIcon(folder[0], 'folder-open')
+ toggleExpendCollapseIcon(expander[0]);
}
});
return true;
@@ -627,23 +649,65 @@ function randomKey(size) {
return key;
}
-function copyTextToClipboard(target) {
- if (target) {
- var temp = document.createElement('textarea');
- temp.value = target.getAttribute('data-clipboard-text');
- document.body.appendChild(temp);
- temp.select();
- document.execCommand('copy');
- if (temp.parentNode) {
- temp.parentNode.removeChild(temp);
- }
- if ($(target).closest('.drdn.expanded').length) {
- $(target).closest('.drdn.expanded').removeClass("expanded");
- }
+function copyToClipboard(text) {
+ if (navigator.clipboard) {
+ return navigator.clipboard.writeText(text).catch(() => {
+ return fallbackClipboardCopy(text);
+ });
+ } else {
+ return fallbackClipboardCopy(text);
+ }
+}
+
+function fallbackClipboardCopy(text) {
+ const temp = document.createElement('textarea');
+ temp.value = text;
+ temp.style.position = 'fixed';
+ temp.style.left = '-9999px';
+ document.body.appendChild(temp);
+ temp.select();
+ document.execCommand('copy');
+ document.body.removeChild(temp);
+ return Promise.resolve();
+}
+
+function copyDataClipboardTextToClipboard(target) {
+ copyToClipboard(target.getAttribute('data-clipboard-text'));
+
+ if ($(target).closest('.drdn.expanded').length) {
+ $(target).closest('.drdn.expanded').removeClass("expanded");
}
return false;
}
+function setupCopyButtonsToPreElements() {
+ document.querySelectorAll('.wiki pre:not(.pre-wrapper pre)').forEach((pre) => {
+ // Wrap the <pre> element with a container and add a copy button
+ const wrapper = document.createElement("div");
+ wrapper.classList.add("pre-wrapper");
+
+ const copyButton = document.createElement("a");
+ copyButton.title = rm.I18n.buttonCopy;
+ copyButton.classList.add("copy-pre-content-link", "icon-only");
+ copyButton.append(createSVGIcon("copy-pre-content"));
+
+ wrapper.appendChild(copyButton);
+ wrapper.append(pre.cloneNode(true));
+ pre.replaceWith(wrapper);
+
+ // Copy the contents of the pre tag when copyButton is clicked
+ copyButton.addEventListener("click", (event) => {
+ event.preventDefault();
+ let textToCopy = (pre.querySelector("code") || pre).textContent.replace(/\n$/, '');
+ if (pre.querySelector("code.syntaxhl")) { textToCopy = textToCopy.replace(/ $/, ''); } // Workaround for half-width space issue in Textile's highlighted code
+ copyToClipboard(textToCopy).then(() => {
+ updateSVGIcon(copyButton, "checked");
+ setTimeout(() => updateSVGIcon(copyButton, "copy-pre-content"), 2000);
+ });
+ });
+ });
+}
+
function updateIssueFrom(url, el) {
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
$(this).data('valuebeforeupdate', $(this).val());
@@ -1160,8 +1224,8 @@ function setupWikiTableSortableHeader() {
});
}
-$(function () {
- $("[title]:not(.no-tooltip)").tooltip({
+function setupHoverTooltips(container) {
+ $(container || 'body').find("[title]:not(.no-tooltip)").tooltip({
show: {
delay: 400
},
@@ -1170,7 +1234,11 @@ $(function () {
at: "center top"
}
});
-});
+}
+function removeHoverTooltips(container) {
+ $(container || 'body').find("[title]:not(.no-tooltip)").tooltip('destroy')
+}
+$(function() { setupHoverTooltips(); });
function inlineAutoComplete(element) {
'use strict';
@@ -1364,3 +1432,4 @@ $(document).ready(setupWikiTableSortableHeader);
$(document).on('focus', '[data-auto-complete=true]', function(event) {
inlineAutoComplete(event.target);
});
+document.addEventListener("DOMContentLoaded", () => { setupCopyButtonsToPreElements(); });
diff --git a/app/assets/javascripts/attachments.js b/app/assets/javascripts/attachments.js
index df9c7090e..4c74b2d74 100644
--- a/app/assets/javascripts/attachments.js
+++ b/app/assets/javascripts/attachments.js
@@ -5,9 +5,13 @@
*/
function addFile(inputEl, file, eagerUpload) {
- var attachmentsFields = $(inputEl).closest('.attachments_form').find('.attachments_fields');
- var addAttachment = $(inputEl).closest('.attachments_form').find('.add_attachment');
+ var attachmentsForm = $(inputEl).closest('.attachments_form')
+ var attachmentsFields = attachmentsForm.find('.attachments_fields');
+ var attachmentsIcons = attachmentsForm.find('.attachments_icons');
+ var addAttachment = attachmentsForm.find('.add_attachment');
var maxFiles = ($(inputEl).attr('multiple') == 'multiple' ? 10 : 1);
+ var delIcon = attachmentsIcons.find('svg.svg-del').clone();
+ var attachmentIcon = attachmentsIcons.find('svg.svg-attachment').clone();
if (attachmentsFields.children().length < maxFiles) {
var attachmentId = addFile.nextAttachmentId++;
@@ -16,12 +20,14 @@ function addFile(inputEl, file, eagerUpload) {
if (!param) {param = 'attachments'};
fileSpan.append(
+ attachmentIcon,
$('<input>', { type: 'text', 'class': 'icon icon-attachment filename readonly', name: param +'[' + attachmentId + '][filename]', readonly: 'readonly'} ).val(file.name),
$('<input>', { type: 'text', 'class': 'description', name: param + '[' + attachmentId + '][description]', maxlength: 255, placeholder: $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload),
$('<input>', { type: 'hidden', 'class': 'token', name: param + '[' + attachmentId + '][token]'} ),
- $('<a>&nbsp</a>').attr({ href: "#", 'class': 'icon-only icon-del remove-upload' }).click(removeFile).toggle(!eagerUpload)
+ $('<a>', { href: "#", 'class': 'icon-only icon-del remove-upload' }).append(delIcon).click(removeFile).toggle(!eagerUpload)
).appendTo(attachmentsFields);
+
if ($(inputEl).data('description') == 0) {
fileSpan.find('input.description').remove();
}
@@ -63,7 +69,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
.done(function(result) {
addInlineAttachmentMarkup(file);
progressSpan.progressbar( 'value', 100 ).remove();
- fileSpan.find('input.description, a').css('display', 'inline-block');
+ fileSpan.find('input.description, a').css('display', 'inline-flex');
})
.fail(function(result) {
progressSpan.text(result.statusText);
diff --git a/app/assets/javascripts/quote_reply.js b/app/assets/javascripts/quote_reply.js
index 7649f5125..dd05d27fe 100644
--- a/app/assets/javascripts/quote_reply.js
+++ b/app/assets/javascripts/quote_reply.js
@@ -1,21 +1,6 @@
-function quoteReply(path, selectorForContentElement, textFormatting) {
- const contentElement = $(selectorForContentElement).get(0);
- const selectedRange = QuoteExtractor.extract(contentElement);
-
- let formatter;
-
- if (textFormatting === 'common_mark') {
- formatter = new QuoteCommonMarkFormatter();
- } else {
- formatter = new QuoteTextFormatter();
- }
-
- $.ajax({
- url: path,
- type: 'post',
- data: { quote: formatter.format(selectedRange) }
- });
-}
+import { Controller } from '@hotwired/stimulus'
+import TurndownService from 'turndown'
+import { post } from '@rails/request.js'
class QuoteExtractor {
static extract(targetElement) {
@@ -214,3 +199,26 @@ class QuoteCommonMarkFormatter {
return htmlFragment.innerHTML;
}
}
+
+export default class extends Controller {
+ static targets = [ 'content' ];
+
+ quote(event) {
+ const { url, textFormatting } = event.params;
+ const selectedRange = QuoteExtractor.extract(this.contentTarget);
+
+ let formatter;
+
+ if (textFormatting === 'common_mark') {
+ formatter = new QuoteCommonMarkFormatter();
+ } else {
+ formatter = new QuoteTextFormatter();
+ }
+
+ post(url, {
+ body: JSON.stringify({ quote: formatter.format(selectedRange) }),
+ contentType: 'application/json',
+ responseKind: 'script'
+ });
+ }
+}
diff --git a/app/assets/javascripts/turndown-7.2.0.min.js b/app/assets/javascripts/turndown-7.2.0.min.js
index f3fb4b1e6..e69de29bb 100644
--- a/app/assets/javascripts/turndown-7.2.0.min.js
+++ b/app/assets/javascripts/turndown-7.2.0.min.js
@@ -1,8 +0,0 @@
-/*
- * Turndown v7.2.0
- * https://github.com/mixmark-io/turndown
- * Copyright (c) 2017 Dom Christie
- * Released under the MIT license
- * https://github.com/mixmark-io/turndown/blob/master/LICENSE
- */
-var TurndownService=(()=>{function u(e,n){return Array(n+1).join(e)}var n=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function f(e){return o(e,n)}var r=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function d(e){return o(e,r)}var i=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function o(e,n){return 0<=n.indexOf(e.nodeName)}function a(n,e){return n.getElementsByTagName&&e.some(function(e){return n.getElementsByTagName(e).length})}var t={};function c(e){return e?e.replace(/(\n+\s*)+/g,"\n"):""}function l(e){for(var n in this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[],e.rules)this.array.push(e.rules[n])}function s(e,n,t){for(var r=0;r<e.length;r++){var i=e[r];if(((e,n,t)=>{var r=e.filter;if("string"==typeof r)return r===n.nodeName.toLowerCase();if(Array.isArray(r))return-1<r.indexOf(n.nodeName.toLowerCase());if("function"==typeof r)return!!r.call(e,n,t);throw new TypeError("`filter` needs to be a string, array, or function")})(i,n,t))return i}}function p(e){var n=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),n}function h(e,n,t){return e&&e.parentNode===n||t(n)?n.nextSibling||n.parentNode:n.firstChild||n.nextSibling||n.parentNode}t.paragraph={filter:"p",replacement:function(e){return"\n\n"+e+"\n\n"}},t.lineBreak={filter:"br",replacement:function(e,n,t){return t.br+"\n"}},t.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,n,t){n=Number(n.nodeName.charAt(1));return"setext"===t.headingStyle&&n<3?"\n\n"+e+"\n"+u(1===n?"=":"-",e.length)+"\n\n":"\n\n"+u("#",n)+" "+e+"\n\n"}},t.blockquote={filter:"blockquote",replacement:function(e){return"\n\n"+(e=(e=e.replace(/^\n+|\n+$/g,"")).replace(/^/gm,"> "))+"\n\n"}},t.list={filter:["ul","ol"],replacement:function(e,n){var t=n.parentNode;return"LI"===t.nodeName&&t.lastElementChild===n?"\n"+e:"\n\n"+e+"\n\n"}},t.listItem={filter:"li",replacement:function(e,n,t){e=e.replace(/^\n+/,"").replace(/\n+$/,"\n").replace(/\n/gm,"\n ");var r,t=t.bulletListMarker+" ",i=n.parentNode;return"OL"===i.nodeName&&(r=i.getAttribute("start"),i=Array.prototype.indexOf.call(i.children,n),t=(r?Number(r)+i:i+1)+". "),t+e+(n.nextSibling&&!/\n$/.test(e)?"\n":"")}},t.indentedCodeBlock={filter:function(e,n){return"indented"===n.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,n,t){return"\n\n "+n.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},t.fencedCodeBlock={filter:function(e,n){return"fenced"===n.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,n,t){for(var r,i=((n.firstChild.getAttribute("class")||"").match(/language-(\S+)/)||[null,""])[1],o=n.firstChild.textContent,n=t.fence.charAt(0),a=3,l=new RegExp("^"+n+"{3,}","gm");r=l.exec(o);)r[0].length>=a&&(a=r[0].length+1);t=u(n,a);return"\n\n"+t+i+"\n"+o.replace(/\n$/,"")+"\n"+t+"\n\n"}},t.horizontalRule={filter:"hr",replacement:function(e,n,t){return"\n\n"+t.hr+"\n\n"}},t.inlineLink={filter:function(e,n){return"inlined"===n.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,n){var t=(t=n.getAttribute("href"))&&t.replace(/([()])/g,"\\$1"),n=c(n.getAttribute("title"));return"["+e+"]("+t+(n=n&&' "'+n.replace(/"/g,'\\"')+'"')+")"}},t.referenceLink={filter:function(e,n){return"referenced"===n.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,n,t){var r=n.getAttribute("href"),i=(i=c(n.getAttribute("title")))&&' "'+i+'"';switch(t.linkReferenceStyle){case"collapsed":a="["+e+"][]",l="["+e+"]: "+r+i;break;case"shortcut":a="["+e+"]",l="["+e+"]: "+r+i;break;default:var o=this.references.length+1,a="["+e+"]["+o+"]",l="["+o+"]: "+r+i}return this.references.push(l),a},references:[],append:function(e){var n="";return this.references.length&&(n="\n\n"+this.references.join("\n")+"\n\n",this.references=[]),n}},t.emphasis={filter:["em","i"],replacement:function(e,n,t){return e.trim()?t.emDelimiter+e+t.emDelimiter:""}},t.strong={filter:["strong","b"],replacement:function(e,n,t){return e.trim()?t.strongDelimiter+e+t.strongDelimiter:""}},t.code={filter:function(e){var n=e.previousSibling||e.nextSibling,n="PRE"===e.parentNode.nodeName&&!n;return"CODE"===e.nodeName&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");for(var n=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",t="`",r=e.match(/`+/gm)||[];-1!==r.indexOf(t);)t+="`";return t+n+e+n+t}},t.image={filter:"img",replacement:function(e,n){var t=c(n.getAttribute("alt")),r=n.getAttribute("src")||"",n=c(n.getAttribute("title"));return r?"!["+t+"]("+r+(n?' "'+n+'"':"")+")":""}},l.prototype={add:function(e,n){this.array.unshift(n)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){return e.isBlank?this.blankRule:s(this.array,e,this.options)||s(this._keep,e,this.options)||s(this._remove,e,this.options)||this.defaultRule},forEach:function(e){for(var n=0;n<this.array.length;n++)e(this.array[n],n)}};var g,m="undefined"!=typeof window?window:{},A=(()=>{var e=m.DOMParser,n=!1;try{(new e).parseFromString("","text/html")&&(n=!0)}catch(e){}return n})()?m.DOMParser:((()=>{var n=!1;try{document.implementation.createHTMLDocument("").open()}catch(e){m.ActiveXObject&&(n=!0)}return n})()?e.prototype.parseFromString=function(e){var n=new window.ActiveXObject("htmlfile");return n.designMode="on",n.open(),n.write(e),n.close(),n}:e.prototype.parseFromString=function(e){var n=document.implementation.createHTMLDocument("");return n.open(),n.write(e),n.close(),n},e);function e(){}function y(e,n){var n={element:e="string"==typeof e?(g=g||new A).parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html").getElementById("turndown-root"):e.cloneNode(!0),isBlock:f,isVoid:d,isPre:n.preformattedCode?v:null},t=n.element,r=n.isBlock,i=n.isVoid,o=n.isPre||function(e){return"PRE"===e.nodeName};if(t.firstChild&&!o(t)){for(var a=null,l=!1,u=h(s=null,t,o);u!==t;){if(3===u.nodeType||4===u.nodeType){var c=u.data.replace(/[ \r\n\t]+/g," ");if(!(c=a&&!/ $/.test(a.data)||l||" "!==c[0]?c:c.substr(1))){u=p(u);continue}u.data=c,a=u}else{if(1!==u.nodeType){u=p(u);continue}r(u)||"BR"===u.nodeName?(a&&(a.data=a.data.replace(/ $/,"")),a=null,l=!1):i(u)||o(u)?l=!(a=null):a&&(l=!1)}var c=h(s,u,o),s=u,u=c}a&&(a.data=a.data.replace(/ $/,""),a.data||p(a))}return e}function v(e){return"PRE"===e.nodeName||"CODE"===e.nodeName}function N(e,n){var t;return e.isBlock=f(e),e.isCode="CODE"===e.nodeName||e.parentNode.isCode,e.isBlank=!d(t=e)&&!(e=>o(e,i))(t)&&/^\s*$/i.test(t.textContent)&&!(e=>a(e,r))(t)&&!(e=>a(e,i))(t),e.flankingWhitespace=((e,n)=>{var t;return e.isBlock||n.preformattedCode&&e.isCode?{leading:"",trailing:""}:((t=(e=>({leading:(e=e.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/))[1],leadingAscii:e[2],leadingNonAscii:e[3],trailing:e[4],trailingNonAscii:e[5],trailingAscii:e[6]}))(e.textContent)).leadingAscii&&E("left",e,n)&&(t.leading=t.leadingNonAscii),t.trailingAscii&&E("right",e,n)&&(t.trailing=t.trailingNonAscii),{leading:t.leading,trailing:t.trailing})})(e,n),e}function E(e,n,t){var r,i,e="left"===e?(r=n.previousSibling,/ $/):(r=n.nextSibling,/^ /);return r&&(3===r.nodeType?i=e.test(r.nodeValue):t.preformattedCode&&"CODE"===r.nodeName?i=!1:1!==r.nodeType||f(r)||(i=e.test(r.textContent))),i}var T=Array.prototype.reduce,R=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function C(e){if(!(this instanceof C))return new C(e);this.options=function(e){for(var n=1;n<arguments.length;n++){var t,r=arguments[n];for(t in r)r.hasOwnProperty(t)&&(e[t]=r[t])}return e}({},{rules:t,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(e,n){return n.isBlock?"\n\n":""},keepReplacement:function(e,n){return n.isBlock?"\n\n"+n.outerHTML+"\n\n":n.outerHTML},defaultReplacement:function(e,n){return n.isBlock?"\n\n"+e+"\n\n":e}},e),this.rules=new l(this.options)}function k(e){var r=this;return T.call(e.childNodes,function(e,n){var t="";return 3===(n=new N(n,r.options)).nodeType?t=n.isCode?n.nodeValue:r.escape(n.nodeValue):1===n.nodeType&&(t=function(e){var n=this.rules.forNode(e),t=k.call(this,e),r=e.flankingWhitespace;(r.leading||r.trailing)&&(t=t.trim());return r.leading+n.replacement(t,e,this.options)+r.trailing}.call(r,n)),b(e,t)},"")}function b(e,n){var t=(e=>{for(var n=e.length;0<n&&"\n"===e[n-1];)n--;return e.substring(0,n)})(e),r=n.replace(/^\n*/,""),e=Math.max(e.length-t.length,n.length-r.length);return t+"\n\n".substring(0,e)+r}return C.prototype={turndown:function(e){if(null==(n=e)||"string"!=typeof n&&(!n.nodeType||1!==n.nodeType&&9!==n.nodeType&&11!==n.nodeType))throw new TypeError(e+" is not a string, or an element/document/fragment node.");var n;return""===e?"":(n=k.call(this,new y(e,this.options)),function(n){var t=this;return this.rules.forEach(function(e){"function"==typeof e.append&&(n=b(n,e.append(t.options)))}),n.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}.call(this,n))},use:function(e){if(Array.isArray(e))for(var n=0;n<e.length;n++)this.use(e[n]);else{if("function"!=typeof e)throw new TypeError("plugin must be a Function or an Array of Functions");e(this)}return this},addRule:function(e,n){return this.rules.add(e,n),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return R.reduce(function(e,n){return e.replace(n[0],n[1])},e)}},C})();