@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,3 +1,5 @@
1
+ var _a;
2
+
1
3
  import { __decorate, __metadata, __read, __spreadArray } from "tslib";
2
4
  import { postConstruct, singleton, GlobalContainer } from 'mana-syringe';
3
5
  import { vec3 } from 'gl-matrix';
@@ -7,18 +9,11 @@ import { ElementEvent } from '../dom';
7
9
  import { Shape } from '../types';
8
10
  import { CSSKeywordValue, CSSStyleValue, CSSUnitValue } from './cssom';
9
11
  import { convertPercentUnit } from './parser';
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';
12
+ import { CSSPropertyLocalPosition, CSSPropertyOpacity, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLengthOrPercentage12, CSSPropertyLengthOrPercentage14, CSSPropertyShadowBlur, CSSPropertyOffsetPath, CSSPropertyOffsetDistance, CSSPropertyZIndex, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyPath, CSSPropertyClipPath, CSSPropertyPoints, CSSPropertyText, CSSPropertyTextTransform } from './properties';
13
+ import { formatAttribute, isNil } from '../utils';
12
14
  import { AABB } from '../shapes';
13
- import { StyleValueRegistry } from './interfaces';
14
- export var PropertySyntax = {
15
- COLOR: '<color>',
16
- PAINT: '<paint>',
17
- NUMBER: '<number>',
18
- LENGTH: '<length>',
19
- PERCENTAGE: '<percentage>',
20
- LENGTH_PERCENTAGE: '<length> | <percentage>'
21
- };
15
+ import { StyleValueRegistry, PropertySyntax } from './interfaces';
16
+ export var PROPERTY_HANDLERS = (_a = {}, _a[PropertySyntax.COORDINATE] = CSSPropertyLocalPosition, _a[PropertySyntax.COLOR] = CSSPropertyColor, _a[PropertySyntax.PAINT] = CSSPropertyColor, _a[PropertySyntax.OPACITY_VALUE] = CSSPropertyOpacity, _a[PropertySyntax.LENGTH_PERCENTAGE] = CSSPropertyLengthOrPercentage, _a[PropertySyntax.LENGTH_PERCENTAGE_12] = CSSPropertyLengthOrPercentage12, _a[PropertySyntax.LENGTH_PERCENTAGE_14] = CSSPropertyLengthOrPercentage14, _a[PropertySyntax.SHADOW_BLUR] = CSSPropertyShadowBlur, _a[PropertySyntax.LIST_OF_POINTS] = CSSPropertyPoints, _a[PropertySyntax.PATH] = CSSPropertyPath, _a[PropertySyntax.FILTER] = CSSPropertyFilter, _a[PropertySyntax.Z_INDEX] = CSSPropertyZIndex, _a[PropertySyntax.OFFSET_PATH] = CSSPropertyOffsetPath, _a[PropertySyntax.OFFSET_DISTANCE] = CSSPropertyOffsetDistance, _a[PropertySyntax.CLIP_PATH] = CSSPropertyClipPath, _a[PropertySyntax.TRANSFORM] = CSSPropertyTransform, _a[PropertySyntax.TRANSFORM_ORIGIN] = CSSPropertyTransformOrigin, _a[PropertySyntax.TEXT] = CSSPropertyText, _a[PropertySyntax.TEXT_TRANSFORM] = CSSPropertyTextTransform, _a);
22
17
  /**
23
18
  * Blink used them in code generation(css_properties.json5)
24
19
  */
