@lfgf/cube-helper-web 0.1.0
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/index.cjs +57 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
connectGanCubeMoves: () => connectGanCubeMoves
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_gan_web_bluetooth = require("gan-web-bluetooth");
|
|
27
|
+
async function connectGanCubeMoves() {
|
|
28
|
+
const cube = await (0, import_gan_web_bluetooth.connectGanCube)();
|
|
29
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
30
|
+
const sub = cube.events$.subscribe((ev) => {
|
|
31
|
+
if (ev?.type !== "MOVE") return;
|
|
32
|
+
const move = String(ev.move || "");
|
|
33
|
+
if (!move) return;
|
|
34
|
+
handlers.forEach((h) => h({ move, ts: Date.now(), raw: ev }));
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
onMove(cb) {
|
|
38
|
+
handlers.add(cb);
|
|
39
|
+
return () => handlers.delete(cb);
|
|
40
|
+
},
|
|
41
|
+
async disconnect() {
|
|
42
|
+
try {
|
|
43
|
+
sub?.unsubscribe?.();
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await cube?.disconnect?.();
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
connectGanCubeMoves
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { connectGanCube } from \"gan-web-bluetooth\";\r\n\r\nexport type CubeMove = { move: string; ts: number; raw?: unknown };\r\n\r\nexport type CubeConnection = {\r\n disconnect(): Promise<void>;\r\n onMove(cb: (m: CubeMove) => void): () => void;\r\n};\r\n\r\nexport async function connectGanCubeMoves(): Promise<CubeConnection> {\r\n const cube: any = await connectGanCube();\r\n\r\n const handlers = new Set<(m: CubeMove) => void>();\r\n\r\n const sub = cube.events$.subscribe((ev: any) => {\r\n if (ev?.type !== \"MOVE\") return;\r\n const move = String(ev.move || \"\");\r\n if (!move) return;\r\n handlers.forEach((h) => h({ move, ts: Date.now(), raw: ev }));\r\n });\r\n\r\n return {\r\n onMove(cb) {\r\n handlers.add(cb);\r\n return () => handlers.delete(cb);\r\n },\r\n async disconnect() {\r\n try { sub?.unsubscribe?.(); } catch { }\r\n try { await cube?.disconnect?.(); } catch { }\r\n },\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAA+B;AAS/B,eAAsB,sBAA+C;AACjE,QAAM,OAAY,UAAM,yCAAe;AAEvC,QAAM,WAAW,oBAAI,IAA2B;AAEhD,QAAM,MAAM,KAAK,QAAQ,UAAU,CAAC,OAAY;AAC5C,QAAI,IAAI,SAAS,OAAQ;AACzB,UAAM,OAAO,OAAO,GAAG,QAAQ,EAAE;AACjC,QAAI,CAAC,KAAM;AACX,aAAS,QAAQ,CAAC,MAAM,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;AAAA,EAChE,CAAC;AAED,SAAO;AAAA,IACH,OAAO,IAAI;AACP,eAAS,IAAI,EAAE;AACf,aAAO,MAAM,SAAS,OAAO,EAAE;AAAA,IACnC;AAAA,IACA,MAAM,aAAa;AACf,UAAI;AAAE,aAAK,cAAc;AAAA,MAAG,QAAQ;AAAA,MAAE;AACtC,UAAI;AAAE,cAAM,MAAM,aAAa;AAAA,MAAG,QAAQ;AAAA,MAAE;AAAA,IAChD;AAAA,EACJ;AACJ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type CubeMove = {
|
|
2
|
+
move: string;
|
|
3
|
+
ts: number;
|
|
4
|
+
raw?: unknown;
|
|
5
|
+
};
|
|
6
|
+
type CubeConnection = {
|
|
7
|
+
disconnect(): Promise<void>;
|
|
8
|
+
onMove(cb: (m: CubeMove) => void): () => void;
|
|
9
|
+
};
|
|
10
|
+
declare function connectGanCubeMoves(): Promise<CubeConnection>;
|
|
11
|
+
|
|
12
|
+
export { type CubeConnection, type CubeMove, connectGanCubeMoves };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type CubeMove = {
|
|
2
|
+
move: string;
|
|
3
|
+
ts: number;
|
|
4
|
+
raw?: unknown;
|
|
5
|
+
};
|
|
6
|
+
type CubeConnection = {
|
|
7
|
+
disconnect(): Promise<void>;
|
|
8
|
+
onMove(cb: (m: CubeMove) => void): () => void;
|
|
9
|
+
};
|
|
10
|
+
declare function connectGanCubeMoves(): Promise<CubeConnection>;
|
|
11
|
+
|
|
12
|
+
export { type CubeConnection, type CubeMove, connectGanCubeMoves };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { connectGanCube } from "gan-web-bluetooth";
|
|
3
|
+
async function connectGanCubeMoves() {
|
|
4
|
+
const cube = await connectGanCube();
|
|
5
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
6
|
+
const sub = cube.events$.subscribe((ev) => {
|
|
7
|
+
if (ev?.type !== "MOVE") return;
|
|
8
|
+
const move = String(ev.move || "");
|
|
9
|
+
if (!move) return;
|
|
10
|
+
handlers.forEach((h) => h({ move, ts: Date.now(), raw: ev }));
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
onMove(cb) {
|
|
14
|
+
handlers.add(cb);
|
|
15
|
+
return () => handlers.delete(cb);
|
|
16
|
+
},
|
|
17
|
+
async disconnect() {
|
|
18
|
+
try {
|
|
19
|
+
sub?.unsubscribe?.();
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await cube?.disconnect?.();
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
connectGanCubeMoves
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { connectGanCube } from \"gan-web-bluetooth\";\r\n\r\nexport type CubeMove = { move: string; ts: number; raw?: unknown };\r\n\r\nexport type CubeConnection = {\r\n disconnect(): Promise<void>;\r\n onMove(cb: (m: CubeMove) => void): () => void;\r\n};\r\n\r\nexport async function connectGanCubeMoves(): Promise<CubeConnection> {\r\n const cube: any = await connectGanCube();\r\n\r\n const handlers = new Set<(m: CubeMove) => void>();\r\n\r\n const sub = cube.events$.subscribe((ev: any) => {\r\n if (ev?.type !== \"MOVE\") return;\r\n const move = String(ev.move || \"\");\r\n if (!move) return;\r\n handlers.forEach((h) => h({ move, ts: Date.now(), raw: ev }));\r\n });\r\n\r\n return {\r\n onMove(cb) {\r\n handlers.add(cb);\r\n return () => handlers.delete(cb);\r\n },\r\n async disconnect() {\r\n try { sub?.unsubscribe?.(); } catch { }\r\n try { await cube?.disconnect?.(); } catch { }\r\n },\r\n };\r\n}\r\n"],"mappings":";AAAA,SAAS,sBAAsB;AAS/B,eAAsB,sBAA+C;AACjE,QAAM,OAAY,MAAM,eAAe;AAEvC,QAAM,WAAW,oBAAI,IAA2B;AAEhD,QAAM,MAAM,KAAK,QAAQ,UAAU,CAAC,OAAY;AAC5C,QAAI,IAAI,SAAS,OAAQ;AACzB,UAAM,OAAO,OAAO,GAAG,QAAQ,EAAE;AACjC,QAAI,CAAC,KAAM;AACX,aAAS,QAAQ,CAAC,MAAM,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;AAAA,EAChE,CAAC;AAED,SAAO;AAAA,IACH,OAAO,IAAI;AACP,eAAS,IAAI,EAAE;AACf,aAAO,MAAM,SAAS,OAAO,EAAE;AAAA,IACnC;AAAA,IACA,MAAM,aAAa;AACf,UAAI;AAAE,aAAK,cAAc;AAAA,MAAG,QAAQ;AAAA,MAAE;AACtC,UAAI;AAAE,cAAM,MAAM,aAAa;AAAA,MAAG,QAAQ;AAAA,MAAE;AAAA,IAChD;AAAA,EACJ;AACJ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lfgf/cube-helper-web",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Web Bluetooth helper for GAN smart cubes (moves stream)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gan",
|
|
7
|
+
"cube",
|
|
8
|
+
"web-bluetooth",
|
|
9
|
+
"rubik",
|
|
10
|
+
"smart-cube",
|
|
11
|
+
"bluetooth"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "lfgf",
|
|
15
|
+
"homepage": "https://github.com/LuisFernandoFernandes/gan-moves",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/LuisFernandoFernandes/gan-moves.git",
|
|
19
|
+
"directory": "packages/cube-helper-web"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/LuisFernandoFernandes/gan-moves/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rimraf dist",
|
|
46
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --sourcemap --clean",
|
|
47
|
+
"prepublishOnly": "npm run build"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"gan-web-bluetooth": "^3.0.2",
|
|
51
|
+
"rxjs": "^7.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"rimraf": "^6.1.2",
|
|
55
|
+
"tsup": "^8.0.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|