nish-ui 1.9.0 → 2.0.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 (152) hide show
  1. package/README.md +218 -58
  2. package/dist/base-tailwind.css +1757 -0
  3. package/dist/base.css +1590 -1445
  4. package/dist/chart.d.ts +4 -1
  5. package/dist/chart.js +122 -49
  6. package/dist/elements-all.d.ts +8 -0
  7. package/dist/elements-all.js +178 -0
  8. package/dist/elements-charts.d.ts +71 -0
  9. package/dist/elements-charts.js +56 -57
  10. package/dist/elements-data.d.ts +71 -0
  11. package/dist/elements-data.js +5 -6
  12. package/dist/elements-forms.d.ts +71 -0
  13. package/dist/elements-forms.js +24 -25
  14. package/dist/elements.d.ts +71 -0
  15. package/dist/elements.js +4 -5
  16. package/dist/esm/chart-values.js +58 -0
  17. package/dist/esm/chart.js +10 -0
  18. package/dist/esm/cn.js +19 -0
  19. package/dist/esm/combobox-filter.js +13 -0
  20. package/dist/esm/components/accordion.js +166 -0
  21. package/dist/esm/components/app-shell.js +198 -0
  22. package/dist/esm/components/avatar-classes.js +28 -0
  23. package/dist/esm/components/avatar.js +113 -0
  24. package/dist/esm/components/breadcrumbs.js +154 -0
  25. package/dist/esm/components/canvas/follow-caption.js +32 -0
  26. package/dist/esm/components/canvas/follow.js +119 -0
  27. package/dist/esm/components/canvas/icons.js +70 -0
  28. package/dist/esm/components/canvas/index.js +10 -0
  29. package/dist/esm/components/canvas/layout.js +258 -0
  30. package/dist/esm/components/canvas/legend.js +93 -0
  31. package/dist/esm/components/canvas/minimap.js +127 -0
  32. package/dist/esm/components/canvas/node.js +87 -0
  33. package/dist/esm/components/canvas/route.js +262 -0
  34. package/dist/esm/components/canvas/system-canvas.js +837 -0
  35. package/dist/esm/components/canvas/types.js +10 -0
  36. package/dist/esm/components/canvas/view.js +47 -0
  37. package/dist/esm/components/chart-hooks.js +19 -0
  38. package/dist/esm/components/charts.js +467 -0
  39. package/dist/esm/components/client.js +24 -0
  40. package/dist/esm/components/combobox.js +343 -0
  41. package/dist/esm/components/command.js +403 -0
  42. package/dist/esm/components/data-classes.js +159 -0
  43. package/dist/esm/components/data.js +517 -0
  44. package/dist/esm/components/display-classes.js +130 -0
  45. package/dist/esm/components/display.js +755 -0
  46. package/dist/esm/components/error-boundary.js +64 -0
  47. package/dist/esm/components/feedback.js +136 -0
  48. package/dist/esm/components/file-dropzone.js +184 -0
  49. package/dist/esm/components/filters.js +108 -0
  50. package/dist/esm/components/flow.js +746 -0
  51. package/dist/esm/components/forms-classes.js +43 -0
  52. package/dist/esm/components/forms.js +581 -0
  53. package/dist/esm/components/hooks-classes.js +9 -0
  54. package/dist/esm/components/hooks.js +236 -0
  55. package/dist/esm/components/icons.js +96 -0
  56. package/dist/esm/components/inbox-classes.js +29 -0
  57. package/dist/esm/components/inbox.js +257 -0
  58. package/dist/esm/components/latest.js +13 -0
  59. package/dist/esm/components/layout-vars.js +96 -0
  60. package/dist/esm/components/layout.js +272 -0
  61. package/dist/esm/components/media.js +143 -0
  62. package/dist/esm/components/nav.js +614 -0
  63. package/dist/esm/components/overlay-classes.js +66 -0
  64. package/dist/esm/components/overlay.js +1461 -0
  65. package/dist/esm/components/pagination-classes.js +29 -0
  66. package/dist/esm/components/pagination.js +154 -0
  67. package/dist/esm/components/portal.js +16 -0
  68. package/dist/esm/components/primitives-classes.js +198 -0
  69. package/dist/esm/components/primitives.js +268 -0
  70. package/dist/esm/components/progress.js +77 -0
  71. package/dist/esm/components/provider.js +32 -0
  72. package/dist/esm/components/radio-group.js +186 -0
  73. package/dist/esm/components/resource-classes.js +133 -0
  74. package/dist/esm/components/resource.js +209 -0
  75. package/dist/esm/components/segmented.js +178 -0
  76. package/dist/esm/components/separator.js +38 -0
  77. package/dist/esm/components/service-tokens.js +221 -0
  78. package/dist/esm/components/settings.js +301 -0
  79. package/dist/esm/components/slider.js +262 -0
  80. package/dist/esm/components/split-classes.js +8 -0
  81. package/dist/esm/components/split.js +411 -0
  82. package/dist/esm/components/strings.js +119 -0
  83. package/dist/esm/components/table.js +144 -0
  84. package/dist/esm/components/tabs-classes.js +21 -0
  85. package/dist/esm/components/tabs.js +201 -0
  86. package/dist/esm/components/tag-input.js +257 -0
  87. package/dist/esm/components/theme-toggle.js +177 -0
  88. package/dist/esm/components/toast.js +361 -0
  89. package/dist/esm/components/url-state.js +118 -0
  90. package/dist/esm/components/visually-hidden.js +20 -0
  91. package/dist/esm/format.js +320 -0
  92. package/dist/esm/inbox-client.js +2 -0
  93. package/dist/esm/inbox-types.js +2 -0
  94. package/dist/esm/index.js +320 -0
  95. package/dist/esm/runtime.js +37 -0
  96. package/dist/esm/server/inbox/client.js +297 -0
  97. package/dist/esm/server/inbox/types.js +24 -0
  98. package/dist/esm/sparkline-path.js +59 -0
  99. package/dist/esm/split-layout.js +419 -0
  100. package/dist/esm/system-canvas.js +2 -0
  101. package/dist/esm/theme.js +804 -0
  102. package/dist/esm/tokens.mjs +425 -0
  103. package/dist/esm/url.js +20 -0
  104. package/dist/files.json +5 -1
  105. package/dist/fonts/LICENSE-Inter.txt +93 -0
  106. package/dist/format.d.ts +32 -18
  107. package/dist/format.js +227 -82
  108. package/dist/inbox-client.js +3 -1
  109. package/dist/index.d.ts +1686 -667
  110. package/dist/nish-components.css +4649 -4506
  111. package/dist/nish-components.min.css +1 -0
  112. package/dist/nish.css +1603 -1450
  113. package/dist/nish.min.css +1 -0
  114. package/dist/node/eslint.js +29 -14
  115. package/dist/node/th-check.js +29 -14
  116. package/dist/node/vite.d.ts +12 -0
  117. package/dist/node/vite.js +12 -2
  118. package/dist/server/hono.d.ts +15 -6
  119. package/dist/server/hono.js +30 -25
  120. package/dist/server/index.d.ts +3 -10
  121. package/dist/server/index.js +71 -38
  122. package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
  123. package/dist/system-canvas-BLuWd69H.d.ts +183 -0
  124. package/dist/system-canvas.d.ts +2 -168
  125. package/dist/tailwind-core.css +114 -0
  126. package/dist/tailwind.css +3 -7
  127. package/dist/theme-init.js +23 -9
  128. package/dist/theme-init.sha256 +1 -0
  129. package/dist/theme.d.ts +243 -4
  130. package/dist/theme.global.js +356 -89
  131. package/dist/theme.js +337 -67
  132. package/dist/tokens.css +14 -6
  133. package/dist/tokens.dtcg.json +1513 -0
  134. package/dist/tokens.js +29 -14
  135. package/dist/tokens.json +512 -0
  136. package/package.json +51 -13
  137. package/dist/chart.js.map +0 -1
  138. package/dist/elements-charts.js.map +0 -1
  139. package/dist/elements-data.js.map +0 -1
  140. package/dist/elements-forms.js.map +0 -1
  141. package/dist/elements.js.map +0 -1
  142. package/dist/format.js.map +0 -1
  143. package/dist/inbox-client.js.map +0 -1
  144. package/dist/index.js +0 -10260
  145. package/dist/index.js.map +0 -1
  146. package/dist/server/hono.js.map +0 -1
  147. package/dist/server/index.js.map +0 -1
  148. package/dist/split-layout.js.map +0 -1
  149. package/dist/system-canvas.js +0 -2204
  150. package/dist/system-canvas.js.map +0 -1
  151. package/dist/theme.global.js.map +0 -1
  152. package/dist/theme.js.map +0 -1
