@antv/g-canvas 1.1.3-alpha.1 → 1.1.5

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.
package/dist/index.umd.js CHANGED
@@ -435,7 +435,6 @@
435
435
  var _class;
436
436
 
437
437
  var DOMInteractionPlugin_1;
438
- var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
439
438
  /**
440
439
  * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
441
440
  */
@@ -451,8 +450,7 @@
451
450
  _proto.apply = function apply(renderingService) {
452
451
  var _this = this;
453
452
 
454
- var canvas = this.renderingContext.root.ownerDocument.defaultView;
455
- var SUPPORT_ONLY_TOUCH = canvas.supportTouchEvent && MOBILE_REGEX.test(navigator.userAgent);
453
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
456
454
 
457
455
  var onPointerMove = function onPointerMove(ev) {
458
456
  renderingService.hooks.pointerMove.call(ev);
@@ -533,24 +531,25 @@
533
531
  while (1) {
534
532
  switch (_context.prev = _context.next) {
535
533
  case 0:
536
- $el = _this.contextService.getDomElement();
534
+ $el = _this.contextService.getDomElement(); // @ts-ignore
537
535
 
538
- if (canvas.supportPointerEvent) {
539
- addPointerEventListener($el);
536
+ if (globalThis.navigator.msPointerEnabled) {
537
+ // @ts-ignore
538
+ $el.style.msContentZooming = 'none'; // @ts-ignore
539
+
540
+ $el.style.msTouchAction = 'none';
541
+ } else if (canvas.supportsPointerEvents) {
542
+ $el.style.touchAction = 'none';
540
543
  }
541
544
 
542
- if (SUPPORT_ONLY_TOUCH) {
543
- addTouchEventListener($el);
544
- } else if (!canvas.supportTouchEvent) {
545
- if (!canvas.supportPointerEvent) {
546
- addMouseEventListener($el);
547
- }
545
+ if (canvas.supportsPointerEvents) {
546
+ addPointerEventListener($el);
548
547
  } else {
549
- addTouchEventListener($el);
548
+ addMouseEventListener($el);
549
+ }
550
550
 
551
- if (!canvas.supportPointerEvent) {
552
- addMouseEventListener($el);
553
- }
551
+ if (canvas.supportsTouchEvents) {
552
+ addTouchEventListener($el);
554
553
  } // use passive event listeners
555
554
  // @see https://zhuanlan.zhihu.com/p/24555031
556
555
 
@@ -560,7 +559,7 @@
560
559
  capture: true
561
560
  });
562
561
 
563
- case 4:
562
+ case 5:
564
563
  case "end":
565
564
  return _context.stop();
566
565
  }
@@ -570,22 +569,14 @@
570
569
  renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
571
570
  var $el = _this.contextService.getDomElement();
572
571
 
573
- if (canvas.supportPointerEvent) {
572
+ if (canvas.supportsPointerEvents) {
574
573
  removePointerEventListener($el);
574
+ } else {
575
+ removeMouseEventListener($el);
575
576
  }
576
577
 
577
- if (SUPPORT_ONLY_TOUCH) {
578
- removeTouchEventListener($el);
579
- } else if (!canvas.supportTouchEvent) {
580
- if (!canvas.supportPointerEvent) {
581
- removeMouseEventListener($el);
582
- }
583
- } else {
578
+ if (canvas.supportsTouchEvents) {
584
579
  removeTouchEventListener($el);
585
-
586
- if (!canvas.supportPointerEvent) {
587
- removeMouseEventListener($el);
588
- }
589
580
  }
590
581
 
591
582
  $el.removeEventListener('wheel', onPointerWheel, true);
@@ -1194,1029 +1185,1084 @@
1194
1185
  }
1195
1186
  }
1196
1187
 
1197
- var StyleRendererFactory = manaSyringe.Syringe.defineToken('StyleRendererFactory');
1198
- var CircleRendererContribution = manaSyringe.Syringe.defineToken('CircleRenderer', {
1199
- multiple: false
1200
- });
1201
- var EllipseRendererContribution = manaSyringe.Syringe.defineToken('EllipseRenderer', {
1202
- multiple: false
1203
- });
1204
- var RectRendererContribution = manaSyringe.Syringe.defineToken('RectRenderer', {
1205
- multiple: false
1206
- });
1207
- var LineRendererContribution = manaSyringe.Syringe.defineToken('LineRenderer', {
1208
- multiple: false
1209
- });
1210
- var PolylineRendererContribution = manaSyringe.Syringe.defineToken('PolylineRenderer', {
1211
- multiple: false
1212
- });
1213
- var PolygonRendererContribution = manaSyringe.Syringe.defineToken('PolygonRenderer', {
1214
- multiple: false
1215
- });
1216
- var PathRendererContribution = manaSyringe.Syringe.defineToken('PathRenderer', {
1217
- multiple: false
1218
- });
1219
- var TextRendererContribution = manaSyringe.Syringe.defineToken('TextRenderer', {
1220
- multiple: false
1221
- });
1222
- var ImageRendererContribution = manaSyringe.Syringe.defineToken('ImageRenderer', {
1223
- multiple: false
1224
- });
1225
-
1226
- var ImagePool = /*#__PURE__*/function () {
1227
- function ImagePool() {
1228
- this.imageCache = {};
1229
- this.patternCache = {};
1230
- this.canvasConfig = void 0;
1231
- }
1188
+ function _regeneratorRuntime$1() {
1189
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1190
+ _regeneratorRuntime$1 = function _regeneratorRuntime() {
1191
+ return exports;
1192
+ };
1232
1193
 
1233
- var _proto = ImagePool.prototype;
1194
+ var exports = {},
1195
+ Op = Object.prototype,
1196
+ hasOwn = Op.hasOwnProperty,
1197
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
1198
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
1199
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1200
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1234
1201
 
1235
- _proto.getImageSync = function getImageSync(src) {
1236
- return this.imageCache[src];
1237
- };
1202
+ function define(obj, key, value) {
1203
+ return Object.defineProperty(obj, key, {
1204
+ value: value,
1205
+ enumerable: !0,
1206
+ configurable: !0,
1207
+ writable: !0
1208
+ }), obj[key];
1209
+ }
1238
1210
 
1239
- _proto.getOrCreateImage = function getOrCreateImage(src) {
1240
- var _this = this;
1211
+ try {
1212
+ define({}, "");
1213
+ } catch (err) {
1214
+ define = function define(obj, key, value) {
1215
+ return obj[key] = value;
1216
+ };
1217
+ }
1241
1218
 
1242
- if (this.imageCache[src]) {
1243
- return Promise.resolve(this.imageCache[src]);
1244
- } // @see https://github.com/antvis/g/issues/938
1219
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1220
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1221
+ generator = Object.create(protoGenerator.prototype),
1222
+ context = new Context(tryLocsList || []);
1223
+ return generator._invoke = function (innerFn, self, context) {
1224
+ var state = "suspendedStart";
1225
+ return function (method, arg) {
1226
+ if ("executing" === state) throw new Error("Generator is already running");
1245
1227
 
1228
+ if ("completed" === state) {
1229
+ if ("throw" === method) throw arg;
1230
+ return doneResult();
1231
+ }
1246
1232
 
1247
- var createImage = this.canvasConfig.createImage;
1248
- return new Promise(function (resolve, reject) {
1249
- var image;
1233
+ for (context.method = method, context.arg = arg;;) {
1234
+ var delegate = context.delegate;
1250
1235
 
1251
- if (createImage) {
1252
- image = createImage(src);
1253
- } else if (g.isBrowser) {
1254
- image = new window.Image();
1255
- }
1236
+ if (delegate) {
1237
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1256
1238
 
1257
- if (image) {
1258
- image.onload = function () {
1259
- resolve(image);
1260
- };
1239
+ if (delegateResult) {
1240
+ if (delegateResult === ContinueSentinel) continue;
1241
+ return delegateResult;
1242
+ }
1243
+ }
1261
1244
 
1262
- image.onerror = function (ev) {
1263
- reject(ev);
1264
- };
1245
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1246
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
1247
+ context.dispatchException(context.arg);
1248
+ } else "return" === context.method && context.abrupt("return", context.arg);
1249
+ state = "executing";
1250
+ var record = tryCatch(innerFn, self, context);
1265
1251
 
1266
- image.crossOrigin = 'Anonymous';
1267
- image.src = src;
1268
- _this.imageCache[src] = image;
1269
- }
1270
- });
1271
- };
1252
+ if ("normal" === record.type) {
1253
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1254
+ return {
1255
+ value: record.arg,
1256
+ done: context.done
1257
+ };
1258
+ }
1272
1259
 
1273
- _proto.getPatternSync = function getPatternSync(pattern) {
1274
- var patternKey = this.generatePatternKey(pattern);
1260
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1261
+ }
1262
+ };
1263
+ }(innerFn, self, context), generator;
1264
+ }
1275
1265
 
1276
- if (this.patternCache[patternKey]) {
1277
- return this.patternCache[patternKey];
1266
+ function tryCatch(fn, obj, arg) {
1267
+ try {
1268
+ return {
1269
+ type: "normal",
1270
+ arg: fn.call(obj, arg)
1271
+ };
1272
+ } catch (err) {
1273
+ return {
1274
+ type: "throw",
1275
+ arg: err
1276
+ };
1278
1277
  }
1279
- };
1278
+ }
1280
1279
 
1281
- _proto.createPattern = function createPattern(patternParams, context) {
1282
- var _this2 = this;
1280
+ exports.wrap = wrap;
1281
+ var ContinueSentinel = {};
1283
1282
 
1284
- return this.getOrCreateImage(patternParams.src).then(function (image) {
1285
- var patternKey = _this2.generatePatternKey(patternParams); // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
1283
+ function Generator() {}
1286
1284
 
1285
+ function GeneratorFunction() {}
1287
1286
 
1288
- var pattern = context.createPattern(image, patternParams.repetition);
1287
+ function GeneratorFunctionPrototype() {}
1289
1288
 
1290
- if (pattern) {
1291
- _this2.patternCache[patternKey] = pattern;
1292
- }
1289
+ var IteratorPrototype = {};
1290
+ define(IteratorPrototype, iteratorSymbol, function () {
1291
+ return this;
1292
+ });
1293
+ var getProto = Object.getPrototypeOf,
1294
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1295
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1296
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1293
1297
 
1294
- return _this2.patternCache[patternKey];
1298
+ function defineIteratorMethods(prototype) {
1299
+ ["next", "throw", "return"].forEach(function (method) {
1300
+ define(prototype, method, function (arg) {
1301
+ return this._invoke(method, arg);
1302
+ });
1295
1303
  });
1296
- };
1304
+ }
1297
1305
 
1298
- _proto.generatePatternKey = function generatePatternKey(pattern) {
1299
- var src = pattern.src,
1300
- repetition = pattern.repetition;
1301
- return "pattern-" + src + "-" + repetition;
1302
- };
1306
+ function AsyncIterator(generator, PromiseImpl) {
1307
+ function invoke(method, arg, resolve, reject) {
1308
+ var record = tryCatch(generator[method], generator, arg);
1303
1309
 
1304
- return ImagePool;
1305
- }();
1310
+ if ("throw" !== record.type) {
1311
+ var result = record.arg,
1312
+ value = result.value;
1313
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1314
+ invoke("next", value, resolve, reject);
1315
+ }, function (err) {
1316
+ invoke("throw", err, resolve, reject);
1317
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1318
+ result.value = unwrapped, resolve(result);
1319
+ }, function (error) {
1320
+ return invoke("throw", error, resolve, reject);
1321
+ });
1322
+ }
1306
1323
 
1307
- __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
1324
+ reject(record.arg);
1325
+ }
1308
1326
 
1309
- ImagePool = __decorate([manaSyringe.singleton()], ImagePool);
1327
+ var previousPromise;
1310
1328
 
1311
- var ImageRenderer = /*#__PURE__*/function () {
1312
- function ImageRenderer() {
1313
- this.imagePool = void 0;
1329
+ this._invoke = function (method, arg) {
1330
+ function callInvokeWithMethodAndArg() {
1331
+ return new PromiseImpl(function (resolve, reject) {
1332
+ invoke(method, arg, resolve, reject);
1333
+ });
1334
+ }
1335
+
1336
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1337
+ };
1314
1338
  }
1315
1339
 
1316
- var _proto = ImageRenderer.prototype;
1340
+ function maybeInvokeDelegate(delegate, context) {
1341
+ var method = delegate.iterator[context.method];
1317
1342
 
1318
- _proto.hash = function hash(parsedStyle) {
1319
- return '';
1320
- };
1343
+ if (undefined === method) {
1344
+ if (context.delegate = null, "throw" === context.method) {
1345
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
1346
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
1347
+ }
1321
1348
 
1322
- _proto.render = function render(context, parsedStyle) {
1323
- var width = parsedStyle.width,
1324
- height = parsedStyle.height,
1325
- img = parsedStyle.img;
1326
- var image;
1327
- var iw = width.value;
1328
- var ih = height.value;
1349
+ return ContinueSentinel;
1350
+ }
1329
1351
 
1330
- if (g.isString(img)) {
1331
- // image has been loaded in `mounted` hook
1332
- image = this.imagePool.getImageSync(img);
1333
- } else {
1334
- iw || (iw = img.width);
1335
- ih || (ih = img.height);
1336
- image = img;
1337
- }
1338
-
1339
- if (image) {
1340
- // node-canvas will throw the following err:
1341
- // Error: Image given has not completed loading
1342
- try {
1343
- context.drawImage(image, 0, 0, iw, ih);
1344
- } catch (e) {}
1345
- }
1346
- };
1352
+ var record = tryCatch(method, delegate.iterator, context.arg);
1353
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1354
+ var info = record.arg;
1355
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
1356
+ }
1347
1357
 
1348
- return ImageRenderer;
1349
- }();
1358
+ function pushTryEntry(locs) {
1359
+ var entry = {
1360
+ tryLoc: locs[0]
1361
+ };
1362
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1363
+ }
1350
1364
 
1351
- __decorate([manaSyringe.inject(ImagePool), __metadata("design:type", ImagePool)], ImageRenderer.prototype, "imagePool", void 0);
1365
+ function resetTryEntry(entry) {
1366
+ var record = entry.completion || {};
1367
+ record.type = "normal", delete record.arg, entry.completion = record;
1368
+ }
1352
1369
 
1353
- ImageRenderer = __decorate([manaSyringe.singleton({
1354
- token: ImageRendererContribution
1355
- })], ImageRenderer);
1370
+ function Context(tryLocsList) {
1371
+ this.tryEntries = [{
1372
+ tryLoc: "root"
1373
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1374
+ }
1356
1375
 
1357
- var TextRenderer = /*#__PURE__*/function () {
1358
- function TextRenderer() {}
1376
+ function values(iterable) {
1377
+ if (iterable) {
1378
+ var iteratorMethod = iterable[iteratorSymbol];
1379
+ if (iteratorMethod) return iteratorMethod.call(iterable);
1380
+ if ("function" == typeof iterable.next) return iterable;
1359
1381
 
1360
- var _proto = TextRenderer.prototype;
1382
+ if (!isNaN(iterable.length)) {
1383
+ var i = -1,
1384
+ next = function next() {
1385
+ for (; ++i < iterable.length;) {
1386
+ if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1387
+ }
1361
1388
 
1362
- _proto.hash = function hash(parsedStyle) {
1363
- return '';
1364
- };
1389
+ return next.value = undefined, next.done = !0, next;
1390
+ };
1365
1391
 
1366
- _proto.render = function render(context, parsedStyle, object) {
1367
- var lineWidth = parsedStyle.lineWidth,
1368
- textAlign = parsedStyle.textAlign,
1369
- textBaseline = parsedStyle.textBaseline,
1370
- lineJoin = parsedStyle.lineJoin,
1371
- _parsedStyle$miterLim = parsedStyle.miterLimit,
1372
- miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
1373
- _parsedStyle$letterSp = parsedStyle.letterSpacing,
1374
- letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
1375
- stroke = parsedStyle.stroke,
1376
- fill = parsedStyle.fill,
1377
- fillOpacity = parsedStyle.fillOpacity,
1378
- strokeOpacity = parsedStyle.strokeOpacity,
1379
- opacity = parsedStyle.opacity,
1380
- metrics = parsedStyle.metrics,
1381
- dx = parsedStyle.dx,
1382
- dy = parsedStyle.dy;
1383
- var font = metrics.font,
1384
- lines = metrics.lines,
1385
- height = metrics.height,
1386
- lineHeight = metrics.lineHeight,
1387
- lineMetrics = metrics.lineMetrics;
1388
- context.font = font;
1389
- context.lineWidth = lineWidth.value;
1390
- context.textAlign = textAlign.value;
1391
- context.textBaseline = textBaseline.value;
1392
- context.lineJoin = lineJoin.value;
1393
- context.miterLimit = miterLimit;
1394
- var linePositionY = 0; // handle vertical text baseline
1392
+ return next.next = next;
1393
+ }
1394
+ }
1395
1395
 
1396
- if (textBaseline.value === 'middle') {
1397
- linePositionY = -height / 2 - lineHeight / 2;
1398
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1399
- linePositionY = -height;
1400
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1401
- linePositionY = -lineHeight;
1402
- } // account for dx & dy
1396
+ return {
1397
+ next: doneResult
1398
+ };
1399
+ }
1403
1400
 
1401
+ function doneResult() {
1402
+ return {
1403
+ value: undefined,
1404
+ done: !0
1405
+ };
1406
+ }
1404
1407
 
1405
- var offsetX = 0;
1408
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1409
+ var ctor = "function" == typeof genFun && genFun.constructor;
1410
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1411
+ }, exports.mark = function (genFun) {
1412
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1413
+ }, exports.awrap = function (arg) {
1414
+ return {
1415
+ __await: arg
1416
+ };
1417
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1418
+ return this;
1419
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1420
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
1421
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1422
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1423
+ return result.done ? result.value : iter.next();
1424
+ });
1425
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1426
+ return this;
1427
+ }), define(Gp, "toString", function () {
1428
+ return "[object Generator]";
1429
+ }), exports.keys = function (object) {
1430
+ var keys = [];
1406
1431
 
1407
- if (dx && dx.unit === g.UnitType.kPixels) {
1408
- offsetX += dx.value;
1432
+ for (var key in object) {
1433
+ keys.push(key);
1409
1434
  }
1410
1435
 
1411
- if (dy && dy.unit === g.UnitType.kPixels) {
1412
- linePositionY += dy.value;
1413
- } // draw lines line by line
1414
-
1415
-
1416
- for (var i = 0; i < lines.length; i++) {
1417
- var linePositionX = lineWidth.value / 2 + offsetX;
1418
- linePositionY += lineHeight; // no need to re-position X, cause we already set text align
1419
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
1436
+ return keys.reverse(), function next() {
1437
+ for (; keys.length;) {
1438
+ var key = keys.pop();
1439
+ if (key in object) return next.value = key, next.done = !1, next;
1440
+ }
1420
1441
 
1421
- if (!g.isNil(stroke) && lineWidth && lineWidth.value) {
1422
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
1442
+ return next.done = !0, next;
1443
+ };
1444
+ }, exports.values = values, Context.prototype = {
1445
+ constructor: Context,
1446
+ reset: function reset(skipTempReset) {
1447
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
1448
+ "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1423
1449
  }
1450
+ },
1451
+ stop: function stop() {
1452
+ this.done = !0;
1453
+ var rootRecord = this.tryEntries[0].completion;
1454
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
1455
+ return this.rval;
1456
+ },
1457
+ dispatchException: function dispatchException(exception) {
1458
+ if (this.done) throw exception;
1459
+ var context = this;
1424
1460
 
1425
- if (!g.isNil(fill)) {
1426
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
1461
+ function handle(loc, caught) {
1462
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1427
1463
  }
1428
- }
1429
- };
1430
1464
 
1431
- _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
1432
- if (isStroke === void 0) {
1433
- isStroke = false;
1434
- } // letterSpacing of 0 means normal, render all texts directly
1465
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1466
+ var entry = this.tryEntries[i],
1467
+ record = entry.completion;
1468
+ if ("root" === entry.tryLoc) return handle("end");
1435
1469
 
1470
+ if (entry.tryLoc <= this.prev) {
1471
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1472
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1436
1473
 
1437
- if (letterSpacing === 0) {
1438
- if (isStroke) {
1439
- this.strokeText(context, text, x, y, strokeOpacity);
1440
- } else {
1441
- this.fillText(context, text, x, y, fillOpacity, opacity);
1474
+ if (hasCatch && hasFinally) {
1475
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1476
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1477
+ } else if (hasCatch) {
1478
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1479
+ } else {
1480
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1481
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1482
+ }
1483
+ }
1442
1484
  }
1485
+ },
1486
+ abrupt: function abrupt(type, arg) {
1487
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1488
+ var entry = this.tryEntries[i];
1443
1489
 
1444
- return;
1445
- } // draw text using left align
1446
-
1447
-
1448
- var currentTextAlign = context.textAlign;
1449
- context.textAlign = 'left';
1450
- var currentPosition = x;
1490
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1491
+ var finallyEntry = entry;
1492
+ break;
1493
+ }
1494
+ }
1451
1495
 
1452
- if (textAlign === 'center') {
1453
- currentPosition = x - lineMetrics.width / 2;
1454
- } else if (textAlign === 'right' || textAlign === 'end') {
1455
- currentPosition = x - lineMetrics.width;
1456
- }
1496
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1497
+ var record = finallyEntry ? finallyEntry.completion : {};
1498
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1499
+ },
1500
+ complete: function complete(record, afterLoc) {
1501
+ if ("throw" === record.type) throw record.arg;
1502
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1503
+ },
1504
+ finish: function finish(finallyLoc) {
1505
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1506
+ var entry = this.tryEntries[i];
1507
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1508
+ }
1509
+ },
1510
+ catch: function _catch(tryLoc) {
1511
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1512
+ var entry = this.tryEntries[i];
1457
1513
 
1458
- var stringArray = Array.from(text);
1459
- var previousWidth = context.measureText(text).width;
1460
- var currentWidth = 0;
1514
+ if (entry.tryLoc === tryLoc) {
1515
+ var record = entry.completion;
1461
1516
 
1462
- for (var i = 0; i < stringArray.length; ++i) {
1463
- var currentChar = stringArray[i];
1517
+ if ("throw" === record.type) {
1518
+ var thrown = record.arg;
1519
+ resetTryEntry(entry);
1520
+ }
1464
1521
 
1465
- if (isStroke) {
1466
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
1467
- } else {
1468
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
1522
+ return thrown;
1523
+ }
1469
1524
  }
1470
1525
 
1471
- currentWidth = context.measureText(text.substring(i + 1)).width;
1472
- currentPosition += previousWidth - currentWidth + letterSpacing;
1473
- previousWidth = currentWidth;
1474
- }
1475
-
1476
- context.textAlign = currentTextAlign;
1477
- };
1478
-
1479
- _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
1480
- var currentGlobalAlpha;
1481
- var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
1482
-
1483
- if (applyOpacity) {
1484
- currentGlobalAlpha = context.globalAlpha;
1485
- context.globalAlpha = fillOpacity * opacity;
1526
+ throw new Error("illegal catch attempt");
1527
+ },
1528
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1529
+ return this.delegate = {
1530
+ iterator: values(iterable),
1531
+ resultName: resultName,
1532
+ nextLoc: nextLoc
1533
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1486
1534
  }
1535
+ }, exports;
1536
+ }
1487
1537
 
1488
- context.fillText(text, x, y);
1538
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1539
+ try {
1540
+ var info = gen[key](arg);
1541
+ var value = info.value;
1542
+ } catch (error) {
1543
+ reject(error);
1544
+ return;
1545
+ }
1489
1546
 
1490
- if (applyOpacity) {
1491
- context.globalAlpha = currentGlobalAlpha;
1492
- }
1493
- };
1547
+ if (info.done) {
1548
+ resolve(value);
1549
+ } else {
1550
+ Promise.resolve(value).then(_next, _throw);
1551
+ }
1552
+ }
1494
1553
 
