@kerf-js/veneer 0.0.0-stage → 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 (389) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +1338 -2
  3. package/package.json +56 -3
  4. package/plugin.d.mts +187 -0
  5. package/plugin.mjs +399 -0
  6. package/src/Accordion.tsx +98 -0
  7. package/src/Alert.tsx +55 -0
  8. package/src/Badge.tsx +39 -0
  9. package/src/Button.tsx +175 -0
  10. package/src/Calendar-month.tsx +140 -0
  11. package/src/Calendar.tsx +335 -0
  12. package/src/Canvas.tsx +221 -0
  13. package/src/Card.tsx +85 -0
  14. package/src/Chart.tsx +278 -0
  15. package/src/Charts.tsx +158 -0
  16. package/src/Chip.tsx +61 -0
  17. package/src/Choice-checkbox.tsx +53 -0
  18. package/src/Choice-parts.tsx +7 -0
  19. package/src/Choice-radio.tsx +78 -0
  20. package/src/Choice-segmented.tsx +76 -0
  21. package/src/Choice-switch.tsx +51 -0
  22. package/src/Choice.tsx +4 -0
  23. package/src/CloseX.tsx +14 -0
  24. package/src/CodeBlock.tsx +81 -0
  25. package/src/CodeInput.tsx +256 -0
  26. package/src/Combobox.tsx +281 -0
  27. package/src/CommandPalette-controller.ts +314 -0
  28. package/src/CommandPalette-rows.tsx +137 -0
  29. package/src/CommandPalette.tsx +196 -0
  30. package/src/DataGrid-actions.ts +119 -0
  31. package/src/DataGrid-body.tsx +58 -0
  32. package/src/DataGrid-controller.ts +145 -0
  33. package/src/DataGrid-header.tsx +108 -0
  34. package/src/DataGrid-model.ts +248 -0
  35. package/src/DataGrid-pivot.tsx +108 -0
  36. package/src/DataGrid-rows.tsx +296 -0
  37. package/src/DataGrid-toolbar.tsx +127 -0
  38. package/src/DataGrid-tree.ts +149 -0
  39. package/src/DataGrid-viewport.tsx +37 -0
  40. package/src/DataGrid.tsx +145 -0
  41. package/src/DateField-presets.tsx +27 -0
  42. package/src/DateField-range.tsx +370 -0
  43. package/src/DateField.tsx +295 -0
  44. package/src/Dither.tsx +313 -0
  45. package/src/Drawer.tsx +123 -0
  46. package/src/DurationField.tsx +227 -0
  47. package/src/Feed.tsx +78 -0
  48. package/src/Field/view.tsx +147 -0
  49. package/src/Field.tsx +238 -0
  50. package/src/HamburgerMenu.tsx +119 -0
  51. package/src/Icon.tsx +15 -0
  52. package/src/Kbd.tsx +6 -0
  53. package/src/KeyValueEditor/actions.ts +75 -0
  54. package/src/KeyValueEditor/rows.tsx +104 -0
  55. package/src/KeyValueEditor.tsx +112 -0
  56. package/src/Layout.tsx +221 -0
  57. package/src/Markdown.tsx +127 -0
  58. package/src/MentionsInput/actions.ts +161 -0
  59. package/src/MentionsInput/end.tsx +82 -0
  60. package/src/MentionsInput.tsx +103 -0
  61. package/src/Menu.tsx +221 -0
  62. package/src/Modal.tsx +109 -0
  63. package/src/MonthPicker/month.tsx +117 -0
  64. package/src/MonthPicker/period.tsx +197 -0
  65. package/src/MonthPicker/shared.tsx +272 -0
  66. package/src/MonthPicker/week.tsx +103 -0
  67. package/src/MonthPicker.tsx +11 -0
  68. package/src/MultiSelect.tsx +139 -0
  69. package/src/Nav.tsx +36 -0
  70. package/src/NumberField.tsx +156 -0
  71. package/src/Pagination.tsx +335 -0
  72. package/src/PaymentCard.tsx +111 -0
  73. package/src/Picker.tsx +228 -0
  74. package/src/PlaceField.tsx +285 -0
  75. package/src/Popover.tsx +88 -0
  76. package/src/Presence.tsx +37 -0
  77. package/src/Progress.tsx +71 -0
  78. package/src/RecurrenceField.tsx +372 -0
  79. package/src/RichSelect/codes.tsx +94 -0
  80. package/src/RichSelect/list.tsx +380 -0
  81. package/src/RichSelect/phone-view.tsx +114 -0
  82. package/src/RichSelect/phone.tsx +305 -0
  83. package/src/RichSelect/search-keys.ts +28 -0
  84. package/src/RichSelect/timezone.tsx +53 -0
  85. package/src/RichSelect.tsx +13 -0
  86. package/src/RichTextEditor/controller.tsx +305 -0
  87. package/src/RichTextEditor/editor.tsx +61 -0
  88. package/src/RichTextEditor/tools.tsx +132 -0
  89. package/src/RichTextEditor/view.tsx +210 -0
  90. package/src/RichTextEditor.tsx +9 -0
  91. package/src/ScrollGrid/measure.ts +39 -0
  92. package/src/ScrollGrid/parts.tsx +112 -0
  93. package/src/ScrollGrid.tsx +375 -0
  94. package/src/ScrollRail.tsx +114 -0
  95. package/src/ScrollView.tsx +57 -0
  96. package/src/Segments/controller.tsx +148 -0
  97. package/src/Segments/events.ts +99 -0
  98. package/src/Segments/view.tsx +77 -0
  99. package/src/Segments.tsx +2 -0
  100. package/src/Select.tsx +343 -0
  101. package/src/Shape.tsx +41 -0
  102. package/src/Shell/branches.tsx +108 -0
  103. package/src/Shell/button.tsx +33 -0
  104. package/src/Shell/shared.tsx +220 -0
  105. package/src/Shell/shell.tsx +25 -0
  106. package/src/Shell/state.ts +138 -0
  107. package/src/Shell/view.tsx +280 -0
  108. package/src/Shell.tsx +17 -0
  109. package/src/SideNav/sections.tsx +50 -0
  110. package/src/SideNav/state.ts +140 -0
  111. package/src/SideNav.tsx +130 -0
  112. package/src/SideNavTitle.tsx +25 -0
  113. package/src/SignaturePad/state.ts +172 -0
  114. package/src/SignaturePad/view.tsx +69 -0
  115. package/src/SignaturePad.tsx +76 -0
  116. package/src/Skeleton.tsx +46 -0
  117. package/src/Slider.tsx +81 -0
  118. package/src/Spinner.tsx +21 -0
  119. package/src/Stage-director.ts +361 -0
  120. package/src/Stage-look.ts +75 -0
  121. package/src/Stage-poster.tsx +62 -0
  122. package/src/Stage-types.ts +206 -0
  123. package/src/Stage.tsx +147 -0
  124. package/src/TabBar.tsx +114 -0
  125. package/src/Table-actions.tsx +51 -0
  126. package/src/Table-base.ts +70 -0
  127. package/src/Table-body.tsx +84 -0
  128. package/src/Table-columns.tsx +58 -0
  129. package/src/Table-details.tsx +66 -0
  130. package/src/Table-editor.tsx +66 -0
  131. package/src/Table-head.tsx +52 -0
  132. package/src/Table-model.ts +82 -0
  133. package/src/Table-notice.ts +39 -0
  134. package/src/Table-paging.ts +50 -0
  135. package/src/Table-rows.tsx +308 -0
  136. package/src/Table-selection.ts +63 -0
  137. package/src/Table-sortbar.tsx +41 -0
  138. package/src/Table-source.ts +66 -0
  139. package/src/Table-toolbar.tsx +71 -0
  140. package/src/Table-types.ts +115 -0
  141. package/src/Table-view.tsx +87 -0
  142. package/src/Table.tsx +31 -0
  143. package/src/Tabs.tsx +129 -0
  144. package/src/Tag.tsx +40 -0
  145. package/src/Ticker.tsx +42 -0
  146. package/src/TimeField-date-model.ts +77 -0
  147. package/src/TimeField-date-view.tsx +152 -0
  148. package/src/TimeField-model.ts +80 -0
  149. package/src/TimeField-options.tsx +224 -0
  150. package/src/TimeField-slots.tsx +32 -0
  151. package/src/TimeField-types.ts +33 -0
  152. package/src/TimeField-view.tsx +124 -0
  153. package/src/TimeField.tsx +126 -0
  154. package/src/Toast.tsx +143 -0
  155. package/src/Toggle.tsx +75 -0
  156. package/src/Tooltip.tsx +69 -0
  157. package/src/Type.tsx +136 -0
  158. package/src/VirtualList-controls.ts +105 -0
  159. package/src/VirtualList-data.ts +43 -0
  160. package/src/VirtualList-measure.ts +169 -0
  161. package/src/VirtualList-metrics.ts +41 -0
  162. package/src/VirtualList-mount.ts +145 -0
  163. package/src/VirtualList-rows.tsx +91 -0
  164. package/src/VirtualList-types.ts +76 -0
  165. package/src/VirtualList-view.tsx +123 -0
  166. package/src/VirtualList.tsx +81 -0
  167. package/src/admin/ApiKeys-actions.ts +124 -0
  168. package/src/admin/ApiKeys-form.tsx +64 -0
  169. package/src/admin/ApiKeys-view.tsx +101 -0
  170. package/src/admin/ApiKeys.tsx +224 -0
  171. package/src/admin/Audit.tsx +246 -0
  172. package/src/admin/Billing.tsx +307 -0
  173. package/src/admin/Cart.tsx +177 -0
  174. package/src/admin/Checkout-address.tsx +125 -0
  175. package/src/admin/Checkout-cart.tsx +78 -0
  176. package/src/admin/Checkout-coupon.ts +34 -0
  177. package/src/admin/Checkout-done.tsx +31 -0
  178. package/src/admin/Checkout-model.ts +33 -0
  179. package/src/admin/Checkout-navigation.ts +76 -0
  180. package/src/admin/Checkout-payment-view.tsx +49 -0
  181. package/src/admin/Checkout-payment.ts +80 -0
  182. package/src/admin/Checkout-review.tsx +60 -0
  183. package/src/admin/Checkout-shipping.tsx +47 -0
  184. package/src/admin/Checkout-state.ts +122 -0
  185. package/src/admin/Checkout-steps.ts +10 -0
  186. package/src/admin/Checkout-summary.tsx +97 -0
  187. package/src/admin/Checkout-types.ts +60 -0
  188. package/src/admin/Checkout-view.tsx +51 -0
  189. package/src/admin/Checkout.tsx +72 -0
  190. package/src/admin/CsvImport-actions.ts +131 -0
  191. package/src/admin/CsvImport.tsx +379 -0
  192. package/src/admin/Danger.tsx +240 -0
  193. package/src/admin/Integrations/Card.tsx +82 -0
  194. package/src/admin/Integrations/Webhooks.tsx +341 -0
  195. package/src/admin/Integrations.tsx +169 -0
  196. package/src/admin/InviteDialog.tsx +153 -0
  197. package/src/admin/Members/columns.tsx +181 -0
  198. package/src/admin/Members.tsx +316 -0
  199. package/src/admin/Order.tsx +115 -0
  200. package/src/admin/PlainTable.tsx +34 -0
  201. package/src/admin/Plans.tsx +375 -0
  202. package/src/admin/SaveBar/actions.ts +86 -0
  203. package/src/admin/SaveBar.tsx +153 -0
  204. package/src/admin/Secret.tsx +74 -0
  205. package/src/admin/Settings.tsx +145 -0
  206. package/src/admin/StepBar.tsx +66 -0
  207. package/src/admin/TagsInput/actions.ts +60 -0
  208. package/src/admin/TagsInput.tsx +95 -0
  209. package/src/admin/atoms.tsx +73 -0
  210. package/src/admin/index.ts +67 -0
  211. package/src/agent/Actions/reasons.tsx +38 -0
  212. package/src/agent/Actions.tsx +166 -0
  213. package/src/agent/AgentPlan.tsx +86 -0
  214. package/src/agent/ArtifactPanel.tsx +299 -0
  215. package/src/agent/Assistant.tsx +168 -0
  216. package/src/agent/Checkpoint.tsx +19 -0
  217. package/src/agent/Cite.tsx +70 -0
  218. package/src/agent/ContextMeter.tsx +70 -0
  219. package/src/agent/Conversation.tsx +70 -0
  220. package/src/agent/Message.tsx +92 -0
  221. package/src/agent/ModelPicker.tsx +167 -0
  222. package/src/agent/Prompt-model.ts +118 -0
  223. package/src/agent/Prompt-view.tsx +246 -0
  224. package/src/agent/Prompt.tsx +128 -0
  225. package/src/agent/Prose.tsx +118 -0
  226. package/src/agent/Question.tsx +137 -0
  227. package/src/agent/Reasoning.tsx +31 -0
  228. package/src/agent/Shimmer.tsx +11 -0
  229. package/src/agent/Sources.tsx +23 -0
  230. package/src/agent/SpeechInput.tsx +243 -0
  231. package/src/agent/Suggestions.tsx +36 -0
  232. package/src/agent/ToolCall.tsx +219 -0
  233. package/src/agent/TraceViewer.tsx +96 -0
  234. package/src/agent/bits.tsx +88 -0
  235. package/src/agent/index.ts +38 -0
  236. package/src/bind.ts +57 -0
  237. package/src/collab/AutoTrack.tsx +91 -0
  238. package/src/collab/Comments.tsx +204 -0
  239. package/src/collab/Composer/state.ts +125 -0
  240. package/src/collab/Composer/view.tsx +155 -0
  241. package/src/collab/Composer.tsx +141 -0
  242. package/src/collab/ConversationList.tsx +120 -0
  243. package/src/collab/Cursors.tsx +71 -0
  244. package/src/collab/DataIntegrity.tsx +103 -0
  245. package/src/collab/Kanban-card.ts +74 -0
  246. package/src/collab/Kanban.tsx +368 -0
  247. package/src/collab/Lock.tsx +36 -0
  248. package/src/collab/PresenceStack.tsx +176 -0
  249. package/src/collab/ShareDialog.tsx +273 -0
  250. package/src/collab/Status.tsx +101 -0
  251. package/src/collab/SyncedForm.tsx +42 -0
  252. package/src/collab/Thread/Message.tsx +265 -0
  253. package/src/collab/Thread/rows.tsx +56 -0
  254. package/src/collab/Thread.tsx +323 -0
  255. package/src/collab/VersionHistory.tsx +173 -0
  256. package/src/collab/ViewportRail.tsx +73 -0
  257. package/src/collab/index.ts +37 -0
  258. package/src/collab/peer.tsx +42 -0
  259. package/src/fields.ts +5 -0
  260. package/src/flow/AuthScreen.tsx +81 -0
  261. package/src/flow/AuthSteps.tsx +296 -0
  262. package/src/flow/Checklist.tsx +211 -0
  263. package/src/flow/ConnBanner.tsx +304 -0
  264. package/src/flow/Flow.tsx +97 -0
  265. package/src/flow/MfaSetup.tsx +244 -0
  266. package/src/flow/Otp.tsx +243 -0
  267. package/src/flow/ReauthDialog.tsx +79 -0
  268. package/src/flow/ShortcutsOverlay.tsx +121 -0
  269. package/src/flow/SignGate.tsx +184 -0
  270. package/src/flow/SignIn.tsx +136 -0
  271. package/src/flow/SignUp.tsx +149 -0
  272. package/src/flow/Sso.tsx +96 -0
  273. package/src/flow/SystemPage/accounts.tsx +74 -0
  274. package/src/flow/SystemPage/art.tsx +113 -0
  275. package/src/flow/SystemPage.tsx +395 -0
  276. package/src/flow/Tour.tsx +207 -0
  277. package/src/flow/index.ts +29 -0
  278. package/src/flow/kit.tsx +334 -0
  279. package/src/index.ts +237 -0
  280. package/src/layout.css +4 -0
  281. package/src/links.css +4 -0
  282. package/src/live/ActivityFeed.tsx +88 -0
  283. package/src/live/Bell.tsx +108 -0
  284. package/src/live/Connection.tsx +113 -0
  285. package/src/live/Inbox.tsx +113 -0
  286. package/src/live/InboxFeed.tsx +67 -0
  287. package/src/live/InboxGestures.ts +41 -0
  288. package/src/live/InboxHandlers.ts +102 -0
  289. package/src/live/InboxHeader.tsx +81 -0
  290. package/src/live/InboxModel.ts +81 -0
  291. package/src/live/InboxRow.tsx +125 -0
  292. package/src/live/MeetingRoom.tsx +22 -0
  293. package/src/live/MeetingRoomControlBar.tsx +197 -0
  294. package/src/live/MeetingRoomHandlers.ts +53 -0
  295. package/src/live/MeetingRoomLayout.tsx +27 -0
  296. package/src/live/MeetingRoomModel.ts +49 -0
  297. package/src/live/MeetingRoomMount.ts +49 -0
  298. package/src/live/MeetingRoomParts.tsx +178 -0
  299. package/src/live/MeetingRoomPerson.tsx +21 -0
  300. package/src/live/MeetingRoomState.ts +88 -0
  301. package/src/live/MeetingRoomTile.tsx +84 -0
  302. package/src/live/MeetingRoomTypes.ts +68 -0
  303. package/src/live/MeetingRoomView.tsx +36 -0
  304. package/src/live/NotificationPreferences.tsx +99 -0
  305. package/src/live/NotificationPreferencesActions.ts +55 -0
  306. package/src/live/NotificationPreferencesCell.tsx +26 -0
  307. package/src/live/NotificationPreferencesCells.tsx +59 -0
  308. package/src/live/NotificationPreferencesGrid.tsx +129 -0
  309. package/src/live/NotificationPreferencesModel.tsx +91 -0
  310. package/src/live/NotificationPreferencesSave.ts +85 -0
  311. package/src/live/NotificationPreferencesWatch.ts +31 -0
  312. package/src/live/Prejoin.tsx +238 -0
  313. package/src/live/PrejoinMeter.tsx +26 -0
  314. package/src/live/PrejoinPreview.tsx +53 -0
  315. package/src/live/PushSoftAsk.tsx +63 -0
  316. package/src/live/TransportPicker.tsx +341 -0
  317. package/src/live/TransportPickerDetails.tsx +130 -0
  318. package/src/live/index.ts +31 -0
  319. package/src/live/notify.tsx +22 -0
  320. package/src/live/shared.tsx +110 -0
  321. package/src/parts.tsx +199 -0
  322. package/src/plugin/catalog.mjs +129 -0
  323. package/src/plugin/dtcg.mjs +79 -0
  324. package/src/plugin/icons.mjs +7 -0
  325. package/src/plugin/seed.mjs +40 -0
  326. package/src/plugin/theme-context.mjs +44 -0
  327. package/src/plugin/theme-css.mjs +143 -0
  328. package/src/plugin/theme-motion.mjs +43 -0
  329. package/src/plugin/theme-parts.d.mts +41 -0
  330. package/src/plugin/theme-parts.mjs +224 -0
  331. package/src/plugin/theme-text.mjs +93 -0
  332. package/src/plugin/theme-values.mjs +15 -0
  333. package/src/plugin/theme.d.mts +82 -0
  334. package/src/plugin/theme.mjs +316 -0
  335. package/src/schedule/Agenda.tsx +124 -0
  336. package/src/schedule/AgendaActions.ts +31 -0
  337. package/src/schedule/AgendaDay.tsx +124 -0
  338. package/src/schedule/AgendaGestures.ts +27 -0
  339. package/src/schedule/AgendaKeys.ts +52 -0
  340. package/src/schedule/AgendaModel.ts +82 -0
  341. package/src/schedule/AgendaNavigation.ts +38 -0
  342. package/src/schedule/AgendaPage.tsx +39 -0
  343. package/src/schedule/AgendaStrip.tsx +55 -0
  344. package/src/schedule/AvailabilityEditor-actions.ts +146 -0
  345. package/src/schedule/AvailabilityEditor-day.tsx +119 -0
  346. package/src/schedule/AvailabilityEditor-view.tsx +205 -0
  347. package/src/schedule/AvailabilityEditor.tsx +113 -0
  348. package/src/schedule/BookingCalendar.tsx +121 -0
  349. package/src/schedule/BookingCalendarActions.ts +85 -0
  350. package/src/schedule/BookingCalendarModel.ts +86 -0
  351. package/src/schedule/BookingCalendarParts.tsx +87 -0
  352. package/src/schedule/Calendar/AgendaView.tsx +45 -0
  353. package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
  354. package/src/schedule/Calendar/CalendarMain.tsx +47 -0
  355. package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
  356. package/src/schedule/Calendar/Column.tsx +129 -0
  357. package/src/schedule/Calendar/EventBlock.tsx +71 -0
  358. package/src/schedule/Calendar/MiniMonth.tsx +169 -0
  359. package/src/schedule/Calendar/MonthGrid.tsx +296 -0
  360. package/src/schedule/Calendar/TimeGrid.tsx +252 -0
  361. package/src/schedule/Calendar/Timeline.tsx +287 -0
  362. package/src/schedule/Calendar/ZoneChip.tsx +73 -0
  363. package/src/schedule/Calendar/calendar-shell.ts +160 -0
  364. package/src/schedule/Calendar/calendar-state.ts +30 -0
  365. package/src/schedule/Calendar/now-spans.tsx +33 -0
  366. package/src/schedule/Calendar/shared.ts +3 -0
  367. package/src/schedule/Calendar/state-actions.ts +189 -0
  368. package/src/schedule/Calendar/state-base.ts +143 -0
  369. package/src/schedule/Calendar/state-keys.ts +128 -0
  370. package/src/schedule/Calendar/time-fit.ts +84 -0
  371. package/src/schedule/Calendar.tsx +182 -0
  372. package/src/schedule/EventEditor.tsx +267 -0
  373. package/src/schedule/EventPopover.tsx +190 -0
  374. package/src/schedule/MeetingPlanner-model.ts +222 -0
  375. package/src/schedule/MeetingPlanner-view.tsx +310 -0
  376. package/src/schedule/MeetingPlanner.tsx +122 -0
  377. package/src/schedule/MoveSheet.tsx +168 -0
  378. package/src/schedule/YearView-model.ts +164 -0
  379. package/src/schedule/YearView-parts.tsx +147 -0
  380. package/src/schedule/YearView.tsx +100 -0
  381. package/src/schedule/bits.tsx +65 -0
  382. package/src/schedule/index.ts +25 -0
  383. package/src/skeleton-css.ts +4 -0
  384. package/src/styles.ts +13 -0
  385. package/src/type.css +15 -0
  386. package/src/ui.ts +41 -0
  387. package/src/use-ui.ts +10 -0
  388. package/tailwind.css +38 -0
  389. package/tokens/color.mjs +87 -0
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@kerf-js/veneer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "veneer, the UI toolkit for kerf: components over @kerf-js/veneer-core",
5
+ "keywords": [
6
+ "kerf"
7
+ ],
8
+ "homepage": "https://github.com/Ravonus/kerf/tree/main/packages/veneer#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/Ravonus/kerf/issues"
11
+ },
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Ravonus/kerf.git",
16
+ "directory": "packages/veneer"
17
+ },
18
+ "files": [
19
+ "src",
20
+ "plugin.mjs",
21
+ "plugin.d.mts",
22
+ "tailwind.css",
23
+ "tokens",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": [
29
+ "*.css",
30
+ "./src/styles.ts",
31
+ "./src/fields.ts",
32
+ "./src/ui.ts"
33
+ ],
34
+ "exports": {
35
+ ".": "./src/index.ts",
36
+ "./skeleton": "./src/skeleton-css.ts",
37
+ "./ui": "./src/ui.ts",
38
+ "./scenes": "./src/Stage.tsx",
39
+ "./plugin": "./plugin.mjs",
40
+ "./theme-parts": "./src/plugin/theme-parts.mjs",
41
+ "./theme": "./src/plugin/theme.mjs",
42
+ "./theme-context": "./src/plugin/theme-context.mjs",
43
+ "./tailwind.css": "./tailwind.css"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "@kerf-js/scroll": "0.1.0",
50
+ "@kerf-js/veneer-core": "0.1.0",
51
+ "@kerf-js/veneer-icons": "0.1.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@kerf-js/core": "^0.1.0"
55
+ },
56
+ "engines": {
57
+ "node": ">=24"
58
+ }
6
59
  }
