obsidian-plugin-dev-kit 0.0.0-stage → 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 (329) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +223 -2
  3. package/bin/opdk.js +34 -0
  4. package/dist/build/args.d.ts +10 -0
  5. package/dist/build/args.js +45 -0
  6. package/dist/build/bundle-check.d.ts +17 -0
  7. package/dist/build/bundle-check.js +42 -0
  8. package/dist/build/bundle-file.d.ts +4 -0
  9. package/dist/build/bundle-file.js +29 -0
  10. package/dist/build/commands.d.ts +5 -0
  11. package/dist/build/commands.js +109 -0
  12. package/dist/build/config.d.ts +3 -0
  13. package/dist/build/config.js +103 -0
  14. package/dist/build/css-imports.d.ts +23 -0
  15. package/dist/build/css-imports.js +50 -0
  16. package/dist/build/css-step.d.ts +10 -0
  17. package/dist/build/css-step.js +27 -0
  18. package/dist/build/css.d.ts +24 -0
  19. package/dist/build/css.js +47 -0
  20. package/dist/build/options.d.ts +55 -0
  21. package/dist/build/options.js +70 -0
  22. package/dist/build/release.d.ts +5 -0
  23. package/dist/build/release.js +34 -0
  24. package/dist/build/report.d.ts +7 -0
  25. package/dist/build/report.js +16 -0
  26. package/dist/build/vault.d.ts +26 -0
  27. package/dist/build/vault.js +290 -0
  28. package/dist/build-info.json +1 -0
  29. package/dist/cli/argv.d.ts +14 -0
  30. package/dist/cli/argv.js +18 -0
  31. package/dist/cli/commands.d.ts +3 -0
  32. package/dist/cli/commands.js +7 -0
  33. package/dist/cli/main.d.ts +2 -0
  34. package/dist/cli/main.js +23 -0
  35. package/dist/cli/process-reporter.d.ts +5 -0
  36. package/dist/cli/process-reporter.js +15 -0
  37. package/dist/cli/registry.d.ts +4 -0
  38. package/dist/cli/registry.js +15 -0
  39. package/dist/cli/reporter.d.ts +53 -0
  40. package/dist/cli/reporter.js +100 -0
  41. package/dist/cli/run.d.ts +9 -0
  42. package/dist/cli/run.js +61 -0
  43. package/dist/cli/types.d.ts +27 -0
  44. package/dist/cli/types.js +1 -0
  45. package/dist/cli/version.d.ts +13 -0
  46. package/dist/cli/version.js +61 -0
  47. package/dist/config/define-config.d.ts +3 -0
  48. package/dist/config/define-config.js +4 -0
  49. package/dist/config/load-config.d.ts +6 -0
  50. package/dist/config/load-config.js +70 -0
  51. package/dist/config/manifest.d.ts +3 -0
  52. package/dist/config/manifest.js +72 -0
  53. package/dist/config/types.d.ts +146 -0
  54. package/dist/config/types.js +23 -0
  55. package/dist/demo/args.d.ts +4 -0
  56. package/dist/demo/args.js +13 -0
  57. package/dist/demo/checks.d.ts +56 -0
  58. package/dist/demo/checks.js +124 -0
  59. package/dist/demo/commands.d.ts +3 -0
  60. package/dist/demo/commands.js +65 -0
  61. package/dist/demo/config.d.ts +57 -0
  62. package/dist/demo/config.js +337 -0
  63. package/dist/demo/ffmpeg-run.d.ts +18 -0
  64. package/dist/demo/ffmpeg-run.js +59 -0
  65. package/dist/demo/ffmpeg.d.ts +63 -0
  66. package/dist/demo/ffmpeg.js +111 -0
  67. package/dist/demo/films.d.ts +46 -0
  68. package/dist/demo/films.js +134 -0
  69. package/dist/demo/phone-layout.d.ts +38 -0
  70. package/dist/demo/phone-layout.js +98 -0
  71. package/dist/demo/phone-render.d.ts +28 -0
  72. package/dist/demo/phone-render.js +124 -0
  73. package/dist/demo/published.d.ts +16 -0
  74. package/dist/demo/published.js +72 -0
  75. package/dist/demo/run.d.ts +31 -0
  76. package/dist/demo/run.js +397 -0
  77. package/dist/demo/stills.d.ts +21 -0
  78. package/dist/demo/stills.js +62 -0
  79. package/dist/e2e/artifacts.d.ts +27 -0
  80. package/dist/e2e/artifacts.js +90 -0
  81. package/dist/e2e/cleanup.d.ts +54 -0
  82. package/dist/e2e/cleanup.js +109 -0
  83. package/dist/e2e/config.d.ts +9 -0
  84. package/dist/e2e/config.js +42 -0
  85. package/dist/e2e/create-test.d.ts +37 -0
  86. package/dist/e2e/create-test.js +109 -0
  87. package/dist/e2e/demo/clip.d.ts +21 -0
  88. package/dist/e2e/demo/clip.js +44 -0
  89. package/dist/e2e/demo/create-demo.d.ts +42 -0
  90. package/dist/e2e/demo/create-demo.js +439 -0
  91. package/dist/e2e/demo/manifest.d.ts +76 -0
  92. package/dist/e2e/demo/manifest.js +168 -0
  93. package/dist/e2e/demo/names.d.ts +18 -0
  94. package/dist/e2e/demo/names.js +44 -0
  95. package/dist/e2e/demo/options.d.ts +22 -0
  96. package/dist/e2e/demo/options.js +59 -0
  97. package/dist/e2e/demo/ownership.d.ts +27 -0
  98. package/dist/e2e/demo/ownership.js +65 -0
  99. package/dist/e2e/demo/page-scripts.d.ts +82 -0
  100. package/dist/e2e/demo/page-scripts.js +250 -0
  101. package/dist/e2e/demo/png.d.ts +8 -0
  102. package/dist/e2e/demo/png.js +23 -0
  103. package/dist/e2e/demo/presets.d.ts +43 -0
  104. package/dist/e2e/demo/presets.js +20 -0
  105. package/dist/e2e/demo/privacy.d.ts +18 -0
  106. package/dist/e2e/demo/privacy.js +30 -0
  107. package/dist/e2e/demo/still-options.d.ts +22 -0
  108. package/dist/e2e/demo/still-options.js +68 -0
  109. package/dist/e2e/demo/types.d.ts +184 -0
  110. package/dist/e2e/demo/types.js +1 -0
  111. package/dist/e2e/electron-binary.d.ts +15 -0
  112. package/dist/e2e/electron-binary.js +30 -0
  113. package/dist/e2e/fixtures.d.ts +62 -0
  114. package/dist/e2e/fixtures.js +68 -0
  115. package/dist/e2e/gate.d.ts +4 -0
  116. package/dist/e2e/gate.js +8 -0
  117. package/dist/e2e/global-setup.d.ts +11 -0
  118. package/dist/e2e/global-setup.js +17 -0
  119. package/dist/e2e/helpers/commands.d.ts +14 -0
  120. package/dist/e2e/helpers/commands.js +56 -0
  121. package/dist/e2e/helpers/create-helpers.d.ts +24 -0
  122. package/dist/e2e/helpers/create-helpers.js +582 -0
  123. package/dist/e2e/helpers/device-metrics.d.ts +21 -0
  124. package/dist/e2e/helpers/device-metrics.js +25 -0
  125. package/dist/e2e/helpers/ime.d.ts +13 -0
  126. package/dist/e2e/helpers/ime.js +19 -0
  127. package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
  128. package/dist/e2e/helpers/layout-page-scripts.js +224 -0
  129. package/dist/e2e/helpers/layout.d.ts +83 -0
  130. package/dist/e2e/helpers/layout.js +148 -0
  131. package/dist/e2e/helpers/mobile.d.ts +31 -0
  132. package/dist/e2e/helpers/mobile.js +26 -0
  133. package/dist/e2e/helpers/page-scripts.d.ts +194 -0
  134. package/dist/e2e/helpers/page-scripts.js +467 -0
  135. package/dist/e2e/helpers/settings.d.ts +8 -0
  136. package/dist/e2e/helpers/settings.js +16 -0
  137. package/dist/e2e/helpers/settle.d.ts +28 -0
  138. package/dist/e2e/helpers/settle.js +33 -0
  139. package/dist/e2e/helpers/types.d.ts +193 -0
  140. package/dist/e2e/helpers/types.js +1 -0
  141. package/dist/e2e/helpers/view-mode.d.ts +23 -0
  142. package/dist/e2e/helpers/view-mode.js +35 -0
  143. package/dist/e2e/index.d.ts +14 -0
  144. package/dist/e2e/index.js +4 -0
  145. package/dist/e2e/internals.d.ts +155 -0
  146. package/dist/e2e/internals.js +8 -0
  147. package/dist/e2e/obsidian-path.d.ts +17 -0
  148. package/dist/e2e/obsidian-path.js +31 -0
  149. package/dist/e2e/options.d.ts +123 -0
  150. package/dist/e2e/options.js +244 -0
  151. package/dist/e2e/page-scripts.d.ts +45 -0
  152. package/dist/e2e/page-scripts.js +53 -0
  153. package/dist/e2e/peers.d.ts +9 -0
  154. package/dist/e2e/peers.js +19 -0
  155. package/dist/e2e/plugins.d.ts +32 -0
  156. package/dist/e2e/plugins.js +119 -0
  157. package/dist/e2e/process-tree.d.ts +33 -0
  158. package/dist/e2e/process-tree.js +133 -0
  159. package/dist/e2e/readiness.d.ts +23 -0
  160. package/dist/e2e/readiness.js +63 -0
  161. package/dist/e2e/seed.d.ts +34 -0
  162. package/dist/e2e/seed.js +122 -0
  163. package/dist/e2e/session.d.ts +71 -0
  164. package/dist/e2e/session.js +266 -0
  165. package/dist/e2e/vault.d.ts +52 -0
  166. package/dist/e2e/vault.js +146 -0
  167. package/dist/e2e/version.d.ts +25 -0
  168. package/dist/e2e/version.js +40 -0
  169. package/dist/eslint/index.d.ts +2 -0
  170. package/dist/eslint/index.js +1 -0
  171. package/dist/eslint/obsidian-plugin.d.ts +49 -0
  172. package/dist/eslint/obsidian-plugin.js +115 -0
  173. package/dist/index.d.ts +3 -0
  174. package/dist/index.js +1 -0
  175. package/dist/kit/args.d.ts +7 -0
  176. package/dist/kit/args.js +21 -0
  177. package/dist/kit/commands.d.ts +3 -0
  178. package/dist/kit/commands.js +52 -0
  179. package/dist/kit/files.d.ts +3 -0
  180. package/dist/kit/files.js +24 -0
  181. package/dist/kit/pins.d.ts +89 -0
  182. package/dist/kit/pins.js +178 -0
  183. package/dist/kit/remote.d.ts +13 -0
  184. package/dist/kit/remote.js +33 -0
  185. package/dist/kit/runners.d.ts +11 -0
  186. package/dist/kit/runners.js +53 -0
  187. package/dist/kit/terminal-text.d.ts +6 -0
  188. package/dist/kit/terminal-text.js +20 -0
  189. package/dist/kit/upgrade.d.ts +26 -0
  190. package/dist/kit/upgrade.js +162 -0
  191. package/dist/peers/resolve.d.ts +8 -0
  192. package/dist/peers/resolve.js +28 -0
  193. package/dist/peers/versions.d.ts +30 -0
  194. package/dist/peers/versions.js +32 -0
  195. package/dist/release/api-check.d.ts +27 -0
  196. package/dist/release/api-check.js +119 -0
  197. package/dist/release/args.d.ts +40 -0
  198. package/dist/release/args.js +120 -0
  199. package/dist/release/assets.d.ts +21 -0
  200. package/dist/release/assets.js +35 -0
  201. package/dist/release/build-check.d.ts +43 -0
  202. package/dist/release/build-check.js +184 -0
  203. package/dist/release/build-script.d.ts +12 -0
  204. package/dist/release/build-script.js +30 -0
  205. package/dist/release/build-tagged.d.ts +26 -0
  206. package/dist/release/build-tagged.js +52 -0
  207. package/dist/release/bump.d.ts +24 -0
  208. package/dist/release/bump.js +58 -0
  209. package/dist/release/changelog.d.ts +25 -0
  210. package/dist/release/changelog.js +148 -0
  211. package/dist/release/check.d.ts +38 -0
  212. package/dist/release/check.js +150 -0
  213. package/dist/release/commands.d.ts +3 -0
  214. package/dist/release/commands.js +154 -0
  215. package/dist/release/committed-tree.d.ts +63 -0
  216. package/dist/release/committed-tree.js +118 -0
  217. package/dist/release/config.d.ts +3 -0
  218. package/dist/release/config.js +28 -0
  219. package/dist/release/gh-access.d.ts +14 -0
  220. package/dist/release/gh-access.js +45 -0
  221. package/dist/release/gh.d.ts +10 -0
  222. package/dist/release/gh.js +33 -0
  223. package/dist/release/git.d.ts +49 -0
  224. package/dist/release/git.js +111 -0
  225. package/dist/release/interrupt.d.ts +30 -0
  226. package/dist/release/interrupt.js +60 -0
  227. package/dist/release/json.d.ts +33 -0
  228. package/dist/release/json.js +81 -0
  229. package/dist/release/kit-check.d.ts +8 -0
  230. package/dist/release/kit-check.js +51 -0
  231. package/dist/release/manifest-rules.d.ts +23 -0
  232. package/dist/release/manifest-rules.js +255 -0
  233. package/dist/release/preflight.d.ts +10 -0
  234. package/dist/release/preflight.js +65 -0
  235. package/dist/release/problems.d.ts +24 -0
  236. package/dist/release/problems.js +11 -0
  237. package/dist/release/project-files.d.ts +14 -0
  238. package/dist/release/project-files.js +16 -0
  239. package/dist/release/publish-command.d.ts +21 -0
  240. package/dist/release/publish-command.js +83 -0
  241. package/dist/release/publish-git.d.ts +37 -0
  242. package/dist/release/publish-git.js +108 -0
  243. package/dist/release/publish-state.d.ts +29 -0
  244. package/dist/release/publish-state.js +70 -0
  245. package/dist/release/publish-verify.d.ts +41 -0
  246. package/dist/release/publish-verify.js +112 -0
  247. package/dist/release/publish-wait.d.ts +25 -0
  248. package/dist/release/publish-wait.js +56 -0
  249. package/dist/release/publish.d.ts +35 -0
  250. package/dist/release/publish.js +181 -0
  251. package/dist/release/release-assets.d.ts +39 -0
  252. package/dist/release/release-assets.js +68 -0
  253. package/dist/release/release.d.ts +37 -0
  254. package/dist/release/release.js +179 -0
  255. package/dist/release/remote.d.ts +12 -0
  256. package/dist/release/remote.js +15 -0
  257. package/dist/release/reproducible.d.ts +16 -0
  258. package/dist/release/reproducible.js +34 -0
  259. package/dist/release/run-tests.d.ts +5 -0
  260. package/dist/release/run-tests.js +17 -0
  261. package/dist/release/semver.d.ts +8 -0
  262. package/dist/release/semver.js +60 -0
  263. package/dist/release/version-rules.d.ts +28 -0
  264. package/dist/release/version-rules.js +63 -0
  265. package/dist/release/versions-json.d.ts +15 -0
  266. package/dist/release/versions-json.js +88 -0
  267. package/dist/release/workflow-run.d.ts +44 -0
  268. package/dist/release/workflow-run.js +71 -0
  269. package/dist/scanner/code-checks.d.ts +41 -0
  270. package/dist/scanner/code-checks.js +82 -0
  271. package/dist/scanner/commands.d.ts +3 -0
  272. package/dist/scanner/commands.js +43 -0
  273. package/dist/scanner/config.d.ts +7 -0
  274. package/dist/scanner/config.js +25 -0
  275. package/dist/scanner/css-check.d.ts +26 -0
  276. package/dist/scanner/css-check.js +63 -0
  277. package/dist/scanner/eslint-nesting.d.ts +16 -0
  278. package/dist/scanner/eslint-nesting.js +45 -0
  279. package/dist/scanner/findings.d.ts +23 -0
  280. package/dist/scanner/findings.js +21 -0
  281. package/dist/scanner/git-files.d.ts +16 -0
  282. package/dist/scanner/git-files.js +73 -0
  283. package/dist/scanner/lint.d.ts +47 -0
  284. package/dist/scanner/lint.js +163 -0
  285. package/dist/scanner/meta-checks.d.ts +8 -0
  286. package/dist/scanner/meta-checks.js +22 -0
  287. package/dist/scanner/outside-project.d.ts +19 -0
  288. package/dist/scanner/outside-project.js +20 -0
  289. package/dist/scanner/run.d.ts +19 -0
  290. package/dist/scanner/run.js +78 -0
  291. package/dist/scanner/scanner-config.d.ts +114 -0
  292. package/dist/scanner/scanner-config.js +207 -0
  293. package/dist/scanner/typescript-gate.d.ts +30 -0
  294. package/dist/scanner/typescript-gate.js +73 -0
  295. package/dist/vitest/build-config.d.ts +17 -0
  296. package/dist/vitest/build-config.js +106 -0
  297. package/dist/vitest/define-unit-config.d.ts +27 -0
  298. package/dist/vitest/define-unit-config.js +45 -0
  299. package/dist/vitest/dom/elements.d.ts +87 -0
  300. package/dist/vitest/dom/elements.js +291 -0
  301. package/dist/vitest/dom/index.d.ts +1 -0
  302. package/dist/vitest/dom/index.js +1 -0
  303. package/dist/vitest/dom/install.d.ts +8 -0
  304. package/dist/vitest/dom/install.js +261 -0
  305. package/dist/vitest/dom/setup.d.ts +1 -0
  306. package/dist/vitest/dom/setup.js +3 -0
  307. package/dist/vitest/index.d.ts +3 -0
  308. package/dist/vitest/index.js +2 -0
  309. package/dist/vitest/options.d.ts +92 -0
  310. package/dist/vitest/options.js +136 -0
  311. package/dist/vitest/peers.d.ts +10 -0
  312. package/dist/vitest/peers.js +51 -0
  313. package/dist/vitest/workspace-root.d.ts +7 -0
  314. package/dist/vitest/workspace-root.js +39 -0
  315. package/docs/build.md +232 -0
  316. package/docs/ci.md +182 -0
  317. package/docs/demo.md +364 -0
  318. package/docs/e2e.md +563 -0
  319. package/docs/release.md +374 -0
  320. package/docs/scanner.md +204 -0
  321. package/docs/unit.md +291 -0
  322. package/package.json +100 -4
  323. package/plugins/opdk/skills/audit/SKILL.md +81 -0
  324. package/plugins/opdk/skills/build/SKILL.md +79 -0
  325. package/plugins/opdk/skills/demo/SKILL.md +102 -0
  326. package/plugins/opdk/skills/e2e/SKILL.md +132 -0
  327. package/plugins/opdk/skills/release/SKILL.md +84 -0
  328. package/plugins/opdk/skills/scanner/SKILL.md +60 -0
  329. package/plugins/opdk/skills/unit/SKILL.md +90 -0