1495
- _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
1496
- var currentGlobalAlpha;
1497
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
1554
+ function _asyncToGenerator$1(fn) {
1555
+ return function () {
1556
+ var self = this,
1557
+ args = arguments;
1558
+ return new Promise(function (resolve, reject) {
1559
+ var gen = fn.apply(self, args);
1498
1560
 
1499
- if (applyOpacity) {
1500
- currentGlobalAlpha = context.globalAlpha;
1501
- context.globalAlpha = strokeOpacity;
1502
- }
1561
+ function _next(value) {
1562
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1563
+ }
1503
1564
 
1504
- context.strokeText(text, x, y);
1565
+ function _throw(err) {
1566
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1567
+ }
1505
1568
 
1506
- if (applyOpacity) {
1507
- context.globalAlpha = currentGlobalAlpha;
1508
- }
1569
+ _next(undefined);
1570
+ });
1509
1571
  };
1572
+ }
1510
1573
 
1511
- return TextRenderer;
1512
- }();
1574
+ function _extends() {
1575
+ _extends = Object.assign || function (target) {
1576
+ for (var i = 1; i < arguments.length; i++) {
1577
+ var source = arguments[i];
1513
1578
 
1514
- TextRenderer = __decorate([manaSyringe.singleton({
1515
- token: TextRendererContribution
1516
- })], TextRenderer);
1579
+ for (var key in source) {
1580
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1581
+ target[key] = source[key];
1582
+ }
1583
+ }
1584
+ }
1517
1585
 
1518
- function _regeneratorRuntime$1() {
1519
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1520
- _regeneratorRuntime$1 = function _regeneratorRuntime() {
1521
- return exports;
1586
+ return target;
1522
1587
  };
1523
1588
 
1524
- var exports = {},
1525
- Op = Object.prototype,
1526
- hasOwn = Op.hasOwnProperty,
1527
- $Symbol = "function" == typeof Symbol ? Symbol : {},
1528
- iteratorSymbol = $Symbol.iterator || "@@iterator",
1529
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1530
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1589
+ return _extends.apply(this, arguments);
1590
+ }
1531
1591
 
1532
- function define(obj, key, value) {
1533
- return Object.defineProperty(obj, key, {
1534
- value: value,
1535
- enumerable: !0,
1536
- configurable: !0,
1537
- writable: !0
1538
- }), obj[key];
1539
- }
1592
+ function _inheritsLoose$1(subClass, superClass) {
1593
+ subClass.prototype = Object.create(superClass.prototype);
1594
+ subClass.prototype.constructor = subClass;
1540
1595
 
1541
- try {
1542
- define({}, "");
1543
- } catch (err) {
1544
- define = function define(obj, key, value) {
1545
- return obj[key] = value;
1546
- };
1547
- }
1596
+ _setPrototypeOf$1(subClass, superClass);
1597
+ }
1548
1598
 
1549
- function wrap(innerFn, outerFn, self, tryLocsList) {
1550
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1551
- generator = Object.create(protoGenerator.prototype),
1552
- context = new Context(tryLocsList || []);
1553
- return generator._invoke = function (innerFn, self, context) {
1554
- var state = "suspendedStart";
1555
- return function (method, arg) {
1556
- if ("executing" === state) throw new Error("Generator is already running");
1599
+ function _setPrototypeOf$1(o, p) {
1600
+ _setPrototypeOf$1 = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
1601
+ o.__proto__ = p;
1602
+ return o;
1603
+ };
1557
1604
 
1558
- if ("completed" === state) {
1559
- if ("throw" === method) throw arg;
1560
- return doneResult();
1561
- }
1605
+ return _setPrototypeOf$1(o, p);
1606
+ }
1607
+ /**
1608
+ * Common utilities
1609
+ * @module glMatrix
1610
+ */
1611
+ // Configuration Constants
1562
1612
 
1563
- for (context.method = method, context.arg = arg;;) {
1564
- var delegate = context.delegate;
1565
1613
 
1566
- if (delegate) {
1567
- var delegateResult = maybeInvokeDelegate(delegate, context);
1614
+ var EPSILON = 0.000001;
1615
+ var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
1616
+ if (!Math.hypot) Math.hypot = function () {
1617
+ var y = 0,
1618
+ i = arguments.length;
1568
1619
 
1569
- if (delegateResult) {
1570
- if (delegateResult === ContinueSentinel) continue;
1571
- return delegateResult;
1572
- }
1573
- }
1620
+ while (i--) {
1621
+ y += arguments[i] * arguments[i];
1622
+ }
1574
1623
 
1575
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1576
- if ("suspendedStart" === state) throw state = "completed", context.arg;
1577
- context.dispatchException(context.arg);
1578
- } else "return" === context.method && context.abrupt("return", context.arg);
1579
- state = "executing";
1580
- var record = tryCatch(innerFn, self, context);
1624
+ return Math.sqrt(y);
1625
+ };
1626
+ /**
1627
+ * 3x3 Matrix
1628
+ * @module mat3
1629
+ */
1581
1630
 
1582
- if ("normal" === record.type) {
1583
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1584
- return {
1585
- value: record.arg,
1586
- done: context.done
1587
- };
1588
- }
1631
+ /**
1632
+ * Creates a new identity mat3
1633
+ *
1634
+ * @returns {mat3} a new 3x3 matrix
1635
+ */
1589
1636
 
1590
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1591
- }
1592
- };
1593
- }(innerFn, self, context), generator;
1594
- }
1637
+ function create() {
1638
+ var out = new ARRAY_TYPE(9);
1595
1639
 
1596
- function tryCatch(fn, obj, arg) {
1597
- try {
1598
- return {
1599
- type: "normal",
1600
- arg: fn.call(obj, arg)
1601
- };
1602
- } catch (err) {
1603
- return {
1604
- type: "throw",
1605
- arg: err
1606
- };
1607
- }
1640
+ if (ARRAY_TYPE != Float32Array) {
1641
+ out[1] = 0;
1642
+ out[2] = 0;
1643
+ out[3] = 0;
1644
+ out[5] = 0;
1645
+ out[6] = 0;
1646
+ out[7] = 0;
1608
1647
  }
1609
1648
 
1610
- exports.wrap = wrap;
1611
- var ContinueSentinel = {};
1612
-
1613
- function Generator() {}
1649
+ out[0] = 1;
1650
+ out[4] = 1;
1651
+ out[8] = 1;
1652
+ return out;
1653
+ }
1654
+ /**
1655
+ * Returns the translation vector component of a transformation
1656
+ * matrix. If a matrix is built with fromRotationTranslation,
1657
+ * the returned vector will be the same as the translation vector
1658
+ * originally supplied.
1659
+ * @param {vec3} out Vector to receive translation component
1660
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1661
+ * @return {vec3} out
1662
+ */
1614
1663
 
1615
- function GeneratorFunction() {}
1616
1664
 
1617
- function GeneratorFunctionPrototype() {}
1665
+ function getTranslation(out, mat) {
1666
+ out[0] = mat[12];
1667
+ out[1] = mat[13];
1668
+ out[2] = mat[14];
1669
+ return out;
1670
+ }
1671
+ /**
1672
+ * Returns the scaling factor component of a transformation
1673
+ * matrix. If a matrix is built with fromRotationTranslationScale
1674
+ * with a normalized Quaternion paramter, the returned vector will be
1675
+ * the same as the scaling vector
1676
+ * originally supplied.
1677
+ * @param {vec3} out Vector to receive scaling factor component
1678
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1679
+ * @return {vec3} out
1680
+ */
1618
1681
 
1619
- var IteratorPrototype = {};
1620
- define(IteratorPrototype, iteratorSymbol, function () {
1621
- return this;
1622
- });
1623
- var getProto = Object.getPrototypeOf,
1624
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1625
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1626
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1627
1682
 
1628
- function defineIteratorMethods(prototype) {
1629
- ["next", "throw", "return"].forEach(function (method) {
1630
- define(prototype, method, function (arg) {
1631
- return this._invoke(method, arg);
1632
- });
1633
- });
1634
- }
1635
-
1636
- function AsyncIterator(generator, PromiseImpl) {
1637
- function invoke(method, arg, resolve, reject) {
1638
- var record = tryCatch(generator[method], generator, arg);
1639
-
1640
- if ("throw" !== record.type) {
1641
- var result = record.arg,
1642
- value = result.value;
1643
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1644
- invoke("next", value, resolve, reject);
1645
- }, function (err) {
1646
- invoke("throw", err, resolve, reject);
1647
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1648
- result.value = unwrapped, resolve(result);
1649
- }, function (error) {
1650
- return invoke("throw", error, resolve, reject);
1651
- });
1652
- }
1653
-
1654
- reject(record.arg);
1655
- }
1656
-
1657
- var previousPromise;
1658
-
1659
- this._invoke = function (method, arg) {
1660
- function callInvokeWithMethodAndArg() {
1661
- return new PromiseImpl(function (resolve, reject) {
1662
- invoke(method, arg, resolve, reject);
1663
- });
1664
- }
1665
-
1666
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1667
- };
1668
- }
1669
-
1670
- function maybeInvokeDelegate(delegate, context) {
1671
- var method = delegate.iterator[context.method];
1672
-
1673
- if (undefined === method) {
1674
- if (context.delegate = null, "throw" === context.method) {
1675
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
1676
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
1677
- }
1678
-
1679
- return ContinueSentinel;
1680
- }
1681
-
1682
- var record = tryCatch(method, delegate.iterator, context.arg);
1683
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1684
- var info = record.arg;
1685
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
1686
- }
1687
-
1688
- function pushTryEntry(locs) {
1689
- var entry = {
1690
- tryLoc: locs[0]
1691
- };
1692
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1693
- }
1694
-
1695
- function resetTryEntry(entry) {
1696
- var record = entry.completion || {};
1697
- record.type = "normal", delete record.arg, entry.completion = record;
1698
- }
1699
-
1700
- function Context(tryLocsList) {
1701
- this.tryEntries = [{
1702
- tryLoc: "root"
1703
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1704
- }
1705
-
1706
- function values(iterable) {
1707
- if (iterable) {
1708
- var iteratorMethod = iterable[iteratorSymbol];
1709
- if (iteratorMethod) return iteratorMethod.call(iterable);
1710
- if ("function" == typeof iterable.next) return iterable;
1711
-
1712
- if (!isNaN(iterable.length)) {
1713
- var i = -1,
1714
- next = function next() {
1715
- for (; ++i < iterable.length;) {
1716
- if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1717
- }
1718
-
1719
- return next.value = undefined, next.done = !0, next;
1720
- };
1721
-
1722
- return next.next = next;
1723
- }
1724
- }
1725
-
1726
- return {
1727
- next: doneResult
1728
- };
1729
- }
1730
-
1731
- function doneResult() {
1732
- return {
1733
- value: undefined,
1734
- done: !0
1735
- };
1736
- }
1737
-
1738
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1739
- var ctor = "function" == typeof genFun && genFun.constructor;
1740
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1741
- }, exports.mark = function (genFun) {
1742
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1743
- }, exports.awrap = function (arg) {
1744
- return {
1745
- __await: arg
1746
- };
1747
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1748
- return this;
1749
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1750
- void 0 === PromiseImpl && (PromiseImpl = Promise);
1751
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1752
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1753
- return result.done ? result.value : iter.next();
1754
- });
1755
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1756
- return this;
1757
- }), define(Gp, "toString", function () {
1758
- return "[object Generator]";
1759
- }), exports.keys = function (object) {
1760
- var keys = [];
1761
-
1762
- for (var key in object) {
1763
- keys.push(key);
1764
- }
1765
-
1766
- return keys.reverse(), function next() {
1767
- for (; keys.length;) {
1768
- var key = keys.pop();
1769
- if (key in object) return next.value = key, next.done = !1, next;
1770
- }
1771
-
1772
- return next.done = !0, next;
1773
- };
1774
- }, exports.values = values, Context.prototype = {
1775
- constructor: Context,
1776
- reset: function reset(skipTempReset) {
1777
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
1778
- "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1779
- }
1780
- },
1781
- stop: function stop() {
1782
- this.done = !0;
1783
- var rootRecord = this.tryEntries[0].completion;
1784
- if ("throw" === rootRecord.type) throw rootRecord.arg;
1785
- return this.rval;
1786
- },
1787
- dispatchException: function dispatchException(exception) {
1788
- if (this.done) throw exception;
1789
- var context = this;
1790
-
1791
- function handle(loc, caught) {
1792
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1793
- }
1794
-
1795
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1796
- var entry = this.tryEntries[i],
1797
- record = entry.completion;
1798
- if ("root" === entry.tryLoc) return handle("end");
1799
-
1800
- if (entry.tryLoc <= this.prev) {
1801
- var hasCatch = hasOwn.call(entry, "catchLoc"),
1802
- hasFinally = hasOwn.call(entry, "finallyLoc");
1803
-
1804
- if (hasCatch && hasFinally) {
1805
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1806
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1807
- } else if (hasCatch) {
1808
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1809
- } else {
1810
- if (!hasFinally) throw new Error("try statement without catch or finally");
1811
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1812
- }
1813
- }
1814
- }
1815
- },
1816
- abrupt: function abrupt(type, arg) {
1817
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1818
- var entry = this.tryEntries[i];
1819
-
1820
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1821
- var finallyEntry = entry;
1822
- break;
1823
- }
1824
- }
1825
-
1826
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1827
- var record = finallyEntry ? finallyEntry.completion : {};
1828
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1829
- },
1830
- complete: function complete(record, afterLoc) {
1831
- if ("throw" === record.type) throw record.arg;
1832
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1833
- },
1834
- finish: function finish(finallyLoc) {
1835
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1836
- var entry = this.tryEntries[i];
1837
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1838
- }
1839
- },
1840
- catch: function _catch(tryLoc) {
1841
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1842
- var entry = this.tryEntries[i];
1843
-
1844
- if (entry.tryLoc === tryLoc) {
1845
- var record = entry.completion;
1846
-
1847
- if ("throw" === record.type) {
1848
- var thrown = record.arg;
1849
- resetTryEntry(entry);
1850
- }
1851
-
1852
- return thrown;
1853
- }
1854
- }
1855
-
1856
- throw new Error("illegal catch attempt");
1857
- },
1858
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1859
- return this.delegate = {
1860
- iterator: values(iterable),
1861
- resultName: resultName,
1862
- nextLoc: nextLoc
1863
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1864
- }
1865
- }, exports;
1683
+ function getScaling(out, mat) {
1684
+ var m11 = mat[0];
1685
+ var m12 = mat[1];
1686
+ var m13 = mat[2];
1687
+ var m21 = mat[4];
1688
+ var m22 = mat[5];
1689
+ var m23 = mat[6];
1690
+ var m31 = mat[8];
1691
+ var m32 = mat[9];
1692
+ var m33 = mat[10];
1693
+ out[0] = Math.hypot(m11, m12, m13);
1694
+ out[1] = Math.hypot(m21, m22, m23);
1695
+ out[2] = Math.hypot(m31, m32, m33);
1696
+ return out;
1866
1697
  }
