@mgamadeus/ddd-admin-ui 0.0.0-stage → 0.1.0-rc.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 (193) hide show
  1. package/.claude/skills/ddd-admin-ui-specialist/SKILL.md +29 -0
  2. package/CHANGELOG.md +16 -0
  3. package/LICENSE +21 -0
  4. package/README.md +131 -2
  5. package/dist/cli/ddd-admin-ui.d.ts +3 -0
  6. package/dist/cli/ddd-admin-ui.d.ts.map +1 -0
  7. package/dist/cli/ddd-admin-ui.js +18 -0
  8. package/dist/cli/ddd-admin-ui.js.map +1 -0
  9. package/dist/cli/linkSkills.d.ts +25 -0
  10. package/dist/cli/linkSkills.d.ts.map +1 -0
  11. package/dist/cli/linkSkills.js +76 -0
  12. package/dist/cli/linkSkills.js.map +1 -0
  13. package/dist/components.css +42 -0
  14. package/dist/data/StatTile.d.ts +8 -0
  15. package/dist/data/StatTile.d.ts.map +1 -0
  16. package/dist/data/StatTile.js +6 -0
  17. package/dist/data/StatTile.js.map +1 -0
  18. package/dist/data/index.d.ts +2 -0
  19. package/dist/data/index.d.ts.map +1 -0
  20. package/dist/data/index.js +2 -0
  21. package/dist/data/index.js.map +1 -0
  22. package/dist/form/Form.d.ts +13 -0
  23. package/dist/form/Form.d.ts.map +1 -0
  24. package/dist/form/Form.js +11 -0
  25. package/dist/form/Form.js.map +1 -0
  26. package/dist/form/fieldLabels.d.ts +10 -0
  27. package/dist/form/fieldLabels.d.ts.map +1 -0
  28. package/dist/form/fieldLabels.js +8 -0
  29. package/dist/form/fieldLabels.js.map +1 -0
  30. package/dist/form/index.d.ts +3 -0
  31. package/dist/form/index.d.ts.map +1 -0
  32. package/dist/form/index.js +3 -0
  33. package/dist/form/index.js.map +1 -0
  34. package/dist/glass/GlassPanel.d.ts +7 -0
  35. package/dist/glass/GlassPanel.d.ts.map +1 -0
  36. package/dist/glass/GlassPanel.js +5 -0
  37. package/dist/glass/GlassPanel.js.map +1 -0
  38. package/dist/glass/index.d.ts +2 -0
  39. package/dist/glass/index.d.ts.map +1 -0
  40. package/dist/glass/index.js +2 -0
  41. package/dist/glass/index.js.map +1 -0
  42. package/dist/i18n/Translate.d.ts +7 -0
  43. package/dist/i18n/Translate.d.ts.map +1 -0
  44. package/dist/i18n/Translate.js +9 -0
  45. package/dist/i18n/Translate.js.map +1 -0
  46. package/dist/i18n/index.d.ts +5 -0
  47. package/dist/i18n/index.d.ts.map +1 -0
  48. package/dist/i18n/index.js +5 -0
  49. package/dist/i18n/index.js.map +1 -0
  50. package/dist/i18n/m.d.ts +7 -0
  51. package/dist/i18n/m.d.ts.map +1 -0
  52. package/dist/i18n/m.js +7 -0
  53. package/dist/i18n/m.js.map +1 -0
  54. package/dist/i18n/store.d.ts +24 -0
  55. package/dist/i18n/store.d.ts.map +1 -0
  56. package/dist/i18n/store.js +30 -0
  57. package/dist/i18n/store.js.map +1 -0
  58. package/dist/i18n/useTranslate.d.ts +9 -0
  59. package/dist/i18n/useTranslate.d.ts.map +1 -0
  60. package/dist/i18n/useTranslate.js +12 -0
  61. package/dist/i18n/useTranslate.js.map +1 -0
  62. package/dist/i18n-keys.json +32 -0
  63. package/dist/list/ClearFiltersButton.d.ts +7 -0
  64. package/dist/list/ClearFiltersButton.d.ts.map +1 -0
  65. package/dist/list/ClearFiltersButton.js +10 -0
  66. package/dist/list/ClearFiltersButton.js.map +1 -0
  67. package/dist/list/DateCell.d.ts +8 -0
  68. package/dist/list/DateCell.d.ts.map +1 -0
  69. package/dist/list/DateCell.js +12 -0
  70. package/dist/list/DateCell.js.map +1 -0
  71. package/dist/list/index.d.ts +3 -0
  72. package/dist/list/index.d.ts.map +1 -0
  73. package/dist/list/index.js +3 -0
  74. package/dist/list/index.js.map +1 -0
  75. package/dist/logic/index.d.ts +6 -0
  76. package/dist/logic/index.d.ts.map +1 -0
  77. package/dist/logic/index.js +6 -0
  78. package/dist/logic/index.js.map +1 -0
  79. package/dist/logic/pure/errors.d.ts +3 -0
  80. package/dist/logic/pure/errors.d.ts.map +1 -0
  81. package/dist/logic/pure/errors.js +5 -0
  82. package/dist/logic/pure/errors.js.map +1 -0
  83. package/dist/logic/pure/format.d.ts +15 -0
  84. package/dist/logic/pure/format.d.ts.map +1 -0
  85. package/dist/logic/pure/format.js +32 -0
  86. package/dist/logic/pure/format.js.map +1 -0
  87. package/dist/logic/pure/notify.d.ts +19 -0
  88. package/dist/logic/pure/notify.d.ts.map +1 -0
  89. package/dist/logic/pure/notify.js +33 -0
  90. package/dist/logic/pure/notify.js.map +1 -0
  91. package/dist/logic/pure/statusMap.d.ts +12 -0
  92. package/dist/logic/pure/statusMap.d.ts.map +1 -0
  93. package/dist/logic/pure/statusMap.js +5 -0
  94. package/dist/logic/pure/statusMap.js.map +1 -0
  95. package/dist/logic/react/useToggle.d.ts +8 -0
  96. package/dist/logic/react/useToggle.d.ts.map +1 -0
  97. package/dist/logic/react/useToggle.js +9 -0
  98. package/dist/logic/react/useToggle.js.map +1 -0
  99. package/dist/media/MediaItemField.d.ts +6 -0
  100. package/dist/media/MediaItemField.d.ts.map +1 -0
  101. package/dist/media/MediaItemField.js +11 -0
  102. package/dist/media/MediaItemField.js.map +1 -0
  103. package/dist/media/index.d.ts +3 -0
  104. package/dist/media/index.d.ts.map +1 -0
  105. package/dist/media/index.js +2 -0
  106. package/dist/media/index.js.map +1 -0
  107. package/dist/media/types.d.ts +7 -0
  108. package/dist/media/types.d.ts.map +1 -0
  109. package/dist/media/types.js +2 -0
  110. package/dist/media/types.js.map +1 -0
  111. package/dist/next/index.d.ts +3 -0
  112. package/dist/next/index.d.ts.map +1 -0
  113. package/dist/next/index.js +3 -0
  114. package/dist/next/index.js.map +1 -0
  115. package/dist/next/searchParamsWriter.d.ts +7 -0
  116. package/dist/next/searchParamsWriter.d.ts.map +1 -0
  117. package/dist/next/searchParamsWriter.js +34 -0
  118. package/dist/next/searchParamsWriter.js.map +1 -0
  119. package/dist/next/useNextSearchParam.d.ts +3 -0
  120. package/dist/next/useNextSearchParam.d.ts.map +1 -0
  121. package/dist/next/useNextSearchParam.js +16 -0
  122. package/dist/next/useNextSearchParam.js.map +1 -0
  123. package/dist/notify-sonner/index.d.ts +2 -0
  124. package/dist/notify-sonner/index.d.ts.map +1 -0
  125. package/dist/notify-sonner/index.js +2 -0
  126. package/dist/notify-sonner/index.js.map +1 -0
  127. package/dist/notify-sonner/sonnerNotifications.d.ts +4 -0
  128. package/dist/notify-sonner/sonnerNotifications.d.ts.map +1 -0
  129. package/dist/notify-sonner/sonnerNotifications.js +12 -0
  130. package/dist/notify-sonner/sonnerNotifications.js.map +1 -0
  131. package/dist/page/PageFrame.d.ts +9 -0
  132. package/dist/page/PageFrame.d.ts.map +1 -0
  133. package/dist/page/PageFrame.js +5 -0
  134. package/dist/page/PageFrame.js.map +1 -0
  135. package/dist/page/index.d.ts +2 -0
  136. package/dist/page/index.d.ts.map +1 -0
  137. package/dist/page/index.js +2 -0
  138. package/dist/page/index.js.map +1 -0
  139. package/dist/primitives/button.d.ts +10 -0
  140. package/dist/primitives/button.d.ts.map +1 -0
  141. package/dist/primitives/button.js +20 -0
  142. package/dist/primitives/button.js.map +1 -0
  143. package/dist/primitives/cn.d.ts +4 -0
  144. package/dist/primitives/cn.d.ts.map +1 -0
  145. package/dist/primitives/cn.js +5 -0
  146. package/dist/primitives/cn.js.map +1 -0
  147. package/dist/primitives/dialog.d.ts +10 -0
  148. package/dist/primitives/dialog.d.ts.map +1 -0
  149. package/dist/primitives/dialog.js +19 -0
  150. package/dist/primitives/dialog.js.map +1 -0
  151. package/dist/primitives/index.d.ts +7 -0
  152. package/dist/primitives/index.d.ts.map +1 -0
  153. package/dist/primitives/index.js +7 -0
  154. package/dist/primitives/index.js.map +1 -0
  155. package/dist/primitives/portalContainer.d.ts +8 -0
  156. package/dist/primitives/portalContainer.d.ts.map +1 -0
  157. package/dist/primitives/portalContainer.js +12 -0
  158. package/dist/primitives/portalContainer.js.map +1 -0
  159. package/dist/primitives/select.d.ts +9 -0
  160. package/dist/primitives/select.d.ts.map +1 -0
  161. package/dist/primitives/select.js +16 -0
  162. package/dist/primitives/select.js.map +1 -0
  163. package/dist/primitives/sheet.d.ts +9 -0
  164. package/dist/primitives/sheet.d.ts.map +1 -0
  165. package/dist/primitives/sheet.js +15 -0
  166. package/dist/primitives/sheet.js.map +1 -0
  167. package/dist/provider/AdminUiProvider.d.ts +7 -0
  168. package/dist/provider/AdminUiProvider.d.ts.map +1 -0
  169. package/dist/provider/AdminUiProvider.js +32 -0
  170. package/dist/provider/AdminUiProvider.js.map +1 -0
  171. package/dist/provider/index.d.ts +3 -0
  172. package/dist/provider/index.d.ts.map +1 -0
  173. package/dist/provider/index.js +2 -0
  174. package/dist/provider/index.js.map +1 -0
  175. package/dist/provider/types.d.ts +33 -0
  176. package/dist/provider/types.d.ts.map +1 -0
  177. package/dist/provider/types.js +2 -0
  178. package/dist/provider/types.js.map +1 -0
  179. package/dist/theme.css +44 -0
  180. package/dist/tokens.json +66 -0
  181. package/dist/translations/TranslatableInputField.d.ts +8 -0
  182. package/dist/translations/TranslatableInputField.d.ts.map +1 -0
  183. package/dist/translations/TranslatableInputField.js +12 -0
  184. package/dist/translations/TranslatableInputField.js.map +1 -0
  185. package/dist/translations/index.d.ts +2 -0
  186. package/dist/translations/index.d.ts.map +1 -0
  187. package/dist/translations/index.js +2 -0
  188. package/dist/translations/index.js.map +1 -0
  189. package/docs/README.md +11 -0
  190. package/package.json +158 -3
  191. package/scripts/check-tokens.mjs +136 -0
  192. package/scripts/lib/i18n-manifest.mjs +91 -0
  193. package/scripts/lib/source-scan.mjs +258 -0
