pixbeam 0.0.0-stage → 0.3.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.
@@ -0,0 +1,503 @@
1
+ import {
2
+ DebugPanel,
3
+ PRESETS,
4
+ Scanner,
5
+ Sender,
6
+ estimatePackets,
7
+ resolveConfig
8
+ } from "../chunks/chunk-EYV5XLLF.js";
9
+
10
+ // src/react/Pixbeam.tsx
11
+ import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
12
+
13
+ // src/react/ReceiveView.tsx
14
+ import { useEffect, useRef, useState } from "react";
15
+
16
+ // src/react/format.ts
17
+ var formatBytes = (n) => n < 1024 ? `${n} B` : n < 1048576 ? `${(n / 1024).toFixed(1)} KB` : `${(n / 1048576).toFixed(2)} MB`;
18
+ var formatTime = (s) => !isFinite(s) ? "-" : s < 1 ? "< 1 dtk" : s < 60 ? `${Math.round(s)} dtk` : `${Math.floor(s / 60)}m ${Math.round(s % 60)}d`;
19
+ function throttle(ms) {
20
+ let last = 0;
21
+ return (force = false) => {
22
+ const now = performance.now();
23
+ if (!force && now - last < ms) return false;
24
+ last = now;
25
+ return true;
26
+ };
27
+ }
28
+
29
+ // src/react/ReceiveView.tsx
30
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
31
+ var EMPTY_HUD = {
32
+ status: "Mencari kode\u2026",
33
+ tone: "",
34
+ progress: 0,
35
+ packets: "0 / -",
36
+ blocks: "-",
37
+ speed: "-",
38
+ valid: "-",
39
+ time: "-",
40
+ ms: "-",
41
+ camera: "-",
42
+ process: "-",
43
+ zoom: "-",
44
+ align: "-",
45
+ exposure: "auto"
46
+ };
47
+ var TEXT_FILE = /\.(txt|md|json|csv|js|ts|html|css|xml|log)$/i;
48
+ function drawOverlay(canvas, video, stats) {
49
+ const dpr = devicePixelRatio || 1;
50
+ const cw = canvas.clientWidth;
51
+ const ch = canvas.clientHeight;
52
+ if (canvas.width !== Math.round(cw * dpr)) canvas.width = Math.round(cw * dpr);
53
+ if (canvas.height !== Math.round(ch * dpr)) canvas.height = Math.round(ch * dpr);
54
+ const ctx = canvas.getContext("2d");
55
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
56
+ ctx.clearRect(0, 0, cw, ch);
57
+ const corners = stats.report.corners;
58
+ const vw = video.videoWidth;
59
+ const vh = video.videoHeight;
60
+ if (!corners || !vw) return;
61
+ const scale = Math.max(cw / vw, ch / vh);
62
+ const ox = (cw - vw * scale) / 2;
63
+ const oy = (ch - vh * scale) / 2;
64
+ const map = ([x, y]) => [x * scale + ox, y * scale + oy];
65
+ ctx.strokeStyle = ctx.fillStyle = stats.report.packets ? "#4ade80" : "#ffffff";
66
+ ctx.lineWidth = 2;
67
+ ctx.beginPath();
68
+ corners.map(map).forEach(([x, y], i) => i ? ctx.lineTo(x, y) : ctx.moveTo(x, y));
69
+ ctx.closePath();
70
+ ctx.stroke();
71
+ for (const [x, y] of corners.map(map)) {
72
+ ctx.beginPath();
73
+ ctx.arc(x, y, 5, 0, Math.PI * 2);
74
+ ctx.fill();
75
+ }
76
+ for (const [x, y] of (stats.report.alignment?.nodes ?? []).map(map)) {
77
+ ctx.beginPath();
78
+ ctx.arc(x, y, 3, 0, Math.PI * 2);
79
+ ctx.fill();
80
+ }
81
+ }
82
+ function toHud(s) {
83
+ const { report, fps, camera } = s;
84
+ const hud = { ...EMPTY_HUD };
85
+ if (!report.corners) hud.status = "Mencari 4 marker sudut\u2026";
86
+ else if (!report.lock) hud.status = "Marker terlihat, mencocokkan pengaturan\u2026";
87
+ else {
88
+ hud.status = `Terkunci \xB7 ${report.lock.preset.w}\xD7${report.lock.preset.h} \xB7 ${2 ** report.lock.bits} warna`;
89
+ hud.tone = "ok";
90
+ }
91
+ hud.ms = `${Math.round(s.processMs)} ms/frame`;
92
+ hud.valid = s.expectedPackets ? `${Math.round(s.validPackets / s.expectedPackets * 100)}%` : "-";
93
+ if (fps.camera) {
94
+ hud.camera = `${fps.width}\xD7${fps.height} \xB7 ${Math.round(fps.camera)} fps`;
95
+ hud.process = `${Math.round(fps.processed)} fps`;
96
+ }
97
+ hud.zoom = camera?.zoomSupported ? `${camera.zoom.toFixed(1)}\xD7` : "tidak ada";
98
+ hud.align = report.alignment ? `${report.alignment.found}/${report.alignment.total}` : "-";
99
+ hud.exposure = camera?.exposureLocked ? "terkunci" : "auto";
100
+ if (s.blockCount) {
101
+ hud.progress = Math.min(99, s.received / s.needed * 100);
102
+ hud.packets = `${s.received.toLocaleString("id")} / \xB1${s.needed.toLocaleString("id")}`;
103
+ hud.blocks = `${s.known}/${s.blockCount}`;
104
+ hud.speed = s.elapsed > 0 ? `${formatBytes(Math.round(s.received * s.blockSize / s.elapsed))}/s` : "-";
105
+ hud.time = formatTime(s.elapsed);
106
+ }
107
+ return hud;
108
+ }
109
+ function ReceiveView({ config, active }) {
110
+ const videoRef = useRef(null);
111
+ const overlayRef = useRef(null);
112
+ const debugRootRef = useRef(null);
113
+ const heatmapRef = useRef(null);
114
+ const debugInfoRef = useRef(null);
115
+ const scannerRef = useRef(null);
116
+ const debugRef = useRef(null);
117
+ const doneRef = useRef(false);
118
+ const [open, setOpen] = useState(false);
119
+ const [autoZoom, setAutoZoom] = useState(config.autoZoom);
120
+ const [lockExposure, setLockExposure] = useState(config.lockExposure);
121
+ const [hud, setHud] = useState(EMPTY_HUD);
122
+ const [result, setResult] = useState(null);
123
+ const [error, setError] = useState("");
124
+ const [copied, setCopied] = useState("");
125
+ useEffect(() => {
126
+ const tick = throttle(150);
127
+ const onStats = (s) => {
128
+ drawOverlay(overlayRef.current, videoRef.current, s);
129
+ debugRef.current?.update(s.report);
130
+ if (!doneRef.current && tick()) setHud(toHud(s));
131
+ };
132
+ const onFile = (f) => {
133
+ doneRef.current = true;
134
+ setHud((h) => ({
135
+ ...h,
136
+ progress: 100,
137
+ blocks: "lengkap",
138
+ status: f.valid ? "Selesai. File diterima utuh." : "Selesai, tetapi checksum gagal.",
139
+ tone: f.valid ? "ok" : "bad"
140
+ }));
141
+ setResult({
142
+ name: f.name,
143
+ size: f.data.length,
144
+ valid: f.valid,
145
+ seconds: f.seconds,
146
+ url: URL.createObjectURL(new Blob([f.data])),
147
+ text: TEXT_FILE.test(f.name) && f.data.length < 2e5 ? new TextDecoder().decode(f.data) : null
148
+ });
149
+ navigator.vibrate?.(80);
150
+ };
151
+ scannerRef.current = new Scanner(videoRef.current, onStats, onFile);
152
+ if (config.debug) debugRef.current = new DebugPanel(debugRootRef.current, heatmapRef.current, debugInfoRef.current);
153
+ return () => scannerRef.current?.stop();
154
+ }, [config.debug]);
155
+ const reset = () => {
156
+ doneRef.current = false;
157
+ scannerRef.current?.reset();
158
+ debugRef.current?.reset();
159
+ setResult((r) => {
160
+ if (r) URL.revokeObjectURL(r.url);
161
+ return null;
162
+ });
163
+ setHud(EMPTY_HUD);
164
+ };
165
+ const close = () => {
166
+ scannerRef.current?.stop();
167
+ setOpen(false);
168
+ document.body.classList.remove("pb-scanning");
169
+ if (document.fullscreenElement) document.exitFullscreen().catch(() => {
170
+ });
171
+ };
172
+ useEffect(() => {
173
+ if (!active && open) close();
174
+ }, [active]);
175
+ const startScan = async () => {
176
+ const scanner = scannerRef.current;
177
+ reset();
178
+ debugRef.current?.setEnabled(config.debug);
179
+ scanner.autoZoom = autoZoom;
180
+ scanner.lockExposure = lockExposure;
181
+ scanner.frameRate = config.cameraFps;
182
+ setError("");
183
+ setOpen(true);
184
+ document.body.classList.add("pb-scanning");
185
+ document.documentElement.requestFullscreen?.().catch(() => {
186
+ });
187
+ try {
188
+ await scanner.start();
189
+ } catch (e) {
190
+ close();
191
+ setError(e.message);
192
+ }
193
+ };
194
+ const copyReport = async () => {
195
+ const text = debugRef.current?.copyReport();
196
+ if (!text) return;
197
+ try {
198
+ await navigator.clipboard.writeText(text);
199
+ setCopied("Tersalin");
200
+ } catch {
201
+ setCopied("Gagal menyalin");
202
+ }
203
+ setTimeout(() => setCopied(""), 1500);
204
+ };
205
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
206
+ /* @__PURE__ */ jsx("div", { className: "pb-grid pb-grid-single", hidden: !active, children: /* @__PURE__ */ jsxs("div", { className: "pb-panel", children: [
207
+ /* @__PURE__ */ jsx("h2", { children: "Penerima" }),
208
+ /* @__PURE__ */ jsx("p", { className: "pb-msg", children: "Kamera akan terbuka layar penuh. Arahkan ke kode di layar pengirim sampai keempat marker sudut terlihat." }),
209
+ /* @__PURE__ */ jsxs("label", { className: "pb-check", children: [
210
+ /* @__PURE__ */ jsx("input", { type: "checkbox", checked: autoZoom, onChange: (e) => setAutoZoom(e.target.checked) }),
211
+ " Zoom otomatis"
212
+ ] }),
213
+ /* @__PURE__ */ jsxs("label", { className: "pb-check", children: [
214
+ /* @__PURE__ */ jsx("input", { type: "checkbox", checked: lockExposure, onChange: (e) => setLockExposure(e.target.checked) }),
215
+ " Kunci exposure dan white balance saat terkunci"
216
+ ] }),
217
+ /* @__PURE__ */ jsx("div", { className: "pb-row", children: /* @__PURE__ */ jsx("button", { className: "pb-primary", onClick: startScan, children: "Mulai scan" }) }),
218
+ error && /* @__PURE__ */ jsx("p", { className: "pb-msg bad", children: error })
219
+ ] }) }),
220
+ /* @__PURE__ */ jsxs("div", { className: "pb-scan", hidden: !open, children: [
221
+ /* @__PURE__ */ jsx("video", { ref: videoRef, playsInline: true, muted: true }),
222
+ /* @__PURE__ */ jsx("canvas", { ref: overlayRef }),
223
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud", children: [
224
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud-top", children: [
225
+ /* @__PURE__ */ jsx("span", { className: `pb-hud-status ${hud.tone}`, children: hud.status }),
226
+ /* @__PURE__ */ jsx("button", { className: "pb-close", onClick: close, "aria-label": "Tutup kamera", children: "\u2715" })
227
+ ] }),
228
+ /* @__PURE__ */ jsx("div", { className: "pb-bar", children: /* @__PURE__ */ jsx("i", { style: { width: `${hud.progress}%` } }) }),
229
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud-line", children: [
230
+ /* @__PURE__ */ jsxs("span", { children: [
231
+ "Paket ",
232
+ /* @__PURE__ */ jsx("b", { children: hud.packets })
233
+ ] }),
234
+ /* @__PURE__ */ jsxs("span", { children: [
235
+ "Blok ",
236
+ /* @__PURE__ */ jsx("b", { children: hud.blocks })
237
+ ] }),
238
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("b", { children: hud.speed }) })
239
+ ] }),
240
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud-line", children: [
241
+ /* @__PURE__ */ jsxs("span", { children: [
242
+ "Valid ",
243
+ /* @__PURE__ */ jsx("b", { children: hud.valid })
244
+ ] }),
245
+ /* @__PURE__ */ jsxs("span", { children: [
246
+ "Waktu ",
247
+ /* @__PURE__ */ jsx("b", { children: hud.time })
248
+ ] }),
249
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx("b", { children: hud.ms }) })
250
+ ] }),
251
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud-line", children: [
252
+ /* @__PURE__ */ jsxs("span", { children: [
253
+ "Kamera ",
254
+ /* @__PURE__ */ jsx("b", { children: hud.camera })
255
+ ] }),
256
+ /* @__PURE__ */ jsxs("span", { children: [
257
+ "Proses ",
258
+ /* @__PURE__ */ jsx("b", { children: hud.process })
259
+ ] })
260
+ ] }),
261
+ /* @__PURE__ */ jsxs("div", { className: "pb-hud-line", children: [
262
+ /* @__PURE__ */ jsxs("span", { children: [
263
+ "Zoom ",
264
+ /* @__PURE__ */ jsx("b", { children: hud.zoom })
265
+ ] }),
266
+ /* @__PURE__ */ jsxs("span", { children: [
267
+ "Align ",
268
+ /* @__PURE__ */ jsx("b", { children: hud.align })
269
+ ] }),
270
+ /* @__PURE__ */ jsxs("span", { children: [
271
+ "Cahaya ",
272
+ /* @__PURE__ */ jsx("b", { children: hud.exposure })
273
+ ] })
274
+ ] })
275
+ ] }),
276
+ config.debug && /* @__PURE__ */ jsxs("div", { className: "pb-debug", ref: debugRootRef, children: [
277
+ /* @__PURE__ */ jsxs("div", { children: [
278
+ /* @__PURE__ */ jsx("canvas", { ref: heatmapRef }),
279
+ /* @__PURE__ */ jsxs("div", { className: "pb-legend", children: [
280
+ "0%",
281
+ /* @__PURE__ */ jsx("i", {}),
282
+ "25%+"
283
+ ] })
284
+ ] }),
285
+ /* @__PURE__ */ jsx("div", { className: "pb-debug-info", ref: debugInfoRef, children: "Menunggu frame terkunci\u2026" }),
286
+ /* @__PURE__ */ jsxs("div", { className: "pb-debug-actions", children: [
287
+ /* @__PURE__ */ jsx("button", { onClick: () => debugRef.current?.reset(), children: "Reset peta" }),
288
+ /* @__PURE__ */ jsx("button", { onClick: copyReport, children: copied || "Salin laporan" })
289
+ ] })
290
+ ] }),
291
+ result && /* @__PURE__ */ jsxs("div", { className: `pb-sheet ${config.debug ? "with-debug" : ""}`, children: [
292
+ /* @__PURE__ */ jsx("h3", { children: result.name }),
293
+ /* @__PURE__ */ jsxs("p", { children: [
294
+ formatBytes(result.size),
295
+ " dalam ",
296
+ formatTime(result.seconds),
297
+ " \xB7 ",
298
+ result.valid ? "checksum cocok" : "checksum tidak cocok"
299
+ ] }),
300
+ /* @__PURE__ */ jsxs("div", { className: "pb-row", children: [
301
+ /* @__PURE__ */ jsx("a", { className: "pb-button pb-primary", href: result.url, download: result.name, children: "Unduh file" }),
302
+ /* @__PURE__ */ jsx("button", { onClick: reset, children: "Scan lagi" }),
303
+ /* @__PURE__ */ jsx("button", { onClick: close, children: "Tutup" })
304
+ ] }),
305
+ result.text !== null && /* @__PURE__ */ jsx("pre", { children: result.text })
306
+ ] })
307
+ ] })
308
+ ] });
309
+ }
310
+
311
+ // src/react/SendView.tsx
312
+ import { useCallback, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
313
+
314
+ // src/react/Stats.tsx
315
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
316
+ function Stats({ rows }) {
317
+ if (!rows.length) return null;
318
+ return /* @__PURE__ */ jsx2("div", { className: "pb-stats", children: rows.map(([label, value]) => /* @__PURE__ */ jsxs2("div", { className: "pb-stat", children: [
319
+ /* @__PURE__ */ jsx2("span", { children: label }),
320
+ /* @__PURE__ */ jsx2("b", { children: value })
321
+ ] }, label)) });
322
+ }
323
+
324
+ // src/react/SendView.tsx
325
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
326
+ function SendView({ config, active }) {
327
+ const canvasRef = useRef2(null);
328
+ const stageRef = useRef2(null);
329
+ const senderRef = useRef2(null);
330
+ const [file, setFile] = useState2(null);
331
+ const [text, setText] = useState2("Halo dari devsejenak. Kalau teks ini muncul di HP, berarti transfer lewat kamera berhasil.");
332
+ const [preset, setPreset] = useState2(config.defaultPreset);
333
+ const [bits, setBits] = useState2(config.defaultBits);
334
+ const [orientation, setOrientation] = useState2(config.defaultOrientation);
335
+ const [fps, setFps] = useState2(Math.min(config.defaultFps, config.maxFps));
336
+ const [testPattern, setTestPattern] = useState2(false);
337
+ const [running, setRunning] = useState2(false);
338
+ const [info, setInfo] = useState2(null);
339
+ const [message, setMessage] = useState2({ text: "" });
340
+ useEffect2(() => {
341
+ const canvas = canvasRef.current;
342
+ const tick = throttle(400);
343
+ const sender = new Sender(canvas, (data) => {
344
+ if (tick()) setInfo({ data: { ...data }, actualFps: sender.actualFps });
345
+ });
346
+ sender.fps = fps;
347
+ sender.orientation = orientation;
348
+ senderRef.current = sender;
349
+ const fit = () => sender.fit();
350
+ const onFullscreen = () => setTimeout(fit, 60);
351
+ addEventListener("resize", fit);
352
+ document.addEventListener("fullscreenchange", onFullscreen);
353
+ return () => {
354
+ sender.stop();
355
+ removeEventListener("resize", fit);
356
+ document.removeEventListener("fullscreenchange", onFullscreen);
357
+ };
358
+ }, []);
359
+ useEffect2(() => {
360
+ if (senderRef.current) senderRef.current.fps = fps;
361
+ }, [fps]);
362
+ const stop = useCallback(() => {
363
+ senderRef.current?.stop();
364
+ setRunning(false);
365
+ }, []);
366
+ useEffect2(() => {
367
+ if (!active) stop();
368
+ }, [active, stop]);
369
+ const start = useCallback(
370
+ async (nextOrientation = orientation) => {
371
+ const sender = senderRef.current;
372
+ const chosen = PRESETS.find((p) => p.id === preset) ?? PRESETS[PRESETS.length - 1];
373
+ sender.orientation = nextOrientation;
374
+ if (config.testPattern && testPattern) {
375
+ sender.startTestPattern(chosen, bits);
376
+ setRunning(true);
377
+ return setMessage({ text: "Mengirim pola uji. Aktifkan mode debug di penerima.", tone: "ok" });
378
+ }
379
+ if (!file && !text.trim()) return setMessage({ text: "Pilih file atau tulis teks dulu.", tone: "bad" });
380
+ const name = file?.name ?? "pesan.txt";
381
+ const bytes = file ? new Uint8Array(await file.arrayBuffer()) : new TextEncoder().encode(text);
382
+ await sender.start(name, bytes, chosen, bits);
383
+ setRunning(true);
384
+ setMessage({ text: `Mengirim ${name}. Buka tab Terima di HP.`, tone: "ok" });
385
+ },
386
+ [orientation, preset, bits, file, text, testPattern, config.testPattern]
387
+ );
388
+ const changeOrientation = (value) => {
389
+ setOrientation(value);
390
+ if (senderRef.current) senderRef.current.orientation = value;
391
+ if (running) start(value);
392
+ else requestAnimationFrame(() => senderRef.current?.fit());
393
+ };
394
+ const toggleFullscreen = async () => {
395
+ try {
396
+ if (document.fullscreenElement) await document.exitFullscreen();
397
+ else await stageRef.current.requestFullscreen();
398
+ } catch {
399
+ setMessage({ text: "Layar penuh tidak didukung di browser ini.", tone: "bad" });
400
+ }
401
+ };
402
+ const rows = [];
403
+ if (info) {
404
+ const { data, actualFps } = info;
405
+ const { layout, blockCount } = data;
406
+ if (blockCount) {
407
+ rows.push(
408
+ ["Ukuran asli", formatBytes(data.originalSize)],
409
+ ["Dikirim", `${formatBytes(data.packedSize)}${data.compressed ? " (kompres)" : ""}`],
410
+ ["Data per frame", formatBytes(layout.packetsPerFrame * layout.packetSize)],
411
+ ["Paket per frame", layout.packetsPerFrame],
412
+ ["Perkiraan waktu", formatTime(Math.ceil(estimatePackets(blockCount) / layout.packetsPerFrame) / fps)],
413
+ ["FPS aktual", actualFps]
414
+ );
415
+ } else {
416
+ rows.push(["Mode", "pola uji"], ["Data per frame", formatBytes(layout.packetsPerFrame * layout.packetSize)], ["Paket per frame", layout.packetsPerFrame], ["FPS aktual", actualFps]);
417
+ }
418
+ }
419
+ return /* @__PURE__ */ jsxs3("div", { className: "pb-grid", hidden: !active, children: [
420
+ /* @__PURE__ */ jsxs3("div", { className: "pb-panel", children: [
421
+ /* @__PURE__ */ jsx3("h2", { children: "Pengirim" }),
422
+ /* @__PURE__ */ jsx3("label", { htmlFor: "pb-file", children: "File" }),
423
+ /* @__PURE__ */ jsx3(
424
+ "input",
425
+ {
426
+ id: "pb-file",
427
+ type: "file",
428
+ onChange: (e) => {
429
+ const f = e.target.files?.[0] ?? null;
430
+ setFile(f);
431
+ if (f) setText("");
432
+ }
433
+ }
434
+ ),
435
+ /* @__PURE__ */ jsx3("label", { htmlFor: "pb-text", children: "Atau teks" }),
436
+ /* @__PURE__ */ jsx3("textarea", { id: "pb-text", value: text, onChange: (e) => setText(e.target.value) }),
437
+ /* @__PURE__ */ jsx3("label", { htmlFor: "pb-preset", children: "Ukuran grid" }),
438
+ /* @__PURE__ */ jsx3("select", { id: "pb-preset", value: preset, onChange: (e) => setPreset(e.target.value), children: PRESETS.map((p) => /* @__PURE__ */ jsxs3("option", { value: p.id, children: [
439
+ p.w,
440
+ " \xD7 ",
441
+ p.h,
442
+ " sel"
443
+ ] }, p.id)) }),
444
+ /* @__PURE__ */ jsx3("label", { htmlFor: "pb-bits", children: "Mode warna" }),
445
+ /* @__PURE__ */ jsxs3("select", { id: "pb-bits", value: bits, onChange: (e) => setBits(Number(e.target.value)), children: [
446
+ /* @__PURE__ */ jsx3("option", { value: 1, children: "Hitam-putih \xB7 1 bit per sel" }),
447
+ /* @__PURE__ */ jsx3("option", { value: 2, children: "4 warna \xB7 2 bit per sel" }),
448
+ /* @__PURE__ */ jsx3("option", { value: 3, children: "8 warna \xB7 3 bit per sel" })
449
+ ] }),
450
+ /* @__PURE__ */ jsx3("label", { htmlFor: "pb-orientation", children: "Orientasi frame" }),
451
+ /* @__PURE__ */ jsxs3("select", { id: "pb-orientation", value: orientation, onChange: (e) => changeOrientation(e.target.value), children: [
452
+ /* @__PURE__ */ jsx3("option", { value: "portrait", children: "Portrait \xB7 HP dipegang tegak" }),
453
+ /* @__PURE__ */ jsx3("option", { value: "landscape", children: "Landscape \xB7 HP dipegang miring" })
454
+ ] }),
455
+ /* @__PURE__ */ jsxs3("label", { htmlFor: "pb-fps", children: [
456
+ "Kecepatan ",
457
+ /* @__PURE__ */ jsx3("span", { className: "pb-mono", children: fps }),
458
+ " frame/detik"
459
+ ] }),
460
+ /* @__PURE__ */ jsx3("input", { id: "pb-fps", type: "range", min: 2, max: config.maxFps, step: 1, value: fps, onChange: (e) => setFps(Number(e.target.value)) }),
461
+ config.testPattern && /* @__PURE__ */ jsxs3("label", { className: "pb-check", children: [
462
+ /* @__PURE__ */ jsx3("input", { type: "checkbox", checked: testPattern, onChange: (e) => setTestPattern(e.target.checked) }),
463
+ " Kirim pola uji"
464
+ ] }),
465
+ /* @__PURE__ */ jsxs3("div", { className: "pb-row", children: [
466
+ /* @__PURE__ */ jsx3("button", { className: "pb-primary", onClick: () => running ? stop() : start(), children: running ? "Berhenti" : "Mulai kirim" }),
467
+ /* @__PURE__ */ jsx3("button", { onClick: toggleFullscreen, children: "Layar penuh" })
468
+ ] }),
469
+ /* @__PURE__ */ jsx3("p", { className: `pb-msg ${message.tone ?? ""}`, children: message.text }),
470
+ /* @__PURE__ */ jsx3(Stats, { rows })
471
+ ] }),
472
+ /* @__PURE__ */ jsxs3("div", { className: `pb-stage ${orientation === "portrait" ? "portrait" : ""}`, ref: stageRef, children: [
473
+ /* @__PURE__ */ jsx3("canvas", { ref: canvasRef, hidden: !running && !info }),
474
+ !running && !info && /* @__PURE__ */ jsx3("p", { className: "pb-empty", children: "Pilih file atau tulis teks, lalu tekan Mulai kirim." })
475
+ ] })
476
+ ] });
477
+ }
478
+
479
+ // src/react/Pixbeam.tsx
480
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
481
+ var tabFromHash = () => typeof location !== "undefined" && location.hash === "#terima" ? "terima" : "kirim";
482
+ function Pixbeam({ config: overrides, heading, intro }) {
483
+ const config = useMemo(() => resolveConfig(overrides), []);
484
+ const [tab, setTab] = useState3("kirim");
485
+ useEffect3(() => {
486
+ const onHash = () => setTab(tabFromHash());
487
+ onHash();
488
+ addEventListener("hashchange", onHash);
489
+ return () => removeEventListener("hashchange", onHash);
490
+ }, []);
491
+ return /* @__PURE__ */ jsxs4("div", { className: "pb", children: [
492
+ /* @__PURE__ */ jsx4("nav", { className: "pb-tabs", "aria-label": "Mode Pixbeam", children: /* @__PURE__ */ jsx4("div", { className: "pb-tabs-inner", children: ["kirim", "terima"].map((t) => /* @__PURE__ */ jsx4("a", { href: `#${t}`, className: tab === t ? "on" : "", "aria-current": tab === t ? "page" : void 0, children: t === "kirim" ? "Kirim" : "Terima" }, t)) }) }),
493
+ /* @__PURE__ */ jsxs4("div", { className: "pb-body", children: [
494
+ heading && /* @__PURE__ */ jsx4("h1", { className: "pb-title", children: heading }),
495
+ intro && /* @__PURE__ */ jsx4("p", { className: "pb-intro", children: intro }),
496
+ /* @__PURE__ */ jsx4(SendView, { config, active: tab === "kirim" }),
497
+ /* @__PURE__ */ jsx4(ReceiveView, { config, active: tab === "terima" })
498
+ ] })
499
+ ] });
500
+ }
501
+ export {
502
+ Pixbeam
503
+ };
package/dist/style.css ADDED
@@ -0,0 +1,67 @@
1
+ .pb{--pb-bg:light-dark(#ffffff,#0b0b0b);--pb-fg:light-dark(#0b0b0b,#f2f2f2);--pb-muted:light-dark(#6b6b6b,#9a9a9a);--pb-line:light-dark(#e6e6e6,#262626);--pb-soft:light-dark(#f5f5f5,#151515);--pb-ok:light-dark(#127a3e,#4ade80);--pb-bad:light-dark(#b42318,#f87171);color:var(--pb-fg)}
2
+ .pb *{box-sizing:border-box;min-width:0}
3
+ .pb [hidden]{display:none!important}
4
+ .pb-mono,.pb-stat b,.pb-hud-line{font-family:"JetBrains Mono",ui-monospace,monospace}
5
+ .pb-tabs{border-bottom:1px solid var(--pb-line);background:var(--pb-bg);position:sticky;top:0;z-index:10}
6
+ .pb-tabs-inner{max-width:1200px;margin:0 auto;padding:0 max(4vw,16px);display:flex;gap:4px}
7
+ .pb-tabs a{padding:12px 16px;color:var(--pb-muted);text-decoration:none;font-weight:500;border-bottom:2px solid transparent;margin-bottom:-1px;min-height:46px;display:flex;align-items:center}
8
+ .pb-tabs a.on{color:var(--pb-fg);border-bottom-color:var(--pb-fg)}
9
+ .pb-title{font-size:clamp(22px,3.4vw,30px);line-height:1.15;letter-spacing:-.02em;margin:0 0 4px;font-weight:600;text-wrap:balance}
10
+ .pb-intro{color:var(--pb-muted);margin:0 0 18px;max-width:62ch}
11
+ .pb-body{max-width:1200px;margin:0 auto;padding:20px max(4vw,16px) 32px}
12
+ .pb-grid{display:grid;grid-template-columns:minmax(0,340px) minmax(0,1fr);gap:20px;align-items:start}
13
+ .pb-grid-single{grid-template-columns:minmax(0,520px)}
14
+ @media(max-width:880px){.pb-grid{grid-template-columns:minmax(0,1fr)}}
15
+ .pb-panel{border:1px solid var(--pb-line);border-radius:12px;padding:18px;background:var(--pb-bg)}
16
+ .pb-panel h2{font-size:15px;margin:0 0 4px;font-weight:600}
17
+ .pb label{display:block;font-size:13px;color:var(--pb-muted);margin:14px 0 6px}
18
+ .pb input[type=file],.pb select,.pb textarea{width:100%;font:inherit;font-size:15px;color:var(--pb-fg);background:var(--pb-bg);border:1px solid var(--pb-line);border-radius:8px;padding:9px 10px}
19
+ .pb textarea{min-height:84px;resize:vertical}
20
+ .pb input[type=range]{width:100%;accent-color:var(--pb-fg)}
21
+ .pb label.pb-check{display:flex;align-items:center;gap:10px;color:var(--pb-fg);font-size:14px;cursor:pointer;min-height:40px;margin:10px 0 0}
22
+ .pb-check input{width:18px;height:18px;accent-color:var(--pb-fg)}
23
+ .pb-row{display:flex;gap:8px;flex-wrap:wrap;margin-top:16px}
24
+ .pb button,.pb-button{font:inherit;font-weight:500;font-size:14px;min-height:42px;padding:9px 16px;border-radius:8px;border:1px solid var(--pb-line);background:var(--pb-bg);color:var(--pb-fg);cursor:pointer;text-decoration:none;display:inline-flex;align-items:center}
25
+ .pb .pb-primary{background:var(--pb-fg);color:var(--pb-bg);border-color:var(--pb-fg)}
26
+ .pb :focus-visible{outline:2px solid var(--pb-fg);outline-offset:2px}
27
+ .pb-msg{font-size:13px;color:var(--pb-muted);margin:10px 0 0;min-height:20px}
28
+ .pb-msg.ok{color:var(--pb-ok)}.pb-msg.bad{color:var(--pb-bad)}
29
+ .pb-stats{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1px;background:var(--pb-line);border:1px solid var(--pb-line);border-radius:10px;overflow:hidden;margin-top:14px}
30
+ .pb-stat{background:var(--pb-bg);padding:9px 12px}
31
+ .pb-stat span{display:block;font-size:12px;color:var(--pb-muted)}
32
+ .pb-stat b{font-weight:500;font-size:15px;white-space:nowrap}
33
+ .pb-stage{background:#000;border-radius:12px;display:flex;align-items:center;justify-content:center;aspect-ratio:16/9;overflow:hidden}
34
+ .pb-stage.portrait{aspect-ratio:auto;height:min(80vh,920px)}
35
+ .pb-stage:fullscreen{border-radius:0;aspect-ratio:auto}
36
+ .pb-stage canvas{image-rendering:pixelated;display:block}
37
+ .pb-empty{color:#8a8a8a;text-align:center;padding:24px;max-width:34ch;font-size:14px}
38
+ .pb-scan{position:fixed;inset:0;z-index:100;background:#000;color:#fff}
39
+ .pb-scan video,.pb-scan>canvas{position:absolute;inset:0;width:100%;height:100%}
40
+ .pb-scan video{object-fit:cover}
41
+ .pb-hud{position:absolute;left:max(12px,env(safe-area-inset-left));right:max(12px,env(safe-area-inset-right));top:max(12px,env(safe-area-inset-top));background:rgba(10,10,10,.62);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:1px solid rgba(255,255,255,.12);border-radius:14px;padding:12px 14px}
42
+ .pb-hud-top{display:flex;align-items:center;justify-content:space-between;gap:10px}
43
+ .pb-hud-status{font-size:14px;font-weight:500;color:#fff}
44
+ .pb-hud-status.ok{color:#4ade80}.pb-hud-status.bad{color:#f87171}
45
+ .pb .pb-close{min-height:36px;min-width:36px;padding:0;justify-content:center;border-radius:50%;background:rgba(255,255,255,.12);border:0;color:#fff;font-size:16px}
46
+ .pb-bar{height:6px;background:rgba(255,255,255,.18);border-radius:3px;overflow:hidden;margin-top:10px}
47
+ .pb-bar i{display:block;height:100%;width:0;background:#fff;transition:width .2s}
48
+ .pb-hud-line{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;font-size:12px;font-weight:500;margin-top:8px;color:rgba(255,255,255,.85)}
49
+ .pb-hud-line b{color:#fff;font-weight:500}
50
+ .pb-sheet{position:absolute;left:max(12px,env(safe-area-inset-left));right:max(12px,env(safe-area-inset-right));bottom:max(12px,env(safe-area-inset-bottom));background:var(--pb-bg);color:var(--pb-fg);border-radius:16px;padding:16px}
51
+ .pb-sheet.with-debug{bottom:calc(46vh + 24px)}
52
+ .pb-sheet h3{margin:0;font-size:16px;font-weight:600;overflow-wrap:anywhere}
53
+ .pb-sheet p{margin:2px 0 0;font-size:13px;color:var(--pb-muted)}
54
+ .pb-sheet pre{white-space:pre-wrap;max-height:30vh;overflow:auto;background:var(--pb-soft);padding:10px;border-radius:8px;font-size:12px;margin:12px 0 0}
55
+ .pb-debug{position:absolute;left:max(12px,env(safe-area-inset-left));right:max(12px,env(safe-area-inset-right));bottom:max(12px,env(safe-area-inset-bottom));background:rgba(10,10,10,.72);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border:1px solid rgba(255,255,255,.12);border-radius:14px;padding:12px;display:grid;grid-template-columns:minmax(0,110px) minmax(0,1fr);gap:12px;max-height:46vh;overflow:auto}
56
+ .pb-debug canvas{width:100%;height:auto;image-rendering:pixelated;border-radius:6px;background:#111;display:block}
57
+ .pb-debug-info{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 10px;font-size:11px;align-content:start}
58
+ .pb-debug-info div span{display:block;color:rgba(255,255,255,.6)}
59
+ .pb-debug-info div b{font:500 12px "JetBrains Mono",monospace;color:#fff;overflow-wrap:anywhere}
60
+ .pb-debug-info .wide{grid-column:1/-1}
61
+ .pb-debug-info p{grid-column:1/-1;margin:4px 0 0;font-size:12px;line-height:1.45}
62
+ .pb-debug-actions{grid-column:1/-1;display:flex;gap:8px;flex-wrap:wrap}
63
+ .pb .pb-debug-actions button{min-height:34px;padding:6px 12px;font-size:12px;background:rgba(255,255,255,.12);border:0;color:#fff}
64
+ .pb-legend{display:flex;align-items:center;gap:6px;font-size:10px;color:rgba(255,255,255,.6);margin-top:6px}
65
+ .pb-legend i{flex:1;height:6px;border-radius:3px;background:linear-gradient(90deg,#282828,#fad214,#fa1414)}
66
+ body.pb-scanning{overflow:hidden}
67
+ @media(prefers-reduced-motion:reduce){.pb-bar i{transition:none}}
@@ -0,0 +1,28 @@
1
+ import type { Point } from '../core/index.js';
2
+ export type { Point };
3
+ export interface ZoomInput {
4
+ now: number;
5
+ locked: boolean;
6
+ cellPx: number | null;
7
+ corners: Point[] | null;
8
+ frameW: number;
9
+ frameH: number;
10
+ }
11
+ export interface ZoomRange {
12
+ min: number;
13
+ max: number;
14
+ step: number;
15
+ }
16
+ export declare class AutoZoom {
17
+ readonly range: ZoomRange;
18
+ target: number;
19
+ cooldown: number;
20
+ lostDelay: number;
21
+ zoom: number;
22
+ private lastChange;
23
+ private lastSeen;
24
+ private unlockedSince;
25
+ constructor(range: ZoomRange, initial?: number);
26
+ next(input: ZoomInput): number | null;
27
+ private clamp;
28
+ }
@@ -0,0 +1,25 @@
1
+ import { FrameReport } from '../core/index.js';
2
+ export interface CameraState {
3
+ zoom: number | null;
4
+ zoomSupported: boolean;
5
+ exposureLocked: boolean;
6
+ }
7
+ export declare class CameraControl {
8
+ private track;
9
+ autoZoom: boolean;
10
+ lockExposure: boolean;
11
+ private zoomer;
12
+ private caps;
13
+ private locked;
14
+ private goodSince;
15
+ private lostSince;
16
+ private busy;
17
+ constructor(track: MediaStreamTrack);
18
+ get state(): CameraState;
19
+ update(report: FrameReport, frameW: number, frameH: number, validRate: number): void;
20
+ reset(): void;
21
+ private updateExposure;
22
+ private lock;
23
+ private unlock;
24
+ private apply;
25
+ }
@@ -0,0 +1,2 @@
1
+ export declare function deflate(bytes: Uint8Array): Promise<Uint8Array | null>;
2
+ export declare function inflate(bytes: Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,17 @@
1
+ import { FrameReport } from '../core/index.js';
2
+ export declare class DebugPanel {
3
+ private root;
4
+ private canvas;
5
+ private text;
6
+ enabled: boolean;
7
+ private map;
8
+ private lastSummary;
9
+ private portrait;
10
+ private frames;
11
+ constructor(root: HTMLElement, canvas: HTMLCanvasElement, text: HTMLElement);
12
+ setEnabled(on: boolean): void;
13
+ reset(): void;
14
+ update(report: FrameReport): void;
15
+ copyReport(): string;
16
+ private render;
17
+ }