push the uni-demo project

This commit is contained in:
2022-06-21 10:55:37 +08:00
parent 37ca848bb6
commit 333705f703
8034 changed files with 1388875 additions and 0 deletions

56
uni-demo/node_modules/zrender/lib/svg/Painter.d.ts generated vendored Normal file
View File

@@ -0,0 +1,56 @@
import Displayable from '../graphic/Displayable';
import Storage from '../Storage';
import { PainterBase } from '../PainterBase';
import { SVGVNode, BrushScope } from './core';
interface SVGPainterOption {
width?: number;
height?: number;
ssr?: boolean;
}
declare class SVGPainter implements PainterBase {
type: string;
storage: Storage;
root: HTMLElement;
private _svgDom;
private _viewport;
private _opts;
private _oldVNode;
private _bgVNode;
private _mainVNode;
private _width;
private _height;
private _backgroundColor;
private _id;
constructor(root: HTMLElement, storage: Storage, opts: SVGPainterOption);
getType(): string;
getViewportRoot(): HTMLElement;
getViewportRootOffset(): {
offsetLeft: number;
offsetTop: number;
};
getSvgDom(): SVGElement;
refresh(): void;
renderOneToVNode(el: Displayable): SVGVNode;
renderToVNode(opts?: {
animation?: boolean;
willUpdate?: boolean;
compress?: boolean;
useViewBox?: boolean;
}): SVGVNode;
renderToString(opts?: {
cssAnimation?: boolean;
useViewBox?: boolean;
}): string;
setBackgroundColor(backgroundColor: string): void;
getSvgRoot(): SVGElement;
_paintList(list: Displayable[], scope: BrushScope, out?: SVGVNode[]): void;
resize(width: number, height: number): void;
getWidth(): number;
getHeight(): number;
dispose(): void;
clear(): void;
toDataURL(base64?: boolean): string;
refreshHover: () => void;
configLayer: (zlevel: number, config: import("../core/types").Dictionary<any>) => void;
}
export default SVGPainter;

234
uni-demo/node_modules/zrender/lib/svg/Painter.js generated vendored Normal file
View File

@@ -0,0 +1,234 @@
import { brush, setClipPath } from './graphic.js';
import { createElement, createVNode, vNodeToString, getCssString, createBrushScope, createSVGVNode } from './core.js';
import { normalizeColor, encodeBase64 } from './helper.js';
import { extend, keys, logError, map, retrieve2 } from '../core/util.js';
import patch, { updateAttrs } from './patch.js';
import { getSize } from '../canvas/helper.js';
var svgId = 0;
var SVGPainter = (function () {
function SVGPainter(root, storage, opts) {
this.type = 'svg';
this.refreshHover = createMethodNotSupport('refreshHover');
this.configLayer = createMethodNotSupport('configLayer');
this.storage = storage;
this._opts = opts = extend({}, opts);
this.root = root;
this._id = 'zr' + svgId++;
this._oldVNode = createSVGVNode(opts.width, opts.height);
if (root && !opts.ssr) {
var viewport = this._viewport = document.createElement('div');
viewport.style.cssText = 'position:relative;overflow:hidden';
var svgDom = this._svgDom = this._oldVNode.elm = createElement('svg');
updateAttrs(null, this._oldVNode);
viewport.appendChild(svgDom);
root.appendChild(viewport);
}
this.resize(opts.width, opts.height);
}
SVGPainter.prototype.getType = function () {
return this.type;
};
SVGPainter.prototype.getViewportRoot = function () {
return this._viewport;
};
SVGPainter.prototype.getViewportRootOffset = function () {
var viewportRoot = this.getViewportRoot();
if (viewportRoot) {
return {
offsetLeft: viewportRoot.offsetLeft || 0,
offsetTop: viewportRoot.offsetTop || 0
};
}
};
SVGPainter.prototype.getSvgDom = function () {
return this._svgDom;
};
SVGPainter.prototype.refresh = function () {
if (this.root) {
var vnode = this.renderToVNode({
willUpdate: true
});
vnode.attrs.style = 'position:absolute;left:0;top:0;user-select:none';
patch(this._oldVNode, vnode);
this._oldVNode = vnode;
}
};
SVGPainter.prototype.renderOneToVNode = function (el) {
return brush(el, createBrushScope(this._id));
};
SVGPainter.prototype.renderToVNode = function (opts) {
opts = opts || {};
var list = this.storage.getDisplayList(true);
var bgColor = this._backgroundColor;
var width = this._width;
var height = this._height;
var scope = createBrushScope(this._id);
scope.animation = opts.animation;
scope.willUpdate = opts.willUpdate;
scope.compress = opts.compress;
var children = [];
if (bgColor && bgColor !== 'none') {
var _a = normalizeColor(bgColor), color = _a.color, opacity = _a.opacity;
this._bgVNode = createVNode('rect', 'bg', {
width: width,
height: height,
x: '0',
y: '0',
id: '0',
fill: color,
'fill-opacity': opacity
});
children.push(this._bgVNode);
}
else {
this._bgVNode = null;
}
var mainVNode = !opts.compress
? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
this._paintList(list, scope, mainVNode ? mainVNode.children : children);
mainVNode && children.push(mainVNode);
var defs = map(keys(scope.defs), function (id) { return scope.defs[id]; });
if (defs.length) {
children.push(createVNode('defs', 'defs', {}, defs));
}
if (opts.animation) {
var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
if (animationCssStr) {
var styleNode = createVNode('style', 'stl', {}, [], animationCssStr);
children.push(styleNode);
}
}
return createSVGVNode(width, height, children, opts.useViewBox);
};
SVGPainter.prototype.renderToString = function (opts) {
opts = opts || {};
return vNodeToString(this.renderToVNode({
animation: retrieve2(opts.cssAnimation, true),
willUpdate: false,
compress: true,
useViewBox: retrieve2(opts.useViewBox, true)
}), { newline: true });
};
SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
this._backgroundColor = backgroundColor;
var bgVNode = this._bgVNode;
if (bgVNode && bgVNode.elm) {
var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
bgVNode.elm.setAttribute('fill', color);
if (opacity < 1) {
bgVNode.elm.setAttribute('fill-opacity', opacity);
}
}
};
SVGPainter.prototype.getSvgRoot = function () {
return this._mainVNode && this._mainVNode.elm;
};
SVGPainter.prototype._paintList = function (list, scope, out) {
var listLen = list.length;
var clipPathsGroupsStack = [];
var clipPathsGroupsStackDepth = 0;
var currentClipPathGroup;
var prevClipPaths;
var clipGroupNodeIdx = 0;
for (var i = 0; i < listLen; i++) {
var displayable = list[i];
if (!displayable.invisible) {
var clipPaths = displayable.__clipPaths;
var len = clipPaths && clipPaths.length || 0;
var prevLen = prevClipPaths && prevClipPaths.length || 0;
var lca = void 0;
for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
if (clipPaths && prevClipPaths
&& clipPaths[lca] === prevClipPaths[lca]) {
break;
}
}
for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
clipPathsGroupsStackDepth--;
currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
}
for (var i_2 = lca + 1; i_2 < len; i_2++) {
var groupAttrs = {};
setClipPath(clipPaths[i_2], groupAttrs, scope);
var g = createVNode('g', 'clip-g-' + clipGroupNodeIdx++, groupAttrs, []);
(currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
currentClipPathGroup = g;
}
prevClipPaths = clipPaths;
var ret = brush(displayable, scope);
if (ret) {
(currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
}
}
}
};
SVGPainter.prototype.resize = function (width, height) {
var opts = this._opts;
var root = this.root;
var viewport = this._viewport;
width != null && (opts.width = width);
height != null && (opts.height = height);
if (root && viewport) {
viewport.style.display = 'none';
width = getSize(root, 0, opts);
height = getSize(root, 1, opts);
viewport.style.display = '';
}
if (this._width !== width || this._height !== height) {
this._width = width;
this._height = height;
if (viewport) {
var viewportStyle = viewport.style;
viewportStyle.width = width + 'px';
viewportStyle.height = height + 'px';
}
var svgDom = this._svgDom;
if (svgDom) {
svgDom.setAttribute('width', width);
svgDom.setAttribute('height', height);
}
}
};
SVGPainter.prototype.getWidth = function () {
return this._width;
};
SVGPainter.prototype.getHeight = function () {
return this._height;
};
SVGPainter.prototype.dispose = function () {
if (this.root) {
this.root.innerHTML = '';
}
this._svgDom =
this._viewport =
this.storage =
this._oldVNode =
this._bgVNode =
this._mainVNode = null;
};
SVGPainter.prototype.clear = function () {
if (this._svgDom) {
this._svgDom.innerHTML = null;
}
this._oldVNode = null;
};
SVGPainter.prototype.toDataURL = function (base64) {
var str = encodeURIComponent(this.renderToString());
var prefix = 'data:image/svg+xml;';
if (base64) {
str = encodeBase64(str);
return str && prefix + 'base64,' + str;
}
return prefix + 'charset=UTF-8,' + str;
};
return SVGPainter;
}());
function createMethodNotSupport(method) {
return function () {
if (process.env.NODE_ENV !== 'production') {
logError('In SVG mode painter not support method "' + method + '"');
}
};
}
export default SVGPainter;

