@kujoforall/paper-ui 0.0.0-stage → 0.2.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 (661) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/LICENSE +21 -0
  3. package/README.md +295 -2
  4. package/dist/components/editor/block-text.d.ts +8 -0
  5. package/dist/components/editor/block-text.d.ts.map +1 -0
  6. package/dist/components/editor/block-text.js +248 -0
  7. package/dist/components/editor/block-text.js.map +1 -0
  8. package/dist/components/editor/blocks.d.ts +33 -0
  9. package/dist/components/editor/blocks.d.ts.map +1 -0
  10. package/dist/components/editor/blocks.js +191 -0
  11. package/dist/components/editor/blocks.js.map +1 -0
  12. package/dist/components/editor/document-editor.d.ts +27 -0
  13. package/dist/components/editor/document-editor.d.ts.map +1 -0
  14. package/dist/components/editor/document-editor.js +42 -0
  15. package/dist/components/editor/document-editor.js.map +1 -0
  16. package/dist/components/editor/document-view.d.ts +22 -0
  17. package/dist/components/editor/document-view.d.ts.map +1 -0
  18. package/dist/components/editor/document-view.js +110 -0
  19. package/dist/components/editor/document-view.js.map +1 -0
  20. package/dist/components/editor/editor-state.d.ts +107 -0
  21. package/dist/components/editor/editor-state.d.ts.map +1 -0
  22. package/dist/components/editor/editor-state.js +217 -0
  23. package/dist/components/editor/editor-state.js.map +1 -0
  24. package/dist/components/editor/extensions/kit-blocks.d.ts +34 -0
  25. package/dist/components/editor/extensions/kit-blocks.d.ts.map +1 -0
  26. package/dist/components/editor/extensions/kit-blocks.js +201 -0
  27. package/dist/components/editor/extensions/kit-blocks.js.map +1 -0
  28. package/dist/components/editor/extensions/spoiler.d.ts +8 -0
  29. package/dist/components/editor/extensions/spoiler.d.ts.map +1 -0
  30. package/dist/components/editor/extensions/spoiler.js +36 -0
  31. package/dist/components/editor/extensions/spoiler.js.map +1 -0
  32. package/dist/components/editor/index.d.ts +10 -0
  33. package/dist/components/editor/index.d.ts.map +1 -0
  34. package/dist/components/editor/index.js +10 -0
  35. package/dist/components/editor/index.js.map +1 -0
  36. package/dist/components/editor/kinds.d.ts +99 -0
  37. package/dist/components/editor/kinds.d.ts.map +1 -0
  38. package/dist/components/editor/kinds.js +74 -0
  39. package/dist/components/editor/kinds.js.map +1 -0
  40. package/dist/components/editor/look.d.ts +18 -0
  41. package/dist/components/editor/look.d.ts.map +1 -0
  42. package/dist/components/editor/look.js +21 -0
  43. package/dist/components/editor/look.js.map +1 -0
  44. package/dist/components/sketch/rough.d.ts +38 -0
  45. package/dist/components/sketch/rough.d.ts.map +1 -0
  46. package/dist/components/sketch/rough.js +57 -0
  47. package/dist/components/sketch/rough.js.map +1 -0
  48. package/dist/components/three/model-viewer.d.ts +36 -0
  49. package/dist/components/three/model-viewer.d.ts.map +1 -0
  50. package/dist/components/three/model-viewer.js +338 -0
  51. package/dist/components/three/model-viewer.js.map +1 -0
  52. package/dist/components/ui/accent-picker.d.ts +2 -0
  53. package/dist/components/ui/accent-picker.d.ts.map +1 -0
  54. package/dist/components/ui/accent-picker.js +44 -0
  55. package/dist/components/ui/accent-picker.js.map +1 -0
  56. package/dist/components/ui/address-field.d.ts +10 -0
  57. package/dist/components/ui/address-field.d.ts.map +1 -0
  58. package/dist/components/ui/address-field.js +24 -0
  59. package/dist/components/ui/address-field.js.map +1 -0
  60. package/dist/components/ui/alert-dialog.d.ts +29 -0
  61. package/dist/components/ui/alert-dialog.d.ts.map +1 -0
  62. package/dist/components/ui/alert-dialog.js +72 -0
  63. package/dist/components/ui/alert-dialog.js.map +1 -0
  64. package/dist/components/ui/animated-height.d.ts +6 -0
  65. package/dist/components/ui/animated-height.d.ts.map +1 -0
  66. package/dist/components/ui/animated-height.js +26 -0
  67. package/dist/components/ui/animated-height.js.map +1 -0
  68. package/dist/components/ui/app-shell.d.ts +26 -0
  69. package/dist/components/ui/app-shell.d.ts.map +1 -0
  70. package/dist/components/ui/app-shell.js +71 -0
  71. package/dist/components/ui/app-shell.js.map +1 -0
  72. package/dist/components/ui/avatar.d.ts +30 -0
  73. package/dist/components/ui/avatar.d.ts.map +1 -0
  74. package/dist/components/ui/avatar.js +50 -0
  75. package/dist/components/ui/avatar.js.map +1 -0
  76. package/dist/components/ui/badge.d.ts +19 -0
  77. package/dist/components/ui/badge.d.ts.map +1 -0
  78. package/dist/components/ui/badge.js +62 -0
  79. package/dist/components/ui/badge.js.map +1 -0
  80. package/dist/components/ui/banner.d.ts +33 -0
  81. package/dist/components/ui/banner.d.ts.map +1 -0
  82. package/dist/components/ui/banner.js +21 -0
  83. package/dist/components/ui/banner.js.map +1 -0
  84. package/dist/components/ui/breadcrumbs.d.ts +10 -0
  85. package/dist/components/ui/breadcrumbs.d.ts.map +1 -0
  86. package/dist/components/ui/breadcrumbs.js +9 -0
  87. package/dist/components/ui/breadcrumbs.js.map +1 -0
  88. package/dist/components/ui/button.d.ts +15 -0
  89. package/dist/components/ui/button.d.ts.map +1 -0
  90. package/dist/components/ui/button.js +110 -0
  91. package/dist/components/ui/button.js.map +1 -0
  92. package/dist/components/ui/calendar.d.ts +5 -0
  93. package/dist/components/ui/calendar.d.ts.map +1 -0
  94. package/dist/components/ui/calendar.js +65 -0
  95. package/dist/components/ui/calendar.js.map +1 -0
  96. package/dist/components/ui/callout.d.ts +32 -0
  97. package/dist/components/ui/callout.d.ts.map +1 -0
  98. package/dist/components/ui/callout.js +40 -0
  99. package/dist/components/ui/callout.js.map +1 -0
  100. package/dist/components/ui/card.d.ts +18 -0
  101. package/dist/components/ui/card.d.ts.map +1 -0
  102. package/dist/components/ui/card.js +28 -0
  103. package/dist/components/ui/card.js.map +1 -0
  104. package/dist/components/ui/checkbox.d.ts +11 -0
  105. package/dist/components/ui/checkbox.d.ts.map +1 -0
  106. package/dist/components/ui/checkbox.js +30 -0
  107. package/dist/components/ui/checkbox.js.map +1 -0
  108. package/dist/components/ui/choice-label.d.ts +13 -0
  109. package/dist/components/ui/choice-label.d.ts.map +1 -0
  110. package/dist/components/ui/choice-label.js +17 -0
  111. package/dist/components/ui/choice-label.js.map +1 -0
  112. package/dist/components/ui/collapsible.d.ts +10 -0
  113. package/dist/components/ui/collapsible.d.ts.map +1 -0
  114. package/dist/components/ui/collapsible.js +21 -0
  115. package/dist/components/ui/collapsible.js.map +1 -0
  116. package/dist/components/ui/collection-layout.d.ts +24 -0
  117. package/dist/components/ui/collection-layout.d.ts.map +1 -0
  118. package/dist/components/ui/collection-layout.js +16 -0
  119. package/dist/components/ui/collection-layout.js.map +1 -0
  120. package/dist/components/ui/combobox.d.ts +10 -0
  121. package/dist/components/ui/combobox.d.ts.map +1 -0
  122. package/dist/components/ui/combobox.js +93 -0
  123. package/dist/components/ui/combobox.js.map +1 -0
  124. package/dist/components/ui/command-menu.d.ts +18 -0
  125. package/dist/components/ui/command-menu.d.ts.map +1 -0
  126. package/dist/components/ui/command-menu.js +49 -0
  127. package/dist/components/ui/command-menu.js.map +1 -0
  128. package/dist/components/ui/context-menu.d.ts +19 -0
  129. package/dist/components/ui/context-menu.d.ts.map +1 -0
  130. package/dist/components/ui/context-menu.js +42 -0
  131. package/dist/components/ui/context-menu.js.map +1 -0
  132. package/dist/components/ui/copy-button.d.ts +11 -0
  133. package/dist/components/ui/copy-button.d.ts.map +1 -0
  134. package/dist/components/ui/copy-button.js +48 -0
  135. package/dist/components/ui/copy-button.js.map +1 -0
  136. package/dist/components/ui/database/calendar-view.d.ts +10 -0
  137. package/dist/components/ui/database/calendar-view.d.ts.map +1 -0
  138. package/dist/components/ui/database/calendar-view.js +65 -0
  139. package/dist/components/ui/database/calendar-view.js.map +1 -0
  140. package/dist/components/ui/database/card-views.d.ts +22 -0
  141. package/dist/components/ui/database/card-views.d.ts.map +1 -0
  142. package/dist/components/ui/database/card-views.js +74 -0
  143. package/dist/components/ui/database/card-views.js.map +1 -0
  144. package/dist/components/ui/database/cells.d.ts +20 -0
  145. package/dist/components/ui/database/cells.d.ts.map +1 -0
  146. package/dist/components/ui/database/cells.js +132 -0
  147. package/dist/components/ui/database/cells.js.map +1 -0
  148. package/dist/components/ui/database/database.d.ts +19 -0
  149. package/dist/components/ui/database/database.d.ts.map +1 -0
  150. package/dist/components/ui/database/database.js +102 -0
  151. package/dist/components/ui/database/database.js.map +1 -0
  152. package/dist/components/ui/database/icons.d.ts +5 -0
  153. package/dist/components/ui/database/icons.d.ts.map +1 -0
  154. package/dist/components/ui/database/icons.js +13 -0
  155. package/dist/components/ui/database/icons.js.map +1 -0
  156. package/dist/components/ui/database/table-view.d.ts +11 -0
  157. package/dist/components/ui/database/table-view.d.ts.map +1 -0
  158. package/dist/components/ui/database/table-view.js +157 -0
  159. package/dist/components/ui/database/table-view.js.map +1 -0
  160. package/dist/components/ui/date-picker.d.ts +40 -0
  161. package/dist/components/ui/date-picker.d.ts.map +1 -0
  162. package/dist/components/ui/date-picker.js +64 -0
  163. package/dist/components/ui/date-picker.js.map +1 -0
  164. package/dist/components/ui/date-time-picker.d.ts +21 -0
  165. package/dist/components/ui/date-time-picker.d.ts.map +1 -0
  166. package/dist/components/ui/date-time-picker.js +34 -0
  167. package/dist/components/ui/date-time-picker.js.map +1 -0
  168. package/dist/components/ui/dialog.d.ts +21 -0
  169. package/dist/components/ui/dialog.d.ts.map +1 -0
  170. package/dist/components/ui/dialog.js +63 -0
  171. package/dist/components/ui/dialog.js.map +1 -0
  172. package/dist/components/ui/document-layout.d.ts +15 -0
  173. package/dist/components/ui/document-layout.d.ts.map +1 -0
  174. package/dist/components/ui/document-layout.js +15 -0
  175. package/dist/components/ui/document-layout.js.map +1 -0
  176. package/dist/components/ui/dropdown-menu.d.ts +24 -0
  177. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  178. package/dist/components/ui/dropdown-menu.js +65 -0
  179. package/dist/components/ui/dropdown-menu.js.map +1 -0
  180. package/dist/components/ui/editable-text.d.ts +24 -0
  181. package/dist/components/ui/editable-text.d.ts.map +1 -0
  182. package/dist/components/ui/editable-text.js +85 -0
  183. package/dist/components/ui/editable-text.js.map +1 -0
  184. package/dist/components/ui/empty-state.d.ts +11 -0
  185. package/dist/components/ui/empty-state.d.ts.map +1 -0
  186. package/dist/components/ui/empty-state.js +9 -0
  187. package/dist/components/ui/empty-state.js.map +1 -0
  188. package/dist/components/ui/error-state.d.ts +20 -0
  189. package/dist/components/ui/error-state.d.ts.map +1 -0
  190. package/dist/components/ui/error-state.js +17 -0
  191. package/dist/components/ui/error-state.js.map +1 -0
  192. package/dist/components/ui/field-button.d.ts +15 -0
  193. package/dist/components/ui/field-button.d.ts.map +1 -0
  194. package/dist/components/ui/field-button.js +18 -0
  195. package/dist/components/ui/field-button.js.map +1 -0
  196. package/dist/components/ui/file-preview.d.ts +5 -0
  197. package/dist/components/ui/file-preview.d.ts.map +1 -0
  198. package/dist/components/ui/file-preview.js +66 -0
  199. package/dist/components/ui/file-preview.js.map +1 -0
  200. package/dist/components/ui/file-uploader.d.ts +39 -0
  201. package/dist/components/ui/file-uploader.d.ts.map +1 -0
  202. package/dist/components/ui/file-uploader.js +111 -0
  203. package/dist/components/ui/file-uploader.js.map +1 -0
  204. package/dist/components/ui/filter-builder.d.ts +18 -0
  205. package/dist/components/ui/filter-builder.d.ts.map +1 -0
  206. package/dist/components/ui/filter-builder.js +98 -0
  207. package/dist/components/ui/filter-builder.js.map +1 -0
  208. package/dist/components/ui/focus-shell.d.ts +14 -0
  209. package/dist/components/ui/focus-shell.d.ts.map +1 -0
  210. package/dist/components/ui/focus-shell.js +13 -0
  211. package/dist/components/ui/focus-shell.js.map +1 -0
  212. package/dist/components/ui/handle-row.d.ts +25 -0
  213. package/dist/components/ui/handle-row.d.ts.map +1 -0
  214. package/dist/components/ui/handle-row.js +110 -0
  215. package/dist/components/ui/handle-row.js.map +1 -0
  216. package/dist/components/ui/header-bar.d.ts +5 -0
  217. package/dist/components/ui/header-bar.d.ts.map +1 -0
  218. package/dist/components/ui/header-bar.js +10 -0
  219. package/dist/components/ui/header-bar.js.map +1 -0
  220. package/dist/components/ui/hover-card.d.ts +6 -0
  221. package/dist/components/ui/hover-card.d.ts.map +1 -0
  222. package/dist/components/ui/hover-card.js +13 -0
  223. package/dist/components/ui/hover-card.js.map +1 -0
  224. package/dist/components/ui/image-block.d.ts +31 -0
  225. package/dist/components/ui/image-block.d.ts.map +1 -0
  226. package/dist/components/ui/image-block.js +103 -0
  227. package/dist/components/ui/image-block.js.map +1 -0
  228. package/dist/components/ui/image-card.d.ts +17 -0
  229. package/dist/components/ui/image-card.d.ts.map +1 -0
  230. package/dist/components/ui/image-card.js +39 -0
  231. package/dist/components/ui/image-card.js.map +1 -0
  232. package/dist/components/ui/image-framer.d.ts +24 -0
  233. package/dist/components/ui/image-framer.d.ts.map +1 -0
  234. package/dist/components/ui/image-framer.js +89 -0
  235. package/dist/components/ui/image-framer.js.map +1 -0
  236. package/dist/components/ui/image-viewer.d.ts +31 -0
  237. package/dist/components/ui/image-viewer.d.ts.map +1 -0
  238. package/dist/components/ui/image-viewer.js +114 -0
  239. package/dist/components/ui/image-viewer.js.map +1 -0
  240. package/dist/components/ui/image.d.ts +33 -0
  241. package/dist/components/ui/image.d.ts.map +1 -0
  242. package/dist/components/ui/image.js +61 -0
  243. package/dist/components/ui/image.js.map +1 -0
  244. package/dist/components/ui/index.d.ts +92 -0
  245. package/dist/components/ui/index.d.ts.map +1 -0
  246. package/dist/components/ui/index.js +92 -0
  247. package/dist/components/ui/index.js.map +1 -0
  248. package/dist/components/ui/input.d.ts +75 -0
  249. package/dist/components/ui/input.d.ts.map +1 -0
  250. package/dist/components/ui/input.js +245 -0
  251. package/dist/components/ui/input.js.map +1 -0
  252. package/dist/components/ui/link-block.d.ts +13 -0
  253. package/dist/components/ui/link-block.d.ts.map +1 -0
  254. package/dist/components/ui/link-block.js +21 -0
  255. package/dist/components/ui/link-block.js.map +1 -0
  256. package/dist/components/ui/list-detail.d.ts +23 -0
  257. package/dist/components/ui/list-detail.d.ts.map +1 -0
  258. package/dist/components/ui/list-detail.js +33 -0
  259. package/dist/components/ui/list-detail.js.map +1 -0
  260. package/dist/components/ui/listbox.d.ts +7 -0
  261. package/dist/components/ui/listbox.d.ts.map +1 -0
  262. package/dist/components/ui/listbox.js +29 -0
  263. package/dist/components/ui/listbox.js.map +1 -0
  264. package/dist/components/ui/mac-card.d.ts +15 -0
  265. package/dist/components/ui/mac-card.d.ts.map +1 -0
  266. package/dist/components/ui/mac-card.js +9 -0
  267. package/dist/components/ui/mac-card.js.map +1 -0
  268. package/dist/components/ui/month-picker.d.ts +13 -0
  269. package/dist/components/ui/month-picker.d.ts.map +1 -0
  270. package/dist/components/ui/month-picker.js +53 -0
  271. package/dist/components/ui/month-picker.js.map +1 -0
  272. package/dist/components/ui/multi-select.d.ts +22 -0
  273. package/dist/components/ui/multi-select.d.ts.map +1 -0
  274. package/dist/components/ui/multi-select.js +88 -0
  275. package/dist/components/ui/multi-select.js.map +1 -0
  276. package/dist/components/ui/nav-tree.d.ts +16 -0
  277. package/dist/components/ui/nav-tree.d.ts.map +1 -0
  278. package/dist/components/ui/nav-tree.js +41 -0
  279. package/dist/components/ui/nav-tree.js.map +1 -0
  280. package/dist/components/ui/page.d.ts +23 -0
  281. package/dist/components/ui/page.d.ts.map +1 -0
  282. package/dist/components/ui/page.js +28 -0
  283. package/dist/components/ui/page.js.map +1 -0
  284. package/dist/components/ui/pagination.d.ts +26 -0
  285. package/dist/components/ui/pagination.d.ts.map +1 -0
  286. package/dist/components/ui/pagination.js +54 -0
  287. package/dist/components/ui/pagination.js.map +1 -0
  288. package/dist/components/ui/picker-panel.d.ts +13 -0
  289. package/dist/components/ui/picker-panel.d.ts.map +1 -0
  290. package/dist/components/ui/picker-panel.js +19 -0
  291. package/dist/components/ui/picker-panel.js.map +1 -0
  292. package/dist/components/ui/popover.d.ts +8 -0
  293. package/dist/components/ui/popover.d.ts.map +1 -0
  294. package/dist/components/ui/popover.js +18 -0
  295. package/dist/components/ui/popover.js.map +1 -0
  296. package/dist/components/ui/progress.d.ts +19 -0
  297. package/dist/components/ui/progress.d.ts.map +1 -0
  298. package/dist/components/ui/progress.js +22 -0
  299. package/dist/components/ui/progress.js.map +1 -0
  300. package/dist/components/ui/property.d.ts +11 -0
  301. package/dist/components/ui/property.d.ts.map +1 -0
  302. package/dist/components/ui/property.js +18 -0
  303. package/dist/components/ui/property.js.map +1 -0
  304. package/dist/components/ui/radio-group.d.ts +8 -0
  305. package/dist/components/ui/radio-group.d.ts.map +1 -0
  306. package/dist/components/ui/radio-group.js +18 -0
  307. package/dist/components/ui/radio-group.js.map +1 -0
  308. package/dist/components/ui/rating.d.ts +14 -0
  309. package/dist/components/ui/rating.d.ts.map +1 -0
  310. package/dist/components/ui/rating.js +61 -0
  311. package/dist/components/ui/rating.js.map +1 -0
  312. package/dist/components/ui/save-status.d.ts +8 -0
  313. package/dist/components/ui/save-status.d.ts.map +1 -0
  314. package/dist/components/ui/save-status.js +31 -0
  315. package/dist/components/ui/save-status.js.map +1 -0
  316. package/dist/components/ui/segmented.d.ts +21 -0
  317. package/dist/components/ui/segmented.d.ts.map +1 -0
  318. package/dist/components/ui/segmented.js +12 -0
  319. package/dist/components/ui/segmented.js.map +1 -0
  320. package/dist/components/ui/select-menu.d.ts +12 -0
  321. package/dist/components/ui/select-menu.d.ts.map +1 -0
  322. package/dist/components/ui/select-menu.js +10 -0
  323. package/dist/components/ui/select-menu.js.map +1 -0
  324. package/dist/components/ui/select.d.ts +16 -0
  325. package/dist/components/ui/select.d.ts.map +1 -0
  326. package/dist/components/ui/select.js +45 -0
  327. package/dist/components/ui/select.js.map +1 -0
  328. package/dist/components/ui/selection-bar.d.ts +12 -0
  329. package/dist/components/ui/selection-bar.d.ts.map +1 -0
  330. package/dist/components/ui/selection-bar.js +15 -0
  331. package/dist/components/ui/selection-bar.js.map +1 -0
  332. package/dist/components/ui/separator.d.ts +4 -0
  333. package/dist/components/ui/separator.d.ts.map +1 -0
  334. package/dist/components/ui/separator.js +12 -0
  335. package/dist/components/ui/separator.js.map +1 -0
  336. package/dist/components/ui/settings-layout.d.ts +34 -0
  337. package/dist/components/ui/settings-layout.d.ts.map +1 -0
  338. package/dist/components/ui/settings-layout.js +16 -0
  339. package/dist/components/ui/settings-layout.js.map +1 -0
  340. package/dist/components/ui/share-link.d.ts +14 -0
  341. package/dist/components/ui/share-link.d.ts.map +1 -0
  342. package/dist/components/ui/share-link.js +16 -0
  343. package/dist/components/ui/share-link.js.map +1 -0
  344. package/dist/components/ui/sheet.d.ts +21 -0
  345. package/dist/components/ui/sheet.d.ts.map +1 -0
  346. package/dist/components/ui/sheet.js +53 -0
  347. package/dist/components/ui/sheet.js.map +1 -0
  348. package/dist/components/ui/sidebar.d.ts +82 -0
  349. package/dist/components/ui/sidebar.d.ts.map +1 -0
  350. package/dist/components/ui/sidebar.js +258 -0
  351. package/dist/components/ui/sidebar.js.map +1 -0
  352. package/dist/components/ui/skeleton.d.ts +8 -0
  353. package/dist/components/ui/skeleton.d.ts.map +1 -0
  354. package/dist/components/ui/skeleton.js +15 -0
  355. package/dist/components/ui/skeleton.js.map +1 -0
  356. package/dist/components/ui/spinner.d.ts +12 -0
  357. package/dist/components/ui/spinner.d.ts.map +1 -0
  358. package/dist/components/ui/spinner.js +14 -0
  359. package/dist/components/ui/spinner.js.map +1 -0
  360. package/dist/components/ui/spotlight.d.ts +23 -0
  361. package/dist/components/ui/spotlight.d.ts.map +1 -0
  362. package/dist/components/ui/spotlight.js +110 -0
  363. package/dist/components/ui/spotlight.js.map +1 -0
  364. package/dist/components/ui/stat-tile.d.ts +8 -0
  365. package/dist/components/ui/stat-tile.d.ts.map +1 -0
  366. package/dist/components/ui/stat-tile.js +9 -0
  367. package/dist/components/ui/stat-tile.js.map +1 -0
  368. package/dist/components/ui/step-dialog.d.ts +20 -0
  369. package/dist/components/ui/step-dialog.d.ts.map +1 -0
  370. package/dist/components/ui/step-dialog.js +36 -0
  371. package/dist/components/ui/step-dialog.js.map +1 -0
  372. package/dist/components/ui/steps-layout.d.ts +20 -0
  373. package/dist/components/ui/steps-layout.d.ts.map +1 -0
  374. package/dist/components/ui/steps-layout.js +26 -0
  375. package/dist/components/ui/steps-layout.js.map +1 -0
  376. package/dist/components/ui/switch.d.ts +8 -0
  377. package/dist/components/ui/switch.d.ts.map +1 -0
  378. package/dist/components/ui/switch.js +21 -0
  379. package/dist/components/ui/switch.js.map +1 -0
  380. package/dist/components/ui/table.d.ts +16 -0
  381. package/dist/components/ui/table.d.ts.map +1 -0
  382. package/dist/components/ui/table.js +76 -0
  383. package/dist/components/ui/table.js.map +1 -0
  384. package/dist/components/ui/tabs.d.ts +7 -0
  385. package/dist/components/ui/tabs.d.ts.map +1 -0
  386. package/dist/components/ui/tabs.js +19 -0
  387. package/dist/components/ui/tabs.js.map +1 -0
  388. package/dist/components/ui/theme-toggle.d.ts +16 -0
  389. package/dist/components/ui/theme-toggle.d.ts.map +1 -0
  390. package/dist/components/ui/theme-toggle.js +65 -0
  391. package/dist/components/ui/theme-toggle.js.map +1 -0
  392. package/dist/components/ui/time-list.d.ts +16 -0
  393. package/dist/components/ui/time-list.d.ts.map +1 -0
  394. package/dist/components/ui/time-list.js +49 -0
  395. package/dist/components/ui/time-list.js.map +1 -0
  396. package/dist/components/ui/time-picker.d.ts +47 -0
  397. package/dist/components/ui/time-picker.d.ts.map +1 -0
  398. package/dist/components/ui/time-picker.js +141 -0
  399. package/dist/components/ui/time-picker.js.map +1 -0
  400. package/dist/components/ui/toast.d.ts +18 -0
  401. package/dist/components/ui/toast.d.ts.map +1 -0
  402. package/dist/components/ui/toast.js +77 -0
  403. package/dist/components/ui/toast.js.map +1 -0
  404. package/dist/components/ui/toggle.d.ts +15 -0
  405. package/dist/components/ui/toggle.d.ts.map +1 -0
  406. package/dist/components/ui/toggle.js +55 -0
  407. package/dist/components/ui/toggle.js.map +1 -0
  408. package/dist/components/ui/tooltip.d.ts +15 -0
  409. package/dist/components/ui/tooltip.d.ts.map +1 -0
  410. package/dist/components/ui/tooltip.js +32 -0
  411. package/dist/components/ui/tooltip.js.map +1 -0
  412. package/dist/components/ui/top-bar.d.ts +25 -0
  413. package/dist/components/ui/top-bar.d.ts.map +1 -0
  414. package/dist/components/ui/top-bar.js +23 -0
  415. package/dist/components/ui/top-bar.js.map +1 -0
  416. package/dist/components/ui/typography.d.ts +40 -0
  417. package/dist/components/ui/typography.d.ts.map +1 -0
  418. package/dist/components/ui/typography.js +98 -0
  419. package/dist/components/ui/typography.js.map +1 -0
  420. package/dist/components/ui/video-block.d.ts +14 -0
  421. package/dist/components/ui/video-block.d.ts.map +1 -0
  422. package/dist/components/ui/video-block.js +22 -0
  423. package/dist/components/ui/video-block.js.map +1 -0
  424. package/dist/hooks/use-dismiss.d.ts +5 -0
  425. package/dist/hooks/use-dismiss.d.ts.map +1 -0
  426. package/dist/hooks/use-dismiss.js +23 -0
  427. package/dist/hooks/use-dismiss.js.map +1 -0
  428. package/dist/hooks/use-escape-first.d.ts +3 -0
  429. package/dist/hooks/use-escape-first.d.ts.map +1 -0
  430. package/dist/hooks/use-escape-first.js +27 -0
  431. package/dist/hooks/use-escape-first.js.map +1 -0
  432. package/dist/hooks/use-media-query.d.ts +5 -0
  433. package/dist/hooks/use-media-query.d.ts.map +1 -0
  434. package/dist/hooks/use-media-query.js +16 -0
  435. package/dist/hooks/use-media-query.js.map +1 -0
  436. package/dist/hooks/use-save-queue.d.ts +13 -0
  437. package/dist/hooks/use-save-queue.d.ts.map +1 -0
  438. package/dist/hooks/use-save-queue.js +57 -0
  439. package/dist/hooks/use-save-queue.js.map +1 -0
  440. package/dist/hooks/use-selection.d.ts +10 -0
  441. package/dist/hooks/use-selection.d.ts.map +1 -0
  442. package/dist/hooks/use-selection.js +52 -0
  443. package/dist/hooks/use-selection.js.map +1 -0
  444. package/dist/hooks/use-shared-transition.d.ts +3 -0
  445. package/dist/hooks/use-shared-transition.d.ts.map +1 -0
  446. package/dist/hooks/use-shared-transition.js +38 -0
  447. package/dist/hooks/use-shared-transition.js.map +1 -0
  448. package/dist/hooks/use-upload-queue.d.ts +22 -0
  449. package/dist/hooks/use-upload-queue.d.ts.map +1 -0
  450. package/dist/hooks/use-upload-queue.js +78 -0
  451. package/dist/hooks/use-upload-queue.js.map +1 -0
  452. package/dist/lib/accent.d.ts +5 -0
  453. package/dist/lib/accent.d.ts.map +1 -0
  454. package/dist/lib/accent.js +10 -0
  455. package/dist/lib/accent.js.map +1 -0
  456. package/dist/lib/bento.d.ts +17 -0
  457. package/dist/lib/bento.d.ts.map +1 -0
  458. package/dist/lib/bento.js +92 -0
  459. package/dist/lib/bento.js.map +1 -0
  460. package/dist/lib/database.d.ts +92 -0
  461. package/dist/lib/database.d.ts.map +1 -0
  462. package/dist/lib/database.js +272 -0
  463. package/dist/lib/database.js.map +1 -0
  464. package/dist/lib/dates.d.ts +30 -0
  465. package/dist/lib/dates.d.ts.map +1 -0
  466. package/dist/lib/dates.js +61 -0
  467. package/dist/lib/dates.js.map +1 -0
  468. package/dist/lib/document.d.ts +79 -0
  469. package/dist/lib/document.d.ts.map +1 -0
  470. package/dist/lib/document.js +11 -0
  471. package/dist/lib/document.js.map +1 -0
  472. package/dist/lib/embed.d.ts +14 -0
  473. package/dist/lib/embed.d.ts.map +1 -0
  474. package/dist/lib/embed.js +63 -0
  475. package/dist/lib/embed.js.map +1 -0
  476. package/dist/lib/files.d.ts +23 -0
  477. package/dist/lib/files.d.ts.map +1 -0
  478. package/dist/lib/files.js +69 -0
  479. package/dist/lib/files.js.map +1 -0
  480. package/dist/lib/justified.d.ts +50 -0
  481. package/dist/lib/justified.d.ts.map +1 -0
  482. package/dist/lib/justified.js +78 -0
  483. package/dist/lib/justified.js.map +1 -0
  484. package/dist/lib/keys.d.ts +18 -0
  485. package/dist/lib/keys.d.ts.map +1 -0
  486. package/dist/lib/keys.js +66 -0
  487. package/dist/lib/keys.js.map +1 -0
  488. package/dist/lib/number.d.ts +4 -0
  489. package/dist/lib/number.d.ts.map +1 -0
  490. package/dist/lib/number.js +33 -0
  491. package/dist/lib/number.js.map +1 -0
  492. package/dist/lib/pointer.d.ts +2 -0
  493. package/dist/lib/pointer.d.ts.map +1 -0
  494. package/dist/lib/pointer.js +4 -0
  495. package/dist/lib/pointer.js.map +1 -0
  496. package/dist/lib/prepare-image.d.ts +43 -0
  497. package/dist/lib/prepare-image.d.ts.map +1 -0
  498. package/dist/lib/prepare-image.js +105 -0
  499. package/dist/lib/prepare-image.js.map +1 -0
  500. package/dist/lib/rich-text-dom.d.ts +16 -0
  501. package/dist/lib/rich-text-dom.d.ts.map +1 -0
  502. package/dist/lib/rich-text-dom.js +145 -0
  503. package/dist/lib/rich-text-dom.js.map +1 -0
  504. package/dist/lib/rich-text.d.ts +15 -0
  505. package/dist/lib/rich-text.d.ts.map +1 -0
  506. package/dist/lib/rich-text.js +35 -0
  507. package/dist/lib/rich-text.js.map +1 -0
  508. package/dist/lib/spotlight.d.ts +22 -0
  509. package/dist/lib/spotlight.d.ts.map +1 -0
  510. package/dist/lib/spotlight.js +66 -0
  511. package/dist/lib/spotlight.js.map +1 -0
  512. package/dist/lib/theme.d.ts +6 -0
  513. package/dist/lib/theme.d.ts.map +1 -0
  514. package/dist/lib/theme.js +15 -0
  515. package/dist/lib/theme.js.map +1 -0
  516. package/dist/lib/time.d.ts +19 -0
  517. package/dist/lib/time.d.ts.map +1 -0
  518. package/dist/lib/time.js +91 -0
  519. package/dist/lib/time.js.map +1 -0
  520. package/dist/lib/tree.d.ts +17 -0
  521. package/dist/lib/tree.d.ts.map +1 -0
  522. package/dist/lib/tree.js +35 -0
  523. package/dist/lib/tree.js.map +1 -0
  524. package/dist/lib/utils.d.ts +3 -0
  525. package/dist/lib/utils.d.ts.map +1 -0
  526. package/dist/lib/utils.js +24 -0
  527. package/dist/lib/utils.js.map +1 -0
  528. package/dist/styles/notion.css +817 -0
  529. package/package.json +129 -5
  530. package/src/components/editor/block-text.tsx +271 -0
  531. package/src/components/editor/blocks.tsx +373 -0
  532. package/src/components/editor/document-editor.tsx +106 -0
  533. package/src/components/editor/document-view.tsx +205 -0
  534. package/src/components/editor/editor-state.tsx +298 -0
  535. package/src/components/editor/extensions/kit-blocks.tsx +452 -0
  536. package/src/components/editor/extensions/spoiler.tsx +81 -0
  537. package/src/components/editor/index.ts +10 -0
  538. package/src/components/editor/kinds.ts +158 -0
  539. package/src/components/editor/look.tsx +36 -0
  540. package/src/components/sketch/rough.tsx +90 -0
  541. package/src/components/three/model-viewer.tsx +514 -0
  542. package/src/components/ui/accent-picker.tsx +72 -0
  543. package/src/components/ui/address-field.tsx +57 -0
  544. package/src/components/ui/alert-dialog.tsx +136 -0
  545. package/src/components/ui/animated-height.tsx +34 -0
  546. package/src/components/ui/app-shell.tsx +140 -0
  547. package/src/components/ui/avatar.tsx +106 -0
  548. package/src/components/ui/badge.tsx +81 -0
  549. package/src/components/ui/banner.tsx +53 -0
  550. package/src/components/ui/breadcrumbs.tsx +25 -0
  551. package/src/components/ui/button.tsx +147 -0
  552. package/src/components/ui/calendar.tsx +101 -0
  553. package/src/components/ui/callout.tsx +61 -0
  554. package/src/components/ui/card.tsx +59 -0
  555. package/src/components/ui/checkbox.tsx +66 -0
  556. package/src/components/ui/choice-label.tsx +43 -0
  557. package/src/components/ui/collapsible.tsx +58 -0
  558. package/src/components/ui/collection-layout.tsx +69 -0
  559. package/src/components/ui/combobox.tsx +155 -0
  560. package/src/components/ui/command-menu.tsx +102 -0
  561. package/src/components/ui/context-menu.tsx +89 -0
  562. package/src/components/ui/copy-button.tsx +80 -0
  563. package/src/components/ui/database/calendar-view.tsx +180 -0
  564. package/src/components/ui/database/card-views.tsx +221 -0
  565. package/src/components/ui/database/cells.tsx +237 -0
  566. package/src/components/ui/database/database.tsx +279 -0
  567. package/src/components/ui/database/icons.ts +15 -0
  568. package/src/components/ui/database/table-view.tsx +311 -0
  569. package/src/components/ui/date-picker.tsx +208 -0
  570. package/src/components/ui/date-time-picker.tsx +123 -0
  571. package/src/components/ui/dialog.tsx +151 -0
  572. package/src/components/ui/document-layout.tsx +52 -0
  573. package/src/components/ui/dropdown-menu.tsx +185 -0
  574. package/src/components/ui/editable-text.tsx +142 -0
  575. package/src/components/ui/empty-state.tsx +35 -0
  576. package/src/components/ui/error-state.tsx +67 -0
  577. package/src/components/ui/field-button.tsx +70 -0
  578. package/src/components/ui/file-preview.tsx +80 -0
  579. package/src/components/ui/file-uploader.tsx +375 -0
  580. package/src/components/ui/filter-builder.tsx +304 -0
  581. package/src/components/ui/focus-shell.tsx +48 -0
  582. package/src/components/ui/handle-row.tsx +252 -0
  583. package/src/components/ui/header-bar.tsx +15 -0
  584. package/src/components/ui/hover-card.tsx +30 -0
  585. package/src/components/ui/image-block.tsx +238 -0
  586. package/src/components/ui/image-card.tsx +95 -0
  587. package/src/components/ui/image-framer.tsx +160 -0
  588. package/src/components/ui/image-viewer.tsx +230 -0
  589. package/src/components/ui/image.tsx +200 -0
  590. package/src/components/ui/index.ts +178 -0
  591. package/src/components/ui/input.tsx +471 -0
  592. package/src/components/ui/link-block.tsx +85 -0
  593. package/src/components/ui/list-detail.tsx +115 -0
  594. package/src/components/ui/listbox.ts +26 -0
  595. package/src/components/ui/mac-card.tsx +46 -0
  596. package/src/components/ui/month-picker.tsx +119 -0
  597. package/src/components/ui/multi-select.tsx +221 -0
  598. package/src/components/ui/nav-tree.tsx +92 -0
  599. package/src/components/ui/page.tsx +73 -0
  600. package/src/components/ui/pagination.tsx +143 -0
  601. package/src/components/ui/picker-panel.tsx +69 -0
  602. package/src/components/ui/popover.tsx +42 -0
  603. package/src/components/ui/progress.tsx +76 -0
  604. package/src/components/ui/property.tsx +33 -0
  605. package/src/components/ui/radio-group.tsx +61 -0
  606. package/src/components/ui/rating.tsx +122 -0
  607. package/src/components/ui/save-status.tsx +53 -0
  608. package/src/components/ui/segmented.tsx +74 -0
  609. package/src/components/ui/select-menu.tsx +54 -0
  610. package/src/components/ui/select.tsx +147 -0
  611. package/src/components/ui/selection-bar.tsx +50 -0
  612. package/src/components/ui/separator.tsx +30 -0
  613. package/src/components/ui/settings-layout.tsx +117 -0
  614. package/src/components/ui/share-link.tsx +66 -0
  615. package/src/components/ui/sheet.tsx +90 -0
  616. package/src/components/ui/sidebar.tsx +627 -0
  617. package/src/components/ui/skeleton.tsx +22 -0
  618. package/src/components/ui/spinner.tsx +28 -0
  619. package/src/components/ui/spotlight.tsx +222 -0
  620. package/src/components/ui/stat-tile.tsx +25 -0
  621. package/src/components/ui/step-dialog.tsx +104 -0
  622. package/src/components/ui/steps-layout.tsx +91 -0
  623. package/src/components/ui/switch.tsx +55 -0
  624. package/src/components/ui/table.tsx +99 -0
  625. package/src/components/ui/tabs.tsx +41 -0
  626. package/src/components/ui/theme-toggle.tsx +80 -0
  627. package/src/components/ui/time-list.tsx +106 -0
  628. package/src/components/ui/time-picker.tsx +344 -0
  629. package/src/components/ui/toast.tsx +132 -0
  630. package/src/components/ui/toggle.tsx +76 -0
  631. package/src/components/ui/tooltip.tsx +78 -0
  632. package/src/components/ui/top-bar.tsx +118 -0
  633. package/src/components/ui/typography.tsx +204 -0
  634. package/src/components/ui/video-block.tsx +66 -0
  635. package/src/hooks/use-dismiss.ts +24 -0
  636. package/src/hooks/use-escape-first.ts +25 -0
  637. package/src/hooks/use-media-query.ts +23 -0
  638. package/src/hooks/use-save-queue.ts +78 -0
  639. package/src/hooks/use-selection.ts +51 -0
  640. package/src/hooks/use-shared-transition.ts +40 -0
  641. package/src/hooks/use-upload-queue.ts +111 -0
  642. package/src/lib/accent.ts +11 -0
  643. package/src/lib/bento.ts +87 -0
  644. package/src/lib/database.ts +322 -0
  645. package/src/lib/dates.ts +75 -0
  646. package/src/lib/document.ts +55 -0
  647. package/src/lib/embed.ts +62 -0
  648. package/src/lib/files.ts +73 -0
  649. package/src/lib/justified.ts +106 -0
  650. package/src/lib/keys.ts +72 -0
  651. package/src/lib/number.ts +29 -0
  652. package/src/lib/pointer.ts +3 -0
  653. package/src/lib/prepare-image.ts +141 -0
  654. package/src/lib/rich-text-dom.ts +138 -0
  655. package/src/lib/rich-text.ts +50 -0
  656. package/src/lib/spotlight.ts +78 -0
  657. package/src/lib/theme.ts +18 -0
  658. package/src/lib/time.ts +83 -0
  659. package/src/lib/tree.ts +41 -0
  660. package/src/lib/utils.ts +25 -0
  661. package/src/styles/notion.css +817 -0
