@kafukatree/dsh-skill-manager 0.0.0-stage → 0.3.1

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 (307) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-lucide.txt +43 -0
  3. package/README.md +44 -2
  4. package/agent-tool.mjs +118 -0
  5. package/client-bridge.mjs +307 -0
  6. package/client-entry.mjs +131 -0
  7. package/client.js +6769 -0
  8. package/control-icon.mjs +40 -0
  9. package/cordis.patch.yml +4 -0
  10. package/design/skill-manager.pen +798 -0
  11. package/design.css +320 -0
  12. package/design.mjs +629 -0
  13. package/dialogs.css +460 -0
  14. package/dialogs.mjs +1130 -0
  15. package/document-link.mjs +13 -0
  16. package/file-actions.mjs +62 -0
  17. package/file-view.mjs +384 -0
  18. package/header-scroll.css +90 -0
  19. package/header-scroll.mjs +121 -0
  20. package/host.mjs +460 -0
  21. package/icon.svg +6 -0
  22. package/import-archive.mjs +41 -0
  23. package/import-commit.mjs +247 -0
  24. package/import-family.mjs +213 -0
  25. package/import-files.mjs +186 -0
  26. package/import-github.mjs +168 -0
  27. package/import-limits.mjs +10 -0
  28. package/import-native.mjs +79 -0
  29. package/imports.mjs +209 -0
  30. package/inventory.mjs +62 -0
  31. package/library.mjs +1334 -0
  32. package/local-families.mjs +277 -0
  33. package/locale/en.json +16 -0
  34. package/locale/zh.json +16 -0
  35. package/management-view.mjs +158 -0
  36. package/mode-view.mjs +72 -0
  37. package/node_modules/pend/LICENSE +23 -0
  38. package/node_modules/pend/README.md +41 -0
  39. package/node_modules/pend/index.js +55 -0
  40. package/node_modules/pend/package.json +18 -0
  41. package/node_modules/pend/test.js +137 -0
  42. package/node_modules/yaml/LICENSE +13 -0
  43. package/node_modules/yaml/README.md +172 -0
  44. package/node_modules/yaml/bin.mjs +11 -0
  45. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  46. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  47. package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
  48. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  49. package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
  50. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  51. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  52. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  53. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  54. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  55. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
  56. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  57. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  58. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  59. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  60. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  61. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  62. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  63. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  64. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  65. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  66. package/node_modules/yaml/browser/dist/errors.js +57 -0
  67. package/node_modules/yaml/browser/dist/index.js +17 -0
  68. package/node_modules/yaml/browser/dist/log.js +11 -0
  69. package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
  70. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  71. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  72. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  73. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  74. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  75. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  76. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  77. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  78. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  79. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  80. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  81. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  82. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  83. package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
  84. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  85. package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
  86. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  87. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  88. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  89. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  90. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  91. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  92. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  93. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  94. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  95. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  96. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  97. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  98. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  99. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  100. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  101. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  102. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
  103. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  104. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  105. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  106. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  107. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  108. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  109. package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
  110. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
  111. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  112. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  113. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
  114. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  115. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  116. package/node_modules/yaml/browser/dist/util.js +11 -0
  117. package/node_modules/yaml/browser/dist/visit.js +233 -0
  118. package/node_modules/yaml/browser/index.js +5 -0
  119. package/node_modules/yaml/browser/package.json +3 -0
  120. package/node_modules/yaml/dist/cli.d.ts +8 -0
  121. package/node_modules/yaml/dist/cli.mjs +201 -0
  122. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  123. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  124. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  125. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  126. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  127. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  128. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  129. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  130. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  131. package/node_modules/yaml/dist/compose/composer.js +224 -0
  132. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  133. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  134. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  135. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  136. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  137. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  138. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  139. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  140. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  141. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  142. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  143. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
  144. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  145. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  146. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  147. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  148. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  149. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  150. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  151. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  152. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  153. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  154. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  155. package/node_modules/yaml/dist/doc/Document.js +337 -0
  156. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  157. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  158. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  159. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  160. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  161. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  162. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  163. package/node_modules/yaml/dist/doc/directives.js +178 -0
  164. package/node_modules/yaml/dist/errors.d.ts +21 -0
  165. package/node_modules/yaml/dist/errors.js +62 -0
  166. package/node_modules/yaml/dist/index.d.ts +25 -0
  167. package/node_modules/yaml/dist/index.js +50 -0
  168. package/node_modules/yaml/dist/log.d.ts +3 -0
  169. package/node_modules/yaml/dist/log.js +19 -0
  170. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  171. package/node_modules/yaml/dist/nodes/Alias.js +120 -0
  172. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  173. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  174. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  175. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  176. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  177. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  178. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  179. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  180. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  181. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  182. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  183. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  184. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  185. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  186. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  187. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  188. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  189. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  190. package/node_modules/yaml/dist/options.d.ts +350 -0
  191. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  192. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  193. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  194. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  195. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  196. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  197. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  198. package/node_modules/yaml/dist/parse/cst.js +112 -0
  199. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  200. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  201. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  202. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  203. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  204. package/node_modules/yaml/dist/parse/parser.js +980 -0
  205. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  206. package/node_modules/yaml/dist/public-api.js +107 -0
  207. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  208. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  209. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  210. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  211. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  212. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  213. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  214. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  215. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  216. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  217. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  218. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  219. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  220. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  221. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  222. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  223. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  224. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  225. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  226. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  227. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  228. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  229. package/node_modules/yaml/dist/schema/tags.js +99 -0
  230. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  231. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  232. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  233. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  234. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  235. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  236. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  237. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  238. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  239. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  240. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  241. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  242. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  243. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  244. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  245. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  246. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  247. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  248. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  249. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  250. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  251. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  252. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  253. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  254. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  255. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  256. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  257. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  258. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  259. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  260. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  261. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  262. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  263. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  264. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  265. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  266. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  267. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  268. package/node_modules/yaml/dist/test-events.js +134 -0
  269. package/node_modules/yaml/dist/util.d.ts +16 -0
  270. package/node_modules/yaml/dist/util.js +28 -0
  271. package/node_modules/yaml/dist/visit.d.ts +102 -0
  272. package/node_modules/yaml/dist/visit.js +236 -0
  273. package/node_modules/yaml/package.json +97 -0
  274. package/node_modules/yaml/util.js +2 -0
  275. package/node_modules/yauzl/LICENSE +21 -0
  276. package/node_modules/yauzl/README.md +1015 -0
  277. package/node_modules/yauzl/crc32.js +45 -0
  278. package/node_modules/yauzl/fd-slicer.js +188 -0
  279. package/node_modules/yauzl/index.js +1096 -0
  280. package/node_modules/yauzl/package.json +40 -0
  281. package/package-files.mjs +244 -0
  282. package/package-view.mjs +375 -0
  283. package/package.css +131 -0
  284. package/package.json +75 -4
  285. package/removal.mjs +313 -0
  286. package/scripts/build.mjs +19 -0
  287. package/scripts/export-design.py +587 -0
  288. package/scripts/run-tests.mjs +14 -0
  289. package/skill-state.mjs +136 -0
  290. package/skills/skill-creator/SKILL.md +48 -0
  291. package/styles.mjs +10 -0
  292. package/surfaces.css +593 -0
  293. package/test/agent-tool.test.mjs +153 -0
  294. package/test/client-bridge.test.mjs +240 -0
  295. package/test/distribution.test.mjs +17 -0
  296. package/test/host.test.mjs +598 -0
  297. package/test/imports.test.mjs +491 -0
  298. package/test/inventory.test.mjs +144 -0
  299. package/test/library.test.mjs +785 -0
  300. package/test/local-families.test.mjs +220 -0
  301. package/test/management-view.test.mjs +102 -0
  302. package/test/mode-view.test.mjs +26 -0
  303. package/test/package-files.test.mjs +221 -0
  304. package/toolbar.css +228 -0
  305. package/typography.css +173 -0
  306. package/ui.css +399 -0
  307. package/ui.mjs +1545 -0
