@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
@@ -1,2 +1,77 @@
1
1
  import { Syringe } from 'mana-syringe';
2
+ /**
3
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
4
+ */
5
+
6
+ export var PropertySyntax;
7
+
8
+ (function (PropertySyntax) {
9
+ /**
10
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
11
+ */
12
+ PropertySyntax["COORDINATE"] = "<coordinate>";
13
+ /**
14
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
15
+ */
16
+
17
+ PropertySyntax["COLOR"] = "<color>";
18
+ /**
19
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
20
+ */
21
+
22
+ PropertySyntax["PAINT"] = "<paint>";
23
+ /**
24
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
25
+ */
26
+
27
+ PropertySyntax["NUMBER"] = "<number>";
28
+ /**
29
+ * <number> with range 0..1
30
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
31
+ */
32
+
33
+ PropertySyntax["OPACITY_VALUE"] = "<opacity-value>";
34
+ /**
35
+ * <number> with range 0..Infinity
36
+ */
37
+
38
+ PropertySyntax["SHADOW_BLUR"] = "<shadow-blur>";
39
+ /**
40
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
41
+ */
42
+
43
+ PropertySyntax["LENGTH"] = "<length>";
44
+ /**
45
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
46
+ */
47
+
48
+ PropertySyntax["PERCENTAGE"] = "<percentage>";
49
+ PropertySyntax["LENGTH_PERCENTAGE"] = "<length> | <percentage>";
50
+ PropertySyntax["LENGTH_PERCENTAGE_12"] = "[<length> | <percentage>]{1,2}";
51
+ /**
52
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
53
+ */
54
+
55
+ PropertySyntax["LENGTH_PERCENTAGE_14"] = "[<length> | <percentage>]{1,4}";
56
+ /**
57
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
58
+ */
59
+
60
+ PropertySyntax["LIST_OF_POINTS"] = "<list-of-points>";
61
+ PropertySyntax["PATH"] = "<path>";
62
+ /**
63
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
64
+ */
65
+
66
+ PropertySyntax["FILTER"] = "<filter>";
67
+ PropertySyntax["Z_INDEX"] = "<z-index>";
68
+ PropertySyntax["OFFSET_PATH"] = "<offset-path>";
69
+ PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
70
+ PropertySyntax["CLIP_PATH"] = "<clip-path>";
71
+ PropertySyntax["TRANSFORM"] = "<transform>";
72
+ PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
73
+ PropertySyntax["TEXT"] = "<text>";
74
+ PropertySyntax["TEXT_TRANSFORM"] = "<text-transform>";
75
+ })(PropertySyntax || (PropertySyntax = {}));
76
+
2
77
  export var StyleValueRegistry = Syringe.defineToken('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;
@@ -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);
@@ -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
  }
