@antv/g 5.0.24 → 5.1.0

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.
Files changed (132) hide show
  1. package/dist/index.umd.min.js +2 -2
  2. package/es/Canvas.js +2 -0
  3. package/es/css/CSSProperty.d.ts +2 -1
  4. package/es/css/StyleValueRegistry.d.ts +2 -1
  5. package/es/css/StyleValueRegistry.js +68 -72
  6. package/es/css/parser/color.d.ts +1 -1
  7. package/es/css/parser/color.js +2 -2
  8. package/es/css/parser/dimension.js +5 -1
  9. package/es/css/parser/path.d.ts +2 -2
  10. package/es/css/parser/path.js +9 -2
  11. package/es/css/parser/points.d.ts +8 -1
  12. package/es/css/parser/points.js +33 -3
  13. package/es/css/parser/transform.js +1 -1
  14. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  15. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  16. package/es/css/properties/CSSPropertyLocalPosition.js +64 -20
  17. package/es/css/properties/CSSPropertyPath.d.ts +2 -2
  18. package/es/css/properties/CSSPropertyPath.js +7 -5
  19. package/es/css/properties/CSSPropertyPoints.js +3 -4
  20. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  21. package/es/css/properties/CSSPropertyTransform.js +76 -104
  22. package/es/display-objects/Circle.d.ts +4 -0
  23. package/es/display-objects/Circle.js +2 -0
  24. package/es/display-objects/DisplayObject.d.ts +1 -7
  25. package/es/display-objects/DisplayObject.js +6 -26
  26. package/es/display-objects/Ellipse.d.ts +4 -0
  27. package/es/display-objects/Ellipse.js +2 -0
  28. package/es/display-objects/Group.d.ts +4 -0
  29. package/es/display-objects/Group.js +2 -0
  30. package/es/display-objects/HTML.d.ts +4 -4
  31. package/es/display-objects/HTML.js +5 -3
  32. package/es/display-objects/Image.d.ts +4 -0
  33. package/es/display-objects/Image.js +2 -0
  34. package/es/display-objects/Line.js +2 -0
  35. package/es/display-objects/Path.d.ts +2 -2
  36. package/es/display-objects/Polygon.js +1 -1
  37. package/es/display-objects/Polyline.js +1 -1
  38. package/es/display-objects/Rect.d.ts +6 -2
  39. package/es/display-objects/Rect.js +2 -0
  40. package/es/display-objects/Text.d.ts +4 -0
  41. package/es/display-objects/Text.js +2 -0
  42. package/es/dom/Element.js +1 -0
  43. package/es/services/EventService.js +10 -2
  44. package/es/services/SceneGraphService.d.ts +2 -0
  45. package/es/services/SceneGraphService.js +9 -0
  46. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  47. package/es/services/aabb/CircleUpdater.js +2 -6
  48. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  49. package/es/services/aabb/EllipseUpdater.js +2 -6
  50. package/es/services/aabb/LineUpdater.d.ts +0 -2
  51. package/es/services/aabb/LineUpdater.js +1 -3
  52. package/es/services/aabb/PathUpdater.d.ts +0 -2
  53. package/es/services/aabb/PathUpdater.js +1 -5
  54. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  55. package/es/services/aabb/PolylineUpdater.js +1 -3
  56. package/es/services/aabb/RectUpdater.d.ts +0 -2
  57. package/es/services/aabb/RectUpdater.js +1 -5
  58. package/es/services/aabb/TextUpdater.d.ts +7 -0
  59. package/es/services/aabb/TextUpdater.js +0 -4
  60. package/es/services/aabb/interfaces.d.ts +0 -3
  61. package/es/types.d.ts +6 -19
  62. package/es/types.js +1 -0
  63. package/es/utils/interpolation.js +2 -8
  64. package/es/utils/math.js +4 -3
  65. package/es/utils/path.d.ts +2 -2
  66. package/es/utils/path.js +61 -24
  67. package/lib/Canvas.js +2 -0
  68. package/lib/css/CSSProperty.d.ts +2 -1
  69. package/lib/css/StyleValueRegistry.d.ts +2 -1
  70. package/lib/css/StyleValueRegistry.js +67 -71
  71. package/lib/css/parser/color.d.ts +1 -1
  72. package/lib/css/parser/color.js +1 -1
  73. package/lib/css/parser/dimension.js +4 -0
  74. package/lib/css/parser/path.d.ts +2 -2
  75. package/lib/css/parser/path.js +9 -2
  76. package/lib/css/parser/points.d.ts +8 -1
  77. package/lib/css/parser/points.js +33 -3
  78. package/lib/css/parser/transform.js +1 -1
  79. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  80. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  81. package/lib/css/properties/CSSPropertyLocalPosition.js +65 -20
  82. package/lib/css/properties/CSSPropertyPath.d.ts +2 -2
  83. package/lib/css/properties/CSSPropertyPath.js +7 -5
  84. package/lib/css/properties/CSSPropertyPoints.js +3 -4
  85. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  86. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  87. package/lib/display-objects/Circle.d.ts +4 -0
  88. package/lib/display-objects/Circle.js +2 -0
  89. package/lib/display-objects/DisplayObject.d.ts +1 -7
  90. package/lib/display-objects/DisplayObject.js +6 -27
  91. package/lib/display-objects/Ellipse.d.ts +4 -0
  92. package/lib/display-objects/Ellipse.js +2 -0
  93. package/lib/display-objects/Group.d.ts +4 -0
  94. package/lib/display-objects/Group.js +2 -0
  95. package/lib/display-objects/HTML.d.ts +4 -4
  96. package/lib/display-objects/HTML.js +5 -3
  97. package/lib/display-objects/Image.d.ts +4 -0
  98. package/lib/display-objects/Image.js +2 -0
  99. package/lib/display-objects/Line.js +2 -0
  100. package/lib/display-objects/Path.d.ts +2 -2
  101. package/lib/display-objects/Polygon.js +1 -1
  102. package/lib/display-objects/Polyline.js +1 -1
  103. package/lib/display-objects/Rect.d.ts +6 -2
  104. package/lib/display-objects/Rect.js +2 -0
  105. package/lib/display-objects/Text.d.ts +4 -0
  106. package/lib/display-objects/Text.js +2 -0
  107. package/lib/dom/Element.js +1 -0
  108. package/lib/services/EventService.js +10 -2
  109. package/lib/services/SceneGraphService.d.ts +2 -0
  110. package/lib/services/SceneGraphService.js +12 -0
  111. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  112. package/lib/services/aabb/CircleUpdater.js +2 -6
  113. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  114. package/lib/services/aabb/EllipseUpdater.js +2 -6
  115. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  116. package/lib/services/aabb/LineUpdater.js +1 -3
  117. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  118. package/lib/services/aabb/PathUpdater.js +1 -5
  119. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  120. package/lib/services/aabb/PolylineUpdater.js +1 -3
  121. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  122. package/lib/services/aabb/RectUpdater.js +1 -5
  123. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  124. package/lib/services/aabb/TextUpdater.js +0 -4
  125. package/lib/services/aabb/interfaces.d.ts +0 -3
  126. package/lib/types.d.ts +6 -19
  127. package/lib/types.js +1 -0
  128. package/lib/utils/interpolation.js +2 -8
  129. package/lib/utils/math.js +4 -3
  130. package/lib/utils/path.d.ts +2 -2
  131. package/lib/utils/path.js +55 -24
  132. package/package.json +3 -3