1698
+ /**
1699
+ * Returns a quaternion representing the rotational component
1700
+ * of a transformation matrix. If a matrix is built with
1701
+ * fromRotationTranslation, the returned quaternion will be the
1702
+ * same as the quaternion originally supplied.
1703
+ * @param {quat} out Quaternion to receive the rotation component
1704
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1705
+ * @return {quat} out
1706
+ */
1867
1707
 
1868
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1869
- try {
1870
- var info = gen[key](arg);
1871
- var value = info.value;
1872
- } catch (error) {
1873
- reject(error);
1874
- return;
1875
- }
1876
1708
 
1877
- if (info.done) {
1878
- resolve(value);
1709
+ function getRotation(out, mat) {
1710
+ var scaling = new ARRAY_TYPE(3);
1711
+ getScaling(scaling, mat);
1712
+ var is1 = 1 / scaling[0];
1713
+ var is2 = 1 / scaling[1];
1714
+ var is3 = 1 / scaling[2];
1715
+ var sm11 = mat[0] * is1;
1716
+ var sm12 = mat[1] * is2;
1717
+ var sm13 = mat[2] * is3;
1718
+ var sm21 = mat[4] * is1;
1719
+ var sm22 = mat[5] * is2;
1720
+ var sm23 = mat[6] * is3;
1721
+ var sm31 = mat[8] * is1;
1722
+ var sm32 = mat[9] * is2;
1723
+ var sm33 = mat[10] * is3;
1724
+ var trace = sm11 + sm22 + sm33;
1725
+ var S = 0;
1726
+
1727
+ if (trace > 0) {
1728
+ S = Math.sqrt(trace + 1.0) * 2;
1729
+ out[3] = 0.25 * S;
1730
+ out[0] = (sm23 - sm32) / S;
1731
+ out[1] = (sm31 - sm13) / S;
1732
+ out[2] = (sm12 - sm21) / S;
1733
+ } else if (sm11 > sm22 && sm11 > sm33) {
1734
+ S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1735
+ out[3] = (sm23 - sm32) / S;
1736
+ out[0] = 0.25 * S;
1737
+ out[1] = (sm12 + sm21) / S;
1738
+ out[2] = (sm31 + sm13) / S;
1739
+ } else if (sm22 > sm33) {
1740
+ S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1741
+ out[3] = (sm31 - sm13) / S;
1742
+ out[0] = (sm12 + sm21) / S;
1743
+ out[1] = 0.25 * S;
1744
+ out[2] = (sm23 + sm32) / S;
1879
1745
  } else {
1880
- Promise.resolve(value).then(_next, _throw);
1746
+ S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1747
+ out[3] = (sm12 - sm21) / S;
1748
+ out[0] = (sm31 + sm13) / S;
1749
+ out[1] = (sm23 + sm32) / S;
1750
+ out[2] = 0.25 * S;
1881
1751
  }
1882
- }
1883
-
1884
- function _asyncToGenerator$1(fn) {
1885
- return function () {
1886
- var self = this,
1887
- args = arguments;
1888
- return new Promise(function (resolve, reject) {
1889
- var gen = fn.apply(self, args);
1890
1752
 
1891
- function _next(value) {
1892
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1893
- }
1894
-
1895
- function _throw(err) {
1896
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1897
- }
1898
-
1899
- _next(undefined);
1900
- });
1901
- };
1753
+ return out;
1902
1754
  }
1755
+ /**
1756
+ * 3 Dimensional Vector
1757
+ * @module vec3
1758
+ */
1903
1759
 
1904
- function _extends() {
1905
- _extends = Object.assign || function (target) {
1906
- for (var i = 1; i < arguments.length; i++) {
1907
- var source = arguments[i];
1908
-
1909
- for (var key in source) {
1910
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1911
- target[key] = source[key];
1912
- }
1913
- }
1914
- }
1915
-
1916
- return target;
1917
- };
1918
-
1919
- return _extends.apply(this, arguments);
1920
- }
1760
+ /**
1761
+ * Creates a new, empty vec3
1762
+ *
1763
+ * @returns {vec3} a new 3D vector
1764
+ */
1921
1765
 
1922
- function _inheritsLoose$1(subClass, superClass) {
1923
- subClass.prototype = Object.create(superClass.prototype);
1924
- subClass.prototype.constructor = subClass;
1925
1766
 
1926
- _setPrototypeOf$1(subClass, superClass);
1927
- }
1767
+ function create$1() {
1768
+ var out = new ARRAY_TYPE(3);
1928
1769
 
1929
- function _setPrototypeOf$1(o, p) {
1930
- _setPrototypeOf$1 = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
1931
- o.__proto__ = p;
1932
- return o;
1933
- };
1770
+ if (ARRAY_TYPE != Float32Array) {
1771
+ out[0] = 0;
1772
+ out[1] = 0;
1773
+ out[2] = 0;
1774
+ }
1934
1775
 
1935
- return _setPrototypeOf$1(o, p);
1776
+ return out;
1936
1777
  }
1778
+ /**
1779
+ * Calculates the length of a vec3
1780
+ *
1781
+ * @param {ReadonlyVec3} a vector to calculate length of
1782
+ * @returns {Number} length of a
1783
+ */
1937
1784
 
