@prunellejs/ui 0.0.0-stage → 0.7.2

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +78 -0
  3. package/package.json +32 -4
  4. package/src/CommandPalette.tsx +262 -0
  5. package/src/DataTable.tsx +244 -0
  6. package/src/Dialog.tsx +181 -0
  7. package/src/Drawer.tsx +4 -0
  8. package/src/Menu.tsx +117 -0
  9. package/src/Select.tsx +125 -0
  10. package/src/Tabs.tsx +64 -0
  11. package/src/Toaster.tsx +105 -0
  12. package/src/behaviors.ts +385 -0
  13. package/src/field-context.ts +21 -0
  14. package/src/fold.ts +7 -0
  15. package/src/index.ts +72 -0
  16. package/src/labels/dialog.ts +3 -0
  17. package/src/labels/fr/dialog.ts +3 -0
  18. package/src/labels/fr/palette.ts +8 -0
  19. package/src/labels/fr/select.ts +1 -0
  20. package/src/labels/fr/table.ts +13 -0
  21. package/src/labels/fr/toaster.ts +1 -0
  22. package/src/labels/palette.ts +8 -0
  23. package/src/labels/select.ts +1 -0
  24. package/src/labels/table.ts +13 -0
  25. package/src/labels/toaster.ts +1 -0
  26. package/src/platform-fallback.ts +36 -0
  27. package/src/plugin.ts +188 -0
  28. package/src/primitives.tsx +238 -0
  29. package/src/static.tsx +324 -0
  30. package/src/styles/bare.css +25 -0
  31. package/src/styles/base.css +61 -0
  32. package/src/styles/components/accordion.css +10 -0
  33. package/src/styles/components/badge.css +6 -0
  34. package/src/styles/components/button.css +11 -0
  35. package/src/styles/components/card.css +5 -0
  36. package/src/styles/components/checkbox.css +11 -0
  37. package/src/styles/components/command.css +25 -0
  38. package/src/styles/components/consent.css +38 -0
  39. package/src/styles/components/datatable.css +9 -0
  40. package/src/styles/components/dialog.css +16 -0
  41. package/src/styles/components/drawer.css +29 -0
  42. package/src/styles/components/field.css +8 -0
  43. package/src/styles/components/layout.css +69 -0
  44. package/src/styles/components/menu.css +21 -0
  45. package/src/styles/components/notice.css +5 -0
  46. package/src/styles/components/popover.css +8 -0
  47. package/src/styles/components/progress.css +14 -0
  48. package/src/styles/components/radio-group.css +11 -0
  49. package/src/styles/components/select.css +25 -0
  50. package/src/styles/components/switch.css +42 -0
  51. package/src/styles/components/tabs.css +4 -0
  52. package/src/styles/components/toast.css +28 -0
  53. package/src/styles/grammars/console.css +179 -0
  54. package/src/styles/grammars/editorial.css +164 -0
  55. package/src/styles/grammars/orbit.css +269 -0
  56. package/src/styles/grammars/prunelle.css +504 -0
  57. package/src/styles/grammars/soft.css +160 -0
  58. package/src/styles/grammars/workshop.css +172 -0
  59. package/src/styles/scan.ts +144 -0
  60. package/src/styles/split.ts +429 -0
  61. package/src/styles/theme.css +22 -0
  62. package/src/styles/themed/accordion.css +20 -0
  63. package/src/styles/themed/badge.css +20 -0
  64. package/src/styles/themed/button.css +24 -0
  65. package/src/styles/themed/card.css +23 -0
  66. package/src/styles/themed/checkbox.css +4 -0
  67. package/src/styles/themed/command.css +33 -0
  68. package/src/styles/themed/consent.css +33 -0
  69. package/src/styles/themed/datatable.css +28 -0
  70. package/src/styles/themed/dialog.css +13 -0
  71. package/src/styles/themed/drawer.css +13 -0
  72. package/src/styles/themed/field.css +22 -0
  73. package/src/styles/themed/menu.css +21 -0
  74. package/src/styles/themed/notice.css +17 -0
  75. package/src/styles/themed/popover.css +11 -0
  76. package/src/styles/themed/radio-group.css +12 -0
  77. package/src/styles/themed/select.css +32 -0
  78. package/src/styles/themed/switch.css +23 -0
  79. package/src/styles/themed/tabs.css +20 -0
  80. package/src/styles/themed/toast.css +18 -0
  81. package/src/table-state.ts +163 -0
  82. package/src/tabs-state.ts +39 -0
  83. package/src/toast.ts +110 -0
  84. package/README.md +0 -3
