yootd 0.2.32 → 0.2.34

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.
@@ -0,0 +1 @@
1
+ export declare const loadScript: (url: string) => Promise<void>;
@@ -0,0 +1,39 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ export var loadScript = /*#__PURE__*/function () {
4
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
5
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6
+ while (1) switch (_context.prev = _context.next) {
7
+ case 0:
8
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
9
+ // 检查是否已经存在
10
+ var scripts = document.head.querySelectorAll('script');
11
+ if (scripts != null && scripts.length > 0) {
12
+ var arr = Array.from(scripts);
13
+ if (arr.findIndex(function (item) {
14
+ return item.src === url;
15
+ }) != -1) {
16
+ resolve();
17
+ return;
18
+ }
19
+ }
20
+ var script = document.createElement('script');
21
+ script.src = url;
22
+ script.onload = function () {
23
+ resolve();
24
+ };
25
+ script.onerror = function (e) {
26
+ reject(e);
27
+ };
28
+ document.head.appendChild(script);
29
+ }));
30
+ case 1:
31
+ case "end":
32
+ return _context.stop();
33
+ }
34
+ }, _callee);
35
+ }));
36
+ return function loadScript(_x) {
37
+ return _ref.apply(this, arguments);
38
+ };
39
+ }();
@@ -4,8 +4,6 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
5
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
- console.log('process.env', process.env.NODE_ENV);
8
- var isDev = process.env.NODE_ENV === 'development';
9
7
  // import * as faceapi from '@vladmandic/face-api';
10
8
  //
11
9
  // import * as posedetection from '@tensorflow-models/pose-detection';
@@ -20,6 +18,7 @@ import { Spin } from "./..";
20
18
  import { useBaseURL } from "../hooks/useBaseURL";
21
19
  import { useOSS } from "../hooks/useOSS";
22
20
  import { useRequest } from "../hooks/useRequest";
21
+ import { loadScript } from "../utils/script";
23
22
  import controlBottomBg from "./assets/control-background.png";
24
23
  var PROGRESS_BAR_HEIGHT = 63;
25
24
  var MIN_SCORE = 0.5; // minimum score
@@ -824,105 +823,76 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
824
823
  case 2:
825
824
  _context3.prev = 2;
826
825
  if (!((aiFeature.anchor || aiFeature.emotion || aiFeature.character || aiFeature.pose) && !tfInitialized)) {
827
- _context3.next = 17;
826
+ _context3.next = 13;
828
827
  break;
829
828
  }
830
- if (!isDev) {
831
- _context3.next = 10;
832
- break;
833
- }
834
- _context3.next = 7;
835
- return import('@tensorflow/tfjs');
836
- case 7:
837
- _context3.t0 = _context3.sent;
838
- _context3.next = 11;
839
- break;
840
- case 10:
841
- _context3.t0 = window.tf;
842
- case 11:
843
- tf = _context3.t0;
844
- _context3.next = 14;
829
+ _context3.next = 6;
830
+ return loadScript("".concat(window.location.origin, "/oss/cdn/@tensorflow/tfjs/dist/tf.min.js"));
831
+ case 6:
832
+ console.log('window.tf', window.tf);
833
+ tf = window.tf; // 初始化
834
+ _context3.next = 10;
845
835
  return tf.setBackend('webgl');
846
- case 14:
847
- _context3.next = 16;
836
+ case 10:
837
+ _context3.next = 12;
848
838
  return tf.ready();
849
- case 16:
839
+ case 12:
850
840
  setTfInitialized(true);
851
- case 17:
852
- _context3.next = 22;
841
+ case 13:
842
+ _context3.next = 18;
853
843
  break;
854
- case 19:
855
- _context3.prev = 19;
856
- _context3.t1 = _context3["catch"](2);
857
- console.error('tensorflow 加载失败: ', _context3.t1);
858
- case 22:
859
- _context3.prev = 22;
844
+ case 15:
845
+ _context3.prev = 15;
846
+ _context3.t0 = _context3["catch"](2);
847
+ console.error('tensorflow 加载失败: ', _context3.t0);
848
+ case 18:
849
+ _context3.prev = 18;
860
850
  if (!((aiFeature.anchor || aiFeature.emotion || aiFeature.character) && !faceApiInitialized)) {
861
- _context3.next = 45;
862
- break;
863
- }
864
- if (!isDev) {
865
- _context3.next = 30;
851
+ _context3.next = 36;
866
852
  break;
867
853
  }
868
- _context3.next = 27;
869
- return import('@vladmandic/face-api');
870
- case 27:
871
- _context3.t2 = _context3.sent;
872
- _context3.next = 31;
873
- break;
874
- case 30:
875
- _context3.t2 = window.faceapi;
876
- case 31:
877
- faceapi = _context3.t2;
878
- _context3.next = 34;
854
+ _context3.next = 22;
855
+ return loadScript("".concat(window.location.origin, "/oss/cdn/@vladmandic/face-api@1.7.15/dist/face-api.js"));
856
+ case 22:
857
+ faceapi = window.faceapi;
858
+ _context3.next = 25;
879
859
  return faceapi.nets.ssdMobilenetv1.load("".concat(OSS, "/model-zoo/face-api-models/model"));
880
- case 34:
881
- _context3.next = 36;
860
+ case 25:
861
+ _context3.next = 27;
882
862
  return faceapi.nets.ageGenderNet.load("".concat(OSS, "/face-api-models/model"));
883
- case 36:
884
- _context3.next = 38;
863
+ case 27:
864
+ _context3.next = 29;
885
865
  return faceapi.nets.faceLandmark68Net.load("".concat(OSS, "/model-zoo/face-api-models/model"));
