逐步完成前后端服务器

This commit is contained in:
2025-09-09 15:00:30 +08:00
parent fcb09432e9
commit c7dfa1e9fc
2937 changed files with 1477567 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import Displayable from '../graphic/Displayable';
import Storage from '../Storage';
import { PainterBase } from '../PainterBase';
interface SVGPainterOption {
width?: number | string;
height?: number | string;
}
declare class SVGPainter implements PainterBase {
type: string;
root: HTMLElement;
storage: Storage;
private _opts;
private _svgDom;
private _svgRoot;
private _backgroundRoot;
private _backgroundNode;
private _gradientManager;
private _patternManager;
private _clipPathManager;
private _shadowManager;
private _viewport;
private _visibleList;
private _width;
private _height;
constructor(root: HTMLElement, storage: Storage, opts: SVGPainterOption, zrId: number);
getType(): string;
getViewportRoot(): HTMLDivElement;
getSvgDom(): SVGElement;
getSvgRoot(): SVGGElement;
getViewportRootOffset(): {
offsetLeft: number;
offsetTop: number;
};
refresh(): void;
setBackgroundColor(backgroundColor: string): void;
createSVGElement(tag: string): SVGElement;
paintOne(el: Displayable): SVGElement;
_paintList(list: Displayable[]): void;
resize(width: number | string, height: number | string): void;
getWidth(): number;
getHeight(): number;
dispose(): void;
clear(): void;
toDataURL(): string;
refreshHover: () => void;
configLayer: (zlevel: number, config: import("../core/types").Dictionary<any>) => void;
}
export default SVGPainter;

292
frontend/node_modules/zrender/lib/svg-legacy/Painter.js generated vendored Normal file
View File

