@meta2d/core 1.0.54 → 1.0.56

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.
Files changed (302) hide show
  1. package/README.md +13 -0
  2. package/package.build.json +39 -0
  3. package/package.json +38 -38
  4. package/src/canvas/canvas.ts +8639 -0
  5. package/src/canvas/canvasImage.ts +525 -0
  6. package/src/canvas/canvasTemplate.ts +257 -0
  7. package/src/canvas/magnifierCanvas.ts +142 -0
  8. package/src/canvas/offscreen.ts +14 -0
  9. package/src/core.ts +5128 -0
  10. package/src/data.ts +86 -0
  11. package/src/diagrams/arrow.ts +50 -0
  12. package/src/diagrams/circle.ts +19 -0
  13. package/src/diagrams/cloud.ts +34 -0
  14. package/src/diagrams/cube.ts +94 -0
  15. package/src/diagrams/diamond.ts +14 -0
  16. package/src/diagrams/file.ts +19 -0
  17. package/src/diagrams/gif.ts +105 -0
  18. package/src/diagrams/{hexagon.js → hexagon.ts} +19 -14
  19. package/src/diagrams/iframe.ts +365 -0
  20. package/src/diagrams/{index.js → index.ts} +36 -34
  21. package/src/diagrams/line/arrow.ts +175 -0
  22. package/src/diagrams/line/curve.ts +260 -0
  23. package/src/diagrams/line/line.ts +409 -0
  24. package/src/diagrams/line/polyline.ts +676 -0
  25. package/src/diagrams/line/smooth.ts +133 -0
  26. package/src/diagrams/message.ts +17 -0
  27. package/src/diagrams/mindLine.ts +31 -0
  28. package/src/diagrams/mindNode.ts +177 -0
  29. package/src/diagrams/panel.ts +149 -0
  30. package/src/diagrams/pentagon.ts +48 -0
  31. package/src/diagrams/pentagram.ts +63 -0
  32. package/src/diagrams/people.ts +23 -0
  33. package/src/diagrams/rectangle.ts +29 -0
  34. package/src/diagrams/svg/parse.ts +319 -0
  35. package/src/diagrams/svgPath.ts +53 -0
  36. package/src/diagrams/triangle.ts +43 -0
  37. package/src/diagrams/video.ts +202 -0
  38. package/src/dialog/dialog.ts +177 -0
  39. package/src/event/event.ts +142 -0
  40. package/src/map/map.ts +239 -0
  41. package/src/options.ts +205 -0
  42. package/src/pen/arrow.ts +259 -0
  43. package/src/pen/math.ts +253 -0
  44. package/src/pen/model.ts +785 -0
  45. package/src/pen/plugin.ts +57 -0
  46. package/src/pen/render.ts +3725 -0
  47. package/src/pen/text.ts +341 -0
  48. package/src/pen/utils.ts +21 -0
  49. package/src/point/point.ts +232 -0
  50. package/src/rect/rect.ts +507 -0
  51. package/src/rect/triangle.ts +16 -0
  52. package/src/scroll/scroll.ts +277 -0
  53. package/src/store/global.ts +38 -0
  54. package/src/store/store.ts +293 -0
  55. package/src/theme.ts +35 -0
  56. package/src/title/title.ts +115 -0
  57. package/src/tooltip/tooltip.ts +199 -0
  58. package/src/utils/clone.ts +79 -0
  59. package/src/utils/color.ts +126 -0
  60. package/src/utils/error.ts +7 -0
  61. package/src/utils/file.ts +46 -0
  62. package/src/utils/{index.d.ts → index.ts} +1 -0
  63. package/src/utils/math.ts +120 -0
  64. package/src/utils/object.ts +23 -0
  65. package/src/utils/padding.ts +48 -0
  66. package/src/utils/time.ts +25 -0
  67. package/src/utils/url.ts +30 -0
  68. package/src/utils/uuid.ts +15 -0
  69. package/index.js +0 -10
  70. package/index.js.map +0 -1
  71. package/src/canvas/canvas.d.ts +0 -455
  72. package/src/canvas/canvas.js +0 -8168
  73. package/src/canvas/canvas.js.map +0 -1
  74. package/src/canvas/canvasImage.d.ts +0 -28
  75. package/src/canvas/canvasImage.js +0 -503
  76. package/src/canvas/canvasImage.js.map +0 -1
  77. package/src/canvas/canvasTemplate.d.ts +0 -19
  78. package/src/canvas/canvasTemplate.js +0 -229
  79. package/src/canvas/canvasTemplate.js.map +0 -1
  80. package/src/canvas/index.js +0 -3
  81. package/src/canvas/index.js.map +0 -1
  82. package/src/canvas/magnifierCanvas.d.ts +0 -20
  83. package/src/canvas/magnifierCanvas.js +0 -101
  84. package/src/canvas/magnifierCanvas.js.map +0 -1
  85. package/src/canvas/offscreen.d.ts +0 -2
  86. package/src/canvas/offscreen.js +0 -14
  87. package/src/canvas/offscreen.js.map +0 -1
  88. package/src/core.d.ts +0 -477
  89. package/src/core.js +0 -5168
  90. package/src/core.js.map +0 -1
  91. package/src/data.d.ts +0 -34
  92. package/src/data.js +0 -85
  93. package/src/data.js.map +0 -1
  94. package/src/diagrams/arrow.d.ts +0 -4
  95. package/src/diagrams/arrow.js +0 -47
  96. package/src/diagrams/arrow.js.map +0 -1
  97. package/src/diagrams/circle.d.ts +0 -2
  98. package/src/diagrams/circle.js +0 -9
  99. package/src/diagrams/circle.js.map +0 -1
  100. package/src/diagrams/cloud.d.ts +0 -2
  101. package/src/diagrams/cloud.js +0 -12
  102. package/src/diagrams/cloud.js.map +0 -1
  103. package/src/diagrams/cube.d.ts +0 -2
  104. package/src/diagrams/cube.js +0 -70
  105. package/src/diagrams/cube.js.map +0 -1
  106. package/src/diagrams/diamond.d.ts +0 -2
  107. package/src/diagrams/diamond.js +0 -13
  108. package/src/diagrams/diamond.js.map +0 -1
  109. package/src/diagrams/file.d.ts +0 -2
  110. package/src/diagrams/file.js +0 -18
  111. package/src/diagrams/file.js.map +0 -1
  112. package/src/diagrams/gif.d.ts +0 -5
  113. package/src/diagrams/gif.js +0 -90
  114. package/src/diagrams/gif.js.map +0 -1
  115. package/src/diagrams/hexagon.d.ts +0 -2
  116. package/src/diagrams/hexagon.js.map +0 -1
  117. package/src/diagrams/iframe.d.ts +0 -2
  118. package/src/diagrams/iframe.js +0 -356
  119. package/src/diagrams/iframe.js.map +0 -1
  120. package/src/diagrams/index.d.ts +0 -71
  121. package/src/diagrams/index.js.map +0 -1
  122. package/src/diagrams/line/arrow.d.ts +0 -2
  123. package/src/diagrams/line/arrow.js +0 -128
  124. package/src/diagrams/line/arrow.js.map +0 -1
  125. package/src/diagrams/line/curve.d.ts +0 -16
  126. package/src/diagrams/line/curve.js +0 -236
  127. package/src/diagrams/line/curve.js.map +0 -1
  128. package/src/diagrams/line/index.js +0 -6
  129. package/src/diagrams/line/index.js.map +0 -1
  130. package/src/diagrams/line/line.d.ts +0 -42
  131. package/src/diagrams/line/line.js +0 -431
  132. package/src/diagrams/line/line.js.map +0 -1
  133. package/src/diagrams/line/polyline.d.ts +0 -10
  134. package/src/diagrams/line/polyline.js +0 -657
  135. package/src/diagrams/line/polyline.js.map +0 -1
  136. package/src/diagrams/line/smooth.d.ts +0 -3
  137. package/src/diagrams/line/smooth.js +0 -174
  138. package/src/diagrams/line/smooth.js.map +0 -1
  139. package/src/diagrams/message.d.ts +0 -2
  140. package/src/diagrams/message.js +0 -15
  141. package/src/diagrams/message.js.map +0 -1
  142. package/src/diagrams/mindLine.d.ts +0 -3
  143. package/src/diagrams/mindLine.js +0 -31
  144. package/src/diagrams/mindLine.js.map +0 -1
  145. package/src/diagrams/mindNode.d.ts +0 -3
  146. package/src/diagrams/mindNode.js +0 -189
  147. package/src/diagrams/mindNode.js.map +0 -1
  148. package/src/diagrams/panel.d.ts +0 -2
  149. package/src/diagrams/panel.js +0 -131
  150. package/src/diagrams/panel.js.map +0 -1
  151. package/src/diagrams/pentagon.d.ts +0 -3
  152. package/src/diagrams/pentagon.js +0 -46
  153. package/src/diagrams/pentagon.js.map +0 -1
  154. package/src/diagrams/pentagram.d.ts +0 -3
  155. package/src/diagrams/pentagram.js +0 -77
  156. package/src/diagrams/pentagram.js.map +0 -1
  157. package/src/diagrams/people.d.ts +0 -2
  158. package/src/diagrams/people.js +0 -19
  159. package/src/diagrams/people.js.map +0 -1
  160. package/src/diagrams/rectangle.d.ts +0 -3
  161. package/src/diagrams/rectangle.js +0 -26
  162. package/src/diagrams/rectangle.js.map +0 -1
  163. package/src/diagrams/svg/parse.d.ts +0 -15
  164. package/src/diagrams/svg/parse.js +0 -326
  165. package/src/diagrams/svg/parse.js.map +0 -1
  166. package/src/diagrams/svgPath.d.ts +0 -2
  167. package/src/diagrams/svgPath.js +0 -30
  168. package/src/diagrams/svgPath.js.map +0 -1
  169. package/src/diagrams/triangle.d.ts +0 -3
  170. package/src/diagrams/triangle.js +0 -41
  171. package/src/diagrams/triangle.js.map +0 -1
  172. package/src/diagrams/video.d.ts +0 -5
  173. package/src/diagrams/video.js +0 -185
  174. package/src/diagrams/video.js.map +0 -1
  175. package/src/dialog/dialog.d.ts +0 -14
  176. package/src/dialog/dialog.js +0 -77
  177. package/src/dialog/dialog.js.map +0 -1
  178. package/src/dialog/index.js +0 -2
  179. package/src/dialog/index.js.map +0 -1
  180. package/src/event/event.d.ts +0 -102
  181. package/src/event/event.js +0 -22
  182. package/src/event/event.js.map +0 -1
  183. package/src/event/index.js +0 -2
  184. package/src/event/index.js.map +0 -1
  185. package/src/map/index.js +0 -2
  186. package/src/map/index.js.map +0 -1
  187. package/src/map/map.d.ts +0 -21
  188. package/src/map/map.js +0 -210
  189. package/src/map/map.js.map +0 -1
  190. package/src/options.d.ts +0 -130
  191. package/src/options.js +0 -80
  192. package/src/options.js.map +0 -1
  193. package/src/pen/arrow.d.ts +0 -4
  194. package/src/pen/arrow.js +0 -188
  195. package/src/pen/arrow.js.map +0 -1
  196. package/src/pen/index.js +0 -7
  197. package/src/pen/index.js.map +0 -1
  198. package/src/pen/math.d.ts +0 -28
  199. package/src/pen/math.js +0 -304
  200. package/src/pen/math.js.map +0 -1
  201. package/src/pen/model.d.ts +0 -512
  202. package/src/pen/model.js +0 -209
  203. package/src/pen/model.js.map +0 -1
  204. package/src/pen/plugin.d.ts +0 -5
  205. package/src/pen/plugin.js +0 -88
  206. package/src/pen/plugin.js.map +0 -1
  207. package/src/pen/render.d.ts +0 -147
  208. package/src/pen/render.js +0 -3229
  209. package/src/pen/render.js.map +0 -1
  210. package/src/pen/text.d.ts +0 -8
  211. package/src/pen/text.js +0 -375
  212. package/src/pen/text.js.map +0 -1
  213. package/src/pen/utils.d.ts +0 -2
  214. package/src/pen/utils.js +0 -41
  215. package/src/pen/utils.js.map +0 -1
  216. package/src/point/index.js +0 -2
  217. package/src/point/index.js.map +0 -1
  218. package/src/point/point.d.ts +0 -65
  219. package/src/point/point.js +0 -179
  220. package/src/point/point.js.map +0 -1
  221. package/src/rect/index.js +0 -2
  222. package/src/rect/index.js.map +0 -1
  223. package/src/rect/rect.d.ts +0 -52
  224. package/src/rect/rect.js +0 -486
  225. package/src/rect/rect.js.map +0 -1
  226. package/src/rect/triangle.d.ts +0 -2
  227. package/src/rect/triangle.js +0 -10
  228. package/src/rect/triangle.js.map +0 -1
  229. package/src/scroll/index.js +0 -2
  230. package/src/scroll/index.js.map +0 -1
  231. package/src/scroll/scroll.d.ts +0 -35
  232. package/src/scroll/scroll.js +0 -221
  233. package/src/scroll/scroll.js.map +0 -1
  234. package/src/store/global.d.ts +0 -25
  235. package/src/store/global.js +0 -18
  236. package/src/store/global.js.map +0 -1
  237. package/src/store/index.js +0 -3
  238. package/src/store/index.js.map +0 -1
  239. package/src/store/store.d.ts +0 -226
  240. package/src/store/store.js +0 -121
  241. package/src/store/store.js.map +0 -1
  242. package/src/theme.d.ts +0 -13
  243. package/src/theme.js +0 -23
  244. package/src/theme.js.map +0 -1
  245. package/src/title/index.js +0 -2
  246. package/src/title/index.js.map +0 -1
  247. package/src/title/title.d.ts +0 -30
  248. package/src/title/title.js +0 -99
  249. package/src/title/title.js.map +0 -1
  250. package/src/tooltip/index.js +0 -2
  251. package/src/tooltip/index.js.map +0 -1
  252. package/src/tooltip/tooltip.d.ts +0 -40
  253. package/src/tooltip/tooltip.js +0 -167
  254. package/src/tooltip/tooltip.js.map +0 -1
  255. package/src/utils/browser.d.ts +0 -1
  256. package/src/utils/browser.js +0 -4
  257. package/src/utils/browser.js.map +0 -1
  258. package/src/utils/clone.d.ts +0 -8
  259. package/src/utils/clone.js +0 -88
  260. package/src/utils/clone.js.map +0 -1
  261. package/src/utils/color.d.ts +0 -3
  262. package/src/utils/color.js +0 -126
  263. package/src/utils/color.js.map +0 -1
  264. package/src/utils/error.d.ts +0 -2
  265. package/src/utils/error.js +0 -6
  266. package/src/utils/error.js.map +0 -1
  267. package/src/utils/file.d.ts +0 -3
  268. package/src/utils/file.js +0 -92
  269. package/src/utils/file.js.map +0 -1
  270. package/src/utils/index.js +0 -9
  271. package/src/utils/index.js.map +0 -1
  272. package/src/utils/math.d.ts +0 -18
  273. package/src/utils/math.js +0 -152
  274. package/src/utils/math.js.map +0 -1
  275. package/src/utils/object.d.ts +0 -2
  276. package/src/utils/object.js +0 -21
  277. package/src/utils/object.js.map +0 -1
  278. package/src/utils/padding.d.ts +0 -7
  279. package/src/utils/padding.js +0 -47
  280. package/src/utils/padding.js.map +0 -1
  281. package/src/utils/time.d.ts +0 -1
  282. package/src/utils/time.js +0 -17
  283. package/src/utils/time.js.map +0 -1
  284. package/src/utils/url.d.ts +0 -4
  285. package/src/utils/url.js +0 -27
  286. package/src/utils/url.js.map +0 -1
  287. package/src/utils/uuid.d.ts +0 -4
  288. package/src/utils/uuid.js +0 -13
  289. package/src/utils/uuid.js.map +0 -1
  290. /package/{index.d.ts → index.ts} +0 -0
  291. /package/src/canvas/{index.d.ts → index.ts} +0 -0
  292. /package/src/diagrams/line/{index.d.ts → index.ts} +0 -0
  293. /package/src/dialog/{index.d.ts → index.ts} +0 -0
  294. /package/src/event/{index.d.ts → index.ts} +0 -0
  295. /package/src/map/{index.d.ts → index.ts} +0 -0
  296. /package/src/pen/{index.d.ts → index.ts} +0 -0
  297. /package/src/point/{index.d.ts → index.ts} +0 -0
  298. /package/src/rect/{index.d.ts → index.ts} +0 -0
  299. /package/src/scroll/{index.d.ts → index.ts} +0 -0
  300. /package/src/store/{index.d.ts → index.ts} +0 -0
  301. /package/src/title/{index.d.ts → index.ts} +0 -0
  302. /package/src/tooltip/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,365 @@