@@ -0,0 +1,172 @@
1
+ /* Grammar: Workshop — tactile 2px ink frames, hard unblurred offset shadows, physical press travel.
2
+ * Inspired by print & craft studios (like jb-peinture). Eject via `prunelle ui-eject workshop`. */
3
+
4
+ @import '../theme.css';
5
+
6
+ @layer kui {
7
+ :root {
8
+ color-scheme: light dark;
9
+ --ui-paper: light-dark(#f1eadc, #181512);
10
+ --ui-surface: light-dark(#fbf7ef, #231f1a);
11
+ --ui-ink: light-dark(#2a231b, #f3ece0);
12
+ --ui-muted: light-dark(#6c6152, #a89d8c);
13
+ --ui-line: light-dark(#2a231b, #e8dfd0);
14
+ --ui-shadow-color: light-dark(#ded4c1, #0b0907);
15
+ --ui-accent: light-dark(#b2492c, #e37455);
16
+ --ui-on-accent: light-dark(#ffffff, #181512);
17
+ --ui-success: light-dark(#31692d, #7ac074);
18
+ --ui-warning: light-dark(#855700, #eab354);
19
+ --ui-danger: light-dark(#b0322a, #f0756b);
20
+ --ui-font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
21
+ --ui-font-display: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
22
+ --ui-radius: 2px;
23
+ --ui-border-w: 2px;
24
+ --ui-shadow: 5px 5px 0 var(--ui-shadow-color);
25
+ --ui-press-shadow: 3px 3px 0 var(--ui-line);
26
+ --ui-motion: 120ms;
27
+ }
28
+
29
+ [data-ui="button"] {
30
+ --ui-btn-f: 700 0.88rem/1 var(--ui-font-body);
31
+ --ui-btn-pad: 0.7rem 1.25rem;
32
+ --ui-btn-bd: var(--ui-border-w) solid var(--ui-line);
33
+ letter-spacing: 0.04em;
34
+ text-transform: uppercase;
35
+ box-shadow: var(--ui-press-shadow);
36
+ &:hover:not(:disabled, [aria-disabled="true"]) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ui-line); }
37
+ &:active:not(:disabled, [aria-disabled="true"]) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ui-line); }
38
+ &[data-tone="accent"], &[data-tone="danger"], &[data-variant="outline"] { border-color: var(--ui-line); }
39
+ &[data-variant="ghost"]:hover:not(:disabled, [aria-disabled="true"]) { border-color: var(--ui-line); transform: none; box-shadow: none; }
40
+ }
41
+
42
+ [data-ui="card"] {
43
+ --ui-card-bd: var(--ui-border-w) solid var(--ui-line);
44
+ --ui-card-pad: 1.25rem;
45
+ --ui-card-hf: 800 1.1rem/1.3 var(--ui-font-display);
46
+ --ui-card-hpb: 0.75rem;
47
+ --ui-card-hmb: 0.75rem;
48
+ --ui-card-hbd: var(--ui-border-w) solid var(--ui-line);
49
+ --ui-card-fpt: 0.75rem;
50
+ --ui-card-fbd: var(--ui-border-w) solid var(--ui-line);
51
+ box-shadow: var(--ui-shadow);
52
+ }
53
+
54
+ [data-ui="badge"] {
55
+ --ui-badge-f: 700 0.74rem/1 var(--ui-font-body);
56
+ --ui-badge-pad: 0.3rem 0.65rem;
57
+ --ui-badge-bd: var(--ui-border-w) solid var(--ui-line);
58
+ --ui-badge-bg: var(--ui-surface);
59
+ --ui-badge-fg: var(--ui-ink);
60
+ --ui-badge-tbg: 100%;
61
+ --ui-badge-tfg: var(--ui-on-accent);
62
+ --ui-badge-tbd: 0%;
63
+ --ui-badge-tbd0: var(--ui-line);
64
+ letter-spacing: 0.08em;
65
+ text-transform: uppercase;
66
+ }
67
+
68
+ [data-ui="notice"] {
69
+ --ui-notice-bw: var(--ui-border-w);
70
+ --ui-notice-pad: 0.9rem 1.1rem;
71
+ box-shadow: 4px 4px 0 var(--ui-shadow-color);
72
+ &[data-tone] { border-color: var(--ui-tone); }
73
+ }
74
+
75
+ [data-ui="field"] {
76
+ --ui-fld-lf: 700 0.82rem/1.2 var(--ui-font-body);
77
+ --ui-in-f: 500 0.95rem/1.4 var(--ui-font-body);
78
+ --ui-in-bd: var(--ui-border-w) solid var(--ui-line);
79
+ --ui-in-pad: 0.6rem 0.85rem;
80
+ & [data-part="label"] { text-transform: uppercase; letter-spacing: 0.06em; }
81
+ & [data-part="error"] { font-weight: 600; }
82
+ }
83
+
84
+ [data-ui="accordion"] {
85
+ --ui-acc-bd: var(--ui-border-w) solid var(--ui-line);
86
+ --ui-acc-bg: var(--ui-surface);
87
+ --ui-acc-gap: calc(-1 * var(--ui-border-w));
88
+ --ui-acc-tpad: 0.85rem 1rem;
89
+ --ui-acc-tf: 700 1rem/1.3 var(--ui-font-body);
90
+ --ui-acc-m: '▸';
91
+ --ui-acc-mo: '▾';
92
+ --ui-acc-cpad: 0 1rem 1rem;
93
+ }
94
+
95
+ [data-ui="tabs"] {
96
+ --ui-tab-disp: inline-flex;
97
+ --ui-tab-gap: 0;
98
+ --ui-tab-pad: 0.55rem 1rem;
99
+ --ui-tab-f: 700 0.82rem/1 var(--ui-font-body);
100
+ --ui-tab-fg: var(--ui-ink);
101
+ --ui-tab-abg: var(--ui-accent);
102
+ --ui-tab-afg: var(--ui-on-accent);
103
+ --ui-tab-aind: none;
104
+ & [data-part="list"] { border: var(--ui-border-w) solid var(--ui-line); background: var(--ui-paper); }
105
+ & [data-part="trigger"] { border-right: var(--ui-border-w) solid var(--ui-line); text-transform: uppercase; &:last-child { border-right: 0; } }
106
+ }
107
+
108
+ dialog[data-ui="dialog"],
109
+ dialog[data-ui="drawer"],
110
+ dialog[data-ui="command"] {
111
+ --ui-dlg-bd: var(--ui-border-w) solid var(--ui-line);
112
+ --ui-dlg-sh: 8px 8px 0 var(--ui-line);
113
+ --ui-dlg-tf: 800 1.25rem/1.25 var(--ui-font-display);
114
+ }
115
+
116
+ [data-ui="popover"],
117
+ [data-ui="menu"],
118
+ [data-ui="select"] {
119
+ --ui-pop-bd: var(--ui-border-w) solid var(--ui-line);
120
+ --ui-pop-sh: var(--ui-shadow);
121
+ --ui-it-f: 600 0.88rem/1.3 var(--ui-font-body);
122
+ --ui-it-hbg: var(--ui-paper);
123
+ }
124
+
125
+ [data-ui="select"] {
126
+ --ui-sel-bd: var(--ui-border-w) solid var(--ui-line);
127
+ --ui-sel-pad: 0.55rem 0.85rem;
128
+ --ui-sel-f: 600 0.9rem/1.3 var(--ui-font-body);
129
+ & [data-part="trigger"] { box-shadow: var(--ui-press-shadow); }
130
+ & [data-part="option"][data-selected="true"] { background: var(--ui-accent); color: var(--ui-on-accent); }
131
+ }
132
+
133
+ [data-ui="toast"] {
134
+ --ui-tst-bw: var(--ui-border-w);
135
+ --ui-tst-sh: var(--ui-shadow);
136
+ --ui-tst-pad: 0.8rem 1rem;
137
+ &[data-tone] { border-color: var(--ui-tone); }
138
+ }
139
+
140
+ [data-ui="switch"] {
141
+ --ui-sw-bd: var(--ui-border-w) solid var(--ui-line);
142
+ --ui-sw-bg: var(--ui-surface);
143
+ --ui-sw-th: var(--ui-line);
144
+ --ui-sw-onbd: var(--ui-line);
145
+ }
146
+
147
+ [data-ui="radio-group"] {
148
+ --ui-rg-lf: 800 0.82rem/1.2 var(--ui-font-body);
149
+ --ui-rg-lc: uppercase;
150
+ --ui-rg-lfg: var(--ui-ink);
151
+ }
152
+
153
+ dialog[data-ui="command"] {
154
+ --ui-cmd-ibb: var(--ui-border-w) solid var(--ui-line);
155
+ --ui-cmd-ibg: var(--ui-paper);
156
+ --ui-cmd-if: 600 0.95rem/1.3 var(--ui-font-body);
157
+ --ui-cmd-mf: 600 0.9rem/1.3 var(--ui-font-body);
158
+ --ui-cmd-hbg: var(--ui-accent);
159
+ --ui-cmd-hfg: var(--ui-on-accent);
160
+ & [data-part="kbd"] { color: currentColor; border: var(--ui-border-w) solid currentColor; font-weight: 700; }
161
+ }
162
+
163
+ [data-ui="datatable"] {
164
+ --ui-srch-bd: var(--ui-border-w) solid var(--ui-line);
165
+ --ui-tbl-bd: var(--ui-border-w) solid var(--ui-line);
166
+ --ui-tbl-bg: var(--ui-surface);
167
+ --ui-th-bb: var(--ui-border-w) solid var(--ui-line);
168
+ --ui-tbl-sel: color-mix(in srgb, var(--ui-accent) 16%, var(--ui-surface));
169
+ & table { box-shadow: var(--ui-shadow); }
170
+ & th { background: var(--ui-paper); text-transform: uppercase; font-weight: 800; }
171
+ }
172
+ }
@@ -0,0 +1,144 @@
1
+ // Static scanner detecting which `@prunellejs/ui` component parts a set of source files renders.
2
+ // Checks both named imports from `@prunellejs/ui` and literal `data-ui="..."` / `data-layout="..."` attributes.
3
+
4
+ import type { UiComponentPart } from './split'
5
+ import { existsSync, readFileSync } from 'node:fs'
6
+ import { resolve } from 'node:path'
7
+ import { UI_COMPONENT_PARTS, UI_EXPORT_TO_PARTS } from './split'
8
+
9
+ const PART_SET = new Set<string>(UI_COMPONENT_PARTS)
10
+ const UI_SRC_DIR = resolve(import.meta.dir, '..')
11
+
12
+ const IMPORT_STMT_RE = /import\s+(?!type\b)([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g
13
+ const NAMED_LIST_RE = /\{([\s\S]*?)\}/
14
+ const NAMESPACE_RE = /\*\s+as\s+[A-Za-z_$]/
15
+ const DATA_UI_ATTR_RE = /\bdata-ui\s*=\s*(?:["']([^"']+)["']|\{([^}]*)\})/g
16
+ const DATA_LAYOUT_ATTR_RE = /\bdata-layout\s*=/
17
+ const STATIC_QUOTED_RE = /^\s*["']([^"']+)["']\s*$/
18
+
19
+ const DATA_UI_ALIASES: Readonly<Record<string, readonly UiComponentPart[]>> = {
20
+ 'table': ['datatable'],
21
+ 'toaster': ['toast'],
22
+ 'dialog-root': ['dialog', 'button', 'layout'],
23
+ 'drawer-root': ['drawer', 'button', 'layout'],
24
+ 'command-root': ['command', 'button'],
25
+ }
26
+
27
+ // prunelle's own components that render `data-ui` markup styled here.
28
+ const PRUNELLE_EXPORT_TO_PARTS: Readonly<Record<string, readonly UiComponentPart[]>> = {
29
+ ConsentBanner: ['consent', 'button'],
30
+ ConsentPreferences: ['consent', 'button'],
31
+ }
32
+
33
+ function isUiImportSource(specifier: string): boolean {
34
+ if (specifier === '@prunellejs/ui')
35
+ return true
36
+ // Tests and monorepo apps may import the workspace package entry directly.
37
+ return specifier.endsWith('/packages/ui/src/index.ts') || specifier.endsWith('/packages/ui/src/index')
38
+ }
39
+
40
+ function isInsideUiPackage(file: string): boolean {
41
+ const norm = file.replace(/\\/g, '/')
42
+ return norm.startsWith(`${UI_SRC_DIR.replace(/\\/g, '/')}/`)
43
+ || norm.includes('/node_modules/@prunellejs/ui/')
44
+ }
45
+
46
+ function addPartForAttr(value: string, out: Set<UiComponentPart>): void {
47
+ const aliased = DATA_UI_ALIASES[value]
48
+ if (aliased !== undefined) {
49
+ for (const p of aliased)
50
+ out.add(p)
51
+ return
52
+ }
53
+ if (PART_SET.has(value))
54
+ out.add(value as UiComponentPart)
55
+ }
56
+
57
+ export interface FileUiScan {
58
+ parts: readonly UiComponentPart[]
59
+ all: boolean
60
+ }
61
+
62
+ function scanSingleFile(file: string): FileUiScan {
63
+ if (isInsideUiPackage(file) || !existsSync(file))
64
+ return { parts: [], all: false }
65
+
66
+ const code = readFileSync(file, 'utf8')
67
+ const parts = new Set<UiComponentPart>()
68
+ let all = false
69
+
70
+ for (const match of code.matchAll(IMPORT_STMT_RE)) {
71
+ const clause = match[1]!
72
+ const source = match[2]!
73
+ const fromPrunelle = source === 'prunelle'
74
+ if (!fromPrunelle && !isUiImportSource(source))
75
+ continue
76
+ if (!fromPrunelle && NAMESPACE_RE.test(clause)) {
77
+ all = true
78
+ break
79
+ }
80
+ const named = NAMED_LIST_RE.exec(clause)
81
+ if (named !== null) {
82
+ for (const rawSpec of named[1]!.split(',')) {
83
+ const spec = rawSpec.trim()
84
+ if (spec === '' || spec.startsWith('type '))
85
+ continue
86
+ const imported = spec.split(/\s+as\s+/)[0]!.trim()
87
+ const mapped = (fromPrunelle ? PRUNELLE_EXPORT_TO_PARTS : UI_EXPORT_TO_PARTS)[imported]
88
+ if (mapped !== undefined) {
89
+ for (const p of mapped)
90
+ parts.add(p)
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ if (!all) {
97
+ if (DATA_LAYOUT_ATTR_RE.test(code))
98
+ parts.add('layout')
99
+ for (const match of code.matchAll(DATA_UI_ATTR_RE)) {
100
+ const literal = match[1]
101
+ if (literal !== undefined) {
102
+ addPartForAttr(literal, parts)
103
+ continue
104
+ }
105
+ const expr = match[2] ?? ''
106
+ const staticMatch = STATIC_QUOTED_RE.exec(expr)
107
+ if (staticMatch !== null) {
108
+ addPartForAttr(staticMatch[1]!, parts)
109
+ }
110
+ else {
111
+ all = true
112
+ break
113
+ }
114
+ }
115
+ }
116
+
117
+ return all
118
+ ? { parts: UI_COMPONENT_PARTS, all: true }
119
+ : { parts: [...parts], all: false }
120
+ }
121
+
122
+ /** Creates a per-build cached scanner resolving the set of `@prunellejs/ui` component parts used by a list of source files. */
123
+ export function createUiPartScanner(): (files: readonly string[]) => Set<UiComponentPart> {
124
+ const cache = new Map<string, FileUiScan>()
125
+ const scan = (file: string): FileUiScan => {
126
+ let entry = cache.get(file)
127
+ if (entry === undefined) {
128
+ entry = scanSingleFile(file)
129
+ cache.set(file, entry)
130
+ }
131
+ return entry
132
+ }
133
+ return (files: readonly string[]): Set<UiComponentPart> => {
134
+ const out = new Set<UiComponentPart>()
135
+ for (const file of files) {
136
+ const res = scan(file)
137
+ if (res.all)
138
+ return new Set(UI_COMPONENT_PARTS)
139
+ for (const p of res.parts)
140
+ out.add(p)
141
+ }
142
+ return out
143
+ }
144
+ }