@ -0,0 +1,292 @@
import { createElement, SVGNS, XLINKNS, XMLNS } from '../svg/core.js';
import { normalizeColor } from '../svg/helper.js';
import * as util from '../core/util.js';
import Path from '../graphic/Path.js';
import ZRImage from '../graphic/Image.js';
import TSpan from '../graphic/TSpan.js';
import arrayDiff from '../core/arrayDiff.js';
import GradientManager from './helper/GradientManager.js';
import PatternManager from './helper/PatternManager.js';
import ClippathManager, { hasClipPath } from './helper/ClippathManager.js';
import ShadowManager from './helper/ShadowManager.js';
import { path as svgPath, image as svgImage, text as svgText } from './graphic.js';
import { getSize } from '../canvas/helper.js';
function getSvgProxy(el) {
if (el instanceof Path) {
return svgPath;
}
else if (el instanceof ZRImage) {
return svgImage;
}
else if (el instanceof TSpan) {
return svgText;
}
else {
return svgPath;
}
}
function checkParentAvailable(parent, child) {
return child && parent && child.parentNode !== parent;
}
function insertAfter(parent, child, prevSibling) {
if (checkParentAvailable(parent, child) && prevSibling) {
var nextSibling = prevSibling.nextSibling;
nextSibling ? parent.insertBefore(child, nextSibling)
: parent.appendChild(child);
}
}
function prepend(parent, child) {
if (checkParentAvailable(parent, child)) {
var firstChild = parent.firstChild;
firstChild ? parent.insertBefore(child, firstChild)
: parent.appendChild(child);
}
}
function remove(parent, child) {
if (child && parent && child.parentNode === parent) {
parent.removeChild(child);
}
}
function removeFromMyParent(child) {
if (child && child.parentNode) {
child.parentNode.removeChild(child);
}
}
function getSvgElement(displayable) {
return displayable.__svgEl;
}
var SVGPainter = (function () {
function SVGPainter(root, storage, opts, zrId) {
this.type = 'svg';
this.refreshHover = createMethodNotSupport('refreshHover');
this.configLayer = createMethodNotSupport('configLayer');
this.root = root;
this.storage = storage;
this._opts = opts = util.extend({}, opts || {});
var svgDom = createElement('svg');
svgDom.setAttributeNS(XMLNS, 'xmlns', SVGNS);
svgDom.setAttributeNS(XMLNS, 'xmlns:xlink', XLINKNS);
svgDom.setAttribute('version', '1.1');
svgDom.setAttribute('baseProfile', 'full');
svgDom.style.cssText = 'user-select:none;position:absolute;left:0;top:0;';
var bgRoot = createElement('g');
svgDom.appendChild(bgRoot);
var svgRoot = createElement('g');
svgDom.appendChild(svgRoot);
this._gradientManager = new GradientManager(zrId, svgRoot);
this._patternManager = new PatternManager(zrId, svgRoot);
this._clipPathManager = new ClippathManager(zrId, svgRoot);
this._shadowManager = new ShadowManager(zrId, svgRoot);
var viewport = document.createElement('div');
viewport.style.cssText = 'overflow:hidden;position:relative';
this._svgDom = svgDom;
this._svgRoot = svgRoot;
this._backgroundRoot = bgRoot;
this._viewport = viewport;
root.appendChild(viewport);
viewport.appendChild(svgDom);
this.resize(opts.width, opts.height);
this._visibleList = [];
}
SVGPainter.prototype.getType = function () {
return 'svg';
};
SVGPainter.prototype.getViewportRoot = function () {
return this._viewport;
};
SVGPainter.prototype.getSvgDom = function () {
return this._svgDom;
};
SVGPainter.prototype.getSvgRoot = function () {
return this._svgRoot;
};
SVGPainter.prototype.getViewportRootOffset = function () {
var viewportRoot = this.getViewportRoot();
if (viewportRoot) {
return {
offsetLeft: viewportRoot.offsetLeft || 0,
offsetTop: viewportRoot.offsetTop || 0
};
}
};
SVGPainter.prototype.refresh = function () {
var list = this.storage.getDisplayList(true);
this._paintList(list);
};
SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
if (this._backgroundRoot && this._backgroundNode) {
this._backgroundRoot.removeChild(this._backgroundNode);
}
var bgNode = createElement('rect');
bgNode.setAttribute('width', this.getWidth());
bgNode.setAttribute('height', this.getHeight());
bgNode.setAttribute('x', 0);
bgNode.setAttribute('y', 0);
bgNode.setAttribute('id', 0);
var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
bgNode.setAttribute('fill', color);
bgNode.setAttribute('fill-opacity', opacity);
this._backgroundRoot.appendChild(bgNode);
this._backgroundNode = bgNode;
};
SVGPainter.prototype.createSVGElement = function (tag) {
return createElement(tag);
};
SVGPainter.prototype.paintOne = function (el) {
var svgProxy = getSvgProxy(el);
svgProxy && svgProxy.brush(el);
return getSvgElement(el);
};
SVGPainter.prototype._paintList = function (list) {
var gradientManager = this._gradientManager;
var patternManager = this._patternManager;
var clipPathManager = this._clipPathManager;
var shadowManager = this._shadowManager;
gradientManager.markAllUnused();
patternManager.markAllUnused();
clipPathManager.markAllUnused();
shadowManager.markAllUnused();
var svgRoot = this._svgRoot;
var visibleList = this._visibleList;
var listLen = list.length;
var newVisibleList = [];
for (var i = 0; i < listLen; i++) {
var displayable = list[i];
var svgProxy = getSvgProxy(displayable);
var svgElement = getSvgElement(displayable);
if (!displayable.invisible) {
if (displayable.__dirty || !svgElement) {
svgProxy && svgProxy.brush(displayable);
svgElement = getSvgElement(displayable);
if (svgElement && displayable.style) {
gradientManager.update(displayable.style.fill);
gradientManager.update(displayable.style.stroke);
patternManager.update(displayable.style.fill);
patternManager.update(displayable.style.stroke);
shadowManager.update(svgElement, displayable);
}
displayable.__dirty = 0;
}
if (svgElement) {
newVisibleList.push(displayable);
}
}
}
var diff = arrayDiff(visibleList, newVisibleList);
var prevSvgElement;
var topPrevSvgElement;
for (var i = 0; i < diff.length; i++) {
var item = diff[i];
if (item.removed) {
for (var k = 0; k < item.count; k++) {
var displayable = visibleList[item.indices[k]];
var svgElement = getSvgElement(displayable);
hasClipPath(displayable) ? removeFromMyParent(svgElement)
: remove(svgRoot, svgElement);
}
}
}
var prevDisplayable;
var currentClipGroup;
for (var i = 0; i < diff.length; i++) {
var item = diff[i];
if (item.removed) {
continue;
}
for (var k = 0; k < item.count; k++) {
var displayable = newVisibleList[item.indices[k]];
var clipGroup = clipPathManager.update(displayable, prevDisplayable);
if (clipGroup !== currentClipGroup) {
prevSvgElement = topPrevSvgElement;
if (clipGroup) {
prevSvgElement ? insertAfter(svgRoot, clipGroup, prevSvgElement)
: prepend(svgRoot, clipGroup);
topPrevSvgElement = clipGroup;
prevSvgElement = null;
}
currentClipGroup = clipGroup;
}
var svgElement = getSvgElement(displayable);
prevSvgElement
? insertAfter(currentClipGroup || svgRoot, svgElement, prevSvgElement)
: prepend(currentClipGroup || svgRoot, svgElement);
prevSvgElement = svgElement || prevSvgElement;
if (!currentClipGroup) {
topPrevSvgElement = prevSvgElement;
}
gradientManager.markUsed(displayable);
gradientManager.addWithoutUpdate(svgElement, displayable);
patternManager.markUsed(displayable);
patternManager.addWithoutUpdate(svgElement, displayable);
clipPathManager.markUsed(displayable);
prevDisplayable = displayable;
}
}
gradientManager.removeUnused();
patternManager.removeUnused();
clipPathManager.removeUnused();
shadowManager.removeUnused();
this._visibleList = newVisibleList;
};
SVGPainter.prototype.resize = function (width, height) {
var viewport = this._viewport;
viewport.style.display = 'none';
var opts = this._opts;
width != null && (opts.width = width);
height != null && (opts.height = height);
width = getSize(this.root, 0, opts);
height = getSize(this.root, 1, opts);
viewport.style.display = '';
if (this._width !== width || this._height !== height) {
this._width = width;
this._height = height;
var viewportStyle = viewport.style;
viewportStyle.width = width + 'px';
viewportStyle.height = height + 'px';
var svgRoot = this._svgDom;
svgRoot.setAttribute('width', width + '');
svgRoot.setAttribute('height', height + '');
}
if (this._backgroundNode) {
this._backgroundNode.setAttribute('width', width);
this._backgroundNode.setAttribute('height', height);
}
};
SVGPainter.prototype.getWidth = function () {
return this._width;
};
SVGPainter.prototype.getHeight = function () {
return this._height;
};
SVGPainter.prototype.dispose = function () {
this.root.innerHTML = '';
this._svgRoot =
this._backgroundRoot =
this._svgDom =
this._backgroundNode =
this._viewport = this.storage = null;
};
SVGPainter.prototype.clear = function () {
var viewportNode = this._viewport;
if (viewportNode && viewportNode.parentNode) {
viewportNode.parentNode.removeChild(viewportNode);
}
};
SVGPainter.prototype.toDataURL = function () {
this.refresh();
var svgDom = this._svgDom;
var outerHTML = svgDom.outerHTML
|| (svgDom.parentNode && svgDom.parentNode.innerHTML);
var html = encodeURIComponent(outerHTML.replace(/></g, '>\n\r<'));
return 'data:image/svg+xml;charset=UTF-8,' + html;
};
return SVGPainter;
}());
function createMethodNotSupport(method) {
return function () {
if (process.env.NODE_ENV !== 'production') {
util.logError('In SVG mode painter not support method "' + method + '"');
}
};
}
export default SVGPainter;

