@realsee/dnalogel 2.0.0-alpha.33 → 2.0.0-alpha.34

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 (112) hide show
  1. package/components/index.js +1450 -0
  2. package/dist/components/PaintBrush/Controller.d.ts +43 -0
  3. package/dist/components/PaintBrush/Subscribe.d.ts +76 -0
  4. package/dist/components/PaintBrush/index.d.ts +27 -0
  5. package/dist/components/PaintBrush/style.d.ts +2 -0
  6. package/dist/components/PaintBrush/tween.d.ts +62 -0
  7. package/dist/components/PaintBrush/typings.d.ts +58 -0
  8. package/dist/components/PaintBrush/utils.d.ts +26 -0
  9. package/dist/components/index.d.ts +2 -0
  10. package/dist/shared-utils/uuid.d.ts +1 -0
  11. package/docs/classes/Magnifier.html +4 -4
  12. package/docs/classes/ModelRoomLabelController.html +4 -4
  13. package/docs/classes/PanoFloorplanRadarPluginController.html +2 -2
  14. package/docs/enums/CameraMovementEffect.html +2 -2
  15. package/docs/enums/DIRECTION.html +1 -1
  16. package/docs/enums/DISPLAY_STRATEGY_TYPE.html +1 -1
  17. package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
  18. package/docs/enums/ITEM_LABEL_PLUGIN_DISPLAY_STRATEGY_TYPE.html +1 -1
  19. package/docs/enums/ModelFloorplanErrorType.html +1 -1
  20. package/docs/enums/Rotation.html +2 -2
  21. package/docs/index.html +1 -1
  22. package/docs/interfaces/CSS3DRenderPluginExportType.html +2 -2
  23. package/docs/interfaces/CameraMovementPluginExportType.html +2 -2
  24. package/docs/interfaces/FloorplanBounding.html +4 -4
  25. package/docs/interfaces/FloorplanData.html +2 -2
  26. package/docs/interfaces/FloorplanEntrance.html +7 -7
  27. package/docs/interfaces/FloorplanExtraObject.html +3 -3
  28. package/docs/interfaces/FloorplanExtraObject3D.html +2 -2
  29. package/docs/interfaces/FloorplanFloorData.html +2 -2
  30. package/docs/interfaces/FloorplanImagePosition.html +2 -2
  31. package/docs/interfaces/FloorplanObserver.html +2 -2
  32. package/docs/interfaces/FloorplanOutlineItem.html +2 -2
  33. package/docs/interfaces/FloorplanPosition.html +2 -2
  34. package/docs/interfaces/FloorplanRoomItem.html +6 -6
  35. package/docs/interfaces/FloorplanRoomLabelItem.html +3 -3
  36. package/docs/interfaces/FloorplanServerBounding.html +4 -4
  37. package/docs/interfaces/FloorplanServerComputedData.html +1 -1
  38. package/docs/interfaces/FloorplanServerData.html +2 -2
  39. package/docs/interfaces/FloorplanServerEntrance.html +7 -7
  40. package/docs/interfaces/FloorplanServerFloorData.html +2 -2
  41. package/docs/interfaces/FloorplanServerImagePosition.html +2 -2
  42. package/docs/interfaces/FloorplanServerObserver.html +2 -2
  43. package/docs/interfaces/FloorplanServerOutlineItem.html +2 -2
  44. package/docs/interfaces/FloorplanServerPosition.html +2 -2
  45. package/docs/interfaces/FloorplanServerRoomItem.html +7 -7
  46. package/docs/interfaces/FloorplanServerRoomLabelItem.html +3 -3
  47. package/docs/interfaces/ItemLabelPluginData.html +1 -1
  48. package/docs/interfaces/ItemLabelPluginExportReturnsType.html +1 -1
  49. package/docs/interfaces/ItemLabelPluginParametersType.html +1 -1
  50. package/docs/interfaces/LineJson.html +1 -1
  51. package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
  52. package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
  53. package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
  54. package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
  55. package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
  56. package/docs/interfaces/ModelFloorplanParameterType.html +1 -1
  57. package/docs/interfaces/ModelFloorplanViewEvent.html +2 -2
  58. package/docs/interfaces/ModelItemLabelPluginData.html +1 -1
  59. package/docs/interfaces/ModelItemLabelPluginExportReturnsType.html +1 -1
  60. package/docs/interfaces/ModelItemLabelPluginParametersType.html +1 -1
  61. package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
  62. package/docs/interfaces/ModelTVVideoPluginData.html +1 -1
  63. package/docs/interfaces/ModelTVVideoPluginExportType.html +1 -1
  64. package/docs/interfaces/ModelTVVideoPluginParameterType.html +1 -1
  65. package/docs/interfaces/ModelViewPluginExportType.html +1 -1
  66. package/docs/interfaces/OpenParameter.html +2 -2
  67. package/docs/interfaces/PanoCompassPluginData.html +1 -1
  68. package/docs/interfaces/PanoCompassPluginParameterType.html +1 -1
  69. package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
  70. package/docs/interfaces/PanoCursorRaycasterPluginParameterType.html +1 -1
  71. package/docs/interfaces/PanoFloorplanRadarPluginControllerParameter.html +1 -1
  72. package/docs/interfaces/PanoMeasureParameterType.html +1 -1
  73. package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
  74. package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
  75. package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
  76. package/docs/interfaces/PanoSpatialTagPluginContentEvent.html +1 -1
  77. package/docs/interfaces/PanoSpatialTagPluginContentReplacement.html +1 -1
  78. package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
  79. package/docs/interfaces/PanoSpatialTagPluginDataElement.html +1 -1
  80. package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
  81. package/docs/interfaces/PanoSpatialTagPluginOriginElement.html +1 -1
  82. package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
  83. package/docs/interfaces/PanoSpatialTagPluginPointElement.html +1 -1
  84. package/docs/interfaces/PanoSpatialTagPluginTagElement.html +1 -1
  85. package/docs/interfaces/Point.html +1 -1
  86. package/docs/interfaces/PointJson.html +1 -1
  87. package/docs/interfaces/Room.html +1 -1
  88. package/docs/interfaces/RoomInfo.html +1 -1
  89. package/docs/interfaces/RoomLabel.html +7 -7
  90. package/docs/interfaces/RoomRules.html +1 -1
  91. package/docs/interfaces/Rooms.html +1 -1
  92. package/docs/interfaces/TopviewFloorplanPluginParameterType.html +9 -9
  93. package/docs/modules.html +20 -20
  94. package/libs/components/PaintBrush/Controller.d.ts +43 -0
  95. package/libs/components/PaintBrush/Controller.js +575 -0
  96. package/libs/components/PaintBrush/Subscribe.d.ts +76 -0
  97. package/libs/components/PaintBrush/Subscribe.js +121 -0
  98. package/libs/components/PaintBrush/index.d.ts +27 -0
  99. package/libs/components/PaintBrush/index.js +57 -0
  100. package/libs/components/PaintBrush/style.d.ts +2 -0
  101. package/libs/components/PaintBrush/style.js +102 -0
  102. package/libs/components/PaintBrush/tween.d.ts +62 -0
  103. package/libs/components/PaintBrush/tween.js +15 -0
  104. package/libs/components/PaintBrush/typings.d.ts +58 -0
  105. package/libs/components/PaintBrush/typings.js +6 -0
  106. package/libs/components/PaintBrush/utils.d.ts +26 -0
  107. package/libs/components/PaintBrush/utils.js +51 -0
  108. package/libs/components/index.d.ts +2 -0
  109. package/libs/components/index.js +3 -0
  110. package/libs/shared-utils/uuid.d.ts +1 -0
  111. package/libs/shared-utils/uuid.js +1 -0
  112. package/package.json +4 -2
