inkless 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +65 -2
- package/bin/inkless.js +10 -0
- package/console-dist/assets/BlueprintTool-CLWuM21a.js +4226 -0
- package/console-dist/assets/index-CIqLZU6s.js +33 -0
- package/console-dist/assets/index-Dv7Gg9qm.css +1 -0
- package/console-dist/favicon.svg +11 -0
- package/console-dist/index.html +18 -0
- package/native/linux/rfcomm.py +84 -0
- package/native/macos/build/InklessBluetooth.app/Contents/Info.plist +26 -0
- package/native/macos/build/InklessBluetooth.app/Contents/MacOS/InklessBluetooth +0 -0
- package/native/macos/build/InklessBluetooth.app/Contents/_CodeSignature/CodeResources +115 -0
- package/package.json +60 -4
- package/skills/inkless/SKILL.md +213 -0
- package/src/core/bits.js +143 -0
- package/src/core/blueprint/demos.js +119 -0
- package/src/core/blueprint/geometry.js +232 -0
- package/src/core/blueprint/index.js +100 -0
- package/src/core/blueprint/layout.js +210 -0
- package/src/core/blueprint/mesh.js +101 -0
- package/src/core/blueprint/methods.js +95 -0
- package/src/core/blueprint/remesh.js +250 -0
- package/src/core/blueprint/slice.js +134 -0
- package/src/core/blueprint/unfold.js +185 -0
- package/src/core/design/codes.js +39 -0
- package/src/core/design/filters.js +109 -0
- package/src/core/design/render.js +317 -0
- package/src/core/design/schema.js +132 -0
- package/src/core/formats/fit.js +46 -0
- package/src/core/formats/index.js +210 -0
- package/src/core/formats/library.js +341 -0
- package/src/core/formats/share.js +65 -0
- package/src/core/index.js +15 -0
- package/src/core/printers/hp6.js +160 -0
- package/src/core/printers/index.js +14 -0
- package/src/core/printers/pm290.js +115 -0
- package/src/core/session.js +56 -0
- package/src/node/artwork.js +33 -0
- package/src/node/cli.js +430 -0
- package/src/node/console/actions.js +30 -0
- package/src/node/console/client.js +68 -0
- package/src/node/console/paths.js +8 -0
- package/src/node/console/server.js +286 -0
- package/src/node/design.js +99 -0
- package/src/node/formats.js +39 -0
- package/src/node/frames.js +93 -0
- package/src/node/index.js +6 -0
- package/src/node/kit.js +12 -0
- package/src/node/skill.js +44 -0
- package/src/node/transports/index.js +21 -0
- package/src/node/transports/linux.js +52 -0
- package/src/node/transports/macos.js +81 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// macOS: IOBluetooth only works from a LaunchServices-launched app with a run
|
|
3
|
+
// loop, so a tiny background app holds the RFCOMM channel and pipes bytes to
|
|
4
|
+
// us over a private Unix socket. It exits when the socket closes.
|
|
5
|
+
import { createServer } from "node:net";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { framedTransport } from "../frames.js";
|
|
12
|
+
|
|
13
|
+
const CONNECT_TIMEOUT_MS = 60000; // the first run waits on the Bluetooth permission prompt
|
|
14
|
+
const OPEN_TIMEOUT_MS = 20000;
|
|
15
|
+
|
|
16
|
+
export function helperApp() {
|
|
17
|
+
const app = process.env.INKLESS_MACOS_HELPER ??
|
|
18
|
+
fileURLToPath(new URL("../../../native/macos/build/InklessBluetooth.app", import.meta.url));
|
|
19
|
+
if (!existsSync(app)) throw new Error(`Bluetooth helper is missing at ${app}; run npm run build:macos`);
|
|
20
|
+
return app;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Launch through LaunchServices; tests replace this with a plain process. */
|
|
24
|
+
function launchApp(args) {
|
|
25
|
+
const child = spawn("/usr/bin/open", ["-W", "-n", "-g", helperApp(), "--args", ...args], { stdio: "ignore" });
|
|
26
|
+
return child;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const withTimeout = (promise, ms, message) =>
|
|
30
|
+
Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new Error(message)), ms).unref())]);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ printer?: any, address?: string, name?: string, list?: boolean, launch?: (args: string[]) => import("node:child_process").ChildProcess }} options
|
|
34
|
+
*/
|
|
35
|
+
export async function openMacTransport({ printer, address, name, list = false, launch = launchApp }) {
|
|
36
|
+
// Unix socket paths are limited to ~104 bytes; /tmp keeps it short.
|
|
37
|
+
const dir = await mkdtemp("/tmp/inkless-");
|
|
38
|
+
const socketPath = join(dir, "bt.sock");
|
|
39
|
+
const server = createServer();
|
|
40
|
+
await new Promise((resolve, reject) => server.once("error", reject).listen(socketPath, () => resolve(undefined)));
|
|
41
|
+
const args = ["--socket", socketPath, "--parent", String(process.pid)];
|
|
42
|
+
if (list) args.push("--list");
|
|
43
|
+
else {
|
|
44
|
+
args.push(...(address ? ["--address", address] : ["--name", name ?? printer.bluetoothName]));
|
|
45
|
+
if (printer.connect.requirePaired) args.push("--require-paired");
|
|
46
|
+
if (printer.connect.openBasebandFirst) args.push("--open-baseband");
|
|
47
|
+
}
|
|
48
|
+
const child = launch(args);
|
|
49
|
+
const cleanup = async () => {
|
|
50
|
+
server.close();
|
|
51
|
+
await rm(dir, { recursive: true, force: true });
|
|
52
|
+
};
|
|
53
|
+
let socket;
|
|
54
|
+
try {
|
|
55
|
+
socket = await withTimeout(
|
|
56
|
+
new Promise((resolve) => server.once("connection", resolve)),
|
|
57
|
+
CONNECT_TIMEOUT_MS,
|
|
58
|
+
"the Bluetooth helper did not start; allow its Bluetooth permission and try again",
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
child.kill();
|
|
62
|
+
await cleanup();
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
const transport = framedTransport(socket, { label: "Bluetooth helper" });
|
|
66
|
+
const exited = new Promise((resolve) => child.once("exit", resolve));
|
|
67
|
+
const close = async () => {
|
|
68
|
+
transport.quit();
|
|
69
|
+
socket.end();
|
|
70
|
+
await withTimeout(exited, 5000, "helper exit").catch(() => child.kill());
|
|
71
|
+
await cleanup();
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const info = await withTimeout(transport.ready, OPEN_TIMEOUT_MS, "the printer's Bluetooth channel did not open");
|
|
75
|
+
if (info.mtu) transport.mtu = info.mtu;
|
|
76
|
+
return { ...transport, info, close, mtu: transport.mtu };
|
|
77
|
+
} catch (error) {
|
|
78
|
+
await close();
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|