View File

@ -0,0 +1,12 @@
import Path from '../graphic/Path';
import ZRImage from '../graphic/Image';
import TSpan from '../graphic/TSpan';
export interface SVGProxy<T> {
brush(el: T): void;
}
declare const svgPath: SVGProxy<Path>;
export { svgPath as path };
declare const svgImage: SVGProxy<ZRImage>;
export { svgImage as image };
declare const svgText: SVGProxy<TSpan>;
export { svgText as text };

126
frontend/node_modules/zrender/lib/svg-legacy/graphic.js generated vendored Normal file
View File

@ -0,0 +1,126 @@
import { createElement, XLINKNS } from '../svg/core.js';
import { getMatrixStr, TEXT_ALIGN_TO_ANCHOR, adjustTextY } from '../svg/helper.js';
import { getLineHeight } from '../contain/text.js';
import SVGPathRebuilder from '../svg/SVGPathRebuilder.js';
import mapStyleToAttrs from '../svg/mapStyleToAttrs.js';
import { DEFAULT_FONT } from '../core/platform.js';
function setTransform(svgEl, m) {
if (m) {
attr(svgEl, 'transform', getMatrixStr(m));
}
}
function attr(el, key, val) {
if (!val || val.type !== 'linear' && val.type !== 'radial') {
el.setAttribute(key, val);
}
}
function attrXLink(el, key, val) {
el.setAttributeNS(XLINKNS, key, val);
}
function attrXML(el, key, val) {
el.setAttributeNS('http://www.w3.org/XML/1998/namespace', key, val);
}
function bindStyle(svgEl, style, el) {
mapStyleToAttrs(function (key, val) { return attr(svgEl, key, val); }, style, el, true);
}
var svgPath = {
brush: function (el) {
var style = el.style;
var svgEl = el.__svgEl;
if (!svgEl) {
svgEl = createElement('path');
el.__svgEl = svgEl;
}
if (!el.path) {
el.createPathProxy();
}
var path = el.path;
if (el.shapeChanged()) {
path.beginPath();
el.buildPath(path, el.shape);
el.pathUpdated();
}
var pathVersion = path.getVersion();
var elExt = el;
var svgPathBuilder = elExt.__svgPathBuilder;
if (elExt.__svgPathVersion !== pathVersion || !svgPathBuilder || el.style.strokePercent < 1) {
if (!svgPathBuilder) {
svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
}
svgPathBuilder.reset();
path.rebuildPath(svgPathBuilder, el.style.strokePercent);
svgPathBuilder.generateStr();
elExt.__svgPathVersion = pathVersion;
}
attr(svgEl, 'd', svgPathBuilder.getStr());
bindStyle(svgEl, style, el);
setTransform(svgEl, el.transform);
}
};
export { svgPath as path };
var svgImage = {
brush: function (el) {
var style = el.style;
var image = style.image;
if (image instanceof HTMLImageElement) {
image = image.src;
}
else if (image instanceof HTMLCanvasElement) {
image = image.toDataURL();
}
if (!image) {
return;
}
var x = style.x || 0;
var y = style.y || 0;
var dw = style.width;
var dh = style.height;
var svgEl = el.__svgEl;
if (!svgEl) {
svgEl = createElement('image');
el.__svgEl = svgEl;
}
if (image !== el.__imageSrc) {
attrXLink(svgEl, 'href', image);
el.__imageSrc = image;
}
attr(svgEl, 'width', dw + '');
attr(svgEl, 'height', dh + '');
attr(svgEl, 'x', x + '');
attr(svgEl, 'y', y + '');
bindStyle(svgEl, style, el);
setTransform(svgEl, el.transform);
}
};
export { svgImage as image };
var svgText = {
brush: function (el) {
var style = el.style;
var text = style.text;
text != null && (text += '');
if (!text || isNaN(style.x) || isNaN(style.y)) {
return;
}
var textSvgEl = el.__svgEl;
if (!textSvgEl) {
textSvgEl = createElement('text');
attrXML(textSvgEl, 'xml:space', 'preserve');
el.__svgEl = textSvgEl;
}
var font = style.font || DEFAULT_FONT;
var textSvgElStyle = textSvgEl.style;
textSvgElStyle.font = font;
textSvgEl.textContent = text;
bindStyle(textSvgEl, style, el);
setTransform(textSvgEl, el.transform);
var x = style.x || 0;
var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign]
|| style.textAlign;
attr(textSvgEl, 'dominant-baseline', 'central');
attr(textSvgEl, 'text-anchor', textAlign);
attr(textSvgEl, 'x', x + '');
attr(textSvgEl, 'y', y + '');
}
};
export { svgText as text };

