@phis/ui 0.4.3 → 0.4.5

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 (282) hide show
  1. package/README.md +9 -3
  2. package/cms/plugins.d.ts +1 -0
  3. package/cms/plugins.js +2 -0
  4. package/components/cms/phi-cms-root-layout.js +30 -1
  5. package/components/controls/phi-anchor-nav-control.js +4 -1
  6. package/components/controls/phi-background-control.d.ts +6 -1
  7. package/components/controls/phi-background-control.js +30 -7
  8. package/components/controls/phi-bullet-list-control.d.ts +7 -2
  9. package/components/controls/phi-bullet-list-control.js +4 -3
  10. package/components/controls/phi-button-control.d.ts +13 -1
  11. package/components/controls/phi-button-control.js +21 -3
  12. package/components/controls/phi-color-control.js +4 -2
  13. package/components/controls/phi-drawer-control-adapter.js +3 -2
  14. package/components/controls/phi-dropdown-control.js +2 -2
  15. package/components/controls/phi-inline-text-editor.js +7 -1
  16. package/components/controls/phi-length-control.js +1 -1
  17. package/components/controls/phi-media-asset-tile-control.js +10 -10
  18. package/components/controls/phi-progress-control.d.ts +10 -2
  19. package/components/controls/phi-progress-control.js +6 -2
  20. package/components/controls/phi-ribbon-control.d.ts +16 -4
  21. package/components/controls/phi-ribbon-control.js +14 -8
  22. package/components/controls/phi-ribbon-wrap-control.d.ts +32 -0
  23. package/components/controls/phi-ribbon-wrap-control.js +31 -0
  24. package/components/controls/phi-segmented-control.d.ts +4 -1
  25. package/components/controls/phi-segmented-control.js +13 -2
  26. package/components/controls/phi-select-control.js +5 -2
  27. package/components/controls/phi-series-chart-control.d.ts +48 -0
  28. package/components/controls/phi-series-chart-control.js +82 -0
  29. package/components/controls/phi-surface-control.d.ts +2 -0
  30. package/components/controls/phi-surface-control.js +16 -1
  31. package/components/controls/phi-switch-control.d.ts +4 -1
  32. package/components/controls/phi-switch-control.js +8 -2
  33. package/components/controls/phi-tag-control.d.ts +4 -1
  34. package/components/controls/phi-tag-control.js +11 -3
  35. package/components/controls/phi-text-control.js +57 -3
  36. package/components/controls/phi-tree-control.js +1 -1
  37. package/components/controls/phi-truncated-hover-text.d.ts +15 -0
  38. package/components/controls/phi-truncated-hover-text.js +25 -0
  39. package/components/forms/link-target-form-control.d.ts +1 -1
  40. package/components/forms/link-target-form-control.js +2 -45
  41. package/components/forms/phi-form-widget-frame.js +4 -2
  42. package/components/layouts/clients/phi-three-column-layout-client.js +10 -1
  43. package/components/layouts/phi-layout-view-model.js +10 -1
  44. package/components/navigation/phi-link.js +6 -1
  45. package/components/regions/clients/cms-region-container-client.js +16 -1
  46. package/components/regions/phi-cms-region-container.js +7 -0
  47. package/components/regions/phi-cms-region-shell.d.ts +22 -1
  48. package/components/regions/phi-cms-region-shell.js +131 -23
  49. package/components/root/phi-config-provider.d.ts +13 -0
  50. package/components/root/phi-config-provider.js +12 -1
  51. package/components/root/phi-root-background.d.ts +7 -0
  52. package/components/root/phi-root-background.js +20 -1
  53. package/components/root/phi-root-layout.d.ts +1 -0
  54. package/components/root/phi-root-layout.js +1 -0
  55. package/components/root/phi-root-theme-resolver.js +15 -1
  56. package/components/root/phi-shell-chrome-overlay.d.ts +18 -1
  57. package/components/root/phi-shell-chrome-overlay.js +26 -4
  58. package/components/runtime/runtime-module-context.d.ts +12 -1
  59. package/components/runtime/runtime-module-context.js +6 -1
  60. package/components/shell/phi-antd-icon.d.ts +1 -0
  61. package/components/shell/phi-antd-icon.js +3 -0
  62. package/components/shell/phi-cms-shell.d.ts +7 -1
  63. package/components/shell/phi-cms-shell.js +4 -2
  64. package/components/shell/use-phi-shell-header-bands.d.ts +5 -0
  65. package/components/shell/use-phi-shell-header-bands.js +64 -0
  66. package/components/shell/use-phi-shell-sticky-bottom.d.ts +18 -0
  67. package/components/shell/use-phi-shell-sticky-bottom.js +54 -0
  68. package/components/shell/use-phi-shell-sticky-top.js +61 -16
  69. package/components/surface/phi-surface-tone.d.ts +13 -0
  70. package/components/surface/phi-surface-tone.js +21 -0
  71. package/components/tables/client/phi-table-binding.d.ts +1 -0
  72. package/components/tables/client/phi-table-binding.js +22 -3
  73. package/components/trees/client/phi-tree-binding.d.ts +1 -0
  74. package/components/trees/client/phi-tree-binding.js +11 -2
  75. package/components/widgets/client/bullet-list-entries-editor.js +7 -1
  76. package/components/widgets/client/html-editor.js +1 -1
  77. package/components/widgets/client/shared/phi-collection-provider.js +4 -3
  78. package/components/widgets/client/shared/phi-collection-view-binding.d.ts +1 -0
  79. package/components/widgets/client/shared/phi-collection-view-binding.js +16 -2
  80. package/components/widgets/client/shared/phi-command-buttons.js +6 -2
  81. package/components/widgets/client/shared/use-page-reference-options.d.ts +17 -0
  82. package/components/widgets/client/shared/use-page-reference-options.js +57 -0
  83. package/components/widgets/config/background.d.ts +52 -1
  84. package/components/widgets/config/background.js +85 -4
  85. package/components/widgets/config/button-variant.d.ts +22 -4
  86. package/components/widgets/config/button-variant.js +24 -5
  87. package/components/widgets/config/common-action-field.d.ts +1 -1
  88. package/components/widgets/config/parser-primitives.js +4 -2
  89. package/components/widgets/config/theme-gradient.d.ts +11 -0
  90. package/components/widgets/config/theme-gradient.js +12 -0
  91. package/components/widgets/label-sets/background.js +4 -0
  92. package/components/widgets/label-sets/geometry.js +2 -0
  93. package/components/widgets/label-sets/inspector.js +4 -0
  94. package/components/widgets/label-types/background.d.ts +2 -0
  95. package/components/widgets/label-types/background.js +2 -0
  96. package/components/widgets/label-types/common-controls.js +2 -2
  97. package/components/widgets/label-types/geometry.d.ts +1 -0
  98. package/components/widgets/label-types/geometry.js +1 -0
  99. package/components/widgets/label-types/inspector.d.ts +4 -0
  100. package/components/widgets/label-types/inspector.js +2 -0
  101. package/components/widgets/shared/bullet-list-vocabulary.d.ts +10 -0
  102. package/components/widgets/shared/bullet-list-vocabulary.js +5 -2
  103. package/components/widgets/shared/card-body-client.d.ts +16 -3
  104. package/components/widgets/shared/card-body-client.js +79 -8
  105. package/components/widgets/shared/card-vocabulary.d.ts +12 -2
  106. package/components/widgets/shared/card-vocabulary.js +7 -0
  107. package/components/widgets/shared/collection-source-failure.d.ts +26 -0
  108. package/components/widgets/shared/collection-source-failure.js +42 -0
  109. package/components/widgets/shared/markdown-body-client.js +39 -10
  110. package/components/widgets/shared/markdown-render.js +16 -3
  111. package/components/widgets/shared/widget-failure-client.d.ts +10 -0
  112. package/components/widgets/shared/widget-failure-client.js +20 -0
  113. package/components/widgets/shared/widget-failure.d.ts +31 -0
  114. package/components/widgets/shared/widget-failure.js +20 -0
  115. package/components/widgets/shared/widget-failure.server.d.ts +9 -0
  116. package/components/widgets/shared/widget-failure.server.js +12 -0
  117. package/gateway/dashboard-card-memo.d.ts +3 -0
  118. package/gateway/dashboard-card-memo.js +25 -0
  119. package/helpers/cms-container-chrome.js +6 -1
  120. package/helpers/cms-region-keys.d.ts +1 -1
  121. package/helpers/layout-style.d.ts +8 -4
  122. package/helpers/layout-style.js +3 -2
  123. package/helpers/locale.d.ts +8 -0
  124. package/helpers/locale.js +18 -0
  125. package/helpers/mode-paint.d.ts +4 -0
  126. package/helpers/mode-paint.js +47 -0
  127. package/helpers/shell-region-style.js +2 -1
  128. package/helpers/surface-style.d.ts +12 -1
  129. package/helpers/surface-style.js +60 -12
  130. package/module-dashboard-cards.d.ts +2 -1
  131. package/module-dashboard-cards.js +2 -1
  132. package/module-records.d.ts +7 -0
  133. package/module-records.js +6 -0
  134. package/package.json +1 -1
  135. package/plugins/runtime-modules/area-definitions.d.ts +0 -42
  136. package/plugins/runtime-modules/area-definitions.js +3 -8
  137. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +21 -2
  138. package/plugins/runtime-modules/builder/clients/inspector-surface-labels.js +1 -0
  139. package/plugins/runtime-modules/builder/clients/layout-scaffold-overlays.js +10 -5
  140. package/plugins/runtime-modules/builder/clients/region-inspector.js +47 -2
  141. package/plugins/runtime-modules/builder/clients/runtime-module-authoring-boundary.js +1 -1
  142. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +7 -4
  143. package/plugins/runtime-modules/builder/controller/page-controller.js +7 -0
  144. package/plugins/runtime-modules/builder/edit-scaffold-drawer.js +3 -2
  145. package/plugins/runtime-modules/builder/persistence.d.ts +3 -0
  146. package/plugins/runtime-modules/builder/persistence.js +9 -1
  147. package/plugins/runtime-modules/builder/render-root-node-scaffold.js +25 -15
  148. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +4 -0
  149. package/plugins/runtime-modules/builder/widgets/structure-region/built-in.js +15 -4
  150. package/plugins/runtime-modules/client-authoring-module.d.ts +8 -1
  151. package/plugins/runtime-modules/client-authoring-module.js +13 -3
  152. package/plugins/runtime-modules/core/content-entries/record-source.server.d.ts +3 -1
  153. package/plugins/runtime-modules/core/content-entries/record-source.server.js +7 -4
  154. package/plugins/runtime-modules/core/widgets/brand/client.d.ts +12 -3
  155. package/plugins/runtime-modules/core/widgets/brand/client.js +3 -11
  156. package/plugins/runtime-modules/core/widgets/brand/home.d.ts +15 -0
  157. package/plugins/runtime-modules/core/widgets/brand/home.js +18 -0
  158. package/plugins/runtime-modules/core/widgets/brand/plugin.js +3 -2
  159. package/plugins/runtime-modules/core/widgets/brand/server.d.ts +2 -2
  160. package/plugins/runtime-modules/core/widgets/brand/server.js +2 -2
  161. package/plugins/runtime-modules/core/widgets/button/client.js +2 -2
  162. package/plugins/runtime-modules/core/widgets/button/config.d.ts +40 -4
  163. package/plugins/runtime-modules/core/widgets/button/config.js +12 -0
  164. package/plugins/runtime-modules/core/widgets/card/config.d.ts +100 -1
  165. package/plugins/runtime-modules/core/widgets/card/config.js +57 -3
  166. package/plugins/runtime-modules/core/widgets/card/editor.js +21 -4
  167. package/plugins/runtime-modules/core/widgets/card/server.js +5 -0
  168. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +4 -1
  169. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +10 -3
  170. package/plugins/runtime-modules/core/widgets/collection-view/authoring.js +1 -1
  171. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +3 -0
  172. package/plugins/runtime-modules/core/widgets/collection-view/client.js +47 -11
  173. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.d.ts +4 -1
  174. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +2 -2
  175. package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +3 -2
  176. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +6 -1
  177. package/plugins/runtime-modules/core/widgets/collection-view/server.js +21 -3
  178. package/plugins/runtime-modules/core/widgets/description/client.js +3 -3
  179. package/plugins/runtime-modules/core/widgets/description/config.d.ts +1 -0
  180. package/plugins/runtime-modules/core/widgets/description/editor.js +3 -2
  181. package/plugins/runtime-modules/core/widgets/description/server.js +3 -2
  182. package/plugins/runtime-modules/core/widgets/entry-detail/plugin.js +1 -1
  183. package/plugins/runtime-modules/core/widgets/entry-detail/server.d.ts +3 -1
  184. package/plugins/runtime-modules/core/widgets/entry-detail/server.js +5 -2
  185. package/plugins/runtime-modules/core/widgets/entry-header/plugin.js +1 -1
  186. package/plugins/runtime-modules/core/widgets/entry-header/server.d.ts +3 -1
  187. package/plugins/runtime-modules/core/widgets/entry-header/server.js +5 -2
  188. package/plugins/runtime-modules/core/widgets/entry-list/config.d.ts +1 -0
  189. package/plugins/runtime-modules/core/widgets/entry-list/plugin.js +1 -1
  190. package/plugins/runtime-modules/core/widgets/entry-list/server.d.ts +6 -3
  191. package/plugins/runtime-modules/core/widgets/entry-list/server.js +13 -6
  192. package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +1 -0
  193. package/plugins/runtime-modules/core/widgets/gallery/plugin.js +1 -1
  194. package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +5 -3
  195. package/plugins/runtime-modules/core/widgets/gallery/server.js +8 -6
  196. package/plugins/runtime-modules/core/widgets/header-navigation/client.js +2 -2
  197. package/plugins/runtime-modules/core/widgets/html/client.js +1 -1
  198. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +320 -2
  199. package/plugins/runtime-modules/core/widgets/markdown/config.js +18 -4
  200. package/plugins/runtime-modules/core/widgets/markdown/editor.js +9 -1
  201. package/plugins/runtime-modules/core/widgets/markdown-toc/client.js +6 -1
  202. package/plugins/runtime-modules/core/widgets/markdown-toc/config.d.ts +14 -0
  203. package/plugins/runtime-modules/core/widgets/markdown-toc/config.js +14 -2
  204. package/plugins/runtime-modules/core/widgets/quick-links/authoring.js +7 -2
  205. package/plugins/runtime-modules/core/widgets/quick-links/client.js +2 -2
  206. package/plugins/runtime-modules/core/widgets/quick-links/items.d.ts +0 -2
  207. package/plugins/runtime-modules/core/widgets/quick-links/items.js +0 -15
  208. package/plugins/runtime-modules/core/widgets/record/client.d.ts +4 -1
  209. package/plugins/runtime-modules/core/widgets/record/client.js +8 -3
  210. package/plugins/runtime-modules/core/widgets/record/plugin.js +3 -2
  211. package/plugins/runtime-modules/core/widgets/record/server.d.ts +3 -1
  212. package/plugins/runtime-modules/core/widgets/record/server.js +2 -2
  213. package/plugins/runtime-modules/core/widgets/result/config.d.ts +1 -0
  214. package/plugins/runtime-modules/core/widgets/segmented/client.js +1 -1
  215. package/plugins/runtime-modules/core/widgets/segmented/config.d.ts +21 -1
  216. package/plugins/runtime-modules/core/widgets/segmented/config.js +11 -1
  217. package/plugins/runtime-modules/core/widgets/sidebar-navigation/authoring.js +1 -1
  218. package/plugins/runtime-modules/core/widgets/sidebar-navigation/client.js +1 -1
  219. package/plugins/runtime-modules/core/widgets/simple-text/client.js +8 -3
  220. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +1 -0
  221. package/plugins/runtime-modules/core/widgets/simple-text/editor.js +2 -2
  222. package/plugins/runtime-modules/core/widgets/switch/client.js +1 -1
  223. package/plugins/runtime-modules/core/widgets/switch/config.d.ts +19 -0
  224. package/plugins/runtime-modules/core/widgets/switch/config.js +11 -0
  225. package/plugins/runtime-modules/core/widgets/table/authoring.js +1 -1
  226. package/plugins/runtime-modules/core/widgets/table/client.d.ts +4 -1
  227. package/plugins/runtime-modules/core/widgets/table/client.js +16 -3
  228. package/plugins/runtime-modules/core/widgets/table/config.d.ts +3 -0
  229. package/plugins/runtime-modules/core/widgets/table/plugin.js +3 -2
  230. package/plugins/runtime-modules/core/widgets/table/server.d.ts +3 -1
  231. package/plugins/runtime-modules/core/widgets/table/server.js +2 -2
  232. package/plugins/runtime-modules/core/widgets/table/static-resource-editor.js +2 -1
  233. package/plugins/runtime-modules/core/widgets/timeline/authoring.js +1 -1
  234. package/plugins/runtime-modules/core/widgets/timeline/client.d.ts +1 -3
  235. package/plugins/runtime-modules/core/widgets/timeline/client.js +14 -4
  236. package/plugins/runtime-modules/core/widgets/tree/authoring.js +1 -1
  237. package/plugins/runtime-modules/core/widgets/tree/client.d.ts +4 -1
  238. package/plugins/runtime-modules/core/widgets/tree/client.js +13 -2
  239. package/plugins/runtime-modules/core/widgets/tree/plugin.js +3 -2
  240. package/plugins/runtime-modules/core/widgets/tree/server.d.ts +3 -1
  241. package/plugins/runtime-modules/core/widgets/tree/server.js +2 -2
  242. package/plugins/runtime-modules/dashboard/card-rows.d.ts +3 -1
  243. package/plugins/runtime-modules/dashboard/card-rows.js +30 -2
  244. package/plugins/runtime-modules/dashboard/clients/dashboard-card-view.js +29 -7
  245. package/plugins/runtime-modules/dashboard/trees/phi-default-builder-dashboard-page-tree.js +5 -40
  246. package/plugins/runtime-modules/theme/presets.d.ts +9 -1
  247. package/plugins/runtime-modules/theme/tour.d.ts +9 -1
  248. package/plugins/runtime-modules/theme/tour.js +10 -1
  249. package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +157 -22
  250. package/plugins/runtime-modules/theme/widgets/brand-controls/config.js +5 -9
  251. package/runtime-data-provider-client.d.ts +2 -0
  252. package/runtime-data-provider-client.js +7 -0
  253. package/server-helpers/cms-link-targets.js +6 -0
  254. package/styles/controls.css +74 -7
  255. package/styles/gradients.css +101 -0
  256. package/styles/layout.css +45 -2
  257. package/styles/root.css +18 -0
  258. package/styles/shell.css +137 -0
  259. package/theme/phi-antd-token-resolver.js +20 -1
  260. package/theme/phi-button-shadow.d.ts +6 -0
  261. package/theme/phi-theme-gradients.d.ts +96 -0
  262. package/theme/phi-theme-gradients.js +245 -0
  263. package/theme/phi-theme-presets.d.ts +3 -0
  264. package/theme/phi-theme-presets.js +3 -0
  265. package/theme/phi-theme-tokens.d.ts +6 -2
  266. package/theme/phi-theme-tokens.js +15 -0
  267. package/theme/phi-theme.d.ts +5 -0
  268. package/theme/phi-theme.js +21 -0
  269. package/theme/phi-tokens.d.ts +16 -15
  270. package/theme/phi-tokens.js +16 -15
  271. package/types/cms-plugins.d.ts +2 -0
  272. package/types/cms-presets.d.ts +7 -0
  273. package/types/core-widget-placements.d.ts +3 -0
  274. package/types/dashboard-cards.d.ts +39 -4
  275. package/types/dashboard-cards.js +6 -0
  276. package/types/layout-style.d.ts +9 -8
  277. package/types/layout-style.js +9 -8
  278. package/types/site-theme.d.ts +10 -2
  279. package/types/surface.d.ts +4 -0
  280. package/types/surface.js +4 -0
  281. package/types.d.ts +1 -1
  282. package/types.js +1 -1
