@visactor/vrender-core 0.17.0-alpha.0 → 0.17.0-alpha.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 (206) hide show
  1. package/cjs/allocator/canvas-allocate.d.ts +2 -0
  2. package/cjs/allocator/canvas-allocate.js +12 -6
  3. package/cjs/allocator/canvas-allocate.js.map +1 -1
  4. package/cjs/common/inversify/annotation/inject.d.ts +1 -0
  5. package/cjs/common/inversify/annotation/inject.js +10 -0
  6. package/cjs/common/inversify/annotation/inject.js.map +1 -0
  7. package/cjs/common/inversify/annotation/inject_base.d.ts +14 -0
  8. package/cjs/common/inversify/annotation/inject_base.js +39 -0
  9. package/cjs/common/inversify/annotation/inject_base.js.map +1 -0
  10. package/cjs/common/inversify/annotation/injectable.d.ts +1 -0
  11. package/cjs/common/{inversify-lite/annotation/post_construct.js → inversify/annotation/injectable.js} +15 -5
  12. package/cjs/common/inversify/annotation/injectable.js.map +1 -0
  13. package/cjs/common/inversify/annotation/multi_inject.d.ts +1 -0
  14. package/cjs/common/inversify/annotation/multi_inject.js +10 -0
  15. package/cjs/common/inversify/annotation/multi_inject.js.map +1 -0
  16. package/cjs/common/inversify/annotation/named.d.ts +1 -0
  17. package/cjs/common/inversify/annotation/named.js +14 -0
  18. package/cjs/common/inversify/annotation/named.js.map +1 -0
  19. package/cjs/common/inversify/binding.d.ts +18 -0
  20. package/cjs/common/inversify/binding.js +26 -0
  21. package/cjs/common/inversify/binding.js.map +1 -0
  22. package/cjs/common/inversify/container.d.ts +28 -0
  23. package/cjs/common/inversify/container.js +155 -0
  24. package/cjs/common/inversify/container.js.map +1 -0
  25. package/cjs/common/inversify/cotainer-module.d.ts +6 -0
  26. package/cjs/common/inversify/cotainer-module.js +16 -0
  27. package/cjs/common/inversify/cotainer-module.js.map +1 -0
  28. package/cjs/common/inversify/index.d.ts +7 -0
  29. package/cjs/common/inversify/index.js +75 -0
  30. package/cjs/common/inversify/index.js.map +1 -0
  31. package/cjs/common/inversify/interfaces.d.ts +218 -0
  32. package/cjs/common/inversify/interfaces.js +6 -0
  33. package/cjs/common/inversify/interfaces.js.map +1 -0
  34. package/cjs/common/inversify/literal_types.d.ts +5 -0
  35. package/cjs/common/inversify/literal_types.js +34 -0
  36. package/cjs/common/inversify/literal_types.js.map +1 -0
  37. package/cjs/common/inversify/meta-data.d.ts +6 -0
  38. package/cjs/common/inversify/meta-data.js +19 -0
  39. package/cjs/common/inversify/meta-data.js.map +1 -0
  40. package/cjs/common/inversify/metadata_keys.d.ts +12 -0
  41. package/cjs/common/inversify/metadata_keys.js +15 -0
  42. package/cjs/common/inversify/metadata_keys.js.map +1 -0
  43. package/cjs/common/inversify/metadata_reader.d.ts +6 -0
  44. package/cjs/common/inversify/metadata_reader.js +28 -0
  45. package/cjs/common/inversify/metadata_reader.js.map +1 -0
  46. package/cjs/common/inversify/syntax/binding_in_syntax.d.ts +10 -0
  47. package/cjs/common/inversify/syntax/binding_in_syntax.js +29 -0
  48. package/cjs/common/inversify/syntax/binding_in_syntax.js.map +1 -0
  49. package/cjs/common/inversify/syntax/binding_to_syntax.d.ts +12 -0
  50. package/cjs/common/inversify/syntax/binding_to_syntax.js +40 -0
  51. package/cjs/common/inversify/syntax/binding_to_syntax.js.map +1 -0
  52. package/cjs/common/inversify/syntax/constraint_helpers.d.ts +2 -0
  53. package/cjs/common/inversify/syntax/constraint_helpers.js +18 -0
  54. package/cjs/common/inversify/syntax/constraint_helpers.js.map +1 -0
  55. package/cjs/common/inversify-lite/index.d.ts +1 -8
  56. package/cjs/common/inversify-lite/index.js +1 -64
  57. package/cjs/common/inversify-lite/index.js.map +1 -1
  58. package/cjs/common/utils.d.ts +1 -0
  59. package/cjs/common/utils.js +10 -1
  60. package/cjs/common/utils.js.map +1 -1
  61. package/cjs/core/global.d.ts +2 -0
  62. package/cjs/core/global.js +4 -3
  63. package/cjs/core/global.js.map +1 -1
  64. package/cjs/core/graphic-utils.d.ts +5 -2
  65. package/cjs/core/graphic-utils.js +14 -4
  66. package/cjs/core/graphic-utils.js.map +1 -1
  67. package/cjs/core/stage.d.ts +4 -1
  68. package/cjs/core/stage.js +26 -22
  69. package/cjs/core/stage.js.map +1 -1
  70. package/cjs/core/window.js +2 -2
  71. package/cjs/core/window.js.map +1 -1
  72. package/cjs/graphic/builtin-symbol/index.d.ts +1 -0
  73. package/cjs/graphic/builtin-symbol/index.js +8 -2
  74. package/cjs/graphic/builtin-symbol/index.js.map +1 -1
  75. package/cjs/graphic/config.js +4 -1
  76. package/cjs/graphic/config.js.map +1 -1
  77. package/cjs/graphic/richtext/paragraph.js +12 -11
  78. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  79. package/cjs/graphic/symbol.js +3 -2
  80. package/cjs/graphic/symbol.js.map +1 -1
  81. package/cjs/graphic/text.d.ts +1 -0
  82. package/cjs/graphic/text.js +93 -7
  83. package/cjs/graphic/text.js.map +1 -1
  84. package/cjs/graphic/wrap-text.js +6 -5
  85. package/cjs/graphic/wrap-text.js.map +1 -1
  86. package/cjs/interface/global.d.ts +1 -0
  87. package/cjs/interface/global.js.map +1 -1
  88. package/cjs/interface/graphic/richText.d.ts +1 -1
  89. package/cjs/interface/graphic/richText.js.map +1 -1
  90. package/cjs/interface/graphic/text.d.ts +4 -1
  91. package/cjs/interface/graphic/text.js.map +1 -1
  92. package/cjs/render/contributions/render/draw-contribution.d.ts +2 -0
  93. package/cjs/render/contributions/render/draw-contribution.js +18 -9
  94. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  95. package/cjs/render/contributions/render/line-render.d.ts +1 -0
  96. package/cjs/render/contributions/render/line-render.js +21 -6
  97. package/cjs/render/contributions/render/line-render.js.map +1 -1
  98. package/cjs/render/contributions/render/text-render.js +12 -10
  99. package/cjs/render/contributions/render/text-render.js.map +1 -1
  100. package/dist/index.js +611 -1515
  101. package/dist/index.min.js +1 -1
  102. package/es/allocator/canvas-allocate.d.ts +2 -0
  103. package/es/allocator/canvas-allocate.js +12 -6
  104. package/es/allocator/canvas-allocate.js.map +1 -1
  105. package/es/common/inversify/annotation/inject.d.ts +1 -0
  106. package/es/common/inversify/annotation/inject.js +6 -0
  107. package/es/common/inversify/annotation/inject.js.map +1 -0
  108. package/es/common/inversify/annotation/inject_base.d.ts +14 -0
  109. package/es/common/inversify/annotation/inject_base.js +29 -0
  110. package/es/common/inversify/annotation/inject_base.js.map +1 -0
  111. package/es/common/inversify/annotation/injectable.d.ts +1 -0
  112. package/es/common/inversify/annotation/injectable.js +10 -0
  113. package/es/common/inversify/annotation/injectable.js.map +1 -0
  114. package/es/common/inversify/annotation/multi_inject.d.ts +1 -0
  115. package/es/common/inversify/annotation/multi_inject.js +6 -0
  116. package/es/common/inversify/annotation/multi_inject.js.map +1 -0
  117. package/es/common/inversify/annotation/named.d.ts +1 -0
  118. package/es/common/inversify/annotation/named.js +10 -0
  119. package/es/common/inversify/annotation/named.js.map +1 -0
  120. package/es/common/inversify/binding.d.ts +18 -0
  121. package/es/common/inversify/binding.js +22 -0
  122. package/es/common/inversify/binding.js.map +1 -0
  123. package/es/common/inversify/container.d.ts +28 -0
  124. package/es/common/inversify/container.js +155 -0
  125. package/es/common/inversify/container.js.map +1 -0
  126. package/es/common/inversify/cotainer-module.d.ts +6 -0
  127. package/es/common/inversify/cotainer-module.js +8 -0
  128. package/es/common/inversify/cotainer-module.js.map +1 -0
  129. package/es/common/inversify/index.d.ts +7 -0
  130. package/es/common/inversify/index.js +14 -0
  131. package/es/common/inversify/index.js.map +1 -0
  132. package/es/common/inversify/interfaces.d.ts +218 -0
  133. package/es/common/inversify/interfaces.js +2 -0
  134. package/es/common/inversify/interfaces.js.map +1 -0
  135. package/es/common/inversify/literal_types.d.ts +5 -0
  136. package/es/common/inversify/literal_types.js +20 -0
  137. package/es/common/inversify/literal_types.js.map +1 -0
  138. package/es/common/inversify/meta-data.d.ts +6 -0
  139. package/es/common/inversify/meta-data.js +11 -0
  140. package/es/common/inversify/meta-data.js.map +1 -0
  141. package/es/common/inversify/metadata_keys.d.ts +12 -0
  142. package/es/common/inversify/metadata_keys.js +28 -0
  143. package/es/common/inversify/metadata_keys.js.map +1 -0
  144. package/es/common/inversify/metadata_reader.d.ts +6 -0
  145. package/es/common/inversify/metadata_reader.js +18 -0
  146. package/es/common/inversify/metadata_reader.js.map +1 -0
  147. package/es/common/inversify/syntax/binding_in_syntax.d.ts +10 -0
  148. package/es/common/inversify/syntax/binding_in_syntax.js +24 -0
  149. package/es/common/inversify/syntax/binding_in_syntax.js.map +1 -0
  150. package/es/common/inversify/syntax/binding_to_syntax.d.ts +12 -0
  151. package/es/common/inversify/syntax/binding_to_syntax.js +36 -0
  152. package/es/common/inversify/syntax/binding_to_syntax.js.map +1 -0
  153. package/es/common/inversify/syntax/constraint_helpers.d.ts +2 -0
  154. package/es/common/inversify/syntax/constraint_helpers.js +16 -0
  155. package/es/common/inversify/syntax/constraint_helpers.js.map +1 -0
  156. package/es/common/inversify-lite/index.d.ts +1 -8
  157. package/es/common/inversify-lite/index.js +1 -15
  158. package/es/common/inversify-lite/index.js.map +1 -1
  159. package/es/common/utils.d.ts +1 -0
  160. package/es/common/utils.js +8 -1
  161. package/es/common/utils.js.map +1 -1
  162. package/es/core/global.d.ts +2 -0
  163. package/es/core/global.js +4 -2
  164. package/es/core/global.js.map +1 -1
  165. package/es/core/graphic-utils.d.ts +5 -2
  166. package/es/core/graphic-utils.js +14 -4
  167. package/es/core/graphic-utils.js.map +1 -1
  168. package/es/core/stage.d.ts +4 -1
  169. package/es/core/stage.js +27 -23
  170. package/es/core/stage.js.map +1 -1
  171. package/es/core/window.js +3 -3
  172. package/es/core/window.js.map +1 -1
  173. package/es/graphic/builtin-symbol/index.d.ts +1 -0
  174. package/es/graphic/builtin-symbol/index.js +8 -0
  175. package/es/graphic/builtin-symbol/index.js.map +1 -1
  176. package/es/graphic/config.js +4 -1
  177. package/es/graphic/config.js.map +1 -1
  178. package/es/graphic/richtext/paragraph.js +5 -2
  179. package/es/graphic/richtext/paragraph.js.map +1 -1
  180. package/es/graphic/symbol.js +4 -3
  181. package/es/graphic/symbol.js.map +1 -1
  182. package/es/graphic/text.d.ts +1 -0
  183. package/es/graphic/text.js +90 -9
  184. package/es/graphic/text.js.map +1 -1
  185. package/es/graphic/wrap-text.js +6 -4
  186. package/es/graphic/wrap-text.js.map +1 -1
  187. package/es/interface/global.d.ts +1 -0
  188. package/es/interface/global.js.map +1 -1
  189. package/es/interface/graphic/richText.d.ts +1 -1
  190. package/es/interface/graphic/richText.js.map +1 -1
  191. package/es/interface/graphic/text.d.ts +4 -1
  192. package/es/interface/graphic/text.js.map +1 -1
  193. package/es/render/contributions/render/draw-contribution.d.ts +2 -0
  194. package/es/render/contributions/render/draw-contribution.js +18 -9
  195. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  196. package/es/render/contributions/render/line-render.d.ts +1 -0
  197. package/es/render/contributions/render/line-render.js +21 -6
  198. package/es/render/contributions/render/line-render.js.map +1 -1
  199. package/es/render/contributions/render/text-render.js +13 -9
  200. package/es/render/contributions/render/text-render.js.map +1 -1
  201. package/package.json +5 -3
  202. package/cjs/common/inversify-lite/annotation/post_construct.d.ts +0 -4
  203. package/cjs/common/inversify-lite/annotation/post_construct.js.map +0 -1
  204. package/es/common/inversify-lite/annotation/post_construct.d.ts +0 -4
  205. package/es/common/inversify-lite/annotation/post_construct.js +0 -10
  206. package/es/common/inversify-lite/annotation/post_construct.js.map +0 -1