View File

@ -0,0 +1,15 @@
import Definable from './Definable';
import Displayable from '../../graphic/Displayable';
import Path from '../../graphic/Path';
export declare function hasClipPath(displayable: Displayable): boolean;
export default class ClippathManager extends Definable {
private _refGroups;
private _keyDuplicateCount;
constructor(zrId: number, svgRoot: SVGElement);
markAllUnused(): void;
private _getClipPathGroup;
update(displayable: Displayable, prevDisplayable: Displayable): SVGElement;
updateDom(parentEl: SVGElement, clipPaths: Path[]): void;
markUsed(displayable: Displayable): void;
removeUnused(): void;
}

View File

@ -0,0 +1,121 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import * as zrUtil from '../../core/util.js';
import { path } from '../graphic.js';
import { isClipPathChanged } from '../../canvas/helper.js';
import { getClipPathsKey, getIdURL } from '../../svg/helper.js';
import { createElement } from '../../svg/core.js';
export function hasClipPath(displayable) {
var clipPaths = displayable.__clipPaths;
return clipPaths && clipPaths.length > 0;
}
var ClippathManager = (function (_super) {
__extends(ClippathManager, _super);
function ClippathManager(zrId, svgRoot) {
var _this = _super.call(this, zrId, svgRoot, 'clipPath', '__clippath_in_use__') || this;
_this._refGroups = {};
_this._keyDuplicateCount = {};
return _this;
}
ClippathManager.prototype.markAllUnused = function () {
_super.prototype.markAllUnused.call(this);
var refGroups = this._refGroups;
for (var key in refGroups) {
if (refGroups.hasOwnProperty(key)) {
this.markDomUnused(refGroups[key]);
}
}
this._keyDuplicateCount = {};
};
ClippathManager.prototype._getClipPathGroup = function (displayable, prevDisplayable) {
if (!hasClipPath(displayable)) {
return;
}
var clipPaths = displayable.__clipPaths;
var keyDuplicateCount = this._keyDuplicateCount;
var clipPathKey = getClipPathsKey(clipPaths);
if (isClipPathChanged(clipPaths, prevDisplayable && prevDisplayable.__clipPaths)) {
keyDuplicateCount[clipPathKey] = keyDuplicateCount[clipPathKey] || 0;
keyDuplicateCount[clipPathKey] && (clipPathKey += '-' + keyDuplicateCount[clipPathKey]);
keyDuplicateCount[clipPathKey]++;
}
return this._refGroups[clipPathKey]
|| (this._refGroups[clipPathKey] = createElement('g'));
};
ClippathManager.prototype.update = function (displayable, prevDisplayable) {
var clipGroup = this._getClipPathGroup(displayable, prevDisplayable);
if (clipGroup) {
this.markDomUsed(clipGroup);
this.updateDom(clipGroup, displayable.__clipPaths);
}
return clipGroup;
};
;
ClippathManager.prototype.updateDom = function (parentEl, clipPaths) {
if (clipPaths && clipPaths.length > 0) {
var defs = this.getDefs(true);
var clipPath = clipPaths[0];
var clipPathEl = void 0;
var id = void 0;
if (clipPath._dom) {
id = clipPath._dom.getAttribute('id');
clipPathEl = clipPath._dom;
if (!defs.contains(clipPathEl)) {
defs.appendChild(clipPathEl);
}
}
else {
id = 'zr' + this._zrId + '-clip-' + this.nextId;
++this.nextId;
clipPathEl = createElement('clipPath');
clipPathEl.setAttribute('id', id);
defs.appendChild(clipPathEl);
clipPath._dom = clipPathEl;
}
path.brush(clipPath);
var pathEl = this.getSvgElement(clipPath);
clipPathEl.innerHTML = '';
clipPathEl.appendChild(pathEl);
parentEl.setAttribute('clip-path', getIdURL(id));
if (clipPaths.length > 1) {
this.updateDom(clipPathEl, clipPaths.slice(1));
}
}
else {
if (parentEl) {
parentEl.setAttribute('clip-path', 'none');
}
}
};
;
ClippathManager.prototype.markUsed = function (displayable) {
var _this = this;
if (displayable.__clipPaths) {
zrUtil.each(displayable.__clipPaths, function (clipPath) {
if (clipPath._dom) {
_super.prototype.markDomUsed.call(_this, clipPath._dom);
}
});
}
};
;
ClippathManager.prototype.removeUnused = function () {
_super.prototype.removeUnused.call(this);
var newRefGroupsMap = {};
var refGroups = this._refGroups;
for (var key in refGroups) {
if (refGroups.hasOwnProperty(key)) {
var group = refGroups[key];
if (!this.isDomUnused(group)) {
newRefGroupsMap[key] = group;
}
else if (group.parentNode) {
group.parentNode.removeChild(group);
}
}
}
this._refGroups = newRefGroupsMap;
};
return ClippathManager;
}(Definable));
export default ClippathManager;

