@micha.bigler/ui-core-micha 3.14.4 → 4.0.1

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 (341) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +7 -0
  3. package/dist/chat/kitSxRegistry.js +9 -0
  4. package/dist/components/charts/kitSxRegistry.js +6 -0
  5. package/dist/entries/charts.js +6 -0
  6. package/dist/entries/chat.js +8 -0
  7. package/dist/entries/markdown.js +1 -0
  8. package/dist/index.js +0 -14
  9. package/dist/pages/AccountPage.js +1 -2
  10. package/dist/pages/LoginPage.js +1 -2
  11. package/dist/pages/PasswordChangePage.js +1 -2
  12. package/dist/pages/PasswordInvitePage.js +1 -2
  13. package/dist/pages/PasswordResetRequestPage.js +1 -2
  14. package/dist/pages/SignUpPage.js +1 -2
  15. package/dist/pages/SignupConfirmPage.js +1 -2
  16. package/dist/theme/kitSxEntry.js +11 -0
  17. package/dist/theme/kitSxRegistry.js +2 -15
  18. package/package.json +31 -7
  19. package/.github/workflows/ci.yml +0 -35
  20. package/.github/workflows/publish.yml +0 -126
  21. package/DESIGN.md +0 -60
  22. package/WORK_ORDERS.md +0 -150
  23. package/dev/entries.jsx +0 -721
  24. package/dev/fixtures.js +0 -26
  25. package/dev/main.jsx +0 -75
  26. package/dev/mockTransport.jsx +0 -128
  27. package/docs/CHART-LAYOUT.md +0 -157
  28. package/docs/DARK-TOKENS.md +0 -140
  29. package/docs/TYPE-SCALE.md +0 -111
  30. package/docs/messaging-deviations.md +0 -118
  31. package/index.html +0 -12
  32. package/renovate.json +0 -10
  33. package/scripts/chart-api-census.mjs +0 -415
  34. package/src/auth/AuthContext.jsx +0 -158
  35. package/src/auth/ReauthModal.jsx +0 -82
  36. package/src/auth/UserMenu.jsx +0 -121
  37. package/src/auth/apiClient.jsx +0 -232
  38. package/src/auth/authApi.jsx +0 -539
  39. package/src/auth/authConfig.jsx +0 -34
  40. package/src/auth/reauth.js +0 -47
  41. package/src/chat/ChatComposer.jsx +0 -36
  42. package/src/chat/ChatList.jsx +0 -87
  43. package/src/chat/ChatThread.jsx +0 -128
  44. package/src/chat/ChatWorkspace.jsx +0 -244
  45. package/src/chat/MarkdownReply.jsx +0 -22
  46. package/src/chat/ModelPicker.jsx +0 -85
  47. package/src/chat/api.js +0 -18
  48. package/src/chat/useChatSocket.js +0 -32
  49. package/src/chat/wire.js +0 -7
  50. package/src/components/AccessCodeManager.jsx +0 -288
  51. package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
  52. package/src/components/AllowedEmailDomainsManager.jsx +0 -92
  53. package/src/components/AuthFactorRequirementCard.jsx +0 -95
  54. package/src/components/BulkInviteCsvTab.jsx +0 -198
  55. package/src/components/EmptyState.jsx +0 -38
  56. package/src/components/LoginForm.jsx +0 -159
  57. package/src/components/MFAComponent.jsx +0 -350
  58. package/src/components/MfaLoginComponent.jsx +0 -252
  59. package/src/components/MobileBottomNav.jsx +0 -82
  60. package/src/components/PasskeysComponent.jsx +0 -252
  61. package/src/components/PasswordChangeForm.jsx +0 -87
  62. package/src/components/PasswordResetRequestForm.jsx +0 -43
  63. package/src/components/PasswordSetForm.jsx +0 -97
  64. package/src/components/ProfileComponent.jsx +0 -348
  65. package/src/components/QrSignupManager.jsx +0 -404
  66. package/src/components/QrSignupValidityManager.jsx +0 -106
  67. package/src/components/RegistrationMethodsManager.jsx +0 -150
  68. package/src/components/SecurityComponent.jsx +0 -141
  69. package/src/components/SocialLoginButtons.jsx +0 -83
  70. package/src/components/SoftChip.jsx +0 -93
  71. package/src/components/StatTile.jsx +0 -39
  72. package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
  73. package/src/components/TurnstileWidget.jsx +0 -99
  74. package/src/components/UserInviteComponent.jsx +0 -76
  75. package/src/components/UserListComponent.jsx +0 -618
  76. package/src/components/charts/BarChart.jsx +0 -102
  77. package/src/components/charts/ChartFrame.jsx +0 -214
  78. package/src/components/charts/LineChart.jsx +0 -126
  79. package/src/components/charts/ScatterChart.jsx +0 -299
  80. package/src/components/charts/TimeSeriesChart.jsx +0 -300
  81. package/src/components/charts/chartDefaults.js +0 -644
  82. package/src/components/charts/chartLabels.js +0 -36
  83. package/src/components/charts/exportChart.js +0 -258
  84. package/src/components/charts/formatters.js +0 -39
  85. package/src/components/charts/palette.js +0 -33
  86. package/src/components/charts/yearTickInterval.js +0 -7
  87. package/src/i18n/authTranslations.ts +0 -2651
  88. package/src/i18n/chartsTranslations.ts +0 -91
  89. package/src/i18n/chatTranslations.ts +0 -55
  90. package/src/i18n/messagingTranslations.ts +0 -120
  91. package/src/i18n/notificationsTranslations.ts +0 -32
  92. package/src/i18n/onboardingTranslations.ts +0 -29
  93. package/src/i18n/sectionNavTranslations.ts +0 -20
  94. package/src/i18n/uiCoreTranslations.js +0 -29
  95. package/src/i18n/userMenuTranslations.ts +0 -5
  96. package/src/index.js +0 -158
  97. package/src/layout/PageLayout.jsx +0 -36
  98. package/src/layout/SectionNav.jsx +0 -320
  99. package/src/messaging/AttachmentList.jsx +0 -145
  100. package/src/messaging/Composer.jsx +0 -197
  101. package/src/messaging/ConversationLaunchers.jsx +0 -51
  102. package/src/messaging/ConversationList.jsx +0 -109
  103. package/src/messaging/DirectMessageLauncher.jsx +0 -112
  104. package/src/messaging/MessageBubble.jsx +0 -183
  105. package/src/messaging/MessagingProvider.jsx +0 -0
  106. package/src/messaging/MessagingScopeConfig.jsx +0 -24
  107. package/src/messaging/PollCard.jsx +0 -163
  108. package/src/messaging/ReactionBar.jsx +0 -43
  109. package/src/messaging/ReadTicks.jsx +0 -82
  110. package/src/messaging/Thread.jsx +0 -195
  111. package/src/messaging/api.js +0 -48
  112. package/src/messaging/composerImageCompression.js +0 -35
  113. package/src/messaging/linkifyText.jsx +0 -37
  114. package/src/notifications/NotificationBell.jsx +0 -84
  115. package/src/notifications/NotificationSettings.jsx +0 -330
  116. package/src/notifications/NotificationsProvider.jsx +0 -224
  117. package/src/notifications/PopupSurface.jsx +0 -105
  118. package/src/notifications/api.js +0 -55
  119. package/src/notifications/feedApi.js +0 -18
  120. package/src/notifications/realtime.jsx +0 -138
  121. package/src/notifications/serviceWorker/sw.js +0 -50
  122. package/src/onboarding/OnboardingProvider.jsx +0 -326
  123. package/src/onboarding/OnboardingWizard.jsx +0 -61
  124. package/src/onboarding/WizardDialogShell.jsx +0 -51
  125. package/src/onboarding/api.js +0 -13
  126. package/src/onboarding/stepSelection.js +0 -16
  127. package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
  128. package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
  129. package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
  130. package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
  131. package/src/pages/AccountPage.jsx +0 -394
  132. package/src/pages/LoginPage.jsx +0 -343
  133. package/src/pages/PasswordChangePage.jsx +0 -62
  134. package/src/pages/PasswordInvitePage.jsx +0 -177
  135. package/src/pages/PasswordResetRequestPage.jsx +0 -68
  136. package/src/pages/SignUpPage.jsx +0 -268
  137. package/src/pages/SignupConfirmPage.jsx +0 -155
  138. package/src/testing/checkKitIntegration.js +0 -233
  139. package/src/theme/createAppTheme.js +0 -423
  140. package/src/theme/fonts.js +0 -3
  141. package/src/theme/index.js +0 -21
  142. package/src/theme/kitSxRegistry.js +0 -285
  143. package/src/theme/themeCompleteness.js +0 -1045
  144. package/src/theme/tokens.js +0 -478
  145. package/src/utils/auth-errors.js +0 -76
  146. package/src/utils/authService.js +0 -223
  147. package/src/utils/resolveErrorText.js +0 -28
  148. package/src/utils/webauthn.js +0 -51
  149. package/tests/AccountPage.profileStatements.test.jsx +0 -162
  150. package/tests/AccountPage.test.jsx +0 -200
  151. package/tests/AuthContext.test.jsx +0 -129
  152. package/tests/BarChart.test.jsx +0 -112
  153. package/tests/BrowserPushStep.test.jsx +0 -110
  154. package/tests/ChartFrame.test.jsx +0 -336
  155. package/tests/ConversationList.test.jsx +0 -144
  156. package/tests/CookieConsentStep.test.jsx +0 -69
  157. package/tests/EmptyState.test.jsx +0 -62
  158. package/tests/LineChart.test.jsx +0 -80
  159. package/tests/MessagingProvider.test.jsx +0 -50
  160. package/tests/MobileBottomNav.test.jsx +0 -319
  161. package/tests/NotificationBell.test.jsx +0 -60
  162. package/tests/NotificationSettings.test.jsx +0 -276
  163. package/tests/NotificationsProvider.test.jsx +0 -240
  164. package/tests/OnboardingProvider.test.jsx +0 -294
  165. package/tests/OnboardingWizard.test.jsx +0 -143
  166. package/tests/PasswordChangeForm.test.jsx +0 -70
  167. package/tests/PasswordInvitePage.test.jsx +0 -142
  168. package/tests/PasswordSetForm.test.jsx +0 -70
  169. package/tests/PopupSurface.test.jsx +0 -142
  170. package/tests/ProfileComponent.refresh.test.jsx +0 -194
  171. package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
  172. package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
  173. package/tests/ScatterChart.test.jsx +0 -270
  174. package/tests/SectionNav.test.jsx +0 -363
  175. package/tests/SignUpPage.test.jsx +0 -208
  176. package/tests/SoftChip.test.jsx +0 -105
  177. package/tests/StatTile.test.jsx +0 -57
  178. package/tests/Thread.test.jsx +0 -151
  179. package/tests/TimeSeriesChart.test.jsx +0 -367
  180. package/tests/UserListComponent.test.jsx +0 -192
  181. package/tests/UserMenu.test.jsx +0 -171
  182. package/tests/apiClientLanguage.test.js +0 -33
  183. package/tests/apiClientPublicPaths.test.js +0 -178
  184. package/tests/authApiLogin.test.js +0 -42
  185. package/tests/authApiRegistration.test.js +0 -31
  186. package/tests/authErrorCodeRendering.test.jsx +0 -77
  187. package/tests/authErrors.test.js +0 -74
  188. package/tests/authTranslations.test.js +0 -74
  189. package/tests/chart-api-census.test.js +0 -366
  190. package/tests/chartAxisTickBand.test.jsx +0 -95
  191. package/tests/chartDefaults.test.js +0 -902
  192. package/tests/chartLabels.test.js +0 -50
  193. package/tests/chartsPalette.test.js +0 -99
  194. package/tests/chatApi.test.js +0 -48
  195. package/tests/chatDriverNames.test.jsx +0 -71
  196. package/tests/chatExports.test.js +0 -3
  197. package/tests/chatList.test.jsx +0 -84
  198. package/tests/chatPicker.test.jsx +0 -82
  199. package/tests/chatSocket.test.jsx +0 -26
  200. package/tests/chatThread.test.jsx +0 -116
  201. package/tests/chatTranslations.test.js +0 -47
  202. package/tests/chatWorkspace.test.jsx +0 -234
  203. package/tests/checkKitIntegration.test.jsx +0 -219
  204. package/tests/createAppTheme.test.js +0 -132
  205. package/tests/createAppThemeDark.test.js +0 -127
  206. package/tests/createAppThemeLightGuard.test.js +0 -40
  207. package/tests/createAppThemePageContrast.test.js +0 -108
  208. package/tests/createAppThemeTypography.test.js +0 -53
  209. package/tests/errorCallSiteGuard.test.js +0 -32
  210. package/tests/exportChart.test.js +0 -313
  211. package/tests/feedApi.test.js +0 -46
  212. package/tests/fixtures/light-theme-baseline.json +0 -2234
  213. package/tests/i18nAggregate.test.js +0 -120
  214. package/tests/i18nGermanVariant.test.js +0 -65
  215. package/tests/loginPageErrorResolution.test.jsx +0 -102
  216. package/tests/messagingApi.test.js +0 -32
  217. package/tests/messagingChunk6.test.jsx +0 -116
  218. package/tests/messagingCompactBubble.test.jsx +0 -64
  219. package/tests/messagingComposer.test.jsx +0 -136
  220. package/tests/messagingComposerChunk5.test.jsx +0 -113
  221. package/tests/messagingContractConformance.test.js +0 -69
  222. package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
  223. package/tests/messagingExports.test.js +0 -21
  224. package/tests/messagingInteractions.test.jsx +0 -136
  225. package/tests/messagingLastMessagePreview.test.jsx +0 -93
  226. package/tests/messagingLinkify.test.jsx +0 -51
  227. package/tests/messagingMessageActions.test.jsx +0 -163
  228. package/tests/messagingMsg6.test.jsx +0 -105
  229. package/tests/messagingMsg6f.test.jsx +0 -155
  230. package/tests/messagingMsg6g.test.jsx +0 -166
  231. package/tests/messagingMsg6h.test.jsx +0 -136
  232. package/tests/messagingMsg6i.test.jsx +0 -129
  233. package/tests/messagingPollRendering.test.jsx +0 -142
  234. package/tests/messagingReactionMerge.test.jsx +0 -77
  235. package/tests/messagingReadTicksTooltip.test.jsx +0 -36
  236. package/tests/messagingThreadReceipts.test.jsx +0 -178
  237. package/tests/messagingThreadingQuoting.test.jsx +0 -87
  238. package/tests/messagingUnreadLifecycle.test.jsx +0 -78
  239. package/tests/notificationsApi.test.js +0 -41
  240. package/tests/notificationsExports.test.js +0 -34
  241. package/tests/onboardingDescriptors.test.js +0 -132
  242. package/tests/packageTreeShaking.test.js +0 -126
  243. package/tests/realtime.test.jsx +0 -219
  244. package/tests/resolveErrorText.test.js +0 -72
  245. package/tests/stepSelection.test.js +0 -53
  246. package/tests/themeCompleteness.test.js +0 -626
  247. package/tests/timeSeriesLegend.test.js +0 -99
  248. package/tests/userScreenTranslations.test.jsx +0 -218
  249. package/tsconfig.build.json +0 -18
  250. package/vite.config.mjs +0 -6
  251. package/work-orders/AUTH-1.md +0 -74
  252. package/work-orders/AUTH-2.md +0 -74
  253. package/work-orders/AUTH-4.md +0 -183
  254. package/work-orders/AUTH-5.md +0 -154
  255. package/work-orders/AUTH-7.md +0 -181
  256. package/work-orders/AUTH-8.md +0 -184
  257. package/work-orders/CHART-1.md +0 -285
  258. package/work-orders/CHART-2.md +0 -222
  259. package/work-orders/CHART-3.md +0 -163
  260. package/work-orders/CHART-4.md +0 -203
  261. package/work-orders/CHART-5.md +0 -226
  262. package/work-orders/CHART-6.md +0 -428
  263. package/work-orders/CHART-7.md +0 -175
  264. package/work-orders/DX-1.md +0 -169
  265. package/work-orders/DX-2.md +0 -188
  266. package/work-orders/DX-3.md +0 -195
  267. package/work-orders/I18N-1.md +0 -254
  268. package/work-orders/I18N-3.md +0 -207
  269. package/work-orders/MSG-3.md +0 -375
  270. package/work-orders/MSG-3b.md +0 -1002
  271. package/work-orders/MSG-3c.md +0 -378
  272. package/work-orders/MSG-3d.md +0 -268
  273. package/work-orders/MSG-3e.md +0 -164
  274. package/work-orders/MSG-3f.md +0 -391
  275. package/work-orders/MSG-6e.md +0 -308
  276. package/work-orders/MSG-6f.md +0 -214
  277. package/work-orders/MSG-6g.md +0 -244
  278. package/work-orders/MSG-6h.md +0 -238
  279. package/work-orders/MSG-6i.md +0 -271
  280. package/work-orders/MSG-6j.md +0 -117
  281. package/work-orders/NOTIF-12.md +0 -214
  282. package/work-orders/NOTIF-13.md +0 -142
  283. package/work-orders/NOTIF-14.md +0 -151
  284. package/work-orders/PRIM-1.md +0 -177
  285. package/work-orders/SHELL-1.md +0 -255
  286. package/work-orders/SHELL-2.md +0 -197
  287. package/work-orders/SHELL-3.md +0 -359
  288. package/work-orders/SHELL-4.md +0 -351
  289. package/work-orders/SHELL-5.md +0 -345
  290. package/work-orders/SHELL-6.md +0 -210
  291. package/work-orders/THEME-1.md +0 -587
  292. package/work-orders/THEME-10.md +0 -303
  293. package/work-orders/THEME-11.md +0 -208
  294. package/work-orders/THEME-2.md +0 -339
  295. package/work-orders/THEME-3.md +0 -210
  296. package/work-orders/THEME-4.md +0 -271
  297. package/work-orders/THEME-5.md +0 -341
  298. package/work-orders/THEME-6.md +0 -247
  299. package/work-orders/THEME-7.md +0 -82
  300. package/work-orders/THEME-8.md +0 -211
  301. package/work-orders/THEME-9.md +0 -194
  302. package/work-orders/UCM-AUTH-10.md +0 -490
  303. package/work-orders/UCM-AUTH-11.md +0 -185
  304. package/work-orders/UCM-AUTH-12.md +0 -98
  305. package/work-orders/UCM-AUTH-13.md +0 -47
  306. package/work-orders/UCM-AUTH-9.md +0 -207
  307. package/work-orders/UCM-CHART-10.md +0 -150
  308. package/work-orders/UCM-CHART-11.md +0 -132
  309. package/work-orders/UCM-CHART-12.md +0 -348
  310. package/work-orders/UCM-CHART-13.md +0 -122
  311. package/work-orders/UCM-CHART-14.md +0 -198
  312. package/work-orders/UCM-CHART-15.md +0 -187
  313. package/work-orders/UCM-CHART-16.md +0 -169
  314. package/work-orders/UCM-CHART-17.md +0 -195
  315. package/work-orders/UCM-CHART-18.md +0 -200
  316. package/work-orders/UCM-CHART-8.md +0 -147
  317. package/work-orders/UCM-CHART-9.md +0 -265
  318. package/work-orders/UCM-CHAT-1.md +0 -190
  319. package/work-orders/UCM-CHAT-2.md +0 -75
  320. package/work-orders/UCM-CI-1.md +0 -65
  321. package/work-orders/UCM-DEP-1.md +0 -63
  322. package/work-orders/UCM-I18N-4.md +0 -226
  323. package/work-orders/UCM-I18N-5.md +0 -211
  324. package/work-orders/UCM-MSG-20.md +0 -192
  325. package/work-orders/UCM-PRIM-2.md +0 -114
  326. package/work-orders/UCM-SHELL-7.md +0 -134
  327. package/work-orders/UCM-SHELL-8.md +0 -125
  328. package/work-orders/UCM-TEST-1.md +0 -304
  329. package/work-orders/UCM-THEME-13.md +0 -69
  330. package/work-orders/UCM-THEME-14.md +0 -312
  331. package/work-orders/UCM-THEME-15.md +0 -356
  332. package/work-orders/UCM-THEME-16.md +0 -80
  333. package/work-orders/UCM-THEME-17.md +0 -111
  334. package/work-orders/UCM-THEME-18.md +0 -184
  335. package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
  336. package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
  337. package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
  338. package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
  339. package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
  340. package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
  341. package/work-orders/assets/UCM-THEME-17-type-scale.html +0 -391
