@antv/g 5.0.24 → 5.1.2

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 (168) hide show
  1. package/dist/index.umd.min.js +2 -2
  2. package/es/Canvas.js +2 -0
  3. package/es/css/CSS.d.ts +4 -2
  4. package/es/css/CSS.js +6 -2
  5. package/es/css/CSSProperty.d.ts +2 -1
  6. package/es/css/StyleValueRegistry.d.ts +24 -55
  7. package/es/css/StyleValueRegistry.js +120 -138
  8. package/es/css/interfaces.d.ts +110 -0
  9. package/es/css/interfaces.js +75 -0
  10. package/es/css/parser/color.d.ts +1 -1
  11. package/es/css/parser/color.js +2 -2
  12. package/es/css/parser/dimension.js +5 -1
  13. package/es/css/parser/path.d.ts +2 -2
  14. package/es/css/parser/path.js +9 -2
  15. package/es/css/parser/points.d.ts +8 -1
  16. package/es/css/parser/points.js +33 -3
  17. package/es/css/parser/transform.js +1 -1
  18. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  19. package/es/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -2
  20. package/es/css/properties/CSSPropertyLengthOrPercentage.js +34 -14
  21. package/es/css/properties/CSSPropertyLengthOrPercentage12.d.ts +15 -0
  22. package/es/css/properties/CSSPropertyLengthOrPercentage12.js +38 -0
  23. package/es/css/properties/CSSPropertyLengthOrPercentage14.d.ts +25 -0
  24. package/es/css/properties/CSSPropertyLengthOrPercentage14.js +42 -0
  25. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  26. package/es/css/properties/CSSPropertyLocalPosition.js +59 -20
  27. package/es/css/properties/CSSPropertyPath.d.ts +3 -3
  28. package/es/css/properties/CSSPropertyPath.js +11 -6
  29. package/es/css/properties/CSSPropertyPoints.js +7 -5
  30. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  31. package/es/css/properties/CSSPropertyTransform.js +76 -104
  32. package/es/css/properties/index.d.ts +2 -2
  33. package/es/css/properties/index.js +2 -2
  34. package/es/display-objects/Circle.d.ts +4 -0
  35. package/es/display-objects/Circle.js +2 -0
  36. package/es/display-objects/CustomElement.d.ts +6 -2
  37. package/es/display-objects/CustomElement.js +15 -5
  38. package/es/display-objects/DisplayObject.d.ts +1 -7
  39. package/es/display-objects/DisplayObject.js +6 -26
  40. package/es/display-objects/Ellipse.d.ts +4 -0
  41. package/es/display-objects/Ellipse.js +2 -0
  42. package/es/display-objects/Group.d.ts +4 -0
  43. package/es/display-objects/Group.js +2 -0
  44. package/es/display-objects/HTML.d.ts +4 -4
  45. package/es/display-objects/HTML.js +5 -3
  46. package/es/display-objects/Image.d.ts +4 -0
  47. package/es/display-objects/Image.js +2 -0
  48. package/es/display-objects/Line.js +2 -0
  49. package/es/display-objects/Polygon.js +1 -1
  50. package/es/display-objects/Polyline.js +1 -1
  51. package/es/display-objects/Rect.d.ts +11 -4
  52. package/es/display-objects/Rect.js +2 -0
  53. package/es/display-objects/Text.d.ts +4 -0
  54. package/es/display-objects/Text.js +4 -2
  55. package/es/dom/Element.js +1 -0
  56. package/es/global-module.js +4 -4
  57. package/es/services/EventService.js +10 -2
  58. package/es/services/SceneGraphService.d.ts +2 -0
  59. package/es/services/SceneGraphService.js +9 -0
  60. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  61. package/es/services/aabb/CircleUpdater.js +2 -6
  62. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  63. package/es/services/aabb/EllipseUpdater.js +2 -6
  64. package/es/services/aabb/LineUpdater.d.ts +0 -2
  65. package/es/services/aabb/LineUpdater.js +1 -3
  66. package/es/services/aabb/PathUpdater.d.ts +0 -2
  67. package/es/services/aabb/PathUpdater.js +1 -5
  68. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  69. package/es/services/aabb/PolylineUpdater.js +1 -3
  70. package/es/services/aabb/RectUpdater.d.ts +0 -2
  71. package/es/services/aabb/RectUpdater.js +1 -5
  72. package/es/services/aabb/TextUpdater.d.ts +7 -0
  73. package/es/services/aabb/TextUpdater.js +0 -4
  74. package/es/services/aabb/interfaces.d.ts +0 -3
  75. package/es/types.d.ts +6 -19
  76. package/es/types.js +1 -0
  77. package/es/utils/interpolation.js +5 -10
  78. package/es/utils/math.js +4 -3
  79. package/es/utils/path.d.ts +2 -2
  80. package/es/utils/path.js +76 -26
  81. package/lib/Canvas.js +2 -0
  82. package/lib/css/CSS.d.ts +4 -2
  83. package/lib/css/CSS.js +6 -2
  84. package/lib/css/CSSProperty.d.ts +2 -1
  85. package/lib/css/StyleValueRegistry.d.ts +24 -55
  86. package/lib/css/StyleValueRegistry.js +120 -137
  87. package/lib/css/interfaces.d.ts +110 -0
  88. package/lib/css/interfaces.js +76 -1
  89. package/lib/css/parser/color.d.ts +1 -1
  90. package/lib/css/parser/color.js +1 -1
  91. package/lib/css/parser/dimension.js +4 -0
  92. package/lib/css/parser/path.d.ts +2 -2
  93. package/lib/css/parser/path.js +9 -2
  94. package/lib/css/parser/points.d.ts +8 -1
  95. package/lib/css/parser/points.js +33 -3
  96. package/lib/css/parser/transform.js +1 -1
  97. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  98. package/lib/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -2
  99. package/lib/css/properties/CSSPropertyLengthOrPercentage.js +34 -14
  100. package/lib/css/properties/CSSPropertyLengthOrPercentage12.d.ts +15 -0
  101. package/lib/css/properties/CSSPropertyLengthOrPercentage12.js +48 -0
  102. package/lib/css/properties/CSSPropertyLengthOrPercentage14.d.ts +25 -0
  103. package/lib/css/properties/CSSPropertyLengthOrPercentage14.js +52 -0
  104. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  105. package/lib/css/properties/CSSPropertyLocalPosition.js +60 -20
  106. package/lib/css/properties/CSSPropertyPath.d.ts +3 -3
  107. package/lib/css/properties/CSSPropertyPath.js +12 -6
  108. package/lib/css/properties/CSSPropertyPoints.js +8 -5
  109. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  110. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  111. package/lib/css/properties/index.d.ts +2 -2
  112. package/lib/css/properties/index.js +17 -17
  113. package/lib/display-objects/Circle.d.ts +4 -0
  114. package/lib/display-objects/Circle.js +2 -0
  115. package/lib/display-objects/CustomElement.d.ts +6 -2
  116. package/lib/display-objects/CustomElement.js +13 -4
  117. package/lib/display-objects/DisplayObject.d.ts +1 -7
  118. package/lib/display-objects/DisplayObject.js +6 -27
  119. package/lib/display-objects/Ellipse.d.ts +4 -0
  120. package/lib/display-objects/Ellipse.js +2 -0
  121. package/lib/display-objects/Group.d.ts +4 -0
  122. package/lib/display-objects/Group.js +2 -0
  123. package/lib/display-objects/HTML.d.ts +4 -4
  124. package/lib/display-objects/HTML.js +5 -3
  125. package/lib/display-objects/Image.d.ts +4 -0
  126. package/lib/display-objects/Image.js +2 -0
  127. package/lib/display-objects/Line.js +2 -0
  128. package/lib/display-objects/Polygon.js +1 -1
  129. package/lib/display-objects/Polyline.js +1 -1
  130. package/lib/display-objects/Rect.d.ts +11 -4
  131. package/lib/display-objects/Rect.js +2 -0
  132. package/lib/display-objects/Text.d.ts +4 -0
  133. package/lib/display-objects/Text.js +4 -2
  134. package/lib/dom/Element.js +1 -0
  135. package/lib/global-module.js +3 -3
  136. package/lib/services/EventService.js +10 -2
  137. package/lib/services/SceneGraphService.d.ts +2 -0
  138. package/lib/services/SceneGraphService.js +12 -0
  139. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  140. package/lib/services/aabb/CircleUpdater.js +2 -6
  141. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  142. package/lib/services/aabb/EllipseUpdater.js +2 -6
  143. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  144. package/lib/services/aabb/LineUpdater.js +1 -3
  145. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  146. package/lib/services/aabb/PathUpdater.js +1 -5
  147. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  148. package/lib/services/aabb/PolylineUpdater.js +1 -3
  149. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  150. package/lib/services/aabb/RectUpdater.js +1 -5
  151. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  152. package/lib/services/aabb/TextUpdater.js +0 -4
  153. package/lib/services/aabb/interfaces.d.ts +0 -3
  154. package/lib/types.d.ts +6 -19
  155. package/lib/types.js +1 -0
  156. package/lib/utils/interpolation.js +6 -10
  157. package/lib/utils/math.js +4 -3
  158. package/lib/utils/path.d.ts +2 -2
  159. package/lib/utils/path.js +70 -26
  160. package/package.json +3 -3
  161. package/es/css/properties/CSSPropertyAnchor.d.ts +0 -8
  162. package/es/css/properties/CSSPropertyAnchor.js +0 -25
  163. package/es/css/properties/CSSPropertyLineDash.d.ts +0 -9
  164. package/es/css/properties/CSSPropertyLineDash.js +0 -25
  165. package/lib/css/properties/CSSPropertyAnchor.d.ts +0 -8
  166. package/lib/css/properties/CSSPropertyAnchor.js +0 -35
  167. package/lib/css/properties/CSSPropertyLineDash.d.ts +0 -9
  168. package/lib/css/properties/CSSPropertyLineDash.js +0 -34
