Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
579 lines (532 loc) · 32.8 KB
/
Copy pathindex.html
File metadata and controls
579 lines (532 loc) · 32.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Material You Notes Ultimate</title>
<!-- Libraries -->
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Quill Editor -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<script src="https://cdn.quilljs.com/1.3.6/quill.min.js"></script>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&family=Roboto:wght@300;400;500;700&family=JetBrains+Mono:wght@400&display=swap" rel="stylesheet">
<style>
/* Global Styles */
body {
font-family: 'Roboto', sans-serif;
-webkit-tap-highlight-color: transparent;
overscroll-behavior-y: none;
}
.font-sans-display { font-family: 'Google Sans', 'Roboto', sans-serif; }
/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(156, 163, 175, 0.3); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(156, 163, 175, 0.5); }
/* Animated Background Blobs */
.blob-cont {
position: fixed; top: 0; left: 0; width: 100%; height: 100vh;
z-index: -1; overflow: hidden; pointer-events: none;
background-color: var(--bg-color, #fdfcff);
transition: background-color 0.5s ease;
}
.dark .blob-cont { --bg-color: #1a1c1e; }
.blob {
position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5;
animation: moveBlob 25s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
mix-blend-mode: multiply;
}
.dark .blob { opacity: 0.25; mix-blend-mode: screen; filter: blur(100px); }
@keyframes moveBlob {
0% { transform: translate(0, 0) scale(1) rotate(0deg); }
50% { transform: translate(10%, 10%) scale(1.1) rotate(90deg); }
100% { transform: translate(-10%, -5%) scale(0.9) rotate(180deg); }
}
/* Stagger Animation */
@keyframes popIn {
0% { opacity: 0; transform: scale(0.8) translateY(40px); }
100% { opacity: 1; transform: scale(1) translateY(0); }
}
.stagger-item { opacity: 0; animation: popIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
/* Quill Overrides */
.ql-container.ql-snow { border: none !important; font-family: 'Roboto', sans-serif; font-size: 1.125rem; }
.ql-editor { padding: 1rem 1.5rem; min-height: 60vh; line-height: 1.75; }
.ql-editor.ql-blank::before { color: #9ca3af; font-style: normal; opacity: 0.6; }
.dark .ql-editor { color: #e2e2e6; }
.dark .ql-editor.ql-blank::before { color: #9ca3af; }
/* Hide scrollbar utility */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
/* Print Styles */
@media print {
@page { margin: 2cm; }
body { background: white !important; color: black !important; -webkit-print-color-adjust: exact; }
.no-print, header, button, .blob-cont, .ql-toolbar, .fixed, .sticky { display: none !important; }
.ql-editor { padding: 0 !important; overflow: visible !important; min-height: auto !important; padding-bottom: 0 !important; }
#root > div > div { height: auto !important; display: block !important; }
.dark .ql-editor { color: black !important; }
}
</style>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: { sans: ['Roboto', 'sans-serif'], display: ['Google Sans', 'Roboto', 'sans-serif'] },
colors: { surface: { light: '#fdfcff', dark: '#1a1c1e' } },
boxShadow: {
'elevation-1': '0px 1px 2px 0px rgba(0,0,0,0.3), 0px 1px 3px 1px rgba(0,0,0,0.15)',
'elevation-3': '0px 4px 8px 3px rgba(0,0,0,0.15), 0px 1px 3px 0px rgba(0,0,0,0.3)',
}
}
}
}
</script>
<script type="importmap">
{
"imports": {
"react": "https://aistudiocdn.com/react@^19.2.1",
"react-dom/": "https://aistudiocdn.com/react-dom@^19.2.1/",
"react/": "https://aistudiocdn.com/react@^19.2.1/",
"lucide-react": "https://aistudiocdn.com/lucide-react@^0.555.0"
}
}
</script>
<link rel="stylesheet" href="/index.css">
</head>
<body class="bg-[#fdfcff] dark:bg-[#1a1c1e] text-[#1a1c1e] dark:text-[#e2e2e6] min-h-screen overflow-hidden selection:bg-blue-200 dark:selection:bg-blue-900/50">
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect, useMemo, useCallback, useRef } = React;
// --- ICONS (SVG Components) ---
const Icon = ({ name, size = 24, className = "", strokeWidth = 2, fill = "none" }) => {
const paths = {
plus: <path d="M12 5v14M5 12h14" />,
search: <><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></>,
arrowLeft: <path d="m12 19-7-7 7-7M19 12H5"/>,
moreVertical: <><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></>,
menu: <path d="M4 12h16M4 6h16M4 18h16" />,
palette: <circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12c0 .667.083 1.32.242 1.947C3.385 18.356 7.425 22 12 22Z"/><path d="M13 14c-1.333-2-2.333-2-3 0"/>,
trash2: <path d="M3 6h18M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2M10 11v6M14 11v6"/>,
archive: <rect width="20" height="5" x="2" y="3" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/>,
moon: <path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>,
sun: <circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>,
pin: <path d="m19 21-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2Z"/>, // using bookmark icon for pin visual preference in keeping
check: <path d="M20 6 9 17l-5-5"/>,
x: <path d="M18 6 6 18M6 6l12 12"/>,
grid: <rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/>,
layoutList: <rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/><path d="M14 4h7M14 9h7M14 15h7M14 20h7"/>,
bold: <path d="M14 12a4 4 0 0 0 0-8H6v8"/><path d="M15 20a4 4 0 0 0 0-8H6v8Z"/>,
italic: <line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/>,
underline: <path d="M6 3v7a6 6 0 0 0 6 6 6 6 0 0 0 6-6V3"/><line x1="4" x2="20" y1="21" y2="21"/>,
strikethrough: <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><line x1="4" x2="20" y1="12" y2="12"/>,
undo: <path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/>,
redo: <path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"/>,
list: <line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><line x1="3" x2="3.01" y1="6" y2="6"/><line x1="3" x2="3.01" y1="12" y2="12"/><line x1="3" x2="3.01" y1="18" y2="18"/>,
listOrdered: <line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>,
checkSquare: <polyline points="9 11 12 14 22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>,
alignLeft: <line x1="17" x2="3" y1="6" y2="6"/><line x1="21" x2="3" y1="12" y2="12"/><line x1="17" x2="3" y1="18" y2="18"/>,
alignCenter: <line x1="17" x2="7" y1="6" y2="6"/><line x1="19" x2="5" y1="12" y2="12"/><line x1="17" x2="7" y1="18" y2="18"/>,
h1: <path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="m17 12 3-2v8"/>,
h2: <path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-5 4-9V5a1 1 0 0 0-1-1h-2"/>,
quote: <path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1Z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1Z"/>,
code: <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>,
keyboard: <rect width="20" height="16" x="2" y="4" rx="2" ry="2"/><path d="M6 8h.001"/><path d="M10 8h.001"/><path d="M14 8h.001"/><path d="M18 8h.001"/><path d="M6 12h.001"/><path d="M10 12h.001"/><path d="M14 12h.001"/><path d="M18 12h.001"/><path d="M7 16h10"/>,
type: <polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/>,
fileText: <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/>,
};
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size}
height={size}
viewBox="0 0 24 24"
fill={fill}
stroke="currentColor"
strokeWidth={strokeWidth}
strokeLinecap="round"
strokeLinejoin="round"
className={className}
>
{paths[name] || <circle cx="12" cy="12" r="10" />}
</svg>
);
};
// --- UTILS ---
const generateId = () => Date.now().toString(36) + Math.random().toString(36).substring(2);
const formatDate = (timestamp) => {
const date = new Date(timestamp);
const now = new Date();
if (date.getFullYear() === now.getFullYear()) {
return date.toLocaleDateString([], { month: 'short', day: 'numeric' });
}
return date.toLocaleDateString([], { year: 'numeric', month: 'short', day: 'numeric' });
};
const getNoteColorClasses = (color, isDark) => {
const colors = {
default: { light: 'bg-white', dark: 'bg-[#1e1f21]', border: isDark ? 'border-gray-700' : 'border-gray-200' },
red: { light: 'bg-[#ffdad6]', dark: 'bg-[#93000a]', border: 'border-transparent' },
orange: { light: 'bg-[#ffdbcc]', dark: 'bg-[#5c1900]', border: 'border-transparent' },
yellow: { light: 'bg-[#ffeea1]', dark: 'bg-[#574500]', border: 'border-transparent' },
green: { light: 'bg-[#bcefa0]', dark: 'bg-[#185200]', border: 'border-transparent' },
cyan: { light: 'bg-[#bce9ff]', dark: 'bg-[#004e6f]', border: 'border-transparent' },
blue: { light: 'bg-[#d7e3ff]', dark: 'bg-[#00468c]', border: 'border-transparent' },
purple: { light: 'bg-[#e9ddff]', dark: 'bg-[#4d2d89]', border: 'border-transparent' },
pink: { light: 'bg-[#ffd9e3]', dark: 'bg-[#630b32]', border: 'border-transparent' },
brown: { light: 'bg-[#f0dbd4]', dark: 'bg-[#562214]', border: 'border-transparent' },
gray: { light: 'bg-[#e3e2e6]', dark: 'bg-[#444746]', border: 'border-transparent' },
};
const theme = colors[color] || colors.default;
return `${isDark ? theme.dark : theme.light} ${isDark ? theme.border : theme.border}`;
};
const getNoteShape = (id, isPinned) => {
if (isPinned) return 'rounded-3xl';
const shapes = [
'rounded-3xl',
'rounded-tl-xl rounded-tr-[3rem] rounded-bl-[3rem] rounded-br-xl',
'rounded-tl-[3rem] rounded-tr-xl rounded-bl-xl rounded-br-[3rem]',
'rounded-t-[2.5rem] rounded-b-xl',
'rounded-b-[2.5rem] rounded-t-xl',
'rounded-[2rem]'
];
const sum = id.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
return shapes[sum % shapes.length];
};
// --- COMPONENTS ---
// Rich Text Editor with Toggle & Auto-Scroll
const RichTextEditor = ({ initialContent, onChange, placeholder, isDark, readOnly }) => {
const editorRef = useRef(null);
const quillInstance = useRef(null);
const [activeFormats, setActiveFormats] = useState({});
const toolbarId = useRef(`toolbar-${Math.random().toString(36).substr(2, 9)}`);
const ensureCursorVisible = () => {
if (!quillInstance.current || !editorRef.current) return;
setTimeout(() => {
const selection = quillInstance.current.getSelection();
if (!selection) return;
const bounds = quillInstance.current.getBounds(selection.index);
const editorContainer = editorRef.current;
const toolbarHeight = 100;
const offset = 60;
const rect = editorContainer.getBoundingClientRect();
const cursorBottom = rect.top + bounds.top + bounds.height;
const visibleHeight = window.innerHeight - toolbarHeight;
if (cursorBottom > visibleHeight - offset) {
editorContainer.scrollBy({ top: (cursorBottom - visibleHeight) + offset, behavior: 'smooth' });
}
}, 100);
};
useEffect(() => {
if (!editorRef.current || quillInstance.current) return;
quillInstance.current = new Quill(editorRef.current, {
theme: 'snow',
placeholder: placeholder || 'Type something...',
readOnly: readOnly,
modules: {
toolbar: { container: `#${toolbarId.current}`, handlers: {} },
history: { delay: 1000, maxStack: 500, userOnly: true }
}
});
if (initialContent) quillInstance.current.clipboard.dangerouslyPasteHTML(0, initialContent);
quillInstance.current.on('text-change', () => {
const html = editorRef.current.querySelector('.ql-editor').innerHTML;
const text = quillInstance.current.getText();
onChange(html, text);
ensureCursorVisible();
});
quillInstance.current.on('selection-change', (range) => {
if (range) {
setActiveFormats(quillInstance.current.getFormat(range));
ensureCursorVisible();
}
});
// Massive bottom padding fix
const editorEl = editorRef.current.querySelector('.ql-editor');
if (editorEl) editorEl.style.paddingBottom = '50vh';
}, []);
const TBtn = ({ format, value, icon, active, onClick }) => {
const handleAction = (e) => {
e.preventDefault(); e.stopPropagation();
if (onClick) { onClick(); return; }
const quill = quillInstance.current;
if (!quill) return;
const current = quill.getFormat();
if (format === 'header' || format === 'list' || format === 'color' || format === 'background' || format === 'align') {
if (current[format] === value) quill.format(format, false);
else quill.format(format, value);
} else {
quill.format(format, !current[format]);
}
requestAnimationFrame(() => setActiveFormats(quill.getFormat(quill.getSelection())));
};
let isActive = active;
if (!isActive) {
if (format === 'header') isActive = activeFormats.header === value;
else if (format === 'list') isActive = activeFormats.list === value;
else if (format === 'align') isActive = activeFormats.align === value;
else if (format === 'color') isActive = activeFormats.color === value;
else if (format === 'background') isActive = activeFormats.background === value;
else if (format) isActive = !!activeFormats[format];
}
return (
<div onMouseDown={handleAction} className={`flex items-center justify-center min-w-[44px] h-[44px] rounded-full cursor-pointer transition-all duration-200 flex-shrink-0 ${isActive ? 'bg-blue-200 text-blue-900 dark:bg-blue-600 dark:text-white transform scale-105 ring-2 ring-blue-300' : 'text-gray-600 dark:text-gray-400 hover:bg-black/5 dark:hover:bg-white/10'}`}>
<Icon name={icon} size={20} strokeWidth={isActive ? 2.5 : 2} />
</div>
);
};
return (
<div className="flex flex-col h-full relative group">
<div ref={editorRef} className="flex-grow overflow-y-auto scroll-smooth" style={{border:'none'}} onClick={ensureCursorVisible}></div>
{!readOnly && (
<div className="sticky bottom-4 left-0 right-0 z-50 flex justify-center w-full px-4 pointer-events-none">
<div id={toolbarId.current} className="pointer-events-auto flex items-center gap-1 overflow-x-auto no-scrollbar bg-[#f0f4f9]/95 dark:bg-[#2b2d31]/95 backdrop-blur-xl border border-white/20 shadow-elevation-3 rounded-[28px] p-2 max-w-full">
<TBtn icon="undo" onClick={() => quillInstance.current.history.undo()} />
<TBtn icon="redo" onClick={() => quillInstance.current.history.redo()} />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="bold" format="bold" />
<TBtn icon="italic" format="italic" />
<TBtn icon="underline" format="underline" />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="h1" format="header" value={1} />
<TBtn icon="h2" format="header" value={2} />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="list" format="list" value="bullet" />
<TBtn icon="listOrdered" format="list" value="ordered" />
<TBtn icon="checkSquare" format="list" value="check" />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="quote" format="blockquote" />
<TBtn icon="code" format="code-block" />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="palette" format="color" value="red" />
<TBtn icon="type" format="background" value="yellow" />
<div className="w-px h-6 bg-gray-300 dark:bg-gray-700 mx-1 opacity-50"></div>
<TBtn icon="alignLeft" format="align" value="" />
<TBtn icon="alignCenter" format="align" value="center" />
<div className="ml-2 pl-2 border-l border-gray-300"><TBtn icon="keyboard" onClick={() => editorRef.current.querySelector('.ql-editor').blur()} /></div>
</div>
</div>
)}
</div>
);
};
// Note Card with Fixed Gesture Logic
const NoteCard = ({ note, onOpen, onLongPress, isSelected, isSelectionMode, isDark, onArchive, onDelete }) => {
const [isPressed, setIsPressed] = useState(false);
const touchStartX = useRef(0);
const touchStartY = useRef(0);
const longPressTimer = useRef(null);
const isScrolling = useRef(false);
const handleTouchStart = (e) => {
touchStartX.current = e.touches[0].clientX;
touchStartY.current = e.touches[0].clientY;
isScrolling.current = false;
setIsPressed(true);
longPressTimer.current = setTimeout(() => {
if (!isScrolling.current) {
onLongPress();
setIsPressed(false);
if (navigator.vibrate) navigator.vibrate(50);
}
}, 600);
};
const handleTouchMove = (e) => {
const diffX = Math.abs(e.touches[0].clientX - touchStartX.current);
const diffY = Math.abs(e.touches[0].clientY - touchStartY.current);
if (diffY > 10 || diffX > 10) { // 10px threshold
isScrolling.current = true;
clearTimeout(longPressTimer.current);
setIsPressed(false);
}
};
const handleTouchEnd = (e) => {
clearTimeout(longPressTimer.current);
setIsPressed(false);
if (!isScrolling.current) {
const diffX = e.changedTouches[0].clientX - touchStartX.current;
if (!isSelectionMode && Math.abs(diffX) > 80) { // Swipe
if (diffX > 0 && onArchive) onArchive();
if (diffX < 0 && onDelete) onDelete();
} else {
// Click
if(isSelectionMode) onLongPress();
else onOpen();
}
}
};
return (
<div
className={`relative mb-4 stagger-item transition-transform duration-200 ${isPressed ? 'scale-95' : 'scale-100'}`}
onTouchStart={handleTouchStart} onTouchMove={handleTouchMove} onTouchEnd={handleTouchEnd}
onClick={(e) => { if(e.detail === 0) return; if(isSelectionMode) onLongPress(); else onOpen(); }}
>
<div className={`${getNoteShape(note.id, note.isPinned)} ${getNoteColorClasses(note.color, isDark)} p-5 overflow-hidden relative transition-shadow ${isSelected ? 'ring-4 ring-blue-400 z-10' : 'shadow-sm'}`}>
<div className="flex justify-between items-start mb-2">
<h3 className="font-sans-display font-medium text-lg leading-snug line-clamp-2">{note.title || <span className="italic opacity-50">Untitled</span>}</h3>
{note.isPinned && <Icon name="pin" size={14} className="opacity-60 ml-2" fill="currentColor" />}
</div>
<div className="text-sm opacity-80 line-clamp-4 max-h-[100px]" dangerouslySetInnerHTML={{__html: note.content || 'Empty'}}></div>
{isSelected && <div className="absolute inset-0 bg-blue-500/20 backdrop-blur-[1px] flex items-center justify-center"><div className="bg-blue-500 text-white rounded-full p-3"><Icon name="check" strokeWidth={3} /></div></div>}
</div>
</div>
);
};
const MasonryGrid = ({ notes, columns = 2, renderItem }) => {
const cols = Array.from({ length: columns }, () => []);
notes.forEach((n, i) => cols[i % columns].push(n));
return (
<div className="flex gap-4 items-start w-full">
{cols.map((colNotes, i) => <div key={i} className="flex-1 flex flex-col gap-0 w-full min-w-0">{colNotes.map(renderItem)}</div>)}
</div>
);
};
// --- MAIN APP ---
const App = () => {
const [notes, setNotes] = useState([]);
const [isDark, setIsDark] = useState(false);
const [viewMode, setViewMode] = useState('list');
const [currentView, setCurrentView] = useState('notes');
const [search, setSearch] = useState('');
const [selectedId, setSelectedId] = useState(null);
const [selectedIds, setSelectedIds] = useState(new Set());
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const [cols, setCols] = useState(2);
const [snackbar, setSnackbar] = useState(null);
// Load
useEffect(() => {
const saved = localStorage.getItem('notes_db_v3');
if (saved) setNotes(JSON.parse(saved));
else {
const init = { id: generateId(), title: 'Welcome', content: '<p>Welcome to <b>Material You Notes</b>. Try swiping right to archive!</p>', plainText: 'Welcome', createdAt: Date.now(), updatedAt: Date.now(), color: 'blue', isPinned: true, isArchived: false, isTrashed: false };
setNotes([init]);
}
setIsDark(localStorage.getItem('theme') === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches);
const handleResize = () => setCols(window.innerWidth > 1024 ? 3 : (window.innerWidth > 600 ? 2 : 2)); // Always 2 cols on mobile for masonry look
handleResize();
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
// Save
useEffect(() => { localStorage.setItem('notes_db_v3', JSON.stringify(notes)); }, [notes]);
useEffect(() => {
localStorage.setItem('theme', isDark ? 'dark' : 'light');
document.documentElement.classList.toggle('dark', isDark);
}, [isDark]);
const createNote = () => {
const newNote = { id: generateId(), title: '', content: '', plainText: '', createdAt: Date.now(), updatedAt: Date.now(), color: 'default', isPinned: false, isArchived: false, isTrashed: false };
setNotes([newNote, ...notes]);
setSelectedId(newNote.id);
setViewMode('editor');
};
const updateNote = (id, updates) => setNotes(prev => prev.map(n => n.id === id ? { ...n, ...updates, updatedAt: Date.now() } : n));
const filtered = useMemo(() => {
let data = notes.filter(n => {
if (search) return n.title.toLowerCase().includes(search.toLowerCase()) || n.plainText.toLowerCase().includes(search.toLowerCase());
if (currentView === 'trash') return n.isTrashed;
if (currentView === 'archive') return n.isArchived && !n.isTrashed;
return !n.isArchived && !n.isTrashed;
});
return data.sort((a, b) => (a.isPinned === b.isPinned) ? b.updatedAt - a.updatedAt : (a.isPinned ? -1 : 1));
}, [notes, currentView, search]);
const bulkAction = (action, val) => {
const ids = Array.from(selectedIds);
if (action === 'delete') {
if (currentView === 'trash') setNotes(prev => prev.filter(n => !ids.includes(n.id)));
else setNotes(prev => prev.map(n => ids.includes(n.id) ? { ...n, isTrashed: true } : n));
} else if (action === 'archive') {
setNotes(prev => prev.map(n => ids.includes(n.id) ? { ...n, isArchived: !n.isArchived } : n));
} else if (action === 'pin') {
setNotes(prev => prev.map(n => ids.includes(n.id) ? { ...n, isPinned: !n.isPinned } : n));
} else if (action === 'color') {
setNotes(prev => prev.map(n => ids.includes(n.id) ? { ...n, color: val } : n));
}
setSelectedIds(new Set());
setSnackbar('Action completed');
setTimeout(() => setSnackbar(null), 3000);
};
if (viewMode === 'editor' && selectedId) {
const note = notes.find(n => n.id === selectedId);
if (!note) { setViewMode('list'); return null; }
const bgClass = getNoteColorClasses(note.color, isDark).split(' ')[0];
return (
<div className={`h-screen flex flex-col ${bgClass} transition-colors`}>
<div className="flex items-center justify-between p-3 backdrop-blur-md border-b border-black/5 dark:border-white/5">
<button onClick={() => setViewMode('list')} className="p-2 rounded-full hover:bg-black/10"><Icon name="arrowLeft" /></button>
<div className="flex gap-2">
<button onClick={() => updateNote(note.id, { isPinned: !note.isPinned })} className={`p-2 rounded-full ${note.isPinned ? 'bg-blue-200 dark:bg-blue-900' : 'hover:bg-black/10'}`}><Icon name="pin" /></button>
<button onClick={() => updateNote(note.id, { isArchived: !note.isArchived })} className="p-2 rounded-full hover:bg-black/10"><Icon name="archive" /></button>
<button onClick={() => {
const colors = ['default', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'pink', 'brown', 'gray'];
updateNote(note.id, { color: colors[(colors.indexOf(note.color) + 1) % colors.length] });
}} className="p-2 rounded-full hover:bg-black/10"><Icon name="palette" /></button>
<button onClick={() => { window.print(); }} className="p-2 rounded-full hover:bg-black/10 no-print"><Icon name="printer" size={20} /></button>
</div>
</div>
<div className="flex-1 flex flex-col relative overflow-hidden">
<input value={note.title} onChange={e => updateNote(note.id, { title: e.target.value })} placeholder="Title" className="bg-transparent text-3xl font-sans-display px-6 py-4 focus:outline-none" />
<div className="flex-1 relative">
<RichTextEditor initialContent={note.content} isDark={isDark} onChange={(h, t) => updateNote(note.id, { content: h, plainText: t })} />
</div>
</div>
</div>
);
}
return (
<div className={`min-h-screen transition-colors ${isDark ? 'bg-[#1a1c1e] text-[#e2e2e6]' : 'bg-[#fdfcff] text-[#1a1c1e]'}`}>
<div className="blob-cont"><div className="blob bg-rose-300 dark:bg-rose-900/30 w-[40vw] h-[40vw] left-[10%] top-[10%]"></div><div className="blob bg-blue-300 dark:bg-blue-900/30 w-[40vw] h-[40vw] right-[10%] bottom-[10%] animation-delay-2000"></div></div>
<header className={`fixed top-0 inset-x-0 z-30 p-3 transition-all ${selectedIds.size > 0 ? '' : (window.scrollY > 10 ? 'bg-surface-light/80 dark:bg-surface-dark/80 backdrop-blur-xl' : '')}`}>
{selectedIds.size > 0 ? (
<div className="bg-blue-100 dark:bg-blue-900/50 rounded-full px-4 py-2 flex justify-between items-center animate-slide-up">
<div className="flex gap-4 items-center"><button onClick={() => setSelectedIds(new Set())}><Icon name="x" /></button><span className="font-bold">{selectedIds.size}</span></div>
<div className="flex gap-1">
<button onClick={() => bulkAction('pin')} className="p-2"><Icon name="pin" /></button>
<button onClick={() => bulkAction('archive')} className="p-2"><Icon name="archive" /></button>
<button onClick={() => bulkAction('delete')} className="p-2"><Icon name="trash2" /></button>
</div>
</div>
) : (
<div className="bg-[#eff1f4]/80 dark:bg-[#2b2d31]/80 backdrop-blur-md rounded-full px-4 py-3 shadow-sm border border-white/20 flex gap-3 items-center">
<button onClick={() => setIsDrawerOpen(true)}><Icon name="menu" /></button>
<input placeholder={`Search ${currentView}...`} value={search} onChange={e => setSearch(e.target.value)} className="bg-transparent flex-1 outline-none font-sans-display" />
<button onClick={() => setIsDark(!isDark)}>{isDark ? <Icon name="sun" /> : <Icon name="moon" />}</button>
<div className="w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center font-bold text-xs">M</div>
</div>
)}
</header>
<div className={`fixed inset-0 bg-black/50 z-40 transition-opacity ${isDrawerOpen ? 'opacity-100' : 'opacity-0 pointer-events-none'}`} onClick={() => setIsDrawerOpen(false)}></div>
<div className={`fixed inset-y-4 left-4 w-72 bg-surface-light dark:bg-surface-dark z-50 rounded-[2rem] shadow-2xl p-4 transition-transform duration-300 ${isDrawerOpen ? 'translate-x-0' : '-translate-x-[120%]'}`}>
<h2 className="text-2xl font-sans-display p-4 mb-2">Notes</h2>
{['notes', 'archive', 'trash'].map(v => (
<button key={v} onClick={() => { setCurrentView(v); setIsDrawerOpen(false); }} className={`w-full text-left px-6 py-4 rounded-full flex gap-4 items-center mb-1 capitalize ${currentView === v ? 'bg-blue-100 dark:bg-blue-900/40 text-blue-900 dark:text-blue-100 font-bold' : 'hover:bg-black/5'}`}>
<Icon name={v === 'notes' ? 'fileText' : (v === 'archive' ? 'archive' : 'trash2')} /> {v}
</button>
))}
</div>
<main className="pt-24 px-4 pb-24 max-w-5xl mx-auto">
<MasonryGrid notes={filtered} columns={cols} renderItem={note => (
<NoteCard key={note.id} note={note} isDark={isDark} isSelected={selectedIds.has(note.id)} isSelectionMode={selectedIds.size > 0}
onOpen={() => { setSelectedId(note.id); setViewMode('editor'); }}
onLongPress={() => {
const s = new Set(selectedIds);
if (s.has(note.id)) s.delete(note.id); else s.add(note.id);
setSelectedIds(s);
}}
onArchive={() => { updateNote(note.id, { isArchived: !note.isArchived }); }}
onDelete={() => { updateNote(note.id, { isTrashed: !note.isTrashed }); }}
/>
)} />
</main>
<button onClick={createNote} className="fixed bottom-8 right-6 w-14 h-14 bg-blue-200 dark:bg-blue-700 text-blue-900 dark:text-white rounded-2xl shadow-elevation-3 flex items-center justify-center hover:scale-110 transition-transform"><Icon name="plus" size={28} strokeWidth={3}/></button>
{snackbar && <div className="fixed bottom-6 left-1/2 -translate-x-1/2 bg-[#303030] text-white px-6 py-3 rounded-full shadow-lg z-50 animate-fade-in">{snackbar}</div>}
</div>
);
};
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
<script type="module" src="/index.tsx"></script>
</body>
</html>