nish-ui 3.1.0 → 3.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 (107) hide show
  1. package/README.md +13 -6
  2. package/dist/base-tailwind.css +30 -15
  3. package/dist/base.css +30 -15
  4. package/dist/chart.js +2 -2
  5. package/dist/elements-all.js +78 -78
  6. package/dist/elements-charts.d.ts +1 -1
  7. package/dist/elements-charts.js +43 -42
  8. package/dist/elements-data.d.ts +10 -0
  9. package/dist/elements-data.js +4 -5
  10. package/dist/elements-forms.js +9 -9
  11. package/dist/elements.d.ts +1 -0
  12. package/dist/elements.js +4 -4
  13. package/dist/esm/chart-values.js +2 -1
  14. package/dist/esm/combobox-filter.js +6 -5
  15. package/dist/esm/command-filter.js +83 -0
  16. package/dist/esm/components/accordion.js +5 -3
  17. package/dist/esm/components/app-shell.js +9 -5
  18. package/dist/esm/components/breadcrumbs.js +8 -4
  19. package/dist/esm/components/calendar-base.js +33 -6
  20. package/dist/esm/components/calendar-classes.js +14 -2
  21. package/dist/esm/components/canvas/follow-caption.js +31 -21
  22. package/dist/esm/components/canvas/follow.js +5 -6
  23. package/dist/esm/components/canvas/minimap.js +3 -3
  24. package/dist/esm/components/canvas/system-canvas.js +3 -1
  25. package/dist/esm/components/canvas/view.js +0 -2
  26. package/dist/esm/components/carousel.js +2 -3
  27. package/dist/esm/components/charts.js +18 -7
  28. package/dist/esm/components/combobox.js +20 -9
  29. package/dist/esm/components/command.js +25 -63
  30. package/dist/esm/components/context-menu.js +2 -1
  31. package/dist/esm/components/data-classes.js +23 -8
  32. package/dist/esm/components/data.js +19 -10
  33. package/dist/esm/components/display.js +24 -15
  34. package/dist/esm/components/drawer.js +17 -4
  35. package/dist/esm/components/error-boundary.js +3 -3
  36. package/dist/esm/components/feedback.js +4 -4
  37. package/dist/esm/components/file-dropzone.js +39 -7
  38. package/dist/esm/components/filters.js +42 -1
  39. package/dist/esm/components/flow.js +12 -9
  40. package/dist/esm/components/forms-classes.js +3 -1
  41. package/dist/esm/components/forms.js +8 -6
  42. package/dist/esm/components/hooks.js +47 -13
  43. package/dist/esm/components/hover-card.js +2 -1
  44. package/dist/esm/components/inbox.js +9 -2
  45. package/dist/esm/components/latest.js +4 -2
  46. package/dist/esm/components/layout.js +7 -4
  47. package/dist/esm/components/menu.js +14 -1
  48. package/dist/esm/components/modal.js +17 -4
  49. package/dist/esm/components/multi-select.js +7 -7
  50. package/dist/esm/components/nav-classes.js +9 -0
  51. package/dist/esm/components/nav.js +32 -12
  52. package/dist/esm/components/navigate.js +1 -1
  53. package/dist/esm/components/overlay-dialog.js +35 -1
  54. package/dist/esm/components/pagination.js +1 -1
  55. package/dist/esm/components/primitives-classes.js +4 -4
  56. package/dist/esm/components/primitives.js +18 -5
  57. package/dist/esm/components/progress.js +2 -1
  58. package/dist/esm/components/radio-group.js +1 -1
  59. package/dist/esm/components/resource-classes.js +7 -3
  60. package/dist/esm/components/resource.js +17 -6
  61. package/dist/esm/components/segmented.js +2 -0
  62. package/dist/esm/components/separator.js +6 -1
  63. package/dist/esm/components/service-tokens.js +18 -7
  64. package/dist/esm/components/settings.js +21 -1
  65. package/dist/esm/components/slider.js +5 -1
  66. package/dist/esm/components/split.js +4 -2
  67. package/dist/esm/components/strings.js +17 -4
  68. package/dist/esm/components/table.js +15 -3
  69. package/dist/esm/components/tabs.js +3 -2
  70. package/dist/esm/components/tag-input.js +5 -1
  71. package/dist/esm/components/time-field.js +15 -7
  72. package/dist/esm/components/toast-card.js +5 -3
  73. package/dist/esm/components/toast-store.js +16 -4
  74. package/dist/esm/components/toast.js +4 -1
  75. package/dist/esm/components/tooltip.js +3 -2
  76. package/dist/esm/components/url-state.js +5 -2
  77. package/dist/esm/components/virtual-table.js +2 -2
  78. package/dist/esm/components/virtual.js +8 -4
  79. package/dist/esm/format.js +27 -4
  80. package/dist/esm/runtime.js +9 -2
  81. package/dist/esm/server/inbox/client.js +4 -0
  82. package/dist/esm/split-layout.js +2 -1
  83. package/dist/esm/theme.js +38 -15
  84. package/dist/esm/tokens.mjs +1 -1
  85. package/dist/format.d.ts +5 -3
  86. package/dist/format.js +36 -7
  87. package/dist/inbox-client.d.ts +6 -2
  88. package/dist/inbox-client.js +4 -1
  89. package/dist/index.d.ts +65 -30
  90. package/dist/nish-components.css +70 -23
  91. package/dist/nish-components.min.css +1 -1
  92. package/dist/nish.css +30 -15
  93. package/dist/nish.min.css +1 -1
  94. package/dist/node/vite.js +1 -1
  95. package/dist/server/hono.d.ts +10 -3
  96. package/dist/server/hono.js +108 -11
  97. package/dist/server/index.d.ts +21 -13
  98. package/dist/server/index.js +124 -29
  99. package/dist/service-tokens.d.ts +4 -4
  100. package/dist/{spa-7myD4xvA.d.ts → spa-FwS7yZ8p.d.ts} +36 -7
  101. package/dist/split-layout.js +2 -2
  102. package/dist/system-canvas.d.ts +11 -10
  103. package/dist/theme.d.ts +30 -2
  104. package/dist/theme.global.js +53 -21
  105. package/dist/theme.js +53 -20
  106. package/package.json +3 -2
  107. package/dist/tokens.js +0 -425