@@ -3,10 +3,85 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyleValueRegistry = void 0;
6
+ exports.StyleValueRegistry = exports.PropertySyntax = void 0;
7
7
 
8
8
  var _manaSyringe = require("mana-syringe");
9
9
 
10
+ /**
11
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
12
+ */
13
+ var PropertySyntax;
14
+ exports.PropertySyntax = PropertySyntax;
15
+
16
+ (function (PropertySyntax) {
17
+ /**
18
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
19
+ */
20
+ PropertySyntax["COORDINATE"] = "<coordinate>";
21
+ /**
22
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
23
+ */
24
+
25
+ PropertySyntax["COLOR"] = "<color>";
26
+ /**
27
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
28
+ */
29
+
30
+ PropertySyntax["PAINT"] = "<paint>";
31
+ /**
32
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
33
+ */
34
+
35
+ PropertySyntax["NUMBER"] = "<number>";
36
+ /**
37
+ * <number> with range 0..1
38
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
39
+ */
40
+
41
+ PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
42
+ /**
43
+ * <number> with range 0..Infinity
44
+ */
45
+
46
+ PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
47
+ /**
48
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
49
+ */
50
+
51
+ PropertySyntax["LENGTH"] = "<length>";
52
+ /**
53
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
54
+ */
55
+
56
+ PropertySyntax["PERCENTAGE"] = "<percentage>";
57
+ PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
58
+ PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
59
+ /**
60
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
61
+ */
62
+
63
+ PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
64
+ /**
65
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
66
+ */
67
+
68
+ PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
69
+ PropertySyntax["PATH"] = "<path>";
70
+ /**
71
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
72
+ */
73
+
74
+ PropertySyntax["FILTER"] = "<filter>";
75
+ PropertySyntax["Z_INDEX"] = "<z-index>";
76
+ PropertySyntax["OFFSET_PATH"] = "<offset-path>";
77
+ PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
78
+ PropertySyntax["CLIP_PATH"] = "<clip-path>";
79
+ PropertySyntax["TRANSFORM"] = "<transform>";
80
+ PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
81
+ PropertySyntax["TEXT"] = "<text>";
82
+ PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
83
+ })(PropertySyntax || (exports.PropertySyntax = PropertySyntax = {}));
84
+
10
85
  var StyleValueRegistry = _manaSyringe.Syringe.defineToken('StyleValueRegistry');
