@antv/g-svg 1.8.47 → 1.8.49

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
@@ -876,147 +876,6 @@
876
876
  Plugin: Plugin
877
877
  });
878
878
 
879
- /**
880
- * Common utilities
881
- * @module glMatrix
882
- */
883
- var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
884
- if (!Math.hypot) Math.hypot = function () {
885
- var y = 0,
886
- i = arguments.length;
887
-
888
- while (i--) {
889
- y += arguments[i] * arguments[i];
890
- }
891
-
892
- return Math.sqrt(y);
893
- };
894
-
895
- /**
896
- * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
897
- * @module mat4
898
- */
899
-
900
- /**
901
- * Creates a new identity mat4
902
- *
903
- * @returns {mat4} a new 4x4 matrix
904
- */
905
-
906
- function create() {
907
- var out = new ARRAY_TYPE(16);
908
-
909
- if (ARRAY_TYPE != Float32Array) {
910
- out[1] = 0;
911
- out[2] = 0;
912
- out[3] = 0;
913
- out[4] = 0;
914
- out[6] = 0;
915
- out[7] = 0;
916
- out[8] = 0;
917
- out[9] = 0;
918
- out[11] = 0;
919
- out[12] = 0;
920
- out[13] = 0;
921
- out[14] = 0;
922
- }
923
-
924
- out[0] = 1;
925
- out[5] = 1;
926
- out[10] = 1;
927
- out[15] = 1;
928
- return out;
929
- }
930
- /**
931
- * Inverts a mat4
932
- *
933
- * @param {mat4} out the receiving matrix
934
- * @param {ReadonlyMat4} a the source matrix
935
- * @returns {mat4} out
936
- */
937
-
938
- function invert(out, a) {
939
- var a00 = a[0],
940
- a01 = a[1],
941
- a02 = a[2],
942
- a03 = a[3];
943
- var a10 = a[4],
944
- a11 = a[5],
945
- a12 = a[6],
946
- a13 = a[7];
947
- var a20 = a[8],
948
- a21 = a[9],
949
- a22 = a[10],
950
- a23 = a[11];
951
- var a30 = a[12],
952
- a31 = a[13],
953
- a32 = a[14],
954
- a33 = a[15];
955
- var b00 = a00 * a11 - a01 * a10;
956
- var b01 = a00 * a12 - a02 * a10;
957
- var b02 = a00 * a13 - a03 * a10;
958
- var b03 = a01 * a12 - a02 * a11;
959
- var b04 = a01 * a13 - a03 * a11;
960
- var b05 = a02 * a13 - a03 * a12;
961
- var b06 = a20 * a31 - a21 * a30;
962
- var b07 = a20 * a32 - a22 * a30;
963
- var b08 = a20 * a33 - a23 * a30;
964
- var b09 = a21 * a32 - a22 * a31;
965
- var b10 = a21 * a33 - a23 * a31;
966
- var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
967
-
968
- var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
969
-
970
- if (!det) {
971
- return null;
972
- }
973
-
974
- det = 1.0 / det;
975
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
976
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
977
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
978
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
979
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
980
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
981
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
982
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
983
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
984
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
985
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
986
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
987
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
988
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
989
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
990
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
991
- return out;
992
- }
993
-
994
- // isFinite,
995
- var isNil = function (value) {
996
- /**
997
- * isNil(null) => true
998
- * isNil() => true
999
- */
1000
- return value === null || value === undefined;
1001
- };
1002
-
1003
- var toString = {}.toString;
1004
- var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
1005
-
1006
- var isString = (function (str) {
1007
- return isType(str, 'String');
1008
- });
1009
-
1010
- var clamp = function (a, min, max) {
1011
- if (a < min) {
1012
- return min;
1013
- }
1014
- else if (a > max) {
1015
- return max;
1016
- }
1017
- return a;
1018
- };
1019
-
1020
879
  function _regeneratorRuntime$2() {
1021
880
  _regeneratorRuntime$2 = function _regeneratorRuntime() {
1022
881
  return exports;
@@ -1348,20 +1207,6 @@
1348
1207
  });
1349
1208
  };
1350
1209
  }
1351
- function _extends() {
1352
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1353
- for (var i = 1; i < arguments.length; i++) {
1354
- var source = arguments[i];
1355
- for (var key in source) {
1356
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1357
- target[key] = source[key];
1358
- }
1359
- }
1360
- }
1361
- return target;
1362
- };
1363
- return _extends.apply(this, arguments);
1364
- }
1365
1210
  function _inheritsLoose$2(subClass, superClass) {
1366
1211
  subClass.prototype = Object.create(superClass.prototype);
1367
1212
  subClass.prototype.constructor = subClass;
@@ -1374,2310 +1219,2465 @@
1374
1219
  };
1375
1220
  return _setPrototypeOf$2(o, p);
1376
1221
  }
1377
- var ElementSVG = function ElementSVG() {
1378
- /**
1379
- * basic element, eg. <circle>|<ellipse>
1380
- */
1381
- this.$el = void 0;
1382
- /**
1383
- * group wrapper for basic element, eg. <g><circle /></g>.
1384
- * if current element is <g>, same as `$el`
1385
- */
1386
- this.$groupEl = void 0;
1387
- /**
1388
- * hitArea:
1389
- * $groupEl -> $el
1390
- * -> $hitTestingEl
1391
- */
1392
- this.$hitTestingEl = void 0;
1393
- };
1394
- ElementSVG.tag = 'c-svg-element';
1395
- function updateImageElementAttribute($el, parsedStyle) {
1396
- var _parsedStyle$img = parsedStyle.img,
1397
- img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
1398
- width = parsedStyle.width,
1399
- height = parsedStyle.height;
1400
- $el.setAttribute('x', '0');
1401
- $el.setAttribute('y', '0');
1402
- if (isString(img)) {
1403
- $el.setAttribute('href', img);
1404
- } else if (img instanceof Image) {
1405
- if (!width) {
1406
- $el.setAttribute('width', "" + img.width);
1407
- // TODO: set renderable.boundsDirty
1408
- // this.attr('width', img.width);
1409
- }
1410
-
1411
- if (!height) {
1412
- $el.setAttribute('height', "" + img.height);
1413
- // this.attr('height', img.height);
1414
- }
1415
-
1416
- $el.setAttribute('href', img.src);
1417
- } else if (
1418
- // @ts-ignore
1419
- img instanceof HTMLElement && isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
1420
- $el.setAttribute('href', img.toDataURL());
1421
- // @ts-ignore
1422
- } else if (img instanceof ImageData) {
1423
- var canvas = document.createElement('canvas');
1424
- // @ts-ignore
1425
- canvas.setAttribute('width', "" + img.width);
1426
- // @ts-ignore
1427
- canvas.setAttribute('height', "" + img.height);
1428
- var context = canvas.getContext('2d');
1429
- if (context) {
1430
- context.putImageData(img, 0, 0);
1431
- if (!width) {
1432
- // @ts-ignore
1433
- $el.setAttribute('width', "" + img.width);
1434
- // this.attr('width', img.width);
1435
- }
1436
-
1437
- if (!height) {
1438
- // @ts-ignore
1439
- $el.setAttribute('height', "" + img.height);
1440
- // this.attr('height', img.height);
1441
- }
1442
-
1443
- $el.setAttribute('href', canvas.toDataURL());
1444
- }
1222
+ function _unsupportedIterableToArray(o, minLen) {
1223
+ if (!o) return;
1224
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
1225
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1226
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1227
+ if (n === "Map" || n === "Set") return Array.from(o);
1228
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1229
+ }
1230
+ function _arrayLikeToArray(arr, len) {
1231
+ if (len == null || len > arr.length) len = arr.length;
1232
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
1233
+ return arr2;
1234
+ }
1235
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
1236
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1237
+ if (it) return (it = it.call(o)).next.bind(it);
1238
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
1239
+ if (it) o = it;
1240
+ var i = 0;
1241
+ return function () {
1242
+ if (i >= o.length) return {
1243
+ done: true
1244
+ };
1245
+ return {
1246
+ done: false,
1247
+ value: o[i++]
1248
+ };
1249
+ };
1445
1250
  }
1251
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1446
1252
  }
1447
- function updateLineElementAttribute($el, parsedStyle) {
1448
- var x1 = parsedStyle.x1,
1449
- y1 = parsedStyle.y1,
1450
- x2 = parsedStyle.x2,
1451
- y2 = parsedStyle.y2,
1452
- _parsedStyle$defX = parsedStyle.defX,
1453
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1454
- _parsedStyle$defY = parsedStyle.defY,
1455
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1456
- markerStart = parsedStyle.markerStart,
1457
- markerEnd = parsedStyle.markerEnd,
1458
- markerStartOffset = parsedStyle.markerStartOffset,
1459
- markerEndOffset = parsedStyle.markerEndOffset;
1460
- var startOffsetX = 0;
1461
- var startOffsetY = 0;
1462
- var endOffsetX = 0;
1463
- var endOffsetY = 0;
1464
- var rad = 0;
1465
- var x;
1466
- var y;
1467
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1468
- x = x2 - x1;
1469
- y = y2 - y1;
1470
- rad = Math.atan2(y, x);
1471
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1472
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1253
+
1254
+ /**
1255
+ * pick shape(s) with Mouse/Touch event
1256
+ *
1257
+ * 1. find AABB with r-tree
1258
+ * 2. use elementFromPoint
1259
+ */
1260
+ var SVGPickerPlugin = /*#__PURE__*/function () {
1261
+ function SVGPickerPlugin() {}
1262
+ var _proto = SVGPickerPlugin.prototype;
1263
+ _proto.apply = function apply(context, runtime) {
1264
+ var _this = this;
1265
+ var doc = context.config.document,
1266
+ renderingService = context.renderingService,
1267
+ svgElementMap = context.svgElementMap;
1268
+ renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
1269
+ var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
1270
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
1271
+ while (1) switch (_context.prev = _context.next) {
1272
+ case 0:
1273
+ return _context.abrupt("return", _this.pick(svgElementMap, doc, result));
1274
+ case 1:
1275
+ case "end":
1276
+ return _context.stop();
1277
+ }
1278
+ }, _callee);
1279
+ }));
1280
+ return function (_x) {
1281
+ return _ref.apply(this, arguments);
1282
+ };
1283
+ }());
1284
+ renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
1285
+ return _this.pick(svgElementMap, doc, result);
1286
+ });
1287
+ };
1288
+ _proto.pick = function pick(svgElementMap, doc, result) {
1289
+ var topmost = result.topmost,
1290
+ _result$position = result.position,
1291
+ clientX = _result$position.clientX,
1292
+ clientY = _result$position.clientY;
1293
+ try {
1294
+ var targets = [];
1295
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
1296
+ for (var _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY)), _step; !(_step = _iterator()).done;) {
1297
+ var element = _step.value;
1298
+ var target = svgElementMap.get(element);
1299
+ // don't need to account for `visibility` since DOM API already does
1300
+ if (target && target.isInteractive()) {
1301
+ targets.push(target);
1302
+ if (topmost) {
1303
+ result.picked = targets;
1304
+ return result;
1305
+ }
1306
+ }
1307
+ }
1308
+ result.picked = targets;
1309
+ } catch (e) {
1310
+ result.picked = [];
1311
+ }
1312
+ return result;
1313
+ };
1314
+ return SVGPickerPlugin;
1315
+ }();
1316
+ SVGPickerPlugin.tag = 'SVGPicker';
1317
+ var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
1318
+ _inheritsLoose$2(Plugin, _AbstractRendererPlug);
1319
+ function Plugin() {
1320
+ var _this;
1321
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1322
+ args[_key] = arguments[_key];
1323
+ }
1324
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
1325
+ _this.name = 'svg-picker';
1326
+ return _this;
1473
1327
  }
1474
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1475
- x = x1 - x2;
1476
- y = y1 - y2;
1477
- rad = Math.atan2(y, x);
1478
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1479
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1328
+ var _proto = Plugin.prototype;
1329
+ _proto.init = function init() {
1330
+ this.addRenderingPlugin(new SVGPickerPlugin());
1331
+ };
1332
+ _proto.destroy = function destroy() {
1333
+ this.removeAllRenderingPlugins();
1334
+ };
1335
+ return Plugin;
1336
+ }(gLite.AbstractRendererPlugin);
1337
+
1338
+ var index_esm$1 = /*#__PURE__*/Object.freeze({
1339
+ __proto__: null,
1340
+ Plugin: Plugin$1
1341
+ });
1342
+
1343
+ /**
1344
+ * Common utilities
1345
+ * @module glMatrix
1346
+ */
1347
+ var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
1348
+ if (!Math.hypot) Math.hypot = function () {
1349
+ var y = 0,
1350
+ i = arguments.length;
1351
+
1352
+ while (i--) {
1353
+ y += arguments[i] * arguments[i];
1480
1354
  }
1481
- // @see https://github.com/antvis/g/issues/1038
1482
- $el.setAttribute('x1', "" + (x1 - defX + startOffsetX));
1483
- $el.setAttribute('y1', "" + (y1 - defY + startOffsetY));
1484
- $el.setAttribute('x2', "" + (x2 - defX + endOffsetX));
1485
- $el.setAttribute('y2', "" + (y2 - defY + endOffsetY));
1486
- }
1487
- function updatePathElementAttribute($el, parsedStyle) {
1488
- var path = parsedStyle.path,
1489
- _parsedStyle$defX = parsedStyle.defX,
1490
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1491
- _parsedStyle$defY = parsedStyle.defY,
1492
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1493
- markerStart = parsedStyle.markerStart,
1494
- markerEnd = parsedStyle.markerEnd,
1495
- markerStartOffset = parsedStyle.markerStartOffset,
1496
- markerEndOffset = parsedStyle.markerEndOffset;
1497
- var startOffsetX = 0;
1498
- var startOffsetY = 0;
1499
- var endOffsetX = 0;
1500
- var endOffsetY = 0;
1501
- var rad = 0;
1502
- var x;
1503
- var y;
1504
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1505
- var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
1506
- p1 = _markerStart$parentNo[0],
1507
- p2 = _markerStart$parentNo[1];
1508
- x = p1[0] - p2[0];
1509
- y = p1[1] - p2[1];
1510
- rad = Math.atan2(y, x);
1511
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1512
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1355
+
1356
+ return Math.sqrt(y);
1357
+ };
1358
+
1359
+ /**
1360
+ * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
1361
+ * @module mat4
1362
+ */
1363
+
1364
+ /**
1365
+ * Creates a new identity mat4
1366
+ *
1367
+ * @returns {mat4} a new 4x4 matrix
1368
+ */
1369
+
1370
+ function create() {
1371
+ var out = new ARRAY_TYPE(16);
1372
+
1373
+ if (ARRAY_TYPE != Float32Array) {
1374
+ out[1] = 0;
1375
+ out[2] = 0;
1376
+ out[3] = 0;
1377
+ out[4] = 0;
1378
+ out[6] = 0;
1379
+ out[7] = 0;
1380
+ out[8] = 0;
1381
+ out[9] = 0;
1382
+ out[11] = 0;
1383
+ out[12] = 0;
1384
+ out[13] = 0;
1385
+ out[14] = 0;
1513
1386
  }
1514
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1515
- var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
1516
- _p = _markerEnd$parentNode[0],
1517
- _p2 = _markerEnd$parentNode[1];
1518
- x = _p[0] - _p2[0];
1519
- y = _p[1] - _p2[1];
1520
- rad = Math.atan2(y, x);
1521
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1522
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1387
+
1388
+ out[0] = 1;
1389
+ out[5] = 1;
1390
+ out[10] = 1;
1391
+ out[15] = 1;
1392
+ return out;
1393
+ }
1394
+ /**
1395
+ * Inverts a mat4
1396
+ *
1397
+ * @param {mat4} out the receiving matrix
1398
+ * @param {ReadonlyMat4} a the source matrix
1399
+ * @returns {mat4} out
1400
+ */
1401
+
1402
+ function invert(out, a) {
1403
+ var a00 = a[0],
1404
+ a01 = a[1],
1405
+ a02 = a[2],
1406
+ a03 = a[3];
1407
+ var a10 = a[4],
1408
+ a11 = a[5],
1409
+ a12 = a[6],
1410
+ a13 = a[7];
1411
+ var a20 = a[8],
1412
+ a21 = a[9],
1413
+ a22 = a[10],
1414
+ a23 = a[11];
1415
+ var a30 = a[12],
1416
+ a31 = a[13],
1417
+ a32 = a[14],
1418
+ a33 = a[15];
1419
+ var b00 = a00 * a11 - a01 * a10;
1420
+ var b01 = a00 * a12 - a02 * a10;
1421
+ var b02 = a00 * a13 - a03 * a10;
1422
+ var b03 = a01 * a12 - a02 * a11;
1423
+ var b04 = a01 * a13 - a03 * a11;
1424
+ var b05 = a02 * a13 - a03 * a12;
1425
+ var b06 = a20 * a31 - a21 * a30;
1426
+ var b07 = a20 * a32 - a22 * a30;
1427
+ var b08 = a20 * a33 - a23 * a30;
1428
+ var b09 = a21 * a32 - a22 * a31;
1429
+ var b10 = a21 * a33 - a23 * a31;
1430
+ var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
1431
+
1432
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1433
+
1434
+ if (!det) {
1435
+ return null;
1523
1436
  }
1524
- $el.setAttribute('d', gLite.translatePathToString(path.absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY));
1437
+
1438
+ det = 1.0 / det;
1439
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
1440
+ out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
1441
+ out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
1442
+ out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
1443
+ out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
1444
+ out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
1445
+ out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
1446
+ out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
1447
+ out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
1448
+ out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
1449
+ out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
1450
+ out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
1451
+ out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
1452
+ out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
1453
+ out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
1454
+ out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1455
+ return out;
1525
1456
  }