package/styles/layout.css CHANGED
@@ -493,8 +493,13 @@
493
493
  * COLOUR the page already computed from them, not the variable -- so the box states its text colour again
494
494
  * and its content reads it from the variables in force there. When the content is already in that mode,
495
495
  * the class has no variables of its own and this resolves to what the page has anyway.
496
+ *
497
+ * The box only, not an Ant Design component inside it: the tone scope keys its variables to the same
498
+ * class, and Ant Design puts that key on every component it draws there. Stated on those too, the colour
499
+ * stopped inheritance at each of them -- a Quick Link's words kept the text colour while the link turned
500
+ * to its hover colour around them.
496
501
  */
497
- :where(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse) {
502
+ :where(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse):where(:not([class^="ant-"], [class*=" ant-"])) {
498
503
  color: var(--ant-color-text);
499
504
  }
500
505
 
@@ -576,6 +581,43 @@
576
581
  transition: scale 300ms ease;
577
582
  }
578
583
 
584
+ /*
585
+ * A card with a ribbon stands in the ribbon's wrapper (`PhiRibbonWrapControl`): a column that takes the
586
+ * slot's size and hands it to the card. A card that lifts carries its ribbon with it -- the ribbon is the
587
+ * card's sibling, so the wrapper moves it when the card moves.
588
+ */
589
+ :where(.phi-card-ribbon) {
590
+ display: flex;
591
+ flex-direction: column;
592
+ min-width: 0;
593
+ }
594
+
595
+ :where(.phi-card-ribbon) > :where(.phi-card) {
596
+ flex: 1 1 auto;
597
+ }
598
+
599
+ /*
600
+ * A little lower than Ant Design sets it, so the ribbon stands centred on the eyebrow's line. Outside
601
+ * `:where`: Ant Design's own `.ant-ribbon` states `top`, and this has to outrank it.
602
+ */
603
+ .phi-card-ribbon > .ant-ribbon {
604
+ top: calc(var(--ant-margin-xs) + 3px);
605
+ }
606
+
607
+ :where(.phi-card-ribbon--lift) > :where(.ant-ribbon) {
608
+ transition: translate 200ms ease;
609
+ }
610
+
611
+ @media (hover: hover) {
612
+ :where(.phi-card-ribbon--lift):has(> .phi-card:hover) > :where(.ant-ribbon) {
613
+ translate: 0 -4px;
614
+ }
615
+ }
616
+
617
+ :where(.phi-card-ribbon--lift):has(> .phi-card:focus-within) > :where(.ant-ribbon) {
618
+ translate: 0 -4px;
619
+ }
620
+
579
621
  @media (hover: hover) {
580
622
  :where(.phi-card--hover-lift):hover {
581
623
  translate: 0 -4px;
@@ -629,7 +671,8 @@
629
671
  transition: none;
630
672
  }
631
673
 
632
- .phi-card--hover-lift:is(:hover, :focus-within) {
674
+ .phi-card--hover-lift:is(:hover, :focus-within),
675
+ .phi-card-ribbon--lift > .ant-ribbon {
633
676
  translate: none;
634
677
  }
635
678
 
package/styles/root.css CHANGED
@@ -237,3 +237,21 @@ samp {
237
237
  animation-delay: 0s !important;
238
238
  }
239
239
  }
240
+
241
+ /* The gates a paint per mode reads (`helpers/mode-paint.ts`): the open one is empty, the closed one is the
242
+ guaranteed-invalid value, so the closed mode's value is the one a `var()` falls back to. Light outside
243
+ the Root Layout as well -- a Modal portalled to <body> still reads one value. */
244
+ :root {
245
+ --phi-mode-light-gate: ;
246
+ --phi-mode-dark-gate: initial;
247
+ }
248
+
249
+ :where([data-phi-theme-mode="light"]) {
250
+ --phi-mode-light-gate: ;
251
+ --phi-mode-dark-gate: initial;
252
+ }
253
+
254
+ :where([data-phi-theme-mode="dark"]) {
255
+ --phi-mode-light-gate: initial;
256
+ --phi-mode-dark-gate: ;
257
+ }
package/styles/shell.css CHANGED
@@ -294,6 +294,33 @@
294
294
  --phi-shell-chrome-filter: var(--phi-shell-chrome-filter-dark, none);
295
295
  }
