| 1234 |
- "use strict";/*!vue3-sketch-ruler v1.3.62022年11月Fri Nov 04 2022 18:18:02 GMT+0800 (中国标准时间)制作*/Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=require("vue-demi"),n=require("vue");var S=(e,t)=>{const r=e.__vccOpts||e;for(const[s,u]of t)r[s]=u;return r};const U=c.defineComponent({name:"LineRuler",props:{scale:Number,thick:Number,palette:Object,index:Number,start:Number,vertical:Boolean,value:Number,isShowReferLine:Boolean},emits:["onMouseDown","onRelease","onRemove"],setup(e,{emit:t}){const r=c.ref(0),s=c.ref(!0);c.onMounted(()=>{r.value=e.value});const u=o=>{s.value=o>=0},d=c.computed(()=>{const o=(r.value-e.start)*e.scale;u(o);const v=o+"px";return e.vertical?{top:v}:{left:v}}),l=c.computed(()=>{var m;const o=`1px solid ${(m=e.palette)==null?void 0:m.lineColor}`,v=e.vertical?{borderTop:o}:{borderLeft:o};return{cursor:e.isShowReferLine?e.vertical?"ns-resize":"ew-resize":"none",...v}}),h=c.computed(()=>e.vertical?{left:e.thick+"px"}:{top:e.thick+"px"});return{startValue:r,showLine:s,offset:d,borderCursor:l,actionStyle:h,handleDown:o=>{const v=e.vertical?o.clientY:o.clientX,f=r.value;t("onMouseDown");const m=A=>{const g=e.vertical?A.clientY:A.clientX,N=Math.round(f+(g-v)/e.scale);r.value=N},C=()=>{t("onRelease",r.value,e.index),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",C)},handleRemove:()=>{t("onRemove",e.index)}}}}),I={class:"value"};function X(e,t,r,s,u,d){return n.withDirectives((n.openBlock(),n.createElementBlock("div",{class:"line",style:n.normalizeStyle([e.offset,e.borderCursor]),onMousedown:t[1]||(t[1]=(...l)=>e.handleDown&&e.handleDown(...l))},[n.createElementVNode("div",{class:"action",style:n.normalizeStyle(e.actionStyle)},[n.createElementVNode("span",{class:"del",onClick:t[0]||(t[0]=(...l)=>e.handleRemove&&e.handleRemove(...l))},"\xD7"),n.createElementVNode("span",I,n.toDisplayString(e.startValue),1)],4)],36)),[[n.vShow,e.showLine]])}var z=S(U,[["render",X],["__scopeId","data-v-5dea28d6"]]);const T=e=>e<=.25?40:e<=.5?20:e<=1?10:e<=2?5:e<=4?2:1,L=.83,$=(e,t,r,s,u,d)=>{const{scale:l,width:h,height:i,ratio:a,palette:o}=u,{bgColor:v,fontColor:f,shadowColor:m,longfgColor:C,shortfgColor:A}=o;if(e.scale(a,a),e.clearRect(0,0,h,i),e.fillStyle=v,e.fillRect(0,0,h,i),s){const w=(r-t)*l,b=s*l;e.fillStyle=m,d?e.fillRect(w,0,b,i*3/8):e.fillRect(0,w,h*3/8,b)}const g=T(l),N=g*l,y=g*10,R=y*l,k=Math.floor(t/g)*g,B=Math.floor(t/y)*y,V=(k-t)/g*N,D=(B-t)/y*R,E=t+Math.ceil((d?h:i)/l);e.beginPath(),e.fillStyle=f,e.strokeStyle=C;for(let w=B,b=0;w<E;w+=y,b++){const p=D+b*R+.5;d?e.moveTo(p,0):e.moveTo(0,p),e.save(),d?e.translate(p,i*.4):e.translate(h*.4,p),d||e.rotate(-Math.PI/2),e.scale(L/a,L/a),e.fillText(w.toString(),4*a,7*a),e.restore(),d?e.lineTo(p,i*9/16):e.lineTo(h*9/16,p)}e.stroke(),e.closePath(),e.beginPath(),e.strokeStyle=A;for(let w=k,b=0;w<E;w+=g,b++){const p=V+b*N+.5;d?e.moveTo(p,0):e.moveTo(0,p),w%y!==0&&(d?e.lineTo(p,i*1/4):e.lineTo(h*1/4,p))}e.stroke(),e.closePath(),e.setTransform(1,0,0,1,0,0)},F=c.defineComponent({name:"CanvasRuler",props:{showIndicator:Boolean,valueNum:Number,scale:Number,ratio:Number,palette:Object,vertical:Boolean,start:Number,width:Number,height:Number,selectStart:Number,selectLength:Number},emits:["onAddLine","update:showIndicator","update:valueNum"],setup(e,{emit:t}){const r=c.reactive({canvasContext:null});let s=1;const u=c.ref(null);c.onMounted(()=>{s=e.ratio||window.devicePixelRatio||1,d(),l(s),h(s)});const d=()=>{r.canvasContext=u.value&&u.value.getContext("2d")},l=a=>{if(u.value){u.value.width=e.width*a,u.value.height=e.height*a;const o=r.canvasContext;o&&(o.font=`${12*a}px -apple-system,
- "Helvetica Neue", ".SFNSText-Regular",
- "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB",
- "Microsoft YaHei", "WenQuanYi Zen Hei", sans-serif`,o.lineWidth=1,o.textBaseline="middle")}},h=a=>{const o={scale:e.scale,width:e.width,height:e.height,palette:e.palette,ratio:a};r.canvasContext&&$(r.canvasContext,e.start,e.selectStart,e.selectLength,o,!e.vertical)};return c.watch(()=>e.start,()=>h(s)),c.watch([()=>e.width,()=>e.height],()=>{l(s),h(s)}),{handle:(a,o)=>{const v=(C,A,g)=>Math.round(A+C/g),f=e.vertical?a.offsetY:a.offsetX,m=v(f,e.start,e.scale);switch(o){case"click":t("onAddLine",m);break;case"enter":t("update:valueNum",m),t("update:showIndicator",!0);break;default:t("update:valueNum",m);break}},canvas:u}}});function M(e,t,r,s,u,d){return n.openBlock(),n.createElementBlock("canvas",{ref:"canvas",class:"ruler",onClick:t[0]||(t[0]=l=>e.handle(l,"click")),onMouseenter:t[1]||(t[1]=l=>e.handle(l,"enter")),onMousemove:t[2]||(t[2]=l=>e.handle(l,"move")),onMouseleave:t[3]||(t[3]=l=>e.$emit("update:showIndicator",!1))},null,544)}var Q=S(F,[["render",M]]);const K={scale:Number,ratio:Number,thick:Number,palette:Object,vertical:{type:Boolean,default:!0},width:{type:Number,default:200},height:{type:Number,default:200},start:{type:Number,default:0},lines:{type:Array,default:()=>[]},selectStart:{type:Number},selectLength:{type:Number},isShowReferLine:{type:Boolean}};const Y=c.defineComponent({name:"RulerWrapper",components:{CanvasRuler:Q,RulerLine:z},props:K,setup(e){const t=c.ref(!1),r=c.ref(0),s=c.computed(()=>e.vertical?"v-container":"h-container"),u=c.computed(()=>{const a={width:`calc(100% - ${e.thick}px)`,height:`${e.thick+1}px`,left:`${e.thick}px`},o={width:`${e.thick&&e.thick+1}px`,height:`calc(100% - ${e.thick}px)`,top:`${e.thick}px`};return e.vertical?o:a}),d=c.computed(()=>{var f;const a=(r.value-e.start)*e.scale;let o="top",v="borderLeft";return o=e.vertical?"top":"left",v=e.vertical?"borderBottom":"borderLeft",{[o]:a+"px",[v]:`1px solid ${(f=e.palette)==null?void 0:f.lineColor}`}}),l=a=>{e.lines.push(a)},h=(a,o)=>{const v=a-e.start,f=(e.vertical?e.height:e.width)/e.scale;v<0||v>f?i(o):e.lines[o]=a},i=a=>{e.lines.splice(a,1)};return{showIndicator:t,valueNum:r,rwClassName:s,rwStyle:u,indicatorStyle:d,handleNewLine:l,handleLineRelease:h,handleLineRemove:i}}}),P={class:"lines"},q={class:"value"};function G(e,t,r,s,u,d){const l=n.resolveComponent("CanvasRuler"),h=n.resolveComponent("RulerLine");return n.openBlock(),n.createElementBlock("div",{class:n.normalizeClass(e.rwClassName),style:n.normalizeStyle(e.rwStyle)},[n.createVNode(l,{vertical:e.vertical,scale:e.scale,width:e.width,height:e.height,start:e.start,ratio:e.ratio,"select-start":e.selectStart,"select-length":e.selectLength,palette:e.palette,valueNum:e.valueNum,"onUpdate:valueNum":t[0]||(t[0]=i=>e.valueNum=i),showIndicator:e.showIndicator,"onUpdate:showIndicator":t[1]||(t[1]=i=>e.showIndicator=i),onOnAddLine:e.handleNewLine},null,8,["vertical","scale","width","height","start","ratio","select-start","select-length","palette","valueNum","showIndicator","onOnAddLine"]),n.withDirectives(n.createElementVNode("div",P,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(e.lines,(i,a)=>(n.openBlock(),n.createBlock(h,{key:i+a,index:a,value:i>>0,scale:e.scale,start:e.start,thick:e.thick,palette:e.palette,vertical:e.vertical,"is-show-refer-line":e.isShowReferLine,onOnRemove:e.handleLineRemove,onOnRelease:e.handleLineRelease},null,8,["index","value","scale","start","thick","palette","vertical","is-show-refer-line","onOnRemove","onOnRelease"]))),128))],512),[[n.vShow,e.isShowReferLine]]),n.withDirectives(n.createElementVNode("div",{class:"indicator",style:n.normalizeStyle(e.indicatorStyle)},[n.createElementVNode("div",q,n.toDisplayString(e.valueNum),1)],4),[[n.vShow,e.showIndicator]])],6)}var H=S(Y,[["render",G],["__scopeId","data-v-b6c23352"]]);const W="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAAAXNSR0IArs4c6QAAAopJREFUOE/FlE9IVEEcx7+/N9ouds1Mu0QUSFZYdIgoUqQoKPBQHsKozpXE7jbTO/U8xLJvn6usBHWQ6hBFXupSkQeVbh0KJEPp0sH+eLGTsKs77xcj78m0ax0E8cHjzZv5zef3/c33xxA24KENYGJzoEEQbNNaN4Zh2OQ4znwYhr9c1/39vwrXVDo0NNS0tLR0GYB5D64BmAMwzMyvlFKz1es10Hw+f4mZ7wHYBeA9gNdENFepVOaEEM3M3OI4Thczn41gt6WUgQ3+C+r7/h0AWQD3mXnYqPA8L9nQ0HCemduIaFpKOWoAhUJhT6VSuQXgOjP3K6W8GLwKzeVyp4jonR0QBEErM48w8zFLyayUsjX+z+VyHhHdZebTSqkxM78CHRgYOKS1/ghgVErZY214RkQ7ADyRUj72ff8qgCtmXUrZGcf5vv8CwEUhxOF0Ov1pBRpla5dSdseBhUJhpznH6tIsZb1KqacW+BGArUaUXX63UuplHJTNZjuEEONSyhozfd/n6mQ1RkXZL2itz7mu+80EDA4ONi8vL/8AcM2UbikyR2BU9cSmmTU70YqKIAj2hWFo2uenlHK/BRg3Y2aeNO5GyU8S0ZbFxcUuz/NKEXAGQKPjOCcymcyX1dIi8DSAiWQyeaavr68cbSgCuBknYubnQoj+TCYzUywWE6VS6S2ADsdx2gxw1X3L7SNENMbMnwE8qK+vf5NKpRaMaeVyeW8ikfiaSqW+R7BuZr5BRMe11p2u607U9Gk8kc/ntzPzQwCmExYATDLzVBiGE0KIowAOADDf3QA+aK2VDaxRajto3K+rq+tl5nYAzQBamHmeiOYBTGmtR6ph/1Rqg9c73pz7dD1qN0TpHyNQRCUDJXrAAAAAAElFTkSuQmCC",Z="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAAAXNSR0IArs4c6QAAAjtJREFUOE/NlD9oFEEUxn9v9ghC0hpRUogIAUmniGAT/5Q2FrETPSNRJILg7RwimI0ox85eQFCEBGIUO1PYpFM0jSConQoBEZGgGPsgl+w+2eM2bC57SopAFqYZ3v7m+977ZoQt+GQLmGxPaBiGgYiMWWvXBHZUGoZhH3BERPYC+4F+4Keq/urt7b1RLpf/ZEBVHa9Wq0HWyg3QKIoGVPU8cA7wgK/pUtXPQJ8xZk+pVBpuNBqXUoUiEvi+P56fzTpo6+SbwHNg1lo7WzTITGEKXFlZeeB53tVCpa3CK8AFa+1cBgvD8LKIXAQOJkkyICJDeYVBEJS6u7s/qeoLa+1o+l9TqXNuBLhmjDlbqVQ+5ICjInIfOBPH8W9jzGCR5YmJiRNxHM+papgqzqDvgSlr7VTernPuO3An3c9bBt74vv+yrdaKyLDv+/1Sq9UGPc97nY9EVuycU2AQOA7cAm4Dr4D5TvVxHB9rKo2iaEFVp621Ln96FEUngaOqGmSxabVqsh3a2h+x1h5qQjNrae/yE4+iaCwDJkky73neTuBZe129Xk+H+BS4l7ZqLVIZ2BhzuFKpvMsDVXXWGPMxFdAedOfcKeCRqj7MYrUhpz09PfXl5eXrectFWXXODQHpOq2qd/95o/JXr6ura3J1dXU6SZIfwKKIHAD2tVYMPBGRx77vN10UXtO85fTkmZmZHUtLSzUR2QXsBhaAL6r6DXhbrVYXi1yss59GqOgub/bN3Z7v6X/tb9Zmp/q/kN8s+lJb8oEAAAAASUVORK5CYII=",j={eyeIcon:{type:String},closeEyeIcon:{type:String},scale:{type:Number,default:1},ratio:{type:Number},thick:{type:Number,default:16},palette:Object,startX:{type:Number},startY:{type:Number,default:0},width:{type:Number,default:200},height:{type:Number,default:200},shadow:{type:Object,default:()=>({x:0,y:0,width:0,height:0})},lines:{type:Object,default:()=>({h:[],v:[]})},isShowReferLine:{type:Boolean,default:!0}};const J=c.defineComponent({name:"SketchRule",components:{RulerWrapper:H},props:j,emits:["onCornerClick"],setup(e,{emit:t}){let r=c.ref(!0);r.value=e.isShowReferLine;const s=c.computed(()=>{function l(i,a){return Object.keys(i).forEach(o=>{o&&i.hasOwnProperty(o)&&(typeof a.key=="object"?i[o]=l(i[o],a[o]):a.hasOwnProperty(o)&&(i[o]=a[o]))}),i}return l({bgColor:"rgba(225,225,225, 0)",longfgColor:"#BABBBC",shortfgColor:"#C8CDD0",fontColor:"#7D8694",shadowColor:"#E8E8E8",lineColor:"#EB5648",borderColor:"#DADADC",cornerActiveColor:"rgb(235, 86, 72, 0.6)",menu:{bgColor:"#fff",dividerColor:"#DBDBDB",listItem:{textColor:"#415058",hoverTextColor:"#298DF8",disabledTextColor:"rgba(65, 80, 88, 0.4)",bgColor:"#fff",hoverBgColor:"#F2F2F2"}}},e.palette||{})}),u=c.computed(()=>({backgroundImage:r.value?`url(${e.eyeIcon||W})`:`url(${e.closeEyeIcon||Z})`,width:e.thick+"px",height:e.thick+"px",borderRight:`1px solid ${s.value.borderColor}`,borderBottom:`1px solid ${s.value.borderColor}`})),d=l=>{r.value=!r.value,t("onCornerClick",r.value)};return c.watch([()=>e.isShowReferLine],()=>{r.value=e.isShowReferLine}),{showReferLine:r,paletteCpu:s,cornerStyle:u,onCornerClick:d}}}),x={id:"mb-ruler",class:"style-ruler mb-ruler"};function _(e,t,r,s,u,d){const l=n.resolveComponent("RulerWrapper");return n.openBlock(),n.createElementBlock("div",x,[n.createVNode(l,{vertical:!1,width:e.width,height:e.thick,"is-show-refer-line":e.showReferLine,thick:e.thick,ratio:e.ratio,start:e.startX,lines:e.lines.h,"select-start":e.shadow.x,"select-length":e.shadow.width,scale:e.scale,palette:e.paletteCpu},null,8,["width","height","is-show-refer-line","thick","ratio","start","lines","select-start","select-length","scale","palette"]),n.createVNode(l,{vertical:!0,width:e.thick,height:e.height,"is-show-refer-line":e.showReferLine,thick:e.thick,ratio:e.ratio,start:e.startY,lines:e.lines.v,"select-start":e.shadow.y,"select-length":e.shadow.height,scale:e.scale,palette:e.paletteCpu},null,8,["width","height","is-show-refer-line","thick","ratio","start","lines","select-start","select-length","scale","palette"]),n.createElementVNode("a",{class:"corner",style:n.normalizeStyle(e.cornerStyle),onClick:t[0]||(t[0]=(...h)=>e.onCornerClick&&e.onCornerClick(...h))},null,4)])}var O=S(J,[["render",_]]);exports.SketchRule=O;exports.default=O;
|