leafer-draw 1.10.0 → 1.11.0

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/web.cjs CHANGED
@@ -874,30 +874,31 @@ function fill(fill, ui, canvas, renderOptions) {
874
874
  }
875
875
 
876
876
  function fills(fills, ui, canvas, renderOptions) {
877
- let item;
877
+ let item, originPaint, countImage;
878
878
  for (let i = 0, len = fills.length; i < len; i++) {
879
- item = fills[i];
879
+ item = fills[i], originPaint = item.originPaint;
880
880
  if (item.image) {
881
+ countImage ? countImage++ : countImage = 1;
881
882
  if (draw.PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue;
882
883
  if (!item.style) {
883
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(item.image, canvas, renderOptions);
884
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions);
884
885
  continue;
885
886
  }
886
887
  }
887
888
  canvas.fillStyle = item.style;
888
- if (item.transform || item.scaleFixed) {
889
+ if (item.transform || originPaint.scaleFixed) {
889
890
  canvas.save();
890
891
  if (item.transform) canvas.transform(item.transform);
891
- if (item.scaleFixed) {
892
+ if (originPaint.scaleFixed) {
892
893
  const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
893
- if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
894
+ if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
894
895
  }
895
- if (item.blendMode) canvas.blendMode = item.blendMode;
896
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
896
897
  fillPathOrText(ui, canvas, renderOptions);
897
898
  canvas.restore();
898
899
  } else {
899
- if (item.blendMode) {
900
- canvas.saveBlendMode(item.blendMode);
900
+ if (originPaint.blendMode) {
901
+ canvas.saveBlendMode(originPaint.blendMode);
901
902
  fillPathOrText(ui, canvas, renderOptions);
902
903
  canvas.restoreBlendMode();
903
904
  } else fillPathOrText(ui, canvas, renderOptions);
@@ -1050,8 +1051,8 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas, renderO
1050
1051
  const {strokeStyle: strokeStyle} = item;
1051
1052
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
1052
1053
  } else canvas.strokeStyle = item.style;
1053
- if (item.blendMode) {
1054
- canvas.saveBlendMode(item.blendMode);
1054
+ if (item.originPaint.blendMode) {
1055
+ canvas.saveBlendMode(item.originPaint.blendMode);
1055
1056
  isText ? draw.Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
1056
1057
  canvas.restoreBlendMode();
1057
1058
  } else {
@@ -1148,62 +1149,63 @@ function compute(attrName, ui) {
1148
1149
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1149
1150
  isTransparent = true;
1150
1151
  }
1151
- }
1152
- if (attrName === "fill") {
1153
- stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1154
- stintSet(data, "__isTransparentFill", isTransparent);
1152
+ if (attrName === "fill") {
1153
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1154
+ stintSet(data, "__isTransparentFill", isTransparent);
1155
+ } else {
1156
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1157
+ stintSet(data, "__isTransparentStroke", isTransparent);
1158
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1159
+ }
1155
1160
  } else {
1156
- stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1157
- stintSet(data, "__isTransparentStroke", isTransparent);
1158
- stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1161
+ data.__removePaint(attrName, false);
1159
1162
  }
1160
1163
  }
1161
1164
 
1162
1165
  function getLeafPaint(attrName, paint, ui) {
1163
1166
  if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1164
- let data;
1167
+ let leafPaint;
1165
1168
  const {boxBounds: boxBounds} = ui.__layout;
1166
1169
  switch (paint.type) {
1167
1170
  case "image":
1168
- data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1171
+ leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1169
1172
  break;
1170
1173
 
1171
1174
  case "linear":
1172
- data = draw.PaintGradient.linearGradient(paint, boxBounds);
1175
+ leafPaint = draw.PaintGradient.linearGradient(paint, boxBounds);
1173
1176
  break;
1174
1177
 
1175
1178
  case "radial":
1176
- data = draw.PaintGradient.radialGradient(paint, boxBounds);
1179
+ leafPaint = draw.PaintGradient.radialGradient(paint, boxBounds);
1177
1180
  break;
1178
1181
 
1179
1182
  case "angular":
1180
- data = draw.PaintGradient.conicGradient(paint, boxBounds);
1183
+ leafPaint = draw.PaintGradient.conicGradient(paint, boxBounds);
1181
1184
  break;
1182
1185
 
1183
1186
  case "solid":
1184
1187
  const {type: type, color: color, opacity: opacity} = paint;
1185
- data = {
1188
+ leafPaint = {
1186
1189
  type: type,
1187
1190
  style: draw.ColorConvert.string(color, opacity)
1188
1191
  };
1189
1192
  break;
1190
1193
 
1191
1194
  default:
1192
- if (!core.isUndefined(paint.r)) data = {
1195
+ if (!core.isUndefined(paint.r)) leafPaint = {
1193
1196
  type: "solid",
1194
1197
  style: draw.ColorConvert.string(paint)
1195
1198
  };
1196
1199
  }
1197
- if (data) {
1198
- if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1200
+ if (leafPaint) {
1201
+ leafPaint.originPaint = paint;
1202
+ if (core.isString(leafPaint.style) && hasTransparent$1(leafPaint.style)) leafPaint.isTransparent = true;
1199
1203
  if (paint.style) {
1200
1204
  if (paint.style.strokeWidth === 0) return undefined;
1201
- data.strokeStyle = paint.style;
1205
+ leafPaint.strokeStyle = paint.style;
1202
1206
  }
1203
- if (paint.editing) data.editing = paint.editing;
1204
- if (paint.blendMode) data.blendMode = paint.blendMode;
1205
1207
  }
1206
- return data;
1208
+ return leafPaint;
1207
1209
  }
1208
1210
 
1209
1211
  const PaintModule = {
@@ -1336,10 +1338,6 @@ const tempScaleData = {};
1336
1338
  const tempImage = {};
1337
1339
 
1338
1340
  function createData(leafPaint, image, paint, box) {
1339
- const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1340
- if (changeful) leafPaint.changeful = changeful;
1341
- if (sync) leafPaint.sync = sync;
1342
- if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1343
1341
  leafPaint.data = draw.PaintImage.getPatternData(paint, box, image);
1344
1342
  }
1345
1343
 
@@ -1599,14 +1597,14 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1599
1597
 
1600
1598
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1601
1599
  const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1602
- const {image: image, data: data} = paint, {exporting: exporting} = renderOptions;
1600
+ const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting} = renderOptions;
1603
1601
  if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting) {
1604
1602
  return false;
1605
1603
  } else {
1606
1604
  if (drawImage) {
1607
1605
  if (data.repeat) {
1608
1606
  drawImage = false;
1609
- } else if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1607
+ } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1610
1608
  drawImage = core.Platform.image.isLarge(image, scaleX, scaleY);
1611
1609
  }
1612
1610
  }
@@ -1618,16 +1616,16 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1618
1616
  draw.PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
1619
1617
  return true;
1620
1618
  } else {
1621
- if (!paint.style || paint.sync || exporting) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions); else draw.PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1619
+ if (!paint.style || originPaint.sync || exporting) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions); else draw.PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1622
1620
  return false;
1623
1621
  }
1624
1622
  }
1625
1623
  }
1626
1624
 
1627
1625
  function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1628
- const {data: data, image: image, blendMode: blendMode} = paint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1626
+ const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1629
1627
  let {width: width, height: height} = image, clipUI;
1630
- if (transform && !transform.onlyScale || (clipUI = u.path || u.cornerRadius) || opacity || blendMode) {
1628
+ if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1631
1629
  canvas.save();
1632
1630
  clipUI && canvas.clipUI(ui);
1633
1631
  blendMode && (canvas.blendMode = blendMode);
@@ -1642,7 +1640,7 @@ function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions
1642
1640
  }
1643
1641
 
1644
1642
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
1645
- const scaleData = ui.getRenderScaleData(true, paint.scaleFixed), {data: data} = paint;
1643
+ const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
1646
1644
  if (canvas) {
1647
1645
  const {pixelRatio: pixelRatio} = canvas;
1648
1646
  scaleData.scaleX *= pixelRatio;
package/dist/web.esm.js CHANGED
@@ -878,30 +878,31 @@ function fill(fill, ui, canvas, renderOptions) {
878
878
  }
879
879
 
880
880
  function fills(fills, ui, canvas, renderOptions) {
881
- let item;
881
+ let item, originPaint, countImage;
882
882
  for (let i = 0, len = fills.length; i < len; i++) {
883
- item = fills[i];
883
+ item = fills[i], originPaint = item.originPaint;
884
884
  if (item.image) {
885
+ countImage ? countImage++ : countImage = 1;
885
886
  if (PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue;
886
887
  if (!item.style) {
887
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(item.image, canvas, renderOptions);
888
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions);
888
889
  continue;
889
890
  }
890
891
  }
891
892
  canvas.fillStyle = item.style;
892
- if (item.transform || item.scaleFixed) {
893
+ if (item.transform || originPaint.scaleFixed) {
893
894
  canvas.save();
894
895
  if (item.transform) canvas.transform(item.transform);
895
- if (item.scaleFixed) {
896
+ if (originPaint.scaleFixed) {
896
897
  const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
897
- if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
898
+ if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
898
899
  }
899
- if (item.blendMode) canvas.blendMode = item.blendMode;
900
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
900
901
  fillPathOrText(ui, canvas, renderOptions);
901
902
  canvas.restore();
902
903
  } else {
903
- if (item.blendMode) {
904
- canvas.saveBlendMode(item.blendMode);
904
+ if (originPaint.blendMode) {
905
+ canvas.saveBlendMode(originPaint.blendMode);
905
906
  fillPathOrText(ui, canvas, renderOptions);
906
907
  canvas.restoreBlendMode();
907
908
  } else fillPathOrText(ui, canvas, renderOptions);
@@ -1054,8 +1055,8 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas, renderO
1054
1055
  const {strokeStyle: strokeStyle} = item;
1055
1056
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
1056
1057
  } else canvas.strokeStyle = item.style;
1057
- if (item.blendMode) {
1058
- canvas.saveBlendMode(item.blendMode);
1058
+ if (item.originPaint.blendMode) {
1059
+ canvas.saveBlendMode(item.originPaint.blendMode);
1059
1060
  isText ? Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
1060
1061
  canvas.restoreBlendMode();
1061
1062
  } else {
@@ -1152,62 +1153,63 @@ function compute(attrName, ui) {
1152
1153
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1153
1154
  isTransparent = true;
1154
1155
  }
1155
- }
1156
- if (attrName === "fill") {
1157
- stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1158
- stintSet(data, "__isTransparentFill", isTransparent);
1156
+ if (attrName === "fill") {
1157
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1158
+ stintSet(data, "__isTransparentFill", isTransparent);
1159
+ } else {
1160
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1161
+ stintSet(data, "__isTransparentStroke", isTransparent);
1162
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1163
+ }
1159
1164
  } else {
1160
- stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1161
- stintSet(data, "__isTransparentStroke", isTransparent);
1162
- stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1165
+ data.__removePaint(attrName, false);
1163
1166
  }
1164
1167
  }
1165
1168
 
1166
1169
  function getLeafPaint(attrName, paint, ui) {
1167
1170
  if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1168
- let data;
1171
+ let leafPaint;
1169
1172
  const {boxBounds: boxBounds} = ui.__layout;
1170
1173
  switch (paint.type) {
1171
1174
  case "image":
1172
- data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1175
+ leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1173
1176
  break;
1174
1177
 
1175
1178
  case "linear":
1176
- data = PaintGradient.linearGradient(paint, boxBounds);
1179
+ leafPaint = PaintGradient.linearGradient(paint, boxBounds);
1177
1180
  break;
1178
1181
 
1179
1182
  case "radial":
1180
- data = PaintGradient.radialGradient(paint, boxBounds);
1183
+ leafPaint = PaintGradient.radialGradient(paint, boxBounds);
1181
1184
  break;
1182
1185
 
1183
1186
  case "angular":
1184
- data = PaintGradient.conicGradient(paint, boxBounds);
1187
+ leafPaint = PaintGradient.conicGradient(paint, boxBounds);
1185
1188
  break;
1186
1189
 
1187
1190
  case "solid":
1188
1191
  const {type: type, color: color, opacity: opacity} = paint;
1189
- data = {
1192
+ leafPaint = {
1190
1193
  type: type,
1191
1194
  style: ColorConvert.string(color, opacity)
1192
1195
  };
1193
1196
  break;
1194
1197
 
1195
1198
  default:
1196
- if (!isUndefined(paint.r)) data = {
1199
+ if (!isUndefined(paint.r)) leafPaint = {
1197
1200
  type: "solid",
1198
1201
  style: ColorConvert.string(paint)
1199
1202
  };
1200
1203
  }
1201
- if (data) {
1202
- if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1204
+ if (leafPaint) {
1205
+ leafPaint.originPaint = paint;
1206
+ if (isString(leafPaint.style) && hasTransparent$1(leafPaint.style)) leafPaint.isTransparent = true;
1203
1207
  if (paint.style) {
1204
1208
  if (paint.style.strokeWidth === 0) return undefined;
1205
- data.strokeStyle = paint.style;
1209
+ leafPaint.strokeStyle = paint.style;
1206
1210
  }
1207
- if (paint.editing) data.editing = paint.editing;
1208
- if (paint.blendMode) data.blendMode = paint.blendMode;
1209
1211
  }
1210
- return data;
1212
+ return leafPaint;
1211
1213
  }
1212
1214
 
1213
1215
  const PaintModule = {
@@ -1340,10 +1342,6 @@ const tempScaleData = {};
1340
1342
  const tempImage = {};
1341
1343
 
1342
1344
  function createData(leafPaint, image, paint, box) {
1343
- const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1344
- if (changeful) leafPaint.changeful = changeful;
1345
- if (sync) leafPaint.sync = sync;
1346
- if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1347
1345
  leafPaint.data = PaintImage.getPatternData(paint, box, image);
1348
1346
  }
1349
1347
 
@@ -1603,14 +1601,14 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1603
1601
 
1604
1602
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1605
1603
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1606
- const {image: image, data: data} = paint, {exporting: exporting} = renderOptions;
1604
+ const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting} = renderOptions;
1607
1605
  if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting) {
1608
1606
  return false;
1609
1607
  } else {
1610
1608
  if (drawImage) {
1611
1609
  if (data.repeat) {
1612
1610
  drawImage = false;
1613
- } else if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
1611
+ } else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
1614
1612
  drawImage = Platform.image.isLarge(image, scaleX, scaleY);
1615
1613
  }
1616
1614
  }
@@ -1622,16 +1620,16 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1622
1620
  PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
1623
1621
  return true;
1624
1622
  } else {
1625
- if (!paint.style || paint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1623
+ if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1626
1624
  return false;
1627
1625
  }
1628
1626
  }
1629
1627
  }
1630
1628
 
1631
1629
  function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1632
- const {data: data, image: image, blendMode: blendMode} = paint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1630
+ const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1633
1631
  let {width: width, height: height} = image, clipUI;
1634
- if (transform && !transform.onlyScale || (clipUI = u.path || u.cornerRadius) || opacity || blendMode) {
1632
+ if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1635
1633
  canvas.save();
1636
1634
  clipUI && canvas.clipUI(ui);
1637
1635
  blendMode && (canvas.blendMode = blendMode);
@@ -1646,7 +1644,7 @@ function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions
1646
1644
  }
1647
1645
 
1648
1646
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
1649
- const scaleData = ui.getRenderScaleData(true, paint.scaleFixed), {data: data} = paint;
1647
+ const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
1650
1648
  if (canvas) {
1651
1649
  const {pixelRatio: pixelRatio} = canvas;
1652
1650
  scaleData.scaleX *= pixelRatio;
@@ -1,2 +1,2 @@
1
- import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as d,Creator as h,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as k,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,FourNumberHelper as A,Matrix as T,ImageEvent as O,MatrixHelper as C,MathHelper as M,AlignHelper as P,PointHelper as W,getMatrixData as D,AroundHelper as I,Direction4 as F,isNumber as z}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{Paint as Y,PaintImage as U,ColorConvert as V,PaintGradient as X,Effect as G,Group as N,TextConvert as q}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const j=t.get("LeaferCanvas");class H extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.display="none",document.body&&document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else j.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),j.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),this.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Q,fileType:Z}=d;function $(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Q(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Q(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q(Z(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=h.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(h,{canvas:(t,e)=>new H(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:J}=navigator;J.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),J.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):J.indexOf("Mac")>-1?i.os="Mac":J.indexOf("Linux")>-1&&(i.os="Linux");class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;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 f,this.target=t,e&&(this.config=a.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(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.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 _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:tt,updateBounds:et,updateChange:it}=m,{pushAllChildBranch:st,pushAllParent:nt}=y;const{worldBounds:at}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,at),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:rt,updateAllChange:lt}=m,dt=t.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new S,this.target=t,e&&(this.config=a.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.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(k.START),this.layoutOnce(),t.emitEvent(new k(k.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.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=B.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=k,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new k(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?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(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||et(s[t])}et(i)}})}(this.__levelList),function(t){t.list.forEach(it)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new k(a,r,this.times)),i.emitEvent(new k(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,B.end(e)}fullLayout(){const t=B.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=k,a=this.getBlocks(new f(e));e.emitEvent(new k(i,a,this.times)),ht.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new k(s,a,this.times)),e.emitEvent(new k(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){rt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),lt(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(){this.__eventIds=[this.target.on_([[k.REQUEST,this.layout,this],[k.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ct=t.get("Renderer");class ut{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:120},this.frames=[],this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(k.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ct.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ct.error(t)}ct.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ct.warn("rendering");if(this.times>3)return ct.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.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;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ut.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,s){const{canvas:n}=this,a=e.includes(this.target.__world),o=a?{includes:a}:{bounds:e,includes:a};this.needFill&&n.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(n,e),i.render(this.target,n,o),this.renderBounds=s=s||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),n.updateRender(s)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);this.requestTime=this.frameTime||Date.now();const e=()=>{const t=1e3/((this.frameTime=Date.now())-this.requestTime),{maxFPS:s}=this.config;if(s&&t>s)return i.requestRender(e);const{frames:n}=this;n.length>30&&n.shift(),n.push(t),this.FPS=Math.round(n.reduce((t,e)=>t+e,0)/n.length),this.requestTime=0,this.checkRender()};i.requestRender(e)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(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 x(0,0,1,1)),this.update()}}__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||ct.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 p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[k.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function ft(t,e,i){t.__.__font?Y.fillText(t,e,i):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function pt(t,e,i,s,n){const a=i.__;E(t)?Y.drawStrokesStyle(t,e,!1,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),s.stroke()),a.__useArrow&&Y.strokeArrow(t,i,s,n)}function gt(t,e,i,s,n){const a=i.__;E(t)?Y.drawStrokesStyle(t,e,!0,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),Y.drawTextStroke(i,s,n))}function _t(t,e,i,s,n){const a=s.getSameCanvas(!0,!0);a.font=i.__.__font,gt(t,2,i,a,n),a.blendMode="outside"===e?"destination-out":"destination-in",Y.fillText(i,a,n),a.blendMode="normal",m.copyCanvasByWorld(i,s,a),a.recycle(i.__nowWorld)}ut.clipSpread=10,Object.assign(h,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new ut(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ht.fullLayout,i.render=function(t,e,i){const s=Object.assign(Object.assign({},i),{topRendering:!0});i.topList=new f,t.__render(e,i),i.topList.length&&i.topList.forEach(t=>t.__render(e,s))};const{getSpread:wt,copyAndSpread:mt,toOuterOf:yt,getOuterOf:vt,getByMove:xt,move:bt,getIntersectData:St}=L,kt={};let Bt;const{stintSet:Rt}=a,{hasTransparent:Et}=V;function Lt(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=U.image(i,t,e,o,!Bt||!Bt[e.url]);break;case"linear":a=X.linearGradient(e,o);break;case"radial":a=X.radialGradient(e,o);break;case"angular":a=X.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:V.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:V.string(e)})}if(a){if(s(a.style)&&Et(a.style)&&(a.isTransparent=!0),e.style){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}e.editing&&(a.editing=e.editing),e.blendMode&&(a.blendMode=e.blendMode)}return a}const At={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Bt=U.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=Lt(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Rt(i,"__isAlphaPixelFill",n),Rt(i,"__isTransparentFill",a)):(Rt(i,"__isAlphaPixelStroke",n),Rt(i,"__isTransparentStroke",a),Rt(i,"__hasMultiStrokeStyle",o))},fill:function(t,e,i,s){i.fillStyle=t,ft(e,i,s)},fills:function(t,e,i,s){let n;for(let a=0,o=t.length;a<o;a++){if(n=t[a],n.image){if(U.checkImage(n,!e.__.__font,e,i,s))continue;if(!n.style){!a&&n.image.isPlacehold&&e.drawImagePlaceholder(n.image,i,s);continue}}if(i.fillStyle=n.style,n.transform||n.scaleFixed){if(i.save(),n.transform&&i.transform(n.transform),n.scaleFixed){const{scaleX:t,scaleY:s}=e.getRenderScaleData(!0);(!0===n.scaleFixed||"zoom-in"===n.scaleFixed&&t>1&&s>1)&&i.scale(1/t,1/s)}n.blendMode&&(i.blendMode=n.blendMode),ft(e,i,s),i.restore()}else n.blendMode?(i.saveBlendMode(n.blendMode),ft(e,i,s),i.restoreBlendMode()):ft(e,i,s)}},fillPathOrText:ft,fillText:function(t,e,i){const s=t.__,{rows:n,decorationY:a}=s.__textDrawData;let o;s.__isPlacehold&&s.placeholderColor&&(e.fillStyle=s.placeholderColor);for(let t=0,i=n.length;t<i;t++)o=n[t],o.text?e.fillText(o.text,o.x,o.y):o.data&&o.data.forEach(t=>{e.fillText(t.char,t.x,o.y)});if(a){const{decorationColor:t,decorationHeight:i}=s.__textDrawData;t&&(e.fillStyle=t),n.forEach(t=>a.forEach(s=>e.fillRect(t.x,t.y+s,t.width,i)))}},stroke:function(t,e,i,s){const n=e.__;if(n.__strokeWidth)if(n.__font)Y.strokeText(t,e,i,s);else switch(n.strokeAlign){case"center":pt(t,1,e,i,s);break;case"inside":!function(t,e,i,s){i.save(),i.clipUI(e),pt(t,2,e,i,s),i.restore()}(t,e,i,s);break;case"outside":!function(t,e,i,s){const n=e.__;if(n.__fillAfterStroke)pt(t,2,e,i,s);else{const{renderBounds:a}=e.__layout,o=i.getSameCanvas(!0,!0);e.__drawRenderPath(o),pt(t,2,e,o,s),o.clipUI(n),o.clearWorld(a),m.copyCanvasByWorld(e,i,o),o.recycle(e.__nowWorld)}}(t,e,i,s)}},strokes:function(t,e,i,s){Y.stroke(t,e,i,s)},strokeText:function(t,e,i,s){switch(e.__.strokeAlign){case"center":gt(t,1,e,i,s);break;case"inside":_t(t,"inside",e,i,s);break;case"outside":e.__.__fillAfterStroke?gt(t,2,e,i,s):_t(t,"outside",e,i,s)}},drawTextStroke:function(t,e,i){let s,n=t.__.__textDrawData;const{rows:a,decorationY:o}=n;for(let t=0,i=a.length;t<i;t++)s=a[t],s.text?e.strokeText(s.text,s.x,s.y):s.data&&s.data.forEach(t=>{e.strokeText(t.char,t.x,s.y)});if(o){const{decorationHeight:t}=n;a.forEach(i=>o.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}},drawStrokesStyle:function(t,e,i,s,n,a){let o;const r=s.__,{__hasMultiStrokeStyle:l}=r;l||n.setStroke(void 0,r.__strokeWidth*e,r);for(let d=0,h=t.length;d<h;d++)if(o=t[d],(!o.image||!U.checkImage(o,!1,s,n,a))&&o.style){if(l){const{strokeStyle:t}=o;t?n.setStroke(o.style,r.__getRealStrokeWidth(t)*e,r,t):n.setStroke(o.style,r.__strokeWidth*e,r)}else n.strokeStyle=o.style;o.blendMode?(n.saveBlendMode(o.blendMode),i?Y.drawTextStroke(s,n,a):n.stroke(),n.restoreBlendMode()):i?Y.drawTextStroke(s,n,a):n.stroke()}},shape:function(t,e,s){const n=e.getSameCanvas(),a=e.bounds,o=t.__nowWorld,r=t.__layout,l=t.__nowWorldShapeBounds||(t.__nowWorldShapeBounds={});let d,h,c,u,f,p;yt(r.strokeSpread?(mt(kt,r.boxBounds,r.strokeSpread),kt):r.boxBounds,o,l);let{scaleX:g,scaleY:_}=t.getRenderScaleData(!0);if(a.includes(l))p=n,d=f=l,h=o;else{let n;if(i.fullImageShadow)n=l;else{const t=r.renderShapeSpread?wt(a,A.swapAndScale(r.renderShapeSpread,g,_)):a;n=St(t,l)}u=a.getFitMatrix(n);let{a:w,d:m}=u;u.a<1&&(p=e.getSameCanvas(),t.__renderShape(p,s),g*=w,_*=m),f=vt(l,u),d=xt(f,-u.e,-u.f),h=vt(o,u),bt(h,-u.e,-u.f);const y=s.matrix;y?(c=new T(u),c.multiply(y),w*=y.scaleX,m*=y.scaleY):c=u,c.withScale(w,m),s=Object.assign(Object.assign({},s),{matrix:c})}return t.__renderShape(n,s),{canvas:n,matrix:c,fitMatrix:u,bounds:d,renderBounds:h,worldCanvas:p,shapeBounds:f,scaleX:g,scaleY:_}}};let Tt,Ot=new x;const{isSame:Ct}=L;function Mt(t,e,i,s,n,a){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||U.createData(n,s,i,a),!0}function Pt(t,e){It(t,O.LOAD,e)}function Wt(t,e){It(t,O.LOADED,e)}function Dt(t,e,i){e.error=i,t.forceUpdate("surface"),It(t,O.ERROR,e)}function It(t,e,i){t.hasEvent(e)&&t.emitEvent(new O(e,i))}function Ft(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:zt,translate:Yt}=C,Ut=new x,Vt={},Xt={};function Gt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let Nt={},qt=D();const{get:jt,set:Ht,rotateOfOuter:Qt,translate:Zt,scaleOfOuter:$t,multiplyParent:Jt,scale:Kt,rotate:te,skew:ee}=C;function ie(t,e,i,s,n,a,o,r){o&&te(t,o),r&&ee(t,r.x,r.y),n&&Kt(t,n,a),Zt(t,e.x+i,e.y+s)}function se(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const{get:ne,scale:ae,copy:oe}=C,{getFloorScale:re}=M,{abs:le}=Math;const de={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return Tt&&i===Tt.paint&&Ct(s,Tt.boxBounds)?a=Tt.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),Tt=r.use>1?{leafPaint:a,paint:i,boxBounds:Ot.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(Mt(t,e,i,r,a,s),n&&(Pt(t,o),Wt(t,o))):r.error?n&&Dt(t,o,r.error):(n&&(Ft(t,!0),Pt(t,o)),a.loadId=r.load(()=>{Ft(t,!1),t.destroyed||(Mt(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Wt(t,o)),a.loadId=void 0},e=>{Ft(t,!1),Dt(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n,a){const{scaleX:o,scaleY:l}=U.getImageRenderScaleData(t,s,n,a),{image:d,data:h}=t,{exporting:c}=a;return!(!h||t.patternId===o+"-"+l&&!c)&&(e&&(h.repeat?e=!1:t.changeful||"miniapp"===i.name&&r.isResizing(s)||c||(e=i.image.isLarge(d,o,l))),e?(s.__.__isFastShadow&&(n.fillStyle=t.style||"#000",n.fill()),U.drawImage(t,o,l,s,n,a),!0):(!t.style||t.sync||c?U.createPattern(t,s,n,a):U.createPatternTask(t,s,n,a),!1))},drawImage:function(t,e,i,s,n,a){const{data:o,image:r,blendMode:l}=t,{opacity:d,transform:h}=o,c=r.getFull(o.filters),u=s.__;let f,{width:p,height:g}=r;h&&!h.onlyScale||(f=u.path||u.cornerRadius)||d||l?(n.save(),f&&n.clipUI(s),l&&(n.blendMode=l),d&&(n.opacity*=d),h&&n.transform(h),n.drawImage(c,0,0,p,g),n.restore()):(o.scaleX&&(p*=o.scaleX,g*=o.scaleY),n.drawImage(c,0,0,p,g))},getImageRenderScaleData:function(t,e,i,s){const n=e.getRenderScaleData(!0,t.scaleFixed),{data:a}=t;if(i){const{pixelRatio:t}=i;n.scaleX*=t,n.scaleY*=t}return a&&a.scaleX&&(n.scaleX*=Math.abs(a.scaleX),n.scaleY*=Math.abs(a.scaleY)),n},recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,d=i.length;l<d;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createPatternTask:function(t,e,i,s){t.patternTask||(t.patternTask=R.patternTasker.add(()=>se(this,void 0,void 0,function*(){t.patternTask=null,i.bounds.hit(e.__nowWorld)&&U.createPattern(t,e,i,s),e.forceUpdate("surface")}),300))},createPattern:function(t,e,s,n){let{scaleX:a,scaleY:o}=U.getImageRenderScaleData(t,e,s,n),r=a+"-"+o;if(t.patternId!==r&&!e.destroyed&&(!i.image.isLarge(t.image,a,o)||t.data.repeat)){const{image:s,data:n}=t,{transform:l,gap:d}=n,h=U.getPatternFixScale(t,a,o);let c,u,f,{width:p,height:g}=s;h&&(a*=h,o*=h),p*=a,g*=o,d&&(u=d.x*a/le(n.scaleX||1),f=d.y*o/le(n.scaleY||1)),(l||1!==a||1!==o)&&(a*=re(p+(u||0)),o*=re(g+(f||0)),c=ne(),l&&oe(c,l),ae(c,1/a,1/o));const _=s.getCanvas(p,g,n.opacity,n.filters,u,f,e.leafer&&e.leafer.config.smooth),w=s.getPattern(_,n.repeat||i.origin.noRepeat||"no-repeat",c,t);t.style=w,t.patternId=r}},getPatternFixScale:function(t,e,s){const{image:n}=t;let a,o=i.image.maxPatternSize,r=n.width*n.height;return n.isSVG?e>1&&(a=Math.ceil(e)/e):o>r&&(o=r),(r*=e*s)>o&&(a=Math.sqrt(o/r)),a},createData:function(t,e,i,s){const{changeful:n,sync:a,scaleFixed:o}=i;n&&(t.changeful=n),a&&(t.sync=a),o&&(t.scaleFixed=o),t.data=U.getPatternData(i,s,e)},getPatternData:function(t,e,i){t.padding&&(e=Ut.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{width:n,height:a}=i,{opacity:o,mode:r,align:l,offset:d,scale:h,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(Xt,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((h||c)&&(M.getScaleData(h,c,i,Vt),x=Vt.scaleX,b=Vt.scaleY),(l||_||g)&&(x&&L.scale(Xt,x,b,!0),l&&P.toPoint(l,Xt,e,Xt,!0,!0))):m&&!u||(x=b=L.getFitScale(e,Xt,"fit"!==r),L.put(e,i,l,x,!1,Xt),L.scale(Xt,x,b,!0)),d&&W.move(Xt,d),r){case"stretch":m?x&&(x=b=void 0):(x=e.width/n,b=e.height/a,U.stretchMode(y,e,x,b));break;case"normal":case"clip":if(Xt.x||Xt.y||x||p||u||f){let t,i;p&&(t=e.width/p.width,i=e.height/p.height),U.clipMode(y,e,Xt.x,Xt.y,x,b,u,f,t,i),t&&(x=x?x*t:t,b=b?b*i:i)}break;case"repeat":(!m||x||u||f)&&U.repeatMode(y,e,n,a,Xt.x,Xt.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:Gt(a,i,n.width,e&&e.x),y:Gt(o,s,n.height,e&&e.y)}}(_,i&&g,Xt.width,Xt.height,e));break;default:x&&U.fillOrFitMode(y,e,Xt.x,Xt.y,x,b,u)}return y.transform||(e.x||e.y)&&Yt(y.transform=zt(),e.x,e.y),x&&(y.scaleX=x,y.scaleY=b),o&&o<1&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y},stretchMode:function(t,e,i,s){const n=jt(),{x:a,y:o}=e;a||o?Zt(n,a,o):n.onlyScale=!0,Kt(n,i,s),t.transform=n},fillOrFitMode:function(t,e,i,s,n,a,o){const r=jt();Zt(r,e.x+i,e.y+s),Kt(r,n,a),o&&Qt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r},clipMode:function(t,e,i,s,n,a,o,r,l,d){const h=jt();ie(h,e,i,s,n,a,o,r),l&&(o||r?(Ht(qt),$t(qt,e,l,d),Jt(h,qt)):$t(h,e,l,d)),t.transform=h},repeatMode:function(t,e,i,s,n,a,o,r,l,d,h,c){const u=jt();if(c)ie(u,e,n,a,o,r,l,d);else{if(l)if("center"===h)Qt(u,{x:i/2,y:s/2},l);else switch(te(u,l),l){case 90:Zt(u,s,0);break;case 180:Zt(u,i,s);break;case 270:Zt(u,0,i)}Nt.x=e.x+n,Nt.y=e.y+a,Zt(u,Nt.x,Nt.y),o&&$t(u,Nt,o,r)}t.transform=u}},{toPoint:he}=I,{hasTransparent:ce}=V,ue={},fe={};function pe(t,e,i,n){if(i){let a,o,r,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(r=t/(d-1),o=V.string(a,n)):(r=a.offset,o=V.string(a.color,n)),e.addColorStop(r,o),!l&&ce(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:ge,getDistance:_e}=W,{get:we,rotateOfOuter:me,scaleOfOuter:ye}=C,{toPoint:ve}=I,xe={},be={};function Se(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=ge(e,i);a=we(),n?(ye(a,e,o/r*(s||1),1),me(a,e,t+90)):(ye(a,e,1,o/r*(s||1)),me(a,e,t))}return a}const{getDistance:ke}=W,{toPoint:Be}=I,Re={},Ee={};const Le={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;he(s||"top",e,ue),he(n||"bottom",e,fe);const r=i.canvas.createLinearGradient(ue.x,ue.y,fe.x,fe.y),l={type:a,style:r};return pe(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;ve(s||"center",e,xe),ve(n||"bottom",e,be);const l=i.canvas.createRadialGradient(xe.x,xe.y,0,xe.x,xe.y,_e(xe,be)),d={type:a,style:l};pe(d,l,t.stops,o);const h=Se(e,xe,be,r,!0);return h&&(d.transform=h),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;Be(s||"center",e,Re),Be(n||"bottom",e,Ee);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Re.x,Re.y):i.canvas.createRadialGradient(Re.x,Re.y,0,Re.x,Re.y,ke(Re,Ee)),d={type:a,style:l};pe(d,l,t.stops,o);const h=Se(e,Re,Ee,r||1,i.conicGradientRotate90);return h&&(d.transform=h),d},getTransform:Se},{copy:Ae,move:Te,toOffsetOutBounds:Oe}=L,{max:Ce,abs:Me}=Math,Pe={},We=new T,De={};function Ie(t,e){let i,s,n,a,o=0,r=0,l=0,d=0;return e.forEach(t=>{i=t.x||0,s=t.y||0,a=1.5*(t.blur||0),n=Me(t.spread||0),o=Ce(o,n+a-s),r=Ce(r,n+a+i),l=Ce(l,n+a+s),d=Ce(d,n+a-i)}),o===r&&r===l&&l===d?o:[o,r,l,d]}function Fe(t,e,s){const{shapeBounds:n}=s;let a,o;i.fullImageShadow?(Ae(Pe,t.bounds),Te(Pe,e.x-n.x,e.y-n.y),a=t.bounds,o=Pe):(a=n,o=e),t.copyWorld(s.canvas,a,o)}const{toOffsetOutBounds:ze}=L,Ye={};const Ue=Ie;const Ve={shadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{shadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;Oe(l,De,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(De.offsetX+(o.x||0)*c*_,De.offsetY+(o.y||0)*u*_,(o.blur||0)*c*_,V.string(o.color)),n=G.getShadowTransform(t,f,i,o,De,_),n&&f.setTransform(n),Fe(f,De,i),n&&f.resetTransform(),s=d,o.box&&(f.restore(),f.save(),r&&(f.copyWorld(f,d,a,"copy"),s=a),r?f.copyWorld(r,a,a,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{innerShadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;ze(l,Ye,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ye.offsetX+(o.x||0)*c*_,Ye.offsetY+(o.y||0)*u*_,(o.blur||0)*c*_),n=G.getShadowTransform(t,f,i,o,Ye,_,!0),n&&f.setTransform(n),Fe(f,Ye,i),f.restore(),r?(f.copyWorld(f,d,a,"copy"),f.copyWorld(r,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,h,l,"source-out"),s=d),f.fillWorld(s,V.string(o.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),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){},getShadowRenderSpread:Ie,getShadowTransform:function(t,e,i,s,n,a,o){if(s.spread){const i=2*s.spread*a*(o?-1:1),{width:r,height:l}=t.__layout.strokeBounds;return We.set().scaleOfOuter({x:(n.x+n.width/2)*e.pixelRatio,y:(n.y+n.height/2)*e.pixelRatio},1+i/r,1+i/l),We}},isTransformShadow(t){},getInnerShadowSpread:Ue},{excludeRenderBounds:Xe}=v;let Ge;function Ne(t,e,i,s,n,a,o,r){switch(e){case"grayscale":Ge||(Ge=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);je(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":je(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function qe(t){return t.getSameCanvas(!1,!0)}function je(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}N.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let d=0,h=l.length;d<h;d++){if(i=l[d],r=i.__.mask,r){o&&(Ne(this,o,t,n,s,a,void 0,!0),s=n=null),"clipping"!==r&&"clipping-path"!==r||Xe(i,e)||i.__render(t,e),a=i.__.opacity,Ge=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=qe(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=qe(t)),n||(n=qe(t)),i.__render(s,e));continue}const h=1===a&&i.__.__blendMode;h&&Ne(this,o,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),h&&Ne(this,o,t,n,s,a,h,!1)}Ne(this,o,t,n,s,a,void 0,!0)};const He=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Qe=He+"_#~&*+\\=|≮≯≈≠=…",Ze=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 $e(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const Je=$e("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ke=$e("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ti=$e(He),ei=$e(Qe),ii=$e("- —/~|┆·");var si;!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"}(si||(si={}));const{Letter:ni,Single:ai,Before:oi,After:ri,Symbol:li,Break:di}=si;function hi(t){return Je[t]?ni:ii[t]?di:Ke[t]?oi:ti[t]?ri:ei[t]?li:Ze.test(t)?ai:ni}const ci={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ui(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:fi}=ci,{Letter:pi,Single:gi,Before:_i,After:wi,Symbol:mi,Break:yi}=si;let vi,xi,bi,Si,ki,Bi,Ri,Ei,Li,Ai,Ti,Oi,Ci,Mi,Pi,Wi,Di,Ii=[];function Fi(t,e){Li&&!Ei&&(Ei=Li),vi.data.push({char:t,width:e}),bi+=e}function zi(){Si+=bi,vi.width=bi,xi.words.push(vi),vi={data:[]},bi=0}function Yi(){Mi&&(Pi.paraNumber++,xi.paraStart=!0,Mi=!1),Li&&(xi.startCharSize=Ei,xi.endCharSize=Li,Ei=0),xi.width=Si,Wi.width?fi(xi):Di&&Ui(),Ii.push(xi),xi={words:[]},Si=0}function Ui(){Si>(Pi.maxWidth||0)&&(Pi.maxWidth=Si)}const{top:Vi,right:Xi,bottom:Gi,left:Ni}=F;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 ji={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{__padding:l}=e;l&&(o?(n=l[Ni],o-=l[Xi]+l[Ni],!o&&(o=.01)):e.autoSizeAlign||(n=l[Ni]),r?(a=l[Vi],r-=l[Vi]+l[Gi],!r&&(r=.01)):e.autoSizeAlign||(a=l[Vi]));const d={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=e.__font};return function(t,e,s){Pi=t,Ii=t.rows,Wi=t.bounds,Di=!Wi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l}=Wi;if(s.__isCharMode){const t="none"!==s.textWrap,i="break"===s.textWrap;Mi=!0,Ti=null,Ei=Ri=Li=bi=Si=0,vi={data:[]},xi={words:[]},n&&(e=[...e]);for(let s=0,d=e.length;s<d;s++)Bi=e[s],"\n"===Bi?(bi&&zi(),xi.paraEnd=!0,Yi(),Mi=!0):(Ai=hi(Bi),Ai===pi&&"none"!==o&&(Bi=ui(Bi,o,!bi)),Ri=r.measureText(Bi).width,n&&(n<0&&(Li=Ri),Ri+=n),Oi=Ai===gi&&(Ti===gi||Ti===pi)||Ti===gi&&Ai!==wi,Ci=!(Ai!==_i&&Ai!==gi||Ti!==mi&&Ti!==wi),ki=Mi&&a?l-a:l,t&&l&&Si+bi+Ri>ki&&(i?(bi&&zi(),Si&&Yi()):(Ci||(Ci=Ai===pi&&Ti==wi),Oi||Ci||Ai===yi||Ai===_i||Ai===gi||bi+Ri>ki?(bi&&zi(),Si&&Yi()):Si&&Yi()))," "===Bi&&!0!==Mi&&Si+bi===0||(Ai===yi?(" "===Bi&&bi&&zi(),Fi(Bi,Ri),zi()):Oi||Ci?(bi&&zi(),Fi(Bi,Ri)):Fi(Bi,Ri)),Ti=Ai);bi&&zi(),Si&&Yi(),Ii.length>0&&(Ii[Ii.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Pi.paraNumber++,Si=r.measureText(t).width,Ii.push({x:a||0,text:t,width:Si,paraStart:!0}),Di&&Ui()})}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":qi(e,"x",t[Ni]);break;case"right":qi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":qi(e,"y",t[Vi]);break;case"bottom":qi(e,"y",-t[Gi])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:d,verticalAlign:h,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(h){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,h=n;o<h;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(d,e),e.__isCharMode&&function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e,r=i&&n.includes("both"),l=r||i&&n.includes("justify"),d=l&&n.includes("letter");let h,c,u,f,p,g,_,w,m,y;s.forEach(t=>{t.words&&(p=a&&t.paraStart?a:0,w=t.words.length,l&&(y=!t.paraEnd||r,c=i-t.width-p,d?f=c/(t.words.reduce((t,e)=>t+e.data.length,0)-1):u=w>1?c/(w-1):0),g=o||t.isOverflow||d?0:u?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===g?(t.x+=p,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=p,h=t.x,t.data=[],t.words.forEach((e,i)=>{1===g?(_={char:"",x:h},h=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,h,_),(t.isOverflow||" "!==_.char)&&t.data.push(_)):h=function(t,e,i,s,n){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width,n&&(e+=n)}),e}(e.data,h,t.data,t.isOverflow,y&&f),y&&(m=i===w-1,u?m||(h+=u,t.width+=u):f&&(t.width+=f*(e.data.length-(m?1:0))))})),t.words=null)})}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?i.canvas.measureText(r).width:0,h=s+n-d;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<h));s--){if(l<h&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(d,e,n,o),"none"!==e.textDecoration&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=V.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(d,e),d}};const Hi={string:function(t,e){if(!t)return"#000";const i=z(e)&&e<1;if(s(t)){if(!i||!V.object)return t;t=V.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(q,ji),Object.assign(V,Hi),Object.assign(Y,At),Object.assign(U,de),Object.assign(X,Le),Object.assign(G,Ve),$();export{ht as Layouter,H as LeaferCanvas,ut as Renderer,K as Watcher,$ as useCanvas};
1
+ import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as d,Creator as h,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as k,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,FourNumberHelper as A,Matrix as T,ImageEvent as O,MatrixHelper as C,MathHelper as P,AlignHelper as W,PointHelper as D,getMatrixData as M,AroundHelper as I,Direction4 as F,isNumber as z}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{Paint as Y,PaintImage as U,ColorConvert as V,PaintGradient as X,Effect as G,Group as N,TextConvert as q}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const j=t.get("LeaferCanvas");class H extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.display="none",document.body&&document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else j.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),j.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),this.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Q,fileType:Z}=d;function $(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Q(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Q(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q(Z(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=h.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(h,{canvas:(t,e)=>new H(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:J}=navigator;J.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),J.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):J.indexOf("Mac")>-1?i.os="Mac":J.indexOf("Linux")>-1&&(i.os="Linux");class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;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 f,this.target=t,e&&(this.config=a.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(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.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 _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:tt,updateBounds:et,updateChange:it}=m,{pushAllChildBranch:st,pushAllParent:nt}=y;const{worldBounds:at}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,at),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:rt,updateAllChange:lt}=m,dt=t.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new S,this.target=t,e&&(this.config=a.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.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(k.START),this.layoutOnce(),t.emitEvent(new k(k.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.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=B.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=k,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new k(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?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(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||et(s[t])}et(i)}})}(this.__levelList),function(t){t.list.forEach(it)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new k(a,r,this.times)),i.emitEvent(new k(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,B.end(e)}fullLayout(){const t=B.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=k,a=this.getBlocks(new f(e));e.emitEvent(new k(i,a,this.times)),ht.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new k(s,a,this.times)),e.emitEvent(new k(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){rt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),lt(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(){this.__eventIds=[this.target.on_([[k.REQUEST,this.layout,this],[k.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ct=t.get("Renderer");class ut{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:120},this.frames=[],this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(k.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ct.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ct.error(t)}ct.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ct.warn("rendering");if(this.times>3)return ct.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.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;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ut.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,s){const{canvas:n}=this,a=e.includes(this.target.__world),o=a?{includes:a}:{bounds:e,includes:a};this.needFill&&n.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(n,e),i.render(this.target,n,o),this.renderBounds=s=s||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),n.updateRender(s)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);this.requestTime=this.frameTime||Date.now();const e=()=>{const t=1e3/((this.frameTime=Date.now())-this.requestTime),{maxFPS:s}=this.config;if(s&&t>s)return i.requestRender(e);const{frames:n}=this;n.length>30&&n.shift(),n.push(t),this.FPS=Math.round(n.reduce((t,e)=>t+e,0)/n.length),this.requestTime=0,this.checkRender()};i.requestRender(e)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(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 x(0,0,1,1)),this.update()}}__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||ct.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 p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[k.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function ft(t,e,i){t.__.__font?Y.fillText(t,e,i):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function pt(t,e,i,s,n){const a=i.__;E(t)?Y.drawStrokesStyle(t,e,!1,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),s.stroke()),a.__useArrow&&Y.strokeArrow(t,i,s,n)}function gt(t,e,i,s,n){const a=i.__;E(t)?Y.drawStrokesStyle(t,e,!0,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),Y.drawTextStroke(i,s,n))}function _t(t,e,i,s,n){const a=s.getSameCanvas(!0,!0);a.font=i.__.__font,gt(t,2,i,a,n),a.blendMode="outside"===e?"destination-out":"destination-in",Y.fillText(i,a,n),a.blendMode="normal",m.copyCanvasByWorld(i,s,a),a.recycle(i.__nowWorld)}ut.clipSpread=10,Object.assign(h,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new ut(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ht.fullLayout,i.render=function(t,e,i){const s=Object.assign(Object.assign({},i),{topRendering:!0});i.topList=new f,t.__render(e,i),i.topList.length&&i.topList.forEach(t=>t.__render(e,s))};const{getSpread:wt,copyAndSpread:mt,toOuterOf:yt,getOuterOf:vt,getByMove:xt,move:bt,getIntersectData:St}=L,kt={};let Bt;const{stintSet:Rt}=a,{hasTransparent:Et}=V;function Lt(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=U.image(i,t,e,o,!Bt||!Bt[e.url]);break;case"linear":a=X.linearGradient(e,o);break;case"radial":a=X.radialGradient(e,o);break;case"angular":a=X.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:V.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:V.string(e)})}if(a&&(a.originPaint=e,s(a.style)&&Et(a.style)&&(a.isTransparent=!0),e.style)){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}return a}const At={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Bt=U.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=Lt(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length?(s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Rt(i,"__isAlphaPixelFill",n),Rt(i,"__isTransparentFill",a)):(Rt(i,"__isAlphaPixelStroke",n),Rt(i,"__isTransparentStroke",a),Rt(i,"__hasMultiStrokeStyle",o))):i.__removePaint(t,!1)},fill:function(t,e,i,s){i.fillStyle=t,ft(e,i,s)},fills:function(t,e,i,s){let n,a,o;for(let r=0,l=t.length;r<l;r++){if(n=t[r],a=n.originPaint,n.image){if(o?o++:o=1,U.checkImage(n,!e.__.__font,e,i,s))continue;if(!n.style){1===o&&n.image.isPlacehold&&e.drawImagePlaceholder(n,i,s);continue}}if(i.fillStyle=n.style,n.transform||a.scaleFixed){if(i.save(),n.transform&&i.transform(n.transform),a.scaleFixed){const{scaleX:t,scaleY:s}=e.getRenderScaleData(!0);(!0===a.scaleFixed||"zoom-in"===a.scaleFixed&&t>1&&s>1)&&i.scale(1/t,1/s)}a.blendMode&&(i.blendMode=a.blendMode),ft(e,i,s),i.restore()}else a.blendMode?(i.saveBlendMode(a.blendMode),ft(e,i,s),i.restoreBlendMode()):ft(e,i,s)}},fillPathOrText:ft,fillText:function(t,e,i){const s=t.__,{rows:n,decorationY:a}=s.__textDrawData;let o;s.__isPlacehold&&s.placeholderColor&&(e.fillStyle=s.placeholderColor);for(let t=0,i=n.length;t<i;t++)o=n[t],o.text?e.fillText(o.text,o.x,o.y):o.data&&o.data.forEach(t=>{e.fillText(t.char,t.x,o.y)});if(a){const{decorationColor:t,decorationHeight:i}=s.__textDrawData;t&&(e.fillStyle=t),n.forEach(t=>a.forEach(s=>e.fillRect(t.x,t.y+s,t.width,i)))}},stroke:function(t,e,i,s){const n=e.__;if(n.__strokeWidth)if(n.__font)Y.strokeText(t,e,i,s);else switch(n.strokeAlign){case"center":pt(t,1,e,i,s);break;case"inside":!function(t,e,i,s){i.save(),i.clipUI(e),pt(t,2,e,i,s),i.restore()}(t,e,i,s);break;case"outside":!function(t,e,i,s){const n=e.__;if(n.__fillAfterStroke)pt(t,2,e,i,s);else{const{renderBounds:a}=e.__layout,o=i.getSameCanvas(!0,!0);e.__drawRenderPath(o),pt(t,2,e,o,s),o.clipUI(n),o.clearWorld(a),m.copyCanvasByWorld(e,i,o),o.recycle(e.__nowWorld)}}(t,e,i,s)}},strokes:function(t,e,i,s){Y.stroke(t,e,i,s)},strokeText:function(t,e,i,s){switch(e.__.strokeAlign){case"center":gt(t,1,e,i,s);break;case"inside":_t(t,"inside",e,i,s);break;case"outside":e.__.__fillAfterStroke?gt(t,2,e,i,s):_t(t,"outside",e,i,s)}},drawTextStroke:function(t,e,i){let s,n=t.__.__textDrawData;const{rows:a,decorationY:o}=n;for(let t=0,i=a.length;t<i;t++)s=a[t],s.text?e.strokeText(s.text,s.x,s.y):s.data&&s.data.forEach(t=>{e.strokeText(t.char,t.x,s.y)});if(o){const{decorationHeight:t}=n;a.forEach(i=>o.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}},drawStrokesStyle:function(t,e,i,s,n,a){let o;const r=s.__,{__hasMultiStrokeStyle:l}=r;l||n.setStroke(void 0,r.__strokeWidth*e,r);for(let d=0,h=t.length;d<h;d++)if(o=t[d],(!o.image||!U.checkImage(o,!1,s,n,a))&&o.style){if(l){const{strokeStyle:t}=o;t?n.setStroke(o.style,r.__getRealStrokeWidth(t)*e,r,t):n.setStroke(o.style,r.__strokeWidth*e,r)}else n.strokeStyle=o.style;o.originPaint.blendMode?(n.saveBlendMode(o.originPaint.blendMode),i?Y.drawTextStroke(s,n,a):n.stroke(),n.restoreBlendMode()):i?Y.drawTextStroke(s,n,a):n.stroke()}},shape:function(t,e,s){const n=e.getSameCanvas(),a=e.bounds,o=t.__nowWorld,r=t.__layout,l=t.__nowWorldShapeBounds||(t.__nowWorldShapeBounds={});let d,h,c,u,f,p;yt(r.strokeSpread?(mt(kt,r.boxBounds,r.strokeSpread),kt):r.boxBounds,o,l);let{scaleX:g,scaleY:_}=t.getRenderScaleData(!0);if(a.includes(l))p=n,d=f=l,h=o;else{let n;if(i.fullImageShadow)n=l;else{const t=r.renderShapeSpread?wt(a,A.swapAndScale(r.renderShapeSpread,g,_)):a;n=St(t,l)}u=a.getFitMatrix(n);let{a:w,d:m}=u;u.a<1&&(p=e.getSameCanvas(),t.__renderShape(p,s),g*=w,_*=m),f=vt(l,u),d=xt(f,-u.e,-u.f),h=vt(o,u),bt(h,-u.e,-u.f);const y=s.matrix;y?(c=new T(u),c.multiply(y),w*=y.scaleX,m*=y.scaleY):c=u,c.withScale(w,m),s=Object.assign(Object.assign({},s),{matrix:c})}return t.__renderShape(n,s),{canvas:n,matrix:c,fitMatrix:u,bounds:d,renderBounds:h,worldCanvas:p,shapeBounds:f,scaleX:g,scaleY:_}}};let Tt,Ot=new x;const{isSame:Ct}=L;function Pt(t,e,i,s,n,a){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||U.createData(n,s,i,a),!0}function Wt(t,e){It(t,O.LOAD,e)}function Dt(t,e){It(t,O.LOADED,e)}function Mt(t,e,i){e.error=i,t.forceUpdate("surface"),It(t,O.ERROR,e)}function It(t,e,i){t.hasEvent(e)&&t.emitEvent(new O(e,i))}function Ft(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:zt,translate:Yt}=C,Ut=new x,Vt={},Xt={};function Gt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let Nt={},qt=M();const{get:jt,set:Ht,rotateOfOuter:Qt,translate:Zt,scaleOfOuter:$t,multiplyParent:Jt,scale:Kt,rotate:te,skew:ee}=C;function ie(t,e,i,s,n,a,o,r){o&&te(t,o),r&&ee(t,r.x,r.y),n&&Kt(t,n,a),Zt(t,e.x+i,e.y+s)}function se(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const{get:ne,scale:ae,copy:oe}=C,{getFloorScale:re}=P,{abs:le}=Math;const de={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return Tt&&i===Tt.paint&&Ct(s,Tt.boxBounds)?a=Tt.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),Tt=r.use>1?{leafPaint:a,paint:i,boxBounds:Ot.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(Pt(t,e,i,r,a,s),n&&(Wt(t,o),Dt(t,o))):r.error?n&&Mt(t,o,r.error):(n&&(Ft(t,!0),Wt(t,o)),a.loadId=r.load(()=>{Ft(t,!1),t.destroyed||(Pt(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Dt(t,o)),a.loadId=void 0},e=>{Ft(t,!1),Mt(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n,a){const{scaleX:o,scaleY:l}=U.getImageRenderScaleData(t,s,n,a),{image:d,data:h,originPaint:c}=t,{exporting:u}=a;return!(!h||t.patternId===o+"-"+l&&!u)&&(e&&(h.repeat?e=!1:c.changeful||"miniapp"===i.name&&r.isResizing(s)||u||(e=i.image.isLarge(d,o,l))),e?(s.__.__isFastShadow&&(n.fillStyle=t.style||"#000",n.fill()),U.drawImage(t,o,l,s,n,a),!0):(!t.style||c.sync||u?U.createPattern(t,s,n,a):U.createPatternTask(t,s,n,a),!1))},drawImage:function(t,e,i,s,n,a){const{data:o,image:r}=t,{blendMode:l}=t.originPaint,{opacity:d,transform:h}=o,c=r.getFull(o.filters),u=s.__;let f,{width:p,height:g}=r;(f=h&&!h.onlyScale||u.path||u.cornerRadius)||d||l?(n.save(),f&&n.clipUI(s),l&&(n.blendMode=l),d&&(n.opacity*=d),h&&n.transform(h),n.drawImage(c,0,0,p,g),n.restore()):(o.scaleX&&(p*=o.scaleX,g*=o.scaleY),n.drawImage(c,0,0,p,g))},getImageRenderScaleData:function(t,e,i,s){const n=e.getRenderScaleData(!0,t.originPaint.scaleFixed),{data:a}=t;if(i){const{pixelRatio:t}=i;n.scaleX*=t,n.scaleY*=t}return a&&a.scaleX&&(n.scaleX*=Math.abs(a.scaleX),n.scaleY*=Math.abs(a.scaleY)),n},recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,d=i.length;l<d;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createPatternTask:function(t,e,i,s){t.patternTask||(t.patternTask=R.patternTasker.add(()=>se(this,void 0,void 0,function*(){t.patternTask=null,i.bounds.hit(e.__nowWorld)&&U.createPattern(t,e,i,s),e.forceUpdate("surface")}),300))},createPattern:function(t,e,s,n){let{scaleX:a,scaleY:o}=U.getImageRenderScaleData(t,e,s,n),r=a+"-"+o;if(t.patternId!==r&&!e.destroyed&&(!i.image.isLarge(t.image,a,o)||t.data.repeat)){const{image:s,data:n}=t,{transform:l,gap:d}=n,h=U.getPatternFixScale(t,a,o);let c,u,f,{width:p,height:g}=s;h&&(a*=h,o*=h),p*=a,g*=o,d&&(u=d.x*a/le(n.scaleX||1),f=d.y*o/le(n.scaleY||1)),(l||1!==a||1!==o)&&(a*=re(p+(u||0)),o*=re(g+(f||0)),c=ne(),l&&oe(c,l),ae(c,1/a,1/o));const _=s.getCanvas(p,g,n.opacity,n.filters,u,f,e.leafer&&e.leafer.config.smooth),w=s.getPattern(_,n.repeat||i.origin.noRepeat||"no-repeat",c,t);t.style=w,t.patternId=r}},getPatternFixScale:function(t,e,s){const{image:n}=t;let a,o=i.image.maxPatternSize,r=n.width*n.height;return n.isSVG?e>1&&(a=Math.ceil(e)/e):o>r&&(o=r),(r*=e*s)>o&&(a=Math.sqrt(o/r)),a},createData:function(t,e,i,s){t.data=U.getPatternData(i,s,e)},getPatternData:function(t,e,i){t.padding&&(e=Ut.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{width:n,height:a}=i,{opacity:o,mode:r,align:l,offset:d,scale:h,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(Xt,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((h||c)&&(P.getScaleData(h,c,i,Vt),x=Vt.scaleX,b=Vt.scaleY),(l||_||g)&&(x&&L.scale(Xt,x,b,!0),l&&W.toPoint(l,Xt,e,Xt,!0,!0))):m&&!u||(x=b=L.getFitScale(e,Xt,"fit"!==r),L.put(e,i,l,x,!1,Xt),L.scale(Xt,x,b,!0)),d&&D.move(Xt,d),r){case"stretch":m?x&&(x=b=void 0):(x=e.width/n,b=e.height/a,U.stretchMode(y,e,x,b));break;case"normal":case"clip":if(Xt.x||Xt.y||x||p||u||f){let t,i;p&&(t=e.width/p.width,i=e.height/p.height),U.clipMode(y,e,Xt.x,Xt.y,x,b,u,f,t,i),t&&(x=x?x*t:t,b=b?b*i:i)}break;case"repeat":(!m||x||u||f)&&U.repeatMode(y,e,n,a,Xt.x,Xt.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:Gt(a,i,n.width,e&&e.x),y:Gt(o,s,n.height,e&&e.y)}}(_,i&&g,Xt.width,Xt.height,e));break;default:x&&U.fillOrFitMode(y,e,Xt.x,Xt.y,x,b,u)}return y.transform||(e.x||e.y)&&Yt(y.transform=zt(),e.x,e.y),x&&(y.scaleX=x,y.scaleY=b),o&&o<1&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y},stretchMode:function(t,e,i,s){const n=jt(),{x:a,y:o}=e;a||o?Zt(n,a,o):n.onlyScale=!0,Kt(n,i,s),t.transform=n},fillOrFitMode:function(t,e,i,s,n,a,o){const r=jt();Zt(r,e.x+i,e.y+s),Kt(r,n,a),o&&Qt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r},clipMode:function(t,e,i,s,n,a,o,r,l,d){const h=jt();ie(h,e,i,s,n,a,o,r),l&&(o||r?(Ht(qt),$t(qt,e,l,d),Jt(h,qt)):$t(h,e,l,d)),t.transform=h},repeatMode:function(t,e,i,s,n,a,o,r,l,d,h,c){const u=jt();if(c)ie(u,e,n,a,o,r,l,d);else{if(l)if("center"===h)Qt(u,{x:i/2,y:s/2},l);else switch(te(u,l),l){case 90:Zt(u,s,0);break;case 180:Zt(u,i,s);break;case 270:Zt(u,0,i)}Nt.x=e.x+n,Nt.y=e.y+a,Zt(u,Nt.x,Nt.y),o&&$t(u,Nt,o,r)}t.transform=u}},{toPoint:he}=I,{hasTransparent:ce}=V,ue={},fe={};function pe(t,e,i,n){if(i){let a,o,r,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(r=t/(d-1),o=V.string(a,n)):(r=a.offset,o=V.string(a.color,n)),e.addColorStop(r,o),!l&&ce(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:ge,getDistance:_e}=D,{get:we,rotateOfOuter:me,scaleOfOuter:ye}=C,{toPoint:ve}=I,xe={},be={};function Se(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=ge(e,i);a=we(),n?(ye(a,e,o/r*(s||1),1),me(a,e,t+90)):(ye(a,e,1,o/r*(s||1)),me(a,e,t))}return a}const{getDistance:ke}=D,{toPoint:Be}=I,Re={},Ee={};const Le={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;he(s||"top",e,ue),he(n||"bottom",e,fe);const r=i.canvas.createLinearGradient(ue.x,ue.y,fe.x,fe.y),l={type:a,style:r};return pe(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;ve(s||"center",e,xe),ve(n||"bottom",e,be);const l=i.canvas.createRadialGradient(xe.x,xe.y,0,xe.x,xe.y,_e(xe,be)),d={type:a,style:l};pe(d,l,t.stops,o);const h=Se(e,xe,be,r,!0);return h&&(d.transform=h),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;Be(s||"center",e,Re),Be(n||"bottom",e,Ee);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Re.x,Re.y):i.canvas.createRadialGradient(Re.x,Re.y,0,Re.x,Re.y,ke(Re,Ee)),d={type:a,style:l};pe(d,l,t.stops,o);const h=Se(e,Re,Ee,r||1,i.conicGradientRotate90);return h&&(d.transform=h),d},getTransform:Se},{copy:Ae,move:Te,toOffsetOutBounds:Oe}=L,{max:Ce,abs:Pe}=Math,We={},De=new T,Me={};function Ie(t,e){let i,s,n,a,o=0,r=0,l=0,d=0;return e.forEach(t=>{i=t.x||0,s=t.y||0,a=1.5*(t.blur||0),n=Pe(t.spread||0),o=Ce(o,n+a-s),r=Ce(r,n+a+i),l=Ce(l,n+a+s),d=Ce(d,n+a-i)}),o===r&&r===l&&l===d?o:[o,r,l,d]}function Fe(t,e,s){const{shapeBounds:n}=s;let a,o;i.fullImageShadow?(Ae(We,t.bounds),Te(We,e.x-n.x,e.y-n.y),a=t.bounds,o=We):(a=n,o=e),t.copyWorld(s.canvas,a,o)}const{toOffsetOutBounds:ze}=L,Ye={};const Ue=Ie;const Ve={shadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{shadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;Oe(l,Me,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(Me.offsetX+(o.x||0)*c*_,Me.offsetY+(o.y||0)*u*_,(o.blur||0)*c*_,V.string(o.color)),n=G.getShadowTransform(t,f,i,o,Me,_),n&&f.setTransform(n),Fe(f,Me,i),n&&f.resetTransform(),s=d,o.box&&(f.restore(),f.save(),r&&(f.copyWorld(f,d,a,"copy"),s=a),r?f.copyWorld(r,a,a,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{innerShadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;ze(l,Ye,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ye.offsetX+(o.x||0)*c*_,Ye.offsetY+(o.y||0)*u*_,(o.blur||0)*c*_),n=G.getShadowTransform(t,f,i,o,Ye,_,!0),n&&f.setTransform(n),Fe(f,Ye,i),f.restore(),r?(f.copyWorld(f,d,a,"copy"),f.copyWorld(r,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,h,l,"source-out"),s=d),f.fillWorld(s,V.string(o.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),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){},getShadowRenderSpread:Ie,getShadowTransform:function(t,e,i,s,n,a,o){if(s.spread){const i=2*s.spread*a*(o?-1:1),{width:r,height:l}=t.__layout.strokeBounds;return De.set().scaleOfOuter({x:(n.x+n.width/2)*e.pixelRatio,y:(n.y+n.height/2)*e.pixelRatio},1+i/r,1+i/l),De}},isTransformShadow(t){},getInnerShadowSpread:Ue},{excludeRenderBounds:Xe}=v;let Ge;function Ne(t,e,i,s,n,a,o,r){switch(e){case"grayscale":Ge||(Ge=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);je(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":je(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function qe(t){return t.getSameCanvas(!1,!0)}function je(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}N.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let d=0,h=l.length;d<h;d++){if(i=l[d],r=i.__.mask,r){o&&(Ne(this,o,t,n,s,a,void 0,!0),s=n=null),"clipping"!==r&&"clipping-path"!==r||Xe(i,e)||i.__render(t,e),a=i.__.opacity,Ge=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=qe(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=qe(t)),n||(n=qe(t)),i.__render(s,e));continue}const h=1===a&&i.__.__blendMode;h&&Ne(this,o,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),h&&Ne(this,o,t,n,s,a,h,!1)}Ne(this,o,t,n,s,a,void 0,!0)};const He=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Qe=He+"_#~&*+\\=|≮≯≈≠=…",Ze=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 $e(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const Je=$e("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ke=$e("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ti=$e(He),ei=$e(Qe),ii=$e("- —/~|┆·");var si;!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"}(si||(si={}));const{Letter:ni,Single:ai,Before:oi,After:ri,Symbol:li,Break:di}=si;function hi(t){return Je[t]?ni:ii[t]?di:Ke[t]?oi:ti[t]?ri:ei[t]?li:Ze.test(t)?ai:ni}const ci={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ui(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:fi}=ci,{Letter:pi,Single:gi,Before:_i,After:wi,Symbol:mi,Break:yi}=si;let vi,xi,bi,Si,ki,Bi,Ri,Ei,Li,Ai,Ti,Oi,Ci,Pi,Wi,Di,Mi,Ii=[];function Fi(t,e){Li&&!Ei&&(Ei=Li),vi.data.push({char:t,width:e}),bi+=e}function zi(){Si+=bi,vi.width=bi,xi.words.push(vi),vi={data:[]},bi=0}function Yi(){Pi&&(Wi.paraNumber++,xi.paraStart=!0,Pi=!1),Li&&(xi.startCharSize=Ei,xi.endCharSize=Li,Ei=0),xi.width=Si,Di.width?fi(xi):Mi&&Ui(),Ii.push(xi),xi={words:[]},Si=0}function Ui(){Si>(Wi.maxWidth||0)&&(Wi.maxWidth=Si)}const{top:Vi,right:Xi,bottom:Gi,left:Ni}=F;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 ji={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{__padding:l}=e;l&&(o?(n=l[Ni],o-=l[Xi]+l[Ni],!o&&(o=.01)):e.autoSizeAlign||(n=l[Ni]),r?(a=l[Vi],r-=l[Vi]+l[Gi],!r&&(r=.01)):e.autoSizeAlign||(a=l[Vi]));const d={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=e.__font};return function(t,e,s){Wi=t,Ii=t.rows,Di=t.bounds,Mi=!Di.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l}=Di;if(s.__isCharMode){const t="none"!==s.textWrap,i="break"===s.textWrap;Pi=!0,Ti=null,Ei=Ri=Li=bi=Si=0,vi={data:[]},xi={words:[]},n&&(e=[...e]);for(let s=0,d=e.length;s<d;s++)Bi=e[s],"\n"===Bi?(bi&&zi(),xi.paraEnd=!0,Yi(),Pi=!0):(Ai=hi(Bi),Ai===pi&&"none"!==o&&(Bi=ui(Bi,o,!bi)),Ri=r.measureText(Bi).width,n&&(n<0&&(Li=Ri),Ri+=n),Oi=Ai===gi&&(Ti===gi||Ti===pi)||Ti===gi&&Ai!==wi,Ci=!(Ai!==_i&&Ai!==gi||Ti!==mi&&Ti!==wi),ki=Pi&&a?l-a:l,t&&l&&Si+bi+Ri>ki&&(i?(bi&&zi(),Si&&Yi()):(Ci||(Ci=Ai===pi&&Ti==wi),Oi||Ci||Ai===yi||Ai===_i||Ai===gi||bi+Ri>ki?(bi&&zi(),Si&&Yi()):Si&&Yi()))," "===Bi&&!0!==Pi&&Si+bi===0||(Ai===yi?(" "===Bi&&bi&&zi(),Fi(Bi,Ri),zi()):Oi||Ci?(bi&&zi(),Fi(Bi,Ri)):Fi(Bi,Ri)),Ti=Ai);bi&&zi(),Si&&Yi(),Ii.length>0&&(Ii[Ii.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Wi.paraNumber++,Si=r.measureText(t).width,Ii.push({x:a||0,text:t,width:Si,paraStart:!0}),Mi&&Ui()})}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":qi(e,"x",t[Ni]);break;case"right":qi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":qi(e,"y",t[Vi]);break;case"bottom":qi(e,"y",-t[Gi])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:d,verticalAlign:h,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(h){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,h=n;o<h;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(d,e),e.__isCharMode&&function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e,r=i&&n.includes("both"),l=r||i&&n.includes("justify"),d=l&&n.includes("letter");let h,c,u,f,p,g,_,w,m,y;s.forEach(t=>{t.words&&(p=a&&t.paraStart?a:0,w=t.words.length,l&&(y=!t.paraEnd||r,c=i-t.width-p,d?f=c/(t.words.reduce((t,e)=>t+e.data.length,0)-1):u=w>1?c/(w-1):0),g=o||t.isOverflow||d?0:u?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===g?(t.x+=p,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=p,h=t.x,t.data=[],t.words.forEach((e,i)=>{1===g?(_={char:"",x:h},h=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,h,_),(t.isOverflow||" "!==_.char)&&t.data.push(_)):h=function(t,e,i,s,n){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width,n&&(e+=n)}),e}(e.data,h,t.data,t.isOverflow,y&&f),y&&(m=i===w-1,u?m||(h+=u,t.width+=u):f&&(t.width+=f*(e.data.length-(m?1:0))))})),t.words=null)})}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?i.canvas.measureText(r).width:0,h=s+n-d;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<h));s--){if(l<h&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(d,e,n,o),"none"!==e.textDecoration&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=V.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(d,e),d}};const Hi={string:function(t,e){if(!t)return"#000";const i=z(e)&&e<1;if(s(t)){if(!i||!V.object)return t;t=V.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(q,ji),Object.assign(V,Hi),Object.assign(Y,At),Object.assign(U,de),Object.assign(X,Le),Object.assign(G,Ve),$();export{ht as Layouter,H as LeaferCanvas,ut as Renderer,K as Watcher,$ as useCanvas};
2
2
  //# sourceMappingURL=web.esm.min.js.map