View File

@ -0,0 +1,22 @@
import Displayable from '../../graphic/Displayable';
export default class Definable {
nextId: number;
protected _zrId: number;
protected _svgRoot: SVGElement;
protected _tagNames: string[];
protected _markLabel: string;
protected _domName: string;
constructor(zrId: number, svgRoot: SVGElement, tagNames: string | string[], markLabel: string, domName?: string);
getDefs(isForceCreating?: boolean): SVGDefsElement;
doUpdate<T>(target: T, onUpdate?: (target: T) => void): void;
add(target: any): SVGElement;
addDom(dom: SVGElement): void;
removeDom<T>(target: T): void;
getDoms(): SVGElement[];
markAllUnused(): void;
markDomUsed(dom: SVGElement): void;
markDomUnused(dom: SVGElement): void;
isDomUnused(dom: SVGElement): boolean;
removeUnused(): void;
getSvgElement(displayable: Displayable): SVGElement;
}

View File

@ -0,0 +1,130 @@
import { createElement } from '../../svg/core.js';
import * as zrUtil from '../../core/util.js';
var MARK_UNUSED = '0';
var MARK_USED = '1';
var Definable = (function () {
function Definable(zrId, svgRoot, tagNames, markLabel, domName) {
this.nextId = 0;
this._domName = '_dom';
this._zrId = zrId;
this._svgRoot = svgRoot;
this._tagNames = typeof tagNames === 'string' ? [tagNames] : tagNames;
this._markLabel = markLabel;
if (domName) {
this._domName = domName;
}
}
Definable.prototype.getDefs = function (isForceCreating) {
var svgRoot = this._svgRoot;
var defs = this._svgRoot.getElementsByTagName('defs');
if (defs.length === 0) {
if (isForceCreating) {
var defs_1 = svgRoot.insertBefore(createElement('defs'), svgRoot.firstChild);
if (!defs_1.contains) {
defs_1.contains = function (el) {
var children = defs_1.children;
if (!children) {
return false;
}
for (var i = children.length - 1; i >= 0; --i) {
if (children[i] === el) {
return true;
}
}
return false;
};
}
return defs_1;
}
else {
return null;
}
}
else {
return defs[0];
}
};
Definable.prototype.doUpdate = function (target, onUpdate) {
if (!target) {
return;
}
var defs = this.getDefs(false);
if (target[this._domName] && defs.contains(target[this._domName])) {
if (typeof onUpdate === 'function') {
onUpdate(target);
}
}
else {
var dom = this.add(target);
if (dom) {
target[this._domName] = dom;
}
}
};
Definable.prototype.add = function (target) {
return null;
};
Definable.prototype.addDom = function (dom) {
var defs = this.getDefs(true);
if (dom.parentNode !== defs) {
defs.appendChild(dom);
}
};
Definable.prototype.removeDom = function (target) {
var defs = this.getDefs(false);
if (defs && target[this._domName]) {
defs.removeChild(target[this._domName]);
target[this._domName] = null;
}
};
Definable.prototype.getDoms = function () {
var defs = this.getDefs(false);
if (!defs) {
return [];
}
var doms = [];
zrUtil.each(this._tagNames, function (tagName) {
var tags = defs.getElementsByTagName(tagName);
for (var i = 0; i < tags.length; i++) {
doms.push(tags[i]);
}
});
return doms;
};
Definable.prototype.markAllUnused = function () {
var doms = this.getDoms();
var that = this;
zrUtil.each(doms, function (dom) {
dom[that._markLabel] = MARK_UNUSED;
});
};
Definable.prototype.markDomUsed = function (dom) {
dom && (dom[this._markLabel] = MARK_USED);
};
;
Definable.prototype.markDomUnused = function (dom) {
dom && (dom[this._markLabel] = MARK_UNUSED);
};
;
Definable.prototype.isDomUnused = function (dom) {
return dom && dom[this._markLabel] !== MARK_USED;
};
Definable.prototype.removeUnused = function () {
var _this = this;
var defs = this.getDefs(false);
if (!defs) {
return;
}
var doms = this.getDoms();
zrUtil.each(doms, function (dom) {
if (_this.isDomUnused(dom)) {
defs.removeChild(dom);
}
});
};
Definable.prototype.getSvgElement = function (displayable) {
return displayable.__svgEl;
};
return Definable;
}());
export default Definable;

