@antv/g 5.0.23 → 5.1.1

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 (230) hide show
  1. package/dist/index.umd.min.js +3 -2
  2. package/es/AbstractRenderer.d.ts +11 -0
  3. package/es/AbstractRenderer.js +17 -2
  4. package/es/Canvas.d.ts +1 -1
  5. package/es/Canvas.js +2 -0
  6. package/es/components/Geometry.d.ts +0 -4
  7. package/es/css/CSS.d.ts +2 -1
  8. package/es/css/CSS.js +5 -1
  9. package/es/css/CSSProperty.d.ts +2 -1
  10. package/es/css/StyleValueRegistry.d.ts +2 -1
  11. package/es/css/StyleValueRegistry.js +71 -88
  12. package/es/css/index.d.ts +1 -1
  13. package/es/css/index.js +1 -1
  14. package/es/css/layout/FragmentResult.d.ts +32 -0
  15. package/es/css/layout/FragmentResult.js +32 -0
  16. package/es/css/layout/LayoutChildren.d.ts +23 -0
  17. package/es/css/layout/LayoutChildren.js +55 -0
  18. package/es/css/layout/LayoutContext.d.ts +35 -0
  19. package/es/css/layout/LayoutContext.js +35 -0
  20. package/es/css/layout/LayoutDefinition.d.ts +20 -0
  21. package/es/css/layout/LayoutDefinition.js +9 -0
  22. package/es/css/layout/LayoutEdges.d.ts +24 -0
  23. package/es/css/layout/LayoutEdges.js +41 -0
  24. package/es/css/layout/LayoutEngine.d.ts +41 -0
  25. package/es/css/layout/LayoutEngine.js +332 -0
  26. package/es/css/layout/LayoutFragment.d.ts +26 -0
  27. package/es/css/layout/LayoutFragment.js +28 -0
  28. package/es/css/layout/LayoutObject.d.ts +46 -0
  29. package/es/css/layout/LayoutObject.js +172 -0
  30. package/es/css/layout/LayoutRegistry.d.ts +16 -0
  31. package/es/css/layout/LayoutRegistry.js +78 -0
  32. package/es/css/layout/LayoutWorkTask.d.ts +14 -0
  33. package/es/css/layout/LayoutWorkTask.js +1 -0
  34. package/es/css/layout/index.d.ts +11 -0
  35. package/es/css/layout/index.js +11 -0
  36. package/es/css/layout/types.d.ts +104 -0
  37. package/es/css/layout/types.js +66 -0
  38. package/es/css/parser/color.d.ts +1 -1
  39. package/es/css/parser/color.js +2 -2
  40. package/es/css/parser/dimension.js +5 -1
  41. package/es/css/parser/path.d.ts +2 -2
  42. package/es/css/parser/path.js +9 -2
  43. package/es/css/parser/points.d.ts +8 -1
  44. package/es/css/parser/points.js +33 -3
  45. package/es/css/parser/transform.js +1 -1
  46. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  47. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  48. package/es/css/properties/CSSPropertyLocalPosition.js +59 -20
  49. package/es/css/properties/CSSPropertyPath.d.ts +2 -2
  50. package/es/css/properties/CSSPropertyPath.js +7 -5
  51. package/es/css/properties/CSSPropertyPoints.js +3 -4
  52. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  53. package/es/css/properties/CSSPropertyTransform.js +76 -104
  54. package/es/display-objects/Circle.d.ts +4 -0
  55. package/es/display-objects/Circle.js +2 -0
  56. package/es/display-objects/CustomElement.d.ts +6 -2
  57. package/es/display-objects/CustomElement.js +15 -5
  58. package/es/display-objects/DisplayObject.d.ts +1 -7
  59. package/es/display-objects/DisplayObject.js +6 -26
  60. package/es/display-objects/Ellipse.d.ts +4 -0
  61. package/es/display-objects/Ellipse.js +2 -0
  62. package/es/display-objects/Group.d.ts +4 -0
  63. package/es/display-objects/Group.js +2 -0
  64. package/es/display-objects/HTML.d.ts +4 -4
  65. package/es/display-objects/HTML.js +5 -3
  66. package/es/display-objects/Image.d.ts +4 -0
  67. package/es/display-objects/Image.js +2 -0
  68. package/es/display-objects/Line.js +2 -0
  69. package/es/display-objects/Path.d.ts +2 -2
  70. package/es/display-objects/Polygon.js +1 -1
  71. package/es/display-objects/Polyline.js +1 -1
  72. package/es/display-objects/Rect.d.ts +6 -2
  73. package/es/display-objects/Rect.js +2 -0
  74. package/es/display-objects/Text.d.ts +4 -0
  75. package/es/display-objects/Text.js +2 -0
  76. package/es/dom/Element.js +1 -0
  77. package/es/global-module.js +87 -1
  78. package/es/index.d.ts +3 -0
  79. package/es/index.js +3 -0
  80. package/es/services/EventService.js +10 -2
  81. package/es/services/OffscreenCanvasCreator.d.ts +1 -1
  82. package/es/services/OffscreenCanvasCreator.js +1 -1
  83. package/es/services/RenderingService.d.ts +1 -1
  84. package/es/services/RenderingService.js +1 -1
  85. package/es/services/SceneGraphService.d.ts +2 -0
  86. package/es/services/SceneGraphService.js +9 -0
  87. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  88. package/es/services/aabb/CircleUpdater.js +2 -6
  89. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  90. package/es/services/aabb/EllipseUpdater.js +2 -6
  91. package/es/services/aabb/LineUpdater.d.ts +0 -2
  92. package/es/services/aabb/LineUpdater.js +1 -3
  93. package/es/services/aabb/PathUpdater.d.ts +0 -2
  94. package/es/services/aabb/PathUpdater.js +1 -5
  95. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  96. package/es/services/aabb/PolylineUpdater.js +1 -3
  97. package/es/services/aabb/RectUpdater.d.ts +0 -2
  98. package/es/services/aabb/RectUpdater.js +1 -5
  99. package/es/services/aabb/TextUpdater.d.ts +7 -0
  100. package/es/services/aabb/TextUpdater.js +0 -4
  101. package/es/services/aabb/interfaces.d.ts +0 -3
  102. package/es/types.d.ts +7 -23
  103. package/es/types.js +1 -0
  104. package/es/utils/deferred.d.ts +43 -0
  105. package/es/utils/deferred.js +117 -0
  106. package/es/utils/dom.d.ts +2 -0
  107. package/es/utils/dom.js +8 -0
  108. package/es/utils/index.d.ts +2 -0
  109. package/es/utils/index.js +3 -1
  110. package/es/utils/interpolation.js +2 -8
  111. package/es/utils/math.js +4 -3
  112. package/es/utils/path.d.ts +2 -2
  113. package/es/utils/path.js +61 -24
  114. package/lib/AbstractRenderer.d.ts +11 -0
  115. package/lib/AbstractRenderer.js +17 -2
  116. package/lib/Canvas.d.ts +1 -1
  117. package/lib/Canvas.js +2 -0
  118. package/lib/components/Geometry.d.ts +0 -4
  119. package/lib/css/CSS.d.ts +2 -1
  120. package/lib/css/CSS.js +7 -1
  121. package/lib/css/CSSProperty.d.ts +2 -1
  122. package/lib/css/StyleValueRegistry.d.ts +2 -1
  123. package/lib/css/StyleValueRegistry.js +70 -88
  124. package/lib/css/index.d.ts +1 -1
  125. package/lib/css/index.js +12 -12
  126. package/lib/css/layout/FragmentResult.d.ts +32 -0
  127. package/lib/css/layout/FragmentResult.js +51 -0
  128. package/lib/css/layout/LayoutChildren.d.ts +23 -0
  129. package/lib/css/layout/LayoutChildren.js +72 -0
  130. package/lib/css/layout/LayoutContext.d.ts +35 -0
  131. package/lib/css/layout/LayoutContext.js +49 -0
  132. package/lib/css/layout/LayoutDefinition.d.ts +20 -0
  133. package/lib/css/layout/LayoutDefinition.js +16 -0
  134. package/lib/css/layout/LayoutEdges.d.ts +24 -0
  135. package/lib/css/layout/LayoutEdges.js +56 -0
  136. package/lib/css/layout/LayoutEngine.d.ts +41 -0
  137. package/lib/css/layout/LayoutEngine.js +345 -0
  138. package/lib/css/layout/LayoutFragment.d.ts +26 -0
  139. package/lib/css/layout/LayoutFragment.js +44 -0
  140. package/lib/css/layout/LayoutObject.d.ts +46 -0
  141. package/lib/css/layout/LayoutObject.js +182 -0
  142. package/lib/css/layout/LayoutRegistry.d.ts +16 -0
  143. package/lib/css/layout/LayoutRegistry.js +87 -0
  144. package/lib/css/layout/LayoutWorkTask.d.ts +14 -0
  145. package/lib/css/layout/LayoutWorkTask.js +5 -0
  146. package/lib/css/layout/index.d.ts +11 -0
  147. package/lib/css/layout/index.js +148 -0
  148. package/lib/css/layout/types.d.ts +104 -0
  149. package/lib/css/layout/types.js +74 -0
  150. package/lib/css/parser/color.d.ts +1 -1
  151. package/lib/css/parser/color.js +1 -1
  152. package/lib/css/parser/dimension.js +4 -0
  153. package/lib/css/parser/path.d.ts +2 -2
  154. package/lib/css/parser/path.js +9 -2
  155. package/lib/css/parser/points.d.ts +8 -1
  156. package/lib/css/parser/points.js +33 -3
  157. package/lib/css/parser/transform.js +1 -1
  158. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  159. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  160. package/lib/css/properties/CSSPropertyLocalPosition.js +60 -20
  161. package/lib/css/properties/CSSPropertyPath.d.ts +2 -2
  162. package/lib/css/properties/CSSPropertyPath.js +7 -5
  163. package/lib/css/properties/CSSPropertyPoints.js +3 -4
  164. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  165. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  166. package/lib/display-objects/Circle.d.ts +4 -0
  167. package/lib/display-objects/Circle.js +2 -0
  168. package/lib/display-objects/CustomElement.d.ts +6 -2
  169. package/lib/display-objects/CustomElement.js +13 -4
  170. package/lib/display-objects/DisplayObject.d.ts +1 -7
  171. package/lib/display-objects/DisplayObject.js +6 -27
  172. package/lib/display-objects/Ellipse.d.ts +4 -0
  173. package/lib/display-objects/Ellipse.js +2 -0
  174. package/lib/display-objects/Group.d.ts +4 -0
  175. package/lib/display-objects/Group.js +2 -0
  176. package/lib/display-objects/HTML.d.ts +4 -4
  177. package/lib/display-objects/HTML.js +5 -3
  178. package/lib/display-objects/Image.d.ts +4 -0
  179. package/lib/display-objects/Image.js +2 -0
  180. package/lib/display-objects/Line.js +2 -0
  181. package/lib/display-objects/Path.d.ts +2 -2
  182. package/lib/display-objects/Polygon.js +1 -1
  183. package/lib/display-objects/Polyline.js +1 -1
  184. package/lib/display-objects/Rect.d.ts +6 -2
  185. package/lib/display-objects/Rect.js +2 -0
  186. package/lib/display-objects/Text.d.ts +4 -0
  187. package/lib/display-objects/Text.js +2 -0
  188. package/lib/dom/Element.js +1 -0
  189. package/lib/global-module.js +89 -1
  190. package/lib/index.d.ts +3 -0
  191. package/lib/index.js +7 -2
  192. package/lib/services/EventService.js +10 -2
  193. package/lib/services/OffscreenCanvasCreator.d.ts +1 -1
  194. package/lib/services/OffscreenCanvasCreator.js +1 -1
  195. package/lib/services/RenderingService.d.ts +1 -1
  196. package/lib/services/RenderingService.js +1 -1
  197. package/lib/services/SceneGraphService.d.ts +2 -0
  198. package/lib/services/SceneGraphService.js +12 -0
  199. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  200. package/lib/services/aabb/CircleUpdater.js +2 -6
  201. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  202. package/lib/services/aabb/EllipseUpdater.js +2 -6
  203. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  204. package/lib/services/aabb/LineUpdater.js +1 -3
  205. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  206. package/lib/services/aabb/PathUpdater.js +1 -5
  207. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  208. package/lib/services/aabb/PolylineUpdater.js +1 -3
  209. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  210. package/lib/services/aabb/RectUpdater.js +1 -5
  211. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  212. package/lib/services/aabb/TextUpdater.js +0 -4
  213. package/lib/services/aabb/interfaces.d.ts +0 -3
  214. package/lib/types.d.ts +7 -23
  215. package/lib/types.js +1 -0
  216. package/lib/utils/deferred.d.ts +43 -0
  217. package/lib/utils/deferred.js +131 -0
  218. package/lib/utils/dom.d.ts +2 -0
  219. package/lib/utils/dom.js +17 -0
  220. package/lib/utils/index.d.ts +2 -0
  221. package/lib/utils/index.js +26 -0
  222. package/lib/utils/interpolation.js +2 -8
  223. package/lib/utils/math.js +4 -3
  224. package/lib/utils/path.d.ts +2 -2
  225. package/lib/utils/path.js +55 -24
  226. package/package.json +3 -3
  227. package/es/css/LayoutRegistry.d.ts +0 -11
  228. package/es/css/LayoutRegistry.js +0 -22
  229. package/lib/css/LayoutRegistry.d.ts +0 -11
  230. package/lib/css/LayoutRegistry.js +0 -30
