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