dsh-think-skin 0.3.0 → 0.3.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.
Files changed (82) hide show
  1. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 1.gif +0 -0
  2. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 2.gif +0 -0
  3. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/200/345/210/207/351/203/275/345/245/275 1.gif +0 -0
  4. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/273/346/204/217.gif +0 -0
  5. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/201/234/346/255/242/345/267/245/344/275/234.gif +0 -0
  6. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/202/254/347/234/240.gif +0 -0
  7. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211.gif +0 -0
  8. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/217/271/345/217/267.gif +0 -0
  9. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/210/206/347/261/263/350/212/261).gif +0 -0
  10. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/224/234/347/224/234/345/234/210).gif +0 -0
  11. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/350/245/277/347/223/234).gif +0 -0
  12. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/221/206(/350/264/264/347/272/270) 2.gif +0 -0
  13. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/224/261/346/255/214.gif +0 -0
  14. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/345/260/217/347/235/241).gif +0 -0
  15. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/346/231/256/351/200/232).gif +0 -0
  16. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/347/226/262/345/200/246).gif +0 -0
  17. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/276/227/345/210/206(10/345/210/206).gif +0 -0
  18. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260).gif +0 -0
  19. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260).gif +0 -0
  20. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/201/274/346/200/222).gif +0 -0
  21. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/231/256/351/200/232).gif +0 -0
  22. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/347/224/237/346/260/224).gif +0 -0
  23. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/346/270/270/346/210/217.gif +0 -0
  24. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/223/346/213/215(/346/211/213/346/234/272).gif +0 -0
  25. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/230/346/211/207.gif +0 -0
  26. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/214/211/351/222/256.gif +0 -0
  27. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/255/243/345/234/250/346/200/235/350/200/203.gif +0 -0
  28. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 2.gif +0 -0
  29. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 3.gif +0 -0
  30. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 1.gif +0 -0
  31. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 2.gif +0 -0
  32. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/273/346/235/277.gif +0 -0
  33. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/234/250/347/234/274.gif +0 -0
  34. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651).gif +0 -0
  35. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/244/274/347/211/251 2.gif +0 -0
  36. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(Bits).gif +0 -0
  37. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203).gif +0 -0
  38. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/345/210/200/345/217/211).gif +0 -0
  39. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/347/255/267/345/255/220).gif +0 -0
  40. package/assets//351/205/222/347/213/220/PS2.gif +0 -0
  41. package/client.js +43 -0
  42. package/package.json +4 -2
  43. package/tools/compile-pack.py +117 -0
  44. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 1_2026-08-18-14-25-14.gif +0 -0
  45. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 2_2026-08-18-14-25-25.gif +0 -0
  46. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/200/345/210/207/351/203/275/345/245/275 1_2026-08-18-14-37-38.gif +0 -0
  47. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/273/346/204/217_2026-08-18-14-15-51.gif +0 -0
  48. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/201/234/346/255/242/345/267/245/344/275/234_2026-08-18-14-34-45.gif +0 -0
  49. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/202/254/347/234/240_2026-08-18-14-15-43.gif +0 -0
  50. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211_2026-08-18-14-35-59.gif +0 -0
  51. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/217/271/345/217/267_2026-08-18-14-12-08.gif +0 -0
  52. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/210/206/347/261/263/350/212/261)_2026-08-18-14-11-25.gif +0 -0
  53. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/224/234/347/224/234/345/234/210)_2026-08-18-14-11-06.gif +0 -0
  54. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/350/245/277/347/223/234)_2026-08-18-14-11-30.gif +0 -0
  55. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/221/206(/350/264/264/347/272/270) 2_2026-08-18-14-10-34.gif +0 -0
  56. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/224/261/346/255/214_2026-08-18-14-28-11.gif +0 -0
  57. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/345/260/217/347/235/241)_2026-08-18-14-39-08.gif +0 -0
  58. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/346/231/256/351/200/232)_2026-08-18-14-39-12.gif +0 -0
  59. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/347/226/262/345/200/246)_2026-08-18-14-39-19.gif +0 -0
  60. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/276/227/345/210/206(10/345/210/206)_2026-08-18-14-27-16.gif +0 -0
  61. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260)_2026-08-18-14-37-20.gif +0 -0
  62. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260)_2026-08-18-14-37-25.gif +0 -0
  63. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/201/274/346/200/222)_2026-08-18-14-38-27.gif +0 -0
  64. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/231/256/351/200/232)_2026-08-18-14-38-34.gif +0 -0
  65. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/347/224/237/346/260/224)_2026-08-18-14-38-24.gif +0 -0
  66. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/346/270/270/346/210/217_2026-08-18-14-13-01.gif +0 -0
  67. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/223/346/213/215(/346/211/213/346/234/272)_2026-08-18-14-04-40.gif +0 -0
  68. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/230/346/211/207_2026-08-18-14-12-51.gif +0 -0
  69. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/214/211/351/222/256_2026-08-18-14-03-53.gif +0 -0
  70. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/255/243/345/234/250/346/200/235/350/200/203_2026-08-18-14-24-28.gif +0 -0
  71. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 2_2026-08-18-14-20-22.gif +0 -0
  72. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 3_2026-08-18-14-20-29.gif +0 -0
  73. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 1_2026-08-18-14-11-56.gif +0 -0
  74. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 2_2026-08-18-14-12-00.gif +0 -0
  75. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/273/346/235/277_2026-08-18-14-36-39.gif +0 -0
  76. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/234/250/347/234/274_2026-08-18-14-38-44.gif +0 -0
  77. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651)_2026-08-18-14-28-50.gif +0 -0
  78. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/244/274/347/211/251 2_2026-08-18-14-14-21.gif +0 -0
  79. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(Bits)_2026-08-18-14-13-19.gif +0 -0
  80. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203)_2026-08-18-14-13-47.gif +0 -0
  81. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/345/210/200/345/217/211)_2026-08-18-14-09-51.gif +0 -0
  82. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/347/255/267/345/255/220)_2026-08-18-14-09-43.gif +0 -0