1938
- var DefaultRenderer = /*#__PURE__*/function () {
1939
- function DefaultRenderer() {}
1940
-
1941
- var _proto = DefaultRenderer.prototype;
1942
-
1943
- _proto.hash = function hash(parsedStyle) {
1944
- // const { fill, opacity, fillOpacity, stroke, strokeOpacity, lineWidth, lineCap, lineJoin } =
1945
- // parsedStyle;
1946
- // return fill + opacity + fillOpacity + stroke + strokeOpacity + lineWidth + lineCap + lineJoin;
1947
- return '';
1948
- };
1949
-
1950
- _proto.render = function render(context, parsedStyle) {
1951
- var fill = parsedStyle.fill,
1952
- opacity = parsedStyle.opacity,
1953
- fillOpacity = parsedStyle.fillOpacity,
1954
- stroke = parsedStyle.stroke,
1955
- strokeOpacity = parsedStyle.strokeOpacity,
1956
- lineWidth = parsedStyle.lineWidth,
1957
- lineCap = parsedStyle.lineCap,
1958
- lineJoin = parsedStyle.lineJoin,
1959
- shadowColor = parsedStyle.shadowColor,
1960
- filter = parsedStyle.filter,
1961
- miterLimit = parsedStyle.miterLimit;
1962
- var hasFill = !g.isNil(fill);
1963
- var hasStroke = !g.isNil(stroke);
1964
- var isFillTransparent = fill.alpha === 0;
1965
-
1966
- if (hasFill) {
1967
- if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
1968
- context.globalAlpha = fillOpacity.value;
1969
- context.fill();
1970
- context.globalAlpha = opacity.value;
1971
- } else {
1972
- context.fill();
1973
- }
1974
- }
1975
-
1976
- if (hasStroke) {
1977
- if (lineWidth && lineWidth.value > 0) {
1978
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
1979
-
1980
- if (applyOpacity) {
1981
- context.globalAlpha = strokeOpacity.value;
1982
- }
1983
1785
 
1984
- context.lineWidth = lineWidth.value;
1786
+ function length(a) {
1787
+ var x = a[0];
1788
+ var y = a[1];
1789
+ var z = a[2];
1790
+ return Math.hypot(x, y, z);
1791
+ }
1792
+ /**
1793
+ * Creates a new vec3 initialized with the given values
1794
+ *
1795
+ * @param {Number} x X component
1796
+ * @param {Number} y Y component
1797
+ * @param {Number} z Z component
1798
+ * @returns {vec3} a new 3D vector
1799
+ */
1985
1800
 
1986
- if (!g.isNil(miterLimit)) {
1987
- context.miterLimit = miterLimit;
1988
- }
1989
1801
 
1990
- if (!g.isNil(lineCap)) {
1991
- context.lineCap = lineCap.value;
1992
- }
1802
+ function fromValues(x, y, z) {
1803
+ var out = new ARRAY_TYPE(3);
1804
+ out[0] = x;
1805
+ out[1] = y;
1806
+ out[2] = z;
1807
+ return out;
1808
+ }
1809
+ /**
1810
+ * Normalize a vec3
1811
+ *
1812
+ * @param {vec3} out the receiving vector
1813
+ * @param {ReadonlyVec3} a vector to normalize
1814
+ * @returns {vec3} out
1815
+ */
1993
1816
 
1994
- if (!g.isNil(lineJoin)) {
1995
- context.lineJoin = lineJoin.value;
1996
- }
1997
1817
 
1998
- var oldShadowBlur;
1999
- var oldShadowColor;
2000
- var oldFilter;
2001
- var hasShadowColor = !g.isNil(shadowColor);
2002
- var hasFilter = !g.isNil(filter);
1818
+ function normalize(out, a) {
1819
+ var x = a[0];
1820
+ var y = a[1];
1821
+ var z = a[2];
1822
+ var len = x * x + y * y + z * z;
2003
1823
 
2004
- if (hasShadowColor) {
2005
- // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
2006
- // save shadow blur
2007
- oldShadowBlur = context.shadowBlur;
2008
- oldShadowColor = context.shadowColor;
1824
+ if (len > 0) {
1825
+ //TODO: evaluate use of glm_invsqrt here?
1826
+ len = 1 / Math.sqrt(len);
1827
+ }
2009
1828
 
2010
- if (!g.isNil(oldShadowBlur)) {
2011
- context.shadowColor = 'transparent';
2012
- context.shadowBlur = 0;
2013
- }
2014
- }
1829
+ out[0] = a[0] * len;
1830
+ out[1] = a[1] * len;
1831
+ out[2] = a[2] * len;
1832
+ return out;
1833
+ }
1834
+ /**
1835
+ * Calculates the dot product of two vec3's
1836
+ *
1837
+ * @param {ReadonlyVec3} a the first operand
1838
+ * @param {ReadonlyVec3} b the second operand
1839
+ * @returns {Number} dot product of a and b
1840
+ */
2015
1841
 
2016
- if (hasFilter) {
2017
- // save drop-shadow filter
2018
- oldFilter = context.filter;
2019
1842
 
2020
- if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
2021
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
2022
- }
2023
- }
1843
+ function dot(a, b) {
1844
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1845
+ }
1846
+ /**
1847
+ * Computes the cross product of two vec3's
1848
+ *
1849
+ * @param {vec3} out the receiving vector
1850
+ * @param {ReadonlyVec3} a the first operand
1851
+ * @param {ReadonlyVec3} b the second operand
1852
+ * @returns {vec3} out
1853
+ */
2024
1854
 
2025
- var drawStroke = hasFill && !isFillTransparent;
2026
1855
 
2027
- if (drawStroke) {
2028
- context.stroke();
2029
- } // restore shadow blur
1856
+ function cross(out, a, b) {
1857
+ var ax = a[0],
1858
+ ay = a[1],
1859
+ az = a[2];
1860
+ var bx = b[0],
1861
+ by = b[1],
1862
+ bz = b[2];
1863
+ out[0] = ay * bz - az * by;
1864
+ out[1] = az * bx - ax * bz;
1865
+ out[2] = ax * by - ay * bx;
1866
+ return out;
1867
+ }
1868
+ /**
1869
+ * Alias for {@link vec3.length}
1870
+ * @function
1871
+ */
2030
1872
 
2031
1873
 
2032
- if (hasShadowColor) {
2033
- context.shadowColor = oldShadowColor;
2034
- context.shadowBlur = oldShadowBlur;
2035
- } // restore filters
1874
+ var len = length;
1875
+ /**
1876
+ * Perform some operation over an array of vec3s.
1877
+ *
1878
+ * @param {Array} a the array of vectors to iterate over
1879
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
1880
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1881
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
1882
+ * @param {Function} fn Function to call for each vector in the array
1883
+ * @param {Object} [arg] additional argument to pass to fn
1884
+ * @returns {Array} a
1885
+ * @function
1886
+ */
2036
1887
 
1888
+ var forEach = function () {
1889
+ var vec = create$1();
1890
+ return function (a, stride, offset, count, fn, arg) {
1891
+ var i, l;
2037
1892
 
2038
- if (hasFilter) {
2039
- context.filter = oldFilter;
2040
- }
1893
+ if (!stride) {
1894
+ stride = 3;
1895
+ }
2041
1896
 
2042
- if (!drawStroke) {
2043
- context.stroke();
2044
- }
2045
- }
1897
+ if (!offset) {
1898
+ offset = 0;
2046
1899
  }
2047
- };
2048
1900
 
2049
- return DefaultRenderer;
1901
+ if (count) {
1902
+ l = Math.min(count * stride + offset, a.length);
1903
+ } else {
1904
+ l = a.length;
1905
+ }
1906
+
1907
+ for (i = offset; i < l; i += stride) {
1908
+ vec[0] = a[i];
1909
+ vec[1] = a[i + 1];
1910
+ vec[2] = a[i + 2];
1911
+ fn(vec, vec, arg);
1912
+ a[i] = vec[0];
1913
+ a[i + 1] = vec[1];
1914
+ a[i + 2] = vec[2];
1915
+ }
1916
+
1917
+ return a;
1918
+ };
2050
1919
  }();
1920
+ /**
1921
+ * 4 Dimensional Vector
1922
+ * @module vec4
1923
+ */
2051
1924
 
2052
- DefaultRenderer = __decorate([manaSyringe.singleton()], DefaultRenderer);
1925
+ /**
1926
+ * Creates a new, empty vec4
1927
+ *
1928
+ * @returns {vec4} a new 4D vector
1929
+ */
2053
1930
 
2054
- var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2055
- _inheritsLoose$1(RectRenderer, _DefaultRenderer);
2056
1931
 
2057
- function RectRenderer() {
2058
- return _DefaultRenderer.apply(this, arguments) || this;
1932
+ function create$2() {
1933
+ var out = new ARRAY_TYPE(4);
1934
+
1935
+ if (ARRAY_TYPE != Float32Array) {
1936
+ out[0] = 0;
1937
+ out[1] = 0;
1938
+ out[2] = 0;
1939
+ out[3] = 0;
2059
1940
  }
2060
1941
 
2061
- return RectRenderer;
2062
- }(DefaultRenderer);
1942
+ return out;
1943
+ }
1944
+ /**
1945
+ * Normalize a vec4
1946
+ *
1947
+ * @param {vec4} out the receiving vector
1948
+ * @param {ReadonlyVec4} a vector to normalize
1949
+ * @returns {vec4} out
1950
+ */
2063
1951
 
2064
- RectRenderer = __decorate([manaSyringe.singleton({
2065
- token: RectRendererContribution
2066
- })], RectRenderer);
2067
1952
 
2068
- var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2069
- _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
1953
+ function normalize$1(out, a) {
1954
+ var x = a[0];
1955
+ var y = a[1];
1956
+ var z = a[2];
1957
+ var w = a[3];
1958
+ var len = x * x + y * y + z * z + w * w;
2070
1959
 
2071
- function CircleRenderer() {
2072
- return _DefaultRenderer.apply(this, arguments) || this;
1960
+ if (len > 0) {
1961
+ len = 1 / Math.sqrt(len);
2073
1962
  }
2074
1963
 
2075
- return CircleRenderer;
2076
- }(DefaultRenderer);
1964
+ out[0] = x * len;
1965
+ out[1] = y * len;
1966
+ out[2] = z * len;
1967
+ out[3] = w * len;
1968
+ return out;
1969
+ }
1970
+ /**
1971
+ * Perform some operation over an array of vec4s.
1972
+ *
1973
+ * @param {Array} a the array of vectors to iterate over
1974
+ * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
1975
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1976
+ * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
1977
+ * @param {Function} fn Function to call for each vector in the array
1978
+ * @param {Object} [arg] additional argument to pass to fn
1979
+ * @returns {Array} a
1980
+ * @function
1981
+ */
2077
1982
 
2078
- CircleRenderer = __decorate([manaSyringe.singleton({
2079
- token: CircleRendererContribution
2080
- })], CircleRenderer);
2081
1983
 
2082
- var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2083
- _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
1984
+ var forEach$1 = function () {
1985
+ var vec = create$2();
1986
+ return function (a, stride, offset, count, fn, arg) {
1987
+ var i, l;
1988
+
1989
+ if (!stride) {
1990
+ stride = 4;
1991
+ }
1992
+
1993
+ if (!offset) {
1994
+ offset = 0;
1995
+ }
1996
+
1997
+ if (count) {
1998
+ l = Math.min(count * stride + offset, a.length);
1999
+ } else {
2000
+ l = a.length;
2001
+ }
2002
+
2003
+ for (i = offset; i < l; i += stride) {
2004
+ vec[0] = a[i];
2005
+ vec[1] = a[i + 1];
2006
+ vec[2] = a[i + 2];
2007
+ vec[3] = a[i + 3];
2008
+ fn(vec, vec, arg);
2009
+ a[i] = vec[0];
2010
+ a[i + 1] = vec[1];
2011
+ a[i + 2] = vec[2];
2012
+ a[i + 3] = vec[3];
2013
+ }
2084
2014
 
2085
- function EllipseRenderer() {
2086
- return _DefaultRenderer.apply(this, arguments) || this;
2087
- }
2015
+ return a;
2016
+ };
2017
+ }();
2018
+ /**
2019
+ * Quaternion
2020
+ * @module quat
2021
+ */
2088
2022
 
2089
- return EllipseRenderer;
2090
- }(DefaultRenderer);
2023
+ /**
2024
+ * Creates a new identity quat
2025
+ *
2026
+ * @returns {quat} a new quaternion
2027
+ */
2091
2028
 
2092
- EllipseRenderer = __decorate([manaSyringe.singleton({
2093
- token: EllipseRendererContribution
2094
- })], EllipseRenderer);
2095
2029
 
2096
- var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2097
- _inheritsLoose$1(LineRenderer, _DefaultRenderer);
2030
+ function create$3() {
2031
+ var out = new ARRAY_TYPE(4);
2098
2032
 
2099
- function LineRenderer() {
2100
- return _DefaultRenderer.apply(this, arguments) || this;
2033
+ if (ARRAY_TYPE != Float32Array) {
2034
+ out[0] = 0;
2035
+ out[1] = 0;
2036
+ out[2] = 0;
2101
2037
  }
2102
2038
 
2103
- return LineRenderer;
2104
- }(DefaultRenderer);
2039
+ out[3] = 1;
2040
+ return out;
2041
+ }
2042
+ /**
2043
+ * Sets a quat from the given angle and rotation axis,
2044
+ * then returns it.
2045
+ *
2046
+ * @param {quat} out the receiving quaternion
2047
+ * @param {ReadonlyVec3} axis the axis around which to rotate
2048
+ * @param {Number} rad the angle in radians
2049
+ * @returns {quat} out
2050
+ **/
2105
2051
 
2106
- LineRenderer = __decorate([manaSyringe.singleton({
2107
- token: LineRendererContribution
2108
- })], LineRenderer);
2109
2052
 
2110
- var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2111
- _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
2053
+ function setAxisAngle(out, axis, rad) {
2054
+ rad = rad * 0.5;
2055
+ var s = Math.sin(rad);
2056
+ out[0] = s * axis[0];
2057
+ out[1] = s * axis[1];
2058
+ out[2] = s * axis[2];
2059
+ out[3] = Math.cos(rad);
2060
+ return out;
2061
+ }
2062
+ /**
2063
+ * Performs a spherical linear interpolation between two quat
2064
+ *
2065
+ * @param {quat} out the receiving quaternion
2066
+ * @param {ReadonlyQuat} a the first operand
2067
+ * @param {ReadonlyQuat} b the second operand
2068
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2069
+ * @returns {quat} out
2070
+ */
2112
2071
 
2113
- function PolylineRenderer() {
2114
- return _DefaultRenderer.apply(this, arguments) || this;
2115
- }
2116
2072
 
