@urso/core 0.7.90 → 0.7.91

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 (133) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +227 -227
  4. package/build/js/index.js +1 -1
  5. package/package.json +50 -50
  6. package/src/js/app.js +104 -104
  7. package/src/js/components/base/controller.js +78 -78
  8. package/src/js/components/debug/controller.js +38 -38
  9. package/src/js/components/debug/coords.js +23 -23
  10. package/src/js/components/debug/fps.js +36 -36
  11. package/src/js/components/debug/template.js +55 -55
  12. package/src/js/components/debug/timescale.js +60 -60
  13. package/src/js/components/deviceRotate/controller.js +95 -95
  14. package/src/js/components/editor/api.js +127 -127
  15. package/src/js/components/editor/controller.js +12 -12
  16. package/src/js/components/fullscreen/android.js +104 -104
  17. package/src/js/components/fullscreen/controller.js +76 -76
  18. package/src/js/components/fullscreen/desktop.js +49 -49
  19. package/src/js/components/fullscreen/ios.js +115 -115
  20. package/src/js/components/layersSwitcher/config.js +26 -26
  21. package/src/js/components/layersSwitcher/controller.js +36 -36
  22. package/src/js/components/loader/controller.js +66 -66
  23. package/src/js/components/loader/template.js +70 -70
  24. package/src/js/components/soundInitialPopup/controller.js +42 -42
  25. package/src/js/components/soundInitialPopup/template.js +109 -109
  26. package/src/js/components/stateDriven/controller.js +123 -123
  27. package/src/js/config/load.js +194 -194
  28. package/src/js/config/main.js +17 -17
  29. package/src/js/extra/browserEvents.js +57 -57
  30. package/src/js/extra/main.js +19 -19
  31. package/src/js/extra/pixiPatch.js +171 -171
  32. package/src/js/index.js +7 -7
  33. package/src/js/lib/cache.js +125 -125
  34. package/src/js/lib/composition.js +85 -85
  35. package/src/js/lib/device.js +1215 -1215
  36. package/src/js/lib/helper.js +678 -678
  37. package/src/js/lib/loader.js +211 -211
  38. package/src/js/lib/localData.js +28 -28
  39. package/src/js/lib/logger.js +69 -69
  40. package/src/js/lib/math.js +161 -161
  41. package/src/js/lib/objectPool.js +207 -207
  42. package/src/js/lib/time.js +18 -18
  43. package/src/js/lib/tween.js +152 -152
  44. package/src/js/modules/assets/baseModel.js +20 -20
  45. package/src/js/modules/assets/config.js +38 -38
  46. package/src/js/modules/assets/controller.js +65 -65
  47. package/src/js/modules/assets/models/atlas.js +18 -18
  48. package/src/js/modules/assets/models/audiosprite.js +28 -28
  49. package/src/js/modules/assets/models/bitmapFont.js +10 -10
  50. package/src/js/modules/assets/models/container.js +18 -18
  51. package/src/js/modules/assets/models/font.js +10 -10
  52. package/src/js/modules/assets/models/html.js +10 -10
  53. package/src/js/modules/assets/models/image.js +17 -17
  54. package/src/js/modules/assets/models/json.js +10 -10
  55. package/src/js/modules/assets/models/jsonAtlas.js +10 -10
  56. package/src/js/modules/assets/models/sound.js +16 -16
  57. package/src/js/modules/assets/models/spine.js +16 -16
  58. package/src/js/modules/assets/service.js +541 -541
  59. package/src/js/modules/i18n/config.js +17 -17
  60. package/src/js/modules/i18n/controller.js +71 -71
  61. package/src/js/modules/instances/controller.js +357 -357
  62. package/src/js/modules/logic/config/sounds.js +23 -23
  63. package/src/js/modules/logic/controller.js +52 -52
  64. package/src/js/modules/logic/main.js +8 -8
  65. package/src/js/modules/logic/sounds.js +103 -103
  66. package/src/js/modules/objects/baseModel.js +207 -207
  67. package/src/js/modules/objects/cache.js +99 -99
  68. package/src/js/modules/objects/config.js +9 -9
  69. package/src/js/modules/objects/controller.js +139 -139
  70. package/src/js/modules/objects/find.js +58 -58
  71. package/src/js/modules/objects/models/atlasImage.js +52 -52
  72. package/src/js/modules/objects/models/bitmapText.js +48 -48
  73. package/src/js/modules/objects/models/button.js +196 -196
  74. package/src/js/modules/objects/models/buttonComposite.js +37 -37
  75. package/src/js/modules/objects/models/checkbox.js +96 -96
  76. package/src/js/modules/objects/models/collection.js +54 -54
  77. package/src/js/modules/objects/models/component.js +48 -48
  78. package/src/js/modules/objects/models/container.js +21 -21
  79. package/src/js/modules/objects/models/dragContainer.js +664 -664
  80. package/src/js/modules/objects/models/emitter.js +69 -69
  81. package/src/js/modules/objects/models/emitterFx.js +114 -114
  82. package/src/js/modules/objects/models/graphics.js +40 -40
  83. package/src/js/modules/objects/models/group.js +21 -21
  84. package/src/js/modules/objects/models/hitArea.js +119 -119
  85. package/src/js/modules/objects/models/image.js +36 -36
  86. package/src/js/modules/objects/models/imagesAnimation.js +115 -115
  87. package/src/js/modules/objects/models/mask.js +40 -40
  88. package/src/js/modules/objects/models/nineSlicePlane.js +32 -32
  89. package/src/js/modules/objects/models/scrollbox.js +66 -66
  90. package/src/js/modules/objects/models/slider.js +352 -352
  91. package/src/js/modules/objects/models/spine.js +338 -338
  92. package/src/js/modules/objects/models/text.js +70 -70
  93. package/src/js/modules/objects/models/textInput.js +68 -68
  94. package/src/js/modules/objects/models/toggle.js +179 -179
  95. package/src/js/modules/objects/models/world.js +21 -21
  96. package/src/js/modules/objects/pool.js +68 -68
  97. package/src/js/modules/objects/propertyAdapter.js +588 -588
  98. package/src/js/modules/objects/proxy.js +298 -298
  99. package/src/js/modules/objects/selector.js +136 -136
  100. package/src/js/modules/objects/service.js +254 -254
  101. package/src/js/modules/objects/styles.js +210 -210
  102. package/src/js/modules/observer/controller.js +167 -167
  103. package/src/js/modules/observer/events.js +56 -56
  104. package/src/js/modules/scenes/controller.js +127 -127
  105. package/src/js/modules/scenes/model.js +28 -28
  106. package/src/js/modules/scenes/pixiWrapper.js +351 -351
  107. package/src/js/modules/scenes/resolutions.js +173 -173
  108. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  109. package/src/js/modules/scenes/service.js +146 -146
  110. package/src/js/modules/soundManager/controller.js +103 -103
  111. package/src/js/modules/soundManager/soundSprite.js +285 -285
  112. package/src/js/modules/statesManager/action.js +97 -97
  113. package/src/js/modules/statesManager/all.js +23 -23
  114. package/src/js/modules/statesManager/configStates.js +77 -77
  115. package/src/js/modules/statesManager/controller.js +218 -218
  116. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  117. package/src/js/modules/statesManager/helper.js +27 -27
  118. package/src/js/modules/statesManager/race.js +91 -91
  119. package/src/js/modules/statesManager/sequence.js +48 -48
  120. package/src/js/modules/template/controller.js +28 -28
  121. package/src/js/modules/template/model.js +11 -11
  122. package/src/js/modules/template/service.js +137 -137
  123. package/src/js/modules/template/types.js +48 -48
  124. package/src/js/modules/transport/baseConnectionType.js +25 -25
  125. package/src/js/modules/transport/config.js +13 -13
  126. package/src/js/modules/transport/connectionTypes/websocket.js +76 -76
  127. package/src/js/modules/transport/connectionTypes/xhr.js +46 -46
  128. package/src/js/modules/transport/controller.js +48 -48
  129. package/src/js/modules/transport/decorator.js +17 -17
  130. package/src/js/modules/transport/service.js +150 -150
  131. package/webpack.config.js +47 -47
  132. package/build/162.js/index.js +0 -1
  133. package/build/24.js/index.js +0 -1