@@ -0,0 +1,207 @@
1
+ import obsidianmd from "eslint-plugin-obsidianmd";
2
+ import tseslint from "typescript-eslint";
3
+ /** The eslint-plugin-obsidianmd version this configuration was diffed against. */
4
+ export const MIRRORED_OBSIDIANMD_VERSION = "0.5.1";
5
+ const CODE_FILES = ["**/*.{ts,cts,mts,tsx,js,cjs,mjs,jsx}"];
6
+ /** The paths the scanner leaves out: upstream's `globalIgnores` list (upstream's 48 less the `e2e` folder, with `eslint` removed from the tool-config group), so the root `eslint.config.js` and `.ts` and the files of `e2e/` are linted, as the live scanner does. */
7
+ export const SCANNER_IGNORES = [
8
+ // Upstream marks these three "Not in the scanner's list": its stand-ins for bundled and minified output, which
9
+ // the scanner recognises by name and, in a TypeScript project, by content. Upstream says to drop `main.js`
10
+ // for a plugin written in JavaScript.
11
+ "main.js",
12
+ "**/*.min.js",
13
+ "**/{dist,build,out,release}/**/*.{js,cjs,mjs,jsx}",
14
+ "node_modules",
15
+ "dist",
16
+ "build",
17
+ "pkg",
18
+ "test-vault",
19
+ ".obsidian",
20
+ "**/.obsidian/**",
21
+ "esbuild.config.mjs",
22
+ "version-bump.mjs",
23
+ "**/*.test.*",
24
+ "**/*.tests.*",
25
+ "**/*.spec.*",
26
+ "**/*.specs.*",
27
+ "**/test/**",
28
+ "**/tests/**",
29
+ "**/__tests__/**",
30
+ "**/mocks/**",
31
+ "**/__mocks__/**",
32
+ "**/*.cjs",
33
+ "**/*.mjs",
34
+ "**/*.cts",
35
+ "**/*.mts",
36
+ "**/vite*",
37
+ "**/scripts/**",
38
+ "**/docs/**",
39
+ "**/i18n/**",
40
+ "**/i18next/**",
41
+ "**/locale/**",
42
+ "**/locales/**",
43
+ "**/translations/**",
44
+ "**/l10n/**",
45
+ ".pnpm-store",
46
+ "**/*.spec.ts",
47
+ "**/testUtils**",
48
+ "automation/**",
49
+ // Upstream also lists `**/e2e/**`, which the kit does not: see "e2e folders" in the header comment.
50
+ "**/e2e-tests/**",
51
+ "**/*.e2e.*",
52
+ "**/wdio.conf.*",
53
+ "**/wdio.*.conf.*",
54
+ "**/playwright.config.*",
55
+ "**/{astro,babel,commitlint,docusaurus,esbuild,jest,oxlint,postcss,prettier,rolldown,rollup,stylelint,svelte,tailwind,tsdown,tsup,uno,webpack}.config.*",
56
+ "**/{eslint,jest}.*.config.*",
57
+ "**/jest.setup.*",
58
+ "**/.{babelrc,eslintrc,mocharc,prettierrc}.*",
59
+ ];
60
+ /** The obsidianmd rules that read the type checker (`meta.docs.requiresTypeChecking`). */
61
+ function typeAwareObsidianRules() {
62
+ return Object.entries(obsidianmd.rules)
63
+ .filter(([, rule]) => {
64
+ const docs = rule.meta?.docs;
65
+ return typeof docs === "object" && docs !== null && "requiresTypeChecking" in docs && docs.requiresTypeChecking === true;
66
+ })
67
+ .map(([name]) => `obsidianmd/${name}`);
68
+ }
69
+ /**
70
+ * The e2e folder, whose exemption from the preset's runtime rules is lifted as well: one plugin's scorecard has
71
+ * `prefer-window-timers`, `no-global-this` and `no-nodejs-modules` for files in `e2e/`. Only the folder `e2e`, not
72
+ * `e2e-tests` or `*.e2e.*` (no evidence). Files under it that the scanner's list names (`*.spec.*`) stay out.
73
+ */
74
+ export const E2E_FILE_PATTERNS = ["**/e2e/**"];
75
+ /**
76
+ * The runtime rule that stays off in `E2E_FILE_PATTERNS` after the lift. one plugin's scorecard has no
77
+ * `prefer-active-doc` for the `document.querySelector(...)` in `e2e/fixtures.ts` (inside a `win.evaluate` callback,
78
+ * the only non-spec use of `document` in its `e2e/`), while the same file has `prefer-window-timers` in the same
79
+ * callback. The preset puts these rules in one block, so the kit switches this one off for the folder. One data point, and three
80
+ * explanations fit it: the scanner exempts the rule in `e2e/`, it skips `document` inside such a callback, or it does
81
+ * not report the rule on any tsconfig-covered file (no scorecard seen has shown it on one). The kit cannot tell them
82
+ * apart, and keeps the off scoped to `e2e/`.
83
+ */
84
+ export const E2E_EXEMPT_RULE = "obsidianmd/prefer-active-doc";
85
+ /**
86
+ * The test-setup files, whose exemption from the preset's runtime rules is lifted (as is the e2e folder's,
87
+ * `E2E_FILE_PATTERNS`). The scanner's ignore list names none of them, and the one scorecard that shows it has a `global-setup.ts` with three `no-nodejs-modules`
88
+ * warnings. The other names are the same family in the preset's own list (`*-global-setup.*`, `test-setup.*`,
89
+ * `setupTests.*`, `*.setup.*`), run by a test runner in Node like that file, and the scanner's list does not name them
90
+ * either; they are inferred from that one scorecard, not seen on their own. Everything else the preset exempts stays
91
+ * exempt: worker files (a Worker has no `activeWindow`, so `prefer-window-timers` and `no-global-this` would be wrong
92
+ * advice there), `test-helpers`, `test-support` and `test-utils` folders, `*.testing.*`, `testUtils*`, and tool configs
93
+ * and scripts, none of which has evidence.
94
+ */
95
+ export const SETUP_FILE_PATTERNS = ["**/{global-setup,*-global-setup,test-setup,setupTests}.*", "**/*.setup.*"];
96
+ const LIFTED_FILE_PATTERNS = [...SETUP_FILE_PATTERNS, ...E2E_FILE_PATTERNS];
97
+ /**
98
+ * The blocks of the preset that carry `ignores` (its exemption of test, worker and tooling files) as the same blocks
99
+ * that apply only to `SETUP_FILE_PATTERNS` and `E2E_FILE_PATTERNS`, without `ignores`. Later blocks override earlier
100
+ * ones, so putting these after the preset turns the rules back on for the setup files and the e2e folder and no other
101
+ * exempted file. Plugins and parsers stay with the original blocks. Flat config reads a nested `files` array as "all
102
+ * of these", so each pattern of the block is paired with each lifted pattern.
103
+ */
104
+ export function withoutRuntimeExemptions(blocks) {
105
+ return blocks.flatMap((block) => {
106
+ if (block.ignores === undefined || block.rules === undefined) {
107
+ return [];
108
+ }
109
+ const own = (block.files ?? ["**/*"]).map((pattern) => [pattern].flat());
110
+ return [{ files: own.flatMap((pattern) => LIFTED_FILE_PATTERNS.map((lifted) => [...pattern, lifted])), rules: block.rules }];
111
+ });
112
+ }
113
+ export function createScannerConfig({ cwd, typeAware, allowDefaultProject = true }) {
114
+ const config = [
115
+ {
116
+ languageOptions: {
117
+ parserOptions: {
118
+ // `allowDefaultProject` lets the plugin's own `eslint.config.*` (usually outside the tsconfig)
119
+ // be linted with type information, which is what produces the `no-unsafe-*` warnings the
120
+ // public scorecard shows for it.
121
+ projectService: { allowDefaultProject: allowDefaultProject ? ["eslint.config.*"] : [] },
122
+ tsconfigRootDir: cwd,
123
+ },
124
+ },
125
+ },
126
+ ...obsidianmd.configs.recommended,
127
+ ...withoutRuntimeExemptions(obsidianmd.configs.recommended),
128
+ {
129
+ // The one runtime rule the e2e exemption keeps: see "e2e folders" in the header comment.
130
+ files: [...E2E_FILE_PATTERNS],
131
+ rules: { [E2E_EXEMPT_RULE]: "off" },
132
+ },
133
+ {
134
+ files: CODE_FILES,
135
+ rules: {
136
+ // Security: kept as errors
137
+ "no-eval": "error",
138
+ "no-unsanitized/method": "error",
139
+ "no-unsanitized/property": "error",
140
+ "obsidianmd/regex-lookbehind": "error",
141
+ "obsidianmd/no-forbidden-elements": "error",
142
+ // Covered by TypeScript or too noisy
143
+ "no-undef": "off",
144
+ "@typescript-eslint/restrict-template-expressions": "off",
145
+ "@typescript-eslint/no-base-to-string": "off",
146
+ "import/no-unresolved": "off",
147
+ // Newest layer: turns these back on at `warn` (upstream's docs, "Rule severity
148
+ // adjustments"), and the public scorecard of a real plugin lists them. In 0.5.1's recommended config
149
+ // the five `no-unsafe-*` rules are `error` for TypeScript files only (off under package.json,
150
+ // manifest.json and LICENSE, absent for JavaScript), so they are set here at `warn`: TypeScript and
151
+ // JavaScript (`eslint.config.js` included) both get them as warnings, as the newest layer does. The
152
+ // command-id rules are already `warn` there; they are listed so the layer stays complete.
153
+ "@typescript-eslint/no-unsafe-member-access": "warn",
154
+ "@typescript-eslint/no-unsafe-assignment": "warn",
155
+ "@typescript-eslint/no-unsafe-argument": "warn",
156
+ "@typescript-eslint/no-unsafe-call": "warn",
157
+ "@typescript-eslint/no-unsafe-return": "warn",
158
+ "obsidianmd/commands/no-command-in-command-id": "warn",
159
+ "obsidianmd/commands/no-plugin-id-in-command-id": "warn",
160
+ },
161
+ },
162
+ {
163
+ // Implied eval, once per call: the core rule in JavaScript, typescript-eslint's in TypeScript, where
164
+ // the recommended config turns the core rule off. An "error" for the core rule in the block above
165
+ // would turn it back on in TypeScript and report each call twice.
166
+ files: ["**/*.{js,cjs,mjs,jsx}"],
167
+ rules: { "no-implied-eval": "error" },
168
+ },
169
+ {
170
+ files: ["**/*.{ts,cts,mts,tsx}"],
171
+ rules: { "@typescript-eslint/no-implied-eval": "error" },
172
+ },
173
+ ];
174
+ if (!typeAware) {
175
+ config.push({
176
+ ...tseslint.configs.disableTypeChecked,
177
+ files: CODE_FILES,
178
+ languageOptions: {
179
+ parserOptions: { projectService: false, project: null },
180
+ },
181
+ rules: {
182
+ ...tseslint.configs.disableTypeChecked.rules,
183
+ ...Object.fromEntries(typeAwareObsidianRules().map((name) => [name, "off"])),
184
+ },
185
+ });
186
+ // disableTypeChecked turns off `@typescript-eslint/no-implied-eval`; the core rule takes over for
187
+ // TypeScript, where the recommended config leaves it off.
188
+ config.push({ files: ["**/*.{ts,cts,mts,tsx}"], rules: { "no-implied-eval": "error" } });
189
+ }
190
+ config.push({
191
+ // Scanner handles this separately. It must be switched off under the glob the rule actually runs on:
192
+ // manifest.json matches no source glob, so an "off" in the block above would not reach it.
193
+ files: ["manifest.json"],
194
+ rules: { "obsidianmd/validate-manifest": "off" },
195
+ }, {
196
+ // Same for LICENSE.
197
+ files: ["LICENSE", "LICENSE.md", "LICENSE.txt"],
198
+ rules: { "obsidianmd/validate-license": "off" },
199
+ }, {
200
+ // The scanner honours disable comments but does not report unused ones
201
+ linterOptions: {
202
+ reportUnusedDisableDirectives: "off",
203
+ reportUnusedInlineConfigs: "off",
204
+ },
205
+ }, { ignores: [...SCANNER_IGNORES] });
206
+ return config;
207
+ }
@@ -0,0 +1,30 @@
1
+ import type { Reporter } from "../cli/reporter.js";
2
+ /**
3
+ * The community scanner type-checks with TypeScript 6, and TypeScript 6 forces `esModuleInterop` on: `moment(date)`
4
+ * imported from `obsidian` is then not callable, and `no-unsafe-call`, `no-unsafe-member-access` and
5
+ * `no-unsafe-return` fire. Under the plugin's own TypeScript 5.9 the same line reports nothing, so a scan on 5.x
6
+ * would show a clean result the scorecard does not (docs/scanner.md, "Differences from the public scorecard").
7
+ */
8
+ export declare const REQUIRED_TYPESCRIPT_MAJOR = 6;
9
+ /** What `opdk scan` prints when the plugin's TypeScript cannot be used: the failure line and the hint under it. */
10
+ export interface TypescriptGap {
11
+ readonly message: string;
12
+ readonly hint: string;
13
+ }
14
+ /**
15
+ * The failure for a TypeScript the scan must not run on, or `undefined` when it may. `version` is what typescript-eslint
16
+ * resolves in the plugin, or `undefined` when none is installed. A version that cannot be read as a major is let
17
+ * through: the scan should not fail on a pre-release tag it does not understand.
18
+ */
19
+ export declare function describeTypescriptGap(version: string | undefined): TypescriptGap | undefined;
20
+ /**
21
+ * The version of the `typescript` that typescript-eslint resolves from the kit's install, which is the plugin's own
22
+ * (a peer dependency of the kit), or `undefined` when there is none. `load` is injectable for tests.
23
+ */
24
+ export declare function readPluginTypescriptVersion(load?: () => unknown): string | undefined;
25
+ /**
26
+ * The check `opdk scan` runs before it loads the scan's ESLint plugins: they `require("typescript")` at import, so
27
+ * without a TypeScript the import itself would fail with a bare "Cannot find package". Prints the failure and returns
28
+ * 1 when no TypeScript is installed; an older one is reported by `runScan`, after the tracked files are listed.
29
+ */
30
+ export declare function missingTypescriptPreflight(pluginId: string, reporter: Reporter, read?: () => string | undefined): number | undefined;
@@ -0,0 +1,73 @@
1
+ import { createRequire } from "node:module";
2
+ import { majorOf } from "./eslint-nesting.js";
3
+ /**
4
+ * The community scanner type-checks with TypeScript 6, and TypeScript 6 forces `esModuleInterop` on: `moment(date)`
5
+ * imported from `obsidian` is then not callable, and `no-unsafe-call`, `no-unsafe-member-access` and
6
+ * `no-unsafe-return` fire. Under the plugin's own TypeScript 5.9 the same line reports nothing, so a scan on 5.x
7
+ * would show a clean result the scorecard does not (docs/scanner.md, "Differences from the public scorecard").
8
+ */
9
+ export const REQUIRED_TYPESCRIPT_MAJOR = 6;
10
+ const UPGRADE_HINT = "Run `npm install -D typescript@6`, then fix what `tsc` reports (TS2349 on `moment` imported from obsidian; the typed-call fix is in docs/scanner.md, \"Differences from the public scorecard\").";
11
+ /**
12
+ * The failure for a TypeScript the scan must not run on, or `undefined` when it may. `version` is what typescript-eslint
13
+ * resolves in the plugin, or `undefined` when none is installed. A version that cannot be read as a major is let
14
+ * through: the scan should not fail on a pre-release tag it does not understand.
15
+ */
16
+ export function describeTypescriptGap(version) {
17
+ if (version === undefined) {
18
+ return {
19
+ message: "the plugin has no TypeScript installed, and the scan type-checks with it.",
20
+ hint: "Run `npm install -D typescript@6`: the community scanner type-checks with TypeScript 6.",
21
+ };
22
+ }
23
+ const major = majorOf(version);
24
+ if (major === undefined || major >= REQUIRED_TYPESCRIPT_MAJOR) {
25
+ return undefined;
26
+ }
27
+ return {
28
+ message: `the plugin has TypeScript ${version}, but the community scanner type-checks with TypeScript ${String(REQUIRED_TYPESCRIPT_MAJOR)}, so findings such as \`no-unsafe-call\` on \`moment(...)\` would be missed.`,
29
+ hint: UPGRADE_HINT,
30
+ };
31
+ }
32
+ /** Loads the `package.json` of the `typescript` that typescript-eslint resolves from the kit's install. Throws when there is none. */
33
+ function loadTypescriptManifest() {
34
+ const fromKit = createRequire(import.meta.url);
35
+ const nextToEstree = createRequire(createRequire(fromKit.resolve("typescript-eslint")).resolve("@typescript-eslint/typescript-estree"));
36
+ return nextToEstree("typescript/package.json");
37
+ }
38
+ /**
39
+ * The version of the `typescript` that typescript-eslint resolves from the kit's install, which is the plugin's own
40
+ * (a peer dependency of the kit), or `undefined` when there is none. `load` is injectable for tests.
41
+ */
42
+ export function readPluginTypescriptVersion(load = loadTypescriptManifest) {
43
+ let manifest;
44
+ try {
45
+ manifest = load();
46
+ }
47
+ catch (error) {
48
+ if (error instanceof Error && "code" in error && error.code === "MODULE_NOT_FOUND") {
49
+ return undefined;
50
+ }
51
+ throw error;
52
+ }
53
+ if (typeof manifest === "object" && manifest !== null && "version" in manifest && typeof manifest.version === "string") {
54
+ return manifest.version;
55
+ }
56
+ throw new Error("the typescript package next to typescript-eslint has no version in its package.json. Reinstall it with `npm install -D typescript@6`.");
57
+ }
58
+ /**
59
+ * The check `opdk scan` runs before it loads the scan's ESLint plugins: they `require("typescript")` at import, so
60
+ * without a TypeScript the import itself would fail with a bare "Cannot find package". Prints the failure and returns
61
+ * 1 when no TypeScript is installed; an older one is reported by `runScan`, after the tracked files are listed.
62
+ */
63
+ export function missingTypescriptPreflight(pluginId, reporter, read = readPluginTypescriptVersion) {
64
+ if (read() !== undefined) {
65
+ return undefined;
66
+ }
67
+ const gap = describeTypescriptGap(undefined);
68
+ if (gap === undefined) {
69
+ return undefined;
70
+ }
71
+ reporter.failure("scan", `${pluginId}: ${gap.message}`, { hint: gap.hint });
72
+ return 1;
73
+ }
@@ -0,0 +1,17 @@
1
+ import type { ViteUserConfig } from "vitest/config";
2
+ import type { ResolvedUnitOptions } from "./options.js";
3
+ /**
4
+ * The Vitest config for resolved options. Pure: the paths of the two setup files are passed in, so no test needs
5
+ * the built package on disk.
6
+ *
7
+ * The config is plain data. A plugin that needs more spreads or `mergeConfig`s it.
8
+ *
9
+ * `server.fs.allow`: Vite refuses to serve a file outside its workspace root, and a kit linked with `npm link` or
10
+ * `file:` has its real folder (where the DOM setup file lives) outside the plugin. When the kit's setup file is used
11
+ * and sits outside `rootDir`, the kit's folder is allowed, together with `workspaceRoot` (Vite's default, which an
12
+ * explicit `allow` replaces). Copies under `node_modules` need nothing and get no `server` key.
13
+ */
14
+ export declare function buildUnitConfig(options: ResolvedUnitOptions, setupFiles: {
15
+ readonly dom: string;
16
+ readonly mocks: string;
17
+ }, workspaceRoot: string): ViteUserConfig;
@@ -0,0 +1,106 @@
1
+ import path from "node:path";
2
+ import { configDefaults } from "vitest/config";
3
+ /**
4
+ * The package `obsidian` has no JavaScript entry (`"main": ""`), so Vite cannot resolve `import "obsidian"` even
5
+ * though the mocks' `vitest-setup` mocks it: the import is aliased to the mocks' own module as well.
6
+ */
7
+ const MOCKS_ALIAS = { obsidian: "obsidian-test-mocks/obsidian" };
8
+ /** What `import "obsidian"` resolves to in the node project and in the DOM project (`undefined`: no alias). */
9
+ function obsidianAliases(options) {
10
+ const { obsidian, rootDir } = options;
11
+ const stub = (file) => ({ obsidian: path.resolve(rootDir, file) });
12
+ switch (obsidian.kind) {
13
+ case "none":
14
+ return { node: undefined, dom: undefined, mocks: false };
15
+ case "stub":
16
+ return { node: stub(obsidian.path), dom: stub(obsidian.path), mocks: false };
17
+ case "mocks":
18
+ return { node: undefined, dom: MOCKS_ALIAS, mocks: true };
19
+ case "split":
20
+ return {
21
+ node: stub(obsidian.node),
22
+ dom: obsidian.dom.kind === "mocks" ? MOCKS_ALIAS : stub(obsidian.dom.path),
23
+ mocks: obsidian.dom.kind === "mocks",
24
+ };
25
+ }
26
+ }
27
+ function isInside(parent, child) {
28
+ const relative = path.relative(parent, child);
29
+ return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
30
+ }
31
+ /** Test environments of the config: jsdom for the DOM files, node for the rest. */
32
+ const DOM_ENVIRONMENT = "jsdom";
33
+ function rootAlias(domKind, aliases, sameAlias, alias) {
34
+ if (domKind === "split")
35
+ return sameAlias ? alias(aliases.node) : {};
36
+ return alias(domKind === "all" ? aliases.dom : aliases.node);
37
+ }
38
+ /**
39
+ * The Vitest config for resolved options. Pure: the paths of the two setup files are passed in, so no test needs
40
+ * the built package on disk.
41
+ *
42
+ * The config is plain data. A plugin that needs more spreads or `mergeConfig`s it.
43
+ *
44
+ * `server.fs.allow`: Vite refuses to serve a file outside its workspace root, and a kit linked with `npm link` or
45
+ * `file:` has its real folder (where the DOM setup file lives) outside the plugin. When the kit's setup file is used
46
+ * and sits outside `rootDir`, the kit's folder is allowed, together with `workspaceRoot` (Vite's default, which an
47
+ * explicit `allow` replaces). Copies under `node_modules` need nothing and get no `server` key.
48
+ */
49
+ export function buildUnitConfig(options, setupFiles, workspaceRoot) {
50
+ const { dom, coverage, include } = options;
51
+ const aliases = obsidianAliases(options);
52
+ const domSetup = aliases.mocks ? [setupFiles.mocks] : [setupFiles.dom];
53
+ const kitDir = path.dirname(setupFiles.dom);
54
+ const kitSetupUsed = !aliases.mocks && (dom.kind === "all" || dom.kind === "split");
55
+ const fsAllow = kitSetupUsed && !isInside(options.rootDir, kitDir) ? [workspaceRoot, kitDir] : [];
56
+ const alias = (value) => (value === undefined ? {} : { resolve: { alias: value } });
57
+ // One alias at the root when both sides agree; each project carries its own when they differ, so every
58
+ // resolved project config shows exactly one `obsidian` entry. (A project alias would override a root one
59
+ // anyway: Vite's mergeAlias puts the project entry first, see mergeConfigRecursively in vite/dist/node.)
60
+ const sameAlias = aliases.node === aliases.dom || aliases.node?.obsidian === aliases.dom?.obsidian;
61
+ // Both modes need the DOM first; the mocks package patches it, the kit polyfill fills it.
62
+ const projects = dom.kind === "split"
63
+ ? [
64
+ {
65
+ extends: true,
66
+ test: {
67
+ name: "unit",
68
+ environment: "node",
69
+ include: [...include],
70
+ exclude: [...configDefaults.exclude, ...dom.globs],
71
+ },
72
+ ...(sameAlias ? {} : alias(aliases.node)),
73
+ },
74
+ {
75
+ extends: true,
76
+ test: {
77
+ name: "dom",
78
+ environment: DOM_ENVIRONMENT,
79
+ include: [...dom.globs],
80
+ setupFiles: domSetup,
81
+ },
82
+ ...(sameAlias && aliases.node !== undefined ? {} : alias(aliases.dom)),
83
+ },
84
+ ]
85
+ : [];
86
+ return {
87
+ ...rootAlias(dom.kind, aliases, sameAlias, alias),
88
+ ...(fsAllow.length > 0 ? { server: { fs: { allow: fsAllow } } } : {}),
89
+ test: {
90
+ // Projects append their own include to the root one (Vitest 5), so with projects the root must have none.
91
+ ...(projects.length > 0 ? {} : { include: [...include] }),
92
+ environment: dom.kind === "all" ? DOM_ENVIRONMENT : "node",
93
+ ...(dom.kind === "all" ? { setupFiles: domSetup } : {}),
94
+ ...(projects.length > 0 ? { projects } : {}),
95
+ coverage: {
96
+ enabled: true,
97
+ provider: "v8",
98
+ reporter: [...coverage.reporters],
99
+ reportsDirectory: "coverage",
100
+ include: [...coverage.include],
101
+ exclude: [...coverage.exclude],
102
+ thresholds: { ...coverage.thresholds },
103
+ },
104
+ },
105
+ };
106
+ }
@@ -0,0 +1,27 @@
1
+ import type { ViteUserConfig } from "vitest/config";
2
+ import type { VersionReader } from "../peers/versions.js";
3
+ import type { UnitConfigOptions } from "./options.js";
4
+ /**
5
+ * The unit-test setup three plugins share, as a Vitest config to export from the plugin's own
6
+ * `vitest.config.ts`:
7
+ *
8
+ * ```ts
9
+ * import { defineUnitConfig } from "obsidian-plugin-dev-kit/vitest";
10
+ * export default defineUnitConfig({
11
+ * coverage: { include: ["src/**\/*.ts"], exclude: ["src/main.ts"] },
12
+ * obsidian: "./src/test/stubs/obsidian.ts",
13
+ * dom: ["src/ui/**\/*.test.ts"],
14
+ * });
15
+ * ```
16
+ *
17
+ * Defaults: tests in `src/**\/*.test.ts` run in node with the v8 coverage provider, reporters `text` and
18
+ * `json-summary` (`coverage/`), and the thresholds 90 lines, functions and statements, 80 branches. Files listed in
19
+ * `dom` run in jsdom with Obsidian's DOM helpers installed. The result is a plain config: spread it or `mergeConfig` it.
20
+ *
21
+ * Needs `vitest` 5, `@vitest/coverage-v8` (the same version) and, when `dom` is used, `jsdom` 30 or newer in the
22
+ * plugin. The kit declares no peer dependency on them (npm would refuse to install the kit next to an older Vitest);
23
+ * the versions are checked here instead, and a mismatch throws with the install command.
24
+ */
25
+ export declare function defineUnitConfig(options: UnitConfigOptions): ViteUserConfig;
26
+ /** {@link defineUnitConfig} with the package lookup injected, so tests need no `node_modules` of their own. */
27
+ export declare function createUnitConfig(options: UnitConfigOptions, readerFor: (rootDir: string) => VersionReader): ViteUserConfig;
@@ -0,0 +1,45 @@
1
+ import fs from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import { createVersionReader } from "../peers/resolve.js";
4
+ import { buildUnitConfig } from "./build-config.js";
5
+ import { assertUnitPeers } from "./peers.js";
6
+ import { resolveUnitOptions } from "./options.js";
7
+ import { findWorkspaceRoot } from "./workspace-root.js";
8
+ /** The setup file of the kit's DOM polyfill, next to this module (`.js` in `dist/`, `.ts` when run from `src/`). */
9
+ function sibling(relative) {
10
+ const extension = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
11
+ return fileURLToPath(new URL(`${relative}${extension}`, import.meta.url));
12
+ }
13
+ /**
14
+ * The unit-test setup three plugins share, as a Vitest config to export from the plugin's own
15
+ * `vitest.config.ts`:
16
+ *
17
+ * ```ts
18
+ * import { defineUnitConfig } from "obsidian-plugin-dev-kit/vitest";
19
+ * export default defineUnitConfig({
20
+ * coverage: { include: ["src/**\/*.ts"], exclude: ["src/main.ts"] },
21
+ * obsidian: "./src/test/stubs/obsidian.ts",
22
+ * dom: ["src/ui/**\/*.test.ts"],
23
+ * });
24
+ * ```
25
+ *
26
+ * Defaults: tests in `src/**\/*.test.ts` run in node with the v8 coverage provider, reporters `text` and
27
+ * `json-summary` (`coverage/`), and the thresholds 90 lines, functions and statements, 80 branches. Files listed in
28
+ * `dom` run in jsdom with Obsidian's DOM helpers installed. The result is a plain config: spread it or `mergeConfig` it.
29
+ *
30
+ * Needs `vitest` 5, `@vitest/coverage-v8` (the same version) and, when `dom` is used, `jsdom` 30 or newer in the
31
+ * plugin. The kit declares no peer dependency on them (npm would refuse to install the kit next to an older Vitest);
32
+ * the versions are checked here instead, and a mismatch throws with the install command.
33
+ */
34
+ export function defineUnitConfig(options) {
35
+ return createUnitConfig(options, (rootDir) => createVersionReader(rootDir));
36
+ }
37
+ /** {@link defineUnitConfig} with the package lookup injected, so tests need no `node_modules` of their own. */
38
+ export function createUnitConfig(options, readerFor) {
39
+ const resolved = resolveUnitOptions(options, process.cwd());
40
+ assertUnitPeers(readerFor(resolved.rootDir), resolved.dom.kind !== "none");
41
+ // Real path of the setup file: Vite checks the real path of a file it serves. Node already resolves symlinks in
42
+ // import.meta.url for a linked kit; realpath keeps that true under --preserve-symlinks / NODE_PRESERVE_SYMLINKS.
43
+ const dom = fs.realpathSync(sibling("./dom/setup"));
44
+ return buildUnitConfig(resolved, { dom, mocks: "obsidian-test-mocks/vitest-setup" }, findWorkspaceRoot(resolved.rootDir));
45
+ }
@@ -0,0 +1,87 @@
1
+ type ElementInfo = DomElementInfo | string;
2
+ /**
3
+ * `createEl()` of the app: a string is shorthand for `{ cls }`; `cls` (string or array), `text`, `attr` (a null value
4
+ * removes the attribute), `title`, `value` (input, select, option), `type` (input; a `<style>` gets it as an
5
+ * attribute), `placeholder` (input), `href` (a, link, base) are applied in that order; then the callback runs, then
6
+ * the element is inserted into `parent` (first, with `prepend`); then every `on*` function in the info is registered
7
+ * as an event listener (`addEventListener(key.substring(2), fn)`, the function itself, so `removeEventListener`
8
+ * with the same function removes it). The info is not mutated. The text and the attributes go through the
9
+ * installed `el.setText()` and `el.setAttrs()`, as in the app.
10
+ */
11
+ export declare function createElement<K extends keyof HTMLElementTagNameMap>(tag: K, info?: ElementInfo, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
12
+ /**
13
+ * `Node#createEl`: the global `createEl` with `parent` set to the node. As in the app, `parent` is written into the
14
+ * info object the caller passed (a string becomes a new `{ cls }` object).
15
+ */
16
+ export declare function createChild<K extends keyof HTMLElementTagNameMap>(parent: Node, tag: K, info?: ElementInfo, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K];
17
+ /** `createFragment()` of the app: a detached fragment, passed to the callback first. */
18
+ export declare function createFragment(callback?: (el: DocumentFragment) => void): DocumentFragment;
19
+ /** `Element#setText`: a Node or fragment replaces the children, anything else is stringified into textContent. */
20
+ export declare function setText(el: Element, value: unknown): void;
21
+ /** `Element#setAttr`: null removes the attribute, anything else is stringified. */
22
+ export declare function setAttr(el: Element, name: string, value: string | number | boolean | null): void;
23
+ /** `Element#setAttrs`: `setAttr` for every own key. */
24
+ export declare function setAttrs(el: Element, attrs: Record<string, string | number | boolean | null>): void;
25
+ /** The app's `getText()`: the text content, as the DOM defines it for elements, documents and fragments. */
26
+ export declare function getText(el: Element): string;
27
+ /** `Element#toggleClass`: the value is truthy to add and falsy to remove, so `undefined` removes (as in the app). */
28
+ export declare function toggleClass(el: Element, classes: string | string[], value: boolean | undefined): void;
29
+ /**
30
+ * `HTMLElement#hide`: remember an inline display value in `data-display`, then set `display: none`. Does nothing
31
+ * when it is already hidden.
32
+ */
33
+ export declare function hide(el: HTMLElement): void;
34
+ /** `HTMLElement#show`: undo `hide()`, restoring the remembered display value. Does nothing unless hidden. */
35
+ export declare function show(el: HTMLElement): void;
36
+ /**
37
+ * `HTMLElement#isShown`. The app returns `!!offsetParent`, which jsdom (no layout) always reports as null, so a
38
+ * literal port would say false for everything. This one is true for an element that is in the document and has
39
+ * no inline `display: none` on itself or an ancestor.
40
+ */
41
+ export declare function isShown(el: HTMLElement): boolean;
42
+ /** `setCssStyles`: assign every own property to `style`. */
43
+ export declare function setCssStyles(el: HTMLElement | SVGElement, styles: Partial<CSSStyleDeclaration>): void;
44
+ /** `setCssProps`: `style.setProperty` for every own key, so custom properties (`--x`) work. */
45
+ export declare function setCssProps(el: HTMLElement | SVGElement, props: Record<string, string>): void;
46
+ /**
47
+ * `Node#instanceOf`: the plain operator, then the same class looked up by name on the node's own window and on the
48
+ * window the app's code runs in. With the one jsdom window of a test the `constructorWin` lookup finds what the
49
+ * `win` lookup found, so only the first two steps are reachable (and tested); the third is kept for parity.
50
+ */
51
+ export declare function instanceOf(node: Node, type: abstract new () => unknown): boolean;
52
+ /**
53
+ * `createSvg()` of the app: an SVG element in the SVG namespace. A string is shorthand for `{ cls }`; `cls` (string
54
+ * or array) goes to `classList`, then `attr`, then the callback, then insertion into `parent` (first, with `prepend`).
55
+ * Unlike `createEl`, there is no `text`, `title` or `on*` handling.
56
+ */
57
+ export declare function createSvgElement<K extends keyof SVGElementTagNameMap>(tag: K, info?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
58
+ /** `Node#createSvg`: the global `createSvg` with `parent` set to the node. As with `createChild`, `parent` is written into the info. */
59
+ export declare function createSvgChild<K extends keyof SVGElementTagNameMap>(parent: Node, tag: K, info?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K];
60
+ /**
61
+ * `Node#setChildrenInPlace`: makes the children of `node` exactly `children`, in order, moving as little as possible.
62
+ * A child already in the right place is not touched (it keeps focus and state); a child not in the list is removed.
63
+ */
64
+ export declare function setChildrenInPlace(node: Node, children: readonly Node[]): void;
65
+ /**
66
+ * `Element#matchParent`: the element itself or its closest ancestor that matches `selector`, not looking above
67
+ * `lastParent` (which is itself checked), or null.
68
+ */
69
+ export declare function matchParent(el: Element, selector: string, lastParent?: Element): Element | null;
70
+ /**
71
+ * `Element#isActiveElement`: focused in its own document, and every frame up to the top window is focused in its
72
+ * parent document too, and that top window is the active one.
73
+ */
74
+ export declare function isActiveElement(el: Element): boolean;
75
+ export type DelegatedListener = (this: EventTarget, ev: Event, delegateTarget: Element) => unknown;
76
+ /**
77
+ * `on(type, selector, listener, options)`: a listener on the target that runs when the event's target (or an
78
+ * ancestor, up to the target) matches `selector`; `listener` gets the event and the matching element.
79
+ */
80
+ export declare function onDelegated(target: EventTarget, type: string, selector: string, listener: DelegatedListener, options?: boolean | AddEventListenerOptions): void;
81
+ /** `off(type, selector, listener, options)`: removes what `onDelegated` registered for the same four arguments. */
82
+ export declare function offDelegated(target: EventTarget, type: string, selector: string, listener: DelegatedListener, options?: boolean | AddEventListenerOptions): void;
83
+ /** `UIEvent#instanceOf`: the plain operator, then the same class by name on the window the event came from. */
84
+ export declare function eventInstanceOf(event: UIEvent, type: abstract new () => unknown): boolean;
85
+ /** `addEventListeners`: `addEventListener(type, fn)` for every own key whose value is a function; other values are skipped. */
86
+ export declare function addEventListeners(el: EventTarget, listeners: Record<string, unknown>): void;
87
+ export {};