2117
- return PolylineRenderer;
2118
- }(DefaultRenderer);
2073
+ function slerp(out, a, b, t) {
2074
+ // benchmarks:
2075
+ // http://jsperf.com/quaternion-slerp-implementations
2076
+ var ax = a[0],
2077
+ ay = a[1],
2078
+ az = a[2],
2079
+ aw = a[3];
2080
+ var bx = b[0],
2081
+ by = b[1],
2082
+ bz = b[2],
2083
+ bw = b[3];
2084
+ var omega, cosom, sinom, scale0, scale1; // calc cosine
2119
2085
 
2120
- PolylineRenderer = __decorate([manaSyringe.singleton({
2121
- token: PolylineRendererContribution
2122
- })], PolylineRenderer);
2086
+ cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
2123
2087
 
2124
- var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2125
- _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
2088
+ if (cosom < 0.0) {
2089
+ cosom = -cosom;
2090
+ bx = -bx;
2091
+ by = -by;
2092
+ bz = -bz;
2093
+ bw = -bw;
2094
+ } // calculate coefficients
2126
2095
 
2127
- function PolygonRenderer() {
2128
- return _DefaultRenderer.apply(this, arguments) || this;
2129
- }
2130
2096
 
2131
- return PolygonRenderer;
2132
- }(DefaultRenderer);
2097
+ if (1.0 - cosom > EPSILON) {
2098
+ // standard case (slerp)
2099
+ omega = Math.acos(cosom);
2100
+ sinom = Math.sin(omega);
2101
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
2102
+ scale1 = Math.sin(t * omega) / sinom;
2103
+ } else {
2104
+ // "from" and "to" quaternions are very close
2105
+ // ... so we can do a linear interpolation
2106
+ scale0 = 1.0 - t;
2107
+ scale1 = t;
2108
+ } // calculate final values
2133
2109
 
2134
- PolygonRenderer = __decorate([manaSyringe.singleton({
2135
- token: PolygonRendererContribution
2136
- })], PolygonRenderer);
2137
2110
 
2138
- var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2139
- _inheritsLoose$1(PathRenderer, _DefaultRenderer);
2111
+ out[0] = scale0 * ax + scale1 * bx;
2112
+ out[1] = scale0 * ay + scale1 * by;
2113
+ out[2] = scale0 * az + scale1 * bz;
2114
+ out[3] = scale0 * aw + scale1 * bw;
2115
+ return out;
2116
+ }
2117
+ /**
2118
+ * Creates a quaternion from the given 3x3 rotation matrix.
2119
+ *
2120
+ * NOTE: The resultant quaternion is not normalized, so you should be sure
2121
+ * to renormalize the quaternion yourself where necessary.
2122
+ *
2123
+ * @param {quat} out the receiving quaternion
2124
+ * @param {ReadonlyMat3} m rotation matrix
2125
+ * @returns {quat} out
2126
+ * @function
2127
+ */
2140
2128
 
2141
- function PathRenderer() {
2142
- return _DefaultRenderer.apply(this, arguments) || this;
2143
- }
2144
2129
 