886
- case 38:
887
- _context3.next = 40;
866
+ case 29:
867
+ _context3.next = 31;
888
868
  return faceapi.nets.faceRecognitionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
889
- case 40:
890
- _context3.next = 42;
869
+ case 31:
870
+ _context3.next = 33;
891
871
  return faceapi.nets.faceExpressionNet.load("".concat(OSS, "/model-zoo/face-api-models/model"));
892
- case 42:
872
+ case 33:
893
873
  setOptions(new faceapi.SsdMobilenetv1Options({
894
874
  minConfidence: MIN_SCORE,
895
875
  maxResults: MAX_RESULTS
896
876
  }));
897
877
  detectAllFacesRef.current = faceapi.detectAllFaces;
898
878
  setFaceApiInitialized(true);
899
- case 45:
900
- _context3.next = 50;
879
+ case 36:
880
+ _context3.next = 41;
901
881
  break;
902
- case 47:
903
- _context3.prev = 47;
904
- _context3.t3 = _context3["catch"](22);
905
- console.error('faceapi 加载失败: ', _context3.t3);
906
- case 50:
907
- _context3.prev = 50;
882
+ case 38:
883
+ _context3.prev = 38;
884
+ _context3.t1 = _context3["catch"](18);
885
+ console.error('faceapi 加载失败: ', _context3.t1);
886
+ case 41:
887
+ _context3.prev = 41;
908
888
  if (!(aiFeature.pose && poseDetector == null)) {
909
- _context3.next = 66;
889
+ _context3.next = 52;
910
890
  break;
911
891
  }
912
- if (!isDev) {
913
- _context3.next = 58;
914
- break;
915
- }
916
- _context3.next = 55;
917
- return import('@tensorflow-models/pose-detection');
918
- case 55:
919
- _context3.t4 = _context3.sent;
920
- _context3.next = 59;
921
- break;
922
- case 58:
923
- _context3.t4 = window.poseDetection;
924
- case 59:
925
- poseDetection = _context3.t4;
892
+ _context3.next = 45;
893
+ return loadScript("".concat(window.location.origin, "/oss/cdn/@tensorflow-models/pose-detection@2.1.3/dist/pose-detection.min.js"));
894
+ case 45:
895
+ poseDetection = window.poseDetection;
926
896
  detectorConfig = {
927
897
  modelType: poseDetection.movenet.modelType.MULTIPOSE_LIGHTNING,
928
898
  enableTracking: true,
@@ -930,24 +900,24 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
930
900
  scoreThreshold: 0.3,
931
901
  modelUrl: "".concat(OSS, "/model-zoo/pose-detection-models/model.json")
932
902
  };
933
- _context3.next = 63;
903
+ _context3.next = 49;
934
904
  return poseDetection.createDetector(poseDetection.SupportedModels.MoveNet, detectorConfig);
935
- case 63:
905
+ case 49:
936
906
  _poseDetector = _context3.sent;
937
907
  getAdjacentPairsRef.current = poseDetection.util.getAdjacentPairs;
938
908
  setPoseDetector(_poseDetector);
939
- case 66:
940
- _context3.next = 71;
909
+ case 52:
910
+ _context3.next = 57;
941
911
  break;
942
- case 68:
943
- _context3.prev = 68;
944
- _context3.t5 = _context3["catch"](50);
945
- console.error('pose detection 加载失败: ', _context3.t5);
946
- case 71:
912
+ case 54:
913
+ _context3.prev = 54;
914
+ _context3.t2 = _context3["catch"](41);
915
+ console.error('pose detection 加载失败: ', _context3.t2);
916
+ case 57:
947
917
  case "end":
948
918
  return _context3.stop();
949
919
  }
950
- }, _callee3, null, [[2, 19], [22, 47], [50, 68]]);
920
+ }, _callee3, null, [[2, 15], [18, 38], [41, 54]]);
951
921
  }))();
952
922
  return function () {
953
923
  loaded = false;
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "yootd",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "description": "基于 Antd 二次开发的组件库",
5
5
  "license": "MIT",
6
+ "sideEffects": [
7
+ "*.scss"
8
+ ],
6
9
  "module": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "files": [
@@ -51,10 +54,13 @@
51
54
  "devDependencies": {
52
55
  "@commitlint/cli": "^17.1.2",
53
56
  "@commitlint/config-conventional": "^17.1.0",
57
+ "@tensorflow-models/pose-detection": ">=2.1.3",
58
+ "@tensorflow/tfjs": ">=4.22.0",
54
59
  "@types/lodash": "^4.17.12",
55
60
  "@types/react": "^18.0.0",
56
61
  "@types/react-dom": "^18.0.0",
57
62
  "@umijs/lint": "^4.0.0",
63
+ "@vladmandic/face-api": ">=1.7.14",
58
64
  "cross-env": "^10.0.0",
59
65
  "dumi": "^2.3.0",
60
66
  "dumi-theme-antd": "^0.4.2",
@@ -74,9 +80,6 @@
74
80
  "@dnd-kit/sortable": ">=8.0.0",
75
81
  "@dnd-kit/utilities": ">=3.2.2",
76
82
  "@tanstack/react-query": ">=5.59.15",
77
- "@tensorflow-models/pose-detection": ">=2.1.3",
78
- "@tensorflow/tfjs": ">=4.22.0",
79
- "@vladmandic/face-api": ">=1.7.14",
80
83
  "@xyflow/react": ">=12.3.3",
81
84
  "antd": ">=5.21.4",
82
85
  "axios": ">=1.7.7",