@loccal/ui 0.0.0-stage → 0.3.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 (254) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +21 -0
  3. package/README.md +38 -3
  4. package/dist/components/ui/accordion.d.ts +6 -0
  5. package/dist/components/ui/accordion.js +17 -0
  6. package/dist/components/ui/ai-panel.d.ts +47 -0
  7. package/dist/components/ui/ai-panel.js +74 -0
  8. package/dist/components/ui/alert-dialog.d.ts +18 -0
  9. package/dist/components/ui/alert-dialog.js +42 -0
  10. package/dist/components/ui/alert.d.ts +10 -0
  11. package/dist/components/ui/alert.js +27 -0
  12. package/dist/components/ui/avatar.d.ts +11 -0
  13. package/dist/components/ui/avatar.js +23 -0
  14. package/dist/components/ui/badge.d.ts +7 -0
  15. package/dist/components/ui/badge.js +36 -0
  16. package/dist/components/ui/breadcrumb.d.ts +10 -0
  17. package/dist/components/ui/breadcrumb.js +36 -0
  18. package/dist/components/ui/button-group.d.ts +10 -0
  19. package/dist/components/ui/button-group.js +36 -0
  20. package/dist/components/ui/button.d.ts +8 -0
  21. package/dist/components/ui/button.js +34 -0
  22. package/dist/components/ui/calendar.d.ts +10 -0
  23. package/dist/components/ui/calendar.js +76 -0
  24. package/dist/components/ui/card.d.ts +11 -0
  25. package/dist/components/ui/card.js +24 -0
  26. package/dist/components/ui/chart.d.ts +44 -0
  27. package/dist/components/ui/chart.js +132 -0
  28. package/dist/components/ui/checkbox.d.ts +3 -0
  29. package/dist/components/ui/checkbox.js +9 -0
  30. package/dist/components/ui/code-view.d.ts +31 -0
  31. package/dist/components/ui/code-view.js +62 -0
  32. package/dist/components/ui/collapsible.d.ts +5 -0
  33. package/dist/components/ui/collapsible.js +13 -0
  34. package/dist/components/ui/command-block.d.ts +28 -0
  35. package/dist/components/ui/command-block.js +58 -0
  36. package/dist/components/ui/command.d.ts +19 -0
  37. package/dist/components/ui/command.js +35 -0
  38. package/dist/components/ui/connection-status.d.ts +29 -0
  39. package/dist/components/ui/connection-status.js +26 -0
  40. package/dist/components/ui/context-menu.d.ts +29 -0
  41. package/dist/components/ui/context-menu.js +51 -0
  42. package/dist/components/ui/data-table.d.ts +49 -0
  43. package/dist/components/ui/data-table.js +100 -0
  44. package/dist/components/ui/dialog.d.ts +18 -0
  45. package/dist/components/ui/dialog.js +37 -0
  46. package/dist/components/ui/drawer.d.ts +16 -0
  47. package/dist/components/ui/drawer.js +75 -0
  48. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  49. package/dist/components/ui/dropdown-menu.js +51 -0
  50. package/dist/components/ui/dropzone.d.ts +11 -0
  51. package/dist/components/ui/dropzone.js +39 -0
  52. package/dist/components/ui/empty.d.ts +11 -0
  53. package/dist/components/ui/empty.js +33 -0
  54. package/dist/components/ui/field.d.ts +24 -0
  55. package/dist/components/ui/field.js +68 -0
  56. package/dist/components/ui/file-tree.d.ts +42 -0
  57. package/dist/components/ui/file-tree.js +88 -0
  58. package/dist/components/ui/file-type-icon.d.ts +16 -0
  59. package/dist/components/ui/file-type-icon.js +19 -0
  60. package/dist/components/ui/hash-chain.d.ts +43 -0
  61. package/dist/components/ui/hash-chain.js +34 -0
  62. package/dist/components/ui/history-palette.d.ts +37 -0
  63. package/dist/components/ui/history-palette.js +44 -0
  64. package/dist/components/ui/hover-card.d.ts +5 -0
  65. package/dist/components/ui/hover-card.js +14 -0
  66. package/dist/components/ui/icon-base.d.ts +15 -0
  67. package/dist/components/ui/icon-base.js +18 -0
  68. package/dist/components/ui/icon.d.ts +15 -0
  69. package/dist/components/ui/icon.js +32 -0
  70. package/dist/components/ui/icons-compat.d.ts +32 -0
  71. package/dist/components/ui/icons-compat.js +34 -0
  72. package/dist/components/ui/icons.d.ts +1048 -0
  73. package/dist/components/ui/icons.js +264 -0
  74. package/dist/components/ui/input-group.d.ts +18 -0
  75. package/dist/components/ui/input-group.js +57 -0
  76. package/dist/components/ui/input-otp.d.ts +11 -0
  77. package/dist/components/ui/input-otp.js +21 -0
  78. package/dist/components/ui/input.d.ts +3 -0
  79. package/dist/components/ui/input.js +7 -0
  80. package/dist/components/ui/kbd.d.ts +3 -0
  81. package/dist/components/ui/kbd.js +9 -0
  82. package/dist/components/ui/label.d.ts +3 -0
  83. package/dist/components/ui/label.js +7 -0
  84. package/dist/components/ui/locale-switch.d.ts +9 -0
  85. package/dist/components/ui/locale-switch.js +31 -0
  86. package/dist/components/ui/log-panel.d.ts +28 -0
  87. package/dist/components/ui/log-panel.js +59 -0
  88. package/dist/components/ui/menubar.d.ts +29 -0
  89. package/dist/components/ui/menubar.js +56 -0
  90. package/dist/components/ui/metric-grid.d.ts +20 -0
  91. package/dist/components/ui/metric-grid.js +14 -0
  92. package/dist/components/ui/model-list.d.ts +33 -0
  93. package/dist/components/ui/model-list.js +69 -0
  94. package/dist/components/ui/navigation-menu.d.ts +11 -0
  95. package/dist/components/ui/navigation-menu.js +31 -0
  96. package/dist/components/ui/number-field.d.ts +29 -0
  97. package/dist/components/ui/number-field.js +65 -0
  98. package/dist/components/ui/pagination.d.ts +17 -0
  99. package/dist/components/ui/pagination.js +26 -0
  100. package/dist/components/ui/pane-tree.d.ts +18 -0
  101. package/dist/components/ui/pane-tree.js +65 -0
  102. package/dist/components/ui/popover.d.ts +9 -0
  103. package/dist/components/ui/popover.js +23 -0
  104. package/dist/components/ui/progress.d.ts +7 -0
  105. package/dist/components/ui/progress.js +20 -0
  106. package/dist/components/ui/radio-group.d.ts +5 -0
  107. package/dist/components/ui/radio-group.js +12 -0
  108. package/dist/components/ui/resizable.d.ts +7 -0
  109. package/dist/components/ui/resizable.js +14 -0
  110. package/dist/components/ui/scroll-area.d.ts +5 -0
  111. package/dist/components/ui/scroll-area.js +11 -0
  112. package/dist/components/ui/select.d.ts +15 -0
  113. package/dist/components/ui/select.js +34 -0
  114. package/dist/components/ui/separator.d.ts +3 -0
  115. package/dist/components/ui/separator.js +8 -0
  116. package/dist/components/ui/settings-layout.d.ts +31 -0
  117. package/dist/components/ui/settings-layout.js +45 -0
  118. package/dist/components/ui/sheet.d.ts +14 -0
  119. package/dist/components/ui/sheet.js +37 -0
  120. package/dist/components/ui/shell-picker.d.ts +18 -0
  121. package/dist/components/ui/shell-picker.js +17 -0
  122. package/dist/components/ui/skeleton.d.ts +2 -0
  123. package/dist/components/ui/skeleton.js +6 -0
  124. package/dist/components/ui/slider.d.ts +3 -0
  125. package/dist/components/ui/slider.js +12 -0
  126. package/dist/components/ui/sonner.d.ts +3 -0
  127. package/dist/components/ui/sonner.js +25 -0
  128. package/dist/components/ui/spinner.d.ts +2 -0
  129. package/dist/components/ui/spinner.js +7 -0
  130. package/dist/components/ui/split-button.d.ts +21 -0
  131. package/dist/components/ui/split-button.js +14 -0
  132. package/dist/components/ui/stat.d.ts +10 -0
  133. package/dist/components/ui/stat.js +8 -0
  134. package/dist/components/ui/status-bar.d.ts +13 -0
  135. package/dist/components/ui/status-bar.js +15 -0
  136. package/dist/components/ui/stepper.d.ts +13 -0
  137. package/dist/components/ui/stepper.js +11 -0
  138. package/dist/components/ui/switch.d.ts +5 -0
  139. package/dist/components/ui/switch.js +8 -0
  140. package/dist/components/ui/table.d.ts +10 -0
  141. package/dist/components/ui/table.js +28 -0
  142. package/dist/components/ui/tabs.d.ts +10 -0
  143. package/dist/components/ui/tabs.js +29 -0
  144. package/dist/components/ui/terminal-tabs.d.ts +31 -0
  145. package/dist/components/ui/terminal-tabs.js +109 -0
  146. package/dist/components/ui/terminal-view.d.ts +51 -0
  147. package/dist/components/ui/terminal-view.js +189 -0
  148. package/dist/components/ui/textarea.d.ts +3 -0
  149. package/dist/components/ui/textarea.js +6 -0
  150. package/dist/components/ui/timeline.d.ts +9 -0
  151. package/dist/components/ui/timeline.js +18 -0
  152. package/dist/components/ui/toggle-group.d.ts +11 -0
  153. package/dist/components/ui/toggle-group.js +24 -0
  154. package/dist/components/ui/toggle.d.ts +8 -0
  155. package/dist/components/ui/toggle.js +26 -0
  156. package/dist/components/ui/tooltip.d.ts +6 -0
  157. package/dist/components/ui/tooltip.js +17 -0
  158. package/dist/components/ui/tree-view.d.ts +20 -0
  159. package/dist/components/ui/tree-view.js +41 -0
  160. package/dist/components/ui/window-frame.d.ts +35 -0
  161. package/dist/components/ui/window-frame.js +49 -0
  162. package/dist/lib/ai-markdown.d.ts +13 -0
  163. package/dist/lib/ai-markdown.js +46 -0
  164. package/dist/lib/command-risk.d.ts +6 -0
  165. package/dist/lib/command-risk.js +42 -0
  166. package/dist/lib/file-icons.d.ts +18 -0
  167. package/dist/lib/file-icons.js +136 -0
  168. package/dist/lib/file-kind.d.ts +10 -0
  169. package/dist/lib/file-kind.js +63 -0
  170. package/dist/lib/format.d.ts +9 -0
  171. package/dist/lib/format.js +30 -0
  172. package/dist/lib/i18n-core.d.ts +20 -0
  173. package/dist/lib/i18n-core.js +36 -0
  174. package/dist/lib/i18n.d.ts +15 -0
  175. package/dist/lib/i18n.js +68 -0
  176. package/dist/lib/icon-data.d.ts +276 -0
  177. package/dist/lib/icon-data.js +307 -0
  178. package/dist/lib/icon-shapes.d.ts +14 -0
  179. package/dist/lib/icon-shapes.js +47 -0
  180. package/dist/lib/log-filter.d.ts +23 -0
  181. package/dist/lib/log-filter.js +44 -0
  182. package/dist/lib/number-field.d.ts +11 -0
  183. package/dist/lib/number-field.js +30 -0
  184. package/dist/lib/pane-tree.d.ts +39 -0
  185. package/dist/lib/pane-tree.js +92 -0
  186. package/dist/lib/platform.d.ts +10 -0
  187. package/dist/lib/platform.js +24 -0
  188. package/dist/lib/shell-meta.d.ts +7 -0
  189. package/dist/lib/shell-meta.js +70 -0
  190. package/dist/lib/syntax.d.ts +16 -0
  191. package/dist/lib/syntax.js +540 -0
  192. package/dist/lib/tab-order.d.ts +6 -0
  193. package/dist/lib/tab-order.js +24 -0
  194. package/dist/lib/table-sort.d.ts +16 -0
  195. package/dist/lib/table-sort.js +66 -0
  196. package/dist/lib/terminal-themes.d.ts +30 -0
  197. package/dist/lib/terminal-themes.js +90 -0
  198. package/dist/lib/utils.d.ts +2 -0
  199. package/dist/lib/utils.js +5 -0
  200. package/dist-cdn/loccal-ui.css +971 -0
  201. package/dist-cdn/loccal-ui.min.js +1 -0
  202. package/dist-wc/base.d.ts +31 -0
  203. package/dist-wc/base.js +104 -0
  204. package/dist-wc/button.d.ts +12 -0
  205. package/dist-wc/button.js +47 -0
  206. package/dist-wc/calendar.d.ts +16 -0
  207. package/dist-wc/calendar.js +106 -0
  208. package/dist-wc/choice.d.ts +17 -0
  209. package/dist-wc/choice.js +76 -0
  210. package/dist-wc/command.d.ts +32 -0
  211. package/dist-wc/command.js +181 -0
  212. package/dist-wc/data-table.d.ts +22 -0
  213. package/dist-wc/data-table.js +128 -0
  214. package/dist-wc/dialog.d.ts +29 -0
  215. package/dist-wc/dialog.js +94 -0
  216. package/dist-wc/disclosure.d.ts +17 -0
  217. package/dist-wc/disclosure.js +91 -0
  218. package/dist-wc/fields2.d.ts +38 -0
  219. package/dist-wc/fields2.js +133 -0
  220. package/dist-wc/file-tree.d.ts +19 -0
  221. package/dist-wc/file-tree.js +97 -0
  222. package/dist-wc/floating.d.ts +32 -0
  223. package/dist-wc/floating.js +91 -0
  224. package/dist-wc/index.d.ts +23 -0
  225. package/dist-wc/index.js +24 -0
  226. package/dist-wc/input-otp.d.ts +14 -0
  227. package/dist-wc/input-otp.js +82 -0
  228. package/dist-wc/navigation-menu.d.ts +14 -0
  229. package/dist-wc/navigation-menu.js +75 -0
  230. package/dist-wc/number-field.d.ts +13 -0
  231. package/dist-wc/number-field.js +67 -0
  232. package/dist-wc/resizable.d.ts +14 -0
  233. package/dist-wc/resizable.js +57 -0
  234. package/dist-wc/select.d.ts +17 -0
  235. package/dist-wc/select.js +80 -0
  236. package/dist-wc/static.d.ts +1 -0
  237. package/dist-wc/static.js +175 -0
  238. package/dist-wc/status-bar.d.ts +11 -0
  239. package/dist-wc/status-bar.js +54 -0
  240. package/dist-wc/styles.css +971 -0
  241. package/dist-wc/tabs.d.ts +16 -0
  242. package/dist-wc/tabs.js +62 -0
  243. package/dist-wc/terminal-tabs.d.ts +16 -0
  244. package/dist-wc/terminal-tabs.js +79 -0
  245. package/dist-wc/toaster.d.ts +16 -0
  246. package/dist-wc/toaster.js +68 -0
  247. package/dist-wc/toggle.d.ts +30 -0
  248. package/dist-wc/toggle.js +101 -0
  249. package/dist-wc/tree.d.ts +17 -0
  250. package/dist-wc/tree.js +72 -0
  251. package/docs/ARQUITETURA-VANILLA.md +54 -0
  252. package/docs/VERSIONING.md +88 -0
  253. package/package.json +1078 -6
  254. package/styles.css +476 -0
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { MinusIcon, SquareIcon, XIcon, CopyIcon } from "./icons.js";
5
+ import { cn } from "../../lib/utils.js";
6
+ const DEFAULT_WINDOW_LABELS = {
7
+ minimise: "Minimizar janela",
8
+ maximise: "Maximizar janela",
9
+ restore: "Restaurar janela",
10
+ close: "Fechar janela",
11
+ };
12
+ const WindowContext = React.createContext({
13
+ platform: "mac",
14
+ maximised: false,
15
+ labels: DEFAULT_WINDOW_LABELS,
16
+ });
17
+ function useWindowFrame() {
18
+ return React.useContext(WindowContext);
19
+ }
20
+ function WindowFrame({ platform = "mac", maximised = false, onMinimise, onToggleMaximise, onClose, labels, className, children, ...props }) {
21
+ const merged = React.useMemo(() => ({ ...DEFAULT_WINDOW_LABELS, ...labels }), [labels]);
22
+ return (_jsx(WindowContext.Provider, { value: { platform, maximised, onMinimise, onToggleMaximise, onClose, labels: merged }, children: _jsx("div", { "data-slot": "window-frame", "data-platform": platform, className: cn("flex flex-col overflow-hidden bg-background text-foreground shadow-floating", maximised ? "rounded-none" : "rounded-xl", className), ...props, children: children }) }));
23
+ }
24
+ function TrafficLights() {
25
+ const { onClose, onMinimise, onToggleMaximise, labels } = useWindowFrame();
26
+ const base = "group/light relative flex size-3 items-center justify-center rounded-full bg-foreground/15 ring-1 ring-inset ring-foreground/10 transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring";
27
+ return (_jsxs("div", { className: "group/lights wails-no-drag flex items-center gap-2 pl-3.5", children: [_jsx("button", { type: "button", "aria-label": labels.close, onClick: onClose, className: cn(base, "group-hover/lights:bg-destructive"), children: _jsx(XIcon, { className: "size-2 text-background opacity-0 group-hover/lights:opacity-80", strokeWidth: 3 }) }), _jsx("button", { type: "button", "aria-label": labels.minimise, onClick: onMinimise, className: cn(base, "group-hover/lights:bg-warning"), children: _jsx(MinusIcon, { className: "size-2 text-background opacity-0 group-hover/lights:opacity-80", strokeWidth: 3 }) }), _jsx("button", { type: "button", "aria-label": labels.maximise, onClick: onToggleMaximise, className: cn(base, "group-hover/lights:bg-success"), children: _jsx(SquareIcon, { className: "size-1.5 text-background opacity-0 group-hover/lights:opacity-80", strokeWidth: 3 }) })] }));
28
+ }
29
+ function WindowsControls() {
30
+ const { onClose, onMinimise, onToggleMaximise, maximised, labels } = useWindowFrame();
31
+ const base = "flex h-full w-11 items-center justify-center text-muted-foreground transition-colors outline-none hover:bg-foreground/8 hover:text-foreground focus-visible:bg-foreground/10";
32
+ return (_jsxs("div", { className: "wails-no-drag ml-auto flex h-full items-stretch", children: [_jsx("button", { type: "button", "aria-label": labels.minimise, onClick: onMinimise, className: base, children: _jsx(MinusIcon, { className: "size-3.5", strokeWidth: 1.5 }) }), _jsx("button", { type: "button", "aria-label": maximised ? labels.restore : labels.maximise, onClick: onToggleMaximise, className: base, children: maximised ? (_jsx(CopyIcon, { className: "size-3 -scale-x-100", strokeWidth: 1.5 })) : (_jsx(SquareIcon, { className: "size-3", strokeWidth: 1.5 })) }), _jsx("button", { type: "button", "aria-label": labels.close, onClick: onClose, className: cn(base, "hover:bg-destructive hover:text-primary-foreground dark:hover:text-foreground"), children: _jsx(XIcon, { className: "size-4", strokeWidth: 1.5 }) })] }));
33
+ }
34
+ /** Controles no estilo GTK/libadwaita (GNOME, KDE com Breeze compativel): circulos discretos a direita. */
35
+ function LinuxControls() {
36
+ const { onClose, onMinimise, onToggleMaximise, maximised, labels } = useWindowFrame();
37
+ const base = "flex size-6 items-center justify-center rounded-full bg-foreground/8 text-foreground/80 transition-colors outline-none hover:bg-foreground/15 focus-visible:ring-2 focus-visible:ring-ring";
38
+ return (_jsxs("div", { className: "wails-no-drag ml-auto flex items-center gap-1.5 pr-2.5", children: [_jsx("button", { type: "button", "aria-label": labels.minimise, onClick: onMinimise, className: base, children: _jsx(MinusIcon, { className: "size-3", strokeWidth: 1.75 }) }), _jsx("button", { type: "button", "aria-label": maximised ? labels.restore : labels.maximise, onClick: onToggleMaximise, className: base, children: maximised ? (_jsx(CopyIcon, { className: "size-2.5 -scale-x-100", strokeWidth: 1.75 })) : (_jsx(SquareIcon, { className: "size-2.5", strokeWidth: 1.75 })) }), _jsx("button", { type: "button", "aria-label": labels.close, onClick: onClose, className: cn(base, "hover:bg-destructive hover:text-primary-foreground dark:hover:text-foreground"), children: _jsx(XIcon, { className: "size-3", strokeWidth: 1.75 }) })] }));
39
+ }
40
+ function TitleBar({ title, icon, className, children, ...props }) {
41
+ const { platform, onToggleMaximise } = useWindowFrame();
42
+ return (_jsxs("header", { "data-slot": "title-bar", onDoubleClick: onToggleMaximise, className: cn("wails-drag relative flex h-10 shrink-0 items-center gap-3 border-b bg-sidebar text-sm select-none", className), ...props, children: [platform === "mac" ? _jsx(TrafficLights, {}) : null, _jsxs("div", { className: cn("flex min-w-0 items-center gap-2", platform === "mac" || platform === "linux"
43
+ ? "pointer-events-none absolute inset-x-0 justify-center"
44
+ : "pl-3"), children: [icon ? _jsx("span", { className: "flex size-4 items-center justify-center text-muted-foreground [&_svg]:size-4", children: icon }) : null, title ? _jsx("span", { className: "truncate text-[13px] font-medium text-foreground/80", children: title }) : null] }), children ? (_jsx("div", { className: cn("wails-no-drag relative flex items-center gap-1", platform === "mac" ? "ml-auto pr-2" : platform === "linux" ? "ml-auto pr-1" : "ml-auto"), children: children })) : null, platform === "windows" ? _jsx(WindowsControls, {}) : null, platform === "linux" ? _jsx(LinuxControls, {}) : null] }));
45
+ }
46
+ function WindowBody({ className, ...props }) {
47
+ return (_jsx("div", { "data-slot": "window-body", className: cn("relative flex min-h-0 flex-1", className), ...props }));
48
+ }
49
+ export { WindowFrame, TitleBar, WindowBody, useWindowFrame };
@@ -0,0 +1,13 @@
1
+ export type AiSegment = {
2
+ kind: "text";
3
+ text: string;
4
+ } | {
5
+ kind: "code";
6
+ lang: string;
7
+ code: string;
8
+ open: boolean;
9
+ };
10
+ export declare function parseAiMarkdown(source: string): AiSegment[];
11
+ export declare function isShellLang(lang: string): boolean;
12
+ /** Blocos fechados em linguagem de shell (ou sem linguagem), prontos para virar CommandBlock. */
13
+ export declare function extractShellCommands(segments: AiSegment[]): string[];
@@ -0,0 +1,46 @@
1
+ // Divide a resposta de um modelo em trechos de texto e blocos de codigo cercados por ```.
2
+ // Tolerante a streaming: um bloco ainda sem fechamento e devolvido como `open: true`.
3
+ const FENCE = /```([^\n`]*)\n?/g;
4
+ export function parseAiMarkdown(source) {
5
+ const segments = [];
6
+ let cursor = 0;
7
+ let inCode = false;
8
+ let lang = "";
9
+ FENCE.lastIndex = 0;
10
+ for (let m = FENCE.exec(source); m; m = FENCE.exec(source)) {
11
+ const chunk = source.slice(cursor, m.index);
12
+ if (inCode) {
13
+ segments.push({ kind: "code", lang, code: chunk.replace(/\n$/, ""), open: false });
14
+ inCode = false;
15
+ }
16
+ else {
17
+ if (chunk.trim())
18
+ segments.push({ kind: "text", text: chunk.replace(/^\n+|\n+$/g, "") });
19
+ inCode = true;
20
+ lang = m[1].trim().toLowerCase();
21
+ }
22
+ cursor = m.index + m[0].length;
23
+ }
24
+ const rest = source.slice(cursor);
25
+ if (inCode)
26
+ segments.push({ kind: "code", lang, code: rest.replace(/\n$/, ""), open: true });
27
+ else if (rest.trim())
28
+ segments.push({ kind: "text", text: rest.replace(/^\n+|\n+$/g, "") });
29
+ return segments;
30
+ }
31
+ const SHELL_LANGS = new Set(["", "sh", "bash", "zsh", "fish", "shell", "console", "powershell", "pwsh", "ps1", "cmd", "bat", "batch", "terminal"]);
32
+ export function isShellLang(lang) {
33
+ return SHELL_LANGS.has(lang);
34
+ }
35
+ /** Blocos fechados em linguagem de shell (ou sem linguagem), prontos para virar CommandBlock. */
36
+ export function extractShellCommands(segments) {
37
+ const out = [];
38
+ for (const s of segments) {
39
+ if (s.kind === "code" && !s.open && isShellLang(s.lang)) {
40
+ const code = s.code.trim();
41
+ if (code)
42
+ out.push(code);
43
+ }
44
+ }
45
+ return out;
46
+ }
@@ -0,0 +1,6 @@
1
+ export type CommandRisk = "low" | "medium" | "high";
2
+ export type RiskAssessment = {
3
+ risk: CommandRisk;
4
+ reasons: string[];
5
+ };
6
+ export declare function assessCommandRisk(command: string): RiskAssessment;
@@ -0,0 +1,42 @@
1
+ // Avaliacao heuristica do risco de um comando de shell sugerido (por IA ou digitado).
2
+ // E um aviso para o usuario, nao uma garantia de seguranca.
3
+ const RULES = [
4
+ { risk: "high", test: /\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r|--recursive\b.*--force|--force\b.*--recursive)\b/i, reason: "rm-recursive-force" },
5
+ { risk: "high", test: /\brm\s+-[a-z]*r[a-z]*\s+(\/|~|\*|\$HOME)(\s|$)/i, reason: "rm-root-or-home" },
6
+ { risk: "high", test: /\bRemove-Item\b[^|\n]*-Recurse\b/i, reason: "remove-item-recurse" },
7
+ { risk: "high", test: /\b(rd|rmdir)\s+\/s\b/i, reason: "rmdir-recursive" },
8
+ { risk: "high", test: /\bdel\s+(\/[a-z]\s+)*\/[sf]\b/i, reason: "del-force" },
9
+ { risk: "high", test: /\bformat(\.com)?\s+[a-z]:/i, reason: "format-drive" },
10
+ { risk: "high", test: /\bdd\s+[^|\n]*\bof=\/dev\//i, reason: "dd-device" },
11
+ { risk: "high", test: /\bmkfs(\.\w+)?\b/i, reason: "mkfs" },
12
+ { risk: "high", test: /\bgit\s+push\b[^|\n]*(--force\b|-f\b)(?!-with-lease)/i, reason: "git-force-push" },
13
+ { risk: "high", test: /\bgit\s+reset\s+--hard\b/i, reason: "git-reset-hard" },
14
+ { risk: "high", test: /\bgit\s+clean\s+-[a-z]*f/i, reason: "git-clean-force" },
15
+ { risk: "high", test: /(curl|wget|iwr|Invoke-WebRequest)\b[^|\n]*\|\s*(sh|bash|zsh|iex|Invoke-Expression|powershell|pwsh)\b/i, reason: "pipe-to-shell" },
16
+ { risk: "high", test: /:\(\)\s*\{\s*:\|:&\s*\};:/, reason: "fork-bomb" },
17
+ { risk: "medium", test: /\bsudo\b/i, reason: "sudo" },
18
+ { risk: "medium", test: /\bchmod\s+(-R\s+)?[0-7]*7{2,3}\b/i, reason: "chmod-wide" },
19
+ { risk: "medium", test: /\b(shutdown|reboot|Restart-Computer|Stop-Computer)\b/i, reason: "power" },
20
+ { risk: "medium", test: /\b(taskkill|kill(all)?|Stop-Process)\b/i, reason: "kill-process" },
21
+ { risk: "medium", test: /\b(npm|pnpm|yarn|pip|pip3)\s+(install|i|add)\s+(-g|--global)\b/i, reason: "global-install" },
22
+ { risk: "medium", test: /\bgit\s+(checkout|restore)\s+(--\s+)?\.\s*$/i, reason: "discard-changes" },
23
+ { risk: "medium", test: /\bgit\s+branch\s+-D\b/, reason: "delete-branch" },
24
+ { risk: "medium", test: /\b(Set-ExecutionPolicy|reg\s+(add|delete)|setx)\b/i, reason: "system-config" },
25
+ { risk: "medium", test: />\s*\/dev\/(sd|nvme)/i, reason: "redirect-device" },
26
+ ];
27
+ const ORDER = { low: 0, medium: 1, high: 2 };
28
+ export function assessCommandRisk(command) {
29
+ const text = command.trim();
30
+ let risk = "low";
31
+ const reasons = [];
32
+ if (!text)
33
+ return { risk, reasons };
34
+ for (const rule of RULES) {
35
+ if (rule.test.test(text)) {
36
+ reasons.push(rule.reason);
37
+ if (ORDER[rule.risk] > ORDER[risk])
38
+ risk = rule.risk;
39
+ }
40
+ }
41
+ return { risk, reasons };
42
+ }
@@ -0,0 +1,18 @@
1
+ export type FileIconSpec = {
2
+ /** Identificador estavel do tipo (ex.: "typescript", "image"). */
3
+ id: string;
4
+ /** Sigla de 1 a 3 caracteres desenhada no selo. */
5
+ label: string;
6
+ /** Cor do selo (hex). */
7
+ color: string;
8
+ /** Cor da sigla (hex), escolhida pelo contraste com o selo. */
9
+ ink: string;
10
+ };
11
+ /** Tipo do arquivo pelo nome completo e depois pela extensao; undefined = sem icone especifico. */
12
+ export declare function fileTypeId(name: string): string | undefined;
13
+ /** Especificacao do icone de um arquivo, ou undefined para o icone generico de arquivo. */
14
+ export declare function fileIconFor(name: string): FileIconSpec | undefined;
15
+ /** Todos os tipos com icone (para galerias e testes). */
16
+ export declare const fileIconTypes: readonly string[];
17
+ /** SVG do selo (string). `size` em px. */
18
+ export declare function fileIconSvg(spec: FileIconSpec, size?: number): string;
@@ -0,0 +1,136 @@
1
+ // Icones de tipo de arquivo (linguagens, formatos e extensoes mais usadas). Vanilla e sem DOM:
2
+ // `fileIconFor` escolhe o icone pelo nome; `fileIconSvg` o desenha como um selo colorido de 16x16 com a sigla do tipo.
3
+ // As formas sao proprias da Loccal UI (selo + sigla), nao reproduzem logotipos de terceiros.
4
+ const DARK = "#1b1b1f";
5
+ const LIGHT = "#ffffff";
6
+ const BY_TYPE = {
7
+ javascript: ["JS", "#f0db4f", DARK],
8
+ typescript: ["TS", "#3178c6"],
9
+ jsx: ["JX", "#f0db4f", DARK],
10
+ tsx: ["TX", "#3178c6"],
11
+ json: ["{}", "#d4a72c", DARK],
12
+ html: ["<>", "#e34f26"],
13
+ xml: ["<>", "#d9822b", DARK],
14
+ svg: ["SV", "#e8912d", DARK],
15
+ css: ["#", "#1572b6"],
16
+ scss: ["S", "#cd6799"],
17
+ less: ["L", "#2b4a7a"],
18
+ vue: ["V", "#41b883", DARK],
19
+ svelte: ["SV", "#ff3e00"],
20
+ go: ["GO", "#00a7c4"],
21
+ rust: ["RS", "#b7410e"],
22
+ c: ["C", "#5560bf"],
23
+ cpp: ["C+", "#00599c"],
24
+ header: ["H", "#7c6fcf"],
25
+ csharp: ["C#", "#8a3f96"],
26
+ java: ["JV", "#d9730d"],
27
+ kotlin: ["KT", "#7f52ff"],
28
+ swift: ["SW", "#f05138"],
29
+ dart: ["DT", "#0175c2"],
30
+ php: ["PH", "#777bb3"],
31
+ python: ["PY", "#3776ab"],
32
+ ruby: ["RB", "#cc342d"],
33
+ lua: ["LU", "#2c2d72"],
34
+ perl: ["PL", "#39457e"],
35
+ elixir: ["EX", "#6e4a7e"],
36
+ haskell: ["HS", "#5e5086"],
37
+ scala: ["SC", "#dc322f"],
38
+ zig: ["ZG", "#f7a41d", DARK],
39
+ r: ["R", "#276dc3"],
40
+ shell: [">_", "#3d9a3a"],
41
+ powershell: ["PS", "#2671be"],
42
+ batch: [">_", "#5a6169"],
43
+ sql: ["DB", "#e38c00", DARK],
44
+ yaml: ["YM", "#c2353a"],
45
+ toml: ["TM", "#9c4221"],
46
+ config: ["CF", "#6b7280"],
47
+ env: ["EN", "#6b7280"],
48
+ markdown: ["MD", "#3b82a0"],
49
+ text: ["TX", "#6b7280"],
50
+ log: ["LG", "#6b7280"],
51
+ docker: ["DK", "#2496ed"],
52
+ make: ["MK", "#6d8086"],
53
+ git: ["GT", "#e0432b"],
54
+ diff: ["±", "#6b7280"],
55
+ license: ["LI", "#6b7280"],
56
+ lock: ["LK", "#7a6f5c"],
57
+ csv: ["CS", "#2e9d6a"],
58
+ database: ["DB", "#7b61a8"],
59
+ pdf: ["PD", "#d63a35"],
60
+ doc: ["DC", "#2b6cb0"],
61
+ sheet: ["XL", "#1f8a4c"],
62
+ slides: ["PP", "#d2562a"],
63
+ image: ["IM", "#1f9e91"],
64
+ video: ["VD", "#9c3fb0"],
65
+ audio: ["AU", "#d6336c"],
66
+ font: ["Aa", "#6b7280"],
67
+ archive: ["ZP", "#8a6d52"],
68
+ binary: ["01", "#4b5563"],
69
+ executable: ["EX", "#4b5563"],
70
+ };
71
+ const EXT = {
72
+ js: "javascript", mjs: "javascript", cjs: "javascript", jsx: "jsx", ts: "typescript", mts: "typescript", cts: "typescript", tsx: "tsx",
73
+ json: "json", jsonc: "json", json5: "json", map: "json", webmanifest: "json", ipynb: "json",
74
+ html: "html", htm: "html", xhtml: "html", xml: "xml", xsd: "xml", xsl: "xml", plist: "xml", csproj: "xml", xaml: "xml", rss: "xml", svg: "svg",
75
+ css: "css", scss: "scss", sass: "scss", less: "less", vue: "vue", svelte: "svelte", astro: "html",
76
+ go: "go", rs: "rust", c: "c", h: "header", hpp: "header", hh: "header", cpp: "cpp", cc: "cpp", cxx: "cpp", ino: "cpp", cs: "csharp",
77
+ java: "java", kt: "kotlin", kts: "kotlin", swift: "swift", dart: "dart", php: "php", py: "python", pyw: "python", pyi: "python",
78
+ rb: "ruby", rake: "ruby", lua: "lua", pl: "perl", pm: "perl", ex: "elixir", exs: "elixir", hs: "haskell", scala: "scala", sc: "scala",
79
+ zig: "zig", r: "r",
80
+ sh: "shell", bash: "shell", zsh: "shell", fish: "shell", ksh: "shell", ps1: "powershell", psm1: "powershell", psd1: "powershell", bat: "batch", cmd: "batch",
81
+ sql: "sql", yaml: "yaml", yml: "yaml", toml: "toml", ini: "config", cfg: "config", conf: "config", properties: "config", editorconfig: "config", env: "env",
82
+ md: "markdown", markdown: "markdown", mdx: "markdown", rst: "text", txt: "text", log: "log", diff: "diff", patch: "diff",
83
+ mk: "make", mak: "make", lock: "lock", csv: "csv", tsv: "csv", db: "database", sqlite: "database", sqlite3: "database", parquet: "database",
84
+ pdf: "pdf", doc: "doc", docx: "doc", odt: "doc", rtf: "doc", xls: "sheet", xlsx: "sheet", ods: "sheet", ppt: "slides", pptx: "slides", odp: "slides",
85
+ png: "image", jpg: "image", jpeg: "image", gif: "image", webp: "image", bmp: "image", ico: "image", avif: "image", tif: "image", tiff: "image", heic: "image", icns: "image",
86
+ mp4: "video", mkv: "video", mov: "video", avi: "video", webm: "video", m4v: "video",
87
+ mp3: "audio", wav: "audio", flac: "audio", ogg: "audio", m4a: "audio", aac: "audio", opus: "audio",
88
+ ttf: "font", otf: "font", woff: "font", woff2: "font", eot: "font",
89
+ zip: "archive", tar: "archive", gz: "archive", tgz: "archive", bz2: "archive", xz: "archive", "7z": "archive", rar: "archive", zst: "archive", iso: "archive", jar: "archive", war: "archive",
90
+ exe: "executable", msi: "executable", app: "executable", apk: "executable", bin: "binary", dll: "binary", so: "binary", dylib: "binary", o: "binary", obj: "binary", class: "binary", wasm: "binary", pyc: "binary",
91
+ };
92
+ const NAME = {
93
+ dockerfile: "docker", ".dockerignore": "docker", "docker-compose.yml": "docker", "docker-compose.yaml": "docker", "compose.yaml": "docker", "compose.yml": "docker",
94
+ makefile: "make", gnumakefile: "make", ".gitignore": "git", ".gitattributes": "git", ".gitmodules": "git", ".gitconfig": "git",
95
+ license: "license", "license.md": "license", "license.txt": "license", copying: "license", notice: "license",
96
+ "package-lock.json": "lock", "pnpm-lock.yaml": "lock", "yarn.lock": "lock", "go.sum": "lock", "cargo.lock": "lock", "poetry.lock": "lock", "composer.lock": "lock", gemfile: "ruby", rakefile: "ruby",
97
+ "go.mod": "go", "go.work": "go", ".env": "env", ".npmrc": "config", ".editorconfig": "config", ".prettierrc": "json", ".eslintrc": "json",
98
+ ".bashrc": "shell", ".zshrc": "shell", ".profile": "shell", readme: "markdown",
99
+ };
100
+ /** Tipo do arquivo pelo nome completo e depois pela extensao; undefined = sem icone especifico. */
101
+ export function fileTypeId(name) {
102
+ const base = name.replace(/\\/g, "/").split("/").pop().toLowerCase();
103
+ if (NAME[base])
104
+ return NAME[base];
105
+ if (base.startsWith(".env."))
106
+ return "env";
107
+ const dot = base.lastIndexOf(".");
108
+ if (dot <= 0)
109
+ return undefined;
110
+ const ext = base.slice(dot + 1);
111
+ if (base.endsWith(".d.ts"))
112
+ return "typescript";
113
+ return EXT[ext];
114
+ }
115
+ /** Especificacao do icone de um arquivo, ou undefined para o icone generico de arquivo. */
116
+ export function fileIconFor(name) {
117
+ const id = fileTypeId(name);
118
+ if (!id)
119
+ return undefined;
120
+ const e = BY_TYPE[id];
121
+ if (!e)
122
+ return undefined;
123
+ return { id, label: e[0], color: e[1], ink: e[2] ?? LIGHT };
124
+ }
125
+ /** Todos os tipos com icone (para galerias e testes). */
126
+ export const fileIconTypes = Object.keys(BY_TYPE);
127
+ const escXml = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
128
+ /** SVG do selo (string). `size` em px. */
129
+ export function fileIconSvg(spec, size = 16) {
130
+ const n = [...spec.label].length;
131
+ const fs = n === 1 ? 9.5 : n === 2 ? 7 : 5.5;
132
+ return (`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 16 16" aria-hidden="true" focusable="false" data-file-type="${spec.id}">` +
133
+ `<rect x="0.75" y="0.75" width="14.5" height="14.5" rx="3.25" fill="${spec.color}"/>` +
134
+ `<text x="8" y="${(8 + fs * 0.36).toFixed(2)}" text-anchor="middle" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="${fs}" font-weight="700" fill="${spec.ink}">${escXml(spec.label)}</text>` +
135
+ `</svg>`);
136
+ }
@@ -0,0 +1,10 @@
1
+ export type FileKind = "folder" | "code" | "config" | "doc" | "image" | "archive" | "data" | "script" | "lock" | "binary" | "file";
2
+ export declare function fileKind(name: string, isDir?: boolean): FileKind;
3
+ export type GitStatus = "modified" | "added" | "deleted" | "untracked" | "renamed" | "conflict";
4
+ /** Interpreta um codigo `git status --porcelain` de dois caracteres. */
5
+ export declare function parsePorcelainStatus(code: string): GitStatus | undefined;
6
+ /** Separa `"XY caminho"` do porcelain v1. */
7
+ export declare function parsePorcelainLine(line: string): {
8
+ status: GitStatus | undefined;
9
+ path: string;
10
+ };
@@ -0,0 +1,63 @@
1
+ // Classificacao de arquivos por extensao para escolher icone (sem dependencia de React).
2
+ const BY_EXT = {
3
+ ts: "code", tsx: "code", js: "code", jsx: "code", mjs: "code", cjs: "code", go: "code", rs: "code", py: "code",
4
+ java: "code", kt: "code", c: "code", h: "code", cpp: "code", cs: "code", rb: "code", php: "code", svelte: "code",
5
+ vue: "code", css: "code", scss: "code", html: "code", sql: "code",
6
+ json: "config", yaml: "config", yml: "config", toml: "config", ini: "config", env: "config", mod: "config", sum: "config",
7
+ md: "doc", mdx: "doc", txt: "doc", pdf: "doc", rst: "doc",
8
+ png: "image", jpg: "image", jpeg: "image", gif: "image", svg: "image", webp: "image", ico: "image",
9
+ zip: "archive", tar: "archive", gz: "archive", "7z": "archive", rar: "archive",
10
+ csv: "data", tsv: "data", parquet: "data", db: "data", sqlite: "data",
11
+ sh: "script", bash: "script", zsh: "script", ps1: "script", bat: "script", cmd: "script",
12
+ lock: "lock",
13
+ exe: "binary", dll: "binary", so: "binary", bin: "binary",
14
+ };
15
+ const BY_NAME = {
16
+ dockerfile: "config",
17
+ makefile: "script",
18
+ "package-lock.json": "lock",
19
+ "pnpm-lock.yaml": "lock",
20
+ "go.sum": "lock",
21
+ ".gitignore": "config",
22
+ ".env": "config",
23
+ };
24
+ export function fileKind(name, isDir = false) {
25
+ if (isDir)
26
+ return "folder";
27
+ const lower = name.toLowerCase();
28
+ const byName = BY_NAME[lower];
29
+ if (byName)
30
+ return byName;
31
+ const dot = lower.lastIndexOf(".");
32
+ if (dot <= 0 && !lower.startsWith("."))
33
+ return "file";
34
+ return BY_EXT[lower.slice(dot + 1)] ?? "file";
35
+ }
36
+ /** Interpreta um codigo `git status --porcelain` de dois caracteres. */
37
+ export function parsePorcelainStatus(code) {
38
+ const c = code.padEnd(2, " ");
39
+ if (c === "??")
40
+ return "untracked";
41
+ if (c.includes("U") || c === "AA" || c === "DD")
42
+ return "conflict";
43
+ if (c.includes("R"))
44
+ return "renamed";
45
+ if (c.includes("D"))
46
+ return "deleted";
47
+ if (c.includes("A"))
48
+ return "added";
49
+ if (c.includes("M"))
50
+ return "modified";
51
+ return undefined;
52
+ }
53
+ /** Separa `"XY caminho"` do porcelain v1. */
54
+ export function parsePorcelainLine(line) {
55
+ const code = line.slice(0, 2);
56
+ let path = line.slice(3).trim();
57
+ const arrow = path.indexOf(" -> ");
58
+ if (arrow !== -1)
59
+ path = path.slice(arrow + 4);
60
+ if (path.startsWith('"') && path.endsWith('"'))
61
+ path = path.slice(1, -1);
62
+ return { status: parsePorcelainStatus(code), path };
63
+ }
@@ -0,0 +1,9 @@
1
+ export declare function formatBytes(bytes: number | undefined): string;
2
+ export type RelativeTimeLabels = {
3
+ now: string;
4
+ minutes: string;
5
+ hours: string;
6
+ days: string;
7
+ };
8
+ /** Tempo decorrido curto ("agora", "5 min", "3 h", "2 d"). `labels` aceita `{n}` como marcador. */
9
+ export declare function relativeTime(thenMs: number, nowMs: number, labels?: Partial<RelativeTimeLabels>): string;
@@ -0,0 +1,30 @@
1
+ // Formatadores puros usados por componentes de dados.
2
+ export function formatBytes(bytes) {
3
+ if (bytes === undefined || !Number.isFinite(bytes) || bytes < 0)
4
+ return "";
5
+ if (bytes < 1024)
6
+ return `${Math.round(bytes)} B`;
7
+ const units = ["KB", "MB", "GB", "TB"];
8
+ let value = bytes / 1024;
9
+ let unit = 0;
10
+ while (value >= 1024 && unit < units.length - 1) {
11
+ value /= 1024;
12
+ unit++;
13
+ }
14
+ return `${value >= 100 || Number.isInteger(value) ? Math.round(value) : value.toFixed(1)} ${units[unit]}`;
15
+ }
16
+ const DEFAULT_RELATIVE = { now: "agora", minutes: "{n} min", hours: "{n} h", days: "{n} d" };
17
+ /** Tempo decorrido curto ("agora", "5 min", "3 h", "2 d"). `labels` aceita `{n}` como marcador. */
18
+ export function relativeTime(thenMs, nowMs, labels = {}) {
19
+ const l = { ...DEFAULT_RELATIVE, ...labels };
20
+ const diff = Math.max(0, nowMs - thenMs);
21
+ const minutes = Math.floor(diff / 60_000);
22
+ if (minutes < 1)
23
+ return l.now;
24
+ if (minutes < 60)
25
+ return l.minutes.replace("{n}", String(minutes));
26
+ const hours = Math.floor(minutes / 60);
27
+ if (hours < 24)
28
+ return l.hours.replace("{n}", String(hours));
29
+ return l.days.replace("{n}", String(Math.floor(hours / 24)));
30
+ }
@@ -0,0 +1,20 @@
1
+ export type Locale = "pt-BR" | "en-US" | "es-ES";
2
+ export declare const LOCALES: {
3
+ id: Locale;
4
+ short: string;
5
+ label: string;
6
+ }[];
7
+ export declare const LOCALE_STORAGE_KEY = "loccal-locale";
8
+ export declare const LOCALE_EVENT = "loccal:locale-changed";
9
+ export declare const DEFAULT_LOCALE: Locale;
10
+ export type Dictionary = Record<string, string>;
11
+ export type Dictionaries = Record<Locale, Dictionary>;
12
+ export declare function isLocale(value: unknown): value is Locale;
13
+ /** Escolhe o idioma inicial: valor salvo, depois idioma do navegador, depois o padrao. */
14
+ export declare function detectLocale(stored?: string | null, navigatorLanguage?: string): Locale;
15
+ /** Valor por idioma, com queda para pt-BR. */
16
+ export declare function pick<T>(locale: Locale, values: Partial<Record<Locale, T>> & {
17
+ "pt-BR": T;
18
+ }): T;
19
+ /** Traducao por chave, com interpolacao `{nome}` e queda para pt-BR e depois para a propria chave. */
20
+ export declare function translate(dicts: Dictionaries, locale: Locale, key: string, params?: Record<string, string | number>): string;
@@ -0,0 +1,36 @@
1
+ // Nucleo puro do i18n (sem React): tipos, deteccao, escolha e traducao.
2
+ export const LOCALES = [
3
+ { id: "pt-BR", short: "PT", label: "Português (Brasil)" },
4
+ { id: "en-US", short: "EN", label: "English (US)" },
5
+ { id: "es-ES", short: "ES", label: "Español" },
6
+ ];
7
+ export const LOCALE_STORAGE_KEY = "loccal-locale";
8
+ export const LOCALE_EVENT = "loccal:locale-changed";
9
+ export const DEFAULT_LOCALE = "pt-BR";
10
+ export function isLocale(value) {
11
+ return value === "pt-BR" || value === "en-US" || value === "es-ES";
12
+ }
13
+ /** Escolhe o idioma inicial: valor salvo, depois idioma do navegador, depois o padrao. */
14
+ export function detectLocale(stored, navigatorLanguage) {
15
+ if (isLocale(stored))
16
+ return stored;
17
+ const lang = (navigatorLanguage ?? "").toLowerCase();
18
+ if (lang.startsWith("pt"))
19
+ return "pt-BR";
20
+ if (lang.startsWith("es"))
21
+ return "es-ES";
22
+ if (lang.startsWith("en"))
23
+ return "en-US";
24
+ return DEFAULT_LOCALE;
25
+ }
26
+ /** Valor por idioma, com queda para pt-BR. */
27
+ export function pick(locale, values) {
28
+ return values[locale] ?? values["pt-BR"];
29
+ }
30
+ /** Traducao por chave, com interpolacao `{nome}` e queda para pt-BR e depois para a propria chave. */
31
+ export function translate(dicts, locale, key, params) {
32
+ const raw = dicts[locale]?.[key] ?? dicts["pt-BR"]?.[key] ?? key;
33
+ if (!params)
34
+ return raw;
35
+ return raw.replace(/\{(\w+)\}/g, (_, name) => (name in params ? String(params[name]) : `{${name}}`));
36
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ import { type Dictionaries, type Locale } from "./i18n-core.js";
3
+ export * from "./i18n-core.js";
4
+ type LocaleContextValue = {
5
+ locale: Locale;
6
+ setLocale: (locale: Locale) => void;
7
+ };
8
+ declare function LocaleProvider({ children, defaultLocale, }: {
9
+ children: React.ReactNode;
10
+ defaultLocale?: Locale;
11
+ }): React.JSX.Element;
12
+ declare function useLocale(): LocaleContextValue;
13
+ /** Hook de traducao para um conjunto de dicionarios do componente/aplicacao. */
14
+ declare function useT(dicts: Dictionaries): (key: string, params?: Record<string, string | number>) => string;
15
+ export { LocaleProvider, useLocale, useT };
@@ -0,0 +1,68 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { DEFAULT_LOCALE, LOCALE_EVENT, LOCALE_STORAGE_KEY, detectLocale, isLocale, translate, } from "./i18n-core.js";
5
+ export * from "./i18n-core.js";
6
+ const LocaleContext = React.createContext({
7
+ locale: DEFAULT_LOCALE,
8
+ setLocale: () => { },
9
+ });
10
+ function readStored() {
11
+ try {
12
+ return window.localStorage.getItem(LOCALE_STORAGE_KEY);
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
18
+ function LocaleProvider({ children, defaultLocale, }) {
19
+ const [locale, setLocaleState] = React.useState(defaultLocale ?? DEFAULT_LOCALE);
20
+ // Le o idioma salvo apos a hidratacao para nao divergir do HTML do servidor.
21
+ React.useEffect(() => {
22
+ if (defaultLocale)
23
+ return;
24
+ setLocaleState(detectLocale(readStored(), navigator.language));
25
+ }, [defaultLocale]);
26
+ React.useEffect(() => {
27
+ document.documentElement.lang = locale;
28
+ }, [locale]);
29
+ // Sincroniza com outras instancias (outra janela via `storage`, mesma janela via evento).
30
+ React.useEffect(() => {
31
+ const onCustom = (e) => {
32
+ const next = e.detail;
33
+ if (isLocale(next))
34
+ setLocaleState(next);
35
+ };
36
+ const onStorage = (e) => {
37
+ if (e.key === LOCALE_STORAGE_KEY && isLocale(e.newValue))
38
+ setLocaleState(e.newValue);
39
+ };
40
+ window.addEventListener(LOCALE_EVENT, onCustom);
41
+ window.addEventListener("storage", onStorage);
42
+ return () => {
43
+ window.removeEventListener(LOCALE_EVENT, onCustom);
44
+ window.removeEventListener("storage", onStorage);
45
+ };
46
+ }, []);
47
+ const setLocale = React.useCallback((next) => {
48
+ setLocaleState(next);
49
+ try {
50
+ window.localStorage.setItem(LOCALE_STORAGE_KEY, next);
51
+ }
52
+ catch {
53
+ // armazenamento indisponivel: mantem so em memoria
54
+ }
55
+ window.dispatchEvent(new CustomEvent(LOCALE_EVENT, { detail: next }));
56
+ }, []);
57
+ const value = React.useMemo(() => ({ locale, setLocale }), [locale, setLocale]);
58
+ return _jsx(LocaleContext.Provider, { value: value, children: children });
59
+ }
60
+ function useLocale() {
61
+ return React.useContext(LocaleContext);
62
+ }
63
+ /** Hook de traducao para um conjunto de dicionarios do componente/aplicacao. */
64
+ function useT(dicts) {
65
+ const { locale } = useLocale();
66
+ return React.useCallback((key, params) => translate(dicts, locale, key, params), [dicts, locale]);
67
+ }
68
+ export { LocaleProvider, useLocale, useT };