UNPKG

301 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
6var _parseFloat = require('@babel/runtime-corejs3/core-js-stable/parse-float');
7var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
8var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
9var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
10var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
11var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
12var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
13var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
14var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
15var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
16var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
17var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
18var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
19var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
20var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
21var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
22var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
24var _Date$now = require('@babel/runtime-corejs3/core-js-stable/date/now');
25var _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
26var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
27var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
28var requestAnimationFrame = require('raf');
29var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
30var RGBColor = require('rgbcolor');
31var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
32var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
33var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
34var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
35var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
36var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
37var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
38var _Array$from = require('@babel/runtime-corejs3/core-js-stable/array/from');
39var _reverseInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reverse');
40var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
41var _get = require('@babel/runtime-corejs3/helpers/get');
42var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
43var svgPathdata = require('svg-pathdata');
44var _Reflect$deleteProperty = require('@babel/runtime-corejs3/core-js-stable/reflect/delete-property');
45var _assertThisInitialized = require('@babel/runtime-corejs3/helpers/assertThisInitialized');
46var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
47var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
48var _getIterator = require('@babel/runtime-corejs3/core-js/get-iterator');
49var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
50var _getIteratorMethod = require('@babel/runtime-corejs3/core-js/get-iterator-method');
51var _Symbol = require('@babel/runtime-corejs3/core-js-stable/symbol');
52var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
53var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
54var _Reflect$apply = require('@babel/runtime-corejs3/core-js-stable/reflect/apply');
55var _Reflect$getPrototypeOf = require('@babel/runtime-corejs3/core-js-stable/reflect/get-prototype-of');
56var stackblurCanvas = require('stackblur-canvas');
57
58function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
59
60var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_startsWithInstanceProperty);
61var _parseFloat__default = /*#__PURE__*/_interopDefaultLegacy(_parseFloat);
62var _mapInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_mapInstanceProperty);
63var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
64var _Object$defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_Object$defineProperty);
65var _Object$defineProperties__default = /*#__PURE__*/_interopDefaultLegacy(_Object$defineProperties);
66var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefaultLegacy(_Object$getOwnPropertyDescriptors);
67var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_forEachInstanceProperty);
68var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefaultLegacy(_Object$getOwnPropertyDescriptor);
69var _filterInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_filterInstanceProperty);
70var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefaultLegacy(_Object$getOwnPropertySymbols);
71var _Object$keys__default = /*#__PURE__*/_interopDefaultLegacy(_Object$keys);
72var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
73var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
74var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
75var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
76var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
77var _concatInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_concatInstanceProperty);
78var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_reduceInstanceProperty);
79var _Date$now__default = /*#__PURE__*/_interopDefaultLegacy(_Date$now);
80var _everyInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_everyInstanceProperty);
81var _Promise__default = /*#__PURE__*/_interopDefaultLegacy(_Promise);
82var _bindInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_bindInstanceProperty);
83var requestAnimationFrame__default = /*#__PURE__*/_interopDefaultLegacy(requestAnimationFrame);
84var _trimInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_trimInstanceProperty);
85var RGBColor__default = /*#__PURE__*/_interopDefaultLegacy(RGBColor);
86var _Reflect$construct__default = /*#__PURE__*/_interopDefaultLegacy(_Reflect$construct);
87var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
88var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
89var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
90var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
91var _someInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_someInstanceProperty);
92var _includesInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_includesInstanceProperty);
93var _Array$from__default = /*#__PURE__*/_interopDefaultLegacy(_Array$from);
94var _reverseInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_reverseInstanceProperty);
95var _indexOfInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_indexOfInstanceProperty);
96var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get);
97var _fillInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_fillInstanceProperty);
98var _Reflect$deleteProperty__default = /*#__PURE__*/_interopDefaultLegacy(_Reflect$deleteProperty);
99var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
100var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_valuesInstanceProperty);
101var _parseInt__default = /*#__PURE__*/_interopDefaultLegacy(_parseInt);
102var _getIterator__default = /*#__PURE__*/_interopDefaultLegacy(_getIterator);
103var _Array$isArray__default = /*#__PURE__*/_interopDefaultLegacy(_Array$isArray);
104var _getIteratorMethod__default = /*#__PURE__*/_interopDefaultLegacy(_getIteratorMethod);
105var _Symbol__default = /*#__PURE__*/_interopDefaultLegacy(_Symbol);
106var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefaultLegacy(_sliceInstanceProperty);
107var _Map__default = /*#__PURE__*/_interopDefaultLegacy(_Map);
108var _Reflect$apply__default = /*#__PURE__*/_interopDefaultLegacy(_Reflect$apply);
109var _Reflect$getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_Reflect$getPrototypeOf);
110
111/**
112 * HTML-safe compress white-spaces.
113 * @param str - String to compress.
114 */
115function compressSpaces(str) {
116 return str.replace(/(?!\u3000)\s+/gm, ' ');
117}
118/**
119 * HTML-safe left trim.
120 * @param str - String to trim.
121 */
122
123function trimLeft(str) {
124 return str.replace(/^[\n \t]+/, '');
125}
126/**
127 * HTML-safe right trim.
128 * @param str - String to trim.
129 */
130
131function trimRight(str) {
132 return str.replace(/[\n \t]+$/, '');
133}
134/**
135 * String to numbers array.
136 * @param str - Numbers string.
137 */
138
139function toNumbers(str) {
140 var matches = (str || '').match(/-?(\d+(?:\.\d*(?:[eE][+-]?\d+)?)?|\.\d+)(?=\D|$)/gm) || [];
141 return _mapInstanceProperty__default['default'](matches).call(matches, _parseFloat__default['default']);
142} // Microsoft Edge fix
143
144var allUppercase = /^[A-Z-]+$/;
145/**
146 * Normalize attribute name.
147 * @param name - Attribute name.
148 */
149
150function normalizeAttributeName(name) {
151 if (allUppercase.test(name)) {
152 return name.toLowerCase();
153 }
154
155 return name;
156}
157/**
158 * Parse external URL.
159 * @param url - CSS url string.
160 */
161
162function parseExternalUrl(url) {
163 // single quotes [2]
164 // v double quotes [3]
165 // v v no quotes [4]
166 // v v v
167 var urlMatch = url.match(/url\(('([^']+)'|"([^"]+)"|([^'"\)]+))\)/) || [];
168 return urlMatch[2] || urlMatch[3] || urlMatch[4];
169}
170/**
171 * Transform floats to integers in rgb colors.
172 * @param color - Color to normalize.
173 */
174
175function normalizeColor(color) {
176 if (!_startsWithInstanceProperty__default['default'](color).call(color, 'rgb')) {
177 return color;
178 }
179
180 var rgbParts = 3;
181 var normalizedColor = color.replace(/\d+(\.\d+)?/g, function (num, isFloat) {
182 return rgbParts-- && isFloat ? String(Math.round(_parseFloat__default['default'](num))) : num;
183 });
184 return normalizedColor;
185}
186
187// slightly modified version of https://github.com/keeganstreet/specificity/blob/master/specificity.js
188var attributeRegex = /(\[[^\]]+\])/g;
189var idRegex = /(#[^\s\+>~\.\[:]+)/g;
190var classRegex = /(\.[^\s\+>~\.\[:]+)/g;
191var pseudoElementRegex = /(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi;
192var pseudoClassWithBracketsRegex = /(:[\w-]+\([^\)]*\))/gi;
193var pseudoClassRegex = /(:[^\s\+>~\.\[:]+)/g;
194var elementRegex = /([^\s\+>~\.\[:]+)/g;
195
196function findSelectorMatch(selector, regex) {
197 var matches = selector.match(regex);
198
199 if (!matches) {
200 return [selector, 0];
201 }
202
203 return [selector.replace(regex, ' '), matches.length];
204}
205/**
206 * Measure selector specificity.
207 * @param selector - Selector to measure.
208 */
209
210
211function getSelectorSpecificity(selector) {
212 var specificity = [0, 0, 0];
213 var currentSelector = selector.replace(/:not\(([^\)]*)\)/g, ' $1 ').replace(/{[\s\S]*/gm, ' ');
214 var delta = 0;
215
216 var _findSelectorMatch = findSelectorMatch(currentSelector, attributeRegex);
217
218 var _findSelectorMatch2 = _slicedToArray__default['default'](_findSelectorMatch, 2);
219
220 currentSelector = _findSelectorMatch2[0];
221 delta = _findSelectorMatch2[1];
222 specificity[1] += delta;
223
224 var _findSelectorMatch3 = findSelectorMatch(currentSelector, idRegex);
225
226 var _findSelectorMatch4 = _slicedToArray__default['default'](_findSelectorMatch3, 2);
227
228 currentSelector = _findSelectorMatch4[0];
229 delta = _findSelectorMatch4[1];
230 specificity[0] += delta;
231
232 var _findSelectorMatch5 = findSelectorMatch(currentSelector, classRegex);
233
234 var _findSelectorMatch6 = _slicedToArray__default['default'](_findSelectorMatch5, 2);
235
236 currentSelector = _findSelectorMatch6[0];
237 delta = _findSelectorMatch6[1];
238 specificity[1] += delta;
239
240 var _findSelectorMatch7 = findSelectorMatch(currentSelector, pseudoElementRegex);
241
242 var _findSelectorMatch8 = _slicedToArray__default['default'](_findSelectorMatch7, 2);
243
244 currentSelector = _findSelectorMatch8[0];
245 delta = _findSelectorMatch8[1];
246 specificity[2] += delta;
247
248 var _findSelectorMatch9 = findSelectorMatch(currentSelector, pseudoClassWithBracketsRegex);
249
250 var _findSelectorMatch10 = _slicedToArray__default['default'](_findSelectorMatch9, 2);
251
252 currentSelector = _findSelectorMatch10[0];
253 delta = _findSelectorMatch10[1];
254 specificity[1] += delta;
255
256 var _findSelectorMatch11 = findSelectorMatch(currentSelector, pseudoClassRegex);
257
258 var _findSelectorMatch12 = _slicedToArray__default['default'](_findSelectorMatch11, 2);
259
260 currentSelector = _findSelectorMatch12[0];
261 delta = _findSelectorMatch12[1];
262 specificity[1] += delta;
263 currentSelector = currentSelector.replace(/[\*\s\+>~]/g, ' ').replace(/[#\.]/g, ' ');
264
265 var _findSelectorMatch13 = findSelectorMatch(currentSelector, elementRegex);
266
267 var _findSelectorMatch14 = _slicedToArray__default['default'](_findSelectorMatch13, 2);
268
269 currentSelector = _findSelectorMatch14[0];
270 delta = _findSelectorMatch14[1];
271 // lgtm [js/useless-assignment-to-local]
272 specificity[2] += delta;
273 return specificity.join('');
274}
275
276var PSEUDO_ZERO = .00000001;
277/**
278 * Vector magnitude.
279 */
280
281function vectorMagnitude(v) {
282 return Math.sqrt(Math.pow(v[0], 2) + Math.pow(v[1], 2));
283}
284/**
285 * Ratio between two vectors.
286 */
287
288function vectorsRatio(u, v) {
289 return (u[0] * v[0] + u[1] * v[1]) / (vectorMagnitude(u) * vectorMagnitude(v));
290}
291/**
292 * Angle between two vectors.
293 */
294
295function vectorsAngle(u, v) {
296 return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vectorsRatio(u, v));
297}
298function CB1(t) {
299 return t * t * t;
300}
301function CB2(t) {
302 return 3 * t * t * (1 - t);
303}
304function CB3(t) {
305 return 3 * t * (1 - t) * (1 - t);
306}
307function CB4(t) {
308 return (1 - t) * (1 - t) * (1 - t);
309}
310function QB1(t) {
311 return t * t;
312}
313function QB2(t) {
314 return 2 * t * (1 - t);
315}
316function QB3(t) {
317 return (1 - t) * (1 - t);
318}
319
320var Property = /*#__PURE__*/function () {
321 function Property(document, name, value) {
322 _classCallCheck__default['default'](this, Property);
323
324 this.document = document;
325 this.name = name;
326 this.value = value;
327 this.isNormalizedColor = false;
328 }
329
330 _createClass__default['default'](Property, [{
331 key: "split",
332 value: function split() {
333 var _context, _context2;
334
335 var separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ' ';
336 var document = this.document,
337 name = this.name;
338 return _mapInstanceProperty__default['default'](_context = _trimInstanceProperty__default['default'](_context2 = compressSpaces(this.getString())).call(_context2).split(separator)).call(_context, function (value) {
339 return new Property(document, name, value);
340 });
341 }
342 }, {
343 key: "hasValue",
344 value: function hasValue(zeroIsValue) {
345 var value = this.value;
346 return value !== null && value !== '' && (zeroIsValue || value !== 0) && typeof value !== 'undefined';
347 }
348 }, {
349 key: "isString",
350 value: function isString(regexp) {
351 var value = this.value;
352 var result = typeof value === 'string';
353
354 if (!result || !regexp) {
355 return result;
356 }
357
358 return regexp.test(value);
359 }
360 }, {
361 key: "isUrlDefinition",
362 value: function isUrlDefinition() {
363 return this.isString(/^url\(/);
364 }
365 }, {
366 key: "isPixels",
367 value: function isPixels() {
368 if (!this.hasValue()) {
369 return false;
370 }
371
372 var asString = this.getString();
373
374 switch (true) {
375 case /px$/.test(asString):
376 case /^[0-9]+$/.test(asString):
377 return true;
378
379 default:
380 return false;
381 }
382 }
383 }, {
384 key: "setValue",
385 value: function setValue(value) {
386 this.value = value;
387 return this;
388 }
389 }, {
390 key: "getValue",
391 value: function getValue(def) {
392 if (typeof def === 'undefined' || this.hasValue()) {
393 return this.value;
394 }
395
396 return def;
397 }
398 }, {
399 key: "getNumber",
400 value: function getNumber(def) {
401 if (!this.hasValue()) {
402 if (typeof def === 'undefined') {
403 return 0;
404 }
405
406 return _parseFloat__default['default'](def);
407 }
408
409 var value = this.value;
410
411 var n = _parseFloat__default['default'](value);
412
413 if (this.isString(/%$/)) {
414 n = n / 100.0;
415 }
416
417 return n;
418 }
419 }, {
420 key: "getString",
421 value: function getString(def) {
422 if (typeof def === 'undefined' || this.hasValue()) {
423 return typeof this.value === 'undefined' ? '' : String(this.value);
424 }
425
426 return String(def);
427 }
428 }, {
429 key: "getColor",
430 value: function getColor(def) {
431 var color = this.getString(def);
432
433 if (this.isNormalizedColor) {
434 return color;
435 }
436
437 this.isNormalizedColor = true;
438 color = normalizeColor(color);
439 this.value = color;
440 return color;
441 }
442 }, {
443 key: "getDpi",
444 value: function getDpi() {
445 return 96.0; // TODO: compute?
446 }
447 }, {
448 key: "getRem",
449 value: function getRem() {
450 return this.document.rootEmSize;
451 }
452 }, {
453 key: "getEm",
454 value: function getEm() {
455 return this.document.emSize;
456 }
457 }, {
458 key: "getUnits",
459 value: function getUnits() {
460 return this.getString().replace(/[0-9\.\-]/g, '');
461 }
462 }, {
463 key: "getPixels",
464 value: function getPixels(axisOrIsFontSize) {
465 var processPercent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
466
467 if (!this.hasValue()) {
468 return 0;
469 }
470
471 var _ref = typeof axisOrIsFontSize === 'boolean' ? [undefined, axisOrIsFontSize] : [axisOrIsFontSize],
472 _ref2 = _slicedToArray__default['default'](_ref, 2),
473 axis = _ref2[0],
474 isFontSize = _ref2[1];
475
476 var viewPort = this.document.screen.viewPort;
477
478 switch (true) {
479 case this.isString(/vmin$/):
480 return this.getNumber() / 100.0 * Math.min(viewPort.computeSize('x'), viewPort.computeSize('y'));
481
482 case this.isString(/vmax$/):
483 return this.getNumber() / 100.0 * Math.max(viewPort.computeSize('x'), viewPort.computeSize('y'));
484
485 case this.isString(/vw$/):
486 return this.getNumber() / 100.0 * viewPort.computeSize('x');
487
488 case this.isString(/vh$/):
489 return this.getNumber() / 100.0 * viewPort.computeSize('y');
490
491 case this.isString(/rem$/):
492 return this.getNumber() * this.getRem();
493
494 case this.isString(/em$/):
495 return this.getNumber() * this.getEm();
496
497 case this.isString(/ex$/):
498 return this.getNumber() * this.getEm() / 2.0;
499
500 case this.isString(/px$/):
501 return this.getNumber();
502
503 case this.isString(/pt$/):
504 return this.getNumber() * this.getDpi() * (1.0 / 72.0);
505
506 case this.isString(/pc$/):
507 return this.getNumber() * 15;
508
509 case this.isString(/cm$/):
510 return this.getNumber() * this.getDpi() / 2.54;
511
512 case this.isString(/mm$/):
513 return this.getNumber() * this.getDpi() / 25.4;
514
515 case this.isString(/in$/):
516 return this.getNumber() * this.getDpi();
517
518 case this.isString(/%$/) && isFontSize:
519 return this.getNumber() * this.getEm();
520
521 case this.isString(/%$/):
522 return this.getNumber() * viewPort.computeSize(axis);
523
524 default:
525 {
526 var n = this.getNumber();
527
528 if (processPercent && n < 1.0) {
529 return n * viewPort.computeSize(axis);
530 }
531
532 return n;
533 }
534 }
535 }
536 }, {
537 key: "getMilliseconds",
538 value: function getMilliseconds() {
539 if (!this.hasValue()) {
540 return 0;
541 }
542
543 if (this.isString(/ms$/)) {
544 return this.getNumber();
545 }
546
547 return this.getNumber() * 1000;
548 }
549 }, {
550 key: "getRadians",
551 value: function getRadians() {
552 if (!this.hasValue()) {
553 return 0;
554 }
555
556 switch (true) {
557 case this.isString(/deg$/):
558 return this.getNumber() * (Math.PI / 180.0);
559
560 case this.isString(/grad$/):
561 return this.getNumber() * (Math.PI / 200.0);
562
563 case this.isString(/rad$/):
564 return this.getNumber();
565
566 default:
567 return this.getNumber() * (Math.PI / 180.0);
568 }
569 }
570 }, {
571 key: "getDefinition",
572 value: function getDefinition() {
573 var asString = this.getString();
574 var name = asString.match(/#([^\)'"]+)/);
575
576 if (name) {
577 name = name[1];
578 }
579
580 if (!name) {
581 name = asString;
582 }
583
584 return this.document.definitions[name];
585 }
586 }, {
587 key: "getFillStyleDefinition",
588 value: function getFillStyleDefinition(element, opacity) {
589 var def = this.getDefinition();
590
591 if (!def) {
592 return null;
593 } // gradient
594
595
596 if (typeof def.createGradient === 'function') {
597 return def.createGradient(this.document.ctx, element, opacity);
598 } // pattern
599
600
601 if (typeof def.createPattern === 'function') {
602 if (def.getHrefAttribute().hasValue()) {
603 var patternTransform = def.getAttribute('patternTransform');
604 def = def.getHrefAttribute().getDefinition();
605
606 if (patternTransform.hasValue()) {
607 def.getAttribute('patternTransform', true).setValue(patternTransform.value);
608 }
609 }
610
611 return def.createPattern(this.document.ctx, element, opacity);
612 }
613
614 return null;
615 }
616 }, {
617 key: "getTextBaseline",
618 value: function getTextBaseline() {
619 if (!this.hasValue()) {
620 return null;
621 }
622
623 return Property.textBaselineMapping[this.getString()];
624 }
625 }, {
626 key: "addOpacity",
627 value: function addOpacity(opacity) {
628 var value = this.getColor();
629 var len = value.length;
630 var commas = 0; // Simulate old RGBColor version, which can't parse rgba.
631
632 for (var i = 0; i < len; i++) {
633 if (value[i] === ',') {
634 commas++;
635 }
636
637 if (commas === 3) {
638 break;
639 }
640 }
641
642 if (opacity.hasValue() && this.isString() && commas !== 3) {
643 var color = new RGBColor__default['default'](value);
644
645 if (color.ok) {
646 color.alpha = opacity.getNumber();
647 value = color.toRGBA();
648 }
649 }
650
651 return new Property(this.document, this.name, value);
652 }
653 }], [{
654 key: "empty",
655 value: function empty(document) {
656 return new Property(document, 'EMPTY', '');
657 }
658 }]);
659
660 return Property;
661}();
662Property.textBaselineMapping = {
663 'baseline': 'alphabetic',
664 'before-edge': 'top',
665 'text-before-edge': 'top',
666 'middle': 'middle',
667 'central': 'middle',
668 'after-edge': 'bottom',
669 'text-after-edge': 'bottom',
670 'ideographic': 'ideographic',
671 'alphabetic': 'alphabetic',
672 'hanging': 'hanging',
673 'mathematical': 'alphabetic'
674};
675
676var ViewPort = /*#__PURE__*/function () {
677 function ViewPort() {
678 _classCallCheck__default['default'](this, ViewPort);
679
680 this.viewPorts = [];
681 }
682
683 _createClass__default['default'](ViewPort, [{
684 key: "clear",
685 value: function clear() {
686 this.viewPorts = [];
687 }
688 }, {
689 key: "setCurrent",
690 value: function setCurrent(width, height) {
691 this.viewPorts.push({
692 width: width,
693 height: height
694 });
695 }
696 }, {
697 key: "removeCurrent",
698 value: function removeCurrent() {
699 this.viewPorts.pop();
700 }
701 }, {
702 key: "getCurrent",
703 value: function getCurrent() {
704 var viewPorts = this.viewPorts;
705 return viewPorts[viewPorts.length - 1];
706 }
707 }, {
708 key: "computeSize",
709 value: function computeSize(d) {
710 if (typeof d === 'number') {
711 return d;
712 }
713
714 if (d === 'x') {
715 return this.width;
716 }
717
718 if (d === 'y') {
719 return this.height;
720 }
721
722 return Math.sqrt(Math.pow(this.width, 2) + Math.pow(this.height, 2)) / Math.sqrt(2);
723 }
724 }, {
725 key: "width",
726 get: function get() {
727 return this.getCurrent().width;
728 }
729 }, {
730 key: "height",
731 get: function get() {
732 return this.getCurrent().height;
733 }
734 }]);
735
736 return ViewPort;
737}();
738
739var Point = /*#__PURE__*/function () {
740 function Point(x, y) {
741 _classCallCheck__default['default'](this, Point);
742
743 this.x = x;
744 this.y = y;
745 }
746
747 _createClass__default['default'](Point, [{
748 key: "angleTo",
749 value: function angleTo(point) {
750 return Math.atan2(point.y - this.y, point.x - this.x);
751 }
752 }, {
753 key: "applyTransform",
754 value: function applyTransform(transform) {
755 var x = this.x,
756 y = this.y;
757 var xp = x * transform[0] + y * transform[2] + transform[4];
758 var yp = x * transform[1] + y * transform[3] + transform[5];
759 this.x = xp;
760 this.y = yp;
761 }
762 }], [{
763 key: "parse",
764 value: function parse(point) {
765 var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
766
767 var _toNumbers = toNumbers(point),
768 _toNumbers2 = _slicedToArray__default['default'](_toNumbers, 2),
769 _toNumbers2$ = _toNumbers2[0],
770 x = _toNumbers2$ === void 0 ? defaultValue : _toNumbers2$,
771 _toNumbers2$2 = _toNumbers2[1],
772 y = _toNumbers2$2 === void 0 ? defaultValue : _toNumbers2$2;
773
774 return new Point(x, y);
775 }
776 }, {
777 key: "parseScale",
778 value: function parseScale(scale) {
779 var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
780
781 var _toNumbers3 = toNumbers(scale),
782 _toNumbers4 = _slicedToArray__default['default'](_toNumbers3, 2),
783 _toNumbers4$ = _toNumbers4[0],
784 x = _toNumbers4$ === void 0 ? defaultValue : _toNumbers4$,
785 _toNumbers4$2 = _toNumbers4[1],
786 y = _toNumbers4$2 === void 0 ? x : _toNumbers4$2;
787
788 return new Point(x, y);
789 }
790 }, {
791 key: "parsePath",
792 value: function parsePath(path) {
793 var points = toNumbers(path);
794 var len = points.length;
795 var pathPoints = [];
796
797 for (var i = 0; i < len; i += 2) {
798 pathPoints.push(new Point(points[i], points[i + 1]));
799 }
800
801 return pathPoints;
802 }
803 }]);
804
805 return Point;
806}();
807
808var Mouse = /*#__PURE__*/function () {
809 function Mouse(screen) {
810 var _context, _context2;
811
812 _classCallCheck__default['default'](this, Mouse);
813
814 this.screen = screen;
815 this.working = false;
816 this.events = [];
817 this.eventElements = [];
818 this.onClick = _bindInstanceProperty__default['default'](_context = this.onClick).call(_context, this);
819 this.onMouseMove = _bindInstanceProperty__default['default'](_context2 = this.onMouseMove).call(_context2, this);
820 }
821
822 _createClass__default['default'](Mouse, [{
823 key: "isWorking",
824 value: function isWorking() {
825 return this.working;
826 }
827 }, {
828 key: "start",
829 value: function start() {
830 if (this.working) {
831 return;
832 }
833
834 var screen = this.screen,
835 onClick = this.onClick,
836 onMouseMove = this.onMouseMove;
837 var canvas = screen.ctx.canvas;
838 canvas.onclick = onClick;
839 canvas.onmousemove = onMouseMove;
840 this.working = true;
841 }
842 }, {
843 key: "stop",
844 value: function stop() {
845 if (!this.working) {
846 return;
847 }
848
849 var canvas = this.screen.ctx.canvas;
850 this.working = false;
851 canvas.onclick = null;
852 canvas.onmousemove = null;
853 }
854 }, {
855 key: "hasEvents",
856 value: function hasEvents() {
857 return this.working && this.events.length > 0;
858 }
859 }, {
860 key: "runEvents",
861 value: function runEvents() {
862 if (!this.working) {
863 return;
864 }
865
866 var document = this.screen,
867 events = this.events,
868 eventElements = this.eventElements;
869 var style = document.ctx.canvas.style;
870
871 if (style) {
872 style.cursor = '';
873 }
874
875 _forEachInstanceProperty__default['default'](events).call(events, function (_ref, i) {
876 var run = _ref.run;
877 var element = eventElements[i];
878
879 while (element) {
880 run(element);
881 element = element.parent;
882 }
883 }); // done running, clear
884
885
886 this.events = [];
887 this.eventElements = [];
888 }
889 }, {
890 key: "checkPath",
891 value: function checkPath(element, ctx) {
892 if (!this.working || !ctx) {
893 return;
894 }
895
896 var events = this.events,
897 eventElements = this.eventElements;
898
899 _forEachInstanceProperty__default['default'](events).call(events, function (_ref2, i) {
900 var x = _ref2.x,
901 y = _ref2.y;
902
903 if (!eventElements[i] && ctx.isPointInPath && ctx.isPointInPath(x, y)) {
904 eventElements[i] = element;
905 }
906 });
907 }
908 }, {
909 key: "checkBoundingBox",
910 value: function checkBoundingBox(element, boundingBox) {
911 if (!this.working || !boundingBox) {
912 return;
913 }
914
915 var events = this.events,
916 eventElements = this.eventElements;
917
918 _forEachInstanceProperty__default['default'](events).call(events, function (_ref3, i) {
919 var x = _ref3.x,
920 y = _ref3.y;
921
922 if (!eventElements[i] && boundingBox.isPointInBox(x, y)) {
923 eventElements[i] = element;
924 }
925 });
926 }
927 }, {
928 key: "mapXY",
929 value: function mapXY(x, y) {
930 var _this$screen = this.screen,
931 window = _this$screen.window,
932 ctx = _this$screen.ctx;
933 var point = new Point(x, y);
934 var element = ctx.canvas;
935
936 while (element) {
937 point.x -= element.offsetLeft;
938 point.y -= element.offsetTop;
939 element = element.offsetParent;
940 }
941
942 if (window.scrollX) {
943 point.x += window.scrollX;
944 }
945
946 if (window.scrollY) {
947 point.y += window.scrollY;
948 }
949
950 return point;
951 }
952 }, {
953 key: "onClick",
954 value: function onClick(evt) {
955 var _this$mapXY = this.mapXY((evt || event).clientX, (evt || event).clientY),
956 x = _this$mapXY.x,
957 y = _this$mapXY.y;
958
959 this.events.push({
960 type: 'onclick',
961 x: x,
962 y: y,
963 run: function run(event) {
964 if (event.onClick) {
965 event.onClick();
966 }
967 }
968 });
969 }
970 }, {
971 key: "onMouseMove",
972 value: function onMouseMove(evt) {
973 var _this$mapXY2 = this.mapXY((evt || event).clientX, (evt || event).clientY),
974 x = _this$mapXY2.x,
975 y = _this$mapXY2.y;
976
977 this.events.push({
978 type: 'onmousemove',
979 x: x,
980 y: y,
981 run: function run(event) {
982 if (event.onMouseMove) {
983 event.onMouseMove();
984 }
985 }
986 });
987 }
988 }]);
989
990 return Mouse;
991}();
992
993var defaultWindow = typeof window !== 'undefined' ? window : null;
994var defaultFetch = typeof fetch !== 'undefined' ? _bindInstanceProperty__default['default'](fetch).call(fetch, void 0) // `fetch` depends on context: `someObject.fetch(...)` will throw error.
995: null;
996
997var Screen = /*#__PURE__*/function () {
998 function Screen(ctx) {
999 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1000 _ref$fetch = _ref.fetch,
1001 fetch = _ref$fetch === void 0 ? defaultFetch : _ref$fetch,
1002 _ref$window = _ref.window,
1003 window = _ref$window === void 0 ? defaultWindow : _ref$window;
1004
1005 _classCallCheck__default['default'](this, Screen);
1006
1007 this.ctx = ctx;
1008 this.FRAMERATE = 30;
1009 this.MAX_VIRTUAL_PIXELS = 30000;
1010 this.CLIENT_WIDTH = 800;
1011 this.CLIENT_HEIGHT = 600;
1012 this.viewPort = new ViewPort();
1013 this.mouse = new Mouse(this);
1014 this.animations = [];
1015 this.waits = [];
1016 this.frameDuration = 0;
1017 this.isReadyLock = false;
1018 this.isFirstRender = true;
1019 this.intervalId = null;
1020 this.window = window;
1021 this.fetch = fetch;
1022 }
1023
1024 _createClass__default['default'](Screen, [{
1025 key: "wait",
1026 value: function wait(checker) {
1027 this.waits.push(checker);
1028 }
1029 }, {
1030 key: "ready",
1031 value: function ready() {
1032 if (!this.readyPromise) {
1033 return _Promise__default['default'].resolve();
1034 }
1035
1036 return this.readyPromise;
1037 }
1038 }, {
1039 key: "isReady",
1040 value: function isReady() {
1041 var _context;
1042
1043 if (this.isReadyLock) {
1044 return true;
1045 }
1046
1047 var isReadyLock = _everyInstanceProperty__default['default'](_context = this.waits).call(_context, function (_) {
1048 return _();
1049 });
1050
1051 if (isReadyLock) {
1052 this.waits = [];
1053
1054 if (this.resolveReady) {
1055 this.resolveReady();
1056 }
1057 }
1058
1059 this.isReadyLock = isReadyLock;
1060 return isReadyLock;
1061 }
1062 }, {
1063 key: "setDefaults",
1064 value: function setDefaults(ctx) {
1065 // initial values and defaults
1066 ctx.strokeStyle = 'rgba(0,0,0,0)';
1067 ctx.lineCap = 'butt';
1068 ctx.lineJoin = 'miter';
1069 ctx.miterLimit = 4;
1070 }
1071 }, {
1072 key: "setViewBox",
1073 value: function setViewBox(_ref2) {
1074 var document = _ref2.document,
1075 ctx = _ref2.ctx,
1076 aspectRatio = _ref2.aspectRatio,
1077 width = _ref2.width,
1078 desiredWidth = _ref2.desiredWidth,
1079 height = _ref2.height,
1080 desiredHeight = _ref2.desiredHeight,
1081 _ref2$minX = _ref2.minX,
1082 minX = _ref2$minX === void 0 ? 0 : _ref2$minX,
1083 _ref2$minY = _ref2.minY,
1084 minY = _ref2$minY === void 0 ? 0 : _ref2$minY,
1085 refX = _ref2.refX,
1086 refY = _ref2.refY,
1087 _ref2$clip = _ref2.clip,
1088 clip = _ref2$clip === void 0 ? false : _ref2$clip,
1089 _ref2$clipX = _ref2.clipX,
1090 clipX = _ref2$clipX === void 0 ? 0 : _ref2$clipX,
1091 _ref2$clipY = _ref2.clipY,
1092 clipY = _ref2$clipY === void 0 ? 0 : _ref2$clipY;
1093 // aspect ratio - http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
1094 var cleanAspectRatio = compressSpaces(aspectRatio).replace(/^defer\s/, ''); // ignore defer
1095
1096 var _cleanAspectRatio$spl = cleanAspectRatio.split(' '),
1097 _cleanAspectRatio$spl2 = _slicedToArray__default['default'](_cleanAspectRatio$spl, 2),
1098 aspectRatioAlign = _cleanAspectRatio$spl2[0],
1099 aspectRatioMeetOrSlice = _cleanAspectRatio$spl2[1];
1100
1101 var align = aspectRatioAlign || 'xMidYMid';
1102 var meetOrSlice = aspectRatioMeetOrSlice || 'meet'; // calculate scale
1103
1104 var scaleX = width / desiredWidth;
1105 var scaleY = height / desiredHeight;
1106 var scaleMin = Math.min(scaleX, scaleY);
1107 var scaleMax = Math.max(scaleX, scaleY);
1108 var finalDesiredWidth = desiredWidth;
1109 var finalDesiredHeight = desiredHeight;
1110
1111 if (meetOrSlice === 'meet') {
1112 finalDesiredWidth *= scaleMin;
1113 finalDesiredHeight *= scaleMin;
1114 }
1115
1116 if (meetOrSlice === 'slice') {
1117 finalDesiredWidth *= scaleMax;
1118 finalDesiredHeight *= scaleMax;
1119 }
1120
1121 var refXProp = new Property(document, 'refX', refX);
1122 var refYProp = new Property(document, 'refY', refY);
1123 var hasRefs = refXProp.hasValue() && refYProp.hasValue();
1124
1125 if (hasRefs) {
1126 ctx.translate(-scaleMin * refXProp.getPixels('x'), -scaleMin * refYProp.getPixels('y'));
1127 }
1128
1129 if (clip) {
1130 var scaledClipX = scaleMin * clipX;
1131 var scaledClipY = scaleMin * clipY;
1132 ctx.beginPath();
1133 ctx.moveTo(scaledClipX, scaledClipY);
1134 ctx.lineTo(width, scaledClipY);
1135 ctx.lineTo(width, height);
1136 ctx.lineTo(scaledClipX, height);
1137 ctx.closePath();
1138 ctx.clip();
1139 }
1140
1141 if (!hasRefs) {
1142 var isMeetMinY = meetOrSlice === 'meet' && scaleMin === scaleY;
1143 var isSliceMaxY = meetOrSlice === 'slice' && scaleMax === scaleY;
1144 var isMeetMinX = meetOrSlice === 'meet' && scaleMin === scaleX;
1145 var isSliceMaxX = meetOrSlice === 'slice' && scaleMax === scaleX;
1146
1147 if (/^xMid/.test(align) && (isMeetMinY || isSliceMaxY)) {
1148 ctx.translate(width / 2.0 - finalDesiredWidth / 2.0, 0);
1149 }
1150
1151 if (/YMid$/.test(align) && (isMeetMinX || isSliceMaxX)) {
1152 ctx.translate(0, height / 2.0 - finalDesiredHeight / 2.0);
1153 }
1154
1155 if (/^xMax/.test(align) && (isMeetMinY || isSliceMaxY)) {
1156 ctx.translate(width - finalDesiredWidth, 0);
1157 }
1158
1159 if (/YMax$/.test(align) && (isMeetMinX || isSliceMaxX)) {
1160 ctx.translate(0, height - finalDesiredHeight);
1161 }
1162 } // scale
1163
1164
1165 switch (true) {
1166 case align === 'none':
1167 ctx.scale(scaleX, scaleY);
1168 break;
1169
1170 case meetOrSlice === 'meet':
1171 ctx.scale(scaleMin, scaleMin);
1172 break;
1173
1174 case meetOrSlice === 'slice':
1175 ctx.scale(scaleMax, scaleMax);
1176 break;
1177 } // translate
1178
1179
1180 ctx.translate(-minX, -minY);
1181 }
1182 }, {
1183 key: "start",
1184 value: function start(element) {
1185 var _this = this;
1186
1187 var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1188 _ref3$enableRedraw = _ref3.enableRedraw,
1189 enableRedraw = _ref3$enableRedraw === void 0 ? false : _ref3$enableRedraw,
1190 _ref3$ignoreMouse = _ref3.ignoreMouse,
1191 ignoreMouse = _ref3$ignoreMouse === void 0 ? false : _ref3$ignoreMouse,
1192 _ref3$ignoreAnimation = _ref3.ignoreAnimation,
1193 ignoreAnimation = _ref3$ignoreAnimation === void 0 ? false : _ref3$ignoreAnimation,
1194 _ref3$ignoreDimension = _ref3.ignoreDimensions,
1195 ignoreDimensions = _ref3$ignoreDimension === void 0 ? false : _ref3$ignoreDimension,
1196 _ref3$ignoreClear = _ref3.ignoreClear,
1197 ignoreClear = _ref3$ignoreClear === void 0 ? false : _ref3$ignoreClear,
1198 forceRedraw = _ref3.forceRedraw,
1199 scaleWidth = _ref3.scaleWidth,
1200 scaleHeight = _ref3.scaleHeight,
1201 offsetX = _ref3.offsetX,
1202 offsetY = _ref3.offsetY;
1203
1204 var FRAMERATE = this.FRAMERATE,
1205 mouse = this.mouse;
1206 var frameDuration = 1000 / FRAMERATE;
1207 this.frameDuration = frameDuration;
1208 this.readyPromise = new _Promise__default['default'](function (resolve) {
1209 _this.resolveReady = resolve;
1210 });
1211
1212 if (this.isReady()) {
1213 this.render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY);
1214 }
1215
1216 if (!enableRedraw) {
1217 return;
1218 }
1219
1220 var now = _Date$now__default['default']();
1221
1222 var then = now;
1223 var delta = 0;
1224
1225 var tick = function tick() {
1226 now = _Date$now__default['default']();
1227 delta = now - then;
1228
1229 if (delta >= frameDuration) {
1230 then = now - delta % frameDuration;
1231
1232 if (_this.shouldUpdate(ignoreAnimation, forceRedraw)) {
1233 _this.render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY);
1234
1235 mouse.runEvents();
1236 }
1237 }
1238
1239 _this.intervalId = requestAnimationFrame__default['default'](tick);
1240 };
1241
1242 if (!ignoreMouse) {
1243 mouse.start();
1244 }
1245
1246 this.intervalId = requestAnimationFrame__default['default'](tick);
1247 }
1248 }, {
1249 key: "stop",
1250 value: function stop() {
1251 if (this.intervalId) {
1252 requestAnimationFrame__default['default'].cancel(this.intervalId);
1253 this.intervalId = null;
1254 }
1255
1256 this.mouse.stop();
1257 }
1258 }, {
1259 key: "shouldUpdate",
1260 value: function shouldUpdate(ignoreAnimation, forceRedraw) {
1261 // need update from animations?
1262 if (!ignoreAnimation) {
1263 var _context2;
1264
1265 var frameDuration = this.frameDuration;
1266
1267 var shouldUpdate = _reduceInstanceProperty__default['default'](_context2 = this.animations).call(_context2, function (shouldUpdate, animation) {
1268 return animation.update(frameDuration) || shouldUpdate;
1269 }, false);
1270
1271 if (shouldUpdate) {
1272 return true;
1273 }
1274 } // need update from redraw?
1275
1276
1277 if (typeof forceRedraw === 'function' && forceRedraw()) {
1278 return true;
1279 }
1280
1281 if (!this.isReadyLock && this.isReady()) {
1282 return true;
1283 } // need update from mouse events?
1284
1285
1286 if (this.mouse.hasEvents()) {
1287 return true;
1288 }
1289
1290 return false;
1291 }
1292 }, {
1293 key: "render",
1294 value: function render(element, ignoreDimensions, ignoreClear, scaleWidth, scaleHeight, offsetX, offsetY) {
1295 var CLIENT_WIDTH = this.CLIENT_WIDTH,
1296 CLIENT_HEIGHT = this.CLIENT_HEIGHT,
1297 viewPort = this.viewPort,
1298 ctx = this.ctx,
1299 isFirstRender = this.isFirstRender;
1300 var canvas = ctx.canvas;
1301 viewPort.clear();
1302
1303 if (canvas.width && canvas.height) {
1304 viewPort.setCurrent(canvas.width, canvas.height);
1305 } else {
1306 viewPort.setCurrent(CLIENT_WIDTH, CLIENT_HEIGHT);
1307 }
1308
1309 var widthStyle = element.getStyle('width');
1310 var heightStyle = element.getStyle('height');
1311
1312 if (!ignoreDimensions && (isFirstRender || typeof scaleWidth !== 'number' && typeof scaleHeight !== 'number')) {
1313 // set canvas size
1314 if (widthStyle.hasValue()) {
1315 canvas.width = widthStyle.getPixels('x');
1316
1317 if (canvas.style) {
1318 canvas.style.width = "".concat(canvas.width, "px");
1319 }
1320 }
1321
1322 if (heightStyle.hasValue()) {
1323 canvas.height = heightStyle.getPixels('y');
1324
1325 if (canvas.style) {
1326 canvas.style.height = "".concat(canvas.height, "px");
1327 }
1328 }
1329 }
1330
1331 var cWidth = canvas.clientWidth || canvas.width;
1332 var cHeight = canvas.clientHeight || canvas.height;
1333
1334 if (ignoreDimensions && widthStyle.hasValue() && heightStyle.hasValue()) {
1335 cWidth = widthStyle.getPixels('x');
1336 cHeight = heightStyle.getPixels('y');
1337 }
1338
1339 viewPort.setCurrent(cWidth, cHeight);
1340
1341 if (typeof offsetX === 'number') {
1342 element.getAttribute('x', true).setValue(offsetX);
1343 }
1344
1345 if (typeof offsetY === 'number') {
1346 element.getAttribute('y', true).setValue(offsetY);
1347 }
1348
1349 if (typeof scaleWidth === 'number' || typeof scaleHeight === 'number') {
1350 var _context3, _context4;
1351
1352 var viewBox = toNumbers(element.getAttribute('viewBox').getString());
1353 var xRatio = 0;
1354 var yRatio = 0;
1355
1356 if (typeof scaleWidth === 'number') {
1357 var _widthStyle = element.getStyle('width');
1358
1359 if (_widthStyle.hasValue()) {
1360 xRatio = _widthStyle.getPixels('x') / scaleWidth;
1361 } else if (!isNaN(viewBox[2])) {
1362 xRatio = viewBox[2] / scaleWidth;
1363 }
1364 }
1365
1366 if (typeof scaleHeight === 'number') {
1367 var _heightStyle = element.getStyle('height');
1368
1369 if (_heightStyle.hasValue()) {
1370 yRatio = _heightStyle.getPixels('y') / scaleHeight;
1371 } else if (!isNaN(viewBox[3])) {
1372 yRatio = viewBox[3] / scaleHeight;
1373 }
1374 }
1375
1376 if (!xRatio) {
1377 xRatio = yRatio;
1378 }
1379
1380 if (!yRatio) {
1381 yRatio = xRatio;
1382 }
1383
1384 element.getAttribute('width', true).setValue(scaleWidth);
1385 element.getAttribute('height', true).setValue(scaleHeight);
1386 var transformStyle = element.getStyle('transform', true, true);
1387 transformStyle.setValue(_concatInstanceProperty__default['default'](_context3 = _concatInstanceProperty__default['default'](_context4 = "".concat(transformStyle.getString(), " scale(")).call(_context4, 1.0 / xRatio, ", ")).call(_context3, 1.0 / yRatio, ")"));
1388 } // clear and render
1389
1390
1391 if (!ignoreClear) {
1392 ctx.clearRect(0, 0, cWidth, cHeight);
1393 }
1394
1395 element.render(ctx);
1396
1397 if (isFirstRender) {
1398 this.isFirstRender = false;
1399 }
1400 }
1401 }]);
1402
1403 return Screen;
1404}();
1405Screen.defaultWindow = defaultWindow;
1406Screen.defaultFetch = defaultFetch;
1407
1408var defaultFetch$1 = Screen.defaultFetch;
1409var DefaultDOMParser = typeof DOMParser !== 'undefined' ? DOMParser : null;
1410
1411var Parser = /*#__PURE__*/function () {
1412 function Parser() {
1413 var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1414 _ref$fetch = _ref.fetch,
1415 fetch = _ref$fetch === void 0 ? defaultFetch$1 : _ref$fetch,
1416 _ref$DOMParser = _ref.DOMParser,
1417 DOMParser = _ref$DOMParser === void 0 ? DefaultDOMParser : _ref$DOMParser;
1418
1419 _classCallCheck__default['default'](this, Parser);
1420
1421 this.fetch = fetch;
1422 this.DOMParser = DOMParser;
1423 }
1424
1425 _createClass__default['default'](Parser, [{
1426 key: "parse",
1427 value: function () {
1428 var _parse = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(resource) {
1429 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
1430 while (1) {
1431 switch (_context.prev = _context.next) {
1432 case 0:
1433 if (!/^</.test(resource)) {
1434 _context.next = 2;
1435 break;
1436 }
1437
1438 return _context.abrupt("return", this.parseFromString(resource));
1439
1440 case 2:
1441 return _context.abrupt("return", this.load(resource));
1442
1443 case 3:
1444 case "end":
1445 return _context.stop();
1446 }
1447 }
1448 }, _callee, this);
1449 }));
1450
1451 function parse(_x) {
1452 return _parse.apply(this, arguments);
1453 }
1454
1455 return parse;
1456 }()
1457 }, {
1458 key: "parseFromString",
1459 value: function parseFromString(xml) {
1460 var parser = new this.DOMParser();
1461
1462 try {
1463 return this.checkDocument(parser.parseFromString(xml, 'image/svg+xml'));
1464 } catch (err) {
1465 return this.checkDocument(parser.parseFromString(xml, 'text/xml'));
1466 }
1467 }
1468 }, {
1469 key: "checkDocument",
1470 value: function checkDocument(document) {
1471 var parserError = document.getElementsByTagName('parsererror')[0];
1472
1473 if (parserError) {
1474 throw new Error(parserError.textContent);
1475 }
1476
1477 return document;
1478 }
1479 }, {
1480 key: "load",
1481 value: function () {
1482 var _load = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(url) {
1483 var response, xml;
1484 return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
1485 while (1) {
1486 switch (_context2.prev = _context2.next) {
1487 case 0:
1488 _context2.next = 2;
1489 return this.fetch(url);
1490
1491 case 2:
1492 response = _context2.sent;
1493 _context2.next = 5;
1494 return response.text();
1495
1496 case 5:
1497 xml = _context2.sent;
1498 return _context2.abrupt("return", this.parseFromString(xml));
1499
1500 case 7:
1501 case "end":
1502 return _context2.stop();
1503 }
1504 }
1505 }, _callee2, this);
1506 }));
1507
1508 function load(_x2) {
1509 return _load.apply(this, arguments);
1510 }
1511
1512 return load;
1513 }()
1514 }]);
1515
1516 return Parser;
1517}();
1518
1519var Translate = /*#__PURE__*/function () {
1520 function Translate(_, point) {
1521 _classCallCheck__default['default'](this, Translate);
1522
1523 this.type = 'translate';
1524 this.point = null;
1525 this.point = Point.parse(point);
1526 }
1527
1528 _createClass__default['default'](Translate, [{
1529 key: "apply",
1530 value: function apply(ctx) {
1531 var _this$point = this.point,
1532 x = _this$point.x,
1533 y = _this$point.y;
1534 ctx.translate(x || 0.0, y || 0.0);
1535 }
1536 }, {
1537 key: "unapply",
1538 value: function unapply(ctx) {
1539 var _this$point2 = this.point,
1540 x = _this$point2.x,
1541 y = _this$point2.y;
1542 ctx.translate(-1.0 * x || 0.0, -1.0 * y || 0.0);
1543 }
1544 }, {
1545 key: "applyToPoint",
1546 value: function applyToPoint(point) {
1547 var _this$point3 = this.point,
1548 x = _this$point3.x,
1549 y = _this$point3.y;
1550 point.applyTransform([1, 0, 0, 1, x || 0.0, y || 0.0]);
1551 }
1552 }]);
1553
1554 return Translate;
1555}();
1556
1557var Rotate = /*#__PURE__*/function () {
1558 function Rotate(document, rotate, transformOrigin) {
1559 _classCallCheck__default['default'](this, Rotate);
1560
1561 this.type = 'rotate';
1562 this.angle = null;
1563 this.originX = null;
1564 this.originY = null;
1565 this.cx = 0;
1566 this.cy = 0;
1567 var numbers = toNumbers(rotate);
1568 this.angle = new Property(document, 'angle', numbers[0]);
1569 this.originX = transformOrigin[0];
1570 this.originY = transformOrigin[1];
1571 this.cx = numbers[1] || 0;
1572 this.cy = numbers[2] || 0;
1573 }
1574
1575 _createClass__default['default'](Rotate, [{
1576 key: "apply",
1577 value: function apply(ctx) {
1578 var cx = this.cx,
1579 cy = this.cy,
1580 originX = this.originX,
1581 originY = this.originY,
1582 angle = this.angle;
1583 var x = cx + originX.getPixels('x');
1584 var y = cy + originY.getPixels('y');
1585 ctx.translate(x, y);
1586 ctx.rotate(angle.getRadians());
1587 ctx.translate(-x, -y);
1588 }
1589 }, {
1590 key: "unapply",
1591 value: function unapply(ctx) {
1592 var cx = this.cx,
1593 cy = this.cy,
1594 angle = this.angle;
1595 ctx.translate(cx, cy);
1596 ctx.rotate(-1.0 * angle.getRadians());
1597 ctx.translate(-cx, -cy);
1598 }
1599 }, {
1600 key: "applyToPoint",
1601 value: function applyToPoint(point) {
1602 var cx = this.cx,
1603 cy = this.cy,
1604 angle = this.angle;
1605 var rad = angle.getRadians();
1606 point.applyTransform([1, 0, 0, 1, cx || 0.0, cy || 0.0 // this.p.y
1607 ]);
1608 point.applyTransform([Math.cos(rad), Math.sin(rad), -Math.sin(rad), Math.cos(rad), 0, 0]);
1609 point.applyTransform([1, 0, 0, 1, -cx || 0.0, -cy || 0.0 // -this.p.y
1610 ]);
1611 }
1612 }]);
1613
1614 return Rotate;
1615}();
1616
1617var Scale = /*#__PURE__*/function () {
1618 function Scale(_, scale) {
1619 _classCallCheck__default['default'](this, Scale);
1620
1621 this.type = 'scale';
1622 this.scale = null;
1623 var scaleSize = Point.parseScale(scale); // Workaround for node-canvas
1624
1625 if (scaleSize.x === 0 || scaleSize.y === 0) {
1626 scaleSize.x = PSEUDO_ZERO;
1627 scaleSize.y = PSEUDO_ZERO;
1628 }
1629
1630 this.scale = scaleSize;
1631 }
1632
1633 _createClass__default['default'](Scale, [{
1634 key: "apply",
1635 value: function apply(ctx) {
1636 var _this$scale = this.scale,
1637 x = _this$scale.x,
1638 y = _this$scale.y;
1639 ctx.scale(x, y || x);
1640 }
1641 }, {
1642 key: "unapply",
1643 value: function unapply(ctx) {
1644 var _this$scale2 = this.scale,
1645 x = _this$scale2.x,
1646 y = _this$scale2.y;
1647 ctx.scale(1.0 / x, 1.0 / y || x);
1648 }
1649 }, {
1650 key: "applyToPoint",
1651 value: function applyToPoint(point) {
1652 var _this$scale3 = this.scale,
1653 x = _this$scale3.x,
1654 y = _this$scale3.y;
1655 point.applyTransform([x || 0.0, 0, 0, y || 0.0, 0, 0]);
1656 }
1657 }]);
1658
1659 return Scale;
1660}();
1661
1662var Matrix = /*#__PURE__*/function () {
1663 function Matrix(_, matrix) {
1664 _classCallCheck__default['default'](this, Matrix);
1665
1666 this.type = 'matrix';
1667 this.matrix = [];
1668 this.matrix = toNumbers(matrix);
1669 }
1670
1671 _createClass__default['default'](Matrix, [{
1672 key: "apply",
1673 value: function apply(ctx) {
1674 var matrix = this.matrix;
1675 ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
1676 }
1677 }, {
1678 key: "unapply",
1679 value: function unapply(ctx) {
1680 var matrix = this.matrix;
1681 var a = matrix[0];
1682 var b = matrix[2];
1683 var c = matrix[4];
1684 var d = matrix[1];
1685 var e = matrix[3];
1686 var f = matrix[5];
1687 var g = 0.0;
1688 var h = 0.0;
1689 var i = 1.0;
1690 var det = 1 / (a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g));
1691 ctx.transform(det * (e * i - f * h), det * (f * g - d * i), det * (c * h - b * i), det * (a * i - c * g), det * (b * f - c * e), det * (c * d - a * f));
1692 }
1693 }, {
1694 key: "applyToPoint",
1695 value: function applyToPoint(point) {
1696 point.applyTransform(this.matrix);
1697 }
1698 }]);
1699
1700 return Matrix;
1701}();
1702
1703function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
1704
1705function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
1706
1707var Skew = /*#__PURE__*/function (_Matrix) {
1708 _inherits__default['default'](Skew, _Matrix);
1709
1710 var _super = _createSuper(Skew);
1711
1712 function Skew(document, skew) {
1713 var _this;
1714
1715 _classCallCheck__default['default'](this, Skew);
1716
1717 _this = _super.call(this, document, skew);
1718 _this.type = 'skew';
1719 _this.angle = null;
1720 _this.angle = new Property(document, 'angle', skew);
1721 return _this;
1722 }
1723
1724 return Skew;
1725}(Matrix);
1726
1727function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
1728
1729function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
1730
1731var SkewX = /*#__PURE__*/function (_Skew) {
1732 _inherits__default['default'](SkewX, _Skew);
1733
1734 var _super = _createSuper$1(SkewX);
1735
1736 function SkewX(document, skew) {
1737 var _this;
1738
1739 _classCallCheck__default['default'](this, SkewX);
1740
1741 _this = _super.call(this, document, skew);
1742 _this.type = 'skewX';
1743 _this.matrix = [1, 0, Math.tan(_this.angle.getRadians()), 1, 0, 0];
1744 return _this;
1745 }
1746
1747 return SkewX;
1748}(Skew);
1749
1750function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
1751
1752function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
1753
1754var SkewY = /*#__PURE__*/function (_Skew) {
1755 _inherits__default['default'](SkewY, _Skew);
1756
1757 var _super = _createSuper$2(SkewY);
1758
1759 function SkewY(document, skew) {
1760 var _this;
1761
1762 _classCallCheck__default['default'](this, SkewY);
1763
1764 _this = _super.call(this, document, skew);
1765 _this.type = 'skewY';
1766 _this.matrix = [1, Math.tan(_this.angle.getRadians()), 0, 1, 0, 0];
1767 return _this;
1768 }
1769
1770 return SkewY;
1771}(Skew);
1772
1773function parseTransforms(transform) {
1774 var _context;
1775
1776 return _trimInstanceProperty__default['default'](_context = compressSpaces(transform)).call(_context).replace(/\)([a-zA-Z])/g, ') $1').replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/);
1777}
1778
1779function parseTransform(transform) {
1780 var _transform$split = transform.split('('),
1781 _transform$split2 = _slicedToArray__default['default'](_transform$split, 2),
1782 type = _transform$split2[0],
1783 value = _transform$split2[1];
1784
1785 return [_trimInstanceProperty__default['default'](type).call(type), _trimInstanceProperty__default['default'](value).call(value).replace(')', '')];
1786}
1787
1788var Transform = /*#__PURE__*/function () {
1789 function Transform(document, transform, transformOrigin) {
1790 var _this = this;
1791
1792 _classCallCheck__default['default'](this, Transform);
1793
1794 this.document = document;
1795 this.transforms = [];
1796 var data = parseTransforms(transform);
1797
1798 _forEachInstanceProperty__default['default'](data).call(data, function (transform) {
1799 if (transform === 'none') {
1800 return;
1801 }
1802
1803 var _parseTransform = parseTransform(transform),
1804 _parseTransform2 = _slicedToArray__default['default'](_parseTransform, 2),
1805 type = _parseTransform2[0],
1806 value = _parseTransform2[1];
1807
1808 var TransformType = Transform.transformTypes[type];
1809
1810 if (typeof TransformType !== 'undefined') {
1811 _this.transforms.push(new TransformType(_this.document, value, transformOrigin));
1812 }
1813 });
1814 }
1815
1816 _createClass__default['default'](Transform, [{
1817 key: "apply",
1818 value: function apply(ctx) {
1819 var transforms = this.transforms;
1820 var len = transforms.length;
1821
1822 for (var i = 0; i < len; i++) {
1823 transforms[i].apply(ctx);
1824 }
1825 }
1826 }, {
1827 key: "unapply",
1828 value: function unapply(ctx) {
1829 var transforms = this.transforms;
1830 var len = transforms.length;
1831
1832 for (var i = len - 1; i >= 0; i--) {
1833 transforms[i].unapply(ctx);
1834 }
1835 } // TODO: applyToPoint unused ... remove?
1836
1837 }, {
1838 key: "applyToPoint",
1839 value: function applyToPoint(point) {
1840 var transforms = this.transforms;
1841 var len = transforms.length;
1842
1843 for (var i = 0; i < len; i++) {
1844 transforms[i].applyToPoint(point);
1845 }
1846 }
1847 }], [{
1848 key: "fromElement",
1849 value: function fromElement(document, element) {
1850 var transformStyle = element.getStyle('transform', false, true);
1851
1852 var _element$getStyle$spl = element.getStyle('transform-origin', false, true).split(),
1853 _element$getStyle$spl2 = _slicedToArray__default['default'](_element$getStyle$spl, 2),
1854 transformOriginXProperty = _element$getStyle$spl2[0],
1855 _element$getStyle$spl3 = _element$getStyle$spl2[1],
1856 transformOriginYProperty = _element$getStyle$spl3 === void 0 ? transformOriginXProperty : _element$getStyle$spl3;
1857
1858 var transformOrigin = [transformOriginXProperty, transformOriginYProperty];
1859
1860 if (transformStyle.hasValue()) {
1861 return new Transform(document, transformStyle.getString(), transformOrigin);
1862 }
1863
1864 return null;
1865 }
1866 }]);
1867
1868 return Transform;
1869}();
1870Transform.transformTypes = {
1871 translate: Translate,
1872 rotate: Rotate,
1873 scale: Scale,
1874 matrix: Matrix,
1875 skewX: SkewX,
1876 skewY: SkewY
1877};
1878
1879var Element = /*#__PURE__*/function () {
1880 function Element(document, node) {
1881 var _context,
1882 _this = this,
1883 _context4;
1884
1885 var captureTextNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1886
1887 _classCallCheck__default['default'](this, Element);
1888
1889 this.document = document;
1890 this.node = node;
1891 this.captureTextNodes = captureTextNodes;
1892 this.attributes = {};
1893 this.styles = {};
1894 this.stylesSpecificity = {};
1895 this.animationFrozen = false;
1896 this.animationFrozenValue = '';
1897 this.parent = null;
1898 this.children = [];
1899
1900 if (!node || node.nodeType !== 1) {
1901 // ELEMENT_NODE
1902 return;
1903 } // add attributes
1904
1905
1906 _forEachInstanceProperty__default['default'](_context = _Array$from__default['default'](node.attributes)).call(_context, function (attribute) {
1907 var nodeName = normalizeAttributeName(attribute.nodeName);
1908 _this.attributes[nodeName] = new Property(document, nodeName, attribute.value);
1909 });
1910
1911 this.addStylesFromStyleDefinition(); // add inline styles
1912
1913 if (this.getAttribute('style').hasValue()) {
1914 var _context2;
1915
1916 var styles = _mapInstanceProperty__default['default'](_context2 = this.getAttribute('style').getString().split(';')).call(_context2, function (_) {
1917 return _trimInstanceProperty__default['default'](_).call(_);
1918 });
1919
1920 _forEachInstanceProperty__default['default'](styles).call(styles, function (style) {
1921 var _context3;
1922
1923 if (!style) {
1924 return;
1925 }
1926
1927 var _style$split$map = _mapInstanceProperty__default['default'](_context3 = style.split(':')).call(_context3, function (_) {
1928 return _trimInstanceProperty__default['default'](_).call(_);
1929 }),
1930 _style$split$map2 = _slicedToArray__default['default'](_style$split$map, 2),
1931 name = _style$split$map2[0],
1932 value = _style$split$map2[1];
1933
1934 _this.styles[name] = new Property(document, name, value);
1935 });
1936 }
1937
1938 var definitions = document.definitions;
1939 var id = this.getAttribute('id'); // add id
1940
1941 if (id.hasValue()) {
1942 if (!definitions[id.getValue()]) {
1943 definitions[id.getValue()] = this;
1944 }
1945 }
1946
1947 _forEachInstanceProperty__default['default'](_context4 = _Array$from__default['default'](node.childNodes)).call(_context4, function (childNode) {
1948 if (childNode.nodeType === 1) {
1949 _this.addChild(childNode); // ELEMENT_NODE
1950
1951 } else if (captureTextNodes && (childNode.nodeType === 3 || childNode.nodeType === 4)) {
1952 var textNode = document.createTextNode(childNode);
1953
1954 if (textNode.getText().length > 0) {
1955 _this.addChild(textNode); // TEXT_NODE
1956
1957 }
1958 }
1959 });
1960 }
1961
1962 _createClass__default['default'](Element, [{
1963 key: "getAttribute",
1964 value: function getAttribute(name) {
1965 var createIfNotExists = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1966 var attr = this.attributes[name];
1967
1968 if (!attr && createIfNotExists) {
1969 var _attr = new Property(this.document, name, '');
1970
1971 this.attributes[name] = _attr;
1972 return _attr;
1973 }
1974
1975 return attr || Property.empty(this.document);
1976 }
1977 }, {
1978 key: "getHrefAttribute",
1979 value: function getHrefAttribute() {
1980 for (var key in this.attributes) {
1981 if (key === 'href' || /:href$/.test(key)) {
1982 return this.attributes[key];
1983 }
1984 }
1985
1986 return Property.empty(this.document);
1987 }
1988 }, {
1989 key: "getStyle",
1990 value: function getStyle(name) {
1991 var createIfNotExists = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1992 var skipAncestors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1993 var style = this.styles[name];
1994
1995 if (style) {
1996 return style;
1997 }
1998
1999 var attr = this.getAttribute(name);
2000
2001 if (attr && attr.hasValue()) {
2002 this.styles[name] = attr; // move up to me to cache
2003
2004 return attr;
2005 }
2006
2007 if (!skipAncestors) {
2008 var parent = this.parent;
2009
2010 if (parent) {
2011 var parentStyle = parent.getStyle(name);
2012
2013 if (parentStyle && parentStyle.hasValue()) {
2014 return parentStyle;
2015 }
2016 }
2017 }
2018
2019 if (createIfNotExists) {
2020 var _style = new Property(this.document, name, '');
2021
2022 this.styles[name] = _style;
2023 return _style;
2024 }
2025
2026 return style || Property.empty(this.document);
2027 }
2028 }, {
2029 key: "render",
2030 value: function render(ctx) {
2031 // don't render display=none
2032 // don't render visibility=hidden
2033 if (this.getStyle('display').getString() === 'none' || this.getStyle('visibility').getString() === 'hidden') {
2034 return;
2035 }
2036
2037 ctx.save();
2038
2039 if (this.getStyle('mask').hasValue()) {
2040 // mask
2041 var mask = this.getStyle('mask').getDefinition();
2042
2043 if (mask) {
2044 this.applyEffects(ctx);
2045 mask.apply(ctx, this);
2046 }
2047 } else if (this.getStyle('filter').getValue('none') !== 'none') {
2048 // filter
2049 var filter = this.getStyle('filter').getDefinition();
2050
2051 if (filter) {
2052 this.applyEffects(ctx);
2053 filter.apply(ctx, this);
2054 }
2055 } else {
2056 this.setContext(ctx);
2057 this.renderChildren(ctx);
2058 this.clearContext(ctx);
2059 }
2060
2061 ctx.restore();
2062 }
2063 }, {
2064 key: "setContext",
2065 value: function setContext(_) {}
2066 }, {
2067 key: "applyEffects",
2068 value: function applyEffects(ctx) {
2069 // transform
2070 var transform = Transform.fromElement(this.document, this);
2071
2072 if (transform) {
2073 transform.apply(ctx);
2074 } // clip
2075
2076
2077 var clipPathStyleProp = this.getStyle('clip-path', false, true);
2078
2079 if (clipPathStyleProp.hasValue()) {
2080 var clip = clipPathStyleProp.getDefinition();
2081
2082 if (clip) {
2083 clip.apply(ctx);
2084 }
2085 }
2086 }
2087 }, {
2088 key: "clearContext",
2089 value: function clearContext(_) {}
2090 }, {
2091 key: "renderChildren",
2092 value: function renderChildren(ctx) {
2093 var _context5;
2094
2095 _forEachInstanceProperty__default['default'](_context5 = this.children).call(_context5, function (child) {
2096 child.render(ctx);
2097 });
2098 }
2099 }, {
2100 key: "addChild",
2101 value: function addChild(childNode) {
2102 var _context6;
2103
2104 var child = childNode instanceof Element ? childNode : this.document.createElement(childNode);
2105 child.parent = this;
2106
2107 if (!_includesInstanceProperty__default['default'](_context6 = Element.ignoreChildTypes).call(_context6, child.type)) {
2108 this.children.push(child);
2109 }
2110 }
2111 }, {
2112 key: "matchesSelector",
2113 value: function matchesSelector(selector) {
2114 var _context7;
2115
2116 var node = this.node;
2117
2118 if (typeof node.matches === 'function') {
2119 return node.matches(selector);
2120 }
2121
2122 var styleClasses = node.getAttribute('class');
2123
2124 if (!styleClasses || styleClasses === '') {
2125 return false;
2126 }
2127
2128 return _someInstanceProperty__default['default'](_context7 = styleClasses.split(' ')).call(_context7, function (styleClass) {
2129 if (".".concat(styleClass) === selector) {
2130 return true;
2131 }
2132 });
2133 }
2134 }, {
2135 key: "addStylesFromStyleDefinition",
2136 value: function addStylesFromStyleDefinition() {
2137 var _this$document = this.document,
2138 styles = _this$document.styles,
2139 stylesSpecificity = _this$document.stylesSpecificity;
2140
2141 for (var selector in styles) {
2142 if (selector[0] !== '@' && this.matchesSelector(selector)) {
2143 var style = styles[selector];
2144 var specificity = stylesSpecificity[selector];
2145
2146 if (style) {
2147 for (var name in style) {
2148 var existingSpecificity = this.stylesSpecificity[name];
2149
2150 if (typeof existingSpecificity === 'undefined') {
2151 existingSpecificity = '000';
2152 }
2153
2154 if (specificity >= existingSpecificity) {
2155 this.styles[name] = style[name];
2156 this.stylesSpecificity[name] = specificity;
2157 }
2158 }
2159 }
2160 }
2161 }
2162 }
2163 }, {
2164 key: "removeStyles",
2165 value: function removeStyles(element, ignoreStyles) {
2166 var toRestore = _reduceInstanceProperty__default['default'](ignoreStyles).call(ignoreStyles, function (toRestore, name) {
2167 var _context8;
2168
2169 var styleProp = element.getStyle(name);
2170
2171 if (!styleProp.hasValue()) {
2172 return toRestore;
2173 }
2174
2175 var value = styleProp.getString();
2176 styleProp.setValue('');
2177 return _concatInstanceProperty__default['default'](_context8 = []).call(_context8, _toConsumableArray__default['default'](toRestore), [[name, value]]);
2178 }, []);
2179
2180 return toRestore;
2181 }
2182 }, {
2183 key: "restoreStyles",
2184 value: function restoreStyles(element, styles) {
2185 _forEachInstanceProperty__default['default'](styles).call(styles, function (_ref) {
2186 var _ref2 = _slicedToArray__default['default'](_ref, 2),
2187 name = _ref2[0],
2188 value = _ref2[1];
2189
2190 element.getStyle(name, true).setValue(value);
2191 });
2192 }
2193 }]);
2194
2195 return Element;
2196}();
2197Element.ignoreChildTypes = ['title'];
2198
2199function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
2200
2201function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
2202
2203var UnknownElement = /*#__PURE__*/function (_Element) {
2204 _inherits__default['default'](UnknownElement, _Element);
2205
2206 var _super = _createSuper$3(UnknownElement);
2207
2208 function UnknownElement(document, node, captureTextNodes) {
2209 var _this;
2210
2211 _classCallCheck__default['default'](this, UnknownElement);
2212
2213 _this = _super.call(this, document, node, captureTextNodes);
2214
2215 return _this;
2216 }
2217
2218 return UnknownElement;
2219}(Element);
2220
2221function wrapFontFamily(fontFamily) {
2222 var trimmed = _trimInstanceProperty__default['default'](fontFamily).call(fontFamily);
2223
2224 return /^('|")/.test(trimmed) ? trimmed : "\"".concat(trimmed, "\"");
2225}
2226
2227function prepareFontFamily(fontFamily) {
2228 var _context;
2229
2230 return typeof process === 'undefined' ? fontFamily : _mapInstanceProperty__default['default'](_context = _trimInstanceProperty__default['default'](fontFamily).call(fontFamily).split(',')).call(_context, wrapFontFamily).join(',');
2231}
2232/**
2233 * https://developer.mozilla.org/en-US/docs/Web/CSS/font-style
2234 */
2235
2236
2237function prepareFontStyle(fontStyle) {
2238 if (!fontStyle) {
2239 return '';
2240 }
2241
2242 var targetFontStyle = _trimInstanceProperty__default['default'](fontStyle).call(fontStyle).toLowerCase();
2243
2244 switch (targetFontStyle) {
2245 case 'normal':
2246 case 'italic':
2247 case 'oblique':
2248 case 'inherit':
2249 case 'initial':
2250 case 'unset':
2251 return targetFontStyle;
2252
2253 default:
2254 if (/^oblique\s+(-|)\d+deg$/.test(targetFontStyle)) {
2255 return targetFontStyle;
2256 }
2257
2258 return '';
2259 }
2260}
2261/**
2262 * https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
2263 */
2264
2265
2266function prepareFontWeight(fontWeight) {
2267 if (!fontWeight) {
2268 return '';
2269 }
2270
2271 var targetFontWeight = _trimInstanceProperty__default['default'](fontWeight).call(fontWeight).toLowerCase();
2272
2273 switch (targetFontWeight) {
2274 case 'normal':
2275 case 'bold':
2276 case 'lighter':
2277 case 'bolder':
2278 case 'inherit':
2279 case 'initial':
2280 case 'unset':
2281 return targetFontWeight;
2282
2283 default:
2284 if (/^[\d.]+$/.test(targetFontWeight)) {
2285 return targetFontWeight;
2286 }
2287
2288 return '';
2289 }
2290}
2291
2292var Font = /*#__PURE__*/function () {
2293 function Font(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit) {
2294 _classCallCheck__default['default'](this, Font);
2295
2296 var inheritFont = inherit ? typeof inherit === 'string' ? Font.parse(inherit) : inherit : {};
2297 this.fontFamily = fontFamily || inheritFont.fontFamily;
2298 this.fontSize = fontSize || inheritFont.fontSize;
2299 this.fontStyle = fontStyle || inheritFont.fontStyle;
2300 this.fontWeight = fontWeight || inheritFont.fontWeight;
2301 this.fontVariant = fontVariant || inheritFont.fontVariant;
2302 }
2303
2304 _createClass__default['default'](Font, [{
2305 key: "toString",
2306 value: function toString() {
2307 var _context2;
2308
2309 return _trimInstanceProperty__default['default'](_context2 = [prepareFontStyle(this.fontStyle), this.fontVariant, prepareFontWeight(this.fontWeight), this.fontSize, // Wrap fontFamily only on nodejs and only for canvas.ctx
2310 prepareFontFamily(this.fontFamily)].join(' ')).call(_context2);
2311 }
2312 }], [{
2313 key: "parse",
2314 value: function parse() {
2315 var _context3;
2316
2317 var font = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
2318 var inherit = arguments.length > 1 ? arguments[1] : undefined;
2319 var fontStyle = '';
2320 var fontVariant = '';
2321 var fontWeight = '';
2322 var fontSize = '';
2323 var fontFamily = '';
2324
2325 var parts = _trimInstanceProperty__default['default'](_context3 = compressSpaces(font)).call(_context3).split(' ');
2326
2327 var set = {
2328 fontSize: false,
2329 fontStyle: false,
2330 fontWeight: false,
2331 fontVariant: false
2332 };
2333
2334 _forEachInstanceProperty__default['default'](parts).call(parts, function (part) {
2335 var _context4, _context5, _context6;
2336
2337 switch (true) {
2338 case !set.fontStyle && _includesInstanceProperty__default['default'](_context4 = Font.styles).call(_context4, part):
2339 if (part !== 'inherit') {
2340 fontStyle = part;
2341 }
2342
2343 set.fontStyle = true;
2344 break;
2345
2346 case !set.fontVariant && _includesInstanceProperty__default['default'](_context5 = Font.variants).call(_context5, part):
2347 if (part !== 'inherit') {
2348 fontVariant = part;
2349 }
2350
2351 set.fontStyle = true;
2352 set.fontVariant = true;
2353 break;
2354
2355 case !set.fontWeight && _includesInstanceProperty__default['default'](_context6 = Font.weights).call(_context6, part):
2356 if (part !== 'inherit') {
2357 fontWeight = part;
2358 }
2359
2360 set.fontStyle = true;
2361 set.fontVariant = true;
2362 set.fontWeight = true;
2363 break;
2364
2365 case !set.fontSize:
2366 if (part !== 'inherit') {
2367 var _part$split = part.split('/');
2368
2369 var _part$split2 = _slicedToArray__default['default'](_part$split, 1);
2370
2371 fontSize = _part$split2[0];
2372 }
2373
2374 set.fontStyle = true;
2375 set.fontVariant = true;
2376 set.fontWeight = true;
2377 set.fontSize = true;
2378 break;
2379
2380 default:
2381 if (part !== 'inherit') {
2382 fontFamily += part;
2383 }
2384
2385 }
2386 });
2387
2388 return new Font(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit);
2389 }
2390 }]);
2391
2392 return Font;
2393}();
2394Font.styles = 'normal|italic|oblique|inherit';
2395Font.variants = 'normal|small-caps|inherit';
2396Font.weights = 'normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit';
2397
2398var BoundingBox = /*#__PURE__*/function () {
2399 function BoundingBox() {
2400 var x1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.NaN;
2401 var y1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.NaN;
2402 var x2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Number.NaN;
2403 var y2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Number.NaN;
2404
2405 _classCallCheck__default['default'](this, BoundingBox);
2406
2407 this.x1 = x1;
2408 this.y1 = y1;
2409 this.x2 = x2;
2410 this.y2 = y2;
2411 this.addPoint(x1, y1);
2412 this.addPoint(x2, y2);
2413 }
2414
2415 _createClass__default['default'](BoundingBox, [{
2416 key: "addPoint",
2417 value: function addPoint(x, y) {
2418 if (typeof x !== 'undefined') {
2419 if (isNaN(this.x1) || isNaN(this.x2)) {
2420 this.x1 = x;
2421 this.x2 = x;
2422 }
2423
2424 if (x < this.x1) {
2425 this.x1 = x;
2426 }
2427
2428 if (x > this.x2) {
2429 this.x2 = x;
2430 }
2431 }
2432
2433 if (typeof y !== 'undefined') {
2434 if (isNaN(this.y1) || isNaN(this.y2)) {
2435 this.y1 = y;
2436 this.y2 = y;
2437 }
2438
2439 if (y < this.y1) {
2440 this.y1 = y;
2441 }
2442
2443 if (y > this.y2) {
2444 this.y2 = y;
2445 }
2446 }
2447 }
2448 }, {
2449 key: "addX",
2450 value: function addX(x) {
2451 this.addPoint(x, null);
2452 }
2453 }, {
2454 key: "addY",
2455 value: function addY(y) {
2456 this.addPoint(null, y);
2457 }
2458 }, {
2459 key: "addBoundingBox",
2460 value: function addBoundingBox(boundingBox) {
2461 if (!boundingBox) {
2462 return;
2463 }
2464
2465 var x1 = boundingBox.x1,
2466 y1 = boundingBox.y1,
2467 x2 = boundingBox.x2,
2468 y2 = boundingBox.y2;
2469 this.addPoint(x1, y1);
2470 this.addPoint(x2, y2);
2471 }
2472 }, {
2473 key: "sumCubic",
2474 value: function sumCubic(t, p0, p1, p2, p3) {
2475 return Math.pow(1 - t, 3) * p0 + 3 * Math.pow(1 - t, 2) * t * p1 + 3 * (1 - t) * Math.pow(t, 2) * p2 + Math.pow(t, 3) * p3;
2476 }
2477 }, {
2478 key: "bezierCurveAdd",
2479 value: function bezierCurveAdd(forX, p0, p1, p2, p3) {
2480 var b = 6 * p0 - 12 * p1 + 6 * p2;
2481 var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
2482 var c = 3 * p1 - 3 * p0;
2483
2484 if (a === 0) {
2485 if (b === 0) {
2486 return;
2487 }
2488
2489 var t = -c / b;
2490
2491 if (0 < t && t < 1) {
2492 if (forX) {
2493 this.addX(this.sumCubic(t, p0, p1, p2, p3));
2494 } else {
2495 this.addY(this.sumCubic(t, p0, p1, p2, p3));
2496 }
2497 }
2498
2499 return;
2500 }
2501
2502 var b2ac = Math.pow(b, 2) - 4 * c * a;
2503
2504 if (b2ac < 0) {
2505 return;
2506 }
2507
2508 var t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
2509
2510 if (0 < t1 && t1 < 1) {
2511 if (forX) {
2512 this.addX(this.sumCubic(t1, p0, p1, p2, p3));
2513 } else {
2514 this.addY(this.sumCubic(t1, p0, p1, p2, p3));
2515 }
2516 }
2517
2518 var t2 = (-b - Math.sqrt(b2ac)) / (2 * a);
2519
2520 if (0 < t2 && t2 < 1) {
2521 if (forX) {
2522 this.addX(this.sumCubic(t2, p0, p1, p2, p3));
2523 } else {
2524 this.addY(this.sumCubic(t2, p0, p1, p2, p3));
2525 }
2526 }
2527 } // from http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html
2528
2529 }, {
2530 key: "addBezierCurve",
2531 value: function addBezierCurve(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) {
2532 this.addPoint(p0x, p0y);
2533 this.addPoint(p3x, p3y);
2534 this.bezierCurveAdd(true, p0x, p1x, p2x, p3x);
2535 this.bezierCurveAdd(false, p0y, p1y, p2y, p3y);
2536 }
2537 }, {
2538 key: "addQuadraticCurve",
2539 value: function addQuadraticCurve(p0x, p0y, p1x, p1y, p2x, p2y) {
2540 var cp1x = p0x + 2 / 3 * (p1x - p0x); // CP1 = QP0 + 2/3 *(QP1-QP0)
2541
2542 var cp1y = p0y + 2 / 3 * (p1y - p0y); // CP1 = QP0 + 2/3 *(QP1-QP0)
2543
2544 var cp2x = cp1x + 1 / 3 * (p2x - p0x); // CP2 = CP1 + 1/3 *(QP2-QP0)
2545
2546 var cp2y = cp1y + 1 / 3 * (p2y - p0y); // CP2 = CP1 + 1/3 *(QP2-QP0)
2547
2548 this.addBezierCurve(p0x, p0y, cp1x, cp2x, cp1y, cp2y, p2x, p2y);
2549 }
2550 }, {
2551 key: "isPointInBox",
2552 value: function isPointInBox(x, y) {
2553 var x1 = this.x1,
2554 y1 = this.y1,
2555 x2 = this.x2,
2556 y2 = this.y2;
2557 return x1 <= x && x <= x2 && y1 <= y && y <= y2;
2558 }
2559 }, {
2560 key: "x",
2561 get: function get() {
2562 return this.x1;
2563 }
2564 }, {
2565 key: "y",
2566 get: function get() {
2567 return this.y1;
2568 }
2569 }, {
2570 key: "width",
2571 get: function get() {
2572 return this.x2 - this.x1;
2573 }
2574 }, {
2575 key: "height",
2576 get: function get() {
2577 return this.y2 - this.y1;
2578 }
2579 }]);
2580
2581 return BoundingBox;
2582}();
2583
2584function _createSuper$4(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$4(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
2585
2586function _isNativeReflectConstruct$4() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
2587
2588var RenderedElement = /*#__PURE__*/function (_Element) {
2589 _inherits__default['default'](RenderedElement, _Element);
2590
2591 var _super = _createSuper$4(RenderedElement);
2592
2593 function RenderedElement() {
2594 var _this;
2595
2596 _classCallCheck__default['default'](this, RenderedElement);
2597
2598 _this = _super.apply(this, arguments);
2599 _this.modifiedEmSizeStack = false;
2600 return _this;
2601 }
2602
2603 _createClass__default['default'](RenderedElement, [{
2604 key: "calculateOpacity",
2605 value: function calculateOpacity() {
2606 var opacity = 1.0; // tslint:disable-next-line: no-this-assignment
2607
2608 var element = this;
2609
2610 while (element) {
2611 var opacityStyle = element.getStyle('opacity', false, true); // no ancestors on style call
2612
2613 if (opacityStyle.hasValue(true)) {
2614 opacity *= opacityStyle.getNumber();
2615 }
2616
2617 element = element.parent;
2618 }
2619
2620 return opacity;
2621 }
2622 }, {
2623 key: "setContext",
2624 value: function setContext(ctx) {
2625 var fromMeasure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2626
2627 if (!fromMeasure) {
2628 // causes stack overflow when measuring text with gradients
2629 // fill
2630 var fillStyleProp = this.getStyle('fill');
2631 var fillOpacityStyleProp = this.getStyle('fill-opacity');
2632 var strokeStyleProp = this.getStyle('stroke');
2633 var strokeOpacityProp = this.getStyle('stroke-opacity');
2634
2635 if (fillStyleProp.isUrlDefinition()) {
2636 var fillStyle = fillStyleProp.getFillStyleDefinition(this, fillOpacityStyleProp);
2637
2638 if (fillStyle) {
2639 ctx.fillStyle = fillStyle;
2640 }
2641 } else if (fillStyleProp.hasValue()) {
2642 if (fillStyleProp.getString() === 'currentColor') {
2643 fillStyleProp.setValue(this.getStyle('color').getColor());
2644 }
2645
2646 var _fillStyle = fillStyleProp.getColor();
2647
2648 if (_fillStyle !== 'inherit') {
2649 ctx.fillStyle = _fillStyle === 'none' ? 'rgba(0,0,0,0)' : _fillStyle;
2650 }
2651 }
2652
2653 if (fillOpacityStyleProp.hasValue()) {
2654 var _fillStyle2 = new Property(this.document, 'fill', ctx.fillStyle).addOpacity(fillOpacityStyleProp).getColor();
2655
2656 ctx.fillStyle = _fillStyle2;
2657 } // stroke
2658
2659
2660 if (strokeStyleProp.isUrlDefinition()) {
2661 var strokeStyle = strokeStyleProp.getFillStyleDefinition(this, strokeOpacityProp);
2662
2663 if (strokeStyle) {
2664 ctx.strokeStyle = strokeStyle;
2665 }
2666 } else if (strokeStyleProp.hasValue()) {
2667 if (strokeStyleProp.getString() === 'currentColor') {
2668 strokeStyleProp.setValue(this.getStyle('color').getColor());
2669 }
2670
2671 var _strokeStyle = strokeStyleProp.getString();
2672
2673 if (_strokeStyle !== 'inherit') {
2674 ctx.strokeStyle = _strokeStyle === 'none' ? 'rgba(0,0,0,0)' : _strokeStyle;
2675 }
2676 }
2677
2678 if (strokeOpacityProp.hasValue()) {
2679 var _strokeStyle2 = new Property(this.document, 'stroke', ctx.strokeStyle).addOpacity(strokeOpacityProp).getString();
2680
2681 ctx.strokeStyle = _strokeStyle2;
2682 }
2683
2684 var strokeWidthStyleProp = this.getStyle('stroke-width');
2685
2686 if (strokeWidthStyleProp.hasValue()) {
2687 var newLineWidth = strokeWidthStyleProp.getPixels();
2688 ctx.lineWidth = !newLineWidth ? PSEUDO_ZERO // browsers don't respect 0 (or node-canvas? :-)
2689 : newLineWidth;
2690 }
2691
2692 var strokeLinecapStyleProp = this.getStyle('stroke-linecap');
2693 var strokeLinejoinStyleProp = this.getStyle('stroke-linejoin');
2694 var strokeMiterlimitProp = this.getStyle('stroke-miterlimit');
2695 var pointOrderStyleProp = this.getStyle('paint-order');
2696 var strokeDasharrayStyleProp = this.getStyle('stroke-dasharray');
2697 var strokeDashoffsetProp = this.getStyle('stroke-dashoffset');
2698
2699 if (strokeLinecapStyleProp.hasValue()) {
2700 ctx.lineCap = strokeLinecapStyleProp.getString();
2701 }
2702
2703 if (strokeLinejoinStyleProp.hasValue()) {
2704 ctx.lineJoin = strokeLinejoinStyleProp.getString();
2705 }
2706
2707 if (strokeMiterlimitProp.hasValue()) {
2708 ctx.miterLimit = strokeMiterlimitProp.getNumber();
2709 }
2710
2711 if (pointOrderStyleProp.hasValue()) {
2712 // ?
2713 ctx.paintOrder = pointOrderStyleProp.getValue();
2714 }
2715
2716 if (strokeDasharrayStyleProp.hasValue() && strokeDasharrayStyleProp.getString() !== 'none') {
2717 var gaps = toNumbers(strokeDasharrayStyleProp.getString());
2718
2719 if (typeof ctx.setLineDash !== 'undefined') {
2720 ctx.setLineDash(gaps);
2721 } else if (typeof ctx.webkitLineDash !== 'undefined') {
2722 ctx.webkitLineDash = gaps;
2723 } else if (typeof ctx.mozDash !== 'undefined' && !(gaps.length === 1 && gaps[0] === 0)) {
2724 ctx.mozDash = gaps;
2725 }
2726
2727 var offset = strokeDashoffsetProp.getPixels();
2728
2729 if (typeof ctx.lineDashOffset !== 'undefined') {
2730 ctx.lineDashOffset = offset;
2731 } else if (typeof ctx.webkitLineDashOffset !== 'undefined') {
2732 ctx.webkitLineDashOffset = offset;
2733 } else if (typeof ctx.mozDashOffset !== 'undefined') {
2734 ctx.mozDashOffset = offset;
2735 }
2736 }
2737 } // font
2738
2739
2740 this.modifiedEmSizeStack = false;
2741
2742 if (typeof ctx.font !== 'undefined') {
2743 var fontStyleProp = this.getStyle('font');
2744 var fontStyleStyleProp = this.getStyle('font-style');
2745 var fontVariantStyleProp = this.getStyle('font-variant');
2746 var fontWeightStyleProp = this.getStyle('font-weight');
2747 var fontSizeStyleProp = this.getStyle('font-size');
2748 var fontFamilyStyleProp = this.getStyle('font-family');
2749 var font = new Font(fontStyleStyleProp.getString(), fontVariantStyleProp.getString(), fontWeightStyleProp.getString(), fontSizeStyleProp.hasValue() ? "".concat(fontSizeStyleProp.getPixels(true), "px") : '', fontFamilyStyleProp.getString(), Font.parse(fontStyleProp.getString(), ctx.font));
2750 fontStyleStyleProp.setValue(font.fontStyle);
2751 fontVariantStyleProp.setValue(font.fontVariant);
2752 fontWeightStyleProp.setValue(font.fontWeight);
2753 fontSizeStyleProp.setValue(font.fontSize);
2754 fontFamilyStyleProp.setValue(font.fontFamily);
2755 ctx.font = font.toString();
2756
2757 if (fontSizeStyleProp.isPixels()) {
2758 this.document.emSize = fontSizeStyleProp.getPixels();
2759 this.modifiedEmSizeStack = true;
2760 }
2761 }
2762
2763 if (!fromMeasure) {
2764 // effects
2765 this.applyEffects(ctx); // opacity
2766
2767 ctx.globalAlpha = this.calculateOpacity();
2768 }
2769 }
2770 }, {
2771 key: "clearContext",
2772 value: function clearContext(ctx) {
2773 _get__default['default'](_getPrototypeOf__default['default'](RenderedElement.prototype), "clearContext", this).call(this, ctx);
2774
2775 if (this.modifiedEmSizeStack) {
2776 this.document.popEmSize();
2777 }
2778 }
2779 }]);
2780
2781 return RenderedElement;
2782}(Element);
2783
2784function _createSuper$5(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$5(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
2785
2786function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
2787
2788var TextElement = /*#__PURE__*/function (_RenderedElement) {
2789 _inherits__default['default'](TextElement, _RenderedElement);
2790
2791 var _super = _createSuper$5(TextElement);
2792
2793 function TextElement(document, node, captureTextNodes) {
2794 var _this;
2795
2796 _classCallCheck__default['default'](this, TextElement);
2797
2798 _this = _super.call(this, document, node, (this instanceof TextElement ? this.constructor : void 0) === TextElement ? true : captureTextNodes);
2799 _this.type = 'text';
2800 _this.x = 0;
2801 _this.y = 0;
2802 _this.measureCache = -1;
2803 return _this;
2804 }
2805
2806 _createClass__default['default'](TextElement, [{
2807 key: "setContext",
2808 value: function setContext(ctx) {
2809 var fromMeasure = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2810
2811 _get__default['default'](_getPrototypeOf__default['default'](TextElement.prototype), "setContext", this).call(this, ctx, fromMeasure);
2812
2813 var textBaseline = this.getStyle('dominant-baseline').getTextBaseline() || this.getStyle('alignment-baseline').getTextBaseline();
2814
2815 if (textBaseline) {
2816 ctx.textBaseline = textBaseline;
2817 }
2818 }
2819 }, {
2820 key: "initializeCoordinates",
2821 value: function initializeCoordinates(ctx) {
2822 this.x = this.getAttribute('x').getPixels('x');
2823 this.y = this.getAttribute('y').getPixels('y');
2824 var dxAttr = this.getAttribute('dx');
2825 var dyAttr = this.getAttribute('dy');
2826
2827 if (dxAttr.hasValue()) {
2828 this.x += dxAttr.getPixels('x');
2829 }
2830
2831 if (dyAttr.hasValue()) {
2832 this.y += dyAttr.getPixels('y');
2833 }
2834
2835 this.x += this.getAnchorDelta(ctx, this, 0);
2836 }
2837 }, {
2838 key: "getBoundingBox",
2839 value: function getBoundingBox(ctx) {
2840 var _context,
2841 _this2 = this;
2842
2843 if (this.type !== 'text') {
2844 return this.getTElementBoundingBox(ctx);
2845 }
2846
2847 this.initializeCoordinates(ctx);
2848 var boundingBox = null;
2849
2850 _forEachInstanceProperty__default['default'](_context = this.children).call(_context, function (_, i) {
2851 var childBoundingBox = _this2.getChildBoundingBox(ctx, _this2, _this2, i);
2852
2853 if (!boundingBox) {
2854 boundingBox = childBoundingBox;
2855 } else {
2856 boundingBox.addBoundingBox(childBoundingBox);
2857 }
2858 });
2859
2860 return boundingBox;
2861 }
2862 }, {
2863 key: "getFontSize",
2864 value: function getFontSize() {
2865 var document = this.document,
2866 parent = this.parent;
2867 var inheritFontSize = Font.parse(document.ctx.font).fontSize;
2868 var fontSize = parent.getStyle('font-size').getNumber(inheritFontSize);
2869 return fontSize;
2870 }
2871 }, {
2872 key: "getTElementBoundingBox",
2873 value: function getTElementBoundingBox(ctx) {
2874 var fontSize = this.getFontSize();
2875 return new BoundingBox(this.x, this.y - fontSize, this.x + this.measureText(ctx), this.y);
2876 }
2877 }, {
2878 key: "getGlyph",
2879 value: function getGlyph(font, text, i) {
2880 var char = text[i];
2881 var glyph = null;
2882
2883 if (font.isArabic) {
2884 var len = text.length;
2885 var prevChar = text[i - 1];
2886 var nextChar = text[i + 1];
2887 var arabicForm = 'isolated';
2888
2889 if ((i === 0 || prevChar === ' ') && i < len - 2 && nextChar !== ' ') {
2890 arabicForm = 'terminal';
2891 }
2892
2893 if (i > 0 && prevChar !== ' ' && i < len - 2 && nextChar !== ' ') {
2894 arabicForm = 'medial';
2895 }
2896
2897 if (i > 0 && prevChar !== ' ' && (i === len - 1 || nextChar === ' ')) {
2898 arabicForm = 'initial';
2899 }
2900
2901 if (typeof font.glyphs[char] !== 'undefined') {
2902 glyph = font.glyphs[char][arabicForm];
2903
2904 if (!glyph && font.glyphs[char].type === 'glyph') {
2905 glyph = font.glyphs[char];
2906 }
2907 }
2908 } else {
2909 glyph = font.glyphs[char];
2910 }
2911
2912 if (!glyph) {
2913 glyph = font.missingGlyph;
2914 }
2915
2916 return glyph;
2917 }
2918 }, {
2919 key: "getText",
2920 value: function getText() {
2921 return '';
2922 }
2923 }, {
2924 key: "getTextFromNode",
2925 value: function getTextFromNode(node) {
2926 var textNode = node || this.node;
2927
2928 var childNodes = _Array$from__default['default'](textNode.parentNode.childNodes);
2929
2930 var index = _indexOfInstanceProperty__default['default'](childNodes).call(childNodes, textNode);
2931
2932 var lastIndex = childNodes.length - 1;
2933 var text = compressSpaces(textNode.value || textNode.text || textNode.textContent || '');
2934
2935 if (index === 0) {
2936 text = trimLeft(text);
2937 }
2938
2939 if (index === lastIndex) {
2940 text = trimRight(text);
2941 }
2942
2943 return text;
2944 }
2945 }, {
2946 key: "renderChildren",
2947 value: function renderChildren(ctx) {
2948 var _context2,
2949 _this3 = this;
2950
2951 if (this.type !== 'text') {
2952 this.renderTElementChildren(ctx);
2953 return;
2954 }
2955
2956 this.initializeCoordinates(ctx);
2957
2958 _forEachInstanceProperty__default['default'](_context2 = this.children).call(_context2, function (_, i) {
2959 _this3.renderChild(ctx, _this3, _this3, i);
2960 });
2961
2962 var mouse = this.document.screen.mouse; // Do not calc bounding box if mouse is not working.
2963
2964 if (mouse.isWorking()) {
2965 mouse.checkBoundingBox(this, this.getBoundingBox(ctx));
2966 }
2967 }
2968 }, {
2969 key: "renderTElementChildren",
2970 value: function renderTElementChildren(ctx) {
2971 var document = this.document,
2972 parent = this.parent;
2973 var renderText = this.getText();
2974 var customFont = parent.getStyle('font-family').getDefinition();
2975
2976 if (customFont) {
2977 var _context3;
2978
2979 var unitsPerEm = customFont.fontFace.unitsPerEm;
2980 var ctxFont = Font.parse(document.ctx.font);
2981 var fontSize = parent.getStyle('font-size').getNumber(ctxFont.fontSize);
2982 var fontStyle = parent.getStyle('font-style').getString(ctxFont.fontStyle);
2983 var scale = fontSize / unitsPerEm;
2984 var text = customFont.isRTL ? _reverseInstanceProperty__default['default'](_context3 = renderText.split('')).call(_context3).join('') : renderText;
2985 var dx = toNumbers(parent.getAttribute('dx').getString());
2986 var len = text.length;
2987
2988 for (var i = 0; i < len; i++) {
2989 var glyph = this.getGlyph(customFont, text, i);
2990 ctx.translate(this.x, this.y);
2991 ctx.scale(scale, -scale);
2992 var lw = ctx.lineWidth;
2993 ctx.lineWidth = ctx.lineWidth * unitsPerEm / fontSize;
2994
2995 if (fontStyle === 'italic') {
2996 ctx.transform(1, 0, .4, 1, 0, 0);
2997 }
2998
2999 glyph.render(ctx);
3000
3001 if (fontStyle === 'italic') {
3002 ctx.transform(1, 0, -.4, 1, 0, 0);
3003 }
3004
3005 ctx.lineWidth = lw;
3006 ctx.scale(1 / scale, -1 / scale);
3007 ctx.translate(-this.x, -this.y);
3008 this.x += fontSize * (glyph.horizAdvX || customFont.horizAdvX) / unitsPerEm;
3009
3010 if (typeof dx[i] !== 'undefined' && !isNaN(dx[i])) {
3011 this.x += dx[i];
3012 }
3013 }
3014
3015 return;
3016 }
3017
3018 var x = this.x,
3019 y = this.y;
3020
3021 if (ctx.paintOrder === 'stroke') {
3022 if (ctx.strokeStyle) {
3023 ctx.strokeText(renderText, x, y);
3024 }
3025
3026 if (ctx.fillStyle) {
3027 ctx.fillText(renderText, x, y);
3028 }
3029 } else {
3030 if (ctx.fillStyle) {
3031 ctx.fillText(renderText, x, y);
3032 }
3033
3034 if (ctx.strokeStyle) {
3035 ctx.strokeText(renderText, x, y);
3036 }
3037 }
3038 }
3039 }, {
3040 key: "getAnchorDelta",
3041 value: function getAnchorDelta(ctx, parent, startI) {
3042 var textAnchor = this.getStyle('text-anchor').getString('start');
3043
3044 if (textAnchor !== 'start') {
3045 var children = parent.children;
3046 var len = children.length;
3047 var child = null;
3048 var width = 0;
3049
3050 for (var i = startI; i < len; i++) {
3051 child = children[i];
3052
3053 if (i > startI && child.getAttribute('x').hasValue() || child.getAttribute('text-anchor').hasValue()) {
3054 break; // new group
3055 }
3056
3057 width += child.measureTextRecursive(ctx);
3058 }
3059
3060 return -1 * (textAnchor === 'end' ? width : width / 2.0);
3061 }
3062
3063 return 0;
3064 }
3065 }, {
3066 key: "adjustChildCoordinates",
3067 value: function adjustChildCoordinates(ctx, textParent, parent, i) {
3068 var child = parent.children[i];
3069
3070 if (typeof child.measureText !== 'function') {
3071 return child;
3072 }
3073
3074 ctx.save();
3075 child.setContext(ctx, true);
3076 var xAttr = child.getAttribute('x');
3077 var yAttr = child.getAttribute('y');
3078 var dxAttr = child.getAttribute('dx');
3079 var dyAttr = child.getAttribute('dy');
3080 var textAnchor = child.getAttribute('text-anchor').getString('start');
3081
3082 if (i === 0 && child.type !== 'textNode') {
3083 if (!xAttr.hasValue()) {
3084 xAttr.setValue(textParent.getAttribute('x').getValue('0'));
3085 }
3086
3087 if (!yAttr.hasValue()) {
3088 yAttr.setValue(textParent.getAttribute('y').getValue('0'));
3089 }
3090
3091 if (!dxAttr.hasValue()) {
3092 dxAttr.setValue(textParent.getAttribute('dx').getValue('0'));
3093 }
3094
3095 if (!dyAttr.hasValue()) {
3096 dyAttr.setValue(textParent.getAttribute('dy').getValue('0'));
3097 }
3098 }
3099
3100 if (xAttr.hasValue()) {
3101 child.x = xAttr.getPixels('x') + textParent.getAnchorDelta(ctx, parent, i);
3102
3103 if (textAnchor !== 'start') {
3104 var width = child.measureTextRecursive(ctx);
3105 child.x += -1 * (textAnchor === 'end' ? width : width / 2.0);
3106 }
3107
3108 if (dxAttr.hasValue()) {
3109 child.x += dxAttr.getPixels('x');
3110 }
3111 } else {
3112 if (textAnchor !== 'start') {
3113 var _width = child.measureTextRecursive(ctx);
3114
3115 textParent.x += -1 * (textAnchor === 'end' ? _width : _width / 2.0);
3116 }
3117
3118 if (dxAttr.hasValue()) {
3119 textParent.x += dxAttr.getPixels('x');
3120 }
3121
3122 child.x = textParent.x;
3123 }
3124
3125 textParent.x = child.x + child.measureText(ctx);
3126
3127 if (yAttr.hasValue()) {
3128 child.y = yAttr.getPixels('y');
3129
3130 if (dyAttr.hasValue()) {
3131 child.y += dyAttr.getPixels('y');
3132 }
3133 } else {
3134 if (dyAttr.hasValue()) {
3135 textParent.y += dyAttr.getPixels('y');
3136 }
3137
3138 child.y = textParent.y;
3139 }
3140
3141 textParent.y = child.y;
3142 child.clearContext(ctx);
3143 ctx.restore();
3144 return child;
3145 }
3146 }, {
3147 key: "getChildBoundingBox",
3148 value: function getChildBoundingBox(ctx, textParent, parent, i) {
3149 var _context4;
3150
3151 var child = this.adjustChildCoordinates(ctx, textParent, parent, i); // not a text node?
3152
3153 if (typeof child.getBoundingBox !== 'function') {
3154 return null;
3155 }
3156
3157 var boundingBox = child.getBoundingBox(ctx);
3158
3159 if (!boundingBox) {
3160 return null;
3161 }
3162
3163 _forEachInstanceProperty__default['default'](_context4 = child.children).call(_context4, function (_, i) {
3164 var childBoundingBox = textParent.getChildBoundingBox(ctx, textParent, child, i);
3165 boundingBox.addBoundingBox(childBoundingBox);
3166 });
3167
3168 return boundingBox;
3169 }
3170 }, {
3171 key: "renderChild",
3172 value: function renderChild(ctx, textParent, parent, i) {
3173 var _context5;
3174
3175 var child = this.adjustChildCoordinates(ctx, textParent, parent, i);
3176 child.render(ctx);
3177
3178 _forEachInstanceProperty__default['default'](_context5 = child.children).call(_context5, function (_, i) {
3179 textParent.renderChild(ctx, textParent, child, i);
3180 });
3181 }
3182 }, {
3183 key: "measureTextRecursive",
3184 value: function measureTextRecursive(ctx) {
3185 var _context6;
3186
3187 var width = _reduceInstanceProperty__default['default'](_context6 = this.children).call(_context6, function (width, child) {
3188 return width + child.measureTextRecursive(ctx);
3189 }, this.measureText(ctx));
3190
3191 return width;
3192 }
3193 }, {
3194 key: "measureText",
3195 value: function measureText(ctx) {
3196 var measureCache = this.measureCache;
3197
3198 if (~measureCache) {
3199 return measureCache;
3200 }
3201
3202 var renderText = this.getText();
3203 var measure = this.measureTargetText(ctx, renderText);
3204 this.measureCache = measure;
3205 return measure;
3206 }
3207 }, {
3208 key: "measureTargetText",
3209 value: function measureTargetText(ctx, targetText) {
3210 if (!targetText.length) {
3211 return 0;
3212 }
3213
3214 var parent = this.parent;
3215 var customFont = parent.getStyle('font-family').getDefinition();
3216
3217 if (customFont) {
3218 var _context7;
3219
3220 var fontSize = this.getFontSize();
3221 var text = customFont.isRTL ? _reverseInstanceProperty__default['default'](_context7 = targetText.split('')).call(_context7).join('') : targetText;
3222 var dx = toNumbers(parent.getAttribute('dx').getString());
3223 var len = text.length;
3224 var _measure = 0;
3225
3226 for (var i = 0; i < len; i++) {
3227 var glyph = this.getGlyph(customFont, text, i);
3228 _measure += (glyph.horizAdvX || customFont.horizAdvX) * fontSize / customFont.fontFace.unitsPerEm;
3229
3230 if (typeof dx[i] !== 'undefined' && !isNaN(dx[i])) {
3231 _measure += dx[i];
3232 }
3233 }
3234
3235 return _measure;
3236 }
3237
3238 if (!ctx.measureText) {
3239 return targetText.length * 10;
3240 }
3241
3242 ctx.save();
3243 this.setContext(ctx, true);
3244
3245 var _ctx$measureText = ctx.measureText(targetText),
3246 measure = _ctx$measureText.width;
3247
3248 this.clearContext(ctx);
3249 ctx.restore();
3250 return measure;
3251 }
3252 }]);
3253
3254 return TextElement;
3255}(RenderedElement);
3256
3257function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
3258
3259function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
3260
3261var TSpanElement = /*#__PURE__*/function (_TextElement) {
3262 _inherits__default['default'](TSpanElement, _TextElement);
3263
3264 var _super = _createSuper$6(TSpanElement);
3265
3266 function TSpanElement(document, node, captureTextNodes) {
3267 var _this;
3268
3269 _classCallCheck__default['default'](this, TSpanElement);
3270
3271 _this = _super.call(this, document, node, (this instanceof TSpanElement ? this.constructor : void 0) === TSpanElement ? true : captureTextNodes);
3272 _this.type = 'tspan'; // if this node has children, then they own the text
3273
3274 _this.text = _this.children.length > 0 ? '' : _this.getTextFromNode();
3275 return _this;
3276 }
3277
3278 _createClass__default['default'](TSpanElement, [{
3279 key: "getText",
3280 value: function getText() {
3281 return this.text;
3282 }
3283 }]);
3284
3285 return TSpanElement;
3286}(TextElement);
3287
3288function _createSuper$7(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$7(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
3289
3290function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
3291
3292var TextNode = /*#__PURE__*/function (_TSpanElement) {
3293 _inherits__default['default'](TextNode, _TSpanElement);
3294
3295 var _super = _createSuper$7(TextNode);
3296
3297 function TextNode() {
3298 var _this;
3299
3300 _classCallCheck__default['default'](this, TextNode);
3301
3302 _this = _super.apply(this, arguments);
3303 _this.type = 'textNode';
3304 return _this;
3305 }
3306
3307 return TextNode;
3308}(TSpanElement);
3309
3310function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
3311
3312function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
3313
3314var PathParser = /*#__PURE__*/function (_SVGPathData) {
3315 _inherits__default['default'](PathParser, _SVGPathData);
3316
3317 var _super = _createSuper$8(PathParser);
3318
3319 function PathParser(path) {
3320 var _this;
3321
3322 _classCallCheck__default['default'](this, PathParser);
3323
3324 _this = _super.call(this, path // Fix spaces after signs.
3325 .replace(/[+-.]\s+/g, '-') // Remove invalid part.
3326 .replace(/[^MmZzLlHhVvCcSsQqTtAae\d\s.,+-].*/g, ''));
3327 _this.control = null;
3328 _this.start = null;
3329 _this.current = null;
3330 _this.command = null;
3331 _this.commands = _this.commands;
3332 _this.i = -1;
3333 _this.previousCommand = null;
3334 _this.points = [];
3335 _this.angles = [];
3336 return _this;
3337 }
3338
3339 _createClass__default['default'](PathParser, [{
3340 key: "reset",
3341 value: function reset() {
3342 this.i = -1;
3343 this.command = null;
3344 this.previousCommand = null;
3345 this.start = new Point(0, 0);
3346 this.control = new Point(0, 0);
3347 this.current = new Point(0, 0);
3348 this.points = [];
3349 this.angles = [];
3350 }
3351 }, {
3352 key: "isEnd",
3353 value: function isEnd() {
3354 var i = this.i,
3355 commands = this.commands;
3356 return i >= commands.length - 1;
3357 }
3358 }, {
3359 key: "next",
3360 value: function next() {
3361 var command = this.commands[++this.i];
3362 this.previousCommand = this.command;
3363 this.command = command;
3364 return command;
3365 }
3366 }, {
3367 key: "getPoint",
3368 value: function getPoint() {
3369 var xProp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'x';
3370 var yProp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'y';
3371 var point = new Point(this.command[xProp], this.command[yProp]);
3372 return this.makeAbsolute(point);
3373 }
3374 }, {
3375 key: "getAsControlPoint",
3376 value: function getAsControlPoint(xProp, yProp) {
3377 var point = this.getPoint(xProp, yProp);
3378 this.control = point;
3379 return point;
3380 }
3381 }, {
3382 key: "getAsCurrentPoint",
3383 value: function getAsCurrentPoint(xProp, yProp) {
3384 var point = this.getPoint(xProp, yProp);
3385 this.current = point;
3386 return point;
3387 }
3388 }, {
3389 key: "getReflectedControlPoint",
3390 value: function getReflectedControlPoint() {
3391 var previousCommand = this.previousCommand.type;
3392
3393 if (previousCommand !== svgPathdata.SVGPathData.CURVE_TO && previousCommand !== svgPathdata.SVGPathData.SMOOTH_CURVE_TO && previousCommand !== svgPathdata.SVGPathData.QUAD_TO && previousCommand !== svgPathdata.SVGPathData.SMOOTH_QUAD_TO) {
3394 return this.current;
3395 } // reflect point
3396
3397
3398 var _this$current = this.current,
3399 cx = _this$current.x,
3400 cy = _this$current.y,
3401 _this$control = this.control,
3402 ox = _this$control.x,
3403 oy = _this$control.y;
3404 var point = new Point(2 * cx - ox, 2 * cy - oy);
3405 return point;
3406 }
3407 }, {
3408 key: "makeAbsolute",
3409 value: function makeAbsolute(point) {
3410 if (this.command.relative) {
3411 var _this$current2 = this.current,
3412 x = _this$current2.x,
3413 y = _this$current2.y;
3414 point.x += x;
3415 point.y += y;
3416 }
3417
3418 return point;
3419 }
3420 }, {
3421 key: "addMarker",
3422 value: function addMarker(point, from, priorTo) {
3423 var points = this.points,
3424 angles = this.angles; // if the last angle isn't filled in because we didn't have this point yet ...
3425
3426 if (priorTo && angles.length > 0 && !angles[angles.length - 1]) {
3427 angles[angles.length - 1] = points[points.length - 1].angleTo(priorTo);
3428 }
3429
3430 this.addMarkerAngle(point, from ? from.angleTo(point) : null);
3431 }
3432 }, {
3433 key: "addMarkerAngle",
3434 value: function addMarkerAngle(point, angle) {
3435 this.points.push(point);
3436 this.angles.push(angle);
3437 }
3438 }, {
3439 key: "getMarkerPoints",
3440 value: function getMarkerPoints() {
3441 return this.points;
3442 }
3443 }, {
3444 key: "getMarkerAngles",
3445 value: function getMarkerAngles() {
3446 var angles = this.angles;
3447 var len = angles.length;
3448
3449 for (var i = 0; i < len; i++) {
3450 if (!angles[i]) {
3451 for (var j = i + 1; j < len; j++) {
3452 if (angles[j]) {
3453 angles[i] = angles[j];
3454 break;
3455 }
3456 }
3457 }
3458 }
3459
3460 return angles;
3461 }
3462 }]);
3463
3464 return PathParser;
3465}(svgPathdata.SVGPathData);
3466
3467function _createSuper$9(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$9(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
3468
3469function _isNativeReflectConstruct$9() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
3470
3471var PathElement = /*#__PURE__*/function (_RenderedElement) {
3472 _inherits__default['default'](PathElement, _RenderedElement);
3473
3474 var _super = _createSuper$9(PathElement);
3475
3476 function PathElement(document, node, captureTextNodes) {
3477 var _this;
3478
3479 _classCallCheck__default['default'](this, PathElement);
3480
3481 _this = _super.call(this, document, node, captureTextNodes);
3482 _this.type = 'path';
3483 _this.pathParser = null;
3484 _this.pathParser = new PathParser(_this.getAttribute('d').getString());
3485 return _this;
3486 }
3487
3488 _createClass__default['default'](PathElement, [{
3489 key: "path",
3490 value: function path(ctx) {
3491 var pathParser = this.pathParser;
3492 var boundingBox = new BoundingBox();
3493 pathParser.reset();
3494
3495 if (ctx) {
3496 ctx.beginPath();
3497 }
3498
3499 while (!pathParser.isEnd()) {
3500 switch (pathParser.next().type) {
3501 case PathParser.MOVE_TO:
3502 this.pathM(ctx, boundingBox);
3503 break;
3504
3505 case PathParser.LINE_TO:
3506 this.pathL(ctx, boundingBox);
3507 break;
3508
3509 case PathParser.HORIZ_LINE_TO:
3510 this.pathH(ctx, boundingBox);
3511 break;
3512
3513 case PathParser.VERT_LINE_TO:
3514 this.pathV(ctx, boundingBox);
3515 break;
3516
3517 case PathParser.CURVE_TO:
3518 this.pathC(ctx, boundingBox);
3519 break;
3520
3521 case PathParser.SMOOTH_CURVE_TO:
3522 this.pathS(ctx, boundingBox);
3523 break;
3524
3525 case PathParser.QUAD_TO:
3526 this.pathQ(ctx, boundingBox);
3527 break;
3528
3529 case PathParser.SMOOTH_QUAD_TO:
3530 this.pathT(ctx, boundingBox);
3531 break;
3532
3533 case PathParser.ARC:
3534 this.pathA(ctx, boundingBox);
3535 break;
3536
3537 case PathParser.CLOSE_PATH:
3538 this.pathZ(ctx, boundingBox);
3539 break;
3540 }
3541 }
3542
3543 return boundingBox;
3544 }
3545 }, {
3546 key: "getBoundingBox",
3547 value: function getBoundingBox(_) {
3548 return this.path();
3549 }
3550 }, {
3551 key: "getMarkers",
3552 value: function getMarkers() {
3553 var pathParser = this.pathParser;
3554 var points = pathParser.getMarkerPoints();
3555 var angles = pathParser.getMarkerAngles();
3556
3557 var markers = _mapInstanceProperty__default['default'](points).call(points, function (point, i) {
3558 return [point, angles[i]];
3559 });
3560
3561 return markers;
3562 }
3563 }, {
3564 key: "renderChildren",
3565 value: function renderChildren(ctx) {
3566 this.path(ctx);
3567 this.document.screen.mouse.checkPath(this, ctx);
3568 var fillRuleStyleProp = this.getStyle('fill-rule');
3569
3570 if (ctx.fillStyle !== '') {
3571 if (fillRuleStyleProp.getString('inherit') !== 'inherit') {
3572 _fillInstanceProperty__default['default'](ctx).call(ctx, fillRuleStyleProp.getString());
3573 } else {
3574 _fillInstanceProperty__default['default'](ctx).call(ctx);
3575 }
3576 }
3577
3578 if (ctx.strokeStyle !== '') {
3579 ctx.stroke();
3580 }
3581
3582 var markers = this.getMarkers();
3583
3584 if (markers) {
3585 var markersLastIndex = markers.length - 1;
3586 var markerStartStyleProp = this.getStyle('marker-start');
3587 var markerMidStyleProp = this.getStyle('marker-mid');
3588 var markerEndStyleProp = this.getStyle('marker-end');
3589
3590 if (markerStartStyleProp.isUrlDefinition()) {
3591 var marker = markerStartStyleProp.getDefinition();
3592
3593 var _markers$ = _slicedToArray__default['default'](markers[0], 2),
3594 point = _markers$[0],
3595 angle = _markers$[1];
3596
3597 marker.render(ctx, point, angle);
3598 }
3599
3600 if (markerMidStyleProp.isUrlDefinition()) {
3601 var _marker = markerMidStyleProp.getDefinition();
3602
3603 for (var i = 1; i < markersLastIndex; i++) {
3604 var _markers$i = _slicedToArray__default['default'](markers[i], 2),
3605 _point = _markers$i[0],
3606 _angle = _markers$i[1];
3607
3608 _marker.render(ctx, _point, _angle);
3609 }
3610 }
3611
3612 if (markerEndStyleProp.isUrlDefinition()) {
3613 var _marker2 = markerEndStyleProp.getDefinition();
3614
3615 var _markers$markersLastI = _slicedToArray__default['default'](markers[markersLastIndex], 2),
3616 _point2 = _markers$markersLastI[0],
3617 _angle2 = _markers$markersLastI[1];
3618
3619 _marker2.render(ctx, _point2, _angle2);
3620 }
3621 }
3622 }
3623 }, {
3624 key: "pathM",
3625 value: function pathM(ctx, boundingBox) {
3626 var pathParser = this.pathParser;
3627
3628 var _PathElement$pathM = PathElement.pathM(pathParser),
3629 point = _PathElement$pathM.point;
3630
3631 var x = point.x,
3632 y = point.y;
3633 pathParser.addMarker(point);
3634 boundingBox.addPoint(x, y);
3635
3636 if (ctx) {
3637 ctx.moveTo(x, y);
3638 }
3639 }
3640 }, {
3641 key: "pathL",
3642 value: function pathL(ctx, boundingBox) {
3643 var pathParser = this.pathParser;
3644
3645 var _PathElement$pathL = PathElement.pathL(pathParser),
3646 current = _PathElement$pathL.current,
3647 point = _PathElement$pathL.point;
3648
3649 var x = point.x,
3650 y = point.y;
3651 pathParser.addMarker(point, current);
3652 boundingBox.addPoint(x, y);
3653
3654 if (ctx) {
3655 ctx.lineTo(x, y);
3656 }
3657 }
3658 }, {
3659 key: "pathH",
3660 value: function pathH(ctx, boundingBox) {
3661 var pathParser = this.pathParser;
3662
3663 var _PathElement$pathH = PathElement.pathH(pathParser),
3664 current = _PathElement$pathH.current,
3665 point = _PathElement$pathH.point;
3666
3667 var x = point.x,
3668 y = point.y;
3669 pathParser.addMarker(point, current);
3670 boundingBox.addPoint(x, y);
3671
3672 if (ctx) {
3673 ctx.lineTo(x, y);
3674 }
3675 }
3676 }, {
3677 key: "pathV",
3678 value: function pathV(ctx, boundingBox) {
3679 var pathParser = this.pathParser;
3680
3681 var _PathElement$pathV = PathElement.pathV(pathParser),
3682 current = _PathElement$pathV.current,
3683 point = _PathElement$pathV.point;
3684
3685 var x = point.x,
3686 y = point.y;
3687 pathParser.addMarker(point, current);
3688 boundingBox.addPoint(x, y);
3689
3690 if (ctx) {
3691 ctx.lineTo(x, y);
3692 }
3693 }
3694 }, {
3695 key: "pathC",
3696 value: function pathC(ctx, boundingBox) {
3697 var pathParser = this.pathParser;
3698
3699 var _PathElement$pathC = PathElement.pathC(pathParser),
3700 current = _PathElement$pathC.current,
3701 point = _PathElement$pathC.point,
3702 controlPoint = _PathElement$pathC.controlPoint,
3703 currentPoint = _PathElement$pathC.currentPoint;
3704
3705 pathParser.addMarker(currentPoint, controlPoint, point);
3706 boundingBox.addBezierCurve(current.x, current.y, point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3707
3708 if (ctx) {
3709 ctx.bezierCurveTo(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3710 }
3711 }
3712 }, {
3713 key: "pathS",
3714 value: function pathS(ctx, boundingBox) {
3715 var pathParser = this.pathParser;
3716
3717 var _PathElement$pathS = PathElement.pathS(pathParser),
3718 current = _PathElement$pathS.current,
3719 point = _PathElement$pathS.point,
3720 controlPoint = _PathElement$pathS.controlPoint,
3721 currentPoint = _PathElement$pathS.currentPoint;
3722
3723 pathParser.addMarker(currentPoint, controlPoint, point);
3724 boundingBox.addBezierCurve(current.x, current.y, point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3725
3726 if (ctx) {
3727 ctx.bezierCurveTo(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3728 }
3729 }
3730 }, {
3731 key: "pathQ",
3732 value: function pathQ(ctx, boundingBox) {
3733 var pathParser = this.pathParser;
3734
3735 var _PathElement$pathQ = PathElement.pathQ(pathParser),
3736 current = _PathElement$pathQ.current,
3737 controlPoint = _PathElement$pathQ.controlPoint,
3738 currentPoint = _PathElement$pathQ.currentPoint;
3739
3740 pathParser.addMarker(currentPoint, controlPoint, controlPoint);
3741 boundingBox.addQuadraticCurve(current.x, current.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3742
3743 if (ctx) {
3744 ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3745 }
3746 }
3747 }, {
3748 key: "pathT",
3749 value: function pathT(ctx, boundingBox) {
3750 var pathParser = this.pathParser;
3751
3752 var _PathElement$pathT = PathElement.pathT(pathParser),
3753 current = _PathElement$pathT.current,
3754 controlPoint = _PathElement$pathT.controlPoint,
3755 currentPoint = _PathElement$pathT.currentPoint;
3756
3757 pathParser.addMarker(currentPoint, controlPoint, controlPoint);
3758 boundingBox.addQuadraticCurve(current.x, current.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3759
3760 if (ctx) {
3761 ctx.quadraticCurveTo(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
3762 }
3763 }
3764 }, {
3765 key: "pathA",
3766 value: function pathA(ctx, boundingBox) {
3767 var pathParser = this.pathParser;
3768
3769 var _PathElement$pathA = PathElement.pathA(pathParser),
3770 currentPoint = _PathElement$pathA.currentPoint,
3771 rX = _PathElement$pathA.rX,
3772 rY = _PathElement$pathA.rY,
3773 sweepFlag = _PathElement$pathA.sweepFlag,
3774 xAxisRotation = _PathElement$pathA.xAxisRotation,
3775 centp = _PathElement$pathA.centp,
3776 a1 = _PathElement$pathA.a1,
3777 ad = _PathElement$pathA.ad; // for markers
3778
3779
3780 var dir = 1 - sweepFlag ? 1.0 : -1.0;
3781 var ah = a1 + dir * (ad / 2.0);
3782 var halfWay = new Point(centp.x + rX * Math.cos(ah), centp.y + rY * Math.sin(ah));
3783 pathParser.addMarkerAngle(halfWay, ah - dir * Math.PI / 2);
3784 pathParser.addMarkerAngle(currentPoint, ah - dir * Math.PI);
3785 boundingBox.addPoint(currentPoint.x, currentPoint.y); // TODO: this is too naive, make it better
3786
3787 if (ctx && !isNaN(a1) && !isNaN(ad)) {
3788 var r = rX > rY ? rX : rY;
3789 var sx = rX > rY ? 1 : rX / rY;
3790 var sy = rX > rY ? rY / rX : 1;
3791 ctx.translate(centp.x, centp.y);
3792 ctx.rotate(xAxisRotation);
3793 ctx.scale(sx, sy);
3794 ctx.arc(0, 0, r, a1, a1 + ad, Boolean(1 - sweepFlag));
3795 ctx.scale(1 / sx, 1 / sy);
3796 ctx.rotate(-xAxisRotation);
3797 ctx.translate(-centp.x, -centp.y);
3798 }
3799 }
3800 }, {
3801 key: "pathZ",
3802 value: function pathZ(ctx, boundingBox) {
3803 PathElement.pathZ(this.pathParser);
3804
3805 if (ctx) {
3806 // only close path if it is not a straight line
3807 if (boundingBox.x1 !== boundingBox.x2 && boundingBox.y1 !== boundingBox.y2) {
3808 ctx.closePath();
3809 }
3810 }
3811 }
3812 }], [{
3813 key: "pathM",
3814 value: function pathM(pathParser) {
3815 var point = pathParser.getAsCurrentPoint();
3816 pathParser.start = pathParser.current;
3817 return {
3818 point: point
3819 };
3820 }
3821 }, {
3822 key: "pathL",
3823 value: function pathL(pathParser) {
3824 var current = pathParser.current;
3825 var point = pathParser.getAsCurrentPoint();
3826 return {
3827 current: current,
3828 point: point
3829 };
3830 }
3831 }, {
3832 key: "pathH",
3833 value: function pathH(pathParser) {
3834 var current = pathParser.current,
3835 command = pathParser.command;
3836 var point = new Point((command.relative ? current.x : 0) + command.x, current.y);
3837 pathParser.current = point;
3838 return {
3839 current: current,
3840 point: point
3841 };
3842 }
3843 }, {
3844 key: "pathV",
3845 value: function pathV(pathParser) {
3846 var current = pathParser.current,
3847 command = pathParser.command;
3848 var point = new Point(current.x, (command.relative ? current.y : 0) + command.y);
3849 pathParser.current = point;
3850 return {
3851 current: current,
3852 point: point
3853 };
3854 }
3855 }, {
3856 key: "pathC",
3857 value: function pathC(pathParser) {
3858 var current = pathParser.current;
3859 var point = pathParser.getPoint('x1', 'y1');
3860 var controlPoint = pathParser.getAsControlPoint('x2', 'y2');
3861 var currentPoint = pathParser.getAsCurrentPoint();
3862 return {
3863 current: current,
3864 point: point,
3865 controlPoint: controlPoint,
3866 currentPoint: currentPoint
3867 };
3868 }
3869 }, {
3870 key: "pathS",
3871 value: function pathS(pathParser) {
3872 var current = pathParser.current;
3873 var point = pathParser.getReflectedControlPoint();
3874 var controlPoint = pathParser.getAsControlPoint('x2', 'y2');
3875 var currentPoint = pathParser.getAsCurrentPoint();
3876 return {
3877 current: current,
3878 point: point,
3879 controlPoint: controlPoint,
3880 currentPoint: currentPoint
3881 };
3882 }
3883 }, {
3884 key: "pathQ",
3885 value: function pathQ(pathParser) {
3886 var current = pathParser.current;
3887 var controlPoint = pathParser.getAsControlPoint('x1', 'y1');
3888 var currentPoint = pathParser.getAsCurrentPoint();
3889 return {
3890 current: current,
3891 controlPoint: controlPoint,
3892 currentPoint: currentPoint
3893 };
3894 }
3895 }, {
3896 key: "pathT",
3897 value: function pathT(pathParser) {
3898 var current = pathParser.current;
3899 var controlPoint = pathParser.getReflectedControlPoint();
3900 pathParser.control = controlPoint;
3901 var currentPoint = pathParser.getAsCurrentPoint();
3902 return {
3903 current: current,
3904 controlPoint: controlPoint,
3905 currentPoint: currentPoint
3906 };
3907 }
3908 }, {
3909 key: "pathA",
3910 value: function pathA(pathParser) {
3911 var current = pathParser.current,
3912 command = pathParser.command;
3913 var rX = command.rX,
3914 rY = command.rY,
3915 xRot = command.xRot,
3916 lArcFlag = command.lArcFlag,
3917 sweepFlag = command.sweepFlag;
3918 var xAxisRotation = xRot * (Math.PI / 180.0);
3919 var currentPoint = pathParser.getAsCurrentPoint(); // Conversion from endpoint to center parameterization
3920 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
3921 // x1', y1'
3922
3923 var currp = new Point(Math.cos(xAxisRotation) * (current.x - currentPoint.x) / 2.0 + Math.sin(xAxisRotation) * (current.y - currentPoint.y) / 2.0, -Math.sin(xAxisRotation) * (current.x - currentPoint.x) / 2.0 + Math.cos(xAxisRotation) * (current.y - currentPoint.y) / 2.0); // adjust radii
3924
3925 var l = Math.pow(currp.x, 2) / Math.pow(rX, 2) + Math.pow(currp.y, 2) / Math.pow(rY, 2);
3926
3927 if (l > 1) {
3928 rX *= Math.sqrt(l);
3929 rY *= Math.sqrt(l);
3930 } // cx', cy'
3931
3932
3933 var s = (lArcFlag === sweepFlag ? -1 : 1) * Math.sqrt((Math.pow(rX, 2) * Math.pow(rY, 2) - Math.pow(rX, 2) * Math.pow(currp.y, 2) - Math.pow(rY, 2) * Math.pow(currp.x, 2)) / (Math.pow(rX, 2) * Math.pow(currp.y, 2) + Math.pow(rY, 2) * Math.pow(currp.x, 2)));
3934
3935 if (isNaN(s)) {
3936 s = 0;
3937 }
3938
3939 var cpp = new Point(s * rX * currp.y / rY, s * -rY * currp.x / rX); // cx, cy
3940
3941 var centp = new Point((current.x + currentPoint.x) / 2.0 + Math.cos(xAxisRotation) * cpp.x - Math.sin(xAxisRotation) * cpp.y, (current.y + currentPoint.y) / 2.0 + Math.sin(xAxisRotation) * cpp.x + Math.cos(xAxisRotation) * cpp.y); // initial angle
3942
3943 var a1 = vectorsAngle([1, 0], [(currp.x - cpp.x) / rX, (currp.y - cpp.y) / rY]); // θ1
3944 // angle delta
3945
3946 var u = [(currp.x - cpp.x) / rX, (currp.y - cpp.y) / rY];
3947 var v = [(-currp.x - cpp.x) / rX, (-currp.y - cpp.y) / rY];
3948 var ad = vectorsAngle(u, v); // Δθ
3949
3950 if (vectorsRatio(u, v) <= -1) {
3951 ad = Math.PI;
3952 }
3953
3954 if (vectorsRatio(u, v) >= 1) {
3955 ad = 0;
3956 }
3957
3958 return {
3959 currentPoint: currentPoint,
3960 rX: rX,
3961 rY: rY,
3962 sweepFlag: sweepFlag,
3963 xAxisRotation: xAxisRotation,
3964 centp: centp,
3965 a1: a1,
3966 ad: ad
3967 };
3968 }
3969 }, {
3970 key: "pathZ",
3971 value: function pathZ(pathParser) {
3972 pathParser.current = pathParser.start;
3973 }
3974 }]);
3975
3976 return PathElement;
3977}(RenderedElement);
3978
3979function _createSuper$a(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$a(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
3980
3981function _isNativeReflectConstruct$a() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
3982
3983var SVGElement = /*#__PURE__*/function (_RenderedElement) {
3984 _inherits__default['default'](SVGElement, _RenderedElement);
3985
3986 var _super = _createSuper$a(SVGElement);
3987
3988 function SVGElement() {
3989 var _this;
3990
3991 _classCallCheck__default['default'](this, SVGElement);
3992
3993 _this = _super.apply(this, arguments);
3994 _this.type = 'svg';
3995 _this.root = false;
3996 return _this;
3997 }
3998
3999 _createClass__default['default'](SVGElement, [{
4000 key: "setContext",
4001 value: function setContext(ctx) {
4002 var document = this.document;
4003 var screen = document.screen,
4004 window = document.window;
4005 var canvas = ctx.canvas;
4006 screen.setDefaults(ctx);
4007
4008 if (canvas.style && typeof ctx.font !== 'undefined' && window && typeof window.getComputedStyle !== 'undefined') {
4009 ctx.font = window.getComputedStyle(canvas).getPropertyValue('font');
4010 var fontSizeProp = new Property(document, 'fontSize', Font.parse(ctx.font).fontSize);
4011
4012 if (fontSizeProp.hasValue()) {
4013 document.rootEmSize = fontSizeProp.getPixels('y');
4014 document.emSize = document.rootEmSize;
4015 }
4016 } // create new view port
4017
4018
4019 if (!this.getAttribute('x').hasValue()) {
4020 this.getAttribute('x', true).setValue(0);
4021 }
4022
4023 if (!this.getAttribute('y').hasValue()) {
4024 this.getAttribute('y', true).setValue(0);
4025 }
4026
4027 var _screen$viewPort = screen.viewPort,
4028 width = _screen$viewPort.width,
4029 height = _screen$viewPort.height;
4030
4031 if (!this.getStyle('width').hasValue()) {
4032 this.getStyle('width', true).setValue('100%');
4033 }
4034
4035 if (!this.getStyle('height').hasValue()) {
4036 this.getStyle('height', true).setValue('100%');
4037 }
4038
4039 if (!this.getStyle('color').hasValue()) {
4040 this.getStyle('color', true).setValue('black');
4041 }
4042
4043 var refXAttr = this.getAttribute('refX');
4044 var refYAttr = this.getAttribute('refY');
4045 var viewBoxAttr = this.getAttribute('viewBox');
4046 var viewBox = viewBoxAttr.hasValue() ? toNumbers(viewBoxAttr.getString()) : null;
4047 var clip = !this.root && this.getStyle('overflow').getValue('hidden') !== 'visible';
4048 var minX = 0;
4049 var minY = 0;
4050 var clipX = 0;
4051 var clipY = 0;
4052
4053 if (viewBox) {
4054 minX = viewBox[0];
4055 minY = viewBox[1];
4056 }
4057
4058 if (!this.root) {
4059 width = this.getStyle('width').getPixels('x');
4060 height = this.getStyle('height').getPixels('y');
4061
4062 if (this.type === 'marker') {
4063 clipX = minX;
4064 clipY = minY;
4065 minX = 0;
4066 minY = 0;
4067 }
4068 }
4069
4070 screen.viewPort.setCurrent(width, height);
4071
4072 if (this.node // is not temporary SVGElement
4073 && this.getStyle('transform', false, true).hasValue() && !this.getStyle('transform-origin', false, true).hasValue()) {
4074 this.getStyle('transform-origin', true, true).setValue('50% 50%');
4075 }
4076
4077 _get__default['default'](_getPrototypeOf__default['default'](SVGElement.prototype), "setContext", this).call(this, ctx);
4078
4079 ctx.translate(this.getAttribute('x').getPixels('x'), this.getAttribute('y').getPixels('y'));
4080
4081 if (viewBox) {
4082 width = viewBox[2];
4083 height = viewBox[3];
4084 }
4085
4086 document.setViewBox({
4087 ctx: ctx,
4088 aspectRatio: this.getAttribute('preserveAspectRatio').getString(),
4089 width: screen.viewPort.width,
4090 desiredWidth: width,
4091 height: screen.viewPort.height,
4092 desiredHeight: height,
4093 minX: minX,
4094 minY: minY,
4095 refX: refXAttr.getValue(),
4096 refY: refYAttr.getValue(),
4097 clip: clip,
4098 clipX: clipX,
4099 clipY: clipY
4100 });
4101
4102 if (viewBox) {
4103 screen.viewPort.removeCurrent();
4104 screen.viewPort.setCurrent(width, height);
4105 }
4106 }
4107 }, {
4108 key: "clearContext",
4109 value: function clearContext(ctx) {
4110 _get__default['default'](_getPrototypeOf__default['default'](SVGElement.prototype), "clearContext", this).call(this, ctx);
4111
4112 this.document.screen.viewPort.removeCurrent();
4113 }
4114 /**
4115 * Resize SVG to fit in given size.
4116 * @param width
4117 * @param height
4118 * @param preserveAspectRatio
4119 */
4120
4121 }, {
4122 key: "resize",
4123 value: function resize(width) {
4124 var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : width;
4125 var preserveAspectRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
4126 var widthAttr = this.getAttribute('width', true);
4127 var heightAttr = this.getAttribute('height', true);
4128 var viewBoxAttr = this.getAttribute('viewBox');
4129 var styleAttr = this.getAttribute('style');
4130 var originWidth = widthAttr.getNumber(0);
4131 var originHeight = heightAttr.getNumber(0);
4132
4133 if (preserveAspectRatio) {
4134 if (typeof preserveAspectRatio === 'string') {
4135 this.getAttribute('preserveAspectRatio', true).setValue(preserveAspectRatio);
4136 } else {
4137 var preserveAspectRatioAttr = this.getAttribute('preserveAspectRatio');
4138
4139 if (preserveAspectRatioAttr.hasValue()) {
4140 preserveAspectRatioAttr.setValue(preserveAspectRatioAttr.getString().replace(/^\s*(\S.*\S)\s*$/, '$1'));
4141 }
4142 }
4143 }
4144
4145 widthAttr.setValue(width);
4146 heightAttr.setValue(height);
4147
4148 if (!viewBoxAttr.hasValue()) {
4149 var _context;
4150
4151 viewBoxAttr.setValue(_concatInstanceProperty__default['default'](_context = "0 0 ".concat(originWidth || width, " ")).call(_context, originHeight || height));
4152 }
4153
4154 if (styleAttr.hasValue()) {
4155 var widthStyle = this.getStyle('width');
4156 var heightStyle = this.getStyle('height');
4157
4158 if (widthStyle.hasValue()) {
4159 widthStyle.setValue("".concat(width, "px"));
4160 }
4161
4162 if (heightStyle.hasValue()) {
4163 heightStyle.setValue("".concat(height, "px"));
4164 }
4165 }
4166 }
4167 }]);
4168
4169 return SVGElement;
4170}(RenderedElement);
4171
4172function _createSuper$b(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$b(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4173
4174function _isNativeReflectConstruct$b() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4175
4176var RectElement = /*#__PURE__*/function (_PathElement) {
4177 _inherits__default['default'](RectElement, _PathElement);
4178
4179 var _super = _createSuper$b(RectElement);
4180
4181 function RectElement() {
4182 var _this;
4183
4184 _classCallCheck__default['default'](this, RectElement);
4185
4186 _this = _super.apply(this, arguments);
4187 _this.type = 'rect';
4188 return _this;
4189 }
4190
4191 _createClass__default['default'](RectElement, [{
4192 key: "path",
4193 value: function path(ctx) {
4194 var x = this.getAttribute('x').getPixels('x');
4195 var y = this.getAttribute('y').getPixels('y');
4196 var width = this.getStyle('width', false, true).getPixels('x');
4197 var height = this.getStyle('height', false, true).getPixels('y');
4198 var rxAttr = this.getAttribute('rx');
4199 var ryAttr = this.getAttribute('ry');
4200 var rx = rxAttr.getPixels('x');
4201 var ry = ryAttr.getPixels('y');
4202
4203 if (rxAttr.hasValue() && !ryAttr.hasValue()) {
4204 ry = rx;
4205 }
4206
4207 if (ryAttr.hasValue() && !rxAttr.hasValue()) {
4208 rx = ry;
4209 }
4210
4211 rx = Math.min(rx, width / 2.0);
4212 ry = Math.min(ry, height / 2.0);
4213
4214 if (ctx) {
4215 var KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
4216 ctx.beginPath(); // always start the path so we don't fill prior paths
4217
4218 if (height > 0 && width > 0) {
4219 ctx.moveTo(x + rx, y);
4220 ctx.lineTo(x + width - rx, y);
4221 ctx.bezierCurveTo(x + width - rx + KAPPA * rx, y, x + width, y + ry - KAPPA * ry, x + width, y + ry);
4222 ctx.lineTo(x + width, y + height - ry);
4223 ctx.bezierCurveTo(x + width, y + height - ry + KAPPA * ry, x + width - rx + KAPPA * rx, y + height, x + width - rx, y + height);
4224 ctx.lineTo(x + rx, y + height);
4225 ctx.bezierCurveTo(x + rx - KAPPA * rx, y + height, x, y + height - ry + KAPPA * ry, x, y + height - ry);
4226 ctx.lineTo(x, y + ry);
4227 ctx.bezierCurveTo(x, y + ry - KAPPA * ry, x + rx - KAPPA * rx, y, x + rx, y);
4228 ctx.closePath();
4229 }
4230 }
4231
4232 return new BoundingBox(x, y, x + width, y + height);
4233 }
4234 }, {
4235 key: "getMarkers",
4236 value: function getMarkers() {
4237 return null;
4238 }
4239 }]);
4240
4241 return RectElement;
4242}(PathElement);
4243
4244function _createSuper$c(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$c(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4245
4246function _isNativeReflectConstruct$c() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4247
4248var CircleElement = /*#__PURE__*/function (_PathElement) {
4249 _inherits__default['default'](CircleElement, _PathElement);
4250
4251 var _super = _createSuper$c(CircleElement);
4252
4253 function CircleElement() {
4254 var _this;
4255
4256 _classCallCheck__default['default'](this, CircleElement);
4257
4258 _this = _super.apply(this, arguments);
4259 _this.type = 'circle';
4260 return _this;
4261 }
4262
4263 _createClass__default['default'](CircleElement, [{
4264 key: "path",
4265 value: function path(ctx) {
4266 var cx = this.getAttribute('cx').getPixels('x');
4267 var cy = this.getAttribute('cy').getPixels('y');
4268 var r = this.getAttribute('r').getPixels();
4269
4270 if (ctx && r > 0) {
4271 ctx.beginPath();
4272 ctx.arc(cx, cy, r, 0, Math.PI * 2, false);
4273 ctx.closePath();
4274 }
4275
4276 return new BoundingBox(cx - r, cy - r, cx + r, cy + r);
4277 }
4278 }, {
4279 key: "getMarkers",
4280 value: function getMarkers() {
4281 return null;
4282 }
4283 }]);
4284
4285 return CircleElement;
4286}(PathElement);
4287
4288function _createSuper$d(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$d(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4289
4290function _isNativeReflectConstruct$d() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4291
4292var EllipseElement = /*#__PURE__*/function (_PathElement) {
4293 _inherits__default['default'](EllipseElement, _PathElement);
4294
4295 var _super = _createSuper$d(EllipseElement);
4296
4297 function EllipseElement() {
4298 var _this;
4299
4300 _classCallCheck__default['default'](this, EllipseElement);
4301
4302 _this = _super.apply(this, arguments);
4303 _this.type = 'ellipse';
4304 return _this;
4305 }
4306
4307 _createClass__default['default'](EllipseElement, [{
4308 key: "path",
4309 value: function path(ctx) {
4310 var KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
4311 var rx = this.getAttribute('rx').getPixels('x');
4312 var ry = this.getAttribute('ry').getPixels('y');
4313 var cx = this.getAttribute('cx').getPixels('x');
4314 var cy = this.getAttribute('cy').getPixels('y');
4315
4316 if (ctx && rx > 0 && ry > 0) {
4317 ctx.beginPath();
4318 ctx.moveTo(cx + rx, cy);
4319 ctx.bezierCurveTo(cx + rx, cy + KAPPA * ry, cx + KAPPA * rx, cy + ry, cx, cy + ry);
4320 ctx.bezierCurveTo(cx - KAPPA * rx, cy + ry, cx - rx, cy + KAPPA * ry, cx - rx, cy);
4321 ctx.bezierCurveTo(cx - rx, cy - KAPPA * ry, cx - KAPPA * rx, cy - ry, cx, cy - ry);
4322 ctx.bezierCurveTo(cx + KAPPA * rx, cy - ry, cx + rx, cy - KAPPA * ry, cx + rx, cy);
4323 ctx.closePath();
4324 }
4325
4326 return new BoundingBox(cx - rx, cy - ry, cx + rx, cy + ry);
4327 }
4328 }, {
4329 key: "getMarkers",
4330 value: function getMarkers() {
4331 return null;
4332 }
4333 }]);
4334
4335 return EllipseElement;
4336}(PathElement);
4337
4338function _createSuper$e(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$e(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4339
4340function _isNativeReflectConstruct$e() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4341
4342var LineElement = /*#__PURE__*/function (_PathElement) {
4343 _inherits__default['default'](LineElement, _PathElement);
4344
4345 var _super = _createSuper$e(LineElement);
4346
4347 function LineElement() {
4348 var _this;
4349
4350 _classCallCheck__default['default'](this, LineElement);
4351
4352 _this = _super.apply(this, arguments);
4353 _this.type = 'line';
4354 return _this;
4355 }
4356
4357 _createClass__default['default'](LineElement, [{
4358 key: "getPoints",
4359 value: function getPoints() {
4360 return [new Point(this.getAttribute('x1').getPixels('x'), this.getAttribute('y1').getPixels('y')), new Point(this.getAttribute('x2').getPixels('x'), this.getAttribute('y2').getPixels('y'))];
4361 }
4362 }, {
4363 key: "path",
4364 value: function path(ctx) {
4365 var _this$getPoints = this.getPoints(),
4366 _this$getPoints2 = _slicedToArray__default['default'](_this$getPoints, 2),
4367 _this$getPoints2$ = _this$getPoints2[0],
4368 x0 = _this$getPoints2$.x,
4369 y0 = _this$getPoints2$.y,
4370 _this$getPoints2$2 = _this$getPoints2[1],
4371 x1 = _this$getPoints2$2.x,
4372 y1 = _this$getPoints2$2.y;
4373
4374 if (ctx) {
4375 ctx.beginPath();
4376 ctx.moveTo(x0, y0);
4377 ctx.lineTo(x1, y1);
4378 }
4379
4380 return new BoundingBox(x0, y0, x1, y1);
4381 }
4382 }, {
4383 key: "getMarkers",
4384 value: function getMarkers() {
4385 var _this$getPoints3 = this.getPoints(),
4386 _this$getPoints4 = _slicedToArray__default['default'](_this$getPoints3, 2),
4387 p0 = _this$getPoints4[0],
4388 p1 = _this$getPoints4[1];
4389
4390 var a = p0.angleTo(p1);
4391 return [[p0, a], [p1, a]];
4392 }
4393 }]);
4394
4395 return LineElement;
4396}(PathElement);
4397
4398function _createSuper$f(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$f(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4399
4400function _isNativeReflectConstruct$f() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4401
4402var PolylineElement = /*#__PURE__*/function (_PathElement) {
4403 _inherits__default['default'](PolylineElement, _PathElement);
4404
4405 var _super = _createSuper$f(PolylineElement);
4406
4407 function PolylineElement(document, node, captureTextNodes) {
4408 var _this;
4409
4410 _classCallCheck__default['default'](this, PolylineElement);
4411
4412 _this = _super.call(this, document, node, captureTextNodes);
4413 _this.type = 'polyline';
4414 _this.points = [];
4415 _this.points = Point.parsePath(_this.getAttribute('points').getString());
4416 return _this;
4417 }
4418
4419 _createClass__default['default'](PolylineElement, [{
4420 key: "path",
4421 value: function path(ctx) {
4422 var points = this.points;
4423
4424 var _points = _slicedToArray__default['default'](points, 1),
4425 _points$ = _points[0],
4426 x0 = _points$.x,
4427 y0 = _points$.y;
4428
4429 var boundingBox = new BoundingBox(x0, y0);
4430
4431 if (ctx) {
4432 ctx.beginPath();
4433 ctx.moveTo(x0, y0);
4434 }
4435
4436 _forEachInstanceProperty__default['default'](points).call(points, function (_ref) {
4437 var x = _ref.x,
4438 y = _ref.y;
4439 boundingBox.addPoint(x, y);
4440
4441 if (ctx) {
4442 ctx.lineTo(x, y);
4443 }
4444 });
4445
4446 return boundingBox;
4447 }
4448 }, {
4449 key: "getMarkers",
4450 value: function getMarkers() {
4451 var points = this.points;
4452 var lastIndex = points.length - 1;
4453 var markers = [];
4454
4455 _forEachInstanceProperty__default['default'](points).call(points, function (point, i) {
4456 if (i === lastIndex) {
4457 return;
4458 }
4459
4460 markers.push([point, point.angleTo(points[i + 1])]);
4461 });
4462
4463 if (markers.length > 0) {
4464 markers.push([points[points.length - 1], markers[markers.length - 1][1]]);
4465 }
4466
4467 return markers;
4468 }
4469 }]);
4470
4471 return PolylineElement;
4472}(PathElement);
4473
4474function _createSuper$g(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$g(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4475
4476function _isNativeReflectConstruct$g() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4477
4478var PolygonElement = /*#__PURE__*/function (_PolylineElement) {
4479 _inherits__default['default'](PolygonElement, _PolylineElement);
4480
4481 var _super = _createSuper$g(PolygonElement);
4482
4483 function PolygonElement() {
4484 var _this;
4485
4486 _classCallCheck__default['default'](this, PolygonElement);
4487
4488 _this = _super.apply(this, arguments);
4489 _this.type = 'polygon';
4490 return _this;
4491 }
4492
4493 _createClass__default['default'](PolygonElement, [{
4494 key: "path",
4495 value: function path(ctx) {
4496 var boundingBox = _get__default['default'](_getPrototypeOf__default['default'](PolygonElement.prototype), "path", this).call(this, ctx);
4497
4498 var _this$points = _slicedToArray__default['default'](this.points, 1),
4499 _this$points$ = _this$points[0],
4500 x = _this$points$.x,
4501 y = _this$points$.y;
4502
4503 if (ctx) {
4504 ctx.lineTo(x, y);
4505 ctx.closePath();
4506 }
4507
4508 return boundingBox;
4509 }
4510 }]);
4511
4512 return PolygonElement;
4513}(PolylineElement);
4514
4515function _createSuper$h(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$h(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4516
4517function _isNativeReflectConstruct$h() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4518
4519var PatternElement = /*#__PURE__*/function (_Element) {
4520 _inherits__default['default'](PatternElement, _Element);
4521
4522 var _super = _createSuper$h(PatternElement);
4523
4524 function PatternElement() {
4525 var _this;
4526
4527 _classCallCheck__default['default'](this, PatternElement);
4528
4529 _this = _super.apply(this, arguments);
4530 _this.type = 'pattern';
4531 return _this;
4532 }
4533
4534 _createClass__default['default'](PatternElement, [{
4535 key: "createPattern",
4536 value: function createPattern(ctx, _, parentOpacityProp) {
4537 var width = this.getStyle('width').getPixels('x', true);
4538 var height = this.getStyle('height').getPixels('y', true); // render me using a temporary svg element
4539
4540 var patternSvg = new SVGElement(this.document, null);
4541 patternSvg.attributes.viewBox = new Property(this.document, 'viewBox', this.getAttribute('viewBox').getValue());
4542 patternSvg.attributes.width = new Property(this.document, 'width', "".concat(width, "px"));
4543 patternSvg.attributes.height = new Property(this.document, 'height', "".concat(height, "px"));
4544 patternSvg.attributes.transform = new Property(this.document, 'transform', this.getAttribute('patternTransform').getValue());
4545 patternSvg.children = this.children;
4546 var patternCanvas = this.document.createCanvas(width, height);
4547 var patternCtx = patternCanvas.getContext('2d');
4548 var xAttr = this.getAttribute('x');
4549 var yAttr = this.getAttribute('y');
4550
4551 if (xAttr.hasValue() && yAttr.hasValue()) {
4552 patternCtx.translate(xAttr.getPixels('x', true), yAttr.getPixels('y', true));
4553 }
4554
4555 if (parentOpacityProp.hasValue()) {
4556 this.styles['fill-opacity'] = parentOpacityProp;
4557 } else {
4558 _Reflect$deleteProperty__default['default'](this.styles, 'fill-opacity');
4559 } // render 3x3 grid so when we transform there's no white space on edges
4560
4561
4562 for (var x = -1; x <= 1; x++) {
4563 for (var y = -1; y <= 1; y++) {
4564 patternCtx.save();
4565 patternSvg.attributes.x = new Property(this.document, 'x', x * patternCanvas.width);
4566 patternSvg.attributes.y = new Property(this.document, 'y', y * patternCanvas.height);
4567 patternSvg.render(patternCtx);
4568 patternCtx.restore();
4569 }
4570 }
4571
4572 var pattern = ctx.createPattern(patternCanvas, 'repeat');
4573 return pattern;
4574 }
4575 }]);
4576
4577 return PatternElement;
4578}(Element);
4579
4580function _createSuper$i(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$i(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4581
4582function _isNativeReflectConstruct$i() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4583
4584var MarkerElement = /*#__PURE__*/function (_Element) {
4585 _inherits__default['default'](MarkerElement, _Element);
4586
4587 var _super = _createSuper$i(MarkerElement);
4588
4589 function MarkerElement() {
4590 var _this;
4591
4592 _classCallCheck__default['default'](this, MarkerElement);
4593
4594 _this = _super.apply(this, arguments);
4595 _this.type = 'marker';
4596 return _this;
4597 }
4598
4599 _createClass__default['default'](MarkerElement, [{
4600 key: "render",
4601 value: function render(ctx, point, angle) {
4602 if (!point) {
4603 return;
4604 }
4605
4606 var x = point.x,
4607 y = point.y;
4608 var orient = this.getAttribute('orient').getValue('auto');
4609 var markerUnits = this.getAttribute('markerUnits').getValue('strokeWidth');
4610 ctx.translate(x, y);
4611
4612 if (orient === 'auto') {
4613 ctx.rotate(angle);
4614 }
4615
4616 if (markerUnits === 'strokeWidth') {
4617 ctx.scale(ctx.lineWidth, ctx.lineWidth);
4618 }
4619
4620 ctx.save(); // render me using a temporary svg element
4621
4622 var markerSvg = new SVGElement(this.document, null);
4623 markerSvg.type = this.type;
4624 markerSvg.attributes.viewBox = new Property(this.document, 'viewBox', this.getAttribute('viewBox').getValue());
4625 markerSvg.attributes.refX = new Property(this.document, 'refX', this.getAttribute('refX').getValue());
4626 markerSvg.attributes.refY = new Property(this.document, 'refY', this.getAttribute('refY').getValue());
4627 markerSvg.attributes.width = new Property(this.document, 'width', this.getAttribute('markerWidth').getValue());
4628 markerSvg.attributes.height = new Property(this.document, 'height', this.getAttribute('markerHeight').getValue());
4629 markerSvg.attributes.overflow = new Property(this.document, 'overflow', this.getAttribute('overflow').getValue());
4630 markerSvg.attributes.fill = new Property(this.document, 'fill', this.getAttribute('fill').getColor('black'));
4631 markerSvg.attributes.stroke = new Property(this.document, 'stroke', this.getAttribute('stroke').getValue('none'));
4632 markerSvg.children = this.children;
4633 markerSvg.render(ctx);
4634 ctx.restore();
4635
4636 if (markerUnits === 'strokeWidth') {
4637 ctx.scale(1 / ctx.lineWidth, 1 / ctx.lineWidth);
4638 }
4639
4640 if (orient === 'auto') {
4641 ctx.rotate(-angle);
4642 }
4643
4644 ctx.translate(-x, -y);
4645 }
4646 }]);
4647
4648 return MarkerElement;
4649}(Element);
4650
4651function _createSuper$j(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$j(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4652
4653function _isNativeReflectConstruct$j() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4654
4655var DefsElement = /*#__PURE__*/function (_Element) {
4656 _inherits__default['default'](DefsElement, _Element);
4657
4658 var _super = _createSuper$j(DefsElement);
4659
4660 function DefsElement() {
4661 var _this;
4662
4663 _classCallCheck__default['default'](this, DefsElement);
4664
4665 _this = _super.apply(this, arguments);
4666 _this.type = 'defs';
4667 return _this;
4668 }
4669
4670 _createClass__default['default'](DefsElement, [{
4671 key: "render",
4672 value: function render() {// NOOP
4673 }
4674 }]);
4675
4676 return DefsElement;
4677}(Element);
4678
4679function _createSuper$k(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$k(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4680
4681function _isNativeReflectConstruct$k() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4682
4683var GElement = /*#__PURE__*/function (_RenderedElement) {
4684 _inherits__default['default'](GElement, _RenderedElement);
4685
4686 var _super = _createSuper$k(GElement);
4687
4688 function GElement() {
4689 var _this;
4690
4691 _classCallCheck__default['default'](this, GElement);
4692
4693 _this = _super.apply(this, arguments);
4694 _this.type = 'g';
4695 return _this;
4696 }
4697
4698 _createClass__default['default'](GElement, [{
4699 key: "getBoundingBox",
4700 value: function getBoundingBox(ctx) {
4701 var _context;
4702
4703 var boundingBox = new BoundingBox();
4704
4705 _forEachInstanceProperty__default['default'](_context = this.children).call(_context, function (child) {
4706 boundingBox.addBoundingBox(child.getBoundingBox(ctx));
4707 });
4708
4709 return boundingBox;
4710 }
4711 }]);
4712
4713 return GElement;
4714}(RenderedElement);
4715
4716function _createSuper$l(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$l(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4717
4718function _isNativeReflectConstruct$l() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4719
4720var GradientElement = /*#__PURE__*/function (_Element) {
4721 _inherits__default['default'](GradientElement, _Element);
4722
4723 var _super = _createSuper$l(GradientElement);
4724
4725 function GradientElement(document, node, captureTextNodes) {
4726 var _this;
4727
4728 _classCallCheck__default['default'](this, GradientElement);
4729
4730 _this = _super.call(this, document, node, captureTextNodes);
4731 _this.attributesToInherit = ['gradientUnits'];
4732 _this.stops = [];
4733
4734 var _assertThisInitialize = _assertThisInitialized__default['default'](_this),
4735 stops = _assertThisInitialize.stops,
4736 children = _assertThisInitialize.children;
4737
4738 _forEachInstanceProperty__default['default'](children).call(children, function (child) {
4739 if (child.type === 'stop') {
4740 stops.push(child);
4741 }
4742 });
4743
4744 return _this;
4745 }
4746
4747 _createClass__default['default'](GradientElement, [{
4748 key: "getGradientUnits",
4749 value: function getGradientUnits() {
4750 return this.getAttribute('gradientUnits').getString('objectBoundingBox');
4751 }
4752 }, {
4753 key: "createGradient",
4754 value: function createGradient(ctx, element, parentOpacityProp) {
4755 var _this2 = this;
4756
4757 // tslint:disable-next-line: no-this-assignment
4758 var stopsContainer = this;
4759
4760 if (this.getHrefAttribute().hasValue()) {
4761 stopsContainer = this.getHrefAttribute().getDefinition();
4762 this.inheritStopContainer(stopsContainer);
4763 }
4764
4765 var _stopsContainer = stopsContainer,
4766 stops = _stopsContainer.stops;
4767 var gradient = this.getGradient(ctx, element);
4768
4769 if (!gradient) {
4770 return this.addParentOpacity(parentOpacityProp, stops[stops.length - 1].color);
4771 }
4772
4773 _forEachInstanceProperty__default['default'](stops).call(stops, function (stop) {
4774 gradient.addColorStop(stop.offset, _this2.addParentOpacity(parentOpacityProp, stop.color));
4775 });
4776
4777 if (this.getAttribute('gradientTransform').hasValue()) {
4778 // render as transformed pattern on temporary canvas
4779 var document = this.document;
4780 var _document$screen = document.screen,
4781 MAX_VIRTUAL_PIXELS = _document$screen.MAX_VIRTUAL_PIXELS,
4782 viewPort = _document$screen.viewPort;
4783
4784 var _viewPort$viewPorts = _slicedToArray__default['default'](viewPort.viewPorts, 1),
4785 rootView = _viewPort$viewPorts[0];
4786
4787 var rect = new RectElement(document, null);
4788 rect.attributes.x = new Property(document, 'x', -MAX_VIRTUAL_PIXELS / 3.0);
4789 rect.attributes.y = new Property(document, 'y', -MAX_VIRTUAL_PIXELS / 3.0);
4790 rect.attributes.width = new Property(document, 'width', MAX_VIRTUAL_PIXELS);
4791 rect.attributes.height = new Property(document, 'height', MAX_VIRTUAL_PIXELS);
4792 var group = new GElement(document, null);
4793 group.attributes.transform = new Property(document, 'transform', this.getAttribute('gradientTransform').getValue());
4794 group.children = [rect];
4795 var patternSvg = new SVGElement(document, null);
4796 patternSvg.attributes.x = new Property(document, 'x', 0);
4797 patternSvg.attributes.y = new Property(document, 'y', 0);
4798 patternSvg.attributes.width = new Property(document, 'width', rootView.width);
4799 patternSvg.attributes.height = new Property(document, 'height', rootView.height);
4800 patternSvg.children = [group];
4801 var patternCanvas = document.createCanvas(rootView.width, rootView.height);
4802 var patternCtx = patternCanvas.getContext('2d');
4803 patternCtx.fillStyle = gradient;
4804 patternSvg.render(patternCtx);
4805 return patternCtx.createPattern(patternCanvas, 'no-repeat');
4806 }
4807
4808 return gradient;
4809 }
4810 }, {
4811 key: "inheritStopContainer",
4812 value: function inheritStopContainer(stopsContainer) {
4813 var _context,
4814 _this3 = this;
4815
4816 _forEachInstanceProperty__default['default'](_context = this.attributesToInherit).call(_context, function (attributeToInherit) {
4817 if (!_this3.getAttribute(attributeToInherit).hasValue() && stopsContainer.getAttribute(attributeToInherit).hasValue()) {
4818 _this3.getAttribute(attributeToInherit, true).setValue(stopsContainer.getAttribute(attributeToInherit).getValue());
4819 }
4820 });
4821 }
4822 }, {
4823 key: "addParentOpacity",
4824 value: function addParentOpacity(parentOpacityProp, color) {
4825 if (parentOpacityProp.hasValue()) {
4826 var colorProp = new Property(this.document, 'color', color);
4827 return colorProp.addOpacity(parentOpacityProp).getColor();
4828 }
4829
4830 return color;
4831 }
4832 }]);
4833
4834 return GradientElement;
4835}(Element);
4836
4837function _createSuper$m(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$m(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4838
4839function _isNativeReflectConstruct$m() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4840
4841var LinearGradientElement = /*#__PURE__*/function (_GradientElement) {
4842 _inherits__default['default'](LinearGradientElement, _GradientElement);
4843
4844 var _super = _createSuper$m(LinearGradientElement);
4845
4846 function LinearGradientElement(document, node, captureTextNodes) {
4847 var _this;
4848
4849 _classCallCheck__default['default'](this, LinearGradientElement);
4850
4851 _this = _super.call(this, document, node, captureTextNodes);
4852 _this.type = 'linearGradient';
4853
4854 _this.attributesToInherit.push('x1', 'y1', 'x2', 'y2');
4855
4856 return _this;
4857 }
4858
4859 _createClass__default['default'](LinearGradientElement, [{
4860 key: "getGradient",
4861 value: function getGradient(ctx, element) {
4862 var isBoundingBoxUnits = this.getGradientUnits() === 'objectBoundingBox';
4863 var boundingBox = isBoundingBoxUnits ? element.getBoundingBox(ctx) : null;
4864
4865 if (isBoundingBoxUnits && !boundingBox) {
4866 return null;
4867 }
4868
4869 if (!this.getAttribute('x1').hasValue() && !this.getAttribute('y1').hasValue() && !this.getAttribute('x2').hasValue() && !this.getAttribute('y2').hasValue()) {
4870 this.getAttribute('x1', true).setValue(0);
4871 this.getAttribute('y1', true).setValue(0);
4872 this.getAttribute('x2', true).setValue(1);
4873 this.getAttribute('y2', true).setValue(0);
4874 }
4875
4876 var x1 = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute('x1').getNumber() : this.getAttribute('x1').getPixels('x');
4877 var y1 = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute('y1').getNumber() : this.getAttribute('y1').getPixels('y');
4878 var x2 = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute('x2').getNumber() : this.getAttribute('x2').getPixels('x');
4879 var y2 = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute('y2').getNumber() : this.getAttribute('y2').getPixels('y');
4880
4881 if (x1 === x2 && y1 === y2) {
4882 return null;
4883 }
4884
4885 return ctx.createLinearGradient(x1, y1, x2, y2);
4886 }
4887 }]);
4888
4889 return LinearGradientElement;
4890}(GradientElement);
4891
4892function _createSuper$n(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$n(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4893
4894function _isNativeReflectConstruct$n() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4895
4896var RadialGradientElement = /*#__PURE__*/function (_GradientElement) {
4897 _inherits__default['default'](RadialGradientElement, _GradientElement);
4898
4899 var _super = _createSuper$n(RadialGradientElement);
4900
4901 function RadialGradientElement(document, node, captureTextNodes) {
4902 var _this;
4903
4904 _classCallCheck__default['default'](this, RadialGradientElement);
4905
4906 _this = _super.call(this, document, node, captureTextNodes);
4907 _this.type = 'radialGradient';
4908
4909 _this.attributesToInherit.push('cx', 'cy', 'r', 'fx', 'fy', 'fr');
4910
4911 return _this;
4912 }
4913
4914 _createClass__default['default'](RadialGradientElement, [{
4915 key: "getGradient",
4916 value: function getGradient(ctx, element) {
4917 var isBoundingBoxUnits = this.getGradientUnits() === 'objectBoundingBox';
4918 var boundingBox = element.getBoundingBox(ctx);
4919
4920 if (isBoundingBoxUnits && !boundingBox) {
4921 return null;
4922 }
4923
4924 if (!this.getAttribute('cx').hasValue()) {
4925 this.getAttribute('cx', true).setValue('50%');
4926 }
4927
4928 if (!this.getAttribute('cy').hasValue()) {
4929 this.getAttribute('cy', true).setValue('50%');
4930 }
4931
4932 if (!this.getAttribute('r').hasValue()) {
4933 this.getAttribute('r', true).setValue('50%');
4934 }
4935
4936 var cx = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute('cx').getNumber() : this.getAttribute('cx').getPixels('x');
4937 var cy = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute('cy').getNumber() : this.getAttribute('cy').getPixels('y');
4938 var fx = cx;
4939 var fy = cy;
4940
4941 if (this.getAttribute('fx').hasValue()) {
4942 fx = isBoundingBoxUnits ? boundingBox.x + boundingBox.width * this.getAttribute('fx').getNumber() : this.getAttribute('fx').getPixels('x');
4943 }
4944
4945 if (this.getAttribute('fy').hasValue()) {
4946 fy = isBoundingBoxUnits ? boundingBox.y + boundingBox.height * this.getAttribute('fy').getNumber() : this.getAttribute('fy').getPixels('y');
4947 }
4948
4949 var r = isBoundingBoxUnits ? (boundingBox.width + boundingBox.height) / 2.0 * this.getAttribute('r').getNumber() : this.getAttribute('r').getPixels();
4950 var fr = this.getAttribute('fr').getPixels();
4951 return ctx.createRadialGradient(fx, fy, fr, cx, cy, r);
4952 }
4953 }]);
4954
4955 return RadialGradientElement;
4956}(GradientElement);
4957
4958function _createSuper$o(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$o(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4959
4960function _isNativeReflectConstruct$o() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4961
4962var StopElement = /*#__PURE__*/function (_Element) {
4963 _inherits__default['default'](StopElement, _Element);
4964
4965 var _super = _createSuper$o(StopElement);
4966
4967 function StopElement(document, node, captureTextNodes) {
4968 var _this;
4969
4970 _classCallCheck__default['default'](this, StopElement);
4971
4972 _this = _super.call(this, document, node, captureTextNodes);
4973 _this.type = 'stop';
4974 var offset = Math.max(0, Math.min(1, _this.getAttribute('offset').getNumber()));
4975
4976 var stopOpacity = _this.getStyle('stop-opacity');
4977
4978 var stopColor = _this.getStyle('stop-color', true);
4979
4980 if (stopColor.getString() === '') {
4981 stopColor.setValue('#000');
4982 }
4983
4984 if (stopOpacity.hasValue()) {
4985 stopColor = stopColor.addOpacity(stopOpacity);
4986 }
4987
4988 _this.offset = offset;
4989 _this.color = stopColor.getColor();
4990 return _this;
4991 }
4992
4993 return StopElement;
4994}(Element);
4995
4996function _createSuper$p(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$p(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
4997
4998function _isNativeReflectConstruct$p() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
4999
5000var AnimateElement = /*#__PURE__*/function (_Element) {
5001 _inherits__default['default'](AnimateElement, _Element);
5002
5003 var _super = _createSuper$p(AnimateElement);
5004
5005 function AnimateElement(document, node, captureTextNodes) {
5006 var _this;
5007
5008 _classCallCheck__default['default'](this, AnimateElement);
5009
5010 _this = _super.call(this, document, node, captureTextNodes);
5011 _this.type = 'animate';
5012 _this.duration = 0;
5013 _this.initialValue = null;
5014 _this.initialUnits = '';
5015 _this.removed = false;
5016 _this.frozen = false;
5017 document.screen.animations.push(_assertThisInitialized__default['default'](_this));
5018 _this.begin = _this.getAttribute('begin').getMilliseconds();
5019 _this.maxDuration = _this.begin + _this.getAttribute('dur').getMilliseconds();
5020 _this.from = _this.getAttribute('from');
5021 _this.to = _this.getAttribute('to');
5022 _this.values = _this.getAttribute('values');
5023
5024 if (_valuesInstanceProperty__default['default'](_this).hasValue()) {
5025 _valuesInstanceProperty__default['default'](_this).setValue(_valuesInstanceProperty__default['default'](_this).getString().split(';'));
5026 }
5027
5028 return _this;
5029 }
5030
5031 _createClass__default['default'](AnimateElement, [{
5032 key: "getProperty",
5033 value: function getProperty() {
5034 var attributeType = this.getAttribute('attributeType').getString();
5035 var attributeName = this.getAttribute('attributeName').getString();
5036
5037 if (attributeType === 'CSS') {
5038 return this.parent.getStyle(attributeName, true);
5039 }
5040
5041 return this.parent.getAttribute(attributeName, true);
5042 }
5043 }, {
5044 key: "calcValue",
5045 value: function calcValue() {
5046 var _context;
5047
5048 var initialUnits = this.initialUnits;
5049
5050 var _this$getProgress = this.getProgress(),
5051 progress = _this$getProgress.progress,
5052 from = _this$getProgress.from,
5053 to = _this$getProgress.to; // tween value linearly
5054
5055
5056 var newValue = from.getNumber() + (to.getNumber() - from.getNumber()) * progress;
5057
5058 if (initialUnits === '%') {
5059 newValue *= 100.0; // numValue() returns 0-1 whereas properties are 0-100
5060 }
5061
5062 return _concatInstanceProperty__default['default'](_context = "".concat(newValue)).call(_context, initialUnits);
5063 }
5064 }, {
5065 key: "update",
5066 value: function update(delta) {
5067 var parent = this.parent;
5068 var prop = this.getProperty(); // set initial value
5069
5070 if (!this.initialValue) {
5071 this.initialValue = prop.getString();
5072 this.initialUnits = prop.getUnits();
5073 } // if we're past the end time
5074
5075
5076 if (this.duration > this.maxDuration) {
5077 var fill = this.getAttribute('fill').getString('remove'); // loop for indefinitely repeating animations
5078
5079 if (this.getAttribute('repeatCount').getString() === 'indefinite' || this.getAttribute('repeatDur').getString() === 'indefinite') {
5080 this.duration = 0;
5081 } else if (fill === 'freeze' && !this.frozen) {
5082 this.frozen = true;
5083 parent.animationFrozen = true;
5084 parent.animationFrozenValue = prop.getString();
5085 } else if (fill === 'remove' && !this.removed) {
5086 this.removed = true;
5087 prop.setValue(parent.animationFrozen ? parent.animationFrozenValue : this.initialValue);
5088 return true;
5089 }
5090
5091 return false;
5092 }
5093
5094 this.duration += delta; // if we're past the begin time
5095
5096 var updated = false;
5097
5098 if (this.begin < this.duration) {
5099 var newValue = this.calcValue(); // tween
5100
5101 var typeAttr = this.getAttribute('type');
5102
5103 if (typeAttr.hasValue()) {
5104 var _context2;
5105
5106 // for transform, etc.
5107 var type = typeAttr.getString();
5108 newValue = _concatInstanceProperty__default['default'](_context2 = "".concat(type, "(")).call(_context2, newValue, ")");
5109 }
5110
5111 prop.setValue(newValue);
5112 updated = true;
5113 }
5114
5115 return updated;
5116 }
5117 }, {
5118 key: "getProgress",
5119 value: function getProgress() {
5120 var document = this.document,
5121 values = _valuesInstanceProperty__default['default'](this);
5122
5123 var result = {
5124 progress: (this.duration - this.begin) / (this.maxDuration - this.begin)
5125 };
5126
5127 if (values.hasValue()) {
5128 var p = result.progress * (values.getValue().length - 1);
5129 var lb = Math.floor(p);
5130 var ub = Math.ceil(p);
5131 result.from = new Property(document, 'from', _parseFloat__default['default'](values.getValue()[lb]));
5132 result.to = new Property(document, 'to', _parseFloat__default['default'](values.getValue()[ub]));
5133 result.progress = (p - lb) / (ub - lb);
5134 } else {
5135 result.from = this.from;
5136 result.to = this.to;
5137 }
5138
5139 return result;
5140 }
5141 }]);
5142
5143 return AnimateElement;
5144}(Element);
5145
5146function _createSuper$q(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$q(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5147
5148function _isNativeReflectConstruct$q() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5149
5150var AnimateColorElement = /*#__PURE__*/function (_AnimateElement) {
5151 _inherits__default['default'](AnimateColorElement, _AnimateElement);
5152
5153 var _super = _createSuper$q(AnimateColorElement);
5154
5155 function AnimateColorElement() {
5156 var _this;
5157
5158 _classCallCheck__default['default'](this, AnimateColorElement);
5159
5160 _this = _super.apply(this, arguments);
5161 _this.type = 'animateColor';
5162 return _this;
5163 }
5164
5165 _createClass__default['default'](AnimateColorElement, [{
5166 key: "calcValue",
5167 value: function calcValue() {
5168 var _this$getProgress = this.getProgress(),
5169 progress = _this$getProgress.progress,
5170 from = _this$getProgress.from,
5171 to = _this$getProgress.to;
5172
5173 var colorFrom = new RGBColor__default['default'](from.getColor());
5174 var colorTo = new RGBColor__default['default'](to.getColor());
5175
5176 if (colorFrom.ok && colorTo.ok) {
5177 var _context, _context2;
5178
5179 // tween color linearly
5180 var r = colorFrom.r + (colorTo.r - colorFrom.r) * progress;
5181 var g = colorFrom.g + (colorTo.g - colorFrom.g) * progress;
5182 var b = colorFrom.b + (colorTo.b - colorFrom.b) * progress; // ? alpha
5183
5184 return _concatInstanceProperty__default['default'](_context = _concatInstanceProperty__default['default'](_context2 = "rgb(".concat(_parseInt__default['default'](r, 10), ", ")).call(_context2, _parseInt__default['default'](g, 10), ", ")).call(_context, _parseInt__default['default'](b, 10), ")");
5185 }
5186
5187 return this.getAttribute('from').getColor();
5188 }
5189 }]);
5190
5191 return AnimateColorElement;
5192}(AnimateElement);
5193
5194function _createSuper$r(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$r(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5195
5196function _isNativeReflectConstruct$r() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5197
5198var AnimateTransformElement = /*#__PURE__*/function (_AnimateElement) {
5199 _inherits__default['default'](AnimateTransformElement, _AnimateElement);
5200
5201 var _super = _createSuper$r(AnimateTransformElement);
5202
5203 function AnimateTransformElement() {
5204 var _this;
5205
5206 _classCallCheck__default['default'](this, AnimateTransformElement);
5207
5208 _this = _super.apply(this, arguments);
5209 _this.type = 'animateTransform';
5210 return _this;
5211 }
5212
5213 _createClass__default['default'](AnimateTransformElement, [{
5214 key: "calcValue",
5215 value: function calcValue() {
5216 var _this$getProgress = this.getProgress(),
5217 progress = _this$getProgress.progress,
5218 from = _this$getProgress.from,
5219 to = _this$getProgress.to; // tween value linearly
5220
5221
5222 var transformFrom = toNumbers(from.getString());
5223 var transformTo = toNumbers(to.getString());
5224
5225 var newValue = _mapInstanceProperty__default['default'](transformFrom).call(transformFrom, function (from, i) {
5226 var to = transformTo[i];
5227 return from + (to - from) * progress;
5228 }).join(' ');
5229
5230 return newValue;
5231 }
5232 }]);
5233
5234 return AnimateTransformElement;
5235}(AnimateElement);
5236
5237function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof _Symbol__default['default'] === "undefined" || _getIteratorMethod__default['default'](o) == null) { if (_Array$isArray__default['default'](o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = _getIterator__default['default'](o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5238
5239function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty__default['default'](_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from__default['default'](o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5240
5241function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5242
5243function _createSuper$s(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$s(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5244
5245function _isNativeReflectConstruct$s() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5246
5247var FontElement = /*#__PURE__*/function (_Element) {
5248 _inherits__default['default'](FontElement, _Element);
5249
5250 var _super = _createSuper$s(FontElement);
5251
5252 function FontElement(document, node, captureTextNodes) {
5253 var _this;
5254
5255 _classCallCheck__default['default'](this, FontElement);
5256
5257 _this = _super.call(this, document, node, captureTextNodes);
5258 _this.type = 'font';
5259 _this.glyphs = {};
5260 _this.horizAdvX = _this.getAttribute('horiz-adv-x').getNumber();
5261 var definitions = document.definitions;
5262
5263 var _assertThisInitialize = _assertThisInitialized__default['default'](_this),
5264 children = _assertThisInitialize.children;
5265
5266 var _iterator = _createForOfIteratorHelper(children),
5267 _step;
5268
5269 try {
5270 for (_iterator.s(); !(_step = _iterator.n()).done;) {
5271 var child = _step.value;
5272
5273 switch (child.type) {
5274 case 'font-face':
5275 {
5276 _this.fontFace = child;
5277 var fontFamilyStyle = child.getStyle('font-family');
5278
5279 if (fontFamilyStyle.hasValue()) {
5280 definitions[fontFamilyStyle.getString()] = _assertThisInitialized__default['default'](_this);
5281 }
5282
5283 break;
5284 }
5285
5286 case 'missing-glyph':
5287 _this.missingGlyph = child;
5288 break;
5289
5290 case 'glyph':
5291 {
5292 var glyph = child;
5293
5294 if (glyph.arabicForm) {
5295 _this.isRTL = true;
5296 _this.isArabic = true;
5297
5298 if (typeof _this.glyphs[glyph.unicode] === 'undefined') {
5299 _this.glyphs[glyph.unicode] = {};
5300 }
5301
5302 _this.glyphs[glyph.unicode][glyph.arabicForm] = glyph;
5303 } else {
5304 _this.glyphs[glyph.unicode] = glyph;
5305 }
5306
5307 break;
5308 }
5309
5310 default:
5311 }
5312 }
5313 } catch (err) {
5314 _iterator.e(err);
5315 } finally {
5316 _iterator.f();
5317 }
5318
5319 return _this;
5320 }
5321
5322 _createClass__default['default'](FontElement, [{
5323 key: "render",
5324 value: function render() {// NO RENDER
5325 }
5326 }]);
5327
5328 return FontElement;
5329}(Element);
5330
5331function _createSuper$t(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$t(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5332
5333function _isNativeReflectConstruct$t() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5334
5335var FontFaceElement = /*#__PURE__*/function (_Element) {
5336 _inherits__default['default'](FontFaceElement, _Element);
5337
5338 var _super = _createSuper$t(FontFaceElement);
5339
5340 function FontFaceElement(document, node, captureTextNodes) {
5341 var _this;
5342
5343 _classCallCheck__default['default'](this, FontFaceElement);
5344
5345 _this = _super.call(this, document, node, captureTextNodes);
5346 _this.type = 'font-face';
5347 _this.ascent = _this.getAttribute('ascent').getNumber();
5348 _this.descent = _this.getAttribute('descent').getNumber();
5349 _this.unitsPerEm = _this.getAttribute('units-per-em').getNumber();
5350 return _this;
5351 }
5352
5353 return FontFaceElement;
5354}(Element);
5355
5356function _createSuper$u(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$u(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5357
5358function _isNativeReflectConstruct$u() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5359
5360var MissingGlyphElement = /*#__PURE__*/function (_PathElement) {
5361 _inherits__default['default'](MissingGlyphElement, _PathElement);
5362
5363 var _super = _createSuper$u(MissingGlyphElement);
5364
5365 function MissingGlyphElement() {
5366 var _this;
5367
5368 _classCallCheck__default['default'](this, MissingGlyphElement);
5369
5370 _this = _super.apply(this, arguments);
5371 _this.type = 'missing-glyph';
5372 _this.horizAdvX = 0;
5373 return _this;
5374 }
5375
5376 return MissingGlyphElement;
5377}(PathElement);
5378
5379function _createSuper$v(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$v(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5380
5381function _isNativeReflectConstruct$v() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5382
5383var GlyphElement = /*#__PURE__*/function (_PathElement) {
5384 _inherits__default['default'](GlyphElement, _PathElement);
5385
5386 var _super = _createSuper$v(GlyphElement);
5387
5388 function GlyphElement(document, node, captureTextNodes) {
5389 var _this;
5390
5391 _classCallCheck__default['default'](this, GlyphElement);
5392
5393 _this = _super.call(this, document, node, captureTextNodes);
5394 _this.type = 'glyph';
5395 _this.horizAdvX = _this.getAttribute('horiz-adv-x').getNumber();
5396 _this.unicode = _this.getAttribute('unicode').getString();
5397 _this.arabicForm = _this.getAttribute('arabic-form').getString();
5398 return _this;
5399 }
5400
5401 return GlyphElement;
5402}(PathElement);
5403
5404function _createSuper$w(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$w(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5405
5406function _isNativeReflectConstruct$w() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5407
5408var TRefElement = /*#__PURE__*/function (_TextElement) {
5409 _inherits__default['default'](TRefElement, _TextElement);
5410
5411 var _super = _createSuper$w(TRefElement);
5412
5413 function TRefElement() {
5414 var _this;
5415
5416 _classCallCheck__default['default'](this, TRefElement);
5417
5418 _this = _super.apply(this, arguments);
5419 _this.type = 'tref';
5420 return _this;
5421 }
5422
5423 _createClass__default['default'](TRefElement, [{
5424 key: "getText",
5425 value: function getText() {
5426 var element = this.getHrefAttribute().getDefinition();
5427
5428 if (element) {
5429 var firstChild = element.children[0];
5430
5431 if (firstChild) {
5432 return firstChild.getText();
5433 }
5434 }
5435
5436 return '';
5437 }
5438 }]);
5439
5440 return TRefElement;
5441}(TextElement);
5442
5443function _createSuper$x(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$x(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5444
5445function _isNativeReflectConstruct$x() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5446
5447var AElement = /*#__PURE__*/function (_TextElement) {
5448 _inherits__default['default'](AElement, _TextElement);
5449
5450 var _super = _createSuper$x(AElement);
5451
5452 function AElement(document, node, captureTextNodes) {
5453 var _context;
5454
5455 var _this;
5456
5457 _classCallCheck__default['default'](this, AElement);
5458
5459 _this = _super.call(this, document, node, captureTextNodes);
5460 _this.type = 'a';
5461 var childNodes = node.childNodes;
5462 var firstChild = childNodes[0];
5463
5464 var hasText = childNodes.length > 0 && _everyInstanceProperty__default['default'](_context = _Array$from__default['default'](childNodes)).call(_context, function (node) {
5465 return node.nodeType === 3;
5466 });
5467
5468 _this.hasText = hasText;
5469 _this.text = hasText ? _this.getTextFromNode(firstChild) : '';
5470 return _this;
5471 }
5472
5473 _createClass__default['default'](AElement, [{
5474 key: "getText",
5475 value: function getText() {
5476 return this.text;
5477 }
5478 }, {
5479 key: "renderChildren",
5480 value: function renderChildren(ctx) {
5481 if (this.hasText) {
5482 // render as text element
5483 _get__default['default'](_getPrototypeOf__default['default'](AElement.prototype), "renderChildren", this).call(this, ctx);
5484
5485 var document = this.document,
5486 x = this.x,
5487 y = this.y;
5488 var mouse = document.screen.mouse;
5489 var fontSize = new Property(document, 'fontSize', Font.parse(document.ctx.font).fontSize); // Do not calc bounding box if mouse is not working.
5490
5491 if (mouse.isWorking()) {
5492 mouse.checkBoundingBox(this, new BoundingBox(x, y - fontSize.getPixels('y'), x + this.measureText(ctx), y));
5493 }
5494 } else if (this.children.length > 0) {
5495 // render as temporary group
5496 var g = new GElement(this.document, null);
5497 g.children = this.children;
5498 g.parent = this;
5499 g.render(ctx);
5500 }
5501 }
5502 }, {
5503 key: "onClick",
5504 value: function onClick() {
5505 var window = this.document.window;
5506
5507 if (window) {
5508 window.open(this.getHrefAttribute().getString());
5509 }
5510 }
5511 }, {
5512 key: "onMouseMove",
5513 value: function onMouseMove() {
5514 var ctx = this.document.ctx;
5515 ctx.canvas.style.cursor = 'pointer';
5516 }
5517 }]);
5518
5519 return AElement;
5520}(TextElement);
5521
5522function _createForOfIteratorHelper$1(o, allowArrayLike) { var it; if (typeof _Symbol__default['default'] === "undefined" || _getIteratorMethod__default['default'](o) == null) { if (_Array$isArray__default['default'](o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = _getIterator__default['default'](o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5523
5524function _unsupportedIterableToArray$1(o, minLen) { var _context5; if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = _sliceInstanceProperty__default['default'](_context5 = Object.prototype.toString.call(o)).call(_context5, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from__default['default'](o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
5525
5526function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5527
5528function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
5529
5530function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default['default'](_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
5531
5532function _createSuper$y(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$y(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
5533
5534function _isNativeReflectConstruct$y() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
5535
5536var TextPathElement = /*#__PURE__*/function (_TextElement) {
5537 _inherits__default['default'](TextPathElement, _TextElement);
5538
5539 var _super = _createSuper$y(TextPathElement);
5540
5541 function TextPathElement(document, node, captureTextNodes) {
5542 var _this;
5543
5544 _classCallCheck__default['default'](this, TextPathElement);
5545
5546 _this = _super.call(this, document, node, captureTextNodes);
5547 _this.type = 'textPath';
5548 _this.textWidth = 0;
5549 _this.textHeight = 0;
5550 _this.pathLength = -1;
5551 _this.glyphInfo = null;
5552 _this.letterSpacingCache = [];
5553 _this.measuresCache = new _Map__default['default']([['', 0]]);
5554
5555 var pathElement = _this.getHrefAttribute().getDefinition();
5556
5557 _this.text = _this.getTextFromNode();
5558 _this.dataArray = _this.parsePathData(pathElement);
5559 return _this;
5560 }
5561
5562 _createClass__default['default'](TextPathElement, [{
5563 key: "getText",
5564 value: function getText() {
5565 return this.text;
5566 }
5567 }, {
5568 key: "path",
5569 value: function path(ctx) {
5570 var dataArray = this.dataArray;
5571
5572 if (ctx) {
5573 ctx.beginPath();
5574 }
5575
5576 _forEachInstanceProperty__default['default'](dataArray).call(dataArray, function (_ref) {
5577 var type = _ref.type,
5578 points = _ref.points;
5579
5580 switch (type) {
5581 case PathParser.LINE_TO:
5582 if (ctx) {
5583 ctx.lineTo(points[0], points[1]);
5584 }
5585
5586 break;
5587
5588 case PathParser.MOVE_TO:
5589 if (ctx) {
5590 ctx.moveTo(points[0], points[1]);
5591 }
5592
5593 break;
5594
5595 case PathParser.CURVE_TO:
5596 if (ctx) {
5597 ctx.bezierCurveTo(points[0], points[1], points[2], points[3], points[4], points[5]);
5598 }
5599
5600 break;
5601
5602 case PathParser.QUAD_TO:
5603 if (ctx) {
5604 ctx.quadraticCurveTo(points[0], points[1], points[2], points[3]);
5605 }
5606
5607 break;
5608
5609 case PathParser.ARC:
5610 {
5611 var _points = _slicedToArray__default['default'](points, 8),
5612 cx = _points[0],
5613 cy = _points[1],
5614 rx = _points[2],
5615 ry = _points[3],
5616 theta = _points[4],
5617 dTheta = _points[5],
5618 psi = _points[6],
5619 fs = _points[7];
5620
5621 var r = rx > ry ? rx : ry;
5622 var scaleX = rx > ry ? 1 : rx / ry;
5623 var scaleY = rx > ry ? ry / rx : 1;
5624
5625 if (ctx) {
5626 ctx.translate(cx, cy);
5627 ctx.rotate(psi);
5628 ctx.scale(scaleX, scaleY);
5629 ctx.arc(0, 0, r, theta, theta + dTheta, Boolean(1 - fs));
5630 ctx.scale(1 / scaleX, 1 / scaleY);
5631 ctx.rotate(-psi);
5632 ctx.translate(-cx, -cy);
5633 }
5634
5635 break;
5636 }
5637
5638 case PathParser.CLOSE_PATH:
5639 if (ctx) {
5640 ctx.closePath();
5641 }
5642
5643 break;
5644 }
5645 });
5646 }
5647 }, {
5648 key: "renderChildren",
5649 value: function renderChildren(ctx) {
5650 this.setTextData(ctx);
5651 ctx.save();
5652 var textDecoration = this.parent.getStyle('text-decoration').getString();
5653 var fontSize = this.getFontSize();
5654 var glyphInfo = this.glyphInfo;
5655 var fill = ctx.fillStyle;
5656
5657 if (textDecoration === 'underline') {
5658 ctx.beginPath();
5659 }
5660
5661 _forEachInstanceProperty__default['default'](glyphInfo).call(glyphInfo, function (glyph, i) {
5662 var p0 = glyph.p0,
5663 p1 = glyph.p1,
5664 rotation = glyph.rotation,
5665 partialText = glyph.text;
5666 ctx.save();
5667 ctx.translate(p0.x, p0.y);
5668 ctx.rotate(rotation);
5669
5670 if (ctx.fillStyle) {
5671 ctx.fillText(partialText, 0, 0);
5672 }
5673
5674 if (ctx.strokeStyle) {
5675 ctx.strokeText(partialText, 0, 0);
5676 }
5677
5678 ctx.restore();
5679
5680 if (textDecoration === 'underline') {
5681 if (i === 0) {
5682 ctx.moveTo(p0.x, p0.y + fontSize / 8);
5683 }
5684
5685 ctx.lineTo(p1.x, p1.y + fontSize / 5);
5686 } //// To assist with debugging visually, uncomment following
5687 //
5688 // ctx.beginPath();
5689 // if (i % 2)
5690 // ctx.strokeStyle = 'red';
5691 // else
5692 // ctx.strokeStyle = 'green';
5693 // ctx.moveTo(p0.x, p0.y);
5694 // ctx.lineTo(p1.x, p1.y);
5695 // ctx.stroke();
5696 // ctx.closePath();
5697
5698 });
5699
5700 if (textDecoration === 'underline') {
5701 ctx.lineWidth = fontSize / 20;
5702 ctx.strokeStyle = fill;
5703 ctx.stroke();
5704 ctx.closePath();
5705 }
5706
5707 ctx.restore();
5708 }
5709 }, {
5710 key: "getLetterSpacingAt",
5711 value: function getLetterSpacingAt() {
5712 var idx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
5713 return this.letterSpacingCache[idx] || 0;
5714 }
5715 }, {
5716 key: "findSegmentToFitChar",
5717 value: function findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, inputOffset, dy, c, charI) {
5718 var offset = inputOffset;
5719 var glyphWidth = this.measureText(ctx, c);
5720
5721 if (c === ' ' && anchor === 'justify' && textFullWidth < fullPathWidth) {
5722 glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
5723 }
5724
5725 if (charI > -1) {
5726 offset += this.getLetterSpacingAt(charI);
5727 }
5728
5729 var splineStep = this.textHeight / 20;
5730 var p0 = this.getEquidistantPointOnPath(offset, splineStep, 0);
5731 var p1 = this.getEquidistantPointOnPath(offset + glyphWidth, splineStep, 0);
5732 var segment = {
5733 p0: p0,
5734 p1: p1
5735 };
5736 var rotation = p0 && p1 ? Math.atan2(p1.y - p0.y, p1.x - p0.x) : 0;
5737
5738 if (dy) {
5739 var dyX = Math.cos(Math.PI / 2 + rotation) * dy;
5740 var dyY = Math.cos(-rotation) * dy;
5741 segment.p0 = _objectSpread(_objectSpread({}, p0), {}, {
5742 x: p0.x + dyX,
5743 y: p0.y + dyY
5744 });
5745 segment.p1 = _objectSpread(_objectSpread({}, p1), {}, {
5746 x: p1.x + dyX,
5747 y: p1.y + dyY
5748 });
5749 }
5750
5751 offset += glyphWidth;
5752 return {
5753 offset: offset,
5754 segment: segment,
5755 rotation: rotation
5756 };
5757 }
5758 }, {
5759 key: "measureText",
5760 value: function measureText(ctx, text) {
5761 var measuresCache = this.measuresCache;
5762 var targetText = text || this.getText();
5763
5764 if (measuresCache.has(targetText)) {
5765 return measuresCache.get(targetText);
5766 }
5767
5768 var measure = this.measureTargetText(ctx, targetText);
5769 measuresCache.set(targetText, measure);
5770 return measure;
5771 } // This method supposes what all custom fonts already loaded.
5772 // If some font will be loaded after this method call, <textPath> will not be rendered correctly.
5773 // You need to call this method manually to update glyphs cache.
5774
5775 }, {
5776 key: "setTextData",
5777 value: function setTextData(ctx) {
5778 var _context,
5779 _this2 = this;
5780
5781 if (this.glyphInfo) {
5782 return;
5783 }
5784
5785 var renderText = this.getText();
5786 var chars = renderText.split('');
5787 var spacesNumber = renderText.split(' ').length - 1;
5788
5789 var dx = _mapInstanceProperty__default['default'](_context = this.parent.getAttribute('dx').split()).call(_context, function (_) {
5790 return _.getPixels('x');
5791 });
5792
5793 var dy = this.parent.getAttribute('dy').getPixels('y');
5794 var anchor = this.parent.getStyle('text-anchor').getString('start');
5795 var thisSpacing = this.getStyle('letter-spacing');
5796 var parentSpacing = this.parent.getStyle('letter-spacing');
5797 var letterSpacing = 0;
5798
5799 if (!thisSpacing.hasValue() || thisSpacing.getValue() === 'inherit') {
5800 letterSpacing = parentSpacing.getPixels();
5801 } else if (thisSpacing.hasValue()) {
5802 if (thisSpacing.getValue() !== 'initial' && thisSpacing.getValue() !== 'unset') {
5803 letterSpacing = thisSpacing.getPixels();
5804 }
5805 } // fill letter-spacing cache
5806
5807
5808 var letterSpacingCache = [];
5809 var textLen = renderText.length;
5810 this.letterSpacingCache = letterSpacingCache;
5811
5812 for (var i = 0; i < textLen; i++) {
5813 letterSpacingCache.push(typeof dx[i] !== 'undefined' ? dx[i] : letterSpacing);
5814 }
5815
5816 var dxSum = _reduceInstanceProperty__default['default'](letterSpacingCache).call(letterSpacingCache, function (acc, cur, i) {
5817 return i === 0 ? 0 : acc + cur || 0;
5818 }, 0);
5819
5820 var textWidth = this.measureText(ctx);
5821 var textFullWidth = Math.max(textWidth + dxSum, 0);
5822 this.textWidth = textWidth;
5823 this.textHeight = this.getFontSize();
5824 this.glyphInfo = [];
5825 var fullPathWidth = this.getPathLength();
5826 var startOffset = this.getStyle('startOffset').getNumber(0) * fullPathWidth;
5827 var offset = 0;
5828
5829 if (anchor === 'middle' || anchor === 'center') {
5830 offset = -textFullWidth / 2;
5831 }
5832
5833 if (anchor === 'end' || anchor === 'right') {
5834 offset = -textFullWidth;
5835 }
5836
5837 offset += startOffset;
5838
5839 _forEachInstanceProperty__default['default'](chars).call(chars, function (char, i) {
5840 // Find such segment what distance between p0 and p1 is approx. width of glyph
5841 var _this2$findSegmentToF = _this2.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, offset, dy, char, i),
5842 nextOffset = _this2$findSegmentToF.offset,
5843 segment = _this2$findSegmentToF.segment,
5844 rotation = _this2$findSegmentToF.rotation;
5845
5846 offset = nextOffset;
5847
5848 if (!segment.p0 || !segment.p1) {
5849 return;
5850 } // const width = this.getLineLength(
5851 // segment.p0.x,
5852 // segment.p0.y,
5853 // segment.p1.x,
5854 // segment.p1.y
5855 // );
5856 // Note: Since glyphs are rendered one at a time, any kerning pair data built into the font will not be used.
5857 // Can foresee having a rough pair table built in that the developer can override as needed.
5858 // Or use "dx" attribute of the <text> node as a naive replacement
5859 // const kern = 0;
5860 // placeholder for future implementation
5861 // const midpoint = this.getPointOnLine(
5862 // kern + width / 2.0,
5863 // segment.p0.x, segment.p0.y, segment.p1.x, segment.p1.y
5864 // );
5865
5866
5867 _this2.glyphInfo.push({
5868 // transposeX: midpoint.x,
5869 // transposeY: midpoint.y,
5870 text: chars[i],
5871 p0: segment.p0,
5872 p1: segment.p1,
5873 rotation: rotation
5874 });
5875 });
5876 }
5877 }, {
5878 key: "parsePathData",
5879 value: function parsePathData(path) {
5880 this.pathLength = -1; // reset path length
5881
5882 if (!path) {
5883 return [];
5884 }
5885
5886 var pathCommands = [];
5887 var pathParser = path.pathParser;
5888 pathParser.reset(); // convert l, H, h, V, and v to L
5889
5890 while (!pathParser.isEnd()) {
5891 var current = pathParser.current;
5892 var startX = current ? current.x : 0;
5893 var startY = current ? current.y : 0;
5894 var command = pathParser.next();
5895 var nextCommandType = command.type;
5896 var points = [];
5897
5898 switch (command.type) {
5899 case PathParser.MOVE_TO:
5900 this.pathM(pathParser, points);
5901 break;
5902
5903 case PathParser.LINE_TO:
5904 nextCommandType = this.pathL(pathParser, points);
5905 break;
5906
5907 case PathParser.HORIZ_LINE_TO:
5908 nextCommandType = this.pathH(pathParser, points);
5909 break;
5910
5911 case PathParser.VERT_LINE_TO:
5912 nextCommandType = this.pathV(pathParser, points);
5913 break;
5914
5915 case PathParser.CURVE_TO:
5916 this.pathC(pathParser, points);
5917 break;
5918
5919 case PathParser.SMOOTH_CURVE_TO:
5920 nextCommandType = this.pathS(pathParser, points);
5921 break;
5922
5923 case PathParser.QUAD_TO:
5924 this.pathQ(pathParser, points);
5925 break;
5926
5927 case PathParser.SMOOTH_QUAD_TO:
5928 nextCommandType = this.pathT(pathParser, points);
5929 break;
5930
5931 case PathParser.ARC:
5932 points = this.pathA(pathParser);
5933 break;
5934
5935 case PathParser.CLOSE_PATH:
5936 PathElement.pathZ(pathParser);
5937 break;
5938 }
5939
5940 if (command.type !== PathParser.CLOSE_PATH) {
5941 pathCommands.push({
5942 type: nextCommandType,
5943 points: points,
5944 start: {
5945 x: startX,
5946 y: startY
5947 },
5948 pathLength: this.calcLength(startX, startY, nextCommandType, points)
5949 });
5950 } else {
5951 pathCommands.push({
5952 type: PathParser.CLOSE_PATH,
5953 points: [],
5954 pathLength: 0
5955 });
5956 }
5957 }
5958
5959 return pathCommands;
5960 }
5961 }, {
5962 key: "pathM",
5963 value: function pathM(pathParser, points) {
5964 var _PathElement$pathM$po = PathElement.pathM(pathParser).point,
5965 x = _PathElement$pathM$po.x,
5966 y = _PathElement$pathM$po.y;
5967 points.push(x, y);
5968 }
5969 }, {
5970 key: "pathL",
5971 value: function pathL(pathParser, points) {
5972 var _PathElement$pathL$po = PathElement.pathL(pathParser).point,
5973 x = _PathElement$pathL$po.x,
5974 y = _PathElement$pathL$po.y;
5975 points.push(x, y);
5976 return PathParser.LINE_TO;
5977 }
5978 }, {
5979 key: "pathH",
5980 value: function pathH(pathParser, points) {
5981 var _PathElement$pathH$po = PathElement.pathH(pathParser).point,
5982 x = _PathElement$pathH$po.x,
5983 y = _PathElement$pathH$po.y;
5984 points.push(x, y);
5985 return PathParser.LINE_TO;
5986 }
5987 }, {
5988 key: "pathV",
5989 value: function pathV(pathParser, points) {
5990 var _PathElement$pathV$po = PathElement.pathV(pathParser).point,
5991 x = _PathElement$pathV$po.x,
5992 y = _PathElement$pathV$po.y;
5993 points.push(x, y);
5994 return PathParser.LINE_TO;
5995 }
5996 }, {
5997 key: "pathC",
5998 value: function pathC(pathParser, points) {
5999 var _PathElement$pathC = PathElement.pathC(pathParser),
6000 point = _PathElement$pathC.point,
6001 controlPoint = _PathElement$pathC.controlPoint,
6002 currentPoint = _PathElement$pathC.currentPoint;
6003
6004 points.push(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
6005 }
6006 }, {
6007 key: "pathS",
6008 value: function pathS(pathParser, points) {
6009 var _PathElement$pathS = PathElement.pathS(pathParser),
6010 point = _PathElement$pathS.point,
6011 controlPoint = _PathElement$pathS.controlPoint,
6012 currentPoint = _PathElement$pathS.currentPoint;
6013
6014 points.push(point.x, point.y, controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
6015 return PathParser.CURVE_TO;
6016 }
6017 }, {
6018 key: "pathQ",
6019 value: function pathQ(pathParser, points) {
6020 var _PathElement$pathQ = PathElement.pathQ(pathParser),
6021 controlPoint = _PathElement$pathQ.controlPoint,
6022 currentPoint = _PathElement$pathQ.currentPoint;
6023
6024 points.push(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
6025 }
6026 }, {
6027 key: "pathT",
6028 value: function pathT(pathParser, points) {
6029 var _PathElement$pathT = PathElement.pathT(pathParser),
6030 controlPoint = _PathElement$pathT.controlPoint,
6031 currentPoint = _PathElement$pathT.currentPoint;
6032
6033 points.push(controlPoint.x, controlPoint.y, currentPoint.x, currentPoint.y);
6034 return PathParser.QUAD_TO;
6035 }
6036 }, {
6037 key: "pathA",
6038 value: function pathA(pathParser) {
6039 var _PathElement$pathA = PathElement.pathA(pathParser),
6040 rX = _PathElement$pathA.rX,
6041 rY = _PathElement$pathA.rY,
6042 sweepFlag = _PathElement$pathA.sweepFlag,
6043 xAxisRotation = _PathElement$pathA.xAxisRotation,
6044 centp = _PathElement$pathA.centp,
6045 a1 = _PathElement$pathA.a1,
6046 ad = _PathElement$pathA.ad;
6047
6048 if (sweepFlag === 0 && ad > 0) {
6049 ad = ad - 2 * Math.PI;
6050 }
6051
6052 if (sweepFlag === 1 && ad < 0) {
6053 ad = ad + 2 * Math.PI;
6054 }
6055
6056 return [centp.x, centp.y, rX, rY, a1, ad, xAxisRotation, sweepFlag];
6057 }
6058 }, {
6059 key: "calcLength",
6060 value: function calcLength(x, y, commandType, points) {
6061 var len = 0;
6062 var p1 = null;
6063 var p2 = null;
6064 var t = 0;
6065
6066 switch (commandType) {
6067 case PathParser.LINE_TO:
6068 return this.getLineLength(x, y, points[0], points[1]);
6069
6070 case PathParser.CURVE_TO:
6071 // Approximates by breaking curve into 100 line segments
6072 len = 0.0;
6073 p1 = this.getPointOnCubicBezier(0, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
6074
6075 for (t = 0.01; t <= 1; t += 0.01) {
6076 p2 = this.getPointOnCubicBezier(t, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
6077 len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
6078 p1 = p2;
6079 }
6080
6081 return len;
6082
6083 case PathParser.QUAD_TO:
6084 // Approximates by breaking curve into 100 line segments
6085 len = 0.0;
6086 p1 = this.getPointOnQuadraticBezier(0, x, y, points[0], points[1], points[2], points[3]);
6087
6088 for (t = 0.01; t <= 1; t += 0.01) {
6089 p2 = this.getPointOnQuadraticBezier(t, x, y, points[0], points[1], points[2], points[3]);
6090 len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
6091 p1 = p2;
6092 }
6093
6094 return len;
6095
6096 case PathParser.ARC:
6097 // Approximates by breaking curve into line segments
6098 len = 0.0;
6099 var start = points[4]; // 4 = theta
6100
6101 var dTheta = points[5]; // 5 = dTheta
6102
6103 var end = points[4] + dTheta;
6104 var inc = Math.PI / 180.0; // 1 degree resolution
6105
6106 if (Math.abs(start - end) < inc) {
6107 inc = Math.abs(start - end);
6108 } // Note: for purpose of calculating arc length, not going to worry about rotating X-axis by angle psi
6109
6110
6111 p1 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], start, 0);
6112
6113 if (dTheta < 0) {
6114 // clockwise
6115 for (t = start - inc; t > end; t -= inc) {
6116 p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
6117 len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
6118 p1 = p2;
6119 }
6120 } else {
6121 // counter-clockwise
6122 for (t = start + inc; t < end; t += inc) {
6123 p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
6124 len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
6125 p1 = p2;
6126 }
6127 }
6128
6129 p2 = this.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], end, 0);
6130 len += this.getLineLength(p1.x, p1.y, p2.x, p2.y);
6131 return len;
6132 }
6133
6134 return 0;
6135 }
6136 }, {
6137 key: "getPointOnLine",
6138 value: function getPointOnLine(dist, P1x, P1y, P2x, P2y) {
6139 var fromX = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : P1x;
6140 var fromY = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : P1y;
6141 var m = (P2y - P1y) / (P2x - P1x + PSEUDO_ZERO);
6142 var run = Math.sqrt(dist * dist / (1 + m * m));
6143
6144 if (P2x < P1x) {
6145 run *= -1;
6146 }
6147
6148 var rise = m * run;
6149 var pt = null;
6150
6151 if (P2x === P1x) {
6152 // vertical line
6153 pt = {
6154 x: fromX,
6155 y: fromY + rise
6156 };
6157 } else if ((fromY - P1y) / (fromX - P1x + PSEUDO_ZERO) === m) {
6158 pt = {
6159 x: fromX + run,
6160 y: fromY + rise
6161 };
6162 } else {
6163 var ix = 0;
6164 var iy = 0;
6165 var len = this.getLineLength(P1x, P1y, P2x, P2y);
6166
6167 if (len < PSEUDO_ZERO) {
6168 return null;
6169 }
6170
6171 var u = (fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y);
6172 u = u / (len * len);
6173 ix = P1x + u * (P2x - P1x);
6174 iy = P1y + u * (P2y - P1y);
6175 var pRise = this.getLineLength(fromX, fromY, ix, iy);
6176 var pRun = Math.sqrt(dist * dist - pRise * pRise);
6177 run = Math.sqrt(pRun * pRun / (1 + m * m));
6178
6179 if (P2x < P1x) {
6180 run *= -1;
6181 }
6182
6183 rise = m * run;
6184 pt = {
6185 x: ix + run,
6186 y: iy + rise
6187 };
6188 }
6189
6190 return pt;
6191 }
6192 }, {
6193 key: "getPointOnPath",
6194 value: function getPointOnPath(distance) {
6195 var fullLen = this.getPathLength();
6196 var cumulativePathLength = 0;
6197 var p = null;
6198
6199 if (distance < -0.00005 || distance - 0.00005 > fullLen) {
6200 return null;
6201 }
6202
6203 var dataArray = this.dataArray;
6204
6205 var _iterator = _createForOfIteratorHelper$1(dataArray),
6206 _step;
6207
6208 try {
6209 for (_iterator.s(); !(_step = _iterator.n()).done;) {
6210 var command = _step.value;
6211
6212 if (command && (command.pathLength < 0.00005 || cumulativePathLength + command.pathLength + 0.00005 < distance)) {
6213 cumulativePathLength += command.pathLength;
6214 continue;
6215 }
6216
6217 var delta = distance - cumulativePathLength;
6218 var currentT = 0;
6219
6220 switch (command.type) {
6221 case PathParser.LINE_TO:
6222 p = this.getPointOnLine(delta, command.start.x, command.start.y, command.points[0], command.points[1], command.start.x, command.start.y);
6223 break;
6224
6225 case PathParser.ARC:
6226 var start = command.points[4]; // 4 = theta
6227
6228 var dTheta = command.points[5]; // 5 = dTheta
6229
6230 var end = command.points[4] + dTheta;
6231 currentT = start + delta / command.pathLength * dTheta;
6232
6233 if (dTheta < 0 && currentT < end || dTheta >= 0 && currentT > end) {
6234 break;
6235 }
6236
6237 p = this.getPointOnEllipticalArc(command.points[0], command.points[1], command.points[2], command.points[3], currentT, command.points[6]);
6238 break;
6239
6240 case PathParser.CURVE_TO:
6241 currentT = delta / command.pathLength;
6242
6243 if (currentT > 1) {
6244 currentT = 1;
6245 }
6246
6247 p = this.getPointOnCubicBezier(currentT, command.start.x, command.start.y, command.points[0], command.points[1], command.points[2], command.points[3], command.points[4], command.points[5]);
6248 break;
6249
6250 case PathParser.QUAD_TO:
6251 currentT = delta / command.pathLength;
6252
6253 if (currentT > 1) {
6254 currentT = 1;
6255 }
6256
6257 p = this.getPointOnQuadraticBezier(currentT, command.start.x, command.start.y, command.points[0], command.points[1], command.points[2], command.points[3]);
6258 break;
6259
6260 default:
6261 }
6262
6263 if (p) {
6264 return p;
6265 }
6266
6267 break;
6268 }
6269 } catch (err) {
6270 _iterator.e(err);
6271 } finally {
6272 _iterator.f();
6273 }
6274
6275 return null;
6276 }
6277 }, {
6278 key: "getLineLength",
6279 value: function getLineLength(x1, y1, x2, y2) {
6280 return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
6281 }
6282 }, {
6283 key: "getPathLength",
6284 value: function getPathLength() {
6285 if (this.pathLength === -1) {
6286 var _context2;
6287
6288 this.pathLength = _reduceInstanceProperty__default['default'](_context2 = this.dataArray).call(_context2, function (length, command) {
6289 return command.pathLength > 0 ? length + command.pathLength : length;
6290 }, 0);
6291 }
6292
6293 return this.pathLength;
6294 }
6295 }, {
6296 key: "getPointOnCubicBezier",
6297 value: function getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
6298 var x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
6299 var y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
6300 return {
6301 x: x,
6302 y: y
6303 };
6304 }
6305 }, {
6306 key: "getPointOnQuadraticBezier",
6307 value: function getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
6308 var x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
6309 var y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
6310 return {
6311 x: x,
6312 y: y
6313 };
6314 }
6315 }, {
6316 key: "getPointOnEllipticalArc",
6317 value: function getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
6318 var cosPsi = Math.cos(psi);
6319 var sinPsi = Math.sin(psi);
6320 var pt = {
6321 x: rx * Math.cos(theta),
6322 y: ry * Math.sin(theta)
6323 };
6324 return {
6325 x: cx + (pt.x * cosPsi - pt.y * sinPsi),
6326 y: cy + (pt.x * sinPsi + pt.y * cosPsi)
6327 };
6328 } // TODO need some optimisations. possibly build cache only for curved segments?
6329
6330 }, {
6331 key: "buildEquidistantCache",
6332 value: function buildEquidistantCache(inputStep, inputPrecision) {
6333 var fullLen = this.getPathLength();
6334 var precision = inputPrecision || 0.25; // accuracy vs performance
6335
6336 var step = inputStep || fullLen / 100;
6337
6338 if (!this.equidistantCache || this.equidistantCache.step !== step || this.equidistantCache.precision !== precision) {
6339 // Prepare cache
6340 this.equidistantCache = {
6341 step: step,
6342 precision: precision,
6343 points: []
6344 }; // Calculate points
6345
6346 var s = 0;
6347
6348 for (var l = 0; l <= fullLen; l += precision) {
6349 var p0 = this.getPointOnPath(l);
6350 var p1 = this.getPointOnPath(l + precision);
6351
6352 if (!p0 || !p1) {
6353 continue;
6354 }
6355
6356 s += this.getLineLength(p0.x, p0.y, p1.x, p1.y);
6357
6358 if (s >= step) {
6359 this.equidistantCache.points.push({
6360 x: p0.x,
6361 y: p0.y,
6362 distance: l
6363 });
6364 s -= step;
6365 }
6366 }
6367 }
6368 }
6369 }, {
6370 key: "getEquidistantPointOnPath",
6371 value: function getEquidistantPointOnPath(targetDistance, step, precision) {
6372 this.buildEquidistantCache(step, precision);
6373
6374 if (targetDistance < 0 || targetDistance - this.getPathLength() > 0.00005) {
6375 return null;
6376 }
6377
6378 var idx = Math.round(targetDistance / this.getPathLength() * (this.equidistantCache.points.length - 1));
6379 return this.equidistantCache.points[idx] || null;
6380 }
6381 }]);
6382
6383 return TextPathElement;
6384}(TextElement);
6385
6386function _createSuper$z(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$z(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6387
6388function _isNativeReflectConstruct$z() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6389
6390var ImageElement = /*#__PURE__*/function (_RenderedElement) {
6391 _inherits__default['default'](ImageElement, _RenderedElement);
6392
6393 var _super = _createSuper$z(ImageElement);
6394
6395 function ImageElement(document, node, captureTextNodes) {
6396 var _this;
6397
6398 _classCallCheck__default['default'](this, ImageElement);
6399
6400 _this = _super.call(this, document, node, captureTextNodes);
6401 _this.type = 'image';
6402 _this.loaded = false;
6403
6404 var href = _this.getHrefAttribute().getString();
6405
6406 if (!href) {
6407 return _possibleConstructorReturn__default['default'](_this);
6408 }
6409
6410 var isSvg = /\.svg$/.test(href);
6411 document.images.push(_assertThisInitialized__default['default'](_this));
6412
6413 if (!isSvg) {
6414 _this.loadImage(href);
6415 } else {
6416 _this.loadSvg(href);
6417 }
6418
6419 _this.isSvg = isSvg;
6420 return _this;
6421 }
6422
6423 _createClass__default['default'](ImageElement, [{
6424 key: "loadImage",
6425 value: function () {
6426 var _loadImage = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(href) {
6427 var image;
6428 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
6429 while (1) {
6430 switch (_context.prev = _context.next) {
6431 case 0:
6432 _context.prev = 0;
6433 _context.next = 3;
6434 return this.document.createImage(href);
6435
6436 case 3:
6437 image = _context.sent;
6438 this.image = image;
6439 _context.next = 10;
6440 break;
6441
6442 case 7:
6443 _context.prev = 7;
6444 _context.t0 = _context["catch"](0);
6445 // tslint:disable-next-line: no-console
6446 console.error("Error while loading image \"".concat(href, "\":"), _context.t0);
6447
6448 case 10:
6449 this.loaded = true;
6450
6451 case 11:
6452 case "end":
6453 return _context.stop();
6454 }
6455 }
6456 }, _callee, this, [[0, 7]]);
6457 }));
6458
6459 function loadImage(_x) {
6460 return _loadImage.apply(this, arguments);
6461 }
6462
6463 return loadImage;
6464 }()
6465 }, {
6466 key: "loadSvg",
6467 value: function () {
6468 var _loadSvg = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(href) {
6469 var response, svg;
6470 return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
6471 while (1) {
6472 switch (_context2.prev = _context2.next) {
6473 case 0:
6474 _context2.prev = 0;
6475 _context2.next = 3;
6476 return this.document.fetch(href);
6477
6478 case 3:
6479 response = _context2.sent;
6480 _context2.next = 6;
6481 return response.text();
6482
6483 case 6:
6484 svg = _context2.sent;
6485 this.image = svg;
6486 _context2.next = 13;
6487 break;
6488
6489 case 10:
6490 _context2.prev = 10;
6491 _context2.t0 = _context2["catch"](0);
6492 // tslint:disable-next-line: no-console
6493 console.error("Error while loading image \"".concat(href, "\":"), _context2.t0);
6494
6495 case 13:
6496 this.loaded = true;
6497
6498 case 14:
6499 case "end":
6500 return _context2.stop();
6501 }
6502 }
6503 }, _callee2, this, [[0, 10]]);
6504 }));
6505
6506 function loadSvg(_x2) {
6507 return _loadSvg.apply(this, arguments);
6508 }
6509
6510 return loadSvg;
6511 }()
6512 }, {
6513 key: "renderChildren",
6514 value: function renderChildren(ctx) {
6515 var document = this.document,
6516 image = this.image,
6517 loaded = this.loaded;
6518 var x = this.getAttribute('x').getPixels('x');
6519 var y = this.getAttribute('y').getPixels('y');
6520 var width = this.getStyle('width').getPixels('x');
6521 var height = this.getStyle('height').getPixels('y');
6522
6523 if (!loaded || !image || !width || !height) {
6524 return;
6525 }
6526
6527 ctx.save();
6528
6529 if (this.isSvg) {
6530 document.canvg.forkString(ctx, this.image, {
6531 ignoreMouse: true,
6532 ignoreAnimation: true,
6533 ignoreDimensions: true,
6534 ignoreClear: true,
6535 offsetX: x,
6536 offsetY: y,
6537 scaleWidth: width,
6538 scaleHeight: height
6539 }).render();
6540 } else {
6541 var _image = this.image;
6542 ctx.translate(x, y);
6543 document.setViewBox({
6544 ctx: ctx,
6545 aspectRatio: this.getAttribute('preserveAspectRatio').getString(),
6546 width: width,
6547 desiredWidth: _image.width,
6548 height: height,
6549 desiredHeight: _image.height
6550 });
6551
6552 if (this.loaded) {
6553 if (typeof _image.complete === 'undefined' || _image.complete) {
6554 ctx.drawImage(_image, 0, 0);
6555 }
6556 }
6557 }
6558
6559 ctx.restore();
6560 }
6561 }, {
6562 key: "getBoundingBox",
6563 value: function getBoundingBox() {
6564 var x = this.getAttribute('x').getPixels('x');
6565 var y = this.getAttribute('y').getPixels('y');
6566 var width = this.getStyle('width').getPixels('x');
6567 var height = this.getStyle('height').getPixels('y');
6568 return new BoundingBox(x, y, x + width, y + height);
6569 }
6570 }]);
6571
6572 return ImageElement;
6573}(RenderedElement);
6574
6575function _createSuper$A(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$A(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6576
6577function _isNativeReflectConstruct$A() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6578
6579var SymbolElement = /*#__PURE__*/function (_RenderedElement) {
6580 _inherits__default['default'](SymbolElement, _RenderedElement);
6581
6582 var _super = _createSuper$A(SymbolElement);
6583
6584 function SymbolElement() {
6585 var _this;
6586
6587 _classCallCheck__default['default'](this, SymbolElement);
6588
6589 _this = _super.apply(this, arguments);
6590 _this.type = 'symbol';
6591 return _this;
6592 }
6593
6594 _createClass__default['default'](SymbolElement, [{
6595 key: "render",
6596 value: function render(_) {// NO RENDER
6597 }
6598 }]);
6599
6600 return SymbolElement;
6601}(RenderedElement);
6602
6603var SVGFontLoader = /*#__PURE__*/function () {
6604 function SVGFontLoader(document) {
6605 _classCallCheck__default['default'](this, SVGFontLoader);
6606
6607 this.document = document;
6608 this.loaded = false;
6609 document.fonts.push(this);
6610 }
6611
6612 _createClass__default['default'](SVGFontLoader, [{
6613 key: "load",
6614 value: function () {
6615 var _load = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(fontFamily, url) {
6616 var _context, document, svgDocument, fonts;
6617
6618 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context2) {
6619 while (1) {
6620 switch (_context2.prev = _context2.next) {
6621 case 0:
6622 _context2.prev = 0;
6623 document = this.document;
6624 _context2.next = 4;
6625 return document.canvg.parser.load(url);
6626
6627 case 4:
6628 svgDocument = _context2.sent;
6629 fonts = svgDocument.getElementsByTagName('font');
6630
6631 _forEachInstanceProperty__default['default'](_context = _Array$from__default['default'](fonts)).call(_context, function (fontNode) {
6632 var font = document.createElement(fontNode);
6633 document.definitions[fontFamily] = font;
6634 });
6635
6636 _context2.next = 12;
6637 break;
6638
6639 case 9:
6640 _context2.prev = 9;
6641 _context2.t0 = _context2["catch"](0);
6642 // tslint:disable-next-line: no-console
6643 console.error("Error while loading font \"".concat(url, "\":"), _context2.t0);
6644
6645 case 12:
6646 this.loaded = true;
6647
6648 case 13:
6649 case "end":
6650 return _context2.stop();
6651 }
6652 }
6653 }, _callee, this, [[0, 9]]);
6654 }));
6655
6656 function load(_x, _x2) {
6657 return _load.apply(this, arguments);
6658 }
6659
6660 return load;
6661 }()
6662 }]);
6663
6664 return SVGFontLoader;
6665}();
6666
6667function _createSuper$B(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$B(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6668
6669function _isNativeReflectConstruct$B() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6670
6671var StyleElement = /*#__PURE__*/function (_Element) {
6672 _inherits__default['default'](StyleElement, _Element);
6673
6674 var _super = _createSuper$B(StyleElement);
6675
6676 function StyleElement(document, node, captureTextNodes) {
6677 var _context;
6678
6679 var _this;
6680
6681 _classCallCheck__default['default'](this, StyleElement);
6682
6683 _this = _super.call(this, document, node, captureTextNodes);
6684 _this.type = 'style';
6685 var css = compressSpaces(_mapInstanceProperty__default['default'](_context = _Array$from__default['default'](node.childNodes)).call(_context, function (_) {
6686 return _.data;
6687 }).join('').replace(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, '') // remove comments
6688 .replace(/@import.*;/g, '') // remove imports
6689 );
6690 var cssDefs = css.split('}');
6691
6692 _forEachInstanceProperty__default['default'](cssDefs).call(cssDefs, function (_) {
6693 var def = _trimInstanceProperty__default['default'](_).call(_);
6694
6695 if (!def) {
6696 return;
6697 }
6698
6699 var cssParts = def.split('{');
6700 var cssClasses = cssParts[0].split(',');
6701 var cssProps = cssParts[1].split(';');
6702
6703 _forEachInstanceProperty__default['default'](cssClasses).call(cssClasses, function (_) {
6704 var cssClass = _trimInstanceProperty__default['default'](_).call(_);
6705
6706 if (!cssClass) {
6707 return;
6708 }
6709
6710 var props = document.styles[cssClass] || {};
6711
6712 _forEachInstanceProperty__default['default'](cssProps).call(cssProps, function (cssProp) {
6713 var _context2, _context3;
6714
6715 var prop = _indexOfInstanceProperty__default['default'](cssProp).call(cssProp, ':');
6716
6717 var name = _trimInstanceProperty__default['default'](_context2 = cssProp.substr(0, prop)).call(_context2);
6718
6719 var value = _trimInstanceProperty__default['default'](_context3 = cssProp.substr(prop + 1, cssProp.length - prop)).call(_context3);
6720
6721 if (name && value) {
6722 props[name] = new Property(document, name, value);
6723 }
6724 });
6725
6726 document.styles[cssClass] = props;
6727 document.stylesSpecificity[cssClass] = getSelectorSpecificity(cssClass);
6728
6729 if (cssClass === '@font-face') {
6730 // && !nodeEnv
6731 var fontFamily = props['font-family'].getString().replace(/"|'/g, '');
6732 var srcs = props.src.getString().split(',');
6733
6734 _forEachInstanceProperty__default['default'](srcs).call(srcs, function (src) {
6735 if (_indexOfInstanceProperty__default['default'](src).call(src, 'format("svg")') > 0) {
6736 var url = parseExternalUrl(src);
6737
6738 if (url) {
6739 new SVGFontLoader(document).load(fontFamily, url);
6740 }
6741 }
6742 });
6743 }
6744 });
6745 });
6746
6747 return _this;
6748 }
6749
6750 return StyleElement;
6751}(Element);
6752StyleElement.parseExternalUrl = parseExternalUrl;
6753
6754function _createSuper$C(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$C(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6755
6756function _isNativeReflectConstruct$C() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6757
6758var UseElement = /*#__PURE__*/function (_RenderedElement) {
6759 _inherits__default['default'](UseElement, _RenderedElement);
6760
6761 var _super = _createSuper$C(UseElement);
6762
6763 function UseElement() {
6764 var _this;
6765
6766 _classCallCheck__default['default'](this, UseElement);
6767
6768 _this = _super.apply(this, arguments);
6769 _this.type = 'use';
6770 return _this;
6771 }
6772
6773 _createClass__default['default'](UseElement, [{
6774 key: "setContext",
6775 value: function setContext(ctx) {
6776 _get__default['default'](_getPrototypeOf__default['default'](UseElement.prototype), "setContext", this).call(this, ctx);
6777
6778 var xAttr = this.getAttribute('x');
6779 var yAttr = this.getAttribute('y');
6780
6781 if (xAttr.hasValue()) {
6782 ctx.translate(xAttr.getPixels('x'), 0);
6783 }
6784
6785 if (yAttr.hasValue()) {
6786 ctx.translate(0, yAttr.getPixels('y'));
6787 }
6788 }
6789 }, {
6790 key: "path",
6791 value: function path(ctx) {
6792 var element = this.element;
6793
6794 if (element) {
6795 element.path(ctx);
6796 }
6797 }
6798 }, {
6799 key: "renderChildren",
6800 value: function renderChildren(ctx) {
6801 var document = this.document,
6802 element = this.element;
6803
6804 if (element) {
6805 var tempSvg = element;
6806
6807 if (element.type === 'symbol') {
6808 // render me using a temporary svg element in symbol cases (http://www.w3.org/TR/SVG/struct.html#UseElement)
6809 tempSvg = new SVGElement(document, null);
6810 tempSvg.attributes.viewBox = new Property(document, 'viewBox', element.getAttribute('viewBox').getString());
6811 tempSvg.attributes.preserveAspectRatio = new Property(document, 'preserveAspectRatio', element.getAttribute('preserveAspectRatio').getString());
6812 tempSvg.attributes.overflow = new Property(document, 'overflow', element.getAttribute('overflow').getString());
6813 tempSvg.children = element.children; // element is still the parent of the children
6814
6815 element.styles.opacity = new Property(document, 'opacity', this.calculateOpacity());
6816 }
6817
6818 if (tempSvg.type === 'svg') {
6819 var widthStyle = this.getStyle('width', false, true);
6820 var heightStyle = this.getStyle('height', false, true); // if symbol or svg, inherit width/height from me
6821
6822 if (widthStyle.hasValue()) {
6823 tempSvg.attributes.width = new Property(document, 'width', widthStyle.getString());
6824 }
6825
6826 if (heightStyle.hasValue()) {
6827 tempSvg.attributes.height = new Property(document, 'height', heightStyle.getString());
6828 }
6829 }
6830
6831 var oldParent = tempSvg.parent;
6832 tempSvg.parent = this;
6833 tempSvg.render(ctx);
6834 tempSvg.parent = oldParent;
6835 }
6836 }
6837 }, {
6838 key: "getBoundingBox",
6839 value: function getBoundingBox(ctx) {
6840 var element = this.element;
6841
6842 if (element) {
6843 return element.getBoundingBox(ctx);
6844 }
6845
6846 return null;
6847 }
6848 }, {
6849 key: "elementTransform",
6850 value: function elementTransform() {
6851 var document = this.document,
6852 element = this.element;
6853 return Transform.fromElement(document, element);
6854 }
6855 }, {
6856 key: "element",
6857 get: function get() {
6858 if (!this._element) {
6859 this._element = this.getHrefAttribute().getDefinition();
6860 }
6861
6862 return this._element;
6863 }
6864 }]);
6865
6866 return UseElement;
6867}(RenderedElement);
6868
6869function _createSuper$D(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$D(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6870
6871function _isNativeReflectConstruct$D() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6872
6873function imGet(img, x, y, width, _, rgba) {
6874 return img[y * width * 4 + x * 4 + rgba];
6875}
6876
6877function imSet(img, x, y, width, _, rgba, val) {
6878 img[y * width * 4 + x * 4 + rgba] = val;
6879}
6880
6881function m(matrix, i, v) {
6882 var mi = matrix[i];
6883 return mi * v;
6884}
6885
6886function c(a, m1, m2, m3) {
6887 return m1 + Math.cos(a) * m2 + Math.sin(a) * m3;
6888}
6889
6890var FeColorMatrixElement = /*#__PURE__*/function (_Element) {
6891 _inherits__default['default'](FeColorMatrixElement, _Element);
6892
6893 var _super = _createSuper$D(FeColorMatrixElement);
6894
6895 function FeColorMatrixElement(document, node, captureTextNodes) {
6896 var _this;
6897
6898 _classCallCheck__default['default'](this, FeColorMatrixElement);
6899
6900 _this = _super.call(this, document, node, captureTextNodes);
6901 _this.type = 'feColorMatrix';
6902 var matrix = toNumbers(_this.getAttribute('values').getString());
6903
6904 switch (_this.getAttribute('type').getString('matrix')) {
6905 // http://www.w3.org/TR/SVG/filters.html#feColorMatrixElement
6906 case 'saturate':
6907 {
6908 var s = matrix[0];
6909 matrix = [0.213 + 0.787 * s, 0.715 - 0.715 * s, 0.072 - 0.072 * s, 0, 0, 0.213 - 0.213 * s, 0.715 + 0.285 * s, 0.072 - 0.072 * s, 0, 0, 0.213 - 0.213 * s, 0.715 - 0.715 * s, 0.072 + 0.928 * s, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
6910 break;
6911 }
6912
6913 case 'hueRotate':
6914 {
6915 var a = matrix[0] * Math.PI / 180.0;
6916 matrix = [c(a, 0.213, 0.787, -0.213), c(a, 0.715, -0.715, -0.715), c(a, 0.072, -0.072, 0.928), 0, 0, c(a, 0.213, -0.213, 0.143), c(a, 0.715, 0.285, 0.140), c(a, 0.072, -0.072, -0.283), 0, 0, c(a, 0.213, -0.213, -0.787), c(a, 0.715, -0.715, 0.715), c(a, 0.072, 0.928, 0.072), 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
6917 break;
6918 }
6919
6920 case 'luminanceToAlpha':
6921 matrix = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2125, 0.7154, 0.0721, 0, 0, 0, 0, 0, 0, 1];
6922 break;
6923 }
6924
6925 _this.matrix = matrix;
6926 _this.includeOpacity = _this.getAttribute('includeOpacity').hasValue();
6927 return _this;
6928 }
6929
6930 _createClass__default['default'](FeColorMatrixElement, [{
6931 key: "apply",
6932 value: function apply(ctx, _, __, width, height) {
6933 // assuming x==0 && y==0 for now
6934 var includeOpacity = this.includeOpacity,
6935 matrix = this.matrix;
6936 var srcData = ctx.getImageData(0, 0, width, height);
6937
6938 for (var y = 0; y < height; y++) {
6939 for (var x = 0; x < width; x++) {
6940 var r = imGet(srcData.data, x, y, width, height, 0);
6941 var g = imGet(srcData.data, x, y, width, height, 1);
6942 var b = imGet(srcData.data, x, y, width, height, 2);
6943 var a = imGet(srcData.data, x, y, width, height, 3);
6944 var nr = m(matrix, 0, r) + m(matrix, 1, g) + m(matrix, 2, b) + m(matrix, 3, a) + m(matrix, 4, 1);
6945 var ng = m(matrix, 5, r) + m(matrix, 6, g) + m(matrix, 7, b) + m(matrix, 8, a) + m(matrix, 9, 1);
6946 var nb = m(matrix, 10, r) + m(matrix, 11, g) + m(matrix, 12, b) + m(matrix, 13, a) + m(matrix, 14, 1);
6947 var na = m(matrix, 15, r) + m(matrix, 16, g) + m(matrix, 17, b) + m(matrix, 18, a) + m(matrix, 19, 1);
6948
6949 if (includeOpacity) {
6950 nr = ng = nb = 0;
6951 na *= a / 255;
6952 }
6953
6954 imSet(srcData.data, x, y, width, height, 0, nr);
6955 imSet(srcData.data, x, y, width, height, 1, ng);
6956 imSet(srcData.data, x, y, width, height, 2, nb);
6957 imSet(srcData.data, x, y, width, height, 3, na);
6958 }
6959 }
6960
6961 ctx.clearRect(0, 0, width, height);
6962 ctx.putImageData(srcData, 0, 0);
6963 }
6964 }]);
6965
6966 return FeColorMatrixElement;
6967}(Element);
6968
6969function _createSuper$E(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$E(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
6970
6971function _isNativeReflectConstruct$E() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
6972
6973var MaskElement = /*#__PURE__*/function (_Element) {
6974 _inherits__default['default'](MaskElement, _Element);
6975
6976 var _super = _createSuper$E(MaskElement);
6977
6978 function MaskElement() {
6979 var _this;
6980
6981 _classCallCheck__default['default'](this, MaskElement);
6982
6983 _this = _super.apply(this, arguments);
6984 _this.type = 'mask';
6985 return _this;
6986 }
6987
6988 _createClass__default['default'](MaskElement, [{
6989 key: "apply",
6990 value: function apply(ctx, element) {
6991 var document = this.document; // render as temp svg
6992
6993 var x = this.getAttribute('x').getPixels('x');
6994 var y = this.getAttribute('y').getPixels('y');
6995 var width = this.getStyle('width').getPixels('x');
6996 var height = this.getStyle('height').getPixels('y');
6997
6998 if (!width && !height) {
6999 var _context;
7000
7001 var boundingBox = new BoundingBox();
7002
7003 _forEachInstanceProperty__default['default'](_context = this.children).call(_context, function (child) {
7004 boundingBox.addBoundingBox(child.getBoundingBox(ctx));
7005 });
7006
7007 x = Math.floor(boundingBox.x1);
7008 y = Math.floor(boundingBox.y1);
7009 width = Math.floor(boundingBox.width);
7010 height = Math.floor(boundingBox.height);
7011 }
7012
7013 var ignoredStyles = this.removeStyles(element, MaskElement.ignoreStyles);
7014 var maskCanvas = document.createCanvas(x + width, y + height);
7015 var maskCtx = maskCanvas.getContext('2d');
7016 document.screen.setDefaults(maskCtx);
7017 this.renderChildren(maskCtx); // convert mask to alpha with a fake node
7018 // TODO: refactor out apply from feColorMatrix
7019
7020 new FeColorMatrixElement(document, {
7021 nodeType: 1,
7022 childNodes: [],
7023 attributes: [{
7024 nodeName: 'type',
7025 value: 'luminanceToAlpha'
7026 }, {
7027 nodeName: 'includeOpacity',
7028 value: 'true'
7029 }]
7030 }).apply(maskCtx, 0, 0, x + width, y + height);
7031 var tmpCanvas = document.createCanvas(x + width, y + height);
7032 var tmpCtx = tmpCanvas.getContext('2d');
7033 document.screen.setDefaults(tmpCtx);
7034 element.render(tmpCtx);
7035 tmpCtx.globalCompositeOperation = 'destination-in';
7036 tmpCtx.fillStyle = maskCtx.createPattern(maskCanvas, 'no-repeat');
7037 tmpCtx.fillRect(0, 0, x + width, y + height);
7038 ctx.fillStyle = tmpCtx.createPattern(tmpCanvas, 'no-repeat');
7039 ctx.fillRect(0, 0, x + width, y + height); // reassign mask
7040
7041 this.restoreStyles(element, ignoredStyles);
7042 }
7043 }, {
7044 key: "render",
7045 value: function render(_) {// NO RENDER
7046 }
7047 }]);
7048
7049 return MaskElement;
7050}(Element);
7051MaskElement.ignoreStyles = ['mask', 'transform', 'clip-path'];
7052
7053function _createSuper$F(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$F(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7054
7055function _isNativeReflectConstruct$F() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7056
7057var noop = function noop() {};
7058
7059var ClipPathElement = /*#__PURE__*/function (_Element) {
7060 _inherits__default['default'](ClipPathElement, _Element);
7061
7062 var _super = _createSuper$F(ClipPathElement);
7063
7064 function ClipPathElement() {
7065 var _this;
7066
7067 _classCallCheck__default['default'](this, ClipPathElement);
7068
7069 _this = _super.apply(this, arguments);
7070 _this.type = 'clipPath';
7071 return _this;
7072 }
7073
7074 _createClass__default['default'](ClipPathElement, [{
7075 key: "apply",
7076 value: function apply(ctx) {
7077 var _context;
7078
7079 var document = this.document;
7080
7081 var contextProto = _Reflect$getPrototypeOf__default['default'](ctx);
7082
7083 var beginPath = ctx.beginPath,
7084 closePath = ctx.closePath;
7085
7086 if (contextProto) {
7087 contextProto.beginPath = noop;
7088 contextProto.closePath = noop;
7089 }
7090
7091 _Reflect$apply__default['default'](beginPath, ctx, []);
7092
7093 _forEachInstanceProperty__default['default'](_context = this.children).call(_context, function (child) {
7094 if (typeof child.path === 'undefined') {
7095 return;
7096 }
7097
7098 var transform = typeof child.elementTransform !== 'undefined' ? child.elementTransform() : null; // handle <use />
7099
7100 if (!transform) {
7101 transform = Transform.fromElement(document, child);
7102 }
7103
7104 if (transform) {
7105 transform.apply(ctx);
7106 }
7107
7108 child.path(ctx);
7109
7110 if (contextProto) {
7111 contextProto.closePath = closePath;
7112 }
7113
7114 if (transform) {
7115 transform.unapply(ctx);
7116 }
7117 });
7118
7119 _Reflect$apply__default['default'](closePath, ctx, []);
7120
7121 ctx.clip();
7122
7123 if (contextProto) {
7124 contextProto.beginPath = beginPath;
7125 contextProto.closePath = closePath;
7126 }
7127 }
7128 }, {
7129 key: "render",
7130 value: function render(_) {// NO RENDER
7131 }
7132 }]);
7133
7134 return ClipPathElement;
7135}(Element);
7136
7137function _createSuper$G(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$G(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7138
7139function _isNativeReflectConstruct$G() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7140
7141var FilterElement = /*#__PURE__*/function (_Element) {
7142 _inherits__default['default'](FilterElement, _Element);
7143
7144 var _super = _createSuper$G(FilterElement);
7145
7146 function FilterElement() {
7147 var _this;
7148
7149 _classCallCheck__default['default'](this, FilterElement);
7150
7151 _this = _super.apply(this, arguments);
7152 _this.type = 'filter';
7153 return _this;
7154 }
7155
7156 _createClass__default['default'](FilterElement, [{
7157 key: "apply",
7158 value: function apply(ctx, element) {
7159 // render as temp svg
7160 var document = this.document,
7161 children = this.children;
7162 var boundingBox = element.getBoundingBox(ctx);
7163
7164 if (!boundingBox) {
7165 return;
7166 }
7167
7168 var px = 0;
7169 var py = 0;
7170
7171 _forEachInstanceProperty__default['default'](children).call(children, function (child) {
7172 var efd = child.extraFilterDistance || 0;
7173 px = Math.max(px, efd);
7174 py = Math.max(py, efd);
7175 });
7176
7177 var width = Math.floor(boundingBox.width);
7178 var height = Math.floor(boundingBox.height);
7179 var tmpCanvasWidth = width + 2 * px;
7180 var tmpCanvasHeight = height + 2 * py;
7181
7182 if (tmpCanvasWidth < 1 || tmpCanvasHeight < 1) {
7183 return;
7184 }
7185
7186 var x = Math.floor(boundingBox.x);
7187 var y = Math.floor(boundingBox.y);
7188 var ignoredStyles = this.removeStyles(element, FilterElement.ignoreStyles);
7189 var tmpCanvas = document.createCanvas(tmpCanvasWidth, tmpCanvasHeight);
7190 var tmpCtx = tmpCanvas.getContext('2d');
7191 document.screen.setDefaults(tmpCtx);
7192 tmpCtx.translate(-x + px, -y + py);
7193 element.render(tmpCtx); // apply filters
7194
7195 _forEachInstanceProperty__default['default'](children).call(children, function (child) {
7196 if (typeof child.apply === 'function') {
7197 child.apply(tmpCtx, 0, 0, tmpCanvasWidth, tmpCanvasHeight);
7198 }
7199 }); // render on me
7200
7201
7202 ctx.drawImage(tmpCanvas, 0, 0, tmpCanvasWidth, tmpCanvasHeight, x - px, y - py, tmpCanvasWidth, tmpCanvasHeight);
7203 this.restoreStyles(element, ignoredStyles);
7204 }
7205 }, {
7206 key: "render",
7207 value: function render(_) {// NO RENDER
7208 }
7209 }]);
7210
7211 return FilterElement;
7212}(Element);
7213FilterElement.ignoreStyles = ['filter', 'transform', 'clip-path'];
7214
7215function _createSuper$H(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$H(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7216
7217function _isNativeReflectConstruct$H() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7218
7219var FeDropShadowElement = /*#__PURE__*/function (_Element) {
7220 _inherits__default['default'](FeDropShadowElement, _Element);
7221
7222 var _super = _createSuper$H(FeDropShadowElement);
7223
7224 function FeDropShadowElement(document, node, captureTextNodes) {
7225 var _this;
7226
7227 _classCallCheck__default['default'](this, FeDropShadowElement);
7228
7229 _this = _super.call(this, document, node, captureTextNodes);
7230 _this.type = 'feDropShadow';
7231
7232 _this.addStylesFromStyleDefinition();
7233
7234 return _this;
7235 }
7236
7237 _createClass__default['default'](FeDropShadowElement, [{
7238 key: "apply",
7239 value: function apply(_, __, ___, ____, _____) {// TODO: implement
7240 }
7241 }]);
7242
7243 return FeDropShadowElement;
7244}(Element);
7245
7246function _createSuper$I(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$I(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7247
7248function _isNativeReflectConstruct$I() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7249
7250var FeMorphologyElement = /*#__PURE__*/function (_Element) {
7251 _inherits__default['default'](FeMorphologyElement, _Element);
7252
7253 var _super = _createSuper$I(FeMorphologyElement);
7254
7255 function FeMorphologyElement() {
7256 var _this;
7257
7258 _classCallCheck__default['default'](this, FeMorphologyElement);
7259
7260 _this = _super.apply(this, arguments);
7261 _this.type = 'feMorphology';
7262 return _this;
7263 }
7264
7265 _createClass__default['default'](FeMorphologyElement, [{
7266 key: "apply",
7267 value: function apply(_, __, ___, ____, _____) {// TODO: implement
7268 }
7269 }]);
7270
7271 return FeMorphologyElement;
7272}(Element);
7273
7274function _createSuper$J(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$J(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7275
7276function _isNativeReflectConstruct$J() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7277
7278var FeCompositeElement = /*#__PURE__*/function (_Element) {
7279 _inherits__default['default'](FeCompositeElement, _Element);
7280
7281 var _super = _createSuper$J(FeCompositeElement);
7282
7283 function FeCompositeElement() {
7284 var _this;
7285
7286 _classCallCheck__default['default'](this, FeCompositeElement);
7287
7288 _this = _super.apply(this, arguments);
7289 _this.type = 'feComposite';
7290 return _this;
7291 }
7292
7293 _createClass__default['default'](FeCompositeElement, [{
7294 key: "apply",
7295 value: function apply(_, __, ___, ____, _____) {// TODO: implement
7296 }
7297 }]);
7298
7299 return FeCompositeElement;
7300}(Element);
7301
7302function _createSuper$K(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$K(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7303
7304function _isNativeReflectConstruct$K() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7305
7306var FeGaussianBlurElement = /*#__PURE__*/function (_Element) {
7307 _inherits__default['default'](FeGaussianBlurElement, _Element);
7308
7309 var _super = _createSuper$K(FeGaussianBlurElement);
7310
7311 function FeGaussianBlurElement(document, node, captureTextNodes) {
7312 var _this;
7313
7314 _classCallCheck__default['default'](this, FeGaussianBlurElement);
7315
7316 _this = _super.call(this, document, node, captureTextNodes);
7317 _this.type = 'feGaussianBlur';
7318 _this.blurRadius = Math.floor(_this.getAttribute('stdDeviation').getNumber());
7319 _this.extraFilterDistance = _this.blurRadius;
7320 return _this;
7321 }
7322
7323 _createClass__default['default'](FeGaussianBlurElement, [{
7324 key: "apply",
7325 value: function apply(ctx, x, y, width, height) {
7326 var document = this.document,
7327 blurRadius = this.blurRadius;
7328 var body = document.window ? document.window.document.body : null;
7329 var canvas = ctx.canvas; // StackBlur requires canvas be on document
7330
7331 canvas.id = document.getUniqueId();
7332
7333 if (body) {
7334 canvas.style.display = 'none';
7335 body.appendChild(canvas);
7336 }
7337
7338 stackblurCanvas.canvasRGBA(canvas, x, y, width, height, blurRadius);
7339
7340 if (body) {
7341 body.removeChild(canvas);
7342 }
7343 }
7344 }]);
7345
7346 return FeGaussianBlurElement;
7347}(Element);
7348
7349function _createSuper$L(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$L(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7350
7351function _isNativeReflectConstruct$L() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7352
7353var TitleElement = /*#__PURE__*/function (_Element) {
7354 _inherits__default['default'](TitleElement, _Element);
7355
7356 var _super = _createSuper$L(TitleElement);
7357
7358 function TitleElement() {
7359 var _this;
7360
7361 _classCallCheck__default['default'](this, TitleElement);
7362
7363 _this = _super.apply(this, arguments);
7364 _this.type = 'title';
7365 return _this;
7366 }
7367
7368 return TitleElement;
7369}(Element);
7370
7371function _createSuper$M(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$M(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
7372
7373function _isNativeReflectConstruct$M() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(_Reflect$construct__default['default'](Date, [], function () {})); return true; } catch (e) { return false; } }
7374
7375var DescElement = /*#__PURE__*/function (_Element) {
7376 _inherits__default['default'](DescElement, _Element);
7377
7378 var _super = _createSuper$M(DescElement);
7379
7380 function DescElement() {
7381 var _this;
7382
7383 _classCallCheck__default['default'](this, DescElement);
7384
7385 _this = _super.apply(this, arguments);
7386 _this.type = 'desc';
7387 return _this;
7388 }
7389
7390 return DescElement;
7391}(Element);
7392
7393var elementTypes = {
7394 'svg': SVGElement,
7395 'rect': RectElement,
7396 'circle': CircleElement,
7397 'ellipse': EllipseElement,
7398 'line': LineElement,
7399 'polyline': PolylineElement,
7400 'polygon': PolygonElement,
7401 'path': PathElement,
7402 'pattern': PatternElement,
7403 'marker': MarkerElement,
7404 'defs': DefsElement,
7405 'linearGradient': LinearGradientElement,
7406 'radialGradient': RadialGradientElement,
7407 'stop': StopElement,
7408 'animate': AnimateElement,
7409 'animateColor': AnimateColorElement,
7410 'animateTransform': AnimateTransformElement,
7411 'font': FontElement,
7412 'font-face': FontFaceElement,
7413 'missing-glyph': MissingGlyphElement,
7414 'glyph': GlyphElement,
7415 'text': TextElement,
7416 'tspan': TSpanElement,
7417 'tref': TRefElement,
7418 'a': AElement,
7419 'textPath': TextPathElement,
7420 'image': ImageElement,
7421 'g': GElement,
7422 'symbol': SymbolElement,
7423 'style': StyleElement,
7424 'use': UseElement,
7425 'mask': MaskElement,
7426 'clipPath': ClipPathElement,
7427 'filter': FilterElement,
7428 'feDropShadow': FeDropShadowElement,
7429 'feMorphology': FeMorphologyElement,
7430 'feComposite': FeCompositeElement,
7431 'feColorMatrix': FeColorMatrixElement,
7432 'feGaussianBlur': FeGaussianBlurElement,
7433 'title': TitleElement,
7434 'desc': DescElement
7435};
7436
7437function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
7438
7439function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys$1(Object(source), true)).call(_context5, function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context6; _forEachInstanceProperty__default['default'](_context6 = ownKeys$1(Object(source))).call(_context6, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
7440
7441function createCanvas(width, height) {
7442 var canvas = document.createElement('canvas');
7443 canvas.width = width;
7444 canvas.height = height;
7445 return canvas;
7446}
7447
7448function createImage(_x) {
7449 return _createImage.apply(this, arguments);
7450}
7451
7452function _createImage() {
7453 _createImage = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(src) {
7454 var anonymousCrossOrigin,
7455 image,
7456 _args = arguments;
7457 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context7) {
7458 while (1) {
7459 switch (_context7.prev = _context7.next) {
7460 case 0:
7461 anonymousCrossOrigin = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
7462 image = document.createElement('img');
7463
7464 if (anonymousCrossOrigin) {
7465 image.crossOrigin = 'Anonymous';
7466 }
7467
7468 return _context7.abrupt("return", new _Promise__default['default'](function (resolve, reject) {
7469 image.onload = function () {
7470 resolve(image);
7471 };
7472
7473 image.onerror = function () {
7474 reject();
7475 };
7476
7477 image.src = src;
7478 }));
7479
7480 case 4:
7481 case "end":
7482 return _context7.stop();
7483 }
7484 }
7485 }, _callee);
7486 }));
7487 return _createImage.apply(this, arguments);
7488}
7489
7490var Document = /*#__PURE__*/function () {
7491 function Document(canvg) {
7492 var _context, _context2;
7493
7494 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
7495 _ref$rootEmSize = _ref.rootEmSize,
7496 rootEmSize = _ref$rootEmSize === void 0 ? 12 : _ref$rootEmSize,
7497 _ref$emSize = _ref.emSize,
7498 emSize = _ref$emSize === void 0 ? 12 : _ref$emSize,
7499 _ref$createCanvas = _ref.createCanvas,
7500 createCanvas = _ref$createCanvas === void 0 ? Document.createCanvas : _ref$createCanvas,
7501 _ref$createImage = _ref.createImage,
7502 createImage = _ref$createImage === void 0 ? Document.createImage : _ref$createImage,
7503 anonymousCrossOrigin = _ref.anonymousCrossOrigin;
7504
7505 _classCallCheck__default['default'](this, Document);
7506
7507 this.canvg = canvg;
7508 this.definitions = {};
7509 this.styles = {};
7510 this.stylesSpecificity = {};
7511 this.images = [];
7512 this.fonts = [];
7513 this.emSizeStack = [];
7514 this.uniqueId = 0;
7515 this.screen = canvg.screen;
7516 this.rootEmSize = rootEmSize;
7517 this.emSize = emSize;
7518 this.createCanvas = createCanvas;
7519 this.createImage = this.bindCreateImage(createImage, anonymousCrossOrigin);
7520 this.screen.wait(_bindInstanceProperty__default['default'](_context = this.isImagesLoaded).call(_context, this));
7521 this.screen.wait(_bindInstanceProperty__default['default'](_context2 = this.isFontsLoaded).call(_context2, this));
7522 }
7523
7524 _createClass__default['default'](Document, [{
7525 key: "bindCreateImage",
7526 value: function bindCreateImage(createImage, anonymousCrossOrigin) {
7527 if (typeof anonymousCrossOrigin === 'boolean') {
7528 return function (source, forceAnonymousCrossOrigin) {
7529 return createImage(source, typeof forceAnonymousCrossOrigin === 'boolean' ? forceAnonymousCrossOrigin : anonymousCrossOrigin);
7530 };
7531 }
7532
7533 return createImage;
7534 }
7535 }, {
7536 key: "popEmSize",
7537 value: function popEmSize() {
7538 var emSizeStack = this.emSizeStack;
7539 emSizeStack.pop();
7540 }
7541 }, {
7542 key: "getUniqueId",
7543 value: function getUniqueId() {
7544 return "canvg".concat(++this.uniqueId);
7545 }
7546 }, {
7547 key: "isImagesLoaded",
7548 value: function isImagesLoaded() {
7549 var _context3;
7550
7551 return _everyInstanceProperty__default['default'](_context3 = this.images).call(_context3, function (_) {
7552 return _.loaded;
7553 });
7554 }
7555 }, {
7556 key: "isFontsLoaded",
7557 value: function isFontsLoaded() {
7558 var _context4;
7559
7560 return _everyInstanceProperty__default['default'](_context4 = this.fonts).call(_context4, function (_) {
7561 return _.loaded;
7562 });
7563 }
7564 }, {
7565 key: "createDocumentElement",
7566 value: function createDocumentElement(document) {
7567 var documentElement = this.createElement(document.documentElement);
7568 documentElement.root = true;
7569 documentElement.addStylesFromStyleDefinition();
7570 this.documentElement = documentElement;
7571 return documentElement;
7572 }
7573 }, {
7574 key: "createElement",
7575 value: function createElement(node) {
7576 var elementType = node.nodeName.replace(/^[^:]+:/, '');
7577 var ElementType = Document.elementTypes[elementType];
7578
7579 if (typeof ElementType !== 'undefined') {
7580 return new ElementType(this, node);
7581 }
7582
7583 return new UnknownElement(this, node);
7584 }
7585 }, {
7586 key: "createTextNode",
7587 value: function createTextNode(node) {
7588 return new TextNode(this, node);
7589 }
7590 }, {
7591 key: "setViewBox",
7592 value: function setViewBox(config) {
7593 this.screen.setViewBox(_objectSpread$1({
7594 document: this
7595 }, config));
7596 }
7597 }, {
7598 key: "window",
7599 get: function get() {
7600 return this.screen.window;
7601 }
7602 }, {
7603 key: "fetch",
7604 get: function get() {
7605 return this.screen.fetch;
7606 }
7607 }, {
7608 key: "ctx",
7609 get: function get() {
7610 return this.screen.ctx;
7611 }
7612 }, {
7613 key: "emSize",
7614 get: function get() {
7615 var emSizeStack = this.emSizeStack;
7616 return emSizeStack[emSizeStack.length - 1];
7617 },
7618 set: function set(value) {
7619 var emSizeStack = this.emSizeStack;
7620 emSizeStack.push(value);
7621 }
7622 }]);
7623
7624 return Document;
7625}();
7626Document.createCanvas = createCanvas;
7627Document.createImage = createImage;
7628Document.elementTypes = elementTypes;
7629
7630function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
7631
7632function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default['default'](_context3 = ownKeys$2(Object(source), true)).call(_context3, function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys$2(Object(source))).call(_context4, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
7633/**
7634 * SVG renderer on canvas.
7635 */
7636
7637var Canvg = /*#__PURE__*/function () {
7638 /**
7639 * Main constructor.
7640 * @param ctx - Rendering context.
7641 * @param svg - SVG Document.
7642 * @param options - Rendering options.
7643 */
7644 function Canvg(ctx, svg) {
7645 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7646
7647 _classCallCheck__default['default'](this, Canvg);
7648
7649 this.parser = new Parser(options);
7650 this.screen = new Screen(ctx, options);
7651 this.options = options;
7652 var document = new Document(this, options);
7653 var documentElement = document.createDocumentElement(svg);
7654 this.document = document;
7655 this.documentElement = documentElement;
7656 }
7657 /**
7658 * Create Canvg instance from SVG source string or URL.
7659 * @param ctx - Rendering context.
7660 * @param svg - SVG source string or URL.
7661 * @param options - Rendering options.
7662 */
7663
7664
7665 _createClass__default['default'](Canvg, [{
7666 key: "fork",
7667
7668 /**
7669 * Create new Canvg instance with inherited options.
7670 * @param ctx - Rendering context.
7671 * @param svg - SVG source string or URL.
7672 * @param options - Rendering options.
7673 */
7674 value: function fork(ctx, svg) {
7675 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7676 return Canvg.from(ctx, svg, _objectSpread$2(_objectSpread$2({}, this.options), options));
7677 }
7678 /**
7679 * Create new Canvg instance with inherited options.
7680 * @param ctx - Rendering context.
7681 * @param svg - SVG source string.
7682 * @param options - Rendering options.
7683 */
7684
7685 }, {
7686 key: "forkString",
7687 value: function forkString(ctx, svg) {
7688 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7689 return Canvg.fromString(ctx, svg, _objectSpread$2(_objectSpread$2({}, this.options), options));
7690 }
7691 /**
7692 * Document is ready promise.
7693 */
7694
7695 }, {
7696 key: "ready",
7697 value: function ready() {
7698 return this.screen.ready();
7699 }
7700 /**
7701 * Document is ready value.
7702 */
7703
7704 }, {
7705 key: "isReady",
7706 value: function isReady() {
7707 return this.screen.isReady();
7708 }
7709 /**
7710 * Render only first frame, ignoring animations and mouse.
7711 * @param options - Rendering options.
7712 */
7713
7714 }, {
7715 key: "render",
7716 value: function () {
7717 var _render = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
7718 var options,
7719 _args = arguments;
7720 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
7721 while (1) {
7722 switch (_context.prev = _context.next) {
7723 case 0:
7724 options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
7725 this.start(_objectSpread$2({
7726 enableRedraw: true,
7727 ignoreAnimation: true,
7728 ignoreMouse: true
7729 }, options));
7730 _context.next = 4;
7731 return this.ready();
7732
7733 case 4:
7734 this.stop();
7735
7736 case 5:
7737 case "end":
7738 return _context.stop();
7739 }
7740 }
7741 }, _callee, this);
7742 }));
7743
7744 function render() {
7745 return _render.apply(this, arguments);
7746 }
7747
7748 return render;
7749 }()
7750 /**
7751 * Start rendering.
7752 * @param options - Render options.
7753 */
7754
7755 }, {
7756 key: "start",
7757 value: function start() {
7758 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7759 var documentElement = this.documentElement,
7760 screen = this.screen,
7761 baseOptions = this.options;
7762 screen.start(documentElement, _objectSpread$2(_objectSpread$2({
7763 enableRedraw: true
7764 }, baseOptions), options));
7765 }
7766 /**
7767 * Stop rendering.
7768 */
7769
7770 }, {
7771 key: "stop",
7772 value: function stop() {
7773 this.screen.stop();
7774 }
7775 /**
7776 * Resize SVG to fit in given size.
7777 * @param width
7778 * @param height
7779 * @param preserveAspectRatio
7780 */
7781
7782 }, {
7783 key: "resize",
7784 value: function resize(width) {
7785 var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : width;
7786 var preserveAspectRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
7787 this.documentElement.resize(width, height, preserveAspectRatio);
7788 }
7789 }], [{
7790 key: "from",
7791 value: function () {
7792 var _from = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(ctx, svg) {
7793 var options,
7794 parser,
7795 svgDocument,
7796 _args2 = arguments;
7797 return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
7798 while (1) {
7799 switch (_context2.prev = _context2.next) {
7800 case 0:
7801 options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
7802 parser = new Parser(options);
7803 _context2.next = 4;
7804 return parser.parse(svg);
7805
7806 case 4:
7807 svgDocument = _context2.sent;
7808 return _context2.abrupt("return", new Canvg(ctx, svgDocument, options));
7809
7810 case 6:
7811 case "end":
7812 return _context2.stop();
7813 }
7814 }
7815 }, _callee2);
7816 }));
7817
7818 function from(_x, _x2) {
7819 return _from.apply(this, arguments);
7820 }
7821
7822 return from;
7823 }()
7824 /**
7825 * Create Canvg instance from SVG source string.
7826 * @param ctx - Rendering context.
7827 * @param svg - SVG source string.
7828 * @param options - Rendering options.
7829 */
7830
7831 }, {
7832 key: "fromString",
7833 value: function fromString(ctx, svg) {
7834 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7835 var parser = new Parser(options);
7836 var svgDocument = parser.parseFromString(svg);
7837 return new Canvg(ctx, svgDocument, options);
7838 }
7839 }]);
7840
7841 return Canvg;
7842}();
7843
7844/**
7845 * Options preset for `OffscreenCanvas`.
7846 * @param config - Preset requirements.
7847 * @param config.DOMParser - XML/HTML parser from string into DOM Document.
7848 */
7849function offscreen() {
7850 var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7851 DOMParserFallback = _ref.DOMParser;
7852
7853 var preset = {
7854 window: null,
7855 ignoreAnimation: true,
7856 ignoreMouse: true,
7857 DOMParser: DOMParserFallback,
7858 createCanvas: function createCanvas(width, height) {
7859 return new OffscreenCanvas(width, height);
7860 },
7861 createImage: function createImage(url) {
7862 return _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
7863 var response, blob, img;
7864 return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
7865 while (1) {
7866 switch (_context.prev = _context.next) {
7867 case 0:
7868 _context.next = 2;
7869 return fetch(url);
7870
7871 case 2:
7872 response = _context.sent;
7873 _context.next = 5;
7874 return response.blob();
7875
7876 case 5:
7877 blob = _context.sent;
7878 _context.next = 8;
7879 return createImageBitmap(blob);
7880
7881 case 8:
7882 img = _context.sent;
7883 return _context.abrupt("return", img);
7884
7885 case 10:
7886 case "end":
7887 return _context.stop();
7888 }
7889 }
7890 }, _callee);
7891 }))();
7892 }
7893 };
7894
7895 if (typeof DOMParser !== 'undefined' || typeof DOMParserFallback === 'undefined') {
7896 _Reflect$deleteProperty__default['default'](preset, 'DOMParser');
7897 }
7898
7899 return preset;
7900}
7901
7902/**
7903 * Options preset for `node-canvas`.
7904 * @param config - Preset requirements.
7905 * @param config.DOMParser - XML/HTML parser from string into DOM Document.
7906 * @param config.canvas - `node-canvas` exports.
7907 * @param config.fetch - WHATWG-compatible `fetch` function.
7908 */
7909function node(_ref) {
7910 var DOMParser = _ref.DOMParser,
7911 canvas = _ref.canvas,
7912 fetch = _ref.fetch;
7913 return {
7914 window: null,
7915 ignoreAnimation: true,
7916 ignoreMouse: true,
7917 DOMParser: DOMParser,
7918 fetch: fetch,
7919 createCanvas: canvas.createCanvas,
7920 createImage: canvas.loadImage
7921 };
7922}
7923
7924var index = /*#__PURE__*/Object.freeze({
7925 __proto__: null,
7926 offscreen: offscreen,
7927 node: node
7928});
7929
7930exports.AElement = AElement;
7931exports.AnimateColorElement = AnimateColorElement;
7932exports.AnimateElement = AnimateElement;
7933exports.AnimateTransformElement = AnimateTransformElement;
7934exports.BoundingBox = BoundingBox;
7935exports.CB1 = CB1;
7936exports.CB2 = CB2;
7937exports.CB3 = CB3;
7938exports.CB4 = CB4;
7939exports.Canvg = Canvg;
7940exports.CircleElement = CircleElement;
7941exports.ClipPathElement = ClipPathElement;
7942exports.DefsElement = DefsElement;
7943exports.DescElement = DescElement;
7944exports.Document = Document;
7945exports.Element = Element;
7946exports.EllipseElement = EllipseElement;
7947exports.FeColorMatrixElement = FeColorMatrixElement;
7948exports.FeCompositeElement = FeCompositeElement;
7949exports.FeDropShadowElement = FeDropShadowElement;
7950exports.FeGaussianBlurElement = FeGaussianBlurElement;
7951exports.FeMorphologyElement = FeMorphologyElement;
7952exports.FilterElement = FilterElement;
7953exports.Font = Font;
7954exports.FontElement = FontElement;
7955exports.FontFaceElement = FontFaceElement;
7956exports.GElement = GElement;
7957exports.GlyphElement = GlyphElement;
7958exports.GradientElement = GradientElement;
7959exports.ImageElement = ImageElement;
7960exports.LineElement = LineElement;
7961exports.LinearGradientElement = LinearGradientElement;
7962exports.MarkerElement = MarkerElement;
7963exports.MaskElement = MaskElement;
7964exports.Matrix = Matrix;
7965exports.MissingGlyphElement = MissingGlyphElement;
7966exports.Mouse = Mouse;
7967exports.PSEUDO_ZERO = PSEUDO_ZERO;
7968exports.Parser = Parser;
7969exports.PathElement = PathElement;
7970exports.PathParser = PathParser;
7971exports.PatternElement = PatternElement;
7972exports.Point = Point;
7973exports.PolygonElement = PolygonElement;
7974exports.PolylineElement = PolylineElement;
7975exports.Property = Property;
7976exports.QB1 = QB1;
7977exports.QB2 = QB2;
7978exports.QB3 = QB3;
7979exports.RadialGradientElement = RadialGradientElement;
7980exports.RectElement = RectElement;
7981exports.RenderedElement = RenderedElement;
7982exports.Rotate = Rotate;
7983exports.SVGElement = SVGElement;
7984exports.SVGFontLoader = SVGFontLoader;
7985exports.Scale = Scale;
7986exports.Screen = Screen;
7987exports.Skew = Skew;
7988exports.SkewX = SkewX;
7989exports.SkewY = SkewY;
7990exports.StopElement = StopElement;
7991exports.StyleElement = StyleElement;
7992exports.SymbolElement = SymbolElement;
7993exports.TRefElement = TRefElement;
7994exports.TSpanElement = TSpanElement;
7995exports.TextElement = TextElement;
7996exports.TextPathElement = TextPathElement;
7997exports.TitleElement = TitleElement;
7998exports.Transform = Transform;
7999exports.Translate = Translate;
8000exports.UnknownElement = UnknownElement;
8001exports.UseElement = UseElement;
8002exports.ViewPort = ViewPort;
8003exports.compressSpaces = compressSpaces;
8004exports.default = Canvg;
8005exports.getSelectorSpecificity = getSelectorSpecificity;
8006exports.normalizeAttributeName = normalizeAttributeName;
8007exports.normalizeColor = normalizeColor;
8008exports.parseExternalUrl = parseExternalUrl;
8009exports.presets = index;
8010exports.toNumbers = toNumbers;
8011exports.trimLeft = trimLeft;
8012exports.trimRight = trimRight;
8013exports.vectorMagnitude = vectorMagnitude;
8014exports.vectorsAngle = vectorsAngle;
8015exports.vectorsRatio = vectorsRatio;
8016//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=