obsidian-plugin-dev-kit 0.0.0-stage → 0.3.3

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,194 @@
1
+ /**
2
+ * Functions Playwright serializes and runs inside Obsidian, for the `obsidian` helpers. Like `../page-scripts.ts`,
3
+ * each one must be self-contained: only its source text crosses into the page, so it cannot call another function
4
+ * of this file or use an import. They are exported so tests can run them against a fake `globalThis`. The page's
5
+ * own DOM and Obsidian types are not available to the kit (`lib` has no DOM), hence the small interfaces below.
6
+ */
7
+ import type { PagePosition } from "../internals.js";
8
+ /** Whether a settings tab with this id is registered (a community plugin's or a core one). */
9
+ export declare function hasSettingTab(id: string): boolean;
10
+ /** The ids of every registered settings tab, for the error of a tab that does not exist. */
11
+ export declare function listSettingTabIds(): string[];
12
+ /** Opens the settings modal (unless it is open already, which would stack a second one), on the tab `id` when given. */
13
+ export declare function openSettingsModal(id: string | null): void;
14
+ export declare function closeSettingsModal(): void;
15
+ export type RunCommandResult = {
16
+ state: "ran";
17
+ } | {
18
+ state: "declined";
19
+ } | {
20
+ state: "missing";
21
+ ids: string[];
22
+ };
23
+ /** Runs a command through Obsidian's own executor, the one the palette and hotkeys use. */
24
+ export declare function runCommandById(id: string): RunCommandResult;
25
+ export interface PageViewState {
26
+ mode?: string;
27
+ source?: boolean;
28
+ }
29
+ export type OpenFileResult = {
30
+ found: false;
31
+ } | {
32
+ found: true;
33
+ view: PageViewState | null;
34
+ };
35
+ /**
36
+ * Opens a note in the active tab and, when a mode is wanted, forces it. `openFile` takes the requested state only
37
+ * when it opens the note; for a note already open in this tab it keeps the mode it has, so the view's state is set
38
+ * directly afterwards. Returns the mode the view ended up in so the caller can verify it.
39
+ */
40
+ export declare function openFileInMode(args: {
41
+ path: string;
42
+ wanted: {
43
+ mode: string;
44
+ source: boolean;
45
+ } | null;
46
+ }): Promise<OpenFileResult>;
47
+ export declare function readActiveFilePath(): string | null;
48
+ /** The whole document of the active editor. `getValue()`, not the DOM: CodeMirror only renders the visible lines. */
49
+ export declare function readEditorText(): string | null;
50
+ export interface PageSelection {
51
+ text: string;
52
+ anchor: PagePosition;
53
+ head: PagePosition;
54
+ }
55
+ export declare function readEditorSelection(): PageSelection | null;
56
+ /** Focuses the active editor and puts the cursor at `position` (CodeMirror clamps a position past the end). */
57
+ export declare function placeEditorCursor(position: PagePosition): boolean;
58
+ /** True when the keyboard focus is inside the first element that matches `selector`. */
59
+ export declare function isFocusInside(selector: string): boolean;
60
+ export declare function isEditorEmpty(): boolean;
61
+ /** True once the document is not `before` any more. */
62
+ export declare function editorTextChanged(before: string): boolean;
63
+ /**
64
+ * True when CodeMirror is not inside a composition. It keeps the flag set for a moment after the commit, and a next
65
+ * composition started inside that window would be read as the same one.
66
+ */
67
+ export declare function isEditorSettled(): boolean;
68
+ export type ApplyThemeResult = {
69
+ ok: true;
70
+ } | {
71
+ ok: false;
72
+ themes: string[];
73
+ };
74
+ /**
75
+ * Sets the colour scheme (`obsidian` is dark, `moonstone` is light) the way Obsidian's appearance settings do, then
76
+ * the community theme when one is named (an empty string is the default theme). Reports the installed themes when
77
+ * the named one is not among them.
78
+ */
79
+ export declare function applyTheme(args: {
80
+ scheme: string;
81
+ theme: string | null;
82
+ }): ApplyThemeResult;
83
+ /** True once the body carries the class of the wanted scheme (`theme-dark` or `theme-light`). */
84
+ export declare function isSchemeApplied(scheme: string): boolean;
85
+ export interface MetadataCacheState {
86
+ total: number;
87
+ cached: number;
88
+ }
89
+ export declare function metadataCacheState(): MetadataCacheState;
90
+ /** True when every markdown file of the vault has its metadata cached; a vault with none is complete at once. */
91
+ export declare function isMetadataCacheComplete(): boolean;
92
+ /** Removes every notice from the DOM and returns how many there were. */
93
+ export declare function removeNotices(): number;
94
+ /**
95
+ * Hides the properties block of notes and saves the setting to app.json at once. `setConfig` alone changes it in
96
+ * memory only: Obsidian reads app.json again after the next settings save (`cleanUi` does one) and the block came
97
+ * back. Returns false when this Obsidian cannot be configured, so the helper can
98
+ * fail with a message.
99
+ */
100
+ export declare function hideNoteProperties(): Promise<boolean>;
101
+ /**
102
+ * Collapses (`true`) or expands (`false`) the left and right side panels. Returns false when this Obsidian has no such
103
+ * split object, so the helper can fail with a message instead of waiting for a state that cannot come.
104
+ */
105
+ export declare function setSidebarsCollapsed(collapsed: boolean): boolean;
106
+ /** True when both side panels are in the wanted state; the panels animate, so `collapse()` returns before it holds. */
107
+ export declare function areSidebarsCollapsed(collapsed: boolean): boolean;
108
+ /**
109
+ * Writes the workspace layout to disk now. The layout is saved on a delay, and `reload()` reloads without saving, so a
110
+ * panel folded just before it would come back open. Does nothing in an Obsidian without `saveLayout()`.
111
+ */
112
+ export declare function saveWorkspaceLayout(): Promise<void>;
113
+ export declare function readConfig(key: string): unknown;
114
+ /**
115
+ * Scrolls the first element matching `selector` from top to bottom in steps a little shorter than its height, so
116
+ * blocks that render when they come into view are drawn. Returns false when nothing matches. It stays at the bottom:
117
+ * the reading view drops the sections that leave the viewport, so scrolling back to the top removed the block the
118
+ * scroll had just drawn (found live in Obsidian 1.14.5).
119
+ * Between steps it waits two animation frames (an IntersectionObserver reports on the next frame), with a 100 ms
120
+ * fallback timer because a window that is not visible does not run frames. The height is read again every step,
121
+ * since drawing a block can make the note longer.
122
+ */
123
+ export declare function scrollThroughElement(selector: string): Promise<boolean>;
124
+ /**
125
+ * Starts watching `root` (a selector; null is the whole `<body>`) for DOM changes, replacing any watch left from an
126
+ * earlier call. Returns false when nothing matches or the page cannot observe mutations. Animations and transitions
127
+ * are not DOM changes, so an endless CSS animation never keeps the page from settling.
128
+ */
129
+ export declare function watchPageChanges(root: string | null): boolean;
130
+ /** Stops the watch of `watchPageChanges`. */
131
+ export declare function stopPageWatch(): void;
132
+ /**
133
+ * True when the watched part of the page has had no DOM change for `quietMs`, no font is loading, and every image
134
+ * inside it that is in the viewport has finished loading (a broken image counts as finished). False when no watch
135
+ * is running, as after a reload. `unsettledReasons` must keep answering the same question.
136
+ */
137
+ export declare function isPageSettled(quietMs: number): boolean;
138
+ /** What keeps the page from being settled right now, for the error of a `settle()` that ran out of time. Empty when it is settled. */
139
+ export declare function unsettledReasons(quietMs: number): string[];
140
+ export type RunWithAppResult = {
141
+ ok: true;
142
+ value: unknown;
143
+ } | {
144
+ ok: false;
145
+ reason: string;
146
+ };
147
+ /**
148
+ * Rebuilds `source` (the text of a function) and calls it with `window.app` and `arg`; the result is awaited. The
149
+ * function crossed the process boundary as source text, so it is rebuilt with an indirect eval. A refusal comes back
150
+ * as a reason; an exception thrown by the function itself is not caught here and reaches the test as it is.
151
+ */
152
+ export declare function runWithApp(args: {
153
+ source: string;
154
+ arg?: unknown;
155
+ }): Promise<RunWithAppResult>;
156
+ export type InstallFakeResult = {
157
+ ok: true;
158
+ } | {
159
+ ok: false;
160
+ reason: string;
161
+ };
162
+ /**
163
+ * Replaces `plugin[path]` (a dotted path) on the live plugin instance. `source` is the text of a factory: it is
164
+ * rebuilt here, called once with `arg`, and the function it returns becomes the replacement, wrapped so that every
165
+ * call's arguments are recorded under `id`. The factory runs once, so what it declares stays alive between calls.
166
+ * The previous value is kept for `removeFake`. Refuses a plugin that is not loaded, a path that does not exist and a
167
+ * factory that fails or does not return a function, so a typo cannot pass silently. Nothing is changed on a refusal.
168
+ */
169
+ export declare function installFake(args: {
170
+ id: string;
171
+ pluginId: string;
172
+ path: string;
173
+ source: string;
174
+ arg?: unknown;
175
+ }): InstallFakeResult;
176
+ export declare function readFakeCalls(id: string): unknown[][] | null;
177
+ /** Puts the original value back (deleting the property if it was inherited) and forgets the record. */
178
+ export declare function removeFake(id: string): boolean;
179
+ export declare function hasInnerWidth(width: number): boolean;
180
+ /** The ids of the plugins Obsidian has enabled, which the page loads again after a reload. */
181
+ export declare function enabledPluginIds(): string[];
182
+ /** Sets a flag that a reload wipes, so the wait can tell the old page from the new one. */
183
+ export declare function markBeforeReload(): void;
184
+ export declare function isReloaded(): boolean;
185
+ /** Starts Obsidian's mobile emulation. The window reloads, so a call that works never returns. */
186
+ export declare function switchMobileEmulation(on: boolean): void;
187
+ /**
188
+ * Starts Obsidian's own reload, the command "Reload app without saving" (`app:reload`). The window reloads, so a call
189
+ * that works never returns. One that returns says why not: "missing" (no `executeCommandById` or no such command),
190
+ * "refused" (the command exists and Obsidian declined to run it) or "started" (it ran and the page is still here).
191
+ */
192
+ export declare function reloadApp(): "missing" | "refused" | "started";
193
+ /** True once the body class says whether Obsidian runs as mobile. */
194
+ export declare function isMobileApplied(on: boolean): boolean;
@@ -0,0 +1,467 @@
1
+ /**
2
+ * Functions Playwright serializes and runs inside Obsidian, for the `obsidian` helpers. Like `../page-scripts.ts`,
3
+ * each one must be self-contained: only its source text crosses into the page, so it cannot call another function
4
+ * of this file or use an import. They are exported so tests can run them against a fake `globalThis`. The page's
5
+ * own DOM and Obsidian types are not available to the kit (`lib` has no DOM), hence the small interfaces below.
6
+ */
7
+ // --- settings ---------------------------------------------------------------------------------------------
8
+ /** Whether a settings tab with this id is registered (a community plugin's or a core one). */
9
+ export function hasSettingTab(id) {
10
+ const setting = globalThis.app?.setting;
11
+ return [...(setting?.pluginTabs ?? []), ...(setting?.settingTabs ?? [])].some((tab) => tab.id === id);
12
+ }
13
+ /** The ids of every registered settings tab, for the error of a tab that does not exist. */
14
+ export function listSettingTabIds() {
15
+ const setting = globalThis.app?.setting;
16
+ return [...(setting?.settingTabs ?? []), ...(setting?.pluginTabs ?? [])].map((tab) => tab.id);
17
+ }
18
+ /** Opens the settings modal (unless it is open already, which would stack a second one), on the tab `id` when given. */
19
+ export function openSettingsModal(id) {
20
+ const globals = globalThis;
21
+ const setting = globals.app?.setting;
22
+ if (globals.document?.querySelector(".modal.mod-settings") === null || globals.document === undefined) {
23
+ setting?.open?.();
24
+ }
25
+ if (id !== null) {
26
+ setting?.openTabById?.(id);
27
+ }
28
+ }
29
+ export function closeSettingsModal() {
30
+ globalThis.app?.setting?.close?.();
31
+ }
32
+ /** Runs a command through Obsidian's own executor, the one the palette and hotkeys use. */
33
+ export function runCommandById(id) {
34
+ const commands = globalThis.app?.commands;
35
+ const registered = commands?.commands ?? {};
36
+ if (!(id in registered)) {
37
+ return { state: "missing", ids: Object.keys(registered) };
38
+ }
39
+ // executeCommandById gives no signal for a declined command: Obsidian 1.14.5 returns true for a command whose
40
+ // checkCallback returned false (and false only for an unknown id). So the check runs first, in its check-only form.
41
+ const command = registered[id];
42
+ if (typeof command?.checkCallback === "function" && command.checkCallback(true) === false) {
43
+ return { state: "declined" };
44
+ }
45
+ return commands?.executeCommandById?.(id) === false ? { state: "declined" } : { state: "ran" };
46
+ }
47
+ /**
48
+ * Opens a note in the active tab and, when a mode is wanted, forces it. `openFile` takes the requested state only
49
+ * when it opens the note; for a note already open in this tab it keeps the mode it has, so the view's state is set
50
+ * directly afterwards. Returns the mode the view ended up in so the caller can verify it.
51
+ */
52
+ export async function openFileInMode(args) {
53
+ const { app } = globalThis;
54
+ const file = app?.vault?.getAbstractFileByPath?.(args.path);
55
+ const leaf = app?.workspace?.getLeaf?.(false);
56
+ if (file === null || file === undefined || typeof file.extension !== "string" || leaf === undefined) {
57
+ return { found: false };
58
+ }
59
+ const { wanted } = args;
60
+ await leaf.openFile(file, wanted === null ? { active: true } : { active: true, state: wanted });
61
+ app?.workspace?.setActiveLeaf?.(leaf, { focus: true });
62
+ const state = leaf.view.getState?.();
63
+ if (wanted !== null && state !== undefined) {
64
+ const mismatch = state.mode !== wanted.mode || (wanted.mode === "source" && state.source !== wanted.source);
65
+ if (mismatch) {
66
+ await leaf.view.setState?.({ ...state, mode: wanted.mode, source: wanted.source }, { history: false });
67
+ }
68
+ }
69
+ const final = leaf.view.getState?.();
70
+ if (final === undefined) {
71
+ return { found: true, view: null };
72
+ }
73
+ return { found: true, view: { mode: String(final.mode), source: final.source === true } };
74
+ }
75
+ export function readActiveFilePath() {
76
+ return globalThis.app?.workspace?.getActiveFile?.()?.path ?? null;
77
+ }
78
+ /** The whole document of the active editor. `getValue()`, not the DOM: CodeMirror only renders the visible lines. */
79
+ export function readEditorText() {
80
+ return globalThis.app?.workspace?.activeEditor?.editor?.getValue() ?? null;
81
+ }
82
+ export function readEditorSelection() {
83
+ const editor = globalThis.app?.workspace?.activeEditor?.editor;
84
+ const first = editor?.listSelections()[0];
85
+ if (editor === undefined || first === undefined) {
86
+ return null;
87
+ }
88
+ return { text: editor.getSelection(), anchor: first.anchor, head: first.head };
89
+ }
90
+ /** Focuses the active editor and puts the cursor at `position` (CodeMirror clamps a position past the end). */
91
+ export function placeEditorCursor(position) {
92
+ const editor = globalThis.app?.workspace?.activeEditor?.editor;
93
+ if (editor === undefined) {
94
+ return false;
95
+ }
96
+ editor.focus();
97
+ editor.setCursor(position);
98
+ return true;
99
+ }
100
+ /** True when the keyboard focus is inside the first element that matches `selector`. */
101
+ export function isFocusInside(selector) {
102
+ const document = globalThis.document;
103
+ return document?.querySelector(selector)?.contains(document.activeElement) === true;
104
+ }
105
+ export function isEditorEmpty() {
106
+ return globalThis.app?.workspace?.activeEditor?.editor?.getValue() === "";
107
+ }
108
+ /** True once the document is not `before` any more. */
109
+ export function editorTextChanged(before) {
110
+ const text = globalThis.app?.workspace?.activeEditor?.editor?.getValue();
111
+ return text !== undefined && text !== before;
112
+ }
113
+ /**
114
+ * True when CodeMirror is not inside a composition. It keeps the flag set for a moment after the commit, and a next
115
+ * composition started inside that window would be read as the same one.
116
+ */
117
+ export function isEditorSettled() {
118
+ return globalThis.app?.workspace?.activeEditor?.editor?.cm?.composing !== true;
119
+ }
120
+ /**
121
+ * Sets the colour scheme (`obsidian` is dark, `moonstone` is light) the way Obsidian's appearance settings do, then
122
+ * the community theme when one is named (an empty string is the default theme). Reports the installed themes when
123
+ * the named one is not among them.
124
+ */
125
+ export function applyTheme(args) {
126
+ const { app } = globalThis;
127
+ if (args.theme !== null && args.theme !== "") {
128
+ const themes = Object.keys(app?.customCss?.themes ?? {});
129
+ if (!themes.includes(args.theme)) {
130
+ return { ok: false, themes };
131
+ }
132
+ }
133
+ app?.changeTheme?.(args.scheme);
134
+ app?.vault?.setConfig?.("theme", args.scheme);
135
+ if (args.theme !== null) {
136
+ app?.customCss?.setTheme?.(args.theme);
137
+ }
138
+ app?.workspace?.trigger?.("css-change");
139
+ return { ok: true };
140
+ }
141
+ /** True once the body carries the class of the wanted scheme (`theme-dark` or `theme-light`). */
142
+ export function isSchemeApplied(scheme) {
143
+ const cls = scheme === "obsidian" ? "theme-dark" : "theme-light";
144
+ return globalThis.document?.body.classList.contains(cls) === true;
145
+ }
146
+ export function metadataCacheState() {
147
+ const app = globalThis.app;
148
+ const files = app?.vault?.getMarkdownFiles?.() ?? [];
149
+ const cached = files.filter((file) => Boolean(app?.metadataCache?.getFileCache?.(file))).length;
150
+ return { total: files.length, cached };
151
+ }
152
+ /** True when every markdown file of the vault has its metadata cached; a vault with none is complete at once. */
153
+ export function isMetadataCacheComplete() {
154
+ const app = globalThis.app;
155
+ const files = app?.vault?.getMarkdownFiles?.() ?? [];
156
+ return files.every((file) => Boolean(app?.metadataCache?.getFileCache?.(file)));
157
+ }
158
+ /** Removes every notice from the DOM and returns how many there were. */
159
+ export function removeNotices() {
160
+ const notices = Array.from(globalThis.document?.querySelectorAll(".notice") ?? []);
161
+ for (const notice of notices) {
162
+ notice.remove();
163
+ }
164
+ return notices.length;
165
+ }
166
+ /**
167
+ * Hides the properties block of notes and saves the setting to app.json at once. `setConfig` alone changes it in
168
+ * memory only: Obsidian reads app.json again after the next settings save (`cleanUi` does one) and the block came
169
+ * back. Returns false when this Obsidian cannot be configured, so the helper can
170
+ * fail with a message.
171
+ */
172
+ export async function hideNoteProperties() {
173
+ const vault = globalThis.app?.vault;
174
+ if (vault?.setConfig === undefined || vault.saveConfig === undefined) {
175
+ return false;
176
+ }
177
+ vault.setConfig("propertiesInDocument", "hidden");
178
+ await vault.saveConfig();
179
+ return true;
180
+ }
181
+ /**
182
+ * Collapses (`true`) or expands (`false`) the left and right side panels. Returns false when this Obsidian has no such
183
+ * split object, so the helper can fail with a message instead of waiting for a state that cannot come.
184
+ */
185
+ export function setSidebarsCollapsed(collapsed) {
186
+ const workspace = globalThis.app?.workspace;
187
+ const splits = [workspace?.leftSplit, workspace?.rightSplit];
188
+ for (const split of splits) {
189
+ if (typeof split?.collapse !== "function" || typeof split.expand !== "function") {
190
+ return false;
191
+ }
192
+ }
193
+ for (const split of splits) {
194
+ if (collapsed) {
195
+ split?.collapse?.();
196
+ }
197
+ else {
198
+ split?.expand?.();
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ /** True when both side panels are in the wanted state; the panels animate, so `collapse()` returns before it holds. */
204
+ export function areSidebarsCollapsed(collapsed) {
205
+ const workspace = globalThis.app?.workspace;
206
+ return [workspace?.leftSplit, workspace?.rightSplit].every((split) => split?.collapsed === collapsed);
207
+ }
208
+ /**
209
+ * Writes the workspace layout to disk now. The layout is saved on a delay, and `reload()` reloads without saving, so a
210
+ * panel folded just before it would come back open. Does nothing in an Obsidian without `saveLayout()`.
211
+ */
212
+ export async function saveWorkspaceLayout() {
213
+ await globalThis.app?.workspace?.saveLayout?.();
214
+ }
215
+ export function readConfig(key) {
216
+ return globalThis.app?.vault?.getConfig?.(key);
217
+ }
218
+ /**
219
+ * Scrolls the first element matching `selector` from top to bottom in steps a little shorter than its height, so
220
+ * blocks that render when they come into view are drawn. Returns false when nothing matches. It stays at the bottom:
221
+ * the reading view drops the sections that leave the viewport, so scrolling back to the top removed the block the
222
+ * scroll had just drawn (found live in Obsidian 1.14.5).
223
+ * Between steps it waits two animation frames (an IntersectionObserver reports on the next frame), with a 100 ms
224
+ * fallback timer because a window that is not visible does not run frames. The height is read again every step,
225
+ * since drawing a block can make the note longer.
226
+ */
227
+ export async function scrollThroughElement(selector) {
228
+ const globals = globalThis;
229
+ const root = globals.document?.querySelector(selector) ?? null;
230
+ if (root === null) {
231
+ return false;
232
+ }
233
+ const frame = () => new Promise((resolve) => {
234
+ const timer = setTimeout(resolve, 100);
235
+ globals.requestAnimationFrame?.(() => {
236
+ globals.requestAnimationFrame?.(() => {
237
+ clearTimeout(timer);
238
+ resolve();
239
+ });
240
+ });
241
+ });
242
+ const maxSteps = 500;
243
+ let top = 0;
244
+ for (let step = 0; step < maxSteps; step++) {
245
+ root.scrollTop = top;
246
+ await frame();
247
+ if (top >= root.scrollHeight - root.clientHeight) {
248
+ break;
249
+ }
250
+ top += Math.max(200, root.clientHeight - 100);
251
+ }
252
+ return true;
253
+ }
254
+ // --- settle -------------------------------------------------------------------------------------------------
255
+ /**
256
+ * Starts watching `root` (a selector; null is the whole `<body>`) for DOM changes, replacing any watch left from an
257
+ * earlier call. Returns false when nothing matches or the page cannot observe mutations. Animations and transitions
258
+ * are not DOM changes, so an endless CSS animation never keeps the page from settling.
259
+ */
260
+ export function watchPageChanges(root) {
261
+ const globals = globalThis;
262
+ globals.__opdkSettle?.observer.disconnect();
263
+ globals.__opdkSettle = undefined;
264
+ const target = root === null ? globals.document?.body : globals.document?.querySelector(root);
265
+ if (target === undefined || target === null || globals.MutationObserver === undefined || globals.performance === undefined) {
266
+ return false;
267
+ }
268
+ const watch = { observer: { disconnect: () => undefined }, lastChange: globals.performance.now(), root: target };
269
+ const { performance } = globals;
270
+ const observer = new globals.MutationObserver(() => {
271
+ watch.lastChange = performance.now();
272
+ });
273
+ observer.observe(target, { childList: true, subtree: true, attributes: true, characterData: true });
274
+ watch.observer = observer;
275
+ globals.__opdkSettle = watch;
276
+ return true;
277
+ }
278
+ /** Stops the watch of `watchPageChanges`. */
279
+ export function stopPageWatch() {
280
+ const globals = globalThis;
281
+ globals.__opdkSettle?.observer.disconnect();
282
+ globals.__opdkSettle = undefined;
283
+ }
284
+ /**
285
+ * True when the watched part of the page has had no DOM change for `quietMs`, no font is loading, and every image
286
+ * inside it that is in the viewport has finished loading (a broken image counts as finished). False when no watch
287
+ * is running, as after a reload. `unsettledReasons` must keep answering the same question.
288
+ */
289
+ export function isPageSettled(quietMs) {
290
+ const globals = globalThis;
291
+ const watch = globals.__opdkSettle;
292
+ if (watch === undefined || globals.performance === undefined || globals.performance.now() - watch.lastChange < quietMs) {
293
+ return false;
294
+ }
295
+ if (globals.document?.fonts?.status === "loading") {
296
+ return false;
297
+ }
298
+ const height = globals.innerHeight ?? 0;
299
+ const width = globals.innerWidth ?? 0;
300
+ const images = watch.root.querySelectorAll("img");
301
+ return !Array.from(images).some((image) => {
302
+ const box = image.getBoundingClientRect();
303
+ return !image.complete && box.bottom > 0 && box.right > 0 && box.top < height && box.left < width;
304
+ });
305
+ }
306
+ /** What keeps the page from being settled right now, for the error of a `settle()` that ran out of time. Empty when it is settled. */
307
+ export function unsettledReasons(quietMs) {
308
+ const globals = globalThis;
309
+ const watch = globals.__opdkSettle;
310
+ if (watch === undefined || globals.performance === undefined) {
311
+ return ["the watch was lost, probably because the window reloaded during settle()"];
312
+ }
313
+ const reasons = [];
314
+ const sinceChange = globals.performance.now() - watch.lastChange;
315
+ if (sinceChange < quietMs) {
316
+ reasons.push(`the DOM changed ${String(Math.round(sinceChange))} ms ago`);
317
+ }
318
+ if (globals.document?.fonts?.status === "loading") {
319
+ reasons.push("a font is still loading");
320
+ }
321
+ const height = globals.innerHeight ?? 0;
322
+ const width = globals.innerWidth ?? 0;
323
+ const images = watch.root.querySelectorAll("img");
324
+ const pending = Array.from(images).filter((image) => {
325
+ const box = image.getBoundingClientRect();
326
+ return !image.complete && box.bottom > 0 && box.right > 0 && box.top < height && box.left < width;
327
+ }).length;
328
+ if (pending > 0) {
329
+ reasons.push(`${String(pending)} ${pending === 1 ? "image" : "images"} in view ${pending === 1 ? "has" : "have"} not finished loading`);
330
+ }
331
+ return reasons;
332
+ }
333
+ /**
334
+ * Rebuilds `source` (the text of a function) and calls it with `window.app` and `arg`; the result is awaited. The
335
+ * function crossed the process boundary as source text, so it is rebuilt with an indirect eval. A refusal comes back
336
+ * as a reason; an exception thrown by the function itself is not caught here and reaches the test as it is.
337
+ */
338
+ export async function runWithApp(args) {
339
+ const { app } = globalThis;
340
+ if (app === undefined) {
341
+ return { ok: false, reason: "window.app is not defined yet" };
342
+ }
343
+ let fn;
344
+ try {
345
+ fn = (0, eval)(`(${args.source})`);
346
+ }
347
+ catch (error) {
348
+ return { ok: false, reason: `the function could not be rebuilt in the page: ${error instanceof Error ? error.message : String(error)}` };
349
+ }
350
+ if (typeof fn !== "function") {
351
+ return { ok: false, reason: "the argument is not a function; pass an arrow function or a function expression" };
352
+ }
353
+ return { ok: true, value: await fn(app, args.arg) };
354
+ }
355
+ /**
356
+ * Replaces `plugin[path]` (a dotted path) on the live plugin instance. `source` is the text of a factory: it is
357
+ * rebuilt here, called once with `arg`, and the function it returns becomes the replacement, wrapped so that every
358
+ * call's arguments are recorded under `id`. The factory runs once, so what it declares stays alive between calls.
359
+ * The previous value is kept for `removeFake`. Refuses a plugin that is not loaded, a path that does not exist and a
360
+ * factory that fails or does not return a function, so a typo cannot pass silently. Nothing is changed on a refusal.
361
+ */
362
+ export function installFake(args) {
363
+ const globals = globalThis;
364
+ const plugins = globals.app?.plugins?.plugins ?? {};
365
+ const plugin = plugins[args.pluginId];
366
+ if (plugin === undefined) {
367
+ return { ok: false, reason: `plugin "${args.pluginId}" is not loaded (loaded: ${Object.keys(plugins).join(", ") || "none"})` };
368
+ }
369
+ const keys = args.path.split(".");
370
+ const key = keys.pop() ?? "";
371
+ let owner = plugin;
372
+ for (const step of keys) {
373
+ const next = owner[step];
374
+ if (typeof next !== "object" || next === null) {
375
+ return { ok: false, reason: `"${step}" in "${args.path}" is not an object on plugin "${args.pluginId}"` };
376
+ }
377
+ owner = next;
378
+ }
379
+ if (key === "" || !(key in owner)) {
380
+ return { ok: false, reason: `plugin "${args.pluginId}" has no property "${args.path}" (properties: ${Object.keys(owner).join(", ")})` };
381
+ }
382
+ let impl;
383
+ try {
384
+ // Indirect eval: the factory crosses the process boundary as source text, and has to be rebuilt in the page.
385
+ const factory = (0, eval)(`(${args.source})`);
386
+ if (typeof factory !== "function") {
387
+ return { ok: false, reason: "the replacement factory is not a function; pass an arrow function or a function expression that returns the replacement" };
388
+ }
389
+ impl = factory(args.arg);
390
+ }
391
+ catch (error) {
392
+ return { ok: false, reason: `the replacement factory threw: ${error instanceof Error ? error.message : String(error)}` };
393
+ }
394
+ if (typeof impl !== "function") {
395
+ return { ok: false, reason: "the replacement factory did not return a function; return the function that replaces the property" };
396
+ }
397
+ const record = {
398
+ calls: [],
399
+ owner,
400
+ key,
401
+ hadOwn: Object.hasOwn(owner, key),
402
+ original: owner[key],
403
+ };
404
+ globals.__opdkFakes ??= new Map();
405
+ globals.__opdkFakes.set(args.id, record);
406
+ owner[key] = function (...callArgs) {
407
+ record.calls.push(callArgs);
408
+ return impl.apply(this, callArgs);
409
+ };
410
+ return { ok: true };
411
+ }
412
+ export function readFakeCalls(id) {
413
+ return globalThis.__opdkFakes?.get(id)?.calls ?? null;
414
+ }
415
+ /** Puts the original value back (deleting the property if it was inherited) and forgets the record. */
416
+ export function removeFake(id) {
417
+ const fakes = globalThis.__opdkFakes;
418
+ const record = fakes?.get(id);
419
+ if (record === undefined) {
420
+ return false;
421
+ }
422
+ if (record.hadOwn) {
423
+ record.owner[record.key] = record.original;
424
+ }
425
+ else {
426
+ // Reflect.deleteProperty, not `delete`: the key is dynamic.
427
+ Reflect.deleteProperty(record.owner, record.key);
428
+ }
429
+ fakes?.delete(id);
430
+ return true;
431
+ }
432
+ // --- mobile ------------------------------------------------------------------------------------------------
433
+ export function hasInnerWidth(width) {
434
+ return globalThis.innerWidth === width;
435
+ }
436
+ /** The ids of the plugins Obsidian has enabled, which the page loads again after a reload. */
437
+ export function enabledPluginIds() {
438
+ return Array.from(globalThis.app?.plugins?.enabledPlugins ?? []);
439
+ }
440
+ /** Sets a flag that a reload wipes, so the wait can tell the old page from the new one. */
441
+ export function markBeforeReload() {
442
+ globalThis.__opdkBeforeReload = true;
443
+ }
444
+ export function isReloaded() {
445
+ const globals = globalThis;
446
+ return globals.__opdkBeforeReload !== true && globals.app?.workspace?.layoutReady === true;
447
+ }
448
+ /** Starts Obsidian's mobile emulation. The window reloads, so a call that works never returns. */
449
+ export function switchMobileEmulation(on) {
450
+ globalThis.app?.emulateMobile?.(on);
451
+ }
452
+ /**
453
+ * Starts Obsidian's own reload, the command "Reload app without saving" (`app:reload`). The window reloads, so a call
454
+ * that works never returns. One that returns says why not: "missing" (no `executeCommandById` or no such command),
455
+ * "refused" (the command exists and Obsidian declined to run it) or "started" (it ran and the page is still here).
456
+ */
457
+ export function reloadApp() {
458
+ const commands = globalThis.app?.commands;
459
+ if (commands?.executeCommandById === undefined || commands.commands === undefined || !("app:reload" in commands.commands)) {
460
+ return "missing";
461
+ }
462
+ return commands.executeCommandById("app:reload") ? "started" : "refused";
463
+ }
464
+ /** True once the body class says whether Obsidian runs as mobile. */
465
+ export function isMobileApplied(on) {
466
+ return globalThis.document?.body.classList.contains("is-mobile") === on;
467
+ }
@@ -0,0 +1,8 @@
1
+ /** The error for a settings modal that did not appear in the main window. */
2
+ export declare function settingsNotOpenedMessage(params: {
3
+ popoutConfigured: boolean;
4
+ windows: number;
5
+ timeoutMs: number;
6
+ }): string;
7
+ /** The error for a settings tab id that is not registered, with the ids that are. */
8
+ export declare function settingsTabNotFoundMessage(tab: string, registered: readonly string[], timeoutMs: number): string;