@leafer-in/export 1.3.0 → 1.3.2

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/export.cjs CHANGED
@@ -218,6 +218,7 @@ canvas.saveAs = function (filename, quality) {
218
218
  });
219
219
  };
220
220
 
221
+ draw.Plugin.add('export');
221
222
  Object.assign(draw.Export, ExportModule);
222
223
  draw.UI.prototype.export = function (filename, options) {
223
224
  return draw.Export.export(this, filename, options);
@@ -1,4 +1,4 @@
1
- import { Bounds, TwoPointBoundsHelper, FileHelper, TaskProcessor, Platform, Matrix, MathHelper, Creator, LeaferCanvasBase, Debug, Export, UI } from '@leafer-ui/draw';
1
+ import { Bounds, TwoPointBoundsHelper, FileHelper, TaskProcessor, Platform, Matrix, MathHelper, Creator, LeaferCanvasBase, Debug, Plugin, Export, UI } from '@leafer-ui/draw';
2
2
 
3
3
  /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
@@ -216,6 +216,7 @@ canvas.saveAs = function (filename, quality) {
216
216
  });
217
217
  };
218
218
 
219
+ Plugin.add('export');
219
220
  Object.assign(Export, ExportModule);
220
221
  UI.prototype.export = function (filename, options) {
221
222
  return Export.export(this, filename, options);
@@ -1 +1 @@
1
- import{Bounds as e,TwoPointBoundsHelper as t,FileHelper as n,TaskProcessor as o,Platform as i,Matrix as s,MathHelper as a,Creator as r,LeaferCanvasBase as c,Debug as l,Export as d,UI as u}from"@leafer-ui/draw";function h(e,t,n,o){return new(n||(n=Promise))((function(i,s){function a(e){try{c(o.next(e))}catch(e){s(e)}}function r(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:f,addPoint:p,toBounds:g}=t;const v={export(t,c,l){this.running=!0;const d=n.fileType(c),u=c.includes(".");return l=n.getExportOptions(l),function(e){w||(w=new o);return new Promise((t=>{w.add((()=>h(this,void 0,void 0,(function*(){return yield e(t)}))),{parallel:!1})}))}((o=>new Promise((v=>{const w=e=>{o(e),v(),this.running=!1},{toURL:m}=i,{download:y}=i.origin;if("json"===d)return u&&y(m(JSON.stringify(t.toJSON(l.json)),"text"),c),w({data:!!u||t.toJSON(l.json)});if("svg"===d)return u&&y(m(t.toSVG(),"svg"),c),w({data:!!u||t.toSVG()});const{leafer:_}=t;_?(x(t),_.waitViewCompleted((()=>h(this,void 0,void 0,(function*(){let o,i,d=1,u=1;const{worldTransform:h,isLeafer:v,isFrame:x}=t,{slice:m,trim:y,onCanvas:b}=l,S=void 0===l.smooth?_.config.smooth:l.smooth,R=l.contextSettings||_.config.contextSettings,B=l.screenshot||t.isApp,O=v&&B&&void 0===l.fill?t.fill:l.fill,P=n.isOpaqueImage(c)||O,X=new s;if(B)o=!0===B?v?_.canvas.bounds:t.worldRenderBounds:B;else{let e=l.relative||(v?"inner":"local");switch(d=h.scaleX,u=h.scaleY,e){case"inner":X.set(h);break;case"local":X.set(h).divide(t.localTransform),d/=t.scaleX,u/=t.scaleY;break;case"world":d=1,u=1;break;case"page":e=t.leafer;default:X.set(h).divide(t.getTransform(e));const n=e.worldTransform;d/=d/n.scaleX,u/=u/n.scaleY}o=t.getBounds("render",e)}const Y={scaleX:1,scaleY:1};a.getScaleData(l.scale,l.size,o,Y);let F=l.pixelRatio||1;t.isApp&&(Y.scaleX*=F,Y.scaleY*=F,F=t.app.pixelRatio);const{x:T,y:A,width:D,height:E}=new e(o).scale(Y.scaleX,Y.scaleY),L={matrix:X.scale(1/Y.scaleX,1/Y.scaleY).invert().translate(-T,-A).withScale(1/d*Y.scaleX,1/u*Y.scaleY)};let j,U=r.canvas({width:Math.round(D),height:Math.round(E),pixelRatio:F,smooth:S,contextSettings:R});if(m&&(j=t,j.__worldOpacity=0,t=_,L.bounds=U.bounds),U.save(),x&&void 0!==O){const e=t.get("fill");t.fill="",t.__render(U,L),t.fill=e}else t.__render(U,L);if(U.restore(),j&&j.__updateWorldOpacity(),y){i=function(t){const{width:n,height:o}=t.view,{data:i}=t.context.getImageData(0,0,n,o);let s,a,r,c=0;for(let e=0;e<i.length;e+=4)0!==i[e+3]&&(s=c%n,a=(c-s)/n,r?p(r,s,a):f(r={},s,a)),c++;const l=new e;return g(r,l),l.scale(1/t.pixelRatio).ceil()}(U);const t=U,{width:n,height:o}=i,s={x:0,y:0,width:n,height:o,pixelRatio:F};U=r.canvas(s),U.copyWorld(t,i,s)}P&&U.fillWorld(U.bounds,O||"#FFFFFF","destination-over"),b&&b(U);const W="canvas"===c?U:yield U.export(c,l);w({data:W,width:U.pixelWidth,height:U.pixelHeight,renderBounds:o,trimBounds:i})}))))):w({data:!1})}))))}};let w;function x(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>x(e)))}const m=c.prototype,y=l.get("@leafer-in/export");m.export=function(e,t){const{quality:o,blob:i}=n.getExportOptions(t);return e.includes(".")?this.saveAs(e,o):i?this.toBlob(e,o):this.toDataURL(e,o)},m.toBlob=function(e,t){return new Promise((n=>{i.origin.canvasToBolb(this.view,e,t).then((e=>{n(e)})).catch((e=>{y.error(e),n(null)}))}))},m.toDataURL=function(e,t){return i.origin.canvasToDataURL(this.view,e,t)},m.saveAs=function(e,t){return new Promise((n=>{i.origin.canvasSaveAs(this.view,e,t).then((()=>{n(!0)})).catch((e=>{y.error(e),n(!1)}))}))},Object.assign(d,v),u.prototype.export=function(e,t){return d.export(this,e,t)};
1
+ import{Bounds as e,TwoPointBoundsHelper as t,FileHelper as n,TaskProcessor as o,Platform as i,Matrix as s,MathHelper as a,Creator as r,LeaferCanvasBase as c,Debug as l,Plugin as d,Export as u,UI as h}from"@leafer-ui/draw";function f(e,t,n,o){return new(n||(n=Promise))((function(i,s){function a(e){try{c(o.next(e))}catch(e){s(e)}}function r(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:p,addPoint:g,toBounds:v}=t;const w={export(t,c,l){this.running=!0;const d=n.fileType(c),u=c.includes(".");return l=n.getExportOptions(l),function(e){x||(x=new o);return new Promise((t=>{x.add((()=>f(this,void 0,void 0,(function*(){return yield e(t)}))),{parallel:!1})}))}((o=>new Promise((h=>{const w=e=>{o(e),h(),this.running=!1},{toURL:x}=i,{download:y}=i.origin;if("json"===d)return u&&y(x(JSON.stringify(t.toJSON(l.json)),"text"),c),w({data:!!u||t.toJSON(l.json)});if("svg"===d)return u&&y(x(t.toSVG(),"svg"),c),w({data:!!u||t.toSVG()});const{leafer:_}=t;_?(m(t),_.waitViewCompleted((()=>f(this,void 0,void 0,(function*(){let o,i,d=1,u=1;const{worldTransform:h,isLeafer:f,isFrame:x}=t,{slice:m,trim:y,onCanvas:b}=l,S=void 0===l.smooth?_.config.smooth:l.smooth,R=l.contextSettings||_.config.contextSettings,B=l.screenshot||t.isApp,O=f&&B&&void 0===l.fill?t.fill:l.fill,P=n.isOpaqueImage(c)||O,X=new s;if(B)o=!0===B?f?_.canvas.bounds:t.worldRenderBounds:B;else{let e=l.relative||(f?"inner":"local");switch(d=h.scaleX,u=h.scaleY,e){case"inner":X.set(h);break;case"local":X.set(h).divide(t.localTransform),d/=t.scaleX,u/=t.scaleY;break;case"world":d=1,u=1;break;case"page":e=t.leafer;default:X.set(h).divide(t.getTransform(e));const n=e.worldTransform;d/=d/n.scaleX,u/=u/n.scaleY}o=t.getBounds("render",e)}const Y={scaleX:1,scaleY:1};a.getScaleData(l.scale,l.size,o,Y);let F=l.pixelRatio||1;t.isApp&&(Y.scaleX*=F,Y.scaleY*=F,F=t.app.pixelRatio);const{x:T,y:A,width:D,height:E}=new e(o).scale(Y.scaleX,Y.scaleY),L={matrix:X.scale(1/Y.scaleX,1/Y.scaleY).invert().translate(-T,-A).withScale(1/d*Y.scaleX,1/u*Y.scaleY)};let j,U=r.canvas({width:Math.round(D),height:Math.round(E),pixelRatio:F,smooth:S,contextSettings:R});if(m&&(j=t,j.__worldOpacity=0,t=_,L.bounds=U.bounds),U.save(),x&&void 0!==O){const e=t.get("fill");t.fill="",t.__render(U,L),t.fill=e}else t.__render(U,L);if(U.restore(),j&&j.__updateWorldOpacity(),y){i=function(t){const{width:n,height:o}=t.view,{data:i}=t.context.getImageData(0,0,n,o);let s,a,r,c=0;for(let e=0;e<i.length;e+=4)0!==i[e+3]&&(s=c%n,a=(c-s)/n,r?g(r,s,a):p(r={},s,a)),c++;const l=new e;return v(r,l),l.scale(1/t.pixelRatio).ceil()}(U);const t=U,{width:n,height:o}=i,s={x:0,y:0,width:n,height:o,pixelRatio:F};U=r.canvas(s),U.copyWorld(t,i,s)}P&&U.fillWorld(U.bounds,O||"#FFFFFF","destination-over"),b&&b(U);const W="canvas"===c?U:yield U.export(c,l);w({data:W,width:U.pixelWidth,height:U.pixelHeight,renderBounds:o,trimBounds:i})}))))):w({data:!1})}))))}};let x;function m(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>m(e)))}const y=c.prototype,_=l.get("@leafer-in/export");y.export=function(e,t){const{quality:o,blob:i}=n.getExportOptions(t);return e.includes(".")?this.saveAs(e,o):i?this.toBlob(e,o):this.toDataURL(e,o)},y.toBlob=function(e,t){return new Promise((n=>{i.origin.canvasToBolb(this.view,e,t).then((e=>{n(e)})).catch((e=>{_.error(e),n(null)}))}))},y.toDataURL=function(e,t){return i.origin.canvasToDataURL(this.view,e,t)},y.saveAs=function(e,t){return new Promise((n=>{i.origin.canvasSaveAs(this.view,e,t).then((()=>{n(!0)})).catch((e=>{_.error(e),n(!1)}))}))},d.add("export"),Object.assign(u,w),h.prototype.export=function(e,t){return u.export(this,e,t)};
package/dist/export.js CHANGED
@@ -217,6 +217,7 @@
217
217
  });
218
218
  };
219
219
 
220
+ draw.Plugin.add('export');
220
221
  Object.assign(draw.Export, ExportModule);
221
222
  draw.UI.prototype.export = function (filename, options) {
222
223
  return draw.Export.export(this, filename, options);
@@ -1 +1 @@
1
- "use strict";var e=require("@leafer-ui/draw");function t(e,t,o,n){return new(o||(o=Promise))((function(i,r){function a(e){try{l(n.next(e))}catch(e){r(e)}}function s(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:o,addPoint:n,toBounds:i}=e.TwoPointBoundsHelper;const r={export(r,l,c){this.running=!0;const d=e.FileHelper.fileType(l),u=l.includes(".");return c=e.FileHelper.getExportOptions(c),function(o){a||(a=new e.TaskProcessor);return new Promise((e=>{a.add((()=>t(this,void 0,void 0,(function*(){return yield o(e)}))),{parallel:!1})}))}((a=>new Promise((f=>{const h=e=>{a(e),f(),this.running=!1},{toURL:p}=e.Platform,{download:g}=e.Platform.origin;if("json"===d)return u&&g(p(JSON.stringify(r.toJSON(c.json)),"text"),l),h({data:!!u||r.toJSON(c.json)});if("svg"===d)return u&&g(p(r.toSVG(),"svg"),l),h({data:!!u||r.toSVG()});const{leafer:v}=r;v?(s(r),v.waitViewCompleted((()=>t(this,void 0,void 0,(function*(){let t,a,s=1,d=1;const{worldTransform:u,isLeafer:f,isFrame:p}=r,{slice:g,trim:w,onCanvas:x}=c,m=void 0===c.smooth?v.config.smooth:c.smooth,y=c.contextSettings||v.config.contextSettings,P=c.screenshot||r.isApp,_=f&&P&&void 0===c.fill?r.fill:c.fill,b=e.FileHelper.isOpaqueImage(l)||_,B=new e.Matrix;if(P)t=!0===P?f?v.canvas.bounds:r.worldRenderBounds:P;else{let e=c.relative||(f?"inner":"local");switch(s=u.scaleX,d=u.scaleY,e){case"inner":B.set(u);break;case"local":B.set(u).divide(r.localTransform),s/=r.scaleX,d/=r.scaleY;break;case"world":s=1,d=1;break;case"page":e=r.leafer;default:B.set(u).divide(r.getTransform(e));const t=e.worldTransform;s/=s/t.scaleX,d/=d/t.scaleY}t=r.getBounds("render",e)}const S={scaleX:1,scaleY:1};e.MathHelper.getScaleData(c.scale,c.size,t,S);let F=c.pixelRatio||1;r.isApp&&(S.scaleX*=F,S.scaleY*=F,F=r.app.pixelRatio);const{x:R,y:O,width:T,height:X}=new e.Bounds(t).scale(S.scaleX,S.scaleY),Y={matrix:B.scale(1/S.scaleX,1/S.scaleY).invert().translate(-R,-O).withScale(1/s*S.scaleX,1/d*S.scaleY)};let E,H=e.Creator.canvas({width:Math.round(T),height:Math.round(X),pixelRatio:F,smooth:m,contextSettings:y});if(g&&(E=r,E.__worldOpacity=0,r=v,Y.bounds=H.bounds),H.save(),p&&void 0!==_){const e=r.get("fill");r.fill="",r.__render(H,Y),r.fill=e}else r.__render(H,Y);if(H.restore(),E&&E.__updateWorldOpacity(),w){a=function(t){const{width:r,height:a}=t.view,{data:s}=t.context.getImageData(0,0,r,a);let l,c,d,u=0;for(let e=0;e<s.length;e+=4)0!==s[e+3]&&(l=u%r,c=(u-l)/r,d?n(d,l,c):o(d={},l,c)),u++;const f=new e.Bounds;return i(d,f),f.scale(1/t.pixelRatio).ceil()}(H);const t=H,{width:r,height:s}=a,l={x:0,y:0,width:r,height:s,pixelRatio:F};H=e.Creator.canvas(l),H.copyWorld(t,a,l)}b&&H.fillWorld(H.bounds,_||"#FFFFFF","destination-over"),x&&x(H);const C="canvas"===l?H:yield H.export(l,c);h({data:C,width:H.pixelWidth,height:H.pixelHeight,renderBounds:t,trimBounds:a})}))))):h({data:!1})}))))}};let a;function s(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>s(e)))}const l=e.LeaferCanvasBase.prototype,c=e.Debug.get("@leafer-in/export");l.export=function(t,o){const{quality:n,blob:i}=e.FileHelper.getExportOptions(o);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},l.toBlob=function(t,o){return new Promise((n=>{e.Platform.origin.canvasToBolb(this.view,t,o).then((e=>{n(e)})).catch((e=>{c.error(e),n(null)}))}))},l.toDataURL=function(t,o){return e.Platform.origin.canvasToDataURL(this.view,t,o)},l.saveAs=function(t,o){return new Promise((n=>{e.Platform.origin.canvasSaveAs(this.view,t,o).then((()=>{n(!0)})).catch((e=>{c.error(e),n(!1)}))}))},Object.assign(e.Export,r),e.UI.prototype.export=function(t,o){return e.Export.export(this,t,o)};
1
+ "use strict";var e=require("@leafer-ui/draw");function t(e,t,o,n){return new(o||(o=Promise))((function(i,r){function a(e){try{l(n.next(e))}catch(e){r(e)}}function s(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:o,addPoint:n,toBounds:i}=e.TwoPointBoundsHelper;const r={export(r,l,c){this.running=!0;const d=e.FileHelper.fileType(l),u=l.includes(".");return c=e.FileHelper.getExportOptions(c),function(o){a||(a=new e.TaskProcessor);return new Promise((e=>{a.add((()=>t(this,void 0,void 0,(function*(){return yield o(e)}))),{parallel:!1})}))}((a=>new Promise((p=>{const f=e=>{a(e),p(),this.running=!1},{toURL:h}=e.Platform,{download:g}=e.Platform.origin;if("json"===d)return u&&g(h(JSON.stringify(r.toJSON(c.json)),"text"),l),f({data:!!u||r.toJSON(c.json)});if("svg"===d)return u&&g(h(r.toSVG(),"svg"),l),f({data:!!u||r.toSVG()});const{leafer:v}=r;v?(s(r),v.waitViewCompleted((()=>t(this,void 0,void 0,(function*(){let t,a,s=1,d=1;const{worldTransform:u,isLeafer:p,isFrame:h}=r,{slice:g,trim:w,onCanvas:x}=c,m=void 0===c.smooth?v.config.smooth:c.smooth,P=c.contextSettings||v.config.contextSettings,y=c.screenshot||r.isApp,_=p&&y&&void 0===c.fill?r.fill:c.fill,b=e.FileHelper.isOpaqueImage(l)||_,B=new e.Matrix;if(y)t=!0===y?p?v.canvas.bounds:r.worldRenderBounds:y;else{let e=c.relative||(p?"inner":"local");switch(s=u.scaleX,d=u.scaleY,e){case"inner":B.set(u);break;case"local":B.set(u).divide(r.localTransform),s/=r.scaleX,d/=r.scaleY;break;case"world":s=1,d=1;break;case"page":e=r.leafer;default:B.set(u).divide(r.getTransform(e));const t=e.worldTransform;s/=s/t.scaleX,d/=d/t.scaleY}t=r.getBounds("render",e)}const S={scaleX:1,scaleY:1};e.MathHelper.getScaleData(c.scale,c.size,t,S);let F=c.pixelRatio||1;r.isApp&&(S.scaleX*=F,S.scaleY*=F,F=r.app.pixelRatio);const{x:R,y:O,width:T,height:X}=new e.Bounds(t).scale(S.scaleX,S.scaleY),Y={matrix:B.scale(1/S.scaleX,1/S.scaleY).invert().translate(-R,-O).withScale(1/s*S.scaleX,1/d*S.scaleY)};let E,H=e.Creator.canvas({width:Math.round(T),height:Math.round(X),pixelRatio:F,smooth:m,contextSettings:P});if(g&&(E=r,E.__worldOpacity=0,r=v,Y.bounds=H.bounds),H.save(),h&&void 0!==_){const e=r.get("fill");r.fill="",r.__render(H,Y),r.fill=e}else r.__render(H,Y);if(H.restore(),E&&E.__updateWorldOpacity(),w){a=function(t){const{width:r,height:a}=t.view,{data:s}=t.context.getImageData(0,0,r,a);let l,c,d,u=0;for(let e=0;e<s.length;e+=4)0!==s[e+3]&&(l=u%r,c=(u-l)/r,d?n(d,l,c):o(d={},l,c)),u++;const p=new e.Bounds;return i(d,p),p.scale(1/t.pixelRatio).ceil()}(H);const t=H,{width:r,height:s}=a,l={x:0,y:0,width:r,height:s,pixelRatio:F};H=e.Creator.canvas(l),H.copyWorld(t,a,l)}b&&H.fillWorld(H.bounds,_||"#FFFFFF","destination-over"),x&&x(H);const C="canvas"===l?H:yield H.export(l,c);f({data:C,width:H.pixelWidth,height:H.pixelHeight,renderBounds:t,trimBounds:a})}))))):f({data:!1})}))))}};let a;function s(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>s(e)))}const l=e.LeaferCanvasBase.prototype,c=e.Debug.get("@leafer-in/export");l.export=function(t,o){const{quality:n,blob:i}=e.FileHelper.getExportOptions(o);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},l.toBlob=function(t,o){return new Promise((n=>{e.Platform.origin.canvasToBolb(this.view,t,o).then((e=>{n(e)})).catch((e=>{c.error(e),n(null)}))}))},l.toDataURL=function(t,o){return e.Platform.origin.canvasToDataURL(this.view,t,o)},l.saveAs=function(t,o){return new Promise((n=>{e.Platform.origin.canvasSaveAs(this.view,t,o).then((()=>{n(!0)})).catch((e=>{c.error(e),n(!1)}))}))},e.Plugin.add("export"),Object.assign(e.Export,r),e.UI.prototype.export=function(t,o){return e.Export.export(this,t,o)};
@@ -1 +1 @@
1
- !function(e){"use strict";function t(e,t,o,n){return new(o||(o=Promise))((function(i,r){function a(e){try{l(n.next(e))}catch(e){r(e)}}function s(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:o,addPoint:n,toBounds:i}=e.TwoPointBoundsHelper;const r={export(r,l,c){this.running=!0;const d=e.FileHelper.fileType(l),u=l.includes(".");return c=e.FileHelper.getExportOptions(c),function(o){a||(a=new e.TaskProcessor);return new Promise((e=>{a.add((()=>t(this,void 0,void 0,(function*(){return yield o(e)}))),{parallel:!1})}))}((a=>new Promise((f=>{const h=e=>{a(e),f(),this.running=!1},{toURL:p}=e.Platform,{download:g}=e.Platform.origin;if("json"===d)return u&&g(p(JSON.stringify(r.toJSON(c.json)),"text"),l),h({data:!!u||r.toJSON(c.json)});if("svg"===d)return u&&g(p(r.toSVG(),"svg"),l),h({data:!!u||r.toSVG()});const{leafer:v}=r;v?(s(r),v.waitViewCompleted((()=>t(this,void 0,void 0,(function*(){let t,a,s=1,d=1;const{worldTransform:u,isLeafer:f,isFrame:p}=r,{slice:g,trim:w,onCanvas:x}=c,m=void 0===c.smooth?v.config.smooth:c.smooth,y=c.contextSettings||v.config.contextSettings,P=c.screenshot||r.isApp,_=f&&P&&void 0===c.fill?r.fill:c.fill,b=e.FileHelper.isOpaqueImage(l)||_,B=new e.Matrix;if(P)t=!0===P?f?v.canvas.bounds:r.worldRenderBounds:P;else{let e=c.relative||(f?"inner":"local");switch(s=u.scaleX,d=u.scaleY,e){case"inner":B.set(u);break;case"local":B.set(u).divide(r.localTransform),s/=r.scaleX,d/=r.scaleY;break;case"world":s=1,d=1;break;case"page":e=r.leafer;default:B.set(u).divide(r.getTransform(e));const t=e.worldTransform;s/=s/t.scaleX,d/=d/t.scaleY}t=r.getBounds("render",e)}const S={scaleX:1,scaleY:1};e.MathHelper.getScaleData(c.scale,c.size,t,S);let F=c.pixelRatio||1;r.isApp&&(S.scaleX*=F,S.scaleY*=F,F=r.app.pixelRatio);const{x:R,y:O,width:T,height:X}=new e.Bounds(t).scale(S.scaleX,S.scaleY),Y={matrix:B.scale(1/S.scaleX,1/S.scaleY).invert().translate(-R,-O).withScale(1/s*S.scaleX,1/d*S.scaleY)};let E,H=e.Creator.canvas({width:Math.round(T),height:Math.round(X),pixelRatio:F,smooth:m,contextSettings:y});if(g&&(E=r,E.__worldOpacity=0,r=v,Y.bounds=H.bounds),H.save(),p&&void 0!==_){const e=r.get("fill");r.fill="",r.__render(H,Y),r.fill=e}else r.__render(H,Y);if(H.restore(),E&&E.__updateWorldOpacity(),w){a=function(t){const{width:r,height:a}=t.view,{data:s}=t.context.getImageData(0,0,r,a);let l,c,d,u=0;for(let e=0;e<s.length;e+=4)0!==s[e+3]&&(l=u%r,c=(u-l)/r,d?n(d,l,c):o(d={},l,c)),u++;const f=new e.Bounds;return i(d,f),f.scale(1/t.pixelRatio).ceil()}(H);const t=H,{width:r,height:s}=a,l={x:0,y:0,width:r,height:s,pixelRatio:F};H=e.Creator.canvas(l),H.copyWorld(t,a,l)}b&&H.fillWorld(H.bounds,_||"#FFFFFF","destination-over"),x&&x(H);const L="canvas"===l?H:yield H.export(l,c);h({data:L,width:H.pixelWidth,height:H.pixelHeight,renderBounds:t,trimBounds:a})}))))):h({data:!1})}))))}};let a;function s(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>s(e)))}const l=e.LeaferCanvasBase.prototype,c=e.Debug.get("@leafer-in/export");l.export=function(t,o){const{quality:n,blob:i}=e.FileHelper.getExportOptions(o);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},l.toBlob=function(t,o){return new Promise((n=>{e.Platform.origin.canvasToBolb(this.view,t,o).then((e=>{n(e)})).catch((e=>{c.error(e),n(null)}))}))},l.toDataURL=function(t,o){return e.Platform.origin.canvasToDataURL(this.view,t,o)},l.saveAs=function(t,o){return new Promise((n=>{e.Platform.origin.canvasSaveAs(this.view,t,o).then((()=>{n(!0)})).catch((e=>{c.error(e),n(!1)}))}))},Object.assign(e.Export,r),e.UI.prototype.export=function(t,o){return e.Export.export(this,t,o)}}(LeaferUI);
1
+ !function(e){"use strict";function t(e,t,o,n){return new(o||(o=Promise))((function(i,r){function a(e){try{l(n.next(e))}catch(e){r(e)}}function s(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{setPoint:o,addPoint:n,toBounds:i}=e.TwoPointBoundsHelper;const r={export(r,l,c){this.running=!0;const d=e.FileHelper.fileType(l),u=l.includes(".");return c=e.FileHelper.getExportOptions(c),function(o){a||(a=new e.TaskProcessor);return new Promise((e=>{a.add((()=>t(this,void 0,void 0,(function*(){return yield o(e)}))),{parallel:!1})}))}((a=>new Promise((f=>{const p=e=>{a(e),f(),this.running=!1},{toURL:h}=e.Platform,{download:g}=e.Platform.origin;if("json"===d)return u&&g(h(JSON.stringify(r.toJSON(c.json)),"text"),l),p({data:!!u||r.toJSON(c.json)});if("svg"===d)return u&&g(h(r.toSVG(),"svg"),l),p({data:!!u||r.toSVG()});const{leafer:v}=r;v?(s(r),v.waitViewCompleted((()=>t(this,void 0,void 0,(function*(){let t,a,s=1,d=1;const{worldTransform:u,isLeafer:f,isFrame:h}=r,{slice:g,trim:w,onCanvas:x}=c,m=void 0===c.smooth?v.config.smooth:c.smooth,P=c.contextSettings||v.config.contextSettings,y=c.screenshot||r.isApp,_=f&&y&&void 0===c.fill?r.fill:c.fill,b=e.FileHelper.isOpaqueImage(l)||_,B=new e.Matrix;if(y)t=!0===y?f?v.canvas.bounds:r.worldRenderBounds:y;else{let e=c.relative||(f?"inner":"local");switch(s=u.scaleX,d=u.scaleY,e){case"inner":B.set(u);break;case"local":B.set(u).divide(r.localTransform),s/=r.scaleX,d/=r.scaleY;break;case"world":s=1,d=1;break;case"page":e=r.leafer;default:B.set(u).divide(r.getTransform(e));const t=e.worldTransform;s/=s/t.scaleX,d/=d/t.scaleY}t=r.getBounds("render",e)}const S={scaleX:1,scaleY:1};e.MathHelper.getScaleData(c.scale,c.size,t,S);let F=c.pixelRatio||1;r.isApp&&(S.scaleX*=F,S.scaleY*=F,F=r.app.pixelRatio);const{x:R,y:O,width:T,height:X}=new e.Bounds(t).scale(S.scaleX,S.scaleY),Y={matrix:B.scale(1/S.scaleX,1/S.scaleY).invert().translate(-R,-O).withScale(1/s*S.scaleX,1/d*S.scaleY)};let E,H=e.Creator.canvas({width:Math.round(T),height:Math.round(X),pixelRatio:F,smooth:m,contextSettings:P});if(g&&(E=r,E.__worldOpacity=0,r=v,Y.bounds=H.bounds),H.save(),h&&void 0!==_){const e=r.get("fill");r.fill="",r.__render(H,Y),r.fill=e}else r.__render(H,Y);if(H.restore(),E&&E.__updateWorldOpacity(),w){a=function(t){const{width:r,height:a}=t.view,{data:s}=t.context.getImageData(0,0,r,a);let l,c,d,u=0;for(let e=0;e<s.length;e+=4)0!==s[e+3]&&(l=u%r,c=(u-l)/r,d?n(d,l,c):o(d={},l,c)),u++;const f=new e.Bounds;return i(d,f),f.scale(1/t.pixelRatio).ceil()}(H);const t=H,{width:r,height:s}=a,l={x:0,y:0,width:r,height:s,pixelRatio:F};H=e.Creator.canvas(l),H.copyWorld(t,a,l)}b&&H.fillWorld(H.bounds,_||"#FFFFFF","destination-over"),x&&x(H);const L="canvas"===l?H:yield H.export(l,c);p({data:L,width:H.pixelWidth,height:H.pixelHeight,renderBounds:t,trimBounds:a})}))))):p({data:!1})}))))}};let a;function s(e){e.__.__needComputePaint&&e.__.__computePaint(),e.isBranch&&e.children.forEach((e=>s(e)))}const l=e.LeaferCanvasBase.prototype,c=e.Debug.get("@leafer-in/export");l.export=function(t,o){const{quality:n,blob:i}=e.FileHelper.getExportOptions(o);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},l.toBlob=function(t,o){return new Promise((n=>{e.Platform.origin.canvasToBolb(this.view,t,o).then((e=>{n(e)})).catch((e=>{c.error(e),n(null)}))}))},l.toDataURL=function(t,o){return e.Platform.origin.canvasToDataURL(this.view,t,o)},l.saveAs=function(t,o){return new Promise((n=>{e.Platform.origin.canvasSaveAs(this.view,t,o).then((()=>{n(!0)})).catch((e=>{c.error(e),n(!1)}))}))},e.Plugin.add("export"),Object.assign(e.Export,r),e.UI.prototype.export=function(t,o){return e.Export.export(this,t,o)}}(LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/export",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "@leafer-in/export",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.3.0",
38
- "@leafer-ui/interface": "^1.3.0",
39
- "@leafer-in/interface": "^1.3.0"
37
+ "@leafer-ui/draw": "^1.3.2",
38
+ "@leafer-ui/interface": "^1.3.2",
39
+ "@leafer-in/interface": "^1.3.2"
40
40
  }
41
41
  }
package/src/index.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { IExportFileType, IExportOptions, IExportResult } from '@leafer-ui/interface'
2
- import { Export, UI } from '@leafer-ui/draw'
2
+ import { Export, UI, Plugin } from '@leafer-ui/draw'
3
3
 
4
4
  import { ExportModule } from './export'
5
5
  import './canvas'
6
6
 
7
7
 
8
+ Plugin.add('export')
9
+
10
+
8
11
  Object.assign(Export, ExportModule)
9
12
 
10
13
  UI.prototype.export = function (filename: IExportFileType | string, options?: IExportOptions | number | boolean): Promise<IExportResult> {