pixi-scrollbox 2.3.1 → 3.0.0

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.
@@ -1,859 +0,0 @@
1
- import * as PIXI from 'pixi.js';
2
- import { Viewport } from 'pixi-viewport';
3
-
4
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5
-
6
- function createCommonjsModule(fn) {
7
- var module = { exports: {} };
8
- return fn(module, module.exports), module.exports;
9
- }
10
-
11
- var penner = createCommonjsModule(function (module, exports) {
12
- /*
13
- Copyright © 2001 Robert Penner
14
- All rights reserved.
15
-
16
- Redistribution and use in source and binary forms, with or without modification,
17
- are permitted provided that the following conditions are met:
18
-
19
- Redistributions of source code must retain the above copyright notice, this list of
20
- conditions and the following disclaimer.
21
- Redistributions in binary form must reproduce the above copyright notice, this list
22
- of conditions and the following disclaimer in the documentation and/or other materials
23
- provided with the distribution.
24
-
25
- Neither the name of the author nor the names of contributors may be used to endorse
26
- or promote products derived from this software without specific prior written permission.
27
-
28
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
29
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34
- AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36
- OF THE POSSIBILITY OF SUCH DAMAGE.
37
- */
38
-
39
- (function() {
40
- var penner, umd;
41
-
42
- umd = function(factory) {
43
- {
44
- return module.exports = factory;
45
- }
46
- };
47
-
48
- penner = {
49
- linear: function(t, b, c, d) {
50
- return c * t / d + b;
51
- },
52
- easeInQuad: function(t, b, c, d) {
53
- return c * (t /= d) * t + b;
54
- },
55
- easeOutQuad: function(t, b, c, d) {
56
- return -c * (t /= d) * (t - 2) + b;
57
- },
58
- easeInOutQuad: function(t, b, c, d) {
59
- if ((t /= d / 2) < 1) {
60
- return c / 2 * t * t + b;
61
- } else {
62
- return -c / 2 * ((--t) * (t - 2) - 1) + b;
63
- }
64
- },
65
- easeInCubic: function(t, b, c, d) {
66
- return c * (t /= d) * t * t + b;
67
- },
68
- easeOutCubic: function(t, b, c, d) {
69
- return c * ((t = t / d - 1) * t * t + 1) + b;
70
- },
71
- easeInOutCubic: function(t, b, c, d) {
72
- if ((t /= d / 2) < 1) {
73
- return c / 2 * t * t * t + b;
74
- } else {
75
- return c / 2 * ((t -= 2) * t * t + 2) + b;
76
- }
77
- },
78
- easeInQuart: function(t, b, c, d) {
79
- return c * (t /= d) * t * t * t + b;
80
- },
81
- easeOutQuart: function(t, b, c, d) {
82
- return -c * ((t = t / d - 1) * t * t * t - 1) + b;
83
- },
84
- easeInOutQuart: function(t, b, c, d) {
85
- if ((t /= d / 2) < 1) {
86
- return c / 2 * t * t * t * t + b;
87
- } else {
88
- return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
89
- }
90
- },
91
- easeInQuint: function(t, b, c, d) {
92
- return c * (t /= d) * t * t * t * t + b;
93
- },
94
- easeOutQuint: function(t, b, c, d) {
95
- return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
96
- },
97
- easeInOutQuint: function(t, b, c, d) {
98
- if ((t /= d / 2) < 1) {
99
- return c / 2 * t * t * t * t * t + b;
100
- } else {
101
- return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
102
- }
103
- },
104
- easeInSine: function(t, b, c, d) {
105
- return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
106
- },
107
- easeOutSine: function(t, b, c, d) {
108
- return c * Math.sin(t / d * (Math.PI / 2)) + b;
109
- },
110
- easeInOutSine: function(t, b, c, d) {
111
- return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
112
- },
113
- easeInExpo: function(t, b, c, d) {
114
- if (t === 0) {
115
- return b;
116
- } else {
117
- return c * Math.pow(2, 10 * (t / d - 1)) + b;
118
- }
119
- },
120
- easeOutExpo: function(t, b, c, d) {
121
- if (t === d) {
122
- return b + c;
123
- } else {
124
- return c * (-Math.pow(2, -10 * t / d) + 1) + b;
125
- }
126
- },
127
- easeInOutExpo: function(t, b, c, d) {
128
- if ((t /= d / 2) < 1) {
129
- return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
130
- } else {
131
- return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
132
- }
133
- },
134
- easeInCirc: function(t, b, c, d) {
135
- return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
136
- },
137
- easeOutCirc: function(t, b, c, d) {
138
- return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
139
- },
140
- easeInOutCirc: function(t, b, c, d) {
141
- if ((t /= d / 2) < 1) {
142
- return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
143
- } else {
144
- return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
145
- }
146
- },
147
- easeInElastic: function(t, b, c, d) {
148
- var a, p, s;
149
- s = 1.70158;
150
- p = 0;
151
- a = c;
152
- if (t === 0) ; else if ((t /= d) === 1) ;
153
- if (!p) {
154
- p = d * .3;
155
- }
156
- if (a < Math.abs(c)) {
157
- a = c;
158
- s = p / 4;
159
- } else {
160
- s = p / (2 * Math.PI) * Math.asin(c / a);
161
- }
162
- return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
163
- },
164
- easeOutElastic: function(t, b, c, d) {
165
- var a, p, s;
166
- s = 1.70158;
167
- p = 0;
168
- a = c;
169
- if (t === 0) ; else if ((t /= d) === 1) ;
170
- if (!p) {
171
- p = d * .3;
172
- }
173
- if (a < Math.abs(c)) {
174
- a = c;
175
- s = p / 4;
176
- } else {
177
- s = p / (2 * Math.PI) * Math.asin(c / a);
178
- }
179
- return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
180
- },
181
- easeInOutElastic: function(t, b, c, d) {
182
- var a, p, s;
183
- s = 1.70158;
184
- p = 0;
185
- a = c;
186
- if (t === 0) ; else if ((t /= d / 2) === 2) ;
187
- if (!p) {
188
- p = d * (.3 * 1.5);
189
- }
190
- if (a < Math.abs(c)) {
191
- a = c;
192
- s = p / 4;
193
- } else {
194
- s = p / (2 * Math.PI) * Math.asin(c / a);
195
- }
196
- if (t < 1) {
197
- return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
198
- } else {
199
- return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
200
- }
201
- },
202
- easeInBack: function(t, b, c, d, s) {
203
- if (s === void 0) {
204
- s = 1.70158;
205
- }
206
- return c * (t /= d) * t * ((s + 1) * t - s) + b;
207
- },
208
- easeOutBack: function(t, b, c, d, s) {
209
- if (s === void 0) {
210
- s = 1.70158;
211
- }
212
- return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
213
- },
214
- easeInOutBack: function(t, b, c, d, s) {
215
- if (s === void 0) {
216
- s = 1.70158;
217
- }
218
- if ((t /= d / 2) < 1) {
219
- return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
220
- } else {
221
- return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
222
- }
223
- },
224
- easeInBounce: function(t, b, c, d) {
225
- var v;
226
- v = penner.easeOutBounce(d - t, 0, c, d);
227
- return c - v + b;
228
- },
229
- easeOutBounce: function(t, b, c, d) {
230
- if ((t /= d) < 1 / 2.75) {
231
- return c * (7.5625 * t * t) + b;
232
- } else if (t < 2 / 2.75) {
233
- return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b;
234
- } else if (t < 2.5 / 2.75) {
235
- return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b;
236
- } else {
237
- return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b;
238
- }
239
- },
240
- easeInOutBounce: function(t, b, c, d) {
241
- var v;
242
- if (t < d / 2) {
243
- v = penner.easeInBounce(t * 2, 0, c, d);
244
- return v * .5 + b;
245
- } else {
246
- v = penner.easeOutBounce(t * 2 - d, 0, c, d);
247
- return v * .5 + c * .5 + b;
248
- }
249
- }
250
- };
251
-
252
- umd(penner);
253
-
254
- }).call(commonjsGlobal);
255
- });
256
-
257
- const scrollboxOptions = {
258
- 'boxWidth': 100,
259
- 'boxHeight': 100,
260
- 'scrollbarSize': 10,
261
- 'scrollbarBackground': 14540253,
262
- 'scrollbarBackgroundAlpha': 1,
263
- 'scrollbarForeground': 8947848,
264
- 'scrollbarForegroundAlpha': 1,
265
- 'dragScroll': true,
266
- 'stopPropagation': true,
267
- 'scrollbarOffsetHorizontal': 0,
268
- 'scrollbarOffsetVertical': 0,
269
- 'underflow': 'top-left',
270
- 'fadeScrollbar': false,
271
- 'fadeScrollbarTime': 1000,
272
- 'fadeScrollboxWait': 3000,
273
- 'fadeScrollboxEase': 'easeInOutSine',
274
- 'passiveWheel': false,
275
- 'clampWheel': true
276
- };
277
-
278
- /**
279
- * pixi.js scrollbox: a masked content box that can scroll vertically or horizontally with scrollbars
280
- */
281
- class Scrollbox extends PIXI.Container {
282
- /**
283
- * create a scrollbox
284
- * @param {object} options
285
- * @param {boolean} [options.dragScroll=true] user may drag the content area to scroll content
286
- * @param {string} [options.overflowX=auto] (none, scroll, hidden, auto) this changes whether the scrollbar is shown
287
- * @param {string} [options.overflowY=auto] (none, scroll, hidden, auto) this changes whether the scrollbar is shown
288
- * @param {string} [options.overflow] (none, scroll, hidden, auto) sets overflowX and overflowY to this value
289
- * @param {number} [options.boxWidth=100] width of scrollbox including scrollbar (in pixels)
290
- * @param {number} [options.boxHeight=100] height of scrollbox including scrollbar (in pixels)
291
- * @param {number} [options.scrollbarSize=10] size of scrollbar (in pixels)
292
- * @param {number} [options.scrollbarOffsetHorizontal=0] offset of horizontal scrollbar (in pixels)
293
- * @param {number} [options.scrollbarOffsetVertical=0] offset of vertical scrollbar (in pixels)
294
- * @param {boolean} [options.stopPropagation=true] call stopPropagation on any events that impact scrollbox
295
- * @param {number} [options.scrollbarBackground=0xdddddd] background color of scrollbar
296
- * @param {number} [options.scrollbarBackgroundAlpha=1] alpha of background of scrollbar
297
- * @param {number} [options.scrollbarForeground=0x888888] foreground color of scrollbar
298
- * @param {number} [options.scrollbarForegroundAlpha=1] alpha of foreground of scrollbar
299
- * @param {string} [options.underflow=top-left] what to do when content underflows the scrollbox size: none: do nothing; (left/right/center AND top/bottom/center); OR center (e.g., 'top-left', 'center', 'none', 'bottomright')
300
- * @param {boolean} [options.noTicker] do not use PIXI.Ticker (for fade to work properly you will need to manually call updateLoop(elapsed) on each frame)
301
- * @param {PIXI.Ticker} [options.ticker=PIXI.Ticker.shared] use this PIXI.Ticker for updates
302
- * @param {boolean} [options.fade] fade the scrollbar when not in use
303
- * @param {number} [options.fadeScrollbarTime=1000] time to fade scrollbar if options.fade is set
304
- * @param {number} [options.fadeScrollboxWait=3000] time to wait before fading the scrollbar if options.fade is set
305
- * @param {(string|function)} [options.fadeScrollboxEase=easeInOutSine] easing function to use for fading
306
- * @param {boolean} [options.passiveWheel=false] whether wheel events are propogated beyond the scrollbox (NOTE: default is now false)
307
- * @param {boolean} [options.clampWheel=true] wheel events should be clamped (to avoid weird bounce with mouse wheel)
308
- * @param {PIXI.InteractionManager} [options.interaction] InteractionManager, available from instantiated PIXI.Renderer.plugins.interaction - used to calculate pointer postion relative to canvas location on screen
309
- * @param {HTMLElement} [options.divWheel] the HTMLElement to use for wheel interactions
310
- */
311
- constructor(options = {}) {
312
- super();
313
- this.options = Object.assign({}, scrollboxOptions, options);
314
- if (options.overflow) {
315
- this.options.overflowX = this.options.overflowY = options.overflow;
316
- }
317
- this.ease = typeof this.options.fadeScrollboxEase === 'function' ? this.options.fadeScrollboxEase : penner[this.options.fadeScrollboxEase];
318
-
319
- /**
320
- * content in placed in here
321
- * you can use any function from pixi-viewport on content to manually move the content (see https://davidfig.github.io/pixi-viewport/jsdoc/)
322
- * @type {Viewport}
323
- */
324
- this.content = this.addChild(new Viewport({
325
- passiveWheel: false,
326
- stopPropagation: this.options.stopPropagation,
327
- screenWidth: this.options.boxWidth,
328
- screenHeight: this.options.boxHeight,
329
- interaction: this.options.interaction,
330
- divWheel: this.options.divWheel,
331
- }));
332
- this.content
333
- .decelerate()
334
- .on('moved', () => this._drawScrollbars());
335
-
336
- // needed to pull this out of viewportOptions because of pixi.js v4 support (which changed from PIXI.ticker.shared to PIXI.Ticker.shared...sigh)
337
- if (options.ticker) {
338
- this.options.ticker = options.ticker;
339
- }
340
- else {
341
- // to avoid Rollup transforming our import, save pixi namespace in a variable
342
- // from here: https://github.com/pixijs/pixi.js/issues/5757
343
- let ticker;
344
- const pixiNS = PIXI;
345
- if (parseInt(/^(\d+)\./.exec(PIXI.VERSION)[1]) < 5) {
346
- ticker = pixiNS.ticker.shared;
347
- }
348
- else {
349
- ticker = pixiNS.Ticker.shared;
350
- }
351
- this.options.ticker = options.ticker || ticker;
352
- }
353
-
354
- /**
355
- * graphics element for drawing the scrollbars
356
- * @type {PIXI.Graphics}
357
- */
358
- this.scrollbar = this.addChild(new PIXI.Graphics());
359
- this.scrollbar.interactive = true;
360
- this.scrollbar.on('pointerdown', this.scrollbarDown, this);
361
- this.interactive = true;
362
- this.on('pointermove', this.scrollbarMove, this);
363
- this.on('pointerup', this.scrollbarUp, this);
364
- this.on('pointercancel', this.scrollbarUp, this);
365
- this.on('pointerupoutside', this.scrollbarUp, this);
366
- this._maskContent = this.addChild(new PIXI.Graphics());
367
- this.update();
368
-
369
- if (!this.options.noTicker) {
370
- this.tickerFunction = () => this.updateLoop(Math.min(this.options.ticker.elapsedMS, 16.6667));
371
- this.options.ticker.add(this.tickerFunction);
372
- }
373
- }
374
-
375
- /**
376
- * offset of horizontal scrollbar (in pixels)
377
- * @type {number}
378
- */
379
- get scrollbarOffsetHorizontal() {
380
- return this.options.scrollbarOffsetHorizontal
381
- }
382
- set scrollbarOffsetHorizontal(value) {
383
- this.options.scrollbarOffsetHorizontal = value;
384
- }
385
-
386
- /**
387
- * offset of vertical scrollbar (in pixels)
388
- * @type {number}
389
- */
390
- get scrollbarOffsetVertical() {
391
- return this.options.scrollbarOffsetVertical
392
- }
393
- set scrollbarOffsetVertical(value) {
394
- this.options.scrollbarOffsetVertical = value;
395
- }
396
-
397
- /**
398
- * disable the scrollbox (if set to true this will also remove the mask)
399
- * @type {boolean}
400
- */
401
- get disable() {
402
- return this._disabled
403
- }
404
- set disable(value) {
405
- if (this._disabled !== value) {
406
- this._disabled = value;
407
- this.update();
408
- }
409
- }
410
-
411
- /**
412
- * call stopPropagation on any events that impact scrollbox
413
- * @type {boolean}
414
- */
415
- get stopPropagation() {
416
- return this.options.stopPropagation
417
- }
418
- set stopPropagation(value) {
419
- this.options.stopPropagation = value;
420
- }
421
-
422
- /**
423
- * user may drag the content area to scroll content
424
- * @type {boolean}
425
- */
426
- get dragScroll() {
427
- return this.options.dragScroll
428
- }
429
- set dragScroll(value) {
430
- this.options.dragScroll = value;
431
- if (value) {
432
- this.content.drag();
433
- }
434
- else {
435
- if (typeof this.content.removePlugin !== 'undefined') {
436
- this.content.removePlugin('drag');
437
- }
438
- else {
439
- this.content.plugins.remove('drag');
440
- }
441
- }
442
- this.update();
443
- }
444
-
445
- /**
446
- * width of scrollbox including the scrollbar (if visible)- this changes the size and not the scale of the box
447
- * @type {number}
448
- */
449
- get boxWidth() {
450
- return this.options.boxWidth
451
- }
452
- set boxWidth(value) {
453
- this.options.boxWidth = value;
454
- this.content.screenWidth = value;
455
- this.update();
456
- }
457
-
458
- /**
459
- * sets overflowX and overflowY to (scroll, hidden, auto) changing whether the scrollbar is shown
460
- * scroll = always show scrollbar
461
- * hidden = hide overflow and do not show scrollbar
462
- * auto = if content is larger than box size, then show scrollbar
463
- * @type {string}
464
- */
465
- get overflow() {
466
- return this.options.overflow
467
- }
468
- set overflow(value) {
469
- this.options.overflow = value;
470
- this.options.overflowX = value;
471
- this.options.overflowY = value;
472
- this.update();
473
- }
474
-
475
- /**
476
- * sets overflowX to (scroll, hidden, auto) changing whether the scrollbar is shown
477
- * scroll = always show scrollbar
478
- * hidden = hide overflow and do not show scrollbar
479
- * auto = if content is larger than box size, then show scrollbar
480
- * @type {string}
481
- */
482
- get overflowX() {
483
- return this.options.overflowX
484
- }
485
- set overflowX(value) {
486
- this.options.overflowX = value;
487
- this.update();
488
- }
489
-
490
- /**
491
- * sets overflowY to (scroll, hidden, auto) changing whether the scrollbar is shown
492
- * scroll = always show scrollbar
493
- * hidden = hide overflow and do not show scrollbar
494
- * auto = if content is larger than box size, then show scrollbar
495
- * @type {string}
496
- */
497
- get overflowY() {
498
- return this.options.overflowY
499
- }
500
- set overflowY(value) {
501
- this.options.overflowY = value;
502
- this.update();
503
- }
504
-
505
- /**
506
- * height of scrollbox including the scrollbar (if visible) - this changes the size and not the scale of the box
507
- * @type {number}
508
- */
509
- get boxHeight() {
510
- return this.options.boxHeight
511
- }
512
- set boxHeight(value) {
513
- this.options.boxHeight = value;
514
- this.content.screenHeight = value;
515
- this.update();
516
- }
517
-
518
- /**
519
- * scrollbar size in pixels
520
- * @type {number}
521
- */
522
- get scrollbarSize() {
523
- return this.options.scrollbarSize
524
- }
525
- set scrollbarSize(value) {
526
- this.options.scrollbarSize = value;
527
- }
528
-
529
- /**
530
- * width of scrollbox less the scrollbar (if visible)
531
- * @type {number}
532
- * @readonly
533
- */
534
- get contentWidth() {
535
- return this.options.boxWidth - (this.isScrollbarVertical ? this.options.scrollbarSize : 0)
536
- }
537
-
538
- /**
539
- * height of scrollbox less the scrollbar (if visible)
540
- * @type {number}
541
- * @readonly
542
- */
543
- get contentHeight() {
544
- return this.options.boxHeight - (this.isScrollbarHorizontal ? this.options.scrollbarSize : 0)
545
- }
546
-
547
- /**
548
- * is the vertical scrollbar visible
549
- * @type {boolean}
550
- * @readonly
551
- */
552
- get isScrollbarVertical() {
553
- return this._isScrollbarVertical
554
- }
555
-
556
- /**
557
- * is the horizontal scrollbar visible
558
- * @type {boolean}
559
- * @readonly
560
- */
561
- get isScrollbarHorizontal() {
562
- return this._isScrollbarHorizontal
563
- }
564
-
565
- /**
566
- * top coordinate of scrollbar
567
- */
568
- get scrollTop() {
569
- return this.content.top
570
- }
571
- set scrollTop(top) {
572
- this.content.top = top;
573
- this._drawScrollbars();
574
- }
575
-
576
- /**
577
- * left coordinate of scrollbar
578
- */
579
- get scrollLeft() {
580
- return this.content.left
581
- }
582
- set scrollLeft(left) {
583
- this.content.left = left;
584
- this._drawScrollbars();
585
- }
586
-
587
- /**
588
- * width of content area
589
- * if not set then it uses content.width to calculate width
590
- */
591
- get scrollWidth() {
592
- return this._scrollWidth || this.content.width
593
- }
594
- set scrollWidth(value) {
595
- this._scrollWidth = value;
596
- }
597
-
598
- /**
599
- * height of content area
600
- * if not set then it uses content.height to calculate height
601
- */
602
- get scrollHeight() {
603
- return this._scrollHeight || this.content.height
604
- }
605
- set scrollHeight(value) {
606
- this._scrollHeight = value;
607
- }
608
-
609
- /**
610
- * draws scrollbars
611
- * @private
612
- */
613
- _drawScrollbars() {
614
- this._isScrollbarHorizontal = this.overflowX === 'scroll' ? true : ['hidden', 'none'].indexOf(this.overflowX) !== -1 ? false : this.scrollWidth > this.options.boxWidth;
615
- this._isScrollbarVertical = this.overflowY === 'scroll' ? true : ['hidden', 'none'].indexOf(this.overflowY) !== -1 ? false : this.scrollHeight > this.options.boxHeight;
616
- this.scrollbar.clear();
617
- this.scrollWidth + (this._isScrollbarVertical ? this.options.scrollbarSize : 0);
618
- this.scrollHeight + (this.isScrollbarHorizontal ? this.options.scrollbarSize : 0);
619
- const width = this.scrollWidth + (this.isScrollbarVertical ? this.options.scrollbarSize : 0);
620
- const height = this.scrollHeight + (this.isScrollbarHorizontal ? this.options.scrollbarSize : 0);
621
- this.scrollbarTop = (this.content.top / height) * this.boxHeight;
622
- this.scrollbarTop = this.scrollbarTop < 0 ? 0 : this.scrollbarTop;
623
- this.scrollbarHeight = (this.boxHeight / height) * this.boxHeight;
624
- this.scrollbarHeight = this.scrollbarTop + this.scrollbarHeight > this.boxHeight ? this.boxHeight - this.scrollbarTop : this.scrollbarHeight;
625
- this.scrollbarLeft = (this.content.left / width) * this.boxWidth;
626
- this.scrollbarLeft = this.scrollbarLeft < 0 ? 0 : this.scrollbarLeft;
627
- this.scrollbarWidth = (this.boxWidth / width) * this.boxWidth;
628
- this.scrollbarWidth = this.scrollbarWidth + this.scrollbarLeft > this.boxWidth ? this.boxWidth - this.scrollbarLeft : this.scrollbarWidth;
629
- if (this.isScrollbarVertical) {
630
- this.scrollbar
631
- .beginFill(this.options.scrollbarBackground, this.options.scrollbarBackgroundAlpha)
632
- .drawRect(this.boxWidth - this.scrollbarSize + this.options.scrollbarOffsetVertical, 0, this.scrollbarSize, this.boxHeight)
633
- .endFill();
634
- }
635
- if (this.isScrollbarHorizontal) {
636
- this.scrollbar
637
- .beginFill(this.options.scrollbarBackground, this.options.scrollbarBackgroundAlpha)
638
- .drawRect(0, this.boxHeight - this.scrollbarSize + this.options.scrollbarOffsetHorizontal, this.boxWidth, this.scrollbarSize)
639
- .endFill();
640
- }
641
- if (this.isScrollbarVertical) {
642
- this.scrollbar
643
- .beginFill(this.options.scrollbarForeground, this.options.scrollbarForegroundAlpha)
644
- .drawRect(this.boxWidth - this.scrollbarSize + this.options.scrollbarOffsetVertical, this.scrollbarTop, this.scrollbarSize, this.scrollbarHeight)
645
- .endFill();
646
- }
647
- if (this.isScrollbarHorizontal) {
648
- this.scrollbar
649
- .beginFill(this.options.scrollbarForeground, this.options.scrollbarForegroundAlpha)
650
- .drawRect(this.scrollbarLeft, this.boxHeight - this.scrollbarSize + this.options.scrollbarOffsetHorizontal, this.scrollbarWidth, this.scrollbarSize)
651
- .endFill();
652
- }
653
- // this.content.forceHitArea = new PIXI.Rectangle(0, 0 , this.boxWidth, this.boxHeight)
654
- this.activateFade();
655
- }
656
-
657
- /**
658
- * draws mask layer
659
- * @private
660
- */
661
- _drawMask() {
662
- this._maskContent
663
- .beginFill(0)
664
- .drawRect(0, 0, this.boxWidth, this.boxHeight)
665
- .endFill();
666
- this.content.mask = this._maskContent;
667
- }
668
-
669
- /**
670
- * call when scrollbox content changes
671
- */
672
- update() {
673
- this.content.mask = null;
674
- this._maskContent.clear();
675
- if (!this._disabled) {
676
- this._drawScrollbars();
677
- this._drawMask();
678
- const direction = this.isScrollbarHorizontal && this.isScrollbarVertical ? 'all' : this.isScrollbarHorizontal ? 'x' : 'y';
679
- if (direction !== null) {
680
- if (this.options.dragScroll) {
681
- this.content.drag({ clampWheel: this.options.clampWheel, direction });
682
- }
683
- this.content.clamp({ direction, underflow: this.options.underflow });
684
- }
685
- }
686
- }
687
-
688
- /**
689
- * called on each frame to update fade scrollbars (if enabled)
690
- * @param {number} elapsed since last frame in milliseconds (usually capped at 16.6667)
691
- */
692
- updateLoop(elapsed) {
693
- if (this.fade) {
694
- if (this.fade.wait > 0) {
695
- this.fade.wait -= elapsed;
696
- if (this.fade.wait <= 0) {
697
- elapsed += this.fade.wait;
698
- }
699
- else {
700
- return
701
- }
702
- }
703
- this.fade.duration += elapsed;
704
- if (this.fade.duration >= this.options.fadeScrollbarTime) {
705
- this.fade = null;
706
- this.scrollbar.alpha = 0;
707
- }
708
- else {
709
- this.scrollbar.alpha = this.ease(this.fade.duration, 1, -1, this.options.fadeScrollbarTime);
710
- }
711
- this.content.dirty = true;
712
- }
713
- }
714
-
715
- /**
716
- * dirty value (used for optimizing draws) for underlying viewport (scrollbox.content)
717
- * @type {boolean}
718
- */
719
- get dirty() {
720
- return this.content.dirty
721
- }
722
- set dirty(value) {
723
- this.content.dirty = value;
724
- }
725
-
726
- /**
727
- * show the scrollbar and restart the timer for fade if options.fade is set
728
- */
729
- activateFade() {
730
- if (!this.fade && this.options.fade) {
731
- this.scrollbar.alpha = 1;
732
- this.fade = { wait: this.options.fadeScrollboxWait, duration: 0 };
733
- }
734
- }
735
-
736
- /**
737
- * handle pointer down on scrollbar
738
- * @param {PIXI.interaction.InteractionEvent} e
739
- * @private
740
- */
741
- scrollbarDown(e) {
742
- const local = this.toLocal(e.data.global);
743
- if (this.isScrollbarHorizontal) {
744
- if (local.y > this.boxHeight - this.scrollbarSize) {
745
- if (local.x >= this.scrollbarLeft && local.x <= this.scrollbarLeft + this.scrollbarWidth) {
746
- this.pointerDown = { type: 'horizontal', last: local };
747
- }
748
- else {
749
- if (local.x > this.scrollbarLeft) {
750
- this.content.left += this.content.worldScreenWidth;
751
- this.update();
752
- }
753
- else {
754
- this.content.left -= this.content.worldScreenWidth;
755
- this.update();
756
- }
757
- }
758
- if (this.options.stopPropagation) {
759
- e.stopPropagation();
760
- }
761
- return
762
- }
763
- }
764
- if (this.isScrollbarVertical) {
765
- if (local.x > this.boxWidth - this.scrollbarSize) {
766
- if (local.y >= this.scrollbarTop && local.y <= this.scrollbarTop + this.scrollbarWidth) {
767
- this.pointerDown = { type: 'vertical', last: local };
768
- }
769
- else {
770
- if (local.y > this.scrollbarTop) {
771
- this.content.top += this.content.worldScreenHeight;
772
- this.update();
773
- }
774
- else {
775
- this.content.top -= this.content.worldScreenHeight;
776
- this.update();
777
- }
778
- }
779
- if (this.options.stopPropagation) {
780
- e.stopPropagation();
781
- }
782
- return
783
- }
784
- }
785
- }
786
-
787
- /**
788
- * handle pointer move on scrollbar
789
- * @param {PIXI.interaction.InteractionEvent} e
790
- * @private
791
- */
792
- scrollbarMove(e) {
793
- if (this.pointerDown) {
794
- if (this.pointerDown.type === 'horizontal') {
795
- const local = this.toLocal(e.data.global);
796
- const width = this.scrollWidth + (this.isScrollbarVertical ? this.options.scrollbarSize : 0);
797
- this.scrollbarLeft += local.x - this.pointerDown.last.x;
798
- this.content.left = this.scrollbarLeft / this.boxWidth * width;
799
- this.pointerDown.last = local;
800
- this.update();
801
- }
802
- else if (this.pointerDown.type === 'vertical') {
803
- const local = this.toLocal(e.data.global);
804
- const height = this.scrollHeight + (this.isScrollbarHorizontal ? this.options.scrollbarSize : 0);
805
- this.scrollbarTop += local.y - this.pointerDown.last.y;
806
- this.content.top = this.scrollbarTop / this.boxHeight * height;
807
- this.pointerDown.last = local;
808
- this.update();
809
- }
810
- if (this.options.stopPropagation) {
811
- e.stopPropagation();
812
- }
813
- }
814
- }
815
-
816
- /**
817
- * handle pointer down on scrollbar
818
- * @private
819
- */
820
- scrollbarUp() {
821
- this.pointerDown = null;
822
- }
823
-
824
- /**
825
- * resize the mask for the container
826
- * @param {object} options
827
- * @param {number} [options.boxWidth] width of scrollbox including scrollbar (in pixels)
828
- * @param {number} [options.boxHeight] height of scrollbox including scrollbar (in pixels)
829
- * @param {number} [options.scrollWidth] set the width of the inside of the scrollbox (leave null to use content.width)
830
- * @param {number} [options.scrollHeight] set the height of the inside of the scrollbox (leave null to use content.height)
831
- */
832
- resize(options) {
833
- this.options.boxWidth = typeof options.boxWidth !== 'undefined' ? options.boxWidth : this.options.boxWidth;
834
- this.options.boxHeight = typeof options.boxHeight !== 'undefined' ? options.boxHeight : this.options.boxHeight;
835
- if (options.scrollWidth) {
836
- this.scrollWidth = options.scrollWidth;
837
- }
838
- if (options.scrollHeight) {
839
- this.scrollHeight = options.scrollHeight;
840
- }
841
- this.content.resize(this.options.boxWidth, this.options.boxHeight, this.scrollWidth, this.scrollHeight);
842
- this.update();
843
- }
844
-
845
- /**
846
- * ensure that the bounding box is visible
847
- * @param {number} x - relative to content's coordinate system
848
- * @param {number} y
849
- * @param {number} width
850
- * @param {number} height
851
- */
852
- ensureVisible(x, y, width, height) {
853
- this.content.ensureVisible(x, y, width, height);
854
- this._drawScrollbars();
855
- }
856
- }
857
-
858
- export { Scrollbox };
859
- //# sourceMappingURL=scrollbox.es.js.map