@@ -0,0 +1,1450 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ function noop() {
8
+ }
9
+ const promise = () => Promise.resolve();
10
+ const state = {
11
+ __queue: Promise.resolve()
12
+ };
13
+ function queue(promiseCallback = promise) {
14
+ state.__queue = state.__queue.then(promiseCallback).catch(promise);
15
+ }
16
+ function transformCoords(coords, cw, ch) {
17
+ const _x = coords.x;
18
+ const _y = coords.y;
19
+ const x = Math.floor(_x / cw * 1e4) / 1e4;
20
+ const y = Math.floor(_y / ch * 1e4) / 1e4;
21
+ return { x, y };
22
+ }
23
+ function unTransformCoords(coords, cw, ch) {
24
+ const { x: _x, y: _y } = coords;
25
+ const x = _x * cw;
26
+ const y = _y * ch;
27
+ return { x, y };
28
+ }
29
+ function getQuadraticCurvePoint(points) {
30
+ if (points.length < 2)
31
+ return {};
32
+ const lastTwo = points.slice(-2);
33
+ const control = lastTwo[0];
34
+ const end = {
35
+ x: (lastTwo[0].x + lastTwo[1].x) / 2,
36
+ y: (lastTwo[0].y + lastTwo[1].y) / 2
37
+ };
38
+ return { control, end };
39
+ }
40
+ function execInterval(i, time, callback = noop) {
41
+ new Promise((resolve) => {
42
+ setTimeout(() => {
43
+ callback();
44
+ resolve(true);
45
+ }, time * i);
46
+ });
47
+ }
48
+ const _window = window;
49
+ const _requestAnimationFrame = window.requestAnimationFrame || _window.webkitRequestAnimationFrame || ((fn) => setTimeout(fn, 16));
50
+ function nextFrame(fn, delay = 0) {
51
+ if (delay <= 0)
52
+ _requestAnimationFrame(fn);
53
+ else
54
+ _requestAnimationFrame(() => nextFrame(fn, delay - 1));
55
+ }
56
+ var Easing$1 = {
57
+ Linear: {
58
+ None: function(amount) {
59
+ return amount;
60
+ }
61
+ },
62
+ Quadratic: {
63
+ In: function(amount) {
64
+ return amount * amount;
65
+ },
66
+ Out: function(amount) {
67
+ return amount * (2 - amount);
68
+ },
69
+ InOut: function(amount) {
70
+ if ((amount *= 2) < 1) {
71
+ return 0.5 * amount * amount;
72
+ }
73
+ return -0.5 * (--amount * (amount - 2) - 1);
74
+ }
75
+ },
76
+ Cubic: {
77
+ In: function(amount) {
78
+ return amount * amount * amount;
79
+ },
80
+ Out: function(amount) {
81
+ return --amount * amount * amount + 1;
82
+ },
83
+ InOut: function(amount) {
84
+ if ((amount *= 2) < 1) {
85
+ return 0.5 * amount * amount * amount;
86
+ }
87
+ return 0.5 * ((amount -= 2) * amount * amount + 2);
88
+ }
89
+ },
90
+ Quartic: {
91
+ In: function(amount) {
92
+ return amount * amount * amount * amount;
93
+ },
94
+ Out: function(amount) {
95
+ return 1 - --amount * amount * amount * amount;
96
+ },
97
+ InOut: function(amount) {
98
+ if ((amount *= 2) < 1) {
99
+ return 0.5 * amount * amount * amount * amount;
100
+ }
101
+ return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
102
+ }
103
+ },
104
+ Quintic: {
105
+ In: function(amount) {
106
+ return amount * amount * amount * amount * amount;
107
+ },
108
+ Out: function(amount) {
109
+ return --amount * amount * amount * amount * amount + 1;
110
+ },
111
+ InOut: function(amount) {
112
+ if ((amount *= 2) < 1) {
113
+ return 0.5 * amount * amount * amount * amount * amount;
114
+ }
115
+ return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
116
+ }
117
+ },
118
+ Sinusoidal: {
119
+ In: function(amount) {
120
+ return 1 - Math.cos(amount * Math.PI / 2);
121
+ },
122
+ Out: function(amount) {
123
+ return Math.sin(amount * Math.PI / 2);
124
+ },
125
+ InOut: function(amount) {
126
+ return 0.5 * (1 - Math.cos(Math.PI * amount));
127
+ }
128
+ },
129
+ Exponential: {
130
+ In: function(amount) {
131
+ return amount === 0 ? 0 : Math.pow(1024, amount - 1);
132
+ },
133
+ Out: function(amount) {
134
+ return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
135
+ },
136
+ InOut: function(amount) {
137
+ if (amount === 0) {
138
+ return 0;
139
+ }
140
+ if (amount === 1) {
141
+ return 1;
142
+ }
143
+ if ((amount *= 2) < 1) {
144
+ return 0.5 * Math.pow(1024, amount - 1);
145
+ }
146
+ return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
147
+ }
148
+ },
149
+ Circular: {
150
+ In: function(amount) {
151
+ return 1 - Math.sqrt(1 - amount * amount);
152
+ },
153
+ Out: function(amount) {
154
+ return Math.sqrt(1 - --amount * amount);
155
+ },
156
+ InOut: function(amount) {
157
+ if ((amount *= 2) < 1) {
158
+ return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
159
+ }
160
+ return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
161
+ }
162
+ },
163
+ Elastic: {
164
+ In: function(amount) {
165
+ if (amount === 0) {
166
+ return 0;
167
+ }
168
+ if (amount === 1) {
169
+ return 1;
170
+ }
171
+ return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
172
+ },
173
+ Out: function(amount) {
174
+ if (amount === 0) {
175
+ return 0;
176
+ }
177
+ if (amount === 1) {
178
+ return 1;
179
+ }
180
+ return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
181
+ },
182
+ InOut: function(amount) {
183
+ if (amount === 0) {
184
+ return 0;
185
+ }
186
+ if (amount === 1) {
187
+ return 1;
188
+ }
189
+ amount *= 2;
190
+ if (amount < 1) {
191
+ return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
192
+ }
193
+ return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
194
+ }
195
+ },
196
+ Back: {
197
+ In: function(amount) {
198
+ var s = 1.70158;
199
+ return amount * amount * ((s + 1) * amount - s);
200
+ },
201
+ Out: function(amount) {
202
+ var s = 1.70158;
203
+ return --amount * amount * ((s + 1) * amount + s) + 1;
204
+ },
205
+ InOut: function(amount) {
206
+ var s = 1.70158 * 1.525;
207
+ if ((amount *= 2) < 1) {
208
+ return 0.5 * (amount * amount * ((s + 1) * amount - s));
209
+ }
210
+ return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
211
+ }
212
+ },
213
+ Bounce: {
214
+ In: function(amount) {
215
+ return 1 - Easing$1.Bounce.Out(1 - amount);
216
+ },
217
+ Out: function(amount) {
218
+ if (amount < 1 / 2.75) {
219
+ return 7.5625 * amount * amount;
220
+ } else if (amount < 2 / 2.75) {
221
+ return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
222
+ } else if (amount < 2.5 / 2.75) {
223
+ return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
224
+ } else {
225
+ return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
226
+ }
227
+ },
228
+ InOut: function(amount) {
229
+ if (amount < 0.5) {
230
+ return Easing$1.Bounce.In(amount * 2) * 0.5;
231
+ }
232
+ return Easing$1.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
233
+ }
234
+ }
235
+ };
236
+ var now;
237
+ if (typeof self === "undefined" && typeof process !== "undefined" && process.hrtime) {
238
+ now = function() {
239
+ var time = process.hrtime();
240
+ return time[0] * 1e3 + time[1] / 1e6;
241
+ };
242
+ } else if (typeof self !== "undefined" && self.performance !== void 0 && self.performance.now !== void 0) {
243
+ now = self.performance.now.bind(self.performance);
244
+ } else if (Date.now !== void 0) {
245
+ now = Date.now;
246
+ } else {
247
+ now = function() {
248
+ return new Date().getTime();
249
+ };
250
+ }
251
+ var now$1 = now;
252
+ var Group = function() {
253
+ function Group2() {
254
+ this._tweens = {};
255
+ this._tweensAddedDuringUpdate = {};
256
+ }
257
+ Group2.prototype.getAll = function() {
258
+ var _this = this;
259
+ return Object.keys(this._tweens).map(function(tweenId) {
260
+ return _this._tweens[tweenId];
261
+ });
262
+ };
263
+ Group2.prototype.removeAll = function() {
264
+ this._tweens = {};
265
+ };
266
+ Group2.prototype.add = function(tween2) {
267
+ this._tweens[tween2.getId()] = tween2;
268
+ this._tweensAddedDuringUpdate[tween2.getId()] = tween2;
269
+ };
270
+ Group2.prototype.remove = function(tween2) {
271
+ delete this._tweens[tween2.getId()];
272
+ delete this._tweensAddedDuringUpdate[tween2.getId()];
273
+ };
274
+ Group2.prototype.update = function(time, preserve) {
275
+ if (time === void 0) {
276
+ time = now$1();
277
+ }
278
+ if (preserve === void 0) {
279
+ preserve = false;
280
+ }
281
+ var tweenIds = Object.keys(this._tweens);
282
+ if (tweenIds.length === 0) {
283
+ return false;
284
+ }
285
+ while (tweenIds.length > 0) {
286
+ this._tweensAddedDuringUpdate = {};
287
+ for (var i = 0; i < tweenIds.length; i++) {
288
+ var tween2 = this._tweens[tweenIds[i]];
289
+ var autoStart = !preserve;
290
+ if (tween2 && tween2.update(time, autoStart) === false && !preserve) {
291
+ delete this._tweens[tweenIds[i]];
292
+ }
293
+ }
294
+ tweenIds = Object.keys(this._tweensAddedDuringUpdate);
295
+ }
296
+ return true;
297
+ };
298
+ return Group2;
299
+ }();
300
+ var Interpolation = {
301
+ Linear: function(v, k) {
302
+ var m = v.length - 1;
303
+ var f = m * k;
304
+ var i = Math.floor(f);
305
+ var fn = Interpolation.Utils.Linear;
306
+ if (k < 0) {
307
+ return fn(v[0], v[1], f);
308
+ }
309
+ if (k > 1) {
310
+ return fn(v[m], v[m - 1], m - f);
311
+ }
312
+ return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
313
+ },
314
+ Bezier: function(v, k) {
315
+ var b = 0;
316
+ var n = v.length - 1;
317
+ var pw = Math.pow;
318
+ var bn = Interpolation.Utils.Bernstein;
319
+ for (var i = 0; i <= n; i++) {
320
+ b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
321
+ }
322
+ return b;
323
+ },
324
+ CatmullRom: function(v, k) {
325
+ var m = v.length - 1;
326
+ var f = m * k;
327
+ var i = Math.floor(f);
328
+ var fn = Interpolation.Utils.CatmullRom;
329
+ if (v[0] === v[m]) {
330
+ if (k < 0) {
331
+ i = Math.floor(f = m * (1 + k));
332
+ }
333
+ return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
334
+ } else {
335
+ if (k < 0) {
336
+ return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
337
+ }
338
+ if (k > 1) {
339
+ return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
340
+ }
341
+ return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
342
+ }
343
+ },
344
+ Utils: {
345
+ Linear: function(p0, p1, t) {
346
+ return (p1 - p0) * t + p0;
347
+ },
348
+ Bernstein: function(n, i) {
349
+ var fc = Interpolation.Utils.Factorial;
350
+ return fc(n) / fc(i) / fc(n - i);
351
+ },
352
+ Factorial: function() {
353
+ var a = [1];
354
+ return function(n) {
355
+ var s = 1;
356
+ if (a[n]) {
357
+ return a[n];
358
+ }
359
+ for (var i = n; i > 1; i--) {
360
+ s *= i;
361
+ }
362
+ a[n] = s;
363
+ return s;
364
+ };
365
+ }(),
366
+ CatmullRom: function(p0, p1, p2, p3, t) {
367
+ var v0 = (p2 - p0) * 0.5;
368
+ var v1 = (p3 - p1) * 0.5;
369
+ var t2 = t * t;
370
+ var t3 = t * t2;
371
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
372
+ }
373
+ }
374
+ };
375
+ var Sequence = function() {
376
+ function Sequence2() {
377
+ }
378
+ Sequence2.nextId = function() {
379
+ return Sequence2._nextId++;
380
+ };
381
+ Sequence2._nextId = 0;
382
+ return Sequence2;
383
+ }();
384
+ var mainGroup = new Group();
385
+ var Tween = function() {
386
+ function Tween2(_object, _group) {
387
+ if (_group === void 0) {
388
+ _group = mainGroup;
389
+ }
390
+ this._object = _object;
391
+ this._group = _group;
392
+ this._isPaused = false;
393
+ this._pauseStart = 0;
394
+ this._valuesStart = {};
395
+ this._valuesEnd = {};
396
+ this._valuesStartRepeat = {};
397
+ this._duration = 1e3;
398
+ this._initialRepeat = 0;
399
+ this._repeat = 0;
400
+ this._yoyo = false;
401
+ this._isPlaying = false;
402
+ this._reversed = false;
403
+ this._delayTime = 0;
404
+ this._startTime = 0;
405
+ this._easingFunction = Easing$1.Linear.None;
406
+ this._interpolationFunction = Interpolation.Linear;
407
+ this._chainedTweens = [];
408
+ this._onStartCallbackFired = false;
409
+ this._id = Sequence.nextId();
410
+ this._isChainStopped = false;
411
+ this._goToEnd = false;
412
+ }
413
+ Tween2.prototype.getId = function() {
414
+ return this._id;
415
+ };
416
+ Tween2.prototype.isPlaying = function() {
417
+ return this._isPlaying;
418
+ };
419
+ Tween2.prototype.isPaused = function() {
420
+ return this._isPaused;
421
+ };
422
+ Tween2.prototype.to = function(properties, duration) {
423
+ this._valuesEnd = Object.create(properties);
424
+ if (duration !== void 0) {
425
+ this._duration = duration;
426
+ }
427
+ return this;
428
+ };
429
+ Tween2.prototype.duration = function(d) {
430
+ this._duration = d;
431
+ return this;
432
+ };
433
+ Tween2.prototype.start = function(time) {
434
+ if (this._isPlaying) {
435
+ return this;
436
+ }
437
+ this._group && this._group.add(this);
438
+ this._repeat = this._initialRepeat;
439
+ if (this._reversed) {
440
+ this._reversed = false;
441
+ for (var property in this._valuesStartRepeat) {
442
+ this._swapEndStartRepeatValues(property);
443
+ this._valuesStart[property] = this._valuesStartRepeat[property];
444
+ }
445
+ }
446
+ this._isPlaying = true;
447
+ this._isPaused = false;
448
+ this._onStartCallbackFired = false;
449
+ this._isChainStopped = false;
450
+ this._startTime = time !== void 0 ? typeof time === "string" ? now$1() + parseFloat(time) : time : now$1();
451
+ this._startTime += this._delayTime;
452
+ this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
453
+ return this;
454
+ };
455
+ Tween2.prototype._setupProperties = function(_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
456
+ for (var property in _valuesEnd) {
457
+ var startValue = _object[property];
458
+ var startValueIsArray = Array.isArray(startValue);
459
+ var propType = startValueIsArray ? "array" : typeof startValue;
460
+ var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
461
+ if (propType === "undefined" || propType === "function") {
462
+ continue;
463
+ }
464
+ if (isInterpolationList) {
465
+ var endValues = _valuesEnd[property];
466
+ if (endValues.length === 0) {
467
+ continue;
468
+ }
469
+ endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
470
+ _valuesEnd[property] = [startValue].concat(endValues);
471
+ }
472
+ if ((propType === "object" || startValueIsArray) && startValue && !isInterpolationList) {
473
+ _valuesStart[property] = startValueIsArray ? [] : {};
474
+ for (var prop in startValue) {
475
+ _valuesStart[property][prop] = startValue[prop];
476
+ }
477
+ _valuesStartRepeat[property] = startValueIsArray ? [] : {};
478
+ this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
479
+ } else {
480
+ if (typeof _valuesStart[property] === "undefined") {
481
+ _valuesStart[property] = startValue;
482
+ }
483
+ if (!startValueIsArray) {
484
+ _valuesStart[property] *= 1;
485
+ }
486
+ if (isInterpolationList) {
487
+ _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
488
+ } else {
489
+ _valuesStartRepeat[property] = _valuesStart[property] || 0;
490
+ }
491
+ }
492
+ }
493
+ };
494
+ Tween2.prototype.stop = function() {
495
+ if (!this._isChainStopped) {
496
+ this._isChainStopped = true;
497
+ this.stopChainedTweens();
498
+ }
499
+ if (!this._isPlaying) {
500
+ return this;
501
+ }
502
+ this._group && this._group.remove(this);
503
+ this._isPlaying = false;
504
+ this._isPaused = false;
505
+ if (this._onStopCallback) {
506
+ this._onStopCallback(this._object);
507
+ }
508
+ return this;
509
+ };
510
+ Tween2.prototype.end = function() {
511
+ this._goToEnd = true;
512
+ this.update(Infinity);
513
+ return this;
514
+ };
515
+ Tween2.prototype.pause = function(time) {
516
+ if (time === void 0) {
517
+ time = now$1();
518
+ }
519
+ if (this._isPaused || !this._isPlaying) {
520
+ return this;
521
+ }
522
+ this._isPaused = true;
523
+ this._pauseStart = time;
524
+ this._group && this._group.remove(this);
525
+ return this;
526
+ };
527
+ Tween2.prototype.resume = function(time) {
528
+ if (time === void 0) {
529
+ time = now$1();
530
+ }
531
+ if (!this._isPaused || !this._isPlaying) {
532
+ return this;
533
+ }
534
+ this._isPaused = false;
535
+ this._startTime += time - this._pauseStart;
536
+ this._pauseStart = 0;
537
+ this._group && this._group.add(this);
538
+ return this;
539
+ };
540
+ Tween2.prototype.stopChainedTweens = function() {
541
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
542
+ this._chainedTweens[i].stop();
543
+ }
544
+ return this;
545
+ };
546
+ Tween2.prototype.group = function(group) {
547
+ this._group = group;
548
+ return this;
549
+ };
550
+ Tween2.prototype.delay = function(amount) {
551
+ this._delayTime = amount;
552
+ return this;
553
+ };
554
+ Tween2.prototype.repeat = function(times) {
555
+ this._initialRepeat = times;
556
+ this._repeat = times;
557
+ return this;
558
+ };
559
+ Tween2.prototype.repeatDelay = function(amount) {
560
+ this._repeatDelayTime = amount;
561
+ return this;
562
+ };
563
+ Tween2.prototype.yoyo = function(yoyo) {
564
+ this._yoyo = yoyo;
565
+ return this;
566
+ };
567
+ Tween2.prototype.easing = function(easingFunction) {
568
+ this._easingFunction = easingFunction;
569
+ return this;
570
+ };
571
+ Tween2.prototype.interpolation = function(interpolationFunction) {
572
+ this._interpolationFunction = interpolationFunction;
573
+ return this;
574
+ };
575
+ Tween2.prototype.chain = function() {
576
+ var tweens = [];
577
+ for (var _i = 0; _i < arguments.length; _i++) {
578
+ tweens[_i] = arguments[_i];
579
+ }
580
+ this._chainedTweens = tweens;
581
+ return this;
582
+ };
583
+ Tween2.prototype.onStart = function(callback) {
584
+ this._onStartCallback = callback;
585
+ return this;
586
+ };
587
+ Tween2.prototype.onUpdate = function(callback) {
588
+ this._onUpdateCallback = callback;
589
+ return this;
590
+ };
591
+ Tween2.prototype.onRepeat = function(callback) {
592
+ this._onRepeatCallback = callback;
593
+ return this;
594
+ };
595
+ Tween2.prototype.onComplete = function(callback) {
596
+ this._onCompleteCallback = callback;
597
+ return this;
598
+ };
599
+ Tween2.prototype.onStop = function(callback) {
600
+ this._onStopCallback = callback;
601
+ return this;
602
+ };
603
+ Tween2.prototype.update = function(time, autoStart) {
604
+ if (time === void 0) {
605
+ time = now$1();
606
+ }
607
+ if (autoStart === void 0) {
608
+ autoStart = true;
609
+ }
610
+ if (this._isPaused)
611
+ return true;
612
+ var property;
613
+ var elapsed;
614
+ var endTime = this._startTime + this._duration;
615
+ if (!this._goToEnd && !this._isPlaying) {
616
+ if (time > endTime)
617
+ return false;
618
+ if (autoStart)
619
+ this.start(time);
620
+ }
621
+ this._goToEnd = false;
622
+ if (time < this._startTime) {
623
+ return true;
624
+ }
625
+ if (this._onStartCallbackFired === false) {
626
+ if (this._onStartCallback) {
627
+ this._onStartCallback(this._object);
628
+ }
629
+ this._onStartCallbackFired = true;
630
+ }
631
+ elapsed = (time - this._startTime) / this._duration;
632
+ elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
633
+ var value = this._easingFunction(elapsed);
634
+ this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
635
+ if (this._onUpdateCallback) {
636
+ this._onUpdateCallback(this._object, elapsed);
637
+ }
638
+ if (elapsed === 1) {
639
+ if (this._repeat > 0) {
640
+ if (isFinite(this._repeat)) {
641
+ this._repeat--;
642
+ }
643
+ for (property in this._valuesStartRepeat) {
644
+ if (!this._yoyo && typeof this._valuesEnd[property] === "string") {
645
+ this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
646
+ }
647
+ if (this._yoyo) {
648
+ this._swapEndStartRepeatValues(property);
649
+ }
650
+ this._valuesStart[property] = this._valuesStartRepeat[property];
651
+ }
652
+ if (this._yoyo) {
653
+ this._reversed = !this._reversed;
654
+ }
655
+ if (this._repeatDelayTime !== void 0) {
656
+ this._startTime = time + this._repeatDelayTime;
657
+ } else {
658
+ this._startTime = time + this._delayTime;
659
+ }
660
+ if (this._onRepeatCallback) {
661
+ this._onRepeatCallback(this._object);
662
+ }
663
+ return true;
664
+ } else {
665
+ if (this._onCompleteCallback) {
666
+ this._onCompleteCallback(this._object);
667
+ }
668
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
669
+ this._chainedTweens[i].start(this._startTime + this._duration);
670
+ }
671
+ this._isPlaying = false;
672
+ return false;
673
+ }
674
+ }
675
+ return true;
676
+ };
677
+ Tween2.prototype._updateProperties = function(_object, _valuesStart, _valuesEnd, value) {
678
+ for (var property in _valuesEnd) {
679
+ if (_valuesStart[property] === void 0) {
680
+ continue;
681
+ }
682
+ var start = _valuesStart[property] || 0;
683
+ var end = _valuesEnd[property];
684
+ var startIsArray = Array.isArray(_object[property]);
685
+ var endIsArray = Array.isArray(end);
686
+ var isInterpolationList = !startIsArray && endIsArray;
687
+ if (isInterpolationList) {
688
+ _object[property] = this._interpolationFunction(end, value);
689
+ } else if (typeof end === "object" && end) {
690
+ this._updateProperties(_object[property], start, end, value);
691
+ } else {
692
+ end = this._handleRelativeValue(start, end);
693
+ if (typeof end === "number") {
694
+ _object[property] = start + (end - start) * value;
695
+ }
696
+ }
697
+ }
698
+ };
699
+ Tween2.prototype._handleRelativeValue = function(start, end) {
700
+ if (typeof end !== "string") {
701
+ return end;
702
+ }
703
+ if (end.charAt(0) === "+" || end.charAt(0) === "-") {
704
+ return start + parseFloat(end);
705
+ } else {
706
+ return parseFloat(end);
707
+ }
708
+ };
709
+ Tween2.prototype._swapEndStartRepeatValues = function(property) {
710
+ var tmp = this._valuesStartRepeat[property];
711
+ var endValue = this._valuesEnd[property];
712
+ if (typeof endValue === "string") {
713
+ this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
714
+ } else {
715
+ this._valuesStartRepeat[property] = this._valuesEnd[property];
716
+ }
717
+ this._valuesEnd[property] = tmp;
718
+ };
719
+ return Tween2;
720
+ }();
721
+ var VERSION = "18.6.4";
722
+ var nextId = Sequence.nextId;
723
+ var TWEEN = mainGroup;
724
+ var getAll = TWEEN.getAll.bind(TWEEN);
725
+ var removeAll = TWEEN.removeAll.bind(TWEEN);
726
+ var add = TWEEN.add.bind(TWEEN);
727
+ var remove = TWEEN.remove.bind(TWEEN);
728
+ var update = TWEEN.update.bind(TWEEN);
729
+ var exports = {
730
+ Easing: Easing$1,
731
+ Group,
732
+ Interpolation,
733
+ now: now$1,
734
+ Sequence,
735
+ nextId,
736
+ Tween,
737
+ VERSION,
738
+ getAll,
739
+ removeAll,
740
+ add,
741
+ remove,
742
+ update
743
+ };
744
+ const Easing = exports.Easing;
745
+ function tween(from, to, duration, easing = Easing.Linear.None) {
746
+ const tweenInstance = new exports.Tween(from).to(to, duration).easing(easing).start();
747
+ function animate(time) {
748
+ if (!tweenInstance.update(time))
749
+ return;
750
+ requestAnimationFrame(animate);
751
+ }
752
+ requestAnimationFrame(animate);
753
+ return tweenInstance;
754
+ }
755
+ var PaintBrushTypeEnum = /* @__PURE__ */ ((PaintBrushTypeEnum2) => {
756
+ PaintBrushTypeEnum2["Drawline"] = "Drawline";
757
+ PaintBrushTypeEnum2["Undo"] = "Undo";
758
+ PaintBrushTypeEnum2["Exit"] = "Exit";
759
+ return PaintBrushTypeEnum2;
760
+ })(PaintBrushTypeEnum || {});
761
+ const EVENT_SYMBOL = Symbol("$$PAINT_BRUSH_EVENT$$");
762
+ function __generateEventIfNotExisted(instance) {
763
+ if (!instance[EVENT_SYMBOL]) {
764
+ instance[EVENT_SYMBOL] = {};
765
+ }
766
+ return instance[EVENT_SYMBOL];
767
+ }
768
+ function __removeEventIfNotExisted(instance) {
769
+ if (!instance[EVENT_SYMBOL]) {
770
+ delete instance[EVENT_SYMBOL];
771
+ }
772
+ }
773
+ class Subscribe {
774
+ hasListener(name) {
775
+ const events = __generateEventIfNotExisted(this);
776
+ return events && events[name] && events[name].length > 0;
777
+ }
778
+ on(name, callback, once) {
779
+ const events = __generateEventIfNotExisted(this);
780
+ if (!events[name])
781
+ events[name] = [];
782
+ events[name].push([callback, once || false]);
783
+ return () => this.off(name, callback);
784
+ }
785
+ once(name, callback) {
786
+ return this.on(name, callback, true);
787
+ }
788
+ off(name, callback) {
789
+ if (name === void 0) {
790
+ __removeEventIfNotExisted(this);
791
+ return;
792
+ }
793
+ const events = __generateEventIfNotExisted(this);
794
+ if (!events[name])
795
+ events[name] = [];
796
+ if (callback === void 0) {
797
+ events[name].length = 0;
798
+ return;
799
+ }
800
+ let index = 0;
801
+ for (; index < events[name].length; index++) {
802
+ if (events[name][index][0] === callback)
803
+ break;
804
+ }
805
+ if (index < events[name].length) {
806
+ events[name].splice(index, 1);
807
+ }
808
+ }
809
+ emit(name, ...data) {
810
+ let canceled = false;
811
+ const events = __generateEventIfNotExisted(this);
812
+ const event = events[name] || [];
813
+ for (let one of event.slice()) {
814
+ const [callback, once = false] = one;
815
+ const result = callback(...data);
816
+ if (once)
817
+ this.off(name, callback);
818
+ if (result === false)
819
+ canceled = true;
820
+ }
821
+ return canceled;
822
+ }
823
+ }
824
+ function S4() {
825
+ return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
826
+ }
827
+ function uuid() {
828
+ return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
829
+ }
830
+ const PaintBrushStyle = `
831
+ <style type="text/css">
832
+
833
+ #_gl_paintBrush {
834
+ position: fixed;
835
+ top: 0;
836
+ bottom: 0;
837
+ left: 0;
838
+ right: 0;
839
+ transform: translateZ(0);
840
+ z-index: 1997;
841
+ pointer-events: none;
842
+ opacity: 0;
843
+ transition: all 500ms;
844
+ }
845
+
846
+ #_gl_paintBrush.brushing {
847
+ opacity: 1;
848
+ }
849
+
850
+ #_gl_paintBrush ._paintBrush-canvas {
851
+ position: absolute;
852
+ width: 100%;
853
+ height: 100%;
854
+ left: 0;
855
+ top: 0;
856
+ }
857
+
858
+ #_gl_paintBrush ._paintBrush-canvas--sync {
859
+ pointer-events: none;
860
+ z-index: 0;
861
+ position: absolute;
862
+ width: 100%;
863
+ height: 100%;
864
+ left: 0;
865
+ top: 0;
866
+ }
867
+
868
+ #_gl_paintBrush ._paintBrush-canvas {
869
+ pointer-events: none;
870
+ z-index: 1;
871
+ }
872
+
873
+ #_gl_paintBrush.brushing ._paintBrush-canvas {
874
+ pointer-events: auto;
875
+ }
876
+
877
+ #_gl_paintBrush ._paintBrush-ctrl {
878
+ width: 140px;
879
+ height: 52px;
880
+ position: absolute;
881
+ bottom: 28px;
882
+ right: 50%;
883
+ transform: translateX(50%);
884
+ font-size: 10px;
885
+ color: white;
886
+ z-index: 2;
887
+ }
888
+
889
+ #_gl_paintBrush.brushing ._paintBrush-ctrl {
890
+ pointer-events: auto;
891
+ }
892
+
893
+ #_gl_paintBrush ._paintBrush-ctrl ._paintBrush-ctrlinner {
894
+ display: flex;
895
+ justify-content: space-between;
896
+ align-items: center;
897
+ width: 100%;
898
+ height: 100%;
899
+ border-radius: 26px;
900
+ padding: 8px 16px;
901
+ box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.2);
902
+ background-image: linear-gradient(180deg, hsl(0deg 0% 0% / 57%), hsl(0deg 0% 0% / 70%) 117%);
903
+ }
904
+
905
+ ._paintBrush-ctrlitem {
906
+ display: flex;
907
+ flex-direction: column;
908
+ justify-content: center;
909
+ align-items: center;
910
+ width: 38px;
911
+ height: 38px;
912
+ cursor: pointer;
913
+ }
914
+
915
+ ._paintBrush-ctrlitem--undo >.brush-icon{
916
+ background-image: url("//vrlab-static.ljcdn.com/release/web/revoke.ab7694ef.svg");
917
+ background-size: 100%;
918
+ width: 22px;
919
+ height: 22px;
920
+ }
921
+
922
+ ._paintBrush-ctrlitem--close >.brush-icon {
923
+ background-image: url("//vrlab-static.ljcdn.com/release/web/exit_paintbrush.02bc1341.svg");
924
+ background-size: 100%;
925
+ width: 22px;
926
+ height: 22px;
927
+ }
928
+
929
+ </style>
930
+ `;
931
+ class Controller extends Subscribe {
932
+ constructor(configs) {
933
+ super();
934
+ __publicField(this, "configs");
935
+ __publicField(this, "clientWidth");
936
+ __publicField(this, "clientHeight");
937
+ __publicField(this, "ready", false);
938
+ __publicField(this, "uuid", uuid());
939
+ __publicField(this, "tween");
940
+ __publicField(this, "tweening", false);
941
+ __publicField(this, "container");
942
+ __publicField(this, "canvas");
943
+ __publicField(this, "data", {});
944
+ __publicField(this, "tempLine", {});
945
+ this.configs = configs;
946
+ this.clientWidth = document.body.clientWidth;
947
+ this.clientHeight = document.body.clientHeight;
948
+ this.container = this.ifInsertToDOM();
949
+ this.canvas = {};
950
+ this.initCtrl();
951
+ }
952
+ get color() {
953
+ return this.configs.currentColor;
954
+ }
955
+ get state() {
956
+ return this.data;
957
+ }
958
+ get dpr() {
959
+ return this.configs.DPR || 1;
960
+ }
961
+ ifInsertToDOM() {
962
+ if (this.container) {
963
+ return this.container;
964
+ }
965
+ if (this.configs.container) {
966
+ this.configs.container.id = "_gl_paintBrush";
967
+ this.container = this.configs.container;
968
+ } else if (!document.getElementById("_gl_paintBrush")) {
969
+ const container = document.createElement("div");
970
+ container.id = "_gl_paintBrush";
971
+ document.body.appendChild(container);
972
+ this.container = container;
973
+ } else {
974
+ this.container = document.getElementById("_gl_paintBrush");
975
+ }
976
+ this.container.innerHTML = PaintBrushStyle;
977
+ return this.container;
978
+ }
979
+ initCanvas(className) {
980
+ const canvas = document.createElement("canvas");
981
+ canvas.className = className;
982
+ canvas.width = this.clientWidth;
983
+ canvas.height = this.clientHeight;
984
+ const ctx = canvas.getContext("2d");
985
+ if (!ctx)
986
+ return;
987
+ ctx.lineWidth = 5 * this.dpr;
988
+ ctx.lineCap = "round";
989
+ ctx.lineJoin = "round";
990
+ this.container.appendChild(canvas);
991
+ return canvas;
992
+ }
993
+ initCtrl() {
994
+ const ctrl = document.createElement("div");
995
+ ctrl.className = "_paintBrush-ctrl";
996
+ const ctrl_inner = document.createElement("div");
997
+ ctrl_inner.className = "_paintBrush-ctrlinner";
998
+ const a_undo = document.createElement("a");
999
+ a_undo.className = "_paintBrush-ctrlitem _paintBrush-ctrlitem--undo";
1000
+ a_undo.addEventListener("click", (e) => {
1001
+ var _a;
1002
+ e.stopPropagation();
1003
+ if (this.configs.onClickUndo) {
1004
+ this.configs.onClickUndo();
1005
+ }
1006
+ if (!this.canvas[this.uuid] || !this.data[this.uuid] || this.data[this.uuid].length === 0) {
1007
+ return;
1008
+ }
1009
+ const popState = this.data[this.uuid].pop();
1010
+ if (popState) {
1011
+ this.emitStateChange({
1012
+ type: PaintBrushTypeEnum.Undo,
1013
+ color: this.color,
1014
+ ready: this.ready,
1015
+ state: popState,
1016
+ uuid: this.uuid
1017
+ });
1018
+ }
1019
+ const $ctx = (_a = this.canvas[this.uuid]) == null ? void 0 : _a.getContext("2d");
1020
+ if (!this.canvas[this.uuid]) {
1021
+ return;
1022
+ }
1023
+ const { width, height } = this.canvas[this.uuid];
1024
+ if ($ctx) {
1025
+ $ctx.clearRect(0, 0, width, height);
1026
+ }
1027
+ this.data[this.uuid].forEach((ld) => this.handleDrawLine(this.uuid, ld, { withUndo: true }));
1028
+ });
1029
+ const a_close = document.createElement("a");
1030
+ a_close.className = "_paintBrush-ctrlitem _paintBrush-ctrlitem--close";
1031
+ a_close.addEventListener("click", (e) => {
1032
+ e.stopPropagation();
1033
+ this.closeBrush();
1034
+ if (this.configs.onClickClose) {
1035
+ this.configs.onClickClose();
1036
+ }
1037
+ });
1038
+ const $A = [a_undo, a_close];
1039
+ $A.forEach(($a) => {
1040
+ const $i = document.createElement("i");
1041
+ $i.className = "brush-icon";
1042
+ const $span = document.createElement("span");
1043
+ $span.className = "brush-txt";
1044
+ $span.innerText = $a.className.endsWith("undo") ? this.configs.onUndoText : this.configs.onExitText;
1045
+ $a.appendChild($i);
1046
+ $a.appendChild($span);
1047
+ });
1048
+ ctrl_inner.appendChild(a_undo);
1049
+ ctrl_inner.appendChild(a_close);
1050
+ ctrl.appendChild(ctrl_inner);
1051
+ this.container.appendChild(ctrl);
1052
+ return ctrl;
1053
+ }
1054
+ openBrush() {
1055
+ if (this.ready)
1056
+ return;
1057
+ if (!this.canvas[this.uuid]) {
1058
+ this.canvas[this.uuid] = this.initCanvas("_paintBrush-canvas");
1059
+ }
1060
+ this.container.className = "brushing";
1061
+ const $curCanvas = this.canvas[this.uuid];
1062
+ const $ctx = $curCanvas.getContext("2d");
1063
+ $ctx.clearRect(0, 0, $curCanvas.width, $curCanvas.height);
1064
+ this.openBrushHandle();
1065
+ this.ready = true;
1066
+ this.emit("readyChange", true);
1067
+ }
1068
+ closeBrush() {
1069
+ if (!this.ready)
1070
+ return;
1071
+ this.container.className = "";
1072
+ this.data = {};
1073
+ this.tempLine = {};
1074
+ Object.keys(this.canvas).forEach((key) => {
1075
+ this.canvas[key].ontouchstart = () => false;
1076
+ this.canvas[key].ontouchmove = () => false;
1077
+ this.canvas[key].ontouchend = () => false;
1078
+ this.canvas[key].ontouchcancel = () => false;
1079
+ const $ctx = this.canvas[key].getContext("2d");
1080
+ if ($ctx) {
1081
+ $ctx.clearRect(0, 0, this.canvas[key].width, this.canvas[key].height);
1082
+ }
1083
+ });
1084
+ this.ready = false;
1085
+ this.emit("readyChange", false);
1086
+ this.emitStateChange({
1087
+ type: PaintBrushTypeEnum.Exit,
1088
+ color: this.color,
1089
+ ready: false,
1090
+ uuid: this.uuid
1091
+ });
1092
+ }
1093
+ updateCurrentColor(color) {
1094
+ const currentCanvas = this.canvas[this.uuid];
1095
+ if (!currentCanvas)
1096
+ return;
1097
+ const currentCtx = currentCanvas.getContext("2d");
1098
+ if (!currentCtx)
1099
+ return;
1100
+ this.configs.currentColor = color;
1101
+ currentCtx.strokeStyle = color;
1102
+ }
1103
+ openBrushHandle() {
1104
+ const currentCanvas = this.canvas[this.uuid];
1105
+ if (!currentCanvas)
1106
+ return;
1107
+ const currentCtx = currentCanvas.getContext("2d");
1108
+ if (!currentCtx)
1109
+ return;
1110
+ const color = this.color || "#6D92FF";
1111
+ currentCtx.strokeStyle = color;
1112
+ let begin = null;
1113
+ let points = [];
1114
+ let move;
1115
+ let line = [];
1116
+ let startTime = 0;
1117
+ const draw = (beginPoint, controlPoint, endPoint) => {
1118
+ const color2 = this.color || "#ff0000";
1119
+ currentCtx.strokeStyle = color2;
1120
+ currentCtx.beginPath();
1121
+ currentCtx.moveTo(beginPoint.x, beginPoint.y);
1122
+ currentCtx.quadraticCurveTo(controlPoint.x, controlPoint.y, endPoint.x, endPoint.y);
1123
+ currentCtx.stroke();
1124
+ };
1125
+ currentCanvas.onmousedown = (e) => {
1126
+ e.preventDefault();
1127
+ startTime = Date.now();
1128
+ const x = e.clientX;
1129
+ const y = e.clientY;
1130
+ points = [];
1131
+ points.push({ x, y });
1132
+ begin = { x, y };
1133
+ move = transformCoords({ x, y }, this.clientWidth, this.clientHeight);
1134
+ line = [];
1135
+ };
1136
+ currentCanvas.onmousemove = (e) => {
1137
+ e.preventDefault();
1138
+ if (!begin)
1139
+ return;
1140
+ const x = Number(e.clientX);
1141
+ const y = Number(e.clientY);
1142
+ if (Math.abs(x - begin.x) < 5 && Math.abs(y - begin.y) < 5) {
1143
+ return;
1144
+ }
1145
+ points.push({ x, y });
1146
+ line.push(transformCoords({ x, y }, this.clientWidth, this.clientHeight));
1147
+ if (points.length < 3) {
1148
+ return;
1149
+ }
1150
+ const { control, end } = getQuadraticCurvePoint(points);
1151
+ if (!control || !end) {
1152
+ return;
1153
+ }
1154
+ draw(begin, control, end);
1155
+ begin = end;
1156
+ };
1157
+ currentCanvas.onmouseup = (e) => {
1158
+ e.preventDefault();
1159
+ begin = null;
1160
+ if (points.length < 3)
1161
+ return;
1162
+ if (!this.data[this.uuid]) {
1163
+ this.data[this.uuid] = [];
1164
+ }
1165
+ const duration = Date.now() - startTime;
1166
+ const state2 = {
1167
+ move: Object.assign({}, move),
1168
+ uuid: this.uuid,
1169
+ line: [...line],
1170
+ color: this.color,
1171
+ duration: duration < 1280 ? duration : duration < 2e3 ? 1280 : 0
1172
+ };
1173
+ this.data[this.uuid].push(state2);
1174
+ nextFrame(() => {
1175
+ this.emitStateChange({
1176
+ type: PaintBrushTypeEnum.Drawline,
1177
+ color: this.color,
1178
+ ready: this.ready,
1179
+ state: state2,
1180
+ uuid: this.uuid
1181
+ });
1182
+ });
1183
+ };
1184
+ currentCanvas.ontouchstart = (e) => {
1185
+ e.preventDefault();
1186
+ startTime = Date.now();
1187
+ const x = e.touches[0].clientX;
1188
+ const y = e.touches[0].clientY;
1189
+ points = [];
1190
+ points.push({ x, y });
1191
+ begin = { x, y };
1192
+ console.log("ontouchstart", x, y, begin);
1193
+ move = transformCoords({ x, y }, this.clientWidth, this.clientHeight);
1194
+ line = [];
1195
+ };
1196
+ currentCanvas.ontouchmove = (e) => {
1197
+ e.preventDefault();
1198
+ if (!begin)
1199
+ return;
1200
+ const x = Number(e.touches[0].clientX);
1201
+ const y = Number(e.touches[0].clientY);
1202
+ if (Math.abs(x - begin.x) < 5 && Math.abs(y - begin.y) < 5)
1203
+ return;
1204
+ points.push({ x, y });
1205
+ line.push(transformCoords({ x, y }, this.clientWidth, this.clientHeight));
1206
+ if (points.length < 3)
1207
+ return;
1208
+ const { control, end } = getQuadraticCurvePoint(points);
1209
+ if (!control || !end)
1210
+ return;
1211
+ draw(begin, control, end);
1212
+ begin = end;
1213
+ };
1214
+ currentCanvas.ontouchend = currentCanvas.ontouchcancel = (e) => {
1215
+ e.preventDefault();
1216
+ begin = null;
1217
+ if (points.length < 3)
1218
+ return;
1219
+ if (!this.data[this.uuid]) {
1220
+ this.data[this.uuid] = [];
1221
+ }
1222
+ const duration = Date.now() - startTime;
1223
+ const state2 = {
1224
+ move: Object.assign({}, move),
1225
+ line: [...line],
1226
+ uuid: this.uuid,
1227
+ color: this.color,
1228
+ duration: duration < 1280 ? duration : duration < 2e3 ? 1280 : 0
1229
+ };
1230
+ this.data[this.uuid].push(state2);
1231
+ nextFrame(() => {
1232
+ this.emitStateChange({
1233
+ type: PaintBrushTypeEnum.Drawline,
1234
+ color: this.color,
1235
+ ready: this.ready,
1236
+ state: state2,
1237
+ uuid: this.uuid
1238
+ });
1239
+ });
1240
+ };
1241
+ }
1242
+ emitStateChange(action, userAction = true) {
1243
+ if (action.type !== PaintBrushTypeEnum.Drawline) {
1244
+ this.emit("stateChange", action, userAction);
1245
+ return;
1246
+ }
1247
+ const timestamp = Date.now();
1248
+ const state2 = action.state;
1249
+ if (!state2)
1250
+ return;
1251
+ if (!state2.line)
1252
+ return;
1253
+ const sliceCount = Math.ceil(state2.line.length / 100);
1254
+ for (let i = 0; i < sliceCount; i++) {
1255
+ const localityAction = {
1256
+ uuid: this.uuid,
1257
+ color: this.color,
1258
+ ready: this.ready,
1259
+ type: action.type,
1260
+ state: {
1261
+ uuid: this.uuid,
1262
+ move: state2.move,
1263
+ duration: state2.duration,
1264
+ color: this.color,
1265
+ line: state2.line.slice(i * 100, (i + 1) * 100)
1266
+ },
1267
+ timestamp,
1268
+ end: i === sliceCount - 1
1269
+ };
1270
+ execInterval(i, 20, () => {
1271
+ this.emit("stateChange", localityAction, userAction);
1272
+ });
1273
+ }
1274
+ }
1275
+ action(action) {
1276
+ const { ready, type, uuid: uuid2 } = action;
1277
+ if (!ready && this.ready) {
1278
+ this.closeBrush();
1279
+ return;
1280
+ }
1281
+ if (ready && !this.ready) {
1282
+ this.openBrush();
1283
+ return;
1284
+ }
1285
+ if (!this.ready) {
1286
+ return;
1287
+ }
1288
+ switch (type) {
1289
+ case PaintBrushTypeEnum.Drawline:
1290
+ const { state: state2, timestamp, end } = action;
1291
+ if (!timestamp)
1292
+ return;
1293
+ if (!state2)
1294
+ return;
1295
+ this.tempLine[timestamp] = [].concat(this.tempLine[timestamp] || [], state2.line);
1296
+ if (end) {
1297
+ Object.assign(state2, { line: this.tempLine[timestamp] });
1298
+ this.handleDrawLine(uuid2, state2, {}, () => delete this.tempLine[timestamp]);
1299
+ }
1300
+ break;
1301
+ case PaintBrushTypeEnum.Undo:
1302
+ this.handleUndo(uuid2);
1303
+ break;
1304
+ }
1305
+ }
1306
+ handleDrawLine(_uuid, data, { withUndo = false }, callback = noop) {
1307
+ if (!data || Object.prototype.toString.call(data) != "[object Object]" || Object.keys(data).length === 0) {
1308
+ return;
1309
+ }
1310
+ console.log("handleDrawLine", data, data.line);
1311
+ queue(() => {
1312
+ return new Promise((resolve) => {
1313
+ if (!withUndo) {
1314
+ if (!this.canvas[_uuid]) {
1315
+ this.canvas[_uuid] = this.initCanvas("_paintBrush-canvas--sync");
1316
+ }
1317
+ if (!this.data[_uuid]) {
1318
+ this.data[_uuid] = [];
1319
+ }
1320
+ this.data[_uuid].push(data);
1321
+ }
1322
+ if (!this.canvas[_uuid]) {
1323
+ return;
1324
+ }
1325
+ const $ctx = this.canvas[_uuid].getContext("2d");
1326
+ if (!$ctx)
1327
+ return;
1328
+ const { line = [], color = "black", duration = 0, uuid: uuid2 } = data;
1329
+ const move = unTransformCoords(data.move || {}, this.clientWidth, this.clientHeight);
1330
+ let points = [move];
1331
+ $ctx.strokeStyle = color;
1332
+ $ctx.beginPath();
1333
+ $ctx.moveTo(move.x, move.y);
1334
+ if (duration && !withUndo) {
1335
+ let drawCache = [];
1336
+ const self2 = this;
1337
+ self2.tween = tween({ step: 0 }, { step: line.length - 1 }, duration).onUpdate(({ step }) => {
1338
+ var _a;
1339
+ self2.tweening = true;
1340
+ if (!self2.ready) {
1341
+ $ctx.clearRect(0, 0, self2.canvas[uuid2].width, self2.canvas[uuid2].height);
1342
+ return (_a = self2.tween) == null ? void 0 : _a.stop();
1343
+ }
1344
+ const i = Math.floor(step);
1345
+ if (!drawCache.find((dc) => dc === i)) {
1346
+ drawCache.push(i);
1347
+ console.log("__debug__", line, line[i], i);
1348
+ points.push(unTransformCoords(line[i], self2.clientWidth, self2.clientHeight));
1349
+ if (points.length < 3)
1350
+ return;
1351
+ const { control, end } = getQuadraticCurvePoint(points);
1352
+ if (!control || !end)
1353
+ return;
1354
+ $ctx.quadraticCurveTo(control.x, control.y, end.x, end.y);
1355
+ $ctx.stroke();
1356
+ }
1357
+ }).onComplete((e) => {
1358
+ self2.tween = void 0;
1359
+ self2.tweening = false;
1360
+ drawCache = [];
1361
+ points = [];
1362
+ if (callback)
1363
+ callback();
1364
+ resolve();
1365
+ });
1366
+ } else {
1367
+ for (let i = 0; i < line.length; i++) {
1368
+ points.push(unTransformCoords(line[i], this.clientWidth, this.clientHeight));
1369
+ if (points.length < 3)
1370
+ continue;
1371
+ const { control, end } = getQuadraticCurvePoint(points);
1372
+ if (!control || !end)
1373
+ continue;
1374
+ $ctx.quadraticCurveTo(control.x, control.y, end.x, end.y);
1375
+ }
1376
+ $ctx.stroke();
1377
+ points = [];
1378
+ if (callback)
1379
+ callback();
1380
+ resolve();
1381
+ }
1382
+ });
1383
+ });
1384
+ }
1385
+ handleUndo(uuid2) {
1386
+ console.log("handleUndo", uuid2, this.canvas[uuid2]);
1387
+ if (!this.canvas[uuid2] || !this.data[uuid2] || this.data[uuid2].length === 0) {
1388
+ return;
1389
+ }
1390
+ this.data[uuid2].pop();
1391
+ const handle = () => {
1392
+ var _a;
1393
+ const $ctx = (_a = this.canvas[uuid2]) == null ? void 0 : _a.getContext("2d");
1394
+ if ($ctx) {
1395
+ $ctx.clearRect(0, 0, this.canvas[uuid2].width, this.canvas[uuid2].height);
1396
+ }
1397
+ this.data[uuid2].forEach((ld) => this.handleDrawLine(uuid2, ld, { withUndo: true }));
1398
+ };
1399
+ if (this.tween && this.tweening) {
1400
+ this.tween.stop();
1401
+ nextFrame(handle, 60);
1402
+ return;
1403
+ }
1404
+ handle();
1405
+ }
1406
+ destroyBrush() {
1407
+ this.closeBrush();
1408
+ this.ready = false;
1409
+ this.emit("readyChange", true);
1410
+ }
1411
+ }
1412
+ class PaintBrush {
1413
+ constructor(configs = {}) {
1414
+ __publicField(this, "controller");
1415
+ const _configs = Object.assign({
1416
+ currentColor: "#f44336",
1417
+ onUndoText: "\u56DE\u9000",
1418
+ onExitText: "\u5173\u95ED"
1419
+ }, configs);
1420
+ this.controller = new Controller(_configs);
1421
+ }
1422
+ on(name, callback) {
1423
+ this.controller.on(name, callback);
1424
+ }
1425
+ off(name, callback) {
1426
+ this.controller.off(name, callback);
1427
+ }
1428
+ once(name, callback) {
1429
+ this.controller.once(name, callback);
1430
+ }
1431
+ show() {
1432
+ this.controller.openBrush();
1433
+ }
1434
+ action(action) {
1435
+ this.controller.action(action);
1436
+ }
1437
+ get state() {
1438
+ return this.controller.state;
1439
+ }
1440
+ get configs() {
1441
+ return this.controller.configs;
1442
+ }
1443
+ dispose() {
1444
+ return this.controller.destroyBrush();
1445
+ }
1446
+ setCurrentColor(color) {
1447
+ this.controller.updateCurrentColor(color);
1448
+ }
1449
+ }
1450
+ export { PaintBrush, PaintBrushTypeEnum };