From f7346255879817e57a3f515b4936fe0de3b2d8e2 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Thu, 4 Jul 2019 15:15:58 +0800 Subject: [PATCH] - Fix: Avoid race condition in `jQuery.svgIcons.js` (evident when attempting to load from `file:` URL in Chrome) - npm: Update devDeps --- CHANGES.md | 2 + dist/canvg.js | 128 ++++++- dist/extensions/ext-arrows.js | 172 ++++++++- dist/extensions/ext-markers.js | 174 ++++++++- dist/extensions/ext-placemark.js | 172 ++++++++- dist/extensions/ext-server_moinsave.js | 128 ++++++- dist/extensions/ext-server_opensave.js | 128 ++++++- dist/extensions/ext-storage.js | 171 ++++++++- dist/index-es.js | 486 ++++++++++++++++--------- dist/index-es.min.js | 2 +- dist/index-es.min.js.map | 2 +- dist/index-umd.js | 486 ++++++++++++++++--------- dist/index-umd.min.js | 2 +- dist/index-umd.min.js.map | 2 +- dist/jspdf.plugin.svgToPdf.js | 184 +++++++++- dist/svgcanvas-iife.js | 314 +++++++++++----- dist/svgcanvas-iife.min.js | 2 +- dist/svgcanvas-iife.min.js.map | 2 +- editor/svgicons/jQuery.svgIcons.js | 122 +++---- editor/xdomain-svgedit-config-iife.js | 486 ++++++++++++++++--------- package-lock.json | 12 +- package.json | 4 +- svgedit-config-iife.js | 486 ++++++++++++++++--------- 23 files changed, 2816 insertions(+), 851 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6006e423..c6574fcd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ - Deprecated: Should now use `avoidClientSideDownload` in place of `avoidClientSide` (config for `ext-server_opensave.js`). +- Fix: Avoid race condition in `jQuery.svgIcons.js` (evident + when attempting to load from `file:` URL in Chrome) - Enhancement: Added `avoidClientSideOpen` config for `ext-server_opensave.js` - Optimization: Re-rerun image optimization per update diff --git a/dist/canvg.js b/dist/canvg.js index e151b560..896e4514 100644 --- a/dist/canvg.js +++ b/dist/canvg.js @@ -134,6 +134,44 @@ var canvg = (function (exports) { return _construct.apply(null, arguments); } + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -238,6 +276,71 @@ var canvg = (function (exports) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * For parsing color values * @module RGBColor @@ -392,7 +495,11 @@ var canvg = (function (exports) { }; // array of color definition objects var colorDefs = [{ - re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, + re: _wrapRegExp(/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, { + r: 1, + g: 2, + b: 3 + }), example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'], process: function process(_) { for (var _len = arguments.length, bits = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { @@ -404,7 +511,11 @@ var canvg = (function (exports) { }); } }, { - re: /^(\w{2})(\w{2})(\w{2})$/, + re: _wrapRegExp(/^(\w{2})(\w{2})(\w{2})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#00ff00', '336699'], process: function process(_) { for (var _len2 = arguments.length, bits = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { @@ -416,7 +527,11 @@ var canvg = (function (exports) { }); } }, { - re: /^(\w{1})(\w{1})(\w{1})$/, + re: _wrapRegExp(/^(\w{1})(\w{1})(\w{1})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#fb0', 'f0f'], process: function process(_) { for (var _len3 = arguments.length, bits = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { @@ -479,7 +594,7 @@ var canvg = (function (exports) { }); _this.ok = true; } - }, this); // validate/cleanup values + }); // validate/cleanup values this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r; this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g; @@ -890,7 +1005,7 @@ var canvg = (function (exports) { /** * Whether a value is `null` or `undefined`. - * @param {Any} val + * @param {any} val * @returns {boolean} */ @@ -971,6 +1086,8 @@ var canvg = (function (exports) { return svg.load(ctx, s); }; + /* eslint-disable jsdoc/check-types */ + /** * @param {module:canvg.CanvgOptions} opts * @returns {object} @@ -978,6 +1095,7 @@ var canvg = (function (exports) { */ function build(opts) { + /* eslint-enable jsdoc/check-types */ var svg = { opts: opts }; diff --git a/dist/extensions/ext-arrows.js b/dist/extensions/ext-arrows.js index 85cc8536..47e15fab 100644 --- a/dist/extensions/ext-arrows.js +++ b/dist/extensions/ext-arrows.js @@ -37,6 +37,170 @@ var svgEditorExtension_arrows = (function () { }; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * ext-arrows.js * @@ -237,13 +401,15 @@ var svgEditorExtension_arrows = (function () { return null; } - var m = str.match(/\(#(.*)\)/); + var m = str.match(_wrapRegExp(/\(#(.+)\)/, { + id: 1 + })); - if (!m || m.length !== 2) { + if (!m || !m.groups.id) { return null; } - return svgCanvas.getElem(m[1]); + return svgCanvas.getElem(m.groups.id); }; unsetArrowNonce = function _ref4(win) { diff --git a/dist/extensions/ext-markers.js b/dist/extensions/ext-markers.js index abf6d261..38fbb89e 100644 --- a/dist/extensions/ext-markers.js +++ b/dist/extensions/ext-markers.js @@ -37,6 +37,170 @@ var svgEditorExtension_markers = (function () { }; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * ext-markers.js * @@ -337,7 +501,7 @@ var svgEditorExtension_markers = (function () { convertline = function _ref6(elem) { // this routine came from the connectors extension // it is needed because midpoint markers don't work with line elements - if (!(elem.tagName === 'line')) { + if (elem.tagName !== 'line') { return elem; } // Convert to polyline to accept mid-arrow @@ -535,13 +699,15 @@ var svgEditorExtension_markers = (function () { return null; } - var m = str.match(/\(#(.*)\)/); + var m = str.match(_wrapRegExp(/\(#(.+)\)/, { + id: 1 + })); - if (!m || m.length !== 2) { + if (!m || !m.groups.id) { return null; } - return svgCanvas.getElem(m[1]); + return svgCanvas.getElem(m.groups.id); }; _context3.next = 17; diff --git a/dist/extensions/ext-placemark.js b/dist/extensions/ext-placemark.js index 3411d8af..57f7b573 100644 --- a/dist/extensions/ext-placemark.js +++ b/dist/extensions/ext-placemark.js @@ -37,6 +37,105 @@ var svgEditorExtension_placemark = (function () { }; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } @@ -75,6 +174,71 @@ var svgEditorExtension_placemark = (function () { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * ext-placemark.js * @@ -321,13 +485,15 @@ var svgEditorExtension_placemark = (function () { return null; } - var m = str.match(/\(#(.*)\)/); + var m = str.match(_wrapRegExp(/\(#(.+)\)/, { + id: 1 + })); - if (!m || m.length !== 2) { + if (!m || !m.groups.id) { return null; } - return svgCanvas.getElem(m[1]); + return svgCanvas.getElem(m.groups.id); }; showPanel = function _ref(on) { diff --git a/dist/extensions/ext-server_moinsave.js b/dist/extensions/ext-server_moinsave.js index 5e4dd602..b14c077c 100644 --- a/dist/extensions/ext-server_moinsave.js +++ b/dist/extensions/ext-server_moinsave.js @@ -134,6 +134,44 @@ var svgEditorExtension_server_moinsave = (function () { return _construct.apply(null, arguments); } + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -238,6 +276,71 @@ var svgEditorExtension_server_moinsave = (function () { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * For parsing color values * @module RGBColor @@ -392,7 +495,11 @@ var svgEditorExtension_server_moinsave = (function () { }; // array of color definition objects var colorDefs = [{ - re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, + re: _wrapRegExp(/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, { + r: 1, + g: 2, + b: 3 + }), example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'], process: function process(_) { for (var _len = arguments.length, bits = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { @@ -404,7 +511,11 @@ var svgEditorExtension_server_moinsave = (function () { }); } }, { - re: /^(\w{2})(\w{2})(\w{2})$/, + re: _wrapRegExp(/^(\w{2})(\w{2})(\w{2})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#00ff00', '336699'], process: function process(_) { for (var _len2 = arguments.length, bits = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { @@ -416,7 +527,11 @@ var svgEditorExtension_server_moinsave = (function () { }); } }, { - re: /^(\w{1})(\w{1})(\w{1})$/, + re: _wrapRegExp(/^(\w{1})(\w{1})(\w{1})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#fb0', 'f0f'], process: function process(_) { for (var _len3 = arguments.length, bits = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { @@ -479,7 +594,7 @@ var svgEditorExtension_server_moinsave = (function () { }); _this.ok = true; } - }, this); // validate/cleanup values + }); // validate/cleanup values this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r; this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g; @@ -890,7 +1005,7 @@ var svgEditorExtension_server_moinsave = (function () { /** * Whether a value is `null` or `undefined`. - * @param {Any} val + * @param {any} val * @returns {boolean} */ @@ -971,6 +1086,8 @@ var svgEditorExtension_server_moinsave = (function () { return svg.load(ctx, s); }; + /* eslint-disable jsdoc/check-types */ + /** * @param {module:canvg.CanvgOptions} opts * @returns {object} @@ -978,6 +1095,7 @@ var svgEditorExtension_server_moinsave = (function () { */ function build(opts) { + /* eslint-enable jsdoc/check-types */ var svg = { opts: opts }; diff --git a/dist/extensions/ext-server_opensave.js b/dist/extensions/ext-server_opensave.js index 799833ab..557d704b 100644 --- a/dist/extensions/ext-server_opensave.js +++ b/dist/extensions/ext-server_opensave.js @@ -134,6 +134,44 @@ var svgEditorExtension_server_opensave = (function () { return _construct.apply(null, arguments); } + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -238,6 +276,71 @@ var svgEditorExtension_server_opensave = (function () { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * For parsing color values * @module RGBColor @@ -392,7 +495,11 @@ var svgEditorExtension_server_opensave = (function () { }; // array of color definition objects var colorDefs = [{ - re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, + re: _wrapRegExp(/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/, { + r: 1, + g: 2, + b: 3 + }), example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'], process: function process(_) { for (var _len = arguments.length, bits = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { @@ -404,7 +511,11 @@ var svgEditorExtension_server_opensave = (function () { }); } }, { - re: /^(\w{2})(\w{2})(\w{2})$/, + re: _wrapRegExp(/^(\w{2})(\w{2})(\w{2})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#00ff00', '336699'], process: function process(_) { for (var _len2 = arguments.length, bits = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { @@ -416,7 +527,11 @@ var svgEditorExtension_server_opensave = (function () { }); } }, { - re: /^(\w{1})(\w{1})(\w{1})$/, + re: _wrapRegExp(/^(\w{1})(\w{1})(\w{1})$/, { + r: 1, + g: 2, + b: 3 + }), example: ['#fb0', 'f0f'], process: function process(_) { for (var _len3 = arguments.length, bits = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { @@ -479,7 +594,7 @@ var svgEditorExtension_server_opensave = (function () { }); _this.ok = true; } - }, this); // validate/cleanup values + }); // validate/cleanup values this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r; this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g; @@ -890,7 +1005,7 @@ var svgEditorExtension_server_opensave = (function () { /** * Whether a value is `null` or `undefined`. - * @param {Any} val + * @param {any} val * @returns {boolean} */ @@ -971,6 +1086,8 @@ var svgEditorExtension_server_opensave = (function () { return svg.load(ctx, s); }; + /* eslint-disable jsdoc/check-types */ + /** * @param {module:canvg.CanvgOptions} opts * @returns {object} @@ -978,6 +1095,7 @@ var svgEditorExtension_server_opensave = (function () { */ function build(opts) { + /* eslint-enable jsdoc/check-types */ var svg = { opts: opts }; diff --git a/dist/extensions/ext-storage.js b/dist/extensions/ext-storage.js index 13e447ab..a23d835a 100644 --- a/dist/extensions/ext-storage.js +++ b/dist/extensions/ext-storage.js @@ -37,6 +37,105 @@ var svgEditorExtension_storage = (function () { }; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } @@ -75,6 +174,71 @@ var svgEditorExtension_storage = (function () { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); + } + /** * ext-storage.js * @@ -125,8 +289,11 @@ var svgEditorExtension_storage = (function () { var loc = top.location; // Allow this to work with the embedded editor as well if (loc.href.includes('storagePrompt=')) { - loc.href = loc.href.replace(/([&?])storagePrompt=[^&]*(&?)/, function (n0, n1, amp) { - return (val ? n1 : '') + val + (!val && amp ? n1 : amp || ''); + loc.href = loc.href.replace(_wrapRegExp(/([&?])storagePrompt=[^&]*(&?)/, { + sep: 1, + amp: 2 + }), function (n0, sep, amp) { + return (val ? sep : '') + val + (!val && amp ? sep : amp || ''); }); } else { loc.href += (loc.href.includes('?') ? '&' : '?') + val; diff --git a/dist/index-es.js b/dist/index-es.js index 4e62d5be..525711c6 100644 --- a/dist/index-es.js +++ b/dist/index-es.js @@ -119,6 +119,74 @@ function _setPrototypeOf(o, p) { return _setPrototypeOf(o, p); } +function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } +} + +function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); +} + +function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; +} + +function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); +} + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -193,6 +261,71 @@ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } +function _wrapRegExp(re, groups) { + _wrapRegExp = function (re, groups) { + return new BabelRegExp(re, groups); + }; + + var _RegExp = _wrapNativeSuper(RegExp); + + var _super = RegExp.prototype; + + var _groups = new WeakMap(); + + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + + _groups.set(_this, groups); + + return _this; + } + + _inherits(BabelRegExp, _RegExp); + + BabelRegExp.prototype.exec = function (str) { + var result = _super.exec.call(this, str); + + if (result) result.groups = buildGroups(result, this); + return result; + }; + + BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + + return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { + return "$" + groups[name]; + })); + } else if (typeof substitution === "function") { + var _this = this; + + return _super[Symbol.replace].call(this, str, function () { + var args = []; + args.push.apply(args, arguments); + + if (typeof args[args.length - 1] !== "object") { + args.push(buildGroups(args, _this)); + } + + return substitution.apply(this, args); + }); + } else { + return _super[Symbol.replace].call(this, str, substitution); + } + }; + + function buildGroups(result, re) { + var g = _groups.get(re); + + return Object.keys(g).reduce(function (groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); + } + + return _wrapRegExp.apply(this, arguments); +} + // http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript/ /** @@ -3167,22 +3300,35 @@ function () { } // TODO: Add skew support in future - var re = /\s*((scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/; + var re = _wrapRegExp(/\s*((?:scale|matrix|rotate|translate)\s*\(.*?\))\s*,?\s*/, { + xform: 1 + }); + var m = true; while (m) { m = str.match(re); str = str.replace(re, ''); - if (m && m[1]) { + if (m && m.groups.xform) { (function () { - var x = m[1]; - var bits = x.split(/\s*\(/); - var name = bits[0]; - var valBits = bits[1].match(/\s*(.*?)\s*\)/); - valBits[1] = valBits[1].replace(/(\d)-/g, '$1 -'); - var valArr = valBits[1].split(/[, ]+/); - var letters = 'abcdef'.split(''); + var x = m.groups.xform; + + var _x$split = x.split(/\s*\(/), + _x$split2 = _slicedToArray(_x$split, 2), + name = _x$split2[0], + bits = _x$split2[1]; + + var valBits = bits.match(_wrapRegExp(/\s*(.*?)\s*\)/, { + nonWhitespace: 1 + })); + valBits.groups.nonWhitespace = valBits.groups.nonWhitespace.replace(_wrapRegExp(/(\d)-/g, { + digit: 1 + }), '$ -'); + var valArr = valBits.groups.nonWhitespace.split(/[, ]+/); + + var letters = _toConsumableArray('abcdef'); + var mtx = svgroot.createSVGMatrix(); Object.values(valArr).forEach(function (item, i) { valArr[i] = parseFloat(item); @@ -6515,11 +6661,12 @@ var reorientGrads = function reorientGrads(elem, m) { var pt1 = transformPoint(x1, y1, m); var pt2 = transformPoint(x2, y2, m); // Convert back to BB points - var gCoords = {}; - gCoords.x1 = (pt1.x - bb.x) / bb.width; - gCoords.y1 = (pt1.y - bb.y) / bb.height; - gCoords.x2 = (pt2.x - bb.x) / bb.width; - gCoords.y2 = (pt2.y - bb.y) / bb.height; + var gCoords = { + x1: (pt1.x - bb.x) / bb.width, + y1: (pt1.y - bb.y) / bb.height, + x2: (pt2.x - bb.x) / bb.width, + y2: (pt2.y - bb.y) / bb.height + }; var newgrad = grad.cloneNode(true); $$1(newgrad).attr(gCoords); newgrad.id = editorContext_.getNextId(); @@ -6703,6 +6850,7 @@ var convertPath = function convertPath(pth, toRel) { d += pathDSegment(letter, [[x1, y1], [x, y]]); break; + // eslint-disable-next-line sonarjs/no-duplicated-branches case 10: // absolute elliptical arc (A) @@ -7950,7 +8098,10 @@ var init$2 = function init(editorContext) { */ var dropXMLInteralSubset = function dropXMLInteralSubset(str) { - return str.replace(/()/, '$1$2'); + return str.replace(_wrapRegExp(/()/, { + doctypeOpen: 1, + doctypeClose: 2 + }), '$$'); }; /** * Converts characters in a string to XML-friendly entities. @@ -8090,9 +8241,16 @@ var dataURLToObjectURL = function dataURLToObjectURL(dataurl) { return ''; } - var arr = dataurl.split(','), - mime = arr[0].match(/:(.*?);/)[1], - bstr = atob(arr[1]); + var _dataurl$split = dataurl.split(','), + _dataurl$split2 = _slicedToArray(_dataurl$split, 2), + prefix = _dataurl$split2[0], + suffix = _dataurl$split2[1], + _prefix$match = prefix.match(_wrapRegExp(/:(.*?);/, { + mime: 1 + })), + mime = _prefix$match.groups.mime, + bstr = atob(suffix); + var n = bstr.length; var u8arr = new Uint8Array(n); @@ -8144,6 +8302,7 @@ var blankPageObjectURL = function () { var text2xml = function text2xml(sXML) { if (sXML.includes('} url +* @param {string|GenericArray} url * @param {module:importModule.ImportConfig} config -* @returns {Promise} The value to which it resolves depends on the export of the targeted module. +* @returns {Promise} The value to which it resolves depends on the export of the targeted module. */ @@ -9502,7 +9668,7 @@ function importScript(url) { * @param {PlainObject} [atts={}] * @param {PlainObject} opts * @param {boolean} [opts.returnDefault=false} = {}] -* @returns {Promise} Resolves to value of loading module or rejects with +* @returns {Promise} Resolves to value of loading module or rejects with * `Error` upon a script loading error. */ @@ -11575,7 +11741,9 @@ var sanitizeSvg = function sanitizeSvg(node) { case 'gradientTransform': case 'patternTransform': { - var val = attr.value.replace(/(\d)-/g, '$1 -'); + var val = attr.value.replace(_wrapRegExp(/(\d)-/g, { + digit: 1 + }), '$ -'); node.setAttribute(attrName, val); break; } @@ -11708,9 +11876,8 @@ var init$4 = function init(editorContext) { }; /** * Applies coordinate changes to an element based on the given matrix. - * @function module:coords.remapElement - * @implements {module:path.EditorContext#remapElement} - * @returns {void} + * @name module:coords.remapElement + * @type {module:path.EditorContext#remapElement} */ var remapElement = function remapElement(selected, changes, m) { @@ -13681,9 +13848,8 @@ function SvgCanvas(container, config) { canvas.current_drawing_ = new Drawing(svgcontent, idprefix); /** * Returns the current Drawing. - * @function module:svgcanvas.SvgCanvas#getCurrentDrawing - * @implements {module:draw.DrawCanvasInit#getCurrentDrawing} - * @returns {module:draw.Drawing} + * @name module:svgcanvas.SvgCanvas#getCurrentDrawing + * @type {module:draw.DrawCanvasInit#getCurrentDrawing} */ var getCurrentDrawing = canvas.getCurrentDrawing = function () { @@ -13762,9 +13928,8 @@ function SvgCanvas(container, config) { }; /** * This should really be an intersection implementing all rather than a union. - * @function module:svgcanvas.SvgCanvas#addSVGElementFromJson - * @implements {module:utilities.EditorContext#addSVGElementFromJson|module:path.EditorContext#addSVGElementFromJson} - * @returns {Element} The new element + * @name module:svgcanvas.SvgCanvas#addSVGElementFromJson + * @type {module:utilities.EditorContext#addSVGElementFromJson|module:path.EditorContext#addSVGElementFromJson} */ @@ -13820,8 +13985,7 @@ function SvgCanvas(container, config) { canvas.hasMatrixTransform = hasMatrixTransform; canvas.transformListToTransform = transformListToTransform; /** - * @implements {module:utilities.EditorContext#getBaseUnit} - * @returns {string} + * @type {module:utilities.EditorContext#getBaseUnit} */ var getBaseUnit = function getBaseUnit() { @@ -13853,8 +14017,7 @@ function SvgCanvas(container, config) { canvas.convertToNum = convertToNum; /** * This should really be an intersection implementing all rather than a union. - * @implements {module:draw.DrawCanvasInit#getSVGContent|module:utilities.EditorContext#getSVGContent} - * @returns {SVGSVGElement} + * @type {module:draw.DrawCanvasInit#getSVGContent|module:utilities.EditorContext#getSVGContent} */ var getSVGContent = function getSVGContent() { @@ -13862,9 +14025,8 @@ function SvgCanvas(container, config) { }; /** * Should really be an intersection with all needing to apply rather than a union. - * @function module:svgcanvas.SvgCanvas#getSelectedElements - * @implements {module:utilities.EditorContext#getSelectedElements|module:draw.DrawCanvasInit#getSelectedElements|module:path.EditorContext#getSelectedElements} - * @returns {Element[]} the array with selected DOM elements + * @name module:svgcanvas.SvgCanvas#getSelectedElements + * @type {module:utilities.EditorContext#getSelectedElements|module:draw.DrawCanvasInit#getSelectedElements|module:path.EditorContext#getSelectedElements} */ @@ -13875,8 +14037,7 @@ function SvgCanvas(container, config) { var pathActions$1 = pathActions; /** * This should actually be an intersection as all interfaces should be met. - * @implements {module:utilities.EditorContext#getSVGRoot|module:recalculate.EditorContext#getSVGRoot|module:coords.EditorContext#getSVGRoot|module:path.EditorContext#getSVGRoot} - * @returns {SVGSVGElement} + * @type {module:utilities.EditorContext#getSVGRoot|module:recalculate.EditorContext#getSVGRoot|module:coords.EditorContext#getSVGRoot|module:path.EditorContext#getSVGRoot} */ var getSVGRoot = function getSVGRoot() { @@ -13920,8 +14081,7 @@ function SvgCanvas(container, config) { this.cleanupElement = cleanupElement; /** * This should actually be an intersection not a union as all should apply. - * @implements {module:coords.EditorContext#getGridSnapping|module:path.EditorContext#getGridSnapping} - * @returns {boolean} + * @type {module:coords.EditorContext#getGridSnapping|module:path.EditorContext#getGridSnapping} */ var getGridSnapping = function getGridSnapping() { @@ -14035,8 +14195,8 @@ function SvgCanvas(container, config) { }); /** * This should really be an intersection applying to all types rather than a union. - * @function module:svgcanvas~addCommandToHistory - * @implements {module:path.EditorContext#addCommandToHistory|module:draw.DrawCanvasInit#addCommandToHistory} + * @name module:svgcanvas~addCommandToHistory + * @type {module:path.EditorContext#addCommandToHistory|module:draw.DrawCanvasInit#addCommandToHistory} */ var addCommandToHistory = function addCommandToHistory(cmd) { @@ -14044,9 +14204,8 @@ function SvgCanvas(container, config) { }; /** * This should really be an intersection applying to all types rather than a union. - * @function module:svgcanvas.SvgCanvas#getZoom - * @implements {module:path.EditorContext#getCurrentZoom|module:select.SVGFactory#getCurrentZoom} - * @returns {Float} The current zoom level + * @name module:svgcanvas.SvgCanvas#getZoom + * @type {module:path.EditorContext#getCurrentZoom|module:select.SVGFactory#getCurrentZoom} */ @@ -14055,9 +14214,8 @@ function SvgCanvas(container, config) { }; /** * This method rounds the incoming value to the nearest value based on the `currentZoom` - * @function module:svgcanvas.SvgCanvas#round - * @implements {module:path.EditorContext#round} - * @returns {Float} Rounded value to nearest value based on `currentZoom` + * @name module:svgcanvas.SvgCanvas#round + * @type {module:path.EditorContext#round} */ @@ -14090,18 +14248,16 @@ function SvgCanvas(container, config) { var selectorManager = this.selectorManager = getSelectorManager(); /** - * @function module:svgcanvas.SvgCanvas#getNextId - * @implements {module:path.EditorContext#getNextId} - * @returns {string} + * @name module:svgcanvas.SvgCanvas#getNextId + * @type {module:path.EditorContext#getNextId} */ var getNextId = canvas.getNextId = function () { return getCurrentDrawing().getNextId(); }; /** - * @function module:svgcanvas.SvgCanvas#getId - * @implements {module:path.EditorContext#getId} - * @returns {string} + * @name module:svgcanvas.SvgCanvas#getId + * @type {module:path.EditorContext#getId} */ @@ -14110,11 +14266,8 @@ function SvgCanvas(container, config) { }; /** * The "implements" should really be an intersection applying to all types rather than a union. - * @function module:svgcanvas.SvgCanvas#call - * @implements {module:draw.DrawCanvasInit#call|module:path.EditorContext#call} - * @param {"selected"|"changed"|"contextset"|"pointsAdded"|"extension_added"|"extensions_added"|"message"|"transition"|"zoomed"|"updateCanvas"|"zoomDone"|"saved"|"exported"|"exportedPDF"|"setnonce"|"unsetnonce"|"cleared"} ev - String with the event name - * @param {module:svgcanvas.SvgCanvas#event:GenericCanvasEvent} arg - Argument to pass through to the callback function. - * @returns {module:svgcanvas.EventHandlerReturn|void} + * @name module:svgcanvas.SvgCanvas#call + * @type {module:draw.DrawCanvasInit#call|module:path.EditorContext#call} */ @@ -14128,8 +14281,8 @@ function SvgCanvas(container, config) { /** * Clears the selection. The 'selected' handler is then optionally called. * This should really be an intersection applying to all types rather than a union. - * @function module:svgcanvas.SvgCanvas#clearSelection - * @implements {module:draw.DrawCanvasInit#clearSelection|module:path.EditorContext#clearSelection} + * @name module:svgcanvas.SvgCanvas#clearSelection + * @type {module:draw.DrawCanvasInit#clearSelection|module:path.EditorContext#clearSelection} * @fires module:svgcanvas.SvgCanvas#event:selected */ @@ -14150,10 +14303,9 @@ function SvgCanvas(container, config) { }; /** * Adds a list of elements to the selection. The 'selected' handler is then called. - * @function module:svgcanvas.SvgCanvas#addToSelection - * @implements {module:path.EditorContext#addToSelection} + * @name module:svgcanvas.SvgCanvas#addToSelection + * @type {module:path.EditorContext#addToSelection} * @fires module:svgcanvas.SvgCanvas#event:selected - * @returns {void} */ @@ -14235,8 +14387,7 @@ function SvgCanvas(container, config) { } }; /** - * @implements {module:path.EditorContext#getOpacity} - * @returns {Float} + * @type {module:path.EditorContext#getOpacity} */ @@ -14244,9 +14395,8 @@ function SvgCanvas(container, config) { return curShape.opacity; }; /** - * @function module:svgcanvas.SvgCanvas#getMouseTarget - * @implements {module:path.EditorContext#getMouseTarget} - * @returns {Element} DOM element we want + * @name module:svgcanvas.SvgCanvas#getMouseTarget + * @type {module:path.EditorContext#getMouseTarget} */ @@ -14314,7 +14464,7 @@ function SvgCanvas(container, config) { canvas.pathActions = pathActions$1; /** - * @implements {module:path.EditorContext#resetD} + * @type {module:path.EditorContext#resetD} */ function resetD(p) { @@ -14979,7 +15129,7 @@ function SvgCanvas(container, config) { /** * @typedef {PlainObject} module:svgcanvas.Message - * @property {Any} data The data + * @property {any} data The data * @property {string} origin The origin */ @@ -18584,10 +18734,12 @@ function SvgCanvas(container, config) { if (val) { if (val.startsWith('data:')) { // Check if an SVG-edit data URI - var m = val.match(/svgedit_url=(.*?);/); + var m = val.match(_wrapRegExp(/svgedit_url=(.*?);/, { + url: 1 + })); if (m) { - var url = decodeURIComponent(m[1]); + var url = decodeURIComponent(m.groups.url); $$9(new Image()).load(function () { image.setAttributeNS(NS.XLINK, 'xlink:href', url); }).attr('src', url); @@ -22380,6 +22532,65 @@ $(function() { }); */ +var isOpera$1 = Boolean(window.opera); + +var fixIDs = function fixIDs(svgEl, svgNum, force) { + var defs = svgEl.find('defs'); + if (!defs.length) return svgEl; + var idElems; + + if (isOpera$1) { + idElems = defs.find('*').filter(function () { + return Boolean(this.id); + }); + } else { + idElems = defs.find('[id]'); + } + + var allElems = svgEl[0].getElementsByTagName('*'), + len = allElems.length; + idElems.each(function (i) { + var id = this.id; + /* + const noDupes = ($(svgdoc).find('#' + id).length <= 1); + if (isOpera) noDupes = false; // Opera didn't clone svgEl, so not reliable + if(!force && noDupes) return; + */ + + var newId = 'x' + id + svgNum + i; + this.id = newId; + var oldVal = 'url(#' + id + ')'; + var newVal = 'url(#' + newId + ')'; // Selector method, possibly faster but fails in Opera / jQuery 1.4.3 + // svgEl.find('[fill="url(#' + id + ')"]').each(function() { + // this.setAttribute('fill', 'url(#' + newId + ')'); + // }).end().find('[stroke="url(#' + id + ')"]').each(function() { + // this.setAttribute('stroke', 'url(#' + newId + ')'); + // }).end().find('use').each(function() { + // if(this.getAttribute('xlink:href') == '#' + id) { + // this.setAttributeNS(xlinkns,'href','#' + newId); + // } + // }).end().find('[filter="url(#' + id + ')"]').each(function() { + // this.setAttribute('filter', 'url(#' + newId + ')'); + // }); + + for (i = 0; i < len; i++) { + var elem = allElems[i]; + + if (elem.getAttribute('fill') === oldVal) { + elem.setAttribute('fill', newVal); + } + + if (elem.getAttribute('stroke') === oldVal) { + elem.setAttribute('stroke', newVal); + } + + if (elem.getAttribute('filter') === oldVal) { + elem.setAttribute('filter', newVal); + } + } + }); + return svgEl; +}; /** * @callback module:jQuerySVGIcons.SVGIconsLoadedCallback * @param {PlainObject} svgIcons IDs keyed to jQuery objects of images @@ -22391,9 +22602,9 @@ $(function() { * @returns {external:jQuery} The enhanced jQuery object */ + function jQueryPluginSVGIcons($) { var svgIcons = {}; - var fixIDs; /** * Map of raster images with each key being the SVG icon ID * to replace, and the value the image file name @@ -22452,8 +22663,7 @@ function jQueryPluginSVGIcons($) { iconsMade = false, dataLoaded = false, loadAttempts = 0; - var isOpera = Boolean(window.opera), - // ua = navigator.userAgent, + var // ua = navigator.userAgent, // isSafari = (ua.includes('Safari/') && !ua.includes('Chrome/')), dataPre = 'data:image/svg+xml;charset=utf-8;base64,'; var dataEl; @@ -22572,7 +22782,7 @@ function jQueryPluginSVGIcons($) { function setIcon(target, icon, id, setID) { - if (isOpera) icon.css('visibility', 'hidden'); + if (isOpera$1) icon.css('visibility', 'hidden'); if (opts.replace) { if (setID) icon.attr('id', id); @@ -22594,7 +22804,7 @@ function jQueryPluginSVGIcons($) { target.append(icon); } - if (isOpera) { + if (isOpera$1) { setTimeout(function () { icon.removeAttr('style'); }, 1); @@ -22686,7 +22896,7 @@ function jQueryPluginSVGIcons($) { svgroot.setAttribute('class', 'svg_icon'); // Without cloning, Firefox will make another GET request. // With cloning, causes issue in Opera/Win/Non-EN - if (!isOpera) svg = svg.cloneNode(true); + if (!isOpera$1) svg = svg.cloneNode(true); svgroot.append(svg); var icon = void 0; @@ -22717,7 +22927,7 @@ function jQueryPluginSVGIcons($) { if (!svgIcons[id]) return; $(sel).each(function (i) { var copy = svgIcons[id].clone(); - if (i > 0 && !toImage) copy = fixIDs(copy, i, true); + if (i > 0 && !toImage) copy = fixIDs(copy, i); setIcon($(this), copy, id); }); }); @@ -22733,64 +22943,6 @@ function jQueryPluginSVGIcons($) { iconsMade = true; if (opts.callback) opts.callback(svgIcons); } - - fixIDs = function fixIDs(svgEl, svgNum, force) { - var defs = svgEl.find('defs'); - if (!defs.length) return svgEl; - var idElems; - - if (isOpera) { - idElems = defs.find('*').filter(function () { - return Boolean(this.id); - }); - } else { - idElems = defs.find('[id]'); - } - - var allElems = svgEl[0].getElementsByTagName('*'), - len = allElems.length; - idElems.each(function (i) { - var id = this.id; - /* - const noDupes = ($(svgdoc).find('#' + id).length <= 1); - if (isOpera) noDupes = false; // Opera didn't clone svgEl, so not reliable - if(!force && noDupes) return; - */ - - var newId = 'x' + id + svgNum + i; - this.id = newId; - var oldVal = 'url(#' + id + ')'; - var newVal = 'url(#' + newId + ')'; // Selector method, possibly faster but fails in Opera / jQuery 1.4.3 - // svgEl.find('[fill="url(#' + id + ')"]').each(function() { - // this.setAttribute('fill', 'url(#' + newId + ')'); - // }).end().find('[stroke="url(#' + id + ')"]').each(function() { - // this.setAttribute('stroke', 'url(#' + newId + ')'); - // }).end().find('use').each(function() { - // if(this.getAttribute('xlink:href') == '#' + id) { - // this.setAttributeNS(xlinkns,'href','#' + newId); - // } - // }).end().find('[filter="url(#' + id + ')"]').each(function() { - // this.setAttribute('filter', 'url(#' + newId + ')'); - // }); - - for (i = 0; i < len; i++) { - var elem = allElems[i]; - - if (elem.getAttribute('fill') === oldVal) { - elem.setAttribute('fill', newVal); - } - - if (elem.getAttribute('stroke') === oldVal) { - elem.setAttribute('stroke', newVal); - } - - if (elem.getAttribute('filter') === oldVal) { - elem.setAttribute('filter', newVal); - } - } - }); - return svgEl; - }; /** * @returns {void} */ @@ -22822,7 +22974,7 @@ function jQueryPluginSVGIcons($) { var icon = svgIcons[id]; if (uniqueClone && icon) { - icon = fixIDs(icon, 0, true).clone(true); + icon = fixIDs(icon, 0).clone(true); } return icon; @@ -24895,7 +25047,7 @@ function toFixedNumeric(value, precision) { } /** * Whether a value is `null` or `undefined`. - * @param {Any} val + * @param {any} val * @returns {boolean} */ @@ -29344,7 +29496,7 @@ editor.setConfig = function (opts, cfgCfg) { * * @param {module:SVGEditor.Config|module:SVGEditor.Prefs} cfgObj * @param {string} key - * @param {Any} val See {@link module:SVGEditor.Config} or {@link module:SVGEditor.Prefs} + * @param {any} val See {@link module:SVGEditor.Config} or {@link module:SVGEditor.Prefs} * @returns {void} */ @@ -29621,7 +29773,9 @@ editor.init = function () { if (!src) { // urldata.source may have been null if it ended with '=' if (qstr.includes('source=data:')) { - src = qstr.match(/source=(data:[^&]*)/)[1]; + src = qstr.match(_wrapRegExp(/source=(data:[^&]*)/, { + src: 1 + })).groups.src; } } @@ -29725,7 +29879,9 @@ editor.init = function () { while (1) { switch (_context2.prev = _context2.next) { case 0: - extName = extname.match(/^ext-(.+)\.js/); + extName = extname.match(_wrapRegExp(/^ext-(.+)\.js/, { + extName: 1 + })).groups.extName; if (extName) { _context2.next = 3; @@ -29748,12 +29904,12 @@ editor.init = function () { _context2.prev = 4; _context2.next = 7; return importSetGlobalDefault(url, { - global: 'svgEditorExtension_' + extName[1].replace(/-/g, '_') + global: 'svgEditorExtension_' + extName.replace(/-/g, '_') }); case 7: imported = _context2.sent; - _imported$name = imported.name, _name2 = _imported$name === void 0 ? extName[1] : _imported$name, init = imported.init; + _imported$name = imported.name, _name2 = _imported$name === void 0 ? extName : _imported$name, init = imported.init; importLocale = getImportLocale({ defaultLang: langParam, defaultName: _name2 @@ -29867,7 +30023,7 @@ editor.init = function () { var uaPrefix = function () { - var regex = /^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/; + var regex = /^(?:Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/; var someScript = document.getElementsByTagName('script')[0]; for (var prop in someScript.style) { @@ -31795,7 +31951,7 @@ editor.init = function () { zoomDone(); }; /** - * @implements {module:jQuerySpinButton.ValueCallback} + * @type {module:jQuerySpinButton.ValueCallback} */ @@ -32761,14 +32917,14 @@ editor.init = function () { setBackground($$b.pref('bkgd_color'), $$b.pref('bkgd_url')); $$b('#image_save_opts input').val([$$b.pref('img_save')]); /** - * @implements {module:jQuerySpinButton.ValueCallback} + * @type {module:jQuerySpinButton.ValueCallback} */ var changeRectRadius = function changeRectRadius(ctl) { svgCanvas.setRectRadius(ctl.value); }; /** - * @implements {module:jQuerySpinButton.ValueCallback} + * @type {module:jQuerySpinButton.ValueCallback} */ @@ -32776,7 +32932,7 @@ editor.init = function () { svgCanvas.setFontSize(ctl.value); }; /** - * @implements {module:jQuerySpinButton.ValueCallback} + * @type {module:jQuerySpinButton.ValueCallback} */ @@ -32790,7 +32946,7 @@ editor.init = function () { svgCanvas.setStrokeWidth(val); }; /** - * @implements {module:jQuerySpinButton.ValueCallback} + * @type {module:jQuerySpinButton.ValueCallback} */ @@ -35117,8 +35273,7 @@ editor.init = function () { $$b(window).bind('load resize', centerCanvas); /** - * @implements {module:jQuerySpinButton.StepCallback} - * @returns {Float} + * @type {module:jQuerySpinButton.StepCallback} */ function stepFontSize(elem, step) { @@ -35149,8 +35304,7 @@ editor.init = function () { return sugVal; } /** - * @implements {module:jQuerySpinButton.StepCallback} - * @returns {Float} + * @type {module:jQuerySpinButton.StepCallback} */ @@ -36729,7 +36883,7 @@ var extensionsAdded = false; var messageQueue = []; /** * @param {PlainObject} info - * @param {Any} info.data + * @param {any} info.data * @param {string} info.origin * @fires module:svgcanvas.SvgCanvas#event:message * @returns {void} diff --git a/dist/index-es.min.js b/dist/index-es.min.js index 8579fe79..1b899a98 100644 --- a/dist/index-es.min.js +++ b/dist/index-es.min.js @@ -1,2 +1,2 @@ -function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t,n,r,a,i,o){try{var s=e[i](o),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,a)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(a,i){var o=e.apply(n,r);function s(e){t(o,a,i,s,l,"next",e)}function l(e){t(o,a,i,s,l,"throw",e)}s(void 0)})}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var n=0;nt.getTotalLength())break;n--}while(n>0);return n}),window.SVGPathSeg=e,window.SVGPathSegClosePath=t,window.SVGPathSegMovetoAbs=n,window.SVGPathSegMovetoRel=a,window.SVGPathSegLinetoAbs=o,window.SVGPathSegLinetoRel=c,window.SVGPathSegCurvetoCubicAbs=d,window.SVGPathSegCurvetoCubicRel=h,window.SVGPathSegCurvetoQuadraticAbs=p,window.SVGPathSegCurvetoQuadraticRel=f,window.SVGPathSegArcAbs=g,window.SVGPathSegArcRel=m,window.SVGPathSegLinetoHorizontalAbs=v,window.SVGPathSegLinetoHorizontalRel=y,window.SVGPathSegLinetoVerticalAbs=_,window.SVGPathSegLinetoVerticalRel=b,window.SVGPathSegCurvetoCubicSmoothAbs=x,window.SVGPathSegCurvetoCubicSmoothRel=w,window.SVGPathSegCurvetoQuadraticSmoothAbs=S,window.SVGPathSegCurvetoQuadraticSmoothRel=k}if(!("SVGPathSegList"in window&&"appendItem"in window.SVGPathSegList.prototype)){var C=function(){function e(t){r(this,e),this._pathElement=t,this._list=this._parsePath(this._pathElement.getAttribute("d")),this._mutationObserverConfig={attributes:!0,attributeFilter:["d"]},this._pathElementMutationObserver=new MutationObserver(this._updateListFromPathMutations.bind(this)),this._pathElementMutationObserver.observe(this._pathElement,this._mutationObserverConfig)}return i(e,[{key:"_checkPathSynchronizedToList",value:function(){this._updateListFromPathMutations(this._pathElementMutationObserver.takeRecords())}},{key:"_updateListFromPathMutations",value:function(e){if(this._pathElement){var t=!1;e.forEach(function(e){"d"===e.attributeName&&(t=!0)}),t&&(this._list=this._parsePath(this._pathElement.getAttribute("d")))}}},{key:"_writeListToPath",value:function(){this._pathElementMutationObserver.disconnect(),this._pathElement.setAttribute("d",e._pathSegArrayAsString(this._list)),this._pathElementMutationObserver.observe(this._pathElement,this._mutationObserverConfig)}},{key:"segmentChanged",value:function(e){this._writeListToPath()}},{key:"clear",value:function(){this._checkPathSynchronizedToList(),this._list.forEach(function(e){e._owningPathSegList=null}),this._list=[],this._writeListToPath()}},{key:"initialize",value:function(e){return this._checkPathSynchronizedToList(),this._list=[e],e._owningPathSegList=this,this._writeListToPath(),e}},{key:"_checkValidIndex",value:function(e){if(isNaN(e)||e<0||e>=this.numberOfItems)throw new Error("INDEX_SIZE_ERR")}},{key:"getItem",value:function(e){return this._checkPathSynchronizedToList(),this._checkValidIndex(e),this._list[e]}},{key:"insertItemBefore",value:function(e,t){return this._checkPathSynchronizedToList(),t>this.numberOfItems&&(t=this.numberOfItems),e._owningPathSegList&&(e=e.clone()),this._list.splice(t,0,e),e._owningPathSegList=this,this._writeListToPath(),e}},{key:"replaceItem",value:function(e,t){return this._checkPathSynchronizedToList(),e._owningPathSegList&&(e=e.clone()),this._checkValidIndex(t),this._list[t]=e,e._owningPathSegList=this,this._writeListToPath(),e}},{key:"removeItem",value:function(e){this._checkPathSynchronizedToList(),this._checkValidIndex(e);var t=this._list[e];return this._list.splice(e,1),this._writeListToPath(),t}},{key:"appendItem",value:function(e){return this._checkPathSynchronizedToList(),e._owningPathSegList&&(e=e.clone()),this._list.push(e),e._owningPathSegList=this,this._writeListToPath(),e}},{key:"_parsePath",value:function(e){if(!e||!e.length)return[];var t=this,n=function(){function e(){r(this,e),this.pathSegList=[]}return i(e,[{key:"appendSegment",value:function(e){this.pathSegList.push(e)}}]),e}(),a=function(){function e(t){r(this,e),this._string=t,this._currentIndex=0,this._endIndex=this._string.length,this._previousCommand=SVGPathSeg.PATHSEG_UNKNOWN,this._skipOptionalSpaces()}return i(e,[{key:"_isCurrentSpace",value:function(){var e=this._string[this._currentIndex];return e<=" "&&(" "===e||"\n"===e||"\t"===e||"\r"===e||"\f"===e)}},{key:"_skipOptionalSpaces",value:function(){for(;this._currentIndex="0"&&e<="9")&&t!==SVGPathSeg.PATHSEG_CLOSEPATH?t===SVGPathSeg.PATHSEG_MOVETO_ABS?SVGPathSeg.PATHSEG_LINETO_ABS:t===SVGPathSeg.PATHSEG_MOVETO_REL?SVGPathSeg.PATHSEG_LINETO_REL:t:SVGPathSeg.PATHSEG_UNKNOWN}},{key:"initialCommandIsMoveTo",value:function(){if(!this.hasMoreData())return!0;var e=this.peekSegmentType();return e===SVGPathSeg.PATHSEG_MOVETO_ABS||e===SVGPathSeg.PATHSEG_MOVETO_REL}},{key:"_parseNumber",value:function(){var e=0,t=0,n=1,r=0,a=1,i=1,o=this._currentIndex;if(this._skipOptionalSpaces(),this._currentIndex"9")&&"."!==this._string.charAt(this._currentIndex))){for(var s=this._currentIndex;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)this._currentIndex++;if(this._currentIndex!==s)for(var l=this._currentIndex-1,c=1;l>=s;)t+=c*(this._string.charAt(l--)-"0"),c*=10;if(this._currentIndex=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)n*=10,r+=(this._string.charAt(this._currentIndex)-"0")/n,this._currentIndex+=1}if(this._currentIndex!==o&&this._currentIndex+1=this._endIndex||this._string.charAt(this._currentIndex)<"0"||this._string.charAt(this._currentIndex)>"9")return;for(;this._currentIndex="0"&&this._string.charAt(this._currentIndex)<="9";)e*=10,e+=this._string.charAt(this._currentIndex)-"0",this._currentIndex++}var u=t+r;if(u*=a,e&&(u*=Math.pow(10,i*e)),o!==this._currentIndex)return this._skipOptionalSpacesOrDelimiter(),u}}},{key:"_parseArcFlag",value:function(){if(!(this._currentIndex>=this._endIndex)){var e=!1,t=this._string.charAt(this._currentIndex++);if("0"===t)e=!1;else{if("1"!==t)return;e=!0}return this._skipOptionalSpacesOrDelimiter(),e}}},{key:"parseSegment",value:function(){var e=this._string[this._currentIndex],n=this._pathSegTypeFromChar(e);if(n===SVGPathSeg.PATHSEG_UNKNOWN){if(this._previousCommand===SVGPathSeg.PATHSEG_UNKNOWN)return null;if((n=this._nextCommandHelper(e,this._previousCommand))===SVGPathSeg.PATHSEG_UNKNOWN)return null}else this._currentIndex++;switch(this._previousCommand=n,n){case SVGPathSeg.PATHSEG_MOVETO_REL:return new SVGPathSegMovetoRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_MOVETO_ABS:return new SVGPathSegMovetoAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_REL:return new SVGPathSegLinetoRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_ABS:return new SVGPathSegLinetoAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:return new SVGPathSegLinetoHorizontalRel(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:return new SVGPathSegLinetoHorizontalAbs(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:return new SVGPathSegLinetoVerticalRel(t,this._parseNumber());case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:return new SVGPathSegLinetoVerticalAbs(t,this._parseNumber());case SVGPathSeg.PATHSEG_CLOSEPATH:return this._skipOptionalSpaces(),new SVGPathSegClosePath(t);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:var r={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicRel(t,r.x,r.y,r.x1,r.y1,r.x2,r.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:var a={x1:this._parseNumber(),y1:this._parseNumber(),x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicAbs(t,a.x,a.y,a.x1,a.y1,a.x2,a.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:var i={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothRel(t,i.x,i.y,i.x2,i.y2);case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:var o={x2:this._parseNumber(),y2:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoCubicSmoothAbs(t,o.x,o.y,o.x2,o.y2);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:var s={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticRel(t,s.x,s.y,s.x1,s.y1);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:var l={x1:this._parseNumber(),y1:this._parseNumber(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegCurvetoQuadraticAbs(t,l.x,l.y,l.x1,l.y1);case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:return new SVGPathSegCurvetoQuadraticSmoothRel(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:return new SVGPathSegCurvetoQuadraticSmoothAbs(t,this._parseNumber(),this._parseNumber());case SVGPathSeg.PATHSEG_ARC_REL:var c={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcRel(t,c.x,c.y,c.x1,c.y1,c.arcAngle,c.arcLarge,c.arcSweep);case SVGPathSeg.PATHSEG_ARC_ABS:var u={x1:this._parseNumber(),y1:this._parseNumber(),arcAngle:this._parseNumber(),arcLarge:this._parseArcFlag(),arcSweep:this._parseArcFlag(),x:this._parseNumber(),y:this._parseNumber()};return new SVGPathSegArcAbs(t,u.x,u.y,u.x1,u.y1,u.arcAngle,u.arcLarge,u.arcSweep);default:throw new Error("Unknown path seg type.")}}}]),e}(),o=new n,s=new a(e);if(!s.initialCommandIsMoveTo())return[];for(;s.hasMoreData();){var l=s.parseSegment();if(!l)return[];o.appendSegment(l)}return o.pathSegList}}],[{key:"_pathSegArrayAsString",value:function(e){var t="",n=!0;return e.forEach(function(e){n?(n=!1,t+=e._asPathString()):t+=" "+e._asPathString()}),t}}]),e}();C.prototype.classname="SVGPathSegList",Object.defineProperty(C.prototype,"numberOfItems",{get:function(){return this._checkPathSynchronizedToList(),this._list.length},enumerable:!0}),Object.defineProperties(SVGPathElement.prototype,{pathSegList:{get:function(){return this._pathSegList||(this._pathSegList=new C(this)),this._pathSegList},enumerable:!0},normalizedPathSegList:{get:function(){return this.pathSegList},enumerable:!0},animatedPathSegList:{get:function(){return this.pathSegList},enumerable:!0},animatedNormalizedPathSegList:{get:function(){return this.pathSegList},enumerable:!0}}),window.SVGPathSegList=C}}();var m,v=jQuery,y=(Boolean(document.createElementNS&&document.createElementNS(f.SVG,"svg").createSVGRect),navigator.userAgent),_=document.createElementNS(f.SVG,"svg"),b=Boolean(window.opera),x=y.includes("AppleWebKit"),w=y.includes("Gecko/"),S=y.includes("MSIE"),k=y.includes("Chrome/"),C=(y.includes("Windows"),y.includes("Macintosh")),A="ontouchstart"in window,E=Boolean(_.querySelector),G=Boolean(document.evaluate),P=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,n=e.createSVGPathSegLinetoAbs(5,5);try{return t.replaceItem(n,1),!0}catch(e){}return!1}(),I=function(){var e=document.createElementNS(f.SVG,"path");e.setAttribute("d","M0,0 10,10");var t=e.pathSegList,n=e.createSVGPathSegLinetoAbs(5,5);try{return t.insertItemBefore(n,1),!0}catch(e){}return!1}(),N=function(){var e=document.createElementNS(f.SVG,"svg"),t=document.createElementNS(f.SVG,"svg");document.documentElement.append(e),t.setAttribute("x",5),e.append(t);var n=document.createElementNS(f.SVG,"text");n.textContent="a",t.append(n);try{return 0===n.getStartPositionOfChar(0).x}catch(e){return!1}finally{e.remove()}}(),T=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 C0,0 10,10 10,0"),e.append(t);var n=t.getBBox();return e.remove(),n.height>4&&n.height<5}(),L=function(){var e=document.createElementNS(f.SVG,"svg");document.documentElement.append(e);var t=document.createElementNS(f.SVG,"path");t.setAttribute("d","M0,0 10,0");var n=document.createElementNS(f.SVG,"path");n.setAttribute("d","M5,0 15,0");var r=document.createElementNS(f.SVG,"g");r.append(t,n),e.append(r);var a=r.getBBox();return e.remove(),15===a.width}(),M=(function(){var e=document.createElementNS(f.SVG,"rect");e.setAttribute("x",.1);var t=!e.cloneNode(!1).getAttribute("x").includes(",");t||v.alert('NOTE: This version of Opera is known to contain bugs in SVG-edit.\nPlease upgrade to the latest version in which the problems have been fixed.')}(),(m=document.createElementNS(f.SVG,"rect")).setAttribute("style","vector-effect:non-scaling-stroke"),"non-scaling-stroke"===m.style.vectorEffect),O=function(){var t=document.createElementNS(f.SVG,"rect").transform.baseVal,n=_.createSVGTransform();t.appendItem(n);var r=t.getItem(0),a=function(t){return t&&"object"===e(t)&&"function"==typeof t.setMatrix&&"angle"in t};return a(r)&&a(n)&&r.type===n.type&&r.angle===n.angle&&r.matrix.a===n.matrix.a&&r.matrix.b===n.matrix.b&&r.matrix.c===n.matrix.c&&r.matrix.d===n.matrix.d&&r.matrix.e===n.matrix.e&&r.matrix.f===n.matrix.f}(),j=function(){return b},V=function(){return x},R=function(){return w},B=function(){return S},D=function(){return k},U=function(){return C},F=function(){return A},H=function(){return L},z=function(){return M};function q(t){var n=t.fn.attr;return t.fn.attr=function(t,r){var a=this.length;if(!a)return n.call(this,t,r);for(var i=0;i=0)return this._xforms[e];var t=new Error("DOMException with code=INDEX_SIZE_ERR");throw t.code=1,t}},{key:"insertItemBefore",value:function(e,t){var n=null;if(t>=0)if(t=0&&(this._removeFromOtherLists(e),this._xforms[t]=e,n=e,this._list._update()),n}},{key:"removeItem",value:function(e){if(e=0){var t,n=this._xforms[e],r=new Array(this.numberOfItems-1);for(t=0;t=0;t--)this.stack[t].unapply(e);e&&e.handleHistoryEvent(ce.AFTER_UNAPPLY,this)}},{key:"elements",value:function(){for(var e=[],t=this.stack.length;t--;)for(var n=this.stack[t].elements(),r=n.length;r--;)e.includes(n[r])||e.push(n[r]);return e}},{key:"addSubCommand",value:function(e){this.stack.push(e)}},{key:"isEmpty",value:function(){return!this.stack.length}}]),t}();ge.type=ge.prototype.type;var me,ve,ye,_e,be,xe=function(){function e(t){r(this,e),this.handler_=t||null,this.undoStackPointer=0,this.undoStack=[],this.undoChangeStackPointer=-1,this.undoableChangeStack=[]}return i(e,[{key:"resetUndoStack",value:function(){this.undoStack=[],this.undoStackPointer=0}},{key:"getUndoStackSize",value:function(){return this.undoStackPointer}},{key:"getRedoStackSize",value:function(){return this.undoStack.length-this.undoStackPointer}},{key:"getNextUndoCommandText",value:function(){return this.undoStackPointer>0?this.undoStack[this.undoStackPointer-1].getText():""}},{key:"getNextRedoCommandText",value:function(){return this.undoStackPointer0&&this.undoStack[--this.undoStackPointer].unapply(this.handler_)}},{key:"redo",value:function(){this.undoStackPointer0&&this.undoStack[this.undoStackPointer++].apply(this.handler_)}},{key:"addCommandToHistory",value:function(e){this.undoStackPointer0&&(this.undoStack=this.undoStack.splice(0,this.undoStackPointer)),this.undoStack.push(e),this.undoStackPointer=this.undoStack.length}},{key:"beginUndoableChange",value:function(e,t){for(var n=++this.undoChangeStackPointer,r=t.length,a=new Array(r),i=new Array(r);r--;){var o=t[r];an(o)||(i[r]=o,a[r]=o.getAttribute(e))}this.undoableChangeStack[n]={attrName:e,oldValues:a,elements:i}}},{key:"finishUndoableChange",value:function(){for(var e=this.undoChangeStackPointer--,t=this.undoableChangeStack[e],n=t.attrName,r=new ge("Change "+n),a=t.elements.length;a--;){var i=t.elements[a];if(!an(i)){var o={};o[n]=t.oldValues[a],o[n]!==i.getAttribute(n)&&r.addSubCommand(new fe(i,o,n))}}return this.undoableChangeStack[e]=null,r}}]),e}(),we=Object.freeze({HistoryEventTypes:ce,MoveElementCommand:de,InsertElementCommand:he,RemoveElementCommand:pe,ChangeElementCommand:fe,BatchCommand:ge,UndoManager:xe}),Se=document.createElementNS(f.SVG,"svg"),ke=function(e,t,n){return{x:n.a*e+n.c*t+n.e,y:n.b*e+n.d*t+n.f}},Ce=function(e){return 1===e.a&&0===e.b&&0===e.c&&1===e.d&&0===e.e&&0===e.f},Ae=function(){for(var e=arguments.length,t=new Array(e),n=0;n(n=parseInt(n))){var r=n;n=t,t=r}for(var a=Se.createSVGMatrix(),i=t;i<=n;++i){var o=i>=0&&ie.x&&t.ye.y},Le=jQuery,Me={2:["x","y"],4:["x","y"],6:["x","y","x1","y1","x2","y2"],8:["x","y","x1","y1"],10:["x","y","r1","r2","angle","largeArcFlag","sweepFlag"],12:["x"],14:["y"],16:["x","y","x2","y2"],18:["x","y"]},Oe={},je=function(e){Object.assign(Oe,e.ui)},Ve=[],Re=!0,Be={},De=null,Ue=null,Fe=function(e){Ue=e,Ve=[0,"ClosePath"];Le.each(["Moveto","Lineto","CurvetoCubic","CurvetoQuadratic","Arc","LinetoHorizontal","LinetoVertical","CurvetoCubicSmooth","CurvetoQuadraticSmooth"],function(e,t){Ve.push(t+"Abs"),Ve.push(t+"Rel")})},He=function(e,t,n){var r=e.pathSegList;if(I)r.insertItemBefore(t,n);else{for(var a=r.numberOfItems,i=[],o=0;o0?(p=g element");this.elem=t,this.segs=[],this.selected_pts=[],De=this,this.init()}return i(e,[{key:"init",value:function(){Le(Xe()).find("*").each(function(){Le(this).attr("display","none")});var e=this.elem.pathSegList,t=e.numberOfItems;this.segs=[],this.selected_pts=[],this.first_seg=null;for(var n=0;n=t?null:i[s+1],u=s-1<0?null:i[s-1];if(2===l.type){if(u&&1!==u.type){var d=i[o];d.next=i[o+1],d.next.prev=d,d.addGrip()}o=s}else if(c&&1===c.type)l.next=i[o+1],l.next.prev=l,l.mate=i[o],l.addGrip(),an(this.first_seg)&&(this.first_seg=l);else if(c)1!==l.type&&(l.addGrip(),c&&2!==c.type&&(l.next=c,l.next.prev=l));else if(1!==l.type){var h=i[o];h.next=i[o+1],h.next.prev=h,h.addGrip(),l.addGrip(),this.first_seg||(this.first_seg=i[o])}}return this}},{key:"eachSeg",value:function(e){for(var t=this.segs.length,n=0;n=0&&n.selected_pts.push(e)}),this.selected_pts.sort();var r=this.selected_pts.length,a=[];for(a.length=r;r--;){var i=this.selected_pts[r],o=this.segs[i];o.select(!0),a[r]=o.ptgrip}var s=e.subpathIsClosed(this.selected_pts[0]);Ue.addPtsToSelection({grips:a,closedSubpath:s})}}],[{key:"subpathIsClosed",value:function(e){var t=!1;return De.eachSeg(function(n){return n<=e||2!==this.type&&(1!==this.type||(t=!0,!1))}),t}}]),e}(),rt=function(e){var t=Be[e.id];return t||(t=Be[e.id]=new nt(e)),t},at=function(e){e in Be&&delete Be[e]},it=function(e,t){var n=e-ye,r=t-_e,a=Math.sqrt(n*n+r*r),i=Math.atan2(r,n)+be;return n=a*Math.cos(i)+ye,r=a*Math.sin(i)+_e,n-=me,r-=ve,a=Math.sqrt(n*n+r*r),i=Math.atan2(r,n)-be,{x:a*Math.cos(i)+me,y:a*Math.sin(i)+ve}},ot=function(){var e=De.elem;if(be=Zt(e,!0)){var t=De.oldbbox;ye=t.x+t.width/2,_e=t.y+t.height/2;var n=Dt(e);me=n.x+n.width/2,ve=n.y+n.height/2;var r=me-ye,a=ve-_e,i=Math.sqrt(r*r+a*a),o=Math.atan2(a,r)+be;me=i*Math.cos(o)+ye,ve=i*Math.sin(o)+_e;for(var s=e.pathSegList,l=s.numberOfItems;l;){l-=1;var c=s.getItem(l),u=c.pathSegType;if(1!==u){var d=it(c.x,c.y),h=[d.x,d.y];if(!an(c.x1)&&!an(c.x2)){var p=it(c.x1,c.y1),f=it(c.x2,c.y2);h.splice(h.length,0,p.x,p.y,f.x,f.y)}$e(u,l,h)}}Dt(e);var g=Ue.getSVGRoot().createSVGTransform(),m=$(e);g.setRotate(180*be/Math.PI,me,ve),m.replaceItem(g,0)}},st=[0,"z","M","m","L","l","C","c","Q","q","A","a","H","h","V","v","S","s","T","t"],lt=function(e,t){for(var n=e.pathSegList,r=n.numberOfItems,a=0,i=0,o="",s=null,l=0;l=C-w&&g<=C+w&&m>=A-w&&m<=A+w){S=!0;break}}a=Ue.getId(),at(a);var E,G,P=Jt(a),I=b.numberOfItems;if(S){if(x<=1&&I>=2){var N=b.getItem(0).x,T=b.getItem(0).y;E=4===(G=v.pathSegList.getItem(1)).pathSegType?_.createSVGPathSegLinetoAbs(N,T):_.createSVGPathSegCurvetoCubicAbs(N,T,G.x1/p,G.y1/p,N,T);var L=_.createSVGPathSegClosePath();b.appendItem(E),b.appendItem(L)}else if(I<3)return!1;if(Le(v).remove(),Ue.setDrawnPath(null),Ue.setStarted(!1),ht){De.matrix&&Ue.remapElement(P,{},De.matrix.inverse());var M=P.getAttribute("d"),O=Le(De.elem).attr("d");return Le(De.elem).attr("d",O+M),Le(P).remove(),De.matrix&&ot(),Fe(),gt.toEditMode(De.elem),De.selectPt(),!1}}else{if(!Le.contains(Ue.getContainer(),Ue.getMouseTarget(e)))return!1;var j=_.pathSegList.numberOfItems,V=_.pathSegList.getItem(j-1),R=V.x,B=V.y;if(e.shiftKey){var D=Ne(R,B,g,m);g=D.x,m=D.y}E=4===(G=v.pathSegList.getItem(1)).pathSegType?_.createSVGPathSegLinetoAbs(Ue.round(g),Ue.round(m)):_.createSVGPathSegCurvetoCubicAbs(Ue.round(g),Ue.round(m),G.x1/p,G.y1/p,G.x2/p,G.y2/p),_.pathSegList.appendItem(E),g*=p,m*=p,v.setAttribute("d",["M",g,m,g,m].join(" ")),y=j,ht&&(y+=De.segs.length),We(y,g,m)}}else{var U="M"+g+","+m+" ";Ue.setDrawnPath(Ue.addSVGElementFromJson({element:"path",curStyles:!0,attr:{d:U,id:Ue.getNextId(),opacity:Ue.getOpacity()/2}})),v.setAttribute("d",["M",d,h,d,h].join(" ")),y=ht?De.segs.length:0,We(y,d,h)}}},mouseMove:function(e,t){var n=Ue.getCurrentZoom();ft=!0;var r=Ue.getDrawnPath();if("path"!==Ue.getCurrentMode())if(De.dragging){var a=Ye({x:De.dragging[0],y:De.dragging[1]},De),i=Ye({x:e,y:t},De),o=i.x-a.x,s=i.y-a.y;De.dragging=[e,t],De.dragctrl?De.moveCtrl(o,s):De.movePts(o,s)}else De.selected_pts=[],De.eachSeg(function(e){if(this.next||this.prev){var t=Ue.getRubberBox().getBBox(),n=qe(this),r={x:n.x,y:n.y,width:0,height:0},a=Te(t,r);this.select(a),a&&De.selected_pts.push(this.index)}});else{if(!r)return;var l=r.pathSegList,c=l.numberOfItems-1;if(ut){var u=Qe("1c1"),d=Qe("0c2");u.setAttribute("cx",e),u.setAttribute("cy",t),u.setAttribute("display","inline");var h=ut[0],p=ut[1],f=h+(h-e/n),g=p+(p-t/n);d.setAttribute("cx",f*n),d.setAttribute("cy",g*n),d.setAttribute("display","inline");var m=Ke(1);if(en(m,{x1:e,y1:t,x2:f*n,y2:g*n,display:"inline"}),0===c)dt=[e,t];else{var v=l.getItem(c-1),y=v.x,_=v.y;6===v.pathSegType?(y+=y-v.x2,_+=_-v.y2):dt&&(y=dt[0]/n,_=dt[1]/n),$e(6,c,[h,p,y,_,f,g],r)}}else{var b=Jt("path_stretch_line");if(b){var x=l.getItem(c);if(6===x.pathSegType){var w=x.x+(x.x-x.x2),S=x.y+(x.y-x.y2);$e(6,1,[e,t,w*n,S*n,e,t],b)}else dt?$e(6,1,[e,t,dt[0],dt[1],e,t],b):$e(4,1,[e,t],b)}}}},mouseUp:function(e,t,n,r){var a=Ue.getDrawnPath();if("path"===Ue.getCurrentMode())return ut=null,a||(t=Jt(Ue.getId()),Ue.setStarted(!1),dt=null),{keep:!0,element:t};var i=Ue.getRubberBox();if(De.dragging){var o=De.cur_pt;De.dragging=!1,De.dragctrl=!1,De.update(),ft&&De.endChanges("Move path point(s)"),e.shiftKey||ft||De.selectPt(o)}else i&&"none"!==i.getAttribute("display")?(i.setAttribute("display","none"),i.getAttribute("width")<=2&&i.getAttribute("height")<=2&>.toSelectMode(e.target)):gt.toSelectMode(e.target);ft=!1},toEditMode:function(e){De=rt(e),Ue.setCurrentMode("pathedit"),Ue.clearSelection(),De.show(!0).update(),De.oldbbox=Dt(De.elem),ht=!1},toSelectMode:function(e){var t=e===De.elem;Ue.setCurrentMode("select"),De.show(!1),pt=!1,Ue.clearSelection(),De.matrix&&ot(),t&&(Ue.call("selected",[e]),Ue.addToSelection([e],!0))},addSubPath:function(e){e?(Ue.setCurrentMode("path"),ht=!0):(gt.clear(!0),gt.toEditMode(De.elem))},select:function(e){pt===e?(gt.toEditMode(e),Ue.setCurrentMode("pathedit")):pt=e},reorient:function(){var e=Ue.getSelectedElements()[0];if(e&&0!==Zt(e)){var t=new ge("Reorient path"),n={d:e.getAttribute("d"),transform:e.getAttribute("transform")};t.addSubCommand(new fe(e,n)),Ue.clearSelection(),this.resetOrientation(e),Ue.addCommandToHistory(t),rt(e).show(!1).matrix=null,this.clear(),Ue.addToSelection([e],!0),Ue.call("changed",Ue.getSelectedElements())}},clear:function(e){var t=Ue.getDrawnPath();if(pt=null,t){var n=Jt(Ue.getId());Le(Jt("path_stretch_line")).remove(),Le(n).remove(),Le(Jt("pathpointgrip_container")).find("*").attr("display","none"),dt=null,Ue.setDrawnPath(null),Ue.setStarted(!1)}else"pathedit"===Ue.getCurrentMode()&&this.toSelectMode();De&&De.init().show(!1)},resetOrientation:function(e){if(an(e)||"path"!==e.nodeName)return!1;var t=$(e),n=Pe(t).matrix;t.clear(),e.removeAttribute("transform");for(var r=e.pathSegList,a=r.numberOfItems,i=function(t){var a=r.getItem(t),i=a.pathSegType;if(1===i)return"continue";var o=[];Le.each(["",1,2],function(e,t){var r=a["x"+t],i=a["y"+t];if(void 0!==r&&void 0!==i){var s=ke(r,i,n);o.splice(o.length,0,s.x,s.y)}}),$e(i,t,o,e)},o=0;o0){var s=t.getItem(n-1).pathSegType;if(2===s){r(n-1,1),e();break}if(1===s&&t.numberOfItems-1===n){r(n,1),e();break}}}return!1}(),De.elem.pathSegList.numberOfItems<=1)return gt.toSelectMode(De.elem),void Ue.canvas.deleteSelectedElements();if(De.init(),De.clearSelection(),window.opera){var r=Le(De.elem);r.attr("d",r.attr("d"))}De.endChanges("Delete path node(s)")}},smoothPolylineIntoPath:function(e){var t,n=e.points,r=n.numberOfItems;if(r>=4){var a=n.getItem(0),i=null,o=[];for(o.push(["M",a.x,",",a.y," C"].join("")),t=1;t<=r-4;t+=3){var s=n.getItem(t),l=n.getItem(t+1),c=n.getItem(t+2);if(i){var u=et(i,s,a);if(u&&2===u.length){var d=o[o.length-1].split(",");d[2]=u[0].x,d[3]=u[0].y,o[o.length-1]=d.join(","),s=u[1]}}o.push([s.x,s.y,l.x,l.y,c.x,c.y].join(",")),a=c,i=l}for(o.push("L");t)/,"$1$2")},kt=function(e){return e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")};function Ct(e){if(e=Gt(e),window.btoa)return window.btoa(e);var t=new Array(4*Math.floor((e.length+2)/3)),n=0,r=0;do{var a=e.charCodeAt(n++),i=e.charCodeAt(n++),o=e.charCodeAt(n++),s=a>>2,l=(3&a)<<4|i>>4,c=(15&i)<<2|o>>6,u=63&o;isNaN(i)?(c=64,u=64):isNaN(o)&&(u=64),t[r++]=vt.charAt(s),t[r++]=vt.charAt(l),t[r++]=vt.charAt(c),t[r++]=vt.charAt(u)}while(n>4,l=(15&a)<<4|i>>2,c=(3&i)<<6|o;t+=String.fromCharCode(s),64!==i&&(t+=String.fromCharCode(l)),64!==o&&(t+=String.fromCharCode(c))}while(nSVG-edit "],{type:"text/html"});return It(e)}(),Tt=function(e){var t,n;e.includes("0?t=t[0]:(t=e.ownerDocument.createElementNS(f.SVG,"defs"),e.firstChild?e.insertBefore(t,e.firstChild.nextSibling):e.append(t)),t},Rt=function(e){for(var t=e.pathSegList,n=t.numberOfItems,r=[[],[]],a=t.getItem(0),i=[a.x,a.y],o=function(e,t,n,r){return function(a){return 1-Math.pow(a,3)*i[e]+3-Math.pow(a,2)*a*t[e]+3*(1-a)*Math.pow(a,2)*n[e]+Math.pow(a,3)*r[e]}},s=0;s0&&y<1&&r[h].push(p(y));var _=(-f-Math.sqrt(v))/(2*g);_>0&&_<1&&r[h].push(p(_))}}else{if(0===f)continue;var b=-m/f;b>0&&b<1&&r[h].push(p(b))}}i=d}else r[0].push(l.x),r[1].push(l.y)}var x=Math.min.apply(null,r[0]),w=Math.max.apply(null,r[0])-x,S=Math.min.apply(null,r[1]);return{x:x,y:S,width:w,height:Math.max.apply(null,r[1])-S}};function Bt(e){if(H())try{return e.getBBox()}catch(e){}var t,n,r=mt.data(e,"ref"),a=null;r?(n=mt(r).children().clone().attr("visibility","hidden"),mt(wt).append(n),a=n.filter("line, path")):a=mt(e).find("line, path");var i=!1;if(a.length)if(a.each(function(){var e=this.getBBox();e.width&&e.height||(i=!0)}),i){var o=r?n:mt(e).children();t=Wt(o)}else t=e.getBBox();else t=e.getBBox();return r&&n.remove(),t}var Dt=function(e){var t=e||_t.geSelectedElements()[0];if(1!==e.nodeType)return null;var n,r=t.nodeName,a=null;switch(r){case"text":""===t.textContent?(t.textContent="a",a=t.getBBox(),t.textContent=""):t.getBBox&&(a=t.getBBox());break;case"path":T?t.getBBox&&(a=t.getBBox()):a=Rt(t);break;case"g":case"a":a=Bt(t);break;default:if("use"===r&&(a=Bt(t)),"use"===r||"foreignObject"===r&&V()){if(a||(a=t.getBBox()),!V()){var i={};i.width=a.width,i.height=a.height,i.x=a.x+parseFloat(t.getAttribute("x")||0),i.y=a.y+parseFloat(t.getAttribute("y")||0),a=i}}else if(yt.includes(r))if(t)try{a=t.getBBox()}catch(e){var o=t.getExtentOfChar(0),s=t.getComputedTextLength();a={x:o.x,y:o.y,width:s,height:o.height}}else{var l=mt(t).closest("foreignObject");l.length&&l[0].getBBox&&(a=l[0].getBBox())}}return a&&(a={x:(n=a).x,y:n.y,width:n.width,height:n.height}),a},Ut=function(e){var t="";return mt.each(e,function(e,n){var r=d(n,2),a=r[0],i=r[1];t+=a;for(var o=0;o-.001&&n<.001||n<-89.99||n>89.99)}(i,o)){if(["ellipse","path","line","polyline","polygon"].includes(e.tagName))r=s=zt(e,t,n);else if("rect"===e.tagName){var l=e.getAttribute("rx"),c=e.getAttribute("ry");(l||c)&&(r=s=zt(e,t,n))}}if(!s){var u=Pe(a).matrix;r=Ge(r.x,r.y,r.width,r.height,u).aabox}}return r};function Yt(e){var t=e.getAttribute("stroke-width");return isNaN(t)||"none"===e.getAttribute("stroke")?0:t/2}var Wt=function(e,t,n){if(!e||!e.length)return!1;var r;if(mt.each(e,function(){r||this.parentNode&&(r=qt(this,t,n))}),void 0===r)return null;var a=r.x+r.width,i=r.y+r.height,o=r.x,s=r.y;if(1===e.length){var l=Yt(e[0]);o-=l,s-=l,a+=l,i+=l}else mt.each(e,function(e,r){var l=qt(r,t,n);if(l){var c=Yt(r);o=Math.min(o,l.x-c),s=Math.min(s,l.y-c),1===r.nodeType&&(a=Math.max(a,l.x+l.width+c),i=Math.max(i,l.y+l.height+c))}});return r.x=o,r.y=s,r.width=a-o,r.height=i-s,r},Xt=function(e){e||(e=mt(_t.getSVGContent()).children());var t=[];return mt(e).children().each(function(e,n){n.getBBox&&t.push(n)}),t.reverse()},Qt=function(e){return e||(e=Xt()),Wt(e,_t.addSVGElementFromJson,_t.pathActions)},Kt=function(e,t){if(!e)return 0;for(var n=e.numberOfItems,r=0;r");var t=e.shortcut||"";on("#cmenu_canvas").append("
  • "+e.label+""+t+"
  • ")}(e)})};function cn(e,t){["id","class","type"].forEach(function(n){n in t&&(e[n]=t[n])})}function un(e,t){return dn(e,o({},t,{returnDefault:!0}))}function dn(e,t){return hn.apply(this,arguments)}function hn(){return(hn=n(regeneratorRuntime.mark(function e(t,n){var r,a;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=n.global,a=n.returnDefault,!!("svgEditor"in window&&window.svgEditor&&!1===window.svgEditor.modules)){e.next=4;break}return e.abrupt("return",fn(t,void 0,{returnDefault:a}));case 4:return e.next=6,pn(t);case 6:return e.abrupt("return",window[r]);case 7:case"end":return e.stop()}},e)}))).apply(this,arguments)}function pn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Array.isArray(e)?Promise.all(e.map(function(e){return pn(e,t)})):new Promise(function(n,r){var a=document.createElement("script");function i(){r(new Error("Failed to import: ".concat(e))),s()}function o(){n(),s()}var s=function(){a.removeEventListener("error",i),a.removeEventListener("load",o),a.remove(),a.src=""};a.defer="defer",cn(a,t),a.addEventListener("error",i),a.addEventListener("load",o),a.src=e,document.head.append(a)})}function fn(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).returnDefault,r=void 0!==n&&n;return Array.isArray(e)?Promise.all(e.map(function(e){return fn(e,t)})):new Promise(function(n,a){var i="$importModule$"+Math.random().toString(32).slice(2),o=document.createElement("script");function s(){a(new Error("Failed to import: ".concat(e))),c()}function l(){n(window[i]),c()}var c=function(){delete window[i],o.removeEventListener("error",s),o.removeEventListener("load",l),o.remove(),URL.revokeObjectURL(o.src),o.src=""};cn(o,t),o.defer="defer",o.type="module",o.addEventListener("error",s),o.addEventListener("load",l);var u=function(e){var t=document.createElement("a");return t.setAttribute("href",e),t.cloneNode(!1).href}(e),d="import * as m from '".concat(u.replace(/'/g,"\\'"),"'; window.").concat(i," = ").concat(r?"m.default || ":"","m;"),h=new Blob([d],{type:"text/javascript"});o.src=URL.createObjectURL(h),document.head.append(o)})}function gn(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{ok:"Ok",cancel:"Cancel"};t("#dialog_container").draggable({cancel:"#dialog_content, #dialog_buttons *",containment:"window"}).css("position","absolute");var r=t("#dialog_box"),a=t("#dialog_buttons"),i=t("#dialog_content");function o(o,s,l,c,u,d){i.html("

    "+s.replace(/\n/g,"

    ")+"

    ").toggleClass("prompt","prompt"===o),a.empty();var h=t('').appendTo(a);return new Promise(function(p,f){var g,m;if("alert"!==o&&t('').appendTo(a).click(function(){r.hide(),p(!1)}),"prompt"===o)(g=t('').prependTo(a)).val(l||""),g.bind("keydown","return",function(){h.click()});else if("select"===o){var v=t('
    ');if(g=t('').appendTo(y)).val(d.value),d.tooltip&&y.attr("title",d.tooltip),m.prop("checked",Boolean(d.checked)),v.append(t("
    ").append(y))}t.each(c||[],function(n,r){"object"===e(r)?g.append(t("