leafer-ui 1.0.9 → 1.1.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/README.md CHANGED
@@ -1,16 +1,10 @@
1
1
  # leafer-ui
2
2
 
3
- 一款好用的 Canvas 渲染引擎,革新的体验。高效绘图 、UI 交互(小游戏、互动应用、组态)、图形编辑,前端开发必备~
3
+ 一款好用的 Canvas 引擎,革新的开发体验,可用于高效绘图 、UI 交互(小游戏、互动应用、组态)、图形编辑。
4
4
 
5
- [![LeaferJS](https://www.leaferjs.com/image/leaferjs.jpg)](https://www.leaferjs.com)
5
+ [![LeaferJS](https://www.leaferjs.com/image/leaferjs.jpg?d=1126)](https://www.leaferjs.com)
6
6
 
7
- [**leafer-ui**](https://leaferjs.com/ui/guide/install/ui/start.html) 是基于核心库 [leafer](https://github.com/leaferjs/leafer) 开发的一套绚丽多彩的 UI 绘图、交互框架。作为[LeaferJS](https://www.leaferjs.com) 的表现层,可结合 AI 绘图、生成界面,表现力丰富、性能强劲,可媲美当前主流设计软件。
8
-
9
- 提供了丰富的 UI 绘图元素,和开箱即用的功能,如自动布局、图形编辑、SVG 导出,方便与 Figma、Sketch 等产品进行数据交换。并为跨平台开发提供了统一的交互事件,如拖拽、旋转、缩放手势等。
10
-
11
- 可用于高效绘图 、UI 交互(小游戏、互动应用、组态)、图形编辑。随着生态的不断发展,未来将支撑可视化开发网页、应用、游戏、动画。
12
-
13
- v1.0 正式版已发布 🎉🎉🎉
7
+ 提供了丰富的 UI 绘图元素,和开箱即用的功能,如自动布局、图形编辑、SVG 导出等,方便与 PS、 Figma、Sketch 等产品进行对接。并为跨平台开发提供了统一的交互事件,如拖拽、旋转、缩放手势等。
14
8
 
15
9
  📗 [图文并茂、由浅入深的了解 LeaferJS](https://leaferjs.com/ui/blog/2024-07-09.html)
16
10
 
@@ -22,17 +16,15 @@ v1.0 正式版已发布 🎉🎉🎉
22
16
 
23
17
  ## 快速入门
24
18
 
25
- [1. 准备在线 Playground 环境](https://leaferjs.com/ui/guide/runtime.md)
19
+ [1. 准备在线 Playground 环境](https://leaferjs.com/ui/guide/runtime.html)
26
20
 
27
21
  可通过 **Cloud Studio** 模版创建一个 **LeaferJS 项目**,用于运行、练习后续的示例代码。
28
22
 
29
- [2. 学习 LeaferJS 快速入门教程](https://leaferjs.com/ui/guide/basic/app.md)
23
+ [2. 学习 LeaferJS 快速入门教程](https://leaferjs.com/ui/guide/basic/app.html)
30
24
 
31
- 跟随官网教程步骤(文档底部有下一步引导按钮)从浅到深的一步步学习。
25
+ 跟随官网教程步骤(文档底部有下一步引导按钮)从浅到深的学习,动手调试每一段示例代码。
32
26
 
33
- 建议将教程中的示例代码复制到 **LeaferJS 项目** 的 index.ts 文件中运行、调试效果。
34
-
35
- [3. 开发一个画龙点睛的小游戏](https://leaferjs.com/ui/contest/guide.md)
27
+ [3. 开发一个画龙点睛的小游戏](https://leaferjs.com/ui/contest/guide.html)
36
28
 
37
29
  给你一条会飞的龙,看你能做出什么好玩的小游戏分享给我们 ◠‿◠
38
30
 
@@ -42,56 +34,80 @@ v1.0 正式版已发布 🎉🎉🎉
42
34
 
43
35
  ## 场景包
44
36
 
45
- 高效绘图场景,推荐安装更轻量的 [leafer-draw](https://leaferjs.com/ui/guide/type/draw/start.html) (49KB min+gzip)。
37
+ 高效绘图场景,推荐安装更轻量的 [leafer-draw](https://leaferjs.com/ui/guide/install/draw/start.html) (49KB min+gzip)。
46
38
 
47
- 游戏开发场景,推荐安装更省心的 [leafer-game](https://leaferjs.com/ui/guide/install/game/start.md),已集成了游戏相关插件。
39
+ 游戏开发场景,推荐安装更省心的 [leafer-game](https://leaferjs.com/ui/guide/install/game/start.html),已集成了游戏相关插件。
48
40
 
49
41
  图形编辑场景,推荐安装更省心的 [leafer-editor](https://leaferjs.com/ui/guide/install/editor/start.html),已集成了图形编辑器相关插件。
50
42
 
51
- ## 入门场景
43
+ ## 互动交流
52
44
 
53
- **高效绘图:** 长图、产品海报、印刷品等
45
+ 有问题、建议可以 [提交 issue](https://github.com/leaferjs/leafer-ui/issues),留下你的贡献足迹。
54
46
 
55
- Flex 自动布局、中心绘制,后端批量生成,渐变、内外阴影、裁剪、遮罩、擦除...
47
+ 欢迎加入 [技术交流群](https://leaferjs.com/#contact) ,与小伙伴们建立联系,共同学习进步,偶尔会有特殊福利。
56
48
 
57
- **UI 交互:** 小游戏、互动应用、组态等
49
+ ## 仓库组成
58
50
 
59
- 跨平台交互事件、手势,CSS 交互状态、光标,动画、状态、过渡、精灵,箭头、连线...
51
+ [LeaferJS](https://github.com/leaferjs/LeaferJS) 主集成仓库,可直接运行代码。
60
52
 
61
- **图形编辑:** 头像裁剪、图片、DIY 编辑器等
53
+ [leafer](https://github.com/leaferjs/leafer) 核心仓库。
62
54
 
63
- 丰富的图形编辑功能、高可定制,标尺、视窗控制、滚动条...
55
+ [leafer-ui](https://github.com/leaferjs/leafer-ui) UI 仓库。
64
56
 
65
- ## 互动交流
57
+ [leafer-in](https://github.com/leaferjs/leafer-in) 插件仓库。
66
58
 
67
- 有问题、建议可以 [提交 issue](https://github.com/leaferjs/leafer-ui/issues),留下你的贡献足迹。
59
+ [leafer-x](https://github.com/leaferjs/leafer-x) 社区插件提交仓库。
68
60
 
69
- 欢迎加入 [技术交流群](https://leaferjs.com/#contact) ,与小伙伴们建立联系,共同学习进步,偶尔会有特殊福利。
61
+ [test](https://github.com/leaferjs/test) 自动化测试仓库。
70
62
 
71
63
  ## 使命与愿景
72
64
 
73
- leafer-ui 致力于实现一套简洁、开放、现代化的 UI 绘图语言标准,表现力丰富,便于 AI 理解,人类可视化使用,并为数字化产品开发提供跨平台、轻量化、高性能的运行时。
65
+ LeaferJS 致力于实现一套简洁、开放、现代化的 UI 绘图语言标准,表现力丰富,便于 AI 理解,人类可视化使用,并为数字化产品开发提供跨平台、轻量化、高性能的运行时。
74
66
 
75
67
  让不同的软件之间能够沟通、协作、共享绘图数据,让数字化产品开发可以更快、更简单。
76
68
 
77
69
  通过不断革新的图形渲染技术、配套支持, 吸引更多的开发者加入使用,建立起一个开放的生态环境,沟通有无,互相从中受益,推动行业的快速发展,并诞生出更多有创意的技术和产品。
78
70
 
79
- 我们正在坚定的向这个目标持续前进,可以通过 [开发计划](https://www.leaferjs.com/ui/plan/) 了解更多信息。
71
+ 我们的目标不仅是让它成为前沿的 2D 和未来的 3D 引擎技术,还希望它能够为开发者带来极致的开发体验,助力开发者快速构建 AI 时代的网页、应用、设计、画布、游戏和动画等可视化生产力工具(如下一代 local-first 的 Figma、Miro、Notion、Unity、Adobe、Canva、Webflow 等)。
72
+
73
+ ![覆盖场景](https://www.leaferjs.com/ui/image/blog/20241120/plan.jpg)
74
+
75
+ 这是一段漫长而又充满乐趣的旅程,我们正在年复一年、坚定地向这个目标持续前进,可以通过 [开发计划](https://www.leaferjs.com/ui/plan/) 了解更多信息。
76
+
77
+ ## 卓越文化
78
+
79
+ 我们追求慢慢打造出这样的团队与社区氛围:
80
+
81
+ **真诚坚韧、追求卓越、热爱生活、与众不同、倾听、互帮互助、懂得取舍、不怕失败、结果导向**
82
+
83
+ 我们相信当一个人身心强健,对这个世界充满无限好奇的时候,会产生出源源不断的生命力和创造力,所以我们鼓励追求卓越与热爱生活,也许我们会因为健身、美食、旅行、摄影、音乐、写作、绘画、舞蹈、游戏等热爱而了解彼此,也许我们还会有自己的乐队、画展、读书会...
84
+
85
+ 我们要一起去攀登一座座别人从未到达过的高峰,同时我们也了解自己的能力边界,将聪明才智都聚焦到我们最感兴趣,也对用户最有价值的那个点上,在那里做出前人未曾有过的东西。
86
+
87
+ 我们知道成功并非一蹴而就,所以我们接纳路途中的失败、偶尔的躺平,只要拥有坚韧的气质和永不放弃的精神,从失败中吸取教训,不断成长,积累一个个小小的胜利,就一定会抵达目的地。
88
+
89
+ 希望我们能一起创办出 **一家像胖东来一样的新型互联网企业和社区,** 如果你喜欢这样的文化,欢迎阅读 [贡献指南](https://www.leaferjs.com/ui/contribute/guide.html),可以一起参与进来。
90
+
91
+ ## 贡献指南
92
+
93
+ 当你使用 LeaferJS 时, 你就已成为了 这个充满活力的大家庭 的一员,踏入这座建设中的“技术城堡”。只有通过每位成员的热情参与与贡献,这座城堡才能逐步走向完善。
94
+
95
+ [社区行为准则](./contributor/CODE_OF_CONDUCT.md)
80
96
 
81
- ### 资源
97
+ [代码提交规范](./contributor/COMMIT_CONVENTION.md)
82
98
 
83
- [官方网站](https://www.leaferjs.com)
99
+ [提问的智慧](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md#%E6%8F%90%E9%97%AE%E7%9A%84%E6%99%BA%E6%85%A7)
84
100
 
85
- [快速上手](https://www.leaferjs.com/ui/guide)
101
+ 有问题、建议可以 提交 [issue](/https://github.com/leaferjs/leafer-ui/issues) 讨论,它更加开放与透明,能够帮助社区沉淀经验,避免重复劳动。
86
102
 
87
- [快速安装](https://www.leaferjs.com/ui/guide/start.html)
103
+ ## 致谢贡献者
88
104
 
89
- [LeaferJS 主仓库](https://github.com/leaferjs/LeaferJS)
105
+ [每一位贡献代码的社区成员](https://github.com/leaferjs/leafer-ui/graphs/contributors)
90
106
 
91
- [leafer 仓库](https://github.com/leaferjs/leafer)
107
+ [每一位参与生态的社区成员](https://www.leaferjs.com/ui/contribute/)
92
108
 
93
- [leafer-in 官方插件仓库](https://github.com/leaferjs/leafer-in)
109
+ ## License
94
110
 
95
- ### License
111
+ MIT 开源许可协议,可以免费使用,且能用于商业场景。
96
112
 
97
- leafer-ui 是采用 MIT 许可的开源项目,可以永久免费使用。
113
+ Copyright © 2023-present Chao (Leafer) Wan
package/dist/web.cjs CHANGED
@@ -644,7 +644,8 @@ class Renderer {
644
644
  this.totalBounds = new core.Bounds();
645
645
  debug$1.log(target.innerName, '--->');
646
646
  try {
647
- target.app.emit(core.RenderEvent.CHILD_START, target);
647
+ if (!target.isApp)
648
+ target.app.emit(core.RenderEvent.CHILD_START, target);
648
649
  this.emitRender(core.RenderEvent.START);
649
650
  this.renderOnce(callback);
650
651
  this.emitRender(core.RenderEvent.END, this.totalBounds);
@@ -1599,6 +1600,8 @@ function stroke(stroke, ui, canvas) {
1599
1600
  case 'center':
1600
1601
  canvas.setStroke(stroke, __strokeWidth, options);
1601
1602
  canvas.stroke();
1603
+ if (options.__useArrow)
1604
+ strokeArrow(ui, canvas);
1602
1605
  break;
1603
1606
  case 'inside':
1604
1607
  canvas.save();
@@ -1636,6 +1639,8 @@ function strokes(strokes, ui, canvas) {
1636
1639
  case 'center':
1637
1640
  canvas.setStroke(undefined, __strokeWidth, options);
1638
1641
  drawStrokesStyle(strokes, false, ui, canvas);
1642
+ if (options.__useArrow)
1643
+ strokeArrow(ui, canvas);
1639
1644
  break;
1640
1645
  case 'inside':
1641
1646
  canvas.save();
@@ -1661,6 +1666,14 @@ function strokes(strokes, ui, canvas) {
1661
1666
  }
1662
1667
  }
1663
1668
  }
1669
+ function strokeArrow(ui, canvas) {
1670
+ if (ui.__.dashPattern) {
1671
+ canvas.beginPath();
1672
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
1673
+ canvas.dashPattern = null;
1674
+ canvas.stroke();
1675
+ }
1676
+ }
1664
1677
 
1665
1678
  const { getSpread, getOuterOf, getByMove, getIntersectData } = core.BoundsHelper;
1666
1679
  function shape(ui, current, options) {
@@ -2378,16 +2391,16 @@ const EffectModule = {
2378
2391
 
2379
2392
  const { excludeRenderBounds } = core.LeafBoundsHelper;
2380
2393
  draw.Group.prototype.__renderMask = function (canvas, options) {
2381
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
2394
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
2382
2395
  const { children } = this;
2383
2396
  for (let i = 0, len = children.length; i < len; i++) {
2384
- child = children[i];
2385
- if (child.__.mask) {
2397
+ child = children[i], mask = child.__.mask;
2398
+ if (mask) {
2386
2399
  if (currentMask) {
2387
2400
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
2388
2401
  maskCanvas = contentCanvas = null;
2389
2402
  }
2390
- if (child.__.mask === 'path') {
2403
+ if (mask === 'path' || mask === 'clipping-path') {
2391
2404
  if (child.opacity < 1) {
2392
2405
  currentMask = 'opacity-path';
2393
2406
  maskOpacity = child.opacity;
@@ -2401,14 +2414,14 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
2401
2414
  child.__clip(contentCanvas || canvas, options);
2402
2415
  }
2403
2416
  else {
2404
- currentMask = 'alpha';
2417
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
2405
2418
  if (!maskCanvas)
2406
2419
  maskCanvas = getCanvas(canvas);
2407
2420
  if (!contentCanvas)
2408
2421
  contentCanvas = getCanvas(canvas);
2409
2422
  child.__render(maskCanvas, options);
2410
2423
  }
2411
- if (child.__.mask !== 'clipping')
2424
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
2412
2425
  continue;
2413
2426
  }
2414
2427
  if (excludeRenderBounds(child, options))
@@ -2419,6 +2432,8 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
2419
2432
  };
2420
2433
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
2421
2434
  switch (maskMode) {
2435
+ case 'grayscale':
2436
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
2422
2437
  case 'alpha':
2423
2438
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
2424
2439
  break;
@@ -3123,15 +3138,12 @@ const canvas = core.LeaferCanvasBase.prototype;
3123
3138
  const debug = core.Debug.get('@leafer-ui/export');
3124
3139
  canvas.export = function (filename, options) {
3125
3140
  const { quality, blob } = core.FileHelper.getExportOptions(options);
3126
- if (filename.includes('.')) {
3141
+ if (filename.includes('.'))
3127
3142
  return this.saveAs(filename, quality);
3128
- }
3129
- else if (blob) {
3143
+ else if (blob)
3130
3144
  return this.toBlob(filename, quality);
3131
- }
3132
- else {
3145
+ else
3133
3146
  return this.toDataURL(filename, quality);
3134
- }
3135
3147
  };
3136
3148
  canvas.toBlob = function (type, quality) {
3137
3149
  return new Promise((resolve) => {
package/dist/web.esm.js CHANGED
@@ -645,7 +645,8 @@ class Renderer {
645
645
  this.totalBounds = new Bounds();
646
646
  debug$1.log(target.innerName, '--->');
647
647
  try {
648
- target.app.emit(RenderEvent.CHILD_START, target);
648
+ if (!target.isApp)
649
+ target.app.emit(RenderEvent.CHILD_START, target);
649
650
  this.emitRender(RenderEvent.START);
650
651
  this.renderOnce(callback);
651
652
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -1600,6 +1601,8 @@ function stroke(stroke, ui, canvas) {
1600
1601
  case 'center':
1601
1602
  canvas.setStroke(stroke, __strokeWidth, options);
1602
1603
  canvas.stroke();
1604
+ if (options.__useArrow)
1605
+ strokeArrow(ui, canvas);
1603
1606
  break;
1604
1607
  case 'inside':
1605
1608
  canvas.save();
@@ -1637,6 +1640,8 @@ function strokes(strokes, ui, canvas) {
1637
1640
  case 'center':
1638
1641
  canvas.setStroke(undefined, __strokeWidth, options);
1639
1642
  drawStrokesStyle(strokes, false, ui, canvas);
1643
+ if (options.__useArrow)
1644
+ strokeArrow(ui, canvas);
1640
1645
  break;
1641
1646
  case 'inside':
1642
1647
  canvas.save();
@@ -1662,6 +1667,14 @@ function strokes(strokes, ui, canvas) {
1662
1667
  }
1663
1668
  }
1664
1669
  }
1670
+ function strokeArrow(ui, canvas) {
1671
+ if (ui.__.dashPattern) {
1672
+ canvas.beginPath();
1673
+ ui.__drawPathByData(canvas, ui.__.__pathForArrow);
1674
+ canvas.dashPattern = null;
1675
+ canvas.stroke();
1676
+ }
1677
+ }
1665
1678
 
1666
1679
  const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
1667
1680
  function shape(ui, current, options) {
@@ -2379,16 +2392,16 @@ const EffectModule = {
2379
2392
 
2380
2393
  const { excludeRenderBounds } = LeafBoundsHelper;
2381
2394
  Group.prototype.__renderMask = function (canvas, options) {
2382
- let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
2395
+ let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
2383
2396
  const { children } = this;
2384
2397
  for (let i = 0, len = children.length; i < len; i++) {
2385
- child = children[i];
2386
- if (child.__.mask) {
2398
+ child = children[i], mask = child.__.mask;
2399
+ if (mask) {
2387
2400
  if (currentMask) {
2388
2401
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
2389
2402
  maskCanvas = contentCanvas = null;
2390
2403
  }
2391
- if (child.__.mask === 'path') {
2404
+ if (mask === 'path' || mask === 'clipping-path') {
2392
2405
  if (child.opacity < 1) {
2393
2406
  currentMask = 'opacity-path';
2394
2407
  maskOpacity = child.opacity;
@@ -2402,14 +2415,14 @@ Group.prototype.__renderMask = function (canvas, options) {
2402
2415
  child.__clip(contentCanvas || canvas, options);
2403
2416
  }
2404
2417
  else {
2405
- currentMask = 'alpha';
2418
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
2406
2419
  if (!maskCanvas)
2407
2420
  maskCanvas = getCanvas(canvas);
2408
2421
  if (!contentCanvas)
2409
2422
  contentCanvas = getCanvas(canvas);
2410
2423
  child.__render(maskCanvas, options);
2411
2424
  }
2412
- if (child.__.mask !== 'clipping')
2425
+ if (!(mask === 'clipping' || mask === 'clipping-path'))
2413
2426
  continue;
2414
2427
  }
2415
2428
  if (excludeRenderBounds(child, options))
@@ -2420,6 +2433,8 @@ Group.prototype.__renderMask = function (canvas, options) {
2420
2433
  };
2421
2434
  function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
2422
2435
  switch (maskMode) {
2436
+ case 'grayscale':
2437
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
2423
2438
  case 'alpha':
2424
2439
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
2425
2440
  break;
@@ -3124,15 +3139,12 @@ const canvas = LeaferCanvasBase.prototype;
3124
3139
  const debug = Debug.get('@leafer-ui/export');
3125
3140
  canvas.export = function (filename, options) {
3126
3141
  const { quality, blob } = FileHelper.getExportOptions(options);
3127
- if (filename.includes('.')) {
3142
+ if (filename.includes('.'))
3128
3143
  return this.saveAs(filename, quality);
3129
- }
3130
- else if (blob) {
3144
+ else if (blob)
3131
3145
  return this.toBlob(filename, quality);
3132
- }
3133
- else {
3146
+ else
3134
3147
  return this.toDataURL(filename, quality);
3135
- }
3136
3148
  };
3137
3149
  canvas.toBlob = function (type, quality) {
3138
3150
  return new Promise((resolve) => {
@@ -1 +1 @@
1
- import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,defineKey as l,FileHelper as d,LeafList as c,RenderEvent as u,ChildEvent as g,WatchEvent as p,PropertyEvent as f,LeafHelper as _,BranchHelper as w,Bounds as v,LeafBoundsHelper as m,LeafLevelList as y,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as E,Answer as L,MathHelper as R,MatrixHelper as k,AlignHelper as M,ImageEvent as T,AroundHelper as S,PointHelper as C,Direction4 as A,TwoPointBoundsHelper as P,TaskProcessor as O,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as D,InteractionBase as I,Cursor as F,HitCanvasManager as z}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as Y,ColorConvert as U,PaintGradient as G,Export as V,Group as j,TextConvert as N,Paint as X,Effect as H}from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class K 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.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="string"==typeof 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 q.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;s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;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),q.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:o,height:r}=this.autoBounds.getBoundsFrom(t),a={width:o,height:r,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(a)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(a)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};s.copyAttrs(e,this,n),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(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.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:Q,fileType:$}=d;function J(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(Q(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,Q(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q($(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 Image,{crossOrigin:o}=i.image;o&&(n.setAttribute("crossOrigin",o),n.crossOrigin=o),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new K(t,e),image:t=>new h(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:Z}=navigator;Z.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Z.indexOf("Safari")>-1&&-1===Z.indexOf("Chrome")&&(i.fullImageShadow=!0),Z.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Z.indexOf("Mac")>-1?i.os="Mac":Z.indexOf("Linux")>-1&&(i.os="Linux");class tt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new c;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 c,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(u.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new c,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([g.ADD,g.REMOVE],this.__onChildEvent,this),t.on_(p.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:et,updateBounds:it,updateAllWorldOpacity:st}=_,{pushAllChildBranch:nt,pushAllParent:ot}=w;const{worldBounds:rt}=m,at={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new v,this.beforeBounds=new v,this.afterBounds=new v,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(at):this.afterBounds.setListWithFn(t,rt),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:lt,updateAllChange:dt}=_,ct=t.get("Layouter");class ut{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(x.START),this.layoutOnce(),t.emitEvent(new x(x.END,this.layoutedBlocks,this.times))}catch(t){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(p.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:o,AFTER:r}=x,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new x(n,a,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?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),ot(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),ot(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||it(s[t])}it(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&st(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new x(o,a,this.times)),i.emitEvent(new x(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=x,o=this.getBlocks(new c(e));e.emitEvent(new x(i,o,this.times)),ut.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(s,o,this.times)),e.emitEvent(new x(n,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){lt(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const gt=t.get("Renderer");class pt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new v,gt.log(e.innerName,"---\x3e");try{e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,gt.error(t)}gt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return gt.warn("rendering");if(this.times>3)return gt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new v,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return gt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new v(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,s){const n=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,n),this.renderBounds=s=s||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),t.showHitView&&this.renderHitView(n),t.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(s)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new v;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(u.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new v(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 v(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||gt.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ft}=E;class _t{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new c(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new c;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||_.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new c;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new c;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new c,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||ft(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:s}=t;if(s&&s.__hasMask&&!t.__.mask&&!s.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:wt,NoAndSkip:vt,YesAndSkip:mt}=L,yt={},xt={},bt={};class Bt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new _t(t,this),t&&this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":yt.id=t.substring(1),t=yt;break;case".":xt.className=t.substring(1),t=xt;break;default:bt.tag=t,t=bt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,e,s){return"node"===i.name&&this.target&&this.target.emit(x.CHECK_UPDATE),this.picker.getByPoint(t,e,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&_.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===wt||o===mt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<vt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(g.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ut(t,e),renderer:(t,e,i)=>new pt(t,e,i),selector:(t,e)=>new Bt(t,e)}),i.layout=ut.fullLayout;const Et={convert(t,e){const i=D.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=D.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=Et.getTouch(t),s=D.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",multiTouch:t.touches.length>1,pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},Lt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let s,n=1,{zoomMode:o,zoomSpeed:r}=e;const a=t.deltaY||t.deltaX;if(o?(s="mouse"===o||!t.deltaX&&(i.intWheelDeltaY?Math.abs(a)>17:Math.ceil(a)!==a),(t.shiftKey||t.metaKey||t.ctrlKey)&&(s=!0)):s=!t.shiftKey&&(t.metaKey||t.ctrlKey),s){r=R.within(r,0,1);n=1-a/(4*(t.deltaY?e.delta.y:e.delta.x))*r,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}},Rt={convert(t){const e=D.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:kt,getZoomEventData:Mt,getRotateEventData:Tt,pathCanDrag:St}=D;class Ct extends I{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(Rt.convert(t))}onKeyUp(t){this.keyUp(Rt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(Et.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||(this.usePointer||(this.usePointer=!0),this.pointerDown(Et.convert(t,this.getLocal(t))))}onPointerMove(t){this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||(this.usePointer||(this.usePointer=!0),this.pointerMove(Et.convert(t,this.getLocal(t,!0))))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(Et.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(Et.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(Et.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(Et.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){const e=Et.getTouch(t),i=this.getLocal(e,!0),{preventDefault:s}=this.config.touch;(!0===s||"auto"===s&&St(this.findPath(i)))&&t.preventDefault(),this.multiTouchStart(t),this.usePointer||(this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0,this.pointerDown(Et.convertTouch(t,i)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=Et.getTouch(t);this.pointerMove(Et.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=Et.getTouch(t);this.pointerUp(Et.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>1,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(D.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config;if(e.disabled)return;const i=e.getScale?e.getScale(t,e):Lt.getScale(t,e),s=this.getLocal(t),n=D.getBase(t);1!==i?this.zoom(Mt(s,i,n)):this.move(kt(s,e.getMove?e.getMove(t,e):Lt.getMove(t,e),n))}onGesturestart(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0)}onGesturechange(t){if(this.useMultiTouch)return;this.preventDefaultWheel(t);const e=this.getLocal(t),i=D.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=R.within(o,0,1),this.zoom(Mt(e,s*s,i)),this.rotate(Tt(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.transformEnd())}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&F.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function At(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function Pt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?Dt(t,!0,e,i):Wt(e,i);break;case"inside":Ot("inside",t,n,e,i);break;case"outside":Ot("outside",t,n,e,i)}}function Ot(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?Dt(e,!0,s,a):Wt(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",At(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function Wt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function Dt(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&Y.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Wt(i,s):s.stroke(),s.restoreBlendMode()):e?Wt(i,s):s.stroke())}const{getSpread:It,getOuterOf:Ft,getByMove:zt,getIntersectData:Yt}=E;let Ut;function Gt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:r,opacity:a}=e;return{type:n,blendMode:o,style:U.string(r,a)};case"image":return Y.image(i,t,e,s,!Ut||!Ut[e.url]);case"linear":return G.linearGradient(e,s);case"radial":return G.radialGradient(e,s);case"angular":return G.conicGradient(e,s);default:return void 0!==e.r?{type:"solid",style:U.string(e)}:void 0}}const Vt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Ut=Y.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=Gt(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?At(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&Y.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?At(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?At(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?At(e,i):n?i.fill(n):i.fill())},fillText:At,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Pt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Pt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Dt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Dt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Dt(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Pt,drawTextStroke:Wt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=Yt(s?It(e.bounds,l===d?s*l:[s*d,s*l]):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:g}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=g),a=Ft(n,r),o=zt(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,g*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,g)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let jt={};const{get:Nt,rotateOfOuter:Xt,translate:Ht,scaleOfOuter:qt,scale:Kt,rotate:Qt}=k;function $t(t,e,i,s,n,o,r){const a=Nt();Ht(a,e.x+i,e.y+s),Kt(a,n,o),r&&Xt(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function Jt(t,e,i,s,n,o,r){const a=Nt();Ht(a,e.x+i,e.y+s),n&&Kt(a,n,o),r&&Qt(a,r),t.transform=a}function Zt(t,e,i,s,n,o,r,a,h,l){const d=Nt();if(h)if("center"===l)Xt(d,{x:i/2,y:s/2},h);else switch(Qt(d,h),h){case 90:Ht(d,s,0);break;case 180:Ht(d,i,s);break;case 270:Ht(d,0,i)}jt.x=e.x+n,jt.y=e.y+o,Ht(d,jt.x,jt.y),r&&qt(d,jt,r,a),t.transform=d}const{get:te,translate:ee}=k,ie=new v,se={},ne={};function oe(t,e,i,s){const{blendMode:n,sync:o}=i;n&&(t.blendMode=n),o&&(t.sync=o),t.data=re(i,s,e)}function re(t,e,i){let{width:s,height:n}=i;t.padding&&(e=ie.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:r,align:a,offset:h,scale:l,size:d,rotation:c,repeat:u}=t,g=e.width===s&&e.height===n,p={mode:r},f="center"!==a&&(c||0)%180==90,_=f?n:s,w=f?s:n;let v,m,y=0,x=0;if(r&&"cover"!==r&&"fit"!==r)(l||d)&&(R.getScaleData(l,d,i,ne),v=ne.scaleX,m=ne.scaleY);else if(!g||c){const t=e.width/_,i=e.height/w;v=m="fit"===r?Math.min(t,i):Math.max(t,i),y+=(e.width-s*v)/2,x+=(e.height-n*m)/2}if(a){const t={x:y,y:x,width:_,height:w};v&&(t.width*=v,t.height*=m),M.toPoint(a,t,e,se,!0),y+=se.x,x+=se.y}switch(h&&(y+=h.x,x+=h.y),r){case"stretch":g||(s=e.width,n=e.height);break;case"normal":case"clip":(y||x||v||c)&&Jt(p,e,y,x,v,m,c);break;case"repeat":(!g||v||c)&&Zt(p,e,s,n,y,x,v,m,c,a),u||(p.repeat="repeat");break;default:v&&$t(p,e,y,x,v,m,c)}return p.transform||(e.x||e.y)&&(p.transform=te(),ee(p.transform,e.x,e.y)),v&&"stretch"!==r&&(p.scaleX=v,p.scaleY=m),p.width=s,p.height=n,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let ae,he=new v;const{isSame:le}=E;function de(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||oe(n,s,i,o),!0}function ce(t,e){pe(t,T.LOAD,e)}function ue(t,e){pe(t,T.LOADED,e)}function ge(t,e,i){e.error=i,t.forceUpdate("surface"),pe(t,T.ERROR,e)}function pe(t,e,i){t.hasEvent(e)&&t.emitEvent(new T(e,i))}function fe(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:_e,scale:we,copy:ve}=k,{ceil:me,abs:ye}=Math;function xe(t,e,s){let{scaleX:n,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o+"-"+s;if(e.patternId===r||t.destroyed)return!1;{n=ye(n),o=ye(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:g,opacity:p,transform:f,repeat:_}=a;u&&(l=_e(),ve(l,f),we(l,1/u,1/g),n*=u,o*=g),n*=s,o*=s,d*=n,c*=o;const w=d*c;if(!_&&w>i.image.maxCacheSize)return!1;let v=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;v>e&&(v=e)}w>v&&(h=Math.sqrt(w/v)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=g),(f||1!==n||1!==o)&&(l||(l=_e(),f&&ve(l,f)),we(l,1/n,1/o));const m=t.getCanvas(me(d)||1,me(c)||1,p),y=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=y,e.patternId=r,!0}}function be(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Be}=Math;const Ee={image:function(t,e,i,s,n){let o,r;const a=B.get(i);return ae&&i===ae.paint&&le(s,ae.boxBounds)?o=ae.leafPaint:(o={type:i.type,image:a},ae=a.use>1?{leafPaint:o,paint:i,boxBounds:he.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(de(t,e,i,a,o,s),n&&(ce(t,r),ue(t,r))):a.error?n&&ge(t,r,a.error):(n&&(fe(t,!0),ce(t,r)),o.loadId=a.load((()=>{fe(t,!1),t.destroyed||(de(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ue(t,r)),o.loadId=null}),(e=>{fe(t,!1),ge(t,r,e),o.loadId=null}))),o},checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:a}=e;if(!s.data||s.patternId===o+"-"+r+"-"+a&&!V.running)return!1;{const{data:h}=s;if(n)if(h.repeat)n=!1;else{let{width:t,height:e}=h;t*=Be(o)*a,e*=Be(r)*a,h.scaleX&&(t*=h.scaleX,e*=h.scaleY),n=t*e>i.image.maxCacheSize||V.running}return n?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),s.blendMode&&(e.blendMode=s.blendMode),h.opacity&&(e.opacity*=h.opacity),h.transform&&e.transform(h.transform),e.drawImage(s.image.view,0,0,h.width,h.height),e.restore(),!0):(!s.style||s.sync||V.running?xe(t,s,a):s.patternTask||(s.patternTask=B.patternTasker.add((()=>be(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&xe(t,s,a),t.forceUpdate("surface")}))),300)),!1)}},createPattern:xe,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,B.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null},createData:oe,getPatternData:re,fillOrFitMode:$t,clipMode:Jt,repeatMode:Zt},{toPoint:Le}=S,Re={},ke={};function Me(t,e,i){if(e){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],"string"==typeof s?t.addColorStop(n/(o-1),U.string(s,i)):t.addColorStop(s.offset,U.string(s.color,i))}}const{getAngle:Te,getDistance:Se}=C,{get:Ce,rotateOfOuter:Ae,scaleOfOuter:Pe}=k,{toPoint:Oe}=S,We={},De={};function Ie(t,e,i,s,n){let o;const{width:r,height:a}=t;if(r!==a||s){const t=Te(e,i);o=Ce(),n?(Pe(o,e,r/a*(s||1),1),Ae(o,e,t+90)):(Pe(o,e,1,r/a*(s||1)),Ae(o,e,t))}return o}const{getDistance:Fe}=C,{toPoint:ze}=S,Ye={},Ue={};const Ge={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;Le(s||"top",e,Re),Le(n||"bottom",e,ke);const h=i.canvas.createLinearGradient(Re.x,Re.y,ke.x,ke.y);Me(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Oe(s||"center",e,We),Oe(n||"bottom",e,De);const l=i.canvas.createRadialGradient(We.x,We.y,0,We.x,We.y,Se(We,De));Me(l,t.stops,r);const d={type:o,style:l},c=Ie(e,We,De,h,!0);return c&&(d.transform=c),a&&(d.blendMode=a),d},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;ze(s||"center",e,Ye),ze(n||"bottom",e,Ue);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Ye.x,Ye.y):i.canvas.createRadialGradient(Ye.x,Ye.y,0,Ye.x,Ye.y,Fe(Ye,Ue));Me(l,t.stops,r);const d={type:o,style:l},c=Ie(e,Ye,Ue,h||1,i.conicGradientRotate90);return c&&(d.transform=c),a&&(d.blendMode=a),d},getTransform:Ie},{copy:Ve,toOffsetOutBounds:je}=E,Ne={},Xe={};function He(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(Ve(Ne,t.bounds),Ne.x+=e.x-r.x,Ne.y+=e.y-r.y,s){const{matrix:t}=n;Ne.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Ne.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Ne.width*=s,Ne.height*=s}t.copyWorld(n.canvas,t.bounds,Ne)}else s&&(Ve(Ne,e),Ne.x-=e.width/2*(s-1),Ne.y-=e.height/2*(s-1),Ne.width*=s,Ne.height*=s),t.copyWorld(n.canvas,r,s?Ne:e)}const{toOffsetOutBounds:qe}=E,Ke={};const Qe={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),p=a.length-1;je(l,Xe),a.forEach(((a,f)=>{g.setWorldShadow(Xe.offsetX+a.x*c,Xe.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,He(g,Xe,n,i),s=l,a.box&&(g.restore(),g.save(),h&&(g.copyWorld(g,l,o,"copy"),s=o),h?g.copyWorld(h,o,o,"destination-out"):g.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(g,s,o,a.blendMode):e.copyWorldToInner(g,s,r.renderBounds,a.blendMode),p&&f<p&&g.clearWorld(s,!0)})),g.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),p=a.length-1;qe(l,Ke),a.forEach(((a,f)=>{g.save(),g.setWorldShadow(Ke.offsetX+a.x*c,Ke.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,He(g,Ke,n,i),g.restore(),h?(g.copyWorld(g,l,o,"copy"),g.copyWorld(h,o,o,"source-out"),s=o):(g.copyWorld(i.canvas,d,l,"source-out"),s=l),g.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(g,s,o,a.blendMode):e.copyWorldToInner(g,s,r.renderBounds,a.blendMode),p&&f<p&&g.clearWorld(s,!0)})),g.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:$e}=m;function Je(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),ti(t,e,i,1)}(t,i,s,n);break;case"opacity-path":ti(t,i,s,o);break;case"path":i.restore()}}function Ze(t){return t.getSameCanvas(!1,!0)}function ti(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}j.prototype.__renderMask=function(t,e){let i,s,n,o,r;const{children:a}=this;for(let h=0,l=a.length;h<l;h++)i=a[h],i.__.mask&&(r&&(Je(this,r,t,n,s,o),s=n=null),"path"===i.__.mask?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=Ze(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="alpha",s||(s=Ze(t)),n||(n=Ze(t)),i.__render(s,e)),"clipping"!==i.__.mask)||$e(i,e)||i.__render(n||t,e);Je(this,r,t,n,s,o)};const ei=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ii=ei+"_#~&*+\\=|≮≯≈≠=…",si=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 ni(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const oi=ni("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ri=ni("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ai=ni(ei),hi=ni(ii),li=ni("- —/~|┆·");var di;!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"}(di||(di={}));const{Letter:ci,Single:ui,Before:gi,After:pi,Symbol:fi,Break:_i}=di;function wi(t){return oi[t]?ci:li[t]?_i:ri[t]?gi:ai[t]?pi:hi[t]?fi:si.test(t)?ui:ci}const vi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function mi(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:yi}=vi,{Letter:xi,Single:bi,Before:Bi,After:Ei,Symbol:Li,Break:Ri}=di;let ki,Mi,Ti,Si,Ci,Ai,Pi,Oi,Wi,Di,Ii,Fi,zi,Yi,Ui,Gi,Vi,ji=[];function Ni(t,e){Wi&&!Oi&&(Oi=Wi),ki.data.push({char:t,width:e}),Ti+=e}function Xi(){Si+=Ti,ki.width=Ti,Mi.words.push(ki),ki={data:[]},Ti=0}function Hi(){Yi&&(Ui.paraNumber++,Mi.paraStart=!0,Yi=!1),Wi&&(Mi.startCharSize=Oi,Mi.endCharSize=Wi,Oi=0),Mi.width=Si,Gi.width?yi(Mi):Vi&&qi(),ji.push(Mi),Mi={words:[]},Si=0}function qi(){Si>(Ui.maxWidth||0)&&(Ui.maxWidth=Si)}const Ki=0,Qi=1,$i=2;const{top:Ji,right:Zi,bottom:ts,left:es}=A;function is(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 ss={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o?(s=l[es],o-=l[Zi]+l[es]):e.autoSizeAlign||(s=l[es]),r?(n=l[Ji],r-=l[Ji]+l[ts]):e.autoSizeAlign||(n=l[Ji]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Ui=t,ji=t.rows,Gi=t.bounds,Vi=!Gi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=Gi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Yi=!0,Ii=null,Oi=Pi=Wi=Ti=Si=0,ki={data:[]},Mi={words:[]};for(let s=0,l=e.length;s<l;s++)Ai=e[s],"\n"===Ai?(Ti&&Xi(),Mi.paraEnd=!0,Hi(),Yi=!0):(Di=wi(Ai),Di===xi&&"none"!==r&&(Ai=mi(Ai,r,!Ti)),Pi=a.measureText(Ai).width,n&&(n<0&&(Wi=Pi),Pi+=n),Fi=Di===bi&&(Ii===bi||Ii===xi)||Ii===bi&&Di!==Ei,zi=!(Di!==Bi&&Di!==bi||Ii!==Li&&Ii!==Ei),Ci=Yi&&o?h-o:h,t&&h&&Si+Ti+Pi>Ci&&(i?(Ti&&Xi(),Si&&Hi()):(zi||(zi=Di===xi&&Ii==Ei),Fi||zi||Di===Ri||Di===Bi||Di===bi||Ti+Pi>Ci?(Ti&&Xi(),Si&&Hi()):Si&&Hi()))," "===Ai&&!0!==Yi&&Si+Ti===0||(Di===Ri?(" "===Ai&&Ti&&Xi(),Ni(Ai,Pi),Xi()):Fi||zi?(Ti&&Xi(),Ni(Ai,Pi)):Ni(Ai,Pi)),Ii=Di);Ti&&Xi(),Si&&Hi(),ji.length>0&&(ji[ji.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Ui.paraNumber++,Si=a.measureText(t).width,ji.push({x:o||0,text:t,width:Si,paraStart:!0}),Vi&&qi()}))}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":is(e,"x",t[es]);break;case"right":is(e,"x",-t[Zi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":is(e,"y",t[Ji]);break;case"bottom":is(e,"y",-t[ts])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d,autoSizeAlign:c}=e;let{x:u,y:g,width:p,height:f}=s,_=n*i.length+(d?d*(t.paraNumber-1):0),w=o;if(a&&_>f)_=Math.max(f,n),t.overflow=i.length;else if(f||c)switch(l){case"middle":g+=(f-_)/2;break;case"bottom":g+=f-_}w+=g;let v,m,y,x=p||c?p:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(v=i[o],v.x=u,v.width<p||v.width>p&&!a)switch(h){case"center":v.x+=(x-v.width)/2;break;case"right":v.x+=x-v.width}v.paraStart&&d&&o>0&&(w+=d),v.y=w,w+=n,t.overflow>o&&w>_&&(v.isOverflow=!0,t.overflow=o+1),m=v.x,y=v.width,r<0&&(v.width<0?(y=-v.width+e.fontSize+r,m-=y,y+=e.fontSize):y-=r),m<s.x&&(s.x=m),y>s.width&&(s.width=y),a&&p&&p<y&&(v.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=g,s.height=_}(d,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?Ki:l>.01?Qi:$i,t.isOverflow&&!a&&(t.textMode=!0),c===$i?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{c===Qi?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:o,overflow:r}=t;let{textOverflow:a}=e;if(o.splice(r),a&&"show"!==a){let t,h;"hide"===a?a="":"ellipsis"===a&&(a="...");const l=a?i.canvas.measureText(a).width:0,d=s+n-l;("none"===e.textWrap?o:[o[r-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],h=t.x+t.width,!(s===i&&h<d));s--){if(h<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:a,x:h}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e,s,o),"none"!==a&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(d,e),d}};const ns={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!U.object)return t;t=U.object(t)}let s=void 0===t.a?1:t.a;i&&(s*=e);const n=t.r+","+t.g+","+t.b;return 1===s?"rgb("+n+")":"rgba("+n+","+s+")"}},{setPoint:os,addPoint:rs,toBounds:as}=P;const hs={export(t,e,s){this.running=!0;const n=d.fileType(e),o=e.includes(".");return s=d.getExportOptions(s),function(t){ls||(ls=new O);return new Promise((e=>{ls.add((()=>be(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((h=>{const l=t=>{r(t),h(),this.running=!1},{toURL:c}=i,{download:u}=i.origin;if("json"===n)return o&&u(c(JSON.stringify(t.toJSON(s.json)),"text"),e),l({data:!!o||t.toJSON(s.json)});if("svg"===n)return o&&u(c(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:g}=t;g?(ds(t),g.waitViewCompleted((()=>be(this,void 0,void 0,(function*(){let i,n,o=1,r=1;const{worldTransform:h,isLeafer:c,isFrame:u}=t,{slice:p,trim:f,onCanvas:_}=s,w=void 0===s.smooth?g.config.smooth:s.smooth,m=s.contextSettings||g.config.contextSettings,y=s.screenshot||t.isApp,x=c&&y&&void 0===s.fill?t.fill:s.fill,b=d.isOpaqueImage(e)||x,B=new W;if(y)i=!0===y?c?g.canvas.bounds:t.worldRenderBounds:y;else{let e=s.relative||(c?"inner":"local");switch(o=h.scaleX,r=h.scaleY,e){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),o/=t.scaleX,r/=t.scaleY;break;case"world":o=1,r=1;break;case"page":e=t.leafer;default:B.set(h).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,r/=r/i.scaleY}i=t.getBounds("render",e)}const E={scaleX:1,scaleY:1};R.getScaleData(s.scale,s.size,i,E);let L=s.pixelRatio||1;t.isApp&&(E.scaleX*=L,E.scaleY*=L,L=t.app.pixelRatio);const{x:k,y:M,width:T,height:S}=new v(i).scale(E.scaleX,E.scaleY),C={matrix:B.scale(1/E.scaleX,1/E.scaleY).invert().translate(-k,-M).withScale(1/o*E.scaleX,1/r*E.scaleY)};let A,P=a.canvas({width:Math.round(T),height:Math.round(S),pixelRatio:L,smooth:w,contextSettings:m});if(p&&(A=t,A.__worldOpacity=0,t=g,C.bounds=P.bounds),P.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(P,C),t.fill=e}else t.__render(P,C);if(P.restore(),A&&A.__updateWorldOpacity(),f){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?rs(r,n,o):os(r={},n,o)),a++;const h=new v;return as(r,h),h.scale(1/t.pixelRatio).ceil()}(P);const t=P,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:L};P=a.canvas(s),P.copyWorld(t,n,s)}b&&P.fillWorld(P.bounds,x||"#FFFFFF","destination-over"),_&&_(P);const O="canvas"===e?P:yield P.export(e,s);l({data:O,width:P.pixelWidth,height:P.pixelHeight,renderBounds:i,trimBounds:n})}))))):l({data:!1})}))))}};let ls;function ds(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>ds(t)))}const cs=e.prototype,us=t.get("@leafer-ui/export");cs.export=function(t,e){const{quality:i,blob:s}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},cs.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{us.error(t),s(null)}))}))},cs.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},cs.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{us.error(t),s(!1)}))}))},Object.assign(N,ss),Object.assign(U,ns),Object.assign(X,Vt),Object.assign(Y,Ee),Object.assign(G,Ge),Object.assign(H,Qe),Object.assign(V,hs),Object.assign(a,{interaction:(t,e,i,s)=>new Ct(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new z}),J();export{Ct as Interaction,ut as Layouter,K as LeaferCanvas,pt as Renderer,Bt as Selector,tt as Watcher,J as useCanvas};
1
+ import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,defineKey as l,FileHelper as d,LeafList as c,RenderEvent as u,ChildEvent as g,WatchEvent as p,PropertyEvent as f,LeafHelper as _,BranchHelper as w,Bounds as v,LeafBoundsHelper as m,LeafLevelList as y,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as E,Answer as L,MathHelper as R,MatrixHelper as k,AlignHelper as M,ImageEvent as T,AroundHelper as S,PointHelper as C,Direction4 as A,TwoPointBoundsHelper as P,TaskProcessor as O,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as D,InteractionBase as I,Cursor as F,HitCanvasManager as z}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as Y,ColorConvert as G,PaintGradient as U,Export as V,Group as j,TextConvert as N,Paint as X,Effect as H}from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class K 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.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="string"==typeof 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 q.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;s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;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),q.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:o,height:r}=this.autoBounds.getBoundsFrom(t),a={width:o,height:r,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(a)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(a)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};s.copyAttrs(e,this,n),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(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.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:Q,fileType:$}=d;function J(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(Q(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,Q(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q($(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 Image,{crossOrigin:o}=i.image;o&&(n.setAttribute("crossOrigin",o),n.crossOrigin=o),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new K(t,e),image:t=>new h(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:Z}=navigator;Z.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Z.indexOf("Safari")>-1&&-1===Z.indexOf("Chrome")&&(i.fullImageShadow=!0),Z.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Z.indexOf("Mac")>-1?i.os="Mac":Z.indexOf("Linux")>-1&&(i.os="Linux");class tt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new c;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 c,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(u.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new c,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([g.ADD,g.REMOVE],this.__onChildEvent,this),t.on_(p.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:et,updateBounds:it,updateAllWorldOpacity:st}=_,{pushAllChildBranch:nt,pushAllParent:ot}=w;const{worldBounds:rt}=m,at={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new v,this.beforeBounds=new v,this.afterBounds=new v,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(at):this.afterBounds.setListWithFn(t,rt),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:lt,updateAllChange:dt}=_,ct=t.get("Layouter");class ut{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(x.START),this.layoutOnce(),t.emitEvent(new x(x.END,this.layoutedBlocks,this.times))}catch(t){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(p.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:o,AFTER:r}=x,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new x(n,a,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?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),ot(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),ot(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||it(s[t])}it(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&st(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new x(o,a,this.times)),i.emitEvent(new x(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=x,o=this.getBlocks(new c(e));e.emitEvent(new x(i,o,this.times)),ut.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(s,o,this.times)),e.emitEvent(new x(n,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){lt(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const gt=t.get("Renderer");class pt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new v,gt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,gt.error(t)}gt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return gt.warn("rendering");if(this.times>3)return gt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new v,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return gt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new v(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,s){const n=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,n),this.renderBounds=s=s||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),t.showHitView&&this.renderHitView(n),t.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(s)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new v;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(u.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new v(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 v(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||gt.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ft}=E;class _t{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new c(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new c;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||_.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new c;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new c;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new c,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||ft(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:s}=t;if(s&&s.__hasMask&&!t.__.mask&&!s.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:wt,NoAndSkip:vt,YesAndSkip:mt}=L,yt={},xt={},bt={};class Bt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new _t(t,this),t&&this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":yt.id=t.substring(1),t=yt;break;case".":xt.className=t.substring(1),t=xt;break;default:bt.tag=t,t=bt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,e,s){return"node"===i.name&&this.target&&this.target.emit(x.CHECK_UPDATE),this.picker.getByPoint(t,e,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&_.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===wt||o===mt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<vt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(g.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ut(t,e),renderer:(t,e,i)=>new pt(t,e,i),selector:(t,e)=>new Bt(t,e)}),i.layout=ut.fullLayout;const Et={convert(t,e){const i=D.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=D.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=Et.getTouch(t),s=D.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",multiTouch:t.touches.length>1,pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},Lt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let s,n=1,{zoomMode:o,zoomSpeed:r}=e;const a=t.deltaY||t.deltaX;if(o?(s="mouse"===o||!t.deltaX&&(i.intWheelDeltaY?Math.abs(a)>17:Math.ceil(a)!==a),(t.shiftKey||t.metaKey||t.ctrlKey)&&(s=!0)):s=!t.shiftKey&&(t.metaKey||t.ctrlKey),s){r=R.within(r,0,1);n=1-a/(4*(t.deltaY?e.delta.y:e.delta.x))*r,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}},Rt={convert(t){const e=D.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:kt,getZoomEventData:Mt,getRotateEventData:Tt,pathCanDrag:St}=D;class Ct extends I{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(Rt.convert(t))}onKeyUp(t){this.keyUp(Rt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(Et.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||(this.usePointer||(this.usePointer=!0),this.pointerDown(Et.convert(t,this.getLocal(t))))}onPointerMove(t){this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||(this.usePointer||(this.usePointer=!0),this.pointerMove(Et.convert(t,this.getLocal(t,!0))))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(Et.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(Et.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(Et.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(Et.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){const e=Et.getTouch(t),i=this.getLocal(e,!0),{preventDefault:s}=this.config.touch;(!0===s||"auto"===s&&St(this.findPath(i)))&&t.preventDefault(),this.multiTouchStart(t),this.usePointer||(this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0,this.pointerDown(Et.convertTouch(t,i)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=Et.getTouch(t);this.pointerMove(Et.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=Et.getTouch(t);this.pointerUp(Et.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>1,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(D.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config;if(e.disabled)return;const i=e.getScale?e.getScale(t,e):Lt.getScale(t,e),s=this.getLocal(t),n=D.getBase(t);1!==i?this.zoom(Mt(s,i,n)):this.move(kt(s,e.getMove?e.getMove(t,e):Lt.getMove(t,e),n))}onGesturestart(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0)}onGesturechange(t){if(this.useMultiTouch)return;this.preventDefaultWheel(t);const e=this.getLocal(t),i=D.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=R.within(o,0,1),this.zoom(Mt(e,s*s,i)),this.rotate(Tt(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.transformEnd())}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&F.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function At(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function Pt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?Dt(t,!0,e,i):Wt(e,i);break;case"inside":Ot("inside",t,n,e,i);break;case"outside":Ot("outside",t,n,e,i)}}function Ot(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?Dt(e,!0,s,a):Wt(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",At(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function Wt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function Dt(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&Y.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Wt(i,s):s.stroke(),s.restoreBlendMode()):e?Wt(i,s):s.stroke())}function It(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}const{getSpread:Ft,getOuterOf:zt,getByMove:Yt,getIntersectData:Gt}=E;let Ut;function Vt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:r,opacity:a}=e;return{type:n,blendMode:o,style:G.string(r,a)};case"image":return Y.image(i,t,e,s,!Ut||!Ut[e.url]);case"linear":return U.linearGradient(e,s);case"radial":return U.radialGradient(e,s);case"angular":return U.conicGradient(e,s);default:return void 0!==e.r?{type:"solid",style:G.string(e)}:void 0}}const jt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Ut=Y.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=Vt(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?At(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&Y.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?At(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?At(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?At(e,i):n?i.fill(n):i.fill())},fillText:At,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Pt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke(),s.__useArrow&&It(e,i);break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Pt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Dt(t,!1,e,i),s.__useArrow&&It(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Dt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Dt(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Pt,drawTextStroke:Wt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=Gt(s?Ft(e.bounds,l===d?s*l:[s*d,s*l]):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:g}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=g),a=zt(n,r),o=Yt(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,g*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,g)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let Nt={};const{get:Xt,rotateOfOuter:Ht,translate:qt,scaleOfOuter:Kt,scale:Qt,rotate:$t}=k;function Jt(t,e,i,s,n,o,r){const a=Xt();qt(a,e.x+i,e.y+s),Qt(a,n,o),r&&Ht(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function Zt(t,e,i,s,n,o,r){const a=Xt();qt(a,e.x+i,e.y+s),n&&Qt(a,n,o),r&&$t(a,r),t.transform=a}function te(t,e,i,s,n,o,r,a,h,l){const d=Xt();if(h)if("center"===l)Ht(d,{x:i/2,y:s/2},h);else switch($t(d,h),h){case 90:qt(d,s,0);break;case 180:qt(d,i,s);break;case 270:qt(d,0,i)}Nt.x=e.x+n,Nt.y=e.y+o,qt(d,Nt.x,Nt.y),r&&Kt(d,Nt,r,a),t.transform=d}const{get:ee,translate:ie}=k,se=new v,ne={},oe={};function re(t,e,i,s){const{blendMode:n,sync:o}=i;n&&(t.blendMode=n),o&&(t.sync=o),t.data=ae(i,s,e)}function ae(t,e,i){let{width:s,height:n}=i;t.padding&&(e=se.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:r,align:a,offset:h,scale:l,size:d,rotation:c,repeat:u}=t,g=e.width===s&&e.height===n,p={mode:r},f="center"!==a&&(c||0)%180==90,_=f?n:s,w=f?s:n;let v,m,y=0,x=0;if(r&&"cover"!==r&&"fit"!==r)(l||d)&&(R.getScaleData(l,d,i,oe),v=oe.scaleX,m=oe.scaleY);else if(!g||c){const t=e.width/_,i=e.height/w;v=m="fit"===r?Math.min(t,i):Math.max(t,i),y+=(e.width-s*v)/2,x+=(e.height-n*m)/2}if(a){const t={x:y,y:x,width:_,height:w};v&&(t.width*=v,t.height*=m),M.toPoint(a,t,e,ne,!0),y+=ne.x,x+=ne.y}switch(h&&(y+=h.x,x+=h.y),r){case"stretch":g||(s=e.width,n=e.height);break;case"normal":case"clip":(y||x||v||c)&&Zt(p,e,y,x,v,m,c);break;case"repeat":(!g||v||c)&&te(p,e,s,n,y,x,v,m,c,a),u||(p.repeat="repeat");break;default:v&&Jt(p,e,y,x,v,m,c)}return p.transform||(e.x||e.y)&&(p.transform=ee(),ie(p.transform,e.x,e.y)),v&&"stretch"!==r&&(p.scaleX=v,p.scaleY=m),p.width=s,p.height=n,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let he,le=new v;const{isSame:de}=E;function ce(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||re(n,s,i,o),!0}function ue(t,e){fe(t,T.LOAD,e)}function ge(t,e){fe(t,T.LOADED,e)}function pe(t,e,i){e.error=i,t.forceUpdate("surface"),fe(t,T.ERROR,e)}function fe(t,e,i){t.hasEvent(e)&&t.emitEvent(new T(e,i))}function _e(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:we,scale:ve,copy:me}=k,{ceil:ye,abs:xe}=Math;function be(t,e,s){let{scaleX:n,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o+"-"+s;if(e.patternId===r||t.destroyed)return!1;{n=xe(n),o=xe(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:g,opacity:p,transform:f,repeat:_}=a;u&&(l=we(),me(l,f),ve(l,1/u,1/g),n*=u,o*=g),n*=s,o*=s,d*=n,c*=o;const w=d*c;if(!_&&w>i.image.maxCacheSize)return!1;let v=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;v>e&&(v=e)}w>v&&(h=Math.sqrt(w/v)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=g),(f||1!==n||1!==o)&&(l||(l=we(),f&&me(l,f)),ve(l,1/n,1/o));const m=t.getCanvas(ye(d)||1,ye(c)||1,p),y=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=y,e.patternId=r,!0}}function Be(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Ee}=Math;const Le={image:function(t,e,i,s,n){let o,r;const a=B.get(i);return he&&i===he.paint&&de(s,he.boxBounds)?o=he.leafPaint:(o={type:i.type,image:a},he=a.use>1?{leafPaint:o,paint:i,boxBounds:le.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ce(t,e,i,a,o,s),n&&(ue(t,r),ge(t,r))):a.error?n&&pe(t,r,a.error):(n&&(_e(t,!0),ue(t,r)),o.loadId=a.load((()=>{_e(t,!1),t.destroyed||(ce(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ge(t,r)),o.loadId=null}),(e=>{_e(t,!1),pe(t,r,e),o.loadId=null}))),o},checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:a}=e;if(!s.data||s.patternId===o+"-"+r+"-"+a&&!V.running)return!1;{const{data:h}=s;if(n)if(h.repeat)n=!1;else{let{width:t,height:e}=h;t*=Ee(o)*a,e*=Ee(r)*a,h.scaleX&&(t*=h.scaleX,e*=h.scaleY),n=t*e>i.image.maxCacheSize||V.running}return n?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),s.blendMode&&(e.blendMode=s.blendMode),h.opacity&&(e.opacity*=h.opacity),h.transform&&e.transform(h.transform),e.drawImage(s.image.view,0,0,h.width,h.height),e.restore(),!0):(!s.style||s.sync||V.running?be(t,s,a):s.patternTask||(s.patternTask=B.patternTasker.add((()=>Be(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&be(t,s,a),t.forceUpdate("surface")}))),300)),!1)}},createPattern:be,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,B.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null},createData:re,getPatternData:ae,fillOrFitMode:Jt,clipMode:Zt,repeatMode:te},{toPoint:Re}=S,ke={},Me={};function Te(t,e,i){if(e){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],"string"==typeof s?t.addColorStop(n/(o-1),G.string(s,i)):t.addColorStop(s.offset,G.string(s.color,i))}}const{getAngle:Se,getDistance:Ce}=C,{get:Ae,rotateOfOuter:Pe,scaleOfOuter:Oe}=k,{toPoint:We}=S,De={},Ie={};function Fe(t,e,i,s,n){let o;const{width:r,height:a}=t;if(r!==a||s){const t=Se(e,i);o=Ae(),n?(Oe(o,e,r/a*(s||1),1),Pe(o,e,t+90)):(Oe(o,e,1,r/a*(s||1)),Pe(o,e,t))}return o}const{getDistance:ze}=C,{toPoint:Ye}=S,Ge={},Ue={};const Ve={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;Re(s||"top",e,ke),Re(n||"bottom",e,Me);const h=i.canvas.createLinearGradient(ke.x,ke.y,Me.x,Me.y);Te(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;We(s||"center",e,De),We(n||"bottom",e,Ie);const l=i.canvas.createRadialGradient(De.x,De.y,0,De.x,De.y,Ce(De,Ie));Te(l,t.stops,r);const d={type:o,style:l},c=Fe(e,De,Ie,h,!0);return c&&(d.transform=c),a&&(d.blendMode=a),d},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Ye(s||"center",e,Ge),Ye(n||"bottom",e,Ue);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Ge.x,Ge.y):i.canvas.createRadialGradient(Ge.x,Ge.y,0,Ge.x,Ge.y,ze(Ge,Ue));Te(l,t.stops,r);const d={type:o,style:l},c=Fe(e,Ge,Ue,h||1,i.conicGradientRotate90);return c&&(d.transform=c),a&&(d.blendMode=a),d},getTransform:Fe},{copy:je,toOffsetOutBounds:Ne}=E,Xe={},He={};function qe(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(je(Xe,t.bounds),Xe.x+=e.x-r.x,Xe.y+=e.y-r.y,s){const{matrix:t}=n;Xe.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Xe.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Xe.width*=s,Xe.height*=s}t.copyWorld(n.canvas,t.bounds,Xe)}else s&&(je(Xe,e),Xe.x-=e.width/2*(s-1),Xe.y-=e.height/2*(s-1),Xe.width*=s,Xe.height*=s),t.copyWorld(n.canvas,r,s?Xe:e)}const{toOffsetOutBounds:Ke}=E,Qe={};const $e={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),p=a.length-1;Ne(l,He),a.forEach(((a,f)=>{g.setWorldShadow(He.offsetX+a.x*c,He.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,qe(g,He,n,i),s=l,a.box&&(g.restore(),g.save(),h&&(g.copyWorld(g,l,o,"copy"),s=o),h?g.copyWorld(h,o,o,"destination-out"):g.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(g,s,o,a.blendMode):e.copyWorldToInner(g,s,r.renderBounds,a.blendMode),p&&f<p&&g.clearWorld(s,!0)})),g.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),p=a.length-1;Ke(l,Qe),a.forEach(((a,f)=>{g.save(),g.setWorldShadow(Qe.offsetX+a.x*c,Qe.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,qe(g,Qe,n,i),g.restore(),h?(g.copyWorld(g,l,o,"copy"),g.copyWorld(h,o,o,"source-out"),s=o):(g.copyWorld(i.canvas,d,l,"source-out"),s=l),g.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(g,s,o,a.blendMode):e.copyWorldToInner(g,s,r.renderBounds,a.blendMode),p&&f<p&&g.clearWorld(s,!0)})),g.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Je}=m;function Ze(t,e,i,s,n,o){switch(e){case"grayscale":n.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),ei(t,e,i,1)}(t,i,s,n);break;case"opacity-path":ei(t,i,s,o);break;case"path":i.restore()}}function ti(t){return t.getSameCanvas(!1,!0)}function ei(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}j.prototype.__renderMask=function(t,e){let i,s,n,o,r,a;const{children:h}=this;for(let l=0,d=h.length;l<d;l++)i=h[l],a=i.__.mask,a&&(r&&(Ze(this,r,t,n,s,o),s=n=null),"path"===a||"clipping-path"===a?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=ti(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="grayscale"===a?"grayscale":"alpha",s||(s=ti(t)),n||(n=ti(t)),i.__render(s,e)),"clipping"!==a&&"clipping-path"!==a)||Je(i,e)||i.__render(n||t,e);Ze(this,r,t,n,s,o)};const ii=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",si=ii+"_#~&*+\\=|≮≯≈≠=…",ni=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 oi(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ri=oi("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ai=oi("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),hi=oi(ii),li=oi(si),di=oi("- —/~|┆·");var ci;!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"}(ci||(ci={}));const{Letter:ui,Single:gi,Before:pi,After:fi,Symbol:_i,Break:wi}=ci;function vi(t){return ri[t]?ui:di[t]?wi:ai[t]?pi:hi[t]?fi:li[t]?_i:ni.test(t)?gi:ui}const mi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function yi(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:xi}=mi,{Letter:bi,Single:Bi,Before:Ei,After:Li,Symbol:Ri,Break:ki}=ci;let Mi,Ti,Si,Ci,Ai,Pi,Oi,Wi,Di,Ii,Fi,zi,Yi,Gi,Ui,Vi,ji,Ni=[];function Xi(t,e){Di&&!Wi&&(Wi=Di),Mi.data.push({char:t,width:e}),Si+=e}function Hi(){Ci+=Si,Mi.width=Si,Ti.words.push(Mi),Mi={data:[]},Si=0}function qi(){Gi&&(Ui.paraNumber++,Ti.paraStart=!0,Gi=!1),Di&&(Ti.startCharSize=Wi,Ti.endCharSize=Di,Wi=0),Ti.width=Ci,Vi.width?xi(Ti):ji&&Ki(),Ni.push(Ti),Ti={words:[]},Ci=0}function Ki(){Ci>(Ui.maxWidth||0)&&(Ui.maxWidth=Ci)}const Qi=0,$i=1,Ji=2;const{top:Zi,right:ts,bottom:es,left:is}=A;function ss(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 ns={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o?(s=l[is],o-=l[ts]+l[is]):e.autoSizeAlign||(s=l[is]),r?(n=l[Zi],r-=l[Zi]+l[es]):e.autoSizeAlign||(n=l[Zi]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Ui=t,Ni=t.rows,Vi=t.bounds,ji=!Vi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=Vi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Gi=!0,Fi=null,Wi=Oi=Di=Si=Ci=0,Mi={data:[]},Ti={words:[]};for(let s=0,l=e.length;s<l;s++)Pi=e[s],"\n"===Pi?(Si&&Hi(),Ti.paraEnd=!0,qi(),Gi=!0):(Ii=vi(Pi),Ii===bi&&"none"!==r&&(Pi=yi(Pi,r,!Si)),Oi=a.measureText(Pi).width,n&&(n<0&&(Di=Oi),Oi+=n),zi=Ii===Bi&&(Fi===Bi||Fi===bi)||Fi===Bi&&Ii!==Li,Yi=!(Ii!==Ei&&Ii!==Bi||Fi!==Ri&&Fi!==Li),Ai=Gi&&o?h-o:h,t&&h&&Ci+Si+Oi>Ai&&(i?(Si&&Hi(),Ci&&qi()):(Yi||(Yi=Ii===bi&&Fi==Li),zi||Yi||Ii===ki||Ii===Ei||Ii===Bi||Si+Oi>Ai?(Si&&Hi(),Ci&&qi()):Ci&&qi()))," "===Pi&&!0!==Gi&&Ci+Si===0||(Ii===ki?(" "===Pi&&Si&&Hi(),Xi(Pi,Oi),Hi()):zi||Yi?(Si&&Hi(),Xi(Pi,Oi)):Xi(Pi,Oi)),Fi=Ii);Si&&Hi(),Ci&&qi(),Ni.length>0&&(Ni[Ni.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Ui.paraNumber++,Ci=a.measureText(t).width,Ni.push({x:o||0,text:t,width:Ci,paraStart:!0}),ji&&Ki()}))}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":ss(e,"x",t[is]);break;case"right":ss(e,"x",-t[ts])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":ss(e,"y",t[Zi]);break;case"bottom":ss(e,"y",-t[es])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d,autoSizeAlign:c}=e;let{x:u,y:g,width:p,height:f}=s,_=n*i.length+(d?d*(t.paraNumber-1):0),w=o;if(a&&_>f)_=Math.max(f,n),t.overflow=i.length;else if(f||c)switch(l){case"middle":g+=(f-_)/2;break;case"bottom":g+=f-_}w+=g;let v,m,y,x=p||c?p:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(v=i[o],v.x=u,v.width<p||v.width>p&&!a)switch(h){case"center":v.x+=(x-v.width)/2;break;case"right":v.x+=x-v.width}v.paraStart&&d&&o>0&&(w+=d),v.y=w,w+=n,t.overflow>o&&w>_&&(v.isOverflow=!0,t.overflow=o+1),m=v.x,y=v.width,r<0&&(v.width<0?(y=-v.width+e.fontSize+r,m-=y,y+=e.fontSize):y-=r),m<s.x&&(s.x=m),y>s.width&&(s.width=y),a&&p&&p<y&&(v.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=g,s.height=_}(d,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?Qi:l>.01?$i:Ji,t.isOverflow&&!a&&(t.textMode=!0),c===Ji?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{c===$i?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:o,overflow:r}=t;let{textOverflow:a}=e;if(o.splice(r),a&&"show"!==a){let t,h;"hide"===a?a="":"ellipsis"===a&&(a="...");const l=a?i.canvas.measureText(a).width:0,d=s+n-l;("none"===e.textWrap?o:[o[r-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],h=t.x+t.width,!(s===i&&h<d));s--){if(h<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:a,x:h}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e,s,o),"none"!==a&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(d,e),d}};const os={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!G.object)return t;t=G.object(t)}let s=void 0===t.a?1:t.a;i&&(s*=e);const n=t.r+","+t.g+","+t.b;return 1===s?"rgb("+n+")":"rgba("+n+","+s+")"}},{setPoint:rs,addPoint:as,toBounds:hs}=P;const ls={export(t,e,s){this.running=!0;const n=d.fileType(e),o=e.includes(".");return s=d.getExportOptions(s),function(t){ds||(ds=new O);return new Promise((e=>{ds.add((()=>Be(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((h=>{const l=t=>{r(t),h(),this.running=!1},{toURL:c}=i,{download:u}=i.origin;if("json"===n)return o&&u(c(JSON.stringify(t.toJSON(s.json)),"text"),e),l({data:!!o||t.toJSON(s.json)});if("svg"===n)return o&&u(c(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:g}=t;g?(cs(t),g.waitViewCompleted((()=>Be(this,void 0,void 0,(function*(){let i,n,o=1,r=1;const{worldTransform:h,isLeafer:c,isFrame:u}=t,{slice:p,trim:f,onCanvas:_}=s,w=void 0===s.smooth?g.config.smooth:s.smooth,m=s.contextSettings||g.config.contextSettings,y=s.screenshot||t.isApp,x=c&&y&&void 0===s.fill?t.fill:s.fill,b=d.isOpaqueImage(e)||x,B=new W;if(y)i=!0===y?c?g.canvas.bounds:t.worldRenderBounds:y;else{let e=s.relative||(c?"inner":"local");switch(o=h.scaleX,r=h.scaleY,e){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),o/=t.scaleX,r/=t.scaleY;break;case"world":o=1,r=1;break;case"page":e=t.leafer;default:B.set(h).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,r/=r/i.scaleY}i=t.getBounds("render",e)}const E={scaleX:1,scaleY:1};R.getScaleData(s.scale,s.size,i,E);let L=s.pixelRatio||1;t.isApp&&(E.scaleX*=L,E.scaleY*=L,L=t.app.pixelRatio);const{x:k,y:M,width:T,height:S}=new v(i).scale(E.scaleX,E.scaleY),C={matrix:B.scale(1/E.scaleX,1/E.scaleY).invert().translate(-k,-M).withScale(1/o*E.scaleX,1/r*E.scaleY)};let A,P=a.canvas({width:Math.round(T),height:Math.round(S),pixelRatio:L,smooth:w,contextSettings:m});if(p&&(A=t,A.__worldOpacity=0,t=g,C.bounds=P.bounds),P.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(P,C),t.fill=e}else t.__render(P,C);if(P.restore(),A&&A.__updateWorldOpacity(),f){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?as(r,n,o):rs(r={},n,o)),a++;const h=new v;return hs(r,h),h.scale(1/t.pixelRatio).ceil()}(P);const t=P,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:L};P=a.canvas(s),P.copyWorld(t,n,s)}b&&P.fillWorld(P.bounds,x||"#FFFFFF","destination-over"),_&&_(P);const O="canvas"===e?P:yield P.export(e,s);l({data:O,width:P.pixelWidth,height:P.pixelHeight,renderBounds:i,trimBounds:n})}))))):l({data:!1})}))))}};let ds;function cs(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>cs(t)))}const us=e.prototype,gs=t.get("@leafer-ui/export");us.export=function(t,e){const{quality:i,blob:s}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},us.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{gs.error(t),s(null)}))}))},us.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},us.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{gs.error(t),s(!1)}))}))},Object.assign(N,ns),Object.assign(G,os),Object.assign(X,jt),Object.assign(Y,Le),Object.assign(U,Ve),Object.assign(H,$e),Object.assign(V,ls),Object.assign(a,{interaction:(t,e,i,s)=>new Ct(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new z}),J();export{Ct as Interaction,ut as Layouter,K as LeaferCanvas,pt as Renderer,Bt as Selector,tt as Watcher,J as useCanvas};