@meta2d/core 1.0.56 → 1.0.58

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 (299) hide show
  1. package/{index.ts → index.d.ts} +9 -9
  2. package/index.js +10 -0
  3. package/index.js.map +1 -0
  4. package/package.json +38 -39
  5. package/src/canvas/canvas.d.ts +456 -0
  6. package/src/canvas/canvas.js +7584 -0
  7. package/src/canvas/canvas.js.map +1 -0
  8. package/src/canvas/canvasImage.d.ts +27 -0
  9. package/src/canvas/canvasImage.js +441 -0
  10. package/src/canvas/canvasImage.js.map +1 -0
  11. package/src/canvas/canvasTemplate.d.ts +18 -0
  12. package/src/canvas/canvasTemplate.js +209 -0
  13. package/src/canvas/canvasTemplate.js.map +1 -0
  14. package/src/canvas/{index.ts → index.d.ts} +2 -2
  15. package/src/canvas/index.js +3 -0
  16. package/src/canvas/index.js.map +1 -0
  17. package/src/canvas/magnifierCanvas.d.ts +19 -0
  18. package/src/canvas/magnifierCanvas.js +102 -0
  19. package/src/canvas/magnifierCanvas.js.map +1 -0
  20. package/src/canvas/offscreen.d.ts +1 -0
  21. package/src/canvas/offscreen.js +14 -0
  22. package/src/canvas/offscreen.js.map +1 -0
  23. package/src/core.d.ts +479 -0
  24. package/src/core.js +4609 -0
  25. package/src/core.js.map +1 -0
  26. package/src/data.d.ts +34 -0
  27. package/src/data.js +85 -0
  28. package/src/data.js.map +1 -0
  29. package/src/diagrams/arrow.d.ts +4 -0
  30. package/src/diagrams/arrow.js +47 -0
  31. package/src/diagrams/arrow.js.map +1 -0
  32. package/src/diagrams/circle.d.ts +2 -0
  33. package/src/diagrams/circle.js +9 -0
  34. package/src/diagrams/circle.js.map +1 -0
  35. package/src/diagrams/cloud.d.ts +2 -0
  36. package/src/diagrams/cloud.js +12 -0
  37. package/src/diagrams/cloud.js.map +1 -0
  38. package/src/diagrams/cube.d.ts +2 -0
  39. package/src/diagrams/cube.js +68 -0
  40. package/src/diagrams/cube.js.map +1 -0
  41. package/src/diagrams/diamond.d.ts +2 -0
  42. package/src/diagrams/diamond.js +13 -0
  43. package/src/diagrams/diamond.js.map +1 -0
  44. package/src/diagrams/file.d.ts +2 -0
  45. package/src/diagrams/file.js +18 -0
  46. package/src/diagrams/file.js.map +1 -0
  47. package/src/diagrams/gif.d.ts +5 -0
  48. package/src/diagrams/gif.js +89 -0
  49. package/src/diagrams/gif.js.map +1 -0
  50. package/src/diagrams/hexagon.d.ts +2 -0
  51. package/src/diagrams/{hexagon.ts → hexagon.js} +55 -60
  52. package/src/diagrams/hexagon.js.map +1 -0
  53. package/src/diagrams/iframe.d.ts +2 -0
  54. package/src/diagrams/iframe.js +338 -0
  55. package/src/diagrams/iframe.js.map +1 -0
  56. package/src/diagrams/index.d.ts +71 -0
  57. package/src/diagrams/{index.ts → index.js} +77 -79
  58. package/src/diagrams/index.js.map +1 -0
  59. package/src/diagrams/line/arrow.d.ts +2 -0
  60. package/src/diagrams/line/arrow.js +128 -0
  61. package/src/diagrams/line/arrow.js.map +1 -0
  62. package/src/diagrams/line/curve.d.ts +16 -0
  63. package/src/diagrams/line/curve.js +227 -0
  64. package/src/diagrams/line/curve.js.map +1 -0
  65. package/src/diagrams/line/{index.ts → index.d.ts} +5 -5
  66. package/src/diagrams/line/index.js +6 -0
  67. package/src/diagrams/line/index.js.map +1 -0
  68. package/src/diagrams/line/line.d.ts +42 -0
  69. package/src/diagrams/line/line.js +375 -0
  70. package/src/diagrams/line/line.js.map +1 -0
  71. package/src/diagrams/line/polyline.d.ts +10 -0
  72. package/src/diagrams/line/polyline.js +627 -0
  73. package/src/diagrams/line/polyline.js.map +1 -0
  74. package/src/diagrams/line/smooth.d.ts +3 -0
  75. package/src/diagrams/line/smooth.js +136 -0
  76. package/src/diagrams/line/smooth.js.map +1 -0
  77. package/src/diagrams/message.d.ts +2 -0
  78. package/src/diagrams/message.js +15 -0
  79. package/src/diagrams/message.js.map +1 -0
  80. package/src/diagrams/mindLine.d.ts +3 -0
  81. package/src/diagrams/mindLine.js +30 -0
  82. package/src/diagrams/mindLine.js.map +1 -0
  83. package/src/diagrams/mindNode.d.ts +3 -0
  84. package/src/diagrams/mindNode.js +161 -0
  85. package/src/diagrams/mindNode.js.map +1 -0
  86. package/src/diagrams/panel.d.ts +2 -0
  87. package/src/diagrams/panel.js +131 -0
  88. package/src/diagrams/panel.js.map +1 -0
  89. package/src/diagrams/pentagon.d.ts +3 -0
  90. package/src/diagrams/pentagon.js +45 -0
  91. package/src/diagrams/pentagon.js.map +1 -0
  92. package/src/diagrams/pentagram.d.ts +3 -0
  93. package/src/diagrams/pentagram.js +51 -0
  94. package/src/diagrams/pentagram.js.map +1 -0
  95. package/src/diagrams/people.d.ts +2 -0
  96. package/src/diagrams/people.js +19 -0
  97. package/src/diagrams/people.js.map +1 -0
  98. package/src/diagrams/rectangle.d.ts +3 -0
  99. package/src/diagrams/rectangle.js +27 -0
  100. package/src/diagrams/rectangle.js.map +1 -0
  101. package/src/diagrams/svg/parse.d.ts +15 -0
  102. package/src/diagrams/svg/parse.js +279 -0
  103. package/src/diagrams/svg/parse.js.map +1 -0
  104. package/src/diagrams/svgPath.d.ts +2 -0
  105. package/src/diagrams/svgPath.js +29 -0
  106. package/src/diagrams/svgPath.js.map +1 -0
  107. package/src/diagrams/triangle.d.ts +3 -0
  108. package/src/diagrams/triangle.js +40 -0
  109. package/src/diagrams/triangle.js.map +1 -0
  110. package/src/diagrams/video.d.ts +5 -0
  111. package/src/diagrams/video.js +184 -0
  112. package/src/diagrams/video.js.map +1 -0
  113. package/src/dialog/dialog.d.ts +21 -0
  114. package/src/dialog/dialog.js +157 -0
  115. package/src/dialog/dialog.js.map +1 -0
  116. package/src/dialog/{index.ts → index.d.ts} +1 -1
  117. package/src/dialog/index.js +2 -0
  118. package/src/dialog/index.js.map +1 -0
  119. package/src/event/event.d.ts +102 -0
  120. package/src/event/event.js +22 -0
  121. package/src/event/event.js.map +1 -0
  122. package/src/event/{index.ts → index.d.ts} +1 -1
  123. package/src/event/index.js +2 -0
  124. package/src/event/index.js.map +1 -0
  125. package/src/map/{index.ts → index.d.ts} +1 -1
  126. package/src/map/index.js +2 -0
  127. package/src/map/index.js.map +1 -0
  128. package/src/map/map.d.ts +21 -0
  129. package/src/map/map.js +212 -0
  130. package/src/map/map.js.map +1 -0
  131. package/src/options.d.ts +130 -0
  132. package/src/options.js +80 -0
  133. package/src/options.js.map +1 -0
  134. package/src/pen/arrow.d.ts +4 -0
  135. package/src/pen/arrow.js +188 -0
  136. package/src/pen/arrow.js.map +1 -0
  137. package/src/pen/{index.ts → index.d.ts} +6 -6
  138. package/src/pen/index.js +7 -0
  139. package/src/pen/index.js.map +1 -0
  140. package/src/pen/math.d.ts +28 -0
  141. package/src/pen/math.js +213 -0
  142. package/src/pen/math.js.map +1 -0
  143. package/src/pen/model.d.ts +514 -0
  144. package/src/pen/model.js +210 -0
  145. package/src/pen/model.js.map +1 -0
  146. package/src/pen/plugin.d.ts +5 -0
  147. package/src/pen/plugin.js +58 -0
  148. package/src/pen/plugin.js.map +1 -0
  149. package/src/pen/render.d.ts +146 -0
  150. package/src/pen/render.js +3234 -0
  151. package/src/pen/render.js.map +1 -0
  152. package/src/pen/text.d.ts +8 -0
  153. package/src/pen/text.js +314 -0
  154. package/src/pen/text.js.map +1 -0
  155. package/src/pen/utils.d.ts +2 -0
  156. package/src/pen/utils.js +19 -0
  157. package/src/pen/utils.js.map +1 -0
  158. package/src/point/{index.ts → index.d.ts} +1 -1
  159. package/src/point/index.js +2 -0
  160. package/src/point/index.js.map +1 -0
  161. package/src/point/point.d.ts +65 -0
  162. package/src/point/point.js +178 -0
  163. package/src/point/point.js.map +1 -0
  164. package/src/rect/{index.ts → index.d.ts} +1 -1
  165. package/src/rect/index.js +2 -0
  166. package/src/rect/index.js.map +1 -0
  167. package/src/rect/rect.d.ts +52 -0
  168. package/src/rect/rect.js +427 -0
  169. package/src/rect/rect.js.map +1 -0
  170. package/src/rect/triangle.d.ts +2 -0
  171. package/src/rect/triangle.js +10 -0
  172. package/src/rect/triangle.js.map +1 -0
  173. package/src/scroll/{index.ts → index.d.ts} +1 -1
  174. package/src/scroll/index.js +2 -0
  175. package/src/scroll/index.js.map +1 -0
  176. package/src/scroll/scroll.d.ts +35 -0
  177. package/src/scroll/scroll.js +234 -0
  178. package/src/scroll/scroll.js.map +1 -0
  179. package/src/store/global.d.ts +25 -0
  180. package/src/store/global.js +18 -0
  181. package/src/store/global.js.map +1 -0
  182. package/src/store/{index.ts → index.d.ts} +2 -2
  183. package/src/store/index.js +3 -0
  184. package/src/store/index.js.map +1 -0
  185. package/src/store/store.d.ts +228 -0
  186. package/src/store/store.js +87 -0
  187. package/src/store/store.js.map +1 -0
  188. package/src/theme.d.ts +13 -0
  189. package/src/theme.js +23 -0
  190. package/src/theme.js.map +1 -0
  191. package/src/title/{index.ts → index.d.ts} +1 -1
  192. package/src/title/index.js +2 -0
  193. package/src/title/index.js.map +1 -0
  194. package/src/title/title.d.ts +30 -0
  195. package/src/title/title.js +99 -0
  196. package/src/title/title.js.map +1 -0
  197. package/src/tooltip/{index.ts → index.d.ts} +1 -1
  198. package/src/tooltip/index.js +2 -0
  199. package/src/tooltip/index.js.map +1 -0
  200. package/src/tooltip/tooltip.d.ts +40 -0
  201. package/src/tooltip/tooltip.js +172 -0
  202. package/src/tooltip/tooltip.js.map +1 -0
  203. package/src/utils/clone.d.ts +8 -0
  204. package/src/utils/clone.js +84 -0
  205. package/src/utils/clone.js.map +1 -0
  206. package/src/utils/color.d.ts +3 -0
  207. package/src/utils/color.js +110 -0
  208. package/src/utils/color.js.map +1 -0
  209. package/src/utils/error.d.ts +2 -0
  210. package/src/utils/error.js +6 -0
  211. package/src/utils/error.js.map +1 -0
  212. package/src/utils/file.d.ts +3 -0
  213. package/src/utils/file.js +40 -0
  214. package/src/utils/file.js.map +1 -0
  215. package/src/utils/{index.ts → index.d.ts} +9 -9
  216. package/src/utils/index.js +10 -0
  217. package/src/utils/index.js.map +1 -0
  218. package/src/utils/math.d.ts +18 -0
  219. package/src/utils/math.js +114 -0
  220. package/src/utils/math.js.map +1 -0
  221. package/src/utils/object.d.ts +2 -0
  222. package/src/utils/object.js +21 -0
  223. package/src/utils/object.js.map +1 -0
  224. package/src/utils/padding.d.ts +7 -0
  225. package/src/utils/padding.js +47 -0
  226. package/src/utils/padding.js.map +1 -0
  227. package/src/utils/time.d.ts +1 -0
  228. package/src/utils/time.js +17 -0
  229. package/src/utils/time.js.map +1 -0
  230. package/src/utils/url.d.ts +4 -0
  231. package/src/utils/url.js +27 -0
  232. package/src/utils/url.js.map +1 -0
  233. package/src/utils/uuid.d.ts +4 -0
  234. package/src/utils/uuid.js +13 -0
  235. package/src/utils/uuid.js.map +1 -0
  236. package/README.md +0 -13
  237. package/package.build.json +0 -39
  238. package/src/canvas/canvas.ts +0 -8639
  239. package/src/canvas/canvasImage.ts +0 -525
  240. package/src/canvas/canvasTemplate.ts +0 -257
  241. package/src/canvas/magnifierCanvas.ts +0 -142
  242. package/src/canvas/offscreen.ts +0 -14
  243. package/src/core.ts +0 -5128
  244. package/src/data.ts +0 -86
  245. package/src/diagrams/arrow.ts +0 -50
  246. package/src/diagrams/circle.ts +0 -19
  247. package/src/diagrams/cloud.ts +0 -34
  248. package/src/diagrams/cube.ts +0 -94
  249. package/src/diagrams/diamond.ts +0 -14
  250. package/src/diagrams/file.ts +0 -19
  251. package/src/diagrams/gif.ts +0 -105
  252. package/src/diagrams/iframe.ts +0 -365
  253. package/src/diagrams/line/arrow.ts +0 -175
  254. package/src/diagrams/line/curve.ts +0 -260
  255. package/src/diagrams/line/line.ts +0 -409
  256. package/src/diagrams/line/polyline.ts +0 -676
  257. package/src/diagrams/line/smooth.ts +0 -133
  258. package/src/diagrams/message.ts +0 -17
  259. package/src/diagrams/mindLine.ts +0 -31
  260. package/src/diagrams/mindNode.ts +0 -177
  261. package/src/diagrams/panel.ts +0 -149
  262. package/src/diagrams/pentagon.ts +0 -48
  263. package/src/diagrams/pentagram.ts +0 -63
  264. package/src/diagrams/people.ts +0 -23
  265. package/src/diagrams/rectangle.ts +0 -29
  266. package/src/diagrams/svg/parse.ts +0 -319
  267. package/src/diagrams/svgPath.ts +0 -53
  268. package/src/diagrams/triangle.ts +0 -43
  269. package/src/diagrams/video.ts +0 -202
  270. package/src/dialog/dialog.ts +0 -177
  271. package/src/event/event.ts +0 -142
  272. package/src/map/map.ts +0 -239
  273. package/src/options.ts +0 -205
  274. package/src/pen/arrow.ts +0 -259
  275. package/src/pen/math.ts +0 -253
  276. package/src/pen/model.ts +0 -785
  277. package/src/pen/plugin.ts +0 -57
  278. package/src/pen/render.ts +0 -3725
  279. package/src/pen/text.ts +0 -341
  280. package/src/pen/utils.ts +0 -21
  281. package/src/point/point.ts +0 -232
  282. package/src/rect/rect.ts +0 -507
  283. package/src/rect/triangle.ts +0 -16
  284. package/src/scroll/scroll.ts +0 -277
  285. package/src/store/global.ts +0 -38
  286. package/src/store/store.ts +0 -293
  287. package/src/theme.ts +0 -35
  288. package/src/title/title.ts +0 -115
  289. package/src/tooltip/tooltip.ts +0 -199
  290. package/src/utils/clone.ts +0 -79
  291. package/src/utils/color.ts +0 -126
  292. package/src/utils/error.ts +0 -7
  293. package/src/utils/file.ts +0 -46
  294. package/src/utils/math.ts +0 -120
  295. package/src/utils/object.ts +0 -23
  296. package/src/utils/padding.ts +0 -48
  297. package/src/utils/time.ts +0 -25
  298. package/src/utils/url.ts +0 -30
  299. package/src/utils/uuid.ts +0 -15
@@ -1,365 +0,0 @@
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
- }
@@ -1,175 +0,0 @@
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
- }