View File

@@ -0,0 +1,20 @@
import { PathRebuilder } from '../core/PathProxy';
export default class SVGPathRebuilder implements PathRebuilder {
private _d;
private _str;
private _invalid;
private _start;
private _p;
reset(precision?: number): void;
moveTo(x: number, y: number): void;
lineTo(x: number, y: number): void;
bezierCurveTo(x: number, y: number, x2: number, y2: number, x3: number, y3: number): void;
quadraticCurveTo(x: number, y: number, x2: number, y2: number): void;
arc(cx: number, cy: number, r: number, startAngle: number, endAngle: number, anticlockwise: boolean): void;
ellipse(cx: number, cy: number, rx: number, ry: number, psi: number, startAngle: number, endAngle: number, anticlockwise: boolean): void;
rect(x: number, y: number, w: number, h: number): void;
closePath(): void;
_add(cmd: string, a?: number, b?: number, c?: number, d?: number, e?: number, f?: number, g?: number, h?: number): void;
generateStr(): void;
getStr(): string;
}

View File

@@ -0,0 +1,103 @@
import { isAroundZero } from './helper.js';
var mathSin = Math.sin;
var mathCos = Math.cos;
var PI = Math.PI;
var PI2 = Math.PI * 2;
var degree = 180 / PI;
var SVGPathRebuilder = (function () {
function SVGPathRebuilder() {
}
SVGPathRebuilder.prototype.reset = function (precision) {
this._start = true;
this._d = [];
this._str = '';
this._p = Math.pow(10, precision || 4);
};
SVGPathRebuilder.prototype.moveTo = function (x, y) {
this._add('M', x, y);
};
SVGPathRebuilder.prototype.lineTo = function (x, y) {
this._add('L', x, y);
};
SVGPathRebuilder.prototype.bezierCurveTo = function (x, y, x2, y2, x3, y3) {
this._add('C', x, y, x2, y2, x3, y3);
};
SVGPathRebuilder.prototype.quadraticCurveTo = function (x, y, x2, y2) {
this._add('Q', x, y, x2, y2);
};
SVGPathRebuilder.prototype.arc = function (cx, cy, r, startAngle, endAngle, anticlockwise) {
this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
};
SVGPathRebuilder.prototype.ellipse = function (cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
var dTheta = endAngle - startAngle;
var clockwise = !anticlockwise;
var dThetaPositive = Math.abs(dTheta);
var isCircle = isAroundZero(dThetaPositive - PI2)
|| (clockwise ? dTheta >= PI2 : -dTheta >= PI2);
var unifiedTheta = dTheta > 0 ? dTheta % PI2 : (dTheta % PI2 + PI2);
var large = false;
if (isCircle) {
large = true;
}
else if (isAroundZero(dThetaPositive)) {
large = false;
}
else {
large = (unifiedTheta >= PI) === !!clockwise;
}
var x0 = cx + rx * mathCos(startAngle);
var y0 = cy + ry * mathSin(startAngle);
if (this._start) {
this._add('M', x0, y0);
}
var xRot = Math.round(psi * degree);
if (isCircle) {
var p = 1 / this._p;
var dTheta_1 = (clockwise ? 1 : -1) * (PI2 - p);
this._add('A', rx, ry, xRot, 1, +clockwise, cx + rx * mathCos(startAngle + dTheta_1), cy + ry * mathSin(startAngle + dTheta_1));
if (p > 1e-2) {
this._add('A', rx, ry, xRot, 0, +clockwise, x0, y0);
}
}
else {
var x = cx + rx * mathCos(endAngle);
var y = cy + ry * mathSin(endAngle);
this._add('A', rx, ry, xRot, +large, +clockwise, x, y);
}
};
SVGPathRebuilder.prototype.rect = function (x, y, w, h) {
this._add('M', x, y);
this._add('l', w, 0);
this._add('l', 0, h);
this._add('l', -w, 0);
this._add('Z');
};
SVGPathRebuilder.prototype.closePath = function () {
if (this._d.length > 0) {
this._add('Z');
}
};
SVGPathRebuilder.prototype._add = function (cmd, a, b, c, d, e, f, g, h) {
var vals = [];
var p = this._p;
for (var i = 1; i < arguments.length; i++) {
var val = arguments[i];
if (isNaN(val)) {
this._invalid = true;
return;
}
vals.push(Math.round(val * p) / p);
}
this._d.push(cmd + vals.join(' '));
this._start = cmd === 'Z';
};
SVGPathRebuilder.prototype.generateStr = function () {
this._str = this._invalid ? '' : this._d.join('');
this._d = [];
};
SVGPathRebuilder.prototype.getStr = function () {
return this._str;
};
return SVGPathRebuilder;
}());
export default SVGPathRebuilder;

44
uni-demo/node_modules/zrender/lib/svg/core.d.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
export declare type CSSSelectorVNode = Record<string, string>;
export declare type CSSAnimationVNode = Record<string, Record<string, string>>;
export declare const SVGNS = "http://www.w3.org/2000/svg";
export declare const XLINKNS = "http://www.w3.org/1999/xlink";
export declare const XMLNS = "http://www.w3.org/2000/xmlns/";
export declare const XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
export declare function createElement(name: string): SVGElement;
export declare type SVGVNodeAttrs = Record<string, string | number | undefined | boolean>;
export interface SVGVNode {
tag: string;
attrs: SVGVNodeAttrs;
children?: SVGVNode[];
text?: string;
elm?: Node;
key: string;
}
export declare function createVNode(tag: string, key: string, attrs?: SVGVNodeAttrs, children?: SVGVNode[], text?: string): SVGVNode;
export declare function vNodeToString(el: SVGVNode, opts?: {
newline?: boolean;
}): string;
export declare function getCssString(selectorNodes: Record<string, CSSSelectorVNode>, animationNodes: Record<string, CSSAnimationVNode>, opts?: {
newline?: boolean;
}): string;
export interface BrushScope {
zrId: string;
shadowCache: Record<string, string>;
gradientCache: Record<string, string>;
patternCache: Record<string, string>;
clipPathCache: Record<string, string>;
defs: Record<string, SVGVNode>;
cssNodes: Record<string, CSSSelectorVNode>;
cssAnims: Record<string, Record<string, Record<string, string>>>;
cssClassIdx: number;
cssAnimIdx: number;
shadowIdx: number;
gradientIdx: number;
patternIdx: number;
clipPathIdx: number;
animation?: boolean;
willUpdate?: boolean;
compress?: boolean;
}
export declare function createBrushScope(zrId: string): BrushScope;
export declare function createSVGVNode(width: number | string, height: number | string, children?: SVGVNode[], useViewBox?: boolean): SVGVNode;