2145
- return PathRenderer;
2146
- }(DefaultRenderer);
2130
+ function fromMat3(out, m) {
2131
+ // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
2132
+ // article "Quaternion Calculus and Fast Animation".
2133
+ var fTrace = m[0] + m[4] + m[8];
2134
+ var fRoot;
2147
2135
 
2148
- PathRenderer = __decorate([manaSyringe.singleton({
2149
- token: PathRendererContribution
2150
- })], PathRenderer);
2136
+ if (fTrace > 0.0) {
2137
+ // |w| > 1/2, may as well choose w > 1/2
2138
+ fRoot = Math.sqrt(fTrace + 1.0); // 2w
2151
2139
 
2152
- var GradientPool = /*#__PURE__*/function () {
2153
- function GradientPool() {
2154
- this.gradientCache = {};
2155
- }
2140
+ out[3] = 0.5 * fRoot;
2141
+ fRoot = 0.5 / fRoot; // 1/(4w)
2156
2142
 
2157
- var _proto = GradientPool.prototype;
2143
+ out[0] = (m[5] - m[7]) * fRoot;
2144
+ out[1] = (m[6] - m[2]) * fRoot;
2145
+ out[2] = (m[1] - m[3]) * fRoot;
2146
+ } else {
2147
+ // |w| <= 1/2
2148
+ var i = 0;
2149
+ if (m[4] > m[0]) i = 1;
2150
+ if (m[8] > m[i * 3 + i]) i = 2;
2151
+ var j = (i + 1) % 3;
2152
+ var k = (i + 2) % 3;
2153
+ fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
2154
+ out[i] = 0.5 * fRoot;
2155
+ fRoot = 0.5 / fRoot;
2156
+ out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
2157
+ out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
2158
+ out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
2159
+ }
2158
2160
 
2159
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2160
- var key = this.generateCacheKey(params);
2161
- var type = params.type,
2162
- x0 = params.x0,
2163
- y0 = params.y0,
2164
- x1 = params.x1,
2165
- y1 = params.y1,
2166
- steps = params.steps,
2167
- width = params.width,
2168
- height = params.height;
2161
+ return out;
2162
+ }
2163
+ /**
2164
+ * Normalize a quat
2165
+ *
2166
+ * @param {quat} out the receiving quaternion
2167
+ * @param {ReadonlyQuat} a quaternion to normalize
2168
+ * @returns {quat} out
2169
+ * @function
2170
+ */
2169
2171
 
2170
- if (this.gradientCache[key]) {
2171
- return this.gradientCache[key];
2172
- }
2173
2172
 
2174
- var gradient = null;
2173
+ var normalize$2 = normalize$1;
2174
+ /**
2175
+ * Sets a quaternion to represent the shortest rotation from one
2176
+ * vector to another.
2177
+ *
2178
+ * Both vectors are assumed to be unit length.
2179
+ *
2180
+ * @param {quat} out the receiving quaternion.
2181
+ * @param {ReadonlyVec3} a the initial vector
2182
+ * @param {ReadonlyVec3} b the destination vector
2183
+ * @returns {quat} out
2184
+ */
2175
2185
 
2176
- if (type === g.GradientPatternType.LinearGradient) {
2177
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2178
- gradient = context.createLinearGradient(x0 * width, y0 * height, x1 * width, y1 * height);
2179
- } else if (type === g.GradientPatternType.RadialGradient) {
2180
- var r = Math.sqrt(width * width + height * height) / 2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2186
+ var rotationTo = function () {
2187
+ var tmpvec3 = create$1();
2188
+ var xUnitVec3 = fromValues(1, 0, 0);
2189
+ var yUnitVec3 = fromValues(0, 1, 0);
2190
+ return function (out, a, b) {
2191
+ var dot$1 = dot(a, b);
2181
2192
 
2182
- gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2193
+ if (dot$1 < -0.999999) {
2194
+ cross(tmpvec3, xUnitVec3, a);
2195
+ if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
2196
+ normalize(tmpvec3, tmpvec3);
2197
+ setAxisAngle(out, tmpvec3, Math.PI);
2198
+ return out;
2199
+ } else if (dot$1 > 0.999999) {
2200
+ out[0] = 0;
2201
+ out[1] = 0;
2202
+ out[2] = 0;
2203
+ out[3] = 1;
2204
+ return out;
2205
+ } else {
2206
+ cross(tmpvec3, a, b);
2207
+ out[0] = tmpvec3[0];
2208
+ out[1] = tmpvec3[1];
2209
+ out[2] = tmpvec3[2];
2210
+ out[3] = 1 + dot$1;
2211
+ return normalize$2(out, out);
2183
2212
  }
2213
+ };
2214
+ }();
2215
+ /**
2216
+ * Performs a spherical linear interpolation with two control points
2217
+ *
2218
+ * @param {quat} out the receiving quaternion
2219
+ * @param {ReadonlyQuat} a the first operand
2220
+ * @param {ReadonlyQuat} b the second operand
2221
+ * @param {ReadonlyQuat} c the third operand
2222
+ * @param {ReadonlyQuat} d the fourth operand
2223
+ * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2224
+ * @returns {quat} out
2225
+ */
2184
2226
 
2185
- if (gradient) {
2186
- steps.forEach(function (_ref) {
2187
- var _gradient;
2188
-
2189
- var offset = _ref[0],
2190
- color = _ref[1];
2191
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(Number(offset), color);
2192
- });
2193
- this.gradientCache[key] = gradient;
2194
- }
2195
2227
 
2196
- return this.gradientCache[key];
2228
+ var sqlerp = function () {
2229
+ var temp1 = create$3();
2230
+ var temp2 = create$3();
2231
+ return function (out, a, b, c, d, t) {
2232
+ slerp(temp1, a, d, t);
2233
+ slerp(temp2, b, c, t);
2234
+ slerp(out, temp1, temp2, 2 * t * (1 - t));
2235
+ return out;
2197
2236
  };
2237
+ }();
2238
+ /**
2239
+ * Sets the specified quaternion with values corresponding to the given
2240
+ * axes. Each axis is a vec3 and is expected to be unit length and
2241
+ * perpendicular to all other specified axes.
2242
+ *
2243
+ * @param {ReadonlyVec3} view the vector representing the viewing direction
2244
+ * @param {ReadonlyVec3} right the vector representing the local "right" direction
2245
+ * @param {ReadonlyVec3} up the vector representing the local "up" direction
2246
+ * @returns {quat} out
2247
+ */
2198
2248
 
2199
- _proto.generateCacheKey = function generateCacheKey(params) {
2200
- // @ts-ignore
2201
- var type = params.type,
2202
- x0 = params.x0,
2203
- y0 = params.y0,
2204
- x1 = params.x1,
2205
- y1 = params.y1,
2206
- r1 = params.r1,
2207
- steps = params.steps,
2208
- width = params.width,
2209
- height = params.height;
2210
- return "gradient-" + type + "-" + x0 + "-" + y0 + "-" + x1 + "-" + y1 + "-" + (r1 || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
2211
- return step.join('');
2212
- }).join('-');
2213
- };
2214
2249
 
2215
- return GradientPool;
2250
+ var setAxes = function () {
2251
+ var matr = create();
2252
+ return function (out, view, right, up) {
2253
+ matr[0] = right[0];
2254
+ matr[3] = right[1];
2255
+ matr[6] = right[2];
2256
+ matr[1] = up[0];
2257
+ matr[4] = up[1];
2258
+ matr[7] = up[2];
2259
+ matr[2] = -view[0];
2260
+ matr[5] = -view[1];
2261
+ matr[8] = -view[2];
2262
+ return normalize$2(out, fromMat3(out, matr));
2263
+ };
2216
2264
  }();
2217
2265
 
2218
- GradientPool = __decorate([manaSyringe.singleton()], GradientPool);
2219
-
2220
2266
  function generatePath(context, parsedStyle) {
2221
2267
  var r = parsedStyle.r;
2222
2268
  context.arc(r.value, r.value, r.value, 0, Math.PI * 2, false);
@@ -2302,742 +2348,687 @@
2302
2348
  context.lineTo(x2.value - defX, y2.value - defY);
2303
2349
  }
2304
2350
 
2305
- function generatePath$4(context, parsedStyle) {
2306
- var _parsedStyle$defX = parsedStyle.defX,
2307
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2308
- _parsedStyle$defY = parsedStyle.defY,
2309
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2310
- var points = parsedStyle.points.points;
2311
- var length = points.length;
2312
- var x1 = points[0][0] - x;
2313
- var y1 = points[0][1] - y;
2314
- var x2 = points[length - 1][0] - x;
2315
- var y2 = points[length - 1][1] - y;
2316
- context.moveTo(x1, y1);
2351
+ function generatePath$4(context, parsedStyle) {
2352
+ var _parsedStyle$defX = parsedStyle.defX,
2353
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2354
+ _parsedStyle$defY = parsedStyle.defY,
2355
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2356
+ var points = parsedStyle.points.points;
2357
+ var length = points.length;
2358
+ var x1 = points[0][0] - x;
2359
+ var y1 = points[0][1] - y;
2360
+ var x2 = points[length - 1][0] - x;
2361
+ var y2 = points[length - 1][1] - y;
2362
+ context.moveTo(x1, y1);
2363
+
2364
+ for (var i = 0; i < length - 1; i++) {
2365
+ var point = points[i];
2366
+ context.lineTo(point[0] - x, point[1] - y);
2367
+ }
2368
+
2369
+ context.lineTo(x2, y2);
2370
+ }
2371
+
2372
+ function generatePath$5(context, parsedStyle) {
2373
+ var _parsedStyle$defX = parsedStyle.defX,
2374
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2375
+ _parsedStyle$defY = parsedStyle.defY,
2376
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2377
+ var points = parsedStyle.points.points;
2378
+ var length = points.length;
2379
+ var x1 = points[0][0] - x;
2380
+ var y1 = points[0][1] - y;
2381
+ var x2 = points[length - 1][0] - x;
2382
+ var y2 = points[length - 1][1] - y;
2383
+ context.moveTo(x1, y1);
2384
+
2385
+ for (var i = 0; i < length - 1; i++) {
2386
+ var point = points[i];
2387
+ context.lineTo(point[0] - x, point[1] - y);
2388
+ }
2389
+
2390
+ context.lineTo(x2, y2);
2391
+ }
2392
+
2393
+ function generatePath$6(context, parsedStyle) {
2394
+ var _parsedStyle$defX = parsedStyle.defX,
2395
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2396
+ _parsedStyle$defY = parsedStyle.defY,
2397
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2398
+ var _parsedStyle$path = parsedStyle.path,
2399
+ curve = _parsedStyle$path.curve,
2400
+ zCommandIndexes = _parsedStyle$path.zCommandIndexes;
2401
+ var path = [].concat(curve);
2402
+ zCommandIndexes.forEach(function (zIndex, index) {
2403
+ path.splice(zIndex + index, 1, ['Z']);
2404
+ });
2405
+
2406
+ for (var i = 0; i < path.length; i++) {
2407
+ var params = path[i]; // eg. M 100 200
2408
+
2409
+ var command = params[0]; // V,H,S,T 都在前面被转换成标准形式
2410
+
2411
+ switch (command) {
2412
+ case 'M':
2413
+ context.moveTo(params[1] - x, params[2] - y);
2414
+ break;
2415
+
2416
+ case 'C':
2417
+ context.bezierCurveTo(params[1] - x, params[2] - y, params[3] - x, params[4] - y, params[5] - x, params[6] - y);
2418
+ break;
2419
+
2420
+ case 'Z':
2421
+ context.closePath();
2422
+ break;
2423
+ }
2424
+ }
2425
+ }
2426
+
2427
+ var PathGeneratorFactory = manaSyringe.Syringe.defineToken('PathGeneratorFactory');
2428
+ var PathGenerator = manaSyringe.Syringe.defineToken('PathGenerator');
2429
+ var StyleRendererFactory = manaSyringe.Syringe.defineToken('StyleRendererFactory');
2430
+ var CircleRendererContribution = manaSyringe.Syringe.defineToken('CircleRenderer', {
2431
+ multiple: false
2432
+ });
2433
+ var EllipseRendererContribution = manaSyringe.Syringe.defineToken('EllipseRenderer', {
2434
+ multiple: false
2435
+ });
2436
+ var RectRendererContribution = manaSyringe.Syringe.defineToken('RectRenderer', {
2437
+ multiple: false
2438
+ });
2439
+ var LineRendererContribution = manaSyringe.Syringe.defineToken('LineRenderer', {
2440
+ multiple: false
2441
+ });
2442
+ var PolylineRendererContribution = manaSyringe.Syringe.defineToken('PolylineRenderer', {
2443
+ multiple: false
2444
+ });
2445
+ var PolygonRendererContribution = manaSyringe.Syringe.defineToken('PolygonRenderer', {
2446
+ multiple: false
2447
+ });
2448
+ var PathRendererContribution = manaSyringe.Syringe.defineToken('PathRenderer', {
2449
+ multiple: false
2450
+ });
2451
+ var TextRendererContribution = manaSyringe.Syringe.defineToken('TextRenderer', {
2452
+ multiple: false
2453
+ });
2454
+ var ImageRendererContribution = manaSyringe.Syringe.defineToken('ImageRenderer', {
2455
+ multiple: false
2456
+ });
2457
+
2458
+ var ImagePool = /*#__PURE__*/function () {
2459
+ function ImagePool() {
2460
+ this.imageCache = {};
2461
+ this.patternCache = {};
2462
+ this.canvasConfig = void 0;
2463
+ }
2464
+
2465
+ var _proto = ImagePool.prototype;
2466
+
2467
+ _proto.getImageSync = function getImageSync(src) {
2468
+ return this.imageCache[src];
2469
+ };
2470
+
2471
+ _proto.getOrCreateImage = function getOrCreateImage(src) {
2472
+ var _this = this;
2473
+
2474
+ if (this.imageCache[src]) {
2475
+ return Promise.resolve(this.imageCache[src]);
2476
+ } // @see https://github.com/antvis/g/issues/938
2477
+
2478
+
2479
+ var createImage = this.canvasConfig.createImage;
2480
+ return new Promise(function (resolve, reject) {
2481
+ var image;
2482
+
2483
+ if (createImage) {
2484
+ image = createImage(src);
2485
+ } else if (g.isBrowser) {
2486
+ image = new window.Image();
2487
+ }
2488
+
2489
+ if (image) {
2490
+ image.onload = function () {
2491
+ resolve(image);
2492
+ };
2493
+
2494
+ image.onerror = function (ev) {
2495
+ reject(ev);
2496
+ };
2497
+
2498
+ image.crossOrigin = 'Anonymous';
2499
+ image.src = src;
2500
+ _this.imageCache[src] = image;
2501
+ }
2502
+ });
2503
+ };
2504
+
2505
+ _proto.getPatternSync = function getPatternSync(pattern) {
2506
+ var patternKey = this.generatePatternKey(pattern);
2507
+
2508
+ if (this.patternCache[patternKey]) {
2509
+ return this.patternCache[patternKey];
2510
+ }
2511
+ };
2512
+
2513
+ _proto.createPattern = function createPattern(patternParams, context) {
2514
+ var _this2 = this;
2515
+
2516
+ return this.getOrCreateImage(patternParams.src).then(function (image) {
2517
+ var patternKey = _this2.generatePatternKey(patternParams); // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
2518
+
2519
+
2520
+ var pattern = context.createPattern(image, patternParams.repetition);
2521
+
2522
+ if (pattern) {
2523
+ _this2.patternCache[patternKey] = pattern;
2524
+ }
2525
+
2526
+ return _this2.patternCache[patternKey];
2527
+ });
2528
+ };
2529
+
2530
+ _proto.generatePatternKey = function generatePatternKey(pattern) {
2531
+ var src = pattern.src,
2532
+ repetition = pattern.repetition;
2533
+ return "pattern-" + src + "-" + repetition;
2534
+ };
2317
2535
 
2318
- for (var i = 0; i < length - 1; i++) {
2319
- var point = points[i];
2320
- context.lineTo(point[0] - x, point[1] - y);
2321
- }
2536
+ return ImagePool;
2537
+ }();
2322
2538
 
2323
- context.lineTo(x2, y2);
2324
- }
2539
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
2325
2540
 
2326
- function generatePath$5(context, parsedStyle) {
2327
- var _parsedStyle$defX = parsedStyle.defX,
2328
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2329
- _parsedStyle$defY = parsedStyle.defY,
2330
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2331
- var points = parsedStyle.points.points;
2332
- var length = points.length;
2333
- var x1 = points[0][0] - x;
2334
- var y1 = points[0][1] - y;
2335
- var x2 = points[length - 1][0] - x;
2336
- var y2 = points[length - 1][1] - y;
2337
- context.moveTo(x1, y1);
2541
+ ImagePool = __decorate([manaSyringe.singleton()], ImagePool);
2338
2542
 
2339
- for (var i = 0; i < length - 1; i++) {
2340
- var point = points[i];
2341
- context.lineTo(point[0] - x, point[1] - y);
2543
+ var ImageRenderer = /*#__PURE__*/function () {
2544
+ function ImageRenderer() {
2545
+ this.imagePool = void 0;
2342
2546
  }
2343
2547
 
2344
- context.lineTo(x2, y2);
2345
- }
2548
+ var _proto = ImageRenderer.prototype;
2346
2549
 
2347
- function generatePath$6(context, parsedStyle) {
2348
- var _parsedStyle$defX = parsedStyle.defX,
2349
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2350
- _parsedStyle$defY = parsedStyle.defY,
2351
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2352
- var _parsedStyle$path = parsedStyle.path,
2353
- curve = _parsedStyle$path.curve,
2354
- zCommandIndexes = _parsedStyle$path.zCommandIndexes;
2355
- var path = [].concat(curve);
2356
- zCommandIndexes.forEach(function (zIndex, index) {
2357
- path.splice(zIndex + index, 1, ['Z']);
2358
- });
2550
+ _proto.hash = function hash(parsedStyle) {
2551
+ return '';
2552
+ };
2359
2553
 
2360
- for (var i = 0; i < path.length; i++) {
2361
- var params = path[i]; // eg. M 100 200
2554
+ _proto.render = function render(context, parsedStyle) {
2555
+ var width = parsedStyle.width,
2556
+ height = parsedStyle.height,
2557
+ img = parsedStyle.img;
2558
+ var image;
2559
+ var iw = width.value;
2560
+ var ih = height.value;
2362
2561
 
2363
- var command = params[0]; // V,H,S,T 都在前面被转换成标准形式
2562
+ if (g.isString(img)) {
2563
+ // image has been loaded in `mounted` hook
2564
+ image = this.imagePool.getImageSync(img);
2565
+ } else {
2566
+ iw || (iw = img.width);
2567
+ ih || (ih = img.height);
2568
+ image = img;
2569
+ }
2364
2570
 
2365
- switch (command) {
2366
- case 'M':
2367
- context.moveTo(params[1] - x, params[2] - y);
2368
- break;
2571
+ if (image) {
2572
+ // node-canvas will throw the following err:
2573
+ // Error: Image given has not completed loading
2574
+ try {
2575
+ context.drawImage(image, 0, 0, iw, ih);
2576
+ } catch (e) {}
2577
+ }
2578
+ };
2369
2579
 
2370
- case 'C':
2371
- context.bezierCurveTo(params[1] - x, params[2] - y, params[3] - x, params[4] - y, params[5] - x, params[6] - y);
2372
- break;
2580
+ return ImageRenderer;
2581
+ }();
2373
2582
 
2374
- case 'Z':
2375
- context.closePath();
2376
- break;
2377
- }
2378
- }
2379
- }
2583
+ __decorate([manaSyringe.inject(ImagePool), __metadata("design:type", ImagePool)], ImageRenderer.prototype, "imagePool", void 0);
2380
2584
 
2381
- var PathGeneratorFactory = manaSyringe.Syringe.defineToken('PathGeneratorFactory');
2382
- var PathGenerator = manaSyringe.Syringe.defineToken('PathGenerator');
2383
- /**
2384
- * Common utilities
2385
- * @module glMatrix
2386
- */
2387
- // Configuration Constants
2585
+ ImageRenderer = __decorate([manaSyringe.singleton({
2586
+ token: ImageRendererContribution
2587
+ })], ImageRenderer);
2388
2588
 
2389
- var EPSILON = 0.000001;
2390
- var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
2391
- if (!Math.hypot) Math.hypot = function () {
2392
- var y = 0,
2393
- i = arguments.length;
2589
+ var TextRenderer = /*#__PURE__*/function () {
2590
+ function TextRenderer() {}
2394
2591
 
2395
- while (i--) {
2396
- y += arguments[i] * arguments[i];
2397
- }
2592
+ var _proto = TextRenderer.prototype;
2398
2593
 
2399
- return Math.sqrt(y);
2400
- };
2401
- /**
2402
- * 3x3 Matrix
2403
- * @module mat3
2404
- */
2594
+ _proto.hash = function hash(parsedStyle) {
2595
+ return '';
2596
+ };
2405
2597
 
2406
- /**
2407
- * Creates a new identity mat3
2408
- *
2409
- * @returns {mat3} a new 3x3 matrix
2410
- */
2598
+ _proto.render = function render(context, parsedStyle, object) {
2599
+ var lineWidth = parsedStyle.lineWidth,
2600
+ textAlign = parsedStyle.textAlign,
2601
+ textBaseline = parsedStyle.textBaseline,
2602
+ lineJoin = parsedStyle.lineJoin,
2603
+ _parsedStyle$miterLim = parsedStyle.miterLimit,
2604
+ miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
2605
+ _parsedStyle$letterSp = parsedStyle.letterSpacing,
2606
+ letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
2607
+ stroke = parsedStyle.stroke,
2608
+ fill = parsedStyle.fill,
2609
+ fillOpacity = parsedStyle.fillOpacity,
2610
+ strokeOpacity = parsedStyle.strokeOpacity,
2611
+ opacity = parsedStyle.opacity,
2612
+ metrics = parsedStyle.metrics,
2613
+ dx = parsedStyle.dx,
2614
+ dy = parsedStyle.dy;
2615
+ var font = metrics.font,
2616
+ lines = metrics.lines,
2617
+ height = metrics.height,
2618
+ lineHeight = metrics.lineHeight,
2619
+ lineMetrics = metrics.lineMetrics;
2620
+ context.font = font;
2621
+ context.lineWidth = lineWidth.value;
2622
+ context.textAlign = textAlign.value;
2623
+ context.textBaseline = textBaseline.value;
2624
+ context.lineJoin = lineJoin.value;
2625
+ context.miterLimit = miterLimit;
2626
+ var linePositionY = 0; // handle vertical text baseline
2411
2627
 
2412
- function create() {
2413
- var out = new ARRAY_TYPE(9);
2628
+ if (textBaseline.value === 'middle') {
2629
+ linePositionY = -height / 2 - lineHeight / 2;
2630
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
2631
+ linePositionY = -height;
2632
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
2633
+ linePositionY = -lineHeight;
2634
+ } // account for dx & dy
2414
2635
 
2415
- if (ARRAY_TYPE != Float32Array) {
2416
- out[1] = 0;
2417
- out[2] = 0;
2418
- out[3] = 0;
2419
- out[5] = 0;
2420
- out[6] = 0;
2421
- out[7] = 0;
2422
- }
2423
2636
 
2424
- out[0] = 1;
2425
- out[4] = 1;
2426
- out[8] = 1;
2427
- return out;
2428
- }
2429
- /**
2430
- * Returns the translation vector component of a transformation
2431
- * matrix. If a matrix is built with fromRotationTranslation,
2432
- * the returned vector will be the same as the translation vector
2433
- * originally supplied.
2434
- * @param {vec3} out Vector to receive translation component
2435
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
2436
- * @return {vec3} out
2437
- */
2637
+ var offsetX = 0;
2438
2638
 
2639
+ if (dx && dx.unit === g.UnitType.kPixels) {
2640
+ offsetX += dx.value;
2641
+ }
2439
2642
 
2440
- function getTranslation(out, mat) {
2441
- out[0] = mat[12];
2442
- out[1] = mat[13];
2443
- out[2] = mat[14];
2444
- return out;
2445
- }
2446
- /**
2447
- * Returns the scaling factor component of a transformation
2448
- * matrix. If a matrix is built with fromRotationTranslationScale
2449
- * with a normalized Quaternion paramter, the returned vector will be
2450
- * the same as the scaling vector
2451
- * originally supplied.
2452
- * @param {vec3} out Vector to receive scaling factor component
2453
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
2454
- * @return {vec3} out
2455
- */
2643
+ if (dy && dy.unit === g.UnitType.kPixels) {
2644
+ linePositionY += dy.value;
2645
+ } // draw lines line by line
2456
2646
 
2457
2647
 
2458
- function getScaling(out, mat) {
2459
- var m11 = mat[0];
2460
- var m12 = mat[1];
2461
- var m13 = mat[2];
2462
- var m21 = mat[4];
2463
- var m22 = mat[5];
2464
- var m23 = mat[6];
2465
- var m31 = mat[8];
2466
- var m32 = mat[9];
2467
- var m33 = mat[10];
2468
- out[0] = Math.hypot(m11, m12, m13);
2469
- out[1] = Math.hypot(m21, m22, m23);
2470
- out[2] = Math.hypot(m31, m32, m33);
2471
- return out;
2472
- }
2473
- /**
2474
- * Returns a quaternion representing the rotational component
2475
- * of a transformation matrix. If a matrix is built with
2476
- * fromRotationTranslation, the returned quaternion will be the
2477
- * same as the quaternion originally supplied.
2478
- * @param {quat} out Quaternion to receive the rotation component
2479
- * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
2480
- * @return {quat} out
2481
- */
2648
+ for (var i = 0; i < lines.length; i++) {
2649
+ var linePositionX = lineWidth.value / 2 + offsetX;
2650
+ linePositionY += lineHeight; // no need to re-position X, cause we already set text align
2651
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
2652
+
2653
+ if (!g.isNil(stroke) && lineWidth && lineWidth.value) {
2654
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
2655
+ }
2656
+
2657
+ if (!g.isNil(fill)) {
2658
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
2659
+ }
2660
+ }
2661
+ };
2482
2662
 
2663
+ _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
2664
+ if (isStroke === void 0) {
2665
+ isStroke = false;
2666
+ } // letterSpacing of 0 means normal, render all texts directly
2483
2667
 
2484
- function getRotation(out, mat) {
2485
- var scaling = new ARRAY_TYPE(3);
2486
- getScaling(scaling, mat);
2487
- var is1 = 1 / scaling[0];
2488
- var is2 = 1 / scaling[1];
2489
- var is3 = 1 / scaling[2];
2490
- var sm11 = mat[0] * is1;
2491
- var sm12 = mat[1] * is2;
2492
- var sm13 = mat[2] * is3;
2493
- var sm21 = mat[4] * is1;
2494
- var sm22 = mat[5] * is2;
2495
- var sm23 = mat[6] * is3;
2496
- var sm31 = mat[8] * is1;
2497
- var sm32 = mat[9] * is2;
2498
- var sm33 = mat[10] * is3;
2499
- var trace = sm11 + sm22 + sm33;
2500
- var S = 0;
2501
2668
 
2502
- if (trace > 0) {
2503
- S = Math.sqrt(trace + 1.0) * 2;
2504
- out[3] = 0.25 * S;
2505
- out[0] = (sm23 - sm32) / S;
2506
- out[1] = (sm31 - sm13) / S;
2507
- out[2] = (sm12 - sm21) / S;
2508
- } else if (sm11 > sm22 && sm11 > sm33) {
2509
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
2510
- out[3] = (sm23 - sm32) / S;
2511
- out[0] = 0.25 * S;
2512
- out[1] = (sm12 + sm21) / S;
2513
- out[2] = (sm31 + sm13) / S;
2514
- } else if (sm22 > sm33) {
2515
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
2516
- out[3] = (sm31 - sm13) / S;
2517
- out[0] = (sm12 + sm21) / S;
2518
- out[1] = 0.25 * S;
2519
- out[2] = (sm23 + sm32) / S;
2520
- } else {
2521
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
2522
- out[3] = (sm12 - sm21) / S;
2523
- out[0] = (sm31 + sm13) / S;
2524
- out[1] = (sm23 + sm32) / S;
2525
- out[2] = 0.25 * S;
2526
- }
2669
+ if (letterSpacing === 0) {
2670
+ if (isStroke) {
2671
+ this.strokeText(context, text, x, y, strokeOpacity);
2672
+ } else {
2673
+ this.fillText(context, text, x, y, fillOpacity, opacity);
2674
+ }
2527
2675
 
2528
- return out;
2529
- }
2530
- /**
2531
- * 3 Dimensional Vector
2532
- * @module vec3
2533
- */
2676
+ return;
2677
+ } // draw text using left align
2534
2678
 
2535
- /**
2536
- * Creates a new, empty vec3
2537
- *
2538
- * @returns {vec3} a new 3D vector
2539
- */
2540
2679
 
2680
+ var currentTextAlign = context.textAlign;
2681
+ context.textAlign = 'left';
2682
+ var currentPosition = x;
2541
2683
 
2542
- function create$1() {
2543
- var out = new ARRAY_TYPE(3);
2684
+ if (textAlign === 'center') {
2685
+ currentPosition = x - lineMetrics.width / 2;
2686
+ } else if (textAlign === 'right' || textAlign === 'end') {
2687
+ currentPosition = x - lineMetrics.width;
2688
+ }
2544
2689
 
2545
- if (ARRAY_TYPE != Float32Array) {
2546
- out[0] = 0;
2547
- out[1] = 0;
2548
- out[2] = 0;
2549
- }
2690
+ var stringArray = Array.from(text);
2691
+ var previousWidth = context.measureText(text).width;
2692
+ var currentWidth = 0;
2550
2693
 
2551
- return out;
2552
- }
2553
- /**
2554
- * Calculates the length of a vec3
2555
- *
2556
- * @param {ReadonlyVec3} a vector to calculate length of
2557
- * @returns {Number} length of a
2558
- */
2694
+ for (var i = 0; i < stringArray.length; ++i) {
2695
+ var currentChar = stringArray[i];
2559
2696
 
2697
+ if (isStroke) {
2698
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
2699
+ } else {
2700
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
2701
+ }
2560
2702
 
2561
- function length(a) {
2562
- var x = a[0];
2563
- var y = a[1];
2564
- var z = a[2];
2565
- return Math.hypot(x, y, z);
2566
- }
2567
- /**
2568
- * Creates a new vec3 initialized with the given values
2569
- *
2570
- * @param {Number} x X component
2571
- * @param {Number} y Y component
2572
- * @param {Number} z Z component
2573
- * @returns {vec3} a new 3D vector
2574
- */
2703
+ currentWidth = context.measureText(text.substring(i + 1)).width;
2704
+ currentPosition += previousWidth - currentWidth + letterSpacing;
2705
+ previousWidth = currentWidth;
2706
+ }
2575
2707
 
2708
+ context.textAlign = currentTextAlign;
2709
+ };
2576
2710
 
2577
- function fromValues(x, y, z) {
2578
- var out = new ARRAY_TYPE(3);
2579
- out[0] = x;
2580
- out[1] = y;
2581
- out[2] = z;
2582
- return out;
2583
- }
2584
- /**
2585
- * Normalize a vec3
2586
- *
2587
- * @param {vec3} out the receiving vector
2588
- * @param {ReadonlyVec3} a vector to normalize
2589
- * @returns {vec3} out
2590
- */
2711
+ _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
2712
+ var currentGlobalAlpha;
2713
+ var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
2591
2714
 
2715
+ if (applyOpacity) {
2716
+ currentGlobalAlpha = context.globalAlpha;
2717
+ context.globalAlpha = fillOpacity * opacity;
2718
+ }
2592
2719
 
2593
- function normalize(out, a) {
2594
- var x = a[0];
2595
- var y = a[1];
2596
- var z = a[2];
2597
- var len = x * x + y * y + z * z;
2720
+ context.fillText(text, x, y);
2598
2721
 
2599
- if (len > 0) {
2600
- //TODO: evaluate use of glm_invsqrt here?
2601
- len = 1 / Math.sqrt(len);
2602
- }
2722
+ if (applyOpacity) {
2723
+ context.globalAlpha = currentGlobalAlpha;
2724
+ }
2725
+ };
2603
2726
 
2604
- out[0] = a[0] * len;
2605
- out[1] = a[1] * len;
2606
- out[2] = a[2] * len;
2607
- return out;
2608
- }
2609
- /**
2610
- * Calculates the dot product of two vec3's
2611
- *
2612
- * @param {ReadonlyVec3} a the first operand
2613
- * @param {ReadonlyVec3} b the second operand
2614
- * @returns {Number} dot product of a and b
2615
- */
2727
+ _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
2728
+ var currentGlobalAlpha;
2729
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
2730
+
2731
+ if (applyOpacity) {
2732
+ currentGlobalAlpha = context.globalAlpha;
2733
+ context.globalAlpha = strokeOpacity;
2734
+ }
2616
2735
 
2736
+ context.strokeText(text, x, y);
2617
2737
 
2618
- function dot(a, b) {
2619
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2620
- }
2621
- /**
2622
- * Computes the cross product of two vec3's
2623
- *
2624
- * @param {vec3} out the receiving vector
2625
- * @param {ReadonlyVec3} a the first operand
2626
- * @param {ReadonlyVec3} b the second operand
2627
- * @returns {vec3} out
2628
- */
2738
+ if (applyOpacity) {
2739
+ context.globalAlpha = currentGlobalAlpha;
2740
+ }
2741
+ };
2629
2742
 