@@ -1,6 +1,7 @@
1
1
  import type { Syringe } from 'mana-syringe';
2
2
  import type { RendererConfig } from './types';
3
3
  export interface RendererPlugin {
4
+ name: string;
4
5
  init: (container: Syringe.Container) => void;
5
6
  destroy: (container: Syringe.Container) => void;
6
7
  }
@@ -10,6 +11,14 @@ export interface IRenderer {
10
11
  * register plugin at runtime
11
12
  */
12
13
  registerPlugin: (plugin: RendererPlugin) => void;
14
+ /**
15
+ * unregister plugin at runtime
16
+ */
17
+ unregisterPlugin: (plugin: RendererPlugin) => void;
18
+ /**
19
+ * get plugin by name
20
+ */
21
+ getPlugin: (name: string) => RendererPlugin;
13
22
  /**
14
23
  * return all registered plugins
15
24
  */
@@ -20,7 +29,9 @@ export declare class AbstractRenderer implements IRenderer {
20
29
  private config;
21
30
  constructor(config?: Partial<RendererConfig>);
22
31
  registerPlugin(plugin: RendererPlugin): void;
32
+ unregisterPlugin(plugin: RendererPlugin): void;
23
33
  getPlugins(): RendererPlugin[];
34
+ getPlugin(name: string): RendererPlugin;
24
35
  getConfig(): RendererConfig;
25
36
  setConfig(config: Partial<RendererConfig>): void;
26
37
  }
@@ -20,8 +20,7 @@ function () {
20
20
  * enable dirty rectangle rendering by default
21
21
  */
22
22
  enableDirtyRectangleRendering: true,
23
- enableDirtyRectangleRenderingDebug: false,
24
- enableTAA: false
23
+ enableDirtyRectangleRenderingDebug: false
25
24
  }, config);