View File

@ -0,0 +1,11 @@
import Definable from './Definable';
import Displayable from '../../graphic/Displayable';
import { GradientObject } from '../../graphic/Gradient';
export default class GradientManager extends Definable {
constructor(zrId: number, svgRoot: SVGElement);
addWithoutUpdate(svgElement: SVGElement, displayable: Displayable): void;
add(gradient: GradientObject): SVGElement;
update(gradient: GradientObject | string): void;
updateDom(gradient: GradientObject, dom: SVGElement): void;
markUsed(displayable: Displayable): void;
}

View File

@ -0,0 +1,128 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import * as zrUtil from '../../core/util.js';
import { getIdURL, isGradient, isLinearGradient, isRadialGradient, normalizeColor, round4 } from '../../svg/helper.js';
import { createElement } from '../../svg/core.js';
var GradientManager = (function (_super) {
__extends(GradientManager, _super);
function GradientManager(zrId, svgRoot) {
return _super.call(this, zrId, svgRoot, ['linearGradient', 'radialGradient'], '__gradient_in_use__') || this;
}
GradientManager.prototype.addWithoutUpdate = function (svgElement, displayable) {
if (displayable && displayable.style) {
var that_1 = this;
zrUtil.each(['fill', 'stroke'], function (fillOrStroke) {
var value = displayable.style[fillOrStroke];
if (isGradient(value)) {
var gradient = value;
var defs = that_1.getDefs(true);
var dom = void 0;
if (gradient.__dom) {
dom = gradient.__dom;
if (!defs.contains(gradient.__dom)) {
that_1.addDom(dom);
}
}
else {
dom = that_1.add(gradient);
}
that_1.markUsed(displayable);
svgElement.setAttribute(fillOrStroke, getIdURL(dom.getAttribute('id')));
}
});
}
};
GradientManager.prototype.add = function (gradient) {
var dom;
if (isLinearGradient(gradient)) {
dom = createElement('linearGradient');
}
else if (isRadialGradient(gradient)) {
dom = createElement('radialGradient');
}
else {
if (process.env.NODE_ENV !== 'production') {
zrUtil.logError('Illegal gradient type.');
}
return null;
}
gradient.id = gradient.id || this.nextId++;
dom.setAttribute('id', 'zr' + this._zrId
+ '-gradient-' + gradient.id);
this.updateDom(gradient, dom);
this.addDom(dom);
return dom;
};
GradientManager.prototype.update = function (gradient) {
if (!isGradient(gradient)) {
return;
}
var that = this;
this.doUpdate(gradient, function () {
var dom = gradient.__dom;
if (!dom) {
return;
}
var tagName = dom.tagName;
var type = gradient.type;
if (type === 'linear' && tagName === 'linearGradient'
|| type === 'radial' && tagName === 'radialGradient') {
that.updateDom(gradient, gradient.__dom);
}
else {
that.removeDom(gradient);
that.add(gradient);
}
});
};
GradientManager.prototype.updateDom = function (gradient, dom) {
if (isLinearGradient(gradient)) {
dom.setAttribute('x1', gradient.x);
dom.setAttribute('y1', gradient.y);
dom.setAttribute('x2', gradient.x2);
dom.setAttribute('y2', gradient.y2);
}
else if (isRadialGradient(gradient)) {
dom.setAttribute('cx', gradient.x);
dom.setAttribute('cy', gradient.y);
dom.setAttribute('r', gradient.r);
}
else {
if (process.env.NODE_ENV !== 'production') {
zrUtil.logError('Illegal gradient type.');
}
return;
}
dom.setAttribute('gradientUnits', gradient.global
? 'userSpaceOnUse'
: 'objectBoundingBox');
dom.innerHTML = '';
var colors = gradient.colorStops;
for (var i = 0, len = colors.length; i < len; ++i) {
var stop_1 = createElement('stop');
stop_1.setAttribute('offset', round4(colors[i].offset) * 100 + '%');
var stopColor = colors[i].color;
var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
stop_1.setAttribute('stop-color', color);
if (opacity < 1) {
stop_1.setAttribute('stop-opacity', opacity);
}
dom.appendChild(stop_1);
}
gradient.__dom = dom;
};
GradientManager.prototype.markUsed = function (displayable) {
if (displayable.style) {
var gradient = displayable.style.fill;
if (gradient && gradient.__dom) {
_super.prototype.markDomUsed.call(this, gradient.__dom);
}
gradient = displayable.style.stroke;
if (gradient && gradient.__dom) {
_super.prototype.markDomUsed.call(this, gradient.__dom);
}
}
};
return GradientManager;
}(Definable));
export default GradientManager;

