draftly 1.0.7 → 2.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.
Files changed (79) hide show
  1. package/README.md +12 -0
  2. package/dist/chunk-3T55CBNZ.cjs +33 -0
  3. package/dist/chunk-3T55CBNZ.cjs.map +1 -0
  4. package/dist/chunk-5MC4T7JH.cjs +58 -0
  5. package/dist/chunk-5MC4T7JH.cjs.map +1 -0
  6. package/dist/{chunk-KBQDZ5IW.cjs → chunk-CLW73JRX.cjs} +100 -75
  7. package/dist/chunk-CLW73JRX.cjs.map +1 -0
  8. package/dist/{chunk-72ZYRGRT.cjs → chunk-EQUQHE2E.cjs} +30 -26
  9. package/dist/chunk-EQUQHE2E.cjs.map +1 -0
  10. package/dist/{chunk-HPSMS2WB.js → chunk-I563H35S.js} +101 -75
  11. package/dist/chunk-I563H35S.js.map +1 -0
  12. package/dist/chunk-IAXF4SJL.js +55 -0
  13. package/dist/chunk-IAXF4SJL.js.map +1 -0
  14. package/dist/chunk-JF3WXXMJ.js +31 -0
  15. package/dist/chunk-JF3WXXMJ.js.map +1 -0
  16. package/dist/{chunk-N3WL3XPB.js → chunk-NRPI5O6Y.js} +2603 -604
  17. package/dist/chunk-NRPI5O6Y.js.map +1 -0
  18. package/dist/{chunk-2B3A3VSQ.cjs → chunk-OMFUE4AQ.cjs} +2642 -622
  19. package/dist/chunk-OMFUE4AQ.cjs.map +1 -0
  20. package/dist/{chunk-DFQYXFOP.js → chunk-TD3L5C45.js} +28 -3
  21. package/dist/chunk-TD3L5C45.js.map +1 -0
  22. package/dist/{chunk-CG4M4TC7.js → chunk-UCHBDJ4R.js} +26 -22
  23. package/dist/chunk-UCHBDJ4R.js.map +1 -0
  24. package/dist/{chunk-KDEDLC3D.cjs → chunk-W75QUUQC.cjs} +29 -2
  25. package/dist/chunk-W75QUUQC.cjs.map +1 -0
  26. package/dist/{draftly-BLnx3uGX.d.cts → draftly-BBL-AdOl.d.cts} +5 -1
  27. package/dist/{draftly-BLnx3uGX.d.ts → draftly-BBL-AdOl.d.ts} +5 -1
  28. package/dist/editor/index.cjs +22 -14
  29. package/dist/editor/index.d.cts +2 -1
  30. package/dist/editor/index.d.ts +2 -1
  31. package/dist/editor/index.js +2 -2
  32. package/dist/index.cjs +65 -39
  33. package/dist/index.d.cts +6 -3
  34. package/dist/index.d.ts +6 -3
  35. package/dist/index.js +6 -4
  36. package/dist/lib/index.cjs +12 -0
  37. package/dist/lib/index.cjs.map +1 -0
  38. package/dist/lib/index.d.cts +16 -0
  39. package/dist/lib/index.d.ts +16 -0
  40. package/dist/lib/index.js +3 -0
  41. package/dist/lib/index.js.map +1 -0
  42. package/dist/plugins/index.cjs +27 -17
  43. package/dist/plugins/index.d.cts +180 -10
  44. package/dist/plugins/index.d.ts +180 -10
  45. package/dist/plugins/index.js +5 -3
  46. package/dist/preview/index.cjs +16 -11
  47. package/dist/preview/index.d.cts +19 -4
  48. package/dist/preview/index.d.ts +19 -4
  49. package/dist/preview/index.js +3 -2
  50. package/package.json +8 -1
  51. package/src/editor/draftly.ts +30 -27
  52. package/src/editor/plugin.ts +5 -1
  53. package/src/editor/theme.ts +1 -0
  54. package/src/editor/utils.ts +33 -0
  55. package/src/index.ts +5 -4
  56. package/src/lib/index.ts +2 -0
  57. package/src/lib/input-handler.ts +45 -0
  58. package/src/plugins/code-plugin.theme.ts +426 -0
  59. package/src/plugins/code-plugin.ts +810 -561
  60. package/src/plugins/emoji-plugin.ts +140 -0
  61. package/src/plugins/index.ts +63 -57
  62. package/src/plugins/inline-plugin.ts +305 -291
  63. package/src/plugins/math-plugin.ts +12 -0
  64. package/src/plugins/table-plugin.ts +1759 -0
  65. package/src/preview/context.ts +4 -1
  66. package/src/preview/css-generator.ts +14 -1
  67. package/src/preview/index.ts +9 -1
  68. package/src/preview/preview.ts +2 -1
  69. package/src/preview/renderer.ts +21 -20
  70. package/src/preview/syntax-theme.ts +110 -0
  71. package/src/preview/types.ts +14 -0
  72. package/dist/chunk-2B3A3VSQ.cjs.map +0 -1
  73. package/dist/chunk-72ZYRGRT.cjs.map +0 -1
  74. package/dist/chunk-CG4M4TC7.js.map +0 -1
  75. package/dist/chunk-DFQYXFOP.js.map +0 -1
  76. package/dist/chunk-HPSMS2WB.js.map +0 -1
  77. package/dist/chunk-KBQDZ5IW.cjs.map +0 -1
  78. package/dist/chunk-KDEDLC3D.cjs.map +0 -1
  79. package/dist/chunk-N3WL3XPB.js.map +0 -1