1
+ import { Pen, setElemPosition } from '../pen';
2
+ import { Point } from '../point';
3
+ import { deepClone, getRootDomain } from '../utils';
4
+
5
+ export function iframe(pen: Pen) {
6
+ if (!pen.onDestroy) {
7
+ pen.onDestroy = destory;
8
+ pen.onMove = move;
9
+ pen.onResize = move;
10
+ pen.onRotate = move;
11
+ pen.onValue = move;
12
+ pen.onMouseMove = mouseMove;
13
+ pen.onBeforeValue = beforeValue;
14
+ pen.onRenderPenRaw = renderPenRaw;
15
+ }
16
+ if (!pen.calculative.singleton) {
17
+ pen.calculative.singleton = {};
18
+ }
19
+ const worldRect = pen.calculative.worldRect;
20
+
21
+ if (!pen.calculative.singleton.div) {
22
+ const div = document.createElement('div');
23
+ div.style.position = 'absolute';
24
+ div.style.outline = 'none';
25
+ div.style.left = '-9999px';
26
+ div.style.top = '-9999px';
27
+ div.style.width = worldRect.width + 'px';
28
+ div.style.height = worldRect.height + 'px';
29
+ document.body.appendChild(div);
30
+ pen.calculative.canvas.externalElements?.parentElement.appendChild(div);
31
+ setElemPosition(pen, div);
32
+ pen.calculative.singleton.div = div;
33
+ const iframe = document.createElement('iframe');
34
+ iframe.style.width = '100%';
35
+ iframe.style.height = '100%';
36
+ iframe.scrolling = pen.scrolling || 'no';
37
+ iframe.frameBorder = '0';
38
+ iframe.style.border = 'none';
39
+ iframe.src = pen.iframe;
40
+ pen.calculative.iframe = pen.iframe;
41
+ div.appendChild(iframe);
42
+ generateAroundDiv(pen);
43
+ iframe.onload = () => {
44
+ iframe.setAttribute('document.domain', '');
45
+ };
46
+ }
47
+
48
+ if (pen.calculative.patchFlags) {
49
+ setElemPosition(pen, pen.calculative.singleton.div);
50
+ }
51
+ pen.onRenderPenRaw(pen);
52
+ return new Path2D();
53
+ }
54
+
55
+ function destory(pen: Pen) {
56
+ updatePointerEvents(pen);
57
+ if (pen.calculative.singleton && pen.calculative.singleton.div) {
58
+ pen.calculative.singleton.div.remove();
59
+ delete pen.calculative.singleton.div;
60
+ }
61
+ }
62
+
63
+ function move(pen: Pen) {
64
+ pen.calculative.singleton.div &&
65
+ setElemPosition(pen, pen.calculative.singleton.div);
66
+ }
67
+
68
+ function beforeValue(pen: Pen, value: any) {
69
+ if (value.iframe) {
70
+ if (pen.calculative.singleton.div) {
71
+ pen.calculative.singleton.div.children[0].src = value.iframe;
72
+ pen.calculative.iframe = value.iframe;
73
+ }
74
+ }
75
+
76
+ if (
77
+ value.operationalRect ||
78
+ value['operationalRect.x'] !== undefined ||
79
+ value['operationalRect.y'] !== undefined ||
80
+ value['operationalRect.width'] !== undefined ||
81
+ value['operationalRect.height'] !== undefined
82
+ ) {
83
+ if (!pen.operationalRect) {
84
+ pen.operationalRect = {};
85
+ }
86
+ let _value = deepClone(value);
87
+ if (!_value.operationalRect) {
88
+ _value.operationalRect = {};
89
+ }
90
+ if (_value['operationalRect.x'] !== undefined) {
91
+ _value.operationalRect.x = _value['operationalRect.x'];
92
+ }
93
+ if (_value['operationalRect.y'] !== undefined) {
94
+ _value.operationalRect.y = _value['operationalRect.y'];
95
+ }
96
+ if (_value['operationalRect.width'] !== undefined) {
97
+ _value.operationalRect.width = _value['operationalRect.width'];
98
+ }
99
+ if (_value['operationalRect.height'] !== undefined) {
100
+ _value.operationalRect.height = _value['operationalRect.height'];
101
+ }
102
+ Object.assign(pen.operationalRect, _value.operationalRect);
103
+ if (pen.calculative.singleton.div) {
104
+ let length = pen.calculative.singleton.div.children.length;
105
+ if (length === 1) {
106
+ //没有创建
107
+ generateAroundDiv(pen);
108
+ } else {
109
+ //有更新值
110
+ pen.calculative.singleton.div.children[1].style.height =
111
+ pen.operationalRect.y * 100 + '%';
112
+ pen.calculative.singleton.div.children[1].style.left =
113
+ pen.operationalRect.x * 100 + '%';
114
+ pen.calculative.singleton.div.children[1].style.width =
115
+ pen.operationalRect.width * 100 + '%';
116
+ pen.calculative.singleton.div.children[2].style.width =
117
+ (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
118
+
119
+ pen.calculative.singleton.div.children[3].style.height =
120
+ (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
121
+ pen.calculative.singleton.div.children[3].style.left =
122
+ pen.operationalRect.x * 100 + '%';
123
+ pen.calculative.singleton.div.children[3].style.width =
124
+ pen.operationalRect.width * 100 + '%';
125
+
126
+ pen.calculative.singleton.div.children[4].style.width =
127
+ pen.operationalRect.x * 100 + '%';
128
+ }
129
+ }
130
+ }
131
+ if (value.blur !== undefined) {
132
+ for (let i = 1; i < 5; i++) {
133
+ pen.calculative.singleton.div.children[i].style[
134
+ 'backdrop-filter'
135
+ ] = `blur(${value.blur || 2}px)`;
136
+ }
137
+ }
138
+ if (value.blurBackground !== undefined) {
139
+ for (let i = 1; i < 5; i++) {
140
+ pen.calculative.singleton.div.children[i].style.backgroundColor =
141
+ value.blurBackground;
142
+ }
143
+ }
144
+ return value;
145
+ }
146
+
147
+ function mouseMove(pen: Pen, e: Point) {
148
+ if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
149
+ return;
150
+ }
151
+ if (initOperationalRect(pen.operationalRect)) {
152
+ if (
153
+ pen.calculative.zIndex < 5 &&
154
+ e.x > pen.x + pen.width * pen.operationalRect.x &&
155
+ e.x <
156
+ pen.x +
157
+ pen.width * (pen.operationalRect.x + pen.operationalRect.width) &&
158
+ e.y > pen.y + pen.height * pen.operationalRect.y &&
159
+ e.y <
160
+ pen.y +
161
+ pen.height * (pen.operationalRect.y + pen.operationalRect.height)
162
+ ) {
163
+ if (pen.calculative.singleton.div) {
164
+ let children: HTMLElement[] =
165
+ pen.calculative.singleton.div.parentNode.children;
166
+ for (let i = 0; i < 6; i++) {
167
+ children[i].style.pointerEvents = 'none';
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ function initOperationalRect(operationalRect) {
175
+ if (operationalRect) {
176
+ if (!operationalRect.width || !operationalRect.height) {
177
+ return false;
178
+ }
179
+ //默认居中
180
+ if (operationalRect.x === undefined) {
181
+ operationalRect.x = (1 - operationalRect.width) / 2;
182
+ }
183
+ if (operationalRect.y === undefined) {
184
+ operationalRect.y = (1 - operationalRect.height) / 2;
185
+ }
186
+ return true;
187
+ } else {
188
+ return false;
189
+ }
190
+ }
191
+
192
+ function generateAroundDiv(pen: Pen) {
193
+ if (!initOperationalRect(pen.operationalRect)) {
194
+ return;
195
+ }
196
+ const div = pen.calculative.singleton.div;
197
+ if (!div) {
198
+ return;
199
+ }
200
+ const top = document.createElement('div');
201
+ top.style.position = 'absolute';
202
+ top.style.left = pen.operationalRect.x * 100 + '%';
203
+ top.style.top = '0px';
204
+ top.style.width = pen.operationalRect.width * 100 + '%';
205
+ top.style.height = pen.operationalRect.y * 100 + '%';
206
+ top.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
207
+ top.style.backgroundColor = pen.blurBackground;
208
+ div.appendChild(top);
209
+
210
+ const right = document.createElement('div');
211
+ right.style.position = 'absolute';
212
+ right.style.right = '0px';
213
+ right.style.top = '0px';
214
+ right.style.width =
215
+ (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
216
+ right.style.height = '100%';
217
+ right.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
218
+ right.style.backgroundColor = pen.blurBackground;
219
+ div.appendChild(right);
220
+
221
+ const bottom = document.createElement('div');
222
+ bottom.style.position = 'absolute';
223
+ bottom.style.left = pen.operationalRect.x * 100 + '%';
224
+ bottom.style.bottom = '0px';
225
+ bottom.style.width = pen.operationalRect.width * 100 + '%';
226
+ bottom.style.height =
227
+ (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
228
+ bottom.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
229
+ bottom.style.backgroundColor = pen.blurBackground;
230
+ div.appendChild(bottom);
231
+
232
+ const left = document.createElement('div');
233
+ left.style.position = 'absolute';
234
+ left.style.left = '0px';
235
+ left.style.top = '0px';
236
+ left.style.width = pen.operationalRect.x * 100 + '%';
237
+ left.style.height = '100%';
238
+ left.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
239
+ left.style.backgroundColor = pen.blurBackground;
240
+ div.appendChild(left);
241
+
242
+ let mouseEnter = () => {
243
+ updatePointerEvents(pen);
244
+ };
245
+
246
+ top.onmouseenter = mouseEnter;
247
+ bottom.onmouseenter = mouseEnter;
248
+ right.onmouseenter = mouseEnter;
249
+ left.onmouseenter = mouseEnter;
250
+ div.onmouseleave = mouseEnter;
251
+ // }
252
+ }
253
+
254
+ function updatePointerEvents(pen: Pen) {
255
+ if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
256
+ return;
257
+ }
258
+ if (pen.calculative.zIndex < 5) {
259
+ let children: any = pen.calculative.singleton.div.parentNode.children;
260
+ for (let i = 1; i < 6; i++) {
261
+ children[i].style.pointerEvents = 'initial';
262
+ }
263
+ }
264
+ }
265
+
266
+ function renderPenRaw(pen: Pen) {
267
+ if (pen.thumbImg) {
268
+ if (!pen.calculative.img) {
269
+ const img = new Image();
270
+ img.crossOrigin =
271
+ pen.crossOrigin === 'undefined'
272
+ ? undefined
273
+ : pen.crossOrigin || 'anonymous';
274
+ if (
275
+ pen.calculative.canvas.store.options.cdn &&
276
+ !(
277
+ pen.thumbImg.startsWith('http') ||
278
+ pen.thumbImg.startsWith('//') ||
279
+ pen.thumbImg.startsWith('data:image')
280
+ )
281
+ ) {
282
+ img.src = pen.calculative.canvas.store.options.cdn + pen.thumbImg;
283
+ } else {
284
+ img.src = pen.thumbImg;
285
+ }
286
+ img.onerror = (e) => {
287
+ img.remove();
288
+ pen.calculative.img = undefined;
289
+ };
290
+ pen.calculative.img = img;
291
+ }
292
+ } else {
293
+ // if (pen.calculative.singleton && pen.calculative.singleton.div) {
294
+ // try {
295
+ // // handleSaveImg(pen);
296
+ // } catch (e) {
297
+ // console.warn(e);
298
+ // pen.calculative.img = null;
299
+ // }
300
+ // }
301
+ }
302
+ }
303
+
304
+ async function handleSaveImg(pen: Pen) {
305
+ let iframeHtml = pen.calculative.singleton.div.children[0].contentWindow;
306
+ const iframeBody = iframeHtml.document.getElementsByTagName('body')[0];
307
+ const iframeScrollY = iframeHtml.document.documentElement.scrollTop;
308
+ const iframeScrollX = iframeHtml.document.documentElement.scrollLeft;
309
+ var fillContent = document.createElement('div');
310
+ // 把需要转换成图片的元素内容赋给创建的元素
311
+ fillContent.innerHTML = iframeBody.outerHTML;
312
+ document.body.appendChild(fillContent);
313
+ iframeHtml.document.domain = getRootDomain();
314
+ if (globalThis.html2canvas) {
315
+ const canvas = await globalThis.html2canvas(fillContent, {
316
+ allowTaint: true,
317
+ useCORS: true,
318
+ width: pen.width, // TODO 截屏按照1920*1080分辨率下的预览窗口宽高
319
+ height: pen.height,
320
+ x: iframeScrollX,
321
+ y: iframeScrollY,
322
+ // foreignObjectRendering: true,
323
+ });
324
+ // canvas.getContext('2d', {
325
+ // willReadFrequently: true,
326
+ // });
327
+ const img = new Image();
328
+ img.crossOrigin =
329
+ pen.crossOrigin === 'undefined'
330
+ ? undefined
331
+ : pen.crossOrigin || 'anonymous';
332
+ img.src = canvas.toDataURL('image/png', 0.1);
333
+ if (img.src.length > 10) {
334
+ pen.calculative.img = img;
335
+ }
336
+ document.body.removeChild(fillContent);
337
+ }
338
+ // globalThis.html2canvas &&
339
+ // globalThis
340
+ // .html2canvas(iframeBody, {
341
+ // allowTaint: true,
342
+ // useCORS: true,
343
+ // width: pen.width, // TODO 截屏按照1920*1080分辨率下的预览窗口宽高
344
+ // height: pen.height,
345
+ // x: iframeScrollX,
346
+ // y: iframeScrollY,
347
+ // foreignObjectRendering: true,
348
+ // })
349
+ // .then((canvas) => {
350
+ // // 转成图片,生成图片地址
351
+ // // imgBase64 = canvas.toDataURL('image/png');
352
+ // const img = new Image();
353
+ // img.crossOrigin =
354
+ // pen.crossOrigin === 'undefined'
355
+ // ? undefined
356
+ // : pen.crossOrigin || 'anonymous';
357
+ // img.src = canvas.toDataURL('image/png', 0.1);
358
+ // if (img.src.length > 10) {
359
+ // pen.calculative.img = img;
360
+ // }
361
+ // })
362
+ // .catch((e) => {
363
+ // console.warn(e);
364
+ // });
365
+ }
@@ -16,6 +16,7 @@ export * from './line';
16
16
  export * from './iframe';
17
17
  export * from './video';
18
18
  export * from './panel';
19
+
19
20
  import { rectangle, square } from './rectangle';
20
21
  import { circle } from './circle';
21
22
  import { svgPath } from './svgPath';
@@ -37,41 +38,42 @@ import { gif } from './gif';
37
38
  import { mindNode, mindNodeAnchors } from './mindNode';
38
39
  import { mindLine, mindLineAnchors } from './mindLine';
39
40
  import { panel } from './panel';
41
+
40
42
  export function commonPens() {
41
- return {
42
- rectangle: rectangle,
43
- square: square,
44
- circle: circle,
45
- svgPath: svgPath,
46
- diamond: diamond,
47
- triangle: triangle,
48
- pentagon: pentagon,
49
- pentagram: pentagram,
50
- hexagon: hexagon,
51
- leftArrow: leftArrow,
52
- rightArrow: rightArrow,
53
- twowayArrow: twowayArrow,
54
- message: message,
55
- cloud: cloud,
56
- file: file,
57
- people: people,
58
- line: line,
59
- iframe: iframe,
60
- video: video,
61
- gif: gif,
62
- mindNode: mindNode,
63
- mindLine: mindLine,
64
- mindNode2: rectangle,
65
- panel: panel
66
- };
43
+ return {
44
+ rectangle,
45
+ square,
46
+ circle,
47
+ svgPath,
48
+ diamond,
49
+ triangle,
50
+ pentagon,
51
+ pentagram,
52
+ hexagon,
53
+ leftArrow,
54
+ rightArrow,
55
+ twowayArrow,
56
+ message,
57
+ cloud,
58
+ file,
59
+ people,
60
+ line,
61
+ iframe,
62
+ video,
63
+ gif,
64
+ mindNode,
65
+ mindLine,
66
+ mindNode2:rectangle,
67
+ panel
68
+ };
67
69
  }
70
+
68
71
  export function commonAnchors() {
69
- return {
70
- triangle: triangleAnchors,
71
- pentagon: pentagonAnchors,
72
- pentagram: pentagramAnchors,
73
- mindNode: mindNodeAnchors,
74
- mindLine: mindLineAnchors,
75
- };
72
+ return {
73
+ triangle: triangleAnchors,
74
+ pentagon: pentagonAnchors,
75
+ pentagram: pentagramAnchors,
76
+ mindNode: mindNodeAnchors,
77
+ mindLine: mindLineAnchors,
78
+ };
76
79
  }
77
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,175 @@
1
+ import { Pen, LineAnimateType } from '../../pen';
2
+ import { Point } from '../../point';
3
+
4
+ //箭头动画
5
+ export function drawArrow(
6
+ pen: Pen,
7
+ ctx?: CanvasRenderingContext2D | Path2D
8
+ ): Path2D {
9
+ const path = !ctx ? new Path2D() : ctx;
10
+ const worldAnchors = pen.calculative.worldAnchors;
11
+ let scale = pen.calculative.canvas.store.data.scale;
12
+ let size = (pen.calculative.animateLineWidth || 6) * scale; // 箭头大小
13
+ let arrowLength = (pen.animateLineWidth*2 || 12) * scale; // 箭头长度
14
+ if(pen.lineAnimateType === LineAnimateType.WaterDrop){
15
+ arrowLength = (pen.animateLineWidth*4 || 24) * scale; // 水滴长度
16
+ }
17
+ let d = (pen.animateInterval || 100) * scale; // 箭头间距
18
+ let smoothLenth = pen.calculative.lineWidth *(pen.calculative.lineSmooth || 0)//*scale;
19
+ let lineWidth = (pen.calculative.animateLineWidth/2 || 3) * scale;
20
+ if (pen.animateReverse) {
21
+ //箭头反向
22
+ arrowLength = -arrowLength;
23
+ size = -size;
24
+ }
25
+ if (worldAnchors.length > 1) {
26
+ let from: Point; // 上一个点
27
+ let lastLength = 0;
28
+ for (let i = 0; i < worldAnchors.length; i++) {
29
+ let pt = worldAnchors[i];
30
+ //获取箭头角度
31
+ if (from) {
32
+ let angle = getAngle(from, pt);
33
+ let newP = {
34
+ x:
35
+ from.x +
36
+ ((pen.calculative.animatePos - lastLength) % d) *
37
+ Math.cos((angle * Math.PI) / 180),
38
+ y:
39
+ from.y -
40
+ ((pen.calculative.animatePos - lastLength) % d) *
41
+ Math.sin((angle * Math.PI) / 180),
42
+ };
43
+ if (pen.animateReverse) {
44
+ newP = {
45
+ x:
46
+ from.x +
47
+ ((pen.length - (pen.calculative.animatePos + lastLength)) % d) *
48
+ Math.cos((angle * Math.PI) / 180),
49
+ y:
50
+ from.y -
51
+ ((pen.length - (pen.calculative.animatePos + lastLength)) % d) *
52
+ Math.sin((angle * Math.PI) / 180),
53
+ };
54
+ }
55
+ let newPTFrom = Math.sqrt(
56
+ (newP.x - from.x) ** 2 + (newP.y - from.y) ** 2
57
+ );
58
+ let ptTFrom = Math.sqrt((pt.x - from.x) ** 2 + (pt.y - from.y) ** 2);
59
+ while (newPTFrom < ptTFrom) {
60
+ if (
61
+ ((pen.animateReverse && newPTFrom - arrowLength < ptTFrom) || //不允许超出连线绘制
62
+ (!pen.animateReverse &&
63
+ newPTFrom > arrowLength)) &&
64
+ newPTFrom > (smoothLenth+arrowLength) &&
65
+ ptTFrom - newPTFrom > smoothLenth
66
+ ) {
67
+ if(pen.lineAnimateType === LineAnimateType.Arrow){
68
+ arrow(path, newP, size, angle, lineWidth, arrowLength);
69
+ }else if(pen.lineAnimateType === LineAnimateType.WaterDrop){
70
+ waterDrop(path, newP, pen.animateReverse, angle, lineWidth, arrowLength);
71
+ }
72
+ }
73
+ newP.x += d * Math.cos((angle * Math.PI) / 180);
74
+ newP.y -= d * Math.sin((angle * Math.PI) / 180);
75
+ newPTFrom = Math.sqrt(
76
+ (newP.x - from.x) ** 2 + (newP.y - from.y) ** 2
77
+ );
78
+ }
79
+ // lastLength += ptTFrom-newPTFrom;
80
+ }
81
+ from = pt;
82
+ }
83
+ }
84
+ if (path instanceof Path2D) return path;
85
+ }
86
+
87
+ //获取两点连线和水平线的夹角
88
+ function getAngle(p1, p2) {
89
+ let dx = p2.x - p1.x;
90
+ let dy = p2.y - p1.y;
91
+ let angle = (Math.atan(dy / dx) * 180) / Math.PI;
92
+ if (p2.x >= p1.x) {
93
+ angle = -angle;
94
+ } else {
95
+ angle = 180 - angle;
96
+ }
97
+ return angle;
98
+ }
99
+
100
+ //获取p相对rp旋转_angle后的点坐标
101
+ function getRotatePoint(p: Point, rp: Point, _angle: number) {
102
+ let angle = ((180 - _angle) * Math.PI) / 180;
103
+ return {
104
+ x: (p.x - rp.x) * Math.cos(angle) - (p.y - rp.y) * Math.sin(angle) + rp.x,
105
+ y: (p.x - rp.x) * Math.sin(angle) + (p.y - rp.y) * Math.cos(angle) + rp.y,
106
+ };
107
+ }
108
+
109
+ //标准箭头
110
+ function arrow(path:CanvasRenderingContext2D |Path2D, newP:Point, size:number, angle:number, lineWidth:number, arrowLength:number){
111
+ let pr = getRotatePoint(
112
+ { x: newP.x + size, y: newP.y + 0.57*size },
113
+ { x: newP.x, y: newP.y },
114
+ angle
115
+ );
116
+ let pl = getRotatePoint(
117
+ { x: newP.x + size, y: newP.y - 0.57*size },
118
+ { x: newP.x, y: newP.y },
119
+ angle
120
+ );
121
+ let pr1 = getRotatePoint(
122
+ { x: newP.x + size, y: newP.y + lineWidth/2 },
123
+ { x: newP.x, y: newP.y },
124
+ angle
125
+ );
126
+ let pr2 = getRotatePoint(
127
+ { x: newP.x + arrowLength, y: newP.y + lineWidth/2},
128
+ { x: newP.x, y: newP.y },
129
+ angle
130
+ );
131
+ let pl1 = getRotatePoint(
132
+ { x: newP.x + size, y: newP.y - lineWidth/2 },
133
+ { x: newP.x, y: newP.y },
134
+ angle
135
+ );
136
+ let pl2 = getRotatePoint(
137
+ { x: newP.x + arrowLength, y: newP.y - lineWidth/2 },
138
+ { x: newP.x, y: newP.y },
139
+ angle
140
+ );
141
+ path.moveTo(pr.x, pr.y);
142
+ path.lineTo(newP.x, newP.y);
143
+ path.lineTo(pl.x, pl.y);
144
+ path.lineTo(pl1.x, pl1.y);
145
+ path.lineTo(pl2.x, pl2.y);
146
+ path.lineTo(pr2.x, pr2.y);
147
+ path.lineTo(pr1.x, pr1.y);
148
+ path.lineTo(pr.x, pr.y);
149
+ }
150
+
151
+ //水滴
152
+ function waterDrop(path:CanvasRenderingContext2D |Path2D, newP:Point, reverse:boolean, angle:number, lineWidth:number, arrowLength:number){
153
+ let dis = lineWidth/2;
154
+ if(reverse){
155
+ dis = -lineWidth/2;
156
+ }
157
+ let pl1 = getRotatePoint(
158
+ { x: newP.x, y: newP.y + dis },
159
+ { x: newP.x, y: newP.y },
160
+ angle
161
+ );
162
+ let pE = getRotatePoint(
163
+ { x: newP.x + arrowLength, y: newP.y },
164
+ { x: newP.x, y: newP.y },
165
+ angle
166
+ );
167
+ let rAngle =Math.PI/2;
168
+ if(reverse){
169
+ rAngle = -Math.PI/2;
170
+ }
171
+ path.moveTo(newP.x, newP.y);
172
+ path.arc(newP.x, newP.y, lineWidth/2, -rAngle-angle/180*Math.PI, rAngle-angle/180*Math.PI, false);
173
+ path.lineTo(pE.x, pE.y);
174
+ path.lineTo(pl1.x, pl1.y);
175
+ }