dsh-happy-reader 0.2.2 → 0.2.4

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 (2) hide show
  1. package/lib/client.js +34 -5
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -29,7 +29,7 @@ window.__ModuleLoader__.load({
29
29
  var exports = module.exports
30
30
 
31
31
  // ── 常量 ────────────────────────────────────────────────────────────
32
- const VERSION = '0.2.2'
32
+ const VERSION = '0.2.4'
33
33
  const STATE_KEY = 'dsh.reader-boost.v1'
34
34
  const FAB_ID = 'dsrb-fab'
35
35
  const PANEL_ID = 'dsrb-panel'
@@ -144,6 +144,8 @@ window.__ModuleLoader__.load({
144
144
  // "开合/新对话"悬浮按钮与"应用/编辑"菜单的定位基准,归零会裁掉它们的上半截。
145
145
  // 改为逐项覆盖:frame 顶部预留条清零、侧栏列自留该变量、收态归零内容圆角、
146
146
  // 全屏隐藏菜单;规则由 html[data-dsrb-fullscreen] 门控,退出全屏即完全还原。
147
+ // 注:.BynINW_* 为应用构建期类名(随应用更新可能变;失效即表现为全屏残留,
148
+ // 按新构建重新对齐即可——无更稳定锚点可用,属原则②下已接受的取舍)。
147
149
  const FS_CSS = [
148
150
  // 镜像官方 html[data-windows-titlebar][data-fullscreen]:overlay 顶距 20px、chrome 顶距 0
149
151
  'html[data-windows-titlebar][data-dsrb-fullscreen]{--dsh-frame-overlay-top:20px;--dsh-frame-chrome-top:0px}',
@@ -317,8 +319,14 @@ window.__ModuleLoader__.load({
317
319
  let next = value
318
320
  if (famNames.length && next.indexOf('var(--dsw-font-family)') !== -1) next = next.split('var(--dsw-font-family)').join(fam)
319
321
  if (code && next.indexOf('var(--ds-font-family-code)') !== -1) next = next.split('var(--ds-font-family-code)').join(cod)
320
- // 行距:把简写里字号后的"/行高"按倍率改写(0.5px 步进),字号本身不动
321
- if (lineH !== null) next = next.replace(/(\/\s*)(\d+(?:\.\d+)?)px/g, (m, lead, n) => lead + Math.round(Number(n) * lineH * 2) / 2 + 'px')
322
+ // 行距:官方行高 token 的真实形态是简写里的 "/ calc(Npx + var(--dsh-content-font-delta))"
323
+ //(增量由官方自管、随字号缩放);按倍率整段放大,字号本身不动
324
+ if (lineH !== null) {
325
+ next = next.replace(
326
+ /(\/\s*)calc\((\d+(?:\.\d+)?)px \+ var\(--dsh-content-font-delta\)\)/g,
327
+ (m, lead, n) => lead + 'calc((' + n + 'px + var(--dsh-content-font-delta)) * ' + lineH + ')',
328
+ )
329
+ }
322
330
  if (next !== value) parts.push(name + ':' + next)
323
331
  }
324
332
  if (letterSp !== null) parts.push('letter-spacing:' + letterSp + 'px')
@@ -1224,7 +1232,7 @@ window.__ModuleLoader__.load({
1224
1232
  if (Math.abs(dx) + Math.abs(dy) > 4) panelDrag.moved = true
1225
1233
  if (!panelDrag.moved) return
1226
1234
  const x = Math.min(Math.max(0, panelDrag.ox + dx), Math.max(0, window.innerWidth - panel.offsetWidth))
1227
- const y = Math.min(Math.max(0, panelDrag.oy + dy), Math.max(0, window.innerHeight - 34))
1235
+ const y = Math.min(Math.max(0, panelDrag.oy + dy), Math.max(0, window.innerHeight - 34)) // 至少留 34px 在视口内(可抓回)
1228
1236
  panel.style.left = x + 'px'
1229
1237
  panel.style.top = y + 'px'
1230
1238
  } else if (panelResize) {
@@ -1368,7 +1376,28 @@ window.__ModuleLoader__.load({
1368
1376
  if (ka) work.setStartBefore(ka)
1369
1377
  if (kf) work.setEndAfter(kf)
1370
1378
  const box = document.createElement('div')
1371
- box.append(work.cloneContents())
1379
+ // 选区克隆丢掉共同祖先往上的层级(代码块外层的 <pre> 即如此丢的),转换器的
1380
+ // 空白折叠随即把换行折掉;按现场回收"预格式化"祖先链(判据=实际生效的
1381
+ // white-space)补壳还原层级——非预格式化选区零改动。
1382
+ const cac = work.commonAncestorContainer
1383
+ let anc = cac.nodeType === 1 ? cac : cac.parentElement
1384
+ const ancShells = []
1385
+ while (anc && anc !== document.body && !anc.matches('[data-chat-node-key]')) {
1386
+ ancShells.push(anc)
1387
+ anc = anc.parentElement
1388
+ }
1389
+ let topShell = -1
1390
+ for (let i = 0; i < ancShells.length; i++) {
1391
+ const ws = getComputedStyle(ancShells[i]).whiteSpace
1392
+ if (ws === 'pre' || ws === 'pre-wrap' || ws === 'pre-line' || ws === 'break-spaces') topShell = i
1393
+ }
1394
+ let nestAt = box
1395
+ for (let i = topShell; i >= 0; i--) {
1396
+ const shell = ancShells[i].cloneNode(false)
1397
+ nestAt.append(shell)
1398
+ nestAt = shell
1399
+ }
1400
+ nestAt.append(work.cloneContents())
1372
1401
  // 公式场景先留存原始 HTML(含 <math>):粘进 Word 等富目标仍可显示公式
1373
1402
  const html = box.querySelector('.katex') ? box.innerHTML : null
1374
1403
  // 标签→Markdown 映射由标准库 turndown 承担(公式已由上面的 katex 规则还原为 LaTeX)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-happy-reader",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Happy Reader(阅读增强):隐藏输入框 / 上边栏、全屏切换、字号 10–40px、行距/字距微调、面板可拖动可拉高、复制为 Markdown(公式→LaTeX)、内容宽度扩展、中英文分别选正文字体 + 代码字体(仅列本机已装)—— 与官方设置协同,不冲突",
5
5
  "type": "module",
6
6
  "license": "MIT",