1526
- function updatePolylineElementAttribute($el, parsedStyle) {
1527
- var points = parsedStyle.points.points,
1528
- _parsedStyle$defX = parsedStyle.defX,
1529
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1530
- _parsedStyle$defY = parsedStyle.defY,
1531
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1532
- markerStart = parsedStyle.markerStart,
1533
- markerStartOffset = parsedStyle.markerStartOffset,
1534
- markerEnd = parsedStyle.markerEnd,
1535
- markerEndOffset = parsedStyle.markerEndOffset;
1536
- var length = points.length;
1537
- if (points && length >= 2) {
1538
- var startOffsetX = 0;
1539
- var startOffsetY = 0;
1540
- var endOffsetX = 0;
1541
- var endOffsetY = 0;
1542
- var rad = 0;
1543
- var x;
1544
- var y;
1545
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1546
- x = points[1][0] - points[0][0];
1547
- y = points[1][1] - points[0][1];
1548
- rad = Math.atan2(y, x);
1549
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1550
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1457
+
1458
+ // isFinite,
1459
+ var isNil = function (value) {
1460
+ /**
1461
+ * isNil(null) => true
1462
+ * isNil() => true
1463
+ */
1464
+ return value === null || value === undefined;
1465
+ };
1466
+
1467
+ var toString = {}.toString;
1468
+ var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
1469
+
1470
+ var isString = (function (str) {
1471
+ return isType(str, 'String');
1472
+ });
1473
+
1474
+ var clamp = function (a, min, max) {
1475
+ if (a < min) {
1476
+ return min;
1551
1477
  }
1552
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1553
- x = points[length - 2][0] - points[length - 1][0];
1554
- y = points[length - 2][1] - points[length - 1][1];
1555
- rad = Math.atan2(y, x);
1556
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1557
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1478
+ else if (a > max) {
1479
+ return max;
1558
1480
  }
1559
- $el.setAttribute('points', points.map(function (point, i) {
1560
- var offsetX = 0;
1561
- var offsetY = 0;
1562
- if (i === 0) {
1563
- offsetX = startOffsetX;
1564
- offsetY = startOffsetY;
1565
- } else if (i === length - 1) {
1566
- offsetX = endOffsetX;
1567
- offsetY = endOffsetY;
1568
- }
1569
- return point[0] - defX + offsetX + "," + (point[1] - defY + offsetY);
1570
- }).join(' '));
1481
+ return a;
1482
+ };
1483
+
1484
+ function _regeneratorRuntime$3() {
1485
+ _regeneratorRuntime$3 = function _regeneratorRuntime() {
1486
+ return exports;
1487
+ };
1488
+ var exports = {},
1489
+ Op = Object.prototype,
1490
+ hasOwn = Op.hasOwnProperty,
1491
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
1492
+ obj[key] = desc.value;
1493
+ },
1494
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
1495
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
1496
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1497
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1498
+ function define(obj, key, value) {
1499
+ return Object.defineProperty(obj, key, {
1500
+ value: value,
1501
+ enumerable: !0,
1502
+ configurable: !0,
1503
+ writable: !0
1504
+ }), obj[key];
1571
1505
  }
1572
- }
1573
- function updateRectElementAttribute($el, parsedStyle) {
1574
- var radius = parsedStyle.radius,
1575
- width = parsedStyle.width,
1576
- height = parsedStyle.height;
1577
- // CSSKeyword: auto
1578
- if (!isFinite(width) || !isFinite(height)) {
1579
- return;
1506
+ try {
1507
+ define({}, "");
1508
+ } catch (err) {
1509
+ define = function define(obj, key, value) {
1510
+ return obj[key] = value;
1511
+ };
1580
1512
  }
1581
- var hasRadius = radius && radius.some(function (r) {
1582
- return r !== 0;
1583
- });
1584
- var d = '';
1585
- if (!hasRadius) {
1586
- d = "M 0,0 l " + width + ",0 l 0," + height + " l" + -width + " 0 z";
1587
- } else {
1588
- var _radius$map = radius.map(function (r) {
1589
- return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
1590
- }),
1591
- tlr = _radius$map[0],
1592
- trr = _radius$map[1],
1593
- brr = _radius$map[2],
1594
- blr = _radius$map[3];
1595
- var signX = width > 0 ? 1 : -1;
1596
- var signY = height > 0 ? 1 : -1;
1597
- // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
1598
- var sweepFlag = signX + signY !== 0 ? 1 : 0;
1599
- d = [["M " + signX * tlr + ",0"], ["l " + (width - signX * (tlr + trr)) + ",0"], ["a " + trr + "," + trr + ",0,0," + sweepFlag + "," + signX * trr + "," + signY * trr], ["l 0," + (height - signY * (trr + brr))], ["a " + brr + "," + brr + ",0,0," + sweepFlag + "," + -signX * brr + "," + signY * brr], ["l " + (signX * (brr + blr) - width) + ",0"], ["a " + blr + "," + blr + ",0,0," + sweepFlag + "," + -signX * blr + "," + -signY * blr], ["l 0," + (signY * (blr + tlr) - height)], ["a " + tlr + "," + tlr + ",0,0," + sweepFlag + "," + signX * tlr + "," + -signY * tlr], ['z']].join(' ');
1513
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1514
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1515
+ generator = Object.create(protoGenerator.prototype),
1516
+ context = new Context(tryLocsList || []);
1517
+ return defineProperty(generator, "_invoke", {
1518
+ value: makeInvokeMethod(innerFn, self, context)
1519
+ }), generator;
1600
1520
  }
1601
- $el.setAttribute('d', d);
1602
- }
1603
- function createSVGElement(type, doc) {
1604
- return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
1605
- }
1606
- function numberToLongString(x) {
1607
- return x.toFixed(6).replace('.000000', '');
1608
- }
1609
- function convertHTML(str) {
1610
- var regex = /[&|<|>|"|']/g;
1611
- return str.replace(regex, function (match) {
1612
- if (match === '&') {
1613
- return '&amp;';
1614
- } else if (match === '<') {
1615
- return '&lt;';
1616
- } else if (match === '>') {
1617
- return '&gt;';
1618
- } else if (match === '"') {
1619
- return '&quot;';
1620
- } else {
1621
- return '&apos;';
1521
+ function tryCatch(fn, obj, arg) {
1522
+ try {
1523
+ return {
1524
+ type: "normal",
1525
+ arg: fn.call(obj, arg)
1526
+ };
1527
+ } catch (err) {
1528
+ return {
1529
+ type: "throw",
1530
+ arg: err
1531
+ };
1622
1532
  }
1533
+ }
1534
+ exports.wrap = wrap;
1535
+ var ContinueSentinel = {};
1536
+ function Generator() {}
1537
+ function GeneratorFunction() {}
1538
+ function GeneratorFunctionPrototype() {}
1539
+ var IteratorPrototype = {};
1540
+ define(IteratorPrototype, iteratorSymbol, function () {
1541
+ return this;
1623
1542
  });
1624
- }
1625
- var SVG_ATTR_MAP = {
1626
- opacity: 'opacity',
1627
- fillStyle: 'fill',
1628
- fill: 'fill',
1629
- fillRule: 'fill-rule',
1630
- fillOpacity: 'fill-opacity',
1631
- strokeStyle: 'stroke',
1632
- strokeOpacity: 'stroke-opacity',
1633
- stroke: 'stroke',
1634
- clipPath: 'clip-path',
1635
- textPath: 'text-path',
1636
- r: 'r',
1637
- rx: 'rx',
1638
- ry: 'ry',
1639
- width: 'width',
1640
- height: 'height',
1641
- lineCap: 'stroke-linecap',
1642
- lineJoin: 'stroke-linejoin',
1643
- lineWidth: 'stroke-width',
1644
- lineDash: 'stroke-dasharray',
1645
- lineDashOffset: 'stroke-dashoffset',
1646
- miterLimit: 'stroke-miterlimit',
1647
- font: 'font',
1648
- fontSize: 'font-size',
1649
- fontStyle: 'font-style',
1650
- fontVariant: 'font-variant',
1651
- fontWeight: 'font-weight',
1652
- fontFamily: 'font-family',
1653
- letterSpacing: 'letter-spacing',
1654
- startArrow: 'marker-start',
1655
- endArrow: 'marker-end',
1656
- class: 'class',
1657
- id: 'id',
1658
- // style: 'style',
1659
- preserveAspectRatio: 'preserveAspectRatio',
1660
- visibility: 'visibility',
1661
- anchor: 'anchor',
1662
- shadowColor: 'flood-color',
1663
- shadowBlur: 'stdDeviation',
1664
- shadowOffsetX: 'dx',
1665
- shadowOffsetY: 'dy',
1666
- filter: 'filter',
1667
- innerHTML: 'innerHTML',
1668
- textAlign: 'text-anchor',
1669
- pointerEvents: 'pointer-events'
1670
- };
1671
- var FORMAT_VALUE_MAP = {
1672
- textAlign: {
1673
- inherit: 'inherit',
1674
- left: 'left',
1675
- start: 'left',
1676
- center: 'middle',
1677
- right: 'end',
1678
- end: 'end'
1543
+ var getProto = Object.getPrototypeOf,
1544
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1545
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1546
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1547
+ function defineIteratorMethods(prototype) {
1548
+ ["next", "throw", "return"].forEach(function (method) {
1549
+ define(prototype, method, function (arg) {
1550
+ return this._invoke(method, arg);
1551
+ });
1552
+ });
1679
1553
  }
1680
- };
1681
- var DEFAULT_VALUE_MAP = {
1682
- textAlign: 'inherit',
1683
- // textBaseline: 'alphabetic',
1684
- // @see https://www.w3.org/TR/SVG/painting.html#LineCaps
1685
- lineCap: 'butt',
1686
- // @see https://www.w3.org/TR/SVG/painting.html#LineJoin
1687
- lineJoin: 'miter',
1688
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
1689
- lineWidth: '1px',
1690
- opacity: '1',
1691
- fillOpacity: '1',
1692
- fillRule: 'nonzero',
1693
- strokeOpacity: '1',
1694
- strokeWidth: '0',
1695
- strokeMiterLimit: '4',
1696
- letterSpacing: '0',
1697
- fontSize: 'inherit',
1698
- fontFamily: 'inherit',
1699
- pointerEvents: 'auto'
1700
- };
1701
- /**
1702
- * G_SVG_PREFIX + nodeName + entity
1703
- *
1704
- * eg. g_svg_circle_345
1705
- */
1706
- var G_SVG_PREFIX = 'g-svg';
1707
- var CLIP_PATH_PREFIX = 'clip-path-';
1708
- var TEXT_PATH_PREFIX = 'text-path-';
1709
- var SVGRendererPlugin = /*#__PURE__*/function () {
1710
- function SVGRendererPlugin(pluginOptions, defElementManager, context) {
1711
- this.pluginOptions = void 0;
1712
- this.defElementManager = void 0;
1713
- this.context = void 0;
1714
- /**
1715
- * <camera>
1716
- */
1717
- this.$camera = void 0;
1718
- /**
1719
- * render at the end of frame
1720
- */
1721
- this.renderQueue = [];
1722
- /**
1723
- * dirty attributes at the end of frame
1724
- */
1725
- this.dirtyAttributes = new WeakMap();
1726
- /**
1727
- * reorder after mounted
1728
- */
1729
- this.pendingReorderQueue = new Set();
1730
- /**
1731
- * <use> elements in <clipPath>, which should be sync with clipPath
1732
- *
1733
- * @example
1734
- * <clipPath transform="matrix(1,0,0,1,-100,-155)" id="clip-path-0-2">
1735
- * <use href="#g_svg_circle_0" transform="matrix(1.477115,0,0,1.477115,150,150)">
1736
- * </use>
1737
- * </clipPath>
1738
- */
1739
- this.clipPathUseMap = new WeakMap();
1740
- this.pluginOptions = pluginOptions;
1741
- this.defElementManager = defElementManager;
1742
- this.context = context;
1554
+ function AsyncIterator(generator, PromiseImpl) {
1555
+ function invoke(method, arg, resolve, reject) {
1556
+ var record = tryCatch(generator[method], generator, arg);
1557
+ if ("throw" !== record.type) {
1558
+ var result = record.arg,
1559
+ value = result.value;
1560
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1561
+ invoke("next", value, resolve, reject);
1562
+ }, function (err) {
1563
+ invoke("throw", err, resolve, reject);
1564
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1565
+ result.value = unwrapped, resolve(result);
1566
+ }, function (error) {
1567
+ return invoke("throw", error, resolve, reject);
1568
+ });
1569
+ }
1570
+ reject(record.arg);
1571
+ }
1572
+ var previousPromise;
1573
+ defineProperty(this, "_invoke", {
1574
+ value: function value(method, arg) {
1575
+ function callInvokeWithMethodAndArg() {
1576
+ return new PromiseImpl(function (resolve, reject) {
1577
+ invoke(method, arg, resolve, reject);
1578
+ });
1579
+ }
1580
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1581
+ }
1582
+ });
1743
1583
  }
1744
- var _proto = SVGRendererPlugin.prototype;
1745
- _proto.apply = function apply(context) {
1746
- var _this = this;
1747
- var renderingService = context.renderingService,
1748
- renderingContext = context.renderingContext;
1749
- this.context = context;
1750
- var canvas = renderingContext.root.ownerDocument.defaultView;
1751
- var document = this.context.config.document;
1752
- var handleMounted = function handleMounted(e) {
1753
- var object = e.target;
1754
- // should remove clipPath already existed in <defs>
1755
- var $useRefs = _this.clipPathUseMap.get(object);
1756
- if ($useRefs) {
1757
- var $def = _this.defElementManager.getDefElement();
1758
- var existed = $def.querySelector("#" + _this.getId(object));
1759
- if (existed) {
1760
- existed.remove();
1584
+ function makeInvokeMethod(innerFn, self, context) {
1585
+ var state = "suspendedStart";
1586
+ return function (method, arg) {
1587
+ if ("executing" === state) throw new Error("Generator is already running");
1588
+ if ("completed" === state) {
1589
+ if ("throw" === method) throw arg;
1590
+ return doneResult();
1591
+ }
1592
+ for (context.method = method, context.arg = arg;;) {
1593
+ var delegate = context.delegate;
1594
+ if (delegate) {
1595
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1596
+ if (delegateResult) {
1597
+ if (delegateResult === ContinueSentinel) continue;
1598
+ return delegateResult;
1599
+ }
1600
+ }
1601
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1602
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
1603
+ context.dispatchException(context.arg);
1604
+ } else "return" === context.method && context.abrupt("return", context.arg);
1605
+ state = "executing";
1606
+ var record = tryCatch(innerFn, self, context);
1607
+ if ("normal" === record.type) {
1608
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1609
+ return {
1610
+ value: record.arg,
1611
+ done: context.done
1612
+ };
1761
1613
  }
1614
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1762
1615
  }
1763
- // create SVG DOM Node
1764
- _this.createSVGDom(document, object, _this.$camera);
1765
1616
  };
1766
- var handleUnmounted = function handleUnmounted(e) {
1767
- var object = e.target;
1768
- _this.defElementManager.clear(object.entity);
1769
- _this.clipPathUseMap.delete(object);
1770
- _this.removeSVGDom(object);
1617
+ }
1618
+ function maybeInvokeDelegate(delegate, context) {
1619
+ var methodName = context.method,
1620
+ method = delegate.iterator[methodName];
1621
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
1622
+ var record = tryCatch(method, delegate.iterator, context.arg);
1623
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1624
+ var info = record.arg;
1625
+ 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);
1626
+ }
1627
+ function pushTryEntry(locs) {
1628
+ var entry = {
1629
+ tryLoc: locs[0]
1771
1630
  };
1772
- var reorderChildren = function reorderChildren(object) {
1773
- var _object$parentNode, _object$parentNode$el;
1774
- var parent = object.parentNode;
1775
- // @ts-ignore
1776
- var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
1777
- var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
1778
- if ($groupEl) {
1779
- _this.reorderChildren(document, $groupEl, children);
1631
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1632
+ }
1633
+ function resetTryEntry(entry) {
1634
+ var record = entry.completion || {};
1635
+ record.type = "normal", delete record.arg, entry.completion = record;
1636
+ }
1637
+ function Context(tryLocsList) {
1638
+ this.tryEntries = [{
1639
+ tryLoc: "root"
1640
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1641
+ }
1642
+ function values(iterable) {
1643
+ if (iterable) {
1644
+ var iteratorMethod = iterable[iteratorSymbol];
1645
+ if (iteratorMethod) return iteratorMethod.call(iterable);
1646
+ if ("function" == typeof iterable.next) return iterable;
1647
+ if (!isNaN(iterable.length)) {
1648
+ var i = -1,
1649
+ next = function next() {
1650
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1651
+ return next.value = undefined, next.done = !0, next;
1652
+ };
1653
+ return next.next = next;
1780
1654
  }
1655
+ }
1656
+ return {
1657
+ next: doneResult
1781
1658
  };
1782
- var handleReparent = function handleReparent(e) {
1783
- var object = e.target;
1784
- reorderChildren(object);
1659
+ }
1660
+ function doneResult() {
1661
+ return {
1662
+ value: undefined,
1663
+ done: !0
1785
1664
  };
1786
- var handleAttributeChanged = function handleAttributeChanged(e) {
1787
- var object = e.target;
1788
- // @see https://github.com/antvis/g/issues/994
1789
- // @ts-ignore
1790
- if (!object.elementSVG) {
1791
- return;
1792
- }
1793
- var attrName = e.attrName;
1794
- var attribtues = _this.dirtyAttributes.get(object);
1795
- if (!attribtues) {
1796
- _this.dirtyAttributes.set(object, []);
1797
- attribtues = _this.dirtyAttributes.get(object);
1798
- }
1799
- attribtues.push(attrName);
1665
+ }
1666
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
1667
+ value: GeneratorFunctionPrototype,
1668
+ configurable: !0
1669
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
1670
+ value: GeneratorFunction,
1671
+ configurable: !0
1672
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1673
+ var ctor = "function" == typeof genFun && genFun.constructor;
1674
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1675
+ }, exports.mark = function (genFun) {
1676
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1677
+ }, exports.awrap = function (arg) {
1678
+ return {
1679
+ __await: arg
1800
1680
  };
1801
- var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
1802
- var _object$elementSVG;
1803
- var object = e.target;
1804
- // @ts-ignore
1805
- var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
1806
- var _object$parsedStyle = object.parsedStyle,
1807
- fill = _object$parsedStyle.fill,
1808
- stroke = _object$parsedStyle.stroke,
1809
- clipPath = _object$parsedStyle.clipPath;
1810
- if (fill && !gLite.isCSSRGB(fill)) {
1811
- _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill', _this);
1812
- }
1813
- if (stroke && !gLite.isCSSRGB(stroke)) {
1814
- _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke', _this);
1815
- }
1816
- if (clipPath) {
1817
- var parentInvert = invert(create(), object.getWorldTransform());
1818
- var clipPathId = CLIP_PATH_PREFIX + clipPath.entity + '-' + object.entity;
1819
- var $def = _this.defElementManager.getDefElement();
1820
- var $existed = $def.querySelector("#" + clipPathId);
1821
- if ($existed) {
1822
- _this.applyTransform($existed, parentInvert);
1823
- }
1681
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1682
+ return this;
1683
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1684
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
1685
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1686
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1687
+ return result.done ? result.value : iter.next();
1688
+ });
1689
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1690
+ return this;
1691
+ }), define(Gp, "toString", function () {
1692
+ return "[object Generator]";
1693
+ }), exports.keys = function (val) {
1694
+ var object = Object(val),
1695
+ keys = [];
1696
+ for (var key in object) keys.push(key);
1697
+ return keys.reverse(), function next() {
1698
+ for (; keys.length;) {
1699
+ var key = keys.pop();
1700
+ if (key in object) return next.value = key, next.done = !1, next;
1824
1701
  }
1702
+ return next.done = !0, next;
1825
1703
  };
1826
- renderingService.hooks.init.tapPromise(SVGRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
1827
- var _this$context$config, background, document, $svg;
1828
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
1829
- while (1) switch (_context.prev = _context.next) {
1830
- case 0:
1831
- _this$context$config = _this.context.config, background = _this$context$config.background, document = _this$context$config.document; // <defs>
1832
- _this.defElementManager.init();
1833
- $svg = _this.context.contextService.getContext();
1834
- if (background) {
1835
- $svg.style.background = background;
1836
- }
1837
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
1838
- $svg.setAttribute('color-interpolation-filters', 'sRGB');
1839
- _this.$camera = createSVGElement('g', document);
1840
- _this.$camera.id = G_SVG_PREFIX + "-camera";
1841
- _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
1842
- $svg.appendChild(_this.$camera);
1843
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
1844
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
1845
- canvas.addEventListener(gLite.ElementEvent.REPARENT, handleReparent);
1846
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
1847
- canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
1848
- case 14:
1849
- case "end":
1850
- return _context.stop();
1851
- }
1852
- }, _callee);
1853
- })));
1854
- renderingService.hooks.destroy.tap(SVGRendererPlugin.tag, function () {
1855
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
1856
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
1857
- canvas.removeEventListener(gLite.ElementEvent.REPARENT, handleReparent);
1858
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
1859
- canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
1860
- });
1861
- renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
1862
- // if (!object.isCulled()) {
1863
- _this.renderQueue.push(object);
1864
- // }
1865
- });
1866
-
1867
- renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
1868
- var doc = _this.context.config.document;
1869
- if (_this.pendingReorderQueue.size) {
1870
- _this.pendingReorderQueue.forEach(function (object) {
1871
- var _object$elementSVG2;
1872
- var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
1873
- var $parentGroupEl =
1874
- // @ts-ignore
1875
- object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
1876
- if ($parentGroupEl) {
1877
- _this.reorderChildren(doc || document, $parentGroupEl, children || []);
1878
- }
1879
- });
1880
- _this.pendingReorderQueue.clear();
1881
- }
1882
- });
1883
- renderingService.hooks.endFrame.tap(SVGRendererPlugin.tag, function () {
1884
- if (renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
1885
- _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
1704
+ }, exports.values = values, Context.prototype = {
1705
+ constructor: Context,
1706
+ reset: function reset(skipTempReset) {
1707
+ 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) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1708
+ },
1709
+ stop: function stop() {
1710
+ this.done = !0;
1711
+ var rootRecord = this.tryEntries[0].completion;
1712
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
1713
+ return this.rval;
1714
+ },
1715
+ dispatchException: function dispatchException(exception) {
1716
+ if (this.done) throw exception;
1717
+ var context = this;
1718
+ function handle(loc, caught) {
1719
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1886
1720
  }
1887
- _this.renderQueue.forEach(function (object) {
1888
- var _object$elementSVG3, _object$elementSVG4;
1889
- // @ts-ignore
1890
- var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el;
1891
- // @ts-ignore
1892
- var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
1893
- if ($el && $groupEl) {
1894
- // apply local RTS transformation to <group> wrapper
1895
- // account for anchor
1896
- var localTransform = object.getLocalTransform();
1897
- _this.applyTransform($groupEl, localTransform);
1898
- // clipped shapes should also be informed
1899
- var $useRefs = _this.clipPathUseMap.get(object);
1900
- if ($useRefs && $useRefs.length) {
1901
- $useRefs.forEach(function ($use) {
1902
- // <clipPath transform="matrix()"><circle /></clipPath>
1903
- _this.applyTransform($use, object.getWorldTransform());
1904
- // const parentInvert = mat4.invert(
1905
- // mat4.create(),
1906
- // (object as DisplayObject).getWorldTransform(),
1907
- // );
1908
- // this.applyTransform($clipPath, parentInvert);
1909
- });
1721
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1722
+ var entry = this.tryEntries[i],
1723
+ record = entry.completion;
1724
+ if ("root" === entry.tryLoc) return handle("end");
1725
+ if (entry.tryLoc <= this.prev) {
1726
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1727
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1728
+ if (hasCatch && hasFinally) {
1729
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1730
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1731
+ } else if (hasCatch) {
1732
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1733
+ } else {
1734
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1735
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1910
1736
  }
1911
- // finish rendering, clear dirty flag
1912
- object.renderable.dirty = false;
1913
1737
  }
1914
- // update dirty attributes
1915
- var attributes = _this.dirtyAttributes.get(object);
1916
- if (attributes) {
1917
- attributes.forEach(function (attrName) {
1918
- if (attrName === 'zIndex') {
1919
- reorderChildren(object);
1920
- } else if (attrName === 'increasedLineWidthForHitTesting') {
1921
- _this.createOrUpdateHitArea(object, $el, $groupEl);
1922
- }
1923
- _this.updateAttribute(object, [attrName]);
1924
- });
1925
- _this.dirtyAttributes.delete(object);
1738
+ }
1739
+ },
1740
+ abrupt: function abrupt(type, arg) {
1741
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1742
+ var entry = this.tryEntries[i];
1743
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1744
+ var finallyEntry = entry;
1745
+ break;
1926
1746
  }
1927
- });
1928
- _this.renderQueue = [];
1929
- });
1930
- };
1931
- _proto.getId = function getId(object) {
1932
- return G_SVG_PREFIX + "-" + object.entity;
1933
- };
1934
- _proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
1935
- // need to reorder parent's children
1936
- children.sort(function (a, b) {
1937
- return a.sortable.renderOrder - b.sortable.renderOrder;
1938
- });
1939
- if (children.length) {
1940
- // create empty fragment
1941
- var fragment = (doc || document).createDocumentFragment();
1942
- children.forEach(function (child) {
1943
- if (child.isConnected) {
1944
- // @ts-ignore
1945
- var $el = child.elementSVG.$groupEl;
1946
- if ($el) {
1947
- fragment.appendChild($el);
1747
+ }
1748
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1749
+ var record = finallyEntry ? finallyEntry.completion : {};
1750
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1751
+ },
1752
+ complete: function complete(record, afterLoc) {
1753
+ if ("throw" === record.type) throw record.arg;
1754
+ 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;
1755
+ },
1756
+ finish: function finish(finallyLoc) {
1757
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1758
+ var entry = this.tryEntries[i];
1759
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1760
+ }
1761
+ },
1762
+ catch: function _catch(tryLoc) {
1763
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1764
+ var entry = this.tryEntries[i];
1765
+ if (entry.tryLoc === tryLoc) {
1766
+ var record = entry.completion;
1767
+ if ("throw" === record.type) {
1768
+ var thrown = record.arg;
1769
+ resetTryEntry(entry);
1948
1770
  }
1771
+ return thrown;
1949
1772
  }
1950
- });
1951
- $groupEl.appendChild(fragment);
1773
+ }
1774
+ throw new Error("illegal catch attempt");
1775
+ },
1776
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1777
+ return this.delegate = {
1778
+ iterator: values(iterable),
1779
+ resultName: resultName,
1780
+ nextLoc: nextLoc
1781
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1952
1782
  }
1783
+ }, exports;
1784
+ }
1785
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
1786
+ try {
1787
+ var info = gen[key](arg);
1788
+ var value = info.value;
1789
+ } catch (error) {
1790
+ reject(error);
1791
+ return;
1792
+ }
1793
+ if (info.done) {
1794
+ resolve(value);
1795
+ } else {
1796
+ Promise.resolve(value).then(_next, _throw);
1797
+ }
1798
+ }
1799
+ function _asyncToGenerator$3(fn) {
1800
+ return function () {
1801
+ var self = this,
1802
+ args = arguments;
1803
+ return new Promise(function (resolve, reject) {
1804
+ var gen = fn.apply(self, args);
1805
+ function _next(value) {
1806
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
1807
+ }
1808
+ function _throw(err) {
1809
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
1810
+ }
1811
+ _next(undefined);
1812
+ });
1953
1813
  };
1954
- _proto.applyTransform = function applyTransform($el, rts) {
1955
- // use proper precision avoiding too long string in `transform`
1956
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
1957
- $el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
1958
- };
1959
- _proto.applyAttributes = function applyAttributes(object) {
1960
- // @ts-ignore
1961
- var elementSVG = object.elementSVG;
1962
- var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
1963
- var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
1964
- if ($el && $groupEl) {
1965
- var nodeName = object.nodeName,
1966
- attributes = object.attributes;
1967
- $el.setAttribute('fill', 'none');
1968
- if (nodeName === gLite.Shape.IMAGE) {
1969
- $el.setAttribute('preserveAspectRatio', 'none');
1814
+ }
1815
+ function _extends() {
1816
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
1817
+ for (var i = 1; i < arguments.length; i++) {
1818
+ var source = arguments[i];
1819
+ for (var key in source) {
1820
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1821
+ target[key] = source[key];
1822
+ }
1970
1823
  }
1971
- // apply attributes
1972
- this.updateAttribute(object, Object.keys(attributes));
1973
1824
  }
1825
+ return target;
1974
1826
  };
1975
- _proto.updateAttribute = function updateAttribute(object, attributes) {
1976
- var _this2 = this;
1977
- var document = this.context.config.document;
1978
- // @ts-ignore
1979
- var _object$elementSVG5 = object.elementSVG,
1980
- $el = _object$elementSVG5.$el,
1981
- $groupEl = _object$elementSVG5.$groupEl,
1982
- $hitTestingEl = _object$elementSVG5.$hitTestingEl;
1983
- var parsedStyle = object.parsedStyle,
1984
- computedStyle = object.computedStyle;
1985
- var shouldUpdateElementAttribute = attributes.some(function (name) {
1986
- return (
1987
- // @ts-ignore
1988
- _this2.context.SVGElementLifeCycleContribution.shouldUpdateElementAttribute(object, name)
1989
- );
1990
- });
1991
- // need re-generate path
1992
- if (shouldUpdateElementAttribute && $el) {
1993
- [$el, $hitTestingEl].forEach(function ($el) {
1994
- if ($el) {
1995
- // @ts-ignore
1996
- _this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el);
1997
- if (object.nodeName !== gLite.Shape.TEXT) {
1998
- _this2.updateAnchorWithTransform(object);
1999
- }
2000
- }
2001
- });
2002
- }
2003
- // update common attributes
2004
- attributes.forEach(function (name) {
2005
- var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
2006
- var usedName = SVG_ATTR_MAP[name];
2007
- var computedValue = gLite.runtime.enableCSSParsing ? computedStyle[name] : parsedStyle[name];
2008
- var computedValueStr = computedValue && computedValue.toString();
2009
- var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[computedValueStr]) || computedValueStr;
2010
- var usedValue = parsedStyle[name];
2011
- var inherited = gLite.runtime.enableCSSParsing && !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
2012
- if (!usedName) {
2013
- return;
2014
- }
2015
- // <foreignObject>
2016
- if (object.nodeName === gLite.Shape.HTML) {
2017
- if (name === 'lineWidth') {
2018
- $el.style['border-width'] = (usedValue || 0) + "px";
2019
- } else if (name === 'lineDash') {
2020
- $el.style['border-style'] = 'dashed';
2021
- }
2022
- }
2023
- if (name === 'fill') {
2024
- if (object.nodeName === gLite.Shape.HTML) {
2025
- $el.style.background = usedValue.toString();
2026
- } else {
2027
- _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
2028
- }
2029
- } else if (name === 'stroke') {
2030
- if (object.nodeName === gLite.Shape.HTML) {
2031
- $el.style['border-color'] = usedValue.toString();
2032
- $el.style['border-style'] = 'solid';
2033
- } else {
2034
- _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
2035
- }
2036
- } else if (inherited && usedName) {
2037
- // use computed value
2038
- // update `visibility` on <group>
2039
- if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
2040
- $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, formattedValueStr);
2041
- } else {
2042
- $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.removeAttribute(usedName);
2043
- }
2044
- } else if (name === 'clipPath') {
2045
- _this2.createOrUpdateClipOrTextPath(document, usedValue, object);
2046
- } else if (name === 'textPath') {
2047
- _this2.createOrUpdateClipOrTextPath(document, usedValue, object, true);
2048
- } else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
2049
- _this2.defElementManager.createOrUpdateShadow(object, $el, name);
2050
- } else if (name === 'filter') {
2051
- _this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
2052
- } else if (name === 'innerHTML') {
2053
- _this2.createOrUpdateInnerHTML(document, $el, usedValue);
2054
- } else if (name === 'anchor') {
2055
- // text' anchor is controlled by `textAnchor` property
2056
- if (object.nodeName !== gLite.Shape.TEXT) {
2057
- _this2.updateAnchorWithTransform(object);
2058
- }
2059
- } else {
2060
- if (computedValue) {
2061
- // use computed value so that we can use cascaded effect in SVG
2062
- // ignore 'unset' and default value
2063
- [$el, $hitTestingEl].forEach(function ($el) {
2064
- if ($el && usedName) {
2065
- if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
2066
- $el.setAttribute(usedName, formattedValueStr);
2067
- } else {
2068
- $el.removeAttribute(usedName);
2069
- }
2070
- }
2071
- });
2072
- }
2073
- }
2074
- });
1827
+ return _extends.apply(this, arguments);
1828
+ }
1829
+ function _inheritsLoose$3(subClass, superClass) {
1830
+ subClass.prototype = Object.create(superClass.prototype);
1831
+ subClass.prototype.constructor = subClass;
1832
+ _setPrototypeOf$3(subClass, superClass);
1833
+ }
1834
+ function _setPrototypeOf$3(o, p) {
1835
+ _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
1836
+ o.__proto__ = p;
1837
+ return o;
2075
1838
  };
