zrender-nightly 5.5.0-dev.20221128 → 5.5.0-dev.20221130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/zrender.js +59 -16
- package/dist/zrender.js.map +1 -1
- package/dist/zrender.min.js +1 -1
- package/lib/core/platform.js +2 -2
- package/lib/core/util.d.ts +10 -3
- package/lib/core/util.js +53 -11
- package/lib/svg/Painter.js +1 -1
- package/lib/svg/graphic.js +2 -1
- package/lib/zrender.d.ts +1 -1
- package/lib/zrender.js +1 -1
- package/package.json +1 -1
- package/src/core/platform.ts +3 -3
- package/src/core/util.ts +73 -17
- package/src/svg/Painter.ts +1 -1
- package/src/svg/graphic.ts +2 -1
- package/src/zrender.ts +1 -1
package/lib/core/platform.js
CHANGED
|
@@ -39,8 +39,8 @@ export var platformApi = {
|
|
|
39
39
|
else {
|
|
40
40
|
text = text || '';
|
|
41
41
|
font = font || DEFAULT_FONT;
|
|
42
|
-
var res =
|
|
43
|
-
var fontSize =
|
|
42
|
+
var res = /(\d+)px/.exec(font);
|
|
43
|
+
var fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
|
|
44
44
|
var width = 0;
|
|
45
45
|
if (font.indexOf('mono') >= 0) {
|
|
46
46
|
width = fontSize * text.length;
|
package/lib/core/util.d.ts
CHANGED
|
@@ -68,13 +68,20 @@ export declare function assert(condition: any, message?: string): void;
|
|
|
68
68
|
export declare function trim(str: string): string;
|
|
69
69
|
export declare function setAsPrimitive(obj: any): void;
|
|
70
70
|
export declare function isPrimitive(obj: any): boolean;
|
|
71
|
+
interface MapInterface<T, KEY extends string | number = string | number> {
|
|
72
|
+
delete(key: KEY): boolean;
|
|
73
|
+
has(key: KEY): boolean;
|
|
74
|
+
get(key: KEY): T | undefined;
|
|
75
|
+
set(key: KEY, value: T): this;
|
|
76
|
+
keys(): KEY[];
|
|
77
|
+
forEach(callback: (value: T, key: KEY) => void): void;
|
|
78
|
+
}
|
|
71
79
|
export declare class HashMap<T, KEY extends string | number = string | number> {
|
|
72
|
-
data:
|
|
73
|
-
[key in KEY]: T;
|
|
74
|
-
};
|
|
80
|
+
data: MapInterface<T, KEY>;
|
|
75
81
|
constructor(obj?: HashMap<T, KEY> | {
|
|
76
82
|
[key in KEY]?: T;
|
|
77
83
|
} | KEY[]);
|
|
84
|
+
hasKey(key: KEY): boolean;
|
|
78
85
|
get(key: KEY): T;
|
|
79
86
|
set(key: KEY, value: T): T;
|
|
80
87
|
each<Context>(cb: (this: Context, value?: T, key?: KEY) => void, context?: Context): void;
|
package/lib/core/util.js
CHANGED
|
@@ -422,11 +422,48 @@ export function setAsPrimitive(obj) {
|
|
|
422
422
|
export function isPrimitive(obj) {
|
|
423
423
|
return obj[primitiveKey];
|
|
424
424
|
}
|
|
425
|
+
var MapPolyfill = (function () {
|
|
426
|
+
function MapPolyfill() {
|
|
427
|
+
this.data = {};
|
|
428
|
+
}
|
|
429
|
+
MapPolyfill.prototype["delete"] = function (key) {
|
|
430
|
+
var existed = this.has(key);
|
|
431
|
+
if (existed) {
|
|
432
|
+
delete this.data[key];
|
|
433
|
+
}
|
|
434
|
+
return existed;
|
|
435
|
+
};
|
|
436
|
+
MapPolyfill.prototype.has = function (key) {
|
|
437
|
+
return this.data.hasOwnProperty(key);
|
|
438
|
+
};
|
|
439
|
+
MapPolyfill.prototype.get = function (key) {
|
|
440
|
+
return this.data[key];
|
|
441
|
+
};
|
|
442
|
+
MapPolyfill.prototype.set = function (key, value) {
|
|
443
|
+
this.data[key] = value;
|
|
444
|
+
return this;
|
|
445
|
+
};
|
|
446
|
+
MapPolyfill.prototype.keys = function () {
|
|
447
|
+
return keys(this.data);
|
|
448
|
+
};
|
|
449
|
+
MapPolyfill.prototype.forEach = function (callback) {
|
|
450
|
+
var data = this.data;
|
|
451
|
+
for (var key in data) {
|
|
452
|
+
if (data.hasOwnProperty(key)) {
|
|
453
|
+
callback(data[key], key);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
return MapPolyfill;
|
|
458
|
+
}());
|
|
459
|
+
var isNativeMapSupported = typeof Map === 'function';
|
|
460
|
+
function maybeNativeMap() {
|
|
461
|
+
return (isNativeMapSupported ? new Map() : new MapPolyfill());
|
|
462
|
+
}
|
|
425
463
|
var HashMap = (function () {
|
|
426
464
|
function HashMap(obj) {
|
|
427
|
-
this.data = {};
|
|
428
465
|
var isArr = isArray(obj);
|
|
429
|
-
this.data =
|
|
466
|
+
this.data = maybeNativeMap();
|
|
430
467
|
var thisMap = this;
|
|
431
468
|
(obj instanceof HashMap)
|
|
432
469
|
? obj.each(visit)
|
|
@@ -435,24 +472,29 @@ var HashMap = (function () {
|
|
|
435
472
|
isArr ? thisMap.set(value, key) : thisMap.set(key, value);
|
|
436
473
|
}
|
|
437
474
|
}
|
|
475
|
+
HashMap.prototype.hasKey = function (key) {
|
|
476
|
+
return this.data.has(key);
|
|
477
|
+
};
|
|
438
478
|
HashMap.prototype.get = function (key) {
|
|
439
|
-
return this.data.
|
|
479
|
+
return this.data.get(key);
|
|
440
480
|
};
|
|
441
481
|
HashMap.prototype.set = function (key, value) {
|
|
442
|
-
|
|
482
|
+
this.data.set(key, value);
|
|
483
|
+
return value;
|
|
443
484
|
};
|
|
444
485
|
HashMap.prototype.each = function (cb, context) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
}
|
|
486
|
+
this.data.forEach(function (value, key) {
|
|
487
|
+
cb.call(context, value, key);
|
|
488
|
+
});
|
|
450
489
|
};
|
|
451
490
|
HashMap.prototype.keys = function () {
|
|
452
|
-
|
|
491
|
+
var keys = this.data.keys();
|
|
492
|
+
return isNativeMapSupported
|
|
493
|
+
? Array.from(keys)
|
|
494
|
+
: keys;
|
|
453
495
|
};
|
|
454
496
|
HashMap.prototype.removeKey = function (key) {
|
|
455
|
-
|
|
497
|
+
this.data["delete"](key);
|
|
456
498
|
};
|
|
457
499
|
return HashMap;
|
|
458
500
|
}());
|
package/lib/svg/Painter.js
CHANGED
|
@@ -243,7 +243,7 @@ function createBackgroundVNode(width, height, backgroundColor, scope) {
|
|
|
243
243
|
else {
|
|
244
244
|
var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
|
|
245
245
|
bgVNode.attrs.fill = color;
|
|
246
|
-
opacity < 1 && (bgVNode.attrs
|
|
246
|
+
opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
return bgVNode;
|
package/lib/svg/graphic.js
CHANGED
|
@@ -108,11 +108,12 @@ export function brushSVGPath(el, scope) {
|
|
|
108
108
|
builtinShpDef[0](shape, attrs, mul);
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
111
|
+
var needBuildPath = !el.path || el.shapeChanged();
|
|
111
112
|
if (!el.path) {
|
|
112
113
|
el.createPathProxy();
|
|
113
114
|
}
|
|
114
115
|
var path = el.path;
|
|
115
|
-
if (
|
|
116
|
+
if (needBuildPath) {
|
|
116
117
|
path.beginPath();
|
|
117
118
|
el.buildPath(path, el.shape);
|
|
118
119
|
el.pathUpdated();
|
package/lib/zrender.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare function dispose(zr: ZRender): void;
|
|
|
84
84
|
export declare function disposeAll(): void;
|
|
85
85
|
export declare function getInstance(id: number): ZRender;
|
|
86
86
|
export declare function registerPainter(name: string, Ctor: PainterBaseCtor): void;
|
|
87
|
-
export declare const version = "5.5.0-dev.
|
|
87
|
+
export declare const version = "5.5.0-dev.20221130";
|
|
88
88
|
export interface ZRenderType extends ZRender {
|
|
89
89
|
}
|
|
90
90
|
export {};
|
package/lib/zrender.js
CHANGED
package/package.json
CHANGED
package/src/core/platform.ts
CHANGED
|
@@ -75,8 +75,8 @@ export const platformApi: Platform = {
|
|
|
75
75
|
text = text || '';
|
|
76
76
|
font = font || DEFAULT_FONT;
|
|
77
77
|
// Use font size if there is no other method can be used.
|
|
78
|
-
const res =
|
|
79
|
-
const fontSize =
|
|
78
|
+
const res = /(\d+)px/.exec(font);
|
|
79
|
+
const fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
|
|
80
80
|
let width = 0;
|
|
81
81
|
if (font.indexOf('mono') >= 0) { // is monospace
|
|
82
82
|
width = fontSize * text.length;
|
|
@@ -103,7 +103,7 @@ export const platformApi: Platform = {
|
|
|
103
103
|
|
|
104
104
|
export function setPlatformAPI(newPlatformApis: Partial<Platform>) {
|
|
105
105
|
for (let key in platformApi) {
|
|
106
|
-
// Don't assign
|
|
106
|
+
// Don't assign unknown methods.
|
|
107
107
|
if ((newPlatformApis as any)[key]) {
|
|
108
108
|
(platformApi as any)[key] = (newPlatformApis as any)[key];
|
|
109
109
|
}
|
package/src/core/util.ts
CHANGED
|
@@ -653,20 +653,72 @@ export function isPrimitive(obj: any): boolean {
|
|
|
653
653
|
return obj[primitiveKey];
|
|
654
654
|
}
|
|
655
655
|
|
|
656
|
+
interface MapInterface<T, KEY extends string | number = string | number> {
|
|
657
|
+
delete(key: KEY): boolean;
|
|
658
|
+
has(key: KEY): boolean;
|
|
659
|
+
get(key: KEY): T | undefined;
|
|
660
|
+
set(key: KEY, value: T): this;
|
|
661
|
+
keys(): KEY[];
|
|
662
|
+
forEach(callback: (value: T, key: KEY) => void): void;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
class MapPolyfill<T, KEY extends string | number = string | number> implements MapInterface<T, KEY> {
|
|
666
|
+
private data: Record<KEY, T> = {} as Record<KEY, T>;
|
|
667
|
+
|
|
668
|
+
delete(key: KEY): boolean {
|
|
669
|
+
const existed = this.has(key);
|
|
670
|
+
if (existed) {
|
|
671
|
+
delete this.data[key];
|
|
672
|
+
}
|
|
673
|
+
return existed;
|
|
674
|
+
}
|
|
675
|
+
has(key: KEY): boolean {
|
|
676
|
+
return this.data.hasOwnProperty(key);
|
|
677
|
+
}
|
|
678
|
+
get(key: KEY): T | undefined {
|
|
679
|
+
return this.data[key];
|
|
680
|
+
}
|
|
681
|
+
set(key: KEY, value: T): this {
|
|
682
|
+
this.data[key] = value;
|
|
683
|
+
return this;
|
|
684
|
+
}
|
|
685
|
+
keys(): KEY[] {
|
|
686
|
+
return keys(this.data);
|
|
687
|
+
}
|
|
688
|
+
forEach(callback: (value: T, key: KEY) => void): void {
|
|
689
|
+
// This is a potential performance bottleneck, see details in
|
|
690
|
+
// https://github.com/ecomfe/zrender/issues/965, however it is now
|
|
691
|
+
// less likely to occur as we default to native maps when possible.
|
|
692
|
+
const data = this.data;
|
|
693
|
+
for (const key in data) {
|
|
694
|
+
if (data.hasOwnProperty(key)) {
|
|
695
|
+
callback(data[key], key);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// We want to use native Map if it is available, but we do not want to polyfill the global scope
|
|
702
|
+
// in case users ship their own polyfills or patch the native map object in any way.
|
|
703
|
+
const isNativeMapSupported = typeof Map === 'function';
|
|
704
|
+
function maybeNativeMap<T, KEY extends string | number = string | number>(): MapInterface<T, KEY> {
|
|
705
|
+
// Map may be a native class if we are running in an ES6 compatible environment.
|
|
706
|
+
// eslint-disable-next-line
|
|
707
|
+
return (isNativeMapSupported ? new Map<KEY, T>() : new MapPolyfill<T, KEY>()) as MapInterface<T, KEY>;
|
|
708
|
+
}
|
|
656
709
|
|
|
657
710
|
/**
|
|
658
711
|
* @constructor
|
|
659
|
-
* @param {Object} obj
|
|
712
|
+
* @param {Object} obj
|
|
660
713
|
*/
|
|
661
714
|
export class HashMap<T, KEY extends string | number = string | number> {
|
|
662
|
-
|
|
663
|
-
data: {[key in KEY]: T} = {} as {[key in KEY]: T};
|
|
715
|
+
data: MapInterface<T, KEY>
|
|
664
716
|
|
|
665
717
|
constructor(obj?: HashMap<T, KEY> | { [key in KEY]?: T } | KEY[]) {
|
|
666
718
|
const isArr = isArray(obj);
|
|
667
719
|
// Key should not be set on this, otherwise
|
|
668
720
|
// methods get/set/... may be overrided.
|
|
669
|
-
this.data =
|
|
721
|
+
this.data = maybeNativeMap<T, KEY>();
|
|
670
722
|
const thisMap = this;
|
|
671
723
|
|
|
672
724
|
(obj instanceof HashMap)
|
|
@@ -678,16 +730,18 @@ export class HashMap<T, KEY extends string | number = string | number> {
|
|
|
678
730
|
}
|
|
679
731
|
}
|
|
680
732
|
|
|
681
|
-
//
|
|
682
|
-
|
|
683
|
-
|
|
733
|
+
// `hasKey` instead of `has` for potential misleading.
|
|
734
|
+
hasKey(key: KEY): boolean {
|
|
735
|
+
return this.data.has(key);
|
|
736
|
+
}
|
|
684
737
|
get(key: KEY): T {
|
|
685
|
-
return this.data.
|
|
738
|
+
return this.data.get(key);
|
|
686
739
|
}
|
|
687
740
|
set(key: KEY, value: T): T {
|
|
688
741
|
// Comparing with invocation chaining, `return value` is more commonly
|
|
689
742
|
// used in this case: `const someVal = map.set('a', genVal());`
|
|
690
|
-
|
|
743
|
+
this.data.set(key, value);
|
|
744
|
+
return value;
|
|
691
745
|
}
|
|
692
746
|
// Although util.each can be performed on this hashMap directly, user
|
|
693
747
|
// should not use the exposed keys, who are prefixed.
|
|
@@ -695,18 +749,20 @@ export class HashMap<T, KEY extends string | number = string | number> {
|
|
|
695
749
|
cb: (this: Context, value?: T, key?: KEY) => void,
|
|
696
750
|
context?: Context
|
|
697
751
|
) {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
}
|
|
752
|
+
this.data.forEach((value, key) => {
|
|
753
|
+
cb.call(context, value, key);
|
|
754
|
+
});
|
|
703
755
|
}
|
|
704
756
|
keys(): KEY[] {
|
|
705
|
-
|
|
757
|
+
const keys = this.data.keys();
|
|
758
|
+
return isNativeMapSupported
|
|
759
|
+
// Native map returns an iterator so we need to convert it to an array
|
|
760
|
+
? Array.from(keys)
|
|
761
|
+
: keys;
|
|
706
762
|
}
|
|
707
763
|
// Do not use this method if performance sensitive.
|
|
708
|
-
removeKey(key: KEY) {
|
|
709
|
-
|
|
764
|
+
removeKey(key: KEY): void {
|
|
765
|
+
this.data.delete(key);
|
|
710
766
|
}
|
|
711
767
|
}
|
|
712
768
|
|
package/src/svg/Painter.ts
CHANGED
|
@@ -393,7 +393,7 @@ function createBackgroundVNode(
|
|
|
393
393
|
else {
|
|
394
394
|
const { color, opacity } = normalizeColor(backgroundColor);
|
|
395
395
|
bgVNode.attrs.fill = color;
|
|
396
|
-
opacity < 1 && (bgVNode.attrs
|
|
396
|
+
opacity < 1 && (bgVNode.attrs['fill-opacity'] = opacity);
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
return bgVNode;
|
package/src/svg/graphic.ts
CHANGED
|
@@ -170,12 +170,13 @@ export function brushSVGPath(el: Path, scope: BrushScope) {
|
|
|
170
170
|
builtinShpDef[0](shape, attrs, mul);
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
173
|
+
const needBuildPath = !el.path || el.shapeChanged();
|
|
173
174
|
if (!el.path) {
|
|
174
175
|
el.createPathProxy();
|
|
175
176
|
}
|
|
176
177
|
const path = el.path;
|
|
177
178
|
|
|
178
|
-
if (
|
|
179
|
+
if (needBuildPath) {
|
|
179
180
|
path.beginPath();
|
|
180
181
|
el.buildPath(path, el.shape);
|
|
181
182
|
el.pathUpdated();
|
package/src/zrender.ts
CHANGED
|
@@ -485,7 +485,7 @@ export function registerPainter(name: string, Ctor: PainterBaseCtor) {
|
|
|
485
485
|
/**
|
|
486
486
|
* @type {string}
|
|
487
487
|
*/
|
|
488
|
-
export const version = '5.5.0-dev.
|
|
488
|
+
export const version = '5.5.0-dev.20221130';
|
|
489
489
|
|
|
490
490
|
|
|
491
491
|
export interface ZRenderType extends ZRender {};
|