turnish 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +16 -16
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +11 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +16 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +12 -2
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(b,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(b=typeof globalThis<"u"?globalThis:b||self,A(b.Turnish={}))})(this,(function(b){"use strict";class A extends Error{reason;filename;line;column;source;constructor(e,n,i,r,s){super(`${e}:${i}:${r}: ${n}`),this.reason=n,this.filename=e,this.line=i,this.column=r,this.source=s}}class se{start;end;source;constructor(e,n,i){this.start=e,this.end=n,this.source=i}}var h;(function(t){t.stylesheet="stylesheet",t.rule="rule",t.declaration="declaration",t.comment="comment",t.container="container",t.charset="charset",t.document="document",t.customMedia="custom-media",t.fontFace="font-face",t.host="host",t.import="import",t.keyframes="keyframes",t.keyframe="keyframe",t.layer="layer",t.media="media",t.namespace="namespace",t.page="page",t.startingStyle="starting-style",t.supports="supports"})(h||(h={}));const F=(t,e,n)=>{let i=n,r=1e4;do{const s=e.map(c=>t.indexOf(c,i));s.push(t.indexOf("\\",i));const l=s.filter(c=>c!==-1);if(l.length===0)return-1;const u=Math.min(...l);if(t[u]!=="\\")return u;i=u+2,r--}while(r>0);throw new Error("Too many escaping")},O=(t,e,n)=>{let i=n,r=1e4;do{const s=e.map(c=>t.indexOf(c,i));s.push(t.indexOf("(",i)),s.push(t.indexOf('"',i)),s.push(t.indexOf("'",i)),s.push(t.indexOf("\\",i));const l=s.filter(c=>c!==-1);if(l.length===0)return-1;const u=Math.min(...l);switch(t[u]){case"\\":i=u+2;break;case"(":{const c=O(t,[")"],u+1);if(c===-1)return-1;i=c+1}break;case'"':{const c=F(t,['"'],u+1);if(c===-1)return-1;i=c+1}break;case"'":{const c=F(t,["'"],u+1);if(c===-1)return-1;i=c+1}break;default:return u}r--}while(r>0);throw new Error("Too many escaping")},S=/\/\*[^]*?(?:\*\/|$)/g;function E(t){return t?t.trim():""}function M(t,e){const n=t&&typeof t.type=="string",i=n?t:e;for(const r in t){const s=t[r];Array.isArray(s)?s.forEach(l=>{M(l,i)}):s&&typeof s=="object"&&M(s,i)}return n&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:e||null}),t}class oe{level=0;indentation=" ";compress=!1;constructor(e){typeof e?.indent=="string"&&(this.indentation=e?.indent),e?.compress&&(this.compress=!0)}emit(e,n){return e}indent(e){return this.level=this.level||1,e?(this.level+=e,""):Array(this.level).join(this.indentation)}visit(e){switch(e.type){case h.stylesheet:return this.stylesheet(e);case h.rule:return this.rule(e);case h.declaration:return this.declaration(e);case h.comment:return this.comment(e);case h.container:return this.container(e);case h.charset:return this.charset(e);case h.document:return this.document(e);case h.customMedia:return this.customMedia(e);case h.fontFace:return this.fontFace(e);case h.host:return this.host(e);case h.import:return this.import(e);case h.keyframes:return this.keyframes(e);case h.keyframe:return this.keyframe(e);case h.layer:return this.layer(e);case h.media:return this.media(e);case h.namespace:return this.namespace(e);case h.page:return this.page(e);case h.startingStyle:return this.startingStyle(e);case h.supports:return this.supports(e)}}mapVisit(e,n){let i="";n=n||"";for(let r=0,s=e.length;r<s;r++)i+=this.visit(e[r]),n&&r<s-1&&(i+=this.emit(n));return i}compile(e){return this.compress?e.stylesheet.rules.map(this.visit,this).join(""):this.stylesheet(e)}stylesheet(e){return this.mapVisit(e.stylesheet.rules,`
|
|
2
2
|
|
|
3
3
|
`)}comment(e){return this.compress?this.emit("",e.position):this.emit(`${this.indent()}/*${e.comment}*/`,e.position)}container(e){return this.compress?this.emit(`@container ${e.container}`,e.position)+this.emit("{")+this.mapVisit(e.rules)+this.emit("}"):this.emit(`${this.indent()}@container ${e.container}`,e.position)+this.emit(` {
|
|
4
4
|
${this.indent(1)}`)+this.mapVisit(e.rules,`
|
|
@@ -46,22 +46,22 @@ ${this.indent(1)}`)+this.mapVisit(e.rules,`
|
|
|
46
46
|
`)+this.emit(this.indent(-1))+this.emit(`
|
|
47
47
|
${this.indent()}}`)}declaration(e){return this.compress?this.emit(`${e.property}:${e.value}`,e.position)+this.emit(";"):e.property==="grid-template-areas"?this.emit(this.indent())+this.emit(e.property+": "+e.value.split(`
|
|
48
48
|
`).join(`
|
|
49
|
-
`.padEnd(22)+this.indent()),e.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${e.property}: ${e.value}`,e.position)+this.emit(";")}}var
|
|
50
|
-
`);i=~y?f.length-y:i+f.length})(o),t=t.slice(o.length),a}function
|
|
51
|
-
`;)e--;return t.substring(0,e)}function z(t){return j(
|
|
52
|
-
`):""}function
|
|
49
|
+
`.padEnd(22)+this.indent()),e.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${e.property}: ${e.value}`,e.position)+this.emit(";")}}var ae={parse:(t,e)=>{e=e||{};let n=1,i=1;function r(){const a={line:n,column:i};return o=>(o.position=new se(a,{line:n,column:i},e?.source||""),T(),o)}const s=[];function l(a){const o=new A(e?.source||"",a,n,i,t);if(!e?.silent)throw o;s.push(o)}function u(){const a=/^{\s*/.exec(t);return!!a&&(m(a),!0)}function c(){const a=/^}/.exec(t);return!!a&&(m(a),!0)}function g(){let a;const o=[];for(T(),d(o);t.length&&t.charAt(0)!=="}"&&(a=Be()||Pe(),a);)o.push(a),d(o);return o}function m(a){const o=a[0];return(function(f){const p=f.match(/\n/g);p&&(n+=p.length);const y=f.lastIndexOf(`
|
|
50
|
+
`);i=~y?f.length-y:i+f.length})(o),t=t.slice(o.length),a}function T(){const a=/^\s*/.exec(t);a&&m(a)}function d(a){a=a||[];let o=R();for(;o;)a.push(o),o=R();return a}function R(){const a=r();if(t.charAt(0)!=="/"||t.charAt(1)!=="*")return;const o=/^\/\*[^]*?\*\//.exec(t);return o?(m(o),a({type:h.comment,comment:o[0].slice(2,-2)})):l("End of comment missing")}function te(){const a=/^([^{]+)/.exec(t);if(a)return m(a),((o,f)=>{const p=[];let y=0;for(;y<o.length;){const N=O(o,f,y);if(N===-1)return p.push(o.substring(y)),p;p.push(o.substring(y,N)),y=N+1}return p})(E(a[0]).replace(S,""),[","]).map(o=>E(o))}function $(){const a=r(),o=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(t);if(!o)return;m(o);const f=E(o[0]),p=/^:\s*/.exec(t);if(!p)return l("property missing ':'");m(p);let y="";const N=O(t,[";","}"]);N!==-1&&(y=t.substring(0,N),m([y]),y=E(y).replace(S,""));const C=a({type:h.declaration,property:f.replace(S,""),value:y}),re=/^[;\s]*/.exec(t);return re&&m(re),C}function ne(){const a=[];if(!u())return l("missing '{'");d(a);let o=$();for(;o;)a.push(o),d(a),o=$();return c()?a:l("missing '}'")}function ie(){const a=[],o=r();let f=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t);for(;f;){const p=m(f);a.push(p[1]);const y=/^,\s*/.exec(t);y&&m(y),f=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t)}if(a.length)return o({type:h.keyframe,values:a,declarations:ne()||[]})}const Le=H("import"),De=H("charset"),Ie=H("namespace");function H(a){const o=new RegExp("^@"+a+`\\s*((?::?[^;'"]|"(?:\\\\"|[^"])*?"|'(?:\\\\'|[^'])*?')+)(?:;|$)`);return()=>{const f=r(),p=o.exec(t);if(!p)return;const y=m(p),N={type:a};return N[a]=y[1].trim(),f(N)}}function Be(){if(t[0]==="@")return(function(){const a=r(),o=/^@([-\w]+)?keyframes\s*/.exec(t);if(!o)return;const f=m(o)[1],p=/^([-\w]+)\s*/.exec(t);if(!p)return l("@keyframes missing name");const y=m(p)[1];if(!u())return l("@keyframes missing '{'");let N=d(),C=ie();for(;C;)N.push(C),N=N.concat(d()),C=ie();return c()?a({type:h.keyframes,name:y,vendor:f,keyframes:N}):l("@keyframes missing '}'")})()||(function(){const a=r(),o=/^@media *([^{]+)/.exec(t);if(!o)return;const f=E(m(o)[1]);if(!u())return l("@media missing '{'");const p=d().concat(g());return c()?a({type:h.media,media:f,rules:p}):l("@media missing '}'")})()||(function(){const a=r(),o=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(t);if(!o)return;const f=m(o);return a({type:h.customMedia,name:E(f[1]),media:E(f[2])})})()||(function(){const a=r(),o=/^@supports *([^{]+)/.exec(t);if(!o)return;const f=E(m(o)[1]);if(!u())return l("@supports missing '{'");const p=d().concat(g());return c()?a({type:h.supports,supports:f,rules:p}):l("@supports missing '}'")})()||Le()||De()||Ie()||(function(){const a=r(),o=/^@([-\w]+)?document *([^{]+)/.exec(t);if(!o)return;const f=m(o),p=E(f[1]),y=E(f[2]);if(!u())return l("@document missing '{'");const N=d().concat(g());return c()?a({type:h.document,document:y,vendor:p,rules:N}):l("@document missing '}'")})()||(function(){const a=r(),o=/^@page */.exec(t);if(!o)return;m(o);const f=te()||[];if(!u())return l("@page missing '{'");let p=d(),y=$();for(;y;)p.push(y),p=p.concat(d()),y=$();return c()?a({type:h.page,selectors:f,declarations:p}):l("@page missing '}'")})()||(function(){const a=r(),o=/^@host\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@host missing '{'");const f=d().concat(g());return c()?a({type:h.host,rules:f}):l("@host missing '}'")})()||(function(){const a=r(),o=/^@font-face\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@font-face missing '{'");let f=d(),p=$();for(;p;)f.push(p),f=f.concat(d()),p=$();return c()?a({type:h.fontFace,declarations:f}):l("@font-face missing '}'")})()||(function(){const a=r(),o=/^@container *([^{]+)/.exec(t);if(!o)return;const f=E(m(o)[1]);if(!u())return l("@container missing '{'");const p=d().concat(g());return c()?a({type:h.container,container:f,rules:p}):l("@container missing '}'")})()||(function(){const a=r(),o=/^@starting-style\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@starting-style missing '{'");const f=d().concat(g());return c()?a({type:h.startingStyle,rules:f}):l("@starting-style missing '}'")})()||(function(){const a=r(),o=/^@layer *([^{;@]+)/.exec(t);if(!o)return;const f=E(m(o)[1]);if(!u()){const y=/^[;\s]*/.exec(t);return y&&m(y),a({type:h.layer,layer:f})}const p=d().concat(g());return c()?a({type:h.layer,layer:f,rules:p}):l("@layer missing '}'")})()}function Pe(){const a=r(),o=te();return o?(d(),a({type:h.rule,selectors:o,declarations:ne()||[]})):l("selector missing")}return M((function(){const a=g();return{type:h.stylesheet,stylesheet:{source:e?.source,rules:a,parsingErrors:s}}})())},stringify:(t,e)=>new oe(e||{}).compile(t)};function ce(t,e){const n=t;return n.isBlock=L(n),n.isCode=n.nodeName==="CODE"||n.parentNode?.isCode,n.isBlank=le(n),n.flankingWhitespace=ue(n,e),n}function le(t){return!G(t)&&!de(t)&&/^\s*$/i.test(t.textContent||"")&&!he(t)&&!ge(t)}function ue(t,e){const n=t;if(n.isBlock||e.preformattedCode&&n.isCode)return{leading:"",trailing:""};const i=me(t.textContent||"");return i.leadingAscii&&_("left",t,e)&&(i.leading=i.leadingNonAscii),i.trailingAscii&&_("right",t,e)&&(i.trailing=i.trailingNonAscii),{leading:i.leading,trailing:i.trailing}}function me(t){const e=t.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return e?{leading:e[1],leadingAscii:e[2],leadingNonAscii:e[3],trailing:e[4],trailingNonAscii:e[5],trailingAscii:e[6]}:{leading:"",leadingAscii:"",leadingNonAscii:"",trailing:"",trailingNonAscii:"",trailingAscii:""}}function _(t,e,n){let i,r,s;return t==="left"?(i=e.previousSibling,r=/ $/):(i=e.nextSibling,r=/^ /),i&&(i.nodeType===3?s=r.test(i.nodeValue||""):n.preformattedCode&&i.nodeName==="CODE"?s=!1:i.nodeType===1&&!L(i)&&(s=r.test(i.textContent||""))),s||!1}const x={Element:1,Text:3,CDATASection:4,Comment:8};function v(t,e){return Array(e+1).join(t)}function j(t){return t.replace(/^\n*/,"")}function U(t){let e=t.length;for(;e>0&&t[e-1]===`
|
|
51
|
+
`;)e--;return t.substring(0,e)}function z(t){return U(j(t))}const fe=["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 L(t){return D(t,fe)}const W=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function G(t){return D(t,W)}function he(t){return Y(t,W)}const K=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"],pe=["P","BR","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","UL","OL","LI","PRE","CODE","HR","A","EM","I","STRONG","B","IMG","DIV","SPAN","TABLE","THEAD","TBODY","TR","TH","TD"];function de(t){return D(t,K)}function ge(t){return Y(t,K)}function D(t,e){return e.indexOf(t.nodeName)>=0}function Y(t,e){return e.some(function(n){return t.nodeType!==x.Element?!1:t.getElementsByTagName(n).length})}function q(t){return t?t.replace(/(\n+\s*)+/g,`
|
|
52
|
+
`):""}function ye(t){return q(t).replace(/[\t\r\n]+/g," ").replace(/ {2,}/g," ").trim()}function w(t){return q(t).replace(/[\t\r\n]+/g," ")}function ke(t){const e=t.parentNode;return e?e.nodeType===x.Element&&e.classList&&e.classList.contains("code")&&e.nodeName==="TD"&&t.nodeName==="PRE":!1}function Ne(t){if(t.nodeName!=="PRE"||t.nodeType!==x.Element)return!1;const e=t.getAttribute("style");if(!e)return!1;const n=ae.parse("pre {"+e+"}");if(!n.stylesheet.rules.length)return!1;const i=n.stylesheet.rules[0];if(!("declarations"in i)||!i.declarations)return!1;const r=i.declarations.find(l=>"property"in l?l.property.toLowerCase()==="font-family":!1);return!r||"value"in r&&!r.value?!1:"value"in r&&r.value.split(",").map(l=>l.trim().toLowerCase()).indexOf("monospace")>=0}function Q(t){return ke(t)||Ne(t)?!0:t.nodeName==="PRE"&&t.firstChild&&t.firstChild.nodeName==="CODE"||!1}const k={};k.paragraph={filter:"p",replacement:function(t){return`
|
|
53
53
|
|
|
54
54
|
`+t+`
|
|
55
55
|
|
|
56
56
|
`}},k.lineBreak={filter:"br",replacement:function(t,e,n){return n.br+`
|
|
57
|
-
`}},k.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(t,e,n){const i=Number(e.nodeName.charAt(1));if(n.headingStyle==="setext"&&i<3){const r=
|
|
57
|
+
`}},k.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(t,e,n){const i=Number(e.nodeName.charAt(1));if(n.headingStyle==="setext"&&i<3){const r=v(i===1?"=":"-",t.length);return`
|
|
58
58
|
|
|
59
59
|
`+t+`
|
|
60
60
|
`+r+`
|
|
61
61
|
|
|
62
62
|
`}else return`
|
|
63
63
|
|
|
64
|
-
`+
|
|
64
|
+
`+v("#",i)+" "+t+`
|
|
65
65
|
|
|
66
66
|
`}},k.blockquote={filter:"blockquote",replacement:function(t){return t=z(t).replace(/^/gm,"> "),`
|
|
67
67
|
|
|
@@ -72,31 +72,31 @@ ${this.indent()}}`)}declaration(e){return this.compress?this.emit(`${e.property}
|
|
|
72
72
|
|
|
73
73
|
`+t+`
|
|
74
74
|
|
|
75
|
-
`}},k.listItem={filter:"li",replacement:function(t,e,n){let i=n.bulletListMarker+" ".repeat(n.listMarkerSpaceCount);const r=e.parentNode;if(r.nodeName==="OL"){const d=r.getAttribute("start")
|
|
75
|
+
`}},k.listItem={filter:"li",replacement:function(t,e,n){let i=n.bulletListMarker+" ".repeat(n.listMarkerSpaceCount);const r=e.parentNode;if(r.nodeName==="OL"){const d=r.getAttribute("start"),R=Array.prototype.indexOf.call(r.children,e);i=(d?Number(d)+R:R+1)+"."+" ".repeat(n.listMarkerSpaceCount)}const s=/\n$/.test(t);if(t=z(t)+(s?`
|
|
76
76
|
`:""),e.childNodes.length>0&&Array.from(e.childNodes).every(d=>d.nodeType===x.Text&&/^\s*$/.test(d.nodeValue||"")||d.nodeType===x.Element&&["UL","OL"].includes(d.nodeName))&&t.trim()!=="")return t+(e.nextSibling?`
|
|
77
|
-
`:"");let u=0,c=r;for(;c;){if(c.nodeName==="UL"||c.nodeName==="OL"){const d=c.parentNode;d&&d.nodeName==="LI"&&u++}c=c.parentNode}let g=n.listItemIndent==="tab"?" ":" ".repeat(n.listItemIndentSpaceCount),m=g.repeat(u);const
|
|
77
|
+
`:"");let u=0,c=r;for(;c;){if(c.nodeName==="UL"||c.nodeName==="OL"){const d=c.parentNode;d&&d.nodeName==="LI"&&u++}c=c.parentNode}let g=n.listItemIndent==="tab"?" ":" ".repeat(n.listItemIndentSpaceCount),m=g.repeat(u);const T=/\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;return t=t.replace(T,`
|
|
78
78
|
`+g),m+i+t+(e.nextSibling?`
|
|
79
79
|
`:"")}},k.indentedCodeBlock={filter:function(t,e){return!!(e&&e.codeBlockStyle==="indented"&&t.nodeName==="PRE"&&t.firstChild&&t.firstChild.nodeName==="CODE")},replacement:function(t,e){return!e||!e.firstChild?"":`
|
|
80
80
|
|
|
81
81
|
`+e.firstChild.textContent.replace(/\n/g,`
|
|
82
82
|
`)+`
|
|
83
83
|
|
|
84
|
-
`}},k.fencedCodeBlock={filter:function(t,e){return!!(e&&e.codeBlockStyle==="fenced"&&t.nodeName==="PRE")},replacement:function(t,e,n){const i=e,r=i.firstChild,s=r&&r.nodeName==="CODE"?r:i,u=((s.getAttribute("class")||"").match(/(?:lang|language)-(\S+)/)||[null,""])[1],c=s.textContent||"",g=n.fence?.charAt(0)||"`";let m=3;const
|
|
84
|
+
`}},k.fencedCodeBlock={filter:function(t,e){return!!(e&&e.codeBlockStyle==="fenced"&&t.nodeName==="PRE")},replacement:function(t,e,n){const i=e,r=i.firstChild,s=r&&r.nodeName==="CODE"?r:i,u=((s.getAttribute("class")||"").match(/(?:lang|language)-(\S+)/)||[null,""])[1],c=s.textContent||"",g=n.fence?.charAt(0)||"`";let m=3;const T=new RegExp("^"+g+"{3,}","gm");let d;for(;d=T.exec(c);)d[0].length>=m&&(m=d[0].length+1);const R=v(g,m);return`
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
`+R+u+`
|
|
87
87
|
`+c.replace(/\n$/,"")+`
|
|
88
|
-
|
|
88
|
+
`+R+`
|
|
89
89
|
|
|
90
90
|
`}},k.horizontalRule={filter:"hr",replacement:function(t,e,n){return`
|
|
91
91
|
|
|
92
92
|
`+n.hr+`
|
|
93
93
|
|
|
94
|
-
`}},k.inlineLink={filter:function(t,e){return!!(e?.linkStyle==="inlined"&&t.nodeName==="A"&&t.getAttribute("href"))},replacement:function(t,e){const n=
|
|
94
|
+
`}},k.inlineLink={filter:function(t,e){return!!(e?.linkStyle==="inlined"&&t.nodeName==="A"&&t.getAttribute("href"))},replacement:function(t,e){const n=ye(t);let i=e.getAttribute("href")?.replace(/([()])/g,"\\$1"),r;const s=e.getAttribute("title");return s?r=' "'+w(s).replace(/"/g,'\\"')+'"':r="","["+n+"]("+i+r+")"}};const I={filter:function(t,e){return!!(e&&e.linkStyle==="referenced"&&t.nodeName==="A"&&t.getAttribute("href"))},replacement:function(t,e,n){const i=I,r=e.getAttribute("href");let s;const l=e.getAttribute("title");l?s=' "'+w(l)+'"':s="";const u=r+s;let c,g;switch(n.linkReferenceStyle){case"collapsed":c="["+t+"][]",g="["+t+"]: "+u;break;case"shortcut":c="["+t+"]",g="["+t+"]: "+u;break;default:{let m;const T=i.urlReferenceIdMap.get(u);n.linkReferenceDeduplication==="full"&&T?(m=T,g="["+m+"]: "+r+s):(m=i.references.length+1,i.urlReferenceIdMap.set(u,m),g="["+m+"]: "+r+s,i.references.push(g)),c="["+t+"]["+m+"]";break}}return n.linkReferenceStyle!=="full"&&(n.linkReferenceDeduplication==="full"?i.urlReferenceIdMap.has(u)||(i.urlReferenceIdMap.set(u,1),i.references.push(g)):i.references.push(g)),c},references:[],urlReferenceIdMap:new Map,append:()=>{const t=I;let e="";return t.references&&t.references.length&&(e=`
|
|
95
95
|
|
|
96
96
|
`+t.references.join(`
|
|
97
97
|
`)+`
|
|
98
98
|
|
|
99
|
-
`,t.references=[],t.urlReferenceIdMap=new Map),e}};k.referenceLink=I,k.emphasis={filter:["em","i"],replacement:(t,e,n)=>(t=t.trim(),t?n.emDelimiter+t+n.emDelimiter:"")},k.strong={filter:["strong","b"],replacement:(t,e,n)=>(t=t.trim(),t?n.strongDelimiter+t+n.strongDelimiter:"")},k.code={filter:t=>{const e=t.parentNode,n=Q(e);return t.nodeName==="CODE"&&!n},replacement:t=>{const e=t.replace(/\r?\n|\r/g," "),n=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"";let i="`";const r=e.match(/`+/gm)||[];for(;r.includes(i);)i=i+"`";return i+n+e+n+i}},k.image={filter:"img",replacement:function(t,e){const n=e.getAttribute("alt"),i=n?w(n):"",r=e.getAttribute("src")||"",s=e.getAttribute("title"),l=s?w(s):"",u=l?' "'+l+'"':"";return r?"":""}};class
|
|
99
|
+
`,t.references=[],t.urlReferenceIdMap=new Map),e}};k.referenceLink=I,k.emphasis={filter:["em","i"],replacement:(t,e,n)=>(t=t.trim(),t?n.emDelimiter+t+n.emDelimiter:"")},k.strong={filter:["strong","b"],replacement:(t,e,n)=>(t=t.trim(),t?n.strongDelimiter+t+n.strongDelimiter:"")},k.code={filter:t=>{const e=t.parentNode,n=Q(e);return t.nodeName==="CODE"&&!n},replacement:t=>{const e=t.replace(/\r?\n|\r/g," "),n=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"";let i="`";const r=e.match(/`+/gm)||[];for(;r.includes(i);)i=i+"`";return i+n+e+n+i}},k.image={filter:"img",replacement:function(t,e){const n=e.getAttribute("alt"),i=n?w(n):"",r=e.getAttribute("src")||"",s=e.getAttribute("title"),l=s?w(s):"",u=l?' "'+l+'"':"";return r?"":""}};class X{options;_keep;_remove;blankRule;keepReplacement;markdownIncludingHtmlReplacement;defaultRule;array;constructor(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.markdownIncludingHtmlReplacement=e.markdownIncludingHtmlReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(const n in e.rules)this.array.push(e.rules[n])}add(e,n){this.array.unshift(n)}keep(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})}remove(e){this._remove.unshift({filter:e,replacement:function(){return""}})}forNode(e){if(e.isBlank)return this.blankRule;if(this.options.htmlRetentionMode==="preserveAll"&&this.isUnsupportedElement(e))return{replacement:this.keepReplacement};if(this.options.htmlRetentionMode==="markdownIncludingHtml"&&this.isUnsupportedElement(e))return{replacement:this.markdownIncludingHtmlReplacement};let n;return(n=B(this.array,e,this.options))||(n=B(this._keep,e,this.options))||(n=B(this._remove,e,this.options))?n:this.defaultRule}isUnsupportedElement(e){const n=e.nodeName;if(n==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"){const i=e.firstChild;if(i.attributes&&i.attributes.length>0){for(let r=0;r<i.attributes.length;r++)if(i.attributes[r].name.toLowerCase()!=="class")return!0}}if(e.attributes&&e.attributes.length>0)switch(n){case"IMG":for(let r=0;r<e.attributes.length;r++){const s=e.attributes[r].name.toLowerCase();if(s!=="src"&&s!=="alt"&&s!=="title")return!0}return!1;case"A":for(let r=0;r<e.attributes.length;r++){const s=e.attributes[r].name.toLowerCase();if(s!=="href"&&s!=="title")return!0}return!1;case"CODE":const i=e.parentNode;if(i&&i.nodeName==="PRE"){for(let r=0;r<e.attributes.length;r++)if(e.attributes[r].name.toLowerCase()!=="class")return!0;return!1}default:return!0}return pe.indexOf(n)===-1}forEach(e){for(let n=0;n<this.array.length;n++)e(this.array[n],n)}}function B(t,e,n){for(let i=0;i<t.length;i++){const r=t[i];if(Te(r,e,n))return r}}function Te(t,e,n){const i=t.filter;if(typeof i=="string"){if(i===e.nodeName.toLowerCase())return!0}else if(Array.isArray(i)){if(i.indexOf(e.nodeName.toLowerCase())>-1)return!0}else if(typeof i=="function"){if(i(e,n))return!0}else throw new TypeError("`filter` needs to be a string, array, or function");return!1}function Ee(t){const e=t.element,n=t.isBlock,i=t.isVoid,r=t.isPre||function(g){return g.nodeName==="PRE"};if(!e.firstChild||r(e))return;let s=null,l=!1,u=null,c=J(u,e,r);for(;c!==e;){if(c.nodeType===x.Text||c.nodeType===x.CDATASection){const m=c;let T=m.data.replace(/[ \r\n\t]+/g," ");if((!s||/ $/.test(s.data))&&!l&&T[0]===" "&&(T=T.substr(1)),!T){c=P(c);continue}m.data=T,s=m}else if(c.nodeType===x.Element)n(c)||c.nodeName==="BR"?(s&&(s.data=s.data.replace(/ $/,"")),s=null,l=!1):i(c)||r(c)?(s=null,l=!0):s&&(l=!1);else{c=P(c);continue}const g=J(u,c,r);u=c,c=g}s&&(s.data=s.data.replace(/ $/,""),s.data||P(s))}function P(t){const e=t.nextSibling??t.parentNode;return t.parentNode&&t.parentNode.removeChild(t),e}function J(t,e,n){return t&&t.parentNode===e||n(e)?e.nextSibling??e.parentNode:e.firstChild??e.nextSibling??e.parentNode}const V=typeof window<"u"?window:typeof globalThis<"u"?globalThis:{};function xe(){const t=typeof V.DOMParser<"u"?V.DOMParser:void 0;let e=!1;if(!t)return!1;try{new t().parseFromString("","text/html")&&(e=!0)}catch{}return e}class Z{parseFromString(e,n){throw new Error("Not implemented")}}function be(){if(typeof window<"u"&&typeof document<"u"&&(typeof process>"u"||process.browser),typeof window<"u"){class t extends Z{parseFromString(n,i){const r=document.implementation.createHTMLDocument("");return r.open(),r.write(n),r.close(),r}}return new t}else{const t=require("@mixmark-io/domino");class e extends Z{parseFromString(i,r){return t.createDocument(i)}}return new e}}const Re=()=>xe()?new V.DOMParser:be();function $e(t,{preformattedCode:e}){let n;return typeof t=="string"?n=Ce().parseFromString('<x-turnish id="turnish-root">'+t+"</x-turnish>","text/html").getElementById("turnish-root"):n=t.cloneNode(!0),Ee({element:n,isBlock:L,isVoid:G,isPre:e?we:void 0}),n}let Ae;function Ce(){return Ae??=Re()}function we(t){return t.nodeName==="PRE"||t.nodeName==="CODE"}const Oe=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/_/g,"\\_"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/<([^>]*)>/g,"\\<$1\\>"],[/^>/g,"\\>"],[/^(\d+)\. /g,"$1\\. "]],Se={rules:k,headingStyle:"atx",hr:"---",bulletListMarker:"-",listMarkerSpaceCount:1,listItemIndent:"space",listItemIndentSpaceCount:4,codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",linkReferenceDeduplication:"full",br:" ",preformattedCode:!1,htmlRetentionMode:"standard",blankReplacement:(t,e)=>e.isBlock?`
|
|
100
100
|
|
|
101
101
|
`:"",keepReplacement:(t,e)=>e.isBlock?`
|
|
102
102
|
|
|
@@ -112,7 +112,7 @@ ${this.indent()}}`)}declaration(e){return this.compress?this.emit(`${e.property}
|
|
|
112
112
|
|
|
113
113
|
`+t+`
|
|
114
114
|
|
|
115
|
-
`:t}};class
|
|
115
|
+
`:t}};class Me{options;rules;constructor(e){this.options=Object.assign({},Se,e),this.rules=new X(this.options)}render(e){if(!ve(e))throw new TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";const n=this.process($e(e,this.options));return this.postProcess(n)}use(e){if(Array.isArray(e))for(let n=0;n<e.length;n++)this.use(e[n]);else if(typeof e=="function")e(this);else throw new TypeError("plugin must be a Function or an Array of Functions");return this}addRule(e,n){return this.rules.add(e,n),this}keep(e){return this.rules.keep(e),this}remove(e){return this.rules.remove(e),this}escape(e){return Oe.reduce(function(n,i){return n.replace(i[0],i[1])},e)}process(e){return Array.from(e.childNodes).reduce((n,i)=>{const r=ce(i,this.options);let s="";if(r.nodeType===x.Text){let l=r.nodeValue??"";if(i.previousSibling&&i.previousSibling.nodeType===x.Element){const u=i.previousSibling;u.nodeName==="INPUT"&&u.getAttribute("type")==="checkbox"&&(l=l.replace(/^\s+/,""))}s=r.isCode?l:this.escape(l)}else r.nodeType===x.Element&&(s=this.replacementForNode(r));return ee(n,s)},"")}postProcess(e){for(const n of this.rules.array)n.append&&(e=ee(e,n.append(this.options)));return e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}replacementForNode(e){const n=this.rules.forNode(e);let i=this.process(e);const r=e.flankingWhitespace;return(r.leading||r.trailing)&&(i=i.trim()),r.leading+n.replacement(i,e,this.options)+r.trailing}isCodeBlock(e){return Q(e)}}function ee(t,e){const n=U(t),i=j(e),r=Math.max(t.length-n.length,e.length-i.length),s=`
|
|
116
116
|
|
|
117
|
-
`.substring(0,r);return n+s+i}function
|
|
117
|
+
`.substring(0,r);return n+s+i}function ve(t){return t!=null&&(typeof t=="string"||t.nodeType&&(t.nodeType===1||t.nodeType===9||t.nodeType===11))}b.NodeTypes=x,b.Rules=X,b.default=Me,Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
118
118
|
//# sourceMappingURL=index.umd.js.map
|