2076
- _proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
2077
- if (noWrapWithGroup === void 0) {
2078
- noWrapWithGroup = false;
1839
+ return _setPrototypeOf$3(o, p);
1840
+ }
1841
+ var ElementSVG = function ElementSVG() {
1842
+ /**
1843
+ * basic element, eg. <circle>|<ellipse>
1844
+ */
1845
+ this.$el = void 0;
1846
+ /**
1847
+ * group wrapper for basic element, eg. <g><circle /></g>.
1848
+ * if current element is <g>, same as `$el`
1849
+ */
1850
+ this.$groupEl = void 0;
1851
+ /**
1852
+ * hitArea:
1853
+ * $groupEl -> $el
1854
+ * -> $hitTestingEl
1855
+ */
1856
+ this.$hitTestingEl = void 0;
1857
+ };
1858
+ ElementSVG.tag = 'c-svg-element';
1859
+ function updateImageElementAttribute($el, parsedStyle) {
1860
+ var _parsedStyle$img = parsedStyle.img,
1861
+ img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
1862
+ width = parsedStyle.width,
1863
+ height = parsedStyle.height;
1864
+ $el.setAttribute('x', '0');
1865
+ $el.setAttribute('y', '0');
1866
+ if (isString(img)) {
1867
+ $el.setAttribute('href', img);
1868
+ } else if (img instanceof Image) {
1869
+ if (!width) {
1870
+ $el.setAttribute('width', "" + img.width);
1871
+ // TODO: set renderable.boundsDirty
1872
+ // this.attr('width', img.width);
2079
1873
  }
2080
- // create svg element
1874
+
1875
+ if (!height) {
1876
+ $el.setAttribute('height', "" + img.height);
1877
+ // this.attr('height', img.height);
1878
+ }
1879
+
1880
+ $el.setAttribute('href', img.src);
1881
+ } else if (
1882
+ // @ts-ignore
1883
+ img instanceof HTMLElement && isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
1884
+ $el.setAttribute('href', img.toDataURL());
2081
1885
  // @ts-ignore
2082
- object.elementSVG = new ElementSVG();
1886
+ } else if (img instanceof ImageData) {
1887
+ var canvas = document.createElement('canvas');
2083
1888
  // @ts-ignore
2084
- var svgElement = object.elementSVG;
2085
- // use <group> as default, eg. CustomElement
2086
- var $el =
1889
+ canvas.setAttribute('width', "" + img.width);
2087
1890
  // @ts-ignore
2088
- this.context.SVGElementLifeCycleContribution.createElement(object);
2089
- if ($el) {
2090
- var _object$parentNode$el2;
2091
- var $groupEl;
2092
- // save $el on parsedStyle, which will be returned in getDomElement()
2093
- if (object.nodeName === gLite.Shape.HTML) {
2094
- object.parsedStyle.$el = $el;
2095
- }
2096
- if (this.pluginOptions.outputSVGElementId) {
2097
- $el.id = this.getId(object);
2098
- }
2099
- if (this.pluginOptions.outputSVGElementName && object.name) {
2100
- $el.setAttribute('name', object.name);
2101
- }
2102
- if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
2103
- $groupEl = createSVGElement('g', document);
2104
- $groupEl.id = $el.id + '-g';
2105
- $groupEl.appendChild($el);
2106
- } else {
2107
- $groupEl = $el;
2108
- }
2109
- svgElement.$el = $el;
2110
- svgElement.$groupEl = $groupEl;
2111
- // apply attributes at first time
2112
- this.applyAttributes(object);
2113
- // create hitArea if necessary
2114
- this.createOrUpdateHitArea(object, $el, $groupEl);
2115
- var $parentGroupEl = root ||
2116
- // @ts-ignore
2117
- object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl);
2118
- if ($parentGroupEl) {
2119
- $parentGroupEl.appendChild($groupEl);
2120
- // need reorder children later
2121
- this.pendingReorderQueue.add(object.parentNode);
1891
+ canvas.setAttribute('height', "" + img.height);
1892
+ var context = canvas.getContext('2d');
1893
+ if (context) {
1894
+ context.putImageData(img, 0, 0);
1895
+ if (!width) {
1896
+ // @ts-ignore
1897
+ $el.setAttribute('width', "" + img.width);
1898
+ // this.attr('width', img.width);
2122
1899
  }
2123
- }
2124
- };
2125
- _proto.removeSVGDom = function removeSVGDom(object) {
2126
- var _object$elementSVG6;
2127
- // @ts-ignore
2128
- var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
2129
- if ($groupEl && $groupEl.parentNode) {
2130
- $groupEl.parentNode.removeChild($groupEl);
2131
- // @ts-ignore
2132
- this.context.SVGElementLifeCycleContribution.destroyElement(object, $groupEl);
2133
- // object.entity.removeComponent(ElementSVG, true);
2134
- }
2135
- };
2136
1900
 
2137
- _proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
2138
- // @ts-ignore
2139
- var svgElement = object.elementSVG;
2140
- var $hitTestingEl = svgElement.$hitTestingEl;
2141
- var increasedLineWidthForHitTesting = object.parsedStyle.increasedLineWidthForHitTesting;
2142
- // account for hitArea
2143
- if (increasedLineWidthForHitTesting) {
2144
- if (!$hitTestingEl) {
2145
- $hitTestingEl = $el.cloneNode();
2146
- if (this.pluginOptions.outputSVGElementId) {
2147
- // use the entity suffix, so that `g-plugin-svg-picker` can extract
2148
- $hitTestingEl.id = G_SVG_PREFIX + "-" + object.nodeName + "-hittesting-" + object.entity;
2149
- }
2150
- // clear attributes like `filter` `font-size`
2151
- ['filter'].forEach(function (attribute) {
2152
- $hitTestingEl.removeAttribute(attribute);
2153
- });
2154
- // hitArea should be 'transparent' but not 'none'
2155
- var hasFill = $el.getAttribute('fill') !== 'none';
2156
- $hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
2157
- $hitTestingEl.setAttribute('stroke', 'transparent');
2158
- $groupEl.appendChild($hitTestingEl);
2159
- svgElement.$hitTestingEl = $hitTestingEl;
2160
- }
2161
- // increase interactive line width
2162
- $hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
2163
- } else {
2164
- if ($hitTestingEl) {
2165
- $groupEl.removeChild($hitTestingEl);
2166
- svgElement.$hitTestingEl = null;
1901
+ if (!height) {
1902
+ // @ts-ignore
1903
+ $el.setAttribute('height', "" + img.height);
1904
+ // this.attr('height', img.height);
2167
1905
  }
1906
+
1907
+ $el.setAttribute('href', canvas.toDataURL());
2168
1908
  }
2169
- };
2170
- _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
2171
- var $div = (doc || document).createElement('div');
2172
- if (typeof usedValue === 'string') {
2173
- $div.innerHTML = usedValue;
2174
- } else {
2175
- $div.appendChild(usedValue);
2176
- }
2177
- $el.innerHTML = '';
2178
- $el.appendChild($div);
2179
- };
2180
- _proto.createOrUpdateClipOrTextPath = function createOrUpdateClipOrTextPath(document, clipPath, object, isTextPath) {
2181
- if (isTextPath === void 0) {
2182
- isTextPath = false;
2183
- }
2184
- // @ts-ignore
2185
- var $groupEl = object.elementSVG.$groupEl;
2186
- var PREFIX = isTextPath ? TEXT_PATH_PREFIX : CLIP_PATH_PREFIX;
2187
- var attributeNameCamel = isTextPath ? 'g' : 'clipPath';
2188
- var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
2189
- if (clipPath) {
2190
- var clipPathId = PREFIX + clipPath.entity + '-' + object.entity;
2191
- var $def = this.defElementManager.getDefElement();
2192
- var existed = $def.querySelector("#" + clipPathId);
2193
- if (!existed) {
2194
- var $clipPath;
2195
- if (isTextPath) {
2196
- // use <path> directly instead of wrapping with <g>
2197
- this.createSVGDom(document, clipPath, null, true);
2198
- // @ts-ignore
2199
- $clipPath = clipPath.elementSVG.$el;
2200
- } else {
2201
- // the clipPath is allowed to be detached from canvas
2202
- if (!clipPath.isConnected) {
2203
- var $existedClipPath = $def.querySelector("#" + this.getId(clipPath));
2204
- if (!$existedClipPath) {
2205
- this.createSVGDom(document, clipPath, $def, true);
2206
- }
2207
- }
2208
- // create <clipPath> dom node
2209
- $clipPath = createSVGElement(attributeNameCamel, document);
2210
- var $use = createSVGElement('use', document);
2211
- // @ts-ignore
2212
- $use.setAttribute('href', "#" + clipPath.elementSVG.$el.id);
2213
- $clipPath.appendChild($use);
2214
- var $useRefs = this.clipPathUseMap.get(clipPath);
2215
- if (!$useRefs) {
2216
- this.clipPathUseMap.set(clipPath, []);
2217
- $useRefs = this.clipPathUseMap.get(clipPath);
2218
- }
2219
- $useRefs.push($use);
2220
- // <clipPath transform="matrix()"><circle /></clipPath>
2221
- this.applyTransform($use, clipPath.getWorldTransform());
2222
- var parentInvert = invert(create(), object.getWorldTransform());
2223
- this.applyTransform($clipPath, parentInvert);
2224
- }
2225
- $clipPath.id = clipPathId;
2226
- // append it to <defs>
2227
- $def.appendChild($clipPath);
2228
- }
2229
- // apply attributes
2230
- this.applyAttributes(clipPath);
2231
- if (!isTextPath) {
2232
- // apply clipPath to $group
2233
- // @see https://github.com/antvis/g/issues/961
2234
- $groupEl.setAttribute(attributeNameHyphen, "url(#" + clipPathId + ")");
2235
- }
2236
- } else {
2237
- if (!isTextPath) {
2238
- // remove clip path
2239
- $groupEl.removeAttribute(attributeNameHyphen);
2240
- }
2241
- }
2242
- }
2243
- /**
2244
- * the origin is bounding box's top left corner
2245
- */;
2246
- _proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
2247
- var _object$elementSVG7, _object$elementSVG8;
2248
- var bounds = object.getGeometryBounds();
2249
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
2250
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
2251
- var _ref2 = object.parsedStyle || {},
2252
- anchor = _ref2.anchor;
2253
- // @ts-ignore
2254
- [(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
2255
- if ($el) {
2256
- var tx = -(anchor[0] * width);
2257
- var ty = -(anchor[1] * height);
2258
- if (tx !== 0 || ty !== 0) {
2259
- // apply anchor to element's `transform` property
2260
- $el.setAttribute('transform',
2261
- // can't use percent unit like translate(-50%, -50%)
2262
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
2263
- "translate(" + tx + "," + ty + ")");
2264
- }
2265
- if (object.nodeName === gLite.Shape.CIRCLE || object.nodeName === gLite.Shape.ELLIPSE) {
2266
- $el.setAttribute('cx', "" + width / 2);
2267
- $el.setAttribute('cy', "" + height / 2);
2268
- }
2269
- }
2270
- });
2271
- };
2272
- return SVGRendererPlugin;
2273
- }();
2274
- SVGRendererPlugin.tag = 'SVGRenderer';
2275
-
2276
- // @see https://github.com/plouc/nivo/issues/164
2277
- var BASELINE_MAP = {
2278
- top: 'hanging',
2279
- middle: 'central',
2280
- bottom: 'text-after-edge',
2281
- alphabetic: 'alphabetic',
2282
- ideographic: 'ideographic',
2283
- hanging: 'hanging'
2284
- };
2285
- function updateTextElementAttribute($el, parsedStyle, text) {
2286
- var lineWidth = parsedStyle.lineWidth,
2287
- dx = parsedStyle.dx,
2288
- dy = parsedStyle.dy,
2289
- textPath = parsedStyle.textPath,
2290
- _parsedStyle$textPath = parsedStyle.textPathSide,
2291
- textPathSide = _parsedStyle$textPath === void 0 ? 'left' : _parsedStyle$textPath,
2292
- _parsedStyle$textPath2 = parsedStyle.textPathStartOffset,
2293
- textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
2294
- _parsedStyle$textDeco = parsedStyle.textDecorationLine,
2295
- textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
2296
- _parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
2297
- textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
2298
- _parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
2299
- textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3,
2300
- metrics = parsedStyle.metrics;
2301
- var textBaseline = parsedStyle.textBaseline;
2302
- if (!gLite.runtime.enableCSSParsing && textBaseline === 'alphabetic') {
2303
- textBaseline = 'bottom';
2304
1909
  }
2305
- $el.setAttribute('dominant-baseline', BASELINE_MAP[textBaseline]);
2306
- $el.setAttribute('paint-order', 'stroke');
2307
- var lines = metrics.lines,
2308
- lineHeight = metrics.lineHeight,
2309
- height = metrics.height;
2310
- var lineNum = lines.length;
2311
- var styleCSSText = '';
2312
- if (dx !== 0 || dy !== 0) {
2313
- styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
1910
+ }
1911
+ function updateLineElementAttribute($el, parsedStyle) {
1912
+ var x1 = parsedStyle.x1,
1913
+ y1 = parsedStyle.y1,
1914
+ x2 = parsedStyle.x2,
1915
+ y2 = parsedStyle.y2,
1916
+ _parsedStyle$defX = parsedStyle.defX,
1917
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1918
+ _parsedStyle$defY = parsedStyle.defY,
1919
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1920
+ markerStart = parsedStyle.markerStart,
1921
+ markerEnd = parsedStyle.markerEnd,
1922
+ markerStartOffset = parsedStyle.markerStartOffset,
1923
+ markerEndOffset = parsedStyle.markerEndOffset;
1924
+ var startOffsetX = 0;
1925
+ var startOffsetY = 0;
1926
+ var endOffsetX = 0;
1927
+ var endOffsetY = 0;
1928
+ var rad = 0;
1929
+ var x;
1930
+ var y;
1931
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1932
+ x = x2 - x1;
1933
+ y = y2 - y1;
1934
+ rad = Math.atan2(y, x);
1935
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1936
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2314
1937
  }
2315
- if (textDecorationLine && textDecorationLine !== 'none') {
2316
- // use CSS text-decoration since the implementation in SVG is not good enough
2317
- styleCSSText += "text-decoration:" + textDecorationLine + " " + textDecorationStyle + " " + textDecorationColor + ";";
1938
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1939
+ x = x1 - x2;
1940
+ y = y1 - y2;
1941
+ rad = Math.atan2(y, x);
1942
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1943
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2318
1944
  }
2319
- if (styleCSSText) {
2320
- $el.setAttribute('style', styleCSSText);
1945
+ // @see https://github.com/antvis/g/issues/1038
1946
+ $el.setAttribute('x1', "" + (x1 - defX + startOffsetX));
1947
+ $el.setAttribute('y1', "" + (y1 - defY + startOffsetY));
1948
+ $el.setAttribute('x2', "" + (x2 - defX + endOffsetX));
1949
+ $el.setAttribute('y2', "" + (y2 - defY + endOffsetY));
1950
+ }
1951
+ function updatePathElementAttribute($el, parsedStyle) {
1952
+ var path = parsedStyle.path,
1953
+ _parsedStyle$defX = parsedStyle.defX,
1954
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1955
+ _parsedStyle$defY = parsedStyle.defY,
1956
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1957
+ markerStart = parsedStyle.markerStart,
1958
+ markerEnd = parsedStyle.markerEnd,
1959
+ markerStartOffset = parsedStyle.markerStartOffset,
1960
+ markerEndOffset = parsedStyle.markerEndOffset;
1961
+ var startOffsetX = 0;
1962
+ var startOffsetY = 0;
1963
+ var endOffsetX = 0;
1964
+ var endOffsetY = 0;
1965
+ var rad = 0;
1966
+ var x;
1967
+ var y;
1968
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1969
+ var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
1970
+ p1 = _markerStart$parentNo[0],
1971
+ p2 = _markerStart$parentNo[1];
1972
+ x = p1[0] - p2[0];
1973
+ y = p1[1] - p2[1];
1974
+ rad = Math.atan2(y, x);
1975
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1976
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2321
1977
  }
2322
- if (lineNum === 1) {
2323
- var textContent = convertHTML(lines[0]);
2324
- $el.setAttribute('dx', "" + lineWidth / 2);
2325
- // Since `text-after-edge` is not a standard property value, we use `dy` instead.
2326
- if (textBaseline === 'bottom' || textBaseline === 'top') {
2327
- $el.setAttribute('dominant-baseline', 'middle');
2328
- $el.setAttribute('dy', textBaseline === 'bottom' ? "-0.5em" : '0.5em');
2329
- }
2330
- // <textPath> only support one line
2331
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
2332
- if (textPath) {
2333
- // clear existed text content first
2334
- $el.innerHTML = '';
2335
- // append <textPath href="#MyPath">text</textPath>
2336
- var $textPath = createSVGElement('textPath', $el.ownerDocument);
2337
- $textPath.setAttribute('href', "#" + (TEXT_PATH_PREFIX + textPath.entity));
2338
- if (textPathSide !== 'left') {
2339
- $textPath.setAttribute('side', textPathSide);
2340
- }
2341
- if (textPathStartOffset !== 0) {
2342
- $textPath.setAttribute('startOffset', "" + textPathStartOffset);
2343
- }
2344
- $textPath.innerHTML = textContent;
2345
- $el.appendChild($textPath);
2346
- } else {
2347
- $el.innerHTML = textContent;
2348
- }
2349
- } else {
2350
- $el.innerHTML = lines.map(function (line, i) {
2351
- var dx = lineWidth / 2;
2352
- var dy = 0;
2353
- if (i === 0) {
2354
- // TODO: handle other textBaseline values
2355
- if (textBaseline === 'middle') {
2356
- dy = lineHeight / 2 - height / 2;
2357
- } else if (textBaseline === 'top' || textBaseline === 'hanging') {
2358
- dy = 0;
2359
- } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
2360
- dy = -lineHeight * (lineNum - 1);
2361
- }
2362
- } else {
2363
- dy = lineHeight;
2364
- }
2365
- return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
2366
- }).join('');
1978
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1979
+ var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
1980
+ _p = _markerEnd$parentNode[0],
1981
+ _p2 = _markerEnd$parentNode[1];
1982
+ x = _p[0] - _p2[0];
1983
+ y = _p[1] - _p2[1];
1984
+ rad = Math.atan2(y, x);
1985
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1986
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2367
1987
  }
1988
+ $el.setAttribute('d', gLite.translatePathToString(path.absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY));
2368
1989
  }
