@hadoku/task-ui-components 0.0.0-stage → 4.20.3

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 (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +917 -2
  3. package/dist/app-header.css +288 -0
  4. package/dist/bento.css +143 -0
  5. package/dist/button.css +227 -0
  6. package/dist/components/AppHeader.d.ts +61 -0
  7. package/dist/components/AppHeader.d.ts.map +1 -0
  8. package/dist/components/AppHeader.js +23 -0
  9. package/dist/components/AppHeader.js.map +1 -0
  10. package/dist/components/BentoCard.d.ts +23 -0
  11. package/dist/components/BentoCard.d.ts.map +1 -0
  12. package/dist/components/BentoCard.js +49 -0
  13. package/dist/components/BentoCard.js.map +1 -0
  14. package/dist/components/BentoGrid.d.ts +24 -0
  15. package/dist/components/BentoGrid.d.ts.map +1 -0
  16. package/dist/components/BentoGrid.js +22 -0
  17. package/dist/components/BentoGrid.js.map +1 -0
  18. package/dist/components/Button.d.ts +28 -0
  19. package/dist/components/Button.d.ts.map +1 -0
  20. package/dist/components/Button.js +51 -0
  21. package/dist/components/Button.js.map +1 -0
  22. package/dist/components/ConnectedSettings.d.ts +53 -0
  23. package/dist/components/ConnectedSettings.d.ts.map +1 -0
  24. package/dist/components/ConnectedSettings.js +302 -0
  25. package/dist/components/ConnectedSettings.js.map +1 -0
  26. package/dist/components/ConnectedThemePicker.d.ts +52 -0
  27. package/dist/components/ConnectedThemePicker.d.ts.map +1 -0
  28. package/dist/components/ConnectedThemePicker.js +32 -0
  29. package/dist/components/ConnectedThemePicker.js.map +1 -0
  30. package/dist/components/ContextMenu.d.ts +22 -0
  31. package/dist/components/ContextMenu.d.ts.map +1 -0
  32. package/dist/components/ContextMenu.js +23 -0
  33. package/dist/components/ContextMenu.js.map +1 -0
  34. package/dist/components/HadokuThemePicker.d.ts +27 -0
  35. package/dist/components/HadokuThemePicker.d.ts.map +1 -0
  36. package/dist/components/HadokuThemePicker.js +19 -0
  37. package/dist/components/HadokuThemePicker.js.map +1 -0
  38. package/dist/components/LoadingSkeleton.d.ts +14 -0
  39. package/dist/components/LoadingSkeleton.d.ts.map +1 -0
  40. package/dist/components/LoadingSkeleton.js +62 -0
  41. package/dist/components/LoadingSkeleton.js.map +1 -0
  42. package/dist/components/Modal.d.ts +39 -0
  43. package/dist/components/Modal.d.ts.map +1 -0
  44. package/dist/components/Modal.js +106 -0
  45. package/dist/components/Modal.js.map +1 -0
  46. package/dist/components/NumberInput.d.ts +26 -0
  47. package/dist/components/NumberInput.d.ts.map +1 -0
  48. package/dist/components/NumberInput.js +131 -0
  49. package/dist/components/NumberInput.js.map +1 -0
  50. package/dist/components/Select.d.ts +52 -0
  51. package/dist/components/Select.d.ts.map +1 -0
  52. package/dist/components/Select.js +281 -0
  53. package/dist/components/Select.js.map +1 -0
  54. package/dist/components/SettingsModal.d.ts +69 -0
  55. package/dist/components/SettingsModal.d.ts.map +1 -0
  56. package/dist/components/SettingsModal.js +141 -0
  57. package/dist/components/SettingsModal.js.map +1 -0
  58. package/dist/components/ThemeIcons.d.ts +26 -0
  59. package/dist/components/ThemeIcons.d.ts.map +1 -0
  60. package/dist/components/ThemeIcons.js +74 -0
  61. package/dist/components/ThemeIcons.js.map +1 -0
  62. package/dist/components/ThemePicker.d.ts +28 -0
  63. package/dist/components/ThemePicker.d.ts.map +1 -0
  64. package/dist/components/ThemePicker.js +101 -0
  65. package/dist/components/ThemePicker.js.map +1 -0
  66. package/dist/components/Toast.d.ts +13 -0
  67. package/dist/components/Toast.d.ts.map +1 -0
  68. package/dist/components/Toast.js +70 -0
  69. package/dist/components/Toast.js.map +1 -0
  70. package/dist/components/Toaster.d.ts +19 -0
  71. package/dist/components/Toaster.d.ts.map +1 -0
  72. package/dist/components/Toaster.js +19 -0
  73. package/dist/components/Toaster.js.map +1 -0
  74. package/dist/components/Tooltip.d.ts +49 -0
  75. package/dist/components/Tooltip.d.ts.map +1 -0
  76. package/dist/components/Tooltip.js +143 -0
  77. package/dist/components/Tooltip.js.map +1 -0
  78. package/dist/context-menu.css +11 -0
  79. package/dist/controls.css +137 -0
  80. package/dist/hooks/useReducedMotion.d.ts +7 -0
  81. package/dist/hooks/useReducedMotion.d.ts.map +1 -0
  82. package/dist/hooks/useReducedMotion.js +25 -0
  83. package/dist/hooks/useReducedMotion.js.map +1 -0
  84. package/dist/hooks/useToast.d.ts +18 -0
  85. package/dist/hooks/useToast.d.ts.map +1 -0
  86. package/dist/hooks/useToast.js +28 -0
  87. package/dist/hooks/useToast.js.map +1 -0
  88. package/dist/icon-btn.css +64 -0
  89. package/dist/index.d.ts +49 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +72 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/lib/menuPlacement.d.ts +16 -0
  94. package/dist/lib/menuPlacement.d.ts.map +1 -0
  95. package/dist/lib/menuPlacement.js +19 -0
  96. package/dist/lib/menuPlacement.js.map +1 -0
  97. package/dist/lib/selectMenus.d.ts +30 -0
  98. package/dist/lib/selectMenus.d.ts.map +1 -0
  99. package/dist/lib/selectMenus.js +236 -0
  100. package/dist/lib/selectMenus.js.map +1 -0
  101. package/dist/lib/settingsClient.d.ts +120 -0
  102. package/dist/lib/settingsClient.d.ts.map +1 -0
  103. package/dist/lib/settingsClient.js +140 -0
  104. package/dist/lib/settingsClient.js.map +1 -0
  105. package/dist/lib/themeScope.d.ts +19 -0
  106. package/dist/lib/themeScope.d.ts.map +1 -0
  107. package/dist/lib/themeScope.js +10 -0
  108. package/dist/lib/themeScope.js.map +1 -0
  109. package/dist/lib/titleTooltips.d.ts +38 -0
  110. package/dist/lib/titleTooltips.d.ts.map +1 -0
  111. package/dist/lib/titleTooltips.js +166 -0
  112. package/dist/lib/titleTooltips.js.map +1 -0
  113. package/dist/lib/tooltipPlacement.d.ts +14 -0
  114. package/dist/lib/tooltipPlacement.d.ts.map +1 -0
  115. package/dist/lib/tooltipPlacement.js +34 -0
  116. package/dist/lib/tooltipPlacement.js.map +1 -0
  117. package/dist/modal.css +129 -0
  118. package/dist/number-input.css +131 -0
  119. package/dist/scrollbar.css +165 -0
  120. package/dist/select.css +251 -0
  121. package/dist/styles.css +1866 -0
  122. package/dist/task-ui-components.css +1866 -0
  123. package/dist/theme-picker.css +219 -0
  124. package/dist/toaster.css +159 -0
  125. package/dist/tooltip.css +103 -0
  126. package/dist/types/index.d.ts +37 -0
  127. package/dist/types/index.d.ts.map +1 -0
  128. package/package.json +60 -4
  129. package/src/app-header.css +288 -0
  130. package/src/bento.css +143 -0
  131. package/src/button.css +227 -0
  132. package/src/components/AppHeader.tsx +87 -0
  133. package/src/components/BentoCard.tsx +72 -0
  134. package/src/components/BentoGrid.tsx +48 -0
  135. package/src/components/Button.tsx +81 -0
  136. package/src/components/ConnectedSettings.tsx +465 -0
  137. package/src/components/ConnectedThemePicker.tsx +79 -0
  138. package/src/components/ContextMenu.tsx +48 -0
  139. package/src/components/HadokuThemePicker.tsx +39 -0
  140. package/src/components/LoadingSkeleton.tsx +84 -0
  141. package/src/components/Modal.tsx +171 -0
  142. package/src/components/NumberInput.tsx +161 -0
  143. package/src/components/Select.tsx +359 -0
  144. package/src/components/SettingsModal.tsx +235 -0
  145. package/src/components/ThemeIcons.tsx +127 -0
  146. package/src/components/ThemePicker.tsx +149 -0
  147. package/src/components/Toast.tsx +92 -0
  148. package/src/components/Toaster.tsx +43 -0
  149. package/src/components/Tooltip.tsx +212 -0
  150. package/src/context-menu.css +11 -0
  151. package/src/controls.css +137 -0
  152. package/src/hooks/useReducedMotion.ts +36 -0
  153. package/src/hooks/useToast.ts +57 -0
  154. package/src/icon-btn.css +64 -0
  155. package/src/index.ts +140 -0
  156. package/src/lib/menuPlacement.ts +31 -0
  157. package/src/lib/selectMenus.ts +303 -0
  158. package/src/lib/settingsClient.ts +377 -0
  159. package/src/lib/themeScope.ts +23 -0
  160. package/src/lib/titleTooltips.ts +236 -0
  161. package/src/lib/tooltipPlacement.ts +59 -0
  162. package/src/modal.css +129 -0
  163. package/src/number-input.css +131 -0
  164. package/src/scrollbar.css +165 -0
  165. package/src/select.css +251 -0
  166. package/src/theme-picker.css +219 -0
  167. package/src/toaster.css +159 -0
  168. package/src/tooltip.css +103 -0
  169. package/src/types/index.ts +43 -0
@@ -0,0 +1,140 @@
1
+ const CONTENT_LEVEL_PATH = "/prefs/api/v1/content-level";
2
+ const SESSION_NAME = "/session/name";
3
+ const SESSION_WHOAMI = "/session/whoami";
4
+ const WHOAMI_GLOBAL = "__hadokuWhoami";
5
+ const REQUEST_TIMEOUT_MS = 8e3;
6
+ function sessionHeaders(extra) {
7
+ const headers = { "Content-Type": "application/json", ...extra };
8
+ const sid = typeof window !== "undefined" ? localStorage.getItem("hadoku_session_id") : null;
9
+ if (sid) headers["X-Session-Id"] = sid;
10
+ return headers;
11
+ }
12
+ async function getContentLevel() {
13
+ try {
14
+ const res = await fetch(CONTENT_LEVEL_PATH, {
15
+ credentials: "same-origin",
16
+ headers: sessionHeaders(),
17
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
18
+ });
19
+ if (!res.ok) return null;
20
+ return await res.json();
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+ async function setContentLevel(level) {
26
+ try {
27
+ const res = await fetch(CONTENT_LEVEL_PATH, {
28
+ method: "PUT",
29
+ credentials: "same-origin",
30
+ headers: sessionHeaders(),
31
+ body: JSON.stringify({ level }),
32
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
33
+ });
34
+ if (!res.ok) return null;
35
+ const stored = await res.json();
36
+ patchSnapshot((prev) => ({ ...prev, content: stored }));
37
+ return stored;
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+ async function setDisplayName(name) {
43
+ try {
44
+ const res = await fetch(SESSION_NAME, {
45
+ method: "POST",
46
+ credentials: "same-origin",
47
+ headers: sessionHeaders(),
48
+ body: JSON.stringify({ name }),
49
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
50
+ });
51
+ if (!res.ok) return null;
52
+ const body = await res.json();
53
+ patchSnapshot((prev) => ({ ...prev, identity: { ...prev.identity, name: body.name } }));
54
+ return body.name;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+ function sharedWhoami() {
60
+ const g = globalThis;
61
+ g[WHOAMI_GLOBAL] ??= fetch(SESSION_WHOAMI, {
62
+ credentials: "same-origin",
63
+ headers: sessionHeaders(),
64
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
65
+ }).then((res) => res.ok ? res.json() : null).catch(() => null);
66
+ return g[WHOAMI_GLOBAL];
67
+ }
68
+ async function whoami() {
69
+ if (typeof window === "undefined") return { userType: "public", name: null };
70
+ try {
71
+ const body = await sharedWhoami();
72
+ if (!body?.valid) return { userType: "public", name: null };
73
+ return { userType: body.userType ?? "public", name: body.name ?? null };
74
+ } catch {
75
+ return { userType: "public", name: null };
76
+ }
77
+ }
78
+ function switchKeyHref() {
79
+ return "/auth?switch=1&return=" + encodeURIComponent(window.location.pathname + window.location.search + window.location.hash);
80
+ }
81
+ const SIGN_IN_MODULE = "/auth/sign-in.js";
82
+ let signInModule = null;
83
+ function loadSignIn() {
84
+ signInModule ??= import(
85
+ /* @vite-ignore */
86
+ SIGN_IN_MODULE
87
+ ).then(
88
+ (m) => typeof m.signIn === "function" ? m.signIn : null,
89
+ () => {
90
+ signInModule = null;
91
+ return null;
92
+ }
93
+ );
94
+ return signInModule;
95
+ }
96
+ let snapshot = null;
97
+ function prefetchSettings(hints = {}) {
98
+ snapshot ??= resolveSettings(hints);
99
+ return snapshot;
100
+ }
101
+ async function resolveSettings(hints) {
102
+ const selfResolving = hints.userType === void 0 && typeof window !== "undefined";
103
+ const bodyPromise = selfResolving ? sharedWhoami() : Promise.resolve(null);
104
+ const identityPromise = hints.userType !== void 0 ? Promise.resolve({ userType: hints.userType, name: hints.name ?? null }) : whoami();
105
+ const contentPromise = bodyPromise.then((body) => {
106
+ const carried = contentFromWhoami(body);
107
+ if (carried) return carried;
108
+ if (looksSignedIn(hints.userType)) return getContentLevel();
109
+ return identityPromise.then((id) => id.userType === "public" ? null : getContentLevel());
110
+ });
111
+ const [identity, content] = await Promise.all([identityPromise, contentPromise]);
112
+ return { identity, content };
113
+ }
114
+ function contentFromWhoami(body) {
115
+ if (!body?.valid) return null;
116
+ const { contentLevel, maxContentLevel } = body;
117
+ if (typeof contentLevel !== "number" || typeof maxContentLevel !== "number") return null;
118
+ if (maxContentLevel < 1) return null;
119
+ return { level: contentLevel, maxLevel: maxContentLevel };
120
+ }
121
+ function looksSignedIn(hinted) {
122
+ if (hinted !== void 0) return hinted !== "public";
123
+ if (typeof window === "undefined") return false;
124
+ const cached = localStorage.getItem("hadoku_user_type");
125
+ return cached !== null && cached !== "public";
126
+ }
127
+ function patchSnapshot(patch) {
128
+ if (!snapshot) return;
129
+ snapshot = snapshot.then(patch);
130
+ }
131
+ export {
132
+ getContentLevel,
133
+ loadSignIn,
134
+ prefetchSettings,
135
+ setContentLevel,
136
+ setDisplayName,
137
+ switchKeyHref,
138
+ whoami
139
+ };
140
+ //# sourceMappingURL=settingsClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settingsClient.js","sources":["../../src/lib/settingsClient.ts"],"sourcesContent":["/**\n * Client for the unified user-settings modal (ConnectedSettings).\n *\n * Two concerns, both cookie-authed against the hadoku.me edge-router, which\n * resolves the `hadoku_session` cookie / `X-Session-Id` header → X-User-Key +\n * X-User-Id for the backend:\n * - display name → POST /session/name (edge-router, self rename)\n * - content level → GET/PUT /prefs/api/v1/content-level (prefs-api)\n *\n * Switching keys goes through the SITE's sign-in client, never a call of ours:\n * see `loadSignIn()`, with `switchKeyHref()` as the fallback.\n *\n * These are same-origin relative paths, so ConnectedSettings is portable to any\n * app served under hadoku.me with zero wiring. Off-origin (e.g. a Storybook or\n * a non-hadoku host) every call resolves to null and the UI degrades to a\n * read-only shell — it never throws.\n *\n * The raw key is never held in the browser (the auth page deliberately drops\n * it), so name + content-level changes go through session identity, not a key\n * header, and no app ever asks for a key at all.\n *\n * WHEN THESE RUN\n * --------------\n * Everything the popout displays is resolved at PAGE LOAD, not on gear-click —\n * see `prefetchSettings()`. Opening settings must cost zero requests. Pinned by\n * `e2e/settings-prefetch.spec.ts` in hadoku-task.\n */\n\n/** Edge-router / prefs-api endpoints (same-origin relative). */\nconst CONTENT_LEVEL_PATH = '/prefs/api/v1/content-level'\nconst SESSION_NAME = '/session/name'\nconst SESSION_WHOAMI = '/session/whoami'\n\n/**\n * The ecosystem's shared boot-whoami promise. hadoku_site's `mf-loader.js`\n * kicks `GET /session/whoami` in parallel with the micro-frontend's module\n * import and parks the promise here precisely so the app it loads doesn't\n * resolve identity a second time; @wolffm/prefs-client already consumes it\n * under the same name. Reading it is what makes settings' identity free.\n *\n * Absent outside that shell (standalone vite, Capacitor, Storybook) — there we\n * fetch, and publish the result under the same key so the next reader is free\n * too.\n */\nconst WHOAMI_GLOBAL = '__hadokuWhoami'\n\n/**\n * Raw whoami body, as both mf-loader and this module see it off the wire.\n *\n * `contentLevel` / `maxContentLevel` are OPTIONAL because the shape is\n * versioned by whatever edge-router is deployed, not by this bundle. They\n * arrive from edge-router ≥ the 2026-08-07 change, which reports the level\n * `authGate` had already resolved to stamp X-Hadoku-Content-Level. When they\n * are absent we fall back to the standalone GET — see resolveSettings.\n */\ninterface WhoamiBody {\n valid?: boolean\n userType?: Tier\n name?: string | null\n contentLevel?: number\n maxContentLevel?: number\n}\n\n// Hard timeout on every settings request. Without it, a request throttled by\n// the browser (e.g. the tab going to the background) leaves the caller's\n// \"saving\" flag stuck true — which disabled the content-level pills until the\n// tab regained focus. AbortSignal.timeout guarantees the promise settles.\nconst REQUEST_TIMEOUT_MS = 8000\n\n/** Session-id header the same way whoami() sends it (cookie is the fallback). */\nfunction sessionHeaders(extra?: Record<string, string>): Record<string, string> {\n const headers: Record<string, string> = { 'Content-Type': 'application/json', ...extra }\n const sid = typeof window !== 'undefined' ? localStorage.getItem('hadoku_session_id') : null\n if (sid) headers['X-Session-Id'] = sid\n return headers\n}\n\nexport interface ContentLevelState {\n /** Current global content-visibility level (1 = safest default). */\n level: number\n /** Highest level this caller's tier may select (friend=3, admin=4). */\n maxLevel: number\n}\n\n/** GET the caller's current content level + tier ceiling. null on error. */\nexport async function getContentLevel(): Promise<ContentLevelState | null> {\n try {\n const res = await fetch(CONTENT_LEVEL_PATH, {\n credentials: 'same-origin',\n headers: sessionHeaders(),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)\n })\n if (!res.ok) return null\n return (await res.json()) as ContentLevelState\n } catch {\n return null\n }\n}\n\n/** PUT a new content level. Server clamps to the tier ceiling → 400 if out of\n * range. Returns the stored state on success, null on any failure. */\nexport async function setContentLevel(level: number): Promise<ContentLevelState | null> {\n try {\n const res = await fetch(CONTENT_LEVEL_PATH, {\n method: 'PUT',\n credentials: 'same-origin',\n headers: sessionHeaders(),\n body: JSON.stringify({ level }),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)\n })\n if (!res.ok) return null\n const stored = (await res.json()) as ContentLevelState\n patchSnapshot(prev => ({ ...prev, content: stored }))\n return stored\n } catch {\n return null\n }\n}\n\n/** POST a new display name for the signed-in user. Returns the stored name\n * (may differ from the request for wp-* protected keys) or null on failure. */\nexport async function setDisplayName(name: string): Promise<string | null> {\n try {\n const res = await fetch(SESSION_NAME, {\n method: 'POST',\n credentials: 'same-origin',\n headers: sessionHeaders(),\n body: JSON.stringify({ name }),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)\n })\n if (!res.ok) return null\n const body = (await res.json()) as { ok: boolean; name: string | null }\n patchSnapshot(prev => ({ ...prev, identity: { ...prev.identity, name: body.name } }))\n return body.name\n } catch {\n return null\n }\n}\n\n/**\n * The hadoku tier ladder, LOW to HIGH: `public < friend < service < wife < admin`.\n * Mirrors TIER_RANK in @wolffm/worker-utils, which this browser bundle cannot\n * import (it would pull hono into the client). A tier missing here does not\n * error — it fails the union and, worse, drops out of every `Record<Tier, …>`\n * lookup, so the caller renders as if unrecognised. Keep it complete.\n */\nexport type Tier = 'public' | 'friend' | 'service' | 'wife' | 'admin'\n\nexport interface Identity {\n userType: Tier\n name: string | null\n}\n\n/**\n * The page's one whoami body, resolved at most once no matter how many callers.\n *\n * Under the hadoku.me shell this costs NO request: mf-loader kicks whoami in\n * parallel with the micro-frontend's module import and parks the promise on\n * WHOAMI_GLOBAL for exactly this reason (@wolffm/prefs-client reads the same\n * key). Elsewhere — standalone vite, Capacitor, Storybook — we fetch once and\n * publish under the same key so the next reader is free too.\n *\n * Resolves to null rather than throwing on any failure.\n */\nfunction sharedWhoami(): Promise<WhoamiBody | null> {\n const g = globalThis as { [WHOAMI_GLOBAL]?: Promise<WhoamiBody | null> }\n g[WHOAMI_GLOBAL] ??= fetch(SESSION_WHOAMI, {\n credentials: 'same-origin',\n headers: sessionHeaders(),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)\n })\n .then(res => (res.ok ? (res.json() as Promise<WhoamiBody>) : null))\n .catch(() => null)\n return g[WHOAMI_GLOBAL]\n}\n\n/**\n * Resolve the signed-in caller's tier + display name from the edge-router.\n * Returns { userType: 'public', name: null } for anonymous / off-origin / any\n * failure — never throws, so ConnectedSettings can render unconditionally.\n */\nexport async function whoami(): Promise<Identity> {\n if (typeof window === 'undefined') return { userType: 'public', name: null }\n try {\n const body = await sharedWhoami()\n if (!body?.valid) return { userType: 'public', name: null }\n return { userType: body.userType ?? 'public', name: body.name ?? null }\n } catch {\n return { userType: 'public', name: null }\n }\n}\n\n/**\n * Where a \"Switch key\" control sends the user when the inline sign-in client\n * (`loadSignIn()`) can't be loaded: the site's sign-in page, which brings them\n * back here afterwards.\n *\n * A browser session is created ONLY by /auth (hadoku_site, 2026-10-25): every\n * render of that page carries an edge-signed funnel token and the device\n * fingerprint, and /session/create alerts on — and will refuse — a sign-in\n * without them. So an app never posts a key itself.\n *\n * `switch=1` stops /auth from sending an already signed-in visitor straight\n * back, which would make switching impossible. `return` is this page's path,\n * query and hash; /auth redirects there with the new session cookie, and the\n * shell's mf-loader resyncs the localStorage mirror (hadoku_session_id /\n * hadoku_user_type) from /session/whoami on that load, so nothing here writes it.\n */\nexport function switchKeyHref(): string {\n return (\n '/auth?switch=1&return=' +\n encodeURIComponent(window.location.pathname + window.location.search + window.location.hash)\n )\n}\n\n/** What the site's sign-in client resolves to on success. */\nexport interface SignInResult {\n valid: boolean\n userType?: string\n sessionId?: string\n}\n\n/** `signIn` from hadoku.me's `/auth/sign-in.js`. Resolves on success; throws an\n * `Error` carrying the server's message on a refused or empty key. */\nexport type SignIn = (key: string) => Promise<SignInResult>\n\n/**\n * The site serves its sign-in page's own client as a module, so an app can sign\n * in INLINE on the same code path as /auth: a fresh funnel token per call, the\n * device fingerprint, and the `/session/create` post that sets the cookie (and\n * writes the hadoku_session_id / hadoku_user_type mirror). This package never\n * posts /session/create itself — a direct post would skip the fingerprint and\n * read as off-funnel — and it does not vendor a copy.\n *\n * The specifier is a VARIABLE on purpose. A literal `import('/auth/sign-in.js')`\n * would have every bundler that re-bundles this package (hadoku_site's build\n * among them) try to resolve the path at build time; this one is only ever\n * resolved by the browser, against whatever origin the page is on. For the\n * same reason it is typed here (`SignIn`) rather than by an ambient module\n * declaration, which only a literal specifier would pick up.\n *\n * The module starts collecting the fingerprint as soon as it evaluates, so call\n * this when a sign-in form OPENS, not when it submits. Memoised; resolves to\n * null when the module can't be loaded (a dev server that isn't hadoku.me),\n * which is the caller's cue to fall back to `switchKeyHref()`.\n */\nconst SIGN_IN_MODULE = '/auth/sign-in.js'\nlet signInModule: Promise<SignIn | null> | null = null\n\nexport function loadSignIn(): Promise<SignIn | null> {\n signInModule ??= import(/* @vite-ignore */ SIGN_IN_MODULE).then(\n (m: { signIn?: unknown }) => (typeof m.signIn === 'function' ? (m.signIn as SignIn) : null),\n () => {\n // Let a later open retry: a failed fetch is not cached by the browser.\n signInModule = null\n return null\n }\n )\n return signInModule\n}\n\n/* ------------------------------------------------------------------ *\n * Prefetch\n * ------------------------------------------------------------------ */\n\n/** Everything the settings popout displays, resolved together. */\nexport interface SettingsSnapshot {\n identity: Identity\n /** null = public caller (no pill) or the request failed. */\n content: ContentLevelState | null\n}\n\n/** Identity the host already knows, so we don't ask the server for it again. */\nexport interface SettingsPrefetchHints {\n /** Caller's tier. When supplied, whoami is skipped entirely. */\n userType?: Tier\n /** Caller's display name. Only meaningful alongside `userType`. */\n name?: string | null\n}\n\nlet snapshot: Promise<SettingsSnapshot> | null = null\n\n/**\n * Resolve — once per page load — everything the settings popout shows.\n *\n * This is THE entry point, and it is called from ConnectedSettings' MOUNT, not\n * from its open handler. Settings data is user identity: it is known at boot,\n * it doesn't change while the page is up, and making the gear the trigger left\n * the panel on screen but blank for a round trip (measured on prod: whoami\n * 167ms and content-level 186ms, issued concurrently). It now rides along with\n * the app's own boot traffic and the click costs nothing.\n *\n * Idempotent and shared: every caller after the first gets the same promise, so\n * N mounted consumers still produce at most one whoami for the whole page.\n * Mutations below write through to it rather than invalidating, so a remount\n * never shows a value the user just changed.\n *\n * Against a current edge-router this issues NO requests of its own at all — the\n * level rides on the whoami the shell already had in flight. See\n * resolveSettings for the fallback when it doesn't.\n */\nexport function prefetchSettings(hints: SettingsPrefetchHints = {}): Promise<SettingsSnapshot> {\n snapshot ??= resolveSettings(hints)\n return snapshot\n}\n\nasync function resolveSettings(hints: SettingsPrefetchHints): Promise<SettingsSnapshot> {\n // The whoami body, not just the adapted identity — edge-router carries the\n // content level on it (see below), and reading the raw body is how we get at\n // it without a second request.\n //\n // Skipped entirely when the host supplied identity: that prop exists for apps\n // that CANNOT reach /session/whoami (conjure sits behind a path-prefixed shim\n // where it 404s), so asking anyway would spend a request to learn nothing.\n const selfResolving = hints.userType === undefined && typeof window !== 'undefined'\n const bodyPromise = selfResolving ? sharedWhoami() : Promise.resolve(null)\n\n const identityPromise: Promise<Identity> =\n hints.userType !== undefined\n ? Promise.resolve({ userType: hints.userType, name: hints.name ?? null })\n : whoami()\n\n // PREFERRED PATH: take the level straight off whoami.\n //\n // edge-router's authGate has already resolved it (registry key → userId →\n // prefs D1) to stamp X-Hadoku-Content-Level, so reporting it on whoami costs\n // it nothing — and it saves us a proxied round trip to prefs-api that\n // measured 132-420ms against prod. Better still, whoami is in flight before\n // this bundle has even loaded, so the value is here the moment we ask.\n //\n // FALLBACK: the standalone GET, for any edge-router older than the\n // 2026-08-07 change, and for callers not behind it at all (Capacitor,\n // Storybook, a non-hadoku host). Gated on identity because the pill is\n // hidden for public callers — fetching an anonymous visitor's level is a\n // guaranteed-wasted request on every page view. `hadoku_user_type` is\n // written by the loader before anything mounts, so where it already says\n // \"signed in\" the fallback goes out concurrently rather than behind whoami.\n const contentPromise = bodyPromise.then(body => {\n const carried = contentFromWhoami(body)\n if (carried) return carried\n if (looksSignedIn(hints.userType)) return getContentLevel()\n return identityPromise.then(id => (id.userType === 'public' ? null : getContentLevel()))\n })\n\n const [identity, content] = await Promise.all([identityPromise, contentPromise])\n return { identity, content }\n}\n\n/**\n * Adapt the content level off a whoami body, or null if that edge-router\n * doesn't report it.\n *\n * Both fields are required, and both must be numbers: a body carrying a level\n * without its ceiling would render a pill with zero segments — worse than the\n * fallback fetch, because it looks like a working control that offers nothing.\n */\nfunction contentFromWhoami(body: WhoamiBody | null): ContentLevelState | null {\n if (!body?.valid) return null\n const { contentLevel, maxContentLevel } = body\n if (typeof contentLevel !== 'number' || typeof maxContentLevel !== 'number') return null\n if (maxContentLevel < 1) return null\n return { level: contentLevel, maxLevel: maxContentLevel }\n}\n\n/** Best-effort \"is this caller signed in?\" from state available synchronously. */\nfunction looksSignedIn(hinted?: Tier): boolean {\n if (hinted !== undefined) return hinted !== 'public'\n if (typeof window === 'undefined') return false\n const cached = localStorage.getItem('hadoku_user_type')\n return cached !== null && cached !== 'public'\n}\n\n/** Keep the prefetched snapshot in step with a successful mutation. */\nfunction patchSnapshot(patch: (prev: SettingsSnapshot) => SettingsSnapshot) {\n if (!snapshot) return\n snapshot = snapshot.then(patch)\n}\n"],"names":[],"m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C;"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Where a popup (tooltip bubble, dropdown list) should be portalled.
3
+ *
4
+ * Theme tokens are scoped: HadokuThemeRoot puts `data-theme` on the app
5
+ * container, and a nested `[data-theme]` scope (a theme preview, an embedded
6
+ * board) can sit inside that. A popup must render inside the SAME scope as its
7
+ * anchor, or it paints in the wrong theme — portalled to <body>, it loses the
8
+ * container's tokens entirely.
9
+ *
10
+ * Rendering it in place keeps the theme but breaks on any ancestor with a
11
+ * `transform`, which becomes the containing block for `position: fixed` and
12
+ * drags the popup off its anchor. The nearest `[data-theme]` ancestor is the
13
+ * best of both: the right tokens, and above every transform between the
14
+ * anchor and the theme root. When the only match is <html>, <body> takes it —
15
+ * :root tokens reach body, and a portal into <html> itself would sit outside
16
+ * the document's body.
17
+ */
18
+ export declare function themeScopeOf(anchor: Element | null): HTMLElement | null;
19
+ //# sourceMappingURL=themeScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeScope.d.ts","sourceRoot":"","sources":["../../src/lib/themeScope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAKvE"}
@@ -0,0 +1,10 @@
1
+ function themeScopeOf(anchor) {
2
+ if (!anchor) return null;
3
+ const scope = anchor.closest("[data-theme]");
4
+ if (!scope || scope === document.documentElement) return document.body;
5
+ return scope;
6
+ }
7
+ export {
8
+ themeScopeOf
9
+ };
10
+ //# sourceMappingURL=themeScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeScope.js","sources":["../../src/lib/themeScope.ts"],"sourcesContent":["/**\n * Where a popup (tooltip bubble, dropdown list) should be portalled.\n *\n * Theme tokens are scoped: HadokuThemeRoot puts `data-theme` on the app\n * container, and a nested `[data-theme]` scope (a theme preview, an embedded\n * board) can sit inside that. A popup must render inside the SAME scope as its\n * anchor, or it paints in the wrong theme — portalled to <body>, it loses the\n * container's tokens entirely.\n *\n * Rendering it in place keeps the theme but breaks on any ancestor with a\n * `transform`, which becomes the containing block for `position: fixed` and\n * drags the popup off its anchor. The nearest `[data-theme]` ancestor is the\n * best of both: the right tokens, and above every transform between the\n * anchor and the theme root. When the only match is <html>, <body> takes it —\n * :root tokens reach body, and a portal into <html> itself would sit outside\n * the document's body.\n */\nexport function themeScopeOf(anchor: Element | null): HTMLElement | null {\n if (!anchor) return null\n const scope = anchor.closest<HTMLElement>('[data-theme]')\n if (!scope || scope === document.documentElement) return document.body\n return scope\n}\n"],"names":[],"mappings":"AAiBO,SAAS,aAAa,QAA4C;AACvE,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,QAAQ,OAAO,QAAqB,cAAc;AACxD,MAAI,CAAC,SAAS,UAAU,SAAS,wBAAwB,SAAS;AAClE,SAAO;AACT;"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Card tooltips for every `title=` on a page, with no change to the markup.
3
+ *
4
+ * import { installTitleTooltips } from '@wolffm/task-ui-components/title-tooltips'
5
+ * import '@wolffm/task-ui-components/tooltip.css'
6
+ * installTitleTooltips()
7
+ *
8
+ * hadoku_site calls this once from its shell, which covers every
9
+ * micro-frontend at once; an app does not call it itself. Framework-free and
10
+ * React-free on purpose: the shell has no React, and this must not pull a
11
+ * second copy into the page.
12
+ *
13
+ * One delegated listener set on the document. On hover (mouse only — touch
14
+ * never showed a native title either) or keyboard focus, the nearest element
15
+ * carrying `title` lends it to the bubble: the attribute moves to
16
+ * `data-hdk-title` for as long as the bubble is up, which is what stops the
17
+ * browser drawing its own on top, and goes back the moment it closes. So
18
+ * outside a hover the DOM is exactly what the app rendered, and code or a
19
+ * framework that reads or re-sets `title` sees its own value. A title the
20
+ * app changes mid-hover (a MutationObserver watches the anchor) re-stashes and
21
+ * updates the open bubble.
22
+ *
23
+ * Same contract as <Tooltip>: hover or focus shows it, Escape dismisses it
24
+ * until the pointer leaves, the pointer can move onto the bubble, a press
25
+ * closes it, and the anchor gets `aria-describedby` while it is up (skipped
26
+ * when the title only repeats the aria-label). The bubble is portalled into
27
+ * the anchor's theme scope, so a nested `[data-theme]` gets its own colours.
28
+ *
29
+ * Opt out per subtree with `data-native-title`.
30
+ */
31
+ import { type TooltipPlacement } from './tooltipPlacement';
32
+ export interface TitleTooltipOptions {
33
+ /** Hover delay before showing, ms. Focus shows immediately. */
34
+ delay?: number;
35
+ placement?: TooltipPlacement;
36
+ }
37
+ export declare function installTitleTooltips(options?: TitleTooltipOptions): () => void;
38
+ //# sourceMappingURL=titleTooltips.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"titleTooltips.d.ts","sourceRoot":"","sources":["../../src/lib/titleTooltips.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAExE,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B;AAQD,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,IAAI,CA6LlF"}
@@ -0,0 +1,166 @@
1
+ import { themeScopeOf } from "./themeScope.js";
2
+ import { placeTooltip } from "./tooltipPlacement.js";
3
+ const HIDE_GRACE_MS = 120;
4
+ const STASH = "data-hdk-title";
5
+ const BUBBLE_ID = "hdk-title-tooltip";
6
+ let uninstallCurrent = null;
7
+ function installTitleTooltips(options = {}) {
8
+ if (uninstallCurrent) return uninstallCurrent;
9
+ const delay = options.delay ?? 300;
10
+ const placement = options.placement ?? "top";
11
+ let anchor = null;
12
+ let bubble = null;
13
+ let timer;
14
+ let dismissed = null;
15
+ const observer = new MutationObserver(() => {
16
+ if (!anchor || !anchor.hasAttribute("title")) return;
17
+ stash(anchor);
18
+ if (bubble) {
19
+ bubble.textContent = anchor.getAttribute(STASH);
20
+ place();
21
+ }
22
+ });
23
+ function stash(el) {
24
+ el.setAttribute(STASH, el.getAttribute("title") ?? "");
25
+ el.removeAttribute("title");
26
+ }
27
+ function restore(el) {
28
+ const text = el.getAttribute(STASH);
29
+ if (text === null) return;
30
+ el.removeAttribute(STASH);
31
+ if (!el.hasAttribute("title")) el.setAttribute("title", text);
32
+ }
33
+ function titledFrom(target) {
34
+ if (!(target instanceof Element)) return null;
35
+ const el = target.closest(`[title], [${STASH}]`);
36
+ if (!el || el.tagName === "IFRAME" || el.closest("[data-native-title]")) return null;
37
+ return (el.getAttribute("title") ?? el.getAttribute(STASH) ?? "").trim() ? el : null;
38
+ }
39
+ function place() {
40
+ if (!anchor || !bubble) return;
41
+ if (!anchor.isConnected) {
42
+ hide(0);
43
+ return;
44
+ }
45
+ const p = placeTooltip(
46
+ placement,
47
+ anchor.getBoundingClientRect(),
48
+ bubble.offsetWidth,
49
+ bubble.offsetHeight
50
+ );
51
+ bubble.style.left = `${p.left}px`;
52
+ bubble.style.top = `${p.top}px`;
53
+ bubble.style.setProperty("--hdk-tooltip-arrow", `${p.arrow}px`);
54
+ bubble.className = `hdk-tooltip hdk-tooltip--card hdk-tooltip--plain hdk-tooltip--${p.side} hdk-tooltip--visible`;
55
+ }
56
+ function arm(el, after) {
57
+ clearTimeout(timer);
58
+ if (el !== anchor) {
59
+ release();
60
+ anchor = el;
61
+ stash(el);
62
+ observer.observe(el, { attributes: true, attributeFilter: ["title"] });
63
+ }
64
+ if (dismissed === el) return;
65
+ timer = setTimeout(open, after);
66
+ }
67
+ function open() {
68
+ if (!anchor) return;
69
+ const scope = themeScopeOf(anchor);
70
+ if (!scope) return;
71
+ if (!bubble) {
72
+ bubble = document.createElement("div");
73
+ bubble.id = BUBBLE_ID;
74
+ bubble.setAttribute("role", "tooltip");
75
+ bubble.addEventListener("pointerenter", () => clearTimeout(timer));
76
+ bubble.addEventListener("pointerleave", () => hide(HIDE_GRACE_MS));
77
+ }
78
+ const text = anchor.getAttribute(STASH) ?? "";
79
+ bubble.textContent = text;
80
+ bubble.className = `hdk-tooltip hdk-tooltip--card hdk-tooltip--plain hdk-tooltip--${placement}`;
81
+ bubble.style.left = "0px";
82
+ bubble.style.top = "0px";
83
+ if (bubble.parentNode !== scope) scope.appendChild(bubble);
84
+ if (text !== anchor.getAttribute("aria-label")) {
85
+ const ids = (anchor.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
86
+ if (!ids.includes(BUBBLE_ID))
87
+ anchor.setAttribute("aria-describedby", [...ids, BUBBLE_ID].join(" "));
88
+ }
89
+ place();
90
+ window.addEventListener("scroll", place, true);
91
+ window.addEventListener("resize", place);
92
+ }
93
+ function release() {
94
+ window.removeEventListener("scroll", place, true);
95
+ window.removeEventListener("resize", place);
96
+ bubble?.remove();
97
+ if (!anchor) return;
98
+ observer.disconnect();
99
+ const ids = (anchor.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((id) => id && id !== BUBBLE_ID);
100
+ if (ids.length) anchor.setAttribute("aria-describedby", ids.join(" "));
101
+ else anchor.removeAttribute("aria-describedby");
102
+ restore(anchor);
103
+ anchor = null;
104
+ }
105
+ function hide(after) {
106
+ clearTimeout(timer);
107
+ if (after === 0) release();
108
+ else timer = setTimeout(release, after);
109
+ }
110
+ const onPointerOver = (e) => {
111
+ if (e.pointerType !== "mouse") return;
112
+ if (bubble && bubble.contains(e.target)) return;
113
+ const el = titledFrom(e.target);
114
+ if (el && el === anchor && bubble?.isConnected) clearTimeout(timer);
115
+ else if (el) arm(el, delay);
116
+ };
117
+ const onPointerOut = (e) => {
118
+ if (e.pointerType !== "mouse") return;
119
+ const to = e.relatedTarget;
120
+ if (dismissed && !(to && dismissed.contains(to))) dismissed = null;
121
+ if (!anchor || to && (anchor.contains(to) || bubble?.contains(to))) return;
122
+ hide(HIDE_GRACE_MS);
123
+ };
124
+ const onPointerDown = () => {
125
+ if (anchor) dismissed = anchor;
126
+ hide(0);
127
+ };
128
+ const onFocusIn = (e) => {
129
+ const target = e.target;
130
+ if (!(target instanceof Element) || !target.matches(":focus-visible")) return;
131
+ const el = titledFrom(target);
132
+ if (el) {
133
+ dismissed = null;
134
+ arm(el, 0);
135
+ }
136
+ };
137
+ const onFocusOut = (e) => {
138
+ if (anchor && anchor.contains(e.target)) hide(0);
139
+ };
140
+ const onKeyDown = (e) => {
141
+ if (e.key !== "Escape" || !anchor || !bubble?.isConnected) return;
142
+ dismissed = anchor;
143
+ hide(0);
144
+ };
145
+ document.addEventListener("pointerover", onPointerOver);
146
+ document.addEventListener("pointerout", onPointerOut);
147
+ document.addEventListener("pointerdown", onPointerDown, true);
148
+ document.addEventListener("focusin", onFocusIn);
149
+ document.addEventListener("focusout", onFocusOut);
150
+ document.addEventListener("keydown", onKeyDown);
151
+ uninstallCurrent = () => {
152
+ hide(0);
153
+ document.removeEventListener("pointerover", onPointerOver);
154
+ document.removeEventListener("pointerout", onPointerOut);
155
+ document.removeEventListener("pointerdown", onPointerDown, true);
156
+ document.removeEventListener("focusin", onFocusIn);
157
+ document.removeEventListener("focusout", onFocusOut);
158
+ document.removeEventListener("keydown", onKeyDown);
159
+ uninstallCurrent = null;
160
+ };
161
+ return uninstallCurrent;
162
+ }
163
+ export {
164
+ installTitleTooltips
165
+ };
166
+ //# sourceMappingURL=titleTooltips.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"titleTooltips.js","sources":["../../src/lib/titleTooltips.ts"],"sourcesContent":["/**\n * Card tooltips for every `title=` on a page, with no change to the markup.\n *\n * import { installTitleTooltips } from '@wolffm/task-ui-components/title-tooltips'\n * import '@wolffm/task-ui-components/tooltip.css'\n * installTitleTooltips()\n *\n * hadoku_site calls this once from its shell, which covers every\n * micro-frontend at once; an app does not call it itself. Framework-free and\n * React-free on purpose: the shell has no React, and this must not pull a\n * second copy into the page.\n *\n * One delegated listener set on the document. On hover (mouse only — touch\n * never showed a native title either) or keyboard focus, the nearest element\n * carrying `title` lends it to the bubble: the attribute moves to\n * `data-hdk-title` for as long as the bubble is up, which is what stops the\n * browser drawing its own on top, and goes back the moment it closes. So\n * outside a hover the DOM is exactly what the app rendered, and code or a\n * framework that reads or re-sets `title` sees its own value. A title the\n * app changes mid-hover (a MutationObserver watches the anchor) re-stashes and\n * updates the open bubble.\n *\n * Same contract as <Tooltip>: hover or focus shows it, Escape dismisses it\n * until the pointer leaves, the pointer can move onto the bubble, a press\n * closes it, and the anchor gets `aria-describedby` while it is up (skipped\n * when the title only repeats the aria-label). The bubble is portalled into\n * the anchor's theme scope, so a nested `[data-theme]` gets its own colours.\n *\n * Opt out per subtree with `data-native-title`.\n */\n\nimport { themeScopeOf } from './themeScope'\nimport { placeTooltip, type TooltipPlacement } from './tooltipPlacement'\n\nexport interface TitleTooltipOptions {\n /** Hover delay before showing, ms. Focus shows immediately. */\n delay?: number\n placement?: TooltipPlacement\n}\n\nconst HIDE_GRACE_MS = 120\nconst STASH = 'data-hdk-title'\nconst BUBBLE_ID = 'hdk-title-tooltip'\n\nlet uninstallCurrent: (() => void) | null = null\n\nexport function installTitleTooltips(options: TitleTooltipOptions = {}): () => void {\n if (uninstallCurrent) return uninstallCurrent\n const delay = options.delay ?? 300\n const placement = options.placement ?? 'top'\n\n let anchor: Element | null = null\n let bubble: HTMLDivElement | null = null\n let timer: ReturnType<typeof setTimeout> | undefined\n // Escape closes the bubble until the pointer leaves that anchor (WCAG 1.4.13).\n let dismissed: Element | null = null\n\n const observer = new MutationObserver(() => {\n if (!anchor || !anchor.hasAttribute('title')) return\n stash(anchor)\n if (bubble) {\n bubble.textContent = anchor.getAttribute(STASH)\n place()\n }\n })\n\n function stash(el: Element) {\n el.setAttribute(STASH, el.getAttribute('title') ?? '')\n el.removeAttribute('title')\n }\n\n function restore(el: Element) {\n const text = el.getAttribute(STASH)\n if (text === null) return\n el.removeAttribute(STASH)\n if (!el.hasAttribute('title')) el.setAttribute('title', text)\n }\n\n function titledFrom(target: EventTarget | null): Element | null {\n if (!(target instanceof Element)) return null\n // The stash too: while the bubble is up the anchor carries data-hdk-title,\n // not title, and a pointerover on its own icon must still find IT rather\n // than a titled ancestor.\n const el = target.closest(`[title], [${STASH}]`)\n if (!el || el.tagName === 'IFRAME' || el.closest('[data-native-title]')) return null\n return (el.getAttribute('title') ?? el.getAttribute(STASH) ?? '').trim() ? el : null\n }\n\n function place() {\n if (!anchor || !bubble) return\n if (!anchor.isConnected) {\n hide(0)\n return\n }\n const p = placeTooltip(\n placement,\n anchor.getBoundingClientRect(),\n bubble.offsetWidth,\n bubble.offsetHeight\n )\n bubble.style.left = `${p.left}px`\n bubble.style.top = `${p.top}px`\n bubble.style.setProperty('--hdk-tooltip-arrow', `${p.arrow}px`)\n bubble.className = `hdk-tooltip hdk-tooltip--card hdk-tooltip--plain hdk-tooltip--${p.side} hdk-tooltip--visible`\n }\n\n /** Take the title off `el` now (before the browser's own ~1s delay runs\n * out) and open the bubble after `after` ms. */\n function arm(el: Element, after: number) {\n clearTimeout(timer)\n if (el !== anchor) {\n release()\n anchor = el\n stash(el)\n observer.observe(el, { attributes: true, attributeFilter: ['title'] })\n }\n if (dismissed === el) return\n timer = setTimeout(open, after)\n }\n\n function open() {\n if (!anchor) return\n const scope = themeScopeOf(anchor)\n if (!scope) return\n if (!bubble) {\n bubble = document.createElement('div')\n bubble.id = BUBBLE_ID\n bubble.setAttribute('role', 'tooltip')\n bubble.addEventListener('pointerenter', () => clearTimeout(timer))\n bubble.addEventListener('pointerleave', () => hide(HIDE_GRACE_MS))\n }\n const text = anchor.getAttribute(STASH) ?? ''\n bubble.textContent = text\n // Parked invisibly at the origin so it can be measured, then placed.\n bubble.className = `hdk-tooltip hdk-tooltip--card hdk-tooltip--plain hdk-tooltip--${placement}`\n bubble.style.left = '0px'\n bubble.style.top = '0px'\n if (bubble.parentNode !== scope) scope.appendChild(bubble)\n if (text !== anchor.getAttribute('aria-label')) {\n const ids = (anchor.getAttribute('aria-describedby') ?? '').split(/\\s+/).filter(Boolean)\n if (!ids.includes(BUBBLE_ID))\n anchor.setAttribute('aria-describedby', [...ids, BUBBLE_ID].join(' '))\n }\n place()\n window.addEventListener('scroll', place, true)\n window.addEventListener('resize', place)\n }\n\n /** Close the bubble and hand the anchor its title back. */\n function release() {\n window.removeEventListener('scroll', place, true)\n window.removeEventListener('resize', place)\n bubble?.remove()\n if (!anchor) return\n observer.disconnect()\n const ids = (anchor.getAttribute('aria-describedby') ?? '')\n .split(/\\s+/)\n .filter(id => id && id !== BUBBLE_ID)\n if (ids.length) anchor.setAttribute('aria-describedby', ids.join(' '))\n else anchor.removeAttribute('aria-describedby')\n restore(anchor)\n anchor = null\n }\n\n function hide(after: number) {\n clearTimeout(timer)\n if (after === 0) release()\n else timer = setTimeout(release, after)\n }\n\n const onPointerOver = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n if (bubble && bubble.contains(e.target as Node)) return\n // Back over the anchor of a bubble still up: just cancel the pending hide.\n // Over it with no bubble (inside the hide grace, or after a dismissal\n // that has since cleared), arm it again — otherwise it stays silent.\n const el = titledFrom(e.target)\n if (el && el === anchor && bubble?.isConnected) clearTimeout(timer)\n else if (el) arm(el, delay)\n }\n\n const onPointerOut = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n const to = e.relatedTarget as Node | null\n // Checked before `anchor`: a dismissal has already released the anchor.\n if (dismissed && !(to && dismissed.contains(to))) dismissed = null\n if (!anchor || (to && (anchor.contains(to) || bubble?.contains(to)))) return\n hide(HIDE_GRACE_MS)\n }\n\n // A press closes it, as it does a native title: the click usually opens\n // something the bubble would sit on top of.\n const onPointerDown = () => {\n if (anchor) dismissed = anchor\n hide(0)\n }\n\n const onFocusIn = (e: FocusEvent) => {\n const target = e.target\n if (!(target instanceof Element) || !target.matches(':focus-visible')) return\n const el = titledFrom(target)\n if (el) {\n dismissed = null\n arm(el, 0)\n }\n }\n\n const onFocusOut = (e: FocusEvent) => {\n if (anchor && anchor.contains(e.target as Node)) hide(0)\n }\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' || !anchor || !bubble?.isConnected) return\n dismissed = anchor\n hide(0)\n }\n\n document.addEventListener('pointerover', onPointerOver)\n document.addEventListener('pointerout', onPointerOut)\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('focusin', onFocusIn)\n document.addEventListener('focusout', onFocusOut)\n document.addEventListener('keydown', onKeyDown)\n\n uninstallCurrent = () => {\n hide(0)\n document.removeEventListener('pointerover', onPointerOver)\n document.removeEventListener('pointerout', onPointerOut)\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('focusin', onFocusIn)\n document.removeEventListener('focusout', onFocusOut)\n document.removeEventListener('keydown', onKeyDown)\n uninstallCurrent = null\n }\n return uninstallCurrent\n}\n"],"names":[],"mappings":";;AAwCA,MAAM,gBAAgB;AACtB,MAAM,QAAQ;AACd,MAAM,YAAY;AAElB,IAAI,mBAAwC;AAErC,SAAS,qBAAqB,UAA+B,IAAgB;AAClF,MAAI,iBAAkB,QAAO;AAC7B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,YAAY,QAAQ,aAAa;AAEvC,MAAI,SAAyB;AAC7B,MAAI,SAAgC;AACpC,MAAI;AAEJ,MAAI,YAA4B;AAEhC,QAAM,WAAW,IAAI,iBAAiB,MAAM;AAC1C,QAAI,CAAC,UAAU,CAAC,OAAO,aAAa,OAAO,EAAG;AAC9C,UAAM,MAAM;AACZ,QAAI,QAAQ;AACV,aAAO,cAAc,OAAO,aAAa,KAAK;AAC9C,YAAA;AAAA,IACF;AAAA,EACF,CAAC;AAED,WAAS,MAAM,IAAa;AAC1B,OAAG,aAAa,OAAO,GAAG,aAAa,OAAO,KAAK,EAAE;AACrD,OAAG,gBAAgB,OAAO;AAAA,EAC5B;AAEA,WAAS,QAAQ,IAAa;AAC5B,UAAM,OAAO,GAAG,aAAa,KAAK;AAClC,QAAI,SAAS,KAAM;AACnB,OAAG,gBAAgB,KAAK;AACxB,QAAI,CAAC,GAAG,aAAa,OAAO,EAAG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eAAe,aAAa;AACzD,aAAS,oBAAoB,cAAc,YAAY;AACvD,aAAS,oBAAoB,eAAe,eAAe,IAAI;AAC/D,aAAS,oBAAoB,WAAW,SAAS;AACjD,aAAS,oBAAoB,YAAY,UAAU;AACnD,aAAS,oBAAoB,WAAW,SAAS;AACjD,uBAAmB;AAAA,EACrB;AACA,SAAO;AACT;"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where a tooltip bubble goes, shared by <Tooltip> and installTitleTooltips so
3
+ * the React and framework-free bubbles sit, flip and clamp identically.
4
+ */
5
+ export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';
6
+ export interface Placed {
7
+ side: TooltipPlacement;
8
+ left: number;
9
+ top: number;
10
+ /** Arrow offset along the bubble edge, so it still points at the anchor after clamping. */
11
+ arrow: number;
12
+ }
13
+ export declare function placeTooltip(preferred: TooltipPlacement, a: DOMRect, w: number, h: number): Placed;
14
+ //# sourceMappingURL=tooltipPlacement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltipPlacement.d.ts","sourceRoot":"","sources":["../../src/lib/tooltipPlacement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAElE,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,gBAAgB,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,2FAA2F;IAC3F,KAAK,EAAE,MAAM,CAAA;CACd;AA0BD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,gBAAgB,EAC3B,CAAC,EAAE,OAAO,EACV,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,MAAM,CAcR"}
@@ -0,0 +1,34 @@
1
+ const GAP = 8;
2
+ const EDGE = 8;
3
+ const OPPOSITE = {
4
+ top: "bottom",
5
+ bottom: "top",
6
+ left: "right",
7
+ right: "left"
8
+ };
9
+ function fits(side, a, w, h) {
10
+ if (side === "top") return a.top - GAP - h >= EDGE;
11
+ if (side === "bottom") return a.bottom + GAP + h <= window.innerHeight - EDGE;
12
+ if (side === "left") return a.left - GAP - w >= EDGE;
13
+ return a.right + GAP + w <= window.innerWidth - EDGE;
14
+ }
15
+ function snap(v) {
16
+ const dpr = window.devicePixelRatio || 1;
17
+ return Math.round(v * dpr) / dpr;
18
+ }
19
+ function placeTooltip(preferred, a, w, h) {
20
+ const side = fits(preferred, a, w, h) || !fits(OPPOSITE[preferred], a, w, h) ? preferred : OPPOSITE[preferred];
21
+ const clamp = (v, max) => Math.min(Math.max(v, EDGE), max - EDGE);
22
+ if (side === "top" || side === "bottom") {
23
+ const left2 = snap(clamp(a.left + a.width / 2 - w / 2, window.innerWidth - w));
24
+ const top2 = snap(side === "top" ? a.top - GAP - h : a.bottom + GAP);
25
+ return { side, left: left2, top: top2, arrow: a.left + a.width / 2 - left2 };
26
+ }
27
+ const top = snap(clamp(a.top + a.height / 2 - h / 2, window.innerHeight - h));
28
+ const left = snap(side === "left" ? a.left - GAP - w : a.right + GAP);
29
+ return { side, left, top, arrow: a.top + a.height / 2 - top };
30
+ }
31
+ export {
32
+ placeTooltip
33
+ };
34
+ //# sourceMappingURL=tooltipPlacement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltipPlacement.js","sources":["../../src/lib/tooltipPlacement.ts"],"sourcesContent":["/**\n * Where a tooltip bubble goes, shared by <Tooltip> and installTitleTooltips so\n * the React and framework-free bubbles sit, flip and clamp identically.\n */\n\nexport type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right'\n\nexport interface Placed {\n side: TooltipPlacement\n left: number\n top: number\n /** Arrow offset along the bubble edge, so it still points at the anchor after clamping. */\n arrow: number\n}\n\nconst GAP = 8\nconst EDGE = 8\n\nconst OPPOSITE: Record<TooltipPlacement, TooltipPlacement> = {\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left'\n}\n\nfunction fits(side: TooltipPlacement, a: DOMRect, w: number, h: number) {\n if (side === 'top') return a.top - GAP - h >= EDGE\n if (side === 'bottom') return a.bottom + GAP + h <= window.innerHeight - EDGE\n if (side === 'left') return a.left - GAP - w >= EDGE\n return a.right + GAP + w <= window.innerWidth - EDGE\n}\n\n/** Onto the device-pixel grid. A bubble at a fractional offset draws its 1px\n * border antialiased across two rows of the screen — a blurred edge. */\nfunction snap(v: number) {\n const dpr = window.devicePixelRatio || 1\n return Math.round(v * dpr) / dpr\n}\n\nexport function placeTooltip(\n preferred: TooltipPlacement,\n a: DOMRect,\n w: number,\n h: number\n): Placed {\n const side =\n fits(preferred, a, w, h) || !fits(OPPOSITE[preferred], a, w, h)\n ? preferred\n : OPPOSITE[preferred]\n const clamp = (v: number, max: number) => Math.min(Math.max(v, EDGE), max - EDGE)\n if (side === 'top' || side === 'bottom') {\n const left = snap(clamp(a.left + a.width / 2 - w / 2, window.innerWidth - w))\n const top = snap(side === 'top' ? a.top - GAP - h : a.bottom + GAP)\n return { side, left, top, arrow: a.left + a.width / 2 - left }\n }\n const top = snap(clamp(a.top + a.height / 2 - h / 2, window.innerHeight - h))\n const left = snap(side === 'left' ? a.left - GAP - w : a.right + GAP)\n return { side, left, top, arrow: a.top + a.height / 2 - top }\n}\n"],"names":["left","top"],"mappings":"AAeA,MAAM,MAAM;AACZ,MAAM,OAAO;AAEb,MAAM,WAAuD;AAAA,EAC3D,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AACT;AAEA,SAAS,KAAK,MAAwB,GAAY,GAAW,GAAW;AACtE,MAAI,SAAS,MAAO,QAAO,EAAE,MAAM,MAAM,KAAK;AAC9C,MAAI,SAAS,SAAU,QAAO,EAAE,SAAS,MAAM,KAAK,OAAO,cAAc;AACzE,MAAI,SAAS,OAAQ,QAAO,EAAE,OAAO,MAAM,KAAK;AAChD,SAAO,EAAE,QAAQ,MAAM,KAAK,OAAO,aAAa;AAClD;AAIA,SAAS,KAAK,GAAW;AACvB,QAAM,MAAM,OAAO,oBAAoB;AACvC,SAAO,KAAK,MAAM,IAAI,GAAG,IAAI;AAC/B;AAEO,SAAS,aACd,WACA,GACA,GACA,GACQ;AACR,QAAM,OACJ,KAAK,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS,SAAS,GAAG,GAAG,GAAG,CAAC,IAC1D,YACA,SAAS,SAAS;AACxB,QAAM,QAAQ,CAAC,GAAW,QAAgB,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,IAAI;AAChF,MAAI,SAAS,SAAS,SAAS,UAAU;AACvC,UAAMA,QAAO,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,IAAI,IAAI,GAAG,OAAO,aAAa,CAAC,CAAC;AAC5E,UAAMC,OAAM,KAAK,SAAS,QAAQ,EAAE,MAAM,MAAM,IAAI,EAAE,SAAS,GAAG;AAClE,WAAO,EAAE,MAAM,MAAAD,OAAM,KAAAC,MAAK,OAAO,EAAE,OAAO,EAAE,QAAQ,IAAID,MAAAA;AAAAA,EAC1D;AACA,QAAM,MAAM,KAAK,MAAM,EAAE,MAAM,EAAE,SAAS,IAAI,IAAI,GAAG,OAAO,cAAc,CAAC,CAAC;AAC5E,QAAM,OAAO,KAAK,SAAS,SAAS,EAAE,OAAO,MAAM,IAAI,EAAE,QAAQ,GAAG;AACpE,SAAO,EAAE,MAAM,MAAM,KAAK,OAAO,EAAE,MAAM,EAAE,SAAS,IAAI,IAAA;AAC1D;"}
package/dist/modal.css ADDED
@@ -0,0 +1,129 @@
1
+ /* Modal styles for @wolffm/task-ui-components.
2
+ *
3
+ * The component shipped without these, which is why it had one adopter: every
4
+ * other app hand-rolled a dialog rather than reproduce the stylesheet. Import
5
+ * alongside the other component CSS:
6
+ * import '@wolffm/task-ui-components/modal.css'
7
+ *
8
+ * Tokens only, so it themes with everything else across all 18 themes.
9
+ */
10
+
11
+ .modal-overlay {
12
+ position: fixed;
13
+ inset: 0;
14
+ background-color: var(--color-bg-overlay);
15
+ display: flex;
16
+ align-items: flex-start;
17
+ justify-content: center;
18
+ padding: 8vh 16px;
19
+ z-index: 50;
20
+ }
21
+
22
+ .modal-card {
23
+ background-color: var(--color-bg-card);
24
+ color: var(--color-text);
25
+ border: 1px solid var(--color-border);
26
+ border-radius: var(--hdk-radius-lg);
27
+ padding: 20px;
28
+ width: min(440px, 92vw);
29
+ max-height: 84vh;
30
+ overflow: auto;
31
+ box-shadow: var(--hdk-shadow-lg);
32
+ }
33
+
34
+ /* The card takes focus on open so Escape works before anything inside is
35
+ * focused; it must not draw a focus ring for that. Controls keep theirs. */
36
+ .modal-card:focus {
37
+ outline: none;
38
+ }
39
+
40
+ /* A dialog that needs room — a review step, a side-by-side. */
41
+ .modal-card--wide {
42
+ width: min(680px, 94vw);
43
+ }
44
+
45
+ .modal-head {
46
+ display: flex;
47
+ align-items: center;
48
+ gap: 10px;
49
+ margin: 0 0 14px;
50
+ }
51
+
52
+ .modal-card h3 {
53
+ margin: 0;
54
+ font-size: var(--hdk-text-lg);
55
+ font-weight: 600;
56
+ }
57
+
58
+ .modal-card label {
59
+ display: block;
60
+ color: var(--color-text-secondary);
61
+ font-size: var(--hdk-text-sm);
62
+ margin: 12px 0 5px;
63
+ }
64
+
65
+ .modal-input {
66
+ width: 100%;
67
+ font: inherit;
68
+ font-size: var(--hdk-text-sm);
69
+ color: var(--color-text);
70
+ background-color: var(--color-bg-alt);
71
+ border: 1px solid var(--color-border);
72
+ border-radius: var(--hdk-radius);
73
+ padding: 9px 11px;
74
+ }
75
+
76
+ .modal-input:focus {
77
+ outline: none;
78
+ border-color: var(--color-primary);
79
+ }
80
+
81
+ .modal-actions {
82
+ display: flex;
83
+ justify-content: flex-end;
84
+ gap: var(--hdk-space-sm);
85
+ margin-top: 18px;
86
+ }
87
+
88
+ .modal-button {
89
+ font: inherit;
90
+ font-size: var(--hdk-text-sm);
91
+ padding: 8px 14px;
92
+ border-radius: var(--hdk-radius);
93
+ border: 1px solid var(--color-border);
94
+ background: none;
95
+ color: var(--color-text);
96
+ cursor: pointer;
97
+ }
98
+
99
+ .modal-button:hover:not(:disabled) {
100
+ border-color: var(--color-primary);
101
+ }
102
+
103
+ .modal-button:disabled {
104
+ opacity: 0.5;
105
+ cursor: not-allowed;
106
+ }
107
+
108
+ .modal-button--primary {
109
+ background-color: var(--color-primary);
110
+ border-color: var(--color-primary);
111
+ color: var(--color-on-primary);
112
+ }
113
+
114
+ /* The destructive button carries its accent on the border, not the label.
115
+ * `--color-danger` as bare text on the card misses AA in 11 of 18 themes —
116
+ * the same unvalidated accent-over-surface pair that check-usage now gates. */
117
+ .modal-button--danger {
118
+ border-color: var(--color-danger);
119
+ color: var(--color-text);
120
+ }
121
+
122
+ /* Filled on hover, so the label takes `on-danger` — NOT `on-primary`, which is
123
+ * derived from primary's luminance and misses AA on a danger fill in 9 of 18
124
+ * themes. `on-danger` over `danger` is the pair check-contrast guarantees. */
125
+ .modal-button--danger:hover:not(:disabled) {
126
+ background-color: var(--color-danger);
127
+ border-color: var(--color-danger);
128
+ color: var(--color-on-danger);
129
+ }