@@ -0,0 +1,106 @@
1
+ /* Rows of pictures that each fill the width exactly, like a contact sheet:
2
+ every row is one height, scaled so its pictures and the gaps between them
3
+ add up to the width. The heights are known before anything is drawn, which
4
+ is what lets a long list be virtualised without measuring.
5
+
6
+ Works on anything with an aspect ratio. Give `group` to start a new section
7
+ (with a heading line) whenever its value changes: months, say. */
8
+
9
+ export type Cell<T> = { item: T; width: number };
10
+ export type Line<T> =
11
+ | { kind: "heading"; key: string; label: string; height: number }
12
+ | { kind: "row"; key: string; height: number; cells: Cell<T>[] };
13
+
14
+ /** One height for every row, or a rhythm: a height chosen by the row's number. */
15
+ export type RowHeight = number | ((row: number) => number);
16
+
17
+ /** A row height from the room there is: about one and a half pictures across a phone, three a tablet, four a wide screen. */
18
+ export const rowHeightFor = (width: number): number => Math.round(Math.min(300, Math.max(170, width / 4.6)));
19
+
20
+ /** A magazine's rhythm: every fourth row is a tall one of one or two pictures, and the rows between alternate taller and shorter. For a selection, not an archive. */
21
+ export const editorialRhythm =
22
+ (width: number): ((row: number) => number) =>
23
+ (row) => {
24
+ const base = rowHeightFor(width);
25
+ if (row % 4 === 0) return Math.round(Math.min(560, Math.max(base * 1.5, width * 0.4)));
26
+ return Math.round(base * (row % 2 === 1 ? 1.2 : 0.95));
27
+ };
28
+
29
+ export function justify<T>(
30
+ items: T[],
31
+ width: number,
32
+ options: {
33
+ id: (item: T) => string;
34
+ /** Width over height. */
35
+ aspect: (item: T) => number;
36
+ rowHeight: RowHeight;
37
+ gap?: number;
38
+ /** A value that starts a new section when it changes, and that section's heading. */
39
+ group?: (item: T) => { key: string; label: string };
40
+ headingHeight?: number;
41
+ },
42
+ ): Line<T>[] {
43
+ const { id, aspect, rowHeight, gap = 12, group, headingHeight = 64 } = options;
44
+ const lines: Line<T>[] = [];
45
+ if (width <= 0) return lines;
46
+
47
+ // A panorama or a sliver would otherwise set the height of its whole row.
48
+ const clamped = (item: T): number => Math.min(Math.max(aspect(item), 0.5), 3);
49
+ let section = "";
50
+ let pending: T[] = [];
51
+ let ratios = 0;
52
+ let row = 0;
53
+ const target = (): number => (typeof rowHeight === "number" ? rowHeight : rowHeight(row));
54
+
55
+ const flush = (full: boolean): void => {
56
+ if (pending.length === 0) return;
57
+ const room = width - gap * (pending.length - 1);
58
+ // A last row that is not full keeps the target height and stays ragged;
59
+ // stretching three pictures across the page would blow them up.
60
+ const height = full ? room / ratios : Math.min(target(), room / ratios);
61
+ lines.push({ kind: "row", key: id(pending[0]), height: Math.round(height) + gap, cells: pending.map((item) => ({ item, width: height * clamped(item) })) });
62
+ pending = [];
63
+ ratios = 0;
64
+ row += 1;
65
+ };
66
+
67
+ for (const item of items) {
68
+ const next = group?.(item);
69
+ if (next !== undefined && next.key !== section) {
70
+ flush(false);
71
+ section = next.key;
72
+ lines.push({ kind: "heading", key: next.key, label: next.label, height: headingHeight });
73
+ }
74
+ pending.push(item);
75
+ ratios += clamped(item);
76
+ if (ratios * target() + gap * (pending.length - 1) >= width) flush(true);
77
+ }
78
+ flush(false);
79
+ return lines;
80
+ }
81
+
82
+ /* Pinterest columns: each picture at its own shape, dealt across the columns
83
+ in order like cards, so the board reads left to right and a last row that
84
+ is not full starts at the left. (Putting each in the shortest column packs
85
+ tighter but drops the last one wherever there is room.) Fewer pictures than
86
+ columns are centred. `below` is room under each picture for a caption. */
87
+ export function masonry<T>(
88
+ items: T[],
89
+ width: number,
90
+ options: { aspect: (item: T) => number; columns: number; gap?: number; below?: number },
91
+ ): { places: { item: T; x: number; y: number; width: number; height: number }[]; height: number } {
92
+ const { aspect, columns, gap = 22, below = 0 } = options;
93
+ if (width <= 0 || columns <= 0) return { places: [], height: 0 };
94
+ const column = (width - gap * (columns - 1)) / columns;
95
+ const heights = Array.from({ length: columns }, () => 0);
96
+ const used = Math.min(columns, items.length);
97
+ const inset = (width - (used * column + gap * (used - 1))) / 2;
98
+ const places = items.map((item, index) => {
99
+ const at = index % columns;
100
+ const height = column / aspect(item);
101
+ const y = heights[at];
102
+ heights[at] = y + height + below + gap;
103
+ return { item, x: inset + at * (column + gap), y, width: column, height };
104
+ });
105
+ return { places, height: Math.max(0, Math.max(...heights) - gap) };
106
+ }
@@ -0,0 +1,72 @@
1
+ /* Keyboard shortcuts written once, shown right on every platform. A shortcut is
2
+ written as "mod+shift+k": `mod` is ⌘ on Apple platforms and Ctrl elsewhere,
3
+ which is what the kit's own shortcuts listen for (⌘\, ⌘K). */
4
+
5
+ export type Platform = "apple" | "other";
6
+
7
+ /** Which platform the browser says it is. "other" on the server. */
8
+ export function platform(): Platform {
9
+ if (typeof navigator === "undefined") return "other";
10
+ const name = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform ?? navigator.platform ?? "";
11
+ return /mac|iphone|ipad|ipod/i.test(name) ? "apple" : "other";
12
+ }
13
+
14
+ type Key = { shown: string; spoken: string };
15
+
16
+ const NAMES: Record<string, Record<Platform, Key>> = {
17
+ mod: { apple: { shown: "⌘", spoken: "Command" }, other: { shown: "Ctrl", spoken: "Control" } },
18
+ ctrl: { apple: { shown: "⌃", spoken: "Control" }, other: { shown: "Ctrl", spoken: "Control" } },
19
+ alt: { apple: { shown: "⌥", spoken: "Option" }, other: { shown: "Alt", spoken: "Alt" } },
20
+ shift: { apple: { shown: "⇧", spoken: "Shift" }, other: { shown: "Shift", spoken: "Shift" } },
21
+ enter: { apple: { shown: "↵", spoken: "Enter" }, other: { shown: "Enter", spoken: "Enter" } },
22
+ backspace: { apple: { shown: "⌫", spoken: "Backspace" }, other: { shown: "Backspace", spoken: "Backspace" } },
23
+ escape: { apple: { shown: "Esc", spoken: "Escape" }, other: { shown: "Esc", spoken: "Escape" } },
24
+ tab: { apple: { shown: "⇥", spoken: "Tab" }, other: { shown: "Tab", spoken: "Tab" } },
25
+ up: { apple: { shown: "↑", spoken: "Up" }, other: { shown: "↑", spoken: "Up" } },
26
+ down: { apple: { shown: "↓", spoken: "Down" }, other: { shown: "↓", spoken: "Down" } },
27
+ left: { apple: { shown: "←", spoken: "Left" }, other: { shown: "←", spoken: "Left" } },
28
+ right: { apple: { shown: "→", spoken: "Right" }, other: { shown: "→", spoken: "Right" } },
29
+ "\\": { apple: { shown: "\\", spoken: "Backslash" }, other: { shown: "\\", spoken: "Backslash" } },
30
+ "/": { apple: { shown: "/", spoken: "Slash" }, other: { shown: "/", spoken: "Slash" } },
31
+ };
32
+
33
+ /** "mod+shift+k" → the keys as shown and as spoken on `on`. */
34
+ export function shortcutKeys(shortcut: string, on: Platform = platform()): Key[] {
35
+ return shortcut
36
+ .split("+")
37
+ .filter(Boolean)
38
+ .map((part) => {
39
+ const key = part.trim().toLowerCase();
40
+ return NAMES[key]?.[on] ?? { shown: key.length === 1 ? key.toUpperCase() : part.trim(), spoken: key.length === 1 ? key.toUpperCase() : part.trim() };
41
+ });
42
+ }
43
+
44
+ /** "mod+k" → "⌘K" on Apple, "Ctrl+K" elsewhere: for text, such as a tooltip. */
45
+ export function formatShortcut(shortcut: string, on: Platform = platform()): string {
46
+ return shortcutKeys(shortcut, on)
47
+ .map((k) => k.shown)
48
+ .join(on === "apple" ? "" : "+");
49
+ }
50
+
51
+ /** "mod+k" → "Command K": what a screen reader should say. */
52
+ export const speakShortcut = (shortcut: string, on: Platform = platform()): string =>
53
+ shortcutKeys(shortcut, on)
54
+ .map((k) => k.spoken)
55
+ .join(" ");
56
+
57
+ const KEY_NAMES: Record<string, string> = { enter: "enter", escape: "escape", tab: "tab", backspace: "backspace", up: "arrowup", down: "arrowdown", left: "arrowleft", right: "arrowright", space: " " };
58
+
59
+ /** Whether a key press is `shortcut` ("mod+k", "shift+?", "f8"). `mod` is ⌘ or Ctrl, either, as the kit's
60
+ own shortcuts take both. Modifiers not written must be up. Safe for the key events autofill sends with no key. */
61
+ export function matchShortcut(e: Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">, shortcut: string): boolean {
62
+ if (typeof e.key !== "string" || e.key === "") return false;
63
+ const parts = shortcut.toLowerCase().split("+");
64
+ const key = parts.pop()!;
65
+ const want = new Set(parts);
66
+ const mod = want.has("mod");
67
+ if (mod ? !(e.metaKey || e.ctrlKey) : e.metaKey !== want.has("meta") || e.ctrlKey !== want.has("ctrl")) return false;
68
+ if (e.altKey !== want.has("alt")) return false;
69
+ // A shifted symbol ("?") is its own key; shift is only checked when written, or for a letter.
70
+ if (want.has("shift") ? !e.shiftKey : e.shiftKey && /^[a-z0-9]$/.test(key)) return false;
71
+ return e.key.toLowerCase() === (KEY_NAMES[key] ?? key);
72
+ }
@@ -0,0 +1,29 @@
1
+ /* Reading a number someone typed, in whichever way they write numbers.
2
+
3
+ Currency signs, spaces and apostrophes (1'000, as in Switzerland) are ignored.
4
+ With both "," and ".", the last one is the decimal point: 1,234.5 and 1.234,5
5
+ are both one thousand two hundred and thirty-four and a half. With only commas,
6
+ they are thousands when every group after the first is three digits (1,234 and
7
+ 12,345,678), and otherwise the decimal point (12,5). With only points, one is the
8
+ decimal point and several are thousands (1.234.567).
9
+
10
+ Returns null for an empty field and NaN for anything that is not a number, so a
11
+ caller can tell "cleared" from "typed nonsense". */
12
+ export function parseNumber(text: string): number | null {
13
+ let s = text.replace(/[\s  '’$€£¥₹]/g, "").replace(/^\((.*)\)$/, "-$1");
14
+ if (s === "") return null;
15
+ const comma = s.lastIndexOf(",");
16
+ const point = s.lastIndexOf(".");
17
+ if (comma !== -1 && point !== -1) {
18
+ s = comma > point ? s.replace(/\./g, "").replace(",", ".") : s.replace(/,/g, "");
19
+ } else if (comma !== -1) {
20
+ s = /^[-+]?\d{1,3}(,\d{3})+$/.test(s) ? s.replace(/,/g, "") : s.replace(",", ".");
21
+ } else if ((s.match(/\./g) ?? []).length > 1) {
22
+ s = s.replace(/\./g, "");
23
+ }
24
+ if (!/^[-+]?(\d+\.?\d*|\.\d+)$/.test(s)) return Number.NaN;
25
+ return Number(s);
26
+ }
27
+
28
+ /** Keeps a number within `min` and `max`, either of which may be absent. */
29
+ export const clamp = (n: number, min?: number, max?: number): number => Math.min(max ?? Infinity, Math.max(min ?? -Infinity, n));
@@ -0,0 +1,3 @@
1
+ // Whether the device is driven by a mouse or trackpad rather than a finger. Asked at
2
+ // the moment of use, in the browser.
3
+ export const finePointer = (): boolean => typeof window !== "undefined" && window.matchMedia("(pointer: fine)").matches;
@@ -0,0 +1,141 @@
1
+ /* Turning a picture off a phone or a camera into what is worth uploading: a display
2
+ JPEG and a thumbnail, each under a byte budget, the right way up, never the
3
+ original. Three apps each wrote this (endgame, medialogue, triptrack); this is
4
+ the one, with their differences as options.
5
+
6
+ - The picture is turned upright from its EXIF orientation (createImageBitmap's
7
+ default) and drawn on white, so a cut-out PNG does not come out on black.
8
+ - It is halved until the last step is small: a canvas shrinking a picture to a
9
+ quarter or less in one go skips pixels and the result shimmers.
10
+ - Each copy is saved at the best quality that fits its budget, stepping down;
11
+ a photograph fits at the first. One that will not fit fails, rather than
12
+ sending what the server will refuse.
13
+ - `square` crops to the middle square first (an avatar, a cover).
14
+ - `hash` adds a SHA-256 of the original file, to spot a picture sent twice.
15
+
16
+ Browser only: it needs a canvas. */
17
+
18
+ export type ImageCopy = {
19
+ /** The longest edge, in pixels. */
20
+ edge?: number;
21
+ /** Or the height, for a thumbnail strip of even height. */
22
+ height?: number;
23
+ /** The most bytes the JPEG may be. */
24
+ bytes: number;
25
+ };
26
+
27
+ export type PreparedImage = {
28
+ display: Blob;
29
+ thumb: Blob;
30
+ /** The display copy's size. */
31
+ width: number;
32
+ height: number;
33
+ aspect: number;
34
+ /** SHA-256 of the original, as hex, when asked for. */
35
+ hash?: string;
36
+ };
37
+
38
+ export const QUALITIES = [0.82, 0.72, 0.6, 0.5, 0.4] as const;
39
+
40
+ const DEFAULTS = {
41
+ display: { edge: 1600, bytes: 1_000_000 },
42
+ thumb: { edge: 400, bytes: 140_000 },
43
+ } satisfies Record<string, ImageCopy>;
44
+
45
+ /** The size a picture of `width` × `height` becomes for `copy`, never larger than it was. */
46
+ export function fitSize(width: number, height: number, copy: Pick<ImageCopy, "edge" | "height">): { width: number; height: number } {
47
+ const scale = Math.min(1, copy.height !== undefined ? copy.height / height : (copy.edge ?? Infinity) / Math.max(width, height));
48
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
49
+ }
50
+
51
+ type Crop = { x: number; y: number; width: number; height: number };
52
+
53
+ function canvasOf(width: number, height: number): [HTMLCanvasElement, CanvasRenderingContext2D] {
54
+ const canvas = document.createElement("canvas");
55
+ canvas.width = width;
56
+ canvas.height = height;
57
+ const context = canvas.getContext("2d");
58
+ if (context === null) throw new Error("This browser could not resize the picture.");
59
+ context.fillStyle = "#fff";
60
+ context.fillRect(0, 0, width, height);
61
+ context.imageSmoothingQuality = "high";
62
+ return [canvas, context];
63
+ }
64
+
65
+ /** `source` (its `crop`) drawn at `width` × `height`, halving on the way so nothing shimmers. */
66
+ export function resizeTo(source: CanvasImageSource, crop: Crop, width: number, height: number): HTMLCanvasElement {
67
+ let current: CanvasImageSource = source;
68
+ let from = crop;
69
+ let w = crop.width;
70
+ let h = crop.height;
71
+ while (w / 2 >= width && h / 2 >= height) {
72
+ w = Math.round(w / 2);
73
+ h = Math.round(h / 2);
74
+ const [canvas, context] = canvasOf(w, h);
75
+ context.drawImage(current, from.x, from.y, from.width, from.height, 0, 0, w, h);
76
+ // A step's own canvas (never the caller's) is let go of once drawn from: iOS Safari caps the memory canvases may hold.
77
+ if (current !== source && current instanceof HTMLCanvasElement) current.width = 0;
78
+ current = canvas;
79
+ from = { x: 0, y: 0, width: w, height: h };
80
+ }
81
+ const [canvas, context] = canvasOf(width, height);
82
+ context.drawImage(current, from.x, from.y, from.width, from.height, 0, 0, width, height);
83
+ if (current !== source && current instanceof HTMLCanvasElement) current.width = 0;
84
+ return canvas;
85
+ }
86
+
87
+ const encode = (canvas: HTMLCanvasElement, quality: number): Promise<Blob> =>
88
+ new Promise((resolve, reject) =>
89
+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error("This browser could not save the picture."))), "image/jpeg", quality),
90
+ );
91
+
92
+ /** The best quality JPEG that fits in `bytes`. */
93
+ export async function jpegUnder(canvas: HTMLCanvasElement, bytes: number, qualities: readonly number[] = QUALITIES): Promise<Blob> {
94
+ let blob: Blob | null = null;
95
+ for (const quality of qualities) {
96
+ blob = await encode(canvas, quality);
97
+ if (blob.size <= bytes) return blob;
98
+ }
99
+ throw new Error("That picture would not shrink far enough to keep.");
100
+ }
101
+
102
+ const hex = (buffer: ArrayBuffer) => [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
103
+
104
+ export async function prepareImage(
105
+ file: Blob,
106
+ {
107
+ display = DEFAULTS.display,
108
+ thumb = DEFAULTS.thumb,
109
+ square = false,
110
+ hash = false,
111
+ qualities = QUALITIES,
112
+ }: { display?: ImageCopy; thumb?: ImageCopy; square?: boolean; hash?: boolean; qualities?: readonly number[] } = {},
113
+ ): Promise<PreparedImage> {
114
+ let bitmap: ImageBitmap;
115
+ try {
116
+ bitmap = await createImageBitmap(file);
117
+ } catch {
118
+ throw new Error("This browser cannot open that kind of picture.");
119
+ }
120
+ try {
121
+ const side = Math.min(bitmap.width, bitmap.height);
122
+ const crop: Crop = square
123
+ ? { x: Math.round((bitmap.width - side) / 2), y: Math.round((bitmap.height - side) / 2), width: side, height: side }
124
+ : { x: 0, y: 0, width: bitmap.width, height: bitmap.height };
125
+ const size = fitSize(crop.width, crop.height, display);
126
+ const big = resizeTo(bitmap, crop, size.width, size.height);
127
+ const small = fitSize(size.width, size.height, thumb);
128
+ const little = resizeTo(big, { x: 0, y: 0, width: size.width, height: size.height }, small.width, small.height);
129
+ return {
130
+ display: await jpegUnder(big, display.bytes, qualities),
131
+ thumb: await jpegUnder(little, thumb.bytes, qualities),
132
+ width: size.width,
133
+ height: size.height,
134
+ aspect: size.width / size.height,
135
+ ...(hash ? { hash: hex(await crypto.subtle.digest("SHA-256", await file.arrayBuffer())) } : null),
136
+ };
137
+ } finally {
138
+ // A 24 MP bitmap is about 100 MB; the next file should not wait for the collector.
139
+ bitmap.close();
140
+ }
141
+ }
@@ -0,0 +1,138 @@
1
+ import { isSafeHref } from "./embed.ts";
2
+ import { normalize, type Span, type Text } from "./rich-text.ts";
3
+
4
+ /* Bridges the span model and the DOM inside a contentEditable element. A link is
5
+ written and read back only when it is a web or mail address, so a `javascript:`
6
+ href pasted in as HTML never survives into the document. */
7
+
8
+ const escape = (s: string) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
9
+
10
+ const UNDERLINE = "link";
11
+ /** Inline code, the same in Code, the editor and the read view. */
12
+ export const CODE_CLASSES = "rounded-small bg-tag-red-bg/70 px-1.5 py-0.5 font-mono text-[0.85em] text-tag-red-ink";
13
+ const CODE = CODE_CLASSES;
14
+ const PAGE_ICON =
15
+ '<svg class="mr-1 mb-0.5 inline size-[1em] text-ink-secondary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>';
16
+
17
+ export function spansToHtml(text: Text): string {
18
+ return text
19
+ .map((span) => {
20
+ // A page link is one uneditable token, as a Notion mention is.
21
+ if (span.page)
22
+ return `<a data-page="${escape(span.page)}" href="/${escape(span.page)}" contenteditable="false" class="font-medium cursor-pointer rounded-small hover:bg-tint-hover">${PAGE_ICON}<span class="${UNDERLINE}">${escape(span.text)}</span></a>`;
23
+ let html = escape(span.text);
24
+ if (span.code) html = `<code class="${CODE}">${html}</code>`;
25
+ if (span.strike) html = `<s>${html}</s>`;
26
+ if (span.italic) html = `<em>${html}</em>`;
27
+ if (span.bold) html = `<strong class="font-semibold">${html}</strong>`;
28
+ if (span.href && isSafeHref(span.href)) html = `<a href="${escape(span.href)}" target="_blank" rel="noreferrer" class="${UNDERLINE}">${html}</a>`;
29
+ return html;
30
+ })
31
+ .join("");
32
+ }
33
+
34
+ type Marks = Omit<Span, "text">;
35
+
36
+ // Reads back whatever the browser left after an edit: our own tags, plus the <b>,
37
+ // <i>, <strike> and styled spans that execCommand produces.
38
+ export function readSpans(root: HTMLElement): Text {
39
+ const out: Text = [];
40
+ const walk = (node: Node, marks: Marks) => {
41
+ if (node.nodeType === Node.TEXT_NODE) {
42
+ out.push({ ...marks, text: (node.nodeValue ?? "").replace(/ /g, " ") });
43
+ return;
44
+ }
45
+ if (!(node instanceof HTMLElement)) return;
46
+ if (node.tagName === "BR") {
47
+ out.push({ ...marks, text: "\n" });
48
+ return;
49
+ }
50
+ if (node.dataset.page) {
51
+ out.push({ text: node.textContent ?? "", page: node.dataset.page });
52
+ return;
53
+ }
54
+ const m = { ...marks };
55
+ const tag = node.tagName;
56
+ const { fontWeight, fontStyle, textDecorationLine } = node.style;
57
+ if (tag === "B" || tag === "STRONG" || fontWeight === "bold" || Number(fontWeight) >= 600) m.bold = true;
58
+ if (fontWeight === "normal" || fontWeight === "400") delete m.bold;
59
+ if (tag === "I" || tag === "EM" || fontStyle === "italic") m.italic = true;
60
+ if (tag === "S" || tag === "STRIKE" || tag === "DEL" || textDecorationLine.includes("line-through")) m.strike = true;
61
+ if (tag === "CODE") m.code = true;
62
+ const href = tag === "A" ? node.getAttribute("href") : null;
63
+ if (href !== null && isSafeHref(href)) m.href = href;
64
+ node.childNodes.forEach((child) => walk(child, m));
65
+ };
66
+ root.childNodes.forEach((child) => walk(child, {}));
67
+ return normalize(out);
68
+ }
69
+
70
+ const length = (node: Node): number => {
71
+ if (node.nodeType === Node.TEXT_NODE) return node.nodeValue?.length ?? 0;
72
+ if (node instanceof HTMLElement && node.tagName === "BR") return 1;
73
+ let n = 0;
74
+ node.childNodes.forEach((child) => (n += length(child)));
75
+ return n;
76
+ };
77
+
78
+ // The caret as a character offset into the element's text, or null when the
79
+ // selection is elsewhere or is a range.
80
+ export function caretOffset(root: HTMLElement): number | null {
81
+ const sel = window.getSelection();
82
+ if (!sel || sel.rangeCount === 0 || !sel.isCollapsed) return null;
83
+ const range = sel.getRangeAt(0);
84
+ if (!root.contains(range.endContainer)) return null;
85
+ const before = document.createRange();
86
+ before.selectNodeContents(root);
87
+ before.setEnd(range.endContainer, range.endOffset);
88
+ return length(before.cloneContents());
89
+ }
90
+
91
+ export function setCaret(root: HTMLElement, at: number | "end"): void {
92
+ root.focus();
93
+ const sel = window.getSelection();
94
+ if (!sel) return;
95
+ const range = document.createRange();
96
+ range.selectNodeContents(root);
97
+ range.collapse(at !== "end");
98
+ if (typeof at === "number" && at > 0) {
99
+ let left = at;
100
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
101
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
102
+ const n = node.nodeValue?.length ?? 0;
103
+ if (left <= n) {
104
+ range.setStart(node, left);
105
+ range.collapse(true);
106
+ break;
107
+ }
108
+ left -= n;
109
+ }
110
+ }
111
+ sel.removeAllRanges();
112
+ sel.addRange(range);
113
+ }
114
+
115
+ export function caretRect(): DOMRect | null {
116
+ const sel = window.getSelection();
117
+ if (!sel || sel.rangeCount === 0) return null;
118
+ const range = sel.getRangeAt(0);
119
+ const rect = range.getClientRects()[0] ?? range.getBoundingClientRect();
120
+ // An empty line has no rects; fall back to the element the caret sits in.
121
+ if (rect.width === 0 && rect.height === 0 && range.startContainer instanceof Element)
122
+ return range.startContainer.getBoundingClientRect();
123
+ return rect;
124
+ }
125
+
126
+ /**
127
+ * Whether the caret sits on the first or the last visual line of `root`, where
128
+ * ArrowUp or ArrowDown leaves the block, as in Notion. Measured, because a
129
+ * wrapped paragraph has several lines and only its edges lead out. An empty
130
+ * block, or a caret the browser cannot place, counts as both.
131
+ */
132
+ export function caretOnEdgeLine(root: HTMLElement, edge: "first" | "last"): boolean {
133
+ const rect = caretRect();
134
+ if (rect === null || (rect.top === 0 && rect.bottom === 0)) return true;
135
+ const box = root.getBoundingClientRect();
136
+ const line = parseFloat(getComputedStyle(root).lineHeight) || rect.height || 20;
137
+ return edge === "first" ? rect.top - box.top < line * 0.8 : box.bottom - rect.bottom < line * 0.8;
138
+ }
@@ -0,0 +1,50 @@
1
+ // Rich text as data: a run of text is a list of spans, each with optional marks.
2
+ // Small enough to store as JSON and diff by eye, and the shape EditableText edits.
3
+ export type Span = {
4
+ text: string;
5
+ bold?: true;
6
+ italic?: true;
7
+ strike?: true;
8
+ code?: true;
9
+ href?: string;
10
+ // An in-app destination, rendered as a mention rather than a link: "docs/intro".
11
+ page?: string;
12
+ };
13
+ export type Text = Span[];
14
+
15
+ export const plain = (text: Text): string => text.map((s) => s.text).join("");
16
+
17
+ const sameMarks = (a: Span, b: Span) =>
18
+ a.bold === b.bold && a.italic === b.italic && a.strike === b.strike && a.code === b.code && a.href === b.href && a.page === b.page;
19
+
20
+ // Drops empty spans and merges neighbours that carry the same marks. A page link
21
+ // never merges: two links to one page side by side are still two links.
22
+ export function normalize(text: Text): Text {
23
+ const out: Text = [];
24
+ for (const span of text) {
25
+ if (span.text === "") continue;
26
+ const last = out.at(-1);
27
+ if (last && !span.page && sameMarks(last, span)) out[out.length - 1] = { ...last, text: last.text + span.text };
28
+ else out.push(span);
29
+ }
30
+ return out;
31
+ }
32
+
33
+ // Splits at a character offset into what comes before and what comes after.
34
+ export function split(text: Text, at: number): [Text, Text] {
35
+ const before: Text = [];
36
+ const after: Text = [];
37
+ let seen = 0;
38
+ for (const span of text) {
39
+ const cut = Math.min(Math.max(at - seen, 0), span.text.length);
40
+ before.push({ ...span, text: span.text.slice(0, cut) });
41
+ after.push({ ...span, text: span.text.slice(cut) });
42
+ seen += span.text.length;
43
+ }
44
+ return [normalize(before), normalize(after)];
45
+ }
46
+
47
+ // Removes the characters in [from, to).
48
+ export function cut(text: Text, from: number, to: number): Text {
49
+ return normalize([...split(text, from)[0], ...split(text, to)[1]]);
50
+ }
@@ -0,0 +1,78 @@
1
+ /* Ranking for the Spotlight: what was typed against a list of places to go.
2
+
3
+ Every word typed has to be found somewhere in an entry — its label, or the
4
+ quieter words around it (its hint, its group, keywords) — so "korea money" finds
5
+ the Money page of the Korea trip. A word found in the label counts for more,
6
+ and more again at the start of the label or of one of its words; a word whose
7
+ letters only appear in order ("gwngjng") still counts, for the label alone. */
8
+
9
+ export type SpotlightEntry = {
10
+ key: string;
11
+ label: string;
12
+ /** Shown after the label, and searched: where the page lives, what it is. */
13
+ hint?: string;
14
+ /** Heads a run of entries while nothing is typed; searched too. */
15
+ group?: string;
16
+ /** Searched but never shown: other names for the same page. */
17
+ keywords?: string[];
18
+ };
19
+
20
+ export type Ranked<T> = { item: T; score: number; hits: number[] };
21
+
22
+ const wordStart = (text: string, at: number) => at === 0 || !/[\p{L}\p{N}]/u.test(text[at - 1]!);
23
+
24
+ /** The positions of `word`'s letters, in order, in `text`, or null. */
25
+ function inOrder(text: string, word: string): number[] | null {
26
+ const hits: number[] = [];
27
+ let from = 0;
28
+ for (const ch of word) {
29
+ const at = text.indexOf(ch, from);
30
+ if (at < 0) return null;
31
+ hits.push(at);
32
+ from = at + 1;
33
+ }
34
+ return hits;
35
+ }
36
+
37
+ function scoreWord(label: string, rest: string, word: string): { score: number; hits: number[] } | null {
38
+ const at = label.indexOf(word);
39
+ if (at >= 0) {
40
+ const hits = Array.from({ length: word.length }, (_, k) => at + k);
41
+ return { score: at === 0 ? 100 : wordStart(label, at) ? 80 : 50, hits };
42
+ }
43
+ const elsewhere = rest.indexOf(word);
44
+ if (elsewhere >= 0) return { score: wordStart(rest, elsewhere) ? 30 : 15, hits: [] };
45
+ const scattered = word.length > 1 ? inOrder(label, word) : null;
46
+ return scattered === null ? null : { score: 20, hits: scattered };
47
+ }
48
+
49
+ /**
50
+ * The entries that match `query`, best first, each with the label positions to
51
+ * highlight. Nothing typed keeps every entry in the order given; equal scores
52
+ * keep that order too, so the owner's ordering breaks ties.
53
+ */
54
+ export function rankEntries<T extends SpotlightEntry>(entries: T[], query: string): Ranked<T>[] {
55
+ const words = query.toLowerCase().split(/\s+/).filter(Boolean);
56
+ if (words.length === 0) return entries.map((item) => ({ item, score: 0, hits: [] }));
57
+
58
+ const ranked: Ranked<T>[] = [];
59
+ for (const item of entries) {
60
+ const label = item.label.toLowerCase();
61
+ const rest = [item.hint, item.group, ...(item.keywords ?? [])].filter(Boolean).join(" · ").toLowerCase();
62
+ let score = 0;
63
+ const hits = new Set<number>();
64
+ let matched = true;
65
+ for (const word of words) {
66
+ const found = scoreWord(label, rest, word);
67
+ if (found === null) {
68
+ matched = false;
69
+ break;
70
+ }
71
+ score += found.score;
72
+ for (const h of found.hits) hits.add(h);
73
+ }
74
+ // A short label that matches is a closer match than a long one.
75
+ if (matched) ranked.push({ item, score: score - label.length / 100, hits: [...hits].sort((a, b) => a - b) });
76
+ }
77
+ return ranked.sort((a, b) => b.score - a.score);
78
+ }
@@ -0,0 +1,18 @@
1
+ /* Light, dark, or whatever the system says, kept in localStorage under a key the app
2
+ chooses (each app on one domain wants its own). Dark mode is the `dark` class on
3
+ <html>; the stylesheet does the rest.
4
+
5
+ themeInitScript() is the same choice made before first paint, so a reload never
6
+ flashes the wrong theme: put it in a <script> in <head> (index.html in Vite,
7
+ `dangerouslySetInnerHTML` in Next's root layout). It also applies the colour theme
8
+ kept by AccentPicker. */
9
+
10
+ export type Theme = "light" | "dark" | "system";
11
+ export const THEMES: readonly Theme[] = ["light", "dark", "system"];
12
+ export const THEME_KEY = "theme";
13
+
14
+ export const isTheme = (value: unknown): value is Theme => value === "light" || value === "dark" || value === "system";
15
+
16
+ export function themeInitScript(storageKey: string = THEME_KEY): string {
17
+ return `try{var t=localStorage.getItem(${JSON.stringify(storageKey)});if(t==="dark"||((t===null||t==="system")&&matchMedia("(prefers-color-scheme: dark)").matches))document.documentElement.classList.add("dark");var a=localStorage.getItem("accent");if(a&&a!=="paper")document.documentElement.dataset.accent=a}catch(e){}`;
18
+ }