wxt 0.18.15 → 0.19.0

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 (257) hide show
  1. package/bin/wxt.mjs +1 -1
  2. package/dist/browser/chrome.d.ts +17 -0
  3. package/dist/browser/chrome.mjs +7 -0
  4. package/dist/browser/index.d.ts +18 -0
  5. package/dist/browser/index.mjs +2 -0
  6. package/dist/builtin-modules/index.d.ts +2 -0
  7. package/dist/builtin-modules/index.mjs +2 -0
  8. package/dist/builtin-modules/unimport.d.ts +8 -0
  9. package/dist/builtin-modules/unimport.mjs +99 -0
  10. package/dist/cli/cli-utils.d.ts +25 -0
  11. package/dist/cli/cli-utils.mjs +58 -0
  12. package/dist/cli/commands.d.ts +2 -0
  13. package/dist/cli/commands.mjs +104 -0
  14. package/dist/cli/index.d.ts +1 -0
  15. package/dist/cli/index.mjs +11 -0
  16. package/dist/client/app-config.d.ts +2 -0
  17. package/dist/client/app-config.mjs +4 -0
  18. package/dist/client/content-scripts/content-script-context.d.ts +114 -0
  19. package/dist/client/content-scripts/content-script-context.mjs +169 -0
  20. package/dist/client/content-scripts/custom-events.d.ts +10 -0
  21. package/dist/client/content-scripts/custom-events.mjs +13 -0
  22. package/dist/client/content-scripts/index.d.ts +2 -0
  23. package/dist/client/content-scripts/index.mjs +2 -0
  24. package/dist/client/content-scripts/location-watcher.d.ts +12 -0
  25. package/dist/client/content-scripts/location-watcher.mjs +22 -0
  26. package/dist/client/content-scripts/ui/index.d.ts +23 -0
  27. package/dist/client/content-scripts/ui/index.mjs +188 -0
  28. package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
  29. package/dist/client/content-scripts/ui/types.mjs +0 -0
  30. package/dist/client/index.d.ts +7 -0
  31. package/dist/client/index.mjs +2 -0
  32. package/dist/core/build.d.ts +15 -0
  33. package/dist/core/build.mjs +6 -0
  34. package/dist/core/builders/vite/index.d.ts +3 -0
  35. package/dist/core/builders/vite/index.mjs +285 -0
  36. package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
  37. package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
  38. package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
  39. package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
  40. package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
  41. package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
  42. package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
  43. package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
  44. package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
  45. package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
  46. package/dist/core/builders/vite/plugins/download.d.ts +10 -0
  47. package/dist/core/builders/vite/plugins/download.mjs +14 -0
  48. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
  49. package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
  50. package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
  51. package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
  52. package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
  53. package/dist/core/builders/vite/plugins/globals.mjs +15 -0
  54. package/dist/core/builders/vite/plugins/index.d.ts +17 -0
  55. package/dist/core/builders/vite/plugins/index.mjs +17 -0
  56. package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
  57. package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
  58. package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
  59. package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
  60. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
  61. package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
  62. package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
  63. package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
  64. package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
  65. package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
  66. package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
  67. package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
  68. package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
  69. package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
  70. package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
  71. package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
  72. package/dist/core/clean.d.ts +21 -0
  73. package/dist/core/clean.mjs +38 -0
  74. package/dist/core/create-server.d.ts +11 -0
  75. package/dist/core/create-server.mjs +206 -0
  76. package/dist/core/define-config.d.ts +2 -0
  77. package/dist/core/define-config.mjs +3 -0
  78. package/dist/core/define-runner-config.d.ts +2 -0
  79. package/dist/core/define-runner-config.mjs +3 -0
  80. package/dist/core/index.d.ts +8 -0
  81. package/dist/core/index.mjs +8 -0
  82. package/dist/core/initialize.d.ts +5 -0
  83. package/dist/core/initialize.mjs +128 -0
  84. package/dist/core/package-managers/bun.d.ts +2 -0
  85. package/dist/core/package-managers/bun.mjs +19 -0
  86. package/dist/core/package-managers/index.d.ts +2 -0
  87. package/dist/core/package-managers/index.mjs +65 -0
  88. package/dist/core/package-managers/npm.d.ts +17 -0
  89. package/dist/core/package-managers/npm.mjs +58 -0
  90. package/dist/core/package-managers/pnpm.d.ts +2 -0
  91. package/dist/core/package-managers/pnpm.mjs +21 -0
  92. package/dist/core/package-managers/types.d.ts +2 -0
  93. package/dist/core/package-managers/types.mjs +0 -0
  94. package/dist/core/package-managers/yarn.d.ts +2 -0
  95. package/dist/core/package-managers/yarn.mjs +31 -0
  96. package/dist/core/prepare.d.ts +2 -0
  97. package/dist/core/prepare.mjs +8 -0
  98. package/dist/core/runners/index.d.ts +2 -0
  99. package/dist/core/runners/index.mjs +12 -0
  100. package/dist/core/runners/manual.d.ts +5 -0
  101. package/dist/core/runners/manual.mjs +16 -0
  102. package/dist/core/runners/safari.d.ts +5 -0
  103. package/dist/core/runners/safari.mjs +16 -0
  104. package/dist/core/runners/web-ext.d.ts +5 -0
  105. package/dist/core/runners/web-ext.mjs +78 -0
  106. package/dist/core/runners/wsl.d.ts +5 -0
  107. package/dist/core/runners/wsl.mjs +16 -0
  108. package/dist/core/utils/arrays.d.ts +13 -0
  109. package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
  110. package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
  111. package/dist/core/utils/building/build-entrypoints.mjs +47 -0
  112. package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
  113. package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
  114. package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
  115. package/dist/core/utils/building/find-entrypoints.mjs +385 -0
  116. package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
  117. package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
  118. package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
  119. package/dist/core/utils/building/group-entrypoints.mjs +37 -0
  120. package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
  121. package/dist/core/utils/building/import-entrypoint.mjs +97 -0
  122. package/dist/core/utils/building/index.d.ts +9 -0
  123. package/dist/core/utils/building/index.mjs +9 -0
  124. package/dist/core/utils/building/internal-build.d.ts +12 -0
  125. package/dist/core/utils/building/internal-build.mjs +112 -0
  126. package/dist/core/utils/building/rebuild.d.ts +23 -0
  127. package/dist/core/utils/building/rebuild.mjs +39 -0
  128. package/dist/core/utils/building/resolve-config.d.ts +11 -0
  129. package/dist/core/utils/building/resolve-config.mjs +364 -0
  130. package/dist/core/utils/cache.d.ts +8 -0
  131. package/dist/core/utils/cache.mjs +21 -0
  132. package/dist/core/utils/cli.d.ts +3 -0
  133. package/dist/core/utils/cli.mjs +26 -0
  134. package/dist/core/utils/constants.d.ts +5 -0
  135. package/dist/core/utils/constants.mjs +1 -0
  136. package/dist/core/utils/content-scripts.d.ts +11 -0
  137. package/dist/core/utils/content-scripts.mjs +60 -0
  138. package/dist/core/utils/content-security-policy.d.ts +14 -0
  139. package/dist/core/utils/content-security-policy.mjs +39 -0
  140. package/dist/core/utils/entrypoints.d.ts +25 -0
  141. package/dist/core/utils/entrypoints.mjs +31 -0
  142. package/dist/core/utils/eslint.d.ts +1 -0
  143. package/dist/core/utils/eslint.mjs +11 -0
  144. package/dist/core/utils/fs.d.ts +13 -0
  145. package/dist/core/utils/fs.mjs +15 -0
  146. package/dist/core/utils/globals.d.ts +11 -0
  147. package/dist/core/utils/globals.mjs +53 -0
  148. package/dist/core/utils/i18n.d.ts +11 -0
  149. package/dist/core/utils/i18n.mjs +35 -0
  150. package/dist/core/utils/log/index.d.ts +4 -0
  151. package/dist/core/utils/log/index.mjs +4 -0
  152. package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
  153. package/dist/core/utils/log/printBuildSummary.mjs +32 -0
  154. package/dist/core/utils/log/printFileList.d.ts +1 -0
  155. package/dist/core/utils/log/printFileList.mjs +42 -0
  156. package/dist/core/utils/log/printHeader.d.ts +1 -0
  157. package/dist/core/utils/log/printHeader.mjs +7 -0
  158. package/dist/core/utils/log/printTable.d.ts +1 -0
  159. package/dist/core/utils/log/printTable.mjs +22 -0
  160. package/dist/core/utils/manifest.d.ts +44 -0
  161. package/dist/core/utils/manifest.mjs +512 -0
  162. package/dist/core/utils/network.d.ts +7 -0
  163. package/dist/core/utils/network.mjs +38 -0
  164. package/dist/core/utils/package.d.ts +6 -0
  165. package/dist/core/utils/package.mjs +14 -0
  166. package/dist/core/utils/paths.d.ts +11 -0
  167. package/dist/core/utils/paths.mjs +10 -0
  168. package/dist/core/utils/strings.d.ts +14 -0
  169. package/dist/core/utils/strings.mjs +18 -0
  170. package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
  171. package/dist/core/utils/testing/fake-objects.mjs +322 -0
  172. package/dist/core/utils/time.d.ts +9 -0
  173. package/dist/core/utils/time.mjs +17 -0
  174. package/dist/core/utils/transform.d.ts +9 -0
  175. package/dist/core/utils/transform.mjs +17 -0
  176. package/dist/core/utils/types.d.ts +10 -0
  177. package/dist/core/utils/types.mjs +0 -0
  178. package/dist/core/utils/validation.d.ts +15 -0
  179. package/dist/core/utils/validation.mjs +55 -0
  180. package/dist/core/utils/virtual-modules.d.ts +22 -0
  181. package/dist/core/utils/virtual-modules.mjs +14 -0
  182. package/dist/core/utils/wsl.d.ts +4 -0
  183. package/dist/core/utils/wsl.mjs +4 -0
  184. package/dist/core/wxt.d.ts +19 -0
  185. package/dist/core/wxt.mjs +41 -0
  186. package/dist/core/zip.d.ts +7 -0
  187. package/dist/core/zip.mjs +137 -0
  188. package/dist/index.d.ts +4 -79
  189. package/dist/index.mjs +3 -0
  190. package/dist/modules.d.ts +10 -20
  191. package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
  192. package/dist/sandbox/define-app-config.d.ts +19 -0
  193. package/dist/sandbox/define-app-config.mjs +3 -0
  194. package/dist/sandbox/define-background.d.ts +3 -0
  195. package/dist/sandbox/define-background.mjs +4 -0
  196. package/dist/sandbox/define-content-script.d.ts +2 -0
  197. package/dist/sandbox/define-content-script.mjs +3 -0
  198. package/dist/sandbox/define-unlisted-script.d.ts +3 -0
  199. package/dist/sandbox/define-unlisted-script.mjs +4 -0
  200. package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
  201. package/dist/sandbox/define-wxt-plugin.mjs +3 -0
  202. package/dist/sandbox/dev-server-websocket.d.ts +21 -0
  203. package/dist/sandbox/dev-server-websocket.mjs +37 -0
  204. package/dist/sandbox/index.d.ts +11 -0
  205. package/dist/sandbox/index.mjs +6 -0
  206. package/dist/sandbox/utils/logger.d.ts +9 -0
  207. package/dist/sandbox/utils/logger.mjs +15 -0
  208. package/dist/storage.d.ts +39 -16
  209. package/dist/{storage.js → storage.mjs} +30 -41
  210. package/dist/testing/fake-browser.d.ts +1 -0
  211. package/dist/testing/fake-browser.mjs +1 -0
  212. package/dist/testing/index.d.ts +5 -0
  213. package/dist/testing/index.mjs +2 -0
  214. package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
  215. package/dist/testing/wxt-vitest-plugin.mjs +26 -0
  216. package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
  217. package/dist/types.mjs +0 -0
  218. package/dist/version.d.ts +1 -0
  219. package/dist/version.mjs +1 -0
  220. package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
  221. package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
  222. package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
  223. package/dist/virtual/mock-browser.mjs +6 -0
  224. package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
  225. package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
  226. package/package.json +47 -57
  227. package/dist/browser.d.ts +0 -18
  228. package/dist/browser.js +0 -6
  229. package/dist/chunk-BM6QYGAW.js +0 -1063
  230. package/dist/chunk-FNTE2L27.js +0 -7
  231. package/dist/chunk-FP7RYLVL.js +0 -3617
  232. package/dist/chunk-KPD5J7PZ.js +0 -1065
  233. package/dist/chunk-QGM4M3NI.js +0 -37
  234. package/dist/chunk-SGKCDMVR.js +0 -38
  235. package/dist/cli.d.ts +0 -2
  236. package/dist/cli.js +0 -4438
  237. package/dist/client.js +0 -424
  238. package/dist/define-app-config-bg54F_lV.d.ts +0 -294
  239. package/dist/execa-4UBDUBJZ.js +0 -7244
  240. package/dist/execa-QLUM2B3W.js +0 -7245
  241. package/dist/index-nWRfwAJi.d.ts +0 -1401
  242. package/dist/index.cjs +0 -14473
  243. package/dist/index.d.cts +0 -81
  244. package/dist/index.js +0 -696
  245. package/dist/modules.cjs +0 -96
  246. package/dist/modules.d.cts +0 -119
  247. package/dist/modules.js +0 -17
  248. package/dist/prompt-25QIVJDC.js +0 -755
  249. package/dist/prompt-7BMKNSWS.js +0 -754
  250. package/dist/sandbox.d.ts +0 -16
  251. package/dist/sandbox.js +0 -36
  252. package/dist/storage.cjs +0 -439
  253. package/dist/storage.d.cts +0 -200
  254. package/dist/testing.cjs +0 -2815
  255. package/dist/testing.d.cts +0 -30
  256. package/dist/testing.js +0 -40
  257. package/dist/virtual/mock-browser.js +0 -6