@@ -11,7 +11,22 @@ var CSSPropertyLengthOrPercentage =
11
11
  function () {
12
12
  function CSSPropertyLengthOrPercentage() {
13
13
  this.parser = parseLengthOrPercentage;
14
- this.mixer = mergeDimensions;
14
+ this.mixer = mergeDimensions; // private nameToBoundsIndex(name: string): number {
15
+ // if (name === 'x' || name === 'cx' || name === 'width') {
16
+ // return 0;
17
+ // } else if (name === 'y' || name === 'cy' || name === 'height') {
18
+ // return 1;
19
+ // }
20
+ // return 2;
21
+ // }
22
+ // private calculateUsedValueWithParentBounds(object: DisplayObject, name: string) {
23
+ // const bounds = (object.parentElement as DisplayObject).getGeometryBounds();
24
+ // const computedValue = object.computedStyle[name].value;
25
+ // return new CSSUnitValue(
26
+ // (bounds.halfExtents[this.nameToBoundsIndex(name)] * 2 * computedValue) / 100,
27
+ // 'px',
28
+ // );
29
+ // }
15
30
  }
16
31
  /**
17
32
  * according to parent's bounds
@@ -22,6 +37,8 @@ function () {
22
37
 
23
38
 
24
39
  CSSPropertyLengthOrPercentage.prototype.calculator = function (name, oldParsed, computed, object, registry) {
40
+ var _a;
41
+
25
42
  if (CSSUnitValue.isRelativeUnit(computed.unit)) {
26
43
  if (computed.unit === UnitType.kPercentage) {
27
44
  // try to resolve according to parent's geometry bounds
@@ -41,7 +58,16 @@ function () {
41
58
  // }
42
59
  return new CSSUnitValue(0, 'px');
43
60
  } else if (computed.unit === UnitType.kEms) {
44
- // TODO: handle ems
61
+ if (object.parentNode) {
62
+ return this.getFontSize(object.parentNode);
63
+ }
64
+
65
+ return new CSSUnitValue(0, 'px');
66
+ } else if (computed.unit === UnitType.kRems) {
67
+ if ((_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.documentElement) {
68
+ return this.getFontSize(object.ownerDocument.documentElement);
69
+ }
70
+
45
71
  return new CSSUnitValue(0, 'px');
46
72
  }
47
73
  } else {
@@ -52,20 +78,14 @@ function () {
52
78
  }
53
79
  };
54
80
 
55
- CSSPropertyLengthOrPercentage.prototype.nameToBoundsIndex = function (name) {
56
- if (name === 'x' || name === 'cx' || name === 'width') {
57
- return 0;
58
- } else if (name === 'y' || name === 'cy' || name === 'height') {
59
- return 1;
60
- }
81
+ CSSPropertyLengthOrPercentage.prototype.getFontSize = function (object) {
82
+ var fontSize = object.parsedStyle.fontSize;
61
83
 
62
- return 2;
63
- };
84
+ if (fontSize && !CSSUnitValue.isRelativeUnit(fontSize.unit)) {
85
+ return fontSize.clone();
86
+ }
64
87
 
65
- CSSPropertyLengthOrPercentage.prototype.calculateUsedValueWithParentBounds = function (object, name) {
66
- var bounds = object.parentElement.getGeometryBounds();
67
- var computedValue = object.computedStyle[name].value;
68
- return new CSSUnitValue(bounds.halfExtents[this.nameToBoundsIndex(name)] * 2 * computedValue / 100, 'px');
88
+ return new CSSUnitValue(0, 'px');
69
89
  };
70
90
 
71
91
  CSSPropertyLengthOrPercentage = __decorate([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,38 @@
1
+ import { __decorate } from "tslib";
2
+ import { singleton } from 'mana-syringe';
3
+ import { parseDimensionArray, mergeDimensionList } from '../parser';
4
+ import { isNumber } from '../../utils';
5
+ /**
6
+ * format to Tuple2<CSSUnitValue>
7
+ *
8
+ * @example
9
+ * rect.style.lineDash = 10;
10
+ * rect.style.lineDash = [10, 10];
11
+ * rect.style.lineDash = '10 10';
12
+ */
13
+
14
+ var CSSPropertyLengthOrPercentage12 =
15
+ /** @class */
16
+ function () {
17
+ function CSSPropertyLengthOrPercentage12() {
18
+ this.mixer = mergeDimensionList;
19
+ }
20
+
21
+ CSSPropertyLengthOrPercentage12.prototype.parser = function (radius) {
22
+ var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
23
+ var formatted;
24
+
25
+ if (parsed.length === 1) {
26
+ formatted = [parsed[0], parsed[0]];
27
+ } else {
28
+ formatted = [parsed[0], parsed[1]];
29
+ }
30
+
31
+ return formatted;
32
+ };
33
+
34
+ CSSPropertyLengthOrPercentage12 = __decorate([singleton()], CSSPropertyLengthOrPercentage12);
35
+ return CSSPropertyLengthOrPercentage12;
36
+ }();
37
+
38
+ export { 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,42 @@
1
+ import { __decorate } from "tslib";
2
+ import { singleton } from 'mana-syringe';
3
+ import { parseDimensionArray, mergeDimensionList } from '../parser';
4
+ import { isNumber } from '../../utils';
5
+ /**
6
+ * used in rounded rect
7
+ *
8
+ * @example
9
+ * rect.style.radius = 10;
10
+ * rect.style.radius = '10 10';
11
+ * rect.style.radius = '10 10 10 10';
12
+ */
13
+
14
+ var CSSPropertyLengthOrPercentage14 =
15
+ /** @class */
16
+ function () {
17
+ function CSSPropertyLengthOrPercentage14() {
18
+ this.mixer = mergeDimensionList;
19
+ }
20
+
21
+ CSSPropertyLengthOrPercentage14.prototype.parser = function (radius) {
22
+ var parsed = parseDimensionArray(isNumber(radius) ? [radius] : radius);
23
+ var formatted; // format to Tuple<CSSUnitValue>
24
+
25
+ if (parsed.length === 1) {
26
+ formatted = [parsed[0], parsed[0], parsed[0], parsed[0]];
27
+ } else if (parsed.length === 2) {
28
+ formatted = [parsed[0], parsed[1], parsed[0], parsed[1]];
29
+ } else if (parsed.length === 3) {
30
+ formatted = [parsed[0], parsed[1], parsed[2], parsed[1]];
31
+ } else {
32
+ formatted = [parsed[0], parsed[1], parsed[2], parsed[3]];
33
+ }
34
+
35
+ return formatted;
36
+ };
37
+
38
+ CSSPropertyLengthOrPercentage14 = __decorate([singleton()], CSSPropertyLengthOrPercentage14);
39
+ return CSSPropertyLengthOrPercentage14;
40
+ }();
41
+
42
+ export { 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
  */
@@ -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,61 @@ 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.LINE:
46
+ var _b = object.parsedStyle,
47
+ x1 = _b.x1,
48
+ x2 = _b.x2,
49
+ y1 = _b.y1,
50
+ y2 = _b.y2;
51
+ var minX = Math.min(x1.value, x2.value);
52
+ var minY = Math.min(y1.value, y2.value);
53
+ x = minX;
54
+ y = minY;
55
+ z = 0;
56
+ break;
57
+
58
+ default:
59
+ if (!isNil(object.parsedStyle.x)) {
60
+ x = object.parsedStyle.x.value;
61
+ }
62
+
63
+ if (!isNil(object.parsedStyle.y)) {
64
+ y = object.parsedStyle.y.value;
65
+ }
66
+
67
+ break;
68
+ }
69
+
70
+ object.parsedStyle.defX = x || 0;
71
+ object.parsedStyle.defY = y || 0;
72
+
73
+ var _c = __read(object.getLocalPosition(), 3),
74
+ ox = _c[0],
75
+ oy = _c[1],
76
+ oz = _c[2];
77
+
78
+ object.setLocalPosition(isNil(x) ? ox : x, isNil(y) ? oy : y, isNil(z) ? oz : z);
40
79
  };
41
80
 
42
81
  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
- 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[];
@@ -1,5 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
+ import { Shape } from '../..';
3
4
  import { Rectangle } from '../../shapes';
4
5
  import { CSSKeywordValue } from '../cssom';
5
6
  import { parsePath, mergePaths } from '../parser';
@@ -16,7 +17,8 @@ function () {
16
17
  }
17
18
 
18
19
  CSSPropertyPath.prototype.calculator = function (name, oldParsed, parsed) {
19
- if (parsed instanceof CSSKeywordValue) {
20
+ // unset
21
+ if (parsed instanceof CSSKeywordValue && parsed.value === 'unset') {
20
22
  return {
21
23
  absolutePath: [],
22
24
  hasArc: false,
@@ -39,11 +41,14 @@ function () {
39
41
 
40
42
 
41
43
  CSSPropertyPath.prototype.postProcessor = function (object) {
42
- 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
+ if (object.nodeName === Shape.PATH) {
45
+ var _a = object.parsedStyle,
46
+ _b = _a.defX,
47
+ defX = _b === void 0 ? 0 : _b,
48
+ _c = _a.defY,
49
+ defY = _c === void 0 ? 0 : _c;
50
+ object.setLocalPosition(defX, defY);
51
+ }
47
52
  };
48
53
 
49
54
  CSSPropertyPath = __decorate([singleton()], CSSPropertyPath);
@@ -1,5 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
+ import { Shape } from '../..';
3
4
  import { parsePoints } from '../parser';
4
5
 
5
6
  var CSSPropertyPoints =
@@ -14,11 +15,12 @@ function () {
14
15
 
15
16
 
16
17
  CSSPropertyPoints.prototype.postProcessor = function (object) {
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
+ if (object.nodeName === Shape.POLYGON || object.nodeName === Shape.POLYLINE) {
19
+ var _a = object.parsedStyle,
20
+ defX = _a.defX,
21
+ defY = _a.defY;
22
+ object.setLocalPosition(defX, defY);
23
+ }
22
24
  };
23
25
 
24
26
  CSSPropertyPoints = __decorate([singleton()], CSSPropertyPoints);