quarkd
Version:
Mobile UI Components built on Web Components.
2 lines (1 loc) • 3.4 kB
JavaScript
import{_ as t,a as e}from"../typeof.js";import{_ as r,a as n,b as o,c as i,P as a,H as s,d as c,N as h,O as p,B as u}from"../index2.js";import{_ as f}from"../defineProperty.js";import"../loading/index.js";function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var o,i=r(t);if(e){var a=r(this).constructor;o=Reflect.construct(i,arguments,a)}else o=i.apply(this,arguments);return n(this,o)}}var d=function(r){o(c,s);var n=l(c);function c(){var e;t(this,c);for(var r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];return e=n.call.apply(n,[this].concat(o)),f(i(e),"width",120),f(i(e),"height",64),f(i(e),"rotate",-22),f(i(e),"fontsize",14),f(i(e),"fontcolor","rgba(0, 0, 0, .15)"),f(i(e),"gapx",24),f(i(e),"gapy",48),f(i(e),"init",!1),f(i(e),"waterMarkRef",a()),e}return e(c,[{key:"paint",value:function(){var t=this;if(this.waterMarkRef&&this.waterMarkRef.current){var e=this.waterMarkRef.current,r=document.createElement("canvas"),n=window.devicePixelRatio,o=r.getContext("2d"),i=this.fontsize*n,a="".concat((this.gapx+this.width)*n,"px"),s="".concat((this.gapy+this.height)*n,"px"),c=this.width*n,h=this.height*n;if(r.setAttribute("width",a),r.setAttribute("height",s),!o)throw new Error("Canvas is not supported in the current environment");if(this.image){o.translate(c/2,h/2),o.rotate(Math.PI/180*this.rotate);var p=new Image;p.alt="",p.crossOrigin="anonymous",p.referrerPolicy="no-referrer",p.onload=function(){o.drawImage(p,-t.width*n/2,-t.height*n/2,t.width*n,t.height*n),o.restore(),e.style.backgroundSize="".concat(t.gapx+t.width,"px"),e.style.backgroundImage="url('".concat(r.toDataURL(),"')")},p.src=this.image}else this.content&&(o.textBaseline="middle",o.textAlign="center",o.translate(c/2,h/2),o.rotate(Math.PI/180*this.rotate),o.font="".concat(i,"px normal normal"),o.fillStyle=this.fontcolor,Array.isArray(this.content)?this.content.forEach((function(t,e){return o.fillText(t,0,e*i)})):o.fillText(this.content,0,0),e.style.backgroundSize="".concat(this.gapx+this.width,"px"),e.style.backgroundImage="url('".concat(r.toDataURL(),"')"))}}},{key:"setText",value:function(t){this.content=t,this.image=null,this.paint()}},{key:"componentDidMount",value:function(){this.paint(),this.init=!0}},{key:"shouldComponentUpdate",value:function(t,e,r){return"text"===t&&e!==r&&(this.content=r),this.init&&this.paint(),!0}},{key:"render",value:function(){return s.h("div",{ref:this.waterMarkRef,class:"quark-watermark",part:"root"})}}]),c}();c([h({type:Number})],d.prototype,"width",void 0),c([h({type:Number})],d.prototype,"height",void 0),c([h({type:Number})],d.prototype,"rotate",void 0),c([h({type:Number})],d.prototype,"fontsize",void 0),c([h()],d.prototype,"fontcolor",void 0),c([h()],d.prototype,"image",void 0),c([h()],d.prototype,"text",void 0),c([h({type:Number})],d.prototype,"gapx",void 0),c([h({type:Number})],d.prototype,"gapy",void 0),c([p()],d.prototype,"content",void 0);var y=d=c([u({tag:"quark-watermark",style:".quark-watermark {\n position: fixed;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n pointer-events: none;\n background-repeat: repeat;\n z-index: var(--watermark-z-index, 2000);\n}\n"})],d);export{y as default};