poi-plugin-kancolle-chs 1.4.1 → 1.4.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poi-plugin-kancolle-chs",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "砍口垒汉化计划PLUS POI 原生独立插件:提供全界面文本替换、正则动态替换、KCSAPI 响应合流、中文字体与贴图魔改、自定义字体适配与官方资源更新",
5
5
  "main": "index.es",
6
6
  "files": [
package/src/constants.es CHANGED
@@ -15,7 +15,7 @@ export const OFFICIAL_REPO_GIT = 'https://github.com/asaico/Kancolle_to_CHS.git'
15
15
  export const OFFICIAL_REPO_RELEASES = 'https://github.com/asaico/Kancolle_to_CHS/releases'
16
16
 
17
17
  // 插件版本与 npm 元信息
18
- let pkgVersion = '1.4.1'
18
+ let pkgVersion = '1.4.2'
19
19
  try {
20
20
  const pkg = require('../package.json')
21
21
  if (pkg && pkg.version) pkgVersion = pkg.version
@@ -161,16 +161,41 @@ export class MainPanel extends Component {
161
161
 
162
162
  // 针对旧版 POI 或特定主题外层容器修正高度与滚动上下文
163
163
  this.fixParentScrollStyles()
164
+ setTimeout(this.fixParentScrollStyles, 50)
165
+ setTimeout(this.fixParentScrollStyles, 250)
166
+
167
+ const rootEl = this.rootRef.current
168
+ if (rootEl) {
169
+ rootEl.addEventListener('wheel', this.handleWheel, { passive: false })
170
+
171
+ const doc = rootEl.ownerDocument || document
172
+ const win = doc.defaultView || (typeof window !== 'undefined' ? window : null)
173
+ this.currentDoc = doc
174
+ this.currentWin = win
175
+
176
+ if (win) {
177
+ win.addEventListener('resize', this.handleResize)
178
+ if (win !== window) {
179
+ // 独立新窗口模式:在 window 与 document 均挂载滚轮监听,实现全屏无死角即时滚动响应
180
+ win.addEventListener('wheel', this.handleWheel, { passive: false })
181
+ doc.addEventListener('wheel', this.handleWheel, { passive: false })
182
+ }
183
+ }
164
184
 
165
- // 绑定原生滚轮双重补偿监听 (保障老旧 Electron 或卡片事件捕获异常环境)
166
- if (this.rootRef && this.rootRef.current) {
167
- this.rootRef.current.addEventListener('wheel', this.handleWheel, { passive: true })
185
+ // 确保进入新窗口时容器立即可获得焦点与滚动上下文
186
+ setTimeout(() => {
187
+ try {
188
+ rootEl.focus({ preventScroll: true })
189
+ } catch (_) {}
190
+ }, 50)
168
191
  }
169
192
 
170
193
  // 监听窗口与容器自适应宽度变化,实现动态窄窗紧凑排版适配
171
194
  this.handleResize = () => {
172
195
  if (this.rootRef && this.rootRef.current) {
173
196
  this.setState({ containerWidth: this.rootRef.current.offsetWidth })
197
+ } else if (this.currentWin) {
198
+ this.setState({ containerWidth: this.currentWin.innerWidth })
174
199
  } else if (typeof window !== 'undefined') {
175
200
  this.setState({ containerWidth: window.innerWidth })
176
201
  }
@@ -235,21 +260,58 @@ export class MainPanel extends Component {
235
260
  if (this.rootRef && this.rootRef.current) {
236
261
  this.rootRef.current.removeEventListener('wheel', this.handleWheel)
237
262
  }
263
+ if (this.currentWin) {
264
+ this.currentWin.removeEventListener('resize', this.handleResize)
265
+ if (this.currentWin !== window) {
266
+ this.currentWin.removeEventListener('wheel', this.handleWheel)
267
+ }
268
+ }
269
+ if (this.currentDoc && this.currentDoc !== document) {
270
+ this.currentDoc.removeEventListener('wheel', this.handleWheel)
271
+ }
238
272
  if (this.ro) {
239
273
  this.ro.disconnect()
240
274
  }
241
275
  }
242
276
 
243
277
  /**
244
- * 自动向上递归修正 POI 外层 Tab 容器的高度与 flex 布局,确保内层滚动条与滚轮绝对可用
278
+ * 自动向上递归修正 POI 外层 Tab 及独立新窗口容器的高度与 flex 布局,确保内层滚动条与滚轮绝对可用
245
279
  */
246
280
  fixParentScrollStyles = () => {
247
281
  try {
248
282
  const root = this.rootRef.current
249
283
  if (!root) return
284
+
285
+ const doc = root.ownerDocument || document
286
+ const win = doc.defaultView || window
287
+ const isDetachedWindow = (doc !== document) || (win !== window) || Boolean(doc.getElementById('plugin-mountpoint'))
288
+
289
+ // 1. 若处于独立新窗口模式,修正 html、body 及 #plugin-mountpoint 的高度与溢出策略
290
+ if (isDetachedWindow) {
291
+ if (doc.documentElement) {
292
+ if (doc.documentElement.style.height !== '100%') doc.documentElement.style.height = '100%'
293
+ if (doc.documentElement.style.overflow !== 'hidden') doc.documentElement.style.overflow = 'hidden'
294
+ }
295
+ if (doc.body) {
296
+ if (doc.body.style.height !== '100%') doc.body.style.height = '100%'
297
+ if (doc.body.style.margin !== '0px') doc.body.style.margin = '0'
298
+ if (doc.body.style.padding !== '0px') doc.body.style.padding = '0'
299
+ if (doc.body.style.overflow !== 'hidden') doc.body.style.overflow = 'hidden'
300
+ }
301
+ const mountpoint = doc.getElementById('plugin-mountpoint')
302
+ if (mountpoint) {
303
+ if (mountpoint.style.height !== '100vh') mountpoint.style.height = '100vh'
304
+ if (mountpoint.style.maxHeight !== '100vh') mountpoint.style.maxHeight = '100vh'
305
+ if (mountpoint.style.display !== 'flex') mountpoint.style.display = 'flex'
306
+ if (mountpoint.style.flexDirection !== 'column') mountpoint.style.flexDirection = 'column'
307
+ if (mountpoint.style.overflow !== 'hidden') mountpoint.style.overflow = 'hidden'
308
+ }
309
+ }
310
+
311
+ // 2. 向上递归修正所有外层容器的高度与 flex 布局
250
312
  let parent = root.parentElement
251
313
  let depth = 0
252
- while (parent && depth < 4) {
314
+ while (parent && depth < 6) {
253
315
  const id = parent.id || ''
254
316
  const cls = parent.className || ''
255
317
  if (
@@ -259,9 +321,17 @@ export class MainPanel extends Component {
259
321
  id.includes('poi-plugin-kancolle-chs') ||
260
322
  id === 'plugin-mountpoint'
261
323
  ) {
262
- if (parent.style.height !== '100%') parent.style.height = '100%'
324
+ if (id === 'plugin-mountpoint') {
325
+ if (parent.style.height !== '100vh') parent.style.height = '100vh'
326
+ if (parent.style.maxHeight !== '100vh') parent.style.maxHeight = '100vh'
327
+ } else {
328
+ if (parent.style.height !== '100%') parent.style.height = '100%'
329
+ if (parent.style.maxHeight !== '100%') parent.style.maxHeight = '100%'
330
+ }
263
331
  if (parent.style.display !== 'flex') parent.style.display = 'flex'
264
332
  if (parent.style.flexDirection !== 'column') parent.style.flexDirection = 'column'
333
+ if (parent.style.flex !== '1 1 0px' && parent.style.flex !== '1') parent.style.flex = '1 1 0'
334
+ if (parent.style.minHeight !== '0px') parent.style.minHeight = '0'
265
335
  if (parent.style.overflow !== 'hidden') parent.style.overflow = 'hidden'
266
336
  }
267
337
  parent = parent.parentElement
@@ -271,20 +341,50 @@ export class MainPanel extends Component {
271
341
  }
272
342
 
273
343
  /**
274
- * 滚轮平滑滚动双重补偿兜底
344
+ * 滚轮平滑滚动双重补偿与新窗口即时响应机制
275
345
  */
276
346
  handleWheel = (e) => {
277
347
  const container = this.rootRef.current
278
348
  if (!container) return
279
- if (container.scrollHeight <= container.clientHeight) return
280
349
 
281
- // 双重保障:若在老版本 POI / Electron 中原生滚轮事件未驱动 scrollTop,进行位移补偿
282
- const prevScrollTop = container.scrollTop
283
- requestAnimationFrame(() => {
284
- if (container && container.scrollTop === prevScrollTop && e.deltaY !== 0) {
285
- container.scrollTop += e.deltaY
286
- }
287
- })
350
+ // 如果事件目标是拥有独立滚动条的子元素(如 textarea),不予干涉
351
+ const target = e.target
352
+ if (target && (target.tagName === 'TEXTAREA' || target.tagName === 'INPUT')) {
353
+ if (target.scrollHeight > target.clientHeight) return
354
+ }
355
+
356
+ // 获取当前所属窗口(若在新窗口打开,则使用该独立窗口的 window 与 rAF)
357
+ const win = container.ownerDocument?.defaultView || (typeof window !== 'undefined' ? window : null)
358
+ const isDetachedWindow = (container.ownerDocument !== document) || (win && win !== window)
359
+
360
+ // 计算滚轮位移量
361
+ let delta = e.deltaY
362
+ if (e.deltaMode === 1) delta *= 25
363
+ else if (e.deltaMode === 2) delta *= container.clientHeight
364
+
365
+ if (container.scrollHeight <= container.clientHeight) {
366
+ // 容错重试:若尚未修正外层样式导致高度膨胀,立即修正一次
367
+ this.fixParentScrollStyles()
368
+ if (container.scrollHeight <= container.clientHeight) return
369
+ }
370
+
371
+ if (isDetachedWindow) {
372
+ // 独立新窗口模式:直接驱动 scrollTop 确保 100% 极速平滑滚动响应
373
+ container.scrollTop += delta
374
+ if (e.cancelable) e.preventDefault()
375
+ } else {
376
+ // 常规主窗口 Tab:双重补偿保障机制
377
+ const prevScrollTop = container.scrollTop
378
+ const rAF = (win && typeof win.requestAnimationFrame === 'function')
379
+ ? win.requestAnimationFrame.bind(win)
380
+ : requestAnimationFrame
381
+
382
+ rAF(() => {
383
+ if (container && container.scrollTop === prevScrollTop && delta !== 0) {
384
+ container.scrollTop += delta
385
+ }
386
+ })
387
+ }
288
388
  }
289
389
 
290
390
  /**
@@ -1867,8 +1967,9 @@ export class MainPanel extends Component {
1867
1967
  style={{
1868
1968
  width: '100%',
1869
1969
  height: '100%',
1870
- minHeight: '100%',
1970
+ minHeight: 0,
1871
1971
  maxHeight: '100%',
1972
+ flex: '1 1 0',
1872
1973
  overflowY: 'auto',
1873
1974
  overflowX: 'hidden',
1874
1975
  WebkitOverflowScrolling: 'touch',
@@ -1970,22 +2071,42 @@ export class MainPanel extends Component {
1970
2071
  }
1971
2072
  }
1972
2073
 
2074
+ /* 新窗口与常规 Tab 模式全层级自适应滚动链保障 */
2075
+ html, body {
2076
+ height: 100% !important;
2077
+ overflow: hidden !important;
2078
+ }
2079
+ #plugin-mountpoint {
2080
+ height: 100vh !important;
2081
+ max-height: 100vh !important;
2082
+ display: flex !important;
2083
+ flex-direction: column !important;
2084
+ overflow: hidden !important;
2085
+ box-sizing: border-box !important;
2086
+ }
2087
+ .poi-app-tabpane,
1973
2088
  #poi-plugin-kancolle-chs,
1974
2089
  #poi-plugin-kancolle-chs.poi-app-tabpane,
1975
2090
  .poi-plugin-content-poi-plugin-kancolle-chs {
1976
2091
  height: 100% !important;
2092
+ max-height: 100% !important;
1977
2093
  display: flex !important;
2094
+ flex: 1 1 0 !important;
2095
+ min-height: 0 !important;
1978
2096
  flex-direction: column !important;
1979
2097
  overflow: hidden !important;
2098
+ box-sizing: border-box !important;
1980
2099
  }
1981
2100
  .kancolle-chs-plus-scroll-container {
1982
2101
  height: 100% !important;
1983
- min-height: 100% !important;
2102
+ min-height: 0 !important;
1984
2103
  max-height: 100% !important;
2104
+ flex: 1 1 0 !important;
1985
2105
  overflow-y: auto !important;
1986
2106
  overflow-x: hidden !important;
1987
2107
  -webkit-overflow-scrolling: touch !important;
1988
2108
  outline: none !important;
2109
+ box-sizing: border-box !important;
1989
2110
  }
1990
2111
  .kancolle-chs-plus-scroll-container::-webkit-scrollbar {
1991
2112
  width: 8px;