@@ -0,0 +1,8 @@
1
+ export interface TranslatableInputFieldProps {
2
+ name: string;
3
+ /** Language of this input, shown next to the label. */
4
+ languageCode: string;
5
+ }
6
+ /** A text input for one language of a translatable property; the label comes from the form. */
7
+ export declare const TranslatableInputField: ({ name, languageCode }: TranslatableInputFieldProps) => import("react").JSX.Element;
8
+ //# sourceMappingURL=TranslatableInputField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslatableInputField.d.ts","sourceRoot":"","sources":["../../src/translations/TranslatableInputField.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,+FAA+F;AAC/F,eAAO,MAAM,sBAAsB,GAAI,wBAAwB,2BAA2B,gCAYzF,CAAC"}
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useFormContext } from 'react-hook-form';
4
+ import { useFieldLabel } from "../form/fieldLabels.js";
5
+ /** A text input for one language of a translatable property; the label comes from the form. */
6
+ export const TranslatableInputField = ({ name, languageCode }) => {
7
+ const label = useFieldLabel(name);
8
+ const { register } = useFormContext();
9
+ const inputId = `${name}-${languageCode}`;
10
+ return (_jsxs("div", { className: "flex flex-col gap-1", "data-slot": "translatable-input", children: [_jsxs("label", { htmlFor: inputId, className: "text-sm font-medium", children: [label, " ", _jsx("span", { className: "text-muted-foreground uppercase", children: languageCode })] }), _jsx("input", { id: inputId, className: "h-9 rounded-md border border-input px-3", ...register(`${name}.${languageCode}`) })] }));
11
+ };
12
+ //# sourceMappingURL=TranslatableInputField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslatableInputField.js","sourceRoot":"","sources":["../../src/translations/TranslatableInputField.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAyB,CAAC;AAQxD,+FAA+F;AAC/F,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,EAA+B,EAAE,EAAE;IAC5F,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IAC1C,OAAO,CACL,eAAK,SAAS,EAAC,qBAAqB,eAAW,oBAAoB,aACjE,iBAAO,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,qBAAqB,aACrD,KAAK,OAAE,eAAM,SAAS,EAAC,iCAAiC,YAAE,YAAY,GAAQ,IACzE,EACR,gBAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAC,yCAAyC,KAAK,QAAQ,CAAC,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC,GAAI,IAC/G,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TranslatableInputField, type TranslatableInputFieldProps } from './TranslatableInputField.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/translations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,2BAA2B,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TranslatableInputField } from "./TranslatableInputField.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/translations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAoC,MAAM,6BAA8B,CAAC"}
package/docs/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @mgamadeus/ddd-admin-ui — documentation
2
+
3
+ Skeleton. The chapters below are filled when the blocks arrive.
4
+
5
+ 1. **Concepts** — runtime layers (pure, react, browser, primitive, block, adapter) and the entries.
6
+ 2. **Host setup** — stylesheets, `tokens.json`, the layer scale, dark mode, the provider and its adapters.
7
+ 3. **Translations** — the store, `m()` on the server, `i18n-keys.json` and the host's translation export.
8
+ 4. **Primitives** — the component set and its overlay layers.
9
+ 5. **Blocks** — list, page, form, translations, media, glass, data.
10
+ 6. **Next adapters** — the URL write queue and URL state.
11
+ 7. **Standards** — rules every admin screen built on these blocks follows.
package/package.json CHANGED
@@ -1,6 +1,161 @@
1
1
  {
2
2
  "name": "@mgamadeus/ddd-admin-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-rc.1",
4
+ "description": "Admin UI building blocks for React 19 / Next 16 / Tailwind 4 apps built on the mgamadeus/ddd framework: pure helpers and React hooks, shadcn-style primitives, list, page, form, translation, media and glass blocks, Next adapters, a provider, two stylesheets and two JSON manifests.",
5
+ "keywords": [
6
+ "ddd",
7
+ "mgamadeus",
8
+ "admin",
9
+ "react",
10
+ "nextjs",
11
+ "tailwindcss",
12
+ "shadcn",
13
+ "radix-ui",
14
+ "ui-components"
15
+ ],
16
+ "homepage": "https://github.com/ddd-framework/ddd-admin-ui#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/ddd-framework/ddd-admin-ui/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ddd-framework/ddd-admin-ui.git"
23
+ },
24
+ "license": "MIT",
25
+ "type": "module",
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "exports": {
30
+ "./logic": {
31
+ "types": "./dist/logic/index.d.ts",
32
+ "import": "./dist/logic/index.js"
33
+ },
34
+ "./i18n": {
35
+ "types": "./dist/i18n/index.d.ts",
36
+ "import": "./dist/i18n/index.js"
37
+ },
38
+ "./primitives": {
39
+ "types": "./dist/primitives/index.d.ts",
40
+ "import": "./dist/primitives/index.js"
41
+ },
42
+ "./list": {
43
+ "types": "./dist/list/index.d.ts",
44
+ "import": "./dist/list/index.js"
45
+ },
46
+ "./page": {
47
+ "types": "./dist/page/index.d.ts",
48
+ "import": "./dist/page/index.js"
49
+ },
50
+ "./form": {
51
+ "types": "./dist/form/index.d.ts",
52
+ "import": "./dist/form/index.js"
53
+ },
54
+ "./translations": {
55
+ "types": "./dist/translations/index.d.ts",
56
+ "import": "./dist/translations/index.js"
57
+ },
58
+ "./media": {
59
+ "types": "./dist/media/index.d.ts",
60
+ "import": "./dist/media/index.js"
61
+ },
62
+ "./glass": {
63
+ "types": "./dist/glass/index.d.ts",
64
+ "import": "./dist/glass/index.js"
65
+ },
66
+ "./data": {
67
+ "types": "./dist/data/index.d.ts",
68
+ "import": "./dist/data/index.js"
69
+ },
70
+ "./next": {
71
+ "types": "./dist/next/index.d.ts",
72
+ "import": "./dist/next/index.js"
73
+ },
74
+ "./provider": {
75
+ "types": "./dist/provider/index.d.ts",
76
+ "import": "./dist/provider/index.js"
77
+ },
78
+ "./notify-sonner": {
79
+ "types": "./dist/notify-sonner/index.d.ts",
80
+ "import": "./dist/notify-sonner/index.js"
81
+ },
82
+ "./theme.css": "./dist/theme.css",
83
+ "./components.css": "./dist/components.css",
84
+ "./tokens.json": "./dist/tokens.json",
85
+ "./i18n-keys.json": "./dist/i18n-keys.json",
86
+ "./package.json": "./package.json"
87
+ },
88
+ "bin": {
89
+ "ddd-admin-ui": "./dist/cli/ddd-admin-ui.js"
90
+ },
91
+ "files": [
92
+ "dist",
93
+ "docs",
94
+ ".claude/skills",
95
+ "scripts/check-tokens.mjs",
96
+ "scripts/lib",
97
+ "README.md",
98
+ "CHANGELOG.md",
99
+ "LICENSE"
100
+ ],
101
+ "engines": {
102
+ "node": ">=20"
103
+ },
104
+ "publishConfig": {
105
+ "access": "public"
106
+ },
107
+ "dependencies": {
108
+ "class-variance-authority": "^0.7.1",
109
+ "clsx": "^2.1.1",
110
+ "cmdk": "^1.1.1",
111
+ "radix-ui": "^1.8.1",
112
+ "tailwind-merge": "^3.3.1"
113
+ },
114
+ "peerDependencies": {
115
+ "@mgamadeus/ddd-web": ">=0.13.0 <1.0.0",
116
+ "lucide-react": ">=0.550.0 <2",
117
+ "next": "^16.0.0",
118
+ "react": "^19.0.0",
119
+ "react-dom": "^19.0.0",
120
+ "react-hook-form": "^7.65.0",
121
+ "recharts": "^3.0.0",
122
+ "sonner": "^2.0.0",
123
+ "tailwindcss": "^4.1.0",
124
+ "zod": "^4.0.0"
125
+ },
126
+ "peerDependenciesMeta": {
127
+ "next": {
128
+ "optional": true
129
+ },
130
+ "recharts": {
131
+ "optional": true
132
+ },
133
+ "sonner": {
134
+ "optional": true
135
+ },
136
+ "tailwindcss": {
137
+ "optional": true
138
+ }
139
+ },
140
+ "devDependencies": {
141
+ "@mgamadeus/ddd-web": "^0.13.0",
142
+ "@types/node": "^24.0.0",
143
+ "@types/react": "^19.3.0",
144
+ "@types/react-dom": "^19.3.0",
145
+ "lucide-react": "^1.73.0",
146
+ "next": "^16.4.6",
147
+ "react": "^19.3.1",
148
+ "react-dom": "^19.3.1",
149
+ "react-hook-form": "^7.92.0",
150
+ "sonner": "^2.0.8",
151
+ "typescript": "^6.0.3",
152
+ "zod": "^4.6.7"
153
+ },
154
+ "scripts": {
155
+ "build": "node scripts/clean.mjs && tsc -p tsconfig.build.json && node scripts/rewrite-declaration-specifiers.mjs && node scripts/copy-assets.mjs",
156
+ "typecheck": "tsc -p .",
157
+ "test": "node --experimental-strip-types --no-warnings --test \"test/unit/**/*.test.ts\" \"test/check-package/**/*.test.ts\"",
158
+ "check-package": "node scripts/check-package.mjs .",
159
+ "i18n:manifest": "node scripts/build-i18n-manifest.mjs"
160
+ }
6
161
  }
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ // Checks a host's built CSS against this package (static; computed values are checked in a browser):
3
+ // a every class token in the package's dist (class-name literals) has a rule in the CSS
4
+ // b every colour and property of tokens.json is declared on :root and, when `themed`, under .dark
5
+ // c declared colour values parse as CSS colours (`0 0% 100%` without hsl() does not)
6
+ //
7
+ // Usage: node node_modules/@mgamadeus/ddd-admin-ui/scripts/check-tokens.mjs <built-css-file…> [--package <dir>]
8
+ // e.g. after `next build`: … check-tokens.mjs .next/static/css/*.css
9
+ // --package the installed package directory (default: the package this script belongs to)
10
+ import * as fs from 'node:fs';
11
+ import * as path from 'node:path';
12
+ import { fileURLToPath, pathToFileURL } from 'node:url';
13
+ import { classTokensOf, cssRules, customPropertyDeclarations, extractClassLiterals, listFiles, stripCssComments } from './lib/source-scan.mjs';
14
+
15
+ /** Class tokens that produce no rule of their own. */
16
+ const MARKER_CLASSES = /^(group|peer)(\/[\w-]+)?$/;
17
+
18
+ const NAMED_COLORS = new Set(
19
+ (
20
+ 'aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood ' +
21
+ 'cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray ' +
22
+ 'darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen ' +
23
+ 'darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue ' +
24
+ 'firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew ' +
25
+ 'hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan ' +
26
+ 'lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray ' +
27
+ 'lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue ' +
28
+ 'mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred ' +
29
+ 'midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid ' +
30
+ 'palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple ' +
31
+ 'rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue ' +
32
+ 'slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white ' +
33
+ 'whitesmoke yellow yellowgreen transparent currentcolor'
34
+ ).split(' '),
35
+ );
36
+ const COLOR_FUNCTION = /^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark|var)\(.*\)$/s;
37
+
38
+ /** Whether a declared value is a complete CSS colour. A `var(…)` reference is accepted (not resolvable statically). */
39
+ export function isCssColor(value) {
40
+ const normalized = value.trim().toLowerCase();
41
+ return (
42
+ /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(normalized) ||
43
+ NAMED_COLORS.has(normalized) ||
44
+ COLOR_FUNCTION.test(normalized)
45
+ );
46
+ }
47
+
48
+ /** The selector form of a class token, escaped as CSS does (`md:h-[1px]` → `md\:h-\[1px\]`). */
49
+ export const escapeClass = (token) => token.replace(/[^A-Za-z0-9_-]/g, (char) => `\\${char}`);
50
+
51
+ const hasRuleFor = (css, token) => {
52
+ const selector = `.${escapeClass(token)}`;
53
+ let index = css.indexOf(selector);
54
+ while (index !== -1) {
55
+ const next = css[index + selector.length];
56
+ if (next === undefined || !/[A-Za-z0-9_\\-]/.test(next)) return true;
57
+ index = css.indexOf(selector, index + 1);
58
+ }
59
+ return false;
60
+ };
61
+
62
+ /**
63
+ * @param {{ packageDir: string, cssFiles: string[] }} options
64
+ * @returns {{ check: 'a' | 'b' | 'c', message: string }[]}
65
+ */
66
+ export function checkTokens({ packageDir, cssFiles }) {
67
+ const problems = [];
68
+ const css = cssFiles.map((file) => stripCssComments(fs.readFileSync(file, 'utf-8'))).join('\n');
69
+ const dist = path.join(packageDir, 'dist');
70
+ const tokens = JSON.parse(fs.readFileSync(path.join(dist, 'tokens.json'), 'utf-8'));
71
+
72
+ // a — class tokens have rules
73
+ const classTokens = new Set();
74
+ for (const file of listFiles(dist).filter((name) => name.endsWith('.js'))) {
75
+ for (const token of classTokensOf(extractClassLiterals(fs.readFileSync(path.join(dist, file), 'utf-8')))) {
76
+ if (!MARKER_CLASSES.test(token)) classTokens.add(token);
77
+ }
78
+ }
79
+ for (const token of [...classTokens].sort()) {
80
+ if (!hasRuleFor(css, token)) problems.push({ check: 'a', message: `no rule for class '${token}'` });
81
+ }
82
+
83
+ // b, c — declarations on :root and .dark
84
+ const declared = { root: new Map(), dark: new Map() };
85
+ for (const rule of cssRules(css)) {
86
+ const selectors = rule.selector.split(',').map((selector) => selector.trim());
87
+ const scope = selectors.some((selector) => selector === ':root' || selector === 'html')
88
+ ? 'root'
89
+ : selectors.some((selector) => /(^|[\s>:(])\.dark(?![\w-])/.test(selector))
90
+ ? 'dark'
91
+ : null;
92
+ if (!scope) continue;
93
+ for (const [name, value] of customPropertyDeclarations(rule.body)) declared[scope].set(name, value);
94
+ }
95
+ const expected = [
96
+ ...Object.entries(tokens.colors ?? {}).map(([name, meta]) => ({ name: `--${name}`, themed: meta.themed, isColor: true })),
97
+ ...Object.entries(tokens.properties ?? {}).map(([name, meta]) => ({ name, themed: meta.themed, isColor: false })),
98
+ ];
99
+ for (const { name, themed, isColor } of expected) {
100
+ for (const scope of themed ? ['root', 'dark'] : ['root']) {
101
+ const value = declared[scope].get(name);
102
+ const where = scope === 'root' ? ':root' : '.dark';
103
+ if (value === undefined) problems.push({ check: 'b', message: `${name} is not declared on ${where}` });
104
+ else if (isColor && !isCssColor(value)) {
105
+ problems.push({ check: 'c', message: `${name} on ${where} is not a CSS colour: '${value}'` });
106
+ }
107
+ }
108
+ }
109
+ return problems;
110
+ }
111
+
112
+ // realpath: a package manager may run this file through a symlink (pnpm's node_modules layout)
113
+ const isMain =
114
+ process.argv[1] !== undefined && import.meta.url === pathToFileURL(fs.realpathSync(path.resolve(process.argv[1]))).href;
115
+ if (isMain) {
116
+ const args = process.argv.slice(2);
117
+ const packageIndex = args.indexOf('--package');
118
+ const packageDir =
119
+ packageIndex === -1
120
+ ? path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
121
+ : path.resolve(args[packageIndex + 1]);
122
+ const cssFiles = args.filter(
123
+ (arg, index) => !arg.startsWith('--') && (packageIndex === -1 || index !== packageIndex + 1),
124
+ );
125
+ if (cssFiles.length === 0) {
126
+ console.error('Usage: check-tokens.mjs <built-css-file…> [--package <dir>]');
127
+ process.exit(2);
128
+ }
129
+ const problems = checkTokens({ packageDir, cssFiles });
130
+ for (const problem of problems) console.error(`[${problem.check}] ${problem.message}`);
131
+ if (problems.length > 0) {
132
+ console.error(`check-tokens: ${problems.length} problem(s) in ${cssFiles.length} CSS file(s)`);
133
+ process.exit(1);
134
+ }
135
+ console.log(`check-tokens: ${cssFiles.length} CSS file(s) cover the package's classes and tokens`);
136
+ }
@@ -0,0 +1,91 @@
1
+ // Collects the translatable texts of the package source into the `i18n-keys.json` manifest.
2
+ // A host's translation export reads the manifest of every installed package, so block texts keep their translations.
3
+ import * as fs from 'node:fs';
4
+ import * as path from 'node:path';
5
+ import { listFiles } from './source-scan.mjs';
6
+
7
+ export const GENERATED_BY = 'scripts/build-i18n-manifest.mjs';
8
+ export const IGNORE_FILE_MARKER = '@translations-ignore-file';
9
+
10
+ const LITERAL = String.raw`'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|\x60(?:[^\x60\\$]|\\.)*\x60`;
11
+ /** `t('…')`, `translateText('…')`, `m('…')`, each with an optional second argument `{ context: '…' }`. */
12
+ const CALL = new RegExp(String.raw`(?<![\w$.])(?:t|translateText|m)\(\s*(${LITERAL})\s*(,\s*\{[^}]*\})?`, 'g');
13
+ const CONTEXT = new RegExp(String.raw`context\s*:\s*(${LITERAL})`);
14
+ /** `<Translate context="…">text</Translate>`. */
15
+ const ELEMENT = /<Translate\b([^>]*)>([^<{}]+)<\/Translate>/g;
16
+ const ELEMENT_CONTEXT = /context=(?:"([^"]*)"|'([^']*)'|\{\s*['"]([^'"]*)['"]\s*\})/;
17
+
18
+ const unquote = (literal) =>
19
+ literal
20
+ .slice(1, -1)
21
+ .replace(/\\n/g, '\n')
22
+ .replace(/\\(.)/g, '$1');
23
+
24
+ /** Same as `translationKeyOf` in `src/i18n/store.ts`. */
25
+ export const translationKeyOf = (text, context) => (context ? `${text}__${context}` : text);
26
+
27
+ const isSourceFile = (file) => /\.(ts|tsx)$/.test(file) && !/\.d\.ts$/.test(file) && !/\.(test|spec)\.tsx?$/.test(file);
28
+
29
+ /**
30
+ * Every translatable text of one source file.
31
+ *
32
+ * @returns {{ text: string, context?: string }[]}
33
+ */
34
+ export function extractTexts(source) {
35
+ if (source.includes(IGNORE_FILE_MARKER)) return [];
36
+ const texts = [];
37
+ for (const match of source.matchAll(CALL)) {
38
+ const context = match[2] ? CONTEXT.exec(match[2]) : null;
39
+ texts.push({ text: unquote(match[1]), ...(context ? { context: unquote(context[1]) } : {}) });
40
+ }
41
+ for (const match of source.matchAll(ELEMENT)) {
42
+ const context = ELEMENT_CONTEXT.exec(match[1]);
43
+ const contextValue = context ? (context[1] ?? context[2] ?? context[3]) : undefined;
44
+ texts.push({ text: match[2].replace(/\s+/g, ' ').trim(), ...(contextValue ? { context: contextValue } : {}) });
45
+ }
46
+ return texts;
47
+ }
48
+
49
+ /**
50
+ * The manifest of a source tree.
51
+ *
52
+ * @param {{ sourceDir: string, hintsFile: string, packageName: string, version: string }} options
53
+ * @returns {{ manifest: object, missingHints: string[] }}
54
+ */
55
+ export function buildI18nManifest({ sourceDir, hintsFile, packageName, version }) {
56
+ const hints = fs.existsSync(hintsFile) ? JSON.parse(fs.readFileSync(hintsFile, 'utf-8')) : {};
57
+ /** @type {Map<string, { key: string, text: string, context?: string, files: Set<string> }>} */
58
+ const byKey = new Map();
59
+ for (const file of listFiles(sourceDir).filter(isSourceFile)) {
60
+ const source = fs.readFileSync(path.join(sourceDir, file), 'utf-8');
61
+ for (const { text, context } of extractTexts(source)) {
62
+ const key = translationKeyOf(text, context);
63
+ const entry = byKey.get(key) ?? { key, text, ...(context ? { context } : {}), files: new Set() };
64
+ entry.files.add(file);
65
+ byKey.set(key, entry);
66
+ }
67
+ }
68
+ const missingHints = [];
69
+ const keys = [...byKey.values()]
70
+ .sort((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0))
71
+ .map(({ key, text, context, files }) => {
72
+ const hint = typeof hints[key] === 'string' ? hints[key] : '';
73
+ if (hint === '') missingHints.push(key);
74
+ return { key, text, ...(context ? { context } : {}), hint, files: [...files].sort() };
75
+ });
76
+ return { manifest: { package: packageName, version, generatedBy: GENERATED_BY, keys }, missingHints };
77
+ }
78
+
79
+ /** The manifest as written to disk. */
80
+ export const serializeManifest = (manifest) => `${JSON.stringify(manifest, null, 2)}\n`;
81
+
82
+ /** Builds the manifest of a repository root (`src/`, `i18n/hints.json`, `package.json`). */
83
+ export function buildI18nManifestForRoot(rootDir, sourceDir = path.join(rootDir, 'src')) {
84
+ const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf-8'));
85
+ return buildI18nManifest({
86
+ sourceDir,
87
+ hintsFile: path.join(rootDir, 'i18n', 'hints.json'),
88
+ packageName: packageJson.name,
89
+ version: packageJson.version,
90
+ });
91
+ }