@siiway/ui-core 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -1
  3. package/dist/boot.d.ts +24 -0
  4. package/dist/boot.d.ts.map +1 -0
  5. package/dist/boot.js +38 -0
  6. package/dist/boot.js.map +1 -0
  7. package/dist/duration.d.ts +27 -0
  8. package/dist/duration.d.ts.map +1 -0
  9. package/dist/duration.js +87 -0
  10. package/dist/duration.js.map +1 -0
  11. package/dist/i18n/en.d.ts +3 -0
  12. package/dist/i18n/en.d.ts.map +1 -0
  13. package/dist/i18n/en.js +56 -0
  14. package/dist/i18n/en.js.map +1 -0
  15. package/dist/i18n/index.d.ts +11 -0
  16. package/dist/i18n/index.d.ts.map +1 -0
  17. package/dist/i18n/index.js +16 -0
  18. package/dist/i18n/index.js.map +1 -0
  19. package/dist/i18n/types.d.ts +72 -0
  20. package/dist/i18n/types.d.ts.map +1 -0
  21. package/dist/i18n/types.js +2 -0
  22. package/dist/i18n/types.js.map +1 -0
  23. package/dist/i18n/zh.d.ts +3 -0
  24. package/dist/i18n/zh.d.ts.map +1 -0
  25. package/dist/i18n/zh.js +56 -0
  26. package/dist/i18n/zh.js.map +1 -0
  27. package/dist/index.d.ts +12 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +12 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/scheme.d.ts +36 -0
  32. package/dist/scheme.d.ts.map +1 -0
  33. package/dist/scheme.js +49 -0
  34. package/dist/scheme.js.map +1 -0
  35. package/dist/theme/brand.d.ts +17 -0
  36. package/dist/theme/brand.d.ts.map +1 -0
  37. package/dist/theme/brand.js +25 -0
  38. package/dist/theme/brand.js.map +1 -0
  39. package/dist/theme/color.d.ts +26 -0
  40. package/dist/theme/color.d.ts.map +1 -0
  41. package/dist/theme/color.js +148 -0
  42. package/dist/theme/color.js.map +1 -0
  43. package/dist/theme/overrides.d.ts +12 -0
  44. package/dist/theme/overrides.d.ts.map +1 -0
  45. package/dist/theme/overrides.js +12 -0
  46. package/dist/theme/overrides.js.map +1 -0
  47. package/dist/tokens/canvas.d.ts +8 -0
  48. package/dist/tokens/canvas.d.ts.map +1 -0
  49. package/dist/tokens/canvas.js +7 -0
  50. package/dist/tokens/canvas.js.map +1 -0
  51. package/dist/tokens/neutral.d.ts +55 -0
  52. package/dist/tokens/neutral.d.ts.map +1 -0
  53. package/dist/tokens/neutral.js +110 -0
  54. package/dist/tokens/neutral.js.map +1 -0
  55. package/dist/tokens/radii.d.ts +8 -0
  56. package/dist/tokens/radii.d.ts.map +1 -0
  57. package/dist/tokens/radii.js +8 -0
  58. package/dist/tokens/radii.js.map +1 -0
  59. package/dist/tokens/shadows.d.ts +14 -0
  60. package/dist/tokens/shadows.d.ts.map +1 -0
  61. package/dist/tokens/shadows.js +21 -0
  62. package/dist/tokens/shadows.js.map +1 -0
  63. package/package.json +25 -2
  64. package/src/boot.ts +55 -0
  65. package/src/duration.ts +119 -0
  66. package/src/i18n/en.ts +66 -0
  67. package/src/i18n/index.ts +24 -0
  68. package/src/i18n/types.ts +82 -0
  69. package/src/i18n/zh.ts +65 -0
  70. package/src/index.ts +46 -0
  71. package/src/scheme.ts +71 -0
  72. package/src/theme/brand.ts +32 -0
  73. package/src/theme/color.ts +147 -0
  74. package/src/theme/overrides.ts +15 -0
  75. package/src/tokens/canvas.ts +8 -0
  76. package/src/tokens/neutral.ts +116 -0
  77. package/src/tokens/radii.ts +7 -0
  78. package/src/tokens/shadows.ts +27 -0
