@rin-ts/sticker 0.0.0-stage → 0.2.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/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # @rin-ts/sticker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@rin-ts/sticker` converts media into WhatsApp-compatible WebP stickers for
4
+ Rin. It keeps codec and pixel work in a persistent native C++ worker, while
5
+ the Bun/TypeScript API manages requests and returns the finished WebP bytes.
6
+
7
+ The design is intended for fast, predictable server-side processing: requests
8
+ are serialized per worker, source and output sizes are bounded, and a worker
9
+ that times out or returns an invalid response is replaced before later work is
10
+ accepted.
11
+
12
+ ## Supported media
13
+
14
+ - PNG, JPEG, static WebP, animated WebP, and videos decoded by FFmpeg
15
+ (including MP4, MOV, WebM, MKV, and AVI)
16
+ - Transparency, alpha trimming, proportional 512 × 512 sizing, and optional
17
+ alpha-aware outlines
18
+ - Static and animated WhatsApp-compatible WebP output
19
+
20
+ GIF, APNG, and Lottie/Telegram `.tgs` remain rejected. Videos are decoded
21
+ directly from the supplied bytes; audio streams are ignored.
22
+
23
+ ## Install
24
+
25
+ Published packages include a prebuilt worker for Linux x64 and Linux ARM64.
26
+ They are available from the public npm registry, so no registry configuration
27
+ or authentication is needed.
28
+
29
+ ```bash
30
+ bun add @rin-ts/sticker
31
+ ```
32
+
33
+ The optional platform worker is selected automatically. Set `workerPath` only
34
+ when you supply a custom worker binary.
35
+
36
+ ## Publishing
37
+
38
+ Maintain a matching `v<version>` Git tag and package versions, then a
39
+ maintainer runs the **Publish packages** workflow from GitHub Actions with that
40
+ tag and the intended npm distribution tag. The workflow publishes the Linux
41
+ packages before the main package and safely skips versions already on npm.
42
+ GitHub requires repository write access to start this manual workflow.
43
+
44
+ Before the first release, configure an npm trusted publisher for each package:
45
+ `@rin-ts/sticker`, `@rin-ts/sticker-linux-x64-gnu`, and
46
+ `@rin-ts/sticker-linux-arm64-gnu`. Use GitHub organization `rin-ts`,
47
+ repository `sticker`, workflow filename `release.yml`, and allow direct
48
+ `npm publish`. This uses GitHub OIDC credentials rather than a stored npm
49
+ token.
50
+
51
+ ## Build from source
52
+
53
+ The native build requires Bun, CMake 3.20+, a C++20 compiler, `pkg-config`,
54
+ and development packages for libpng, libjpeg, libwebp, libwebpmux,
55
+ libwebpdemux, libavformat, libavcodec, libavutil, and libswscale. On Void,
56
+ install these FFmpeg headers with `sudo xbps-install -S ffmpeg6-devel`.
57
+
58
+ ```bash
59
+ bun install
60
+ bun run build:native
61
+ ```
62
+
63
+ This produces `build/native/bin/sticker_worker`.
64
+
65
+ ## Usage
66
+
67
+ Create one worker when the application starts, then reuse it for every sticker
68
+ request. Supply already-bounded media bytes; the worker accepts at most 16 MiB
69
+ per source asset.
70
+
71
+ ```ts
72
+ import { createNativeStickerWorker } from "@rin-ts/sticker";
73
+
74
+ const stickerWorker = createNativeStickerWorker({
75
+ // workerPath: "/opt/rin/sticker_worker",
76
+ timeoutMs: 15_000,
77
+ });
78
+
79
+ const source = await Bun.file("./photo.png").arrayBuffer();
80
+
81
+ const sticker = await stickerWorker.transcode(source, {
82
+ trim: true,
83
+ alphaThreshold: 4,
84
+ outline: {
85
+ width: 8,
86
+ color: { red: 255, green: 255, blue: 255, alpha: 255 },
87
+ },
88
+ });
89
+
90
+ // For a Zapo/Rin handler:
91
+ await context.reply({ type: "sticker", media: sticker.data });
92
+
93
+ // During application shutdown:
94
+ await stickerWorker.close();
95
+ ```
96
+
97
+ `transcode()` returns `data` (the WebP bytes), `width`, `height`,
98
+ `frameCount`, `durationMs`, and `isAnimated`.
99
+
100
+ ## Output and operational limits
101
+
102
+ Successful output is validated as 512 × 512 WebP. Static stickers are capped
103
+ at 100 KiB; animated stickers are capped at 500 KiB, must contain more than
104
+ one frame, use frame delays of at least 8 ms, and last no more than 10 seconds.
105
+ These are conservative WhatsApp sticker-pack compatibility targets.
106
+
107
+ The worker is an isolated stdin/stdout subprocess, not a file-path CLI or an
108
+ HTTP server. It accepts bytes and rendering options only. For production,
109
+ continue to enforce download limits in the application, use finite worker
110
+ pools, and run workers with appropriate OS-level CPU and memory limits.
111
+
112
+ For development:
113
+
114
+ ```bash
115
+ bun run test:native
116
+ ```
117
+
118
+ ## License
119
+
120
+ GPL-3.0-only. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@rin-ts/sticker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Native C++ WhatsApp WebP sticker worker for Rin.",
5
+ "license": "GPL-3.0-only",
6
+ "type": "module",
7
+ "exports": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "files": [
10
+ "src",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/rin-ts/sticker.git"
17
+ },
18
+ "bugs": "https://github.com/rin-ts/sticker/issues",
19
+ "homepage": "https://github.com/rin-ts/sticker#readme",
20
+ "publishConfig": {
21
+ "registry": "https://registry.npmjs.org/",
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build:native": "bun run scripts/build-native.ts",
26
+ "test": "bun run typecheck && bun run test:native",
27
+ "test:native": "bun run build:native && ctest --test-dir build/native --output-on-failure && bun test ./tests/native_bridge.test.ts",
28
+ "typecheck": "bun check"
29
+ },
30
+ "devDependencies": {
31
+ "@types/bun": "latest"
32
+ },
33
+ "peerDependencies": {
34
+ "typescript": "^7"
35
+ },
36
+ "optionalDependencies": {
37
+ "@rin-ts/sticker-linux-arm64-gnu": "0.2.0",
38
+ "@rin-ts/sticker-linux-x64-gnu": "0.2.0"
39
+ }
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ export {
2
+ NativeStickerWorker,
3
+ NativeStickerWorkerClosedError,
4
+ NativeStickerWorkerError,
5
+ NativeStickerWorkerTimeoutError,
6
+ NativeStickerWorkerTransportError,
7
+ createNativeStickerWorker,
8
+ } from "./native.ts";
9
+
10
+ export type {
11
+ OutlineOptions,
12
+ RgbaColor,
13
+ } from "./types.ts";
14
+
15
+ export type {
16
+ NativeStickerResult,
17
+ NativeStickerSource,
18
+ NativeStickerTranscodeOptions,
19
+ NativeStickerWorkerOptions,
20
+ } from "./native.ts";