@idraw/util 0.2.0-alpha.20 → 0.2.0-alpha.24

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.js CHANGED
@@ -274,6 +274,9 @@ var Context = (function () {
274
274
  scrollY: 0,
275
275
  };
276
276
  }
277
+ Context.prototype.getContext = function () {
278
+ return this._ctx;
279
+ };
277
280
  Context.prototype.resetSize = function (opts) {
278
281
  this._opts = __assign(__assign({}, this._opts), opts);
279
282
  };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare class Context implements TypeContext {
8
8
  private _ctx;
9
9
  private _transform;
10
10
  constructor(ctx: CanvasRenderingContext2D, opts: Options);
11
+ getContext(): CanvasRenderingContext2D;
11
12
  resetSize(opts: TypeBoardSizeOptions): void;
12
13
  calcDeviceNum(num: number): number;
13
14
  calcScreenNum(num: number): number;
package/dist/index.es.js CHANGED
@@ -272,6 +272,9 @@ var Context = (function () {
272
272
  scrollY: 0,
273
273
  };
274
274
  }
275
+ Context.prototype.getContext = function () {
276
+ return this._ctx;
277
+ };
275
278
  Context.prototype.resetSize = function (opts) {
276
279
  this._opts = __assign(__assign({}, this._opts), opts);
277
280
  };
@@ -275,6 +275,9 @@ var iDrawUtil = (function () {
275
275
  scrollY: 0,
276
276
  };
277
277
  }
278
+ Context.prototype.getContext = function () {
279
+ return this._ctx;
280
+ };
278
281
  Context.prototype.resetSize = function (opts) {
279
282
  this._opts = __assign(__assign({}, this._opts), opts);
280
283
  };
@@ -1 +1 @@
1
- var iDrawUtil=function(){'use strict';function t(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function e(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var n={type:function(t,n){var o=e(t);return!0===n?o.toLocaleLowerCase():o},array:function(t){return'Array'===e(t)},json:function(t){return'Object'===e(t)},function:function(t){return'Function'===e(t)},asyncFunction:function(t){return'AsyncFunction'===e(t)},string:function(t){return'String'===e(t)},number:function(t){return'Number'===e(t)},undefined:function(t){return'Undefined'===e(t)},null:function(t){return'Null'===e(t)},promise:function(t){return'Promise'===e(t)}},o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function c(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}u((o=o.apply(t,e||[])).next())}))}function i(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(t,e){var n=e.width,o=e.height;return new Promise((function(e,r){var i=new Blob(["\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\""+(n||'')+"\" height = \""+(o||'')+"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n "+t+"\n </div>\n </foreignObject>\n </svg>\n "],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(i),s.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},s.onerror=function(t){r(t)}}))}function c(t){return new Promise((function(e,n){var o=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},r.onerror=function(t){n(t)}}))}var u=window.Image;function a(t){return new Promise((function(e,n){var o=new u;o.onload=function(){e(o)},o.onabort=n,o.onerror=n,o.src=t}))}var h=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.resetSize=function(t){this._opts=o(o({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=o(o({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,n,o,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(n),o,r,i)},t.prototype.rect=function(t,e,n,o){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.fillRect=function(t,e,n,o){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.clearRect=function(t,e,n,o){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,n,o,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=t[1],r=t[2],i=t[3],s=t[4],c=t[t.length-4],u=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(n,this._doSize(o),this._doSize(r),this._doSize(i),this._doSize(s),this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h)):this._ctx.drawImage(n,this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,n,o){return void 0!==o?this._ctx.fillText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.fillText(t,this._doSize(e),this._doSize(n))},t.prototype.strokeText=function(t,e,n,o){return void 0!==o?this._ctx.strokeText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.strokeText(t,this._doSize(e),this._doSize(n))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push(""+t.fontWeight),e.push(this._doSize(t.fontSize||12)+"px"),e.push(""+(t.fontFamily||'sans-serif')),this._ctx.font=""+e.join(' ')},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,n,o,r,i,s,c){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),r,i,s,c)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollX)/n;return this._doSize(o)},t.prototype._doY=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollY)/n;return this._doSize(o)},t}();function l(t){return'number'==typeof t&&(t>0||t<=0)}function f(t){return'number'==typeof t&&t>=0}function p(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(""+t)}function d(t){return'string'==typeof t&&/^(data:image\/)/.test(""+t)}var _={x:function(t){return l(t)},y:function(t){return l(t)},w:f,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:l,borderWidth:function(t){return f(t)},borderRadius:function(t){return l(t)&&t>=0},color:function(e){return t(e)},imageSrc:function(t){return d(t)||p(t)},imageURL:p,imageBase64:d,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test((""+t).trim())&&/<\/[\s]{0,}svg>$/i.test((""+t).trim())},html:function(t){var e=!1;if('string'==typeof t){var n=document.createElement('div');n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return l(t)&&t>0},lineHeight:function(t){return l(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return l(t)&&t>0}};function y(t){void 0===t&&(t={});var e=t.borderColor,n=t.borderRadius,o=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!_.number(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))}var g={attrs:function(t){var e=t.x,n=t.y,o=t.w,r=t.h,i=t.angle;return!!(_.x(e)&&_.y(n)&&_.w(o)&&_.h(r)&&_.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,n=t.color,o=t.fontSize,r=t.lineHeight,i=t.fontFamily,s=t.textAlign,c=t.fontWeight,u=t.bgColor,a=t.strokeWidth,h=t.strokeColor;return!!_.text(e)&&(!!_.color(n)&&(!!_.fontSize(o)&&(!(t.hasOwnProperty('bgColor')&&!_.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!_.fontWeight(c))&&(!(t.hasOwnProperty('lineHeight')&&!_.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!_.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!_.textAlign(s))&&(!(t.hasOwnProperty('strokeWidth')&&!_.strokeWidth(a))&&(!(t.hasOwnProperty('strokeColor')&&!_.color(h))&&!!y(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&!!y(t)},circleDesc:function(t){var e=t.bgColor,n=t.borderColor,o=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderColor')&&!_.color(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))},imageDesc:function(t){var e=t.src;return!!_.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!_.svg(e)},htmlDesc:function(t){var e=t.html;return!!_.html(e)}},v={is:_,check:g,time:{delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,n){return function o(r){var i=t[r];r===t.length&&n&&(i=n);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,o.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var n=-1;return function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];n>0||(n=setTimeout((function(){t.apply(void 0,o),n=-1}),e))}}},loader:{loadImage:a,loadSVG:function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,c(t)];case 1:return[4,a(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,s(t,e)];case 1:return[4,a(n.sent())];case 2:return[2,n.sent()]}}))}))}},file:{downloadImageFromCanvas:function(t,e){var n=e.filename,o=e.type,r=void 0===o?'image/jpeg':o,i=t.toDataURL(r),s=document.createElement('a');s.href=i,s.download=n;var c=document.createEvent('MouseEvents');c.initEvent('click',!0,!1),s.dispatchEvent(c)}},color:{toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:t},uuid:{createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return""+t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()}},istype:n,data:{deepClone:function(t){return function t(e){var n,o=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(o)>=0)return e;if('Array'===o){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===o){var i={};return Object.keys(e).forEach((function(n){i[n]=t(e[n])})),i}}(t)}},Context:h};return v}();
1
+ var iDrawUtil=function(){'use strict';function t(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function e(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var n={type:function(t,n){var o=e(t);return!0===n?o.toLocaleLowerCase():o},array:function(t){return'Array'===e(t)},json:function(t){return'Object'===e(t)},function:function(t){return'Function'===e(t)},asyncFunction:function(t){return'AsyncFunction'===e(t)},string:function(t){return'String'===e(t)},number:function(t){return'Number'===e(t)},undefined:function(t){return'Undefined'===e(t)},null:function(t){return'Null'===e(t)},promise:function(t){return'Promise'===e(t)}},o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},o.apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function c(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}u((o=o.apply(t,e||[])).next())}))}function i(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(t,e){var n=e.width,o=e.height;return new Promise((function(e,r){var i=new Blob(["\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\""+(n||'')+"\" height = \""+(o||'')+"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n "+t+"\n </div>\n </foreignObject>\n </svg>\n "],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(i),s.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},s.onerror=function(t){r(t)}}))}function c(t){return new Promise((function(e,n){var o=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var n,o=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.result;e(o)},r.onerror=function(t){n(t)}}))}var u=window.Image;function a(t){return new Promise((function(e,n){var o=new u;o.onload=function(){e(o)},o.onabort=n,o.onerror=n,o.src=t}))}var h=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=o(o({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=o(o({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,n,o,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(n),o,r,i)},t.prototype.rect=function(t,e,n,o){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.fillRect=function(t,e,n,o){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.clearRect=function(t,e,n,o){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,n,o,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=t[0],o=t[1],r=t[2],i=t[3],s=t[4],c=t[t.length-4],u=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(n,this._doSize(o),this._doSize(r),this._doSize(i),this._doSize(s),this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h)):this._ctx.drawImage(n,this._doSize(c),this._doSize(u),this._doSize(a),this._doSize(h))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,n,o){return void 0!==o?this._ctx.fillText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.fillText(t,this._doSize(e),this._doSize(n))},t.prototype.strokeText=function(t,e,n,o){return void 0!==o?this._ctx.strokeText(t,this._doSize(e),this._doSize(n),this._doSize(o)):this._ctx.strokeText(t,this._doSize(e),this._doSize(n))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push(""+t.fontWeight),e.push(this._doSize(t.fontSize||12)+"px"),e.push(""+(t.fontFamily||'sans-serif')),this._ctx.font=""+e.join(' ')},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,n,o,r,i,s,c){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(n),this._doSize(o),r,i,s,c)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollX)/n;return this._doSize(o)},t.prototype._doY=function(t){var e=this._transform,n=e.scale,o=(t-e.scrollY)/n;return this._doSize(o)},t}();function l(t){return'number'==typeof t&&(t>0||t<=0)}function f(t){return'number'==typeof t&&t>=0}function p(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(""+t)}function d(t){return'string'==typeof t&&/^(data:image\/)/.test(""+t)}var _={x:function(t){return l(t)},y:function(t){return l(t)},w:f,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:l,borderWidth:function(t){return f(t)},borderRadius:function(t){return l(t)&&t>=0},color:function(e){return t(e)},imageSrc:function(t){return d(t)||p(t)},imageURL:p,imageBase64:d,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test((""+t).trim())&&/<\/[\s]{0,}svg>$/i.test((""+t).trim())},html:function(t){var e=!1;if('string'==typeof t){var n=document.createElement('div');n.innerHTML=t,n.children.length>0&&(e=!0),n=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return l(t)&&t>0},lineHeight:function(t){return l(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return l(t)&&t>0}};function y(t){void 0===t&&(t={});var e=t.borderColor,n=t.borderRadius,o=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!_.number(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))}var g={attrs:function(t){var e=t.x,n=t.y,o=t.w,r=t.h,i=t.angle;return!!(_.x(e)&&_.y(n)&&_.w(o)&&_.h(r)&&_.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,n=t.color,o=t.fontSize,r=t.lineHeight,i=t.fontFamily,s=t.textAlign,c=t.fontWeight,u=t.bgColor,a=t.strokeWidth,h=t.strokeColor;return!!_.text(e)&&(!!_.color(n)&&(!!_.fontSize(o)&&(!(t.hasOwnProperty('bgColor')&&!_.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!_.fontWeight(c))&&(!(t.hasOwnProperty('lineHeight')&&!_.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!_.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!_.textAlign(s))&&(!(t.hasOwnProperty('strokeWidth')&&!_.strokeWidth(a))&&(!(t.hasOwnProperty('strokeColor')&&!_.color(h))&&!!y(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&!!y(t)},circleDesc:function(t){var e=t.bgColor,n=t.borderColor,o=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!_.color(e))&&(!(t.hasOwnProperty('borderColor')&&!_.color(n))&&!(t.hasOwnProperty('borderWidth')&&!_.number(o)))},imageDesc:function(t){var e=t.src;return!!_.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!_.svg(e)},htmlDesc:function(t){var e=t.html;return!!_.html(e)}},v={is:_,check:g,time:{delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,n){return function o(r){var i=t[r];r===t.length&&n&&(i=n);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,o.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var n=-1;return function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];n>0||(n=setTimeout((function(){t.apply(void 0,o),n=-1}),e))}}},loader:{loadImage:a,loadSVG:function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,c(t)];case 1:return[4,a(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,s(t,e)];case 1:return[4,a(n.sent())];case 2:return[2,n.sent()]}}))}))}},file:{downloadImageFromCanvas:function(t,e){var n=e.filename,o=e.type,r=void 0===o?'image/jpeg':o,i=t.toDataURL(r),s=document.createElement('a');s.href=i,s.download=n;var c=document.createEvent('MouseEvents');c.initEvent('click',!0,!1),s.dispatchEvent(c)}},color:{toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:t},uuid:{createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return""+t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()}},istype:n,data:{deepClone:function(t){return function t(e){var n,o=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(o)>=0)return e;if('Array'===o){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===o){var i={};return Object.keys(e).forEach((function(n){i[n]=t(e[n])})),i}}(t)}},Context:h};return v}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idraw/util",
3
- "version": "0.2.0-alpha.20",
3
+ "version": "0.2.0-alpha.24",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -10,7 +10,8 @@
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
12
  "files": [
13
- "dist"
13
+ "dist/*.ts",
14
+ "dist/*.js"
14
15
  ],
15
16
  "repository": {
16
17
  "type": "git",
@@ -23,10 +24,10 @@
23
24
  "author": "chenshenhai",
24
25
  "license": "MIT",
25
26
  "devDependencies": {
26
- "@idraw/types": "^0.2.0-alpha.20"
27
+ "@idraw/types": "^0.2.0-alpha.24"
27
28
  },
28
29
  "publishConfig": {
29
30
  "access": "public"
30
31
  },
31
- "gitHead": "d2340084ef92bd3637e8c7727b31e875864f13c8"
32
+ "gitHead": "70860fa58b898e9f8e7dbac1e46edd1ddf2dd461"
32
33
  }