@mt-kit/vue-directives
Version:
165 lines (140 loc) • 16.9 kB
JavaScript
(function(d,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d.microVueDirectives={}))})(this,function(d){"use strict";function f(e){const t=new Date(e),n=t.getFullYear(),o=t.getMonth()+1<10?`0${t.getMonth()+1}`:t.getMonth()+1,r=t.getDate()<10?`0${t.getDate()}`:t.getDate(),i=t.getHours()<10?`0${t.getHours()}`:t.getHours(),s=t.getMinutes()<10?`0${t.getMinutes()}`:t.getMinutes(),c=t.getSeconds()<10?`0${t.getSeconds()}`:t.getSeconds();return`${n}-${o}-${r} ${i}:${s}:${c}`}function q(e){e.directive("conversion-time",{mounted(t){const n=t.textContent;let o=Number.parseInt(n);JSON.stringify(o).length===10&&(o=o*1e3),t.textContent=f(o)}})}var F=Object.defineProperty,W=(e,t,n)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,g=(e,t,n)=>W(e,typeof t!="symbol"?t+"":t,n);function Y(e){return e instanceof Element||e!=null&&typeof e=="object"&&"nodeType"in e&&typeof e.nodeType=="number"&&"nodeName"in e&&typeof e.nodeName=="string"}var k=function(){if(typeof Map<"u")return Map;function e(t,n){var o=-1;return t.some(function(r,i){return r[0]===n?(o=i,!0):!1}),o}return function(){function t(){this.__entries__=[]}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),t.prototype.get=function(n){var o=e(this.__entries__,n),r=this.__entries__[o];return r&&r[1]},t.prototype.set=function(n,o){var r=e(this.__entries__,n);~r?this.__entries__[r][1]=o:this.__entries__.push([n,o])},t.prototype.delete=function(n){var o=this.__entries__,r=e(o,n);~r&&o.splice(r,1)},t.prototype.has=function(n){return!!~e(this.__entries__,n)},t.prototype.clear=function(){this.__entries__.splice(0)},t.prototype.forEach=function(n,o){o===void 0&&(o=null);for(var r=0,i=this.__entries__;r<i.length;r++){var s=i[r];n.call(o,s[1],s[0])}},t}()}(),y=typeof window<"u"&&typeof document<"u"&&window.document===document,p=function(){return typeof global<"u"&&global.Math===Math?global:typeof self<"u"&&self.Math===Math?self:typeof window<"u"&&window.Math===Math?window:Function("return this")()}(),I=function(){return typeof requestAnimationFrame=="function"?requestAnimationFrame.bind(p):function(e){return setTimeout(function(){return e(Date.now())},1e3/60)}}(),X=2;function B(e,t){var n=!1,o=!1,r=0;function i(){n&&(n=!1,e()),o&&c()}function s(){I(i)}function c(){var a=Date.now();if(n){if(a-r<X)return;o=!0}else n=!0,o=!1,setTimeout(s,t);r=a}return c}var G=20,P=["top","right","bottom","left","width","height","size","weight"],V=typeof MutationObserver<"u",J=function(){function e(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=B(this.refresh.bind(this),G)}return e.prototype.addObserver=function(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()},e.prototype.removeObserver=function(t){var n=this.observers_,o=n.indexOf(t);~o&&n.splice(o,1),!n.length&&this.connected_&&this.disconnect_()},e.prototype.refresh=function(){var t=this.updateObservers_();t&&this.refresh()},e.prototype.updateObservers_=function(){var t=this.observers_.filter(function(n){return n.gatherActive(),n.hasActive()});return t.forEach(function(n){return n.broadcastActive()}),t.length>0},e.prototype.connect_=function(){!y||this.connected_||(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),V?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},e.prototype.disconnect_=function(){!y||!this.connected_||(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},e.prototype.onTransitionEnd_=function(t){var n=t.propertyName,o=n===void 0?"":n,r=P.some(function(i){return!!~o.indexOf(i)});r&&this.refresh()},e.getInstance=function(){return this.instance_||(this.instance_=new e),this.instance_},e.instance_=null,e}(),T=function(e,t){for(var n=0,o=Object.keys(t);n<o.length;n++){var r=o[n];Object.defineProperty(e,r,{value:t[r],enumerable:!1,writable:!1,configurable:!0})}return e},h=function(e){var t=e&&e.ownerDocument&&e.ownerDocument.defaultView;return t||p},$=v(0,0,0,0);function m(e){return parseFloat(e)||0}function L(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return t.reduce(function(o,r){var i=e["border-"+r+"-width"];return o+m(i)},0)}function K(e){for(var t=["top","right","bottom","left"],n={},o=0,r=t;o<r.length;o++){var i=r[o],s=e["padding-"+i];n[i]=m(s)}return n}function Q(e){var t=e.getBBox();return v(0,0,t.width,t.height)}function U(e){var t=e.clientWidth,n=e.clientHeight;if(!t&&!n)return $;var o=h(e).getComputedStyle(e),r=K(o),i=r.left+r.right,s=r.top+r.bottom,c=m(o.width),a=m(o.height);if(o.boxSizing==="border-box"&&(Math.round(c+i)!==t&&(c-=L(o,"left","right")+i),Math.round(a+s)!==n&&(a-=L(o,"top","bottom")+s)),!ee(e)){var u=Math.round(c+i)-t,l=Math.round(a+s)-n;Math.abs(u)!==1&&(c-=u),Math.abs(l)!==1&&(a-=l)}return v(r.left,r.top,c,a)}var Z=function(){return typeof SVGGraphicsElement<"u"?function(e){return e instanceof h(e).SVGGraphicsElement}:function(e){return e instanceof h(e).SVGElement&&typeof e.getBBox=="function"}}();function ee(e){return e===h(e).document.documentElement}function te(e){return y?Z(e)?Q(e):U(e):$}function ne(e){var t=e.x,n=e.y,o=e.width,r=e.height,i=typeof DOMRectReadOnly<"u"?DOMRectReadOnly:Object,s=Object.create(i.prototype);return T(s,{x:t,y:n,width:o,height:r,top:n,right:t+o,bottom:r+n,left:t}),s}function v(e,t,n,o){return{x:e,y:t,width:n,height:o}}var oe=function(){function e(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=v(0,0,0,0),this.target=t}return e.prototype.isActive=function(){var t=te(this.target);return this.contentRect_=t,t.width!==this.broadcastWidth||t.height!==this.broadcastHeight},e.prototype.broadcastRect=function(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t},e}(),re=function(){function e(t,n){var o=ne(n);T(this,{target:t,contentRect:o})}return e}(),ie=function(){function e(t,n,o){if(this.activeObservations_=[],this.observations_=new k,typeof t!="function")throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=t,this.controller_=n,this.callbackCtx_=o}return e.prototype.observe=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(t instanceof h(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var n=this.observations_;n.has(t)||(n.set(t,new oe(t)),this.controller_.addObserver(this),this.controller_.refresh())}},e.prototype.unobserve=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if(!(typeof Element>"u"||!(Element instanceof Object))){if(!(t instanceof h(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var n=this.observations_;n.has(t)&&(n.delete(t),n.size||this.controller_.removeObserver(this))}},e.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},e.prototype.gatherActive=function(){var t=this;this.clearActive(),this.observations_.forEach(function(n){n.isActive()&&t.activeObservations_.push(n)})},e.prototype.broadcastActive=function(){if(this.hasActive()){var t=this.callbackCtx_,n=this.activeObservations_.map(function(o){return new re(o.target,o.broadcastRect())});this.callback_.call(t,n,t),this.clearActive()}},e.prototype.clearActive=function(){this.activeObservations_.splice(0)},e.prototype.hasActive=function(){return this.activeObservations_.length>0},e}(),A=typeof WeakMap<"u"?new WeakMap:new k,D=function(){function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var n=J.getInstance(),o=new ie(t,n,this);A.set(this,o)}return e}();["observe","unobserve","disconnect"].forEach(function(e){D.prototype[e]=function(){var t;return(t=A.get(this))[e].apply(t,arguments)}}),function(){return typeof p.ResizeObserver<"u"?p.ResizeObserver:D}();function se(e,t,n){if(!Y(e))throw new Error(`Element(${e})not DOM.`);const o=e;let r={offsetX:0,offsetY:0};const i=a=>{o.style.position="relative";const u=a.clientX,l=a.clientY,{offsetX:E,offsetY:x}=r,b=o.getBoundingClientRect(),z=b.left,R=b.top,de=b.width,he=b.height,{clientWidth:fe}=document.documentElement,{clientHeight:pe}=document.documentElement,j=N=>{let O=E+N.clientX-u,M=x+N.clientY-l;const me=-z+E,ve=-R+x,be=fe-z-de+E,ge=pe-R-he+x;t||(O=Math.min(Math.max(O,me),be),M=Math.min(Math.max(M,ve),ge)),r={offsetX:O,offsetY:M},o.style.transform=`translate(${r.offsetX||0}px, ${r.offsetY||0}px)`},H=()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",H)};document.addEventListener("mousemove",j),document.addEventListener("mouseup",H)},s=()=>{o.addEventListener("mousedown",i)},c=()=>{o.removeEventListener("mousedown",i),o.style.position="static"};return new IntersectionObserver(a=>{if(a[0].intersectionRatio<=0){c();return}s()}).observe(o),r}function ae(e=!1){return`
<style>
:host {
${e?`
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;`:""}
--monospace: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--red: #ff5555;
--yellow: #e2aa53;
--purple: #cfa4ff;
--cyan: #2dd9da;
--dim: #c9c9c9;
${e?`
--window-background: #181818;
--window-color: #d8d8d8;`:""}
}
.backdrop {
${e?`
position: fixed;
z-index: 99999;
top: 0;
left: 0;`:""}
width: 100%;
height: 100%;
overflow-y: scroll;
margin: 0;
${e?"background: rgba(0, 0, 0, 0.66);":""}
background: rgba(0, 0, 0, 0.66);
}
.window {
font-family: var(--monospace);
line-height: 1.5;
${e?"width: 800px;":"width: 100%"}
color: var(--window-color);
${e?"margin: 30px auto;":""}
padding: 25px 40px;
position: relative;
background: var(--window-background);
border-radius: 6px 6px 8px 8px;
overflow: hidden;
border-top: 8px solid var(--red);
direction: ltr;
text-align: left;
}
pre {
font-family: var(--monospace);
font-size: 16px;
margin-top: 0;
margin-bottom: 1em;
overflow-x: scroll;
scrollbar-width: none;
}
pre::-webkit-scrollbar {
display: none;
}
pre.frame::-webkit-scrollbar {
display: block;
height: 5px;
}
pre.frame::-webkit-scrollbar-thumb {
background: #999;
border-radius: 5px;
}
pre.frame {
scrollbar-width: thin;
}
.message {
line-height: 1.3;
font-weight: 600;
white-space: pre-wrap;
}
.message-body {
color: var(--red);
}
.plugin {
color: var(--purple);
}
.file {
color: var(--cyan);
margin-bottom: 0;
white-space: pre-wrap;
word-break: break-all;
}
.frame {
color: var(--yellow);
}
.stack {
font-size: 13px;
color: var(--dim);
}
.tip {
font-size: 13px;
color: #999;
border-top: 1px dotted #999;
padding-top: 13px;
line-height: 1.8;
}
code {
font-size: 13px;
font-family: var(--monospace);
color: var(--yellow);
}
.file-link {
text-decoration: underline;
cursor: pointer;
}
a {
color: var(--dim);
}
kbd {
line-height: 1.5;
font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 0.75rem;
font-weight: 700;
background-color: rgb(38, 40, 44);
color: rgb(166, 167, 171);
padding: 0.15rem 0.3rem;
border-radius: 0.25rem;
border-width: 0.0625rem 0.0625rem 0.1875rem;
border-style: solid;
border-color: rgb(54, 57, 64);
border-image: initial;
}
</style>
<div class="backdrop" part="backdrop">
<div class="window" part="window">
<pre class="message" part="message"><span class="plugin" part="plugin"></span><span class="message-body" part="message-body"></span></pre>
<pre class="file" part="file"></pre>
<pre class="frame" part="frame"></pre>
<pre class="stack" part="stack"></pre>
<div class="tip" part="tip">
Click outside, press <kbd>Esc</kbd> key, or fix the code to dismiss.
</div>
</div>
</div>
`}const S=/(?:[a-z]:\\|\/).*?:\d+:\d+/gi,w=/^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm,{HTMLElement:ce=class{}}=globalThis;let ue=class extends ce{constructor(e,t=!1,n=!0){var o,r,i;super(),g(this,"root"),g(this,"closeOnEsc"),g(this,"dialog"),this.root=this.attachShadow({mode:"open"}),this.root.innerHTML=ae(t),this.dialog=t,t||this.closeText(),w.lastIndex=0;const s=e.frame&&w.test(e.frame),c=s?e.message.replaceAll(w,""):e.message;e.plugin&&this.text(".plugin",`[plugin:${e.plugin}] `),this.text(".message-body",c.trim());const[a]=(((o=e.loc)==null?void 0:o.file)||e.id||"unknown file").split("?");e.loc?this.text(".file",`${a}:${e.loc.line}:${e.loc.column}`,n):e.id&&this.text(".file",a),s&&this.text(".frame",((r=e.frame)==null?void 0:r.trim())||""),this.text(".stack",e.stack,n),(i=this.root.querySelector(".window"))==null||i.addEventListener("click",u=>{u.stopPropagation()}),this.addEventListener("click",()=>{this.close()}),this.closeOnEsc=u=>{(u.key==="Escape"||u.code==="Escape")&&this.close()},document.addEventListener("keydown",this.closeOnEsc)}text(e,t,n=!1){const o=this.root.querySelector(e);if(n){let r=0,i;for(S.lastIndex=0;i=S.exec(t);){const{0:s,index:c}=i;if(c!=null){const a=t.slice(r,c),u=document.location.protocol+s;o.append(document.createTextNode(a));const l=document.createElement("a");l.textContent=s,l.className="file-link",l.href=u,l.target="_blank",o.append(l),r+=a.length+s.length}}}else o.textContent=t}closeText(){const e=this.root.querySelector(".tip");e.style.display="none"}close(){var e;this.dialog&&((e=this.parentNode)==null||e.removeChild(this),document.removeEventListener("keydown",this.closeOnEsc))}};const C="imitation-vue-error",{customElements:_}=globalThis;_&&!_.get(C)&&_.define(C,ue),customElements.get("imitation-vue-error");function le(e){e.directive("directiveDraggable",{mounted(t,n){se(t,n.value)}})}d.directiveConversionTime=q,d.directiveDraggable=le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});