pose-gesture-sdk 1.2.0 → 1.2.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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "pose-gesture-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "基于 MediaPipe Tasks(PoseLandmarker)的手语/手势采集状态机 SDK,纯本地运行、零外网依赖。举手保持 startSeconds 秒返回 start,手放下/手消失保持 endSeconds 秒返回 end。",
5
5
  "main": "pose-gesture-sdk.js",
6
6
  "module": "pose-gesture-sdk.js",
7
7
  "exports": {
8
8
  ".": "./pose-gesture-sdk.js",
9
9
  "./assets/*": "./assets/*",
10
- "./copy-assets": "./scripts/copy-assets.mjs"
10
+ "./copy-assets": "./scripts/copy-assets.cjs"
11
11
  },
12
12
  "files": [
13
13
  "pose-gesture-sdk.js",
@@ -15,7 +15,7 @@
15
15
  "scripts/"
16
16
  ],
17
17
  "scripts": {
18
- "copy-assets": "node scripts/copy-assets.mjs"
18
+ "copy-assets": "node scripts/copy-assets.cjs"
19
19
  },
20
20
  "keywords": [
21
21
  "mediapipe",
@@ -1,43 +1,61 @@
1
- #!/usr/bin/env node
2
- /**
3
- * copy-assets.mjs
4
- * 将 pose-gesture-sdk 包内内置的推理资源(assets/:wasm + vision_bundle.js + pose_landmarker.task)
5
- * 拷贝到业务项目的公开目录,供浏览器通过 HTTP 加载(node_modules 内文件无法被浏览器直接访问)。
6
- *
7
- * 用法:
8
- * node node_modules/pose-gesture-sdk/scripts/copy-assets.mjs --out=public/pose-gesture-sdk
9
- * npm run copy-assets --prefix node_modules/pose-gesture-sdk -- --out=public/pose-gesture-sdk
10
- *
11
- * 默认输出目录:./public/pose-gesture-sdk
12
- * 拷贝完成后,构建工具打包场景需在 SDK init 配置中显式传入三个资源路径(modelUrl / wasmUrl / mediapipeJsUrl)
13
- * 指向该公开目录(如 '/public/pose-gesture-sdk/pose_landmarker.task' 等)。
14
- *(浏览器 <script> 引入场景无需本脚本与路径配置:SDK 自动定位包内 assets/ 资源。)
15
- */
16
- import { cpSync, mkdirSync, existsSync } from 'node:fs';
17
- import { dirname, join, resolve } from 'node:path';
18
- import { fileURLToPath } from 'node:url';
19
-
20
- // 包根目录(本文件位于 <pkg>/scripts/ 下)
21
- const PKG_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..');
22
- const ASSETS_DIR = join(PKG_DIR, 'assets');
23
-
24
- // 解析 --out=xxx 参数,默认 ./public/pose-gesture-sdk
25
- const outArg = process.argv.find((a) => a.startsWith('--out='));
26
- const OUT_DIR = resolve(outArg ? outArg.slice('--out='.length) : 'public/pose-gesture-sdk');
27
-
28
- if (!existsSync(ASSETS_DIR)) {
29
- console.error('[pose-gesture-sdk] 未找到包内置资源目录:', ASSETS_DIR);
30
- process.exit(1);
31
- }
32
-
33
- mkdirSync(OUT_DIR, { recursive: true });
34
- cpSync(ASSETS_DIR, OUT_DIR, { recursive: true });
35
-
36
- console.log('[pose-gesture-sdk] 推理资源已拷贝到:', OUT_DIR);
37
- // 公开访问路径提示(保证以 / 开头,直接可拷贝到 SDK init 配置中)
38
- var PUB = '/' + (outArg ? outArg.slice(6) : 'public/pose-gesture-sdk').replace(/^\/+|\/+$/g, '');
39
- console.log('[pose-gesture-sdk] 构建工具打包场景请在 SDK init 配置中显式传入资源路径:');
40
- console.log(' modelUrl: "' + PUB + '/pose_landmarker.task"');
41
- console.log(' wasmUrl: "' + PUB + '/wasm"');
42
- console.log(' mediapipeJsUrl: "' + PUB + '/vision_bundle.js"');
43
- console.log('(浏览器 <script> 引入场景无需以上配置:SDK 自动使用包内 assets/ 资源)');
1
+ #!/usr/bin/env node
2
+ /**
3
+ * copy-assets.cjs
4
+ * 将 pose-gesture-sdk 包内内置的推理资源(assets/:wasm + vision_bundle.js + pose_landmarker.task)
5
+ * 拷贝到业务项目的公开目录,供浏览器通过 HTTP 加载(node_modules 内文件无法被浏览器直接访问)。
6
+ *
7
+ * 用法(需在业务项目根目录,即含 node_modules/ 的目录下执行):
8
+ * node node_modules/pose-gesture-sdk/scripts/copy-assets.cjs --out=public/pose-gesture-sdk
9
+ * npm run copy-assets # 业务项目 package.json 中已配置的便捷命令
10
+ *
11
+ * 默认输出目录:./public/pose-gesture-sdk
12
+ * 拷贝完成后,构建工具打包场景需在 SDK init 配置中显式传入三个资源路径(modelUrl / wasmUrl / mediapipeJsUrl)
13
+ * 指向该公开目录(如 '/public/pose-gesture-sdk/pose_landmarker.task' 等)。
14
+ *(浏览器 <script> 引入场景无需本脚本与路径配置:SDK 自动定位包内 assets/ 资源。)
15
+ *
16
+ * 说明:本脚本采用 CommonJS(而非 .mjs)实现。当前环境(Node 22 + Windows)下,
17
+ * 以 ESM 方式执行并对含大二进制(.wasm)目录做拷贝会触发原生层段错误(SIGSEGV / 0xC0000005),
18
+ * 改用 CJS 可稳定完成拷贝。
19
+ */
20
+ const { existsSync, mkdirSync, readdirSync, copyFileSync, statSync } = require('node:fs');
21
+ const { join, resolve } = require('node:path');
22
+
23
+ // 包根目录:本文件位于 <pkg>/scripts/ 下
24
+ const PKG_DIR = resolve(__dirname, '..');
25
+ const ASSETS_DIR = join(PKG_DIR, 'assets');
26
+
27
+ // 解析 --out=xxx 参数,默认 ./public/pose-gesture-sdk
28
+ const outArg = process.argv.find((a) => a.startsWith('--out='));
29
+ const OUT_DIR = resolve(outArg ? outArg.slice('--out='.length) : 'public/pose-gesture-sdk');
30
+
31
+ if (!existsSync(ASSETS_DIR)) {
32
+ console.error('[pose-gesture-sdk] 未找到包内置资源目录:', ASSETS_DIR);
33
+ process.exit(1);
34
+ }
35
+
36
+ /**
37
+ * 手写递归拷贝,规避部分 Node 版本在 Windows 上对 fs.cpSync({ recursive: true })
38
+ * 拷贝含大二进制文件(.wasm)目录时的段错误(SIGSEGV / 0xC0000005)。
39
+ */
40
+ function copyRecursive(src, dest) {
41
+ const st = statSync(src);
42
+ if (st.isDirectory()) {
43
+ mkdirSync(dest, { recursive: true });
44
+ for (const name of readdirSync(src)) {
45
+ copyRecursive(join(src, name), join(dest, name));
46
+ }
47
+ } else {
48
+ copyFileSync(src, dest);
49
+ }
50
+ }
51
+
52
+ copyRecursive(ASSETS_DIR, OUT_DIR);
53
+
54
+ console.log('[pose-gesture-sdk] 推理资源已拷贝到:', OUT_DIR);
55
+ // 公开访问路径提示(保证以 / 开头,直接可拷贝到 SDK init 配置中)
56
+ var PUB = '/' + (outArg ? outArg.slice(6) : 'public/pose-gesture-sdk').replace(/^\/+|\/+$/g, '');
57
+ console.log('[pose-gesture-sdk] 构建工具打包场景请在 SDK init 配置中显式传入资源路径:');
58
+ console.log(' modelUrl: "' + PUB + '/pose_landmarker.task"');
59
+ console.log(' wasmUrl: "' + PUB + '/wasm"');
60
+ console.log(' mediapipeJsUrl: "' + PUB + '/vision_bundle.js"');
61
+ console.log('(浏览器 <script> 引入场景无需以上配置:SDK 自动使用包内 assets/ 资源)');