2369
- var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
2370
- var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[gLite.Shape.RECT] = 'path', _SHAPE2TAGS[gLite.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[gLite.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[gLite.Shape.IMAGE] = 'image', _SHAPE2TAGS[gLite.Shape.GROUP] = 'g', _SHAPE2TAGS[gLite.Shape.LINE] = 'line', _SHAPE2TAGS[gLite.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[gLite.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[gLite.Shape.TEXT] = 'text', _SHAPE2TAGS[gLite.Shape.PATH] = 'path', _SHAPE2TAGS[gLite.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
2371
- var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[gLite.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[gLite.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[gLite.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[gLite.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[gLite.Shape.LINE] = ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYLINE] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYGON] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.PATH] = ['path', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'maxLines', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'textOverflow', 'textPath', 'textPathSide', 'textPathStartOffset', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle',
2372
- // 'whiteSpace',
2373
- 'dx', 'dy'], _SHAPE_UPDATE_DEPS);
2374
- var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
2375
- function DefaultElementLifeCycleContribution(context) {
2376
- this.context = void 0;
2377
- this.context = context;
2378
- }
2379
- var _proto = DefaultElementLifeCycleContribution.prototype;
2380
- _proto.createElement = function createElement(object) {
2381
- var doc = this.context.config.document;
2382
- var type = SHAPE2TAGS[object.nodeName] || 'g';
2383
- return createSVGElement(type, doc || document);
2384
- };
2385
- _proto.destroyElement = function destroyElement(object, $el) {};
2386
- _proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
2387
- var nodeName = object.nodeName;
2388
- return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
2389
- };
2390
- _proto.updateElementAttribute = function updateElementAttribute(object) {
2391
- // @ts-ignore
2392
- var $el = object.elementSVG.$el;
2393
- var nodeName = object.nodeName,
2394
- parsedStyle = object.parsedStyle;
2395
- switch (nodeName) {
2396
- case gLite.Shape.IMAGE:
2397
- {
2398
- updateImageElementAttribute($el, parsedStyle);
2399
- break;
2400
- }
2401
- case gLite.Shape.RECT:
2402
- {
2403
- updateRectElementAttribute($el, parsedStyle);
2404
- break;
2405
- }
2406
- case gLite.Shape.LINE:
2407
- {
2408
- updateLineElementAttribute($el, parsedStyle);
2409
- break;
2410
- }
2411
- case gLite.Shape.POLYGON:
2412
- case gLite.Shape.POLYLINE:
2413
- {
2414
- updatePolylineElementAttribute($el, parsedStyle);
2415
- break;
2416
- }
2417
- case gLite.Shape.PATH:
2418
- {
2419
- updatePathElementAttribute($el, parsedStyle);
2420
- break;
2421
- }
2422
- case gLite.Shape.TEXT:
2423
- {
2424
- updateTextElementAttribute($el, parsedStyle);
2425
- break;
2426
- }
1990
+ function updatePolylineElementAttribute($el, parsedStyle) {
1991
+ var points = parsedStyle.points.points,
1992
+ _parsedStyle$defX = parsedStyle.defX,
1993
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1994
+ _parsedStyle$defY = parsedStyle.defY,
1995
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1996
+ markerStart = parsedStyle.markerStart,
1997
+ markerStartOffset = parsedStyle.markerStartOffset,
1998
+ markerEnd = parsedStyle.markerEnd,
1999
+ markerEndOffset = parsedStyle.markerEndOffset;
2000
+ var length = points.length;
2001
+ if (points && length >= 2) {
2002
+ var startOffsetX = 0;
2003
+ var startOffsetY = 0;
2004
+ var endOffsetX = 0;
2005
+ var endOffsetY = 0;
2006
+ var rad = 0;
2007
+ var x;
2008
+ var y;
2009
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
2010
+ x = points[1][0] - points[0][0];
2011
+ y = points[1][1] - points[0][1];
2012
+ rad = Math.atan2(y, x);
2013
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
2014
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
2427
2015
  }
2428
- };
2429
- return DefaultElementLifeCycleContribution;
2430
- }();
2431
- var FILTER_PREFIX = 'g-filter-';
2432
- /**
2433
- * use SVG filters, eg. blur, brightness, contrast...
2434
- * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2435
- */
2436
- function createOrUpdateFilter(document, $def, object, $el, filters) {
2437
- // eg. filter="url(#f1) url(#f2)"
2438
- var filterName = FILTER_PREFIX + object.entity;
2439
- var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
2440
- if ($existedFilters.length) {
2441
- $existedFilters.forEach(function ($filter) {
2442
- $def.removeChild($filter);
2443
- });
2016
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
2017
+ x = points[length - 2][0] - points[length - 1][0];
2018
+ y = points[length - 2][1] - points[length - 1][1];
2019
+ rad = Math.atan2(y, x);
2020
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
2021
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
2022
+ }
2023
+ $el.setAttribute('points', points.map(function (point, i) {
2024
+ var offsetX = 0;
2025
+ var offsetY = 0;
2026
+ if (i === 0) {
2027
+ offsetX = startOffsetX;
2028
+ offsetY = startOffsetY;
2029
+ } else if (i === length - 1) {
2030
+ offsetX = endOffsetX;
2031
+ offsetY = endOffsetY;
2032
+ }
2033
+ return point[0] - defX + offsetX + "," + (point[1] - defY + offsetY);
2034
+ }).join(' '));
2444
2035
  }
2445
- if (filters.length === 0) {
2446
- // 'none'
2447
- $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2036
+ }
2037
+ function updateRectElementAttribute($el, parsedStyle) {
2038
+ var radius = parsedStyle.radius,
2039
+ width = parsedStyle.width,
2040
+ height = parsedStyle.height;
2041
+ // CSSKeyword: auto
2042
+ if (!isFinite(width) || !isFinite(height)) {
2043
+ return;
2044
+ }
2045
+ var hasRadius = radius && radius.some(function (r) {
2046
+ return r !== 0;
2047
+ });
2048
+ var d = '';
2049
+ if (!hasRadius) {
2050
+ d = "M 0,0 l " + width + ",0 l 0," + height + " l" + -width + " 0 z";
2448
2051
  } else {
2449
- var filterIds = filters.map(function (_ref, i) {
2450
- var name = _ref.name,
2451
- params = _ref.params;
2452
- var $filter = createSVGElement('filter', document);
2453
- // @see https://github.com/antvis/g/issues/1025
2454
- $filter.setAttribute('filterUnits', 'userSpaceOnUse');
2455
- if (name === 'blur') {
2456
- createBlur(document, $filter, params);
2457
- } else if (name === 'brightness') {
2458
- createBrightness(document, $filter, params);
2459
- } else if (name === 'drop-shadow') {
2460
- createDropShadow(document, $filter, params);
2461
- } else if (name === 'contrast') {
2462
- createContrast(document, $filter, params);
2463
- } else if (name === 'grayscale') {
2464
- createGrayscale(document, $filter, params);
2465
- } else if (name === 'sepia') {
2466
- createSepia(document, $filter, params);
2467
- } else if (name === 'saturate') {
2468
- createSaturate(document, $filter, params);
2469
- } else if (name === 'hue-rotate') {
2470
- createHueRotate(document, $filter, params);
2471
- } else if (name === 'invert') {
2472
- createInvert(document, $filter, params);
2473
- }
2474
- $filter.id = filterName + "-" + i;
2475
- $filter.setAttribute('name', filterName);
2476
- $def.appendChild($filter);
2477
- return $filter.id;
2478
- });
2479
- // @see https://github.com/antvis/G/issues/1114
2480
- setTimeout(function () {
2481
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
2482
- return "url(#" + filterId + ")";
2483
- }).join(' '));
2484
- });
2052
+ var _radius$map = radius.map(function (r) {
2053
+ return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
2054
+ }),
2055
+ tlr = _radius$map[0],
2056
+ trr = _radius$map[1],
2057
+ brr = _radius$map[2],
2058
+ blr = _radius$map[3];
2059
+ var signX = width > 0 ? 1 : -1;
2060
+ var signY = height > 0 ? 1 : -1;
2061
+ // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
2062
+ var sweepFlag = signX + signY !== 0 ? 1 : 0;
2063
+ d = [["M " + signX * tlr + ",0"], ["l " + (width - signX * (tlr + trr)) + ",0"], ["a " + trr + "," + trr + ",0,0," + sweepFlag + "," + signX * trr + "," + signY * trr], ["l 0," + (height - signY * (trr + brr))], ["a " + brr + "," + brr + ",0,0," + sweepFlag + "," + -signX * brr + "," + signY * brr], ["l " + (signX * (brr + blr) - width) + ",0"], ["a " + blr + "," + blr + ",0,0," + sweepFlag + "," + -signX * blr + "," + -signY * blr], ["l 0," + (signY * (blr + tlr) - height)], ["a " + tlr + "," + tlr + ",0,0," + sweepFlag + "," + signX * tlr + "," + -signY * tlr], ['z']].join(' ');
2485
2064
  }
2065
+ $el.setAttribute('d', d);
2486
2066
  }
2487
- function convertToAbsoluteValue(param) {
2488
- return param.unit === gLite.UnitType.kPercentage ? param.value / 100 : param.value;
2067
+ function createSVGElement(type, doc) {
2068
+ return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
2489
2069
  }
2490
- /**
2491
- * @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
2492
- */
2493
- function createBlur(document, $filter, params) {
2494
- var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2495
- $feGaussianBlur.setAttribute('in', 'SourceGraphic');
2496
- $feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
2497
- $filter.appendChild($feGaussianBlur);
2070
+ function numberToLongString(x) {
2071
+ return x.toFixed(6).replace('.000000', '');
2498
2072
  }
2499
- function createFeComponentTransfer(document, $filter, _ref2) {
2500
- var type = _ref2.type,
2501
- slope = _ref2.slope,
2502
- intercept = _ref2.intercept,
2503
- tableValues = _ref2.tableValues;
2504
- var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
2505
- [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
2506
- $feFunc.setAttribute('type', type);
2507
- if (type === 'table') {
2508
- $feFunc.setAttribute('tableValues', "" + tableValues);
2073
+ function convertHTML(str) {
2074
+ var regex = /[&|<|>|"|']/g;
2075
+ return str.replace(regex, function (match) {
2076
+ if (match === '&') {
2077
+ return '&amp;';
2078
+ } else if (match === '<') {
2079
+ return '&lt;';
2080
+ } else if (match === '>') {
2081
+ return '&gt;';
2082
+ } else if (match === '"') {
2083
+ return '&quot;';
2509
2084
  } else {
2510
- $feFunc.setAttribute('slope', "" + slope);
2511
- $feFunc.setAttribute('intercept', "" + intercept);
2085
+ return '&apos;';
2512
2086
  }
2513
- $feComponentTransfer.appendChild($feFunc);
2514
- });
2515
- $filter.appendChild($feComponentTransfer);
2516
- }
2517
- function createContrast(document, $filter, params) {
2518
- var slope = convertToAbsoluteValue(params[0]);
2519
- createFeComponentTransfer(document, $filter, {
2520
- type: 'linear',
2521
- slope: slope,
2522
- intercept: -(0.5 * slope) + 0.5
2523
- });
2524
- }
2525
- function createInvert(document, $filter, params) {
2526
- var amount = convertToAbsoluteValue(params[0]);
2527
- createFeComponentTransfer(document, $filter, {
2528
- type: 'table',
2529
- tableValues: amount + " " + (1 - amount)
2530
2087
  });
2531
2088
  }
2532
- function createBrightness(document, $filter, params) {
2533
- var slope = convertToAbsoluteValue(params[0]);
2534
- createFeComponentTransfer(document, $filter, {
2535
- type: 'linear',
2536
- slope: slope,
2537
- intercept: 0
2538
- });
2539
- }
2540
- function createSaturate(document, $filter, params) {
2541
- var amount = convertToAbsoluteValue(params[0]);
2542
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
2543
- $feColorMatrix.setAttribute('type', 'saturate');
2544
- $feColorMatrix.setAttribute('values', "" + amount);
2545
- $filter.appendChild($feColorMatrix);
2546
- }
2547
- function createHueRotate(document, $filter, params) {
2548
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
2549
- $feColorMatrix.setAttribute('type', 'hueRotate');
2550
- // $feColorMatrix.setAttribute('values', `${params[0].to(UnitType.kDegrees).value}`);
2551
- // FIXME: convert to degrees
2552
- $feColorMatrix.setAttribute('values', "" + params[0].value);
2553
- $filter.appendChild($feColorMatrix);
2554
- }
2555
- function createDropShadow(document, $filter, params) {
2556
- var shadowOffsetX = params[0].value;
2557
- var shadowOffsetY = params[1].value;
2558
- var shadowBlur = params[2].value;
2559
- // @ts-ignore
2560
- var shadowColor = params[3].formatted;
2561
- var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2562
- $feGaussianBlur.setAttribute('in', 'SourceAlpha');
2563
- $feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
2564
- $filter.appendChild($feGaussianBlur);
2565
- var $feOffset = createSVGElement('feOffset', document);
2566
- $feOffset.setAttribute('dx', "" + shadowOffsetX);
2567
- $feOffset.setAttribute('dy', "" + shadowOffsetY);
2568
- $feOffset.setAttribute('result', 'offsetblur');
2569
- $filter.appendChild($feOffset);
2570
- var $feFlood = createSVGElement('feFlood', document);
2571
- $feFlood.setAttribute('flood-color', shadowColor);
2572
- $filter.appendChild($feFlood);
2573
- var $feComposite = createSVGElement('feComposite', document);
2574
- $feComposite.setAttribute('in2', 'offsetblur');
2575
- $feComposite.setAttribute('operator', 'in');
2576
- $filter.appendChild($feComposite);
2577
- var $feMerge = createSVGElement('feMerge', document);
2578
- $filter.appendChild($feMerge);
2579
- var $feMergeNode1 = createSVGElement('feMergeNode', document);
2580
- var $feMergeNode2 = createSVGElement('feMergeNode', document);
2581
- $feMergeNode2.setAttribute('in', 'SourceGraphic');
2582
- $feMerge.appendChild($feMergeNode1);
2583
- $feMerge.appendChild($feMergeNode2);
2584
- }
2585
- function createFeColorMatrix(document, $filter, matrix) {
2586
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
2587
- $feColorMatrix.setAttribute('type', 'matrix');
2588
- $feColorMatrix.setAttribute('values', matrix.join(' '));
2589
- $filter.appendChild($feColorMatrix);
2590
- }
2591
- /**
2592
- * @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
2593
- */
2594
- function createGrayscale(document, $filter, params) {
2595
- var amount = convertToAbsoluteValue(params[0]);
2596
- createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2597
- }
2598
- /**
2599
- * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
2600
- */
2601
- function createSepia(document, $filter, params) {
2602
- var amount = convertToAbsoluteValue(params[0]);
2603
- createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2604
- }
2605
- var PATTERN_PREFIX = 'g-pattern-';
2606
- var cacheKey2IDMap = {};
2607
- var counter = 0;
2608
- function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage, plugin) {
2609
- // eg. clipPath don't have fill/stroke
2610
- if (!parsedColor) {
2611
- return '';
2612
- }
2613
- if (gLite.isCSSRGB(parsedColor)) {
2614
- // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
2615
- if (object.style[name] === 'currentColor') {
2616
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
2617
- } else {
2618
- // constant value, eg. '#fff'
2619
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
2620
- }
2621
- } else if (gLite.isPattern(parsedColor)) {
2622
- var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage, plugin);
2623
- // use style instead of attribute when applying <pattern>
2624
- // @see https://stackoverflow.com/a/7723115
2625
- $el.style[name] = "url(#" + patternId + ")";
2626
- return patternId;
2627
- } else {
2628
- if (parsedColor.length === 1) {
2629
- var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
2630
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
2631
- return gradientId;
2632
- } else {
2633
- // @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
2634
- var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
2635
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
2636
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
2637
- return filterId;
2638
- }
2639
- }
2640
- return '';
2641
- }
2642
- function generateCacheKey(src, options) {
2643
- if (options === void 0) {
2644
- options = {};
2645
- }
2646
- var cacheKey = '';
2647
- if (gLite.isCSSGradientValue(src)) {
2648
- var type = src.type,
2649
- value = src.value;
2650
- if (type === gLite.GradientType.LinearGradient || type === gLite.GradientType.RadialGradient) {
2651
- // @ts-ignore
2652
- var _value$options = _extends({}, value, options),
2653
- _type = _value$options.type,
2654
- width = _value$options.width,
2655
- height = _value$options.height,
2656
- steps = _value$options.steps,
2657
- angle = _value$options.angle,
2658
- cx = _value$options.cx,
2659
- cy = _value$options.cy,
2660
- size = _value$options.size;
2661
- cacheKey = "gradient-" + _type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref) {
2662
- var offset = _ref.offset,
2663
- color = _ref.color;
2664
- return "" + offset + color;
2665
- }).join('-');
2666
- }
2667
- } else if (gLite.isPattern(src)) {
2668
- if (isString(src.image)) {
2669
- cacheKey = "pattern-" + src.image + "-" + src.repetition;
2670
- } else if (src.image.nodeName === 'rect') {
2671
- // use rect's entity as key
2672
- cacheKey = "pattern-rect-" + src.image.entity;
2673
- } else {
2674
- cacheKey = "pattern-" + counter;
2675
- }
2676
- }
2677
- if (cacheKey) {
2678
- if (!cacheKey2IDMap[cacheKey]) {
2679
- cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
2680
- }
2681
- }
2682
- return cacheKey2IDMap[cacheKey];
2683
- }
2684
- function formatTransform(transform) {
2685
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/patternTransform
2686
- // should remove unit: rotate(20deg) -> rotate(20)
2687
- return gLite.parseTransform(transform).map(function (parsed) {
2688
- var t = parsed.t,
2689
- d = parsed.d;
2690
- if (t === 'translate') {
2691
- return "translate(" + d[0].value + " " + d[1].value + ")";
2692
- } else if (t === 'translatex') {
2693
- return "translate(" + d[0].value + " 0)";
2694
- } else if (t === 'translatey') {
2695
- return "translate(0 " + d[0].value + ")";
2696
- } else if (t === 'rotate') {
2697
- return "rotate(" + d[0].value + ")";
2698
- } else if (t === 'scale') {
2699
- // scale(1) scale(1, 1)
2700
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2701
- return s.value;
2702
- })) || [1, 1];
2703
- return "scale(" + newScale[0] + ", " + newScale[1] + ")";
2704
- } else if (t === 'scalex') {
2705
- var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2706
- return s.value;
2707
- })) || [1];
2708
- return "scale(" + _newScale[0] + ", 1)";
2709
- } else if (t === 'scaley') {
2710
- var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2711
- return s.value;
2712
- })) || [1];
2713
- return "scale(1, " + _newScale2[0] + ")";
2714
- } else if (t === 'skew') {
2715
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2716
- return s.value;
2717
- })) || [0, 0];
2718
- return "skewX(" + newSkew[0] + ") skewY(" + newSkew[1] + ")";
2719
- } else if (t === 'skewx') {
2720
- var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2721
- return s.value;
2722
- })) || [0];
2723
- return "skewX(" + _newSkew[0] + ")";
2724
- } else if (t === 'skewy') {
2725
- var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
2726
- return s.value;
2727
- })) || [0];
2728
- return "skewY(" + _newSkew2[0] + ")";
2729
- } else if (t === 'matrix') {
2730
- var _d$map = d.map(function (s) {
2731
- return s.value;
2732
- }),
2733
- a = _d$map[0],
2734
- b = _d$map[1],
2735
- c = _d$map[2],
2736
- dd = _d$map[3],
2737
- tx = _d$map[4],
2738
- ty = _d$map[5];
2739
- return "matrix(" + a + " " + b + " " + c + " " + dd + " " + tx + " " + ty + ")";
2740
- }
2741
- }).join(' ');
2742
- }
2743
- function create$Pattern(document, $def, object, pattern, patternId, width, height) {
2744
- var repetition = pattern.repetition,
2745
- transform = pattern.transform;
2746
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
2747
- var $pattern = createSVGElement('pattern', document);
2748
- if (transform) {
2749
- $pattern.setAttribute('patternTransform', formatTransform(transform));
2750
- }
2751
- $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
2752
- $pattern.id = patternId;
2753
- $def.appendChild($pattern);
2754
- $pattern.setAttribute('x', '0');
2755
- $pattern.setAttribute('y', '0');
2756
- var _object$getGeometryBo = object.getGeometryBounds(),
2757
- halfExtents = _object$getGeometryBo.halfExtents;
2758
- // There is no equivalent to CSS no-repeat for SVG patterns
2759
- // @see https://stackoverflow.com/a/33481956
2760
- var patternWidth = width;
2761
- var patternHeight = height;
2762
- if (repetition === 'repeat-x') {
2763
- patternHeight = halfExtents[1] * 2;
2764
- } else if (repetition === 'repeat-y') {
2765
- patternWidth = halfExtents[0] * 2;
2766
- } else if (repetition === 'no-repeat') {
2767
- patternWidth = halfExtents[0] * 2;
2768
- patternHeight = halfExtents[1] * 2;
2769
- }
2770
- $pattern.setAttribute('width', "" + patternWidth);
2771
- $pattern.setAttribute('height', "" + patternHeight);
2772
- return $pattern;
2773
- }
2774
- function createOrUpdatePattern(document, $def, object, pattern, createImage, plugin) {
2775
- var patternId = generateCacheKey(pattern);
2776
- var $existed = $def.querySelector("#" + patternId);
2777
- if (!$existed) {
2778
- var image = pattern.image;
2779
- var imageURL = '';
2780
- if (isString(image)) {
2781
- imageURL = image;
2782
- } else {
2783
- if (gLite.isBrowser) {
2784
- if (image instanceof HTMLImageElement) {
2785
- imageURL = image.src;
2786
- } else if (image instanceof HTMLCanvasElement) {
2787
- imageURL = image.toDataURL();
2788
- } else ;
2789
- }
2790
- }
2791
- if (imageURL) {
2792
- var $image = createSVGElement('image', document);
2793
- // use href instead of xlink:href
2794
- // @see https://stackoverflow.com/a/13379007
2795
- $image.setAttribute('href', imageURL);
2796
- var img;
2797
- if (createImage) {
2798
- img = createImage(imageURL);
2799
- } else if (gLite.isBrowser) {
2800
- img = new window.Image();
2801
- }
2802
- if (!imageURL.match(/^data:/i)) {
2803
- img.crossOrigin = 'Anonymous';
2804
- $image.setAttribute('crossorigin', 'anonymous');
2805
- }
2806
- img.src = imageURL;
2807
- var onload = function onload() {
2808
- var $pattern = create$Pattern(document, $def, object, pattern, patternId, img.width, img.height);
2809
- $def.appendChild($pattern);
2810
- $pattern.appendChild($image);
2811
- $image.setAttribute('x', '0');
2812
- $image.setAttribute('y', '0');
2813
- $image.setAttribute('width', "" + img.width);
2814
- $image.setAttribute('height', "" + img.height);
2815
- };
2816
- if (img.complete) {
2817
- onload();
2818
- } else {
2819
- img.onload = onload;
2820
- // Fix onload() bug in IE9
2821
- // img.src = img.src;
2822
- }
2823
- }
2824
-
2825
- if (image.nodeName === 'rect') {
2826
- var _image$parsedStyle = image.parsedStyle,
2827
- width = _image$parsedStyle.width,
2828
- height = _image$parsedStyle.height;
2829
- var $pattern = create$Pattern(document, $def, image, pattern, patternId, width, height);
2830
- // traverse subtree of pattern
2831
- image.forEach(function (object) {
2832
- plugin.createSVGDom(document, object, null);
2833
- // @ts-ignore
2834
- var svgElement = object.elementSVG;
2835
- // apply local RTS transformation to <group> wrapper
2836
- // account for anchor
2837
- var localTransform = object.getLocalTransform();
2838
- plugin.applyTransform(svgElement.$groupEl, localTransform);
2839
- });
2840
- // @ts-ignore
2841
- var svgElement = image.elementSVG;
2842
- $pattern.appendChild(svgElement.$groupEl);
2843
- }
2844
- }
2845
- return patternId;
2846
- }
2847
- function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
2848
- var bounds = object.getGeometryBounds();
2849
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
2850
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
2851
- var gradientId = generateCacheKey(parsedColor, {
2852
- width: width,
2853
- height: height
2854
- });
2855
- var $existed = $def.querySelector("#" + gradientId);
2856
- if (!$existed) {
2857
- // <linearGradient> <radialGradient>
2858
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
2859
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
2860
- $existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document);
2861
- // @see https://github.com/antvis/g/issues/1025
2862
- $existed.setAttribute('gradientUnits', 'userSpaceOnUse');
2863
- // add stops
2864
- var innerHTML = '';
2865
- parsedColor.value.steps
2866
- // sort by offset @see https://github.com/antvis/G/issues/1171
2867
- .sort(function (a, b) {
2868
- return a.offset.value - b.offset.value;
2869
- }).forEach(function (_ref2) {
2870
- var offset = _ref2.offset,
2871
- color = _ref2.color;
2872
- // TODO: support absolute unit like `px`
2873
- innerHTML += "<stop offset=\"" + offset.value / 100 + "\" stop-color=\"" + color + "\"></stop>";
2874
- });
2875
- $existed.innerHTML = innerHTML;
2876
- $existed.id = gradientId;
2877
- $def.appendChild($existed);
2878
- }
2879
- if (parsedColor.type === gLite.GradientType.LinearGradient) {
2880
- var angle = parsedColor.value.angle;
2881
- var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
2882
- x1 = _computeLinearGradien.x1,
2883
- y1 = _computeLinearGradien.y1,
2884
- x2 = _computeLinearGradien.x2,
2885
- y2 = _computeLinearGradien.y2;
2886
- $existed.setAttribute('x1', "" + x1);
2887
- $existed.setAttribute('y1', "" + y1);
2888
- $existed.setAttribute('x2', "" + x2);
2889
- $existed.setAttribute('y2', "" + y2);
2890
- // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
2891
- } else {
2892
- var _parsedColor$value = parsedColor.value,
2893
- cx = _parsedColor$value.cx,
2894
- cy = _parsedColor$value.cy,
2895
- size = _parsedColor$value.size;
2896
- var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
2897
- x = _computeRadialGradien.x,
2898
- y = _computeRadialGradien.y,
2899
- r = _computeRadialGradien.r;
2900
- $existed.setAttribute('cx', "" + x);
2901
- $existed.setAttribute('cy', "" + y);
2902
- $existed.setAttribute('r', "" + r);
2903
- }
2904
- return gradientId;
2905
- }
2906
- function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
2907
- var filterId = FILTER_PREFIX + object.entity + '-gradient';
2908
- var $existed = $def.querySelector("#" + filterId);
2909
- if (!$existed) {
2910
- $existed = createSVGElement('filter', document);
2911
- $existed.setAttribute('filterUnits', 'userSpaceOnUse');
2912
- // @see https://github.com/antvis/g/issues/1025
2913
- $existed.setAttribute('x', '0%');
2914
- $existed.setAttribute('y', '0%');
2915
- $existed.setAttribute('width', '100%');
2916
- $existed.setAttribute('height', '100%');
2917
- $existed.id = filterId;
2918
- $def.appendChild($existed);
2089
+ var SVG_ATTR_MAP = {
2090
+ opacity: 'opacity',
2091
+ fillStyle: 'fill',
2092
+ fill: 'fill',
2093
+ fillRule: 'fill-rule',
2094
+ fillOpacity: 'fill-opacity',
2095
+ strokeStyle: 'stroke',
2096
+ strokeOpacity: 'stroke-opacity',
2097
+ stroke: 'stroke',
2098
+ clipPath: 'clip-path',
2099
+ textPath: 'text-path',
2100
+ r: 'r',
2101
+ rx: 'rx',
2102
+ ry: 'ry',
2103
+ width: 'width',
2104
+ height: 'height',
2105
+ lineCap: 'stroke-linecap',
2106
+ lineJoin: 'stroke-linejoin',
2107
+ lineWidth: 'stroke-width',
2108
+ lineDash: 'stroke-dasharray',
2109
+ lineDashOffset: 'stroke-dashoffset',
2110
+ miterLimit: 'stroke-miterlimit',
2111
+ font: 'font',
2112
+ fontSize: 'font-size',
2113
+ fontStyle: 'font-style',
2114
+ fontVariant: 'font-variant',
2115
+ fontWeight: 'font-weight',
2116
+ fontFamily: 'font-family',
2117
+ letterSpacing: 'letter-spacing',
2118
+ startArrow: 'marker-start',
2119
+ endArrow: 'marker-end',
2120
+ class: 'class',
2121
+ id: 'id',
2122
+ // style: 'style',
2123
+ preserveAspectRatio: 'preserveAspectRatio',
2124
+ visibility: 'visibility',
2125
+ anchor: 'anchor',
2126
+ shadowColor: 'flood-color',
2127
+ shadowBlur: 'stdDeviation',
2128
+ shadowOffsetX: 'dx',
2129
+ shadowOffsetY: 'dy',
2130
+ filter: 'filter',
2131
+ innerHTML: 'innerHTML',
2132
+ textAlign: 'text-anchor',
2133
+ pointerEvents: 'pointer-events'
2134
+ };
2135
+ var FORMAT_VALUE_MAP = {
2136
+ textAlign: {
2137
+ inherit: 'inherit',
2138
+ left: 'left',
2139
+ start: 'left',
2140
+ center: 'middle',
2141
+ right: 'end',
2142
+ end: 'end'
2919
2143
  }
2920
- /**
2921
- * <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
2922
- * <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
2923
- <feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
2924
- <feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
2925
- <feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
2926
- <feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
2927
- </filter>
2928
- */
2929
- var blended = 0;
2930
- gradients.forEach(function (gradient, i) {
2931
- var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
2932
- var rectId = gradientId + '_rect';
2933
- var $rect = createSVGElement('rect', document);
2934
- $rect.setAttribute('x', '0');
2935
- $rect.setAttribute('y', '0');
2936
- $rect.setAttribute('width', '100%');
2937
- $rect.setAttribute('height', '100%');
2938
- $rect.setAttribute('fill', "url(#" + gradientId + ")");
2939
- $rect.id = rectId;
2940
- $def.appendChild($rect);
2941
- var $feImage = createSVGElement('feImage', document);
2942
- $feImage.setAttribute('href', "#" + rectId);
2943
- $feImage.setAttribute('result', filterId + "-" + i);
2944
- $existed.appendChild($feImage);
2945
- if (i > 0) {
2946
- var $feBlend = createSVGElement('feBlend', document);
2947
- $feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
2948
- $feBlend.setAttribute('in2', filterId + "-" + i);
2949
- $feBlend.setAttribute('result', filterId + "-blended-" + blended++);
2950
- // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
2951
- $feBlend.setAttribute('mode', 'multiply');
2952
- $existed.appendChild($feBlend);
2953
- }
2954
- });
2955
- var $feComposite = createSVGElement('feComposite', document);
2956
- $feComposite.setAttribute('in', filterId + "-blended-" + blended);
2957
- $feComposite.setAttribute('in2', 'SourceGraphic');
2958
- $feComposite.setAttribute('operator', 'in');
2959
- $existed.appendChild($feComposite);
2960
- return filterId;
2961
- }
2962
- var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
2144
+ };
2145
+ var DEFAULT_VALUE_MAP = {
2146
+ textAlign: 'inherit',
2147
+ // textBaseline: 'alphabetic',
2148
+ // @see https://www.w3.org/TR/SVG/painting.html#LineCaps
2149
+ lineCap: 'butt',
2150
+ // @see https://www.w3.org/TR/SVG/painting.html#LineJoin
2151
+ lineJoin: 'miter',
2152
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
2153
+ lineWidth: '1px',
2154
+ opacity: '1',
2155
+ fillOpacity: '1',
2156
+ fillRule: 'nonzero',
2157
+ strokeOpacity: '1',
2158
+ strokeWidth: '0',
2159
+ strokeMiterLimit: '4',
2160
+ letterSpacing: '0',
2161
+ fontSize: 'inherit',
2162
+ fontFamily: 'inherit',
2163
+ pointerEvents: 'auto'
2164
+ };
2963
2165
  /**
2964
- * use SVG filters
2965
- * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2166
+ * G_SVG_PREFIX + nodeName + entity
2167
+ *
2168
+ * eg. g_svg_circle_345
2966
2169
  */