@@ -0,0 +1,10 @@
1
+ export declare class WxtLocationChangeEvent extends Event {
2
+ readonly newUrl: URL;
3
+ readonly oldUrl: URL;
4
+ static EVENT_NAME: string;
5
+ constructor(newUrl: URL, oldUrl: URL);
6
+ }
7
+ /**
8
+ * Returns an event name unique to the extension and content script that's running.
9
+ */
10
+ export declare function getUniqueEventName(eventName: string): string;
@@ -0,0 +1,13 @@
1
+ import { browser } from "wxt/browser";
2
+ export class WxtLocationChangeEvent extends Event {
3
+ constructor(newUrl, oldUrl) {
4
+ super(WxtLocationChangeEvent.EVENT_NAME, {});
5
+ this.newUrl = newUrl;
6
+ this.oldUrl = oldUrl;
7
+ }
8
+ static EVENT_NAME = getUniqueEventName("wxt:locationchange");
9
+ }
10
+ export function getUniqueEventName(eventName) {
11
+ const entrypointName = typeof import.meta.env === "undefined" ? "build" : import.meta.env.ENTRYPOINT;
12
+ return `${browser?.runtime?.id}:${entrypointName}:${eventName}`;
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './content-script-context';
2
+ export * from './ui';
@@ -0,0 +1,2 @@
1
+ export * from "./content-script-context.mjs";
2
+ export * from "./ui/index.mjs";
@@ -0,0 +1,12 @@
1
+ import { ContentScriptContext } from '.';
2
+ /**
3
+ * Create a util that watches for URL changes, dispatching the custom event when detected. Stops
4
+ * watching when content script is invalidated.
5
+ */
6
+ export declare function createLocationWatcher(ctx: ContentScriptContext): {
7
+ /**
8
+ * Ensure the location watcher is actively looking for URL changes. If it's already watching,
9
+ * this is a noop.
10
+ */
11
+ run(): void;
12
+ };
@@ -0,0 +1,22 @@
1
+ import { WxtLocationChangeEvent } from "./custom-events.mjs";
2
+ export function createLocationWatcher(ctx) {
3
+ let interval;
4
+ let oldUrl;
5
+ return {
6
+ /**
7
+ * Ensure the location watcher is actively looking for URL changes. If it's already watching,
8
+ * this is a noop.
9
+ */
10
+ run() {
11
+ if (interval != null) return;
12
+ oldUrl = new URL(location.href);
13
+ interval = ctx.setInterval(() => {
14
+ let newUrl = new URL(location.href);
15
+ if (newUrl.href !== oldUrl.href) {
16
+ window.dispatchEvent(new WxtLocationChangeEvent(newUrl, oldUrl));
17
+ oldUrl = newUrl;
18
+ }
19
+ }, 1e3);
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,23 @@
1
+ import { ContentScriptContext } from '..';
2
+ import { IframeContentScriptUi, IframeContentScriptUiOptions, IntegratedContentScriptUi, IntegratedContentScriptUiOptions, ShadowRootContentScriptUi, ShadowRootContentScriptUiOptions } from './types';
3
+ export * from './types';
4
+ /**
5
+ * Create a content script UI without any isolation.
6
+ *
7
+ * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#integrated
8
+ */
9
+ export declare function createIntegratedUi<TMounted>(ctx: ContentScriptContext, options: IntegratedContentScriptUiOptions<TMounted>): IntegratedContentScriptUi<TMounted>;
10
+ /**
11
+ * Create a content script UI using an iframe.
12
+ *
13
+ * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#iframe
14
+ */
15
+ export declare function createIframeUi<TMounted>(ctx: ContentScriptContext, options: IframeContentScriptUiOptions<TMounted>): IframeContentScriptUi<TMounted>;
16
+ /**
17
+ * Create a content script UI inside a [`ShadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot).
18
+ *
19
+ * > This function is async because it has to load the CSS via a network call.
20
+ *
21
+ * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#shadowroot
22
+ */
23
+ export declare function createShadowRootUi<TMounted>(ctx: ContentScriptContext, options: ShadowRootContentScriptUiOptions<TMounted>): Promise<ShadowRootContentScriptUi<TMounted>>;
@@ -0,0 +1,188 @@
1
+ import { browser } from "wxt/browser";
2
+ import { logger } from "../../../sandbox/utils/logger.mjs";
3
+ import { createIsolatedElement } from "@webext-core/isolated-element";
4
+ export * from "./types.mjs";
5
+ export function createIntegratedUi(ctx, options) {
6
+ const wrapper = document.createElement(options.tag || "div");
7
+ wrapper.setAttribute("data-wxt-integrated", "");
8
+ let mounted = void 0;
9
+ const mount = () => {
10
+ applyPosition(wrapper, void 0, options);
11
+ mountUi(wrapper, options);
12
+ mounted = options.onMount?.(wrapper);
13
+ };
14
+ const remove = () => {
15
+ options.onRemove?.(mounted);
16
+ wrapper.remove();
17
+ mounted = void 0;
18
+ };
19
+ ctx.onInvalidated(remove);
20
+ return {
21
+ get mounted() {
22
+ return mounted;
23
+ },
24
+ wrapper,
25
+ mount,
26
+ remove
27
+ };
28
+ }
29
+ export function createIframeUi(ctx, options) {
30
+ const wrapper = document.createElement("div");
31
+ wrapper.setAttribute("data-wxt-iframe", "");
32
+ const iframe = document.createElement("iframe");
33
+ iframe.src = browser.runtime.getURL(options.page);
34
+ wrapper.appendChild(iframe);
35
+ let mounted = void 0;
36
+ const mount = () => {
37
+ applyPosition(wrapper, iframe, options);
38
+ mountUi(wrapper, options);
39
+ mounted = options.onMount?.(wrapper, iframe);
40
+ };
41
+ const remove = () => {
42
+ options.onRemove?.(mounted);
43
+ wrapper.remove();
44
+ mounted = void 0;
45
+ };
46
+ ctx.onInvalidated(remove);
47
+ return {
48
+ get mounted() {
49
+ return mounted;
50
+ },
51
+ iframe,
52
+ wrapper,
53
+ mount,
54
+ remove
55
+ };
56
+ }
57
+ export async function createShadowRootUi(ctx, options) {
58
+ const css = [options.css ?? ""];
59
+ if (ctx.options?.cssInjectionMode === "ui") {
60
+ const entryCss = await loadCss();
61
+ css.push(entryCss.replaceAll(":root", ":host"));
62
+ }
63
+ const {
64
+ isolatedElement: uiContainer,
65
+ parentElement: shadowHost,
66
+ shadow
67
+ } = await createIsolatedElement({
68
+ name: options.name,
69
+ css: {
70
+ textContent: css.join("\n").trim()
71
+ },
72
+ mode: options.mode ?? "open",
73
+ isolateEvents: options.isolateEvents
74
+ });
75
+ shadowHost.setAttribute("data-wxt-shadow-root", "");
76
+ let mounted;
77
+ const mount = () => {
78
+ mountUi(shadowHost, options);
79
+ applyPosition(shadowHost, shadow.querySelector("html"), options);
80
+ mounted = options.onMount(uiContainer, shadow, shadowHost);
81
+ };
82
+ const remove = () => {
83
+ options.onRemove?.(mounted);
84
+ shadowHost.remove();
85
+ while (uiContainer.lastChild)
86
+ uiContainer.removeChild(uiContainer.lastChild);
87
+ mounted = void 0;
88
+ };
89
+ ctx.onInvalidated(remove);
90
+ return {
91
+ shadow,
92
+ shadowHost,
93
+ uiContainer,
94
+ mount,
95
+ remove,
96
+ get mounted() {
97
+ return mounted;
98
+ }
99
+ };
100
+ }
101
+ function applyPosition(root, positionedElement, options) {
102
+ if (options.position === "inline") return;
103
+ if (options.zIndex != null) root.style.zIndex = String(options.zIndex);
104
+ root.style.overflow = "visible";
105
+ root.style.position = "relative";
106
+ root.style.width = "0";
107
+ root.style.height = "0";
108
+ root.style.display = "block";
109
+ if (positionedElement) {
110
+ if (options.position === "overlay") {
111
+ positionedElement.style.position = "absolute";
112
+ if (options.alignment?.startsWith("bottom-"))
113
+ positionedElement.style.bottom = "0";
114
+ else positionedElement.style.top = "0";
115
+ if (options.alignment?.endsWith("-right"))
116
+ positionedElement.style.right = "0";
117
+ else positionedElement.style.left = "0";
118
+ } else {
119
+ positionedElement.style.position = "fixed";
120
+ positionedElement.style.top = "0";
121
+ positionedElement.style.bottom = "0";
122
+ positionedElement.style.left = "0";
123
+ positionedElement.style.right = "0";
124
+ }
125
+ }
126
+ }
127
+ function getAnchor(options) {
128
+ if (options.anchor == null) return document.body;
129
+ let resolved = typeof options.anchor === "function" ? options.anchor() : options.anchor;
130
+ if (typeof resolved === "string") {
131
+ if (resolved.startsWith("/")) {
132
+ const result = document.evaluate(
133
+ resolved,
134
+ document,
135
+ null,
136
+ XPathResult.FIRST_ORDERED_NODE_TYPE,
137
+ null
138
+ );
139
+ return result.singleNodeValue ?? void 0;
140
+ } else {
141
+ return document.querySelector(resolved) ?? void 0;
142
+ }
143
+ }
144
+ return resolved ?? void 0;
145
+ }
146
+ function mountUi(root, options) {
147
+ const anchor = getAnchor(options);
148
+ if (anchor == null)
149
+ throw Error(
150
+ "Failed to mount content script UI: could not find anchor element"
151
+ );
152
+ switch (options.append) {
153
+ case void 0:
154
+ case "last":
155
+ anchor.append(root);
156
+ break;
157
+ case "first":
158
+ anchor.prepend(root);
159
+ break;
160
+ case "replace":
161
+ anchor.replaceWith(root);
162
+ break;
163
+ case "after":
164
+ anchor.parentElement?.insertBefore(root, anchor.nextElementSibling);
165
+ break;
166
+ case "before":
167
+ anchor.parentElement?.insertBefore(root, anchor);
168
+ break;
169
+ default:
170
+ options.append(anchor, root);
171
+ break;
172
+ }
173
+ }
174
+ async function loadCss() {
175
+ const url = browser.runtime.getURL(
176
+ `/content-scripts/${import.meta.env.ENTRYPOINT}.css`
177
+ );
178
+ try {
179
+ const res = await fetch(url);
180
+ return await res.text();
181
+ } catch (err) {
182
+ logger.warn(
183
+ `Failed to load styles @ ${url}. Did you forget to import the stylesheet in your entrypoint?`,
184
+ err
185
+ );
186
+ return "";
187
+ }
188
+ }
@@ -1,13 +1,10 @@
1
- import { b as ContentScriptContext, a as WxtAppConfig } from './define-app-config-bg54F_lV.js';
2
- import 'webextension-polyfill';
3
-
4
- interface IntegratedContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
1
+ export interface IntegratedContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
5
2
  /**
6
3
  * A wrapper div that assists in positioning.
7
4
  */
8
5
  wrapper: HTMLElement;
9
6
  }
10
- interface IframeContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
7
+ export interface IframeContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
11
8
  /**
12
9
  * The iframe added to the DOM.
13
10
  */
@@ -17,7 +14,7 @@ interface IframeContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
17
14
  */
18
15
  wrapper: HTMLDivElement;
19
16
  }
20
- interface ShadowRootContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
17
+ export interface ShadowRootContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
21
18
  /**
22
19
  * The `HTMLElement` hosting the shadow root used to isolate the UI's styles. This is the element
23
20
  * that get's added to the DOM. This element's style is not isolated from the webpage.
@@ -33,7 +30,7 @@ interface ShadowRootContentScriptUi<TMounted> extends ContentScriptUi<TMounted>
33
30
  */
34
31
  shadow: ShadowRoot;
35
32
  }
36
- interface ContentScriptUi<TMounted> {
33
+ export interface ContentScriptUi<TMounted> {
37
34
  /**
38
35
  * Function that mounts or remounts the UI on the page.
39
36
  */
@@ -47,14 +44,14 @@ interface ContentScriptUi<TMounted> {
47
44
  */
48
45
  mounted: TMounted | undefined;
49
46
  }
50
- type ContentScriptUiOptions<TMounted> = ContentScriptPositioningOptions & ContentScriptAnchoredOptions & {
47
+ export type ContentScriptUiOptions<TMounted> = ContentScriptPositioningOptions & ContentScriptAnchoredOptions & {
51
48
  /**
52
49
  * Callback called before the UI is removed from the webpage. Use to cleanup your UI, like
53
50
  * unmounting your Vue or React apps.
54
51
  */
55
52
  onRemove?: (mounted: TMounted | undefined) => void;
56
53
  };
57
- type IntegratedContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
54
+ export type IntegratedContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
58
55
  /**
59
56
  * Tag used to create the wrapper element.
60
57
  *
@@ -69,7 +66,7 @@ type IntegratedContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounte
69
66
  */
70
67
  onMount: (wrapper: HTMLElement) => TMounted;
71
68
  };
72
- type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
69
+ export type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
73
70
  /**
74
71
  * The path to the HTML page that will be shown in the iframe. This string is passed into
75
72
  * `browser.runtime.getURL`.
@@ -83,7 +80,7 @@ type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> &
83
80
  */
84
81
  onMount?: (wrapper: HTMLElement, iframe: HTMLIFrameElement) => TMounted;
85
82
  };
86
- type ShadowRootContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
83
+ export type ShadowRootContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
87
84
  /**
88
85
  * The name of the custom component used to host the ShadowRoot. Must be kebab-case.
89
86
  */
@@ -118,15 +115,15 @@ type ShadowRootContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounte
118
115
  */
119
116
  onMount: (uiContainer: HTMLElement, shadow: ShadowRoot, shadowHost: HTMLElement) => TMounted;
120
117
  };
121
- type ContentScriptOverlayAlignment = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
118
+ export type ContentScriptOverlayAlignment = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
122
119
  /**
123
120
  * ![Visualization of different append modes](https://wxt.dev/content-script-ui-append.png)
124
121
  */
125
- type ContentScriptAppendMode = 'last' | 'first' | 'replace' | 'before' | 'after' | ((anchor: Element, ui: Element) => void);
126
- interface ContentScriptInlinePositioningOptions {
122
+ export type ContentScriptAppendMode = 'last' | 'first' | 'replace' | 'before' | 'after' | ((anchor: Element, ui: Element) => void);
123
+ export interface ContentScriptInlinePositioningOptions {
127
124
  position: 'inline';
128
125
  }
129
- interface ContentScriptOverlayPositioningOptions {
126
+ export interface ContentScriptOverlayPositioningOptions {
130
127
  position: 'overlay';
131
128
  /**
132
129
  * The `z-index` used on the `wrapper` element. Set to a positive number to show your UI over website
@@ -143,7 +140,7 @@ interface ContentScriptOverlayPositioningOptions {
143
140
  */
144
141
  alignment?: ContentScriptOverlayAlignment;
145
142
  }
146
- interface ContentScriptModalPositioningOptions {
143
+ export interface ContentScriptModalPositioningOptions {
147
144
  position: 'modal';
148
145
  /**
149
146
  * The `z-index` used on the `shadowHost`. Set to a positive number to show your UI over website
@@ -152,12 +149,12 @@ interface ContentScriptModalPositioningOptions {
152
149
  zIndex?: number;
153
150
  }
154
151
  /**
155
- * Choose between `"inline"`, `"overlay"`, or `"modal" `types.
152
+ * Choose between `"inline"`, `"overlay"`, or `"modal"` positions.
156
153
  *
157
- * ![Visualization of different types](https://wxt.dev/content-script-ui-type.png)
154
+ * ![Visualization of different types](https://wxt.dev/content-script-ui-position.png)
158
155
  */
159
- type ContentScriptPositioningOptions = ContentScriptInlinePositioningOptions | ContentScriptOverlayPositioningOptions | ContentScriptModalPositioningOptions;
160
- interface ContentScriptAnchoredOptions {
156
+ export type ContentScriptPositioningOptions = ContentScriptInlinePositioningOptions | ContentScriptOverlayPositioningOptions | ContentScriptModalPositioningOptions;
157
+ export interface ContentScriptAnchoredOptions {
161
158
  /**
162
159
  * A CSS selector, XPath expression, element, or function that returns one of the three. Along with `append`, the
163
160
  * `anchor` dictates where in the page the UI will be added.
@@ -175,28 +172,3 @@ interface ContentScriptAnchoredOptions {
175
172
  */
176
173
  append?: ContentScriptAppendMode | ((anchor: Element, ui: Element) => void);
177
174
  }
178
-
179
- /**
180
- * Create a content script UI without any isolation.
181
- *
182
- * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#integrated
183
- */
184
- declare function createIntegratedUi<TMounted>(ctx: ContentScriptContext, options: IntegratedContentScriptUiOptions<TMounted>): IntegratedContentScriptUi<TMounted>;
185
- /**
186
- * Create a content script UI using an iframe.
187
- *
188
- * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#iframe
189
- */
190
- declare function createIframeUi<TMounted>(ctx: ContentScriptContext, options: IframeContentScriptUiOptions<TMounted>): IframeContentScriptUi<TMounted>;
191
- /**
192
- * Create a content script UI inside a [`ShadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot).
193
- *
194
- * > This function is async because it has to load the CSS via a network call.
195
- *
196
- * @see https://wxt.dev/guide/key-concepts/content-script-ui.html#shadowroot
197
- */
198
- declare function createShadowRootUi<TMounted>(ctx: ContentScriptContext, options: ShadowRootContentScriptUiOptions<TMounted>): Promise<ShadowRootContentScriptUi<TMounted>>;
199
-
200
- declare function useAppConfig(): WxtAppConfig;
201
-
202
- export { type ContentScriptAnchoredOptions, type ContentScriptAppendMode, ContentScriptContext, type ContentScriptInlinePositioningOptions, type ContentScriptModalPositioningOptions, type ContentScriptOverlayAlignment, type ContentScriptOverlayPositioningOptions, type ContentScriptPositioningOptions, type ContentScriptUi, type ContentScriptUiOptions, type IframeContentScriptUi, type IframeContentScriptUiOptions, type IntegratedContentScriptUi, type IntegratedContentScriptUiOptions, type ShadowRootContentScriptUi, type ShadowRootContentScriptUiOptions, createIframeUi, createIntegratedUi, createShadowRootUi, useAppConfig };
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Any runtime APIs that use the web extension APIs.
3
+ *
4
+ * @module wxt/client
5
+ */
6
+ export * from './content-scripts';
7
+ export * from './app-config';
@@ -0,0 +1,2 @@
1
+ export * from "./content-scripts/index.mjs";
2
+ export * from "./app-config.mjs";
@@ -0,0 +1,15 @@
1
+ import { BuildOutput, InlineConfig } from '../types';
2
+ /**
3
+ * Bundles the extension for production. Returns a promise of the build result. Discovers the `wxt.config.ts` file in
4
+ * the root directory, and merges that config with what is passed in.
5
+ *
6
+ * @example
7
+ * // Use config from `wxt.config.ts`
8
+ * const res = await build()
9
+ *
10
+ * // or override config `from wxt.config.ts`
11
+ * const res = await build({
12
+ * // Override config...
13
+ * })
14
+ */
15
+ export declare function build(config?: InlineConfig): Promise<BuildOutput>;
@@ -0,0 +1,6 @@
1
+ import { internalBuild } from "./utils/building/index.mjs";
2
+ import { registerWxt } from "./wxt.mjs";
3
+ export async function build(config) {
4
+ await registerWxt("build", config);
5
+ return await internalBuild();
6
+ }
@@ -0,0 +1,3 @@
1
+ import { ResolvedConfig, WxtBuilder, WxtDevServer, WxtHooks } from '../../../types';
2
+ import { Hookable } from 'hookable';
3
+ export declare function createViteBuilder(wxtConfig: ResolvedConfig, hooks: Hookable<WxtHooks>, server?: WxtDevServer): Promise<WxtBuilder>;