@@ -30,29 +25,6 @@ export var BUILT_IN_PROPERTIES = [{
30
25
  */
31
26
  name: 'display',
32
27
  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
28
  }, {
57
29
  /**
58
30
  * range [0.0, 1.0]
@@ -61,8 +33,7 @@ export var BUILT_IN_PROPERTIES = [{
61
33
  name: 'opacity',
62
34
  interpolable: true,
63
35
  defaultValue: '1',
64
- syntax: PropertySyntax.NUMBER,
65
- handler: CSSPropertyOpacity
36
+ syntax: PropertySyntax.OPACITY_VALUE
66
37
  }, {
67
38
  /**
68
39
  * range [0.0, 1.0]
@@ -72,8 +43,7 @@ export var BUILT_IN_PROPERTIES = [{
72
43
  interpolable: true,
73
44
  inherited: true,
74
45
  defaultValue: '1',
75
- syntax: PropertySyntax.NUMBER,
76
- handler: CSSPropertyOpacity
46
+ syntax: PropertySyntax.OPACITY_VALUE
77
47
  }, {
78
48
  /**
79
49
  * range [0.0, 1.0]
@@ -83,8 +53,7 @@ export var BUILT_IN_PROPERTIES = [{
83
53
  interpolable: true,
84
54
  inherited: true,
85
55
  defaultValue: '1',
86
- syntax: PropertySyntax.NUMBER,
87
- handler: CSSPropertyOpacity
56
+ syntax: PropertySyntax.OPACITY_VALUE
88
57
  }, {
89
58
  /**
90
59
  * background-color is not inheritable
@@ -94,37 +63,32 @@ export var BUILT_IN_PROPERTIES = [{
94
63
  interpolable: true,
95
64
  keywords: ['none'],
96
65
  defaultValue: 'none',
97
- syntax: PropertySyntax.PAINT,
98
- handler: CSSPropertyColor
66
+ syntax: PropertySyntax.PAINT
99
67
  }, {
100
68
  name: 'stroke',
101
69
  interpolable: true,
102
70
  keywords: ['none'],
103
71
  defaultValue: 'none',
104
- syntax: PropertySyntax.PAINT,
105
- handler: CSSPropertyColor
72
+ syntax: PropertySyntax.PAINT
106
73
  }, {
107
74
  name: 'shadowColor',
108
75
  interpolable: true,
109
- syntax: PropertySyntax.COLOR,
110
- handler: CSSPropertyColor
76
+ syntax: PropertySyntax.COLOR
111
77
  }, {
112
78
  name: 'shadowOffsetX',
113
79
  interpolable: true,
114
80
  layoutDependent: true,
115
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
116
- handler: CSSPropertyLengthOrPercentage
81
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
117
82
  }, {
118
83
  name: 'shadowOffsetY',
119
84
  interpolable: true,
120
85
  layoutDependent: true,
121
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
122
- handler: CSSPropertyLengthOrPercentage
86
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
123
87
  }, {
124
88
  name: 'shadowBlur',
125
89
  interpolable: true,
126
90
  layoutDependent: true,
127
- handler: CSSPropertyShadowBlur
91
+ syntax: PropertySyntax.SHADOW_BLUR
128
92
  }, {
129
93
  /**
130
94
  * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width
@@ -135,15 +99,13 @@ export var BUILT_IN_PROPERTIES = [{
135
99
  defaultValue: '1',
136
100
  layoutDependent: true,
137
101
  alias: ['strokeWidth'],
138
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
139
- handler: CSSPropertyLengthOrPercentage
102
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
140
103
  }, {
141
104
  name: 'increasedLineWidthForHitTesting',
142
105
  inherited: true,
143
106
  defaultValue: '0',
144
107
  layoutDependent: true,
145
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
146
- handler: CSSPropertyLengthOrPercentage
108
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
147
109
  }, {
148
110
  name: 'lineJoin',
149
111
  inherited: true,
@@ -164,40 +126,40 @@ export var BUILT_IN_PROPERTIES = [{
164
126
  inherited: true,
165
127
  keywords: ['none'],
166
128
  alias: ['strokeDasharray'],
167
- handler: CSSPropertyLineDash
129
+ syntax: PropertySyntax.LENGTH_PERCENTAGE_12
168
130
  }, {
169
131
  name: 'lineDashOffset',
170
132
  interpolable: true,
171
133
  inherited: true,
172
134
  defaultValue: '0',
173
135
  alias: ['strokeDashoffset'],
174
- handler: CSSPropertyLengthOrPercentage
136
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
175
137
  }, {
176
138
  name: 'offsetPath',
177
- handler: CSSPropertyOffsetPath
139
+ syntax: PropertySyntax.OFFSET_PATH
178
140
  }, {
179
141
  name: 'offsetDistance',
180
142
  interpolable: true,
181
- handler: CSSPropertyOffsetDistance
143
+ syntax: PropertySyntax.OFFSET_DISTANCE
182
144
  }, {
183
145
  name: 'dx',
184
146
  interpolable: true,
185
147
  layoutDependent: true,
186
148
  defaultValue: '0',
187
- handler: CSSPropertyLengthOrPercentage
149
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
188
150
  }, {
189
151
  name: 'dy',
190
152
  interpolable: true,
191
153
  layoutDependent: true,
192
154
  defaultValue: '0',
193
- handler: CSSPropertyLengthOrPercentage
155
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
194
156
  }, {
195
157
  name: 'zIndex',
196
158
  independent: true,
197
159
  interpolable: true,
198
160
  defaultValue: '0',
199
161
  keywords: ['auto'],
200
- handler: CSSPropertyZIndex
162
+ syntax: PropertySyntax.Z_INDEX
201
163
  }, {
202
164
  name: 'visibility',
203
165
  keywords: ['visible', 'hidden'],
@@ -219,49 +181,78 @@ export var BUILT_IN_PROPERTIES = [{
219
181
  name: 'filter',
220
182
  independent: true,
221
183
  layoutDependent: true,
222
- handler: CSSPropertyFilter
184
+ syntax: PropertySyntax.FILTER
223
185
  }, {
224
186
  name: 'clipPath',
225
- handler: CSSPropertyClipPath
187
+ syntax: PropertySyntax.CLIP_PATH
226
188
  }, {
227
189
  name: 'transform',
190
+ parsePriority: 100,
228
191
  interpolable: true,
229
192
  keywords: ['none'],
230
193
  defaultValue: 'none',
231
- handler: CSSPropertyTransform
194
+ syntax: PropertySyntax.TRANSFORM
232
195
  }, {
233
196
  name: 'transformOrigin',
234
197
  parsePriority: 100,
235
198
  // interpolable: true,
236
199
  defaultValue: 'left top',
237
200
  layoutDependent: true,
238
- handler: CSSPropertyTransformOrigin
201
+ syntax: PropertySyntax.TRANSFORM_ORIGIN
239
202
  }, {
240
203
  name: 'anchor',
241
204
  parsePriority: 99,
242
205
  layoutDependent: true,
243
- handler: CSSPropertyAnchor
244
- }, // Circle
206
+ syntax: PropertySyntax.LENGTH_PERCENTAGE_12
207
+ }, // <circle> & <ellipse>
245
208
  {
209
+ name: 'cx',
210
+ interpolable: true,
211
+ defaultValue: '0',
212
+ syntax: PropertySyntax.COORDINATE
213
+ }, {
214
+ name: 'cy',
215
+ interpolable: true,
216
+ defaultValue: '0',
217
+ syntax: PropertySyntax.COORDINATE
218
+ }, {
246
219
  name: 'r',
247
220
  interpolable: true,
248
221
  layoutDependent: true,
249
222
  defaultValue: '0',
250
- handler: CSSPropertyLengthOrPercentage
223
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
251
224
  }, {
252
225
  name: 'rx',
253
226
  interpolable: true,
254
227
  layoutDependent: true,
255
228
  defaultValue: 'auto',
256
- handler: CSSPropertyLengthOrPercentage
229
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
257
230
  }, {
258
231
  name: 'ry',
259
232
  interpolable: true,
260
233
  layoutDependent: true,
261
234
  defaultValue: 'auto',
262
- handler: CSSPropertyLengthOrPercentage
263
- }, // Rect Image
235
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
236
+ }, // Rect Image Group
264
237
  {
238
+ // x in local space
239
+ name: 'x',
240
+ interpolable: true,
241
+ defaultValue: '0',
242
+ syntax: PropertySyntax.COORDINATE
243
+ }, {
244
+ // y in local space
245
+ name: 'y',
246
+ interpolable: true,
247
+ defaultValue: '0',
248
+ syntax: PropertySyntax.COORDINATE
249
+ }, {
250
+ // z in local space
251
+ name: 'z',
252
+ interpolable: true,
253
+ defaultValue: '0',
254
+ syntax: PropertySyntax.COORDINATE
255
+ }, {
265
256
  name: 'width',
266
257
  interpolable: true,
267
258
  layoutDependent: true,
@@ -270,8 +261,8 @@ export var BUILT_IN_PROPERTIES = [{
270
261
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/width
271
262
  */
272
263
  keywords: ['auto', 'fit-content', 'min-content', 'max-content'],
273
- defaultValue: '0',
274
- handler: CSSPropertyLengthOrPercentage
264
+ defaultValue: 'auto',
265
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
275
266
  }, {
276
267
  name: 'height',
277
268
  interpolable: true,
@@ -281,70 +272,71 @@ export var BUILT_IN_PROPERTIES = [{
281
272
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/height
282
273
  */
283
274
  keywords: ['auto', 'fit-content', 'min-content', 'max-content'],
284
- defaultValue: '0',
285
- handler: CSSPropertyLengthOrPercentage
275
+ defaultValue: 'auto',
276
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
286
277
  }, {
287
278
  name: 'radius',
288
279
  interpolable: true,
289
280
  layoutDependent: true,
290
281
  defaultValue: '0',
291
- handler: CSSPropertyLengthOrPercentage
282
+ syntax: PropertySyntax.LENGTH_PERCENTAGE_14
292
283
  }, // Line
293
284
  {
294
285
  name: 'x1',
295
286
  interpolable: true,
296
287
  layoutDependent: true,
297
- handler: CSSPropertyLocalPosition
288
+ syntax: PropertySyntax.COORDINATE
298
289
  }, {
299
290
  name: 'y1',
300
291
  interpolable: true,
301
292
  layoutDependent: true,
302
- handler: CSSPropertyLocalPosition
293
+ syntax: PropertySyntax.COORDINATE
303
294
  }, {
304
295
  name: 'z1',
305
296
  interpolable: true,
306
297
  layoutDependent: true,
307
- handler: CSSPropertyLocalPosition
298
+ syntax: PropertySyntax.COORDINATE
308
299
  }, {
309
300
  name: 'x2',
310
301
  interpolable: true,
311
302
  layoutDependent: true,
312
- handler: CSSPropertyLocalPosition
303
+ syntax: PropertySyntax.COORDINATE
313
304
  }, {
314
305
  name: 'y2',
315
306
  interpolable: true,
316
307
  layoutDependent: true,
317
- handler: CSSPropertyLocalPosition
308
+ syntax: PropertySyntax.COORDINATE
318
309
  }, {
319
310
  name: 'z2',
320
311
  interpolable: true,
321
312
  layoutDependent: true,
322
- handler: CSSPropertyLocalPosition
313
+ syntax: PropertySyntax.COORDINATE
323
314
  }, // Path
324
315
  {
325
316
  name: 'path',
326
317
  interpolable: true,
327
318
  layoutDependent: true,
328
319
  defaultValue: '',
329
- handler: CSSPropertyPath
330
- }, // Polyline
320
+ alias: ['d'],
321
+ syntax: PropertySyntax.PATH
322
+ }, // Polyline & Polygon
331
323
  {
332
324
  name: 'points',
333
325
  layoutDependent: true,
334
- handler: CSSPropertyPoints
326
+ syntax: PropertySyntax.LIST_OF_POINTS
335
327
  }, // Text
336
328
  {
337
329
  name: 'text',
338
330
  layoutDependent: true,
339
- handler: CSSPropertyText,
340
- defaultValue: ''
331
+ defaultValue: '',
332
+ syntax: PropertySyntax.TEXT
341
333
  }, {
342
334
  name: 'textTransform',
343
335
  layoutDependent: true,
344
336
  inherited: true,
345
337
  keywords: ['capitalize', 'uppercase', 'lowercase', 'none'],
346
338
  defaultValue: 'none',
347
- handler: CSSPropertyTextTransform
339
+ syntax: PropertySyntax.TEXT_TRANSFORM
348
340
  }, {
349
341
  name: 'font',
350
342
  layoutDependent: true
@@ -358,7 +350,7 @@ export var BUILT_IN_PROPERTIES = [{
358
350
  */
359
351
  defaultValue: '16px',
360
352
  layoutDependent: true,
361
- handler: CSSPropertyLengthOrPercentage
353
+ syntax: PropertySyntax.LENGTH_PERCENTAGE
362
354
  }, {
363
355
  name: 'fontFamily',
364
356
  layoutDependent: true,
@@ -475,6 +467,10 @@ function () {
475
467
  });
476
468
  };
477
469
 
470
+ DefaultStyleValueRegistry.prototype.unregisterMetadata = function (name) {
471
+ delete this.cache[name];
472
+ };
473
+
478
474
  DefaultStyleValueRegistry.prototype.getMetadata = function (name) {
479
475
  return this.cache[name];
480
476
  };
@@ -526,7 +522,7 @@ function () {
526
522
 
527
523
  if (!skipParse) {
528
524
  sortedNames.forEach(function (name) {
529
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name]);
525
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object);
530
526
  });
531
527
  }
532
528
 
@@ -570,11 +566,11 @@ function () {
570
566
  */
571
567
 
572
568
 
573
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value) {
569
+ DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object) {
574
570
  var metadata = this.getMetadata(name);
575
571
  var computed = value;
576
572
 
577
- if (value === '') {
573
+ if (value === '' || isNil(value)) {
578
574
  value = 'unset';
579
575
  }
580
576
 
@@ -583,7 +579,8 @@ function () {
583
579
  } else {
584
580
  if (metadata) {
585
581
  var keywords = metadata.keywords,
586
- handler = metadata.handler; // use keywords
582
+ syntax = metadata.syntax;
583
+ var handler = syntax && PROPERTY_HANDLERS[syntax]; // use keywords
587
584
 
588
585
  if (keywords && keywords.indexOf(value) > -1) {
589
586
  computed = new CSSKeywordValue(value);
@@ -593,7 +590,7 @@ function () {
593
590
 
594
591
  if (propertyHandler && propertyHandler.parser) {
595
592
  // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
596
- computed = propertyHandler.parser(value);
593
+ computed = propertyHandler.parser(value, object);
597
594
  }
598
595
  }
599
596
  }
@@ -612,7 +609,7 @@ function () {
612
609
  var used = computed instanceof CSSStyleValue ? computed.clone() : computed;
613
610
 
614
611
  if (metadata) {
615
- var handler = metadata.handler,
612
+ var syntax = metadata.syntax,
616
613
  inherited = metadata.inherited,
617
614
  defaultValue = metadata.defaultValue;
618
615
 
@@ -632,8 +629,8 @@ function () {
632
629
 
633
630
  if (value === 'initial') {
634
631
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
635
- if (defaultValue) {
636
- computed = this.parseProperty(name, defaultValue);
632
+ if (!isNil(defaultValue)) {
633
+ computed = this.parseProperty(name, defaultValue, object);
637
634
  }
638
635
  } else if (value === 'inherit') {
639
636
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
@@ -652,6 +649,8 @@ function () {
652
649
  }
653
650
  }
654
651
 
652
+ var handler = syntax && PROPERTY_HANDLERS[syntax];
653
+
655
654
  if (handler) {
656
655
  var propertyHandler = GlobalContainer.get(handler); // convert computed value to used value
657
656
 
@@ -673,8 +672,9 @@ function () {
673
672
  DefaultStyleValueRegistry.prototype.postProcessProperty = function (name, object) {
674
673
  var metadata = this.getMetadata(name);
675
674
 
676
- if (metadata && metadata.handler) {
677
- var propertyHandler = GlobalContainer.get(metadata.handler);
675
+ if (metadata && metadata.syntax) {
676
+ var handler = metadata.syntax && PROPERTY_HANDLERS[metadata.syntax];
677
+ var propertyHandler = GlobalContainer.get(handler);
678
678
 
679
679
  if (propertyHandler && propertyHandler.postProcessor) {
680
680
  propertyHandler.postProcessor(object);
@@ -770,41 +770,23 @@ function () {
770
770
  height = _b.height,
771
771
  _c = _b.depth,
772
772
  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
773
+ _d = _b.offsetX,
774
+ offsetX = _d === void 0 ? 0 : _d,
775
+ _e = _b.offsetY,
776
+ offsetY = _e === void 0 ? 0 : _e,
777
+ _f = _b.offsetZ,
778
+ offsetZ = _f === void 0 ? 0 : _f; // init with content box
797
779
 
798
780
 
799
781
  var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
800
782
 
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;
783
+ var _g = parsedStyle,
784
+ lineWidth = _g.lineWidth,
785
+ increasedLineWidthForHitTesting = _g.increasedLineWidthForHitTesting,
786
+ shadowColor = _g.shadowColor,
787
+ _h = _g.filter,
788
+ filter = _h === void 0 ? [] : _h,
789
+ transformOrigin = _g.transformOrigin;
808
790
  var anchor = parsedStyle.anchor; // <Text> use textAlign & textBaseline instead of anchor
809
791
 
810
792
  if (object.nodeName === Shape.TEXT) {
@@ -820,13 +802,13 @@ function () {
820
802
  geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
821
803
 
822
804
  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;
805
+ var _j = geometry_1.renderBounds,
806
+ min = _j.min,
807
+ max = _j.max;
808
+ var _k = parsedStyle,
809
+ shadowBlur = _k.shadowBlur,
810
+ shadowOffsetX = _k.shadowOffsetX,
811
+ shadowOffsetY = _k.shadowOffsetY;
830
812
  var shadowBlurInPixels = shadowBlur && shadowBlur.value || 0;
831
813
  var shadowOffsetXInPixels = shadowOffsetX && shadowOffsetX.value || 0;
832
814
  var shadowOffsetYInPixels = shadowOffsetY && shadowOffsetY.value || 0;
@@ -1,6 +1,116 @@
1
1
  import { Syringe } from 'mana-syringe';
2
2
  import type { DisplayObject } from '../display-objects';
3
+ /**
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
5
+ */
6
+ export declare enum PropertySyntax {
7
+ /**
8
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate
9
+ */
10
+ COORDINATE = "<coordinate>",
11
+ /**
12
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color
13
+ */
14
+ COLOR = "<color>",
15
+ /**
16
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint
17
+ */
18
+ PAINT = "<paint>",
19
+ /**
20
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number
21
+ */
22
+ NUMBER = "<number>",
23
+ /**
24
+ * <number> with range 0..1
25
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value
26
+ */
27
+ OPACITY_VALUE = "<opacity-value>",
28
+ /**
29
+ * <number> with range 0..Infinity
30
+ */
31
+ SHADOW_BLUR = "<shadow-blur>",
32
+ /**
33
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
34
+ */
35
+ LENGTH = "<length>",
36
+ /**
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage
38
+ */
39
+ PERCENTAGE = "<percentage>",
40
+ LENGTH_PERCENTAGE = "<length> | <percentage>",
41
+ LENGTH_PERCENTAGE_12 = "[<length> | <percentage>]{1,2}",
42
+ /**
43
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax
44
+ */
45
+ LENGTH_PERCENTAGE_14 = "[<length> | <percentage>]{1,4}",
46
+ /**
47
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts
48
+ */
49
+ LIST_OF_POINTS = "<list-of-points>",
50
+ PATH = "<path>",
51
+ /**
52
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax
53
+ */
54
+ FILTER = "<filter>",
55
+ Z_INDEX = "<z-index>",
56
+ OFFSET_PATH = "<offset-path>",
57
+ OFFSET_DISTANCE = "<offset-distance>",
58
+ CLIP_PATH = "<clip-path>",
59
+ TRANSFORM = "<transform>",
60
+ TRANSFORM_ORIGIN = "<transform-origin>",
61
+ TEXT = "<text>",
62
+ TEXT_TRANSFORM = "<text-transform>"
63
+ }
64
+ export interface PropertyMetadata {
65
+ name: string;
66
+ /**
67
+ * The interpolable flag indicates whether a property can be animated smoothly.
68
+ * Default to `false`.
69
+ */
70
+ interpolable?: boolean;
71
+ /**
72
+ * The property will inherit by default if no value is specified.
73
+ * Default to `false`.
74
+ */
75
+ inherited?: boolean;
76
+ /**
77
+ * This property affects only one field on ComputedStyle, and can be set
78
+ * directly during inheritance instead of forcing a recalc.
79
+ */
80
+ independent?: boolean;
81
+ /**
82
+ * This specifies the default value for this field.
83
+ * - for keyword fields, this is the initial keyword
84
+ * - for other fields, this is a string containg the C++ expression that is used to initialise the field.
85
+ */
86
+ defaultValue?: string;
87
+ /**
88
+ * The resolved value used for getComputedStyle() depends on layout for this
89
+ * property, which means we may need to update layout to return the correct
90
+ * value from getComputedStyle().
91
+ */
92
+ layoutDependent?: boolean;
93
+ /**
94
+ * This specifies all valid keyword values for the property.
95
+ */
96
+ keywords?: string[];
97
+ /**
98
+ * eg. strokeWidth is an alias of lineWidth
99
+ */
100
+ alias?: string[];
101
+ /**
102
+ * sort before init attributes according to this priority
103
+ */
104
+ parsePriority?: number;
105
+ /**
106
+ * eg. <color> <paint> <number>
107
+ */
108
+ syntax?: string;
109
+ }
3
110
  export declare const StyleValueRegistry: Syringe.DefinedToken;
4
111
  export interface StyleValueRegistry {
5
112
  recalc: (displayObject: DisplayObject) => void;
113
+ registerMetadata: (metadata: PropertyMetadata) => void;
114
+ unregisterMetadata: (name: string) => void;
115
+ getMetadata: (name: string) => PropertyMetadata;
6
116
  }