2967
- function createOrUpdateShadow(document, $def, object, $el, name) {
2968
- var _object$parsedStyle = object.parsedStyle,
2969
- shadowType = _object$parsedStyle.shadowType,
2970
- shadowBlur = _object$parsedStyle.shadowBlur,
2971
- shadowColor = _object$parsedStyle.shadowColor,
2972
- shadowOffsetX = _object$parsedStyle.shadowOffsetX,
2973
- shadowOffsetY = _object$parsedStyle.shadowOffsetY;
2974
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
2975
- var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
2976
- var $existedFilter = $def.querySelector("#" + shadowId);
2977
- if ($existedFilter) {
2978
- var existedShadowType = $existedFilter.getAttribute('data-type');
2979
- if (existedShadowType !== shadowType || !hasShadow) {
2980
- // remove existed shadow
2981
- $existedFilter.remove();
2982
- $existedFilter = null;
2983
- }
2984
- }
2985
- // <Group> also has shadowType as its default value
2986
- // only apply shadow when blur > 0
2987
- if (hasShadow) {
2988
- // use filter <feDropShadow>
2989
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2990
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2991
- } else {
2992
- $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2993
- return;
2994
- }
2995
- if (!$existedFilter) {
2996
- $existedFilter = createSVGElement('filter', document);
2997
- $existedFilter.setAttribute('data-type', shadowType);
2998
- if (shadowType === 'outer') {
2999
- var $feDropShadow = createSVGElement('feDropShadow', document);
3000
- $feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3001
- $feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3002
- $feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3003
- $feDropShadow.setAttribute('flood-color', shadowColor.toString());
3004
- $existedFilter.appendChild($feDropShadow);
3005
- } else if (shadowType === 'inner') {
3006
- var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
3007
- $feComponentTransfer.setAttribute('in', 'SourceAlpha');
3008
- var $feFuncA = createSVGElement('feFuncA', document);
3009
- $feFuncA.setAttribute('type', 'table');
3010
- $feFuncA.setAttribute('tableValues', '1 0');
3011
- $feComponentTransfer.appendChild($feFuncA);
3012
- $existedFilter.appendChild($feComponentTransfer);
3013
- var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
3014
- $feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3015
- $existedFilter.appendChild($feGaussianBlur);
3016
- var $feOffset = createSVGElement('feOffset', document);
3017
- $feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3018
- $feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3019
- $feOffset.setAttribute('result', 'offsetblur');
3020
- $existedFilter.appendChild($feOffset);
3021
- var $feFlood = createSVGElement('feFlood', document);
3022
- $feFlood.setAttribute('flood-color', shadowColor.toString());
3023
- $feFlood.setAttribute('result', 'color');
3024
- $existedFilter.appendChild($feFlood);
3025
- var $feComposite = createSVGElement('feComposite', document);
3026
- $feComposite.setAttribute('in2', 'offsetblur');
3027
- $feComposite.setAttribute('operator', 'in');
3028
- $existedFilter.appendChild($feComposite);
3029
- var $feComposite2 = createSVGElement('feComposite', document);
3030
- $feComposite2.setAttribute('in2', 'SourceAlpha');
3031
- $feComposite2.setAttribute('operator', 'in');
3032
- $existedFilter.appendChild($feComposite2);
3033
- var $feMerge = createSVGElement('feMerge', document);
3034
- $existedFilter.appendChild($feMerge);
3035
- var $feMergeNode = createSVGElement('feMergeNode', document);
3036
- $feMergeNode.setAttribute('in', 'SourceGraphic');
3037
- var $feMergeNode2 = createSVGElement('feMergeNode', document);
3038
- $feMerge.appendChild($feMergeNode);
3039
- $feMerge.appendChild($feMergeNode2);
3040
- }
3041
- $existedFilter.id = shadowId;
3042
- // @see https://github.com/antvis/g/issues/1025
3043
- $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
3044
- $def.appendChild($existedFilter);
3045
- return;
3046
- }
3047
- if (shadowType === 'inner') {
3048
- var _$feGaussianBlur = $existedFilter.children[1];
3049
- var _$feOffset = $existedFilter.children[2];
3050
- var _$feFlood = $existedFilter.children[3];
3051
- if (name === 'shadowColor') {
3052
- _$feFlood.setAttribute('flood-color', shadowColor.toString());
3053
- } else if (name === 'shadowBlur') {
3054
- // half the blur radius
3055
- // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
3056
- // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
3057
- _$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3058
- } else if (name === 'shadowOffsetX') {
3059
- _$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3060
- } else if (name === 'shadowOffsetY') {
3061
- _$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3062
- }
3063
- } else if (shadowType === 'outer') {
3064
- var _$feDropShadow = $existedFilter.children[0];
3065
- if (name === 'shadowColor') {
3066
- _$feDropShadow.setAttribute('flood-color', shadowColor.toString());
3067
- } else if (name === 'shadowBlur') {
3068
- // half the blur radius
3069
- // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
3070
- // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
3071
- _$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3072
- } else if (name === 'shadowOffsetX') {
3073
- _$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3074
- } else if (name === 'shadowOffsetY') {
3075
- _$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3076
- }
3077
- }
3078
- }
3079
- var urlRegexp = /url\("?#(.*)\)/;
3080
- var DefElementManager = /*#__PURE__*/function () {
3081
- function DefElementManager(context) {
2170
+ var G_SVG_PREFIX = 'g-svg';
2171
+ var CLIP_PATH_PREFIX = 'clip-path-';
2172
+ var TEXT_PATH_PREFIX = 'text-path-';
2173
+ var SVGRendererPlugin = /*#__PURE__*/function () {
2174
+ function SVGRendererPlugin(pluginOptions, defElementManager, context) {
2175
+ this.pluginOptions = void 0;
2176
+ this.defElementManager = void 0;
3082
2177
  this.context = void 0;
2178
+ this.svgElementMap = new WeakMap();
3083
2179
  /**
3084
- * container for <gradient> <clipPath>...
2180
+ * <camera>
3085
2181
  */
3086
- this.$def = void 0;
3087
- this.gradientCache = {};
2182
+ this.$camera = void 0;
2183
+ /**
2184
+ * render at the end of frame
2185
+ */
2186
+ this.renderQueue = [];
2187
+ /**
2188
+ * dirty attributes at the end of frame
2189
+ */
2190
+ this.dirtyAttributes = new WeakMap();
2191
+ /**
2192
+ * reorder after mounted
2193
+ */
2194
+ this.pendingReorderQueue = new Set();
2195
+ /**
2196
+ * <use> elements in <clipPath>, which should be sync with clipPath
2197
+ *
2198
+ * @example
2199
+ * <clipPath transform="matrix(1,0,0,1,-100,-155)" id="clip-path-0-2">
2200
+ * <use href="#g_svg_circle_0" transform="matrix(1.477115,0,0,1.477115,150,150)">
2201
+ * </use>
2202
+ * </clipPath>
2203
+ */
2204
+ this.clipPathUseMap = new WeakMap();
2205
+ this.pluginOptions = pluginOptions;
2206
+ this.defElementManager = defElementManager;
3088
2207
  this.context = context;
3089
2208
  }
3090
- var _proto = DefElementManager.prototype;
3091
- _proto.getDefElement = function getDefElement() {
3092
- return this.$def;
2209
+ var _proto = SVGRendererPlugin.prototype;
2210
+ _proto.apply = function apply(context) {
2211
+ var _this = this;
2212
+ var renderingService = context.renderingService,
2213
+ renderingContext = context.renderingContext;
2214
+ this.context = context;
2215
+ // @ts-ignore
2216
+ this.context.svgElementMap = this.svgElementMap;
2217
+ var canvas = renderingContext.root.ownerDocument.defaultView;
2218
+ var document = this.context.config.document;
2219
+ var handleMounted = function handleMounted(e) {
2220
+ var object = e.target;
2221
+ // should remove clipPath already existed in <defs>
2222
+ var $useRefs = _this.clipPathUseMap.get(object);
2223
+ if ($useRefs) {
2224
+ var $def = _this.defElementManager.getDefElement();
2225
+ var existed = $def.querySelector("#" + _this.getId(object));
2226
+ if (existed) {
2227
+ existed.remove();
2228
+ }
2229
+ }
2230
+ // create SVG DOM Node
2231
+ _this.createSVGDom(document, object, _this.$camera);
2232
+ };
2233
+ var handleUnmounted = function handleUnmounted(e) {
2234
+ var object = e.target;
2235
+ _this.defElementManager.clear(object.entity);
2236
+ _this.clipPathUseMap.delete(object);
2237
+ _this.removeSVGDom(object);
2238
+ };
2239
+ var reorderChildren = function reorderChildren(object) {
2240
+ var _object$parentNode, _object$parentNode$el;
2241
+ var parent = object.parentNode;
2242
+ // @ts-ignore
2243
+ var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
2244
+ var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
2245
+ if ($groupEl) {
2246
+ _this.reorderChildren(document, $groupEl, children);
2247
+ }
2248
+ };
2249
+ var handleReparent = function handleReparent(e) {
2250
+ var object = e.target;
2251
+ reorderChildren(object);
2252
+ };
2253
+ var handleAttributeChanged = function handleAttributeChanged(e) {
2254
+ var object = e.target;
2255
+ // @see https://github.com/antvis/g/issues/994
2256
+ // @ts-ignore
2257
+ if (!object.elementSVG) {
2258
+ return;
2259
+ }
2260
+ var attrName = e.attrName;
2261
+ var attribtues = _this.dirtyAttributes.get(object);
2262
+ if (!attribtues) {
2263
+ _this.dirtyAttributes.set(object, []);
2264
+ attribtues = _this.dirtyAttributes.get(object);
2265
+ }
2266
+ attribtues.push(attrName);
2267
+ };
2268
+ var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
2269
+ var _object$elementSVG;
2270
+ var object = e.target;
2271
+ // @ts-ignore
2272
+ var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
2273
+ var _object$parsedStyle = object.parsedStyle,
2274
+ fill = _object$parsedStyle.fill,
2275
+ stroke = _object$parsedStyle.stroke,
2276
+ clipPath = _object$parsedStyle.clipPath;
2277
+ if (fill && !gLite.isCSSRGB(fill)) {
2278
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill', _this);
2279
+ }
2280
+ if (stroke && !gLite.isCSSRGB(stroke)) {
2281
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke', _this);
2282
+ }
2283
+ if (clipPath) {
2284
+ var parentInvert = invert(create(), object.getWorldTransform());
2285
+ var clipPathId = CLIP_PATH_PREFIX + clipPath.entity + '-' + object.entity;
2286
+ var $def = _this.defElementManager.getDefElement();
2287
+ var $existed = $def.querySelector("#" + clipPathId);
2288
+ if ($existed) {
2289
+ _this.applyTransform($existed, parentInvert);
2290
+ }
2291
+ }
2292
+ };
2293
+ renderingService.hooks.init.tapPromise(SVGRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
2294
+ var _this$context$config, background, document, $svg;
2295
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
2296
+ while (1) switch (_context.prev = _context.next) {
2297
+ case 0:
2298
+ _this$context$config = _this.context.config, background = _this$context$config.background, document = _this$context$config.document; // <defs>
2299
+ _this.defElementManager.init();
2300
+ $svg = _this.context.contextService.getContext();
2301
+ if (background) {
2302
+ $svg.style.background = background;
2303
+ }
2304
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
2305
+ $svg.setAttribute('color-interpolation-filters', 'sRGB');
2306
+ _this.$camera = createSVGElement('g', document);
2307
+ _this.$camera.id = G_SVG_PREFIX + "-camera";
2308
+ _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
2309
+ $svg.appendChild(_this.$camera);
2310
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
2311
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2312
+ canvas.addEventListener(gLite.ElementEvent.REPARENT, handleReparent);
2313
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
2314
+ canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
2315
+ case 14:
2316
+ case "end":
2317
+ return _context.stop();
2318
+ }
2319
+ }, _callee);
2320
+ })));
2321
+ renderingService.hooks.destroy.tap(SVGRendererPlugin.tag, function () {
2322
+ canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
2323
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2324
+ canvas.removeEventListener(gLite.ElementEvent.REPARENT, handleReparent);
2325
+ canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
2326
+ canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
2327
+ });
2328
+ renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
2329
+ // if (!object.isCulled()) {
2330
+ _this.renderQueue.push(object);
2331
+ // }
2332
+ });
2333
+
2334
+ renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
2335
+ var doc = _this.context.config.document;
2336
+ if (_this.pendingReorderQueue.size) {
2337
+ _this.pendingReorderQueue.forEach(function (object) {
2338
+ var _object$elementSVG2;
2339
+ var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
2340
+ var $parentGroupEl =
2341
+ // @ts-ignore
2342
+ object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
2343
+ if ($parentGroupEl) {
2344
+ _this.reorderChildren(doc || document, $parentGroupEl, children || []);
2345
+ }
2346
+ });
2347
+ _this.pendingReorderQueue.clear();
2348
+ }
2349
+ });
2350
+ renderingService.hooks.endFrame.tap(SVGRendererPlugin.tag, function () {
2351
+ if (renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
2352
+ _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
2353
+ }
2354
+ _this.renderQueue.forEach(function (object) {
2355
+ var _object$elementSVG3, _object$elementSVG4;
2356
+ // @ts-ignore
2357
+ var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el;
2358
+ // @ts-ignore
2359
+ var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
2360
+ if ($el && $groupEl) {
2361
+ // apply local RTS transformation to <group> wrapper
2362
+ // account for anchor
2363
+ var localTransform = object.getLocalTransform();
2364
+ _this.applyTransform($groupEl, localTransform);
2365
+ // clipped shapes should also be informed
2366
+ var $useRefs = _this.clipPathUseMap.get(object);
2367
+ if ($useRefs && $useRefs.length) {
2368
+ $useRefs.forEach(function ($use) {
2369
+ // <clipPath transform="matrix()"><circle /></clipPath>
2370
+ _this.applyTransform($use, object.getWorldTransform());
2371
+ // const parentInvert = mat4.invert(
2372
+ // mat4.create(),
2373
+ // (object as DisplayObject).getWorldTransform(),
2374
+ // );
2375
+ // this.applyTransform($clipPath, parentInvert);
2376
+ });
2377
+ }
2378
+ // finish rendering, clear dirty flag
2379
+ object.renderable.dirty = false;
2380
+ }
2381
+ // update dirty attributes
2382
+ var attributes = _this.dirtyAttributes.get(object);
2383
+ if (attributes) {
2384
+ attributes.forEach(function (attrName) {
2385
+ if (attrName === 'zIndex') {
2386
+ reorderChildren(object);
2387
+ } else if (attrName === 'increasedLineWidthForHitTesting') {
2388
+ _this.createOrUpdateHitArea(object, $el, $groupEl);
2389
+ }
2390
+ _this.updateAttribute(object, [attrName]);
2391
+ });
2392
+ _this.dirtyAttributes.delete(object);
2393
+ }
2394
+ });
2395
+ _this.renderQueue = [];
2396
+ });
3093
2397
  };
