@aionbuilders/nabu 0.1.0-alpha.9 → 0.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 (319) hide show
  1. package/CHANGELOG.md +523 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -144
  4. package/dist/behaviors/text/RichText.svelte +25 -2
  5. package/dist/behaviors/text/index.d.ts +2 -0
  6. package/dist/behaviors/text/index.js +2 -0
  7. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +5 -0
  8. package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
  9. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  10. package/dist/behaviors/text/markdown-syntax.js +81 -0
  11. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  12. package/dist/behaviors/text/rich-text.extension.js +135 -53
  13. package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
  14. package/dist/behaviors/text/text.behavior.svelte.js +657 -55
  15. package/dist/behaviors/text/typography.extension.d.ts +7 -0
  16. package/dist/behaviors/text/typography.extension.js +25 -0
  17. package/dist/blocks/Block.svelte +5 -2
  18. package/dist/blocks/BlockList.svelte +48 -0
  19. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  20. package/dist/blocks/Nabu.svelte +180 -14
  21. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  22. package/dist/blocks/block.extension.d.ts +3 -0
  23. package/dist/blocks/block.extension.js +8 -9
  24. package/dist/blocks/block.svelte.d.ts +356 -68
  25. package/dist/blocks/block.svelte.js +388 -42
  26. package/dist/blocks/blockquote/Blockquote.svelte +39 -0
  27. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  28. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
  29. package/dist/blocks/blockquote/blockquote.extension.js +80 -0
  30. package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
  31. package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
  32. package/dist/blocks/blockquote/index.d.ts +3 -0
  33. package/dist/blocks/blockquote/index.js +3 -0
  34. package/dist/blocks/callout/Callout.svelte +67 -0
  35. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  36. package/dist/blocks/callout/callout.extension.d.ts +4 -0
  37. package/dist/blocks/callout/callout.extension.js +84 -0
  38. package/dist/blocks/callout/callout.svelte.d.ts +80 -0
  39. package/dist/blocks/callout/callout.svelte.js +189 -0
  40. package/dist/blocks/callout/index.d.ts +3 -0
  41. package/dist/blocks/callout/index.js +3 -0
  42. package/dist/blocks/chunks.d.ts +49 -0
  43. package/dist/blocks/chunks.js +90 -0
  44. package/dist/blocks/code/Code.svelte +84 -0
  45. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  46. package/dist/blocks/code/code.extension.d.ts +4 -0
  47. package/dist/blocks/code/code.extension.js +88 -0
  48. package/dist/blocks/code/code.svelte.d.ts +68 -0
  49. package/dist/blocks/code/code.svelte.js +245 -0
  50. package/dist/blocks/code/index.d.ts +3 -0
  51. package/dist/blocks/code/index.js +3 -0
  52. package/dist/blocks/container.utils.d.ts +85 -13
  53. package/dist/blocks/container.utils.js +338 -178
  54. package/dist/blocks/dialogue/Dialogue.svelte +8 -2
  55. package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
  56. package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
  57. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  58. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  59. package/dist/blocks/dialogue/index.d.ts +12 -1
  60. package/dist/blocks/dialogue/index.js +51 -35
  61. package/dist/blocks/divider/Divider.svelte +28 -0
  62. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  63. package/dist/blocks/divider/divider.extension.d.ts +23 -0
  64. package/dist/blocks/divider/divider.extension.js +153 -0
  65. package/dist/blocks/divider/divider.svelte.d.ts +54 -0
  66. package/dist/blocks/divider/divider.svelte.js +89 -0
  67. package/dist/blocks/divider/index.d.ts +3 -0
  68. package/dist/blocks/divider/index.js +3 -0
  69. package/dist/blocks/file/File.svelte +56 -0
  70. package/dist/blocks/file/File.svelte.d.ts +11 -0
  71. package/dist/blocks/file/file.extension.d.ts +4 -0
  72. package/dist/blocks/file/file.extension.js +27 -0
  73. package/dist/blocks/file/file.svelte.d.ts +29 -0
  74. package/dist/blocks/file/file.svelte.js +77 -0
  75. package/dist/blocks/file/index.d.ts +3 -0
  76. package/dist/blocks/file/index.js +3 -0
  77. package/dist/blocks/heading/Heading.svelte +2 -1
  78. package/dist/blocks/heading/heading.svelte.d.ts +27 -34
  79. package/dist/blocks/heading/heading.svelte.js +72 -60
  80. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  81. package/dist/blocks/heading/index.d.ts +2 -2
  82. package/dist/blocks/heading/index.js +33 -8
  83. package/dist/blocks/image/Image.svelte +41 -0
  84. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  85. package/dist/blocks/image/image.extension.d.ts +5 -0
  86. package/dist/blocks/image/image.extension.js +34 -0
  87. package/dist/blocks/image/image.svelte.d.ts +61 -0
  88. package/dist/blocks/image/image.svelte.js +114 -0
  89. package/dist/blocks/image/index.d.ts +3 -0
  90. package/dist/blocks/image/index.js +3 -0
  91. package/dist/blocks/index.d.ts +11 -1
  92. package/dist/blocks/index.js +11 -1
  93. package/dist/blocks/list/List.svelte +9 -2
  94. package/dist/blocks/list/ListItem.svelte +44 -7
  95. package/dist/blocks/list/convert.d.ts +20 -0
  96. package/dist/blocks/list/convert.js +92 -0
  97. package/dist/blocks/list/hooks/onBeforeInput.hook.js +60 -26
  98. package/dist/blocks/list/html-flat.d.ts +78 -0
  99. package/dist/blocks/list/html-flat.js +244 -0
  100. package/dist/blocks/list/indent.d.ts +86 -0
  101. package/dist/blocks/list/indent.js +205 -0
  102. package/dist/blocks/list/index.d.ts +7 -3
  103. package/dist/blocks/list/index.js +43 -31
  104. package/dist/blocks/list/list-item.svelte.d.ts +43 -17
  105. package/dist/blocks/list/list-item.svelte.js +143 -93
  106. package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
  107. package/dist/blocks/list/list.behavior.svelte.js +10 -5
  108. package/dist/blocks/list/list.svelte.d.ts +101 -23
  109. package/dist/blocks/list/list.svelte.js +136 -114
  110. package/dist/blocks/list/markdown.d.ts +149 -0
  111. package/dist/blocks/list/markdown.js +442 -0
  112. package/dist/blocks/list/normalize.d.ts +11 -0
  113. package/dist/blocks/list/normalize.js +396 -0
  114. package/dist/blocks/list/paste.d.ts +45 -0
  115. package/dist/blocks/list/paste.js +242 -0
  116. package/dist/blocks/list/step-back.d.ts +24 -0
  117. package/dist/blocks/list/step-back.js +87 -0
  118. package/dist/blocks/list/to-list.d.ts +7 -0
  119. package/dist/blocks/list/to-list.js +44 -0
  120. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  121. package/dist/blocks/list/todos-toggle.js +48 -0
  122. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  123. package/dist/blocks/list/todos.svelte.js +76 -0
  124. package/dist/blocks/media/index.d.ts +2 -0
  125. package/dist/blocks/media/index.js +2 -0
  126. package/dist/blocks/media/markdown.d.ts +12 -0
  127. package/dist/blocks/media/markdown.js +26 -0
  128. package/dist/blocks/media/media-block.svelte.d.ts +107 -0
  129. package/dist/blocks/media/media-block.svelte.js +181 -0
  130. package/dist/blocks/media/media.helpers.d.ts +24 -0
  131. package/dist/blocks/media/media.helpers.js +88 -0
  132. package/dist/blocks/megablock.svelte.d.ts +50 -19
  133. package/dist/blocks/megablock.svelte.js +115 -74
  134. package/dist/blocks/move.d.ts +23 -0
  135. package/dist/blocks/move.js +92 -0
  136. package/dist/blocks/nabu.svelte.d.ts +846 -75
  137. package/dist/blocks/nabu.svelte.js +1990 -182
  138. package/dist/blocks/paragraph/Paragraph.svelte +1 -0
  139. package/dist/blocks/paragraph/index.d.ts +2 -2
  140. package/dist/blocks/paragraph/index.js +35 -16
  141. package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
  142. package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
  143. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  144. package/dist/blocks/paragraph/table.html.js +111 -0
  145. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  146. package/dist/blocks/paragraph/table.markdown.js +90 -0
  147. package/dist/blocks/region/Region.svelte +264 -0
  148. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  149. package/dist/blocks/region/actions.d.ts +135 -0
  150. package/dist/blocks/region/actions.js +402 -0
  151. package/dist/blocks/region/close.d.ts +35 -0
  152. package/dist/blocks/region/close.js +130 -0
  153. package/dist/blocks/region/commands.d.ts +6 -0
  154. package/dist/blocks/region/commands.js +277 -0
  155. package/dist/blocks/region/create.d.ts +72 -0
  156. package/dist/blocks/region/create.js +208 -0
  157. package/dist/blocks/region/end-marker.d.ts +35 -0
  158. package/dist/blocks/region/end-marker.js +51 -0
  159. package/dist/blocks/region/facts.d.ts +69 -0
  160. package/dist/blocks/region/facts.js +152 -0
  161. package/dist/blocks/region/format.d.ts +91 -0
  162. package/dist/blocks/region/format.js +260 -0
  163. package/dist/blocks/region/index.d.ts +14 -0
  164. package/dist/blocks/region/index.js +14 -0
  165. package/dist/blocks/region/insert.d.ts +59 -0
  166. package/dist/blocks/region/insert.js +102 -0
  167. package/dist/blocks/region/messages.d.ts +254 -0
  168. package/dist/blocks/region/messages.js +131 -0
  169. package/dist/blocks/region/normalize.d.ts +7 -0
  170. package/dist/blocks/region/normalize.js +170 -0
  171. package/dist/blocks/region/region.extension.d.ts +58 -0
  172. package/dist/blocks/region/region.extension.js +119 -0
  173. package/dist/blocks/region/region.svelte.d.ts +221 -0
  174. package/dist/blocks/region/region.svelte.js +582 -0
  175. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  176. package/dist/blocks/region/regions.svelte.js +276 -0
  177. package/dist/blocks/region/serialize.d.ts +57 -0
  178. package/dist/blocks/region/serialize.js +112 -0
  179. package/dist/blocks/region/types.d.ts +255 -0
  180. package/dist/blocks/region/types.js +204 -0
  181. package/dist/blocks/selection.svelte.d.ts +106 -8
  182. package/dist/blocks/selection.svelte.js +632 -74
  183. package/dist/blocks/subthread.d.ts +80 -0
  184. package/dist/blocks/subthread.js +167 -0
  185. package/dist/blocks/text-block.svelte.d.ts +70 -0
  186. package/dist/blocks/text-block.svelte.js +108 -0
  187. package/dist/blocks/toggle/Toggle.svelte +73 -0
  188. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  189. package/dist/blocks/toggle/index.d.ts +3 -0
  190. package/dist/blocks/toggle/index.js +3 -0
  191. package/dist/blocks/toggle/markdown.d.ts +20 -0
  192. package/dist/blocks/toggle/markdown.js +112 -0
  193. package/dist/blocks/toggle/toggle.extension.d.ts +4 -0
  194. package/dist/blocks/toggle/toggle.extension.js +18 -0
  195. package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
  196. package/dist/blocks/toggle/toggle.svelte.js +352 -0
  197. package/dist/blocks/undo-selection.d.ts +175 -0
  198. package/dist/blocks/undo-selection.js +360 -0
  199. package/dist/blocks/video/Video.svelte +42 -0
  200. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  201. package/dist/blocks/video/index.d.ts +3 -0
  202. package/dist/blocks/video/index.js +3 -0
  203. package/dist/blocks/video/video.extension.d.ts +4 -0
  204. package/dist/blocks/video/video.extension.js +27 -0
  205. package/dist/blocks/video/video.svelte.d.ts +29 -0
  206. package/dist/blocks/video/video.svelte.js +80 -0
  207. package/dist/extend.d.ts +55 -0
  208. package/dist/extend.js +88 -0
  209. package/dist/files/assets.clipboard.d.ts +77 -0
  210. package/dist/files/assets.clipboard.js +152 -0
  211. package/dist/files/files.svelte.d.ts +363 -0
  212. package/dist/files/files.svelte.js +897 -0
  213. package/dist/files/index.d.ts +3 -0
  214. package/dist/files/index.js +3 -0
  215. package/dist/files/outbox.d.ts +69 -0
  216. package/dist/files/outbox.js +48 -0
  217. package/dist/files/status.d.ts +65 -0
  218. package/dist/files/status.js +87 -0
  219. package/dist/files/store.d.ts +97 -0
  220. package/dist/files/store.js +65 -0
  221. package/dist/files/uploads.svelte.d.ts +174 -0
  222. package/dist/files/uploads.svelte.js +504 -0
  223. package/dist/index.d.ts +68 -6
  224. package/dist/index.js +117 -7
  225. package/dist/nabu-theme.css +112 -0
  226. package/dist/paste/html.paste.d.ts +74 -3
  227. package/dist/paste/html.paste.js +555 -83
  228. package/dist/paste/markdown-inline.d.ts +86 -0
  229. package/dist/paste/markdown-inline.js +528 -0
  230. package/dist/paste/markdown.paste.d.ts +2 -8
  231. package/dist/paste/markdown.paste.js +78 -94
  232. package/dist/paste/nabu.paste.d.ts +3 -0
  233. package/dist/paste/nabu.paste.js +29 -3
  234. package/dist/paste/plain-text.paste.d.ts +2 -2
  235. package/dist/paste/plain-text.paste.js +3 -3
  236. package/dist/persistence/asset-store.d.ts +51 -0
  237. package/dist/persistence/asset-store.js +103 -0
  238. package/dist/persistence/autosave.d.ts +53 -0
  239. package/dist/persistence/autosave.js +62 -0
  240. package/dist/persistence/compact.d.ts +162 -0
  241. package/dist/persistence/compact.js +141 -0
  242. package/dist/persistence/history.d.ts +77 -0
  243. package/dist/persistence/history.js +176 -0
  244. package/dist/persistence/indexeddb.d.ts +190 -4
  245. package/dist/persistence/indexeddb.js +333 -29
  246. package/dist/persistence/merge.d.ts +38 -0
  247. package/dist/persistence/merge.js +36 -0
  248. package/dist/persistence/outbox.d.ts +25 -0
  249. package/dist/persistence/outbox.js +40 -0
  250. package/dist/persistence/persistence.d.ts +70 -9
  251. package/dist/persistence/persistence.js +507 -35
  252. package/dist/persistence/recovery.d.ts +79 -0
  253. package/dist/persistence/recovery.js +79 -0
  254. package/dist/persistence/release.d.ts +34 -0
  255. package/dist/persistence/release.js +64 -0
  256. package/dist/persistence/state.svelte.d.ts +53 -0
  257. package/dist/persistence/state.svelte.js +48 -0
  258. package/dist/persistence/sync.d.ts +39 -0
  259. package/dist/persistence/sync.js +138 -0
  260. package/dist/persistence/tail.d.ts +42 -0
  261. package/dist/persistence/tail.js +103 -0
  262. package/dist/presets.d.ts +29 -24
  263. package/dist/presets.js +51 -14
  264. package/dist/themes/atelier.css +318 -0
  265. package/dist/ui/CommandChooser.svelte +153 -0
  266. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  267. package/dist/ui/CommandInvite.svelte +99 -0
  268. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  269. package/dist/ui/DragHandle.svelte +217 -0
  270. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  271. package/dist/ui/FloatingToolbar.svelte +165 -0
  272. package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
  273. package/dist/ui/SlashMenu.svelte +215 -0
  274. package/dist/ui/SlashMenu.svelte.d.ts +33 -0
  275. package/dist/ui/anchor.d.ts +112 -0
  276. package/dist/ui/anchor.js +136 -0
  277. package/dist/ui/index.d.ts +10 -0
  278. package/dist/ui/index.js +15 -0
  279. package/dist/ui/slash-menu.svelte.d.ts +112 -0
  280. package/dist/ui/slash-menu.svelte.js +150 -0
  281. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  282. package/dist/utils/command-confirm.svelte.js +673 -0
  283. package/dist/utils/commands.d.ts +328 -0
  284. package/dist/utils/commands.js +416 -0
  285. package/dist/utils/dom-scope.d.ts +14 -0
  286. package/dist/utils/dom-scope.js +20 -0
  287. package/dist/utils/drop.d.ts +160 -0
  288. package/dist/utils/drop.js +305 -0
  289. package/dist/utils/extensions.d.ts +488 -40
  290. package/dist/utils/extensions.js +300 -19
  291. package/dist/utils/html.d.ts +44 -0
  292. package/dist/utils/html.js +183 -0
  293. package/dist/utils/index.d.ts +4 -0
  294. package/dist/utils/index.js +4 -0
  295. package/dist/utils/keys.d.ts +120 -0
  296. package/dist/utils/keys.js +248 -0
  297. package/dist/utils/links.d.ts +22 -0
  298. package/dist/utils/links.js +34 -0
  299. package/dist/utils/placeholders.d.ts +88 -0
  300. package/dist/utils/placeholders.js +91 -0
  301. package/dist/utils/selection.svelte.d.ts +47 -19
  302. package/dist/utils/selection.svelte.js +60 -10
  303. package/dist/utils/spellcheck.d.ts +9 -0
  304. package/dist/utils/spellcheck.js +17 -0
  305. package/dist/utils/tab.d.ts +31 -0
  306. package/dist/utils/tab.js +117 -0
  307. package/dist/utils/words.d.ts +7 -0
  308. package/dist/utils/words.js +62 -0
  309. package/dist/vite.d.ts +22 -0
  310. package/dist/vite.js +34 -0
  311. package/package.json +61 -22
  312. package/dist/blocks/zone/Zone.svelte +0 -258
  313. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  314. package/dist/blocks/zone/index.d.ts +0 -2
  315. package/dist/blocks/zone/index.js +0 -2
  316. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  317. package/dist/blocks/zone/zone.extension.js +0 -221
  318. package/dist/blocks/zone/zone.svelte.d.ts +0 -112
  319. package/dist/blocks/zone/zone.svelte.js +0 -321
