@tarsis/toolkit 0.3.2 → 0.4.1

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