3094
- _proto.init = function init() {
3095
- var document = this.context.config.document;
3096
- var $svg = this.context.contextService.getContext();
3097
- this.$def = createSVGElement('defs', document);
3098
- $svg.appendChild(this.$def);
2398
+ _proto.getId = function getId(object) {
2399
+ return G_SVG_PREFIX + "-" + object.entity;
3099
2400
  };
3100
- _proto.clear = function clear(entity) {
3101
- var _this = this;
3102
- Object.keys(this.gradientCache).forEach(function (id) {
3103
- _this.clearUnusedDefElement(_this.gradientCache, id, entity);
2401
+ _proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
2402
+ // need to reorder parent's children
2403
+ children.sort(function (a, b) {
2404
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3104
2405
  });
2406
+ if (children.length) {
2407
+ // create empty fragment
2408
+ var fragment = (doc || document).createDocumentFragment();
2409
+ children.forEach(function (child) {
2410
+ if (child.isConnected) {
2411
+ // @ts-ignore
2412
+ var $el = child.elementSVG.$groupEl;
2413
+ if ($el) {
2414
+ fragment.appendChild($el);
2415
+ }
2416
+ }
2417
+ });
2418
+ $groupEl.appendChild(fragment);
2419
+ }
3105
2420
  };
3106
- _proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
3107
- if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
3108
- var targetElement = this.$def.querySelector("#" + id);
3109
- if (targetElement) {
3110
- this.$def.removeChild(targetElement);
2421
+ _proto.applyTransform = function applyTransform($el, rts) {
2422
+ // use proper precision avoiding too long string in `transform`
2423
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
2424
+ $el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
2425
+ };
2426
+ _proto.applyAttributes = function applyAttributes(object) {
2427
+ // @ts-ignore
2428
+ var elementSVG = object.elementSVG;
2429
+ var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
2430
+ var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
2431
+ if ($el && $groupEl) {
2432
+ var nodeName = object.nodeName,
2433
+ attributes = object.attributes;
2434
+ $el.setAttribute('fill', 'none');
2435
+ if (nodeName === gLite.Shape.IMAGE) {
2436
+ $el.setAttribute('preserveAspectRatio', 'none');
3111
2437
  }
2438
+ // apply attributes
2439
+ this.updateAttribute(object, Object.keys(attributes));
3112
2440
  }
3113
2441
  };
3114
- _proto.createOrUpdateGradientAndPattern = function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name, plugin) {
3115
- var _this$context$config = this.context.config,
3116
- doc = _this$context$config.document,
3117
- createImage = _this$context$config.createImage;
2442
+ _proto.updateAttribute = function updateAttribute(object, attributes) {
2443
+ var _this2 = this;
2444
+ var document = this.context.config.document;
2445
+ // @ts-ignore
2446
+ var _object$elementSVG5 = object.elementSVG,
2447
+ $el = _object$elementSVG5.$el,
2448
+ $groupEl = _object$elementSVG5.$groupEl,
2449
+ $hitTestingEl = _object$elementSVG5.$hitTestingEl;
2450
+ var parsedStyle = object.parsedStyle,
2451
+ computedStyle = object.computedStyle;
2452
+ var shouldUpdateElementAttribute = attributes.some(function (name) {
2453
+ return (
2454
+ // @ts-ignore
2455
+ _this2.context.SVGElementLifeCycleContribution.shouldUpdateElementAttribute(object, name)
2456
+ );
2457
+ });
2458
+ // need re-generate path
2459
+ if (shouldUpdateElementAttribute && $el) {
2460
+ [$el, $hitTestingEl].forEach(function ($el) {
2461
+ if ($el) {
2462
+ // @ts-ignore
2463
+ _this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el);
2464
+ if (object.nodeName !== gLite.Shape.TEXT) {
2465
+ _this2.updateAnchorWithTransform(object);
2466
+ }
2467
+ }
2468
+ });
2469
+ }
2470
+ // update common attributes
2471
+ attributes.forEach(function (name) {
2472
+ var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
2473
+ var usedName = SVG_ATTR_MAP[name];
2474
+ var computedValue = gLite.runtime.enableCSSParsing ? computedStyle[name] : parsedStyle[name];
2475
+ var computedValueStr = !isNil(computedValue) && computedValue.toString();
2476
+ var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[computedValueStr]) || computedValueStr;
2477
+ var usedValue = parsedStyle[name];
2478
+ var inherited = gLite.runtime.enableCSSParsing && !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
2479
+ if (!usedName) {
2480
+ return;
2481
+ }
2482
+ // <foreignObject>
2483
+ if (object.nodeName === gLite.Shape.HTML) {
2484
+ if (name === 'lineWidth') {
2485
+ $el.style['border-width'] = (usedValue || 0) + "px";
2486
+ } else if (name === 'lineDash') {
2487
+ $el.style['border-style'] = 'dashed';
2488
+ }
2489
+ }
2490
+ if (name === 'fill') {
2491
+ if (object.nodeName === gLite.Shape.HTML) {
2492
+ $el.style.background = usedValue.toString();
2493
+ } else {
2494
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
2495
+ }
2496
+ } else if (name === 'stroke') {
2497
+ if (object.nodeName === gLite.Shape.HTML) {
2498
+ $el.style['border-color'] = usedValue.toString();
2499
+ $el.style['border-style'] = 'solid';
2500
+ } else {
2501
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
2502
+ }
2503
+ } else if (inherited && usedName) {
2504
+ // use computed value
2505
+ // update `visibility` on <group>
2506
+ if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
2507
+ $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, formattedValueStr);
2508
+ } else {
2509
+ $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.removeAttribute(usedName);
2510
+ }
2511
+ } else if (name === 'clipPath') {
2512
+ _this2.createOrUpdateClipOrTextPath(document, usedValue, object);
2513
+ } else if (name === 'textPath') {
2514
+ _this2.createOrUpdateClipOrTextPath(document, usedValue, object, true);
2515
+ } else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
2516
+ _this2.defElementManager.createOrUpdateShadow(object, $el, name);
2517
+ } else if (name === 'filter') {
2518
+ _this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
2519
+ } else if (name === 'innerHTML') {
2520
+ _this2.createOrUpdateInnerHTML(document, $el, usedValue);
2521
+ } else if (name === 'anchor') {
2522
+ // text' anchor is controlled by `textAnchor` property
2523
+ if (object.nodeName !== gLite.Shape.TEXT) {
2524
+ _this2.updateAnchorWithTransform(object);
2525
+ }
2526
+ } else {
2527
+ if (!isNil(computedValue)) {
2528
+ // use computed value so that we can use cascaded effect in SVG
2529
+ // ignore 'unset' and default value
2530
+ [$el, $hitTestingEl].forEach(function ($el) {
2531
+ if ($el && usedName) {
2532
+ if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
2533
+ $el.setAttribute(usedName, formattedValueStr);
2534
+ } else {
2535
+ $el.removeAttribute(usedName);
2536
+ }
2537
+ }
2538
+ });
2539
+ }
2540
+ }
2541
+ });
2542
+ };
2543
+ _proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
2544
+ if (noWrapWithGroup === void 0) {
2545
+ noWrapWithGroup = false;
2546
+ }
2547
+ // create svg element
2548
+ // @ts-ignore
2549
+ object.elementSVG = new ElementSVG();
2550
+ // @ts-ignore
2551
+ var svgElement = object.elementSVG;
2552
+ // use <group> as default, eg. CustomElement
2553
+ var $el =
2554
+ // @ts-ignore
2555
+ this.context.SVGElementLifeCycleContribution.createElement(object);
3118
2556
  if ($el) {
3119
- var attributeValue = '';
3120
- if (gLite.isPattern(parsedColor)) {
3121
- // `fill: url(#${patternId})`
3122
- attributeValue = $el.style[name];
3123
- } else {
3124
- // `url(#${gradientId})`
3125
- attributeValue = $el.getAttribute(name) || '';
2557
+ var _object$parentNode$el2;
2558
+ var $groupEl;
2559
+ // save $el on parsedStyle, which will be returned in getDomElement()
2560
+ if (object.nodeName === gLite.Shape.HTML) {
2561
+ object.parsedStyle.$el = $el;
3126
2562
  }
3127
- var matches = attributeValue.match(urlRegexp);
3128
- if (matches && matches.length > 1) {
3129
- this.clearUnusedDefElement(this.gradientCache, matches[1].replace('"', ''), object.entity);
2563
+ if (this.pluginOptions.outputSVGElementId) {
2564
+ $el.id = this.getId(object);
3130
2565
  }
3131
- var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage, plugin);
3132
- if (newDefElementId) {
3133
- if (!this.gradientCache[newDefElementId]) {
3134
- this.gradientCache[newDefElementId] = new Set();
3135
- }
3136
- this.gradientCache[newDefElementId].add(object.entity);
2566
+ if (this.pluginOptions.outputSVGElementName && object.name) {
2567
+ $el.setAttribute('name', object.name);
2568
+ }
2569
+ if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
2570
+ $groupEl = createSVGElement('g', document);
2571
+ $groupEl.id = $el.id + '-g';
2572
+ $groupEl.appendChild($el);
2573
+ } else {
2574
+ $groupEl = $el;
2575
+ }
2576
+ svgElement.$el = $el;
2577
+ svgElement.$groupEl = $groupEl;
2578
+ this.svgElementMap.set($el, object);
2579
+ // apply attributes at first time
2580
+ this.applyAttributes(object);
2581
+ // create hitArea if necessary
2582
+ this.createOrUpdateHitArea(object, $el, $groupEl);
2583
+ var $parentGroupEl = root ||
2584
+ // @ts-ignore
2585
+ object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl);
2586
+ if ($parentGroupEl) {
2587
+ $parentGroupEl.appendChild($groupEl);
2588
+ // need reorder children later
2589
+ this.pendingReorderQueue.add(object.parentNode);
3137
2590
  }
3138
2591
  }
3139
2592
  };
3140
- _proto.createOrUpdateShadow = function createOrUpdateShadow$1(object, $el, name) {
3141
- var doc = this.context.config.document;
3142
- createOrUpdateShadow(doc || document, this.$def, object, $el, name);
2593
+ _proto.removeSVGDom = function removeSVGDom(object) {
2594
+ var _object$elementSVG6;
2595
+ // @ts-ignore
2596
+ var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
2597
+ if ($groupEl && $groupEl.parentNode) {
2598
+ $groupEl.parentNode.removeChild($groupEl);
2599
+ // @ts-ignore
2600
+ this.context.SVGElementLifeCycleContribution.destroyElement(object, $groupEl);
2601
+ // object.entity.removeComponent(ElementSVG, true);
2602
+ }
3143
2603
  };
3144
- _proto.createOrUpdateFilter = function createOrUpdateFilter$1(object, $el, filters) {
3145
- var doc = this.context.config.document;
3146
- createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
2604
+
2605
+ _proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
2606
+ // @ts-ignore
2607
+ var svgElement = object.elementSVG;
2608
+ var $hitTestingEl = svgElement.$hitTestingEl;
2609
+ var increasedLineWidthForHitTesting = object.parsedStyle.increasedLineWidthForHitTesting;
2610
+ // account for hitArea
2611
+ if (increasedLineWidthForHitTesting) {
2612
+ if (!$hitTestingEl) {
2613
+ $hitTestingEl = $el.cloneNode();
2614
+ if (this.pluginOptions.outputSVGElementId) {
2615
+ // use the entity suffix, so that `g-plugin-svg-picker` can extract
2616
+ $hitTestingEl.id = G_SVG_PREFIX + "-" + object.nodeName + "-hittesting-" + object.entity;
2617
+ }
2618
+ // clear attributes like `filter` `font-size`
2619
+ ['filter'].forEach(function (attribute) {
2620
+ $hitTestingEl.removeAttribute(attribute);
2621
+ });
2622
+ // hitArea should be 'transparent' but not 'none'
2623
+ var hasFill = $el.getAttribute('fill') !== 'none';
2624
+ $hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
2625
+ $hitTestingEl.setAttribute('stroke', 'transparent');
2626
+ $groupEl.appendChild($hitTestingEl);
2627
+ svgElement.$hitTestingEl = $hitTestingEl;
2628
+ }
2629
+ // increase interactive line width
2630
+ $hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
2631
+ } else {
2632
+ if ($hitTestingEl) {
2633
+ $groupEl.removeChild($hitTestingEl);
2634
+ svgElement.$hitTestingEl = null;
2635
+ }
2636
+ }
3147
2637
  };
3148
- return DefElementManager;
3149
- }();
3150
- var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
3151
- _inheritsLoose$2(Plugin, _AbstractRendererPlug);
3152
- function Plugin(options) {
3153
- var _this;
3154
- if (options === void 0) {
3155
- options = {};
2638
+ _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
2639
+ var $div = (doc || document).createElement('div');
2640
+ if (typeof usedValue === 'string') {
2641
+ $div.innerHTML = usedValue;
2642
+ } else {
2643
+ $div.appendChild(usedValue);
3156
2644
  }
3157
- _this = _AbstractRendererPlug.call(this) || this;
3158
- _this.options = void 0;
3159
- _this.name = 'svg-renderer';
3160
- _this.options = options;
3161
- return _this;
3162
- }
3163
- var _proto = Plugin.prototype;
3164
- _proto.init = function init() {
3165
- var _this$options = this.options,
3166
- outputSVGElementId = _this$options.outputSVGElementId,
3167
- outputSVGElementName = _this$options.outputSVGElementName;
3168
- var defElementManager = new DefElementManager(this.context);
3169
- // default implementation
3170
- var defaultElementLifeCycleContribution = new DefaultElementLifeCycleContribution(this.context);
3171
- // @ts-ignore
3172
- this.context.defaultElementLifeCycleContribution = defaultElementLifeCycleContribution;
3173
- // @ts-ignore
3174
- this.context.SVGElementLifeCycleContribution = defaultElementLifeCycleContribution;
3175
- var SVGRendererPluginOptions = {
3176
- outputSVGElementId: !isNil(outputSVGElementId) ? !!outputSVGElementId : true,
3177
- outputSVGElementName: !isNil(outputSVGElementName) ? !!outputSVGElementName : true
3178
- };
3179
- this.addRenderingPlugin(
3180
- // @ts-ignore
3181
- new SVGRendererPlugin(SVGRendererPluginOptions, defElementManager, this.context));
2645
+ $el.innerHTML = '';
2646
+ $el.appendChild($div);
3182
2647
  };
3183
- _proto.destroy = function destroy() {
3184
- this.removeAllRenderingPlugins();
2648
+ _proto.createOrUpdateClipOrTextPath = function createOrUpdateClipOrTextPath(document, clipPath, object, isTextPath) {
2649
+ if (isTextPath === void 0) {
2650
+ isTextPath = false;
2651
+ }
3185
2652
  // @ts-ignore
3186
- delete this.context.defaultElementLifeCycleContribution;
2653
+ var $groupEl = object.elementSVG.$groupEl;
2654
+ var PREFIX = isTextPath ? TEXT_PATH_PREFIX : CLIP_PATH_PREFIX;
2655
+ var attributeNameCamel = isTextPath ? 'g' : 'clipPath';
2656
+ var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
2657
+ if (clipPath) {
2658
+ var clipPathId = PREFIX + clipPath.entity + '-' + object.entity;
2659
+ var $def = this.defElementManager.getDefElement();
2660
+ var existed = $def.querySelector("#" + clipPathId);
2661
+ if (!existed) {
2662
+ var $clipPath;
2663
+ if (isTextPath) {
2664
+ // use <path> directly instead of wrapping with <g>
2665
+ this.createSVGDom(document, clipPath, null, true);
2666
+ // @ts-ignore
2667
+ $clipPath = clipPath.elementSVG.$el;
2668
+ } else {
2669
+ // the clipPath is allowed to be detached from canvas
2670
+ if (!clipPath.isConnected) {
2671
+ var $existedClipPath = $def.querySelector("#" + this.getId(clipPath));
2672
+ if (!$existedClipPath) {
2673
+ this.createSVGDom(document, clipPath, $def, true);
2674
+ }
2675
+ }
2676
+ // create <clipPath> dom node
2677
+ $clipPath = createSVGElement(attributeNameCamel, document);
2678
+ var $use = createSVGElement('use', document);
2679
+ // @ts-ignore
2680
+ $use.setAttribute('href', "#" + clipPath.elementSVG.$el.id);
2681
+ $clipPath.appendChild($use);
2682
+ var $useRefs = this.clipPathUseMap.get(clipPath);
2683
+ if (!$useRefs) {
2684
+ this.clipPathUseMap.set(clipPath, []);
2685
+ $useRefs = this.clipPathUseMap.get(clipPath);
2686
+ }
2687
+ $useRefs.push($use);
2688
+ // <clipPath transform="matrix()"><circle /></clipPath>
2689
+ this.applyTransform($use, clipPath.getWorldTransform());
2690
+ var parentInvert = invert(create(), object.getWorldTransform());
2691
+ this.applyTransform($clipPath, parentInvert);
2692
+ }
2693
+ $clipPath.id = clipPathId;
2694
+ // append it to <defs>
2695
+ $def.appendChild($clipPath);
2696
+ }
2697
+ // apply attributes
2698
+ this.applyAttributes(clipPath);
2699
+ if (!isTextPath) {
2700
+ // apply clipPath to $group
2701
+ // @see https://github.com/antvis/g/issues/961
2702
+ $groupEl.setAttribute(attributeNameHyphen, "url(#" + clipPathId + ")");
2703
+ }
2704
+ } else {
2705
+ if (!isTextPath) {
2706
+ // remove clip path
2707
+ $groupEl.removeAttribute(attributeNameHyphen);
2708
+ }
2709
+ }
2710
+ }
2711
+ /**
2712
+ * the origin is bounding box's top left corner
2713
+ */;
2714
+ _proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
2715
+ var _object$elementSVG7, _object$elementSVG8;
2716
+ var bounds = object.getGeometryBounds();
2717
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
2718
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
2719
+ var _ref2 = object.parsedStyle || {},
2720
+ anchor = _ref2.anchor;
3187
2721
  // @ts-ignore
3188
- delete this.context.SVGElementLifeCycleContribution;
3189
- };
3190
- return Plugin;
3191
- }(gLite.AbstractRendererPlugin);
3192
-
3193
- var index_esm$1 = /*#__PURE__*/Object.freeze({
3194
- __proto__: null,
3195
- CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
3196
- DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
3197
- DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
3198
- ElementSVG: ElementSVG,
3199
- G_SVG_PREFIX: G_SVG_PREFIX,
3200
- Plugin: Plugin$1,
3201
- SHAPE2TAGS: SHAPE2TAGS,
3202
- SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
3203
- SVGRendererPlugin: SVGRendererPlugin,
3204
- SVG_ATTR_MAP: SVG_ATTR_MAP,
3205
- TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
3206
- createSVGElement: createSVGElement,
3207
- updateImageElementAttribute: updateImageElementAttribute,
3208
- updateLineElementAttribute: updateLineElementAttribute,
3209
- updatePathElementAttribute: updatePathElementAttribute,
3210
- updatePolylineElementAttribute: updatePolylineElementAttribute,
3211
- updateRectElementAttribute: updateRectElementAttribute,
3212
- updateTextElementAttribute: updateTextElementAttribute
3213
- });
3214
-
3215
- function _regeneratorRuntime$3() {
3216
- _regeneratorRuntime$3 = function _regeneratorRuntime() {
3217
- return exports;
2722
+ [(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
2723
+ if ($el) {
2724
+ var tx = -(anchor[0] * width);
2725
+ var ty = -(anchor[1] * height);
2726
+ if (tx !== 0 || ty !== 0) {
2727
+ // apply anchor to element's `transform` property
2728
+ $el.setAttribute('transform',
2729
+ // can't use percent unit like translate(-50%, -50%)
2730
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
2731
+ "translate(" + tx + "," + ty + ")");
2732
+ }
2733
+ if (object.nodeName === gLite.Shape.CIRCLE || object.nodeName === gLite.Shape.ELLIPSE) {
2734
+ $el.setAttribute('cx', "" + width / 2);
2735
+ $el.setAttribute('cy', "" + height / 2);
2736
+ }
2737
+ }
2738
+ });
3218
2739
  };
3219
- var exports = {},
3220
- Op = Object.prototype,
3221
- hasOwn = Op.hasOwnProperty,
3222
- defineProperty = Object.defineProperty || function (obj, key, desc) {
3223
- obj[key] = desc.value;
3224
- },
3225
- $Symbol = "function" == typeof Symbol ? Symbol : {},
3226
- iteratorSymbol = $Symbol.iterator || "@@iterator",
3227
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
3228
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
3229
- function define(obj, key, value) {
3230
- return Object.defineProperty(obj, key, {
3231
- value: value,
3232
- enumerable: !0,
3233
- configurable: !0,
3234
- writable: !0
3235
- }), obj[key];
3236
- }
3237
- try {
3238
- define({}, "");
3239
- } catch (err) {
3240
- define = function define(obj, key, value) {
3241
- return obj[key] = value;
3242
- };
2740
+ return SVGRendererPlugin;
2741
+ }();
2742
+ SVGRendererPlugin.tag = 'SVGRenderer';
2743
+
2744
+ // @see https://github.com/plouc/nivo/issues/164
2745
+ var BASELINE_MAP = {
2746
+ top: 'hanging',
2747
+ middle: 'central',
2748
+ bottom: 'text-after-edge',
2749
+ alphabetic: 'alphabetic',
2750
+ ideographic: 'ideographic',
2751
+ hanging: 'hanging'
2752
+ };
2753
+ function updateTextElementAttribute($el, parsedStyle, text) {
2754
+ var lineWidth = parsedStyle.lineWidth,
2755
+ dx = parsedStyle.dx,
2756
+ dy = parsedStyle.dy,
2757
+ textPath = parsedStyle.textPath,
2758
+ _parsedStyle$textPath = parsedStyle.textPathSide,
2759
+ textPathSide = _parsedStyle$textPath === void 0 ? 'left' : _parsedStyle$textPath,
2760
+ _parsedStyle$textPath2 = parsedStyle.textPathStartOffset,
2761
+ textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
2762
+ _parsedStyle$textDeco = parsedStyle.textDecorationLine,
2763
+ textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
2764
+ _parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
2765
+ textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
2766
+ _parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
2767
+ textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3,
2768
+ metrics = parsedStyle.metrics;
2769
+ var textBaseline = parsedStyle.textBaseline;
2770
+ if (!gLite.runtime.enableCSSParsing && textBaseline === 'alphabetic') {
2771
+ textBaseline = 'bottom';
3243
2772
  }
3244
- function wrap(innerFn, outerFn, self, tryLocsList) {
3245
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
3246
- generator = Object.create(protoGenerator.prototype),
3247
- context = new Context(tryLocsList || []);
3248
- return defineProperty(generator, "_invoke", {
3249
- value: makeInvokeMethod(innerFn, self, context)
3250
- }), generator;
2773
+ $el.setAttribute('dominant-baseline', BASELINE_MAP[textBaseline]);
2774
+ $el.setAttribute('paint-order', 'stroke');
2775
+ var lines = metrics.lines,
2776
+ lineHeight = metrics.lineHeight,
2777
+ height = metrics.height;
2778
+ var lineNum = lines.length;
2779
+ var styleCSSText = '';
2780
+ if (dx !== 0 || dy !== 0) {
2781
+ styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
3251
2782
  }
3252
- function tryCatch(fn, obj, arg) {
3253
- try {
3254
- return {
3255
- type: "normal",
3256
- arg: fn.call(obj, arg)
3257
- };
3258
- } catch (err) {
3259
- return {
3260
- type: "throw",
3261
- arg: err
3262
- };
3263
- }
2783
+ if (textDecorationLine && textDecorationLine !== 'none') {
2784
+ // use CSS text-decoration since the implementation in SVG is not good enough
2785
+ styleCSSText += "text-decoration:" + textDecorationLine + " " + textDecorationStyle + " " + textDecorationColor + ";";
3264
2786
  }
3265
- exports.wrap = wrap;
3266
- var ContinueSentinel = {};
3267
- function Generator() {}
3268
- function GeneratorFunction() {}
3269
- function GeneratorFunctionPrototype() {}
3270
- var IteratorPrototype = {};
3271
- define(IteratorPrototype, iteratorSymbol, function () {
3272
- return this;
3273
- });
3274
- var getProto = Object.getPrototypeOf,
3275
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
3276
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
3277
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
3278
- function defineIteratorMethods(prototype) {
3279
- ["next", "throw", "return"].forEach(function (method) {
3280
- define(prototype, method, function (arg) {
3281
- return this._invoke(method, arg);
3282
- });
3283
- });
2787
+ if (styleCSSText) {
2788
+ $el.setAttribute('style', styleCSSText);
3284
2789
  }
3285
- function AsyncIterator(generator, PromiseImpl) {
3286
- function invoke(method, arg, resolve, reject) {
3287
- var record = tryCatch(generator[method], generator, arg);
3288
- if ("throw" !== record.type) {
3289
- var result = record.arg,
3290
- value = result.value;
3291
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3292
- invoke("next", value, resolve, reject);
3293
- }, function (err) {
3294
- invoke("throw", err, resolve, reject);
3295
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
3296
- result.value = unwrapped, resolve(result);
3297
- }, function (error) {
3298
- return invoke("throw", error, resolve, reject);
3299
- });
2790
+ if (lineNum === 1) {
2791
+ var textContent = convertHTML(lines[0]);
2792
+ $el.setAttribute('dx', "" + lineWidth / 2);
2793
+ // Since `text-after-edge` is not a standard property value, we use `dy` instead.
2794
+ if (textBaseline === 'bottom' || textBaseline === 'top') {
2795
+ $el.setAttribute('dominant-baseline', 'middle');
2796
+ $el.setAttribute('dy', textBaseline === 'bottom' ? "-0.5em" : '0.5em');
2797
+ }
2798
+ // <textPath> only support one line
2799
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
2800
+ if (textPath) {
2801
+ // clear existed text content first
2802
+ $el.innerHTML = '';
2803
+ // append <textPath href="#MyPath">text</textPath>
2804
+ var $textPath = createSVGElement('textPath', $el.ownerDocument);
2805
+ $textPath.setAttribute('href', "#" + (TEXT_PATH_PREFIX + textPath.entity));
2806
+ if (textPathSide !== 'left') {
2807
+ $textPath.setAttribute('side', textPathSide);
3300
2808
  }
3301
- reject(record.arg);
2809
+ if (textPathStartOffset !== 0) {
2810
+ $textPath.setAttribute('startOffset', "" + textPathStartOffset);
2811
+ }
2812
+ $textPath.innerHTML = textContent;
2813
+ $el.appendChild($textPath);
2814
+ } else {
2815
+ $el.innerHTML = textContent;
3302
2816
  }
3303
- var previousPromise;
3304
- defineProperty(this, "_invoke", {
3305
- value: function value(method, arg) {
3306
- function callInvokeWithMethodAndArg() {
3307
- return new PromiseImpl(function (resolve, reject) {
3308
- invoke(method, arg, resolve, reject);
3309
- });
2817
+ } else {
2818
+ $el.innerHTML = lines.map(function (line, i) {
2819
+ var dx = lineWidth / 2;
2820
+ var dy = 0;
2821
+ if (i === 0) {
2822
+ // TODO: handle other textBaseline values
2823
+ if (textBaseline === 'middle') {
2824
+ dy = lineHeight / 2 - height / 2;
2825
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
2826
+ dy = 0;
2827
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
2828
+ dy = -lineHeight * (lineNum - 1);
3310
2829
  }
3311
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
2830
+ } else {
2831
+ dy = lineHeight;
3312
2832
  }
2833
+ return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
2834
+ }).join('');
2835
+ }
2836
+ }
2837
+ var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
2838
+ var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[gLite.Shape.RECT] = 'path', _SHAPE2TAGS[gLite.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[gLite.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[gLite.Shape.IMAGE] = 'image', _SHAPE2TAGS[gLite.Shape.GROUP] = 'g', _SHAPE2TAGS[gLite.Shape.LINE] = 'line', _SHAPE2TAGS[gLite.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[gLite.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[gLite.Shape.TEXT] = 'text', _SHAPE2TAGS[gLite.Shape.PATH] = 'path', _SHAPE2TAGS[gLite.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
2839
+ var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[gLite.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[gLite.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[gLite.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[gLite.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[gLite.Shape.LINE] = ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYLINE] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYGON] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.PATH] = ['path', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'maxLines', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'textOverflow', 'textPath', 'textPathSide', 'textPathStartOffset', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle',
2840
+ // 'whiteSpace',
2841
+ 'dx', 'dy'], _SHAPE_UPDATE_DEPS);
2842
+ var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
2843
+ function DefaultElementLifeCycleContribution(context) {
2844
+ this.context = void 0;
2845
+ this.context = context;
2846
+ }
2847
+ var _proto = DefaultElementLifeCycleContribution.prototype;
2848
+ _proto.createElement = function createElement(object) {
2849
+ var doc = this.context.config.document;
2850
+ var type = SHAPE2TAGS[object.nodeName] || 'g';
2851
+ return createSVGElement(type, doc || document);
2852
+ };
2853
+ _proto.destroyElement = function destroyElement(object, $el) {};
2854
+ _proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
2855
+ var nodeName = object.nodeName;
2856
+ return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
2857
+ };
2858
+ _proto.updateElementAttribute = function updateElementAttribute(object) {
2859
+ // @ts-ignore
2860
+ var $el = object.elementSVG.$el;
2861
+ var nodeName = object.nodeName,
2862
+ parsedStyle = object.parsedStyle;
2863
+ switch (nodeName) {
2864
+ case gLite.Shape.IMAGE:
2865
+ {
2866
+ updateImageElementAttribute($el, parsedStyle);
2867
+ break;
2868
+ }
2869
+ case gLite.Shape.RECT:
2870
+ {
2871
+ updateRectElementAttribute($el, parsedStyle);
2872
+ break;
2873
+ }
2874
+ case gLite.Shape.LINE:
2875
+ {
2876
+ updateLineElementAttribute($el, parsedStyle);
2877
+ break;
2878
+ }
2879
+ case gLite.Shape.POLYGON:
2880
+ case gLite.Shape.POLYLINE:
2881
+ {
2882
+ updatePolylineElementAttribute($el, parsedStyle);
2883
+ break;
2884
+ }
2885
+ case gLite.Shape.PATH:
2886
+ {
2887
+ updatePathElementAttribute($el, parsedStyle);
2888
+ break;
2889
+ }
2890
+ case gLite.Shape.TEXT:
2891
+ {
2892
+ updateTextElementAttribute($el, parsedStyle);
2893
+ break;
2894
+ }
2895
+ }
2896
+ };
2897
+ return DefaultElementLifeCycleContribution;
2898
+ }();
2899
+ var FILTER_PREFIX = 'g-filter-';
2900
+ /**
2901
+ * use SVG filters, eg. blur, brightness, contrast...
2902
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2903
+ */
2904
+ function createOrUpdateFilter(document, $def, object, $el, filters) {
2905
+ // eg. filter="url(#f1) url(#f2)"
2906
+ var filterName = FILTER_PREFIX + object.entity;
2907
+ var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
2908
+ if ($existedFilters.length) {
2909
+ $existedFilters.forEach(function ($filter) {
2910
+ $def.removeChild($filter);
3313
2911
  });
3314
2912
  }
3315
- function makeInvokeMethod(innerFn, self, context) {
3316
- var state = "suspendedStart";
3317
- return function (method, arg) {
3318
- if ("executing" === state) throw new Error("Generator is already running");
3319
- if ("completed" === state) {
3320
- if ("throw" === method) throw arg;
3321
- return doneResult();
3322
- }
3323
- for (context.method = method, context.arg = arg;;) {
3324
- var delegate = context.delegate;
3325
- if (delegate) {
3326
- var delegateResult = maybeInvokeDelegate(delegate, context);
3327
- if (delegateResult) {
3328
- if (delegateResult === ContinueSentinel) continue;
3329
- return delegateResult;
3330
- }
3331
- }
3332
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
3333
- if ("suspendedStart" === state) throw state = "completed", context.arg;
3334
- context.dispatchException(context.arg);
3335
- } else "return" === context.method && context.abrupt("return", context.arg);
3336
- state = "executing";
3337
- var record = tryCatch(innerFn, self, context);
3338
- if ("normal" === record.type) {
3339
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
3340
- return {
3341
- value: record.arg,
3342
- done: context.done
3343
- };
3344
- }
3345
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
2913
+ if (filters.length === 0) {
2914
+ // 'none'
2915
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2916
+ } else {
2917
+ var filterIds = filters.map(function (_ref, i) {
2918
+ var name = _ref.name,
2919
+ params = _ref.params;
2920
+ var $filter = createSVGElement('filter', document);
2921
+ // @see https://github.com/antvis/g/issues/1025
2922
+ $filter.setAttribute('filterUnits', 'userSpaceOnUse');
2923
+ if (name === 'blur') {
2924
+ createBlur(document, $filter, params);
2925
+ } else if (name === 'brightness') {
2926
+ createBrightness(document, $filter, params);
2927
+ } else if (name === 'drop-shadow') {
2928
+ createDropShadow(document, $filter, params);
2929
+ } else if (name === 'contrast') {
2930
+ createContrast(document, $filter, params);
2931
+ } else if (name === 'grayscale') {
2932
+ createGrayscale(document, $filter, params);
2933
+ } else if (name === 'sepia') {
2934
+ createSepia(document, $filter, params);
2935
+ } else if (name === 'saturate') {
2936
+ createSaturate(document, $filter, params);
2937
+ } else if (name === 'hue-rotate') {
2938
+ createHueRotate(document, $filter, params);
2939
+ } else if (name === 'invert') {
2940
+ createInvert(document, $filter, params);
3346
2941
  }
3347
- };
2942
+ $filter.id = filterName + "-" + i;
2943
+ $filter.setAttribute('name', filterName);
2944
+ $def.appendChild($filter);
2945
+ return $filter.id;
2946
+ });
2947
+ // @see https://github.com/antvis/G/issues/1114
2948
+ setTimeout(function () {
2949
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
2950
+ return "url(#" + filterId + ")";
2951
+ }).join(' '));
2952
+ });
3348
2953
  }
3349
- function maybeInvokeDelegate(delegate, context) {
3350
- var methodName = context.method,
3351
- method = delegate.iterator[methodName];
3352
- if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
3353
- var record = tryCatch(method, delegate.iterator, context.arg);
3354
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
3355
- var info = record.arg;
3356
- 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);
2954
+ }
2955
+ function convertToAbsoluteValue(param) {
2956
+ return param.unit === gLite.UnitType.kPercentage ? param.value / 100 : param.value;
2957
+ }
2958
+ /**
2959
+ * @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
2960
+ */
2961
+ function createBlur(document, $filter, params) {
2962
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2963
+ $feGaussianBlur.setAttribute('in', 'SourceGraphic');
2964
+ $feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
2965
+ $filter.appendChild($feGaussianBlur);
2966
+ }
2967
+ function createFeComponentTransfer(document, $filter, _ref2) {
2968
+ var type = _ref2.type,
2969
+ slope = _ref2.slope,
2970
+ intercept = _ref2.intercept,
2971
+ tableValues = _ref2.tableValues;
2972
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
2973
+ [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
2974
+ $feFunc.setAttribute('type', type);
2975
+ if (type === 'table') {
2976
+ $feFunc.setAttribute('tableValues', "" + tableValues);
2977
+ } else {
2978
+ $feFunc.setAttribute('slope', "" + slope);
2979
+ $feFunc.setAttribute('intercept', "" + intercept);
2980
+ }
2981
+ $feComponentTransfer.appendChild($feFunc);
2982
+ });
2983
+ $filter.appendChild($feComponentTransfer);
2984
+ }
2985
+ function createContrast(document, $filter, params) {
2986
+ var slope = convertToAbsoluteValue(params[0]);
2987
+ createFeComponentTransfer(document, $filter, {
2988
+ type: 'linear',
2989
+ slope: slope,
2990
+ intercept: -(0.5 * slope) + 0.5
2991
+ });
2992
+ }
2993
+ function createInvert(document, $filter, params) {
2994
+ var amount = convertToAbsoluteValue(params[0]);
2995
+ createFeComponentTransfer(document, $filter, {
2996
+ type: 'table',
2997
+ tableValues: amount + " " + (1 - amount)
2998
+ });
2999
+ }
3000
+ function createBrightness(document, $filter, params) {
3001
+ var slope = convertToAbsoluteValue(params[0]);
3002
+ createFeComponentTransfer(document, $filter, {
3003
+ type: 'linear',
3004
+ slope: slope,
3005
+ intercept: 0
3006
+ });
3007
+ }
3008
+ function createSaturate(document, $filter, params) {
3009
+ var amount = convertToAbsoluteValue(params[0]);
3010
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
3011
+ $feColorMatrix.setAttribute('type', 'saturate');
3012
+ $feColorMatrix.setAttribute('values', "" + amount);
3013
+ $filter.appendChild($feColorMatrix);
3014
+ }
3015
+ function createHueRotate(document, $filter, params) {
3016
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
3017
+ $feColorMatrix.setAttribute('type', 'hueRotate');
3018
+ // $feColorMatrix.setAttribute('values', `${params[0].to(UnitType.kDegrees).value}`);
3019
+ // FIXME: convert to degrees
3020
+ $feColorMatrix.setAttribute('values', "" + params[0].value);
3021
+ $filter.appendChild($feColorMatrix);
3022
+ }
3023
+ function createDropShadow(document, $filter, params) {
3024
+ var shadowOffsetX = params[0].value;
3025
+ var shadowOffsetY = params[1].value;
3026
+ var shadowBlur = params[2].value;
3027
+ // @ts-ignore
3028
+ var shadowColor = params[3].formatted;
3029
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
3030
+ $feGaussianBlur.setAttribute('in', 'SourceAlpha');
3031
+ $feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
3032
+ $filter.appendChild($feGaussianBlur);
3033
+ var $feOffset = createSVGElement('feOffset', document);
3034
+ $feOffset.setAttribute('dx', "" + shadowOffsetX);
3035
+ $feOffset.setAttribute('dy', "" + shadowOffsetY);
3036
+ $feOffset.setAttribute('result', 'offsetblur');
3037
+ $filter.appendChild($feOffset);
3038
+ var $feFlood = createSVGElement('feFlood', document);
3039
+ $feFlood.setAttribute('flood-color', shadowColor);
3040
+ $filter.appendChild($feFlood);
3041
+ var $feComposite = createSVGElement('feComposite', document);
3042
+ $feComposite.setAttribute('in2', 'offsetblur');
3043
+ $feComposite.setAttribute('operator', 'in');
3044
+ $filter.appendChild($feComposite);
3045
+ var $feMerge = createSVGElement('feMerge', document);
3046
+ $filter.appendChild($feMerge);
3047
+ var $feMergeNode1 = createSVGElement('feMergeNode', document);
3048
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
3049
+ $feMergeNode2.setAttribute('in', 'SourceGraphic');
3050
+ $feMerge.appendChild($feMergeNode1);
3051
+ $feMerge.appendChild($feMergeNode2);
3052
+ }
3053
+ function createFeColorMatrix(document, $filter, matrix) {
3054
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
3055
+ $feColorMatrix.setAttribute('type', 'matrix');
3056
+ $feColorMatrix.setAttribute('values', matrix.join(' '));
3057
+ $filter.appendChild($feColorMatrix);
3058
+ }
3059
+ /**
3060
+ * @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
3061
+ */
3062
+ function createGrayscale(document, $filter, params) {
3063
+ var amount = convertToAbsoluteValue(params[0]);
3064
+ createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
3065
+ }
3066
+ /**
3067
+ * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
3068
+ */
3069
+ function createSepia(document, $filter, params) {
3070
+ var amount = convertToAbsoluteValue(params[0]);
3071
+ createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
3072
+ }
3073
+ var PATTERN_PREFIX = 'g-pattern-';
3074
+ var cacheKey2IDMap = {};
3075
+ var counter = 0;
3076
+ function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage, plugin) {
3077
+ // eg. clipPath don't have fill/stroke
3078
+ if (!parsedColor) {
3079
+ return '';
3357
3080
  }
3358
- function pushTryEntry(locs) {
3359
- var entry = {
3360
- tryLoc: locs[0]
3361
- };
3362
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
3081
+ if (gLite.isCSSRGB(parsedColor)) {
3082
+ // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
3083
+ if (object.style[name] === 'currentColor') {
3084
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
3085
+ } else {
3086
+ // constant value, eg. '#fff'
3087
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
3088
+ }
3089
+ } else if (gLite.isPattern(parsedColor)) {
3090
+ var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage, plugin);
3091
+ // use style instead of attribute when applying <pattern>
3092
+ // @see https://stackoverflow.com/a/7723115
3093
+ $el.style[name] = "url(#" + patternId + ")";
3094
+ return patternId;
3095
+ } else {
3096
+ if (parsedColor.length === 1) {
3097
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
3098
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
3099
+ return gradientId;
3100
+ } else {
3101
+ // @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
3102
+ var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
3103
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
3104
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
3105
+ return filterId;
3106
+ }
3363
3107
  }
3364
- function resetTryEntry(entry) {
3365
- var record = entry.completion || {};
3366
- record.type = "normal", delete record.arg, entry.completion = record;
3108
+ return '';
3109
+ }
3110
+ function generateCacheKey(src, options) {
3111
+ if (options === void 0) {
3112
+ options = {};
3113
+ }
3114
+ var cacheKey = '';
3115
+ if (gLite.isCSSGradientValue(src)) {
3116
+ var type = src.type,
3117
+ value = src.value;
3118
+ if (type === gLite.GradientType.LinearGradient || type === gLite.GradientType.RadialGradient) {
3119
+ // @ts-ignore
3120
+ var _value$options = _extends({}, value, options),
3121
+ _type = _value$options.type,
3122
+ width = _value$options.width,
3123
+ height = _value$options.height,
3124
+ steps = _value$options.steps,
3125
+ angle = _value$options.angle,
3126
+ cx = _value$options.cx,
3127
+ cy = _value$options.cy,
3128
+ size = _value$options.size;
3129
+ cacheKey = "gradient-" + _type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref) {
3130
+ var offset = _ref.offset,
3131
+ color = _ref.color;
3132
+ return "" + offset + color;
3133
+ }).join('-');
3134
+ }
3135
+ } else if (gLite.isPattern(src)) {
3136
+ if (isString(src.image)) {
3137
+ cacheKey = "pattern-" + src.image + "-" + src.repetition;
3138
+ } else if (src.image.nodeName === 'rect') {
3139
+ // use rect's entity as key
3140
+ cacheKey = "pattern-rect-" + src.image.entity;
3141
+ } else {
3142
+ cacheKey = "pattern-" + counter;
3143
+ }
3367
3144
  }
3368
- function Context(tryLocsList) {
3369
- this.tryEntries = [{
3370
- tryLoc: "root"
3371
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
3145
+ if (cacheKey) {
3146
+ if (!cacheKey2IDMap[cacheKey]) {
3147
+ cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
3148
+ }
3372
3149
  }
3373
- function values(iterable) {
3374
- if (iterable) {
3375
- var iteratorMethod = iterable[iteratorSymbol];
3376
- if (iteratorMethod) return iteratorMethod.call(iterable);
3377
- if ("function" == typeof iterable.next) return iterable;
3378
- if (!isNaN(iterable.length)) {
3379
- var i = -1,
3380
- next = function next() {
3381
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
3382
- return next.value = undefined, next.done = !0, next;
3383
- };
3384
- return next.next = next;
3385
- }
3150
+ return cacheKey2IDMap[cacheKey];
3151
+ }
3152
+ function formatTransform(transform) {
3153
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/patternTransform
3154
+ // should remove unit: rotate(20deg) -> rotate(20)
3155
+ return gLite.parseTransform(transform).map(function (parsed) {
3156
+ var t = parsed.t,
3157
+ d = parsed.d;
3158
+ if (t === 'translate') {
3159
+ return "translate(" + d[0].value + " " + d[1].value + ")";
3160
+ } else if (t === 'translatex') {
3161
+ return "translate(" + d[0].value + " 0)";
3162
+ } else if (t === 'translatey') {
3163
+ return "translate(0 " + d[0].value + ")";
3164
+ } else if (t === 'rotate') {
3165
+ return "rotate(" + d[0].value + ")";
3166
+ } else if (t === 'scale') {
3167
+ // scale(1) scale(1, 1)
3168
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3169
+ return s.value;
3170
+ })) || [1, 1];
3171
+ return "scale(" + newScale[0] + ", " + newScale[1] + ")";
3172
+ } else if (t === 'scalex') {
3173
+ var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3174
+ return s.value;
3175
+ })) || [1];
3176
+ return "scale(" + _newScale[0] + ", 1)";
3177
+ } else if (t === 'scaley') {
3178
+ var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3179
+ return s.value;
3180
+ })) || [1];
3181
+ return "scale(1, " + _newScale2[0] + ")";
3182
+ } else if (t === 'skew') {
3183
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3184
+ return s.value;
3185
+ })) || [0, 0];
3186
+ return "skewX(" + newSkew[0] + ") skewY(" + newSkew[1] + ")";
3187
+ } else if (t === 'skewx') {
3188
+ var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3189
+ return s.value;
3190
+ })) || [0];
3191
+ return "skewX(" + _newSkew[0] + ")";
3192
+ } else if (t === 'skewy') {
3193
+ var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
3194
+ return s.value;
3195
+ })) || [0];
3196
+ return "skewY(" + _newSkew2[0] + ")";
3197
+ } else if (t === 'matrix') {
3198
+ var _d$map = d.map(function (s) {
3199
+ return s.value;
3200
+ }),
3201
+ a = _d$map[0],
3202
+ b = _d$map[1],
3203
+ c = _d$map[2],
3204
+ dd = _d$map[3],
3205
+ tx = _d$map[4],
3206
+ ty = _d$map[5];
3207
+ return "matrix(" + a + " " + b + " " + c + " " + dd + " " + tx + " " + ty + ")";
3386
3208
  }