@@ -0,0 +1,426 @@
1
+ import { createTheme } from "../editor";
2
+
3
+ /** Shared theme styles for editor + preview code blocks. */
4
+ export const codePluginTheme = createTheme({
5
+ default: {
6
+ // Inline code
7
+ ".cm-draftly-code-inline": {
8
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
9
+ fontSize: "0.9rem",
10
+ backgroundColor: "rgba(0, 0, 0, 0.05)",
11
+ padding: "0.1rem 0.25rem",
12
+ border: "1px solid var(--color-border)",
13
+ borderRadius: "3px",
14
+ },
15
+
16
+ // Fenced code block lines
17
+ ".cm-draftly-code-block-line": {
18
+ "--radius": "0.375rem",
19
+
20
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
21
+ fontSize: "0.9rem",
22
+ backgroundColor: "rgba(0, 0, 0, 0.03)",
23
+ padding: "0 1rem !important",
24
+ lineHeight: "1.5",
25
+ borderLeft: "1px solid var(--color-border)",
26
+ borderRight: "1px solid var(--color-border)",
27
+ },
28
+
29
+ // First line of code block
30
+ ".cm-draftly-code-block-line-start": {
31
+ borderTopLeftRadius: "var(--radius)",
32
+ borderTopRightRadius: "var(--radius)",
33
+ position: "relative",
34
+ overflow: "hidden",
35
+ borderTop: "1px solid var(--color-border)",
36
+ paddingBottom: "0.5rem !important",
37
+ },
38
+
39
+ // Remove top radius when header is present
40
+ ".cm-draftly-code-block-has-header": {
41
+ padding: "0 !important",
42
+ paddingBottom: "0.5rem !important",
43
+ },
44
+
45
+ // Code block header widget
46
+ ".cm-draftly-code-header": {
47
+ display: "flex",
48
+ justifyContent: "space-between",
49
+ alignItems: "center",
50
+ padding: "0.25rem 1rem",
51
+ backgroundColor: "rgba(0, 0, 0, 0.06)",
52
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
53
+ fontSize: "0.85rem",
54
+
55
+ ".cm-draftly-code-header-left": {
56
+ display: "flex",
57
+ alignItems: "center",
58
+ gap: "0.5rem",
59
+
60
+ ".cm-draftly-code-header-title": {
61
+ color: "var(--color-text, inherit)",
62
+ fontWeight: "500",
63
+ },
64
+
65
+ ".cm-draftly-code-header-lang": {
66
+ color: "#6a737d",
67
+ opacity: "0.8",
68
+ },
69
+ },
70
+
71
+ ".cm-draftly-code-header-right": {
72
+ display: "flex",
73
+ alignItems: "center",
74
+ gap: "0.5rem",
75
+
76
+ ".cm-draftly-code-copy-btn": {
77
+ display: "flex",
78
+ alignItems: "center",
79
+ justifyContent: "center",
80
+ padding: "0.25rem",
81
+ backgroundColor: "transparent",
82
+ border: "none",
83
+ borderRadius: "4px",
84
+ cursor: "pointer",
85
+ color: "#6a737d",
86
+ transition: "color 0.2s, background-color 0.2s",
87
+
88
+ "&:hover": {
89
+ backgroundColor: "rgba(0, 0, 0, 0.1)",
90
+ color: "var(--color-text, inherit)",
91
+ },
92
+
93
+ "&.copied": {
94
+ color: "#22c55e",
95
+ },
96
+ },
97
+ },
98
+ },
99
+
100
+ // Caption (below code block)
101
+ ".cm-draftly-code-block-has-caption": {
102
+ padding: "0 !important",
103
+ paddingTop: "0.5rem !important",
104
+ },
105
+
106
+ ".cm-draftly-code-caption": {
107
+ textAlign: "center",
108
+ fontSize: "0.85rem",
109
+ color: "#6a737d",
110
+ fontStyle: "italic",
111
+ padding: "0.25rem 1rem",
112
+ backgroundColor: "rgba(0, 0, 0, 0.06)",
113
+ },
114
+
115
+ // Last line of code block
116
+ ".cm-draftly-code-block-line-end": {
117
+ borderBottomLeftRadius: "var(--radius)",
118
+ borderBottomRightRadius: "var(--radius)",
119
+ borderBottom: "1px solid var(--color-border)",
120
+ paddingTop: "0.5rem !important",
121
+
122
+ "& br": {
123
+ display: "none",
124
+ },
125
+ },
126
+
127
+ // Fence markers (```)
128
+ ".cm-draftly-code-fence": {
129
+ color: "#6a737d",
130
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
131
+ },
132
+
133
+ // Line numbers
134
+ ".cm-draftly-code-line-numbered": {
135
+ paddingLeft: "calc(var(--line-num-width, 2ch) + 1rem) !important",
136
+ position: "relative",
137
+
138
+ "&::before": {
139
+ content: "attr(data-line-num)",
140
+ position: "absolute",
141
+ left: "0.5rem",
142
+ top: "0.2rem",
143
+ width: "var(--line-num-width, 2ch)",
144
+ textAlign: "right",
145
+ color: "#6a737d",
146
+ opacity: "0.6",
147
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
148
+ fontSize: "0.85rem",
149
+ userSelect: "none",
150
+ },
151
+ },
152
+
153
+ ".cm-draftly-code-line-numbered-diff": {
154
+ paddingLeft: "calc(var(--line-num-old-width, 2ch) + var(--line-num-new-width, 2ch) + 2.75rem) !important",
155
+ position: "relative",
156
+
157
+ "&::before": {
158
+ content: "attr(data-line-num-old)",
159
+ position: "absolute",
160
+ left: "0.5rem",
161
+ top: "0.2rem",
162
+ width: "var(--line-num-old-width, 2ch)",
163
+ textAlign: "right",
164
+ color: "#6a737d",
165
+ opacity: "0.6",
166
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
167
+ fontSize: "0.85rem",
168
+ userSelect: "none",
169
+ },
170
+
171
+ "&::after": {
172
+ content: 'attr(data-line-num-new) " " attr(data-diff-marker)',
173
+ position: "absolute",
174
+ left: "calc(0.5rem + var(--line-num-old-width, 2ch) + 0.75rem)",
175
+ top: "0.2rem",
176
+ width: "calc(var(--line-num-new-width, 2ch) + 2ch)",
177
+ textAlign: "right",
178
+ color: "#6a737d",
179
+ opacity: "0.6",
180
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
181
+ fontSize: "0.85rem",
182
+ userSelect: "none",
183
+ },
184
+
185
+ "&.cm-draftly-code-line-diff-gutter": {
186
+ paddingLeft: "calc(var(--line-num-width, 2ch) + 2rem) !important",
187
+
188
+ "&::after": {
189
+ content: "attr(data-diff-marker)",
190
+ position: "absolute",
191
+ left: "calc(0.5rem + var(--line-num-width, 2ch) + 0.35rem)",
192
+ top: "0.1rem",
193
+ width: "1ch",
194
+ textAlign: "right",
195
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
196
+ fontSize: "0.85rem",
197
+ fontWeight: "700",
198
+ userSelect: "none",
199
+ },
200
+ },
201
+ },
202
+
203
+ // Preview: code lines (need block display for full-width highlights)
204
+ ".cm-draftly-code-line": {
205
+ display: "block",
206
+ position: "relative",
207
+ paddingLeft: "1rem",
208
+ paddingRight: "1rem",
209
+ lineHeight: "1.5",
210
+ borderLeft: "3px solid transparent",
211
+ },
212
+
213
+ // Line highlight
214
+ ".cm-draftly-code-line-highlight": {
215
+ backgroundColor: "rgba(255, 220, 100, 0.2) !important",
216
+ borderLeft: "3px solid #f0b429 !important",
217
+ },
218
+
219
+ ".cm-draftly-code-line-diff-add": {
220
+ color: "inherit",
221
+ backgroundColor: "rgba(34, 197, 94, 0.12) !important",
222
+ borderLeft: "3px solid #22c55e !important",
223
+
224
+ "&.cm-draftly-code-line-diff-gutter::after": {
225
+ color: "#16a34a",
226
+ },
227
+ },
228
+
229
+ ".cm-draftly-code-line-diff-del": {
230
+ color: "inherit",
231
+ backgroundColor: "rgba(239, 68, 68, 0.12) !important",
232
+ borderLeft: "3px solid #ef4444 !important",
233
+
234
+ "&.cm-draftly-code-line-diff-gutter::after": {
235
+ color: "#dc2626",
236
+ },
237
+ },
238
+
239
+ ".cm-draftly-code-diff-sign-add": {
240
+ color: "#16a34a",
241
+ fontWeight: "700",
242
+ },
243
+
244
+ ".cm-draftly-code-diff-sign-del": {
245
+ color: "#dc2626",
246
+ fontWeight: "700",
247
+ },
248
+
249
+ ".cm-draftly-code-diff-mod-add": {
250
+ color: "inherit",
251
+ backgroundColor: "rgba(34, 197, 94, 0.25)",
252
+ borderRadius: "2px",
253
+ padding: "0.1rem 0",
254
+ },
255
+
256
+ ".cm-draftly-code-diff-mod-del": {
257
+ color: "inherit",
258
+ backgroundColor: "rgba(239, 68, 68, 0.25)",
259
+ borderRadius: "2px",
260
+ padding: "0.1rem 0",
261
+ },
262
+
263
+ // Text highlight
264
+ ".cm-draftly-code-text-highlight": {
265
+ color: "inherit",
266
+ backgroundColor: "rgba(255, 220, 100, 0.4)",
267
+ borderRadius: "2px",
268
+ padding: "0.1rem 0",
269
+ },
270
+
271
+ // Preview: container wrapper
272
+ ".cm-draftly-code-container": {
273
+ margin: "1rem 0",
274
+ borderRadius: "var(--radius)",
275
+ overflow: "hidden",
276
+ border: "1px solid var(--color-border)",
277
+
278
+ ".cm-draftly-code-header": {
279
+ borderRadius: "0",
280
+ border: "none",
281
+ borderBottom: "1px solid var(--color-border)",
282
+ },
283
+
284
+ ".cm-draftly-code-block": {
285
+ margin: "0",
286
+ borderRadius: "0",
287
+ border: "none",
288
+ whiteSpace: "pre-wrap",
289
+ },
290
+
291
+ ".cm-draftly-code-caption": {
292
+ borderTop: "1px solid var(--color-border)",
293
+ },
294
+ },
295
+
296
+ // Preview: standalone code block (not in container)
297
+ ".cm-draftly-code-block": {
298
+ fontFamily: "var(--font-jetbrains-mono, monospace)",
299
+ fontSize: "0.9rem",
300
+ backgroundColor: "rgba(0, 0, 0, 0.03)",
301
+ padding: "1rem",
302
+ overflow: "auto",
303
+ position: "relative",
304
+ borderRadius: "var(--radius)",
305
+ border: "1px solid var(--color-border)",
306
+
307
+ "&.cm-draftly-code-block-has-header": {
308
+ borderTopLeftRadius: "0",
309
+ borderTopRightRadius: "0",
310
+ borderTop: "none",
311
+ margin: "0",
312
+ paddingTop: "0.5rem !important",
313
+ },
314
+
315
+ "&.cm-draftly-code-block-has-caption": {
316
+ borderBottomLeftRadius: "0",
317
+ borderBottomRightRadius: "0",
318
+ borderBottom: "none",
319
+ paddingBottom: "0.5rem !important",
320
+ },
321
+ },
322
+ },
323
+
324
+ dark: {
325
+ ".cm-draftly-code-inline": {
326
+ backgroundColor: "rgba(255, 255, 255, 0.1)",
327
+ },
328
+
329
+ ".cm-draftly-code-block-line": {
330
+ backgroundColor: "rgba(255, 255, 255, 0.05)",
331
+ },
332
+
333
+ ".cm-draftly-code-fence": {
334
+ color: "#8b949e",
335
+ },
336
+
337
+ ".cm-draftly-code-block": {
338
+ backgroundColor: "rgba(255, 255, 255, 0.05)",
339
+ },
340
+
341
+ ".cm-draftly-code-header": {
342
+ backgroundColor: "rgba(255, 255, 255, 0.08)",
343
+
344
+ ".cm-draftly-code-header-lang": {
345
+ color: "#8b949e",
346
+ },
347
+
348
+ ".cm-draftly-code-copy-btn": {
349
+ color: "#8b949e",
350
+
351
+ "&:hover": {
352
+ backgroundColor: "rgba(255, 255, 255, 0.1)",
353
+ },
354
+ },
355
+ },
356
+
357
+ ".cm-draftly-code-caption": {
358
+ backgroundColor: "rgba(255, 255, 255, 0.05)",
359
+ },
360
+
361
+ ".cm-draftly-code-line-numbered": {
362
+ "&::before": {
363
+ color: "#8b949e",
364
+ },
365
+ },
366
+
367
+ ".cm-draftly-code-line-numbered-diff": {
368
+ "&::before": {
369
+ color: "#8b949e",
370
+ },
371
+
372
+ "&::after": {
373
+ color: "#8b949e",
374
+ },
375
+ },
376
+
377
+ ".cm-draftly-code-line-diff-gutter": {
378
+ "&::after": {
379
+ color: "#8b949e",
380
+ },
381
+ },
382
+
383
+ ".cm-draftly-code-line-highlight": {
384
+ backgroundColor: "rgba(255, 220, 100, 0.15) !important",
385
+ borderLeft: "3px solid #d9a520 !important",
386
+ },
387
+
388
+ ".cm-draftly-code-line-diff-add": {
389
+ backgroundColor: "rgba(34, 197, 94, 0.15) !important",
390
+ borderLeft: "3px solid #22c55e !important",
391
+
392
+ "&.cm-draftly-code-line-diff-gutter::after": {
393
+ color: "#4ade80",
394
+ },
395
+ },
396
+
397
+ ".cm-draftly-code-line-diff-del": {
398
+ backgroundColor: "rgba(239, 68, 68, 0.15) !important",
399
+ borderLeft: "3px solid #ef4444 !important",
400
+
401
+ "&.cm-draftly-code-line-diff-gutter::after": {
402
+ color: "#f87171",
403
+ },
404
+ },
405
+
406
+ ".cm-draftly-code-diff-sign-add": {
407
+ color: "#4ade80",
408
+ },
409
+
410
+ ".cm-draftly-code-diff-sign-del": {
411
+ color: "#f87171",
412
+ },
413
+
414
+ ".cm-draftly-code-diff-mod-add": {
415
+ backgroundColor: "rgba(34, 197, 94, 0.3)",
416
+ },
417
+
418
+ ".cm-draftly-code-diff-mod-del": {
419
+ backgroundColor: "rgba(239, 68, 68, 0.3)",
420
+ },
421
+
422
+ ".cm-draftly-code-text-highlight": {
423
+ backgroundColor: "rgba(255, 220, 100, 0.3)",
424
+ },
425
+ },
426
+ });