@farisabid/foliokit 0.0.0-stage → 1.0.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +151 -2
  3. package/bin/foliokit.js +476 -0
  4. package/package.json +46 -4
  5. package/public/css/main.css +915 -0
  6. package/public/css/tokens.css +29 -0
  7. package/public/favicon.svg +17 -0
  8. package/public/index.html +747 -0
  9. package/public/js/core/pdf-engine.js +69 -0
  10. package/public/js/core/state.js +365 -0
  11. package/public/js/tools/dev-tools.js +1508 -0
  12. package/public/js/tools/edit-pdf.js +1618 -0
  13. package/public/js/tools/office-tools.js +221 -0
  14. package/public/js/tools/pdf-ops.js +949 -0
  15. package/public/js/tools/sign-pdf.js +198 -0
  16. package/public/manifest.json +26 -0
  17. package/public/sw.js +88 -0
  18. package/public/vendor/fonts/inter-1.woff2 +0 -0
  19. package/public/vendor/fonts/inter-2.woff2 +0 -0
  20. package/public/vendor/fonts/inter-3.woff2 +0 -0
  21. package/public/vendor/fonts/inter-4.woff2 +0 -0
  22. package/public/vendor/fonts/inter-5.woff2 +0 -0
  23. package/public/vendor/fonts/inter-6.woff2 +0 -0
  24. package/public/vendor/fonts/inter-7.woff2 +0 -0
  25. package/public/vendor/fonts/inter.css +316 -0
  26. package/public/vendor/fonts/jbmono-1.woff2 +0 -0
  27. package/public/vendor/fonts/jbmono-2.woff2 +0 -0
  28. package/public/vendor/fonts/jbmono-3.woff2 +0 -0
  29. package/public/vendor/fonts/jbmono-4.woff2 +0 -0
  30. package/public/vendor/fonts/jbmono-5.woff2 +0 -0
  31. package/public/vendor/fonts/jbmono-6.woff2 +0 -0
  32. package/public/vendor/fonts/jbmono.css +109 -0
  33. package/public/vendor/jszip.min.js +13 -0
  34. package/public/vendor/pdf-lib.min.js +16 -0
  35. package/public/vendor/pdf.min.js +22 -0
  36. package/public/vendor/pdf.worker.min.js +22 -0
  37. package/public/vendor/qrcode.min.js +1 -0
  38. package/server.js +125 -0
  39. package/start.bat +19 -0
  40. package/start.sh +12 -0