2743
+ return TextRenderer;
2744
+ }();
2630
2745
 
2631
- function cross(out, a, b) {
2632
- var ax = a[0],
2633
- ay = a[1],
2634
- az = a[2];
2635
- var bx = b[0],
2636
- by = b[1],
2637
- bz = b[2];
2638
- out[0] = ay * bz - az * by;
2639
- out[1] = az * bx - ax * bz;
2640
- out[2] = ax * by - ay * bx;
2641
- return out;
2642
- }
2643
- /**
2644
- * Alias for {@link vec3.length}
2645
- * @function
2646
- */
2746
+ TextRenderer = __decorate([manaSyringe.singleton({
2747
+ token: TextRendererContribution
2748
+ })], TextRenderer);
2647
2749
 
2750
+ var DefaultRenderer = /*#__PURE__*/function () {
2751
+ function DefaultRenderer() {}
2648
2752
 
2649
- var len = length;
2650
- /**
2651
- * Perform some operation over an array of vec3s.
2652
- *
2653
- * @param {Array} a the array of vectors to iterate over
2654
- * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
2655
- * @param {Number} offset Number of elements to skip at the beginning of the array
2656
- * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
2657
- * @param {Function} fn Function to call for each vector in the array
2658
- * @param {Object} [arg] additional argument to pass to fn
2659
- * @returns {Array} a
2660
- * @function
2661
- */
2753
+ var _proto = DefaultRenderer.prototype;
2662
2754
 
2663
- var forEach = function () {
2664
- var vec = create$1();
2665
- return function (a, stride, offset, count, fn, arg) {
2666
- var i, l;
2755
+ _proto.hash = function hash(parsedStyle) {
2756
+ // const { fill, opacity, fillOpacity, stroke, strokeOpacity, lineWidth, lineCap, lineJoin } =
2757
+ // parsedStyle;
2758
+ // return fill + opacity + fillOpacity + stroke + strokeOpacity + lineWidth + lineCap + lineJoin;
2759
+ return '';
2760
+ };
2667
2761
 
2668
- if (!stride) {
2669
- stride = 3;
2670
- }
2762
+ _proto.render = function render(context, parsedStyle) {
2763
+ var fill = parsedStyle.fill,
2764
+ opacity = parsedStyle.opacity,
2765
+ fillOpacity = parsedStyle.fillOpacity,
2766
+ stroke = parsedStyle.stroke,
2767
+ strokeOpacity = parsedStyle.strokeOpacity,
2768
+ lineWidth = parsedStyle.lineWidth,
2769
+ lineCap = parsedStyle.lineCap,
2770
+ lineJoin = parsedStyle.lineJoin,
2771
+ shadowColor = parsedStyle.shadowColor,
2772
+ filter = parsedStyle.filter,
2773
+ miterLimit = parsedStyle.miterLimit;
2774
+ var hasFill = !g.isNil(fill);
2775
+ var hasStroke = !g.isNil(stroke);
2776
+ var isFillTransparent = fill.alpha === 0;
2671
2777
 
2672
- if (!offset) {
2673
- offset = 0;
2778
+ if (hasFill) {
2779
+ if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
2780
+ context.globalAlpha = fillOpacity.value;
2781
+ context.fill();
2782
+ context.globalAlpha = opacity.value;
2783
+ } else {
2784
+ context.fill();
2785
+ }
2674
2786
  }
2675
2787
 
2676
- if (count) {
2677
- l = Math.min(count * stride + offset, a.length);
2678
- } else {
2679
- l = a.length;
2680
- }
2788
+ if (hasStroke) {
2789
+ if (lineWidth && lineWidth.value > 0) {
2790
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
2681
2791
 
2682
- for (i = offset; i < l; i += stride) {
2683
- vec[0] = a[i];
2684
- vec[1] = a[i + 1];
2685
- vec[2] = a[i + 2];
2686
- fn(vec, vec, arg);
2687
- a[i] = vec[0];
2688
- a[i + 1] = vec[1];
2689
- a[i + 2] = vec[2];
2690
- }
2792
+ if (applyOpacity) {
2793
+ context.globalAlpha = strokeOpacity.value;
2794
+ }
2691
2795
 
2692
- return a;
2693
- };
2694
- }();
2695
- /**
2696
- * 4 Dimensional Vector
2697
- * @module vec4
2698
- */
2796
+ context.lineWidth = lineWidth.value;
2699
2797
 
2700
- /**
2701
- * Creates a new, empty vec4
2702
- *
2703
- * @returns {vec4} a new 4D vector
2704
- */
2798
+ if (!g.isNil(miterLimit)) {
2799
+ context.miterLimit = miterLimit;
2800
+ }
2705
2801
 
2802
+ if (!g.isNil(lineCap)) {
2803
+ context.lineCap = lineCap.value;
2804
+ }
2706
2805
 
2707
- function create$2() {
2708
- var out = new ARRAY_TYPE(4);
2806
+ if (!g.isNil(lineJoin)) {
2807
+ context.lineJoin = lineJoin.value;
2808
+ }
2709
2809
 
2710
- if (ARRAY_TYPE != Float32Array) {
2711
- out[0] = 0;
2712
- out[1] = 0;
2713
- out[2] = 0;
2714
- out[3] = 0;
2715
- }
2810
+ var oldShadowBlur;
2811
+ var oldShadowColor;
2812
+ var oldFilter;
2813
+ var hasShadowColor = !g.isNil(shadowColor);
2814
+ var hasFilter = !g.isNil(filter);
2716
2815
 
2717
- return out;
2718
- }
2719
- /**
2720
- * Normalize a vec4
2721
- *
2722
- * @param {vec4} out the receiving vector
2723
- * @param {ReadonlyVec4} a vector to normalize
2724
- * @returns {vec4} out
2725
- */
2816
+ if (hasShadowColor) {
2817
+ // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
2818
+ // save shadow blur
2819
+ oldShadowBlur = context.shadowBlur;
2820
+ oldShadowColor = context.shadowColor;
2726
2821
 
2822
+ if (!g.isNil(oldShadowBlur)) {
2823
+ context.shadowColor = 'transparent';
2824
+ context.shadowBlur = 0;
2825
+ }
2826
+ }
2727
2827
 
2728
- function normalize$1(out, a) {
2729
- var x = a[0];
2730
- var y = a[1];
2731
- var z = a[2];
2732
- var w = a[3];
2733
- var len = x * x + y * y + z * z + w * w;
2828
+ if (hasFilter) {
2829
+ // save drop-shadow filter
2830
+ oldFilter = context.filter;
2734
2831
 
2735
- if (len > 0) {
2736
- len = 1 / Math.sqrt(len);
2737
- }
2832
+ if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
2833
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
2834
+ }
2835
+ }
2738
2836
 
2739
- out[0] = x * len;
2740
- out[1] = y * len;
2741
- out[2] = z * len;
2742
- out[3] = w * len;
2743
- return out;
2744
- }
2745
- /**
2746
- * Perform some operation over an array of vec4s.
2747
- *
2748
- * @param {Array} a the array of vectors to iterate over
2749
- * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
2750
- * @param {Number} offset Number of elements to skip at the beginning of the array
2751
- * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
2752
- * @param {Function} fn Function to call for each vector in the array
2753
- * @param {Object} [arg] additional argument to pass to fn
2754
- * @returns {Array} a
2755
- * @function
2756
- */
2837
+ var drawStroke = hasFill && !isFillTransparent;
2757
2838
 
2839
+ if (drawStroke) {
2840
+ context.stroke();
2841
+ } // restore shadow blur
2758
2842
 
2759
- var forEach$1 = function () {
2760
- var vec = create$2();
2761
- return function (a, stride, offset, count, fn, arg) {
2762
- var i, l;
2763
2843
 
2764
- if (!stride) {
2765
- stride = 4;
2766
- }
2844
+ if (hasShadowColor) {
2845
+ context.shadowColor = oldShadowColor;
2846
+ context.shadowBlur = oldShadowBlur;
2847
+ } // restore filters
2767
2848
 
2768
- if (!offset) {
2769
- offset = 0;
2770
- }
2771
2849
 
2772
- if (count) {
2773
- l = Math.min(count * stride + offset, a.length);
2774
- } else {
2775
- l = a.length;
2776
- }
2850
+ if (hasFilter) {
2851
+ context.filter = oldFilter;
2852
+ }
2777
2853
 
2778
- for (i = offset; i < l; i += stride) {
2779
- vec[0] = a[i];
2780
- vec[1] = a[i + 1];
2781
- vec[2] = a[i + 2];
2782
- vec[3] = a[i + 3];
2783
- fn(vec, vec, arg);
2784
- a[i] = vec[0];
2785
- a[i + 1] = vec[1];
2786
- a[i + 2] = vec[2];
2787
- a[i + 3] = vec[3];
2854
+ if (!drawStroke) {
2855
+ context.stroke();
2856
+ }
2857
+ }
2788
2858
  }
2789
-
2790
- return a;
2791
2859
  };
2860
+
2861
+ return DefaultRenderer;
2792
2862
  }();
2793
- /**
2794
- * Quaternion
2795
- * @module quat
2796
- */
2797
2863
 
2798
- /**
2799
- * Creates a new identity quat
2800
- *
2801
- * @returns {quat} a new quaternion
2802
- */
2864
+ DefaultRenderer = __decorate([manaSyringe.singleton()], DefaultRenderer);
2865
+
2866
+ var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2867
+ _inheritsLoose$1(RectRenderer, _DefaultRenderer);
2803
2868
 
2869
+ function RectRenderer() {
2870
+ return _DefaultRenderer.apply(this, arguments) || this;
2871
+ }
2804
2872
 
2805
- function create$3() {
2806
- var out = new ARRAY_TYPE(4);
2873
+ return RectRenderer;
2874
+ }(DefaultRenderer);
2807
2875
 
2808
- if (ARRAY_TYPE != Float32Array) {
2809
- out[0] = 0;
2810
- out[1] = 0;
2811
- out[2] = 0;
2876
+ RectRenderer = __decorate([manaSyringe.singleton({
2877
+ token: RectRendererContribution
2878
+ })], RectRenderer);
2879
+
2880
+ var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2881
+ _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
2882
+
2883
+ function CircleRenderer() {
2884
+ return _DefaultRenderer.apply(this, arguments) || this;
2812
2885
  }
2813
2886
 
2814
- out[3] = 1;
2815
- return out;
2816
- }
2817
- /**
2818
- * Sets a quat from the given angle and rotation axis,
2819
- * then returns it.
2820
- *
2821
- * @param {quat} out the receiving quaternion
2822
- * @param {ReadonlyVec3} axis the axis around which to rotate
2823
- * @param {Number} rad the angle in radians
2824
- * @returns {quat} out
2825
- **/
2887
+ return CircleRenderer;
2888
+ }(DefaultRenderer);
2826
2889
 
2890
+ CircleRenderer = __decorate([manaSyringe.singleton({
2891
+ token: CircleRendererContribution
2892
+ })], CircleRenderer);
2827
2893
 
2828
- function setAxisAngle(out, axis, rad) {
2829
- rad = rad * 0.5;
2830
- var s = Math.sin(rad);
2831
- out[0] = s * axis[0];
2832
- out[1] = s * axis[1];
2833
- out[2] = s * axis[2];
2834
- out[3] = Math.cos(rad);
2835
- return out;
2836
- }
2837
- /**
2838
- * Performs a spherical linear interpolation between two quat
2839
- *
2840
- * @param {quat} out the receiving quaternion
2841
- * @param {ReadonlyQuat} a the first operand
2842
- * @param {ReadonlyQuat} b the second operand
2843
- * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2844
- * @returns {quat} out
2845
- */
2894
+ var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2895
+ _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
2896
+
2897
+ function EllipseRenderer() {
2898
+ return _DefaultRenderer.apply(this, arguments) || this;
2899
+ }
2900
+
2901
+ return EllipseRenderer;
2902
+ }(DefaultRenderer);
2903
+
2904
+ EllipseRenderer = __decorate([manaSyringe.singleton({
2905
+ token: EllipseRendererContribution
2906
+ })], EllipseRenderer);
2907
+
2908
+ var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2909
+ _inheritsLoose$1(LineRenderer, _DefaultRenderer);
2910
+
2911
+ function LineRenderer() {
2912
+ return _DefaultRenderer.apply(this, arguments) || this;
2913
+ }
2914
+
2915
+ return LineRenderer;
2916
+ }(DefaultRenderer);
2846
2917
 
