@zonsh/ui 0.2.0 → 0.5.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 (200) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/accordion.js +1 -1
  4. package/dist/components/alert-dialog.js +1 -1
  5. package/dist/components/ascii-field.d.ts +1 -1
  6. package/dist/components/ascii-field.js +2 -1
  7. package/dist/components/bottom-nav.d.ts +86 -0
  8. package/dist/components/bottom-nav.js +175 -0
  9. package/dist/components/breadcrumb.d.ts +9 -0
  10. package/dist/components/breadcrumb.js +6 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +2 -2
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/calendar.d.ts +1 -1
  15. package/dist/components/calendar.js +18 -3
  16. package/dist/components/carousel.d.ts +22 -3
  17. package/dist/components/carousel.js +25 -7
  18. package/dist/components/chart.d.ts +20 -0
  19. package/dist/components/chart.js +52 -3
  20. package/dist/components/code-block.d.ts +20 -10
  21. package/dist/components/code-block.js +54 -12
  22. package/dist/components/collapsible.js +3 -3
  23. package/dist/components/color-picker.d.ts +30 -8
  24. package/dist/components/color-picker.js +48 -27
  25. package/dist/components/combobox.d.ts +21 -3
  26. package/dist/components/combobox.js +79 -7
  27. package/dist/components/command.d.ts +23 -3
  28. package/dist/components/command.js +63 -18
  29. package/dist/components/conversation.d.ts +10 -1
  30. package/dist/components/conversation.js +24 -7
  31. package/dist/components/copy-button.d.ts +15 -6
  32. package/dist/components/copy-button.js +27 -10
  33. package/dist/components/data-table.d.ts +66 -6
  34. package/dist/components/data-table.js +376 -23
  35. package/dist/components/date-picker.d.ts +73 -4
  36. package/dist/components/date-picker.js +138 -7
  37. package/dist/components/dialog.d.ts +10 -1
  38. package/dist/components/dialog.js +6 -3
  39. package/dist/components/drawer.d.ts +10 -1
  40. package/dist/components/drawer.js +6 -3
  41. package/dist/components/feature-list.js +2 -2
  42. package/dist/components/field.d.ts +27 -8
  43. package/dist/components/field.js +49 -4
  44. package/dist/components/file-drop.d.ts +26 -4
  45. package/dist/components/file-drop.js +125 -64
  46. package/dist/components/filter-bar.d.ts +50 -3
  47. package/dist/components/filter-bar.js +71 -33
  48. package/dist/components/form.d.ts +4 -2
  49. package/dist/components/form.js +24 -2
  50. package/dist/components/graph.d.ts +41 -0
  51. package/dist/components/graph.js +106 -50
  52. package/dist/components/illustration.js +51 -4
  53. package/dist/components/input-group.d.ts +18 -7
  54. package/dist/components/input-group.js +41 -19
  55. package/dist/components/input.d.ts +2 -2
  56. package/dist/components/input.js +3 -3
  57. package/dist/components/kbd.d.ts +17 -0
  58. package/dist/components/kbd.js +8 -1
  59. package/dist/components/layout.d.ts +2 -1
  60. package/dist/components/layout.js +55 -11
  61. package/dist/components/lightbox.d.ts +100 -0
  62. package/dist/components/lightbox.js +457 -0
  63. package/dist/components/locale.d.ts +44 -0
  64. package/dist/components/locale.js +37 -0
  65. package/dist/components/logo.js +1 -1
  66. package/dist/components/menu.js +3 -1
  67. package/dist/components/menubar.js +60 -13
  68. package/dist/components/message.d.ts +3 -3
  69. package/dist/components/message.js +12 -8
  70. package/dist/components/meter.js +3 -1
  71. package/dist/components/money-input.d.ts +80 -0
  72. package/dist/components/money-input.js +253 -0
  73. package/dist/components/navigation-menu.js +4 -2
  74. package/dist/components/number-field.d.ts +21 -2
  75. package/dist/components/number-field.js +53 -28
  76. package/dist/components/otp-field.d.ts +14 -1
  77. package/dist/components/otp-field.js +10 -2
  78. package/dist/components/pagination.d.ts +13 -7
  79. package/dist/components/pagination.js +18 -7
  80. package/dist/components/pdf-viewer.d.ts +67 -2
  81. package/dist/components/pdf-viewer.js +88 -21
  82. package/dist/components/phone-input.d.ts +79 -0
  83. package/dist/components/phone-input.js +282 -0
  84. package/dist/components/popover.js +1 -1
  85. package/dist/components/progress.js +3 -1
  86. package/dist/components/prompt-input.d.ts +34 -9
  87. package/dist/components/prompt-input.js +37 -17
  88. package/dist/components/radio-group.js +7 -2
  89. package/dist/components/rating.d.ts +73 -0
  90. package/dist/components/rating.js +124 -0
  91. package/dist/components/reasoning.d.ts +16 -1
  92. package/dist/components/reasoning.js +10 -7
  93. package/dist/components/resizable.d.ts +10 -1
  94. package/dist/components/resizable.js +4 -1
  95. package/dist/components/response.d.ts +17 -5
  96. package/dist/components/response.js +58 -18
  97. package/dist/components/scroll-area.d.ts +1 -1
  98. package/dist/components/select.js +14 -3
  99. package/dist/components/separator.js +1 -1
  100. package/dist/components/sidebar.d.ts +20 -4
  101. package/dist/components/sidebar.js +70 -35
  102. package/dist/components/site-header.d.ts +46 -12
  103. package/dist/components/site-header.js +78 -19
  104. package/dist/components/skeleton.d.ts +1 -1
  105. package/dist/components/skeleton.js +1 -1
  106. package/dist/components/slider.js +3 -1
  107. package/dist/components/sortable.d.ts +178 -0
  108. package/dist/components/sortable.js +1282 -0
  109. package/dist/components/sources.d.ts +17 -2
  110. package/dist/components/sources.js +11 -4
  111. package/dist/components/spinner.d.ts +13 -1
  112. package/dist/components/spinner.js +5 -2
  113. package/dist/components/stat.d.ts +91 -0
  114. package/dist/components/stat.js +141 -0
  115. package/dist/components/stepper.d.ts +71 -0
  116. package/dist/components/stepper.js +101 -0
  117. package/dist/components/switch.d.ts +2 -2
  118. package/dist/components/switch.js +2 -2
  119. package/dist/components/table.d.ts +13 -3
  120. package/dist/components/table.js +231 -41
  121. package/dist/components/tabs.js +8 -4
  122. package/dist/components/tags-input.d.ts +18 -2
  123. package/dist/components/tags-input.js +66 -34
  124. package/dist/components/theme.d.ts +16 -2
  125. package/dist/components/theme.js +34 -8
  126. package/dist/components/time-field.d.ts +24 -4
  127. package/dist/components/time-field.js +32 -9
  128. package/dist/components/timeline.d.ts +18 -2
  129. package/dist/components/timeline.js +13 -4
  130. package/dist/components/tippy.d.ts +48 -0
  131. package/dist/components/tippy.js +648 -0
  132. package/dist/components/toast.d.ts +18 -2
  133. package/dist/components/toast.js +12 -3
  134. package/dist/components/toggle-group.js +1 -0
  135. package/dist/components/tool-call.d.ts +19 -8
  136. package/dist/components/tool-call.js +23 -7
  137. package/dist/components/toolbar.d.ts +1 -1
  138. package/dist/components/toolbar.js +10 -2
  139. package/dist/components/tooltip.d.ts +4 -2
  140. package/dist/components/tooltip.js +10 -4
  141. package/dist/components/tour.d.ts +127 -0
  142. package/dist/components/tour.js +673 -0
  143. package/dist/components/tree.js +45 -9
  144. package/dist/components/video-player.d.ts +10 -2
  145. package/dist/components/video-player.js +134 -38
  146. package/dist/illustration.d.ts +2 -0
  147. package/dist/illustration.js +7 -0
  148. package/dist/index.d.ts +11 -3
  149. package/dist/index.js +11 -3
  150. package/dist/lib/code-highlight.d.ts +3 -16
  151. package/dist/lib/code-highlight.js +160 -10
  152. package/dist/lib/code-theme.js +3 -3
  153. package/dist/lib/digit-roll.js +8 -8
  154. package/dist/lib/field-errors.d.ts +28 -0
  155. package/dist/lib/field-errors.js +24 -0
  156. package/dist/lib/field-value.d.ts +13 -0
  157. package/dist/lib/field-value.js +44 -0
  158. package/dist/lib/glide.d.ts +5 -4
  159. package/dist/lib/glide.js +5 -4
  160. package/dist/lib/graph-layout.js +11 -2
  161. package/dist/lib/money.d.ts +73 -0
  162. package/dist/lib/money.js +343 -0
  163. package/dist/lib/phone-countries.d.ts +1 -0
  164. package/dist/lib/phone-countries.js +281 -0
  165. package/dist/lib/phone.d.ts +90 -0
  166. package/dist/lib/phone.js +286 -0
  167. package/dist/lib/platform.d.ts +8 -3
  168. package/dist/lib/platform.js +13 -6
  169. package/dist/lib/row-index.d.ts +15 -0
  170. package/dist/lib/row-index.js +136 -0
  171. package/dist/lib/table-fit.d.ts +3 -2
  172. package/dist/lib/table-fit.js +52 -23
  173. package/dist/lib/theme-script.d.ts +15 -2
  174. package/dist/lib/theme-script.js +23 -3
  175. package/dist/lib/tippy/pixels.d.ts +47 -0
  176. package/dist/lib/tippy/pixels.js +187 -0
  177. package/dist/lib/tippy/sprite.d.ts +86 -0
  178. package/dist/lib/tippy/sprite.js +753 -0
  179. package/dist/messages/de.d.ts +12 -0
  180. package/dist/messages/de.js +326 -0
  181. package/dist/styles/expressive.css +60 -26
  182. package/dist/styles/index.css +11 -2
  183. package/dist/styles/material.css +47 -23
  184. package/dist/styles/parts/ai.css +4 -2
  185. package/dist/styles/parts/controls.css +85 -32
  186. package/dist/styles/parts/data.css +33 -5
  187. package/dist/styles/parts/feedback.css +110 -13
  188. package/dist/styles/parts/foundations.css +1 -1
  189. package/dist/styles/parts/navigation.css +230 -5
  190. package/dist/styles/parts/overlays.css +98 -11
  191. package/dist/styles/parts/pdf.css +13 -7
  192. package/dist/styles/tokens.css +28 -4
  193. package/dist/vite.d.ts +0 -50
  194. package/dist/vite.js +0 -100
  195. package/package.json +28 -33
  196. package/dist/components/code-highlight.d.ts +0 -13
  197. package/dist/components/code-highlight.js +0 -107
  198. package/dist/components/whiteboard.d.ts +0 -80
  199. package/dist/components/whiteboard.js +0 -389
  200. package/dist/styles/parts/whiteboard.css +0 -855