@@ -1,665 +1,665 @@
1
- const ModulesObjectsModelsContainer = require('./container.js');
2
- const containers = [];
3
-
4
- class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
5
- _mask = null;
6
- _interactiveLayer = null;
7
- _startPosition = null;
8
- _startY = 0;
9
- _offsetStartY = 0;
10
- _needBlock = false;
11
- _needMoveSlider = true;
12
- _moveStartedY = 0;
13
- _dragStarted = false;
14
- _minMoveDurationForEasing = 100;
15
- _minMoveDistanceForEasing = 50;
16
- _minMoveDistance = 15;
17
- _currentPosition = 0;
18
-
19
- constructor(params) {
20
- super(params);
21
-
22
- this.type = Urso.types.objects.DRAGCONTAINER;
23
-
24
- this._onScrollSliderMove = this._onScrollSliderMove.bind(this);
25
- this._sliderHandleDrop = this._sliderHandleDrop.bind(this);
26
- this._setSliderHandler = this._setSliderHandler.bind(this);
27
- this._switchBlock = this._switchBlock.bind(this);
28
- this._pointerEventsHandler = this._pointerEventsHandler.bind(this);
29
- this._onResolutionChange = this._onResolutionChange.bind(this);
30
-
31
- this._setupDragContainer();
32
- containers.push(this);
33
- }
34
-
35
- /**
36
- * Setups initial params on create.
37
- * @param { Object } params
38
- */
39
- setupParams(params) {
40
- super.setupParams(params);
41
- this.speed = Urso.helper.recursiveGet('speed', params, 1);
42
- this.dragIndex = Urso.helper.recursiveGet('dragIndex', params, 0);
43
- this.sliderClass = Urso.helper.recursiveGet('sliderClass', params, false);
44
- this.onMoveCallback = Urso.helper.recursiveGet('onMoveCallback', params, false);
45
- this.easingTime = Urso.helper.recursiveGet('easingTime', params, 1.5);
46
- this.easingDistance = Urso.helper.recursiveGet('easingDistance', params, 200);
47
- this.zIndex = Urso.helper.recursiveGet('zIndex', params, 10);
48
- this.width = Urso.helper.recursiveGet('width', params, 200); // Width of container visible area. Numbers only.
49
- this.height = Urso.helper.recursiveGet('height', params, 200); // Height of container visible area. Numbers only.
50
- }
51
-
52
- /**
53
- * Checks if interactive layer is visible and move in progress.
54
- * @returns { Boolean }
55
- */
56
- get _moveInProgress() {
57
- return this._interactiveLayer.visible
58
- }
59
-
60
- /**
61
- * Sets interactiveLayer visibility.
62
- */
63
- set _moveInProgress(inProgress) {
64
- this._interactiveLayer.visible = inProgress;
65
- }
66
-
67
- /**
68
- * Resizes mask and interactiveLayer according dragContainer size
69
- * @param { Boolean } needResetMaskY
70
- */
71
- resize(needResetMaskY) {
72
- this._resizeInteractiveLayer();
73
- this._resizeMask();
74
-
75
- if (needResetMaskY) {
76
- this._mask.y = 0;
77
- }
78
- }
79
-
80
- /**
81
- * Initial setup dragContainers params.
82
- */
83
- _setupDragContainer() {
84
- this._setMask();
85
- this._resizeInteractiveLayer();
86
- this._resizeMask();
87
- this._setResizeReactively();
88
- this._currentPosition = this._baseObject.y;
89
- }
90
-
91
- /**
92
- * Subscribes resize() method on dragContauber width/height params change
93
- */
94
- _setResizeReactively() {
95
- Urso.helper.reactive(this, 'width', () => this.resize());
96
- Urso.helper.reactive(this, 'height', () => this.resize());
97
- }
98
-
99
- /**
100
- * Setups mask and interactive layer of dragContainer
101
- */
102
- _setMask() {
103
- this._mask = this._makeMask();
104
-
105
- this._interactiveLayer = this._makeInteractiveLayer();
106
- this._interactiveLayer.on('pointermove', (e) => this._onPointerMove(e));
107
-
108
- this._baseObject.addChild(this._mask);
109
- this._baseObject.addChild(this._interactiveLayer);
110
-
111
- this._baseObject.mask = this._mask;
112
- }
113
-
114
- /**
115
- * Function takes pointer coords and checks if pointer over current dragContainer.
116
- * @param { Object } coords
117
- * @returns { Boolean }
118
- */
119
- _isActive({ x, y }) {
120
- const pointerOverContainers = containers
121
- .filter((container) => {
122
- const points = this._getObjectPoints(container);
123
- return this._checkPointerOver({ x, y }, ...points);
124
- })
125
- .filter((container) => container._baseObject.worldVisible)
126
- .filter((container) => !container._needBlock)
127
- .filter((container) => {
128
- const height = container.getAbsoluteSize().height;
129
- return container.height - height < 0;
130
- })
131
- .sort((firstContainer, secondContainer) => secondContainer.dragIndex - firstContainer.dragIndex);
132
-
133
- return pointerOverContainers[0] === this;
134
- }
135
-
136
- /**
137
- * Hides attached slider if dragContainer cannot be scrolled
138
- */
139
- _changeSliderVisibility() {
140
- if (!this._slider)
141
- return;
142
-
143
- this._slider.visible = this.height < this._baseObject.height;
144
- }
145
-
146
- /**
147
- * Function takes pointer coords and coords of the two container's vertexes
148
- * returns relative position of pointer between two points
149
- * @param { Object } pointerCoords
150
- * @param { Object } point1
151
- * @param { Object } point2
152
- * @returns { Number }
153
- */
154
- _getPointerRelativePosition(pointerCoords, point1, point2) {
155
- const xDelta = point2.x - point1.x;
156
- const yDelta = point2.y - point1.y;
157
- const poiterDeltaY = pointerCoords.y - point1.y;
158
- const poiterDeltaX = pointerCoords.x - point1.x;
159
- return xDelta * poiterDeltaY - yDelta * poiterDeltaX;
160
- }
161
-
162
- /**
163
- * Takes pointer coords and dragContainer vertexes coords.
164
- * Checks if pointer is inside dragContainer rectangle.
165
- * @param { Object } pointerCoords
166
- * @param { Object } pointA
167
- * @param { Object } pointB
168
- * @param { Object } pointC
169
- * @param { Object } pointD
170
- * @returns { Boolean }
171
- */
172
- _checkPointerOver(pointerCoords, pointA, pointB, pointC, pointD) {
173
- const point1 = this._getPointerRelativePosition(pointerCoords, pointA, pointB);
174
- const point2 = this._getPointerRelativePosition(pointerCoords, pointB, pointC);
175
- const point3 = this._getPointerRelativePosition(pointerCoords, pointC, pointD);
176
- const point4 = this._getPointerRelativePosition(pointerCoords, pointD, pointA);
177
- return (point1 < 0 && point2 < 0 && point3 < 0 && point4 < 0) || (point1 > 0 && point2 > 0 && point3 > 0 && point4 > 0);
178
- }
179
-
180
- /**
181
- * Function takes container object and calculate it's vertexes coords.
182
- * Returns array of coords.
183
- * @param { Object } container
184
- * @returns { Array }
185
- */
186
- _getObjectPoints(container) {
187
- const { x, y } = container._mask.toGlobal(new PIXI.Point(0, 0));
188
-
189
- const { width, height } = container._mask;
190
- const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
191
-
192
- return [
193
- { x, y },
194
- { x: x + width * scaleX, y },
195
- { x: x + width * scaleX, y: y + height * scaleY },
196
- { x, y: y + height * scaleY }
197
- ];
198
- }
199
-
200
- /**
201
- * Function takes dragContainer object and recurcievly calculates it's global scale and position
202
- * @param { Object }
203
- * @returns { Object }
204
- */
205
- _getScaleAndPositionRecursive({ scaleX, scaleY, parent, x, y }) {
206
- if (!parent) {
207
- return { scaleX, scaleY, x, y };
208
- }
209
-
210
- const { scaleX: parentScaleX, scaleY: parentScaleY, x: parentX, y: parentY } = this._getScaleAndPositionRecursive(parent);
211
-
212
- return {
213
- scaleX: scaleX * parentScaleX,
214
- scaleY: scaleY * parentScaleY,
215
- x: x + parentX,
216
- y: y + parentY,
217
- }
218
- }
219
-
220
- /**
221
- * Callback on pointer move. Takes pointer event data.
222
- * @param { Object } e
223
- */
224
- _documentPointerMove(e) {
225
- if(!this._movePossible)
226
- return;
227
-
228
- this._moveInProgress = true;
229
-
230
- const offset = e.offsetY ?? e.changedTouches[0].changedOffsetY ?? e.changedTouches[0].clientY ?? 0;
231
-
232
- if (Math.abs(this._moveStartedY - offset) > this._minMoveDistance && !this._dragStarted) {
233
- this._dragStarted = true;
234
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_STARTED, { name: this.name, className: this.class, id: this.id });
235
- }
236
- }
237
-
238
- /**
239
- * Callback on move end. Unblock all dragContainers and if move was longer than requred minimum starts easing
240
- */
241
- _documentPointerEnd() {
242
- this._movePossible = false;
243
- const timeDelta = Date.now() - this._lastMoveTime;
244
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, { names: ['*'], needBlock: false });
245
-
246
- if (this._wasMoved && timeDelta < this._minMoveDurationForEasing)
247
- this._startMoveEasing();
248
- else
249
- this._startPosition = null;
250
-
251
- this._onMoveComplete();
252
- this._wasMoved = false;
253
- }
254
-
255
- /**
256
- * Starts easing animation in the end of move
257
- */
258
- _startMoveEasing() {
259
- const targetY = this._getEasingTargetY();
260
-
261
- if (!targetY) {
262
- this._startPosition = null;
263
- return
264
- };
265
-
266
- let obj = { y: this._baseObject.y };
267
-
268
- this._easingTween = gsap.to(obj, this.easingTime, {
269
- y: targetY, ease: 'power2',
270
- onUpdate: () => {
271
- this._move(obj.y, true);
272
- this._isBorder && this._killTweens();
273
- },
274
- onComplete: () => {
275
- this._startPosition = null;
276
- }
277
- })
278
- }
279
-
280
- /**
281
- * Kills al animation tweens
282
- */
283
- _killTweens() {
284
- if (this._easingTween) {
285
- this._easingTween.pause();
286
- this._easingTween.kill(true);
287
- this._easingTween = null;
288
- this._startPosition = null;
289
- };
290
- }
291
-
292
- /**
293
- * Calculates target move coordinate of easing
294
- * @returns { Number }
295
- */
296
- _getEasingTargetY() {
297
- const multipler = this._moveStartY > this._baseObject.y ? -1 : 1;
298
-
299
- if (Math.abs(this._moveStartY - this._baseObject.y) < this._minMoveDistanceForEasing)
300
- return false;
301
-
302
- return this._baseObject.y + this.easingDistance * multipler;
303
- }
304
-
305
- /**
306
- * Resets params on move callback
307
- */
308
- _onMoveComplete() {
309
- this._moveInProgress = false;
310
- this._dragStarted = false;
311
- this._isWheelMove = false;
312
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_FINISHED, { name: this.name, className: this.class, id: this.id });
313
- this._isBorder = false;
314
- }
315
-
316
- /**
317
- * Checks if next dragContainer Y coordinate is in possible range.
318
- * If it's out of possible range returns nearest possible point.
319
- * @param { Number } y
320
- * @param { Number } lastPosY
321
- * @param { Number } deltaY
322
- * @returns { Number }
323
- */
324
- _getValidatedY(y, lastPosY, deltaY) {
325
- if (y > 0) {
326
- this._startY = -deltaY;
327
- y = 0;
328
- }
329
-
330
- if (lastPosY > y) {
331
- this._startY = lastPosY - deltaY;
332
- this._isBorder = true;
333
- y = lastPosY;
334
- }
335
-
336
- const possibleMinY = this.height - this._calcMaxY(this._baseObject);
337
-
338
- if (y < possibleMinY) {
339
- y = possibleMinY;
340
- this._isBorder = true
341
- }
342
-
343
- return y;
344
- }
345
-
346
- /**
347
- * Calculates max possible dragContainer Y
348
- * @param { Object } pixiObject
349
- * @returns { Number }
350
- */
351
- _calcMaxY(pixiObject) {
352
- let maxY = 0;
353
-
354
- pixiObject.children.forEach(element => {
355
- if (element.isMask)
356
- return;
357
-
358
- const elementLimit = element.y + element.height;
359
-
360
- if (elementLimit > maxY)
361
- maxY = elementLimit;
362
- });
363
-
364
- return maxY;
365
- }
366
-
367
- /**
368
- * Validates next dragContainer position.
369
- * @param { Number } lastY
370
- * @param { Boolean } isWheel
371
- * @returns { Number }
372
- */
373
- _validateY(lastY, isWheel) {
374
- const deltaY = isWheel ? lastY * this.speed : ((lastY - this._startPosition.y) * this.speed);
375
- const lastPosY = this._mask.height - this._baseObject.height;
376
- const targetY = isWheel ? lastY : this._startY + deltaY
377
- return this._getValidatedY(targetY, lastPosY, deltaY);;
378
- }
379
-
380
- /**
381
- * Moves dragContainer
382
- * @param { Number } nextY
383
- * @param { Boolean } isWheel
384
- */
385
- _move(nextY, isWheel) {
386
- this._lastMoveTime = Date.now();
387
- this._onMoveCallback();
388
- const y = this._validateY(nextY, isWheel);
389
- this._setNewPosition(y);
390
- this._needMoveSlider && this._setSliderPosition(y);
391
- }
392
-
393
- /**
394
- * Calls given onMoveCallback if it's exists
395
- */
396
- _onMoveCallback() {
397
- this.onMoveCallback && this.onMoveCallback();
398
- }
399
-
400
- /**
401
- * Sets slider.
402
- */
403
- _setSlider() {
404
- if (!this.sliderClass)
405
- return
406
-
407
- this._slider = Urso.findOne(`.${this.sliderClass}`);
408
- }
409
-
410
- /**
411
- * Updates slider position alongside with dragged container.
412
- * @param { Number } y
413
- */
414
- _setSliderPosition(y) {
415
- if (!this._slider)
416
- return;
417
-
418
- const { height } = this.getAbsoluteSize();
419
- const positionCoefficient = Math.abs(y / (height - this.height));
420
- this._slider.setHandlePosition(positionCoefficient);
421
- }
422
-
423
- /**
424
- * Callback on move start.
425
- */
426
- _documentPointerStart() {
427
- this._startY = this._getCurrentY();
428
- this._moveStartY = this._getCurrentY();
429
- this._startTime = Date.now();
430
- this._movePossible = true;
431
- this._killTweens();
432
- }
433
-
434
- /**
435
- * Sets dragContainer validated position.
436
- * @param { Number } y
437
- */
438
- _setNewPosition(y) {
439
- this._baseObject.y = y;
440
- this._mask.y = -y;
441
- this._interactiveLayer.y = -y;
442
- this._currentPosition = y;
443
- }
444
-
445
- /**
446
- * Returns current container position.
447
- * @returns { Number }
448
- */
449
- _getCurrentY() {
450
- return this._baseObject.y;
451
- }
452
-
453
- /**
454
- * Moves container on wheel scroll.
455
- * @param { Object }
456
- */
457
- _documentWheelScroll({ x, y, deltaY }) {
458
- if (Urso.device.desktop) {
459
- x = Urso.scenes.getMouseCoords().x;
460
- y = Urso.scenes.getMouseCoords().y;
461
- }
462
-
463
- if (!this._isActive({ x, y }))
464
- return;
465
-
466
- this._isWheelMove = true;
467
-
468
- this._killTweens();
469
- const { x: startX, y: startY } = this._baseObject;
470
- this._startPosition = { x: startX, y: startY };
471
- this._moveStartY = this._getCurrentY();
472
- const nextY = startY - deltaY;
473
-
474
- this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SCROLL, { name: this.name, className: this.class, id: this.id });
475
-
476
- this._move(nextY, true);
477
- this._startMoveEasing();
478
- }
479
-
480
- /**
481
- * Drags container on pointer move.
482
- * @param { Object } event
483
- */
484
- _onPointerMove(event) {
485
- let { data: { global: { x, y } } } = event;
486
-
487
- if (!this._startPosition) {
488
- this._startPosition = { x, y };
489
- }
490
-
491
- if (!this._isActive({ x, y })) {
492
- this._moveInProgress = false;
493
- return;
494
- }
495
-
496
- this._wasMoved = true;
497
- this._move(y);
498
- }
499
-
500
- /**
501
- * Resizes mask according dragContainer size.
502
- */
503
- _resizeMask() {
504
- this._mask.width = this.width;
505
- this._mask.height = this.height;
506
- }
507
-
508
- /**
509
- * Resizes interactive layer according dragContainer size.
510
- */
511
- _resizeInteractiveLayer() {
512
- this._interactiveLayer.width = this.width;
513
- this._interactiveLayer.height = this.height;
514
- }
515
-
516
- /**
517
- * Creates a PIXI.Graphics rectangle which represents area in which we can interact with dragContainer.
518
- * @returns { Object }
519
- */
520
- _makeInteractiveLayer() {
521
- let layer = new PIXI.Graphics();
522
- layer.beginFill(0xffffff);
523
- layer.drawRect(0, 0, 1, 1);
524
- layer.endFill();
525
- layer.zIndex = this.zIndex;
526
- layer.alpha = 0;
527
- layer.visible = false;
528
- layer.interactive = true;
529
- return layer;
530
- }
531
-
532
- /**
533
- * Create PIXI.Graphics object that used as mask of dragContainer.
534
- * @returns { Object }
535
- */
536
- _makeMask() {
537
- let mask = new PIXI.Graphics();
538
- mask.lineStyle(0);
539
- mask.beginFill(0xffffff);
540
- mask.drawRect(0, 0, 1, 1);
541
- mask.endFill();
542
- return mask;
543
- }
544
-
545
- /**
546
- * Moves dragContainer via attached slider.
547
- * @param { Object }
548
- */
549
- _onScrollSliderMove({ position, class: className }) {
550
- if (className !== this.sliderClass)
551
- return
552
-
553
- if (this.height >= this._baseObject.height) {
554
- this._slider.setHandlePosition(0);
555
- return;
556
- }
557
-
558
- const { sliderSize } = this._slider;
559
- const containerHeight = this._mask.height - this._baseObject.height;
560
- const diffY = position > 0 ? position / sliderSize * containerHeight : 0;
561
-
562
- this._needMoveSlider = false;
563
- this._move(diffY, true)
564
- }
565
-
566
- /**
567
- * Callback on slider move end.
568
- * @param { Object }
569
- */
570
- _sliderHandleDrop({ class: className }) {
571
- if (className === this.sliderClass)
572
- this._needMoveSlider = true;
573
- }
574
-
575
- /**
576
- * function recieves object that contains an array of dragcontainer's names or ['*'] if we need block all dragContainers
577
- * @param { Object } blockParams
578
- */
579
- _switchBlock(blockParams) {
580
- if (!blockParams)
581
- return;
582
-
583
- const { names, needBlock } = blockParams;
584
-
585
- if (names.includes(this.name) || names.includes('*')) {
586
- this._needBlock = needBlock;
587
- }
588
- }
589
-
590
- /**
591
- * Checks if need to set slider. If no dragContainerName - slider will be set for all dragContainers.
592
- * @param {String} dragContainerName
593
- */
594
- _setSliderHandler(dragContainerName) {
595
- if (dragContainerName && dragContainerName !== this.name)
596
- return;
597
-
598
- this._setSlider();
599
- }
600
-
601
- /**
602
- * Sets callbacks on pointer events
603
- */
604
- _pointerEventsHandler(event) {
605
- switch (event.type) {
606
- case 'mousedown':
607
- this._moveStartedY = event.offsetY;
608
- this._documentPointerStart(event);
609
- break;
610
- case 'touchstart':
611
- this._offsetStartY = event.changedTouches[0].offsetY;
612
- this._moveStartedY = event.changedTouches[0].offsetY || event.changedTouches[0].clientY;
613
- this._documentPointerStart(event);
614
- break;
615
- case 'mousemove':
616
- case 'touchmove':
617
- this._documentPointerMove(event);
618
- break;
619
- case 'touchend':
620
- case 'mouseup':
621
- this._documentPointerEnd(event);
622
- break;
623
- case 'wheel':
624
- this._documentWheelScroll(event);
625
- break;
626
- default:
627
- break;
628
- }
629
- }
630
-
631
- /**
632
- * Resets last saved position of dragContainer on resolution change.
633
- */
634
- _onResolutionChange() {
635
- this._setNewPosition(this._currentPosition);
636
- }
637
-
638
- /**
639
- * Unsubscribes methods on object destroy.
640
- */
641
- _customDestroy() {
642
- this.removeListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
643
- this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
644
- this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
645
- this.removeListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
646
- this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
647
- this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
648
- this.removeListener(Urso.events.MODULES_SCENES_NEW_RESOLUTION, this._onResolutionChange);
649
- }
650
-
651
- /**
652
- * Subscribes methods.
653
- */
654
- _subscribeOnce() {
655
- this.addListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
656
- this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
657
- this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
658
- this.addListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
659
- this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
660
- this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
661
- this.addListener(Urso.events.MODULES_SCENES_NEW_RESOLUTION, this._onResolutionChange);
662
- }
663
- }
664
-
1
+ const ModulesObjectsModelsContainer = require('./container.js');
2
+ const containers = [];
3
+
4
+ class ModulesObjectsModelsDragContainer extends ModulesObjectsModelsContainer {
5
+ _mask = null;
6
+ _interactiveLayer = null;
7
+ _startPosition = null;
8
+ _startY = 0;
9
+ _offsetStartY = 0;
10
+ _needBlock = false;
11
+ _needMoveSlider = true;
12
+ _moveStartedY = 0;
13
+ _dragStarted = false;
14
+ _minMoveDurationForEasing = 100;
15
+ _minMoveDistanceForEasing = 50;
16
+ _minMoveDistance = 15;
17
+ _currentPosition = 0;
18
+
19
+ constructor(params) {
20
+ super(params);
21
+
22
+ this.type = Urso.types.objects.DRAGCONTAINER;
23
+
24
+ this._onScrollSliderMove = this._onScrollSliderMove.bind(this);
25
+ this._sliderHandleDrop = this._sliderHandleDrop.bind(this);
26
+ this._setSliderHandler = this._setSliderHandler.bind(this);
27
+ this._switchBlock = this._switchBlock.bind(this);
28
+ this._pointerEventsHandler = this._pointerEventsHandler.bind(this);
29
+ this._onResolutionChange = this._onResolutionChange.bind(this);
30
+
31
+ this._setupDragContainer();
32
+ containers.push(this);
33
+ }
34
+
35
+ /**
36
+ * Setups initial params on create.
37
+ * @param { Object } params
38
+ */
39
+ setupParams(params) {
40
+ super.setupParams(params);
41
+ this.speed = Urso.helper.recursiveGet('speed', params, 1);
42
+ this.dragIndex = Urso.helper.recursiveGet('dragIndex', params, 0);
43
+ this.sliderClass = Urso.helper.recursiveGet('sliderClass', params, false);
44
+ this.onMoveCallback = Urso.helper.recursiveGet('onMoveCallback', params, false);
45
+ this.easingTime = Urso.helper.recursiveGet('easingTime', params, 1.5);
46
+ this.easingDistance = Urso.helper.recursiveGet('easingDistance', params, 200);
47
+ this.zIndex = Urso.helper.recursiveGet('zIndex', params, 10);
48
+ this.width = Urso.helper.recursiveGet('width', params, 200); // Width of container visible area. Numbers only.
49
+ this.height = Urso.helper.recursiveGet('height', params, 200); // Height of container visible area. Numbers only.
50
+ }
51
+
52
+ /**
53
+ * Checks if interactive layer is visible and move in progress.
54
+ * @returns { Boolean }
55
+ */
56
+ get _moveInProgress() {
57
+ return this._interactiveLayer.visible
58
+ }
59
+
60
+ /**
61
+ * Sets interactiveLayer visibility.
62
+ */
63
+ set _moveInProgress(inProgress) {
64
+ this._interactiveLayer.visible = inProgress;
65
+ }
66
+
67
+ /**
68
+ * Resizes mask and interactiveLayer according dragContainer size
69
+ * @param { Boolean } needResetMaskY
70
+ */
71
+ resize(needResetMaskY) {
72
+ this._resizeInteractiveLayer();
73
+ this._resizeMask();
74
+
75
+ if (needResetMaskY) {
76
+ this._mask.y = 0;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Initial setup dragContainers params.
82
+ */
83
+ _setupDragContainer() {
84
+ this._setMask();
85
+ this._resizeInteractiveLayer();
86
+ this._resizeMask();
87
+ this._setResizeReactively();
88
+ this._currentPosition = this._baseObject.y;
89
+ }
90
+
91
+ /**
92
+ * Subscribes resize() method on dragContauber width/height params change
93
+ */
94
+ _setResizeReactively() {
95
+ Urso.helper.reactive(this, 'width', () => this.resize());
96
+ Urso.helper.reactive(this, 'height', () => this.resize());
97
+ }
98
+
99
+ /**
100
+ * Setups mask and interactive layer of dragContainer
101
+ */
102
+ _setMask() {
103
+ this._mask = this._makeMask();
104
+
105
+ this._interactiveLayer = this._makeInteractiveLayer();
106
+ this._interactiveLayer.on('pointermove', (e) => this._onPointerMove(e));
107
+
108
+ this._baseObject.addChild(this._mask);
109
+ this._baseObject.addChild(this._interactiveLayer);
110
+
111
+ this._baseObject.mask = this._mask;
112
+ }
113
+
114
+ /**
115
+ * Function takes pointer coords and checks if pointer over current dragContainer.
116
+ * @param { Object } coords
117
+ * @returns { Boolean }
118
+ */
119
+ _isActive({ x, y }) {
120
+ const pointerOverContainers = containers
121
+ .filter((container) => {
122
+ const points = this._getObjectPoints(container);
123
+ return this._checkPointerOver({ x, y }, ...points);
124
+ })
125
+ .filter((container) => container._baseObject.worldVisible)
126
+ .filter((container) => !container._needBlock)
127
+ .filter((container) => {
128
+ const height = container.getAbsoluteSize().height;
129
+ return container.height - height < 0;
130
+ })
131
+ .sort((firstContainer, secondContainer) => secondContainer.dragIndex - firstContainer.dragIndex);
132
+
133
+ return pointerOverContainers[0] === this;
134
+ }
135
+
136
+ /**
137
+ * Hides attached slider if dragContainer cannot be scrolled
138
+ */
139
+ _changeSliderVisibility() {
140
+ if (!this._slider)
141
+ return;
142
+
143
+ this._slider.visible = this.height < this._baseObject.height;
144
+ }
145
+
146
+ /**
147
+ * Function takes pointer coords and coords of the two container's vertexes
148
+ * returns relative position of pointer between two points
149
+ * @param { Object } pointerCoords
150
+ * @param { Object } point1
151
+ * @param { Object } point2
152
+ * @returns { Number }
153
+ */
154
+ _getPointerRelativePosition(pointerCoords, point1, point2) {
155
+ const xDelta = point2.x - point1.x;
156
+ const yDelta = point2.y - point1.y;
157
+ const poiterDeltaY = pointerCoords.y - point1.y;
158
+ const poiterDeltaX = pointerCoords.x - point1.x;
159
+ return xDelta * poiterDeltaY - yDelta * poiterDeltaX;
160
+ }
161
+
162
+ /**
163
+ * Takes pointer coords and dragContainer vertexes coords.
164
+ * Checks if pointer is inside dragContainer rectangle.
165
+ * @param { Object } pointerCoords
166
+ * @param { Object } pointA
167
+ * @param { Object } pointB
168
+ * @param { Object } pointC
169
+ * @param { Object } pointD
170
+ * @returns { Boolean }
171
+ */
172
+ _checkPointerOver(pointerCoords, pointA, pointB, pointC, pointD) {
173
+ const point1 = this._getPointerRelativePosition(pointerCoords, pointA, pointB);
174
+ const point2 = this._getPointerRelativePosition(pointerCoords, pointB, pointC);
175
+ const point3 = this._getPointerRelativePosition(pointerCoords, pointC, pointD);
176
+ const point4 = this._getPointerRelativePosition(pointerCoords, pointD, pointA);
177
+ return (point1 < 0 && point2 < 0 && point3 < 0 && point4 < 0) || (point1 > 0 && point2 > 0 && point3 > 0 && point4 > 0);
178
+ }
179
+
180
+ /**
181
+ * Function takes container object and calculate it's vertexes coords.
182
+ * Returns array of coords.
183
+ * @param { Object } container
184
+ * @returns { Array }
185
+ */
186
+ _getObjectPoints(container) {
187
+ const { x, y } = container._mask.toGlobal(new PIXI.Point(0, 0));
188
+
189
+ const { width, height } = container._mask;
190
+ const { scaleX, scaleY } = this._getScaleAndPositionRecursive(this);
191
+
192
+ return [
193
+ { x, y },
194
+ { x: x + width * scaleX, y },
195
+ { x: x + width * scaleX, y: y + height * scaleY },
196
+ { x, y: y + height * scaleY }
197
+ ];
198
+ }
199
+
200
+ /**
201
+ * Function takes dragContainer object and recurcievly calculates it's global scale and position
202
+ * @param { Object }
203
+ * @returns { Object }
204
+ */
205
+ _getScaleAndPositionRecursive({ scaleX, scaleY, parent, x, y }) {
206
+ if (!parent) {
207
+ return { scaleX, scaleY, x, y };
208
+ }
209
+
210
+ const { scaleX: parentScaleX, scaleY: parentScaleY, x: parentX, y: parentY } = this._getScaleAndPositionRecursive(parent);
211
+
212
+ return {
213
+ scaleX: scaleX * parentScaleX,
214
+ scaleY: scaleY * parentScaleY,
215
+ x: x + parentX,
216
+ y: y + parentY,
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Callback on pointer move. Takes pointer event data.
222
+ * @param { Object } e
223
+ */
224
+ _documentPointerMove(e) {
225
+ if(!this._movePossible)
226
+ return;
227
+
228
+ this._moveInProgress = true;
229
+
230
+ const offset = e.offsetY ?? e.changedTouches[0].changedOffsetY ?? e.changedTouches[0].clientY ?? 0;
231
+
232
+ if (Math.abs(this._moveStartedY - offset) > this._minMoveDistance && !this._dragStarted) {
233
+ this._dragStarted = true;
234
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_STARTED, { name: this.name, className: this.class, id: this.id });
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Callback on move end. Unblock all dragContainers and if move was longer than requred minimum starts easing
240
+ */
241
+ _documentPointerEnd() {
242
+ this._movePossible = false;
243
+ const timeDelta = Date.now() - this._lastMoveTime;
244
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, { names: ['*'], needBlock: false });
245
+
246
+ if (this._wasMoved && timeDelta < this._minMoveDurationForEasing)
247
+ this._startMoveEasing();
248
+ else
249
+ this._startPosition = null;
250
+
251
+ this._onMoveComplete();
252
+ this._wasMoved = false;
253
+ }
254
+
255
+ /**
256
+ * Starts easing animation in the end of move
257
+ */
258
+ _startMoveEasing() {
259
+ const targetY = this._getEasingTargetY();
260
+
261
+ if (!targetY) {
262
+ this._startPosition = null;
263
+ return
264
+ };
265
+
266
+ let obj = { y: this._baseObject.y };
267
+
268
+ this._easingTween = gsap.to(obj, this.easingTime, {
269
+ y: targetY, ease: 'power2',
270
+ onUpdate: () => {
271
+ this._move(obj.y, true);
272
+ this._isBorder && this._killTweens();
273
+ },
274
+ onComplete: () => {
275
+ this._startPosition = null;
276
+ }
277
+ })
278
+ }
279
+
280
+ /**
281
+ * Kills al animation tweens
282
+ */
283
+ _killTweens() {
284
+ if (this._easingTween) {
285
+ this._easingTween.pause();
286
+ this._easingTween.kill(true);
287
+ this._easingTween = null;
288
+ this._startPosition = null;
289
+ };
290
+ }
291
+
292
+ /**
293
+ * Calculates target move coordinate of easing
294
+ * @returns { Number }
295
+ */
296
+ _getEasingTargetY() {
297
+ const multipler = this._moveStartY > this._baseObject.y ? -1 : 1;
298
+
299
+ if (Math.abs(this._moveStartY - this._baseObject.y) < this._minMoveDistanceForEasing)
300
+ return false;
301
+
302
+ return this._baseObject.y + this.easingDistance * multipler;
303
+ }
304
+
305
+ /**
306
+ * Resets params on move callback
307
+ */
308
+ _onMoveComplete() {
309
+ this._moveInProgress = false;
310
+ this._dragStarted = false;
311
+ this._isWheelMove = false;
312
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_DRAG_FINISHED, { name: this.name, className: this.class, id: this.id });
313
+ this._isBorder = false;
314
+ }
315
+
316
+ /**
317
+ * Checks if next dragContainer Y coordinate is in possible range.
318
+ * If it's out of possible range returns nearest possible point.
319
+ * @param { Number } y
320
+ * @param { Number } lastPosY
321
+ * @param { Number } deltaY
322
+ * @returns { Number }
323
+ */
324
+ _getValidatedY(y, lastPosY, deltaY) {
325
+ if (y > 0) {
326
+ this._startY = -deltaY;
327
+ y = 0;
328
+ }
329
+
330
+ if (lastPosY > y) {
331
+ this._startY = lastPosY - deltaY;
332
+ this._isBorder = true;
333
+ y = lastPosY;
334
+ }
335
+
336
+ const possibleMinY = this.height - this._calcMaxY(this._baseObject);
337
+
338
+ if (y < possibleMinY) {
339
+ y = possibleMinY;
340
+ this._isBorder = true
341
+ }
342
+
343
+ return y;
344
+ }
345
+
346
+ /**
347
+ * Calculates max possible dragContainer Y
348
+ * @param { Object } pixiObject
349
+ * @returns { Number }
350
+ */
351
+ _calcMaxY(pixiObject) {
352
+ let maxY = 0;
353
+
354
+ pixiObject.children.forEach(element => {
355
+ if (element.isMask)
356
+ return;
357
+
358
+ const elementLimit = element.y + element.height;
359
+
360
+ if (elementLimit > maxY)
361
+ maxY = elementLimit;
362
+ });
363
+
364
+ return maxY;
365
+ }
366
+
367
+ /**
368
+ * Validates next dragContainer position.
369
+ * @param { Number } lastY
370
+ * @param { Boolean } isWheel
371
+ * @returns { Number }
372
+ */
373
+ _validateY(lastY, isWheel) {
374
+ const deltaY = isWheel ? lastY * this.speed : ((lastY - this._startPosition.y) * this.speed);
375
+ const lastPosY = this._mask.height - this._baseObject.height;
376
+ const targetY = isWheel ? lastY : this._startY + deltaY
377
+ return this._getValidatedY(targetY, lastPosY, deltaY);;
378
+ }
379
+
380
+ /**
381
+ * Moves dragContainer
382
+ * @param { Number } nextY
383
+ * @param { Boolean } isWheel
384
+ */
385
+ _move(nextY, isWheel) {
386
+ this._lastMoveTime = Date.now();
387
+ this._onMoveCallback();
388
+ const y = this._validateY(nextY, isWheel);
389
+ this._setNewPosition(y);
390
+ this._needMoveSlider && this._setSliderPosition(y);
391
+ }
392
+
393
+ /**
394
+ * Calls given onMoveCallback if it's exists
395
+ */
396
+ _onMoveCallback() {
397
+ this.onMoveCallback && this.onMoveCallback();
398
+ }
399
+
400
+ /**
401
+ * Sets slider.
402
+ */
403
+ _setSlider() {
404
+ if (!this.sliderClass)
405
+ return
406
+
407
+ this._slider = Urso.findOne(`.${this.sliderClass}`);
408
+ }
409
+
410
+ /**
411
+ * Updates slider position alongside with dragged container.
412
+ * @param { Number } y
413
+ */
414
+ _setSliderPosition(y) {
415
+ if (!this._slider)
416
+ return;
417
+
418
+ const { height } = this.getAbsoluteSize();
419
+ const positionCoefficient = Math.abs(y / (height - this.height));
420
+ this._slider.setHandlePosition(positionCoefficient);
421
+ }
422
+
423
+ /**
424
+ * Callback on move start.
425
+ */
426
+ _documentPointerStart() {
427
+ this._startY = this._getCurrentY();
428
+ this._moveStartY = this._getCurrentY();
429
+ this._startTime = Date.now();
430
+ this._movePossible = true;
431
+ this._killTweens();
432
+ }
433
+
434
+ /**
435
+ * Sets dragContainer validated position.
436
+ * @param { Number } y
437
+ */
438
+ _setNewPosition(y) {
439
+ this._baseObject.y = y;
440
+ this._mask.y = -y;
441
+ this._interactiveLayer.y = -y;
442
+ this._currentPosition = y;
443
+ }
444
+
445
+ /**
446
+ * Returns current container position.
447
+ * @returns { Number }
448
+ */
449
+ _getCurrentY() {
450
+ return this._baseObject.y;
451
+ }
452
+
453
+ /**
454
+ * Moves container on wheel scroll.
455
+ * @param { Object }
456
+ */
457
+ _documentWheelScroll({ x, y, deltaY }) {
458
+ if (Urso.device.desktop) {
459
+ x = Urso.scenes.getMouseCoords().x;
460
+ y = Urso.scenes.getMouseCoords().y;
461
+ }
462
+
463
+ if (!this._isActive({ x, y }))
464
+ return;
465
+
466
+ this._isWheelMove = true;
467
+
468
+ this._killTweens();
469
+ const { x: startX, y: startY } = this._baseObject;
470
+ this._startPosition = { x: startX, y: startY };
471
+ this._moveStartY = this._getCurrentY();
472
+ const nextY = startY - deltaY;
473
+
474
+ this.emit(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SCROLL, { name: this.name, className: this.class, id: this.id });
475
+
476
+ this._move(nextY, true);
477
+ this._startMoveEasing();
478
+ }
479
+
480
+ /**
481
+ * Drags container on pointer move.
482
+ * @param { Object } event
483
+ */
484
+ _onPointerMove(event) {
485
+ let { data: { global: { x, y } } } = event;
486
+
487
+ if (!this._startPosition) {
488
+ this._startPosition = { x, y };
489
+ }
490
+
491
+ if (!this._isActive({ x, y })) {
492
+ this._moveInProgress = false;
493
+ return;
494
+ }
495
+
496
+ this._wasMoved = true;
497
+ this._move(y);
498
+ }
499
+
500
+ /**
501
+ * Resizes mask according dragContainer size.
502
+ */
503
+ _resizeMask() {
504
+ this._mask.width = this.width;
505
+ this._mask.height = this.height;
506
+ }
507
+
508
+ /**
509
+ * Resizes interactive layer according dragContainer size.
510
+ */
511
+ _resizeInteractiveLayer() {
512
+ this._interactiveLayer.width = this.width;
513
+ this._interactiveLayer.height = this.height;
514
+ }
515
+
516
+ /**
517
+ * Creates a PIXI.Graphics rectangle which represents area in which we can interact with dragContainer.
518
+ * @returns { Object }
519
+ */
520
+ _makeInteractiveLayer() {
521
+ let layer = new PIXI.Graphics();
522
+ layer.beginFill(0xffffff);
523
+ layer.drawRect(0, 0, 1, 1);
524
+ layer.endFill();
525
+ layer.zIndex = this.zIndex;
526
+ layer.alpha = 0;
527
+ layer.visible = false;
528
+ layer.interactive = true;
529
+ return layer;
530
+ }
531
+
532
+ /**
533
+ * Create PIXI.Graphics object that used as mask of dragContainer.
534
+ * @returns { Object }
535
+ */
536
+ _makeMask() {
537
+ let mask = new PIXI.Graphics();
538
+ mask.lineStyle(0);
539
+ mask.beginFill(0xffffff);
540
+ mask.drawRect(0, 0, 1, 1);
541
+ mask.endFill();
542
+ return mask;
543
+ }
544
+
545
+ /**
546
+ * Moves dragContainer via attached slider.
547
+ * @param { Object }
548
+ */
549
+ _onScrollSliderMove({ position, class: className }) {
550
+ if (className !== this.sliderClass)
551
+ return
552
+
553
+ if (this.height >= this._baseObject.height) {
554
+ this._slider.setHandlePosition(0);
555
+ return;
556
+ }
557
+
558
+ const { sliderSize } = this._slider;
559
+ const containerHeight = this._mask.height - this._baseObject.height;
560
+ const diffY = position > 0 ? position / sliderSize * containerHeight : 0;
561
+
562
+ this._needMoveSlider = false;
563
+ this._move(diffY, true)
564
+ }
565
+
566
+ /**
567
+ * Callback on slider move end.
568
+ * @param { Object }
569
+ */
570
+ _sliderHandleDrop({ class: className }) {
571
+ if (className === this.sliderClass)
572
+ this._needMoveSlider = true;
573
+ }
574
+
575
+ /**
576
+ * function recieves object that contains an array of dragcontainer's names or ['*'] if we need block all dragContainers
577
+ * @param { Object } blockParams
578
+ */
579
+ _switchBlock(blockParams) {
580
+ if (!blockParams)
581
+ return;
582
+
583
+ const { names, needBlock } = blockParams;
584
+
585
+ if (names.includes(this.name) || names.includes('*')) {
586
+ this._needBlock = needBlock;
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Checks if need to set slider. If no dragContainerName - slider will be set for all dragContainers.
592
+ * @param {String} dragContainerName
593
+ */
594
+ _setSliderHandler(dragContainerName) {
595
+ if (dragContainerName && dragContainerName !== this.name)
596
+ return;
597
+
598
+ this._setSlider();
599
+ }
600
+
601
+ /**
602
+ * Sets callbacks on pointer events
603
+ */
604
+ _pointerEventsHandler(event) {
605
+ switch (event.type) {
606
+ case 'mousedown':
607
+ this._moveStartedY = event.offsetY;
608
+ this._documentPointerStart(event);
609
+ break;
610
+ case 'touchstart':
611
+ this._offsetStartY = event.changedTouches[0].offsetY;
612
+ this._moveStartedY = event.changedTouches[0].offsetY || event.changedTouches[0].clientY;
613
+ this._documentPointerStart(event);
614
+ break;
615
+ case 'mousemove':
616
+ case 'touchmove':
617
+ this._documentPointerMove(event);
618
+ break;
619
+ case 'touchend':
620
+ case 'mouseup':
621
+ this._documentPointerEnd(event);
622
+ break;
623
+ case 'wheel':
624
+ this._documentWheelScroll(event);
625
+ break;
626
+ default:
627
+ break;
628
+ }
629
+ }
630
+
631
+ /**
632
+ * Resets last saved position of dragContainer on resolution change.
633
+ */
634
+ _onResolutionChange() {
635
+ this._setNewPosition(this._currentPosition);
636
+ }
637
+
638
+ /**
639
+ * Unsubscribes methods on object destroy.
640
+ */
641
+ _customDestroy() {
642
+ this.removeListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
643
+ this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
644
+ this.removeListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
645
+ this.removeListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
646
+ this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
647
+ this.removeListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
648
+ this.removeListener(Urso.events.MODULES_SCENES_NEW_RESOLUTION, this._onResolutionChange);
649
+ }
650
+
651
+ /**
652
+ * Subscribes methods.
653
+ */
654
+ _subscribeOnce() {
655
+ this.addListener(Urso.events.EXTRA_BROWSEREVENTS_POINTER_EVENT, this._pointerEventsHandler);
656
+ this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, this._onScrollSliderMove);
657
+ this.addListener(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, this._sliderHandleDrop);
658
+ this.addListener(Urso.events.MODULES_SCENES_DISPLAY_FINISHED, this._setSliderHandler);
659
+ this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SETSLIDER, this._setSliderHandler);
660
+ this.addListener(Urso.events.MODULES_OBJECTS_DRAGCONTAINER_SWITCHBLOCK, this._switchBlock);
661
+ this.addListener(Urso.events.MODULES_SCENES_NEW_RESOLUTION, this._onResolutionChange);
662
+ }
663
+ }
664
+
665
665
  module.exports = ModulesObjectsModelsDragContainer;