3387
- return {
3388
- next: doneResult
3389
- };
3209
+ }).join(' ');
3210
+ }
3211
+ function create$Pattern(document, $def, object, pattern, patternId, width, height) {
3212
+ var repetition = pattern.repetition,
3213
+ transform = pattern.transform;
3214
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
3215
+ var $pattern = createSVGElement('pattern', document);
3216
+ if (transform) {
3217
+ $pattern.setAttribute('patternTransform', formatTransform(transform));
3390
3218
  }
3391
- function doneResult() {
3392
- return {
3393
- value: undefined,
3394
- done: !0
3395
- };
3219
+ $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
3220
+ $pattern.id = patternId;
3221
+ $def.appendChild($pattern);
3222
+ $pattern.setAttribute('x', '0');
3223
+ $pattern.setAttribute('y', '0');
3224
+ var _object$getGeometryBo = object.getGeometryBounds(),
3225
+ halfExtents = _object$getGeometryBo.halfExtents;
3226
+ // There is no equivalent to CSS no-repeat for SVG patterns
3227
+ // @see https://stackoverflow.com/a/33481956
3228
+ var patternWidth = width;
3229
+ var patternHeight = height;
3230
+ if (repetition === 'repeat-x') {
3231
+ patternHeight = halfExtents[1] * 2;
3232
+ } else if (repetition === 'repeat-y') {
3233
+ patternWidth = halfExtents[0] * 2;
3234
+ } else if (repetition === 'no-repeat') {
3235
+ patternWidth = halfExtents[0] * 2;
3236
+ patternHeight = halfExtents[1] * 2;
3396
3237
  }
3397
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
3398
- value: GeneratorFunctionPrototype,
3399
- configurable: !0
3400
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
3401
- value: GeneratorFunction,
3402
- configurable: !0
3403
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
3404
- var ctor = "function" == typeof genFun && genFun.constructor;
3405
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
3406
- }, exports.mark = function (genFun) {
3407
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
3408
- }, exports.awrap = function (arg) {
3409
- return {
3410
- __await: arg
3411
- };
3412
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
3413
- return this;
3414
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
3415
- void 0 === PromiseImpl && (PromiseImpl = Promise);
3416
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
3417
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
3418
- return result.done ? result.value : iter.next();
3419
- });
3420
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
3421
- return this;
3422
- }), define(Gp, "toString", function () {
3423
- return "[object Generator]";
3424
- }), exports.keys = function (val) {
3425
- var object = Object(val),
3426
- keys = [];
3427
- for (var key in object) keys.push(key);
3428
- return keys.reverse(), function next() {
3429
- for (; keys.length;) {
3430
- var key = keys.pop();
3431
- if (key in object) return next.value = key, next.done = !1, next;
3432
- }
3433
- return next.done = !0, next;
3434
- };
3435
- }, exports.values = values, Context.prototype = {
3436
- constructor: Context,
3437
- reset: function reset(skipTempReset) {
3438
- 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) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
3439
- },
3440
- stop: function stop() {
3441
- this.done = !0;
3442
- var rootRecord = this.tryEntries[0].completion;
3443
- if ("throw" === rootRecord.type) throw rootRecord.arg;
3444
- return this.rval;
3445
- },
3446
- dispatchException: function dispatchException(exception) {
3447
- if (this.done) throw exception;
3448
- var context = this;
3449
- function handle(loc, caught) {
3450
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
3451
- }
3452
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3453
- var entry = this.tryEntries[i],
3454
- record = entry.completion;
3455
- if ("root" === entry.tryLoc) return handle("end");
3456
- if (entry.tryLoc <= this.prev) {
3457
- var hasCatch = hasOwn.call(entry, "catchLoc"),
3458
- hasFinally = hasOwn.call(entry, "finallyLoc");
3459
- if (hasCatch && hasFinally) {
3460
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
3461
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
3462
- } else if (hasCatch) {
3463
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
3464
- } else {
3465
- if (!hasFinally) throw new Error("try statement without catch or finally");
3466
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
3467
- }
3468
- }
3238
+ $pattern.setAttribute('width', "" + patternWidth);
3239
+ $pattern.setAttribute('height', "" + patternHeight);
3240
+ return $pattern;
3241
+ }
3242
+ function createOrUpdatePattern(document, $def, object, pattern, createImage, plugin) {
3243
+ var patternId = generateCacheKey(pattern);
3244
+ var $existed = $def.querySelector("#" + patternId);
3245
+ if (!$existed) {
3246
+ var image = pattern.image;
3247
+ var imageURL = '';
3248
+ if (isString(image)) {
3249
+ imageURL = image;
3250
+ } else {
3251
+ if (gLite.isBrowser) {
3252
+ if (image instanceof HTMLImageElement) {
3253
+ imageURL = image.src;
3254
+ } else if (image instanceof HTMLCanvasElement) {
3255
+ imageURL = image.toDataURL();
3256
+ } else ;
3469
3257
  }
3470
- },
3471
- abrupt: function abrupt(type, arg) {
3472
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3473
- var entry = this.tryEntries[i];
3474
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
3475
- var finallyEntry = entry;
3476
- break;
3477
- }
3258
+ }
3259
+ if (imageURL) {
3260
+ var $image = createSVGElement('image', document);
3261
+ // use href instead of xlink:href
3262
+ // @see https://stackoverflow.com/a/13379007
3263
+ $image.setAttribute('href', imageURL);
3264
+ var img;
3265
+ if (createImage) {
3266
+ img = createImage(imageURL);
3267
+ } else if (gLite.isBrowser) {
3268
+ img = new window.Image();
3478
3269
  }
3479
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
3480
- var record = finallyEntry ? finallyEntry.completion : {};
3481
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
3482
- },
3483
- complete: function complete(record, afterLoc) {
3484
- if ("throw" === record.type) throw record.arg;
3485
- 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;
3486
- },
3487
- finish: function finish(finallyLoc) {
3488
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3489
- var entry = this.tryEntries[i];
3490
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
3270
+ if (!imageURL.match(/^data:/i)) {
3271
+ img.crossOrigin = 'Anonymous';
3272
+ $image.setAttribute('crossorigin', 'anonymous');
3491
3273
  }
3492
- },
3493
- catch: function _catch(tryLoc) {
3494
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3495
- var entry = this.tryEntries[i];
3496
- if (entry.tryLoc === tryLoc) {
3497
- var record = entry.completion;
3498
- if ("throw" === record.type) {
3499
- var thrown = record.arg;
3500
- resetTryEntry(entry);
3501
- }
3502
- return thrown;
3503
- }
3274
+ img.src = imageURL;
3275
+ var onload = function onload() {
3276
+ var $pattern = create$Pattern(document, $def, object, pattern, patternId, img.width, img.height);
3277
+ $def.appendChild($pattern);
3278
+ $pattern.appendChild($image);
3279
+ $image.setAttribute('x', '0');
3280
+ $image.setAttribute('y', '0');
3281
+ $image.setAttribute('width', "" + img.width);
3282
+ $image.setAttribute('height', "" + img.height);
3283
+ };
3284
+ if (img.complete) {
3285
+ onload();
3286
+ } else {
3287
+ img.onload = onload;
3288
+ // Fix onload() bug in IE9
3289
+ // img.src = img.src;
3504
3290
  }
3505
- throw new Error("illegal catch attempt");
3506
- },
3507
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
3508
- return this.delegate = {
3509
- iterator: values(iterable),
3510
- resultName: resultName,
3511
- nextLoc: nextLoc
3512
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
3513
3291
  }
3514
- }, exports;
3292
+
3293
+ if (image.nodeName === 'rect') {
3294
+ var _image$parsedStyle = image.parsedStyle,
3295
+ width = _image$parsedStyle.width,
3296
+ height = _image$parsedStyle.height;
3297
+ var $pattern = create$Pattern(document, $def, image, pattern, patternId, width, height);
3298
+ // traverse subtree of pattern
3299
+ image.forEach(function (object) {
3300
+ plugin.createSVGDom(document, object, null);
3301
+ // @ts-ignore
3302
+ var svgElement = object.elementSVG;
3303
+ // apply local RTS transformation to <group> wrapper
3304
+ // account for anchor
3305
+ var localTransform = object.getLocalTransform();
3306
+ plugin.applyTransform(svgElement.$groupEl, localTransform);
3307
+ });
3308
+ // @ts-ignore
3309
+ var svgElement = image.elementSVG;
3310
+ $pattern.appendChild(svgElement.$groupEl);
3311
+ }
3312
+ }
3313
+ return patternId;
3515
3314
  }
