zrender-nightly 5.4.4-dev.20231115 → 5.4.4-dev.20231117

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.
@@ -26,7 +26,7 @@ import { getLineHeight } from '../contain/text';
26
26
  import TSpan, { TSpanStyleProps } from '../graphic/TSpan';
27
27
  import SVGPathRebuilder from './SVGPathRebuilder';
28
28
  import mapStyleToAttrs from './mapStyleToAttrs';
29
- import { SVGVNodeAttrs, createVNode, SVGVNode, vNodeToString, BrushScope } from './core';
29
+ import { SVGVNodeAttrs, createVNode, SVGVNode, vNodeToString, BrushScope, META_DATA_PREFIX } from './core';
30
30
  import { MatrixArray } from '../core/matrix';
31
31
  import Displayable from '../graphic/Displayable';
32
32
  import { assert, clone, isFunction, isString, logError, map, retrieve2 } from '../core/util';
@@ -39,6 +39,8 @@ import { ImageLike } from '../core/types';
39
39
  import { createCSSAnimation } from './cssAnimation';
40
40
  import { hasSeparateFont, parseFontSize } from '../graphic/Text';
41
41
  import { DEFAULT_FONT, DEFAULT_FONT_FAMILY } from '../core/platform';
42
+ import { createCSSEmphasis } from './cssEmphasis';
43
+ import { getElementSSRData } from '../zrender';
42
44
 
43
45
  const round = Math.round;
44
46
 
@@ -61,6 +63,10 @@ function setStyleAttrs(attrs: SVGVNodeAttrs, style: AllStyleOption, el: Path | T
61
63
  else if (isFillStroke && isPattern(val)) {
62
64
  setPattern(el, attrs, key, scope);
63
65
  }
66
+ else if (isFillStroke && val === 'none') {
67
+ // When is none, it cannot be interacted when ssr
68
+ attrs[key] = 'transparent';
69
+ }
64
70
  else {
65
71
  attrs[key] = val;
66
72
  }
@@ -69,6 +75,19 @@ function setStyleAttrs(attrs: SVGVNodeAttrs, style: AllStyleOption, el: Path | T
69
75
  setShadow(el, attrs, scope);
70
76
  }
71
77
 
78
+ function setMetaData(attrs: SVGVNodeAttrs, el: Path | TSpan | ZRImage) {
79
+ const metaData = getElementSSRData(el);
80
+ if (metaData) {
81
+ metaData.each((val, key) => {
82
+ attrs[(META_DATA_PREFIX + key).toLowerCase()]
83
+ = val + '';
84
+ });
85
+ if (el.isSilent()) {
86
+ attrs[META_DATA_PREFIX + 'silent'] = 'true';
87
+ }
88
+ }
89
+ }
90
+
72
91
  function noRotateScale(m: MatrixArray) {
73
92
  return isAroundZero(m[0] - 1)
74
93
  && isAroundZero(m[1])
@@ -204,8 +223,10 @@ export function brushSVGPath(el: Path, scope: BrushScope) {
204
223
 
205
224
  setTransform(attrs, el.transform);
206
225
  setStyleAttrs(attrs, style, el, scope);
226
+ setMetaData(attrs, el);
207
227
 
208
228
  scope.animation && createCSSAnimation(el, attrs, scope);
229
+ scope.emphasis && createCSSEmphasis(el, attrs, scope);
209
230
 
210
231
  return createVNode(svgElType, el.id + '', attrs);
211
232
  }
@@ -248,6 +269,7 @@ export function brushSVGImage(el: ZRImage, scope: BrushScope) {
248
269
 
249
270
  setTransform(attrs, el.transform);
250
271
  setStyleAttrs(attrs, style, el, scope);
272
+ setMetaData(attrs, el);
251
273
 
252
274
  scope.animation && createCSSAnimation(el, attrs, scope);
253
275
 
@@ -319,6 +341,7 @@ export function brushSVGTSpan(el: TSpan, scope: BrushScope) {
319
341
  }
320
342
  setTransform(attrs, el.transform);
321
343
  setStyleAttrs(attrs, style, el, scope);
344
+ setMetaData(attrs, el);
322
345
 
323
346
  scope.animation && createCSSAnimation(el, attrs, scope);
324
347
 
package/src/tool/color.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import LRU from '../core/LRU';
2
+ import { extend, isGradientObject, isString, map } from '../core/util';
3
+ import { GradientObject } from '../graphic/Gradient';
2
4
 
3
5
  const kCSSColorTable = {
4
6
  'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
@@ -566,4 +568,28 @@ export function random(): string {
566
568
  Math.round(Math.random() * 255),
567
569
  Math.round(Math.random() * 255)
568
570
  ], 'rgb');
569
- }
571
+ }
572
+
573
+ const liftedColorCache = new LRU<string>(100);
574
+ export function liftColor(color: GradientObject): GradientObject;
575
+ export function liftColor(color: string): string;
576
+ export function liftColor(color: string | GradientObject): string | GradientObject {
577
+ if (isString(color)) {
578
+ let liftedColor = liftedColorCache.get(color);
579
+ if (!liftedColor) {
580
+ liftedColor = lift(color, -0.1);
581
+ liftedColorCache.put(color, liftedColor);
582
+ }
583
+ return liftedColor;
584
+ }
585
+ else if (isGradientObject(color)) {
586
+ const ret = extend({}, color) as GradientObject;
587
+ ret.colorStops = map(color.colorStops, stop => ({
588
+ offset: stop.offset,
589
+ color: lift(stop.color, -0.1)
590
+ }));
591
+ return ret;
592
+ }
593
+ // Change nothing.
594
+ return color;
595
+ }
package/src/zrender.ts CHANGED
@@ -482,10 +482,27 @@ export function registerPainter(name: string, Ctor: PainterBaseCtor) {
482
482
  painterCtors[name] = Ctor;
483
483
  }
484
484
 
485
+ export type ElementSSRData = zrUtil.HashMap<unknown>;
486
+ export type ElementSSRDataGetter<T> = (el: Element) => zrUtil.HashMap<T>;
487
+
488
+ let ssrDataGetter = function (el: Element): ElementSSRData {
489
+ return null;
490
+ }
491
+
492
+ export function getElementSSRData(el: Element): ElementSSRData {
493
+ if (typeof ssrDataGetter === 'function') {
494
+ return ssrDataGetter(el);
495
+ }
496
+ }
497
+
498
+ export function registerSSRDataGetter<T>(getter: ElementSSRDataGetter<T>) {
499
+ ssrDataGetter = getter;
500
+ }
501
+
485
502
  /**
486
503
  * @type {string}
487
504
  */
488
- export const version = '5.4.4-dev.20231115';
505
+ export const version = '5.4.4-dev.20231117';
489
506
 
490
507
 
491
508
  export interface ZRenderType extends ZRender {};