package/dist/theme.js CHANGED
@@ -24,7 +24,7 @@ var LIGHT_HUES = {
24
24
  var DARK_CHART = ["#8b93ff", "#34d399", "#fbbf24", "#fb7185", "#38bdf8", "#c084fc", "#fb923c", "#a3e635"];
25
25
  var LIGHT_CHART = ["#6366f1", "#059669", "#c96d06", "#f43f5e", "#0284c7", "#a855f7", "#ea580c", "#5a910c"];
26
26
  var chart = (list) => Object.fromEntries(list.map((c, i) => [`chart-${i + 1}`, c]));
27
- var THEMES = {
27
+ var RAW_THEMES = {
28
28
  dark: {
29
29
  label: "Dark",
30
30
  scheme: "dark",
@@ -35,6 +35,7 @@ var THEMES = {
35
35
  overlay: "#22252f",
36
36
  line: "#262935",
37
37
  "line-strong": "#3a3e4d",
38
+ "line-control": "#666975",
38
39
  hi: "#ececf1",
39
40
  hi2: "#a8aab7",
40
41
  hi3: "#8a8d9b",
@@ -63,9 +64,10 @@ var THEMES = {
63
64
  overlay: "#e6e4de",
64
65
  line: "#e2e0da",
65
66
  "line-strong": "#c9c6bd",
67
+ "line-control": "#8a8881",
66
68
  hi: "#17171c",
67
69
  hi2: "#4f515c",
68
- hi3: "#666874",
70
+ hi3: "#626470",
69
71
  ghost: "#8a8c98",
70
72
  accent: "#4338ca",
71
73
  accent2: "#7e22ce",
@@ -101,9 +103,10 @@ var THEMES = {
101
103
  overlay: "#36363d",
102
104
  line: "#3a3a42",
103
105
  "line-strong": "#52525b",
106
+ "line-control": "#77777e",
104
107
  hi: "#f4f4f5",
105
- hi2: "#a1a1aa",
106
- hi3: "#8f8f99",
108
+ hi2: "#b8b8c0",
109
+ hi3: "#a0a0a8",
107
110
  ghost: "#71717a",
108
111
  accent: "#a5b4fc",
109
112
  accent2: "#c084fc",
@@ -133,6 +136,7 @@ var THEMES = {
133
136
  overlay: "#1c2820",
134
137
  line: "#233028",
135
138
  "line-strong": "#34483b",
139
+ "line-control": "#5c6c61",
136
140
  hi: "#d1fae5",
137
141
  hi2: "#8fc4a8",
138
142
  hi3: "#74a68b",
@@ -161,9 +165,10 @@ var THEMES = {
161
165
  overlay: "#44403c",
162
166
  line: "#44403c",
163
167
  "line-strong": "#57534e",
168
+ "line-control": "#83807c",
164
169
  hi: "#f5f0eb",
165
- hi2: "#b3ada8",
166
- hi3: "#a39d98",
170
+ hi2: "#c6c0bb",
171
+ hi3: "#b2ada8",
167
172
  ghost: "#78716c",
168
173
  accent: "#fdba74",
169
174
  accent2: "#f472b6",
@@ -194,6 +199,7 @@ var THEMES = {
194
199
  overlay: "#103658",
195
200
  line: "#123050",
196
201
  "line-strong": "#1f4a72",
202
+ "line-control": "#507291",
197
203
  hi: "#e0f2fe",
198
204
  hi2: "#9ccde6",
199
205
  hi3: "#6fa9c6",
@@ -222,6 +228,7 @@ var THEMES = {
222
228
  overlay: "#222222",
223
229
  line: "#4a4a4a",
224
230
  "line-strong": "#8a8a8a",
231
+ "line-control": "#8a8a8a",
225
232
  hi: "#ffffff",
226
233
  hi2: "#d4d4d4",
227
234
  hi3: "#bdbdbd",
@@ -241,37 +248,220 @@ var THEMES = {
241
248
  }
242
249
  }
243
250
  };
244
- for (const t of Object.values(THEMES)) {
245
- for (const r of ["ok", "loss", "warn", "info"]) {
246
- t.colors[`${r}-fill`] ??= t.colors[r];
247
- t.colors[`on-${r}`] ??= t.colors["on-accent"];
251
+ var withFills = (t) => {
252
+ const c = t.colors;
253
+ const fills = Object.fromEntries(
254
+ ["ok", "loss", "warn", "info"].flatMap((r) => [
255
+ [`${r}-fill`, c[`${r}-fill`] ?? c[r]],
256
+ [`on-${r}`, c[`on-${r}`] ?? c["on-accent"]]
257
+ ])
258
+ );
259
+ return { ...t, colors: { ...c, ...fills, "on-accent2": c["on-accent2"] ?? c["on-accent"] } };
260
+ };
261
+ var THEMES = /* @__PURE__ */ Object.fromEntries(
262
+ Object.entries(RAW_THEMES).map(([name, t]) => [name, withFills(t)])
263
+ );
264
+ var DEFAULT_THEME = "dark";
265
+
266
+ // src/runtime.ts
267
+ var version = true ? "2.0.1" : "dev";
268
+ var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
269
+ function runtime() {
270
+ const g = globalThis;
271
+ return g[KEY] ??= { versions: /* @__PURE__ */ new Set(), slots: {} };
272
+ }
273
+ function register(rt) {
274
+ rt.versions.add(version);
275
+ if (rt.versions.size > 1 && !rt.warned && globalThis.process?.env?.NODE_ENV !== "production") {
276
+ rt.warned = true;
277
+ console.warn(
278
+ `nish-ui: two versions are loaded on this page (${[...rt.versions].join(", ")}). Overlays, toasts and theme state are shared, but mixing versions is unsupported.`
279
+ );
248
280
  }
249
- t.colors["on-accent2"] ??= t.colors["on-accent"];
250
281
  }
251
- var DEFAULT_THEME = "dark";
282
+ var registered = false;
283
+ function shared(key, init) {
284
+ const rt = runtime();
285
+ if (!registered) {
286
+ registered = true;
287
+ register(rt);
288
+ }
289
+ if (!(key in rt.slots)) rt.slots[key] = init();
290
+ return rt.slots[key];
291
+ }
292
+
293
+ // src/url.ts
294
+ function safeUrl(href) {
295
+ if (href == null) return null;
296
+ const raw = String(href);
297
+ let start = 0;
298
+ let end = raw.length;
299
+ while (start < end && raw.charCodeAt(start) <= 32) start++;
300
+ while (end > start && raw.charCodeAt(end - 1) <= 32) end--;
301
+ const out = raw.slice(start, end).replace(/[\t\n\r]/g, "");
302
+ if (out === "") return null;
303
+ if (out !== out.trim()) return null;
304
+ if (/[\u0000-\u001f\u007f]/.test(out)) return null;
305
+ const m = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(out);
306
+ if (!m) return out;
307
+ const scheme = m[1].toLowerCase();
308
+ return scheme === "http" || scheme === "https" || scheme === "mailto" || scheme === "tel" ? out : null;
309
+ }
310
+
311
+ // src/components/strings.ts
312
+ var DEFAULT_STRINGS = {
313
+ close: "Close",
314
+ cancel: "Cancel",
315
+ menu: "Menu",
316
+ back: "Back: ",
317
+ dismiss: "Dismiss",
318
+ moreCount: (count) => `${count} more`,
319
+ copy: "Copy",
320
+ copied: "Copied",
321
+ hubTitle: "Back to nish.software",
322
+ hubLabel: "\u2190 nish.software",
323
+ moreActions: "More actions",
324
+ more: "More",
325
+ legend: "Legend",
326
+ optional: "Optional",
327
+ search: "Search",
328
+ clearSearch: "Clear search",
329
+ remove: "Remove",
330
+ removeNamed: (name) => `Remove ${name}`,
331
+ noMatches: "No matches",
332
+ clear: "Clear",
333
+ searching: "Searching\u2026",
334
+ searchPlaceholder: "Search\u2026",
335
+ noResults: "No results",
336
+ results: "Results",
337
+ loading: "Loading",
338
+ failedToLoad: "Failed to load",
339
+ retry: "Retry",
340
+ actions: "Actions",
341
+ offline: "You're offline",
342
+ nothingHere: "Nothing here yet",
343
+ loadingNamed: (label) => `Loading ${label}`,
344
+ sortBy: "Sort by",
345
+ sortDefault: "Default",
346
+ noData: "No data",
347
+ noDataNamed: (label) => `${label}: no data`,
348
+ filters: "Filters",
349
+ clearFilters: "Clear filters",
350
+ done: "Done",
351
+ activeCount: (n) => `${n} active`,
352
+ newCount: (value) => `${value} new`,
353
+ sections: "Sections",
354
+ theme: "Theme",
355
+ sidebar: "Sidebar",
356
+ expandSidebar: "Expand sidebar",
357
+ collapseSidebar: "Collapse sidebar",
358
+ skipToContent: "Skip to content",
359
+ themeSystem: "System",
360
+ themeLight: "Light",
361
+ themeDark: "Dark",
362
+ themeToggleLabel: (current, next) => `Theme: ${current}. Switch to ${next}`,
363
+ themePreset: "Theme preset",
364
+ themePresetPlaceholder: "Preset\u2026",
365
+ errorStaleTitle: "A new version is available",
366
+ errorStaleBody: "Reload the page to get the latest version.",
367
+ errorTitle: "Something went wrong",
368
+ errorBody: "An unexpected error occurred.",
369
+ errorDetails: "Details",
370
+ errorTryAgain: "Try again",
371
+ errorReload: "Reload page",
372
+ saving: "Saving\u2026",
373
+ saved: "Saved",
374
+ saveFailed: "Could not save",
375
+ enterNumber: "Enter a number",
376
+ resizeColumns: "Resize columns",
377
+ resizeRows: "Resize rows",
378
+ layoutPresets: "Layout presets",
379
+ live: "Live",
380
+ offlineBadge: "Offline",
381
+ progress: "Progress",
382
+ workflow: "Workflow",
383
+ activity: "Activity",
384
+ other: "Other",
385
+ waiting: "Waiting",
386
+ noActivity: "No activity yet",
387
+ systemMap: "System map",
388
+ zoomOut: "Zoom out",
389
+ zoomIn: "Zoom in",
390
+ fitToScreen: "Fit to screen",
391
+ followActivity: "Follow activity",
392
+ canvasLines: "Lines",
393
+ serviceTokens: "Service tokens",
394
+ serviceTokensIntro: "Machine clients, like the nish MCP server, use these tokens to read this app. Revoking one stops it at once.",
395
+ loadingServiceTokens: "Loading service tokens",
396
+ tokenRevoke: "Revoke",
397
+ tokenRevoked: "Revoked",
398
+ tokenRevokedAt: (when) => `Revoked ${when}`,
399
+ tokenRevokeNamed: (name) => `Revoke ${name}`,
400
+ tokenRevokeTitle: (name) => `Revoke ${name}?`,
401
+ tokenRevokeFailed: "Could not revoke the token.",
402
+ inboxMarkHandled: "Mark handled",
403
+ inboxSnooze: "Snooze",
404
+ inboxActions: "Actions",
405
+ inboxViews: "Inbox views",
406
+ inboxOpen: "Open",
407
+ inboxSnoozed: "Snoozed",
408
+ inboxHandled: "Handled",
409
+ inboxFilterBySource: "Filter by source",
410
+ inboxHappened: (count) => `Happened ${count} times`,
411
+ previousPage: "Previous page",
412
+ nextPage: "Next page",
413
+ pageLabel: (n) => `Page ${n}`,
414
+ paginationLabel: "Pagination",
415
+ breadcrumbs: "Breadcrumbs",
416
+ removeTag: (tag) => `Remove ${tag}`,
417
+ dropzoneLabel: "Drop files here or browse",
418
+ browseFiles: "Browse files",
419
+ removeFile: (name) => `Remove ${name}`,
420
+ avatar: "Avatar",
421
+ avatarMore: (count) => `${count} more`,
422
+ sliderMin: "Minimum",
423
+ sliderMax: "Maximum",
424
+ accordion: "Accordion",
425
+ progressIndeterminate: "Loading"
426
+ };
252
427
 
253
428
  // src/theme.ts
254
- var PRESETS = Object.keys(THEMES).map((id) => ({
255
- id,
256
- label: THEMES[id].label,
257
- scheme: THEMES[id].scheme,
258
- colors: THEMES[id].colors
259
- }));
260
- var KEY = "nish-theme";
429
+ function buildPresets() {
430
+ return Object.keys(THEMES).map((id) => ({
431
+ id,
432
+ label: THEMES[id].label,
433
+ scheme: THEMES[id].scheme,
434
+ colors: THEMES[id].colors
435
+ }));
436
+ }
437
+ var PRESETS = /* @__PURE__ */ buildPresets();
438
+ var DEFAULT_KEY = "nish-theme";
261
439
  var SHARED_DOMAIN = "nish.software";
262
440
  var ONE_YEAR = 60 * 60 * 24 * 365;
263
- var extra = {};
441
+ var state = () => shared("theme", () => ({ extra: {}, listeners: /* @__PURE__ */ new Set(), watching: false, switchId: 0 }));
442
+ var warn = (msg) => {
443
+ if (globalThis.process?.env?.NODE_ENV !== "production") console.warn(`nish-ui: ${msg}`);
444
+ };
445
+ function storageKey() {
446
+ if (typeof document === "undefined") return DEFAULT_KEY;
447
+ const k = document.documentElement.getAttribute("data-nish-storage-key");
448
+ return k && /^[A-Za-z0-9_-]+$/.test(k) ? k : DEFAULT_KEY;
449
+ }
264
450
  function registerThemes(themes) {
265
- Object.assign(extra, themes);
451
+ Object.assign(state().extra, themes);
266
452
  }
267
453
  var has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
268
454
  function isThemeName(v) {
269
- return typeof v === "string" && (has(THEMES, v) || has(extra, v));
455
+ return typeof v === "string" && (has(THEMES, v) || has(state().extra, v));
270
456
  }
271
457
  function readCookie() {
272
458
  if (typeof document === "undefined") return null;
273
- const m = document.cookie.match(/(?:^|;\s*)nish-theme=([a-z0-9-]+)/);
274
- return m ? m[1] : null;
459
+ try {
460
+ const m = document.cookie.match(new RegExp(`(?:^|;\\s*)${storageKey()}=([a-z0-9-]+)`));
461
+ return m ? m[1] : null;
462
+ } catch {
463
+ return null;
464
+ }
275
465
  }
276
466
  var covers = (domain, host) => host === domain || host.endsWith("." + domain);
277
467
  function cookieDomain(host, attr) {
@@ -287,7 +477,7 @@ function sharedDomain() {
287
477
  function getThemeChoice() {
288
478
  let v = null;
289
479
  try {
290
- v = readCookie() ?? localStorage.getItem(KEY);
480
+ v = readCookie() ?? localStorage.getItem(storageKey());
291
481
  } catch {
292
482
  }
293
483
  return v === "system" || isThemeName(v) ? v : "system";
@@ -307,28 +497,49 @@ function resolveTheme(choice = getThemeChoice()) {
307
497
  return theme;
308
498
  }
309
499
  function schemeOf(theme) {
310
- return has(THEMES, theme) ? THEMES[theme].scheme : extra[theme] ?? "dark";
500
+ const { extra } = state();
501
+ return has(THEMES, theme) ? THEMES[theme].scheme : has(extra, theme) ? extra[theme] : "dark";
311
502
  }
312
503
  function applyTheme(choice = getThemeChoice()) {
313
504
  const theme = resolveTheme(choice);
314
505
  const root = document.documentElement;
506
+ const previous = root.getAttribute("data-theme");
507
+ if (previous && previous !== theme) suspendTransitions(root);
315
508
  root.setAttribute("data-theme", theme);
316
509
  root.setAttribute("data-scheme", schemeOf(theme));
317
510
  root.setAttribute("data-theme-choice", choice);
318
511
  root.style.colorScheme = schemeOf(theme);
319
512
  syncChromeColor();
320
- listeners.forEach((fn) => fn(choice, theme));
513
+ state().listeners.forEach((fn) => fn(choice, theme));
321
514
  return theme;
322
515
  }
516
+ function suspendTransitions(root) {
517
+ const st = state();
518
+ const id = ++st.switchId;
519
+ root.setAttribute("data-nish-theme-switching", "");
520
+ const done = () => {
521
+ if (st.switchId === id) root.removeAttribute("data-nish-theme-switching");
522
+ };
523
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => requestAnimationFrame(done));
524
+ else setTimeout(done, 32);
525
+ }
323
526
  function setThemeChoice(choice) {
527
+ if (choice !== "system" && !isThemeName(choice)) {
528
+ warn(`unknown theme "${String(choice)}" ignored. Register it with registerThemes() first.`);
529
+ return resolveTheme(getThemeChoice());
530
+ }
531
+ const key = storageKey();
324
532
  try {
325
- localStorage.setItem(KEY, choice);
533
+ localStorage.setItem(key, choice);
326
534
  } catch {
327
535
  }
328
- const domain = sharedDomain();
329
- if (domain) {
330
- const secure = location.protocol === "https:" ? "; Secure" : "";
331
- document.cookie = `${KEY}=${choice}; Domain=.${domain}; Path=/; Max-Age=${ONE_YEAR}; SameSite=Lax${secure}`;
536
+ try {
537
+ const domain = sharedDomain();
538
+ if (domain) {
539
+ const secure = location.protocol === "https:" ? "; Secure" : "";
540
+ document.cookie = `${key}=${choice}; Domain=.${domain}; Path=/; Max-Age=${ONE_YEAR}; SameSite=Lax${secure}`;
541
+ }
542
+ } catch {
332
543
  }
333
544
  return applyTheme(choice);
334
545
  }
@@ -338,26 +549,26 @@ function readToken(name) {
338
549
  function syncChromeColor() {
339
550
  const bg = readToken("bg");
340
551
  if (!bg) return;
341
- let meta = document.querySelector('meta[name="theme-color"]');
552
+ let meta = document.querySelector('meta[name="theme-color"][data-nish]') ?? document.querySelector('meta[name="theme-color"]:not([media]):not([data-nish-keep])');
342
553
  if (!meta) {
343
554
  meta = document.createElement("meta");
344
555
  meta.name = "theme-color";
345
- document.head.appendChild(meta);
556
+ (document.head || document.documentElement).appendChild(meta);
346
557
  }
558
+ meta.setAttribute("data-nish", "");
347
559
  meta.content = bg;
348
560
  }
349
- var listeners = /* @__PURE__ */ new Set();
350
- var watching = false;
351
561
  function watch() {
352
- if (watching || typeof window === "undefined") return;
353
- watching = true;
562
+ const st = state();
563
+ if (st.watching || typeof window === "undefined") return;
564
+ st.watching = true;
354
565
  const reapply = () => {
355
566
  const choice = getThemeChoice();
356
567
  if (choice !== document.documentElement.getAttribute("data-theme-choice") || choice === "system") applyTheme(choice);
357
568
  };
358
- matchMedia("(prefers-color-scheme: light)").addEventListener("change", reapply);
569
+ if (typeof matchMedia === "function") matchMedia("(prefers-color-scheme: light)").addEventListener("change", reapply);
359
570
  window.addEventListener("storage", (e) => {
360
- if (e.key === KEY) reapply();
571
+ if (e.key === storageKey()) reapply();
361
572
  });
362
573
  document.addEventListener("visibilitychange", () => {
363
574
  if (document.visibilityState === "visible") reapply();
@@ -365,8 +576,11 @@ function watch() {
365
576
  }
366
577
  function onThemeChange(fn) {
367
578
  watch();
579
+ const { listeners } = state();
368
580
  listeners.add(fn);
369
- return () => listeners.delete(fn);
581
+ return () => {
582
+ listeners.delete(fn);
583
+ };
370
584
  }
371
585
  var TOGGLE_ORDER = ["system", "light", "dark"];
372
586
  function cycleTheme() {
@@ -374,12 +588,47 @@ function cycleTheme() {
374
588
  setThemeChoice(next);
375
589
  return next;
376
590
  }
591
+ var SVG_NS = "http://www.w3.org/2000/svg";
592
+ function svgIcon(size, shapes, attrs = {}) {
593
+ const el = document.createElementNS(SVG_NS, "svg");
594
+ const all = {
595
+ width: String(size),
596
+ height: String(size),
597
+ viewBox: "0 0 24 24",
598
+ fill: "none",
599
+ stroke: "currentColor",
600
+ "stroke-width": "2",
601
+ "stroke-linecap": "round",
602
+ "stroke-linejoin": "round",
603
+ "aria-hidden": "true",
604
+ focusable: "false",
605
+ ...attrs
606
+ };
607
+ for (const k of Object.keys(all)) el.setAttribute(k, all[k]);
608
+ for (const [tag, a] of shapes) {
609
+ const child = document.createElementNS(SVG_NS, tag);
610
+ for (const k of Object.keys(a)) child.setAttribute(k, a[k]);
611
+ el.appendChild(child);
612
+ }
613
+ return el;
614
+ }
377
615
  var TOGGLE_ICONS = {
378
- system: '<rect width="20" height="14" x="2" y="3" rx="2"/><path d="M8 21h8M12 17v4"/>',
379
- light: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2m-7.07-2.93 1.41-1.41M17.66 6.34l1.41-1.41M2 12h2m16 0h2M4.93 4.93l1.41 1.41m11.32 11.32 1.41 1.41"/>',
380
- dark: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9"/>'
616
+ system: [
617
+ ["rect", { width: "20", height: "14", x: "2", y: "3", rx: "2" }],
618
+ ["path", { d: "M8 21h8M12 17v4" }]
619
+ ],
620
+ light: [
621
+ ["circle", { cx: "12", cy: "12", r: "4" }],
622
+ ["path", { d: "M12 2v2M12 20v2m-7.07-2.93 1.41-1.41M17.66 6.34l1.41-1.41M2 12h2m16 0h2M4.93 4.93l1.41 1.41m11.32 11.32 1.41 1.41" }]
623
+ ],
624
+ dark: [["path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9" }]]
381
625
  };
382
- var DEFAULT_TOGGLE_LABELS = { system: "System", light: "Light", dark: "Dark" };
626
+ var defaultToggleLabels = () => ({
627
+ system: DEFAULT_STRINGS.themeSystem,
628
+ light: DEFAULT_STRINGS.themeLight,
629
+ dark: DEFAULT_STRINGS.themeDark
630
+ });
631
+ var DEFAULT_ELSEWHERE = "set on another site";
383
632
  function nextChoice(choice) {
384
633
  const i = TOGGLE_ORDER.indexOf(choice);
385
634
  return TOGGLE_ORDER[(i + 1) % TOGGLE_ORDER.length];
@@ -390,11 +639,20 @@ function themeLabel(choice, words) {
390
639
  return choice.charAt(0).toUpperCase() + choice.slice(1);
391
640
  }
392
641
  function mountThemeToggle(button, opts = {}) {
393
- const words = { ...DEFAULT_TOGGLE_LABELS, ...opts.labels };
642
+ const words = { ...defaultToggleLabels(), ...opts.labels };
643
+ const sentence = opts.strings?.themeToggleLabel ?? DEFAULT_STRINGS.themeToggleLabel;
644
+ const elsewhereWords = opts.elsewhereLabel ?? DEFAULT_ELSEWHERE;
394
645
  if (button.tagName === "BUTTON" && !button.getAttribute("type")) button.setAttribute("type", "button");
395
- button.innerHTML = Object.keys(TOGGLE_ICONS).map(
396
- (id) => `<svg data-icon="${id}" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${TOGGLE_ICONS[id]}</svg>`
397
- ).join("") + (opts.showLabel ? '<span data-theme-word aria-hidden="true"></span>' : "");
646
+ const children = Object.keys(TOGGLE_ICONS).map(
647
+ (id) => svgIcon(16, TOGGLE_ICONS[id], { "data-icon": id })
648
+ );
649
+ if (opts.showLabel) {
650
+ const w = document.createElement("span");
651
+ w.setAttribute("data-theme-word", "");
652
+ w.setAttribute("aria-hidden", "true");
653
+ children.push(w);
654
+ }
655
+ button.replaceChildren(...children);
398
656
  const word = button.querySelector("[data-theme-word]");
399
657
  const render = (choice) => {
400
658
  const icon = choice === "system" || choice === "light" || choice === "dark" ? choice : schemeOf(choice);
@@ -403,8 +661,8 @@ function mountThemeToggle(button, opts = {}) {
403
661
  if (svg.getAttribute("data-icon") === icon) svg.removeAttribute("display");
404
662
  else svg.setAttribute("display", "none");
405
663
  });
406
- const elsewhere = TOGGLE_ORDER.includes(choice) ? "" : " (set on another site)";
407
- const label = `Theme: ${themeLabel(choice, words)}${elsewhere}. Switch to ${themeLabel(nextChoice(choice), words)}`;
664
+ const elsewhere = TOGGLE_ORDER.includes(choice) ? "" : ` (${elsewhereWords})`;
665
+ const label = sentence(`${themeLabel(choice, words)}${elsewhere}`, themeLabel(nextChoice(choice), words));
408
666
  button.setAttribute("aria-label", label);
409
667
  button.setAttribute("title", label);
410
668
  if (word) word.textContent = themeLabel(choice, words);
@@ -420,12 +678,23 @@ function mountThemeToggle(button, opts = {}) {
420
678
  off();
421
679
  };
422
680
  }
423
- var TOAST_ICON_PATHS = {
424
- neutral: '<circle cx="12" cy="12" r="10"/><path d="M12 16v-4M12 8h.01"/>',
425
- info: '<circle cx="12" cy="12" r="10"/><path d="M12 16v-4M12 8h.01"/>',
426
- ok: '<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',
427
- warn: '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4M12 17h.01"/>',
428
- loss: '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4M12 17h.01"/>'
681
+ var TRIANGLE = [
682
+ ["path", { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" }],
683
+ ["path", { d: "M12 9v4M12 17h.01" }]
684
+ ];
685
+ var INFO = [
686
+ ["circle", { cx: "12", cy: "12", r: "10" }],
687
+ ["path", { d: "M12 16v-4M12 8h.01" }]
688
+ ];
689
+ var TOAST_ICONS = {
690
+ neutral: INFO,
691
+ info: INFO,
692
+ ok: [
693
+ ["circle", { cx: "12", cy: "12", r: "10" }],
694
+ ["path", { d: "m9 12 2 2 4-4" }]
695
+ ],
696
+ warn: TRIANGLE,
697
+ loss: TRIANGLE
429
698
  };
430
699
  var TOAST_MS = 6e3;
431
700
  var toastRegion = null;
@@ -445,7 +714,7 @@ function showToast(content, opts = {}) {
445
714
  const icon = document.createElement("span");
446
715
  icon.className = "nish-toast-icon";
447
716
  icon.setAttribute("aria-hidden", "true");
448
- icon.innerHTML = `<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" focusable="false">${TOAST_ICON_PATHS[opts.tone ?? "neutral"]}</svg>`;
717
+ icon.append(svgIcon(15, TOAST_ICONS[opts.tone ?? "neutral"]));
449
718
  box.append(icon);
450
719
  const body = document.createElement("p");
451
720
  body.className = "nish-toast-body";
@@ -478,15 +747,16 @@ function showToast(content, opts = {}) {
478
747
  holds -= 1;
479
748
  if (holds === 0) run(Math.max(remaining, 1e3));
480
749
  };
481
- if (opts.action) {
482
- const a = opts.action;
483
- const el = document.createElement(a.href ? "a" : "button");
750
+ const action = opts.action;
751
+ const href = action?.href != null ? safeUrl(action.href) : null;
752
+ if (action && (action.href == null || href != null)) {
753
+ const el = document.createElement(action.href != null ? "a" : "button");
484
754
  el.className = "nish-toast-action";
485
- el.textContent = a.label;
486
- if (a.href) el.href = a.href;
755
+ el.textContent = action.label;
756
+ if (href != null) el.href = href;
487
757
  else el.type = "button";
488
758
  el.addEventListener("click", () => {
489
- a.onClick?.();
759
+ action.onClick?.();
490
760
  hide();
491
761
  });
492
762
  box.append(el);
@@ -494,8 +764,8 @@ function showToast(content, opts = {}) {
494
764
  const close = document.createElement("button");
495
765
  close.type = "button";
496
766
  close.className = "nish-toast-close";
497
- close.setAttribute("aria-label", opts.dismissLabel ?? "Dismiss");
498
- close.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M18 6 6 18M6 6l12 12"/></svg>';
767
+ close.setAttribute("aria-label", opts.dismissLabel ?? opts.strings?.dismiss ?? DEFAULT_STRINGS.dismiss);
768
+ close.append(svgIcon(14, [["path", { d: "M18 6 6 18M6 6l12 12" }]]));
499
769
  close.addEventListener("click", hide);
500
770
  box.append(close);
501
771
  box.addEventListener("pointerenter", (e) => e.pointerType === "mouse" && pause());
@@ -544,7 +814,7 @@ function confirmDialog(opts) {
544
814
  b.textContent = label;
545
815
  return b;
546
816
  };
547
- const cancelBtn = button(opts.cancelLabel ?? "Cancel", "nish-btn");
817
+ const cancelBtn = button(opts.cancelLabel ?? opts.strings?.cancel ?? DEFAULT_STRINGS.cancel, "nish-btn");
548
818
  const confirmBtn = button(opts.confirmLabel ?? "Confirm", `nish-btn ${danger ? "nish-btn--danger" : "nish-btn--primary"}`);
549
819
  (danger ? cancelBtn : confirmBtn).autofocus = true;
550
820
  actions.append(cancelBtn, confirmBtn);
package/dist/tokens.css CHANGED
@@ -109,6 +109,7 @@
109
109
  --nish-overlay: #22252f;
110
110
  --nish-line: #262935;
111
111
  --nish-line-strong: #3a3e4d;
112
+ --nish-line-control: #666975;
112
113
  --nish-hi: #ececf1;
113
114
  --nish-hi2: #a8aab7;
114
115
  --nish-hi3: #8a8d9b;
@@ -159,9 +160,10 @@
159
160
  --nish-overlay: #e6e4de;
160
161
  --nish-line: #e2e0da;
161
162
  --nish-line-strong: #c9c6bd;
163
+ --nish-line-control: #8a8881;
162
164
  --nish-hi: #17171c;
163
165
  --nish-hi2: #4f515c;
164
- --nish-hi3: #666874;
166
+ --nish-hi3: #626470;
165
167
  --nish-ghost: #8a8c98;
166
168
  --nish-accent: #4338ca;
167
169
  --nish-accent2: #7e22ce;
@@ -209,9 +211,10 @@
209
211
  --nish-overlay: #e6e4de;
210
212
  --nish-line: #e2e0da;
211
213
  --nish-line-strong: #c9c6bd;
214
+ --nish-line-control: #8a8881;
212
215
  --nish-hi: #17171c;
213
216
  --nish-hi2: #4f515c;
214
- --nish-hi3: #666874;
217
+ --nish-hi3: #626470;
215
218
  --nish-ghost: #8a8c98;
216
219
  --nish-accent: #4338ca;
217
220
  --nish-accent2: #7e22ce;
@@ -258,9 +261,10 @@
258
261
  --nish-overlay: #36363d;
259
262
  --nish-line: #3a3a42;
260
263
  --nish-line-strong: #52525b;
264
+ --nish-line-control: #77777e;
261
265
  --nish-hi: #f4f4f5;
262
- --nish-hi2: #a1a1aa;
263
- --nish-hi3: #8f8f99;
266
+ --nish-hi2: #b8b8c0;
267
+ --nish-hi3: #a0a0a8;
264
268
  --nish-ghost: #71717a;
265
269
  --nish-accent: #a5b4fc;
266
270
  --nish-accent2: #c084fc;
@@ -307,6 +311,7 @@
307
311
  --nish-overlay: #1c2820;
308
312
  --nish-line: #233028;
309
313
  --nish-line-strong: #34483b;
314
+ --nish-line-control: #5c6c61;
310
315
  --nish-hi: #d1fae5;
311
316
  --nish-hi2: #8fc4a8;
312
317
  --nish-hi3: #74a68b;
@@ -356,9 +361,10 @@
356
361
  --nish-overlay: #44403c;
357
362
  --nish-line: #44403c;
358
363
  --nish-line-strong: #57534e;
364
+ --nish-line-control: #83807c;
359
365
  --nish-hi: #f5f0eb;
360
- --nish-hi2: #b3ada8;
361
- --nish-hi3: #a39d98;
366
+ --nish-hi2: #c6c0bb;
367
+ --nish-hi3: #b2ada8;
362
368
  --nish-ghost: #78716c;
363
369
  --nish-accent: #fdba74;
364
370
  --nish-accent2: #f472b6;
@@ -405,6 +411,7 @@
405
411
  --nish-overlay: #103658;
406
412
  --nish-line: #123050;
407
413
  --nish-line-strong: #1f4a72;
414
+ --nish-line-control: #507291;
408
415
  --nish-hi: #e0f2fe;
409
416
  --nish-hi2: #9ccde6;
410
417
  --nish-hi3: #6fa9c6;
@@ -454,6 +461,7 @@
454
461
  --nish-overlay: #222222;
455
462
  --nish-line: #4a4a4a;
456
463
  --nish-line-strong: #8a8a8a;
464
+ --nish-line-control: #8a8a8a;
457
465
  --nish-hi: #ffffff;
458
466
  --nish-hi2: #d4d4d4;
459
467
  --nish-hi3: #bdbdbd;