@galacean/engine-loader 0.0.0-experimental-2.0-spine.0 → 0.0.0-experimental-2.0-spine.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -643,6 +643,39 @@ function float32ArrayToVector2(float32Array, vertexCount) {
643
643
  return array;
644
644
  }
645
645
 
646
+ function _is_native_reflect_construct() {
647
+ // Since Reflect.construct can't be properly polyfilled, some
648
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
649
+ // Those polyfills don't allow us to subclass built-ins, so we need to
650
+ // use our fallback implementation.
651
+ try {
652
+ // If the internal slots aren't set, this throws an error similar to
653
+ // TypeError: this is not a Boolean object.
654
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
655
+ } catch (_) {}
656
+ return (_is_native_reflect_construct = function() {
657
+ return !!result;
658
+ })();
659
+ }
660
+
661
+ function _construct(Parent, args, Class) {
662
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
663
+ else {
664
+ _construct = function construct(Parent, args, Class) {
665
+ var a = [null];
666
+ a.push.apply(a, args);
667
+ var Constructor = Function.bind.apply(Parent, a);
668
+ var instance = new Constructor();
669
+
670
+ if (Class) _set_prototype_of(instance, Class.prototype);
671
+
672
+ return instance;
673
+ };
674
+ }
675
+
676
+ return _construct.apply(null, arguments);
677
+ }
678
+
646
679
  function _object_without_properties_loose(source, excluded) {
647
680
  if (source == null) return {};
648
681
 
@@ -776,16 +809,17 @@ var ReflectionParser = /*#__PURE__*/ function() {
776
809
  * 1. null/undefined/primitive → passthrough
777
810
  * 2. Array → recurse each element
778
811
  * 3. { $ref } → asset reference
779
- * 4. { $type } → polymorphic type construct
812
+ * 4. { $type } → polymorphic type construct; optional $args are constructor args
780
813
  * 5. { $class } → registered class constructor
781
814
  * 6. { $entity } → entity reference by path (flat index + optional children descent)
782
815
  * 7. { $component } → component reference
783
816
  * 8. { $signal } → signal binding
784
- * 9. plain object → recurse values (modify originValue in place if exists)
817
+ * 9. { $props/$calls } mutate the existing target object
818
+ * 10. plain object → recurse values (modify originValue in place if exists)
785
819
  */ _proto._resolveValue = function _resolveValue(value, originValue) {
786
820
  var _this, _loop = function(key) {
787
- promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
788
- return target[key] = v;
821
+ promises.push(_this._resolveValue(obj[key], target1[key]).then(function(v) {
822
+ return target1[key] = v;
789
823
  }));
790
824
  };
791
825
  var _this1 = this;
@@ -814,12 +848,22 @@ var ReflectionParser = /*#__PURE__*/ function() {
814
848
  }
815
849
  // $type — polymorphic type: construct instance and apply remaining props
816
850
  if ("$type" in obj) {
817
- var $type = obj.$type, rest = _object_without_properties_loose(obj, [
818
- "$type"
851
+ var $type = obj.$type, $args = obj.$args, $props = obj.$props, $calls = obj.$calls, rest = _object_without_properties_loose(obj, [
852
+ "$type",
853
+ "$args",
854
+ "$props",
855
+ "$calls"
819
856
  ]);
820
857
  return this._resolveRegisteredClass($type, "$type").then(function(Class) {
821
- var instance = new Class();
822
- return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
858
+ if ($args !== undefined && !Array.isArray($args)) {
859
+ return Promise.reject(new Error("$type.$args must be an array"));
860
+ }
861
+ return Promise.all(($args != null ? $args : []).map(function(arg) {
862
+ return _this1._resolveValue(arg);
863
+ })).then(function(resolvedArgs) {
864
+ var instance = _construct(Class, [].concat(resolvedArgs));
865
+ return _this1._applyRuntimeMutation(instance, Object.keys(rest).length > 0 ? rest : undefined, $props, $calls);
866
+ });
823
867
  });
824
868
  }
825
869
  // $class — registered class constructor for factory-style methods.
@@ -838,14 +882,50 @@ var ReflectionParser = /*#__PURE__*/ function() {
838
882
  if ("$signal" in obj) {
839
883
  return this._resolveSignal(originValue, obj.$signal);
840
884
  }
885
+ // Runtime mutation block for existing nested objects.
886
+ if ("$props" in obj || "$calls" in obj) {
887
+ var target = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
888
+ return this._applyRuntimeMutation(target, undefined, obj.$props, obj.$calls);
889
+ }
841
890
  // Plain object — recurse each value, modifying originValue in place or building a new object
842
- var target = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
891
+ var target1 = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
843
892
  var promises = [];
844
893
  for(var key in obj)_this = this, _loop(key);
845
894
  return Promise.all(promises).then(function() {
846
- return target;
895
+ return target1;
847
896
  });
848
897
  };
898
+ _proto._applyRuntimeMutation = function _applyRuntimeMutation(target, directProps, runtimeProps, runtimeCalls) {
899
+ var props = directProps ? _extends({}, directProps) : undefined;
900
+ var calls;
901
+ try {
902
+ var normalizedProps = this._normalizeRuntimeProps(runtimeProps);
903
+ if (normalizedProps) {
904
+ props = Object.assign(props != null ? props : {}, normalizedProps);
905
+ }
906
+ calls = this._normalizeRuntimeCalls(runtimeCalls);
907
+ } catch (error) {
908
+ return Promise.reject(error);
909
+ }
910
+ return this.parseMutationBlock(target, {
911
+ props: props,
912
+ calls: calls
913
+ });
914
+ };
915
+ _proto._normalizeRuntimeProps = function _normalizeRuntimeProps(props) {
916
+ if (props === undefined) return undefined;
917
+ if (props == null || (typeof props === "undefined" ? "undefined" : _type_of(props)) !== "object" || Array.isArray(props)) {
918
+ throw new Error("$props must be an object");
919
+ }
920
+ return props;
921
+ };
922
+ _proto._normalizeRuntimeCalls = function _normalizeRuntimeCalls(calls) {
923
+ if (calls === undefined) return undefined;
924
+ if (!Array.isArray(calls)) {
925
+ throw new Error("$calls must be an array");
926
+ }
927
+ return calls;
928
+ };
849
929
  _proto._getRegisteredClass = function _getRegisteredClass(value, sentinel) {
850
930
  if (typeof value !== "string" || value.length === 0) {
851
931
  throw new Error("" + sentinel + " must be a non-empty registered class name string");