dsh-pdf-workbench 1.3.1 → 1.3.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 (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +199 -192
  3. package/client.js +1037 -451
  4. package/docs/RELEASE.md +119 -110
  5. package/icon.svg +6 -6
  6. package/package.json +9 -1
  7. package/screenshots.json +8 -8
  8. package/src/client/host-ui-entry.js +11 -0
  9. package/src/client/react-jsx-runtime.cjs +21 -0
  10. package/src/client/viewer.js +80 -80
  11. package/src/host/routes.js +2 -0
  12. package/src/host/update.js +10 -1
  13. package/tools/AGENTS.md +33 -33
  14. package/tools/README.md +138 -138
  15. package/tools/auto_chapters.py +122 -122
  16. package/tools/dsfile.mjs +198 -198
  17. package/tools/export_chapter.py +108 -108
  18. package/tools/export_page.py +91 -91
  19. package/tools/md2overlay.py +200 -200
  20. package/tools/md2tex.py +422 -422
  21. package/tools/node.cmd +3 -0
  22. package/tools/pdf_blocks.py +110 -110
  23. package/tools/pdf_fontsize.py +20 -20
  24. package/tools/pdf_merge.py +15 -15
  25. package/tools/pdf_pagesizes.py +8 -8
  26. package/tools/pdf_raster.py +21 -21
  27. package/tools/pdfkit.py +896 -896
  28. package/tools/py.cmd +3 -0
  29. package/tools/realign_overlay.py +248 -248
  30. package/tools/rebuild_overlay.py +55 -55
  31. package/tools/rename_chapters.py +93 -93
  32. package/tools//350/247/204/350/214/203/00_/345/205/261/345/220/214/347/272/246/345/256/232.md +142 -142
  33. package/tools//350/247/204/350/214/203/01_/346/226/207/346/234/254/346/217/220/345/217/226.md +204 -204
  34. package/tools//350/247/204/350/214/203/02_/347/255/224/347/226/221.md +61 -61
  35. package/tools//350/247/204/350/214/203/03_/344/271/240/351/242/230/350/247/243/347/255/224.md +77 -77
  36. package/tools//350/247/204/350/214/203/api/346/217/220/347/244/272/350/257/215_/346/217/220/345/217/226.md +11 -11
  37. package/vendor/cmaps/LICENSE.txt +36 -36
  38. package/vendor/fonts/excalifont/OFL.txt +98 -98
  39. package/vendor/fonts/zhhand/OFL.txt +99 -99
  40. package/vendor/host-ui.cjs +1719 -0
  41. package/vendor/host-ui.css +799 -0
  42. package/vendor/pdf.min.mjs +28 -28
  43. package/vendor/pdf.worker.min.mjs +28 -28
  44. package/vendor/pdfjs-LICENSE.txt +177 -177
  45. package/vendor/rough/LICENSE +21 -21
  46. package/vendor/rough/rough.mjs +1 -1
  47. package/vendor/wasm/LICENSE_JBIG2 +196 -196
  48. package/vendor/wasm/LICENSE_OPENJPEG +39 -39
  49. package/vendor/wasm/LICENSE_PDFJS_JBIG2 +13 -13
  50. package/vendor/wasm/LICENSE_PDFJS_OPENJPEG +22 -22
  51. package/vendor/wasm/LICENSE_PDFJS_QCMS +19 -19
  52. package/vendor/wasm/LICENSE_QCMS +21 -21
  53. package/vendor/wasm/jbig2_nowasm_fallback.js +15 -15
  54. package/vendor/wasm/openjpeg_nowasm_fallback.js +17 -17
  55. package//345/256/211/350/243/205/344/270/216/345/210/206/345/217/221.md +1 -1
package/client.js CHANGED
@@ -23,6 +23,84 @@ window.__ModuleLoader__.load({
23
23
  const useMemo = React.useMemo
24
24
  const useRef = React.useRef
25
25
 
26
+ // Official host primitives are build-time source in DSH. The build script
27
+ // compiles the subset we use into one CJS file; load it with this instance's
28
+ // require so React and React DOM are the host's copies, never a duplicate.
29
+ let hostUi = null
30
+ let hostUiPromise = null
31
+ const hostUiWaiters = new Set()
32
+
33
+ function hostComponent(name) {
34
+ if (hostUi === null) return null
35
+ const value = hostUi[name]
36
+ if (typeof value === 'function') return value
37
+ if (value !== null && value !== undefined && typeof value === 'object' && value.$$typeof) return value
38
+ return null
39
+ }
40
+
41
+ function notifyHostUi() {
42
+ for (const waiter of hostUiWaiters) {
43
+ try { waiter() } catch { /* a stale component */ }
44
+ }
45
+ }
46
+
47
+ async function loadHostUi() {
48
+ if (hostUi !== null) return hostUi
49
+ if (hostUiPromise !== null) return await hostUiPromise
50
+ hostUiPromise = (async () => {
51
+ try {
52
+ const [codeResponse, cssResponse] = await Promise.all([
53
+ window.fetch('/pdfdesk/vendor/host-ui.cjs', { credentials: 'same-origin' }),
54
+ window.fetch('/pdfdesk/vendor/host-ui.css', { credentials: 'same-origin' }),
55
+ ])
56
+ if (!codeResponse.ok) return null
57
+ const code = await codeResponse.text()
58
+ const module = { exports: {} }
59
+ // esbuild emitted a CJS bundle. React and React DOM stay external and
60
+ // resolve through the host module table.
61
+ const execute = new Function('require', 'module', 'exports', 'process', code)
62
+ execute(require, module, module.exports, { env: {} })
63
+ if (cssResponse.ok) {
64
+ const css = await cssResponse.text()
65
+ if (css !== '') {
66
+ const style = document.createElement('style')
67
+ style.id = 'pdfdesk-host-ui'
68
+ style.textContent = css
69
+ document.head.appendChild(style)
70
+ }
71
+ }
72
+ hostUi = module.exports
73
+ notifyHostUi()
74
+ return hostUi
75
+ } catch {
76
+ hostUi = null
77
+ return null
78
+ }
79
+ })()
80
+ return await hostUiPromise
81
+ }
82
+
83
+ /**
84
+ * Subscribe a component to the host-primitives load.
85
+ * @returns {object | null} the loaded primitives, or null while falling back.
86
+ */
87
+ function useHostUi() {
88
+ const [, setTick] = React.useState(0)
89
+ React.useEffect(() => {
90
+ let alive = true
91
+ const bump = () => {
92
+ if (alive) setTick(value => value + 1)
93
+ }
94
+ hostUiWaiters.add(bump)
95
+ void loadHostUi().then(bump)
96
+ return () => {
97
+ alive = false
98
+ hostUiWaiters.delete(bump)
99
+ }
100
+ }, [])
101
+ return hostUi
102
+ }
103
+
26
104
  const PANEL_ID = 'pdfdesk'
27
105
  const NS = 'pdfDesk'
28
106
  const ENDPOINT = 'pdfdesk/'
@@ -639,7 +717,18 @@ window.__ModuleLoader__.load({
639
717
  updateChecking: '检查中…',
640
718
  updateHint: '只在你点击时访问 GitHub releases',
641
719
  updateLatest: '已是最新版本(v{version})',
642
- updateNew: '发现新版本 {version}(当前 {current}),到 GitHub Releases 下载',
720
+ updateNew: '发现新版本 {version}(当前 {current}),可以立即更新',
721
+ updateNow: '立即更新',
722
+ updateDownloadOnly: '市场未管理这个插件,点击会下载 zip;解压后在 DSH 插件页更新',
723
+ updateMarketStarting: '正在通过插件市场更新…',
724
+ updateMarketProgress: '正在更新:{state}',
725
+ updateMarketDone: '已更新到 v{version};重启 DSH 后生效',
726
+ updateMarketFailed: '更新失败:{message}',
727
+ updateRetry: '重试',
728
+ updateDownload: '下载新版本 zip',
729
+ modalClose: '关闭',
730
+ hostUiLoaded: '界面组件:官方宿主 primitives',
731
+ hostUiFallback: '界面组件:本地回退(宿主 primitives 未加载)',
643
732
  updateNoRelease: '仓库还没有发布版本',
644
733
  updateFailed: '检查更新失败(网络或代理问题),可稍后重试',
645
734
  pdfPassword: '这个 PDF 有密码或加密,暂时打不开——请先解除保护再放进书库',
@@ -1172,7 +1261,18 @@ window.__ModuleLoader__.load({
1172
1261
  updateChecking: 'Checking…',
1173
1262
  updateHint: 'Only contacts GitHub releases on click',
1174
1263
  updateLatest: 'Up to date (v{version})',
1175
- updateNew: 'Version {version} is available (you have {current}) — see GitHub Releases',
1264
+ updateNew: 'Version {version} is available (you have {current}) — update now',
1265
+ updateNow: 'Update now',
1266
+ updateDownloadOnly: 'The market does not manage this plugin; the button downloads the zip. Unzip it and update in the DSH plugin page.',
1267
+ updateMarketStarting: 'Updating through the plugin market…',
1268
+ updateMarketProgress: 'Updating: {state}',
1269
+ updateMarketDone: 'Updated to v{version}; restart DSH to apply',
1270
+ updateMarketFailed: 'Update failed: {message}',
1271
+ updateRetry: 'Retry',
1272
+ updateDownload: 'Download the new zip',
1273
+ modalClose: 'Close',
1274
+ hostUiLoaded: 'UI components: official host primitives',
1275
+ hostUiFallback: 'UI components: local fallback (host primitives not loaded)',
1176
1276
  updateNoRelease: 'The repository has no release yet',
1177
1277
  updateFailed: 'Update check failed (network or proxy) — try again later',
1178
1278
  pdfPassword: 'This PDF is password-protected or encrypted, so it cannot be opened yet — remove the protection first',
@@ -2869,7 +2969,7 @@ window.__ModuleLoader__.load({
2869
2969
  const sub = book.whole === true
2870
2970
  ? `${format('wholeBadge')} · ${format('wholeHint')}`
2871
2971
  : [book.author, format('chapters', { n: chapters })].filter(item => item !== '').join(' · ')
2872
- return h('button', {
2972
+ return h(KitButton, {
2873
2973
  type: 'button',
2874
2974
  className: props.selected ? 'md-card md-card-selected' : 'md-card',
2875
2975
  onClick: () => {
@@ -2907,7 +3007,7 @@ window.__ModuleLoader__.load({
2907
3007
  * @returns {import('react').ReactElement} the tile.
2908
3008
  */
2909
3009
  function CollectionCard(props) {
2910
- return h('button', {
3010
+ return h(KitButton, {
2911
3011
  type: 'button',
2912
3012
  className: 'md-collection',
2913
3013
  onClick: props.onOpen,
@@ -2955,41 +3055,31 @@ window.__ModuleLoader__.load({
2955
3055
  // popup blocked
2956
3056
  }
2957
3057
  }
2958
- return h('div', {
2959
- className: 'md-env-backdrop',
2960
- role: 'presentation',
2961
- onClick: event => {
2962
- if (event.target === event.currentTarget) props.onClose()
2963
- },
2964
- },
2965
- h('div', {
2966
- className: 'md-env-dialog', role: 'dialog', 'aria-modal': 'true',
2967
- 'aria-label': format('envPromptTitle'),
2968
- },
2969
- h('h3', { className: 'md-env-title' }, format('envPromptTitle')),
2970
- h('p', { className: 'md-env-body' }, format('envPromptBody', {
2971
- needs: needs.join(' + '),
2972
- use: format(useKey),
2973
- })),
2974
- h('div', { className: 'md-env-actions' },
2975
- h('button', { type: 'button', className: 'md-btn', onClick: props.onClose }, format('envPromptBack')),
2976
- python ? h('button', {
2977
- type: 'button', className: 'md-btn md-btn-small',
2978
- onClick: () => open(PYTHON_URL),
2979
- }, format('envPromptDownloadPython')) : null,
2980
- tex ? h('button', {
2981
- type: 'button', className: 'md-btn md-btn-small',
2982
- onClick: () => open(TEXLIVE_URL),
2983
- }, format('envPromptDownloadTex')) : null,
2984
- key ? h('button', {
2985
- type: 'button', className: 'md-btn md-btn-small',
2986
- onClick: () => {
2987
- if (typeof props.onOpenSettings === 'function') props.onOpenSettings()
2988
- },
2989
- }, format('envPromptKey')) : null
2990
- )
2991
- )
2992
- )
3058
+ return h(KitModal, {
3059
+ title: format('envPromptTitle'),
3060
+ onClose: props.onClose,
3061
+ children: h('p', { className: 'md-env-body' }, format('envPromptBody', {
3062
+ needs: needs.join(' + '),
3063
+ use: format(useKey),
3064
+ })),
3065
+ footer: [
3066
+ h(KitButton, { key: 'back', variant: 'outline', onClick: props.onClose }, format('envPromptBack')),
3067
+ python ? h(KitButton, {
3068
+ key: 'python', variant: 'outline',
3069
+ onClick: () => open(PYTHON_URL),
3070
+ }, format('envPromptDownloadPython')) : null,
3071
+ tex ? h(KitButton, {
3072
+ key: 'tex', variant: 'outline',
3073
+ onClick: () => open(TEXLIVE_URL),
3074
+ }, format('envPromptDownloadTex')) : null,
3075
+ key ? h(KitButton, {
3076
+ key: 'key', variant: 'primary',
3077
+ onClick: () => {
3078
+ if (typeof props.onOpenSettings === 'function') props.onOpenSettings()
3079
+ },
3080
+ }, format('envPromptKey')) : null,
3081
+ ],
3082
+ })
2993
3083
  }
2994
3084
 
2995
3085
  /**
@@ -3014,39 +3104,29 @@ window.__ModuleLoader__.load({
3014
3104
  setBusy(false)
3015
3105
  }
3016
3106
  }
3017
- return h('div', {
3018
- className: 'md-env-backdrop',
3019
- role: 'presentation',
3020
- onClick: event => {
3021
- if (event.target === event.currentTarget) props.onCancel()
3022
- },
3023
- },
3024
- h('div', {
3025
- className: 'md-env-dialog md-workspace-dialog',
3026
- role: 'dialog', 'aria-modal': 'true', 'aria-label': format('workspaceTitle'),
3027
- },
3028
- h('h3', { className: 'md-env-title' }, format('workspaceTitle')),
3107
+ return h(KitModal, {
3108
+ title: format('workspaceTitle'),
3109
+ className: 'md-workspace-dialog',
3110
+ onClose: props.onCancel,
3111
+ children: h(React.Fragment, null,
3029
3112
  h('p', { className: 'md-env-body' }, format('workspaceBody')),
3030
3113
  h('div', { className: 'md-workspace-list' },
3031
3114
  h('span', { className: 'md-workspace-label' }, format('workspaceSelect')),
3032
3115
  props.workspaces.length === 0
3033
3116
  ? h('span', { className: 'md-shelf-sub' }, format('workspaceEmpty'))
3034
- : props.workspaces.map(item => h('button', {
3117
+ : props.workspaces.map(item => h(KitButton, {
3035
3118
  key: item.id,
3036
- type: 'button', className: 'md-workspace-item',
3119
+ variant: 'outline',
3037
3120
  onClick: () => props.onPick(item),
3038
- },
3039
- h('strong', null, item.title === '' ? item.path : item.title),
3040
- h('span', null, item.path)
3041
- ))
3121
+ }, item.title === '' ? item.path : `${item.title} · ${item.path}`))
3042
3122
  ),
3043
3123
  h('div', { className: 'md-workspace-new' },
3044
3124
  h('span', { className: 'md-workspace-label' }, format('workspaceNew')),
3045
3125
  h('span', { className: 'md-shelf-sub' }, format('workspacePath')),
3046
- h('input', {
3126
+ h(KitInput, {
3047
3127
  className: 'md-settings-input',
3048
3128
  value: path,
3049
- onChange: event => setPath(event.target.value),
3129
+ onChange: value => setPath(value),
3050
3130
  onKeyDown: event => {
3051
3131
  if (event.key !== 'Enter') return
3052
3132
  event.preventDefault()
@@ -3054,20 +3134,269 @@ window.__ModuleLoader__.load({
3054
3134
  },
3055
3135
  })
3056
3136
  ),
3057
- error === '' ? null : h('p', { className: 'md-settings-note' }, error),
3058
- h('div', { className: 'md-env-actions' },
3059
- h('button', { type: 'button', className: 'md-btn', onClick: props.onCancel }, format('workspaceCancel')),
3060
- h('button', {
3061
- type: 'button', className: 'md-btn md-btn-small',
3062
- disabled: busy || path.trim() === '',
3063
- onClick: () => { void create() },
3064
- }, busy ? format('creating') : format('workspaceCreate'))
3065
- )
3137
+ error === '' ? null : h('p', { className: 'md-settings-note' }, error)
3138
+ ),
3139
+ footer: [
3140
+ h(KitButton, { key: 'cancel', variant: 'ghost', onClick: props.onCancel }, format('workspaceCancel')),
3141
+ h(KitButton, {
3142
+ key: 'create',
3143
+ variant: 'primary',
3144
+ disabled: busy || path.trim() === '',
3145
+ onClick: () => { void create() },
3146
+ }, busy ? format('creating') : format('workspaceCreate')),
3147
+ ],
3148
+ })
3149
+ }
3150
+
3151
+ /**
3152
+ * Button adapter: host Button when the primitives bundle is available, the
3153
+ * workbench's own button otherwise. All native button props are forwarded.
3154
+ */
3155
+ const KitButton = React.forwardRef(function KitButton(props, ref) {
3156
+ const ui = useHostUi()
3157
+ const className = typeof props.className === 'string' ? props.className : ''
3158
+ const variant = props.variant !== undefined
3159
+ ? props.variant
3160
+ : className.includes('md-btn-primary')
3161
+ ? 'primary'
3162
+ : className.includes('md-btn-ghost')
3163
+ ? 'ghost'
3164
+ : 'outline'
3165
+ // Dense workbench controls use the small host size by default.
3166
+ const size = props.size !== undefined ? props.size : 'sm'
3167
+ const hostClasses = className.split(/\s+/).filter(name => name !== ''
3168
+ && (name === 'md-btn-danger' || !name.startsWith('md-btn'))).join(' ')
3169
+ // Cards, chapter rows and picker/file rows are layout surfaces first. The
3170
+ // host Button's inline-flex chrome would flatten their internal grid, so
3171
+ // those stay on the native button while ordinary action buttons use the
3172
+ // host control.
3173
+ const nativeOnly = /(?:^|\s)(md-card|md-collection|md-row|md-picker-row|md-file|md-note-style-btn|md-note-color|md-rail-btn|md-icon-btn|md-crumb|md-crumb-current|md-btn-ghost)(?:\s|$)/.test(className)
3174
+ const { variant: _variant, size: _size, hostClassName: _hostClassName, className: _className, children, ...rest } = props
3175
+ const HostButton = ui !== null && ui !== undefined && ui.Button !== undefined
3176
+ && ui.Button !== null
3177
+ && (typeof ui.Button === 'function' || (typeof ui.Button === 'object' && ui.Button.$$typeof))
3178
+ ? ui.Button
3179
+ : null
3180
+ if (HostButton !== null && !nativeOnly) {
3181
+ return h(HostButton, {
3182
+ ...rest,
3183
+ ref,
3184
+ variant,
3185
+ size,
3186
+ className: [hostClasses, props.hostClassName].filter(Boolean).join(' '),
3187
+ disabled: props.disabled === true,
3188
+ title: props.title,
3189
+ type: props.type === undefined ? 'button' : props.type,
3190
+ onClick: props.onClick,
3191
+ }, children)
3192
+ }
3193
+ return h('button', {
3194
+ ...rest,
3195
+ ref,
3196
+ type: props.type === undefined ? 'button' : props.type,
3197
+ className: props.className,
3198
+ disabled: props.disabled === true,
3199
+ title: props.title,
3200
+ onClick: props.onClick,
3201
+ }, children)
3202
+ })
3203
+
3204
+ /**
3205
+ * Input adapter: host Input when available; the business onChange always
3206
+ * receives the value, never the raw event.
3207
+ */
3208
+ const KitInput = React.forwardRef(function KitInput(props, ref) {
3209
+ const ui = useHostUi()
3210
+ const controlled = props.value !== undefined
3211
+ const value = controlled && props.value !== null ? String(props.value) : ''
3212
+ const change = event => {
3213
+ if (typeof props.onChange === 'function') props.onChange(event.target.value, event)
3214
+ }
3215
+ const HostInput = ui !== null && ui !== undefined && ui.Input !== undefined
3216
+ && ui.Input !== null
3217
+ && (typeof ui.Input === 'function' || (typeof ui.Input === 'object' && ui.Input.$$typeof))
3218
+ ? ui.Input
3219
+ : null
3220
+ if (HostInput !== null) {
3221
+ return h(HostInput, {
3222
+ ref,
3223
+ ...(controlled ? { value } : { defaultValue: props.defaultValue }),
3224
+ type: props.type === undefined ? 'text' : props.type,
3225
+ placeholder: props.placeholder,
3226
+ disabled: props.disabled === true,
3227
+ readOnly: props.readOnly === true,
3228
+ autoFocus: props.autoFocus === true,
3229
+ min: props.min,
3230
+ max: props.max,
3231
+ step: props.step,
3232
+ inputMode: props.inputMode,
3233
+ title: props.title,
3234
+ 'aria-label': props['aria-label'],
3235
+ onChange: change,
3236
+ onKeyDown: props.onKeyDown,
3237
+ onBlur: props.onBlur,
3238
+ className: 'md-kit-input',
3239
+ })
3240
+ }
3241
+ return h('span', { className: `md-kit-input${props.className === undefined ? '' : ` ${props.className}`}` },
3242
+ h('input', {
3243
+ ref,
3244
+ className: props.className,
3245
+ type: props.type === undefined ? 'text' : props.type,
3246
+ ...(controlled ? { value } : { defaultValue: props.defaultValue }),
3247
+ placeholder: props.placeholder,
3248
+ disabled: props.disabled === true,
3249
+ readOnly: props.readOnly === true,
3250
+ autoFocus: props.autoFocus === true,
3251
+ min: props.min,
3252
+ max: props.max,
3253
+ step: props.step,
3254
+ inputMode: props.inputMode,
3255
+ title: props.title,
3256
+ 'aria-label': props['aria-label'],
3257
+ onChange: change,
3258
+ onKeyDown: props.onKeyDown,
3259
+ onBlur: props.onBlur,
3260
+ })
3261
+ )
3262
+ })
3263
+
3264
+ /**
3265
+ * Modal adapter: host Modal owns the portal, focus trap, Escape and scrim;
3266
+ * the fallback keeps the workbench shell.
3267
+ */
3268
+ function KitModal(props) {
3269
+ const ui = useHostUi()
3270
+ const HostModal = ui !== null && ui !== undefined && typeof ui.Modal === 'function' ? ui.Modal : null
3271
+ if (HostModal !== null) {
3272
+ return h(HostModal, {
3273
+ open: true,
3274
+ onClose: props.onClose,
3275
+ title: props.title,
3276
+ closeLabel: format('modalClose'),
3277
+ headless: props.headless === true,
3278
+ className: props.className,
3279
+ contentClassName: props.contentClassName,
3280
+ children: props.children,
3281
+ footer: props.footer,
3282
+ })
3283
+ }
3284
+ return h('div', {
3285
+ className: 'md-env-backdrop',
3286
+ role: 'presentation',
3287
+ onClick: event => {
3288
+ if (event.target === event.currentTarget && typeof props.onClose === 'function') props.onClose()
3289
+ },
3290
+ },
3291
+ h('div', {
3292
+ className: `md-env-dialog${props.className === undefined ? '' : ` ${props.className}`}`,
3293
+ role: 'dialog',
3294
+ 'aria-modal': 'true',
3295
+ 'aria-label': props.title ?? '',
3296
+ },
3297
+ h('div', { className: 'md-modal-head' },
3298
+ h('h3', { className: 'md-env-title' }, props.title ?? ''),
3299
+ typeof props.onClose !== 'function'
3300
+ ? null
3301
+ : h(KitButton, {
3302
+ type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
3303
+ 'aria-label': format('modalClose'), title: format('modalClose'),
3304
+ onClick: props.onClose,
3305
+ }, '×')
3306
+ ),
3307
+ h('div', { className: 'md-modal-body' }, props.children),
3308
+ props.footer === undefined || props.footer === null
3309
+ ? null
3310
+ : h('div', { className: 'md-modal-foot' }, props.footer)
3066
3311
  )
3067
3312
  )
3068
3313
  }
3069
3314
 
3315
+ /**
3316
+ * Select adapter: host Menu with a button anchor; fallback list stays local.
3317
+ * @param {{ value: string, label: string, placeholder?: string, options: object[], disabled?: boolean, onChange: Function }} props - select state.
3318
+ * @returns {import('react').ReactElement} the select.
3319
+ */
3320
+ function KitSelect(props) {
3321
+ const ui = useHostUi()
3322
+ const [open, setOpen] = React.useState(false)
3323
+ const rootRef = React.useRef(null)
3324
+ React.useEffect(() => {
3325
+ if (!open) return undefined
3326
+ const onPointer = event => {
3327
+ if (rootRef.current !== null && !rootRef.current.contains(event.target)) setOpen(false)
3328
+ }
3329
+ const onKey = event => {
3330
+ if (event.key === 'Escape') setOpen(false)
3331
+ }
3332
+ window.addEventListener('pointerdown', onPointer)
3333
+ window.addEventListener('keydown', onKey)
3334
+ return () => {
3335
+ window.removeEventListener('pointerdown', onPointer)
3336
+ window.removeEventListener('keydown', onKey)
3337
+ }
3338
+ }, [open])
3339
+ const options = Array.isArray(props.options) ? props.options : []
3340
+ const value = props.value === undefined || props.value === null ? '' : String(props.value)
3341
+ const current = options.find(option => String(option.value) === value)
3342
+ const label = current === undefined ? (props.placeholder === undefined ? '' : props.placeholder) : current.label
3343
+ const trigger = h(KitButton, {
3344
+ className: `md-btn md-btn-small${props.className === undefined ? '' : ` ${props.className}`}`,
3345
+ variant: 'outline',
3346
+ disabled: props.disabled === true,
3347
+ title: props.title,
3348
+ onClick: () => setOpen(value => !value),
3349
+ 'aria-label': props.label,
3350
+ 'aria-expanded': open ? 'true' : 'false',
3351
+ 'aria-haspopup': 'listbox',
3352
+ }, label)
3353
+ const HostMenu = ui !== null && ui !== undefined && ui.Menu !== undefined
3354
+ && (typeof ui.Menu === 'function' || (typeof ui.Menu === 'object' && ui.Menu.$$typeof))
3355
+ ? ui.Menu
3356
+ : null
3357
+ if (HostMenu !== null) {
3358
+ return h(HostMenu, {
3359
+ open,
3360
+ anchor: trigger,
3361
+ items: options.map(option => ({
3362
+ id: String(option.value),
3363
+ label: option.label,
3364
+ disabled: option.disabled === true,
3365
+ })),
3366
+ selectedId: value,
3367
+ onSelect: id => {
3368
+ setOpen(false)
3369
+ if (typeof props.onChange === 'function') props.onChange(id)
3370
+ },
3371
+ onClose: () => setOpen(false),
3372
+ side: 'bottom',
3373
+ align: 'start',
3374
+ portal: true,
3375
+ compact: true,
3376
+ })
3377
+ }
3378
+ return h('span', { className: 'md-kit-select', ref: rootRef },
3379
+ trigger,
3380
+ open
3381
+ ? h('div', { className: 'md-kit-select-menu', role: 'listbox', 'aria-label': props.label },
3382
+ options.map(option => h(KitButton, {
3383
+ key: String(option.value),
3384
+ type: 'button',
3385
+ className: 'md-kit-select-option',
3386
+ role: 'option',
3387
+ 'aria-selected': String(option.value) === value ? 'true' : 'false',
3388
+ disabled: option.disabled === true,
3389
+ onClick: () => {
3390
+ setOpen(false)
3391
+ if (typeof props.onChange === 'function') props.onChange(String(option.value))
3392
+ },
3393
+ }, option.label)))
3394
+ : null
3395
+ )
3396
+ }
3397
+
3070
3398
  function SettingsDialog(props) {
3399
+ const hostUi = useHostUi()
3071
3400
  const envTools = props.envTools ?? { python: false, tex: false, apiKey: false }
3072
3401
  // The dialog is paged: reading switches, the keyboard table, the toolchain
3073
3402
  // check, and the about/update row. Tabs keep it from becoming a long scroll.
@@ -3132,21 +3461,21 @@ window.__ModuleLoader__.load({
3132
3461
  h('h4', { className: 'md-settings-heading' }, format('settingsFeatures')),
3133
3462
  h('div', { className: 'md-settings-row' },
3134
3463
  h('span', null, format('previewPdf')),
3135
- h('button', {
3464
+ h(KitButton, {
3136
3465
  type: 'button', className: 'md-btn md-btn-small',
3137
3466
  onClick: props.onPreview,
3138
3467
  }, props.previewPdf ? format('previewOn') : format('previewOff'))
3139
3468
  ),
3140
3469
  h('div', { className: 'md-settings-row' },
3141
3470
  h('span', null, format('deleteNonPdf')),
3142
- h('button', {
3471
+ h(KitButton, {
3143
3472
  type: 'button', className: 'md-btn md-btn-small',
3144
3473
  onClick: props.onNonPdf,
3145
3474
  }, props.allowNonPdfDelete ? format('previewOn') : format('previewOff'))
3146
3475
  ),
3147
3476
  h('div', { className: 'md-settings-row' },
3148
3477
  h('span', { title: format('socraticHint') }, format('socraticToggle')),
3149
- h('button', {
3478
+ h(KitButton, {
3150
3479
  type: 'button', className: 'md-btn md-btn-small',
3151
3480
  title: format('socraticHint'),
3152
3481
  onClick: props.onSocratic,
@@ -3154,7 +3483,7 @@ window.__ModuleLoader__.load({
3154
3483
  ),
3155
3484
  h('div', { className: 'md-settings-row' },
3156
3485
  h('span', null, format('toolRail')),
3157
- h('button', {
3486
+ h(KitButton, {
3158
3487
  type: 'button', className: 'md-btn md-btn-small',
3159
3488
  onClick: props.onRailSide,
3160
3489
  }, props.railSide === 'left' ? format('railLeft') : format('railRight'))
@@ -3228,12 +3557,12 @@ window.__ModuleLoader__.load({
3228
3557
  SHORTCUT_ACTIONS.map(action => h('div', { className: 'md-settings-row md-shortcut-row', key: action.id },
3229
3558
  h('span', { className: 'md-shortcut-name' }, format(action.labelKey)),
3230
3559
  h('span', { className: 'md-shortcut-key' }, listening === action.id ? format('shortcutsRecording') : bindingLabel(bindings[action.id])),
3231
- h('button', {
3560
+ h(KitButton, {
3232
3561
  type: 'button', className: 'md-btn md-btn-small',
3233
3562
  'aria-pressed': listening === action.id ? 'true' : 'false',
3234
3563
  onClick: () => setListening(listening === action.id ? '' : action.id),
3235
3564
  }, listening === action.id ? format('shortcutsCancel') : format('shortcutsRecord')),
3236
- h('button', {
3565
+ h(KitButton, {
3237
3566
  type: 'button', className: 'md-btn md-btn-small',
3238
3567
  disabled: bindingList(bindings[action.id]).length === 0,
3239
3568
  onClick: () => saveBinding(action.id, []),
@@ -3241,7 +3570,7 @@ window.__ModuleLoader__.load({
3241
3570
  ))
3242
3571
  ),
3243
3572
  h('div', { className: 'md-settings-actions' },
3244
- h('button', {
3573
+ h(KitButton, {
3245
3574
  type: 'button', className: 'md-btn md-btn-small',
3246
3575
  onClick: () => {
3247
3576
  const defaults = {}
@@ -3250,7 +3579,7 @@ window.__ModuleLoader__.load({
3250
3579
  writeShortcutBindings(defaults)
3251
3580
  },
3252
3581
  }, format('shortcutsRestore')),
3253
- h('button', {
3582
+ h(KitButton, {
3254
3583
  type: 'button', className: 'md-btn md-btn-small',
3255
3584
  onClick: () => {
3256
3585
  const empty = {}
@@ -3266,11 +3595,11 @@ window.__ModuleLoader__.load({
3266
3595
  h('h4', { className: 'md-settings-heading' }, format('envTitle')),
3267
3596
  h('div', { className: 'md-settings-row' },
3268
3597
  h('span', null, `${format('envPython')}:${envTools.python ? format('envOn') : format('envOff')}(${format('envPythonSize')})`),
3269
- envTools.python ? null : h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink('https://www.python.org/downloads/windows/') }, format('envDownload'))
3598
+ envTools.python ? null : h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink('https://www.python.org/downloads/windows/') }, format('envDownload'))
3270
3599
  ),
3271
3600
  h('div', { className: 'md-settings-row' },
3272
3601
  h('span', null, `${format('envTex')}:${envTools.tex ? format('envOn') : format('envOff')}(${format('envTexSize')})`),
3273
- envTools.tex ? null : h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink(TEXLIVE_URL) }, format('envDownload'))
3602
+ envTools.tex ? null : h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink(TEXLIVE_URL) }, format('envDownload'))
3274
3603
  ),
3275
3604
  h('p', { className: 'md-shelf-sub' }, format('envImpact')),
3276
3605
  h('p', { className: 'md-shelf-sub' }, `${format('apiKeyTitle')}:${envTools.apiKey ? format('apiKeyConfigured') : format('apiKeyMissing')}`)
@@ -3279,40 +3608,64 @@ window.__ModuleLoader__.load({
3279
3608
  h('h4', { className: 'md-settings-heading' }, format('apiKeyTitle')),
3280
3609
  h('p', { className: 'md-shelf-sub' }, apiKeyNote),
3281
3610
  h('div', { className: 'md-settings-row' },
3282
- h('input', {
3611
+ h(KitInput, {
3283
3612
  className: 'md-settings-input', type: 'password',
3284
3613
  value: apiKey, placeholder: 'sk-...',
3285
- onChange: event => setApiKey(event.target.value),
3614
+ onChange: value => setApiKey(value),
3286
3615
  }),
3287
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: () => { void saveApiKey() } }, format('apiKeySave'))
3616
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => { void saveApiKey() } }, format('apiKeySave'))
3288
3617
  )
3289
3618
  )
3290
3619
  )
3291
3620
  const about = h('div', { className: 'md-settings-section' },
3292
3621
  h('h4', { className: 'md-settings-heading' }, format('githubRepo')),
3293
- h('button', {
3622
+ h(KitButton, {
3294
3623
  type: 'button', className: 'md-btn md-btn-small',
3295
3624
  onClick: () => openLink(GITHUB_URL),
3296
3625
  }, format('githubRepo')),
3297
- h('button', {
3298
- type: 'button', className: 'md-btn md-btn-small', disabled: props.updateBusy === true,
3626
+ h(KitButton, {
3627
+ className: 'md-btn md-btn-small', disabled: props.updateBusy === true,
3299
3628
  title: format('updateHint'),
3300
3629
  onClick: props.onCheckUpdate,
3301
- }, props.updateBusy === true ? format('updateChecking') : format('updateCheck'))
3630
+ }, props.updateBusy === true ? format('updateChecking') : format('updateCheck')),
3631
+ props.updateInfo === null
3632
+ ? null
3633
+ : h('div', { className: 'md-update-box' },
3634
+ h('p', { className: 'md-shelf-sub' },
3635
+ `v${props.updateInfo.current} → v${props.updateInfo.version}`),
3636
+ props.marketUpdate !== null
3637
+ ? h(KitButton, {
3638
+ className: 'md-btn md-btn-small',
3639
+ disabled: props.updateBusy === true,
3640
+ onClick: props.onInstallUpdate,
3641
+ }, format('updateNow'))
3642
+ : h('a', {
3643
+ className: 'md-btn md-btn-small',
3644
+ href: props.updateInfo.download,
3645
+ target: '_blank',
3646
+ rel: 'noreferrer',
3647
+ title: format('updateDownloadOnly'),
3648
+ }, format('updateNow')),
3649
+ h('p', { className: 'md-shelf-sub' },
3650
+ props.marketUpdate !== null ? format('updateHint') : format('updateDownloadOnly'))
3651
+ ),
3652
+ props.updateOperation === null
3653
+ ? null
3654
+ : h('p', { className: 'md-settings-note', role: 'status' }, props.updateOperation.message),
3655
+ h('p', { className: 'md-shelf-sub' }, hostUi !== null ? format('hostUiLoaded') : format('hostUiFallback'))
3302
3656
  )
3303
- return h(React.Fragment, null,
3304
- h('div', { className: 'md-picker-backdrop', 'aria-hidden': true, onClick: props.onClose }),
3305
- h('div', { className: 'md-picker md-settings-page', role: 'dialog', 'aria-modal': 'true', 'aria-label': format('settings') },
3306
- h('div', { className: 'md-picker-head' },
3307
- h('span', { className: 'md-picker-title' }, format('settings')),
3657
+ return h(KitModal, {
3658
+ title: format('settings'),
3659
+ onClose: props.onClose,
3660
+ className: 'md-settings-modal',
3661
+ contentClassName: 'md-settings-content',
3662
+ children: h(React.Fragment, null,
3663
+ h('div', { className: 'md-settings-meta' },
3308
3664
  h('span', { className: 'md-settings-version' }, `${format('version')} ${props.version}`),
3309
- h('button', {
3310
- type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
3311
- 'aria-label': format('previewClose'), onClick: props.onClose,
3312
- }, '×')
3665
+ h('span', { className: 'md-shelf-sub' }, hostUi !== null ? format('hostUiLoaded') : format('hostUiFallback'))
3313
3666
  ),
3314
3667
  h('div', { className: 'md-settings-tabs', role: 'tablist' },
3315
- tabs.map(item => h('button', {
3668
+ tabs.map(item => h(KitButton, {
3316
3669
  key: item.id,
3317
3670
  type: 'button',
3318
3671
  role: 'tab',
@@ -3323,8 +3676,8 @@ window.__ModuleLoader__.load({
3323
3676
  }, item.label))
3324
3677
  ),
3325
3678
  tab === 'reading' ? reading : tab === 'workflow' ? workflow : tab === 'keys' ? keys : tab === 'env' ? env : about
3326
- )
3327
- )
3679
+ ),
3680
+ })
3328
3681
  }
3329
3682
 
3330
3683
  /**
@@ -3416,11 +3769,11 @@ window.__ModuleLoader__.load({
3416
3769
  return h('section', { className: 'md-libraries md-home', ref: sectionRef, 'aria-label': format('librariesTitle') },
3417
3770
  h(PixelWhale),
3418
3771
  h('div', { className: `md-home-toolbar${stuck ? ' is-stuck' : ''}` },
3419
- h('button', {
3772
+ h(KitButton, {
3420
3773
  type: 'button', className: 'md-btn md-btn-small md-btn-primary', disabled: busy,
3421
3774
  onClick: scrollToAdd,
3422
3775
  }, format('libraryAddTitle')),
3423
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: scrollToManual }, format('manualTitle')),
3776
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: scrollToManual }, format('manualTitle')),
3424
3777
  h('span', { className: 'md-home-toolbar-count' }, format('heroMeta', { n: props.libraries.length }))
3425
3778
  ),
3426
3779
  h('header', { className: 'md-hero' },
@@ -3428,18 +3781,18 @@ window.__ModuleLoader__.load({
3428
3781
  h('h1', { className: 'md-hero-title' }, format('heroTitle')),
3429
3782
  h('p', { className: 'md-hero-lead' }, format('heroLead')),
3430
3783
  h('div', { className: 'md-hero-actions' },
3431
- h('button', {
3784
+ h(KitButton, {
3432
3785
  type: 'button', className: 'md-btn md-btn-primary', disabled: busy,
3433
3786
  onClick: scrollToAdd,
3434
3787
  }, format('libraryAddTitle')),
3435
3788
  props.libraries.length === 0
3436
3789
  ? null
3437
- : h('button', {
3790
+ : h(KitButton, {
3438
3791
  type: 'button', className: 'md-btn',
3439
3792
  disabled: props.sampleBusy || busy || props.sample?.book == null,
3440
3793
  onClick: props.onLoadSample,
3441
3794
  }, props.sampleBusy ? format('sampleBusy') : format('sampleLoad')),
3442
- h('button', { type: 'button', className: 'md-btn md-btn-ghost', onClick: scrollToManual }, format('manualTitle'))
3795
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-ghost', onClick: scrollToManual }, format('manualTitle'))
3443
3796
  ),
3444
3797
  stuck
3445
3798
  ? null
@@ -3469,7 +3822,7 @@ window.__ModuleLoader__.load({
3469
3822
  ),
3470
3823
  h('code', { className: 'md-path' }, item.libraryDir),
3471
3824
  h('div', { className: 'md-library-actions' },
3472
- h('button', {
3825
+ h(KitButton, {
3473
3826
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost md-icon-btn',
3474
3827
  disabled: busy,
3475
3828
  title: format('libraryRemove'),
@@ -3489,13 +3842,13 @@ window.__ModuleLoader__.load({
3489
3842
  h('p', { className: 'md-shelf-sub' }, format('libraryAddHint'))
3490
3843
  ),
3491
3844
  h('div', { className: 'md-add-row' },
3492
- h('input', {
3845
+ h(KitInput, {
3493
3846
  className: 'md-input md-add-path', value: dir, disabled: busy,
3494
3847
  placeholder: format('addPathPlaceholder'),
3495
3848
  'aria-label': format('libraryPath'),
3496
- onChange: event => setDir(event.target.value),
3849
+ onChange: value => setDir(value),
3497
3850
  }),
3498
- h('button', {
3851
+ h(KitButton, {
3499
3852
  type: 'button', className: 'md-btn md-btn-small', disabled: busy,
3500
3853
  onClick: () => {
3501
3854
  void props.onPick().then(picked => {
@@ -3509,13 +3862,13 @@ window.__ModuleLoader__.load({
3509
3862
  })
3510
3863
  },
3511
3864
  }, format('libraryPick')),
3512
- h('input', {
3865
+ h(KitInput, {
3513
3866
  className: 'md-input md-add-name', value: name, disabled: busy,
3514
3867
  placeholder: format('addNamePlaceholder'),
3515
3868
  'aria-label': format('libraryName'),
3516
- onChange: event => setName(event.target.value),
3869
+ onChange: value => setName(value),
3517
3870
  }),
3518
- h('button', {
3871
+ h(KitButton, {
3519
3872
  type: 'button', className: 'md-btn md-btn-small md-btn-primary md-add-submit',
3520
3873
  disabled: busy || dir.trim() === '',
3521
3874
  onClick: () => props.onAdd(dir, name),
@@ -3562,7 +3915,7 @@ window.__ModuleLoader__.load({
3562
3915
  h('p', { className: 'md-manual-text' }, format('manualEnvLead')),
3563
3916
  h('p', { className: 'md-manual-text' }, `${format('envTitle')}:${props.canRender ? format('envReady') : format('envMissing')}`),
3564
3917
  h('div', { className: 'md-manual-actions' },
3565
- props.canRender ? null : h('button', {
3918
+ props.canRender ? null : h(KitButton, {
3566
3919
  type: 'button', className: 'md-btn md-btn-small',
3567
3920
  onClick: () => {
3568
3921
  try {
@@ -3578,7 +3931,7 @@ window.__ModuleLoader__.load({
3578
3931
  h('summary', { className: 'md-manual-sub-summary' }, format('aiPromptTitle')),
3579
3932
  h('p', { className: 'md-manual-text' }, format('aiPromptHint')),
3580
3933
  h('code', { className: 'md-manual-code' }, format('aiPromptText')),
3581
- h('button', {
3934
+ h(KitButton, {
3582
3935
  type: 'button', className: 'md-btn md-btn-small',
3583
3936
  onClick: props.onCopyPrompt,
3584
3937
  }, format('aiPromptCopy'))
@@ -3624,7 +3977,7 @@ window.__ModuleLoader__.load({
3624
3977
  size: formatBytes(props.sample.book.bytes),
3625
3978
  })}`),
3626
3979
  h('p', { className: 'md-shelf-sub' }, format('sampleHint')),
3627
- h('button', {
3980
+ h(KitButton, {
3628
3981
  type: 'button', className: 'md-btn',
3629
3982
  disabled: props.sampleBusy || props.busy,
3630
3983
  onClick: props.onLoadSample,
@@ -3634,7 +3987,7 @@ window.__ModuleLoader__.load({
3634
3987
  h('div', { className: 'md-tool-card' },
3635
3988
  h('h3', { className: 'md-subheading' }, format('splitToolTitle')),
3636
3989
  h('p', { className: 'md-shelf-sub' }, format('splitHint')),
3637
- h('button', {
3990
+ h(KitButton, {
3638
3991
  type: 'button', className: 'md-btn', disabled: busy,
3639
3992
  onClick: props.onSplit,
3640
3993
  }, busy ? format('libraryBusy') : format('splitStart'))
@@ -3642,7 +3995,7 @@ window.__ModuleLoader__.load({
3642
3995
  h('div', { className: 'md-tool-card' },
3643
3996
  h('h3', { className: 'md-subheading' }, format('importToolTitle')),
3644
3997
  h('p', { className: 'md-shelf-sub' }, format('importFilesHint')),
3645
- h('button', {
3998
+ h(KitButton, {
3646
3999
  type: 'button', className: 'md-btn', disabled: busy || props.importBusy,
3647
4000
  onClick: props.onImport,
3648
4001
  }, props.importBusy ? format('importBusy') : format('importStart'))
@@ -3651,7 +4004,7 @@ window.__ModuleLoader__.load({
3651
4004
  h('h3', { className: 'md-subheading' }, format('envTitle')),
3652
4005
  h('p', { className: 'md-shelf-sub' }, `${format('envPython')}:${envTools.python ? format('envOn') : format('envOff')} · ${format('envTex')}:${envTools.tex ? format('envOn') : format('envOff')}`),
3653
4006
  h('div', { className: 'md-library-tools' },
3654
- envTools.python ? null : h('button', {
4007
+ envTools.python ? null : h(KitButton, {
3655
4008
  type: 'button', className: 'md-btn md-btn-small',
3656
4009
  onClick: () => {
3657
4010
  try {
@@ -3661,7 +4014,7 @@ window.__ModuleLoader__.load({
3661
4014
  }
3662
4015
  },
3663
4016
  }, `${format('envPython')}(${format('envPythonSize')})`),
3664
- envTools.tex ? null : h('button', {
4017
+ envTools.tex ? null : h(KitButton, {
3665
4018
  type: 'button', className: 'md-btn md-btn-small',
3666
4019
  onClick: () => {
3667
4020
  try {
@@ -3777,32 +4130,32 @@ window.__ModuleLoader__.load({
3777
4130
  ? null
3778
4131
  : h('div', { className: 'md-shelf-actions' },
3779
4132
  h('span', { className: 'md-shelf-selected' }, format('shelfSelected', { n: props.selected.size })),
3780
- h('button', {
4133
+ h(KitButton, {
3781
4134
  type: 'button', className: 'md-btn md-btn-small',
3782
4135
  onClick: props.onCreateShelf,
3783
4136
  }, format('shelfNew')),
3784
4137
  props.group === 'hidden'
3785
- ? h('button', {
4138
+ ? h(KitButton, {
3786
4139
  type: 'button', className: 'md-btn md-btn-small',
3787
4140
  onClick: props.onUnhide,
3788
4141
  }, format('shelfUnhide'))
3789
- : h('button', {
4142
+ : h(KitButton, {
3790
4143
  type: 'button', className: 'md-btn md-btn-small',
3791
4144
  onClick: props.onHide,
3792
4145
  }, format('shelfHide')),
3793
4146
  props.group === 'hidden'
3794
- ? h('button', {
4147
+ ? h(KitButton, {
3795
4148
  type: 'button', className: 'md-btn md-btn-small',
3796
4149
  onClick: props.onTrashSelected,
3797
4150
  }, format('shelfTrash'))
3798
4151
  : null,
3799
4152
  props.group !== null && props.group !== 'hidden'
3800
- ? h('button', {
4153
+ ? h(KitButton, {
3801
4154
  type: 'button', className: 'md-btn md-btn-small',
3802
4155
  onClick: props.onRemoveFromShelf,
3803
4156
  }, format('shelfRemove'))
3804
4157
  : null,
3805
- h('button', {
4158
+ h(KitButton, {
3806
4159
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
3807
4160
  onClick: props.onClear,
3808
4161
  }, format('shelfClear'))
@@ -3816,31 +4169,25 @@ window.__ModuleLoader__.load({
3816
4169
  * @returns {import('react').ReactElement} the dialog.
3817
4170
  */
3818
4171
  function ShelfNameDialog(props) {
3819
- return h(React.Fragment, null,
3820
- h('div', { className: 'md-picker-backdrop', 'aria-hidden': true, onClick: props.onClose }),
3821
- h('div', { className: 'md-picker', role: 'dialog', 'aria-modal': 'true', 'aria-label': format('shelfName') },
3822
- h('div', { className: 'md-picker-head' },
3823
- h('span', { className: 'md-picker-title' }, format('shelfName')),
3824
- h('button', {
3825
- type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
3826
- 'aria-label': format('previewClose'), onClick: props.onClose,
3827
- }, '×')
3828
- ),
3829
- h('input', {
4172
+ return h(KitModal, {
4173
+ title: format('shelfName'),
4174
+ onClose: props.onClose,
4175
+ children: h(React.Fragment, null,
4176
+ h(KitInput, {
3830
4177
  className: 'md-input', value: props.name, autoFocus: true,
3831
4178
  placeholder: format('shelfName'),
3832
- onChange: event => props.onChange(event.target.value),
4179
+ onChange: value => props.onChange(value),
3833
4180
  onKeyDown: event => {
3834
4181
  if (event.key === 'Enter') props.onConfirm()
3835
4182
  },
3836
4183
  }),
3837
- props.error === '' ? null : h('div', { className: 'md-state-error', role: 'alert' }, props.error),
3838
- h('div', { className: 'md-library-tools', style: { order: 3 } },
3839
- h('button', { type: 'button', className: 'md-btn', onClick: props.onConfirm }, format('shelfCreate')),
3840
- h('button', { type: 'button', className: 'md-btn md-btn-ghost', onClick: props.onClose }, format('previewClose'))
3841
- )
3842
- )
3843
- )
4184
+ props.error === '' ? null : h('div', { className: 'md-state-error', role: 'alert' }, props.error)
4185
+ ),
4186
+ footer: [
4187
+ h(KitButton, { key: 'cancel', variant: 'ghost', onClick: props.onClose }, format('previewClose')),
4188
+ h(KitButton, { key: 'save', variant: 'primary', onClick: props.onConfirm }, format('shelfCreate')),
4189
+ ],
4190
+ })
3844
4191
  }
3845
4192
 
3846
4193
  /**
@@ -3866,13 +4213,13 @@ window.__ModuleLoader__.load({
3866
4213
  return h('li', { key: item.id, className: 'md-session-row', 'data-via-link': item.viaLink ? 'true' : undefined },
3867
4214
  editing
3868
4215
  ? h('div', { className: 'md-session-edit' },
3869
- h('input', {
4216
+ h(KitInput, {
3870
4217
  className: 'md-session-input',
3871
4218
  value: renaming.value,
3872
4219
  'aria-label': format('rename'),
3873
4220
  title: format('renameHint'),
3874
4221
  autoFocus: true,
3875
- onChange: event => props.onRenameInput(event.target.value),
4222
+ onChange: value => props.onRenameInput(value),
3876
4223
  onKeyDown: event => {
3877
4224
  if (event.key === 'Enter') {
3878
4225
  event.preventDefault()
@@ -3884,17 +4231,17 @@ window.__ModuleLoader__.load({
3884
4231
  }
3885
4232
  },
3886
4233
  }),
3887
- h('button', {
4234
+ h(KitButton, {
3888
4235
  type: 'button', className: 'md-btn md-btn-small', disabled: renaming.saving,
3889
4236
  onClick: props.onCommitRename,
3890
4237
  }, format('renameSave')),
3891
- h('button', {
4238
+ h(KitButton, {
3892
4239
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost', disabled: renaming.saving,
3893
4240
  onClick: props.onCancelRename,
3894
4241
  }, format('renameCancel')),
3895
4242
  renaming.error === '' ? null : h('span', { className: 'md-session-edit-error', role: 'alert' }, renaming.error)
3896
4243
  )
3897
- : h('button', {
4244
+ : h(KitButton, {
3898
4245
  type: 'button',
3899
4246
  className: 'md-session',
3900
4247
  title,
@@ -3916,14 +4263,14 @@ window.__ModuleLoader__.load({
3916
4263
  editing ? null : h('span', { className: 'md-session-actions' },
3917
4264
  item.pending
3918
4265
  ? null
3919
- : h('button', {
4266
+ : h(KitButton, {
3920
4267
  type: 'button', className: 'md-icon-btn', title: format('rename'),
3921
4268
  'aria-label': `${format('rename')}:${label}`,
3922
4269
  onClick: () => props.onStartRename(props.chapter, item),
3923
4270
  }, '✎'),
3924
4271
  item.pending
3925
4272
  ? null
3926
- : h('button', {
4273
+ : h(KitButton, {
3927
4274
  type: 'button', className: 'md-icon-btn md-icon-btn-text', title: `${format('archiveSession')}(不删除,可在 DSH 归档里恢复)`,
3928
4275
  'aria-label': `${format('archiveSession')}:${label}`,
3929
4276
  onClick: () => {
@@ -3933,7 +4280,7 @@ window.__ModuleLoader__.load({
3933
4280
  },
3934
4281
  }, format('archiveSession')),
3935
4282
  item.viaLink
3936
- ? h('button', {
4283
+ ? h(KitButton, {
3937
4284
  type: 'button', className: 'md-icon-btn', title: format('unlink'),
3938
4285
  'aria-label': `${format('unlink')}:${label}`,
3939
4286
  onClick: () => props.onUnlink(item),
@@ -3948,12 +4295,12 @@ window.__ModuleLoader__.load({
3948
4295
  props.loaded
3949
4296
  ? null
3950
4297
  : h('span', { className: 'md-session-state' }, format(props.available ? 'sessionLoading' : 'sessionUnavailable')),
3951
- h('button', {
4298
+ h(KitButton, {
3952
4299
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
3953
4300
  onClick: props.onToggle,
3954
4301
  }, props.open === false ? format('artifactsExpand') : format('artifactsCollapse')),
3955
4302
  props.loaded && props.available
3956
- ? h('button', {
4303
+ ? h(KitButton, {
3957
4304
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost md-session-digest',
3958
4305
  title: format('digestHint'),
3959
4306
  'aria-label': format('digestOf'),
@@ -3963,7 +4310,7 @@ window.__ModuleLoader__.load({
3963
4310
  ),
3964
4311
  props.error === '' ? null : h('div', { className: 'md-alert md-alert-inline', role: 'alert' },
3965
4312
  h('span', { className: 'md-alert-text' }, props.error),
3966
- props.errorSession === null ? null : h('button', {
4313
+ props.errorSession === null ? null : h(KitButton, {
3967
4314
  type: 'button', className: 'md-btn md-btn-small', disabled: busy,
3968
4315
  onClick: props.onRetryRename,
3969
4316
  }, format('retryRename'))
@@ -3975,7 +4322,7 @@ window.__ModuleLoader__.load({
3975
4322
  return h('div', { key: mode, className: 'md-session-group' },
3976
4323
  h('div', { className: 'md-session-group-head' },
3977
4324
  h('span', { className: 'md-session-mode' }, format(`mode.${mode}`)),
3978
- h('button', {
4325
+ h(KitButton, {
3979
4326
  type: 'button',
3980
4327
  className: 'md-btn md-btn-small md-session-new',
3981
4328
  disabled: busy || !props.available,
@@ -3983,7 +4330,7 @@ window.__ModuleLoader__.load({
3983
4330
  'aria-label': format('newSessionOf', { mode: format(`mode.${mode}`) }),
3984
4331
  onClick: () => props.onNewSession(props.chapter, mode),
3985
4332
  }, props.creatingMode === mode ? format('creating') : `+ ${format('newSession')}`),
3986
- h('button', {
4333
+ h(KitButton, {
3987
4334
  type: 'button',
3988
4335
  className: 'md-btn md-btn-small md-btn-ghost',
3989
4336
  disabled: busy || !props.available,
@@ -3991,7 +4338,7 @@ window.__ModuleLoader__.load({
3991
4338
  'aria-label': format('forceNewOf', { mode: format(`mode.${mode}`) }),
3992
4339
  onClick: () => props.onNewSession(props.chapter, mode, { forceNew: true }),
3993
4340
  }, format('forceNew')),
3994
- h('button', {
4341
+ h(KitButton, {
3995
4342
  type: 'button',
3996
4343
  className: 'md-btn md-btn-small md-btn-ghost',
3997
4344
  disabled: busy || !props.available,
@@ -4017,27 +4364,20 @@ window.__ModuleLoader__.load({
4017
4364
  const needle = query.trim().toLowerCase()
4018
4365
  const filtered = needle === '' ? props.candidates : props.candidates.filter(item => item.label.toLowerCase().includes(needle))
4019
4366
  const shown = filtered.slice(0, 300)
4020
- return h(React.Fragment, null,
4021
- h('div', { className: 'md-picker-backdrop', 'aria-hidden': true, onClick: props.onClose }),
4022
- h('div', { className: 'md-picker', role: 'dialog', 'aria-modal': 'true', 'aria-label': format('importTitle') },
4023
- h('div', { className: 'md-picker-head' },
4024
- h('span', { className: 'md-picker-title' }, format('importTitle')),
4025
- h('button', {
4026
- type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
4027
- 'aria-label': format('previewClose'), title: format('previewClose'),
4028
- onClick: props.onClose,
4029
- }, '×')
4030
- ),
4367
+ return h(KitModal, {
4368
+ title: format('importTitle'),
4369
+ onClose: props.onClose,
4370
+ children: h(React.Fragment, null,
4031
4371
  h('div', { className: 'md-picker-sub' },
4032
4372
  format('importChapter', { code: props.target.code, title: props.target.title })),
4033
- h('input', {
4373
+ h(KitInput, {
4034
4374
  className: 'md-picker-search',
4035
4375
  type: 'search',
4036
4376
  placeholder: format('importSearch'),
4037
4377
  'aria-label': format('importSearch'),
4038
4378
  value: query,
4039
4379
  autoFocus: true,
4040
- onChange: event => setQuery(event.target.value),
4380
+ onChange: value => setQuery(value),
4041
4381
  onKeyDown: event => {
4042
4382
  if (event.key === 'Escape') {
4043
4383
  event.preventDefault()
@@ -4050,7 +4390,7 @@ window.__ModuleLoader__.load({
4050
4390
  ? h('div', { className: 'md-picker-empty' }, format('importEmpty'))
4051
4391
  : h('ul', { className: 'md-picker-list' },
4052
4392
  shown.map(item => h('li', { key: item.id },
4053
- h('button', {
4393
+ h(KitButton, {
4054
4394
  type: 'button',
4055
4395
  className: 'md-picker-row',
4056
4396
  disabled: item.linked,
@@ -4068,8 +4408,9 @@ window.__ModuleLoader__.load({
4068
4408
  ? h('div', { className: 'md-picker-note' }, format('importTruncated', { n: shown.length }))
4069
4409
  : null,
4070
4410
  h('div', { className: 'md-picker-note' }, format('importHint'))
4071
- )
4072
- )
4411
+ ),
4412
+ footer: [h(KitButton, { key: 'close', variant: 'ghost', onClick: props.onClose }, format('previewClose'))],
4413
+ })
4073
4414
  }
4074
4415
 
4075
4416
  /**
@@ -4079,17 +4420,10 @@ window.__ModuleLoader__.load({
4079
4420
  */
4080
4421
  function DigestDialog(props) {
4081
4422
  const digest = props.digest
4082
- return h(React.Fragment, null,
4083
- h('div', { className: 'md-picker-backdrop', 'aria-hidden': true, onClick: props.onClose }),
4084
- h('div', { className: 'md-picker md-digest', role: 'dialog', 'aria-modal': 'true', 'aria-label': format('digestTitle') },
4085
- h('div', { className: 'md-picker-head' },
4086
- h('span', { className: 'md-picker-title' }, format('digestTitle')),
4087
- h('button', {
4088
- type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
4089
- 'aria-label': format('previewClose'), title: format('previewClose'),
4090
- onClick: props.onClose,
4091
- }, '×')
4092
- ),
4423
+ return h(KitModal, {
4424
+ title: format('digestTitle'),
4425
+ onClose: props.onClose,
4426
+ children: h(React.Fragment, null,
4093
4427
  digest.phase === 'working'
4094
4428
  ? h('div', { className: 'md-picker-empty', role: 'status' }, format('digestWorking'))
4095
4429
  : digest.phase === 'error'
@@ -4098,16 +4432,17 @@ window.__ModuleLoader__.load({
4098
4432
  : h(React.Fragment, null,
4099
4433
  h('pre', { className: 'md-digest-text' }, digest.text),
4100
4434
  h('div', { className: 'md-digest-actions' },
4101
- h('button', {
4102
- type: 'button', className: 'md-btn md-btn-small',
4435
+ h(KitButton, {
4436
+ variant: 'outline',
4103
4437
  onClick: () => props.onCopy(digest.text),
4104
4438
  }, format('digestCopy')),
4105
4439
  digest.path === '' ? null : h('code', { className: 'md-path' }, digest.path)
4106
4440
  )
4107
4441
  ),
4108
4442
  h('div', { className: 'md-picker-note' }, format('digestHint'))
4109
- )
4110
- )
4443
+ ),
4444
+ footer: [h(KitButton, { key: 'close', variant: 'ghost', onClick: props.onClose }, format('previewClose'))],
4445
+ })
4111
4446
  }
4112
4447
 
4113
4448
  /**
@@ -4133,7 +4468,7 @@ window.__ModuleLoader__.load({
4133
4468
  key: `${index}:${item.name}`,
4134
4469
  className: String(item.name).includes('__') ? 'md-artifact-item md-artifact-child' : 'md-artifact-item',
4135
4470
  },
4136
- h('button', {
4471
+ h(KitButton, {
4137
4472
  type: 'button',
4138
4473
  className: 'md-file',
4139
4474
  onContextMenu: event => {
@@ -4194,7 +4529,7 @@ window.__ModuleLoader__.load({
4194
4529
  : null,
4195
4530
  props.mathMode === true ? h('div', { className: 'md-artifact-modes' },
4196
4531
  MODES.map(mode => h(React.Fragment, { key: mode },
4197
- h('button', {
4532
+ h(KitButton, {
4198
4533
  type: 'button',
4199
4534
  className: 'md-btn md-btn-small md-btn-ghost md-artifact-mode',
4200
4535
  onClick: event => {
@@ -4207,7 +4542,7 @@ window.__ModuleLoader__.load({
4207
4542
  props.onArtifactSession(props.chapter, item, mode, 0)
4208
4543
  },
4209
4544
  }, format(`mode.${mode}`)),
4210
- h('button', {
4545
+ h(KitButton, {
4211
4546
  type: 'button',
4212
4547
  className: 'md-btn md-btn-small md-btn-ghost md-artifact-mode',
4213
4548
  title: format('forceNewHint'),
@@ -4220,7 +4555,7 @@ window.__ModuleLoader__.load({
4220
4555
  ) : null,
4221
4556
  props.mathMode === true && groups !== undefined
4222
4557
  ? h(React.Fragment, null,
4223
- h('button', {
4558
+ h(KitButton, {
4224
4559
  type: 'button', className: 'md-artifact-session-toggle',
4225
4560
  onClick: event => {
4226
4561
  event.stopPropagation()
@@ -4237,7 +4572,7 @@ window.__ModuleLoader__.load({
4237
4572
  MODES.flatMap(mode => (Array.isArray(groups[mode]) ? groups[mode] : []).map(entry => h('li', {
4238
4573
  key: entry.id, className: 'md-session-row',
4239
4574
  },
4240
- h('button', {
4575
+ h(KitButton, {
4241
4576
  type: 'button', className: 'md-session',
4242
4577
  onClick: () => props.onOpenSession(entry),
4243
4578
  }, h('span', { className: 'md-session-name' }, entry.title === '' ? entry.displayTitle : entry.title))
@@ -4263,7 +4598,7 @@ window.__ModuleLoader__.load({
4263
4598
  if (phase === 'error') {
4264
4599
  body = h('div', { className: 'md-alert md-alert-inline', role: 'alert' },
4265
4600
  h('span', { className: 'md-alert-text' }, state.error === '' ? format('artifactsFailed') : state.error),
4266
- h('button', {
4601
+ h(KitButton, {
4267
4602
  type: 'button',
4268
4603
  className: 'md-btn md-btn-small',
4269
4604
  'aria-label': format('artifactsReloadAria'),
@@ -4277,7 +4612,7 @@ window.__ModuleLoader__.load({
4277
4612
  h('span', null, state.missing === true ? format('artifactsMissing') : format('artifactsEmpty')),
4278
4613
  h('span', { className: 'md-artifacts-hint' }, format('artifactsEmptyHint')),
4279
4614
  h('code', { className: 'md-path' }, state.dir),
4280
- h('button', {
4615
+ h(KitButton, {
4281
4616
  type: 'button',
4282
4617
  className: 'md-btn md-btn-small md-btn-ghost',
4283
4618
  onClick: () => props.onCopyPath(state.dir),
@@ -4297,7 +4632,7 @@ window.__ModuleLoader__.load({
4297
4632
  },
4298
4633
  h('div', { className: 'md-artifacts-head' },
4299
4634
  h('span', { className: 'md-artifacts-title' }, format('artifactsTitle')),
4300
- h('button', {
4635
+ h(KitButton, {
4301
4636
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
4302
4637
  onClick: () => setCollapsed(value => !value),
4303
4638
  }, collapsed ? format('artifactsExpand') : format('artifactsCollapse')),
@@ -4307,7 +4642,7 @@ window.__ModuleLoader__.load({
4307
4642
  phase === 'ready' && truncated
4308
4643
  ? h('span', { className: 'md-session-count' }, format('filesTruncated', { n: items.length }))
4309
4644
  : null,
4310
- h('button', {
4645
+ h(KitButton, {
4311
4646
  type: 'button',
4312
4647
  className: 'md-btn md-btn-small md-btn-ghost',
4313
4648
  'aria-label': format('artifactsReloadAria'),
@@ -4350,7 +4685,7 @@ window.__ModuleLoader__.load({
4350
4685
  h('div', null, preview.error === '' ? format('previewFailed') : preview.error),
4351
4686
  preview.errorCode === 'not-found' ? h('div', null, format('previewGone')) : null,
4352
4687
  h('div', { className: 'md-state-actions' },
4353
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: props.onRetry }, format('previewRetry'))
4688
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: props.onRetry }, format('previewRetry'))
4354
4689
  )
4355
4690
  )
4356
4691
  } else if (preview.phase === 'unsupported') {
@@ -4389,7 +4724,7 @@ window.__ModuleLoader__.load({
4389
4724
  h('div', { className: 'md-preview-meta' },
4390
4725
  [formatSize(preview.size), formatDate(preview.mtime)].filter(Boolean).join(' · '))
4391
4726
  ),
4392
- h('button', {
4727
+ h(KitButton, {
4393
4728
  type: 'button',
4394
4729
  className: 'md-btn md-btn-small md-btn-ghost',
4395
4730
  'aria-label': format('previewClose'),
@@ -4513,6 +4848,21 @@ window.__ModuleLoader__.load({
4513
4848
  out.push(points[points.length - 1])
4514
4849
  return out
4515
4850
  }
4851
+ /**
4852
+ * The page-fraction box of a text note. Notes saved before boxes existed
4853
+ * only carry x/y, so they get a stable size derived from their text; the
4854
+ * first resize writes explicit w/h without touching the text or style.
4855
+ * @param {object} entry - a stored text note.
4856
+ * @returns {{ x: number, y: number, w: number, h: number }} the box.
4857
+ */
4858
+ function noteBox(entry) {
4859
+ const text = String(entry.text ?? '')
4860
+ const fallbackWidth = Math.min(0.7, Math.max(0.18, text.length * 0.018))
4861
+ const w = Number.isFinite(entry.w) && entry.w > 0 ? entry.w : fallbackWidth
4862
+ const h = Number.isFinite(entry.h) && entry.h > 0 ? entry.h : 0.09
4863
+ return { x: entry.x, y: entry.y, w, h }
4864
+ }
4865
+
4516
4866
  /**
4517
4867
  * Translate one mark, used while dragging a selection.
4518
4868
  * @param {object} entry - the stored mark.
@@ -4592,7 +4942,7 @@ window.__ModuleLoader__.load({
4592
4942
  * line breaks stay. The draft's colour/size/family are written only when it
4593
4943
  * names them, so older notes keep their exact stored shape.
4594
4944
  * @param {Array<object>} list - the page's annotations.
4595
- * @param {{ index: number, x: number, y: number, color?: string, fontSize?: number, fontFamily?: string }} draft - the edited note.
4945
+ * @param {{ index: number, x: number, y: number, w?: number, h?: number, color?: string, fontSize?: number, fontFamily?: string, textAlign?: string }} draft - the edited note.
4596
4946
  * @param {string} raw - what the editor holds.
4597
4947
  * @returns {Array<object>} the new list (a copy; the input is untouched).
4598
4948
  */
@@ -4604,6 +4954,8 @@ window.__ModuleLoader__.load({
4604
4954
  if (typeof draft.fontSize === 'number' && Number.isFinite(draft.fontSize)) style.fontSize = draft.fontSize
4605
4955
  if (typeof draft.fontFamily === 'string' && draft.fontFamily !== '') style.fontFamily = draft.fontFamily
4606
4956
  if (typeof draft.textAlign === 'string' && draft.textAlign !== '') style.textAlign = draft.textAlign
4957
+ if (Number.isFinite(draft.w) && draft.w > 0) style.w = draft.w
4958
+ if (Number.isFinite(draft.h) && draft.h > 0) style.h = draft.h
4607
4959
  if (draft.index >= 0 && draft.index < next.length) {
4608
4960
  if (value === '') next.splice(draft.index, 1)
4609
4961
  else next[draft.index] = { ...next[draft.index], text: value, ...style }
@@ -4676,9 +5028,9 @@ window.__ModuleLoader__.load({
4676
5028
  function inkHit(entry, point, reachForWidth) {
4677
5029
  if (entry.kind === 'text') {
4678
5030
  const reach = reachForWidth(2)
4679
- const width = Math.min(0.9, Math.max(0.08, String(entry.text ?? '').length * 0.018))
4680
- return point[0] >= entry.x - reach && point[0] <= entry.x + width + reach
4681
- && point[1] >= entry.y - 0.02 - reach && point[1] <= entry.y + 0.035 + reach
5031
+ const box = noteBox(entry)
5032
+ return point[0] >= box.x - reach && point[0] <= box.x + box.w + reach
5033
+ && point[1] >= box.y - reach && point[1] <= box.y + box.h + reach
4682
5034
  }
4683
5035
  if (entry.kind === 'shape') {
4684
5036
  const reach = reachForWidth(Number(entry.width) || 2) + 0.012
@@ -4813,7 +5165,7 @@ window.__ModuleLoader__.load({
4813
5165
  ),
4814
5166
  h('div', { className: 'md-note-style-row' },
4815
5167
  h('span', { className: 'md-note-style-label' }, format('annotFontFamily')),
4816
- Object.keys(NOTE_FONTS).map(key => h('button', {
5168
+ Object.keys(NOTE_FONTS).map(key => h(KitButton, {
4817
5169
  key,
4818
5170
  type: 'button',
4819
5171
  className: 'md-note-style-btn',
@@ -4824,7 +5176,7 @@ window.__ModuleLoader__.load({
4824
5176
  ),
4825
5177
  h('div', { className: 'md-note-style-row' },
4826
5178
  h('span', { className: 'md-note-style-label' }, format('annotColor')),
4827
- NOTE_COLORS.map(value => h('button', {
5179
+ NOTE_COLORS.map(value => h(KitButton, {
4828
5180
  key: value,
4829
5181
  type: 'button',
4830
5182
  className: 'md-note-color',
@@ -4847,7 +5199,7 @@ window.__ModuleLoader__.load({
4847
5199
  function NoteStyleMenu(props) {
4848
5200
  const [open, setOpen] = useState(false)
4849
5201
  return h('span', { className: 'md-note-style-wrap' },
4850
- h('button', {
5202
+ h(KitButton, {
4851
5203
  type: 'button',
4852
5204
  className: 'md-btn md-btn-small md-note-style-trigger',
4853
5205
  'aria-haspopup': 'menu',
@@ -4898,13 +5250,16 @@ window.__ModuleLoader__.load({
4898
5250
  if (save) props.onSave()
4899
5251
  else props.onCancel()
4900
5252
  }
4901
- // The editor sits on the PDF page: keep the box inside the page even when
4902
- // the click lands near the right edge (the note itself stays at its point).
4903
- const left = Math.min(0.66, Math.max(0, draft.x)) * 100
5253
+ // The editor is the note box itself: drag-created boxes open at their
5254
+ // exact size, and older point notes fall back to a small default box.
5255
+ const left = Math.min(1, Math.max(0, draft.x))
5256
+ const top = Math.min(1, Math.max(0, draft.y))
5257
+ const width = Math.min(1 - left, Math.max(0.04, Number.isFinite(draft.w) ? draft.w : 0.38))
5258
+ const height = Math.min(1 - top, Math.max(0.035, Number.isFinite(draft.h) ? draft.h : 0.09))
4904
5259
  return h('div', {
4905
5260
  className: 'md-note-editor',
4906
5261
  ref: editorRef,
4907
- style: { left: `${left}%`, top: `${Math.max(0, draft.y) * 100}%`, maxWidth: `calc(100% - ${left}% - 6px)` },
5262
+ style: { left: `${left * 100}%`, top: `${top * 100}%`, width: `${width * 100}%`, height: `${height * 100}%` },
4908
5263
  onPointerDown: event => event.stopPropagation(),
4909
5264
  onPointerMove: event => event.stopPropagation(),
4910
5265
  onDoubleClick: event => event.stopPropagation(),
@@ -5475,6 +5830,7 @@ window.__ModuleLoader__.load({
5475
5830
  const storageKey = `pdfdesk:annots:${props.bookId}:${props.code}:${props.page}:${props.store}`
5476
5831
  const [strokes, setStrokes] = useState([])
5477
5832
  const [draft, setDraft] = useState(null)
5833
+ const [textDraft, setTextDraft] = useState(null)
5478
5834
  const [note, setNote] = useState(null)
5479
5835
  const strokesRef = useRef([])
5480
5836
  const draftRef = useRef(null)
@@ -5489,9 +5845,9 @@ window.__ModuleLoader__.load({
5489
5845
  const pointOf = event => inkPointOf(event, event.currentTarget)
5490
5846
  const within = (entry, point) => {
5491
5847
  if (entry.kind === 'text') {
5492
- const width = Math.min(0.9, Math.max(0.08, String(entry.text ?? '').length * 0.018))
5493
- return point[0] >= entry.x - HIT && point[0] <= entry.x + width + HIT
5494
- && point[1] >= entry.y - 0.02 - HIT && point[1] <= entry.y + 0.035 + HIT
5848
+ const box = noteBox(entry)
5849
+ return point[0] >= box.x - HIT && point[0] <= box.x + box.w + HIT
5850
+ && point[1] >= box.y - HIT && point[1] <= box.y + box.h + HIT
5495
5851
  }
5496
5852
  // This column keeps its fixed page-unit eraser: the shared segment test
5497
5853
  // only needs the reach this column has always used.
@@ -5562,6 +5918,7 @@ window.__ModuleLoader__.load({
5562
5918
  draftRef.current = null
5563
5919
  setDraft(null)
5564
5920
  setNote(null)
5921
+ setTextDraft(null)
5565
5922
  noteText.current = ''
5566
5923
  undoStack.current = []
5567
5924
  redoStack.current = []
@@ -5578,17 +5935,25 @@ window.__ModuleLoader__.load({
5578
5935
  noteRef.current = value
5579
5936
  setNote(value)
5580
5937
  }
5581
- const openNote = point => {
5938
+ const openNote = (point, box) => {
5582
5939
  const list = strokesRef.current
5583
- const index = list.findIndex(entry => entry.kind === 'text' && within(entry, point))
5940
+ const index = box === undefined ? list.findIndex(entry => entry.kind === 'text' && within(entry, point)) : -1
5584
5941
  noteSeq.current += 1
5585
5942
  const entry = index >= 0 ? list[index] : null
5586
5943
  noteText.current = entry === null ? '' : String(entry.text ?? '')
5944
+ const bounds = entry === null ? null : noteBox(entry)
5945
+ const fallbackWidth = Math.min(0.38, Math.max(0.18, 1 - point[0] - 0.02))
5946
+ const x = box === undefined ? Math.min(point[0], Math.max(0, 1 - fallbackWidth - 0.02)) : Math.max(0, Math.min(1 - 0.02, box.x))
5947
+ const y = box === undefined ? Math.min(point[1], 0.96) : Math.max(0, Math.min(1 - 0.02, box.y))
5948
+ const w = bounds === null ? (box === undefined ? fallbackWidth : Math.max(0.04, Math.min(1 - x, box.w))) : bounds.w
5949
+ const h = bounds === null ? (box === undefined ? 0.09 : Math.max(0.035, Math.min(1 - y, box.h))) : bounds.h
5587
5950
  setNoteBoth({
5588
5951
  id: noteSeq.current,
5589
5952
  index,
5590
- x: entry === null ? point[0] : entry.x,
5591
- y: entry === null ? point[1] : entry.y,
5953
+ x: bounds === null ? x : bounds.x,
5954
+ y: bounds === null ? y : bounds.y,
5955
+ w,
5956
+ h,
5592
5957
  text: noteText.current,
5593
5958
  color: entry === null ? props.color : (entry.color ?? props.color),
5594
5959
  fontSize: entry === null || !Number.isFinite(entry.fontSize) ? NOTE_SIZES[0] : entry.fontSize,
@@ -5622,10 +5987,9 @@ window.__ModuleLoader__.load({
5622
5987
  return
5623
5988
  }
5624
5989
  if (props.tool === 'text') {
5625
- // A click always starts a note where it lands: an editor left open is
5626
- // saved first, so a page can hold as many notes as the reader places.
5990
+ // Press-drag draws a box; a click still opens a default box on release.
5627
5991
  if (noteRef.current !== null) saveNote(noteRef.current.id)
5628
- openNote(point)
5992
+ setTextDraft({ x0: point[0], y0: point[1], x1: point[0], y1: point[1] })
5629
5993
  return
5630
5994
  }
5631
5995
  setDraftBoth({ kind: 'stroke', points: [point], color: props.color, width: props.width })
@@ -5638,6 +6002,13 @@ window.__ModuleLoader__.load({
5638
6002
  commit(strokesRef.current.filter(entry => !within(entry, point)))
5639
6003
  return
5640
6004
  }
6005
+ if (textDraft !== null) {
6006
+ const point = pointOf(event)
6007
+ if (point === null) return
6008
+ event.preventDefault()
6009
+ setTextDraft(current => (current === null ? null : { ...current, x1: point[0], y1: point[1] }))
6010
+ return
6011
+ }
5641
6012
  const current = draftRef.current
5642
6013
  if (current === null) return
5643
6014
  const point = pointOf(event)
@@ -5649,6 +6020,17 @@ window.__ModuleLoader__.load({
5649
6020
  }
5650
6021
  const up = () => {
5651
6022
  erasing.current = false
6023
+ if (textDraft !== null) {
6024
+ const box = textDraft
6025
+ setTextDraft(null)
6026
+ const x = Math.min(box.x0, box.x1)
6027
+ const y = Math.min(box.y0, box.y1)
6028
+ const w = Math.abs(box.x1 - box.x0)
6029
+ const h = Math.abs(box.y1 - box.y0)
6030
+ if (w > 0.012 && h > 0.012) openNote([x, y], { x, y, w, h })
6031
+ else openNote([box.x0, box.y0])
6032
+ return
6033
+ }
5652
6034
  const current = draftRef.current
5653
6035
  if (current === null) return
5654
6036
  setDraftBoth(null)
@@ -5687,39 +6069,57 @@ window.__ModuleLoader__.load({
5687
6069
  vectorEffect: 'non-scaling-stroke',
5688
6070
  strokeLinecap: 'round',
5689
6071
  strokeLinejoin: 'round',
6072
+ }),
6073
+ textDraft === null ? null : h('rect', {
6074
+ x: Math.min(textDraft.x0, textDraft.x1),
6075
+ y: Math.min(textDraft.y0, textDraft.y1),
6076
+ width: Math.abs(textDraft.x1 - textDraft.x0),
6077
+ height: Math.abs(textDraft.y1 - textDraft.y0),
6078
+ fill: 'none',
6079
+ stroke: '#2f6df6',
6080
+ strokeWidth: 1.5,
6081
+ strokeDasharray: '5 4',
6082
+ vectorEffect: 'non-scaling-stroke',
5690
6083
  })
5691
6084
  ),
5692
- notes.map((entry, index) => h('div', {
5693
- key: `note-${index}`,
5694
- className: 'md-annot-text',
5695
- title: props.tool === '' ? format('annotTextEditHint') : undefined,
5696
- style: {
5697
- left: `${entry.x * 100}%`,
5698
- top: `${entry.y * 100}%`,
5699
- color: entry.color ?? '#e0554a',
5700
- fontSize: Number.isFinite(entry.fontSize) ? `${entry.fontSize}px` : undefined,
5701
- fontFamily: typeof entry.fontFamily === 'string' ? (NOTE_FONTS[entry.fontFamily] ?? undefined) : undefined,
5702
- },
5703
- onPointerDown: props.tool === '' ? event => event.stopPropagation() : undefined,
5704
- onDoubleClick: props.tool === ''
5705
- ? event => {
5706
- event.preventDefault()
5707
- event.stopPropagation()
5708
- noteSeq.current += 1
5709
- noteText.current = String(entry.text ?? '')
5710
- setNoteBoth({
5711
- id: noteSeq.current,
5712
- index: strokesRef.current.indexOf(entry),
5713
- x: entry.x,
5714
- y: entry.y,
5715
- text: noteText.current,
5716
- color: entry.color ?? props.color,
5717
- fontSize: Number.isFinite(entry.fontSize) ? entry.fontSize : NOTE_SIZES[0],
5718
- fontFamily: typeof entry.fontFamily === 'string' ? entry.fontFamily : 'normal',
5719
- })
5720
- }
5721
- : undefined,
5722
- }, entry.text)),
6085
+ notes.map((entry, index) => {
6086
+ const bounds = noteBox(entry)
6087
+ const hasBox = Number.isFinite(entry.w) && entry.w > 0 && Number.isFinite(entry.h) && entry.h > 0
6088
+ return h('div', {
6089
+ key: `note-${index}`,
6090
+ className: 'md-annot-text',
6091
+ title: props.tool === '' ? format('annotTextEditHint') : undefined,
6092
+ style: {
6093
+ left: `${bounds.x * 100}%`,
6094
+ top: `${bounds.y * 100}%`,
6095
+ ...(hasBox ? { width: `${bounds.w * 100}%`, height: `${bounds.h * 100}%` } : { maxWidth: '70%' }),
6096
+ color: entry.color ?? '#e0554a',
6097
+ fontSize: Number.isFinite(entry.fontSize) ? `${entry.fontSize}px` : undefined,
6098
+ fontFamily: typeof entry.fontFamily === 'string' ? (NOTE_FONTS[entry.fontFamily] ?? undefined) : undefined,
6099
+ },
6100
+ onPointerDown: props.tool === '' ? event => event.stopPropagation() : undefined,
6101
+ onDoubleClick: props.tool === ''
6102
+ ? event => {
6103
+ event.preventDefault()
6104
+ event.stopPropagation()
6105
+ noteSeq.current += 1
6106
+ noteText.current = String(entry.text ?? '')
6107
+ setNoteBoth({
6108
+ id: noteSeq.current,
6109
+ index: strokesRef.current.indexOf(entry),
6110
+ x: bounds.x,
6111
+ y: bounds.y,
6112
+ w: bounds.w,
6113
+ h: bounds.h,
6114
+ text: noteText.current,
6115
+ color: entry.color ?? props.color,
6116
+ fontSize: Number.isFinite(entry.fontSize) ? entry.fontSize : NOTE_SIZES[0],
6117
+ fontFamily: typeof entry.fontFamily === 'string' ? entry.fontFamily : 'normal',
6118
+ })
6119
+ }
6120
+ : undefined,
6121
+ }, entry.text)
6122
+ }),
5723
6123
  note === null ? null : h(NoteEditor, {
5724
6124
  key: `note-${note.id}`,
5725
6125
  draft: note,
@@ -5817,14 +6217,14 @@ window.__ModuleLoader__.load({
5817
6217
  if (Array.isArray(row.children) && row.children.length > 0) {
5818
6218
  const open = openGroup === row.id
5819
6219
  return h('div', { key: row.id, className: 'md-fallback-group' },
5820
- h('button', {
6220
+ h(KitButton, {
5821
6221
  type: 'button',
5822
6222
  className: 'md-fallback-row md-fallback-parent',
5823
6223
  'aria-expanded': open ? 'true' : 'false',
5824
6224
  onClick: () => setOpenGroup(open ? '' : row.id),
5825
6225
  }, `${row.label} ${open ? '▾' : '▸'}`),
5826
6226
  open
5827
- ? h('div', { className: 'md-fallback-children' }, row.children.map(child => h('button', {
6227
+ ? h('div', { className: 'md-fallback-children' }, row.children.map(child => h(KitButton, {
5828
6228
  key: child.id,
5829
6229
  type: 'button',
5830
6230
  className: 'md-fallback-row',
@@ -5833,7 +6233,7 @@ window.__ModuleLoader__.load({
5833
6233
  }, child.label)))
5834
6234
  : null)
5835
6235
  }
5836
- return h('button', {
6236
+ return h(KitButton, {
5837
6237
  key: row.id,
5838
6238
  type: 'button',
5839
6239
  className: 'md-fallback-row',
@@ -6319,6 +6719,8 @@ window.__ModuleLoader__.load({
6319
6719
  const [selection, setSelection] = useState(null)
6320
6720
  // A shape being dragged out, and a selected mark being moved.
6321
6721
  const [shapeDraft, setShapeDraft] = useState(null)
6722
+ // A text box being dragged out before the editor opens.
6723
+ const [textDraft, setTextDraft] = useState(null)
6322
6724
  const [drag, setDrag] = useState(null)
6323
6725
  const [resize, setResize] = useState(null)
6324
6726
  const [resizeEntry, setResizeEntry] = useState(null)
@@ -6830,6 +7232,7 @@ window.__ModuleLoader__.load({
6830
7232
  useEffect(() => {
6831
7233
  setNoteEdit(null)
6832
7234
  setDraftStroke(null)
7235
+ setTextDraft(null)
6833
7236
  setSelection(null)
6834
7237
  setDrag(null)
6835
7238
  setResize(null)
@@ -6865,19 +7268,24 @@ window.__ModuleLoader__.load({
6865
7268
  // pointer is opened for editing instead of stacking a second note on top.
6866
7269
  // `side` says which layer opened the draft, so the editor renders in that
6867
7270
  // column and never in the other one.
6868
- const openNote = (point, side) => {
7271
+ const openNote = (point, side, box) => {
6869
7272
  const list = strokesRef.current
6870
- const found = list.findIndex(entry => entry.kind === 'text' && annotHit(entry, point))
7273
+ const found = box === undefined
7274
+ ? list.findIndex(entry => entry.kind === 'text' && annotHit(entry, point))
7275
+ : -1
6871
7276
  noteSeq.current += 1
6872
7277
  if (found >= 0) {
6873
7278
  const entry = list[found]
7279
+ const bounds = noteBox(entry)
6874
7280
  noteText.current = String(entry.text ?? '')
6875
7281
  setNoteEdit({
6876
7282
  id: noteSeq.current,
6877
7283
  side,
6878
7284
  index: found,
6879
- x: entry.x,
6880
- y: entry.y,
7285
+ x: bounds.x,
7286
+ y: bounds.y,
7287
+ w: bounds.w,
7288
+ h: bounds.h,
6881
7289
  text: noteText.current,
6882
7290
  color: entry.color ?? annotColor,
6883
7291
  fontSize: Number.isFinite(entry.fontSize) ? entry.fontSize : NOTE_SIZES[0],
@@ -6886,13 +7294,22 @@ window.__ModuleLoader__.load({
6886
7294
  })
6887
7295
  return
6888
7296
  }
7297
+ const fallbackWidth = Math.min(0.38, Math.max(0.18, 1 - point[0] - 0.02))
7298
+ const x = box === undefined
7299
+ ? Math.min(point[0], Math.max(0, 1 - fallbackWidth - 0.02))
7300
+ : Math.max(0, Math.min(1 - 0.02, box.x))
7301
+ const y = box === undefined ? Math.min(point[1], 1 - 0.04) : Math.max(0, Math.min(1 - 0.02, box.y))
7302
+ const w = box === undefined ? fallbackWidth : Math.max(0.04, Math.min(1 - x, box.w))
7303
+ const h = box === undefined ? 0.09 : Math.max(0.035, Math.min(1 - y, box.h))
6889
7304
  noteText.current = ''
6890
7305
  setNoteEdit({
6891
7306
  id: noteSeq.current,
6892
7307
  side,
6893
7308
  index: -1,
6894
- x: point[0],
6895
- y: point[1],
7309
+ x,
7310
+ y,
7311
+ w,
7312
+ h,
6896
7313
  text: '',
6897
7314
  color: noteStyle.color,
6898
7315
  fontSize: noteStyle.fontSize,
@@ -6958,7 +7375,7 @@ window.__ModuleLoader__.load({
6958
7375
  * @param {string} path - SVG path for `annotIcon`.
6959
7376
  * @returns {import('react').ReactElement} the button.
6960
7377
  */
6961
- const railTool = (id, labelKey, path) => h('button', {
7378
+ const railTool = (id, labelKey, path) => h(KitButton, {
6962
7379
  type: 'button',
6963
7380
  className: 'md-rail-btn',
6964
7381
  'aria-pressed': annotTool === id ? 'true' : 'false',
@@ -6999,10 +7416,10 @@ window.__ModuleLoader__.load({
6999
7416
  return
7000
7417
  }
7001
7418
  if (annotTool === 'text') {
7002
- // A click always starts a note where it lands: an open editor is saved
7003
- // first, so a page can hold as many notes as the reader places.
7419
+ // A press-drag draws the box; a simple click still opens a default
7420
+ // box on release, so both PPT-style and point-style placement work.
7004
7421
  if (noteEditRef.current !== null) saveNote(noteEditRef.current.id)
7005
- openNote(point, side)
7422
+ setTextDraft({ x0: point[0], y0: point[1], x1: point[0], y1: point[1], side })
7006
7423
  return
7007
7424
  }
7008
7425
  setDraftStroke({ kind: 'stroke', points: [[point[0], point[1], strokePressure(event)]], color: annotColor, width: annotWidth })
@@ -7017,6 +7434,13 @@ window.__ModuleLoader__.load({
7017
7434
  savePageAnnots(strokesRef.current.filter(entry => !annotHit(entry, point)))
7018
7435
  return
7019
7436
  }
7437
+ if (textDraft !== null) {
7438
+ const point = annotPoint(event)
7439
+ if (point === null) return
7440
+ event.preventDefault()
7441
+ setTextDraft(current => (current === null ? null : { ...current, x1: point[0], y1: point[1] }))
7442
+ return
7443
+ }
7020
7444
  if (resize !== null) {
7021
7445
  const point = annotPoint(event)
7022
7446
  if (point === null) return
@@ -7069,6 +7493,17 @@ window.__ModuleLoader__.load({
7069
7493
  }
7070
7494
  const annotUp = () => {
7071
7495
  erasing.current = false
7496
+ if (textDraft !== null) {
7497
+ const draft = textDraft
7498
+ setTextDraft(null)
7499
+ const x = Math.min(draft.x0, draft.x1)
7500
+ const y = Math.min(draft.y0, draft.y1)
7501
+ const w = Math.abs(draft.x1 - draft.x0)
7502
+ const h = Math.abs(draft.y1 - draft.y0)
7503
+ if (w > 0.012 && h > 0.012) openNote([x, y], draft.side, { x, y, w, h })
7504
+ else openNote([draft.x0, draft.y0], draft.side)
7505
+ return
7506
+ }
7072
7507
  if (resizeEntry !== null && resize !== null) {
7073
7508
  savePageAnnots(strokesRef.current.map((entry, index) => (index === resize.index ? resizeEntry : entry)))
7074
7509
  setResize(null)
@@ -7663,6 +8098,19 @@ window.__ModuleLoader__.load({
7663
8098
  vectorEffect: 'non-scaling-stroke',
7664
8099
  })
7665
8100
  : null,
8101
+ textDraft !== null
8102
+ ? h('rect', {
8103
+ x: Math.min(textDraft.x0, textDraft.x1),
8104
+ y: Math.min(textDraft.y0, textDraft.y1),
8105
+ width: Math.abs(textDraft.x1 - textDraft.x0),
8106
+ height: Math.abs(textDraft.y1 - textDraft.y0),
8107
+ fill: 'none',
8108
+ stroke: '#2f6df6',
8109
+ strokeWidth: 1.5,
8110
+ strokeDasharray: '5 4',
8111
+ vectorEffect: 'non-scaling-stroke',
8112
+ })
8113
+ : null,
7666
8114
  strokes.map((stroke, index) => {
7667
8115
  if (stroke.kind === 'text' || stroke.kind === 'shape') return null
7668
8116
  const shown = drag !== null && drag.index === index ? translateEntry(stroke, drag.dx, drag.dy) : stroke
@@ -7736,67 +8184,80 @@ window.__ModuleLoader__.load({
7736
8184
  // Iterating `strokes` (not the filtered notes) keeps the index aligned
7737
8185
  // with the stored list, so a double-click edits the right entry.
7738
8186
  strokes.map((entry, index) => (entry.kind === 'text'
7739
- ? h('div', {
7740
- key: `text-${index}`,
7741
- className: selection !== null && selection.index === index ? 'md-annot-text md-annot-selected' : 'md-annot-text',
7742
- title: annotTool === '' ? format('annotTextEditHint') : undefined,
7743
- style: {
7744
- left: `${entry.x * 100}%`,
7745
- top: `${entry.y * 100}%`,
7746
- color: entry.color ?? '#e0554a',
7747
- fontSize: Number.isFinite(entry.fontSize) ? `${entry.fontSize}px` : undefined,
7748
- fontFamily: typeof entry.fontFamily === 'string' ? (NOTE_FONTS[entry.fontFamily] ?? undefined) : undefined,
7749
- opacity: entry.opacity ?? 1,
7750
- textAlign: typeof entry.textAlign === 'string' ? entry.textAlign : 'left',
7751
- },
7752
- onPointerDown: annotTool === '' ? event => event.stopPropagation() : undefined,
7753
- onDoubleClick: annotTool === ''
7754
- ? event => {
7755
- event.preventDefault()
7756
- event.stopPropagation()
7757
- noteSeq.current += 1
7758
- noteText.current = String(entry.text ?? '')
7759
- setNoteEdit({
7760
- id: noteSeq.current,
7761
- side,
7762
- index,
7763
- x: entry.x,
7764
- y: entry.y,
7765
- text: noteText.current,
7766
- color: entry.color ?? annotColor,
7767
- fontSize: Number.isFinite(entry.fontSize) ? entry.fontSize : NOTE_SIZES[0],
7768
- fontFamily: typeof entry.fontFamily === 'string' ? entry.fontFamily : 'normal',
7769
- })
7770
- }
7771
- : undefined,
7772
- }, entry.text)
7773
- : null)),
7774
- selection !== null && selectedEntry !== undefined && selectedEntry.kind === 'shape' && annotTool === 'select'
7775
- ? h('div', { className: 'md-shape-handles' },
7776
- (selectedEntry.shape === 'line' || selectedEntry.shape === 'arrow'
7777
- ? [['start', selectedEntry.x0, selectedEntry.y0], ['end', selectedEntry.x1, selectedEntry.y1]]
7778
- : [
7779
- ['nw', selectedEntry.x, selectedEntry.y],
7780
- ['ne', selectedEntry.x + selectedEntry.w, selectedEntry.y],
7781
- ['sw', selectedEntry.x, selectedEntry.y + selectedEntry.h],
7782
- ['se', selectedEntry.x + selectedEntry.w, selectedEntry.y + selectedEntry.h],
7783
- ]).map(item => h('div', {
7784
- key: item[0],
7785
- className: 'md-shape-handle',
7786
- style: { left: `${item[1] * 100}%`, top: `${item[2] * 100}%` },
7787
- onPointerDown: event => {
7788
- event.preventDefault()
7789
- event.stopPropagation()
7790
- const box = event.currentTarget.closest('.md-annot')?.getBoundingClientRect()
7791
- if (box === undefined || box === null) return
7792
- const point = [
7793
- Math.min(1, Math.max(0, (event.clientX - box.left) / box.width)),
7794
- Math.min(1, Math.max(0, (event.clientY - box.top) / box.height)),
7795
- ]
7796
- setResize({ index: selection.index, corner: item[0], start: point, original: selectedEntry })
7797
- setResizeEntry(selectedEntry)
8187
+ ? (() => {
8188
+ const shown = drag !== null && drag.index === index ? translateEntry(entry, drag.dx, drag.dy) : entry
8189
+ const bounds = noteBox(shown)
8190
+ const hasBox = Number.isFinite(shown.w) && shown.w > 0 && Number.isFinite(shown.h) && shown.h > 0
8191
+ return h('div', {
8192
+ key: `text-${index}`,
8193
+ className: selection !== null && selection.index === index ? 'md-annot-text md-annot-selected' : 'md-annot-text',
8194
+ title: annotTool === '' ? format('annotTextEditHint') : undefined,
8195
+ style: {
8196
+ left: `${bounds.x * 100}%`,
8197
+ top: `${bounds.y * 100}%`,
8198
+ ...(hasBox ? { width: `${bounds.w * 100}%`, height: `${bounds.h * 100}%` } : { maxWidth: '70%' }),
8199
+ color: entry.color ?? '#e0554a',
8200
+ fontSize: Number.isFinite(entry.fontSize) ? `${entry.fontSize}px` : undefined,
8201
+ fontFamily: typeof entry.fontFamily === 'string' ? (NOTE_FONTS[entry.fontFamily] ?? undefined) : undefined,
8202
+ opacity: entry.opacity ?? 1,
8203
+ textAlign: typeof entry.textAlign === 'string' ? entry.textAlign : 'left',
7798
8204
  },
7799
- })))
8205
+ onPointerDown: annotTool === '' ? event => event.stopPropagation() : undefined,
8206
+ onDoubleClick: annotTool === ''
8207
+ ? event => {
8208
+ event.preventDefault()
8209
+ event.stopPropagation()
8210
+ noteSeq.current += 1
8211
+ noteText.current = String(entry.text ?? '')
8212
+ setNoteEdit({
8213
+ id: noteSeq.current,
8214
+ side,
8215
+ index,
8216
+ x: bounds.x,
8217
+ y: bounds.y,
8218
+ w: bounds.w,
8219
+ h: bounds.h,
8220
+ text: noteText.current,
8221
+ color: entry.color ?? annotColor,
8222
+ fontSize: Number.isFinite(entry.fontSize) ? entry.fontSize : NOTE_SIZES[0],
8223
+ fontFamily: typeof entry.fontFamily === 'string' ? entry.fontFamily : 'normal',
8224
+ textAlign: typeof entry.textAlign === 'string' ? entry.textAlign : 'left',
8225
+ })
8226
+ }
8227
+ : undefined,
8228
+ }, entry.text)
8229
+ })()
8230
+ : null)),
8231
+ selection !== null && selectedEntry !== undefined && (selectedEntry.kind === 'shape' || selectedEntry.kind === 'text') && annotTool === 'select'
8232
+ ? (() => {
8233
+ const box = selectedEntry.kind === 'text' ? noteBox(selectedEntry) : selectedEntry
8234
+ return h('div', { className: 'md-shape-handles' },
8235
+ (selectedEntry.kind === 'shape' && (selectedEntry.shape === 'line' || selectedEntry.shape === 'arrow')
8236
+ ? [['start', box.x0, box.y0], ['end', box.x1, box.y1]]
8237
+ : [
8238
+ ['nw', box.x, box.y],
8239
+ ['ne', box.x + box.w, box.y],
8240
+ ['sw', box.x, box.y + box.h],
8241
+ ['se', box.x + box.w, box.y + box.h],
8242
+ ]).map(item => h('div', {
8243
+ key: item[0],
8244
+ className: 'md-shape-handle',
8245
+ style: { left: `${item[1] * 100}%`, top: `${item[2] * 100}%` },
8246
+ onPointerDown: event => {
8247
+ event.preventDefault()
8248
+ event.stopPropagation()
8249
+ const annot = event.currentTarget.closest('.md-annot')?.getBoundingClientRect()
8250
+ if (annot === undefined || annot === null) return
8251
+ const point = [
8252
+ Math.min(1, Math.max(0, (event.clientX - annot.left) / annot.width)),
8253
+ Math.min(1, Math.max(0, (event.clientY - annot.top) / annot.height)),
8254
+ ]
8255
+ const original = selectedEntry.kind === 'text' ? { ...selectedEntry, ...box } : box
8256
+ setResize({ index: selection.index, corner: item[0], start: point, original })
8257
+ setResizeEntry(original)
8258
+ },
8259
+ })))
8260
+ })()
7800
8261
  : null,
7801
8262
  noteEdit === null || noteEdit.side !== side
7802
8263
  ? null
@@ -7851,33 +8312,33 @@ window.__ModuleLoader__.load({
7851
8312
  onPointerLeave: () => setRailOpen(false),
7852
8313
  },
7853
8314
  h('div', { className: 'md-reader-bar' },
7854
- h('button', {
8315
+ h(KitButton, {
7855
8316
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
7856
8317
  title: format('readerShelfHint'), 'aria-label': format('readerShelf'),
7857
8318
  onClick: props.onShelf,
7858
8319
  }, `⌂ ${format('readerShelf')}`),
7859
- h('button', { type: 'button', className: 'md-btn md-btn-small md-btn-ghost', onClick: props.onBack }, `‹ ${format('readerBack')}`),
8320
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small md-btn-ghost', onClick: props.onBack }, `‹ ${format('readerBack')}`),
7860
8321
  h('div', { className: 'md-reader-titles' },
7861
8322
  h('span', { className: 'md-reader-name', title: label }, label),
7862
8323
  sub === '' ? null : h('span', { className: 'md-reader-sub' }, sub)
7863
8324
  ),
7864
8325
  h('div', { className: 'md-reader-tools' },
7865
- h('button', {
8326
+ h(KitButton, {
7866
8327
  type: 'button', className: 'md-btn md-btn-small',
7867
8328
  disabled: reader.page <= 1, title: format('readerFirstHint'), 'aria-label': format('readerFirst'),
7868
8329
  onClick: () => props.onPage(1),
7869
8330
  }, '⇤'),
7870
- h('button', {
8331
+ h(KitButton, {
7871
8332
  type: 'button', className: 'md-btn md-btn-small',
7872
8333
  disabled: reader.page <= 1, title: format('readerPrev'), 'aria-label': format('readerPrev'),
7873
8334
  onClick: props.onPrev,
7874
8335
  }, '‹'),
7875
- h('input', {
8336
+ h(KitInput, {
7876
8337
  className: 'md-reader-page',
7877
8338
  type: 'number', min: 1, max: reader.count > 0 ? reader.count : undefined,
7878
8339
  value: pageText,
7879
8340
  'aria-label': format('readerPage'),
7880
- onChange: event => setPageText(event.target.value),
8341
+ onChange: value => setPageText(value),
7881
8342
  onKeyDown: event => {
7882
8343
  if (event.key !== 'Enter') return
7883
8344
  event.preventDefault()
@@ -7886,43 +8347,43 @@ window.__ModuleLoader__.load({
7886
8347
  onBlur: commitPage,
7887
8348
  }),
7888
8349
  h('span', { className: 'md-reader-of' }, format('readerOf', { n: reader.count > 0 ? reader.count : '?' })),
7889
- h('button', {
8350
+ h(KitButton, {
7890
8351
  type: 'button', className: 'md-btn md-btn-small',
7891
8352
  disabled: reader.count === 0 || reader.page >= reader.count,
7892
8353
  title: format('readerNext'), 'aria-label': format('readerNext'),
7893
8354
  onClick: props.onNext,
7894
8355
  }, '›'),
7895
8356
  h('span', { className: 'md-reader-sep', 'aria-hidden': true }),
7896
- h('button', {
8357
+ h(KitButton, {
7897
8358
  type: 'button', className: `md-btn md-btn-small${dual ? ' md-hidden' : ''}`, disabled: !ready,
7898
8359
  title: format('readerZoomOut'), 'aria-label': format('readerZoomOut'),
7899
8360
  onClick: props.onZoomOut,
7900
8361
  }, '−'),
7901
- h('button', {
8362
+ h(KitButton, {
7902
8363
  type: 'button', className: `md-btn md-btn-small${dual ? ' md-hidden' : ''}`, disabled: !ready,
7903
8364
  title: format('readerFit'),
7904
8365
  onClick: props.onFit,
7905
8366
  }, format('readerFit')),
7906
- h('button', {
8367
+ h(KitButton, {
7907
8368
  type: 'button', className: `md-btn md-btn-small${dual ? ' md-hidden' : ''}`, disabled: !ready,
7908
8369
  title: format('readerZoomIn'), 'aria-label': format('readerZoomIn'),
7909
8370
  onClick: props.onZoomIn,
7910
8371
  }, '+'),
7911
8372
  h('span', { className: `md-reader-scale${dual ? ' md-hidden' : ''}`, 'aria-hidden': true }, `${Math.round((reader.scale ?? 1) * 100)}%`)
7912
8373
  ),
7913
- h('button', {
8374
+ h(KitButton, {
7914
8375
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
7915
8376
  'aria-label': format('toolsToggle'), title: format('toolsToggle'),
7916
8377
  onClick: () => setToolsOpen(value => !value),
7917
8378
  }, toolsOpen ? '⌃' : '⌄'),
7918
- h('button', {
8379
+ h(KitButton, {
7919
8380
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
7920
8381
  'aria-label': format('previewClose'), title: format('previewClose'),
7921
8382
  onClick: props.onBack,
7922
8383
  }, '×')
7923
8384
  ),
7924
8385
  h('div', { className: 'md-reader-subbar', style: toolsOpen ? undefined : { display: 'none' } },
7925
- h('button', {
8386
+ h(KitButton, {
7926
8387
  type: 'button', className: 'md-btn md-btn-small',
7927
8388
  disabled: props.busy,
7928
8389
  title: format('generalSessionHint'),
@@ -7932,20 +8393,20 @@ window.__ModuleLoader__.load({
7932
8393
  }, format('generalSession')),
7933
8394
  h('span', { className: 'md-reader-sep', 'aria-hidden': true }),
7934
8395
  h('span', { className: 'md-reader-modes', role: 'group', 'aria-label': format('readerMode') },
7935
- h('button', {
8396
+ h(KitButton, {
7936
8397
  type: 'button', className: 'md-btn md-btn-small', 'aria-pressed': modeOf('single') ? 'true' : 'false',
7937
8398
  onClick: () => props.onMode('single'),
7938
8399
  }, format('readerModeSingle')),
7939
- h('button', {
8400
+ h(KitButton, {
7940
8401
  type: 'button', className: 'md-btn md-btn-small', 'aria-pressed': modeOf('continuous') ? 'true' : 'false',
7941
8402
  onClick: () => props.onMode('continuous'),
7942
8403
  }, format('readerModeContinuous')),
7943
- h('button', {
8404
+ h(KitButton, {
7944
8405
  type: 'button', className: 'md-btn md-btn-small', 'aria-pressed': showBlocks ? 'true' : 'false',
7945
8406
  title: format('blocksHint'),
7946
8407
  onClick: () => setShowBlocks(value => !value),
7947
8408
  }, format('blocksToggle')),
7948
- h('button', {
8409
+ h(KitButton, {
7949
8410
  type: 'button', className: 'md-btn md-btn-small', 'aria-pressed': dual ? 'true' : 'false',
7950
8411
  title: format('dualHint'),
7951
8412
  onClick: () => {
@@ -7971,7 +8432,7 @@ window.__ModuleLoader__.load({
7971
8432
  })
7972
8433
  },
7973
8434
  }, format('dualToggle')),
7974
- h('button', {
8435
+ h(KitButton, {
7975
8436
  type: 'button', className: 'md-btn md-btn-small', 'aria-pressed': overlay ? 'true' : 'false',
7976
8437
  title: format('overlayHint'),
7977
8438
  onClick: () => {
@@ -7997,43 +8458,43 @@ window.__ModuleLoader__.load({
7997
8458
  },
7998
8459
  }, format('overlayToggle')),
7999
8460
  overlay
8000
- ? h('button', {
8461
+ ? h(KitButton, {
8001
8462
  type: 'button', className: 'md-btn md-btn-small md-blocks-toggle',
8002
8463
  'aria-pressed': autoBoxed ? 'true' : 'false',
8003
8464
  title: format(autoBoxed ? 'overlayBlocksCancelHint' : 'overlayBlocksHint'),
8004
8465
  onClick: () => { void maskAllBlocks() },
8005
8466
  }, autoBoxed ? format('overlayBlocksCancel') : format('overlayBlocks'))
8006
8467
  : null,
8007
- h('select', {
8468
+ h(KitSelect, {
8008
8469
  className: 'md-reader-lang md-reader-export',
8009
8470
  value: '',
8010
8471
  title: format('exportGroupHint'),
8011
- 'aria-label': format('exportGroup'),
8012
- onChange: event => {
8013
- const action = event.target.value
8014
- event.target.value = ''
8472
+ label: format('exportGroup'),
8473
+ placeholder: format('exportGroup'),
8474
+ options: [
8475
+ { value: 'page', label: format('exportPage') },
8476
+ { value: 'chapter', label: format('exportChapter') },
8477
+ { value: 'import', label: format('importAnnots') },
8478
+ ],
8479
+ onChange: action => {
8015
8480
  if (action === 'page') void exportPage()
8016
8481
  else if (action === 'chapter') void exportChapter()
8017
8482
  else if (action === 'import') void importAnnots()
8018
8483
  },
8019
- },
8020
- h('option', { value: '' }, format('exportGroup')),
8021
- h('option', { value: 'page' }, format('exportPage')),
8022
- h('option', { value: 'chapter' }, format('exportChapter')),
8023
- h('option', { value: 'import' }, format('importAnnots'))
8024
- ),
8484
+ }),
8025
8485
  h('span', { className: 'md-reader-sep', 'aria-hidden': true }),
8026
- h('select', {
8486
+ h(KitSelect, {
8027
8487
  className: 'md-reader-lang',
8028
8488
  value: translateTarget,
8029
8489
  title: format('translateHint'),
8030
- 'aria-label': format('translateFor'),
8031
- onChange: event => setTranslateTarget(event.target.value),
8032
- },
8033
- h('option', { value: 'zh' }, format('langZh')),
8034
- h('option', { value: 'en' }, format('langEn'))
8035
- ),
8036
- h('button', {
8490
+ label: format('translateFor'),
8491
+ options: [
8492
+ { value: 'zh', label: format('langZh') },
8493
+ { value: 'en', label: format('langEn') },
8494
+ ],
8495
+ onChange: value => setTranslateTarget(value),
8496
+ }),
8497
+ h(KitButton, {
8037
8498
  type: 'button', className: 'md-btn md-btn-small',
8038
8499
  disabled: translating || reader.phase !== 'ready',
8039
8500
  title: format('translateHint'),
@@ -8052,14 +8513,14 @@ window.__ModuleLoader__.load({
8052
8513
  ? null
8053
8514
  : h(React.Fragment, null,
8054
8515
  h('span', { className: 'md-reader-sep', 'aria-hidden': true }),
8055
- h('button', {
8516
+ h(KitButton, {
8056
8517
  type: 'button', className: 'md-btn md-btn-small',
8057
8518
  'aria-pressed': props.forceNew ? 'true' : 'false',
8058
8519
  title: format('forceNewHint'),
8059
8520
  onClick: () => props.onForceNew(!props.forceNew),
8060
8521
  }, format('forceNew')),
8061
8522
  h('span', { className: 'md-reader-newlabel' }, format('readerNewLabel')),
8062
- MODES.map(mode => h('button', {
8523
+ MODES.map(mode => h(KitButton, {
8063
8524
  key: mode,
8064
8525
  type: 'button',
8065
8526
  className: 'md-btn md-btn-small',
@@ -8073,25 +8534,25 @@ window.__ModuleLoader__.load({
8073
8534
  translateNote === '' ? null : h('div', { className: 'md-reader-note-reveal' },
8074
8535
  h('div', { className: 'md-reader-note', role: 'status' },
8075
8536
  h('span', null, translateNote),
8076
- translating ? h('button', {
8537
+ translating ? h(KitButton, {
8077
8538
  type: 'button', className: 'md-btn md-btn-small',
8078
8539
  onClick: cancelTranslate,
8079
8540
  }, format('translateCancel')) : null,
8080
8541
  !translating && partialPages.length > 0 && props.canTranslate === true
8081
- ? h('button', {
8542
+ ? h(KitButton, {
8082
8543
  type: 'button', className: 'md-btn md-btn-small',
8083
8544
  title: format('translateResumeHint'),
8084
8545
  onClick: () => { void runTranslate(true) },
8085
8546
  }, format('translateResume'))
8086
8547
  : null,
8087
8548
  exportJob !== ''
8088
- ? h('button', {
8549
+ ? h(KitButton, {
8089
8550
  type: 'button', className: 'md-btn md-btn-small',
8090
8551
  onClick: cancelExport,
8091
8552
  }, format('exportCancel'))
8092
8553
  : null,
8093
8554
  !translating && retryAction !== null
8094
- ? h('button', {
8555
+ ? h(KitButton, {
8095
8556
  type: 'button', className: 'md-btn md-btn-small',
8096
8557
  onClick: () => {
8097
8558
  const run = retryAction
@@ -8114,7 +8575,7 @@ window.__ModuleLoader__.load({
8114
8575
  // The button disappears while the rebuild runs; the note itself
8115
8576
  // carries the progress, so there is no button label to explain.
8116
8577
  overlayReflow && !realigning
8117
- ? h('button', {
8578
+ ? h(KitButton, {
8118
8579
  type: 'button', className: 'md-btn md-btn-small',
8119
8580
  title: format('overlayRealignHint'),
8120
8581
  onClick: () => { void realignOverlay() },
@@ -8130,16 +8591,16 @@ window.__ModuleLoader__.load({
8130
8591
  h('div', { className: 'md-reader-column', ref: dualLeft },
8131
8592
  h('div', { className: 'md-reader-colhead' },
8132
8593
  h('span', { className: 'md-reader-coltitle' }, format('dualOriginal')),
8133
- h('button', {
8594
+ h(KitButton, {
8134
8595
  type: 'button', className: 'md-btn md-btn-small',
8135
8596
  onClick: () => setDualLeftScale(value => Math.max(0.2, (value ?? dualFit.left ?? 1) / 1.2)),
8136
8597
  }, '−'),
8137
8598
  h('span', { className: 'md-reader-scale' }, String(Math.round((dualLeftScale ?? dualFit.left ?? 1) * 100)) + '%'),
8138
- h('button', {
8599
+ h(KitButton, {
8139
8600
  type: 'button', className: 'md-btn md-btn-small',
8140
8601
  onClick: () => setDualLeftScale(value => Math.min(3, (value ?? dualFit.left ?? 1) * 1.2)),
8141
8602
  }, '+'),
8142
- h('button', {
8603
+ h(KitButton, {
8143
8604
  type: 'button', className: 'md-btn md-btn-small',
8144
8605
  onClick: () => setDualLeftScale(null),
8145
8606
  }, format('readerFitScreen'))
@@ -8164,16 +8625,16 @@ window.__ModuleLoader__.load({
8164
8625
  h('div', { className: 'md-reader-colhead' },
8165
8626
  h('span', { className: 'md-reader-coltitle' }, format('dualTranslated')),
8166
8627
  h('span', { className: 'md-reader-scale' }, format('dualPage', { n: dualRightPage })),
8167
- h('button', {
8628
+ h(KitButton, {
8168
8629
  type: 'button', className: 'md-btn md-btn-small',
8169
8630
  onClick: () => setRightScale(value => Math.max(0.5, (value ?? dualFit.right ?? 1) - 0.1)),
8170
8631
  }, '−'),
8171
8632
  h('span', { className: 'md-reader-scale' }, String(Math.round((rightScale ?? dualFit.right ?? 1) * 100)) + '%'),
8172
- h('button', {
8633
+ h(KitButton, {
8173
8634
  type: 'button', className: 'md-btn md-btn-small',
8174
8635
  onClick: () => setRightScale(value => Math.min(3, (value ?? dualFit.right ?? 1) + 0.1)),
8175
8636
  }, '+'),
8176
- h('button', {
8637
+ h(KitButton, {
8177
8638
  type: 'button', className: 'md-btn md-btn-small',
8178
8639
  onClick: () => setRightScale(null),
8179
8640
  }, format('readerFitScreen'))
@@ -8214,7 +8675,7 @@ window.__ModuleLoader__.load({
8214
8675
  h('div', { className: 'md-reader-state md-state-error', role: 'alert' },
8215
8676
  h('div', null, reader.error === '' ? format('readerFailed') : reader.error),
8216
8677
  h('div', { className: 'md-state-actions' },
8217
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: props.onRetry }, format('readerRetry'))
8678
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: props.onRetry }, format('readerRetry'))
8218
8679
  )
8219
8680
  ))
8220
8681
  : h(PdfViewer, {
@@ -8277,19 +8738,19 @@ window.__ModuleLoader__.load({
8277
8738
  railTool('ellipse', 'shapeEllipse', 'M12 5c5 0 8 3 8 7s-3 7-8 7-8-3-8-7 3-7 8-7z'),
8278
8739
  railTool('mask', 'overlayToggle', 'M4 4h16v16H4zM8 4v16M16 4v16'),
8279
8740
  h('span', { className: 'md-rail-sep', 'aria-hidden': true }),
8280
- h('button', {
8741
+ h(KitButton, {
8281
8742
  type: 'button', className: 'md-rail-btn',
8282
8743
  disabled: undoAvailable === 0,
8283
8744
  title: format('undoHint'), 'aria-label': format('undo'),
8284
8745
  onClick: undoEither,
8285
8746
  }, annotIcon('M9 14 4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3')),
8286
- h('button', {
8747
+ h(KitButton, {
8287
8748
  type: 'button', className: 'md-rail-btn',
8288
8749
  disabled: redoAvailable === 0,
8289
8750
  title: format('redoHint'), 'aria-label': format('redo'),
8290
8751
  onClick: redoEither,
8291
8752
  }, annotIcon('M15 14l5-5-5-5M20 9H9a5 5 0 0 0 0 10h3')),
8292
- h('button', {
8753
+ h(KitButton, {
8293
8754
  type: 'button', className: 'md-rail-btn',
8294
8755
  title: format('annotClearHint'), 'aria-label': format('annotClear'),
8295
8756
  onClick: clearAnnots,
@@ -8310,7 +8771,7 @@ window.__ModuleLoader__.load({
8310
8771
  : h(React.Fragment, null,
8311
8772
  h('div', { className: 'md-note-style-row' },
8312
8773
  h('span', { className: 'md-note-style-label' }, format('annotColor')),
8313
- ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h('button', {
8774
+ ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h(KitButton, {
8314
8775
  key: color,
8315
8776
  type: 'button',
8316
8777
  className: 'md-note-color',
@@ -8340,7 +8801,7 @@ window.__ModuleLoader__.load({
8340
8801
  : h('div', { className: 'md-selection-panel', 'data-side': railSide },
8341
8802
  h('div', { className: 'md-selection-head' },
8342
8803
  h('span', null, format('selectionTitle')),
8343
- h('button', {
8804
+ h(KitButton, {
8344
8805
  type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
8345
8806
  'aria-label': format('previewClose'), onClick: () => setSelection(null),
8346
8807
  }, '×')
@@ -8350,7 +8811,7 @@ window.__ModuleLoader__.load({
8350
8811
  h(NoteStyleControls, { style: selectedEntry, onChange: patchSelection }),
8351
8812
  h('div', { className: 'md-note-style-row' },
8352
8813
  h('span', { className: 'md-note-style-label' }, format('alignTitle')),
8353
- [['left', 'alignLeft'], ['center', 'alignCenter'], ['right', 'alignRight']].map(item => h('button', {
8814
+ [['left', 'alignLeft'], ['center', 'alignCenter'], ['right', 'alignRight']].map(item => h(KitButton, {
8354
8815
  key: item[0],
8355
8816
  type: 'button',
8356
8817
  className: 'md-note-style-btn',
@@ -8362,7 +8823,7 @@ window.__ModuleLoader__.load({
8362
8823
  : h(React.Fragment, null,
8363
8824
  h('div', { className: 'md-note-style-row' },
8364
8825
  h('span', { className: 'md-note-style-label' }, format('annotColor')),
8365
- ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h('button', {
8826
+ ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h(KitButton, {
8366
8827
  key: color,
8367
8828
  type: 'button',
8368
8829
  className: 'md-note-color',
@@ -8385,12 +8846,12 @@ window.__ModuleLoader__.load({
8385
8846
  ? h(React.Fragment, null,
8386
8847
  h('div', { className: 'md-note-style-row' },
8387
8848
  h('span', { className: 'md-note-style-label' }, format('fillTitle')),
8388
- h('button', {
8849
+ h(KitButton, {
8389
8850
  type: 'button', className: 'md-note-style-btn',
8390
8851
  'data-on': selectedEntry.fill === undefined || selectedEntry.fill === '' ? 'true' : undefined,
8391
8852
  onClick: () => patchSelection({ fill: '' }),
8392
8853
  }, format('fillNone')),
8393
- ['#f2c94c', '#f28b82', '#aecbfa', '#b7e1cd'].map(color => h('button', {
8854
+ ['#f2c94c', '#f28b82', '#aecbfa', '#b7e1cd'].map(color => h(KitButton, {
8394
8855
  key: color,
8395
8856
  type: 'button',
8396
8857
  className: 'md-note-color',
@@ -8402,12 +8863,12 @@ window.__ModuleLoader__.load({
8402
8863
  ),
8403
8864
  h('div', { className: 'md-note-style-row' },
8404
8865
  h('span', { className: 'md-note-style-label' }, format('fillStyleTitle')),
8405
- h('button', {
8866
+ h(KitButton, {
8406
8867
  type: 'button', className: 'md-note-style-btn',
8407
8868
  'data-on': selectedEntry.fillStyle !== 'solid' ? 'true' : undefined,
8408
8869
  onClick: () => patchSelection({ fillStyle: 'hachure' }),
8409
8870
  }, format('fillHachure')),
8410
- h('button', {
8871
+ h(KitButton, {
8411
8872
  type: 'button', className: 'md-note-style-btn',
8412
8873
  'data-on': selectedEntry.fillStyle === 'solid' ? 'true' : undefined,
8413
8874
  onClick: () => patchSelection({ fillStyle: 'solid' }),
@@ -8415,17 +8876,17 @@ window.__ModuleLoader__.load({
8415
8876
  ),
8416
8877
  h('div', { className: 'md-note-style-row' },
8417
8878
  h('span', { className: 'md-note-style-label' }, format('strokeStyleTitle')),
8418
- h('button', {
8879
+ h(KitButton, {
8419
8880
  type: 'button', className: 'md-note-style-btn',
8420
8881
  'data-on': (selectedEntry.strokeStyle ?? 'solid') === 'solid' ? 'true' : undefined,
8421
8882
  onClick: () => patchSelection({ strokeStyle: 'solid' }),
8422
8883
  }, format('styleSolid')),
8423
- h('button', {
8884
+ h(KitButton, {
8424
8885
  type: 'button', className: 'md-note-style-btn',
8425
8886
  'data-on': selectedEntry.strokeStyle === 'dashed' ? 'true' : undefined,
8426
8887
  onClick: () => patchSelection({ strokeStyle: 'dashed' }),
8427
8888
  }, format('styleDashed')),
8428
- h('button', {
8889
+ h(KitButton, {
8429
8890
  type: 'button', className: 'md-note-style-btn',
8430
8891
  'data-on': selectedEntry.strokeStyle === 'dotted' ? 'true' : undefined,
8431
8892
  onClick: () => patchSelection({ strokeStyle: 'dotted' }),
@@ -8445,11 +8906,11 @@ window.__ModuleLoader__.load({
8445
8906
  h('span', { className: 'md-note-size-value' }, `${Math.round((selectedEntry.opacity ?? 1) * 100)}%`)
8446
8907
  ),
8447
8908
  h('div', { className: 'md-selection-actions' },
8448
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: duplicateSelection }, format('duplicateSelection')),
8449
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: () => reorderSelection(true) }, format('bringFront')),
8450
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: () => reorderSelection(false) }, format('sendBack'))
8909
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: duplicateSelection }, format('duplicateSelection')),
8910
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => reorderSelection(true) }, format('bringFront')),
8911
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => reorderSelection(false) }, format('sendBack'))
8451
8912
  ),
8452
- h('button', {
8913
+ h(KitButton, {
8453
8914
  type: 'button', className: 'md-btn md-btn-small md-selection-delete',
8454
8915
  onClick: deleteSelection,
8455
8916
  }, format('selectionDelete'))
@@ -8495,7 +8956,7 @@ window.__ModuleLoader__.load({
8495
8956
  files === 0 ? '' : format(filesMore ? 'filesCountPlus' : 'filesCount', { n: files }),
8496
8957
  ].filter(Boolean).join(' · ')
8497
8958
  return h('li', { className: 'md-chapter', 'data-open': open ? 'true' : undefined },
8498
- h('button', {
8959
+ h(KitButton, {
8499
8960
  type: 'button',
8500
8961
  className: 'md-row',
8501
8962
  'aria-expanded': open ? 'true' : 'false',
@@ -8515,13 +8976,13 @@ window.__ModuleLoader__.load({
8515
8976
  h('span', { className: 'md-detail-key' }, format('pdfLabel')),
8516
8977
  h('span', { className: 'md-detail-value' }, `${chapter.file}.pdf`),
8517
8978
  typeof chapter.pdfPath === 'string' && chapter.pdfPath !== ''
8518
- ? h('button', {
8979
+ ? h(KitButton, {
8519
8980
  type: 'button', className: 'md-btn md-btn-small',
8520
8981
  title: chapter.pdfPath,
8521
8982
  onClick: () => props.onCopyPath(chapter.pdfPath),
8522
8983
  }, format('copyPath'))
8523
8984
  : null,
8524
- h('button', {
8985
+ h(KitButton, {
8525
8986
  type: 'button', className: 'md-btn md-btn-small md-detail-open',
8526
8987
  onClick: () => props.onOpenPdf(chapter),
8527
8988
  }, format('openPdf'))
@@ -8529,11 +8990,11 @@ window.__ModuleLoader__.load({
8529
8990
  translatedPdf === '' ? null : h('div', { className: 'md-detail-line' },
8530
8991
  h('span', { className: 'md-detail-key' }, format('translatedLabel')),
8531
8992
  h('span', { className: 'md-detail-value' }, translatedPdf),
8532
- h('button', {
8993
+ h(KitButton, {
8533
8994
  type: 'button', className: 'md-btn md-btn-small md-detail-open',
8534
8995
  onClick: () => props.onOpenPdf(chapter, 'translated'),
8535
8996
  }, format('openPdf')),
8536
- h('button', {
8997
+ h(KitButton, {
8537
8998
  type: 'button', className: 'md-btn md-btn-small',
8538
8999
  onClick: async () => {
8539
9000
  if (typeof window !== 'undefined' && typeof window.confirm === 'function'
@@ -8694,7 +9155,7 @@ window.__ModuleLoader__.load({
8694
9155
  }),
8695
9156
  visible < chapters.length
8696
9157
  ? h('li', { key: '__more', className: 'md-chapters-more', ref: sentinel },
8697
- h('button', {
9158
+ h(KitButton, {
8698
9159
  type: 'button',
8699
9160
  className: 'md-btn md-btn-small',
8700
9161
  onClick: () => setVisible(count => Math.min(chapters.length, count + WINDOW)),
@@ -8772,6 +9233,9 @@ window.__ModuleLoader__.load({
8772
9233
  .md-env-title { margin: 0; font-size: 15px; }
8773
9234
  .md-env-body { margin: 0; font-size: 13px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
8774
9235
  .md-env-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
9236
+ .md-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
9237
+ .md-modal-body { display: flex; flex-direction: column; gap: 12px; }
9238
+ .md-modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
8775
9239
  .md-workspace-dialog { width: min(520px, 100%); }
8776
9240
  .md-workspace-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; }
8777
9241
  .md-workspace-label { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); }
@@ -8788,10 +9252,23 @@ window.__ModuleLoader__.load({
8788
9252
  .md-settings-heading { margin: 0; font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-primary); }
8789
9253
  .md-settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12.5px; }
8790
9254
  .md-settings-input { flex: 1 1 auto; min-width: 0; font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--dsw-alias-border-l3); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); }
9255
+ .md-kit-input { flex: 1 1 auto; min-width: 0; }
9256
+ .md-kit-input input { font: inherit; }
9257
+ .md-kit-select { position: relative; display: inline-flex; flex-direction: column; }
9258
+ .md-kit-select-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 140px; padding: 4px; display: flex; flex-direction: column; gap: 2px; background: var(--dsw-alias-bg-layer-1); border: .5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-md); box-shadow: var(--dsw-elevation-prominent); }
9259
+ .md-kit-select-option { display: flex; align-items: center; min-height: 30px; padding: 0 8px; border: 0; border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-primary); text-align: left; cursor: pointer; }
9260
+ .md-kit-select-option:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
9261
+ .md-kit-select-option:disabled { opacity: .4; cursor: not-allowed; }
8791
9262
  .md-settings-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
8792
9263
  .md-tab-btn[data-on='true'] { background: var(--dsw-alias-interactive-bg-hover); border-color: var(--dsw-alias-brand-primary); font-weight: 600; }
8793
9264
  .md-settings-note { margin: 0; font-size: 12px; color: var(--dsw-alias-brand-primary); }
8794
9265
  .md-settings-actions { display: flex; gap: 8px; padding-top: 4px; }
9266
+ .md-update-box { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: .5px solid var(--dsw-alias-border-l2); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-1); }
9267
+ .md-update-box .md-btn { align-self: flex-start; }
9268
+ .md-settings-modal { width: min(720px, 92vw); max-height: 86vh; }
9269
+ .md-settings-modal .md-modal-body { max-height: calc(86vh - 110px); overflow-y: auto; }
9270
+ .md-settings-content { max-height: calc(86vh - 110px); overflow-y: auto; }
9271
+ .md-settings-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 4px; }
8795
9272
  .md-shortcut-list { display: flex; flex-direction: column; gap: 4px; }
8796
9273
  .md-shortcut-row { gap: 8px; }
8797
9274
  .md-shortcut-name { flex: 1 1 auto; min-width: 0; }
@@ -9132,7 +9609,8 @@ window.__ModuleLoader__.load({
9132
9609
  .md-annot[data-tool="pen"], .md-annot[data-tool="erase"], .md-annot[data-tool="text"] { pointer-events: auto; }
9133
9610
  .md-annot[data-tool="line"], .md-annot[data-tool="arrow"], .md-annot[data-tool="rect"], .md-annot[data-tool="diamond"], .md-annot[data-tool="ellipse"] { pointer-events: auto; cursor: crosshair; }
9134
9611
  .md-annot[data-tool="select"] { pointer-events: auto; cursor: default; }
9135
- .md-annot-text.md-annot-selected { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 3px; border-radius: 3px; }
9612
+ .md-annot-text.md-annot-selected { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; border-radius: 0; }
9613
+ .md-annot-text.md-annot-selected { cursor: move; }
9136
9614
  /* The vertical tool rail: collected PDF tools, revealed only while the pointer
9137
9615
  is on the page edge, with a short fade/slide so it does not pop. */
9138
9616
  .md-rail-wrap { position: absolute; top: 0; bottom: 0; z-index: 40; width: 30px; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
@@ -9168,18 +9646,18 @@ window.__ModuleLoader__.load({
9168
9646
  .md-shape-handles { position: absolute; inset: 0; pointer-events: none; }
9169
9647
  .md-shape-handle { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: var(--dsw-alias-bg-base); border: 1.5px solid var(--dsw-alias-brand-primary); border-radius: 2px; pointer-events: auto; cursor: nwse-resize; }
9170
9648
  .md-annot[data-tool="pen"] { cursor: crosshair; }
9171
- .md-annot[data-tool="text"] { cursor: text; }
9649
+ .md-annot[data-tool="text"] { cursor: crosshair; }
9172
9650
  .md-annot[data-tool="erase"] { cursor: cell; }
9173
9651
  .md-annot-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
9174
9652
  /* A text note is transparent: it sits straight on the page, and a faint outline
9175
9653
  appears only on hover, when it can be double-clicked for editing. */
9176
- .md-annot-text { position: absolute; max-width: 70%; font-size: 14px; font-weight: 600; line-height: 1.35; white-space: pre-wrap; pointer-events: none; padding: 0 2px; border-radius: 4px; }
9654
+ .md-annot-text { position: absolute; box-sizing: border-box; font-size: 14px; font-weight: 600; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; overflow: hidden; pointer-events: none; padding: 2px 4px; border: 1px solid transparent; border-radius: 0; }
9177
9655
  /* With no tool picked, a note is clickable so a double-click can edit it. */
9178
9656
  .md-annot[data-tool=""] .md-annot-text { pointer-events: auto; cursor: text; }
9179
- .md-annot[data-tool=""] .md-annot-text:hover { box-shadow: 0 0 0 1px color-mix(in srgb, var(--dsw-alias-brand-primary) 55%, transparent); }
9657
+ .md-annot[data-tool=""] .md-annot-text:hover { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 55%, transparent); }
9180
9658
  /* The in-place editor is transparent too: only the text and the caret show.
9181
9659
  The style row never takes focus, so changing a font cannot blur-save. */
9182
- .md-note-editor { position: absolute; z-index: 8; display: flex; flex-direction: column; gap: 2px; width: 280px; min-width: 160px; padding: 2px; border: 1px dashed color-mix(in srgb, var(--dsw-alias-brand-primary) 42%, transparent); border-radius: 6px; pointer-events: auto; }
9660
+ .md-note-editor { position: absolute; z-index: 8; box-sizing: border-box; display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: 0; padding: 1px; border: 1px dashed color-mix(in srgb, var(--dsw-alias-brand-primary) 42%, transparent); border-radius: 0; pointer-events: auto; }
9183
9661
  .md-note-style { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 0; background: transparent; box-shadow: none; }
9184
9662
  /* Text parameters now live in the toolbar: a nested menu, not a box on the page. */
9185
9663
  .md-note-style-wrap { position: relative; display: inline-flex; align-items: center; }
@@ -9194,7 +9672,7 @@ window.__ModuleLoader__.load({
9194
9672
  .md-note-style-sep { width: 1px; height: 14px; margin: 0 2px; background: color-mix(in srgb, var(--dsw-alias-border-l3) 70%, transparent); }
9195
9673
  .md-note-color { width: 14px; height: 14px; padding: 0; border: 1px solid var(--dsw-alias-border-l3); border-radius: 50%; cursor: pointer; }
9196
9674
  .md-note-color[data-on="true"] { box-shadow: 0 0 0 2px var(--dsw-alias-bg-base), 0 0 0 3px var(--dsw-alias-brand-primary); }
9197
- .md-note-input { box-sizing: border-box; width: 100%; min-height: 28px; max-height: 240px; overflow: auto; line-height: 1.35; padding: 2px; border-radius: 4px; border: none; background: transparent; box-shadow: none; outline: none; caret-color: currentColor; }
9675
+ .md-note-input { box-sizing: border-box; width: 100%; height: 100%; min-height: 0; max-height: none; overflow: auto; line-height: 1.35; padding: 2px; border-radius: 0; border: none; background: transparent; box-shadow: none; outline: none; caret-color: currentColor; resize: none; }
9198
9676
  .md-note-input::placeholder { color: var(--dsw-alias-label-secondary); opacity: 0.85; }
9199
9677
  .md-note-hint { align-self: flex-start; font-size: 11px; line-height: 1.4; padding: 0 2px; color: var(--dsw-alias-label-secondary); text-shadow: 0 1px 2px color-mix(in srgb, var(--dsw-alias-bg-base) 90%, transparent); }
9200
9678
  .md-icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 3px 6px; }
@@ -9508,7 +9986,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
9508
9986
  if (sidePanelTimer.current !== null) clearTimeout(sidePanelTimer.current)
9509
9987
  if (sideCloseTimer.current !== null) clearTimeout(sideCloseTimer.current)
9510
9988
  }, [])
9511
- const sideRailTool = (id, labelKey, path) => h('button', {
9989
+ const sideRailTool = (id, labelKey, path) => h(KitButton, {
9512
9990
  type: 'button',
9513
9991
  className: 'md-rail-btn',
9514
9992
  'aria-pressed': tool === id ? 'true' : 'false',
@@ -10557,7 +11035,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10557
11035
  ? h('div', { className: 'md-reader-state md-state-error', role: 'alert' },
10558
11036
  h('div', null, error === '' ? format('readerFailed') : error),
10559
11037
  h('div', { className: 'md-state-actions' },
10560
- h('button', {
11038
+ h(KitButton, {
10561
11039
  type: 'button',
10562
11040
  className: 'md-btn md-btn-small',
10563
11041
  onClick: () => setDocRev(value => value + 1),
@@ -10601,7 +11079,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10601
11079
  toolsHidden
10602
11080
  // The way back to the toolbar: a handle that appears when the pointer
10603
11081
  // is over the preview, without taking any layout space.
10604
- ? h('button', {
11082
+ ? h(KitButton, {
10605
11083
  type: 'button',
10606
11084
  className: 'md-btn md-btn-small md-side-handle',
10607
11085
  title: format('sideShowToolbar'),
@@ -10612,7 +11090,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10612
11090
  }, '⋯')
10613
11091
  : null,
10614
11092
  toolsHidden ? null : h('div', { className: 'md-side-bar' },
10615
- h('button', {
11093
+ h(KitButton, {
10616
11094
  type: 'button',
10617
11095
  className: 'md-btn md-btn-small',
10618
11096
  title: format('readerPrev'),
@@ -10621,7 +11099,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10621
11099
  onClick: () => goPage(page - 1),
10622
11100
  }, '‹'),
10623
11101
  gotoOpen
10624
- ? h('input', {
11102
+ ? h(KitInput, {
10625
11103
  key: 'goto',
10626
11104
  ref: gotoInput,
10627
11105
  className: 'md-side-goto',
@@ -10645,7 +11123,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10645
11123
  },
10646
11124
  onBlur: () => setGotoOpen(false),
10647
11125
  })
10648
- : h('button', {
11126
+ : h(KitButton, {
10649
11127
  type: 'button',
10650
11128
  className: 'md-btn md-btn-small md-side-count',
10651
11129
  title: format('sideGotoHint'),
@@ -10653,7 +11131,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10653
11131
  disabled: count === 0 || phase !== 'ready',
10654
11132
  onClick: () => setGotoOpen(true),
10655
11133
  }, count === 0 ? String(page) : `${page} / ${count}`),
10656
- h('button', {
11134
+ h(KitButton, {
10657
11135
  type: 'button',
10658
11136
  className: 'md-btn md-btn-small',
10659
11137
  title: format('readerNext'),
@@ -10661,7 +11139,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10661
11139
  disabled: count === 0 || page >= count || phase !== 'ready',
10662
11140
  onClick: () => goPage(page + 1),
10663
11141
  }, '›'),
10664
- h('button', {
11142
+ h(KitButton, {
10665
11143
  type: 'button',
10666
11144
  className: 'md-btn md-btn-small',
10667
11145
  title: format('readerMode'),
@@ -10669,7 +11147,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10669
11147
  'aria-pressed': mode === 'continuous' ? 'true' : 'false',
10670
11148
  onClick: () => setMode(mode === 'single' ? 'continuous' : 'single'),
10671
11149
  }, mode === 'single' ? format('readerModeSingle') : format('readerModeContinuous')),
10672
- h('button', {
11150
+ h(KitButton, {
10673
11151
  type: 'button',
10674
11152
  className: 'md-btn md-btn-small',
10675
11153
  title: format('readerZoomOut'),
@@ -10677,7 +11155,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10677
11155
  disabled: phase !== 'ready',
10678
11156
  onClick: () => zoomTo(renderScale / 1.2),
10679
11157
  }, '−'),
10680
- h('button', {
11158
+ h(KitButton, {
10681
11159
  type: 'button',
10682
11160
  className: 'md-btn md-btn-small',
10683
11161
  title: format('readerFit'),
@@ -10685,7 +11163,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10685
11163
  disabled: phase !== 'ready',
10686
11164
  onClick: () => fitToColumn(),
10687
11165
  }, '⤢'),
10688
- h('button', {
11166
+ h(KitButton, {
10689
11167
  type: 'button',
10690
11168
  className: 'md-btn md-btn-small',
10691
11169
  title: format('readerZoomIn'),
@@ -10694,7 +11172,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10694
11172
  onClick: () => zoomTo(renderScale * 1.2),
10695
11173
  }, '+'),
10696
11174
  h('span', { className: 'md-side-gap' }),
10697
- h('button', {
11175
+ h(KitButton, {
10698
11176
  type: 'button',
10699
11177
  className: 'md-btn md-btn-small md-icon-btn',
10700
11178
  'aria-pressed': tool === 'pen' ? 'true' : 'false',
@@ -10702,7 +11180,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10702
11180
  'aria-label': format('annotPen'),
10703
11181
  onClick: () => toggleTool('pen'),
10704
11182
  }, annotIcon('M12 20h9M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z')),
10705
- h('button', {
11183
+ h(KitButton, {
10706
11184
  type: 'button',
10707
11185
  className: 'md-btn md-btn-small md-icon-btn',
10708
11186
  'aria-pressed': tool === 'erase' ? 'true' : 'false',
@@ -10710,7 +11188,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10710
11188
  'aria-label': format('annotErase'),
10711
11189
  onClick: () => toggleTool('erase'),
10712
11190
  }, annotIcon('m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21M22 21H7M5 11l9 9')),
10713
- h('button', {
11191
+ h(KitButton, {
10714
11192
  type: 'button',
10715
11193
  className: 'md-btn md-btn-small md-icon-btn',
10716
11194
  'aria-pressed': tool === 'text' ? 'true' : 'false',
@@ -10719,7 +11197,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10719
11197
  onClick: () => toggleTool('text'),
10720
11198
  }, annotIcon('M4 6h16M12 6v13M9 19h6')),
10721
11199
  h(NoteStyleMenu, { style: noteEdit ?? noteStyle, onChange: changeNoteStyle }),
10722
- h('button', {
11200
+ h(KitButton, {
10723
11201
  type: 'button',
10724
11202
  className: 'md-btn md-btn-small md-icon-btn',
10725
11203
  'aria-pressed': tool === 'mask' ? 'true' : 'false',
@@ -10728,7 +11206,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10728
11206
  onClick: () => toggleTool('mask'),
10729
11207
  }, annotIcon('M4 4h16v16H4zM8 4v16M16 4v16')),
10730
11208
  h('span', { className: 'md-side-gap' }),
10731
- h('button', {
11209
+ h(KitButton, {
10732
11210
  type: 'button',
10733
11211
  className: 'md-btn md-btn-small md-icon-btn',
10734
11212
  disabled: historyCounts.undo === 0,
@@ -10736,7 +11214,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10736
11214
  'aria-label': format('undo'),
10737
11215
  onClick: () => undoPage(),
10738
11216
  }, annotIcon('M9 14 4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3')),
10739
- h('button', {
11217
+ h(KitButton, {
10740
11218
  type: 'button',
10741
11219
  className: 'md-btn md-btn-small md-icon-btn',
10742
11220
  disabled: historyCounts.redo === 0,
@@ -10747,7 +11225,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10747
11225
  h('span', { className: 'md-side-gap' }),
10748
11226
  h('span', { className: 'md-side-zoom', title: format(autoFit ? 'sideAutoFitOn' : 'sideMenuZoom') },
10749
11227
  `${Math.round(shown * 100)}%`),
10750
- h('button', {
11228
+ h(KitButton, {
10751
11229
  type: 'button',
10752
11230
  className: 'md-btn md-btn-small md-side-more',
10753
11231
  title: format('sideMenuHint'),
@@ -10774,13 +11252,13 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10774
11252
  sideRailTool('ellipse', 'shapeEllipse', 'M12 5c5 0 8 3 8 7s-3 7-8 7-8-3-8-7 3-7 8-7z'),
10775
11253
  sideRailTool('mask', 'overlayToggle', 'M4 4h16v16H4zM8 4v16M16 4v16'),
10776
11254
  h('span', { className: 'md-rail-sep', 'aria-hidden': true }),
10777
- h('button', {
11255
+ h(KitButton, {
10778
11256
  type: 'button', className: 'md-rail-btn',
10779
11257
  disabled: historyCounts.undo === 0,
10780
11258
  title: format('undoHint'), 'aria-label': format('undo'),
10781
11259
  onClick: () => undoPage(),
10782
11260
  }, annotIcon('M9 14 4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3')),
10783
- h('button', {
11261
+ h(KitButton, {
10784
11262
  type: 'button', className: 'md-rail-btn',
10785
11263
  disabled: historyCounts.redo === 0,
10786
11264
  title: format('redoHint'), 'aria-label': format('redo'),
@@ -10804,7 +11282,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
10804
11282
  : h(React.Fragment, null,
10805
11283
  h('div', { className: 'md-note-style-row' },
10806
11284
  h('span', { className: 'md-note-style-label' }, format('annotColor')),
10807
- ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h('button', {
11285
+ ['#1f1f1f', '#e0554a', '#2f6df6', '#2ecc71'].map(color => h(KitButton, {
10808
11286
  key: color,
10809
11287
  type: 'button',
10810
11288
  className: 'md-note-color',
@@ -11035,6 +11513,9 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
11035
11513
  const [libBusy, setLibBusy] = useState(false)
11036
11514
  const [libError, setLibError] = useState('')
11037
11515
  const [updateBusy, setUpdateBusy] = useState(false)
11516
+ const [updateInfo, setUpdateInfo] = useState(null)
11517
+ const [marketUpdate, setMarketUpdate] = useState(null)
11518
+ const [updateOperation, setUpdateOperation] = useState(null)
11038
11519
  const [previewPdf, setPreviewPdf] = useState(() => {
11039
11520
  try {
11040
11521
  return window.localStorage.getItem('pdfdesk:preview-pdf') !== '0'
@@ -11073,7 +11554,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
11073
11554
  useEffect(() => {
11074
11555
  if (!settingsOpen) return undefined
11075
11556
  const onDown = event => {
11076
- if (event.target instanceof Element && event.target.closest('.md-settings, .md-settings-page, .md-picker') !== null) return
11557
+ if (event.target instanceof Element && event.target.closest('.md-settings, .md-settings-modal, .md-settings-content, .md-settings-page, .md-picker') !== null) return
11077
11558
  setSettingsOpen(false)
11078
11559
  }
11079
11560
  const onKey = event => {
@@ -12441,6 +12922,10 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
12441
12922
  if (archivedIds.has(id)) continue
12442
12923
  const summary = list.byId[id]
12443
12924
  if (summary === undefined || summary.blank !== true || summary.origin === 'subagent') continue
12925
+ // A workbench-created pending blank already carries one preset prompt
12926
+ // (or is about to). Reusing it for another mode would append the next
12927
+ // preset to that draft; leave it for cleanup instead.
12928
+ if (id in (pendingRef.current ?? {}) || freshPending.current.has(id)) continue
12444
12929
  if (pendingDrafts.current.has(id)) continue
12445
12930
  if (typeof summary.title === 'string' && summary.title !== '') continue
12446
12931
  if (typeof summary.cwd === 'string' && summary.cwd !== '' && target.cwd !== '' && !sameDirectory(summary.cwd, target.cwd)) continue
@@ -13061,6 +13546,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13061
13546
  const checkUpdates = useCallback(async () => {
13062
13547
  if (updateBusy) return
13063
13548
  setUpdateBusy(true)
13549
+ setUpdateOperation(null)
13064
13550
  try {
13065
13551
  // The Host performs the request: it can follow a local proxy, while the
13066
13552
  // Electron renderer cannot.
@@ -13072,12 +13558,24 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13072
13558
  }
13073
13559
  const latest = typeof payload.latest === 'string' ? payload.latest : ''
13074
13560
  if (latest === '') {
13561
+ setUpdateInfo(null)
13075
13562
  showNotice(format('updateNoRelease'))
13076
13563
  return
13077
13564
  }
13078
- showNotice(compareVersions(latest, current) > 0
13079
- ? format('updateNew', { version: latest.replace(/^v/i, ''), current })
13080
- : format('updateLatest', { version: current }))
13565
+ const version = typeof payload.version === 'string' && payload.version !== ''
13566
+ ? payload.version
13567
+ : latest.replace(/^v/i, '')
13568
+ const download = typeof payload.download === 'string' ? payload.download : ''
13569
+ const comparison = compareVersions(latest, current)
13570
+ if (comparison <= 0) {
13571
+ setUpdateInfo(null)
13572
+ setMarketUpdate(null)
13573
+ showNotice(format('updateLatest', { version: current }))
13574
+ return
13575
+ }
13576
+ setUpdateInfo({ latest, version, current, download, url: typeof payload.url === 'string' ? payload.url : '' })
13577
+ setMarketUpdate(await discoverMarketUpdate(current))
13578
+ showNotice(format('updateNew', { version, current }))
13081
13579
  } catch {
13082
13580
  showNotice(format('updateFailed'))
13083
13581
  } finally {
@@ -13085,6 +13583,101 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13085
13583
  }
13086
13584
  }, [catalog, showNotice, updateBusy])
13087
13585
 
13586
+ /**
13587
+ * Discover whether dshmarket can update this installed package.
13588
+ * @param {string} current - installed version.
13589
+ * @returns {Promise<object | null>} market update info, or null.
13590
+ */
13591
+ const discoverMarketUpdate = useCallback(async current => {
13592
+ try {
13593
+ const capabilityResponse = await window.fetch('/dsh-market/api/v1/capabilities', { credentials: 'same-origin' })
13594
+ if (!capabilityResponse.ok) return null
13595
+ const capabilities = await capabilityResponse.json()
13596
+ if (capabilities === null || typeof capabilities !== 'object'
13597
+ || capabilities.features === undefined || capabilities.features.update !== true
13598
+ || capabilities.endpoints === undefined || typeof capabilities.endpoints.updates !== 'string') return null
13599
+ const url = new URL(capabilities.endpoints.updates, window.location.origin)
13600
+ url.searchParams.set('name', 'dsh-pdf-workbench')
13601
+ url.searchParams.set('force', '1')
13602
+ const response = await window.fetch(url, { credentials: 'same-origin' })
13603
+ if (!response.ok) return null
13604
+ const payload = await response.json()
13605
+ const item = payload !== null && typeof payload === 'object' ? payload.package : null
13606
+ if (item === null || typeof item !== 'object' || item.updateAvailable !== true) return null
13607
+ if (compareVersions(String(item.latestVersion ?? ''), current) <= 0) return null
13608
+ return { item, endpoints: capabilities.endpoints, restart: capabilities.restart }
13609
+ } catch {
13610
+ return null
13611
+ }
13612
+ }, [])
13613
+
13614
+ /** Start the one-click update: market operation when managed, otherwise download. */
13615
+ const installUpdate = useCallback(async () => {
13616
+ if (updateInfo === null || updateBusy) return
13617
+ if (marketUpdate !== null && typeof marketUpdate.endpoints?.updates === 'string') {
13618
+ setUpdateBusy(true)
13619
+ setUpdateOperation({ state: 'starting', message: format('updateMarketStarting') })
13620
+ try {
13621
+ const response = await window.fetch(marketUpdate.endpoints.updates, {
13622
+ method: 'POST',
13623
+ credentials: 'same-origin',
13624
+ headers: { 'Content-Type': 'application/json' },
13625
+ body: JSON.stringify({ packageName: 'dsh-pdf-workbench' }),
13626
+ })
13627
+ if (!response.ok) {
13628
+ setUpdateOperation({ state: 'failed', message: format('updateMarketFailed', { message: `HTTP ${response.status}` }) })
13629
+ return
13630
+ }
13631
+ const started = await response.json()
13632
+ const operationId = typeof started.operationId === 'string' ? started.operationId : ''
13633
+ if (operationId === '') {
13634
+ setUpdateOperation({ state: 'failed', message: format('updateMarketFailed', { message: 'no operationId' }) })
13635
+ return
13636
+ }
13637
+ const terminal = new Set(['succeeded', 'failed', 'cancelled', 'rolled-back'])
13638
+ for (let attempt = 0; attempt < 180; attempt += 1) {
13639
+ await new Promise(resolve => window.setTimeout(resolve, 1000))
13640
+ const pollUrl = new URL(marketUpdate.endpoints.operations, window.location.origin)
13641
+ pollUrl.searchParams.set('operationId', operationId)
13642
+ const pollResponse = await window.fetch(pollUrl, { credentials: 'same-origin' })
13643
+ if (!pollResponse.ok) continue
13644
+ const pollPayload = await pollResponse.json()
13645
+ const operation = pollPayload !== null && typeof pollPayload === 'object' && pollPayload.operation !== undefined
13646
+ ? pollPayload.operation
13647
+ : pollPayload
13648
+ const state = operation !== null && typeof operation === 'object' && typeof operation.state === 'string' ? operation.state : ''
13649
+ setUpdateOperation({ state, message: format('updateMarketProgress', { state: state === '' ? '…' : state }) })
13650
+ if (!terminal.has(state)) continue
13651
+ if (state === 'succeeded') {
13652
+ const version = typeof operation.installedVersion === 'string' && operation.installedVersion !== ''
13653
+ ? operation.installedVersion
13654
+ : updateInfo.version
13655
+ setUpdateInfo(null)
13656
+ setMarketUpdate(null)
13657
+ setUpdateOperation({ state, message: format('updateMarketDone', { version }) })
13658
+ } else {
13659
+ const message = typeof operation.message === 'string' && operation.message !== '' ? operation.message : state
13660
+ setUpdateOperation({ state, message: format('updateMarketFailed', { message }) })
13661
+ }
13662
+ return
13663
+ }
13664
+ setUpdateOperation({ state: 'failed', message: format('updateMarketFailed', { message: 'timeout' }) })
13665
+ } catch (error) {
13666
+ setUpdateOperation({ state: 'failed', message: format('updateMarketFailed', { message: errorText(error) }) })
13667
+ } finally {
13668
+ setUpdateBusy(false)
13669
+ }
13670
+ return
13671
+ }
13672
+ if (updateInfo.download !== '') {
13673
+ try {
13674
+ window.open(updateInfo.download, '_blank', 'noopener')
13675
+ } catch {
13676
+ // popup blocked
13677
+ }
13678
+ }
13679
+ }, [format, marketUpdate, updateBusy, updateInfo])
13680
+
13088
13681
  /** Persist hidden books / shelves for the active library. */
13089
13682
  const saveShelfGroups = useCallback(next => {
13090
13683
  setShelfGroups(next)
@@ -13543,7 +14136,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13543
14136
  h('div', { className: 'md-empty-title' }, format('loadFailed')),
13544
14137
  h('p', { className: 'md-state-detail' }, blockingError),
13545
14138
  h('div', { className: 'md-state-actions' },
13546
- h('button', { type: 'button', className: 'md-btn', onClick: reload }, format('retry'))
14139
+ h(KitButton, { type: 'button', className: 'md-btn', onClick: reload }, format('retry'))
13547
14140
  )
13548
14141
  )
13549
14142
  } else if (catalog === null || work === null) {
@@ -13576,7 +14169,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13576
14169
  h('div', { className: 'md-empty-title' }, format('loadFailed')),
13577
14170
  h('p', { className: 'md-state-detail' }, blockingError),
13578
14171
  h('div', { className: 'md-state-actions' },
13579
- h('button', { type: 'button', className: 'md-btn', onClick: reload }, format('retry'))
14172
+ h(KitButton, { type: 'button', className: 'md-btn', onClick: reload }, format('retry'))
13580
14173
  )
13581
14174
  )
13582
14175
  } else if (book !== null) {
@@ -13738,40 +14331,29 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13738
14331
  }, format(mathMode ? 'workflowMath' : 'workflowGeneral'))
13739
14332
  ),
13740
14333
  h('div', { className: 'md-head-actions' },
13741
- book === null ? null : h('button', {
14334
+ book === null ? null : h(KitButton, {
13742
14335
  type: 'button', className: 'md-btn md-btn-ghost', onClick: backToShelf,
13743
14336
  }, `‹ ${format('back')}`),
13744
- h('button', {
13745
- type: 'button', className: 'md-btn md-btn-ghost',
13746
- title: GITHUB_URL,
13747
- onClick: () => {
13748
- try {
13749
- window.open(GITHUB_URL, '_blank', 'noopener')
13750
- } catch {
13751
- // popup blocked: ignore
13752
- }
13753
- },
13754
- }, 'GitHub'),
13755
14337
  h('div', { className: 'md-settings' },
13756
- h('button', {
14338
+ h(KitButton, {
13757
14339
  type: 'button', className: 'md-btn md-btn-ghost',
13758
14340
  'aria-haspopup': 'dialog', 'aria-expanded': settingsOpen ? 'true' : 'false',
13759
14341
  onClick: () => setSettingsOpen(value => !value),
13760
14342
  }, `⚙ ${format('settings')}`)
13761
14343
  ),
13762
- h('button', {
14344
+ h(KitButton, {
13763
14345
  type: 'button', className: 'md-btn', disabled: busy || creatingKey !== '',
13764
14346
  title: format('cleanupHint'),
13765
14347
  onClick: cleanupNow,
13766
14348
  }, format('cleanup')),
13767
- h('button', {
14349
+ h(KitButton, {
13768
14350
  type: 'button', className: 'md-btn', disabled: busy,
13769
14351
  onClick: reload,
13770
14352
  }, busy ? format('refreshing') : format('refresh'))
13771
14353
  )
13772
14354
  ),
13773
14355
  h('nav', { className: 'md-crumbs', 'aria-label': format('crumbsLabel'), inert: covered ? '' : undefined },
13774
- h('button', {
14356
+ h(KitButton, {
13775
14357
  type: 'button',
13776
14358
  className: librariesView ? 'md-crumb-current' : 'md-crumb',
13777
14359
  disabled: librariesView,
@@ -13782,7 +14364,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13782
14364
  ? null
13783
14365
  : book === null && groupName === null
13784
14366
  ? h('span', { className: 'md-crumb-current', 'aria-current': 'page' }, libraryName)
13785
- : h('button', {
14367
+ : h(KitButton, {
13786
14368
  type: 'button', className: 'md-crumb',
13787
14369
  onClick: goShelf,
13788
14370
  }, libraryName),
@@ -13791,7 +14373,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13791
14373
  ? null
13792
14374
  : book === null
13793
14375
  ? h('span', { className: 'md-crumb-current', 'aria-current': 'page' }, groupName)
13794
- : h('button', {
14376
+ : h(KitButton, {
13795
14377
  type: 'button', className: 'md-crumb',
13796
14378
  onClick: () => openGroup(group),
13797
14379
  }, groupName),
@@ -13800,7 +14382,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13800
14382
  ),
13801
14383
  inlineError === '' ? null : h('div', { className: 'md-alert', role: 'alert', inert: covered ? '' : undefined },
13802
14384
  h('span', { className: 'md-alert-text' }, inlineError),
13803
- h('button', { type: 'button', className: 'md-btn md-btn-small', onClick: reload }, format('retry'))
14385
+ h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: reload }, format('retry'))
13804
14386
  ),
13805
14387
  notice === '' ? null : h('div', { className: 'md-notice', role: 'status', inert: covered ? '' : undefined }, notice),
13806
14388
  catalog === null || blockingError !== '' || partialFiles === 0 ? null : h('div', { className: 'md-hint', inert: covered ? '' : undefined },
@@ -13857,6 +14439,10 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
13857
14439
  onWorkflowChange: value => writeWorkflowMode(value),
13858
14440
  onApiKeyChange: configured => setEnvTools(current => ({ ...current, apiKey: configured === true })),
13859
14441
  updateBusy,
14442
+ updateInfo,
14443
+ marketUpdate,
14444
+ updateOperation,
14445
+ onInstallUpdate: installUpdate,
13860
14446
  onCheckUpdate: checkUpdates,
13861
14447
  previewPdf,
13862
14448
  allowNonPdfDelete,
@@ -14041,7 +14627,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
14041
14627
  h('p', { className: 'md-state-detail' }, format('pageCrashHint')),
14042
14628
  h('pre', { className: 'md-state-detail' }, message),
14043
14629
  h('div', { className: 'md-state-actions' },
14044
- h('button', { type: 'button', className: 'md-btn', onClick: this.retry }, format('retry'))
14630
+ h(KitButton, { type: 'button', className: 'md-btn', onClick: this.retry }, format('retry'))
14045
14631
  )
14046
14632
  )
14047
14633
  )