package/client.js CHANGED
@@ -1975,6 +1975,40 @@ window.__ModuleLoader__.load({
1975
1975
  )
1976
1976
  }
1977
1977
 
1978
+ /**
1979
+ * The nav icon for our settings section.
1980
+ *
1981
+ * `settings.section.icon` hands the component `size` (requested square edge)
1982
+ * and `active` (whether the section is selected). We show the active pack's
1983
+ * cover; glyph packs get a star instead, since they have no artwork.
1984
+ */
1985
+ function SettingsIcon({ size, active }) {
1986
+ const [, bump] = React.useState(0)
1987
+ React.useEffect(() => {
1988
+ if (pack === null) loadPack().then(() => bump((n) => n + 1))
1989
+ }, [])
1990
+ const edge = Number.isFinite(Number(size)) ? Number(size) : 16
1991
+ const box = { width: edge + 'px', height: edge + 'px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }
1992
+
1993
+ if (pack === null) return h('span', { style: { ...box, fontSize: edge * 0.9 } }, '✻')
1994
+ // 字形套也有封面(那个橙色 ✻ 占位图),照样用它,别退化成文字
1995
+ const file = pack.cover || (Array.isArray(pack.images) && pack.images[0] !== undefined
1996
+ ? pack.images[0].file
1997
+ : null)
1998
+ if (file === null) return h('span', { style: { ...box, fontSize: edge * 0.9 } }, '✻')
1999
+ return h('img', {
2000
+ src: imageUrl(file),
2001
+ alt: '',
2002
+ style: {
2003
+ width: edge + 'px',
2004
+ height: edge + 'px',
2005
+ objectFit: 'contain',
2006
+ borderRadius: '3px',
2007
+ opacity: active === false ? 0.85 : 1,
2008
+ },
2009
+ })
2010
+ }
2011
+
1978
2012
  /** Register the settings page. Failure here must not take the skin down. */
1979
2013
  function registerSettings(ctx) {
1980
2014
  try {
@@ -1985,6 +2019,15 @@ window.__ModuleLoader__.load({
1985
2019
  label: () => '思考状态',
1986
2020
  inject: () => ({}),
1987
2021
  }, SettingsPanel))
2022
+
2023
+ // 同一个 id 才会被挂到我们那一行的图标位上
2024
+ ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
2025
+ name: 'settings.section.icon',
2026
+ id: 'think-skin',
2027
+ order: 40,
2028
+ label: () => '思考状态',
2029
+ inject: () => ({}),
2030
+ }, SettingsIcon))
1988
2031
  } catch {
1989
2032
  /* the panel is optional; the skin keeps working without it */
1990
2033
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-think-skin",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Reskin the DSH thinking row: your own image, your own words, double random.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,7 +31,9 @@
31
31
  "assets/cover.gif",
32
32
  "assets/compiled-128",
33
33
  "assets/ClaudeCode/verbs.json",
34
- "assets/ClaudeCode/placeholder.png"
34
+ "assets/ClaudeCode/placeholder.png",
35
+ "assets/酒狐",
36
+ "tools/compile-pack.py"
35
37
  ],