2918
+ LineRenderer = __decorate([manaSyringe.singleton({
2919
+ token: LineRendererContribution
2920
+ })], LineRenderer);
2847
2921
 
2848
- function slerp(out, a, b, t) {
2849
- // benchmarks:
2850
- // http://jsperf.com/quaternion-slerp-implementations
2851
- var ax = a[0],
2852
- ay = a[1],
2853
- az = a[2],
2854
- aw = a[3];
2855
- var bx = b[0],
2856
- by = b[1],
2857
- bz = b[2],
2858
- bw = b[3];
2859
- var omega, cosom, sinom, scale0, scale1; // calc cosine
2922
+ var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2923
+ _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
2860
2924
 
2861
- cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
2925
+ function PolylineRenderer() {
2926
+ return _DefaultRenderer.apply(this, arguments) || this;
2927
+ }
2862
2928
 
2863
- if (cosom < 0.0) {
2864
- cosom = -cosom;
2865
- bx = -bx;
2866
- by = -by;
2867
- bz = -bz;
2868
- bw = -bw;
2869
- } // calculate coefficients
2929
+ return PolylineRenderer;
2930
+ }(DefaultRenderer);
2870
2931
 
2932
+ PolylineRenderer = __decorate([manaSyringe.singleton({
2933
+ token: PolylineRendererContribution
2934
+ })], PolylineRenderer);
2871
2935
 
2872
- if (1.0 - cosom > EPSILON) {
2873
- // standard case (slerp)
2874
- omega = Math.acos(cosom);
2875
- sinom = Math.sin(omega);
2876
- scale0 = Math.sin((1.0 - t) * omega) / sinom;
2877
- scale1 = Math.sin(t * omega) / sinom;
2878
- } else {
2879
- // "from" and "to" quaternions are very close
2880
- // ... so we can do a linear interpolation
2881
- scale0 = 1.0 - t;
2882
- scale1 = t;
2883
- } // calculate final values
2936
+ var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2937
+ _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
2884
2938
 
2939
+ function PolygonRenderer() {
2940
+ return _DefaultRenderer.apply(this, arguments) || this;
2941
+ }
2885
2942
 
2886
- out[0] = scale0 * ax + scale1 * bx;
2887
- out[1] = scale0 * ay + scale1 * by;
2888
- out[2] = scale0 * az + scale1 * bz;
2889
- out[3] = scale0 * aw + scale1 * bw;
2890
- return out;
2891
- }
2892
- /**
2893
- * Creates a quaternion from the given 3x3 rotation matrix.
2894
- *
2895
- * NOTE: The resultant quaternion is not normalized, so you should be sure
2896
- * to renormalize the quaternion yourself where necessary.
2897
- *
2898
- * @param {quat} out the receiving quaternion
2899
- * @param {ReadonlyMat3} m rotation matrix
2900
- * @returns {quat} out
2901
- * @function
2902
- */
2943
+ return PolygonRenderer;
2944
+ }(DefaultRenderer);
2903
2945
 
2946
+ PolygonRenderer = __decorate([manaSyringe.singleton({
2947
+ token: PolygonRendererContribution
2948
+ })], PolygonRenderer);
2904
2949
 
2905
- function fromMat3(out, m) {
2906
- // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
2907
- // article "Quaternion Calculus and Fast Animation".
2908
- var fTrace = m[0] + m[4] + m[8];
2909
- var fRoot;
2950
+ var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2951
+ _inheritsLoose$1(PathRenderer, _DefaultRenderer);
2910
2952
 
2911
- if (fTrace > 0.0) {
2912
- // |w| > 1/2, may as well choose w > 1/2
2913
- fRoot = Math.sqrt(fTrace + 1.0); // 2w
2953
+ function PathRenderer() {
2954
+ return _DefaultRenderer.apply(this, arguments) || this;
2955
+ }
2914
2956
 
2915
- out[3] = 0.5 * fRoot;
2916
- fRoot = 0.5 / fRoot; // 1/(4w)
2957
+ return PathRenderer;
2958
+ }(DefaultRenderer);
2917
2959
 
2918
- out[0] = (m[5] - m[7]) * fRoot;
2919
- out[1] = (m[6] - m[2]) * fRoot;
2920
- out[2] = (m[1] - m[3]) * fRoot;
2921
- } else {
2922
- // |w| <= 1/2
2923
- var i = 0;
2924
- if (m[4] > m[0]) i = 1;
2925
- if (m[8] > m[i * 3 + i]) i = 2;
2926
- var j = (i + 1) % 3;
2927
- var k = (i + 2) % 3;
2928
- fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
2929
- out[i] = 0.5 * fRoot;
2930
- fRoot = 0.5 / fRoot;
2931
- out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
2932
- out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
2933
- out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
2960
+ PathRenderer = __decorate([manaSyringe.singleton({
2961
+ token: PathRendererContribution
2962
+ })], PathRenderer);
2963
+
2964
+ var GradientPool = /*#__PURE__*/function () {
2965
+ function GradientPool() {
2966
+ this.gradientCache = {};
2934
2967
  }
2935
2968
 
2936
- return out;
2937
- }
2938
- /**
2939
- * Normalize a quat
2940
- *
2941
- * @param {quat} out the receiving quaternion
2942
- * @param {ReadonlyQuat} a quaternion to normalize
2943
- * @returns {quat} out
2944
- * @function
2945
- */
2969
+ var _proto = GradientPool.prototype;
2970
+
2971
+ _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2972
+ var key = this.generateCacheKey(params);
2973
+ var type = params.type,
2974
+ x0 = params.x0,
2975
+ y0 = params.y0,
2976
+ x1 = params.x1,
2977
+ y1 = params.y1,
2978
+ steps = params.steps,
2979
+ width = params.width,
2980
+ height = params.height;
2946
2981
 
2982
+ if (this.gradientCache[key]) {
2983
+ return this.gradientCache[key];
2984
+ }
2947
2985
 
2948
- var normalize$2 = normalize$1;
2949
- /**
2950
- * Sets a quaternion to represent the shortest rotation from one
2951
- * vector to another.
2952
- *
2953
- * Both vectors are assumed to be unit length.
2954
- *
2955
- * @param {quat} out the receiving quaternion.
2956
- * @param {ReadonlyVec3} a the initial vector
2957
- * @param {ReadonlyVec3} b the destination vector
2958
- * @returns {quat} out
2959
- */
2986
+ var gradient = null;
2960
2987
 
2961
- var rotationTo = function () {
2962
- var tmpvec3 = create$1();
2963
- var xUnitVec3 = fromValues(1, 0, 0);
2964
- var yUnitVec3 = fromValues(0, 1, 0);
2965
- return function (out, a, b) {
2966
- var dot$1 = dot(a, b);
2988
+ if (type === g.GradientPatternType.LinearGradient) {
2989
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2990
+ gradient = context.createLinearGradient(x0 * width, y0 * height, x1 * width, y1 * height);
2991
+ } else if (type === g.GradientPatternType.RadialGradient) {
2992
+ var r = Math.sqrt(width * width + height * height) / 2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2967
2993
 
2968
- if (dot$1 < -0.999999) {
2969
- cross(tmpvec3, xUnitVec3, a);
2970
- if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
2971
- normalize(tmpvec3, tmpvec3);
2972
- setAxisAngle(out, tmpvec3, Math.PI);
2973
- return out;
2974
- } else if (dot$1 > 0.999999) {
2975
- out[0] = 0;
2976
- out[1] = 0;
2977
- out[2] = 0;
2978
- out[3] = 1;
2979
- return out;
2980
- } else {
2981
- cross(tmpvec3, a, b);
2982
- out[0] = tmpvec3[0];
2983
- out[1] = tmpvec3[1];
2984
- out[2] = tmpvec3[2];
2985
- out[3] = 1 + dot$1;
2986
- return normalize$2(out, out);
2994
+ gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2987
2995
  }
2988
- };
2989
- }();
2990
- /**
2991
- * Performs a spherical linear interpolation with two control points
2992
- *
2993
- * @param {quat} out the receiving quaternion
2994
- * @param {ReadonlyQuat} a the first operand
2995
- * @param {ReadonlyQuat} b the second operand
2996
- * @param {ReadonlyQuat} c the third operand
2997
- * @param {ReadonlyQuat} d the fourth operand
2998
- * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2999
- * @returns {quat} out
3000
- */
3001
2996
 
2997
+ if (gradient) {
2998
+ steps.forEach(function (_ref) {
2999
+ var _gradient;
3002
3000
 
3003
- var sqlerp = function () {
3004
- var temp1 = create$3();
3005
- var temp2 = create$3();
3006
- return function (out, a, b, c, d, t) {
3007
- slerp(temp1, a, d, t);
3008
- slerp(temp2, b, c, t);
3009
- slerp(out, temp1, temp2, 2 * t * (1 - t));
3010
- return out;
3011
- };
3012
- }();
3013
- /**
3014
- * Sets the specified quaternion with values corresponding to the given
3015
- * axes. Each axis is a vec3 and is expected to be unit length and
3016
- * perpendicular to all other specified axes.
3017
- *
3018
- * @param {ReadonlyVec3} view the vector representing the viewing direction
3019
- * @param {ReadonlyVec3} right the vector representing the local "right" direction
3020
- * @param {ReadonlyVec3} up the vector representing the local "up" direction
3021
- * @returns {quat} out
3022
- */
3001
+ var offset = _ref[0],
3002
+ color = _ref[1];
3003
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(Number(offset), color);
3004
+ });
3005
+ this.gradientCache[key] = gradient;
3006
+ }
3023
3007
 
3008
+ return this.gradientCache[key];
3009
+ };
3024
3010
 
3025
- var setAxes = function () {
3026
- var matr = create();
3027
- return function (out, view, right, up) {
3028
- matr[0] = right[0];
3029
- matr[3] = right[1];
3030
- matr[6] = right[2];
3031
- matr[1] = up[0];
3032
- matr[4] = up[1];
3033
- matr[7] = up[2];
3034
- matr[2] = -view[0];
3035
- matr[5] = -view[1];
3036
- matr[8] = -view[2];
3037
- return normalize$2(out, fromMat3(out, matr));
3011
+ _proto.generateCacheKey = function generateCacheKey(params) {
3012
+ // @ts-ignore
3013
+ var type = params.type,
3014
+ x0 = params.x0,
3015
+ y0 = params.y0,
3016
+ x1 = params.x1,
3017
+ y1 = params.y1,
3018
+ r1 = params.r1,
3019
+ steps = params.steps,
3020
+ width = params.width,
3021
+ height = params.height;
3022
+ return "gradient-" + type + "-" + x0 + "-" + y0 + "-" + x1 + "-" + y1 + "-" + (r1 || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
3023
+ return step.join('');
3024
+ }).join('-');
3038
3025
  };
3026
+
3027
+ return GradientPool;
3039
3028
  }();
3040
3029
 
3030
+ GradientPool = __decorate([manaSyringe.singleton()], GradientPool);
3031
+
3041
3032
  var RBushNode = function RBushNode() {
3042
3033
  this.aabb = void 0;
3043
3034
  };