package/dist/vite.js CHANGED
@@ -1,6 +1,3 @@
1
- import { createReadStream, existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { dirname, join, sep } from "node:path";
4
1
  /**
5
2
  * Vite helper: proxies the Licht faces (Licht, Licht Sans, Licht Mono …) from zon.sh to the app's own origin.
6
3
  *
@@ -30,100 +27,3 @@ export function zonFonts(options = {}) {
30
27
  },
31
28
  };
32
29
  }
33
- /**
34
- * The Licht face each of Excalidraw's drawing fonts is drawn in, by Excalidraw's font folder.
35
- * Text on the canvas — and in its SVG and PNG exports — is set in Licht: Soft for normal text
36
- * (the default), Serif in place of the handwriting, Mono for code, Sans for the rest.
37
- */
38
- export const EXCALIDRAW_LICHT = {
39
- Nunito: "LichtSoft-Regular",
40
- Virgil: "LichtSoft-Regular",
41
- Excalifont: "LichtSerif-Regular",
42
- Lilita: "LichtSans-Regular",
43
- Liberation: "LichtSans-Regular",
44
- ComicShanns: "LichtMono-Regular",
45
- Cascadia: "LichtMono-Regular",
46
- };
47
- /**
48
- * Vite helper: serves Excalidraw's fonts — for Whiteboard (`@zonsh/ui/whiteboard`) — from the
49
- * app's own origin, at /excalidraw/fonts/*, instead of the CDN Excalidraw would use. In
50
- * development they stream from node_modules; a build writes them beside your assets.
51
- *
52
- * import { excalidrawAssets, zonFonts } from "@zonsh/ui/vite";
53
- * export default defineConfig({ plugins: [react(), tailwindcss(), zonFonts(), excalidrawAssets()] });
54
- *
55
- * Its drawing fonts are swapped for Licht (see EXCALIDRAW_LICHT): their requests go to
56
- * /licht/fonts/*, the same proxy zonFonts() sets up and your host mirrors in production. Only
57
- * Xiaolai, the CJK fallback, stays Excalidraw's.
58
- *
59
- * Pass the same folder to Whiteboard's `assetPath` (default `/excalidraw/`, plus your Vite
60
- * `base` if the app is not served from the root). Only the fonts a drawing uses are downloaded.
61
- */
62
- export function excalidrawAssets(options = {}) {
63
- const folder = (options.path ?? "excalidraw").replace(/^\/+|\/+$/g, "");
64
- const marker = `/${folder}/fonts/`;
65
- let fonts = "";
66
- const swapped = new RegExp(`"\\./fonts/(${Object.keys(EXCALIDRAW_LICHT).join("|")})/[^"]+\\.woff2"`, "g");
67
- /** Excalidraw's font folder, found from the app or, failing that, from this package. */
68
- const locate = (root) => {
69
- for (const from of [join(root, "package.json"), import.meta.url]) {
70
- try {
71
- const dir = join(dirname(createRequire(from).resolve("@excalidraw/excalidraw")), "fonts");
72
- if (existsSync(dir))
73
- return dir;
74
- }
75
- catch {
76
- // Not resolvable from here: try the next place.
77
- }
78
- }
79
- return "";
80
- };
81
- return {
82
- name: "zon-excalidraw-assets",
83
- configResolved(config) {
84
- fonts = locate(config.root);
85
- },
86
- configureServer(server) {
87
- server.middlewares.use((req, res, next) => {
88
- const url = (req.url ?? "").split("?")[0];
89
- const at = url.indexOf(marker);
90
- if (!fonts || at === -1)
91
- return next();
92
- const rest = decodeURIComponent(url.slice(at + marker.length));
93
- // A drawing font: its Licht face, through the /licht/fonts proxy.
94
- const licht = EXCALIDRAW_LICHT[rest.split("/")[0]];
95
- if (licht) {
96
- res.statusCode = 302;
97
- res.setHeader("Location", `/licht/fonts/${licht}.woff2`);
98
- res.end();
99
- return;
100
- }
101
- const file = join(fonts, rest);
102
- if (!file.startsWith(fonts) || !existsSync(file) || !statSync(file).isFile())
103
- return next();
104
- res.setHeader("Content-Type", file.endsWith(".woff2") ? "font/woff2" : "application/octet-stream");
105
- res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
106
- createReadStream(file).pipe(res);
107
- });
108
- },
109
- // In a build, Excalidraw asks for its drawing fonts at their Licht address directly. (In
110
- // development its prebundled code keeps its own paths, and the middleware above answers them.)
111
- transform(code, id) {
112
- if (!id.includes("excalidraw") || !code.includes('"./fonts/'))
113
- return null;
114
- const next = code.replace(swapped, (_, family) => `(location.origin+"/licht/fonts/${EXCALIDRAW_LICHT[family]}.woff2")`);
115
- return next === code ? null : { code: next, map: null };
116
- },
117
- generateBundle() {
118
- if (!fonts)
119
- return;
120
- for (const name of readdirSync(fonts, { recursive: true })) {
121
- const full = join(fonts, name);
122
- // Fonts Licht stands in for are never asked for.
123
- if (EXCALIDRAW_LICHT[name.split(sep)[0]] || !statSync(full).isFile())
124
- continue;
125
- this.emitFile({ type: "asset", fileName: `${folder}/fonts/${name.split(sep).join("/")}`, source: readFileSync(full) });
126
- }
127
- },
128
- };
129
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zonsh/ui",
3
- "version": "0.2.0",
3
+ "version": "0.5.0",
4
4
  "description": "zon component library — Base UI primitives in the zon material.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,10 +44,6 @@
44
44
  "types": "./dist/components/chart.d.ts",
45
45
  "default": "./dist/components/chart.js"
46
46
  },
47
- "./code-highlight": {
48
- "types": "./dist/components/code-highlight.d.ts",
49
- "default": "./dist/components/code-highlight.js"
50
- },
51
47
  "./data-table": {
52
48
  "types": "./dist/components/data-table.d.ts",
53
49
  "default": "./dist/components/data-table.js"
@@ -72,9 +68,17 @@
72
68
  "types": "./dist/components/graph.d.ts",
73
69
  "default": "./dist/components/graph.js"
74
70
  },
75
- "./whiteboard": {
76
- "types": "./dist/components/whiteboard.d.ts",
77
- "default": "./dist/components/whiteboard.js"
71
+ "./illustration": {
72
+ "types": "./dist/illustration.d.ts",
73
+ "default": "./dist/illustration.js"
74
+ },
75
+ "./tippy": {
76
+ "types": "./dist/components/tippy.d.ts",
77
+ "default": "./dist/components/tippy.js"
78
+ },
79
+ "./messages/de": {
80
+ "types": "./dist/messages/de.d.ts",
81
+ "default": "./dist/messages/de.js"
78
82
  },
79
83
  "./styles.css": "./dist/styles/index.css",
80
84
  "./tokens.css": "./dist/styles/tokens.css",
@@ -96,7 +100,6 @@
96
100
  },
97
101
  "peerDependencies": {
98
102
  "@dagrejs/dagre": "^3.1.1",
99
- "@excalidraw/excalidraw": "^0.18.1",
100
103
  "@tanstack/react-table": "^9.2.6",
101
104
  "@xyflow/react": "^12.12.0",
102
105
  "d3-force": "^3.0.0",
@@ -108,7 +111,6 @@
108
111
  "react-dom": ">=19",
109
112
  "react-resizable-panels": "^4.14.2",
110
113
  "recharts": "^3.10.1",
111
- "shiki": "^4.5.0",
112
114
  "tailwindcss": "^4.1.15",
113
115
  "vite": ">=6"
114
116
  },
@@ -116,9 +118,6 @@
116
118
  "@dagrejs/dagre": {
117
119
  "optional": true
118
120
  },
119
- "@excalidraw/excalidraw": {
120
- "optional": true
121
- },
122
121
  "@tanstack/react-table": {
123
122
  "optional": true
124
123
  },
@@ -146,43 +145,39 @@
146
145
  "recharts": {
147
146
  "optional": true
148
147
  },
149
- "shiki": {
150
- "optional": true
151
- },
152
148
  "vite": {
153
149
  "optional": true
154
150
  }
155
151
  },
