UNPKG

@diplodoc/transform

Version:

A simple transformer of text in YFM (Yandex Flavored Markdown) to HTML

3 lines (2 loc) 9.12 kB
"use strict";(()=>{(()=>{var q=Object.create,T=Object.defineProperty,U=Object.getOwnPropertyDescriptor,O=Object.getOwnPropertyNames,z=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,W=(t,e)=>function(){return e||(0,t[O(t)[0]])((e={exports:{}}).exports,e),e.exports},H=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!V.call(t,n)&&n!==o&&T(t,n,{get:()=>e[n],enumerable:!(r=U(e,n))||r.enumerable});return t},K=(t,e,o)=>(o=t!=null?q(z(t)):{},H(e||!t||!t.__esModule?T(o,"default",{value:t,enumerable:!0}):o,t)),Y=W({"node_modules/get-root-node-polyfill/index.js"(t,e){"use strict";function o(c){var s=typeof c=="object"&&!!c.composed;return s?r(this):n(this)}function r(c){var s=n(c);return i(s)?r(s.host):s}function n(c){return c.parentNode!=null?n(c.parentNode):c}function i(c){return c.nodeName==="#document-fragment"&&c.constructor.name==="ShadowRoot"}typeof e=="object"&&e.exports&&(e.exports=o)}}),G=K(Y());typeof document!="undefined"&&(function(t){let e=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector;e?t.matches=t.matchesSelector=e:t.matches=t.matchesSelector=function(r){let i=(t.getRootNode?t.getRootNode():G.default.call(t)).querySelectorAll(r),c=this;return Array.prototype.some.call(i,s=>s===c)}})(Element.prototype);var g=t=>{let e=t.composedPath();return Array.isArray(e)&&e.length>0?e[0]:t.target},y=t=>{let e=g(t);return!e||!e.matches},E=async t=>{if(!t)return;if(navigator.clipboard&&typeof navigator.clipboard.writeText)return navigator.clipboard.writeText(t);let e=document.createElement("textarea");e.setAttribute("style","position: absolute; left: 1000%"),e.textContent=t,document.body.append(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)},J=".yfm-clipboard-button",X=".yfm-wrapping-button";function Z(t){if(!t)return;let e=t.getAttribute("data-animation"),o=t.getRootNode().getElementById(`visibileAnimation-${e}`);o&&o.beginElement()}function Q(t){var e;let o=(e=t.parentNode)==null?void 0:e.parentNode,r=o==null?void 0:o.querySelector("pre code");if(!o||!r)return;let n=Array.from(r.childNodes).filter(i=>!(i instanceof HTMLElement&&i.classList.contains("yfm-line-number"))).map(i=>i.textContent).join("");E(n.trim()).then(()=>{Z(o.querySelector(".yfm-clipboard-icon")),setTimeout(()=>t.blur(),1500)})}function tt(t){var e;let o=(e=t.parentNode)==null?void 0:e.parentNode,r=o==null?void 0:o.querySelector("pre code");!o||!r||(r.classList.toggle("wrap"),setTimeout(()=>t.blur(),500))}typeof document!="undefined"&&document.addEventListener("click",t=>{if(y(t))return;let e=g(t);e.matches(J)?Q(e):e.matches(X)&&tt(e)});var et=".dc-doc-page__content",x="yfm yfm-tooltip",A="open",_="data-tooltip-id",ot={mainAxis:5},nt={top:"bottom",bottom:"top",left:"right",right:"left"},rt={top:0,bottom:0,left:0,right:0};function L(t){return t==="top"||t==="bottom"}function it(t=0){return typeof t=="number"?{top:t,bottom:t,left:t,right:t}:{...rt,...t}}function w(t){let[e,o]=t.split("-");return{side:e,alignment:o}}function S(t){return nt[t]}function ct(t){let{side:e,alignment:o}=w(t),r=S(e);return o?`${r}-${o}`:r}function C(t,e,o){let r=N(t,{top:e.y,left:e.x});return ft(o,r,5)}function st(t,e,o){let r=S(o);return t[o]>0&&e[r]<t[o]}function ut(t,e,o,r,n,i,c=!0){let s=D(t,e,n,r,i);if(!c)return{coords:s,placement:r};let d=C(e,s,o),{side:l}=w(r);if(d[l]<=0)return{coords:s,placement:r};let p=ct(r),f=D(t,e,n,p,i),a=C(e,f,o);return st(d,a,l)?{coords:f,placement:p}:{coords:s,placement:r}}function lt(){let t=Math.random().toString(36).substring(2,6),e=Date.now().toString(36);return`${t}${e}`}function m(t){return{...t,right:t.left+t.width,bottom:t.top+t.height}}function N(t,e){var o,r,n,i;return m({top:(o=e.top)!=null?o:t.top,left:(r=e.left)!=null?r:t.left,width:(n=e.width)!=null?n:t.width,height:(i=e.height)!=null?i:t.height})}function P(){let{documentElement:t,body:e}=document,o=window.scrollY||t.scrollTop||e.scrollTop,r=window.scrollX||t.scrollLeft||e.scrollLeft,n=t.clientTop||e.clientTop||0,i=t.clientLeft||e.clientLeft||0;return m({top:Math.round(o-n),left:Math.round(r-i),width:document.body.clientWidth,height:document.body.clientHeight})}function R(t){let e=P(),o=t.getBoundingClientRect();return m({top:Math.round(o.top+e.top),left:Math.round(o.left+e.left),width:o.width,height:o.height})}function at(t,e,o){let{mainAxis:r=0,crossAxis:n=0}=t,i=L(e),c=e==="top"||e==="left"?-1:1,s=o&&i?-1:1,d=r*c,l=n*s;return i?{x:l,y:d}:{x:d,y:l}}function D(t,e,o,r,n){let{side:i,alignment:c}=w(r),s=L(i),d=s?"x":"y",l=d==="y"?"height":"width",p=t.left+t.width/2-e.width/2,f=t.top+t.height/2-e.height/2,a=t[l]/2-e[l]/2,u={x:t.left,y:t.top};switch(i){case"top":{u.x=p,u.y=t.top-e.height;break}case"bottom":{u.x=p,u.y=t.top+t.height;break}case"right":{u.x=t.left+t.width,u.y=f;break}case"left":{u.x=t.left-e.width,u.y=f;break}}switch(c){case"start":{u[d]-=a*(n&&s?-1:1);break}case"end":{u[d]+=a*(n&&s?-1:1);break}}let h=at(o,i,n);return u.x+=h.x,u.y+=h.y,u}function dt(t,e){let o=R(e);return m({top:t.top-o.top+e.offsetTop,left:t.left-o.left+e.offsetLeft,width:t.width,height:t.height})}function ft(t,e,o=0){let{top:r,bottom:n,left:i,right:c}=it(o);return{top:t.top-e.top+r,bottom:e.bottom-t.bottom+n,left:t.left-e.left+i,right:e.right-t.right+c}}function I(t={}){let{closeDelay:e=1e3,additionalClassName:o}=t,r=!1,n={currentId:null,timer:null,unsubscribe:null},i=()=>n.currentId?document.getElementById(n.currentId):null,c=()=>n.currentId?k(n.currentId):null,s=()=>{let a=i();n.timer&&(clearTimeout(n.timer),n.timer=null),n.unsubscribe&&(n.unsubscribe(),n.unsubscribe=null),a&&(a.classList.remove(A),mt(a),n.currentId=null)},d=(a,u)=>{s();let h=pt({text:u,className:o}),M=B.bind(null,t,a,h);n.currentId=h.id,ht(h,a),n.unsubscribe=bt(a,M),h.classList.add(A),M(),e>0&&(n.timer=setTimeout(s,e))},l=()=>{let a=i(),u=c();if(a&&!u){s();return}a&&u&&B(t,u,a)};return{get visible(){return!!n.currentId},getActiveReference:c,show:d,hide:s,init:()=>{r||(r=!0,window.addEventListener("scroll",l),window.addEventListener("resize",l))},cleanup:()=>{r&&(r=!1,window.removeEventListener("scroll",l),window.removeEventListener("resize",l))}}}function pt(t){let{text:e,className:o}=t,r=lt(),n=document.createElement("div");return n.id=r,n.className=o?`${x} ${o}`:x,n.setAttribute("role","tooltip"),n.setAttribute("aria-live","polite"),n.textContent=e,n}function ht(t,e){let o=document.querySelector(et)||document.body,r=e.getAttribute("aria-live");e.setAttribute(_,t.id),r&&t.setAttribute("aria-live",r),o.appendChild(t)}function mt(t){if(t.id){let e=k(t.id);e==null||e.removeAttribute(_)}t.remove()}function k(t){return document.querySelector(`[${_}="${t}"]`)}function bt(t,e){let o=gt(t);return o.addEventListener("scroll",e),()=>{o.removeEventListener("scroll",e)}}function gt(t){return t.closest("table")||t.closest("code")||t.parentElement||document.body}function vt(t,e){let o=e.parentElement;if(!o)return null;let r={reference:t,tooltip:e,offsetParent:o},n=P(),i=R(t),{width:c,height:s}=e.getBoundingClientRect();return{isRtl:document.dir==="rtl",viewport:n,reference:i,tooltip:m({top:0,left:0,width:c,height:s}),elements:r}}function B(t,e,o){let r=vt(e,o);if(!r)return;let n=yt(r,t);o.style.top=`${n.y}px`,o.style.left=`${n.x}px`}function yt(t,e){let{placement:o="bottom-start",offset:r=ot,flip:n=!0}=e,{reference:i,tooltip:c,viewport:s,isRtl:d}=t,{coords:l}=ut(i,c,s,o,r,d,n),p=N(c,{top:l.y,left:l.x}),f=dt(p,t.elements.offsetParent);return{x:f.left,y:f.top}}var v={ru:"\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E",en:"Copied",ar:"\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",cs:"Zkop\xEDrov\xE1no",fr:"Copi\xE9",es:"Copiado",he:"\u05D4\u05D5\u05E2\u05EA\u05E7",bg:"\u041A\u043E\u043F\u0438\u0440\u0430\u043D\u043E",et:"Kopeeritud",el:"\u0391\u03BD\u03C4\u03B9\u03B3\u03C1\u03AC\u03C6\u03B7\u03BA\u03B5",pt:"Copiado",zh:"\u5DF2\u590D\u5236","zh-tw":"\u5DF2\u8907\u88FD",kk:"\u041A\u04E9\u0448\u0456\u0440\u0456\u043B\u0434\u0456",tr:"Kopyaland\u0131",uz:"Nusxalandi"},Et=/^(?:https?|file):$/,_t=".yfm-clipboard-anchor",F=I();function wt(t){let e=t.nodeName==="A"?t.href:t.dataset.href,o=new URL(e||"",window.location.href);return Et.test(o.protocol)?o.href:window.location.href}typeof document!="undefined"&&(F.init(),document.addEventListener("click",t=>{let e=g(t);if(y(t)||!e.matches(_t))return;let o=wt(e);E(o).then(()=>{var r;let n=document.documentElement.lang||"en",i=(r=v[n])!=null?r:v.en;F.show(e,i)})}));var $="yfm-clipboard-inline-code",Tt=`.${$}`,b=I({additionalClassName:"inline_code_tooltip"});function j(t){let e=t.innerText;e&&E(e).then(()=>{var o;let r=document.documentElement.lang||"en",n=(o=v[r])!=null?o:v.en;b.show(t,n)})}typeof document!="undefined"&&(b.init(),document.addEventListener("click",t=>{let e=g(t),o=e.matches(Tt);y(t)||!o||j(e)}),document.addEventListener("keydown",t=>{if(t.key==="Enter"&&document.activeElement){let e=document.activeElement;if(!e.classList.contains($))return;j(e)}if(t.key==="Escape"&&b.visible){let e=b.getActiveReference();b.hide(),e==null||e.focus()}}))})();})(); //# sourceMappingURL=base.min.js.map