@@ -0,0 +1,221 @@
1
+ /* Foliokit — Office Tools
2
+ * Kwitansi/terbilang, Studio TTD, QR Code, Diff Checker, Utilitas Teks, Kompresor Foto.
3
+ */
4
+
5
+ // ==========================================
6
+ // 4. KWITANSI / TERBILANG
7
+ // ==========================================
8
+ function angkaTerbilang(nilai) {
9
+ nilai = Math.floor(Math.abs(nilai));
10
+ const huruf = ['', 'Satu', 'Dua', 'Tiga', 'Empat', 'Lima', 'Enam', 'Tujuh', 'Delapan', 'Sembilan', 'Sepuluh', 'Sebelas'];
11
+ if (nilai < 12) return ' ' + huruf[nilai];
12
+ if (nilai < 20) return angkaTerbilang(nilai - 10) + ' Belas';
13
+ if (nilai < 100) return angkaTerbilang(Math.floor(nilai / 10)) + ' Puluh' + angkaTerbilang(nilai % 10);
14
+ if (nilai < 200) return ' Seratus' + angkaTerbilang(nilai - 100);
15
+ if (nilai < 1000) return angkaTerbilang(Math.floor(nilai / 100)) + ' Ratus' + angkaTerbilang(nilai % 100);
16
+ if (nilai < 2000) return ' Seribu' + angkaTerbilang(nilai - 1000);
17
+ if (nilai < 1000000) return angkaTerbilang(Math.floor(nilai / 1000)) + ' Ribu' + angkaTerbilang(nilai % 1000);
18
+ if (nilai < 1000000000) return angkaTerbilang(Math.floor(nilai / 1000000)) + ' Juta' + angkaTerbilang(nilai % 1000000);
19
+ if (nilai < 1000000000000) return angkaTerbilang(Math.floor(nilai / 1000000000)) + ' Miliar' + angkaTerbilang(nilai % 1000000000);
20
+ if (nilai < 1000000000000000) return angkaTerbilang(Math.floor(nilai / 1000000000000)) + ' Triliun' + angkaTerbilang(nilai % 1000000000000);
21
+ return '';
22
+ }
23
+
24
+ function renderReceipt() {
25
+ const v = id => document.getElementById(id)?.value || '';
26
+ const no = v('rec-in-no');
27
+ const from = v('rec-in-from');
28
+ const amount = parseFloat(v('rec-in-amount')) || 0;
29
+ const desc = v('rec-in-desc');
30
+ const city = v('rec-in-city');
31
+ const signer = v('rec-in-signer');
32
+ const date = new Date().toLocaleDateString('id-ID', { day: 'numeric', month: 'long', year: 'numeric' });
33
+
34
+ const words = angkaTerbilang(amount).replace(/\s+/g, ' ').trim();
35
+ const wordResult = words ? words.charAt(0).toUpperCase() + words.slice(1) + ' Rupiah' : 'Nol Rupiah';
36
+
37
+ const set = (id, txt) => { const el = document.getElementById(id); if (el) el.textContent = txt; };
38
+ set('rec-out-no', no);
39
+ set('rec-in-words', wordResult);
40
+ set('rec-out-from', from);
41
+ set('rec-out-words', wordResult);
42
+ set('rec-out-desc', desc);
43
+ set('rec-out-amount', 'Rp ' + amount.toLocaleString('id-ID') + ',-');
44
+ set('rec-out-city-date', `${city}, ${date}`);
45
+ set('rec-out-signer', signer);
46
+ }
47
+
48
+
49
+ // ==========================================
50
+ // 9. SIGNATURE STUDIO (transparent PNG)
51
+ // ==========================================
52
+ let studioCanvas, studioCtx, studioDrawing = false, studioColor = '#18181B', studioWidth = 3;
53
+
54
+ function initSigStudio() {
55
+ if (studioCanvas) return;
56
+ studioCanvas = document.getElementById('studio-sig-canvas');
57
+ studioCtx = studioCanvas.getContext('2d');
58
+ studioCtx.lineCap = 'round';
59
+ studioCtx.lineJoin = 'round';
60
+ studioCtx.strokeStyle = studioColor;
61
+ studioCtx.lineWidth = studioWidth;
62
+ attachDraw(studioCanvas, studioCtx, () => studioDrawing, v => studioDrawing = v);
63
+ }
64
+
65
+ function clearStudioSig() { if (studioCtx) studioCtx.clearRect(0, 0, studioCanvas.width, studioCanvas.height); }
66
+ function setStudioColor(color, btn) {
67
+ studioColor = color;
68
+ if (studioCtx) studioCtx.strokeStyle = color;
69
+ document.querySelectorAll('#view-sig-studio .ink-dot').forEach(b => b.classList.remove('active'));
70
+ if (btn) btn.classList.add('active');
71
+ }
72
+ function setStudioWidth(w) { studioWidth = parseInt(w); if (studioCtx) studioCtx.lineWidth = studioWidth; }
73
+
74
+ function downloadStudioSig() {
75
+ if (!studioCanvas || !hasInk(studioCanvas)) return showToast('Gambar tanda tangan terlebih dahulu.', false);
76
+ studioCanvas.toBlob(blob => {
77
+ downloadBlob(blob, tsName('Tanda_Tangan_Transparan', 'png'));
78
+ showToast('Tanda tangan transparan diunduh.');
79
+ }, 'image/png');
80
+ }
81
+
82
+ // ==========================================
83
+ // 10. QR CODE
84
+ // ==========================================
85
+ function toggleQrFields() {
86
+ const type = document.querySelector('input[name="qr-type"]:checked')?.value || 'link';
87
+ document.getElementById('qr-fields-link').classList.toggle('hidden', type !== 'link');
88
+ document.getElementById('qr-fields-wa').classList.toggle('hidden', type !== 'wa');
89
+ document.getElementById('qr-fields-wifi').classList.toggle('hidden', type !== 'wifi');
90
+ generateQrCode();
91
+ }
92
+
93
+ let lastQrData = '';
94
+ function generateQrCode() {
95
+ const box = document.getElementById('qr-result-box');
96
+ if (!box) return;
97
+ const data = getQrData();
98
+ lastQrData = data;
99
+ box.innerHTML = '';
100
+ if (typeof QRCode !== 'undefined') {
101
+ new QRCode(box, { text: data || ' ', width: 200, height: 200, colorDark: '#18181B', colorLight: '#ffffff', correctLevel: QRCode.CorrectLevel.H });
102
+ } else {
103
+ box.innerHTML = '<div style="width:200px;height:200px;display:flex;align-items:center;justify-content:center;color:var(--muted);font-size:11px;">Pustaka QR tidak termuat</div>';
104
+ }
105
+ const label = document.getElementById('qr-text-preview');
106
+ if (label) label.textContent = data;
107
+ }
108
+
109
+ function downloadQr() {
110
+ const box = document.getElementById('qr-result-box');
111
+ const canvas = box?.querySelector('canvas');
112
+ const img = box?.querySelector('img');
113
+ if (canvas) {
114
+ canvas.toBlob(b => { downloadBlob(b, tsName('QRCode', 'png')); showToast('QR Code diunduh.'); }, 'image/png');
115
+ } else if (img) {
116
+ fetch(img.src).then(r => r.blob()).then(b => { downloadBlob(b, tsName('QRCode', 'png')); showToast('QR Code diunduh.'); });
117
+ } else {
118
+ showToast('Buat QR Code terlebih dahulu.', false);
119
+ }
120
+ }
121
+
122
+ // ==========================================
123
+ // 11. DIFF CHECKER
124
+ // ==========================================
125
+ function compareTexts() {
126
+ const t1 = document.getElementById('diff-text-1').value;
127
+ const t2 = document.getElementById('diff-text-2').value;
128
+ const box = document.getElementById('diff-result-box');
129
+ const a = t1.split(/\s+/).filter(Boolean);
130
+ const b = t2.split(/\s+/).filter(Boolean);
131
+ let html = '', i = 0, j = 0;
132
+ while (i < a.length || j < b.length) {
133
+ if (i < a.length && j < b.length && a[i] === b[j]) {
134
+ html += `<span style="color:#3F3F46;">${a[i]} </span>`; i++; j++;
135
+ } else if (i < a.length && !b.slice(j).includes(a[i])) {
136
+ html += `<span class="diff-removed">${a[i]} </span>`; i++;
137
+ } else if (j < b.length) {
138
+ html += `<span class="diff-added">${b[j]} </span>`; j++;
139
+ } else { i++; }
140
+ }
141
+ box.innerHTML = html || '<span style="color:var(--muted);">Tidak ada perbedaan terdeteksi.</span>';
142
+ showToast('Perbandingan selesai.');
143
+ }
144
+
145
+ // ==========================================
146
+ // 12. TEXT TOOLS
147
+ // ==========================================
148
+ function analyzeText() {
149
+ const text = document.getElementById('text-tool-input')?.value || '';
150
+ const words = text.trim() ? text.trim().split(/\s+/).length : 0;
151
+ const setV = (id, v) => { const el = document.getElementById(id); if (el) el.textContent = v; };
152
+ setV('stat-words', words.toLocaleString('id-ID'));
153
+ setV('stat-chars', text.length.toLocaleString('id-ID'));
154
+ setV('stat-chars-nospace', text.replace(/\s+/g, '').length.toLocaleString('id-ID'));
155
+ setV('stat-lines', (text ? text.split(/\r\n|\r|\n/).length : 0).toLocaleString('id-ID'));
156
+ setV('stat-readtime', `~${Math.ceil(words / 200)} mnt`);
157
+ }
158
+
159
+ function transformText(action) {
160
+ const input = document.getElementById('text-tool-input');
161
+ if (!input) return;
162
+ let t = input.value;
163
+ if (action === 'upper') t = t.toUpperCase();
164
+ else if (action === 'lower') t = t.toLowerCase();
165
+ else if (action === 'title') t = t.replace(/\w\S*/g, w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase());
166
+ else if (action === 'clean-spaces') t = t.replace(/[ \t]+/g, ' ').replace(/^[ \t]+|[ \t]+$/gm, '');
167
+ else if (action === 'clean-lines') t = t.replace(/(\r\n|\r|\n){2,}/g, '\n');
168
+ input.value = t;
169
+ analyzeText();
170
+ showToast('Teks diperbarui.');
171
+ }
172
+
173
+ function copyAnalyzedText() {
174
+ const input = document.getElementById('text-tool-input');
175
+ if (!input || !input.value) return showToast('Belum ada teks.', false);
176
+ navigator.clipboard.writeText(input.value);
177
+ showToast('Teks disalin ke papan klip.');
178
+ }
179
+
180
+ // ==========================================
181
+ // 13. IMAGE TOOLS
182
+ // ==========================================
183
+ function loadImgFile(file) {
184
+ if (!file) return;
185
+ loadedImgFile = file;
186
+ const reader = new FileReader();
187
+ reader.onload = e => {
188
+ const preview = document.getElementById('img-source-preview');
189
+ preview.src = e.target.result;
190
+ preview.classList.remove('hidden');
191
+ document.getElementById('img-source-info').textContent = `${file.name} • ${fmtSize(file.size)}`;
192
+ };
193
+ reader.readAsDataURL(file);
194
+ }
195
+
196
+ function handleImgSelect(e) { loadImgFile(e.target.files[0]); }
197
+
198
+ function processImageTool() {
199
+ if (!loadedImgFile) return showToast('Pilih berkas gambar terlebih dahulu.', false);
200
+ const quality = parseFloat(document.getElementById('img-quality-slider').value);
201
+ const format = document.getElementById('img-target-format').value;
202
+ const img = new Image();
203
+ const reader = new FileReader();
204
+ reader.onload = evt => {
205
+ img.onload = () => {
206
+ const canvas = document.createElement('canvas');
207
+ canvas.width = img.width; canvas.height = img.height;
208
+ const ctx = canvas.getContext('2d');
209
+ ctx.drawImage(img, 0, 0);
210
+ canvas.toBlob(blob => {
211
+ const ext = format === 'image/png' ? 'png' : format === 'image/webp' ? 'webp' : 'jpg';
212
+ const name = loadedImgFile.name.replace(/\.[^/.]+$/, '') + `_hasil.${ext}`;
213
+ downloadBlob(blob, name);
214
+ showToast(`Gambar disimpan. Ukuran baru: ${fmtSize(blob.size)}.`);
215
+ }, format, quality);
216
+ };
217
+ img.src = evt.target.result;
218
+ };
219
+ reader.readAsDataURL(loadedImgFile);
220
+ }
221
+