156
152
  "dependencies": {
157
- "@base-ui/react": "^1.8.0",
158
- "@tanstack/react-virtual": "^3.14.19",
153
+ "@base-ui/react": "^1.9.0",
154
+ "@tanstack/react-virtual": "^3.14.26",
159
155
  "clsx": "^2.1.1",
160
- "lucide-react": "^1.49.0",
161
- "marked": "^18.1.2",
156
+ "lucide-react": "^1.67.0",
157
+ "marked": "^18.1.3",
158
+ "shiki": "^4.6.0",
162
159
  "tailwind-merge": "^3.7.0"
163
160
  },
164
161
  "devDependencies": {
165
- "@dagrejs/dagre": "^3.1.1",
166
- "@excalidraw/excalidraw": "^0.18.1",
167
- "@tanstack/react-table": "^9.2.6",
162
+ "@dagrejs/dagre": "^3.1.3",
163
+ "@tanstack/react-table": "^9.3.1",
168
164
  "@types/d3-force": "3.0.10",
169
- "@types/node": "^26.6.3",
165
+ "@types/node": "^26.6.6",
170
166
  "@types/react": "^19.3.0",
171
167
  "@types/react-dom": "^19.3.0",
172
- "@xyflow/react": "^12.12.0",
173
- "d3-force": "^3.0.0",
168
+ "@xyflow/react": "^12.12.1",
169
+ "d3-force": "^3.0.1",
174
170
  "date-fns": "^4.4.0",
175
171
  "embla-carousel-react": "^8.6.0",
176
- "pdfjs-dist": "^6.4.299",
177
- "react": "^19.3.0",
172
+ "pdfjs-dist": "^6.5.438",
173
+ "react": "^19.3.1",
178
174
  "react-day-picker": "^10.0.2",
179
- "react-dom": "^19.3.0",
180
- "react-resizable-panels": "^4.14.2",
175
+ "react-dom": "^19.3.1",
176
+ "react-resizable-panels": "^4.17.0",
181
177
  "recharts": "^3.10.1",
182
- "shiki": "4.5.0",
183
- "tailwindcss": "^4.3.3",
178
+ "tailwindcss": "^4.3.4",
184
179
  "typescript": "^7.0.2",
185
- "vite": "^8.3.2"
180
+ "vite": "^8.3.5"
186
181
  },
