@tarsis/toolkit 0.1.0 → 0.1.2

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.
@@ -0,0 +1,3256 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const index = require('./index-CsdKS34u.cjs');
6
+
7
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
+
9
+ function getDefaultExportFromCjs (x) {
10
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
11
+ }
12
+
13
+ function getAugmentedNamespace(n) {
14
+ if (n.__esModule) return n;
15
+ var f = n.default;
16
+ if (typeof f == "function") {
17
+ var a = function a () {
18
+ if (this instanceof a) {
19
+ return Reflect.construct(f, arguments, this.constructor);
20
+ }
21
+ return f.apply(this, arguments);
22
+ };
23
+ a.prototype = f.prototype;
24
+ } else a = {};
25
+ Object.defineProperty(a, '__esModule', {value: true});
26
+ Object.keys(n).forEach(function (k) {
27
+ var d = Object.getOwnPropertyDescriptor(n, k);
28
+ Object.defineProperty(a, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () {
31
+ return n[k];
32
+ }
33
+ });
34
+ });
35
+ return a;
36
+ }
37
+
38
+ var threeOrbitControls;
39
+ var hasRequiredThreeOrbitControls;
40
+
41
+ function requireThreeOrbitControls () {
42
+ if (hasRequiredThreeOrbitControls) return threeOrbitControls;
43
+ hasRequiredThreeOrbitControls = 1;
44
+ threeOrbitControls = function( THREE ) {
45
+ /**
46
+ * @author qiao / https://github.com/qiao
47
+ * @author mrdoob / http://mrdoob.com
48
+ * @author alteredq / http://alteredqualia.com/
49
+ * @author WestLangley / http://github.com/WestLangley
50
+ * @author erich666 / http://erichaines.com
51
+ */
52
+
53
+ // This set of controls performs orbiting, dollying (zooming), and panning.
54
+ // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
55
+ //
56
+ // Orbit - left mouse / touch: one finger move
57
+ // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
58
+ // Pan - right mouse, or arrow keys / touch: three finter swipe
59
+
60
+ function OrbitControls( object, domElement ) {
61
+
62
+ this.object = object;
63
+
64
+ this.domElement = ( domElement !== undefined ) ? domElement : document;
65
+
66
+ // Set to false to disable this control
67
+ this.enabled = true;
68
+
69
+ // "target" sets the location of focus, where the object orbits around
70
+ this.target = new THREE.Vector3();
71
+
72
+ // How far you can dolly in and out ( PerspectiveCamera only )
73
+ this.minDistance = 0;
74
+ this.maxDistance = Infinity;
75
+
76
+ // How far you can zoom in and out ( OrthographicCamera only )
77
+ this.minZoom = 0;
78
+ this.maxZoom = Infinity;
79
+
80
+ // How far you can orbit vertically, upper and lower limits.
81
+ // Range is 0 to Math.PI radians.
82
+ this.minPolarAngle = 0; // radians
83
+ this.maxPolarAngle = Math.PI; // radians
84
+
85
+ // How far you can orbit horizontally, upper and lower limits.
86
+ // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
87
+ this.minAzimuthAngle = - Infinity; // radians
88
+ this.maxAzimuthAngle = Infinity; // radians
89
+
90
+ // Set to true to enable damping (inertia)
91
+ // If damping is enabled, you must call controls.update() in your animation loop
92
+ this.enableDamping = false;
93
+ this.dampingFactor = 0.25;
94
+
95
+ // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
96
+ // Set to false to disable zooming
97
+ this.enableZoom = true;
98
+ this.zoomSpeed = 1.0;
99
+
100
+ // Set to false to disable rotating
101
+ this.enableRotate = true;
102
+ this.rotateSpeed = 1.0;
103
+
104
+ // Set to false to disable panning
105
+ this.enablePan = true;
106
+ this.keyPanSpeed = 7.0; // pixels moved per arrow key push
107
+
108
+ // Set to true to automatically rotate around the target
109
+ // If auto-rotate is enabled, you must call controls.update() in your animation loop
110
+ this.autoRotate = false;
111
+ this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
112
+
113
+ // Set to false to disable use of the keys
114
+ this.enableKeys = true;
115
+
116
+ // The four arrow keys
117
+ this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
118
+
119
+ // Mouse buttons
120
+ this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
121
+
122
+ // for reset
123
+ this.target0 = this.target.clone();
124
+ this.position0 = this.object.position.clone();
125
+ this.zoom0 = this.object.zoom;
126
+
127
+ //
128
+ // public methods
129
+ //
130
+
131
+ this.getPolarAngle = function () {
132
+
133
+ return spherical.phi;
134
+
135
+ };
136
+
137
+ this.getAzimuthalAngle = function () {
138
+
139
+ return spherical.theta;
140
+
141
+ };
142
+
143
+ this.reset = function () {
144
+
145
+ scope.target.copy( scope.target0 );
146
+ scope.object.position.copy( scope.position0 );
147
+ scope.object.zoom = scope.zoom0;
148
+
149
+ scope.object.updateProjectionMatrix();
150
+ scope.dispatchEvent( changeEvent );
151
+
152
+ scope.update();
153
+
154
+ state = STATE.NONE;
155
+
156
+ };
157
+
158
+ // this method is exposed, but perhaps it would be better if we can make it private...
159
+ this.update = function() {
160
+
161
+ var offset = new THREE.Vector3();
162
+
163
+ // so camera.up is the orbit axis
164
+ var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
165
+ var quatInverse = quat.clone().inverse();
166
+
167
+ var lastPosition = new THREE.Vector3();
168
+ var lastQuaternion = new THREE.Quaternion();
169
+
170
+ return function update () {
171
+
172
+ var position = scope.object.position;
173
+
174
+ offset.copy( position ).sub( scope.target );
175
+
176
+ // rotate offset to "y-axis-is-up" space
177
+ offset.applyQuaternion( quat );
178
+
179
+ // angle from z-axis around y-axis
180
+ spherical.setFromVector3( offset );
181
+
182
+ if ( scope.autoRotate && state === STATE.NONE ) {
183
+
184
+ rotateLeft( getAutoRotationAngle() );
185
+
186
+ }
187
+
188
+ spherical.theta += sphericalDelta.theta;
189
+ spherical.phi += sphericalDelta.phi;
190
+
191
+ // restrict theta to be between desired limits
192
+ spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
193
+
194
+ // restrict phi to be between desired limits
195
+ spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
196
+
197
+ spherical.makeSafe();
198
+
199
+
200
+ spherical.radius *= scale;
201
+
202
+ // restrict radius to be between desired limits
203
+ spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
204
+
205
+ // move target to panned location
206
+ scope.target.add( panOffset );
207
+
208
+ offset.setFromSpherical( spherical );
209
+
210
+ // rotate offset back to "camera-up-vector-is-up" space
211
+ offset.applyQuaternion( quatInverse );
212
+
213
+ position.copy( scope.target ).add( offset );
214
+
215
+ scope.object.lookAt( scope.target );
216
+
217
+ if ( scope.enableDamping === true ) {
218
+
219
+ sphericalDelta.theta *= ( 1 - scope.dampingFactor );
220
+ sphericalDelta.phi *= ( 1 - scope.dampingFactor );
221
+
222
+ } else {
223
+
224
+ sphericalDelta.set( 0, 0, 0 );
225
+
226
+ }
227
+
228
+ scale = 1;
229
+ panOffset.set( 0, 0, 0 );
230
+
231
+ // update condition is:
232
+ // min(camera displacement, camera rotation in radians)^2 > EPS
233
+ // using small-angle approximation cos(x/2) = 1 - x^2 / 8
234
+
235
+ if ( zoomChanged ||
236
+ lastPosition.distanceToSquared( scope.object.position ) > EPS ||
237
+ 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
238
+
239
+ scope.dispatchEvent( changeEvent );
240
+
241
+ lastPosition.copy( scope.object.position );
242
+ lastQuaternion.copy( scope.object.quaternion );
243
+ zoomChanged = false;
244
+
245
+ return true;
246
+
247
+ }
248
+
249
+ return false;
250
+
251
+ };
252
+
253
+ }();
254
+
255
+ this.dispose = function() {
256
+
257
+ scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
258
+ scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );
259
+ scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );
260
+
261
+ scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
262
+ scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
263
+ scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );
264
+
265
+ document.removeEventListener( 'mousemove', onMouseMove, false );
266
+ document.removeEventListener( 'mouseup', onMouseUp, false );
267
+
268
+ window.removeEventListener( 'keydown', onKeyDown, false );
269
+
270
+ //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
271
+
272
+ };
273
+
274
+ //
275
+ // internals
276
+ //
277
+
278
+ var scope = this;
279
+
280
+ var changeEvent = { type: 'change' };
281
+ var startEvent = { type: 'start' };
282
+ var endEvent = { type: 'end' };
283
+
284
+ var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
285
+
286
+ var state = STATE.NONE;
287
+
288
+ var EPS = 0.000001;
289
+
290
+ // current position in spherical coordinates
291
+ var spherical = new THREE.Spherical();
292
+ var sphericalDelta = new THREE.Spherical();
293
+
294
+ var scale = 1;
295
+ var panOffset = new THREE.Vector3();
296
+ var zoomChanged = false;
297
+
298
+ var rotateStart = new THREE.Vector2();
299
+ var rotateEnd = new THREE.Vector2();
300
+ var rotateDelta = new THREE.Vector2();
301
+
302
+ var panStart = new THREE.Vector2();
303
+ var panEnd = new THREE.Vector2();
304
+ var panDelta = new THREE.Vector2();
305
+
306
+ var dollyStart = new THREE.Vector2();
307
+ var dollyEnd = new THREE.Vector2();
308
+ var dollyDelta = new THREE.Vector2();
309
+
310
+ function getAutoRotationAngle() {
311
+
312
+ return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
313
+
314
+ }
315
+
316
+ function getZoomScale() {
317
+
318
+ return Math.pow( 0.95, scope.zoomSpeed );
319
+
320
+ }
321
+
322
+ function rotateLeft( angle ) {
323
+
324
+ sphericalDelta.theta -= angle;
325
+
326
+ }
327
+
328
+ function rotateUp( angle ) {
329
+
330
+ sphericalDelta.phi -= angle;
331
+
332
+ }
333
+
334
+ var panLeft = function() {
335
+
336
+ var v = new THREE.Vector3();
337
+
338
+ return function panLeft( distance, objectMatrix ) {
339
+
340
+ v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
341
+ v.multiplyScalar( - distance );
342
+
343
+ panOffset.add( v );
344
+
345
+ };
346
+
347
+ }();
348
+
349
+ var panUp = function() {
350
+
351
+ var v = new THREE.Vector3();
352
+
353
+ return function panUp( distance, objectMatrix ) {
354
+
355
+ v.setFromMatrixColumn( objectMatrix, 1 ); // get Y column of objectMatrix
356
+ v.multiplyScalar( distance );
357
+
358
+ panOffset.add( v );
359
+
360
+ };
361
+
362
+ }();
363
+
364
+ // deltaX and deltaY are in pixels; right and down are positive
365
+ var pan = function() {
366
+
367
+ var offset = new THREE.Vector3();
368
+
369
+ return function pan ( deltaX, deltaY ) {
370
+
371
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
372
+
373
+ if ( scope.object instanceof THREE.PerspectiveCamera ) {
374
+
375
+ // perspective
376
+ var position = scope.object.position;
377
+ offset.copy( position ).sub( scope.target );
378
+ var targetDistance = offset.length();
379
+
380
+ // half of the fov is center to top of screen
381
+ targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
382
+
383
+ // we actually don't use screenWidth, since perspective camera is fixed to screen height
384
+ panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
385
+ panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
386
+
387
+ } else if ( scope.object instanceof THREE.OrthographicCamera ) {
388
+
389
+ // orthographic
390
+ panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
391
+ panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
392
+
393
+ } else {
394
+
395
+ // camera neither orthographic nor perspective
396
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
397
+ scope.enablePan = false;
398
+
399
+ }
400
+
401
+ };
402
+
403
+ }();
404
+
405
+ function dollyIn( dollyScale ) {
406
+
407
+ if ( scope.object instanceof THREE.PerspectiveCamera ) {
408
+
409
+ scale /= dollyScale;
410
+
411
+ } else if ( scope.object instanceof THREE.OrthographicCamera ) {
412
+
413
+ scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
414
+ scope.object.updateProjectionMatrix();
415
+ zoomChanged = true;
416
+
417
+ } else {
418
+
419
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
420
+ scope.enableZoom = false;
421
+
422
+ }
423
+
424
+ }
425
+
426
+ function dollyOut( dollyScale ) {
427
+
428
+ if ( scope.object instanceof THREE.PerspectiveCamera ) {
429
+
430
+ scale *= dollyScale;
431
+
432
+ } else if ( scope.object instanceof THREE.OrthographicCamera ) {
433
+
434
+ scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
435
+ scope.object.updateProjectionMatrix();
436
+ zoomChanged = true;
437
+
438
+ } else {
439
+
440
+ console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
441
+ scope.enableZoom = false;
442
+
443
+ }
444
+
445
+ }
446
+
447
+ //
448
+ // event callbacks - update the object state
449
+ //
450
+
451
+ function handleMouseDownRotate( event ) {
452
+
453
+ //console.log( 'handleMouseDownRotate' );
454
+
455
+ rotateStart.set( event.clientX, event.clientY );
456
+
457
+ }
458
+
459
+ function handleMouseDownDolly( event ) {
460
+
461
+ //console.log( 'handleMouseDownDolly' );
462
+
463
+ dollyStart.set( event.clientX, event.clientY );
464
+
465
+ }
466
+
467
+ function handleMouseDownPan( event ) {
468
+
469
+ //console.log( 'handleMouseDownPan' );
470
+
471
+ panStart.set( event.clientX, event.clientY );
472
+
473
+ }
474
+
475
+ function handleMouseMoveRotate( event ) {
476
+
477
+ //console.log( 'handleMouseMoveRotate' );
478
+
479
+ rotateEnd.set( event.clientX, event.clientY );
480
+ rotateDelta.subVectors( rotateEnd, rotateStart );
481
+
482
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
483
+
484
+ // rotating across whole screen goes 360 degrees around
485
+ rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
486
+
487
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
488
+ rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
489
+
490
+ rotateStart.copy( rotateEnd );
491
+
492
+ scope.update();
493
+
494
+ }
495
+
496
+ function handleMouseMoveDolly( event ) {
497
+
498
+ //console.log( 'handleMouseMoveDolly' );
499
+
500
+ dollyEnd.set( event.clientX, event.clientY );
501
+
502
+ dollyDelta.subVectors( dollyEnd, dollyStart );
503
+
504
+ if ( dollyDelta.y > 0 ) {
505
+
506
+ dollyIn( getZoomScale() );
507
+
508
+ } else if ( dollyDelta.y < 0 ) {
509
+
510
+ dollyOut( getZoomScale() );
511
+
512
+ }
513
+
514
+ dollyStart.copy( dollyEnd );
515
+
516
+ scope.update();
517
+
518
+ }
519
+
520
+ function handleMouseMovePan( event ) {
521
+
522
+ //console.log( 'handleMouseMovePan' );
523
+
524
+ panEnd.set( event.clientX, event.clientY );
525
+
526
+ panDelta.subVectors( panEnd, panStart );
527
+
528
+ pan( panDelta.x, panDelta.y );
529
+
530
+ panStart.copy( panEnd );
531
+
532
+ scope.update();
533
+
534
+ }
535
+
536
+ function handleMouseWheel( event ) {
537
+
538
+ //console.log( 'handleMouseWheel' );
539
+
540
+ if ( event.deltaY < 0 ) {
541
+
542
+ dollyOut( getZoomScale() );
543
+
544
+ } else if ( event.deltaY > 0 ) {
545
+
546
+ dollyIn( getZoomScale() );
547
+
548
+ }
549
+
550
+ scope.update();
551
+
552
+ }
553
+
554
+ function handleKeyDown( event ) {
555
+
556
+ //console.log( 'handleKeyDown' );
557
+
558
+ switch ( event.keyCode ) {
559
+
560
+ case scope.keys.UP:
561
+ pan( 0, scope.keyPanSpeed );
562
+ scope.update();
563
+ break;
564
+
565
+ case scope.keys.BOTTOM:
566
+ pan( 0, - scope.keyPanSpeed );
567
+ scope.update();
568
+ break;
569
+
570
+ case scope.keys.LEFT:
571
+ pan( scope.keyPanSpeed, 0 );
572
+ scope.update();
573
+ break;
574
+
575
+ case scope.keys.RIGHT:
576
+ pan( - scope.keyPanSpeed, 0 );
577
+ scope.update();
578
+ break;
579
+
580
+ }
581
+
582
+ }
583
+
584
+ function handleTouchStartRotate( event ) {
585
+
586
+ //console.log( 'handleTouchStartRotate' );
587
+
588
+ rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
589
+
590
+ }
591
+
592
+ function handleTouchStartDolly( event ) {
593
+
594
+ //console.log( 'handleTouchStartDolly' );
595
+
596
+ var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
597
+ var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
598
+
599
+ var distance = Math.sqrt( dx * dx + dy * dy );
600
+
601
+ dollyStart.set( 0, distance );
602
+
603
+ }
604
+
605
+ function handleTouchStartPan( event ) {
606
+
607
+ //console.log( 'handleTouchStartPan' );
608
+
609
+ panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
610
+
611
+ }
612
+
613
+ function handleTouchMoveRotate( event ) {
614
+
615
+ //console.log( 'handleTouchMoveRotate' );
616
+
617
+ rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
618
+ rotateDelta.subVectors( rotateEnd, rotateStart );
619
+
620
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
621
+
622
+ // rotating across whole screen goes 360 degrees around
623
+ rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
624
+
625
+ // rotating up and down along whole screen attempts to go 360, but limited to 180
626
+ rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
627
+
628
+ rotateStart.copy( rotateEnd );
629
+
630
+ scope.update();
631
+
632
+ }
633
+
634
+ function handleTouchMoveDolly( event ) {
635
+
636
+ //console.log( 'handleTouchMoveDolly' );
637
+
638
+ var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
639
+ var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
640
+
641
+ var distance = Math.sqrt( dx * dx + dy * dy );
642
+
643
+ dollyEnd.set( 0, distance );
644
+
645
+ dollyDelta.subVectors( dollyEnd, dollyStart );
646
+
647
+ if ( dollyDelta.y > 0 ) {
648
+
649
+ dollyOut( getZoomScale() );
650
+
651
+ } else if ( dollyDelta.y < 0 ) {
652
+
653
+ dollyIn( getZoomScale() );
654
+
655
+ }
656
+
657
+ dollyStart.copy( dollyEnd );
658
+
659
+ scope.update();
660
+
661
+ }
662
+
663
+ function handleTouchMovePan( event ) {
664
+
665
+ //console.log( 'handleTouchMovePan' );
666
+
667
+ panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
668
+
669
+ panDelta.subVectors( panEnd, panStart );
670
+
671
+ pan( panDelta.x, panDelta.y );
672
+
673
+ panStart.copy( panEnd );
674
+
675
+ scope.update();
676
+
677
+ }
678
+
679
+ //
680
+ // event handlers - FSM: listen for events and reset state
681
+ //
682
+
683
+ function onMouseDown( event ) {
684
+
685
+ if ( scope.enabled === false ) return;
686
+
687
+ event.preventDefault();
688
+
689
+ if ( event.button === scope.mouseButtons.ORBIT ) {
690
+
691
+ if ( scope.enableRotate === false ) return;
692
+
693
+ handleMouseDownRotate( event );
694
+
695
+ state = STATE.ROTATE;
696
+
697
+ } else if ( event.button === scope.mouseButtons.ZOOM ) {
698
+
699
+ if ( scope.enableZoom === false ) return;
700
+
701
+ handleMouseDownDolly( event );
702
+
703
+ state = STATE.DOLLY;
704
+
705
+ } else if ( event.button === scope.mouseButtons.PAN ) {
706
+
707
+ if ( scope.enablePan === false ) return;
708
+
709
+ handleMouseDownPan( event );
710
+
711
+ state = STATE.PAN;
712
+
713
+ }
714
+
715
+ if ( state !== STATE.NONE ) {
716
+
717
+ document.addEventListener( 'mousemove', onMouseMove, false );
718
+ document.addEventListener( 'mouseup', onMouseUp, false );
719
+
720
+ scope.dispatchEvent( startEvent );
721
+
722
+ }
723
+
724
+ }
725
+
726
+ function onMouseMove( event ) {
727
+
728
+ if ( scope.enabled === false ) return;
729
+
730
+ event.preventDefault();
731
+
732
+ if ( state === STATE.ROTATE ) {
733
+
734
+ if ( scope.enableRotate === false ) return;
735
+
736
+ handleMouseMoveRotate( event );
737
+
738
+ } else if ( state === STATE.DOLLY ) {
739
+
740
+ if ( scope.enableZoom === false ) return;
741
+
742
+ handleMouseMoveDolly( event );
743
+
744
+ } else if ( state === STATE.PAN ) {
745
+
746
+ if ( scope.enablePan === false ) return;
747
+
748
+ handleMouseMovePan( event );
749
+
750
+ }
751
+
752
+ }
753
+
754
+ function onMouseUp( event ) {
755
+
756
+ if ( scope.enabled === false ) return;
757
+
758
+ document.removeEventListener( 'mousemove', onMouseMove, false );
759
+ document.removeEventListener( 'mouseup', onMouseUp, false );
760
+
761
+ scope.dispatchEvent( endEvent );
762
+
763
+ state = STATE.NONE;
764
+
765
+ }
766
+
767
+ function onMouseWheel( event ) {
768
+
769
+ if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
770
+
771
+ event.preventDefault();
772
+ event.stopPropagation();
773
+
774
+ handleMouseWheel( event );
775
+
776
+ scope.dispatchEvent( startEvent ); // not sure why these are here...
777
+ scope.dispatchEvent( endEvent );
778
+
779
+ }
780
+
781
+ function onKeyDown( event ) {
782
+
783
+ if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
784
+
785
+ handleKeyDown( event );
786
+
787
+ }
788
+
789
+ function onTouchStart( event ) {
790
+
791
+ if ( scope.enabled === false ) return;
792
+
793
+ switch ( event.touches.length ) {
794
+
795
+ case 1: // one-fingered touch: rotate
796
+
797
+ if ( scope.enableRotate === false ) return;
798
+
799
+ handleTouchStartRotate( event );
800
+
801
+ state = STATE.TOUCH_ROTATE;
802
+
803
+ break;
804
+
805
+ case 2: // two-fingered touch: dolly
806
+
807
+ if ( scope.enableZoom === false ) return;
808
+
809
+ handleTouchStartDolly( event );
810
+
811
+ state = STATE.TOUCH_DOLLY;
812
+
813
+ break;
814
+
815
+ case 3: // three-fingered touch: pan
816
+
817
+ if ( scope.enablePan === false ) return;
818
+
819
+ handleTouchStartPan( event );
820
+
821
+ state = STATE.TOUCH_PAN;
822
+
823
+ break;
824
+
825
+ default:
826
+
827
+ state = STATE.NONE;
828
+
829
+ }
830
+
831
+ if ( state !== STATE.NONE ) {
832
+
833
+ scope.dispatchEvent( startEvent );
834
+
835
+ }
836
+
837
+ }
838
+
839
+ function onTouchMove( event ) {
840
+
841
+ if ( scope.enabled === false ) return;
842
+
843
+ event.preventDefault();
844
+ event.stopPropagation();
845
+
846
+ switch ( event.touches.length ) {
847
+
848
+ case 1: // one-fingered touch: rotate
849
+
850
+ if ( scope.enableRotate === false ) return;
851
+ if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?...
852
+
853
+ handleTouchMoveRotate( event );
854
+
855
+ break;
856
+
857
+ case 2: // two-fingered touch: dolly
858
+
859
+ if ( scope.enableZoom === false ) return;
860
+ if ( state !== STATE.TOUCH_DOLLY ) return; // is this needed?...
861
+
862
+ handleTouchMoveDolly( event );
863
+
864
+ break;
865
+
866
+ case 3: // three-fingered touch: pan
867
+
868
+ if ( scope.enablePan === false ) return;
869
+ if ( state !== STATE.TOUCH_PAN ) return; // is this needed?...
870
+
871
+ handleTouchMovePan( event );
872
+
873
+ break;
874
+
875
+ default:
876
+
877
+ state = STATE.NONE;
878
+
879
+ }
880
+
881
+ }
882
+
883
+ function onTouchEnd( event ) {
884
+
885
+ if ( scope.enabled === false ) return;
886
+
887
+ scope.dispatchEvent( endEvent );
888
+
889
+ state = STATE.NONE;
890
+
891
+ }
892
+
893
+ function onContextMenu( event ) {
894
+
895
+ event.preventDefault();
896
+
897
+ }
898
+
899
+ //
900
+
901
+ scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
902
+
903
+ scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
904
+ scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
905
+
906
+ scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
907
+ scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
908
+ scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
909
+
910
+ window.addEventListener( 'keydown', onKeyDown, false );
911
+
912
+ // force an update at start
913
+
914
+ this.update();
915
+
916
+ }
917
+ OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
918
+ OrbitControls.prototype.constructor = OrbitControls;
919
+
920
+ Object.defineProperties( OrbitControls.prototype, {
921
+
922
+ center: {
923
+
924
+ get: function () {
925
+
926
+ console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
927
+ return this.target;
928
+
929
+ }
930
+
931
+ },
932
+
933
+ // backward compatibility
934
+
935
+ noZoom: {
936
+
937
+ get: function () {
938
+
939
+ console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
940
+ return ! this.enableZoom;
941
+
942
+ },
943
+
944
+ set: function ( value ) {
945
+
946
+ console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
947
+ this.enableZoom = ! value;
948
+
949
+ }
950
+
951
+ },
952
+
953
+ noRotate: {
954
+
955
+ get: function () {
956
+
957
+ console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
958
+ return ! this.enableRotate;
959
+
960
+ },
961
+
962
+ set: function ( value ) {
963
+
964
+ console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
965
+ this.enableRotate = ! value;
966
+
967
+ }
968
+
969
+ },
970
+
971
+ noPan: {
972
+
973
+ get: function () {
974
+
975
+ console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
976
+ return ! this.enablePan;
977
+
978
+ },
979
+
980
+ set: function ( value ) {
981
+
982
+ console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
983
+ this.enablePan = ! value;
984
+
985
+ }
986
+
987
+ },
988
+
989
+ noKeys: {
990
+
991
+ get: function () {
992
+
993
+ console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
994
+ return ! this.enableKeys;
995
+
996
+ },
997
+
998
+ set: function ( value ) {
999
+
1000
+ console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1001
+ this.enableKeys = ! value;
1002
+
1003
+ }
1004
+
1005
+ },
1006
+
1007
+ staticMoving : {
1008
+
1009
+ get: function () {
1010
+
1011
+ console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1012
+ return ! this.enableDamping;
1013
+
1014
+ },
1015
+
1016
+ set: function ( value ) {
1017
+
1018
+ console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1019
+ this.enableDamping = ! value;
1020
+
1021
+ }
1022
+
1023
+ },
1024
+
1025
+ dynamicDampingFactor : {
1026
+
1027
+ get: function () {
1028
+
1029
+ console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1030
+ return this.dampingFactor;
1031
+
1032
+ },
1033
+
1034
+ set: function ( value ) {
1035
+
1036
+ console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1037
+ this.dampingFactor = value;
1038
+
1039
+ }
1040
+
1041
+ }
1042
+
1043
+ } );
1044
+
1045
+ return OrbitControls;
1046
+ };
1047
+ return threeOrbitControls;
1048
+ }
1049
+
1050
+ var threeOrbitControlsExports = requireThreeOrbitControls();
1051
+ const OrbitControls = /*@__PURE__*/getDefaultExportFromCjs(threeOrbitControlsExports);
1052
+
1053
+ var xhr = {exports: {}};
1054
+
1055
+ var window_1;
1056
+ var hasRequiredWindow;
1057
+
1058
+ function requireWindow () {
1059
+ if (hasRequiredWindow) return window_1;
1060
+ hasRequiredWindow = 1;
1061
+ var win;
1062
+
1063
+ if (typeof window !== "undefined") {
1064
+ win = window;
1065
+ } else if (typeof commonjsGlobal !== "undefined") {
1066
+ win = commonjsGlobal;
1067
+ } else if (typeof self !== "undefined"){
1068
+ win = self;
1069
+ } else {
1070
+ win = {};
1071
+ }
1072
+
1073
+ window_1 = win;
1074
+ return window_1;
1075
+ }
1076
+
1077
+ var isFunction_1;
1078
+ var hasRequiredIsFunction;
1079
+
1080
+ function requireIsFunction () {
1081
+ if (hasRequiredIsFunction) return isFunction_1;
1082
+ hasRequiredIsFunction = 1;
1083
+ isFunction_1 = isFunction;
1084
+
1085
+ var toString = Object.prototype.toString;
1086
+
1087
+ function isFunction (fn) {
1088
+ if (!fn) {
1089
+ return false
1090
+ }
1091
+ var string = toString.call(fn);
1092
+ return string === '[object Function]' ||
1093
+ (typeof fn === 'function' && string !== '[object RegExp]') ||
1094
+ (typeof window !== 'undefined' &&
1095
+ // IE8 and below
1096
+ (fn === window.setTimeout ||
1097
+ fn === window.alert ||
1098
+ fn === window.confirm ||
1099
+ fn === window.prompt))
1100
+ } return isFunction_1;
1101
+ }
1102
+
1103
+ var parseHeaders;
1104
+ var hasRequiredParseHeaders;
1105
+
1106
+ function requireParseHeaders () {
1107
+ if (hasRequiredParseHeaders) return parseHeaders;
1108
+ hasRequiredParseHeaders = 1;
1109
+ var trim = function(string) {
1110
+ return string.replace(/^\s+|\s+$/g, '');
1111
+ }
1112
+ , isArray = function(arg) {
1113
+ return Object.prototype.toString.call(arg) === '[object Array]';
1114
+ };
1115
+
1116
+ parseHeaders = function (headers) {
1117
+ if (!headers)
1118
+ return {}
1119
+
1120
+ var result = {};
1121
+
1122
+ var headersArr = trim(headers).split('\n');
1123
+
1124
+ for (var i = 0; i < headersArr.length; i++) {
1125
+ var row = headersArr[i];
1126
+ var index = row.indexOf(':')
1127
+ , key = trim(row.slice(0, index)).toLowerCase()
1128
+ , value = trim(row.slice(index + 1));
1129
+
1130
+ if (typeof(result[key]) === 'undefined') {
1131
+ result[key] = value;
1132
+ } else if (isArray(result[key])) {
1133
+ result[key].push(value);
1134
+ } else {
1135
+ result[key] = [ result[key], value ];
1136
+ }
1137
+ }
1138
+
1139
+ return result
1140
+ };
1141
+ return parseHeaders;
1142
+ }
1143
+
1144
+ var immutable;
1145
+ var hasRequiredImmutable;
1146
+
1147
+ function requireImmutable () {
1148
+ if (hasRequiredImmutable) return immutable;
1149
+ hasRequiredImmutable = 1;
1150
+ immutable = extend;
1151
+
1152
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
1153
+
1154
+ function extend() {
1155
+ var target = {};
1156
+
1157
+ for (var i = 0; i < arguments.length; i++) {
1158
+ var source = arguments[i];
1159
+
1160
+ for (var key in source) {
1161
+ if (hasOwnProperty.call(source, key)) {
1162
+ target[key] = source[key];
1163
+ }
1164
+ }
1165
+ }
1166
+
1167
+ return target
1168
+ }
1169
+ return immutable;
1170
+ }
1171
+
1172
+ var hasRequiredXhr;
1173
+
1174
+ function requireXhr () {
1175
+ if (hasRequiredXhr) return xhr.exports;
1176
+ hasRequiredXhr = 1;
1177
+ var window = requireWindow();
1178
+ var isFunction = requireIsFunction();
1179
+ var parseHeaders = requireParseHeaders();
1180
+ var xtend = requireImmutable();
1181
+
1182
+ xhr.exports = createXHR;
1183
+ // Allow use of default import syntax in TypeScript
1184
+ xhr.exports.default = createXHR;
1185
+ createXHR.XMLHttpRequest = window.XMLHttpRequest || noop;
1186
+ createXHR.XDomainRequest = "withCredentials" in (new createXHR.XMLHttpRequest()) ? createXHR.XMLHttpRequest : window.XDomainRequest;
1187
+
1188
+ forEachArray(["get", "put", "post", "patch", "head", "delete"], function(method) {
1189
+ createXHR[method === "delete" ? "del" : method] = function(uri, options, callback) {
1190
+ options = initParams(uri, options, callback);
1191
+ options.method = method.toUpperCase();
1192
+ return _createXHR(options)
1193
+ };
1194
+ });
1195
+
1196
+ function forEachArray(array, iterator) {
1197
+ for (var i = 0; i < array.length; i++) {
1198
+ iterator(array[i]);
1199
+ }
1200
+ }
1201
+
1202
+ function isEmpty(obj){
1203
+ for(var i in obj){
1204
+ if(obj.hasOwnProperty(i)) return false
1205
+ }
1206
+ return true
1207
+ }
1208
+
1209
+ function initParams(uri, options, callback) {
1210
+ var params = uri;
1211
+
1212
+ if (isFunction(options)) {
1213
+ callback = options;
1214
+ if (typeof uri === "string") {
1215
+ params = {uri:uri};
1216
+ }
1217
+ } else {
1218
+ params = xtend(options, {uri: uri});
1219
+ }
1220
+
1221
+ params.callback = callback;
1222
+ return params
1223
+ }
1224
+
1225
+ function createXHR(uri, options, callback) {
1226
+ options = initParams(uri, options, callback);
1227
+ return _createXHR(options)
1228
+ }
1229
+
1230
+ function _createXHR(options) {
1231
+ if(typeof options.callback === "undefined"){
1232
+ throw new Error("callback argument missing")
1233
+ }
1234
+
1235
+ var called = false;
1236
+ var callback = function cbOnce(err, response, body){
1237
+ if(!called){
1238
+ called = true;
1239
+ options.callback(err, response, body);
1240
+ }
1241
+ };
1242
+
1243
+ function readystatechange() {
1244
+ if (xhr.readyState === 4) {
1245
+ setTimeout(loadFunc, 0);
1246
+ }
1247
+ }
1248
+
1249
+ function getBody() {
1250
+ // Chrome with requestType=blob throws errors arround when even testing access to responseText
1251
+ var body = undefined;
1252
+
1253
+ if (xhr.response) {
1254
+ body = xhr.response;
1255
+ } else {
1256
+ body = xhr.responseText || getXml(xhr);
1257
+ }
1258
+
1259
+ if (isJson) {
1260
+ try {
1261
+ body = JSON.parse(body);
1262
+ } catch (e) {}
1263
+ }
1264
+
1265
+ return body
1266
+ }
1267
+
1268
+ function errorFunc(evt) {
1269
+ clearTimeout(timeoutTimer);
1270
+ if(!(evt instanceof Error)){
1271
+ evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") );
1272
+ }
1273
+ evt.statusCode = 0;
1274
+ return callback(evt, failureResponse)
1275
+ }
1276
+
1277
+ // will load the data & process the response in a special response object
1278
+ function loadFunc() {
1279
+ if (aborted) return
1280
+ var status;
1281
+ clearTimeout(timeoutTimer);
1282
+ if(options.useXDR && xhr.status===undefined) {
1283
+ //IE8 CORS GET successful response doesn't have a status field, but body is fine
1284
+ status = 200;
1285
+ } else {
1286
+ status = (xhr.status === 1223 ? 204 : xhr.status);
1287
+ }
1288
+ var response = failureResponse;
1289
+ var err = null;
1290
+
1291
+ if (status !== 0){
1292
+ response = {
1293
+ body: getBody(),
1294
+ statusCode: status,
1295
+ method: method,
1296
+ headers: {},
1297
+ url: uri,
1298
+ rawRequest: xhr
1299
+ };
1300
+ if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE
1301
+ response.headers = parseHeaders(xhr.getAllResponseHeaders());
1302
+ }
1303
+ } else {
1304
+ err = new Error("Internal XMLHttpRequest Error");
1305
+ }
1306
+ return callback(err, response, response.body)
1307
+ }
1308
+
1309
+ var xhr = options.xhr || null;
1310
+
1311
+ if (!xhr) {
1312
+ if (options.cors || options.useXDR) {
1313
+ xhr = new createXHR.XDomainRequest();
1314
+ }else {
1315
+ xhr = new createXHR.XMLHttpRequest();
1316
+ }
1317
+ }
1318
+
1319
+ var key;
1320
+ var aborted;
1321
+ var uri = xhr.url = options.uri || options.url;
1322
+ var method = xhr.method = options.method || "GET";
1323
+ var body = options.body || options.data;
1324
+ var headers = xhr.headers = options.headers || {};
1325
+ var sync = !!options.sync;
1326
+ var isJson = false;
1327
+ var timeoutTimer;
1328
+ var failureResponse = {
1329
+ body: undefined,
1330
+ headers: {},
1331
+ statusCode: 0,
1332
+ method: method,
1333
+ url: uri,
1334
+ rawRequest: xhr
1335
+ };
1336
+
1337
+ if ("json" in options && options.json !== false) {
1338
+ isJson = true;
1339
+ headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json"); //Don't override existing accept header declared by user
1340
+ if (method !== "GET" && method !== "HEAD") {
1341
+ headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json"); //Don't override existing accept header declared by user
1342
+ body = JSON.stringify(options.json === true ? body : options.json);
1343
+ }
1344
+ }
1345
+
1346
+ xhr.onreadystatechange = readystatechange;
1347
+ xhr.onload = loadFunc;
1348
+ xhr.onerror = errorFunc;
1349
+ // IE9 must have onprogress be set to a unique function.
1350
+ xhr.onprogress = function () {
1351
+ // IE must die
1352
+ };
1353
+ xhr.onabort = function(){
1354
+ aborted = true;
1355
+ };
1356
+ xhr.ontimeout = errorFunc;
1357
+ xhr.open(method, uri, !sync, options.username, options.password);
1358
+ //has to be after open
1359
+ if(!sync) {
1360
+ xhr.withCredentials = !!options.withCredentials;
1361
+ }
1362
+ // Cannot set timeout with sync request
1363
+ // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
1364
+ // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
1365
+ if (!sync && options.timeout > 0 ) {
1366
+ timeoutTimer = setTimeout(function(){
1367
+ if (aborted) return
1368
+ aborted = true;//IE9 may still call readystatechange
1369
+ xhr.abort("timeout");
1370
+ var e = new Error("XMLHttpRequest timeout");
1371
+ e.code = "ETIMEDOUT";
1372
+ errorFunc(e);
1373
+ }, options.timeout );
1374
+ }
1375
+
1376
+ if (xhr.setRequestHeader) {
1377
+ for(key in headers){
1378
+ if(headers.hasOwnProperty(key)){
1379
+ xhr.setRequestHeader(key, headers[key]);
1380
+ }
1381
+ }
1382
+ } else if (options.headers && !isEmpty(options.headers)) {
1383
+ throw new Error("Headers cannot be set on an XDomainRequest object")
1384
+ }
1385
+
1386
+ if ("responseType" in options) {
1387
+ xhr.responseType = options.responseType;
1388
+ }
1389
+
1390
+ if ("beforeSend" in options &&
1391
+ typeof options.beforeSend === "function"
1392
+ ) {
1393
+ options.beforeSend(xhr);
1394
+ }
1395
+
1396
+ // Microsoft Edge browser sends "undefined" when send is called with undefined value.
1397
+ // XMLHttpRequest spec says to pass null as body to indicate no body
1398
+ // See https://github.com/naugtur/xhr/issues/100.
1399
+ xhr.send(body || null);
1400
+
1401
+ return xhr
1402
+
1403
+
1404
+ }
1405
+
1406
+ function getXml(xhr) {
1407
+ // xhr.responseXML will throw Exception "InvalidStateError" or "DOMException"
1408
+ // See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML.
1409
+ try {
1410
+ if (xhr.responseType === "document") {
1411
+ return xhr.responseXML
1412
+ }
1413
+ var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror";
1414
+ if (xhr.responseType === "" && !firefoxBugTakenEffect) {
1415
+ return xhr.responseXML
1416
+ }
1417
+ } catch (e) {}
1418
+
1419
+ return null
1420
+ }
1421
+
1422
+ function noop() {}
1423
+ return xhr.exports;
1424
+ }
1425
+
1426
+ var parseBmfontAscii;
1427
+ var hasRequiredParseBmfontAscii;
1428
+
1429
+ function requireParseBmfontAscii () {
1430
+ if (hasRequiredParseBmfontAscii) return parseBmfontAscii;
1431
+ hasRequiredParseBmfontAscii = 1;
1432
+ parseBmfontAscii = function parseBMFontAscii(data) {
1433
+ if (!data)
1434
+ throw new Error('no data provided')
1435
+ data = data.toString().trim();
1436
+
1437
+ var output = {
1438
+ pages: [],
1439
+ chars: [],
1440
+ kernings: []
1441
+ };
1442
+
1443
+ var lines = data.split(/\r\n?|\n/g);
1444
+
1445
+ if (lines.length === 0)
1446
+ throw new Error('no data in BMFont file')
1447
+
1448
+ for (var i = 0; i < lines.length; i++) {
1449
+ var lineData = splitLine(lines[i], i);
1450
+ if (!lineData) //skip empty lines
1451
+ continue
1452
+
1453
+ if (lineData.key === 'page') {
1454
+ if (typeof lineData.data.id !== 'number')
1455
+ throw new Error('malformed file at line ' + i + ' -- needs page id=N')
1456
+ if (typeof lineData.data.file !== 'string')
1457
+ throw new Error('malformed file at line ' + i + ' -- needs page file="path"')
1458
+ output.pages[lineData.data.id] = lineData.data.file;
1459
+ } else if (lineData.key === 'chars' || lineData.key === 'kernings') ; else if (lineData.key === 'char') {
1460
+ output.chars.push(lineData.data);
1461
+ } else if (lineData.key === 'kerning') {
1462
+ output.kernings.push(lineData.data);
1463
+ } else {
1464
+ output[lineData.key] = lineData.data;
1465
+ }
1466
+ }
1467
+
1468
+ return output
1469
+ };
1470
+
1471
+ function splitLine(line, idx) {
1472
+ line = line.replace(/\t+/g, ' ').trim();
1473
+ if (!line)
1474
+ return null
1475
+
1476
+ var space = line.indexOf(' ');
1477
+ if (space === -1)
1478
+ throw new Error("no named row at line " + idx)
1479
+
1480
+ var key = line.substring(0, space);
1481
+
1482
+ line = line.substring(space + 1);
1483
+ //clear "letter" field as it is non-standard and
1484
+ //requires additional complexity to parse " / = symbols
1485
+ line = line.replace(/letter=[\'\"]\S+[\'\"]/gi, '');
1486
+ line = line.split("=");
1487
+ line = line.map(function(str) {
1488
+ return str.trim().match((/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g))
1489
+ });
1490
+
1491
+ var data = [];
1492
+ for (var i = 0; i < line.length; i++) {
1493
+ var dt = line[i];
1494
+ if (i === 0) {
1495
+ data.push({
1496
+ key: dt[0],
1497
+ data: ""
1498
+ });
1499
+ } else if (i === line.length - 1) {
1500
+ data[data.length - 1].data = parseData(dt[0]);
1501
+ } else {
1502
+ data[data.length - 1].data = parseData(dt[0]);
1503
+ data.push({
1504
+ key: dt[1],
1505
+ data: ""
1506
+ });
1507
+ }
1508
+ }
1509
+
1510
+ var out = {
1511
+ key: key,
1512
+ data: {}
1513
+ };
1514
+
1515
+ data.forEach(function(v) {
1516
+ out.data[v.key] = v.data;
1517
+ });
1518
+
1519
+ return out
1520
+ }
1521
+
1522
+ function parseData(data) {
1523
+ if (!data || data.length === 0)
1524
+ return ""
1525
+
1526
+ if (data.indexOf('"') === 0 || data.indexOf("'") === 0)
1527
+ return data.substring(1, data.length - 1)
1528
+ if (data.indexOf(',') !== -1)
1529
+ return parseIntList(data)
1530
+ return parseInt(data, 10)
1531
+ }
1532
+
1533
+ function parseIntList(data) {
1534
+ return data.split(',').map(function(val) {
1535
+ return parseInt(val, 10)
1536
+ })
1537
+ }
1538
+ return parseBmfontAscii;
1539
+ }
1540
+
1541
+ var parseAttribs;
1542
+ var hasRequiredParseAttribs;
1543
+
1544
+ function requireParseAttribs () {
1545
+ if (hasRequiredParseAttribs) return parseAttribs;
1546
+ hasRequiredParseAttribs = 1;
1547
+ //Some versions of GlyphDesigner have a typo
1548
+ //that causes some bugs with parsing.
1549
+ //Need to confirm with recent version of the software
1550
+ //to see whether this is still an issue or not.
1551
+ var GLYPH_DESIGNER_ERROR = 'chasrset';
1552
+
1553
+ parseAttribs = function parseAttributes(obj) {
1554
+ obj = Object.assign({}, obj);
1555
+ if (GLYPH_DESIGNER_ERROR in obj) {
1556
+ obj['charset'] = obj[GLYPH_DESIGNER_ERROR];
1557
+ delete obj[GLYPH_DESIGNER_ERROR];
1558
+ }
1559
+
1560
+ for (var k in obj) {
1561
+ if (k === 'face' || k === 'charset')
1562
+ continue
1563
+ else if (k === 'padding' || k === 'spacing')
1564
+ obj[k] = parseIntList(obj[k]);
1565
+ else
1566
+ obj[k] = parseInt(obj[k], 10);
1567
+ }
1568
+ return obj
1569
+ };
1570
+
1571
+ function parseIntList(data) {
1572
+ return data.split(',').map(function(val) {
1573
+ return parseInt(val, 10)
1574
+ })
1575
+ }
1576
+ return parseAttribs;
1577
+ }
1578
+
1579
+ var xmlParseFromString;
1580
+ var hasRequiredXmlParseFromString;
1581
+
1582
+ function requireXmlParseFromString () {
1583
+ if (hasRequiredXmlParseFromString) return xmlParseFromString;
1584
+ hasRequiredXmlParseFromString = 1;
1585
+ xmlParseFromString = (function xmlparser() {
1586
+ //common browsers
1587
+ if (typeof self.DOMParser !== 'undefined') {
1588
+ return function(str) {
1589
+ var parser = new self.DOMParser();
1590
+ return parser.parseFromString(str, 'application/xml')
1591
+ }
1592
+ }
1593
+
1594
+ //IE8 fallback
1595
+ if (typeof self.ActiveXObject !== 'undefined'
1596
+ && new self.ActiveXObject('Microsoft.XMLDOM')) {
1597
+ return function(str) {
1598
+ var xmlDoc = new self.ActiveXObject("Microsoft.XMLDOM");
1599
+ xmlDoc.async = "false";
1600
+ xmlDoc.loadXML(str);
1601
+ return xmlDoc
1602
+ }
1603
+ }
1604
+
1605
+ //last resort fallback
1606
+ return function(str) {
1607
+ var div = document.createElement('div');
1608
+ div.innerHTML = str;
1609
+ return div
1610
+ }
1611
+ })();
1612
+ return xmlParseFromString;
1613
+ }
1614
+
1615
+ var browser$1;
1616
+ var hasRequiredBrowser$1;
1617
+
1618
+ function requireBrowser$1 () {
1619
+ if (hasRequiredBrowser$1) return browser$1;
1620
+ hasRequiredBrowser$1 = 1;
1621
+ var parseAttributes = requireParseAttribs();
1622
+ var parseFromString = requireXmlParseFromString();
1623
+
1624
+ //In some cases element.attribute.nodeName can return
1625
+ //all lowercase values.. so we need to map them to the correct
1626
+ //case
1627
+ var NAME_MAP = {
1628
+ scaleh: 'scaleH',
1629
+ scalew: 'scaleW',
1630
+ stretchh: 'stretchH',
1631
+ lineheight: 'lineHeight',
1632
+ alphachnl: 'alphaChnl',
1633
+ redchnl: 'redChnl',
1634
+ greenchnl: 'greenChnl',
1635
+ bluechnl: 'blueChnl'
1636
+ };
1637
+
1638
+ browser$1 = function parse(data) {
1639
+ data = data.toString();
1640
+
1641
+ var xmlRoot = parseFromString(data);
1642
+ var output = {
1643
+ pages: [],
1644
+ chars: [],
1645
+ kernings: []
1646
+ }
1647
+
1648
+ //get config settings
1649
+ ;['info', 'common'].forEach(function(key) {
1650
+ var element = xmlRoot.getElementsByTagName(key)[0];
1651
+ if (element)
1652
+ output[key] = parseAttributes(getAttribs(element));
1653
+ });
1654
+
1655
+ //get page info
1656
+ var pageRoot = xmlRoot.getElementsByTagName('pages')[0];
1657
+ if (!pageRoot)
1658
+ throw new Error('malformed file -- no <pages> element')
1659
+ var pages = pageRoot.getElementsByTagName('page');
1660
+ for (var i=0; i<pages.length; i++) {
1661
+ var p = pages[i];
1662
+ var id = parseInt(p.getAttribute('id'), 10);
1663
+ var file = p.getAttribute('file');
1664
+ if (isNaN(id))
1665
+ throw new Error('malformed file -- page "id" attribute is NaN')
1666
+ if (!file)
1667
+ throw new Error('malformed file -- needs page "file" attribute')
1668
+ output.pages[parseInt(id, 10)] = file;
1669
+ }
1670
+ ['chars', 'kernings'].forEach(function(key) {
1671
+ var element = xmlRoot.getElementsByTagName(key)[0];
1672
+ if (!element)
1673
+ return
1674
+ var childTag = key.substring(0, key.length-1);
1675
+ var children = element.getElementsByTagName(childTag);
1676
+ for (var i=0; i<children.length; i++) {
1677
+ var child = children[i];
1678
+ output[key].push(parseAttributes(getAttribs(child)));
1679
+ }
1680
+ });
1681
+ return output
1682
+ };
1683
+
1684
+ function getAttribs(element) {
1685
+ var attribs = getAttribList(element);
1686
+ return attribs.reduce(function(dict, attrib) {
1687
+ var key = mapName(attrib.nodeName);
1688
+ dict[key] = attrib.nodeValue;
1689
+ return dict
1690
+ }, {})
1691
+ }
1692
+
1693
+ function getAttribList(element) {
1694
+ //IE8+ and modern browsers
1695
+ var attribs = [];
1696
+ for (var i=0; i<element.attributes.length; i++)
1697
+ attribs.push(element.attributes[i]);
1698
+ return attribs
1699
+ }
1700
+
1701
+ function mapName(nodeName) {
1702
+ return NAME_MAP[nodeName.toLowerCase()] || nodeName
1703
+ }
1704
+ return browser$1;
1705
+ }
1706
+
1707
+ var parseBmfontBinary;
1708
+ var hasRequiredParseBmfontBinary;
1709
+
1710
+ function requireParseBmfontBinary () {
1711
+ if (hasRequiredParseBmfontBinary) return parseBmfontBinary;
1712
+ hasRequiredParseBmfontBinary = 1;
1713
+ var HEADER = [66, 77, 70];
1714
+
1715
+ parseBmfontBinary = function readBMFontBinary(buf) {
1716
+ if (buf.length < 6)
1717
+ throw new Error('invalid buffer length for BMFont')
1718
+
1719
+ var header = HEADER.every(function(byte, i) {
1720
+ return buf.readUInt8(i) === byte
1721
+ });
1722
+
1723
+ if (!header)
1724
+ throw new Error('BMFont missing BMF byte header')
1725
+
1726
+ var i = 3;
1727
+ var vers = buf.readUInt8(i++);
1728
+ if (vers > 3)
1729
+ throw new Error('Only supports BMFont Binary v3 (BMFont App v1.10)')
1730
+
1731
+ var target = { kernings: [], chars: [] };
1732
+ for (var b=0; b<5; b++)
1733
+ i += readBlock(target, buf, i);
1734
+ return target
1735
+ };
1736
+
1737
+ function readBlock(target, buf, i) {
1738
+ if (i > buf.length-1)
1739
+ return 0
1740
+
1741
+ var blockID = buf.readUInt8(i++);
1742
+ var blockSize = buf.readInt32LE(i);
1743
+ i += 4;
1744
+
1745
+ switch(blockID) {
1746
+ case 1:
1747
+ target.info = readInfo(buf, i);
1748
+ break
1749
+ case 2:
1750
+ target.common = readCommon(buf, i);
1751
+ break
1752
+ case 3:
1753
+ target.pages = readPages(buf, i, blockSize);
1754
+ break
1755
+ case 4:
1756
+ target.chars = readChars(buf, i, blockSize);
1757
+ break
1758
+ case 5:
1759
+ target.kernings = readKernings(buf, i, blockSize);
1760
+ break
1761
+ }
1762
+ return 5 + blockSize
1763
+ }
1764
+
1765
+ function readInfo(buf, i) {
1766
+ var info = {};
1767
+ info.size = buf.readInt16LE(i);
1768
+
1769
+ var bitField = buf.readUInt8(i+2);
1770
+ info.smooth = (bitField >> 7) & 1;
1771
+ info.unicode = (bitField >> 6) & 1;
1772
+ info.italic = (bitField >> 5) & 1;
1773
+ info.bold = (bitField >> 4) & 1;
1774
+
1775
+ //fixedHeight is only mentioned in binary spec
1776
+ if ((bitField >> 3) & 1)
1777
+ info.fixedHeight = 1;
1778
+
1779
+ info.charset = buf.readUInt8(i+3) || '';
1780
+ info.stretchH = buf.readUInt16LE(i+4);
1781
+ info.aa = buf.readUInt8(i+6);
1782
+ info.padding = [
1783
+ buf.readInt8(i+7),
1784
+ buf.readInt8(i+8),
1785
+ buf.readInt8(i+9),
1786
+ buf.readInt8(i+10)
1787
+ ];
1788
+ info.spacing = [
1789
+ buf.readInt8(i+11),
1790
+ buf.readInt8(i+12)
1791
+ ];
1792
+ info.outline = buf.readUInt8(i+13);
1793
+ info.face = readStringNT(buf, i+14);
1794
+ return info
1795
+ }
1796
+
1797
+ function readCommon(buf, i) {
1798
+ var common = {};
1799
+ common.lineHeight = buf.readUInt16LE(i);
1800
+ common.base = buf.readUInt16LE(i+2);
1801
+ common.scaleW = buf.readUInt16LE(i+4);
1802
+ common.scaleH = buf.readUInt16LE(i+6);
1803
+ common.pages = buf.readUInt16LE(i+8);
1804
+ buf.readUInt8(i+10);
1805
+ common.packed = 0;
1806
+ common.alphaChnl = buf.readUInt8(i+11);
1807
+ common.redChnl = buf.readUInt8(i+12);
1808
+ common.greenChnl = buf.readUInt8(i+13);
1809
+ common.blueChnl = buf.readUInt8(i+14);
1810
+ return common
1811
+ }
1812
+
1813
+ function readPages(buf, i, size) {
1814
+ var pages = [];
1815
+ var text = readNameNT(buf, i);
1816
+ var len = text.length+1;
1817
+ var count = size / len;
1818
+ for (var c=0; c<count; c++) {
1819
+ pages[c] = buf.slice(i, i+text.length).toString('utf8');
1820
+ i += len;
1821
+ }
1822
+ return pages
1823
+ }
1824
+
1825
+ function readChars(buf, i, blockSize) {
1826
+ var chars = [];
1827
+
1828
+ var count = blockSize / 20;
1829
+ for (var c=0; c<count; c++) {
1830
+ var char = {};
1831
+ var off = c*20;
1832
+ char.id = buf.readUInt32LE(i + 0 + off);
1833
+ char.x = buf.readUInt16LE(i + 4 + off);
1834
+ char.y = buf.readUInt16LE(i + 6 + off);
1835
+ char.width = buf.readUInt16LE(i + 8 + off);
1836
+ char.height = buf.readUInt16LE(i + 10 + off);
1837
+ char.xoffset = buf.readInt16LE(i + 12 + off);
1838
+ char.yoffset = buf.readInt16LE(i + 14 + off);
1839
+ char.xadvance = buf.readInt16LE(i + 16 + off);
1840
+ char.page = buf.readUInt8(i + 18 + off);
1841
+ char.chnl = buf.readUInt8(i + 19 + off);
1842
+ chars[c] = char;
1843
+ }
1844
+ return chars
1845
+ }
1846
+
1847
+ function readKernings(buf, i, blockSize) {
1848
+ var kernings = [];
1849
+ var count = blockSize / 10;
1850
+ for (var c=0; c<count; c++) {
1851
+ var kern = {};
1852
+ var off = c*10;
1853
+ kern.first = buf.readUInt32LE(i + 0 + off);
1854
+ kern.second = buf.readUInt32LE(i + 4 + off);
1855
+ kern.amount = buf.readInt16LE(i + 8 + off);
1856
+ kernings[c] = kern;
1857
+ }
1858
+ return kernings
1859
+ }
1860
+
1861
+ function readNameNT(buf, offset) {
1862
+ var pos=offset;
1863
+ for (; pos<buf.length; pos++) {
1864
+ if (buf[pos] === 0x00)
1865
+ break
1866
+ }
1867
+ return buf.slice(offset, pos)
1868
+ }
1869
+
1870
+ function readStringNT(buf, offset) {
1871
+ return readNameNT(buf, offset).toString('utf8')
1872
+ }
1873
+ return parseBmfontBinary;
1874
+ }
1875
+
1876
+ const __viteBrowserExternal = {};
1877
+
1878
+ const __viteBrowserExternal$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1879
+ __proto__: null,
1880
+ default: __viteBrowserExternal
1881
+ }, Symbol.toStringTag, { value: 'Module' }));
1882
+
1883
+ const require$$0 = /*@__PURE__*/getAugmentedNamespace(__viteBrowserExternal$1);
1884
+
1885
+ var bufferEqual;
1886
+ var hasRequiredBufferEqual;
1887
+
1888
+ function requireBufferEqual () {
1889
+ if (hasRequiredBufferEqual) return bufferEqual;
1890
+ hasRequiredBufferEqual = 1;
1891
+ var Buffer = require$$0.Buffer; // for use with browserify
1892
+
1893
+ bufferEqual = function (a, b) {
1894
+ if (!Buffer.isBuffer(a)) return undefined;
1895
+ if (!Buffer.isBuffer(b)) return undefined;
1896
+ if (typeof a.equals === 'function') return a.equals(b);
1897
+ if (a.length !== b.length) return false;
1898
+
1899
+ for (var i = 0; i < a.length; i++) {
1900
+ if (a[i] !== b[i]) return false;
1901
+ }
1902
+
1903
+ return true;
1904
+ };
1905
+ return bufferEqual;
1906
+ }
1907
+
1908
+ var isBinary;
1909
+ var hasRequiredIsBinary;
1910
+
1911
+ function requireIsBinary () {
1912
+ if (hasRequiredIsBinary) return isBinary;
1913
+ hasRequiredIsBinary = 1;
1914
+ var equal = requireBufferEqual();
1915
+ var HEADER = Buffer.from([66, 77, 70, 3]);
1916
+
1917
+ isBinary = function(buf) {
1918
+ if (typeof buf === 'string')
1919
+ return buf.substring(0, 3) === 'BMF'
1920
+ return buf.length > 4 && equal(buf.slice(0, 4), HEADER)
1921
+ };
1922
+ return isBinary;
1923
+ }
1924
+
1925
+ var browser;
1926
+ var hasRequiredBrowser;
1927
+
1928
+ function requireBrowser () {
1929
+ if (hasRequiredBrowser) return browser;
1930
+ hasRequiredBrowser = 1;
1931
+ var xhr = requireXhr();
1932
+ var noop = function(){};
1933
+ var parseASCII = requireParseBmfontAscii();
1934
+ var parseXML = requireBrowser$1();
1935
+ var readBinary = requireParseBmfontBinary();
1936
+ var isBinaryFormat = requireIsBinary();
1937
+ var xtend = requireImmutable();
1938
+
1939
+ var xml2 = (function hasXML2() {
1940
+ return self.XMLHttpRequest && "withCredentials" in new XMLHttpRequest
1941
+ })();
1942
+
1943
+ browser = function(opt, cb) {
1944
+ cb = typeof cb === 'function' ? cb : noop;
1945
+
1946
+ if (typeof opt === 'string')
1947
+ opt = { uri: opt };
1948
+ else if (!opt)
1949
+ opt = {};
1950
+
1951
+ var expectBinary = opt.binary;
1952
+ if (expectBinary)
1953
+ opt = getBinaryOpts(opt);
1954
+
1955
+ xhr(opt, function(err, res, body) {
1956
+ if (err)
1957
+ return cb(err)
1958
+ if (!/^2/.test(res.statusCode))
1959
+ return cb(new Error('http status code: '+res.statusCode))
1960
+ if (!body)
1961
+ return cb(new Error('no body result'))
1962
+
1963
+ var binary = false;
1964
+
1965
+ //if the response type is an array buffer,
1966
+ //we need to convert it into a regular Buffer object
1967
+ if (isArrayBuffer(body)) {
1968
+ var array = new Uint8Array(body);
1969
+ body = Buffer.from(array, 'binary');
1970
+ }
1971
+
1972
+ //now check the string/Buffer response
1973
+ //and see if it has a binary BMF header
1974
+ if (isBinaryFormat(body)) {
1975
+ binary = true;
1976
+ //if we have a string, turn it into a Buffer
1977
+ if (typeof body === 'string')
1978
+ body = Buffer.from(body, 'binary');
1979
+ }
1980
+
1981
+ //we are not parsing a binary format, just ASCII/XML/etc
1982
+ if (!binary) {
1983
+ //might still be a buffer if responseType is 'arraybuffer'
1984
+ if (Buffer.isBuffer(body))
1985
+ body = body.toString(opt.encoding);
1986
+ body = body.trim();
1987
+ }
1988
+
1989
+ var result;
1990
+ try {
1991
+ var type = res.headers['content-type'];
1992
+ if (binary)
1993
+ result = readBinary(body);
1994
+ else if (/json/.test(type) || body.charAt(0) === '{')
1995
+ result = JSON.parse(body);
1996
+ else if (/xml/.test(type) || body.charAt(0) === '<')
1997
+ result = parseXML(body);
1998
+ else
1999
+ result = parseASCII(body);
2000
+ } catch (e) {
2001
+ cb(new Error('error parsing font '+e.message));
2002
+ cb = noop;
2003
+ }
2004
+ cb(null, result);
2005
+ });
2006
+ };
2007
+
2008
+ function isArrayBuffer(arr) {
2009
+ var str = Object.prototype.toString;
2010
+ return str.call(arr) === '[object ArrayBuffer]'
2011
+ }
2012
+
2013
+ function getBinaryOpts(opt) {
2014
+ //IE10+ and other modern browsers support array buffers
2015
+ if (xml2)
2016
+ return xtend(opt, { responseType: 'arraybuffer' })
2017
+
2018
+ if (typeof self.XMLHttpRequest === 'undefined')
2019
+ throw new Error('your browser does not support XHR loading')
2020
+
2021
+ //IE9 and XML1 browsers could still use an override
2022
+ var req = new self.XMLHttpRequest();
2023
+ req.overrideMimeType('text/plain; charset=x-user-defined');
2024
+ return xtend({
2025
+ xhr: req
2026
+ }, opt)
2027
+ }
2028
+ return browser;
2029
+ }
2030
+
2031
+ var browserExports = requireBrowser();
2032
+ const loadFont = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
2033
+
2034
+ var wordWrapper = {exports: {}};
2035
+
2036
+ var hasRequiredWordWrapper;
2037
+
2038
+ function requireWordWrapper () {
2039
+ if (hasRequiredWordWrapper) return wordWrapper.exports;
2040
+ hasRequiredWordWrapper = 1;
2041
+ (function (module) {
2042
+ var newline = /\n/;
2043
+ var newlineChar = '\n';
2044
+ var whitespace = /\s/;
2045
+
2046
+ module.exports = function(text, opt) {
2047
+ var lines = module.exports.lines(text, opt);
2048
+ return lines.map(function(line) {
2049
+ return text.substring(line.start, line.end)
2050
+ }).join('\n')
2051
+ };
2052
+
2053
+ module.exports.lines = function wordwrap(text, opt) {
2054
+ opt = opt||{};
2055
+
2056
+ //zero width results in nothing visible
2057
+ if (opt.width === 0 && opt.mode !== 'nowrap')
2058
+ return []
2059
+
2060
+ text = text||'';
2061
+ var width = typeof opt.width === 'number' ? opt.width : Number.MAX_VALUE;
2062
+ var start = Math.max(0, opt.start||0);
2063
+ var end = typeof opt.end === 'number' ? opt.end : text.length;
2064
+ var mode = opt.mode;
2065
+
2066
+ var measure = opt.measure || monospace;
2067
+ if (mode === 'pre')
2068
+ return pre(measure, text, start, end, width)
2069
+ else
2070
+ return greedy(measure, text, start, end, width, mode)
2071
+ };
2072
+
2073
+ function idxOf(text, chr, start, end) {
2074
+ var idx = text.indexOf(chr, start);
2075
+ if (idx === -1 || idx > end)
2076
+ return end
2077
+ return idx
2078
+ }
2079
+
2080
+ function isWhitespace(chr) {
2081
+ return whitespace.test(chr)
2082
+ }
2083
+
2084
+ function pre(measure, text, start, end, width) {
2085
+ var lines = [];
2086
+ var lineStart = start;
2087
+ for (var i=start; i<end && i<text.length; i++) {
2088
+ var chr = text.charAt(i);
2089
+ var isNewline = newline.test(chr);
2090
+
2091
+ //If we've reached a newline, then step down a line
2092
+ //Or if we've reached the EOF
2093
+ if (isNewline || i===end-1) {
2094
+ var lineEnd = isNewline ? i : i+1;
2095
+ var measured = measure(text, lineStart, lineEnd, width);
2096
+ lines.push(measured);
2097
+
2098
+ lineStart = i+1;
2099
+ }
2100
+ }
2101
+ return lines
2102
+ }
2103
+
2104
+ function greedy(measure, text, start, end, width, mode) {
2105
+ //A greedy word wrapper based on LibGDX algorithm
2106
+ //https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/BitmapFontCache.java
2107
+ var lines = [];
2108
+
2109
+ var testWidth = width;
2110
+ //if 'nowrap' is specified, we only wrap on newline chars
2111
+ if (mode === 'nowrap')
2112
+ testWidth = Number.MAX_VALUE;
2113
+
2114
+ while (start < end && start < text.length) {
2115
+ //get next newline position
2116
+ var newLine = idxOf(text, newlineChar, start, end);
2117
+
2118
+ //eat whitespace at start of line
2119
+ while (start < newLine) {
2120
+ if (!isWhitespace( text.charAt(start) ))
2121
+ break
2122
+ start++;
2123
+ }
2124
+
2125
+ //determine visible # of glyphs for the available width
2126
+ var measured = measure(text, start, newLine, testWidth);
2127
+
2128
+ var lineEnd = start + (measured.end-measured.start);
2129
+ var nextStart = lineEnd + newlineChar.length;
2130
+
2131
+ //if we had to cut the line before the next newline...
2132
+ if (lineEnd < newLine) {
2133
+ //find char to break on
2134
+ while (lineEnd > start) {
2135
+ if (isWhitespace(text.charAt(lineEnd)))
2136
+ break
2137
+ lineEnd--;
2138
+ }
2139
+ if (lineEnd === start) {
2140
+ if (nextStart > start + newlineChar.length) nextStart--;
2141
+ lineEnd = nextStart; // If no characters to break, show all.
2142
+ } else {
2143
+ nextStart = lineEnd;
2144
+ //eat whitespace at end of line
2145
+ while (lineEnd > start) {
2146
+ if (!isWhitespace(text.charAt(lineEnd - newlineChar.length)))
2147
+ break
2148
+ lineEnd--;
2149
+ }
2150
+ }
2151
+ }
2152
+ if (lineEnd >= start) {
2153
+ var result = measure(text, start, lineEnd, testWidth);
2154
+ lines.push(result);
2155
+ }
2156
+ start = nextStart;
2157
+ }
2158
+ return lines
2159
+ }
2160
+
2161
+ //determines the visible number of glyphs within a given width
2162
+ function monospace(text, start, end, width) {
2163
+ var glyphs = Math.min(width, end-start);
2164
+ return {
2165
+ start: start,
2166
+ end: start+glyphs
2167
+ }
2168
+ }
2169
+ } (wordWrapper));
2170
+ return wordWrapper.exports;
2171
+ }
2172
+
2173
+ var asNumber;
2174
+ var hasRequiredAsNumber;
2175
+
2176
+ function requireAsNumber () {
2177
+ if (hasRequiredAsNumber) return asNumber;
2178
+ hasRequiredAsNumber = 1;
2179
+ asNumber = function numtype(num, def) {
2180
+ return typeof num === 'number'
2181
+ ? num
2182
+ : (typeof def === 'number' ? def : 0)
2183
+ };
2184
+ return asNumber;
2185
+ }
2186
+
2187
+ var layoutBmfontText;
2188
+ var hasRequiredLayoutBmfontText;
2189
+
2190
+ function requireLayoutBmfontText () {
2191
+ if (hasRequiredLayoutBmfontText) return layoutBmfontText;
2192
+ hasRequiredLayoutBmfontText = 1;
2193
+ var wordWrap = requireWordWrapper();
2194
+ var xtend = requireImmutable();
2195
+ var number = requireAsNumber();
2196
+
2197
+ var X_HEIGHTS = ['x', 'e', 'a', 'o', 'n', 's', 'r', 'c', 'u', 'm', 'v', 'w', 'z'];
2198
+ var M_WIDTHS = ['m', 'w'];
2199
+ var CAP_HEIGHTS = ['H', 'I', 'N', 'E', 'F', 'K', 'L', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
2200
+
2201
+
2202
+ var TAB_ID = '\t'.charCodeAt(0);
2203
+ var SPACE_ID = ' '.charCodeAt(0);
2204
+ var ALIGN_LEFT = 0,
2205
+ ALIGN_CENTER = 1,
2206
+ ALIGN_RIGHT = 2;
2207
+
2208
+ layoutBmfontText = function createLayout(opt) {
2209
+ return new TextLayout(opt)
2210
+ };
2211
+
2212
+ function TextLayout(opt) {
2213
+ this.glyphs = [];
2214
+ this._measure = this.computeMetrics.bind(this);
2215
+ this.update(opt);
2216
+ }
2217
+
2218
+ TextLayout.prototype.update = function(opt) {
2219
+ opt = xtend({
2220
+ measure: this._measure
2221
+ }, opt);
2222
+ this._opt = opt;
2223
+ this._opt.tabSize = number(this._opt.tabSize, 4);
2224
+
2225
+ if (!opt.font)
2226
+ throw new Error('must provide a valid bitmap font')
2227
+
2228
+ var glyphs = this.glyphs;
2229
+ var text = opt.text||'';
2230
+ var font = opt.font;
2231
+ this._setupSpaceGlyphs(font);
2232
+
2233
+ var lines = wordWrap.lines(text, opt);
2234
+ var minWidth = opt.width || 0;
2235
+
2236
+ //clear glyphs
2237
+ glyphs.length = 0;
2238
+
2239
+ //get max line width
2240
+ var maxLineWidth = lines.reduce(function(prev, line) {
2241
+ return Math.max(prev, line.width, minWidth)
2242
+ }, 0);
2243
+
2244
+ //the pen position
2245
+ var x = 0;
2246
+ var y = 0;
2247
+ var lineHeight = number(opt.lineHeight, font.common.lineHeight);
2248
+ var baseline = font.common.base;
2249
+ var descender = lineHeight-baseline;
2250
+ var letterSpacing = opt.letterSpacing || 0;
2251
+ var height = lineHeight * lines.length - descender;
2252
+ var align = getAlignType(this._opt.align);
2253
+
2254
+ //draw text along baseline
2255
+ y -= height;
2256
+
2257
+ //the metrics for this text layout
2258
+ this._width = maxLineWidth;
2259
+ this._height = height;
2260
+ this._descender = lineHeight - baseline;
2261
+ this._baseline = baseline;
2262
+ this._xHeight = getXHeight(font);
2263
+ this._capHeight = getCapHeight(font);
2264
+ this._lineHeight = lineHeight;
2265
+ this._ascender = lineHeight - descender - this._xHeight;
2266
+
2267
+ //layout each glyph
2268
+ var self = this;
2269
+ lines.forEach(function(line, lineIndex) {
2270
+ var start = line.start;
2271
+ var end = line.end;
2272
+ var lineWidth = line.width;
2273
+ var lastGlyph;
2274
+
2275
+ //for each glyph in that line...
2276
+ for (var i=start; i<end; i++) {
2277
+ var id = text.charCodeAt(i);
2278
+ var glyph = self.getGlyph(font, id);
2279
+ if (glyph) {
2280
+ if (lastGlyph)
2281
+ x += getKerning(font, lastGlyph.id, glyph.id);
2282
+
2283
+ var tx = x;
2284
+ if (align === ALIGN_CENTER)
2285
+ tx += (maxLineWidth-lineWidth)/2;
2286
+ else if (align === ALIGN_RIGHT)
2287
+ tx += (maxLineWidth-lineWidth);
2288
+
2289
+ glyphs.push({
2290
+ position: [tx, y],
2291
+ data: glyph,
2292
+ index: i,
2293
+ line: lineIndex
2294
+ });
2295
+
2296
+ //move pen forward
2297
+ x += glyph.xadvance + letterSpacing;
2298
+ lastGlyph = glyph;
2299
+ }
2300
+ }
2301
+
2302
+ //next line down
2303
+ y += lineHeight;
2304
+ x = 0;
2305
+ });
2306
+ this._linesTotal = lines.length;
2307
+ };
2308
+
2309
+ TextLayout.prototype._setupSpaceGlyphs = function(font) {
2310
+ //These are fallbacks, when the font doesn't include
2311
+ //' ' or '\t' glyphs
2312
+ this._fallbackSpaceGlyph = null;
2313
+ this._fallbackTabGlyph = null;
2314
+
2315
+ if (!font.chars || font.chars.length === 0)
2316
+ return
2317
+
2318
+ //try to get space glyph
2319
+ //then fall back to the 'm' or 'w' glyphs
2320
+ //then fall back to the first glyph available
2321
+ var space = getGlyphById(font, SPACE_ID)
2322
+ || getMGlyph(font)
2323
+ || font.chars[0];
2324
+
2325
+ //and create a fallback for tab
2326
+ var tabWidth = this._opt.tabSize * space.xadvance;
2327
+ this._fallbackSpaceGlyph = space;
2328
+ this._fallbackTabGlyph = xtend(space, {
2329
+ x: 0, y: 0, xadvance: tabWidth, id: TAB_ID,
2330
+ xoffset: 0, yoffset: 0, width: 0, height: 0
2331
+ });
2332
+ };
2333
+
2334
+ TextLayout.prototype.getGlyph = function(font, id) {
2335
+ var glyph = getGlyphById(font, id);
2336
+ if (glyph)
2337
+ return glyph
2338
+ else if (id === TAB_ID)
2339
+ return this._fallbackTabGlyph
2340
+ else if (id === SPACE_ID)
2341
+ return this._fallbackSpaceGlyph
2342
+ return null
2343
+ };
2344
+
2345
+ TextLayout.prototype.computeMetrics = function(text, start, end, width) {
2346
+ var letterSpacing = this._opt.letterSpacing || 0;
2347
+ var font = this._opt.font;
2348
+ var curPen = 0;
2349
+ var curWidth = 0;
2350
+ var count = 0;
2351
+ var glyph;
2352
+ var lastGlyph;
2353
+
2354
+ if (!font.chars || font.chars.length === 0) {
2355
+ return {
2356
+ start: start,
2357
+ end: start,
2358
+ width: 0
2359
+ }
2360
+ }
2361
+
2362
+ end = Math.min(text.length, end);
2363
+ for (var i=start; i < end; i++) {
2364
+ var id = text.charCodeAt(i);
2365
+ var glyph = this.getGlyph(font, id);
2366
+
2367
+ if (glyph) {
2368
+ //move pen forward
2369
+ glyph.xoffset;
2370
+ var kern = lastGlyph ? getKerning(font, lastGlyph.id, glyph.id) : 0;
2371
+ curPen += kern;
2372
+
2373
+ var nextPen = curPen + glyph.xadvance + letterSpacing;
2374
+ var nextWidth = curPen + glyph.width;
2375
+
2376
+ //we've hit our limit; we can't move onto the next glyph
2377
+ if (nextWidth >= width || nextPen >= width)
2378
+ break
2379
+
2380
+ //otherwise continue along our line
2381
+ curPen = nextPen;
2382
+ curWidth = nextWidth;
2383
+ lastGlyph = glyph;
2384
+ }
2385
+ count++;
2386
+ }
2387
+
2388
+ //make sure rightmost edge lines up with rendered glyphs
2389
+ if (lastGlyph)
2390
+ curWidth += lastGlyph.xoffset;
2391
+
2392
+ return {
2393
+ start: start,
2394
+ end: start + count,
2395
+ width: curWidth
2396
+ }
2397
+ }
2398
+
2399
+ //getters for the private vars
2400
+ ;['width', 'height',
2401
+ 'descender', 'ascender',
2402
+ 'xHeight', 'baseline',
2403
+ 'capHeight',
2404
+ 'lineHeight' ].forEach(addGetter);
2405
+
2406
+ function addGetter(name) {
2407
+ Object.defineProperty(TextLayout.prototype, name, {
2408
+ get: wrapper(name),
2409
+ configurable: true
2410
+ });
2411
+ }
2412
+
2413
+ //create lookups for private vars
2414
+ function wrapper(name) {
2415
+ return (new Function([
2416
+ 'return function '+name+'() {',
2417
+ ' return this._'+name,
2418
+ '}'
2419
+ ].join('\n')))()
2420
+ }
2421
+
2422
+ function getGlyphById(font, id) {
2423
+ if (!font.chars || font.chars.length === 0)
2424
+ return null
2425
+
2426
+ var glyphIdx = findChar(font.chars, id);
2427
+ if (glyphIdx >= 0)
2428
+ return font.chars[glyphIdx]
2429
+ return null
2430
+ }
2431
+
2432
+ function getXHeight(font) {
2433
+ for (var i=0; i<X_HEIGHTS.length; i++) {
2434
+ var id = X_HEIGHTS[i].charCodeAt(0);
2435
+ var idx = findChar(font.chars, id);
2436
+ if (idx >= 0)
2437
+ return font.chars[idx].height
2438
+ }
2439
+ return 0
2440
+ }
2441
+
2442
+ function getMGlyph(font) {
2443
+ for (var i=0; i<M_WIDTHS.length; i++) {
2444
+ var id = M_WIDTHS[i].charCodeAt(0);
2445
+ var idx = findChar(font.chars, id);
2446
+ if (idx >= 0)
2447
+ return font.chars[idx]
2448
+ }
2449
+ return 0
2450
+ }
2451
+
2452
+ function getCapHeight(font) {
2453
+ for (var i=0; i<CAP_HEIGHTS.length; i++) {
2454
+ var id = CAP_HEIGHTS[i].charCodeAt(0);
2455
+ var idx = findChar(font.chars, id);
2456
+ if (idx >= 0)
2457
+ return font.chars[idx].height
2458
+ }
2459
+ return 0
2460
+ }
2461
+
2462
+ function getKerning(font, left, right) {
2463
+ if (!font.kernings || font.kernings.length === 0)
2464
+ return 0
2465
+
2466
+ var table = font.kernings;
2467
+ for (var i=0; i<table.length; i++) {
2468
+ var kern = table[i];
2469
+ if (kern.first === left && kern.second === right)
2470
+ return kern.amount
2471
+ }
2472
+ return 0
2473
+ }
2474
+
2475
+ function getAlignType(align) {
2476
+ if (align === 'center')
2477
+ return ALIGN_CENTER
2478
+ else if (align === 'right')
2479
+ return ALIGN_RIGHT
2480
+ return ALIGN_LEFT
2481
+ }
2482
+
2483
+ function findChar (array, value, start) {
2484
+ start = start || 0;
2485
+ for (var i = start; i < array.length; i++) {
2486
+ if (array[i].id === value) {
2487
+ return i
2488
+ }
2489
+ }
2490
+ return -1
2491
+ }
2492
+ return layoutBmfontText;
2493
+ }
2494
+
2495
+ var inherits_browser = {exports: {}};
2496
+
2497
+ var hasRequiredInherits_browser;
2498
+
2499
+ function requireInherits_browser () {
2500
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
2501
+ hasRequiredInherits_browser = 1;
2502
+ if (typeof Object.create === 'function') {
2503
+ // implementation from standard node.js 'util' module
2504
+ inherits_browser.exports = function inherits(ctor, superCtor) {
2505
+ if (superCtor) {
2506
+ ctor.super_ = superCtor;
2507
+ ctor.prototype = Object.create(superCtor.prototype, {
2508
+ constructor: {
2509
+ value: ctor,
2510
+ enumerable: false,
2511
+ writable: true,
2512
+ configurable: true
2513
+ }
2514
+ });
2515
+ }
2516
+ };
2517
+ } else {
2518
+ // old school shim for old browsers
2519
+ inherits_browser.exports = function inherits(ctor, superCtor) {
2520
+ if (superCtor) {
2521
+ ctor.super_ = superCtor;
2522
+ var TempCtor = function () {};
2523
+ TempCtor.prototype = superCtor.prototype;
2524
+ ctor.prototype = new TempCtor();
2525
+ ctor.prototype.constructor = ctor;
2526
+ }
2527
+ };
2528
+ }
2529
+ return inherits_browser.exports;
2530
+ }
2531
+
2532
+ var dtype;
2533
+ var hasRequiredDtype;
2534
+
2535
+ function requireDtype () {
2536
+ if (hasRequiredDtype) return dtype;
2537
+ hasRequiredDtype = 1;
2538
+ dtype = function(dtype) {
2539
+ switch (dtype) {
2540
+ case 'int8':
2541
+ return Int8Array
2542
+ case 'int16':
2543
+ return Int16Array
2544
+ case 'int32':
2545
+ return Int32Array
2546
+ case 'uint8':
2547
+ return Uint8Array
2548
+ case 'uint16':
2549
+ return Uint16Array
2550
+ case 'uint32':
2551
+ return Uint32Array
2552
+ case 'float32':
2553
+ return Float32Array
2554
+ case 'float64':
2555
+ return Float64Array
2556
+ case 'array':
2557
+ return Array
2558
+ case 'uint8_clamped':
2559
+ return Uint8ClampedArray
2560
+ }
2561
+ };
2562
+ return dtype;
2563
+ }
2564
+
2565
+ var anArray_1;
2566
+ var hasRequiredAnArray;
2567
+
2568
+ function requireAnArray () {
2569
+ if (hasRequiredAnArray) return anArray_1;
2570
+ hasRequiredAnArray = 1;
2571
+ var str = Object.prototype.toString;
2572
+
2573
+ anArray_1 = anArray;
2574
+
2575
+ function anArray(arr) {
2576
+ return (
2577
+ arr.BYTES_PER_ELEMENT
2578
+ && str.call(arr.buffer) === '[object ArrayBuffer]'
2579
+ || Array.isArray(arr)
2580
+ )
2581
+ }
2582
+ return anArray_1;
2583
+ }
2584
+
2585
+ /*!
2586
+ * Determine if an object is a Buffer
2587
+ *
2588
+ * @author Feross Aboukhadijeh <https://feross.org>
2589
+ * @license MIT
2590
+ */
2591
+
2592
+ var isBuffer_1;
2593
+ var hasRequiredIsBuffer;
2594
+
2595
+ function requireIsBuffer () {
2596
+ if (hasRequiredIsBuffer) return isBuffer_1;
2597
+ hasRequiredIsBuffer = 1;
2598
+ // The _isBuffer check is for Safari 5-7 support, because it's missing
2599
+ // Object.prototype.constructor. Remove this eventually
2600
+ isBuffer_1 = function (obj) {
2601
+ return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
2602
+ };
2603
+
2604
+ function isBuffer (obj) {
2605
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
2606
+ }
2607
+
2608
+ // For Node v0.10 support. Remove this eventually.
2609
+ function isSlowBuffer (obj) {
2610
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
2611
+ }
2612
+ return isBuffer_1;
2613
+ }
2614
+
2615
+ var quadIndices;
2616
+ var hasRequiredQuadIndices;
2617
+
2618
+ function requireQuadIndices () {
2619
+ if (hasRequiredQuadIndices) return quadIndices;
2620
+ hasRequiredQuadIndices = 1;
2621
+ var dtype = requireDtype();
2622
+ var anArray = requireAnArray();
2623
+ var isBuffer = requireIsBuffer();
2624
+
2625
+ var CW = [0, 2, 3];
2626
+ var CCW = [2, 1, 3];
2627
+
2628
+ quadIndices = function createQuadElements(array, opt) {
2629
+ //if user didn't specify an output array
2630
+ if (!array || !(anArray(array) || isBuffer(array))) {
2631
+ opt = array || {};
2632
+ array = null;
2633
+ }
2634
+
2635
+ if (typeof opt === 'number') //backwards-compatible
2636
+ opt = { count: opt };
2637
+ else
2638
+ opt = opt || {};
2639
+
2640
+ var type = typeof opt.type === 'string' ? opt.type : 'uint16';
2641
+ var count = typeof opt.count === 'number' ? opt.count : 1;
2642
+ var start = (opt.start || 0);
2643
+
2644
+ var dir = opt.clockwise !== false ? CW : CCW,
2645
+ a = dir[0],
2646
+ b = dir[1],
2647
+ c = dir[2];
2648
+
2649
+ var numIndices = count * 6;
2650
+
2651
+ var indices = array || new (dtype(type))(numIndices);
2652
+ for (var i = 0, j = 0; i < numIndices; i += 6, j += 4) {
2653
+ var x = i + start;
2654
+ indices[x + 0] = j + 0;
2655
+ indices[x + 1] = j + 1;
2656
+ indices[x + 2] = j + 2;
2657
+ indices[x + 3] = j + a;
2658
+ indices[x + 4] = j + b;
2659
+ indices[x + 5] = j + c;
2660
+ }
2661
+ return indices
2662
+ };
2663
+ return quadIndices;
2664
+ }
2665
+
2666
+ var vertices = {};
2667
+
2668
+ var hasRequiredVertices;
2669
+
2670
+ function requireVertices () {
2671
+ if (hasRequiredVertices) return vertices;
2672
+ hasRequiredVertices = 1;
2673
+ vertices.pages = function pages (glyphs) {
2674
+ var pages = new Float32Array(glyphs.length * 4 * 1);
2675
+ var i = 0;
2676
+ glyphs.forEach(function (glyph) {
2677
+ var id = glyph.data.page || 0;
2678
+ pages[i++] = id;
2679
+ pages[i++] = id;
2680
+ pages[i++] = id;
2681
+ pages[i++] = id;
2682
+ });
2683
+ return pages
2684
+ };
2685
+
2686
+ vertices.uvs = function uvs (glyphs, texWidth, texHeight, flipY) {
2687
+ var uvs = new Float32Array(glyphs.length * 4 * 2);
2688
+ var i = 0;
2689
+ glyphs.forEach(function (glyph) {
2690
+ var bitmap = glyph.data;
2691
+ var bw = (bitmap.x + bitmap.width);
2692
+ var bh = (bitmap.y + bitmap.height);
2693
+
2694
+ // top left position
2695
+ var u0 = bitmap.x / texWidth;
2696
+ var v1 = bitmap.y / texHeight;
2697
+ var u1 = bw / texWidth;
2698
+ var v0 = bh / texHeight;
2699
+
2700
+ if (flipY) {
2701
+ v1 = (texHeight - bitmap.y) / texHeight;
2702
+ v0 = (texHeight - bh) / texHeight;
2703
+ }
2704
+
2705
+ // BL
2706
+ uvs[i++] = u0;
2707
+ uvs[i++] = v1;
2708
+ // TL
2709
+ uvs[i++] = u0;
2710
+ uvs[i++] = v0;
2711
+ // TR
2712
+ uvs[i++] = u1;
2713
+ uvs[i++] = v0;
2714
+ // BR
2715
+ uvs[i++] = u1;
2716
+ uvs[i++] = v1;
2717
+ });
2718
+ return uvs
2719
+ };
2720
+
2721
+ vertices.positions = function positions (glyphs) {
2722
+ var positions = new Float32Array(glyphs.length * 4 * 2);
2723
+ var i = 0;
2724
+ glyphs.forEach(function (glyph) {
2725
+ var bitmap = glyph.data;
2726
+
2727
+ // bottom left position
2728
+ var x = glyph.position[0] + bitmap.xoffset;
2729
+ var y = glyph.position[1] + bitmap.yoffset;
2730
+
2731
+ // quad size
2732
+ var w = bitmap.width;
2733
+ var h = bitmap.height;
2734
+
2735
+ // BL
2736
+ positions[i++] = x;
2737
+ positions[i++] = y;
2738
+ // TL
2739
+ positions[i++] = x;
2740
+ positions[i++] = y + h;
2741
+ // TR
2742
+ positions[i++] = x + w;
2743
+ positions[i++] = y + h;
2744
+ // BR
2745
+ positions[i++] = x + w;
2746
+ positions[i++] = y;
2747
+ });
2748
+ return positions
2749
+ };
2750
+ return vertices;
2751
+ }
2752
+
2753
+ var utils = {};
2754
+
2755
+ var hasRequiredUtils;
2756
+
2757
+ function requireUtils () {
2758
+ if (hasRequiredUtils) return utils;
2759
+ hasRequiredUtils = 1;
2760
+ var itemSize = 2;
2761
+ var box = { min: [0, 0], max: [0, 0] };
2762
+
2763
+ function bounds (positions) {
2764
+ var count = positions.length / itemSize;
2765
+ box.min[0] = positions[0];
2766
+ box.min[1] = positions[1];
2767
+ box.max[0] = positions[0];
2768
+ box.max[1] = positions[1];
2769
+
2770
+ for (var i = 0; i < count; i++) {
2771
+ var x = positions[i * itemSize + 0];
2772
+ var y = positions[i * itemSize + 1];
2773
+ box.min[0] = Math.min(x, box.min[0]);
2774
+ box.min[1] = Math.min(y, box.min[1]);
2775
+ box.max[0] = Math.max(x, box.max[0]);
2776
+ box.max[1] = Math.max(y, box.max[1]);
2777
+ }
2778
+ }
2779
+
2780
+ utils.computeBox = function (positions, output) {
2781
+ bounds(positions);
2782
+ output.min.set(box.min[0], box.min[1], 0);
2783
+ output.max.set(box.max[0], box.max[1], 0);
2784
+ };
2785
+
2786
+ utils.computeSphere = function (positions, output) {
2787
+ bounds(positions);
2788
+ var minX = box.min[0];
2789
+ var minY = box.min[1];
2790
+ var maxX = box.max[0];
2791
+ var maxY = box.max[1];
2792
+ var width = maxX - minX;
2793
+ var height = maxY - minY;
2794
+ var length = Math.sqrt(width * width + height * height);
2795
+ output.center.set(minX + width / 2, minY + height / 2, 0);
2796
+ output.radius = length / 2;
2797
+ };
2798
+ return utils;
2799
+ }
2800
+
2801
+ var threeBmfontText;
2802
+ var hasRequiredThreeBmfontText;
2803
+
2804
+ function requireThreeBmfontText () {
2805
+ if (hasRequiredThreeBmfontText) return threeBmfontText;
2806
+ hasRequiredThreeBmfontText = 1;
2807
+ var createLayout = requireLayoutBmfontText();
2808
+ var inherits = requireInherits_browser();
2809
+ var createIndices = requireQuadIndices();
2810
+
2811
+ var vertices = requireVertices();
2812
+ var utils = requireUtils();
2813
+
2814
+ var Base = THREE.BufferGeometry;
2815
+
2816
+ threeBmfontText = function createTextGeometry (opt) {
2817
+ return new TextGeometry(opt)
2818
+ };
2819
+
2820
+ function TextGeometry (opt) {
2821
+ Base.call(this);
2822
+
2823
+ if (typeof opt === 'string') {
2824
+ opt = { text: opt };
2825
+ }
2826
+
2827
+ // use these as default values for any subsequent
2828
+ // calls to update()
2829
+ this._opt = Object.assign({}, opt);
2830
+
2831
+ // also do an initial setup...
2832
+ if (opt) this.update(opt);
2833
+ }
2834
+
2835
+ inherits(TextGeometry, Base);
2836
+
2837
+ TextGeometry.prototype.update = function (opt) {
2838
+ if (typeof opt === 'string') {
2839
+ opt = { text: opt };
2840
+ }
2841
+
2842
+ // use constructor defaults
2843
+ opt = Object.assign({}, this._opt, opt);
2844
+
2845
+ if (!opt.font) {
2846
+ throw new TypeError('must specify a { font } in options')
2847
+ }
2848
+
2849
+ this.layout = createLayout(opt);
2850
+
2851
+ // get vec2 texcoords
2852
+ var flipY = opt.flipY !== false;
2853
+
2854
+ // the desired BMFont data
2855
+ var font = opt.font;
2856
+
2857
+ // determine texture size from font file
2858
+ var texWidth = font.common.scaleW;
2859
+ var texHeight = font.common.scaleH;
2860
+
2861
+ // get visible glyphs
2862
+ var glyphs = this.layout.glyphs.filter(function (glyph) {
2863
+ var bitmap = glyph.data;
2864
+ return bitmap.width * bitmap.height > 0
2865
+ });
2866
+
2867
+ // provide visible glyphs for convenience
2868
+ this.visibleGlyphs = glyphs;
2869
+
2870
+ // get common vertex data
2871
+ var positions = vertices.positions(glyphs);
2872
+ var uvs = vertices.uvs(glyphs, texWidth, texHeight, flipY);
2873
+ var indices = createIndices([], {
2874
+ clockwise: true,
2875
+ type: 'uint16',
2876
+ count: glyphs.length
2877
+ });
2878
+
2879
+ // update vertex data
2880
+ this.setIndex(indices);
2881
+ this.setAttribute('position', new THREE.BufferAttribute(positions, 2));
2882
+ this.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
2883
+
2884
+ // update multipage data
2885
+ if (!opt.multipage && 'page' in this.attributes) {
2886
+ // disable multipage rendering
2887
+ this.removeAttribute('page');
2888
+ } else if (opt.multipage) {
2889
+ // enable multipage rendering
2890
+ var pages = vertices.pages(glyphs);
2891
+ this.setAttribute('page', new THREE.BufferAttribute(pages, 1));
2892
+ }
2893
+ };
2894
+
2895
+ TextGeometry.prototype.computeBoundingSphere = function () {
2896
+ if (this.boundingSphere === null) {
2897
+ this.boundingSphere = new THREE.Sphere();
2898
+ }
2899
+
2900
+ var positions = this.attributes.position.array;
2901
+ var itemSize = this.attributes.position.itemSize;
2902
+ if (!positions || !itemSize || positions.length < 2) {
2903
+ this.boundingSphere.radius = 0;
2904
+ this.boundingSphere.center.set(0, 0, 0);
2905
+ return
2906
+ }
2907
+ utils.computeSphere(positions, this.boundingSphere);
2908
+ if (isNaN(this.boundingSphere.radius)) {
2909
+ console.error('THREE.BufferGeometry.computeBoundingSphere(): ' +
2910
+ 'Computed radius is NaN. The ' +
2911
+ '"position" attribute is likely to have NaN values.');
2912
+ }
2913
+ };
2914
+
2915
+ TextGeometry.prototype.computeBoundingBox = function () {
2916
+ if (this.boundingBox === null) {
2917
+ this.boundingBox = new THREE.Box3();
2918
+ }
2919
+
2920
+ var bbox = this.boundingBox;
2921
+ var positions = this.attributes.position.array;
2922
+ var itemSize = this.attributes.position.itemSize;
2923
+ if (!positions || !itemSize || positions.length < 2) {
2924
+ bbox.makeEmpty();
2925
+ return
2926
+ }
2927
+ utils.computeBox(positions, bbox);
2928
+ };
2929
+ return threeBmfontText;
2930
+ }
2931
+
2932
+ var threeBmfontTextExports = requireThreeBmfontText();
2933
+ const createGeometry = /*@__PURE__*/getDefaultExportFromCjs(threeBmfontTextExports);
2934
+
2935
+ /*
2936
+ object-assign
2937
+ (c) Sindre Sorhus
2938
+ @license MIT
2939
+ */
2940
+
2941
+ var objectAssign;
2942
+ var hasRequiredObjectAssign;
2943
+
2944
+ function requireObjectAssign () {
2945
+ if (hasRequiredObjectAssign) return objectAssign;
2946
+ hasRequiredObjectAssign = 1;
2947
+ /* eslint-disable no-unused-vars */
2948
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
2949
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
2950
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
2951
+
2952
+ function toObject(val) {
2953
+ if (val === null || val === undefined) {
2954
+ throw new TypeError('Object.assign cannot be called with null or undefined');
2955
+ }
2956
+
2957
+ return Object(val);
2958
+ }
2959
+
2960
+ function shouldUseNative() {
2961
+ try {
2962
+ if (!Object.assign) {
2963
+ return false;
2964
+ }
2965
+
2966
+ // Detect buggy property enumeration order in older V8 versions.
2967
+
2968
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
2969
+ var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
2970
+ test1[5] = 'de';
2971
+ if (Object.getOwnPropertyNames(test1)[0] === '5') {
2972
+ return false;
2973
+ }
2974
+
2975
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
2976
+ var test2 = {};
2977
+ for (var i = 0; i < 10; i++) {
2978
+ test2['_' + String.fromCharCode(i)] = i;
2979
+ }
2980
+ var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
2981
+ return test2[n];
2982
+ });
2983
+ if (order2.join('') !== '0123456789') {
2984
+ return false;
2985
+ }
2986
+
2987
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
2988
+ var test3 = {};
2989
+ 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
2990
+ test3[letter] = letter;
2991
+ });
2992
+ if (Object.keys(Object.assign({}, test3)).join('') !==
2993
+ 'abcdefghijklmnopqrst') {
2994
+ return false;
2995
+ }
2996
+
2997
+ return true;
2998
+ } catch (err) {
2999
+ // We don't expect any of the above to throw, but better to be safe.
3000
+ return false;
3001
+ }
3002
+ }
3003
+
3004
+ objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
3005
+ var from;
3006
+ var to = toObject(target);
3007
+ var symbols;
3008
+
3009
+ for (var s = 1; s < arguments.length; s++) {
3010
+ from = Object(arguments[s]);
3011
+
3012
+ for (var key in from) {
3013
+ if (hasOwnProperty.call(from, key)) {
3014
+ to[key] = from[key];
3015
+ }
3016
+ }
3017
+
3018
+ if (getOwnPropertySymbols) {
3019
+ symbols = getOwnPropertySymbols(from);
3020
+ for (var i = 0; i < symbols.length; i++) {
3021
+ if (propIsEnumerable.call(from, symbols[i])) {
3022
+ to[symbols[i]] = from[symbols[i]];
3023
+ }
3024
+ }
3025
+ }
3026
+ }
3027
+
3028
+ return to;
3029
+ };
3030
+ return objectAssign;
3031
+ }
3032
+
3033
+ var msdf;
3034
+ var hasRequiredMsdf;
3035
+
3036
+ function requireMsdf () {
3037
+ if (hasRequiredMsdf) return msdf;
3038
+ hasRequiredMsdf = 1;
3039
+ var assign = requireObjectAssign();
3040
+
3041
+ msdf = function createMSDFShader (opt) {
3042
+ opt = opt || {};
3043
+ var opacity = typeof opt.opacity === 'number' ? opt.opacity : 1;
3044
+ var alphaTest = typeof opt.alphaTest === 'number' ? opt.alphaTest : 0.0001;
3045
+ var precision = opt.precision || 'highp';
3046
+ var color = opt.color;
3047
+ var map = opt.map;
3048
+ var negate = typeof opt.negate === 'boolean' ? opt.negate : true;
3049
+
3050
+ // remove to satisfy r73
3051
+ delete opt.map;
3052
+ delete opt.color;
3053
+ delete opt.precision;
3054
+ delete opt.opacity;
3055
+ delete opt.negate;
3056
+
3057
+ return assign({
3058
+ uniforms: {
3059
+ opacity: { type: 'f', value: opacity },
3060
+ map: { type: 't', value: map || new THREE.Texture() },
3061
+ color: { type: 'c', value: new THREE.Color(color) }
3062
+ },
3063
+ vertexShader: [
3064
+ 'attribute vec2 uv;',
3065
+ 'attribute vec4 position;',
3066
+ 'uniform mat4 projectionMatrix;',
3067
+ 'uniform mat4 modelViewMatrix;',
3068
+ 'varying vec2 vUv;',
3069
+ 'void main() {',
3070
+ 'vUv = uv;',
3071
+ 'gl_Position = projectionMatrix * modelViewMatrix * position;',
3072
+ '}'
3073
+ ].join('\n'),
3074
+ fragmentShader: [
3075
+ '#ifdef GL_OES_standard_derivatives',
3076
+ '#extension GL_OES_standard_derivatives : enable',
3077
+ '#endif',
3078
+ 'precision ' + precision + ' float;',
3079
+ 'uniform float opacity;',
3080
+ 'uniform vec3 color;',
3081
+ 'uniform sampler2D map;',
3082
+ 'varying vec2 vUv;',
3083
+
3084
+ 'float median(float r, float g, float b) {',
3085
+ ' return max(min(r, g), min(max(r, g), b));',
3086
+ '}',
3087
+
3088
+ 'void main() {',
3089
+ ' vec3 sample = ' + (negate ? '1.0 - ' : '') + 'texture2D(map, vUv).rgb;',
3090
+ ' float sigDist = median(sample.r, sample.g, sample.b) - 0.5;',
3091
+ ' float alpha = clamp(sigDist/fwidth(sigDist) + 0.5, 0.0, 1.0);',
3092
+ ' gl_FragColor = vec4(color.xyz, alpha * opacity);',
3093
+ alphaTest === 0
3094
+ ? ''
3095
+ : ' if (gl_FragColor.a < ' + alphaTest + ') discard;',
3096
+ '}'
3097
+ ].join('\n')
3098
+ }, opt);
3099
+ };
3100
+ return msdf;
3101
+ }
3102
+
3103
+ var msdfExports = requireMsdf();
3104
+ const MSDFShader = /*@__PURE__*/getDefaultExportFromCjs(msdfExports);
3105
+
3106
+ const vertexShader = `
3107
+ varying vec2 vUv;
3108
+ varying vec3 vPos;
3109
+
3110
+ void main() {
3111
+ vUv = uv;
3112
+ vPos = position;
3113
+
3114
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.);
3115
+ }
3116
+ `;
3117
+ const fragmentShader = `
3118
+ varying vec2 vUv;
3119
+ varying vec3 vPos;
3120
+
3121
+ uniform sampler2D uTexture;
3122
+ uniform float uTime;
3123
+
3124
+ void main() {
3125
+ float time = uTime * 0.5;
3126
+ vec2 repeat = -vec2(12., 3.);
3127
+ // To repeat the uvs we need to multiply them by a scalar
3128
+ // and then get the fractional part of it so they from 0 to 1
3129
+ // To move them continuously we have to add time
3130
+ // to the x or y component, to change the direction
3131
+ vec2 uv = fract(vUv * repeat - vec2(time, 0.)); // The sign of time change direction of movement
3132
+
3133
+ // Fake shadow
3134
+ float shadow = clamp(vPos.z / 5., 0., 1.);
3135
+
3136
+ vec3 texture = texture2D(uTexture, uv).rgb;
3137
+ // texture *= vec3(uv.x, uv.y, 1.); // To help visualize the repeated uvs
3138
+
3139
+ gl_FragColor = vec4(texture * shadow, 1.);
3140
+ }
3141
+ `;
3142
+
3143
+ class GL {
3144
+ renderer;
3145
+ camera;
3146
+ scene;
3147
+ controls;
3148
+ clock;
3149
+ rt;
3150
+ rtCamera;
3151
+ rtScene;
3152
+ text;
3153
+ mesh;
3154
+ geometry;
3155
+ material;
3156
+ fontGeometry;
3157
+ fontMaterial;
3158
+ loader;
3159
+ constructor() {
3160
+ this.renderer = new index.WebGLRenderer({
3161
+ alpha: true
3162
+ });
3163
+ this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
3164
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
3165
+ this.renderer.setClearColor(0, 1);
3166
+ document.body.appendChild(this.renderer.domElement);
3167
+ this.camera = new index.PerspectiveCamera(
3168
+ 45,
3169
+ window.innerWidth / window.innerHeight,
3170
+ 1,
3171
+ 1e3
3172
+ );
3173
+ this.camera.position.z = 60;
3174
+ this.scene = new index.Scene();
3175
+ this.controls = new (OrbitControls(index.THREE))(
3176
+ this.camera,
3177
+ this.renderer.domElement
3178
+ );
3179
+ this.clock = new index.Clock();
3180
+ }
3181
+ init() {
3182
+ loadFont("/fonts/orbitron/orbitron-black.fnt", (_, font) => {
3183
+ this.fontGeometry = createGeometry({
3184
+ font,
3185
+ text: "ENDLESS"
3186
+ });
3187
+ this.loader = new index.TextureLoader();
3188
+ this.loader.load("/fonts/orbitron/orbitron-black.png", (texture) => {
3189
+ this.fontMaterial = new index.RawShaderMaterial(
3190
+ MSDFShader({
3191
+ map: texture,
3192
+ side: index.DoubleSide,
3193
+ transparent: true,
3194
+ negate: false,
3195
+ color: 16777215
3196
+ })
3197
+ );
3198
+ this.createRenderTarget();
3199
+ this.createMesh();
3200
+ this.animate();
3201
+ this.addEvents();
3202
+ });
3203
+ });
3204
+ }
3205
+ createRenderTarget() {
3206
+ this.rt = new index.WebGLRenderTarget(window.innerWidth, window.innerHeight);
3207
+ this.rtCamera = new index.PerspectiveCamera(45, 1, 0.1, 1e3);
3208
+ this.rtCamera.position.z = 2.5;
3209
+ this.rtScene = new index.Scene();
3210
+ this.rtScene.background = new index.Color("#000000");
3211
+ this.text = new index.Mesh(this.fontGeometry, this.fontMaterial);
3212
+ this.text.position.set(-0.965, -0.525, 0);
3213
+ this.text.rotation.set(Math.PI, 0, 0);
3214
+ this.text.scale.set(8e-3, 0.04, 1);
3215
+ this.rtScene.add(this.text);
3216
+ }
3217
+ createMesh() {
3218
+ if (!this.rt) return;
3219
+ this.geometry = new index.TorusKnotGeometry(9, 3, 768, 3, 4, 3);
3220
+ this.material = new index.ShaderMaterial({
3221
+ vertexShader,
3222
+ fragmentShader,
3223
+ uniforms: {
3224
+ uTime: { value: 0 },
3225
+ uTexture: { value: this.rt.texture }
3226
+ }
3227
+ });
3228
+ this.mesh = new index.Mesh(this.geometry, this.material);
3229
+ this.scene.add(this.mesh);
3230
+ }
3231
+ animate() {
3232
+ requestAnimationFrame(this.animate.bind(this));
3233
+ this.render();
3234
+ }
3235
+ render() {
3236
+ if (!this.material || !this.rt || !this.rtScene || !this.rtCamera) return;
3237
+ this.controls.update();
3238
+ this.material.uniforms.uTime.value = this.clock.getElapsedTime();
3239
+ this.renderer.setRenderTarget(this.rt);
3240
+ this.renderer.render(this.rtScene, this.rtCamera);
3241
+ this.renderer.setRenderTarget(null);
3242
+ this.renderer.render(this.scene, this.camera);
3243
+ }
3244
+ addEvents() {
3245
+ window.addEventListener("resize", this.resize.bind(this));
3246
+ }
3247
+ resize() {
3248
+ const width = window.innerWidth;
3249
+ const height = window.innerHeight;
3250
+ this.camera.aspect = width / height;
3251
+ this.camera.updateProjectionMatrix();
3252
+ this.renderer.setSize(width, height);
3253
+ }
3254
+ }
3255
+
3256
+ exports.GL = GL;