105
uni-demo/node_modules/zrender/lib/svg/core.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import { keys, map } from '../core/util.js';
export var SVGNS = 'http://www.w3.org/2000/svg';
export var XLINKNS = 'http://www.w3.org/1999/xlink';
export var XMLNS = 'http://www.w3.org/2000/xmlns/';
export var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
export function createElement(name) {
return document.createElementNS(SVGNS, name);
}
;
export function createVNode(tag, key, attrs, children, text) {
return {
tag: tag,
attrs: attrs || {},
children: children,
text: text,
key: key
};
}
function createElementOpen(name, attrs) {
var attrsStr = [];
if (attrs) {
for (var key in attrs) {
var val = attrs[key];
var part = key;
if (val === false) {
continue;
}
else if (val !== true && val != null) {
part += "=\"" + val + "\"";
}
attrsStr.push(part);
}
}
return "<" + name + " " + attrsStr.join(' ') + ">";
}
function createElementClose(name) {
return "</" + name + ">";
}
export function vNodeToString(el, opts) {
opts = opts || {};
var S = opts.newline ? '\n' : '';
function convertElToString(el) {
var children = el.children, tag = el.tag, attrs = el.attrs;
return createElementOpen(tag, attrs)
+ (el.text || '')
+ (children ? "" + S + map(children, function (child) { return convertElToString(child); }).join(S) + S : '')
+ createElementClose(tag);
}
return convertElToString(el);
}
export function getCssString(selectorNodes, animationNodes, opts) {
opts = opts || {};
var S = opts.newline ? '\n' : '';
var bracketBegin = " {" + S;
var bracketEnd = S + "}";
var selectors = map(keys(selectorNodes), function (className) {
return className + bracketBegin + map(keys(selectorNodes[className]), function (attrName) {
return attrName + ":" + selectorNodes[className][attrName] + ";";
}).join(S) + bracketEnd;
}).join(S);
var animations = map(keys(animationNodes), function (animationName) {
return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function (percent) {
return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function (attrName) {
var val = animationNodes[animationName][percent][attrName];
if (attrName === 'd') {
val = "path(\"" + val + "\")";
}
return attrName + ":" + val + ";";
}).join(S) + bracketEnd;
}).join(S) + bracketEnd;
}).join(S);
if (!selectors && !animations) {
return '';
}
return ['<![CDATA[', selectors, animations, ']]>'].join(S);
}
export function createBrushScope(zrId) {
return {
zrId: zrId,
shadowCache: {},
patternCache: {},
gradientCache: {},
clipPathCache: {},
defs: {},
cssNodes: {},
cssAnims: {},
cssClassIdx: 0,
cssAnimIdx: 0,
shadowIdx: 0,
gradientIdx: 0,
patternIdx: 0,
clipPathIdx: 0
};
}
export function createSVGVNode(width, height, children, useViewBox) {
return createVNode('svg', 'root', {
'width': width,
'height': height,
'xmlns': SVGNS,
'xmlns:xlink': XLINKNS,
'version': '1.1',
'baseProfile': 'full',
'viewBox': useViewBox ? "0 0 " + width + " " + height : false
}, children);
}

View File

@@ -0,0 +1,5 @@
import Displayable from '../graphic/Displayable';
import { SVGVNodeAttrs, BrushScope } from './core';
export declare const EASING_MAP: Record<string, string>;
export declare const ANIMATE_STYLE_MAP: Record<string, string>;
export declare function createCSSAnimation(el: Displayable, attrs: SVGVNodeAttrs, scope: BrushScope, onlyShape?: boolean): void;

275
uni-demo/node_modules/zrender/lib/svg/cssAnimation.js generated vendored Normal file
View File

@@ -0,0 +1,275 @@
import { copyTransform } from '../core/Transformable.js';
import { createBrushScope } from './core.js';
import SVGPathRebuilder from './SVGPathRebuilder.js';
import PathProxy from '../core/PathProxy.js';
import { getPathPrecision, getSRTTransformString } from './helper.js';
import { each, extend, filter, isNumber, isString, keys } from '../core/util.js';
import CompoundPath from '../graphic/CompoundPath.js';
import { createCubicEasingFunc } from '../animation/cubicEasing.js';
export var EASING_MAP = {
cubicIn: '0.32,0,0.67,0',
cubicOut: '0.33,1,0.68,1',
cubicInOut: '0.65,0,0.35,1',
quadraticIn: '0.11,0,0.5,0',
quadraticOut: '0.5,1,0.89,1',
quadraticInOut: '0.45,0,0.55,1',
quarticIn: '0.5,0,0.75,0',
quarticOut: '0.25,1,0.5,1',
quarticInOut: '0.76,0,0.24,1',
quinticIn: '0.64,0,0.78,0',
quinticOut: '0.22,1,0.36,1',
quinticInOut: '0.83,0,0.17,1',
sinusoidalIn: '0.12,0,0.39,0',
sinusoidalOut: '0.61,1,0.88,1',
sinusoidalInOut: '0.37,0,0.63,1',
exponentialIn: '0.7,0,0.84,0',
exponentialOut: '0.16,1,0.3,1',
exponentialInOut: '0.87,0,0.13,1',
circularIn: '0.55,0,1,0.45',
circularOut: '0,0.55,0.45,1',
circularInOut: '0.85,0,0.15,1'
};
var transformOriginKey = 'transform-origin';
function buildPathString(el, kfShape, path) {
var shape = extend({}, el.shape);
extend(shape, kfShape);
el.buildPath(path, shape);
var svgPathBuilder = new SVGPathRebuilder();
svgPathBuilder.reset(getPathPrecision(el));
path.rebuildPath(svgPathBuilder, 1);
svgPathBuilder.generateStr();
return svgPathBuilder.getStr();
}
function setTransformOrigin(target, transform) {
var originX = transform.originX, originY = transform.originY;
if (originX || originY) {
target[transformOriginKey] = originX + "px " + originY + "px";
}
}
export var ANIMATE_STYLE_MAP = {
fill: 'fill',
opacity: 'opacity',
lineWidth: 'stroke-width',
lineDashOffset: 'stroke-dashoffset'
};
function addAnimation(cssAnim, scope) {
var animationName = scope.zrId + '-ani-' + scope.cssAnimIdx++;
scope.cssAnims[animationName] = cssAnim;
return animationName;
}
function createCompoundPathCSSAnimation(el, attrs, scope) {
var paths = el.shape.paths;
var composedAnim = {};
var cssAnimationCfg;
var cssAnimationName;
each(paths, function (path) {
var subScope = createBrushScope(scope.zrId);
subScope.animation = true;
createCSSAnimation(path, {}, subScope, true);
var cssAnims = subScope.cssAnims;
var cssNodes = subScope.cssNodes;
var animNames = keys(cssAnims);
var len = animNames.length;
if (!len) {
return;
}
cssAnimationName = animNames[len - 1];
var lastAnim = cssAnims[cssAnimationName];
for (var percent in lastAnim) {
var kf = lastAnim[percent];
composedAnim[percent] = composedAnim[percent] || { d: '' };
composedAnim[percent].d += kf.d || '';
}
for (var className in cssNodes) {
var val = cssNodes[className].animation;
if (val.indexOf(cssAnimationName) >= 0) {
cssAnimationCfg = val;
}
}
});
if (!cssAnimationCfg) {
return;
}
attrs.d = false;
var animationName = addAnimation(composedAnim, scope);
return cssAnimationCfg.replace(cssAnimationName, animationName);
}
function getEasingFunc(easing) {
return isString(easing)
? EASING_MAP[easing]
? "cubic-bezier(" + EASING_MAP[easing] + ")"
: createCubicEasingFunc(easing) ? easing : ''
: '';
}
export function createCSSAnimation(el, attrs, scope, onlyShape) {
var animators = el.animators;
var len = animators.length;
var cssAnimations = [];
if (el instanceof CompoundPath) {
var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
if (animationCfg) {
cssAnimations.push(animationCfg);
}
else if (!len) {
return;
}
}
else if (!len) {
return;
}
var groupAnimators = {};
for (var i = 0; i < len; i++) {
var animator = animators[i];
var cfgArr = [animator.getMaxTime() / 1000 + 's'];
var easing = getEasingFunc(animator.getClip().easing);
var delay = animator.getDelay();
if (easing) {
cfgArr.push(easing);
}
else {
cfgArr.push('linear');
}
if (delay) {
cfgArr.push(delay / 1000 + 's');
}
if (animator.getLoop()) {
cfgArr.push('infinite');
}
var cfg = cfgArr.join(' ');
groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
groupAnimators[cfg][1].push(animator);
}
function createSingleCSSAnimation(groupAnimator) {
var animators = groupAnimator[1];
var len = animators.length;
var transformKfs = {};
var shapeKfs = {};
var finalKfs = {};
var animationTimingFunctionAttrName = 'animation-timing-function';
function saveAnimatorTrackToCssKfs(animator, cssKfs, toCssAttrName) {
var tracks = animator.getTracks();
var maxTime = animator.getMaxTime();
for (var k = 0; k < tracks.length; k++) {
var track = tracks[k];
if (track.needsAnimate()) {
var kfs = track.keyframes;
var attrName = track.propName;
toCssAttrName && (attrName = toCssAttrName(attrName));
if (attrName) {
for (var i = 0; i < kfs.length; i++) {
var kf = kfs[i];
var percent = Math.round(kf.time / maxTime * 100) + '%';
var kfEasing = getEasingFunc(kf.easing);
var rawValue = kf.rawValue;
if (isString(rawValue) || isNumber(rawValue)) {
cssKfs[percent] = cssKfs[percent] || {};
cssKfs[percent][attrName] = kf.rawValue;
if (kfEasing) {
cssKfs[percent][animationTimingFunctionAttrName] = kfEasing;
}
}
}
}
}
}
}
for (var i = 0; i < len; i++) {
var animator = animators[i];
var targetProp = animator.targetName;
if (!targetProp) {
!onlyShape && saveAnimatorTrackToCssKfs(animator, transformKfs);
}
else if (targetProp === 'shape') {
saveAnimatorTrackToCssKfs(animator, shapeKfs);
}
}
for (var percent in transformKfs) {
var transform = {};
copyTransform(transform, el);
extend(transform, transformKfs[percent]);
var str = getSRTTransformString(transform);
var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
finalKfs[percent] = str ? {
transform: str
} : {};
setTransformOrigin(finalKfs[percent], transform);
if (timingFunction) {
finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
}
}
;
var path;
var canAnimateShape = true;
for (var percent in shapeKfs) {
finalKfs[percent] = finalKfs[percent] || {};
var isFirst = !path;
var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
if (isFirst) {
path = new PathProxy();
}
var len_1 = path.len();
path.reset();
finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
var newLen = path.len();
if (!isFirst && len_1 !== newLen) {
canAnimateShape = false;
break;
}
if (timingFunction) {
finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
}
}
;
if (!canAnimateShape) {
for (var percent in finalKfs) {
delete finalKfs[percent].d;
}
}
if (!onlyShape) {
for (var i = 0; i < len; i++) {
var animator = animators[i];
var targetProp = animator.targetName;
if (targetProp === 'style') {
saveAnimatorTrackToCssKfs(animator, finalKfs, function (propName) { return ANIMATE_STYLE_MAP[propName]; });
}
}
}
var percents = keys(finalKfs);
var allTransformOriginSame = true;
var transformOrigin;
for (var i = 1; i < percents.length; i++) {
var p0 = percents[i - 1];
var p1 = percents[i];
if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
allTransformOriginSame = false;
break;
}
transformOrigin = finalKfs[p0][transformOriginKey];
}
if (allTransformOriginSame && transformOrigin) {
for (var percent in finalKfs) {
if (finalKfs[percent][transformOriginKey]) {
delete finalKfs[percent][transformOriginKey];
}
}
attrs[transformOriginKey] = transformOrigin;
}
if (filter(percents, function (percent) { return keys(finalKfs[percent]).length > 0; }).length) {
var animationName = addAnimation(finalKfs, scope);
return animationName + " " + groupAnimator[0] + " both";
}
}
for (var key in groupAnimators) {
var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
if (animationCfg) {
cssAnimations.push(animationCfg);
}
}
if (cssAnimations.length) {
var className = scope.zrId + '-cls-' + scope.cssClassIdx++;
scope.cssNodes['.' + className] = {
animation: cssAnimations.join(',')
};
attrs["class"] = className;
}
}