@@ -1,36 +0,0 @@
1
- // Short, granularity-aware x-axis tick labels.
2
- //
3
- // Not a style choice -- MUI X-Charts has a known, unfixed bug (mui-x#18768,
4
- // duplicate of #18399): when the measured space for a tick label gets
5
- // tight, its ellipsize() logic doesn't truncate the text, it collapses it
6
- // to an empty string (the <tspan> stays in the DOM with no content). It
7
- // only reproduces with long label text ("08/05, 10:00 AM"-style, ~16
8
- // characters) combined with this app's actual font metrics (DM Sans) --
9
- // short labels like "05.08." or "10:00" leave enough margin that the bug
10
- // never triggers. Same fix already proven in jg-ferien's ActivitySection.
11
-
12
- // `locale` defaults to "de-CH" only as a fallback for callers that don't
13
- // pass the app's active i18n language (found in review: an earlier version
14
- // hardcoded "de-CH" always, showing German month names to en/fr users).
15
-
16
- export function formatShortTime(date, locale = 'de-CH') {
17
- // hour12 forced false regardless of locale -- an English 12-hour label
18
- // ("10:00 AM") is exactly the longer style that triggered the original
19
- // collapse bug; staying short is the point, not locale fidelity here.
20
- return date.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit', hour12: false });
21
- }
22
-
23
- export function formatShortDate(date, locale = 'de-CH') {
24
- return date.toLocaleDateString(locale, { day: '2-digit', month: '2-digit' });
25
- }
26
-
27
- export function formatShortMonth(date, locale = 'de-CH') {
28
- return date.toLocaleDateString(locale, { month: 'short', year: '2-digit' });
29
- }
30
-
31
- // "All" spans years -- day/month labels repeat (e.g. every "01.04." shows up
32
- // once per year) and read as meaningless noise; a bare year number is the
33
- // only granularity dense multi-year history can show cleanly.
34
- export function formatShortYear(date, locale = 'de-CH') {
35
- return date.toLocaleDateString(locale, { year: 'numeric' });
36
- }
@@ -1,258 +0,0 @@
1
- // UCM-CHART-17: the two exports promise two different things and now keep them.
2
- //
3
- // SVG stays a true, portable vector: only the chart's own MUI x-charts surface, but with the
4
- // computed styles that render it correctly (font, colour, stroke) written inline, since nothing
5
- // downstream of a cloned+serialised node carries the page's emotion CSS classes. PNG rasterises
6
- // the whole container -- chart, hand-built legend, size key, footnotes -- because that is what
7
- // the screen actually shows (`AccessGapScatterPanel` and its siblings render the legend/size key
8
- // as HTML/SVG siblings of the chart since `HRAM-RES-39`/`HRAM-VIS-2`, outside the chart's own SVG).
9
- //
10
- // Both paths route DOM through an SVG (`<foreignObject>` for the PNG's arbitrary HTML+SVG mix,
11
- // direct serialisation for the chart-only SVG) into an `Image`, then a `<canvas>` -- the platform's
12
- // own APIs, no rasteriser dependency added (this package's only runtime dependency stays
13
- // `@fontsource/dm-sans`). A library was seriously considered, not just skipped: the naive version
14
- // of this technique (an `Image` loaded from a `blob:` URL) taints the canvas on `toBlob` in Chrome
15
- // the moment the SVG contains a `<foreignObject>`, unconditionally -- see `rasterize`'s own comment
16
- // for how that was confirmed live and worked around with a `data:` URI instead, which is what
17
- // makes the platform-only approach actually viable rather than merely attempted.
18
- //
19
- // Font embedding: NOT done. Inlined `font-family` records the real value (e.g. `"DM Sans", ...`
20
- // with its documented fallback stack) instead of nothing at all, which is already a correctness
21
- // improvement over the pre-fix export (unstyled, arbitrary browser default). A machine without DM
22
- // Sans installed falls back through that stack -- an honest, visible degradation, not a silent one,
23
- // and embedding the font file was judged not worth the added complexity/weight for this WO.
24
-
25
- const SVG_NS = 'http://www.w3.org/2000/svg';
26
- const XHTML_NS = 'http://www.w3.org/1999/xhtml';
27
-
28
- // Typography and SVG paint -- what actually makes a chart LOOK like the theme instead of bare SVG
29
- // defaults (tick fonts and sizes, axis/grid colours, text fill). Deliberately curated, not a full
30
- // `getComputedStyle` dump: every extra property is bytes in a file a human may open in Illustrator
31
- // or Inkscape.
32
- // UCM-CHART-18: `transform`/`transform-origin` added -- a rotated element (e.g. a legend swatch
33
- // rotated into a diamond) previously exported unrotated, since nothing wrote the resolved CSS
34
- // transform onto the clone. `getComputedStyle` returns the FINAL, resolved matrix -- already
35
- // incorporating an SVG element's own `transform` PRESENTATION ATTRIBUTE, which `cloneNode` also
36
- // keeps -- and an inline `style` declaration always wins over a presentation attribute (SVG2:
37
- // presentation attributes carry the lowest possible specificity), so writing the computed value
38
- // inline overrides rather than composes with it. Verified live against a rotated legend swatch and
39
- // against `xLabels="angled"` tick labels: neither double-rotates or double-displaces.
40
- const CHART_STYLE_PROPERTIES = [
41
- 'font-family', 'font-size', 'font-weight', 'font-style', 'line-height', 'letter-spacing',
42
- 'fill', 'stroke', 'stroke-width', 'stroke-dasharray', 'stroke-linecap', 'stroke-linejoin',
43
- 'opacity', 'fill-opacity', 'stroke-opacity', 'text-anchor', 'dominant-baseline', 'color',
44
- 'transform', 'transform-origin',
45
- ];
46
-
47
- // Box layout/appearance for the HTML legend and size key a panel renders beside the chart --
48
- // only needed for the PNG's whole-container rasterisation, where a hand-built legend is plain
49
- // HTML with no chart-specific paint properties of its own. `overflow` and the grid properties
50
- // (reviewer finding) cover MUI's own composed layouts too, not only a hand-built flex legend --
51
- // `ChartsSurface` itself sits in a `grid-area`, so a container that lets MUI position multiple
52
- // parts via CSS Grid needs those to reposition correctly once cloned out of the page.
53
- const CONTAINER_LAYOUT_STYLE_PROPERTIES = [
54
- 'background-color', 'border-color', 'border-width', 'border-style', 'border-radius',
55
- 'display', 'flex-direction', 'flex-wrap', 'flex', 'align-items', 'justify-content',
56
- 'justify-items', 'align-content', 'gap', 'overflow',
57
- 'grid-template-columns', 'grid-template-rows', 'grid-template-areas', 'grid-area',
58
- 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
59
- 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
60
- 'width', 'height', 'box-sizing', 'text-align', 'white-space',
61
- ];
62
-
63
- // Deliberate, not positional (UCM-CHART-17 scope item 3): MUI x-charts' own root `<svg>` always
64
- // carries `MuiChartsSurface-root` (`@mui/x-charts/ChartsSurface`) -- a stable selector, unlike "the
65
- // first svg in the container", which silently exported a size-key SVG once one existed ahead of
66
- // the chart. Falls back to the first SVG for a bespoke (non-MUI) SVG child, which `ChartFrame`'s
67
- // own docblock explicitly allows.
68
- function findChartSvg(chartContainer) {
69
- const svg = chartContainer?.querySelector('svg.MuiChartsSurface-root') || chartContainer?.querySelector('svg');
70
- if (!svg) throw new Error('Chart container does not contain an SVG element.');
71
- return svg;
72
- }
73
-
74
- // UCM-CHART-18: an exported image shows what the chart COMMUNICATES, not what can be clicked --
75
- // a panel's own controls (an info `IconButton`, a drill-down `Button`, ...) live in `children`
76
- // alongside the chart (`ChartFrame`'s `chartRef` wraps `children` only, not `toolbar`/`controls`/
77
- // `meta`), so the whole-container PNG picked them up once it started rasterising `chartRef` in
78
- // full (`UCM-CHART-17`). `[role="button"]` catches MUI's own non-native button-like elements (e.g.
79
- // an `IconButton` can render as a `<span>`/`<div>` with that role) that a tag-name selector alone
80
- // would miss; `a[href]`/`[role="link"]` (reviewer finding) cover a drill-down built as a link
81
- // rather than a `<button>`.
82
- const INTERACTIVE_CONTROL_SELECTOR = 'button, input, select, textarea, [role="button"], a[href], [role="link"]';
83
-
84
- // ui_reviewer + reviewer finding, independently: MUI's OWN chart legend can be interactive
85
- // (`onItemClick`/`toggleVisibilityOnClick`) and, when it is, X-Charts renders each legend item as
86
- // `<button role="button" class="...MuiChartsLegend-series...">`, WRAPPING the series swatch and
87
- // label -- that markup IS the legend's explanatory content, not chrome, and the WO's own risk
88
- // section says exactly this: "if it vanishes, that is a finding that changes the approach, not a
89
- // detail to paper over." A blanket `.remove()` would delete the swatch+label along with the click
90
- // handler. Unwrapped instead: replace the interactive element with a plain, non-interactive one
91
- // carrying the SAME class/style/children, so the legend keeps every pixel of content while losing
92
- // only its clickability (irrelevant anyway -- a rasterised PNG has no click handlers regardless).
93
- const MUI_INTERACTIVE_LEGEND_ITEM_SELECTOR = '.MuiChartsLegend-series';
94
-
95
- function stripInteractiveControls(clone) {
96
- clone.querySelectorAll(INTERACTIVE_CONTROL_SELECTOR).forEach((node) => {
97
- if (node.matches(MUI_INTERACTIVE_LEGEND_ITEM_SELECTOR)) {
98
- const unwrapped = document.createElement('span');
99
- unwrapped.className = node.className;
100
- const style = node.getAttribute('style');
101
- if (style) unwrapped.setAttribute('style', style);
102
- while (node.firstChild) unwrapped.appendChild(node.firstChild);
103
- node.replaceWith(unwrapped);
104
- return;
105
- }
106
- node.remove();
107
- });
108
- }
109
-
110
- // Walks `sourceRoot` and `cloneRoot` in lockstep (both traversed in the same, deterministic
111
- // document order, since `cloneRoot` is a structural copy of `sourceRoot`) and writes each node's
112
- // RESOLVED style for `properties` onto the clone as an inline `style` attribute. This is what
113
- // carries the page's emotion CSS classes (which the clone keeps by name but not by rule) into a
114
- // standalone file that has no access to that stylesheet.
115
- function inlineComputedStyles(sourceRoot, cloneRoot, properties) {
116
- const sourceNodes = [sourceRoot, ...sourceRoot.querySelectorAll('*')];
117
- const cloneNodes = [cloneRoot, ...cloneRoot.querySelectorAll('*')];
118
- sourceNodes.forEach((sourceNode, index) => {
119
- const cloneNode = cloneNodes[index];
120
- if (!cloneNode || cloneNode.nodeType !== Node.ELEMENT_NODE) return;
121
- const computed = window.getComputedStyle(sourceNode);
122
- const declarations = properties
123
- .map((property) => `${property}: ${computed.getPropertyValue(property)}`)
124
- .join('; ');
125
- const existing = cloneNode.getAttribute('style');
126
- cloneNode.setAttribute('style', existing ? `${existing}; ${declarations}` : declarations);
127
- });
128
- }
129
-
130
- function svgToBlob(svg) {
131
- return new Blob([new XMLSerializer().serializeToString(svg)], { type: 'image/svg+xml;charset=utf-8' });
132
- }
133
-
134
- function download(blob, filename) {
135
- const url = URL.createObjectURL(blob);
136
- const anchor = document.createElement('a');
137
- anchor.href = url;
138
- anchor.download = filename;
139
- document.body.appendChild(anchor);
140
- anchor.click();
141
- anchor.remove();
142
- URL.revokeObjectURL(url);
143
- }
144
-
145
- // The chart's own surface, faithfully styled -- true vector, chart only. Does not gain the
146
- // legend/size key rendered beside it; that is correct for what this format is for (Part A).
147
- function chartSvgBlob(chartContainer) {
148
- const svg = findChartSvg(chartContainer);
149
- const clone = svg.cloneNode(true);
150
- inlineComputedStyles(svg, clone, CHART_STYLE_PROPERTIES);
151
- // reviewer finding: MUI's ChartsSurface only ever gives the root <svg> a `viewBox` -- its actual
152
- // pixel size comes from CSS (`width: 100%; height: 100%` against the page's own layout), which
153
- // has nothing to resolve against once cloned out to a standalone file. Without an explicit
154
- // width/height a standalone viewer falls back to the SVG UA default (typically 300x150).
155
- const rect = svg.getBoundingClientRect();
156
- clone.setAttribute('width', Math.ceil(rect.width) || svg.clientWidth || 1);
157
- clone.setAttribute('height', Math.ceil(rect.height) || svg.clientHeight || 1);
158
- clone.setAttribute('xmlns', SVG_NS);
159
- return svgToBlob(clone);
160
- }
161
-
162
- // The whole container, as seen -- chart plus everything the panel renders beside it, via an SVG
163
- // `<foreignObject>` wrapping a styled clone of the container's actual DOM. Standard platform
164
- // technique for DOM rasterisation without a library: the intermediate SVG is never downloaded, only
165
- // decoded into an `Image` and drawn onto a `<canvas>`.
166
- function containerSvgBlob(chartContainer) {
167
- const rect = chartContainer.getBoundingClientRect();
168
- const width = Math.ceil(rect.width) || chartContainer.scrollWidth || 1;
169
- const height = Math.ceil(rect.height) || chartContainer.scrollHeight || 1;
170
-
171
- const clone = chartContainer.cloneNode(true);
172
- inlineComputedStyles(chartContainer, clone, [...CHART_STYLE_PROPERTIES, ...CONTAINER_LAYOUT_STYLE_PROPERTIES]);
173
- // UCM-CHART-18 scope item 2, deliberately AFTER inlineComputedStyles, never before:
174
- // inlineComputedStyles walks `chartContainer` and `clone` IN LOCKSTEP BY INDEX
175
- // (`sourceNodes[i]` <-> `cloneNodes[i]`, both from `querySelectorAll('*')`). Removing nodes from
176
- // the clone first would shift every subsequent index out of alignment with the still-intact
177
- // source tree, so elements downstream of the first removal would silently receive a DIFFERENT
178
- // element's computed style -- wrong, but not obviously wrong, since the result still looks like a
179
- // styled export.
180
- stripInteractiveControls(clone);
181
- clone.setAttribute('xmlns', XHTML_NS);
182
-
183
- const svg = document.createElementNS(SVG_NS, 'svg');
184
- svg.setAttribute('xmlns', SVG_NS);
185
- svg.setAttribute('width', width);
186
- svg.setAttribute('height', height);
187
- svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
188
- const foreignObject = document.createElementNS(SVG_NS, 'foreignObject');
189
- foreignObject.setAttribute('width', '100%');
190
- foreignObject.setAttribute('height', '100%');
191
- foreignObject.appendChild(clone);
192
- svg.appendChild(foreignObject);
193
-
194
- return { svg, width, height };
195
- }
196
-
197
- // UCM-CHART-17 risk section, confirmed live (not assumed): an SVG containing a `<foreignObject>`
198
- // taints the canvas on `toBlob` in Chrome -- unconditionally, even with zero external references
199
- // (verified: a foreignObject holding nothing but plain styled text already triggers
200
- // `SecurityError: Tainted canvases may not be exported`) -- but ONLY when the image is loaded via
201
- // a `blob:` object URL. The identical SVG loaded via a `data:` URI does not taint the canvas at
202
- // all. This is why the SVG-only export (`chartSvgBlob`, no foreignObject) can keep using
203
- // `URL.createObjectURL` for its own download, while the PNG path's `Image` source specifically
204
- // must be a `data:` URI. No rasteriser dependency needed once this is accounted for.
205
- async function svgToDataUri(svg) {
206
- const svgString = await svgToBlob(svg).text();
207
- return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
208
- }
209
-
210
- async function rasterize(svg, width, height, backgroundColour) {
211
- const dataUri = await svgToDataUri(svg);
212
- return new Promise((resolve, reject) => {
213
- const image = new Image();
214
-
215
- image.onload = () => {
216
- try {
217
- const canvas = document.createElement('canvas');
218
- canvas.width = width * 2;
219
- canvas.height = height * 2;
220
- const context = canvas.getContext('2d');
221
- context.fillStyle = backgroundColour;
222
- context.fillRect(0, 0, canvas.width, canvas.height);
223
- context.drawImage(image, 0, 0, canvas.width, canvas.height);
224
- canvas.toBlob((blob) => {
225
- if (!blob) {
226
- reject(new Error('Unable to create PNG export.'));
227
- return;
228
- }
229
- resolve(blob);
230
- }, 'image/png');
231
- } catch (error) {
232
- reject(error);
233
- }
234
- };
235
- image.onerror = () => {
236
- reject(new Error('Unable to rasterize chart container for PNG export.'));
237
- };
238
- image.src = dataUri;
239
- });
240
- }
241
-
242
- /** Serializes the chart's own SVG surface, styles inlined, and downloads it. */
243
- export function exportChartSvg(chartContainer, filename = 'chart.svg') {
244
- const blob = chartSvgBlob(chartContainer);
245
- download(blob, filename);
246
- return blob;
247
- }
248
-
249
- /**
250
- * Rasterizes the whole chart container -- chart, legend, size key, footnotes, everything the panel
251
- * renders beside the chart -- at two-times scale and downloads it.
252
- */
253
- export async function exportChartPng(chartContainer, filename = 'chart.png', backgroundColour) {
254
- const { svg, width, height } = containerSvgBlob(chartContainer);
255
- const blob = await rasterize(svg, width, height, backgroundColour);
256
- download(blob, filename);
257
- return blob;
258
- }
@@ -1,39 +0,0 @@
1
- import { useTranslation } from 'react-i18next';
2
-
3
- export function formatPercentage(value, locale, options = {}) {
4
- return new Intl.NumberFormat(locale, {
5
- style: 'percent',
6
- maximumFractionDigits: 1,
7
- ...options,
8
- }).format(value);
9
- }
10
-
11
- export function formatCompact(value, locale, options = {}) {
12
- return new Intl.NumberFormat(locale, {
13
- notation: 'compact',
14
- maximumFractionDigits: 1,
15
- ...options,
16
- }).format(value);
17
- }
18
-
19
- export function formatRatio(value, locale, options = {}) {
20
- return new Intl.NumberFormat(locale, {
21
- maximumFractionDigits: 2,
22
- ...options,
23
- }).format(value);
24
- }
25
-
26
- /** Creates locale-aware formatter functions for use in chart axes and tooltips. */
27
- export function createChartFormatters(locale) {
28
- return {
29
- percentage: (value, options) => formatPercentage(value, locale, options),
30
- compact: (value, options) => formatCompact(value, locale, options),
31
- ratio: (value, options) => formatRatio(value, locale, options),
32
- };
33
- }
34
-
35
- /** Resolves formatter locale from the active react-i18next instance. */
36
- export function useChartFormatters() {
37
- const { i18n } = useTranslation();
38
- return createChartFormatters(i18n.language);
39
- }
@@ -1,33 +0,0 @@
1
- import { useTheme } from '@mui/material/styles';
2
-
3
- /**
4
- * Returns neutral chart colours derived only from the active MUI theme.
5
- * Consumers may replace either array with their own domain palette.
6
- */
7
- export function getNeutralChartPalette(theme) {
8
- const palette = theme.palette;
9
- const isDark = palette.mode === 'dark';
10
- const dataSeries = palette.dataSeries?.categorical;
11
-
12
- return {
13
- categorical: Array.isArray(dataSeries) && dataSeries.length > 0
14
- ? [...dataSeries]
15
- : isDark
16
- ? [palette.primary.light, palette.secondary.light, palette.info.light, palette.success.light, palette.warning.light]
17
- : [palette.primary.main, palette.secondary.main, palette.info.main, palette.success.main, palette.warning.main],
18
- sequential: isDark
19
- ? [palette.action.disabled, palette.text.secondary, palette.primary.light, palette.primary.main, palette.primary.dark]
20
- : [palette.action.disabled, palette.divider, palette.text.secondary, palette.primary.light, palette.primary.main],
21
- // THEME-10: an undifferentiated mass (e.g. a scatter cloud with no colour
22
- // dimension encoded) is ink-neutral, not a series hue -- a KPI identity
23
- // colour there implies a meaning the cloud does not carry. `text.secondary`
24
- // reads as neutral ink in both palette modes without competing with an
25
- // actual categorical/sequential encoding drawn on top of it.
26
- neutral: palette.text.secondary,
27
- };
28
- }
29
-
30
- /** Resolves the kit's neutral palette from the nearest MUI ThemeProvider. */
31
- export function useNeutralChartPalette() {
32
- return getNeutralChartPalette(useTheme());
33
- }
@@ -1,7 +0,0 @@
1
- /** Return one January tick for every calendar year represented in dates. */
2
- export function yearTickInterval(dates) {
3
- const years = new Set(dates.map((date) => date.getFullYear()));
4
- return [...years]
5
- .sort((first, second) => first - second)
6
- .map((year) => new Date(year, 0, 1));
7
- }