@@ -25,24 +25,34 @@
25
25
  export class SvelteSelection {
26
26
  /** @type {Selection?} */
27
27
  raw: Selection | null;
28
- is: boolean;
29
- anchorNode: Node | null;
30
- anchorOffset: number;
31
- focusNode: Node | null;
32
- focusOffset: number;
33
- isCollapsed: boolean;
28
+ /** @public */
29
+ public is: boolean;
30
+ /** @public */
31
+ public anchorNode: Node | null;
32
+ /** @public */
33
+ public anchorOffset: number;
34
+ /** @public */
35
+ public focusNode: Node | null;
36
+ /** @public */
37
+ public focusOffset: number;
38
+ /** @public */
39
+ public isCollapsed: boolean;
34
40
  rangeCount: number;
35
41
  type: string;
36
42
  direction: "forward" | "backward" | "none";
37
43
  startNode: Node | null;
38
44
  endNode: Node | null;
39
- startOffset: number;
40
- endOffset: number;
45
+ /** @public */
46
+ public startOffset: number;
47
+ /** @public */
48
+ public endOffset: number;
41
49
  ranges: Range[];
42
50
  firstRange: Range;
43
- get range(): Range;
51
+ /** @public */
52
+ public get range(): Range;
44
53
  lastRange: Range;
45
- text: string;
54
+ /** @public */
55
+ public text: string;
46
56
  html: string;
47
57
  hasSelection: boolean;
48
58
  isEmpty: boolean;
@@ -51,8 +61,26 @@ export class SvelteSelection {
51
61
  allText: string;
52
62
  allHtml: string;
53
63
  boundingRects: DOMRect[];
64
+ /**
65
+ * Whether the live DOM selection is one this wrapper reflects. A subclass bound to a part of the page (an editor's own
66
+ * root) overrides it: a selection that is none of its business is NOT mirrored, the wrapper reads as "no selection".
67
+ * @param {Selection} raw
68
+ * @returns {boolean}
69
+ */
70
+ reflects(raw: Selection): boolean;
54
71
  refresh: () => void;
55
72
  /**
73
+ * Synchronise (de façon synchrone et idempotente) l'état avec la sélection DOM courante.
74
+ *
75
+ * `selectionchange` est asynchrone (tâche mise en file) : un événement d'entrée
76
+ * (keydown, beforeinput…) qui suit de très près un déplacement du caret verrait
77
+ * un état périmé. À appeler au tout début de ces handlers. Ne touche à l'état
78
+ * que si les points de la sélection ont réellement changé (pas de churn réactif).
79
+ * @returns {boolean} True si l'état a été mis à jour
80
+ * @public
81
+ */
82
+ public sync: () => boolean;
83
+ /**
56
84
  * Ajoute une range à la sélection.
57
85
  * @param {Range} range - La range à ajouter.
58
86
  * @returns {boolean} True si l'opération a réussi
@@ -112,9 +140,9 @@ export class SvelteSelection {
112
140
  * @param {Node} focusNode - Le nœud de focus.
113
141
  * @param {number} focusOffset - L'offset de focus.
114
142
  * @returns {boolean} True si l'opération a réussi
115
-
143
+ * @public
116
144
  */
117
- setBaseAndExtent: (anchorNode: Node, anchorOffset: number, focusNode: Node, focusOffset: number) => boolean;
145
+ public setBaseAndExtent: (anchorNode: Node, anchorOffset: number, focusNode: Node, focusOffset: number) => boolean;
118
146
  /**
119
147
  * Vérifie si la sélection contient un nœud donné.
120
148
  * @param {Node} node - Le nœud à vérifier.
@@ -163,15 +191,15 @@ export class SvelteSelection {
163
191
  * Observe un élément contenteditable pour les mutations DOM qui peuvent
164
192
  * affecter la position du caret sans déclencher selectionchange
165
193
  *
166
- * @param {Element} element - L'élément contenteditable à observer
167
- * @param {Object} options - Options d'observation
168
- * @param {number} options.debounceMs - Délai de debounce en ms (défaut: 16ms = ~1 frame)
169
- * @param {boolean} options.observeAttributes - Observer les changements d'attributs (défaut: false)
194
+ * @param {HTMLElement} element - L'élément contenteditable à observer
195
+ * @param {Object} [options] - Options d'observation
196
+ * @param {number} [options.debounceMs] - Délai de debounce en ms (défaut: 16ms = ~1 frame)
197
+ * @param {boolean} [options.observeAttributes] - Observer les changements d'attributs (défaut: false)
170
198
  * @returns {boolean} True si l'observation a été configurée avec succès
171
199
  */
172
- observe: (element: Element, options?: {
173
- debounceMs: number;
174
- observeAttributes: boolean;
200
+ observe: (element: HTMLElement, options?: {
201
+ debounceMs?: number | undefined;
202
+ observeAttributes?: boolean | undefined;
175
203
  }) => boolean;
176
204
  /**
177
205
  * Arrête l'observation d'un élément spécifique
@@ -56,16 +56,22 @@ export class SvelteSelection {
56
56
  * @type {SelectionObject?}
57
57
  */
58
58
  #sel = $state(null);
59
+ /** @public */
59
60
  is = $derived(!!this.#sel);
60
61
 
61
62
  /** @type {Range[]} */
62
63
  #ranges = $state([]);
63
64
 
64
65
  // Propriétés réactives de base
66
+ /** @public */
65
67
  anchorNode = $derived(this.#sel?.anchorNode ?? null);
68
+ /** @public */
66
69
  anchorOffset = $derived(this.#sel?.anchorOffset ?? 0);
70
+ /** @public */
67
71
  focusNode = $derived(this.#sel?.focusNode ?? null);
72
+ /** @public */
68
73
  focusOffset = $derived(this.#sel?.focusOffset ?? 0);
74
+ /** @public */
69
75
  isCollapsed = $derived(this.#sel?.isCollapsed ?? true);
70
76
  rangeCount = $derived(this.#sel?.rangeCount ?? 0);
71
77
  type = $derived(this.#sel?.type ?? '');
@@ -73,12 +79,15 @@ export class SvelteSelection {
73
79
 
74
80
  startNode = $derived(this.#sel?.startNode ?? null);
75
81
  endNode = $derived(this.#sel?.endNode ?? null);
82
+ /** @public */
76
83
  startOffset = $derived(this.#sel?.startOffset ?? 0);
84
+ /** @public */
77
85
  endOffset = $derived(this.#sel?.endOffset ?? 0);
78
86
 
79
87
  // Propriétés des ranges
80
88
  ranges = $derived(this.#ranges);
81
89
  firstRange = $derived(this.#ranges[0] ?? null);
90
+ /** @public */
82
91
  get range() {
83
92
  // Retourne la première range si elle existe, sinon null
84
93
  return this.firstRange;
@@ -86,6 +95,7 @@ export class SvelteSelection {
86
95
  lastRange = $derived(this.#ranges[this.#ranges.length - 1] ?? null);
87
96
 
88
97
  // Propriétés dérivées utiles
98
+ /** @public */
89
99
  text = $derived(this.#sel?.text ?? '');
90
100
  html = $derived(this.#sel?.html ?? '');
91
101
  hasSelection = $derived(!this.isCollapsed && this.rangeCount > 0);
@@ -132,12 +142,20 @@ export class SvelteSelection {
132
142
  }).filter(rect => rect !== null);
133
143
  });
134
144
 
145
+ /**
146
+ * Whether the live DOM selection is one this wrapper reflects. A subclass bound to a part of the page (an editor's own
147
+ * root) overrides it: a selection that is none of its business is NOT mirrored, the wrapper reads as "no selection".
148
+ * @param {Selection} raw
149
+ * @returns {boolean}
150
+ */
151
+ reflects(raw) { return true; }
152
+
135
153
  // Méthode privée pour mettre à jour la sélection
136
154
  #updateSelection = () => {
137
155
  try {
138
156
  this.raw = window.getSelection();
139
157
 
140
- if (!this.raw) {
158
+ if (!this.raw || !this.reflects(this.raw)) {
141
159
  this.#sel = null;
142
160
  this.#ranges = [];
143
161
  return;
@@ -190,7 +208,7 @@ export class SvelteSelection {
190
208
  isCollapsed: this.raw.isCollapsed,
191
209
  rangeCount: this.raw.rangeCount,
192
210
  type: this.raw.type,
193
- direction: this.raw.direction || 'none',
211
+ direction: /** @type {"forward" | "backward" | "none"} */ (this.raw.direction || 'none'),
194
212
  text,
195
213
  html
196
214
  };
@@ -203,6 +221,37 @@ export class SvelteSelection {
203
221
 
204
222
  // Méthode pour rafraîchir la sélection manuellement
205
223
  refresh = () => this.#updateSelection();
224
+
225
+ /**
226
+ * Synchronise (de façon synchrone et idempotente) l'état avec la sélection DOM courante.
227
+ *
228
+ * `selectionchange` est asynchrone (tâche mise en file) : un événement d'entrée
229
+ * (keydown, beforeinput…) qui suit de très près un déplacement du caret verrait
230
+ * un état périmé. À appeler au tout début de ces handlers. Ne touche à l'état
231
+ * que si les points de la sélection ont réellement changé (pas de churn réactif).
232
+ * @returns {boolean} True si l'état a été mis à jour
233
+ * @public
234
+ */
235
+ sync = () => {
236
+ if (typeof window === 'undefined' || !window.getSelection) return false;
237
+ const raw = window.getSelection();
238
+ const cur = this.#sel;
239
+ if (raw && !this.reflects(raw)) {
240
+ if (!cur) return false; // already "no selection"
241
+ } else if (!raw || raw.rangeCount === 0) {
242
+ if (!cur || cur.rangeCount === 0) return false;
243
+ } else if (cur && cur.rangeCount === raw.rangeCount && cur.type === raw.type) {
244
+ const range = raw.getRangeAt(0);
245
+ if (
246
+ cur.anchorNode === raw.anchorNode && cur.anchorOffset === raw.anchorOffset &&
247
+ cur.focusNode === raw.focusNode && cur.focusOffset === raw.focusOffset &&
248
+ cur.startNode === range.startContainer && cur.startOffset === range.startOffset &&
249
+ cur.endNode === range.endContainer && cur.endOffset === range.endOffset
250
+ ) return false;
251
+ }
252
+ this.#updateSelection();
253
+ return true;
254
+ };
206
255
 
207
256
  // Méthodes de manipulation de la sélection avec gestion d'erreurs
208
257
 
@@ -354,7 +403,7 @@ export class SvelteSelection {
354
403
  * @param {Node} focusNode - Le nœud de focus.
355
404
  * @param {number} focusOffset - L'offset de focus.
356
405
  * @returns {boolean} True si l'opération a réussi
357
-
406
+ * @public
358
407
  */
359
408
  setBaseAndExtent = (anchorNode, anchorOffset, focusNode, focusOffset) => {
360
409
  try {
@@ -477,16 +526,17 @@ export class SvelteSelection {
477
526
  #observedElements = new Set();
478
527
 
479
528
  /** @type {number?} */
529
+ /** @type {ReturnType<typeof setTimeout> | null} */
480
530
  #debounceTimer = null;
481
531
 
482
532
  /**
483
533
  * Observe un élément contenteditable pour les mutations DOM qui peuvent
484
534
  * affecter la position du caret sans déclencher selectionchange
485
535
  *
486
- * @param {Element} element - L'élément contenteditable à observer
487
- * @param {Object} options - Options d'observation
488
- * @param {number} options.debounceMs - Délai de debounce en ms (défaut: 16ms = ~1 frame)
489
- * @param {boolean} options.observeAttributes - Observer les changements d'attributs (défaut: false)
536
+ * @param {HTMLElement} element - L'élément contenteditable à observer
537
+ * @param {Object} [options] - Options d'observation
538
+ * @param {number} [options.debounceMs] - Délai de debounce en ms (défaut: 16ms = ~1 frame)
539
+ * @param {boolean} [options.observeAttributes] - Observer les changements d'attributs (défaut: false)
490
540
  * @returns {boolean} True si l'observation a été configurée avec succès
491
541
  */
492
542
  observe = (element, options = {}) => {
@@ -510,7 +560,7 @@ export class SvelteSelection {
510
560
  if (mutation.type === 'attributes') {
511
561
  const attr = mutation.attributeName;
512
562
  // Ne considérer que les attributs qui peuvent affecter le layout/contenu
513
- return ['class', 'style', 'contenteditable'].includes(attr);
563
+ return ['class', 'style', 'contenteditable'].includes(/** @type {string} */ (attr));
514
564
  }
515
565
 
516
566
  // Toujours considérer les changements de contenu
@@ -554,7 +604,7 @@ export class SvelteSelection {
554
604
  if (this.#observedElements.size === 0 && this.#mutationObserver) {
555
605
  this.#mutationObserver.disconnect();
556
606
  this.#mutationObserver = null;
557
- clearTimeout(this.#debounceTimer);
607
+ clearTimeout(this.#debounceTimer ?? undefined);
558
608
  this.#debounceTimer = null;
559
609
  }
560
610
 
@@ -571,7 +621,7 @@ export class SvelteSelection {
571
621
  }
572
622
 
573
623
  this.#observedElements.clear();
574
- clearTimeout(this.#debounceTimer);
624
+ clearTimeout(this.#debounceTimer ?? undefined);
575
625
  this.#debounceTimer = null;
576
626
  };
577
627
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Normalizes the `lang` option. `undefined` / `null` / `''` mean "unset" (valid, no attribute).
3
+ * @param {unknown} value
4
+ * @returns {{ lang: string | undefined, valid: boolean }}
5
+ */
6
+ export function normalizeLang(value: unknown): {
7
+ lang: string | undefined;
8
+ valid: boolean;
9
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Editor options `spellcheck` / `lang` (see NabuInit).
3
+ */
4
+
5
+ /** Loose BCP 47 shape: primary language (2-3 letters) then subtags (e.g. `fr`, `en-GB`, `zh-Hant-TW`, `es-419`). */
6
+ const LANG_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$/;
7
+
8
+ /**
9
+ * Normalizes the `lang` option. `undefined` / `null` / `''` mean "unset" (valid, no attribute).
10
+ * @param {unknown} value
11
+ * @returns {{ lang: string | undefined, valid: boolean }}
12
+ */
13
+ export function normalizeLang(value) {
14
+ if (value === undefined || value === null || value === '') return { lang: undefined, valid: true };
15
+ if (typeof value === 'string' && LANG_PATTERN.test(value)) return { lang: value, valid: true };
16
+ return { lang: undefined, valid: false };
17
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Whether `value` is an implemented mode.
3
+ * @param {unknown} value
4
+ * @returns {value is TabMode}
5
+ */
6
+ export function isTabMode(value: unknown): value is TabMode;
7
+ /**
8
+ * Resolve the `tab` option: a valid mode wins; `undefined` gives the default silently; anything else (unknown mode,
9
+ * `'nest'`, a wrong type) warns and gives the default.
10
+ * @param {unknown} value
11
+ * @param {TabMode} fallback
12
+ * @param {(message: string) => void} [warn]
13
+ * @returns {TabMode}
14
+ */
15
+ export function resolveTabMode(value: unknown, fallback: TabMode, warn?: (message: string) => void): TabMode;
16
+ /**
17
+ * Apply the `tab` option to a Tab / Shift+Tab that nothing structural handled. Call it last in the keydown chain.
18
+ * @param {Nabu} nabu
19
+ * @param {KeyboardEvent} e
20
+ * @param {boolean} escaped an Escape that nothing consumed was the previous key: the way out is open for this key
21
+ * @returns {boolean} whether the key was swallowed
22
+ */
23
+ export function handleTabKey(nabu: Nabu, e: KeyboardEvent, escaped: boolean): boolean;
24
+ /** @typedef {'focus' | 'stay' | 'indent'} TabMode */
25
+ /** The implemented modes. */
26
+ export const TAB_MODES: readonly ["focus", "stay", "indent"];
27
+ /** Default announcement of the Escape-then-Tab way out (option `tabHint`). */
28
+ export const DEFAULT_TAB_HINT: "Press Escape then Tab to leave the editor";
29
+ export function isModifierKey(e: KeyboardEvent): boolean;
30
+ export type TabMode = "focus" | "stay" | "indent";
31
+ import type { Nabu } from '../blocks/nabu.svelte.js';
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The `tab` option (P-41): what Tab / Shift+Tab do in a plain text block, i.e. when NOTHING structural took the key.
3
+ *
4
+ * Structural meanings always come first and are never affected by this option: list indent / outdent, code indentation, region
5
+ * title promote / demote (a command, ADR 017) and anything an extension handles in its own `onKeyDown` / `keydown`. The engine
6
+ * calls {@link handleTabKey} AFTER all of them, only for a key that is still not `defaultPrevented`. Agnostic: it names no block
7
+ * type, it only asks a block for its `text` behavior.
8
+ *
9
+ * Modes:
10
+ * - `'focus'`: the browser default, Tab leaves the editor (like a `<textarea>`). Nothing is prevented.
11
+ * - `'stay'`: Tab and Shift+Tab are swallowed, the caret stays. Escape then Tab leaves: after an Escape that nothing consumed
12
+ * (no slash menu, chooser or pending command), the NEXT Tab / Shift+Tab is left to the browser; any other key or a click
13
+ * arms the trap again. Announced to screen readers through `aria-description` on the editor root (option `tabHint`).
14
+ * - `'indent'`: Tab inserts a `\t` at the caret (it replaces a selection inside ONE block); Shift+Tab removes one `\t` right
15
+ * before the caret, if there is one, else nothing. With a selection spanning several blocks, or in a block without a text
16
+ * behavior or whose text is isolated (a region title), it behaves like `'stay'`. Same Escape-then-Tab way out as `'stay'`
17
+ * (otherwise the editor would be a keyboard trap) and the same announcement.
18
+ * - `'nest'` (Notion-style nesting) is planned, NOT implemented: asking for it warns and falls back to the default.
19
+ *
20
+ * @import { Nabu } from '../blocks/nabu.svelte.js'
21
+ */
22
+
23
+ import { tick } from 'svelte';
24
+
25
+ /** @typedef {'focus' | 'stay' | 'indent'} TabMode */
26
+
27
+ /** The implemented modes. */
28
+ export const TAB_MODES = /** @type {const} */ (['focus', 'stay', 'indent']);
29
+
30
+ /** Default announcement of the Escape-then-Tab way out (option `tabHint`). */
31
+ export const DEFAULT_TAB_HINT = 'Press Escape then Tab to leave the editor';
32
+
33
+ /**
34
+ * Whether `value` is an implemented mode.
35
+ * @param {unknown} value
36
+ * @returns {value is TabMode}
37
+ */
38
+ export function isTabMode(value) {
39
+ return typeof value === 'string' && /** @type {readonly string[]} */ (TAB_MODES).includes(value);
40
+ }
41
+
42
+ /**
43
+ * Resolve the `tab` option: a valid mode wins; `undefined` gives the default silently; anything else (unknown mode,
44
+ * `'nest'`, a wrong type) warns and gives the default.
45
+ * @param {unknown} value
46
+ * @param {TabMode} fallback
47
+ * @param {(message: string) => void} [warn]
48
+ * @returns {TabMode}
49
+ */
50
+ export function resolveTabMode(value, fallback, warn) {
51
+ if (value === undefined || value === null) return fallback;
52
+ if (isTabMode(value)) return value;
53
+ warn?.(value === 'nest'
54
+ ? `Option "tab": 'nest' is not implemented yet, using '${fallback}'`
55
+ : `Ignoring invalid option "tab" (${JSON.stringify(value)}; expected 'focus', 'stay' or 'indent'), using '${fallback}'`);
56
+ return fallback;
57
+ }
58
+
59
+ /** Keys that are only modifiers: pressing one (e.g. the Shift of Shift+Tab) is not "another key". @type {Set<string>} */
60
+ const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'AltGraph', 'Meta', 'OS', 'CapsLock', 'NumLock', 'ScrollLock', 'Fn', 'FnLock', 'Hyper', 'Super', 'Symbol', 'SymbolLock']);
61
+
62
+ /** @param {KeyboardEvent} e */
63
+ export const isModifierKey = (e) => MODIFIER_KEYS.has(e.key);
64
+
65
+ /**
66
+ * Apply the `tab` option to a Tab / Shift+Tab that nothing structural handled. Call it last in the keydown chain.
67
+ * @param {Nabu} nabu
68
+ * @param {KeyboardEvent} e
69
+ * @param {boolean} escaped an Escape that nothing consumed was the previous key: the way out is open for this key
70
+ * @returns {boolean} whether the key was swallowed
71
+ */
72
+ export function handleTabKey(nabu, e, escaped) {
73
+ if (e.key !== 'Tab' || e.ctrlKey || e.altKey || e.metaKey || e.defaultPrevented) return false;
74
+ if (e.isComposing || e.keyCode === 229 || nabu.composing) return false;
75
+ const mode = nabu.tab;
76
+ if (mode === 'focus' || escaped) return false; // the browser moves the focus
77
+ e.preventDefault();
78
+ if (mode === 'indent') indentWithTab(nabu, e.shiftKey);
79
+ return true;
80
+ }
81
+
82
+ /**
83
+ * @param {Nabu} nabu
84
+ * @param {boolean} outdent Shift+Tab
85
+ */
86
+ function indentWithTab(nabu, outdent) {
87
+ const sel = nabu.selection;
88
+ const block = sel.anchorBlock;
89
+ if (!block || block !== sel.focusBlock || block.isolatesSelection) return; // several blocks, or no editable text: like 'stay'
90
+ const behavior = block.behaviors?.get('text');
91
+ const range = behavior?.selection;
92
+ if (!behavior || !range) return;
93
+
94
+ if (outdent) {
95
+ if (!range.isCollapsed || range.from <= 0 || behavior.text[range.from - 1] !== '\t') return;
96
+ behavior.delete({ index: range.from - 1, length: 1 });
97
+ nabu.storedMarks = null;
98
+ block.commit();
99
+ tick().then(() => nabu.selection.setCursor(block, range.from - 1));
100
+ return;
101
+ }
102
+
103
+ const from = range.from;
104
+ if (!range.isCollapsed) behavior.delete({ index: from, length: range.to - from }, range);
105
+ behavior.insert(from, '\t');
106
+ // The cursor's pending marks apply to what is typed, like any inserted character (see TextBehavior#handleInsertText).
107
+ const stored = nabu.storedMarks;
108
+ if (stored) {
109
+ const span = { from, to: from + 1, isCollapsed: false };
110
+ for (const [name, on] of Object.entries(stored)) {
111
+ if (on) behavior.applyMark(name, true, span);
112
+ else behavior.removeMark(name, span);
113
+ }
114
+ }
115
+ block.commit();
116
+ tick().then(() => nabu.selection.setCursor(block, from + 1));
117
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Number of words in a text.
3
+ * @param {string} text
4
+ * @param {string} [lang] BCP 47 tag of the text (the editor's `lang`); unset: the platform default
5
+ * @returns {number}
6
+ */
7
+ export function countWords(text: string, lang?: string): number;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Word counting for the text of a block (`wordCount`).
3
+ *
4
+ * Splitting on whitespace is wrong for the languages that write words without spaces (Chinese, Japanese, Thai, Khmer...): a whole
5
+ * sentence would count as one word. When the platform has `Intl.Segmenter` the text is segmented with `granularity: 'word'` and
6
+ * only the segments that are `isWordLike` (letters and digits, not spaces or punctuation) are counted, with the document
7
+ * language as locale (`nabu.lang`, a BCP 47 tag; the Chinese / Japanese dictionaries need it to cut the same way as the
8
+ * reader would). Without `Intl.Segmenter` it falls back to the whitespace split.
9
+ *
10
+ * Differences from a whitespace count, by design (they follow the Unicode word-break rules, UAX #29): punctuation and quotation
11
+ * marks standing alone (`«`, `»`, `-`, an em dash) are not words, an apostrophe inside a word keeps it whole (`l'homme`,
12
+ * `don't`), and a hyphenated compound is several words (`well-known` is two).
13
+ *
14
+ * Cost: typing re-counts only the block being edited (the count is a `$derived` of its text). To keep the first count of a big
15
+ * document cheap, a plain Latin word is counted without the segmenter (whitespace tokens that are letters and digits only are
16
+ * one word by the same rules).
17
+ */
18
+
19
+ /** @type {Map<string, Intl.Segmenter | null>} */
20
+ const segmenters = new Map();
21
+
22
+ /**
23
+ * The word segmenter for a locale, `null` when the platform has none. An unusable locale falls back to the default one.
24
+ * @param {string | undefined} lang
25
+ * @returns {Intl.Segmenter | null}
26
+ */
27
+ function segmenterFor(lang) {
28
+ const key = lang ?? '';
29
+ const known = segmenters.get(key);
30
+ if (known !== undefined) return known;
31
+ /** @type {Intl.Segmenter | null} */
32
+ let segmenter = null;
33
+ if (typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function') {
34
+ try { segmenter = new Intl.Segmenter(lang || undefined, { granularity: 'word' }); }
35
+ catch { segmenter = segmenterFor(undefined); } // a locale the platform rejects
36
+ }
37
+ segmenters.set(key, segmenter);
38
+ return segmenter;
39
+ }
40
+
41
+ /** One word with certainty: Latin letters (with accents) and digits only. */
42
+ const LATIN_WORD = /^[0-9A-Za-zÀ-ÖØ-öø-ɏ]+$/;
43
+
44
+ /**
45
+ * Number of words in a text.
46
+ * @param {string} text
47
+ * @param {string} [lang] BCP 47 tag of the text (the editor's `lang`); unset: the platform default
48
+ * @returns {number}
49
+ */
50
+ export function countWords(text, lang) {
51
+ if (!text) return 0;
52
+ const tokens = text.split(/\s+/);
53
+ const segmenter = segmenterFor(lang);
54
+ if (!segmenter) return tokens.reduce((n, token) => n + (token ? 1 : 0), 0);
55
+ let count = 0;
56
+ for (const token of tokens) {
57
+ if (!token) continue;
58
+ if (LATIN_WORD.test(token)) { count++; continue; }
59
+ for (const part of segmenter.segment(token)) if (part.isWordLike) count++;
60
+ }
61
+ return count;
62
+ }
package/dist/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Vite plugin preset for Nabu.
3
+ *
4
+ * Loro-CRDT ships a WebAssembly module loaded with top-level `await`. This
5
+ * helper bundles what Vite needs for it, so consumers only add one entry to
6
+ * their Vite config:
7
+ *
8
+ * ```js
9
+ * // vite.config.js
10
+ * import { nabu } from '@aionbuilders/nabu/vite';
11
+ * export default defineConfig({ plugins: [sveltekit(), nabu()] });
12
+ * ```
13
+ *
14
+ * It registers `vite-plugin-wasm` and sets `build.target` to `'esnext'`
15
+ * (unless you already set it): modern browsers support top-level await
16
+ * natively, so no `vite-plugin-top-level-await` transform is needed (that
17
+ * plugin is incompatible with Vite 8 / Rolldown).
18
+ *
19
+ * @returns {Promise<import('vite').Plugin[]>}
20
+ */
21
+ export function nabu(): Promise<import("vite").Plugin[]>;
22
+ export default nabu;
package/dist/vite.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Vite plugin preset for Nabu.
3
+ *
4
+ * Loro-CRDT ships a WebAssembly module loaded with top-level `await`. This
5
+ * helper bundles what Vite needs for it, so consumers only add one entry to
6
+ * their Vite config:
7
+ *
8
+ * ```js
9
+ * // vite.config.js
10
+ * import { nabu } from '@aionbuilders/nabu/vite';
11
+ * export default defineConfig({ plugins: [sveltekit(), nabu()] });
12
+ * ```
13
+ *
14
+ * It registers `vite-plugin-wasm` and sets `build.target` to `'esnext'`
15
+ * (unless you already set it): modern browsers support top-level await
16
+ * natively, so no `vite-plugin-top-level-await` transform is needed (that
17
+ * plugin is incompatible with Vite 8 / Rolldown).
18
+ *
19
+ * @returns {Promise<import('vite').Plugin[]>}
20
+ */
21
+ export async function nabu() {
22
+ const { default: wasm } = await import('vite-plugin-wasm');
23
+ return [
24
+ wasm(),
25
+ {
26
+ name: 'nabu:esnext-target',
27
+ config(config) {
28
+ if (config.build?.target === undefined) return { build: { target: 'esnext' } };
29
+ },
30
+ },
31
+ ];
32
+ }
33
+
34
+ export default nabu;