@meta2d/core 1.0.55 → 1.0.57

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 (223) hide show
  1. package/index.d.ts +9 -9
  2. package/index.js +9 -9
  3. package/package.json +38 -39
  4. package/src/canvas/canvas.d.ts +456 -456
  5. package/src/canvas/canvas.js +7583 -8186
  6. package/src/canvas/canvas.js.map +1 -1
  7. package/src/canvas/canvasImage.d.ts +27 -28
  8. package/src/canvas/canvasImage.js +440 -502
  9. package/src/canvas/canvasImage.js.map +1 -1
  10. package/src/canvas/canvasTemplate.d.ts +18 -19
  11. package/src/canvas/canvasTemplate.js +208 -228
  12. package/src/canvas/canvasTemplate.js.map +1 -1
  13. package/src/canvas/index.d.ts +2 -2
  14. package/src/canvas/index.js +2 -2
  15. package/src/canvas/magnifierCanvas.d.ts +19 -20
  16. package/src/canvas/magnifierCanvas.js +101 -100
  17. package/src/canvas/magnifierCanvas.js.map +1 -1
  18. package/src/canvas/offscreen.d.ts +1 -2
  19. package/src/canvas/offscreen.js +13 -13
  20. package/src/canvas/offscreen.js.map +1 -1
  21. package/src/core.d.ts +479 -479
  22. package/src/core.js +4589 -5198
  23. package/src/core.js.map +1 -1
  24. package/src/data.d.ts +34 -34
  25. package/src/data.js +84 -84
  26. package/src/data.js.map +1 -1
  27. package/src/diagrams/arrow.d.ts +4 -4
  28. package/src/diagrams/arrow.js +46 -46
  29. package/src/diagrams/arrow.js.map +1 -1
  30. package/src/diagrams/circle.d.ts +2 -2
  31. package/src/diagrams/circle.js +8 -8
  32. package/src/diagrams/circle.js.map +1 -1
  33. package/src/diagrams/cloud.d.ts +2 -2
  34. package/src/diagrams/cloud.js +11 -11
  35. package/src/diagrams/cloud.js.map +1 -1
  36. package/src/diagrams/cube.d.ts +2 -2
  37. package/src/diagrams/cube.js +67 -69
  38. package/src/diagrams/cube.js.map +1 -1
  39. package/src/diagrams/diamond.d.ts +2 -2
  40. package/src/diagrams/diamond.js +12 -12
  41. package/src/diagrams/diamond.js.map +1 -1
  42. package/src/diagrams/file.d.ts +2 -2
  43. package/src/diagrams/file.js +17 -17
  44. package/src/diagrams/file.js.map +1 -1
  45. package/src/diagrams/gif.d.ts +5 -5
  46. package/src/diagrams/gif.js +88 -89
  47. package/src/diagrams/gif.js.map +1 -1
  48. package/src/diagrams/hexagon.d.ts +2 -2
  49. package/src/diagrams/hexagon.js +54 -54
  50. package/src/diagrams/hexagon.js.map +1 -1
  51. package/src/diagrams/iframe.d.ts +2 -2
  52. package/src/diagrams/iframe.js +337 -355
  53. package/src/diagrams/iframe.js.map +1 -1
  54. package/src/diagrams/index.d.ts +71 -71
  55. package/src/diagrams/index.js +76 -76
  56. package/src/diagrams/index.js.map +1 -1
  57. package/src/diagrams/line/arrow.d.ts +2 -2
  58. package/src/diagrams/line/arrow.js +127 -127
  59. package/src/diagrams/line/arrow.js.map +1 -1
  60. package/src/diagrams/line/curve.d.ts +16 -16
  61. package/src/diagrams/line/curve.js +226 -235
  62. package/src/diagrams/line/curve.js.map +1 -1
  63. package/src/diagrams/line/index.d.ts +5 -5
  64. package/src/diagrams/line/index.js +5 -5
  65. package/src/diagrams/line/line.d.ts +42 -42
  66. package/src/diagrams/line/line.js +369 -430
  67. package/src/diagrams/line/line.js.map +1 -1
  68. package/src/diagrams/line/polyline.d.ts +10 -10
  69. package/src/diagrams/line/polyline.js +626 -656
  70. package/src/diagrams/line/polyline.js.map +1 -1
  71. package/src/diagrams/line/smooth.d.ts +3 -3
  72. package/src/diagrams/line/smooth.js +135 -173
  73. package/src/diagrams/line/smooth.js.map +1 -1
  74. package/src/diagrams/message.d.ts +2 -2
  75. package/src/diagrams/message.js +14 -14
  76. package/src/diagrams/message.js.map +1 -1
  77. package/src/diagrams/mindLine.d.ts +3 -3
  78. package/src/diagrams/mindLine.js +29 -30
  79. package/src/diagrams/mindLine.js.map +1 -1
  80. package/src/diagrams/mindNode.d.ts +3 -3
  81. package/src/diagrams/mindNode.js +160 -188
  82. package/src/diagrams/mindNode.js.map +1 -1
  83. package/src/diagrams/panel.d.ts +2 -2
  84. package/src/diagrams/panel.js +130 -130
  85. package/src/diagrams/panel.js.map +1 -1
  86. package/src/diagrams/pentagon.d.ts +3 -3
  87. package/src/diagrams/pentagon.js +44 -45
  88. package/src/diagrams/pentagon.js.map +1 -1
  89. package/src/diagrams/pentagram.d.ts +3 -3
  90. package/src/diagrams/pentagram.js +50 -76
  91. package/src/diagrams/pentagram.js.map +1 -1
  92. package/src/diagrams/people.d.ts +2 -2
  93. package/src/diagrams/people.js +18 -18
  94. package/src/diagrams/people.js.map +1 -1
  95. package/src/diagrams/rectangle.d.ts +3 -3
  96. package/src/diagrams/rectangle.js +25 -25
  97. package/src/diagrams/rectangle.js.map +1 -1
  98. package/src/diagrams/svg/parse.d.ts +15 -15
  99. package/src/diagrams/svg/parse.js +278 -325
  100. package/src/diagrams/svg/parse.js.map +1 -1
  101. package/src/diagrams/svgPath.d.ts +2 -2
  102. package/src/diagrams/svgPath.js +28 -29
  103. package/src/diagrams/svgPath.js.map +1 -1
  104. package/src/diagrams/triangle.d.ts +3 -3
  105. package/src/diagrams/triangle.js +39 -40
  106. package/src/diagrams/triangle.js.map +1 -1
  107. package/src/diagrams/video.d.ts +5 -5
  108. package/src/diagrams/video.js +183 -184
  109. package/src/diagrams/video.js.map +1 -1
  110. package/src/dialog/dialog.d.ts +21 -21
  111. package/src/dialog/dialog.js +156 -97
  112. package/src/dialog/dialog.js.map +1 -1
  113. package/src/dialog/index.d.ts +1 -1
  114. package/src/dialog/index.js +1 -1
  115. package/src/event/event.d.ts +102 -102
  116. package/src/event/event.js +21 -21
  117. package/src/event/index.d.ts +1 -1
  118. package/src/event/index.js +1 -1
  119. package/src/map/index.d.ts +1 -1
  120. package/src/map/index.js +1 -1
  121. package/src/map/map.d.ts +21 -21
  122. package/src/map/map.js +211 -209
  123. package/src/map/map.js.map +1 -1
  124. package/src/options.d.ts +130 -130
  125. package/src/options.js +79 -79
  126. package/src/options.js.map +1 -1
  127. package/src/pen/arrow.d.ts +4 -4
  128. package/src/pen/arrow.js +187 -187
  129. package/src/pen/arrow.js.map +1 -1
  130. package/src/pen/index.d.ts +6 -6
  131. package/src/pen/index.js +6 -6
  132. package/src/pen/math.d.ts +28 -28
  133. package/src/pen/math.js +212 -303
  134. package/src/pen/math.js.map +1 -1
  135. package/src/pen/model.d.ts +514 -514
  136. package/src/pen/model.js +209 -209
  137. package/src/pen/model.js.map +1 -1
  138. package/src/pen/plugin.d.ts +5 -5
  139. package/src/pen/plugin.js +57 -87
  140. package/src/pen/plugin.js.map +1 -1
  141. package/src/pen/render.d.ts +146 -147
  142. package/src/pen/render.js +3233 -3235
  143. package/src/pen/render.js.map +1 -1
  144. package/src/pen/text.d.ts +8 -8
  145. package/src/pen/text.js +315 -374
  146. package/src/pen/text.js.map +1 -1
  147. package/src/pen/utils.d.ts +2 -2
  148. package/src/pen/utils.js +18 -40
  149. package/src/pen/utils.js.map +1 -1
  150. package/src/point/index.d.ts +1 -1
  151. package/src/point/index.js +1 -1
  152. package/src/point/point.d.ts +65 -65
  153. package/src/point/point.js +177 -178
  154. package/src/point/point.js.map +1 -1
  155. package/src/rect/index.d.ts +1 -1
  156. package/src/rect/index.js +1 -1
  157. package/src/rect/rect.d.ts +52 -52
  158. package/src/rect/rect.js +426 -485
  159. package/src/rect/rect.js.map +1 -1
  160. package/src/rect/triangle.d.ts +2 -2
  161. package/src/rect/triangle.js +9 -9
  162. package/src/rect/triangle.js.map +1 -1
  163. package/src/scroll/index.d.ts +1 -1
  164. package/src/scroll/index.js +1 -1
  165. package/src/scroll/scroll.d.ts +35 -35
  166. package/src/scroll/scroll.js +233 -220
  167. package/src/scroll/scroll.js.map +1 -1
  168. package/src/store/global.d.ts +25 -25
  169. package/src/store/global.js +17 -17
  170. package/src/store/global.js.map +1 -1
  171. package/src/store/index.d.ts +2 -2
  172. package/src/store/index.js +2 -2
  173. package/src/store/store.d.ts +228 -228
  174. package/src/store/store.js +86 -120
  175. package/src/store/store.js.map +1 -1
  176. package/src/theme.d.ts +13 -13
  177. package/src/theme.js +22 -22
  178. package/src/theme.js.map +1 -1
  179. package/src/title/index.d.ts +1 -1
  180. package/src/title/index.js +1 -1
  181. package/src/title/title.d.ts +30 -30
  182. package/src/title/title.js +98 -98
  183. package/src/title/title.js.map +1 -1
  184. package/src/tooltip/index.d.ts +1 -1
  185. package/src/tooltip/index.js +1 -1
  186. package/src/tooltip/tooltip.d.ts +40 -40
  187. package/src/tooltip/tooltip.js +171 -166
  188. package/src/tooltip/tooltip.js.map +1 -1
  189. package/src/utils/clone.d.ts +8 -8
  190. package/src/utils/clone.js +83 -87
  191. package/src/utils/clone.js.map +1 -1
  192. package/src/utils/color.d.ts +3 -3
  193. package/src/utils/color.js +109 -125
  194. package/src/utils/color.js.map +1 -1
  195. package/src/utils/error.d.ts +2 -2
  196. package/src/utils/error.js +5 -5
  197. package/src/utils/error.js.map +1 -1
  198. package/src/utils/file.d.ts +3 -3
  199. package/src/utils/file.js +39 -91
  200. package/src/utils/file.js.map +1 -1
  201. package/src/utils/index.d.ts +9 -8
  202. package/src/utils/index.js +9 -8
  203. package/src/utils/index.js.map +1 -1
  204. package/src/utils/math.d.ts +18 -18
  205. package/src/utils/math.js +113 -151
  206. package/src/utils/math.js.map +1 -1
  207. package/src/utils/object.d.ts +2 -2
  208. package/src/utils/object.js +20 -20
  209. package/src/utils/object.js.map +1 -1
  210. package/src/utils/padding.d.ts +7 -7
  211. package/src/utils/padding.js +46 -46
  212. package/src/utils/padding.js.map +1 -1
  213. package/src/utils/time.d.ts +1 -1
  214. package/src/utils/time.js +16 -16
  215. package/src/utils/time.js.map +1 -1
  216. package/src/utils/url.d.ts +4 -4
  217. package/src/utils/url.js +26 -26
  218. package/src/utils/url.js.map +1 -1
  219. package/src/utils/uuid.d.ts +4 -4
  220. package/src/utils/uuid.js +12 -12
  221. package/src/utils/browser.d.ts +0 -1
  222. package/src/utils/browser.js +0 -4
  223. package/src/utils/browser.js.map +0 -1