@@ -0,0 +1,13 @@
1
+ // MarkdownDelegate passes decoded file destinations. Resolve them only within the current package.
2
+ export function packageDocumentLink(documentPath, destination) {
3
+ if (!destination || /^(?:[a-z][a-z\d+.-]*:|\/\/)|[\\\u0000-\u001f\u007f]/iu.test(destination)) return
4
+ const parts = destination.startsWith('/') ? [] : documentPath.split('/').slice(0, -1)
5
+ for (const part of destination.split('/')) {
6
+ if (!part || part === '.') continue
7
+ if (part === '..') {
8
+ if (!parts.length) return
9
+ parts.pop()
10
+ } else parts.push(part)
11
+ }
12
+ return parts.length ? parts.join('/') : undefined
13
+ }
@@ -0,0 +1,62 @@
1
+ import { problem, readRegular } from './import-files.mjs'
2
+ import { verifyResource } from './package-files.mjs'
3
+
4
+ function canReveal(controller) {
5
+ const desktop = controller.workspaceDesktop?.()
6
+ return desktop ? desktop.available && desktop.fileManager !== null : controller.canOpenWorkspacePath()
7
+ }
8
+
9
+ async function canOpenMarkdown(entry, signal) {
10
+ const { bytes } = await readRegular(entry.target, 4096, true)
11
+ await verifyResource(entry, signal)
12
+ let prefix
13
+ try { prefix = new TextDecoder('utf-8', { fatal: true }).decode(bytes, { stream: true }) }
14
+ catch { return false }
15
+ return !!prefix && !/[\u0000-\u0008\u000e-\u001f\u007f]/u.test(prefix) && !/^(#!|\[Desktop Entry\])/u.test(prefix)
16
+ }
17
+
18
+ async function applicationsFor(controller, entry, signal) {
19
+ const applications = await controller.workspacePathApplications?.({ path: entry.target }, signal) ?? []
20
+ await verifyResource(entry, signal)
21
+ return applications.map(({ id, name, default: isDefault }) => ({ id, name, isDefault }))
22
+ }
23
+
24
+ export async function openOptions(controller, resource, signal) {
25
+ const result = { archived: resource?.files.archived ?? false, applications: [], canReveal: false }
26
+ if (!resource || result.archived || !controller.canOpenWorkspacePath()) return result
27
+ const { entry } = resource
28
+ result.canReveal = canReveal(controller)
29
+ if (!await canOpenMarkdown(entry, signal)) return result
30
+ try {
31
+ result.applications = await applicationsFor(controller, entry, signal)
32
+ } catch (error) {
33
+ signal.throwIfAborted()
34
+ if (error.code === 'gateway/bad-request') result.canReveal = false
35
+ else if (error.code !== 'gateway/internal') throw error
36
+ }
37
+ return result
38
+ }
39
+
40
+ export async function openSkillItem(controller, resource, kind, applicationId, signal) {
41
+ if (!resource) throw problem('NO_LOCAL_FILE', '此技能没有可打开的本地 Markdown 说明。')
42
+ if (resource.files.archived) throw problem('ARCHIVED_RESOURCE', '此技能位于应用归档中,请在 DSH 中查看文件。')
43
+ const { entry } = resource
44
+ if (!controller.canOpenWorkspacePath() || (kind === 'directory' && !canReveal(controller))) {
45
+ throw problem('OPEN_UNAVAILABLE', '当前主机没有可用的桌面文件打开服务。')
46
+ }
47
+ const request = { path: entry.target }
48
+ if (kind === 'directory') {
49
+ request.action = 'reveal'
50
+ } else {
51
+ if (!await canOpenMarkdown(entry, signal)) throw problem('NO_LOCAL_FILE', '技能说明的内容不是可打开的 Markdown 文本。')
52
+ if (applicationId !== undefined) {
53
+ const applications = await applicationsFor(controller, entry, signal)
54
+ if (!applications.some(application => application.id === applicationId)) {
55
+ throw problem('APPLICATION_UNAVAILABLE', '此应用已无法打开该文件,请重新查看可用应用。')
56
+ }
57
+ request.application = applicationId
58
+ }
59
+ }
60
+ await verifyResource(entry, signal)
61
+ return controller.openWorkspacePath(request, signal)
62
+ }
package/file-view.mjs ADDED
@@ -0,0 +1,384 @@
1
+ import { controlIcon } from './control-icon.mjs'
2
+
3
+ function sizeLabel(bytes) {
4
+ if (!Number.isFinite(bytes) || bytes < 0) return ''
5
+ const units = ['B', 'KB', 'MB', 'GB', 'TB']
6
+ let amount = bytes
7
+ let unit = 0
8
+ while (amount >= 1024 && unit < units.length - 1) { amount /= 1024; unit++ }
9
+ return `${Number(amount.toFixed(unit && amount < 10 ? 1 : 0))} ${units[unit]}`
10
+ }
11
+
12
+ function fileType(name) {
13
+ const ext = /\.([\p{L}\d]+)$/u.exec(name)?.[1].toLowerCase()
14
+ if (ext === 'md' || ext === 'markdown') return 'Markdown'
15
+ if (ext === 'yml') return 'YAML'
16
+ return ext ? ext.toUpperCase() : '文件'
17
+ }
18
+
19
+ // The owner supplies host operations scoped to the selected resource. A flat skill
20
+ // supplies its entry path with browse disabled and never navigates its parent folder.
21
+ export function createFileView(container, api, { renderMarkdown } = {}) {
22
+ const doc = container.ownerDocument
23
+ const scroller = container.closest('.sm-ui-scroll') || container
24
+
25
+ function el(tag, className, text) {
26
+ const node = doc.createElement(tag)
27
+ if (className) node.className = className
28
+ if (text != null) node.textContent = text
29
+ return node
30
+ }
31
+
32
+ function button(className, text, action) {
33
+ const node = el('button', className, text)
34
+ node.type = 'button'
35
+ node.addEventListener('click', action)
36
+ return node
37
+ }
38
+
39
+ function iconButton(label, icon, action) {
40
+ const node = button('sm-ui-icon-button', '', action)
41
+ node.setAttribute('aria-label', label)
42
+ node.title = label
43
+ node.append(controlIcon(icon, 14))
44
+ return node
45
+ }
46
+
47
+ function rightArrow() {
48
+ const arrow = controlIcon('arrow-left', 12)
49
+ arrow.classList.add('sm-pkg-arrow')
50
+ return arrow
51
+ }
52
+
53
+ const filesPanel = el('div', 'sm-file-view')
54
+ filesPanel.hidden = true
55
+ const rootLocation = el('div', 'sm-pkg-root')
56
+ const rootPath = el('code', 'sm-pkg-root-value')
57
+ rootLocation.append(el('span', 'sm-pkg-root-label', '根路径'), rootPath)
58
+ const navigation = el('nav', 'sm-pkg-path')
59
+ navigation.setAttribute('aria-label', '文件路径')
60
+ const up = iconButton('返回上一级目录', 'arrow-left', goUp)
61
+ up.setAttribute('aria-keyshortcuts', 'Escape Alt+ArrowUp')
62
+ up.title = '返回上一级目录(Esc)'
63
+ const crumbs = el('ol', 'sm-pkg-crumbs')
64
+ navigation.append(up, crumbs)
65
+ const fileList = el('ul', 'sm-pkg-list')
66
+ fileList.setAttribute('aria-label', '目录内容')
67
+ const preview = el('section', 'sm-pkg-preview')
68
+ preview.setAttribute('aria-label', '文件预览')
69
+ const fileNote = el('p', 'sm-pkg-note')
70
+ fileNote.setAttribute('role', 'status')
71
+ const retryBox = el('div', 'sm-ui-warning')
72
+ const reason = el('span')
73
+ reason.setAttribute('role', 'alert')
74
+ const retry = button('sm-ui-text-action', '重试', () => readLocation())
75
+ retryBox.append(reason, retry)
76
+ const more = button('sm-ui-button sm-pkg-more', '加载更多', () => readLocation())
77
+ filesPanel.append(rootLocation, navigation, fileList, preview, fileNote, retryBox, more)
78
+ container.append(filesPanel)
79
+
80
+ let resource = null
81
+ let path = ''
82
+ let file = null
83
+ let markdown = null
84
+ let pending = false
85
+ let request = 0
86
+ let disposed = false
87
+ const folders = new Map()
88
+ const positions = new Map()
89
+ const documentPositions = new Map()
90
+ const entryButtons = new Map()
91
+ const currentCrumb = () => crumbs.lastElementChild?.lastElementChild
92
+
93
+ function screenKey() {
94
+ return file ? `file:${file.path}` : `directory:${path}`
95
+ }
96
+
97
+ function saveScroll() {
98
+ // A pending preview can be shorter than the document previously read here.
99
+ const waiting = file && (!file.data || (markdown && !markdown.region))
100
+ if (waiting && positions.has(screenKey())) return
101
+ positions.set(screenKey(), scroller.scrollTop)
102
+ }
103
+ function restoreScroll() { scroller.scrollTop = positions.get(screenKey()) || 0 }
104
+
105
+ function unmountMarkdown() {
106
+ if (!markdown) return
107
+ const { filePath, region, dispose } = markdown
108
+ markdown = null
109
+ if (region) documentPositions.set(filePath, region.scrollTop)
110
+ dispose?.()
111
+ }
112
+
113
+ function invalidate() {
114
+ request++
115
+ pending = false
116
+ unmountMarkdown()
117
+ }
118
+
119
+ function directory() {
120
+ if (!folders.has(path)) folders.set(path, { entries: [], loaded: false, next: 0, error: '' })
121
+ return folders.get(path)
122
+ }
123
+
124
+ function openLocation(nextPath, nextFile = null) {
125
+ if (!resource.browse) return
126
+ if (nextPath === path && nextFile?.path === file?.path) return
127
+ const previous = file?.path || path
128
+ const prefix = nextPath ? `${nextPath}/` : ''
129
+ const child = !nextFile && previous.startsWith(prefix) && previous !== nextPath
130
+ ? prefix + previous.slice(prefix.length).split('/')[0] : undefined
131
+ saveScroll()
132
+ invalidate()
133
+ path = nextPath
134
+ file = nextFile ? { ...nextFile, data: null, error: '' } : null
135
+ showLocation(child)
136
+ restoreScroll()
137
+ const target = entryButtons.get(child) || currentCrumb()
138
+ target?.focus({ preventScroll: true })
139
+ }
140
+
141
+ function goUp() {
142
+ if (file) openLocation(path)
143
+ else if (path) openLocation(path.split('/').slice(0, -1).join('/'))
144
+ }
145
+
146
+ filesPanel.addEventListener('keydown', event => {
147
+ if (!resource?.browse || (!file && !path) || event.defaultPrevented || event.isComposing) return
148
+ if (event.key === 'Escape' || (event.altKey && event.key === 'ArrowUp')) {
149
+ event.preventDefault()
150
+ event.stopPropagation()
151
+ goUp()
152
+ }
153
+ })
154
+
155
+ function renderCrumbs() {
156
+ const chain = []
157
+ if (resource.browse) {
158
+ chain.push({ name: '根目录', path: '' })
159
+ for (const name of path.split('/').filter(Boolean)) {
160
+ chain.push({ name, path: [chain.at(-1).path, name].filter(Boolean).join('/') })
161
+ }
162
+ }
163
+ if (file) chain.push(file)
164
+ crumbs.replaceChildren(...chain.map((part, index) => {
165
+ const li = el('li')
166
+ const current = index === chain.length - 1
167
+ const segment = current ? el('span', '', part.name) : button('sm-pkg-crumb', part.name, () => openLocation(part.path))
168
+ if (current) { segment.setAttribute('aria-current', 'page'); segment.tabIndex = -1 }
169
+ segment.title = part.path || resource.root || '根目录'
170
+ li.append(segment)
171
+ return li
172
+ }))
173
+ up.hidden = !resource.browse || (!path && !file)
174
+ }
175
+
176
+ function entryRow(entry) {
177
+ const row = el('li')
178
+ const link = entry.kind === 'link'
179
+ const isDirectory = entry.kind === 'directory'
180
+ const node = link ? el('div', 'sm-pkg-row sm-pkg-link') : button('sm-pkg-row', '', () => {
181
+ if (isDirectory) openLocation(entry.path)
182
+ else openLocation(path, entry)
183
+ })
184
+ if (!link) entryButtons.set(entry.path, node)
185
+ const kind = link ? '符号链接' : isDirectory ? '目录' : fileType(entry.name)
186
+ const meta = [kind, entry.kind === 'file' ? sizeLabel(entry.size) : ''].filter(Boolean).join(' · ')
187
+ node.append(controlIcon(link ? 'link' : isDirectory ? 'folder' : 'file', 16), el('span', 'sm-pkg-entry-name', entry.name), el('span', 'sm-pkg-entry-meta', meta))
188
+ if (!link) node.append(rightArrow())
189
+ row.append(node)
190
+ return row
191
+ }
192
+
193
+ function mountMarkdown(content, label, previousTop) {
194
+ const target = el('div', 'sm-document-scroll')
195
+ preview.append(target)
196
+ const view = { filePath: file.path, region: null, dispose: null }
197
+ markdown = view
198
+ const loadingTop = scroller.scrollTop
199
+ view.dispose = renderMarkdown(target, content, {
200
+ label, filePath: view.filePath, packageId: resource.id,
201
+ onReady(region) {
202
+ if (markdown !== view || view.region === region) return
203
+ view.region = region
204
+ region.scrollTop = documentPositions.get(view.filePath) || 0
205
+ if (previousTop && scroller.scrollTop === loadingTop) scroller.scrollTop = previousTop
206
+ },
207
+ onOpenFile: resource.browse ? relativePath => {
208
+ if (markdown !== view) return
209
+ const parts = relativePath.split('/')
210
+ const name = parts.pop()
211
+ openLocation(parts.join('/'), { name, path: relativePath })
212
+ } : undefined,
213
+ })
214
+ }
215
+
216
+ function renderPreview(previousTop) {
217
+ unmountMarkdown()
218
+ preview.replaceChildren()
219
+ if (!file?.data) return
220
+ preview.hidden = false
221
+ const { kind, content, size, truncated } = file.data
222
+ const type = fileType(file.name)
223
+ const labels = [type]
224
+ if (kind === 'binary') labels.push('二进制文件')
225
+ labels.push(sizeLabel(size))
226
+ if (truncated) labels.push('仅显示开头部分')
227
+ preview.append(el('p', 'sm-pkg-file-meta', labels.filter(Boolean).join(' · ')))
228
+ if (kind === 'text' && content) {
229
+ const label = `${file.name} 正文`
230
+ if (type === 'Markdown' && renderMarkdown) {
231
+ try {
232
+ mountMarkdown(content, label, previousTop)
233
+ } catch (error) {
234
+ unmountMarkdown()
235
+ file.data = null
236
+ file.error = error?.message || String(error || '预览失败,请重试。')
237
+ }
238
+ return
239
+ }
240
+ const body = el('pre', 'sm-pkg-file-text', content)
241
+ body.tabIndex = 0
242
+ body.setAttribute('aria-label', label)
243
+ preview.append(body)
244
+ } else if (kind === 'text') preview.append(el('p', 'sm-pkg-note', '文件为空。'))
245
+ }
246
+
247
+ function renderReadState() {
248
+ const state = file || directory()
249
+ fileList.hidden = !!file || !resource.browse
250
+ preview.hidden = !file?.data
251
+ fileList.setAttribute('aria-busy', String(!file && pending))
252
+ preview.setAttribute('aria-busy', String(!!file && pending))
253
+ more.hidden = !!file || !state.loaded || state.next === null || !!state.error
254
+ more.setAttribute('aria-disabled', String(pending))
255
+ retryBox.hidden = !state.error
256
+ retry.setAttribute('aria-disabled', String(pending))
257
+ if (reason.textContent !== state.error) reason.textContent = state.error
258
+ fileNote.textContent = pending ? (file ? '正在读取文件…' : '正在读取目录…')
259
+ : !file && state.loaded && !state.entries.length ? '目录为空。' : ''
260
+ fileNote.hidden = !fileNote.textContent
261
+ }
262
+
263
+ function showLocation(focusPath) {
264
+ if (rootPath.textContent !== (resource.root || '')) rootPath.textContent = resource.root || ''
265
+ rootLocation.hidden = !resource.root
266
+ renderCrumbs()
267
+ entryButtons.clear()
268
+ fileList.replaceChildren(...(file ? [] : directory().entries.map(entryRow)))
269
+ renderPreview(positions.get(screenKey()))
270
+ renderReadState()
271
+ const state = file || directory()
272
+ if ((file || resource.browse) && !state.error && !(file ? file.data : state.loaded)) void readLocation(focusPath)
273
+ }
274
+
275
+ async function readLocation(focusPath) {
276
+ if (pending || disposed || filesPanel.hidden) return
277
+ const state = file || directory()
278
+ if (!file && state.next === null) return
279
+ const version = ++request
280
+ let firstAddedButton
281
+ pending = true
282
+ renderReadState()
283
+ const previousTop = file && positions.get(screenKey())
284
+ if (previousTop) scroller.scrollTop = previousTop
285
+ const loadingTop = scroller.scrollTop
286
+ let resumeReading = false
287
+ try {
288
+ if (file) {
289
+ const result = await api.file(file.path)
290
+ if (version !== request) return
291
+ resumeReading = previousTop > 0 && scroller.scrollTop === loadingTop
292
+ state.error = ''
293
+ state.data = result
294
+ renderPreview(resumeReading ? previousTop : undefined)
295
+ } else {
296
+ const result = await api.entries(path, state.next)
297
+ if (version !== request) return
298
+ if (result.root && result.root !== resource.root) {
299
+ resource.root = result.root
300
+ rootPath.textContent = result.root
301
+ rootLocation.hidden = false
302
+ }
303
+ const existing = new Set(state.entries.map(entry => entry.path))
304
+ const added = []
305
+ for (const entry of result.entries) if (!existing.has(entry.path)) {
306
+ existing.add(entry.path)
307
+ state.entries.push(entry)
308
+ added.push(entryRow(entry))
309
+ }
310
+ state.loaded = true
311
+ state.next = result.nextOffset
312
+ fileList.append(...added)
313
+ firstAddedButton = added.find(row => row.firstElementChild?.tagName === 'BUTTON')?.firstElementChild
314
+ state.error = ''
315
+ }
316
+ } catch (error) {
317
+ if (version !== request) return
318
+ state.error = error?.message || String(error || '读取失败,请重试。')
319
+ } finally {
320
+ if (version === request) {
321
+ pending = false
322
+ const active = doc.activeElement
323
+ renderReadState()
324
+ if (resumeReading && !markdown) scroller.scrollTop = previousTop
325
+ if (active === more || active === retry) {
326
+ const target = state.error ? retry : firstAddedButton || (more.hidden ? currentCrumb() : more)
327
+ target?.focus({ preventScroll: true })
328
+ } else if (focusPath && active === currentCrumb()) {
329
+ entryButtons.get(focusPath)?.focus({ preventScroll: true })
330
+ }
331
+ }
332
+ }
333
+ }
334
+
335
+ function hide() {
336
+ if (filesPanel.hidden) return
337
+ saveScroll()
338
+ invalidate()
339
+ filesPanel.hidden = true
340
+ }
341
+
342
+ function show({ id, root, file: entry, browse = !!api.entries, reset = false, focus = false }) {
343
+ if (disposed) return
344
+ const fresh = !resource || resource.id !== id || resource.browse !== browse || resource.suppliedRoot !== root || reset
345
+ const entering = filesPanel.hidden
346
+ if (fresh) {
347
+ invalidate()
348
+ resource = { id, root, suppliedRoot: root, browse }
349
+ folders.clear()
350
+ positions.clear()
351
+ documentPositions.clear()
352
+ path = ''
353
+ file = null
354
+ }
355
+ filesPanel.hidden = false
356
+ const opening = entry && entry !== file?.path
357
+ if (opening) {
358
+ if (!fresh && !entering) {
359
+ saveScroll()
360
+ invalidate()
361
+ }
362
+ const parts = entry.split('/')
363
+ file = { name: parts.pop(), path: entry, data: null, error: '' }
364
+ path = parts.join('/')
365
+ }
366
+ if (fresh || entering || opening) {
367
+ showLocation()
368
+ restoreScroll()
369
+ }
370
+ if (focus) currentCrumb()?.focus({ preventScroll: true })
371
+ }
372
+
373
+ function dispose() {
374
+ hide()
375
+ disposed = true
376
+ folders.clear()
377
+ positions.clear()
378
+ documentPositions.clear()
379
+ entryButtons.clear()
380
+ filesPanel.remove()
381
+ }
382
+
383
+ return { show, hide, dispose }
384
+ }
@@ -0,0 +1,90 @@
1
+ .sm-ui-scroll:has(.sm-ui-page[data-view="list"] .sm-ui-header-bar) {
2
+ overflow-x: hidden;
3
+ scroll-padding-block-start: var(--sm-header-scroll-padding, 0px);
4
+ }
5
+
6
+ /* Let the header span the complete panel and keep the list in its own centered column. */
7
+ .sm-ui-library > .sm-ui-header-bar {
8
+ --sm-header-inset: 28px;
9
+ --sm-header-compact-inset: 16px;
10
+ container: sm-library / inline-size;
11
+ position: sticky;
12
+ top: 0;
13
+ z-index: 2;
14
+ inline-size: var(--sm-header-viewport, 100%);
15
+ min-block-size: 0;
16
+ margin-inline: calc((100% - var(--sm-header-available, 100%)) / 2);
17
+ padding-inline: var(--sm-page-gutter);
18
+ pointer-events: none;
19
+ overflow-anchor: none;
20
+ }
21
+ .sm-ui-library > .sm-ui-header-bar:has(> [data-sm-header-live]) { block-size: 0; }
22
+
23
+ [data-platform="darwin"] .sm-ui-header-bar {
24
+ --sm-header-inset: calc(28px + var(--dsh-frame-top-clearance, 0px));
25
+ }
26
+
27
+ [data-platform="darwin"] [data-sidebar-collapsed] .sm-ui-header-bar {
28
+ --sm-header-compact-inset: calc(8px + var(--dsh-frame-top-clearance, 0px));
29
+ }
30
+
31
+ .sm-ui-header-bar > .sm-pen-header {
32
+ inline-size: 100%;
33
+ max-inline-size: 960px;
34
+ min-block-size: 0;
35
+ margin-inline: auto;
36
+ padding-block-start: var(--sm-header-inset);
37
+ gap: 16px;
38
+ pointer-events: auto;
39
+ }
40
+
41
+ @container sm-library (width < 600px) {
42
+ .sm-ui-header-bar > .sm-pen-header { align-items: center; }
43
+ }
44
+
45
+ .sm-ui-header-bar > [data-sm-header-probe] {
46
+ position: absolute;
47
+ inset: 0 auto auto 0;
48
+ visibility: hidden;
49
+ pointer-events: none;
50
+ }
51
+
52
+ .sm-ui-header-bar > [data-sm-header-probe][data-compact] {
53
+ align-items: center;
54
+ padding-block: var(--sm-header-compact-inset) 16px;
55
+ }
56
+
57
+ [data-sm-header-probe][data-compact] [data-part="heading"] { display: none; }
58
+ [data-sm-header-probe][data-compact] .sm-ui-tab-row {
59
+ order: -1;
60
+ flex: 1 1 0;
61
+ min-inline-size: min(202px, 100%);
62
+ max-inline-size: 364px;
63
+ }
64
+ [data-sm-header-probe][data-compact] .sm-ui-tabs { inline-size: 100%; }
65
+
66
+ .sm-ui-header-bar::before {
67
+ content: '';
68
+ position: absolute;
69
+ inset: 0 0 auto;
70
+ block-size: var(--sm-header-paint, 100%);
71
+ background: var(--dsw-alias-bg-base, var(--sm-bg));
72
+ pointer-events: none;
73
+ }
74
+ .sm-ui-header-bar[data-compact]::before { border-block-end: 0.5px solid var(--dsw-alias-border-l3, var(--sm-line)); }
75
+
76
+ /* Only the painted height is a native window-drag region or pointer target. */
77
+ .sm-ui-header-bar > [data-sm-header-live] {
78
+ position: relative;
79
+ block-size: var(--sm-header-paint);
80
+ padding: 0;
81
+ clip-path: inset(0);
82
+ }
83
+ .sm-pen-header[data-sm-header-live] .sm-ui-tab-row { display: contents; }
84
+ .sm-pen-header[data-sm-header-live] :is([data-part="heading"], [data-part="actions"], .sm-ui-tabs) {
85
+ position: absolute;
86
+ inset: 0 auto auto 0;
87
+ inline-size: var(--sm-header-width);
88
+ margin: 0;
89
+ translate: var(--sm-header-position);
90
+ }
@@ -0,0 +1,121 @@
1
+ const partSelectors = ['[data-part="heading"]', '[data-part="actions"]', '.sm-ui-tabs']
2
+
3
+ function snapshot(header, elements) {
4
+ const frame = header.getBoundingClientRect()
5
+ return {
6
+ height: frame.height,
7
+ parts: elements.map(element => {
8
+ const box = element.getBoundingClientRect()
9
+ return { x: box.left - frame.left, y: box.top - frame.top, width: box.width, height: box.height }
10
+ }),
11
+ }
12
+ }
13
+
14
+ /** Keep the list's resting height while the same buttons and tabs move into the sticky row. */
15
+ export function attachHeaderScroll(scroller, header, signal) {
16
+ if (signal.aborted) return
17
+ const doc = header.ownerDocument
18
+ const win = doc.defaultView
19
+ const list = header.parentElement
20
+ const elements = partSelectors.map(selector => header.querySelector(selector))
21
+ if (!list || elements.some(element => !element)) return
22
+
23
+ const bar = doc.createElement('div')
24
+ bar.className = 'sm-ui-header-bar'
25
+ const spacer = doc.createElement('div')
26
+ spacer.setAttribute('aria-hidden', 'true')
27
+ header.before(bar, spacer)
28
+ bar.append(header)
29
+
30
+ let resting, compact, travel
31
+ let pending = 0
32
+ let lastOffset = -1
33
+
34
+ function paint() {
35
+ if (!resting || list.hidden) return
36
+ const offset = Math.min(travel, Math.max(0, scroller.scrollTop))
37
+ if (offset === lastOffset) return
38
+ lastOffset = offset
39
+ bar.toggleAttribute('data-compact', offset >= travel)
40
+ bar.style.setProperty('--sm-header-paint', `${Math.max(compact.height, resting.height - offset)}px`)
41
+ elements.forEach((element, index) => {
42
+ const from = resting.parts[index]
43
+ const to = compact.parts[index]
44
+ const progress = Math.min(1, offset / Math.max(1, Math.abs(to.y - from.y)))
45
+ const x = from.x + (to.x - from.x) * progress
46
+ const y = from.y + (to.y - from.y) * progress
47
+ const width = from.width + (to.width - from.width) * progress
48
+ element.style.setProperty('--sm-header-position', `${x}px ${y}px`)
49
+ element.style.setProperty('--sm-header-width', `${width}px`)
50
+ })
51
+ }
52
+
53
+ function measure() {
54
+ pending = 0
55
+ if (signal.aborted || list.hidden || !scroller.clientWidth) return
56
+ // The native header includes the classic scrollbar in its centering width. The list does not.
57
+ bar.style.setProperty('--sm-header-viewport', `${scroller.offsetWidth}px`)
58
+ bar.style.setProperty('--sm-header-available', `${scroller.clientWidth}px`)
59
+
60
+ const probe = header.cloneNode(true)
61
+ probe.removeAttribute('data-sm-header-live')
62
+ probe.removeAttribute('data-window-drag')
63
+ probe.setAttribute('data-sm-header-probe', '')
64
+ probe.setAttribute('aria-hidden', 'true')
65
+ probe.inert = true
66
+ for (const node of probe.querySelectorAll('[id]')) node.removeAttribute('id')
67
+ probe.style.inlineSize = `${header.getBoundingClientRect().width}px`
68
+ bar.append(probe)
69
+ try {
70
+ const copies = partSelectors.map(selector => probe.querySelector(selector))
71
+ resting = snapshot(probe, copies)
72
+ probe.setAttribute('data-compact', '')
73
+ compact = snapshot(probe, copies)
74
+ } finally {
75
+ probe.remove()
76
+ }
77
+
78
+ const heading = resting.parts[0]
79
+ compact.parts[0] = { ...heading, y: -heading.height }
80
+ travel = Math.max(1, resting.height - compact.height,
81
+ ...resting.parts.map((from, index) => Math.abs(compact.parts[index].y - from.y)))
82
+ // The spacer preserves list flow without pulling a tall sticky box upward at the end of a short window.
83
+ spacer.style.height = `${resting.height}px`
84
+ scroller.style.setProperty('--sm-header-scroll-padding', `${compact.height + 8}px`)
85
+ header.setAttribute('data-sm-header-live', '')
86
+ lastOffset = -1
87
+ paint()
88
+ }
89
+
90
+ function scheduleMeasure() {
91
+ if (!pending && !signal.aborted) pending = win.requestAnimationFrame(measure)
92
+ }
93
+
94
+ const resize = new win.ResizeObserver(scheduleMeasure)
95
+ resize.observe(scroller)
96
+ const changes = new win.MutationObserver(scheduleMeasure)
97
+ changes.observe(header, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ['hidden', 'aria-busy'] })
98
+ changes.observe(list, { attributes: true, attributeFilter: ['hidden'] })
99
+ changes.observe(list.parentElement, { attributes: true, attributeFilter: ['data-view'] })
100
+ // A loaded system font or the macOS traffic-light inset can change without resizing the scrollport.
101
+ for (let ancestor = scroller.parentElement; ancestor; ancestor = ancestor.parentElement) {
102
+ changes.observe(ancestor, { attributes: true, attributeFilter: ['style', 'class', 'data-platform', 'data-sidebar-collapsed'] })
103
+ }
104
+ scroller.addEventListener('scroll', paint, { passive: true, signal })
105
+ win.addEventListener('resize', scheduleMeasure, { signal })
106
+ doc.fonts?.addEventListener('loadingdone', scheduleMeasure, { signal })
107
+ signal.addEventListener('abort', () => {
108
+ resize.disconnect()
109
+ changes.disconnect()
110
+ win.cancelAnimationFrame(pending)
111
+ scroller.style.removeProperty('--sm-header-scroll-padding')
112
+ header.removeAttribute('data-sm-header-live')
113
+ for (const element of elements) {
114
+ element.style.removeProperty('--sm-header-position')
115
+ element.style.removeProperty('--sm-header-width')
116
+ }
117
+ bar.replaceWith(header)
118
+ spacer.remove()
119
+ }, { once: true })
120
+ measure()
121
+ }