View File

@ -0,0 +1,11 @@
import Definable from './Definable';
import Displayable from '../../graphic/Displayable';
import { PatternObject } from '../../graphic/Pattern';
export default class PatternManager extends Definable {
constructor(zrId: number, svgRoot: SVGElement);
addWithoutUpdate(svgElement: SVGElement, displayable: Displayable): void;
add(pattern: PatternObject): SVGElement;
update(pattern: PatternObject | string): void;
updateDom(pattern: PatternObject, patternDom: SVGElement): void;
markUsed(displayable: Displayable): void;
}

View File

@ -0,0 +1,127 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import * as zrUtil from '../../core/util.js';
import { createOrUpdateImage } from '../../graphic/helper/image.js';
import WeakMap from '../../core/WeakMap.js';
import { getIdURL, isPattern, isSVGPattern } from '../../svg/helper.js';
import { createElement } from '../../svg/core.js';
var patternDomMap = new WeakMap();
var PatternManager = (function (_super) {
__extends(PatternManager, _super);
function PatternManager(zrId, svgRoot) {
return _super.call(this, zrId, svgRoot, ['pattern'], '__pattern_in_use__') || this;
}
PatternManager.prototype.addWithoutUpdate = function (svgElement, displayable) {
if (displayable && displayable.style) {
var that_1 = this;
zrUtil.each(['fill', 'stroke'], function (fillOrStroke) {
var pattern = displayable.style[fillOrStroke];
if (isPattern(pattern)) {
var defs = that_1.getDefs(true);
var dom = patternDomMap.get(pattern);
if (dom) {
if (!defs.contains(dom)) {
that_1.addDom(dom);
}
}
else {
dom = that_1.add(pattern);
}
that_1.markUsed(displayable);
svgElement.setAttribute(fillOrStroke, getIdURL(dom.getAttribute('id')));
}
});
}
};
PatternManager.prototype.add = function (pattern) {
if (!isPattern(pattern)) {
return;
}
var dom = createElement('pattern');
pattern.id = pattern.id == null ? this.nextId++ : pattern.id;
dom.setAttribute('id', 'zr' + this._zrId
+ '-pattern-' + pattern.id);
dom.setAttribute('patternUnits', 'userSpaceOnUse');
this.updateDom(pattern, dom);
this.addDom(dom);
return dom;
};
PatternManager.prototype.update = function (pattern) {
if (!isPattern(pattern)) {
return;
}
var that = this;
this.doUpdate(pattern, function () {
var dom = patternDomMap.get(pattern);
that.updateDom(pattern, dom);
});
};
PatternManager.prototype.updateDom = function (pattern, patternDom) {
if (isSVGPattern(pattern)) {
}
else {
var img = void 0;
var prevImage = patternDom.getElementsByTagName('image');
if (prevImage.length) {
if (pattern.image) {
img = prevImage[0];
}
else {
patternDom.removeChild(prevImage[0]);
return;
}
}
else if (pattern.image) {
img = createElement('image');
}
if (img) {
var imageSrc = void 0;
var patternImage = pattern.image;
if (typeof patternImage === 'string') {
imageSrc = patternImage;
}
else if (patternImage instanceof HTMLImageElement) {
imageSrc = patternImage.src;
}
else if (patternImage instanceof HTMLCanvasElement) {
imageSrc = patternImage.toDataURL();
}
if (imageSrc) {
img.setAttribute('href', imageSrc);
var hostEl = {
dirty: function () { }
};
var updateSize = function (img) {
patternDom.setAttribute('width', img.width);
patternDom.setAttribute('height', img.height);
};
var createdImage = createOrUpdateImage(imageSrc, img, hostEl, updateSize);
if (createdImage && createdImage.width && createdImage.height) {
updateSize(createdImage);
}
patternDom.appendChild(img);
}
}
}
var x = pattern.x || 0;
var y = pattern.y || 0;
var rotation = (pattern.rotation || 0) / Math.PI * 180;
var scaleX = pattern.scaleX || 1;
var scaleY = pattern.scaleY || 1;
var transform = "translate(" + x + ", " + y + ") rotate(" + rotation + ") scale(" + scaleX + ", " + scaleY + ")";
patternDom.setAttribute('patternTransform', transform);
patternDomMap.set(pattern, patternDom);
};
PatternManager.prototype.markUsed = function (displayable) {
if (displayable.style) {
if (isPattern(displayable.style.fill)) {
_super.prototype.markDomUsed.call(this, patternDomMap.get(displayable.style.fill));
}
if (isPattern(displayable.style.stroke)) {
_super.prototype.markDomUsed.call(this, patternDomMap.get(displayable.style.stroke));
}
}
};
return PatternManager;
}(Definable));
export default PatternManager;