3516
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
3517
- try {
3518
- var info = gen[key](arg);
3519
- var value = info.value;
3520
- } catch (error) {
3521
- reject(error);
3315
+ function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
3316
+ var bounds = object.getGeometryBounds();
3317
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
3318
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3319
+ var gradientId = generateCacheKey(parsedColor, {
3320
+ width: width,
3321
+ height: height
3322
+ });
3323
+ var $existed = $def.querySelector("#" + gradientId);
3324
+ if (!$existed) {
3325
+ // <linearGradient> <radialGradient>
3326
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
3327
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
3328
+ $existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document);
3329
+ // @see https://github.com/antvis/g/issues/1025
3330
+ $existed.setAttribute('gradientUnits', 'userSpaceOnUse');
3331
+ // add stops
3332
+ var innerHTML = '';
3333
+ parsedColor.value.steps
3334
+ // sort by offset @see https://github.com/antvis/G/issues/1171
3335
+ .sort(function (a, b) {
3336
+ return a.offset.value - b.offset.value;
3337
+ }).forEach(function (_ref2) {
3338
+ var offset = _ref2.offset,
3339
+ color = _ref2.color;
3340
+ // TODO: support absolute unit like `px`
3341
+ innerHTML += "<stop offset=\"" + offset.value / 100 + "\" stop-color=\"" + color + "\"></stop>";
3342
+ });
3343
+ $existed.innerHTML = innerHTML;
3344
+ $existed.id = gradientId;
3345
+ $def.appendChild($existed);
3346
+ }
3347
+ if (parsedColor.type === gLite.GradientType.LinearGradient) {
3348
+ var angle = parsedColor.value.angle;
3349
+ var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
3350
+ x1 = _computeLinearGradien.x1,
3351
+ y1 = _computeLinearGradien.y1,
3352
+ x2 = _computeLinearGradien.x2,
3353
+ y2 = _computeLinearGradien.y2;
3354
+ $existed.setAttribute('x1', "" + x1);
3355
+ $existed.setAttribute('y1', "" + y1);
3356
+ $existed.setAttribute('x2', "" + x2);
3357
+ $existed.setAttribute('y2', "" + y2);
3358
+ // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
3359
+ } else {
3360
+ var _parsedColor$value = parsedColor.value,
3361
+ cx = _parsedColor$value.cx,
3362
+ cy = _parsedColor$value.cy,
3363
+ size = _parsedColor$value.size;
3364
+ var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
3365
+ x = _computeRadialGradien.x,
3366
+ y = _computeRadialGradien.y,
3367
+ r = _computeRadialGradien.r;
3368
+ $existed.setAttribute('cx', "" + x);
3369
+ $existed.setAttribute('cy', "" + y);
3370
+ $existed.setAttribute('r', "" + r);
3371
+ }
3372
+ return gradientId;
3373
+ }
3374
+ function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
3375
+ var filterId = FILTER_PREFIX + object.entity + '-gradient';
3376
+ var $existed = $def.querySelector("#" + filterId);
3377
+ if (!$existed) {
3378
+ $existed = createSVGElement('filter', document);
3379
+ $existed.setAttribute('filterUnits', 'userSpaceOnUse');
3380
+ // @see https://github.com/antvis/g/issues/1025
3381
+ $existed.setAttribute('x', '0%');
3382
+ $existed.setAttribute('y', '0%');
3383
+ $existed.setAttribute('width', '100%');
3384
+ $existed.setAttribute('height', '100%');
3385
+ $existed.id = filterId;
3386
+ $def.appendChild($existed);
3387
+ }
3388
+ /**
3389
+ * <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
3390
+ * <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
3391
+ <feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
3392
+ <feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
3393
+ <feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
3394
+ <feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
3395
+ </filter>
3396
+ */
3397
+ var blended = 0;
3398
+ gradients.forEach(function (gradient, i) {
3399
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
3400
+ var rectId = gradientId + '_rect';
3401
+ var $rect = createSVGElement('rect', document);
3402
+ $rect.setAttribute('x', '0');
3403
+ $rect.setAttribute('y', '0');
3404
+ $rect.setAttribute('width', '100%');
3405
+ $rect.setAttribute('height', '100%');
3406
+ $rect.setAttribute('fill', "url(#" + gradientId + ")");
3407
+ $rect.id = rectId;
3408
+ $def.appendChild($rect);
3409
+ var $feImage = createSVGElement('feImage', document);
3410
+ $feImage.setAttribute('href', "#" + rectId);
3411
+ $feImage.setAttribute('result', filterId + "-" + i);
3412
+ $existed.appendChild($feImage);
3413
+ if (i > 0) {
3414
+ var $feBlend = createSVGElement('feBlend', document);
3415
+ $feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
3416
+ $feBlend.setAttribute('in2', filterId + "-" + i);
3417
+ $feBlend.setAttribute('result', filterId + "-blended-" + blended++);
3418
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
3419
+ $feBlend.setAttribute('mode', 'multiply');
3420
+ $existed.appendChild($feBlend);
3421
+ }
3422
+ });
3423
+ var $feComposite = createSVGElement('feComposite', document);
3424
+ $feComposite.setAttribute('in', filterId + "-blended-" + blended);
3425
+ $feComposite.setAttribute('in2', 'SourceGraphic');
3426
+ $feComposite.setAttribute('operator', 'in');
3427
+ $existed.appendChild($feComposite);
3428
+ return filterId;
3429
+ }
3430
+ var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
3431
+ /**
3432
+ * use SVG filters
3433
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
3434
+ */
3435
+ function createOrUpdateShadow(document, $def, object, $el, name) {
3436
+ var _object$parsedStyle = object.parsedStyle,
3437
+ shadowType = _object$parsedStyle.shadowType,
3438
+ shadowBlur = _object$parsedStyle.shadowBlur,
3439
+ shadowColor = _object$parsedStyle.shadowColor,
3440
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
3441
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY;
3442
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3443
+ var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
3444
+ var $existedFilter = $def.querySelector("#" + shadowId);
3445
+ if ($existedFilter) {
3446
+ var existedShadowType = $existedFilter.getAttribute('data-type');
3447
+ if (existedShadowType !== shadowType || !hasShadow) {
3448
+ // remove existed shadow
3449
+ $existedFilter.remove();
3450
+ $existedFilter = null;
3451
+ }
3452
+ }
3453
+ // <Group> also has shadowType as its default value
3454
+ // only apply shadow when blur > 0
3455
+ if (hasShadow) {
3456
+ // use filter <feDropShadow>
3457
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
3458
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
3459
+ } else {
3460
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
3461
+ return;
3462
+ }
3463
+ if (!$existedFilter) {
3464
+ $existedFilter = createSVGElement('filter', document);
3465
+ $existedFilter.setAttribute('data-type', shadowType);
3466
+ if (shadowType === 'outer') {
3467
+ var $feDropShadow = createSVGElement('feDropShadow', document);
3468
+ $feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3469
+ $feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3470
+ $feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3471
+ $feDropShadow.setAttribute('flood-color', shadowColor.toString());
3472
+ $existedFilter.appendChild($feDropShadow);
3473
+ } else if (shadowType === 'inner') {
3474
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
3475
+ $feComponentTransfer.setAttribute('in', 'SourceAlpha');
3476
+ var $feFuncA = createSVGElement('feFuncA', document);
3477
+ $feFuncA.setAttribute('type', 'table');
3478
+ $feFuncA.setAttribute('tableValues', '1 0');
3479
+ $feComponentTransfer.appendChild($feFuncA);
3480
+ $existedFilter.appendChild($feComponentTransfer);
3481
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
3482
+ $feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3483
+ $existedFilter.appendChild($feGaussianBlur);
3484
+ var $feOffset = createSVGElement('feOffset', document);
3485
+ $feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3486
+ $feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3487
+ $feOffset.setAttribute('result', 'offsetblur');
3488
+ $existedFilter.appendChild($feOffset);
3489
+ var $feFlood = createSVGElement('feFlood', document);
3490
+ $feFlood.setAttribute('flood-color', shadowColor.toString());
3491
+ $feFlood.setAttribute('result', 'color');
3492
+ $existedFilter.appendChild($feFlood);
3493
+ var $feComposite = createSVGElement('feComposite', document);
3494
+ $feComposite.setAttribute('in2', 'offsetblur');
3495
+ $feComposite.setAttribute('operator', 'in');
3496
+ $existedFilter.appendChild($feComposite);
3497
+ var $feComposite2 = createSVGElement('feComposite', document);
3498
+ $feComposite2.setAttribute('in2', 'SourceAlpha');
3499
+ $feComposite2.setAttribute('operator', 'in');
3500
+ $existedFilter.appendChild($feComposite2);
3501
+ var $feMerge = createSVGElement('feMerge', document);
3502
+ $existedFilter.appendChild($feMerge);
3503
+ var $feMergeNode = createSVGElement('feMergeNode', document);
3504
+ $feMergeNode.setAttribute('in', 'SourceGraphic');
3505
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
3506
+ $feMerge.appendChild($feMergeNode);
3507
+ $feMerge.appendChild($feMergeNode2);
3508
+ }
3509
+ $existedFilter.id = shadowId;
3510
+ // @see https://github.com/antvis/g/issues/1025
3511
+ $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
3512
+ $def.appendChild($existedFilter);
3522
3513
  return;
3523
3514
  }
3524
- if (info.done) {
3525
- resolve(value);
3526
- } else {
3527
- Promise.resolve(value).then(_next, _throw);
3515
+ if (shadowType === 'inner') {
3516
+ var _$feGaussianBlur = $existedFilter.children[1];
3517
+ var _$feOffset = $existedFilter.children[2];
3518
+ var _$feFlood = $existedFilter.children[3];
3519
+ if (name === 'shadowColor') {
3520
+ _$feFlood.setAttribute('flood-color', shadowColor.toString());
3521
+ } else if (name === 'shadowBlur') {
3522
+ // half the blur radius
3523
+ // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
3524
+ // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
3525
+ _$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3526
+ } else if (name === 'shadowOffsetX') {
3527
+ _$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3528
+ } else if (name === 'shadowOffsetY') {
3529
+ _$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3530
+ }
3531
+ } else if (shadowType === 'outer') {
3532
+ var _$feDropShadow = $existedFilter.children[0];
3533
+ if (name === 'shadowColor') {
3534
+ _$feDropShadow.setAttribute('flood-color', shadowColor.toString());
3535
+ } else if (name === 'shadowBlur') {
3536
+ // half the blur radius
3537
+ // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
3538
+ // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
3539
+ _$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
3540
+ } else if (name === 'shadowOffsetX') {
3541
+ _$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
3542
+ } else if (name === 'shadowOffsetY') {
3543
+ _$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
3544
+ }
3528
3545
  }
3529
3546
  }
3530
- function _asyncToGenerator$3(fn) {
3531
- return function () {
3532
- var self = this,
3533
- args = arguments;
3534
- return new Promise(function (resolve, reject) {
3535
- var gen = fn.apply(self, args);
3536
- function _next(value) {
3537
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
3538
- }
3539
- function _throw(err) {
3540
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3541
- }
3542
- _next(undefined);
3543
- });
3547
+ var urlRegexp = /url\("?#(.*)\)/;
3548
+ var DefElementManager = /*#__PURE__*/function () {
3549
+ function DefElementManager(context) {
3550
+ this.context = void 0;
3551
+ /**
3552
+ * container for <gradient> <clipPath>...
3553
+ */
3554
+ this.$def = void 0;
3555
+ this.gradientCache = {};
3556
+ this.context = context;
3557
+ }
3558
+ var _proto = DefElementManager.prototype;
3559
+ _proto.getDefElement = function getDefElement() {
3560
+ return this.$def;
3544
3561
  };
3545
- }
3546
- function _inheritsLoose$3(subClass, superClass) {
3547
- subClass.prototype = Object.create(superClass.prototype);
3548
- subClass.prototype.constructor = subClass;
3549
- _setPrototypeOf$3(subClass, superClass);
3550
- }
3551
- function _setPrototypeOf$3(o, p) {
3552
- _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3553
- o.__proto__ = p;
3554
- return o;
3562
+ _proto.init = function init() {
3563
+ var document = this.context.config.document;
3564
+ var $svg = this.context.contextService.getContext();
3565
+ this.$def = createSVGElement('defs', document);
3566
+ $svg.appendChild(this.$def);
3555
3567
  };
3556
- return _setPrototypeOf$3(o, p);
3557
- }
3558
- function _unsupportedIterableToArray(o, minLen) {
3559
- if (!o) return;
3560
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
3561
- var n = Object.prototype.toString.call(o).slice(8, -1);
3562
- if (n === "Object" && o.constructor) n = o.constructor.name;
3563
- if (n === "Map" || n === "Set") return Array.from(o);
3564
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
3565
- }
3566
- function _arrayLikeToArray(arr, len) {
3567
- if (len == null || len > arr.length) len = arr.length;
3568
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
3569
- return arr2;
3570
- }
3571
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
3572
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
3573
- if (it) return (it = it.call(o)).next.bind(it);
3574
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
3575
- if (it) o = it;
3576
- var i = 0;
3577
- return function () {
3578
- if (i >= o.length) return {
3579
- done: true
3580
- };
3581
- return {
3582
- done: false,
3583
- value: o[i++]
3584
- };
3585
- };
3586
- }
3587
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3588
- }
3589
-
3590
- /**
3591
- * pick shape(s) with Mouse/Touch event
3592
- *
3593
- * 1. find AABB with r-tree
3594
- * 2. use elementFromPoint
3595
- */
3596
- var SVGPickerPlugin = /*#__PURE__*/function () {
3597
- function SVGPickerPlugin() {}
3598
- var _proto = SVGPickerPlugin.prototype;
3599
- _proto.apply = function apply(context, runtime) {
3568
+ _proto.clear = function clear(entity) {
3600
3569
  var _this = this;
3601
- var doc = context.config.document,
3602
- renderingService = context.renderingService;
3603
- renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
3604
- var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
3605
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
3606
- while (1) switch (_context.prev = _context.next) {
3607
- case 0:
3608
- return _context.abrupt("return", _this.pick(runtime, doc, result));
3609
- case 1:
3610
- case "end":
3611
- return _context.stop();
3612
- }
3613
- }, _callee);
3614
- }));
3615
- return function (_x) {
3616
- return _ref.apply(this, arguments);
3617
- };
3618
- }());
3619
- renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
3620
- return _this.pick(runtime, doc, result);
3570
+ Object.keys(this.gradientCache).forEach(function (id) {
3571
+ _this.clearUnusedDefElement(_this.gradientCache, id, entity);
3621
3572
  });
3622
3573
  };
3623
- _proto.pick = function pick(runtime, doc, result) {
3624
- var topmost = result.topmost,
3625
- _result$position = result.position,
3626
- clientX = _result$position.clientX,
3627
- clientY = _result$position.clientY;
3628
- try {
3629
- var targets = [];
3630
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
3631
- for (var _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY)), _step; !(_step = _iterator()).done;) {
3632
- var element = _step.value;
3633
- // eg. g_svg_circle_345
3634
- var id = element && element.getAttribute('id');
3635
- if (id && id.startsWith(G_SVG_PREFIX)) {
3636
- var index = id.lastIndexOf('-');
3637
- var target = runtime.displayObjectPool.getByEntity(id.substring(index + 1));
3638
- // don't need to account for `visibility` since DOM API already does
3639
- if (target && target.isInteractive()) {
3640
- targets.push(target);
3641
- if (topmost) {
3642
- result.picked = targets;
3643
- return result;
3644
- }
3645
- }
3574
+ _proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
3575
+ if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
3576
+ var targetElement = this.$def.querySelector("#" + id);
3577
+ if (targetElement) {
3578
+ this.$def.removeChild(targetElement);
3579
+ }
3580
+ }
3581
+ };
3582
+ _proto.createOrUpdateGradientAndPattern = function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name, plugin) {
3583
+ var _this$context$config = this.context.config,
3584
+ doc = _this$context$config.document,
3585
+ createImage = _this$context$config.createImage;
3586
+ if ($el) {
3587
+ var attributeValue = '';
3588
+ if (gLite.isPattern(parsedColor)) {
3589
+ // `fill: url(#${patternId})`
3590
+ attributeValue = $el.style[name];
3591
+ } else {
3592
+ // `url(#${gradientId})`
3593
+ attributeValue = $el.getAttribute(name) || '';
3594
+ }
3595
+ var matches = attributeValue.match(urlRegexp);
3596
+ if (matches && matches.length > 1) {
3597
+ this.clearUnusedDefElement(this.gradientCache, matches[1].replace('"', ''), object.entity);
3598
+ }
3599
+ var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage, plugin);
3600
+ if (newDefElementId) {
3601
+ if (!this.gradientCache[newDefElementId]) {
3602
+ this.gradientCache[newDefElementId] = new Set();
3646
3603
  }
3604
+ this.gradientCache[newDefElementId].add(object.entity);
3647
3605
  }
3648
- result.picked = targets;
3649
- } catch (e) {
3650
- result.picked = [];
3651
3606
  }
3652
- return result;
3653
3607
  };
3654
- return SVGPickerPlugin;
3608
+ _proto.createOrUpdateShadow = function createOrUpdateShadow$1(object, $el, name) {
3609
+ var doc = this.context.config.document;
3610
+ createOrUpdateShadow(doc || document, this.$def, object, $el, name);
3611
+ };
3612
+ _proto.createOrUpdateFilter = function createOrUpdateFilter$1(object, $el, filters) {
3613
+ var doc = this.context.config.document;
3614
+ createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
3615
+ };
3616
+ return DefElementManager;
3655
3617
  }();
3656
- SVGPickerPlugin.tag = 'SVGPicker';
3657
3618
  var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
3658
3619
  _inheritsLoose$3(Plugin, _AbstractRendererPlug);
3659
- function Plugin() {
3620
+ function Plugin(options) {
3660
3621
  var _this;
3661
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3662
- args[_key] = arguments[_key];
3622
+ if (options === void 0) {
3623
+ options = {};
3663
3624
  }
3664
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
3665
- _this.name = 'svg-picker';
3625
+ _this = _AbstractRendererPlug.call(this) || this;
3626
+ _this.options = void 0;
3627
+ _this.name = 'svg-renderer';
3628
+ _this.options = options;
3666
3629
  return _this;
3667
3630
  }
3668
3631
  var _proto = Plugin.prototype;
3669
3632
  _proto.init = function init() {
3670
- this.addRenderingPlugin(new SVGPickerPlugin());
3633
+ var _this$options = this.options,
3634
+ outputSVGElementId = _this$options.outputSVGElementId,
3635
+ outputSVGElementName = _this$options.outputSVGElementName;
3636
+ var defElementManager = new DefElementManager(this.context);
3637
+ // default implementation
3638
+ var defaultElementLifeCycleContribution = new DefaultElementLifeCycleContribution(this.context);
3639
+ // @ts-ignore
3640
+ this.context.defaultElementLifeCycleContribution = defaultElementLifeCycleContribution;
3641
+ // @ts-ignore
3642
+ this.context.SVGElementLifeCycleContribution = defaultElementLifeCycleContribution;
3643
+ var SVGRendererPluginOptions = {
3644
+ outputSVGElementId: !isNil(outputSVGElementId) ? !!outputSVGElementId : true,
3645
+ outputSVGElementName: !isNil(outputSVGElementName) ? !!outputSVGElementName : true
3646
+ };
3647
+ this.addRenderingPlugin(
3648
+ // @ts-ignore
3649
+ new SVGRendererPlugin(SVGRendererPluginOptions, defElementManager, this.context));
3671
3650
  };
3672
3651
  _proto.destroy = function destroy() {
3673
3652
  this.removeAllRenderingPlugins();
3653
+ // @ts-ignore
3654
+ delete this.context.defaultElementLifeCycleContribution;
3655
+ // @ts-ignore
3656
+ delete this.context.SVGElementLifeCycleContribution;
3674
3657
  };
3675
3658
  return Plugin;
3676
3659
  }(gLite.AbstractRendererPlugin);
3677
3660
 
3678
3661
  var index_esm$2 = /*#__PURE__*/Object.freeze({
3679
3662
  __proto__: null,
3680
- Plugin: Plugin$2
3663
+ CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
3664
+ DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
3665
+ DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
3666
+ ElementSVG: ElementSVG,
3667
+ G_SVG_PREFIX: G_SVG_PREFIX,
3668
+ Plugin: Plugin$2,
3669
+ SHAPE2TAGS: SHAPE2TAGS,
3670
+ SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
3671
+ SVGRendererPlugin: SVGRendererPlugin,
3672
+ SVG_ATTR_MAP: SVG_ATTR_MAP,
3673
+ TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
3674
+ createSVGElement: createSVGElement,
3675
+ updateImageElementAttribute: updateImageElementAttribute,
3676
+ updateLineElementAttribute: updateLineElementAttribute,
3677
+ updatePathElementAttribute: updatePathElementAttribute,
3678
+ updatePolylineElementAttribute: updatePolylineElementAttribute,
3679
+ updateRectElementAttribute: updateRectElementAttribute,
3680
+ updateTextElementAttribute: updateTextElementAttribute
3681
3681
  });
3682
3682
 
3683
3683
  var _excluded = ["offset", "composite", "computedOffset", "easing"],
@@ -3934,11 +3934,11 @@
3934
3934
  }
3935
3935
  _this = _AbstractRenderer.call(this, config) || this;
3936
3936
  _this.registerPlugin(new ContextRegisterPlugin());
3937
- _this.registerPlugin(new Plugin$1({
3937
+ _this.registerPlugin(new Plugin$2({
3938
3938
  outputSVGElementId: config.outputSVGElementId
3939
3939
  }));
3940
3940
  _this.registerPlugin(new Plugin());
3941
- _this.registerPlugin(new Plugin$2());
3941
+ _this.registerPlugin(new Plugin$1());
3942
3942
  return _this;
3943
3943
  }
3944
3944
  return Renderer;
@@ -3946,8 +3946,8 @@
3946
3946
 
3947
3947
  exports.DomInteraction = index_esm;
3948
3948
  exports.Renderer = Renderer;
3949
- exports.SVGPicker = index_esm$2;
3950
- exports.SVGRenderer = index_esm$1;
3949
+ exports.SVGPicker = index_esm$1;
3950
+ exports.SVGRenderer = index_esm$2;
3951
3951
 
3952
3952
  Object.defineProperty(exports, '__esModule', { value: true });
3953
3953