@@ -120,12 +120,17 @@ function createLimiter(o = {}) {
120
120
  const cap = o.cap ?? 1e4;
121
121
  const entries = /* @__PURE__ */ new Map();
122
122
  const makeRoom = (now) => {
123
+ if (cap <= 0) return false;
123
124
  if (entries.size < cap) return true;
124
125
  for (const [k, v] of entries) if (v.reset <= now) entries.delete(k);
125
126
  for (const [k, v] of entries) {
126
127
  if (entries.size < cap) break;
127
128
  if (v.count < max) entries.delete(k);
128
129
  }
130
+ for (const k of entries.keys()) {
131
+ if (entries.size < cap) break;
132
+ entries.delete(k);
133
+ }
129
134
  return entries.size < cap;
130
135
  };
131
136
  const touch = (key, now) => {
@@ -246,6 +251,7 @@ function errorResponse(err, req, log = (line) => console.error(line)) {
246
251
  }
247
252
 
248
253
  // src/server/spa.ts
254
+ import { createHash as createHash2 } from "crypto";
249
255
  import { readFile, stat } from "fs/promises";
250
256
  import { resolve as resolve2, sep } from "path";
251
257
  var SECURITY_HEADERS = {
@@ -283,6 +289,35 @@ async function isFile(path) {
283
289
  return false;
284
290
  }
285
291
  }
292
+ function checkSources(list) {
293
+ const out = list ?? [];
294
+ for (const v of out) {
295
+ if (/[;,\r\n]/.test(v)) throw new Error(`@nish/ui/server: bad csp source: ${v}`);
296
+ }
297
+ return out;
298
+ }
299
+ function inlineScriptHashes(html) {
300
+ const lower = html.toLowerCase();
301
+ const hashes = /* @__PURE__ */ new Set();
302
+ let i = lower.indexOf("<script");
303
+ while (i >= 0) {
304
+ const tagEnd = lower.indexOf(">", i);
305
+ if (tagEnd < 0) break;
306
+ const next = lower.charAt(i + 7);
307
+ const isTag = next === ">" || next === "/" || /\s/.test(next);
308
+ const close = lower.indexOf("</script", tagEnd + 1);
309
+ if (isTag) {
310
+ const attrs = lower.slice(i + 7, tagEnd);
311
+ if (!/(?:^|[\s"'/])src\s*=/.test(attrs) && close >= 0) {
312
+ const content = html.slice(tagEnd + 1, close);
313
+ if (content.length > 0) hashes.add(`'sha256-${createHash2("sha256").update(content, "utf8").digest("base64")}'`);
314
+ }
315
+ }
316
+ if (close < 0) break;
317
+ i = lower.indexOf("<script", close);
318
+ }
319
+ return [...hashes];
320
+ }
286
321
  function createSpaHandler(o) {
287
322
  const dir = resolve2(o.dir);
288
323
  const indexName = o.index ?? "index.html";
@@ -292,10 +327,42 @@ function createSpaHandler(o) {
292
327
  const indexPath = resolve2(dir, indexName);
293
328
  const safety = { ...SECURITY_HEADERS };
294
329
  if (o.frameOptions !== false) safety["X-Frame-Options"] = "SAMEORIGIN";
330
+ const cspOpt = o.csp === "strict" ? {} : o.csp;
331
+ const cspConnect = checkSources(cspOpt?.connect);
332
+ const cspImg = checkSources(cspOpt?.img);
333
+ const cspScript = checkSources(cspOpt?.script);
334
+ const cspFrame = checkSources(cspOpt?.frameAncestors);
335
+ const cspHeader = cspOpt?.reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy";
336
+ const policies = /* @__PURE__ */ new Map();
337
+ const buildPolicy = (html) => [
338
+ "default-src 'self'",
339
+ ["script-src", "'self'", ...inlineScriptHashes(html), ...cspScript].join(" "),
340
+ "style-src 'self' 'unsafe-inline'",
341
+ ["img-src", "'self'", "data:", ...cspImg].join(" "),
342
+ ["connect-src", "'self'", ...cspConnect].join(" "),
343
+ "font-src 'self'",
344
+ "object-src 'none'",
345
+ "base-uri 'none'",
346
+ "form-action 'self'",
347
+ ["frame-ancestors", ...cspFrame.length ? cspFrame : ["'self'"]].join(" ")
348
+ ].join("; ");
295
349
  const text = (body, status) => new Response(body, { status, headers: { "Content-Type": "text/plain; charset=utf-8", ...safety } });
296
350
  const send = async (file, cache, head) => {
351
+ const type = contentType(file);
352
+ const headers = { "Content-Type": type, "Cache-Control": cache, ...safety };
353
+ if (cspOpt && type.startsWith("text/html")) {
354
+ const mtimeMs = (await stat(file)).mtimeMs;
355
+ const html = await readFile(file);
356
+ let hit = policies.get(file);
357
+ if (!hit || hit.mtimeMs !== mtimeMs) {
358
+ hit = { mtimeMs, policy: buildPolicy(html.toString("utf8")) };
359
+ policies.set(file, hit);
360
+ }
361
+ headers[cspHeader] = hit.policy;
362
+ return new Response(head ? null : html, { status: 200, headers });
363
+ }
297
364
  const body = head ? null : await readFile(file);
298
- return new Response(body, { status: 200, headers: { "Content-Type": contentType(file), "Cache-Control": cache, ...safety } });
365
+ return new Response(body, { status: 200, headers });
299
366
  };
300
367
  return async (req) => {
301
368
  const head = req.method === "HEAD";
@@ -324,6 +391,36 @@ function createSpaHandler(o) {
324
391
  };
325
392
  }
326
393
 
394
+ // src/server/direct-call.ts
395
+ var LOOPBACK_PEERS = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
396
+ var FORBIDDEN_HEADERS = ["forwarded", "via", "x-real-ip", "true-client-ip", "cdn-loop", "origin"];
397
+ var FORBIDDEN_PREFIXES = ["x-forwarded-", "cf-"];
398
+ function headerNames(headers) {
399
+ if (typeof headers.forEach === "function" && typeof headers.get === "function") {
400
+ const names = [];
401
+ headers.forEach((_v, k) => names.push(k.toLowerCase()));
402
+ return names;
403
+ }
404
+ return Object.entries(headers).filter(([, v]) => v !== void 0).map(([k]) => k.toLowerCase());
405
+ }
406
+ function headerValue(headers, name) {
407
+ if (typeof headers.get === "function") return headers.get(name) ?? void 0;
408
+ for (const [k, v] of Object.entries(headers)) {
409
+ if (k.toLowerCase() === name) return Array.isArray(v) ? v[0] : v;
410
+ }
411
+ return void 0;
412
+ }
413
+ function isDirectCall(req) {
414
+ if (!req.remoteAddress || !LOOPBACK_PEERS.has(req.remoteAddress)) return false;
415
+ if (headerValue(req.headers, "host") !== `127.0.0.1:${req.port}`) return false;
416
+ for (const name of headerNames(req.headers)) {
417
+ if (FORBIDDEN_HEADERS.includes(name)) return false;
418
+ if (FORBIDDEN_PREFIXES.some((p) => name.startsWith(p))) return false;
419
+ if (name.startsWith("sec-fetch-") && !(name === "sec-fetch-mode" && headerValue(req.headers, name) === "cors")) return false;
420
+ }
421
+ return true;
422
+ }
423
+
327
424
  // src/server/inbox/types.ts
328
425
  var INBOX_ACTION_HEADER = "X-Inbox-Action";
329
426
  var INBOX_ACTION_TIMEOUT_MS = 8e3;
@@ -580,6 +677,10 @@ function createInboxClient(options) {
580
677
  }
581
678
  if (queue[0] === head) queue.shift();
582
679
  if (result.kind === "ok") sentSinceDown++;
680
+ else if (!loggedInvalid.has(result.error)) {
681
+ loggedInvalid.add(result.error);
682
+ log(`queued event dropped: ${result.error}`);
683
+ }
583
684
  }
584
685
  retryStep = 0;
585
686
  if (down) {
@@ -636,39 +737,29 @@ function createInboxClient(options) {
636
737
  }
637
738
 
638
739
  // src/server/inbox/action.ts
639
- import { createHash as createHash2, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
740
+ import { createHash as createHash3, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
640
741
  var INBOX_ACTION_PATH = "/api/inbox/action";
641
742
  var ACTION_TOKEN_FIELD = "actionToken";
642
743
  var inboxActionTarget = (port, path) => `http://127.0.0.1:${port}${path ?? INBOX_ACTION_PATH}`;
643
- var LOOPBACK_PEERS = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
644
- var FORBIDDEN_HEADERS = ["forwarded", "via", "x-real-ip", "true-client-ip", "cdn-loop", "origin"];
645
- var FORBIDDEN_PREFIXES = ["x-forwarded-", "cf-"];
646
744
  var ACTION_ID_RE2 = /^[a-z0-9][a-z0-9-]{0,31}$/;
647
745
  var HASH_RE = /^[0-9a-f]{64}$/;
648
- function headerNames(headers) {
649
- if (typeof headers.forEach === "function" && typeof headers.get === "function") {
650
- const names = [];
651
- headers.forEach((_v, k) => names.push(k.toLowerCase()));
652
- return names;
653
- }
654
- return Object.entries(headers).filter(([, v]) => v !== void 0).map(([k]) => k.toLowerCase());
655
- }
656
- function headerValue(headers, name) {
657
- if (typeof headers.get === "function") return headers.get(name) ?? void 0;
746
+ function inboxHeader(headers) {
747
+ if (typeof headers.get === "function") return headers.get("x-inbox-action") ?? void 0;
658
748
  for (const [k, v] of Object.entries(headers)) {
659
- if (k.toLowerCase() === name) return Array.isArray(v) ? v[0] : v;
749
+ if (k.toLowerCase() === "x-inbox-action") return Array.isArray(v) ? v[0] : v;
660
750
  }
661
751
  return void 0;
662
752
  }
663
753
  function isInboxCall(req) {
664
- if (!req.remoteAddress || !LOOPBACK_PEERS.has(req.remoteAddress)) return false;
665
- if (headerValue(req.headers, "host") !== `127.0.0.1:${req.port}`) return false;
666
- for (const name of headerNames(req.headers)) {
667
- if (FORBIDDEN_HEADERS.includes(name)) return false;
668
- if (FORBIDDEN_PREFIXES.some((p) => name.startsWith(p))) return false;
669
- if (name.startsWith("sec-fetch-") && !(name === "sec-fetch-mode" && headerValue(req.headers, name) === "cors")) return false;
754
+ return isDirectCall(req) && inboxHeader(req.headers) === "1";
755
+ }
756
+ function validDedupeKey(k) {
757
+ if (typeof k !== "string" || k.length < 1 || k.length > 200) return false;
758
+ for (let i = 0; i < k.length; i++) {
759
+ const c = k.charCodeAt(i);
760
+ if (c < 32 || c === 127) return false;
670
761
  }
671
- return headerValue(req.headers, "x-inbox-action") === "1";
762
+ return true;
672
763
  }
673
764
  function parseInboxActionCall(body, source) {
674
765
  if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
@@ -677,23 +768,23 @@ function parseInboxActionCall(body, source) {
677
768
  if (typeof b.actionId !== "string" || !ACTION_ID_RE2.test(b.actionId)) return null;
678
769
  if (b.source !== source) return null;
679
770
  if (typeof b.kind !== "string") return null;
680
- if (b.dedupeKey !== null && typeof b.dedupeKey !== "string") return null;
771
+ if (b.dedupeKey !== null && !validDedupeKey(b.dedupeKey)) return null;
681
772
  const data = b.data;
682
- if (typeof data !== "object" || data === null || Array.isArray(data)) return null;
773
+ if (data !== null && data !== void 0 && (typeof data !== "object" || Array.isArray(data))) return null;
683
774
  return {
684
775
  itemId: b.itemId,
685
776
  actionId: b.actionId,
686
777
  source,
687
778
  kind: b.kind,
688
779
  dedupeKey: b.dedupeKey,
689
- data
780
+ data: data ?? {}
690
781
  };
691
782
  }
692
783
  function newActionToken() {
693
784
  return randomBytes2(32).toString("base64url");
694
785
  }
695
786
  function hashActionToken(token) {
696
- return createHash2("sha256").update(token, "utf8").digest("hex");
787
+ return createHash3("sha256").update(token, "utf8").digest("hex");
697
788
  }
698
789
  function actionTokenMatches(token, storedHash) {
699
790
  if (typeof token !== "string" || token.length < 1 || token.length > 128) return false;
@@ -706,12 +797,12 @@ function inboxAction(id, label, target) {
706
797
  }
707
798
 
708
799
  // src/server/service-tokens.ts
709
- import { createHash as createHash3, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual3 } from "crypto";
800
+ import { createHash as createHash4, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual3 } from "crypto";
710
801
  import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "fs";
711
802
  import { dirname as dirname2 } from "path";
712
803
  var TOKEN_RE = /^nish_[a-z][a-z0-9-]*_[A-Za-z0-9_-]{43}$/;
713
804
  var HEX_RE2 = /^[0-9a-f]{64}$/;
714
- var hashServiceToken = (token) => createHash3("sha256").update(token, "utf8").digest("hex");
805
+ var hashServiceToken = (token) => createHash4("sha256").update(token, "utf8").digest("hex");
715
806
  function mintServiceToken(app) {
716
807
  if (!/^[a-z][a-z0-9-]*$/.test(app)) throw new Error(`bad app name: ${app}`);
717
808
  const token = `nish_${app}_${randomBytes3(32).toString("base64url")}`;
@@ -772,6 +863,7 @@ function jsonRevocationStore(file) {
772
863
  };
773
864
  return {
774
865
  load() {
866
+ kept.length = 0;
775
867
  let text;
776
868
  try {
777
869
  text = readFileSync2(file, "utf8");
@@ -888,8 +980,10 @@ function isDirectLoopback(get, port) {
888
980
  if (get("origin") !== void 0) return false;
889
981
  return PROXY_HEADERS.every((h) => get(h) === void 0);
890
982
  }
983
+ var LOOPBACK_PEERS2 = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
891
984
  function checkServiceRequest(get, o) {
892
985
  if (!isDirectLoopback(get, o.port)) return { status: 403, error: "Forbidden" };
986
+ if ("remoteAddress" in o && (!o.remoteAddress || !LOOPBACK_PEERS2.has(o.remoteAddress))) return { status: 403, error: "Forbidden" };
893
987
  const r = o.tokens.verify(get("authorization"), o.scope);
894
988
  if (!r.ok) return { status: r.status, error: r.status === 401 ? "Unauthorized" : "Forbidden" };
895
989
  return null;
@@ -947,6 +1041,7 @@ export {
947
1041
  inboxActionTarget,
948
1042
  installProcessHandlers,
949
1043
  isCrossSiteWrite,
1044
+ isDirectCall,
950
1045
  isDirectLoopback,
951
1046
  isInboxActionTarget,
952
1047
  isInboxCall,
@@ -44,13 +44,13 @@ interface ServiceTokensSectionProps extends Omit<ComponentPropsWithRef<"section"
44
44
  /** Anchor id on the section. Default "service-tokens". */
45
45
  id?: string;
46
46
  className?: string;
47
- /** Shown when the list is empty. Default "No service tokens. No machine client can read this app." */
47
+ /** Shown when the list is empty. Default: the `tokenEmpty` string ("No service tokens. No machine client can read this app."). */
48
48
  emptyMessage?: ReactNode;
49
- /** The body of the revoke confirmation. Default explains that the token stops working and cannot be restored. */
49
+ /** The body of the revoke confirmation. Default: the `tokenRevokeBody` string, which explains that the token stops working and cannot be restored. */
50
50
  revokeBody?: ReactNode;
51
- /** The "created <date>" part of a token's description. Default `created ${when}`. */
51
+ /** The "created <date>" part of a token's description. Default: the `tokenCreated` string ("created <when>"). */
52
52
  createdLabel?: (when: string) => string;
53
- /** Added to the description of a token that comes from the SERVICE_TOKENS environment variable. Default "from SERVICE_TOKENS". */
53
+ /** Added to the description of a token that comes from the SERVICE_TOKENS environment variable. Default: the `tokenFromEnv` string ("from SERVICE_TOKENS"). */
54
54
  envSourceLabel?: string;
55
55
  }
56
56
  /** The settings block that lists an app's service tokens with a Revoke button each. */
@@ -1,4 +1,4 @@
1
- /** 127.0.0.0/8, ::1 and ::ffff:127.x. */
1
+ /** 127.0.0.0/8, ::1 and ::ffff:127.x. Not authentication: behind Caddy every public request arrives from loopback. */
2
2
  declare function isLoopback(address: string | null | undefined): boolean;
3
3
  /** Which forwarding headers `clientIp` believes.
4
4
  * - 'none' (default): none. The socket address is the client. Right when the app is reached directly.
@@ -91,7 +91,7 @@ interface InboxEventInput {
91
91
  kind: string;
92
92
  /** Headline, trimmed, 1-140 characters. Longer text is cut to 139 plus an ellipsis. */
93
93
  title: string;
94
- /** Details, trimmed, up to 2000 characters. Longer text is cut to 1999 plus an ellipsis; an empty string becomes undefined. */
94
+ /** Details, trimmed, up to 2000 characters. Longer text is cut to 1999 plus an ellipsis; an empty string becomes null. */
95
95
  body?: string;
96
96
  /** Link opened when the notification or item is tapped. http: or https:, up to 2000 characters. */
97
97
  url?: string;
@@ -103,7 +103,11 @@ interface InboxEventInput {
103
103
  resolve?: boolean;
104
104
  /** ISO 8601 time the event happened. Defaults to now; future times are clamped to now. */
105
105
  occurredAt?: string;
106
- /** Flat extra data, JSON-encoded at most 4096 bytes. */
106
+ /**
107
+ * Flat extra data, JSON-encoded at most 4096 bytes. Only data.actionToken (ACTION_TOKEN_FIELD) is private
108
+ * (stripped before the browser and /api/v1 see the item); every other key is visible in the inbox UI and API.
109
+ * /ingest trusts every local caller, so action routes must verify actionToken (actionTokenMatches) on every call.
110
+ */
107
111
  data?: InboxData;
108
112
  /** Up to 3 buttons shown on the item, ids unique. A repeat with the same dedupeKey replaces them. */
109
113
  actions?: Array<Omit<InboxAction, 'method'> & {
@@ -209,8 +213,9 @@ interface InboxListResponse {
209
213
  interface Limiter {
210
214
  /** Counts one attempt for key and says whether it may go ahead: true for the first `max`
211
215
  * attempts inside the current window, false after. Synchronous, so check it before any
212
- * `await` and parallel requests cannot all pass. A new key when the limiter is full of locked
213
- * keys gets false. */
216
+ * `await` and parallel requests cannot all pass. When the table is full, expired keys go first,
217
+ * then the oldest unlocked keys, then the oldest locked keys, so a flood of locked keys can
218
+ * never lock out a new client. */
214
219
  hit(key: string, now?: number): boolean;
215
220
  /** False once `max` failures happened inside the current window for key. */
216
221
  allowed(key: string, now?: number): boolean;
@@ -301,15 +306,21 @@ declare function loadManagedServiceTokens(o: {
301
306
  }): ManagedServiceTokens;
302
307
  declare function createServiceTokens(entries: ServiceTokenEntry[]): ServiceTokens;
303
308
  /**
304
- * True only for a request made straight to the app on loopback: Host is 127.0.0.1, localhost or
309
+ * Header-only check for a request made straight to the app: Host is 127.0.0.1, localhost or
305
310
  * [::1] with the app's port, there are no proxy headers and no Origin (browsers never get in).
311
+ * Every header is client-controlled, so this does not prove the socket peer is loopback.
312
+ * @deprecated Checks only headers; prefer isDirectCall, which also checks the socket peer.
306
313
  */
307
314
  declare function isDirectLoopback(get: (name: string) => string | undefined, port: number): boolean;
308
- /** Framework-free check: the status and body a guard should answer with, or null to continue. */
315
+ /** Framework-free check: the status and body a guard should answer with, or null to continue.
316
+ * Apps should pass `remoteAddress`, the socket peer (hono: `remoteAddressOf(c)`): when the property is present
317
+ * the request is also refused with 403 unless the peer is 127.0.0.1, ::1 or ::ffff:127.0.0.1 (null or empty is
318
+ * refused). Omitting it keeps the old header-only check. */
309
319
  declare function checkServiceRequest(get: (name: string) => string | undefined, o: {
310
320
  tokens: ServiceTokens;
311
321
  scope: string;
312
322
  port: number;
323
+ remoteAddress?: string | null;
313
324
  }): {
314
325
  status: 401 | 403;
315
326
  error: string;
@@ -368,7 +379,25 @@ interface SpaOptions {
368
379
  notBuilt?: string;
369
380
  /** Sends `X-Frame-Options: SAMEORIGIN` unless false (for an app that is meant to be framed). */
370
381
  frameOptions?: false;
382
+ /** Sends a Content-Security-Policy on HTML answers. Off by default. 'strict' or an object builds
383
+ * default-src 'self'; script-src 'self' <sha256 of every inline <script> in the HTML>; style-src 'self' 'unsafe-inline'; img-src 'self' data: <img>; connect-src 'self' <connect>; font-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'self' (or <frameAncestors>).
384
+ * reportOnly sends Content-Security-Policy-Report-Only instead, to try a policy first. */
385
+ csp?: 'strict' | {
386
+ connect?: string[];
387
+ img?: string[];
388
+ script?: string[];
389
+ frameAncestors?: string[];
390
+ reportOnly?: boolean;
391
+ };
371
392
  }
393
+ /**
394
+ * Serves a built single-page app: files under `dir`, the index for any other extensionless path.
395
+ *
396
+ * `csp` adds a Content-Security-Policy to HTML answers only. Every inline script in the HTML being
397
+ * served is hashed automatically, so the theme-init script that nishThemeInit() injects into the
398
+ * built index.html is allowed without copying its hash. An app that uses the nonce placeholder
399
+ * setup (`__NISH_CSP_NONCE__`) should leave `csp` off and send its own header.
400
+ */
372
401
  declare function createSpaHandler(o: SpaOptions): (req: Request) => Promise<Response>;
373
402
 
374
403
  export { createLimiter as A, createServiceTokens as B, createSessionAuth as D, createSessionToken as E, createSpaHandler as F, hashServiceToken as G, isCrossSiteWrite as H, isDirectLoopback as J, isLoopback as K, jsonRevocationStore as N, loadManagedServiceTokens as O, loadServiceTokens as P, mintServiceToken as Q, passwordMatches as U, readCookie as W, verifySessionToken as X, INBOX_ACTION_HEADER as h, INBOX_ACTION_TIMEOUT_MS as i, INBOX_DEFAULT_SETTINGS as j, INBOX_SOURCE_LABELS as k, MIN_SECRET_BYTES as r, SESSION_DAYS as t, checkServiceRequest as y, clientIp as z };
@@ -361,7 +361,8 @@ function swapSlots(slots, a, b) {
361
361
  function narrowLayout(count, n, aspect) {
362
362
  if (count === 1) return leaf(0);
363
363
  const dir = n.dir === "auto" ? aspect >= 1.2 ? "row" : "col" : n.dir;
364
- const split = Math.min(0.8, Math.max(0.2, n.split));
364
+ const s = Number.isFinite(n.split) ? n.split : 0.5;
365
+ const split = Math.min(0.8, Math.max(0.2, s));
365
366
  return {
366
367
  type: "split",
367
368
  dir,
@@ -417,4 +418,3 @@ export {
417
418
  resizeAt,
418
419
  swapSlots
419
420
  };
420
- //# sourceMappingURL=split-layout.js.map
@@ -123,6 +123,17 @@ interface CanvasLayout {
123
123
  h: number;
124
124
  }>;
125
125
  }
126
+ /** Options for `layoutSystem`. */
127
+ interface LayoutOptions {
128
+ /** Default "columns". */
129
+ mode?: "columns" | "bands";
130
+ /** "bands" only: the widest a row of groups may get, world px (at least one group per row). */
131
+ width?: number;
132
+ /** "bands" only: used to size the gaps between rows for the edge lanes. */
133
+ edges?: CanvasEdge[];
134
+ columnGap?: number;
135
+ rowGap?: number;
136
+ }
126
137
  /** Where every group and node sits, in world units (px at zoom 1). Pure and deterministic.
127
138
  *
128
139
  * "columns" (default): columns are the distinct `column` values in ascending order, groups
@@ -134,16 +145,6 @@ interface CanvasLayout {
134
145
  * "bands": bands are the distinct `band ?? column` values in ascending order, stacked top to
135
146
  * bottom; each band wraps its groups (by `column`, then input order) into rows no wider than
136
147
  * `width`. The gaps between rows grow with the number of edge ends that need lanes there. */
137
- interface LayoutOptions {
138
- /** Default "columns". */
139
- mode?: "columns" | "bands";
140
- /** "bands" only: the widest a row of groups may get, world px (at least one group per row). */
141
- width?: number;
142
- /** "bands" only: used to size the gaps between rows for the edge lanes. */
143
- edges?: CanvasEdge[];
144
- columnGap?: number;
145
- rowGap?: number;
146
- }
147
148
  declare function layoutSystem(groups: CanvasGroup[], o?: LayoutOptions): CanvasLayout;
148
149
  /** The layout to show in a viewport of `viewport` px. "columns" and "bands" use that mode;
149
150
  * "auto" picks whichever candidate shows the map biggest. Pure and deterministic. */
package/dist/theme.d.ts CHANGED
@@ -17,6 +17,8 @@ interface NishStrings {
17
17
  back: string;
18
18
  /** ContextMenu: the menu's accessible name when no menuLabel is given. */
19
19
  contextMenu: string;
20
+ /** CommandPalette: accessible name of the external-link mark on a row that opens in a new tab. */
21
+ opensInNewTab: string;
20
22
  /** VirtualTable: live-region message after the sort changes (dir null when cleared). */
21
23
  sortAnnounce: (header: string, dir: 'asc' | 'desc' | null) => string;
22
24
  /** Toast, Callout: dismiss button. */
@@ -27,6 +29,8 @@ interface NishStrings {
27
29
  copy: string;
28
30
  /** CopyButton: label after copying. */
29
31
  copied: string;
32
+ /** CopyButton: label when copying failed. */
33
+ copyFailed: string;
30
34
  /** AppHeader: hub pill title. */
31
35
  hubTitle: string;
32
36
  /** AppHeader: hub pill text. */
@@ -49,6 +53,8 @@ interface NishStrings {
49
53
  removeNamed: (name: string) => string;
50
54
  /** Combobox, CommandPalette: empty list. */
51
55
  noMatches: string;
56
+ /** Combobox, MultiSelect, CommandPalette: polite announcement of how many results are showing. */
57
+ resultsCount: (count: number) => string;
52
58
  /** Combobox, FilterBar, FilterSheet: clear button. */
53
59
  clear: string;
54
60
  /** Combobox: loading row. */
@@ -133,6 +139,8 @@ interface NishStrings {
133
139
  actions: string;
134
140
  /** ConnectionBanner: offline message. */
135
141
  offline: string;
142
+ /** ConnectionBanner: default message when the server probe fails. */
143
+ serverUnreachable: string;
136
144
  /** ResponsiveTable, AsyncPanel: empty state. */
137
145
  nothingHere: string;
138
146
  /** ResponsiveTable: skeleton label. */
@@ -145,6 +153,10 @@ interface NishStrings {
145
153
  noData: string;
146
154
  /** LineChart, BarChart: aria label of an empty chart. */
147
155
  noDataNamed: (label: string) => string;
156
+ /** RangeBar: default accessible name, with locale-formatted numbers (current is null when not set). */
157
+ rangeLabel: (low: string, high: string, current: string | null, min: string, max: string) => string;
158
+ /** LineChart: last row of the hidden data table when it was cut short. */
159
+ chartTruncated: (shown: number, total: number) => string;
148
160
  /** FilterBar, FilterSheet: title. */
149
161
  filters: string;
150
162
  /** FilterBar: clear all filters. */
@@ -157,6 +169,8 @@ interface NishStrings {
157
169
  newCount: (value: string | number) => string;
158
170
  /** BottomNav, NavRail, SectionNav: landmark. */
159
171
  sections: string;
172
+ /** SectionNav: default landmark name. */
173
+ onThisPage: string;
160
174
  /** MoreSheet: theme row. */
161
175
  theme: string;
162
176
  /** NavRail: sidebar landmark. */
@@ -249,6 +263,8 @@ interface NishStrings {
249
263
  followActivity: string;
250
264
  /** SystemCanvas legend: menu label. */
251
265
  canvasLines: string;
266
+ /** SystemCanvas: role description of the canvas region. */
267
+ canvasRole: string;
252
268
  /** ServiceTokens: title. */
253
269
  serviceTokens: string;
254
270
  /** ServiceTokens: intro text. */
@@ -267,6 +283,14 @@ interface NishStrings {
267
283
  tokenRevokeTitle: (name: string) => string;
268
284
  /** ServiceTokens: revoke failure with no message. */
269
285
  tokenRevokeFailed: string;
286
+ /** ServiceTokens: empty-list message. */
287
+ tokenEmpty: string;
288
+ /** ServiceTokens: body of the revoke confirm dialog. */
289
+ tokenRevokeBody: string;
290
+ /** ServiceTokens: created-at text on a row. */
291
+ tokenCreated: (when: string) => string;
292
+ /** ServiceTokens: source tag for a token that comes from the SERVICE_TOKENS environment variable. */
293
+ tokenFromEnv: string;
270
294
  /** Inbox: mark-handled action. */
271
295
  inboxMarkHandled: string;
272
296
  /** Inbox: snooze action. */
@@ -291,6 +315,8 @@ interface NishStrings {
291
315
  nextPage: string;
292
316
  /** Pagination: page button aria label. */
293
317
  pageLabel: (n: number) => string;
318
+ /** Pagination: compact text, for example "Page 3 of 10". */
319
+ pageOfCount: (page: number, count: number) => string;
294
320
  /** Pagination: nav landmark. */
295
321
  paginationLabel: string;
296
322
  /** Breadcrumbs: nav landmark. */
@@ -495,8 +521,10 @@ declare function mountScrollspy(nav: HTMLElement, o?: MountScrollspyOptions): ((
495
521
  * restored now. Updates the `.nish-checklist-progress` element before the list (or the
496
522
  * first one in its parent) to "{done} of {total}" and its `--p` meter. Without
497
523
  * `data-store` it still counts. Storage failures are ignored. Returns a function that
498
- * removes the listener. */
499
- declare function mountChecklist(list: HTMLElement): () => void;
524
+ * removes the listener. Pass `format` for another language than "{done} of {total}". */
525
+ declare function mountChecklist(list: HTMLElement, opts?: {
526
+ format?: (done: number, total: number) => string;
527
+ }): () => void;
500
528
  /** For pages without a framework: apply now and start syncing. */
501
529
  declare function initTheme(): ThemeName;
502
530