@antv/g-svg 1.8.18 → 1.8.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContextRegisterPlugin.d.ts.map +1 -1
- package/dist/SVGContextService.d.ts +4 -4
- package/dist/SVGContextService.d.ts.map +1 -1
- package/dist/index.esm.js +7 -17
- package/dist/index.js +6 -16
- package/dist/index.umd.js +1491 -1419
- package/dist/index.umd.min.js +4 -4
- package/package.json +5 -5
package/dist/index.umd.js
CHANGED
|
@@ -400,32 +400,6 @@
|
|
|
400
400
|
return _setPrototypeOf(o, p);
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
/******************************************************************************
|
|
404
|
-
Copyright (c) Microsoft Corporation.
|
|
405
|
-
|
|
406
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
407
|
-
purpose with or without fee is hereby granted.
|
|
408
|
-
|
|
409
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
410
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
411
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
412
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
413
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
414
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
415
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
416
|
-
***************************************************************************** */
|
|
417
|
-
|
|
418
|
-
function __decorate(decorators, target, key, desc) {
|
|
419
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
420
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
421
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
422
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function __param(paramIndex, decorator) {
|
|
426
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
427
|
-
}
|
|
428
|
-
|
|
429
403
|
function _regeneratorRuntime$1() {
|
|
430
404
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
431
405
|
_regeneratorRuntime$1 = function _regeneratorRuntime() {
|
|
@@ -825,29 +799,27 @@
|
|
|
825
799
|
return o;
|
|
826
800
|
};
|
|
827
801
|
return _setPrototypeOf$1(o, p);
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
var _class;
|
|
802
|
+
} // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
|
831
803
|
|
|
832
|
-
var DOMInteractionPlugin_1;
|
|
833
804
|
/**
|
|
834
805
|
* listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
|
|
835
806
|
*/
|
|
836
807
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
this.
|
|
841
|
-
this.contextService = contextService;
|
|
842
|
-
this.renderingContext = renderingContext;
|
|
808
|
+
|
|
809
|
+
var DOMInteractionPlugin = /*#__PURE__*/function () {
|
|
810
|
+
function DOMInteractionPlugin() {
|
|
811
|
+
this.context = void 0;
|
|
843
812
|
}
|
|
844
813
|
|
|
845
814
|
var _proto = DOMInteractionPlugin.prototype;
|
|
846
815
|
|
|
847
|
-
_proto.apply = function apply(
|
|
816
|
+
_proto.apply = function apply(context) {
|
|
848
817
|
var _this = this;
|
|
849
818
|
|
|
850
|
-
var
|
|
819
|
+
var renderingService = context.renderingService,
|
|
820
|
+
renderingContext = context.renderingContext;
|
|
821
|
+
this.context = context;
|
|
822
|
+
var canvas = renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
|
|
851
823
|
|
|
852
824
|
var onPointerMove = function onPointerMove(ev) {
|
|
853
825
|
renderingService.hooks.pointerMove.call(ev);
|
|
@@ -923,13 +895,13 @@
|
|
|
923
895
|
globalThis.removeEventListener('mouseup', onPointerUp, true);
|
|
924
896
|
};
|
|
925
897
|
|
|
926
|
-
renderingService.hooks.init.tapPromise(
|
|
898
|
+
renderingService.hooks.init.tapPromise(DOMInteractionPlugin.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
|
|
927
899
|
var $el;
|
|
928
900
|
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
929
901
|
while (1) {
|
|
930
902
|
switch (_context.prev = _context.next) {
|
|
931
903
|
case 0:
|
|
932
|
-
$el = _this.contextService.getDomElement(); // @ts-ignore
|
|
904
|
+
$el = _this.context.contextService.getDomElement(); // @ts-ignore
|
|
933
905
|
|
|
934
906
|
if (globalThis.navigator.msPointerEnabled) {
|
|
935
907
|
// @ts-ignore
|
|
@@ -964,8 +936,8 @@
|
|
|
964
936
|
}
|
|
965
937
|
}, _callee);
|
|
966
938
|
})));
|
|
967
|
-
renderingService.hooks.destroy.tap(
|
|
968
|
-
var $el = _this.contextService.getDomElement(); // @ts-ignore
|
|
939
|
+
renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
|
|
940
|
+
var $el = _this.context.contextService.getDomElement(); // @ts-ignore
|
|
969
941
|
|
|
970
942
|
|
|
971
943
|
if (globalThis.navigator.msPointerEnabled) {
|
|
@@ -992,13 +964,9 @@
|
|
|
992
964
|
};
|
|
993
965
|
|
|
994
966
|
return DOMInteractionPlugin;
|
|
995
|
-
}()
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
}), __param(0, gLite.inject(gLite.ContextService)), __param(1, gLite.inject(gLite.RenderingContext))], DOMInteractionPlugin);
|
|
999
|
-
var containerModule = gLite.Module(function (register) {
|
|
1000
|
-
register(DOMInteractionPlugin);
|
|
1001
|
-
});
|
|
967
|
+
}();
|
|
968
|
+
|
|
969
|
+
DOMInteractionPlugin.tag = 'DOMInteraction';
|
|
1002
970
|
|
|
1003
971
|
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
1004
972
|
_inheritsLoose$1(Plugin, _AbstractRendererPlug);
|
|
@@ -1018,11 +986,11 @@
|
|
|
1018
986
|
var _proto = Plugin.prototype;
|
|
1019
987
|
|
|
1020
988
|
_proto.init = function init() {
|
|
1021
|
-
this.
|
|
989
|
+
this.addRenderingPlugin(new DOMInteractionPlugin());
|
|
1022
990
|
};
|
|
1023
991
|
|
|
1024
992
|
_proto.destroy = function destroy() {
|
|
1025
|
-
this.
|
|
993
|
+
this.removeAllRenderingPlugins();
|
|
1026
994
|
};
|
|
1027
995
|
|
|
1028
996
|
return Plugin;
|
|
@@ -1918,1623 +1886,1741 @@
|
|
|
1918
1886
|
|
|
1919
1887
|
$el.setAttribute('d', d);
|
|
1920
1888
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
var FILTER_PREFIX = 'g-filter-';
|
|
1927
|
-
/**
|
|
1928
|
-
* use SVG filters, eg. blur, brightness, contrast...
|
|
1929
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
1889
|
+
/**
|
|
1890
|
+
* Common utilities
|
|
1891
|
+
* @module glMatrix
|
|
1930
1892
|
*/
|
|
1931
1893
|
|
|
1932
|
-
function createOrUpdateFilter(document, $def, object, $el, filters) {
|
|
1933
|
-
// eg. filter="url(#f1) url(#f2)"
|
|
1934
|
-
var filterName = FILTER_PREFIX + object.entity;
|
|
1935
|
-
var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
|
|
1936
|
-
|
|
1937
|
-
if ($existedFilters.length) {
|
|
1938
|
-
$existedFilters.forEach(function ($filter) {
|
|
1939
|
-
$def.removeChild($filter);
|
|
1940
|
-
});
|
|
1941
|
-
}
|
|
1942
1894
|
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
var filterIds = filters.map(function (_ref, i) {
|
|
1948
|
-
var name = _ref.name,
|
|
1949
|
-
params = _ref.params;
|
|
1950
|
-
var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
|
|
1895
|
+
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
1896
|
+
if (!Math.hypot) Math.hypot = function () {
|
|
1897
|
+
var y = 0,
|
|
1898
|
+
i = arguments.length;
|
|
1951
1899
|
|
|
1952
|
-
|
|
1900
|
+
while (i--) {
|
|
1901
|
+
y += arguments[i] * arguments[i];
|
|
1902
|
+
}
|
|
1953
1903
|
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
} else if (name === 'contrast') {
|
|
1961
|
-
createContrast(document, $filter, params);
|
|
1962
|
-
} else if (name === 'grayscale') {
|
|
1963
|
-
createGrayscale(document, $filter, params);
|
|
1964
|
-
} else if (name === 'sepia') {
|
|
1965
|
-
createSepia(document, $filter, params);
|
|
1966
|
-
} else if (name === 'saturate') {
|
|
1967
|
-
createSaturate(document, $filter, params);
|
|
1968
|
-
} else if (name === 'hue-rotate') {
|
|
1969
|
-
createHueRotate(document, $filter, params);
|
|
1970
|
-
} else if (name === 'invert') {
|
|
1971
|
-
createInvert(document, $filter, params);
|
|
1972
|
-
}
|
|
1904
|
+
return Math.sqrt(y);
|
|
1905
|
+
};
|
|
1906
|
+
/**
|
|
1907
|
+
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
1908
|
+
* @module mat4
|
|
1909
|
+
*/
|
|
1973
1910
|
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1911
|
+
/**
|
|
1912
|
+
* Creates a new identity mat4
|
|
1913
|
+
*
|
|
1914
|
+
* @returns {mat4} a new 4x4 matrix
|
|
1915
|
+
*/
|
|
1979
1916
|
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1917
|
+
function create() {
|
|
1918
|
+
var out = new ARRAY_TYPE(16);
|
|
1919
|
+
|
|
1920
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1921
|
+
out[1] = 0;
|
|
1922
|
+
out[2] = 0;
|
|
1923
|
+
out[3] = 0;
|
|
1924
|
+
out[4] = 0;
|
|
1925
|
+
out[6] = 0;
|
|
1926
|
+
out[7] = 0;
|
|
1927
|
+
out[8] = 0;
|
|
1928
|
+
out[9] = 0;
|
|
1929
|
+
out[11] = 0;
|
|
1930
|
+
out[12] = 0;
|
|
1931
|
+
out[13] = 0;
|
|
1932
|
+
out[14] = 0;
|
|
1985
1933
|
}
|
|
1986
|
-
}
|
|
1987
1934
|
|
|
1988
|
-
|
|
1989
|
-
|
|
1935
|
+
out[0] = 1;
|
|
1936
|
+
out[5] = 1;
|
|
1937
|
+
out[10] = 1;
|
|
1938
|
+
out[15] = 1;
|
|
1939
|
+
return out;
|
|
1990
1940
|
}
|
|
1991
|
-
/**
|
|
1992
|
-
*
|
|
1941
|
+
/**
|
|
1942
|
+
* Inverts a mat4
|
|
1943
|
+
*
|
|
1944
|
+
* @param {mat4} out the receiving matrix
|
|
1945
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
1946
|
+
* @returns {mat4} out
|
|
1993
1947
|
*/
|
|
1994
1948
|
|
|
1995
1949
|
|
|
1996
|
-
function
|
|
1997
|
-
var
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
1950
|
+
function invert(out, a) {
|
|
1951
|
+
var a00 = a[0],
|
|
1952
|
+
a01 = a[1],
|
|
1953
|
+
a02 = a[2],
|
|
1954
|
+
a03 = a[3];
|
|
1955
|
+
var a10 = a[4],
|
|
1956
|
+
a11 = a[5],
|
|
1957
|
+
a12 = a[6],
|
|
1958
|
+
a13 = a[7];
|
|
1959
|
+
var a20 = a[8],
|
|
1960
|
+
a21 = a[9],
|
|
1961
|
+
a22 = a[10],
|
|
1962
|
+
a23 = a[11];
|
|
1963
|
+
var a30 = a[12],
|
|
1964
|
+
a31 = a[13],
|
|
1965
|
+
a32 = a[14],
|
|
1966
|
+
a33 = a[15];
|
|
1967
|
+
var b00 = a00 * a11 - a01 * a10;
|
|
1968
|
+
var b01 = a00 * a12 - a02 * a10;
|
|
1969
|
+
var b02 = a00 * a13 - a03 * a10;
|
|
1970
|
+
var b03 = a01 * a12 - a02 * a11;
|
|
1971
|
+
var b04 = a01 * a13 - a03 * a11;
|
|
1972
|
+
var b05 = a02 * a13 - a03 * a12;
|
|
1973
|
+
var b06 = a20 * a31 - a21 * a30;
|
|
1974
|
+
var b07 = a20 * a32 - a22 * a30;
|
|
1975
|
+
var b08 = a20 * a33 - a23 * a30;
|
|
1976
|
+
var b09 = a21 * a32 - a22 * a31;
|
|
1977
|
+
var b10 = a21 * a33 - a23 * a31;
|
|
1978
|
+
var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
|
|
1979
|
+
|
|
1980
|
+
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
1981
|
+
|
|
1982
|
+
if (!det) {
|
|
1983
|
+
return null;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
det = 1.0 / det;
|
|
1987
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
1988
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
1989
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
1990
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
1991
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
1992
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
1993
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
1994
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
1995
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
1996
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
1997
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
1998
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
1999
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
2000
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
2001
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
2002
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
2003
|
+
return out;
|
|
2001
2004
|
}
|
|
2002
2005
|
|
|
2003
|
-
function
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
intercept = _ref2.intercept,
|
|
2007
|
-
tableValues = _ref2.tableValues;
|
|
2008
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2009
|
-
[createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
|
|
2010
|
-
$feFunc.setAttribute('type', type);
|
|
2006
|
+
function createSVGElement(type, doc) {
|
|
2007
|
+
return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
|
|
2008
|
+
}
|
|
2011
2009
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2010
|
+
function numberToLongString(x) {
|
|
2011
|
+
return x.toFixed(6).replace('.000000', '');
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
function convertHTML(str) {
|
|
2015
|
+
var regex = /[&|<|>|"|']/g;
|
|
2016
|
+
return str.replace(regex, function (match) {
|
|
2017
|
+
if (match === '&') {
|
|
2018
|
+
return '&';
|
|
2019
|
+
} else if (match === '<') {
|
|
2020
|
+
return '<';
|
|
2021
|
+
} else if (match === '>') {
|
|
2022
|
+
return '>';
|
|
2023
|
+
} else if (match === '"') {
|
|
2024
|
+
return '"';
|
|
2014
2025
|
} else {
|
|
2015
|
-
|
|
2016
|
-
$feFunc.setAttribute('intercept', "" + intercept);
|
|
2026
|
+
return ''';
|
|
2017
2027
|
}
|
|
2018
|
-
|
|
2019
|
-
$feComponentTransfer.appendChild($feFunc);
|
|
2020
2028
|
});
|
|
2021
|
-
$filter.appendChild($feComponentTransfer);
|
|
2022
2029
|
}
|
|
2023
2030
|
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2031
|
+
var SVG_ATTR_MAP = {
|
|
2032
|
+
opacity: 'opacity',
|
|
2033
|
+
fillStyle: 'fill',
|
|
2034
|
+
fill: 'fill',
|
|
2035
|
+
fillRule: 'fill-rule',
|
|
2036
|
+
fillOpacity: 'fill-opacity',
|
|
2037
|
+
strokeStyle: 'stroke',
|
|
2038
|
+
strokeOpacity: 'stroke-opacity',
|
|
2039
|
+
stroke: 'stroke',
|
|
2040
|
+
clipPath: 'clip-path',
|
|
2041
|
+
textPath: 'text-path',
|
|
2042
|
+
r: 'r',
|
|
2043
|
+
rx: 'rx',
|
|
2044
|
+
ry: 'ry',
|
|
2045
|
+
width: 'width',
|
|
2046
|
+
height: 'height',
|
|
2047
|
+
lineCap: 'stroke-linecap',
|
|
2048
|
+
lineJoin: 'stroke-linejoin',
|
|
2049
|
+
lineWidth: 'stroke-width',
|
|
2050
|
+
lineDash: 'stroke-dasharray',
|
|
2051
|
+
lineDashOffset: 'stroke-dashoffset',
|
|
2052
|
+
miterLimit: 'stroke-miterlimit',
|
|
2053
|
+
font: 'font',
|
|
2054
|
+
fontSize: 'font-size',
|
|
2055
|
+
fontStyle: 'font-style',
|
|
2056
|
+
fontVariant: 'font-variant',
|
|
2057
|
+
fontWeight: 'font-weight',
|
|
2058
|
+
fontFamily: 'font-family',
|
|
2059
|
+
letterSpacing: 'letter-spacing',
|
|
2060
|
+
startArrow: 'marker-start',
|
|
2061
|
+
endArrow: 'marker-end',
|
|
2062
|
+
class: 'class',
|
|
2063
|
+
id: 'id',
|
|
2064
|
+
// style: 'style',
|
|
2065
|
+
preserveAspectRatio: 'preserveAspectRatio',
|
|
2066
|
+
visibility: 'visibility',
|
|
2067
|
+
anchor: 'anchor',
|
|
2068
|
+
shadowColor: 'flood-color',
|
|
2069
|
+
shadowBlur: 'stdDeviation',
|
|
2070
|
+
shadowOffsetX: 'dx',
|
|
2071
|
+
shadowOffsetY: 'dy',
|
|
2072
|
+
filter: 'filter',
|
|
2073
|
+
innerHTML: 'innerHTML',
|
|
2074
|
+
textAlign: 'text-anchor',
|
|
2075
|
+
pointerEvents: 'pointer-events'
|
|
2076
|
+
};
|
|
2077
|
+
var FORMAT_VALUE_MAP = {
|
|
2078
|
+
textAlign: {
|
|
2079
|
+
inherit: 'inherit',
|
|
2080
|
+
left: 'left',
|
|
2081
|
+
start: 'left',
|
|
2082
|
+
center: 'middle',
|
|
2083
|
+
right: 'end',
|
|
2084
|
+
end: 'end'
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
var DEFAULT_VALUE_MAP = {
|
|
2088
|
+
textAlign: 'inherit',
|
|
2089
|
+
// textBaseline: 'alphabetic',
|
|
2090
|
+
// @see https://www.w3.org/TR/SVG/painting.html#LineCaps
|
|
2091
|
+
lineCap: 'butt',
|
|
2092
|
+
// @see https://www.w3.org/TR/SVG/painting.html#LineJoin
|
|
2093
|
+
lineJoin: 'miter',
|
|
2094
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
|
|
2095
|
+
lineWidth: '1px',
|
|
2096
|
+
opacity: '1',
|
|
2097
|
+
fillOpacity: '1',
|
|
2098
|
+
fillRule: 'nonzero',
|
|
2099
|
+
strokeOpacity: '1',
|
|
2100
|
+
strokeWidth: '0',
|
|
2101
|
+
strokeMiterLimit: '4',
|
|
2102
|
+
letterSpacing: '0',
|
|
2103
|
+
fontSize: 'inherit',
|
|
2104
|
+
fontFamily: 'inherit',
|
|
2105
|
+
pointerEvents: 'auto'
|
|
2106
|
+
};
|
|
2107
|
+
/**
|
|
2108
|
+
* G_SVG_PREFIX + nodeName + entity
|
|
2109
|
+
*
|
|
2110
|
+
* eg. g_svg_circle_345
|
|
2111
|
+
*/
|
|
2032
2112
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
type: 'table',
|
|
2037
|
-
tableValues: amount + " " + (1 - amount)
|
|
2038
|
-
});
|
|
2039
|
-
}
|
|
2113
|
+
var G_SVG_PREFIX = 'g_svg';
|
|
2114
|
+
var CLIP_PATH_PREFIX = 'clip-path-';
|
|
2115
|
+
var TEXT_PATH_PREFIX = 'text-path-';
|
|
2040
2116
|
|
|
2041
|
-
function
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2117
|
+
var SVGRendererPlugin = /*#__PURE__*/function () {
|
|
2118
|
+
function SVGRendererPlugin(pluginOptions, defElementManager, context) {
|
|
2119
|
+
this.pluginOptions = void 0;
|
|
2120
|
+
this.defElementManager = void 0;
|
|
2121
|
+
this.context = void 0;
|
|
2122
|
+
this.$camera = void 0;
|
|
2123
|
+
this.renderQueue = [];
|
|
2124
|
+
this.dirtyAttributes = new WeakMap();
|
|
2125
|
+
this.pendingReorderQueue = new Set();
|
|
2126
|
+
this.clipPathUseMap = new WeakMap();
|
|
2127
|
+
this.pluginOptions = pluginOptions;
|
|
2128
|
+
this.defElementManager = defElementManager;
|
|
2129
|
+
this.context = context;
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* <camera>
|
|
2133
|
+
*/
|
|
2049
2134
|
|
|
2050
|
-
function createSaturate(document, $filter, params) {
|
|
2051
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2052
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2053
|
-
$feColorMatrix.setAttribute('type', 'saturate');
|
|
2054
|
-
$feColorMatrix.setAttribute('values', "" + amount);
|
|
2055
|
-
$filter.appendChild($feColorMatrix);
|
|
2056
|
-
}
|
|
2057
2135
|
|
|
2058
|
-
|
|
2059
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2060
|
-
$feColorMatrix.setAttribute('type', 'hueRotate');
|
|
2061
|
-
$feColorMatrix.setAttribute('values', "" + params[0].to(gLite.UnitType.kDegrees).value);
|
|
2062
|
-
$filter.appendChild($feColorMatrix);
|
|
2063
|
-
}
|
|
2136
|
+
var _proto = SVGRendererPlugin.prototype;
|
|
2064
2137
|
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
var shadowOffsetY = params[1].value;
|
|
2068
|
-
var shadowBlur = params[2].value; // @ts-ignore
|
|
2069
|
-
|
|
2070
|
-
var shadowColor = params[3].formatted;
|
|
2071
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2072
|
-
$feGaussianBlur.setAttribute('in', 'SourceAlpha');
|
|
2073
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
|
|
2074
|
-
$filter.appendChild($feGaussianBlur);
|
|
2075
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2076
|
-
$feOffset.setAttribute('dx', "" + shadowOffsetX);
|
|
2077
|
-
$feOffset.setAttribute('dy', "" + shadowOffsetY);
|
|
2078
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2079
|
-
$filter.appendChild($feOffset);
|
|
2080
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2081
|
-
$feFlood.setAttribute('flood-color', shadowColor);
|
|
2082
|
-
$filter.appendChild($feFlood);
|
|
2083
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2084
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2085
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2086
|
-
$filter.appendChild($feComposite);
|
|
2087
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2088
|
-
$filter.appendChild($feMerge);
|
|
2089
|
-
var $feMergeNode1 = createSVGElement('feMergeNode', document);
|
|
2090
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2091
|
-
$feMergeNode2.setAttribute('in', 'SourceGraphic');
|
|
2092
|
-
$feMerge.appendChild($feMergeNode1);
|
|
2093
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
function createFeColorMatrix(document, $filter, matrix) {
|
|
2097
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2098
|
-
$feColorMatrix.setAttribute('type', 'matrix');
|
|
2099
|
-
$feColorMatrix.setAttribute('values', matrix.join(' '));
|
|
2100
|
-
$filter.appendChild($feColorMatrix);
|
|
2101
|
-
}
|
|
2102
|
-
/**
|
|
2103
|
-
* @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
|
|
2104
|
-
*/
|
|
2138
|
+
_proto.apply = function apply(context) {
|
|
2139
|
+
var _this = this;
|
|
2105
2140
|
|
|
2141
|
+
var renderingService = context.renderingService,
|
|
2142
|
+
renderingContext = context.renderingContext;
|
|
2143
|
+
this.context = context;
|
|
2144
|
+
var document = this.context.config.document;
|
|
2106
2145
|
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
|
|
2113
|
-
*/
|
|
2146
|
+
var handleMounted = function handleMounted(e) {
|
|
2147
|
+
var object = e.target; // create SVG DOM Node
|
|
2114
2148
|
|
|
2149
|
+
_this.createSVGDom(document, object, _this.$camera);
|
|
2150
|
+
};
|
|
2115
2151
|
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
|
|
2119
|
-
}
|
|
2152
|
+
var handleUnmounted = function handleUnmounted(e) {
|
|
2153
|
+
var object = e.target;
|
|
2120
2154
|
|
|
2121
|
-
|
|
2122
|
-
var cacheKey2IDMap = {};
|
|
2123
|
-
var counter = 0;
|
|
2155
|
+
_this.defElementManager.clear(object.entity);
|
|
2124
2156
|
|
|
2125
|
-
|
|
2126
|
-
// eg. clipPath don't have fill/stroke
|
|
2127
|
-
if (!parsedColor) {
|
|
2128
|
-
return '';
|
|
2129
|
-
}
|
|
2157
|
+
_this.clipPathUseMap.delete(object);
|
|
2130
2158
|
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
if (object.style[name] === 'currentColor') {
|
|
2134
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
|
|
2135
|
-
} else {
|
|
2136
|
-
// constant value, eg. '#fff'
|
|
2137
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
|
|
2138
|
-
}
|
|
2139
|
-
} else if (gLite.isPattern(parsedColor)) {
|
|
2140
|
-
var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage); // use style instead of attribute when applying <pattern>
|
|
2141
|
-
// @see https://stackoverflow.com/a/7723115
|
|
2159
|
+
_this.removeSVGDom(object);
|
|
2160
|
+
};
|
|
2142
2161
|
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
if (parsedColor.length === 1) {
|
|
2147
|
-
var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
|
|
2148
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
|
|
2149
|
-
return gradientId;
|
|
2150
|
-
} else {
|
|
2151
|
-
// @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
|
|
2152
|
-
var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
|
|
2153
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
|
|
2154
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
|
|
2155
|
-
return filterId;
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2162
|
+
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
2163
|
+
var object = e.target; // @see https://github.com/antvis/g/issues/994
|
|
2164
|
+
// @ts-ignore
|
|
2158
2165
|
|
|
2159
|
-
|
|
2160
|
-
|
|
2166
|
+
if (!object.elementSVG) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2161
2169
|
|
|
2162
|
-
|
|
2163
|
-
if (options === void 0) {
|
|
2164
|
-
options = {};
|
|
2165
|
-
}
|
|
2170
|
+
var attrName = e.attrName;
|
|
2166
2171
|
|
|
2167
|
-
|
|
2172
|
+
var attribtues = _this.dirtyAttributes.get(object);
|
|
2168
2173
|
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
value = src.value;
|
|
2174
|
+
if (!attribtues) {
|
|
2175
|
+
_this.dirtyAttributes.set(object, []);
|
|
2172
2176
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
var _value$options = _extends({}, value, options),
|
|
2176
|
-
_type = _value$options.type,
|
|
2177
|
-
width = _value$options.width,
|
|
2178
|
-
height = _value$options.height,
|
|
2179
|
-
steps = _value$options.steps,
|
|
2180
|
-
angle = _value$options.angle,
|
|
2181
|
-
cx = _value$options.cx,
|
|
2182
|
-
cy = _value$options.cy,
|
|
2183
|
-
size = _value$options.size;
|
|
2177
|
+
attribtues = _this.dirtyAttributes.get(object);
|
|
2178
|
+
}
|
|
2184
2179
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
color = _ref.color;
|
|
2188
|
-
return "" + offset + color;
|
|
2189
|
-
}).join('-');
|
|
2190
|
-
}
|
|
2191
|
-
} else if (gLite.isPattern(src)) {
|
|
2192
|
-
if (isString(src.image)) {
|
|
2193
|
-
cacheKey = "pattern-" + src.image + "-" + src.repetition;
|
|
2194
|
-
} else {
|
|
2195
|
-
cacheKey = "pattern-" + counter;
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2180
|
+
attribtues.push(attrName);
|
|
2181
|
+
};
|
|
2198
2182
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2183
|
+
var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
|
|
2184
|
+
var _object$elementSVG;
|
|
2204
2185
|
|
|
2205
|
-
|
|
2206
|
-
}
|
|
2186
|
+
var object = e.target; // @ts-ignore
|
|
2207
2187
|
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2188
|
+
var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
|
|
2189
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
2190
|
+
fill = _object$parsedStyle.fill,
|
|
2191
|
+
stroke = _object$parsedStyle.stroke;
|
|
2211
2192
|
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
var imageURL = '';
|
|
2193
|
+
if (fill && !(fill instanceof gLite.CSSRGB)) {
|
|
2194
|
+
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill');
|
|
2195
|
+
}
|
|
2216
2196
|
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
} else {
|
|
2220
|
-
if (gLite.isBrowser) {
|
|
2221
|
-
if (image instanceof HTMLImageElement) {
|
|
2222
|
-
imageURL = image.src;
|
|
2223
|
-
} else if (image instanceof HTMLCanvasElement) {
|
|
2224
|
-
imageURL = image.toDataURL();
|
|
2225
|
-
} else ;
|
|
2197
|
+
if (stroke && !(stroke instanceof gLite.CSSRGB)) {
|
|
2198
|
+
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke');
|
|
2226
2199
|
}
|
|
2227
|
-
}
|
|
2200
|
+
};
|
|
2228
2201
|
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
var $pattern = createSVGElement('pattern', document);
|
|
2232
|
-
$pattern.setAttribute('patternUnits', 'userSpaceOnUse');
|
|
2233
|
-
var $image = createSVGElement('image', document);
|
|
2234
|
-
$pattern.appendChild($image);
|
|
2235
|
-
$pattern.id = patternId;
|
|
2236
|
-
$def.appendChild($pattern); // use href instead of xlink:href
|
|
2237
|
-
// @see https://stackoverflow.com/a/13379007
|
|
2202
|
+
renderingService.hooks.init.tapPromise(SVGRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
|
|
2203
|
+
var _this$context$config, background, document, $svg;
|
|
2238
2204
|
|
|
2239
|
-
$
|
|
2240
|
-
|
|
2205
|
+
return _regeneratorRuntime$2().wrap(function _callee$(_context) {
|
|
2206
|
+
while (1) {
|
|
2207
|
+
switch (_context.prev = _context.next) {
|
|
2208
|
+
case 0:
|
|
2209
|
+
_this$context$config = _this.context.config, background = _this$context$config.background, document = _this$context$config.document; // <defs>
|
|
2241
2210
|
|
|
2242
|
-
|
|
2243
|
-
img = createImage(imageURL);
|
|
2244
|
-
} else if (gLite.isBrowser) {
|
|
2245
|
-
img = new window.Image();
|
|
2246
|
-
}
|
|
2211
|
+
_this.defElementManager.init();
|
|
2247
2212
|
|
|
2248
|
-
|
|
2249
|
-
img.crossOrigin = 'Anonymous';
|
|
2250
|
-
$image.setAttribute('crossorigin', 'anonymous');
|
|
2251
|
-
}
|
|
2213
|
+
$svg = _this.context.contextService.getContext();
|
|
2252
2214
|
|
|
2253
|
-
|
|
2215
|
+
if (background) {
|
|
2216
|
+
$svg.style.background = background;
|
|
2217
|
+
} // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
|
|
2254
2218
|
|
|
2255
|
-
var onload = function onload() {
|
|
2256
|
-
$pattern.setAttribute('x', '0');
|
|
2257
|
-
$pattern.setAttribute('y', '0');
|
|
2258
2219
|
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2220
|
+
$svg.setAttribute('color-interpolation-filters', 'sRGB');
|
|
2221
|
+
_this.$camera = createSVGElement('g', document);
|
|
2222
|
+
_this.$camera.id = G_SVG_PREFIX + "_camera";
|
|
2262
2223
|
|
|
2224
|
+
_this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
|
|
2263
2225
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2226
|
+
$svg.appendChild(_this.$camera);
|
|
2227
|
+
renderingContext.root.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
2228
|
+
renderingContext.root.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
2229
|
+
renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
2230
|
+
renderingContext.root.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
|
|
2266
2231
|
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
} else if (repetition === 'no-repeat') {
|
|
2272
|
-
patternWidth = halfExtents[0] * 2;
|
|
2273
|
-
patternHeight = halfExtents[1] * 2;
|
|
2232
|
+
case 13:
|
|
2233
|
+
case "end":
|
|
2234
|
+
return _context.stop();
|
|
2235
|
+
}
|
|
2274
2236
|
}
|
|
2237
|
+
}, _callee);
|
|
2238
|
+
})));
|
|
2239
|
+
renderingService.hooks.destroy.tap(SVGRendererPlugin.tag, function () {
|
|
2240
|
+
renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
2241
|
+
renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
2242
|
+
renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
2243
|
+
renderingContext.root.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
|
|
2244
|
+
});
|
|
2245
|
+
renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
|
|
2246
|
+
// if (!object.isCulled()) {
|
|
2247
|
+
_this.renderQueue.push(object); // }
|
|
2275
2248
|
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
$image.setAttribute('y', '0');
|
|
2280
|
-
$image.setAttribute('width', "" + img.width);
|
|
2281
|
-
$image.setAttribute('height', "" + img.height);
|
|
2282
|
-
};
|
|
2283
|
-
|
|
2284
|
-
if (img.complete) {
|
|
2285
|
-
onload();
|
|
2286
|
-
} else {
|
|
2287
|
-
img.onload = onload; // Fix onload() bug in IE9
|
|
2249
|
+
});
|
|
2250
|
+
renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
|
|
2251
|
+
var doc = _this.context.config.document;
|
|
2288
2252
|
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
}
|
|
2253
|
+
if (_this.pendingReorderQueue.size) {
|
|
2254
|
+
_this.pendingReorderQueue.forEach(function (object) {
|
|
2255
|
+
var _object$elementSVG2;
|
|
2293
2256
|
|
|
2294
|
-
|
|
2295
|
-
|
|
2257
|
+
var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
|
|
2258
|
+
var $parentGroupEl = // @ts-ignore
|
|
2259
|
+
object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
|
|
2296
2260
|
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
var gradientId = generateCacheKey(parsedColor, {
|
|
2302
|
-
width: width,
|
|
2303
|
-
height: height
|
|
2304
|
-
});
|
|
2305
|
-
var $existed = $def.querySelector("#" + gradientId);
|
|
2261
|
+
if ($parentGroupEl) {
|
|
2262
|
+
_this.reorderChildren(doc || document, $parentGroupEl, children || []);
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2306
2265
|
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2266
|
+
_this.pendingReorderQueue.clear();
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
renderingService.hooks.endFrame.tap(SVGRendererPlugin.tag, function () {
|
|
2270
|
+
if (renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
|
|
2271
|
+
_this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
|
|
2272
|
+
}
|
|
2312
2273
|
|
|
2313
|
-
|
|
2274
|
+
_this.renderQueue.forEach(function (object) {
|
|
2275
|
+
var _object$elementSVG3, _object$elementSVG4; // @ts-ignore
|
|
2314
2276
|
|
|
2315
|
-
var innerHTML = '';
|
|
2316
|
-
parsedColor.value.steps // sort by offset @see https://github.com/antvis/G/issues/1171
|
|
2317
|
-
.sort(function (a, b) {
|
|
2318
|
-
return a.offset.value - b.offset.value;
|
|
2319
|
-
}).forEach(function (_ref2) {
|
|
2320
|
-
var offset = _ref2.offset,
|
|
2321
|
-
color = _ref2.color; // TODO: support absolute unit like `px`
|
|
2322
2277
|
|
|
2323
|
-
|
|
2324
|
-
});
|
|
2325
|
-
$existed.innerHTML = innerHTML;
|
|
2326
|
-
$existed.id = gradientId;
|
|
2327
|
-
$def.appendChild($existed);
|
|
2328
|
-
}
|
|
2278
|
+
var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el; // @ts-ignore
|
|
2329
2279
|
|
|
2330
|
-
|
|
2331
|
-
var angle = parsedColor.value.angle;
|
|
2280
|
+
var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
|
|
2332
2281
|
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
y2 = _computeLinearGradien.y2;
|
|
2282
|
+
if ($el && $groupEl) {
|
|
2283
|
+
// apply local RTS transformation to <group> wrapper
|
|
2284
|
+
// account for anchor
|
|
2285
|
+
var localTransform = object.getLocalTransform();
|
|
2338
2286
|
|
|
2339
|
-
|
|
2340
|
-
$existed.setAttribute('y1', "" + y1);
|
|
2341
|
-
$existed.setAttribute('x2', "" + x2);
|
|
2342
|
-
$existed.setAttribute('y2', "" + y2); // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
|
|
2343
|
-
} else {
|
|
2344
|
-
var _parsedColor$value = parsedColor.value,
|
|
2345
|
-
cx = _parsedColor$value.cx,
|
|
2346
|
-
cy = _parsedColor$value.cy,
|
|
2347
|
-
size = _parsedColor$value.size;
|
|
2287
|
+
_this.applyTransform($groupEl, localTransform); // clipped shapes should also be informed
|
|
2348
2288
|
|
|
2349
|
-
var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
|
|
2350
|
-
x = _computeRadialGradien.x,
|
|
2351
|
-
y = _computeRadialGradien.y,
|
|
2352
|
-
r = _computeRadialGradien.r;
|
|
2353
2289
|
|
|
2354
|
-
|
|
2355
|
-
$existed.setAttribute('cy', "" + y);
|
|
2356
|
-
$existed.setAttribute('r', "" + r);
|
|
2357
|
-
}
|
|
2290
|
+
var $useRefs = _this.clipPathUseMap.get(object);
|
|
2358
2291
|
|
|
2359
|
-
|
|
2360
|
-
|
|
2292
|
+
if ($useRefs && $useRefs.length) {
|
|
2293
|
+
$useRefs.forEach(function ($use) {
|
|
2294
|
+
_this.applyTransform($use, localTransform);
|
|
2295
|
+
});
|
|
2296
|
+
} // finish rendering, clear dirty flag
|
|
2361
2297
|
|
|
2362
|
-
function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
|
|
2363
|
-
var filterId = FILTER_PREFIX + object.entity + '-gradient';
|
|
2364
|
-
var $existed = $def.querySelector("#" + filterId);
|
|
2365
2298
|
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
$existed.setAttribute('filterUnits', 'userSpaceOnUse'); // @see https://github.com/antvis/g/issues/1025
|
|
2299
|
+
object.renderable.dirty = false;
|
|
2300
|
+
} // update dirty attributes
|
|
2369
2301
|
|
|
2370
|
-
$existed.setAttribute('x', '0%');
|
|
2371
|
-
$existed.setAttribute('y', '0%');
|
|
2372
|
-
$existed.setAttribute('width', '100%');
|
|
2373
|
-
$existed.setAttribute('height', '100%');
|
|
2374
|
-
$existed.id = filterId;
|
|
2375
|
-
$def.appendChild($existed);
|
|
2376
|
-
}
|
|
2377
|
-
/**
|
|
2378
|
-
* <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
|
|
2379
|
-
* <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
|
|
2380
|
-
<feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
|
|
2381
|
-
<feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
|
|
2382
|
-
<feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
|
|
2383
|
-
<feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
|
|
2384
|
-
</filter>
|
|
2385
|
-
*/
|
|
2386
2302
|
|
|
2303
|
+
var attributes = _this.dirtyAttributes.get(object);
|
|
2387
2304
|
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
var $rect = createSVGElement('rect', document);
|
|
2393
|
-
$rect.setAttribute('x', '0');
|
|
2394
|
-
$rect.setAttribute('y', '0');
|
|
2395
|
-
$rect.setAttribute('width', '100%');
|
|
2396
|
-
$rect.setAttribute('height', '100%');
|
|
2397
|
-
$rect.setAttribute('fill', "url(#" + gradientId + ")");
|
|
2398
|
-
$rect.id = rectId;
|
|
2399
|
-
$def.appendChild($rect);
|
|
2400
|
-
var $feImage = createSVGElement('feImage', document);
|
|
2401
|
-
$feImage.setAttribute('href', "#" + rectId);
|
|
2402
|
-
$feImage.setAttribute('result', filterId + "-" + i);
|
|
2403
|
-
$existed.appendChild($feImage);
|
|
2305
|
+
if (attributes) {
|
|
2306
|
+
attributes.forEach(function (attrName) {
|
|
2307
|
+
if (attrName === 'zIndex') {
|
|
2308
|
+
var _object$parentNode, _object$parentNode$el;
|
|
2404
2309
|
|
|
2405
|
-
|
|
2406
|
-
var $feBlend = createSVGElement('feBlend', document);
|
|
2407
|
-
$feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
|
|
2408
|
-
$feBlend.setAttribute('in2', filterId + "-" + i);
|
|
2409
|
-
$feBlend.setAttribute('result', filterId + "-blended-" + blended++); // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
|
|
2310
|
+
var parent = object.parentNode; // @ts-ignore
|
|
2410
2311
|
|
|
2411
|
-
|
|
2412
|
-
$existed.appendChild($feBlend);
|
|
2413
|
-
}
|
|
2414
|
-
});
|
|
2415
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2416
|
-
$feComposite.setAttribute('in', filterId + "-blended-" + blended);
|
|
2417
|
-
$feComposite.setAttribute('in2', 'SourceGraphic');
|
|
2418
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2419
|
-
$existed.appendChild($feComposite);
|
|
2420
|
-
return filterId;
|
|
2421
|
-
}
|
|
2312
|
+
var _$groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
|
|
2422
2313
|
|
|
2423
|
-
|
|
2424
|
-
/**
|
|
2425
|
-
* use SVG filters
|
|
2426
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2427
|
-
*/
|
|
2314
|
+
var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
|
|
2428
2315
|
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
2436
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
2437
|
-
var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
|
|
2438
|
-
var $existedFilter = $def.querySelector("#" + shadowId);
|
|
2316
|
+
if (_$groupEl) {
|
|
2317
|
+
_this.reorderChildren(document, _$groupEl, children);
|
|
2318
|
+
}
|
|
2319
|
+
} else if (attrName === 'increasedLineWidthForHitTesting') {
|
|
2320
|
+
_this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
2321
|
+
}
|
|
2439
2322
|
|
|
2440
|
-
|
|
2441
|
-
|
|
2323
|
+
_this.updateAttribute(object, [attrName]);
|
|
2324
|
+
});
|
|
2442
2325
|
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
$existedFilter = null;
|
|
2447
|
-
}
|
|
2448
|
-
} // <Group> also has shadowType as its default value
|
|
2449
|
-
// only apply shadow when blur > 0
|
|
2326
|
+
_this.dirtyAttributes.delete(object);
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2450
2329
|
|
|
2330
|
+
_this.renderQueue = [];
|
|
2331
|
+
});
|
|
2332
|
+
};
|
|
2451
2333
|
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
|
|
2456
|
-
} else {
|
|
2457
|
-
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2458
|
-
return;
|
|
2459
|
-
}
|
|
2334
|
+
_proto.getId = function getId(object) {
|
|
2335
|
+
return G_SVG_PREFIX + "_" + object.nodeName + "_" + object.entity;
|
|
2336
|
+
};
|
|
2460
2337
|
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2338
|
+
_proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
|
|
2339
|
+
// need to reorder parent's children
|
|
2340
|
+
children.sort(function (a, b) {
|
|
2341
|
+
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
2342
|
+
});
|
|
2464
2343
|
|
|
2465
|
-
if (
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
} else if (shadowType === 'inner') {
|
|
2473
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2474
|
-
$feComponentTransfer.setAttribute('in', 'SourceAlpha');
|
|
2475
|
-
var $feFuncA = createSVGElement('feFuncA', document);
|
|
2476
|
-
$feFuncA.setAttribute('type', 'table');
|
|
2477
|
-
$feFuncA.setAttribute('tableValues', '1 0');
|
|
2478
|
-
$feComponentTransfer.appendChild($feFuncA);
|
|
2479
|
-
$existedFilter.appendChild($feComponentTransfer);
|
|
2480
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2481
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2482
|
-
$existedFilter.appendChild($feGaussianBlur);
|
|
2483
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2484
|
-
$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2485
|
-
$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2486
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2487
|
-
$existedFilter.appendChild($feOffset);
|
|
2488
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2489
|
-
$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
2490
|
-
$feFlood.setAttribute('result', 'color');
|
|
2491
|
-
$existedFilter.appendChild($feFlood);
|
|
2492
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2493
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2494
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2495
|
-
$existedFilter.appendChild($feComposite);
|
|
2496
|
-
var $feComposite2 = createSVGElement('feComposite', document);
|
|
2497
|
-
$feComposite2.setAttribute('in2', 'SourceAlpha');
|
|
2498
|
-
$feComposite2.setAttribute('operator', 'in');
|
|
2499
|
-
$existedFilter.appendChild($feComposite2);
|
|
2500
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2501
|
-
$existedFilter.appendChild($feMerge);
|
|
2502
|
-
var $feMergeNode = createSVGElement('feMergeNode', document);
|
|
2503
|
-
$feMergeNode.setAttribute('in', 'SourceGraphic');
|
|
2504
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2505
|
-
$feMerge.appendChild($feMergeNode);
|
|
2506
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2507
|
-
}
|
|
2344
|
+
if (children.length) {
|
|
2345
|
+
// create empty fragment
|
|
2346
|
+
var fragment = (doc || document).createDocumentFragment();
|
|
2347
|
+
children.forEach(function (child) {
|
|
2348
|
+
if (child.isConnected) {
|
|
2349
|
+
// @ts-ignore
|
|
2350
|
+
var $el = child.elementSVG.$groupEl;
|
|
2508
2351
|
|
|
2509
|
-
|
|
2352
|
+
if ($el) {
|
|
2353
|
+
fragment.appendChild($el);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
$groupEl.appendChild(fragment);
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2510
2360
|
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2361
|
+
_proto.applyTransform = function applyTransform($el, rts) {
|
|
2362
|
+
// use proper precision avoiding too long string in `transform`
|
|
2363
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
2364
|
+
$el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
|
|
2365
|
+
};
|
|
2515
2366
|
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
var
|
|
2519
|
-
var
|
|
2367
|
+
_proto.applyAttributes = function applyAttributes(object) {
|
|
2368
|
+
// @ts-ignore
|
|
2369
|
+
var elementSVG = object.elementSVG;
|
|
2370
|
+
var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
|
|
2371
|
+
var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
|
|
2520
2372
|
|
|
2521
|
-
if (
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
2526
|
-
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
2527
|
-
_$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2528
|
-
} else if (name === 'shadowOffsetX') {
|
|
2529
|
-
_$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2530
|
-
} else if (name === 'shadowOffsetY') {
|
|
2531
|
-
_$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2532
|
-
}
|
|
2533
|
-
} else if (shadowType === 'outer') {
|
|
2534
|
-
var _$feDropShadow = $existedFilter.children[0];
|
|
2373
|
+
if ($el && $groupEl) {
|
|
2374
|
+
var nodeName = object.nodeName,
|
|
2375
|
+
attributes = object.attributes;
|
|
2376
|
+
$el.setAttribute('fill', 'none');
|
|
2535
2377
|
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
_$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2543
|
-
} else if (name === 'shadowOffsetX') {
|
|
2544
|
-
_$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2545
|
-
} else if (name === 'shadowOffsetY') {
|
|
2546
|
-
_$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2378
|
+
if (nodeName === gLite.Shape.IMAGE) {
|
|
2379
|
+
$el.setAttribute('preserveAspectRatio', 'none');
|
|
2380
|
+
} // apply attributes
|
|
2381
|
+
|
|
2382
|
+
|
|
2383
|
+
this.updateAttribute(object, Object.keys(attributes));
|
|
2547
2384
|
}
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2385
|
+
};
|
|
2550
2386
|
|
|
2551
|
-
|
|
2387
|
+
_proto.updateAttribute = function updateAttribute(object, attributes) {
|
|
2388
|
+
var _this2 = this;
|
|
2552
2389
|
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2390
|
+
var document = this.context.config.document; // @ts-ignore
|
|
2391
|
+
|
|
2392
|
+
var _object$elementSVG5 = object.elementSVG,
|
|
2393
|
+
$el = _object$elementSVG5.$el,
|
|
2394
|
+
$groupEl = _object$elementSVG5.$groupEl,
|
|
2395
|
+
$hitTestingEl = _object$elementSVG5.$hitTestingEl;
|
|
2396
|
+
var parsedStyle = object.parsedStyle,
|
|
2397
|
+
computedStyle = object.computedStyle;
|
|
2398
|
+
var shouldUpdateElementAttribute = attributes.some(function (name) {
|
|
2399
|
+
return (// @ts-ignore
|
|
2400
|
+
_this2.context.SVGElementLifeCycleContribution.shouldUpdateElementAttribute(object, name)
|
|
2401
|
+
);
|
|
2402
|
+
}); // need re-generate path
|
|
2565
2403
|
|
|
2404
|
+
if (shouldUpdateElementAttribute && $el) {
|
|
2405
|
+
[$el, $hitTestingEl].forEach(function ($el) {
|
|
2406
|
+
if ($el) {
|
|
2407
|
+
// @ts-ignore
|
|
2408
|
+
_this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el);
|
|
2566
2409
|
|
|
2567
|
-
|
|
2410
|
+
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
2411
|
+
_this2.updateAnchorWithTransform(object);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
});
|
|
2415
|
+
} // update common attributes
|
|
2568
2416
|
|
|
2569
|
-
_proto.getDefElement = function getDefElement() {
|
|
2570
|
-
return this.$def;
|
|
2571
|
-
};
|
|
2572
2417
|
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
var $svg = this.contextService.getContext();
|
|
2576
|
-
this.$def = createSVGElement('defs', document);
|
|
2577
|
-
$svg.appendChild(this.$def);
|
|
2578
|
-
};
|
|
2418
|
+
attributes.forEach(function (name) {
|
|
2419
|
+
var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
|
|
2579
2420
|
|
|
2580
|
-
|
|
2581
|
-
|
|
2421
|
+
var usedName = SVG_ATTR_MAP[name];
|
|
2422
|
+
var computedValue = computedStyle[name];
|
|
2423
|
+
var computedValueStr = computedValue && computedValue.toString();
|
|
2424
|
+
var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[computedValueStr]) || computedValueStr;
|
|
2425
|
+
var usedValue = parsedStyle[name];
|
|
2426
|
+
var inherited = !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
|
|
2582
2427
|
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
};
|
|
2428
|
+
if (!usedName) {
|
|
2429
|
+
return;
|
|
2430
|
+
} // <foreignObject>
|
|
2587
2431
|
|
|
2588
|
-
_proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
|
|
2589
|
-
if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
|
|
2590
|
-
var targetElement = this.$def.querySelector("#" + id);
|
|
2591
2432
|
|
|
2592
|
-
if (
|
|
2593
|
-
|
|
2433
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
2434
|
+
if (name === 'lineWidth') {
|
|
2435
|
+
$el.style['border-width'] = (usedValue || 0) + "px";
|
|
2436
|
+
} else if (name === 'lineDash') {
|
|
2437
|
+
$el.style['border-style'] = 'dashed';
|
|
2438
|
+
}
|
|
2594
2439
|
}
|
|
2595
|
-
|
|
2440
|
+
|
|
2441
|
+
if (name === 'fill') {
|
|
2442
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
2443
|
+
$el.style.background = usedValue.toString();
|
|
2444
|
+
} else {
|
|
2445
|
+
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
|
|
2446
|
+
}
|
|
2447
|
+
} else if (name === 'stroke') {
|
|
2448
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
2449
|
+
$el.style['border-color'] = usedValue.toString();
|
|
2450
|
+
$el.style['border-style'] = 'solid';
|
|
2451
|
+
} else {
|
|
2452
|
+
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
|
|
2453
|
+
}
|
|
2454
|
+
} else if (inherited && usedName) {
|
|
2455
|
+
// use computed value
|
|
2456
|
+
// update `visibility` on <group>
|
|
2457
|
+
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
2458
|
+
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, formattedValueStr);
|
|
2459
|
+
} else {
|
|
2460
|
+
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.removeAttribute(usedName);
|
|
2461
|
+
}
|
|
2462
|
+
} else if (name === 'clipPath') {
|
|
2463
|
+
_this2.createOrUpdateClipOrTextPath(document, usedValue, object);
|
|
2464
|
+
} else if (name === 'textPath') {
|
|
2465
|
+
_this2.createOrUpdateClipOrTextPath(document, usedValue, object, true);
|
|
2466
|
+
} else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
|
|
2467
|
+
_this2.defElementManager.createOrUpdateShadow(object, $el, name);
|
|
2468
|
+
} else if (name === 'filter') {
|
|
2469
|
+
_this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
|
|
2470
|
+
} else if (name === 'innerHTML') {
|
|
2471
|
+
_this2.createOrUpdateInnerHTML(document, $el, usedValue);
|
|
2472
|
+
} else if (name === 'anchor') {
|
|
2473
|
+
// text' anchor is controlled by `textAnchor` property
|
|
2474
|
+
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
2475
|
+
_this2.updateAnchorWithTransform(object);
|
|
2476
|
+
}
|
|
2477
|
+
} else {
|
|
2478
|
+
if (computedValue) {
|
|
2479
|
+
// use computed value so that we can use cascaded effect in SVG
|
|
2480
|
+
// ignore 'unset' and default value
|
|
2481
|
+
[$el, $hitTestingEl].forEach(function ($el) {
|
|
2482
|
+
if ($el && usedName) {
|
|
2483
|
+
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
2484
|
+
$el.setAttribute(usedName, formattedValueStr);
|
|
2485
|
+
} else {
|
|
2486
|
+
$el.removeAttribute(usedName);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
});
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2596
2493
|
};
|
|
2597
2494
|
|
|
2598
|
-
_proto.
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2495
|
+
_proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
|
|
2496
|
+
if (noWrapWithGroup === void 0) {
|
|
2497
|
+
noWrapWithGroup = false;
|
|
2498
|
+
} // create svg element
|
|
2499
|
+
// @ts-ignore
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
object.elementSVG = new ElementSVG(); // @ts-ignore
|
|
2503
|
+
|
|
2504
|
+
var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
|
|
2505
|
+
// @ts-ignore
|
|
2506
|
+
|
|
2507
|
+
var $el = this.context.SVGElementLifeCycleContribution.createElement(object);
|
|
2602
2508
|
|
|
2603
2509
|
if ($el) {
|
|
2604
|
-
var
|
|
2510
|
+
var _object$parentNode$el2;
|
|
2605
2511
|
|
|
2512
|
+
var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
|
|
2606
2513
|
|
|
2607
|
-
|
|
2514
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
2515
|
+
object.parsedStyle.$el = $el;
|
|
2516
|
+
}
|
|
2608
2517
|
|
|
2609
|
-
if (
|
|
2610
|
-
this.
|
|
2518
|
+
if (this.pluginOptions.outputSVGElementId) {
|
|
2519
|
+
$el.id = this.getId(object);
|
|
2611
2520
|
}
|
|
2612
2521
|
|
|
2613
|
-
|
|
2522
|
+
if (this.pluginOptions.outputSVGElementName && object.name) {
|
|
2523
|
+
$el.setAttribute('name', object.name);
|
|
2524
|
+
}
|
|
2614
2525
|
|
|
2615
|
-
if (
|
|
2616
|
-
|
|
2526
|
+
if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
|
|
2527
|
+
$groupEl = createSVGElement('g', document);
|
|
2528
|
+
$groupEl.appendChild($el);
|
|
2529
|
+
} else {
|
|
2530
|
+
$groupEl = $el;
|
|
2617
2531
|
}
|
|
2618
2532
|
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
};
|
|
2533
|
+
svgElement.$el = $el;
|
|
2534
|
+
svgElement.$groupEl = $groupEl; // apply attributes at first time
|
|
2622
2535
|
|
|
2623
|
-
|
|
2624
|
-
var doc = this.canvasConfig.document;
|
|
2625
|
-
createOrUpdateShadow(doc || document, this.$def, object, $el, name);
|
|
2626
|
-
};
|
|
2536
|
+
this.applyAttributes(object); // create hitArea if necessary
|
|
2627
2537
|
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2538
|
+
this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
2539
|
+
var $parentGroupEl = // @ts-ignore
|
|
2540
|
+
object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl) || root;
|
|
2541
|
+
|
|
2542
|
+
if ($parentGroupEl) {
|
|
2543
|
+
$parentGroupEl.appendChild($groupEl); // need reorder children later
|
|
2544
|
+
|
|
2545
|
+
this.pendingReorderQueue.add(object.parentNode);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2631
2548
|
};
|
|
2632
2549
|
|
|
2633
|
-
|
|
2634
|
-
|
|
2550
|
+
_proto.removeSVGDom = function removeSVGDom(object) {
|
|
2551
|
+
var _object$elementSVG6; // @ts-ignore
|
|
2635
2552
|
|
|
2636
|
-
DefElementManager = __decorate([gLite.singleton(), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.ContextService))], DefElementManager);
|
|
2637
|
-
var ElementLifeCycleContribution = gLite.Syringe.defineToken('', {
|
|
2638
|
-
multiple: false
|
|
2639
|
-
});
|
|
2640
|
-
var SVGRendererPluginOptions = gLite.Syringe.defineToken('');
|
|
2641
2553
|
|
|
2642
|
-
|
|
2643
|
-
return x.toFixed(6).replace('.000000', '');
|
|
2644
|
-
}
|
|
2554
|
+
var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
|
|
2645
2555
|
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
return '&';
|
|
2651
|
-
} else if (match === '<') {
|
|
2652
|
-
return '<';
|
|
2653
|
-
} else if (match === '>') {
|
|
2654
|
-
return '>';
|
|
2655
|
-
} else if (match === '"') {
|
|
2656
|
-
return '"';
|
|
2657
|
-
} else {
|
|
2658
|
-
return ''';
|
|
2556
|
+
if ($groupEl && $groupEl.parentNode) {
|
|
2557
|
+
$groupEl.parentNode.removeChild($groupEl); // @ts-ignore
|
|
2558
|
+
|
|
2559
|
+
this.context.SVGElementLifeCycleContribution.destroyElement(object, $groupEl); // object.entity.removeComponent(ElementSVG, true);
|
|
2659
2560
|
}
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2561
|
+
};
|
|
2662
2562
|
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
fillStyle: 'fill',
|
|
2669
|
-
fill: 'fill',
|
|
2670
|
-
fillRule: 'fill-rule',
|
|
2671
|
-
fillOpacity: 'fill-opacity',
|
|
2672
|
-
strokeStyle: 'stroke',
|
|
2673
|
-
strokeOpacity: 'stroke-opacity',
|
|
2674
|
-
stroke: 'stroke',
|
|
2675
|
-
clipPath: 'clip-path',
|
|
2676
|
-
textPath: 'text-path',
|
|
2677
|
-
r: 'r',
|
|
2678
|
-
rx: 'rx',
|
|
2679
|
-
ry: 'ry',
|
|
2680
|
-
width: 'width',
|
|
2681
|
-
height: 'height',
|
|
2682
|
-
lineCap: 'stroke-linecap',
|
|
2683
|
-
lineJoin: 'stroke-linejoin',
|
|
2684
|
-
lineWidth: 'stroke-width',
|
|
2685
|
-
lineDash: 'stroke-dasharray',
|
|
2686
|
-
lineDashOffset: 'stroke-dashoffset',
|
|
2687
|
-
miterLimit: 'stroke-miterlimit',
|
|
2688
|
-
font: 'font',
|
|
2689
|
-
fontSize: 'font-size',
|
|
2690
|
-
fontStyle: 'font-style',
|
|
2691
|
-
fontVariant: 'font-variant',
|
|
2692
|
-
fontWeight: 'font-weight',
|
|
2693
|
-
fontFamily: 'font-family',
|
|
2694
|
-
letterSpacing: 'letter-spacing',
|
|
2695
|
-
startArrow: 'marker-start',
|
|
2696
|
-
endArrow: 'marker-end',
|
|
2697
|
-
class: 'class',
|
|
2698
|
-
id: 'id',
|
|
2699
|
-
// style: 'style',
|
|
2700
|
-
preserveAspectRatio: 'preserveAspectRatio',
|
|
2701
|
-
visibility: 'visibility',
|
|
2702
|
-
anchor: 'anchor',
|
|
2703
|
-
shadowColor: 'flood-color',
|
|
2704
|
-
shadowBlur: 'stdDeviation',
|
|
2705
|
-
shadowOffsetX: 'dx',
|
|
2706
|
-
shadowOffsetY: 'dy',
|
|
2707
|
-
filter: 'filter',
|
|
2708
|
-
innerHTML: 'innerHTML',
|
|
2709
|
-
textAlign: 'text-anchor',
|
|
2710
|
-
pointerEvents: 'pointer-events'
|
|
2711
|
-
};
|
|
2712
|
-
var FORMAT_VALUE_MAP = {
|
|
2713
|
-
textAlign: {
|
|
2714
|
-
inherit: 'inherit',
|
|
2715
|
-
left: 'left',
|
|
2716
|
-
start: 'left',
|
|
2717
|
-
center: 'middle',
|
|
2718
|
-
right: 'end',
|
|
2719
|
-
end: 'end'
|
|
2720
|
-
}
|
|
2721
|
-
};
|
|
2722
|
-
var DEFAULT_VALUE_MAP = {
|
|
2723
|
-
textAlign: 'inherit',
|
|
2724
|
-
// textBaseline: 'alphabetic',
|
|
2725
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineCaps
|
|
2726
|
-
lineCap: 'butt',
|
|
2727
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineJoin
|
|
2728
|
-
lineJoin: 'miter',
|
|
2729
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
|
|
2730
|
-
lineWidth: '1px',
|
|
2731
|
-
opacity: '1',
|
|
2732
|
-
fillOpacity: '1',
|
|
2733
|
-
fillRule: 'nonzero',
|
|
2734
|
-
strokeOpacity: '1',
|
|
2735
|
-
strokeWidth: '0',
|
|
2736
|
-
strokeMiterLimit: '4',
|
|
2737
|
-
letterSpacing: '0',
|
|
2738
|
-
fontSize: 'inherit',
|
|
2739
|
-
fontFamily: 'inherit',
|
|
2740
|
-
pointerEvents: 'auto'
|
|
2741
|
-
};
|
|
2742
|
-
/**
|
|
2743
|
-
* G_SVG_PREFIX + nodeName + entity
|
|
2744
|
-
*
|
|
2745
|
-
* eg. g_svg_circle_345
|
|
2746
|
-
*/
|
|
2747
|
-
|
|
2748
|
-
var G_SVG_PREFIX = 'g_svg';
|
|
2749
|
-
var CLIP_PATH_PREFIX = 'clip-path-';
|
|
2750
|
-
var TEXT_PATH_PREFIX = 'text-path-';
|
|
2751
|
-
var SVGRendererPlugin = SVGRendererPlugin_1 = (_class$1 = /*#__PURE__*/function () {
|
|
2752
|
-
function SVGRendererPlugin(canvasConfig, camera, contextService, renderingContext, styleValueRegistry, createElementContribution, defElementManager, pluginOptions) {
|
|
2753
|
-
this.canvasConfig = void 0;
|
|
2754
|
-
this.camera = void 0;
|
|
2755
|
-
this.contextService = void 0;
|
|
2756
|
-
this.renderingContext = void 0;
|
|
2757
|
-
this.styleValueRegistry = void 0;
|
|
2758
|
-
this.createElementContribution = void 0;
|
|
2759
|
-
this.defElementManager = void 0;
|
|
2760
|
-
this.pluginOptions = void 0;
|
|
2761
|
-
this.$camera = void 0;
|
|
2762
|
-
this.renderQueue = [];
|
|
2763
|
-
this.dirtyAttributes = new WeakMap();
|
|
2764
|
-
this.pendingReorderQueue = new Set();
|
|
2765
|
-
this.canvasConfig = canvasConfig;
|
|
2766
|
-
this.camera = camera;
|
|
2767
|
-
this.contextService = contextService;
|
|
2768
|
-
this.renderingContext = renderingContext;
|
|
2769
|
-
this.styleValueRegistry = styleValueRegistry;
|
|
2770
|
-
this.createElementContribution = createElementContribution;
|
|
2771
|
-
this.defElementManager = defElementManager;
|
|
2772
|
-
this.pluginOptions = pluginOptions;
|
|
2773
|
-
}
|
|
2774
|
-
/**
|
|
2775
|
-
* <camera>
|
|
2776
|
-
*/
|
|
2563
|
+
_proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
|
|
2564
|
+
// @ts-ignore
|
|
2565
|
+
var svgElement = object.elementSVG;
|
|
2566
|
+
var $hitTestingEl = svgElement.$hitTestingEl;
|
|
2567
|
+
var increasedLineWidthForHitTesting = object.parsedStyle.increasedLineWidthForHitTesting; // account for hitArea
|
|
2777
2568
|
|
|
2569
|
+
if (increasedLineWidthForHitTesting) {
|
|
2570
|
+
if (!$hitTestingEl) {
|
|
2571
|
+
$hitTestingEl = $el.cloneNode();
|
|
2778
2572
|
|
|
2779
|
-
|
|
2573
|
+
if (this.pluginOptions.outputSVGElementId) {
|
|
2574
|
+
// use the entity suffix, so that `g-plugin-svg-picker` can extract
|
|
2575
|
+
$hitTestingEl.id = G_SVG_PREFIX + "_" + object.nodeName + "_hittesting_" + object.entity;
|
|
2576
|
+
} // clear attributes like `filter` `font-size`
|
|
2780
2577
|
|
|
2781
|
-
_proto.apply = function apply(renderingService) {
|
|
2782
|
-
var _this = this;
|
|
2783
2578
|
|
|
2784
|
-
|
|
2579
|
+
['filter'].forEach(function (attribute) {
|
|
2580
|
+
$hitTestingEl.removeAttribute(attribute);
|
|
2581
|
+
}); // hitArea should be 'transparent' but not 'none'
|
|
2785
2582
|
|
|
2786
|
-
|
|
2787
|
-
|
|
2583
|
+
var hasFill = $el.getAttribute('fill') !== 'none';
|
|
2584
|
+
$hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
|
|
2585
|
+
$hitTestingEl.setAttribute('stroke', 'transparent');
|
|
2586
|
+
$groupEl.appendChild($hitTestingEl);
|
|
2587
|
+
svgElement.$hitTestingEl = $hitTestingEl;
|
|
2588
|
+
} // increase interactive line width
|
|
2788
2589
|
|
|
2789
|
-
_this.createSVGDom(document, object, _this.$camera);
|
|
2790
|
-
};
|
|
2791
2590
|
|
|
2792
|
-
|
|
2793
|
-
|
|
2591
|
+
$hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
|
|
2592
|
+
} else {
|
|
2593
|
+
if ($hitTestingEl) {
|
|
2594
|
+
$groupEl.removeChild($hitTestingEl);
|
|
2595
|
+
svgElement.$hitTestingEl = null;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2794
2599
|
|
|
2795
|
-
|
|
2600
|
+
_proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
|
|
2601
|
+
var $div = (doc || document).createElement('div');
|
|
2796
2602
|
|
|
2797
|
-
|
|
2798
|
-
|
|
2603
|
+
if (typeof usedValue === 'string') {
|
|
2604
|
+
$div.innerHTML = usedValue;
|
|
2605
|
+
} else {
|
|
2606
|
+
$div.appendChild(usedValue);
|
|
2607
|
+
}
|
|
2799
2608
|
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2609
|
+
$el.innerHTML = '';
|
|
2610
|
+
$el.appendChild($div);
|
|
2611
|
+
};
|
|
2803
2612
|
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2613
|
+
_proto.createOrUpdateClipOrTextPath = function createOrUpdateClipOrTextPath(document, clipPath, object, isTextPath) {
|
|
2614
|
+
if (isTextPath === void 0) {
|
|
2615
|
+
isTextPath = false;
|
|
2616
|
+
} // @ts-ignore
|
|
2807
2617
|
|
|
2808
|
-
var attrName = e.attrName;
|
|
2809
2618
|
|
|
2810
|
-
|
|
2619
|
+
var $groupEl = object.elementSVG.$groupEl;
|
|
2620
|
+
var PREFIX = isTextPath ? TEXT_PATH_PREFIX : CLIP_PATH_PREFIX;
|
|
2621
|
+
var attributeNameCamel = isTextPath ? 'g' : 'clipPath';
|
|
2622
|
+
var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
|
|
2811
2623
|
|
|
2812
|
-
|
|
2813
|
-
|
|
2624
|
+
if (clipPath) {
|
|
2625
|
+
var clipPathId = PREFIX + clipPath.entity + '-' + object.entity;
|
|
2626
|
+
var $def = this.defElementManager.getDefElement();
|
|
2627
|
+
var existed = $def.querySelector("#" + clipPathId);
|
|
2814
2628
|
|
|
2815
|
-
|
|
2816
|
-
|
|
2629
|
+
if (!existed) {
|
|
2630
|
+
var $clipPath;
|
|
2817
2631
|
|
|
2818
|
-
|
|
2819
|
-
|
|
2632
|
+
if (isTextPath) {
|
|
2633
|
+
// use <path> directly instead of wrapping with <g>
|
|
2634
|
+
this.createSVGDom(document, clipPath, null, true); // @ts-ignore
|
|
2820
2635
|
|
|
2821
|
-
|
|
2822
|
-
|
|
2636
|
+
$clipPath = clipPath.elementSVG.$el;
|
|
2637
|
+
} else {
|
|
2638
|
+
// the clipPath is allowed to be detached from canvas
|
|
2639
|
+
if (!clipPath.isConnected) {
|
|
2640
|
+
var $existedClipPath = $def.querySelector("#" + this.getId(clipPath));
|
|
2823
2641
|
|
|
2824
|
-
|
|
2642
|
+
if (!$existedClipPath) {
|
|
2643
|
+
this.createSVGDom(document, clipPath, $def, true);
|
|
2644
|
+
}
|
|
2645
|
+
} // create <clipPath> dom node
|
|
2825
2646
|
|
|
2826
|
-
var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
|
|
2827
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
2828
|
-
fill = _object$parsedStyle.fill,
|
|
2829
|
-
stroke = _object$parsedStyle.stroke;
|
|
2830
2647
|
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
}
|
|
2648
|
+
$clipPath = createSVGElement(attributeNameCamel, document);
|
|
2649
|
+
var $use = createSVGElement('use', document); // @ts-ignore
|
|
2834
2650
|
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
};
|
|
2651
|
+
$use.setAttribute('href', "#" + clipPath.elementSVG.$el.id);
|
|
2652
|
+
$clipPath.appendChild($use);
|
|
2653
|
+
var $useRefs = this.clipPathUseMap.get(clipPath);
|
|
2839
2654
|
|
|
2840
|
-
|
|
2841
|
-
|
|
2655
|
+
if (!$useRefs) {
|
|
2656
|
+
this.clipPathUseMap.set(clipPath, []);
|
|
2657
|
+
$useRefs = this.clipPathUseMap.get(clipPath);
|
|
2658
|
+
}
|
|
2842
2659
|
|
|
2843
|
-
|
|
2844
|
-
while (1) {
|
|
2845
|
-
switch (_context.prev = _context.next) {
|
|
2846
|
-
case 0:
|
|
2847
|
-
_this$canvasConfig = _this.canvasConfig, background = _this$canvasConfig.background, document = _this$canvasConfig.document; // <defs>
|
|
2660
|
+
$useRefs.push($use); // <clipPath transform="matrix()"><circle /></clipPath>
|
|
2848
2661
|
|
|
2849
|
-
|
|
2662
|
+
this.applyTransform($use, clipPath.getWorldTransform());
|
|
2663
|
+
var parentInvert = invert(create(), object.getWorldTransform());
|
|
2664
|
+
this.applyTransform($clipPath, parentInvert);
|
|
2665
|
+
}
|
|
2850
2666
|
|
|
2851
|
-
|
|
2667
|
+
$clipPath.id = clipPathId; // append it to <defs>
|
|
2852
2668
|
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
} // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
|
|
2669
|
+
$def.appendChild($clipPath);
|
|
2670
|
+
} // apply attributes
|
|
2856
2671
|
|
|
2857
2672
|
|
|
2858
|
-
|
|
2859
|
-
_this.$camera = createSVGElement('g', document);
|
|
2860
|
-
_this.$camera.id = G_SVG_PREFIX + "_camera";
|
|
2673
|
+
this.applyAttributes(clipPath);
|
|
2861
2674
|
|
|
2862
|
-
|
|
2675
|
+
if (!isTextPath) {
|
|
2676
|
+
// apply clipPath to $group
|
|
2677
|
+
// @see https://github.com/antvis/g/issues/961
|
|
2678
|
+
$groupEl.setAttribute(attributeNameHyphen, "url(#" + clipPathId + ")");
|
|
2679
|
+
}
|
|
2680
|
+
} else {
|
|
2681
|
+
if (!isTextPath) {
|
|
2682
|
+
// remove clip path
|
|
2683
|
+
$groupEl.removeAttribute(attributeNameHyphen);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
/**
|
|
2688
|
+
* the origin is bounding box's top left corner
|
|
2689
|
+
*/
|
|
2690
|
+
;
|
|
2863
2691
|
|
|
2864
|
-
|
|
2692
|
+
_proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
|
|
2693
|
+
var _object$elementSVG7, _object$elementSVG8;
|
|
2865
2694
|
|
|
2866
|
-
|
|
2695
|
+
var bounds = object.getGeometryBounds();
|
|
2696
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
2697
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
2867
2698
|
|
|
2868
|
-
|
|
2699
|
+
var _ref2 = object.parsedStyle || {},
|
|
2700
|
+
anchor = _ref2.anchor; // @ts-ignore
|
|
2869
2701
|
|
|
2870
|
-
_this.renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
2871
2702
|
|
|
2872
|
-
|
|
2703
|
+
[(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
|
|
2704
|
+
if ($el) {
|
|
2705
|
+
var tx = -(anchor[0] * width);
|
|
2706
|
+
var ty = -(anchor[1] * height);
|
|
2873
2707
|
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2708
|
+
if (tx !== 0 || ty !== 0) {
|
|
2709
|
+
// apply anchor to element's `transform` property
|
|
2710
|
+
$el.setAttribute('transform', // can't use percent unit like translate(-50%, -50%)
|
|
2711
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
|
|
2712
|
+
"translate(" + tx + "," + ty + ")");
|
|
2878
2713
|
}
|
|
2879
|
-
}, _callee);
|
|
2880
|
-
})));
|
|
2881
|
-
renderingService.hooks.destroy.tap(SVGRendererPlugin_1.tag, function () {
|
|
2882
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
2883
|
-
|
|
2884
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
2885
|
-
|
|
2886
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
2887
|
-
|
|
2888
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
|
|
2889
|
-
});
|
|
2890
|
-
renderingService.hooks.render.tap(SVGRendererPlugin_1.tag, function (object) {
|
|
2891
|
-
// if (!object.isCulled()) {
|
|
2892
|
-
_this.renderQueue.push(object); // }
|
|
2893
2714
|
|
|
2715
|
+
if (object.nodeName === gLite.Shape.CIRCLE || object.nodeName === gLite.Shape.ELLIPSE) {
|
|
2716
|
+
$el.setAttribute('cx', "" + width / 2);
|
|
2717
|
+
$el.setAttribute('cy', "" + height / 2);
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2894
2720
|
});
|
|
2895
|
-
|
|
2896
|
-
var doc = _this.canvasConfig.document;
|
|
2721
|
+
};
|
|
2897
2722
|
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
var _object$elementSVG2;
|
|
2723
|
+
return SVGRendererPlugin;
|
|
2724
|
+
}();
|
|
2901
2725
|
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2726
|
+
SVGRendererPlugin.tag = 'SVGRenderer';
|
|
2727
|
+
var BASELINE_MAP = {
|
|
2728
|
+
top: 'before-edge',
|
|
2729
|
+
middle: 'central',
|
|
2730
|
+
bottom: 'after-edge',
|
|
2731
|
+
alphabetic: 'alphabetic',
|
|
2732
|
+
ideographic: 'ideographic',
|
|
2733
|
+
hanging: 'hanging'
|
|
2734
|
+
}; // for FireFox
|
|
2735
|
+
// @see https://github.com/plouc/nivo/issues/164
|
|
2905
2736
|
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2737
|
+
var BASELINE_MAP_FOR_FIREFOX = {
|
|
2738
|
+
top: 'text-before-edge',
|
|
2739
|
+
middle: 'central',
|
|
2740
|
+
bottom: 'text-after-edge',
|
|
2741
|
+
alphabetic: 'alphabetic',
|
|
2742
|
+
ideographic: 'ideographic',
|
|
2743
|
+
hanging: 'hanging'
|
|
2744
|
+
};
|
|
2910
2745
|
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2746
|
+
function updateTextElementAttribute($el, parsedStyle) {
|
|
2747
|
+
var textBaseline = parsedStyle.textBaseline,
|
|
2748
|
+
lineWidth = parsedStyle.lineWidth,
|
|
2749
|
+
metrics = parsedStyle.metrics,
|
|
2750
|
+
dx = parsedStyle.dx,
|
|
2751
|
+
dy = parsedStyle.dy,
|
|
2752
|
+
textPath = parsedStyle.textPath,
|
|
2753
|
+
_parsedStyle$textPath = parsedStyle.textPathSide,
|
|
2754
|
+
textPathSide = _parsedStyle$textPath === void 0 ? 'left' : _parsedStyle$textPath,
|
|
2755
|
+
_parsedStyle$textPath2 = parsedStyle.textPathStartOffset,
|
|
2756
|
+
textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
|
|
2757
|
+
_parsedStyle$textDeco = parsedStyle.textDecorationLine,
|
|
2758
|
+
textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
|
|
2759
|
+
_parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
|
|
2760
|
+
textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
|
|
2761
|
+
_parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
|
|
2762
|
+
textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3;
|
|
2763
|
+
var browser = detect();
|
|
2918
2764
|
|
|
2919
|
-
|
|
2920
|
-
|
|
2765
|
+
if (browser && browser.name === 'firefox') {
|
|
2766
|
+
// compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
|
|
2767
|
+
$el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline] || 'alphabetic');
|
|
2768
|
+
} else {
|
|
2769
|
+
$el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline]);
|
|
2770
|
+
$el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline]);
|
|
2771
|
+
}
|
|
2921
2772
|
|
|
2773
|
+
$el.setAttribute('paint-order', 'stroke');
|
|
2774
|
+
var lines = metrics.lines,
|
|
2775
|
+
lineHeight = metrics.lineHeight,
|
|
2776
|
+
height = metrics.height;
|
|
2777
|
+
var lineNum = lines.length;
|
|
2778
|
+
var styleCSSText = '';
|
|
2922
2779
|
|
|
2923
|
-
|
|
2780
|
+
if (dx !== 0 || dy !== 0) {
|
|
2781
|
+
styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
|
|
2782
|
+
}
|
|
2924
2783
|
|
|
2925
|
-
|
|
2784
|
+
if (textDecorationLine && textDecorationLine !== 'none') {
|
|
2785
|
+
// use CSS text-decoration since the implementation in SVG is not good enough
|
|
2786
|
+
styleCSSText += "text-decoration:" + textDecorationLine + " " + textDecorationStyle + " " + textDecorationColor + ";";
|
|
2787
|
+
}
|
|
2926
2788
|
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
_this.applyTransform($groupEl, object.getLocalTransform()); // finish rendering, clear dirty flag
|
|
2789
|
+
if (styleCSSText) {
|
|
2790
|
+
$el.setAttribute('style', styleCSSText);
|
|
2791
|
+
}
|
|
2931
2792
|
|
|
2793
|
+
if (lineNum === 1) {
|
|
2794
|
+
var textContent = convertHTML(lines[0]);
|
|
2795
|
+
$el.setAttribute('dx', "" + lineWidth / 2); // <textPath> only support one line
|
|
2796
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
|
|
2932
2797
|
|
|
2933
|
-
|
|
2934
|
-
|
|
2798
|
+
if (textPath) {
|
|
2799
|
+
// clear existed text content first
|
|
2800
|
+
$el.innerHTML = ''; // append <textPath href="#MyPath">text</textPath>
|
|
2935
2801
|
|
|
2802
|
+
var $textPath = createSVGElement('textPath', $el.ownerDocument);
|
|
2803
|
+
$textPath.setAttribute('href', "#" + (TEXT_PATH_PREFIX + textPath.entity));
|
|
2936
2804
|
|
|
2937
|
-
|
|
2805
|
+
if (textPathSide !== 'left') {
|
|
2806
|
+
$textPath.setAttribute('side', textPathSide);
|
|
2807
|
+
}
|
|
2938
2808
|
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
var _object$parentNode, _object$parentNode$el;
|
|
2809
|
+
if (textPathStartOffset !== 0) {
|
|
2810
|
+
$textPath.setAttribute('startOffset', "" + textPathStartOffset);
|
|
2811
|
+
}
|
|
2943
2812
|
|
|
2944
|
-
|
|
2813
|
+
$textPath.innerHTML = textContent;
|
|
2814
|
+
$el.appendChild($textPath);
|
|
2815
|
+
} else {
|
|
2816
|
+
$el.innerHTML = textContent;
|
|
2817
|
+
}
|
|
2818
|
+
} else {
|
|
2819
|
+
$el.innerHTML = lines.map(function (line, i) {
|
|
2820
|
+
var dx = lineWidth / 2;
|
|
2821
|
+
var dy = 0;
|
|
2945
2822
|
|
|
2946
|
-
|
|
2823
|
+
if (i === 0) {
|
|
2824
|
+
// TODO: handle other textBaseline values
|
|
2825
|
+
if (textBaseline === 'middle') {
|
|
2826
|
+
dy = lineHeight / 2 - height / 2;
|
|
2827
|
+
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
2828
|
+
dy = 0;
|
|
2829
|
+
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
2830
|
+
dy = -lineHeight * (lineNum - 1);
|
|
2831
|
+
}
|
|
2832
|
+
} else {
|
|
2833
|
+
dy = lineHeight;
|
|
2834
|
+
}
|
|
2947
2835
|
|
|
2948
|
-
|
|
2836
|
+
return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
|
|
2837
|
+
}).join('');
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2949
2840
|
|
|
2950
|
-
|
|
2951
|
-
_this.reorderChildren(document, _$groupEl, children);
|
|
2952
|
-
}
|
|
2953
|
-
} else if (attrName === 'increasedLineWidthForHitTesting') {
|
|
2954
|
-
_this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
2955
|
-
}
|
|
2841
|
+
var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
|
|
2956
2842
|
|
|
2957
|
-
|
|
2958
|
-
|
|
2843
|
+
var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[gLite.Shape.RECT] = 'path', _SHAPE2TAGS[gLite.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[gLite.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[gLite.Shape.IMAGE] = 'image', _SHAPE2TAGS[gLite.Shape.GROUP] = 'g', _SHAPE2TAGS[gLite.Shape.LINE] = 'line', _SHAPE2TAGS[gLite.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[gLite.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[gLite.Shape.TEXT] = 'text', _SHAPE2TAGS[gLite.Shape.PATH] = 'path', _SHAPE2TAGS[gLite.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
|
|
2844
|
+
var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[gLite.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[gLite.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[gLite.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[gLite.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[gLite.Shape.LINE] = ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYLINE] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYGON] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.PATH] = ['path', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'maxLines', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'textOverflow', 'textPath', 'textPathSide', 'textPathStartOffset', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle', // 'whiteSpace',
|
|
2845
|
+
'dx', 'dy'], _SHAPE_UPDATE_DEPS);
|
|
2959
2846
|
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2847
|
+
var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
|
|
2848
|
+
function DefaultElementLifeCycleContribution(context) {
|
|
2849
|
+
this.context = void 0;
|
|
2850
|
+
this.context = context;
|
|
2851
|
+
}
|
|
2963
2852
|
|
|
2964
|
-
|
|
2965
|
-
|
|
2853
|
+
var _proto = DefaultElementLifeCycleContribution.prototype;
|
|
2854
|
+
|
|
2855
|
+
_proto.createElement = function createElement(object) {
|
|
2856
|
+
var doc = this.context.config.document;
|
|
2857
|
+
var type = SHAPE2TAGS[object.nodeName] || 'g';
|
|
2858
|
+
return createSVGElement(type, doc || document);
|
|
2966
2859
|
};
|
|
2967
2860
|
|
|
2968
|
-
_proto.
|
|
2969
|
-
// need to reorder parent's children
|
|
2970
|
-
children.sort(function (a, b) {
|
|
2971
|
-
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
2972
|
-
});
|
|
2861
|
+
_proto.destroyElement = function destroyElement(object, $el) {};
|
|
2973
2862
|
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
if (child.isConnected) {
|
|
2979
|
-
// @ts-ignore
|
|
2980
|
-
var $el = child.elementSVG.$groupEl;
|
|
2863
|
+
_proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
|
|
2864
|
+
var nodeName = object.nodeName;
|
|
2865
|
+
return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
|
|
2866
|
+
};
|
|
2981
2867
|
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2868
|
+
_proto.updateElementAttribute = function updateElementAttribute(object) {
|
|
2869
|
+
// @ts-ignore
|
|
2870
|
+
var $el = object.elementSVG.$el;
|
|
2871
|
+
var nodeName = object.nodeName,
|
|
2872
|
+
parsedStyle = object.parsedStyle;
|
|
2873
|
+
|
|
2874
|
+
switch (nodeName) {
|
|
2875
|
+
case gLite.Shape.IMAGE:
|
|
2876
|
+
{
|
|
2877
|
+
updateImageElementAttribute($el, parsedStyle);
|
|
2878
|
+
break;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
case gLite.Shape.RECT:
|
|
2882
|
+
{
|
|
2883
|
+
updateRectElementAttribute($el, parsedStyle);
|
|
2884
|
+
break;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
case gLite.Shape.LINE:
|
|
2888
|
+
{
|
|
2889
|
+
updateLineElementAttribute($el, parsedStyle);
|
|
2890
|
+
break;
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
case gLite.Shape.POLYGON:
|
|
2894
|
+
case gLite.Shape.POLYLINE:
|
|
2895
|
+
{
|
|
2896
|
+
updatePolylineElementAttribute($el, parsedStyle);
|
|
2897
|
+
break;
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
case gLite.Shape.PATH:
|
|
2901
|
+
{
|
|
2902
|
+
updatePathElementAttribute($el, parsedStyle);
|
|
2903
|
+
break;
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
case gLite.Shape.TEXT:
|
|
2907
|
+
{
|
|
2908
|
+
updateTextElementAttribute($el, parsedStyle);
|
|
2909
|
+
break;
|
|
2985
2910
|
}
|
|
2986
|
-
});
|
|
2987
|
-
$groupEl.appendChild(fragment);
|
|
2988
2911
|
}
|
|
2989
2912
|
};
|
|
2990
2913
|
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
2994
|
-
$el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
|
|
2995
|
-
};
|
|
2914
|
+
return DefaultElementLifeCycleContribution;
|
|
2915
|
+
}();
|
|
2996
2916
|
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
2917
|
+
var FILTER_PREFIX = 'g-filter-';
|
|
2918
|
+
/**
|
|
2919
|
+
* use SVG filters, eg. blur, brightness, contrast...
|
|
2920
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2921
|
+
*/
|
|
3002
2922
|
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
2923
|
+
function createOrUpdateFilter(document, $def, object, $el, filters) {
|
|
2924
|
+
// eg. filter="url(#f1) url(#f2)"
|
|
2925
|
+
var filterName = FILTER_PREFIX + object.entity;
|
|
2926
|
+
var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
|
|
3007
2927
|
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2928
|
+
if ($existedFilters.length) {
|
|
2929
|
+
$existedFilters.forEach(function ($filter) {
|
|
2930
|
+
$def.removeChild($filter);
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
3011
2933
|
|
|
2934
|
+
if (filters.length === 0) {
|
|
2935
|
+
// 'none'
|
|
2936
|
+
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2937
|
+
} else {
|
|
2938
|
+
var filterIds = filters.map(function (_ref, i) {
|
|
2939
|
+
var name = _ref.name,
|
|
2940
|
+
params = _ref.params;
|
|
2941
|
+
var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
|
|
3012
2942
|
|
|
3013
|
-
|
|
3014
|
-
}
|
|
3015
|
-
};
|
|
2943
|
+
$filter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
3016
2944
|
|
|
3017
|
-
|
|
3018
|
-
|
|
2945
|
+
if (name === 'blur') {
|
|
2946
|
+
createBlur(document, $filter, params);
|
|
2947
|
+
} else if (name === 'brightness') {
|
|
2948
|
+
createBrightness(document, $filter, params);
|
|
2949
|
+
} else if (name === 'drop-shadow') {
|
|
2950
|
+
createDropShadow(document, $filter, params);
|
|
2951
|
+
} else if (name === 'contrast') {
|
|
2952
|
+
createContrast(document, $filter, params);
|
|
2953
|
+
} else if (name === 'grayscale') {
|
|
2954
|
+
createGrayscale(document, $filter, params);
|
|
2955
|
+
} else if (name === 'sepia') {
|
|
2956
|
+
createSepia(document, $filter, params);
|
|
2957
|
+
} else if (name === 'saturate') {
|
|
2958
|
+
createSaturate(document, $filter, params);
|
|
2959
|
+
} else if (name === 'hue-rotate') {
|
|
2960
|
+
createHueRotate(document, $filter, params);
|
|
2961
|
+
} else if (name === 'invert') {
|
|
2962
|
+
createInvert(document, $filter, params);
|
|
2963
|
+
}
|
|
3019
2964
|
|
|
3020
|
-
|
|
2965
|
+
$filter.id = filterName + "-" + i;
|
|
2966
|
+
$filter.setAttribute('name', filterName);
|
|
2967
|
+
$def.appendChild($filter);
|
|
2968
|
+
return $filter.id;
|
|
2969
|
+
}); // @see https://github.com/antvis/G/issues/1114
|
|
3021
2970
|
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
return _this2.createElementContribution.shouldUpdateElementAttribute(object, name);
|
|
3030
|
-
}); // need re-generate path
|
|
2971
|
+
setTimeout(function () {
|
|
2972
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
|
|
2973
|
+
return "url(#" + filterId + ")";
|
|
2974
|
+
}).join(' '));
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
3031
2978
|
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
2979
|
+
function convertToAbsoluteValue(param) {
|
|
2980
|
+
return param.unit === gLite.UnitType.kPercentage ? param.value / 100 : param.value;
|
|
2981
|
+
}
|
|
2982
|
+
/**
|
|
2983
|
+
* @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
|
|
2984
|
+
*/
|
|
3036
2985
|
|
|
3037
|
-
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
3038
|
-
_this2.updateAnchorWithTransform(object);
|
|
3039
|
-
}
|
|
3040
|
-
}
|
|
3041
|
-
});
|
|
3042
|
-
} // update common attributes
|
|
3043
2986
|
|
|
2987
|
+
function createBlur(document, $filter, params) {
|
|
2988
|
+
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2989
|
+
$feGaussianBlur.setAttribute('in', 'SourceGraphic');
|
|
2990
|
+
$feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
|
|
2991
|
+
$filter.appendChild($feGaussianBlur);
|
|
2992
|
+
}
|
|
3044
2993
|
|
|
3045
|
-
|
|
3046
|
-
|
|
2994
|
+
function createFeComponentTransfer(document, $filter, _ref2) {
|
|
2995
|
+
var type = _ref2.type,
|
|
2996
|
+
slope = _ref2.slope,
|
|
2997
|
+
intercept = _ref2.intercept,
|
|
2998
|
+
tableValues = _ref2.tableValues;
|
|
2999
|
+
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
3000
|
+
[createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
|
|
3001
|
+
$feFunc.setAttribute('type', type);
|
|
3047
3002
|
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3003
|
+
if (type === 'table') {
|
|
3004
|
+
$feFunc.setAttribute('tableValues', "" + tableValues);
|
|
3005
|
+
} else {
|
|
3006
|
+
$feFunc.setAttribute('slope', "" + slope);
|
|
3007
|
+
$feFunc.setAttribute('intercept', "" + intercept);
|
|
3008
|
+
}
|
|
3054
3009
|
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3010
|
+
$feComponentTransfer.appendChild($feFunc);
|
|
3011
|
+
});
|
|
3012
|
+
$filter.appendChild($feComponentTransfer);
|
|
3013
|
+
}
|
|
3058
3014
|
|
|
3015
|
+
function createContrast(document, $filter, params) {
|
|
3016
|
+
var slope = convertToAbsoluteValue(params[0]);
|
|
3017
|
+
createFeComponentTransfer(document, $filter, {
|
|
3018
|
+
type: 'linear',
|
|
3019
|
+
slope: slope,
|
|
3020
|
+
intercept: -(0.5 * slope) + 0.5
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3059
3023
|
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3024
|
+
function createInvert(document, $filter, params) {
|
|
3025
|
+
var amount = convertToAbsoluteValue(params[0]);
|
|
3026
|
+
createFeComponentTransfer(document, $filter, {
|
|
3027
|
+
type: 'table',
|
|
3028
|
+
tableValues: amount + " " + (1 - amount)
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3067
3031
|
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3032
|
+
function createBrightness(document, $filter, params) {
|
|
3033
|
+
var slope = convertToAbsoluteValue(params[0]);
|
|
3034
|
+
createFeComponentTransfer(document, $filter, {
|
|
3035
|
+
type: 'linear',
|
|
3036
|
+
slope: slope,
|
|
3037
|
+
intercept: 0
|
|
3038
|
+
});
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
function createSaturate(document, $filter, params) {
|
|
3042
|
+
var amount = convertToAbsoluteValue(params[0]);
|
|
3043
|
+
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
3044
|
+
$feColorMatrix.setAttribute('type', 'saturate');
|
|
3045
|
+
$feColorMatrix.setAttribute('values', "" + amount);
|
|
3046
|
+
$filter.appendChild($feColorMatrix);
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
function createHueRotate(document, $filter, params) {
|
|
3050
|
+
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
3051
|
+
$feColorMatrix.setAttribute('type', 'hueRotate');
|
|
3052
|
+
$feColorMatrix.setAttribute('values', "" + params[0].to(gLite.UnitType.kDegrees).value);
|
|
3053
|
+
$filter.appendChild($feColorMatrix);
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
function createDropShadow(document, $filter, params) {
|
|
3057
|
+
var shadowOffsetX = params[0].value;
|
|
3058
|
+
var shadowOffsetY = params[1].value;
|
|
3059
|
+
var shadowBlur = params[2].value; // @ts-ignore
|
|
3060
|
+
|
|
3061
|
+
var shadowColor = params[3].formatted;
|
|
3062
|
+
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
3063
|
+
$feGaussianBlur.setAttribute('in', 'SourceAlpha');
|
|
3064
|
+
$feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
|
|
3065
|
+
$filter.appendChild($feGaussianBlur);
|
|
3066
|
+
var $feOffset = createSVGElement('feOffset', document);
|
|
3067
|
+
$feOffset.setAttribute('dx', "" + shadowOffsetX);
|
|
3068
|
+
$feOffset.setAttribute('dy', "" + shadowOffsetY);
|
|
3069
|
+
$feOffset.setAttribute('result', 'offsetblur');
|
|
3070
|
+
$filter.appendChild($feOffset);
|
|
3071
|
+
var $feFlood = createSVGElement('feFlood', document);
|
|
3072
|
+
$feFlood.setAttribute('flood-color', shadowColor);
|
|
3073
|
+
$filter.appendChild($feFlood);
|
|
3074
|
+
var $feComposite = createSVGElement('feComposite', document);
|
|
3075
|
+
$feComposite.setAttribute('in2', 'offsetblur');
|
|
3076
|
+
$feComposite.setAttribute('operator', 'in');
|
|
3077
|
+
$filter.appendChild($feComposite);
|
|
3078
|
+
var $feMerge = createSVGElement('feMerge', document);
|
|
3079
|
+
$filter.appendChild($feMerge);
|
|
3080
|
+
var $feMergeNode1 = createSVGElement('feMergeNode', document);
|
|
3081
|
+
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
3082
|
+
$feMergeNode2.setAttribute('in', 'SourceGraphic');
|
|
3083
|
+
$feMerge.appendChild($feMergeNode1);
|
|
3084
|
+
$feMerge.appendChild($feMergeNode2);
|
|
3085
|
+
}
|
|
3121
3086
|
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3087
|
+
function createFeColorMatrix(document, $filter, matrix) {
|
|
3088
|
+
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
3089
|
+
$feColorMatrix.setAttribute('type', 'matrix');
|
|
3090
|
+
$feColorMatrix.setAttribute('values', matrix.join(' '));
|
|
3091
|
+
$filter.appendChild($feColorMatrix);
|
|
3092
|
+
}
|
|
3093
|
+
/**
|
|
3094
|
+
* @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
|
|
3095
|
+
*/
|
|
3127
3096
|
|
|
3128
3097
|
|
|
3129
|
-
|
|
3098
|
+
function createGrayscale(document, $filter, params) {
|
|
3099
|
+
var amount = convertToAbsoluteValue(params[0]);
|
|
3100
|
+
createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
|
|
3104
|
+
*/
|
|
3130
3105
|
|
|
3131
|
-
var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
|
|
3132
3106
|
|
|
3133
|
-
|
|
3107
|
+
function createSepia(document, $filter, params) {
|
|
3108
|
+
var amount = convertToAbsoluteValue(params[0]);
|
|
3109
|
+
createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
|
|
3110
|
+
}
|
|
3134
3111
|
|
|
3135
|
-
|
|
3136
|
-
|
|
3112
|
+
var PATTERN_PREFIX = 'g-pattern-';
|
|
3113
|
+
var cacheKey2IDMap = {};
|
|
3114
|
+
var counter = 0;
|
|
3137
3115
|
|
|
3138
|
-
|
|
3116
|
+
function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage) {
|
|
3117
|
+
// eg. clipPath don't have fill/stroke
|
|
3118
|
+
if (!parsedColor) {
|
|
3119
|
+
return '';
|
|
3120
|
+
}
|
|
3139
3121
|
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3122
|
+
if (parsedColor instanceof gLite.CSSRGB) {
|
|
3123
|
+
// keep using currentColor @see https://github.com/d3/d3-axis/issues/49
|
|
3124
|
+
if (object.style[name] === 'currentColor') {
|
|
3125
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
|
|
3126
|
+
} else {
|
|
3127
|
+
// constant value, eg. '#fff'
|
|
3128
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
|
|
3129
|
+
}
|
|
3130
|
+
} else if (gLite.isPattern(parsedColor)) {
|
|
3131
|
+
var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage); // use style instead of attribute when applying <pattern>
|
|
3132
|
+
// @see https://stackoverflow.com/a/7723115
|
|
3143
3133
|
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3134
|
+
$el.style[name] = "url(#" + patternId + ")";
|
|
3135
|
+
return patternId;
|
|
3136
|
+
} else {
|
|
3137
|
+
if (parsedColor.length === 1) {
|
|
3138
|
+
var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
|
|
3139
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
|
|
3140
|
+
return gradientId;
|
|
3141
|
+
} else {
|
|
3142
|
+
// @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
|
|
3143
|
+
var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
|
|
3144
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
|
|
3145
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
|
|
3146
|
+
return filterId;
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3147
3149
|
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
}
|
|
3150
|
+
return '';
|
|
3151
|
+
}
|
|
3151
3152
|
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
$groupEl = $el;
|
|
3157
|
-
}
|
|
3153
|
+
function generateCacheKey(src, options) {
|
|
3154
|
+
if (options === void 0) {
|
|
3155
|
+
options = {};
|
|
3156
|
+
}
|
|
3158
3157
|
|
|
3159
|
-
|
|
3160
|
-
svgElement.$groupEl = $groupEl; // apply attributes at first time
|
|
3158
|
+
var cacheKey = '';
|
|
3161
3159
|
|
|
3162
|
-
|
|
3160
|
+
if (src instanceof gLite.CSSGradientValue) {
|
|
3161
|
+
var type = src.type,
|
|
3162
|
+
value = src.value;
|
|
3163
3163
|
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3164
|
+
if (type === gLite.GradientType.LinearGradient || type === gLite.GradientType.RadialGradient) {
|
|
3165
|
+
// @ts-ignore
|
|
3166
|
+
var _value$options = _extends({}, value, options),
|
|
3167
|
+
_type = _value$options.type,
|
|
3168
|
+
width = _value$options.width,
|
|
3169
|
+
height = _value$options.height,
|
|
3170
|
+
steps = _value$options.steps,
|
|
3171
|
+
angle = _value$options.angle,
|
|
3172
|
+
cx = _value$options.cx,
|
|
3173
|
+
cy = _value$options.cy,
|
|
3174
|
+
size = _value$options.size;
|
|
3167
3175
|
|
|
3168
|
-
|
|
3169
|
-
|
|
3176
|
+
cacheKey = "gradient-" + _type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref) {
|
|
3177
|
+
var offset = _ref.offset,
|
|
3178
|
+
color = _ref.color;
|
|
3179
|
+
return "" + offset + color;
|
|
3180
|
+
}).join('-');
|
|
3181
|
+
}
|
|
3182
|
+
} else if (gLite.isPattern(src)) {
|
|
3183
|
+
if (isString(src.image)) {
|
|
3184
|
+
cacheKey = "pattern-" + src.image + "-" + src.repetition;
|
|
3185
|
+
} else {
|
|
3186
|
+
cacheKey = "pattern-" + counter;
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3170
3189
|
|
|
3171
|
-
|
|
3172
|
-
|
|
3190
|
+
if (cacheKey) {
|
|
3191
|
+
if (!cacheKey2IDMap[cacheKey]) {
|
|
3192
|
+
cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
|
|
3173
3193
|
}
|
|
3174
|
-
}
|
|
3194
|
+
}
|
|
3175
3195
|
|
|
3176
|
-
|
|
3177
|
-
|
|
3196
|
+
return cacheKey2IDMap[cacheKey];
|
|
3197
|
+
}
|
|
3178
3198
|
|
|
3199
|
+
function createOrUpdatePattern(document, $def, object, pattern, createImage) {
|
|
3200
|
+
var patternId = generateCacheKey(pattern);
|
|
3201
|
+
var $existed = $def.querySelector("#" + patternId);
|
|
3179
3202
|
|
|
3180
|
-
|
|
3203
|
+
if (!$existed) {
|
|
3204
|
+
var image = pattern.image,
|
|
3205
|
+
repetition = pattern.repetition;
|
|
3206
|
+
var imageURL = '';
|
|
3181
3207
|
|
|
3182
|
-
if (
|
|
3183
|
-
|
|
3184
|
-
|
|
3208
|
+
if (isString(image)) {
|
|
3209
|
+
imageURL = image;
|
|
3210
|
+
} else {
|
|
3211
|
+
if (gLite.isBrowser) {
|
|
3212
|
+
if (image instanceof HTMLImageElement) {
|
|
3213
|
+
imageURL = image.src;
|
|
3214
|
+
} else if (image instanceof HTMLCanvasElement) {
|
|
3215
|
+
imageURL = image.toDataURL();
|
|
3216
|
+
} else ;
|
|
3217
|
+
}
|
|
3185
3218
|
}
|
|
3186
|
-
};
|
|
3187
3219
|
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3220
|
+
if (imageURL) {
|
|
3221
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
|
|
3222
|
+
var $pattern = createSVGElement('pattern', document);
|
|
3223
|
+
$pattern.setAttribute('patternUnits', 'userSpaceOnUse');
|
|
3224
|
+
var $image = createSVGElement('image', document);
|
|
3225
|
+
$pattern.appendChild($image);
|
|
3226
|
+
$pattern.id = patternId;
|
|
3227
|
+
$def.appendChild($pattern); // use href instead of xlink:href
|
|
3228
|
+
// @see https://stackoverflow.com/a/13379007
|
|
3193
3229
|
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
$hitTestingEl = $el.cloneNode();
|
|
3230
|
+
$image.setAttribute('href', imageURL);
|
|
3231
|
+
var img;
|
|
3197
3232
|
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3233
|
+
if (createImage) {
|
|
3234
|
+
img = createImage(imageURL);
|
|
3235
|
+
} else if (gLite.isBrowser) {
|
|
3236
|
+
img = new window.Image();
|
|
3237
|
+
}
|
|
3202
3238
|
|
|
3239
|
+
if (!imageURL.match(/^data:/i)) {
|
|
3240
|
+
img.crossOrigin = 'Anonymous';
|
|
3241
|
+
$image.setAttribute('crossorigin', 'anonymous');
|
|
3242
|
+
}
|
|
3203
3243
|
|
|
3204
|
-
|
|
3205
|
-
$hitTestingEl.removeAttribute(attribute);
|
|
3206
|
-
}); // hitArea should be 'transparent' but not 'none'
|
|
3244
|
+
img.src = imageURL;
|
|
3207
3245
|
|
|
3208
|
-
|
|
3209
|
-
$
|
|
3210
|
-
$
|
|
3211
|
-
$groupEl.appendChild($hitTestingEl);
|
|
3212
|
-
svgElement.$hitTestingEl = $hitTestingEl;
|
|
3213
|
-
} // increase interactive line width
|
|
3246
|
+
var onload = function onload() {
|
|
3247
|
+
$pattern.setAttribute('x', '0');
|
|
3248
|
+
$pattern.setAttribute('y', '0');
|
|
3214
3249
|
|
|
3250
|
+
var _object$getGeometryBo = object.getGeometryBounds(),
|
|
3251
|
+
halfExtents = _object$getGeometryBo.halfExtents; // There is no equivalent to CSS no-repeat for SVG patterns
|
|
3252
|
+
// @see https://stackoverflow.com/a/33481956
|
|
3215
3253
|
|
|
3216
|
-
$hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
|
|
3217
|
-
} else {
|
|
3218
|
-
if ($hitTestingEl) {
|
|
3219
|
-
$groupEl.removeChild($hitTestingEl);
|
|
3220
|
-
svgElement.$hitTestingEl = null;
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
};
|
|
3224
3254
|
|
|
3225
|
-
|
|
3226
|
-
|
|
3255
|
+
var patternWidth = img.width;
|
|
3256
|
+
var patternHeight = img.height;
|
|
3227
3257
|
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3258
|
+
if (repetition === 'repeat-x') {
|
|
3259
|
+
patternHeight = halfExtents[1] * 2;
|
|
3260
|
+
} else if (repetition === 'repeat-y') {
|
|
3261
|
+
patternWidth = halfExtents[0] * 2;
|
|
3262
|
+
} else if (repetition === 'no-repeat') {
|
|
3263
|
+
patternWidth = halfExtents[0] * 2;
|
|
3264
|
+
patternHeight = halfExtents[1] * 2;
|
|
3265
|
+
}
|
|
3233
3266
|
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3267
|
+
$pattern.setAttribute('width', "" + patternWidth);
|
|
3268
|
+
$pattern.setAttribute('height', "" + patternHeight);
|
|
3269
|
+
$image.setAttribute('x', '0');
|
|
3270
|
+
$image.setAttribute('y', '0');
|
|
3271
|
+
$image.setAttribute('width', "" + img.width);
|
|
3272
|
+
$image.setAttribute('height', "" + img.height);
|
|
3273
|
+
};
|
|
3274
|
+
|
|
3275
|
+
if (img.complete) {
|
|
3276
|
+
onload();
|
|
3277
|
+
} else {
|
|
3278
|
+
img.onload = onload; // Fix onload() bug in IE9
|
|
3237
3279
|
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
isTextPath = false;
|
|
3280
|
+
img.src = img.src;
|
|
3281
|
+
}
|
|
3241
3282
|
}
|
|
3283
|
+
}
|
|
3242
3284
|
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
|
|
3246
|
-
|
|
3247
|
-
if (clipPath) {
|
|
3248
|
-
var _clipPath$elementSVG;
|
|
3285
|
+
return patternId;
|
|
3286
|
+
}
|
|
3249
3287
|
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3288
|
+
function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
|
|
3289
|
+
var bounds = object.getGeometryBounds();
|
|
3290
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
3291
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
3292
|
+
var gradientId = generateCacheKey(parsedColor, {
|
|
3293
|
+
width: width,
|
|
3294
|
+
height: height
|
|
3295
|
+
});
|
|
3296
|
+
var $existed = $def.querySelector("#" + gradientId);
|
|
3253
3297
|
|
|
3254
|
-
|
|
3255
|
-
|
|
3298
|
+
if (!$existed) {
|
|
3299
|
+
// <linearGradient> <radialGradient>
|
|
3300
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
|
|
3301
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
|
|
3302
|
+
$existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document); // @see https://github.com/antvis/g/issues/1025
|
|
3256
3303
|
|
|
3257
|
-
|
|
3258
|
-
// use <path> directly instead of wrapping with <g>
|
|
3259
|
-
this.createSVGDom(document, clipPath, null, true); // @ts-ignore
|
|
3304
|
+
$existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
|
|
3260
3305
|
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3306
|
+
var innerHTML = '';
|
|
3307
|
+
parsedColor.value.steps // sort by offset @see https://github.com/antvis/G/issues/1171
|
|
3308
|
+
.sort(function (a, b) {
|
|
3309
|
+
return a.offset.value - b.offset.value;
|
|
3310
|
+
}).forEach(function (_ref2) {
|
|
3311
|
+
var offset = _ref2.offset,
|
|
3312
|
+
color = _ref2.color; // TODO: support absolute unit like `px`
|
|
3265
3313
|
|
|
3266
|
-
|
|
3314
|
+
innerHTML += "<stop offset=\"" + offset.value / 100 + "\" stop-color=\"" + color + "\"></stop>";
|
|
3315
|
+
});
|
|
3316
|
+
$existed.innerHTML = innerHTML;
|
|
3317
|
+
$existed.id = gradientId;
|
|
3318
|
+
$def.appendChild($existed);
|
|
3319
|
+
}
|
|
3267
3320
|
|
|
3268
|
-
|
|
3269
|
-
|
|
3321
|
+
if (parsedColor.type === gLite.GradientType.LinearGradient) {
|
|
3322
|
+
var angle = parsedColor.value.angle;
|
|
3270
3323
|
|
|
3271
|
-
|
|
3324
|
+
var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
|
|
3325
|
+
x1 = _computeLinearGradien.x1,
|
|
3326
|
+
y1 = _computeLinearGradien.y1,
|
|
3327
|
+
x2 = _computeLinearGradien.x2,
|
|
3328
|
+
y2 = _computeLinearGradien.y2;
|
|
3272
3329
|
|
|
3273
|
-
|
|
3274
|
-
|
|
3330
|
+
$existed.setAttribute('x1', "" + x1);
|
|
3331
|
+
$existed.setAttribute('y1', "" + y1);
|
|
3332
|
+
$existed.setAttribute('x2', "" + x2);
|
|
3333
|
+
$existed.setAttribute('y2', "" + y2); // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
|
|
3334
|
+
} else {
|
|
3335
|
+
var _parsedColor$value = parsedColor.value,
|
|
3336
|
+
cx = _parsedColor$value.cx,
|
|
3337
|
+
cy = _parsedColor$value.cy,
|
|
3338
|
+
size = _parsedColor$value.size;
|
|
3275
3339
|
|
|
3340
|
+
var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
|
|
3341
|
+
x = _computeRadialGradien.x,
|
|
3342
|
+
y = _computeRadialGradien.y,
|
|
3343
|
+
r = _computeRadialGradien.r;
|
|
3276
3344
|
|
|
3277
|
-
|
|
3345
|
+
$existed.setAttribute('cx', "" + x);
|
|
3346
|
+
$existed.setAttribute('cy', "" + y);
|
|
3347
|
+
$existed.setAttribute('r', "" + r);
|
|
3348
|
+
}
|
|
3278
3349
|
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
this.applyTransform($clipPathGroupEl, clipPath.getLocalTransform());
|
|
3282
|
-
} // apply attributes
|
|
3350
|
+
return gradientId;
|
|
3351
|
+
}
|
|
3283
3352
|
|
|
3353
|
+
function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
|
|
3354
|
+
var filterId = FILTER_PREFIX + object.entity + '-gradient';
|
|
3355
|
+
var $existed = $def.querySelector("#" + filterId);
|
|
3284
3356
|
|
|
3285
|
-
|
|
3357
|
+
if (!$existed) {
|
|
3358
|
+
$existed = createSVGElement('filter', document);
|
|
3359
|
+
$existed.setAttribute('filterUnits', 'userSpaceOnUse'); // @see https://github.com/antvis/g/issues/1025
|
|
3286
3360
|
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
if (!isTextPath) {
|
|
3294
|
-
// remove clip path
|
|
3295
|
-
$groupEl.removeAttribute(attributeNameHyphen);
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3361
|
+
$existed.setAttribute('x', '0%');
|
|
3362
|
+
$existed.setAttribute('y', '0%');
|
|
3363
|
+
$existed.setAttribute('width', '100%');
|
|
3364
|
+
$existed.setAttribute('height', '100%');
|
|
3365
|
+
$existed.id = filterId;
|
|
3366
|
+
$def.appendChild($existed);
|
|
3298
3367
|
}
|
|
3299
3368
|
/**
|
|
3300
|
-
*
|
|
3369
|
+
* <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
|
|
3370
|
+
* <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
|
|
3371
|
+
<feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
|
|
3372
|
+
<feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
|
|
3373
|
+
<feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
|
|
3374
|
+
<feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
|
|
3375
|
+
</filter>
|
|
3301
3376
|
*/
|
|
3302
|
-
;
|
|
3303
|
-
|
|
3304
|
-
_proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
|
|
3305
|
-
var _object$elementSVG7, _object$elementSVG8;
|
|
3306
|
-
|
|
3307
|
-
var bounds = object.getGeometryBounds();
|
|
3308
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
3309
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
3310
|
-
|
|
3311
|
-
var _ref2 = object.parsedStyle || {},
|
|
3312
|
-
anchor = _ref2.anchor; // @ts-ignore
|
|
3313
|
-
|
|
3314
3377
|
|
|
3315
|
-
[(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
|
|
3316
|
-
if ($el) {
|
|
3317
|
-
var tx = -(anchor[0] * width);
|
|
3318
|
-
var ty = -(anchor[1] * height);
|
|
3319
3378
|
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3379
|
+
var blended = 0;
|
|
3380
|
+
gradients.forEach(function (gradient, i) {
|
|
3381
|
+
var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
|
|
3382
|
+
var rectId = gradientId + '_rect';
|
|
3383
|
+
var $rect = createSVGElement('rect', document);
|
|
3384
|
+
$rect.setAttribute('x', '0');
|
|
3385
|
+
$rect.setAttribute('y', '0');
|
|
3386
|
+
$rect.setAttribute('width', '100%');
|
|
3387
|
+
$rect.setAttribute('height', '100%');
|
|
3388
|
+
$rect.setAttribute('fill', "url(#" + gradientId + ")");
|
|
3389
|
+
$rect.id = rectId;
|
|
3390
|
+
$def.appendChild($rect);
|
|
3391
|
+
var $feImage = createSVGElement('feImage', document);
|
|
3392
|
+
$feImage.setAttribute('href', "#" + rectId);
|
|
3393
|
+
$feImage.setAttribute('result', filterId + "-" + i);
|
|
3394
|
+
$existed.appendChild($feImage);
|
|
3326
3395
|
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
});
|
|
3333
|
-
};
|
|
3396
|
+
if (i > 0) {
|
|
3397
|
+
var $feBlend = createSVGElement('feBlend', document);
|
|
3398
|
+
$feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
|
|
3399
|
+
$feBlend.setAttribute('in2', filterId + "-" + i);
|
|
3400
|
+
$feBlend.setAttribute('result', filterId + "-blended-" + blended++); // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
|
|
3334
3401
|
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
hanging: 'hanging'
|
|
3347
|
-
}; // for FireFox
|
|
3348
|
-
// @see https://github.com/plouc/nivo/issues/164
|
|
3402
|
+
$feBlend.setAttribute('mode', 'multiply');
|
|
3403
|
+
$existed.appendChild($feBlend);
|
|
3404
|
+
}
|
|
3405
|
+
});
|
|
3406
|
+
var $feComposite = createSVGElement('feComposite', document);
|
|
3407
|
+
$feComposite.setAttribute('in', filterId + "-blended-" + blended);
|
|
3408
|
+
$feComposite.setAttribute('in2', 'SourceGraphic');
|
|
3409
|
+
$feComposite.setAttribute('operator', 'in');
|
|
3410
|
+
$existed.appendChild($feComposite);
|
|
3411
|
+
return filterId;
|
|
3412
|
+
}
|
|
3349
3413
|
|
|
3350
|
-
var
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
ideographic: 'ideographic',
|
|
3356
|
-
hanging: 'hanging'
|
|
3357
|
-
};
|
|
3414
|
+
var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
|
|
3415
|
+
/**
|
|
3416
|
+
* use SVG filters
|
|
3417
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
3418
|
+
*/
|
|
3358
3419
|
|
|
3359
|
-
function
|
|
3360
|
-
var
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
|
|
3370
|
-
_parsedStyle$textDeco = parsedStyle.textDecorationLine,
|
|
3371
|
-
textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
|
|
3372
|
-
_parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
|
|
3373
|
-
textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
|
|
3374
|
-
_parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
|
|
3375
|
-
textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3;
|
|
3376
|
-
var browser = detect();
|
|
3420
|
+
function createOrUpdateShadow(document, $def, object, $el, name) {
|
|
3421
|
+
var _object$parsedStyle = object.parsedStyle,
|
|
3422
|
+
shadowType = _object$parsedStyle.shadowType,
|
|
3423
|
+
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
3424
|
+
shadowColor = _object$parsedStyle.shadowColor,
|
|
3425
|
+
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
3426
|
+
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
3427
|
+
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
3428
|
+
var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
|
|
3429
|
+
var $existedFilter = $def.querySelector("#" + shadowId);
|
|
3377
3430
|
|
|
3378
|
-
if (
|
|
3379
|
-
|
|
3380
|
-
$el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline] || 'alphabetic');
|
|
3381
|
-
} else {
|
|
3382
|
-
$el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline]);
|
|
3383
|
-
$el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline]);
|
|
3384
|
-
}
|
|
3431
|
+
if ($existedFilter) {
|
|
3432
|
+
var existedShadowType = $existedFilter.getAttribute('data-type');
|
|
3385
3433
|
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3434
|
+
if (existedShadowType !== shadowType || !hasShadow) {
|
|
3435
|
+
// remove existed shadow
|
|
3436
|
+
$existedFilter.remove();
|
|
3437
|
+
$existedFilter = null;
|
|
3438
|
+
}
|
|
3439
|
+
} // <Group> also has shadowType as its default value
|
|
3440
|
+
// only apply shadow when blur > 0
|
|
3392
3441
|
|
|
3393
|
-
if (dx !== 0 || dy !== 0) {
|
|
3394
|
-
styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
|
|
3395
|
-
}
|
|
3396
3442
|
|
|
3397
|
-
if (
|
|
3398
|
-
// use
|
|
3399
|
-
|
|
3443
|
+
if (hasShadow) {
|
|
3444
|
+
// use filter <feDropShadow>
|
|
3445
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
|
|
3446
|
+
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
|
|
3447
|
+
} else {
|
|
3448
|
+
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
3449
|
+
return;
|
|
3400
3450
|
}
|
|
3401
3451
|
|
|
3402
|
-
if (
|
|
3403
|
-
$
|
|
3404
|
-
|
|
3452
|
+
if (!$existedFilter) {
|
|
3453
|
+
$existedFilter = createSVGElement('filter', document);
|
|
3454
|
+
$existedFilter.setAttribute('data-type', shadowType);
|
|
3405
3455
|
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3456
|
+
if (shadowType === 'outer') {
|
|
3457
|
+
var $feDropShadow = createSVGElement('feDropShadow', document);
|
|
3458
|
+
$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
3459
|
+
$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
3460
|
+
$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
3461
|
+
$feDropShadow.setAttribute('flood-color', shadowColor.toString());
|
|
3462
|
+
$existedFilter.appendChild($feDropShadow);
|
|
3463
|
+
} else if (shadowType === 'inner') {
|
|
3464
|
+
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
3465
|
+
$feComponentTransfer.setAttribute('in', 'SourceAlpha');
|
|
3466
|
+
var $feFuncA = createSVGElement('feFuncA', document);
|
|
3467
|
+
$feFuncA.setAttribute('type', 'table');
|
|
3468
|
+
$feFuncA.setAttribute('tableValues', '1 0');
|
|
3469
|
+
$feComponentTransfer.appendChild($feFuncA);
|
|
3470
|
+
$existedFilter.appendChild($feComponentTransfer);
|
|
3471
|
+
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
3472
|
+
$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
3473
|
+
$existedFilter.appendChild($feGaussianBlur);
|
|
3474
|
+
var $feOffset = createSVGElement('feOffset', document);
|
|
3475
|
+
$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
3476
|
+
$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
3477
|
+
$feOffset.setAttribute('result', 'offsetblur');
|
|
3478
|
+
$existedFilter.appendChild($feOffset);
|
|
3479
|
+
var $feFlood = createSVGElement('feFlood', document);
|
|
3480
|
+
$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
3481
|
+
$feFlood.setAttribute('result', 'color');
|
|
3482
|
+
$existedFilter.appendChild($feFlood);
|
|
3483
|
+
var $feComposite = createSVGElement('feComposite', document);
|
|
3484
|
+
$feComposite.setAttribute('in2', 'offsetblur');
|
|
3485
|
+
$feComposite.setAttribute('operator', 'in');
|
|
3486
|
+
$existedFilter.appendChild($feComposite);
|
|
3487
|
+
var $feComposite2 = createSVGElement('feComposite', document);
|
|
3488
|
+
$feComposite2.setAttribute('in2', 'SourceAlpha');
|
|
3489
|
+
$feComposite2.setAttribute('operator', 'in');
|
|
3490
|
+
$existedFilter.appendChild($feComposite2);
|
|
3491
|
+
var $feMerge = createSVGElement('feMerge', document);
|
|
3492
|
+
$existedFilter.appendChild($feMerge);
|
|
3493
|
+
var $feMergeNode = createSVGElement('feMergeNode', document);
|
|
3494
|
+
$feMergeNode.setAttribute('in', 'SourceGraphic');
|
|
3495
|
+
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
3496
|
+
$feMerge.appendChild($feMergeNode);
|
|
3497
|
+
$feMerge.appendChild($feMergeNode2);
|
|
3498
|
+
}
|
|
3410
3499
|
|
|
3411
|
-
|
|
3412
|
-
// clear existed text content first
|
|
3413
|
-
$el.innerHTML = ''; // append <textPath href="#MyPath">text</textPath>
|
|
3500
|
+
$existedFilter.id = shadowId; // @see https://github.com/antvis/g/issues/1025
|
|
3414
3501
|
|
|
3415
|
-
|
|
3416
|
-
|
|
3502
|
+
$existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
3503
|
+
$def.appendChild($existedFilter);
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3417
3506
|
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3507
|
+
if (shadowType === 'inner') {
|
|
3508
|
+
var _$feGaussianBlur = $existedFilter.children[1];
|
|
3509
|
+
var _$feOffset = $existedFilter.children[2];
|
|
3510
|
+
var _$feFlood = $existedFilter.children[3];
|
|
3421
3511
|
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3512
|
+
if (name === 'shadowColor') {
|
|
3513
|
+
_$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
3514
|
+
} else if (name === 'shadowBlur') {
|
|
3515
|
+
// half the blur radius
|
|
3516
|
+
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
3517
|
+
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
3518
|
+
_$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
3519
|
+
} else if (name === 'shadowOffsetX') {
|
|
3520
|
+
_$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
3521
|
+
} else if (name === 'shadowOffsetY') {
|
|
3522
|
+
_$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
3523
|
+
}
|
|
3524
|
+
} else if (shadowType === 'outer') {
|
|
3525
|
+
var _$feDropShadow = $existedFilter.children[0];
|
|
3425
3526
|
|
|
3426
|
-
|
|
3427
|
-
$
|
|
3428
|
-
} else {
|
|
3429
|
-
|
|
3527
|
+
if (name === 'shadowColor') {
|
|
3528
|
+
_$feDropShadow.setAttribute('flood-color', shadowColor.toString());
|
|
3529
|
+
} else if (name === 'shadowBlur') {
|
|
3530
|
+
// half the blur radius
|
|
3531
|
+
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
3532
|
+
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
3533
|
+
_$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
3534
|
+
} else if (name === 'shadowOffsetX') {
|
|
3535
|
+
_$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
3536
|
+
} else if (name === 'shadowOffsetY') {
|
|
3537
|
+
_$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
3430
3538
|
}
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
|
-
var dx = lineWidth / 2;
|
|
3434
|
-
var dy = 0;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3435
3541
|
|
|
3436
|
-
|
|
3437
|
-
// TODO: handle other textBaseline values
|
|
3438
|
-
if (textBaseline === 'middle') {
|
|
3439
|
-
dy = lineHeight / 2 - height / 2;
|
|
3440
|
-
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
3441
|
-
dy = 0;
|
|
3442
|
-
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
3443
|
-
dy = -lineHeight * (lineNum - 1);
|
|
3444
|
-
}
|
|
3445
|
-
} else {
|
|
3446
|
-
dy = lineHeight;
|
|
3447
|
-
}
|
|
3542
|
+
var urlRegexp = /url\(#(.*)\)/;
|
|
3448
3543
|
|
|
3449
|
-
|
|
3450
|
-
|
|
3544
|
+
var DefElementManager = /*#__PURE__*/function () {
|
|
3545
|
+
function DefElementManager(context) {
|
|
3546
|
+
this.context = void 0;
|
|
3547
|
+
this.$def = void 0;
|
|
3548
|
+
this.gradientCache = {};
|
|
3549
|
+
this.context = context;
|
|
3451
3550
|
}
|
|
3452
|
-
|
|
3551
|
+
/**
|
|
3552
|
+
* container for <gradient> <clipPath>...
|
|
3553
|
+
*/
|
|
3453
3554
|
|
|
3454
|
-
var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
|
|
3455
3555
|
|
|
3456
|
-
|
|
3457
|
-
var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[gLite.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[gLite.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[gLite.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[gLite.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[gLite.Shape.LINE] = ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYLINE] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYGON] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.PATH] = ['path', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'maxLines', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'textOverflow', 'textPath', 'textPathSide', 'textPathStartOffset', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle', // 'whiteSpace',
|
|
3458
|
-
'dx', 'dy'], _SHAPE_UPDATE_DEPS);
|
|
3556
|
+
var _proto = DefElementManager.prototype;
|
|
3459
3557
|
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
this.canvasConfig = canvasConfig;
|
|
3464
|
-
}
|
|
3558
|
+
_proto.getDefElement = function getDefElement() {
|
|
3559
|
+
return this.$def;
|
|
3560
|
+
};
|
|
3465
3561
|
|
|
3466
|
-
|
|
3562
|
+
_proto.init = function init() {
|
|
3563
|
+
var document = this.context.config.document;
|
|
3564
|
+
var $svg = this.context.contextService.getContext();
|
|
3565
|
+
this.$def = createSVGElement('defs', document);
|
|
3566
|
+
$svg.appendChild(this.$def);
|
|
3567
|
+
};
|
|
3467
3568
|
|
|
3468
|
-
_proto.
|
|
3469
|
-
var
|
|
3470
|
-
|
|
3471
|
-
|
|
3569
|
+
_proto.clear = function clear(entity) {
|
|
3570
|
+
var _this = this;
|
|
3571
|
+
|
|
3572
|
+
Object.keys(this.gradientCache).forEach(function (id) {
|
|
3573
|
+
_this.clearUnusedDefElement(_this.gradientCache, id, entity);
|
|
3574
|
+
});
|
|
3472
3575
|
};
|
|
3473
3576
|
|
|
3474
|
-
_proto.
|
|
3577
|
+
_proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
|
|
3578
|
+
if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
|
|
3579
|
+
var targetElement = this.$def.querySelector("#" + id);
|
|
3475
3580
|
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3581
|
+
if (targetElement) {
|
|
3582
|
+
this.$def.removeChild(targetElement);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3479
3585
|
};
|
|
3480
3586
|
|
|
3481
|
-
_proto.
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
parsedStyle = object.parsedStyle;
|
|
3587
|
+
_proto.createOrUpdateGradientAndPattern = function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name) {
|
|
3588
|
+
var _this$context$config = this.context.config,
|
|
3589
|
+
doc = _this$context$config.document,
|
|
3590
|
+
createImage = _this$context$config.createImage;
|
|
3486
3591
|
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
{
|
|
3490
|
-
updateImageElementAttribute($el, parsedStyle);
|
|
3491
|
-
break;
|
|
3492
|
-
}
|
|
3592
|
+
if ($el) {
|
|
3593
|
+
var _$el$getAttribute; // `url(#${gradientId})`
|
|
3493
3594
|
|
|
3494
|
-
case gLite.Shape.RECT:
|
|
3495
|
-
{
|
|
3496
|
-
updateRectElementAttribute($el, parsedStyle);
|
|
3497
|
-
break;
|
|
3498
|
-
}
|
|
3499
3595
|
|
|
3500
|
-
|
|
3501
|
-
{
|
|
3502
|
-
updateLineElementAttribute($el, parsedStyle);
|
|
3503
|
-
break;
|
|
3504
|
-
}
|
|
3596
|
+
var matches = (_$el$getAttribute = $el.getAttribute(name)) === null || _$el$getAttribute === void 0 ? void 0 : _$el$getAttribute.match(urlRegexp);
|
|
3505
3597
|
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
updatePolylineElementAttribute($el, parsedStyle);
|
|
3510
|
-
break;
|
|
3511
|
-
}
|
|
3598
|
+
if (matches && matches.length > 1) {
|
|
3599
|
+
this.clearUnusedDefElement(this.gradientCache, matches[1], object.entity);
|
|
3600
|
+
}
|
|
3512
3601
|
|
|
3513
|
-
|
|
3514
|
-
{
|
|
3515
|
-
updatePathElementAttribute($el, parsedStyle);
|
|
3516
|
-
break;
|
|
3517
|
-
}
|
|
3602
|
+
var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage);
|
|
3518
3603
|
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3604
|
+
if (!this.gradientCache[newDefElementId]) {
|
|
3605
|
+
this.gradientCache[newDefElementId] = new Set();
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3608
|
+
this.gradientCache[newDefElementId].add(object.entity);
|
|
3524
3609
|
}
|
|
3525
3610
|
};
|
|
3526
3611
|
|
|
3527
|
-
|
|
3528
|
-
|
|
3612
|
+
_proto.createOrUpdateShadow = function createOrUpdateShadow$1(object, $el, name) {
|
|
3613
|
+
var doc = this.context.config.document;
|
|
3614
|
+
createOrUpdateShadow(doc || document, this.$def, object, $el, name);
|
|
3615
|
+
};
|
|
3529
3616
|
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
});
|
|
3617
|
+
_proto.createOrUpdateFilter = function createOrUpdateFilter$1(object, $el, filters) {
|
|
3618
|
+
var doc = this.context.config.document;
|
|
3619
|
+
createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
|
|
3620
|
+
};
|
|
3621
|
+
|
|
3622
|
+
return DefElementManager;
|
|
3623
|
+
}();
|
|
3538
3624
|
|
|
3539
3625
|
var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
3540
3626
|
_inheritsLoose$2(Plugin, _AbstractRendererPlug);
|
|
@@ -3559,18 +3645,27 @@
|
|
|
3559
3645
|
var _this$options = this.options,
|
|
3560
3646
|
outputSVGElementId = _this$options.outputSVGElementId,
|
|
3561
3647
|
outputSVGElementName = _this$options.outputSVGElementName;
|
|
3562
|
-
this.
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
this.
|
|
3648
|
+
var defElementManager = new DefElementManager(this.context); // default implementation
|
|
3649
|
+
|
|
3650
|
+
var defaultElementLifeCycleContribution = new DefaultElementLifeCycleContribution(this.context); // @ts-ignore
|
|
3651
|
+
|
|
3652
|
+
this.context.defaultElementLifeCycleContribution = defaultElementLifeCycleContribution; // @ts-ignore
|
|
3653
|
+
|
|
3654
|
+
this.context.SVGElementLifeCycleContribution = defaultElementLifeCycleContribution;
|
|
3655
|
+
var SVGRendererPluginOptions = {
|
|
3656
|
+
outputSVGElementId: !isNil(outputSVGElementId) ? !!outputSVGElementId : true,
|
|
3657
|
+
outputSVGElementName: !isNil(outputSVGElementName) ? !!outputSVGElementName : true
|
|
3658
|
+
};
|
|
3659
|
+
this.addRenderingPlugin( // @ts-ignore
|
|
3660
|
+
new SVGRendererPlugin(SVGRendererPluginOptions, defElementManager, this.context));
|
|
3569
3661
|
};
|
|
3570
3662
|
|
|
3571
3663
|
_proto.destroy = function destroy() {
|
|
3572
|
-
this.
|
|
3573
|
-
|
|
3664
|
+
this.removeAllRenderingPlugins(); // @ts-ignore
|
|
3665
|
+
|
|
3666
|
+
delete this.context.defaultElementLifeCycleContribution; // @ts-ignore
|
|
3667
|
+
|
|
3668
|
+
delete this.context.SVGElementLifeCycleContribution;
|
|
3574
3669
|
};
|
|
3575
3670
|
|
|
3576
3671
|
return Plugin;
|
|
@@ -3580,18 +3675,15 @@
|
|
|
3580
3675
|
__proto__: null,
|
|
3581
3676
|
CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
|
|
3582
3677
|
DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
|
|
3583
|
-
|
|
3584
|
-
ElementLifeCycleContribution: ElementLifeCycleContribution,
|
|
3678
|
+
DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
|
|
3585
3679
|
ElementSVG: ElementSVG,
|
|
3586
3680
|
G_SVG_PREFIX: G_SVG_PREFIX,
|
|
3587
3681
|
Plugin: Plugin$1,
|
|
3588
3682
|
SHAPE2TAGS: SHAPE2TAGS,
|
|
3589
3683
|
SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
|
|
3590
|
-
|
|
3591
|
-
SVGRendererPluginOptions: SVGRendererPluginOptions,
|
|
3684
|
+
SVGRendererPlugin: SVGRendererPlugin,
|
|
3592
3685
|
SVG_ATTR_MAP: SVG_ATTR_MAP,
|
|
3593
3686
|
TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
|
|
3594
|
-
containerModule: containerModule$1,
|
|
3595
3687
|
createSVGElement: createSVGElement,
|
|
3596
3688
|
updateImageElementAttribute: updateImageElementAttribute,
|
|
3597
3689
|
updateLineElementAttribute: updateLineElementAttribute,
|
|
@@ -4041,10 +4133,6 @@
|
|
|
4041
4133
|
|
|
4042
4134
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
4043
4135
|
}
|
|
4044
|
-
|
|
4045
|
-
var _class$2;
|
|
4046
|
-
|
|
4047
|
-
var SVGPickerPlugin_1;
|
|
4048
4136
|
/**
|
|
4049
4137
|
* pick shape(s) with Mouse/Touch event
|
|
4050
4138
|
*
|
|
@@ -4052,21 +4140,18 @@
|
|
|
4052
4140
|
* 2. use elementFromPoint
|
|
4053
4141
|
*/
|
|
4054
4142
|
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
this.displayObjectPool = void 0;
|
|
4059
|
-
this.canvasConfig = canvasConfig;
|
|
4060
|
-
this.displayObjectPool = displayObjectPool;
|
|
4061
|
-
}
|
|
4143
|
+
|
|
4144
|
+
var SVGPickerPlugin = /*#__PURE__*/function () {
|
|
4145
|
+
function SVGPickerPlugin() {}
|
|
4062
4146
|
|
|
4063
4147
|
var _proto = SVGPickerPlugin.prototype;
|
|
4064
4148
|
|
|
4065
|
-
_proto.apply = function apply(
|
|
4149
|
+
_proto.apply = function apply(context) {
|
|
4066
4150
|
var _this = this;
|
|
4067
4151
|
|
|
4068
|
-
var doc =
|
|
4069
|
-
|
|
4152
|
+
var doc = context.config.document,
|
|
4153
|
+
renderingService = context.renderingService;
|
|
4154
|
+
renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
|
|
4070
4155
|
var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
|
|
4071
4156
|
return _regeneratorRuntime$3().wrap(function _callee$(_context) {
|
|
4072
4157
|
while (1) {
|
|
@@ -4086,7 +4171,7 @@
|
|
|
4086
4171
|
return _ref.apply(this, arguments);
|
|
4087
4172
|
};
|
|
4088
4173
|
}());
|
|
4089
|
-
renderingService.hooks.pickSync.tap(
|
|
4174
|
+
renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
|
|
4090
4175
|
return _this.pick(doc, result);
|
|
4091
4176
|
});
|
|
4092
4177
|
};
|
|
@@ -4107,7 +4192,7 @@
|
|
|
4107
4192
|
|
|
4108
4193
|
if (id && id.startsWith(G_SVG_PREFIX)) {
|
|
4109
4194
|
var index = id.lastIndexOf('_');
|
|
4110
|
-
var target =
|
|
4195
|
+
var target = gLite.runtime.displayObjectPool.getByEntity(Number(id.substring(index + 1))); // don't need to account for `visibility` since DOM API already does
|
|
4111
4196
|
|
|
4112
4197
|
if (target && target.isInteractive()) {
|
|
4113
4198
|
targets.push(target);
|
|
@@ -4129,13 +4214,9 @@
|
|
|
4129
4214
|
};
|
|
4130
4215
|
|
|
4131
4216
|
return SVGPickerPlugin;
|
|
4132
|
-
}()
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
}), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.DisplayObjectPool))], SVGPickerPlugin);
|
|
4136
|
-
var containerModule$2 = gLite.Module(function (register) {
|
|
4137
|
-
register(SVGPickerPlugin);
|
|
4138
|
-
});
|
|
4217
|
+
}();
|
|
4218
|
+
|
|
4219
|
+
SVGPickerPlugin.tag = 'SVGPicker';
|
|
4139
4220
|
|
|
4140
4221
|
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4141
4222
|
_inheritsLoose$3(Plugin, _AbstractRendererPlug);
|
|
@@ -4155,11 +4236,11 @@
|
|
|
4155
4236
|
var _proto = Plugin.prototype;
|
|
4156
4237
|
|
|
4157
4238
|
_proto.init = function init() {
|
|
4158
|
-
this.
|
|
4239
|
+
this.addRenderingPlugin(new SVGPickerPlugin());
|
|
4159
4240
|
};
|
|
4160
4241
|
|
|
4161
4242
|
_proto.destroy = function destroy() {
|
|
4162
|
-
this.
|
|
4243
|
+
this.removeAllRenderingPlugins();
|
|
4163
4244
|
};
|
|
4164
4245
|
|
|
4165
4246
|
return Plugin;
|
|
@@ -4171,12 +4252,12 @@
|
|
|
4171
4252
|
});
|
|
4172
4253
|
|
|
4173
4254
|
var SVGContextService = /*#__PURE__*/function () {
|
|
4174
|
-
function SVGContextService(
|
|
4175
|
-
this.canvasConfig = void 0;
|
|
4255
|
+
function SVGContextService(context) {
|
|
4176
4256
|
this.$container = void 0;
|
|
4177
4257
|
this.$namespace = void 0;
|
|
4178
4258
|
this.dpr = void 0;
|
|
4179
|
-
this.canvasConfig =
|
|
4259
|
+
this.canvasConfig = void 0;
|
|
4260
|
+
this.canvasConfig = context.config;
|
|
4180
4261
|
}
|
|
4181
4262
|
|
|
4182
4263
|
var _proto = SVGContextService.prototype;
|
|
@@ -4297,16 +4378,6 @@
|
|
|
4297
4378
|
return SVGContextService;
|
|
4298
4379
|
}();
|
|
4299
4380
|
|
|
4300
|
-
SVGContextService = __decorate([gLite.singleton({
|
|
4301
|
-
token: gLite.ContextService
|
|
4302
|
-
}), __param(0, gLite.inject(gLite.CanvasConfig))], SVGContextService);
|
|
4303
|
-
|
|
4304
|
-
var containerModule$3 = gLite.Module(function (register) {
|
|
4305
|
-
/**
|
|
4306
|
-
* implements ContextService
|
|
4307
|
-
*/
|
|
4308
|
-
register(SVGContextService);
|
|
4309
|
-
});
|
|
4310
4381
|
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4311
4382
|
_inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
4312
4383
|
|
|
@@ -4325,11 +4396,12 @@
|
|
|
4325
4396
|
var _proto = ContextRegisterPlugin.prototype;
|
|
4326
4397
|
|
|
4327
4398
|
_proto.init = function init() {
|
|
4328
|
-
|
|
4399
|
+
// @ts-ignore
|
|
4400
|
+
this.context.ContextService = SVGContextService;
|
|
4329
4401
|
};
|
|
4330
4402
|
|
|
4331
4403
|
_proto.destroy = function destroy() {
|
|
4332
|
-
this.
|
|
4404
|
+
delete this.context.ContextService;
|
|
4333
4405
|
};
|
|
4334
4406
|
|
|
4335
4407
|
return ContextRegisterPlugin;
|