@leafer-ui/miniapp 1.0.0-rc.23 → 1.0.0-rc.25
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/miniapp.esm.js +42 -43
- package/dist/miniapp.esm.min.js +1 -1
- package/dist/miniapp.module.js +274 -210
- package/dist/miniapp.module.min.js +1 -1
- package/package.json +10 -10
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MatrixHelper, AlignHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
4
|
import { InteractionHelper, InteractionBase, HitCanvasManager, Platform as Platform$1 } from '@leafer-ui/core';
|
|
@@ -665,7 +665,7 @@ class Renderer {
|
|
|
665
665
|
canvas.clear();
|
|
666
666
|
}
|
|
667
667
|
else {
|
|
668
|
-
bounds.spread(
|
|
668
|
+
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
|
|
669
669
|
canvas.clearWorld(bounds, true);
|
|
670
670
|
canvas.clipWorld(bounds, true);
|
|
671
671
|
}
|
|
@@ -1092,15 +1092,12 @@ class Interaction extends InteractionBase {
|
|
|
1092
1092
|
this.onTouchCancel();
|
|
1093
1093
|
}
|
|
1094
1094
|
}
|
|
1095
|
-
getLocal(
|
|
1096
|
-
if (
|
|
1097
|
-
|
|
1098
|
-
if (p.x !== undefined) {
|
|
1099
|
-
return { x: p.x, y: p.y };
|
|
1095
|
+
getLocal(clientPoint, updateClient) {
|
|
1096
|
+
if (clientPoint.x !== undefined) {
|
|
1097
|
+
return { x: clientPoint.x, y: clientPoint.y };
|
|
1100
1098
|
}
|
|
1101
1099
|
else {
|
|
1102
|
-
|
|
1103
|
-
return { x: p.clientX - clientBounds.x, y: p.clientY - clientBounds.y };
|
|
1100
|
+
return super.getLocal(clientPoint, updateClient);
|
|
1104
1101
|
}
|
|
1105
1102
|
}
|
|
1106
1103
|
getTouches(touches) {
|
|
@@ -1870,13 +1867,14 @@ const PaintImageModule = {
|
|
|
1870
1867
|
recycleImage
|
|
1871
1868
|
};
|
|
1872
1869
|
|
|
1873
|
-
const
|
|
1874
|
-
const
|
|
1870
|
+
const { toPoint: toPoint$2 } = AroundHelper;
|
|
1871
|
+
const realFrom$2 = {};
|
|
1872
|
+
const realTo$2 = {};
|
|
1875
1873
|
function linearGradient(paint, box) {
|
|
1876
1874
|
let { from, to, type, blendMode, opacity } = paint;
|
|
1877
|
-
from ||
|
|
1878
|
-
to ||
|
|
1879
|
-
const style = Platform.canvas.createLinearGradient(
|
|
1875
|
+
toPoint$2(from || 'top', box, realFrom$2);
|
|
1876
|
+
toPoint$2(to || 'bottom', box, realTo$2);
|
|
1877
|
+
const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1880
1878
|
applyStops(style, paint.stops, opacity);
|
|
1881
1879
|
const data = { type, style };
|
|
1882
1880
|
if (blendMode)
|
|
@@ -1887,23 +1885,25 @@ function applyStops(gradient, stops, opacity) {
|
|
|
1887
1885
|
let stop;
|
|
1888
1886
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1889
1887
|
stop = stops[i];
|
|
1890
|
-
|
|
1888
|
+
if (typeof stop === 'string') {
|
|
1889
|
+
gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
|
|
1890
|
+
}
|
|
1891
|
+
else {
|
|
1892
|
+
gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
|
|
1893
|
+
}
|
|
1891
1894
|
}
|
|
1892
1895
|
}
|
|
1893
1896
|
|
|
1894
|
-
const {
|
|
1897
|
+
const { getAngle: getAngle$1, getDistance: getDistance$1 } = PointHelper;
|
|
1895
1898
|
const { get: get$1, rotateOfOuter: rotateOfOuter$1, scaleOfOuter: scaleOfOuter$1 } = MatrixHelper;
|
|
1896
|
-
const
|
|
1897
|
-
const defaultTo$1 = { x: 0.5, y: 1 };
|
|
1899
|
+
const { toPoint: toPoint$1 } = AroundHelper;
|
|
1898
1900
|
const realFrom$1 = {};
|
|
1899
1901
|
const realTo$1 = {};
|
|
1900
1902
|
function radialGradient(paint, box) {
|
|
1901
1903
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
1902
|
-
from ||
|
|
1903
|
-
to ||
|
|
1904
|
-
const {
|
|
1905
|
-
set$1(realFrom$1, x + from.x * width, y + from.y * height);
|
|
1906
|
-
set$1(realTo$1, x + to.x * width, y + to.y * height);
|
|
1904
|
+
toPoint$1(from || 'center', box, realFrom$1);
|
|
1905
|
+
toPoint$1(to || 'bottom', box, realTo$1);
|
|
1906
|
+
const { width, height } = box;
|
|
1907
1907
|
let transform;
|
|
1908
1908
|
if (width !== height || stretch) {
|
|
1909
1909
|
transform = get$1();
|
|
@@ -1918,19 +1918,16 @@ function radialGradient(paint, box) {
|
|
|
1918
1918
|
return data;
|
|
1919
1919
|
}
|
|
1920
1920
|
|
|
1921
|
-
const {
|
|
1921
|
+
const { getAngle, getDistance } = PointHelper;
|
|
1922
1922
|
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
|
|
1923
|
-
const
|
|
1924
|
-
const defaultTo = { x: 0.5, y: 1 };
|
|
1923
|
+
const { toPoint } = AroundHelper;
|
|
1925
1924
|
const realFrom = {};
|
|
1926
1925
|
const realTo = {};
|
|
1927
1926
|
function conicGradient(paint, box) {
|
|
1928
1927
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
1929
|
-
from ||
|
|
1930
|
-
to ||
|
|
1931
|
-
const {
|
|
1932
|
-
set(realFrom, x + from.x * width, y + from.y * height);
|
|
1933
|
-
set(realTo, x + to.x * width, y + to.y * height);
|
|
1928
|
+
toPoint(from || 'center', box, realFrom);
|
|
1929
|
+
toPoint(to || 'bottom', box, realTo);
|
|
1930
|
+
const { width, height } = box;
|
|
1934
1931
|
const transform = get();
|
|
1935
1932
|
const angle = getAngle(realFrom, realTo);
|
|
1936
1933
|
if (Platform.conicGradientRotate90) {
|
|
@@ -2084,7 +2081,7 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
2084
2081
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2085
2082
|
maskCanvas = contentCanvas = null;
|
|
2086
2083
|
}
|
|
2087
|
-
if (child.__.
|
|
2084
|
+
if (child.__.mask === 'path') {
|
|
2088
2085
|
if (child.opacity < 1) {
|
|
2089
2086
|
currentMask = 'opacity-path';
|
|
2090
2087
|
maskOpacity = child.opacity;
|
|
@@ -2105,7 +2102,7 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
2105
2102
|
contentCanvas = getCanvas(canvas);
|
|
2106
2103
|
child.__render(maskCanvas, options);
|
|
2107
2104
|
}
|
|
2108
|
-
if (child.__.
|
|
2105
|
+
if (child.__.mask !== 'clipping')
|
|
2109
2106
|
continue;
|
|
2110
2107
|
}
|
|
2111
2108
|
if (excludeRenderBounds(child, options))
|
|
@@ -2406,11 +2403,11 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
2406
2403
|
if (mode === WordMode) {
|
|
2407
2404
|
wordChar = { char: '', x: charX };
|
|
2408
2405
|
charX = toWordChar(word.data, charX, wordChar);
|
|
2409
|
-
if (wordChar.char !== ' ')
|
|
2406
|
+
if (row.isOverflow || wordChar.char !== ' ')
|
|
2410
2407
|
row.data.push(wordChar);
|
|
2411
2408
|
}
|
|
2412
2409
|
else {
|
|
2413
|
-
charX = toChar(word.data, charX, row.data);
|
|
2410
|
+
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
2414
2411
|
}
|
|
2415
2412
|
if (!row.paraEnd && addWordWidth) {
|
|
2416
2413
|
charX += addWordWidth;
|
|
@@ -2437,9 +2434,9 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2437
2434
|
});
|
|
2438
2435
|
return charX;
|
|
2439
2436
|
}
|
|
2440
|
-
function toChar(data, charX, rowData) {
|
|
2437
|
+
function toChar(data, charX, rowData, isOverflow) {
|
|
2441
2438
|
data.forEach(char => {
|
|
2442
|
-
if (char.char !== ' ') {
|
|
2439
|
+
if (isOverflow || char.char !== ' ') {
|
|
2443
2440
|
char.x = charX;
|
|
2444
2441
|
rowData.push(char);
|
|
2445
2442
|
}
|
|
@@ -2471,12 +2468,14 @@ function layoutText(drawData, style) {
|
|
|
2471
2468
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
2472
2469
|
row = rows[i];
|
|
2473
2470
|
row.x = x;
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2471
|
+
if (row.width < width || (row.width > width && !__clipText)) {
|
|
2472
|
+
switch (textAlign) {
|
|
2473
|
+
case 'center':
|
|
2474
|
+
row.x += (width - row.width) / 2;
|
|
2475
|
+
break;
|
|
2476
|
+
case 'right':
|
|
2477
|
+
row.x += width - row.width;
|
|
2478
|
+
}
|
|
2480
2479
|
}
|
|
2481
2480
|
if (row.paraStart && paraSpacing && i > 0)
|
|
2482
2481
|
starY += paraSpacing;
|
package/dist/miniapp.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as h,LeafList as d,RenderEvent as l,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as g,BranchHelper as p,Bounds as _,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,Answer as k,MatrixHelper as S,AlignHelper as L,ImageEvent as E,PointHelper as T,Direction4 as M,TwoPointBoundsHelper as A,TaskProcessor as C,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as O,InteractionBase as I,HitCanvasManager as P,Platform as F}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as D,ColorConvert as z,PaintGradient as N,Export as V,Group as Y,TextConvert as U,Paint as j,Effect as H}from"@leafer-ui/draw";class X extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:G,fileType:q}=h;function Q(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(G(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,i,s)=>{let n=t.toDataURL(G(q(i)),s);return n=n.substring(n.indexOf("64,")+3),e.origin.download(n,i)},download:(t,s)=>new Promise(((n,o)=>{let a;s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,a=!0);const r=i.getFileSystemManager();r.writeFile({filePath:s,data:t,encoding:"base64",success(){a&&e.miniapp.saveToAlbum(s).then((()=>{r.unlink({filePath:s})})),n()},fail(t){o(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new X(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class J{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new d,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:K,updateBounds:Z,updateAllWorldOpacity:$}=g,{pushAllChildBranch:tt,pushAllParent:et}=p;const{worldBounds:it}=w,st={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,it)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(st):this.afterBounds.setListWithFn(t,it),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:ot,updateAllChange:at}=g,rt=y.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){rt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?rt.warn("layouting"):this.times>3?rt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(K(t,!0),e.add(t),t.isBranch&&tt(t,e),et(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),et(t,e)))}))}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach((n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||Z(s[t])}Z(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&$(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new d(e));e.emitEvent(new v(i,o,this.times)),ht.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){ot(t,!0),t.isBranch?p.updateBounds(t):g.updateBounds(t),at(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=y.get("Renderer");class lt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new _,dt.log(e.innerName,"---\x3e");try{this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new _(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new _(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new _(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||dt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ct}=R;class ut{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new d(i.findList),i.findList||this.hitBranch(o);const{list:a}=this.findList,r=this.getBestMatchLeaf(a,i.bottomList,n),h=n?this.getPath(r):this.getHitablePath(r);return this.clear(),s?{path:h,target:r,throughPath:a.length?this.getThroughPath(a):h}:{path:h,target:r}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new d;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||g.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new d;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new d,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,a=i.length;t<a;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||ct(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.add(i||t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:ft,NoAndSkip:gt,YesAndSkip:pt}=k,_t={},wt={},yt={};class mt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(this.innerIdMap[e]=t,1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new ut(t,this),this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":_t.id=t.substring(1),t=_t;break;case".":wt.className=t.substring(1),t=wt;break;default:yt.tag=t,t=yt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,i,s){return"node"===e.name&&this.target.emit(v.CHECK_UPDATE),this.picker.getByPoint(t,i,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&g.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let a=0,r=t.length;a<r;a++){if(n=t[a],o=e(n,s),o===ft||o===pt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<gt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(c.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new J(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new lt(t,e,i),selector:(t,e)=>new mt(t,e)}),e.layout=ht.fullLayout;const vt={convertTouch(t,e){const i=vt.getTouch(t),s=O.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force||1})},getTouch:t=>t.touches[0]||t.changedTouches[0]};class xt extends I{__listenEvents(){super.__listenEvents(),this.config.eventer&&(this.config.eventer.receiveEvent=this.receive.bind(this))}receive(t){switch(t.type){case"touchstart":this.onTouchStart(t);break;case"touchmove":this.onTouchMove(t);break;case"touchend":this.onTouchEnd(t);break;case"touchcancel":this.onTouchCancel()}}getLocal(t,e){if(e&&this.canvas.updateClientBounds(),void 0!==t.x)return{x:t.x,y:t.y};{const{clientBounds:e}=this.canvas;return{x:t.clientX-e.x,y:t.clientY-e.y}}}getTouches(t){return t}onTouchStart(t){this.multiTouchStart(t);const e=vt.getTouch(t);this.pointerDown(vt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.useMultiTouch)return;const e=vt.getTouch(t);this.pointerMove(vt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){this.multiTouchEnd();const e=vt.getTouch(t);this.pointerUp(vt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(O.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}destroy(){super.destroy(),this.touches=null}}function bt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function Bt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?St(t,!0,e,i):kt(e,i);break;case"inside":Rt("inside",t,n,e,i);break;case"outside":Rt("outside",t,n,e,i)}}function Rt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?St(e,!0,s,r):kt(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",bt(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function kt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function St(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&D.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?kt(i,s):s.stroke(),s.restoreBlendMode()):e?kt(i,s):s.stroke())}const{getSpread:Lt,getOuterOf:Et,getByMove:Tt,getIntersectData:Mt}=R;let At;function Ct(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:z.string(a,r)};case"image":return D.image(i,t,e,s,!At||!At[e.url]);case"linear":return N.linearGradient(e,s);case"radial":return N.radialGradient(e,s);case"angular":return N.conicGradient(e,s);default:return e.r?{type:"solid",style:z.string(e)}:void 0}}const Wt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),At=D.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=Ct(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?bt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&D.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?bt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?bt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?bt(e,i):n?i.fill(n):i.fill())},fillText:bt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)Bt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)Bt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),St(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),St(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),St(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:Bt,drawTextStroke:kt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,h,{scaleX:d,scaleY:l}=n;if(d<0&&(d=-d),l<0&&(l=-l),e.bounds.includes(n))h=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=Mt(s?Lt(e.bounds,d===l?s*d:[s*l,s*d]):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),d*=u,l*=f),r=Et(n,a),o=Tt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:h,shapeBounds:r,scaleX:d,scaleY:l}}};let Ot={};const{get:It,rotateOfOuter:Pt,translate:Ft,scaleOfOuter:Dt,scale:zt,rotate:Nt}=S;function Vt(t,e,i,s,n,o,a){const r=It();Ft(r,e.x+i,e.y+s),zt(r,n,o),a&&Pt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Yt(t,e,i,s,n,o,a){const r=It();Ft(r,e.x+i,e.y+s),n&&zt(r,n,o),a&&Nt(r,a),t.transform=r}function Ut(t,e,i,s,n,o,a,r,h,d){const l=It();if(h)if("center"===d)Pt(l,{x:i/2,y:s/2},h);else switch(Nt(l,h),h){case 90:Ft(l,s,0);break;case 180:Ft(l,i,s);break;case 270:Ft(l,0,i)}Ot.x=e.x+n,Ot.y=e.y+o,Ft(l,Ot.x,Ot.y),a&&Dt(l,Ot,a,r),t.transform=l}const{get:jt,translate:Ht}=S,Xt=new _,Gt={};function qt(t,e,i,s){let{width:n,height:o}=e;i.padding&&(s=Xt.set(s).shrink(i.padding));const{opacity:a,mode:r,align:h,offset:d,scale:l,size:c,rotation:u,blendMode:f,repeat:g}=i,p=s.width===n&&s.height===o;f&&(t.blendMode=f);const _=t.data={mode:r},w="center"!==h&&(u||0)%180==90,y=w?o:n,m=w?n:o;let v,x,b=0,B=0;if(r&&"cover"!==r&&"fit"!==r)c?(v=("number"==typeof c?c:c.width)/n,x=("number"==typeof c?c:c.height)/o):l&&(v="number"==typeof l?l:l.x,x="number"==typeof l?l:l.y);else if(!p||u){const t=s.width/y,e=s.height/m;v=x="fit"===r?Math.min(t,e):Math.max(t,e),b+=(s.width-n*v)/2,B+=(s.height-o*x)/2}if(h){const t={x:b,y:B,width:y,height:m};v&&(t.width*=v,t.height*=x),L.toPoint(h,t,s,Gt,!0),b+=Gt.x,B+=Gt.y}switch(d&&(b+=d.x,B+=d.y),r){case"strench":p||(n=s.width,o=s.height);break;case"normal":case"clip":(b||B||v||u)&&Yt(_,s,b,B,v,x,u);break;case"repeat":(!p||v||u)&&Ut(_,s,n,o,b,B,v,x,u,h),g||(_.repeat="repeat");break;default:v&&Vt(_,s,b,B,v,x,u)}_.transform||(s.x||s.y)&&(_.transform=jt(),Ht(_.transform,s.x,s.y)),v&&"strench"!==r&&(_.scaleX=v,_.scaleY=x),_.width=n,_.height=o,a&&(_.opacity=a),g&&(_.repeat="string"==typeof g?"x"===g?"repeat-x":"repeat-y":"repeat")}let Qt,Jt=new _;const{isSame:Kt}=R;function Zt(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||qt(n,s,i,o),!0}function $t(t,e){ie(t,E.LOAD,e)}function te(t,e){ie(t,E.LOADED,e)}function ee(t,e,i){e.error=i,t.forceUpdate("surface"),ie(t,E.ERROR,e)}function ie(t,e,i){t.hasEvent(e)&&t.emitEvent(new E(e,i))}function se(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:ne,scale:oe,copy:ae}=S,{ceil:re,abs:he}=Math;function de(t,i,s){let{scaleX:n,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=he(n),o=he(o);const{image:t,data:r}=i;let h,d,{width:l,height:c,scaleX:u,scaleY:f,opacity:g,transform:p,repeat:_}=r;u&&(d=ne(),ae(d,p),oe(d,1/u,1/f),n*=u,o*=f),n*=s,o*=s,l*=n,c*=o;const w=l*c;if(!_&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,l/=h,c/=h),u&&(n/=u,o/=f),(p||1!==n||1!==o)&&(d||(d=ne(),p&&ae(d,p)),oe(d,1/n,1/o));const m=t.getCanvas(re(l)||1,re(c)||1,g),v=t.getPattern(m,_||e.origin.noRepeat||"no-repeat",d,i);return i.style=v,i.patternId=a,!0}}function le(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{h(s.next(t))}catch(t){o(t)}}function r(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ce}=Math;const ue={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Qt&&i===Qt.paint&&Kt(s,Qt.boxBounds)?o=Qt.leafPaint:(o={type:i.type,image:r},Qt=r.use>1?{leafPaint:o,paint:i,boxBounds:Jt.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Zt(t,e,i,r,o,s),n&&($t(t,a),te(t,a))):r.error?n&&ee(t,a,r.error):(se(t,!0),n&&$t(t,a),o.loadId=r.load((()=>{se(t,!1),t.destroyed||(Zt(t,e,i,r,o,s)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),te(t,a)),o.loadId=null}),(e=>{se(t,!1),ee(t,a,e),o.loadId=null}))),o},createData:qt,fillOrFitMode:Vt,clipMode:Yt,repeatMode:Ut,createPattern:de,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=b.patternLocked?t.__world:t.__nowWorld;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=ce(o)*i.pixelRatio,s*=ce(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||V.running?de(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>le(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__nowWorld)&&de(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,h=i.length;r<h;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},fe={x:.5,y:0},ge={x:.5,y:1};function pe(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,z.string(s.color,i))}const{set:_e,getAngle:we,getDistance:ye}=T,{get:me,rotateOfOuter:ve,scaleOfOuter:xe}=S,be={x:.5,y:.5},Be={x:.5,y:1},Re={},ke={};const{set:Se,getAngle:Le,getDistance:Ee}=T,{get:Te,rotateOfOuter:Me,scaleOfOuter:Ae}=S,Ce={x:.5,y:.5},We={x:.5,y:1},Oe={},Ie={};const Pe={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;s||(s=fe),n||(n=ge);const h=e.canvas.createLinearGradient(i.x+s.x*i.width,i.y+s.y*i.height,i.x+n.x*i.width,i.y+n.y*i.height);pe(h,t.stops,r);const d={type:o,style:h};return a&&(d.blendMode=a),d},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;s||(s=be),n||(n=Be);const{x:d,y:l,width:c,height:u}=i;let f;_e(Re,d+s.x*c,l+s.y*u),_e(ke,d+n.x*c,l+n.y*u),(c!==u||h)&&(f=me(),xe(f,Re,c/u*(h||1),1),ve(f,Re,we(Re,ke)+90));const g=e.canvas.createRadialGradient(Re.x,Re.y,0,Re.x,Re.y,ye(Re,ke));pe(g,t.stops,a);const p={type:o,style:g,transform:f};return r&&(p.blendMode=r),p},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;s||(s=Ce),n||(n=We);const{x:d,y:l,width:c,height:u}=i;Se(Oe,d+s.x*c,l+s.y*u),Se(Ie,d+n.x*c,l+n.y*u);const f=Te(),g=Le(Oe,Ie);e.conicGradientRotate90?(Ae(f,Oe,c/u*(h||1),1),Me(f,Oe,g+90)):(Ae(f,Oe,1,c/u*(h||1)),Me(f,Oe,g));const p=e.conicGradientSupport?e.canvas.createConicGradient(0,Oe.x,Oe.y):e.canvas.createRadialGradient(Oe.x,Oe.y,0,Oe.x,Oe.y,Ee(Oe,Ie));pe(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_}},{copy:Fe,toOffsetOutBounds:De}=R,ze={},Ne={};function Ve(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(Fe(ze,t.bounds),ze.x+=i.x-a.x,ze.y+=i.y-a.y,s){const{matrix:t}=n;ze.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),ze.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),ze.width*=s,ze.height*=s}t.copyWorld(n.canvas,t.bounds,ze)}else s&&(Fe(ze,i),ze.x-=i.width/2*(s-1),ze.y-=i.height/2*(s-1),ze.width*=s,ze.height*=s),t.copyWorld(n.canvas,a,s?ze:i)}const{toOffsetOutBounds:Ye}=R,Ue={};const je={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;De(d,Ne),r.forEach(((r,p)=>{f.setWorldShadow(Ne.offsetX+r.x*c,Ne.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ve(f,Ne,n,i),s=d,r.box&&(f.restore(),f.save(),h&&(f.copyWorld(f,d,o,"copy"),s=o),h?f.copyWorld(h,o,o,"destination-out"):f.copyWorld(i.canvas,l,d,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),g&&p<g&&f.clearWorld(s,!0)})),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Ye(d,Ue),r.forEach(((r,p)=>{f.save(),f.setWorldShadow(Ue.offsetX+r.x*c,Ue.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ve(f,Ue,n,i),f.restore(),h?(f.copyWorld(f,d,o,"copy"),f.copyWorld(h,o,o,"source-out"),s=o):(f.copyWorld(i.canvas,l,d,"source-out"),s=d),f.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),g&&p<g&&f.clearWorld(s,!0)})),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:He}=w;function Xe(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),qe(t,e,i,1)}(t,i,s,n);break;case"opacity-path":qe(t,i,s,o);break;case"path":i.restore()}}function Ge(t){return t.getSameCanvas(!1,!0)}function qe(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}Y.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let h=0,d=r.length;h<d;h++)i=r[h],i.__.mask&&(a&&(Xe(this,a,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Ge(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=Ge(t)),n||(n=Ge(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||He(i,e)||i.__render(n||t,e);Xe(this,a,t,n,s,o)};const Qe=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Je=Qe+"_#~&*+\\=|≮≯≈≠=…",Ke=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Ze(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const $e=Ze("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ti=Ze("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ei=Ze(Qe),ii=Ze(Je),si=Ze("- —/~|┆·");var ni;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(ni||(ni={}));const{Letter:oi,Single:ai,Before:ri,After:hi,Symbol:di,Break:li}=ni;function ci(t){return $e[t]?oi:si[t]?li:ti[t]?ri:ei[t]?hi:ii[t]?di:Ke.test(t)?ai:oi}const ui={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function fi(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:gi}=ui,{Letter:pi,Single:_i,Before:wi,After:yi,Symbol:mi,Break:vi}=ni;let xi,bi,Bi,Ri,ki,Si,Li,Ei,Ti,Mi,Ai,Ci,Wi,Oi,Ii,Pi,Fi=[];function Di(t,e){Ti&&!Ei&&(Ei=Ti),xi.data.push({char:t,width:e}),Bi+=e}function zi(){Ri+=Bi,xi.width=Bi,bi.words.push(xi),xi={data:[]},Bi=0}function Ni(){Oi&&(Ii.paraNumber++,bi.paraStart=!0,Oi=!1),Ti&&(bi.startCharSize=Ei,bi.endCharSize=Ti,Ei=0),bi.width=Ri,Pi.width&&gi(bi),Fi.push(bi),bi={words:[]},Ri=0}const Vi=0,Yi=1,Ui=2;const{top:ji,right:Hi,bottom:Xi,left:Gi}=M;function qi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Qi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:h,__padding:d}=i;d&&(o&&(s=d[Gi],o-=d[Hi]+d[Gi]),a&&(n=d[ji],a-=d[ji]+d[Xi]));const l={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=h};return function(t,i,s){Ii=t,Fi=t.rows,Pi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:h,height:d}=Pi;if(h||d||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;Oi=!0,Ai=null,Ei=Li=Ti=Bi=Ri=0,xi={data:[]},bi={words:[]};for(let s=0,d=i.length;s<d;s++)Si=i[s],"\n"===Si?(Bi&&zi(),bi.paraEnd=!0,Ni(),Oi=!0):(Mi=ci(Si),Mi===pi&&"none"!==a&&(Si=fi(Si,a,!Bi)),Li=r.measureText(Si).width,n&&(n<0&&(Ti=Li),Li+=n),Ci=Mi===_i&&(Ai===_i||Ai===pi)||Ai===_i&&Mi!==yi,Wi=!(Mi!==wi&&Mi!==_i||Ai!==mi&&Ai!==yi),ki=Oi&&o?h-o:h,t&&h&&Ri+Bi+Li>ki&&(e?(Bi&&zi(),Ni()):(Wi||(Wi=Mi===pi&&Ai==yi),Ci||Wi||Mi===vi||Mi===wi||Mi===_i||Bi+Li>ki?(Bi&&zi(),Ni()):Ni()))," "===Si&&!0!==Oi&&Ri+Bi===0||(Mi===vi?(" "===Si&&Bi&&zi(),Di(Si,Li),zi()):Ci||Wi?(Bi&&zi(),Di(Si,Li)):Di(Si,Li)),Ai=Mi);Bi&&zi(),Ri&&Ni(),Fi.length>0&&(Fi[Fi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Ii.paraNumber++,Fi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,i),d&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":qi(e,"x",t[Gi]);break;case"right":qi(e,"x",-t[Hi])}if(!n)switch(i.verticalAlign){case"top":qi(e,"y",t[ji]);break;case"bottom":qi(e,"y",-t[Xi])}}(d,l,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:h,verticalAlign:d,paraSpacing:l}=e;let c,u,f,{x:g,y:p,width:_,height:w}=s,y=n*i.length+(l?l*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(d){case"middle":p+=(w-y)/2;break;case"bottom":p+=w-y}m+=p;for(let o=0,d=i.length;o<d;o++){switch(c=i[o],c.x=g,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&l&&o>0&&(m+=l),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<s.x&&(s.x=u),f>s.width&&(s.width=f),r&&_&&_<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=y}(l,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let h,d,l,c,u;n.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,d=i&&"justify"===o&&t.words.length>1?(i-t.width-l)/(t.words.length-1):0,c=r||t.isOverflow?Vi:d>.01?Yi:Ui,t.isOverflow&&!r&&(t.textMode=!0),c===Ui?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,h=t.x,t.data=[],t.words.forEach((e=>{c===Yi?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&d&&(h+=d,t.width+=d)}))),t.words=null)}))}(l,i,o),l.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),o&&"show"!==o){let t,a;"hide"===o?o="":"ellipsis"===o&&(o="...");const r=o?e.canvas.measureText(o).width:0,h=i.x+i.width-r;("none"===i.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],a=t.x+t.width,!(s===i&&a<h));s--){if(a<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(l,i),l}};const Ji={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Ki,addPoint:Zi,toBounds:$i}=A;const ts={export(t,i,s){return this.running=!0,function(t){es||(es=new C);return new Promise((e=>{es.add((()=>le(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((n=>new Promise((o=>{const r=t=>{n(t),o(),this.running=!1};if("json"===i)return r({data:t.toJSON()});if("json"===h.fileType(i))return e.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),i),r({data:!0});const{leafer:d}=t;d?d.waitViewCompleted((()=>le(this,void 0,void 0,(function*(){s=h.getExportOptions(s);let e,n,o=1,l=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:g,trim:p,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;t.isApp&&(y*=m,m=t.app.pixelRatio);const v=s.screenshot||t.isApp,x=u&&v&&void 0===s.fill?t.fill:s.fill,b=h.isOpaqueImage(i)||x,B=new W;if(v)e=!0===v?u?d.canvas.bounds:t.worldRenderBounds:v;else{let i=s.relative||(u?"inner":"local");switch(o=c.scaleX,l=c.scaleY,i){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),o/=t.scaleX,l/=t.scaleY;break;case"world":o=1,l=1;break;case"page":i=t.leafer;default:B.set(c).divide(t.getTransform(i));const e=i.worldTransform;o/=o/e.scaleX,l/=l/e.scaleY}e=t.getBounds("render",i)}const{x:R,y:k,width:S,height:L}=new _(e).scale(y);let E=a.canvas({width:Math.round(S),height:Math.round(L),pixelRatio:m});const T={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/o*y,1/l*y)};if(g&&(t=d,T.bounds=E.bounds),E.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(E,T),t.fill=e}else t.__render(E,T);if(E.restore(),p){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Zi(a,n,o):Ki(a={},n,o)),r++;const h=new _;return $i(a,h),h.scale(1/t.pixelRatio).ceil()}(E);const t=E,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:m};E=a.canvas(s),E.copyWorld(t,n,s)}b&&E.fillWorld(E.bounds,x||"#FFFFFF","destination-over"),w&&w(E);const M="canvas"===i?E:yield E.export(i,s);r({data:M,width:E.pixelWidth,height:E.pixelHeight,renderBounds:e,trimBounds:n})})))):r({data:!1})}))))}};let es;const is=t.prototype,ss=y.get("@leafer-ui/export");is.export=function(t,e){const{quality:i,blob:s}=h.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},is.toBlob=function(t,i){return new Promise((s=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{s(t)})).catch((t=>{ss.error(t),s(null)}))}))},is.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},is.saveAs=function(t,i){return new Promise((s=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{s(!0)})).catch((t=>{ss.error(t),s(!1)}))}))},Object.assign(U,Qi),Object.assign(z,Ji),Object.assign(j,Wt),Object.assign(D,ue),Object.assign(N,Pe),Object.assign(H,je),Object.assign(V,ts),Object.assign(a,{interaction:(t,e,i,s)=>new xt(t,e,i,s),hitCanvas:(t,e)=>new X(t,e),hitCanvasManager:()=>new P});try{Q(0,wx)}catch(t){}X.prototype.__createContext=function(){if(this.viewSelect){const t=F.origin.createCanvas(1,1),e=this.view.getContext("2d");this.testView=this.view,this.testContext=e,this.view=t}this.context=this.view.getContext("2d"),this.__bindContext()},X.prototype.updateRender=function(){if(this.testView){let t=this.context.createPattern(this.view,F.origin.noRepeat);this.testContext.clearRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t,this.testContext.fillRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t=null}},X.prototype.updateViewSize=function(){const{width:t,height:e,pixelRatio:i,view:s,testView:n}=this;s.width=t*i,s.height=e*i,n&&(n.width=s.width,n.height=s.height)};export{xt as Interaction,ht as Layouter,X as LeaferCanvas,lt as Renderer,mt as Selector,J as Watcher,Q as useCanvas};
|
|
1
|
+
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as h,LeafList as d,RenderEvent as l,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as g,BranchHelper as p,Bounds as _,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,Answer as k,MatrixHelper as S,AlignHelper as L,ImageEvent as E,AroundHelper as T,PointHelper as M,Direction4 as A,TwoPointBoundsHelper as C,TaskProcessor as W,Matrix as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as I,InteractionBase as P,HitCanvasManager as F,Platform as D}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as z,ColorConvert as N,PaintGradient as V,Export as U,Group as Y,TextConvert as j,Paint as H,Effect as G}from"@leafer-ui/draw";class X extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:q,fileType:Q}=h;function J(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(q(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,i,s)=>{let n=t.toDataURL(q(Q(i)),s);return n=n.substring(n.indexOf("64,")+3),e.origin.download(n,i)},download:(t,s)=>new Promise(((n,o)=>{let a;s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,a=!0);const r=i.getFileSystemManager();r.writeFile({filePath:s,data:t,encoding:"base64",success(){a&&e.miniapp.saveToAlbum(s).then((()=>{r.unlink({filePath:s})})),n()},fail(t){o(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new X(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new d,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:Z,updateBounds:$,updateAllWorldOpacity:tt}=g,{pushAllChildBranch:et,pushAllParent:it}=p;const{worldBounds:st}=w,nt={x:0,y:0,width:1e5,height:1e5};class ot{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,st)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(nt):this.afterBounds.setListWithFn(t,st),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:at,updateAllChange:rt}=g,ht=y.get("Layouter");class dt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){ht.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ht.warn("layouting"):this.times>3?ht.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(Z(t,!0),e.add(t),t.isBranch&&et(t,e),it(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),it(t,e)))}))}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach((n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||$(s[t])}$(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&tt(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new d(e));e.emitEvent(new v(i,o,this.times)),dt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){at(t,!0),t.isBranch?p.updateBounds(t):g.updateBounds(t),rt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ot([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ot(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const lt=y.get("Renderer");class ct{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new _,lt.log(e.innerName,"---\x3e");try{this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,lt.error(t)}lt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return lt.warn("rendering");if(this.times>3)return lt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return lt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new _(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new _(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new _(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||lt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ut}=R;class ft{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new d(i.findList),i.findList||this.hitBranch(o);const{list:a}=this.findList,r=this.getBestMatchLeaf(a,i.bottomList,n),h=n?this.getPath(r):this.getHitablePath(r);return this.clear(),s?{path:h,target:r,throughPath:a.length?this.getThroughPath(a):h}:{path:h,target:r}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new d;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||g.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new d;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new d,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,a=i.length;t<a;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||ut(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.add(i||t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:gt,NoAndSkip:pt,YesAndSkip:_t}=k,wt={},yt={},mt={};class vt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(this.innerIdMap[e]=t,1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new ft(t,this),this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":wt.id=t.substring(1),t=wt;break;case".":yt.className=t.substring(1),t=yt;break;default:mt.tag=t,t=mt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,i,s){return"node"===e.name&&this.target.emit(v.CHECK_UPDATE),this.picker.getByPoint(t,i,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&g.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let a=0,r=t.length;a<r;a++){if(n=t[a],o=e(n,s),o===gt||o===_t){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<pt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(c.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new dt(t,e),renderer:(t,e,i)=>new ct(t,e,i),selector:(t,e)=>new vt(t,e)}),e.layout=dt.fullLayout;const xt={convertTouch(t,e){const i=xt.getTouch(t),s=I.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force||1})},getTouch:t=>t.touches[0]||t.changedTouches[0]};class bt extends P{__listenEvents(){super.__listenEvents(),this.config.eventer&&(this.config.eventer.receiveEvent=this.receive.bind(this))}receive(t){switch(t.type){case"touchstart":this.onTouchStart(t);break;case"touchmove":this.onTouchMove(t);break;case"touchend":this.onTouchEnd(t);break;case"touchcancel":this.onTouchCancel()}}getLocal(t,e){return void 0!==t.x?{x:t.x,y:t.y}:super.getLocal(t,e)}getTouches(t){return t}onTouchStart(t){this.multiTouchStart(t);const e=xt.getTouch(t);this.pointerDown(xt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.useMultiTouch)return;const e=xt.getTouch(t);this.pointerMove(xt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){this.multiTouchEnd();const e=xt.getTouch(t);this.pointerUp(xt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(I.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}destroy(){super.destroy(),this.touches=null}}function Bt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function Rt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?Lt(t,!0,e,i):St(e,i);break;case"inside":kt("inside",t,n,e,i);break;case"outside":kt("outside",t,n,e,i)}}function kt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?Lt(e,!0,s,r):St(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",Bt(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function St(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function Lt(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&z.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?St(i,s):s.stroke(),s.restoreBlendMode()):e?St(i,s):s.stroke())}const{getSpread:Et,getOuterOf:Tt,getByMove:Mt,getIntersectData:At}=R;let Ct;function Wt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:N.string(a,r)};case"image":return z.image(i,t,e,s,!Ct||!Ct[e.url]);case"linear":return V.linearGradient(e,s);case"radial":return V.radialGradient(e,s);case"angular":return V.conicGradient(e,s);default:return e.r?{type:"solid",style:N.string(e)}:void 0}}const Ot={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Ct=z.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=Wt(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?Bt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&z.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?Bt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Bt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Bt(e,i):n?i.fill(n):i.fill())},fillText:Bt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)Rt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)Rt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Lt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Lt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),Lt(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:Rt,drawTextStroke:St,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,h,{scaleX:d,scaleY:l}=n;if(d<0&&(d=-d),l<0&&(l=-l),e.bounds.includes(n))h=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=At(s?Et(e.bounds,d===l?s*d:[s*l,s*d]):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),d*=u,l*=f),r=Tt(n,a),o=Mt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:h,shapeBounds:r,scaleX:d,scaleY:l}}};let It={};const{get:Pt,rotateOfOuter:Ft,translate:Dt,scaleOfOuter:zt,scale:Nt,rotate:Vt}=S;function Ut(t,e,i,s,n,o,a){const r=Pt();Dt(r,e.x+i,e.y+s),Nt(r,n,o),a&&Ft(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Yt(t,e,i,s,n,o,a){const r=Pt();Dt(r,e.x+i,e.y+s),n&&Nt(r,n,o),a&&Vt(r,a),t.transform=r}function jt(t,e,i,s,n,o,a,r,h,d){const l=Pt();if(h)if("center"===d)Ft(l,{x:i/2,y:s/2},h);else switch(Vt(l,h),h){case 90:Dt(l,s,0);break;case 180:Dt(l,i,s);break;case 270:Dt(l,0,i)}It.x=e.x+n,It.y=e.y+o,Dt(l,It.x,It.y),a&&zt(l,It,a,r),t.transform=l}const{get:Ht,translate:Gt}=S,Xt=new _,qt={};function Qt(t,e,i,s){let{width:n,height:o}=e;i.padding&&(s=Xt.set(s).shrink(i.padding));const{opacity:a,mode:r,align:h,offset:d,scale:l,size:c,rotation:u,blendMode:f,repeat:g}=i,p=s.width===n&&s.height===o;f&&(t.blendMode=f);const _=t.data={mode:r},w="center"!==h&&(u||0)%180==90,y=w?o:n,m=w?n:o;let v,x,b=0,B=0;if(r&&"cover"!==r&&"fit"!==r)c?(v=("number"==typeof c?c:c.width)/n,x=("number"==typeof c?c:c.height)/o):l&&(v="number"==typeof l?l:l.x,x="number"==typeof l?l:l.y);else if(!p||u){const t=s.width/y,e=s.height/m;v=x="fit"===r?Math.min(t,e):Math.max(t,e),b+=(s.width-n*v)/2,B+=(s.height-o*x)/2}if(h){const t={x:b,y:B,width:y,height:m};v&&(t.width*=v,t.height*=x),L.toPoint(h,t,s,qt,!0),b+=qt.x,B+=qt.y}switch(d&&(b+=d.x,B+=d.y),r){case"strench":p||(n=s.width,o=s.height);break;case"normal":case"clip":(b||B||v||u)&&Yt(_,s,b,B,v,x,u);break;case"repeat":(!p||v||u)&&jt(_,s,n,o,b,B,v,x,u,h),g||(_.repeat="repeat");break;default:v&&Ut(_,s,b,B,v,x,u)}_.transform||(s.x||s.y)&&(_.transform=Ht(),Gt(_.transform,s.x,s.y)),v&&"strench"!==r&&(_.scaleX=v,_.scaleY=x),_.width=n,_.height=o,a&&(_.opacity=a),g&&(_.repeat="string"==typeof g?"x"===g?"repeat-x":"repeat-y":"repeat")}let Jt,Kt=new _;const{isSame:Zt}=R;function $t(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Qt(n,s,i,o),!0}function te(t,e){se(t,E.LOAD,e)}function ee(t,e){se(t,E.LOADED,e)}function ie(t,e,i){e.error=i,t.forceUpdate("surface"),se(t,E.ERROR,e)}function se(t,e,i){t.hasEvent(e)&&t.emitEvent(new E(e,i))}function ne(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:oe,scale:ae,copy:re}=S,{ceil:he,abs:de}=Math;function le(t,i,s){let{scaleX:n,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=de(n),o=de(o);const{image:t,data:r}=i;let h,d,{width:l,height:c,scaleX:u,scaleY:f,opacity:g,transform:p,repeat:_}=r;u&&(d=oe(),re(d,p),ae(d,1/u,1/f),n*=u,o*=f),n*=s,o*=s,l*=n,c*=o;const w=l*c;if(!_&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,l/=h,c/=h),u&&(n/=u,o/=f),(p||1!==n||1!==o)&&(d||(d=oe(),p&&re(d,p)),ae(d,1/n,1/o));const m=t.getCanvas(he(l)||1,he(c)||1,g),v=t.getPattern(m,_||e.origin.noRepeat||"no-repeat",d,i);return i.style=v,i.patternId=a,!0}}function ce(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{h(s.next(t))}catch(t){o(t)}}function r(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ue}=Math;const fe={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Jt&&i===Jt.paint&&Zt(s,Jt.boxBounds)?o=Jt.leafPaint:(o={type:i.type,image:r},Jt=r.use>1?{leafPaint:o,paint:i,boxBounds:Kt.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?($t(t,e,i,r,o,s),n&&(te(t,a),ee(t,a))):r.error?n&&ie(t,a,r.error):(ne(t,!0),n&&te(t,a),o.loadId=r.load((()=>{ne(t,!1),t.destroyed||($t(t,e,i,r,o,s)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ee(t,a)),o.loadId=null}),(e=>{ne(t,!1),ie(t,a,e),o.loadId=null}))),o},createData:Qt,fillOrFitMode:Ut,clipMode:Yt,repeatMode:jt,createPattern:le,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=b.patternLocked?t.__world:t.__nowWorld;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=ue(o)*i.pixelRatio,s*=ue(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||U.running?le(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>ce(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__nowWorld)&&le(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,h=i.length;r<h;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},{toPoint:ge}=T,pe={},_e={};function we(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],"string"==typeof s?t.addColorStop(n/(o-1),N.string(s,i)):t.addColorStop(s.offset,N.string(s.color,i))}const{getAngle:ye,getDistance:me}=M,{get:ve,rotateOfOuter:xe,scaleOfOuter:be}=S,{toPoint:Be}=T,Re={},ke={};const{getAngle:Se,getDistance:Le}=M,{get:Ee,rotateOfOuter:Te,scaleOfOuter:Me}=S,{toPoint:Ae}=T,Ce={},We={};const Oe={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;ge(s||"top",i,pe),ge(n||"bottom",i,_e);const h=e.canvas.createLinearGradient(pe.x,pe.y,_e.x,_e.y);we(h,t.stops,r);const d={type:o,style:h};return a&&(d.blendMode=a),d},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;Be(s||"center",i,Re),Be(n||"bottom",i,ke);const{width:d,height:l}=i;let c;(d!==l||h)&&(c=ve(),be(c,Re,d/l*(h||1),1),xe(c,Re,ye(Re,ke)+90));const u=e.canvas.createRadialGradient(Re.x,Re.y,0,Re.x,Re.y,me(Re,ke));we(u,t.stops,a);const f={type:o,style:u,transform:c};return r&&(f.blendMode=r),f},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;Ae(s||"center",i,Ce),Ae(n||"bottom",i,We);const{width:d,height:l}=i,c=Ee(),u=Se(Ce,We);e.conicGradientRotate90?(Me(c,Ce,d/l*(h||1),1),Te(c,Ce,u+90)):(Me(c,Ce,1,d/l*(h||1)),Te(c,Ce,u));const f=e.conicGradientSupport?e.canvas.createConicGradient(0,Ce.x,Ce.y):e.canvas.createRadialGradient(Ce.x,Ce.y,0,Ce.x,Ce.y,Le(Ce,We));we(f,t.stops,a);const g={type:o,style:f,transform:c};return r&&(g.blendMode=r),g}},{copy:Ie,toOffsetOutBounds:Pe}=R,Fe={},De={};function ze(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(Ie(Fe,t.bounds),Fe.x+=i.x-a.x,Fe.y+=i.y-a.y,s){const{matrix:t}=n;Fe.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Fe.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Fe.width*=s,Fe.height*=s}t.copyWorld(n.canvas,t.bounds,Fe)}else s&&(Ie(Fe,i),Fe.x-=i.width/2*(s-1),Fe.y-=i.height/2*(s-1),Fe.width*=s,Fe.height*=s),t.copyWorld(n.canvas,a,s?Fe:i)}const{toOffsetOutBounds:Ne}=R,Ve={};const Ue={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Pe(d,De),r.forEach(((r,p)=>{f.setWorldShadow(De.offsetX+r.x*c,De.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ze(f,De,n,i),s=d,r.box&&(f.restore(),f.save(),h&&(f.copyWorld(f,d,o,"copy"),s=o),h?f.copyWorld(h,o,o,"destination-out"):f.copyWorld(i.canvas,l,d,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),g&&p<g&&f.clearWorld(s,!0)})),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Ne(d,Ve),r.forEach(((r,p)=>{f.save(),f.setWorldShadow(Ve.offsetX+r.x*c,Ve.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ze(f,Ve,n,i),f.restore(),h?(f.copyWorld(f,d,o,"copy"),f.copyWorld(h,o,o,"source-out"),s=o):(f.copyWorld(i.canvas,l,d,"source-out"),s=d),f.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),g&&p<g&&f.clearWorld(s,!0)})),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ye}=w;function je(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),Ge(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Ge(t,i,s,o);break;case"path":i.restore()}}function He(t){return t.getSameCanvas(!1,!0)}function Ge(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}Y.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let h=0,d=r.length;h<d;h++)i=r[h],i.__.mask&&(a&&(je(this,a,t,n,s,o),s=n=null),"path"===i.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=He(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=He(t)),n||(n=He(t)),i.__render(s,e)),"clipping"!==i.__.mask)||Ye(i,e)||i.__render(n||t,e);je(this,a,t,n,s,o)};const Xe=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",qe=Xe+"_#~&*+\\=|≮≯≈≠=…",Qe=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Je(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ke=Je("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ze=Je("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),$e=Je(Xe),ti=Je(qe),ei=Je("- —/~|┆·");var ii;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(ii||(ii={}));const{Letter:si,Single:ni,Before:oi,After:ai,Symbol:ri,Break:hi}=ii;function di(t){return Ke[t]?si:ei[t]?hi:Ze[t]?oi:$e[t]?ai:ti[t]?ri:Qe.test(t)?ni:si}const li={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ci(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:ui}=li,{Letter:fi,Single:gi,Before:pi,After:_i,Symbol:wi,Break:yi}=ii;let mi,vi,xi,bi,Bi,Ri,ki,Si,Li,Ei,Ti,Mi,Ai,Ci,Wi,Oi,Ii=[];function Pi(t,e){Li&&!Si&&(Si=Li),mi.data.push({char:t,width:e}),xi+=e}function Fi(){bi+=xi,mi.width=xi,vi.words.push(mi),mi={data:[]},xi=0}function Di(){Ci&&(Wi.paraNumber++,vi.paraStart=!0,Ci=!1),Li&&(vi.startCharSize=Si,vi.endCharSize=Li,Si=0),vi.width=bi,Oi.width&&ui(vi),Ii.push(vi),vi={words:[]},bi=0}const zi=0,Ni=1,Vi=2;const{top:Ui,right:Yi,bottom:ji,left:Hi}=A;function Gi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Xi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:h,__padding:d}=i;d&&(o&&(s=d[Hi],o-=d[Yi]+d[Hi]),a&&(n=d[Ui],a-=d[Ui]+d[ji]));const l={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=h};return function(t,i,s){Wi=t,Ii=t.rows,Oi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:h,height:d}=Oi;if(h||d||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;Ci=!0,Ti=null,Si=ki=Li=xi=bi=0,mi={data:[]},vi={words:[]};for(let s=0,d=i.length;s<d;s++)Ri=i[s],"\n"===Ri?(xi&&Fi(),vi.paraEnd=!0,Di(),Ci=!0):(Ei=di(Ri),Ei===fi&&"none"!==a&&(Ri=ci(Ri,a,!xi)),ki=r.measureText(Ri).width,n&&(n<0&&(Li=ki),ki+=n),Mi=Ei===gi&&(Ti===gi||Ti===fi)||Ti===gi&&Ei!==_i,Ai=!(Ei!==pi&&Ei!==gi||Ti!==wi&&Ti!==_i),Bi=Ci&&o?h-o:h,t&&h&&bi+xi+ki>Bi&&(e?(xi&&Fi(),Di()):(Ai||(Ai=Ei===fi&&Ti==_i),Mi||Ai||Ei===yi||Ei===pi||Ei===gi||xi+ki>Bi?(xi&&Fi(),Di()):Di()))," "===Ri&&!0!==Ci&&bi+xi===0||(Ei===yi?(" "===Ri&&xi&&Fi(),Pi(Ri,ki),Fi()):Mi||Ai?(xi&&Fi(),Pi(Ri,ki)):Pi(Ri,ki)),Ti=Ei);xi&&Fi(),bi&&Di(),Ii.length>0&&(Ii[Ii.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Wi.paraNumber++,Ii.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,i),d&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Gi(e,"x",t[Hi]);break;case"right":Gi(e,"x",-t[Yi])}if(!n)switch(i.verticalAlign){case"top":Gi(e,"y",t[Ui]);break;case"bottom":Gi(e,"y",-t[ji])}}(d,l,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:h,verticalAlign:d,paraSpacing:l}=e;let c,u,f,{x:g,y:p,width:_,height:w}=s,y=n*i.length+(l?l*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(d){case"middle":p+=(w-y)/2;break;case"bottom":p+=w-y}m+=p;for(let o=0,d=i.length;o<d;o++){if(c=i[o],c.x=g,c.width<_||c.width>_&&!r)switch(h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&l&&o>0&&(m+=l),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<s.x&&(s.x=u),f>s.width&&(s.width=f),r&&_&&_<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=y}(l,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let h,d,l,c,u;n.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,d=i&&"justify"===o&&t.words.length>1?(i-t.width-l)/(t.words.length-1):0,c=r||t.isOverflow?zi:d>.01?Ni:Vi,t.isOverflow&&!r&&(t.textMode=!0),c===Vi?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,h=t.x,t.data=[],t.words.forEach((e=>{c===Ni?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&d&&(h+=d,t.width+=d)}))),t.words=null)}))}(l,i,o),l.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),o&&"show"!==o){let t,a;"hide"===o?o="":"ellipsis"===o&&(o="...");const r=o?e.canvas.measureText(o).width:0,h=i.x+i.width-r;("none"===i.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],a=t.x+t.width,!(s===i&&a<h));s--){if(a<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(l,i),l}};const qi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Qi,addPoint:Ji,toBounds:Ki}=C;const Zi={export(t,i,s){return this.running=!0,function(t){$i||($i=new W);return new Promise((e=>{$i.add((()=>ce(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((n=>new Promise((o=>{const r=t=>{n(t),o(),this.running=!1};if("json"===i)return r({data:t.toJSON()});if("json"===h.fileType(i))return e.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),i),r({data:!0});const{leafer:d}=t;d?d.waitViewCompleted((()=>ce(this,void 0,void 0,(function*(){s=h.getExportOptions(s);let e,n,o=1,l=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:g,trim:p,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;t.isApp&&(y*=m,m=t.app.pixelRatio);const v=s.screenshot||t.isApp,x=u&&v&&void 0===s.fill?t.fill:s.fill,b=h.isOpaqueImage(i)||x,B=new O;if(v)e=!0===v?u?d.canvas.bounds:t.worldRenderBounds:v;else{let i=s.relative||(u?"inner":"local");switch(o=c.scaleX,l=c.scaleY,i){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),o/=t.scaleX,l/=t.scaleY;break;case"world":o=1,l=1;break;case"page":i=t.leafer;default:B.set(c).divide(t.getTransform(i));const e=i.worldTransform;o/=o/e.scaleX,l/=l/e.scaleY}e=t.getBounds("render",i)}const{x:R,y:k,width:S,height:L}=new _(e).scale(y);let E=a.canvas({width:Math.round(S),height:Math.round(L),pixelRatio:m});const T={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/o*y,1/l*y)};if(g&&(t=d,T.bounds=E.bounds),E.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(E,T),t.fill=e}else t.__render(E,T);if(E.restore(),p){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Ji(a,n,o):Qi(a={},n,o)),r++;const h=new _;return Ki(a,h),h.scale(1/t.pixelRatio).ceil()}(E);const t=E,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:m};E=a.canvas(s),E.copyWorld(t,n,s)}b&&E.fillWorld(E.bounds,x||"#FFFFFF","destination-over"),w&&w(E);const M="canvas"===i?E:yield E.export(i,s);r({data:M,width:E.pixelWidth,height:E.pixelHeight,renderBounds:e,trimBounds:n})})))):r({data:!1})}))))}};let $i;const ts=t.prototype,es=y.get("@leafer-ui/export");ts.export=function(t,e){const{quality:i,blob:s}=h.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},ts.toBlob=function(t,i){return new Promise((s=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{s(t)})).catch((t=>{es.error(t),s(null)}))}))},ts.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},ts.saveAs=function(t,i){return new Promise((s=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{s(!0)})).catch((t=>{es.error(t),s(!1)}))}))},Object.assign(j,Xi),Object.assign(N,qi),Object.assign(H,Ot),Object.assign(z,fe),Object.assign(V,Oe),Object.assign(G,Ue),Object.assign(U,Zi),Object.assign(a,{interaction:(t,e,i,s)=>new bt(t,e,i,s),hitCanvas:(t,e)=>new X(t,e),hitCanvasManager:()=>new F});try{J(0,wx)}catch(t){}X.prototype.__createContext=function(){if(this.viewSelect){const t=D.origin.createCanvas(1,1),e=this.view.getContext("2d");this.testView=this.view,this.testContext=e,this.view=t}this.context=this.view.getContext("2d"),this.__bindContext()},X.prototype.updateRender=function(){if(this.testView){let t=this.context.createPattern(this.view,D.origin.noRepeat);this.testContext.clearRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t,this.testContext.fillRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t=null}},X.prototype.updateViewSize=function(){const{width:t,height:e,pixelRatio:i,view:s,testView:n}=this;s.width=t*i,s.height=e*i,n&&(n.width=s.width,n.height=s.height)};export{bt as Interaction,dt as Layouter,X as LeaferCanvas,ct as Renderer,vt as Selector,K as Watcher,J as useCanvas};
|