View File

@ -0,0 +1,12 @@
import Definable from './Definable';
import Displayable from '../../graphic/Displayable';
export default class ShadowManager extends Definable {
private _shadowDomMap;
private _shadowDomPool;
constructor(zrId: number, svgRoot: SVGElement);
private _getFromPool;
update(svgElement: SVGElement, displayable: Displayable): void;
remove(svgElement: SVGElement, displayable: Displayable): void;
updateDom(svgElement: SVGElement, displayable: Displayable, shadowDom: SVGElement): void;
removeUnused(): void;
}

View File

@ -0,0 +1,89 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import { getIdURL, getShadowKey, hasShadow, normalizeColor } from '../../svg/helper.js';
import { createElement } from '../../svg/core.js';
var ShadowManager = (function (_super) {
__extends(ShadowManager, _super);
function ShadowManager(zrId, svgRoot) {
var _this = _super.call(this, zrId, svgRoot, ['filter'], '__filter_in_use__', '_shadowDom') || this;
_this._shadowDomMap = {};
_this._shadowDomPool = [];
return _this;
}
ShadowManager.prototype._getFromPool = function () {
var shadowDom = this._shadowDomPool.pop();
if (!shadowDom) {
shadowDom = createElement('filter');
shadowDom.setAttribute('id', 'zr' + this._zrId + '-shadow-' + this.nextId++);
var domChild = createElement('feDropShadow');
shadowDom.appendChild(domChild);
this.addDom(shadowDom);
}
return shadowDom;
};
ShadowManager.prototype.update = function (svgElement, displayable) {
var style = displayable.style;
if (hasShadow(style)) {
var shadowKey = getShadowKey(displayable);
var shadowDom = displayable._shadowDom = this._shadowDomMap[shadowKey];
if (!shadowDom) {
shadowDom = this._getFromPool();
this._shadowDomMap[shadowKey] = shadowDom;
}
this.updateDom(svgElement, displayable, shadowDom);
}
else {
this.remove(svgElement, displayable);
}
};
ShadowManager.prototype.remove = function (svgElement, displayable) {
if (displayable._shadowDom != null) {
displayable._shadowDom = null;
svgElement.removeAttribute('filter');
}
};
ShadowManager.prototype.updateDom = function (svgElement, displayable, shadowDom) {
var domChild = shadowDom.children[0];
var style = displayable.style;
var globalScale = displayable.getGlobalScale();
var scaleX = globalScale[0];
var scaleY = globalScale[1];
if (!scaleX || !scaleY) {
return;
}
var offsetX = style.shadowOffsetX || 0;
var offsetY = style.shadowOffsetY || 0;
var blur = style.shadowBlur;
var normalizedColor = normalizeColor(style.shadowColor);
domChild.setAttribute('dx', offsetX / scaleX + '');
domChild.setAttribute('dy', offsetY / scaleY + '');
domChild.setAttribute('flood-color', normalizedColor.color);
domChild.setAttribute('flood-opacity', normalizedColor.opacity + '');
var stdDx = blur / 2 / scaleX;
var stdDy = blur / 2 / scaleY;
var stdDeviation = stdDx + ' ' + stdDy;
domChild.setAttribute('stdDeviation', stdDeviation);
shadowDom.setAttribute('x', '-100%');
shadowDom.setAttribute('y', '-100%');
shadowDom.setAttribute('width', '300%');
shadowDom.setAttribute('height', '300%');
displayable._shadowDom = shadowDom;
svgElement.setAttribute('filter', getIdURL(shadowDom.getAttribute('id')));
};
ShadowManager.prototype.removeUnused = function () {
var defs = this.getDefs(false);
if (!defs) {
return;
}
var shadowDomsPool = this._shadowDomPool;
var shadowDomMap = this._shadowDomMap;
for (var key in shadowDomMap) {
if (shadowDomMap.hasOwnProperty(key)) {
shadowDomsPool.push(shadowDomMap[key]);
}
}
this._shadowDomMap = {};
};
return ShadowManager;
}(Definable));
export default ShadowManager;

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,3 @@
import { registerPainter } from '../zrender.js';
import Painter from './Painter.js';
registerPainter('svg-legacy', Painter);