36
38
  "dsh": {
37
39
  "bundle": {
@@ -0,0 +1,117 @@
1
+ """Recompile a pack's images at 128px, keeping every frame and its delay.
2
+
3
+ The rule this file exists to protect: **never rewrite per-frame timing.** A GIF
4
+ carries its own cadence — the fish sources run at 20 ms per frame, the fox at
5
+ 100 ms. Forcing a fixed frame rate is what made the fox spin twice too fast and
6
+ cost the fish two thirds of its frames.
7
+
8
+ Usage:
9
+ python tools/compile-pack.py --pack 蓝色大肥鱼 --source assets/蓝色大肥鱼
10
+ python tools/compile-pack.py --pack 酒狐 --source assets/酒狐
11
+ python tools/compile-pack.py --pack 蓝色大肥鱼 --source ... --dry-run
12
+ """
13
+
14
+ import argparse
15
+ import io
16
+ import json
17
+ import os
18
+ import re
19
+ import sys
20
+
21
+ try:
22
+ from PIL import Image, ImageSequence
23
+ except ImportError:
24
+ sys.exit("需要 Pillow:pip install pillow")
25
+
26
+ HERE = os.path.dirname(os.path.abspath(__file__))
27
+ ROOT = os.path.dirname(HERE)
28
+ BOX = (128, 128)
29
+
30
+
31
+ def store_root():
32
+ home = os.environ.get("DSH_HOME") or os.path.join(os.path.expanduser("~"), ".dsh")
33
+ return os.path.join(home, "storages", "think_skin")
34
+
35
+
36
+ def action_of(filename):
37
+ """`蓝色大肥鱼_思考(认真地)_2026-08-18-14-37-25.gif` -> `思考(认真地)`."""
38
+ stem = os.path.splitext(os.path.basename(filename))[0]
39
+ stem = re.sub(r"_\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}$", "", stem)
40
+ stem = re.sub(r"^[^_]+_", "", stem)
41
+ return stem.strip()
42
+
43
+
44
+ def compile_gif(src, dst):
45
+ """Resize every frame to fit BOX, preserving the frame count and delays."""
46
+ im = Image.open(src)
47
+ frames = []
48
+ durations = []
49
+ for frame in ImageSequence.Iterator(im):
50
+ durations.append(frame.info.get("duration", 100) or 100)
51
+ rgba = frame.convert("RGBA")
52
+ w, h = rgba.size
53
+ scale = min(BOX[0] / w, BOX[1] / h)
54
+ size = (max(1, int(round(w * scale))), max(1, int(round(h * scale))))
55
+ scaled = rgba.resize(size, Image.LANCZOS)
56
+ canvas = Image.new("RGBA", BOX, (0, 0, 0, 0))
57
+ canvas.paste(scaled, ((BOX[0] - size[0]) // 2, (BOX[1] - size[1]) // 2), scaled)
58
+ frames.append(canvas)
59
+ frames[0].save(
60
+ dst,
61
+ save_all=True,
62
+ append_images=frames[1:],
63
+ duration=durations,
64
+ loop=0,
65
+ disposal=2,
66
+ optimize=True,
67
+ )
68
+ return len(frames), sum(durations)
69
+
70
+
71
+ def main():
72
+ parser = argparse.ArgumentParser()
73
+ parser.add_argument("--pack", required=True, help="pack id in pack.json")
74
+ parser.add_argument("--source", required=True, help="directory of original GIFs")
75
+ parser.add_argument("--dry-run", action="store_true")
76
+ args = parser.parse_args()
77
+
78
+ manifest_path = os.path.join(store_root(), "pack.json")
79
+ document = json.load(io.open(manifest_path, encoding="utf-8"))
80
+ pack = next((p for p in document["packs"] if p["id"] == args.pack), None)
81
+ if pack is None:
82
+ sys.exit("pack.json 里没有 " + args.pack)
83
+
84
+ sources = {}
85
+ for name in os.listdir(args.source):
86
+ path = os.path.join(args.source, name)
87
+ if os.path.splitext(name)[1].lower() != ".gif":
88
+ continue
89
+ sources[action_of(name)] = path
90
+
91
+ print("源目录 %d 个 GIF,清单 %d 张图" % (len(sources), len(pack["images"])))
92
+ before = 0
93
+ after = 0
94
+ missing = []
95
+ for image in pack["images"]:
96
+ target = os.path.join(store_root(), "images", image["file"].replace("/", os.sep))
97
+ if os.path.exists(target):
98
+ before += os.path.getsize(target)
99
+ src = sources.get(image.get("name", ""))
100
+ if src is None:
101
+ missing.append(image.get("name", "?"))
102
+ continue
103
+ if args.dry_run:
104
+ continue
105
+ frames, total = compile_gif(src, target)
106
+ after += os.path.getsize(target)
107
+ print(" %-16s %3d 帧 %.2fs %4d KB" % (
108
+ image.get("name", "")[:16], frames, total / 1000, os.path.getsize(target) // 1024))
109
+
110
+ if missing:
111
+ print("没找到源文件: " + ", ".join(missing))
112
+ if not args.dry_run:
113
+ print("合计 %.2f MB → %.2f MB" % (before / 1024 / 1024, after / 1024 / 1024))
114
+
115
+
116
+ if __name__ == "__main__":
117
+ main()