@@ -1,356 +1,338 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { setElemPosition } from '../pen';
38
- import { deepClone, getRootDomain } from '../utils';
39
- export function iframe(pen) {
40
- var _a;
41
- if (!pen.onDestroy) {
42
- pen.onDestroy = destory;
43
- pen.onMove = move;
44
- pen.onResize = move;
45
- pen.onRotate = move;
46
- pen.onValue = move;
47
- pen.onMouseMove = mouseMove;
48
- pen.onBeforeValue = beforeValue;
49
- pen.onRenderPenRaw = renderPenRaw;
50
- }
51
- if (!pen.calculative.singleton) {
52
- pen.calculative.singleton = {};
53
- }
54
- var worldRect = pen.calculative.worldRect;
55
- if (!pen.calculative.singleton.div) {
56
- var div = document.createElement('div');
57
- div.style.position = 'absolute';
58
- div.style.outline = 'none';
59
- div.style.left = '-9999px';
60
- div.style.top = '-9999px';
61
- div.style.width = worldRect.width + 'px';
62
- div.style.height = worldRect.height + 'px';
63
- document.body.appendChild(div);
64
- (_a = pen.calculative.canvas.externalElements) === null || _a === void 0 ? void 0 : _a.parentElement.appendChild(div);
65
- setElemPosition(pen, div);
66
- pen.calculative.singleton.div = div;
67
- var iframe_1 = document.createElement('iframe');
68
- iframe_1.style.width = '100%';
69
- iframe_1.style.height = '100%';
70
- iframe_1.scrolling = pen.scrolling || 'no';
71
- iframe_1.frameBorder = '0';
72
- iframe_1.style.border = 'none';
73
- iframe_1.src = pen.iframe;
74
- pen.calculative.iframe = pen.iframe;
75
- div.appendChild(iframe_1);
76
- generateAroundDiv(pen);
77
- iframe_1.onload = function () {
78
- iframe_1.setAttribute('document.domain', '');
79
- };
80
- }
81
- if (pen.calculative.patchFlags) {
82
- setElemPosition(pen, pen.calculative.singleton.div);
83
- }
84
- pen.onRenderPenRaw(pen);
85
- return new Path2D();
86
- }
87
- function destory(pen) {
88
- updatePointerEvents(pen);
89
- if (pen.calculative.singleton && pen.calculative.singleton.div) {
90
- pen.calculative.singleton.div.remove();
91
- delete pen.calculative.singleton.div;
92
- }
93
- }
94
- function move(pen) {
95
- pen.calculative.singleton.div &&
96
- setElemPosition(pen, pen.calculative.singleton.div);
97
- }
98
- function beforeValue(pen, value) {
99
- if (value.iframe) {
100
- if (pen.calculative.singleton.div) {
101
- pen.calculative.singleton.div.children[0].src = value.iframe;
102
- pen.calculative.iframe = value.iframe;
103
- }
104
- }
105
- if (value.operationalRect ||
106
- value['operationalRect.x'] !== undefined ||
107
- value['operationalRect.y'] !== undefined ||
108
- value['operationalRect.width'] !== undefined ||
109
- value['operationalRect.height'] !== undefined) {
110
- if (!pen.operationalRect) {
111
- pen.operationalRect = {};
112
- }
113
- var _value = deepClone(value);
114
- if (!_value.operationalRect) {
115
- _value.operationalRect = {};
116
- }
117
- if (_value['operationalRect.x'] !== undefined) {
118
- _value.operationalRect.x = _value['operationalRect.x'];
119
- }
120
- if (_value['operationalRect.y'] !== undefined) {
121
- _value.operationalRect.y = _value['operationalRect.y'];
122
- }
123
- if (_value['operationalRect.width'] !== undefined) {
124
- _value.operationalRect.width = _value['operationalRect.width'];
125
- }
126
- if (_value['operationalRect.height'] !== undefined) {
127
- _value.operationalRect.height = _value['operationalRect.height'];
128
- }
129
- Object.assign(pen.operationalRect, _value.operationalRect);
130
- if (pen.calculative.singleton.div) {
131
- var length_1 = pen.calculative.singleton.div.children.length;
132
- if (length_1 === 1) {
133
- //没有创建
134
- generateAroundDiv(pen);
135
- }
136
- else {
137
- //有更新值
138
- pen.calculative.singleton.div.children[1].style.height =
139
- pen.operationalRect.y * 100 + '%';
140
- pen.calculative.singleton.div.children[1].style.left =
141
- pen.operationalRect.x * 100 + '%';
142
- pen.calculative.singleton.div.children[1].style.width =
143
- pen.operationalRect.width * 100 + '%';
144
- pen.calculative.singleton.div.children[2].style.width =
145
- (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
146
- pen.calculative.singleton.div.children[3].style.height =
147
- (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
148
- pen.calculative.singleton.div.children[3].style.left =
149
- pen.operationalRect.x * 100 + '%';
150
- pen.calculative.singleton.div.children[3].style.width =
151
- pen.operationalRect.width * 100 + '%';
152
- pen.calculative.singleton.div.children[4].style.width =
153
- pen.operationalRect.x * 100 + '%';
154
- }
155
- }
156
- }
157
- if (value.blur !== undefined) {
158
- for (var i = 1; i < 5; i++) {
159
- pen.calculative.singleton.div.children[i].style['backdrop-filter'] = "blur(" + (value.blur || 2) + "px)";
160
- }
161
- }
162
- if (value.blurBackground !== undefined) {
163
- for (var i = 1; i < 5; i++) {
164
- pen.calculative.singleton.div.children[i].style.backgroundColor =
165
- value.blurBackground;
166
- }
167
- }
168
- return value;
169
- }
170
- function mouseMove(pen, e) {
171
- if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
172
- return;
173
- }
174
- if (initOperationalRect(pen.operationalRect)) {
175
- if (pen.calculative.zIndex < 5 &&
176
- e.x > pen.x + pen.width * pen.operationalRect.x &&
177
- e.x <
178
- pen.x +
179
- pen.width * (pen.operationalRect.x + pen.operationalRect.width) &&
180
- e.y > pen.y + pen.height * pen.operationalRect.y &&
181
- e.y <
182
- pen.y +
183
- pen.height * (pen.operationalRect.y + pen.operationalRect.height)) {
184
- if (pen.calculative.singleton.div) {
185
- var children = pen.calculative.singleton.div.parentNode.children;
186
- for (var i = 0; i < 6; i++) {
187
- children[i].style.pointerEvents = 'none';
188
- }
189
- }
190
- }
191
- }
192
- }
193
- function initOperationalRect(operationalRect) {
194
- if (operationalRect) {
195
- if (!operationalRect.width || !operationalRect.height) {
196
- return false;
197
- }
198
- //默认居中
199
- if (operationalRect.x === undefined) {
200
- operationalRect.x = (1 - operationalRect.width) / 2;
201
- }
202
- if (operationalRect.y === undefined) {
203
- operationalRect.y = (1 - operationalRect.height) / 2;
204
- }
205
- return true;
206
- }
207
- else {
208
- return false;
209
- }
210
- }
211
- function generateAroundDiv(pen) {
212
- if (!initOperationalRect(pen.operationalRect)) {
213
- return;
214
- }
215
- var div = pen.calculative.singleton.div;
216
- if (!div) {
217
- return;
218
- }
219
- var top = document.createElement('div');
220
- top.style.position = 'absolute';
221
- top.style.left = pen.operationalRect.x * 100 + '%';
222
- top.style.top = '0px';
223
- top.style.width = pen.operationalRect.width * 100 + '%';
224
- top.style.height = pen.operationalRect.y * 100 + '%';
225
- top.style['backdrop-filter'] = "blur(" + (pen.blur || 2) + "px)";
226
- top.style.backgroundColor = pen.blurBackground;
227
- div.appendChild(top);
228
- var right = document.createElement('div');
229
- right.style.position = 'absolute';
230
- right.style.right = '0px';
231
- right.style.top = '0px';
232
- right.style.width =
233
- (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
234
- right.style.height = '100%';
235
- right.style['backdrop-filter'] = "blur(" + (pen.blur || 2) + "px)";
236
- right.style.backgroundColor = pen.blurBackground;
237
- div.appendChild(right);
238
- var bottom = document.createElement('div');
239
- bottom.style.position = 'absolute';
240
- bottom.style.left = pen.operationalRect.x * 100 + '%';
241
- bottom.style.bottom = '0px';
242
- bottom.style.width = pen.operationalRect.width * 100 + '%';
243
- bottom.style.height =
244
- (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
245
- bottom.style['backdrop-filter'] = "blur(" + (pen.blur || 2) + "px)";
246
- bottom.style.backgroundColor = pen.blurBackground;
247
- div.appendChild(bottom);
248
- var left = document.createElement('div');
249
- left.style.position = 'absolute';
250
- left.style.left = '0px';
251
- left.style.top = '0px';
252
- left.style.width = pen.operationalRect.x * 100 + '%';
253
- left.style.height = '100%';
254
- left.style['backdrop-filter'] = "blur(" + (pen.blur || 2) + "px)";
255
- left.style.backgroundColor = pen.blurBackground;
256
- div.appendChild(left);
257
- var mouseEnter = function () {
258
- updatePointerEvents(pen);
259
- };
260
- top.onmouseenter = mouseEnter;
261
- bottom.onmouseenter = mouseEnter;
262
- right.onmouseenter = mouseEnter;
263
- left.onmouseenter = mouseEnter;
264
- div.onmouseleave = mouseEnter;
265
- // }
266
- }
267
- function updatePointerEvents(pen) {
268
- if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
269
- return;
270
- }
271
- if (pen.calculative.zIndex < 5) {
272
- var children = pen.calculative.singleton.div.parentNode.children;
273
- for (var i = 1; i < 6; i++) {
274
- children[i].style.pointerEvents = 'initial';
275
- }
276
- }
277
- }
278
- function renderPenRaw(pen) {
279
- if (pen.thumbImg) {
280
- if (!pen.calculative.img) {
281
- var img_1 = new Image();
282
- img_1.crossOrigin =
283
- pen.crossOrigin === 'undefined'
284
- ? undefined
285
- : pen.crossOrigin || 'anonymous';
286
- if (pen.calculative.canvas.store.options.cdn &&
287
- !(pen.thumbImg.startsWith('http') ||
288
- pen.thumbImg.startsWith('//') ||
289
- pen.thumbImg.startsWith('data:image'))) {
290
- img_1.src = pen.calculative.canvas.store.options.cdn + pen.thumbImg;
291
- }
292
- else {
293
- img_1.src = pen.thumbImg;
294
- }
295
- img_1.onerror = function (e) {
296
- img_1.remove();
297
- pen.calculative.img = undefined;
298
- };
299
- pen.calculative.img = img_1;
300
- }
301
- }
302
- else {
303
- // if (pen.calculative.singleton && pen.calculative.singleton.div) {
304
- // try {
305
- // // handleSaveImg(pen);
306
- // } catch (e) {
307
- // console.warn(e);
308
- // pen.calculative.img = null;
309
- // }
310
- // }
311
- }
312
- }
313
- function handleSaveImg(pen) {
314
- return __awaiter(this, void 0, void 0, function () {
315
- var iframeHtml, iframeBody, iframeScrollY, iframeScrollX, fillContent, canvas, img;
316
- return __generator(this, function (_a) {
317
- switch (_a.label) {
318
- case 0:
319
- iframeHtml = pen.calculative.singleton.div.children[0].contentWindow;
320
- iframeBody = iframeHtml.document.getElementsByTagName('body')[0];
321
- iframeScrollY = iframeHtml.document.documentElement.scrollTop;
322
- iframeScrollX = iframeHtml.document.documentElement.scrollLeft;
323
- fillContent = document.createElement('div');
324
- // 把需要转换成图片的元素内容赋给创建的元素
325
- fillContent.innerHTML = iframeBody.outerHTML;
326
- document.body.appendChild(fillContent);
327
- iframeHtml.document.domain = getRootDomain();
328
- if (!globalThis.html2canvas) return [3 /*break*/, 2];
329
- return [4 /*yield*/, globalThis.html2canvas(fillContent, {
330
- allowTaint: true,
331
- useCORS: true,
332
- width: pen.width,
333
- height: pen.height,
334
- x: iframeScrollX,
335
- y: iframeScrollY,
336
- // foreignObjectRendering: true,
337
- })];
338
- case 1:
339
- canvas = _a.sent();
340
- img = new Image();
341
- img.crossOrigin =
342
- pen.crossOrigin === 'undefined'
343
- ? undefined
344
- : pen.crossOrigin || 'anonymous';
345
- img.src = canvas.toDataURL('image/png', 0.1);
346
- if (img.src.length > 10) {
347
- pen.calculative.img = img;
348
- }
349
- document.body.removeChild(fillContent);
350
- _a.label = 2;
351
- case 2: return [2 /*return*/];
352
- }
353
- });
354
- });
355
- }
1
+ import { setElemPosition } from '../pen';
2
+ import { deepClone, getRootDomain } from '../utils';
3
+ export function iframe(pen) {
4
+ if (!pen.onDestroy) {
5
+ pen.onDestroy = destory;
6
+ pen.onMove = move;
7
+ pen.onResize = move;
8
+ pen.onRotate = move;
9
+ pen.onValue = move;
10
+ pen.onMouseMove = mouseMove;
11
+ pen.onBeforeValue = beforeValue;
12
+ pen.onRenderPenRaw = renderPenRaw;
13
+ }
14
+ if (!pen.calculative.singleton) {
15
+ pen.calculative.singleton = {};
16
+ }
17
+ const worldRect = pen.calculative.worldRect;
18
+ if (!pen.calculative.singleton.div) {
19
+ const div = document.createElement('div');
20
+ div.style.position = 'absolute';
21
+ div.style.outline = 'none';
22
+ div.style.left = '-9999px';
23
+ div.style.top = '-9999px';
24
+ div.style.width = worldRect.width + 'px';
25
+ div.style.height = worldRect.height + 'px';
26
+ document.body.appendChild(div);
27
+ pen.calculative.canvas.externalElements?.parentElement.appendChild(div);
28
+ setElemPosition(pen, div);
29
+ pen.calculative.singleton.div = div;
30
+ const iframe = document.createElement('iframe');
31
+ iframe.style.width = '100%';
32
+ iframe.style.height = '100%';
33
+ iframe.scrolling = pen.scrolling || 'no';
34
+ iframe.frameBorder = '0';
35
+ iframe.style.border = 'none';
36
+ iframe.src = pen.iframe;
37
+ pen.calculative.iframe = pen.iframe;
38
+ div.appendChild(iframe);
39
+ generateAroundDiv(pen);
40
+ iframe.onload = () => {
41
+ iframe.setAttribute('document.domain', '');
42
+ };
43
+ }
44
+ if (pen.calculative.patchFlags) {
45
+ setElemPosition(pen, pen.calculative.singleton.div);
46
+ }
47
+ pen.onRenderPenRaw(pen);
48
+ return new Path2D();
49
+ }
50
+ function destory(pen) {
51
+ updatePointerEvents(pen);
52
+ if (pen.calculative.singleton && pen.calculative.singleton.div) {
53
+ pen.calculative.singleton.div.remove();
54
+ delete pen.calculative.singleton.div;
55
+ }
56
+ }
57
+ function move(pen) {
58
+ pen.calculative.singleton.div &&
59
+ setElemPosition(pen, pen.calculative.singleton.div);
60
+ }
61
+ function beforeValue(pen, value) {
62
+ if (value.iframe) {
63
+ if (pen.calculative.singleton.div) {
64
+ pen.calculative.singleton.div.children[0].src = value.iframe;
65
+ pen.calculative.iframe = value.iframe;
66
+ }
67
+ }
68
+ if (value.operationalRect ||
69
+ value['operationalRect.x'] !== undefined ||
70
+ value['operationalRect.y'] !== undefined ||
71
+ value['operationalRect.width'] !== undefined ||
72
+ value['operationalRect.height'] !== undefined) {
73
+ if (!pen.operationalRect) {
74
+ pen.operationalRect = {};
75
+ }
76
+ let _value = deepClone(value);
77
+ if (!_value.operationalRect) {
78
+ _value.operationalRect = {};
79
+ }
80
+ if (_value['operationalRect.x'] !== undefined) {
81
+ _value.operationalRect.x = _value['operationalRect.x'];
82
+ }
83
+ if (_value['operationalRect.y'] !== undefined) {
84
+ _value.operationalRect.y = _value['operationalRect.y'];
85
+ }
86
+ if (_value['operationalRect.width'] !== undefined) {
87
+ _value.operationalRect.width = _value['operationalRect.width'];
88
+ }
89
+ if (_value['operationalRect.height'] !== undefined) {
90
+ _value.operationalRect.height = _value['operationalRect.height'];
91
+ }
92
+ Object.assign(pen.operationalRect, _value.operationalRect);
93
+ if (pen.calculative.singleton.div) {
94
+ let length = pen.calculative.singleton.div.children.length;
95
+ if (length === 1) {
96
+ //没有创建
97
+ generateAroundDiv(pen);
98
+ }
99
+ else {
100
+ //有更新值
101
+ pen.calculative.singleton.div.children[1].style.height =
102
+ pen.operationalRect.y * 100 + '%';
103
+ pen.calculative.singleton.div.children[1].style.left =
104
+ pen.operationalRect.x * 100 + '%';
105
+ pen.calculative.singleton.div.children[1].style.width =
106
+ pen.operationalRect.width * 100 + '%';
107
+ pen.calculative.singleton.div.children[2].style.width =
108
+ (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
109
+ pen.calculative.singleton.div.children[3].style.height =
110
+ (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
111
+ pen.calculative.singleton.div.children[3].style.left =
112
+ pen.operationalRect.x * 100 + '%';
113
+ pen.calculative.singleton.div.children[3].style.width =
114
+ pen.operationalRect.width * 100 + '%';
115
+ pen.calculative.singleton.div.children[4].style.width =
116
+ pen.operationalRect.x * 100 + '%';
117
+ }
118
+ }
119
+ }
120
+ if (value.blur !== undefined) {
121
+ for (let i = 1; i < 5; i++) {
122
+ pen.calculative.singleton.div.children[i].style['backdrop-filter'] = `blur(${value.blur || 2}px)`;
123
+ }
124
+ }
125
+ if (value.blurBackground !== undefined) {
126
+ for (let i = 1; i < 5; i++) {
127
+ pen.calculative.singleton.div.children[i].style.backgroundColor =
128
+ value.blurBackground;
129
+ }
130
+ }
131
+ return value;
132
+ }
133
+ function mouseMove(pen, e) {
134
+ if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
135
+ return;
136
+ }
137
+ if (initOperationalRect(pen.operationalRect)) {
138
+ if (pen.calculative.zIndex < 5 &&
139
+ e.x > pen.x + pen.width * pen.operationalRect.x &&
140
+ e.x <
141
+ pen.x +
142
+ pen.width * (pen.operationalRect.x + pen.operationalRect.width) &&
143
+ e.y > pen.y + pen.height * pen.operationalRect.y &&
144
+ e.y <
145
+ pen.y +
146
+ pen.height * (pen.operationalRect.y + pen.operationalRect.height)) {
147
+ if (pen.calculative.singleton.div) {
148
+ let children = pen.calculative.singleton.div.parentNode.children;
149
+ for (let i = 0; i < 6; i++) {
150
+ children[i].style.pointerEvents = 'none';
151
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+ function initOperationalRect(operationalRect) {
157
+ if (operationalRect) {
158
+ if (!operationalRect.width || !operationalRect.height) {
159
+ return false;
160
+ }
161
+ //默认居中
162
+ if (operationalRect.x === undefined) {
163
+ operationalRect.x = (1 - operationalRect.width) / 2;
164
+ }
165
+ if (operationalRect.y === undefined) {
166
+ operationalRect.y = (1 - operationalRect.height) / 2;
167
+ }
168
+ return true;
169
+ }
170
+ else {
171
+ return false;
172
+ }
173
+ }
174
+ function generateAroundDiv(pen) {
175
+ if (!initOperationalRect(pen.operationalRect)) {
176
+ return;
177
+ }
178
+ const div = pen.calculative.singleton.div;
179
+ if (!div) {
180
+ return;
181
+ }
182
+ const top = document.createElement('div');
183
+ top.style.position = 'absolute';
184
+ top.style.left = pen.operationalRect.x * 100 + '%';
185
+ top.style.top = '0px';
186
+ top.style.width = pen.operationalRect.width * 100 + '%';
187
+ top.style.height = pen.operationalRect.y * 100 + '%';
188
+ top.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
189
+ top.style.backgroundColor = pen.blurBackground;
190
+ div.appendChild(top);
191
+ const right = document.createElement('div');
192
+ right.style.position = 'absolute';
193
+ right.style.right = '0px';
194
+ right.style.top = '0px';
195
+ right.style.width =
196
+ (1 - pen.operationalRect.x - pen.operationalRect.width) * 100 + '%';
197
+ right.style.height = '100%';
198
+ right.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
199
+ right.style.backgroundColor = pen.blurBackground;
200
+ div.appendChild(right);
201
+ const bottom = document.createElement('div');
202
+ bottom.style.position = 'absolute';
203
+ bottom.style.left = pen.operationalRect.x * 100 + '%';
204
+ bottom.style.bottom = '0px';
205
+ bottom.style.width = pen.operationalRect.width * 100 + '%';
206
+ bottom.style.height =
207
+ (1 - pen.operationalRect.y - pen.operationalRect.height) * 100 + '%';
208
+ bottom.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
209
+ bottom.style.backgroundColor = pen.blurBackground;
210
+ div.appendChild(bottom);
211
+ const left = document.createElement('div');
212
+ left.style.position = 'absolute';
213
+ left.style.left = '0px';
214
+ left.style.top = '0px';
215
+ left.style.width = pen.operationalRect.x * 100 + '%';
216
+ left.style.height = '100%';
217
+ left.style['backdrop-filter'] = `blur(${pen.blur || 2}px)`;
218
+ left.style.backgroundColor = pen.blurBackground;
219
+ div.appendChild(left);
220
+ let mouseEnter = () => {
221
+ updatePointerEvents(pen);
222
+ };
223
+ top.onmouseenter = mouseEnter;
224
+ bottom.onmouseenter = mouseEnter;
225
+ right.onmouseenter = mouseEnter;
226
+ left.onmouseenter = mouseEnter;
227
+ div.onmouseleave = mouseEnter;
228
+ // }
229
+ }
230
+ function updatePointerEvents(pen) {
231
+ if (!pen.calculative.canvas.store.data.locked && !pen.locked) {
232
+ return;
233
+ }
234
+ if (pen.calculative.zIndex < 5) {
235
+ let children = pen.calculative.singleton.div.parentNode.children;
236
+ for (let i = 1; i < 6; i++) {
237
+ children[i].style.pointerEvents = 'initial';
238
+ }
239
+ }
240
+ }
241
+ function renderPenRaw(pen) {
242
+ if (pen.thumbImg) {
243
+ if (!pen.calculative.img) {
244
+ const img = new Image();
245
+ img.crossOrigin =
246
+ pen.crossOrigin === 'undefined'
247
+ ? undefined
248
+ : pen.crossOrigin || 'anonymous';
249
+ if (pen.calculative.canvas.store.options.cdn &&
250
+ !(pen.thumbImg.startsWith('http') ||
251
+ pen.thumbImg.startsWith('//') ||
252
+ pen.thumbImg.startsWith('data:image'))) {
253
+ img.src = pen.calculative.canvas.store.options.cdn + pen.thumbImg;
254
+ }
255
+ else {
256
+ img.src = pen.thumbImg;
257
+ }
258
+ img.onerror = (e) => {
259
+ img.remove();
260
+ pen.calculative.img = undefined;
261
+ };
262
+ pen.calculative.img = img;
263
+ }
264
+ }
265
+ else {
266
+ // if (pen.calculative.singleton && pen.calculative.singleton.div) {
267
+ // try {
268
+ // // handleSaveImg(pen);
269
+ // } catch (e) {
270
+ // console.warn(e);
271
+ // pen.calculative.img = null;
272
+ // }
273
+ // }
274
+ }
275
+ }
276
+ async function handleSaveImg(pen) {
277
+ let iframeHtml = pen.calculative.singleton.div.children[0].contentWindow;
278
+ const iframeBody = iframeHtml.document.getElementsByTagName('body')[0];
279
+ const iframeScrollY = iframeHtml.document.documentElement.scrollTop;
280
+ const iframeScrollX = iframeHtml.document.documentElement.scrollLeft;
281
+ var fillContent = document.createElement('div');
282
+ // 把需要转换成图片的元素内容赋给创建的元素
283
+ fillContent.innerHTML = iframeBody.outerHTML;
284
+ document.body.appendChild(fillContent);
285
+ iframeHtml.document.domain = getRootDomain();
286
+ if (globalThis.html2canvas) {
287
+ const canvas = await globalThis.html2canvas(fillContent, {
288
+ allowTaint: true,
289
+ useCORS: true,
290
+ width: pen.width, // TODO 截屏按照1920*1080分辨率下的预览窗口宽高
291
+ height: pen.height,
292
+ x: iframeScrollX,
293
+ y: iframeScrollY,
294
+ // foreignObjectRendering: true,
295
+ });
296
+ // canvas.getContext('2d', {
297
+ // willReadFrequently: true,
298
+ // });
299
+ const img = new Image();
300
+ img.crossOrigin =
301
+ pen.crossOrigin === 'undefined'
302
+ ? undefined
303
+ : pen.crossOrigin || 'anonymous';
304
+ img.src = canvas.toDataURL('image/png', 0.1);
305
+ if (img.src.length > 10) {
306
+ pen.calculative.img = img;
307
+ }
308
+ document.body.removeChild(fillContent);
309
+ }
310
+ // globalThis.html2canvas &&
311
+ // globalThis
312
+ // .html2canvas(iframeBody, {
313
+ // allowTaint: true,
314
+ // useCORS: true,
315
+ // width: pen.width, // TODO 截屏按照1920*1080分辨率下的预览窗口宽高
316
+ // height: pen.height,
317
+ // x: iframeScrollX,
318
+ // y: iframeScrollY,
319
+ // foreignObjectRendering: true,
320
+ // })
321
+ // .then((canvas) => {
322
+ // // 转成图片,生成图片地址
323
+ // // imgBase64 = canvas.toDataURL('image/png');
324
+ // const img = new Image();
325
+ // img.crossOrigin =
326
+ // pen.crossOrigin === 'undefined'
327
+ // ? undefined
328
+ // : pen.crossOrigin || 'anonymous';
329
+ // img.src = canvas.toDataURL('image/png', 0.1);
330
+ // if (img.src.length > 10) {
331
+ // pen.calculative.img = img;
332
+ // }
333
+ // })
334
+ // .catch((e) => {
335
+ // console.warn(e);
336
+ // });
337
+ }
356
338
  //# sourceMappingURL=iframe.js.map