13
uni-demo/node_modules/zrender/lib/svg/domapi.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export declare function createTextNode(text: string): Text;
export declare function createComment(text: string): Comment;
export declare function insertBefore(parentNode: Node, newNode: Node, referenceNode: Node | null): void;
export declare function removeChild(node: Node, child: Node): void;
export declare function appendChild(node: Node, child: Node): void;
export declare function parentNode(node: Node): Node | null;
export declare function nextSibling(node: Node): Node | null;
export declare function tagName(elm: Element): string;
export declare function setTextContent(node: Node, text: string | null): void;
export declare function getTextContent(node: Node): string | null;
export declare function isElement(node: Node): node is Element;
export declare function isText(node: Node): node is Text;
export declare function isComment(node: Node): node is Comment;

39
uni-demo/node_modules/zrender/lib/svg/domapi.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
export function createTextNode(text) {
return document.createTextNode(text);
}
export function createComment(text) {
return document.createComment(text);
}
export function insertBefore(parentNode, newNode, referenceNode) {
parentNode.insertBefore(newNode, referenceNode);
}
export function removeChild(node, child) {
node.removeChild(child);
}
export function appendChild(node, child) {
node.appendChild(child);
}
export function parentNode(node) {
return node.parentNode;
}
export function nextSibling(node) {
return node.nextSibling;
}
export function tagName(elm) {
return elm.tagName;
}
export function setTextContent(node, text) {
node.textContent = text;
}
export function getTextContent(node) {
return node.textContent;
}
export function isElement(node) {
return node.nodeType === 1;
}
export function isText(node) {
return node.nodeType === 3;
}
export function isComment(node) {
return node.nodeType === 8;
}

10
uni-demo/node_modules/zrender/lib/svg/graphic.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import Path from '../graphic/Path';
import ZRImage from '../graphic/Image';
import TSpan from '../graphic/TSpan';
import { SVGVNodeAttrs, SVGVNode, BrushScope } from './core';
import Displayable from '../graphic/Displayable';
export declare function brushSVGPath(el: Path, scope: BrushScope): SVGVNode;
export declare function brushSVGImage(el: ZRImage, scope: BrushScope): SVGVNode;
export declare function brushSVGTSpan(el: TSpan, scope: BrushScope): SVGVNode;
export declare function brush(el: Displayable, scope: BrushScope): SVGVNode;
export declare function setClipPath(clipPath: Path, attrs: SVGVNodeAttrs, scope: BrushScope): void;

421
uni-demo/node_modules/zrender/lib/svg/graphic.js generated vendored Normal file
View File