296
296
 
297
+ /* The Overlay in a tone's mode (LAYOUTING.md "Surface tone"), for a box whose Background is the Theme's
298
+ (`PHI_BACKGROUND_THEME_STYLE`). The tone's class publishes the Overlay of the mode it asks for, so the
299
+ box -- and an untoned box inside it -- reads that mode's variables; `inverse` is read against the page's
300
+ mode, as the tone scope reads it, and turns with the mode switch. Inside the Root Layout only: a Modal
301
+ or Drawer portalled to `<body>` has no Overlay published, and its box falls back to the container
302
+ ground of the tone's mode. The Root Layout's own values above stay what the Chrome Regions and panes
303
+ read; those are computed on the Root Layout and inherited, so a tone below cannot touch them. */
304
+ :where([data-phi-root-layout="true"]) :where(.phi-tone-light),
305
+ :where([data-phi-root-layout="true"][data-phi-theme-mode="dark"]) :where(.phi-tone-inverse) {
306
+ --phi-shell-chrome-image: var(--phi-shell-chrome-image-light, none);
307
+ --phi-shell-chrome-size: var(--phi-shell-chrome-size-light, auto);
308
+ --phi-shell-chrome-position: var(--phi-shell-chrome-position-light, 0 0);
309
+ --phi-shell-chrome-repeat: var(--phi-shell-chrome-repeat-light, repeat);
310
+ --phi-shell-chrome-color: var(--phi-shell-chrome-color-light, transparent);
311
+ --phi-shell-chrome-filter: var(--phi-shell-chrome-filter-light, none);
312
+ }
313
+
314
+ :where([data-phi-root-layout="true"]) :where(.phi-tone-dark),
315
+ :where([data-phi-root-layout="true"]:not([data-phi-theme-mode="dark"])) :where(.phi-tone-inverse) {
316
+ --phi-shell-chrome-image: var(--phi-shell-chrome-image-dark, none);
317
+ --phi-shell-chrome-size: var(--phi-shell-chrome-size-dark, auto);
318
+ --phi-shell-chrome-position: var(--phi-shell-chrome-position-dark, 0 0);
319
+ --phi-shell-chrome-repeat: var(--phi-shell-chrome-repeat-dark, repeat);
320
+ --phi-shell-chrome-color: var(--phi-shell-chrome-color-dark, transparent);
321
+ --phi-shell-chrome-filter: var(--phi-shell-chrome-filter-dark, none);
322
+ }
323
+
297
324
  /* A Chrome Region carries the marker only while it authored no ground of its own, so there is nothing
298
325
  left to fall back through here: the shared colour is the ground. It needs no light and dark pair
299
326
  either, because the pair above has already resolved the mode. This rule follows the two that set the
@@ -332,6 +359,17 @@
332
359
  z-index: 50;
333
360
  }
334
361
 
362
+ /*
363
+ * The Header's panes stand above every Sider's. Both are grid items at the same level, and a Sider's
364
+ * pane comes later in the DOM, so at an equal `z-index` it painted over the Header's where the two meet:
365
+ * the Sider's ground hid the Header's and cut its Shadow at the Sider's edge. Still below every Chrome
366
+ * Region (100 and up).
367
+ */
368
+ .phi-shell-chrome-pane--header,
369
+ .phi-shell-chrome-pane--header-bottom {
370
+ z-index: 51;
371
+ }
372
+
335
373
  /*
336
374
  * What the pane paints is set inline by the Shell, not here.
337
375
  *
@@ -430,6 +468,41 @@
430
468
  --phi-region-chrome-attachment: scroll;
431
469
  }
432
470
 
471
+ /*
472
+ * A toned band takes no paint from its family's pane (LAYOUTING.md "Surface tone").
473
+ *
474
+ * A toned Chrome Region paints its own ground -- the tone's container ground, a stated Background, or
475
+ * the Overlay of its tone's mode -- and never carries the marker. The pane behind it keeps the page's
476
+ * mode, so where that ground lets anything through, the page-mode glass showed under the tone's. The
477
+ * pane cannot be cut around one band without knowing its height, so it stops painting for the whole
478
+ * family and the family's marker bands paint the Overlay themselves, as they do without panes. Its
479
+ * geometry and Shadow stay: the frame's edge is where it was, and the Header still stands over the
480
+ * Sider. The pane's paint is inline and reads these properties on the pane itself, so they are set
481
+ * there. Untoned families match nothing here.
482
+ */
483
+ .shell-sider-full:has(> :is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"], [data-phi-region-key="header_bottom"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--header,
484
+ .shell-sider-embedded:has(> :is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--header,
485
+ .shell-sider-embedded:has(> [data-phi-region-key="header_bottom"]:is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--header-bottom,
486
+ [data-phi-shell-chrome-panes="true"]:has(> [data-phi-region-key="sider_left"]:is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--sider,
487
+ [data-phi-shell-chrome-panes="true"]:has(> [data-phi-region-key="sider_right"]:is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--sider-right,
488
+ [data-phi-shell-chrome-panes="true"]:has(> :is([data-phi-region-key="footer_top"], [data-phi-region-key="footer_main"], [data-phi-region-key="footer_bottom"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse)) > .phi-shell-chrome-pane--footer {
489
+ --phi-shell-chrome-image: none;
490
+ --phi-shell-chrome-color: transparent;
491
+ --phi-shell-chrome-filter: none;
492
+ }
493
+
494
+ .shell-sider-full:has(> :is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"], [data-phi-region-key="header_bottom"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse))
495
+ > .phi-cms-region-shell[data-phi-shell-chrome="true"]:is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"], [data-phi-region-key="header_bottom"]),
496
+ .shell-sider-embedded:has(> :is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse))
497
+ > .phi-cms-region-shell[data-phi-shell-chrome="true"]:is([data-phi-region-key="header_top"], [data-phi-region-key="header_main"]),
498
+ [data-phi-shell-chrome-panes="true"]:has(> :is([data-phi-region-key="footer_top"], [data-phi-region-key="footer_main"], [data-phi-region-key="footer_bottom"]):is(.phi-tone-light, .phi-tone-dark, .phi-tone-inverse))
499
+ > .phi-cms-region-shell[data-phi-shell-chrome="true"]:is([data-phi-region-key="footer_top"], [data-phi-region-key="footer_main"], [data-phi-region-key="footer_bottom"]) {
500
+ --phi-region-chrome-image: var(--phi-shell-chrome-image, none);
501
+ --phi-region-chrome-color: var(--phi-shell-chrome-color, transparent);
502
+ --phi-region-chrome-filter: var(--phi-shell-chrome-filter, none);
503
+ --phi-region-chrome-attachment: fixed;
504
+ }
505
+
433
506
  /* ---------------------------------------------------------------------------------------------
434
507
  Revealing `header_top` (SHELL.md "Region visibility per Page")
435
508
 
@@ -483,3 +556,67 @@
483
556
  transition: none;
484
557
  }
485
558
  }
559
+
560
+ /* -------------------------------------------------------------------------------------------------
561
+ Hero at the top.
562
+
563
+ A Page with a Hero starts it at the top of the window, behind the Header bands; a Page without one
564
+ keeps its content below them. No setting decides it: the Hero is the stage behind the Header, the
565
+ content the surface under it.
566
+
567
+ The Header rows hold no room here -- fixed at zero, so the Hero spanning them cannot grow them -- and
568
+ the grid depends on no measurement. Each band stands where the bands above it end, the glass pane
569
+ covers their sum, and the Hero's root Layout keeps its content below them by the same sum on top of
570
+ its own inset. Those values come from the Area's configs on the first paint and from the browser after
571
+ (`use-phi-shell-header-bands.ts`); a late one moves a band or the Hero's words, never the page.
572
+
573
+ Not where a Sider is embedded beside `header_bottom`: there the Sider would start behind the Header too.
574
+ The band offsets are important because a Region's root states `margin: 0` inline.
575
+ --------------------------------------------------------------------------------------------- */
576
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) {
577
+ --phi-shell-header-height: calc(var(--phi-shell-band-top, 0px) + var(--phi-shell-band-main, 0px) + var(--phi-shell-band-bottom, 0px));
578
+ grid-template-rows: 0px 0px 0px auto minmax(0, 1fr) auto auto auto;
579
+ }
580
+
581
+ /* Sized by their content, not their zero row: a band without a stated height whose content fills it by
582
+ percentage (`height: 100%`) would otherwise resolve against the row and fold to nothing. A stated height
583
+ is inline and wins. */
584
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > [data-phi-region-key^="header_"] {
585
+ align-self: start;
586
+ height: max-content;
587
+ }
588
+
589
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > [data-phi-region-key="header_main"] {
590
+ margin-block-start: var(--phi-shell-band-top, 0px) !important;
591
+ }
592
+
593
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > [data-phi-region-key="header_bottom"] {
594
+ margin-block-start: calc(var(--phi-shell-band-top, 0px) + var(--phi-shell-band-main, 0px)) !important;
595
+ }
596
+
597
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > [data-phi-region-key="hero"] {
598
+ grid-row-start: header_top-start;
599
+ }
600
+
601
+ /* One pane over all three bands, its height their sum; the second Header pane has nothing left to cover. */
602
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > .phi-shell-chrome-pane--header {
603
+ grid-row: header_top-start / header_top-end;
604
+ align-self: start;
605
+ height: var(--phi-shell-header-height);
606
+ }
607
+
608
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]):has(> [data-phi-region-key="hero"]) > .phi-shell-chrome-pane--header-bottom {
609
+ display: none;
610
+ }
611
+
612
+ /* Important because the Layout's padding is inline; the rule only adds to it, read back from `--phi-layout-padding-top`. */
613
+ [data-phi-shell-layout]:not([data-phi-shell-variant="embedded-sider"]) > [data-phi-region-key="hero"] > .phi-cms-region-shell__content > .phi-slot-child > [data-layout-kind] {
614
+ padding-block-start: calc(var(--phi-shell-header-height, 0px) + var(--phi-layout-padding-top, 0px)) !important;
615
+ }
616
+
617
+ /* Content reaching into the Hero (SHELL.md): the Page's `content` set up by its `heroOverlap`, so its first
618
+ boxes stand on the Hero's picture. It follows the Hero in the DOM at the same z-index, so it paints over
619
+ it. Important because a Region's root states `margin: 0` inline. Nothing happens without a Hero. */
620
+ [data-phi-shell-layout]:has(> [data-phi-region-key="hero"]) > main [data-phi-region-key="content"] {
621
+ margin-block-start: calc(-1 * var(--phi-region-hero-overlap, 0px)) !important;
622
+ }
@@ -1,4 +1,5 @@
1
1
  import darkAlgorithm from "antd/es/theme/themes/dark";
2
+ import { generateColorPalettes as generateDarkColorPalettes } from "antd/es/theme/themes/dark/colors";
2
3
  import defaultAlgorithm from "antd/es/theme/themes/default";
3
4
  import seedToken from "antd/es/theme/themes/seed";
4
5
  import formatToken from "antd/es/theme/util/alias";
@@ -34,13 +35,31 @@ export function createPhiAntdThemeCssVarKey(scope, identity) {
34
35
  .replace(/^-+|-+$/g, "") || "theme";
35
36
  return `phi-${normalizedScope}-${hashPhiAntdThemeIdentity(identity)}`;
36
37
  }
38
+ /*
39
+ * A link and an info colour pointed at turn lighter in the dark mode, as a primary button does.
40
+ *
41
+ * Ant Design takes both hovers from step 4 of the colour's palette in either mode. In the light palette
42
+ * that step is a lighter tint; the dark algorithm reorders its palette so the low steps fade into the dark
43
+ * ground for borders and fills, and step 4 there is the border's -- darker than the colour itself, so a
44
+ * link went dim on a dark ground when pointed at (#3867b5 to #274069 on #08153a). The primary hover takes
45
+ * step 5, which in the dark palette is the lighter one; these take it too. A hover a Theme states itself
46
+ * still wins: `formatToken` lays the stated tokens over this.
47
+ */
48
+ function withPhiDarkHoverSteps(seed, derived) {
49
+ const linkBase = seed.colorLink || seed.colorInfo;
50
+ return {
51
+ ...derived,
52
+ ...(linkBase ? { colorLinkHover: generateDarkColorPalettes(linkBase)[5] } : {}),
53
+ ...(seed.colorInfo ? { colorInfoHover: generateDarkColorPalettes(seed.colorInfo)[5] } : {}),
54
+ };
55
+ }
37
56
  export function resolvePhiAntdAliasTokens(mode, token) {
38
57
  const mergedSeedToken = {
39
58
  ...seedToken,
40
59
  ...token,
41
60
  };
42
61
  const derivativeToken = mode === "dark"
43
- ? darkAlgorithm(mergedSeedToken)
62
+ ? withPhiDarkHoverSteps(mergedSeedToken, darkAlgorithm(mergedSeedToken))
44
63
  : defaultAlgorithm(mergedSeedToken);
45
64
  return formatToken({
46
65
  ...derivativeToken,
@@ -1,4 +1,5 @@
1
1
  import type { PhiThemeMode } from "./phi-theme-presets";
2
+ import type { PhiThemeGradientKey } from "./phi-theme-gradients";
2
3
  /**
3
4
  * The shadow under each kind of Button, as a step rather than as CSS.
4
5
  *
@@ -21,6 +22,11 @@ export declare const PHI_BUTTON_SHADOW_STEPS: readonly ["none", "soft", "strong"
21
22
  export type PhiButtonShadowStep = (typeof PHI_BUTTON_SHADOW_STEPS)[number];
22
23
  export type PhiThemeButtons = {
23
24
  shadow?: Partial<Record<PhiButtonShadowKind, PhiButtonShadowStep>> | null;
25
+ /**
26
+ * The Theme gradient every primary Button is filled with (theme/phi-theme-gradients.ts); absent, they
27
+ * keep their one colour. A Button can still choose a gradient of its own with the `gradient` variant.
28
+ */
29
+ primaryGradient?: PhiThemeGradientKey | null;
24
30
  };
25
31
  export declare function isPhiButtonShadowStep(value: unknown): value is PhiButtonShadowStep;
26
32
  /**
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The Theme's gradients: three named slots, like the ten custom colours, that a control can take its
3
+ * ground from instead of from one colour.
4
+ *
5
+ * A gradient belongs to a mode for the reason a mode seed does: the ground that reads as a brand on a
6
+ * light page -- a deep burgundy run -- is a hole in a dark one, where the same brand reads as gold. So a
7
+ * palette states each slot per mode (`modes[mode].gradients`), and a slot it leaves out is derived from
8
+ * the mode's own colours, which is what lets every Theme offer all three without anybody drawing them.
9
+ *
10
+ * They reach the page as Ant Design tokens -- `phiGradient1` and its `phiGradient1Text` -- and Ant Design
11
+ * writes every token as a custom property under the Theme's class (`--ant-phi-gradient-1`). That is the
12
+ * whole transport: the root writes both modes, a Surface tone writes its own mode on its box, and the
13
+ * Theme workspace's preview writes the draft's, so a control that reads the property is in the right mode
14
+ * wherever it stands without asking which one that is.
15
+ */
16
+ export declare const PHI_THEME_GRADIENT_KEYS: readonly ["gradient1", "gradient2", "gradient3"];
17
+ export type PhiThemeGradientKey = (typeof PHI_THEME_GRADIENT_KEYS)[number];
18
+ export type PhiThemeGradientDirection = "to right" | "to left" | "to bottom" | "to top" | `${number}deg`;
19
+ /** The same shape a Background's gradient Base has, so the one editor draws and reads both. */
20
+ export type PhiThemeGradientStop = {
21
+ color: string;
22
+ percent: number;
23
+ };
24
+ export type PhiThemeGradient = {
25
+ direction: PhiThemeGradientDirection;
26
+ stops: PhiThemeGradientStop[];
27
+ /**
28
+ * Which of the Theme's two text colours stands on it (`PhiThemeGradientInks`); absent, whichever reads
29
+ * better where it reads worst. No colour of its own: words on a run read like the Theme's other words,
30
+ * and follow when the Theme's text colours change.
31
+ */
32
+ text?: PhiThemeGradientTextTone;
33
+ };
34
+ export declare const PHI_THEME_GRADIENT_TEXT_TONES: readonly ["light", "dark"];
35
+ export type PhiThemeGradientTextTone = (typeof PHI_THEME_GRADIENT_TEXT_TONES)[number];
36
+ /**
37
+ * The Theme's two text colours for words on a run, in one mode: `light` is the text it sets on a solid
38
+ * coloured ground (`colorTextLightSolid`), `dark` the darker of its text and its ground -- its text in
39
+ * light mode, its ground in dark mode, where the text is the light one.
40
+ */
41
+ export type PhiThemeGradientInks = Record<PhiThemeGradientTextTone, string>;
42
+ /**
43
+ * A slot as a palette states it: a whole run, or only which text colour stands on the run the slot
44
+ * derives -- so choosing the words does not freeze the palette's colours into the slot.
45
+ */
46
+ export type PhiThemeGradientSlot = PhiThemeGradient | {
47
+ text: PhiThemeGradientTextTone;
48
+ };
49
+ export type PhiThemeGradientPalette = Partial<Record<PhiThemeGradientKey, PhiThemeGradientSlot>>;
50
+ /** A slot as a value a control or a widget config may store; anything else reads as no gradient. */
51
+ export declare function readPhiThemeGradientKey(value: unknown): PhiThemeGradientKey | undefined;
52
+ /** The text tone a stored slot states, with or without a run of its own. */
53
+ export declare function readPhiThemeGradientTextTone(value: unknown): PhiThemeGradientTextTone | undefined;
54
+ /** A stored gradient, read strictly: two stops at least, each a colour and a place on the run. */
55
+ export declare function readPhiThemeGradient(value: unknown): PhiThemeGradient | null;
56
+ export declare const PHI_THEME_GRADIENT_CSS_VARS: Record<PhiThemeGradientKey, {
57
+ paint: string;
58
+ text: string;
59
+ }>;
60
+ /** A run a little lighter under the pointer, a little darker while it is pressed. */
61
+ export declare const PHI_GRADIENT_HOVER_FILTER = "brightness(1.18) saturate(1.15)";
62
+ /** The two text colours of one mode's resolved tokens (`PhiThemeGradientInks`). */
63
+ export declare function resolvePhiThemeGradientInks(token: Record<string, unknown>): PhiThemeGradientInks;
64
+ /** Where a text colour reads worst on a gradient: the ratio, the stop, and whether under the pointer. */
65
+ export type PhiThemeGradientContrast = {
66
+ ratio: number;
67
+ stopIndex: number;
68
+ color: string;
69
+ hover: boolean;
70
+ };
71
+ /**
72
+ * Where a text colour reads worst on the run. Text crosses the whole run, so the stop it reads worst on
73
+ * decides -- at rest and under the pointer, where the hover filter lightens run and words alike. A
74
+ * translucent text colour is laid on each stop first. `null` where a colour is not one this can read
75
+ * (`hsl()`, a variable): the Theme workspace then says nothing rather than something wrong.
76
+ */
77
+ export declare function resolvePhiThemeGradientContrast(gradient: PhiThemeGradient, text: string): PhiThemeGradientContrast | null;
78
+ /** The weakest contrast a text colour has anywhere on the run, at rest or under the pointer. */
79
+ export declare function resolvePhiThemeGradientWorstContrast(gradient: PhiThemeGradient, text: string): number | null;
80
+ /** Which of the two text colours reads better where the run reads worst for it. */
81
+ export declare function resolvePhiThemeGradientAutoTextTone(gradient: PhiThemeGradient, inks: PhiThemeGradientInks): PhiThemeGradientTextTone;
82
+ /** Every slot of one mode: what the palette states, the derived run where it states nothing. */
83
+ export declare function resolvePhiThemeGradients(stated: PhiThemeGradientPalette | null | undefined, token: Record<string, unknown>): Record<PhiThemeGradientKey, PhiThemeGradient>;
84
+ /** The text colour on a run: the tone it states, else the one that reads better. */
85
+ export declare function resolvePhiThemeGradientText(gradient: PhiThemeGradient, inks: PhiThemeGradientInks): string;
86
+ /**
87
+ * The tokens one mode's gradients become, and the primary Buttons' run when the Theme asks for one.
88
+ *
89
+ * Laid over the resolved alias tokens rather than fed to the algorithm: they are not seeds, nothing
90
+ * derives from them, and they are read back only as the custom properties Ant Design writes for them.
91
+ */
92
+ export declare function buildPhiThemeGradientTokens({ gradients, token, primaryButtonGradient, }: {
93
+ gradients: PhiThemeGradientPalette | null | undefined;
94
+ token: Record<string, unknown>;
95
+ primaryButtonGradient?: PhiThemeGradientKey | null;
96
+ }): Record<string, string>;
@@ -0,0 +1,245 @@
1
+ /**
2
+ * The Theme's gradients: three named slots, like the ten custom colours, that a control can take its
3
+ * ground from instead of from one colour.
4
+ *
5
+ * A gradient belongs to a mode for the reason a mode seed does: the ground that reads as a brand on a
6
+ * light page -- a deep burgundy run -- is a hole in a dark one, where the same brand reads as gold. So a
7
+ * palette states each slot per mode (`modes[mode].gradients`), and a slot it leaves out is derived from
8
+ * the mode's own colours, which is what lets every Theme offer all three without anybody drawing them.
9
+ *
10
+ * They reach the page as Ant Design tokens -- `phiGradient1` and its `phiGradient1Text` -- and Ant Design
11
+ * writes every token as a custom property under the Theme's class (`--ant-phi-gradient-1`). That is the
12
+ * whole transport: the root writes both modes, a Surface tone writes its own mode on its box, and the
13
+ * Theme workspace's preview writes the draft's, so a control that reads the property is in the right mode
14
+ * wherever it stands without asking which one that is.
15
+ */
16
+ export const PHI_THEME_GRADIENT_KEYS = ["gradient1", "gradient2", "gradient3"];
17
+ export const PHI_THEME_GRADIENT_TEXT_TONES = ["light", "dark"];
18
+ function isPhiThemeGradientKey(value) {
19
+ return typeof value === "string" && PHI_THEME_GRADIENT_KEYS.includes(value);
20
+ }
21
+ /** A slot as a value a control or a widget config may store; anything else reads as no gradient. */
22
+ export function readPhiThemeGradientKey(value) {
23
+ return isPhiThemeGradientKey(value) ? value : undefined;
24
+ }
25
+ function isGradientDirection(value) {
26
+ return typeof value === "string"
27
+ && (["to right", "to left", "to bottom", "to top"].includes(value) || /^-?\d+(\.\d+)?deg$/.test(value));
28
+ }
29
+ /** The text tone a stored slot states, with or without a run of its own. */
30
+ export function readPhiThemeGradientTextTone(value) {
31
+ const text = value && typeof value === "object" ? value.text : undefined;
32
+ return PHI_THEME_GRADIENT_TEXT_TONES.find((tone) => tone === text);
33
+ }
34
+ /** A stored gradient, read strictly: two stops at least, each a colour and a place on the run. */
35
+ export function readPhiThemeGradient(value) {
36
+ if (!value || typeof value !== "object")
37
+ return null;
38
+ const raw = value;
39
+ if (!isGradientDirection(raw.direction) || !Array.isArray(raw.stops))
40
+ return null;
41
+ const stops = raw.stops.flatMap((stop) => {
42
+ if (!stop || typeof stop !== "object")
43
+ return [];
44
+ const { color, percent } = stop;
45
+ return typeof color === "string" && color.trim() && typeof percent === "number" && Number.isFinite(percent)
46
+ ? [{ color: color.trim(), percent: Math.min(100, Math.max(0, percent)) }]
47
+ : [];
48
+ });
49
+ if (stops.length < 2)
50
+ return null;
51
+ const text = PHI_THEME_GRADIENT_TEXT_TONES.find((tone) => tone === raw.text);
52
+ return { direction: raw.direction, stops, ...(text ? { text } : {}) };
53
+ }
54
+ function serializePhiThemeGradientCss(gradient) {
55
+ return `linear-gradient(${gradient.direction}, ${gradient.stops.map((stop) => `${stop.color} ${stop.percent}%`).join(", ")})`;
56
+ }
57
+ /*
58
+ * The custom properties, named the way Ant Design names a token's (`token2CSSVar`): `phiGradient1Text`
59
+ * becomes `--ant-phi-gradient-1-text`. Stated once so CSS and controls never spell them differently.
60
+ */
61
+ const PHI_THEME_GRADIENT_TOKEN_NAMES = {
62
+ gradient1: { paint: "phiGradient1", text: "phiGradient1Text" },
63
+ gradient2: { paint: "phiGradient2", text: "phiGradient2Text" },
64
+ gradient3: { paint: "phiGradient3", text: "phiGradient3Text" },
65
+ };
66
+ export const PHI_THEME_GRADIENT_CSS_VARS = {
67
+ gradient1: { paint: "--ant-phi-gradient-1", text: "--ant-phi-gradient-1-text" },
68
+ gradient2: { paint: "--ant-phi-gradient-2", text: "--ant-phi-gradient-2-text" },
69
+ gradient3: { paint: "--ant-phi-gradient-3", text: "--ant-phi-gradient-3-text" },
70
+ };
71
+ /*
72
+ * The primary Buttons' run when the Theme gives them one, with the filter each pressed state lays over
73
+ * it; `none` in all three otherwise, so the rules in `styles/gradients.css` change nothing on a Theme
74
+ * that never asked for a gradient. The states are filters rather than a second picture: Ant Design
75
+ * transitions every property of a Button, and a picture swapped on hover crossfades badly -- it
76
+ * flickered as the pointer left -- where a filter eases.
77
+ */
78
+ const PHI_PRIMARY_BUTTON_GRADIENT_TOKENS = {
79
+ paint: "phiPrimaryButtonGradient",
80
+ hover: "phiPrimaryButtonGradientHover",
81
+ active: "phiPrimaryButtonGradientActive",
82
+ text: "phiPrimaryButtonGradientText",
83
+ };
84
+ /** A run a little lighter under the pointer, a little darker while it is pressed. */
85
+ export const PHI_GRADIENT_HOVER_FILTER = "brightness(1.18) saturate(1.15)";
86
+ const PHI_GRADIENT_ACTIVE_FILTER = "brightness(0.88)";
87
+ /* Enough of CSS colour for what a palette states: hex in its four lengths and `rgb()`/`rgba()`. */
88
+ function parseColor(value) {
89
+ const text = value.trim().toLowerCase();
90
+ const hex = /^#([0-9a-f]{3,8})$/.exec(text)?.[1];
91
+ if (hex) {
92
+ const full = hex.length <= 4 ? [...hex].map((digit) => digit + digit).join("") : hex;
93
+ return {
94
+ r: Number.parseInt(full.slice(0, 2), 16),
95
+ g: Number.parseInt(full.slice(2, 4), 16),
96
+ b: Number.parseInt(full.slice(4, 6), 16),
97
+ a: full.length >= 8 ? Number.parseInt(full.slice(6, 8), 16) / 255 : 1,
98
+ };
99
+ }
100
+ const rgb = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+)(%?))?/.exec(text);
101
+ if (!rgb)
102
+ return null;
103
+ const alpha = rgb[4] == null ? 1 : Number(rgb[4]) / (rgb[5] ? 100 : 1);
104
+ return { r: Number(rgb[1]), g: Number(rgb[2]), b: Number(rgb[3]), a: Math.min(1, Math.max(0, alpha)) };
105
+ }
106
+ /** A translucent text colour as it lands on its ground: the near-black `0.88` text is not black. */
107
+ function composite(top, ground) {
108
+ const mix = (front, back) => front * top.a + back * (1 - top.a);
109
+ return { r: mix(top.r, ground.r), g: mix(top.g, ground.g), b: mix(top.b, ground.b) };
110
+ }
111
+ /* What `filter: brightness(n)` does to a colour: each channel scaled and clipped. */
112
+ function brighten(colour, factor) {
113
+ const scale = (channel) => Math.min(255, channel * factor);
114
+ return { r: scale(colour.r), g: scale(colour.g), b: scale(colour.b) };
115
+ }
116
+ function relativeLuminance({ r, g, b }) {
117
+ const channel = (value) => {
118
+ const c = value / 255;
119
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
120
+ };
121
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
122
+ }
123
+ function contrastOf(first, second) {
124
+ const [light, dark] = [relativeLuminance(first), relativeLuminance(second)].sort((x, y) => y - x);
125
+ return (light + 0.05) / (dark + 0.05);
126
+ }
127
+ /** How much lighter a gradient Control is under the pointer (`styles/gradients.css`). */
128
+ const PHI_GRADIENT_HOVER_BRIGHTNESS = 1.18;
129
+ const PHI_GRADIENT_LIGHT_TEXT = "#ffffff";
130
+ const PHI_GRADIENT_DARK_TEXT = "rgba(0, 0, 0, 0.88)";
131
+ /** The two text colours of one mode's resolved tokens (`PhiThemeGradientInks`). */
132
+ export function resolvePhiThemeGradientInks(token) {
133
+ const light = tokenColor(token, "colorTextLightSolid", PHI_GRADIENT_LIGHT_TEXT);
134
+ const candidates = [tokenColor(token, "colorText", PHI_GRADIENT_DARK_TEXT), tokenColor(token, "colorBgBase", PHI_GRADIENT_DARK_TEXT)];
135
+ const darkness = (colour) => {
136
+ const parsed = parseColor(colour);
137
+ return parsed ? relativeLuminance(composite(parsed, { r: 255, g: 255, b: 255 })) : Number.POSITIVE_INFINITY;
138
+ };
139
+ const dark = candidates.reduce((darkest, next) => (darkness(next) < darkness(darkest) ? next : darkest));
140
+ return { light, dark: Number.isFinite(darkness(dark)) ? dark : PHI_GRADIENT_DARK_TEXT };
141
+ }
142
+ /**
143
+ * Where a text colour reads worst on the run. Text crosses the whole run, so the stop it reads worst on
144
+ * decides -- at rest and under the pointer, where the hover filter lightens run and words alike. A
145
+ * translucent text colour is laid on each stop first. `null` where a colour is not one this can read
146
+ * (`hsl()`, a variable): the Theme workspace then says nothing rather than something wrong.
147
+ */
148
+ export function resolvePhiThemeGradientContrast(gradient, text) {
149
+ const words = parseColor(text);
150
+ if (!words)
151
+ return null;
152
+ let worst = null;
153
+ for (const [stopIndex, stop] of gradient.stops.entries()) {
154
+ const ground = parseColor(stop.color);
155
+ if (!ground)
156
+ return null;
157
+ for (const hover of [false, true]) {
158
+ const factor = hover ? PHI_GRADIENT_HOVER_BRIGHTNESS : 1;
159
+ const lit = brighten(ground, factor);
160
+ const ratio = contrastOf(lit, brighten(composite(words, ground), factor));
161
+ if (worst == null || ratio < worst.ratio - 1e-9) {
162
+ worst = { ratio, stopIndex, color: stop.color, hover };
163
+ }
164
+ }
165
+ }
166
+ return worst;
167
+ }
168
+ /** The weakest contrast a text colour has anywhere on the run, at rest or under the pointer. */
169
+ export function resolvePhiThemeGradientWorstContrast(gradient, text) {
170
+ return resolvePhiThemeGradientContrast(gradient, text)?.ratio ?? null;
171
+ }
172
+ /** Which of the two text colours reads better where the run reads worst for it. */
173
+ export function resolvePhiThemeGradientAutoTextTone(gradient, inks) {
174
+ const light = resolvePhiThemeGradientWorstContrast(gradient, inks.light) ?? 0;
175
+ const dark = resolvePhiThemeGradientWorstContrast(gradient, inks.dark) ?? 0;
176
+ return light >= dark ? "light" : "dark";
177
+ }
178
+ function tokenColor(token, key, fallback) {
179
+ const value = token[key];
180
+ return typeof value === "string" && value.trim() ? value : fallback;
181
+ }
182
+ /**
183
+ * The three slots a mode offers when its palette states none: runs within the mode's own colours, so they
184
+ * belong to whichever brand the Theme carries. The primary's hover into its pressed shade first -- the
185
+ * brand --, the warning colour second because a palette's accent sits there, then the info colour into
186
+ * the primary, a run for the chrome. Three cover what a site asks of a run; a fourth was the third
187
+ * turned round.
188
+ */
189
+ function buildPhiThemeDefaultGradients(token) {
190
+ const primary = tokenColor(token, "colorPrimary", "#1677ff");
191
+ const primaryHover = tokenColor(token, "colorPrimaryHover", primary);
192
+ const primaryActive = tokenColor(token, "colorPrimaryActive", primary);
193
+ const warning = tokenColor(token, "colorWarning", "#faad14");
194
+ const warningHover = tokenColor(token, "colorWarningHover", warning);
195
+ const warningActive = tokenColor(token, "colorWarningActive", warning);
196
+ const info = tokenColor(token, "colorInfo", primary);
197
+ return {
198
+ gradient1: { direction: "135deg", stops: [{ color: primaryHover, percent: 0 }, { color: primaryActive, percent: 100 }] },
199
+ gradient2: { direction: "135deg", stops: [{ color: warningHover, percent: 0 }, { color: warningActive, percent: 100 }] },
200
+ gradient3: { direction: "135deg", stops: [{ color: info, percent: 0 }, { color: primary, percent: 100 }] },
201
+ };
202
+ }
203
+ /** Every slot of one mode: what the palette states, the derived run where it states nothing. */
204
+ export function resolvePhiThemeGradients(stated, token) {
205
+ const defaults = buildPhiThemeDefaultGradients(token);
206
+ return Object.fromEntries(PHI_THEME_GRADIENT_KEYS.map((key) => {
207
+ const own = readPhiThemeGradient(stated?.[key]);
208
+ const text = readPhiThemeGradientTextTone(stated?.[key]);
209
+ return [key, own ?? (text ? { ...defaults[key], text } : defaults[key])];
210
+ }));
211
+ }
212
+ /** The text colour on a run: the tone it states, else the one that reads better. */
213
+ export function resolvePhiThemeGradientText(gradient, inks) {
214
+ return inks[gradient.text ?? resolvePhiThemeGradientAutoTextTone(gradient, inks)];
215
+ }
216
+ /**
217
+ * The tokens one mode's gradients become, and the primary Buttons' run when the Theme asks for one.
218
+ *
219
+ * Laid over the resolved alias tokens rather than fed to the algorithm: they are not seeds, nothing
220
+ * derives from them, and they are read back only as the custom properties Ant Design writes for them.
221
+ */
222
+ export function buildPhiThemeGradientTokens({ gradients, token, primaryButtonGradient, }) {
223
+ const resolved = resolvePhiThemeGradients(gradients, token);
224
+ const inks = resolvePhiThemeGradientInks(token);
225
+ const tokens = {};
226
+ for (const key of PHI_THEME_GRADIENT_KEYS) {
227
+ const names = PHI_THEME_GRADIENT_TOKEN_NAMES[key];
228
+ tokens[names.paint] = serializePhiThemeGradientCss(resolved[key]);
229
+ tokens[names.text] = resolvePhiThemeGradientText(resolved[key], inks);
230
+ }
231
+ if (primaryButtonGradient && isPhiThemeGradientKey(primaryButtonGradient)) {
232
+ const paint = tokens[PHI_THEME_GRADIENT_TOKEN_NAMES[primaryButtonGradient].paint];
233
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.paint] = paint;
234
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.hover] = PHI_GRADIENT_HOVER_FILTER;
235
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.active] = PHI_GRADIENT_ACTIVE_FILTER;
236
+ // Only stated with a run under it: absent, the rule falls back to Ant Design's own primary text.
237
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.text] = tokens[PHI_THEME_GRADIENT_TOKEN_NAMES[primaryButtonGradient].text];
238
+ }
239
+ else {
240
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.paint] = "none";
241
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.hover] = "none";
242
+ tokens[PHI_PRIMARY_BUTTON_GRADIENT_TOKENS.active] = "none";
243
+ }
244
+ return tokens;
245
+ }