@@ -0,0 +1,147 @@
1
+ // Colour conversions for the brand ramp (HSL) and the colour picker (HSV).
2
+
3
+ const HEX_COLOR = /^#?([0-9a-f]{6})$/i;
4
+ const SHORT_HEX_COLOR = /^#?([0-9a-f]{3})$/i;
5
+ const ACCENT_HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
6
+
7
+ /**
8
+ * Normalizes a colour a person typed: three or six hex digits, `#` optional.
9
+ * Returns lowercase `#rrggbb`, or null when the input isn't one.
10
+ */
11
+ export function normalizeHexColor(value: string): string | null {
12
+ const input = value.trim();
13
+ const full = HEX_COLOR.exec(input);
14
+ if (full) return `#${full[1]!.toLowerCase()}`;
15
+
16
+ const short = SHORT_HEX_COLOR.exec(input);
17
+ if (!short) return null;
18
+
19
+ return `#${[...short[1]!].map((digit) => digit.repeat(2)).join("")}`.toLowerCase();
20
+ }
21
+
22
+ /**
23
+ * Normalizes a configured accent: `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`.
24
+ * Alpha has no meaning for a brand ramp, so it is dropped. Anything else, or
25
+ * nothing, gives `fallback`.
26
+ */
27
+ export function normalizeAccent(value: string | null | undefined, fallback: string): string {
28
+ if (!value) return fallback;
29
+ const m = ACCENT_HEX.exec(value.trim());
30
+ if (!m) return fallback;
31
+ const digits = m[1]!.toLowerCase();
32
+ if (digits.length <= 4) {
33
+ return `#${digits
34
+ .slice(0, 3)
35
+ .split("")
36
+ .map((c) => c + c)
37
+ .join("")}`;
38
+ }
39
+ return `#${digits.slice(0, 6)}`;
40
+ }
41
+
42
+ /** `#rrggbb` → [hue 0–360, saturation 0–100, lightness 0–100], unrounded. */
43
+ export function hexToHsl(hex: string): [number, number, number] {
44
+ const r = parseInt(hex.slice(1, 3), 16) / 255;
45
+ const g = parseInt(hex.slice(3, 5), 16) / 255;
46
+ const b = parseInt(hex.slice(5, 7), 16) / 255;
47
+ const max = Math.max(r, g, b);
48
+ const min = Math.min(r, g, b);
49
+ let h = 0;
50
+ let s = 0;
51
+ const l = (max + min) / 2;
52
+ if (max !== min) {
53
+ const d = max - min;
54
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
55
+ if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
56
+ else if (max === g) h = ((b - r) / d + 2) / 6;
57
+ else h = ((r - g) / d + 4) / 6;
58
+ }
59
+ return [h * 360, s * 100, l * 100];
60
+ }
61
+
62
+ /** Hue 0–360, saturation 0–100, lightness 0–100 → lowercase `#rrggbb`. */
63
+ export function hslToHex(h: number, s: number, l: number): string {
64
+ const hN = h / 360;
65
+ const sN = s / 100;
66
+ const lN = l / 100;
67
+ const hue2rgb = (p: number, q: number, t: number) => {
68
+ if (t < 0) t += 1;
69
+ if (t > 1) t -= 1;
70
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
71
+ if (t < 1 / 2) return q;
72
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
73
+ return p;
74
+ };
75
+ let r: number, g: number, b: number;
76
+ if (sN === 0) {
77
+ r = g = b = lN;
78
+ } else {
79
+ const q = lN < 0.5 ? lN * (1 + sN) : lN + sN - lN * sN;
80
+ const p = 2 * lN - q;
81
+ r = hue2rgb(p, q, hN + 1 / 3);
82
+ g = hue2rgb(p, q, hN);
83
+ b = hue2rgb(p, q, hN - 1 / 3);
84
+ }
85
+ const hex = (v: number) =>
86
+ Math.round(v * 255)
87
+ .toString(16)
88
+ .padStart(2, "0");
89
+ return `#${hex(r)}${hex(g)}${hex(b)}`;
90
+ }
91
+
92
+ /** Hue 0–360, saturation and value 0–1. */
93
+ export interface HsvColor {
94
+ h: number;
95
+ s: number;
96
+ v: number;
97
+ }
98
+
99
+ /** Any colour normalizeHexColor accepts → HSV, or null. */
100
+ export function hexToHsv(value: string): HsvColor | null {
101
+ const normalized = normalizeHexColor(value);
102
+ if (!normalized) return null;
103
+
104
+ const red = Number.parseInt(normalized.slice(1, 3), 16) / 255;
105
+ const green = Number.parseInt(normalized.slice(3, 5), 16) / 255;
106
+ const blue = Number.parseInt(normalized.slice(5, 7), 16) / 255;
107
+ const max = Math.max(red, green, blue);
108
+ const min = Math.min(red, green, blue);
109
+ const delta = max - min;
110
+ let hue = 0;
111
+
112
+ if (delta !== 0) {
113
+ if (max === red) hue = 60 * (((green - blue) / delta) % 6);
114
+ else if (max === green) hue = 60 * ((blue - red) / delta + 2);
115
+ else hue = 60 * ((red - green) / delta + 4);
116
+ }
117
+
118
+ if (hue < 0) hue += 360;
119
+ return { h: hue, s: max === 0 ? 0 : delta / max, v: max };
120
+ }
121
+
122
+ /** HSV → lowercase `#rrggbb`. Out-of-range values are clamped. */
123
+ export function hsvToHex({ h, s, v }: HsvColor): string {
124
+ const hue = ((h % 360) + 360) % 360;
125
+ const saturation = Math.min(1, Math.max(0, s));
126
+ const value = Math.min(1, Math.max(0, v));
127
+ const chroma = value * saturation;
128
+ const section = hue / 60;
129
+ const secondary = chroma * (1 - Math.abs((section % 2) - 1));
130
+ const offset = value - chroma;
131
+ let rgb: [number, number, number];
132
+
133
+ if (section < 1) rgb = [chroma, secondary, 0];
134
+ else if (section < 2) rgb = [secondary, chroma, 0];
135
+ else if (section < 3) rgb = [0, chroma, secondary];
136
+ else if (section < 4) rgb = [0, secondary, chroma];
137
+ else if (section < 5) rgb = [secondary, 0, chroma];
138
+ else rgb = [chroma, 0, secondary];
139
+
140
+ return `#${rgb
141
+ .map((channel) =>
142
+ Math.round((channel + offset) * 255)
143
+ .toString(16)
144
+ .padStart(2, "0"),
145
+ )
146
+ .join("")}`;
147
+ }
@@ -0,0 +1,15 @@
1
+ import type { Scheme } from "../scheme.js";
2
+ import { NEUTRAL, type NeutralTokens } from "../tokens/neutral.js";
3
+ import { RADII } from "../tokens/radii.js";
4
+ import { SHADOWS, type ShadowTokens } from "../tokens/shadows.js";
5
+
6
+ export type ThemeOverrides = typeof RADII & ShadowTokens & NeutralTokens;
7
+
8
+ /**
9
+ * Every token the SiiWay look changes from Fluent's defaults, for one scheme.
10
+ * Spread it over a Fluent theme built from brandRamp():
11
+ * `{ ...createLightTheme(brandRamp(accent)), ...themeOverrides("light") }`.
12
+ */
13
+ export function themeOverrides(scheme: Scheme): ThemeOverrides {
14
+ return { ...RADII, ...SHADOWS[scheme], ...NEUTRAL[scheme] };
15
+ }
@@ -0,0 +1,8 @@
1
+ import type { Scheme } from "../scheme.js";
2
+
3
+ /**
4
+ * The page backdrop that header, sidebar and content share, and that cards
5
+ * sit on with a hairline border. Darker than colorNeutralBackground1 in the
6
+ * dark scheme, so cards still read as surfaces there.
7
+ */
8
+ export const CANVAS: Record<Scheme, string> = { light: "#ffffff", dark: "#1a1a1a" };
@@ -0,0 +1,116 @@
1
+ import type { Scheme } from "../scheme.js";
2
+
3
+ // Neutral ramp modelled on the Cloudflare dashboard: one flat page colour
4
+ // (CANVAS) shared by header, sidebar and content; surfaces that differ from it
5
+ // by a hairline border and at most a shade of fill; true neutral greys.
6
+ // StrokeAccessible keeps form-control boundaries above 3:1.
7
+ //
8
+ // Keys are Fluent token names. Fluent's React components and its web
9
+ // components both read these as CSS variables (--colorNeutralBackground1, …),
10
+ // so any adapter can apply them.
11
+
12
+ const LIGHT = {
13
+ colorNeutralBackground1: "#ffffff",
14
+ colorNeutralBackground1Hover: "#f7f7f7",
15
+ colorNeutralBackground1Pressed: "#efefef",
16
+ colorNeutralBackground1Selected: "#f2f2f2",
17
+ colorNeutralBackground2: "#fafafa",
18
+ colorNeutralBackground2Hover: "#f2f2f2",
19
+ colorNeutralBackground2Pressed: "#ebebeb",
20
+ colorNeutralBackground2Selected: "#efefef",
21
+ colorNeutralBackground3: "#f2f2f2",
22
+ colorNeutralBackground3Hover: "#ebebeb",
23
+ colorNeutralBackground3Pressed: "#e3e3e3",
24
+ colorNeutralBackground3Selected: "#ebebeb",
25
+ colorNeutralBackground4: "#ebebeb",
26
+ colorNeutralBackground4Hover: "#e3e3e3",
27
+ colorNeutralBackground4Pressed: "#dbdbdb",
28
+ colorNeutralBackground4Selected: "#e3e3e3",
29
+ colorNeutralBackground5: "#e3e3e3",
30
+ colorNeutralBackground5Hover: "#dbdbdb",
31
+ colorNeutralBackground5Pressed: "#d4d4d4",
32
+ colorNeutralBackground5Selected: "#dbdbdb",
33
+ colorNeutralBackground6: "#dbdbdb",
34
+ colorNeutralForeground1: "#171717",
35
+ colorNeutralForeground1Hover: "#171717",
36
+ colorNeutralForeground1Pressed: "#171717",
37
+ colorNeutralForeground1Selected: "#171717",
38
+ colorNeutralForeground2: "#404040",
39
+ colorNeutralForeground2Hover: "#171717",
40
+ colorNeutralForeground2Pressed: "#171717",
41
+ colorNeutralForeground2Selected: "#171717",
42
+ colorNeutralForeground3: "#6b6b6b",
43
+ colorNeutralForeground3Hover: "#404040",
44
+ colorNeutralForeground3Pressed: "#404040",
45
+ colorNeutralForeground3Selected: "#404040",
46
+ colorNeutralForeground4: "#858585",
47
+ colorNeutralStroke1: "#dedede",
48
+ colorNeutralStroke1Hover: "#c7c7c7",
49
+ colorNeutralStroke1Pressed: "#b3b3b3",
50
+ colorNeutralStroke1Selected: "#bdbdbd",
51
+ colorNeutralStroke2: "#e8e8e8",
52
+ colorNeutralStroke3: "#f0f0f0",
53
+ colorNeutralStrokeAccessible: "#858585",
54
+ colorNeutralStrokeAccessibleHover: "#6b6b6b",
55
+ colorNeutralStrokeAccessiblePressed: "#595959",
56
+ // Loading placeholders: a shade off the card, not a block of grey.
57
+ colorNeutralStencil1: "#ececec",
58
+ colorNeutralStencil2: "#f6f6f6",
59
+ colorNeutralStencil1Alpha: "rgba(0, 0, 0, 0.07)",
60
+ colorNeutralStencil2Alpha: "rgba(0, 0, 0, 0.035)",
61
+ };
62
+
63
+ const DARK: typeof LIGHT = {
64
+ colorNeutralBackground1: "#222222",
65
+ colorNeutralBackground1Hover: "#292929",
66
+ colorNeutralBackground1Pressed: "#303030",
67
+ colorNeutralBackground1Selected: "#2c2c2c",
68
+ colorNeutralBackground2: "#1f1f1f",
69
+ colorNeutralBackground2Hover: "#262626",
70
+ colorNeutralBackground2Pressed: "#2d2d2d",
71
+ colorNeutralBackground2Selected: "#2a2a2a",
72
+ colorNeutralBackground3: "#2b2b2b",
73
+ colorNeutralBackground3Hover: "#323232",
74
+ colorNeutralBackground3Pressed: "#393939",
75
+ colorNeutralBackground3Selected: "#323232",
76
+ colorNeutralBackground4: "#323232",
77
+ colorNeutralBackground4Hover: "#393939",
78
+ colorNeutralBackground4Pressed: "#404040",
79
+ colorNeutralBackground4Selected: "#393939",
80
+ colorNeutralBackground5: "#393939",
81
+ colorNeutralBackground5Hover: "#404040",
82
+ colorNeutralBackground5Pressed: "#474747",
83
+ colorNeutralBackground5Selected: "#404040",
84
+ colorNeutralBackground6: "#404040",
85
+ colorNeutralForeground1: "#f0f0f0",
86
+ colorNeutralForeground1Hover: "#ffffff",
87
+ colorNeutralForeground1Pressed: "#ffffff",
88
+ colorNeutralForeground1Selected: "#ffffff",
89
+ colorNeutralForeground2: "#d0d0d0",
90
+ colorNeutralForeground2Hover: "#f5f5f5",
91
+ colorNeutralForeground2Pressed: "#f5f5f5",
92
+ colorNeutralForeground2Selected: "#f5f5f5",
93
+ colorNeutralForeground3: "#a3a3a3",
94
+ colorNeutralForeground3Hover: "#d0d0d0",
95
+ colorNeutralForeground3Pressed: "#d0d0d0",
96
+ colorNeutralForeground3Selected: "#d0d0d0",
97
+ colorNeutralForeground4: "#858585",
98
+ colorNeutralStroke1: "#3b3b3b",
99
+ colorNeutralStroke1Hover: "#4a4a4a",
100
+ colorNeutralStroke1Pressed: "#575757",
101
+ colorNeutralStroke1Selected: "#4a4a4a",
102
+ colorNeutralStroke2: "#313131",
103
+ colorNeutralStroke3: "#292929",
104
+ colorNeutralStrokeAccessible: "#8f8f8f",
105
+ colorNeutralStrokeAccessibleHover: "#a8a8a8",
106
+ colorNeutralStrokeAccessiblePressed: "#bababa",
107
+ colorNeutralStencil1: "#303030",
108
+ colorNeutralStencil2: "#282828",
109
+ colorNeutralStencil1Alpha: "rgba(255, 255, 255, 0.07)",
110
+ colorNeutralStencil2Alpha: "rgba(255, 255, 255, 0.035)",
111
+ };
112
+
113
+ export type NeutralTokens = typeof LIGHT;
114
+
115
+ /** Neutral backgrounds, foregrounds, strokes and stencils, per scheme. */
116
+ export const NEUTRAL: Record<Scheme, NeutralTokens> = { light: LIGHT, dark: DARK };
@@ -0,0 +1,7 @@
1
+ /** Corner radii, one step rounder than Fluent's defaults. */
2
+ export const RADII = {
3
+ borderRadiusMedium: "6px",
4
+ borderRadiusLarge: "8px",
5
+ borderRadiusXLarge: "10px",
6
+ borderRadius2XLarge: "12px",
7
+ };
@@ -0,0 +1,27 @@
1
+ import type { Scheme } from "../scheme.js";
2
+
3
+ // Only floating surfaces (menus, popovers, dialogs) use these; page content is
4
+ // flat and separated by borders alone.
5
+
6
+ const LIGHT = {
7
+ shadow2: "0 1px 2px rgba(0, 0, 0, 0.05)",
8
+ shadow4: "0 1px 3px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04)",
9
+ shadow8: "0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05)",
10
+ shadow16: "0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.05)",
11
+ shadow28: "0 14px 36px rgba(0, 0, 0, 0.14), 0 3px 8px rgba(0, 0, 0, 0.06)",
12
+ shadow64: "0 24px 64px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08)",
13
+ };
14
+
15
+ const DARK: typeof LIGHT = {
16
+ shadow2: "0 1px 2px rgba(0, 0, 0, 0.5)",
17
+ shadow4: "0 1px 3px rgba(0, 0, 0, 0.55), 0 1px 2px rgba(0, 0, 0, 0.4)",
18
+ shadow8: "0 4px 12px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4)",
19
+ shadow16: "0 8px 24px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4)",
20
+ shadow28: "0 14px 36px rgba(0, 0, 0, 0.65), 0 3px 8px rgba(0, 0, 0, 0.4)",
21
+ shadow64: "0 24px 64px rgba(0, 0, 0, 0.7), 0 4px 12px rgba(0, 0, 0, 0.45)",
22
+ };
23
+
24
+ export type ShadowTokens = typeof LIGHT;
25
+
26
+ /** Shadows for floating surfaces, per scheme. */
27
+ export const SHADOWS: Record<Scheme, ShadowTokens> = { light: LIGHT, dark: DARK };