@@ -0,0 +1,421 @@
import { adjustTextY, getIdURL, getMatrixStr, getPathPrecision, getShadowKey, getSRTTransformString, hasShadow, isAroundZero, isGradient, isImagePattern, isLinearGradient, isPattern, isRadialGradient, normalizeColor, round4, TEXT_ALIGN_TO_ANCHOR } from './helper.js';
import Path from '../graphic/Path.js';
import ZRImage from '../graphic/Image.js';
import { getLineHeight } from '../contain/text.js';
import TSpan from '../graphic/TSpan.js';
import SVGPathRebuilder from './SVGPathRebuilder.js';
import mapStyleToAttrs from './mapStyleToAttrs.js';
import { createVNode, vNodeToString } from './core.js';
import { assert, clone, isFunction, isString, logError, map, retrieve2 } from '../core/util.js';
import { createOrUpdateImage } from '../graphic/helper/image.js';
import { createCSSAnimation } from './cssAnimation.js';
import { hasSeparateFont, parseFontSize } from '../graphic/Text.js';
import { DEFAULT_FONT, DEFAULT_FONT_FAMILY } from '../core/platform.js';
var round = Math.round;
function isImageLike(val) {
return val && isString(val.src);
}
function isCanvasLike(val) {
return val && isFunction(val.toDataURL);
}
function setStyleAttrs(attrs, style, el, scope) {
mapStyleToAttrs(function (key, val) {
var isFillStroke = key === 'fill' || key === 'stroke';
if (isFillStroke && isGradient(val)) {
setGradient(style, attrs, key, scope);
}
else if (isFillStroke && isPattern(val)) {
setPattern(el, attrs, key, scope);
}
else {
attrs[key] = val;
}
}, style, el, false);
setShadow(el, attrs, scope);
}
function noRotateScale(m) {
return isAroundZero(m[0] - 1)
&& isAroundZero(m[1])
&& isAroundZero(m[2])
&& isAroundZero(m[3] - 1);
}
function noTranslate(m) {
return isAroundZero(m[4]) && isAroundZero(m[5]);
}
function setTransform(attrs, m, compress) {
if (m && !(noTranslate(m) && noRotateScale(m))) {
var mul = compress ? 10 : 1e4;
attrs.transform = noRotateScale(m)
? "translate(" + round(m[4] * mul) / mul + " " + round(m[5] * mul) / mul + ")" : getMatrixStr(m);
}
}
function convertPolyShape(shape, attrs, mul) {
var points = shape.points;
var strArr = [];
for (var i = 0; i < points.length; i++) {
strArr.push(round(points[i][0] * mul) / mul);
strArr.push(round(points[i][1] * mul) / mul);
}
attrs.points = strArr.join(' ');
}
function validatePolyShape(shape) {
return !shape.smooth;
}
function createAttrsConvert(desc) {
var normalizedDesc = map(desc, function (item) {
return (typeof item === 'string' ? [item, item] : item);
});
return function (shape, attrs, mul) {
for (var i = 0; i < normalizedDesc.length; i++) {
var item = normalizedDesc[i];
var val = shape[item[0]];
if (val != null) {
attrs[item[1]] = round(val * mul) / mul;
}
}
};
}
var buitinShapesDef = {
circle: [createAttrsConvert(['cx', 'cy', 'r'])],
polyline: [convertPolyShape, validatePolyShape],
polygon: [convertPolyShape, validatePolyShape]
};
function hasShapeAnimation(el) {
var animators = el.animators;
for (var i = 0; i < animators.length; i++) {
if (animators[i].targetName === 'shape') {
return true;
}
}
return false;
}
export function brushSVGPath(el, scope) {
var style = el.style;
var shape = el.shape;
var builtinShpDef = buitinShapesDef[el.type];
var attrs = {};
var needsAnimate = scope.animation;
var svgElType = 'path';
var strokePercent = el.style.strokePercent;
var precision = (scope.compress && getPathPrecision(el)) || 4;
if (builtinShpDef
&& !scope.willUpdate
&& !(builtinShpDef[1] && !builtinShpDef[1](shape))
&& !(needsAnimate && hasShapeAnimation(el))
&& !(strokePercent < 1)) {
svgElType = el.type;
var mul = Math.pow(10, precision);
builtinShpDef[0](shape, attrs, mul);
}
else {
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
|| strokePercent !== elExt.__svgPathStrokePercent) {
if (!svgPathBuilder) {
svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder();
}
svgPathBuilder.reset(precision);
path.rebuildPath(svgPathBuilder, strokePercent);
svgPathBuilder.generateStr();
elExt.__svgPathVersion = pathVersion;
elExt.__svgPathStrokePercent = strokePercent;
}
attrs.d = svgPathBuilder.getStr();
}
setTransform(attrs, el.transform);
setStyleAttrs(attrs, style, el, scope);
scope.animation && createCSSAnimation(el, attrs, scope);
return createVNode(svgElType, el.id + '', attrs);
}
export function brushSVGImage(el, scope) {
var style = el.style;
var image = style.image;
if (image && !isString(image)) {
if (isImageLike(image)) {
image = image.src;
}
else if (isCanvasLike(image)) {
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 attrs = {
href: image,
width: dw,
height: dh
};
if (x) {
attrs.x = x;
}
if (y) {
attrs.y = y;
}
setTransform(attrs, el.transform);
setStyleAttrs(attrs, style, el, scope);
scope.animation && createCSSAnimation(el, attrs, scope);
return createVNode('image', el.id + '', attrs);
}
;
export function brushSVGTSpan(el, scope) {
var style = el.style;
var text = style.text;
text != null && (text += '');
if (!text || isNaN(style.x) || isNaN(style.y)) {
return;
}
var font = style.font || DEFAULT_FONT;
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;
var attrs = {
'dominant-baseline': 'central',
'text-anchor': textAlign
};
if (hasSeparateFont(style)) {
var separatedFontStr = '';
var fontStyle = style.fontStyle;
var fontSize = parseFontSize(style.fontSize);
if (!parseFloat(fontSize)) {
return;
}
var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
var fontWeight = style.fontWeight;
separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
if (fontStyle && fontStyle !== 'normal') {
separatedFontStr += "font-style:" + fontStyle + ";";
}
if (fontWeight && fontWeight !== 'normal') {
separatedFontStr += "font-weight:" + fontWeight + ";";
}
attrs.style = separatedFontStr;
}
else {
attrs.style = "font: " + font;
}
if (text.match(/\s/)) {
attrs['xml:space'] = 'preserve';
}
if (x) {
attrs.x = x;
}
if (y) {
attrs.y = y;
}
setTransform(attrs, el.transform);
setStyleAttrs(attrs, style, el, scope);
scope.animation && createCSSAnimation(el, attrs, scope);
return createVNode('text', el.id + '', attrs, undefined, text);
}
export function brush(el, scope) {
if (el instanceof Path) {
return brushSVGPath(el, scope);
}
else if (el instanceof ZRImage) {
return brushSVGImage(el, scope);
}
else if (el instanceof TSpan) {
return brushSVGTSpan(el, scope);
}
}
function setShadow(el, attrs, scope) {
var style = el.style;
if (hasShadow(style)) {
var shadowKey = getShadowKey(el);
var shadowCache = scope.shadowCache;
var shadowId = shadowCache[shadowKey];
if (!shadowId) {
var globalScale = el.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_1 = style.shadowBlur;
var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
var stdDx = blur_1 / 2 / scaleX;
var stdDy = blur_1 / 2 / scaleY;
var stdDeviation = stdDx + ' ' + stdDy;
shadowId = scope.zrId + '-s' + scope.shadowIdx++;
scope.defs[shadowId] = createVNode('filter', shadowId, {
'id': shadowId,
'x': '-100%',
'y': '-100%',
'width': '300%',
'height': '300%'
}, [
createVNode('feDropShadow', '', {
'dx': offsetX / scaleX,
'dy': offsetY / scaleY,
'stdDeviation': stdDeviation,
'flood-color': color,
'flood-opacity': opacity
})
]);
shadowCache[shadowKey] = shadowId;
}
attrs.filter = getIdURL(shadowId);
}
}
function setGradient(style, attrs, target, scope) {
var val = style[target];
var gradientTag;
var gradientAttrs = {
'gradientUnits': val.global
? 'userSpaceOnUse'
: 'objectBoundingBox'
};
if (isLinearGradient(val)) {
gradientTag = 'linearGradient';
gradientAttrs.x1 = val.x;
gradientAttrs.y1 = val.y;
gradientAttrs.x2 = val.x2;
gradientAttrs.y2 = val.y2;
}
else if (isRadialGradient(val)) {
gradientTag = 'radialGradient';
gradientAttrs.cx = retrieve2(val.x, 0.5);
gradientAttrs.cy = retrieve2(val.y, 0.5);
gradientAttrs.r = retrieve2(val.r, 0.5);
}
else {
if (process.env.NODE_ENV !== 'production') {
logError('Illegal gradient type.');
}
return;
}
var colors = val.colorStops;
var colorStops = [];
for (var i = 0, len = colors.length; i < len; ++i) {
var offset = round4(colors[i].offset) * 100 + '%';
var stopColor = colors[i].color;
var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
var stopsAttrs = {
'offset': offset
};
stopsAttrs['stop-color'] = color;
if (opacity < 1) {
stopsAttrs['stop-opacity'] = opacity;
}
colorStops.push(createVNode('stop', i + '', stopsAttrs));
}
var gradientVNode = createVNode(gradientTag, '', gradientAttrs, colorStops);
var gradientKey = vNodeToString(gradientVNode);
var gradientCache = scope.gradientCache;
var gradientId = gradientCache[gradientKey];
if (!gradientId) {
gradientId = scope.zrId + '-g' + scope.gradientIdx++;
gradientCache[gradientKey] = gradientId;
gradientAttrs.id = gradientId;
scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
}
attrs[target] = getIdURL(gradientId);
}
function setPattern(el, attrs, target, scope) {
var val = el.style[target];
var patternAttrs = {
'patternUnits': 'userSpaceOnUse'
};
var child;
if (isImagePattern(val)) {
var imageWidth_1 = val.imageWidth;
var imageHeight_1 = val.imageHeight;
var imageSrc = void 0;
var patternImage = val.image;
if (isString(patternImage)) {
imageSrc = patternImage;
}
else if (isImageLike(patternImage)) {
imageSrc = patternImage.src;
}
else if (isCanvasLike(patternImage)) {
imageSrc = patternImage.toDataURL();
}
if (typeof Image === 'undefined') {
var errMsg = 'Image width/height must been given explictly in svg-ssr renderer.';
assert(imageWidth_1, errMsg);
assert(imageHeight_1, errMsg);
}
else if (imageWidth_1 == null || imageHeight_1 == null) {
var setSizeToVNode_1 = function (vNode, img) {
if (vNode) {
var svgEl = vNode.elm;
var width = (vNode.attrs.width = imageWidth_1 || img.width);
var height = (vNode.attrs.height = imageHeight_1 || img.height);
if (svgEl) {
svgEl.setAttribute('width', width);
svgEl.setAttribute('height', height);
}
}
};
var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
setSizeToVNode_1(patternVNode, img);
setSizeToVNode_1(child, img);
});
if (createdImage && createdImage.width && createdImage.height) {
imageWidth_1 = imageWidth_1 || createdImage.width;
imageHeight_1 = imageHeight_1 || createdImage.height;
}
}
child = createVNode('image', 'img', {
href: imageSrc,
width: imageWidth_1,
height: imageHeight_1
});
patternAttrs.width = imageWidth_1;
patternAttrs.height = imageHeight_1;
}
else if (val.svgElement) {
child = clone(val.svgElement);
patternAttrs.width = val.svgWidth;
patternAttrs.height = val.svgHeight;
}
if (!child) {
return;
}
patternAttrs.patternTransform = getSRTTransformString(val);
var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
var patternKey = vNodeToString(patternVNode);
var patternCache = scope.patternCache;
var patternId = patternCache[patternKey];
if (!patternId) {
patternId = scope.zrId + '-p' + scope.patternIdx++;
patternCache[patternKey] = patternId;
patternAttrs.id = patternId;
patternVNode = scope.defs[patternId] = createVNode('pattern', patternId, patternAttrs, [child]);
}
attrs[target] = getIdURL(patternId);
}
export function setClipPath(clipPath, attrs, scope) {
var clipPathCache = scope.clipPathCache, defs = scope.defs;
var clipPathId = clipPathCache[clipPath.id];
if (!clipPathId) {
clipPathId = scope.zrId + '-c' + scope.clipPathIdx++;
var clipPathAttrs = {
id: clipPathId
};
clipPathCache[clipPath.id] = clipPathId;
defs[clipPathId] = createVNode('clipPath', clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
}
attrs['clip-path'] = getIdURL(clipPathId);
}

37
uni-demo/node_modules/zrender/lib/svg/helper.d.ts generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import { MatrixArray } from '../core/matrix';
import Transformable, { TransformProp } from '../core/Transformable';
import Displayable from '../graphic/Displayable';
import { GradientObject } from '../graphic/Gradient';
import { LinearGradientObject } from '../graphic/LinearGradient';
import Path from '../graphic/Path';
import { ImagePatternObject, PatternObject, SVGPatternObject } from '../graphic/Pattern';
import { RadialGradientObject } from '../graphic/RadialGradient';
export declare function normalizeColor(color: string): {
color: string;
opacity: number;
};
export declare function isAroundZero(transform: number): boolean;
export declare function round3(transform: number): number;
export declare function round4(transform: number): number;
export declare function round1(transform: number): number;
export declare function getMatrixStr(m: MatrixArray): string;
export declare const TEXT_ALIGN_TO_ANCHOR: {
left: string;
right: string;
center: string;
middle: string;
};
export declare function adjustTextY(y: number, lineHeight: number, textBaseline: CanvasTextBaseline): number;
export declare function hasShadow(style: Displayable['style']): any;
export declare function getShadowKey(displayable: Displayable): string;
export declare function getClipPathsKey(clipPaths: Path[]): string;
export declare function isImagePattern(val: any): val is ImagePatternObject;
export declare function isSVGPattern(val: any): val is SVGPatternObject;
export declare function isPattern(val: any): val is PatternObject;
export declare function isLinearGradient(val: GradientObject): val is LinearGradientObject;
export declare function isRadialGradient(val: GradientObject): val is RadialGradientObject;
export declare function isGradient(val: any): val is GradientObject;
export declare function getIdURL(id: string): string;
export declare function getPathPrecision(el: Path): number;
export declare function getSRTTransformString(transform: Partial<Pick<Transformable, TransformProp>>): string;
export declare const encodeBase64: (str: string) => string;

153
uni-demo/node_modules/zrender/lib/svg/helper.js generated vendored Normal file
View File

@@ -0,0 +1,153 @@
import { RADIAN_TO_DEGREE, retrieve2, logError, isFunction } from '../core/util.js';
import { parse } from '../tool/color.js';
import env from '../core/env.js';
var mathRound = Math.round;
export function normalizeColor(color) {
var opacity;
if (!color || color === 'transparent') {
color = 'none';
}
else if (typeof color === 'string' && color.indexOf('rgba') > -1) {
var arr = parse(color);
if (arr) {
color = 'rgb(' + arr[0] + ',' + arr[1] + ',' + arr[2] + ')';
opacity = arr[3];
}
}
return {
color: color,
opacity: opacity == null ? 1 : opacity
};
}
var EPSILON = 1e-4;
export function isAroundZero(transform) {
return transform < EPSILON && transform > -EPSILON;
}
export function round3(transform) {
return mathRound(transform * 1e3) / 1e3;
}
export function round4(transform) {
return mathRound(transform * 1e4) / 1e4;
}
export function round1(transform) {
return mathRound(transform * 10) / 10;
}
export function getMatrixStr(m) {
return 'matrix('
+ round3(m[0]) + ','
+ round3(m[1]) + ','
+ round3(m[2]) + ','
+ round3(m[3]) + ','
+ round4(m[4]) + ','
+ round4(m[5])
+ ')';
}
export var TEXT_ALIGN_TO_ANCHOR = {
left: 'start',
right: 'end',
center: 'middle',
middle: 'middle'
};
export function adjustTextY(y, lineHeight, textBaseline) {
if (textBaseline === 'top') {
y += lineHeight / 2;
}
else if (textBaseline === 'bottom') {
y -= lineHeight / 2;
}
return y;
}
export function hasShadow(style) {
return style
&& (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
}
export function getShadowKey(displayable) {
var style = displayable.style;
var globalScale = displayable.getGlobalScale();
return [
style.shadowColor,
(style.shadowBlur || 0).toFixed(2),
(style.shadowOffsetX || 0).toFixed(2),
(style.shadowOffsetY || 0).toFixed(2),
globalScale[0],
globalScale[1]
].join(',');
}
export function getClipPathsKey(clipPaths) {
var key = [];
if (clipPaths) {
for (var i = 0; i < clipPaths.length; i++) {
var clipPath = clipPaths[i];
key.push(clipPath.id);
}
}
return key.join(',');
}
export function isImagePattern(val) {
return val && (!!val.image);
}
export function isSVGPattern(val) {
return val && (!!val.svgElement);
}
export function isPattern(val) {
return isImagePattern(val) || isSVGPattern(val);
}
export function isLinearGradient(val) {
return val.type === 'linear';
}
export function isRadialGradient(val) {
return val.type === 'radial';
}
export function isGradient(val) {
return val && (val.type === 'linear'
|| val.type === 'radial');
}
export function getIdURL(id) {
return "url(#" + id + ")";
}
export function getPathPrecision(el) {
var scale = el.getGlobalScale();
var size = Math.max(scale[0], scale[1]);
return Math.max(Math.ceil(Math.log(size) / Math.log(10)), 1);
}
export function getSRTTransformString(transform) {
var x = transform.x || 0;
var y = transform.y || 0;
var rotation = (transform.rotation || 0) * RADIAN_TO_DEGREE;
var scaleX = retrieve2(transform.scaleX, 1);
var scaleY = retrieve2(transform.scaleY, 1);
var skewX = transform.skewX || 0;
var skewY = transform.skewY || 0;
var res = [];
if (x || y) {
res.push("translate(" + x + "px," + y + "px)");
}
if (rotation) {
res.push("rotate(" + rotation + ")");
}
if (scaleX !== 1 || scaleY !== 1) {
res.push("scale(" + scaleX + "," + scaleY + ")");
}
if (skewX || skewY) {
res.push("skew(" + mathRound(skewX * RADIAN_TO_DEGREE) + "deg, " + mathRound(skewY * RADIAN_TO_DEGREE) + "deg)");
}
return res.join(' ');
}
export var encodeBase64 = (function () {
if (env.hasGlobalWindow && isFunction(window.btoa)) {
return function (str) {
return window.btoa(unescape(str));
};
}
if (typeof Buffer !== 'undefined') {
return function (str) {
return Buffer.from(str).toString('base64');
};
}
return function (str) {
if (process.env.NODE_ENV !== 'production') {
logError('Base64 isn\'t natively supported in the current environment.');
}
return null;
};
})();

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,129 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import * as zrUtil from '../../core/util.js';
import { isClipPathChanged } from '../../canvas/helper.js';
function generateClipPathsKey(clipPaths) {
var key = [];
if (clipPaths) {
for (var i = 0; i < clipPaths.length; i++) {
var clipPath = clipPaths[i];
key.push(clipPath.id);
}
}
return key.join(',');
}
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 = generateClipPathsKey(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] = this.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 = this.createElement('clipPath');
clipPathEl.setAttribute('id', id);
defs.appendChild(clipPathEl);
clipPath._dom = clipPathEl;
}
var svgProxy = this.getSvgProxy(clipPath);
svgProxy.brush(clipPath);
var pathEl = this.getSvgElement(clipPath);
clipPathEl.innerHTML = '';
clipPathEl.appendChild(pathEl);
parentEl.setAttribute('clip-path', 'url(#' + 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,28 @@
import { createElement } from '../core';
import Path from '../../graphic/Path';
import ZRImage from '../../graphic/Image';
import TSpan from '../../graphic/TSpan';
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);
createElement: typeof createElement;
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;
getSvgProxy(displayable: Displayable): import("../graphic").SVGProxy<Path<import("../../graphic/Path").PathProps>> | import("../graphic").SVGProxy<ZRImage> | import("../graphic").SVGProxy<TSpan>;
getSvgElement(displayable: Displayable): SVGElement;
}