package/plugin.d.mts ADDED
@@ -0,0 +1,187 @@
1
+ import type { PluginInstance } from '@kerf-js/core/plugin'
2
+
3
+ /** For `site.head`: restores `setDial(…, { persist: true })` before the first paint. */
4
+ export const dialScript: string
5
+
6
+ /** Every spec rule keyed on `[data-fields="classic"]`, re-scoped to the root: classic fields as the default. */
7
+ export function classicCss(): string
8
+
9
+ /** What `veneer()` takes in kerf.config: the seed, the default dials, radius, fonts and any token. */
10
+ export interface VeneerOptions {
11
+ /**
12
+ * The brand's hue family: `{ accent: '#rrggbb' }` (or a name from `colors`), or a hue and chroma. Each theme solves its own lightness, and the build
13
+ * prints where it landed. `neutral` tints pages, surfaces and text the same way. Checked at the stops `dials` leave (D010).
14
+ */
15
+ seed?: ({ accent: string } | { hue: number; chroma: number } | {}) & {
16
+ neutral?: string | { hue: number; chroma: number }
17
+ }
18
+ /** `'classic'` makes classic fields the default. */
19
+ fields?: 'floating' | 'classic'
20
+ /** The app's default dials. A `data-*` on `<html>` or any scope still wins. */
21
+ dials?: {
22
+ expression?: 'quiet' | 'balanced' | 'vivid'
23
+ density?: 'compact' | 'cozy' | 'comfortable'
24
+ flair?: 'sweep' | 'none'
25
+ theme?: 'light' | 'dark'
26
+ /** The named theme (from `themes`) a page shows when nothing chooses one. */
27
+ palette?: string
28
+ }
29
+ /** Replaces the radius each expression sets. */
30
+ radius?: 'sharp' | 'soft' | 'round'
31
+ /** Replaces the icon drawing each expression shows: a vivid site with balanced (line) icons is `icons: 'balanced'`. */
32
+ icons?: 'quiet' | 'balanced' | 'vivid'
33
+ /** A family name, or a full CSS font stack. */
34
+ fonts?: { body?: string; display?: string; mono?: string }
35
+ /** Any spec token, like `{ '--veneer-color-page': '#fafafa' }`. Checked at the stops `dials` leave (D010). */
36
+ tokens?: Record<`--veneer-${string}`, string>
37
+ /**
38
+ * Named colours, like Tailwind's: `{ brand: '#e8590c' }`. Use the name anywhere a colour goes (`parts`, `tone="brand"`,
39
+ * Tailwind's `bg-brand`). Each one also becomes a tone, solved like the accent so it reads in light and dark.
40
+ */
41
+ colors?: Record<string, `#${string}`>
42
+ /** The scale every part reads: radius, space, type, shadows, motion. A number is px (ms for durations). */
43
+ system?: VeneerSystem
44
+ /** Any part, at rest and in each state: `{ button: { radius: 'pill', bg: 'brand', hover: { bg: 'ink' } } }`. */
45
+ parts?: VeneerParts
46
+ /** Named themes, each with the same options. `data-palette="ocean"` (or `setDial('palette', 'ocean')`) switches. */
47
+ themes?: Record<string, VeneerTheme>
48
+ }
49
+
50
+ /** One named theme: its own seed, colours, scale, parts and tokens, over the page's. */
51
+ export interface VeneerTheme {
52
+ seed?: VeneerOptions['seed']
53
+ colors?: Record<string, `#${string}`>
54
+ system?: VeneerSystem
55
+ parts?: VeneerParts
56
+ tokens?: Record<`--veneer-${string}`, string>
57
+ }
58
+
59
+ type Len = number | string
60
+ /** The handles of `cubic-bezier(x1, y1, x2, y2)`, the same shape a scroll timeline's key takes. */
61
+ export type Handles = readonly [x1: number, y1: number, x2: number, y2: number]
62
+ /** A CSS easing, or cubic-bezier handles. */
63
+ type Ease = string | Handles
64
+ type Color = string
65
+ /** Text roles veneer sets type for. */
66
+ type TextRole =
67
+ | 'body'
68
+ | 'button'
69
+ | 'caption'
70
+ | 'code'
71
+ | 'control'
72
+ | 'display'
73
+ | 'eyebrow'
74
+ | 'heading'
75
+ | 'label'
76
+ | 'prose'
77
+ | 'title'
78
+
79
+ /**
80
+ * A length on a line: `min` px at the `from` width, `max` px at `to`, held outside them (a `clamp()` on `vw`). Inside a
81
+ * breakpoint, `from` is the breakpoint.
82
+ */
83
+ export interface Fluid {
84
+ min: number
85
+ max: number
86
+ from?: number
87
+ to: number
88
+ }
89
+ /** A value by viewport width: `base` below the first breakpoint, then one from each min-width in px. */
90
+ export type ByWidth<T> = { base?: T; [minWidth: number]: T }
91
+
92
+ /**
93
+ * One text role's type. A number is px for `size` and `tracking`. Any property can change by width
94
+ * (`{ base: 16, 768: 14 }`); `size` and `tracking` can also be `Fluid`: `{ base: 72, 768: { min: 120, max: 220, to: 1680 } }`.
95
+ */
96
+ export interface TextStyle {
97
+ size?: Len | Fluid | ByWidth<Len | Fluid>
98
+ weight?: number | string | ByWidth<number | string>
99
+ leading?: number | string | ByWidth<number | string>
100
+ tracking?: Len | Fluid | ByWidth<Len | Fluid>
101
+ case?: string | ByWidth<string>
102
+ font?: string | ByWidth<string>
103
+ }
104
+
105
+ /** The design system's own scales, retuned app-wide: `system.radius.control`, `system.space.related`, `system.text.button`. */
106
+ export interface VeneerSystem {
107
+ radius?: { control?: Len; surface?: Len; mark?: Len; round?: Len }
108
+ space?: { hair?: Len; tight?: Len; related?: Len; group?: Len; section?: Len; page?: Len }
109
+ pad?: { control?: Len; surface?: Len }
110
+ control?: { sm?: Len; md?: Len; lg?: Len }
111
+ font?: { sans?: string; display?: string; mono?: string }
112
+ /** veneer's roles, and any role the app names (`narrative`): each becomes `--veneer-text-<role>-*` and `data-role="<role>"`. */
113
+ text?: { [R in TextRole]?: TextStyle } & Record<string, TextStyle>
114
+ shadow?: { 0?: string; 1?: string; 2?: string; 3?: string; sm?: string; md?: string; lg?: string }
115
+ /** veneer's steps, and any the app names (`glide: 300`): `--veneer-duration-<name>`, exact, ms for a number. */
116
+ duration?: { instant?: Len; fast?: Len; base?: Len; slow?: Len } & Record<string, Len>
117
+ /** veneer's curves, and any the app names: `--veneer-ease-<name>`, a CSS easing or cubic-bezier handles. */
118
+ ease?: { [E in 'in' | 'out' | 'in-out' | 'pop' | 'spring' | 'sheet']?: Ease } & Record<
119
+ string,
120
+ Ease
121
+ >
122
+ border?: { hairline?: Len; emphasis?: Len }
123
+ icon?: { sm?: Len; md?: Len; stroke?: number | string }
124
+ }
125
+
126
+ /** Properties every part takes. Colours are names from `colors` or CSS colours; lengths are px or names. */
127
+ export interface PartProps {
128
+ bg?: Color
129
+ text?: Color
130
+ border?: Color
131
+ borderWidth?: Len
132
+ radius?: number | 'control' | 'surface' | 'mark' | 'round' | 'pill' | 'none' | (string & {})
133
+ padding?: Len
134
+ paddingX?: Len
135
+ paddingY?: Len
136
+ gap?: Len
137
+ margin?: Len
138
+ height?: Len
139
+ minHeight?: Len
140
+ width?: Len
141
+ size?: Len
142
+ shadow?: 'none' | 'sm' | 'md' | 'lg' | 0 | 1 | 2 | 3 | (string & {})
143
+ opacity?: number
144
+ scale?: number
145
+ /** ms for a number; a name from `system.duration` reads its token. */
146
+ duration?: Len
147
+ /** A name from `system.ease`, a CSS easing, or cubic-bezier handles. */
148
+ easing?: Ease
149
+ font?: 'sans' | 'display' | 'mono' | (string & {})
150
+ fontSize?: Len
151
+ weight?: number | string
152
+ leading?: number | string
153
+ tracking?: Len
154
+ case?: 'none' | 'uppercase' | 'lowercase' | 'capitalize'
155
+ }
156
+ type State = 'hover' | 'focus' | 'press' | 'active' | 'open' | 'disabled'
157
+ /** A part's look at rest, then per state. */
158
+ export type PartStyle<P = PartProps, S extends string = State> = P & { [K in S]?: P }
159
+ type Underline = { color?: Color; width?: Len; offset?: Len; duration?: Len }
160
+ type Emphasis = 'soft' | 'outline' | 'ghost' | 'frame' | 'link'
161
+
162
+ /** Every element `veneer({ parts })` can restyle, at rest and per state: `parts.button.hover.bg`, `parts.nav.underline`. */
163
+ export interface VeneerParts {
164
+ button?: PartStyle & { [E in Emphasis]?: PartStyle }
165
+ iconButton?: PartStyle<PartProps & { icon?: Len }>
166
+ copy?: PartStyle
167
+ close?: PartStyle
168
+ link?: PartStyle & { underline?: PartStyle<Underline, 'hover' | 'focus'> }
169
+ nav?: PartProps & { item?: PartStyle; underline?: Underline }
170
+ tabs?: PartProps & { tab?: PartStyle; underline?: Underline }
171
+ pill?: PartStyle
172
+ badge?: PartStyle
173
+ chip?: PartStyle
174
+ card?: PartStyle
175
+ field?: PartStyle & { label?: PartStyle<{ text?: Color }, 'hover' | 'focus'> }
176
+ /** The stroke that draws round a control on hover and focus, the text it lights, and its speed. */
177
+ sweep?: { stroke?: Color; base?: Color; text?: Color; width?: Len; duration?: Len }
178
+ dialog?: PartProps
179
+ sheet?: PartProps
180
+ popover?: PartProps
181
+ toast?: PartProps
182
+ }
183
+
184
+ /** The Vite plugin that serves veneer's tokens for an app. */
185
+ export const veneer: (options?: VeneerOptions) => PluginInstance<unknown>
186
+ /** The plugin, for `import veneer from`. */
187
+ export default veneer
package/plugin.mjs ADDED
@@ -0,0 +1,399 @@
1
+ // veneer() contributes configuration, tokens, component discovery and agent instructions.
2
+ // Seed hues are contrast-checked and fitted against the canonical veneer-core stylesheet.
3
+ // Classic fields and dial defaults re-scope canonical rules; explicit markup still wins.
4
+ // Radius, fonts and token overrides apply at every scope and pass the same contrast checks.
5
+ import { execFileSync } from 'node:child_process'
6
+ import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
7
+ import { tmpdir } from 'node:os'
8
+ import { join } from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+ import { definePlugin } from '@kerf-js/core/plugin'
11
+ import { hex, luminance, toLinear } from './tokens/color.mjs'
12
+ import { ICONS } from './src/plugin/icons.mjs'
13
+ import { componentCatalog } from './src/plugin/catalog.mjs'
14
+ import { dtcgTokens } from './src/plugin/dtcg.mjs'
15
+ import { DEFAULT, normalizeSeed, seedByName } from './src/plugin/seed.mjs'
16
+ import { checkTokens, tailwindTheme, themed, themeOptions } from './src/plugin/theme.mjs'
17
+ import { themeContext } from './src/plugin/theme-context.mjs'
18
+
19
+ const core = new URL('../veneer-core/', import.meta.url)
20
+ const DIALS = {
21
+ expression: ['quiet', 'balanced', 'vivid'],
22
+ density: ['compact', 'cozy', 'comfortable'],
23
+ flair: ['sweep', 'none'],
24
+ theme: ['light', 'dark'],
25
+ }
26
+ const RADII = { sharp: [2, 2, 2], soft: [8, 12, 4], round: [14, 20, 6] }
27
+ const FONTS = {
28
+ body: ['sans', 'ui-sans-serif, system-ui, sans-serif'],
29
+ display: ['display', 'ui-sans-serif, system-ui, sans-serif'],
30
+ mono: ['mono', 'ui-monospace, monospace'],
31
+ }
32
+ // The spec's scope roots (veneer.css §2): every one recomputes the sys tokens, so an override has to land on each.
33
+ const SCOPES =
34
+ ':root,[data-expression],[data-density],[data-form],[data-pointer],[data-motion],[data-flair],[data-theme],[data-palette],[data-veneer]'
35
+ const THEMING = ['colors', 'system', 'parts', 'themes']
36
+ const safe = (value) => typeof value === 'string' && value !== '' && !/[;{}<]/.test(value)
37
+ const bad = (path, message) => Object.assign(new Error(message), { path })
38
+
39
+ function options(input) {
40
+ const out = {}
41
+ for (const key of Object.keys(input))
42
+ if (
43
+ !['seed', 'fields', 'dials', 'radius', 'icons', 'fonts', 'tokens', ...THEMING].includes(key)
44
+ )
45
+ throw Object.assign(new Error(`unknown option \`${key}\``), { path: key })
46
+ if (input.fields !== undefined && input.fields !== 'floating' && input.fields !== 'classic')
47
+ throw Object.assign(new Error(`must be 'floating' or 'classic'`), { path: 'fields' })
48
+ if (input.seed !== undefined) {
49
+ try {
50
+ const seed = seedByName(input.seed, input.colors)
51
+ out.seed = normalizeSeed(seed)
52
+ if (typeof seed?.accent === 'string') out.asked = seed.accent.toLowerCase()
53
+ } catch (error) {
54
+ throw Object.assign(/** @type {Error} */ (error), { path: 'seed' })
55
+ }
56
+ }
57
+ if (input.fields) out.fields = input.fields
58
+ const { palette, ...dialsIn } = input.dials ?? {}
59
+ for (const [dial, value] of Object.entries(dialsIn)) {
60
+ if (!DIALS[dial])
61
+ throw bad(`dials.${dial}`, `unknown dial; use ${Object.keys(DIALS).join(', ')}`)
62
+ if (!DIALS[dial].includes(value))
63
+ throw bad(`dials.${dial}`, `must be one of ${DIALS[dial].join(', ')}`)
64
+ }
65
+ if (Object.keys(dialsIn).length) out.dials = dialsIn
66
+ if (input.radius !== undefined) {
67
+ if (!RADII[input.radius]) throw bad('radius', `must be one of ${Object.keys(RADII).join(', ')}`)
68
+ out.radius = input.radius
69
+ }
70
+ if (input.icons !== undefined && !ICONS[input.icons])
71
+ throw bad('icons', `must be one of ${Object.keys(ICONS).join(', ')}`)
72
+ if (input.icons) out.icons = input.icons
73
+ for (const [font, value] of Object.entries(input.fonts ?? {})) {
74
+ if (!FONTS[font])
75
+ throw bad(`fonts.${font}`, `unknown font; use ${Object.keys(FONTS).join(', ')}`)
76
+ if (!safe(value)) throw bad(`fonts.${font}`, 'must be a font family or a CSS font stack')
77
+ }
78
+ if (input.fonts) out.fonts = input.fonts
79
+ checkTokens(input.tokens, 'tokens')
80
+ if (input.tokens) out.tokens = input.tokens
81
+ const seedAt = (seed, path, colors) => {
82
+ try {
83
+ return normalizeSeed(seedByName(seed, colors))
84
+ } catch (error) {
85
+ throw Object.assign(/** @type {Error} */ (error), { path })
86
+ }
87
+ }
88
+ if (THEMING.some((k) => input[k] !== undefined) || palette !== undefined)
89
+ out.theme = themeOptions({ ...input, default: palette }, themeContext(core).tokenNames, {
90
+ seed: seedAt,
91
+ tokens: (tokens, path) => checkTokens(tokens, path) ?? {},
92
+ })
93
+ if (palette !== undefined) out.theme.default = palette
94
+ return out
95
+ }
96
+
97
+ const fontStack = (value, fallback) =>
98
+ value.includes(',') ? value : `${JSON.stringify(value)}, ${fallback}`
99
+
100
+ /** The radius, fonts and tokens as declarations, or '' with none set. */
101
+ function overrides({ seed, radius, icons, fonts = {}, tokens = {}, theme }) {
102
+ const out = {}
103
+ // The neutral's refs are redeclared at each expression stop, so it lands on every scope, as a token does.
104
+ if (seed?.neutral)
105
+ Object.assign(out, {
106
+ '--veneer-ref-neutral-h': seed.neutral.hue,
107
+ '--veneer-ref-neutral-c': seed.neutral.chroma,
108
+ })
109
+ if (radius)
110
+ [out['--veneer-radius-control'], out['--veneer-radius-surface'], out['--veneer-radius-mark']] =
111
+ RADII[radius].map((px) => `${px}px`)
112
+ if (icons) for (const [k, v] of Object.entries(ICONS[icons])) out[`--veneer-icon-${k}`] = v
113
+ for (const [font, value] of Object.entries(fonts))
114
+ out[`--veneer-font-${FONTS[font][0]}`] = fontStack(value, FONTS[font][1])
115
+ Object.assign(out, theme?.system, tokens)
116
+ return Object.entries(out)
117
+ .map(([k, v]) => `${k}:${v}`)
118
+ .join(';')
119
+ }
120
+
121
+ // In veneer.base, a later layer than veneer.tokens, so a token set here beats every dial stop and every copied default.
122
+ const overrideCss = (declarations) =>
123
+ declarations ? `@layer veneer.base{${SCOPES}{${declarations}}}\n` : ''
124
+
125
+ const seedCss = (s) =>
126
+ `@layer veneer.tokens{:root{--veneer-seed-accent-h:${s.hue};--veneer-seed-accent-c:${s.chroma}}}\n`
127
+
128
+ /** The spec checker's report on veneer.css with the seed and any token overrides applied. */
129
+ function contrast(seed, declarations) {
130
+ const dir = mkdtempSync(join(tmpdir(), 'veneer-seed-'))
131
+ try {
132
+ const css = join(dir, 'veneer.css')
133
+ writeFileSync(
134
+ css,
135
+ readFileSync(new URL('styles/veneer.css', core), 'utf8') +
136
+ `\n:root{--veneer-seed-accent-h:${seed.hue};--veneer-seed-accent-c:${seed.chroma}}\n${declarations && `${SCOPES}{${declarations}}\n`}`,
137
+ )
138
+ let out
139
+ try {
140
+ out = execFileSync(
141
+ process.execPath,
142
+ [fileURLToPath(new URL('scripts/contrast-check.mjs', core)), css, '--json'],
143
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] },
144
+ )
145
+ } catch (e) {
146
+ out = e.stdout // exit 1 on failures; the JSON is still on stdout
147
+ }
148
+ return JSON.parse(out)
149
+ } finally {
150
+ rmSync(dir, { recursive: true, force: true })
151
+ }
152
+ }
153
+
154
+ /** The theme and expression stops an app's `dials` can render by default. Markup that sets another stop is the app's to check. */
155
+ const renders =
156
+ (dials = {}) =>
157
+ (r) =>
158
+ (!dials.theme || r.theme === dials.theme) &&
159
+ (!dials.expression || r.expression === dials.expression)
160
+
161
+ /** D010 with every failing pair, at the stops `dials` leave. Returns how many pairs passed. */
162
+ export function checkSeed(seed, declarations = '', dials) {
163
+ const results = contrast(seed, declarations).results.filter(renders(dials))
164
+ const failed = results.filter((r) => !r.pass)
165
+ const failures = failed.map(
166
+ (r) => `${r.combo}: ${r.fg} on ${r.bg} is ${r.ratio.toFixed(2)}:1, needs ${r.min}:1`,
167
+ )
168
+ if (failures.length)
169
+ throw Object.assign(
170
+ new Error(
171
+ `veneer colours fail contrast (${failures.length} pairs): ${failures.slice(0, 5).join('; ')}${failures.length > 5 ? '; …' : ''}`,
172
+ ),
173
+ {
174
+ code: 'D010',
175
+ failures,
176
+ help: 'Change the seed or token named in each pair, or limit the stops with `dials`. `kerf docs theme` has worked looks.',
177
+ },
178
+ )
179
+ return results.length
180
+ }
181
+
182
+ /** Where a seed's accent lands: a seed sets the hue family, and each theme solves its own lightness for contrast. */
183
+ function landed(seed, declarations, asked) {
184
+ const { resolved } = contrast(seed, declarations)
185
+ const light = resolved['light/balanced']?.['accent-solid'],
186
+ dark = resolved['dark/balanced']?.['accent-solid']
187
+ return light === asked && dark === asked
188
+ ? undefined
189
+ : `veneer: accent ${asked} landed as ${light} light, ${dark} dark. A seed sets the hue family; pin an exact brand with \`--veneer-color-accent-solid\` (\`kerf docs theme\`).`
190
+ }
191
+
192
+ /** The resolved tokens as DTCG 2025.10, using the app's seed and overrides. */
193
+ export function dtcg(css = '') {
194
+ return dtcgTokens(css, core)
195
+ }
196
+
197
+ // A token's value in the spec, with `from` (its lightness for one theme) replaced by `to`.
198
+ function relit(token, from, to) {
199
+ const value = readFileSync(new URL('styles/veneer.css', core), 'utf8')
200
+ .replace(/\/\*[\s\S]*?\*\//g, '')
201
+ .match(new RegExp(`${token}:\\s*([^;]+);`))[1]
202
+ return value.replace(/\s+/g, ' ').replace(`oklch(${from} `, `oklch(${to} `)
203
+ }
204
+
205
+ /** The lightness at which `chroma` and `hue` have luminance `Y`: contrast only sees luminance, so this keeps the default's contrast. */
206
+ function lightnessFor(Y, chroma, hue) {
207
+ let lo = 0,
208
+ hi = 1
209
+ for (let k = 0; k < 24; k++) {
210
+ const mid = (lo + hi) / 2
211
+ if (luminance(toLinear({ L: mid, C: chroma, H: hue })) < Y) lo = mid
212
+ else hi = mid
213
+ }
214
+ return Math.ceil(hi * 1000) / 1000
215
+ }
216
+
217
+ // The spec's lightnesses are tuned for the default hue, and equal lightness is not equal luminance: other hues land just
218
+ // outside the two tightest pairs (light sweep against the ink, dark accent text on its pressed fill). Those two tokens
219
+ // are relit to the default's luminance, keeping the hue and chroma. Accent text takes a 3% margin: at these hues the soft
220
+ // fill behind it is brighter too, and text only ever gets lighter.
221
+ function fitted(seed) {
222
+ const sweep = lightnessFor(
223
+ luminance(toLinear({ L: 0.515, C: 0.13, H: DEFAULT.hue })),
224
+ Math.min(Math.max(seed.chroma * 1.25, 0.12), 0.13),
225
+ seed.hue,
226
+ )
227
+ const text = lightnessFor(
228
+ luminance(toLinear({ L: 0.8, C: DEFAULT.chroma, H: DEFAULT.hue })) * 1.03,
229
+ seed.chroma,
230
+ seed.hue,
231
+ )
232
+ return {
233
+ '--veneer-color-sweep': relit('--veneer-color-sweep', 0.515, sweep),
234
+ '--veneer-color-accent-text': relit('--veneer-color-accent-text', 0.8, Math.max(text, 0.8)),
235
+ }
236
+ }
237
+
238
+ /** `declarations` plus whatever a custom seed needs to pass, or D010. A token set in the config beats a fitted one. */
239
+ function fitSeed(seed, declarations, dials) {
240
+ try {
241
+ checkSeed(seed, declarations, dials)
242
+ return declarations
243
+ } catch (error) {
244
+ if (error.code !== 'D010') throw error
245
+ }
246
+ const fit = Object.entries(fitted(seed))
247
+ .filter(([token]) => !declarations.includes(`${token}:`))
248
+ .map(([k, v]) => `${k}:${v}`)
249
+ const merged = [...fit, ...(declarations ? [declarations] : [])].join(';')
250
+ checkSeed(seed, merged, dials)
251
+ return merged
252
+ }
253
+
254
+ /** Every spec rule keyed on `key`, re-scoped to `scope`, inside its original layer. */
255
+ function rescoped(key, scope) {
256
+ const files = [
257
+ new URL('styles/veneer.css', core),
258
+ ...['inputs', 'components'].flatMap((dir) =>
259
+ // Selective choice mirrors already occur in choice.css; defaults copy each rule once.
260
+ readdirSync(new URL(`styles/${dir}/`, core))
261
+ .filter((f) => !f.startsWith('choice-'))
262
+ .map((f) => new URL(`styles/${dir}/${f}`, core)),
263
+ ),
264
+ ]
265
+ let out = ''
266
+ for (const file of files) {
267
+ const css = readFileSync(file, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '')
268
+ const stack = []
269
+ let start = 0
270
+ for (let i = 0; i < css.length; i++) {
271
+ if (css[i] === '{') {
272
+ stack.push({ prelude: css.slice(start, i).trim(), at: i })
273
+ start = i + 1
274
+ } else if (css[i] === '}') {
275
+ const open = stack.pop()
276
+ if (open && open.prelude.includes(key) && !open.prelude.startsWith('@')) {
277
+ const layers = stack.map((s) => s.prelude).filter((p) => p.startsWith('@'))
278
+ const rule = `${open.prelude.replaceAll(key, scope)}{${css.slice(open.at + 1, i).trim()}}`
279
+ out += layers.reduceRight((inner, p) => `${p}{${inner}}`, rule) + '\n'
280
+ }
281
+ start = i + 1
282
+ } else if (css[i] === ';' && !stack.length) start = i + 1
283
+ }
284
+ }
285
+ return out
286
+ }
287
+
288
+ /**
289
+ * For `site.head`: applies the dials `setDial(…, { persist: true })` kept, before the first paint, so a prerendered page
290
+ * doesn't show the OS theme first.
291
+ */
292
+ export const dialScript = `<script>try{Object.assign(document.documentElement.dataset,JSON.parse(localStorage.getItem('veneer:dials')||'{}'))}catch(e){}</script>`
293
+
294
+ export const classicCss = () =>
295
+ rescoped('[data-fields="classic"]', ':root:not([data-fields="floating"])')
296
+ export const dialCss = (dial, value) =>
297
+ rescoped(`[data-${dial}="${value}"]`, `:root:not([data-${dial}])`)
298
+
299
+ /**
300
+ * The app's colours for its generated share cards (`site.card`, research 20 §10): the page, text and accent tokens of
301
+ * veneer.css as sRGB, since a card is an image and has no stylesheet.
302
+ */
303
+ function cardColors(seed, dials) {
304
+ const color = (L, C, H) => hex(toLinear({ L, C, H }))
305
+ const [h, c] = seed.neutral ? [seed.neutral.hue, seed.neutral.chroma] : [85, 0.012] // --veneer-ref-neutral: warm paper and ink, or the seed's
306
+ return {
307
+ scheme: dials?.theme ?? 'dark',
308
+ dark: {
309
+ background: color(0.155, c, h),
310
+ text: color(0.935, c, h),
311
+ subtle: color(0.735, c, h),
312
+ accent: color(0.76, seed.chroma * 1.15, seed.hue),
313
+ },
314
+ light: {
315
+ background: color(0.972, c / 2, h),
316
+ text: color(0.235, c, h),
317
+ subtle: color(0.475, c, h),
318
+ accent: color(0.5, Math.min(seed.chroma, 0.13), seed.hue),
319
+ },
320
+ }
321
+ }
322
+
323
+ const agents = `Import components from \`@kerf-js/veneer\`. Layout: \`Stack Row Grid Split Center Cover Frame Spacer Inset\` (\`gap\`: hair tight related group section page). No raw values (D001–D007); intent props only: \`tone\` (neutral accent positive caution critical info), \`emphasis\` (solid soft outline ghost frame link), \`size\` (sm md lg). The look comes from dials: \`data-expression|theme|density|motion|flair\` on any element (scopes nest). Fields take \`label\` (required), \`hint\`, \`error\`. App-wide: \`veneer({ seed: { accent }, dials, radius, icons, fonts, tokens })\` (\`icons\` pins the icon tier); D010 fails a pair that can't pass. Theming: \`colors\` names colours (\`tone="brand"\`), \`system\` retunes scales, \`parts\` restyles an element per state (\`parts.button.hover.bg\`; \`kerf docs theme\` lists parts), \`themes\` are named looks switched by \`data-palette\` or \`setPalette\`. Own CSS: never a bare \`[data-part]\`; hang it from its \`[data-scope]\`. A tall sticky header sets \`--veneer-scroll-offset\`.`
324
+
325
+ const catalog = componentCatalog()
326
+
327
+ export const veneer = definePlugin({
328
+ name: '@kerf-js/veneer',
329
+ version: '0.1.0',
330
+ kerf: '*',
331
+ namespace: 'D',
332
+ options,
333
+ // A custom seed runs veneer-core's contrast checker over a temporary copy of its stylesheet (checkSeed).
334
+ permissions: {
335
+ fs: { read: ['node_modules/@kerf-js/veneer-core/**'], write: ['$TMPDIR/veneer-seed-*'] },
336
+ spawn: ['node'],
337
+ },
338
+ contribute(o) {
339
+ const seed = o.seed ?? DEFAULT
340
+ const custom = seed.hue !== DEFAULT.hue || seed.chroma !== DEFAULT.chroma
341
+ let declarations = overrides(o)
342
+ if (custom) declarations = fitSeed(seed, declarations, o.dials) // throws { code: 'D010' }
343
+ else if (declarations) checkSeed(seed, declarations, o.dials)
344
+ const note = o.asked && landed(seed, declarations, o.asked)
345
+ const theming = o.theme
346
+ ? themed(o.theme, {
347
+ context: themeContext(core),
348
+ seed,
349
+ dials: o.dials,
350
+ checkSeed: fitSeed,
351
+ declare: overrides,
352
+ })
353
+ : ''
354
+ const tailwind = o.theme ? tailwindTheme(o.theme) : ''
355
+ const dials = Object.entries(o.dials ?? {})
356
+ .map(([dial, value]) => dialCss(dial, value))
357
+ .join('')
358
+ const css =
359
+ (custom ? seedCss(seed) : '') +
360
+ (o.fields === 'classic' ? classicCss() : '') +
361
+ dials +
362
+ overrideCss(declarations) +
363
+ theming
364
+ return {
365
+ tokens: {
366
+ namespace: 'veneer',
367
+ ...(css && { css }),
368
+ ...(tailwind && { cssEntries: { tailwind } }),
369
+ values: {
370
+ seed: { hue: seed.hue, chroma: seed.chroma },
371
+ fields: o.fields ?? 'floating',
372
+ ...(o.dials && { dials: o.dials }),
373
+ },
374
+ },
375
+ agents: { title: 'veneer (UI kit)', text: agents },
376
+ ...(note && { notes: [note] }),
377
+ card: cardColors(seed, o.dials),
378
+ catalog,
379
+ map: [
380
+ {
381
+ want: 'UI components',
382
+ call: 'Import from `@kerf-js/veneer`; `kerf plugins` has the catalog',
383
+ have: `${catalog.length} components`,
384
+ },
385
+ ],
386
+ diagnostics: [
387
+ {
388
+ code: 'D010',
389
+ catches:
390
+ 'A token override, alone or with the seed, that leaves text, a control boundary or the focus ring below WCAG contrast at some dial stop',
391
+ fix: 'Change the token or seed; the message lists each failing pair',
392
+ severity: 'error',
393
+ },
394
+ ],
395
+ }
396
+ },
397
+ })
398
+
399
+ export default veneer