package/es/Canvas.js CHANGED
@@ -94,6 +94,8 @@ function (_super) {
94
94
  /**
95
95
  * limits query
96
96
  */
97
+ // the following feature-detect from hammer.js
98
+ // @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
97
99
 
98
100
  _this.supportTouchEvent = supportTouchEvent !== null && supportTouchEvent !== void 0 ? supportTouchEvent : 'ontouchstart' in globalThis;
99
101
  _this.supportPointerEvent = supportPointerEvent !== null && supportPointerEvent !== void 0 ? supportPointerEvent : !!globalThis.PointerEvent;
@@ -1,8 +1,9 @@
1
+ import type { DisplayObject } from '../display-objects';
1
2
  import type { IElement } from '../dom';
2
3
  import type { StyleValueRegistry } from './interfaces';
3
4
  export declare type Interpolatable = number | boolean | number[] | boolean[];
4
5
  declare type CSSPropertyMixer<Parsed = any, T extends Interpolatable = any> = (left: Parsed, right: Parsed, displayObject: IElement | null) => [T, T, (i: T) => string | any] | undefined;
5
- declare type CSSPropertyParser<Parsed> = (value: string | any) => Parsed;
6
+ declare type CSSPropertyParser<Parsed> = (value: string | any, object: DisplayObject) => Parsed;
6
7
  declare type CSSPropertyCalculator<Parsed, Used> = (name: string, oldParsed: Parsed, parsed: Parsed, object: IElement, registry: StyleValueRegistry) => Used;
7
8
  /**
8
9
  * 1. parser: raw CSS string -> Computed Value
@@ -14,6 +14,7 @@ export declare const PropertySyntax: {
14
14
  LENGTH: string;
15
15
  PERCENTAGE: string;
16
16
  LENGTH_PERCENTAGE: string;
17
+ LIST_OF_POINTS: string;
17
18
  };
18
19
  export interface PropertyMetadata {
19
20
  name: string;
@@ -99,7 +100,7 @@ export declare class DefaultStyleValueRegistry implements StyleValueRegistry {
99
100
  /**
100
101
  * string -> parsed value
101
102
  */
102
- parseProperty(name: string, value: any): CSSStyleValue;
103
+ parseProperty(name: string, value: any, object: DisplayObject): CSSStyleValue;
103
104
  /**
104
105
  * computed value -> used value
105
106
  */
@@ -8,7 +8,7 @@ import { Shape } from '../types';
8
8
  import { CSSKeywordValue, CSSStyleValue, CSSUnitValue } from './cssom';
9
9
  import { convertPercentUnit } from './parser';
10
10
  import { CSSPropertyLocalPosition, CSSPropertyOpacity, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLineDash, CSSPropertyShadowBlur, CSSPropertyOffsetPath, CSSPropertyOffsetDistance, CSSPropertyAnchor, CSSPropertyZIndex, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyPath, CSSPropertyClipPath, CSSPropertyPoints, CSSPropertyText, CSSPropertyTextTransform } from './properties';
11
- import { formatAttribute } from '../utils';
11
+ import { formatAttribute, isNil } from '../utils';
12
12
  import { AABB } from '../shapes';
13
13
  import { StyleValueRegistry } from './interfaces';
14
14
  export var PropertySyntax = {
@@ -17,7 +17,8 @@ export var PropertySyntax = {
17
17
  NUMBER: '<number>',
18
18
  LENGTH: '<length>',
19
19
  PERCENTAGE: '<percentage>',
20
- LENGTH_PERCENTAGE: '<length> | <percentage>'
20
+ LENGTH_PERCENTAGE: '<length> | <percentage>',
21
+ LIST_OF_POINTS: '<list-of-points>'
21
22
  };
22
23
  /**
23
24
  * Blink used them in code generation(css_properties.json5)
@@ -30,29 +31,6 @@ export var BUILT_IN_PROPERTIES = [{
30
31
  */
31
32
  name: 'display',
32
33
  keywords: ['none']
33
- }, {
34
- // x in local space
35
- name: 'x',
36
- interpolable: true,
37
- alias: ['cx'],
38
- defaultValue: '0',
39
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
40
- handler: CSSPropertyLocalPosition
41
- }, {
42
- // y in local space
43
- name: 'y',
44
- interpolable: true,
45
- alias: ['cy'],
46
- defaultValue: '0',
47
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
48
- handler: CSSPropertyLocalPosition
49
- }, {
50
- // z in local space
51
- name: 'z',
52
- interpolable: true,
53
- defaultValue: '0',
54
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
55
- handler: CSSPropertyLocalPosition
56
34
  }, {
57
35
  /**
58
36
  * range [0.0, 1.0]
@@ -225,6 +203,7 @@ export var BUILT_IN_PROPERTIES = [{
225
203
  handler: CSSPropertyClipPath
226
204
  }, {
227
205
  name: 'transform',
206
+ parsePriority: 100,
228
207
  interpolable: true,
229
208
  keywords: ['none'],
230
209
  defaultValue: 'none',
@@ -241,8 +220,20 @@ export var BUILT_IN_PROPERTIES = [{
241
220
  parsePriority: 99,
242
221
  layoutDependent: true,
243
222
  handler: CSSPropertyAnchor
244
- }, // Circle
223
+ }, // <circle> & <ellipse>
245
224
  {
225
+ name: 'cx',
226
+ interpolable: true,
227
+ defaultValue: '0',
228
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
229
+ handler: CSSPropertyLocalPosition
230
+ }, {
231
+ name: 'cy',
232
+ interpolable: true,
233
+ defaultValue: '0',
234
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
235
+ handler: CSSPropertyLocalPosition
236
+ }, {
246
237
  name: 'r',
247
238
  interpolable: true,
248
239
  layoutDependent: true,
@@ -260,8 +251,29 @@ export var BUILT_IN_PROPERTIES = [{
260
251
  layoutDependent: true,
261
252
  defaultValue: 'auto',
262
253
  handler: CSSPropertyLengthOrPercentage
263
- }, // Rect Image
254
+ }, // Rect Image Group
264
255
  {
256
+ // x in local space
257
+ name: 'x',
258
+ interpolable: true,
259
+ defaultValue: '0',
260
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
261
+ handler: CSSPropertyLocalPosition
262
+ }, {
263
+ // y in local space
264
+ name: 'y',
265
+ interpolable: true,
266
+ defaultValue: '0',
267
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
268
+ handler: CSSPropertyLocalPosition
269
+ }, {
270
+ // z in local space
271
+ name: 'z',
272
+ interpolable: true,
273
+ defaultValue: '0',
274
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
275
+ handler: CSSPropertyLocalPosition
276
+ }, {
265
277
  name: 'width',
266
278
  interpolable: true,
267
279
  layoutDependent: true,
@@ -326,11 +338,13 @@ export var BUILT_IN_PROPERTIES = [{
326
338
  interpolable: true,
327
339
  layoutDependent: true,
328
340
  defaultValue: '',
341
+ alias: ['d'],
329
342
  handler: CSSPropertyPath
330
- }, // Polyline
343
+ }, // Polyline & Polygon
331
344
  {
332
345
  name: 'points',
333
346
  layoutDependent: true,
347
+ syntax: PropertySyntax.LIST_OF_POINTS,
334
348
  handler: CSSPropertyPoints
335
349
  }, // Text
336
350
  {
@@ -526,7 +540,7 @@ function () {
526
540
 
527
541
  if (!skipParse) {
528
542
  sortedNames.forEach(function (name) {
529
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name]);
543
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object);
530
544
  });
531
545
  }
532
546
 
@@ -570,11 +584,11 @@ function () {
570
584
  */
571
585
 
572
586
 
573
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value) {
587
+ DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object) {
574
588
  var metadata = this.getMetadata(name);
575
589
  var computed = value;
576
590
 
577
- if (value === '') {
591
+ if (value === '' || isNil(value)) {
578
592
  value = 'unset';
579
593
  }
580
594
 
@@ -593,7 +607,7 @@ function () {
593
607
 
594
608
  if (propertyHandler && propertyHandler.parser) {
595
609
  // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
596
- computed = propertyHandler.parser(value);
610
+ computed = propertyHandler.parser(value, object);
597
611
  }
598
612
  }
599
613
  }
@@ -632,8 +646,8 @@ function () {
632
646
 
633
647
  if (value === 'initial') {
634
648
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
635
- if (defaultValue) {
636
- computed = this.parseProperty(name, defaultValue);
649
+ if (!isNil(defaultValue)) {
650
+ computed = this.parseProperty(name, defaultValue, object);
637
651
  }
638
652
  } else if (value === 'inherit') {
639
653
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
@@ -770,41 +784,23 @@ function () {
770
784
  height = _b.height,
771
785
  _c = _b.depth,
772
786
  depth = _c === void 0 ? 0 : _c,
773
- _d = _b.x,
774
- x = _d === void 0 ? 0 : _d,
775
- _e = _b.y,
776
- y = _e === void 0 ? 0 : _e,
777
- // z = 0,
778
- _f = _b.offsetX,
779
- // z = 0,
780
- offsetX = _f === void 0 ? 0 : _f,
781
- _g = _b.offsetY,
782
- offsetY = _g === void 0 ? 0 : _g,
783
- _h = _b.offsetZ,
784
- offsetZ = _h === void 0 ? 0 : _h;
785
-
786
- if (object.nodeName === Shape.LINE || object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH) {
787
- parsedStyle.offsetX = x - (parsedStyle.defX || 0);
788
- parsedStyle.offsetY = y - (parsedStyle.defY || 0);
789
- parsedStyle.defX = x;
790
- parsedStyle.defY = y; // modify x/y/z
791
-
792
- object.attributes.x += parsedStyle.offsetX;
793
- object.attributes.y += parsedStyle.offsetY;
794
- parsedStyle.x = parsedStyle.x.add(new CSSUnitValue(parsedStyle.offsetX, 'px'));
795
- parsedStyle.y = parsedStyle.y.add(new CSSUnitValue(parsedStyle.offsetY, 'px'));
796
- } // init with content box
787
+ _d = _b.offsetX,
788
+ offsetX = _d === void 0 ? 0 : _d,
789
+ _e = _b.offsetY,
790
+ offsetY = _e === void 0 ? 0 : _e,
791
+ _f = _b.offsetZ,
792
+ offsetZ = _f === void 0 ? 0 : _f; // init with content box
797
793
 
798
794
 
799
795
  var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
800
796
 
801
- var _j = parsedStyle,
802
- lineWidth = _j.lineWidth,
803
- increasedLineWidthForHitTesting = _j.increasedLineWidthForHitTesting,
804
- shadowColor = _j.shadowColor,
805
- _k = _j.filter,
806
- filter = _k === void 0 ? [] : _k,
807
- transformOrigin = _j.transformOrigin;
797
+ var _g = parsedStyle,
798
+ lineWidth = _g.lineWidth,
799
+ increasedLineWidthForHitTesting = _g.increasedLineWidthForHitTesting,
800
+ shadowColor = _g.shadowColor,
801
+ _h = _g.filter,
802
+ filter = _h === void 0 ? [] : _h,
803
+ transformOrigin = _g.transformOrigin;
808
804
  var anchor = parsedStyle.anchor; // <Text> use textAlign & textBaseline instead of anchor
809
805
 
810
806
  if (object.nodeName === Shape.TEXT) {
@@ -820,13 +816,13 @@ function () {
820
816
  geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
821
817
 
822
818
  if (shadowColor) {
823
- var _l = geometry_1.renderBounds,
824
- min = _l.min,
825
- max = _l.max;
826
- var _m = parsedStyle,
827
- shadowBlur = _m.shadowBlur,
828
- shadowOffsetX = _m.shadowOffsetX,
829
- shadowOffsetY = _m.shadowOffsetY;
819
+ var _j = geometry_1.renderBounds,
820
+ min = _j.min,
821
+ max = _j.max;
822
+ var _k = parsedStyle,
823
+ shadowBlur = _k.shadowBlur,
824
+ shadowOffsetX = _k.shadowOffsetX,
825
+ shadowOffsetY = _k.shadowOffsetY;
830
826
  var shadowBlurInPixels = shadowBlur && shadowBlur.value || 0;
831
827
  var shadowOffsetXInPixels = shadowOffsetX && shadowOffsetX.value || 0;
832
828
  var shadowOffsetYInPixels = shadowOffsetY && shadowOffsetY.value || 0;
@@ -2,5 +2,5 @@ import { CSSRGB, CSSGradientValue } from '../cssom';
2
2
  /**
3
3
  * @see https://github.com/WebKit/WebKit/blob/main/Source/WebCore/css/parser/CSSParser.cpp#L97
4
4
  */
5
- export declare function parseColor(colorStr?: string): CSSRGB | CSSGradientValue;
5
+ export declare function parseColor(colorStr: string): CSSRGB | CSSGradientValue;
6
6
  export declare function mergeColors(left: CSSRGB | CSSGradientValue, right: CSSRGB | CSSGradientValue): [number[], number[], (color: number[]) => string] | undefined;
@@ -1,7 +1,7 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import * as d3 from 'd3-color';
3
3
  import { CSSRGB, CSSGradientValue, GradientPatternType } from '../cssom';
4
- import { clamp, isString } from '../../utils';
4
+ import { clamp, isNil, isString } from '../../utils';
5
5
  var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
6
6
  var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
7
7
  var regexPR = /^p\s*\(\s*([axyn])\s*\)\s*(.*)/i;
@@ -11,7 +11,7 @@ var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
11
11
  */
12
12
 
13
13
  export function parseColor(colorStr) {
14
- if (colorStr === void 0) {
14
+ if (isNil(colorStr)) {
15
15
  colorStr = '';
16
16
  }
17
17
 
@@ -1,8 +1,12 @@
1
1
  import { AABB } from '../../shapes';
2
- import { isString, rad2deg, turn2deg } from '../../utils';
2
+ import { isNil, isString, rad2deg, turn2deg } from '../../utils';
3
3
  import { UnitType } from '../cssom';
4
4
  import { CSSUnitValue } from '../cssom';
5
5
  export function parseDimension(unitRegExp, string) {
6
+ if (isNil(string)) {
7
+ return new CSSUnitValue(0, 'px');
8
+ }
9
+
6
10
  string = "".concat(string).trim().toLowerCase();
7
11
 
8
12
  if (isFinite(Number(string))) {
@@ -1,5 +1,5 @@
1
1
  import type { PathCommand } from '../../types';
2
- import type { ParsedPathStyleProps } from '../../display-objects';
2
+ import type { ParsedPathStyleProps, DisplayObject } from '../../display-objects';
3
3
  import type { IElement } from '../../dom';
4
- export declare function parsePath(path: string): ParsedPathStyleProps['path'];
4
+ export declare function parsePath(path: string, object: DisplayObject): ParsedPathStyleProps['path'];
5
5
  export declare function mergePaths(left: ParsedPathStyleProps['path'], right: ParsedPathStyleProps['path'], object: IElement): [PathCommand[], PathCommand[], (b: PathCommand[]) => PathCommand[]];
@@ -3,7 +3,7 @@ import { path2Absolute, path2Segments, path2Curve } from '@antv/util';
3
3
  import { Cubic as CubicUtil } from '@antv/g-math';
4
4
  import { clonePath, equalizeSegments, getDrawDirection, getRotatedCurve, reverseCurve } from '../../utils/path';
5
5
  import { Rectangle } from '../../shapes/Rectangle';
6
- export function parsePath(path) {
6
+ export function parsePath(path, object) {
7
7
  var absolutePath = path2Absolute(path);
8
8
  var hasArc = hasArcOrBezier(absolutePath);
9
9
  var clonedAbsolutePath = absolutePath.slice();
@@ -24,6 +24,13 @@ export function parsePath(path) {
24
24
  totalLength = _c.totalLength,
25
25
  curveSegments = _c.curveSegments;
26
26
 
27
+ var rect = getPathBBox(curve);
28
+
29
+ if (object) {
30
+ object.parsedStyle.defX = rect.x;
31
+ object.parsedStyle.defY = rect.y;
32
+ }
33
+
27
34
  return {
28
35
  absolutePath: absolutePath,
29
36
  hasArc: hasArc,
@@ -34,7 +41,7 @@ export function parsePath(path) {
34
41
  totalLength: totalLength,
35
42
  curveSegments: curveSegments,
36
43
  zCommandIndexes: zCommandIndexes,
37
- rect: getPathBBox(curve)
44
+ rect: rect
38
45
  };
39
46
  }
40
47
 
@@ -1,4 +1,11 @@
1
- export declare function parsePoints(points: string | [number, number][]): {
1
+ import type { DisplayObject } from '../..';
2
+ /**
3
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
4
+ *
5
+ * @example
6
+ * points="100,10 250,150 200,110"
7
+ */
8
+ export declare function parsePoints(pointsOrStr: string | [number, number][], object: DisplayObject): {
2
9
  points: [number, number][];
3
10
  totalLength: number;
4
11
  segments: [number, number][];
@@ -1,8 +1,26 @@
1
+ import { __read, __spreadArray } from "tslib";
1
2
  import { Line as LineUtil, Polyline as PolylineUtil } from '@antv/g-math';
2
3
  import { isString } from '../../utils';
3
- export function parsePoints(points) {
4
- if (isString(points)) {
5
- return null;
4
+ /**
5
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
6
+ *
7
+ * @example
8
+ * points="100,10 250,150 200,110"
9
+ */
10
+
11
+ export function parsePoints(pointsOrStr, object) {
12
+ var points;
13
+
14
+ if (isString(pointsOrStr)) {
15
+ points = pointsOrStr.split(' ').map(function (pointStr) {
16
+ var _a = __read(pointStr.split(','), 2),
17
+ x = _a[0],
18
+ y = _a[1];
19
+
20
+ return [Number(x), Number(y)];
21
+ });
22
+ } else {
23
+ points = pointsOrStr;
6
24
  }
7
25
 
8
26
  var segments = [];
@@ -20,6 +38,18 @@ export function parsePoints(points) {
20
38
  segments.push(segmentT);
21
39
  }
22
40
  });
41
+ var minX = Math.min.apply(Math, __spreadArray([], __read(points.map(function (point) {
42
+ return point[0];
43
+ })), false));
44
+ var minY = Math.min.apply(Math, __spreadArray([], __read(points.map(function (point) {
45
+ return point[1];
46
+ })), false));
47
+
48
+ if (object) {
49
+ object.parsedStyle.defX = minX;
50
+ object.parsedStyle.defY = minY;
51
+ }
52
+
23
53
  return {
24
54
  points: points,
25
55
  totalLength: totalLength,
@@ -50,7 +50,7 @@ var transformFunctions = {
50
50
  */
51
51
 
52
52
  export function parseTransform(string) {
53
- string = string.toLowerCase().trim();
53
+ string = (string || 'none').toLowerCase().trim();
54
54
 
55
55
  if (string === 'none') {
56
56
  return [];
@@ -1,6 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { dirtifyToRoot } from '../../services';
4
+ import { CSSKeywordValue } from '../cssom';
4
5
  /**
5
6
  * @see /zh/docs/api/basic/display-object#clippath
6
7
  * @example
@@ -25,7 +26,12 @@ function () {
25
26
  function CSSPropertyClipPath() {}
26
27
 
27
28
  CSSPropertyClipPath.prototype.calculator = function (name, oldClipPath, newClipPath, object) {
28
- // clear ref to old clip path
29
+ // unset
30
+ if (newClipPath instanceof CSSKeywordValue) {
31
+ newClipPath = null;
32
+ } // clear ref to old clip path
33
+
34
+
29
35
  if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.style.clipPathTargets) {
30
36
  var index = oldClipPath.style.clipPathTargets.indexOf(object);
31
37
  oldClipPath.style.clipPathTargets.splice(index, 1);
@@ -1,20 +1,11 @@
1
1
  import type { DisplayObject } from '../../display-objects';
2
2
  import type { CSSProperty } from '../CSSProperty';
3
3
  import type { CSSUnitValue } from '../cssom';
4
- import { mergeDimensions } from '../parser';
5
4
  import { CSSPropertyLengthOrPercentage } from './CSSPropertyLengthOrPercentage';
6
5
  /**
7
6
  * local position
8
7
  */
9
8
  export declare class CSSPropertyLocalPosition extends CSSPropertyLengthOrPercentage implements Partial<CSSProperty<CSSUnitValue, CSSUnitValue>> {
10
- /**
11
- * <length> & <percentage>
12
- */
13
- parser: (css: string) => CSSUnitValue;
14
- /**
15
- * mix between CSS.px(x)
16
- */
17
- mixer: typeof mergeDimensions;
18
9
  /**
19
10
  * update local position
20
11
  */
@@ -1,7 +1,8 @@
1
- import { __decorate, __extends } from "tslib";
1
+ import { __decorate, __extends, __read } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
- import { mergeDimensions, parseLengthOrPercentage } from '../parser';
4
3
  import { CSSPropertyLengthOrPercentage } from './CSSPropertyLengthOrPercentage';
4
+ import { isNil } from '../../utils';
5
+ import { Shape } from '../../types';
5
6
  /**
6
7
  * local position
7
8
  */
@@ -12,19 +13,7 @@ function (_super) {
12
13
  __extends(CSSPropertyLocalPosition, _super);
13
14
 
14
15
  function CSSPropertyLocalPosition() {
15
- var _this = _super !== null && _super.apply(this, arguments) || this;
16
- /**
17
- * <length> & <percentage>
18
- */
19
-
20
-
21
- _this.parser = parseLengthOrPercentage;
22
- /**
23
- * mix between CSS.px(x)
24
- */
25
-
26
- _this.mixer = mergeDimensions;
27
- return _this;
16
+ return _super !== null && _super.apply(this, arguments) || this;
28
17
  }
29
18
  /**
30
19
  * update local position
@@ -32,11 +21,66 @@ function (_super) {
32
21
 
33
22
 
34
23
  CSSPropertyLocalPosition.prototype.postProcessor = function (object) {
35
- var _a = object.parsedStyle,
36
- x = _a.x,
37
- y = _a.y,
38
- z = _a.z;
39
- object.setLocalPosition(x && x.value || 0, y && y.value || 0, z && z.value || 0);
24
+ var x;
25
+ var y;
26
+ var z;
27
+
28
+ switch (object.nodeName) {
29
+ case Shape.CIRCLE:
30
+ case Shape.ELLIPSE:
31
+ var _a = object.parsedStyle,
32
+ cx = _a.cx,
33
+ cy = _a.cy;
34
+
35
+ if (!isNil(cx)) {
36
+ x = cx.value;
37
+ }
38
+
39
+ if (!isNil(cy)) {
40
+ y = cy.value;
41
+ }
42
+
43
+ break;
44
+
45
+ case Shape.RECT:
46
+ case Shape.GROUP:
47
+ case Shape.IMAGE:
48
+ case Shape.HTML:
49
+ case Shape.TEXT:
50
+ case Shape.MESH:
51
+ if (!isNil(object.parsedStyle.x)) {
52
+ x = object.parsedStyle.x.value;
53
+ }
54
+
55
+ if (!isNil(object.parsedStyle.y)) {
56
+ y = object.parsedStyle.y.value;
57
+ }
58
+
59
+ break;
60
+
61
+ case Shape.LINE:
62
+ var _b = object.parsedStyle,
63
+ x1 = _b.x1,
64
+ x2 = _b.x2,
65
+ y1 = _b.y1,
66
+ y2 = _b.y2;
67
+ var minX = Math.min(x1.value, x2.value);
68
+ var minY = Math.min(y1.value, y2.value);
69
+ x = minX;
70
+ y = minY;
71
+ z = 0;
72
+ break;
73
+ }
74
+
75
+ object.parsedStyle.defX = x || 0;
76
+ object.parsedStyle.defY = y || 0;
77
+
78
+ var _c = __read(object.getLocalPosition(), 3),
79
+ ox = _c[0],
80
+ oy = _c[1],
81
+ oz = _c[2];
82
+
83
+ object.setLocalPosition(isNil(x) ? ox : x, isNil(y) ? oy : y, isNil(z) ? oz : z);
40
84
  };
41
85
 
42
86
  CSSPropertyLocalPosition = __decorate([singleton()], CSSPropertyLocalPosition);
@@ -8,12 +8,12 @@ export declare class CSSPropertyPath implements Partial<CSSProperty<ParsedPathSt
8
8
  */
9
9
  parser: typeof parsePath;
10
10
  calculator(name: string, oldParsed: ParsedPathStyleProps['path'], parsed: ParsedPathStyleProps['path']): {
11
- absolutePath: import("../../types").PathCommand[];
11
+ absolutePath: import("../..").PathCommand[];
12
12
  hasArc: boolean;
13
13
  segments: import("../../display-objects").PathSegment[];
14
14
  polygons: [number, number][][];
15
15
  polylines: [number, number][][];
16
- curve: import("../../types").PathCommand[];
16
+ curve: import("../..").PathCommand[];
17
17
  totalLength: number;
18
18
  curveSegments: number[][];
19
19
  zCommandIndexes: number[];
@@ -16,7 +16,8 @@ function () {
16
16
  }
17
17
 
18
18
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
19
- if (parsed instanceof CSSKeywordValue) {
19
+ // unset
20
+ if (parsed instanceof CSSKeywordValue && parsed.value === 'unset') {
20
21
  return {
21
22
  absolutePath: [],
22
23
  hasArc: false,
@@ -40,10 +41,11 @@ function () {
40
41
 
41
42
  CSSPropertyPath.prototype.postProcessor = function (object) {
42
43
  var _a = object.parsedStyle,
43
- x = _a.x,
44
- y = _a.y,
45
- z = _a.z;
46
- object.setLocalPosition(x && x.value || 0, y && y.value || 0, z && z.value || 0);
44
+ _b = _a.defX,
45
+ defX = _b === void 0 ? 0 : _b,
46
+ _c = _a.defY,
47
+ defY = _c === void 0 ? 0 : _c;
48
+ object.setLocalPosition(defX, defY);
47
49
  };
48
50
 
49
51
  CSSPropertyPath = __decorate([singleton()], CSSPropertyPath);
@@ -15,10 +15,9 @@ function () {
15
15
 
16
16
  CSSPropertyPoints.prototype.postProcessor = function (object) {
17
17
  var _a = object.parsedStyle,
18
- x = _a.x,
19
- y = _a.y,
20
- z = _a.z;
21
- object.setLocalPosition(x && x.value || 0, y && y.value || 0, z && z.value || 0);
18
+ defX = _a.defX,
19
+ defY = _a.defY;
20
+ object.setLocalPosition(defX, defY);
22
21
  };
23
22
 
24
23
  CSSPropertyPoints = __decorate([singleton()], CSSPropertyPoints);
@@ -34,5 +34,5 @@ import { parseTransform, mergeTransforms } from '../parser';
34
34
  export declare class CSSPropertyTransform implements Partial<CSSProperty<any[], any[]>> {
35
35
  parser: typeof parseTransform;
36
36
  mixer: typeof mergeTransforms;
37
- calculator(name: string, oldValue: any[], newValue: any[], object: DisplayObject): any[];
37
+ postProcessor(object: DisplayObject): void;
38
38
  }