11
86
 
12
87
  exports.StyleValueRegistry = StyleValueRegistry;
@@ -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;
@@ -29,7 +29,7 @@ var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
29
29
  */
30
30
 
31
31
  function parseColor(colorStr) {
32
- if (colorStr === void 0) {
32
+ if ((0, _utils.isNil)(colorStr)) {
33
33
  colorStr = '';
34
34
  }
35
35
 
@@ -19,6 +19,10 @@ var _utils = require("../../utils");
19
19
  var _cssom = require("../cssom");
20
20
 
21
21
  function parseDimension(unitRegExp, string) {
22
+ if ((0, _utils.isNil)(string)) {
23
+ return new _cssom.CSSUnitValue(0, 'px');
24
+ }
25
+
22
26
  string = "".concat(string).trim().toLowerCase();
23
27
 
24
28
  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[]];
@@ -16,7 +16,7 @@ var _path = require("../../utils/path");
16
16
 
17
17
  var _Rectangle = require("../../shapes/Rectangle");
18
18
 
19
- function parsePath(path) {
19
+ function parsePath(path, object) {
20
20
  var absolutePath = (0, _util.path2Absolute)(path);
21
21
  var hasArc = hasArcOrBezier(absolutePath);
22
22
  var clonedAbsolutePath = absolutePath.slice();
@@ -37,6 +37,13 @@ function parsePath(path) {
37
37
  totalLength = _c.totalLength,
38
38
  curveSegments = _c.curveSegments;
39
39
 
40
+ var rect = getPathBBox(curve);
41
+
42
+ if (object) {
43
+ object.parsedStyle.defX = rect.x;
44
+ object.parsedStyle.defY = rect.y;
45
+ }
46
+
40
47
  return {
41
48
  absolutePath: absolutePath,
42
49
  hasArc: hasArc,
@@ -47,7 +54,7 @@ function parsePath(path) {
47
54
  totalLength: totalLength,
48
55
  curveSegments: curveSegments,
49
56
  zCommandIndexes: zCommandIndexes,
50
- rect: getPathBBox(curve)
57
+ rect: rect
51
58
  };
52
59
  }
53
60
 
@@ -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][];
@@ -5,13 +5,31 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.parsePoints = parsePoints;
7
7
 
8
+ var _tslib = require("tslib");
9
+
8
10
  var _gMath = require("@antv/g-math");
9
11
 
10
12
  var _utils = require("../../utils");
11
13
 
12
- function parsePoints(points) {
13
- if ((0, _utils.isString)(points)) {
14
- return null;
14
+ /**
15
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
16
+ *
17
+ * @example
18
+ * points="100,10 250,150 200,110"
19
+ */
20
+ function parsePoints(pointsOrStr, object) {
21
+ var points;
22
+
23
+ if ((0, _utils.isString)(pointsOrStr)) {
24
+ points = pointsOrStr.split(' ').map(function (pointStr) {
25
+ var _a = (0, _tslib.__read)(pointStr.split(','), 2),
26
+ x = _a[0],
27
+ y = _a[1];
28
+
29
+ return [Number(x), Number(y)];
30
+ });
31
+ } else {
32
+ points = pointsOrStr;
15
33
  }
16
34
 
17
35
  var segments = [];
@@ -31,6 +49,18 @@ function parsePoints(points) {
31
49
  segments.push(segmentT);
32
50
  }
33
51
  });
52
+ var minX = Math.min.apply(Math, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(points.map(function (point) {
53
+ return point[0];
54
+ })), false));
55
+ var minY = Math.min.apply(Math, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(points.map(function (point) {
56
+ return point[1];
57
+ })), false));
58
+
59
+ if (object) {
60
+ object.parsedStyle.defX = minX;
61
+ object.parsedStyle.defY = minY;
62
+ }
63
+
34
64
  return {
35
65
  points: points,
36
66
  totalLength: totalLength,
@@ -63,7 +63,7 @@ var transformFunctions = {
63
63
  */
64
64
 
65
65
  function parseTransform(string) {
66
- string = string.toLowerCase().trim();
66
+ string = (string || 'none').toLowerCase().trim();
67
67
 
68
68
  if (string === 'none') {
69
69
  return [];
@@ -11,6 +11,8 @@ var _manaSyringe = require("mana-syringe");
11
11
 
12
12
  var _services = require("../../services");
13
13
 
14
+ var _cssom = require("../cssom");
15
+
14
16
  /**
15
17
  * @see /zh/docs/api/basic/display-object#clippath
16
18
  * @example
@@ -34,7 +36,12 @@ function () {
34
36
  function CSSPropertyClipPath() {}
35
37
 
36
38
  CSSPropertyClipPath.prototype.calculator = function (name, oldClipPath, newClipPath, object) {
37
- // clear ref to old clip path
39
+ // unset
40
+ if (newClipPath instanceof _cssom.CSSKeywordValue) {
41
+ newClipPath = null;
42
+ } // clear ref to old clip path
43
+
44
+
38
45
  if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.style.clipPathTargets) {
39
46
  var index = oldClipPath.style.clipPathTargets.indexOf(object);
40
47
  oldClipPath.style.clipPathTargets.splice(index, 1);
@@ -16,6 +16,5 @@ export declare class CSSPropertyLengthOrPercentage implements Partial<CSSPropert
16
16
  * CSS.percent(50) -> CSS.px(0.5 * parent.width)
17
17
  */
18
18
  calculator(name: string, oldParsed: CSSUnitValue, computed: CSSUnitValue, object: DisplayObject, registry: StyleValueRegistry): CSSUnitValue;
19
- private nameToBoundsIndex;
20
- private calculateUsedValueWithParentBounds;
19
+ private getFontSize;
21
20
  }
@@ -21,7 +21,22 @@ var CSSPropertyLengthOrPercentage =
21
21
  function () {
22
22
  function CSSPropertyLengthOrPercentage() {
23
23
  this.parser = _parser.parseLengthOrPercentage;
24
- this.mixer = _parser.mergeDimensions;
24
+ this.mixer = _parser.mergeDimensions; // private nameToBoundsIndex(name: string): number {
25
+ // if (name === 'x' || name === 'cx' || name === 'width') {
26
+ // return 0;
27
+ // } else if (name === 'y' || name === 'cy' || name === 'height') {
28
+ // return 1;
29
+ // }
30
+ // return 2;
31
+ // }
32
+ // private calculateUsedValueWithParentBounds(object: DisplayObject, name: string) {
33
+ // const bounds = (object.parentElement as DisplayObject).getGeometryBounds();
34
+ // const computedValue = object.computedStyle[name].value;
35
+ // return new CSSUnitValue(
36
+ // (bounds.halfExtents[this.nameToBoundsIndex(name)] * 2 * computedValue) / 100,
37
+ // 'px',
38
+ // );
39
+ // }
25
40
  }
26
41
  /**
27
42
  * according to parent's bounds
@@ -32,6 +47,8 @@ function () {
32
47
 
33
48
 
34
49
  CSSPropertyLengthOrPercentage.prototype.calculator = function (name, oldParsed, computed, object, registry) {
50
+ var _a;
51
+
35
52
  if (_cssom.CSSUnitValue.isRelativeUnit(computed.unit)) {
36
53
  if (computed.unit === _cssom.UnitType.kPercentage) {
37
54
  // try to resolve according to parent's geometry bounds
@@ -51,7 +68,16 @@ function () {
51
68
  // }
52
69
  return new _cssom.CSSUnitValue(0, 'px');
53
70
  } else if (computed.unit === _cssom.UnitType.kEms) {
54
- // TODO: handle ems
71
+ if (object.parentNode) {
72
+ return this.getFontSize(object.parentNode);
73
+ }
74
+
75
+ return new _cssom.CSSUnitValue(0, 'px');
76
+ } else if (computed.unit === _cssom.UnitType.kRems) {
77
+ if ((_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.documentElement) {
78
+ return this.getFontSize(object.ownerDocument.documentElement);
79
+ }
80
+
55
81
  return new _cssom.CSSUnitValue(0, 'px');
56
82
  }
57
83
  } else {
@@ -62,20 +88,14 @@ function () {
62
88
  }
63
89
  };
64
90
 
65
- CSSPropertyLengthOrPercentage.prototype.nameToBoundsIndex = function (name) {
66
- if (name === 'x' || name === 'cx' || name === 'width') {
67
- return 0;
68
- } else if (name === 'y' || name === 'cy' || name === 'height') {
69
- return 1;
70
- }
91
+ CSSPropertyLengthOrPercentage.prototype.getFontSize = function (object) {
92
+ var fontSize = object.parsedStyle.fontSize;
71
93
 
72
- return 2;
73
- };
94
+ if (fontSize && !_cssom.CSSUnitValue.isRelativeUnit(fontSize.unit)) {
95
+ return fontSize.clone();
96
+ }
74
97
 
75
- CSSPropertyLengthOrPercentage.prototype.calculateUsedValueWithParentBounds = function (object, name) {
76
- var bounds = object.parentElement.getGeometryBounds();
77
- var computedValue = object.computedStyle[name].value;
78
- return new _cssom.CSSUnitValue(bounds.halfExtents[this.nameToBoundsIndex(name)] * 2 * computedValue / 100, 'px');
98
+ return new _cssom.CSSUnitValue(0, 'px');
79
99
  };
80
100
 
81
101
  CSSPropertyLengthOrPercentage = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], CSSPropertyLengthOrPercentage);
@@ -0,0 +1,15 @@
1
+ import type { CSSProperty } from '../CSSProperty';
2
+ import type { CSSUnitValue } from '../cssom';
3
+ import { mergeDimensionList } from '../parser';
4
+ /**
5
+ * format to Tuple2<CSSUnitValue>
6
+ *
7
+ * @example
8
+ * rect.style.lineDash = 10;
9
+ * rect.style.lineDash = [10, 10];
10
+ * rect.style.lineDash = '10 10';
11
+ */
12
+ export declare class CSSPropertyLengthOrPercentage12 implements Partial<CSSProperty<[CSSUnitValue, CSSUnitValue], [CSSUnitValue, CSSUnitValue]>> {
13
+ parser(radius: string | number | number[]): [CSSUnitValue, CSSUnitValue];
14
+ mixer: typeof mergeDimensionList;
15
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CSSPropertyLengthOrPercentage12 = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ var _manaSyringe = require("mana-syringe");
11
+
12
+ var _parser = require("../parser");
13
+
14
+ var _utils = require("../../utils");
15
+
16
+ /**
17
+ * format to Tuple2<CSSUnitValue>
18
+ *
19
+ * @example
20
+ * rect.style.lineDash = 10;
21
+ * rect.style.lineDash = [10, 10];
22
+ * rect.style.lineDash = '10 10';
23
+ */
24
+ var CSSPropertyLengthOrPercentage12 =
25
+ /** @class */
26
+ function () {
27
+ function CSSPropertyLengthOrPercentage12() {
28
+ this.mixer = _parser.mergeDimensionList;
29
+ }
30
+
31
+ CSSPropertyLengthOrPercentage12.prototype.parser = function (radius) {
32
+ var parsed = (0, _parser.parseDimensionArray)((0, _utils.isNumber)(radius) ? [radius] : radius);
33
+ var formatted;
34
+
35
+ if (parsed.length === 1) {
36
+ formatted = [parsed[0], parsed[0]];
37
+ } else {
38
+ formatted = [parsed[0], parsed[1]];
39
+ }
40
+
41
+ return formatted;
42
+ };
43
+
44
+ CSSPropertyLengthOrPercentage12 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], CSSPropertyLengthOrPercentage12);
45
+ return CSSPropertyLengthOrPercentage12;
46
+ }();
47
+
48
+ exports.CSSPropertyLengthOrPercentage12 = CSSPropertyLengthOrPercentage12;
@@ -0,0 +1,25 @@
1
+ import type { CSSProperty } from '../CSSProperty';
2
+ import type { CSSUnitValue } from '../cssom';
3
+ import { mergeDimensionList } from '../parser';
4
+ /**
5
+ * used in rounded rect
6
+ *
7
+ * @example
8
+ * rect.style.radius = 10;
9
+ * rect.style.radius = '10 10';
10
+ * rect.style.radius = '10 10 10 10';
11
+ */
12
+ export declare class CSSPropertyLengthOrPercentage14 implements Partial<CSSProperty<[
13
+ CSSUnitValue,
14
+ CSSUnitValue,
15
+ CSSUnitValue,
16
+ CSSUnitValue
17
+ ], [
18
+ CSSUnitValue,
19
+ CSSUnitValue,
20
+ CSSUnitValue,
21
+ CSSUnitValue
22
+ ]>> {
23
+ parser(radius: string | number | number[]): [CSSUnitValue, CSSUnitValue, CSSUnitValue, CSSUnitValue];
24
+ mixer: typeof mergeDimensionList;
25
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CSSPropertyLengthOrPercentage14 = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ var _manaSyringe = require("mana-syringe");
11
+
12
+ var _parser = require("../parser");
13
+
14
+ var _utils = require("../../utils");
15
+
16
+ /**
17
+ * used in rounded rect
18
+ *
19
+ * @example
20
+ * rect.style.radius = 10;
21
+ * rect.style.radius = '10 10';
22
+ * rect.style.radius = '10 10 10 10';
23
+ */
24
+ var CSSPropertyLengthOrPercentage14 =
25
+ /** @class */
26
+ function () {
27
+ function CSSPropertyLengthOrPercentage14() {
28
+ this.mixer = _parser.mergeDimensionList;
29
+ }
30
+
31
+ CSSPropertyLengthOrPercentage14.prototype.parser = function (radius) {
32
+ var parsed = (0, _parser.parseDimensionArray)((0, _utils.isNumber)(radius) ? [radius] : radius);
33
+ var formatted; // format to Tuple<CSSUnitValue>
34
+
35
+ if (parsed.length === 1) {
36
+ formatted = [parsed[0], parsed[0], parsed[0], parsed[0]];
37
+ } else if (parsed.length === 2) {
38
+ formatted = [parsed[0], parsed[1], parsed[0], parsed[1]];
39
+ } else if (parsed.length === 3) {
40
+ formatted = [parsed[0], parsed[1], parsed[2], parsed[1]];
41
+ } else {
42
+ formatted = [parsed[0], parsed[1], parsed[2], parsed[3]];
43
+ }
44
+
45
+ return formatted;
46
+ };
47
+
48
+ CSSPropertyLengthOrPercentage14 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], CSSPropertyLengthOrPercentage14);
49
+ return CSSPropertyLengthOrPercentage14;
50
+ }();
51
+
52
+ exports.CSSPropertyLengthOrPercentage14 = CSSPropertyLengthOrPercentage14;
@@ -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
  */
@@ -9,10 +9,12 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _manaSyringe = require("mana-syringe");
11
11
 
12
- var _parser = require("../parser");
13
-
14
12
  var _CSSPropertyLengthOrPercentage = require("./CSSPropertyLengthOrPercentage");
15
13
 
14
+ var _utils = require("../../utils");
15
+
16
+ var _types = require("../../types");
17
+
16
18
  /**
17
19
  * local position
18
20
  */
@@ -22,19 +24,7 @@ function (_super) {
22
24
  (0, _tslib.__extends)(CSSPropertyLocalPosition, _super);
23
25
 
24
26
  function CSSPropertyLocalPosition() {
25
- var _this = _super !== null && _super.apply(this, arguments) || this;
26
- /**
27
- * <length> & <percentage>
28
- */
29
-
30
-
31
- _this.parser = _parser.parseLengthOrPercentage;
32
- /**
33
- * mix between CSS.px(x)
34
- */
35
-
36
- _this.mixer = _parser.mergeDimensions;
37
- return _this;
27
+ return _super !== null && _super.apply(this, arguments) || this;
38
28
  }
39
29
  /**
40
30
  * update local position
@@ -42,11 +32,61 @@ function (_super) {
42
32
 
43
33
 
44
34
  CSSPropertyLocalPosition.prototype.postProcessor = function (object) {
45
- var _a = object.parsedStyle,
46
- x = _a.x,
47
- y = _a.y,
48
- z = _a.z;
49
- object.setLocalPosition(x && x.value || 0, y && y.value || 0, z && z.value || 0);
35
+ var x;
36
+ var y;
37
+ var z;
38
+
39
+ switch (object.nodeName) {
40
+ case _types.Shape.CIRCLE:
41
+ case _types.Shape.ELLIPSE:
42
+ var _a = object.parsedStyle,
43
+ cx = _a.cx,
44
+ cy = _a.cy;
45
+
46
+ if (!(0, _utils.isNil)(cx)) {
47
+ x = cx.value;
48
+ }
49
+
50
+ if (!(0, _utils.isNil)(cy)) {
51
+ y = cy.value;
52
+ }
53
+
54
+ break;
55
+
56
+ case _types.Shape.LINE:
57
+ var _b = object.parsedStyle,
58
+ x1 = _b.x1,
59
+ x2 = _b.x2,
60
+ y1 = _b.y1,
61
+ y2 = _b.y2;
62
+ var minX = Math.min(x1.value, x2.value);
63
+ var minY = Math.min(y1.value, y2.value);
64
+ x = minX;
65
+ y = minY;
66
+ z = 0;
67
+ break;
68
+
69
+ default:
70
+ if (!(0, _utils.isNil)(object.parsedStyle.x)) {
71
+ x = object.parsedStyle.x.value;
72
+ }
73
+
74
+ if (!(0, _utils.isNil)(object.parsedStyle.y)) {
75
+ y = object.parsedStyle.y.value;
76
+ }
77
+
78
+ break;
79
+ }
80
+
81
+ object.parsedStyle.defX = x || 0;
82
+ object.parsedStyle.defY = y || 0;
83
+
84
+ var _c = (0, _tslib.__read)(object.getLocalPosition(), 3),
85
+ ox = _c[0],
86
+ oy = _c[1],
87
+ oz = _c[2];
88
+
89
+ object.setLocalPosition((0, _utils.isNil)(x) ? ox : x, (0, _utils.isNil)(y) ? oy : y, (0, _utils.isNil)(z) ? oz : z);
50
90
  };
51
91
 
52
92
  CSSPropertyLocalPosition = (0, _tslib.__decorate)([(0, _manaSyringe.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
- segments: import("../../display-objects").PathSegment[];
13
+ segments: import("../..").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[];
@@ -9,6 +9,8 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _manaSyringe = require("mana-syringe");
11
11
 
12
+ var _ = require("../..");
13
+
12
14
  var _shapes = require("../../shapes");
13
15
 
14
16
  var _cssom = require("../cssom");
@@ -27,7 +29,8 @@ function () {
27
29
  }
28
30
 
29
31
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
30
- if (parsed instanceof _cssom.CSSKeywordValue) {
32
+ // unset
33
+ if (parsed instanceof _cssom.CSSKeywordValue && parsed.value === 'unset') {
31
34
  return {
32
35
  absolutePath: [],
33
36
  hasArc: false,
@@ -50,11 +53,14 @@ function () {
50
53
 
51
54
 
52
55
  CSSPropertyPath.prototype.postProcessor = function (object) {
53
- var _a = object.parsedStyle,
54
- x = _a.x,
55
- y = _a.y,
56
- z = _a.z;
57
- object.setLocalPosition(x && x.value || 0, y && y.value || 0, z && z.value || 0);
56
+ if (object.nodeName === _.Shape.PATH) {
57
+ var _a = object.parsedStyle,
58
+ _b = _a.defX,
59
+ defX = _b === void 0 ? 0 : _b,
60
+ _c = _a.defY,
61
+ defY = _c === void 0 ? 0 : _c;
62
+ object.setLocalPosition(defX, defY);
63
+ }
58
64
  };
59
65
 
60
66
  CSSPropertyPath = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], CSSPropertyPath);