26
25
  }
27
26
 
@@ -29,10 +28,26 @@ function () {
29
28
  this.plugins.push(plugin);
30
29
  };
31
30
 
31
+ AbstractRenderer.prototype.unregisterPlugin = function (plugin) {
32
+ var index = this.plugins.findIndex(function (p) {
33
+ return p === plugin;
34
+ });
35
+
36
+ if (index > -1) {
37
+ this.plugins.splice(index, 1);
38
+ }
39
+ };
40
+
32
41
  AbstractRenderer.prototype.getPlugins = function () {
33
42
  return this.plugins;
34
43
  };
35
44
 
45
+ AbstractRenderer.prototype.getPlugin = function (name) {
46
+ return this.plugins.find(function (plugin) {
47
+ return plugin.name === name;
48
+ });
49
+ };
50
+
36
51
  AbstractRenderer.prototype.getConfig = function () {
37
52
  return this.config;
38
53
  };
package/es/Canvas.d.ts CHANGED
@@ -96,7 +96,7 @@ export declare class Canvas extends EventTarget implements ICanvas {
96
96
  * get the root displayObject in scenegraph
97
97
  * @alias this.document.documentElement
98
98
  */
99
- getRoot(): import("./display-objects").Group;
99
+ getRoot(): import(".").Group;
100
100
  /**
101
101
  * get the camera of canvas
102
102
  */
package/es/Canvas.js CHANGED
@@ -94,6 +94,8 @@ function (_super) {
94
94
  /**
95
95
  * limits query
96
96
  */
97
+ // the following feature-detect from hammer.js
98
+ // @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
97
99
 
98
100
  _this.supportTouchEvent = supportTouchEvent !== null && supportTouchEvent !== void 0 ? supportTouchEvent : 'ontouchstart' in globalThis;
99
101
  _this.supportPointerEvent = supportPointerEvent !== null && supportPointerEvent !== void 0 ? supportPointerEvent : !!globalThis.PointerEvent;
@@ -9,8 +9,4 @@ export declare class Geometry {
9
9
  * including extra rendering effects, eg. shadowBlur filters(drop-shadow, blur)
10
10
  */
11
11
  renderBounds: AABB | undefined;
12
- /**
13
- * account for `hitArea` & `increasedLineWidthForHitTesting`
14
- */
15
- hitAreaBounds: AABB | undefined;
16
12
  }
package/es/css/CSS.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CSSUnitValue } from './cssom';
2
+ import type { LayoutDefinitionCtor } from './layout';
2
3
  /**
3
4
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty#parameters
4
5
  */
@@ -80,5 +81,5 @@ export declare const CSS: {
80
81
  * @see https://github.com/w3c/css-houdini-drafts/blob/main/css-layout-api/EXPLAINER.md
81
82
  * @see https://developer.mozilla.org/en-US/docs/Web/Guide/Houdini#css_layout_api
82
83
  */
83
- registerLayout: (name: string) => void;
84
+ registerLayout: (name: string, clazz: LayoutDefinitionCtor) => void;
84
85
  };
package/es/css/CSS.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { GlobalContainer } from 'mana-syringe';
2
2
  import { CSSUnitValue } from './cssom';
3
3
  import { StyleValueRegistry } from './interfaces';
4
+ import { LayoutRegistry } from './layout';
4
5
  /**
5
6
  * holds useful CSS-related methods.
6
7
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS
@@ -109,5 +110,8 @@ export var CSS = {
109
110
  * @see https://github.com/w3c/css-houdini-drafts/blob/main/css-layout-api/EXPLAINER.md
110
111
  * @see https://developer.mozilla.org/en-US/docs/Web/Guide/Houdini#css_layout_api
111
112
  */
112
- registerLayout: function registerLayout(name) {}
113
+ registerLayout: function registerLayout(name, clazz) {
114
+ var layoutRegistry = GlobalContainer.get(LayoutRegistry);
115
+ layoutRegistry.registerLayout(name, clazz);
116
+ }
113
117
  };
