@antv/g-svg 1.8.17 → 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 +1503 -1354
- 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,6 +1886,126 @@
|
|
|
1918
1886
|
|
|
1919
1887
|
$el.setAttribute('d', d);
|
|
1920
1888
|
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Common utilities
|
|
1891
|
+
* @module glMatrix
|
|
1892
|
+
*/
|
|
1893
|
+
|
|
1894
|
+
|
|
1895
|
+
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
1896
|
+
if (!Math.hypot) Math.hypot = function () {
|
|
1897
|
+
var y = 0,
|
|
1898
|
+
i = arguments.length;
|
|
1899
|
+
|
|
1900
|
+
while (i--) {
|
|
1901
|
+
y += arguments[i] * arguments[i];
|
|
1902
|
+
}
|
|
1903
|
+
|
|
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
|
+
*/
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* Creates a new identity mat4
|
|
1913
|
+
*
|
|
1914
|
+
* @returns {mat4} a new 4x4 matrix
|
|
1915
|
+
*/
|
|
1916
|
+
|
|
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;
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
out[0] = 1;
|
|
1936
|
+
out[5] = 1;
|
|
1937
|
+
out[10] = 1;
|
|
1938
|
+
out[15] = 1;
|
|
1939
|
+
return out;
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Inverts a mat4
|
|
1943
|
+
*
|
|
1944
|
+
* @param {mat4} out the receiving matrix
|
|
1945
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
1946
|
+
* @returns {mat4} out
|
|
1947
|
+
*/
|
|
1948
|
+
|
|
1949
|
+
|
|
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;
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
function createSVGElement(type, doc) {
|
|
2007
|
+
return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
|
|
2008
|
+
}
|
|
1921
2009
|
|
|
1922
2010
|
function numberToLongString(x) {
|
|
1923
2011
|
return x.toFixed(6).replace('.000000', '');
|
|
@@ -1940,1526 +2028,1599 @@
|
|
|
1940
2028
|
});
|
|
1941
2029
|
}
|
|
1942
2030
|
|
|
1943
|
-
var
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
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'
|
|
1960
2106
|
};
|
|
2107
|
+
/**
|
|
2108
|
+
* G_SVG_PREFIX + nodeName + entity
|
|
2109
|
+
*
|
|
2110
|
+
* eg. g_svg_circle_345
|
|
2111
|
+
*/
|
|
1961
2112
|
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
metrics = parsedStyle.metrics,
|
|
1966
|
-
dx = parsedStyle.dx,
|
|
1967
|
-
dy = parsedStyle.dy;
|
|
1968
|
-
var browser = detect();
|
|
2113
|
+
var G_SVG_PREFIX = 'g_svg';
|
|
2114
|
+
var CLIP_PATH_PREFIX = 'clip-path-';
|
|
2115
|
+
var TEXT_PATH_PREFIX = 'text-path-';
|
|
1969
2116
|
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
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;
|
|
1976
2130
|
}
|
|
2131
|
+
/**
|
|
2132
|
+
* <camera>
|
|
2133
|
+
*/
|
|
1977
2134
|
|
|
1978
|
-
$el.setAttribute('paint-order', 'stroke');
|
|
1979
|
-
var lines = metrics.lines,
|
|
1980
|
-
lineHeight = metrics.lineHeight,
|
|
1981
|
-
height = metrics.height;
|
|
1982
|
-
var lineNum = lines.length;
|
|
1983
|
-
$el.setAttribute('style', "transform:translate(" + dx + "px, " + dy + "px);");
|
|
1984
2135
|
|
|
1985
|
-
|
|
1986
|
-
$el.innerHTML = convertHTML(lines[0]);
|
|
1987
|
-
$el.setAttribute('dx', "" + lineWidth / 2);
|
|
1988
|
-
} else {
|
|
1989
|
-
$el.innerHTML = lines.map(function (line, i) {
|
|
1990
|
-
var dx = lineWidth / 2;
|
|
1991
|
-
var dy = 0;
|
|
2136
|
+
var _proto = SVGRendererPlugin.prototype;
|
|
1992
2137
|
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
if (textBaseline === 'middle') {
|
|
1996
|
-
dy = lineHeight / 2 - height / 2;
|
|
1997
|
-
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
1998
|
-
dy = 0;
|
|
1999
|
-
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
2000
|
-
dy = -lineHeight * (lineNum - 1);
|
|
2001
|
-
}
|
|
2002
|
-
} else {
|
|
2003
|
-
dy = lineHeight;
|
|
2004
|
-
}
|
|
2138
|
+
_proto.apply = function apply(context) {
|
|
2139
|
+
var _this = this;
|
|
2005
2140
|
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2141
|
+
var renderingService = context.renderingService,
|
|
2142
|
+
renderingContext = context.renderingContext;
|
|
2143
|
+
this.context = context;
|
|
2144
|
+
var document = this.context.config.document;
|
|
2010
2145
|
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
});
|
|
2014
|
-
var SVGRendererPluginOptions = gLite.Syringe.defineToken('');
|
|
2146
|
+
var handleMounted = function handleMounted(e) {
|
|
2147
|
+
var object = e.target; // create SVG DOM Node
|
|
2015
2148
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
}
|
|
2149
|
+
_this.createSVGDom(document, object, _this.$camera);
|
|
2150
|
+
};
|
|
2019
2151
|
|
|
2020
|
-
|
|
2152
|
+
var handleUnmounted = function handleUnmounted(e) {
|
|
2153
|
+
var object = e.target;
|
|
2021
2154
|
|
|
2022
|
-
|
|
2023
|
-
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', // 'whiteSpace',
|
|
2024
|
-
'dx', 'dy'], _SHAPE_UPDATE_DEPS);
|
|
2155
|
+
_this.defElementManager.clear(object.entity);
|
|
2025
2156
|
|
|
2026
|
-
|
|
2027
|
-
function DefaultElementLifeCycleContribution(canvasConfig) {
|
|
2028
|
-
this.canvasConfig = void 0;
|
|
2029
|
-
this.canvasConfig = canvasConfig;
|
|
2030
|
-
}
|
|
2157
|
+
_this.clipPathUseMap.delete(object);
|
|
2031
2158
|
|
|
2032
|
-
|
|
2159
|
+
_this.removeSVGDom(object);
|
|
2160
|
+
};
|
|
2033
2161
|
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
return createSVGElement(type, doc || document);
|
|
2038
|
-
};
|
|
2162
|
+
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
2163
|
+
var object = e.target; // @see https://github.com/antvis/g/issues/994
|
|
2164
|
+
// @ts-ignore
|
|
2039
2165
|
|
|
2040
|
-
|
|
2166
|
+
if (!object.elementSVG) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2041
2169
|
|
|
2042
|
-
|
|
2043
|
-
var nodeName = object.nodeName;
|
|
2044
|
-
return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
|
|
2045
|
-
};
|
|
2170
|
+
var attrName = e.attrName;
|
|
2046
2171
|
|
|
2047
|
-
|
|
2048
|
-
// @ts-ignore
|
|
2049
|
-
var $el = object.elementSVG.$el;
|
|
2050
|
-
var nodeName = object.nodeName,
|
|
2051
|
-
parsedStyle = object.parsedStyle;
|
|
2172
|
+
var attribtues = _this.dirtyAttributes.get(object);
|
|
2052
2173
|
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
{
|
|
2056
|
-
updateImageElementAttribute($el, parsedStyle);
|
|
2057
|
-
break;
|
|
2058
|
-
}
|
|
2174
|
+
if (!attribtues) {
|
|
2175
|
+
_this.dirtyAttributes.set(object, []);
|
|
2059
2176
|
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
updateRectElementAttribute($el, parsedStyle);
|
|
2063
|
-
break;
|
|
2064
|
-
}
|
|
2177
|
+
attribtues = _this.dirtyAttributes.get(object);
|
|
2178
|
+
}
|
|
2065
2179
|
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
updateLineElementAttribute($el, parsedStyle);
|
|
2069
|
-
break;
|
|
2070
|
-
}
|
|
2180
|
+
attribtues.push(attrName);
|
|
2181
|
+
};
|
|
2071
2182
|
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
{
|
|
2075
|
-
updatePolylineElementAttribute($el, parsedStyle);
|
|
2076
|
-
break;
|
|
2077
|
-
}
|
|
2183
|
+
var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
|
|
2184
|
+
var _object$elementSVG;
|
|
2078
2185
|
|
|
2079
|
-
|
|
2080
|
-
{
|
|
2081
|
-
updatePathElementAttribute($el, parsedStyle);
|
|
2082
|
-
break;
|
|
2083
|
-
}
|
|
2186
|
+
var object = e.target; // @ts-ignore
|
|
2084
2187
|
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
};
|
|
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;
|
|
2092
2192
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2193
|
+
if (fill && !(fill instanceof gLite.CSSRGB)) {
|
|
2194
|
+
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill');
|
|
2195
|
+
}
|
|
2095
2196
|
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
/**
|
|
2101
|
-
* use SVG filters, eg. blur, brightness, contrast...
|
|
2102
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2103
|
-
*/
|
|
2197
|
+
if (stroke && !(stroke instanceof gLite.CSSRGB)) {
|
|
2198
|
+
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke');
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2104
2201
|
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
var filterName = FILTER_PREFIX + object.entity;
|
|
2108
|
-
var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
|
|
2202
|
+
renderingService.hooks.init.tapPromise(SVGRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
|
|
2203
|
+
var _this$context$config, background, document, $svg;
|
|
2109
2204
|
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
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>
|
|
2115
2210
|
|
|
2116
|
-
|
|
2117
|
-
// 'none'
|
|
2118
|
-
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2119
|
-
} else {
|
|
2120
|
-
var filterIds = filters.map(function (_ref, i) {
|
|
2121
|
-
var name = _ref.name,
|
|
2122
|
-
params = _ref.params;
|
|
2123
|
-
var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
|
|
2211
|
+
_this.defElementManager.init();
|
|
2124
2212
|
|
|
2125
|
-
|
|
2213
|
+
$svg = _this.context.contextService.getContext();
|
|
2126
2214
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
createBrightness(document, $filter, params);
|
|
2131
|
-
} else if (name === 'drop-shadow') {
|
|
2132
|
-
createDropShadow(document, $filter, params);
|
|
2133
|
-
} else if (name === 'contrast') {
|
|
2134
|
-
createContrast(document, $filter, params);
|
|
2135
|
-
} else if (name === 'grayscale') {
|
|
2136
|
-
createGrayscale(document, $filter, params);
|
|
2137
|
-
} else if (name === 'sepia') {
|
|
2138
|
-
createSepia(document, $filter, params);
|
|
2139
|
-
} else if (name === 'saturate') {
|
|
2140
|
-
createSaturate(document, $filter, params);
|
|
2141
|
-
} else if (name === 'hue-rotate') {
|
|
2142
|
-
createHueRotate(document, $filter, params);
|
|
2143
|
-
} else if (name === 'invert') {
|
|
2144
|
-
createInvert(document, $filter, params);
|
|
2145
|
-
}
|
|
2215
|
+
if (background) {
|
|
2216
|
+
$svg.style.background = background;
|
|
2217
|
+
} // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
|
|
2146
2218
|
|
|
2147
|
-
$filter.id = filterName + "-" + i;
|
|
2148
|
-
$filter.setAttribute('name', filterName);
|
|
2149
|
-
$def.appendChild($filter);
|
|
2150
|
-
return $filter.id;
|
|
2151
|
-
}); // @see https://github.com/antvis/G/issues/1114
|
|
2152
2219
|
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2220
|
+
$svg.setAttribute('color-interpolation-filters', 'sRGB');
|
|
2221
|
+
_this.$camera = createSVGElement('g', document);
|
|
2222
|
+
_this.$camera.id = G_SVG_PREFIX + "_camera";
|
|
2223
|
+
|
|
2224
|
+
_this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
|
|
2225
|
+
|
|
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);
|
|
2231
|
+
|
|
2232
|
+
case 13:
|
|
2233
|
+
case "end":
|
|
2234
|
+
return _context.stop();
|
|
2235
|
+
}
|
|
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);
|
|
2157
2244
|
});
|
|
2158
|
-
|
|
2159
|
-
|
|
2245
|
+
renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
|
|
2246
|
+
// if (!object.isCulled()) {
|
|
2247
|
+
_this.renderQueue.push(object); // }
|
|
2160
2248
|
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
/**
|
|
2165
|
-
* @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
|
|
2166
|
-
*/
|
|
2249
|
+
});
|
|
2250
|
+
renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
|
|
2251
|
+
var doc = _this.context.config.document;
|
|
2167
2252
|
|
|
2253
|
+
if (_this.pendingReorderQueue.size) {
|
|
2254
|
+
_this.pendingReorderQueue.forEach(function (object) {
|
|
2255
|
+
var _object$elementSVG2;
|
|
2168
2256
|
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
|
|
2173
|
-
$filter.appendChild($feGaussianBlur);
|
|
2174
|
-
}
|
|
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;
|
|
2175
2260
|
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
tableValues = _ref2.tableValues;
|
|
2181
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2182
|
-
[createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
|
|
2183
|
-
$feFunc.setAttribute('type', type);
|
|
2261
|
+
if ($parentGroupEl) {
|
|
2262
|
+
_this.reorderChildren(doc || document, $parentGroupEl, children || []);
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2184
2265
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
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
|
+
}
|
|
2191
2273
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
$filter.appendChild($feComponentTransfer);
|
|
2195
|
-
}
|
|
2274
|
+
_this.renderQueue.forEach(function (object) {
|
|
2275
|
+
var _object$elementSVG3, _object$elementSVG4; // @ts-ignore
|
|
2196
2276
|
|
|
2197
|
-
function createContrast(document, $filter, params) {
|
|
2198
|
-
var slope = convertToAbsoluteValue(params[0]);
|
|
2199
|
-
createFeComponentTransfer(document, $filter, {
|
|
2200
|
-
type: 'linear',
|
|
2201
|
-
slope: slope,
|
|
2202
|
-
intercept: -(0.5 * slope) + 0.5
|
|
2203
|
-
});
|
|
2204
|
-
}
|
|
2205
2277
|
|
|
2206
|
-
|
|
2207
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2208
|
-
createFeComponentTransfer(document, $filter, {
|
|
2209
|
-
type: 'table',
|
|
2210
|
-
tableValues: amount + " " + (1 - amount)
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2278
|
+
var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el; // @ts-ignore
|
|
2213
2279
|
|
|
2214
|
-
|
|
2215
|
-
var slope = convertToAbsoluteValue(params[0]);
|
|
2216
|
-
createFeComponentTransfer(document, $filter, {
|
|
2217
|
-
type: 'linear',
|
|
2218
|
-
slope: slope,
|
|
2219
|
-
intercept: 0
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2280
|
+
var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
|
|
2222
2281
|
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
$feColorMatrix.setAttribute('values', "" + amount);
|
|
2228
|
-
$filter.appendChild($feColorMatrix);
|
|
2229
|
-
}
|
|
2282
|
+
if ($el && $groupEl) {
|
|
2283
|
+
// apply local RTS transformation to <group> wrapper
|
|
2284
|
+
// account for anchor
|
|
2285
|
+
var localTransform = object.getLocalTransform();
|
|
2230
2286
|
|
|
2231
|
-
|
|
2232
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2233
|
-
$feColorMatrix.setAttribute('type', 'hueRotate');
|
|
2234
|
-
$feColorMatrix.setAttribute('values', "" + params[0].to(gLite.UnitType.kDegrees).value);
|
|
2235
|
-
$filter.appendChild($feColorMatrix);
|
|
2236
|
-
}
|
|
2287
|
+
_this.applyTransform($groupEl, localTransform); // clipped shapes should also be informed
|
|
2237
2288
|
|
|
2238
|
-
function createDropShadow(document, $filter, params) {
|
|
2239
|
-
var shadowOffsetX = params[0].value;
|
|
2240
|
-
var shadowOffsetY = params[1].value;
|
|
2241
|
-
var shadowBlur = params[2].value; // @ts-ignore
|
|
2242
2289
|
|
|
2243
|
-
|
|
2244
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2245
|
-
$feGaussianBlur.setAttribute('in', 'SourceAlpha');
|
|
2246
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
|
|
2247
|
-
$filter.appendChild($feGaussianBlur);
|
|
2248
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2249
|
-
$feOffset.setAttribute('dx', "" + shadowOffsetX);
|
|
2250
|
-
$feOffset.setAttribute('dy', "" + shadowOffsetY);
|
|
2251
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2252
|
-
$filter.appendChild($feOffset);
|
|
2253
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2254
|
-
$feFlood.setAttribute('flood-color', shadowColor);
|
|
2255
|
-
$filter.appendChild($feFlood);
|
|
2256
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2257
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2258
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2259
|
-
$filter.appendChild($feComposite);
|
|
2260
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2261
|
-
$filter.appendChild($feMerge);
|
|
2262
|
-
var $feMergeNode1 = createSVGElement('feMergeNode', document);
|
|
2263
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2264
|
-
$feMergeNode2.setAttribute('in', 'SourceGraphic');
|
|
2265
|
-
$feMerge.appendChild($feMergeNode1);
|
|
2266
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2267
|
-
}
|
|
2290
|
+
var $useRefs = _this.clipPathUseMap.get(object);
|
|
2268
2291
|
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
|
|
2277
|
-
*/
|
|
2292
|
+
if ($useRefs && $useRefs.length) {
|
|
2293
|
+
$useRefs.forEach(function ($use) {
|
|
2294
|
+
_this.applyTransform($use, localTransform);
|
|
2295
|
+
});
|
|
2296
|
+
} // finish rendering, clear dirty flag
|
|
2278
2297
|
|
|
2279
2298
|
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
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]);
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
|
|
2286
|
-
*/
|
|
2299
|
+
object.renderable.dirty = false;
|
|
2300
|
+
} // update dirty attributes
|
|
2287
2301
|
|
|
2288
2302
|
|
|
2289
|
-
|
|
2290
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2291
|
-
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]);
|
|
2292
|
-
}
|
|
2303
|
+
var attributes = _this.dirtyAttributes.get(object);
|
|
2293
2304
|
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2305
|
+
if (attributes) {
|
|
2306
|
+
attributes.forEach(function (attrName) {
|
|
2307
|
+
if (attrName === 'zIndex') {
|
|
2308
|
+
var _object$parentNode, _object$parentNode$el;
|
|
2297
2309
|
|
|
2298
|
-
|
|
2299
|
-
// eg. clipPath don't have fill/stroke
|
|
2300
|
-
if (!parsedColor) {
|
|
2301
|
-
return '';
|
|
2302
|
-
}
|
|
2310
|
+
var parent = object.parentNode; // @ts-ignore
|
|
2303
2311
|
|
|
2304
|
-
|
|
2305
|
-
// keep using currentColor @see https://github.com/d3/d3-axis/issues/49
|
|
2306
|
-
if (object.style[name] === 'currentColor') {
|
|
2307
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
|
|
2308
|
-
} else {
|
|
2309
|
-
// constant value, eg. '#fff'
|
|
2310
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
|
|
2311
|
-
}
|
|
2312
|
-
} else if (gLite.isPattern(parsedColor)) {
|
|
2313
|
-
var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage); // use style instead of attribute when applying <pattern>
|
|
2314
|
-
// @see https://stackoverflow.com/a/7723115
|
|
2315
|
-
|
|
2316
|
-
$el.style[name] = "url(#" + patternId + ")";
|
|
2317
|
-
return patternId;
|
|
2318
|
-
} else {
|
|
2319
|
-
if (parsedColor.length === 1) {
|
|
2320
|
-
var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
|
|
2321
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
|
|
2322
|
-
return gradientId;
|
|
2323
|
-
} else {
|
|
2324
|
-
// @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
|
|
2325
|
-
var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
|
|
2326
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
|
|
2327
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
|
|
2328
|
-
return filterId;
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
return '';
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
function generateCacheKey(src, options) {
|
|
2336
|
-
if (options === void 0) {
|
|
2337
|
-
options = {};
|
|
2338
|
-
}
|
|
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;
|
|
2339
2313
|
|
|
2340
|
-
|
|
2314
|
+
var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
|
|
2341
2315
|
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2316
|
+
if (_$groupEl) {
|
|
2317
|
+
_this.reorderChildren(document, _$groupEl, children);
|
|
2318
|
+
}
|
|
2319
|
+
} else if (attrName === 'increasedLineWidthForHitTesting') {
|
|
2320
|
+
_this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
2321
|
+
}
|
|
2345
2322
|
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
var _value$options = _extends({}, value, options),
|
|
2349
|
-
_type = _value$options.type,
|
|
2350
|
-
width = _value$options.width,
|
|
2351
|
-
height = _value$options.height,
|
|
2352
|
-
steps = _value$options.steps,
|
|
2353
|
-
angle = _value$options.angle,
|
|
2354
|
-
cx = _value$options.cx,
|
|
2355
|
-
cy = _value$options.cy,
|
|
2356
|
-
size = _value$options.size;
|
|
2323
|
+
_this.updateAttribute(object, [attrName]);
|
|
2324
|
+
});
|
|
2357
2325
|
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
return "" + offset + color;
|
|
2362
|
-
}).join('-');
|
|
2363
|
-
}
|
|
2364
|
-
} else if (gLite.isPattern(src)) {
|
|
2365
|
-
if (isString(src.image)) {
|
|
2366
|
-
cacheKey = "pattern-" + src.image + "-" + src.repetition;
|
|
2367
|
-
} else {
|
|
2368
|
-
cacheKey = "pattern-" + counter;
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2326
|
+
_this.dirtyAttributes.delete(object);
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2371
2329
|
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2330
|
+
_this.renderQueue = [];
|
|
2331
|
+
});
|
|
2332
|
+
};
|
|
2377
2333
|
|
|
2378
|
-
|
|
2379
|
-
|
|
2334
|
+
_proto.getId = function getId(object) {
|
|
2335
|
+
return G_SVG_PREFIX + "_" + object.nodeName + "_" + object.entity;
|
|
2336
|
+
};
|
|
2380
2337
|
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
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
|
+
});
|
|
2384
2343
|
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
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;
|
|
2389
2351
|
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
} else if (image instanceof HTMLCanvasElement) {
|
|
2397
|
-
imageURL = image.toDataURL();
|
|
2398
|
-
} else ;
|
|
2399
|
-
}
|
|
2352
|
+
if ($el) {
|
|
2353
|
+
fragment.appendChild($el);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
$groupEl.appendChild(fragment);
|
|
2400
2358
|
}
|
|
2359
|
+
};
|
|
2401
2360
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
$pattern.appendChild($image);
|
|
2408
|
-
$pattern.id = patternId;
|
|
2409
|
-
$def.appendChild($pattern); // use href instead of xlink:href
|
|
2410
|
-
// @see https://stackoverflow.com/a/13379007
|
|
2411
|
-
|
|
2412
|
-
$image.setAttribute('href', imageURL);
|
|
2413
|
-
var img;
|
|
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
|
+
};
|
|
2414
2366
|
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
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;
|
|
2420
2372
|
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2373
|
+
if ($el && $groupEl) {
|
|
2374
|
+
var nodeName = object.nodeName,
|
|
2375
|
+
attributes = object.attributes;
|
|
2376
|
+
$el.setAttribute('fill', 'none');
|
|
2425
2377
|
|
|
2426
|
-
|
|
2378
|
+
if (nodeName === gLite.Shape.IMAGE) {
|
|
2379
|
+
$el.setAttribute('preserveAspectRatio', 'none');
|
|
2380
|
+
} // apply attributes
|
|
2427
2381
|
|
|
2428
|
-
var onload = function onload() {
|
|
2429
|
-
$pattern.setAttribute('x', '0');
|
|
2430
|
-
$pattern.setAttribute('y', '0');
|
|
2431
2382
|
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2383
|
+
this.updateAttribute(object, Object.keys(attributes));
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2435
2386
|
|
|
2387
|
+
_proto.updateAttribute = function updateAttribute(object, attributes) {
|
|
2388
|
+
var _this2 = this;
|
|
2436
2389
|
|
|
2437
|
-
|
|
2438
|
-
var patternHeight = img.height;
|
|
2390
|
+
var document = this.context.config.document; // @ts-ignore
|
|
2439
2391
|
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
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
|
|
2448
2403
|
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
$
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
$image.setAttribute('height', "" + img.height);
|
|
2455
|
-
};
|
|
2404
|
+
if (shouldUpdateElementAttribute && $el) {
|
|
2405
|
+
[$el, $hitTestingEl].forEach(function ($el) {
|
|
2406
|
+
if ($el) {
|
|
2407
|
+
// @ts-ignore
|
|
2408
|
+
_this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el);
|
|
2456
2409
|
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2410
|
+
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
2411
|
+
_this2.updateAnchorWithTransform(object);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
});
|
|
2415
|
+
} // update common attributes
|
|
2461
2416
|
|
|
2462
|
-
img.src = img.src;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
2417
|
|
|
2467
|
-
|
|
2468
|
-
|
|
2418
|
+
attributes.forEach(function (name) {
|
|
2419
|
+
var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
|
|
2469
2420
|
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
height: height
|
|
2477
|
-
});
|
|
2478
|
-
var $existed = $def.querySelector("#" + gradientId);
|
|
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);
|
|
2479
2427
|
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
|
|
2484
|
-
$existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document); // @see https://github.com/antvis/g/issues/1025
|
|
2428
|
+
if (!usedName) {
|
|
2429
|
+
return;
|
|
2430
|
+
} // <foreignObject>
|
|
2485
2431
|
|
|
2486
|
-
$existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
|
|
2487
2432
|
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
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
|
+
}
|
|
2439
|
+
}
|
|
2495
2440
|
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
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
|
+
});
|
|
2493
|
+
};
|
|
2502
2494
|
|
|
2503
|
-
|
|
2504
|
-
|
|
2495
|
+
_proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
|
|
2496
|
+
if (noWrapWithGroup === void 0) {
|
|
2497
|
+
noWrapWithGroup = false;
|
|
2498
|
+
} // create svg element
|
|
2499
|
+
// @ts-ignore
|
|
2505
2500
|
|
|
2506
|
-
var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
|
|
2507
|
-
x1 = _computeLinearGradien.x1,
|
|
2508
|
-
y1 = _computeLinearGradien.y1,
|
|
2509
|
-
x2 = _computeLinearGradien.x2,
|
|
2510
|
-
y2 = _computeLinearGradien.y2;
|
|
2511
2501
|
|
|
2512
|
-
|
|
2513
|
-
$existed.setAttribute('y1', "" + y1);
|
|
2514
|
-
$existed.setAttribute('x2', "" + x2);
|
|
2515
|
-
$existed.setAttribute('y2', "" + y2); // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
|
|
2516
|
-
} else {
|
|
2517
|
-
var _parsedColor$value = parsedColor.value,
|
|
2518
|
-
cx = _parsedColor$value.cx,
|
|
2519
|
-
cy = _parsedColor$value.cy,
|
|
2520
|
-
size = _parsedColor$value.size;
|
|
2502
|
+
object.elementSVG = new ElementSVG(); // @ts-ignore
|
|
2521
2503
|
|
|
2522
|
-
var
|
|
2523
|
-
|
|
2524
|
-
y = _computeRadialGradien.y,
|
|
2525
|
-
r = _computeRadialGradien.r;
|
|
2504
|
+
var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
|
|
2505
|
+
// @ts-ignore
|
|
2526
2506
|
|
|
2527
|
-
$
|
|
2528
|
-
$existed.setAttribute('cy', "" + y);
|
|
2529
|
-
$existed.setAttribute('r', "" + r);
|
|
2530
|
-
}
|
|
2507
|
+
var $el = this.context.SVGElementLifeCycleContribution.createElement(object);
|
|
2531
2508
|
|
|
2532
|
-
|
|
2533
|
-
|
|
2509
|
+
if ($el) {
|
|
2510
|
+
var _object$parentNode$el2;
|
|
2534
2511
|
|
|
2535
|
-
|
|
2536
|
-
var filterId = FILTER_PREFIX + object.entity + '-gradient';
|
|
2537
|
-
var $existed = $def.querySelector("#" + filterId);
|
|
2512
|
+
var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
|
|
2538
2513
|
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2514
|
+
if (object.nodeName === gLite.Shape.HTML) {
|
|
2515
|
+
object.parsedStyle.$el = $el;
|
|
2516
|
+
}
|
|
2542
2517
|
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
$existed.setAttribute('height', '100%');
|
|
2547
|
-
$existed.id = filterId;
|
|
2548
|
-
$def.appendChild($existed);
|
|
2549
|
-
}
|
|
2550
|
-
/**
|
|
2551
|
-
* <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
|
|
2552
|
-
* <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
|
|
2553
|
-
<feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
|
|
2554
|
-
<feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
|
|
2555
|
-
<feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
|
|
2556
|
-
<feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
|
|
2557
|
-
</filter>
|
|
2558
|
-
*/
|
|
2518
|
+
if (this.pluginOptions.outputSVGElementId) {
|
|
2519
|
+
$el.id = this.getId(object);
|
|
2520
|
+
}
|
|
2559
2521
|
|
|
2522
|
+
if (this.pluginOptions.outputSVGElementName && object.name) {
|
|
2523
|
+
$el.setAttribute('name', object.name);
|
|
2524
|
+
}
|
|
2560
2525
|
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
$rect.setAttribute('y', '0');
|
|
2568
|
-
$rect.setAttribute('width', '100%');
|
|
2569
|
-
$rect.setAttribute('height', '100%');
|
|
2570
|
-
$rect.setAttribute('fill', "url(#" + gradientId + ")");
|
|
2571
|
-
$rect.id = rectId;
|
|
2572
|
-
$def.appendChild($rect);
|
|
2573
|
-
var $feImage = createSVGElement('feImage', document);
|
|
2574
|
-
$feImage.setAttribute('href', "#" + rectId);
|
|
2575
|
-
$feImage.setAttribute('result', filterId + "-" + i);
|
|
2576
|
-
$existed.appendChild($feImage);
|
|
2526
|
+
if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
|
|
2527
|
+
$groupEl = createSVGElement('g', document);
|
|
2528
|
+
$groupEl.appendChild($el);
|
|
2529
|
+
} else {
|
|
2530
|
+
$groupEl = $el;
|
|
2531
|
+
}
|
|
2577
2532
|
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
$feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
|
|
2581
|
-
$feBlend.setAttribute('in2', filterId + "-" + i);
|
|
2582
|
-
$feBlend.setAttribute('result', filterId + "-blended-" + blended++); // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
|
|
2533
|
+
svgElement.$el = $el;
|
|
2534
|
+
svgElement.$groupEl = $groupEl; // apply attributes at first time
|
|
2583
2535
|
|
|
2584
|
-
|
|
2585
|
-
|
|
2536
|
+
this.applyAttributes(object); // create hitArea if necessary
|
|
2537
|
+
|
|
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
|
+
}
|
|
2586
2547
|
}
|
|
2587
|
-
}
|
|
2588
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2589
|
-
$feComposite.setAttribute('in', filterId + "-blended-" + blended);
|
|
2590
|
-
$feComposite.setAttribute('in2', 'SourceGraphic');
|
|
2591
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2592
|
-
$existed.appendChild($feComposite);
|
|
2593
|
-
return filterId;
|
|
2594
|
-
}
|
|
2548
|
+
};
|
|
2595
2549
|
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
* use SVG filters
|
|
2599
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2600
|
-
*/
|
|
2550
|
+
_proto.removeSVGDom = function removeSVGDom(object) {
|
|
2551
|
+
var _object$elementSVG6; // @ts-ignore
|
|
2601
2552
|
|
|
2602
|
-
function createOrUpdateShadow(document, $def, object, $el, name) {
|
|
2603
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
2604
|
-
shadowType = _object$parsedStyle.shadowType,
|
|
2605
|
-
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
2606
|
-
shadowColor = _object$parsedStyle.shadowColor,
|
|
2607
|
-
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
2608
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
2609
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
2610
|
-
var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
|
|
2611
|
-
var $existedFilter = $def.querySelector("#" + shadowId);
|
|
2612
2553
|
|
|
2613
|
-
|
|
2614
|
-
var existedShadowType = $existedFilter.getAttribute('data-type');
|
|
2554
|
+
var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
|
|
2615
2555
|
|
|
2616
|
-
if (
|
|
2617
|
-
//
|
|
2618
|
-
|
|
2619
|
-
$
|
|
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);
|
|
2620
2560
|
}
|
|
2621
|
-
}
|
|
2622
|
-
// only apply shadow when blur > 0
|
|
2561
|
+
};
|
|
2623
2562
|
|
|
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
|
|
2624
2568
|
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
|
|
2629
|
-
} else {
|
|
2630
|
-
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2631
|
-
return;
|
|
2632
|
-
}
|
|
2569
|
+
if (increasedLineWidthForHitTesting) {
|
|
2570
|
+
if (!$hitTestingEl) {
|
|
2571
|
+
$hitTestingEl = $el.cloneNode();
|
|
2633
2572
|
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
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`
|
|
2637
2577
|
|
|
2638
|
-
if (shadowType === 'outer') {
|
|
2639
|
-
var $feDropShadow = createSVGElement('feDropShadow', document);
|
|
2640
|
-
$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2641
|
-
$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2642
|
-
$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2643
|
-
$feDropShadow.setAttribute('flood-color', shadowColor.toString());
|
|
2644
|
-
$existedFilter.appendChild($feDropShadow);
|
|
2645
|
-
} else if (shadowType === 'inner') {
|
|
2646
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2647
|
-
$feComponentTransfer.setAttribute('in', 'SourceAlpha');
|
|
2648
|
-
var $feFuncA = createSVGElement('feFuncA', document);
|
|
2649
|
-
$feFuncA.setAttribute('type', 'table');
|
|
2650
|
-
$feFuncA.setAttribute('tableValues', '1 0');
|
|
2651
|
-
$feComponentTransfer.appendChild($feFuncA);
|
|
2652
|
-
$existedFilter.appendChild($feComponentTransfer);
|
|
2653
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2654
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2655
|
-
$existedFilter.appendChild($feGaussianBlur);
|
|
2656
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2657
|
-
$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2658
|
-
$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2659
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2660
|
-
$existedFilter.appendChild($feOffset);
|
|
2661
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2662
|
-
$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
2663
|
-
$feFlood.setAttribute('result', 'color');
|
|
2664
|
-
$existedFilter.appendChild($feFlood);
|
|
2665
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2666
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2667
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2668
|
-
$existedFilter.appendChild($feComposite);
|
|
2669
|
-
var $feComposite2 = createSVGElement('feComposite', document);
|
|
2670
|
-
$feComposite2.setAttribute('in2', 'SourceAlpha');
|
|
2671
|
-
$feComposite2.setAttribute('operator', 'in');
|
|
2672
|
-
$existedFilter.appendChild($feComposite2);
|
|
2673
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2674
|
-
$existedFilter.appendChild($feMerge);
|
|
2675
|
-
var $feMergeNode = createSVGElement('feMergeNode', document);
|
|
2676
|
-
$feMergeNode.setAttribute('in', 'SourceGraphic');
|
|
2677
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2678
|
-
$feMerge.appendChild($feMergeNode);
|
|
2679
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2680
|
-
}
|
|
2681
2578
|
|
|
2682
|
-
|
|
2579
|
+
['filter'].forEach(function (attribute) {
|
|
2580
|
+
$hitTestingEl.removeAttribute(attribute);
|
|
2581
|
+
}); // hitArea should be 'transparent' but not 'none'
|
|
2683
2582
|
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
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
|
|
2688
2589
|
|
|
2689
|
-
if (shadowType === 'inner') {
|
|
2690
|
-
var _$feGaussianBlur = $existedFilter.children[1];
|
|
2691
|
-
var _$feOffset = $existedFilter.children[2];
|
|
2692
|
-
var _$feFlood = $existedFilter.children[3];
|
|
2693
2590
|
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
_$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2701
|
-
} else if (name === 'shadowOffsetX') {
|
|
2702
|
-
_$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2703
|
-
} else if (name === 'shadowOffsetY') {
|
|
2704
|
-
_$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2591
|
+
$hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
|
|
2592
|
+
} else {
|
|
2593
|
+
if ($hitTestingEl) {
|
|
2594
|
+
$groupEl.removeChild($hitTestingEl);
|
|
2595
|
+
svgElement.$hitTestingEl = null;
|
|
2596
|
+
}
|
|
2705
2597
|
}
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2598
|
+
};
|
|
2599
|
+
|
|
2600
|
+
_proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
|
|
2601
|
+
var $div = (doc || document).createElement('div');
|
|
2602
|
+
|
|
2603
|
+
if (typeof usedValue === 'string') {
|
|
2604
|
+
$div.innerHTML = usedValue;
|
|
2605
|
+
} else {
|
|
2606
|
+
$div.appendChild(usedValue);
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
$el.innerHTML = '';
|
|
2610
|
+
$el.appendChild($div);
|
|
2611
|
+
};
|
|
2612
|
+
|
|
2613
|
+
_proto.createOrUpdateClipOrTextPath = function createOrUpdateClipOrTextPath(document, clipPath, object, isTextPath) {
|
|
2614
|
+
if (isTextPath === void 0) {
|
|
2615
|
+
isTextPath = false;
|
|
2616
|
+
} // @ts-ignore
|
|
2617
|
+
|
|
2618
|
+
|
|
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';
|
|
2623
|
+
|
|
2624
|
+
if (clipPath) {
|
|
2625
|
+
var clipPathId = PREFIX + clipPath.entity + '-' + object.entity;
|
|
2626
|
+
var $def = this.defElementManager.getDefElement();
|
|
2627
|
+
var existed = $def.querySelector("#" + clipPathId);
|
|
2628
|
+
|
|
2629
|
+
if (!existed) {
|
|
2630
|
+
var $clipPath;
|
|
2631
|
+
|
|
2632
|
+
if (isTextPath) {
|
|
2633
|
+
// use <path> directly instead of wrapping with <g>
|
|
2634
|
+
this.createSVGDom(document, clipPath, null, true); // @ts-ignore
|
|
2635
|
+
|
|
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));
|
|
2708
2641
|
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
2714
|
-
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
2715
|
-
_$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2716
|
-
} else if (name === 'shadowOffsetX') {
|
|
2717
|
-
_$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2718
|
-
} else if (name === 'shadowOffsetY') {
|
|
2719
|
-
_$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2642
|
+
if (!$existedClipPath) {
|
|
2643
|
+
this.createSVGDom(document, clipPath, $def, true);
|
|
2644
|
+
}
|
|
2645
|
+
} // create <clipPath> dom node
|
|
2723
2646
|
|
|
2724
|
-
var urlRegexp = /url\(#(.*)\)/;
|
|
2725
2647
|
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2648
|
+
$clipPath = createSVGElement(attributeNameCamel, document);
|
|
2649
|
+
var $use = createSVGElement('use', document); // @ts-ignore
|
|
2650
|
+
|
|
2651
|
+
$use.setAttribute('href', "#" + clipPath.elementSVG.$el.id);
|
|
2652
|
+
$clipPath.appendChild($use);
|
|
2653
|
+
var $useRefs = this.clipPathUseMap.get(clipPath);
|
|
2654
|
+
|
|
2655
|
+
if (!$useRefs) {
|
|
2656
|
+
this.clipPathUseMap.set(clipPath, []);
|
|
2657
|
+
$useRefs = this.clipPathUseMap.get(clipPath);
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
$useRefs.push($use); // <clipPath transform="matrix()"><circle /></clipPath>
|
|
2661
|
+
|
|
2662
|
+
this.applyTransform($use, clipPath.getWorldTransform());
|
|
2663
|
+
var parentInvert = invert(create(), object.getWorldTransform());
|
|
2664
|
+
this.applyTransform($clipPath, parentInvert);
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
$clipPath.id = clipPathId; // append it to <defs>
|
|
2668
|
+
|
|
2669
|
+
$def.appendChild($clipPath);
|
|
2670
|
+
} // apply attributes
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
this.applyAttributes(clipPath);
|
|
2674
|
+
|
|
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
|
+
}
|
|
2734
2686
|
}
|
|
2735
2687
|
/**
|
|
2736
|
-
*
|
|
2688
|
+
* the origin is bounding box's top left corner
|
|
2737
2689
|
*/
|
|
2690
|
+
;
|
|
2738
2691
|
|
|
2692
|
+
_proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
|
|
2693
|
+
var _object$elementSVG7, _object$elementSVG8;
|
|
2739
2694
|
|
|
2740
|
-
|
|
2695
|
+
var bounds = object.getGeometryBounds();
|
|
2696
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
2697
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
2741
2698
|
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
};
|
|
2699
|
+
var _ref2 = object.parsedStyle || {},
|
|
2700
|
+
anchor = _ref2.anchor; // @ts-ignore
|
|
2745
2701
|
|
|
2746
|
-
_proto.init = function init() {
|
|
2747
|
-
var document = this.canvasConfig.document;
|
|
2748
|
-
var $svg = this.contextService.getContext();
|
|
2749
|
-
this.$def = createSVGElement('defs', document);
|
|
2750
|
-
$svg.appendChild(this.$def);
|
|
2751
|
-
};
|
|
2752
2702
|
|
|
2753
|
-
|
|
2754
|
-
|
|
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);
|
|
2755
2707
|
|
|
2756
|
-
|
|
2757
|
-
|
|
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 + ")");
|
|
2713
|
+
}
|
|
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
|
+
}
|
|
2758
2720
|
});
|
|
2759
2721
|
};
|
|
2760
2722
|
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
var targetElement = this.$def.querySelector("#" + id);
|
|
2723
|
+
return SVGRendererPlugin;
|
|
2724
|
+
}();
|
|
2764
2725
|
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
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
|
|
2770
2736
|
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
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
|
+
};
|
|
2775
2745
|
|
|
2776
|
-
|
|
2777
|
-
|
|
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();
|
|
2778
2764
|
|
|
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
|
+
}
|
|
2779
2772
|
|
|
2780
|
-
|
|
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 = '';
|
|
2781
2779
|
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2780
|
+
if (dx !== 0 || dy !== 0) {
|
|
2781
|
+
styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
|
|
2782
|
+
}
|
|
2785
2783
|
|
|
2786
|
-
|
|
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
|
+
}
|
|
2787
2788
|
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2789
|
+
if (styleCSSText) {
|
|
2790
|
+
$el.setAttribute('style', styleCSSText);
|
|
2791
|
+
}
|
|
2791
2792
|
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
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
|
|
2795
2797
|
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
};
|
|
2798
|
+
if (textPath) {
|
|
2799
|
+
// clear existed text content first
|
|
2800
|
+
$el.innerHTML = ''; // append <textPath href="#MyPath">text</textPath>
|
|
2800
2801
|
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
|
|
2804
|
-
};
|
|
2802
|
+
var $textPath = createSVGElement('textPath', $el.ownerDocument);
|
|
2803
|
+
$textPath.setAttribute('href', "#" + (TEXT_PATH_PREFIX + textPath.entity));
|
|
2805
2804
|
|
|
2806
|
-
|
|
2807
|
-
|
|
2805
|
+
if (textPathSide !== 'left') {
|
|
2806
|
+
$textPath.setAttribute('side', textPathSide);
|
|
2807
|
+
}
|
|
2808
2808
|
|
|
2809
|
-
|
|
2809
|
+
if (textPathStartOffset !== 0) {
|
|
2810
|
+
$textPath.setAttribute('startOffset', "" + textPathStartOffset);
|
|
2811
|
+
}
|
|
2810
2812
|
|
|
2811
|
-
|
|
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;
|
|
2812
2822
|
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
ry: 'ry',
|
|
2826
|
-
width: 'width',
|
|
2827
|
-
height: 'height',
|
|
2828
|
-
lineCap: 'stroke-linecap',
|
|
2829
|
-
lineJoin: 'stroke-linejoin',
|
|
2830
|
-
lineWidth: 'stroke-width',
|
|
2831
|
-
lineDash: 'stroke-dasharray',
|
|
2832
|
-
lineDashOffset: 'stroke-dashoffset',
|
|
2833
|
-
miterLimit: 'stroke-miterlimit',
|
|
2834
|
-
font: 'font',
|
|
2835
|
-
fontSize: 'font-size',
|
|
2836
|
-
fontStyle: 'font-style',
|
|
2837
|
-
fontVariant: 'font-variant',
|
|
2838
|
-
fontWeight: 'font-weight',
|
|
2839
|
-
fontFamily: 'font-family',
|
|
2840
|
-
letterSpacing: 'letter-spacing',
|
|
2841
|
-
startArrow: 'marker-start',
|
|
2842
|
-
endArrow: 'marker-end',
|
|
2843
|
-
class: 'class',
|
|
2844
|
-
id: 'id',
|
|
2845
|
-
// style: 'style',
|
|
2846
|
-
preserveAspectRatio: 'preserveAspectRatio',
|
|
2847
|
-
visibility: 'visibility',
|
|
2848
|
-
anchor: 'anchor',
|
|
2849
|
-
shadowColor: 'flood-color',
|
|
2850
|
-
shadowBlur: 'stdDeviation',
|
|
2851
|
-
shadowOffsetX: 'dx',
|
|
2852
|
-
shadowOffsetY: 'dy',
|
|
2853
|
-
filter: 'filter',
|
|
2854
|
-
innerHTML: 'innerHTML',
|
|
2855
|
-
textAlign: 'text-anchor',
|
|
2856
|
-
pointerEvents: 'pointer-events'
|
|
2857
|
-
};
|
|
2858
|
-
var FORMAT_VALUE_MAP = {
|
|
2859
|
-
textAlign: {
|
|
2860
|
-
inherit: 'inherit',
|
|
2861
|
-
left: 'left',
|
|
2862
|
-
start: 'left',
|
|
2863
|
-
center: 'middle',
|
|
2864
|
-
right: 'end',
|
|
2865
|
-
end: 'end'
|
|
2866
|
-
}
|
|
2867
|
-
};
|
|
2868
|
-
var DEFAULT_VALUE_MAP = {
|
|
2869
|
-
textAlign: 'inherit',
|
|
2870
|
-
// textBaseline: 'alphabetic',
|
|
2871
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineCaps
|
|
2872
|
-
lineCap: 'butt',
|
|
2873
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineJoin
|
|
2874
|
-
lineJoin: 'miter',
|
|
2875
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
|
|
2876
|
-
lineWidth: '1px',
|
|
2877
|
-
opacity: '1',
|
|
2878
|
-
fillOpacity: '1',
|
|
2879
|
-
strokeOpacity: '1',
|
|
2880
|
-
strokeWidth: '0',
|
|
2881
|
-
strokeMiterLimit: '4',
|
|
2882
|
-
letterSpacing: '0',
|
|
2883
|
-
fontSize: 'inherit',
|
|
2884
|
-
fontFamily: 'inherit',
|
|
2885
|
-
pointerEvents: 'auto'
|
|
2886
|
-
};
|
|
2887
|
-
/**
|
|
2888
|
-
* G_SVG_PREFIX + nodeName + entity
|
|
2889
|
-
*
|
|
2890
|
-
* eg. g_svg_circle_345
|
|
2891
|
-
*/
|
|
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
|
+
}
|
|
2892
2835
|
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
var SVGRendererPlugin = SVGRendererPlugin_1 = (_class$1 = /*#__PURE__*/function () {
|
|
2896
|
-
function SVGRendererPlugin(canvasConfig, camera, contextService, renderingContext, styleValueRegistry, createElementContribution, defElementManager, pluginOptions) {
|
|
2897
|
-
this.canvasConfig = void 0;
|
|
2898
|
-
this.camera = void 0;
|
|
2899
|
-
this.contextService = void 0;
|
|
2900
|
-
this.renderingContext = void 0;
|
|
2901
|
-
this.styleValueRegistry = void 0;
|
|
2902
|
-
this.createElementContribution = void 0;
|
|
2903
|
-
this.defElementManager = void 0;
|
|
2904
|
-
this.pluginOptions = void 0;
|
|
2905
|
-
this.$camera = void 0;
|
|
2906
|
-
this.renderQueue = [];
|
|
2907
|
-
this.dirtyAttributes = new WeakMap();
|
|
2908
|
-
this.pendingReorderQueue = new Set();
|
|
2909
|
-
this.canvasConfig = canvasConfig;
|
|
2910
|
-
this.camera = camera;
|
|
2911
|
-
this.contextService = contextService;
|
|
2912
|
-
this.renderingContext = renderingContext;
|
|
2913
|
-
this.styleValueRegistry = styleValueRegistry;
|
|
2914
|
-
this.createElementContribution = createElementContribution;
|
|
2915
|
-
this.defElementManager = defElementManager;
|
|
2916
|
-
this.pluginOptions = pluginOptions;
|
|
2836
|
+
return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
|
|
2837
|
+
}).join('');
|
|
2917
2838
|
}
|
|
2918
|
-
|
|
2919
|
-
* <camera>
|
|
2920
|
-
*/
|
|
2839
|
+
}
|
|
2921
2840
|
|
|
2841
|
+
var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
|
|
2922
2842
|
|
|
2923
|
-
|
|
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);
|
|
2924
2846
|
|
|
2925
|
-
|
|
2926
|
-
|
|
2847
|
+
var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
|
|
2848
|
+
function DefaultElementLifeCycleContribution(context) {
|
|
2849
|
+
this.context = void 0;
|
|
2850
|
+
this.context = context;
|
|
2851
|
+
}
|
|
2927
2852
|
|
|
2928
|
-
|
|
2853
|
+
var _proto = DefaultElementLifeCycleContribution.prototype;
|
|
2929
2854
|
|
|
2930
|
-
|
|
2931
|
-
|
|
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);
|
|
2859
|
+
};
|
|
2932
2860
|
|
|
2933
|
-
|
|
2934
|
-
};
|
|
2861
|
+
_proto.destroyElement = function destroyElement(object, $el) {};
|
|
2935
2862
|
|
|
2936
|
-
|
|
2937
|
-
|
|
2863
|
+
_proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
|
|
2864
|
+
var nodeName = object.nodeName;
|
|
2865
|
+
return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
|
|
2866
|
+
};
|
|
2938
2867
|
|
|
2939
|
-
|
|
2868
|
+
_proto.updateElementAttribute = function updateElementAttribute(object) {
|
|
2869
|
+
// @ts-ignore
|
|
2870
|
+
var $el = object.elementSVG.$el;
|
|
2871
|
+
var nodeName = object.nodeName,
|
|
2872
|
+
parsedStyle = object.parsedStyle;
|
|
2940
2873
|
|
|
2941
|
-
|
|
2942
|
-
|
|
2874
|
+
switch (nodeName) {
|
|
2875
|
+
case gLite.Shape.IMAGE:
|
|
2876
|
+
{
|
|
2877
|
+
updateImageElementAttribute($el, parsedStyle);
|
|
2878
|
+
break;
|
|
2879
|
+
}
|
|
2943
2880
|
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2881
|
+
case gLite.Shape.RECT:
|
|
2882
|
+
{
|
|
2883
|
+
updateRectElementAttribute($el, parsedStyle);
|
|
2884
|
+
break;
|
|
2885
|
+
}
|
|
2947
2886
|
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2887
|
+
case gLite.Shape.LINE:
|
|
2888
|
+
{
|
|
2889
|
+
updateLineElementAttribute($el, parsedStyle);
|
|
2890
|
+
break;
|
|
2891
|
+
}
|
|
2951
2892
|
|
|
2952
|
-
|
|
2893
|
+
case gLite.Shape.POLYGON:
|
|
2894
|
+
case gLite.Shape.POLYLINE:
|
|
2895
|
+
{
|
|
2896
|
+
updatePolylineElementAttribute($el, parsedStyle);
|
|
2897
|
+
break;
|
|
2898
|
+
}
|
|
2953
2899
|
|
|
2954
|
-
|
|
2900
|
+
case gLite.Shape.PATH:
|
|
2901
|
+
{
|
|
2902
|
+
updatePathElementAttribute($el, parsedStyle);
|
|
2903
|
+
break;
|
|
2904
|
+
}
|
|
2955
2905
|
|
|
2956
|
-
|
|
2957
|
-
|
|
2906
|
+
case gLite.Shape.TEXT:
|
|
2907
|
+
{
|
|
2908
|
+
updateTextElementAttribute($el, parsedStyle);
|
|
2909
|
+
break;
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
};
|
|
2958
2913
|
|
|
2959
|
-
|
|
2960
|
-
|
|
2914
|
+
return DefaultElementLifeCycleContribution;
|
|
2915
|
+
}();
|
|
2961
2916
|
|
|
2962
|
-
|
|
2963
|
-
|
|
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
|
+
*/
|
|
2964
2922
|
|
|
2965
|
-
|
|
2966
|
-
|
|
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 + "]");
|
|
2967
2927
|
|
|
2968
|
-
|
|
2928
|
+
if ($existedFilters.length) {
|
|
2929
|
+
$existedFilters.forEach(function ($filter) {
|
|
2930
|
+
$def.removeChild($filter);
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2969
2933
|
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
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
|
|
2974
2942
|
|
|
2975
|
-
|
|
2976
|
-
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill');
|
|
2977
|
-
}
|
|
2943
|
+
$filter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
2978
2944
|
|
|
2979
|
-
if (
|
|
2980
|
-
|
|
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);
|
|
2981
2963
|
}
|
|
2982
|
-
};
|
|
2983
2964
|
|
|
2984
|
-
|
|
2985
|
-
|
|
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
|
|
2986
2970
|
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
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
|
+
}
|
|
2992
2978
|
|
|
2993
|
-
|
|
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
|
+
*/
|
|
2994
2985
|
|
|
2995
|
-
$svg = _this.contextService.getContext();
|
|
2996
2986
|
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
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
|
+
}
|
|
2993
|
+
|
|
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);
|
|
3000
3002
|
|
|
3003
|
+
if (type === 'table') {
|
|
3004
|
+
$feFunc.setAttribute('tableValues', "" + tableValues);
|
|
3005
|
+
} else {
|
|
3006
|
+
$feFunc.setAttribute('slope', "" + slope);
|
|
3007
|
+
$feFunc.setAttribute('intercept', "" + intercept);
|
|
3008
|
+
}
|
|
3001
3009
|
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3010
|
+
$feComponentTransfer.appendChild($feFunc);
|
|
3011
|
+
});
|
|
3012
|
+
$filter.appendChild($feComponentTransfer);
|
|
3013
|
+
}
|
|
3005
3014
|
|
|
3006
|
-
|
|
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
|
+
}
|
|
3007
3023
|
|
|
3008
|
-
|
|
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
|
+
}
|
|
3031
|
+
|
|
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
|
+
}
|
|
3009
3048
|
|
|
3010
|
-
|
|
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
|
+
}
|
|
3011
3055
|
|
|
3012
|
-
|
|
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
|
|
3013
3060
|
|
|
3014
|
-
|
|
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
|
+
}
|
|
3015
3086
|
|
|
3016
|
-
|
|
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
|
+
*/
|
|
3017
3096
|
|
|
3018
|
-
case 13:
|
|
3019
|
-
case "end":
|
|
3020
|
-
return _context.stop();
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
3023
|
-
}, _callee);
|
|
3024
|
-
})));
|
|
3025
|
-
renderingService.hooks.destroy.tap(SVGRendererPlugin_1.tag, function () {
|
|
3026
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
3027
3097
|
|
|
3028
|
-
|
|
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
|
+
*/
|
|
3029
3105
|
|
|
3030
|
-
_this.renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
3031
3106
|
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
_this.renderQueue.push(object); // }
|
|
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
|
+
}
|
|
3037
3111
|
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3112
|
+
var PATTERN_PREFIX = 'g-pattern-';
|
|
3113
|
+
var cacheKey2IDMap = {};
|
|
3114
|
+
var counter = 0;
|
|
3041
3115
|
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3116
|
+
function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage) {
|
|
3117
|
+
// eg. clipPath don't have fill/stroke
|
|
3118
|
+
if (!parsedColor) {
|
|
3119
|
+
return '';
|
|
3120
|
+
}
|
|
3045
3121
|
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
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
|
|
3049
3133
|
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
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
|
+
}
|
|
3054
3149
|
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
});
|
|
3058
|
-
renderingService.hooks.endFrame.tap(SVGRendererPlugin_1.tag, function () {
|
|
3059
|
-
if (_this.renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
|
|
3060
|
-
_this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
|
|
3061
|
-
}
|
|
3150
|
+
return '';
|
|
3151
|
+
}
|
|
3062
3152
|
|
|
3063
|
-
|
|
3064
|
-
|
|
3153
|
+
function generateCacheKey(src, options) {
|
|
3154
|
+
if (options === void 0) {
|
|
3155
|
+
options = {};
|
|
3156
|
+
}
|
|
3065
3157
|
|
|
3158
|
+
var cacheKey = '';
|
|
3066
3159
|
|
|
3067
|
-
|
|
3160
|
+
if (src instanceof gLite.CSSGradientValue) {
|
|
3161
|
+
var type = src.type,
|
|
3162
|
+
value = src.value;
|
|
3068
3163
|
|
|
3069
|
-
|
|
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;
|
|
3070
3175
|
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
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
|
+
}
|
|
3075
3189
|
|
|
3190
|
+
if (cacheKey) {
|
|
3191
|
+
if (!cacheKey2IDMap[cacheKey]) {
|
|
3192
|
+
cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3076
3195
|
|
|
3077
|
-
|
|
3078
|
-
|
|
3196
|
+
return cacheKey2IDMap[cacheKey];
|
|
3197
|
+
}
|
|
3079
3198
|
|
|
3199
|
+
function createOrUpdatePattern(document, $def, object, pattern, createImage) {
|
|
3200
|
+
var patternId = generateCacheKey(pattern);
|
|
3201
|
+
var $existed = $def.querySelector("#" + patternId);
|
|
3080
3202
|
|
|
3081
|
-
|
|
3203
|
+
if (!$existed) {
|
|
3204
|
+
var image = pattern.image,
|
|
3205
|
+
repetition = pattern.repetition;
|
|
3206
|
+
var imageURL = '';
|
|
3082
3207
|
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
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
|
+
}
|
|
3218
|
+
}
|
|
3087
3219
|
|
|
3088
|
-
|
|
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
|
|
3089
3229
|
|
|
3090
|
-
|
|
3230
|
+
$image.setAttribute('href', imageURL);
|
|
3231
|
+
var img;
|
|
3091
3232
|
|
|
3092
|
-
|
|
3233
|
+
if (createImage) {
|
|
3234
|
+
img = createImage(imageURL);
|
|
3235
|
+
} else if (gLite.isBrowser) {
|
|
3236
|
+
img = new window.Image();
|
|
3237
|
+
}
|
|
3093
3238
|
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
_this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
3099
|
-
}
|
|
3239
|
+
if (!imageURL.match(/^data:/i)) {
|
|
3240
|
+
img.crossOrigin = 'Anonymous';
|
|
3241
|
+
$image.setAttribute('crossorigin', 'anonymous');
|
|
3242
|
+
}
|
|
3100
3243
|
|
|
3101
|
-
|
|
3102
|
-
});
|
|
3244
|
+
img.src = imageURL;
|
|
3103
3245
|
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3246
|
+
var onload = function onload() {
|
|
3247
|
+
$pattern.setAttribute('x', '0');
|
|
3248
|
+
$pattern.setAttribute('y', '0');
|
|
3107
3249
|
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
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
|
|
3111
3253
|
|
|
3112
|
-
_proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
|
|
3113
|
-
// need to reorder parent's children
|
|
3114
|
-
children.sort(function (a, b) {
|
|
3115
|
-
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
3116
|
-
});
|
|
3117
3254
|
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
var fragment = (doc || document).createDocumentFragment();
|
|
3121
|
-
children.forEach(function (child) {
|
|
3122
|
-
if (child.isConnected) {
|
|
3123
|
-
// @ts-ignore
|
|
3124
|
-
var $el = child.elementSVG.$groupEl;
|
|
3255
|
+
var patternWidth = img.width;
|
|
3256
|
+
var patternHeight = img.height;
|
|
3125
3257
|
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
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;
|
|
3129
3265
|
}
|
|
3130
|
-
});
|
|
3131
|
-
$groupEl.appendChild(fragment);
|
|
3132
|
-
}
|
|
3133
|
-
};
|
|
3134
|
-
|
|
3135
|
-
_proto.applyTransform = function applyTransform($el, rts) {
|
|
3136
|
-
// use proper precision avoiding too long string in `transform`
|
|
3137
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
3138
|
-
$el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
|
|
3139
|
-
};
|
|
3140
|
-
|
|
3141
|
-
_proto.applyAttributes = function applyAttributes(object) {
|
|
3142
|
-
// @ts-ignore
|
|
3143
|
-
var elementSVG = object.elementSVG;
|
|
3144
|
-
var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
|
|
3145
|
-
var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
|
|
3146
|
-
|
|
3147
|
-
if ($el && $groupEl) {
|
|
3148
|
-
var nodeName = object.nodeName,
|
|
3149
|
-
attributes = object.attributes;
|
|
3150
|
-
$el.setAttribute('fill', 'none');
|
|
3151
3266
|
|
|
3152
|
-
|
|
3153
|
-
$
|
|
3154
|
-
|
|
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
|
+
};
|
|
3155
3274
|
|
|
3275
|
+
if (img.complete) {
|
|
3276
|
+
onload();
|
|
3277
|
+
} else {
|
|
3278
|
+
img.onload = onload; // Fix onload() bug in IE9
|
|
3156
3279
|
|
|
3157
|
-
|
|
3280
|
+
img.src = img.src;
|
|
3281
|
+
}
|
|
3158
3282
|
}
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
_proto.updateAttribute = function updateAttribute(object, attributes) {
|
|
3162
|
-
var _this2 = this;
|
|
3283
|
+
}
|
|
3163
3284
|
|
|
3164
|
-
|
|
3285
|
+
return patternId;
|
|
3286
|
+
}
|
|
3165
3287
|
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
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);
|
|
3175
3297
|
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
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
|
|
3180
3303
|
|
|
3181
|
-
|
|
3182
|
-
_this2.updateAnchorWithTransform(object);
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
});
|
|
3186
|
-
} // update common attributes
|
|
3304
|
+
$existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
|
|
3187
3305
|
|
|
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`
|
|
3188
3313
|
|
|
3189
|
-
|
|
3190
|
-
|
|
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
|
+
}
|
|
3191
3320
|
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
var computedValueStr = computedValue && computedValue.toString();
|
|
3195
|
-
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;
|
|
3196
|
-
var usedValue = parsedStyle[name];
|
|
3197
|
-
var inherited = !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
|
|
3321
|
+
if (parsedColor.type === gLite.GradientType.LinearGradient) {
|
|
3322
|
+
var angle = parsedColor.value.angle;
|
|
3198
3323
|
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3324
|
+
var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
|
|
3325
|
+
x1 = _computeLinearGradien.x1,
|
|
3326
|
+
y1 = _computeLinearGradien.y1,
|
|
3327
|
+
x2 = _computeLinearGradien.x2,
|
|
3328
|
+
y2 = _computeLinearGradien.y2;
|
|
3202
3329
|
|
|
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;
|
|
3203
3339
|
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
$el.style['border-style'] = 'dashed';
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3340
|
+
var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
|
|
3341
|
+
x = _computeRadialGradien.x,
|
|
3342
|
+
y = _computeRadialGradien.y,
|
|
3343
|
+
r = _computeRadialGradien.r;
|
|
3211
3344
|
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
|
|
3217
|
-
}
|
|
3218
|
-
} else if (name === 'stroke') {
|
|
3219
|
-
if (object.nodeName === gLite.Shape.HTML) {
|
|
3220
|
-
$el.style['border-color'] = usedValue.toString();
|
|
3221
|
-
$el.style['border-style'] = 'solid';
|
|
3222
|
-
} else {
|
|
3223
|
-
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
|
|
3224
|
-
}
|
|
3225
|
-
} else if (inherited && usedName) {
|
|
3226
|
-
// use computed value
|
|
3227
|
-
// update `visibility` on <group>
|
|
3228
|
-
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
3229
|
-
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, formattedValueStr);
|
|
3230
|
-
} else {
|
|
3231
|
-
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.removeAttribute(usedName);
|
|
3232
|
-
}
|
|
3233
|
-
} else if (name === 'clipPath') {
|
|
3234
|
-
_this2.createOrUpdateClipPath(document, usedValue, $groupEl);
|
|
3235
|
-
} else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
|
|
3236
|
-
_this2.defElementManager.createOrUpdateShadow(object, $el, name);
|
|
3237
|
-
} else if (name === 'filter') {
|
|
3238
|
-
_this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
|
|
3239
|
-
} else if (name === 'innerHTML') {
|
|
3240
|
-
_this2.createOrUpdateInnerHTML(document, $el, usedValue);
|
|
3241
|
-
} else if (name === 'anchor') {
|
|
3242
|
-
// text' anchor is controlled by `textAnchor` property
|
|
3243
|
-
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
3244
|
-
_this2.updateAnchorWithTransform(object);
|
|
3245
|
-
}
|
|
3246
|
-
} else {
|
|
3247
|
-
if (computedValue) {
|
|
3248
|
-
// use computed value so that we can use cascaded effect in SVG
|
|
3249
|
-
// ignore 'unset' and default value
|
|
3250
|
-
[$el, $hitTestingEl].forEach(function ($el) {
|
|
3251
|
-
if ($el && usedName) {
|
|
3252
|
-
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
3253
|
-
$el.setAttribute(usedName, formattedValueStr);
|
|
3254
|
-
} else {
|
|
3255
|
-
$el.removeAttribute(usedName);
|
|
3256
|
-
}
|
|
3257
|
-
}
|
|
3258
|
-
});
|
|
3259
|
-
}
|
|
3260
|
-
}
|
|
3261
|
-
});
|
|
3262
|
-
};
|
|
3345
|
+
$existed.setAttribute('cx', "" + x);
|
|
3346
|
+
$existed.setAttribute('cy', "" + y);
|
|
3347
|
+
$existed.setAttribute('r', "" + r);
|
|
3348
|
+
}
|
|
3263
3349
|
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
noWrapWithGroup = false;
|
|
3267
|
-
} // create svg element
|
|
3268
|
-
// @ts-ignore
|
|
3350
|
+
return gradientId;
|
|
3351
|
+
}
|
|
3269
3352
|
|
|
3353
|
+
function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
|
|
3354
|
+
var filterId = FILTER_PREFIX + object.entity + '-gradient';
|
|
3355
|
+
var $existed = $def.querySelector("#" + filterId);
|
|
3270
3356
|
|
|
3271
|
-
|
|
3357
|
+
if (!$existed) {
|
|
3358
|
+
$existed = createSVGElement('filter', document);
|
|
3359
|
+
$existed.setAttribute('filterUnits', 'userSpaceOnUse'); // @see https://github.com/antvis/g/issues/1025
|
|
3272
3360
|
|
|
3273
|
-
|
|
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);
|
|
3367
|
+
}
|
|
3368
|
+
/**
|
|
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>
|
|
3376
|
+
*/
|
|
3274
3377
|
|
|
3275
|
-
var $el = this.createElementContribution.createElement(object);
|
|
3276
3378
|
|
|
3277
|
-
|
|
3278
|
-
|
|
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);
|
|
3279
3395
|
|
|
3280
|
-
|
|
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
|
|
3281
3401
|
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
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
|
+
}
|
|
3285
3413
|
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
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
|
+
*/
|
|
3289
3419
|
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
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);
|
|
3293
3430
|
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
$groupEl.appendChild($el);
|
|
3297
|
-
} else {
|
|
3298
|
-
$groupEl = $el;
|
|
3299
|
-
}
|
|
3431
|
+
if ($existedFilter) {
|
|
3432
|
+
var existedShadowType = $existedFilter.getAttribute('data-type');
|
|
3300
3433
|
|
|
3301
|
-
|
|
3302
|
-
|
|
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
|
|
3303
3441
|
|
|
3304
|
-
this.applyAttributes(object); // create hitArea if necessary
|
|
3305
3442
|
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
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;
|
|
3450
|
+
}
|
|
3309
3451
|
|
|
3310
|
-
|
|
3311
|
-
|
|
3452
|
+
if (!$existedFilter) {
|
|
3453
|
+
$existedFilter = createSVGElement('filter', document);
|
|
3454
|
+
$existedFilter.setAttribute('data-type', shadowType);
|
|
3312
3455
|
|
|
3313
|
-
|
|
3314
|
-
|
|
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);
|
|
3315
3498
|
}
|
|
3316
|
-
};
|
|
3317
3499
|
|
|
3318
|
-
|
|
3319
|
-
var _object$elementSVG6; // @ts-ignore
|
|
3500
|
+
$existedFilter.id = shadowId; // @see https://github.com/antvis/g/issues/1025
|
|
3320
3501
|
|
|
3502
|
+
$existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
3503
|
+
$def.appendChild($existedFilter);
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3321
3506
|
|
|
3322
|
-
|
|
3507
|
+
if (shadowType === 'inner') {
|
|
3508
|
+
var _$feGaussianBlur = $existedFilter.children[1];
|
|
3509
|
+
var _$feOffset = $existedFilter.children[2];
|
|
3510
|
+
var _$feFlood = $existedFilter.children[3];
|
|
3323
3511
|
|
|
3324
|
-
if (
|
|
3325
|
-
$
|
|
3326
|
-
|
|
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);
|
|
3327
3523
|
}
|
|
3328
|
-
}
|
|
3329
|
-
|
|
3330
|
-
_proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
|
|
3331
|
-
// @ts-ignore
|
|
3332
|
-
var svgElement = object.elementSVG;
|
|
3333
|
-
var $hitTestingEl = svgElement.$hitTestingEl;
|
|
3334
|
-
var increasedLineWidthForHitTesting = object.parsedStyle.increasedLineWidthForHitTesting; // account for hitArea
|
|
3335
|
-
|
|
3336
|
-
if (increasedLineWidthForHitTesting) {
|
|
3337
|
-
if (!$hitTestingEl) {
|
|
3338
|
-
$hitTestingEl = $el.cloneNode();
|
|
3524
|
+
} else if (shadowType === 'outer') {
|
|
3525
|
+
var _$feDropShadow = $existedFilter.children[0];
|
|
3339
3526
|
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
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);
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3344
3541
|
|
|
3542
|
+
var urlRegexp = /url\(#(.*)\)/;
|
|
3345
3543
|
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
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;
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* container for <gradient> <clipPath>...
|
|
3553
|
+
*/
|
|
3349
3554
|
|
|
3350
|
-
var hasFill = $el.getAttribute('fill') !== 'none';
|
|
3351
|
-
$hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
|
|
3352
|
-
$hitTestingEl.setAttribute('stroke', 'transparent');
|
|
3353
|
-
$groupEl.appendChild($hitTestingEl);
|
|
3354
|
-
svgElement.$hitTestingEl = $hitTestingEl;
|
|
3355
|
-
} // increase interactive line width
|
|
3356
3555
|
|
|
3556
|
+
var _proto = DefElementManager.prototype;
|
|
3357
3557
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
if ($hitTestingEl) {
|
|
3361
|
-
$groupEl.removeChild($hitTestingEl);
|
|
3362
|
-
svgElement.$hitTestingEl = null;
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3558
|
+
_proto.getDefElement = function getDefElement() {
|
|
3559
|
+
return this.$def;
|
|
3365
3560
|
};
|
|
3366
3561
|
|
|
3367
|
-
_proto.
|
|
3368
|
-
var
|
|
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
|
+
};
|
|
3369
3568
|
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
} else {
|
|
3373
|
-
$div.appendChild(usedValue);
|
|
3374
|
-
}
|
|
3569
|
+
_proto.clear = function clear(entity) {
|
|
3570
|
+
var _this = this;
|
|
3375
3571
|
|
|
3376
|
-
|
|
3377
|
-
|
|
3572
|
+
Object.keys(this.gradientCache).forEach(function (id) {
|
|
3573
|
+
_this.clearUnusedDefElement(_this.gradientCache, id, entity);
|
|
3574
|
+
});
|
|
3378
3575
|
};
|
|
3379
3576
|
|
|
3380
|
-
_proto.
|
|
3381
|
-
if (
|
|
3382
|
-
var
|
|
3383
|
-
|
|
3384
|
-
var clipPathId = CLIP_PATH_PREFIX + clipPath.entity;
|
|
3385
|
-
var $def = this.defElementManager.getDefElement();
|
|
3386
|
-
var existed = $def.querySelector("#" + clipPathId);
|
|
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);
|
|
3387
3580
|
|
|
3388
|
-
if (
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3581
|
+
if (targetElement) {
|
|
3582
|
+
this.$def.removeChild(targetElement);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3393
3586
|
|
|
3394
|
-
|
|
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;
|
|
3395
3591
|
|
|
3396
|
-
|
|
3397
|
-
|
|
3592
|
+
if ($el) {
|
|
3593
|
+
var _$el$getAttribute; // `url(#${gradientId})`
|
|
3398
3594
|
|
|
3399
3595
|
|
|
3400
|
-
var
|
|
3596
|
+
var matches = (_$el$getAttribute = $el.getAttribute(name)) === null || _$el$getAttribute === void 0 ? void 0 : _$el$getAttribute.match(urlRegexp);
|
|
3401
3597
|
|
|
3402
|
-
if (
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
} // apply attributes
|
|
3598
|
+
if (matches && matches.length > 1) {
|
|
3599
|
+
this.clearUnusedDefElement(this.gradientCache, matches[1], object.entity);
|
|
3600
|
+
}
|
|
3406
3601
|
|
|
3602
|
+
var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage);
|
|
3407
3603
|
|
|
3408
|
-
this.
|
|
3409
|
-
|
|
3604
|
+
if (!this.gradientCache[newDefElementId]) {
|
|
3605
|
+
this.gradientCache[newDefElementId] = new Set();
|
|
3606
|
+
}
|
|
3410
3607
|
|
|
3411
|
-
|
|
3412
|
-
} else {
|
|
3413
|
-
// remove clip path
|
|
3414
|
-
$groupEl.removeAttribute('clip-path');
|
|
3608
|
+
this.gradientCache[newDefElementId].add(object.entity);
|
|
3415
3609
|
}
|
|
3416
|
-
}
|
|
3417
|
-
/**
|
|
3418
|
-
* the origin is bounding box's top left corner
|
|
3419
|
-
*/
|
|
3420
|
-
;
|
|
3421
|
-
|
|
3422
|
-
_proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
|
|
3423
|
-
var _object$elementSVG7, _object$elementSVG8;
|
|
3424
|
-
|
|
3425
|
-
var bounds = object.getGeometryBounds();
|
|
3426
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
3427
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
3428
|
-
|
|
3429
|
-
var _ref2 = object.parsedStyle || {},
|
|
3430
|
-
anchor = _ref2.anchor; // @ts-ignore
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
[(_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) {
|
|
3434
|
-
if ($el) {
|
|
3435
|
-
var tx = -(anchor[0] * width);
|
|
3436
|
-
var ty = -(anchor[1] * height);
|
|
3610
|
+
};
|
|
3437
3611
|
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
"translate(" + tx + "," + ty + ")");
|
|
3443
|
-
}
|
|
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
|
+
};
|
|
3444
3616
|
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
}
|
|
3449
|
-
}
|
|
3450
|
-
});
|
|
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);
|
|
3451
3620
|
};
|
|
3452
3621
|
|
|
3453
|
-
return
|
|
3454
|
-
}()
|
|
3455
|
-
SVGRendererPlugin = SVGRendererPlugin_1 = __decorate([gLite.singleton({
|
|
3456
|
-
contrib: gLite.RenderingPluginContribution
|
|
3457
|
-
}), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.DefaultCamera)), __param(2, gLite.inject(gLite.ContextService)), __param(3, gLite.inject(gLite.RenderingContext)), __param(4, gLite.inject(gLite.StyleValueRegistry)), __param(5, gLite.inject(ElementLifeCycleContribution)), __param(6, gLite.inject(DefElementManager)), __param(7, gLite.inject(SVGRendererPluginOptions))], SVGRendererPlugin);
|
|
3458
|
-
var containerModule$1 = gLite.Module(function (register) {
|
|
3459
|
-
register(DefElementManager);
|
|
3460
|
-
register(DefaultElementLifeCycleContribution);
|
|
3461
|
-
register(SVGRendererPlugin);
|
|
3462
|
-
});
|
|
3622
|
+
return DefElementManager;
|
|
3623
|
+
}();
|
|
3463
3624
|
|
|
3464
3625
|
var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
3465
3626
|
_inheritsLoose$2(Plugin, _AbstractRendererPlug);
|
|
@@ -3484,18 +3645,27 @@
|
|
|
3484
3645
|
var _this$options = this.options,
|
|
3485
3646
|
outputSVGElementId = _this$options.outputSVGElementId,
|
|
3486
3647
|
outputSVGElementName = _this$options.outputSVGElementName;
|
|
3487
|
-
this.
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
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));
|
|
3494
3661
|
};
|
|
3495
3662
|
|
|
3496
3663
|
_proto.destroy = function destroy() {
|
|
3497
|
-
this.
|
|
3498
|
-
|
|
3664
|
+
this.removeAllRenderingPlugins(); // @ts-ignore
|
|
3665
|
+
|
|
3666
|
+
delete this.context.defaultElementLifeCycleContribution; // @ts-ignore
|
|
3667
|
+
|
|
3668
|
+
delete this.context.SVGElementLifeCycleContribution;
|
|
3499
3669
|
};
|
|
3500
3670
|
|
|
3501
3671
|
return Plugin;
|
|
@@ -3503,18 +3673,17 @@
|
|
|
3503
3673
|
|
|
3504
3674
|
var index_esm$1 = /*#__PURE__*/Object.freeze({
|
|
3505
3675
|
__proto__: null,
|
|
3676
|
+
CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
|
|
3506
3677
|
DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
|
|
3507
|
-
|
|
3508
|
-
ElementLifeCycleContribution: ElementLifeCycleContribution,
|
|
3678
|
+
DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
|
|
3509
3679
|
ElementSVG: ElementSVG,
|
|
3510
3680
|
G_SVG_PREFIX: G_SVG_PREFIX,
|
|
3511
3681
|
Plugin: Plugin$1,
|
|
3512
3682
|
SHAPE2TAGS: SHAPE2TAGS,
|
|
3513
3683
|
SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
|
|
3514
|
-
|
|
3515
|
-
SVGRendererPluginOptions: SVGRendererPluginOptions,
|
|
3684
|
+
SVGRendererPlugin: SVGRendererPlugin,
|
|
3516
3685
|
SVG_ATTR_MAP: SVG_ATTR_MAP,
|
|
3517
|
-
|
|
3686
|
+
TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
|
|
3518
3687
|
createSVGElement: createSVGElement,
|
|
3519
3688
|
updateImageElementAttribute: updateImageElementAttribute,
|
|
3520
3689
|
updateLineElementAttribute: updateLineElementAttribute,
|
|
@@ -3964,10 +4133,6 @@
|
|
|
3964
4133
|
|
|
3965
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.");
|
|
3966
4135
|
}
|
|
3967
|
-
|
|
3968
|
-
var _class$2;
|
|
3969
|
-
|
|
3970
|
-
var SVGPickerPlugin_1;
|
|
3971
4136
|
/**
|
|
3972
4137
|
* pick shape(s) with Mouse/Touch event
|
|
3973
4138
|
*
|
|
@@ -3975,21 +4140,18 @@
|
|
|
3975
4140
|
* 2. use elementFromPoint
|
|
3976
4141
|
*/
|
|
3977
4142
|
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
this.displayObjectPool = void 0;
|
|
3982
|
-
this.canvasConfig = canvasConfig;
|
|
3983
|
-
this.displayObjectPool = displayObjectPool;
|
|
3984
|
-
}
|
|
4143
|
+
|
|
4144
|
+
var SVGPickerPlugin = /*#__PURE__*/function () {
|
|
4145
|
+
function SVGPickerPlugin() {}
|
|
3985
4146
|
|
|
3986
4147
|
var _proto = SVGPickerPlugin.prototype;
|
|
3987
4148
|
|
|
3988
|
-
_proto.apply = function apply(
|
|
4149
|
+
_proto.apply = function apply(context) {
|
|
3989
4150
|
var _this = this;
|
|
3990
4151
|
|
|
3991
|
-
var doc =
|
|
3992
|
-
|
|
4152
|
+
var doc = context.config.document,
|
|
4153
|
+
renderingService = context.renderingService;
|
|
4154
|
+
renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
|
|
3993
4155
|
var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
|
|
3994
4156
|
return _regeneratorRuntime$3().wrap(function _callee$(_context) {
|
|
3995
4157
|
while (1) {
|
|
@@ -4009,7 +4171,7 @@
|
|
|
4009
4171
|
return _ref.apply(this, arguments);
|
|
4010
4172
|
};
|
|
4011
4173
|
}());
|
|
4012
|
-
renderingService.hooks.pickSync.tap(
|
|
4174
|
+
renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
|
|
4013
4175
|
return _this.pick(doc, result);
|
|
4014
4176
|
});
|
|
4015
4177
|
};
|
|
@@ -4030,7 +4192,7 @@
|
|
|
4030
4192
|
|
|
4031
4193
|
if (id && id.startsWith(G_SVG_PREFIX)) {
|
|
4032
4194
|
var index = id.lastIndexOf('_');
|
|
4033
|
-
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
|
|
4034
4196
|
|
|
4035
4197
|
if (target && target.isInteractive()) {
|
|
4036
4198
|
targets.push(target);
|
|
@@ -4052,13 +4214,9 @@
|
|
|
4052
4214
|
};
|
|
4053
4215
|
|
|
4054
4216
|
return SVGPickerPlugin;
|
|
4055
|
-
}()
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
}), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.DisplayObjectPool))], SVGPickerPlugin);
|
|
4059
|
-
var containerModule$2 = gLite.Module(function (register) {
|
|
4060
|
-
register(SVGPickerPlugin);
|
|
4061
|
-
});
|
|
4217
|
+
}();
|
|
4218
|
+
|
|
4219
|
+
SVGPickerPlugin.tag = 'SVGPicker';
|
|
4062
4220
|
|
|
4063
4221
|
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4064
4222
|
_inheritsLoose$3(Plugin, _AbstractRendererPlug);
|
|
@@ -4078,11 +4236,11 @@
|
|
|
4078
4236
|
var _proto = Plugin.prototype;
|
|
4079
4237
|
|
|
4080
4238
|
_proto.init = function init() {
|
|
4081
|
-
this.
|
|
4239
|
+
this.addRenderingPlugin(new SVGPickerPlugin());
|
|
4082
4240
|
};
|
|
4083
4241
|
|
|
4084
4242
|
_proto.destroy = function destroy() {
|
|
4085
|
-
this.
|
|
4243
|
+
this.removeAllRenderingPlugins();
|
|
4086
4244
|
};
|
|
4087
4245
|
|
|
4088
4246
|
return Plugin;
|
|
@@ -4094,12 +4252,12 @@
|
|
|
4094
4252
|
});
|
|
4095
4253
|
|
|
4096
4254
|
var SVGContextService = /*#__PURE__*/function () {
|
|
4097
|
-
function SVGContextService(
|
|
4098
|
-
this.canvasConfig = void 0;
|
|
4255
|
+
function SVGContextService(context) {
|
|
4099
4256
|
this.$container = void 0;
|
|
4100
4257
|
this.$namespace = void 0;
|
|
4101
4258
|
this.dpr = void 0;
|
|
4102
|
-
this.canvasConfig =
|
|
4259
|
+
this.canvasConfig = void 0;
|
|
4260
|
+
this.canvasConfig = context.config;
|
|
4103
4261
|
}
|
|
4104
4262
|
|
|
4105
4263
|
var _proto = SVGContextService.prototype;
|
|
@@ -4220,16 +4378,6 @@
|
|
|
4220
4378
|
return SVGContextService;
|
|
4221
4379
|
}();
|
|
4222
4380
|
|
|
4223
|
-
SVGContextService = __decorate([gLite.singleton({
|
|
4224
|
-
token: gLite.ContextService
|
|
4225
|
-
}), __param(0, gLite.inject(gLite.CanvasConfig))], SVGContextService);
|
|
4226
|
-
|
|
4227
|
-
var containerModule$3 = gLite.Module(function (register) {
|
|
4228
|
-
/**
|
|
4229
|
-
* implements ContextService
|
|
4230
|
-
*/
|
|
4231
|
-
register(SVGContextService);
|
|
4232
|
-
});
|
|
4233
4381
|
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
4234
4382
|
_inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
4235
4383
|
|
|
@@ -4248,11 +4396,12 @@
|
|
|
4248
4396
|
var _proto = ContextRegisterPlugin.prototype;
|
|
4249
4397
|
|
|
4250
4398
|
_proto.init = function init() {
|
|
4251
|
-
|
|
4399
|
+
// @ts-ignore
|
|
4400
|
+
this.context.ContextService = SVGContextService;
|
|
4252
4401
|
};
|
|
4253
4402
|
|
|
4254
4403
|
_proto.destroy = function destroy() {
|
|
4255
|
-
this.
|
|
4404
|
+
delete this.context.ContextService;
|
|
4256
4405
|
};
|
|
4257
4406
|
|
|
4258
4407
|
return ContextRegisterPlugin;
|