package/dist/index.js CHANGED
@@ -4,62 +4,25 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VRenderCore = {}, global.VUtils));
5
5
  })(this, (function (exports, vutils) { 'use strict';
6
6
 
7
- let idCounter = 0;
8
- function id() {
9
- return idCounter++;
7
+ class Generator {
8
+ static GenAutoIncrementId() {
9
+ return Generator.auto_increment_id++;
10
+ }
10
11
  }
12
+ Generator.auto_increment_id = 0;
11
13
 
12
14
  class ContainerModule {
13
15
  constructor(registry) {
14
- this.id = id();
16
+ this.id = Generator.GenAutoIncrementId();
15
17
  this.registry = registry;
16
18
  }
17
19
  }
18
20
 
19
21
  const NAMED_TAG = 'named';
20
- const NAME_TAG = 'name';
21
- const UNMANAGED_TAG = 'unmanaged';
22
- const OPTIONAL_TAG = 'optional';
23
22
  const INJECT_TAG = 'inject';
24
23
  const MULTI_INJECT_TAG = 'multi_inject';
25
24
  const TAGGED = 'inversify:tagged';
26
- const TAGGED_PROP = 'inversify:tagged_props';
27
25
  const PARAM_TYPES = 'inversify:paramtypes';
28
- const DESIGN_PARAM_TYPES = 'design:paramtypes';
29
- const POST_CONSTRUCT = 'post_construct';
30
- const PRE_DESTROY = 'pre_destroy';
31
- function getNonCustomTagKeys() {
32
- return [INJECT_TAG, MULTI_INJECT_TAG, NAME_TAG, UNMANAGED_TAG, NAMED_TAG, OPTIONAL_TAG];
33
- }
34
- const NON_CUSTOM_TAG_KEYS = getNonCustomTagKeys();
35
-
36
- const DUPLICATED_INJECTABLE_DECORATOR = 'Cannot apply @injectable decorator multiple times.';
37
- const DUPLICATED_METADATA = 'Metadata key was used more than once in a parameter:';
38
- const NULL_ARGUMENT = 'NULL argument';
39
- const KEY_NOT_FOUND = 'Key Not Found';
40
- const AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:';
41
- const CANNOT_UNBIND = 'Could not unbind serviceIdentifier:';
42
- const NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:';
43
- const MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:';
44
- const MISSING_INJECT_ANNOTATION = 'Missing required @inject or @multiInject annotation in:';
45
- const UNDEFINED_INJECT_ANNOTATION = (name) => `@inject called with undefined this could mean that the class ${name} has ` +
46
- 'a circular dependency problem. You can use a LazyServiceIdentifer to ' +
47
- 'overcome this limitation.';
48
- const INVALID_BINDING_TYPE = 'Invalid binding type:';
49
- const INVALID_FUNCTION_BINDING = 'Value provided to function binding must be a function!';
50
- const INVALID_TO_SELF_VALUE = 'The toSelf function can only be applied when a constructor is ' + 'used as service identifier';
51
- const INVALID_DECORATOR_OPERATION = 'The @inject @multiInject @tagged and @named decorators ' +
52
- 'must be applied to the parameters of a class constructor or a class property.';
53
- const ARGUMENTS_LENGTH_MISMATCH = (...values) => 'The number of constructor arguments in the derived class ' +
54
- `${values[0]} must be >= than the number of constructor arguments of its base class.`;
55
- const CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = 'Invalid Container constructor argument. Container options ' + 'must be an object.';
56
- const CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = 'Invalid Container option. Default scope must ' + 'be a string ("singleton" or "transient").';
57
- const CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = 'Invalid Container option. Auto bind injectable must ' + 'be a boolean';
58
- const CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = 'Invalid Container option. Skip base check must ' + 'be a boolean';
59
- const MULTIPLE_POST_CONSTRUCT_METHODS = 'Cannot apply @postConstruct decorator multiple times in the same class';
60
- const ASYNC_UNBIND_REQUIRED = 'Attempting to unbind dependency with asynchronous destruction (@preDestroy or onDeactivation)';
61
- const PRE_DESTROY_ERROR = (clazz, errorMessage) => `@preDestroy error in class ${clazz}: ${errorMessage}`;
62
- const ON_DEACTIVATION_ERROR = (clazz, errorMessage) => `onDeactivation() error in class ${clazz}: ${errorMessage}`;
63
26
 
64
27
  class Metadata {
65
28
  constructor(key, value) {
@@ -74,17 +37,6 @@
74
37
  }
75
38
  }
76
39
 
77
- function getFirstArrayDuplicate(array) {
78
- const seenValues = new Set();
79
- for (const entry of array) {
80
- if (seenValues.has(entry)) {
81
- return entry;
82
- }
83
- seenValues.add(entry);
84
- }
85
- return undefined;
86
- }
87
-
88
40
  let Reflect$1;
89
41
  var Reflect$2 = (function (Reflect) {
90
42
  (function (factory) {
@@ -668,40 +620,8 @@
668
620
  return Reflect;
669
621
  })(Reflect$1 || (Reflect$1 = {}));
670
622
 
671
- function targetIsConstructorFunction(target) {
672
- return target.prototype !== undefined;
673
- }
674
- function _throwIfMethodParameter(parameterName) {
675
- if (parameterName !== undefined) {
676
- throw new Error(INVALID_DECORATOR_OPERATION);
677
- }
678
- }
679
- function tagParameter(annotationTarget, parameterName, parameterIndex, metadata) {
680
- _throwIfMethodParameter(parameterName);
681
- _tagParameterOrProperty(TAGGED, annotationTarget, parameterIndex.toString(), metadata);
682
- }
683
- function tagProperty(annotationTarget, propertyName, metadata) {
684
- if (targetIsConstructorFunction(annotationTarget)) {
685
- throw new Error(INVALID_DECORATOR_OPERATION);
686
- }
687
- _tagParameterOrProperty(TAGGED_PROP, annotationTarget.constructor, propertyName, metadata);
688
- }
689
- function _ensureNoMetadataKeyDuplicates(metadata) {
690
- let metadatas = [];
691
- if (Array.isArray(metadata)) {
692
- metadatas = metadata;
693
- const duplicate = getFirstArrayDuplicate(metadatas.map(md => md.key));
694
- if (duplicate !== undefined) {
695
- throw new Error(`${DUPLICATED_METADATA} ${duplicate.toString()}`);
696
- }
697
- }
698
- else {
699
- metadatas = [metadata];
700
- }
701
- return metadatas;
702
- }
703
623
  function _tagParameterOrProperty(metadataKey, annotationTarget, key, metadata) {
704
- const metadatas = _ensureNoMetadataKeyDuplicates(metadata);
624
+ const metadatas = [metadata];
705
625
  let paramsOrPropertiesMetadata = {};
706
626
  if (Reflect$2.hasOwnMetadata(metadataKey, annotationTarget)) {
707
627
  paramsOrPropertiesMetadata = Reflect$2.getMetadata(metadataKey, annotationTarget);
@@ -710,35 +630,21 @@
710
630
  if (paramOrPropertyMetadata === undefined) {
711
631
  paramOrPropertyMetadata = [];
712
632
  }
713
- else {
714
- for (const m of paramOrPropertyMetadata) {
715
- if (metadatas.some(md => md.key === m.key)) {
716
- throw new Error(`${DUPLICATED_METADATA} ${m.key.toString()}`);
717
- }
718
- }
719
- }
720
633
  paramOrPropertyMetadata.push(...metadatas);
721
634
  paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata;
722
635
  Reflect$2.defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget);
723
636
  }
637
+ function tagParameter(annotationTarget, parameterName, parameterIndex, metadata) {
638
+ _tagParameterOrProperty(TAGGED, annotationTarget, parameterIndex.toString(), metadata);
639
+ }
724
640
  function createTaggedDecorator(metadata) {
725
641
  return (target, targetKey, indexOrPropertyDescriptor) => {
726
- if (typeof indexOrPropertyDescriptor === 'number') {
727
- tagParameter(target, targetKey, indexOrPropertyDescriptor, metadata);
728
- }
729
- else {
730
- tagProperty(target, targetKey, metadata);
731
- }
642
+ tagParameter(target, targetKey, indexOrPropertyDescriptor, metadata);
732
643
  };
733
644
  }
734
-
735
645
  function injectBase(metadataKey) {
736
646
  return (serviceIdentifier) => {
737
647
  return (target, targetKey, indexOrPropertyDescriptor) => {
738
- if (serviceIdentifier === undefined) {
739
- const className = typeof target === 'function' ? target.name : target.constructor.name;
740
- throw new Error(UNDEFINED_INJECT_ANNOTATION(className));
741
- }
742
648
  return createTaggedDecorator(new Metadata(metadataKey, serviceIdentifier))(target, targetKey, indexOrPropertyDescriptor);
743
649
  };
744
650
  };
@@ -750,11 +656,7 @@
750
656
 
751
657
  function injectable() {
752
658
  return function (target) {
753
- if (Reflect$2.hasOwnMetadata(PARAM_TYPES, target)) {
754
- throw new Error(DUPLICATED_INJECTABLE_DECORATOR);
755
- }
756
- const types = Reflect$2.getMetadata(DESIGN_PARAM_TYPES, target) || [];
757
- Reflect$2.defineMetadata(PARAM_TYPES, types, target);
659
+ Reflect$2.defineMetadata(PARAM_TYPES, null, target);
758
660
  return target;
759
661
  };
760
662
  }
@@ -763,65 +665,7 @@
763
665
  return createTaggedDecorator(new Metadata(NAMED_TAG, name));
764
666
  }
765
667
 
766
- function _typeof(o) {
767
- "@babel/helpers - typeof";
768
-
769
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
770
- return typeof o;
771
- } : function (o) {
772
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
773
- }, _typeof(o);
774
- }
775
-
776
- function __decorate(decorators, target, key, desc) {
777
- var c = arguments.length,
778
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
779
- d;
780
- if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
781
- return c > 3 && r && Object.defineProperty(target, key, r), r;
782
- }
783
- function __param(paramIndex, decorator) {
784
- return function (target, key) {
785
- decorator(target, key, paramIndex);
786
- };
787
- }
788
- function __metadata(metadataKey, metadataValue) {
789
- if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
790
- }
791
- function __awaiter(thisArg, _arguments, P, generator) {
792
- function adopt(value) {
793
- return value instanceof P ? value : new P(function (resolve) {
794
- resolve(value);
795
- });
796
- }
797
- return new (P || (P = Promise))(function (resolve, reject) {
798
- function fulfilled(value) {
799
- try {
800
- step(generator.next(value));
801
- } catch (e) {
802
- reject(e);
803
- }
804
- }
805
- function rejected(value) {
806
- try {
807
- step(generator["throw"](value));
808
- } catch (e) {
809
- reject(e);
810
- }
811
- }
812
- function step(result) {
813
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
814
- }
815
- step((generator = generator.apply(thisArg, _arguments || [])).next());
816
- });
817
- }
818
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
819
- var e = new Error(message);
820
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
821
- };
822
-
823
668
  const BindingScopeEnum = {
824
- Request: 'Request',
825
669
  Singleton: 'Singleton',
826
670
  Transient: 'Transient'
827
671
  };
@@ -835,15 +679,10 @@
835
679
  Invalid: 'Invalid',
836
680
  Provider: 'Provider'
837
681
  };
838
- const TargetTypeEnum = {
839
- ClassProperty: 'ClassProperty',
840
- ConstructorArgument: 'ConstructorArgument',
841
- Variable: 'Variable'
842
- };
843
682
 
844
683
  class Binding {
845
684
  constructor(serviceIdentifier, scope) {
846
- this.id = id();
685
+ this.id = Generator.GenAutoIncrementId();
847
686
  this.activated = false;
848
687
  this.serviceIdentifier = serviceIdentifier;
849
688
  this.scope = scope;
@@ -853,8 +692,6 @@
853
692
  this.cache = null;
854
693
  this.factory = null;
855
694
  this.provider = null;
856
- this.onActivation = null;
857
- this.onDeactivation = null;
858
695
  this.dynamicValue = null;
859
696
  }
860
697
  clone() {
@@ -864,11 +701,8 @@
864
701
  clone.dynamicValue = this.dynamicValue;
865
702
  clone.scope = this.scope;
866
703
  clone.type = this.type;
867
- clone.factory = this.factory;
868
704
  clone.provider = this.provider;
869
705
  clone.constraint = this.constraint;
870
- clone.onActivation = this.onActivation;
871
- clone.onDeactivation = this.onDeactivation;
872
706
  clone.cache = this.cache;
873
707
  return clone;
874
708
  }
@@ -884,1290 +718,329 @@
884
718
  };
885
719
  }
886
720
  getPropertiesMetadata(constructorFunc) {
887
- const userGeneratedMetadata = Reflect$2.getMetadata(TAGGED_PROP, constructorFunc) || [];
888
- return userGeneratedMetadata;
721
+ throw new Error('暂未实现');
889
722
  }
890
723
  }
891
724
 
892
- const BindingCount = {
893
- MultipleBindingsAvailable: 2,
894
- NoBindingsAvailable: 0,
895
- OnlyOneBindingAvailable: 1
896
- };
897
-
898
- function getServiceIdentifierAsString(serviceIdentifier) {
899
- if (typeof serviceIdentifier === 'function') {
900
- const _serviceIdentifier = serviceIdentifier;
901
- return _serviceIdentifier.name;
902
- }
903
- else if (typeof serviceIdentifier === 'symbol') {
904
- return serviceIdentifier.toString();
905
- }
906
- const _serviceIdentifier = serviceIdentifier;
907
- return _serviceIdentifier;
908
- }
909
- function listRegisteredBindingsForServiceIdentifier(container, serviceIdentifier, getBindings) {
910
- let registeredBindingsList = '';
911
- const registeredBindings = getBindings(container, serviceIdentifier);
912
- if (registeredBindings.length !== 0) {
913
- registeredBindingsList = '\nRegistered bindings:';
914
- registeredBindings.forEach((binding) => {
915
- let name = 'Object';
916
- if (binding.implementationType !== null) {
917
- name = getFunctionName(binding.implementationType);
918
- }
919
- registeredBindingsList = `${registeredBindingsList}\n ${name}`;
920
- if (binding.constraint.metaData) {
921
- registeredBindingsList = `${registeredBindingsList} - ${binding.constraint.metaData}`;
922
- }
923
- });
924
- }
925
- return registeredBindingsList;
926
- }
927
- function listMetadataForTarget(serviceIdentifierString, target) {
928
- if (target.isTagged() || target.isNamed()) {
929
- let m = '';
930
- const namedTag = target.getNamedTag();
931
- const otherTags = target.getCustomTags();
932
- if (namedTag !== null) {
933
- m += namedTag.toString() + '\n';
725
+ const taggedConstraint = (key) => (value) => {
726
+ const constraint = (request) => {
727
+ if (request == null || request.constructorArgsMetadata == null) {
728
+ return false;
934
729
  }
935
- if (otherTags !== null) {
936
- otherTags.forEach(tag => {
937
- m += tag.toString() + '\n';
938
- });
730
+ const constructorArgsMetadata = request.constructorArgsMetadata;
731
+ for (let i = 0; i < constructorArgsMetadata.length; i++) {
732
+ if (constructorArgsMetadata[i].key === key && constructorArgsMetadata[i].value === value) {
733
+ return true;
734
+ }
939
735
  }
940
- return ` ${serviceIdentifierString}\n ${serviceIdentifierString} - ${m}`;
736
+ return false;
737
+ };
738
+ constraint.metaData = new Metadata(key, value);
739
+ return constraint;
740
+ };
741
+ const namedConstraint = taggedConstraint(NAMED_TAG);
742
+
743
+ class BindingInSyntax {
744
+ constructor(binding) {
745
+ this._binding = binding;
941
746
  }
942
- return ` ${serviceIdentifierString}`;
943
- }
944
- function getFunctionName(func) {
945
- if (func.name) {
946
- return func.name;
747
+ inRequestScope() {
748
+ throw new Error('暂未实现');
947
749
  }
948
- const name = func.toString();
949
- const match = name.match(/^function\s*([^\s(]+)/);
950
- return match ? match[1] : `Anonymous function: ${name}`;
951
- }
952
- function getSymbolDescription(symbol) {
953
- return symbol.toString().slice(7, -1);
954
- }
955
-
956
- class Context {
957
- constructor(container) {
958
- this.id = id();
959
- this.container = container;
750
+ inSingletonScope() {
751
+ this._binding.scope = BindingScopeEnum.Singleton;
752
+ return this;
960
753
  }
961
- addPlan(plan) {
962
- this.plan = plan;
754
+ inTransientScope() {
755
+ this._binding.scope = BindingScopeEnum.Transient;
756
+ return this;
963
757
  }
964
- setCurrentRequest(currentRequest) {
965
- this.currentRequest = currentRequest;
758
+ whenTargetNamed(name) {
759
+ this._binding.constraint = namedConstraint(name);
760
+ return this;
966
761
  }
967
762
  }
968
763
 
969
- class Plan {
970
- constructor(parentContext, rootRequest) {
971
- this.parentContext = parentContext;
972
- this.rootRequest = rootRequest;
764
+ class BindingToSyntax {
765
+ constructor(binding) {
766
+ this._binding = binding;
973
767
  }
974
- }
975
-
976
- class LazyServiceIdentifer {
977
- constructor(cb) {
978
- this._cb = cb;
768
+ to(constructor) {
769
+ this._binding.type = BindingTypeEnum.Instance;
770
+ this._binding.implementationType = constructor;
771
+ return new BindingInSyntax(this._binding);
979
772
  }
980
- unwrap() {
981
- return this._cb();
773
+ toSelf() {
774
+ const self = this._binding.serviceIdentifier;
775
+ return this.to(self);
982
776
  }
983
- }
984
-
985
- class QueryableString {
986
- constructor(str) {
987
- this.str = str;
777
+ toDynamicValue(func) {
778
+ this._binding.type = BindingTypeEnum.DynamicValue;
779
+ this._binding.cache = null;
780
+ this._binding.dynamicValue = func;
781
+ this._binding.implementationType = null;
782
+ return new BindingInSyntax(this._binding);
988
783
  }
989
- contains(searchString) {
990
- return this.str.indexOf(searchString) !== -1;
784
+ toConstantValue(value) {
785
+ this._binding.type = BindingTypeEnum.ConstantValue;
786
+ this._binding.cache = value;
787
+ this._binding.dynamicValue = null;
788
+ this._binding.implementationType = null;
789
+ this._binding.scope = BindingScopeEnum.Singleton;
790
+ return new BindingInSyntax(this._binding);
991
791
  }
992
- equals(compareString) {
993
- return this.str === compareString;
792
+ toFactory(factory) {
793
+ this._binding.type = BindingTypeEnum.Factory;
794
+ this._binding.factory = factory;
795
+ this._binding.scope = BindingScopeEnum.Singleton;
796
+ return new BindingInSyntax(this._binding);
994
797
  }
995
- value() {
996
- return this.str;
798
+ toService(service) {
799
+ this.toDynamicValue(context => context.container.get(service));
997
800
  }
998
801
  }
999
802
 
1000
- class Target {
1001
- constructor(type, identifier, serviceIdentifier, namedOrTagged) {
1002
- this.id = id();
1003
- this.type = type;
1004
- this.serviceIdentifier = serviceIdentifier;
1005
- const queryableName = typeof identifier === 'symbol' ? getSymbolDescription(identifier) : identifier;
1006
- this.name = new QueryableString(queryableName || '');
1007
- this.identifier = identifier;
1008
- this.metadata = [];
1009
- let metadataItem = null;
1010
- if (typeof namedOrTagged === 'string') {
1011
- metadataItem = new Metadata(NAMED_TAG, namedOrTagged);
1012
- }
1013
- else if (namedOrTagged instanceof Metadata) {
1014
- metadataItem = namedOrTagged;
1015
- }
1016
- if (metadataItem !== null) {
1017
- this.metadata.push(metadataItem);
1018
- }
803
+ class Container {
804
+ constructor(containerOptions) {
805
+ const options = containerOptions || {};
806
+ options.defaultScope = options.defaultScope || BindingScopeEnum.Transient;
807
+ this.options = options;
808
+ this.id = Generator.GenAutoIncrementId();
809
+ this._bindingDictionary = new Map();
810
+ this._metadataReader = new MetadataReader();
1019
811
  }
1020
- hasTag(key) {
1021
- for (const m of this.metadata) {
1022
- if (m.key === key) {
1023
- return true;
1024
- }
1025
- }
1026
- return false;
812
+ load(module) {
813
+ const getHelpers = this._getContainerModuleHelpersFactory();
814
+ const containerModuleHelpers = getHelpers(module.id);
815
+ module.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
1027
816
  }
1028
- isArray() {
1029
- return this.hasTag(MULTI_INJECT_TAG);
817
+ get(serviceIdentifier) {
818
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false);
819
+ return this._get(getArgs);
1030
820
  }
1031
- matchesArray(name) {
1032
- return this.matchesTag(MULTI_INJECT_TAG)(name);
821
+ getAll(serviceIdentifier) {
822
+ const getArgs = this._getAllArgs(serviceIdentifier);
823
+ return this._get(getArgs);
1033
824
  }
1034
- isNamed() {
1035
- return this.hasTag(NAMED_TAG);
825
+ getTagged(serviceIdentifier, key, value) {
826
+ const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
827
+ return this._get(getArgs);
1036
828
  }
1037
- isTagged() {
1038
- return this.metadata.some(metadata => NON_CUSTOM_TAG_KEYS.every(key => metadata.key !== key));
829
+ getNamed(serviceIdentifier, named) {
830
+ return this.getTagged(serviceIdentifier, NAMED_TAG, named);
1039
831
  }
1040
- isOptional() {
1041
- return this.matchesTag(OPTIONAL_TAG)(true);
832
+ isBound(serviceIdentifier) {
833
+ return this._bindingDictionary.has(serviceIdentifier);
1042
834
  }
1043
- getNamedTag() {
1044
- if (this.isNamed()) {
1045
- return this.metadata.filter(m => m.key === NAMED_TAG)[0];
1046
- }
1047
- return null;
835
+ bind(serviceIdentifier) {
836
+ const scope = this.options.defaultScope;
837
+ const binding = new Binding(serviceIdentifier, scope);
838
+ const list = this._bindingDictionary.get(serviceIdentifier) || [];
839
+ list.push(binding);
840
+ this._bindingDictionary.set(serviceIdentifier, list);
841
+ return new BindingToSyntax(binding);
1048
842
  }
1049
- getCustomTags() {
1050
- if (this.isTagged()) {
1051
- return this.metadata.filter(metadata => NON_CUSTOM_TAG_KEYS.every(key => metadata.key !== key));
1052
- }
1053
- return null;
843
+ unbind(serviceIdentifier) {
844
+ this._bindingDictionary.delete(serviceIdentifier);
1054
845
  }
1055
- matchesNamedTag(name) {
1056
- return this.matchesTag(NAMED_TAG)(name);
846
+ rebind(serviceIdentifier) {
847
+ this.unbind(serviceIdentifier);
848
+ return this.bind(serviceIdentifier);
1057
849
  }
1058
- matchesTag(key) {
1059
- return (value) => {
1060
- for (const m of this.metadata) {
1061
- if (m.key === key && m.value === value) {
1062
- return true;
1063
- }
1064
- }
1065
- return false;
850
+ _getContainerModuleHelpersFactory() {
851
+ const setModuleId = (bindingToSyntax, moduleId) => {
852
+ bindingToSyntax._binding.moduleId = moduleId;
853
+ };
854
+ const getBindFunction = (moduleId) => (serviceIdentifier) => {
855
+ const bindingToSyntax = this.bind(serviceIdentifier);
856
+ setModuleId(bindingToSyntax, moduleId);
857
+ return bindingToSyntax;
858
+ };
859
+ const getUnbindFunction = () => (serviceIdentifier) => {
860
+ return this.unbind(serviceIdentifier);
861
+ };
862
+ const getUnbindAsyncFunction = () => (serviceIdentifier) => {
863
+ return null;
864
+ };
865
+ const getIsboundFunction = () => (serviceIdentifier) => {
866
+ return this.isBound(serviceIdentifier);
867
+ };
868
+ const getRebindFunction = (moduleId) => (serviceIdentifier) => {
869
+ const bindingToSyntax = this.rebind(serviceIdentifier);
870
+ setModuleId(bindingToSyntax, moduleId);
871
+ return bindingToSyntax;
1066
872
  };
873
+ return (mId) => ({
874
+ bindFunction: getBindFunction(mId),
875
+ isboundFunction: getIsboundFunction(),
876
+ rebindFunction: getRebindFunction(mId),
877
+ unbindFunction: getUnbindFunction(),
878
+ unbindAsyncFunction: getUnbindAsyncFunction()
879
+ });
1067
880
  }
1068
- }
1069
-
1070
- function getDependencies(metadataReader, func) {
1071
- const constructorName = getFunctionName(func);
1072
- return getTargets(metadataReader, constructorName, func, false);
1073
- }
1074
- function getTargets(metadataReader, constructorName, func, isBaseClass) {
1075
- const metadata = metadataReader.getConstructorMetadata(func);
1076
- const serviceIdentifiers = metadata.compilerGeneratedMetadata;
1077
- if (serviceIdentifiers === undefined) {
1078
- const msg = `${MISSING_INJECTABLE_ANNOTATION} ${constructorName}.`;
1079
- throw new Error(msg);
1080
- }
1081
- const constructorArgsMetadata = metadata.userGeneratedMetadata;
1082
- const keys = Object.keys(constructorArgsMetadata);
1083
- const hasUserDeclaredUnknownInjections = func.length === 0 && keys.length > 0;
1084
- const hasOptionalParameters = keys.length > func.length;
1085
- const iterations = hasUserDeclaredUnknownInjections || hasOptionalParameters ? keys.length : func.length;
1086
- const constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
1087
- const propertyTargets = getClassPropsAsTargets(metadataReader, func, constructorName);
1088
- const targets = [...constructorTargets, ...propertyTargets];
1089
- return targets;
1090
- }
1091
- function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
1092
- const targetMetadata = constructorArgsMetadata[index.toString()] || [];
1093
- const metadata = formatTargetMetadata(targetMetadata);
1094
- const isManaged = metadata.unmanaged !== true;
1095
- let serviceIdentifier = serviceIdentifiers[index];
1096
- const injectIdentifier = metadata.inject || metadata.multiInject;
1097
- serviceIdentifier = (injectIdentifier ? injectIdentifier : serviceIdentifier);
1098
- if (serviceIdentifier instanceof LazyServiceIdentifer) {
1099
- serviceIdentifier = serviceIdentifier.unwrap();
1100
- }
1101
- if (isManaged) {
1102
- const isObject = serviceIdentifier === Object;
1103
- const isFunction = serviceIdentifier === Function;
1104
- const isUndefined = serviceIdentifier === undefined;
1105
- const isUnknownType = isObject || isFunction || isUndefined;
1106
- if (!isBaseClass && isUnknownType) {
1107
- const msg = `${MISSING_INJECT_ANNOTATION} argument ${index} in class ${constructorName}.`;
1108
- throw new Error(msg);
1109
- }
1110
- const target = new Target(TargetTypeEnum.ConstructorArgument, metadata.targetName, serviceIdentifier);
1111
- target.metadata = targetMetadata;
1112
- return target;
881
+ _getNotAllArgs(serviceIdentifier, isMultiInject, key, value) {
882
+ return {
883
+ avoidConstraints: false,
884
+ isMultiInject,
885
+ serviceIdentifier,
886
+ key,
887
+ value
888
+ };
1113
889
  }
1114
- return null;
1115
- }
1116
- function getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations) {
1117
- const targets = [];
1118
- for (let i = 0; i < iterations; i++) {
1119
- const index = i;
1120
- const target = getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata);
1121
- if (target !== null) {
1122
- targets.push(target);
1123
- }
1124
- }
1125
- return targets;
1126
- }
1127
- function _getServiceIdentifierForProperty(inject, multiInject, propertyName, className) {
1128
- const serviceIdentifier = inject || multiInject;
1129
- if (serviceIdentifier === undefined) {
1130
- const msg = `${MISSING_INJECTABLE_ANNOTATION} for property ${String(propertyName)} in class ${className}.`;
1131
- throw new Error(msg);
1132
- }
1133
- return serviceIdentifier;
1134
- }
1135
- function getClassPropsAsTargets(metadataReader, constructorFunc, constructorName) {
1136
- const classPropsMetadata = metadataReader.getPropertiesMetadata(constructorFunc);
1137
- let targets = [];
1138
- const symbolKeys = Object.getOwnPropertySymbols(classPropsMetadata);
1139
- const stringKeys = Object.keys(classPropsMetadata);
1140
- const keys = stringKeys.concat(symbolKeys);
1141
- for (const key of keys) {
1142
- const targetMetadata = classPropsMetadata[key];
1143
- const metadata = formatTargetMetadata(targetMetadata);
1144
- const identifier = metadata.targetName || key;
1145
- const serviceIdentifier = _getServiceIdentifierForProperty(metadata.inject, metadata.multiInject, key, constructorName);
1146
- const target = new Target(TargetTypeEnum.ClassProperty, identifier, serviceIdentifier);
1147
- target.metadata = targetMetadata;
1148
- targets.push(target);
1149
- }
1150
- const baseConstructor = Object.getPrototypeOf(constructorFunc.prototype).constructor;
1151
- if (baseConstructor !== Object) {
1152
- const baseTargets = getClassPropsAsTargets(metadataReader, baseConstructor, constructorName);
1153
- targets = [...targets, ...baseTargets];
1154
- }
1155
- return targets;
1156
- }
1157
- function getBaseClassDependencyCount(metadataReader, func) {
1158
- const baseConstructor = Object.getPrototypeOf(func.prototype).constructor;
1159
- if (baseConstructor !== Object) {
1160
- const baseConstructorName = getFunctionName(baseConstructor);
1161
- const targets = getTargets(metadataReader, baseConstructorName, baseConstructor, true);
1162
- const metadata = targets.map(t => t.metadata.filter(m => m.key === UNMANAGED_TAG));
1163
- const unmanagedCount = [].concat.apply([], metadata).length;
1164
- const dependencyCount = targets.length - unmanagedCount;
1165
- if (dependencyCount > 0) {
1166
- return dependencyCount;
1167
- }
1168
- return getBaseClassDependencyCount(metadataReader, baseConstructor);
890
+ _getAllArgs(serviceIdentifier) {
891
+ return {
892
+ avoidConstraints: true,
893
+ isMultiInject: true,
894
+ serviceIdentifier
895
+ };
1169
896
  }
1170
- return 0;
1171
- }
1172
- function formatTargetMetadata(targetMetadata) {
1173
- const targetMetadataMap = {};
1174
- targetMetadata.forEach((m) => {
1175
- targetMetadataMap[m.key.toString()] = m.value;
1176
- });
1177
- return {
1178
- inject: targetMetadataMap[INJECT_TAG],
1179
- multiInject: targetMetadataMap[MULTI_INJECT_TAG],
1180
- targetName: targetMetadataMap[NAME_TAG],
1181
- unmanaged: targetMetadataMap[UNMANAGED_TAG]
1182
- };
1183
- }
1184
-
1185
- class Request {
1186
- constructor(serviceIdentifier, parentContext, parentRequest, bindings, target) {
1187
- this.id = id();
1188
- this.serviceIdentifier = serviceIdentifier;
1189
- this.parentContext = parentContext;
1190
- this.parentRequest = parentRequest;
1191
- this.target = target;
1192
- this.childRequests = [];
1193
- this.bindings = Array.isArray(bindings) ? bindings : [bindings];
1194
- this.requestScope = parentRequest === null ? new Map() : null;
1195
- }
1196
- addChildRequest(serviceIdentifier, bindings, target) {
1197
- const child = new Request(serviceIdentifier, this.parentContext, this, bindings, target);
1198
- this.childRequests.push(child);
1199
- return child;
1200
- }
1201
- }
1202
-
1203
- function getBindingDictionary(cntnr) {
1204
- return cntnr
1205
- ._bindingDictionary;
1206
- }
1207
- function _createTarget(isMultiInject, targetType, serviceIdentifier, name, key, value) {
1208
- const metadataKey = isMultiInject ? MULTI_INJECT_TAG : INJECT_TAG;
1209
- const injectMetadata = new Metadata(metadataKey, serviceIdentifier);
1210
- const target = new Target(targetType, name, serviceIdentifier, injectMetadata);
1211
- if (key !== undefined) {
1212
- const tagMetadata = new Metadata(key, value);
1213
- target.metadata.push(tagMetadata);
1214
- }
1215
- return target;
1216
- }
1217
- function _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target) {
1218
- let bindings = getBindings(context.container, target.serviceIdentifier);
1219
- let activeBindings = [];
1220
- if (bindings.length === BindingCount.NoBindingsAvailable &&
1221
- context.container.options.autoBindInjectable &&
1222
- typeof target.serviceIdentifier === 'function' &&
1223
- metadataReader.getConstructorMetadata(target.serviceIdentifier).compilerGeneratedMetadata) {
1224
- context.container.bind(target.serviceIdentifier).toSelf();
1225
- bindings = getBindings(context.container, target.serviceIdentifier);
1226
- }
1227
- if (!avoidConstraints) {
1228
- activeBindings = bindings.filter(binding => {
1229
- const request = new Request(binding.serviceIdentifier, context, parentRequest, binding, target);
1230
- return binding.constraint(request);
897
+ _get(getArgs) {
898
+ const result = [];
899
+ const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier);
900
+ bindings.forEach(binding => {
901
+ result.push(this._resolveFromBinding(binding));
1231
902
  });
903
+ return !getArgs.isMultiInject && result.length === 1 ? result[0] : result;
1232
904
  }
1233
- else {
1234
- activeBindings = bindings;
1235
- }
1236
- _validateActiveBindingCount(target.serviceIdentifier, activeBindings, target, context.container);
1237
- return activeBindings;
1238
- }
1239
- function _validateActiveBindingCount(serviceIdentifier, bindings, target, container) {
1240
- switch (bindings.length) {
1241
- case BindingCount.NoBindingsAvailable:
1242
- if (target.isOptional()) {
1243
- return bindings;
1244
- }
1245
- const serviceIdentifierString = getServiceIdentifierAsString(serviceIdentifier);
1246
- let msg = NOT_REGISTERED;
1247
- msg += listMetadataForTarget(serviceIdentifierString, target);
1248
- msg += listRegisteredBindingsForServiceIdentifier(container, serviceIdentifierString, getBindings);
1249
- throw new Error(msg);
1250
- case BindingCount.OnlyOneBindingAvailable:
1251
- return bindings;
1252
- case BindingCount.MultipleBindingsAvailable:
1253
- default:
1254
- if (!target.isArray()) {
1255
- const serviceIdentifierString = getServiceIdentifierAsString(serviceIdentifier);
1256
- let msg = `${AMBIGUOUS_MATCH} ${serviceIdentifierString}`;
1257
- msg += listRegisteredBindingsForServiceIdentifier(container, serviceIdentifierString, getBindings);
1258
- throw new Error(msg);
1259
- }
1260
- else {
1261
- return bindings;
1262
- }
1263
- }
1264
- }
1265
- function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, parentRequest, target) {
1266
- let activeBindings;
1267
- let childRequest;
1268
- if (parentRequest === null) {
1269
- activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target);
1270
- childRequest = new Request(serviceIdentifier, context, null, activeBindings, target);
1271
- const thePlan = new Plan(context, childRequest);
1272
- context.addPlan(thePlan);
1273
- }
1274
- else {
1275
- activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target);
1276
- childRequest = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target);
1277
- }
1278
- activeBindings.forEach(binding => {
1279
- let subChildRequest = null;
1280
- if (target.isArray()) {
1281
- subChildRequest = childRequest.addChildRequest(binding.serviceIdentifier, binding, target);
1282
- }
1283
- else {
1284
- if (binding.cache) {
1285
- return;
1286
- }
1287
- subChildRequest = childRequest;
1288
- }
1289
- if (binding.type === BindingTypeEnum.Instance && binding.implementationType !== null) {
1290
- const dependencies = getDependencies(metadataReader, binding.implementationType);
1291
- if (!context.container.options.skipBaseClassChecks) {
1292
- const baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, binding.implementationType);
1293
- if (dependencies.length < baseClassDependencyCount) {
1294
- const error = ARGUMENTS_LENGTH_MISMATCH(getFunctionName(binding.implementationType));
1295
- throw new Error(error);
1296
- }
1297
- }
1298
- dependencies.forEach((dependency) => {
1299
- _createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
905
+ _getChildRequest(binding) {
906
+ const constr = binding.implementationType;
907
+ const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr);
908
+ const keys = Object.keys(userGeneratedMetadata);
909
+ const arr = [];
910
+ for (let i = 0; i < keys.length; i++) {
911
+ const constructorArgsMetadata = userGeneratedMetadata[i];
912
+ const targetMetadataMap = {};
913
+ constructorArgsMetadata.forEach(md => {
914
+ targetMetadataMap[md.key] = md.value;
915
+ });
916
+ const metadata = {
917
+ inject: targetMetadataMap[INJECT_TAG],
918
+ multiInject: targetMetadataMap[MULTI_INJECT_TAG]
919
+ };
920
+ const injectIdentifier = metadata.inject || metadata.multiInject;
921
+ const target = {
922
+ serviceIdentifier: injectIdentifier,
923
+ constructorArgsMetadata
924
+ };
925
+ const bindings = this._bindingDictionary.get(injectIdentifier).filter(b => {
926
+ return b.constraint(target);
1300
927
  });
928
+ const request = {
929
+ injectIdentifier,
930
+ metadata: constructorArgsMetadata,
931
+ bindings
932
+ };
933
+ arr.push(request);
1301
934
  }
1302
- });
1303
- }
1304
- function getBindings(container, serviceIdentifier) {
1305
- let bindings = [];
1306
- const bindingDictionary = getBindingDictionary(container);
1307
- if (bindingDictionary.hasKey(serviceIdentifier)) {
1308
- bindings = bindingDictionary.get(serviceIdentifier);
1309
- }
1310
- else if (container.parent !== null) {
1311
- bindings = getBindings(container.parent, serviceIdentifier);
1312
- }
1313
- return bindings;
1314
- }
1315
- function plan(metadataReader, container, isMultiInject, targetType, serviceIdentifier, key, value, avoidConstraints = false) {
1316
- const context = new Context(container);
1317
- const target = _createTarget(isMultiInject, targetType, serviceIdentifier, '', key, value);
1318
- _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, null, target);
1319
- return context;
1320
- }
1321
- function createMockRequest(container, serviceIdentifier, key, value) {
1322
- const target = new Target(TargetTypeEnum.Variable, '', serviceIdentifier, new Metadata(key, value));
1323
- const context = new Context(container);
1324
- const request = new Request(serviceIdentifier, context, null, [], target);
1325
- return request;
1326
- }
1327
-
1328
- function isPromise(object) {
1329
- const isObjectOrFunction = (typeof object === 'object' && object !== null) || typeof object === 'function';
1330
- return isObjectOrFunction && typeof object.then === 'function';
1331
- }
1332
- function isPromiseOrContainsPromise(object) {
1333
- if (isPromise(object)) {
1334
- return true;
1335
- }
1336
- return Array.isArray(object) && object.some(isPromise);
1337
- }
1338
-
1339
- const tryGetFromScope = (requestScope, binding) => {
1340
- if (binding.scope === BindingScopeEnum.Singleton && binding.activated) {
1341
- return binding.cache;
1342
- }
1343
- if (binding.scope === BindingScopeEnum.Request && requestScope.has(binding.id)) {
1344
- return requestScope.get(binding.id);
1345
- }
1346
- return null;
1347
- };
1348
- const saveToScope = (requestScope, binding, result) => {
1349
- if (binding.scope === BindingScopeEnum.Singleton) {
1350
- _saveToSingletonScope(binding, result);
1351
- }
1352
- if (binding.scope === BindingScopeEnum.Request) {
1353
- _saveToRequestScope(requestScope, binding, result);
1354
- }
1355
- };
1356
- const _saveToRequestScope = (requestScope, binding, result) => {
1357
- if (!requestScope.has(binding.id)) {
1358
- requestScope.set(binding.id, result);
1359
- }
1360
- };
1361
- const _saveToSingletonScope = (binding, result) => {
1362
- binding.cache = result;
1363
- binding.activated = true;
1364
- if (isPromise(result)) {
1365
- void _saveAsyncResultToSingletonScope(binding, result);
1366
- }
1367
- };
1368
- const _saveAsyncResultToSingletonScope = (binding, asyncResult) => __awaiter(void 0, void 0, void 0, function* () {
1369
- try {
1370
- const result = yield asyncResult;
1371
- binding.cache = result;
1372
- }
1373
- catch (ex) {
1374
- binding.cache = null;
1375
- binding.activated = false;
1376
- throw ex;
1377
- }
1378
- });
1379
-
1380
- var FactoryType;
1381
- (function (FactoryType) {
1382
- FactoryType["DynamicValue"] = "toDynamicValue";
1383
- FactoryType["Factory"] = "toFactory";
1384
- FactoryType["Provider"] = "toProvider";
1385
- })(FactoryType || (FactoryType = {}));
1386
-
1387
- const ensureFullyBound = (binding) => {
1388
- let boundValue = null;
1389
- switch (binding.type) {
1390
- case BindingTypeEnum.ConstantValue:
1391
- case BindingTypeEnum.Function:
1392
- boundValue = binding.cache;
1393
- break;
1394
- case BindingTypeEnum.Constructor:
1395
- case BindingTypeEnum.Instance:
1396
- boundValue = binding.implementationType;
1397
- break;
1398
- case BindingTypeEnum.DynamicValue:
1399
- boundValue = binding.dynamicValue;
1400
- break;
1401
- case BindingTypeEnum.Provider:
1402
- boundValue = binding.provider;
1403
- break;
1404
- case BindingTypeEnum.Factory:
1405
- boundValue = binding.factory;
1406
- break;
1407
- }
1408
- if (boundValue === null) {
1409
- const serviceIdentifierAsString = getServiceIdentifierAsString(binding.serviceIdentifier);
1410
- throw new Error(`${INVALID_BINDING_TYPE} ${serviceIdentifierAsString}`);
935
+ return arr;
1411
936
  }
1412
- };
1413
- const getFactoryDetails = (binding) => {
1414
- switch (binding.type) {
1415
- case BindingTypeEnum.Factory:
1416
- return { factory: binding.factory, factoryType: FactoryType.Factory };
1417
- case BindingTypeEnum.Provider:
1418
- return { factory: binding.provider, factoryType: FactoryType.Provider };
1419
- case BindingTypeEnum.DynamicValue:
1420
- return { factory: binding.dynamicValue, factoryType: FactoryType.DynamicValue };
1421
- default:
1422
- throw new Error(`Unexpected factory type ${binding.type}`);
937
+ _resolveFromBinding(binding) {
938
+ const result = this._getResolvedFromBinding(binding);
939
+ this._saveToScope(binding, result);
940
+ return result;
1423
941
  }
1424
- };
1425
-
1426
- const tryAndThrowErrorIfStackOverflow = (fn, errorCallback) => {
1427
- return fn();
1428
- };
1429
-
1430
- function _resolveRequests(childRequests, resolveRequest) {
1431
- return childRequests.reduce((resolvedRequests, childRequest) => {
1432
- const injection = resolveRequest(childRequest);
1433
- const targetType = childRequest.target.type;
1434
- if (targetType === TargetTypeEnum.ConstructorArgument) {
1435
- resolvedRequests.constructorInjections.push(injection);
1436
- }
1437
- else {
1438
- resolvedRequests.propertyRequests.push(childRequest);
1439
- resolvedRequests.propertyInjections.push(injection);
1440
- }
1441
- if (!resolvedRequests.isAsync) {
1442
- resolvedRequests.isAsync = isPromiseOrContainsPromise(injection);
1443
- }
1444
- return resolvedRequests;
1445
- }, { constructorInjections: [], propertyInjections: [], propertyRequests: [], isAsync: false });
1446
- }
1447
- function _createInstance(constr, childRequests, resolveRequest) {
1448
- let result;
1449
- if (childRequests.length > 0) {
1450
- const resolved = _resolveRequests(childRequests, resolveRequest);
1451
- const createInstanceWithInjectionsArg = Object.assign(Object.assign({}, resolved), { constr });
1452
- if (resolved.isAsync) {
1453
- result = createInstanceWithInjectionsAsync(createInstanceWithInjectionsArg);
1454
- }
1455
- else {
1456
- result = createInstanceWithInjections(createInstanceWithInjectionsArg);
942
+ _getResolvedFromBinding(binding) {
943
+ let result;
944
+ switch (binding.type) {
945
+ case BindingTypeEnum.ConstantValue:
946
+ case BindingTypeEnum.Function:
947
+ result = binding.cache;
948
+ break;
949
+ case BindingTypeEnum.Instance:
950
+ result = this._resolveInstance(binding, binding.implementationType);
951
+ break;
952
+ default:
953
+ result = binding.dynamicValue({ container: this });
1457
954
  }
955
+ return result;
1458
956
  }
1459
- else {
1460
- result = new constr();
1461
- }
1462
- return result;
1463
- }
1464
- function createInstanceWithInjections(args) {
1465
- const instance = new args.constr(...args.constructorInjections);
1466
- args.propertyRequests.forEach((r, index) => {
1467
- const property = r.target.identifier;
1468
- const injection = args.propertyInjections[index];
1469
- instance[property] = injection;
1470
- });
1471
- return instance;
1472
- }
1473
- function createInstanceWithInjectionsAsync(args) {
1474
- return __awaiter(this, void 0, void 0, function* () {
1475
- const constructorInjections = yield possiblyWaitInjections(args.constructorInjections);
1476
- const propertyInjections = yield possiblyWaitInjections(args.propertyInjections);
1477
- return createInstanceWithInjections(Object.assign(Object.assign({}, args), { constructorInjections, propertyInjections }));
1478
- });
1479
- }
1480
- function possiblyWaitInjections(possiblePromiseinjections) {
1481
- return __awaiter(this, void 0, void 0, function* () {
1482
- const injections = [];
1483
- for (const injection of possiblePromiseinjections) {
1484
- if (Array.isArray(injection)) {
1485
- injections.push(Promise.all(injection));
1486
- }
1487
- else {
1488
- injections.push(injection);
1489
- }
957
+ _resolveInstance(binding, constr) {
958
+ if (binding.activated) {
959
+ return binding.cache;
1490
960
  }
1491
- return Promise.all(injections);
1492
- });
1493
- }
1494
- function _getInstanceAfterPostConstruct(constr, result) {
1495
- const postConstructResult = _postConstruct(constr, result);
1496
- if (isPromise(postConstructResult)) {
1497
- return postConstructResult.then(() => result);
1498
- }
1499
- return result;
1500
- }
1501
- function _postConstruct(constr, instance) {
1502
- var _a, _b;
1503
- if (Reflect$2.hasMetadata(POST_CONSTRUCT, constr)) {
1504
- const data = Reflect$2.getMetadata(POST_CONSTRUCT, constr);
1505
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
1506
- }
1507
- }
1508
- function _validateInstanceResolution(binding, constr) {
1509
- if (binding.scope !== BindingScopeEnum.Singleton) {
1510
- _throwIfHandlingDeactivation(binding, constr);
961
+ const childRequests = this._getChildRequest(binding);
962
+ return this._createInstance(constr, childRequests);
1511
963
  }
1512
- }
1513
- function _throwIfHandlingDeactivation(binding, constr) {
1514
- const scopeErrorMessage = `Class cannot be instantiated in ${binding.scope === BindingScopeEnum.Request ? 'request' : 'transient'} scope.`;
1515
- if (typeof binding.onDeactivation === 'function') {
1516
- throw new Error(ON_DEACTIVATION_ERROR(constr.name, scopeErrorMessage));
1517
- }
1518
- if (Reflect$2.hasMetadata(PRE_DESTROY, constr)) {
1519
- throw new Error(PRE_DESTROY_ERROR(constr.name, scopeErrorMessage));
1520
- }
1521
- }
1522
- function resolveInstance(binding, constr, childRequests, resolveRequest) {
1523
- _validateInstanceResolution(binding, constr);
1524
- const result = _createInstance(constr, childRequests, resolveRequest);
1525
- if (isPromise(result)) {
1526
- return result.then(resolvedResult => _getInstanceAfterPostConstruct(constr, resolvedResult));
964
+ _createInstance(constr, childRequests) {
965
+ if (childRequests.length) {
966
+ const resolved = this._resolveRequests(childRequests);
967
+ const obj = new constr(...resolved);
968
+ return obj;
969
+ }
970
+ const obj = new constr();
971
+ return obj;
1527
972
  }
1528
- return _getInstanceAfterPostConstruct(constr, result);
1529
- }
1530
-
1531
- const _resolveRequest = (requestScope) => (request) => {
1532
- request.parentContext.setCurrentRequest(request);
1533
- const bindings = request.bindings;
1534
- const childRequests = request.childRequests;
1535
- const targetIsAnArray = request.target && request.target.isArray();
1536
- const targetParentIsNotAnArray = !request.parentRequest ||
1537
- !request.parentRequest.target ||
1538
- !request.target ||
1539
- !request.parentRequest.target.matchesArray(request.target.serviceIdentifier);
1540
- if (targetIsAnArray && targetParentIsNotAnArray) {
1541
- return childRequests.map((childRequest) => {
1542
- const _f = _resolveRequest(requestScope);
1543
- return _f(childRequest);
973
+ _resolveRequests(childRequests) {
974
+ return childRequests.map(request => {
975
+ return request.bindings.length > 1
976
+ ? request.bindings.map(binding => this._resolveFromBinding(binding))
977
+ : this._resolveFromBinding(request.bindings[0]);
1544
978
  });
1545
979
  }
1546
- if (request.target.isOptional() && bindings.length === 0) {
1547
- return undefined;
1548
- }
1549
- const binding = bindings[0];
1550
- return _resolveBinding(requestScope, request, binding);
1551
- };
1552
- const _resolveFactoryFromBinding = (binding, context) => {
1553
- const factoryDetails = getFactoryDetails(binding);
1554
- return tryAndThrowErrorIfStackOverflow(() => factoryDetails.factory.bind(binding)(context));
1555
- };
1556
- const _getResolvedFromBinding = (requestScope, request, binding) => {
1557
- let result;
1558
- const childRequests = request.childRequests;
1559
- ensureFullyBound(binding);
1560
- switch (binding.type) {
1561
- case BindingTypeEnum.ConstantValue:
1562
- case BindingTypeEnum.Function:
1563
- result = binding.cache;
1564
- break;
1565
- case BindingTypeEnum.Constructor:
1566
- result = binding.implementationType;
1567
- break;
1568
- case BindingTypeEnum.Instance:
1569
- result = resolveInstance(binding, binding.implementationType, childRequests, _resolveRequest(requestScope));
1570
- break;
1571
- default:
1572
- result = _resolveFactoryFromBinding(binding, request.parentContext);
1573
- }
1574
- return result;
1575
- };
1576
- const _resolveInScope = (requestScope, binding, resolveFromBinding) => {
1577
- let result = tryGetFromScope(requestScope, binding);
1578
- if (result !== null) {
1579
- return result;
1580
- }
1581
- result = resolveFromBinding();
1582
- saveToScope(requestScope, binding, result);
1583
- return result;
1584
- };
1585
- const _resolveBinding = (requestScope, request, binding) => {
1586
- return _resolveInScope(requestScope, binding, () => {
1587
- const result = _getResolvedFromBinding(requestScope, request, binding);
1588
- return result;
1589
- });
1590
- };
1591
- function resolve(context) {
1592
- const _f = _resolveRequest(context.plan.rootRequest.requestScope);
1593
- return _f(context.plan.rootRequest);
1594
- }
1595
-
1596
- class BindingOnSyntax {
1597
- constructor(binding) {
1598
- this._binding = binding;
1599
- }
1600
- }
1601
-
1602
- const taggedConstraint = (key) => (value) => {
1603
- const constraint = (request) => request !== null && request.target !== null && request.target.matchesTag(key)(value);
1604
- constraint.metaData = new Metadata(key, value);
1605
- return constraint;
1606
- };
1607
- const namedConstraint = taggedConstraint(NAMED_TAG);
1608
-
1609
- class BindingWhenSyntax {
1610
- constructor(binding) {
1611
- this._binding = binding;
1612
- }
1613
- whenTargetNamed(name) {
1614
- this._binding.constraint = namedConstraint(name);
1615
- return new BindingOnSyntax(this._binding);
1616
- }
1617
- }
1618
-
1619
- class BindingWhenOnSyntax {
1620
- constructor(binding) {
1621
- this._binding = binding;
1622
- this._bindingWhenSyntax = new BindingWhenSyntax(this._binding);
1623
- }
1624
- whenTargetNamed(name) {
1625
- return this._bindingWhenSyntax.whenTargetNamed(name);
980
+ _saveToScope(binding, result) {
981
+ if (binding.scope === BindingScopeEnum.Singleton) {
982
+ binding.cache = result;
983
+ binding.activated = true;
984
+ }
1626
985
  }
1627
986
  }
1628
987
 
1629
- class BindingInSyntax {
1630
- constructor(binding) {
1631
- this._binding = binding;
1632
- }
1633
- inRequestScope() {
1634
- this._binding.scope = BindingScopeEnum.Request;
1635
- return new BindingWhenOnSyntax(this._binding);
1636
- }
1637
- inSingletonScope() {
1638
- this._binding.scope = BindingScopeEnum.Singleton;
1639
- return new BindingWhenOnSyntax(this._binding);
1640
- }
1641
- inTransientScope() {
1642
- this._binding.scope = BindingScopeEnum.Transient;
1643
- return new BindingWhenOnSyntax(this._binding);
1644
- }
1645
- }
988
+ function _typeof(o) {
989
+ "@babel/helpers - typeof";
1646
990
 
1647
- class BindingInWhenOnSyntax {
1648
- constructor(binding) {
1649
- this._binding = binding;
1650
- this._bindingWhenSyntax = new BindingWhenSyntax(this._binding);
1651
- this._bindingInSyntax = new BindingInSyntax(binding);
1652
- }
1653
- inRequestScope() {
1654
- return this._bindingInSyntax.inRequestScope();
1655
- }
1656
- inSingletonScope() {
1657
- return this._bindingInSyntax.inSingletonScope();
1658
- }
1659
- inTransientScope() {
1660
- return this._bindingInSyntax.inTransientScope();
1661
- }
1662
- whenTargetNamed(name) {
1663
- return this._bindingWhenSyntax.whenTargetNamed(name);
1664
- }
991
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
992
+ return typeof o;
993
+ } : function (o) {
994
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
995
+ }, _typeof(o);
1665
996
  }
1666
997
 
1667
- class BindingToSyntax {
1668
- constructor(binding) {
1669
- this._binding = binding;
1670
- }
1671
- to(constructor) {
1672
- this._binding.type = BindingTypeEnum.Instance;
1673
- this._binding.implementationType = constructor;
1674
- return new BindingInWhenOnSyntax(this._binding);
1675
- }
1676
- toSelf() {
1677
- if (typeof this._binding.serviceIdentifier !== 'function') {
1678
- throw new Error(`${INVALID_TO_SELF_VALUE}`);
1679
- }
1680
- const self = this._binding.serviceIdentifier;
1681
- return this.to(self);
1682
- }
1683
- toConstantValue(value) {
1684
- this._binding.type = BindingTypeEnum.ConstantValue;
1685
- this._binding.cache = value;
1686
- this._binding.dynamicValue = null;
1687
- this._binding.implementationType = null;
1688
- this._binding.scope = BindingScopeEnum.Singleton;
1689
- return new BindingWhenOnSyntax(this._binding);
1690
- }
1691
- toDynamicValue(func) {
1692
- this._binding.type = BindingTypeEnum.DynamicValue;
1693
- this._binding.cache = null;
1694
- this._binding.dynamicValue = func;
1695
- this._binding.implementationType = null;
1696
- return new BindingInWhenOnSyntax(this._binding);
1697
- }
1698
- toConstructor(constructor) {
1699
- this._binding.type = BindingTypeEnum.Constructor;
1700
- this._binding.implementationType = constructor;
1701
- this._binding.scope = BindingScopeEnum.Singleton;
1702
- return new BindingWhenOnSyntax(this._binding);
1703
- }
1704
- toFactory(factory) {
1705
- this._binding.type = BindingTypeEnum.Factory;
1706
- this._binding.factory = factory;
1707
- this._binding.scope = BindingScopeEnum.Singleton;
1708
- return new BindingWhenOnSyntax(this._binding);
1709
- }
1710
- toFunction(func) {
1711
- if (typeof func !== 'function') {
1712
- throw new Error(INVALID_FUNCTION_BINDING);
1713
- }
1714
- const bindingWhenOnSyntax = this.toConstantValue(func);
1715
- this._binding.type = BindingTypeEnum.Function;
1716
- this._binding.scope = BindingScopeEnum.Singleton;
1717
- return bindingWhenOnSyntax;
1718
- }
1719
- toAutoFactory(serviceIdentifier) {
1720
- this._binding.type = BindingTypeEnum.Factory;
1721
- this._binding.factory = context => {
1722
- const autofactory = () => context.container.get(serviceIdentifier);
1723
- return autofactory;
1724
- };
1725
- this._binding.scope = BindingScopeEnum.Singleton;
1726
- return new BindingWhenOnSyntax(this._binding);
1727
- }
1728
- toAutoNamedFactory(serviceIdentifier) {
1729
- this._binding.type = BindingTypeEnum.Factory;
1730
- this._binding.factory = context => {
1731
- return (named) => context.container.getNamed(serviceIdentifier, named);
1732
- };
1733
- return new BindingWhenOnSyntax(this._binding);
1734
- }
1735
- toProvider(provider) {
1736
- this._binding.type = BindingTypeEnum.Provider;
1737
- this._binding.provider = provider;
1738
- this._binding.scope = BindingScopeEnum.Singleton;
1739
- return new BindingWhenOnSyntax(this._binding);
1740
- }
1741
- toService(service) {
1742
- this.toDynamicValue(context => context.container.get(service));
1743
- }
998
+ function __decorate(decorators, target, key, desc) {
999
+ var c = arguments.length,
1000
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
1001
+ d;
1002
+ if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1003
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1744
1004
  }
1745
-
1746
- function isClonable(obj) {
1747
- return (typeof obj === 'object' &&
1748
- obj !== null &&
1749
- 'clone' in obj &&
1750
- typeof obj.clone === 'function');
1005
+ function __param(paramIndex, decorator) {
1006
+ return function (target, key) {
1007
+ decorator(target, key, paramIndex);
1008
+ };
1751
1009
  }
1752
-
1753
- class Lookup {
1754
- constructor() {
1755
- this._map = new Map();
1756
- }
1757
- getMap() {
1758
- return this._map;
1759
- }
1760
- add(serviceIdentifier, value) {
1761
- if (serviceIdentifier === null || serviceIdentifier === undefined) {
1762
- throw new Error(NULL_ARGUMENT);
1763
- }
1764
- if (value === null || value === undefined) {
1765
- throw new Error(NULL_ARGUMENT);
1766
- }
1767
- const entry = this._map.get(serviceIdentifier);
1768
- if (entry !== undefined) {
1769
- entry.push(value);
1770
- }
1771
- else {
1772
- this._map.set(serviceIdentifier, [value]);
1773
- }
1774
- }
1775
- get(serviceIdentifier) {
1776
- if (serviceIdentifier === null || serviceIdentifier === undefined) {
1777
- throw new Error(NULL_ARGUMENT);
1778
- }
1779
- const entry = this._map.get(serviceIdentifier);
1780
- if (entry !== undefined) {
1781
- return entry;
1782
- }
1783
- throw new Error(KEY_NOT_FOUND);
1784
- }
1785
- remove(serviceIdentifier) {
1786
- if (serviceIdentifier === null || serviceIdentifier === undefined) {
1787
- throw new Error(NULL_ARGUMENT);
1788
- }
1789
- if (!this._map.delete(serviceIdentifier)) {
1790
- throw new Error(KEY_NOT_FOUND);
1791
- }
1792
- }
1793
- removeIntersection(lookup) {
1794
- this.traverse((serviceIdentifier, value) => {
1795
- const lookupActivations = lookup.hasKey(serviceIdentifier) ? lookup.get(serviceIdentifier) : undefined;
1796
- if (lookupActivations !== undefined) {
1797
- const filteredValues = value.filter(lookupValue => !lookupActivations.some(moduleActivation => lookupValue === moduleActivation));
1798
- this._setValue(serviceIdentifier, filteredValues);
1799
- }
1800
- });
1801
- }
1802
- removeByCondition(condition) {
1803
- const removals = [];
1804
- this._map.forEach((entries, key) => {
1805
- const updatedEntries = [];
1806
- for (const entry of entries) {
1807
- const remove = condition(entry);
1808
- if (remove) {
1809
- removals.push(entry);
1810
- }
1811
- else {
1812
- updatedEntries.push(entry);
1813
- }
1814
- }
1815
- this._setValue(key, updatedEntries);
1816
- });
1817
- return removals;
1818
- }
1819
- hasKey(serviceIdentifier) {
1820
- if (serviceIdentifier === null || serviceIdentifier === undefined) {
1821
- throw new Error(NULL_ARGUMENT);
1822
- }
1823
- return this._map.has(serviceIdentifier);
1824
- }
1825
- clone() {
1826
- const copy = new Lookup();
1827
- this._map.forEach((value, key) => {
1828
- value.forEach(b => copy.add(key, isClonable(b) ? b.clone() : b));
1829
- });
1830
- return copy;
1831
- }
1832
- traverse(func) {
1833
- this._map.forEach((value, key) => {
1834
- func(key, value);
1835
- });
1836
- }
1837
- _setValue(serviceIdentifier, value) {
1838
- if (value.length > 0) {
1839
- this._map.set(serviceIdentifier, value);
1840
- }
1841
- else {
1842
- this._map.delete(serviceIdentifier);
1843
- }
1844
- }
1010
+ function __metadata(metadataKey, metadataValue) {
1011
+ if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1845
1012
  }
1846
-
1847
- class Container {
1848
- static merge(container1, container2, ...containers) {
1849
- const container = new Container();
1850
- const targetContainers = [
1851
- container1,
1852
- container2,
1853
- ...containers
1854
- ].map(targetContainer => getBindingDictionary(targetContainer));
1855
- const bindingDictionary = getBindingDictionary(container);
1856
- function copyDictionary(origin, destination) {
1857
- origin.traverse((_key, value) => {
1858
- value.forEach(binding => {
1859
- destination.add(binding.serviceIdentifier, binding.clone());
1860
- });
1861
- });
1862
- }
1863
- targetContainers.forEach(targetBindingDictionary => {
1864
- copyDictionary(targetBindingDictionary, bindingDictionary);
1865
- });
1866
- return container;
1867
- }
1868
- constructor(containerOptions) {
1869
- const options = containerOptions || {};
1870
- if (typeof options !== 'object') {
1871
- throw new Error(`${CONTAINER_OPTIONS_MUST_BE_AN_OBJECT}`);
1872
- }
1873
- if (options.defaultScope === undefined) {
1874
- options.defaultScope = BindingScopeEnum.Transient;
1875
- }
1876
- else if (options.defaultScope !== BindingScopeEnum.Singleton &&
1877
- options.defaultScope !== BindingScopeEnum.Transient &&
1878
- options.defaultScope !== BindingScopeEnum.Request) {
1879
- throw new Error(`${CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE}`);
1880
- }
1881
- if (options.autoBindInjectable === undefined) {
1882
- options.autoBindInjectable = false;
1883
- }
1884
- else if (typeof options.autoBindInjectable !== 'boolean') {
1885
- throw new Error(`${CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE}`);
1886
- }
1887
- if (options.skipBaseClassChecks === undefined) {
1888
- options.skipBaseClassChecks = false;
1889
- }
1890
- else if (typeof options.skipBaseClassChecks !== 'boolean') {
1891
- throw new Error(`${CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK}`);
1892
- }
1893
- this.options = {
1894
- autoBindInjectable: options.autoBindInjectable,
1895
- defaultScope: options.defaultScope,
1896
- skipBaseClassChecks: options.skipBaseClassChecks
1897
- };
1898
- this.id = id();
1899
- this._bindingDictionary = new Lookup();
1900
- this.parent = null;
1901
- this._metadataReader = new MetadataReader();
1902
- }
1903
- load(...modules) {
1904
- const getHelpers = this._getContainerModuleHelpersFactory();
1905
- for (const currentModule of modules) {
1906
- const containerModuleHelpers = getHelpers(currentModule.id);
1907
- currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
1908
- }
1909
- }
1910
- unload(...modules) {
1911
- modules.forEach(module => {
1912
- const deactivations = this._removeModuleBindings(module.id);
1913
- this._deactivateSingletons(deactivations);
1914
- });
1915
- }
1916
- bind(serviceIdentifier) {
1917
- const scope = this.options.defaultScope || BindingScopeEnum.Transient;
1918
- const binding = new Binding(serviceIdentifier, scope);
1919
- this._bindingDictionary.add(serviceIdentifier, binding);
1920
- return new BindingToSyntax(binding);
1921
- }
1922
- rebind(serviceIdentifier) {
1923
- this.unbind(serviceIdentifier);
1924
- return this.bind(serviceIdentifier);
1925
- }
1926
- unbind(serviceIdentifier) {
1927
- if (this._bindingDictionary.hasKey(serviceIdentifier)) {
1928
- const bindings = this._bindingDictionary.get(serviceIdentifier);
1929
- this._deactivateSingletons(bindings);
1930
- }
1931
- this._removeServiceFromDictionary(serviceIdentifier);
1932
- }
1933
- unbindAll() {
1934
- this._bindingDictionary.traverse((_key, value) => {
1935
- this._deactivateSingletons(value);
1936
- });
1937
- this._bindingDictionary = new Lookup();
1938
- }
1939
- isBound(serviceIdentifier) {
1940
- let bound = this._bindingDictionary.hasKey(serviceIdentifier);
1941
- if (!bound && this.parent) {
1942
- bound = this.parent.isBound(serviceIdentifier);
1943
- }
1944
- return bound;
1945
- }
1946
- isCurrentBound(serviceIdentifier) {
1947
- return this._bindingDictionary.hasKey(serviceIdentifier);
1948
- }
1949
- isBoundNamed(serviceIdentifier, named) {
1950
- return this.isBoundTagged(serviceIdentifier, NAMED_TAG, named);
1951
- }
1952
- isBoundTagged(serviceIdentifier, key, value) {
1953
- let bound = false;
1954
- if (this._bindingDictionary.hasKey(serviceIdentifier)) {
1955
- const bindings = this._bindingDictionary.get(serviceIdentifier);
1956
- const request = createMockRequest(this, serviceIdentifier, key, value);
1957
- bound = bindings.some(b => b.constraint(request));
1958
- }
1959
- if (!bound && this.parent) {
1960
- bound = this.parent.isBoundTagged(serviceIdentifier, key, value);
1961
- }
1962
- return bound;
1963
- }
1964
- applyCustomMetadataReader(metadataReader) {
1965
- this._metadataReader = metadataReader;
1966
- }
1967
- get(serviceIdentifier) {
1968
- const getArgs = this._getNotAllArgs(serviceIdentifier, false);
1969
- const data = this._getButThrowIfAsync(getArgs);
1970
- return data;
1971
- }
1972
- getAsync(serviceIdentifier) {
1973
- return __awaiter(this, void 0, void 0, function* () {
1974
- const getArgs = this._getNotAllArgs(serviceIdentifier, false);
1975
- return this._get(getArgs);
1976
- });
1977
- }
1978
- getTagged(serviceIdentifier, key, value) {
1979
- const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
1980
- return this._getButThrowIfAsync(getArgs);
1981
- }
1982
- getNamed(serviceIdentifier, named) {
1983
- return this.getTagged(serviceIdentifier, NAMED_TAG, named);
1984
- }
1985
- getAll(serviceIdentifier) {
1986
- const getArgs = this._getAllArgs(serviceIdentifier);
1987
- return this._getButThrowIfAsync(getArgs);
1988
- }
1989
- getAllTagged(serviceIdentifier, key, value) {
1990
- const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
1991
- return this._getButThrowIfAsync(getArgs);
1992
- }
1993
- getAllNamed(serviceIdentifier, named) {
1994
- return this.getAllTagged(serviceIdentifier, NAMED_TAG, named);
1995
- }
1996
- resolve(constructorFunction) {
1997
- const isBound = this.isBound(constructorFunction);
1998
- if (!isBound) {
1999
- this.bind(constructorFunction).toSelf();
2000
- }
2001
- const resolved = this.get(constructorFunction);
2002
- if (!isBound) {
2003
- this.unbind(constructorFunction);
2004
- }
2005
- return resolved;
2006
- }
2007
- _preDestroy(constructor, instance) {
2008
- var _a, _b;
2009
- if (Reflect$2.hasMetadata(PRE_DESTROY, constructor)) {
2010
- const data = Reflect$2.getMetadata(PRE_DESTROY, constructor);
2011
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
2012
- }
2013
- }
2014
- _removeModuleBindings(moduleId) {
2015
- return this._bindingDictionary.removeByCondition(binding => binding.moduleId === moduleId);
2016
- }
2017
- _deactivate(binding, instance) {
2018
- const constructor = Object.getPrototypeOf(instance).constructor;
2019
- try {
2020
- const propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
2021
- if (isPromise(propagateDeactivationResult)) {
2022
- return this._handleDeactivationError(propagateDeactivationResult, constructor);
2023
- }
2024
- }
2025
- catch (ex) {
2026
- if (ex instanceof Error) {
2027
- throw new Error(ON_DEACTIVATION_ERROR(constructor.name, ex.message));
2028
- }
2029
- }
2030
- }
2031
- _handleDeactivationError(asyncResult, constructor) {
2032
- return __awaiter(this, void 0, void 0, function* () {
2033
- try {
2034
- yield asyncResult;
2035
- }
2036
- catch (ex) {
2037
- if (ex instanceof Error) {
2038
- throw new Error(ON_DEACTIVATION_ERROR(constructor.name, ex.message));
2039
- }
2040
- }
2041
- });
2042
- }
2043
- _getContainerModuleHelpersFactory() {
2044
- const setModuleId = (bindingToSyntax, moduleId) => {
2045
- bindingToSyntax._binding.moduleId = moduleId;
2046
- };
2047
- const getBindFunction = (moduleId) => (serviceIdentifier) => {
2048
- const bindingToSyntax = this.bind(serviceIdentifier);
2049
- setModuleId(bindingToSyntax, moduleId);
2050
- return bindingToSyntax;
2051
- };
2052
- const getUnbindFunction = () => (serviceIdentifier) => {
2053
- return this.unbind(serviceIdentifier);
2054
- };
2055
- const getUnbindAsyncFunction = () => (serviceIdentifier) => {
2056
- return null;
2057
- };
2058
- const getIsboundFunction = () => (serviceIdentifier) => {
2059
- return this.isBound(serviceIdentifier);
2060
- };
2061
- const getRebindFunction = (moduleId) => (serviceIdentifier) => {
2062
- const bindingToSyntax = this.rebind(serviceIdentifier);
2063
- setModuleId(bindingToSyntax, moduleId);
2064
- return bindingToSyntax;
2065
- };
2066
- return (mId) => ({
2067
- bindFunction: getBindFunction(mId),
2068
- isboundFunction: getIsboundFunction(),
2069
- rebindFunction: getRebindFunction(mId),
2070
- unbindFunction: getUnbindFunction(),
2071
- unbindAsyncFunction: getUnbindAsyncFunction()
2072
- });
2073
- }
2074
- _get(getArgs) {
2075
- const planAndResolveArgs = Object.assign(Object.assign({}, getArgs), { contextInterceptor: context => context, targetType: TargetTypeEnum.Variable });
2076
- return this._planAndResolve()(planAndResolveArgs);
2077
- }
2078
- _getButThrowIfAsync(getArgs) {
2079
- const result = this._get(getArgs);
2080
- return result;
2081
- }
2082
- _getAllArgs(serviceIdentifier) {
2083
- const getAllArgs = {
2084
- avoidConstraints: true,
2085
- isMultiInject: true,
2086
- serviceIdentifier
2087
- };
2088
- return getAllArgs;
2089
- }
2090
- _getNotAllArgs(serviceIdentifier, isMultiInject, key, value) {
2091
- const getNotAllArgs = {
2092
- avoidConstraints: false,
2093
- isMultiInject,
2094
- serviceIdentifier,
2095
- key,
2096
- value
2097
- };
2098
- return getNotAllArgs;
2099
- }
2100
- _planAndResolve() {
2101
- return (args) => {
2102
- let context = plan(this._metadataReader, this, args.isMultiInject, args.targetType, args.serviceIdentifier, args.key, args.value, args.avoidConstraints);
2103
- context = args.contextInterceptor(context);
2104
- const result = resolve(context);
2105
- return result;
2106
- };
2107
- }
2108
- _deactivateIfSingleton(binding) {
2109
- if (!binding.activated) {
2110
- return;
2111
- }
2112
- if (isPromise(binding.cache)) {
2113
- return binding.cache.then(resolved => this._deactivate(binding, resolved));
2114
- }
2115
- return this._deactivate(binding, binding.cache);
2116
- }
2117
- _deactivateSingletons(bindings) {
2118
- for (const binding of bindings) {
2119
- const result = this._deactivateIfSingleton(binding);
2120
- if (isPromise(result)) {
2121
- throw new Error(ASYNC_UNBIND_REQUIRED);
2122
- }
2123
- }
2124
- }
2125
- _propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor) {
2126
- if (this.parent) {
2127
- return this._deactivate.bind(this.parent)(binding, instance);
2128
- }
2129
- return this._bindingDeactivationAndPreDestroy(binding, instance, constructor);
2130
- }
2131
- _removeServiceFromDictionary(serviceIdentifier) {
2132
- try {
2133
- this._bindingDictionary.remove(serviceIdentifier);
2134
- }
2135
- catch (e) {
2136
- throw new Error(`${CANNOT_UNBIND} ${getServiceIdentifierAsString(serviceIdentifier)}`);
2137
- }
1013
+ function __awaiter(thisArg, _arguments, P, generator) {
1014
+ function adopt(value) {
1015
+ return value instanceof P ? value : new P(function (resolve) {
1016
+ resolve(value);
1017
+ });
1018
+ }
1019
+ return new (P || (P = Promise))(function (resolve, reject) {
1020
+ function fulfilled(value) {
1021
+ try {
1022
+ step(generator.next(value));
1023
+ } catch (e) {
1024
+ reject(e);
1025
+ }
2138
1026
  }
2139
- _bindingDeactivationAndPreDestroy(binding, instance, constructor) {
2140
- if (typeof binding.onDeactivation === 'function') {
2141
- const result = binding.onDeactivation(instance);
2142
- if (isPromise(result)) {
2143
- return result.then(() => this._preDestroy(constructor, instance));
2144
- }
2145
- }
2146
- return this._preDestroy(constructor, instance);
1027
+ function rejected(value) {
1028
+ try {
1029
+ step(generator["throw"](value));
1030
+ } catch (e) {
1031
+ reject(e);
1032
+ }
2147
1033
  }
2148
- _bindingDeactivationAndPreDestroyAsync(binding, instance, constructor) {
2149
- return __awaiter(this, void 0, void 0, function* () {
2150
- if (typeof binding.onDeactivation === 'function') {
2151
- yield binding.onDeactivation(instance);
2152
- }
2153
- yield this._preDestroy(constructor, instance);
2154
- });
1034
+ function step(result) {
1035
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
2155
1036
  }
1037
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1038
+ });
2156
1039
  }
2157
-
2158
- function propertyEventDecorator(eventKey, errorMessage) {
2159
- return () => {
2160
- return (target, propertyKey) => {
2161
- const metadata = new Metadata(eventKey, propertyKey);
2162
- if (Reflect$2.hasOwnMetadata(eventKey, target.constructor)) {
2163
- throw new Error(errorMessage);
2164
- }
2165
- Reflect$2.defineMetadata(eventKey, metadata, target.constructor);
2166
- };
2167
- };
2168
- }
2169
-
2170
- const postConstruct = propertyEventDecorator(POST_CONSTRUCT, MULTIPLE_POST_CONSTRUCT_METHODS);
1040
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1041
+ var e = new Error(message);
1042
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1043
+ };
2171
1044
 
2172
1045
  const ContributionProvider = Symbol('ContributionProvider');
2173
1046
  class ContributionProviderCache {
@@ -2352,11 +1225,13 @@
2352
1225
  }
2353
1226
  constructor(contributions) {
2354
1227
  this.contributions = contributions;
1228
+ this.id = Generator.GenAutoIncrementId();
2355
1229
  this.hooks = {
2356
1230
  onSetEnv: new SyncHook(['lastEnv', 'env', 'global'])
2357
1231
  };
2358
1232
  this.measureTextMethod = 'native';
2359
1233
  this.optimizeVisible = false;
1234
+ this.optmizeSkipCheckBoundariesThreshold = 0;
2360
1235
  }
2361
1236
  bindContribution(params) {
2362
1237
  const promiseArr = [];
@@ -4291,7 +3166,10 @@
4291
3166
  direction: 'horizontal',
4292
3167
  wordBreak: 'break-all',
4293
3168
  ignoreBuf: false,
4294
- verticalMode: 0
3169
+ verticalMode: 0,
3170
+ whiteSpace: 'no-wrap',
3171
+ heightLimit: Infinity,
3172
+ lineClamp: Infinity
4295
3173
  };
4296
3174
  const DefaultStyle = Object.assign(Object.assign(Object.assign({ opacity: 1, background: null, texture: null, textureColor: 'black', textureSize: 10, texturePadding: 2, backgroundMode: 0, blur: 0, cursor: null, html: null }, DefaultFillStyle), DefaultStrokeStyle), DefaultLayout);
4297
3175
  const DefaultConnectAttribute = {
@@ -5422,6 +4300,13 @@
5422
4300
  class DefaultCanvasAllocate {
5423
4301
  constructor() {
5424
4302
  this.pools = [];
4303
+ this.allocatedCanvas = [];
4304
+ }
4305
+ shareCanvas() {
4306
+ if (this.allocatedCanvas.length) {
4307
+ return this.allocatedCanvas[0];
4308
+ }
4309
+ return this.getCommonCanvas();
5425
4310
  }
5426
4311
  getCommonCanvas() {
5427
4312
  if (!this._commonCanvas) {
@@ -5431,7 +4316,9 @@
5431
4316
  }
5432
4317
  allocate(data) {
5433
4318
  if (!this.pools.length) {
5434
- return wrapCanvas(Object.assign({ nativeCanvas: application.global.createCanvas(data) }, data));
4319
+ const c = wrapCanvas(Object.assign({ nativeCanvas: application.global.createCanvas(data) }, data));
4320
+ this.allocatedCanvas.push(c);
4321
+ return c;
5435
4322
  }
5436
4323
  const m = this.pools.pop();
5437
4324
  m.resize(data.width, data.height);
@@ -5445,7 +4332,9 @@
5445
4332
  height: canvas.height / canvas.dpr,
5446
4333
  dpr: canvas.dpr
5447
4334
  };
5448
- return wrapCanvas(Object.assign({ nativeCanvas: application.global.createCanvas(data) }, data));
4335
+ const c = wrapCanvas(Object.assign({ nativeCanvas: application.global.createCanvas(data) }, data));
4336
+ this.allocatedCanvas.push(c);
4337
+ return c;
5449
4338
  }
5450
4339
  const m = this.pools.pop();
5451
4340
  m.width = canvas.width;
@@ -5465,6 +4354,14 @@
5465
4354
  const canvasAllocate = new DefaultCanvasAllocate();
5466
4355
 
5467
4356
  exports.DefaultGraphicUtil = class DefaultGraphicUtil {
4357
+ get canvas() {
4358
+ this.tryInitCanvas();
4359
+ return this._canvas;
4360
+ }
4361
+ get context() {
4362
+ this.tryInitCanvas();
4363
+ return this._context;
4364
+ }
5468
4365
  constructor(contributions) {
5469
4366
  this.contributions = contributions;
5470
4367
  this.configured = false;
@@ -5484,14 +4381,18 @@
5484
4381
  if (this.configured) {
5485
4382
  return;
5486
4383
  }
5487
- const canvas = canvasAllocate.getCommonCanvas();
5488
- this.canvas = canvas;
5489
- this.context = canvas.getContext('2d');
5490
4384
  this.contributions.getContributions().forEach(contribution => {
5491
4385
  contribution.configure(this, env);
5492
4386
  });
5493
4387
  this.configured = true;
5494
4388
  }
4389
+ tryInitCanvas() {
4390
+ if (!this._canvas) {
4391
+ const canvas = canvasAllocate.shareCanvas();
4392
+ this._canvas = canvas;
4393
+ this._context = canvas.getContext('2d');
4394
+ }
4395
+ }
5495
4396
  bindTextMeasure(tm) {
5496
4397
  this._textMeasure = tm;
5497
4398
  }
@@ -5816,13 +4717,6 @@
5816
4717
  return null;
5817
4718
  }
5818
4719
 
5819
- class Generator {
5820
- static GenAutoIncrementId() {
5821
- return Generator.auto_increment_id++;
5822
- }
5823
- }
5824
- Generator.auto_increment_id = 0;
5825
-
5826
4720
  class Node extends vutils.EventEmitter {
5827
4721
  get previousSibling() {
5828
4722
  return this._prev;
@@ -9022,6 +7916,13 @@
9022
7916
  }
9023
7917
  RafBasedSTO.TimeOut = 1000 / 60;
9024
7918
  const rafBasedSto = new RafBasedSTO();
7919
+ const calculateLineHeight = (lineHeight, fontSize) => {
7920
+ if (vutils.isString(lineHeight) && lineHeight[lineHeight.length - 1] === '%') {
7921
+ const scale = Number.parseFloat(lineHeight.substring(0, lineHeight.length - 1)) / 100;
7922
+ return fontSize * scale;
7923
+ }
7924
+ return lineHeight;
7925
+ };
9025
7926
 
9026
7927
  class IncreaseCount extends ACustomAnimate {
9027
7928
  constructor(from, to, duration, easing, params) {
@@ -13466,6 +12367,7 @@
13466
12367
  };
13467
12368
  this._uid = Generator.GenAutoIncrementId();
13468
12369
  this.global = application.global;
12370
+ this.postInit();
13469
12371
  }
13470
12372
  postInit() {
13471
12373
  this.global.hooks.onSetEnv.tap('window', () => {
@@ -13551,12 +12453,6 @@
13551
12453
  return this._handler.getTopLeft(baseWindow);
13552
12454
  }
13553
12455
  };
13554
- __decorate([
13555
- postConstruct(),
13556
- __metadata("design:type", Function),
13557
- __metadata("design:paramtypes", []),
13558
- __metadata("design:returntype", void 0)
13559
- ], exports.DefaultWindow.prototype, "postInit", null);
13560
12456
  exports.DefaultWindow = __decorate([
13561
12457
  injectable(),
13562
12458
  __metadata("design:paramtypes", [])
@@ -14324,6 +13220,8 @@
14324
13220
  const TEXT_UPDATE_TAG_KEY = [
14325
13221
  'text',
14326
13222
  'maxLineWidth',
13223
+ 'heightLimit',
13224
+ 'lineClamp',
14327
13225
  'fontSize',
14328
13226
  'fontFamily',
14329
13227
  'fontWeight',
@@ -14408,6 +13306,113 @@
14408
13306
  this.clearUpdateBoundTag();
14409
13307
  return bounds;
14410
13308
  }
13309
+ updateWrapAABBBounds(text) {
13310
+ var _a, _b, _c, _d;
13311
+ const textTheme = getTheme(this).text;
13312
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
13313
+ const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
13314
+ const buf = ignoreBuf ? 0 : 2;
13315
+ if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
13316
+ const bbox = this.cache.layoutData.bbox;
13317
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
13318
+ if (stroke) {
13319
+ this._AABBBounds.expand(lineWidth / 2);
13320
+ }
13321
+ return this._AABBBounds;
13322
+ }
13323
+ const textMeasure = application.graphicUtil.textMeasure;
13324
+ const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure);
13325
+ const lines = vutils.isArray(text) ? text.map(l => l.toString()) : [text.toString()];
13326
+ const linesLayout = [];
13327
+ const bboxWH = [0, 0];
13328
+ let lineCountLimit = Infinity;
13329
+ if (heightLimit > 0) {
13330
+ lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1);
13331
+ }
13332
+ if (lineClamp) {
13333
+ lineCountLimit = Math.min(lineCountLimit, lineClamp);
13334
+ }
13335
+ if (typeof maxLineWidth === 'number' && maxLineWidth !== Infinity) {
13336
+ if (maxLineWidth > 0) {
13337
+ for (let i = 0; i < lines.length; i++) {
13338
+ const str = lines[i];
13339
+ let needCut = true;
13340
+ if (i === lineCountLimit - 1) {
13341
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
13342
+ linesLayout.push({
13343
+ str: clip.str,
13344
+ width: clip.width
13345
+ });
13346
+ break;
13347
+ }
13348
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, wordBreak === 'break-word');
13349
+ if (str !== '' && clip.str === '') {
13350
+ if (ellipsis) {
13351
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
13352
+ clip.str = (_c = clipEllipsis.str) !== null && _c !== void 0 ? _c : '';
13353
+ clip.width = (_d = clipEllipsis.width) !== null && _d !== void 0 ? _d : 0;
13354
+ }
13355
+ else {
13356
+ clip.str = '';
13357
+ clip.width = 0;
13358
+ }
13359
+ needCut = false;
13360
+ }
13361
+ linesLayout.push({
13362
+ str: clip.str,
13363
+ width: clip.width
13364
+ });
13365
+ if (clip.str.length === str.length) ;
13366
+ else if (needCut) {
13367
+ const newStr = str.substring(clip.str.length);
13368
+ lines.splice(i + 1, 0, newStr);
13369
+ }
13370
+ }
13371
+ }
13372
+ let maxWidth = 0;
13373
+ linesLayout.forEach(layout => {
13374
+ maxWidth = Math.max(maxWidth, layout.width);
13375
+ });
13376
+ bboxWH[0] = maxWidth;
13377
+ }
13378
+ else {
13379
+ let lineWidth = 0;
13380
+ let width;
13381
+ let text;
13382
+ for (let i = 0, len = lines.length; i < len; i++) {
13383
+ if (i === lineCountLimit - 1) {
13384
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, false);
13385
+ linesLayout.push({
13386
+ str: clip.str,
13387
+ width: clip.width
13388
+ });
13389
+ lineWidth = Math.max(lineWidth, clip.width);
13390
+ break;
13391
+ }
13392
+ text = lines[i];
13393
+ width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, wordBreak === 'break-word');
13394
+ lineWidth = Math.max(lineWidth, width);
13395
+ linesLayout.push({ str: text, width });
13396
+ }
13397
+ bboxWH[0] = lineWidth;
13398
+ }
13399
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
13400
+ const bbox = {
13401
+ xOffset: 0,
13402
+ yOffset: 0,
13403
+ width: bboxWH[0],
13404
+ height: bboxWH[1]
13405
+ };
13406
+ layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
13407
+ const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
13408
+ this.cache.layoutData = layoutData;
13409
+ this.clearUpdateShapeTag();
13410
+ this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
13411
+ if (stroke) {
13412
+ this._AABBBounds.expand(lineWidth / 2);
13413
+ }
13414
+ return this._AABBBounds;
13415
+ }
14411
13416
  updateSingallineAABBBounds(text) {
14412
13417
  const textTheme = getTheme(this).text;
14413
13418
  const { direction = textTheme.direction } = this.attribute;
@@ -14429,9 +13434,13 @@
14429
13434
  let width;
14430
13435
  let str;
14431
13436
  const attribute = this.attribute;
14432
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf } = attribute;
13437
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, ignoreBuf = textTheme.ignoreBuf, whiteSpace = textTheme.whiteSpace } = attribute;
13438
+ if (whiteSpace === 'normal') {
13439
+ return this.updateWrapAABBBounds(text);
13440
+ }
14433
13441
  const buf = ignoreBuf ? 0 : Math.max(2, fontSize * 0.075);
14434
- const { lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf } = attribute;
13442
+ const textFontSize = attribute.fontSize || textTheme.fontSize;
13443
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) !== null && _a !== void 0 ? _a : textFontSize + buf;
14435
13444
  if (!this.shouldUpdateShape() && this.cache) {
14436
13445
  width = (_b = this.cache.clipedWidth) !== null && _b !== void 0 ? _b : 0;
14437
13446
  const dx = textDrawOffsetX(textAlign, width);
@@ -14489,7 +13498,8 @@
14489
13498
  const attribute = this.attribute;
14490
13499
  const { ignoreBuf = textTheme.ignoreBuf } = attribute;
14491
13500
  const buf = ignoreBuf ? 0 : 2;
14492
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
13501
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, fontFamily = textTheme.fontFamily, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
13502
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14493
13503
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
14494
13504
  if (!verticalMode) {
14495
13505
  const t = textAlign;
@@ -14546,11 +13556,15 @@
14546
13556
  return this._AABBBounds;
14547
13557
  }
14548
13558
  updateHorizontalMultilineAABBBounds(text) {
14549
- var _a;
13559
+ var _a, _b;
14550
13560
  const textTheme = getTheme(this).text;
14551
13561
  const attribute = this.attribute;
14552
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, lineHeight = attribute.lineHeight || attribute.fontSize || textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak } = attribute;
14553
- if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
13562
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, whiteSpace = textTheme.whiteSpace } = attribute;
13563
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize);
13564
+ if (whiteSpace === 'normal') {
13565
+ return this.updateWrapAABBBounds(text);
13566
+ }
13567
+ if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
14554
13568
  const bbox = this.cache.layoutData.bbox;
14555
13569
  this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
14556
13570
  if (stroke) {
@@ -14578,7 +13592,8 @@
14578
13592
  const attribute = this.attribute;
14579
13593
  const { ignoreBuf = textTheme.ignoreBuf } = attribute;
14580
13594
  const buf = ignoreBuf ? 0 : 2;
14581
- const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineHeight = (_a = attribute.lineHeight) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
13595
+ const { maxLineWidth = textTheme.maxLineWidth, ellipsis = textTheme.ellipsis, fontFamily = textTheme.fontFamily, fontSize = textTheme.fontSize, fontWeight = textTheme.fontWeight, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, verticalMode = textTheme.verticalMode } = attribute;
13596
+ const lineHeight = (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14582
13597
  let { textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline } = attribute;
14583
13598
  if (!verticalMode) {
14584
13599
  const t = textAlign;
@@ -14685,11 +13700,12 @@
14685
13700
  return text != null && text !== '';
14686
13701
  }
14687
13702
  updateMultilineAABBBounds(text) {
14688
- var _a, _b, _c;
13703
+ var _a, _b, _c, _d;
14689
13704
  const textTheme = getTheme(this).text;
14690
- const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, lineHeight = this.attribute.lineHeight || this.attribute.fontSize || textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
13705
+ const { fontFamily = textTheme.fontFamily, textAlign = textTheme.textAlign, textBaseline = textTheme.textBaseline, fontSize = textTheme.fontSize, ellipsis = textTheme.ellipsis, maxLineWidth, stroke = textTheme.stroke, lineWidth = textTheme.lineWidth, wordBreak = textTheme.wordBreak, fontWeight = textTheme.fontWeight, ignoreBuf = textTheme.ignoreBuf, heightLimit = 0, lineClamp } = this.attribute;
13706
+ const lineHeight = (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) !== null && _a !== void 0 ? _a : (this.attribute.fontSize || textTheme.fontSize);
14691
13707
  const buf = ignoreBuf ? 0 : 2;
14692
- if (!this.shouldUpdateShape() && ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.layoutData)) {
13708
+ if (!this.shouldUpdateShape() && ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.layoutData)) {
14693
13709
  const bbox = this.cache.layoutData.bbox;
14694
13710
  this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height);
14695
13711
  if (stroke) {
@@ -14726,8 +13742,8 @@
14726
13742
  if (str !== '' && clip.str === '') {
14727
13743
  if (ellipsis) {
14728
13744
  const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, false);
14729
- clip.str = (_b = clipEllipsis.str) !== null && _b !== void 0 ? _b : '';
14730
- clip.width = (_c = clipEllipsis.width) !== null && _c !== void 0 ? _c : 0;
13745
+ clip.str = (_c = clipEllipsis.str) !== null && _c !== void 0 ? _c : '';
13746
+ clip.width = (_d = clipEllipsis.width) !== null && _d !== void 0 ? _d : 0;
14731
13747
  }
14732
13748
  else {
14733
13749
  clip.str = '';
@@ -15569,6 +14585,13 @@
15569
14585
  builtinSymbols.forEach(symbol => {
15570
14586
  builtinSymbolsMap[symbol.type] = symbol;
15571
14587
  });
14588
+ const builtInSymbolStrMap = {
14589
+ arrowLeft: 'M 0.25 -0.5 L -0.25 0 l 0.5 0.5',
14590
+ arrowRight: 'M -0.25 -0.5 l 0.5 0.5 l -0.5 0.5',
14591
+ rect: 'M -0.5,0.25 L 0.5,0.25 L 0.5,-0.25,L -0.5,-0.25 Z',
14592
+ rectRound: 'M 0.3 -0.5 C 0.41 -0.5 0.5 -0.41 0.5 -0.3 C 0.5 -0.3 0.5 0.3 0.5 0.3 C 0.5 0.41 0.41 0.5 0.3 0.5 C 0.3 0.5 -0.3 0.5 -0.3 0.5 C -0.41 0.5 -0.5 0.41 -0.5 0.3 C -0.5 0.3 -0.5 -0.3 -0.5 -0.3 C -0.5 -0.41 -0.41 -0.5 -0.3 -0.5 C -0.3 -0.5 0.3 -0.5 0.3 -0.5 Z',
14593
+ roundLine: 'M 1.2392 -0.258 L -1.3432 -0.258 C -1.4784 -0.258 -1.588 -0.1436 -1.588 -0.002 c 0 0.1416 0.1096 0.256 0.2448 0.256 l 2.5824 0 c 0.1352 0 0.2448 -0.1144 0.2448 -0.256 C 1.484 -0.1436 1.3744 -0.258 1.2392 -0.258 z'
14594
+ };
15572
14595
 
15573
14596
  const _tempBounds$1 = new vutils.AABBBounds();
15574
14597
  const SYMBOL_UPDATE_TAG_KEY = ['symbolType', 'size', ...GRAPHIC_UPDATE_TAG_KEY];
@@ -15594,7 +14617,7 @@
15594
14617
  }
15595
14618
  doUpdateParsedPath() {
15596
14619
  const symbolTheme = getTheme(this).symbol;
15597
- const { symbolType = symbolTheme.symbolType } = this.attribute;
14620
+ let { symbolType = symbolTheme.symbolType } = this.attribute;
15598
14621
  let path = builtinSymbolsMap[symbolType];
15599
14622
  if (path) {
15600
14623
  this._parsedPath = path;
@@ -15605,6 +14628,8 @@
15605
14628
  this._parsedPath = path;
15606
14629
  return path;
15607
14630
  }
14631
+ const _symbolType = builtInSymbolStrMap[symbolType];
14632
+ symbolType = _symbolType || symbolType;
15608
14633
  const valid = isSvg(symbolType);
15609
14634
  if (valid === true) {
15610
14635
  const parser = new XMLParser();
@@ -16354,8 +15379,9 @@
16354
15379
  constructor(text, newLine, character) {
16355
15380
  this.fontSize = character.fontSize || 16;
16356
15381
  this.textBaseline = character.textBaseline || 'alphabetic';
16357
- if (typeof character.lineHeight === 'number') {
16358
- this.lineHeight = character.lineHeight > this.fontSize ? character.lineHeight : this.fontSize;
15382
+ const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);
15383
+ if (typeof lineHeight === 'number') {
15384
+ this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;
16359
15385
  }
16360
15386
  else {
16361
15387
  this.lineHeight = Math.floor(1.2 * this.fontSize);
@@ -20671,19 +19697,55 @@
20671
19697
  }
20672
19698
  return !!ret;
20673
19699
  }
19700
+ drawLinearLineHighPerformance(line, context, fill, stroke, fillOpacity, strokeOpacity, offsetX, offsetY, lineAttribute, drawContext, params, fillCb, strokeCb) {
19701
+ var _a;
19702
+ context.beginPath();
19703
+ const z = (_a = this.z) !== null && _a !== void 0 ? _a : 0;
19704
+ const { points } = line.attribute;
19705
+ const startP = points[0];
19706
+ context.moveTo(startP.x, startP.y, z);
19707
+ for (let i = 1; i < points.length; i++) {
19708
+ const p = points[i];
19709
+ context.lineTo(p.x, p.y, z);
19710
+ }
19711
+ context.setShadowBlendStyle && context.setShadowBlendStyle(line, line.attribute, lineAttribute);
19712
+ const { x: originX = 0, x: originY = 0 } = line.attribute;
19713
+ if (fill !== false) {
19714
+ if (fillCb) {
19715
+ fillCb(context, line.attribute, lineAttribute);
19716
+ }
19717
+ else if (fillOpacity) {
19718
+ context.setCommonStyle(line, line.attribute, originX - offsetX, originY - offsetY, lineAttribute);
19719
+ context.fill();
19720
+ }
19721
+ }
19722
+ if (stroke !== false) {
19723
+ if (strokeCb) {
19724
+ strokeCb(context, line.attribute, lineAttribute);
19725
+ }
19726
+ else if (strokeOpacity) {
19727
+ context.setStrokeStyle(line, line.attribute, originX - offsetX, originY - offsetY, lineAttribute);
19728
+ context.stroke();
19729
+ }
19730
+ }
19731
+ }
20674
19732
  drawShape(line, context, x, y, drawContext, params, fillCb, strokeCb) {
20675
19733
  const lineAttribute = getTheme(line, params === null || params === void 0 ? void 0 : params.theme).line;
20676
- const { fill = lineAttribute.fill, stroke = lineAttribute.stroke, fillOpacity = lineAttribute.fillOpacity, strokeOpacity = lineAttribute.strokeOpacity } = line.attribute;
19734
+ const { fill = lineAttribute.fill, stroke = lineAttribute.stroke, fillOpacity = lineAttribute.fillOpacity, strokeOpacity = lineAttribute.strokeOpacity, segments, points, closePath } = line.attribute;
20677
19735
  const data = this.valid(line, lineAttribute, fillCb, strokeCb);
20678
19736
  if (!data) {
20679
19737
  return;
20680
19738
  }
19739
+ let { curveType = lineAttribute.curveType } = line.attribute;
19740
+ if (closePath && curveType === 'linear') {
19741
+ curveType = 'linearClosed';
19742
+ }
19743
+ const { clipRange = lineAttribute.clipRange, clipRangeByDimension = lineAttribute.clipRangeByDimension } = line.attribute;
19744
+ if (clipRange === 1 && !segments && !points.some(p => p.defined === false) && curveType === 'linear') {
19745
+ return this.drawLinearLineHighPerformance(line, context, !!fill, !!stroke, fillOpacity, strokeOpacity, x, y, lineAttribute, drawContext, params, fillCb, strokeCb);
19746
+ }
20681
19747
  if (line.shouldUpdateShape()) {
20682
- const { points, segments, closePath } = line.attribute;
20683
- let { curveType = lineAttribute.curveType } = line.attribute;
20684
- if (closePath && curveType === 'linear') {
20685
- curveType = 'linearClosed';
20686
- }
19748
+ const { points, segments } = line.attribute;
20687
19749
  const _points = points;
20688
19750
  if (segments && segments.length) {
20689
19751
  let startPoint;
@@ -20747,7 +19809,6 @@
20747
19809
  }
20748
19810
  line.clearUpdateShapeTag();
20749
19811
  }
20750
- const { clipRange = lineAttribute.clipRange, clipRangeByDimension = lineAttribute.clipRangeByDimension } = line.attribute;
20751
19812
  if (Array.isArray(line.cache)) {
20752
19813
  const segments = line.attribute.segments.filter(item => item.points.length);
20753
19814
  if (segments[0].points.length === 1) {
@@ -21691,14 +20752,14 @@
21691
20752
  drawShape(text, context, x, y, drawContext, params, fillCb, strokeCb) {
21692
20753
  var _a, _b, _c;
21693
20754
  const textAttribute = getTheme(text, params === null || params === void 0 ? void 0 : params.theme).text;
21694
- const { text: str, fill = textAttribute.fill, stroke = textAttribute.stroke, fillOpacity = textAttribute.fillOpacity, strokeOpacity = textAttribute.strokeOpacity, opacity = textAttribute.opacity, lineWidth = textAttribute.lineWidth, visible = textAttribute.visible, underline = textAttribute.underline, lineThrough = textAttribute.lineThrough, keepDirIn3d = textAttribute.keepDirIn3d, direction = textAttribute.direction, fontSize = textAttribute.fontSize, verticalMode = textAttribute.verticalMode, x: originX = textAttribute.x, y: originY = textAttribute.y } = text.attribute;
20755
+ const { text: str, underline = textAttribute.underline, lineThrough = textAttribute.lineThrough, keepDirIn3d = textAttribute.keepDirIn3d, direction = textAttribute.direction, fontSize = textAttribute.fontSize, verticalMode = textAttribute.verticalMode, x: originX = textAttribute.x, y: originY = textAttribute.y } = text.attribute;
21695
20756
  let { textAlign = textAttribute.textAlign, textBaseline = textAttribute.textBaseline } = text.attribute;
21696
20757
  if (!verticalMode && direction === 'vertical') {
21697
20758
  const t = textAlign;
21698
20759
  textAlign = (_a = text.getBaselineMapAlign()[textBaseline]) !== null && _a !== void 0 ? _a : 'left';
21699
20760
  textBaseline = (_b = text.getAlignMapBaseline()[t]) !== null && _b !== void 0 ? _b : 'top';
21700
20761
  }
21701
- const lineHeight = (_c = text.attribute.lineHeight) !== null && _c !== void 0 ? _c : fontSize;
20762
+ const lineHeight = (_c = calculateLineHeight(text.attribute.lineHeight, fontSize)) !== null && _c !== void 0 ? _c : fontSize;
21702
20763
  const data = this.valid(text, textAttribute, fillCb, strokeCb);
21703
20764
  if (!data) {
21704
20765
  return;
@@ -21779,6 +20840,7 @@
21779
20840
  }
21780
20841
  }
21781
20842
  else {
20843
+ text.tryUpdateAABBBounds();
21782
20844
  const cache = text.cache;
21783
20845
  const { verticalList } = cache;
21784
20846
  context.textAlign = 'left';
@@ -21822,7 +20884,6 @@
21822
20884
  }
21823
20885
  }
21824
20886
  else {
21825
- const cache = text.cache;
21826
20887
  if (direction === 'horizontal') {
21827
20888
  context.setTextStyle(text.attribute, textAttribute, z);
21828
20889
  const t = text.clipedText;
@@ -21839,31 +20900,35 @@
21839
20900
  }
21840
20901
  drawText(t, 0, dy, 0);
21841
20902
  }
21842
- else if (cache) {
21843
- context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
21844
- const { verticalList } = cache;
21845
- let offsetY = 0;
21846
- const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
21847
- let offsetX = 0;
21848
- if (textBaseline === 'bottom') {
21849
- offsetX = -lineHeight;
21850
- }
21851
- else if (textBaseline === 'middle') {
21852
- offsetX = -lineHeight / 2;
21853
- }
21854
- if (textAlign === 'center') {
21855
- offsetY -= totalW / 2;
21856
- }
21857
- else if (textAlign === 'right') {
21858
- offsetY -= totalW;
20903
+ else {
20904
+ text.tryUpdateAABBBounds();
20905
+ const cache = text.cache;
20906
+ if (cache) {
20907
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
20908
+ const { verticalList } = cache;
20909
+ let offsetY = 0;
20910
+ const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
20911
+ let offsetX = 0;
20912
+ if (textBaseline === 'bottom') {
20913
+ offsetX = -lineHeight;
20914
+ }
20915
+ else if (textBaseline === 'middle') {
20916
+ offsetX = -lineHeight / 2;
20917
+ }
20918
+ if (textAlign === 'center') {
20919
+ offsetY -= totalW / 2;
20920
+ }
20921
+ else if (textAlign === 'right') {
20922
+ offsetY -= totalW;
20923
+ }
20924
+ context.textAlign = 'left';
20925
+ context.textBaseline = 'top';
20926
+ verticalList[0].forEach(item => {
20927
+ const { text, width, direction } = item;
20928
+ drawText(text, offsetX, offsetY, direction);
20929
+ offsetY += width;
20930
+ });
21859
20931
  }
21860
- context.textAlign = 'left';
21861
- context.textBaseline = 'top';
21862
- verticalList[0].forEach(item => {
21863
- const { text, width, direction } = item;
21864
- drawText(text, offsetX, offsetY, direction);
21865
- offsetY += width;
21866
- });
21867
20932
  }
21868
20933
  }
21869
20934
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context);
@@ -23249,6 +22314,7 @@
23249
22314
  this.backupDirtyBounds = new vutils.Bounds();
23250
22315
  this.global = application.global;
23251
22316
  this.layerService = application.layerService;
22317
+ this.init();
23252
22318
  }
23253
22319
  init() {
23254
22320
  this.contributions.forEach(item => {
@@ -23265,7 +22331,17 @@
23265
22331
  .getContributions()
23266
22332
  .sort((a, b) => a.order - b.order);
23267
22333
  }
22334
+ prepareForDraw(renderService, drawContext) {
22335
+ const count = renderService.renderTreeRoots.reduce((a, b) => a + b.count, 0);
22336
+ if (count < this.global.optmizeSkipCheckBoundariesThreshold) {
22337
+ this.useDirtyBounds = false;
22338
+ }
22339
+ else {
22340
+ this.useDirtyBounds = true;
22341
+ }
22342
+ }
23268
22343
  draw(renderService, drawContext) {
22344
+ this.prepareForDraw(renderService, drawContext);
23269
22345
  drawContext.drawContribution = this;
23270
22346
  this.currentRenderMap = this.styleRenderMap.get(drawContext.renderStyle) || this.defaultRenderMap;
23271
22347
  this.currentRenderService = renderService;
@@ -23338,13 +22414,17 @@
23338
22414
  this._increaseRender(group, drawContext);
23339
22415
  return;
23340
22416
  }
23341
- if (!vutils.isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {
22417
+ if (this.useDirtyBounds && !vutils.isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {
23342
22418
  return;
23343
22419
  }
23344
- const tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);
23345
- const gm = group.transMatrix;
23346
- const nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);
23347
- this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());
22420
+ let nextM;
22421
+ let tempBounds;
22422
+ if (this.useDirtyBounds) {
22423
+ tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);
22424
+ const gm = group.transMatrix;
22425
+ nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);
22426
+ this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());
22427
+ }
23348
22428
  this.renderItem(group, drawContext, {
23349
22429
  drawingCb: () => {
23350
22430
  var _a;
@@ -23373,9 +22453,11 @@
23373
22453
  }, false, !!((_a = drawContext.context) === null || _a === void 0 ? void 0 : _a.camera));
23374
22454
  }
23375
22455
  });
23376
- this.dirtyBounds.copy(tempBounds);
23377
- boundsAllocate.free(tempBounds);
23378
- matrixAllocate.free(nextM);
22456
+ if (this.useDirtyBounds) {
22457
+ this.dirtyBounds.copy(tempBounds);
22458
+ boundsAllocate.free(tempBounds);
22459
+ matrixAllocate.free(nextM);
22460
+ }
23379
22461
  }
23380
22462
  _increaseRender(group, drawContext) {
23381
22463
  const { layer, stage } = drawContext;
@@ -23451,7 +22533,7 @@
23451
22533
  this.dirtyBounds.translate(-scrollX, -scrollY);
23452
22534
  }
23453
22535
  }
23454
- if (!(graphic.isContainer || vutils.isRectIntersect(graphic.AABBBounds, this.dirtyBounds, false))) {
22536
+ if (this.useDirtyBounds && !(graphic.isContainer || vutils.isRectIntersect(graphic.AABBBounds, this.dirtyBounds, false))) {
23455
22537
  retrans && this.dirtyBounds.copy(tempBounds);
23456
22538
  return;
23457
22539
  }
@@ -23513,12 +22595,6 @@
23513
22595
  return;
23514
22596
  }
23515
22597
  };
23516
- __decorate([
23517
- postConstruct(),
23518
- __metadata("design:type", Function),
23519
- __metadata("design:paramtypes", []),
23520
- __metadata("design:returntype", void 0)
23521
- ], DefaultDrawContribution.prototype, "init", null);
23522
22598
  DefaultDrawContribution = __decorate([
23523
22599
  injectable(),
23524
22600
  __param(0, multiInject(GraphicRender)),
@@ -25677,6 +24753,10 @@
25677
24753
  get defaultLayer() {
25678
24754
  return this.at(0);
25679
24755
  }
24756
+ get eventSystem() {
24757
+ this.tryInitEventSystem();
24758
+ return this._eventSystem;
24759
+ }
25680
24760
  constructor(params) {
25681
24761
  var _a;
25682
24762
  super({});
@@ -25721,13 +24801,35 @@
25721
24801
  this.renderCount = 0;
25722
24802
  this._subView = !(this._viewBox.width() === this.width && this._viewBox.height() === this.height);
25723
24803
  this._background = (_a = params.background) !== null && _a !== void 0 ? _a : DefaultConfig$1.BACKGROUND;
25724
- this.appendChild(this.layerService.createLayer(this, params.canvas && vutils.isString(params.canvas) ? { main: true, canvasId: params.canvas } : { main: true }));
24804
+ this.appendChild(this.layerService.createLayer(this, { main: true }));
25725
24805
  this.nextFrameRenderLayerSet = new Set();
25726
24806
  this.willNextFrameRender = false;
25727
24807
  this.stage = this;
25728
24808
  this.renderStyle = params.renderStyle;
25729
- if (this.global.supportEvent) {
25730
- this.eventSystem = new EventSystem({
24809
+ if (params.autoRender) {
24810
+ this.enableAutoRender();
24811
+ }
24812
+ if (params.disableDirtyBounds === false) {
24813
+ this.enableDirtyBounds();
24814
+ }
24815
+ if (params.enableHtmlAttribute) {
24816
+ this.enableHtmlAttribute(params.enableHtmlAttribute);
24817
+ }
24818
+ params.enableLayout && this.enableLayout();
24819
+ this.hooks.beforeRender.tap('constructor', this.beforeRender);
24820
+ this.hooks.afterRender.tap('constructor', this.afterRender);
24821
+ this._beforeRender = params.beforeRender;
24822
+ this._afterRender = params.afterRender;
24823
+ this.ticker = params.ticker || defaultTicker;
24824
+ this.supportInteractiveLayer = params.interactiveLayer !== false;
24825
+ this.timeline = new DefaultTimeline();
24826
+ this.ticker.addTimeline(this.timeline);
24827
+ this.timeline.pause();
24828
+ this.optmize(params.optimize);
24829
+ }
24830
+ tryInitEventSystem() {
24831
+ if (this.global.supportEvent && !this._eventSystem) {
24832
+ this._eventSystem = new EventSystem({
25731
24833
  targetElement: this.window,
25732
24834
  resolution: this.window.dpr || this.global.devicePixelRatio,
25733
24835
  rootNode: this,
@@ -25749,39 +24851,32 @@
25749
24851
  }
25750
24852
  });
25751
24853
  }
25752
- if (params.autoRender) {
25753
- this.enableAutoRender();
25754
- }
25755
- if (params.disableDirtyBounds === false) {
25756
- this.enableDirtyBounds();
25757
- }
25758
- if (params.enableHtmlAttribute) {
25759
- this.enableHtmlAttribute(params.enableHtmlAttribute);
24854
+ }
24855
+ preventRender(prevent) {
24856
+ if (prevent) {
24857
+ this._skipRender = -Infinity;
25760
24858
  }
25761
- params.enableLayout && this.enableLayout();
25762
- this.hooks.beforeRender.tap('constructor', this.beforeRender);
25763
- this.hooks.afterRender.tap('constructor', this.afterRender);
25764
- this._beforeRender = params.beforeRender;
25765
- this._afterRender = params.afterRender;
25766
- this.ticker = params.ticker || defaultTicker;
25767
- this.supportInteractiveLayer = params.interactiveLayer !== false;
25768
- this.timeline = new DefaultTimeline();
25769
- this.ticker.addTimeline(this.timeline);
25770
- this.timeline.pause();
25771
- this.optmize(params.optimize);
25772
- if (this._background && vutils.isString(this._background)) {
25773
- this.setAttributes({ background: this._background });
24859
+ else {
24860
+ if (this.params && this.params.optimize && this.params.optimize.skipRenderWithOutRange !== false) {
24861
+ this._skipRender = this.window.isVisible() ? 0 : 1;
24862
+ }
24863
+ else {
24864
+ this._skipRender = 0;
24865
+ }
25774
24866
  }
25775
24867
  }
25776
24868
  optmize(params) {
25777
24869
  this.optmizeRender(params === null || params === void 0 ? void 0 : params.skipRenderWithOutRange);
25778
24870
  }
25779
- optmizeRender(skipRenderWithOutRange = true) {
24871
+ optmizeRender(skipRenderWithOutRange = false) {
25780
24872
  if (!skipRenderWithOutRange) {
25781
24873
  return;
25782
24874
  }
25783
- this._skipRender = this.window.isVisible() ? 0 : 1;
24875
+ this._skipRender = this._skipRender < 0 ? this._skipRender : this.window.isVisible() ? 0 : 1;
25784
24876
  this.window.onVisibleChange(visible => {
24877
+ if (this._skipRender < 0) {
24878
+ return;
24879
+ }
25785
24880
  if (visible) {
25786
24881
  if (this.dirtyBounds) {
25787
24882
  this.dirtyBounds.setValue(0, 0, this._viewBox.width(), this._viewBox.height());
@@ -26073,13 +25168,13 @@
26073
25168
  layer.render({
26074
25169
  renderService: this.renderService,
26075
25170
  background: layer === this.defaultLayer ? this.background : undefined,
26076
- updateBounds: !!this.dirtyBounds
25171
+ updateBounds: !!(this.dirtyBounds && !this.dirtyBounds.empty())
26077
25172
  }, Object.assign({ renderStyle: this.renderStyle }, params));
26078
25173
  });
26079
25174
  if (this.interactiveLayer && !layerList.includes(this.interactiveLayer)) {
26080
25175
  this.interactiveLayer.render({
26081
25176
  renderService: this.renderService,
26082
- updateBounds: !!this.dirtyBounds
25177
+ updateBounds: !!(this.dirtyBounds && !this.dirtyBounds.empty())
26083
25178
  }, Object.assign({ renderStyle: this.renderStyle }, params));
26084
25179
  }
26085
25180
  }
@@ -26183,7 +25278,7 @@
26183
25278
  }
26184
25279
  renderTo(window, params) {
26185
25280
  this.forEachChildren((layer, i) => {
26186
- layer.drawTo(window, Object.assign(Object.assign({}, params), { renderService: this.renderService, background: layer === this.defaultLayer ? this.background : undefined, clear: i === 0, updateBounds: !!this.dirtyBounds }));
25281
+ layer.drawTo(window, Object.assign(Object.assign({}, params), { renderService: this.renderService, background: layer === this.defaultLayer ? this.background : undefined, clear: i === 0, updateBounds: !!(this.dirtyBounds && !this.dirtyBounds.empty()) }));
26187
25282
  });
26188
25283
  }
26189
25284
  renderToNewWindow(fullImage = true, viewBox) {
@@ -27471,9 +26566,11 @@
27471
26566
  exports.bindContributionProvider = bindContributionProvider;
27472
26567
  exports.bindContributionProviderNoSingletonScope = bindContributionProviderNoSingletonScope;
27473
26568
  exports.boundStroke = boundStroke;
26569
+ exports.builtInSymbolStrMap = builtInSymbolStrMap;
27474
26570
  exports.builtinSymbols = builtinSymbols;
27475
26571
  exports.builtinSymbolsMap = builtinSymbolsMap;
27476
26572
  exports.calcLineCache = calcLineCache$1;
26573
+ exports.calculateLineHeight = calculateLineHeight;
27477
26574
  exports.canvasAllocate = canvasAllocate;
27478
26575
  exports.centroidOfSubpath = centroidOfSubpath;
27479
26576
  exports.circleBounds = circleBounds;
@@ -27617,7 +26714,6 @@
27617
26714
  exports.pointInterpolationHighPerformance = pointInterpolationHighPerformance;
27618
26715
  exports.pointsEqual = pointsEqual;
27619
26716
  exports.pointsInterpolation = pointsInterpolation;
27620
- exports.postConstruct = postConstruct;
27621
26717
  exports.rafBasedSto = rafBasedSto;
27622
26718
  exports.rectFillVisible = rectFillVisible;
27623
26719
  exports.rectStrokeVisible = rectStrokeVisible;