@@ -1,8 +1,9 @@
1
+ import type { DisplayObject } from '../display-objects';
1
2
  import type { IElement } from '../dom';
2
3
  import type { StyleValueRegistry } from './interfaces';
3
4
  export declare type Interpolatable = number | boolean | number[] | boolean[];
4
5
  declare type CSSPropertyMixer<Parsed = any, T extends Interpolatable = any> = (left: Parsed, right: Parsed, displayObject: IElement | null) => [T, T, (i: T) => string | any] | undefined;
5
- declare type CSSPropertyParser<Parsed> = (value: string | any) => Parsed;
6
+ declare type CSSPropertyParser<Parsed> = (value: string | any, object: DisplayObject) => Parsed;
6
7
  declare type CSSPropertyCalculator<Parsed, Used> = (name: string, oldParsed: Parsed, parsed: Parsed, object: IElement, registry: StyleValueRegistry) => Used;
7
8
  /**
8
9
  * 1. parser: raw CSS string -> Computed Value
@@ -14,6 +14,7 @@ export declare const PropertySyntax: {
14
14
  LENGTH: string;
15
15
  PERCENTAGE: string;
16
16
  LENGTH_PERCENTAGE: string;
17
+ LIST_OF_POINTS: string;
17
18
  };
18
19
  export interface PropertyMetadata {
19
20
  name: string;
@@ -99,7 +100,7 @@ export declare class DefaultStyleValueRegistry implements StyleValueRegistry {
99
100
  /**
100
101
  * string -> parsed value
101
102
  */
102
- parseProperty(name: string, value: any): CSSStyleValue;
103
+ parseProperty(name: string, value: any, object: DisplayObject): CSSStyleValue;
103
104
  /**
104
105
  * computed value -> used value
105
106
  */
@@ -8,7 +8,7 @@ import { Shape } from '../types';
8
8
  import { CSSKeywordValue, CSSStyleValue, CSSUnitValue } from './cssom';
9
9
  import { convertPercentUnit } from './parser';