View File

@@ -0,0 +1,149 @@
import { createElement } from '../core.js';
import * as zrUtil from '../../core/util.js';
import Path from '../../graphic/Path.js';
import ZRImage from '../../graphic/Image.js';
import TSpan from '../../graphic/TSpan.js';
import { path as svgPath, image as svgImage, text as svgText } from '../graphic.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.createElement = createElement;
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(this.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.getSvgProxy = function (displayable) {
if (displayable instanceof Path) {
return svgPath;
}
else if (displayable instanceof ZRImage) {
return svgImage;
}
else if (displayable instanceof TSpan) {
return svgText;
}
else {
return svgPath;
}
};
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,141 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import * as zrUtil from '../../core/util.js';
import * as colorTool from '../../tool/color.js';
function isLinearGradient(value) {
return value.type === 'linear';
}
function isRadialGradient(value) {
return value.type === 'radial';
}
function isGradient(value) {
return value && (value.type === 'linear'
|| value.type === 'radial');
}
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);
var id = dom.getAttribute('id');
svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
}
});
}
};
GradientManager.prototype.add = function (gradient) {
var dom;
if (isLinearGradient(gradient)) {
dom = this.createElement('linearGradient');
}
else if (isRadialGradient(gradient)) {
dom = this.createElement('radialGradient');
}
else {
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 {
zrUtil.logError('Illegal gradient type.');
return;
}
if (gradient.global) {
dom.setAttribute('gradientUnits', 'userSpaceOnUse');
}
else {
dom.setAttribute('gradientUnits', 'objectBoundingBox');
}
dom.innerHTML = '';
var colors = gradient.colorStops;
for (var i = 0, len = colors.length; i < len; ++i) {
var stop_1 = this.createElement('stop');
stop_1.setAttribute('offset', colors[i].offset * 100 + '%');
var color = colors[i].color;
if (color.indexOf('rgba') > -1) {
var opacity = colorTool.parse(color)[3];
var hex = colorTool.toHex(color);
stop_1.setAttribute('stop-color', '#' + hex);
stop_1.setAttribute('stop-opacity', opacity + '');
}
else {
stop_1.setAttribute('stop-color', colors[i].color);
}
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,140 @@
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';
function isPattern(value) {
return value && (!!value.image || !!value.svgElement);
}
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);
var id = dom.getAttribute('id');
svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
}
});
}
};
PatternManager.prototype.add = function (pattern) {
if (!isPattern(pattern)) {
return;
}
var dom = this.createElement('pattern');
pattern.id = pattern.id == null ? this.nextId++ : pattern.id;
dom.setAttribute('id', 'zr' + this._zrId
+ '-pattern-' + pattern.id);
dom.setAttribute('x', '0');
dom.setAttribute('y', '0');
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) {
var svgElement = pattern.svgElement;
if (svgElement instanceof SVGElement) {
if (svgElement.parentNode !== patternDom) {
patternDom.innerHTML = '';
patternDom.appendChild(svgElement);
patternDom.setAttribute('width', pattern.svgWidth + '');
patternDom.setAttribute('height', pattern.svgHeight + '');
}
}
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 = this.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);
img.setAttribute('x', '0');
img.setAttribute('y', '0');
var hostEl = {
dirty: function () { }
};
var createdImage = createOrUpdateImage(imageSrc, img, hostEl, function (img) {
patternDom.setAttribute('width', img.width + '');
patternDom.setAttribute('height', img.height + '');
});
if (createdImage && createdImage.width && createdImage.height) {
patternDom.setAttribute('width', createdImage.width + '');
patternDom.setAttribute('height', createdImage.height + '');
}
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,105 @@
import { __extends } from "tslib";
import Definable from './Definable.js';
import { normalizeColor } from '../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 = this.createElement('filter');
shadowDom.setAttribute('id', 'zr' + this._zrId + '-shadow-' + this.nextId++);
var domChild = this.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;
var id = shadowDom.getAttribute('id');
svgElement.setAttribute('filter', 'url(#' + 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;
function hasShadow(style) {
return style
&& (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY);
}
function getShadowKey(displayable) {
var style = displayable.style;
var globalScale = displayable.getGlobalScale();
return [
style.shadowColor,
(style.shadowBlur || 0).toFixed(2),
(style.shadowOffsetX || 0).toFixed(2),
(style.shadowOffsetY || 0).toFixed(2),
globalScale[0],
globalScale[1]
].join(',');
}

View File

@@ -0,0 +1,6 @@
import Path, { PathStyleProps } from '../graphic/Path';
import ZRImage, { ImageStyleProps } from '../graphic/Image';
import TSpan, { TSpanStyleProps } from '../graphic/TSpan';
declare type AllStyleOption = PathStyleProps | TSpanStyleProps | ImageStyleProps;
export default function mapStyleToAttrs(updateAttr: (key: string, val: string | number) => void, style: AllStyleOption, el: Path | TSpan | ZRImage, forceUpdate: boolean): void;
export {};

View File

@@ -0,0 +1,81 @@
import { DEFAULT_PATH_STYLE } from '../graphic/Path.js';
import ZRImage from '../graphic/Image.js';
import { getLineDash } from '../canvas/dashStyle.js';
import { map } from '../core/util.js';
import { normalizeColor } from './helper.js';
var NONE = 'none';
var mathRound = Math.round;
function pathHasFill(style) {
var fill = style.fill;
return fill != null && fill !== NONE;
}
function pathHasStroke(style) {
var stroke = style.stroke;
return stroke != null && stroke !== NONE;
}
var strokeProps = ['lineCap', 'miterLimit', 'lineJoin'];
var svgStrokeProps = map(strokeProps, function (prop) { return "stroke-" + prop.toLowerCase(); });
export default function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
var opacity = style.opacity == null ? 1 : style.opacity;
if (el instanceof ZRImage) {
updateAttr('opacity', opacity);
return;
}
if (pathHasFill(style)) {
var fill = normalizeColor(style.fill);
updateAttr('fill', fill.color);
var fillOpacity = style.fillOpacity != null
? style.fillOpacity * fill.opacity * opacity
: fill.opacity * opacity;
if (forceUpdate || fillOpacity < 1) {
updateAttr('fill-opacity', fillOpacity);
}
}
else {
updateAttr('fill', NONE);
}
if (pathHasStroke(style)) {
var stroke = normalizeColor(style.stroke);
updateAttr('stroke', stroke.color);
var strokeScale = style.strokeNoScale
? el.getLineScale()
: 1;
var strokeWidth = (strokeScale ? (style.lineWidth || 0) / strokeScale : 0);
var strokeOpacity = style.strokeOpacity != null
? style.strokeOpacity * stroke.opacity * opacity
: stroke.opacity * opacity;
var strokeFirst = style.strokeFirst;
if (forceUpdate || strokeWidth !== 1) {
updateAttr('stroke-width', strokeWidth);
}
if (forceUpdate || strokeFirst) {
updateAttr('paint-order', strokeFirst ? 'stroke' : 'fill');
}
if (forceUpdate || strokeOpacity < 1) {
updateAttr('stroke-opacity', strokeOpacity);
}
if (style.lineDash) {
var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
if (lineDash) {
lineDashOffset = mathRound(lineDashOffset || 0);
updateAttr('stroke-dasharray', lineDash.join(','));
if (lineDashOffset || forceUpdate) {
updateAttr('stroke-dashoffset', lineDashOffset);
}
}
}
else if (forceUpdate) {
updateAttr('stroke-dasharray', NONE);
}
for (var i = 0; i < strokeProps.length; i++) {
var propName = strokeProps[i];
if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
var val = style[propName] || DEFAULT_PATH_STYLE[propName];
val && updateAttr(svgStrokeProps[i], val);
}
}
}
else if (forceUpdate) {
updateAttr('stroke', NONE);
}
}