187
182
  "scripts": {
188
183
  "gen:index": "node ../../scripts/gen-index.mjs",
@@ -1,13 +0,0 @@
1
- import * as React from "react";
2
- import { zonCodeTheme } from "../lib/code-theme.js";
3
- export { zonCodeTheme };
4
- /**
5
- * CodeHighlightProvider — lets CodeBlocks inside it colour their code: a block with `highlight`
6
- * and a `language` is tokenised with Shiki, VS Code's own grammars, in the zon theme. Shiki and
7
- * each language load the first time a block needs them; until then, and for a language Shiki does
8
- * not know, the block stays plain mono. It is its own entry (`@zonsh/ui/code-highlight`) so the
9
- * main entry never pulls Shiki in; install `shiki` to use it.
10
- */
11
- export declare function CodeHighlightProvider({ children }: {
12
- children?: React.ReactNode;
13
- }): React.JSX.Element;
@@ -1,107 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import * as React from "react";
4
- import { CodeHighlighterContext } from "../lib/code-highlight.js";
5
- import { zonCodeTheme } from "../lib/code-theme.js";
6
- export { zonCodeTheme };
7
- /* One highlighter for the page, made on first use: Shiki's core, its JavaScript regex engine (no
8
- WebAssembly to fetch) and the grammars, each loaded only when a block asks for its language. */
9
- let core;
10
- const languages = new Map();
11
- const getCore = () => (core ??= Promise.all([import("shiki/core"), import("shiki/engine/javascript"), import("shiki/langs")]).then(async ([{ createHighlighterCore }, { createJavaScriptRegexEngine }, { bundledLanguages }]) => ({
12
- highlighter: await createHighlighterCore({
13
- themes: [zonCodeTheme],
14
- langs: [],
15
- engine: createJavaScriptRegexEngine({ forgiving: true }),
16
- }),
17
- langs: bundledLanguages,
18
- })));
19
- let ready;
20
- const loadedLanguages = new Set();
21
- /** Longer lines stay mono, as in VS Code: a minified file or a data URL would take the page with it. */
22
- const MAX_LINE = 5000;
23
- /**
24
- * The last few blocks coloured. Code that grows — a reply streaming in — keeps the lines it had:
25
- * only the new ones, and the last (still being written), are tokenised again.
26
- */
27
- const recent = [];
28
- /** `code`'s lines as tokens, and the state after them, going on from `state`. */
29
- function tokenizeLines(highlighter, code, lang, state) {
30
- const tokens = highlighter.codeToTokensBase(code, {
31
- lang,
32
- theme: "zon",
33
- tokenizeMaxLineLength: MAX_LINE,
34
- grammarState: state,
35
- });
36
- const lines = tokens.map((line) => line.map((token) => ({
37
- content: token.content,
38
- color: token.color,
39
- fontStyle: token.fontStyle,
40
- })));
41
- return { lines, state: highlighter.getLastGrammarState(tokens) ?? state };
42
- }
43
- const shiki = {
44
- load(language) {
45
- const lang = language.toLowerCase();
46
- let loading = languages.get(lang);
47
- if (!loading) {
48
- loading = getCore()
49
- .then(async ({ highlighter, langs }) => {
50
- // Its own keys only: a fence named `constructor` or `__proto__` is no grammar.
51
- const grammar = Object.hasOwn(langs, lang) ? langs[lang] : undefined;
52
- if (!grammar)
53
- return false;
54
- await highlighter.loadLanguage(grammar);
55
- ready = highlighter;
56
- loadedLanguages.add(lang);
57
- return true;
58
- })
59
- .catch(() => false);
60
- languages.set(lang, loading);
61
- }
62
- return loading;
63
- },
64
- tokenize(code, language) {
65
- const lang = language.toLowerCase();
66
- if (!ready || !loadedLanguages.has(lang))
67
- return null;
68
- try {
69
- const cut = code.lastIndexOf("\n");
70
- const head = cut === -1 ? "" : code.slice(0, cut);
71
- const at = recent.findIndex((r) => r.lang === lang && (head === r.head || head.startsWith(`${r.head}\n`)));
72
- let lines = [];
73
- let state;
74
- if (at !== -1) {
75
- const [hit] = recent.splice(at, 1);
76
- ({ lines, state } = hit);
77
- if (head !== hit.head) {
78
- const more = tokenizeLines(ready, head.slice(hit.head.length + 1), lang, state);
79
- lines = [...lines, ...more.lines];
80
- state = more.state;
81
- }
82
- }
83
- else if (cut !== -1) {
84
- ({ lines, state } = tokenizeLines(ready, head, lang, undefined));
85
- }
86
- if (cut !== -1) {
87
- recent.unshift({ lang, head, lines, state });
88
- recent.length = Math.min(recent.length, 8);
89
- }
90
- return [...lines, ...tokenizeLines(ready, code.slice(cut + 1), lang, state).lines];
91
- }
92
- catch {
93
- // A grammar that cannot take this code: it stays mono rather than taking the page down.
94
- return null;
95
- }
96
- },
97
- };
98
- /**
99
- * CodeHighlightProvider — lets CodeBlocks inside it colour their code: a block with `highlight`
100
- * and a `language` is tokenised with Shiki, VS Code's own grammars, in the zon theme. Shiki and
101
- * each language load the first time a block needs them; until then, and for a language Shiki does
102
- * not know, the block stays plain mono. It is its own entry (`@zonsh/ui/code-highlight`) so the
103
- * main entry never pulls Shiki in; install `shiki` to use it.
104
- */
105
- export function CodeHighlightProvider({ children }) {
106
- return _jsx(CodeHighlighterContext.Provider, { value: shiki, children: children });
107
- }
@@ -1,80 +0,0 @@
1
- import type { ExcalidrawElementSkeleton } from "@excalidraw/excalidraw/data/transform";
2
- import type { ExcalidrawElement } from "@excalidraw/excalidraw/element/types";
3
- import type { AppState, BinaryFiles, ExcalidrawImperativeAPI, LibraryItems } from "@excalidraw/excalidraw/types";
4
- import * as React from "react";
5
- /** A drawing: its elements, and optionally the view and the images it holds. */
6
- export interface WhiteboardScene {
7
- elements: readonly ExcalidrawElement[];
8
- appState?: Partial<AppState>;
9
- files?: BinaryFiles;
10
- }
11
- /** What a `ref` on Whiteboard gives you. */
12
- export interface WhiteboardHandle {
13
- /** Excalidraw's own API, once it has loaded: `updateScene`, `scrollToContent` and the rest. */
14
- readonly api: ExcalidrawImperativeAPI | null;
15
- /** The drawing as it is now. */
16
- getScene(): WhiteboardScene;
17
- /** The drawing as a PNG. `scale` 2 by default, for sharp screens. */
18
- toPng(options?: {
19
- scale?: number;
20
- background?: boolean;
21
- }): Promise<Blob>;
22
- /** The drawing as an SVG element. */
23
- toSvg(options?: {
24
- background?: boolean;
25
- }): Promise<SVGSVGElement>;
26
- /** Removes everything drawn. */
27
- clear(): void;
28
- }
29
- /**
30
- * A drawing to start from. Its elements are full Excalidraw elements (a saved scene), or simple
31
- * skeletons — `{ type: "rectangle", x, y, width, height, label: { text } }`, arrows with `start`
32
- * and `end` — which are filled in when the whiteboard loads.
33
- */
34
- export interface WhiteboardInitialData {
35
- elements: readonly (ExcalidrawElement | ExcalidrawElementSkeleton)[];
36
- appState?: Partial<AppState>;
37
- files?: BinaryFiles;
38
- /** The library to start with: shapes kept to place again. */
39
- libraryItems?: LibraryItems;
40
- }
41
- export interface WhiteboardProps extends Omit<React.ComponentProps<"div">, "onChange" | "ref"> {
42
- ref?: React.Ref<WhiteboardHandle>;
43
- /** The drawing to start from: a saved scene, or element skeletons. */
44
- initialData?: WhiteboardInitialData | null;
45
- /** Called when the drawing changes — not on every move of the pointer. */
46
- onChange?: (scene: WhiteboardScene) => void;
47
- /** Called when the library changes: something added to it or removed. Keep it to restore it. */
48
- onLibraryChange?: (items: LibraryItems) => void;
49
- /** Look, pan and zoom, but not draw. */
50
- readOnly?: boolean;
51
- /** Snap to a grid. */
52
- grid?: boolean;
53
- /** The name exports are saved under. */
54
- name?: string;
55
- /**
56
- * Where Excalidraw's fonts are served from, with a trailing slash: the folder that holds
57
- * `fonts/`. Default `/excalidraw/`. Serve them with `excalidrawAssets()` from `@zonsh/ui/vite`
58
- * — never from a CDN.
59
- */
60
- assetPath?: string;
61
- /** `region` (default): a square surface; `card`: the 20px object. */
62
- variant?: "region" | "card";
63
- /**
64
- * How new drawing looks. `clean` (default): crisp lines and thin strokes — the zon drawing.
65
- * `sketch`: Excalidraw's hand-drawn lines. Text is Licht Soft in both.
66
- */
67
- look?: "clean" | "sketch";
68
- }
69
- /**
70
- * Whiteboard — a canvas to draw on: shapes, arrows, text, freehand lines and images, in
71
- * Excalidraw's hand-drawn style, its interface set in the zon material and following light and
72
- * dark. Pan with a drag on empty space or the wheel, zoom with a pinch or Ctrl/⌘ and the wheel.
73
- *
74
- * Excalidraw is large, so it is loaded only when a whiteboard first appears; until then a
75
- * skeleton holds its place. It needs `@excalidraw/excalidraw` and is imported from
76
- * `@zonsh/ui/whiteboard`; serve its fonts from your own origin with `excalidrawAssets()`.
77
- * The rule people break: putting it on a page that does not need drawing, where it only costs
78
- * the download.
79
- */
80
- export declare function Whiteboard({ ref, initialData, onChange, onLibraryChange, readOnly, grid, name, assetPath, variant, look, className, ...props }: WhiteboardProps): React.JSX.Element;