10
10
  import { CSSPropertyLocalPosition, CSSPropertyOpacity, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLineDash, CSSPropertyShadowBlur, CSSPropertyOffsetPath, CSSPropertyOffsetDistance, CSSPropertyAnchor, CSSPropertyZIndex, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyPath, CSSPropertyClipPath, CSSPropertyPoints, CSSPropertyText, CSSPropertyTextTransform } from './properties';
11
- import { formatAttribute } from '../utils';
11
+ import { formatAttribute, isNil } from '../utils';
12
12
  import { AABB } from '../shapes';
13
13
  import { StyleValueRegistry } from './interfaces';
14
14
  export var PropertySyntax = {
@@ -17,7 +17,8 @@ export var PropertySyntax = {
17
17
  NUMBER: '<number>',
18
18
  LENGTH: '<length>',
19
19
  PERCENTAGE: '<percentage>',
20
- LENGTH_PERCENTAGE: '<length> | <percentage>'
20
+ LENGTH_PERCENTAGE: '<length> | <percentage>',
21
+ LIST_OF_POINTS: '<list-of-points>'
21
22
  };
22
23
  /**
23
24
  * Blink used them in code generation(css_properties.json5)
@@ -30,29 +31,6 @@ export var BUILT_IN_PROPERTIES = [{
30
31
  */
31
32
  name: 'display',
32
33
  keywords: ['none']
33
- }, {
34
- // x in local space
35
- name: 'x',
36
- interpolable: true,
37
- alias: ['cx'],
38
- defaultValue: '0',
39
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
40
- handler: CSSPropertyLocalPosition
41
- }, {
42
- // y in local space
43
- name: 'y',
44
- interpolable: true,
45
- alias: ['cy'],
46
- defaultValue: '0',
47
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
48
- handler: CSSPropertyLocalPosition
49
- }, {
50
- // z in local space
51
- name: 'z',
52
- interpolable: true,
53
- defaultValue: '0',
54
- syntax: PropertySyntax.LENGTH_PERCENTAGE,
55
- handler: CSSPropertyLocalPosition
56
34
  }, {
57
35
  /**
58
36
  * range [0.0, 1.0]
@@ -142,7 +120,6 @@ export var BUILT_IN_PROPERTIES = [{
142
120
  inherited: true,
143
121
  defaultValue: '0',
144
122
  layoutDependent: true,
145
- alias: ['lineAppendWidth'],
146
123
  syntax: PropertySyntax.LENGTH_PERCENTAGE,
147
124
  handler: CSSPropertyLengthOrPercentage
148
125
  }, {
@@ -226,6 +203,7 @@ export var BUILT_IN_PROPERTIES = [{
226
203
  handler: CSSPropertyClipPath
227
204
  }, {
228
205
  name: 'transform',
206
+ parsePriority: 100,
229
207
  interpolable: true,
230
208
  keywords: ['none'],
231
209
  defaultValue: 'none',
@@ -242,8 +220,20 @@ export var BUILT_IN_PROPERTIES = [{
242
220
  parsePriority: 99,
243
221
  layoutDependent: true,
244
222
  handler: CSSPropertyAnchor
245
- }, // Circle
223
+ }, // <circle> & <ellipse>
246
224
  {
225
+ name: 'cx',
226
+ interpolable: true,
227
+ defaultValue: '0',
228
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
229
+ handler: CSSPropertyLocalPosition
230
+ }, {
231
+ name: 'cy',
232
+ interpolable: true,
233
+ defaultValue: '0',
234
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
235
+ handler: CSSPropertyLocalPosition
236
+ }, {
247
237
  name: 'r',
248
238
  interpolable: true,
249
239
  layoutDependent: true,
@@ -261,8 +251,29 @@ export var BUILT_IN_PROPERTIES = [{
261
251
  layoutDependent: true,
262
252
  defaultValue: 'auto',
263
253
  handler: CSSPropertyLengthOrPercentage
264
- }, // Rect Image
254
+ }, // Rect Image Group
265
255
  {
256
+ // x in local space
257
+ name: 'x',
258
+ interpolable: true,
259
+ defaultValue: '0',
260
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
261
+ handler: CSSPropertyLocalPosition
262
+ }, {
263
+ // y in local space
264
+ name: 'y',
265
+ interpolable: true,
266
+ defaultValue: '0',
267
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
268
+ handler: CSSPropertyLocalPosition
269
+ }, {
270
+ // z in local space
271
+ name: 'z',
272
+ interpolable: true,
273
+ defaultValue: '0',
274
+ syntax: PropertySyntax.LENGTH_PERCENTAGE,
275
+ handler: CSSPropertyLocalPosition
276
+ }, {
266
277
  name: 'width',
267
278
  interpolable: true,
268
279
  layoutDependent: true,
@@ -327,11 +338,13 @@ export var BUILT_IN_PROPERTIES = [{
327
338
  interpolable: true,
328
339
  layoutDependent: true,
329
340
  defaultValue: '',
341
+ alias: ['d'],
330
342
  handler: CSSPropertyPath
331
- }, // Polyline
343
+ }, // Polyline & Polygon
332
344
  {
333
345
  name: 'points',
334
346
  layoutDependent: true,
347
+ syntax: PropertySyntax.LIST_OF_POINTS,
335
348
  handler: CSSPropertyPoints
336
349
  }, // Text
337
350
  {
@@ -527,7 +540,7 @@ function () {
527
540
 
528
541
  if (!skipParse) {
529
542
  sortedNames.forEach(function (name) {
530
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name]);
543
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object);
531
544
  });
532
545
  }
533
546
 
@@ -571,11 +584,11 @@ function () {
571
584
  */
572
585
 
573
586
 
574
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value) {
587
+ DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object) {
575
588
  var metadata = this.getMetadata(name);
576
589
  var computed = value;
577
590
 
578
- if (value === '') {
591
+ if (value === '' || isNil(value)) {
579
592
  value = 'unset';
580
593
  }
581
594
 
@@ -594,7 +607,7 @@ function () {
594
607
 
595
608
  if (propertyHandler && propertyHandler.parser) {
596
609
  // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
597
- computed = propertyHandler.parser(value);
610
+ computed = propertyHandler.parser(value, object);
598
611
  }
599
612
  }
600
613
  }
@@ -633,8 +646,8 @@ function () {
633
646
 
634
647
  if (value === 'initial') {
635
648
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/initial
636
- if (defaultValue) {
637
- computed = this.parseProperty(name, defaultValue);
649
+ if (!isNil(defaultValue)) {
650
+ computed = this.parseProperty(name, defaultValue, object);
638
651
  }
639
652
  } else if (value === 'inherit') {
640
653
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
@@ -764,10 +777,6 @@ function () {
764
777
  geometry_1.renderBounds = new AABB();
765
778
  }
766
779
 
767
- if (!geometry_1.hitAreaBounds) {
768
- geometry_1.hitAreaBounds = new AABB();
769
- }
770
-
771
780
  var parsedStyle = object.parsedStyle;
772
781
 
773
782
  var _b = geometryUpdater.update(parsedStyle, object),
@@ -775,41 +784,23 @@ function () {
775
784
  height = _b.height,
776
785
  _c = _b.depth,
777
786
  depth = _c === void 0 ? 0 : _c,
778
- _d = _b.x,
779
- x = _d === void 0 ? 0 : _d,
780
- _e = _b.y,
781
- y = _e === void 0 ? 0 : _e,
782
- // z = 0,
783
- _f = _b.offsetX,
784
- // z = 0,
785
- offsetX = _f === void 0 ? 0 : _f,
786
- _g = _b.offsetY,
787
- offsetY = _g === void 0 ? 0 : _g,
788
- _h = _b.offsetZ,
789
- offsetZ = _h === void 0 ? 0 : _h;
790
-
791
- if (object.nodeName === Shape.LINE || object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH) {
792
- parsedStyle.offsetX = x - (parsedStyle.defX || 0);
793
- parsedStyle.offsetY = y - (parsedStyle.defY || 0);
794
- parsedStyle.defX = x;
795
- parsedStyle.defY = y; // modify x/y/z
796
-
797
- object.attributes.x += parsedStyle.offsetX;
798
- object.attributes.y += parsedStyle.offsetY;
799
- parsedStyle.x = parsedStyle.x.add(new CSSUnitValue(parsedStyle.offsetX, 'px'));
800
- parsedStyle.y = parsedStyle.y.add(new CSSUnitValue(parsedStyle.offsetY, 'px'));
801
- } // init with content box
787
+ _d = _b.offsetX,
788
+ offsetX = _d === void 0 ? 0 : _d,
789
+ _e = _b.offsetY,
790
+ offsetY = _e === void 0 ? 0 : _e,
791
+ _f = _b.offsetZ,
792
+ offsetZ = _f === void 0 ? 0 : _f; // init with content box
802
793
 
803
794
 
804
795
  var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
805
796
 
806
- var _j = parsedStyle,
807
- lineWidth = _j.lineWidth,
808
- increasedLineWidthForHitTesting = _j.increasedLineWidthForHitTesting,
809
- shadowColor = _j.shadowColor,
810
- _k = _j.filter,
811
- filter = _k === void 0 ? [] : _k,
812
- transformOrigin = _j.transformOrigin;
797
+ var _g = parsedStyle,
798
+ lineWidth = _g.lineWidth,
799
+ increasedLineWidthForHitTesting = _g.increasedLineWidthForHitTesting,
800
+ shadowColor = _g.shadowColor,
801
+ _h = _g.filter,
802
+ filter = _h === void 0 ? [] : _h,
803
+ transformOrigin = _g.transformOrigin;
813
804
  var anchor = parsedStyle.anchor; // <Text> use textAlign & textBaseline instead of anchor
814
805
 
815
806
  if (object.nodeName === Shape.TEXT) {
@@ -819,27 +810,19 @@ function () {
819
810
  var center = vec3.fromValues((1 - (anchor && anchor[0].value || 0) * 2) * halfExtents[0] + offsetX, (1 - (anchor && anchor[1].value || 0) * 2) * halfExtents[1] + offsetY, (1 - (anchor && ((_a = anchor[2]) === null || _a === void 0 ? void 0 : _a.value) || 0) * 2) * halfExtents[2] + offsetZ); // update geometry's AABB
820
811
 
821
812
  geometry_1.contentBounds.update(center, halfExtents);
813
+ var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2; // append border
822
814
 
823
- if (lineWidth) {
824
- // append border
825
- vec3.add(halfExtents, halfExtents, vec3.fromValues(lineWidth.value / 2, lineWidth.value / 2, 0));
826
- geometry_1.renderBounds.update(center, halfExtents);
827
- }
828
-
829
- if (increasedLineWidthForHitTesting) {
830
- vec3.add(halfExtents, halfExtents, vec3.fromValues(increasedLineWidthForHitTesting.value / 2, increasedLineWidthForHitTesting.value / 2, 0));
831
- geometry_1.hitAreaBounds.update(center, halfExtents);
832
- } // account for shadow, only support constant value now
833
-
815
+ vec3.add(halfExtents, halfExtents, vec3.fromValues(halfLineWidth, halfLineWidth, 0));
816
+ geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
834
817
 
835
818
  if (shadowColor) {
836
- var _l = geometry_1.renderBounds,
837
- min = _l.min,
838
- max = _l.max;
839
- var _m = parsedStyle,
840
- shadowBlur = _m.shadowBlur,
841
- shadowOffsetX = _m.shadowOffsetX,
842
- shadowOffsetY = _m.shadowOffsetY;
819
+ var _j = geometry_1.renderBounds,
820
+ min = _j.min,
821
+ max = _j.max;
822
+ var _k = parsedStyle,
823
+ shadowBlur = _k.shadowBlur,
824
+ shadowOffsetX = _k.shadowOffsetX,
825
+ shadowOffsetY = _k.shadowOffsetY;
843
826
  var shadowBlurInPixels = shadowBlur && shadowBlur.value || 0;
844
827
  var shadowOffsetXInPixels = shadowOffsetX && shadowOffsetX.value || 0;
845
828
  var shadowOffsetYInPixels = shadowOffsetY && shadowOffsetY.value || 0;
package/es/css/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export * from './interfaces';
5
5
  export * from './cssom';
6
6
  export * from './parser';
7
7
  export * from './properties';
8
+ export * from './layout';
8
9
  export * from './CSS';
9
10
  export * from './CSSProperty';
10
- export * from './LayoutRegistry';
11
11
  export * from './StyleValueRegistry';
package/es/css/index.js CHANGED
@@ -5,7 +5,7 @@ export * from './interfaces';
5
5
  export * from './cssom';
6
6
  export * from './parser';
7
7
  export * from './properties';
8
+ export * from './layout';
8
9
  export * from './CSS';
9
10
  export * from './CSSProperty';
10
- export * from './LayoutRegistry';
11
11
  export * from './StyleValueRegistry';
@@ -0,0 +1,32 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import { LayoutObject } from './LayoutObject';
3
+ import { LayoutContext } from './LayoutContext';
4
+ import type { LayoutFragment } from './LayoutFragment';
5
+ export declare const FragmentResultFactory: Syringe.DefinedToken;
6
+ export interface FragmentResultFactory {
7
+ (options: FragmentResultOptions): FragmentResult;
8
+ }
9
+ /**
10
+ * The web developer defined layout method can return either a FragmentResultOptions or a FragmentResult.
11
+ */
12
+ export declare const FragmentResultOptions: Syringe.DefinedToken;
13
+ export interface FragmentResultOptions<T = void> {
14
+ inlineSize: number;
15
+ blockSize: number;
16
+ autoBlockSize: number;
17
+ childFragments: LayoutFragment[];
18
+ data: T;
19
+ }
20
+ export declare const ContextNode: Syringe.DefinedToken;
21
+ export declare class FragmentResult<T = void> {
22
+ protected readonly _layoutContext: LayoutContext;
23
+ protected readonly _node: LayoutObject;
24
+ protected readonly options: FragmentResultOptions<T>;
25
+ private layoutContext;
26
+ readonly inlineSize: number;
27
+ readonly blockSize: number;
28
+ private node;
29
+ childFragments: LayoutFragment[];
30
+ data: T;
31
+ constructor(_layoutContext: LayoutContext, _node: LayoutObject, options: FragmentResultOptions<T>);
32
+ }
@@ -0,0 +1,32 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, injectable, Syringe } from 'mana-syringe';
3
+ import { LayoutObject } from './LayoutObject';
4
+ import { LayoutContext } from './LayoutContext';
5
+ export var FragmentResultFactory = Syringe.defineToken('FragmentResultFactory');
6
+ /**
7
+ * The web developer defined layout method can return either a FragmentResultOptions or a FragmentResult.
8
+ */
9
+
10
+ export var FragmentResultOptions = Syringe.defineToken('FragmentResultOptions');
11
+ export var ContextNode = Syringe.defineToken('contextNode');
12
+
13
+ var FragmentResult =
14
+ /** @class */
15
+ function () {
16
+ function FragmentResult(_layoutContext, _node, options) {
17
+ this._layoutContext = _layoutContext;
18
+ this._node = _node;
19
+ this.options = options;
20
+ this.layoutContext = _layoutContext;
21
+ this.inlineSize = options === null || options === void 0 ? void 0 : options.inlineSize;
22
+ this.blockSize = options === null || options === void 0 ? void 0 : options.blockSize;
23
+ this.childFragments = options === null || options === void 0 ? void 0 : options.childFragments;
24
+ this.data = options.data;
25
+ this.node = _node;
26
+ }
27
+
28
+ FragmentResult = __decorate([injectable(), __param(0, inject(LayoutContext)), __param(1, inject(ContextNode)), __param(2, inject(FragmentResultOptions)), __metadata("design:paramtypes", [LayoutContext, LayoutObject, Object])], FragmentResult);
29
+ return FragmentResult;
30
+ }();
31
+
32
+ export { FragmentResult };
@@ -0,0 +1,23 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import type { LayoutObject } from './LayoutObject';
3
+ import { LayoutContext } from './LayoutContext';
4
+ import type { LayoutFragment } from './LayoutFragment';
5
+ import type { IntrinsicSizes, LayoutConstraints } from './types';
6
+ export declare const LayoutChildrenFactory: Syringe.DefinedToken;
7
+ export interface LayoutChildrenFactory {
8
+ (options: LayoutChildrenOptions): LayoutChildren;
9
+ }
10
+ export declare const LayoutChildrenOptions: Syringe.DefinedToken;
11
+ export interface LayoutChildrenOptions {
12
+ node: LayoutObject;
13
+ }
14
+ export declare class LayoutChildren {
15
+ protected readonly _layoutContext: LayoutContext;
16
+ protected readonly options: LayoutChildrenOptions;
17
+ node: LayoutObject;
18
+ readonly styleMap: Map<string, any>;
19
+ layoutContext: LayoutContext;
20
+ constructor(_layoutContext: LayoutContext, options: LayoutChildrenOptions);
21
+ intrinsicSizes(): Promise<IntrinsicSizes>;
22
+ layoutNextFragment(constraints: LayoutConstraints): Promise<LayoutFragment>;
23
+ }
@@ -0,0 +1,55 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, injectable, Syringe } from 'mana-syringe';
3
+ import { Deferred } from '../../utils';
4
+ import { LayoutContext } from './LayoutContext';
5
+ import { LayoutTaskType } from './types';
6
+ export var LayoutChildrenFactory = Syringe.defineToken('LayoutChildrenFactory');
7
+ export var LayoutChildrenOptions = Syringe.defineToken('LayoutChildrenOptions');
8
+
9
+ var LayoutChildren =
10
+ /** @class */
11
+ function () {
12
+ function LayoutChildren(_layoutContext, options) {
13
+ this._layoutContext = _layoutContext;
14
+ this.options = options;
15
+ this.layoutContext = _layoutContext;
16
+ this.node = options.node;
17
+ this.styleMap = options.node.getAllStyle();
18
+ }
19
+
20
+ LayoutChildren.prototype.intrinsicSizes = function () {
21
+ // if (this.contextId !== this.layoutContext.contextId) {
22
+ // throw new Error('Invalid State: wrong layout context');
23
+ // }
24
+ var deferred = new Deferred();
25
+ this.layoutContext.appendWorkTask({
26
+ layoutChild: this,
27
+ taskType: LayoutTaskType.IntrinsicSizes,
28
+ deferred: deferred
29
+ });
30
+ return deferred.promise;
31
+ };
32
+
33
+ LayoutChildren.prototype.layoutNextFragment = function (constraints) {
34
+ // if (this.layoutContext.contextId !== this.layoutContext.contextId) {
35
+ // throw new Error('Invalid State: wrong layout context');
36
+ // }
37
+ if (this.layoutContext.mode === LayoutTaskType.IntrinsicSizes) {
38
+ throw new Error('Not Supported: cant call layoutNextFragment in intrinsicSizes');
39
+ }
40
+
41
+ var deferred = new Deferred();
42
+ this.layoutContext.appendWorkTask({
43
+ layoutConstraints: constraints,
44
+ layoutChild: this,
45
+ taskType: LayoutTaskType.Layout,
46
+ deferred: deferred
47
+ });
48
+ return deferred.promise;
49
+ };
50
+
51
+ LayoutChildren = __decorate([injectable(), __param(0, inject(LayoutContext)), __param(1, inject(LayoutChildrenOptions)), __metadata("design:paramtypes", [LayoutContext, Object])], LayoutChildren);
52
+ return LayoutChildren;
53
+ }();
54
+
55
+ export { LayoutChildren };
@@ -0,0 +1,35 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import type { LayoutWorkTask } from './LayoutWorkTask';
3
+ import type { LayoutTaskType } from './types';
4
+ import type { ContextId } from './types';
5
+ import type { FragmentResultFactory } from './FragmentResult';
6
+ import type { LayoutChildrenFactory } from './LayoutChildren';
7
+ import type { LayoutFragmentFactory } from './LayoutFragment';
8
+ export declare const LayoutContextFactory: Syringe.DefinedToken;
9
+ export interface LayoutContextFactory {
10
+ (options: {
11
+ mode: LayoutTaskType;
12
+ }): LayoutContext;
13
+ }
14
+ export declare const LayoutContextOptions: Syringe.DefinedToken;
15
+ export interface LayoutContextOptions {
16
+ mode: LayoutTaskType;
17
+ layoutChildrenFactory: LayoutChildrenFactory;
18
+ fragmentResultFactory: FragmentResultFactory;
19
+ layoutFragmentFactory: LayoutFragmentFactory;
20
+ }
21
+ /**
22
+ * 每次layout 有单独的 context
23
+ */
24
+ export declare class LayoutContext {
25
+ protected readonly options: LayoutContextOptions;
26
+ contextId: ContextId;
27
+ workQueue: LayoutWorkTask[];
28
+ mode: LayoutTaskType;
29
+ layoutChildrenFactory: LayoutChildrenFactory;
30
+ fragmentResultFactory: FragmentResultFactory;
31
+ layoutFragmentFactory: LayoutFragmentFactory;
32
+ constructor(options: LayoutContextOptions);
33
+ appendWorkTask(work: LayoutWorkTask): void;
34
+ clearWorkQueue(): void;
35
+ }