3
uni-demo/node_modules/zrender/lib/svg/patch.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import { SVGVNode } from './core';
export declare function updateAttrs(oldVnode: SVGVNode, vnode: SVGVNode): void;
export default function patch(oldVnode: SVGVNode, vnode: SVGVNode): SVGVNode;

250
uni-demo/node_modules/zrender/lib/svg/patch.js generated vendored Normal file
View File

@@ -0,0 +1,250 @@
import { isArray, isObject } from '../core/util.js';
import { createElement, createVNode, XMLNS, XML_NAMESPACE, XLINKNS } from './core.js';
import * as api from './domapi.js';
var colonChar = 58;
var xChar = 120;
var emptyNode = createVNode('', '');
function isUndef(s) {
return s === undefined;
}
function isDef(s) {
return s !== undefined;
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var map = {};
for (var i = beginIdx; i <= endIdx; ++i) {
var key = children[i].key;
if (key !== undefined) {
if (process.env.NODE_ENV !== 'production') {
if (map[key] != null) {
console.error("Duplicate key " + key);
}
}
map[key] = i;
}
}
return map;
}
function sameVnode(vnode1, vnode2) {
var isSameKey = vnode1.key === vnode2.key;
var isSameTag = vnode1.tag === vnode2.tag;
return isSameTag && isSameKey;
}
function createElm(vnode) {
var i;
var children = vnode.children;
var tag = vnode.tag;
if (isDef(tag)) {
var elm = (vnode.elm = createElement(tag));
updateAttrs(emptyNode, vnode);
if (isArray(children)) {
for (i = 0; i < children.length; ++i) {
var ch = children[i];
if (ch != null) {
api.appendChild(elm, createElm(ch));
}
}
}
else if (isDef(vnode.text) && !isObject(vnode.text)) {
api.appendChild(elm, api.createTextNode(vnode.text));
}
}
else {
vnode.elm = api.createTextNode(vnode.text);
}
return vnode.elm;
}
function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var ch = vnodes[startIdx];
if (ch != null) {
api.insertBefore(parentElm, createElm(ch), before);
}
}
}
function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var ch = vnodes[startIdx];
if (ch != null) {
if (isDef(ch.tag)) {
var parent_1 = api.parentNode(ch.elm);
api.removeChild(parent_1, ch.elm);
}
else {
api.removeChild(parentElm, ch.elm);
}
}
}
}
export function updateAttrs(oldVnode, vnode) {
var key;
var elm = vnode.elm;
var oldAttrs = oldVnode && oldVnode.attrs || {};
var attrs = vnode.attrs || {};
if (oldAttrs === attrs) {
return;
}
for (key in attrs) {
var cur = attrs[key];
var old = oldAttrs[key];
if (old !== cur) {
if (cur === true) {
elm.setAttribute(key, '');
}
else if (cur === false) {
elm.removeAttribute(key);
}
else {
if (key.charCodeAt(0) !== xChar) {
elm.setAttribute(key, cur);
}
else if (key === 'xmlns:xlink' || key === 'xmlns') {
elm.setAttributeNS(XMLNS, key, cur);
}
else if (key.charCodeAt(3) === colonChar) {
elm.setAttributeNS(XML_NAMESPACE, key, cur);
}
else if (key.charCodeAt(5) === colonChar) {
elm.setAttributeNS(XLINKNS, key, cur);
}
else {
elm.setAttribute(key, cur);
}
}
}
}
for (key in oldAttrs) {
if (!(key in attrs)) {
elm.removeAttribute(key);
}
}
}
function updateChildren(parentElm, oldCh, newCh) {
var oldStartIdx = 0;
var newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVnode = oldCh[0];
var oldEndVnode = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVnode = newCh[0];
var newEndVnode = newCh[newEndIdx];
var oldKeyToIdx;
var idxInOld;
var elmToMove;
var before;
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (oldStartVnode == null) {
oldStartVnode = oldCh[++oldStartIdx];
}
else if (oldEndVnode == null) {
oldEndVnode = oldCh[--oldEndIdx];
}
else if (newStartVnode == null) {
newStartVnode = newCh[++newStartIdx];
}
else if (newEndVnode == null) {
newEndVnode = newCh[--newEndIdx];
}
else if (sameVnode(oldStartVnode, newStartVnode)) {
patchVnode(oldStartVnode, newStartVnode);
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
}
else if (sameVnode(oldEndVnode, newEndVnode)) {
patchVnode(oldEndVnode, newEndVnode);
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
}
else if (sameVnode(oldStartVnode, newEndVnode)) {
patchVnode(oldStartVnode, newEndVnode);
api.insertBefore(parentElm, oldStartVnode.elm, api.nextSibling(oldEndVnode.elm));
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
}
else if (sameVnode(oldEndVnode, newStartVnode)) {
patchVnode(oldEndVnode, newStartVnode);
api.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
}
else {
if (isUndef(oldKeyToIdx)) {
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
}
idxInOld = oldKeyToIdx[newStartVnode.key];
if (isUndef(idxInOld)) {
api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
}
else {
elmToMove = oldCh[idxInOld];
if (elmToMove.tag !== newStartVnode.tag) {
api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
}
else {
patchVnode(elmToMove, newStartVnode);
oldCh[idxInOld] = undefined;
api.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
}
}
newStartVnode = newCh[++newStartIdx];
}
}
if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
if (oldStartIdx > oldEndIdx) {
before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
}
else {
removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
}
}
}
function patchVnode(oldVnode, vnode) {
var elm = (vnode.elm = oldVnode.elm);
var oldCh = oldVnode.children;
var ch = vnode.children;
if (oldVnode === vnode) {
return;
}
updateAttrs(oldVnode, vnode);
if (isUndef(vnode.text)) {
if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) {
updateChildren(elm, oldCh, ch);
}
}
else if (isDef(ch)) {
if (isDef(oldVnode.text)) {
api.setTextContent(elm, '');
}
addVnodes(elm, null, ch, 0, ch.length - 1);
}
else if (isDef(oldCh)) {
removeVnodes(elm, oldCh, 0, oldCh.length - 1);
}
else if (isDef(oldVnode.text)) {
api.setTextContent(elm, '');
}
}
else if (oldVnode.text !== vnode.text) {
if (isDef(oldCh)) {
removeVnodes(elm, oldCh, 0, oldCh.length - 1);
}
api.setTextContent(elm, vnode.text);
}
}
export default function patch(oldVnode, vnode) {
if (sameVnode(oldVnode, vnode)) {
patchVnode(oldVnode, vnode);
}
else {
var elm = oldVnode.elm;
var parent_2 = api.parentNode(elm);
createElm(vnode);
if (parent_2 !== null) {
api.insertBefore(parent_2, vnode.elm, api.nextSibling(elm));
removeVnodes(parent_2, [oldVnode], 0, 0);
}
}
return vnode;
}

1
uni-demo/node_modules/zrender/lib/svg/svg.d.ts generated vendored Normal file
View File

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

3
uni-demo/node_modules/zrender/lib/svg/svg.js generated vendored Normal file
View File

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