@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
@@ -0,0 +1,143 @@
1
+ // The CSS veneer({ colors, parts, themes }) writes: colours as tokens and tones, parts as rules in the veneer.theme layer,
2
+ // each named theme under [data-palette]. Read and checked options come from theme.mjs.
3
+ import { fromHex } from '../../tokens/color.mjs'
4
+ import { STATES } from './theme-parts.mjs'
5
+ import { mediaCss, roleCss } from './theme-text.mjs'
6
+
7
+ // -- CSS -----------------------------------------------------------------------------------------------------------
8
+
9
+ /** The selector a row lands on, with its state put where the part's `&` is. */
10
+ function selectorOf(row) {
11
+ const { spec, target, state } = row
12
+ // a target can name its own place for a state: a channel the component animates to, rather than a :hover rule
13
+ const channel = state && target[state]
14
+ const base = target.on ?? spec.sel
15
+ return base.replaceAll('&', channel || !state ? '' : STATES[state])
16
+ }
17
+
18
+ /** Declarations for one row. */
19
+ function declarations(row) {
20
+ const t =
21
+ row.state && row.target[row.state] ? { ...row.target, ...row.target[row.state] } : row.target
22
+ if (t.vars) return t.vars.map((v) => `${v}:${row.value}`)
23
+ return [t.css].flat().map((p) => `${p}:${row.value}`)
24
+ }
25
+
26
+ const where = (prefixes, sel) =>
27
+ prefixes
28
+ ? prefixes
29
+ .flatMap((p) => [`:where(${p}) :where(${sel})`, `:where(${p}):where(${sel})`])
30
+ .join(',')
31
+ : `:where(${sel})`
32
+
33
+ /** One scope's part rules: the page's (`prefixes` null) or a named theme's. Scope tokens land on every scope root. */
34
+ const ORDER = [null, ...Object.keys(STATES)]
35
+ function partCss(rows, prefixes, scopes) {
36
+ const bySel = new Map()
37
+ // rest first, then the states in a fixed order: every rule has :where() weight, so the later one wins
38
+ const sorted = [...rows].sort((a, b) => ORDER.indexOf(a.state) - ORDER.indexOf(b.state))
39
+ for (const row of sorted) {
40
+ const sel = row.target.scope ? null : selectorOf(row)
41
+ const key = sel ?? '@scopes'
42
+ if (!bySel.has(key)) bySel.set(key, [])
43
+ bySel.get(key).push(...declarations(row))
44
+ }
45
+ let css = ''
46
+ for (const [sel, decls] of bySel) {
47
+ const selector =
48
+ sel === '@scopes'
49
+ ? prefixes
50
+ ? prefixes.flatMap((p) => [p, `${p} :is(${scopes})`]).join(',')
51
+ : scopes
52
+ : where(prefixes, sel)
53
+ css += `${selector}{${decls.join(';')}}`
54
+ }
55
+ return css
56
+ }
57
+
58
+ /** A named colour's six tone channels, solved the way veneer solves its accent: the hue family, lit per theme. */
59
+ export function toneChannels(hex, formulas) {
60
+ const { C, H } = fromHex(hex)
61
+ // the accent's chroma still follows the expression dial (--veneer-ref-accent-k), as veneer's own accent does
62
+ const sub = (f) =>
63
+ f
64
+ .replaceAll('var(--_ac)', `calc(${C.toFixed(3)} * var(--veneer-ref-accent-k))`)
65
+ .replaceAll('var(--_ah)', H.toFixed(1))
66
+ return Object.entries(formulas)
67
+ .map(([channel, f]) => `${channel}:${sub(f)}`)
68
+ .join(';')
69
+ }
70
+
71
+ function colorsCss(colors, prefixes, formulas) {
72
+ if (!Object.keys(colors).length) return ''
73
+ const vars = Object.entries(colors)
74
+ .map(([n, v]) => `--veneer-color-${n}:${v}`)
75
+ .join(';')
76
+ const root = prefixes ? prefixes.join(',') : ':root'
77
+ let css = `${root}{${vars}}`
78
+ for (const [name, hex] of Object.entries(colors))
79
+ css += `${where(prefixes, `[data-tone="${name}"]`)}{${toneChannels(hex, formulas)}}`
80
+ return css
81
+ }
82
+
83
+ const declare = (tokens) =>
84
+ Object.entries(tokens)
85
+ .map(([k, v]) => `${k}:${v}`)
86
+ .join(';')
87
+
88
+ /**
89
+ * The CSS for `colors`, `parts` and each named theme. `ctx` carries the stylesheet facts: `layers` (veneer's sub-layer
90
+ * order), `scopes` (its scope roots) and `formulas` (the accent channel formulas).
91
+ */
92
+ export function themeCss(o, ctx) {
93
+ const { layers, scopes, formulas, stops } = ctx
94
+ let parts = colorsCss(o.colors ?? {}, null, formulas) + partCss(o.rows, null, scopes)
95
+ let tokens = ''
96
+ let media = mediaCss(o.media, 'veneer.base', scopes)
97
+ for (const [name, theme] of Object.entries(o.themes)) {
98
+ const prefixes = [
99
+ `[data-palette="${name}"]`,
100
+ ...(o.default === name ? [':root:not([data-palette])'] : []),
101
+ ]
102
+ if (theme.seed) {
103
+ tokens += `${prefixes.join(',')}{--veneer-seed-accent-h:${theme.seed.hue};--veneer-seed-accent-c:${theme.seed.chroma}}`
104
+ }
105
+ // a seed or a fitted token moves colour tokens the stop's refs point at
106
+ if (theme.seed || Object.keys(theme.system).length)
107
+ tokens += stopRefsCss(`[data-palette="${name}"]`, stops)
108
+ const at = prefixes.flatMap((p) => [p, `${p} :is(${scopes})`]).join(',')
109
+ if (Object.keys(theme.system).length) parts += `${at}{${declare(theme.system)}}`
110
+ parts += colorsCss(theme.colors, prefixes, formulas) + partCss(theme.rows, prefixes, scopes)
111
+ media += mediaCss(theme.media, 'veneer.theme', at)
112
+ }
113
+ const roles = roleCss(o.roles)
114
+ if (!parts && !tokens && !roles && !media) return ''
115
+ return (
116
+ `@layer veneer.${layers.join(',veneer.')},veneer.theme;\n` +
117
+ (tokens && `@layer veneer.tokens{${tokens}}\n`) +
118
+ roles +
119
+ (parts && `@layer veneer.theme{${parts}}\n`) +
120
+ media
121
+ )
122
+ }
123
+ // A palette below the page's root: the stop's colour refs again, at no specificity so the element's own stop wins.
124
+ // The stop is the nearest data-expression above it, or balanced with none; quiet and vivid come later so they win.
125
+ function stopRefsCss(at, stops) {
126
+ if (!stops) return ''
127
+ const own = `${at}:not(:root)`
128
+ return (
129
+ (stops.balanced && `:where(${own}){${stops.balanced}}`) +
130
+ (stops.quiet && `:where([data-expression="quiet"] ${own}){${stops.quiet}}`) +
131
+ (stops.vivid && `:where([data-expression="vivid"] ${own}){${stops.vivid}}`)
132
+ )
133
+ }
134
+
135
+ /** Tailwind v4 names for the app's colours (`bg-brand`, `text-ink`), or '' with none: on the var, so themes follow. */
136
+ export function tailwindTheme(o) {
137
+ const names = new Set([
138
+ ...Object.keys(o.colors ?? {}),
139
+ ...Object.values(o.themes ?? {}).flatMap((t) => Object.keys(t.colors ?? {})),
140
+ ])
141
+ if (!names.size) return ''
142
+ return `@theme inline {\n${[...names].map((n) => ` --color-${n}: var(--veneer-color-${n});`).join('\n')}\n}\n`
143
+ }
@@ -0,0 +1,43 @@
1
+ // `system.duration` and `system.ease`: veneer's steps and curves, and any the app names. An app's token is exact (no
2
+ // dial rescales it), and a part's `duration` or `easing` can name it.
3
+ import { NAME, bad, safe } from './theme-values.mjs'
4
+
5
+ const OWN = {
6
+ duration: ['instant', 'fast', 'base', 'slow'],
7
+ ease: ['in', 'out', 'in-out', 'pop', 'spring', 'sheet'],
8
+ }
9
+ const KIND = { time: 'duration', ease: 'ease' }
10
+
11
+ export function motionToken(group, key, { tokenNames, at }) {
12
+ const token = `--veneer-${group}-${key}`
13
+ if (OWN[group].includes(key) || (NAME.test(key) && !tokenNames.has(token))) return token
14
+ throw bad(at, `unknown step; use ${OWN[group].join(', ')} or a lowercase name of your own`)
15
+ }
16
+
17
+ /** A motion value as CSS: a number of ms, `[x1, y1, x2, y2]` handles for cubic-bezier(), or as written. */
18
+ export function motionValue(group, v, at) {
19
+ if (Array.isArray(v)) {
20
+ const x = (n) => Number.isFinite(n) && n >= 0 && n <= 1
21
+ if (group !== 'ease' || v.length !== 4 || !v.every(Number.isFinite) || !x(v[0]) || !x(v[2]))
22
+ throw bad(at, 'must be cubic-bezier handles [x1, y1, x2, y2], x1 and x2 from 0 to 1')
23
+ return `cubic-bezier(${v.join(', ')})`
24
+ }
25
+ if (!safe(v)) throw bad(at, 'must be a CSS value or a number')
26
+ return group === 'duration' && Number.isFinite(v) ? `${v}ms` : String(v)
27
+ }
28
+
29
+ export function motionNames(...systems) {
30
+ const names = { duration: new Set(OWN.duration), ease: new Set(OWN.ease) }
31
+ for (const system of systems)
32
+ for (const group of ['duration', 'ease'])
33
+ for (const key of Object.keys(system?.[group] ?? {})) names[group].add(key)
34
+ return names
35
+ }
36
+
37
+ // a part's duration or easing: a declared name reads its token, anything else is a value
38
+ export function motionRef(kind, v, { names, at }) {
39
+ const group = KIND[kind]
40
+ return typeof v === 'string' && names[group].has(v)
41
+ ? `var(--veneer-${group}-${v})`
42
+ : motionValue(group, v, at)
43
+ }
@@ -0,0 +1,41 @@
1
+ /** How a property's value is read: a colour, a length, a space or radius step, a time, a shadow, an easing, a font. */
2
+ export type PropKind =
3
+ | 'color'
4
+ | 'length'
5
+ | 'space'
6
+ | 'radius'
7
+ | 'time'
8
+ | 'shadow'
9
+ | 'ease'
10
+ | 'font'
11
+ | 'plain'
12
+
13
+ /** Where one property lands: CSS properties or tone channels, and how its value reads. */
14
+ export interface PartProp {
15
+ css?: string | string[]
16
+ vars?: string[]
17
+ kind: PropKind
18
+ }
19
+
20
+ /** One restylable element: its selector, its own properties, its states and inner parts. */
21
+ export interface PartSpec {
22
+ about?: string
23
+ for?: string[]
24
+ sel: string
25
+ props?: Record<string, PartProp>
26
+ states?: string[]
27
+ sub?: Record<string, PartSpec>
28
+ }
29
+
30
+ /** States a part can take, as the selector each adds. */
31
+ export const STATES: Record<string, string>
32
+ /** Properties every part takes. */
33
+ export const PROPS: Record<string, PartProp>
34
+ /** The parts, by name. */
35
+ export const PARTS: Record<string, PartSpec>
36
+ /** Every part, sub-parts included, as `[path, spec]` with `path` like `nav.underline`. */
37
+ export function allParts(): [string, PartSpec][]
38
+ /** A part's properties: the shared ones, then its own. */
39
+ export function propsOf(spec: PartSpec): Record<string, PartProp>
40
+ /** The states a part takes. */
41
+ export function statesOf(spec: PartSpec): string[]
@@ -0,0 +1,224 @@
1
+ // What `veneer({ parts })` can restyle: each part's selector, its states, and where each property lands.
2
+ // One table drives the CSS (theme.mjs), the types (plugin.d.mts) and the docs (`kerf docs theme`).
3
+
4
+ /** States a part can take. `&` in a part's selector is where the state goes. */
5
+ export const STATES = {
6
+ hover: ':hover',
7
+ focus: ':focus-visible',
8
+ press: ':active',
9
+ active:
10
+ ':is([aria-current]:not([aria-current="false"]), [aria-selected="true"], [aria-pressed="true"], [data-state="on"])',
11
+ open: ':is([aria-expanded="true"], [data-state="open"], [open])',
12
+ disabled: ':is(:disabled, [aria-disabled="true"])',
13
+ }
14
+
15
+ /**
16
+ * Properties every part takes. `kind` sets how a value is read: a colour (a name from `colors`, or any CSS colour), a
17
+ * length (a number is px, a name from `system.space` or `system.radius`), a time (a number is ms), or a plain value.
18
+ */
19
+ export const PROPS = {
20
+ bg: { css: 'background-color', kind: 'color' },
21
+ text: { css: 'color', kind: 'color' },
22
+ border: { css: 'border-color', kind: 'color' },
23
+ borderWidth: { css: 'border-width', kind: 'length' },
24
+ radius: { css: 'border-radius', kind: 'radius' },
25
+ padding: { css: 'padding', kind: 'space' },
26
+ paddingX: { css: 'padding-inline', kind: 'space' },
27
+ paddingY: { css: 'padding-block', kind: 'space' },
28
+ gap: { css: 'gap', kind: 'space' },
29
+ margin: { css: 'margin', kind: 'space' },
30
+ height: { css: 'block-size', kind: 'length' },
31
+ minHeight: { css: 'min-block-size', kind: 'length' },
32
+ width: { css: 'inline-size', kind: 'length' },
33
+ size: { css: ['inline-size', 'block-size'], kind: 'length' },
34
+ shadow: { css: 'box-shadow', kind: 'shadow' },
35
+ opacity: { css: 'opacity', kind: 'plain' },
36
+ scale: { css: 'scale', kind: 'plain' },
37
+ duration: { css: 'transition-duration', kind: 'time' },
38
+ easing: { css: 'transition-timing-function', kind: 'ease' },
39
+ font: { css: 'font-family', kind: 'font' },
40
+ fontSize: { css: 'font-size', kind: 'length' },
41
+ weight: { css: 'font-weight', kind: 'plain' },
42
+ leading: { css: 'line-height', kind: 'plain' },
43
+ tracking: { css: 'letter-spacing', kind: 'length' },
44
+ case: { css: 'text-transform', kind: 'plain' },
45
+ }
46
+
47
+ // A solid control paints its fill and hover from tone channels, never `background` alone: a part that sets these
48
+ // moves the channels, so the hover wash, the vivid pull-out and the sweep all follow. Tones set by markup win.
49
+ // `hover.bg` is the hover channel at rest (the wash animates to it), not a second fill under :hover. A solid's text is
50
+ // its on-fill ink; every other emphasis draws its text in the tone's text colour.
51
+ const channels = (sel, solid) => ({
52
+ bg: {
53
+ vars: ['--_solid'],
54
+ on: `${sel}:not([data-tone])`,
55
+ kind: 'color',
56
+ hover: { vars: ['--_solid-hover'] },
57
+ },
58
+ text: {
59
+ vars: solid ? ['--_ink-on', '--_ink'] : ['--_text', '--_ink'],
60
+ on: `${sel}:not([data-tone])`,
61
+ kind: 'color',
62
+ },
63
+ border: { vars: ['--_edge', '--_border'], on: `${sel}:not([data-tone])`, kind: 'color' },
64
+ })
65
+ const EMPHASES = ['soft', 'outline', 'ghost', 'frame', 'link']
66
+ const emphasis = (e) => {
67
+ const sel = `[data-scope="button"][data-emphasis="${e}"]&`
68
+ return { sel, props: { ...channels(sel, false) } }
69
+ }
70
+
71
+ const sweepHost = { radius: { css: ['border-radius', '--veneer-sweep-radius'], kind: 'radius' } }
72
+
73
+ /**
74
+ * The parts. `for` names the components a part styles (their docs pages list it). `sel` is the element (with `&` where
75
+ * a state attaches); `props` adds or replaces properties; `states` limits the states (all by default). `sub` names inner pieces, each a part of its own (`nav.underline`).
76
+ */
77
+ export const PARTS = {
78
+ button: {
79
+ about: 'Button and ButtonLink',
80
+ for: ['Button'],
81
+ sel: '[data-scope="button"]&',
82
+ props: { ...channels('[data-scope="button"]:not([data-emphasis])&', true), ...sweepHost },
83
+ sub: Object.fromEntries(EMPHASES.map((e) => [e, emphasis(e)])),
84
+ },
85
+ iconButton: {
86
+ about: 'A button that holds only an icon (copy, close, menu): square by default',
87
+ for: ['Button'],
88
+ sel: '[data-scope="button"][data-icon-only]&',
89
+ props: { ...sweepHost, icon: { css: '--veneer-icon-md', kind: 'length' } },
90
+ },
91
+ copy: { about: 'CopyButton', for: ['CodeBlock'], sel: '[data-copy]&', props: sweepHost },
92
+ close: {
93
+ about: 'The close button of a dialog, sheet, drawer, alert or side nav',
94
+ for: ['Modal', 'Drawer', 'Alert', 'SideNav'],
95
+ sel: '[data-part="close"]&',
96
+ },
97
+ link: {
98
+ about: 'Link: the text link with the drawn underline',
99
+ for: ['Link'],
100
+ sel: 'a[data-scope="link"]&',
101
+ sub: {
102
+ underline: {
103
+ sel: 'a[data-scope="link"]&',
104
+ states: ['hover', 'focus'],
105
+ props: {
106
+ color: { css: 'text-decoration-color', kind: 'color' },
107
+ width: { css: 'text-decoration-thickness', kind: 'length' },
108
+ offset: { css: 'text-underline-offset', kind: 'length' },
109
+ },
110
+ },
111
+ },
112
+ },
113
+ nav: {
114
+ about: 'Nav: the row or column of links with the sliding bar',
115
+ for: ['Nav', 'SideNav'],
116
+ sel: '[data-scope="nav"]&',
117
+ states: [],
118
+ sub: {
119
+ item: { sel: '[data-scope="nav"] a&' },
120
+ underline: {
121
+ sel: '[data-scope="nav"] > [data-part="indicator"]&',
122
+ states: [],
123
+ props: {
124
+ color: { css: 'background-color', kind: 'color' },
125
+ width: { vars: ['--_bar'], on: '[data-scope="nav"]', kind: 'length' },
126
+ duration: { css: 'transition-duration', kind: 'time' },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ tabs: {
132
+ about: 'Tabs',
133
+ for: ['Tabs'],
134
+ sel: '[data-scope="tabs"] > [data-part="list"]&',
135
+ states: [],
136
+ sub: {
137
+ tab: {
138
+ sel: '[data-scope="tabs"] > [data-part="list"] > [data-part="trigger"]&',
139
+ props: sweepHost,
140
+ },
141
+ underline: {
142
+ sel: '[data-scope="tabs"] > [data-part="list"] > [data-part="indicator"]&',
143
+ states: [],
144
+ props: {
145
+ color: { css: 'background-color', kind: 'color' },
146
+ width: { css: 'block-size', kind: 'length' },
147
+ },
148
+ },
149
+ },
150
+ },
151
+ pill: { about: 'Pill and PillLink', sel: '[data-scope="pill"]&', props: sweepHost },
152
+ badge: { about: 'Badge', for: ['Badge'], sel: '[data-scope="badge"]&' },
153
+ chip: { about: 'Chip', for: ['Chip'], sel: '[data-scope="chip"]&', props: sweepHost },
154
+ card: { about: 'Card and Surface', for: ['Card'], sel: '[data-scope="surface"]&' },
155
+ field: {
156
+ about: 'Text fields, selects and pickers',
157
+ for: ['Field', 'Textarea', 'Search', 'Select', 'NumberField', 'DateField', 'TimeField'],
158
+ sel: '[data-scope="field"] > [data-part="control"]&',
159
+ props: { bg: { vars: ['--veneer-color-field'], kind: 'color' }, ...sweepHost },
160
+ sub: {
161
+ label: {
162
+ sel: '[data-scope="field"] [data-part="label"]&',
163
+ states: ['hover', 'focus'],
164
+ props: {
165
+ // at rest, and while the sweep runs (hover and focus share one colour: the label lights with the stroke)
166
+ text: {
167
+ vars: ['--veneer-color-label', '--veneer-color-label-rest'],
168
+ on: '[data-scope="field"]',
169
+ kind: 'color',
170
+ hover: { vars: ['--veneer-color-label-active'] },
171
+ focus: { vars: ['--veneer-color-label-active'] },
172
+ },
173
+ },
174
+ },
175
+ },
176
+ },
177
+ sweep: {
178
+ about:
179
+ 'The sweep: the stroke that draws round a control on hover and focus, and the text while it runs',
180
+ sel: ':root&',
181
+ states: [],
182
+ props: {
183
+ stroke: { vars: ['--veneer-color-sweep'], kind: 'color', scope: true },
184
+ base: { vars: ['--veneer-color-sweep-base'], kind: 'color', scope: true },
185
+ text: { vars: ['--veneer-color-label-active'], kind: 'color', scope: true },
186
+ width: { vars: ['--veneer-sweep-width'], kind: 'length', scope: true },
187
+ duration: { vars: ['--veneer-ref-sweep', '--veneer-ref-frame'], kind: 'time', scope: true },
188
+ },
189
+ },
190
+ dialog: {
191
+ about: 'Modal and Dialog',
192
+ for: ['Modal'],
193
+ sel: 'dialog[data-scope="dialog"]&',
194
+ states: [],
195
+ },
196
+ sheet: {
197
+ about: 'Sheet and Drawer',
198
+ for: ['Drawer'],
199
+ sel: 'dialog[data-scope="sheet"]&',
200
+ states: [],
201
+ },
202
+ popover: {
203
+ about: 'Popover, Menu and Tooltip panels',
204
+ for: ['Popover', 'Menu', 'Tooltip'],
205
+ sel: ':is([data-scope="popover"], [data-scope="menu"], [data-scope="tooltip"])&',
206
+ states: [],
207
+ },
208
+ toast: { about: 'Toast', for: ['Toast'], sel: '[data-scope="toast"]&', states: [] },
209
+ }
210
+
211
+ /** Every part, sub-parts included, as `[path, spec]` with `path` like `nav.underline`. */
212
+ export function allParts() {
213
+ const out = []
214
+ for (const [name, spec] of Object.entries(PARTS)) {
215
+ out.push([name, spec])
216
+ for (const [sub, inner] of Object.entries(spec.sub ?? {})) out.push([`${name}.${sub}`, inner])
217
+ }
218
+ return out
219
+ }
220
+
221
+ /** A part's properties: the shared ones, then its own (which replace a shared one of the same name). */
222
+ export const propsOf = (spec) => ({ ...PROPS, ...spec.props })
223
+ /** The states a part takes. */
224
+ export const statesOf = (spec) => spec.states ?? Object.keys(STATES)
@@ -0,0 +1,93 @@
1
+ // `system.text.<role>`: a role's type tokens. One of veneer's roles takes the tokens veneer has for it; a role the app
2
+ // names takes all six, and a rule that applies them to `data-role="<role>"`, as veneer's type.css does for its own.
3
+ // A value can change with the viewport: a base, then a value or a fluid line from each min-width. Breakpoints are
4
+ // media queries, so a fluid line runs on vw and meets them exactly.
5
+ import { NAME, bad, fontValue, plain, px, safe } from './theme-values.mjs'
6
+
7
+ const PROPS = {
8
+ size: 'font-size',
9
+ weight: 'font-weight',
10
+ leading: 'line-height',
11
+ tracking: 'letter-spacing',
12
+ case: 'text-transform',
13
+ font: 'font-family',
14
+ }
15
+ const UNITLESS = new Set(['weight', 'leading'])
16
+ const format = (prop, v) =>
17
+ prop === 'font' ? fontValue(v) : UNITLESS.has(prop) ? String(v) : px(v)
18
+
19
+ const round = (n) => Math.round(n * 1e4) / 1e4
20
+ // veneer's root font-size is the body size, so the user's rem is --veneer-rem, as in veneer's own fluid roles
21
+ const rem = (n) => `${round(n / 16)} * var(--veneer-rem)`
22
+ const isFluid = (v) => plain(v) && 'min' in v
23
+
24
+ /** `{ min, max, from, to }` in px: min at the `from` width, max at `to`, held outside them. */
25
+ function fluidCss(v, from, at) {
26
+ const { min, max, to } = v
27
+ if (![min, max, from, to].every(Number.isFinite) || !(to > from))
28
+ throw bad(at, 'must be { min, max, from, to } in px, with to wider than from')
29
+ const slope = (max - min) / (to - from)
30
+ const line = `calc(${rem(min - slope * from)} + ${round(slope * 100)}vw)`
31
+ return `clamp(calc(${rem(Math.min(min, max))}), ${line}, calc(${rem(Math.max(min, max))}))`
32
+ }
33
+
34
+ /** One value as CSS: plain, or a fluid line for a length. */
35
+ function valueCss(prop, v, { from, at }) {
36
+ if (isFluid(v)) {
37
+ if (prop !== 'size' && prop !== 'tracking') throw bad(at, 'only size and tracking can be fluid')
38
+ return fluidCss(v, v.from ?? from, at)
39
+ }
40
+ if (!safe(v)) throw bad(at, 'must be a CSS value, a number, or { base, <min-width>: value }')
41
+ return format(prop, v)
42
+ }
43
+
44
+ /** A property's value into `out`, or its base into `out` and each breakpoint's value into `media`. */
45
+ function place(token, prop, v, { out, media, at }) {
46
+ if (!plain(v) || isFluid(v)) {
47
+ out[token] = valueCss(prop, v, { at })
48
+ return
49
+ }
50
+ for (const [key, step] of Object.entries(v)) {
51
+ if (key === 'base') out[token] = valueCss(prop, step, { at: `${at}.base` })
52
+ else if (/^[1-9]\d*$/.test(key))
53
+ (media[key] ??= {})[token] = valueCss(prop, step, { from: Number(key), at: `${at}.${key}` })
54
+ else throw bad(`${at}.${key}`, 'must be base or a min-width in px, like 768')
55
+ }
56
+ }
57
+
58
+ /** Writes one role's tokens into `out` and `media`; an app's role also records its properties in `roles`. */
59
+ export function textTokens(role, value, { tokenNames, out, media, roles, at }) {
60
+ if (!plain(value)) throw bad(at, 'must be { size, weight, leading, tracking, case, font }')
61
+ const own = [...tokenNames].some((t) => t.startsWith(`--veneer-text-${role}-`))
62
+ if (!own && !NAME.test(role)) throw bad(at, 'must be a lowercase name, like narrative')
63
+ for (const [prop, v] of Object.entries(value)) {
64
+ const token = `--veneer-text-${role}-${prop}`
65
+ if (!PROPS[prop])
66
+ throw bad(`${at}.${prop}`, `unknown property; use ${Object.keys(PROPS).join(', ')}`)
67
+ if (own && !tokenNames.has(token)) throw bad(`${at}.${prop}`, `veneer has no ${token}`)
68
+ place(token, prop, v, { out, media, at: `${at}.${prop}` })
69
+ if (!own) (roles[role] ??= new Set()).add(prop)
70
+ }
71
+ }
72
+
73
+ /** Each breakpoint's tokens on `selector` in `layer`, narrowest first (integer keys iterate in order). */
74
+ export const mediaCss = (media = {}, layer, selector) =>
75
+ Object.entries(media)
76
+ .map(
77
+ ([width, tokens]) =>
78
+ `@media (min-width:${width}px){@layer ${layer}{${selector}{${Object.entries(tokens)
79
+ .map(([k, v]) => `${k}:${v}`)
80
+ .join(';')}}}}\n`,
81
+ )
82
+ .join('')
83
+
84
+ /** The rules for the app's roles, in veneer.layout beside veneer's own, so the app's CSS still wins. */
85
+ export function roleCss(roles = {}) {
86
+ const rules = Object.entries(roles).map(
87
+ ([role, props]) =>
88
+ `:where([data-scope="text"][data-role="${role}"]){${[...props]
89
+ .map((p) => `${PROPS[p]}:var(--veneer-text-${role}-${p})`)
90
+ .join(';')}}`,
91
+ )
92
+ return rules.length ? `@layer veneer.layout{${rules.join('')}}\n` : ''
93
+ }
@@ -0,0 +1,15 @@
1
+ // How the theme compiler reads one configured value: the checks and formats its modules share.
2
+ export const NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/
3
+
4
+ export const bad = (path, message) => Object.assign(new Error(message), { path })
5
+ export const plain = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
6
+ export const safe = (v) =>
7
+ (typeof v === 'string' && v !== '' && !/[;{}<>]/.test(v)) || Number.isFinite(v)
8
+ export const px = (v) => (Number.isFinite(v) ? `${v}px` : v)
9
+
10
+ const stack = (v) =>
11
+ v.includes(',') || v.startsWith('var(')
12
+ ? v
13
+ : `${JSON.stringify(v)}, ui-sans-serif, system-ui, sans-serif`
14
+ export const fontValue = (v) =>
15
+ ['sans', 'display', 'mono'].includes(v) ? `var(--veneer-font-${v})` : stack(v)
@@ -0,0 +1,82 @@
1
+ /** The stylesheet facts the compiler reads: veneer's layer order, scope roots, token names and accent formulas. */
2
+ export interface ThemeContext {
3
+ layers: string[]
4
+ scopes: string
5
+ tokenNames: Set<string>
6
+ formulas: Record<string, string>
7
+ stops?: Record<string, string>
8
+ }
9
+
10
+ /** One configured property on one part, in one state. */
11
+ export interface PartRow {
12
+ part: string
13
+ prop: string
14
+ state: string | null
15
+ value: string
16
+ }
17
+
18
+ /** A named theme after checking: its seed, colours, tokens and part rows. */
19
+ export interface CheckedTheme {
20
+ seed?: { hue: number; chroma: number; neutral?: { hue: number; chroma: number } }
21
+ colors: Record<string, string>
22
+ system: Record<string, string>
23
+ rows: PartRow[]
24
+ /** Tokens a breakpoint sets, by min-width in px. */
25
+ media?: Record<string, Record<string, string>>
26
+ }
27
+
28
+ /** `colors`, `system`, `parts` and `themes` after checking, ready for themeCss(). */
29
+ export interface ThemeOptions {
30
+ colors?: Record<string, string>
31
+ system: Record<string, string>
32
+ rows: PartRow[]
33
+ themes: Record<string, CheckedTheme>
34
+ default?: string
35
+ /** The app's own text roles (not veneer's), each with the properties it sets. */
36
+ roles?: Record<string, Set<string>>
37
+ /** Tokens a breakpoint sets, by min-width in px. */
38
+ media?: Record<string, Record<string, string>>
39
+ }
40
+
41
+ /** Checks `colors`, `system`, `parts` and `themes`; throws an Error with `path` on the first bad value. */
42
+ export function themeOptions(
43
+ input: Record<string, unknown>,
44
+ tokenNames: Set<string>,
45
+ check: {
46
+ seed: (seed: unknown, path: string, colors: Record<string, string>) => unknown
47
+ tokens: (tokens: Record<string, string> | undefined, path: string) => Record<string, string>
48
+ },
49
+ ): ThemeOptions
50
+
51
+ /** The CSS for checked options. */
52
+ export function themeCss(options: ThemeOptions, context: Omit<ThemeContext, 'tokenNames'>): string
53
+
54
+ /** Part text on a part fill below 4.5:1, as messages. */
55
+ export function partContrast(
56
+ rows: PartRow[],
57
+ colors: Record<string, string>,
58
+ scope: string,
59
+ ): string[]
60
+
61
+ /** `tokens` checked: `--veneer-*` names with CSS values. Throws with `path`. */
62
+ export function checkTokens(
63
+ tokens: Record<string, string> | undefined,
64
+ path: string,
65
+ ): Record<string, string> | undefined
66
+
67
+ /** A seed as `{ hue, chroma, neutral? }`; throws on a value out of range. */
68
+ export function normalizeSeed(seed: unknown): {
69
+ hue: number
70
+ chroma: number
71
+ neutral?: { hue: number; chroma: number }
72
+ }
73
+
74
+ /** A seed with colour names swapped for the colours they name. */
75
+ export function seedByName(seed: unknown, colors?: Record<string, unknown>): unknown
76
+
77
+ /** The parts table; `@kerf-js/veneer/theme-parts` has it typed. */
78
+ export const PARTS: Record<string, unknown>
79
+ /** Tailwind v4 `@theme` names for the configured colours. */
80
+ export function tailwindTheme(options: Record<string, unknown>): string
81
+ /** A colour's tone channels, solved as veneer solves its accent. */
82
+ export function toneChannels(hex: string, formulas: Record<string, string>): string